@sphereon/ssi-sdk.xstate-machine-persistence 0.33.1-feature.vcdm2.tsup.32 → 0.33.1-next.3
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/agent/MachineStatePersistence.d.ts +26 -0
- package/dist/agent/MachineStatePersistence.d.ts.map +1 -0
- package/dist/agent/MachineStatePersistence.js +197 -0
- package/dist/agent/MachineStatePersistence.js.map +1 -0
- package/dist/functions/index.d.ts +4 -0
- package/dist/functions/index.d.ts.map +1 -0
- package/dist/functions/index.js +20 -0
- package/dist/functions/index.js.map +1 -0
- package/dist/functions/machineRegistration.d.ts +130 -0
- package/dist/functions/machineRegistration.d.ts.map +1 -0
- package/dist/functions/machineRegistration.js +303 -0
- package/dist/functions/machineRegistration.js.map +1 -0
- package/dist/functions/stateEventEmitter.d.ts +10 -0
- package/dist/functions/stateEventEmitter.d.ts.map +1 -0
- package/dist/functions/stateEventEmitter.js +21 -0
- package/dist/functions/stateEventEmitter.js.map +1 -0
- package/dist/functions/stateMapper.d.ts +34 -0
- package/dist/functions/stateMapper.d.ts.map +1 -0
- package/dist/functions/stateMapper.js +83 -0
- package/dist/functions/stateMapper.js.map +1 -0
- package/dist/index.d.ts +5 -425
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -1222
- package/dist/index.js.map +1 -1
- package/dist/{index.d.cts → ssi-sdk.xstate-machine-persistence.d.ts} +467 -426
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/types/IMachineStatePersistence.d.ts +62 -0
- package/dist/types/IMachineStatePersistence.d.ts.map +1 -0
- package/dist/types/IMachineStatePersistence.js +3 -0
- package/dist/types/IMachineStatePersistence.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/types.d.ts +173 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +13 -0
- package/dist/types/types.js.map +1 -0
- package/package.json +14 -25
- package/src/__tests__/localAgent.test.ts +0 -1
- package/src/__tests__/restAgent.test.ts +1 -4
- package/src/__tests__/shared/MachineStatePersistenceAgentLogic.ts +0 -1
- package/dist/index.cjs +0 -1254
- package/dist/index.cjs.map +0 -1
|
@@ -1,426 +1,467 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { EventObject
|
|
4
|
-
import { EventObject as
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*
|
|
35
|
-
|
|
36
|
-
type
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
*
|
|
121
|
-
* @
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
*
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
*
|
|
136
|
-
* @
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* @
|
|
154
|
-
* @
|
|
155
|
-
* @
|
|
156
|
-
* @
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
context:
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
*
|
|
313
|
-
* @
|
|
314
|
-
*/
|
|
315
|
-
declare
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
* @
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
}) => Promise<
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
* @
|
|
356
|
-
* @
|
|
357
|
-
* @
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
* @param {
|
|
389
|
-
* @
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
*
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
1
|
+
import { AnyEventObject } from 'xstate';
|
|
2
|
+
import { DefaultContext } from 'xstate';
|
|
3
|
+
import { EventObject } from 'xstate';
|
|
4
|
+
import { EventObject as EventObject_2 } from 'xstate/lib/types';
|
|
5
|
+
import { HistoryValue } from 'xstate';
|
|
6
|
+
import { IAbstractMachineStateStore } from '@sphereon/ssi-sdk.data-store';
|
|
7
|
+
import { IAgentContext } from '@veramo/core';
|
|
8
|
+
import { IAgentPlugin } from '@veramo/core';
|
|
9
|
+
import { Interpreter } from 'xstate';
|
|
10
|
+
import { IPluginMethodMap } from '@veramo/core';
|
|
11
|
+
import { SCXML } from 'xstate';
|
|
12
|
+
import { State } from 'xstate';
|
|
13
|
+
import { StateSchema } from 'xstate';
|
|
14
|
+
import { StateValue } from 'xstate';
|
|
15
|
+
import { StoreMachineStateDeleteExpiredArgs } from '@sphereon/ssi-sdk.data-store';
|
|
16
|
+
import { StoreMachineStateInfo } from '@sphereon/ssi-sdk.data-store';
|
|
17
|
+
import { StoreMachineStatesFindActiveArgs } from '@sphereon/ssi-sdk.data-store';
|
|
18
|
+
import { TypegenDisabled } from 'xstate';
|
|
19
|
+
import { Typestate } from 'xstate';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Represents the arguments for deleting expired states from a machine.
|
|
23
|
+
*/
|
|
24
|
+
export declare type DeleteExpiredStatesArgs = Pick<StoreMachineStateDeleteExpiredArgs, 'deleteDoneStates' | 'machineName' | 'tenantId'>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Represents the result of a state deletion operation.
|
|
28
|
+
*
|
|
29
|
+
* @typedef {number} DeleteStateResult
|
|
30
|
+
*/
|
|
31
|
+
export declare type DeleteStateResult = number;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Deserializes a serialized machine state.
|
|
35
|
+
*
|
|
36
|
+
* @template T - The type of the machine's context.
|
|
37
|
+
* @template TEvent - The type of the events that the machine handles.
|
|
38
|
+
* @param {string} state - The serialized machine state.
|
|
39
|
+
* @returns {State<T, TEvent>} - The deserialized machine state.
|
|
40
|
+
*/
|
|
41
|
+
export declare const deserializeMachineState: <T, TEvent extends EventObject_2>(state: string) => State<T, TEvent>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Emits a machine state persistence event.
|
|
45
|
+
*
|
|
46
|
+
* @param {MachineStatePersistEvent} event - The event to be emitted.
|
|
47
|
+
* @param {RequiredContext} context - The required agent context for the event emission.
|
|
48
|
+
* @returns {void}
|
|
49
|
+
*/
|
|
50
|
+
export declare const emitMachineStatePersistEvent: (event: MachineStatePersistEvent, context: RequiredContext) => void;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Represents the arguments for finding active states of a store machine.
|
|
54
|
+
*/
|
|
55
|
+
export declare type FindActiveStatesArgs = StoreMachineStatesFindActiveArgs;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The interface definition for a plugin that can issue and verify Verifiable Credentials and Presentations
|
|
59
|
+
* that use JSON-LD format.
|
|
60
|
+
*
|
|
61
|
+
* @remarks Please see {@link https://www.w3.org/TR/vc-data-model | W3C Verifiable Credentials data model}
|
|
62
|
+
*
|
|
63
|
+
* @beta This API is likely to change without a BREAKING CHANGE notice
|
|
64
|
+
*/
|
|
65
|
+
export declare interface IMachineStatePersistence extends IPluginMethodMap {
|
|
66
|
+
/**
|
|
67
|
+
* Loads the states of active xstate machines from the database.
|
|
68
|
+
*
|
|
69
|
+
* @param args FindActiveStatesArgs
|
|
70
|
+
* type of the event
|
|
71
|
+
*
|
|
72
|
+
* @returns state or null
|
|
73
|
+
*
|
|
74
|
+
* @beta This API is likely to change without a BREAKING CHANGE notice
|
|
75
|
+
*/
|
|
76
|
+
machineStatesFindActive(args: FindActiveStatesArgs): Promise<Array<MachineStateInfo>>;
|
|
77
|
+
/**
|
|
78
|
+
* Deletes the state of an xstate machine in the database.
|
|
79
|
+
*
|
|
80
|
+
* @param args DeleteExpiredStatesArgs
|
|
81
|
+
* type: optional type of the machine
|
|
82
|
+
*
|
|
83
|
+
* @beta This API is likely to change without a BREAKING CHANGE notice
|
|
84
|
+
*/
|
|
85
|
+
machineStatesDeleteExpired(args: DeleteExpiredStatesArgs): Promise<DeleteStateResult>;
|
|
86
|
+
/**
|
|
87
|
+
* Initializes a state object for a new machine. Does not persist anything
|
|
88
|
+
* @param args Requires a machineName, instanceId and tenantId are optional
|
|
89
|
+
*/
|
|
90
|
+
machineStateInit(args: InitMachineStateArgs): Promise<MachineStateInit>;
|
|
91
|
+
/**
|
|
92
|
+
* Persists the state
|
|
93
|
+
* @param args MachineStatePersistArgs
|
|
94
|
+
*
|
|
95
|
+
* @param context
|
|
96
|
+
* @beta This API is likely to change without a BREAKING CHANGE notice
|
|
97
|
+
*/
|
|
98
|
+
machineStatePersist(args: MachineStatePersistArgs, context: RequiredContext): Promise<MachineStateInfo>;
|
|
99
|
+
/**
|
|
100
|
+
* Get a particular machine state by instance id and tenant id
|
|
101
|
+
* @param args instance id and tenant id
|
|
102
|
+
*
|
|
103
|
+
* @param context
|
|
104
|
+
* @beta This API is likely to change without a BREAKING CHANGE notice
|
|
105
|
+
*/
|
|
106
|
+
machineStateGet(args: MachineStateGetArgs, context: RequiredContext): Promise<MachineStateInfo>;
|
|
107
|
+
/**
|
|
108
|
+
* Delete a particular machine state by instance id and tenant id
|
|
109
|
+
* @param args instance id and tenant id
|
|
110
|
+
*
|
|
111
|
+
* @param context
|
|
112
|
+
* @beta This API is likely to change without a BREAKING CHANGE notice
|
|
113
|
+
*/
|
|
114
|
+
machineStateDelete(args: MachineStateDeleteArgs, context: RequiredContext): Promise<boolean>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Represents the arguments required to initialize the machine state.
|
|
119
|
+
* @typedef {Object} InitMachineStateArgs@typedef {Object} InitMachineStateArgs
|
|
120
|
+
* @property {string} machineName - The name of the machine.
|
|
121
|
+
* @property {Partial<MachineStateInit>} [additionalArgs] - Additional initialization arguments for the machine state.
|
|
122
|
+
*/
|
|
123
|
+
export declare type InitMachineStateArgs = Omit<Partial<MachineStateInit>, 'instanceId'> & Pick<MachineStateInfo, 'machineName'> & Pick<MachineStatePersistenceOpts, 'customInstanceId' | 'existingInstanceId'> & {
|
|
124
|
+
cleanupAllOtherInstances?: boolean;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Resumes the interpreter from a given state.
|
|
129
|
+
*
|
|
130
|
+
* @param {Object} args - The arguments for resuming the interpreter.
|
|
131
|
+
* @param {MachineStateInfo} args.machineState - The machine state information.
|
|
132
|
+
* @param {boolean} [args.noRegistration] - If true, no registration will be performed.
|
|
133
|
+
* @param {Interpreter} args.interpreter - The interpreter instance.
|
|
134
|
+
* @param {IAgentContext<IMachineStatePersistence>} args.context - The context for machine state persistence.
|
|
135
|
+
*
|
|
136
|
+
* @returns {Promise<Interpreter>} - A promise that resolves to the resumed interpreter.
|
|
137
|
+
*/
|
|
138
|
+
export declare const interpreterResumeFromState: <TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
139
|
+
value: any;
|
|
140
|
+
context: TContext;
|
|
141
|
+
}, TResolvedTypesMeta = TypegenDisabled>(args: {
|
|
142
|
+
machineState: MachineStateInfo;
|
|
143
|
+
noRegistration?: boolean;
|
|
144
|
+
cleanupAllOtherInstances?: boolean;
|
|
145
|
+
cleanupOnFinalState?: boolean;
|
|
146
|
+
interpreter: Interpreter<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>;
|
|
147
|
+
context: IAgentContext<IMachineStatePersistence>;
|
|
148
|
+
}) => Promise<StartedInterpreterInfo<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>>;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Starts or resumes the given state machine interpreter.
|
|
152
|
+
*
|
|
153
|
+
* @async
|
|
154
|
+
* @param {Object} args - The arguments for starting or resuming the interpreter.
|
|
155
|
+
* @param {MachineStateInitType | 'auto'} [args.stateType] - The state type. Defaults to 'auto'.
|
|
156
|
+
* @param {string} [args.instanceId] - The instance ID.
|
|
157
|
+
* @param {string} [args.machineName] - The machine name.
|
|
158
|
+
* @param {string} [args.tenantId] - The tenant ID.
|
|
159
|
+
* @param {boolean} args.singletonCheck - Whether to perform a singleton check or not. If more than one machine instance is found an error will be thrown
|
|
160
|
+
* @param {boolean} [args.noRegistration] - Whether to skip state change event registration or not.
|
|
161
|
+
* @param {Interpreter<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>} args.interpreter - The interpreter to start or resume.
|
|
162
|
+
* @param {IAgentContext<IMachineStatePersistence>} args.context - The agent context.
|
|
163
|
+
* @returns {Promise} A promise that resolves when the interpreter is started or resumed.
|
|
164
|
+
* @throws {Error} If there are multiple active instances of the machine and singletonCheck is true.
|
|
165
|
+
* @throws {Error} If a new instance was requested with the same ID as an existing active instance.
|
|
166
|
+
* @throws {Error} If the existing state machine with the given machine name and instance ID cannot be found.
|
|
167
|
+
*/
|
|
168
|
+
export declare const interpreterStartOrResume: <TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
169
|
+
value: any;
|
|
170
|
+
context: TContext;
|
|
171
|
+
}, TResolvedTypesMeta = TypegenDisabled>(args: {
|
|
172
|
+
stateType?: MachineStateInitType | "auto";
|
|
173
|
+
instanceId?: string;
|
|
174
|
+
machineName?: string;
|
|
175
|
+
tenantId?: string;
|
|
176
|
+
singletonCheck: boolean;
|
|
177
|
+
noRegistration?: boolean;
|
|
178
|
+
cleanupAllOtherInstances?: boolean;
|
|
179
|
+
cleanupOnFinalState?: boolean;
|
|
180
|
+
interpreter: Interpreter<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>;
|
|
181
|
+
context: IAgentContext<IMachineStatePersistence>;
|
|
182
|
+
}) => Promise<StartedInterpreterInfo<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>>;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Resumes or starts the interpreter from the initial machine state.
|
|
186
|
+
*
|
|
187
|
+
* @async
|
|
188
|
+
* @param {Object} args - The arguments for the function.
|
|
189
|
+
* @param {MachineStateInit & {stateType?: MachineStateInitType}} args.init - The initialization state of the machine.
|
|
190
|
+
* @param {boolean} args.noRegistration - Whether registration is required, defaults to false.
|
|
191
|
+
* @param {Interpreter<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>} args.interpreter - The interpreter object.
|
|
192
|
+
* @param {IAgentContext<IMachineStatePersistence>} args.context - The context object.
|
|
193
|
+
* @returns {Promise} - A promise that resolves to the interpreter instance.
|
|
194
|
+
* @throws {Error} - If the machine name from init does not match the interpreter id.
|
|
195
|
+
*/
|
|
196
|
+
export declare const interpreterStartOrResumeFromInit: <TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
197
|
+
value: any;
|
|
198
|
+
context: TContext;
|
|
199
|
+
}, TResolvedTypesMeta = TypegenDisabled>(args: {
|
|
200
|
+
init: MachineStateInit & {
|
|
201
|
+
stateType?: MachineStateInitType;
|
|
202
|
+
};
|
|
203
|
+
cleanupAllOtherInstances?: boolean;
|
|
204
|
+
cleanupOnFinalState?: boolean;
|
|
205
|
+
noRegistration?: boolean;
|
|
206
|
+
interpreter: Interpreter<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>;
|
|
207
|
+
context: IAgentContext<IMachineStatePersistence>;
|
|
208
|
+
}) => Promise<StartedInterpreterInfo<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>>;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Represents the arguments required for deleting a machine state.
|
|
212
|
+
*
|
|
213
|
+
* @typedef {object} MachineStateDeleteArgs@typedef {object} MachineStateDeleteArgs
|
|
214
|
+
* @property {string} existingInstanceId - The ID of the machine instance to delete the state for.
|
|
215
|
+
* @property {string} tenantId - The ID of the tenant owning the machine instance.
|
|
216
|
+
*/
|
|
217
|
+
export declare type MachineStateDeleteArgs = Pick<StoreMachineStateInfo, 'instanceId' | 'tenantId'>;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Represents the arguments required to get machine state.
|
|
221
|
+
* @typedef {Object} MachineStateGetArgs@typedef {Object} MachineStateGetArgs
|
|
222
|
+
* @property {string} existingInstanceId - The ID of the machine instance.
|
|
223
|
+
* @property {string} tenantId - The ID of the tenant the machine belongs to.
|
|
224
|
+
*/
|
|
225
|
+
export declare type MachineStateGetArgs = Pick<StoreMachineStateInfo, 'instanceId' | 'tenantId'>;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Represents the information about the current state of a machine.
|
|
229
|
+
* @typedef {Object} MachineStateInfo@typedef {Object} MachineStateInfo
|
|
230
|
+
* @property {string} id - The ID of the machine.
|
|
231
|
+
* @property {SerializableState} state - The serializable state of the machine.
|
|
232
|
+
* @property {string} description - The description of the machine state.
|
|
233
|
+
*/
|
|
234
|
+
export declare type MachineStateInfo = Omit<StoreMachineStateInfo, 'state'> & {
|
|
235
|
+
state: SerializableState;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Represents the initial state for a machine.
|
|
240
|
+
*
|
|
241
|
+
* @typedef {Object} MachineStateInit@typedef {Object} MachineStateInit
|
|
242
|
+
* @property {string} existingInstanceId - The unique identifier for the machine instance.
|
|
243
|
+
* @property {string} machineName - The name of the machine.
|
|
244
|
+
* @property {string} tenantId - The identifier for the tenant associated with the machine.
|
|
245
|
+
* @property {Date} createdAt - The date and time when the machine was created.
|
|
246
|
+
* @property {Date} expiresAt - The date and time when the machine's state expires.
|
|
247
|
+
*/
|
|
248
|
+
export declare type MachineStateInit = Pick<MachineStateInfo, 'instanceId' | 'machineName' | 'tenantId' | 'createdAt' | 'expiresAt'> & {
|
|
249
|
+
stateType: MachineStateInitType;
|
|
250
|
+
machineState?: MachineStateInfo;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
export declare type MachineStateInitType = 'new' | 'existing';
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Represents the arguments required to persist the machine state.
|
|
257
|
+
*/
|
|
258
|
+
export declare type MachineStatePersistArgs = Omit<MachineStateInit, 'createdAt'> & Pick<MachineStateInfo, 'state' | 'instanceId'> & Partial<Pick<MachineStateInfo, 'updatedCount'>> & {
|
|
259
|
+
cleanupOnFinalState?: boolean;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* This class implements the IMachineStatePersistence interface using a datastore.
|
|
264
|
+
*
|
|
265
|
+
* This allows you to store and retrieve the State of a state machine/application by their types.
|
|
266
|
+
*
|
|
267
|
+
* @beta This API may change without a BREAKING CHANGE notice.
|
|
268
|
+
*/
|
|
269
|
+
export declare class MachineStatePersistence implements IAgentPlugin {
|
|
270
|
+
readonly schema: any;
|
|
271
|
+
readonly methods: IMachineStatePersistence | {};
|
|
272
|
+
readonly eventTypes: Array<string>;
|
|
273
|
+
private readonly _store?;
|
|
274
|
+
get store(): IAbstractMachineStateStore;
|
|
275
|
+
constructor(opts: MachineStatePersistOpts);
|
|
276
|
+
onEvent(event: MachineStatePersistEvent, context: RequiredContext): Promise<void>;
|
|
277
|
+
private machineStateInit;
|
|
278
|
+
private machineStatePersist;
|
|
279
|
+
private machineStatesFindActive;
|
|
280
|
+
private machineStatesDeleteExpired;
|
|
281
|
+
private machineStateGet;
|
|
282
|
+
private machineStateDelete;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export declare type MachineStatePersistenceOpts = {
|
|
286
|
+
disablePersistence?: boolean;
|
|
287
|
+
customInstanceId?: string;
|
|
288
|
+
existingInstanceId?: string;
|
|
289
|
+
expireInMS?: number;
|
|
290
|
+
expiresAt?: Date;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Represents a machine state persist event.
|
|
295
|
+
*
|
|
296
|
+
* @typedef {Object} MachineStatePersistEvent@typedef {Object} MachineStatePersistEvent
|
|
297
|
+
* @property {MachineStatePersistEventType} type - The type of the persist event.
|
|
298
|
+
* @property {MachineStatePersistArgs} data - The data associated with the persist event, along with additional properties `_eventCounter` and `_eventDate`.
|
|
299
|
+
* @property {number} data._eventCounter - The counter for the persist event.
|
|
300
|
+
* @property {Date} data._eventDate - The date and time the persist event occurred.
|
|
301
|
+
*/
|
|
302
|
+
export declare type MachineStatePersistEvent = {
|
|
303
|
+
type: MachineStatePersistEventType;
|
|
304
|
+
data: Omit<MachineStatePersistArgs, 'machineState'> & {
|
|
305
|
+
_eventCounter: number;
|
|
306
|
+
_eventDate: Date;
|
|
307
|
+
_cleanupOnFinalState: boolean;
|
|
308
|
+
};
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Enum representing the types of machine state persist events.
|
|
313
|
+
* @enum {string}
|
|
314
|
+
*/
|
|
315
|
+
export declare enum MachineStatePersistEventType {
|
|
316
|
+
INIT = "INIT",
|
|
317
|
+
EVERY = "EVERY"
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Initialize the machine state persistence. Returns a unique instanceId and the machine name amongst others
|
|
322
|
+
*
|
|
323
|
+
* @param {Object} opts - The options for initializing the machine state persistence.
|
|
324
|
+
* @param {InitMachineStateArgs} opts - The arguments for initializing the machine state.
|
|
325
|
+
* @param {IAgentContext<any>} opts.context - The agent context.
|
|
326
|
+
* @returns {Promise<MachineStateInit | undefined>} - A promise that resolves to the initialized machine state, or undefined if the agent isn't using the Xstate plugin.
|
|
327
|
+
*/
|
|
328
|
+
export declare const machineStatePersistInit: (opts: InitMachineStateArgs & Pick<MachineStatePersistenceOpts, "existingInstanceId" | "customInstanceId"> & {
|
|
329
|
+
context: IAgentContext<any>;
|
|
330
|
+
}) => Promise<MachineStateInit | undefined>;
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* This function allows for the persistence of machine state on every xstate transition. It emits an event with the new state
|
|
334
|
+
* and other relevant data to be handled by the persistence plugin when enabled.
|
|
335
|
+
*
|
|
336
|
+
* @param {Object} opts - The options object.
|
|
337
|
+
* @param {Interpreter} opts.instance - The XState machine interpreter instance.
|
|
338
|
+
* @param {IAgentContext<any>} opts.context - The agent context.
|
|
339
|
+
* @param {MachineStateInit} opts.init - The initial persistence options, containing the unique instanceId.
|
|
340
|
+
* @returns {Promise<void>} - A promise that resolves when the persistence event is emitted.
|
|
341
|
+
*/
|
|
342
|
+
export declare const machineStatePersistOnTransition: <TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
343
|
+
value: any;
|
|
344
|
+
context: TContext;
|
|
345
|
+
}, TResolvedTypesMeta = TypegenDisabled>(opts: {
|
|
346
|
+
interpreter: Interpreter<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>;
|
|
347
|
+
context: IAgentContext<any>;
|
|
348
|
+
init: MachineStateInit;
|
|
349
|
+
cleanupOnFinalState?: boolean;
|
|
350
|
+
}) => Promise<void>;
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Represents the options for persisting machine state.
|
|
354
|
+
*
|
|
355
|
+
* @typedef {Object} MachineStatePersistOpts@typedef {Object} MachineStatePersistOpts
|
|
356
|
+
* @property {IAbstractMachineStateStore} store - The store used to persist the machine state.
|
|
357
|
+
* @property {Array<string>} eventTypes - The types of events to be persisted.
|
|
358
|
+
*/
|
|
359
|
+
export declare type MachineStatePersistOpts = {
|
|
360
|
+
store?: IAbstractMachineStateStore;
|
|
361
|
+
eventTypes: Array<string>;
|
|
362
|
+
isRESTClient?: boolean;
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Persist the initial state of a machine and register it with the given machine instance.
|
|
367
|
+
*
|
|
368
|
+
* @param {InitMachineStateArgs & {instance: Interpreter<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>, context: IAgentContext<any>}} args - The options for initializing
|
|
369
|
+
* machine state and registering it.
|
|
370
|
+
* @returns {Promise<MachineStateInit | undefined>} - A promise that resolves to the initial state of the machine, or undefined if the agent isn't using the Xstate plugin.
|
|
371
|
+
*/
|
|
372
|
+
export declare const machineStatePersistRegistration: <TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
373
|
+
value: any;
|
|
374
|
+
context: TContext;
|
|
375
|
+
}, TResolvedTypesMeta = TypegenDisabled>(args: Omit<InitMachineStateArgs, "machineName"> & Partial<Pick<InitMachineStateArgs, "machineName">> & MachineStatePersistenceOpts & {
|
|
376
|
+
cleanupOnFinalState?: boolean;
|
|
377
|
+
cleanupAllOtherInstances?: boolean;
|
|
378
|
+
interpreter: Interpreter<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>;
|
|
379
|
+
context: IAgentContext<any>;
|
|
380
|
+
}) => Promise<MachineStateInit | undefined>;
|
|
381
|
+
|
|
382
|
+
export declare const machineStateToMachineInit: (machineInfo: MachineStatePersistArgs, existingState: Partial<StoreMachineStateInfo>) => MachineStateInit;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Create a machine state info object useful for the store, based on the provided machine info and existing state.
|
|
386
|
+
*
|
|
387
|
+
* @param {MachineStatePersistArgs} machineInfo - The machine info object.
|
|
388
|
+
* @param {Partial<StoreMachineStateInfo>} [existingState] - The optional existing state object.
|
|
389
|
+
* @returns {StoreMachineStateInfo} - The store machine state info object.
|
|
390
|
+
*/
|
|
391
|
+
export declare const machineStateToStoreInfo: (machineInfo: MachineStatePersistArgs, existingState?: Partial<StoreMachineStateInfo>) => StoreMachineStateInfo;
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Represents a RequiredContext class, which is a type definition for the context required by an agent.
|
|
395
|
+
* It is used to enforce that the agent context implements the necessary interfaces.
|
|
396
|
+
*
|
|
397
|
+
* @typeparam T - The type of the machine state persistence.
|
|
398
|
+
*/
|
|
399
|
+
export declare type RequiredContext = IAgentContext<IMachineStatePersistence>;
|
|
400
|
+
|
|
401
|
+
export declare const schema: any;
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Represents the serializable state of a machine.
|
|
405
|
+
*
|
|
406
|
+
* @typedef {Object} SerializableState@typedef {Object} SerializableState
|
|
407
|
+
* @property {XStateConfig<any, AnyEventObject>} config - The machine configuration.
|
|
408
|
+
*/
|
|
409
|
+
export declare type SerializableState = XStateConfig<any, AnyEventObject>;
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Serializes a machine state to a string representation.
|
|
413
|
+
*
|
|
414
|
+
* @param {State<T, TEvent> | SerializableState | string} state - The machine state to serialize.
|
|
415
|
+
* @returns {string} - The serialized machine state.
|
|
416
|
+
*/
|
|
417
|
+
export declare const serializeMachineState: <T, TEvent extends EventObject_2>(state: State<T, TEvent> | SerializableState | string) => string;
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Represents the information for a started interpreter.
|
|
421
|
+
*
|
|
422
|
+
* @template TContext The type of the context object.
|
|
423
|
+
* @template TStateSchema The type of the state schema.
|
|
424
|
+
* @template TEvent The type of the event object.
|
|
425
|
+
* @template TTypestate The type of the typestate object.
|
|
426
|
+
* @template TResolvedTypesMeta The type of the resolved types meta object.
|
|
427
|
+
*/
|
|
428
|
+
export declare type StartedInterpreterInfo<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
429
|
+
value: any;
|
|
430
|
+
context: TContext;
|
|
431
|
+
}, TResolvedTypesMeta = TypegenDisabled> = {
|
|
432
|
+
interpreter: Interpreter<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>;
|
|
433
|
+
machineState?: MachineStateInfo;
|
|
434
|
+
init: MachineStateInit;
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
export declare const storeInfoToMachineInit: (args: StoreMachineStateInfo & {
|
|
438
|
+
stateType: MachineStateInitType;
|
|
439
|
+
machineState?: MachineStateInfo;
|
|
440
|
+
}) => MachineStateInit;
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* The configuration for the XState machine state. Simplified StateConfig object from XState so we have a minimal typed structure
|
|
444
|
+
*
|
|
445
|
+
* @template TContext - The context type for the state.
|
|
446
|
+
* @template TEvent - The event type for the state.
|
|
447
|
+
*/
|
|
448
|
+
export declare interface XStateConfig<TContext, TEvent extends EventObject> {
|
|
449
|
+
value: StateValue;
|
|
450
|
+
context: TContext;
|
|
451
|
+
_event: SCXML.Event<TEvent>;
|
|
452
|
+
_sessionid: string | null;
|
|
453
|
+
historyValue?: HistoryValue | undefined;
|
|
454
|
+
history?: any;
|
|
455
|
+
actions?: Array<any>;
|
|
456
|
+
activities?: any;
|
|
457
|
+
meta?: any;
|
|
458
|
+
events?: TEvent[];
|
|
459
|
+
configuration: Array<any>;
|
|
460
|
+
transitions: Array<any>;
|
|
461
|
+
children: Record<string, any>;
|
|
462
|
+
done?: boolean;
|
|
463
|
+
tags?: Set<string>;
|
|
464
|
+
machine?: any;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
export { }
|