Loading src/codegen/__snapshots__/class.test.ts.snap +855 −855 File changed.Preview size limit exceeded, changes collapsed. Show changes src/codegen/class.ts +2 −1 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ import { generateFields } from "./field.ts"; import { generateInspector } from "./inspector.ts"; import { generateProperties } from "./property.ts"; import type { TypeSchema } from "./schema.ts"; import { emitOverride } from "./type.ts"; /** * Sorts the given types topologically so that the base types come before the Loading Loading @@ -66,7 +67,7 @@ async function* generateClass( /** * The type URI of {@link ${type.name}}: \`${typeUri}\`. */ static get typeId(): URL { static ${emitOverride(typeUri, types)} get typeId(): URL { return new URL(${JSON.stringify(typeUri)}); } `; Loading src/codegen/codec.ts +4 −3 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ import { generateField, getFieldName } from "./field.ts"; import type { TypeSchema } from "./schema.ts"; import { areAllScalarTypes, emitOverride, getAllProperties, getDecoder, getDecoders, Loading @@ -26,7 +27,7 @@ export async function* generateEncoder( when \`format\` is set to \`'expand'\`. * @returns The JSON-LD representation of this object. */ async toJsonLd(options: { ${emitOverride(typeUri, types)} async toJsonLd(options: { format?: "compact" | "expand", contextLoader?: DocumentLoader, context?: string | Record<string, string> | (string | Record<string, string>)[], Loading Loading @@ -240,7 +241,7 @@ export async function* generateEncoder( return compacted; } protected isCompactable(): boolean { protected ${emitOverride(typeUri, types)} isCompactable(): boolean { `; for (const property of type.properties) { if (!property.range.every((r) => isCompactableType(r, types))) { Loading Loading @@ -270,7 +271,7 @@ export async function* generateDecoder( * @returns The object of this type. * @throws {TypeError} If the given \`json\` is invalid. */ static async fromJsonLd( static ${emitOverride(typeUri, types)} async fromJsonLd( json: unknown, options: { documentLoader?: DocumentLoader, Loading src/codegen/constructor.ts +7 −2 Original line number Diff line number Diff line import { getFieldName } from "./field.ts"; import type { PropertySchema, TypeSchema } from "./schema.ts"; import { areAllScalarTypes, getTypeGuards, getTypeNames } from "./type.ts"; import { areAllScalarTypes, emitOverride, getTypeGuards, getTypeNames, } from "./type.ts"; function generateParameterType( property: PropertySchema, Loading Loading @@ -184,7 +189,7 @@ export async function* generateCloner( * @options The options to use for cloning. * @returns The cloned instance. */ clone( ${emitOverride(typeUri, types)} clone( values: `; for await (const code of generateParametersType(typeUri, types)) yield code; Loading src/codegen/inspector.ts +6 −3 Original line number Diff line number Diff line import { getFieldName } from "./field.ts"; import type { TypeSchema } from "./schema.ts"; import { emitOverride } from "./type.ts"; export async function* generateInspector( typeUri: string, Loading @@ -7,7 +8,9 @@ export async function* generateInspector( ): AsyncIterable<string> { const type = types[typeUri]; yield ` protected _getCustomInspectProxy(): Record<string, unknown> { protected ${ emitOverride(typeUri, types) } _getCustomInspectProxy(): Record<string, unknown> { `; if (type.extends == null) { yield ` Loading Loading @@ -70,7 +73,7 @@ export async function* generateInspector( return proxy; } [Symbol.for("Deno.customInspect")]( ${emitOverride(typeUri, types)} [Symbol.for("Deno.customInspect")]( inspect: typeof Deno.inspect, options: Deno.InspectOptions, ): string { Loading @@ -78,7 +81,7 @@ export async function* generateInspector( return ${JSON.stringify(type.name + " ")} + inspect(proxy, options); } [Symbol.for("nodejs.util.inspect.custom")]( ${emitOverride(typeUri, types)} [Symbol.for("nodejs.util.inspect.custom")]( _depth: number, options: unknown, inspect: (value: unknown, options: unknown) => string, Loading Loading
src/codegen/__snapshots__/class.test.ts.snap +855 −855 File changed.Preview size limit exceeded, changes collapsed. Show changes
src/codegen/class.ts +2 −1 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ import { generateFields } from "./field.ts"; import { generateInspector } from "./inspector.ts"; import { generateProperties } from "./property.ts"; import type { TypeSchema } from "./schema.ts"; import { emitOverride } from "./type.ts"; /** * Sorts the given types topologically so that the base types come before the Loading Loading @@ -66,7 +67,7 @@ async function* generateClass( /** * The type URI of {@link ${type.name}}: \`${typeUri}\`. */ static get typeId(): URL { static ${emitOverride(typeUri, types)} get typeId(): URL { return new URL(${JSON.stringify(typeUri)}); } `; Loading
src/codegen/codec.ts +4 −3 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ import { generateField, getFieldName } from "./field.ts"; import type { TypeSchema } from "./schema.ts"; import { areAllScalarTypes, emitOverride, getAllProperties, getDecoder, getDecoders, Loading @@ -26,7 +27,7 @@ export async function* generateEncoder( when \`format\` is set to \`'expand'\`. * @returns The JSON-LD representation of this object. */ async toJsonLd(options: { ${emitOverride(typeUri, types)} async toJsonLd(options: { format?: "compact" | "expand", contextLoader?: DocumentLoader, context?: string | Record<string, string> | (string | Record<string, string>)[], Loading Loading @@ -240,7 +241,7 @@ export async function* generateEncoder( return compacted; } protected isCompactable(): boolean { protected ${emitOverride(typeUri, types)} isCompactable(): boolean { `; for (const property of type.properties) { if (!property.range.every((r) => isCompactableType(r, types))) { Loading Loading @@ -270,7 +271,7 @@ export async function* generateDecoder( * @returns The object of this type. * @throws {TypeError} If the given \`json\` is invalid. */ static async fromJsonLd( static ${emitOverride(typeUri, types)} async fromJsonLd( json: unknown, options: { documentLoader?: DocumentLoader, Loading
src/codegen/constructor.ts +7 −2 Original line number Diff line number Diff line import { getFieldName } from "./field.ts"; import type { PropertySchema, TypeSchema } from "./schema.ts"; import { areAllScalarTypes, getTypeGuards, getTypeNames } from "./type.ts"; import { areAllScalarTypes, emitOverride, getTypeGuards, getTypeNames, } from "./type.ts"; function generateParameterType( property: PropertySchema, Loading Loading @@ -184,7 +189,7 @@ export async function* generateCloner( * @options The options to use for cloning. * @returns The cloned instance. */ clone( ${emitOverride(typeUri, types)} clone( values: `; for await (const code of generateParametersType(typeUri, types)) yield code; Loading
src/codegen/inspector.ts +6 −3 Original line number Diff line number Diff line import { getFieldName } from "./field.ts"; import type { TypeSchema } from "./schema.ts"; import { emitOverride } from "./type.ts"; export async function* generateInspector( typeUri: string, Loading @@ -7,7 +8,9 @@ export async function* generateInspector( ): AsyncIterable<string> { const type = types[typeUri]; yield ` protected _getCustomInspectProxy(): Record<string, unknown> { protected ${ emitOverride(typeUri, types) } _getCustomInspectProxy(): Record<string, unknown> { `; if (type.extends == null) { yield ` Loading Loading @@ -70,7 +73,7 @@ export async function* generateInspector( return proxy; } [Symbol.for("Deno.customInspect")]( ${emitOverride(typeUri, types)} [Symbol.for("Deno.customInspect")]( inspect: typeof Deno.inspect, options: Deno.InspectOptions, ): string { Loading @@ -78,7 +81,7 @@ export async function* generateInspector( return ${JSON.stringify(type.name + " ")} + inspect(proxy, options); } [Symbol.for("nodejs.util.inspect.custom")]( ${emitOverride(typeUri, types)} [Symbol.for("nodejs.util.inspect.custom")]( _depth: number, options: unknown, inspect: (value: unknown, options: unknown) => string, Loading