@lunora/cli 1.0.0-alpha.22 → 1.0.0-alpha.23
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/bin.mjs +1 -1
- package/dist/index.d.mts +33 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.mjs +1 -1
- package/dist/packem_chunks/handler10.mjs +7 -13
- package/dist/packem_chunks/handler11.mjs +18 -188
- package/dist/packem_chunks/handler12.mjs +175 -114
- package/dist/packem_chunks/handler13.mjs +117 -51
- package/dist/packem_chunks/handler14.mjs +49 -42
- package/dist/packem_chunks/handler15.mjs +45 -66
- package/dist/packem_chunks/handler16.mjs +72 -36
- package/dist/packem_chunks/handler17.mjs +37 -99
- package/dist/packem_chunks/handler18.mjs +86 -151
- package/dist/packem_chunks/handler19.mjs +147 -66
- package/dist/packem_chunks/handler20.mjs +70 -75
- package/dist/packem_chunks/handler21.mjs +70 -287
- package/dist/packem_chunks/handler9.mjs +310 -11
- package/dist/packem_chunks/runDeployCommand.mjs +102 -12
- package/dist/packem_shared/{COMMANDS-D3h9Iwvl.mjs → COMMANDS-Dwo9q7Bt.mjs} +18 -15
- package/dist/packem_shared/wrangler-secrets-P2_ZUR-k.mjs +47 -0
- package/package.json +2 -2
package/dist/bin.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -226,6 +226,35 @@ declare const createRecordingSpawner: (exitCode?: number) => {
|
|
|
226
226
|
calls: RecordedSpawn[];
|
|
227
227
|
spawner: Spawner;
|
|
228
228
|
};
|
|
229
|
+
interface SecretListRunnerResult {
|
|
230
|
+
code: number;
|
|
231
|
+
stderr: string;
|
|
232
|
+
stdout: string;
|
|
233
|
+
}
|
|
234
|
+
/** Runs an argv and resolves its captured output. Injected in tests. */
|
|
235
|
+
type SecretListRunner = (command: string, args: ReadonlyArray<string>, cwd: string) => Promise<SecretListRunnerResult>;
|
|
236
|
+
interface ListRemoteSecretsInputs {
|
|
237
|
+
cwd: string;
|
|
238
|
+
/** Cloudflare environment name (`--env`). */
|
|
239
|
+
env?: string;
|
|
240
|
+
/** Injected command runner; defaults to a real `wrangler secret list`. */
|
|
241
|
+
runner?: SecretListRunner;
|
|
242
|
+
/** Target a temporary-account deployment (`--temporary`). */
|
|
243
|
+
temporary?: boolean;
|
|
244
|
+
}
|
|
245
|
+
interface ListRemoteSecretsResult {
|
|
246
|
+
/** Diagnostic message when `ok` is false. */
|
|
247
|
+
error?: string;
|
|
248
|
+
/** Remote secret names (sorted), empty when none or on failure. */
|
|
249
|
+
names: ReadonlyArray<string>;
|
|
250
|
+
/** False when wrangler failed or its output could not be parsed. */
|
|
251
|
+
ok: boolean;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Parse `wrangler secret list --format json` output into a sorted name list.
|
|
255
|
+
* The payload is an array of `{ name, type }`; anything else yields `undefined`
|
|
256
|
+
* so the caller can report a parse failure rather than silently returning [].
|
|
257
|
+
*/
|
|
229
258
|
type FetchLike = (input: string, init?: {
|
|
230
259
|
body?: string;
|
|
231
260
|
headers?: Record<string, string>;
|
|
@@ -318,6 +347,10 @@ interface DeployCommandOptions {
|
|
|
318
347
|
preview?: boolean;
|
|
319
348
|
/** Railpack-availability probe injected in tests. Defaults to a real `railpack --version` + `BUILDKIT_HOST` check. */
|
|
320
349
|
railpackAvailable?: DockerProbe;
|
|
350
|
+
/** Confirm prompt for the missing-secret offer; injected in tests. Defaults to the TTY prompt. */
|
|
351
|
+
secretConfirm?: (message: string) => Promise<boolean>;
|
|
352
|
+
/** Remote-secret lister for the missing-secret offer; injected in tests. Defaults to `wrangler secret list`. */
|
|
353
|
+
secretLister?: (inputs: ListRemoteSecretsInputs) => Promise<ListRemoteSecretsResult>;
|
|
321
354
|
skipCodegen?: boolean;
|
|
322
355
|
spawner?: Spawner;
|
|
323
356
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -226,6 +226,35 @@ declare const createRecordingSpawner: (exitCode?: number) => {
|
|
|
226
226
|
calls: RecordedSpawn[];
|
|
227
227
|
spawner: Spawner;
|
|
228
228
|
};
|
|
229
|
+
interface SecretListRunnerResult {
|
|
230
|
+
code: number;
|
|
231
|
+
stderr: string;
|
|
232
|
+
stdout: string;
|
|
233
|
+
}
|
|
234
|
+
/** Runs an argv and resolves its captured output. Injected in tests. */
|
|
235
|
+
type SecretListRunner = (command: string, args: ReadonlyArray<string>, cwd: string) => Promise<SecretListRunnerResult>;
|
|
236
|
+
interface ListRemoteSecretsInputs {
|
|
237
|
+
cwd: string;
|
|
238
|
+
/** Cloudflare environment name (`--env`). */
|
|
239
|
+
env?: string;
|
|
240
|
+
/** Injected command runner; defaults to a real `wrangler secret list`. */
|
|
241
|
+
runner?: SecretListRunner;
|
|
242
|
+
/** Target a temporary-account deployment (`--temporary`). */
|
|
243
|
+
temporary?: boolean;
|
|
244
|
+
}
|
|
245
|
+
interface ListRemoteSecretsResult {
|
|
246
|
+
/** Diagnostic message when `ok` is false. */
|
|
247
|
+
error?: string;
|
|
248
|
+
/** Remote secret names (sorted), empty when none or on failure. */
|
|
249
|
+
names: ReadonlyArray<string>;
|
|
250
|
+
/** False when wrangler failed or its output could not be parsed. */
|
|
251
|
+
ok: boolean;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Parse `wrangler secret list --format json` output into a sorted name list.
|
|
255
|
+
* The payload is an array of `{ name, type }`; anything else yields `undefined`
|
|
256
|
+
* so the caller can report a parse failure rather than silently returning [].
|
|
257
|
+
*/
|
|
229
258
|
type FetchLike = (input: string, init?: {
|
|
230
259
|
body?: string;
|
|
231
260
|
headers?: Record<string, string>;
|
|
@@ -318,6 +347,10 @@ interface DeployCommandOptions {
|
|
|
318
347
|
preview?: boolean;
|
|
319
348
|
/** Railpack-availability probe injected in tests. Defaults to a real `railpack --version` + `BUILDKIT_HOST` check. */
|
|
320
349
|
railpackAvailable?: DockerProbe;
|
|
350
|
+
/** Confirm prompt for the missing-secret offer; injected in tests. Defaults to the TTY prompt. */
|
|
351
|
+
secretConfirm?: (message: string) => Promise<boolean>;
|
|
352
|
+
/** Remote-secret lister for the missing-secret offer; injected in tests. Defaults to `wrangler secret list`. */
|
|
353
|
+
secretLister?: (inputs: ListRemoteSecretsInputs) => Promise<ListRemoteSecretsResult>;
|
|
321
354
|
skipCodegen?: boolean;
|
|
322
355
|
spawner?: Spawner;
|
|
323
356
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { COMMANDS, VERSION, runCli } from './packem_shared/COMMANDS-
|
|
1
|
+
export { COMMANDS, VERSION, runCli } from './packem_shared/COMMANDS-Dwo9q7Bt.mjs';
|
|
2
2
|
export { runCodegenCommand } from './packem_chunks/runCodegenCommand.mjs';
|
|
3
3
|
export { DEFAULT_IMPORT_BATCH_SIZE, runExportCommand, runImportCommand } from './packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs';
|
|
4
4
|
export { runDeployCommand } from './packem_chunks/runDeployCommand.mjs';
|
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
import { d as defineHandler } from '../packem_shared/command-BC30oSBW.mjs';
|
|
2
2
|
import { a as resolveProductionWorkerUrl } from '../packem_shared/resolve-target-qbsJ_5sF.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { runExportCommand } from '../packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs';
|
|
4
4
|
|
|
5
|
-
const execute = defineHandler(
|
|
6
|
-
|
|
7
|
-
if (!file) {
|
|
8
|
-
logger.error("import requires a file. Usage: lunora import <path> [--table <name>]");
|
|
9
|
-
return { code: 1 };
|
|
10
|
-
}
|
|
11
|
-
return runImportCommand({
|
|
12
|
-
batchSize: options.batchSize,
|
|
13
|
-
file,
|
|
5
|
+
const execute = defineHandler(
|
|
6
|
+
({ argument, cwd, logger, options }) => runExportCommand({
|
|
14
7
|
logger,
|
|
8
|
+
out: argument[0] ?? options.out,
|
|
15
9
|
prod: options.prod === true,
|
|
16
|
-
|
|
10
|
+
tables: options.tables,
|
|
17
11
|
token: options.token,
|
|
18
12
|
url: resolveProductionWorkerUrl({ cwd, prod: options.prod === true, url: options.url })
|
|
19
|
-
})
|
|
20
|
-
|
|
13
|
+
})
|
|
14
|
+
);
|
|
21
15
|
|
|
22
16
|
export { execute };
|
|
@@ -1,192 +1,22 @@
|
|
|
1
|
-
import { readFileSync, existsSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { discoverSchema } from '@lunora/codegen';
|
|
4
|
-
import { readLinkedProject } from '@lunora/config';
|
|
5
|
-
import { parse } from 'jsonc-parser';
|
|
6
|
-
import { Project } from 'ts-morph';
|
|
7
1
|
import { d as defineHandler } from '../packem_shared/command-BC30oSBW.mjs';
|
|
2
|
+
import { a as resolveProductionWorkerUrl } from '../packem_shared/resolve-target-qbsJ_5sF.mjs';
|
|
3
|
+
import { runImportCommand } from '../packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs';
|
|
8
4
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
24
|
-
};
|
|
25
|
-
const arrayField = (record, key) => {
|
|
26
|
-
if (record === null || typeof record !== "object") {
|
|
27
|
-
return [];
|
|
28
|
-
}
|
|
29
|
-
const value = record[key];
|
|
30
|
-
return Array.isArray(value) ? value : [];
|
|
31
|
-
};
|
|
32
|
-
const summariseWrangler = (raw) => {
|
|
33
|
-
const durableObjectBindings = arrayField(raw.durable_objects ?? {}, "bindings");
|
|
34
|
-
const d1 = arrayField(raw, "d1_databases");
|
|
35
|
-
const vectorize = arrayField(raw, "vectorize");
|
|
36
|
-
return {
|
|
37
|
-
bindings: {
|
|
38
|
-
d1: d1.map((entry) => stringField(entry, "binding") ?? "<unnamed>"),
|
|
39
|
-
durableObjects: durableObjectBindings.map((entry) => stringField(entry, "name") ?? "<unnamed>"),
|
|
40
|
-
vectorize: vectorize.map((entry) => stringField(entry, "binding") ?? "<unnamed>")
|
|
41
|
-
},
|
|
42
|
-
compatibilityDate: stringField(raw, "compatibility_date"),
|
|
43
|
-
compatibilityFlags: arrayField(raw, "compatibility_flags").filter((entry) => typeof entry === "string"),
|
|
44
|
-
main: stringField(raw, "main"),
|
|
45
|
-
name: stringField(raw, "name")
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
const summariseSchema = (schema) => {
|
|
49
|
-
return {
|
|
50
|
-
tables: schema.tables.map((table) => {
|
|
51
|
-
let shard = "root";
|
|
52
|
-
if (table.shardMode === "global") {
|
|
53
|
-
shard = "global";
|
|
54
|
-
} else if (typeof table.shardMode === "object") {
|
|
55
|
-
shard = `shardBy(${table.shardMode.field})`;
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
indexes: table.indexes.length,
|
|
59
|
-
name: table.name,
|
|
60
|
-
shard
|
|
61
|
-
};
|
|
62
|
-
}),
|
|
63
|
-
vectorIndexes: schema.vectorIndexes.length
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
const collectLunoraPackages = (projectRoot) => {
|
|
67
|
-
const pkgPath = join(projectRoot, "package.json");
|
|
68
|
-
if (!existsSync(pkgPath)) {
|
|
69
|
-
return [];
|
|
70
|
-
}
|
|
71
|
-
let pkg;
|
|
72
|
-
try {
|
|
73
|
-
pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
74
|
-
} catch {
|
|
75
|
-
return [];
|
|
76
|
-
}
|
|
77
|
-
if (pkg === null || typeof pkg !== "object") {
|
|
78
|
-
return [];
|
|
79
|
-
}
|
|
80
|
-
const sections = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"];
|
|
81
|
-
const seen = /* @__PURE__ */ new Map();
|
|
82
|
-
for (const section of sections) {
|
|
83
|
-
const block = pkg[section];
|
|
84
|
-
if (block === null || typeof block !== "object") {
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
for (const [name, version] of Object.entries(block)) {
|
|
88
|
-
if (!name.startsWith("@lunora/")) {
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
if (typeof version === "string" && !seen.has(name)) {
|
|
92
|
-
seen.set(name, version);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return [...seen.entries()].toSorted(([a], [b]) => a.localeCompare(b)).map(([name, version]) => {
|
|
97
|
-
return { name, version };
|
|
5
|
+
const execute = defineHandler(({ argument, cwd, logger, options }) => {
|
|
6
|
+
const file = argument[0];
|
|
7
|
+
if (!file) {
|
|
8
|
+
logger.error("import requires a file. Usage: lunora import <path> [--table <name>]");
|
|
9
|
+
return { code: 1 };
|
|
10
|
+
}
|
|
11
|
+
return runImportCommand({
|
|
12
|
+
batchSize: options.batchSize,
|
|
13
|
+
file,
|
|
14
|
+
logger,
|
|
15
|
+
prod: options.prod === true,
|
|
16
|
+
table: options.table,
|
|
17
|
+
token: options.token,
|
|
18
|
+
url: resolveProductionWorkerUrl({ cwd, prod: options.prod === true, url: options.url })
|
|
98
19
|
});
|
|
99
|
-
};
|
|
100
|
-
const collectInfo = (projectRoot) => {
|
|
101
|
-
const lunoraPackages = collectLunoraPackages(projectRoot);
|
|
102
|
-
const wranglerPath = findWranglerFile(projectRoot);
|
|
103
|
-
let wrangler;
|
|
104
|
-
if (wranglerPath) {
|
|
105
|
-
try {
|
|
106
|
-
wrangler = summariseWrangler(parse(readFileSync(wranglerPath, "utf8")));
|
|
107
|
-
} catch {
|
|
108
|
-
wrangler = void 0;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
const schemaPath = join(projectRoot, "lunora", "schema.ts");
|
|
112
|
-
let schema;
|
|
113
|
-
let schemaError;
|
|
114
|
-
if (existsSync(schemaPath)) {
|
|
115
|
-
try {
|
|
116
|
-
const project = new Project({ skipAddingFilesFromTsConfig: true, useInMemoryFileSystem: false });
|
|
117
|
-
schema = summariseSchema(discoverSchema(project, schemaPath));
|
|
118
|
-
} catch (error) {
|
|
119
|
-
schemaError = error instanceof Error ? error.message : String(error);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return {
|
|
123
|
-
link: readLinkedProject(projectRoot),
|
|
124
|
-
lunoraPackages,
|
|
125
|
-
projectRoot,
|
|
126
|
-
schema,
|
|
127
|
-
schemaError,
|
|
128
|
-
wrangler,
|
|
129
|
-
wranglerPath
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
const renderText = (snapshot, logger) => {
|
|
133
|
-
logger.info(`project: ${snapshot.projectRoot}`);
|
|
134
|
-
logger.info("");
|
|
135
|
-
logger.info("@lunora/* packages:");
|
|
136
|
-
if (snapshot.lunoraPackages.length === 0) {
|
|
137
|
-
logger.info(" (none found in package.json)");
|
|
138
|
-
} else {
|
|
139
|
-
for (const pkg of snapshot.lunoraPackages) {
|
|
140
|
-
logger.info(` ${pkg.name}@${pkg.version}`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
logger.info("");
|
|
144
|
-
if (snapshot.wrangler) {
|
|
145
|
-
logger.info(`wrangler: ${snapshot.wranglerPath ?? ""}`);
|
|
146
|
-
logger.info(` name: ${snapshot.wrangler.name ?? "<unset>"}`);
|
|
147
|
-
logger.info(` main: ${snapshot.wrangler.main ?? "<unset>"}`);
|
|
148
|
-
logger.info(` compatibility_date: ${snapshot.wrangler.compatibilityDate ?? "<unset>"}`);
|
|
149
|
-
logger.info(` compatibility_flags: ${snapshot.wrangler.compatibilityFlags.join(", ") || "<none>"}`);
|
|
150
|
-
logger.info(` durable objects: ${snapshot.wrangler.bindings.durableObjects.join(", ") || "<none>"}`);
|
|
151
|
-
logger.info(` d1 databases: ${snapshot.wrangler.bindings.d1.join(", ") || "<none>"}`);
|
|
152
|
-
logger.info(` vectorize indexes: ${snapshot.wrangler.bindings.vectorize.join(", ") || "<none>"}`);
|
|
153
|
-
} else {
|
|
154
|
-
logger.info("wrangler: (not found)");
|
|
155
|
-
}
|
|
156
|
-
logger.info("");
|
|
157
|
-
if (snapshot.link) {
|
|
158
|
-
logger.info(`link: ${snapshot.link.workerName ?? "(unnamed)"} -> ${snapshot.link.workerUrl ?? "<no url>"}`);
|
|
159
|
-
if (snapshot.link.env !== void 0) {
|
|
160
|
-
logger.info(` env: ${snapshot.link.env}`);
|
|
161
|
-
}
|
|
162
|
-
} else {
|
|
163
|
-
logger.info("link: (not linked — run `lunora link --url <https://your-worker>`)");
|
|
164
|
-
}
|
|
165
|
-
logger.info("");
|
|
166
|
-
if (snapshot.schemaError !== void 0) {
|
|
167
|
-
logger.warn(`schema: parse error — ${snapshot.schemaError}`);
|
|
168
|
-
} else if (snapshot.schema) {
|
|
169
|
-
logger.info(`schema: ${String(snapshot.schema.tables.length)} table(s), ${String(snapshot.schema.vectorIndexes)} vector index(es)`);
|
|
170
|
-
for (const table of snapshot.schema.tables) {
|
|
171
|
-
logger.info(` ${table.name} [${table.shard}, ${String(table.indexes)} index(es)]`);
|
|
172
|
-
}
|
|
173
|
-
} else {
|
|
174
|
-
logger.info("schema: (no lunora/schema.ts)");
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
const runInfoCommand = (options) => {
|
|
178
|
-
const cwd = options.cwd ?? process.cwd();
|
|
179
|
-
const snapshot = collectInfo(cwd);
|
|
180
|
-
if (options.json) {
|
|
181
|
-
process.stdout.write(`${JSON.stringify(snapshot, void 0, 2)}
|
|
182
|
-
`);
|
|
183
|
-
} else {
|
|
184
|
-
renderText(snapshot, options.logger);
|
|
185
|
-
}
|
|
186
|
-
return { code: 0, snapshot };
|
|
187
|
-
};
|
|
188
|
-
const execute = defineHandler(
|
|
189
|
-
({ cwd, logger, options }) => runInfoCommand({ cwd, json: options.json === true, logger })
|
|
190
|
-
);
|
|
20
|
+
});
|
|
191
21
|
|
|
192
|
-
export {
|
|
22
|
+
export { execute };
|
|
@@ -1,131 +1,192 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { discoverSchema } from '@lunora/codegen';
|
|
4
|
+
import { readLinkedProject } from '@lunora/config';
|
|
5
|
+
import { parse } from 'jsonc-parser';
|
|
6
|
+
import { Project } from 'ts-morph';
|
|
2
7
|
import { d as defineHandler } from '../packem_shared/command-BC30oSBW.mjs';
|
|
3
|
-
import { a as resolveProductionWorkerUrl } from '../packem_shared/resolve-target-qbsJ_5sF.mjs';
|
|
4
8
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
+
const findWranglerFile = (projectRoot) => {
|
|
10
|
+
for (const candidate of ["wrangler.jsonc", "wrangler.json"]) {
|
|
11
|
+
const fullPath = join(projectRoot, candidate);
|
|
12
|
+
if (existsSync(fullPath)) {
|
|
13
|
+
return fullPath;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return void 0;
|
|
17
|
+
};
|
|
18
|
+
const stringField = (record, key) => {
|
|
19
|
+
if (record === null || typeof record !== "object") {
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
const value = record[key];
|
|
23
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
24
|
+
};
|
|
25
|
+
const arrayField = (record, key) => {
|
|
26
|
+
if (record === null || typeof record !== "object") {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
const value = record[key];
|
|
30
|
+
return Array.isArray(value) ? value : [];
|
|
31
|
+
};
|
|
32
|
+
const summariseWrangler = (raw) => {
|
|
33
|
+
const durableObjectBindings = arrayField(raw.durable_objects ?? {}, "bindings");
|
|
34
|
+
const d1 = arrayField(raw, "d1_databases");
|
|
35
|
+
const vectorize = arrayField(raw, "vectorize");
|
|
9
36
|
return {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
37
|
+
bindings: {
|
|
38
|
+
d1: d1.map((entry) => stringField(entry, "binding") ?? "<unnamed>"),
|
|
39
|
+
durableObjects: durableObjectBindings.map((entry) => stringField(entry, "name") ?? "<unnamed>"),
|
|
40
|
+
vectorize: vectorize.map((entry) => stringField(entry, "binding") ?? "<unnamed>")
|
|
41
|
+
},
|
|
42
|
+
compatibilityDate: stringField(raw, "compatibility_date"),
|
|
43
|
+
compatibilityFlags: arrayField(raw, "compatibility_flags").filter((entry) => typeof entry === "string"),
|
|
44
|
+
main: stringField(raw, "main"),
|
|
45
|
+
name: stringField(raw, "name")
|
|
18
46
|
};
|
|
19
47
|
};
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
...formatSection(
|
|
38
|
-
"Write-conflict hot-spots (OCC contention — candidates for sharding):",
|
|
39
|
-
report.writeContention,
|
|
40
|
-
"none — no write conflicts observed",
|
|
41
|
-
(row) => `${row.path} ${row.conflicts.toString()}/${row.calls.toString()} calls (${percent(row.rate)})`
|
|
42
|
-
),
|
|
43
|
-
"",
|
|
44
|
-
...formatSection(
|
|
45
|
-
"Error hot-spots:",
|
|
46
|
-
report.errorHotspots,
|
|
47
|
-
"none — no errors observed",
|
|
48
|
-
(row) => `${row.path} ${row.errors.toString()}/${row.calls.toString()} calls (${percent(row.rate)})${errorTail(row)}`
|
|
49
|
-
),
|
|
50
|
-
"",
|
|
51
|
-
...formatSection(
|
|
52
|
-
"Latency outliers (slowest single call):",
|
|
53
|
-
report.latencyOutliers,
|
|
54
|
-
"none — no functions have run",
|
|
55
|
-
(row) => `${row.path} max ${formatMs(row.maxDurationMs)}, mean ${formatMs(row.meanDurationMs)} over ${row.calls.toString()} calls`
|
|
56
|
-
)
|
|
57
|
-
].join("\n");
|
|
48
|
+
const summariseSchema = (schema) => {
|
|
49
|
+
return {
|
|
50
|
+
tables: schema.tables.map((table) => {
|
|
51
|
+
let shard = "root";
|
|
52
|
+
if (table.shardMode === "global") {
|
|
53
|
+
shard = "global";
|
|
54
|
+
} else if (typeof table.shardMode === "object") {
|
|
55
|
+
shard = `shardBy(${table.shardMode.field})`;
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
indexes: table.indexes.length,
|
|
59
|
+
name: table.name,
|
|
60
|
+
shard
|
|
61
|
+
};
|
|
62
|
+
}),
|
|
63
|
+
vectorIndexes: schema.vectorIndexes.length
|
|
64
|
+
};
|
|
58
65
|
};
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
66
|
+
const collectLunoraPackages = (projectRoot) => {
|
|
67
|
+
const pkgPath = join(projectRoot, "package.json");
|
|
68
|
+
if (!existsSync(pkgPath)) {
|
|
69
|
+
return [];
|
|
62
70
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return { code: 1 };
|
|
71
|
+
let pkg;
|
|
72
|
+
try {
|
|
73
|
+
pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
74
|
+
} catch {
|
|
75
|
+
return [];
|
|
69
76
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
options.logger.error("admin token required — pass --token or set LUNORA_ADMIN_TOKEN");
|
|
73
|
-
return { code: 1 };
|
|
77
|
+
if (pkg === null || typeof pkg !== "object") {
|
|
78
|
+
return [];
|
|
74
79
|
}
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
80
|
+
const sections = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"];
|
|
81
|
+
const seen = /* @__PURE__ */ new Map();
|
|
82
|
+
for (const section of sections) {
|
|
83
|
+
const block = pkg[section];
|
|
84
|
+
if (block === null || typeof block !== "object") {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
for (const [name, version] of Object.entries(block)) {
|
|
88
|
+
if (!name.startsWith("@lunora/")) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (typeof version === "string" && !seen.has(name)) {
|
|
92
|
+
seen.set(name, version);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
78
95
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
96
|
+
return [...seen.entries()].toSorted(([a], [b]) => a.localeCompare(b)).map(([name, version]) => {
|
|
97
|
+
return { name, version };
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
const collectInfo = (projectRoot) => {
|
|
101
|
+
const lunoraPackages = collectLunoraPackages(projectRoot);
|
|
102
|
+
const wranglerPath = findWranglerFile(projectRoot);
|
|
103
|
+
let wrangler;
|
|
104
|
+
if (wranglerPath) {
|
|
105
|
+
try {
|
|
106
|
+
wrangler = summariseWrangler(parse(readFileSync(wranglerPath, "utf8")));
|
|
107
|
+
} catch {
|
|
108
|
+
wrangler = void 0;
|
|
109
|
+
}
|
|
83
110
|
}
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
111
|
+
const schemaPath = join(projectRoot, "lunora", "schema.ts");
|
|
112
|
+
let schema;
|
|
113
|
+
let schemaError;
|
|
114
|
+
if (existsSync(schemaPath)) {
|
|
115
|
+
try {
|
|
116
|
+
const project = new Project({ skipAddingFilesFromTsConfig: true, useInMemoryFileSystem: false });
|
|
117
|
+
schema = summariseSchema(discoverSchema(project, schemaPath));
|
|
118
|
+
} catch (error) {
|
|
119
|
+
schemaError = error instanceof Error ? error.message : String(error);
|
|
120
|
+
}
|
|
87
121
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
122
|
+
return {
|
|
123
|
+
link: readLinkedProject(projectRoot),
|
|
124
|
+
lunoraPackages,
|
|
125
|
+
projectRoot,
|
|
126
|
+
schema,
|
|
127
|
+
schemaError,
|
|
128
|
+
wrangler,
|
|
129
|
+
wranglerPath
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
const renderText = (snapshot, logger) => {
|
|
133
|
+
logger.info(`project: ${snapshot.projectRoot}`);
|
|
134
|
+
logger.info("");
|
|
135
|
+
logger.info("@lunora/* packages:");
|
|
136
|
+
if (snapshot.lunoraPackages.length === 0) {
|
|
137
|
+
logger.info(" (none found in package.json)");
|
|
138
|
+
} else {
|
|
139
|
+
for (const pkg of snapshot.lunoraPackages) {
|
|
140
|
+
logger.info(` ${pkg.name}@${pkg.version}`);
|
|
141
|
+
}
|
|
98
142
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
143
|
+
logger.info("");
|
|
144
|
+
if (snapshot.wrangler) {
|
|
145
|
+
logger.info(`wrangler: ${snapshot.wranglerPath ?? ""}`);
|
|
146
|
+
logger.info(` name: ${snapshot.wrangler.name ?? "<unset>"}`);
|
|
147
|
+
logger.info(` main: ${snapshot.wrangler.main ?? "<unset>"}`);
|
|
148
|
+
logger.info(` compatibility_date: ${snapshot.wrangler.compatibilityDate ?? "<unset>"}`);
|
|
149
|
+
logger.info(` compatibility_flags: ${snapshot.wrangler.compatibilityFlags.join(", ") || "<none>"}`);
|
|
150
|
+
logger.info(` durable objects: ${snapshot.wrangler.bindings.durableObjects.join(", ") || "<none>"}`);
|
|
151
|
+
logger.info(` d1 databases: ${snapshot.wrangler.bindings.d1.join(", ") || "<none>"}`);
|
|
152
|
+
logger.info(` vectorize indexes: ${snapshot.wrangler.bindings.vectorize.join(", ") || "<none>"}`);
|
|
153
|
+
} else {
|
|
154
|
+
logger.info("wrangler: (not found)");
|
|
155
|
+
}
|
|
156
|
+
logger.info("");
|
|
157
|
+
if (snapshot.link) {
|
|
158
|
+
logger.info(`link: ${snapshot.link.workerName ?? "(unnamed)"} -> ${snapshot.link.workerUrl ?? "<no url>"}`);
|
|
159
|
+
if (snapshot.link.env !== void 0) {
|
|
160
|
+
logger.info(` env: ${snapshot.link.env}`);
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
logger.info("link: (not linked — run `lunora link --url <https://your-worker>`)");
|
|
105
164
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
165
|
+
logger.info("");
|
|
166
|
+
if (snapshot.schemaError !== void 0) {
|
|
167
|
+
logger.warn(`schema: parse error — ${snapshot.schemaError}`);
|
|
168
|
+
} else if (snapshot.schema) {
|
|
169
|
+
logger.info(`schema: ${String(snapshot.schema.tables.length)} table(s), ${String(snapshot.schema.vectorIndexes)} vector index(es)`);
|
|
170
|
+
for (const table of snapshot.schema.tables) {
|
|
171
|
+
logger.info(` ${table.name} [${table.shard}, ${String(table.indexes)} index(es)]`);
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
logger.info("schema: (no lunora/schema.ts)");
|
|
111
175
|
}
|
|
112
|
-
const report = buildInsightsReport(functions, resolveLimit(options.limit));
|
|
113
|
-
options.logger.info(options.json ? JSON.stringify(report, void 0, 2) : formatInsightsReport(report));
|
|
114
|
-
return { code: 0, report };
|
|
115
176
|
};
|
|
116
|
-
const
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
})
|
|
129
|
-
|
|
177
|
+
const runInfoCommand = (options) => {
|
|
178
|
+
const cwd = options.cwd ?? process.cwd();
|
|
179
|
+
const snapshot = collectInfo(cwd);
|
|
180
|
+
if (options.json) {
|
|
181
|
+
process.stdout.write(`${JSON.stringify(snapshot, void 0, 2)}
|
|
182
|
+
`);
|
|
183
|
+
} else {
|
|
184
|
+
renderText(snapshot, options.logger);
|
|
185
|
+
}
|
|
186
|
+
return { code: 0, snapshot };
|
|
187
|
+
};
|
|
188
|
+
const execute = defineHandler(
|
|
189
|
+
({ cwd, logger, options }) => runInfoCommand({ cwd, json: options.json === true, logger })
|
|
190
|
+
);
|
|
130
191
|
|
|
131
|
-
export {
|
|
192
|
+
export { collectInfo, execute, runInfoCommand };
|