@fedify/vocab-tools 2.4.0-dev.2035 → 2.4.0-dev.2047

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
@@ -18,6 +18,10 @@ const INTERNAL_RUNTIME_IMPORTS = [
18
18
  "isTrustedIriOrigin",
19
19
  "normalizeJsonLdIris",
20
20
  ].join(",\n ");
21
+ const PORTABLE_DEREFERENCE_IMPORTS = [
22
+ "dereferencePortableIri",
23
+ "isPortableIri",
24
+ ].join(",\n ");
21
25
  const SIGNED_REPRESENTATION_IMPORTS = [
22
26
  "enterSignedValueScope",
23
27
  "resolveSignedValues",
@@ -42,6 +46,7 @@ const RUNTIME_IMPORTS = [
42
46
  "parseGatewayUrl",
43
47
  "parseIri",
44
48
  "parseJsonLdId",
49
+ "type PortableObjectVerifier",
45
50
  "type RemoteDocument",
46
51
  ].join(",\n ");
47
52
 
@@ -273,6 +278,7 @@ export async function* generateClasses(
273
278
  from "@opentelemetry/api";\n`;
274
279
  yield `import {\n ${RUNTIME_IMPORTS}\n} from "@fedify/vocab-runtime";\n`;
275
280
  yield `import {\n ${INTERNAL_RUNTIME_IMPORTS}\n} from "@fedify/vocab-runtime/internal/jsonld-cache";\n`;
281
+ yield `import {\n ${PORTABLE_DEREFERENCE_IMPORTS}\n} from "@fedify/vocab-runtime/internal/portable-dereference";\n`;
276
282
  yield `import {\n ${SIGNED_REPRESENTATION_IMPORTS}\n} from "@fedify/vocab-runtime/internal/signed-representation";\n`;
277
283
  yield `import {
278
284
  isTemporalDuration,
package/src/property.ts CHANGED
@@ -74,6 +74,8 @@ async function* generateProperty(
74
74
  suppressError?: boolean,
75
75
  tracerProvider?: TracerProvider,
76
76
  crossOrigin?: "ignore" | "throw" | "trust";
77
+ gateways?: readonly (string | URL)[];
78
+ verifyPortableObject?: PortableObjectVerifier;
77
79
  } = {},
78
80
  ): Promise<${getTypeNames(property.range, types)} | null> {
79
81
  const documentLoader =
@@ -87,6 +89,44 @@ async function* generateProperty(
87
89
  ${JSON.stringify(metadata.version)},
88
90
  );
89
91
  return await tracer.startActiveSpan("activitypub.lookup_object", async (span) => {
92
+ if (isPortableIri(url)) {
93
+ try {
94
+ const obj = await dereferencePortableIri(url, {
95
+ documentLoader,
96
+ contextLoader,
97
+ tracerProvider,
98
+ gateways: options.gateways,
99
+ verifyPortableObject: options.verifyPortableObject,
100
+ suppressError: options.suppressError,
101
+ crossOrigin: options.crossOrigin,
102
+ span,
103
+ parse: (document, parseOptions) =>
104
+ this.#${property.singularName}_fromJsonLd(document, {
105
+ documentLoader,
106
+ contextLoader: parseOptions.contextLoader,
107
+ tracerProvider,
108
+ baseUrl: parseOptions.baseUrl,
109
+ }),
110
+ });
111
+ if (obj != null) {
112
+ span.setAttribute("activitypub.object.id", (obj.id ?? url).href);
113
+ span.setAttribute(
114
+ "activitypub.object.type",
115
+ // @ts-ignore: obj.constructor always has a typeId.
116
+ obj.constructor.typeId.href
117
+ );
118
+ }
119
+ return obj;
120
+ } catch (e) {
121
+ span.setStatus({
122
+ code: SpanStatusCode.ERROR,
123
+ message: String(e),
124
+ });
125
+ throw e;
126
+ } finally {
127
+ span.end();
128
+ }
129
+ }
90
130
  const lookupUrl = formatIri(url);
91
131
  let fetchResult: RemoteDocument;
92
132
  try {
@@ -266,6 +306,8 @@ async function* generateProperty(
266
306
  suppressError?: boolean,
267
307
  tracerProvider?: TracerProvider,
268
308
  crossOrigin?: "ignore" | "throw" | "trust";
309
+ gateways?: readonly (string | URL)[];
310
+ verifyPortableObject?: PortableObjectVerifier;
269
311
  } = {}
270
312
  ): Promise<${getTypeNames(property.range, types)} | null> {
271
313
  if (this._warning != null) {
@@ -381,6 +423,8 @@ async function* generateProperty(
381
423
  suppressError?: boolean,
382
424
  tracerProvider?: TracerProvider,
383
425
  crossOrigin?: "ignore" | "throw" | "trust";
426
+ gateways?: readonly (string | URL)[];
427
+ verifyPortableObject?: PortableObjectVerifier;
384
428
  } = {}
385
429
  ): AsyncIterable<${getTypeNames(property.range, types)}> {
386
430
  if (this._warning != null) {