@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.
- package/dist/mod.cjs +822 -99
- package/dist/mod.js +822 -99
- package/package.json +19 -2
- package/deno.json +0 -32
- package/src/__snapshots__/class.test.ts.deno.snap +0 -169445
- package/src/__snapshots__/class.test.ts.node.snap +0 -169443
- package/src/__snapshots__/class.test.ts.snap +0 -169445
- package/src/class.test.ts +0 -299
- package/src/class.ts +0 -490
- package/src/codec.test.ts +0 -512
- package/src/codec.ts +0 -695
- package/src/constructor.ts +0 -467
- package/src/deep-clone.ts +0 -176
- package/src/field.ts +0 -48
- package/src/fs.test.ts +0 -31
- package/src/fs.ts +0 -21
- package/src/generate.ts +0 -24
- package/src/inspector.ts +0 -117
- package/src/mod.ts +0 -8
- package/src/property-array.ts +0 -198
- package/src/property.ts +0 -755
- package/src/schema.test.ts +0 -389
- package/src/schema.ts +0 -444
- package/src/schema.yaml +0 -336
- package/src/type.ts +0 -744
- package/tsconfig.check.json +0 -12
- package/tsdown.config.ts +0 -30
package/src/schema.test.ts
DELETED
|
@@ -1,389 +0,0 @@
|
|
|
1
|
-
import { deepStrictEqual, ok, rejects, throws } from "node:assert";
|
|
2
|
-
import { test } from "node:test";
|
|
3
|
-
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import { stringify } from "yaml";
|
|
7
|
-
import {
|
|
8
|
-
hasSingularAccessor,
|
|
9
|
-
isNonFunctionalProperty,
|
|
10
|
-
loadSchemaFiles,
|
|
11
|
-
type PropertySchema,
|
|
12
|
-
type TypeSchema,
|
|
13
|
-
type TypeUri,
|
|
14
|
-
validateTypeSchemas,
|
|
15
|
-
} from "./schema.ts";
|
|
16
|
-
|
|
17
|
-
test(
|
|
18
|
-
"isNonFunctionalProperty: " + "returns true for non-functional property",
|
|
19
|
-
() => {
|
|
20
|
-
const property: PropertySchema = {
|
|
21
|
-
singularName: "name",
|
|
22
|
-
pluralName: "names",
|
|
23
|
-
uri: "https://example.com/name",
|
|
24
|
-
description: "A name property",
|
|
25
|
-
range: ["https://example.com/Text"] as [TypeUri],
|
|
26
|
-
functional: false,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
ok(isNonFunctionalProperty(property));
|
|
30
|
-
|
|
31
|
-
// Type narrowing test - this should compile without errors
|
|
32
|
-
if (isNonFunctionalProperty(property)) {
|
|
33
|
-
// These properties should be accessible
|
|
34
|
-
const _pluralName = property.pluralName;
|
|
35
|
-
const _singularAccessor = property.singularAccessor;
|
|
36
|
-
const _container = property.container;
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
test(
|
|
42
|
-
"isNonFunctionalProperty: " +
|
|
43
|
-
"returns true for property without functional field",
|
|
44
|
-
() => {
|
|
45
|
-
const property: PropertySchema = {
|
|
46
|
-
singularName: "name",
|
|
47
|
-
pluralName: "names",
|
|
48
|
-
uri: "https://example.com/name",
|
|
49
|
-
description: "A name property",
|
|
50
|
-
range: ["https://example.com/Text"] as [TypeUri],
|
|
51
|
-
// functional is optional and defaults to false
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
ok(isNonFunctionalProperty(property));
|
|
55
|
-
},
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
test("isNonFunctionalProperty: returns false for functional property", () => {
|
|
59
|
-
const property: PropertySchema = {
|
|
60
|
-
singularName: "id",
|
|
61
|
-
uri: "https://example.com/id",
|
|
62
|
-
description: "An ID property",
|
|
63
|
-
range: ["https://example.com/ID"] as [TypeUri],
|
|
64
|
-
functional: true,
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
ok(!isNonFunctionalProperty(property));
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test("hasSingularAccessor: returns true for functional property", () => {
|
|
71
|
-
const property: PropertySchema = {
|
|
72
|
-
singularName: "id",
|
|
73
|
-
uri: "https://example.com/id",
|
|
74
|
-
description: "An ID property",
|
|
75
|
-
range: ["https://example.com/ID"] as [TypeUri],
|
|
76
|
-
functional: true,
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
ok(hasSingularAccessor(property));
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test(
|
|
83
|
-
"hasSingularAccessor: " +
|
|
84
|
-
"returns true for non-functional property with singularAccessor",
|
|
85
|
-
() => {
|
|
86
|
-
const property: PropertySchema = {
|
|
87
|
-
singularName: "name",
|
|
88
|
-
pluralName: "names",
|
|
89
|
-
uri: "https://example.com/name",
|
|
90
|
-
description: "A name property",
|
|
91
|
-
range: ["https://example.com/Text"] as [TypeUri],
|
|
92
|
-
functional: false,
|
|
93
|
-
singularAccessor: true,
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
ok(hasSingularAccessor(property));
|
|
97
|
-
},
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
test(
|
|
101
|
-
"hasSingularAccessor: " +
|
|
102
|
-
"returns false for non-functional property without singularAccessor",
|
|
103
|
-
() => {
|
|
104
|
-
const property: PropertySchema = {
|
|
105
|
-
singularName: "name",
|
|
106
|
-
pluralName: "names",
|
|
107
|
-
uri: "https://example.com/name",
|
|
108
|
-
description: "A name property",
|
|
109
|
-
range: ["https://example.com/Text"] as [TypeUri],
|
|
110
|
-
functional: false,
|
|
111
|
-
singularAccessor: false,
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
ok(!hasSingularAccessor(property));
|
|
115
|
-
},
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
test(
|
|
119
|
-
"hasSingularAccessor: " +
|
|
120
|
-
"returns false for non-functional property with undefined singularAccessor",
|
|
121
|
-
() => {
|
|
122
|
-
const property: PropertySchema = {
|
|
123
|
-
singularName: "name",
|
|
124
|
-
pluralName: "names",
|
|
125
|
-
uri: "https://example.com/name",
|
|
126
|
-
description: "A name property",
|
|
127
|
-
range: ["https://example.com/Text"] as [TypeUri],
|
|
128
|
-
// functional defaults to false, singularAccessor is undefined
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
ok(!hasSingularAccessor(property));
|
|
132
|
-
},
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
test(
|
|
136
|
-
"Type guard combinations: " + "functional property with redundantProperties",
|
|
137
|
-
() => {
|
|
138
|
-
const property: PropertySchema = {
|
|
139
|
-
singularName: "type",
|
|
140
|
-
uri: "https://www.w3.org/ns/activitystreams#type",
|
|
141
|
-
description: "The type of the object",
|
|
142
|
-
range: ["https://example.com/Type"] as [TypeUri],
|
|
143
|
-
functional: true,
|
|
144
|
-
redundantProperties: [
|
|
145
|
-
{ uri: "https://www.w3.org/1999/02/22-rdf-syntax-ns#type" },
|
|
146
|
-
],
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
ok(!isNonFunctionalProperty(property));
|
|
150
|
-
ok(hasSingularAccessor(property));
|
|
151
|
-
},
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
test("Type guard combinations: non-functional property with container", () => {
|
|
155
|
-
const property: PropertySchema = {
|
|
156
|
-
singularName: "item",
|
|
157
|
-
pluralName: "items",
|
|
158
|
-
uri: "https://example.com/item",
|
|
159
|
-
description: "List of items",
|
|
160
|
-
range: ["https://example.com/Item"] as [TypeUri],
|
|
161
|
-
functional: false,
|
|
162
|
-
container: "list",
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
ok(isNonFunctionalProperty(property));
|
|
166
|
-
ok(!hasSingularAccessor(property));
|
|
167
|
-
|
|
168
|
-
// Type narrowing test
|
|
169
|
-
if (isNonFunctionalProperty(property)) {
|
|
170
|
-
deepStrictEqual(property.container, "list");
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
|
|
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
|
-
};
|
|
184
|
-
|
|
185
|
-
ok(isNonFunctionalProperty(property));
|
|
186
|
-
ok(!hasSingularAccessor(property));
|
|
187
|
-
|
|
188
|
-
// Type narrowing test
|
|
189
|
-
if (isNonFunctionalProperty(property)) {
|
|
190
|
-
deepStrictEqual(property.container, "graph");
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
test("Type guard combinations: untyped property", () => {
|
|
195
|
-
const property: PropertySchema = {
|
|
196
|
-
singularName: "value",
|
|
197
|
-
pluralName: "values",
|
|
198
|
-
uri: "https://example.com/value",
|
|
199
|
-
description: "Untyped values",
|
|
200
|
-
untyped: true,
|
|
201
|
-
range: ["https://example.com/Value"] as [TypeUri],
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
ok(isNonFunctionalProperty(property));
|
|
205
|
-
ok(!hasSingularAccessor(property));
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
test("validateTypeSchemas() rejects mixed fedify:vocabEntityType ranges", () => {
|
|
209
|
-
const types: Record<string, TypeSchema> = {
|
|
210
|
-
"https://example.com/tombstone": {
|
|
211
|
-
name: "Tombstone",
|
|
212
|
-
uri: "https://example.com/tombstone" as TypeUri,
|
|
213
|
-
compactName: "Tombstone",
|
|
214
|
-
entity: true,
|
|
215
|
-
description: "A tombstone.",
|
|
216
|
-
properties: [
|
|
217
|
-
{
|
|
218
|
-
singularName: "formerType",
|
|
219
|
-
pluralName: "formerTypes",
|
|
220
|
-
uri: "https://example.com/formerType",
|
|
221
|
-
compactName: "formerType",
|
|
222
|
-
description: "The former type.",
|
|
223
|
-
range: [
|
|
224
|
-
"fedify:vocabEntityType",
|
|
225
|
-
"http://www.w3.org/2001/XMLSchema#anyURI",
|
|
226
|
-
] as [TypeUri, TypeUri],
|
|
227
|
-
},
|
|
228
|
-
],
|
|
229
|
-
defaultContext:
|
|
230
|
-
"https://example.com/context" as TypeSchema["defaultContext"],
|
|
231
|
-
},
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
throws(
|
|
235
|
-
() => validateTypeSchemas(types),
|
|
236
|
-
(error) => {
|
|
237
|
-
ok(error instanceof TypeError);
|
|
238
|
-
deepStrictEqual(
|
|
239
|
-
error.message,
|
|
240
|
-
"The property Tombstone.formerType cannot mix fedify:vocabEntityType " +
|
|
241
|
-
"with other range types because the generated decoder cannot " +
|
|
242
|
-
"disambiguate entity type references from ordinary IRIs.",
|
|
243
|
-
);
|
|
244
|
-
return true;
|
|
245
|
-
},
|
|
246
|
-
);
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
test("loadSchemaFiles validates redundant properties on both property kinds", async () => {
|
|
250
|
-
const dir = await mkdtemp(join(tmpdir(), "fedify-schema-"));
|
|
251
|
-
try {
|
|
252
|
-
for (const functional of [false, true]) {
|
|
253
|
-
const property = {
|
|
254
|
-
singularName: "value",
|
|
255
|
-
...(functional ? { functional: true } : { pluralName: "values" }),
|
|
256
|
-
uri: "https://example.com/value",
|
|
257
|
-
description: "A value.",
|
|
258
|
-
range: ["http://www.w3.org/2001/XMLSchema#string"],
|
|
259
|
-
redundantProperties: [{ uri: "https://example.com/alias" }],
|
|
260
|
-
};
|
|
261
|
-
const type = {
|
|
262
|
-
name: "Fixture",
|
|
263
|
-
uri: "https://example.com/Fixture",
|
|
264
|
-
entity: false,
|
|
265
|
-
description: "A fixture.",
|
|
266
|
-
defaultContext: {},
|
|
267
|
-
properties: [property],
|
|
268
|
-
};
|
|
269
|
-
for (const policy of [undefined, "all", "canonical"]) {
|
|
270
|
-
await writeFile(
|
|
271
|
-
join(dir, "fixture.yaml"),
|
|
272
|
-
stringify({
|
|
273
|
-
...type,
|
|
274
|
-
properties: [{ ...property, redundantPropertiesWrite: policy }],
|
|
275
|
-
}),
|
|
276
|
-
);
|
|
277
|
-
const types = await loadSchemaFiles(dir);
|
|
278
|
-
deepStrictEqual(
|
|
279
|
-
types[type.uri].properties[0].redundantProperties,
|
|
280
|
-
property.redundantProperties,
|
|
281
|
-
);
|
|
282
|
-
deepStrictEqual(
|
|
283
|
-
types[type.uri].properties[0].redundantPropertiesWrite,
|
|
284
|
-
policy,
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
for (const invalid of [
|
|
288
|
-
{ redundantPropertiesWrite: "merge" },
|
|
289
|
-
{ redundantPropertiesWrite: 42 },
|
|
290
|
-
{ redundantProperties: "alias" },
|
|
291
|
-
{ redundantProperties: [{}] },
|
|
292
|
-
{ redundantProperties: [{ uri: 42 }] },
|
|
293
|
-
{
|
|
294
|
-
redundantProperties: [
|
|
295
|
-
{
|
|
296
|
-
uri: "https://example.com/alias",
|
|
297
|
-
compactName: 42,
|
|
298
|
-
},
|
|
299
|
-
],
|
|
300
|
-
},
|
|
301
|
-
]) {
|
|
302
|
-
await writeFile(
|
|
303
|
-
join(dir, "fixture.yaml"),
|
|
304
|
-
stringify({
|
|
305
|
-
...type,
|
|
306
|
-
properties: [{ ...property, ...invalid }],
|
|
307
|
-
}),
|
|
308
|
-
);
|
|
309
|
-
await rejects(loadSchemaFiles(dir), AggregateError);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
} finally {
|
|
313
|
-
await rm(dir, { recursive: true, force: true });
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
test("loadSchemaFiles validates context container terms", async () => {
|
|
318
|
-
const dir = await mkdtemp(join(tmpdir(), "fedify-schema-context-"));
|
|
319
|
-
const uri = "https://example.com/Fixture";
|
|
320
|
-
const type = {
|
|
321
|
-
name: "Fixture",
|
|
322
|
-
uri,
|
|
323
|
-
entity: false,
|
|
324
|
-
description: "A fixture.",
|
|
325
|
-
properties: [],
|
|
326
|
-
};
|
|
327
|
-
const writeTerm = (term: unknown) =>
|
|
328
|
-
writeFile(
|
|
329
|
-
join(dir, "fixture.yaml"),
|
|
330
|
-
stringify({ ...type, defaultContext: [{ term }] }),
|
|
331
|
-
);
|
|
332
|
-
try {
|
|
333
|
-
for (const container of ["@set", "@list"]) {
|
|
334
|
-
await writeTerm({
|
|
335
|
-
"@id": "toot:attributionDomains",
|
|
336
|
-
"@container": container,
|
|
337
|
-
});
|
|
338
|
-
const types = await loadSchemaFiles(dir);
|
|
339
|
-
deepStrictEqual(types[uri].defaultContext, [
|
|
340
|
-
{
|
|
341
|
-
term: {
|
|
342
|
-
"@id": "toot:attributionDomains",
|
|
343
|
-
"@container": container,
|
|
344
|
-
},
|
|
345
|
-
},
|
|
346
|
-
]);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
await writeTerm({
|
|
350
|
-
"@id": "toot:attributionDomains",
|
|
351
|
-
"@type": "@id",
|
|
352
|
-
"@container": "@set",
|
|
353
|
-
});
|
|
354
|
-
const withType = await loadSchemaFiles(dir);
|
|
355
|
-
deepStrictEqual(withType[uri].defaultContext, [
|
|
356
|
-
{
|
|
357
|
-
term: {
|
|
358
|
-
"@id": "toot:attributionDomains",
|
|
359
|
-
"@type": "@id",
|
|
360
|
-
"@container": "@set",
|
|
361
|
-
},
|
|
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 (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
|
-
]) {
|
|
383
|
-
await writeTerm(invalid);
|
|
384
|
-
await rejects(loadSchemaFiles(dir), AggregateError);
|
|
385
|
-
}
|
|
386
|
-
} finally {
|
|
387
|
-
await rm(dir, { recursive: true, force: true });
|
|
388
|
-
}
|
|
389
|
-
});
|