@fedify/vocab-tools 2.5.0-dev.2687 → 2.5.0-dev.2710

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.
@@ -1,467 +0,0 @@
1
- import { getFieldName } from "./field.ts";
2
- import { hasSingularAccessor, isNonFunctionalProperty } from "./schema.ts";
3
- import type { PropertySchema, TypeSchema } from "./schema.ts";
4
- import {
5
- areAllScalarTypes,
6
- emitOverride,
7
- getTypeGuards,
8
- getTypeNames,
9
- } from "./type.ts";
10
-
11
- function generateParameterType(
12
- property: PropertySchema,
13
- types: Record<string, TypeSchema>,
14
- ): string {
15
- const range = property.range;
16
- const scalar = areAllScalarTypes(range, types);
17
- const code: string[] = [];
18
- if (hasSingularAccessor(property)) {
19
- if (scalar) {
20
- code.push(
21
- `${property.singularName}?: ${getTypeNames(range, types)} | null;`,
22
- );
23
- } else {
24
- code.push(
25
- `${property.singularName}?: ${getTypeNames(
26
- range,
27
- types,
28
- )} | URL | null;`,
29
- );
30
- }
31
- }
32
- if (isNonFunctionalProperty(property)) {
33
- if (scalar) {
34
- code.push(
35
- `${property.pluralName}?: (${getTypeNames(range, types, true)})[];`,
36
- );
37
- } else {
38
- code.push(
39
- `${property.pluralName}?: (${getTypeNames(range, types)} | URL)[];`,
40
- );
41
- }
42
- }
43
- return code.join("\n");
44
- }
45
-
46
- async function* generateParametersType(
47
- typeUri: string,
48
- types: Record<string, TypeSchema>,
49
- parentheses = true,
50
- excludeProperties: string[] = [],
51
- ): AsyncIterable<string> {
52
- const type = types[typeUri];
53
- if (parentheses) yield "{\n";
54
- if (type.extends == null) {
55
- yield `id?: URL | null;\n`;
56
- } else {
57
- for await (const code of generateParametersType(
58
- type.extends,
59
- types,
60
- false,
61
- [...excludeProperties, ...type.properties.map((p) => p.singularName)],
62
- )) {
63
- yield code;
64
- }
65
- }
66
- for (const property of type.properties) {
67
- if (excludeProperties.includes(property.singularName)) continue;
68
- yield generateParameterType(property, types);
69
- }
70
- if (parentheses) yield "}\n";
71
- }
72
-
73
- function generateValidatedArrayCopy(
74
- name: string,
75
- typeNames: string,
76
- typeGuards: string,
77
- ): string {
78
- return (
79
- `
80
- let copied!: (${typeNames})[];
81
- let valid = false;
82
- if (Array.isArray(values.${name})) {
83
- const array = values.${name};
84
- const test = (v: ${typeNames}): boolean => ${typeGuards};
85
- let checked: VocabArrayValidation | undefined;
86
- if (array.length < vocabSparseArrayMinimumLength
87
- ? array.every(test)
88
- : (checked = vocabValidatePropertyArray(array, test)).valid) {
89
- const input = values.${name};
90
- if (input.length < vocabSparseArrayMinimumLength && !checked?.sparse) {
91
- copied = input.slice();
92
- valid = true;
93
- } else {
94
- const result = vocabCopyValidatedPropertyArray(
95
- input, test, checked ?? { valid: true, sparse: false },
96
- );
97
- if (result.ok) {
98
- copied = result.array;
99
- valid = true;
100
- }
101
- }
102
- }
103
- }
104
- if (valid) {
105
- `.trimEnd() + "\n"
106
- );
107
- }
108
-
109
- export async function* generateConstructor(
110
- typeUri: string,
111
- types: Record<string, TypeSchema>,
112
- ): AsyncIterable<string> {
113
- const type = types[typeUri];
114
- yield `
115
- /**
116
- * Constructs a new instance of ${type.name} with the given values.
117
- * @param values The values to initialize the instance with.
118
- * @param options The options to use for initialization.
119
- */
120
- constructor(
121
- values:
122
- `;
123
- for await (const code of generateParametersType(typeUri, types)) yield code;
124
- yield `,
125
- options: {
126
- documentLoader?: DocumentLoader,
127
- contextLoader?: DocumentLoader,
128
- tracerProvider?: TracerProvider,
129
- verifyPortableObject?: PortableObjectVerifier,
130
- } = {},
131
- ) {
132
- `;
133
- if (type.extends == null) {
134
- yield `
135
- this.#documentLoader = options.documentLoader;
136
- this.#contextLoader = options.contextLoader;
137
- this.#tracerProvider = options.tracerProvider;
138
- this.#verifyPortableObject = options.verifyPortableObject;
139
- const baseUrl = (options as { baseUrl?: URL }).baseUrl;
140
- this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href);
141
- if ("$warning" in options) {
142
- this.#warning = options.$warning as unknown as {
143
- category: string[];
144
- message: string;
145
- values?: Record<string, unknown>;
146
- };
147
- }
148
- if (values.id == null || values.id instanceof URL) {
149
- this.id = values.id ?? null;
150
- } else {
151
- throw new TypeError("The id must be a URL.");
152
- }
153
- `;
154
- } else {
155
- yield "super(values, options);";
156
- }
157
- for (const property of type.properties) {
158
- const fieldName = await getFieldName(property.uri);
159
- const trustFieldName = await getFieldName(property.uri, "#_trust");
160
- const allScalarTypes = areAllScalarTypes(property.range, types);
161
- if (hasSingularAccessor(property)) {
162
- let typeGuards = getTypeGuards(
163
- property.range,
164
- types,
165
- `values.${property.singularName}`,
166
- );
167
- let typeNames = getTypeNames(property.range, types);
168
- const scalar = areAllScalarTypes(property.range, types);
169
- if (!scalar) {
170
- typeGuards = `${typeGuards} || values.${property.singularName} instanceof URL`;
171
- typeNames = `${typeNames} | URL`;
172
- }
173
- yield `
174
- if ("${property.singularName}" in values && \
175
- values.${property.singularName} != null) {
176
- if (${typeGuards}) {
177
- // @ts-ignore: type is checked above.
178
- this.${fieldName} = [values.${property.singularName}];
179
- `;
180
- if (!allScalarTypes) yield `this.${trustFieldName}.add(0);`;
181
- yield `
182
- } else {
183
- throw new TypeError(
184
- "The ${property.singularName} must be of type " +
185
- ${JSON.stringify(typeNames)} + ".",
186
- );
187
- }
188
- }
189
- `;
190
- }
191
- if (isNonFunctionalProperty(property)) {
192
- let typeGuards = getTypeGuards(property.range, types, `v`);
193
- let typeNames = getTypeNames(property.range, types);
194
- const scalar = areAllScalarTypes(property.range, types);
195
- if (!scalar) {
196
- typeGuards = `${typeGuards} || v instanceof URL`;
197
- typeNames = `${typeNames} | URL`;
198
- }
199
- yield `
200
- if ("${property.pluralName}" in values && \
201
- values.${property.pluralName} != null) {
202
- `;
203
- if (property && property.singularAccessor) {
204
- yield `
205
- if ("${property.singularName}" in values &&
206
- values.${property.singularName} != null) {
207
- throw new TypeError(
208
- "Cannot initialize both ${property.singularName} and " +
209
- "${property.pluralName} at the same time.",
210
- );
211
- }
212
- `;
213
- }
214
- yield generateValidatedArrayCopy(
215
- property.pluralName,
216
- typeNames,
217
- typeGuards,
218
- );
219
- yield `
220
- // @ts-ignore: type is checked above.
221
- this.${fieldName} = copied;
222
- `;
223
- if (!allScalarTypes) {
224
- yield `
225
- vocabSetTrustPrefix(this.${trustFieldName}, this.${fieldName}.length);
226
- `;
227
- }
228
- yield `
229
- } else {
230
- throw new TypeError(
231
- "The ${property.pluralName} must be an array of type " +
232
- ${JSON.stringify(typeNames)} + ".",
233
- );
234
- }
235
- }
236
- `;
237
- }
238
- }
239
- yield "}\n";
240
- }
241
-
242
- export async function* generateCloner(
243
- typeUri: string,
244
- types: Record<string, TypeSchema>,
245
- ): AsyncIterable<string> {
246
- const type = types[typeUri];
247
- yield `
248
- /**
249
- * Clones this instance, optionally updating it with the given values.
250
- *
251
- * This is a shallow copy: property arrays are copied, but nested objects
252
- * and URLs are shared with this instance. Dereferencing accessors can cache
253
- * fetched objects in the instance whose accessor is called. Hydrating a
254
- * shared nested object through the clone can affect the original as well,
255
- * and can change JSON-LD output when either is embedded in another
256
- * object. Hydrating a top-level property of the clone does not update this
257
- * instance's property.
258
- *
259
- * To resolve properties without sharing nested objects, use
260
- * {@link ${type.name}.deepClone} before hydration.
261
- * See the [vocabulary manual](https://fedify.dev/manual/vocab#immutability)
262
- * for details, including how cached JSON-LD affects serialization.
263
- *
264
- * A clone never inherits a signed JSON-LD representation retained by
265
- * \`signObject()\`: the clone may differ from the document that the proof
266
- * covers, so embedding the original secured JSON in a parent document
267
- * would be wrong. Sign the clone again if it has to be embedded as a
268
- * secured child.
269
- *
270
- * @param values The values to update the clone with.
271
- * @param options The options to use for cloning.
272
- * @returns The cloned instance with its own property arrays. Nested objects
273
- * and URLs are shared with this instance.
274
- */
275
- ${emitOverride(typeUri, types)} clone(
276
- values:
277
- `;
278
- for await (const code of generateParametersType(typeUri, types)) yield code;
279
- yield `
280
- = {},
281
- options: {
282
- documentLoader?: DocumentLoader,
283
- contextLoader?: DocumentLoader,
284
- verifyPortableObject?: PortableObjectVerifier,
285
- } = {}
286
- ): ${type.name} {
287
- if (this._warning != null) {
288
- getLogger(this._warning.category).warn(
289
- this._warning.message,
290
- this._warning.values
291
- );
292
- // @ts-ignore: $warning is not recognized as a property, but it is.
293
- options = { ...options, $warning: this._warning };
294
- }
295
- `;
296
- if (type.extends == null) {
297
- yield `
298
- // @ts-ignore: this.constructor is not recognized as a constructor, but it is.
299
- const clone: ${type.name} = new this.constructor(
300
- { id: values.id ?? this.id },
301
- options
302
- );
303
- copyPortableProvenance(this, clone);
304
- `;
305
- } else {
306
- yield `const clone = super.clone(values, options) as unknown as ${type.name};`;
307
- }
308
- for (const property of type.properties) {
309
- const fieldName = await getFieldName(property.uri);
310
- const trustFieldName = await getFieldName(property.uri, "#_trust");
311
- const allScalarTypes = areAllScalarTypes(property.range, types);
312
- yield `clone.${fieldName} = this.${fieldName}.length < vocabSparseArrayMinimumLength
313
- ? this.${fieldName}.slice() : vocabCopyPropertyArray(this.${fieldName});`;
314
- if (!allScalarTypes) {
315
- yield `clone.${trustFieldName} = vocabCopyTrustSet(
316
- this.${trustFieldName}, clone.${trustFieldName},
317
- );`;
318
- }
319
- if (hasSingularAccessor(property)) {
320
- let typeGuards = getTypeGuards(
321
- property.range,
322
- types,
323
- `values.${property.singularName}`,
324
- );
325
- let typeNames = getTypeNames(property.range, types);
326
- const scalar = areAllScalarTypes(property.range, types);
327
- if (!scalar) {
328
- typeGuards = `${typeGuards} || values.${property.singularName} instanceof URL`;
329
- typeNames = `${typeNames} | URL`;
330
- }
331
- yield `
332
- if ("${property.singularName}" in values && \
333
- values.${property.singularName} != null) {
334
- if (${typeGuards}) {
335
- // @ts-ignore: type is checked above.
336
- clone.${fieldName} = [values.${property.singularName}];
337
- `;
338
- if (!allScalarTypes) {
339
- yield `clone.${trustFieldName} = new Set();
340
- clone.${trustFieldName}[vocabTrustPrefix] = 1;`;
341
- }
342
- yield `
343
- } else {
344
- throw new TypeError(
345
- "The ${property.singularName} must be of type " +
346
- ${JSON.stringify(typeNames)} + ".",
347
- );
348
- }
349
- }
350
- `;
351
- }
352
- if (isNonFunctionalProperty(property)) {
353
- let typeGuards = getTypeGuards(property.range, types, `v`);
354
- let typeNames = getTypeNames(property.range, types);
355
- const scalar = areAllScalarTypes(property.range, types);
356
- if (!scalar) {
357
- typeGuards = `${typeGuards} || v instanceof URL`;
358
- typeNames = `${typeNames} | URL`;
359
- }
360
- yield `
361
- if ("${property.pluralName}" in values && \
362
- values.${property.pluralName} != null) {
363
- `;
364
- if (property.singularAccessor) {
365
- yield `
366
- if ("${property.singularName}" in values &&
367
- values.${property.singularName} != null) {
368
- throw new TypeError(
369
- "Cannot update both ${property.singularName} and " +
370
- "${property.pluralName} at the same time.",
371
- );
372
- }
373
- `;
374
- }
375
- yield generateValidatedArrayCopy(
376
- property.pluralName,
377
- typeNames,
378
- typeGuards,
379
- );
380
- yield `
381
- // @ts-ignore: type is checked above.
382
- clone.${fieldName} = copied;
383
- `;
384
- if (!allScalarTypes) {
385
- yield `
386
- clone.${trustFieldName} = new Set();
387
- vocabSetTrustPrefix(clone.${trustFieldName}, clone.${fieldName}.length);
388
- `;
389
- }
390
- yield `
391
- } else {
392
- throw new TypeError(
393
- "The ${property.pluralName} must be an array of type " +
394
- ${JSON.stringify(typeNames)} + ".",
395
- );
396
- }
397
- }
398
- `;
399
- }
400
- }
401
- yield (
402
- `
403
- return clone;
404
- }
405
- `.trimEnd() + "\n"
406
- );
407
- }
408
-
409
- export async function* generateDeepCloner(
410
- typeUri: string,
411
- types: Record<string, TypeSchema>,
412
- ): AsyncIterable<string> {
413
- const type = types[typeUri];
414
- yield `
415
- /**
416
- * Copies this instance and its nested vocabulary objects, optionally
417
- * replacing property values. Replacement values are copied too.
418
- *
419
- * Property arrays, URLs and byte arrays are independent of the source.
420
- * Repeated references remain shared within the copy. References to this
421
- * source in replacement values receive a separate copy of its pre-update
422
- * values, rather than referring back to the updated root.
423
- * Other scalar values, including opaque cryptographic keys, are shared.
424
- *
425
- * Each copied object retains its own default loaders, tracer, verifier
426
- * and base URL. Options override defaults only on the root instance.
427
- * This method does not fetch or serialize objects. Cached JSON-LD and
428
- * retained signed representations are not copied; unknown JSON-LD
429
- * properties and original formatting are not preserved. Sign the copy
430
- * again if it needs a valid proof.
431
- *
432
- * Trust and portable provenance follow clone() rules at every level.
433
- * Historical referrers within the graph are copied without replacements;
434
- * referrers outside the graph still point at the original external objects.
435
- * Custom clone() overrides must return fresh, compatible instances and
436
- * remain responsible for their own constructor and cloning side effects.
437
- * Large sparse property arrays with ordinary data entries are copied using
438
- * a snapshot of their length and present indices. Entries added after a
439
- * snapshot are not visited; deleted entries are skipped, and values changed
440
- * after the snapshot are read when reached. Custom
441
- * clone() overrides must avoid structurally changing a field being copied
442
- * if they need all its nested objects to be independent of the source.
443
- *
444
- * @param values The values to replace before copying the graph.
445
- * @param options Root loader and verifier overrides. Undefined options
446
- * retain the corresponding defaults.
447
- * @returns An independent copy of the stored vocabulary graph.
448
- * @since 2.5.0
449
- */
450
- ${emitOverride(typeUri, types)} deepClone(values:
451
- `;
452
- for await (const code of generateParametersType(typeUri, types)) yield code;
453
- yield `= {}, options: {
454
- documentLoader?: DocumentLoader,
455
- contextLoader?: DocumentLoader,
456
- verifyPortableObject?: PortableObjectVerifier,
457
- } = {}): ${type.name} {
458
- const cloneOptions = {
459
- documentLoader: options.documentLoader ?? this._documentLoader,
460
- contextLoader: options.contextLoader ?? this._contextLoader,
461
- verifyPortableObject: options.verifyPortableObject ?? this._verifyPortableObject,
462
- tracerProvider: this._tracerProvider,
463
- baseUrl: this._baseUrl,
464
- };
465
- return deepCloneGraph(this, this.clone(values, cloneOptions));
466
- }\n`;
467
- }
package/src/deep-clone.ts DELETED
@@ -1,176 +0,0 @@
1
- import { getFieldName } from "./field.ts";
2
- import type { PropertySchema, TypeSchema } from "./schema.ts";
3
- import { getTypeName } from "./type.ts";
4
-
5
- function needsCopy(
6
- property: PropertySchema,
7
- types: Record<string, TypeSchema>,
8
- ): boolean {
9
- return property.range.some(
10
- (uri) =>
11
- uri in types || ["URL", "Uint8Array"].includes(getTypeName(uri, types)),
12
- );
13
- }
14
-
15
- /** Emits module-private graph-copy support, shared by all generated classes. */
16
- export function generateDeepCloneHelpers(): string {
17
- return `
18
- interface DeepCloneContext {
19
- value<T>(value: T): T;
20
- }
21
-
22
- interface DeepCloneDescriptor {
23
- create(source: object): object;
24
- copy(destination: object, context: DeepCloneContext): void;
25
- }
26
-
27
- const deepCloneDescriptors = new Map<object, DeepCloneDescriptor>();
28
-
29
- function getDeepCloneDescriptor(value: object): DeepCloneDescriptor | undefined {
30
- let prototype: object | null = globalThis.Object.getPrototypeOf(value);
31
- while (prototype != null) {
32
- const descriptor = deepCloneDescriptors.get(prototype);
33
- if (descriptor != null) return descriptor;
34
- prototype = globalThis.Object.getPrototypeOf(prototype);
35
- }
36
- return undefined;
37
- }
38
-
39
- function deepCloneGraph<T extends object>(source: object, root: T): T {
40
- const memo = new Map<object, object>();
41
- const destinations = new Set<object>();
42
- const shells: object[] = [];
43
- let next = 0;
44
-
45
- function enqueue(original: object, destination: object): void {
46
- if (destination == null || typeof destination !== "object" ||
47
- original === destination || destinations.has(destination) ||
48
- !globalThis.Object.prototype.isPrototypeOf.call(
49
- globalThis.Object.getPrototypeOf(original), destination
50
- ) || getDeepCloneDescriptor(destination) == null) {
51
- throw new TypeError("clone() must return a fresh, compatible instance.");
52
- }
53
- destinations.add(destination);
54
- shells.push(destination);
55
- }
56
-
57
- const context: DeepCloneContext = {
58
- value<V>(value: V): V {
59
- if (value == null || typeof value !== "object") return value;
60
- const existing = memo.get(value);
61
- if (existing != null) return existing as V;
62
- if (value instanceof URL) {
63
- const copy = new URL(value.href);
64
- memo.set(value, copy);
65
- return copy as V;
66
- }
67
- if (value instanceof Uint8Array) {
68
- const copy = new Uint8Array(value);
69
- memo.set(value, copy);
70
- return copy as V;
71
- }
72
- const descriptor = getDeepCloneDescriptor(value);
73
- // Other supported scalars (Temporal, LanguageString, Intl.Locale,
74
- // CryptoKey and class constructors) are shared as immutable values.
75
- if (descriptor == null) return value;
76
- const copy = descriptor.create(value);
77
- enqueue(value, copy);
78
- memo.set(value, copy);
79
- return copy as V;
80
- },
81
- };
82
-
83
- function drain(): void {
84
- while (next < shells.length) {
85
- const shell = shells[next++];
86
- getDeepCloneDescriptor(shell)!.copy(shell, context);
87
- }
88
- }
89
-
90
- // The effective root includes replacements. References to the source root
91
- // instead receive a separate copy of its pre-update values.
92
- enqueue(source, root);
93
- drain();
94
-
95
- // Discover historical root ancestry without substituting replacement values
96
- // into it. The resolver deliberately returns undefined in this first pass.
97
- const count = shells.length;
98
- for (let i = 0; i < count; i++) {
99
- retargetPortableReferrer(shells[i], (original) => {
100
- if (original === source) context.value(source);
101
- return undefined;
102
- });
103
- }
104
- drain();
105
- for (const shell of shells) {
106
- retargetPortableReferrer(shell, (original) => memo.get(original));
107
- }
108
- return root;
109
- }
110
- `;
111
- }
112
-
113
- /** Emits private-field copiers inside static blocks, keeping them out of d.ts. */
114
- export async function* generateDeepCloneDescriptor(
115
- typeUri: string,
116
- types: Record<string, TypeSchema>,
117
- ): AsyncIterable<string> {
118
- const type = types[typeUri];
119
- const properties = type.properties.filter((p) => needsCopy(p, types));
120
- if (type.extends != null && properties.length < 1) return;
121
- yield `static {\n`;
122
- if (type.extends == null) {
123
- yield `deepCloneDescriptors.set(this.prototype, {
124
- create(value: object): object {
125
- const source = value as ${type.name};
126
- const options = {
127
- documentLoader: source.#documentLoader,
128
- contextLoader: source.#contextLoader,
129
- tracerProvider: source.#tracerProvider,
130
- verifyPortableObject: source.#verifyPortableObject,
131
- baseUrl: source.#_baseUrl,
132
- };
133
- return source.clone({}, options);
134
- },
135
- copy(value: object, context: DeepCloneContext): void {
136
- const node = value as ${type.name};
137
- const identified = node as { id: URL | null };
138
- identified.id = context.value(identified.id);
139
- `;
140
- } else {
141
- yield `const base = getDeepCloneDescriptor(this.prototype)!;
142
- deepCloneDescriptors.set(this.prototype, {
143
- create: base.create,
144
- copy(value: object, context: DeepCloneContext): void {
145
- base.copy(value, context);
146
- const node = value as ${type.name};
147
- `;
148
- }
149
- for (const property of properties) {
150
- const field = await getFieldName(property.uri);
151
- yield `
152
- {
153
- const array = node.${field};
154
- const snapshot = array.length < vocabSparseArrayMinimumLength
155
- ? undefined : vocabSparseArraySnapshot(array);
156
- if (snapshot != null) {
157
- for (const i of snapshot.indices) {
158
- if (!globalThis.Object.hasOwn(array, i)) continue;
159
- const value = array[i];
160
- if (value != null && typeof value === "object") {
161
- array[i] = context.value(value);
162
- }
163
- }
164
- } else {
165
- for (let i = 0; i < node.${field}.length; i++) {
166
- const value = node.${field}[i];
167
- if (value != null && typeof value === "object") {
168
- node.${field}[i] = context.value(value);
169
- }
170
- }
171
- }
172
- }
173
- `;
174
- }
175
- yield `} }); }\n`;
176
- }
package/src/field.ts DELETED
@@ -1,48 +0,0 @@
1
- import { encodeBase58 } from "byte-encodings/base58";
2
- import type { PropertySchema, TypeSchema } from "./schema.ts";
3
- import { areAllScalarTypes, getTypeNames } from "./type.ts";
4
-
5
- export async function getFieldName(
6
- propertyUri: string,
7
- prefix = "#",
8
- ): Promise<string> {
9
- const hashedUri = await crypto.subtle.digest(
10
- "SHA-1",
11
- new TextEncoder().encode(propertyUri),
12
- );
13
- const match = propertyUri.match(/#([A-Za-z0-9_]+)$/);
14
- const suffix = match == null ? "" : `_${match[1]}`;
15
- return `${prefix}_${encodeBase58(hashedUri)}${suffix}`;
16
- }
17
-
18
- export async function generateField(
19
- property: PropertySchema,
20
- types: Record<string, TypeSchema>,
21
- prefix = "#",
22
- ): Promise<string> {
23
- const fieldName = await getFieldName(property.uri, prefix);
24
- if (areAllScalarTypes(property.range, types)) {
25
- return `${fieldName}: (${getTypeNames(
26
- property.range,
27
- types,
28
- true,
29
- )})[] = [];\n`;
30
- } else {
31
- const typeNames = getTypeNames(property.range, types);
32
- const trustFieldName = await getFieldName(property.uri, `${prefix}_trust`);
33
- return `
34
- ${fieldName}: (${typeNames} | URL)[] = [];
35
- ${trustFieldName}: VocabTrustSet = new Set();
36
- `;
37
- }
38
- }
39
-
40
- export async function* generateFields(
41
- typeUri: string,
42
- types: Record<string, TypeSchema>,
43
- ): AsyncIterable<string> {
44
- const type = types[typeUri];
45
- for (const property of type.properties) {
46
- yield await generateField(property, types);
47
- }
48
- }