Loading CHANGES.md +11 −0 Original line number Original line Diff line number Diff line Loading @@ -13,6 +13,17 @@ Version 0.6.0 To be released. To be released. - `DocumentLoader` is now propagated to the loaded remote objects from Activity Vocabulary objects. [[#27]] - Added `options` parameter to Activity Vocabulary constructors. - Added `options` parameter to `clone()` method of Activity Vocabulary objects. - The Activity Vocabulary object passed to `InboxListener` now implicitly loads remote object with an authenticated `DocumentLoader`. [#27]: https://github.com/dahlia/fedify/issues/27 Version 0.5.0 Version 0.5.0 ------------- ------------- Loading codegen/__snapshots__/class.test.ts.snap +1141 −1550 File changed.File size exceeds preview limit. View original file View changed file codegen/class.ts +8 −1 Original line number Original line Diff line number Diff line Loading @@ -46,7 +46,14 @@ async function* generateClass( yield `export class ${type.name} {\n`; yield `export class ${type.name} {\n`; } } if (type.extends == null) { if (type.extends == null) { yield "readonly id: URL | null;\n"; yield ` readonly #documentLoader?: DocumentLoader; readonly id: URL | null; protected get _documentLoader(): DocumentLoader | undefined { return this.#documentLoader; } `; } } for await (const code of generateFields(typeUri, types)) yield code; for await (const code of generateFields(typeUri, types)) yield code; for await (const code of generateConstructor(typeUri, types)) yield code; for await (const code of generateConstructor(typeUri, types)) yield code; Loading codegen/codec.ts +5 −4 Original line number Original line Diff line number Diff line Loading @@ -87,7 +87,7 @@ export async function* generateDecoder( */ */ static async fromJsonLd( static async fromJsonLd( json: unknown, json: unknown, options: { documentLoader?: DocumentLoader } = {} options: { documentLoader?: DocumentLoader } = {}, ): Promise<${type.name}> { ): Promise<${type.name}> { if (typeof json === "undefined") { if (typeof json === "undefined") { throw new TypeError("Invalid JSON-LD: undefined."); throw new TypeError("Invalid JSON-LD: undefined."); Loading Loading @@ -129,9 +129,10 @@ export async function* generateDecoder( `; `; if (type.extends == null) { if (type.extends == null) { yield ` yield ` const instance = new this({ const instance = new this( id: "@id" in values ? new URL(values["@id"] as string) : undefined, { id: "@id" in values ? new URL(values["@id"] as string) : undefined }, }); { documentLoader: options?.documentLoader }, ); `; `; } else { } else { yield ` yield ` Loading codegen/constructor.ts +22 −8 Original line number Original line Diff line number Diff line Loading @@ -67,15 +67,23 @@ export async function* generateConstructor( /** /** * Constructs a new instance of ${type.name} with the given values. * Constructs a new instance of ${type.name} with the given values. * @param values The values to initialize the instance with. * @param values The values to initialize the instance with. * @param options The options to use for initialization. */ */ constructor(values: constructor( values: `; `; for await (const code of generateParametersType(typeUri, types)) yield code; for await (const code of generateParametersType(typeUri, types)) yield code; yield ") {\n"; yield `, { documentLoader }: { documentLoader?: DocumentLoader } = {}, ) { `; if (type.extends == null) { if (type.extends == null) { yield "this.id = values.id ?? null;"; yield ` this.#documentLoader = documentLoader; this.id = values.id ?? null; `; } else { } else { yield "super(values);"; yield "super(values, { documentLoader });"; } } for (const property of type.properties) { for (const property of type.properties) { const fieldName = await getFieldName(property.uri); const fieldName = await getFieldName(property.uri); Loading Loading @@ -121,19 +129,25 @@ export async function* generateCloner( /** /** * Clones this instance, optionally updating it with the given values. * Clones this instance, optionally updating it with the given values. * @param values The values to update the clone with. * @param values The values to update the clone with. * @options The options to use for cloning. * @returns The cloned instance. * @returns The cloned instance. */ */ clone(values: clone( values: `; `; for await (const code of generateParametersType(typeUri, types)) yield code; for await (const code of generateParametersType(typeUri, types)) yield code; yield ` = {}): ${type.name} {\n`; yield ` = {}, options: { documentLoader?: DocumentLoader } = {} ): ${type.name} { `; if (type.extends == null) { if (type.extends == null) { yield ` yield ` // @ts-ignore: this.constructor is not recognized as a constructor, but it is. // @ts-ignore: this.constructor is not recognized as a constructor, but it is. const clone: ${type.name} = new this.constructor({ id: values.id }); const clone: ${type.name} = new this.constructor({ id: values.id }, options); `; `; } else { } else { yield `const clone = super.clone(values) as unknown as ${type.name};`; yield `const clone = super.clone(values, options) as unknown as ${type.name};`; } } for (const property of type.properties) { for (const property of type.properties) { const fieldName = await getFieldName(property.uri); const fieldName = await getFieldName(property.uri); Loading Loading
CHANGES.md +11 −0 Original line number Original line Diff line number Diff line Loading @@ -13,6 +13,17 @@ Version 0.6.0 To be released. To be released. - `DocumentLoader` is now propagated to the loaded remote objects from Activity Vocabulary objects. [[#27]] - Added `options` parameter to Activity Vocabulary constructors. - Added `options` parameter to `clone()` method of Activity Vocabulary objects. - The Activity Vocabulary object passed to `InboxListener` now implicitly loads remote object with an authenticated `DocumentLoader`. [#27]: https://github.com/dahlia/fedify/issues/27 Version 0.5.0 Version 0.5.0 ------------- ------------- Loading
codegen/__snapshots__/class.test.ts.snap +1141 −1550 File changed.File size exceeds preview limit. View original file View changed file
codegen/class.ts +8 −1 Original line number Original line Diff line number Diff line Loading @@ -46,7 +46,14 @@ async function* generateClass( yield `export class ${type.name} {\n`; yield `export class ${type.name} {\n`; } } if (type.extends == null) { if (type.extends == null) { yield "readonly id: URL | null;\n"; yield ` readonly #documentLoader?: DocumentLoader; readonly id: URL | null; protected get _documentLoader(): DocumentLoader | undefined { return this.#documentLoader; } `; } } for await (const code of generateFields(typeUri, types)) yield code; for await (const code of generateFields(typeUri, types)) yield code; for await (const code of generateConstructor(typeUri, types)) yield code; for await (const code of generateConstructor(typeUri, types)) yield code; Loading
codegen/codec.ts +5 −4 Original line number Original line Diff line number Diff line Loading @@ -87,7 +87,7 @@ export async function* generateDecoder( */ */ static async fromJsonLd( static async fromJsonLd( json: unknown, json: unknown, options: { documentLoader?: DocumentLoader } = {} options: { documentLoader?: DocumentLoader } = {}, ): Promise<${type.name}> { ): Promise<${type.name}> { if (typeof json === "undefined") { if (typeof json === "undefined") { throw new TypeError("Invalid JSON-LD: undefined."); throw new TypeError("Invalid JSON-LD: undefined."); Loading Loading @@ -129,9 +129,10 @@ export async function* generateDecoder( `; `; if (type.extends == null) { if (type.extends == null) { yield ` yield ` const instance = new this({ const instance = new this( id: "@id" in values ? new URL(values["@id"] as string) : undefined, { id: "@id" in values ? new URL(values["@id"] as string) : undefined }, }); { documentLoader: options?.documentLoader }, ); `; `; } else { } else { yield ` yield ` Loading
codegen/constructor.ts +22 −8 Original line number Original line Diff line number Diff line Loading @@ -67,15 +67,23 @@ export async function* generateConstructor( /** /** * Constructs a new instance of ${type.name} with the given values. * Constructs a new instance of ${type.name} with the given values. * @param values The values to initialize the instance with. * @param values The values to initialize the instance with. * @param options The options to use for initialization. */ */ constructor(values: constructor( values: `; `; for await (const code of generateParametersType(typeUri, types)) yield code; for await (const code of generateParametersType(typeUri, types)) yield code; yield ") {\n"; yield `, { documentLoader }: { documentLoader?: DocumentLoader } = {}, ) { `; if (type.extends == null) { if (type.extends == null) { yield "this.id = values.id ?? null;"; yield ` this.#documentLoader = documentLoader; this.id = values.id ?? null; `; } else { } else { yield "super(values);"; yield "super(values, { documentLoader });"; } } for (const property of type.properties) { for (const property of type.properties) { const fieldName = await getFieldName(property.uri); const fieldName = await getFieldName(property.uri); Loading Loading @@ -121,19 +129,25 @@ export async function* generateCloner( /** /** * Clones this instance, optionally updating it with the given values. * Clones this instance, optionally updating it with the given values. * @param values The values to update the clone with. * @param values The values to update the clone with. * @options The options to use for cloning. * @returns The cloned instance. * @returns The cloned instance. */ */ clone(values: clone( values: `; `; for await (const code of generateParametersType(typeUri, types)) yield code; for await (const code of generateParametersType(typeUri, types)) yield code; yield ` = {}): ${type.name} {\n`; yield ` = {}, options: { documentLoader?: DocumentLoader } = {} ): ${type.name} { `; if (type.extends == null) { if (type.extends == null) { yield ` yield ` // @ts-ignore: this.constructor is not recognized as a constructor, but it is. // @ts-ignore: this.constructor is not recognized as a constructor, but it is. const clone: ${type.name} = new this.constructor({ id: values.id }); const clone: ${type.name} = new this.constructor({ id: values.id }, options); `; `; } else { } else { yield `const clone = super.clone(values) as unknown as ${type.name};`; yield `const clone = super.clone(values, options) as unknown as ${type.name};`; } } for (const property of type.properties) { for (const property of type.properties) { const fieldName = await getFieldName(property.uri); const fieldName = await getFieldName(property.uri); Loading