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