@darkrymit/crunes-cli 0.7.2 → 0.8.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 +5 -4
- package/dist/chunks/{add-OWYVF3IE.js → add-CBHWFGCA.js} +2 -2
- package/dist/chunks/{apply-OMEVXCHC.js → apply-YC6JEPUN.js} +6 -5
- package/dist/chunks/args-repl-TX3YWUOO.js +81 -0
- package/dist/chunks/banner-repl-DD22Z33A.js +52 -0
- package/dist/chunks/benchmark-BJEAAFWG.js +234 -0
- package/dist/chunks/{browse-COH6IJEX.js → browse-JZFU52ET.js} +2 -2
- package/dist/chunks/{chunk-2Q24YPGL.js → chunk-2PBPDTRD.js} +2 -2
- package/dist/chunks/chunk-63H5VXZY.js +101 -0
- package/dist/chunks/{chunk-GHQOK4L7.js → chunk-65J65MAP.js} +1 -1
- package/dist/chunks/{chunk-HMU2J25D.js → chunk-6MRZXASS.js} +3 -3
- package/dist/chunks/{chunk-BEVULQIG.js → chunk-ASZKAC24.js} +2 -1
- package/dist/chunks/{chunk-AIEWOUXT.js → chunk-DZJRYFOP.js} +104 -41
- package/dist/chunks/{chunk-QMWGQXEZ.js → chunk-G4ZAUHHA.js} +2 -4
- package/dist/chunks/{chunk-67I2J474.js → chunk-J3GZ3DXD.js} +14 -55
- package/dist/chunks/{chunk-XIXND2M4.js → chunk-JOAL437H.js} +5 -1
- package/dist/chunks/{chunk-6I7RHSAA.js → chunk-JU6FKUBY.js} +30394 -26055
- package/dist/chunks/{chunk-5RGDIMK6.js → chunk-NAEVMRNA.js} +22031 -13353
- package/dist/chunks/{chunk-NXSDVVTW.js → chunk-NDEYEYSU.js} +22 -69
- package/dist/chunks/{chunk-L72BG6DS.js → chunk-NYLRTAAA.js} +1 -1
- package/dist/chunks/{chunk-UGN3FFEF.js → chunk-V35LVVNV.js} +5113 -2117
- package/dist/chunks/chunk-ZJDKCC2Y.js +105 -0
- package/dist/chunks/{clear-Y5POLIMF.js → clear-YBDIPEEH.js} +5 -9
- package/dist/chunks/commands-repl-IPLJ4M7X.js +65 -0
- package/dist/chunks/complete-input-repl-IDSCMRYL.js +71 -0
- package/dist/chunks/{create-I6BNYZ5Q.js → create-ZFFV3Z2P.js} +2 -1
- package/dist/chunks/{delete-UB5SXO5I.js → delete-C4UJ7X5K.js} +5 -9
- package/dist/chunks/delete-E4TEBRPX.js +27 -0
- package/dist/chunks/{delete-7CQFYIXS.js → delete-LNOYM5KG.js} +5 -9
- package/dist/chunks/{disable-FCBW7WVG.js → disable-TMG2K3BF.js} +6 -6
- package/dist/chunks/{doctor-DS57HDLJ.js → doctor-N43QEMAH.js} +2 -2
- package/dist/chunks/{enable-IXRVUXJM.js → enable-327OMBPC.js} +6 -6
- package/dist/chunks/{globals-YCJ2DGWC.js → globals-H2WF344Y.js} +2 -2
- package/dist/chunks/{init-WGKQVAZE.js → init-HU5OMHEH.js} +1 -1
- package/dist/chunks/input-repl-ZBH6FVPV.js +87 -0
- package/dist/chunks/{install-BCTBOPBS.js → install-RRLUOYFO.js} +6 -6
- package/dist/chunks/intro-4CICBP2J.js +2727 -0
- package/dist/chunks/{kill-LWRXZVM5.js → kill-2UG7PHUV.js} +4 -10
- package/dist/chunks/list-4X3JFQGS.js +41 -0
- package/dist/chunks/{list-ZBYPMUID.js → list-7VHJIUDX.js} +2 -2
- package/dist/chunks/list-A5WVDBWF.js +53 -0
- package/dist/chunks/{list-NGOCMJXE.js → list-CK5X2YN3.js} +5 -4
- package/dist/chunks/{list-TTKLNJKI.js → list-FLAYJQKN.js} +2 -2
- package/dist/chunks/list-PTAWQYWG.js +35 -0
- package/dist/chunks/list-U7PAYNAH.js +47 -0
- package/dist/chunks/{list-OTOMCFLA.js → list-WH7KESMV.js} +12 -11
- package/dist/chunks/{query-NY4SCO77.js → query-AW7WYILM.js} +5 -9
- package/dist/chunks/{registry-W5XFI5T6.js → registry-3QIL5SVL.js} +2 -2
- package/dist/chunks/{remove-WEAZFZCO.js → remove-QUH2D3S5.js} +2 -2
- package/dist/chunks/repl-STBZC4P2.js +180 -0
- package/dist/chunks/repl-VGC5FUJG.js +378 -0
- package/dist/chunks/resolver-QMIY33FM.js +26 -0
- package/dist/chunks/run-T33CMCFZ.js +26 -0
- package/dist/chunks/{run-J2A5YTTY.js → run-Y4TG3EM3.js} +22 -3
- package/dist/chunks/rune-UBRVWG5A.js +139 -0
- package/dist/chunks/{search-XENXL3GC.js → search-MSSDGJTF.js} +2 -2
- package/dist/chunks/{uninstall-MX5PLGDI.js → uninstall-55YTHZRH.js} +5 -5
- package/dist/chunks/unset-YASSMSE5.js +24 -0
- package/dist/chunks/{update-7XDTVFZ3.js → update-EWWDROKW.js} +2 -2
- package/dist/chunks/{update-IEE54GPY.js → update-G6XO4RIM.js} +6 -6
- package/dist/chunks/{utils-JKGIWZTS.js → utils-XOWJQWNR.js} +2 -2
- package/dist/chunks/{version-OPTLR63W.js → version-I442SSH7.js} +10 -5
- package/dist/cli.js +114 -81
- package/package.json +9 -4
- package/dist/chunks/benchmark-ATSRQIDC.js +0 -164
- package/dist/chunks/check-G72VZKIP.js +0 -144
- package/dist/chunks/chunk-3TM6B4E5.js +0 -70
- package/dist/chunks/chunk-XXUNHQIB.js +0 -129
- package/dist/chunks/intro-QVSLNH4R.js +0 -1510
- package/dist/chunks/list-5DVVP7HX.js +0 -50
- package/dist/chunks/list-6WL5LGIZ.js +0 -80
- package/dist/chunks/list-YPI7YDKK.js +0 -80
- package/dist/chunks/run-AUAGELWL.js +0 -23
- package/dist/chunks/rune-ZYEVEYID.js +0 -87
- package/dist/chunks/unset-KQOZYVTE.js +0 -28
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
require_micromatch,
|
|
3
|
-
runRune
|
|
4
|
-
} from "./chunk-6I7RHSAA.js";
|
|
5
1
|
import {
|
|
6
2
|
loadConfig
|
|
7
3
|
} from "./chunk-H3BVJCIL.js";
|
|
4
|
+
import {
|
|
5
|
+
isGlobMatch,
|
|
6
|
+
isWildcardMatch,
|
|
7
|
+
runRune
|
|
8
|
+
} from "./chunk-JU6FKUBY.js";
|
|
8
9
|
import {
|
|
9
10
|
isVerbose,
|
|
10
11
|
output
|
|
11
12
|
} from "./chunk-6XLT25GS.js";
|
|
12
13
|
import {
|
|
13
|
-
__toESM,
|
|
14
14
|
init_require_shim
|
|
15
15
|
} from "./chunk-TPK5AGRA.js";
|
|
16
16
|
|
|
@@ -40,14 +40,16 @@ function renderSection(section) {
|
|
|
40
40
|
}
|
|
41
41
|
const content = render(section.data);
|
|
42
42
|
if (content) {
|
|
43
|
-
|
|
44
|
-
parts.push("```md\n" + content + "\n```");
|
|
45
|
-
} else {
|
|
46
|
-
parts.push(content);
|
|
47
|
-
}
|
|
43
|
+
parts.push(content);
|
|
48
44
|
}
|
|
49
45
|
return parts.filter(Boolean).join("\n") || null;
|
|
50
46
|
}
|
|
47
|
+
function formatSection(section, rune) {
|
|
48
|
+
const nameStr = section.title ?? section.name ?? "(no title)";
|
|
49
|
+
const attrsStr = section.attrs && Object.keys(section.attrs).length > 0 ? " " + Object.entries(section.attrs).map(([k, v]) => `[${k}: ${v}]`).join(" ") : "";
|
|
50
|
+
const content = render(section.data);
|
|
51
|
+
return `[${rune}:section] ${nameStr}${attrsStr}${content ? "\n" + content : ""}`;
|
|
52
|
+
}
|
|
51
53
|
function renderTree(root) {
|
|
52
54
|
if (!root) return null;
|
|
53
55
|
const lines = [`${root.name.padEnd(12)}${root.description}`];
|
|
@@ -65,15 +67,61 @@ function appendChildren(children, prefix, lines) {
|
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
|
|
70
|
+
// src/rune/commands/batch-permission.js
|
|
71
|
+
init_require_shim();
|
|
72
|
+
function buildMatchString(key, args) {
|
|
73
|
+
return args.length === 0 ? key : `${key} ${args.join(" ")}`;
|
|
74
|
+
}
|
|
75
|
+
function checkBatchPermission(entry, matchString) {
|
|
76
|
+
const batch = entry?.batch;
|
|
77
|
+
if (!batch) return { allowed: false, reason: "No batch block declared" };
|
|
78
|
+
const deny = batch.deny ?? [];
|
|
79
|
+
const allow = batch.allow ?? [];
|
|
80
|
+
const spaceIdx = matchString.indexOf(" ");
|
|
81
|
+
const subject = spaceIdx === -1 ? matchString : matchString.slice(spaceIdx + 1);
|
|
82
|
+
if (deny.length > 0 && isWildcardMatch(subject, deny)) {
|
|
83
|
+
return { allowed: false, reason: "Matches deny pattern" };
|
|
84
|
+
}
|
|
85
|
+
if (allow.length > 0 && isWildcardMatch(subject, allow)) {
|
|
86
|
+
return { allowed: true };
|
|
87
|
+
}
|
|
88
|
+
return { allowed: false, reason: "No matching allow pattern" };
|
|
89
|
+
}
|
|
90
|
+
|
|
68
91
|
// src/rune/commands/run.js
|
|
69
|
-
|
|
92
|
+
function parseBracketKey(token) {
|
|
93
|
+
if (!token) return { key: null, bracketArgs: [] };
|
|
94
|
+
const bracketStart = token.indexOf("[");
|
|
95
|
+
if (bracketStart === -1) return { key: token, bracketArgs: [] };
|
|
96
|
+
const bracketEnd = token.lastIndexOf("]");
|
|
97
|
+
const key = token.slice(0, bracketStart);
|
|
98
|
+
const inner = bracketEnd > bracketStart ? token.slice(bracketStart + 1, bracketEnd) : token.slice(bracketStart + 1);
|
|
99
|
+
const bracketArgs = inner.trim() ? inner.trim().split(/\s+/) : [];
|
|
100
|
+
return { key: key || null, bracketArgs };
|
|
101
|
+
}
|
|
70
102
|
function parseSegment(argv) {
|
|
103
|
+
if (!argv.length) return { key: null, sections: null, runeArgs: [] };
|
|
104
|
+
const { key, bracketArgs } = parseBracketKey(argv[0]);
|
|
105
|
+
if (key && key.startsWith("-")) {
|
|
106
|
+
output.error(`Unknown option or misplaced flag: "${key}"`);
|
|
107
|
+
output.info(`
|
|
108
|
+
Arguments must follow this strict structure:
|
|
109
|
+
1. Global Flags (e.g., --cwd, --verbose)
|
|
110
|
+
2. Command (e.g., run, bench)
|
|
111
|
+
3. Command Flags (e.g., --format, -b)
|
|
112
|
+
4. Rune Key (e.g., myrune[-s section])
|
|
113
|
+
5. Rune Arguments (e.g., --strict, pos-arg)
|
|
114
|
+
|
|
115
|
+
Example: crunes --cwd ./dir run myrune[-s summary] --strict
|
|
116
|
+
`.trimEnd());
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
71
119
|
let sections = null;
|
|
72
120
|
let i = 0;
|
|
73
|
-
while (i <
|
|
74
|
-
const tok =
|
|
75
|
-
if ((tok === "--section" || tok === "-s") && i + 1 <
|
|
76
|
-
sections =
|
|
121
|
+
while (i < bracketArgs.length) {
|
|
122
|
+
const tok = bracketArgs[i];
|
|
123
|
+
if ((tok === "--section" || tok === "-s") && i + 1 < bracketArgs.length) {
|
|
124
|
+
sections = bracketArgs[i + 1].split(",").map((s) => s.trim()).filter(Boolean);
|
|
77
125
|
i += 2;
|
|
78
126
|
} else if (tok.startsWith("--section=")) {
|
|
79
127
|
sections = tok.slice(10).split(",").map((s) => s.trim()).filter(Boolean);
|
|
@@ -82,26 +130,10 @@ function parseSegment(argv) {
|
|
|
82
130
|
sections = tok.slice(3).split(",").map((s) => s.trim()).filter(Boolean);
|
|
83
131
|
i++;
|
|
84
132
|
} else {
|
|
85
|
-
|
|
133
|
+
i++;
|
|
86
134
|
}
|
|
87
135
|
}
|
|
88
|
-
|
|
89
|
-
if (key && key.startsWith("-")) {
|
|
90
|
-
output.error(`Unknown option or misplaced flag: "${key}"`);
|
|
91
|
-
output.info(`
|
|
92
|
-
Arguments must follow this strict structure:
|
|
93
|
-
1. Global Flags (e.g., --cwd, --verbose)
|
|
94
|
-
2. Command (e.g., use, check, bench)
|
|
95
|
-
3. Command Flags (e.g., --format, -b)
|
|
96
|
-
4. Rune Key (e.g., myrune)
|
|
97
|
-
5. Rune Arguments (e.g., --strict, pos-arg)
|
|
98
|
-
|
|
99
|
-
Example: crunes --cwd ./dir use --format json myrune --strict
|
|
100
|
-
`.trimEnd());
|
|
101
|
-
process.exit(1);
|
|
102
|
-
}
|
|
103
|
-
const runeArgs = key !== null ? argv.slice(i + 1) : [];
|
|
104
|
-
return { key, sections, runeArgs };
|
|
136
|
+
return { key, sections, runeArgs: argv.slice(1) };
|
|
105
137
|
}
|
|
106
138
|
function parseRunArgs(argv) {
|
|
107
139
|
let format = "text";
|
|
@@ -138,12 +170,13 @@ function parseRunArgs(argv) {
|
|
|
138
170
|
}
|
|
139
171
|
rawSegments.push(current);
|
|
140
172
|
const segments = rawSegments.map(parseSegment);
|
|
141
|
-
return { segments, format, failFast };
|
|
173
|
+
return { segments, format, failFast, isBatch: allowBatch };
|
|
142
174
|
}
|
|
143
175
|
async function handler({
|
|
144
176
|
segments,
|
|
145
177
|
format = "text",
|
|
146
178
|
failFast = false,
|
|
179
|
+
isBatch = false,
|
|
147
180
|
projectRoot = process.cwd(),
|
|
148
181
|
configRoot = projectRoot
|
|
149
182
|
}) {
|
|
@@ -161,6 +194,31 @@ async function handler({
|
|
|
161
194
|
output.info("Run `crunes init` to create a config file.");
|
|
162
195
|
process.exit(1);
|
|
163
196
|
}
|
|
197
|
+
if (isBatch) {
|
|
198
|
+
const { resolvePluginRune } = await import("./resolver-QMIY33FM.js");
|
|
199
|
+
const { loadPluginJson } = await import("./manifest-7RVNKBOH.js");
|
|
200
|
+
for (const seg of segments) {
|
|
201
|
+
let entry = config.runes?.[seg.key] ?? {};
|
|
202
|
+
if (!entry.batch && seg.key.includes(":")) {
|
|
203
|
+
try {
|
|
204
|
+
const match = await resolvePluginRune(config, seg.key);
|
|
205
|
+
if (match) {
|
|
206
|
+
const runeKey = seg.key.slice(seg.key.indexOf(":") + 1);
|
|
207
|
+
const pluginJson = await loadPluginJson(match.pluginDir);
|
|
208
|
+
const pluginRuneBatch = pluginJson.runes?.[runeKey]?.batch;
|
|
209
|
+
if (pluginRuneBatch) entry = { batch: pluginRuneBatch };
|
|
210
|
+
}
|
|
211
|
+
} catch {
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const matchString = buildMatchString(seg.key, seg.runeArgs);
|
|
215
|
+
const result = checkBatchPermission(entry, matchString);
|
|
216
|
+
if (!result.allowed) {
|
|
217
|
+
output.error(`Batch not permitted for "${matchString}". Add a batch.allow pattern in config.json or run it separately.`);
|
|
218
|
+
process.exit(1);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
164
222
|
let anyFailed = false;
|
|
165
223
|
for (let i = 0; i < segments.length; i++) {
|
|
166
224
|
const printedSections = /* @__PURE__ */ new Set();
|
|
@@ -173,11 +231,11 @@ async function handler({
|
|
|
173
231
|
configDir: configRoot,
|
|
174
232
|
instanceId: String(i + 1),
|
|
175
233
|
onEvent(event) {
|
|
176
|
-
const { type, message, section, instanceId: instanceId2, rune } = event;
|
|
177
|
-
const prefix = `[${instanceId2}:${rune}:${type}]`;
|
|
234
|
+
const { type, level, message, meta, section, instanceId: instanceId2, rune } = event;
|
|
235
|
+
const prefix = level ? `[${instanceId2}:${rune}:${type}:${level}]` : `[${instanceId2}:${rune}:${type}]`;
|
|
178
236
|
if (format === "jsonl") {
|
|
179
237
|
if (type === "section") {
|
|
180
|
-
if (sectionFilter && !
|
|
238
|
+
if (sectionFilter && !isGlobMatch(section.name, sectionFilter)) {
|
|
181
239
|
return;
|
|
182
240
|
}
|
|
183
241
|
printedSections.add(section);
|
|
@@ -186,12 +244,14 @@ async function handler({
|
|
|
186
244
|
type,
|
|
187
245
|
rune,
|
|
188
246
|
instance: instanceId2,
|
|
247
|
+
...level != null ? { level } : {},
|
|
189
248
|
...message != null ? { message } : {},
|
|
249
|
+
...meta != null ? { meta } : {},
|
|
190
250
|
...section != null ? { section } : {}
|
|
191
251
|
}) + "\n");
|
|
192
252
|
} else {
|
|
193
253
|
if (type === "section") {
|
|
194
|
-
if (!sectionFilter ||
|
|
254
|
+
if (!sectionFilter || isGlobMatch(section.name, sectionFilter)) {
|
|
195
255
|
const rendered = renderSection(section);
|
|
196
256
|
const lines = rendered ? rendered.split("\n") : [];
|
|
197
257
|
let contentStartIndex = 1;
|
|
@@ -208,13 +268,14 @@ ${content}
|
|
|
208
268
|
printedSections.add(section);
|
|
209
269
|
}
|
|
210
270
|
} else {
|
|
271
|
+
const attrsStr = meta && Object.keys(meta).length > 0 ? " " + Object.entries(meta).map(([k, v]) => `[${k}: ${v}]`).join(" ") : "";
|
|
211
272
|
if (message && message.includes("\n")) {
|
|
212
|
-
process.stdout.write(`${prefix}
|
|
273
|
+
process.stdout.write(`${prefix}${attrsStr}
|
|
213
274
|
${message}
|
|
214
275
|
|
|
215
276
|
`);
|
|
216
277
|
} else {
|
|
217
|
-
process.stdout.write(`${prefix} ${message ?? ""}
|
|
278
|
+
process.stdout.write(`${prefix} ${message ?? ""}${attrsStr}
|
|
218
279
|
`);
|
|
219
280
|
}
|
|
220
281
|
}
|
|
@@ -237,7 +298,7 @@ ${msg}`);
|
|
|
237
298
|
if (failFast) process.exit(1);
|
|
238
299
|
continue;
|
|
239
300
|
}
|
|
240
|
-
const filtered = sectionFilter ? sections.filter((s) =>
|
|
301
|
+
const filtered = sectionFilter ? sections.filter((s) => isGlobMatch(s.name, sectionFilter)) : sections;
|
|
241
302
|
const instanceId = String(i + 1);
|
|
242
303
|
for (const sect of filtered) {
|
|
243
304
|
const alreadyPrinted = Array.from(printedSections).some((p) => p.name === sect.name);
|
|
@@ -275,6 +336,8 @@ ${content}
|
|
|
275
336
|
}
|
|
276
337
|
|
|
277
338
|
export {
|
|
339
|
+
formatSection,
|
|
340
|
+
parseBracketKey,
|
|
278
341
|
parseSegment,
|
|
279
342
|
parseRunArgs,
|
|
280
343
|
handler
|
|
@@ -10,10 +10,8 @@ function shortHash(str) {
|
|
|
10
10
|
}
|
|
11
11
|
var KEY_MATERIALS = {
|
|
12
12
|
"global-plugin": ({ pluginId, name }) => `global-plugin|${pluginId}|${name}`,
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"local-project": ({ projectId, name }) => `local-project|${projectId}|${name}`,
|
|
16
|
-
"local-project-plugin": ({ projectId, pluginId, name }) => `local-project-plugin|${projectId}|${pluginId}|${name}`
|
|
13
|
+
"local": ({ projectId, name }) => `local|${projectId}|${name}`,
|
|
14
|
+
"local-plugin": ({ projectId, pluginId, name }) => `local-plugin|${projectId}|${pluginId}|${name}`
|
|
17
15
|
};
|
|
18
16
|
function storageKey(type, { projectId, pluginId, name }) {
|
|
19
17
|
const materialFn = KEY_MATERIALS[type];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
storageKey
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-G4ZAUHHA.js";
|
|
4
4
|
import {
|
|
5
5
|
getSqliteBasePath,
|
|
6
6
|
getSqliteJsonPath
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-6MRZXASS.js";
|
|
8
8
|
import {
|
|
9
9
|
init_require_shim
|
|
10
10
|
} from "./chunk-TPK5AGRA.js";
|
|
@@ -27,12 +27,6 @@ async function loadDatabase() {
|
|
|
27
27
|
function getSqlitePluginDir(pluginId) {
|
|
28
28
|
return path.join(getSqliteBasePath(), "plugins", pluginId);
|
|
29
29
|
}
|
|
30
|
-
function getSqliteProjectDir(key) {
|
|
31
|
-
return path.join(getSqliteBasePath(), "projects", key);
|
|
32
|
-
}
|
|
33
|
-
function getSqliteProjectPluginDir(key, pluginId) {
|
|
34
|
-
return path.join(getSqliteBasePath(), "project-plugins", key, pluginId);
|
|
35
|
-
}
|
|
36
30
|
async function loadSqliteDbs() {
|
|
37
31
|
try {
|
|
38
32
|
return JSON.parse(await readFile(getSqliteJsonPath(), "utf8"));
|
|
@@ -40,43 +34,11 @@ async function loadSqliteDbs() {
|
|
|
40
34
|
return { format: "1", databases: {} };
|
|
41
35
|
}
|
|
42
36
|
}
|
|
43
|
-
async function
|
|
37
|
+
async function listSqliteDbs() {
|
|
44
38
|
const data = await loadSqliteDbs();
|
|
45
|
-
|
|
46
|
-
const key = storageKey(scope, { projectId: effectiveProjectId, pluginId, name });
|
|
47
|
-
data.databases[key] = {
|
|
48
|
-
path: resolvedPath,
|
|
49
|
-
scope,
|
|
50
|
-
projectKey: effectiveProjectId,
|
|
51
|
-
pluginId: pluginId ?? null,
|
|
52
|
-
location,
|
|
53
|
-
name,
|
|
54
|
-
firstSeenAt: data.databases[key]?.firstSeenAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
55
|
-
};
|
|
56
|
-
const p = getSqliteJsonPath();
|
|
57
|
-
await mkdir(dirname(p), { recursive: true });
|
|
58
|
-
await writeFile(p, JSON.stringify(data, null, 2), "utf8");
|
|
59
|
-
}
|
|
60
|
-
function scopedDatabases(data, projectKey) {
|
|
61
|
-
if (projectKey === void 0) return data.databases;
|
|
62
|
-
return Object.fromEntries(
|
|
63
|
-
Object.entries(data.databases).filter(
|
|
64
|
-
([, e]) => (e.scope === "global-project" || e.scope === "global-project-plugin") && e.projectKey === projectKey
|
|
65
|
-
)
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
async function listSqliteDbs(projectKey = void 0) {
|
|
69
|
-
const data = await loadSqliteDbs();
|
|
70
|
-
return Object.entries(scopedDatabases(data, projectKey)).map(([key, entry]) => ({ key, ...entry }));
|
|
39
|
+
return Object.entries(data.databases).map(([key, entry]) => ({ key, ...entry }));
|
|
71
40
|
}
|
|
72
41
|
async function listLocalSqliteDbs(projectDir) {
|
|
73
|
-
let projectId;
|
|
74
|
-
try {
|
|
75
|
-
const raw = await readFile(path.join(projectDir, ".crunes", "project.local.json"), "utf8");
|
|
76
|
-
projectId = JSON.parse(raw).id;
|
|
77
|
-
} catch {
|
|
78
|
-
return [];
|
|
79
|
-
}
|
|
80
42
|
const results = [];
|
|
81
43
|
const localSqliteDir = path.join(projectDir, ".crunes", "sqlite");
|
|
82
44
|
async function scanScope(scopeDir, scope, pluginId = null) {
|
|
@@ -89,13 +51,13 @@ async function listLocalSqliteDbs(projectDir) {
|
|
|
89
51
|
for (const entry of entries) {
|
|
90
52
|
if (!entry.isFile() || !entry.name.endsWith(".sqlite")) continue;
|
|
91
53
|
const name = entry.name.slice(0, -".sqlite".length);
|
|
92
|
-
const key = storageKey(scope, { projectId, pluginId, name });
|
|
93
|
-
const location = pluginId ? `@local-
|
|
94
|
-
results.push({ key, scope, projectKey:
|
|
54
|
+
const key = storageKey(scope, { projectId: null, pluginId, name });
|
|
55
|
+
const location = pluginId ? `@local-plugin-sqlite/${pluginId}/${name}` : `@local-sqlite/${name}`;
|
|
56
|
+
results.push({ key, scope, projectKey: null, pluginId, location, name, firstSeenAt: null, path: path.join(scopeDir, entry.name) });
|
|
95
57
|
}
|
|
96
58
|
}
|
|
97
|
-
await scanScope(path.join(localSqliteDir, "project"), "local
|
|
98
|
-
const pluginsDir = path.join(localSqliteDir, "
|
|
59
|
+
await scanScope(path.join(localSqliteDir, "project"), "local");
|
|
60
|
+
const pluginsDir = path.join(localSqliteDir, "plugins");
|
|
99
61
|
let pluginEntries;
|
|
100
62
|
try {
|
|
101
63
|
pluginEntries = await readdir(pluginsDir, { withFileTypes: true });
|
|
@@ -104,7 +66,7 @@ async function listLocalSqliteDbs(projectDir) {
|
|
|
104
66
|
}
|
|
105
67
|
for (const pluginEntry of pluginEntries) {
|
|
106
68
|
if (!pluginEntry.isDirectory()) continue;
|
|
107
|
-
await scanScope(path.join(pluginsDir, pluginEntry.name), "local-
|
|
69
|
+
await scanScope(path.join(pluginsDir, pluginEntry.name), "local-plugin", pluginEntry.name);
|
|
108
70
|
}
|
|
109
71
|
return results;
|
|
110
72
|
}
|
|
@@ -115,9 +77,9 @@ function resolveKey(id, databases) {
|
|
|
115
77
|
if (matches.length === 0) throw new Error(`No SQLite database matching "${id}".`);
|
|
116
78
|
throw new Error(`Ambiguous id "${id}" \u2014 matches: ${matches.join(", ")}.`);
|
|
117
79
|
}
|
|
118
|
-
async function deleteSqliteDb(id
|
|
80
|
+
async function deleteSqliteDb(id) {
|
|
119
81
|
const data = await loadSqliteDbs();
|
|
120
|
-
const key = resolveKey(id,
|
|
82
|
+
const key = resolveKey(id, data.databases);
|
|
121
83
|
const { path: dbPath, name } = data.databases[key];
|
|
122
84
|
await rm(dbPath, { force: true });
|
|
123
85
|
await rm(dbPath + "-wal", { force: true });
|
|
@@ -128,10 +90,10 @@ async function deleteSqliteDb(id, projectKey = void 0) {
|
|
|
128
90
|
await writeFile(p, JSON.stringify(data, null, 2), "utf8");
|
|
129
91
|
return { name };
|
|
130
92
|
}
|
|
131
|
-
async function querySqliteDb(id, sql
|
|
93
|
+
async function querySqliteDb(id, sql) {
|
|
132
94
|
const Database = await loadDatabase();
|
|
133
95
|
const data = await loadSqliteDbs();
|
|
134
|
-
const key = resolveKey(id,
|
|
96
|
+
const key = resolveKey(id, data.databases);
|
|
135
97
|
const { path: dbPath } = data.databases[key];
|
|
136
98
|
const db = new Database(dbPath, { readonly: true });
|
|
137
99
|
try {
|
|
@@ -143,9 +105,6 @@ async function querySqliteDb(id, sql, projectKey = void 0) {
|
|
|
143
105
|
|
|
144
106
|
export {
|
|
145
107
|
getSqlitePluginDir,
|
|
146
|
-
getSqliteProjectDir,
|
|
147
|
-
getSqliteProjectPluginDir,
|
|
148
|
-
upsertSqliteDb,
|
|
149
108
|
listSqliteDbs,
|
|
150
109
|
listLocalSqliteDbs,
|
|
151
110
|
deleteSqliteDb,
|
|
@@ -286,7 +286,11 @@ function formatNode(node, { prefix = "", indent = "" } = {}) {
|
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
288
|
function formatMembers(members, { prefix = "", indent = "" } = {}) {
|
|
289
|
-
|
|
289
|
+
const sorted = [...members ?? []].sort((a, b) => {
|
|
290
|
+
const rank = (k) => k === "namespace" ? 0 : k === "function" ? 1 : 2;
|
|
291
|
+
return rank(a.kind) - rank(b.kind);
|
|
292
|
+
});
|
|
293
|
+
return sorted.map((m) => formatNode(m, { prefix, indent })).filter(Boolean).join("\n\n");
|
|
290
294
|
}
|
|
291
295
|
|
|
292
296
|
export {
|