@toolr/seedr 0.1.30 → 0.1.31
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/{chunk-B5AVQWXW.js → chunk-HYIVKVYC.js} +40 -35
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -7,18 +7,18 @@ import { fileURLToPath } from "url";
|
|
|
7
7
|
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
8
|
var REGISTRY_PATH = join(__dirname, "../../../../registry");
|
|
9
9
|
var GITHUB_RAW_URL = "https://raw.githubusercontent.com/twiced-technology-gmbh/seedr/main/registry";
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
-
set(manifest) {
|
|
16
|
-
this.data = manifest;
|
|
17
|
-
},
|
|
18
|
-
clear() {
|
|
19
|
-
this.data = null;
|
|
20
|
-
}
|
|
10
|
+
var cache = {
|
|
11
|
+
index: null,
|
|
12
|
+
types: /* @__PURE__ */ new Map(),
|
|
13
|
+
assembled: null
|
|
21
14
|
};
|
|
15
|
+
async function loadFile(filename) {
|
|
16
|
+
try {
|
|
17
|
+
return await readFile(join(REGISTRY_PATH, filename), "utf-8");
|
|
18
|
+
} catch {
|
|
19
|
+
return fetchRemote(`${GITHUB_RAW_URL}/${filename}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
22
|
async function fetchRemote(url) {
|
|
23
23
|
const response = await fetch(url);
|
|
24
24
|
if (!response.ok) {
|
|
@@ -26,39 +26,44 @@ async function fetchRemote(url) {
|
|
|
26
26
|
}
|
|
27
27
|
return response.text();
|
|
28
28
|
}
|
|
29
|
+
async function loadIndex() {
|
|
30
|
+
if (cache.index) return cache.index;
|
|
31
|
+
const content = await loadFile("manifest.json");
|
|
32
|
+
const data = JSON.parse(content);
|
|
33
|
+
cache.index = data;
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
async function loadTypeItems(type) {
|
|
37
|
+
const cached = cache.types.get(type);
|
|
38
|
+
if (cached) return cached;
|
|
39
|
+
const index = await loadIndex();
|
|
40
|
+
const desc = index.types[type];
|
|
41
|
+
const content = await loadFile(desc.file);
|
|
42
|
+
const typeManifest = JSON.parse(content);
|
|
43
|
+
cache.types.set(type, typeManifest.items);
|
|
44
|
+
return typeManifest.items;
|
|
45
|
+
}
|
|
29
46
|
async function loadManifest() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
} catch {
|
|
41
|
-
try {
|
|
42
|
-
const content = await fetchRemote(`${GITHUB_RAW_URL}/manifest.json`);
|
|
43
|
-
const manifest = JSON.parse(content);
|
|
44
|
-
manifestCache.set(manifest);
|
|
45
|
-
return manifest;
|
|
46
|
-
} catch (error) {
|
|
47
|
-
throw new Error(
|
|
48
|
-
`Could not load registry manifest: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
47
|
+
if (cache.assembled) return cache.assembled;
|
|
48
|
+
const index = await loadIndex();
|
|
49
|
+
const typeEntries = Object.entries(index.types);
|
|
50
|
+
const typeResults = await Promise.all(
|
|
51
|
+
typeEntries.map(async ([type]) => loadTypeItems(type))
|
|
52
|
+
);
|
|
53
|
+
const items = typeResults.flat();
|
|
54
|
+
const manifest = { version: index.version, items };
|
|
55
|
+
cache.assembled = manifest;
|
|
56
|
+
return manifest;
|
|
52
57
|
}
|
|
53
58
|
async function getItem(slug) {
|
|
54
59
|
const manifest = await loadManifest();
|
|
55
60
|
return manifest.items.find((item) => item.slug === slug);
|
|
56
61
|
}
|
|
57
62
|
async function listItems(type) {
|
|
58
|
-
const manifest = await loadManifest();
|
|
59
63
|
if (type) {
|
|
60
|
-
return
|
|
64
|
+
return loadTypeItems(type);
|
|
61
65
|
}
|
|
66
|
+
const manifest = await loadManifest();
|
|
62
67
|
return manifest.items;
|
|
63
68
|
}
|
|
64
69
|
async function searchItems(query) {
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED