@methodacting/actor-kit 0.47.0 → 0.47.2

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/src/types.ts CHANGED
@@ -3,6 +3,7 @@ import { Operation } from "fast-json-patch";
3
3
  import type {
4
4
  AnyEventObject,
5
5
  AnyStateMachine,
6
+ EventFromLogic,
6
7
  SnapshotFrom,
7
8
  StateMachine,
8
9
  StateValueFrom,
@@ -24,7 +25,7 @@ export type EnvWithDurableObjects = {
24
25
 
25
26
  export type AnyEvent = z.infer<typeof AnyEventSchema>;
26
27
 
27
- export interface ActorServerMethods<TMachine extends BaseActorKitStateMachine> {
28
+ export interface ActorServerMethods<TMachine extends AnyStateMachine> {
28
29
  fetch(request: Request): Promise<Response>;
29
30
  spawn(props: {
30
31
  actorType: string;
@@ -47,7 +48,7 @@ export interface ActorServerMethods<TMachine extends BaseActorKitStateMachine> {
47
48
  }>;
48
49
  }
49
50
 
50
- export type ActorServer<TMachine extends AnyActorKitStateMachine> =
51
+ export type ActorServer<TMachine extends AnyStateMachine> =
51
52
  DurableObject & ActorServerMethods<TMachine>;
52
53
  export type AnyActorServer = ActorServer<any>;
53
54
 
@@ -68,11 +69,11 @@ type EventObject = {
68
69
  };
69
70
 
70
71
  type EventSchemaUnion = z.ZodDiscriminatedUnion<
71
- "type",
72
72
  [
73
73
  z.ZodObject<z.ZodRawShape & { type: z.ZodString }>,
74
74
  ...z.ZodObject<z.ZodRawShape & { type: z.ZodString }>[]
75
- ]
75
+ ],
76
+ "type"
76
77
  >;
77
78
 
78
79
  export type EventSchemas = {
@@ -127,7 +128,12 @@ export type WithActorKitInput<
127
128
  TEnv extends EnvWithDurableObjects
128
129
  > = TInputProps & BaseActorKitInput<TEnv>;
129
130
 
130
- export type AnyActorKitStateMachine = ActorKitStateMachine<any, any, any>;
131
+ /**
132
+ * Any actor-kit compatible state machine.
133
+ * Alias for AnyStateMachine — actor-kit accepts any xstate machine
134
+ * whose context has public/private structure.
135
+ */
136
+ export type AnyActorKitStateMachine = AnyStateMachine;
131
137
 
132
138
  type AnyActorKitEvent = (
133
139
  | WithActorKitEvent<AnyEventObject, "client">
@@ -194,45 +200,30 @@ export type CallerSnapshotFrom<TMachine extends AnyStateMachine> = {
194
200
  value: SnapshotFrom<TMachine> extends { value: infer V } ? V : unknown;
195
201
  };
196
202
 
197
- export type ClientEventFrom<T extends AnyActorKitStateMachine> =
198
- T extends StateMachine<
199
- any,
200
- infer TEvent,
201
- any,
202
- any,
203
- any,
204
- any,
205
- any,
206
- any,
207
- any,
208
- any,
209
- any,
210
- any,
211
- any,
212
- any
213
- >
203
+ /**
204
+ * Extract client events from a machine type.
205
+ * Uses EventFromLogic (interface-based) instead of StateMachine (class-based)
206
+ * to avoid nominal typing issues when xstate is resolved from different paths.
207
+ * Supports both actor-kit wrapped events (WithActorKitEvent<E, "client">)
208
+ * and plain xstate machines where the event type is used directly.
209
+ */
210
+ export type ClientEventFrom<T extends AnyStateMachine> =
211
+ EventFromLogic<T> extends infer TEvent
214
212
  ? TEvent extends WithActorKitEvent<infer E, "client">
215
213
  ? Omit<E, keyof BaseActorKitEvent<EnvWithDurableObjects>>
216
- : never
214
+ : Omit<TEvent, keyof BaseActorKitEvent<EnvWithDurableObjects>>
217
215
  : never;
218
216
 
219
- export type ServiceEventFrom<T extends AnyActorKitStateMachine> =
220
- T extends StateMachine<
221
- any,
222
- infer TEvent,
223
- any,
224
- any,
225
- any,
226
- any,
227
- any,
228
- any,
229
- any,
230
- any,
231
- any,
232
- any,
233
- any,
234
- any
235
- >
217
+ /**
218
+ * Extract service events from a machine type.
219
+ * Uses EventFromLogic (interface-based) instead of StateMachine (class-based)
220
+ * to avoid nominal typing issues when xstate is resolved from different paths.
221
+ * Supports both actor-kit wrapped events (WithActorKitEvent<E, "service">)
222
+ * and plain xstate machines (falls back to never since plain machines
223
+ * don't distinguish client vs service events).
224
+ */
225
+ export type ServiceEventFrom<T extends AnyStateMachine> =
226
+ EventFromLogic<T> extends infer TEvent
236
227
  ? TEvent extends WithActorKitEvent<infer E, "service">
237
228
  ? Omit<E, keyof BaseActorKitEvent<EnvWithDurableObjects>>
238
229
  : never
@@ -244,7 +235,7 @@ export type ScreamingSnakeToKebab<S extends string> =
244
235
  ? `${Lowercase<T>}-${ScreamingSnakeToKebab<U>}`
245
236
  : Lowercase<S>;
246
237
 
247
- export type DurableObjectActor<TMachine extends AnyActorKitStateMachine> =
238
+ export type DurableObjectActor<TMachine extends AnyStateMachine> =
248
239
  ActorServer<TMachine>;
249
240
 
250
241
  type CamelToSnakeCase<S extends string> = S extends `${infer T}${infer U}`
@@ -260,7 +251,7 @@ type KebabToCamelCase<S extends string> = S extends `${infer T}-${infer U}`
260
251
  export type KebabToScreamingSnake<S extends string> = Uppercase<
261
252
  CamelToSnakeCase<KebabToCamelCase<S>>
262
253
  >;
263
- export interface MatchesProps<TMachine extends AnyActorKitStateMachine> {
254
+ export interface MatchesProps<TMachine extends AnyStateMachine> {
264
255
  state: StateValueFrom<TMachine>;
265
256
  and?: StateValueFrom<TMachine>;
266
257
  or?: StateValueFrom<TMachine>;
@@ -279,7 +270,7 @@ export type ActorKitEmittedEvent = {
279
270
  // checksum: string;
280
271
  // };
281
272
 
282
- export type ActorKitClient<TMachine extends AnyActorKitStateMachine> = {
273
+ export type ActorKitClient<TMachine extends AnyStateMachine> = {
283
274
  connect: () => Promise<void>;
284
275
  disconnect: () => void;
285
276
  send: (event: ClientEventFrom<TMachine>) => void;
@@ -306,7 +297,7 @@ type ExtractEventType<TMachine> = TMachine extends ActorKitStateMachine<
306
297
  type ExtractEnvType<TEvent> = TEvent extends { env: infer TEnv } ? TEnv : never;
307
298
 
308
299
  // Finally, our InferEnvFromMachine type that ensures EnvWithDurableObjects
309
- export type EnvFromMachine<TMachine extends AnyActorKitStateMachine> =
300
+ export type EnvFromMachine<TMachine extends AnyStateMachine> =
310
301
  ExtractEnvType<ExtractEventType<TMachine>> extends never
311
302
  ? EnvWithDurableObjects
312
303
  : ExtractEnvType<ExtractEventType<TMachine>> & EnvWithDurableObjects;
package/src/worker.ts CHANGED
@@ -1,2 +1,12 @@
1
1
  export { createActorKitRouter } from "./createActorKitRouter";
2
- export { createMachineServer } from "./createMachineServer";
2
+ export { createMachineServer } from "./createMachineServer";
3
+ export type {
4
+ ActorServer,
5
+ ActorServerMethods,
6
+ BaseActorKitEvent,
7
+ CallerSnapshotFrom,
8
+ ClientEventFrom,
9
+ EnvFromMachine,
10
+ MachineServerOptions,
11
+ ServiceEventFrom,
12
+ } from "./types";