@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-Dc0q0hIy.cjs → cli-BBO_YNVC.cjs} +1349 -546
- package/dist/{cli-DgZv5A0G.mjs → cli-D67ea3Lu.mjs} +1348 -545
- 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-VZ99IAMv.d.cts → index-Dse6wZJH.d.cts} +99 -25
- package/dist/{index-VZ99IAMv.d.mts → index-Dse6wZJH.d.mts} +99 -25
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +334 -163
- package/dist/index.d.mts +334 -163
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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
|
|
|
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,74 @@ 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. `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.
|
|
725
858
|
*/
|
|
726
|
-
deployManifest():
|
|
859
|
+
deployManifest(): Array<{
|
|
860
|
+
kind: "queue";
|
|
861
|
+
name: string;
|
|
862
|
+
binding: string;
|
|
863
|
+
consumer?: boolean;
|
|
864
|
+
}>;
|
|
727
865
|
};
|
|
728
866
|
/**
|
|
729
867
|
* Internal context type — own config first, no state, merged queue events.
|
|
@@ -744,7 +882,8 @@ type Ctx = PluginCtx$1<Config$1, Record<string, never>, WorkerEvents & QueueEven
|
|
|
744
882
|
//#endregion
|
|
745
883
|
//#region src/plugins/queues/index.d.ts
|
|
746
884
|
/**
|
|
747
|
-
* Standard tier — Cloudflare Queues producer + consumer dispatch
|
|
885
|
+
* Standard tier — Cloudflare Queues producer + per-instance consumer dispatch over a keyed map of
|
|
886
|
+
* instances.
|
|
748
887
|
*
|
|
749
888
|
* `events` is declared first and via `register.map<QueueEvents>` so the plugin's own events infer
|
|
750
889
|
* into the factory context; the api wiring is therefore arrow-wrapped (contextually typed).
|
|
@@ -753,15 +892,7 @@ type Ctx = PluginCtx$1<Config$1, Record<string, never>, WorkerEvents & QueueEven
|
|
|
753
892
|
*
|
|
754
893
|
* @see README.md
|
|
755
894
|
*/
|
|
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
|
-
}, {
|
|
895
|
+
declare const queuesPlugin: import("@moku-labs/core").PluginInstance<"queues", Config$1, Record<string, never>, Api, {
|
|
765
896
|
"queue:message": {
|
|
766
897
|
queue: string;
|
|
767
898
|
messageId: string;
|
|
@@ -810,28 +941,43 @@ type StorageProvider = {
|
|
|
810
941
|
list(opts?: R2ListOptions): Promise<R2Objects>;
|
|
811
942
|
};
|
|
812
943
|
declare namespace types_d_exports$5 {
|
|
813
|
-
export { StorageApi, StorageConfig, StorageCtx,
|
|
944
|
+
export { R2Instance, StorageApi, StorageBucketApi, StorageConfig, StorageCtx, StorageProvider };
|
|
814
945
|
}
|
|
815
946
|
/**
|
|
816
|
-
*
|
|
947
|
+
* A single R2 bucket instance: its base Cloudflare name, the env binding it resolves off, and an
|
|
948
|
+
* optional deploy-time upload directory.
|
|
817
949
|
*
|
|
818
950
|
* @example
|
|
819
|
-
* ```
|
|
820
|
-
* {
|
|
951
|
+
* ```typescript
|
|
952
|
+
* { name: "tracker-files", binding: "FILES" }
|
|
821
953
|
* ```
|
|
822
954
|
*/
|
|
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;
|
|
955
|
+
type R2Instance = {
|
|
956
|
+
/** 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`). */
|
|
957
|
+
binding: string; /** Directory uploaded to this bucket at deploy (deploy metadata only). */
|
|
958
|
+
upload?: string; /** Marks this instance the default when more than one is configured. */
|
|
959
|
+
default?: boolean;
|
|
832
960
|
};
|
|
833
|
-
/**
|
|
834
|
-
|
|
961
|
+
/**
|
|
962
|
+
* storage plugin config — a keyed map of R2 bucket instances. The key is the stable logical id used by
|
|
963
|
+
* `app.storage.use("key")`; a single entry (or one flagged `default: true`) is the implicit default.
|
|
964
|
+
*
|
|
965
|
+
* @example
|
|
966
|
+
* ```typescript
|
|
967
|
+
* { files: { name: "tracker-files", binding: "FILES" } }
|
|
968
|
+
* ```
|
|
969
|
+
*/
|
|
970
|
+
type StorageConfig = Record<string, R2Instance>;
|
|
971
|
+
/**
|
|
972
|
+
* The env-first object surface for one R2 bucket (the methods bound to a single instance).
|
|
973
|
+
*
|
|
974
|
+
* @example
|
|
975
|
+
* ```typescript
|
|
976
|
+
* const body = await app.storage.get(env, "assets/logo.png");
|
|
977
|
+
* await app.storage.use("uploads").put(env, "avatar.png", buffer);
|
|
978
|
+
* ```
|
|
979
|
+
*/
|
|
980
|
+
type StorageBucketApi = {
|
|
835
981
|
/**
|
|
836
982
|
* Read an object; resolves null when the key is absent.
|
|
837
983
|
*
|
|
@@ -865,12 +1011,37 @@ type StorageApi = {
|
|
|
865
1011
|
* @returns The list result.
|
|
866
1012
|
*/
|
|
867
1013
|
list(env: WorkerEnv, opts?: R2ListOptions): Promise<R2Objects>;
|
|
1014
|
+
};
|
|
1015
|
+
/**
|
|
1016
|
+
* The app.storage surface — the default bucket's methods, a `use(key)` selector for the others, plus
|
|
1017
|
+
* deploy metadata.
|
|
1018
|
+
*
|
|
1019
|
+
* @example
|
|
1020
|
+
* ```typescript
|
|
1021
|
+
* const body = await app.storage.get(env, "assets/logo.png"); // default bucket
|
|
1022
|
+
* await app.storage.use("uploads").put(env, "avatar.png", buffer); // a named bucket
|
|
1023
|
+
* ```
|
|
1024
|
+
*/
|
|
1025
|
+
type StorageApi = StorageBucketApi & {
|
|
868
1026
|
/**
|
|
869
|
-
*
|
|
1027
|
+
* Select a specific R2 bucket instance by its config key.
|
|
870
1028
|
*
|
|
871
|
-
* @
|
|
1029
|
+
* @param key - The instance key (as configured under `pluginConfigs.storage`).
|
|
1030
|
+
* @returns The object surface bound to that bucket.
|
|
872
1031
|
*/
|
|
873
|
-
|
|
1032
|
+
use(key: string): StorageBucketApi;
|
|
1033
|
+
/**
|
|
1034
|
+
* Returns this plugin's own deploy metadata (one entry per configured bucket), read by the deploy
|
|
1035
|
+
* plugin. Build-time only — takes no env.
|
|
1036
|
+
*
|
|
1037
|
+
* @returns One r2 deploy descriptor per configured instance.
|
|
1038
|
+
*/
|
|
1039
|
+
deployManifest(): Array<{
|
|
1040
|
+
kind: "r2";
|
|
1041
|
+
name: string;
|
|
1042
|
+
binding: string;
|
|
1043
|
+
upload?: string;
|
|
1044
|
+
}>;
|
|
874
1045
|
};
|
|
875
1046
|
/**
|
|
876
1047
|
* Internal context type — own config first, no state, no storage events.
|
|
@@ -1002,7 +1173,7 @@ declare const createPlugin: import("@moku-labs/core").BoundCreatePluginFunction<
|
|
|
1002
1173
|
current: () => "production" | "development" | "test";
|
|
1003
1174
|
}>]>>;
|
|
1004
1175
|
/** 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$
|
|
1176
|
+
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
1177
|
"server:matched": {
|
|
1007
1178
|
path: string;
|
|
1008
1179
|
method: string;
|
|
@@ -1015,7 +1186,7 @@ declare const boundCreateApp: <const ExtraPlugins extends readonly import("@moku
|
|
|
1015
1186
|
isDev: () => boolean;
|
|
1016
1187
|
isProduction: () => boolean;
|
|
1017
1188
|
current: () => "production" | "development" | "test";
|
|
1018
|
-
}>]>> | undefined) => import("@moku-labs/core").App<WorkerConfig, WorkerEvents, (import("@moku-labs/core").PluginInstance<"bindings", Config$
|
|
1189
|
+
}>]>> | 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
1190
|
"server:matched": {
|
|
1020
1191
|
path: string;
|
|
1021
1192
|
method: string;
|