@fedify/vocab-tools 2.5.0-dev.2619 → 2.5.0-dev.2687
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/deno.json +2 -2
- package/dist/mod.cjs +6 -5
- package/dist/mod.d.cts +3 -3
- package/dist/mod.d.ts +3 -3
- package/dist/mod.js +6 -5
- package/package.json +3 -3
- package/src/__snapshots__/class.test.ts.deno.snap +1 -0
- package/src/__snapshots__/class.test.ts.node.snap +1 -0
- package/src/__snapshots__/class.test.ts.snap +1 -0
- package/src/class.test.ts +43 -46
- package/src/class.ts +21 -15
- package/src/codec.test.ts +281 -248
- package/src/codec.ts +14 -22
- package/src/constructor.ts +20 -17
- package/src/deep-clone.ts +3 -2
- package/src/field.ts +5 -3
- package/src/inspector.ts +4 -3
- package/src/property.ts +64 -63
- package/src/schema.test.ts +60 -62
- package/src/schema.ts +79 -72
- package/src/type.ts +23 -17
- package/tsdown.config.ts +9 -7
package/src/codec.ts
CHANGED
|
@@ -137,13 +137,7 @@ export async function* generateEncoder(
|
|
|
137
137
|
yield "retainedSignedValueRef(v, signedValues.scope) ?? (";
|
|
138
138
|
yield "v instanceof URL ? formatIri(v) : ";
|
|
139
139
|
}
|
|
140
|
-
const encoders = getEncoders(
|
|
141
|
-
property.range,
|
|
142
|
-
types,
|
|
143
|
-
"v",
|
|
144
|
-
"options",
|
|
145
|
-
true,
|
|
146
|
-
);
|
|
140
|
+
const encoders = getEncoders(property.range, types, "v", "options", true);
|
|
147
141
|
for (const code of encoders) yield code;
|
|
148
142
|
if (!areAllScalarTypes(property.range, types)) yield ")";
|
|
149
143
|
yield `
|
|
@@ -188,10 +182,10 @@ export async function* generateEncoder(
|
|
|
188
182
|
}
|
|
189
183
|
yield `
|
|
190
184
|
${
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
185
|
+
type.typeless
|
|
186
|
+
? ""
|
|
187
|
+
: `result["type"] = ${JSON.stringify(type.compactName ?? type.uri)};`
|
|
188
|
+
}
|
|
195
189
|
if (this.id != null) result["id"] = formatIri(this.id);
|
|
196
190
|
result["@context"] = ${JSON.stringify(type.defaultContext)};
|
|
197
191
|
return signedValues.owner
|
|
@@ -290,7 +284,7 @@ export async function* generateEncoder(
|
|
|
290
284
|
${JSON.stringify(type.defaultContext)};
|
|
291
285
|
`;
|
|
292
286
|
const hasExtraContexts = Object.values(types).some((t) =>
|
|
293
|
-
t.properties.some((p) => p.extraContext != null)
|
|
287
|
+
t.properties.some((p) => p.extraContext != null),
|
|
294
288
|
);
|
|
295
289
|
if (hasExtraContexts) {
|
|
296
290
|
yield `
|
|
@@ -567,9 +561,10 @@ export async function* generateDecoder(
|
|
|
567
561
|
const variable = await getFieldName(property.uri, "");
|
|
568
562
|
yield await generateField(property, types, "const ");
|
|
569
563
|
const arrayVariable = `${variable}__array`;
|
|
570
|
-
const propertyValues =
|
|
571
|
-
|
|
572
|
-
|
|
564
|
+
const propertyValues =
|
|
565
|
+
property.uri === "https://w3id.org/fep/ef61/gateways"
|
|
566
|
+
? "getPortableActorGateways(values) as typeof values[string]"
|
|
567
|
+
: `values[${JSON.stringify(property.uri)}]`;
|
|
573
568
|
yield `
|
|
574
569
|
let ${arrayVariable} = ${propertyValues};
|
|
575
570
|
`;
|
|
@@ -582,13 +577,10 @@ export async function* generateDecoder(
|
|
|
582
577
|
`;
|
|
583
578
|
}
|
|
584
579
|
}
|
|
585
|
-
let itemsExpression =
|
|
586
|
-
`${arrayVariable}.length === 1 && "@list" in ${arrayVariable}[0]
|
|
580
|
+
let itemsExpression = `${arrayVariable}.length === 1 && "@list" in ${arrayVariable}[0]
|
|
587
581
|
? ${arrayVariable}[0]["@list"]
|
|
588
582
|
: ${arrayVariable}`;
|
|
589
|
-
if (
|
|
590
|
-
isNonFunctionalProperty(property) && property.container === "graph"
|
|
591
|
-
) {
|
|
583
|
+
if (isNonFunctionalProperty(property) && property.container === "graph") {
|
|
592
584
|
itemsExpression = `(${itemsExpression}).flatMap((item: unknown) =>
|
|
593
585
|
item != null && typeof item === "object" && "@graph" in item &&
|
|
594
586
|
Array.isArray((item as { "@graph": unknown })["@graph"])
|
|
@@ -625,8 +617,8 @@ export async function* generateDecoder(
|
|
|
625
617
|
yield `
|
|
626
618
|
const decoded =
|
|
627
619
|
`;
|
|
628
|
-
const lenient =
|
|
629
|
-
skipsUnparsable(property.range[0]);
|
|
620
|
+
const lenient =
|
|
621
|
+
property.range.length == 1 && skipsUnparsable(property.range[0]);
|
|
630
622
|
if (property.range.length == 1) {
|
|
631
623
|
if (lenient) {
|
|
632
624
|
yield getDataCheck(property.range[0], types, "v");
|
package/src/constructor.ts
CHANGED
|
@@ -22,9 +22,10 @@ function generateParameterType(
|
|
|
22
22
|
);
|
|
23
23
|
} else {
|
|
24
24
|
code.push(
|
|
25
|
-
`${property.singularName}?: ${
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
`${property.singularName}?: ${getTypeNames(
|
|
26
|
+
range,
|
|
27
|
+
types,
|
|
28
|
+
)} | URL | null;`,
|
|
28
29
|
);
|
|
29
30
|
}
|
|
30
31
|
}
|
|
@@ -53,12 +54,12 @@ async function* generateParametersType(
|
|
|
53
54
|
if (type.extends == null) {
|
|
54
55
|
yield `id?: URL | null;\n`;
|
|
55
56
|
} else {
|
|
56
|
-
for await (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
]
|
|
61
|
-
) {
|
|
57
|
+
for await (const code of generateParametersType(
|
|
58
|
+
type.extends,
|
|
59
|
+
types,
|
|
60
|
+
false,
|
|
61
|
+
[...excludeProperties, ...type.properties.map((p) => p.singularName)],
|
|
62
|
+
)) {
|
|
62
63
|
yield code;
|
|
63
64
|
}
|
|
64
65
|
}
|
|
@@ -74,7 +75,8 @@ function generateValidatedArrayCopy(
|
|
|
74
75
|
typeNames: string,
|
|
75
76
|
typeGuards: string,
|
|
76
77
|
): string {
|
|
77
|
-
return
|
|
78
|
+
return (
|
|
79
|
+
`
|
|
78
80
|
let copied!: (${typeNames})[];
|
|
79
81
|
let valid = false;
|
|
80
82
|
if (Array.isArray(values.${name})) {
|
|
@@ -100,7 +102,8 @@ function generateValidatedArrayCopy(
|
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
104
|
if (valid) {
|
|
103
|
-
`.trimEnd() + "\n"
|
|
105
|
+
`.trimEnd() + "\n"
|
|
106
|
+
);
|
|
104
107
|
}
|
|
105
108
|
|
|
106
109
|
export async function* generateConstructor(
|
|
@@ -164,8 +167,7 @@ export async function* generateConstructor(
|
|
|
164
167
|
let typeNames = getTypeNames(property.range, types);
|
|
165
168
|
const scalar = areAllScalarTypes(property.range, types);
|
|
166
169
|
if (!scalar) {
|
|
167
|
-
typeGuards =
|
|
168
|
-
`${typeGuards} || values.${property.singularName} instanceof URL`;
|
|
170
|
+
typeGuards = `${typeGuards} || values.${property.singularName} instanceof URL`;
|
|
169
171
|
typeNames = `${typeNames} | URL`;
|
|
170
172
|
}
|
|
171
173
|
yield `
|
|
@@ -323,8 +325,7 @@ export async function* generateCloner(
|
|
|
323
325
|
let typeNames = getTypeNames(property.range, types);
|
|
324
326
|
const scalar = areAllScalarTypes(property.range, types);
|
|
325
327
|
if (!scalar) {
|
|
326
|
-
typeGuards =
|
|
327
|
-
`${typeGuards} || values.${property.singularName} instanceof URL`;
|
|
328
|
+
typeGuards = `${typeGuards} || values.${property.singularName} instanceof URL`;
|
|
328
329
|
typeNames = `${typeNames} | URL`;
|
|
329
330
|
}
|
|
330
331
|
yield `
|
|
@@ -397,10 +398,12 @@ export async function* generateCloner(
|
|
|
397
398
|
`;
|
|
398
399
|
}
|
|
399
400
|
}
|
|
400
|
-
yield
|
|
401
|
+
yield (
|
|
402
|
+
`
|
|
401
403
|
return clone;
|
|
402
404
|
}
|
|
403
|
-
`.trimEnd() + "\n"
|
|
405
|
+
`.trimEnd() + "\n"
|
|
406
|
+
);
|
|
404
407
|
}
|
|
405
408
|
|
|
406
409
|
export async function* generateDeepCloner(
|
package/src/deep-clone.ts
CHANGED
|
@@ -6,8 +6,9 @@ function needsCopy(
|
|
|
6
6
|
property: PropertySchema,
|
|
7
7
|
types: Record<string, TypeSchema>,
|
|
8
8
|
): boolean {
|
|
9
|
-
return property.range.some(
|
|
10
|
-
|
|
9
|
+
return property.range.some(
|
|
10
|
+
(uri) =>
|
|
11
|
+
uri in types || ["URL", "Uint8Array"].includes(getTypeName(uri, types)),
|
|
11
12
|
);
|
|
12
13
|
}
|
|
13
14
|
|
package/src/field.ts
CHANGED
|
@@ -22,9 +22,11 @@ export async function generateField(
|
|
|
22
22
|
): Promise<string> {
|
|
23
23
|
const fieldName = await getFieldName(property.uri, prefix);
|
|
24
24
|
if (areAllScalarTypes(property.range, types)) {
|
|
25
|
-
return `${fieldName}: (${
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
return `${fieldName}: (${getTypeNames(
|
|
26
|
+
property.range,
|
|
27
|
+
types,
|
|
28
|
+
true,
|
|
29
|
+
)})[] = [];\n`;
|
|
28
30
|
} else {
|
|
29
31
|
const typeNames = getTypeNames(property.range, types);
|
|
30
32
|
const trustFieldName = await getFieldName(property.uri, `${prefix}_trust`);
|
package/src/inspector.ts
CHANGED
|
@@ -9,9 +9,10 @@ export async function* generateInspector(
|
|
|
9
9
|
): AsyncIterable<string> {
|
|
10
10
|
const type = types[typeUri];
|
|
11
11
|
yield `
|
|
12
|
-
protected ${
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
protected ${emitOverride(
|
|
13
|
+
typeUri,
|
|
14
|
+
types,
|
|
15
|
+
)} _getCustomInspectProxy(): Record<string, unknown> {
|
|
15
16
|
`;
|
|
16
17
|
if (type.extends == null) {
|
|
17
18
|
yield `
|
package/src/property.ts
CHANGED
|
@@ -41,9 +41,10 @@ async function* generateProperty(
|
|
|
41
41
|
if (areAllScalarTypes(property.range, types)) {
|
|
42
42
|
if (hasSingularAccessor(property)) {
|
|
43
43
|
yield doc;
|
|
44
|
-
yield `${override} get ${property.singularName}(): (${
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
yield `${override} get ${property.singularName}(): (${getTypeNames(
|
|
45
|
+
property.range,
|
|
46
|
+
types,
|
|
47
|
+
)} | null) {
|
|
47
48
|
if (this._warning != null) {
|
|
48
49
|
getLogger(this._warning.category).warn(
|
|
49
50
|
this._warning.message,
|
|
@@ -57,9 +58,11 @@ async function* generateProperty(
|
|
|
57
58
|
}
|
|
58
59
|
if (isNonFunctionalProperty(property)) {
|
|
59
60
|
yield doc;
|
|
60
|
-
yield `get ${property.pluralName}(): (${
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
yield `get ${property.pluralName}(): (${getTypeNames(
|
|
62
|
+
property.range,
|
|
63
|
+
types,
|
|
64
|
+
true,
|
|
65
|
+
)})[] {
|
|
63
66
|
return this.${await getFieldName(property.uri)};
|
|
64
67
|
}
|
|
65
68
|
`;
|
|
@@ -308,10 +311,7 @@ async function* generateProperty(
|
|
|
308
311
|
const baseUrl = options.baseUrl;
|
|
309
312
|
const verifyPortableObject = options.verifyPortableObject;
|
|
310
313
|
`;
|
|
311
|
-
if (
|
|
312
|
-
property.preprocessors != null &&
|
|
313
|
-
property.preprocessors.length > 0
|
|
314
|
-
) {
|
|
314
|
+
if (property.preprocessors != null && property.preprocessors.length > 0) {
|
|
315
315
|
yield `
|
|
316
316
|
if (jsonLd != null && typeof jsonLd === "object") {
|
|
317
317
|
const _expanded = await jsonld.expand(jsonLd, {
|
|
@@ -331,9 +331,9 @@ async function* generateProperty(
|
|
|
331
331
|
}
|
|
332
332
|
yield `
|
|
333
333
|
{
|
|
334
|
-
const _result = await ${varName}[${
|
|
335
|
-
|
|
336
|
-
|
|
334
|
+
const _result = await ${varName}[${JSON.stringify(
|
|
335
|
+
pp.function,
|
|
336
|
+
)}](_pp_obj, {
|
|
337
337
|
documentLoader,
|
|
338
338
|
contextLoader,
|
|
339
339
|
tracerProvider,
|
|
@@ -341,9 +341,10 @@ async function* generateProperty(
|
|
|
341
341
|
baseUrl,
|
|
342
342
|
});
|
|
343
343
|
if (_result instanceof Error) throw _result;
|
|
344
|
-
if (_result !== undefined) return _result as ${
|
|
345
|
-
|
|
346
|
-
|
|
344
|
+
if (_result !== undefined) return _result as ${getTypeNames(
|
|
345
|
+
property.range,
|
|
346
|
+
types,
|
|
347
|
+
)};
|
|
347
348
|
}
|
|
348
349
|
`;
|
|
349
350
|
}
|
|
@@ -443,15 +444,15 @@ async function* generateProperty(
|
|
|
443
444
|
let v = this.${await getFieldName(property.uri)}[0];
|
|
444
445
|
if (!(v instanceof URL) &&
|
|
445
446
|
!(0 < (this.${await getFieldName(
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
447
|
+
property.uri,
|
|
448
|
+
"#_trust",
|
|
449
|
+
)}[vocabTrustPrefix] ?? 0) ||
|
|
449
450
|
this.${await getFieldName(property.uri, "#_trust")}.has(0))) {
|
|
450
451
|
if (v.id == null) {
|
|
451
452
|
if (isUnsecuredPortableObject(this)) {
|
|
452
|
-
warnUnverifiableEmbeddedObject(this, ${
|
|
453
|
-
|
|
454
|
-
|
|
453
|
+
warnUnverifiableEmbeddedObject(this, ${JSON.stringify(
|
|
454
|
+
property.uri,
|
|
455
|
+
)});
|
|
455
456
|
return null;
|
|
456
457
|
}
|
|
457
458
|
} else if (
|
|
@@ -472,9 +473,9 @@ async function* generateProperty(
|
|
|
472
473
|
this.${await getFieldName(property.uri)}[0] = fetched;
|
|
473
474
|
this.${await getFieldName(property.uri, "#_trust")}.add(0);
|
|
474
475
|
this._cachedJsonLd = undefined;
|
|
475
|
-
recordPortableReferrer(this, fetched, ${
|
|
476
|
-
|
|
477
|
-
|
|
476
|
+
recordPortableReferrer(this, fetched, ${JSON.stringify(
|
|
477
|
+
property.uri,
|
|
478
|
+
)});
|
|
478
479
|
return fetched;
|
|
479
480
|
}
|
|
480
481
|
`;
|
|
@@ -512,25 +513,25 @@ async function* generateProperty(
|
|
|
512
513
|
yield `
|
|
513
514
|
if (v?.id != null &&
|
|
514
515
|
((${
|
|
515
|
-
|
|
516
|
-
|
|
516
|
+
type.trustEmbeddedObjects === false ? "" : "this.id != null && "
|
|
517
|
+
}!isTrustedIriOrigin(options, v.id, ${trustOwner})) ||
|
|
517
518
|
isUnsecuredPortableObject(this) ||
|
|
518
519
|
mustDereferencePortableObject(
|
|
519
520
|
this, ${trustOwner}, v.id, options,
|
|
520
521
|
)) &&
|
|
521
522
|
!(0 < (this.${await getFieldName(
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
523
|
+
property.uri,
|
|
524
|
+
"#_trust",
|
|
525
|
+
)}[vocabTrustPrefix] ?? 0) ||
|
|
525
526
|
this.${await getFieldName(property.uri, "#_trust")}.has(0))) {
|
|
526
527
|
if (options.crossOrigin === "throw") {
|
|
527
528
|
throw new Error(
|
|
528
529
|
"The property object's @id (" + v.id.href + ") has a different " +
|
|
529
530
|
"origin than the property owner's @id (" + ${
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
531
|
+
type.trustEmbeddedObjects === false
|
|
532
|
+
? '"untrusted metadata"'
|
|
533
|
+
: "(this.id?.href ?? null)"
|
|
534
|
+
} + "); " +
|
|
534
535
|
"refusing to return the object. If you want to bypass this " +
|
|
535
536
|
"check and are aware of the security implications, set the " +
|
|
536
537
|
'crossOrigin option to "trust".'
|
|
@@ -543,10 +544,10 @@ async function* generateProperty(
|
|
|
543
544
|
"aware of the security implications, set the crossOrigin option " +
|
|
544
545
|
'to "trust".',
|
|
545
546
|
{ objectId: v.id.href, parentObjectId: ${
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
547
|
+
type.trustEmbeddedObjects === false
|
|
548
|
+
? '"untrusted metadata"'
|
|
549
|
+
: "(this.id?.href ?? null)"
|
|
550
|
+
} },
|
|
550
551
|
);
|
|
551
552
|
return null;
|
|
552
553
|
}
|
|
@@ -620,15 +621,15 @@ async function* generateProperty(
|
|
|
620
621
|
let v = vs[i];
|
|
621
622
|
if (!(v instanceof URL) &&
|
|
622
623
|
!(i < (this.${await getFieldName(
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
624
|
+
property.uri,
|
|
625
|
+
"#_trust",
|
|
626
|
+
)}[vocabTrustPrefix] ?? 0) ||
|
|
626
627
|
this.${await getFieldName(property.uri, "#_trust")}.has(i))) {
|
|
627
628
|
if (v.id == null) {
|
|
628
629
|
if (isUnsecuredPortableObject(this)) {
|
|
629
|
-
warnUnverifiableEmbeddedObject(this, ${
|
|
630
|
-
|
|
631
|
-
|
|
630
|
+
warnUnverifiableEmbeddedObject(this, ${JSON.stringify(
|
|
631
|
+
property.uri,
|
|
632
|
+
)});
|
|
632
633
|
continue;
|
|
633
634
|
}
|
|
634
635
|
} else if (
|
|
@@ -652,9 +653,9 @@ async function* generateProperty(
|
|
|
652
653
|
vs[i] = fetched;
|
|
653
654
|
this.${await getFieldName(property.uri, "#_trust")}.add(i);
|
|
654
655
|
this._cachedJsonLd = undefined;
|
|
655
|
-
recordPortableReferrer(this, fetched, ${
|
|
656
|
-
|
|
657
|
-
|
|
656
|
+
recordPortableReferrer(this, fetched, ${JSON.stringify(
|
|
657
|
+
property.uri,
|
|
658
|
+
)});
|
|
658
659
|
yield fetched;
|
|
659
660
|
continue;
|
|
660
661
|
}
|
|
@@ -682,9 +683,9 @@ async function* generateProperty(
|
|
|
682
683
|
if (!options.suppressError) throw error;
|
|
683
684
|
getLogger(["fedify", "vocab"]).debug(
|
|
684
685
|
"Failed to parse embedded value of {property} at index {index}: {error}",
|
|
685
|
-
{ property: ${
|
|
686
|
-
|
|
687
|
-
|
|
686
|
+
{ property: ${JSON.stringify(
|
|
687
|
+
property.uri,
|
|
688
|
+
)}, index: i, error },
|
|
688
689
|
);
|
|
689
690
|
continue;
|
|
690
691
|
}
|
|
@@ -695,25 +696,25 @@ async function* generateProperty(
|
|
|
695
696
|
yield `
|
|
696
697
|
if (v?.id != null &&
|
|
697
698
|
((${
|
|
698
|
-
|
|
699
|
-
|
|
699
|
+
type.trustEmbeddedObjects === false ? "" : "this.id != null && "
|
|
700
|
+
}!isTrustedIriOrigin(options, v.id, ${trustOwner})) ||
|
|
700
701
|
isUnsecuredPortableObject(this) ||
|
|
701
702
|
mustDereferencePortableObject(
|
|
702
703
|
this, ${trustOwner}, v.id, options,
|
|
703
704
|
)) &&
|
|
704
705
|
!(i < (this.${await getFieldName(
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
706
|
+
property.uri,
|
|
707
|
+
"#_trust",
|
|
708
|
+
)}[vocabTrustPrefix] ?? 0) ||
|
|
708
709
|
this.${await getFieldName(property.uri, "#_trust")}.has(i))) {
|
|
709
710
|
if (options.crossOrigin === "throw") {
|
|
710
711
|
throw new Error(
|
|
711
712
|
"The property object's @id (" + v.id.href + ") has a different " +
|
|
712
713
|
"origin than the property owner's @id (" + ${
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
714
|
+
type.trustEmbeddedObjects === false
|
|
715
|
+
? '"untrusted metadata"'
|
|
716
|
+
: "(this.id?.href ?? null)"
|
|
717
|
+
} + "); " +
|
|
717
718
|
"refusing to return the object. If you want to bypass this " +
|
|
718
719
|
"check and are aware of the security implications, set the " +
|
|
719
720
|
'crossOrigin option to "trust".'
|
|
@@ -726,10 +727,10 @@ async function* generateProperty(
|
|
|
726
727
|
"aware of the security implications, set the crossOrigin " +
|
|
727
728
|
'option to "trust".',
|
|
728
729
|
{ objectId: v.id.href, parentObjectId: ${
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
730
|
+
type.trustEmbeddedObjects === false
|
|
731
|
+
? '"untrusted metadata"'
|
|
732
|
+
: "(this.id?.href ?? null)"
|
|
733
|
+
} },
|
|
733
734
|
);
|
|
734
735
|
continue;
|
|
735
736
|
}
|
package/src/schema.test.ts
CHANGED
|
@@ -15,8 +15,7 @@ import {
|
|
|
15
15
|
} from "./schema.ts";
|
|
16
16
|
|
|
17
17
|
test(
|
|
18
|
-
"isNonFunctionalProperty: " +
|
|
19
|
-
"returns true for non-functional property",
|
|
18
|
+
"isNonFunctionalProperty: " + "returns true for non-functional property",
|
|
20
19
|
() => {
|
|
21
20
|
const property: PropertySchema = {
|
|
22
21
|
singularName: "name",
|
|
@@ -172,28 +171,25 @@ test("Type guard combinations: non-functional property with container", () => {
|
|
|
172
171
|
}
|
|
173
172
|
});
|
|
174
173
|
|
|
175
|
-
test(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
container: "graph",
|
|
186
|
-
};
|
|
174
|
+
test("Type guard combinations: non-functional property with graph container", () => {
|
|
175
|
+
const property: PropertySchema = {
|
|
176
|
+
singularName: "member",
|
|
177
|
+
pluralName: "members",
|
|
178
|
+
uri: "https://example.com/member",
|
|
179
|
+
description: "Graph of members",
|
|
180
|
+
range: ["https://example.com/Member"] as [TypeUri],
|
|
181
|
+
functional: false,
|
|
182
|
+
container: "graph",
|
|
183
|
+
};
|
|
187
184
|
|
|
188
|
-
|
|
189
|
-
|
|
185
|
+
ok(isNonFunctionalProperty(property));
|
|
186
|
+
ok(!hasSingularAccessor(property));
|
|
190
187
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
);
|
|
188
|
+
// Type narrowing test
|
|
189
|
+
if (isNonFunctionalProperty(property)) {
|
|
190
|
+
deepStrictEqual(property.container, "graph");
|
|
191
|
+
}
|
|
192
|
+
});
|
|
197
193
|
|
|
198
194
|
test("Type guard combinations: untyped property", () => {
|
|
199
195
|
const property: PropertySchema = {
|
|
@@ -288,21 +284,21 @@ test("loadSchemaFiles validates redundant properties on both property kinds", as
|
|
|
288
284
|
policy,
|
|
289
285
|
);
|
|
290
286
|
}
|
|
291
|
-
for (
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
287
|
+
for (const invalid of [
|
|
288
|
+
{ redundantPropertiesWrite: "merge" },
|
|
289
|
+
{ redundantPropertiesWrite: 42 },
|
|
290
|
+
{ redundantProperties: "alias" },
|
|
291
|
+
{ redundantProperties: [{}] },
|
|
292
|
+
{ redundantProperties: [{ uri: 42 }] },
|
|
293
|
+
{
|
|
294
|
+
redundantProperties: [
|
|
295
|
+
{
|
|
300
296
|
uri: "https://example.com/alias",
|
|
301
297
|
compactName: 42,
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
) {
|
|
298
|
+
},
|
|
299
|
+
],
|
|
300
|
+
},
|
|
301
|
+
]) {
|
|
306
302
|
await writeFile(
|
|
307
303
|
join(dir, "fixture.yaml"),
|
|
308
304
|
stringify({
|
|
@@ -340,12 +336,14 @@ test("loadSchemaFiles validates context container terms", async () => {
|
|
|
340
336
|
"@container": container,
|
|
341
337
|
});
|
|
342
338
|
const types = await loadSchemaFiles(dir);
|
|
343
|
-
deepStrictEqual(types[uri].defaultContext, [
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
339
|
+
deepStrictEqual(types[uri].defaultContext, [
|
|
340
|
+
{
|
|
341
|
+
term: {
|
|
342
|
+
"@id": "toot:attributionDomains",
|
|
343
|
+
"@container": container,
|
|
344
|
+
},
|
|
347
345
|
},
|
|
348
|
-
|
|
346
|
+
]);
|
|
349
347
|
}
|
|
350
348
|
|
|
351
349
|
await writeTerm({
|
|
@@ -354,34 +352,34 @@ test("loadSchemaFiles validates context container terms", async () => {
|
|
|
354
352
|
"@container": "@set",
|
|
355
353
|
});
|
|
356
354
|
const withType = await loadSchemaFiles(dir);
|
|
357
|
-
deepStrictEqual(withType[uri].defaultContext, [
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
355
|
+
deepStrictEqual(withType[uri].defaultContext, [
|
|
356
|
+
{
|
|
357
|
+
term: {
|
|
358
|
+
"@id": "toot:attributionDomains",
|
|
359
|
+
"@type": "@id",
|
|
360
|
+
"@container": "@set",
|
|
361
|
+
},
|
|
362
362
|
},
|
|
363
|
-
|
|
363
|
+
]);
|
|
364
364
|
|
|
365
365
|
// The pre-existing object term shape must keep validating:
|
|
366
366
|
await writeTerm({ "@type": "@id" });
|
|
367
367
|
await loadSchemaFiles(dir);
|
|
368
368
|
|
|
369
|
-
for (
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
]
|
|
384
|
-
) {
|
|
369
|
+
for (const invalid of [
|
|
370
|
+
{ "@id": "toot:attributionDomains", "@container": "@id" },
|
|
371
|
+
{
|
|
372
|
+
"@id": "toot:attributionDomains",
|
|
373
|
+
"@container": "https://example.com/bogus",
|
|
374
|
+
},
|
|
375
|
+
{ "@id": "toot:attributionDomains", "@container": "@bogus" },
|
|
376
|
+
{
|
|
377
|
+
"@id": "toot:attributionDomains",
|
|
378
|
+
"@container": "@set",
|
|
379
|
+
"@unknown": "@set",
|
|
380
|
+
},
|
|
381
|
+
{ "@container": "@set" },
|
|
382
|
+
]) {
|
|
385
383
|
await writeTerm(invalid);
|
|
386
384
|
await rejects(loadSchemaFiles(dir), AggregateError);
|
|
387
385
|
}
|