@rytejs/core 0.7.0 → 0.8.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/dist/executor/index.d.cts +3 -3
- package/dist/executor/index.d.ts +3 -3
- package/dist/index.cjs +118 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +115 -1
- package/dist/index.js.map +1 -1
- package/dist/{plugin-DHN3Pk52.d.ts → plugin-CIVHyBaZ.d.ts} +69 -13
- package/dist/{plugin-DHS8yUmS.d.cts → plugin-CQUbAdxj.d.cts} +69 -13
- package/dist/reactor/index.d.cts +2 -2
- package/dist/reactor/index.d.ts +2 -2
- package/dist/{snapshot-D5iZubCz.d.cts → snapshot-6pxxtOjB.d.cts} +26 -1
- package/dist/{snapshot-D5iZubCz.d.ts → snapshot-6pxxtOjB.d.ts} +26 -1
- package/dist/store/index.d.cts +3 -3
- package/dist/store/index.d.ts +3 -3
- package/dist/{types-BtMTMoOZ.d.cts → types-BuFyzP66.d.cts} +1 -1
- package/dist/{types-C0nlrs5c.d.ts → types-D41DR3xh.d.ts} +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,33 @@
|
|
|
1
|
-
import { W as WorkflowConfig,
|
|
1
|
+
import { W as WorkflowConfig, a as WorkflowSnapshot, c as ClientWorkflow, V as ValidationError, S as StateNames, l as StateData, n as WorkflowOf, m as Workflow, o as WorkflowConfigInput, C as CommandNames, f as CommandPayload, k as EventNames, j as EventData, E as ErrorCodes, i as ErrorData, e as Command, D as DispatchResult, P as PipelineError } from './snapshot-6pxxtOjB.js';
|
|
2
2
|
import { ZodType, z } from 'zod';
|
|
3
3
|
|
|
4
|
+
declare const SERVER_BRAND: unique symbol;
|
|
5
|
+
/** Brands a Zod schema type as server-only at the TypeScript level. */
|
|
6
|
+
type Server<T extends ZodType> = T & {
|
|
7
|
+
readonly [SERVER_BRAND]: true;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Marks a Zod schema as server-only. Fields wrapped in `server()` are stripped
|
|
11
|
+
* from client snapshots and excluded from client TypeScript types.
|
|
12
|
+
*
|
|
13
|
+
* Returns a new schema reference — the original is not mutated, so shared
|
|
14
|
+
* schemas can safely be used in both server and non-server positions.
|
|
15
|
+
*/
|
|
16
|
+
declare function server<T extends ZodType>(schema: T): Server<T>;
|
|
17
|
+
/** Returns `true` if the schema was wrapped with `server()`. */
|
|
18
|
+
declare function isServerField(schema: ZodType): boolean;
|
|
19
|
+
type ServerBranded = {
|
|
20
|
+
readonly [SERVER_BRAND]: true;
|
|
21
|
+
};
|
|
22
|
+
/** Computes the client-safe inferred type from a Zod schema by filtering out server-branded fields. */
|
|
23
|
+
type ClientInfer<T extends ZodType> = T extends {
|
|
24
|
+
shape: infer Shape extends Record<string, ZodType>;
|
|
25
|
+
} ? {
|
|
26
|
+
[K in keyof Shape as Shape[K] extends ServerBranded ? never : K]: Shape[K] extends {
|
|
27
|
+
shape: Record<string, ZodType>;
|
|
28
|
+
} ? ClientInfer<Shape[K]> : z.infer<Shape[K]>;
|
|
29
|
+
} : z.infer<T>;
|
|
30
|
+
|
|
4
31
|
/**
|
|
5
32
|
* The result of {@link defineWorkflow} — holds schemas and creates workflow instances.
|
|
6
33
|
*/
|
|
@@ -82,6 +109,36 @@ interface WorkflowDefinition<TConfig extends WorkflowConfig = WorkflowConfig> {
|
|
|
82
109
|
ok: false;
|
|
83
110
|
error: ValidationError;
|
|
84
111
|
};
|
|
112
|
+
/**
|
|
113
|
+
* Serializes a workflow into a client-safe snapshot with server-only fields stripped.
|
|
114
|
+
*
|
|
115
|
+
* @param workflow - The workflow instance to serialize
|
|
116
|
+
* @returns A {@link WorkflowSnapshot} with server-only fields removed from `data`
|
|
117
|
+
*/
|
|
118
|
+
serializeForClient(workflow: Workflow<TConfig>): WorkflowSnapshot<TConfig>;
|
|
119
|
+
/**
|
|
120
|
+
* Returns a client-safe projection of this definition.
|
|
121
|
+
* Memoized — returns the same instance on repeated calls.
|
|
122
|
+
*/
|
|
123
|
+
forClient(): ClientWorkflowDefinition<TConfig>;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* A client-safe projection of a workflow definition.
|
|
127
|
+
* State schemas have server-only fields removed. Returned by {@link WorkflowDefinition.forClient}.
|
|
128
|
+
*/
|
|
129
|
+
interface ClientWorkflowDefinition<TConfig extends WorkflowConfig = WorkflowConfig> {
|
|
130
|
+
/** The raw Zod schema configuration. */
|
|
131
|
+
readonly config: TConfig;
|
|
132
|
+
readonly name: string;
|
|
133
|
+
getStateSchema(stateName: string): ZodType;
|
|
134
|
+
hasState(stateName: string): boolean;
|
|
135
|
+
deserialize(snapshot: WorkflowSnapshot<TConfig>): {
|
|
136
|
+
ok: true;
|
|
137
|
+
workflow: ClientWorkflow<TConfig>;
|
|
138
|
+
} | {
|
|
139
|
+
ok: false;
|
|
140
|
+
error: ValidationError;
|
|
141
|
+
};
|
|
85
142
|
}
|
|
86
143
|
/**
|
|
87
144
|
* Creates a workflow definition from a name and Zod schema configuration.
|
|
@@ -105,6 +162,11 @@ declare function defineWorkflow<const TConfig extends WorkflowConfigInput>(name:
|
|
|
105
162
|
[K in keyof TConfig["errors"]]: z.infer<TConfig["errors"][K]>;
|
|
106
163
|
};
|
|
107
164
|
};
|
|
165
|
+
_clientResolved: {
|
|
166
|
+
states: {
|
|
167
|
+
[K in keyof TConfig["states"]]: ClientInfer<TConfig["states"][K]>;
|
|
168
|
+
};
|
|
169
|
+
};
|
|
108
170
|
}>;
|
|
109
171
|
|
|
110
172
|
/** A phantom-typed key for type-safe middleware state storage via {@link Context.set} and {@link Context.get}. */
|
|
@@ -253,14 +315,8 @@ declare class WorkflowRouter<TConfig extends WorkflowConfig, TDeps = {}> {
|
|
|
253
315
|
* @param event - The lifecycle event name
|
|
254
316
|
* @param callback - The callback to invoke when the event fires
|
|
255
317
|
*/
|
|
256
|
-
on(event: "dispatch:start", callback: (workflow: Workflow<TConfig>, command:
|
|
257
|
-
|
|
258
|
-
payload: unknown;
|
|
259
|
-
}) => void | Promise<void>): this;
|
|
260
|
-
on(event: "dispatch:end", callback: (workflow: Workflow<TConfig>, command: {
|
|
261
|
-
type: CommandNames<TConfig>;
|
|
262
|
-
payload: unknown;
|
|
263
|
-
}, result: DispatchResult<TConfig>) => void | Promise<void>): this;
|
|
318
|
+
on(event: "dispatch:start", callback: (workflow: Workflow<TConfig>, command: Command<TConfig>) => void | Promise<void>): this;
|
|
319
|
+
on(event: "dispatch:end", callback: (workflow: Workflow<TConfig>, command: Command<TConfig>, result: DispatchResult<TConfig>) => void | Promise<void>): this;
|
|
264
320
|
on(event: "pipeline:start", callback: (ctx: ReadonlyContext<TConfig, TDeps>) => void | Promise<void>): this;
|
|
265
321
|
on(event: "pipeline:end", callback: (ctx: ReadonlyContext<TConfig, TDeps>, result: DispatchResult<TConfig>) => void | Promise<void>): this;
|
|
266
322
|
on(event: "transition", callback: (from: StateNames<TConfig>, to: StateNames<TConfig>, workflow: Workflow<TConfig>) => void | Promise<void>): this;
|
|
@@ -292,9 +348,9 @@ declare class WorkflowRouter<TConfig extends WorkflowConfig, TDeps = {}> {
|
|
|
292
348
|
* @param command - The command with its type and payload
|
|
293
349
|
* @returns A {@link DispatchResult} indicating success or failure with the updated workflow and events
|
|
294
350
|
*/
|
|
295
|
-
dispatch(workflow: Workflow<TConfig>, command: {
|
|
296
|
-
type:
|
|
297
|
-
payload:
|
|
351
|
+
dispatch<C extends CommandNames<TConfig>>(workflow: Workflow<TConfig>, command: {
|
|
352
|
+
type: C;
|
|
353
|
+
payload: CommandPayload<TConfig, C>;
|
|
298
354
|
}): Promise<DispatchResult<TConfig>>;
|
|
299
355
|
private executePipeline;
|
|
300
356
|
}
|
|
@@ -336,4 +392,4 @@ declare function defineGenericPlugin(fn: (router: WorkflowRouter<any, any>) => v
|
|
|
336
392
|
*/
|
|
337
393
|
declare function isPlugin(value: unknown): value is Plugin<WorkflowConfig, unknown>;
|
|
338
394
|
|
|
339
|
-
export { type Context as C, type GenericPlugin as G, type Plugin as P, type ReadonlyContext as R, type WorkflowDefinition as W, type
|
|
395
|
+
export { type Context as C, type GenericPlugin as G, type Plugin as P, type ReadonlyContext as R, type Server as S, type WorkflowDefinition as W, type ClientWorkflowDefinition as a, type ContextKey as b, type RouterOptions as c, WorkflowRouter as d, createKey as e, defineGenericPlugin as f, definePlugin as g, defineWorkflow as h, isPlugin as i, isServerField as j, server as s };
|
|
@@ -1,6 +1,33 @@
|
|
|
1
|
-
import { W as WorkflowConfig,
|
|
1
|
+
import { W as WorkflowConfig, a as WorkflowSnapshot, c as ClientWorkflow, V as ValidationError, S as StateNames, l as StateData, n as WorkflowOf, m as Workflow, o as WorkflowConfigInput, C as CommandNames, f as CommandPayload, k as EventNames, j as EventData, E as ErrorCodes, i as ErrorData, e as Command, D as DispatchResult, P as PipelineError } from './snapshot-6pxxtOjB.cjs';
|
|
2
2
|
import { ZodType, z } from 'zod';
|
|
3
3
|
|
|
4
|
+
declare const SERVER_BRAND: unique symbol;
|
|
5
|
+
/** Brands a Zod schema type as server-only at the TypeScript level. */
|
|
6
|
+
type Server<T extends ZodType> = T & {
|
|
7
|
+
readonly [SERVER_BRAND]: true;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Marks a Zod schema as server-only. Fields wrapped in `server()` are stripped
|
|
11
|
+
* from client snapshots and excluded from client TypeScript types.
|
|
12
|
+
*
|
|
13
|
+
* Returns a new schema reference — the original is not mutated, so shared
|
|
14
|
+
* schemas can safely be used in both server and non-server positions.
|
|
15
|
+
*/
|
|
16
|
+
declare function server<T extends ZodType>(schema: T): Server<T>;
|
|
17
|
+
/** Returns `true` if the schema was wrapped with `server()`. */
|
|
18
|
+
declare function isServerField(schema: ZodType): boolean;
|
|
19
|
+
type ServerBranded = {
|
|
20
|
+
readonly [SERVER_BRAND]: true;
|
|
21
|
+
};
|
|
22
|
+
/** Computes the client-safe inferred type from a Zod schema by filtering out server-branded fields. */
|
|
23
|
+
type ClientInfer<T extends ZodType> = T extends {
|
|
24
|
+
shape: infer Shape extends Record<string, ZodType>;
|
|
25
|
+
} ? {
|
|
26
|
+
[K in keyof Shape as Shape[K] extends ServerBranded ? never : K]: Shape[K] extends {
|
|
27
|
+
shape: Record<string, ZodType>;
|
|
28
|
+
} ? ClientInfer<Shape[K]> : z.infer<Shape[K]>;
|
|
29
|
+
} : z.infer<T>;
|
|
30
|
+
|
|
4
31
|
/**
|
|
5
32
|
* The result of {@link defineWorkflow} — holds schemas and creates workflow instances.
|
|
6
33
|
*/
|
|
@@ -82,6 +109,36 @@ interface WorkflowDefinition<TConfig extends WorkflowConfig = WorkflowConfig> {
|
|
|
82
109
|
ok: false;
|
|
83
110
|
error: ValidationError;
|
|
84
111
|
};
|
|
112
|
+
/**
|
|
113
|
+
* Serializes a workflow into a client-safe snapshot with server-only fields stripped.
|
|
114
|
+
*
|
|
115
|
+
* @param workflow - The workflow instance to serialize
|
|
116
|
+
* @returns A {@link WorkflowSnapshot} with server-only fields removed from `data`
|
|
117
|
+
*/
|
|
118
|
+
serializeForClient(workflow: Workflow<TConfig>): WorkflowSnapshot<TConfig>;
|
|
119
|
+
/**
|
|
120
|
+
* Returns a client-safe projection of this definition.
|
|
121
|
+
* Memoized — returns the same instance on repeated calls.
|
|
122
|
+
*/
|
|
123
|
+
forClient(): ClientWorkflowDefinition<TConfig>;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* A client-safe projection of a workflow definition.
|
|
127
|
+
* State schemas have server-only fields removed. Returned by {@link WorkflowDefinition.forClient}.
|
|
128
|
+
*/
|
|
129
|
+
interface ClientWorkflowDefinition<TConfig extends WorkflowConfig = WorkflowConfig> {
|
|
130
|
+
/** The raw Zod schema configuration. */
|
|
131
|
+
readonly config: TConfig;
|
|
132
|
+
readonly name: string;
|
|
133
|
+
getStateSchema(stateName: string): ZodType;
|
|
134
|
+
hasState(stateName: string): boolean;
|
|
135
|
+
deserialize(snapshot: WorkflowSnapshot<TConfig>): {
|
|
136
|
+
ok: true;
|
|
137
|
+
workflow: ClientWorkflow<TConfig>;
|
|
138
|
+
} | {
|
|
139
|
+
ok: false;
|
|
140
|
+
error: ValidationError;
|
|
141
|
+
};
|
|
85
142
|
}
|
|
86
143
|
/**
|
|
87
144
|
* Creates a workflow definition from a name and Zod schema configuration.
|
|
@@ -105,6 +162,11 @@ declare function defineWorkflow<const TConfig extends WorkflowConfigInput>(name:
|
|
|
105
162
|
[K in keyof TConfig["errors"]]: z.infer<TConfig["errors"][K]>;
|
|
106
163
|
};
|
|
107
164
|
};
|
|
165
|
+
_clientResolved: {
|
|
166
|
+
states: {
|
|
167
|
+
[K in keyof TConfig["states"]]: ClientInfer<TConfig["states"][K]>;
|
|
168
|
+
};
|
|
169
|
+
};
|
|
108
170
|
}>;
|
|
109
171
|
|
|
110
172
|
/** A phantom-typed key for type-safe middleware state storage via {@link Context.set} and {@link Context.get}. */
|
|
@@ -253,14 +315,8 @@ declare class WorkflowRouter<TConfig extends WorkflowConfig, TDeps = {}> {
|
|
|
253
315
|
* @param event - The lifecycle event name
|
|
254
316
|
* @param callback - The callback to invoke when the event fires
|
|
255
317
|
*/
|
|
256
|
-
on(event: "dispatch:start", callback: (workflow: Workflow<TConfig>, command:
|
|
257
|
-
|
|
258
|
-
payload: unknown;
|
|
259
|
-
}) => void | Promise<void>): this;
|
|
260
|
-
on(event: "dispatch:end", callback: (workflow: Workflow<TConfig>, command: {
|
|
261
|
-
type: CommandNames<TConfig>;
|
|
262
|
-
payload: unknown;
|
|
263
|
-
}, result: DispatchResult<TConfig>) => void | Promise<void>): this;
|
|
318
|
+
on(event: "dispatch:start", callback: (workflow: Workflow<TConfig>, command: Command<TConfig>) => void | Promise<void>): this;
|
|
319
|
+
on(event: "dispatch:end", callback: (workflow: Workflow<TConfig>, command: Command<TConfig>, result: DispatchResult<TConfig>) => void | Promise<void>): this;
|
|
264
320
|
on(event: "pipeline:start", callback: (ctx: ReadonlyContext<TConfig, TDeps>) => void | Promise<void>): this;
|
|
265
321
|
on(event: "pipeline:end", callback: (ctx: ReadonlyContext<TConfig, TDeps>, result: DispatchResult<TConfig>) => void | Promise<void>): this;
|
|
266
322
|
on(event: "transition", callback: (from: StateNames<TConfig>, to: StateNames<TConfig>, workflow: Workflow<TConfig>) => void | Promise<void>): this;
|
|
@@ -292,9 +348,9 @@ declare class WorkflowRouter<TConfig extends WorkflowConfig, TDeps = {}> {
|
|
|
292
348
|
* @param command - The command with its type and payload
|
|
293
349
|
* @returns A {@link DispatchResult} indicating success or failure with the updated workflow and events
|
|
294
350
|
*/
|
|
295
|
-
dispatch(workflow: Workflow<TConfig>, command: {
|
|
296
|
-
type:
|
|
297
|
-
payload:
|
|
351
|
+
dispatch<C extends CommandNames<TConfig>>(workflow: Workflow<TConfig>, command: {
|
|
352
|
+
type: C;
|
|
353
|
+
payload: CommandPayload<TConfig, C>;
|
|
298
354
|
}): Promise<DispatchResult<TConfig>>;
|
|
299
355
|
private executePipeline;
|
|
300
356
|
}
|
|
@@ -336,4 +392,4 @@ declare function defineGenericPlugin(fn: (router: WorkflowRouter<any, any>) => v
|
|
|
336
392
|
*/
|
|
337
393
|
declare function isPlugin(value: unknown): value is Plugin<WorkflowConfig, unknown>;
|
|
338
394
|
|
|
339
|
-
export { type Context as C, type GenericPlugin as G, type Plugin as P, type ReadonlyContext as R, type WorkflowDefinition as W, type
|
|
395
|
+
export { type Context as C, type GenericPlugin as G, type Plugin as P, type ReadonlyContext as R, type Server as S, type WorkflowDefinition as W, type ClientWorkflowDefinition as a, type ContextKey as b, type RouterOptions as c, WorkflowRouter as d, createKey as e, defineGenericPlugin as f, definePlugin as g, defineWorkflow as h, isPlugin as i, isServerField as j, server as s };
|
package/dist/reactor/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { W as WorkflowConfig,
|
|
1
|
+
import { d as WorkflowRouter } from '../plugin-CQUbAdxj.cjs';
|
|
2
|
+
import { W as WorkflowConfig, k as EventNames, j as EventData } from '../snapshot-6pxxtOjB.cjs';
|
|
3
3
|
import 'zod';
|
|
4
4
|
|
|
5
5
|
interface ReactorCommand {
|
package/dist/reactor/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { W as WorkflowConfig,
|
|
1
|
+
import { d as WorkflowRouter } from '../plugin-CIVHyBaZ.js';
|
|
2
|
+
import { W as WorkflowConfig, k as EventNames, j as EventData } from '../snapshot-6pxxtOjB.js';
|
|
3
3
|
import 'zod';
|
|
4
4
|
|
|
5
5
|
interface ReactorCommand {
|
|
@@ -32,6 +32,9 @@ interface WorkflowConfig extends WorkflowConfigInput {
|
|
|
32
32
|
events: Record<string, unknown>;
|
|
33
33
|
errors: Record<string, unknown>;
|
|
34
34
|
};
|
|
35
|
+
_clientResolved: {
|
|
36
|
+
states: Record<string, unknown>;
|
|
37
|
+
};
|
|
35
38
|
}
|
|
36
39
|
type StateNames<T extends WorkflowConfig> = keyof T["states"] & string;
|
|
37
40
|
type CommandNames<T extends WorkflowConfig> = keyof T["commands"] & string;
|
|
@@ -41,8 +44,30 @@ type ErrorCodes<T extends WorkflowConfig> = keyof T["errors"] & string;
|
|
|
41
44
|
type Prettify<T> = {
|
|
42
45
|
[K in keyof T]: T[K];
|
|
43
46
|
} & {};
|
|
47
|
+
/** Discriminated union of all commands with typed payloads — narrows payload when checking type. */
|
|
48
|
+
type Command<T extends WorkflowConfig> = {
|
|
49
|
+
[C in CommandNames<T>]: {
|
|
50
|
+
type: C;
|
|
51
|
+
payload: CommandPayload<T, C>;
|
|
52
|
+
};
|
|
53
|
+
}[CommandNames<T>];
|
|
44
54
|
/** Resolves the data type for a given state from pre-computed types. */
|
|
45
55
|
type StateData<T extends WorkflowConfig, S extends StateNames<T>> = Prettify<T["_resolved"]["states"][S]>;
|
|
56
|
+
/** Resolves the client-safe data type for a given state (server fields stripped). */
|
|
57
|
+
type ClientStateData<T extends WorkflowConfig, S extends StateNames<T>> = Prettify<T["_clientResolved"]["states"][S]>;
|
|
58
|
+
/** Client-side workflow narrowed to a specific known state. */
|
|
59
|
+
interface ClientWorkflowOf<TConfig extends WorkflowConfig, S extends StateNames<TConfig>> {
|
|
60
|
+
readonly id: string;
|
|
61
|
+
readonly definitionName: string;
|
|
62
|
+
readonly state: S;
|
|
63
|
+
readonly data: ClientStateData<TConfig, S>;
|
|
64
|
+
readonly createdAt: Date;
|
|
65
|
+
readonly updatedAt: Date;
|
|
66
|
+
}
|
|
67
|
+
/** Discriminated union of all possible client-side workflow states. */
|
|
68
|
+
type ClientWorkflow<TConfig extends WorkflowConfig = WorkflowConfig> = {
|
|
69
|
+
[S in StateNames<TConfig>]: ClientWorkflowOf<TConfig, S>;
|
|
70
|
+
}[StateNames<TConfig>];
|
|
46
71
|
/** Resolves the payload type for a given command from pre-computed types. */
|
|
47
72
|
type CommandPayload<T extends WorkflowConfig, C extends CommandNames<T>> = Prettify<T["_resolved"]["commands"][C]>;
|
|
48
73
|
/** Resolves the data type for a given event from pre-computed types. */
|
|
@@ -162,4 +187,4 @@ interface WorkflowSnapshot<TConfig extends WorkflowConfig = WorkflowConfig> {
|
|
|
162
187
|
readonly version: number;
|
|
163
188
|
}
|
|
164
189
|
|
|
165
|
-
export { type CommandNames as C, type DispatchResult as D, type ErrorCodes as E, type PipelineError as P, type StateNames as S, ValidationError as V, type WorkflowConfig as W, type WorkflowSnapshot as a, type
|
|
190
|
+
export { type CommandNames as C, type DispatchResult as D, type ErrorCodes as E, type PipelineError as P, type StateNames as S, ValidationError as V, type WorkflowConfig as W, type WorkflowSnapshot as a, type ClientStateData as b, type ClientWorkflow as c, type ClientWorkflowOf as d, type Command as e, type CommandPayload as f, type ConfigOf as g, DomainErrorSignal as h, type ErrorData as i, type EventData as j, type EventNames as k, type StateData as l, type Workflow as m, type WorkflowOf as n, type WorkflowConfigInput as o };
|
|
@@ -32,6 +32,9 @@ interface WorkflowConfig extends WorkflowConfigInput {
|
|
|
32
32
|
events: Record<string, unknown>;
|
|
33
33
|
errors: Record<string, unknown>;
|
|
34
34
|
};
|
|
35
|
+
_clientResolved: {
|
|
36
|
+
states: Record<string, unknown>;
|
|
37
|
+
};
|
|
35
38
|
}
|
|
36
39
|
type StateNames<T extends WorkflowConfig> = keyof T["states"] & string;
|
|
37
40
|
type CommandNames<T extends WorkflowConfig> = keyof T["commands"] & string;
|
|
@@ -41,8 +44,30 @@ type ErrorCodes<T extends WorkflowConfig> = keyof T["errors"] & string;
|
|
|
41
44
|
type Prettify<T> = {
|
|
42
45
|
[K in keyof T]: T[K];
|
|
43
46
|
} & {};
|
|
47
|
+
/** Discriminated union of all commands with typed payloads — narrows payload when checking type. */
|
|
48
|
+
type Command<T extends WorkflowConfig> = {
|
|
49
|
+
[C in CommandNames<T>]: {
|
|
50
|
+
type: C;
|
|
51
|
+
payload: CommandPayload<T, C>;
|
|
52
|
+
};
|
|
53
|
+
}[CommandNames<T>];
|
|
44
54
|
/** Resolves the data type for a given state from pre-computed types. */
|
|
45
55
|
type StateData<T extends WorkflowConfig, S extends StateNames<T>> = Prettify<T["_resolved"]["states"][S]>;
|
|
56
|
+
/** Resolves the client-safe data type for a given state (server fields stripped). */
|
|
57
|
+
type ClientStateData<T extends WorkflowConfig, S extends StateNames<T>> = Prettify<T["_clientResolved"]["states"][S]>;
|
|
58
|
+
/** Client-side workflow narrowed to a specific known state. */
|
|
59
|
+
interface ClientWorkflowOf<TConfig extends WorkflowConfig, S extends StateNames<TConfig>> {
|
|
60
|
+
readonly id: string;
|
|
61
|
+
readonly definitionName: string;
|
|
62
|
+
readonly state: S;
|
|
63
|
+
readonly data: ClientStateData<TConfig, S>;
|
|
64
|
+
readonly createdAt: Date;
|
|
65
|
+
readonly updatedAt: Date;
|
|
66
|
+
}
|
|
67
|
+
/** Discriminated union of all possible client-side workflow states. */
|
|
68
|
+
type ClientWorkflow<TConfig extends WorkflowConfig = WorkflowConfig> = {
|
|
69
|
+
[S in StateNames<TConfig>]: ClientWorkflowOf<TConfig, S>;
|
|
70
|
+
}[StateNames<TConfig>];
|
|
46
71
|
/** Resolves the payload type for a given command from pre-computed types. */
|
|
47
72
|
type CommandPayload<T extends WorkflowConfig, C extends CommandNames<T>> = Prettify<T["_resolved"]["commands"][C]>;
|
|
48
73
|
/** Resolves the data type for a given event from pre-computed types. */
|
|
@@ -162,4 +187,4 @@ interface WorkflowSnapshot<TConfig extends WorkflowConfig = WorkflowConfig> {
|
|
|
162
187
|
readonly version: number;
|
|
163
188
|
}
|
|
164
189
|
|
|
165
|
-
export { type CommandNames as C, type DispatchResult as D, type ErrorCodes as E, type PipelineError as P, type StateNames as S, ValidationError as V, type WorkflowConfig as W, type WorkflowSnapshot as a, type
|
|
190
|
+
export { type CommandNames as C, type DispatchResult as D, type ErrorCodes as E, type PipelineError as P, type StateNames as S, ValidationError as V, type WorkflowConfig as W, type WorkflowSnapshot as a, type ClientStateData as b, type ClientWorkflow as c, type ClientWorkflowOf as d, type Command as e, type CommandPayload as f, type ConfigOf as g, DomainErrorSignal as h, type ErrorData as i, type EventData as j, type EventNames as k, type StateData as l, type Workflow as m, type WorkflowOf as n, type WorkflowConfigInput as o };
|
package/dist/store/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as StoreAdapter } from '../types-
|
|
2
|
-
export { b as SaveOptions, S as StoredWorkflow } from '../types-
|
|
3
|
-
import '../snapshot-
|
|
1
|
+
import { a as StoreAdapter } from '../types-BuFyzP66.cjs';
|
|
2
|
+
export { b as SaveOptions, S as StoredWorkflow } from '../types-BuFyzP66.cjs';
|
|
3
|
+
import '../snapshot-6pxxtOjB.cjs';
|
|
4
4
|
import 'zod';
|
|
5
5
|
|
|
6
6
|
declare class ConcurrencyConflictError extends Error {
|
package/dist/store/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as StoreAdapter } from '../types-
|
|
2
|
-
export { b as SaveOptions, S as StoredWorkflow } from '../types-
|
|
3
|
-
import '../snapshot-
|
|
1
|
+
import { a as StoreAdapter } from '../types-D41DR3xh.js';
|
|
2
|
+
export { b as SaveOptions, S as StoredWorkflow } from '../types-D41DR3xh.js';
|
|
3
|
+
import '../snapshot-6pxxtOjB.js';
|
|
4
4
|
import 'zod';
|
|
5
5
|
|
|
6
6
|
declare class ConcurrencyConflictError extends Error {
|