@mfdaves/okf-mcp 0.3.3 → 0.5.0
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/.agents/skills/okf-v02-migration/SKILL.md +37 -0
- package/.agents/skills/okf-v02-migration/agents/openai.yaml +6 -0
- package/.agents/skills/okf-v02-migration/references/field-mapping.md +26 -0
- package/README.md +192 -78
- package/okf/bundles/okf-mcp/distribution/reference-bundle.md +2 -2
- package/okf/bundles/okf-mcp/index.md +7 -0
- package/okf/bundles/okf-mcp/interfaces/http-authoring-api.md +2 -2
- package/okf/bundles/okf-mcp/interfaces/mcp-tools.md +8 -4
- package/okf/bundles/okf-mcp/overview/okf-mcp.md +2 -2
- package/okf/bundles/okf-mcp/policies/authoring-safety.md +5 -3
- package/okf/bundles/okf-mcp/runtime/file-concept-store.md +7 -5
- package/okf/bundles/okf-mcp/runtime/indexer.md +6 -4
- package/okf/bundles/okf-mcp/runtime/mcp-server.md +6 -6
- package/okf/bundles/okf-mcp/specs/attested-computation.md +24 -0
- package/okf/bundles/okf-mcp/specs/concept-format.md +5 -3
- package/okf/bundles/okf-mcp/specs/git-sources.md +23 -0
- package/okf/bundles/okf-mcp/workflows/v02-migration.md +24 -0
- package/package.json +9 -3
- package/server.json +5 -5
- package/src/assets.js +469 -0
- package/src/authoring.js +492 -20
- package/src/cli.js +467 -37
- package/src/computation.js +366 -0
- package/src/git-source.js +551 -0
- package/src/graph.js +71 -18
- package/src/http-server.js +8 -1
- package/src/index.js +5 -0
- package/src/indexer.js +428 -24
- package/src/markdown.js +129 -0
- package/src/mcp-server.js +447 -313
- package/src/migration.js +687 -0
- package/src/parser.js +135 -54
- package/src/plugins.js +30 -50
- package/src/project.js +74 -17
- package/src/remote.js +232 -17
- package/src/search.js +69 -6
- package/src/store.js +421 -25
- package/src/v02.js +545 -0
- package/src/validation.js +13 -2
- package/src/mcp-protocol.js +0 -283
package/src/assets.js
ADDED
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const crypto = require("crypto");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
|
|
7
|
+
const DEFAULT_MAX_ASSET_BYTES = 1024 * 1024;
|
|
8
|
+
|
|
9
|
+
const MIME_TYPES = Object.freeze({
|
|
10
|
+
".css": "text/css",
|
|
11
|
+
".csv": "text/csv",
|
|
12
|
+
".graphql": "application/graphql",
|
|
13
|
+
".gql": "application/graphql",
|
|
14
|
+
".html": "text/html",
|
|
15
|
+
".htm": "text/html",
|
|
16
|
+
".js": "text/javascript",
|
|
17
|
+
".json": "application/json",
|
|
18
|
+
".md": "text/markdown",
|
|
19
|
+
".proto": "text/plain",
|
|
20
|
+
".py": "text/x-python",
|
|
21
|
+
".sh": "text/x-shellscript",
|
|
22
|
+
".sql": "application/sql",
|
|
23
|
+
".toml": "application/toml",
|
|
24
|
+
".ts": "text/typescript",
|
|
25
|
+
".txt": "text/plain",
|
|
26
|
+
".xml": "application/xml",
|
|
27
|
+
".yaml": "application/yaml",
|
|
28
|
+
".yml": "application/yaml",
|
|
29
|
+
".gif": "image/gif",
|
|
30
|
+
".gz": "application/gzip",
|
|
31
|
+
".jpeg": "image/jpeg",
|
|
32
|
+
".jpg": "image/jpeg",
|
|
33
|
+
".pdf": "application/pdf",
|
|
34
|
+
".png": "image/png",
|
|
35
|
+
".svg": "image/svg+xml",
|
|
36
|
+
".webp": "image/webp",
|
|
37
|
+
".zip": "application/zip",
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const TEXT_APPLICATION_MIME_TYPES = new Set([
|
|
41
|
+
"application/graphql",
|
|
42
|
+
"application/json",
|
|
43
|
+
"application/sql",
|
|
44
|
+
"application/toml",
|
|
45
|
+
"application/xml",
|
|
46
|
+
"application/yaml",
|
|
47
|
+
"image/svg+xml",
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
const BINARY_MIME_PREFIXES = ["audio/", "video/"];
|
|
51
|
+
const BINARY_MIME_TYPES = new Set([
|
|
52
|
+
"application/gzip",
|
|
53
|
+
"application/pdf",
|
|
54
|
+
"application/zip",
|
|
55
|
+
"image/gif",
|
|
56
|
+
"image/jpeg",
|
|
57
|
+
"image/png",
|
|
58
|
+
"image/webp",
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
class AssetRegistryError extends Error {
|
|
62
|
+
constructor(code, message) {
|
|
63
|
+
super(message);
|
|
64
|
+
this.name = "AssetRegistryError";
|
|
65
|
+
this.code = code;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function normalizeSlashes(value) {
|
|
70
|
+
return String(value || "").replace(/\\/g, "/");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function assetKey(bundle, relativePath) {
|
|
74
|
+
return `${String(bundle || "")}:${normalizeSlashes(relativePath)}`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function isExternalReference(value) {
|
|
78
|
+
const text = String(value || "").trim();
|
|
79
|
+
return (
|
|
80
|
+
text.startsWith("//")
|
|
81
|
+
|| text.startsWith("#")
|
|
82
|
+
|| /^[A-Za-z][A-Za-z0-9+.-]*:/.test(text)
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function looksLikeExplicitSourcePath(value) {
|
|
87
|
+
const text = normalizeSlashes(String(value || "").trim());
|
|
88
|
+
if (!text || isExternalReference(text) || text.includes("\0")) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
return (
|
|
92
|
+
text.startsWith("/")
|
|
93
|
+
|| text.startsWith("./")
|
|
94
|
+
|| text.startsWith("../")
|
|
95
|
+
|| text.startsWith("references/")
|
|
96
|
+
|| (text.includes("/") && Boolean(path.posix.extname(text)))
|
|
97
|
+
|| Object.prototype.hasOwnProperty.call(MIME_TYPES, path.posix.extname(text).toLowerCase())
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function isLocalAssetReference(value, options) {
|
|
102
|
+
if (typeof value !== "string") {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
const text = value.trim();
|
|
106
|
+
if (!text || text.includes("\0") || isExternalReference(text)) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
return Boolean(options && options.allowBare) || looksLikeExplicitSourcePath(text);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function documentValue(document, key) {
|
|
113
|
+
const layers = [
|
|
114
|
+
document,
|
|
115
|
+
document && document.signals,
|
|
116
|
+
document && document.normalized,
|
|
117
|
+
document && document.v02,
|
|
118
|
+
document && document.frontmatter,
|
|
119
|
+
document && document.metadata,
|
|
120
|
+
];
|
|
121
|
+
for (const layer of layers) {
|
|
122
|
+
if (layer && Object.prototype.hasOwnProperty.call(layer, key)) {
|
|
123
|
+
return layer[key];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function collectAssetReferences(document) {
|
|
130
|
+
if (!document || typeof document !== "object") {
|
|
131
|
+
return [];
|
|
132
|
+
}
|
|
133
|
+
const bundle = String(document.bundle || "").trim();
|
|
134
|
+
const fromPath = normalizeSlashes(document.path || "");
|
|
135
|
+
const referencedByUri = document.uri || document.pathUri || "";
|
|
136
|
+
const references = [];
|
|
137
|
+
|
|
138
|
+
function add(role, field, value, allowBare) {
|
|
139
|
+
if (!isLocalAssetReference(value, { allowBare })) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
references.push({
|
|
143
|
+
bundle,
|
|
144
|
+
fromPath,
|
|
145
|
+
referencedByUri,
|
|
146
|
+
role,
|
|
147
|
+
field,
|
|
148
|
+
value: String(value).trim(),
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
add("resource", "resource", documentValue(document, "resource"), true);
|
|
153
|
+
|
|
154
|
+
const sources = documentValue(document, "sources");
|
|
155
|
+
if (Array.isArray(sources)) {
|
|
156
|
+
sources.forEach((source, index) => {
|
|
157
|
+
if (source && typeof source === "object" && !Array.isArray(source)) {
|
|
158
|
+
add("source", `sources[${index}].resource`, source.resource, false);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const computation = documentValue(document, "computation");
|
|
164
|
+
if (typeof computation === "string") {
|
|
165
|
+
add("computation", "computation", computation, true);
|
|
166
|
+
} else if (computation && typeof computation === "object" && !Array.isArray(computation)) {
|
|
167
|
+
const fileComputation = computation.mode === "file"
|
|
168
|
+
? computation
|
|
169
|
+
: computation.computation && computation.computation.mode === "file"
|
|
170
|
+
? computation.computation
|
|
171
|
+
: null;
|
|
172
|
+
if (fileComputation) {
|
|
173
|
+
add("computation", "computation", fileComputation.path, true);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const executor = documentValue(document, "executor")
|
|
178
|
+
|| (computation && typeof computation === "object" && computation.executor);
|
|
179
|
+
if (executor && typeof executor === "object" && !Array.isArray(executor)) {
|
|
180
|
+
add("executor", "executor.resource", executor.resource, true);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const attester = documentValue(document, "attester")
|
|
184
|
+
|| (computation && typeof computation === "object" && computation.attester);
|
|
185
|
+
if (attester && typeof attester === "object" && !Array.isArray(attester)) {
|
|
186
|
+
add("attester", "attester.resource", attester.resource, true);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return references;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function isInsidePath(root, target) {
|
|
193
|
+
const relative = path.relative(path.resolve(root), path.resolve(target));
|
|
194
|
+
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function resolveBundleAssetPath(bundleRoot, fromPath, reference) {
|
|
198
|
+
if (!bundleRoot) {
|
|
199
|
+
throw new AssetRegistryError("asset_bundle_root_missing", "Referenced asset has no local bundle root.");
|
|
200
|
+
}
|
|
201
|
+
const raw = normalizeSlashes(String(reference || "").trim());
|
|
202
|
+
if (!raw || raw.includes("\0") || isExternalReference(raw)) {
|
|
203
|
+
throw new AssetRegistryError("asset_invalid_reference", "Referenced asset is not a safe bundle-local path.");
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const root = path.resolve(bundleRoot);
|
|
207
|
+
const relative = raw.startsWith("/")
|
|
208
|
+
? path.posix.normalize(raw.slice(1))
|
|
209
|
+
: path.posix.normalize(path.posix.join(path.posix.dirname(normalizeSlashes(fromPath || "")), raw));
|
|
210
|
+
if (!relative || relative === "." || relative === ".." || relative.startsWith("../") || path.posix.isAbsolute(relative)) {
|
|
211
|
+
throw new AssetRegistryError("asset_outside_root", `Referenced asset resolves outside bundle root: ${raw}`);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const absolutePath = path.resolve(root, ...relative.split("/"));
|
|
215
|
+
if (!isInsidePath(root, absolutePath)) {
|
|
216
|
+
throw new AssetRegistryError("asset_outside_root", `Referenced asset resolves outside bundle root: ${raw}`);
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
root,
|
|
220
|
+
path: normalizeSlashes(relative),
|
|
221
|
+
absolutePath,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function inspectAssetPath(root, relativePath) {
|
|
226
|
+
let rootStat;
|
|
227
|
+
try {
|
|
228
|
+
rootStat = fs.lstatSync(root);
|
|
229
|
+
} catch (error) {
|
|
230
|
+
if (error && error.code === "ENOENT") {
|
|
231
|
+
throw new AssetRegistryError("asset_bundle_root_missing", `Bundle root does not exist: ${root}`);
|
|
232
|
+
}
|
|
233
|
+
throw error;
|
|
234
|
+
}
|
|
235
|
+
if (rootStat.isSymbolicLink()) {
|
|
236
|
+
throw new AssetRegistryError("asset_symlink", "Referenced assets cannot use a symbolic-link bundle root.");
|
|
237
|
+
}
|
|
238
|
+
if (!rootStat.isDirectory()) {
|
|
239
|
+
throw new AssetRegistryError("asset_bundle_root_invalid", `Bundle root is not a directory: ${root}`);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const segments = normalizeSlashes(relativePath).split("/");
|
|
243
|
+
let current = root;
|
|
244
|
+
for (let index = 0; index < segments.length; index += 1) {
|
|
245
|
+
current = path.join(current, segments[index]);
|
|
246
|
+
let stat;
|
|
247
|
+
try {
|
|
248
|
+
stat = fs.lstatSync(current);
|
|
249
|
+
} catch (error) {
|
|
250
|
+
if (error && error.code === "ENOENT") {
|
|
251
|
+
throw new AssetRegistryError("asset_missing", `Referenced asset does not exist: ${relativePath}`);
|
|
252
|
+
}
|
|
253
|
+
throw error;
|
|
254
|
+
}
|
|
255
|
+
if (stat.isSymbolicLink()) {
|
|
256
|
+
throw new AssetRegistryError("asset_symlink", `Referenced asset path traverses a symbolic link: ${relativePath}`);
|
|
257
|
+
}
|
|
258
|
+
if (index < segments.length - 1 && !stat.isDirectory()) {
|
|
259
|
+
throw new AssetRegistryError("asset_path_component_not_directory", `Referenced asset path has a non-directory component: ${relativePath}`);
|
|
260
|
+
}
|
|
261
|
+
if (index === segments.length - 1 && !stat.isFile()) {
|
|
262
|
+
throw new AssetRegistryError("asset_not_file", `Referenced asset is not a regular file: ${relativePath}`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function mimeTypeForPath(relativePath) {
|
|
268
|
+
return MIME_TYPES[path.posix.extname(String(relativePath || "")).toLowerCase()] || "application/octet-stream";
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function mimeIsDefinitelyBinary(mimeType) {
|
|
272
|
+
return BINARY_MIME_TYPES.has(mimeType) || BINARY_MIME_PREFIXES.some((prefix) => mimeType.startsWith(prefix));
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function mimeIsText(mimeType) {
|
|
276
|
+
return mimeType.startsWith("text/") || TEXT_APPLICATION_MIME_TYPES.has(mimeType);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function classifyAssetContent(content, mimeType) {
|
|
280
|
+
if (mimeIsDefinitelyBinary(mimeType) || content.includes(0)) {
|
|
281
|
+
return { kind: "binary", encoding: null, text: null, validUtf8: false };
|
|
282
|
+
}
|
|
283
|
+
try {
|
|
284
|
+
const text = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(content);
|
|
285
|
+
return { kind: "text", encoding: "utf-8", text, validUtf8: true };
|
|
286
|
+
} catch (error) {
|
|
287
|
+
return { kind: "binary", encoding: null, text: null, validUtf8: false };
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function bundleMapFor(bundles) {
|
|
292
|
+
if (bundles instanceof Map) {
|
|
293
|
+
return bundles;
|
|
294
|
+
}
|
|
295
|
+
const out = new Map();
|
|
296
|
+
if (Array.isArray(bundles)) {
|
|
297
|
+
bundles.forEach((bundle) => {
|
|
298
|
+
if (bundle && bundle.id) {
|
|
299
|
+
out.set(String(bundle.id), bundle);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
} else if (bundles && typeof bundles === "object") {
|
|
303
|
+
Object.entries(bundles).forEach(([id, bundle]) => out.set(id, bundle));
|
|
304
|
+
}
|
|
305
|
+
return out;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function diagnosticFor(error, reference, extra) {
|
|
309
|
+
const known = error instanceof AssetRegistryError;
|
|
310
|
+
return Object.assign({
|
|
311
|
+
code: known ? error.code : "asset_read_error",
|
|
312
|
+
severity: "warning",
|
|
313
|
+
layer: "project",
|
|
314
|
+
bundle: reference.bundle,
|
|
315
|
+
path: reference.fromPath,
|
|
316
|
+
field: reference.field,
|
|
317
|
+
target: reference.value,
|
|
318
|
+
message: error && error.message ? error.message : String(error),
|
|
319
|
+
}, extra || {});
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function publicReference(reference) {
|
|
323
|
+
return {
|
|
324
|
+
uri: reference.referencedByUri,
|
|
325
|
+
bundle: reference.bundle,
|
|
326
|
+
path: reference.fromPath,
|
|
327
|
+
field: reference.field,
|
|
328
|
+
role: reference.role,
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function buildAssetRegistry(documents, bundles, options) {
|
|
333
|
+
const config = options || {};
|
|
334
|
+
const maxAssetBytes = config.maxAssetBytes === undefined
|
|
335
|
+
? DEFAULT_MAX_ASSET_BYTES
|
|
336
|
+
: Number(config.maxAssetBytes);
|
|
337
|
+
if (!Number.isSafeInteger(maxAssetBytes) || maxAssetBytes < 1) {
|
|
338
|
+
throw new TypeError("maxAssetBytes must be a positive safe integer.");
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const bundleById = bundleMapFor(bundles);
|
|
342
|
+
const groups = new Map();
|
|
343
|
+
const diagnostics = [];
|
|
344
|
+
|
|
345
|
+
(documents || []).forEach((document) => {
|
|
346
|
+
collectAssetReferences(document).forEach((reference) => {
|
|
347
|
+
const configuredBundle = bundleById.get(reference.bundle);
|
|
348
|
+
const bundleRoot = document.bundleRoot || (configuredBundle && configuredBundle.root);
|
|
349
|
+
let resolved;
|
|
350
|
+
try {
|
|
351
|
+
resolved = resolveBundleAssetPath(bundleRoot, reference.fromPath, reference.value);
|
|
352
|
+
} catch (error) {
|
|
353
|
+
diagnostics.push(diagnosticFor(error, reference));
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
if (typeof config.skipResolvedPath === "function"
|
|
357
|
+
&& config.skipResolvedPath(configuredBundle || { id: reference.bundle }, resolved.path, reference)) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
if (typeof config.allowResolvedPath === "function"
|
|
361
|
+
&& !config.allowResolvedPath(configuredBundle || { id: reference.bundle }, resolved.path, reference)) {
|
|
362
|
+
diagnostics.push(diagnosticFor(
|
|
363
|
+
new AssetRegistryError("asset_excluded", `Referenced asset is excluded by bundle policy: ${resolved.path}`),
|
|
364
|
+
reference,
|
|
365
|
+
));
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
const groupKey = `${reference.bundle}\u0000${resolved.path}`;
|
|
369
|
+
if (!groups.has(groupKey)) {
|
|
370
|
+
groups.set(groupKey, {
|
|
371
|
+
key: groupKey,
|
|
372
|
+
bundle: reference.bundle,
|
|
373
|
+
root: resolved.root,
|
|
374
|
+
path: resolved.path,
|
|
375
|
+
absolutePath: resolved.absolutePath,
|
|
376
|
+
references: [],
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
groups.get(groupKey).references.push(reference);
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
const assets = [];
|
|
384
|
+
Array.from(groups.values())
|
|
385
|
+
.sort((left, right) => left.bundle.localeCompare(right.bundle) || left.path.localeCompare(right.path))
|
|
386
|
+
.forEach((group) => {
|
|
387
|
+
const first = group.references[0];
|
|
388
|
+
let content;
|
|
389
|
+
try {
|
|
390
|
+
inspectAssetPath(group.root, group.path);
|
|
391
|
+
const stat = fs.statSync(group.absolutePath);
|
|
392
|
+
if (stat.size > maxAssetBytes) {
|
|
393
|
+
throw new AssetRegistryError("asset_too_large", `Referenced asset exceeds the ${maxAssetBytes} byte limit: ${group.path}`);
|
|
394
|
+
}
|
|
395
|
+
let descriptor;
|
|
396
|
+
try {
|
|
397
|
+
descriptor = fs.openSync(group.absolutePath, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW || 0));
|
|
398
|
+
content = fs.readFileSync(descriptor);
|
|
399
|
+
} finally {
|
|
400
|
+
if (descriptor !== undefined) {
|
|
401
|
+
fs.closeSync(descriptor);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
if (content.length > maxAssetBytes) {
|
|
405
|
+
throw new AssetRegistryError("asset_too_large", `Referenced asset exceeds the ${maxAssetBytes} byte limit: ${group.path}`);
|
|
406
|
+
}
|
|
407
|
+
} catch (error) {
|
|
408
|
+
const normalizedError = error && error.code === "ELOOP"
|
|
409
|
+
? new AssetRegistryError("asset_symlink", `Referenced asset is a symbolic link: ${group.path}`)
|
|
410
|
+
: error;
|
|
411
|
+
diagnostics.push(diagnosticFor(normalizedError, first, {
|
|
412
|
+
referencedBy: group.references.map(publicReference),
|
|
413
|
+
}));
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const mimeType = mimeTypeForPath(group.path);
|
|
418
|
+
const classification = classifyAssetContent(content, mimeType);
|
|
419
|
+
const referencedBy = group.references.map(publicReference).sort((left, right) => (
|
|
420
|
+
String(left.uri).localeCompare(String(right.uri)) || left.field.localeCompare(right.field)
|
|
421
|
+
));
|
|
422
|
+
const roles = Array.from(new Set(group.references.map((reference) => reference.role))).sort();
|
|
423
|
+
const asset = {
|
|
424
|
+
key: assetKey(group.bundle, group.path),
|
|
425
|
+
bundle: group.bundle,
|
|
426
|
+
path: group.path,
|
|
427
|
+
size: content.length,
|
|
428
|
+
sha256: `sha256:${crypto.createHash("sha256").update(content).digest("hex")}`,
|
|
429
|
+
mimeType,
|
|
430
|
+
kind: classification.kind,
|
|
431
|
+
encoding: classification.encoding,
|
|
432
|
+
text: classification.text,
|
|
433
|
+
roles,
|
|
434
|
+
referencedBy,
|
|
435
|
+
};
|
|
436
|
+
Object.defineProperty(asset, "_contentBytes", {
|
|
437
|
+
configurable: false,
|
|
438
|
+
enumerable: false,
|
|
439
|
+
value: content,
|
|
440
|
+
writable: false,
|
|
441
|
+
});
|
|
442
|
+
assets.push(asset);
|
|
443
|
+
|
|
444
|
+
if (mimeIsText(mimeType) && !classification.validUtf8) {
|
|
445
|
+
diagnostics.push(diagnosticFor(
|
|
446
|
+
new AssetRegistryError("asset_invalid_utf8", `Text asset is not valid UTF-8: ${group.path}`),
|
|
447
|
+
first,
|
|
448
|
+
{ referencedBy },
|
|
449
|
+
));
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
const byKey = new Map(assets.map((asset) => [asset.key, asset]));
|
|
454
|
+
return { assets, byKey, diagnostics };
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
module.exports = {
|
|
458
|
+
AssetRegistryError,
|
|
459
|
+
DEFAULT_MAX_ASSET_BYTES,
|
|
460
|
+
assetKey,
|
|
461
|
+
buildAssetRegistry,
|
|
462
|
+
classifyAssetContent,
|
|
463
|
+
collectAssetReferences,
|
|
464
|
+
isExternalReference,
|
|
465
|
+
isLocalAssetReference,
|
|
466
|
+
mimeIsText,
|
|
467
|
+
mimeTypeForPath,
|
|
468
|
+
resolveBundleAssetPath,
|
|
469
|
+
};
|