@fedify/vocab 2.4.0-dev.1504 → 2.4.0-dev.1528
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 +3731 -2360
- package/dist/mod.js +3732 -2361
- package/dist-tests/{actor-B-hIveNP.mjs → actor-BP_hyy_7.mjs} +2 -2
- package/dist-tests/actor.test.mjs +2 -2
- package/dist-tests/lookup.test.mjs +7 -5
- package/dist-tests/type.test.mjs +1 -1
- package/dist-tests/{vocab-XnSGFOqq.mjs → vocab-CQX0Zq_l.mjs} +3727 -2358
- package/dist-tests/vocab.test.mjs +788 -1
- package/package.json +5 -8
- package/scripts/codegen.ts +38 -13
- package/src/lookup.ts +6 -2
- package/src/vocab.test.ts +1132 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/vocab",
|
|
3
|
-
"version": "2.4.0-dev.
|
|
3
|
+
"version": "2.4.0-dev.1528+fea670ad",
|
|
4
4
|
"homepage": "https://fedify.dev/",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,10 +10,7 @@
|
|
|
10
10
|
"bugs": {
|
|
11
11
|
"url": "https://github.com/fedify-dev/fedify/issues"
|
|
12
12
|
},
|
|
13
|
-
"funding":
|
|
14
|
-
"https://opencollective.com/fedify",
|
|
15
|
-
"https://github.com/sponsors/dahlia"
|
|
16
|
-
],
|
|
13
|
+
"funding": "https://opencollective.com/fedify",
|
|
17
14
|
"engines": {
|
|
18
15
|
"deno": ">=2.0.0",
|
|
19
16
|
"node": ">=22.0.0",
|
|
@@ -46,9 +43,9 @@
|
|
|
46
43
|
"es-toolkit": "1.46.1",
|
|
47
44
|
"jsonld": "^9.0.0",
|
|
48
45
|
"pkijs": "^3.3.3",
|
|
49
|
-
"@fedify/vocab-tools": "2.4.0-dev.
|
|
50
|
-
"@fedify/webfinger": "2.4.0-dev.
|
|
51
|
-
"@fedify/vocab-runtime": "2.4.0-dev.
|
|
46
|
+
"@fedify/vocab-tools": "2.4.0-dev.1528+fea670ad",
|
|
47
|
+
"@fedify/webfinger": "2.4.0-dev.1528+fea670ad",
|
|
48
|
+
"@fedify/vocab-runtime": "2.4.0-dev.1528+fea670ad"
|
|
52
49
|
},
|
|
53
50
|
"devDependencies": {
|
|
54
51
|
"@types/node": "^22.17.0",
|
package/scripts/codegen.ts
CHANGED
|
@@ -7,36 +7,49 @@ const LOCK_RETRY_MS = 100;
|
|
|
7
7
|
const LOCK_TIMEOUT_MS = 60 * 1000; // 1 minute
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Get the latest mtime
|
|
10
|
+
* Get the latest mtime among files under a directory tree (recursively),
|
|
11
|
+
* limited to the given file extensions. Returns 0 if the directory is absent.
|
|
11
12
|
*/
|
|
12
|
-
async function
|
|
13
|
+
async function getLatestMtimeUnder(
|
|
14
|
+
dir: Path,
|
|
15
|
+
exts: readonly string[],
|
|
16
|
+
): Promise<number> {
|
|
17
|
+
if (!(await dir.exists())) return 0;
|
|
13
18
|
let latestMtime = 0;
|
|
14
|
-
for await (const entry of
|
|
15
|
-
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
|
|
19
|
+
for await (const entry of Deno.readDir(dir.toString())) {
|
|
20
|
+
const child = dir.join(entry.name);
|
|
21
|
+
if (entry.isDirectory) {
|
|
22
|
+
const mtime = await getLatestMtimeUnder(child, exts);
|
|
23
|
+
if (mtime > latestMtime) latestMtime = mtime;
|
|
24
|
+
} else if (entry.isFile && exts.some((ext) => entry.name.endsWith(ext))) {
|
|
25
|
+
const fileStat = await child.stat();
|
|
26
|
+
const mtime = fileStat?.mtime?.getTime() ?? 0;
|
|
27
|
+
if (mtime > latestMtime) latestMtime = mtime;
|
|
21
28
|
}
|
|
22
29
|
}
|
|
23
30
|
return latestMtime;
|
|
24
31
|
}
|
|
25
32
|
|
|
26
33
|
/**
|
|
27
|
-
* Check if the generated file is up to date compared to source files
|
|
34
|
+
* Check if the generated file is up to date compared to its source files,
|
|
35
|
+
* including the generator itself (`@fedify/vocab-tools` and this codegen
|
|
36
|
+
* script): changing the generator changes the generated output, so the
|
|
37
|
+
* generated file must be at least as new as those too.
|
|
28
38
|
*/
|
|
29
39
|
async function isUpToDate(
|
|
30
40
|
schemaDir: Path,
|
|
31
41
|
generatedPath: Path,
|
|
42
|
+
generatorMtime: number,
|
|
32
43
|
): Promise<boolean> {
|
|
33
44
|
try {
|
|
34
45
|
const [sourceMtime, generatedStat] = await Promise.all([
|
|
35
|
-
|
|
46
|
+
// Match loadSchemaFiles()'s /\.ya?ml$/i: a .yml schema is a real input.
|
|
47
|
+
getLatestMtimeUnder(schemaDir, [".yaml", ".yml"]),
|
|
36
48
|
generatedPath.stat(),
|
|
37
49
|
]);
|
|
38
50
|
if (!generatedStat?.mtime) return false;
|
|
39
|
-
return generatedStat.mtime.getTime() >=
|
|
51
|
+
return generatedStat.mtime.getTime() >=
|
|
52
|
+
Math.max(sourceMtime, generatorMtime);
|
|
40
53
|
} catch {
|
|
41
54
|
// If generated file doesn't exist, it's not up to date
|
|
42
55
|
return false;
|
|
@@ -117,8 +130,20 @@ async function codegen() {
|
|
|
117
130
|
// Acquire lock to prevent concurrent codegen
|
|
118
131
|
const lock = await acquireLock(lockPath);
|
|
119
132
|
try {
|
|
133
|
+
// The generated vocab.ts depends not only on the YAML schemas but on the
|
|
134
|
+
// generator itself: @fedify/vocab-tools and this codegen script. Sample
|
|
135
|
+
// its mtime inside the lock so that a generator edit made while we were
|
|
136
|
+
// waiting for the lock is not missed by the freshness check below.
|
|
137
|
+
const generatorMtime = Math.max(
|
|
138
|
+
await getLatestMtimeUnder(
|
|
139
|
+
packageDir.parent()!.join("vocab-tools", "src"),
|
|
140
|
+
[".ts", ".yaml", ".yml"],
|
|
141
|
+
),
|
|
142
|
+
await getLatestMtimeUnder(scriptsDir, [".ts"]),
|
|
143
|
+
);
|
|
144
|
+
|
|
120
145
|
// Check if regeneration is needed (after acquiring lock)
|
|
121
|
-
if (await isUpToDate(schemaDir, realPath)) {
|
|
146
|
+
if (await isUpToDate(schemaDir, realPath, generatorMtime)) {
|
|
122
147
|
$.log("vocab.ts is up to date, skipping codegen");
|
|
123
148
|
return;
|
|
124
149
|
}
|
package/src/lookup.ts
CHANGED
|
@@ -2,6 +2,8 @@ import type { GetUserAgentOptions } from "@fedify/vocab-runtime";
|
|
|
2
2
|
import {
|
|
3
3
|
type DocumentLoader,
|
|
4
4
|
getDocumentLoader,
|
|
5
|
+
haveSameIriOrigin,
|
|
6
|
+
parseIri,
|
|
5
7
|
type RemoteDocument,
|
|
6
8
|
} from "@fedify/vocab-runtime";
|
|
7
9
|
import { lookupWebFinger } from "@fedify/webfinger";
|
|
@@ -312,12 +314,14 @@ async function lookupObjectInternal(
|
|
|
312
314
|
}
|
|
313
315
|
if (remoteDoc == null) return null;
|
|
314
316
|
let object: Object;
|
|
317
|
+
let documentUrl: URL;
|
|
315
318
|
try {
|
|
319
|
+
documentUrl = parseIri(remoteDoc.documentUrl);
|
|
316
320
|
object = await Object.fromJsonLd(remoteDoc.document, {
|
|
317
321
|
documentLoader,
|
|
318
322
|
contextLoader: options.contextLoader,
|
|
319
323
|
tracerProvider: options.tracerProvider,
|
|
320
|
-
baseUrl:
|
|
324
|
+
baseUrl: documentUrl,
|
|
321
325
|
});
|
|
322
326
|
} catch (error) {
|
|
323
327
|
if (error instanceof TypeError) {
|
|
@@ -331,7 +335,7 @@ async function lookupObjectInternal(
|
|
|
331
335
|
}
|
|
332
336
|
if (
|
|
333
337
|
options.crossOrigin !== "trust" && object.id != null &&
|
|
334
|
-
object.id
|
|
338
|
+
!haveSameIriOrigin(object.id, documentUrl)
|
|
335
339
|
) {
|
|
336
340
|
if (options.crossOrigin === "throw") {
|
|
337
341
|
throw new Error(
|