@resourcexjs/registry 2.5.0 → 2.5.1
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/README.md +276 -302
- package/dist/index.d.ts +161 -34
- package/dist/index.js +257 -150
- package/dist/index.js.map +14 -9
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -28,11 +28,10 @@ var EOF_BUFFER = new Uint8Array(BLOCK_SIZE * 2);
|
|
|
28
28
|
var gzipAsync = promisify(gzip);
|
|
29
29
|
function locate(rxm) {
|
|
30
30
|
return {
|
|
31
|
-
|
|
31
|
+
registry: rxm.registry,
|
|
32
32
|
path: rxm.path,
|
|
33
33
|
name: rxm.name,
|
|
34
|
-
|
|
35
|
-
version: rxm.version
|
|
34
|
+
tag: rxm.tag
|
|
36
35
|
};
|
|
37
36
|
}
|
|
38
37
|
function resource(rxm, rxa) {
|
|
@@ -45,56 +44,85 @@ function resource(rxm, rxa) {
|
|
|
45
44
|
}
|
|
46
45
|
var gunzipAsync = promisify2(gunzip);
|
|
47
46
|
function format(rxl) {
|
|
48
|
-
let result =
|
|
47
|
+
let result = "";
|
|
48
|
+
if (rxl.registry) {
|
|
49
|
+
result += rxl.registry + "/";
|
|
50
|
+
}
|
|
49
51
|
if (rxl.path) {
|
|
50
52
|
result += rxl.path + "/";
|
|
51
53
|
}
|
|
52
54
|
result += rxl.name;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
if (rxl.tag && rxl.tag !== "latest") {
|
|
56
|
+
result += ":" + rxl.tag;
|
|
57
|
+
}
|
|
55
58
|
return result;
|
|
56
59
|
}
|
|
57
|
-
function
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
+
function looksLikeRegistry(str) {
|
|
61
|
+
if (str.includes(":") && !str.includes("/")) {
|
|
62
|
+
return true;
|
|
60
63
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
throw new LocatorError("locator must contain version (@)", locator);
|
|
64
|
+
if (str.includes(".")) {
|
|
65
|
+
return true;
|
|
64
66
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (!version) {
|
|
68
|
-
throw new LocatorError("version is required", locator);
|
|
67
|
+
if (str === "localhost") {
|
|
68
|
+
return true;
|
|
69
69
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
function parse(locator) {
|
|
73
|
+
if (!locator || typeof locator !== "string") {
|
|
74
|
+
throw new LocatorError("Locator must be a non-empty string", locator);
|
|
75
|
+
}
|
|
76
|
+
if (locator.includes("@")) {
|
|
77
|
+
throw new LocatorError("Invalid locator format. Use name:tag instead of name@version", locator);
|
|
78
|
+
}
|
|
79
|
+
const lastSlashIndex = locator.lastIndexOf("/");
|
|
80
|
+
let beforeSlash = "";
|
|
81
|
+
let afterSlash = locator;
|
|
82
|
+
if (lastSlashIndex !== -1) {
|
|
83
|
+
beforeSlash = locator.substring(0, lastSlashIndex);
|
|
84
|
+
afterSlash = locator.substring(lastSlashIndex + 1);
|
|
85
|
+
}
|
|
86
|
+
const colonIndex = afterSlash.lastIndexOf(":");
|
|
87
|
+
let name;
|
|
88
|
+
let tag;
|
|
89
|
+
if (colonIndex === -1) {
|
|
90
|
+
name = afterSlash;
|
|
91
|
+
tag = "latest";
|
|
92
|
+
} else {
|
|
93
|
+
name = afterSlash.substring(0, colonIndex);
|
|
94
|
+
tag = afterSlash.substring(colonIndex + 1);
|
|
73
95
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (!type) {
|
|
77
|
-
throw new LocatorError("type is required", locator);
|
|
96
|
+
if (!name) {
|
|
97
|
+
throw new LocatorError("Name is required", locator);
|
|
78
98
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
throw new LocatorError("locator must contain domain", locator);
|
|
99
|
+
if (!tag) {
|
|
100
|
+
throw new LocatorError("Tag cannot be empty. Use name:tag format or omit tag for :latest", locator);
|
|
82
101
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
102
|
+
if (lastSlashIndex === -1) {
|
|
103
|
+
return {
|
|
104
|
+
registry: undefined,
|
|
105
|
+
path: undefined,
|
|
106
|
+
name,
|
|
107
|
+
tag
|
|
108
|
+
};
|
|
88
109
|
}
|
|
89
|
-
|
|
90
|
-
|
|
110
|
+
const parts = beforeSlash.split("/");
|
|
111
|
+
if (looksLikeRegistry(parts[0])) {
|
|
112
|
+
const registry = parts[0];
|
|
113
|
+
const path = parts.length > 1 ? parts.slice(1).join("/") : undefined;
|
|
114
|
+
return {
|
|
115
|
+
registry,
|
|
116
|
+
path,
|
|
117
|
+
name,
|
|
118
|
+
tag
|
|
119
|
+
};
|
|
91
120
|
}
|
|
92
121
|
return {
|
|
93
|
-
|
|
94
|
-
path,
|
|
122
|
+
registry: undefined,
|
|
123
|
+
path: beforeSlash,
|
|
95
124
|
name,
|
|
96
|
-
|
|
97
|
-
version
|
|
125
|
+
tag
|
|
98
126
|
};
|
|
99
127
|
}
|
|
100
128
|
|
|
@@ -128,21 +156,19 @@ class RegistryError extends ResourceXError {
|
|
|
128
156
|
}
|
|
129
157
|
}
|
|
130
158
|
|
|
131
|
-
// src/registries/
|
|
132
|
-
class
|
|
159
|
+
// src/registries/LocalRegistry.ts
|
|
160
|
+
class LocalRegistry {
|
|
133
161
|
storage;
|
|
134
162
|
constructor(storage) {
|
|
135
163
|
this.storage = storage;
|
|
136
164
|
}
|
|
137
165
|
buildKeyPrefix(rxl) {
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
const version = rxl.version ?? "latest";
|
|
141
|
-
let key = domain;
|
|
166
|
+
const tag = rxl.tag ?? "latest";
|
|
167
|
+
let key = rxl.name;
|
|
142
168
|
if (rxl.path) {
|
|
143
|
-
key
|
|
169
|
+
key = `${rxl.path}/${key}`;
|
|
144
170
|
}
|
|
145
|
-
key += `/${
|
|
171
|
+
key += `/${tag}`;
|
|
146
172
|
return key;
|
|
147
173
|
}
|
|
148
174
|
async get(rxl) {
|
|
@@ -157,11 +183,11 @@ class HostedRegistry {
|
|
|
157
183
|
}
|
|
158
184
|
const manifestJson = JSON.parse(manifestData.toString("utf-8"));
|
|
159
185
|
const rxm = {
|
|
160
|
-
|
|
186
|
+
registry: manifestJson.registry,
|
|
161
187
|
path: manifestJson.path,
|
|
162
188
|
name: manifestJson.name,
|
|
163
189
|
type: manifestJson.type,
|
|
164
|
-
|
|
190
|
+
tag: manifestJson.tag,
|
|
165
191
|
files: manifestJson.files
|
|
166
192
|
};
|
|
167
193
|
const archiveData = await this.storage.get(archiveKey);
|
|
@@ -173,11 +199,11 @@ class HostedRegistry {
|
|
|
173
199
|
const manifestKey = `${prefix}/manifest.json`;
|
|
174
200
|
const archiveKey = `${prefix}/archive.tar.gz`;
|
|
175
201
|
const manifestJson = {
|
|
176
|
-
|
|
202
|
+
registry: rxr.manifest.registry,
|
|
177
203
|
path: rxr.manifest.path,
|
|
178
204
|
name: rxr.manifest.name,
|
|
179
205
|
type: rxr.manifest.type,
|
|
180
|
-
|
|
206
|
+
tag: rxr.manifest.tag,
|
|
181
207
|
files: rxr.manifest.files
|
|
182
208
|
};
|
|
183
209
|
const manifestData = Buffer.from(JSON.stringify(manifestJson, null, 2), "utf-8");
|
|
@@ -210,7 +236,7 @@ class HostedRegistry {
|
|
|
210
236
|
if (query) {
|
|
211
237
|
const lowerQuery = query.toLowerCase();
|
|
212
238
|
filtered = locators.filter((rxl) => {
|
|
213
|
-
const searchText = `${rxl.
|
|
239
|
+
const searchText = `${rxl.path ?? ""} ${rxl.name}`.toLowerCase();
|
|
214
240
|
return searchText.includes(lowerQuery);
|
|
215
241
|
});
|
|
216
242
|
}
|
|
@@ -223,30 +249,18 @@ class HostedRegistry {
|
|
|
223
249
|
parseKeyToRXL(key) {
|
|
224
250
|
const dirPath = key.replace(/\/manifest\.json$/, "");
|
|
225
251
|
const parts = dirPath.split("/");
|
|
226
|
-
if (parts.length <
|
|
252
|
+
if (parts.length < 2) {
|
|
227
253
|
return null;
|
|
228
254
|
}
|
|
229
|
-
const
|
|
230
|
-
const
|
|
231
|
-
const domain = parts.shift();
|
|
255
|
+
const tag = parts.pop();
|
|
256
|
+
const name = parts.pop();
|
|
232
257
|
const path = parts.length > 0 ? parts.join("/") : undefined;
|
|
233
|
-
|
|
234
|
-
let name;
|
|
235
|
-
let type;
|
|
236
|
-
if (dotIndex !== -1) {
|
|
237
|
-
name = nameTypePart.substring(0, dotIndex);
|
|
238
|
-
type = nameTypePart.substring(dotIndex + 1);
|
|
239
|
-
} else {
|
|
240
|
-
name = nameTypePart;
|
|
241
|
-
type = undefined;
|
|
242
|
-
}
|
|
243
|
-
let locatorStr = domain;
|
|
258
|
+
let locatorStr = "";
|
|
244
259
|
if (path)
|
|
245
|
-
locatorStr +=
|
|
246
|
-
locatorStr +=
|
|
247
|
-
if (
|
|
248
|
-
locatorStr +=
|
|
249
|
-
locatorStr += `@${version}`;
|
|
260
|
+
locatorStr += `${path}/`;
|
|
261
|
+
locatorStr += name;
|
|
262
|
+
if (tag !== "latest")
|
|
263
|
+
locatorStr += `:${tag}`;
|
|
250
264
|
try {
|
|
251
265
|
return parse(locatorStr);
|
|
252
266
|
} catch {
|
|
@@ -261,14 +275,13 @@ class MirrorRegistry {
|
|
|
261
275
|
this.storage = storage;
|
|
262
276
|
}
|
|
263
277
|
buildKeyPrefix(rxl) {
|
|
264
|
-
const
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
let key = domain;
|
|
278
|
+
const registry = rxl.registry ?? "localhost";
|
|
279
|
+
const tag = rxl.tag ?? "latest";
|
|
280
|
+
let key = registry;
|
|
268
281
|
if (rxl.path) {
|
|
269
282
|
key += `/${rxl.path}`;
|
|
270
283
|
}
|
|
271
|
-
key += `/${
|
|
284
|
+
key += `/${rxl.name}/${tag}`;
|
|
272
285
|
return key;
|
|
273
286
|
}
|
|
274
287
|
async get(rxl) {
|
|
@@ -283,11 +296,11 @@ class MirrorRegistry {
|
|
|
283
296
|
}
|
|
284
297
|
const manifestJson = JSON.parse(manifestData.toString("utf-8"));
|
|
285
298
|
const rxm = {
|
|
286
|
-
|
|
299
|
+
registry: manifestJson.registry,
|
|
287
300
|
path: manifestJson.path,
|
|
288
301
|
name: manifestJson.name,
|
|
289
302
|
type: manifestJson.type,
|
|
290
|
-
|
|
303
|
+
tag: manifestJson.tag,
|
|
291
304
|
files: manifestJson.files
|
|
292
305
|
};
|
|
293
306
|
const archiveData = await this.storage.get(archiveKey);
|
|
@@ -299,11 +312,11 @@ class MirrorRegistry {
|
|
|
299
312
|
const manifestKey = `${prefix}/manifest.json`;
|
|
300
313
|
const archiveKey = `${prefix}/archive.tar.gz`;
|
|
301
314
|
const manifestJson = {
|
|
302
|
-
|
|
315
|
+
registry: rxr.manifest.registry,
|
|
303
316
|
path: rxr.manifest.path,
|
|
304
317
|
name: rxr.manifest.name,
|
|
305
318
|
type: rxr.manifest.type,
|
|
306
|
-
|
|
319
|
+
tag: rxr.manifest.tag,
|
|
307
320
|
files: rxr.manifest.files
|
|
308
321
|
};
|
|
309
322
|
const manifestData = Buffer.from(JSON.stringify(manifestJson, null, 2), "utf-8");
|
|
@@ -336,7 +349,7 @@ class MirrorRegistry {
|
|
|
336
349
|
if (query) {
|
|
337
350
|
const lowerQuery = query.toLowerCase();
|
|
338
351
|
filtered = locators.filter((rxl) => {
|
|
339
|
-
const searchText = `${rxl.
|
|
352
|
+
const searchText = `${rxl.registry ?? ""} ${rxl.path ?? ""} ${rxl.name}`.toLowerCase();
|
|
340
353
|
return searchText.includes(lowerQuery);
|
|
341
354
|
});
|
|
342
355
|
}
|
|
@@ -346,22 +359,22 @@ class MirrorRegistry {
|
|
|
346
359
|
}
|
|
347
360
|
return result;
|
|
348
361
|
}
|
|
349
|
-
async clear(
|
|
350
|
-
if (
|
|
351
|
-
await this.storage.delete(
|
|
362
|
+
async clear(registry) {
|
|
363
|
+
if (registry) {
|
|
364
|
+
await this.storage.delete(registry);
|
|
352
365
|
} else {
|
|
353
366
|
const allKeys = await this.storage.list();
|
|
354
|
-
const
|
|
367
|
+
const registries = new Set;
|
|
355
368
|
for (const key of allKeys) {
|
|
356
369
|
const firstSlash = key.indexOf("/");
|
|
357
370
|
if (firstSlash !== -1) {
|
|
358
|
-
|
|
371
|
+
registries.add(key.substring(0, firstSlash));
|
|
359
372
|
} else {
|
|
360
|
-
|
|
373
|
+
registries.add(key);
|
|
361
374
|
}
|
|
362
375
|
}
|
|
363
|
-
for (const
|
|
364
|
-
await this.storage.delete(
|
|
376
|
+
for (const r of registries) {
|
|
377
|
+
await this.storage.delete(r);
|
|
365
378
|
}
|
|
366
379
|
}
|
|
367
380
|
}
|
|
@@ -371,27 +384,16 @@ class MirrorRegistry {
|
|
|
371
384
|
if (parts.length < 3) {
|
|
372
385
|
return null;
|
|
373
386
|
}
|
|
374
|
-
const
|
|
375
|
-
const
|
|
376
|
-
const
|
|
387
|
+
const tag = parts.pop();
|
|
388
|
+
const name = parts.pop();
|
|
389
|
+
const registry = parts.shift();
|
|
377
390
|
const path = parts.length > 0 ? parts.join("/") : undefined;
|
|
378
|
-
|
|
379
|
-
let name;
|
|
380
|
-
let type;
|
|
381
|
-
if (dotIndex !== -1) {
|
|
382
|
-
name = nameTypePart.substring(0, dotIndex);
|
|
383
|
-
type = nameTypePart.substring(dotIndex + 1);
|
|
384
|
-
} else {
|
|
385
|
-
name = nameTypePart;
|
|
386
|
-
type = undefined;
|
|
387
|
-
}
|
|
388
|
-
let locatorStr = domain;
|
|
391
|
+
let locatorStr = registry;
|
|
389
392
|
if (path)
|
|
390
393
|
locatorStr += `/${path}`;
|
|
391
394
|
locatorStr += `/${name}`;
|
|
392
|
-
if (
|
|
393
|
-
locatorStr +=
|
|
394
|
-
locatorStr += `@${version}`;
|
|
395
|
+
if (tag !== "latest")
|
|
396
|
+
locatorStr += `:${tag}`;
|
|
395
397
|
try {
|
|
396
398
|
return parse(locatorStr);
|
|
397
399
|
} catch {
|
|
@@ -435,15 +437,16 @@ function define(input) {
|
|
|
435
437
|
if (!obj.type || typeof obj.type !== "string") {
|
|
436
438
|
throw new DefinitionError("type is required");
|
|
437
439
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
+
const tagValue = obj.tag ?? obj.version;
|
|
441
|
+
if (tagValue !== undefined && typeof tagValue !== "string") {
|
|
442
|
+
throw new DefinitionError("tag must be a string");
|
|
440
443
|
}
|
|
441
444
|
const rxd = {
|
|
442
445
|
...obj,
|
|
443
446
|
name: obj.name,
|
|
444
447
|
type: obj.type,
|
|
445
|
-
|
|
446
|
-
|
|
448
|
+
tag: typeof tagValue === "string" ? tagValue : undefined,
|
|
449
|
+
registry: typeof obj.registry === "string" ? obj.registry : undefined,
|
|
447
450
|
path: typeof obj.path === "string" ? obj.path : undefined,
|
|
448
451
|
description: typeof obj.description === "string" ? obj.description : undefined,
|
|
449
452
|
author: typeof obj.author === "string" ? obj.author : undefined,
|
|
@@ -455,11 +458,11 @@ function define(input) {
|
|
|
455
458
|
}
|
|
456
459
|
function manifest(rxd) {
|
|
457
460
|
return {
|
|
458
|
-
|
|
461
|
+
registry: rxd.registry,
|
|
459
462
|
path: rxd.path,
|
|
460
463
|
name: rxd.name,
|
|
461
464
|
type: rxd.type,
|
|
462
|
-
|
|
465
|
+
tag: rxd.tag ?? "latest"
|
|
463
466
|
};
|
|
464
467
|
}
|
|
465
468
|
var BLOCK_SIZE2 = 512;
|
|
@@ -888,11 +891,10 @@ async function archive(files) {
|
|
|
888
891
|
}
|
|
889
892
|
function locate2(rxm) {
|
|
890
893
|
return {
|
|
891
|
-
|
|
894
|
+
registry: rxm.registry,
|
|
892
895
|
path: rxm.path,
|
|
893
896
|
name: rxm.name,
|
|
894
|
-
|
|
895
|
-
version: rxm.version
|
|
897
|
+
tag: rxm.tag
|
|
896
898
|
};
|
|
897
899
|
}
|
|
898
900
|
function resource2(rxm, rxa) {
|
|
@@ -977,14 +979,13 @@ class LinkedRegistry {
|
|
|
977
979
|
this.basePath = basePath;
|
|
978
980
|
}
|
|
979
981
|
buildLinkPath(rxl) {
|
|
980
|
-
const
|
|
981
|
-
const
|
|
982
|
-
|
|
983
|
-
let linkPath = join2(this.basePath, domain);
|
|
982
|
+
const registry = rxl.registry ?? "localhost";
|
|
983
|
+
const tag = rxl.tag ?? "latest";
|
|
984
|
+
let linkPath = join2(this.basePath, registry);
|
|
984
985
|
if (rxl.path) {
|
|
985
986
|
linkPath = join2(linkPath, rxl.path);
|
|
986
987
|
}
|
|
987
|
-
return join2(linkPath,
|
|
988
|
+
return join2(linkPath, rxl.name, tag);
|
|
988
989
|
}
|
|
989
990
|
async isSymlink(path) {
|
|
990
991
|
try {
|
|
@@ -1027,7 +1028,7 @@ class LinkedRegistry {
|
|
|
1027
1028
|
if (query) {
|
|
1028
1029
|
const lowerQuery = query.toLowerCase();
|
|
1029
1030
|
filtered = locators.filter((rxl) => {
|
|
1030
|
-
const searchText = `${rxl.
|
|
1031
|
+
const searchText = `${rxl.registry ?? ""} ${rxl.path ?? ""} ${rxl.name}`.toLowerCase();
|
|
1031
1032
|
return searchText.includes(lowerQuery);
|
|
1032
1033
|
});
|
|
1033
1034
|
}
|
|
@@ -1083,27 +1084,16 @@ class LinkedRegistry {
|
|
|
1083
1084
|
if (parts.length < 3) {
|
|
1084
1085
|
return null;
|
|
1085
1086
|
}
|
|
1086
|
-
const
|
|
1087
|
-
const
|
|
1088
|
-
const
|
|
1087
|
+
const tag = parts.pop();
|
|
1088
|
+
const name = parts.pop();
|
|
1089
|
+
const registry = parts.shift();
|
|
1089
1090
|
const path = parts.length > 0 ? parts.join("/") : undefined;
|
|
1090
|
-
|
|
1091
|
-
let name;
|
|
1092
|
-
let type;
|
|
1093
|
-
if (dotIndex !== -1) {
|
|
1094
|
-
name = nameTypePart.substring(0, dotIndex);
|
|
1095
|
-
type = nameTypePart.substring(dotIndex + 1);
|
|
1096
|
-
} else {
|
|
1097
|
-
name = nameTypePart;
|
|
1098
|
-
type = undefined;
|
|
1099
|
-
}
|
|
1100
|
-
let locatorStr = domain;
|
|
1091
|
+
let locatorStr = registry;
|
|
1101
1092
|
if (path)
|
|
1102
1093
|
locatorStr += `/${path}`;
|
|
1103
1094
|
locatorStr += `/${name}`;
|
|
1104
|
-
if (
|
|
1105
|
-
locatorStr +=
|
|
1106
|
-
locatorStr += `@${version}`;
|
|
1095
|
+
if (tag !== "latest")
|
|
1096
|
+
locatorStr += `:${tag}`;
|
|
1107
1097
|
try {
|
|
1108
1098
|
return parse(locatorStr);
|
|
1109
1099
|
} catch {
|
|
@@ -1111,6 +1101,116 @@ class LinkedRegistry {
|
|
|
1111
1101
|
}
|
|
1112
1102
|
}
|
|
1113
1103
|
}
|
|
1104
|
+
// src/chain/RegistryAccessChain.ts
|
|
1105
|
+
class RegistryAccessChain {
|
|
1106
|
+
accessors;
|
|
1107
|
+
memCache = new Map;
|
|
1108
|
+
useMemCache;
|
|
1109
|
+
constructor(accessors, options) {
|
|
1110
|
+
this.accessors = accessors;
|
|
1111
|
+
this.useMemCache = options?.memCache ?? false;
|
|
1112
|
+
}
|
|
1113
|
+
async get(rxl) {
|
|
1114
|
+
const key = format(rxl);
|
|
1115
|
+
if (this.useMemCache && this.memCache.has(key)) {
|
|
1116
|
+
return this.memCache.get(key);
|
|
1117
|
+
}
|
|
1118
|
+
for (const accessor of this.accessors) {
|
|
1119
|
+
if (await accessor.canHandle(rxl)) {
|
|
1120
|
+
const rxr = await accessor.get(rxl);
|
|
1121
|
+
if (this.useMemCache && accessor.name !== "linked") {
|
|
1122
|
+
this.memCache.set(key, rxr);
|
|
1123
|
+
}
|
|
1124
|
+
return rxr;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
throw new RegistryError(`Resource not found: ${key}`);
|
|
1128
|
+
}
|
|
1129
|
+
async has(rxl) {
|
|
1130
|
+
const key = format(rxl);
|
|
1131
|
+
if (this.useMemCache && this.memCache.has(key)) {
|
|
1132
|
+
return true;
|
|
1133
|
+
}
|
|
1134
|
+
for (const accessor of this.accessors) {
|
|
1135
|
+
if (await accessor.canHandle(rxl)) {
|
|
1136
|
+
return true;
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
return false;
|
|
1140
|
+
}
|
|
1141
|
+
clearCache() {
|
|
1142
|
+
this.memCache.clear();
|
|
1143
|
+
}
|
|
1144
|
+
invalidate(rxl) {
|
|
1145
|
+
this.memCache.delete(format(rxl));
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
// src/chain/LinkedAccessor.ts
|
|
1149
|
+
class LinkedAccessor {
|
|
1150
|
+
registry;
|
|
1151
|
+
name = "linked";
|
|
1152
|
+
constructor(registry) {
|
|
1153
|
+
this.registry = registry;
|
|
1154
|
+
}
|
|
1155
|
+
async canHandle(rxl) {
|
|
1156
|
+
return this.registry.has(rxl);
|
|
1157
|
+
}
|
|
1158
|
+
async get(rxl) {
|
|
1159
|
+
return this.registry.get(rxl);
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
// src/chain/LocalAccessor.ts
|
|
1163
|
+
class LocalAccessor {
|
|
1164
|
+
registry;
|
|
1165
|
+
name = "local";
|
|
1166
|
+
constructor(registry) {
|
|
1167
|
+
this.registry = registry;
|
|
1168
|
+
}
|
|
1169
|
+
async canHandle(rxl) {
|
|
1170
|
+
if (rxl.registry) {
|
|
1171
|
+
return false;
|
|
1172
|
+
}
|
|
1173
|
+
return this.registry.has(rxl);
|
|
1174
|
+
}
|
|
1175
|
+
async get(rxl) {
|
|
1176
|
+
return this.registry.get(rxl);
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
// src/chain/CacheAccessor.ts
|
|
1180
|
+
class CacheAccessor {
|
|
1181
|
+
registry;
|
|
1182
|
+
name = "cache";
|
|
1183
|
+
constructor(registry) {
|
|
1184
|
+
this.registry = registry;
|
|
1185
|
+
}
|
|
1186
|
+
async canHandle(rxl) {
|
|
1187
|
+
if (!rxl.registry) {
|
|
1188
|
+
return false;
|
|
1189
|
+
}
|
|
1190
|
+
return this.registry.has(rxl);
|
|
1191
|
+
}
|
|
1192
|
+
async get(rxl) {
|
|
1193
|
+
return this.registry.get(rxl);
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
// src/chain/RemoteAccessor.ts
|
|
1197
|
+
class RemoteAccessor {
|
|
1198
|
+
fetcher;
|
|
1199
|
+
cache;
|
|
1200
|
+
name = "remote";
|
|
1201
|
+
constructor(fetcher, cache) {
|
|
1202
|
+
this.fetcher = fetcher;
|
|
1203
|
+
this.cache = cache;
|
|
1204
|
+
}
|
|
1205
|
+
async canHandle(rxl) {
|
|
1206
|
+
return !!rxl.registry;
|
|
1207
|
+
}
|
|
1208
|
+
async get(rxl) {
|
|
1209
|
+
const rxr = await this.fetcher.fetch(rxl);
|
|
1210
|
+
await this.cache.put(rxr);
|
|
1211
|
+
return rxr;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1114
1214
|
// src/discovery.ts
|
|
1115
1215
|
async function discoverRegistry(domain) {
|
|
1116
1216
|
const wellKnownUrl = `https://${domain}/.well-known/resourcex`;
|
|
@@ -1157,35 +1257,42 @@ class RegistryMiddleware {
|
|
|
1157
1257
|
}
|
|
1158
1258
|
}
|
|
1159
1259
|
// src/middleware/DomainValidation.ts
|
|
1160
|
-
class
|
|
1161
|
-
|
|
1162
|
-
constructor(inner,
|
|
1260
|
+
class RegistryValidation extends RegistryMiddleware {
|
|
1261
|
+
trustedRegistry;
|
|
1262
|
+
constructor(inner, trustedRegistry) {
|
|
1163
1263
|
super(inner);
|
|
1164
|
-
this.
|
|
1264
|
+
this.trustedRegistry = trustedRegistry;
|
|
1165
1265
|
}
|
|
1166
|
-
|
|
1167
|
-
if (rxr.manifest.
|
|
1168
|
-
throw new RegistryError(`Untrusted
|
|
1266
|
+
validateRegistry(rxr) {
|
|
1267
|
+
if (rxr.manifest.registry !== this.trustedRegistry) {
|
|
1268
|
+
throw new RegistryError(`Untrusted registry: resource claims "${rxr.manifest.registry}" but registry only trusts "${this.trustedRegistry}"`);
|
|
1169
1269
|
}
|
|
1170
1270
|
}
|
|
1171
1271
|
async get(rxl) {
|
|
1172
1272
|
const rxr = await this.inner.get(rxl);
|
|
1173
|
-
this.
|
|
1273
|
+
this.validateRegistry(rxr);
|
|
1174
1274
|
return rxr;
|
|
1175
1275
|
}
|
|
1176
1276
|
}
|
|
1177
|
-
function
|
|
1178
|
-
return new
|
|
1277
|
+
function withRegistryValidation(registry, trustedRegistry) {
|
|
1278
|
+
return new RegistryValidation(registry, trustedRegistry);
|
|
1179
1279
|
}
|
|
1280
|
+
var DomainValidation = RegistryValidation;
|
|
1281
|
+
var withDomainValidation = withRegistryValidation;
|
|
1180
1282
|
export {
|
|
1181
1283
|
withDomainValidation,
|
|
1182
1284
|
discoverRegistry,
|
|
1285
|
+
RemoteAccessor,
|
|
1183
1286
|
RegistryMiddleware,
|
|
1184
1287
|
RegistryError,
|
|
1288
|
+
RegistryAccessChain,
|
|
1185
1289
|
MirrorRegistry,
|
|
1290
|
+
LocalRegistry,
|
|
1291
|
+
LocalAccessor,
|
|
1186
1292
|
LinkedRegistry,
|
|
1187
|
-
|
|
1188
|
-
DomainValidation
|
|
1293
|
+
LinkedAccessor,
|
|
1294
|
+
DomainValidation,
|
|
1295
|
+
CacheAccessor
|
|
1189
1296
|
};
|
|
1190
1297
|
|
|
1191
|
-
//# debugId=
|
|
1298
|
+
//# debugId=94E483D2C901ABA364756E2164756E21
|