This release is 23 versions behind 1.4.9 — the latest version of @fedify/fedify. Jump to latest
Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
An ActivityPub/fediverse server framework
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293import { getFieldName } from "./field.ts"; import type { TypeSchema } from "./schema.ts"; import { emitOverride } from "./type.ts"; export async function* generateInspector( typeUri: string, types: Record<string, TypeSchema>, ): AsyncIterable<string> { const type = types[typeUri]; yield ` protected ${ emitOverride(typeUri, types) } _getCustomInspectProxy(): Record<string, unknown> { `; if (type.extends == null) { yield ` const proxy: Record<string, unknown> = {}; if (this.id != null) { proxy.id = { [Symbol.for("Deno.customInspect")]: ( inspect: typeof Deno.inspect, options: Deno.InspectOptions, ): string => "URL " + inspect(this.id!.href, options), [Symbol.for("nodejs.util.inspect.custom")]: ( _depth: number, options: unknown, inspect: (value: unknown, options: unknown) => string, ): string => "URL " + inspect(this.id!.href, options), }; } `; } else { yield "const proxy: Record<string, unknown> = super._getCustomInspectProxy();"; } for (const property of type.properties) { const fieldName = await getFieldName(property.uri); const localName = await getFieldName(property.uri, ""); yield ` const ${localName} = this.${fieldName} // deno-lint-ignore no-explicit-any .map((v: any) => v instanceof URL ? { [Symbol.for("Deno.customInspect")]: ( inspect: typeof Deno.inspect, options: Deno.InspectOptions, ): string => "URL " + inspect(v.href, options), [Symbol.for("nodejs.util.inspect.custom")]: ( _depth: number, options: unknown, inspect: (value: unknown, options: unknown) => string, ): string => "URL " + inspect(v.href, options), } : v); `; if (property.functional || property.singularAccessor) { yield ` if (${localName}.length == 1) { proxy.${property.singularName} = ${localName}[0]; } `; } if (!property.functional) { yield ` if (${localName}.length > 1 || !(${JSON.stringify(property.singularName)} in proxy) && ${localName}.length > 0) { proxy.${property.pluralName} = ${localName}; } `; } } yield ` return proxy; } ${emitOverride(typeUri, types)} [Symbol.for("Deno.customInspect")]( inspect: typeof Deno.inspect, options: Deno.InspectOptions, ): string { const proxy = this._getCustomInspectProxy(); return ${JSON.stringify(type.name + " ")} + inspect(proxy, options); } ${emitOverride(typeUri, types)} [Symbol.for("nodejs.util.inspect.custom")]( _depth: number, options: unknown, inspect: (value: unknown, options: unknown) => string, ): string { const proxy = this._getCustomInspectProxy(); return ${JSON.stringify(type.name + " ")} + inspect(proxy, options); } `; }