@fedify/vocab-tools 2.4.0-dev.2247 → 2.4.0-dev.2256

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/class.ts CHANGED
@@ -16,6 +16,7 @@ const INTERNAL_RUNTIME_IMPORTS = [
16
16
  "compactJsonLdCache",
17
17
  "createScopedContextLoader",
18
18
  "getJsonLdContext",
19
+ "getPortableActorGateways",
19
20
  "isTrustedIriOrigin",
20
21
  "normalizeJsonLdIris",
21
22
  ].join(",\n ");
@@ -313,6 +314,12 @@ function decodeIri(iri: string): URL {
313
314
  ? new URL("at://" + encodeURIComponent(iri.substring(5)))
314
315
  : parseIri(iri);
315
316
  }
317
+
318
+ function inspectIri(iri: URL): string {
319
+ // Inspecting an object must not throw, even for a URL that cannot be
320
+ // formatted as an IRI, e.g., a malformed portable ID:
321
+ try { return formatIri(iri); } catch { return iri.href; }
322
+ }
316
323
  `;
317
324
  yield `
318
325
  function isValidLanguageTag(language: string): boolean {
package/src/codec.ts CHANGED
@@ -538,8 +538,11 @@ export async function* generateDecoder(
538
538
  const variable = await getFieldName(property.uri, "");
539
539
  yield await generateField(property, types, "const ");
540
540
  const arrayVariable = `${variable}__array`;
541
+ const propertyValues = property.uri === "https://w3id.org/fep/ef61/gateways"
542
+ ? "getPortableActorGateways(values) as typeof values[string]"
543
+ : `values[${JSON.stringify(property.uri)}]`;
541
544
  yield `
542
- let ${arrayVariable} = values[${JSON.stringify(property.uri)}];
545
+ let ${arrayVariable} = ${propertyValues};
543
546
  `;
544
547
  if (property.functional && property.redundantProperties != null) {
545
548
  for (const prop of property.redundantProperties) {
package/src/inspector.ts CHANGED
@@ -21,12 +21,12 @@ export async function* generateInspector(
21
21
  [Symbol.for("Deno.customInspect")]: (
22
22
  inspect: typeof Deno.inspect,
23
23
  options: Deno.InspectOptions,
24
- ): string => "URL " + inspect(this.id!.href, options),
24
+ ): string => "URL " + inspect(inspectIri(this.id!), options),
25
25
  [Symbol.for("nodejs.util.inspect.custom")]: (
26
26
  _depth: number,
27
27
  options: unknown,
28
28
  inspect: (value: unknown, options: unknown) => string,
29
- ): string => "URL " + inspect(this.id!.href, options),
29
+ ): string => "URL " + inspect(inspectIri(this.id!), options),
30
30
  };
31
31
  }
32
32
  `;
@@ -44,12 +44,12 @@ export async function* generateInspector(
44
44
  [Symbol.for("Deno.customInspect")]: (
45
45
  inspect: typeof Deno.inspect,
46
46
  options: Deno.InspectOptions,
47
- ): string => "URL " + inspect(v.href, options),
47
+ ): string => "URL " + inspect(inspectIri(v), options),
48
48
  [Symbol.for("nodejs.util.inspect.custom")]: (
49
49
  _depth: number,
50
50
  options: unknown,
51
51
  inspect: (value: unknown, options: unknown) => string,
52
- ): string => "URL " + inspect(v.href, options),
52
+ ): string => "URL " + inspect(inspectIri(v), options),
53
53
  }
54
54
  : v);
55
55
  `;
package/src/type.ts CHANGED
@@ -340,10 +340,10 @@ const scalarTypes: Record<string, ScalarType> = {
340
340
  return `${v} instanceof URL && isGatewayUrl(${v})`;
341
341
  },
342
342
  encoder(v) {
343
- return `{ "@id": formatIri(${v}) }`;
343
+ return `{ "@id": ${v}.origin }`;
344
344
  },
345
345
  compactEncoder(v) {
346
- return `formatIri(${v})`;
346
+ return `${v}.origin`;
347
347
  },
348
348
  dataCheck(v) {
349
349
  return `${v} != null && typeof ${v} === "object" &&