Loading .vscode/settings.json +1 −0 Original line number Diff line number Diff line Loading @@ -80,6 +80,7 @@ "spki", "subproperty", "superproperty", "supertypes", "tempserver", "unfollow", "unfollowing", Loading codegen/__snapshots__/class.test.ts.snap +1012 −110 File changed.Preview size limit exceeded, changes collapsed. Show changes codegen/codec.ts +36 −2 Original line number Diff line number Diff line Loading @@ -88,11 +88,45 @@ export async function* generateEncoder( { documentLoader: options.contextLoader }, ); } return await jsonld.compact( const docContext = options.context ?? ${JSON.stringify(type.defaultContext)}; const compacted = await jsonld.compact( values, options.context ?? ${JSON.stringify(type.defaultContext)}, docContext, { documentLoader: options.contextLoader }, ); if (docContext != null) { // Embed context `; const supertypes: string[] = []; for ( let uri: string | undefined = typeUri; uri != null; uri = types[uri].extends ) { supertypes.push(uri); } for (const supertype of supertypes) { for (const property of types[supertype].properties) { if (property.embedContext == null) continue; const compactName = property.embedContext.compactName; yield ` if (${JSON.stringify(compactName)} in compacted && compacted.${compactName} != null) { if (Array.isArray(compacted.${compactName})) { for (const element of compacted.${compactName}) { element["@context"] = docContext; } } else { compacted.${compactName}["@context"] = docContext; } } `; } } yield ` } return compacted; } `; } Loading codegen/schema.ts +17 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,23 @@ export interface PropertySchemaBase { * the generated property accessors. */ description: string; /** * Whether the enclosed object should have its own context when the document * is compacted. */ embedContext?: { /** * The compact name of the property that contains the context. */ compactName: string; /** * Whether the embedded context should be the same as the context of * the enclosing document. */ inherit: true; }; } export type PropertySchemaTyping = { Loading codegen/schema.yaml +15 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,21 @@ $defs: The description of the property. It is used as the doc comment of the generated property accessors. type: string embedContext: description: >- Whether the enclosed object should have its own context when the document is compacted. type: object properties: compactName: description: >- The compact name of the property that contains the context. type: string inherit: description: >- Whether the embedded context should be the same as the context of the enclosing document. const: true required: - singularName - uri Loading Loading
.vscode/settings.json +1 −0 Original line number Diff line number Diff line Loading @@ -80,6 +80,7 @@ "spki", "subproperty", "superproperty", "supertypes", "tempserver", "unfollow", "unfollowing", Loading
codegen/__snapshots__/class.test.ts.snap +1012 −110 File changed.Preview size limit exceeded, changes collapsed. Show changes
codegen/codec.ts +36 −2 Original line number Diff line number Diff line Loading @@ -88,11 +88,45 @@ export async function* generateEncoder( { documentLoader: options.contextLoader }, ); } return await jsonld.compact( const docContext = options.context ?? ${JSON.stringify(type.defaultContext)}; const compacted = await jsonld.compact( values, options.context ?? ${JSON.stringify(type.defaultContext)}, docContext, { documentLoader: options.contextLoader }, ); if (docContext != null) { // Embed context `; const supertypes: string[] = []; for ( let uri: string | undefined = typeUri; uri != null; uri = types[uri].extends ) { supertypes.push(uri); } for (const supertype of supertypes) { for (const property of types[supertype].properties) { if (property.embedContext == null) continue; const compactName = property.embedContext.compactName; yield ` if (${JSON.stringify(compactName)} in compacted && compacted.${compactName} != null) { if (Array.isArray(compacted.${compactName})) { for (const element of compacted.${compactName}) { element["@context"] = docContext; } } else { compacted.${compactName}["@context"] = docContext; } } `; } } yield ` } return compacted; } `; } Loading
codegen/schema.ts +17 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,23 @@ export interface PropertySchemaBase { * the generated property accessors. */ description: string; /** * Whether the enclosed object should have its own context when the document * is compacted. */ embedContext?: { /** * The compact name of the property that contains the context. */ compactName: string; /** * Whether the embedded context should be the same as the context of * the enclosing document. */ inherit: true; }; } export type PropertySchemaTyping = { Loading
codegen/schema.yaml +15 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,21 @@ $defs: The description of the property. It is used as the doc comment of the generated property accessors. type: string embedContext: description: >- Whether the enclosed object should have its own context when the document is compacted. type: object properties: compactName: description: >- The compact name of the property that contains the context. type: string inherit: description: >- Whether the embedded context should be the same as the context of the enclosing document. const: true required: - singularName - uri Loading