@fedify/vocab-tools 2.5.0-dev.2562 → 2.5.0-dev.2597
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 +1 -1
- package/dist/mod.cjs +9 -8
- package/dist/mod.d.cts +13 -1
- package/dist/mod.d.ts +13 -1
- package/dist/mod.js +9 -8
- package/dist/schema.yaml +38 -10
- package/package.json +3 -3
- package/src/__snapshots__/class.test.ts.deno.snap +1737 -828
- package/src/__snapshots__/class.test.ts.node.snap +1737 -828
- package/src/__snapshots__/class.test.ts.snap +1737 -828
- package/src/inspector.ts +6 -6
- package/src/schema.test.ts +72 -0
- package/src/schema.ts +17 -1
- package/src/schema.yaml +38 -10
- package/src/type.ts +1 -0
- package/tsconfig.check.json +12 -0
package/src/inspector.ts
CHANGED
|
@@ -19,8 +19,8 @@ export async function* generateInspector(
|
|
|
19
19
|
if (this.id != null) {
|
|
20
20
|
proxy.id = {
|
|
21
21
|
[Symbol.for("Deno.customInspect")]: (
|
|
22
|
-
inspect:
|
|
23
|
-
options:
|
|
22
|
+
inspect: (value: unknown, options: unknown) => string,
|
|
23
|
+
options: unknown,
|
|
24
24
|
): string => "URL " + inspect(inspectIri(this.id!), options),
|
|
25
25
|
[Symbol.for("nodejs.util.inspect.custom")]: (
|
|
26
26
|
_depth: number,
|
|
@@ -42,8 +42,8 @@ export async function* generateInspector(
|
|
|
42
42
|
.map((v: any) => v instanceof URL
|
|
43
43
|
? {
|
|
44
44
|
[Symbol.for("Deno.customInspect")]: (
|
|
45
|
-
inspect:
|
|
46
|
-
options:
|
|
45
|
+
inspect: (value: unknown, options: unknown) => string,
|
|
46
|
+
options: unknown,
|
|
47
47
|
): string => "URL " + inspect(inspectIri(v), options),
|
|
48
48
|
[Symbol.for("nodejs.util.inspect.custom")]: (
|
|
49
49
|
_depth: number,
|
|
@@ -94,8 +94,8 @@ export async function* generateInspectorPostClass(
|
|
|
94
94
|
(${className}.prototype as any)[Symbol.for("Deno.customInspect")] =
|
|
95
95
|
function (
|
|
96
96
|
this: ${className},
|
|
97
|
-
inspect:
|
|
98
|
-
options:
|
|
97
|
+
inspect: (value: unknown, options: unknown) => string,
|
|
98
|
+
options: unknown,
|
|
99
99
|
): string {
|
|
100
100
|
const proxy = this._getCustomInspectProxy();
|
|
101
101
|
return ${JSON.stringify(type.name + " ")} + inspect(proxy, options);
|
package/src/schema.test.ts
CHANGED
|
@@ -317,3 +317,75 @@ test("loadSchemaFiles validates redundant properties on both property kinds", as
|
|
|
317
317
|
await rm(dir, { recursive: true, force: true });
|
|
318
318
|
}
|
|
319
319
|
});
|
|
320
|
+
|
|
321
|
+
test("loadSchemaFiles validates context container terms", async () => {
|
|
322
|
+
const dir = await mkdtemp(join(tmpdir(), "fedify-schema-context-"));
|
|
323
|
+
const uri = "https://example.com/Fixture";
|
|
324
|
+
const type = {
|
|
325
|
+
name: "Fixture",
|
|
326
|
+
uri,
|
|
327
|
+
entity: false,
|
|
328
|
+
description: "A fixture.",
|
|
329
|
+
properties: [],
|
|
330
|
+
};
|
|
331
|
+
const writeTerm = (term: unknown) =>
|
|
332
|
+
writeFile(
|
|
333
|
+
join(dir, "fixture.yaml"),
|
|
334
|
+
stringify({ ...type, defaultContext: [{ term }] }),
|
|
335
|
+
);
|
|
336
|
+
try {
|
|
337
|
+
for (const container of ["@set", "@list"]) {
|
|
338
|
+
await writeTerm({
|
|
339
|
+
"@id": "toot:attributionDomains",
|
|
340
|
+
"@container": container,
|
|
341
|
+
});
|
|
342
|
+
const types = await loadSchemaFiles(dir);
|
|
343
|
+
deepStrictEqual(types[uri].defaultContext, [{
|
|
344
|
+
term: {
|
|
345
|
+
"@id": "toot:attributionDomains",
|
|
346
|
+
"@container": container,
|
|
347
|
+
},
|
|
348
|
+
}]);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
await writeTerm({
|
|
352
|
+
"@id": "toot:attributionDomains",
|
|
353
|
+
"@type": "@id",
|
|
354
|
+
"@container": "@set",
|
|
355
|
+
});
|
|
356
|
+
const withType = await loadSchemaFiles(dir);
|
|
357
|
+
deepStrictEqual(withType[uri].defaultContext, [{
|
|
358
|
+
term: {
|
|
359
|
+
"@id": "toot:attributionDomains",
|
|
360
|
+
"@type": "@id",
|
|
361
|
+
"@container": "@set",
|
|
362
|
+
},
|
|
363
|
+
}]);
|
|
364
|
+
|
|
365
|
+
// The pre-existing object term shape must keep validating:
|
|
366
|
+
await writeTerm({ "@type": "@id" });
|
|
367
|
+
await loadSchemaFiles(dir);
|
|
368
|
+
|
|
369
|
+
for (
|
|
370
|
+
const invalid of [
|
|
371
|
+
{ "@id": "toot:attributionDomains", "@container": "@id" },
|
|
372
|
+
{
|
|
373
|
+
"@id": "toot:attributionDomains",
|
|
374
|
+
"@container": "https://example.com/bogus",
|
|
375
|
+
},
|
|
376
|
+
{ "@id": "toot:attributionDomains", "@container": "@bogus" },
|
|
377
|
+
{
|
|
378
|
+
"@id": "toot:attributionDomains",
|
|
379
|
+
"@container": "@set",
|
|
380
|
+
"@unknown": "@set",
|
|
381
|
+
},
|
|
382
|
+
{ "@container": "@set" },
|
|
383
|
+
]
|
|
384
|
+
) {
|
|
385
|
+
await writeTerm(invalid);
|
|
386
|
+
await rejects(loadSchemaFiles(dir), AggregateError);
|
|
387
|
+
}
|
|
388
|
+
} finally {
|
|
389
|
+
await rm(dir, { recursive: true, force: true });
|
|
390
|
+
}
|
|
391
|
+
});
|
package/src/schema.ts
CHANGED
|
@@ -260,7 +260,23 @@ export type Context = Uri | EmbeddedContext | (Uri | EmbeddedContext)[];
|
|
|
260
260
|
|
|
261
261
|
type Uri = "http://{string}" | "https://{string}";
|
|
262
262
|
type EmbeddedContext = Record<string, TermDefinition>;
|
|
263
|
-
type TermDefinition =
|
|
263
|
+
type TermDefinition =
|
|
264
|
+
| Uri
|
|
265
|
+
| Record<string, Uri | "@id">
|
|
266
|
+
| ContainerTermDefinition;
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* A term definition that carries a JSON-LD `@container` keyword.
|
|
270
|
+
*
|
|
271
|
+
* The JSON Schema in *schema.yaml* enforces this shape conditionally whenever
|
|
272
|
+
* an embedded context term has `@container`; the TypeScript union cannot
|
|
273
|
+
* express the conditional and serves only as a guide.
|
|
274
|
+
*/
|
|
275
|
+
interface ContainerTermDefinition {
|
|
276
|
+
"@id": string;
|
|
277
|
+
"@type"?: Uri | "@id";
|
|
278
|
+
"@container": "@set" | "@list";
|
|
279
|
+
}
|
|
264
280
|
|
|
265
281
|
/**
|
|
266
282
|
* Type guard to check if a property is not functional (has pluralName).
|
package/src/schema.yaml
CHANGED
|
@@ -228,16 +228,44 @@ $defs:
|
|
|
228
228
|
$ref: "#/$defs/ldTermDefinition"
|
|
229
229
|
|
|
230
230
|
ldTermDefinition:
|
|
231
|
-
|
|
232
|
-
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
231
|
+
allOf:
|
|
232
|
+
- anyOf:
|
|
233
|
+
- type: string
|
|
234
|
+
format: uri
|
|
235
|
+
- type: object
|
|
236
|
+
patternProperties:
|
|
237
|
+
"^.+$":
|
|
238
|
+
anyOf:
|
|
239
|
+
- type: string
|
|
240
|
+
format: uri
|
|
241
|
+
- const: "@id"
|
|
242
|
+
- $ref: "#/$defs/ldContainerTermDefinition"
|
|
243
|
+
- if:
|
|
244
|
+
type: object
|
|
245
|
+
required:
|
|
246
|
+
- "@container"
|
|
247
|
+
then:
|
|
248
|
+
$ref: "#/$defs/ldContainerTermDefinition"
|
|
249
|
+
|
|
250
|
+
ldContainerTermDefinition:
|
|
251
|
+
type: object
|
|
252
|
+
properties:
|
|
253
|
+
"@id":
|
|
254
|
+
type: string
|
|
255
|
+
format: uri
|
|
256
|
+
"@type":
|
|
257
|
+
anyOf:
|
|
258
|
+
- type: string
|
|
259
|
+
format: uri
|
|
260
|
+
- const: "@id"
|
|
261
|
+
"@container":
|
|
262
|
+
enum:
|
|
263
|
+
- "@set"
|
|
264
|
+
- "@list"
|
|
265
|
+
required:
|
|
266
|
+
- "@id"
|
|
267
|
+
- "@container"
|
|
268
|
+
additionalProperties: false
|
|
241
269
|
|
|
242
270
|
description: The schema of a type. It is used to generate a class.
|
|
243
271
|
type: object
|
package/src/type.ts
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.node.json",
|
|
3
|
+
"include": ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts"],
|
|
4
|
+
"exclude": [
|
|
5
|
+
"dist",
|
|
6
|
+
"dist-tests",
|
|
7
|
+
"node_modules",
|
|
8
|
+
// Uses Deno's @std/testing and bun:test snapshots; owned by
|
|
9
|
+
// check:types:deno until #1288.
|
|
10
|
+
"src/class.test.ts"
|
|
11
|
+
]
|
|
12
|
+
}
|