@moku-labs/worker 0.6.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.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_cli = require("./cli-Dc0q0hIy.cjs");
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-VZ99IAMv.cjs";
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-VZ99IAMv.mjs";
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-DgZv5A0G.mjs";
1
+ import { n as deployPlugin, t as cliPlugin } from "./cli-D67ea3Lu.mjs";
2
2
  export { cliPlugin, deployPlugin };
@@ -109,6 +109,32 @@ type Config$1 = {
109
109
  * Also the file parsed in the universal/non-moku path.
110
110
  */
111
111
  configFile: string;
112
+ /**
113
+ * The Worker entry module → wrangler `main` (e.g. "src/cloudflare/worker.ts"). Required for any
114
+ * real Worker deploy (its absence is wrangler's "Missing entry-point" error).
115
+ */
116
+ entry?: string;
117
+ /**
118
+ * Enable Node.js compat → `compatibility_flags: ["nodejs_compat"]`. Needed when the Worker bundle
119
+ * pulls in Node-flavored code (e.g. composing the deploy/cli tooling into the runtime app).
120
+ */
121
+ nodeCompat?: boolean;
122
+ /**
123
+ * Static assets served via `env.<binding>` → the wrangler `assets` block. `spa: true` sets
124
+ * `not_found_handling: "single-page-application"` so client-routed deep links resolve to index.html.
125
+ */
126
+ assets?: {
127
+ binding: string;
128
+ directory: string;
129
+ spa?: boolean;
130
+ };
131
+ /**
132
+ * Escape hatch — extra top-level wrangler keys merged into the generated config for anything the
133
+ * typed fields above don't cover (`vars`, `routes`, `observability`, `triggers`, …). The
134
+ * deploy-managed resource keys (name, compatibility_date, kv_namespaces, r2_buckets, d1_databases,
135
+ * queues, durable_objects, and the auto-derived Durable Object `migrations`) always win over these.
136
+ */
137
+ wrangler?: Record<string, unknown>;
112
138
  /**
113
139
  * Standing CI/automated default for `run()`. When true (or when stdout is non-TTY) the deploy
114
140
  * never prompts and auto-confirms every gate; `run({ ci })` overrides it per call. CF credentials
@@ -127,24 +153,36 @@ type Config$1 = {
127
153
  migrateLocal: boolean; /** Debounce window (ms) coalescing rapid file changes into one rebuild. */
128
154
  debounceMs: number;
129
155
  };
130
- /** Discriminated union of resource descriptors returned by each plugin's deployManifest(). */
156
+ /**
157
+ * Discriminated union of per-INSTANCE resource descriptors. Each resource plugin's `deployManifest()`
158
+ * returns an ARRAY of these (one per configured instance). `name` is the base Cloudflare resource
159
+ * name (stage-suffixed downstream via {@link stageName}); `binding` is the stable env var. Durable
160
+ * Objects carry no provisioned `name` — they ship with the Worker script — and declare the exported
161
+ * `className` instead.
162
+ */
131
163
  type ResourceManifest = {
132
164
  kind: "r2";
133
- bucket: string;
165
+ name: string;
166
+ binding: string;
134
167
  upload?: string;
135
168
  } | {
136
169
  kind: "kv";
170
+ name: string;
137
171
  binding: string;
138
172
  } | {
139
173
  kind: "d1";
174
+ name: string;
140
175
  binding: string;
141
176
  migrations?: string;
142
177
  } | {
143
178
  kind: "queue";
144
- producers: string[];
179
+ name: string;
180
+ binding: string;
181
+ consumer?: boolean;
145
182
  } | {
146
183
  kind: "do";
147
- bindings: Record<string, string>;
184
+ binding: string;
185
+ className: string;
148
186
  };
149
187
  /**
150
188
  * The whole deploy manifest the pipeline consumes (assembled, or caller-supplied for the
@@ -174,12 +212,23 @@ type InfraPlan = {
174
212
  missing: ResourceManifest[];
175
213
  };
176
214
  /**
177
- * Outcome of acting on an {@link InfraPlan}: the resources just created, those skipped because
178
- * they already existed, and the merged id map (binding Cloudflare id) for the config writer.
215
+ * A resource that failed to provision, with the (branded) error message captured so the guided flow
216
+ * can show WHICH resource failed and why instead of aborting the whole run on the first failure.
217
+ */
218
+ type ProvisionFailure = {
219
+ /** The resource descriptor that failed to create. */resource: ResourceManifest; /** The captured error message (e.g. the branded wrangler failure). */
220
+ error: string;
221
+ };
222
+ /**
223
+ * Outcome of acting on an {@link InfraPlan}: the resources just created, those skipped because they
224
+ * already existed, those that FAILED to create, and the merged id map (binding → Cloudflare id) for
225
+ * the config writer. Provisioning is resilient — a single resource failure is captured here, not
226
+ * thrown, so the guided flow can report a clear per-resource result.
179
227
  */
