@moku-labs/worker 0.7.0 → 0.7.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/dist/{cli-C8DdTtzn.cjs → cli-BBO_YNVC.cjs} +122 -71
- package/dist/{cli-Bb37rYq_.mjs → cli-D67ea3Lu.mjs} +122 -71
- package/dist/cli.cjs +1 -1
- package/dist/cli.d.cts +1 -1
- package/dist/cli.d.mts +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/{index-BKOUpKtC.d.cts → index-Dse6wZJH.d.cts} +39 -16
- package/dist/{index-BKOUpKtC.d.mts → index-Dse6wZJH.d.mts} +39 -16
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +5 -2
- package/dist/index.d.mts +5 -2
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -761,7 +761,8 @@ const createQueuesApi = (ctx) => {
|
|
|
761
761
|
deployManifest: () => Object.values(ctx.config).map((instance) => ({
|
|
762
762
|
kind: "queue",
|
|
763
763
|
name: instance.name,
|
|
764
|
-
binding: instance.binding
|
|
764
|
+
binding: instance.binding,
|
|
765
|
+
...instance.onMessage ? { consumer: true } : {}
|
|
765
766
|
}))
|
|
766
767
|
};
|
|
767
768
|
};
|
|
@@ -2527,16 +2528,20 @@ const parseJsonc = (source) => {
|
|
|
2527
2528
|
*
|
|
2528
2529
|
* @param resources - All resource descriptors from the manifest.
|
|
2529
2530
|
* @param ids - Captured Cloudflare ids keyed by binding; the entry's `id` is filled from here.
|
|
2530
|
-
* @returns One wrangler KV namespace entry per kv resource
|
|
2531
|
+
* @returns One wrangler KV namespace entry per kv resource — real `id` when known, omitted otherwise
|
|
2532
|
+
* (wrangler rejects an empty `id`, but a local-dev / freshly-generated config validates without one).
|
|
2531
2533
|
* @example
|
|
2532
2534
|
* ```ts
|
|
2533
2535
|
* const kv = buildKvNamespaces([{ kind: "kv", binding: "CACHE" }], { CACHE: "ns123" });
|
|
2534
2536
|
* ```
|
|
2535
2537
|
*/
|
|
2536
|
-
const buildKvNamespaces = (resources, ids) => resources.filter((resource) => resource.kind === "kv").map((resource) =>
|
|
2537
|
-
|
|
2538
|
-
id
|
|
2539
|
-
|
|
2538
|
+
const buildKvNamespaces = (resources, ids) => resources.filter((resource) => resource.kind === "kv").map((resource) => {
|
|
2539
|
+
const id = ids[resource.binding];
|
|
2540
|
+
return id ? {
|
|
2541
|
+
binding: resource.binding,
|
|
2542
|
+
id
|
|
2543
|
+
} : { binding: resource.binding };
|
|
2544
|
+
});
|
|
2540
2545
|
/**
|
|
2541
2546
|
* Build the wrangler `r2_buckets` array from the manifest's r2 resources.
|
|
2542
2547
|
*
|
|
@@ -2563,31 +2568,41 @@ const buildR2Buckets = (resources) => resources.filter((resource) => resource.ki
|
|
|
2563
2568
|
* ```
|
|
2564
2569
|
*/
|
|
2565
2570
|
const buildD1Databases = (resources, ids) => resources.filter((resource) => resource.kind === "d1").map((resource) => {
|
|
2571
|
+
const databaseId = ids[resource.binding];
|
|
2566
2572
|
const entry = {
|
|
2567
2573
|
binding: resource.binding,
|
|
2568
|
-
database_name: resource.name
|
|
2569
|
-
database_id: ids[resource.binding] ?? ""
|
|
2574
|
+
database_name: resource.name
|
|
2570
2575
|
};
|
|
2576
|
+
if (databaseId) entry.database_id = databaseId;
|
|
2571
2577
|
if (resource.migrations) entry.migrations_dir = resource.migrations;
|
|
2572
2578
|
return entry;
|
|
2573
2579
|
});
|
|
2574
2580
|
/**
|
|
2575
|
-
* Build the wrangler `queues` producers
|
|
2581
|
+
* Build the wrangler `queues` section (producers + consumers) from the manifest's queue resources.
|
|
2582
|
+
* Every queue is a `producer`; a queue flagged `consumer: true` (it declares an `onMessage` handler)
|
|
2583
|
+
* is ALSO registered as a `consumer` so wrangler delivers its messages to this Worker's queue()
|
|
2584
|
+
* handler — both locally under `wrangler dev` and in production. Without the consumer entry the
|
|
2585
|
+
* handler never runs (the bug that silently drops a queue-driven activity feed).
|
|
2576
2586
|
*
|
|
2577
2587
|
* @param resources - All resource descriptors from the manifest.
|
|
2578
|
-
* @returns The queues section, or undefined when there are
|
|
2588
|
+
* @returns The queues section (producers, plus consumers when any), or undefined when there are none.
|
|
2579
2589
|
* @example
|
|
2580
2590
|
* ```ts
|
|
2581
|
-
* const q = buildQueues([{ kind: "queue", name: "tracker-activity", binding: "ACTIVITY" }]);
|
|
2591
|
+
* const q = buildQueues([{ kind: "queue", name: "tracker-activity", binding: "ACTIVITY", consumer: true }]);
|
|
2582
2592
|
* ```
|
|
2583
2593
|
*/
|
|
2584
2594
|
const buildQueues = (resources) => {
|
|
2585
2595
|
const queueResources = resources.filter((resource) => resource.kind === "queue");
|
|
2586
2596
|
if (queueResources.length === 0) return void 0;
|
|
2587
|
-
|
|
2597
|
+
const producers = queueResources.map((resource) => ({
|
|
2588
2598
|
queue: resource.name,
|
|
2589
2599
|
binding: resource.binding
|
|
2590
|
-
}))
|
|
2600
|
+
}));
|
|
2601
|
+
const consumers = queueResources.filter((resource) => resource.consumer === true).map((resource) => ({ queue: resource.name }));
|
|
2602
|
+
return consumers.length > 0 ? {
|
|
2603
|
+
producers,
|
|
2604
|
+
consumers
|
|
2605
|
+
} : { producers };
|
|
2591
2606
|
};
|
|
2592
2607
|
/**
|
|
2593
2608
|
* Build the wrangler `durable_objects` bindings section from the manifest's do resources.
|
|
@@ -2695,7 +2710,8 @@ const wranglerExtra = (config) => {
|
|
|
2695
2710
|
* @param configFile - Path to the wrangler config file.
|
|
2696
2711
|
* @param manifest - The assembled deploy manifest.
|
|
2697
2712
|
* @param ids - Captured Cloudflare ids keyed by binding (kv namespace id, d1 database id). Defaults
|
|
2698
|
-
* to an empty map, in which case `id`/`database_id` are
|
|
2713
|
+
* to an empty map, in which case `id`/`database_id` are OMITTED (not "") so the generated config
|
|
2714
|
+
* still validates for local `dev` (wrangler rejects an empty id); a deploy fills the real ids.
|
|
2699
2715
|
* @param extra - Extra top-level wrangler keys to merge in (the app's `deploy.wrangler` config).
|
|
2700
2716
|
* @returns Resolves once the file is written.
|
|
2701
2717
|
* @example
|
|
@@ -3158,6 +3174,50 @@ const createDeployApi = (ctx) => ({
|
|
|
3158
3174
|
await runDev(ctx, opts, realDevDeps());
|
|
3159
3175
|
},
|
|
3160
3176
|
/**
|
|
3177
|
+
* Execute a SQL file against a configured D1 database via `wrangler d1 execute` — for seeding dev
|
|
3178
|
+
* data. Local by default (applies that database's migrations first so the file's tables exist);
|
|
3179
|
+
* `opts.remote` seeds Cloudflare (schema is applied by `deploy`). Generates the wrangler config up
|
|
3180
|
+
* front so the binding resolves even on a first run. Streams wrangler's output.
|
|
3181
|
+
*
|
|
3182
|
+
* @param sqlFile - Path to the SQL file to execute (e.g. "db/seed.sql").
|
|
3183
|
+
* @param opts - Optional options.
|
|
3184
|
+
* @param opts.stage - Stage for the generated config's resource names (defaults to the app stage).
|
|
3185
|
+
* @param opts.binding - The d1 binding to target when more than one is configured (e.g. "DB").
|
|
3186
|
+
* @param opts.remote - Seed the remote (Cloudflare) D1 instead of the local one.
|
|
3187
|
+
* @returns Resolves once wrangler finishes executing the file.
|
|
3188
|
+
* @example
|
|
3189
|
+
* ```ts
|
|
3190
|
+
* await api.seed("db/seed.sql"); // local default d1 (migrate, then execute)
|
|
3191
|
+
* await api.seed("db/seed.sql", { remote: true }); // remote d1
|
|
3192
|
+
* ```
|
|
3193
|
+
*/
|
|
3194
|
+
async seed(sqlFile, opts) {
|
|
3195
|
+
if (!ctx.has("d1")) throw new Error("[moku-worker] seed: no d1 database is configured.");
|
|
3196
|
+
const stage = opts?.stage ?? ctx.global.stage;
|
|
3197
|
+
await writeWranglerConfig(ctx.config.configFile, assembleManifest(ctx, stage), {}, wranglerExtra(ctx.config));
|
|
3198
|
+
const databases = ctx.require(d1Plugin).deployManifest();
|
|
3199
|
+
const wanted = opts?.binding;
|
|
3200
|
+
const matched = wanted === void 0 ? databases : databases.filter((database) => database.binding === wanted);
|
|
3201
|
+
const target = matched.length === 1 ? matched[0] : void 0;
|
|
3202
|
+
if (target === void 0) throw new Error(wanted === void 0 ? `[moku-worker] seed: ${String(databases.length)} d1 databases configured — pass { binding } to choose one.` : `[moku-worker] seed: no d1 database is bound to "${wanted}".`);
|
|
3203
|
+
const scope = opts?.remote === true ? "--remote" : "--local";
|
|
3204
|
+
if (scope === "--local" && target.migrations !== void 0) await runWranglerInherit([
|
|
3205
|
+
"d1",
|
|
3206
|
+
"migrations",
|
|
3207
|
+
"apply",
|
|
3208
|
+
target.binding,
|
|
3209
|
+
"--local"
|
|
3210
|
+
]);
|
|
3211
|
+
await runWranglerInherit([
|
|
3212
|
+
"d1",
|
|
3213
|
+
"execute",
|
|
3214
|
+
target.binding,
|
|
3215
|
+
scope,
|
|
3216
|
+
"--file",
|
|
3217
|
+
sqlFile
|
|
3218
|
+
]);
|
|
3219
|
+
},
|
|
3220
|
+
/**
|
|
3161
3221
|
* Scaffold a starting wrangler config (and CI files when ci is set).
|
|
3162
3222
|
* Idempotent: an existing config file is left untouched.
|
|
3163
3223
|
*
|
|
@@ -3284,54 +3344,10 @@ const deployPlugin = createPlugin("deploy", {
|
|
|
3284
3344
|
/**
|
|
3285
3345
|
* @file cli plugin — argv parsing helpers (isolated so they unit-test without a real process).
|
|
3286
3346
|
*
|
|
3287
|
-
* `dev`
|
|
3288
|
-
*
|
|
3347
|
+
* `deploy`/`dev` resolve the target stage from the command line (`--stage dev`) so a consumer never
|
|
3348
|
+
* hardcodes it. The dev PORT is not parsed here — it comes only from the `dev()` argument (no hidden
|
|
3349
|
+
* argv/config resolution). Pure: takes an argv array, reads no globals. Node-only tooling.
|
|
3289
3350
|
*/
|
|
3290
|
-
/** The valid TCP port range a `--port` value must fall within to be accepted. */
|
|
3291
|
-
const MAX_PORT = 65535;
|
|
3292
|
-
/**
|
|
3293
|
-
* Extract a `--port`/`-p` value from a single token (and the token after it, for the spaced form).
|
|
3294
|
-
*
|
|
3295
|
-
* @param token - The current argv token.
|
|
3296
|
-
* @param next - The following argv token (the value, for the `--port 3000` spaced form).
|
|
3297
|
-
* @returns The raw string value when this token is a port flag, else undefined.
|
|
3298
|
-
* @example
|
|
3299
|
-
* ```ts
|
|
3300
|
-
* portValueFrom("--port=3000", undefined); // "3000"
|
|
3301
|
-
* portValueFrom("--port", "3000"); // "3000"
|
|
3302
|
-
* portValueFrom("--config", "x"); // undefined
|
|
3303
|
-
* ```
|
|
3304
|
-
*/
|
|
3305
|
-
const portValueFrom = (token, next) => {
|
|
3306
|
-
const inline = /^(?:--port|-p)=(.+)$/u.exec(token);
|
|
3307
|
-
if (inline) return inline[1];
|
|
3308
|
-
if (token === "--port" || token === "-p") return next;
|
|
3309
|
-
};
|
|
3310
|
-
/**
|
|
3311
|
-
* Parse a `--port <n>` / `--port=<n>` / `-p <n>` flag out of an argv array.
|
|
3312
|
-
*
|
|
3313
|
-
* Returns the first valid port (a positive integer ≤ 65535) found, or undefined when the flag is
|
|
3314
|
-
* absent or its value is not a usable port — letting the caller fall back to a default.
|
|
3315
|
-
*
|
|
3316
|
-
* @param argv - The argv array to scan (the caller passes the process argv).
|
|
3317
|
-
* @returns The parsed port number, or undefined when no valid `--port`/`-p` flag is present.
|
|
3318
|
-
* @example
|
|
3319
|
-
* ```ts
|
|
3320
|
-
* parsePortArg(["bun", "scripts/dev.ts", "--port", "3000"]); // 3000
|
|
3321
|
-
* parsePortArg(["bun", "scripts/dev.ts", "--port=3000"]); // 3000
|
|
3322
|
-
* parsePortArg(["bun", "scripts/dev.ts"]); // undefined
|
|
3323
|
-
* ```
|
|
3324
|
-
*/
|
|
3325
|
-
const parsePortArg = (argv) => {
|
|
3326
|
-
for (let index = 0; index < argv.length; index++) {
|
|
3327
|
-
const token = argv[index];
|
|
3328
|
-
if (token === void 0) continue;
|
|
3329
|
-
const raw = portValueFrom(token, argv[index + 1]);
|
|
3330
|
-
if (raw === void 0) continue;
|
|
3331
|
-
const port = Number(raw);
|
|
3332
|
-
if (Number.isInteger(port) && port > 0 && port <= MAX_PORT) return port;
|
|
3333
|
-
}
|
|
3334
|
-
};
|
|
3335
3351
|
/**
|
|
3336
3352
|
* Extract a `--stage` value from a single token (and the token after it, for the spaced form).
|
|
3337
3353
|
*
|
|
@@ -3342,7 +3358,7 @@ const parsePortArg = (argv) => {
|
|
|
3342
3358
|
* ```ts
|
|
3343
3359
|
* stageValueFrom("--stage=dev", undefined); // "dev"
|
|
3344
3360
|
* stageValueFrom("--stage", "dev"); // "dev"
|
|
3345
|
-
* stageValueFrom("--
|
|
3361
|
+
* stageValueFrom("--other", "x"); // undefined
|
|
3346
3362
|
* ```
|
|
3347
3363
|
*/
|
|
3348
3364
|
const stageValueFrom = (token, next) => {
|
|
@@ -3392,19 +3408,21 @@ const parseStageArg = (argv) => {
|
|
|
3392
3408
|
*/
|
|
3393
3409
|
const createCliApi = (ctx) => ({
|
|
3394
3410
|
/**
|
|
3395
|
-
* Run the Worker locally.
|
|
3396
|
-
*
|
|
3397
|
-
*
|
|
3398
|
-
*
|
|
3411
|
+
* Run the Worker locally. The dev port comes ONLY from `opts.port` — the consumer passes it (e.g.
|
|
3412
|
+
* parsed from its own CLI flags in scripts/dev.ts); when omitted it defaults to wrangler's 8787.
|
|
3413
|
+
* There is no hidden argv/config port resolution. Prints a branded dev-session banner, then
|
|
3414
|
+
* delegates to deploy.dev; a `webBuild` hook (e.g. `() => webApp.cli.build()`) wires the web build
|
|
3415
|
+
* into the dev loop so the site recompiles on change. A failure renders a branded `✗` line +
|
|
3416
|
+
* non-zero exit, not a stack.
|
|
3399
3417
|
*
|
|
3400
3418
|
* @param opts - Optional local dev options.
|
|
3401
|
-
* @param opts.port - Local dev port to bind.
|
|
3419
|
+
* @param opts.port - Local dev port to bind. Defaults to 8787 when omitted.
|
|
3402
3420
|
* @param opts.stage - Stage for the generated wrangler config; falls back to `--stage` then the app stage.
|
|
3403
3421
|
* @param opts.webBuild - Rebuild the web site on change (e.g. `() => webApp.cli.build()`).
|
|
3404
3422
|
* @returns Resolves when the dev session ends.
|
|
3405
3423
|
* @example
|
|
3406
3424
|
* ```ts
|
|
3407
|
-
* await api.dev({ webBuild: () => web.cli.build() });
|
|
3425
|
+
* await api.dev({ port: 7878, webBuild: () => web.cli.build() });
|
|
3408
3426
|
* ```
|
|
3409
3427
|
*/
|
|
3410
3428
|
async dev(opts) {
|
|
@@ -3413,11 +3431,10 @@ const createCliApi = (ctx) => ({
|
|
|
3413
3431
|
wordmark: "moku worker",
|
|
3414
3432
|
label: "dev session"
|
|
3415
3433
|
});
|
|
3416
|
-
const port = opts?.port ?? parsePortArg(process.argv) ?? ctx.config.port;
|
|
3417
3434
|
const stage = opts?.stage ?? parseStageArg(process.argv);
|
|
3418
3435
|
try {
|
|
3419
3436
|
await ctx.require(deployPlugin).dev({
|
|
3420
|
-
port,
|
|
3437
|
+
...opts?.port === void 0 ? {} : { port: opts.port },
|
|
3421
3438
|
...stage === void 0 ? {} : { stage },
|
|
3422
3439
|
...opts?.webBuild ? { webBuild: opts.webBuild } : {}
|
|
3423
3440
|
});
|
|
@@ -3457,6 +3474,40 @@ const createCliApi = (ctx) => ({
|
|
|
3457
3474
|
}
|
|
3458
3475
|
},
|
|
3459
3476
|
/**
|
|
3477
|
+
* Seed a configured D1 database from a SQL file (delegates to deploy.seed). Local by default;
|
|
3478
|
+
* `opts.remote` seeds Cloudflare. The stage is resolved from a `--stage <name>` CLI flag (so
|
|
3479
|
+
* `bun run dev --seed --stage dev` seeds the dev database). A failure renders a branded `✗` line
|
|
3480
|
+
* and sets a non-zero exit code rather than throwing.
|
|
3481
|
+
*
|
|
3482
|
+
* @param sqlFile - Path to the SQL file to execute (e.g. "db/seed.sql").
|
|
3483
|
+
* @param opts - Optional options.
|
|
3484
|
+
* @param opts.binding - The d1 binding to target when more than one is configured (e.g. "DB").
|
|
3485
|
+
* @param opts.remote - Seed the remote (Cloudflare) D1 instead of the local one.
|
|
3486
|
+
* @returns Resolves once the seed completes (or after a failure is rendered).
|
|
3487
|
+
* @example
|
|
3488
|
+
* ```ts
|
|
3489
|
+
* await app.cli.seed("db/seed.sql"); // before app.cli.dev(...)
|
|
3490
|
+
* ```
|
|
3491
|
+
*/
|
|
3492
|
+
async seed(sqlFile, opts) {
|
|
3493
|
+
const ui = (0, _moku_labs_common_cli.createBrandConsole)();
|
|
3494
|
+
ui.lockup({
|
|
3495
|
+
wordmark: "moku worker",
|
|
3496
|
+
label: "seed"
|
|
3497
|
+
});
|
|
3498
|
+
const stage = parseStageArg(process.argv);
|
|
3499
|
+
try {
|
|
3500
|
+
await ctx.require(deployPlugin).seed(sqlFile, {
|
|
3501
|
+
...opts,
|
|
3502
|
+
...stage === void 0 ? {} : { stage }
|
|
3503
|
+
});
|
|
3504
|
+
ui.check(true, "seeded", sqlFile);
|
|
3505
|
+
} catch (error) {
|
|
3506
|
+
ui.error(error instanceof Error ? error.message : String(error));
|
|
3507
|
+
process.exitCode = 1;
|
|
3508
|
+
}
|
|
3509
|
+
},
|
|
3510
|
+
/**
|
|
3460
3511
|
* Verify the `.env` token (no sub) or print the config-derived token guidance (`"setup"`),
|
|
3461
3512
|
* rendered in Moku style. `setup` works without a token; verify reports the resolved account.
|
|
3462
3513
|
*
|
|
@@ -3651,7 +3702,7 @@ const createCliHooks = (ctx) => {
|
|
|
3651
3702
|
*/
|
|
3652
3703
|
const cliPlugin = createPlugin("cli", {
|
|
3653
3704
|
depends: [deployPlugin],
|
|
3654
|
-
config: {
|
|
3705
|
+
config: {},
|
|
3655
3706
|
onInit: (ctx) => {
|
|
3656
3707
|
ctx.log.clearSinks();
|
|
3657
3708
|
ctx.log.addSink((0, _moku_labs_common_cli.brandedSink)("info"));
|
|
@@ -738,7 +738,8 @@ const createQueuesApi = (ctx) => {
|
|
|
738
738
|
deployManifest: () => Object.values(ctx.config).map((instance) => ({
|
|
739
739
|
kind: "queue",
|
|
740
740
|
name: instance.name,
|
|
741
|
-
binding: instance.binding
|
|
741
|
+
binding: instance.binding,
|
|
742
|
+
...instance.onMessage ? { consumer: true } : {}
|
|
742
743
|
}))
|
|
743
744
|
};
|
|
744
745
|
};
|
|
@@ -2504,16 +2505,20 @@ const parseJsonc = (source) => {
|
|
|
2504
2505
|
*
|
|
2505
2506
|
* @param resources - All resource descriptors from the manifest.
|
|
2506
2507
|
* @param ids - Captured Cloudflare ids keyed by binding; the entry's `id` is filled from here.
|
|
2507
|
-
* @returns One wrangler KV namespace entry per kv resource
|
|
2508
|
+
* @returns One wrangler KV namespace entry per kv resource — real `id` when known, omitted otherwise
|
|
2509
|
+
* (wrangler rejects an empty `id`, but a local-dev / freshly-generated config validates without one).
|
|
2508
2510
|
* @example
|
|
2509
2511
|
* ```ts
|
|
2510
2512
|
* const kv = buildKvNamespaces([{ kind: "kv", binding: "CACHE" }], { CACHE: "ns123" });
|
|
2511
2513
|
* ```
|
|
2512
2514
|
*/
|
|
2513
|
-
const buildKvNamespaces = (resources, ids) => resources.filter((resource) => resource.kind === "kv").map((resource) =>
|
|
2514
|
-
|
|
2515
|
-
id
|
|
2516
|
-
|
|
2515
|
+
const buildKvNamespaces = (resources, ids) => resources.filter((resource) => resource.kind === "kv").map((resource) => {
|
|
2516
|
+
const id = ids[resource.binding];
|
|
2517
|
+
return id ? {
|
|
2518
|
+
binding: resource.binding,
|
|
2519
|
+
id
|
|
2520
|
+
} : { binding: resource.binding };
|
|
2521
|
+
});
|
|
2517
2522
|
/**
|
|
2518
2523
|
* Build the wrangler `r2_buckets` array from the manifest's r2 resources.
|
|
2519
2524
|
*
|
|
@@ -2540,31 +2545,41 @@ const buildR2Buckets = (resources) => resources.filter((resource) => resource.ki
|
|
|
2540
2545
|
* ```
|
|
2541
2546
|
*/
|
|
2542
2547
|
const buildD1Databases = (resources, ids) => resources.filter((resource) => resource.kind === "d1").map((resource) => {
|
|
2548
|
+
const databaseId = ids[resource.binding];
|
|
2543
2549
|
const entry = {
|
|
2544
2550
|
binding: resource.binding,
|
|
2545
|
-
database_name: resource.name
|
|
2546
|
-
database_id: ids[resource.binding] ?? ""
|
|
2551
|
+
database_name: resource.name
|
|
2547
2552
|
};
|
|
2553
|
+
if (databaseId) entry.database_id = databaseId;
|
|
2548
2554
|
if (resource.migrations) entry.migrations_dir = resource.migrations;
|
|
2549
2555
|
return entry;
|
|
2550
2556
|
});
|
|
2551
2557
|
/**
|
|
2552
|
-
* Build the wrangler `queues` producers
|
|
2558
|
+
* Build the wrangler `queues` section (producers + consumers) from the manifest's queue resources.
|
|
2559
|
+
* Every queue is a `producer`; a queue flagged `consumer: true` (it declares an `onMessage` handler)
|
|
2560
|
+
* is ALSO registered as a `consumer` so wrangler delivers its messages to this Worker's queue()
|
|
2561
|
+
* handler — both locally under `wrangler dev` and in production. Without the consumer entry the
|
|
2562
|
+
* handler never runs (the bug that silently drops a queue-driven activity feed).
|
|
2553
2563
|
*
|
|
2554
2564
|
* @param resources - All resource descriptors from the manifest.
|
|
2555
|
-
* @returns The queues section, or undefined when there are
|
|
2565
|
+
* @returns The queues section (producers, plus consumers when any), or undefined when there are none.
|
|
2556
2566
|
* @example
|
|
2557
2567
|
* ```ts
|
|
2558
|
-
* const q = buildQueues([{ kind: "queue", name: "tracker-activity", binding: "ACTIVITY" }]);
|
|
2568
|
+
* const q = buildQueues([{ kind: "queue", name: "tracker-activity", binding: "ACTIVITY", consumer: true }]);
|
|
2559
2569
|
* ```
|
|
2560
2570
|
*/
|
|
2561
2571
|
const buildQueues = (resources) => {
|
|
2562
2572
|
const queueResources = resources.filter((resource) => resource.kind === "queue");
|
|
2563
2573
|
if (queueResources.length === 0) return void 0;
|
|
2564
|
-
|
|
2574
|
+
const producers = queueResources.map((resource) => ({
|
|
2565
2575
|
queue: resource.name,
|
|
2566
2576
|
binding: resource.binding
|
|
2567
|
-
}))
|
|
2577
|
+
}));
|
|
2578
|
+
const consumers = queueResources.filter((resource) => resource.consumer === true).map((resource) => ({ queue: resource.name }));
|
|
2579
|
+
return consumers.length > 0 ? {
|
|
2580
|
+
producers,
|
|
2581
|
+
consumers
|
|
2582
|
+
} : { producers };
|
|
2568
2583
|
};
|
|
2569
2584
|
/**
|
|
2570
2585
|
* Build the wrangler `durable_objects` bindings section from the manifest's do resources.
|
|
@@ -2672,7 +2687,8 @@ const wranglerExtra = (config) => {
|
|
|
2672
2687
|
* @param configFile - Path to the wrangler config file.
|
|
2673
2688
|
* @param manifest - The assembled deploy manifest.
|
|
2674
2689
|
* @param ids - Captured Cloudflare ids keyed by binding (kv namespace id, d1 database id). Defaults
|
|
2675
|
-
* to an empty map, in which case `id`/`database_id` are
|
|
2690
|
+
* to an empty map, in which case `id`/`database_id` are OMITTED (not "") so the generated config
|
|
2691
|
+
* still validates for local `dev` (wrangler rejects an empty id); a deploy fills the real ids.
|
|
2676
2692
|
* @param extra - Extra top-level wrangler keys to merge in (the app's `deploy.wrangler` config).
|
|
2677
2693
|
* @returns Resolves once the file is written.
|
|
2678
2694
|
* @example
|
|
@@ -3135,6 +3151,50 @@ const createDeployApi = (ctx) => ({
|
|
|
3135
3151
|
await runDev(ctx, opts, realDevDeps());
|
|
3136
3152
|
},
|
|
3137
3153
|
/**
|
|
3154
|
+
* Execute a SQL file against a configured D1 database via `wrangler d1 execute` — for seeding dev
|
|
3155
|
+
* data. Local by default (applies that database's migrations first so the file's tables exist);
|
|
3156
|
+
* `opts.remote` seeds Cloudflare (schema is applied by `deploy`). Generates the wrangler config up
|
|
3157
|
+
* front so the binding resolves even on a first run. Streams wrangler's output.
|
|
3158
|
+
*
|
|
3159
|
+
* @param sqlFile - Path to the SQL file to execute (e.g. "db/seed.sql").
|
|
3160
|
+
* @param opts - Optional options.
|
|
3161
|
+
* @param opts.stage - Stage for the generated config's resource names (defaults to the app stage).
|
|
3162
|
+
* @param opts.binding - The d1 binding to target when more than one is configured (e.g. "DB").
|
|
3163
|
+
* @param opts.remote - Seed the remote (Cloudflare) D1 instead of the local one.
|
|
3164
|
+
* @returns Resolves once wrangler finishes executing the file.
|
|
3165
|
+
* @example
|
|
3166
|
+
* ```ts
|
|
3167
|
+
* await api.seed("db/seed.sql"); // local default d1 (migrate, then execute)
|
|
3168
|
+
* await api.seed("db/seed.sql", { remote: true }); // remote d1
|
|
3169
|
+
* ```
|
|
3170
|
+
*/
|
|
3171
|
+
async seed(sqlFile, opts) {
|
|
3172
|
+
if (!ctx.has("d1")) throw new Error("[moku-worker] seed: no d1 database is configured.");
|
|
3173
|
+
const stage = opts?.stage ?? ctx.global.stage;
|
|
3174
|
+
await writeWranglerConfig(ctx.config.configFile, assembleManifest(ctx, stage), {}, wranglerExtra(ctx.config));
|
|
3175
|
+
const databases = ctx.require(d1Plugin).deployManifest();
|
|
3176
|
+
const wanted = opts?.binding;
|
|
3177
|
+
const matched = wanted === void 0 ? databases : databases.filter((database) => database.binding === wanted);
|
|
3178
|
+
const target = matched.length === 1 ? matched[0] : void 0;
|
|
3179
|
+
if (target === void 0) throw new Error(wanted === void 0 ? `[moku-worker] seed: ${String(databases.length)} d1 databases configured — pass { binding } to choose one.` : `[moku-worker] seed: no d1 database is bound to "${wanted}".`);
|
|
3180
|
+
const scope = opts?.remote === true ? "--remote" : "--local";
|
|
3181
|
+
if (scope === "--local" && target.migrations !== void 0) await runWranglerInherit([
|
|
3182
|
+
"d1",
|
|
3183
|
+
"migrations",
|
|
3184
|
+
"apply",
|
|
3185
|
+
target.binding,
|
|
3186
|
+
"--local"
|
|
3187
|
+
]);
|
|
3188
|
+
await runWranglerInherit([
|
|
3189
|
+
"d1",
|
|
3190
|
+
"execute",
|
|
3191
|
+
target.binding,
|
|
3192
|
+
scope,
|
|
3193
|
+
"--file",
|
|
3194
|
+
sqlFile
|
|
3195
|
+
]);
|
|
3196
|
+
},
|
|
3197
|
+
/**
|
|
3138
3198
|
* Scaffold a starting wrangler config (and CI files when ci is set).
|
|
3139
3199
|
* Idempotent: an existing config file is left untouched.
|
|
3140
3200
|
*
|
|
@@ -3261,54 +3321,10 @@ const deployPlugin = createPlugin("deploy", {
|
|
|
3261
3321
|
/**
|
|
3262
3322
|
* @file cli plugin — argv parsing helpers (isolated so they unit-test without a real process).
|
|
3263
3323
|
*
|
|
3264
|
-
* `dev`
|
|
3265
|
-
*
|
|
3324
|
+
* `deploy`/`dev` resolve the target stage from the command line (`--stage dev`) so a consumer never
|
|
3325
|
+
* hardcodes it. The dev PORT is not parsed here — it comes only from the `dev()` argument (no hidden
|
|
3326
|
+
* argv/config resolution). Pure: takes an argv array, reads no globals. Node-only tooling.
|
|
3266
3327
|
*/
|
|
3267
|
-
/** The valid TCP port range a `--port` value must fall within to be accepted. */
|
|
3268
|
-
const MAX_PORT = 65535;
|
|
3269
|
-
/**
|
|
3270
|
-
* Extract a `--port`/`-p` value from a single token (and the token after it, for the spaced form).
|
|
3271
|
-
*
|
|
3272
|
-
* @param token - The current argv token.
|
|
3273
|
-
* @param next - The following argv token (the value, for the `--port 3000` spaced form).
|
|
3274
|
-
* @returns The raw string value when this token is a port flag, else undefined.
|
|
3275
|
-
* @example
|
|
3276
|
-
* ```ts
|
|
3277
|
-
* portValueFrom("--port=3000", undefined); // "3000"
|
|
3278
|
-
* portValueFrom("--port", "3000"); // "3000"
|
|
3279
|
-
* portValueFrom("--config", "x"); // undefined
|
|
3280
|
-
* ```
|
|
3281
|
-
*/
|
|
3282
|
-
const portValueFrom = (token, next) => {
|
|
3283
|
-
const inline = /^(?:--port|-p)=(.+)$/u.exec(token);
|
|
3284
|
-
if (inline) return inline[1];
|
|
3285
|
-
if (token === "--port" || token === "-p") return next;
|
|
3286
|
-
};
|
|
3287
|
-
/**
|
|
3288
|
-
* Parse a `--port <n>` / `--port=<n>` / `-p <n>` flag out of an argv array.
|
|
3289
|
-
*
|
|
3290
|
-
* Returns the first valid port (a positive integer ≤ 65535) found, or undefined when the flag is
|
|
3291
|
-
* absent or its value is not a usable port — letting the caller fall back to a default.
|
|
3292
|
-
*
|
|
3293
|
-
* @param argv - The argv array to scan (the caller passes the process argv).
|
|
3294
|
-
* @returns The parsed port number, or undefined when no valid `--port`/`-p` flag is present.
|
|
3295
|
-
* @example
|
|
3296
|
-
* ```ts
|
|
3297
|
-
* parsePortArg(["bun", "scripts/dev.ts", "--port", "3000"]); // 3000
|
|
3298
|
-
* parsePortArg(["bun", "scripts/dev.ts", "--port=3000"]); // 3000
|
|
3299
|
-
* parsePortArg(["bun", "scripts/dev.ts"]); // undefined
|
|
3300
|
-
* ```
|
|
3301
|
-
*/
|
|
3302
|
-
const parsePortArg = (argv) => {
|
|
3303
|
-
for (let index = 0; index < argv.length; index++) {
|
|
3304
|
-
const token = argv[index];
|
|
3305
|
-
if (token === void 0) continue;
|
|
3306
|
-
const raw = portValueFrom(token, argv[index + 1]);
|
|
3307
|
-
if (raw === void 0) continue;
|
|
3308
|
-
const port = Number(raw);
|
|
3309
|
-
if (Number.isInteger(port) && port > 0 && port <= MAX_PORT) return port;
|
|
3310
|
-
}
|
|
3311
|
-
};
|
|
3312
3328
|
/**
|
|
3313
3329
|
* Extract a `--stage` value from a single token (and the token after it, for the spaced form).
|
|
3314
3330
|
*
|
|
@@ -3319,7 +3335,7 @@ const parsePortArg = (argv) => {
|
|
|
3319
3335
|
* ```ts
|
|
3320
3336
|
* stageValueFrom("--stage=dev", undefined); // "dev"
|
|
3321
3337
|
* stageValueFrom("--stage", "dev"); // "dev"
|
|
3322
|
-
* stageValueFrom("--
|
|
3338
|
+
* stageValueFrom("--other", "x"); // undefined
|
|
3323
3339
|
* ```
|
|
3324
3340
|
*/
|
|
3325
3341
|
const stageValueFrom = (token, next) => {
|
|
@@ -3369,19 +3385,21 @@ const parseStageArg = (argv) => {
|
|
|
3369
3385
|
*/
|
|
3370
3386
|
const createCliApi = (ctx) => ({
|
|
3371
3387
|
/**
|
|
3372
|
-
* Run the Worker locally.
|
|
3373
|
-
*
|
|
3374
|
-
*
|
|
3375
|
-
*
|
|
3388
|
+
* Run the Worker locally. The dev port comes ONLY from `opts.port` — the consumer passes it (e.g.
|
|
3389
|
+
* parsed from its own CLI flags in scripts/dev.ts); when omitted it defaults to wrangler's 8787.
|
|
3390
|
+
* There is no hidden argv/config port resolution. Prints a branded dev-session banner, then
|
|
3391
|
+
* delegates to deploy.dev; a `webBuild` hook (e.g. `() => webApp.cli.build()`) wires the web build
|
|
3392
|
+
* into the dev loop so the site recompiles on change. A failure renders a branded `✗` line +
|
|
3393
|
+
* non-zero exit, not a stack.
|
|
3376
3394
|
*
|
|
3377
3395
|
* @param opts - Optional local dev options.
|
|
3378
|
-
* @param opts.port - Local dev port to bind.
|
|
3396
|
+
* @param opts.port - Local dev port to bind. Defaults to 8787 when omitted.
|
|
3379
3397
|
* @param opts.stage - Stage for the generated wrangler config; falls back to `--stage` then the app stage.
|
|
3380
3398
|
* @param opts.webBuild - Rebuild the web site on change (e.g. `() => webApp.cli.build()`).
|
|
3381
3399
|
* @returns Resolves when the dev session ends.
|
|
3382
3400
|
* @example
|
|
3383
3401
|
* ```ts
|
|
3384
|
-
* await api.dev({ webBuild: () => web.cli.build() });
|
|
3402
|
+
* await api.dev({ port: 7878, webBuild: () => web.cli.build() });
|
|
3385
3403
|
* ```
|
|
3386
3404
|
*/
|
|
3387
3405
|
async dev(opts) {
|
|
@@ -3390,11 +3408,10 @@ const createCliApi = (ctx) => ({
|
|
|
3390
3408
|
wordmark: "moku worker",
|
|
3391
3409
|
label: "dev session"
|
|
3392
3410
|
});
|
|
3393
|
-
const port = opts?.port ?? parsePortArg(process.argv) ?? ctx.config.port;
|
|
3394
3411
|
const stage = opts?.stage ?? parseStageArg(process.argv);
|
|
3395
3412
|
try {
|
|
3396
3413
|
await ctx.require(deployPlugin).dev({
|
|
3397
|
-
port,
|
|
3414
|
+
...opts?.port === void 0 ? {} : { port: opts.port },
|
|
3398
3415
|
...stage === void 0 ? {} : { stage },
|
|
3399
3416
|
...opts?.webBuild ? { webBuild: opts.webBuild } : {}
|
|
3400
3417
|
});
|
|
@@ -3434,6 +3451,40 @@ const createCliApi = (ctx) => ({
|
|
|
3434
3451
|
}
|
|
3435
3452
|
},
|
|
3436
3453
|
/**
|
|
3454
|
+
* Seed a configured D1 database from a SQL file (delegates to deploy.seed). Local by default;
|
|
3455
|
+
* `opts.remote` seeds Cloudflare. The stage is resolved from a `--stage <name>` CLI flag (so
|
|
3456
|
+
* `bun run dev --seed --stage dev` seeds the dev database). A failure renders a branded `✗` line
|
|
3457
|
+
* and sets a non-zero exit code rather than throwing.
|
|
3458
|
+
*
|
|
3459
|
+
* @param sqlFile - Path to the SQL file to execute (e.g. "db/seed.sql").
|
|
3460
|
+
* @param opts - Optional options.
|
|
3461
|
+
* @param opts.binding - The d1 binding to target when more than one is configured (e.g. "DB").
|
|
3462
|
+
* @param opts.remote - Seed the remote (Cloudflare) D1 instead of the local one.
|
|
3463
|
+
* @returns Resolves once the seed completes (or after a failure is rendered).
|
|
3464
|
+
* @example
|
|
3465
|
+
* ```ts
|
|
3466
|
+
* await app.cli.seed("db/seed.sql"); // before app.cli.dev(...)
|
|
3467
|
+
* ```
|
|
3468
|
+
*/
|
|
3469
|
+
async seed(sqlFile, opts) {
|
|
3470
|
+
const ui = createBrandConsole();
|
|
3471
|
+
ui.lockup({
|
|
3472
|
+
wordmark: "moku worker",
|
|
3473
|
+
label: "seed"
|
|
3474
|
+
});
|
|
3475
|
+
const stage = parseStageArg(process.argv);
|
|
3476
|
+
try {
|
|
3477
|
+
await ctx.require(deployPlugin).seed(sqlFile, {
|
|
3478
|
+
...opts,
|
|
3479
|
+
...stage === void 0 ? {} : { stage }
|
|
3480
|
+
});
|
|
3481
|
+
ui.check(true, "seeded", sqlFile);
|
|
3482
|
+
} catch (error) {
|
|
3483
|
+
ui.error(error instanceof Error ? error.message : String(error));
|
|
3484
|
+
process.exitCode = 1;
|
|
3485
|
+
}
|
|
3486
|
+
},
|
|
3487
|
+
/**
|
|
3437
3488
|
* Verify the `.env` token (no sub) or print the config-derived token guidance (`"setup"`),
|
|
3438
3489
|
* rendered in Moku style. `setup` works without a token; verify reports the resolved account.
|
|
3439
3490
|
*
|
|
@@ -3628,7 +3679,7 @@ const createCliHooks = (ctx) => {
|
|
|
3628
3679
|
*/
|
|
3629
3680
|
const cliPlugin = createPlugin("cli", {
|
|
3630
3681
|
depends: [deployPlugin],
|
|
3631
|
-
config: {
|
|
3682
|
+
config: {},
|
|
3632
3683
|
onInit: (ctx) => {
|
|
3633
3684
|
ctx.log.clearSinks();
|
|
3634
3685
|
ctx.log.addSink(brandedSink("info"));
|
package/dist/cli.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_cli = require("./cli-
|
|
2
|
+
const require_cli = require("./cli-BBO_YNVC.cjs");
|
|
3
3
|
exports.cliPlugin = require_cli.cliPlugin;
|
|
4
4
|
exports.deployPlugin = require_cli.deployPlugin;
|
package/dist/cli.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as ResourceManifest, n as cliPlugin, r as ExternalManifest, t as deployPlugin } from "./index-
|
|
1
|
+
import { i as ResourceManifest, n as cliPlugin, r as ExternalManifest, t as deployPlugin } from "./index-Dse6wZJH.cjs";
|
|
2
2
|
export { type ExternalManifest, type ResourceManifest, cliPlugin, deployPlugin };
|
package/dist/cli.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as ResourceManifest, n as cliPlugin, r as ExternalManifest, t as deployPlugin } from "./index-
|
|
1
|
+
import { i as ResourceManifest, n as cliPlugin, r as ExternalManifest, t as deployPlugin } from "./index-Dse6wZJH.mjs";
|
|
2
2
|
export { type ExternalManifest, type ResourceManifest, cliPlugin, deployPlugin };
|
package/dist/cli.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as deployPlugin, t as cliPlugin } from "./cli-
|
|
1
|
+
import { n as deployPlugin, t as cliPlugin } from "./cli-D67ea3Lu.mjs";
|
|
2
2
|
export { cliPlugin, deployPlugin };
|
|
@@ -178,6 +178,7 @@ type ResourceManifest = {
|
|
|
178
178
|
kind: "queue";
|
|
179
179
|
name: string;
|
|
180
180
|
binding: string;
|
|
181
|
+
consumer?: boolean;
|
|
181
182
|
} | {
|
|
182
183
|
kind: "do";
|
|
183
184
|
binding: string;
|
|
@@ -252,30 +253,27 @@ type TokenRequirement = {
|
|
|
252
253
|
};
|
|
253
254
|
//#endregion
|
|
254
255
|
//#region src/plugins/cli/types.d.ts
|
|
255
|
-
/**
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
* @default 8787
|
|
262
|
-
*/
|
|
263
|
-
readonly port: number;
|
|
264
|
-
};
|
|
256
|
+
/**
|
|
257
|
+
* Resolved configuration for the cli plugin. The cli surface is configuration-free: the dev port is
|
|
258
|
+
* NOT set here (it comes only from `dev({ port })`), so there are no keys to set under
|
|
259
|
+
* `pluginConfigs.cli`.
|
|
260
|
+
*/
|
|
261
|
+
type Config = Record<string, never>;
|
|
265
262
|
/** Public api surface of the cli plugin, mounted at app.cli.*. */
|
|
266
263
|
type Api = {
|
|
267
264
|
/**
|
|
268
|
-
* Run the Worker locally via Wrangler (delegates to deploy.dev).
|
|
269
|
-
* `opts.port
|
|
270
|
-
* a branded `✗` line and sets a non-zero exit code rather than
|
|
265
|
+
* Run the Worker locally via Wrangler (delegates to deploy.dev). The dev port comes only from
|
|
266
|
+
* `opts.port` — the consumer passes it (e.g. parsed from its own CLI flags); it defaults to 8787
|
|
267
|
+
* when omitted. A failure renders a branded `✗` line and sets a non-zero exit code rather than
|
|
268
|
+
* throwing a raw stack trace.
|
|
271
269
|
*
|
|
272
|
-
* @param opts - Optional port
|
|
273
|
-
* @param opts.port - Local dev port to bind
|
|
270
|
+
* @param opts - Optional port and web build hook.
|
|
271
|
+
* @param opts.port - Local dev port to bind. Defaults to 8787 when omitted.
|
|
274
272
|
* @param opts.webBuild - Rebuild the web site on change (e.g. `() => webApp.cli.build()`).
|
|
275
273
|
* @returns Resolves when the dev session ends.
|
|
276
274
|
* @example
|
|
277
275
|
* ```ts
|
|
278
|
-
* await app.cli.dev({ webBuild: () => web.cli.build() });
|
|
276
|
+
* await app.cli.dev({ port: 7878, webBuild: () => web.cli.build() });
|
|
279
277
|
* ```
|
|
280
278
|
*/
|
|
281
279
|
dev(opts?: {
|
|
@@ -301,6 +299,26 @@ type Api = {
|
|
|
301
299
|
ci?: boolean;
|
|
302
300
|
webBuild?: WebBuild;
|
|
303
301
|
}): Promise<void>;
|
|
302
|
+
/**
|
|
303
|
+
* Seed a configured D1 database from a SQL file (delegates to deploy.seed). Local by default
|
|
304
|
+
* (applies the database's migrations first so its tables exist, then executes the file);
|
|
305
|
+
* `opts.remote` seeds Cloudflare. A failure renders a branded `✗` line and sets a non-zero exit
|
|
306
|
+
* code rather than throwing.
|
|
307
|
+
*
|
|
308
|
+
* @param sqlFile - Path to the SQL file to execute (e.g. "db/seed.sql").
|
|
309
|
+
* @param opts - Optional options.
|
|
310
|
+
* @param opts.binding - The d1 binding to target when more than one is configured (e.g. "DB").
|
|
311
|
+
* @param opts.remote - Seed the remote (Cloudflare) D1 instead of the local one.
|
|
312
|
+
* @returns Resolves once the seed completes (or after a failure is rendered).
|
|
313
|
+
* @example
|
|
314
|
+
* ```ts
|
|
315
|
+
* await app.cli.seed("db/seed.sql"); // local; --stage honored
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
seed(sqlFile: string, opts?: {
|
|
319
|
+
binding?: string;
|
|
320
|
+
remote?: boolean;
|
|
321
|
+
}): Promise<void>;
|
|
304
322
|
/**
|
|
305
323
|
* Verify the `.env` Cloudflare token (no sub), or print the config-derived token-creation
|
|
306
324
|
* guidance (`"setup"`). Delegates to deploy.verifyAuth() / deploy.tokenInstructions().
|
|
@@ -389,6 +407,11 @@ declare const deployPlugin: import("@moku-labs/core").PluginInstance<"deploy", C
|
|
|
389
407
|
stage?: string;
|
|
390
408
|
webBuild?: WebBuild;
|
|
391
409
|
}): Promise<void>;
|
|
410
|
+
seed(sqlFile: string, opts?: {
|
|
411
|
+
stage?: string;
|
|
412
|
+
binding?: string;
|
|
413
|
+
remote?: boolean;
|
|
414
|
+
}): Promise<void>;
|
|
392
415
|
init: (opts?: {
|
|
393
416
|
ci?: boolean;
|
|
394
417
|
}) => Promise<void>;
|
|
@@ -178,6 +178,7 @@ type ResourceManifest = {
|
|
|
178
178
|
kind: "queue";
|
|
179
179
|
name: string;
|
|
180
180
|
binding: string;
|
|
181
|
+
consumer?: boolean;
|
|
181
182
|
} | {
|
|
182
183
|
kind: "do";
|
|
183
184
|
binding: string;
|
|
@@ -252,30 +253,27 @@ type TokenRequirement = {
|
|
|
252
253
|
};
|
|
253
254
|
//#endregion
|
|
254
255
|
//#region src/plugins/cli/types.d.ts
|
|
255
|
-
/**
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
* @default 8787
|
|
262
|
-
*/
|
|
263
|
-
readonly port: number;
|
|
264
|
-
};
|
|
256
|
+
/**
|
|
257
|
+
* Resolved configuration for the cli plugin. The cli surface is configuration-free: the dev port is
|
|
258
|
+
* NOT set here (it comes only from `dev({ port })`), so there are no keys to set under
|
|
259
|
+
* `pluginConfigs.cli`.
|
|
260
|
+
*/
|
|
261
|
+
type Config = Record<string, never>;
|
|
265
262
|
/** Public api surface of the cli plugin, mounted at app.cli.*. */
|
|
266
263
|
type Api = {
|
|
267
264
|
/**
|
|
268
|
-
* Run the Worker locally via Wrangler (delegates to deploy.dev).
|
|
269
|
-
* `opts.port
|
|
270
|
-
* a branded `✗` line and sets a non-zero exit code rather than
|
|
265
|
+
* Run the Worker locally via Wrangler (delegates to deploy.dev). The dev port comes only from
|
|
266
|
+
* `opts.port` — the consumer passes it (e.g. parsed from its own CLI flags); it defaults to 8787
|
|
267
|
+
* when omitted. A failure renders a branded `✗` line and sets a non-zero exit code rather than
|
|
268
|
+
* throwing a raw stack trace.
|
|
271
269
|
*
|
|
272
|
-
* @param opts - Optional port
|
|
273
|
-
* @param opts.port - Local dev port to bind
|
|
270
|
+
* @param opts - Optional port and web build hook.
|
|
271
|
+
* @param opts.port - Local dev port to bind. Defaults to 8787 when omitted.
|
|
274
272
|
* @param opts.webBuild - Rebuild the web site on change (e.g. `() => webApp.cli.build()`).
|
|
275
273
|
* @returns Resolves when the dev session ends.
|
|
276
274
|
* @example
|
|
277
275
|
* ```ts
|
|
278
|
-
* await app.cli.dev({ webBuild: () => web.cli.build() });
|
|
276
|
+
* await app.cli.dev({ port: 7878, webBuild: () => web.cli.build() });
|
|
279
277
|
* ```
|
|
280
278
|
*/
|
|
281
279
|
dev(opts?: {
|
|
@@ -301,6 +299,26 @@ type Api = {
|
|
|
301
299
|
ci?: boolean;
|
|
302
300
|
webBuild?: WebBuild;
|
|
303
301
|
}): Promise<void>;
|
|
302
|
+
/**
|
|
303
|
+
* Seed a configured D1 database from a SQL file (delegates to deploy.seed). Local by default
|
|
304
|
+
* (applies the database's migrations first so its tables exist, then executes the file);
|
|
305
|
+
* `opts.remote` seeds Cloudflare. A failure renders a branded `✗` line and sets a non-zero exit
|
|
306
|
+
* code rather than throwing.
|
|
307
|
+
*
|
|
308
|
+
* @param sqlFile - Path to the SQL file to execute (e.g. "db/seed.sql").
|
|
309
|
+
* @param opts - Optional options.
|
|
310
|
+
* @param opts.binding - The d1 binding to target when more than one is configured (e.g. "DB").
|
|
311
|
+
* @param opts.remote - Seed the remote (Cloudflare) D1 instead of the local one.
|
|
312
|
+
* @returns Resolves once the seed completes (or after a failure is rendered).
|
|
313
|
+
* @example
|
|
314
|
+
* ```ts
|
|
315
|
+
* await app.cli.seed("db/seed.sql"); // local; --stage honored
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
seed(sqlFile: string, opts?: {
|
|
319
|
+
binding?: string;
|
|
320
|
+
remote?: boolean;
|
|
321
|
+
}): Promise<void>;
|
|
304
322
|
/**
|
|
305
323
|
* Verify the `.env` Cloudflare token (no sub), or print the config-derived token-creation
|
|
306
324
|
* guidance (`"setup"`). Delegates to deploy.verifyAuth() / deploy.tokenInstructions().
|
|
@@ -389,6 +407,11 @@ declare const deployPlugin: import("@moku-labs/core").PluginInstance<"deploy", C
|
|
|
389
407
|
stage?: string;
|
|
390
408
|
webBuild?: WebBuild;
|
|
391
409
|
}): Promise<void>;
|
|
410
|
+
seed(sqlFile: string, opts?: {
|
|
411
|
+
stage?: string;
|
|
412
|
+
binding?: string;
|
|
413
|
+
remote?: boolean;
|
|
414
|
+
}): Promise<void>;
|
|
392
415
|
init: (opts?: {
|
|
393
416
|
ci?: boolean;
|
|
394
417
|
}) => Promise<void>;
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_cli = require("./cli-
|
|
2
|
+
const require_cli = require("./cli-BBO_YNVC.cjs");
|
|
3
3
|
let _moku_labs_common = require("@moku-labs/common");
|
|
4
4
|
//#region src/env-provider.ts
|
|
5
5
|
/**
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as WorkerConfig, c as WorkerPluginCtx, i as ResourceManifest, n as cliPlugin, o as WorkerEnv, r as ExternalManifest, s as WorkerEvents, t as deployPlugin } from "./index-
|
|
1
|
+
import { a as WorkerConfig, c as WorkerPluginCtx, i as ResourceManifest, n as cliPlugin, o as WorkerEnv, r as ExternalManifest, s as WorkerEvents, t as deployPlugin } from "./index-Dse6wZJH.cjs";
|
|
2
2
|
import { envPlugin, logPlugin } from "@moku-labs/common";
|
|
3
3
|
import { PluginCtx, PluginCtx as PluginCtx$1, PluginInstance } from "@moku-labs/core";
|
|
4
4
|
|
|
@@ -852,12 +852,15 @@ type Api = QueueProducerApi & {
|
|
|
852
852
|
* Return this plugin's deploy metadata (one entry per configured instance), read by the deploy
|
|
853
853
|
* plugin. Build-time only — takes no env.
|
|
854
854
|
*
|
|
855
|
-
* @returns One queue deploy descriptor per configured instance.
|
|
855
|
+
* @returns One queue deploy descriptor per configured instance. `consumer: true` marks an instance
|
|
856
|
+
* that declares an `onMessage` handler — the deploy plugin registers those as wrangler
|
|
857
|
+
* `consumers` so this Worker actually receives the queue's messages.
|
|
856
858
|
*/
|
|
857
859
|
deployManifest(): Array<{
|
|
858
860
|
kind: "queue";
|
|
859
861
|
name: string;
|
|
860
862
|
binding: string;
|
|
863
|
+
consumer?: boolean;
|
|
861
864
|
}>;
|
|
862
865
|
};
|
|
863
866
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as WorkerConfig, c as WorkerPluginCtx, i as ResourceManifest, n as cliPlugin, o as WorkerEnv, r as ExternalManifest, s as WorkerEvents, t as deployPlugin } from "./index-
|
|
1
|
+
import { a as WorkerConfig, c as WorkerPluginCtx, i as ResourceManifest, n as cliPlugin, o as WorkerEnv, r as ExternalManifest, s as WorkerEvents, t as deployPlugin } from "./index-Dse6wZJH.mjs";
|
|
2
2
|
import { envPlugin, logPlugin } from "@moku-labs/common";
|
|
3
3
|
import { PluginCtx, PluginCtx as PluginCtx$1, PluginInstance } from "@moku-labs/core";
|
|
4
4
|
|
|
@@ -852,12 +852,15 @@ type Api = QueueProducerApi & {
|
|
|
852
852
|
* Return this plugin's deploy metadata (one entry per configured instance), read by the deploy
|
|
853
853
|
* plugin. Build-time only — takes no env.
|
|
854
854
|
*
|
|
855
|
-
* @returns One queue deploy descriptor per configured instance.
|
|
855
|
+
* @returns One queue deploy descriptor per configured instance. `consumer: true` marks an instance
|
|
856
|
+
* that declares an `onMessage` handler — the deploy plugin registers those as wrangler
|
|
857
|
+
* `consumers` so this Worker actually receives the queue's messages.
|
|
856
858
|
*/
|
|
857
859
|
deployManifest(): Array<{
|
|
858
860
|
kind: "queue";
|
|
859
861
|
name: string;
|
|
860
862
|
binding: string;
|
|
863
|
+
consumer?: boolean;
|
|
861
864
|
}>;
|
|
862
865
|
};
|
|
863
866
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as kvPlugin, c as d1Plugin, d as createCore, f as createPlugin$1, i as queuesPlugin, l as bindingsPlugin, n as deployPlugin, o as durableObjectsPlugin, p as stagePlugin, r as storagePlugin, s as defineDurableObject, t as cliPlugin, u as coreConfig } from "./cli-
|
|
1
|
+
import { a as kvPlugin, c as d1Plugin, d as createCore, f as createPlugin$1, i as queuesPlugin, l as bindingsPlugin, n as deployPlugin, o as durableObjectsPlugin, p as stagePlugin, r as storagePlugin, s as defineDurableObject, t as cliPlugin, u as coreConfig } from "./cli-D67ea3Lu.mjs";
|
|
2
2
|
import { envPlugin, logPlugin } from "@moku-labs/common";
|
|
3
3
|
//#region src/env-provider.ts
|
|
4
4
|
/**
|
package/package.json
CHANGED