Skip to main content
This release is 23 versions behind 1.4.9 — the latest version of @fedify/fedify. Jump to latest

Built and signed on GitHub Actions

An ActivityPub/fediverse server framework

This package works with Node.js, Deno, Bun
This package works with Node.js
This package works with Deno
This package works with Bun
JSR Score
94%
Published
3 months ago (1.3.3)
Package root>codegen>inspector.ts
import { 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); } `; }