180
228
  type ProvisionResult = {
181
229
  /** Resources created during this run. */created: ProvisionedRef[]; /** Resources skipped because they already existed. */
182
- skipped: ProvisionedRef[]; /** Merged binding Cloudflare id map (existing + created) for writeWranglerConfig. */
230
+ skipped: ProvisionedRef[]; /** Resources that failed to create (captured, not thrown). */
231
+ failed: ProvisionFailure[]; /** Merged binding → Cloudflare id map (existing + created) for writeWranglerConfig. */
183
232
  ids: Record<string, string>;
184
233
  };
185
234
  /** Result of verifying the `.env` Cloudflare API token and resolving its account. */
@@ -204,30 +253,27 @@ type TokenRequirement = {
204
253
  };
205
254
  //#endregion
206
255
  //#region src/plugins/cli/types.d.ts
207
- /** Resolved configuration for the cli plugin. Flat; complete defaults so omission never yields undefined. */
208
- type Config = {
209
- /**
210
- * Default local dev port forwarded to deploy.dev when dev() gets no port.
211
- * Passed through to `wrangler dev --port <n>`.
212
- *
213
- * @default 8787
214
- */
215
- readonly port: number;
216
- };
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>;
217
262
  /** Public api surface of the cli plugin, mounted at app.cli.*. */
