@fedify/vocab-tools 2.5.0-dev.2664 → 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 +1 -1
- package/dist/mod.d.cts +3 -3
- package/dist/mod.d.ts +3 -3
- package/dist/mod.js +1 -1
- package/package.json +2 -2
- package/src/class.test.ts +43 -46
- package/src/class.ts +18 -14
- 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 +75 -70
- package/src/type.ts +23 -17
- package/tsdown.config.ts +9 -7
package/src/codec.test.ts
CHANGED
|
@@ -99,14 +99,16 @@ async function withFixture(
|
|
|
99
99
|
entity: false,
|
|
100
100
|
description: "An embedded value.",
|
|
101
101
|
defaultContext: [AS, CONTEXT] as unknown as TypeSchema["defaultContext"],
|
|
102
|
-
properties: [
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
102
|
+
properties: [
|
|
103
|
+
{
|
|
104
|
+
singularName: "label",
|
|
105
|
+
functional: true,
|
|
106
|
+
uri: `${NS}label`,
|
|
107
|
+
compactName: "label",
|
|
108
|
+
description: "A label.",
|
|
109
|
+
range: [`${XSD}string`],
|
|
110
|
+
},
|
|
111
|
+
],
|
|
110
112
|
},
|
|
111
113
|
};
|
|
112
114
|
const source = (await Array.fromAsync(generateClasses(types))).join("");
|
|
@@ -134,34 +136,36 @@ const document = (properties: Record<string, unknown>) => ({
|
|
|
134
136
|
|
|
135
137
|
test("redundant properties select the first non-empty entire set", async () => {
|
|
136
138
|
await withFixture({}, async (Fixture, contextLoader) => {
|
|
137
|
-
for (
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
[
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
) {
|
|
139
|
+
for (const [properties, expected] of [
|
|
140
|
+
[
|
|
141
|
+
{ [`${NS}first`]: [literal("a"), literal("b"), literal("a")] },
|
|
142
|
+
["a", "b", "a"],
|
|
143
|
+
],
|
|
144
|
+
[{ [`${NS}value`]: [], [`${NS}first`]: [literal("a")] }, ["a"]],
|
|
145
|
+
[{ [`${NS}first`]: [], [`${NS}second`]: [literal("b")] }, ["b"]],
|
|
146
|
+
[
|
|
147
|
+
{ [`${NS}value`]: [literal("c")], [`${NS}first`]: [literal("a")] },
|
|
148
|
+
["c"],
|
|
149
|
+
],
|
|
150
|
+
[
|
|
151
|
+
{ [`${NS}first`]: [literal("a")], [`${NS}second`]: [literal("b")] },
|
|
152
|
+
["a"],
|
|
153
|
+
],
|
|
154
|
+
[{}, []],
|
|
155
|
+
] as const) {
|
|
155
156
|
const parsed = await Fixture.fromJsonLd(document(properties), {
|
|
156
157
|
contextLoader,
|
|
157
158
|
});
|
|
158
159
|
deepStrictEqual(parsed.values, expected);
|
|
159
160
|
}
|
|
160
|
-
const parsed = await Fixture.fromJsonLd(
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
161
|
+
const parsed = await Fixture.fromJsonLd(
|
|
162
|
+
{
|
|
163
|
+
"@context": termsForRead(),
|
|
164
|
+
type: "Fixture",
|
|
165
|
+
alternate: ["a", "b", "a"],
|
|
166
|
+
},
|
|
167
|
+
{ contextLoader },
|
|
168
|
+
);
|
|
165
169
|
deepStrictEqual(parsed.values, ["a", "b", "a"]);
|
|
166
170
|
});
|
|
167
171
|
});
|
|
@@ -171,21 +175,24 @@ function termsForRead() {
|
|
|
171
175
|
}
|
|
172
176
|
|
|
173
177
|
test("redundant properties do not retry invalid canonical values", async () => {
|
|
174
|
-
await withFixture(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
178
|
+
await withFixture(
|
|
179
|
+
{
|
|
180
|
+
range: [
|
|
181
|
+
`${XSD}string`,
|
|
182
|
+
"http://www.w3.org/1999/02/22-rdf-syntax-ns#langString",
|
|
183
|
+
],
|
|
184
|
+
},
|
|
185
|
+
async (Fixture, contextLoader) => {
|
|
186
|
+
const parsed = await Fixture.fromJsonLd(
|
|
187
|
+
document({
|
|
188
|
+
[`${NS}value`]: [literal(42)],
|
|
189
|
+
[`${NS}first`]: [literal("fallback")],
|
|
190
|
+
}),
|
|
191
|
+
{ contextLoader },
|
|
192
|
+
);
|
|
193
|
+
deepStrictEqual(parsed.values, []);
|
|
194
|
+
},
|
|
195
|
+
);
|
|
189
196
|
await withFixture(
|
|
190
197
|
{ range: ["fedify:url"] },
|
|
191
198
|
async (Fixture, contextLoader) => {
|
|
@@ -202,13 +209,15 @@ test("redundant properties do not retry invalid canonical values", async () => {
|
|
|
202
209
|
await withFixture(
|
|
203
210
|
{ range: [`${XSD}anyURI`] },
|
|
204
211
|
async (Fixture, contextLoader) => {
|
|
205
|
-
await rejects(
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
+
await rejects(
|
|
213
|
+
Fixture.fromJsonLd(
|
|
214
|
+
document({
|
|
215
|
+
[`${NS}value`]: [{ "@id": "http://[" }],
|
|
216
|
+
[`${NS}first`]: [{ "@id": "https://example.com/fallback" }],
|
|
217
|
+
}),
|
|
218
|
+
{ contextLoader },
|
|
219
|
+
),
|
|
220
|
+
);
|
|
212
221
|
},
|
|
213
222
|
);
|
|
214
223
|
});
|
|
@@ -225,10 +234,10 @@ for (const policy of [undefined, "all", "canonical"] as const) {
|
|
|
225
234
|
contextLoader,
|
|
226
235
|
});
|
|
227
236
|
deepStrictEqual(await instance.toJsonLd({ contextLoader }), compact);
|
|
228
|
-
const expanded = await instance.toJsonLd({
|
|
237
|
+
const expanded = (await instance.toJsonLd({
|
|
229
238
|
format: "expand",
|
|
230
239
|
contextLoader,
|
|
231
|
-
}) as unknown as Record<string, unknown>[];
|
|
240
|
+
})) as unknown as Record<string, unknown>[];
|
|
232
241
|
for (const alias of ["first", "second"]) {
|
|
233
242
|
if (policy === "canonical" || values.length === 0) {
|
|
234
243
|
ok(!(alias in compact));
|
|
@@ -264,83 +273,93 @@ for (const policy of [undefined, "all", "canonical"] as const) {
|
|
|
264
273
|
for (const container of ["list", "graph"] as const) {
|
|
265
274
|
for (const policy of ["all", "canonical"] as const) {
|
|
266
275
|
test(`redundant ${container} containers with ${policy} writes`, async () => {
|
|
267
|
-
await withFixture(
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
container === "list" ? ["a", "b", "a"] : ["a", "b"],
|
|
293
|
-
);
|
|
294
|
-
const instance = new Fixture({ values: parsed.values });
|
|
295
|
-
const compact = await instance.toJsonLd({
|
|
296
|
-
format: "compact",
|
|
297
|
-
contextLoader,
|
|
298
|
-
});
|
|
299
|
-
if (container === "list" || policy === "all") {
|
|
300
|
-
deepStrictEqual(await instance.toJsonLd({ contextLoader }), compact);
|
|
301
|
-
} else {
|
|
302
|
-
// Parsed children retain expanded caches in the heuristic path.
|
|
303
|
-
const defaultOutput = await instance.toJsonLd({ contextLoader });
|
|
304
|
-
const decoded = await Fixture.fromJsonLd(defaultOutput, {
|
|
305
|
-
contextLoader,
|
|
306
|
-
});
|
|
276
|
+
await withFixture(
|
|
277
|
+
{
|
|
278
|
+
container,
|
|
279
|
+
redundantPropertiesWrite: policy,
|
|
280
|
+
range: container === "graph" ? [`${NS}Value`] : [`${XSD}string`],
|
|
281
|
+
},
|
|
282
|
+
async (Fixture, contextLoader) => {
|
|
283
|
+
const items =
|
|
284
|
+
container === "list"
|
|
285
|
+
? [literal("a"), literal("b"), literal("a")]
|
|
286
|
+
: [
|
|
287
|
+
{ "@type": [`${NS}Value`], [`${NS}label`]: [literal("a")] },
|
|
288
|
+
{ "@type": [`${NS}Value`], [`${NS}label`]: [literal("b")] },
|
|
289
|
+
];
|
|
290
|
+
const set =
|
|
291
|
+
container === "list"
|
|
292
|
+
? [{ "@list": items }]
|
|
293
|
+
: items.map((item) => ({ "@graph": [item] }));
|
|
294
|
+
const parsed = await Fixture.fromJsonLd(
|
|
295
|
+
document({
|
|
296
|
+
[`${NS}first`]: set,
|
|
297
|
+
[`${NS}second`]: [{ "@list": [literal("other")] }],
|
|
298
|
+
}),
|
|
299
|
+
{ contextLoader },
|
|
300
|
+
);
|
|
307
301
|
deepStrictEqual(
|
|
308
|
-
|
|
309
|
-
|
|
302
|
+
container === "list"
|
|
303
|
+
? parsed.values
|
|
304
|
+
: parsed.values.map((v) => (v as { label: string }).label),
|
|
305
|
+
container === "list" ? ["a", "b", "a"] : ["a", "b"],
|
|
310
306
|
);
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
307
|
+
const instance = new Fixture({ values: parsed.values });
|
|
308
|
+
const compact = await instance.toJsonLd({
|
|
309
|
+
format: "compact",
|
|
310
|
+
contextLoader,
|
|
311
|
+
});
|
|
312
|
+
if (container === "list" || policy === "all") {
|
|
313
|
+
deepStrictEqual(
|
|
314
|
+
await instance.toJsonLd({ contextLoader }),
|
|
315
|
+
compact,
|
|
316
|
+
);
|
|
320
317
|
} else {
|
|
318
|
+
// Parsed children retain expanded caches in the heuristic path.
|
|
319
|
+
const defaultOutput = await instance.toJsonLd({ contextLoader });
|
|
320
|
+
const decoded = await Fixture.fromJsonLd(defaultOutput, {
|
|
321
|
+
contextLoader,
|
|
322
|
+
});
|
|
321
323
|
deepStrictEqual(
|
|
322
|
-
|
|
323
|
-
|
|
324
|
+
decoded.values.map((v) => (v as { label: string }).label),
|
|
325
|
+
["a", "b"],
|
|
324
326
|
);
|
|
325
|
-
deepStrictEqual(compact[alias], compact.value);
|
|
326
327
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
328
|
+
const expanded = (await instance.toJsonLd({
|
|
329
|
+
format: "expand",
|
|
330
|
+
contextLoader,
|
|
331
|
+
})) as unknown as Record<string, unknown>[];
|
|
332
|
+
for (const alias of ["first", "second"]) {
|
|
333
|
+
if (policy === "canonical") {
|
|
334
|
+
ok(!(`${NS}${alias}` in expanded[0]));
|
|
335
|
+
ok(!(alias in compact));
|
|
336
|
+
} else {
|
|
337
|
+
deepStrictEqual(
|
|
338
|
+
expanded[0][`${NS}${alias}`],
|
|
339
|
+
expanded[0][`${NS}value`],
|
|
340
|
+
);
|
|
341
|
+
deepStrictEqual(compact[alias], compact.value);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
const roundtrip = await Fixture.fromJsonLd(compact, {
|
|
345
|
+
contextLoader,
|
|
346
|
+
});
|
|
347
|
+
deepStrictEqual(
|
|
348
|
+
container === "list"
|
|
349
|
+
? roundtrip.values
|
|
350
|
+
: roundtrip.values.map((v) => (v as { label: string }).label),
|
|
351
|
+
container === "list" ? ["a", "b", "a"] : ["a", "b"],
|
|
352
|
+
);
|
|
353
|
+
const empty = await Fixture.fromJsonLd(
|
|
354
|
+
document({
|
|
355
|
+
[`${NS}value`]: [{ [`@${container}`]: [] }],
|
|
356
|
+
[`${NS}first`]: set,
|
|
357
|
+
}),
|
|
358
|
+
{ contextLoader },
|
|
359
|
+
);
|
|
360
|
+
deepStrictEqual(empty.values, []);
|
|
361
|
+
},
|
|
362
|
+
);
|
|
344
363
|
});
|
|
345
364
|
}
|
|
346
365
|
}
|
|
@@ -348,132 +367,146 @@ for (const container of ["list", "graph"] as const) {
|
|
|
348
367
|
for (const functional of [false, true]) {
|
|
349
368
|
test(`URI-only aliases and portable read keys (functional=${functional})`, async () => {
|
|
350
369
|
for (const policy of ["all", "canonical"] as const) {
|
|
351
|
-
await withFixture(
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
370
|
+
await withFixture(
|
|
371
|
+
{
|
|
372
|
+
...(functional ? { functional: true } : {}),
|
|
373
|
+
range: [`${XSD}anyURI`],
|
|
374
|
+
redundantPropertiesWrite: policy,
|
|
375
|
+
redundantProperties: [{ uri: `${NS}first` }],
|
|
376
|
+
},
|
|
377
|
+
async (Fixture, contextLoader, source) => {
|
|
378
|
+
ok(!source.includes("result[undefined]"));
|
|
379
|
+
match(source, /PORTABLE_IRI_KEYS[^\n]+https:\/\/example.com\/first/);
|
|
380
|
+
const url = new URL("https://example.com/object");
|
|
381
|
+
const instance = new Fixture(
|
|
382
|
+
functional ? { value: url } : { values: [url] },
|
|
383
|
+
);
|
|
384
|
+
const compact = await instance.toJsonLd({
|
|
385
|
+
format: "compact",
|
|
386
|
+
contextLoader,
|
|
387
|
+
});
|
|
388
|
+
deepStrictEqual(await instance.toJsonLd({ contextLoader }), compact);
|
|
389
|
+
const expanded = (await instance.toJsonLd({
|
|
390
|
+
format: "expand",
|
|
391
|
+
contextLoader,
|
|
392
|
+
})) as unknown as Record<string, unknown>[];
|
|
393
|
+
if (policy === "all") {
|
|
394
|
+
deepStrictEqual(expanded[0][`${NS}first`], [{ "@id": url.href }]);
|
|
395
|
+
} else ok(!(`${NS}first` in expanded[0]));
|
|
396
|
+
const custom = await instance.toJsonLd({
|
|
397
|
+
format: "compact",
|
|
398
|
+
contextLoader,
|
|
399
|
+
context: {
|
|
400
|
+
type: "@type",
|
|
401
|
+
Fixture: `${NS}Fixture`,
|
|
402
|
+
value: { "@id": `${NS}value`, "@type": "@id" },
|
|
403
|
+
},
|
|
404
|
+
});
|
|
405
|
+
if (policy === "all") {
|
|
406
|
+
deepStrictEqual(custom[`${NS}first`], { "@id": url.href });
|
|
407
|
+
} else {
|
|
408
|
+
ok(!(`${NS}first` in custom));
|
|
409
|
+
}
|
|
410
|
+
const parsed = await Fixture.fromJsonLd(
|
|
411
|
+
document({
|
|
412
|
+
[`${NS}first`]: [{ "@id": "ap://did:key:z6Mkabc/objects/1" }],
|
|
413
|
+
}),
|
|
414
|
+
{ contextLoader },
|
|
415
|
+
);
|
|
416
|
+
const value = functional ? parsed.value : parsed.values[0];
|
|
417
|
+
ok(value instanceof URL);
|
|
418
|
+
const cached = await parsed.toJsonLd({ contextLoader });
|
|
419
|
+
deepStrictEqual(cached[`${NS}first`], [
|
|
420
|
+
{
|
|
421
|
+
"@id": "ap+ef61://did:key:z6Mkabc/objects/1",
|
|
422
|
+
},
|
|
423
|
+
]);
|
|
424
|
+
const compactInput = await Fixture.fromJsonLd(
|
|
425
|
+
{
|
|
426
|
+
"@context": [AS, CONTEXT],
|
|
427
|
+
type: "Fixture",
|
|
428
|
+
first: "ap://did:key:z6Mkabc/objects/1",
|
|
429
|
+
},
|
|
430
|
+
{ contextLoader },
|
|
431
|
+
);
|
|
432
|
+
const compactCache = await compactInput.toJsonLd({ contextLoader });
|
|
433
|
+
deepStrictEqual(
|
|
434
|
+
compactCache.first,
|
|
435
|
+
"ap+ef61://did:key:z6Mkabc/objects/1",
|
|
436
|
+
);
|
|
437
|
+
},
|
|
438
|
+
);
|
|
412
439
|
}
|
|
413
440
|
});
|
|
414
441
|
}
|
|
415
442
|
|
|
416
443
|
test("absolute IRIs are read from nodes and plain literals without a base", async () => {
|
|
417
|
-
await withFixture(
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
444
|
+
await withFixture(
|
|
445
|
+
{
|
|
446
|
+
range: ["fedify:absoluteIri"],
|
|
447
|
+
redundantPropertiesWrite: "canonical",
|
|
448
|
+
redundantProperties: [{ uri: `${NS}first` }],
|
|
449
|
+
},
|
|
450
|
+
async (Fixture, contextLoader, source) => {
|
|
451
|
+
match(source, /PORTABLE_IRI_KEYS[^\n]+https:\/\/example.com\/value/);
|
|
452
|
+
match(source, /PORTABLE_IRI_KEYS[^\n]+https:\/\/example.com\/first/);
|
|
453
|
+
const values = [
|
|
454
|
+
{ "@id": "https://example.com/node" },
|
|
455
|
+
literal("urn:example:literal"),
|
|
456
|
+
{ "@value": "https://example.com/any-uri", "@type": `${XSD}anyURI` },
|
|
457
|
+
{ "@value": "https://example.com/string", "@type": `${XSD}string` },
|
|
458
|
+
// A context's default language tags uncoerced strings:
|
|
459
|
+
{ "@value": "https://example.com/tagged", "@language": "und" },
|
|
460
|
+
// Relative IRIs are never resolved against the object's ID:
|
|
461
|
+
{ "@id": "CC-BY-4.0" },
|
|
462
|
+
{ "@id": "_:b0" },
|
|
463
|
+
literal("Creative Commons Attribution 4.0 International"),
|
|
464
|
+
{ "@value": "https://example.com/date", "@type": `${XSD}date` },
|
|
465
|
+
];
|
|
466
|
+
const expected = [
|
|
467
|
+
new URL("https://example.com/node"),
|
|
468
|
+
new URL("urn:example:literal"),
|
|
469
|
+
new URL("https://example.com/any-uri"),
|
|
470
|
+
new URL("https://example.com/string"),
|
|
471
|
+
new URL("https://example.com/tagged"),
|
|
472
|
+
];
|
|
473
|
+
for (const key of ["value", "first"]) {
|
|
474
|
+
const parsed = await Fixture.fromJsonLd(
|
|
475
|
+
{
|
|
476
|
+
"@id": "https://example.com/objects/1",
|
|
477
|
+
...document({ [`${NS}${key}`]: values }),
|
|
478
|
+
},
|
|
479
|
+
{ contextLoader, baseUrl: new URL("https://example.com/base/") },
|
|
480
|
+
);
|
|
481
|
+
deepStrictEqual(parsed.values, expected);
|
|
482
|
+
}
|
|
483
|
+
// An invalid canonical set is not replaced by a synonym:
|
|
484
|
+
const invalid = await Fixture.fromJsonLd(
|
|
485
|
+
document({
|
|
486
|
+
[`${NS}value`]: [{ "@id": "CC-BY-4.0" }],
|
|
487
|
+
[`${NS}first`]: [{ "@id": "https://example.com/fallback" }],
|
|
488
|
+
}),
|
|
489
|
+
{ contextLoader },
|
|
451
490
|
);
|
|
452
|
-
deepStrictEqual(
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
const compact = await instance.toJsonLd({
|
|
474
|
-
format: "compact",
|
|
475
|
-
contextLoader,
|
|
476
|
-
});
|
|
477
|
-
deepStrictEqual(compact.value, expected.map((url) => url.href));
|
|
478
|
-
});
|
|
491
|
+
deepStrictEqual(invalid.values, []);
|
|
492
|
+
const instance = new Fixture({ values: expected });
|
|
493
|
+
const expanded = (await instance.toJsonLd({
|
|
494
|
+
format: "expand",
|
|
495
|
+
contextLoader,
|
|
496
|
+
})) as unknown as Record<string, unknown>[];
|
|
497
|
+
deepStrictEqual(
|
|
498
|
+
expanded[0][`${NS}value`],
|
|
499
|
+
expected.map((url) => ({ "@id": url.href })),
|
|
500
|
+
);
|
|
501
|
+
ok(!(`${NS}first` in expanded[0]));
|
|
502
|
+
const compact = await instance.toJsonLd({
|
|
503
|
+
format: "compact",
|
|
504
|
+
contextLoader,
|
|
505
|
+
});
|
|
506
|
+
deepStrictEqual(
|
|
507
|
+
compact.value,
|
|
508
|
+
expected.map((url) => url.href),
|
|
509
|
+
);
|
|
510
|
+
},
|
|
511
|
+
);
|
|
479
512
|
});
|