@moku-labs/worker 0.2.0 → 0.2.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.
@@ -0,0 +1,63 @@
1
+ import { PluginCtx } from "@moku-labs/core";
2
+
3
+ //#region src/config.d.ts
4
+ /** Per-request Cloudflare bindings object (env). Framework-level shared type. */
5
+ type WorkerEnv = Record<string, unknown>;
6
+ /** Global framework config — flat, with complete defaults. */
7
+ type WorkerConfig = {
8
+ stage: "production" | "development" | "test";
9
+ name: string;
10
+ compatibilityDate: string;
11
+ };
12
+ /** Global framework events — declared once, visible to every plugin. */
13
+ type WorkerEvents = {
14
+ "request:start": {
15
+ method: string;
16
+ path: string;
17
+ requestId: string;
18
+ };
19
+ "request:end": {
20
+ method: string;
21
+ path: string;
22
+ status: number;
23
+ ms: number;
24
+ };
25
+ "deploy:phase": {
26
+ phase: string;
27
+ detail?: string;
28
+ };
29
+ "deploy:complete": {
30
+ url: string;
31
+ };
32
+ "provision:resource": {
33
+ kind: "kv" | "r2" | "d1" | "queue" | "do";
34
+ name: string;
35
+ };
36
+ };
37
+ /**
38
+ * Worker-bound plugin context for Layer-3 consumer plugins. Aliases the core
39
+ * {@link PluginCtx} with the global {@link WorkerEvents} pre-merged into the event
40
+ * map, so a consumer plugin types its own `config`/`state`/`emit` by passing only
41
+ * its OWN event map — never hand-merging `WorkerEvents`, and never importing from
42
+ * `@moku-labs/core` (a Layer-1 boundary the spec validator flags for consumers).
43
+ *
44
+ * A plugin that resolves sibling plugins also needs a `require` field; intersect the
45
+ * public `Server.RequireFn` for it, exactly as this framework's own plugins do. When
46
+ * you need the unaliased shape (e.g. a different global event map), use the raw
47
+ * re-exported {@link PluginCtx} instead.
48
+ *
49
+ * @template Config - This plugin's own flat configuration object.
50
+ * @template State - This plugin's mutable state (use `Record<string, never>` when stateless).
51
+ * @template Events - This plugin's own event map, merged on top of {@link WorkerEvents}; defaults to none.
52
+ * @example
53
+ * ```typescript
54
+ * import type { Server, WorkerPluginCtx } from "@moku-labs/worker";
55
+ * type MyEvents = { "my:done": { id: string } };
56
+ * export type MyCtx = WorkerPluginCtx<MyConfig, Record<string, never>, MyEvents> & {
57
+ * require: Server.RequireFn;
58
+ * };
59
+ * ```
60
+ */
61
+ type WorkerPluginCtx<Config, State, Events extends Record<string, unknown> = Record<never, never>> = PluginCtx<Config, State, WorkerEvents & Events>;
62
+ //#endregion
63
+ export { WorkerPluginCtx as i, WorkerEnv as n, WorkerEvents as r, WorkerConfig as t };
@@ -0,0 +1,63 @@
1
+ import { PluginCtx } from "@moku-labs/core";
2
+
3
+ //#region src/config.d.ts
4
+ /** Per-request Cloudflare bindings object (env). Framework-level shared type. */
5
+ type WorkerEnv = Record<string, unknown>;
6
+ /** Global framework config — flat, with complete defaults. */
7
+ type WorkerConfig = {
8
+ stage: "production" | "development" | "test";
9
+ name: string;
10
+ compatibilityDate: string;
11
+ };
12
+ /** Global framework events — declared once, visible to every plugin. */
13
+ type WorkerEvents = {
14
+ "request:start": {
15
+ method: string;
16
+ path: string;
17
+ requestId: string;
18
+ };
19
+ "request:end": {
20
+ method: string;
21
+ path: string;
22
+ status: number;
23
+ ms: number;
24
+ };
25
+ "deploy:phase": {
26
+ phase: string;
27
+ detail?: string;
28
+ };
29
+ "deploy:complete": {
30
+ url: string;
31
+ };
32
+ "provision:resource": {
33
+ kind: "kv" | "r2" | "d1" | "queue" | "do";
34
+ name: string;
35
+ };
36
+ };
37
+ /**
38
+ * Worker-bound plugin context for Layer-3 consumer plugins. Aliases the core
39
+ * {@link PluginCtx} with the global {@link WorkerEvents} pre-merged into the event
40
+ * map, so a consumer plugin types its own `config`/`state`/`emit` by passing only
41
+ * its OWN event map — never hand-merging `WorkerEvents`, and never importing from
42
+ * `@moku-labs/core` (a Layer-1 boundary the spec validator flags for consumers).
43
+ *
44
+ * A plugin that resolves sibling plugins also needs a `require` field; intersect the
45
+ * public `Server.RequireFn` for it, exactly as this framework's own plugins do. When
46
+ * you need the unaliased shape (e.g. a different global event map), use the raw
47
+ * re-exported {@link PluginCtx} instead.
48
+ *
49
+ * @template Config - This plugin's own flat configuration object.
50
+ * @template State - This plugin's mutable state (use `Record<string, never>` when stateless).
51
+ * @template Events - This plugin's own event map, merged on top of {@link WorkerEvents}; defaults to none.
52
+ * @example
53
+ * ```typescript
54
+ * import type { Server, WorkerPluginCtx } from "@moku-labs/worker";
55
+ * type MyEvents = { "my:done": { id: string } };
56
+ * export type MyCtx = WorkerPluginCtx<MyConfig, Record<string, never>, MyEvents> & {
57
+ * require: Server.RequireFn;
58
+ * };
59
+ * ```
60
+ */
61
+ type WorkerPluginCtx<Config, State, Events extends Record<string, unknown> = Record<never, never>> = PluginCtx<Config, State, WorkerEvents & Events>;
62
+ //#endregion
63
+ export { WorkerPluginCtx as i, WorkerEnv as n, WorkerEvents as r, WorkerConfig as t };
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { n as WorkerEnv, r as WorkerEvents, t as WorkerConfig } from "./config-AjH57AmD.cjs";
2
- import { PluginCtx, PluginInstance } from "@moku-labs/core";
1
+ import { i as WorkerPluginCtx, n as WorkerEnv, r as WorkerEvents, t as WorkerConfig } from "./config-Bj3GUJT_.cjs";
2
+ import { PluginCtx, PluginCtx as PluginCtx$1, PluginInstance } from "@moku-labs/core";
3
3
  import { envPlugin, logPlugin } from "@moku-labs/common";