218
263
  type Api = {
219
264
  /**
220
- * Run the Worker locally via Wrangler (delegates to deploy.dev). Resolves the port from
221
- * `opts.port`, else a `--port <n>` CLI flag, else the configured default (8787). A failure renders
222
- * a branded `✗` line and sets a non-zero exit code rather than throwing a raw stack trace.
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.
223
269
  *
224
- * @param opts - Optional port override and web build hook.
225
- * @param opts.port - Local dev port to bind (overrides the `--port` flag and the default).
270
+ * @param opts - Optional port and web build hook.
271
+ * @param opts.port - Local dev port to bind. Defaults to 8787 when omitted.
226
272
  * @param opts.webBuild - Rebuild the web site on change (e.g. `() => webApp.cli.build()`).
227
273
  * @returns Resolves when the dev session ends.
228
274
  * @example
229
275
  * ```ts
230
- * await app.cli.dev({ webBuild: () => web.cli.build() }); // port from --port or 8787
276
+ * await app.cli.dev({ port: 7878, webBuild: () => web.cli.build() });
231
277
  * ```
232
278
  */
233
279
  dev(opts?: {
@@ -253,6 +299,26 @@ type Api = {
253
299
  ci?: boolean;
254
300
  webBuild?: WebBuild;
255
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>;
256
322
  /**
257
323
  * Verify the `.env` Cloudflare token (no sub), or print the config-derived token-creation
258
324
  * guidance (`"setup"`). Delegates to deploy.verifyAuth() / deploy.tokenInstructions().
@@ -332,13 +398,20 @@ declare const cliPlugin: import("@moku-labs/core").PluginInstance<"cli", Config,
332
398
  declare const deployPlugin: import("@moku-labs/core").PluginInstance<"deploy", Config$1, Record<string, never>, {
333
399
  run(opts?: {
334
400
  ci?: boolean;
401
+ stage?: string;
335
402
  webBuild?: WebBuild;
336
403
  manifest?: ExternalManifest;
337
404
  }): Promise<void>;
338
- dev: (opts?: {
405
+ dev(opts?: {
339
406
  port?: number;
407
+ stage?: string;
340
408
  webBuild?: WebBuild;
341
- }) => Promise<void>;
409
+ }): Promise<void>;
410
+ seed(sqlFile: string, opts?: {
411
+ stage?: string;
412
+ binding?: string;
413
+ remote?: boolean;
414
+ }): Promise<void>;
342
415
  init: (opts?: {
343
416
  ci?: boolean;
344
417
  }) => Promise<void>;
@@ -346,6 +419,7 @@ declare const deployPlugin: import("@moku-labs/core").PluginInstance<"deploy", C
346
419
  provisionInfra: (plan: InfraPlan) => Promise<ProvisionResult>;
347
420
  verifyAuth: () => Promise<AuthStatus>;
348
421
  requiredToken: () => TokenRequirement;
422
+ ciToken: () => PermissionGroup[];
349
423
  tokenInstructions: () => string;
350
424
  wrangler: (args: string[]) => Promise<void>;
351
425
  }, {}> & Record<never, never>;
@@ -109,6 +109,32 @@ type Config$1 = {
109
109
  * Also the file parsed in the universal/non-moku path.
110
110
  */
111
111
  configFile: string;
112
+ /**
113
+ * The Worker entry module → wrangler `main` (e.g. "src/cloudflare/worker.ts"). Required for any
114
+ * real Worker deploy (its absence is wrangler's "Missing entry-point" error).
115
+ */
116
+ entry?: string;
117
+ /**
118
+ * Enable Node.js compat → `compatibility_flags: ["nodejs_compat"]`. Needed when the Worker bundle
119
+ * pulls in Node-flavored code (e.g. composing the deploy/cli tooling into the runtime app).
120
+ */
121
+ nodeCompat?: boolean;
122
+ /**
123
+ * Static assets served via `env.<binding>` → the wrangler `assets` block. `spa: true` sets
124
+ * `not_found_handling: "single-page-application"` so client-routed deep links resolve to index.html.
125
+ */
126
+ assets?: {
127
+ binding: string;
128
+ directory: string;
129
+ spa?: boolean;
130
+ };
131
+ /**
132
+ * Escape hatch — extra top-level wrangler keys merged into the generated config for anything the
133
+ * typed fields above don't cover (`vars`, `routes`, `observability`, `triggers`, …). The
134
+ * deploy-managed resource keys (name, compatibility_date, kv_namespaces, r2_buckets, d1_databases,
135
+ * queues, durable_objects, and the auto-derived Durable Object `migrations`) always win over these.
136
+ */
137
+ wrangler?: Record<string, unknown>;
112
138
  /**
113
139
  * Standing CI/automated default for `run()`. When true (or when stdout is non-TTY) the deploy
114
140
  * never prompts and auto-confirms every gate; `run({ ci })` overrides it per call. CF credentials
@@ -127,24 +153,36 @@ type Config$1 = {
127
153
  migrateLocal: boolean; /** Debounce window (ms) coalescing rapid file changes into one rebuild. */
128
154
  debounceMs: number;
129
155
  };
130
- /** Discriminated union of resource descriptors returned by each plugin's deployManifest(). */
156
+ /**
157
+ * Discriminated union of per-INSTANCE resource descriptors. Each resource plugin's `deployManifest()`
158
+ * returns an ARRAY of these (one per configured instance). `name` is the base Cloudflare resource
159
+ * name (stage-suffixed downstream via {@link stageName}); `binding` is the stable env var. Durable
160
+ * Objects carry no provisioned `name` — they ship with the Worker script — and declare the exported
161
+ * `className` instead.
162
+ */
131
163
  type ResourceManifest = {
132
164
  kind: "r2";
133
- bucket: string;
165
+ name: string;
166
+ binding: string;
134
167
  upload?: string;
135
168
  } | {
136
169
  kind: "kv";
170
+ name: string;
137
171
  binding: string;
138
172
  } | {
139
173
  kind: "d1";
174
+ name: string;
140
175
  binding: string;
141
176
  migrations?: string;
142
177
  } | {
143
178
  kind: "queue";
144
- producers: string[];
179
+ name: string;
180
+ binding: string;
181
+ consumer?: boolean;
145
182
  } | {
146
183
  kind: "do";
147
- bindings: Record<string, string>;
184
+ binding: string;
185
+ className: string;
148
186
  };
149
187
  /**
150
188
  * The whole deploy manifest the pipeline consumes (assembled, or caller-supplied for the
@@ -174,12 +212,23 @@ type InfraPlan = {
174
212
  missing: ResourceManifest[];
175
213
  };
176
214
  /**
177
- * Outcome of acting on an {@link InfraPlan}: the resources just created, those skipped because
178
- * they already existed, and the merged id map (binding Cloudflare id) for the config writer.
215
+ * A resource that failed to provision, with the (branded) error message captured so the guided flow
216
+ * can show WHICH resource failed and why instead of aborting the whole run on the first failure.
217
+ */
218
+ type ProvisionFailure = {
219
+ /** The resource descriptor that failed to create. */resource: ResourceManifest; /** The captured error message (e.g. the branded wrangler failure). */
220
+ error: string;
221
+ };
222
+ /**
223
+ * Outcome of acting on an {@link InfraPlan}: the resources just created, those skipped because they
224
+ * already existed, those that FAILED to create, and the merged id map (binding → Cloudflare id) for
225
+ * the config writer. Provisioning is resilient — a single resource failure is captured here, not
226
+ * thrown, so the guided flow can report a clear per-resource result.
179
227
  */
180
228
  type ProvisionResult = {
181
229
  /** Resources created during this run. */created: ProvisionedRef[]; /** Resources skipped because they already existed. */
182
- skipped: ProvisionedRef[]; /** Merged binding Cloudflare id map (existing + created) for writeWranglerConfig. */
230
+ skipped: ProvisionedRef[]; /** Resources that failed to create (captured, not thrown). */
231
+ failed: ProvisionFailure[]; /** Merged binding → Cloudflare id map (existing + created) for writeWranglerConfig. */
183
232
  ids: Record<string, string>;
184
233
  };
185
234
  /** Result of verifying the `.env` Cloudflare API token and resolving its account. */
@@ -204,30 +253,27 @@ type TokenRequirement = {
204
253
  };
205
254
  //#endregion
206
255
  //#region src/plugins/cli/types.d.ts
207
- /** Resolved configuration for the cli plugin. Flat; complete defaults so omission never yields undefined. */
208
- type Config = {
209
- /**
210
- * Default local dev port forwarded to deploy.dev when dev() gets no port.
211
- * Passed through to `wrangler dev --port <n>`.
212
- *
213
- * @default 8787
214
- */
215
- readonly port: number;
216
- };
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>;
217
262
  /** Public api surface of the cli plugin, mounted at app.cli.*. */
218
263
  type Api = {
219
264
  /**
220
- * Run the Worker locally via Wrangler (delegates to deploy.dev). Resolves the port from
221
- * `opts.port`, else a `--port <n>` CLI flag, else the configured default (8787). A failure renders
222
- * a branded `✗` line and sets a non-zero exit code rather than throwing a raw stack trace.
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.
223
269
  *
224
- * @param opts - Optional port override and web build hook.
225
- * @param opts.port - Local dev port to bind (overrides the `--port` flag and the default).
270
+ * @param opts - Optional port and web build hook.
271
+ * @param opts.port - Local dev port to bind. Defaults to 8787 when omitted.
226
272
  * @param opts.webBuild - Rebuild the web site on change (e.g. `() => webApp.cli.build()`).
227
273
  * @returns Resolves when the dev session ends.
228
274
  * @example
229
275
  * ```ts
230
- * await app.cli.dev({ webBuild: () => web.cli.build() }); // port from --port or 8787
276
+ * await app.cli.dev({ port: 7878, webBuild: () => web.cli.build() });
231
277
  * ```
232
278
  */
233
279
  dev(opts?: {
@@ -253,6 +299,26 @@ type Api = {
253
299
  ci?: boolean;
254
300
  webBuild?: WebBuild;
255
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>;
256
322
  /**
257
323
  * Verify the `.env` Cloudflare token (no sub), or print the config-derived token-creation
258
324
  * guidance (`"setup"`). Delegates to deploy.verifyAuth() / deploy.tokenInstructions().
@@ -332,13 +398,20 @@ declare const cliPlugin: import("@moku-labs/core").PluginInstance<"cli", Config,
332
398
  declare const deployPlugin: import("@moku-labs/core").PluginInstance<"deploy", Config$1, Record<string, never>, {
333
399
  run(opts?: {
334
400
  ci?: boolean;
401
+ stage?: string;
335
402
  webBuild?: WebBuild;
336
403
  manifest?: ExternalManifest;
337
404
  }): Promise<void>;
338
- dev: (opts?: {
405
+ dev(opts?: {
339
406
  port?: number;
407
+ stage?: string;
340
408
  webBuild?: WebBuild;
341
- }) => Promise<void>;
409
+ }): Promise<void>;
410
+ seed(sqlFile: string, opts?: {
411
+ stage?: string;
412
+ binding?: string;
413
+ remote?: boolean;
414
+ }): Promise<void>;
342
415
  init: (opts?: {
343
416
  ci?: boolean;
344
417
  }) => Promise<void>;
@@ -346,6 +419,7 @@ declare const deployPlugin: import("@moku-labs/core").PluginInstance<"deploy", C
346
419
  provisionInfra: (plan: InfraPlan) => Promise<ProvisionResult>;
347
420
  verifyAuth: () => Promise<AuthStatus>;
348
421
  requiredToken: () => TokenRequirement;
422
+ ciToken: () => PermissionGroup[];
349
423
  tokenInstructions: () => string;
350
424
  wrangler: (args: string[]) => Promise<void>;
351
425
  }, {}> & Record<never, never>;
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_cli = require("./cli-Dc0q0hIy.cjs");
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
  /**