@moku-labs/worker 0.5.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -9
- package/dist/cli-Bb37rYq_.mjs +3640 -0
- package/dist/cli-C8DdTtzn.cjs +3740 -0
- package/dist/cli.cjs +3 -1920
- package/dist/cli.d.cts +1 -270
- package/dist/cli.d.mts +1 -270
- package/dist/cli.mjs +1 -1895
- package/dist/index-BKOUpKtC.d.cts +404 -0
- package/dist/index-BKOUpKtC.d.mts +404 -0
- package/dist/index.cjs +61 -63
- package/dist/index.d.cts +338 -166
- package/dist/index.d.mts +338 -166
- package/dist/index.mjs +49 -53
- package/package.json +1 -1
- package/dist/config-BYPJvEbl.d.cts +0 -88
- package/dist/config-BYPJvEbl.d.mts +0 -88
- package/dist/storage-COo-F38H.mjs +0 -884
- package/dist/storage-CgXl-dUA.cjs +0 -949
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
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-BKOUpKtC.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
|
|
|
5
5
|
//#region \0rolldown/runtime.js
|
|
6
6
|
declare namespace types_d_exports {
|
|
7
|
-
export { BindingsApi, Config$
|
|
7
|
+
export { BindingsApi, Config$5 as Config, Context };
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* bindings config. Flat (spec/05 §3,§6) — a complete default so omission
|
|
@@ -15,7 +15,7 @@ declare namespace types_d_exports {
|
|
|
15
15
|
* { required: ["MY_KV", "DB"] }
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
|
-
type Config$
|
|
18
|
+
type Config$5 = {
|
|
19
19
|
required: string[];
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
@@ -50,7 +50,7 @@ type BindingsApi = {
|
|
|
50
50
|
* api-factory context. State slot is Record<string, never> — bindings holds NO
|
|
51
51
|
* state (F4). Type-argument order is PluginCtx<Config, State, Events>.
|
|
52
52
|
*/
|
|
53
|
-
type Context = PluginCtx$1<Config$
|
|
53
|
+
type Context = PluginCtx$1<Config$5, Record<string, never>, WorkerEvents>;
|
|
54
54
|
//#endregion
|
|
55
55
|
//#region src/plugins/bindings/index.d.ts
|
|
56
56
|
/**
|
|
@@ -62,7 +62,7 @@ type Context = PluginCtx$1<Config$4, Record<string, never>, WorkerEvents>;
|
|
|
62
62
|
*
|
|
63
63
|
* @see README.md
|
|
64
64
|
*/
|
|
65
|
-
declare const bindingsPlugin: import("@moku-labs/core").PluginInstance<"bindings", Config$
|
|
65
|
+
declare const bindingsPlugin: import("@moku-labs/core").PluginInstance<"bindings", Config$5, Record<string, never>, BindingsApi, {}> & Record<never, never>;
|
|
66
66
|
declare namespace types_d_exports$4 {
|
|
67
67
|
export { Api$3 as Api, CompiledEndpoint, Endpoint, EndpointHandler, MatchResult, Method, PathParams, PathSegment, RequestContext, RequireFn, ServerConfig, ServerCtx, ServerEvents, ServerState };
|
|
68
68
|
}
|
|
@@ -335,35 +335,43 @@ type EndpointBuilder<Path extends string> = {
|
|
|
335
335
|
*/
|
|
336
336
|
declare const endpoint: <Path extends string>(path: Path) => EndpointBuilder<Path>;
|
|
337
337
|
declare namespace types_d_exports$1 {
|
|
338
|
-
export { Api$2 as Api, Config$
|
|
338
|
+
export { Api$2 as Api, Config$4 as Config, D1Ctx, D1DatabaseApi, D1Instance };
|
|
339
339
|
}
|
|
340
340
|
/**
|
|
341
|
-
*
|
|
341
|
+
* A single D1 database instance: its base Cloudflare name + the env binding it resolves off, plus
|
|
342
|
+
* optional deploy-time migrations metadata.
|
|
342
343
|
*
|
|
343
344
|
* @example
|
|
344
345
|
* ```ts
|
|
345
|
-
* { binding: "DB", migrations: "
|
|
346
|
+
* { name: "tracker-db", binding: "DB", migrations: "db/migrations" }
|
|
346
347
|
* ```
|
|
347
348
|
*/
|
|
348
|
-
type
|
|
349
|
-
/** D1
|
|
350
|
-
|
|
349
|
+
type D1Instance = {
|
|
350
|
+
/** Base Cloudflare D1 database name (stage-suffixed at deploy). */name: string; /** Env binding name the database resolves off the per-request `env` (e.g. `env.DB`). */
|
|
351
|
+
binding: string; /** Migrations directory; deploy-time metadata only. Omit when there are none. */
|
|
352
|
+
migrations?: string; /** Marks this instance the default when more than one is configured. */
|
|
353
|
+
default?: boolean;
|
|
351
354
|
};
|
|
352
355
|
/**
|
|
353
|
-
*
|
|
356
|
+
* d1 plugin config — a keyed map of D1 database instances. The key is the stable logical id used by
|
|
357
|
+
* `app.d1.use("key")`; a single entry (or one flagged `default: true`) is the implicit default.
|
|
354
358
|
*
|
|
355
359
|
* @example
|
|
356
360
|
* ```ts
|
|
357
|
-
* {
|
|
361
|
+
* { main: { name: "tracker-db", binding: "DB", migrations: "db/migrations" } }
|
|
358
362
|
* ```
|
|
359
363
|
*/
|
|
360
|
-
type
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
364
|
+
type Config$4 = Record<string, D1Instance>;
|
|
365
|
+
/**
|
|
366
|
+
* The SQL surface for one D1 database (the thin typed wrappers bound to a single instance).
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```ts
|
|
370
|
+
* const { results } = await app.d1.query<Product>(env, "SELECT * FROM products");
|
|
371
|
+
* await app.d1.use("analytics").run(env, "INSERT INTO events (name) VALUES (?)", "click");
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
type D1DatabaseApi = {
|
|
367
375
|
/**
|
|
368
376
|
* Run a statement and return all rows.
|
|
369
377
|
*
|
|
@@ -406,18 +414,43 @@ type Api$2 = {
|
|
|
406
414
|
* @returns The request-resolved database handle.
|
|
407
415
|
*/
|
|
408
416
|
prepare: (env: WorkerEnv) => D1Database;
|
|
417
|
+
};
|
|
418
|
+
/**
|
|
419
|
+
* The app.d1 surface — the default database's methods, a `use(key)` selector for the others, plus
|
|
420
|
+
* deploy metadata.
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* ```ts
|
|
424
|
+
* const { results } = await app.d1.query<Product>(env, "SELECT * FROM products"); // default db
|
|
425
|
+
* await app.d1.use("analytics").run(env, "INSERT INTO events (name) VALUES (?)", "click");
|
|
426
|
+
* ```
|
|
427
|
+
*/
|
|
428
|
+
type Api$2 = D1DatabaseApi & {
|
|
429
|
+
/**
|
|
430
|
+
* Select a specific D1 database instance by its config key.
|
|
431
|
+
*
|
|
432
|
+
* @param key - The instance key (as configured under `pluginConfigs.d1`).
|
|
433
|
+
* @returns The SQL surface bound to that database.
|
|
434
|
+
*/
|
|
435
|
+
use(key: string): D1DatabaseApi;
|
|
409
436
|
/**
|
|
410
|
-
* Return this plugin's deploy metadata (read by the deploy
|
|
437
|
+
* Return this plugin's deploy metadata (one entry per configured database), read by the deploy
|
|
438
|
+
* plugin. Build-time only — takes no `env`.
|
|
411
439
|
*
|
|
412
|
-
* @returns
|
|
440
|
+
* @returns One d1 deploy descriptor per configured instance.
|
|
413
441
|
*/
|
|
414
|
-
deployManifest
|
|
442
|
+
deployManifest(): Array<{
|
|
443
|
+
kind: "d1";
|
|
444
|
+
name: string;
|
|
445
|
+
binding: string;
|
|
446
|
+
migrations?: string;
|
|
447
|
+
}>;
|
|
415
448
|
};
|
|
416
449
|
/**
|
|
417
450
|
* Internal context type — own config first, no state, no d1-local events.
|
|
418
451
|
* Intersected with a narrow `require` typed to the one dependency d1 resolves.
|
|
419
452
|
*/
|
|
420
|
-
type D1Ctx = PluginCtx$1<Config$
|
|
453
|
+
type D1Ctx = PluginCtx$1<Config$4, Record<string, never>, WorkerEvents> & {
|
|
421
454
|
/**
|
|
422
455
|
* Resolve a dependency plugin's api. d1 only ever resolves `bindingsPlugin`.
|
|
423
456
|
*
|
|
@@ -437,71 +470,26 @@ type D1Ctx = PluginCtx$1<Config$3, Record<string, never>, WorkerEvents> & {
|
|
|
437
470
|
*
|
|
438
471
|
* @see README.md
|
|
439
472
|
*/
|
|
440
|
-
declare const d1Plugin: import("@moku-labs/core").PluginInstance<"d1", Config$
|
|
473
|
+
declare const d1Plugin: import("@moku-labs/core").PluginInstance<"d1", Config$4, Record<string, never>, {
|
|
474
|
+
use: (key: string) => {
|
|
475
|
+
query: <T = unknown>(env: WorkerEnv, sql: string, ...params: unknown[]) => Promise<D1Result<T>>;
|
|
476
|
+
first: <T = unknown>(env: WorkerEnv, sql: string, ...params: unknown[]) => Promise<T | null>;
|
|
477
|
+
run: (env: WorkerEnv, sql: string, ...params: unknown[]) => Promise<D1Result<Record<string, unknown>>>;
|
|
478
|
+
batch: (env: WorkerEnv, stmts: D1PreparedStatement[]) => Promise<D1Result<unknown>[]>;
|
|
479
|
+
prepare: (env: WorkerEnv) => D1Database;
|
|
480
|
+
};
|
|
481
|
+
deployManifest: () => {
|
|
482
|
+
kind: "d1";
|
|
483
|
+
name: string;
|
|
484
|
+
binding: string;
|
|
485
|
+
migrations?: string;
|
|
486
|
+
}[];
|
|
441
487
|
query: <T = unknown>(env: WorkerEnv, sql: string, ...params: unknown[]) => Promise<D1Result<T>>;
|
|
442
488
|
first: <T = unknown>(env: WorkerEnv, sql: string, ...params: unknown[]) => Promise<T | null>;
|
|
443
489
|
run: (env: WorkerEnv, sql: string, ...params: unknown[]) => Promise<D1Result<Record<string, unknown>>>;
|
|
444
490
|
batch: (env: WorkerEnv, stmts: D1PreparedStatement[]) => Promise<D1Result<unknown>[]>;
|
|
445
491
|
prepare: (env: WorkerEnv) => D1Database;
|
|
446
|
-
deployManifest: () => DeployManifest$2;
|
|
447
492
|
}, {}> & Record<never, never>;
|
|
448
|
-
declare namespace types_d_exports$2 {
|
|
449
|
-
export { Api$1 as Api, Config$2 as Config, Ctx$1 as Ctx, DeployManifest$1 as DeployManifest };
|
|
450
|
-
}
|
|
451
|
-
/**
|
|
452
|
-
* durableObjects plugin configuration. Flat; complete default so omission never yields undefined.
|
|
453
|
-
*
|
|
454
|
-
* @example
|
|
455
|
-
* ```ts
|
|
456
|
-
* { bindings: { counter: "COUNTER" } }
|
|
457
|
-
* ```
|
|
458
|
-
*/
|
|
459
|
-
type Config$2 = {
|
|
460
|
-
/** Logical name -> Cloudflare DO binding name. A missing logical name falls back to itself. Default {}. */bindings: Record<string, string>;
|
|
461
|
-
};
|
|
462
|
-
/**
|
|
463
|
-
* Deploy metadata entry for Durable Objects, read by the deploy plugin.
|
|
464
|
-
*
|
|
465
|
-
* @example
|
|
466
|
-
* ```ts
|
|
467
|
-
* { kind: "do", bindings: { counter: "COUNTER" } }
|
|
468
|
-
* ```
|
|
469
|
-
*/
|
|
470
|
-
type DeployManifest$1 = {
|
|
471
|
-
/** Discriminant identifying this as a Durable Objects resource. */kind: "do"; /** Logical name -> Cloudflare DO binding name. */
|
|
472
|
-
bindings: Record<string, string>;
|
|
473
|
-
};
|
|
474
|
-
/** Public api surface of the durableObjects plugin. */
|
|
475
|
-
type Api$1 = {
|
|
476
|
-
/**
|
|
477
|
-
* Resolve a DurableObjectStub off the request env (logical name -> configured binding).
|
|
478
|
-
*
|
|
479
|
-
* @param env - Per-request Cloudflare bindings.
|
|
480
|
-
* @param logicalName - Logical DO name used in code.
|
|
481
|
-
* @param idName - Stable id name passed to idFromName.
|
|
482
|
-
* @returns The addressed Durable Object stub.
|
|
483
|
-
*/
|
|
484
|
-
get(env: WorkerEnv, logicalName: string, idName: string): DurableObjectStub;
|
|
485
|
-
/**
|
|
486
|
-
* Return this plugin's deploy metadata (read by the deploy plugin).
|
|
487
|
-
*
|
|
488
|
-
* @returns Deploy manifest entry `{ kind: "do", bindings }`.
|
|
489
|
-
*/
|
|
490
|
-
deployManifest(): DeployManifest$1;
|
|
491
|
-
};
|
|
492
|
-
/**
|
|
493
|
-
* Internal context type — own config first, no state, no DO events.
|
|
494
|
-
* Intersected with a narrow `require` typed to the one dependency durableObjects resolves.
|
|
495
|
-
*/
|
|
496
|
-
type Ctx$1 = PluginCtx$1<Config$2, Record<string, never>, WorkerEvents> & {
|
|
497
|
-
/**
|
|
498
|
-
* Resolve a dependency plugin's api. durableObjects only ever resolves `bindingsPlugin`.
|
|
499
|
-
*
|
|
500
|
-
* @param plugin - The bindingsPlugin instance.
|
|
501
|
-
* @returns The resolved bindings api.
|
|
502
|
-
*/
|
|
503
|
-
require(plugin: typeof bindingsPlugin): BindingsApi;
|
|
504
|
-
};
|
|
505
493
|
//#endregion
|
|
506
494
|
//#region src/plugins/durable-objects/helpers.d.ts
|
|
507
495
|
/**
|
|
@@ -559,31 +547,101 @@ type DurableObjectBaseConstructor = new (ctx: DurableObjectState, env: WorkerEnv
|
|
|
559
547
|
declare const defineDurableObject: (name: string) => DurableObjectBaseConstructor & {
|
|
560
548
|
readonly doName: string;
|
|
561
549
|
};
|
|
550
|
+
declare namespace types_d_exports$2 {
|
|
551
|
+
export { Api$1 as Api, Config$3 as Config, Ctx$1 as Ctx, DoInstance };
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* A single Durable Object instance: the env binding it resolves off plus the EXPORTED class it
|
|
555
|
+
* addresses. DOs are not provisioned (they ship with the Worker script), so there is no base
|
|
556
|
+
* Cloudflare `name` — `binding` is the env var and `className` is the class the consumer exports from
|
|
557
|
+
* `worker.ts`, decoupled from the logical key.
|
|
558
|
+
*
|
|
559
|
+
* @example
|
|
560
|
+
* ```ts
|
|
561
|
+
* { binding: "BOARD", className: "BoardChannel" }
|
|
562
|
+
* ```
|
|
563
|
+
*/
|
|
564
|
+
type DoInstance = {
|
|
565
|
+
/** Env binding name the namespace resolves off the per-request `env` (e.g. `env.BOARD`). */binding: string; /** The EXPORTED Durable Object class name (e.g. `"BoardChannel"`), used in the wrangler config. */
|
|
566
|
+
className: string; /** Marks this instance the default when more than one is configured. */
|
|
567
|
+
default?: boolean;
|
|
568
|
+
};
|
|
569
|
+
/**
|
|
570
|
+
* durableObjects plugin config — a keyed map of Durable Object instances. The key is the stable
|
|
571
|
+
* logical name passed to `app.durableObjects.get(env, key, id)`; a single entry (or one flagged
|
|
572
|
+
* `default: true`) is the implicit default.
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
* ```ts
|
|
576
|
+
* { board: { binding: "BOARD", className: "BoardChannel" } }
|
|
577
|
+
* ```
|
|
578
|
+
*/
|
|
579
|
+
type Config$3 = Record<string, DoInstance>;
|
|
580
|
+
/** Public api surface of the durableObjects plugin. */
|
|
581
|
+
type Api$1 = {
|
|
582
|
+
/**
|
|
583
|
+
* Resolve a DurableObjectStub off the request env (logical key -> configured binding).
|
|
584
|
+
*
|
|
585
|
+
* @param env - Per-request Cloudflare bindings.
|
|
586
|
+
* @param logicalName - Logical DO key (selects the configured instance).
|
|
587
|
+
* @param idName - Stable id name passed to idFromName.
|
|
588
|
+
* @returns The addressed Durable Object stub.
|
|
589
|
+
*/
|
|
590
|
+
get(env: WorkerEnv, logicalName: string, idName: string): DurableObjectStub;
|
|
591
|
+
/**
|
|
592
|
+
* Return this plugin's deploy metadata — one entry per configured instance (read by the deploy
|
|
593
|
+
* plugin).
|
|
594
|
+
*
|
|
595
|
+
* @returns One do deploy descriptor per configured instance.
|
|
596
|
+
*/
|
|
597
|
+
deployManifest(): Array<{
|
|
598
|
+
kind: "do";
|
|
599
|
+
binding: string;
|
|
600
|
+
className: string;
|
|
601
|
+
}>;
|
|
602
|
+
};
|
|
603
|
+
/**
|
|
604
|
+
* Internal context type — own config first, no state, no DO events.
|
|
605
|
+
* Intersected with a narrow `require` typed to the one dependency durableObjects resolves.
|
|
606
|
+
*/
|
|
607
|
+
type Ctx$1 = PluginCtx$1<Config$3, Record<string, never>, WorkerEvents> & {
|
|
608
|
+
/**
|
|
609
|
+
* Resolve a dependency plugin's api. durableObjects only ever resolves `bindingsPlugin`.
|
|
610
|
+
*
|
|
611
|
+
* @param plugin - The bindingsPlugin instance.
|
|
612
|
+
* @returns The resolved bindings api.
|
|
613
|
+
*/
|
|
614
|
+
require(plugin: typeof bindingsPlugin): BindingsApi;
|
|
615
|
+
};
|
|
562
616
|
//#endregion
|
|
563
617
|
//#region src/plugins/durable-objects/index.d.ts
|
|
564
618
|
/**
|
|
565
619
|
* Cloudflare Durable Objects plugin — Standard tier.
|
|
566
620
|
*
|
|
567
621
|
* Exposes `get(env, logicalName, idName)` (synchronous stub accessor, threaded env) and
|
|
568
|
-
* `deployManifest()` (build-time metadata). Depends on
|
|
569
|
-
* resolution. The `defineDurableObject` helper is mounted under
|
|
570
|
-
* at the top level for consumer use.
|
|
622
|
+
* `deployManifest()` (build-time metadata, one entry per configured instance). Depends on
|
|
623
|
+
* `bindingsPlugin` for namespace resolution. The `defineDurableObject` helper is mounted under
|
|
624
|
+
* `helpers` and re-exported at the top level for consumer use.
|
|
571
625
|
*
|
|
572
626
|
* @example
|
|
573
627
|
* ```typescript
|
|
574
628
|
* // Consumer endpoint handler:
|
|
575
|
-
* const stub = app.durableObjects.get(env, "
|
|
629
|
+
* const stub = app.durableObjects.get(env, "board", params.room!);
|
|
576
630
|
* const res = await stub.fetch("https://do/increment");
|
|
577
|
-
* // Consumer DO class:
|
|
578
|
-
* export class
|
|
631
|
+
* // Consumer DO class (the EXPORTED className referenced by the "board" instance):
|
|
632
|
+
* export class BoardChannel extends defineDurableObject("BoardChannel") {
|
|
579
633
|
* async fetch(): Promise<Response> { return new Response("ok"); }
|
|
580
634
|
* }
|
|
581
635
|
* ```
|
|
582
636
|
* @see README.md
|
|
583
637
|
*/
|
|
584
|
-
declare const durableObjectsPlugin: import("@moku-labs/core").PluginInstance<"durableObjects", Config$
|
|
638
|
+
declare const durableObjectsPlugin: import("@moku-labs/core").PluginInstance<"durableObjects", Config$3, Record<string, never>, {
|
|
585
639
|
get: (env: WorkerEnv, logicalName: string, idName: string) => DurableObjectStub;
|
|
586
|
-
deployManifest: () =>
|
|
640
|
+
deployManifest: () => Array<{
|
|
641
|
+
kind: "do";
|
|
642
|
+
binding: string;
|
|
643
|
+
className: string;
|
|
644
|
+
}>;
|
|
587
645
|
}, {}> & {
|
|
588
646
|
defineDurableObject: (name: string) => DurableObjectBaseConstructor & {
|
|
589
647
|
readonly doName: string;
|
|
@@ -592,15 +650,38 @@ declare const durableObjectsPlugin: import("@moku-labs/core").PluginInstance<"du
|
|
|
592
650
|
//#endregion
|
|
593
651
|
//#region src/plugins/kv/api.d.ts
|
|
594
652
|
/**
|
|
595
|
-
*
|
|
653
|
+
* A single KV namespace instance: its base Cloudflare name + the env binding it resolves off.
|
|
654
|
+
*
|
|
655
|
+
* @example
|
|
656
|
+
* ```typescript
|
|
657
|
+
* { name: "tracker-cache", binding: "CACHE" }
|
|
658
|
+
* ```
|
|
659
|
+
*/
|
|
660
|
+
type KvInstance = {
|
|
661
|
+
/** Base Cloudflare KV namespace name (stage-suffixed at deploy). */name: string; /** Env binding name the namespace resolves off the per-request `env` (e.g. `env.CACHE`). */
|
|
662
|
+
binding: string; /** Marks this instance the default when more than one is configured. */
|
|
663
|
+
default?: boolean;
|
|
664
|
+
};
|
|
665
|
+
/**
|
|
666
|
+
* kv plugin config — a keyed map of KV namespace instances. The key is the stable logical id used by
|
|
667
|
+
* `app.kv.use("key")`; a single entry (or one flagged `default: true`) is the implicit default.
|
|
668
|
+
*
|
|
669
|
+
* @example
|
|
670
|
+
* ```typescript
|
|
671
|
+
* { cache: { name: "tracker-cache", binding: "CACHE" } }
|
|
672
|
+
* ```
|
|
673
|
+
*/
|
|
674
|
+
type Config$2 = Record<string, KvInstance>;
|
|
675
|
+
/**
|
|
676
|
+
* The env-first key/value surface for one KV namespace (the methods bound to a single instance).
|
|
596
677
|
*
|
|
597
678
|
* @example
|
|
598
679
|
* ```typescript
|
|
599
680
|
* const value = await app.kv.get(env, "feature-flags");
|
|
600
|
-
* await app.kv.put(env, "session:1", "data", { expirationTtl: 3600 });
|
|
681
|
+
* await app.kv.use("sessions").put(env, "session:1", "data", { expirationTtl: 3600 });
|
|
601
682
|
* ```
|
|
602
683
|
*/
|
|
603
|
-
type
|
|
684
|
+
type KvNamespaceApi = {
|
|
604
685
|
/**
|
|
605
686
|
* Reads a value by key from the KV namespace. Returns null when absent.
|
|
606
687
|
*
|
|
@@ -635,16 +716,36 @@ type KvApi = {
|
|
|
635
716
|
* @returns The list result.
|
|
636
717
|
*/
|
|
637
718
|
list(env: WorkerEnv, opts?: KVNamespaceListOptions): Promise<KVNamespaceListResult<unknown, string>>;
|
|
719
|
+
};
|
|
720
|
+
/**
|
|
721
|
+
* The app.kv surface — the default namespace's methods, a `use(key)` selector for the others, plus
|
|
722
|
+
* deploy metadata.
|
|
723
|
+
*
|
|
724
|
+
* @example
|
|
725
|
+
* ```typescript
|
|
726
|
+
* const value = await app.kv.get(env, "feature-flags"); // default namespace
|
|
727
|
+
* await app.kv.use("sessions").put(env, "s:1", "data"); // a named namespace
|
|
728
|
+
* ```
|
|
729
|
+
*/
|
|
730
|
+
type KvApi = KvNamespaceApi & {
|
|
638
731
|
/**
|
|
639
|
-
*
|
|
640
|
-
* Build-time only — takes no env.
|
|
732
|
+
* Select a specific KV namespace instance by its config key.
|
|
641
733
|
*
|
|
642
|
-
* @
|
|
734
|
+
* @param key - The instance key (as configured under `pluginConfigs.kv`).
|
|
735
|
+
* @returns The key/value surface bound to that namespace.
|
|
643
736
|
*/
|
|
644
|
-
|
|
737
|
+
use(key: string): KvNamespaceApi;
|
|
738
|
+
/**
|
|
739
|
+
* Returns this plugin's own deploy metadata (one entry per configured namespace), read by the
|
|
740
|
+
* deploy plugin. Build-time only — takes no env.
|
|
741
|
+
*
|
|
742
|
+
* @returns One kv deploy descriptor per configured instance.
|
|
743
|
+
*/
|
|
744
|
+
deployManifest(): Array<{
|
|
645
745
|
kind: "kv";
|
|
746
|
+
name: string;
|
|
646
747
|
binding: string;
|
|
647
|
-
}
|
|
748
|
+
}>;
|
|
648
749
|
};
|
|
649
750
|
//#endregion
|
|
650
751
|
//#region src/plugins/kv/index.d.ts
|
|
@@ -657,31 +758,35 @@ type KvApi = {
|
|
|
657
758
|
*
|
|
658
759
|
* @see README.md
|
|
659
760
|
*/
|
|
660
|
-
declare const kvPlugin: import("@moku-labs/core").PluginInstance<"kv", {
|
|
661
|
-
binding: string;
|
|
662
|
-
}, Record<string, never>, KvApi, {}> & Record<never, never>;
|
|
761
|
+
declare const kvPlugin: import("@moku-labs/core").PluginInstance<"kv", Config$2, Record<string, never>, KvApi, {}> & Record<never, never>;
|
|
663
762
|
declare namespace types_d_exports$3 {
|
|
664
|
-
export { Api, Config$1 as Config, Ctx,
|
|
763
|
+
export { Api, Config$1 as Config, Ctx, QueueEvents, QueueInstance, QueueProducerApi };
|
|
665
764
|
}
|
|
666
765
|
/**
|
|
667
|
-
*
|
|
766
|
+
* A single Cloudflare Queue instance: its base CF queue name, the producer env binding it
|
|
767
|
+
* resolves off, and an optional per-instance consumer handler.
|
|
768
|
+
*
|
|
769
|
+
* @example
|
|
770
|
+
* ```ts
|
|
771
|
+
* { name: "tracker-activity", binding: "ACTIVITY", onMessage: async (m, env) => {} }
|
|
772
|
+
* ```
|
|
668
773
|
*/
|
|
669
|
-
type
|
|
670
|
-
/**
|
|
671
|
-
|
|
774
|
+
type QueueInstance = {
|
|
775
|
+
/** Base Cloudflare queue name (stage-suffixed at deploy, e.g. `tracker-activity-dev`). */name: string; /** Producer env binding the Queue resolves off the per-request `env` (e.g. `env.ACTIVITY`). */
|
|
776
|
+
binding: string; /** Per-instance consumer handler — awaited once per message in `consume()`. Optional → no-op. */
|
|
777
|
+
onMessage?: (message: Message, env: WorkerEnv) => Promise<void>; /** Marks this instance the default when more than one is configured. */
|
|
778
|
+
default?: boolean;
|
|
672
779
|
};
|
|
673
780
|
/**
|
|
674
|
-
*
|
|
781
|
+
* queues plugin config — a keyed map of Queue instances. The key is the stable logical id used by
|
|
782
|
+
* `app.queues.use("key")`; a single entry (or one flagged `default: true`) is the implicit default.
|
|
675
783
|
*
|
|
676
784
|
* @example
|
|
677
785
|
* ```ts
|
|
678
|
-
* {
|
|
786
|
+
* { activity: { name: "tracker-activity", binding: "ACTIVITY", onMessage: async () => {} } }
|
|
679
787
|
* ```
|
|
680
788
|
*/
|
|
681
|
-
type
|
|
682
|
-
/** Discriminant identifying this as a queue resource. */kind: "queue"; /** Queue names produced to. */
|
|
683
|
-
producers: string[];
|
|
684
|
-
};
|
|
789
|
+
type Config$1 = Record<string, QueueInstance>;
|
|
685
790
|
/** Per-plugin event map for queues. */
|
|
686
791
|
type QueueEvents = {
|
|
687
792
|
"queue:message": {
|
|
@@ -689,41 +794,71 @@ type QueueEvents = {
|
|
|
689
794
|
messageId: string;
|
|
690
795
|
};
|
|
691
796
|
};
|
|
692
|
-
/**
|
|
693
|
-
|
|
797
|
+
/**
|
|
798
|
+
* The producer surface for one Queue instance (the send methods bound to a single instance).
|
|
799
|
+
*
|
|
800
|
+
* @example
|
|
801
|
+
* ```ts
|
|
802
|
+
* await app.queues.use("activity").send(env, { userId: "u1" });
|
|
803
|
+
* ```
|
|
804
|
+
*/
|
|
805
|
+
type QueueProducerApi = {
|
|
694
806
|
/**
|
|
695
|
-
* Enqueue a single message onto
|
|
807
|
+
* Enqueue a single message onto this instance's queue.
|
|
696
808
|
*
|
|
697
|
-
* @param env - Per-request Cloudflare bindings.
|
|
698
|
-
* @param
|
|
699
|
-
* @
|
|
700
|
-
* @returns Resolves once enqueued.
|
|
809
|
+
* @param env - Per-request Cloudflare bindings object.
|
|
810
|
+
* @param body - Message body to enqueue.
|
|
811
|
+
* @returns Resolves once the message is enqueued.
|
|
701
812
|
*/
|
|
702
|
-
send(env: WorkerEnv,
|
|
813
|
+
send(env: WorkerEnv, body: unknown): Promise<void>;
|
|
703
814
|
/**
|
|
704
|
-
* Enqueue many messages; each element becomes one message.
|
|
815
|
+
* Enqueue many messages onto this instance's queue; each element becomes one message.
|
|
705
816
|
*
|
|
706
|
-
* @param env - Per-request Cloudflare bindings.
|
|
707
|
-
* @param
|
|
708
|
-
* @
|
|
709
|
-
* @returns Resolves once enqueued.
|
|
817
|
+
* @param env - Per-request Cloudflare bindings object.
|
|
818
|
+
* @param bodies - Array of message bodies; each becomes one message.
|
|
819
|
+
* @returns Resolves once all messages are enqueued.
|
|
710
820
|
*/
|
|
711
|
-
sendBatch(env: WorkerEnv,
|
|
821
|
+
sendBatch(env: WorkerEnv, bodies: unknown[]): Promise<void>;
|
|
822
|
+
};
|
|
823
|
+
/**
|
|
824
|
+
* The app.queues surface — the default instance's producer methods, a `use(key)` selector for the
|
|
825
|
+
* others, the consumer dispatch entry, plus deploy metadata.
|
|
826
|
+
*
|
|
827
|
+
* @example
|
|
828
|
+
* ```ts
|
|
829
|
+
* await app.queues.send(env, { orderId: "1" }); // default instance
|
|
830
|
+
* await app.queues.use("activity").send(env, { id: 2 }); // a named instance
|
|
831
|
+
* ```
|
|
832
|
+
*/
|
|
833
|
+
type Api = QueueProducerApi & {
|
|
712
834
|
/**
|
|
713
|
-
*
|
|
835
|
+
* Select a specific Queue instance by its config key.
|
|
836
|
+
*
|
|
837
|
+
* @param key - The instance key (as configured under `pluginConfigs.queues`).
|
|
838
|
+
* @returns The producer surface bound to that instance.
|
|
839
|
+
*/
|
|
840
|
+
use(key: string): QueueProducerApi;
|
|
841
|
+
/**
|
|
842
|
+
* Consumer dispatch — the Worker's `queue()` export delegates here. Routes the batch to the
|
|
843
|
+
* matching instance's `onMessage` (by config key map / CF queue name).
|
|
714
844
|
*
|
|
715
845
|
* @param batch - The incoming message batch.
|
|
716
846
|
* @param env - Per-request Cloudflare bindings.
|
|
717
|
-
* @param
|
|
847
|
+
* @param ctx - waitUntil / passThroughOnException.
|
|
718
848
|
* @returns Resolves after all messages settle.
|
|
719
849
|
*/
|
|
720
|
-
consume(batch: MessageBatch, env: WorkerEnv,
|
|
850
|
+
consume(batch: MessageBatch, env: WorkerEnv, ctx: ExecutionContext): Promise<void>;
|
|
721
851
|
/**
|
|
722
|
-
* Return this plugin's deploy metadata (read by the deploy
|
|
852
|
+
* Return this plugin's deploy metadata (one entry per configured instance), read by the deploy
|
|
853
|
+
* plugin. Build-time only — takes no env.
|
|
723
854
|
*
|
|
724
|
-
* @returns
|
|
855
|
+
* @returns One queue deploy descriptor per configured instance.
|
|
725
856
|
*/
|
|
726
|
-
deployManifest():
|
|
857
|
+
deployManifest(): Array<{
|
|
858
|
+
kind: "queue";
|
|
859
|
+
name: string;
|
|
860
|
+
binding: string;
|
|
861
|
+
}>;
|
|
727
862
|
};
|
|
728
863
|
/**
|
|
729
864
|
* Internal context type — own config first, no state, merged queue events.
|
|
@@ -744,7 +879,8 @@ type Ctx = PluginCtx$1<Config$1, Record<string, never>, WorkerEvents & QueueEven
|
|
|
744
879
|
//#endregion
|
|
745
880
|
//#region src/plugins/queues/index.d.ts
|
|
746
881
|
/**
|
|
747
|
-
* Standard tier — Cloudflare Queues producer + consumer dispatch
|
|
882
|
+
* Standard tier — Cloudflare Queues producer + per-instance consumer dispatch over a keyed map of
|
|
883
|
+
* instances.
|
|
748
884
|
*
|
|
749
885
|
* `events` is declared first and via `register.map<QueueEvents>` so the plugin's own events infer
|
|
750
886
|
* into the factory context; the api wiring is therefore arrow-wrapped (contextually typed).
|
|
@@ -753,15 +889,7 @@ type Ctx = PluginCtx$1<Config$1, Record<string, never>, WorkerEvents & QueueEven
|
|
|
753
889
|
*
|
|
754
890
|
* @see README.md
|
|
755
891
|
*/
|
|
756
|
-
declare const queuesPlugin: import("@moku-labs/core").PluginInstance<"queues", Config$1, Record<string, never>, {
|
|
757
|
-
send: (env: Parameters<(message: Message, env: WorkerEnv) => Promise<void>>[1], q: string, body: unknown) => Promise<void>;
|
|
758
|
-
sendBatch: (env: Parameters<(message: Message, env: WorkerEnv) => Promise<void>>[1], q: string, bodies: unknown[]) => Promise<void>;
|
|
759
|
-
consume: (batch: MessageBatch, env: Parameters<(message: Message, env: WorkerEnv) => Promise<void>>[1], _exec: ExecutionContext) => Promise<void>;
|
|
760
|
-
deployManifest: () => {
|
|
761
|
-
kind: "queue";
|
|
762
|
-
producers: string[];
|
|
763
|
-
};
|
|
764
|
-
}, {
|
|
892
|
+
declare const queuesPlugin: import("@moku-labs/core").PluginInstance<"queues", Config$1, Record<string, never>, Api, {
|
|
765
893
|
"queue:message": {
|
|
766
894
|
queue: string;
|
|
767
895
|
messageId: string;
|
|
@@ -810,28 +938,43 @@ type StorageProvider = {
|
|
|
810
938
|
list(opts?: R2ListOptions): Promise<R2Objects>;
|
|
811
939
|
};
|
|
812
940
|
declare namespace types_d_exports$5 {
|
|
813
|
-
export { StorageApi, StorageConfig, StorageCtx,
|
|
941
|
+
export { R2Instance, StorageApi, StorageBucketApi, StorageConfig, StorageCtx, StorageProvider };
|
|
814
942
|
}
|
|
815
943
|
/**
|
|
816
|
-
*
|
|
944
|
+
* A single R2 bucket instance: its base Cloudflare name, the env binding it resolves off, and an
|
|
945
|
+
* optional deploy-time upload directory.
|
|
817
946
|
*
|
|
818
947
|
* @example
|
|
819
|
-
* ```
|
|
820
|
-
* {
|
|
948
|
+
* ```typescript
|
|
949
|
+
* { name: "tracker-files", binding: "FILES" }
|
|
821
950
|
* ```
|
|
822
951
|
*/
|
|
823
|
-
type
|
|
824
|
-
/**
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
type StorageManifest = {
|
|
829
|
-
/** Discriminant identifying this as an R2 resource. */readonly kind: "r2"; /** R2 bucket binding name. */
|
|
830
|
-
readonly bucket: string; /** Directory uploaded to R2 at deploy. */
|
|
831
|
-
readonly upload: string;
|
|
952
|
+
type R2Instance = {
|
|
953
|
+
/** Base Cloudflare R2 bucket name (stage-suffixed at deploy). */name: string; /** Env binding name the bucket resolves off the per-request `env` (e.g. `env.FILES`). */
|
|
954
|
+
binding: string; /** Directory uploaded to this bucket at deploy (deploy metadata only). */
|
|
955
|
+
upload?: string; /** Marks this instance the default when more than one is configured. */
|
|
956
|
+
default?: boolean;
|
|
832
957
|
};
|
|
833
|
-
/**
|
|
834
|
-
|
|
958
|
+
/**
|
|
959
|
+
* storage plugin config — a keyed map of R2 bucket instances. The key is the stable logical id used by
|
|
960
|
+
* `app.storage.use("key")`; a single entry (or one flagged `default: true`) is the implicit default.
|
|
961
|
+
*
|
|
962
|
+
* @example
|
|
963
|
+
* ```typescript
|
|
964
|
+
* { files: { name: "tracker-files", binding: "FILES" } }
|
|
965
|
+
* ```
|
|
966
|
+
*/
|
|
967
|
+
type StorageConfig = Record<string, R2Instance>;
|
|
968
|
+
/**
|
|
969
|
+
* The env-first object surface for one R2 bucket (the methods bound to a single instance).
|
|
970
|
+
*
|
|
971
|
+
* @example
|
|
972
|
+
* ```typescript
|
|
973
|
+
* const body = await app.storage.get(env, "assets/logo.png");
|
|
974
|
+
* await app.storage.use("uploads").put(env, "avatar.png", buffer);
|
|
975
|
+
* ```
|
|
976
|
+
*/
|
|
977
|
+
type StorageBucketApi = {
|
|
835
978
|
/**
|
|
836
979
|
* Read an object; resolves null when the key is absent.
|
|
837
980
|
*
|
|
@@ -865,12 +1008,37 @@ type StorageApi = {
|
|
|
865
1008
|
* @returns The list result.
|
|
866
1009
|
*/
|
|
867
1010
|
list(env: WorkerEnv, opts?: R2ListOptions): Promise<R2Objects>;
|
|
1011
|
+
};
|
|
1012
|
+
/**
|
|
1013
|
+
* The app.storage surface — the default bucket's methods, a `use(key)` selector for the others, plus
|
|
1014
|
+
* deploy metadata.
|
|
1015
|
+
*
|
|
1016
|
+
* @example
|
|
1017
|
+
* ```typescript
|
|
1018
|
+
* const body = await app.storage.get(env, "assets/logo.png"); // default bucket
|
|
1019
|
+
* await app.storage.use("uploads").put(env, "avatar.png", buffer); // a named bucket
|
|
1020
|
+
* ```
|
|
1021
|
+
*/
|
|
1022
|
+
type StorageApi = StorageBucketApi & {
|
|
868
1023
|
/**
|
|
869
|
-
*
|
|
1024
|
+
* Select a specific R2 bucket instance by its config key.
|
|
870
1025
|
*
|
|
871
|
-
* @
|
|
1026
|
+
* @param key - The instance key (as configured under `pluginConfigs.storage`).
|
|
1027
|
+
* @returns The object surface bound to that bucket.
|
|
872
1028
|
*/
|
|
873
|
-
|
|
1029
|
+
use(key: string): StorageBucketApi;
|
|
1030
|
+
/**
|
|
1031
|
+
* Returns this plugin's own deploy metadata (one entry per configured bucket), read by the deploy
|
|
1032
|
+
* plugin. Build-time only — takes no env.
|
|
1033
|
+
*
|
|
1034
|
+
* @returns One r2 deploy descriptor per configured instance.
|
|
1035
|
+
*/
|
|
1036
|
+
deployManifest(): Array<{
|
|
1037
|
+
kind: "r2";
|
|
1038
|
+
name: string;
|
|
1039
|
+
binding: string;
|
|
1040
|
+
upload?: string;
|
|
1041
|
+
}>;
|
|
874
1042
|
};
|
|
875
1043
|
/**
|
|
876
1044
|
* Internal context type — own config first, no state, no storage events.
|
|
@@ -1002,7 +1170,7 @@ declare const createPlugin: import("@moku-labs/core").BoundCreatePluginFunction<
|
|
|
1002
1170
|
current: () => "production" | "development" | "test";
|
|
1003
1171
|
}>]>>;
|
|
1004
1172
|
/** The core-bound app factory; wrapped by {@link createApp} to bridge `config.stage`. */
|
|
1005
|
-
declare const boundCreateApp: <const ExtraPlugins extends readonly import("@moku-labs/core").AnyPluginInstance[] = readonly []>(options?: import("@moku-labs/core").CreateAppOptions<WorkerConfig, WorkerEvents, (import("@moku-labs/core").PluginInstance<"bindings", Config$
|
|
1173
|
+
declare const boundCreateApp: <const ExtraPlugins extends readonly import("@moku-labs/core").AnyPluginInstance[] = readonly []>(options?: import("@moku-labs/core").CreateAppOptions<WorkerConfig, WorkerEvents, (import("@moku-labs/core").PluginInstance<"bindings", Config$5, Record<string, never>, BindingsApi, {}> & Record<never, never>) | (import("@moku-labs/core").PluginInstance<"server", ServerConfig, ServerState, Api$3, {
|
|
1006
1174
|
"server:matched": {
|
|
1007
1175
|
path: string;
|
|
1008
1176
|
method: string;
|
|
@@ -1015,7 +1183,7 @@ declare const boundCreateApp: <const ExtraPlugins extends readonly import("@moku
|
|
|
1015
1183
|
isDev: () => boolean;
|
|
1016
1184
|
isProduction: () => boolean;
|
|
1017
1185
|
current: () => "production" | "development" | "test";
|
|
1018
|
-
}>]>> | undefined) => import("@moku-labs/core").App<WorkerConfig, WorkerEvents, (import("@moku-labs/core").PluginInstance<"bindings", Config$
|
|
1186
|
+
}>]>> | undefined) => import("@moku-labs/core").App<WorkerConfig, WorkerEvents, (import("@moku-labs/core").PluginInstance<"bindings", Config$5, Record<string, never>, BindingsApi, {}> & Record<never, never>) | (import("@moku-labs/core").PluginInstance<"server", ServerConfig, ServerState, Api$3, {
|
|
1019
1187
|
"server:matched": {
|
|
1020
1188
|
path: string;
|
|
1021
1189
|
method: string;
|
|
@@ -1041,8 +1209,11 @@ declare const boundCreateApp: <const ExtraPlugins extends readonly import("@moku
|
|
|
1041
1209
|
* that sees the consumer's chosen stage, so it mirrors `config.stage` into the stage
|
|
1042
1210
|
* plugin's level-4 `pluginConfigs` override (`WorkerConfig.stage → pluginConfigs.stage.stage`).
|
|
1043
1211
|
* When `config.stage` is omitted, the global config and the stage plugin both fall back
|
|
1044
|
-
* to their identical `"production"` default.
|
|
1045
|
-
*
|
|
1212
|
+
* to their identical `"production"` default. It ALSO wires a default workerd-safe
|
|
1213
|
+
* {@link workerSafeProcessEnv} provider into the `env` core plugin (same bridge mechanism) so
|
|
1214
|
+
* deploy/auth can read `CLOUDFLARE_API_TOKEN` and friends via `ctx.env` — without it the env plugin
|
|
1215
|
+
* has zero providers and every `ctx.env` read is undefined. See the module JSDoc above for the
|
|
1216
|
+
* full options/defaults table.
|
|
1046
1217
|
*
|
|
1047
1218
|
* @param options - The createApp options (`config`, `pluginConfigs`, `plugins`, and lifecycle callbacks).
|
|
1048
1219
|
* @returns The initialized app — every plugin's `onInit` has already run.
|
|
@@ -1050,8 +1221,9 @@ declare const boundCreateApp: <const ExtraPlugins extends readonly import("@moku
|
|
|
1050
1221
|
* ```typescript
|
|
1051
1222
|
* const app = createApp({ config: { stage: "development", name: "my-worker" } });
|
|
1052
1223
|
* app.stage.isDev(); // true — bridged from config.stage
|
|
1224
|
+
* app.env.get("CLOUDFLARE_API_TOKEN"); // read from process.env via the default env provider
|
|
1053
1225
|
* ```
|
|
1054
1226
|
*/
|
|
1055
1227
|
declare const createApp: typeof boundCreateApp;
|
|
1056
1228
|
//#endregion
|
|
1057
|
-
export { type types_d_exports as Bindings, type types_d_exports$1 as D1, type types_d_exports$2 as DurableObjects, type PluginCtx, type types_d_exports$3 as Queues, type types_d_exports$4 as Server, type StageApi, type types_d_exports$5 as Storage, type WorkerConfig, type WorkerEnv, type WorkerEvents, type WorkerPluginCtx, bindingsPlugin, createApp, createPlugin, d1Plugin, defineDurableObject, durableObjectsPlugin, endpoint, envPlugin, kvPlugin, logPlugin, queuesPlugin, serverPlugin, stagePlugin, storagePlugin };
|
|
1229
|
+
export { type types_d_exports as Bindings, type types_d_exports$1 as D1, type types_d_exports$2 as DurableObjects, type ExternalManifest, type PluginCtx, type types_d_exports$3 as Queues, type ResourceManifest, type types_d_exports$4 as Server, type StageApi, type types_d_exports$5 as Storage, type WorkerConfig, type WorkerEnv, type WorkerEvents, type WorkerPluginCtx, bindingsPlugin, cliPlugin, createApp, createPlugin, d1Plugin, defineDurableObject, deployPlugin, durableObjectsPlugin, endpoint, envPlugin, kvPlugin, logPlugin, queuesPlugin, serverPlugin, stagePlugin, storagePlugin };
|