@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/dist/browser.d.ts +15 -284
- package/dist/index.d.ts +57 -263
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/react.d.ts +18 -286
- package/dist/react.js.map +1 -1
- package/dist/src/createActorFetch.d.ts +3 -3
- package/dist/src/createActorFetch.d.ts.map +1 -1
- package/dist/src/createActorKitContext.d.ts +3 -3
- package/dist/src/createActorKitContext.d.ts.map +1 -1
- package/dist/src/createActorKitRouter.d.ts.map +1 -1
- package/dist/src/createMachineServer.d.ts +21 -14
- package/dist/src/createMachineServer.d.ts.map +1 -1
- package/dist/src/react.d.ts +1 -0
- package/dist/src/react.d.ts.map +1 -1
- package/dist/src/schemas.d.ts +44 -250
- package/dist/src/schemas.d.ts.map +1 -1
- package/dist/src/storage.d.ts +1 -1
- package/dist/src/storage.d.ts.map +1 -1
- package/dist/src/types.d.ts +12 -12
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/worker.d.ts +1 -0
- package/dist/src/worker.d.ts.map +1 -1
- package/package.json +18 -15
- package/src/createActorFetch.ts +4 -4
- package/src/createActorKitContext.tsx +2 -3
- package/src/createActorKitRouter.ts +7 -4
- package/src/createMachineServer.ts +20 -30
- package/src/react.ts +8 -0
- package/src/schemas.ts +5 -2
- package/src/storage.ts +45 -31
- package/src/types.ts +35 -44
- package/src/worker.ts +11 -1
package/dist/browser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DurableObject } from 'cloudflare:workers';
|
|
2
|
-
import {
|
|
2
|
+
import { AnyStateMachine, SnapshotFrom, EventFromLogic, StateValueFrom } from 'xstate';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
declare const RequestInfoSchema: z.ZodObject<{
|
|
@@ -18,252 +18,26 @@ declare const RequestInfoSchema: z.ZodObject<{
|
|
|
18
18
|
verifiedBot: z.ZodBoolean;
|
|
19
19
|
jsDetection: z.ZodObject<{
|
|
20
20
|
passed: z.ZodBoolean;
|
|
21
|
-
},
|
|
22
|
-
passed: boolean;
|
|
23
|
-
}, {
|
|
24
|
-
passed: boolean;
|
|
25
|
-
}>;
|
|
21
|
+
}, z.core.$strip>;
|
|
26
22
|
staticResource: z.ZodBoolean;
|
|
27
23
|
detectionIds: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
28
24
|
score: z.ZodNumber;
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
verifiedBot: boolean;
|
|
32
|
-
jsDetection: {
|
|
33
|
-
passed: boolean;
|
|
34
|
-
};
|
|
35
|
-
staticResource: boolean;
|
|
36
|
-
detectionIds: Record<string, any>;
|
|
37
|
-
score: number;
|
|
38
|
-
}, {
|
|
39
|
-
corporateProxy: boolean;
|
|
40
|
-
verifiedBot: boolean;
|
|
41
|
-
jsDetection: {
|
|
42
|
-
passed: boolean;
|
|
43
|
-
};
|
|
44
|
-
staticResource: boolean;
|
|
45
|
-
detectionIds: Record<string, any>;
|
|
46
|
-
score: number;
|
|
47
|
-
}>;
|
|
48
|
-
}, "strip", z.ZodTypeAny, {
|
|
49
|
-
longitude: string;
|
|
50
|
-
latitude: string;
|
|
51
|
-
continent: string;
|
|
52
|
-
country: string;
|
|
53
|
-
city: string;
|
|
54
|
-
timezone: string;
|
|
55
|
-
postalCode: string;
|
|
56
|
-
region: string;
|
|
57
|
-
regionCode: string;
|
|
58
|
-
metroCode: string;
|
|
59
|
-
botManagement: {
|
|
60
|
-
corporateProxy: boolean;
|
|
61
|
-
verifiedBot: boolean;
|
|
62
|
-
jsDetection: {
|
|
63
|
-
passed: boolean;
|
|
64
|
-
};
|
|
65
|
-
staticResource: boolean;
|
|
66
|
-
detectionIds: Record<string, any>;
|
|
67
|
-
score: number;
|
|
68
|
-
};
|
|
69
|
-
}, {
|
|
70
|
-
longitude: string;
|
|
71
|
-
latitude: string;
|
|
72
|
-
continent: string;
|
|
73
|
-
country: string;
|
|
74
|
-
city: string;
|
|
75
|
-
timezone: string;
|
|
76
|
-
postalCode: string;
|
|
77
|
-
region: string;
|
|
78
|
-
regionCode: string;
|
|
79
|
-
metroCode: string;
|
|
80
|
-
botManagement: {
|
|
81
|
-
corporateProxy: boolean;
|
|
82
|
-
verifiedBot: boolean;
|
|
83
|
-
jsDetection: {
|
|
84
|
-
passed: boolean;
|
|
85
|
-
};
|
|
86
|
-
staticResource: boolean;
|
|
87
|
-
detectionIds: Record<string, any>;
|
|
88
|
-
score: number;
|
|
89
|
-
};
|
|
90
|
-
}>;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
}, z.core.$strip>;
|
|
91
27
|
declare const CallerSchema: z.ZodObject<{
|
|
92
28
|
id: z.ZodString;
|
|
93
|
-
type: z.ZodEnum<
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}, {
|
|
98
|
-
type: "client" | "system" | "service";
|
|
99
|
-
id: string;
|
|
100
|
-
}>;
|
|
101
|
-
declare const SystemEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
102
|
-
type: z.ZodLiteral<"INITIALIZE">;
|
|
103
|
-
caller: z.ZodObject<{
|
|
104
|
-
type: z.ZodLiteral<"system">;
|
|
105
|
-
id: z.ZodString;
|
|
106
|
-
}, "strip", z.ZodTypeAny, {
|
|
107
|
-
type: "system";
|
|
108
|
-
id: string;
|
|
109
|
-
}, {
|
|
110
|
-
type: "system";
|
|
111
|
-
id: string;
|
|
112
|
-
}>;
|
|
113
|
-
}, "strip", z.ZodTypeAny, {
|
|
114
|
-
type: "INITIALIZE";
|
|
115
|
-
caller: {
|
|
116
|
-
type: "system";
|
|
117
|
-
id: string;
|
|
118
|
-
};
|
|
119
|
-
}, {
|
|
120
|
-
type: "INITIALIZE";
|
|
121
|
-
caller: {
|
|
122
|
-
type: "system";
|
|
123
|
-
id: string;
|
|
124
|
-
};
|
|
125
|
-
}>, z.ZodObject<{
|
|
126
|
-
type: z.ZodLiteral<"CONNECT">;
|
|
127
|
-
caller: z.ZodObject<{
|
|
128
|
-
type: z.ZodLiteral<"system">;
|
|
129
|
-
id: z.ZodString;
|
|
130
|
-
}, "strip", z.ZodTypeAny, {
|
|
131
|
-
type: "system";
|
|
132
|
-
id: string;
|
|
133
|
-
}, {
|
|
134
|
-
type: "system";
|
|
135
|
-
id: string;
|
|
136
|
-
}>;
|
|
137
|
-
connectingCaller: z.ZodObject<{
|
|
138
|
-
id: z.ZodString;
|
|
139
|
-
type: z.ZodEnum<["client", "system", "service"]>;
|
|
140
|
-
}, "strip", z.ZodTypeAny, {
|
|
141
|
-
type: "client" | "system" | "service";
|
|
142
|
-
id: string;
|
|
143
|
-
}, {
|
|
144
|
-
type: "client" | "system" | "service";
|
|
145
|
-
id: string;
|
|
29
|
+
type: z.ZodEnum<{
|
|
30
|
+
client: "client";
|
|
31
|
+
system: "system";
|
|
32
|
+
service: "service";
|
|
146
33
|
}>;
|
|
147
|
-
},
|
|
148
|
-
type: "CONNECT";
|
|
149
|
-
caller: {
|
|
150
|
-
type: "system";
|
|
151
|
-
id: string;
|
|
152
|
-
};
|
|
153
|
-
connectingCaller: {
|
|
154
|
-
type: "client" | "system" | "service";
|
|
155
|
-
id: string;
|
|
156
|
-
};
|
|
157
|
-
}, {
|
|
158
|
-
type: "CONNECT";
|
|
159
|
-
caller: {
|
|
160
|
-
type: "system";
|
|
161
|
-
id: string;
|
|
162
|
-
};
|
|
163
|
-
connectingCaller: {
|
|
164
|
-
type: "client" | "system" | "service";
|
|
165
|
-
id: string;
|
|
166
|
-
};
|
|
167
|
-
}>, z.ZodObject<{
|
|
168
|
-
type: z.ZodLiteral<"DISCONNECT">;
|
|
169
|
-
caller: z.ZodObject<{
|
|
170
|
-
type: z.ZodLiteral<"system">;
|
|
171
|
-
id: z.ZodString;
|
|
172
|
-
}, "strip", z.ZodTypeAny, {
|
|
173
|
-
type: "system";
|
|
174
|
-
id: string;
|
|
175
|
-
}, {
|
|
176
|
-
type: "system";
|
|
177
|
-
id: string;
|
|
178
|
-
}>;
|
|
179
|
-
disconnectingCaller: z.ZodObject<{
|
|
180
|
-
id: z.ZodString;
|
|
181
|
-
type: z.ZodEnum<["client", "system", "service"]>;
|
|
182
|
-
}, "strip", z.ZodTypeAny, {
|
|
183
|
-
type: "client" | "system" | "service";
|
|
184
|
-
id: string;
|
|
185
|
-
}, {
|
|
186
|
-
type: "client" | "system" | "service";
|
|
187
|
-
id: string;
|
|
188
|
-
}>;
|
|
189
|
-
}, "strip", z.ZodTypeAny, {
|
|
190
|
-
type: "DISCONNECT";
|
|
191
|
-
caller: {
|
|
192
|
-
type: "system";
|
|
193
|
-
id: string;
|
|
194
|
-
};
|
|
195
|
-
disconnectingCaller: {
|
|
196
|
-
type: "client" | "system" | "service";
|
|
197
|
-
id: string;
|
|
198
|
-
};
|
|
199
|
-
}, {
|
|
200
|
-
type: "DISCONNECT";
|
|
201
|
-
caller: {
|
|
202
|
-
type: "system";
|
|
203
|
-
id: string;
|
|
204
|
-
};
|
|
205
|
-
disconnectingCaller: {
|
|
206
|
-
type: "client" | "system" | "service";
|
|
207
|
-
id: string;
|
|
208
|
-
};
|
|
209
|
-
}>, z.ZodObject<{
|
|
210
|
-
type: z.ZodLiteral<"RESUME">;
|
|
211
|
-
caller: z.ZodObject<{
|
|
212
|
-
type: z.ZodLiteral<"system">;
|
|
213
|
-
id: z.ZodString;
|
|
214
|
-
}, "strip", z.ZodTypeAny, {
|
|
215
|
-
type: "system";
|
|
216
|
-
id: string;
|
|
217
|
-
}, {
|
|
218
|
-
type: "system";
|
|
219
|
-
id: string;
|
|
220
|
-
}>;
|
|
221
|
-
}, "strip", z.ZodTypeAny, {
|
|
222
|
-
type: "RESUME";
|
|
223
|
-
caller: {
|
|
224
|
-
type: "system";
|
|
225
|
-
id: string;
|
|
226
|
-
};
|
|
227
|
-
}, {
|
|
228
|
-
type: "RESUME";
|
|
229
|
-
caller: {
|
|
230
|
-
type: "system";
|
|
231
|
-
id: string;
|
|
232
|
-
};
|
|
233
|
-
}>, z.ZodObject<{
|
|
234
|
-
type: z.ZodLiteral<"MIGRATE">;
|
|
235
|
-
caller: z.ZodObject<{
|
|
236
|
-
type: z.ZodLiteral<"system">;
|
|
237
|
-
id: z.ZodString;
|
|
238
|
-
}, "strip", z.ZodTypeAny, {
|
|
239
|
-
type: "system";
|
|
240
|
-
id: string;
|
|
241
|
-
}, {
|
|
242
|
-
type: "system";
|
|
243
|
-
id: string;
|
|
244
|
-
}>;
|
|
245
|
-
operations: z.ZodArray<z.ZodAny, "many">;
|
|
246
|
-
}, "strip", z.ZodTypeAny, {
|
|
247
|
-
type: "MIGRATE";
|
|
248
|
-
caller: {
|
|
249
|
-
type: "system";
|
|
250
|
-
id: string;
|
|
251
|
-
};
|
|
252
|
-
operations: any[];
|
|
253
|
-
}, {
|
|
254
|
-
type: "MIGRATE";
|
|
255
|
-
caller: {
|
|
256
|
-
type: "system";
|
|
257
|
-
id: string;
|
|
258
|
-
};
|
|
259
|
-
operations: any[];
|
|
260
|
-
}>]>;
|
|
34
|
+
}, z.core.$strip>;
|
|
261
35
|
|
|
262
36
|
type EnvWithDurableObjects = {
|
|
263
37
|
ACTOR_KIT_SECRET: string;
|
|
264
38
|
[key: string]: DurableObjectNamespace<ActorServer<any>> | unknown;
|
|
265
39
|
};
|
|
266
|
-
interface ActorServerMethods<TMachine extends
|
|
40
|
+
interface ActorServerMethods<TMachine extends AnyStateMachine> {
|
|
267
41
|
fetch(request: Request): Promise<Response>;
|
|
268
42
|
spawn(props: {
|
|
269
43
|
actorType: string;
|
|
@@ -282,60 +56,17 @@ interface ActorServerMethods<TMachine extends BaseActorKitStateMachine> {
|
|
|
282
56
|
snapshot: CallerSnapshotFrom<TMachine>;
|
|
283
57
|
}>;
|
|
284
58
|
}
|
|
285
|
-
type ActorServer<TMachine extends
|
|
59
|
+
type ActorServer<TMachine extends AnyStateMachine> = DurableObject & ActorServerMethods<TMachine>;
|
|
286
60
|
type Caller = z.infer<typeof CallerSchema>;
|
|
287
61
|
type RequestInfo = z.infer<typeof RequestInfoSchema>;
|
|
288
62
|
type CallerType = "client" | "system" | "service";
|
|
289
|
-
type
|
|
290
|
-
type: string;
|
|
291
|
-
};
|
|
292
|
-
type BaseActorKitContext<TPublicProps extends {
|
|
293
|
-
[key: string]: unknown;
|
|
294
|
-
}, TPrivateProps extends {
|
|
295
|
-
[key: string]: unknown;
|
|
296
|
-
}> = {
|
|
297
|
-
public: TPublicProps;
|
|
298
|
-
private: Record<string, TPrivateProps>;
|
|
299
|
-
};
|
|
300
|
-
type ActorKitStateMachine<TEvent extends BaseActorKitEvent<EnvWithDurableObjects>, TInput extends {
|
|
301
|
-
id: string;
|
|
302
|
-
caller: Caller;
|
|
303
|
-
storage: DurableObjectStorage;
|
|
304
|
-
}, TContext extends BaseActorKitContext<any, any> & {
|
|
305
|
-
[key: string]: unknown;
|
|
306
|
-
}> = StateMachine<TContext, TEvent & EventObject, any, any, any, any, any, any, any, TInput, any, any, any, any>;
|
|
307
|
-
type BaseActorKitInput<TEnv = EnvWithDurableObjects> = {
|
|
308
|
-
id: string;
|
|
309
|
-
caller: Caller;
|
|
310
|
-
env: TEnv;
|
|
311
|
-
storage: DurableObjectStorage;
|
|
312
|
-
};
|
|
313
|
-
type WithActorKitInput<TInputProps extends {
|
|
314
|
-
[key: string]: unknown;
|
|
315
|
-
}, TEnv extends EnvWithDurableObjects> = TInputProps & BaseActorKitInput<TEnv>;
|
|
316
|
-
type AnyActorKitStateMachine = ActorKitStateMachine<any, any, any>;
|
|
317
|
-
type AnyActorKitEvent = (WithActorKitEvent<AnyEventObject, "client"> | WithActorKitEvent<AnyEventObject, "service"> | ActorKitSystemEvent) & BaseActorKitEvent<EnvWithDurableObjects>;
|
|
318
|
-
type AnyActorKitInput = WithActorKitInput<{
|
|
319
|
-
[key: string]: unknown;
|
|
320
|
-
}, EnvWithDurableObjects> & {
|
|
321
|
-
storage: DurableObjectStorage;
|
|
322
|
-
};
|
|
323
|
-
type AnyActorKitContext = {
|
|
324
|
-
public: {
|
|
325
|
-
[key: string]: unknown;
|
|
326
|
-
};
|
|
327
|
-
private: Record<string, {
|
|
328
|
-
[key: string]: unknown;
|
|
329
|
-
}>;
|
|
330
|
-
};
|
|
331
|
-
type BaseActorKitStateMachine = ActorKitStateMachine<AnyActorKitEvent, AnyActorKitInput, AnyActorKitContext>;
|
|
63
|
+
type AnyActorKitStateMachine = AnyStateMachine;
|
|
332
64
|
interface BaseActorKitEvent<TEnv extends EnvWithDurableObjects> {
|
|
333
65
|
caller: Caller;
|
|
334
66
|
storage: DurableObjectStorage;
|
|
335
67
|
requestInfo?: RequestInfo;
|
|
336
68
|
env: TEnv;
|
|
337
69
|
}
|
|
338
|
-
type ActorKitSystemEvent = z.infer<typeof SystemEventSchema>;
|
|
339
70
|
type WithActorKitEvent<T extends {
|
|
340
71
|
type: string;
|
|
341
72
|
}, C extends CallerType> = T & BaseActorKitEvent<EnvWithDurableObjects> & {
|
|
@@ -358,9 +89,9 @@ type CallerSnapshotFrom<TMachine extends AnyStateMachine> = {
|
|
|
358
89
|
value: infer V;
|
|
359
90
|
} ? V : unknown;
|
|
360
91
|
};
|
|
361
|
-
type ClientEventFrom<T extends
|
|
362
|
-
type ServiceEventFrom<T extends
|
|
363
|
-
type ActorKitClient<TMachine extends
|
|
92
|
+
type ClientEventFrom<T extends AnyStateMachine> = EventFromLogic<T> extends infer TEvent ? TEvent extends WithActorKitEvent<infer E, "client"> ? Omit<E, keyof BaseActorKitEvent<EnvWithDurableObjects>> : Omit<TEvent, keyof BaseActorKitEvent<EnvWithDurableObjects>> : never;
|
|
93
|
+
type ServiceEventFrom<T extends AnyStateMachine> = EventFromLogic<T> extends infer TEvent ? TEvent extends WithActorKitEvent<infer E, "service"> ? Omit<E, keyof BaseActorKitEvent<EnvWithDurableObjects>> : never : never;
|
|
94
|
+
type ActorKitClient<TMachine extends AnyStateMachine> = {
|
|
364
95
|
connect: () => Promise<void>;
|
|
365
96
|
disconnect: () => void;
|
|
366
97
|
send: (event: ClientEventFrom<TMachine>) => void;
|