@fedify/vocab-tools 2.4.0-dev.2010 → 2.4.0-dev.2027

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,11 @@ const INTERNAL_RUNTIME_IMPORTS = [
18
18
  "isTrustedIriOrigin",
19
19
  "normalizeJsonLdIris",
20
20
  ].join(",\n ");
21
+ const SIGNED_REPRESENTATION_IMPORTS = [
22
+ "enterSignedValueScope",
23
+ "resolveSignedValues",
24
+ "retainedSignedValueRef",
25
+ ].join(",\n ");
21
26
  const RUNTIME_IMPORTS = [
22
27
  "canParseDecimal",
23
28
  "decodeMultibase",
@@ -268,6 +273,7 @@ export async function* generateClasses(
268
273
  from "@opentelemetry/api";\n`;
269
274
  yield `import {\n ${RUNTIME_IMPORTS}\n} from "@fedify/vocab-runtime";\n`;
270
275
  yield `import {\n ${INTERNAL_RUNTIME_IMPORTS}\n} from "@fedify/vocab-runtime/internal/jsonld-cache";\n`;
276
+ yield `import {\n ${SIGNED_REPRESENTATION_IMPORTS}\n} from "@fedify/vocab-runtime/internal/signed-representation";\n`;
271
277
  yield `import {
272
278
  isTemporalDuration,
273
279
  isTemporalInstant,
package/src/codec.ts CHANGED
@@ -95,6 +95,10 @@ export async function* generateEncoder(
95
95
  ...options,
96
96
  contextLoader: options.contextLoader ?? getDocumentLoader(),
97
97
  };
98
+ // Joins the enclosing frame's signed-value scope, or starts one when this
99
+ // frame is the outermost. Only the owning frame puts retained signed
100
+ // child documents back in place of their placeholders.
101
+ const signedValues = enterSignedValueScope(options);
98
102
  `;
99
103
  if (isCompactableType(typeUri, types)) {
100
104
  yield `
@@ -127,6 +131,7 @@ export async function* generateEncoder(
127
131
  const item = (
128
132
  `;
129
133
  if (!areAllScalarTypes(property.range, types)) {
134
+ yield "retainedSignedValueRef(v, signedValues.scope) ?? (";
130
135
  yield "v instanceof URL ? formatIri(v) : ";
131
136
  }
132
137
  const encoders = getEncoders(
@@ -137,6 +142,7 @@ export async function* generateEncoder(
137
142
  true,
138
143
  );
139
144
  for (const code of encoders) yield code;
145
+ if (!areAllScalarTypes(property.range, types)) yield ")";
140
146
  yield `
141
147
  );
142
148
  compactItems.push(item);
@@ -180,7 +186,9 @@ export async function* generateEncoder(
180
186
  }
181
187
  if (this.id != null) result["id"] = formatIri(this.id);
182
188
  result["@context"] = ${JSON.stringify(type.defaultContext)};
183
- return result;
189
+ return signedValues.owner
190
+ ? resolveSignedValues(result, signedValues.scope)
191
+ : result;
184
192
  }
185
193
  `;
186
194
  }
@@ -210,11 +218,13 @@ export async function* generateEncoder(
210
218
  let element = (
211
219
  `;
212
220
  if (!areAllScalarTypes(property.range, types)) {
221
+ yield "retainedSignedValueRef(v, signedValues.scope) ?? (";
213
222
  yield 'v instanceof URL ? { "@id": formatIri(v) } : ';
214
223
  }
215
224
  for (const code of getEncoders(property.range, types, "v", "options")) {
216
225
  yield code;
217
226
  }
227
+ if (!areAllScalarTypes(property.range, types)) yield ")";
218
228
  yield `
219
229
  );
220
230
  if (Array.isArray(element)) {
@@ -325,7 +335,9 @@ export async function* generateEncoder(
325
335
  }
326
336
  yield `
327
337
  }
328
- return compacted;
338
+ return signedValues.owner
339
+ ? resolveSignedValues(compacted, signedValues.scope)
340
+ : compacted;
329
341
  }
330
342
 
331
343
  protected ${emitOverride(typeUri, types)} isCompactable(): boolean {
@@ -208,6 +208,13 @@ export async function* generateCloner(
208
208
  yield `
209
209
  /**
210
210
  * Clones this instance, optionally updating it with the given values.
211
+ *
212
+ * A clone never inherits a signed JSON-LD representation retained by
213
+ * \`signObject()\`: the clone may differ from the document that the proof
214
+ * covers, so embedding the original secured JSON in a parent document
215
+ * would be wrong. Sign the clone again if it has to be embedded as a
216
+ * secured child.
217
+ *
211
218
  * @param values The values to update the clone with.
212
219
  * @param options The options to use for cloning.
213
220
  * @returns The cloned instance.