4
4
 
5
5
  //#region \0rolldown/runtime.js
@@ -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<Config$4, Record<string, never>, WorkerEvents>;
53
+ type Context = PluginCtx$1<Config$4, Record<string, never>, WorkerEvents>;
54
54
  //#endregion
55
55
  //#region src/plugins/bindings/index.d.ts
56
56
  /**
@@ -186,7 +186,7 @@ type ServerEvents = {
186
186
  };
187
187
  };
188
188
  /** Full server plugin context (own config + state + merged events + cross-plugin reach). */
189
- type ServerCtx = PluginCtx<ServerConfig, ServerState, WorkerEvents & ServerEvents> & {
189
+ type ServerCtx = PluginCtx$1<ServerConfig, ServerState, WorkerEvents & ServerEvents> & {
190
190
  /** Cross-plugin require threaded into each RequestContext. */require: RequireFn; /** Presence check for an optional plugin. */
191
191
  has: (name: string) => boolean;
192
192
  };
@@ -417,7 +417,7 @@ type Api$2 = {
417
417
  * Internal context type — own config first, no state, no d1-local events.
418
418
  * Intersected with a narrow `require` typed to the one dependency d1 resolves.
419
419
  */
420
- type D1Ctx = PluginCtx<Config$3, Record<string, never>, WorkerEvents> & {
420
+ type D1Ctx = PluginCtx$1<Config$3, Record<string, never>, WorkerEvents> & {
421
421
  /**
422
422
  * Resolve a dependency plugin's api. d1 only ever resolves `bindingsPlugin`.
423
423
  *
@@ -493,7 +493,7 @@ type Api$1 = {
493
493
  * Internal context type — own config first, no state, no DO events.
494
494
  * Intersected with a narrow `require` typed to the one dependency durableObjects resolves.
495
495
  */
496
- type Ctx$1 = PluginCtx<Config$2, Record<string, never>, WorkerEvents> & {
496
+ type Ctx$1 = PluginCtx$1<Config$2, Record<string, never>, WorkerEvents> & {
497
497
  /**
498
498
  * Resolve a dependency plugin's api. durableObjects only ever resolves `bindingsPlugin`.
499
499
  *
@@ -732,7 +732,7 @@ type Api = {
732
732
  * (core's "advanced composition" note), typed to the one dependency queues resolves —
733
733
  * `require(bindingsPlugin)` → `BindingsApi`. Core does not export `RequireFunction`.
734
734
  */
735
- type Ctx = PluginCtx<Config$1, Record<string, never>, WorkerEvents & QueueEvents> & {
735
+ type Ctx = PluginCtx$1<Config$1, Record<string, never>, WorkerEvents & QueueEvents> & {
736
736
  /**
737
737
  * Resolve a dependency plugin's api. queues only ever resolves `bindingsPlugin`.
738
738
  *
@@ -878,7 +878,7 @@ type StorageApi = {
878
878
  * resolves — mirrors the kv/api.ts pattern (PluginCtx has no `require` by
879
879
  * default; core does not export a generic RequireFunction).
880
880
  */
881
- type StorageCtx = PluginCtx<StorageConfig, Record<string, never>, WorkerEvents> & {
881
+ type StorageCtx = PluginCtx$1<StorageConfig, Record<string, never>, WorkerEvents> & {
882
882
  /**
883
883
  * Resolve a dependency plugin's api. storage only ever resolves bindingsPlugin.
884
884
  *
@@ -1028,4 +1028,4 @@ declare const createApp: <const ExtraPlugins extends readonly import("@moku-labs
1028
1028
  current: () => "production" | "development" | "test";
1029
1029
  }>]>>;
1030
1030
  //#endregion
1031
- export { type types_d_exports as Bindings, type types_d_exports$1 as D1, type types_d_exports$2 as DurableObjects, 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, bindingsPlugin, createApp, createPlugin, d1Plugin, defineDurableObject, durableObjectsPlugin, endpoint, envPlugin, kvPlugin, logPlugin, queuesPlugin, serverPlugin, stagePlugin, storagePlugin };
1031
+ 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 };
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { n as WorkerEnv, r as WorkerEvents, t as WorkerConfig } from "./config-AjH57AmD.mjs";
1
+ import { i as WorkerPluginCtx, n as WorkerEnv, r as WorkerEvents, t as WorkerConfig } from "./config-Bj3GUJT_.mjs";
2
2
  import { envPlugin, logPlugin } from "@moku-labs/common";
3
- import { PluginCtx, PluginInstance } from "@moku-labs/core";
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 {
@@ -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<Config$4, Record<string, never>, WorkerEvents>;
53
+ type Context = PluginCtx$1<Config$4, Record<string, never>, WorkerEvents>;
54
54
  //#endregion
55
55
  //#region src/plugins/bindings/index.d.ts
56
56
  /**
@@ -186,7 +186,7 @@ type ServerEvents = {
186
186
  };
187
187
  };
188
188
  /** Full server plugin context (own config + state + merged events + cross-plugin reach). */
189
- type ServerCtx = PluginCtx<ServerConfig, ServerState, WorkerEvents & ServerEvents> & {
189
+ type ServerCtx = PluginCtx$1<ServerConfig, ServerState, WorkerEvents & ServerEvents> & {
190
190
  /** Cross-plugin require threaded into each RequestContext. */require: RequireFn; /** Presence check for an optional plugin. */
191
191
  has: (name: string) => boolean;
192
192
  };
@@ -417,7 +417,7 @@ type Api$2 = {
417
417
  * Internal context type — own config first, no state, no d1-local events.
418
418
  * Intersected with a narrow `require` typed to the one dependency d1 resolves.
419
419
  */
420
- type D1Ctx = PluginCtx<Config$3, Record<string, never>, WorkerEvents> & {
420
+ type D1Ctx = PluginCtx$1<Config$3, Record<string, never>, WorkerEvents> & {
421
421
  /**
422
422
  * Resolve a dependency plugin's api. d1 only ever resolves `bindingsPlugin`.
423
423
  *
@@ -493,7 +493,7 @@ type Api$1 = {
493
493
  * Internal context type — own config first, no state, no DO events.
494
494
  * Intersected with a narrow `require` typed to the one dependency durableObjects resolves.
495
495
  */
496
- type Ctx$1 = PluginCtx<Config$2, Record<string, never>, WorkerEvents> & {
496
+ type Ctx$1 = PluginCtx$1<Config$2, Record<string, never>, WorkerEvents> & {
497
497
  /**
498
498
  * Resolve a dependency plugin's api. durableObjects only ever resolves `bindingsPlugin`.
499
499
  *
@@ -732,7 +732,7 @@ type Api = {
732
732
  * (core's "advanced composition" note), typed to the one dependency queues resolves —
733
733
  * `require(bindingsPlugin)` → `BindingsApi`. Core does not export `RequireFunction`.
734
734
  */
735
- type Ctx = PluginCtx<Config$1, Record<string, never>, WorkerEvents & QueueEvents> & {
735
+ type Ctx = PluginCtx$1<Config$1, Record<string, never>, WorkerEvents & QueueEvents> & {
736
736
  /**
737
737
  * Resolve a dependency plugin's api. queues only ever resolves `bindingsPlugin`.
738
738
  *
@@ -878,7 +878,7 @@ type StorageApi = {
878
878
  * resolves — mirrors the kv/api.ts pattern (PluginCtx has no `require` by
879
879
  * default; core does not export a generic RequireFunction).
880
880
  */
881
- type StorageCtx = PluginCtx<StorageConfig, Record<string, never>, WorkerEvents> & {
881
+ type StorageCtx = PluginCtx$1<StorageConfig, Record<string, never>, WorkerEvents> & {
882
882
  /**
883
883
  * Resolve a dependency plugin's api. storage only ever resolves bindingsPlugin.
884
884
  *
@@ -1028,4 +1028,4 @@ declare const createApp: <const ExtraPlugins extends readonly import("@moku-labs
1028
1028
  current: () => "production" | "development" | "test";
1029
1029
  }>]>>;
1030
1030
  //#endregion
1031
- export { type types_d_exports as Bindings, type types_d_exports$1 as D1, type types_d_exports$2 as DurableObjects, 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, bindingsPlugin, createApp, createPlugin, d1Plugin, defineDurableObject, durableObjectsPlugin, endpoint, envPlugin, kvPlugin, logPlugin, queuesPlugin, serverPlugin, stagePlugin, storagePlugin };
1031
+ 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moku-labs/worker",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Cloudflare Worker framework for Moku — Durable Objects, Queues, R2, D1, and KV plugins that compose with Moku Web.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,36 +0,0 @@
1
- //#region src/config.d.ts
2
- /** Per-request Cloudflare bindings object (env). Framework-level shared type. */
3
- type WorkerEnv = Record<string, unknown>;
4
- /** Global framework config — flat, with complete defaults. */
5
- type WorkerConfig = {
6
- stage: "production" | "development" | "test";
7
- name: string;
8
- compatibilityDate: string;
9
- };
10
- /** Global framework events — declared once, visible to every plugin. */
11
- type WorkerEvents = {
12
- "request:start": {
13
- method: string;
14
- path: string;
15
- requestId: string;
16
- };
17
- "request:end": {
18
- method: string;
19
- path: string;
20
- status: number;
21
- ms: number;
22
- };
23
- "deploy:phase": {
24
- phase: string;
25
- detail?: string;
26
- };
27
- "deploy:complete": {
28
- url: string;
29
- };
30
- "provision:resource": {
31
- kind: "kv" | "r2" | "d1" | "queue" | "do";
32
- name: string;
33
- };
34
- };
35
- //#endregion
36
- export { WorkerEnv as n, WorkerEvents as r, WorkerConfig as t };
@@ -1,36 +0,0 @@
1
- //#region src/config.d.ts
2
- /** Per-request Cloudflare bindings object (env). Framework-level shared type. */
3
- type WorkerEnv = Record<string, unknown>;
4
- /** Global framework config — flat, with complete defaults. */
5
- type WorkerConfig = {
6
- stage: "production" | "development" | "test";
7
- name: string;
8
- compatibilityDate: string;
9
- };
10
- /** Global framework events — declared once, visible to every plugin. */
11
- type WorkerEvents = {
12
- "request:start": {
13
- method: string;
14
- path: string;
15
- requestId: string;
16
- };
17
- "request:end": {
18
- method: string;
19
- path: string;
20
- status: number;
21
- ms: number;
22
- };
23
- "deploy:phase": {
24
- phase: string;
25
- detail?: string;
26
- };
27
- "deploy:complete": {
28
- url: string;
29
- };
30
- "provision:resource": {
31
- kind: "kv" | "r2" | "d1" | "queue" | "do";
32
- name: string;
33
- };
34
- };
35
- //#endregion
36
- export { WorkerEnv as n, WorkerEvents as r, WorkerConfig as t };