@sphereon/ssi-sdk.xstate-machine-persistence 0.32.1-next.54 → 0.33.1-feature.jose.vcdm.55

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.
Files changed (45) hide show
  1. package/dist/index.cjs +1065 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/{ssi-sdk.xstate-machine-persistence.d.ts → index.d.cts} +426 -467
  4. package/dist/index.d.ts +425 -5
  5. package/dist/index.js +1033 -21
  6. package/dist/index.js.map +1 -1
  7. package/package.json +25 -14
  8. package/plugin.schema.json +76 -265
  9. package/src/__tests__/localAgent.test.ts +1 -0
  10. package/src/__tests__/restAgent.test.ts +4 -1
  11. package/src/__tests__/shared/MachineStatePersistenceAgentLogic.ts +1 -0
  12. package/dist/agent/MachineStatePersistence.d.ts +0 -26
  13. package/dist/agent/MachineStatePersistence.d.ts.map +0 -1
  14. package/dist/agent/MachineStatePersistence.js +0 -197
  15. package/dist/agent/MachineStatePersistence.js.map +0 -1
  16. package/dist/functions/index.d.ts +0 -4
  17. package/dist/functions/index.d.ts.map +0 -1
  18. package/dist/functions/index.js +0 -20
  19. package/dist/functions/index.js.map +0 -1
  20. package/dist/functions/machineRegistration.d.ts +0 -130
  21. package/dist/functions/machineRegistration.d.ts.map +0 -1
  22. package/dist/functions/machineRegistration.js +0 -303
  23. package/dist/functions/machineRegistration.js.map +0 -1
  24. package/dist/functions/stateEventEmitter.d.ts +0 -10
  25. package/dist/functions/stateEventEmitter.d.ts.map +0 -1
  26. package/dist/functions/stateEventEmitter.js +0 -21
  27. package/dist/functions/stateEventEmitter.js.map +0 -1
  28. package/dist/functions/stateMapper.d.ts +0 -34
  29. package/dist/functions/stateMapper.d.ts.map +0 -1
  30. package/dist/functions/stateMapper.js +0 -83
  31. package/dist/functions/stateMapper.js.map +0 -1
  32. package/dist/index.d.ts.map +0 -1
  33. package/dist/tsdoc-metadata.json +0 -11
  34. package/dist/types/IMachineStatePersistence.d.ts +0 -62
  35. package/dist/types/IMachineStatePersistence.d.ts.map +0 -1
  36. package/dist/types/IMachineStatePersistence.js +0 -3
  37. package/dist/types/IMachineStatePersistence.js.map +0 -1
  38. package/dist/types/index.d.ts +0 -3
  39. package/dist/types/index.d.ts.map +0 -1
  40. package/dist/types/index.js +0 -19
  41. package/dist/types/index.js.map +0 -1
  42. package/dist/types/types.d.ts +0 -173
  43. package/dist/types/types.d.ts.map +0 -1
  44. package/dist/types/types.js +0 -13
  45. package/dist/types/types.js.map +0 -1
@@ -3,6 +3,9 @@
3
3
  "components": {
4
4
  "schemas": {
5
5
  "MachineStateDeleteArgs": {
6
+ "$ref": "#/components/schemas/Pick<StoreMachineStateInfo,(\"instanceId\"|\"tenantId\")>"
7
+ },
8
+ "Pick<StoreMachineStateInfo,(\"instanceId\"|\"tenantId\")>": {
6
9
  "type": "object",
7
10
  "properties": {
8
11
  "instanceId": {
@@ -15,25 +18,15 @@
15
18
  },
16
19
  "required": [
17
20
  "instanceId"
18
- ]
21
+ ],
22
+ "additionalProperties": false
19
23
  },
20
24
  "MachineStateGetArgs": {
21
- "type": "object",
22
- "properties": {
23
- "instanceId": {
24
- "type": "string",
25
- "description": "Unique instance ID of the machine"
26
- },
27
- "tenantId": {
28
- "type": "string"
29
- }
30
- },
31
- "required": [
32
- "instanceId"
33
- ]
25
+ "$ref": "#/components/schemas/Pick<StoreMachineStateInfo,(\"instanceId\"|\"tenantId\")>"
34
26
  },
35
27
  "MachineStateInfo": {
36
28
  "type": "object",
29
+ "additionalProperties": false,
37
30
  "properties": {
38
31
  "state": {
39
32
  "$ref": "#/components/schemas/SerializableState"
@@ -136,21 +129,13 @@
136
129
  "items": {}
137
130
  },
138
131
  "children": {
139
- "type": "object"
132
+ "$ref": "#/components/schemas/Record<string,any>"
140
133
  },
141
134
  "done": {
142
135
  "type": "boolean"
143
136
  },
144
137
  "tags": {
145
- "type": "object",
146
- "properties": {
147
- "size": {
148
- "type": "number"
149
- }
150
- },
151
- "required": [
152
- "size"
153
- ]
138
+ "$ref": "#/components/schemas/Set<string>"
154
139
  },
155
140
  "machine": {}
156
141
  },
@@ -163,6 +148,7 @@
163
148
  "transitions",
164
149
  "children"
165
150
  ],
151
+ "additionalProperties": false,
166
152
  "description": "The configuration for the XState machine state. Simplified StateConfig object from XState so we have a minimal typed structure"
167
153
  },
168
154
  "StateValue": {
@@ -228,7 +214,8 @@
228
214
  "type",
229
215
  "data",
230
216
  "$$type"
231
- ]
217
+ ],
218
+ "additionalProperties": false
232
219
  },
233
220
  "AnyEventObject": {
234
221
  "type": "object",
@@ -246,17 +233,7 @@
246
233
  "type": "object",
247
234
  "properties": {
248
235
  "states": {
249
- "type": "object",
250
- "additionalProperties": {
251
- "anyOf": [
252
- {
253
- "$ref": "#/components/schemas/HistoryValue"
254
- },
255
- {
256
- "not": {}
257
- }
258
- ]
259
- }
236
+ "$ref": "#/components/schemas/Record<string,(interface-434048446-6094-6223-434048446-0-57488|undefined)>"
260
237
  },
261
238
  "current": {
262
239
  "$ref": "#/components/schemas/StateValue"
@@ -264,10 +241,40 @@
264
241
  },
265
242
  "required": [
266
243
  "states"
267
- ]
244
+ ],
245
+ "additionalProperties": false
246
+ },
247
+ "Record<string,(interface-434048446-6094-6223-434048446-0-57488|undefined)>": {
248
+ "type": "object",
249
+ "additionalProperties": {
250
+ "anyOf": [
251
+ {
252
+ "$ref": "#/components/schemas/HistoryValue"
253
+ },
254
+ {
255
+ "not": {}
256
+ }
257
+ ]
258
+ }
259
+ },
260
+ "Record<string,any>": {
261
+ "type": "object"
262
+ },
263
+ "Set<string>": {
264
+ "type": "object",
265
+ "properties": {
266
+ "size": {
267
+ "type": "number"
268
+ }
269
+ },
270
+ "required": [
271
+ "size"
272
+ ],
273
+ "additionalProperties": false
268
274
  },
269
275
  "InitMachineStateArgs": {
270
276
  "type": "object",
277
+ "additionalProperties": false,
271
278
  "properties": {
272
279
  "cleanupAllOtherInstances": {
273
280
  "type": "boolean"
@@ -279,16 +286,14 @@
279
286
  "type": "string"
280
287
  },
281
288
  "machineName": {
282
- "type": "object",
283
- "properties": {},
289
+ "type": "string",
284
290
  "description": "Machine name"
285
291
  },
286
292
  "tenantId": {
287
293
  "type": "string"
288
294
  },
289
295
  "createdAt": {
290
- "type": "object",
291
- "properties": {},
296
+ "type": "string",
292
297
  "description": "Represents the creation date"
293
298
  },
294
299
  "expiresAt": {
@@ -296,84 +301,26 @@
296
301
  "description": "Represents the expiration date"
297
302
  },
298
303
  "stateType": {
299
- "anyOf": [
300
- {
301
- "type": "object",
302
- "properties": {}
303
- },
304
- {
305
- "type": "object",
306
- "properties": {}
307
- }
308
- ]
304
+ "$ref": "#/components/schemas/MachineStateInitType"
309
305
  },
310
306
  "machineState": {
311
- "type": "object",
312
- "properties": {
313
- "state": {
314
- "$ref": "#/components/schemas/SerializableState"
315
- },
316
- "instanceId": {
317
- "type": "string",
318
- "description": "Unique instance ID of the machine"
319
- },
320
- "sessionId": {
321
- "type": "string",
322
- "description": "Session Id of the machine. Not necessarily unique"
323
- },
324
- "machineName": {
325
- "type": "string",
326
- "description": "Machine name"
327
- },
328
- "latestStateName": {
329
- "type": "string",
330
- "description": "The latest state name. Can be empty for a newly initialize machine"
331
- },
332
- "latestEventType": {
333
- "type": "string",
334
- "description": "event types like SET_TOC, SET_FIRSTNAME, .... Will be xstate.init on a newly initialized machine"
335
- },
336
- "createdAt": {
337
- "type": "string",
338
- "description": "Represents the creation date"
339
- },
340
- "expiresAt": {
341
- "type": "string",
342
- "description": "Represents the expiration date"
343
- },
344
- "updatedAt": {
345
- "type": "string",
346
- "description": "Represents the update date"
347
- },
348
- "updatedCount": {
349
- "type": "number",
350
- "description": "Represents a counter for tracking updates."
351
- },
352
- "completedAt": {
353
- "type": "string",
354
- "format": "date-time"
355
- },
356
- "tenantId": {
357
- "type": "string"
358
- }
359
- },
360
- "required": [
361
- "createdAt",
362
- "instanceId",
363
- "latestEventType",
364
- "machineName",
365
- "state",
366
- "updatedAt",
367
- "updatedCount"
368
- ]
307
+ "$ref": "#/components/schemas/MachineStateInfo"
369
308
  }
370
309
  },
371
310
  "required": [
372
311
  "machineName"
373
312
  ]
374
313
  },
314
+ "MachineStateInitType": {
315
+ "type": "string",
316
+ "enum": [
317
+ "new",
318
+ "existing"
319
+ ]
320
+ },
375
321
  "MachineStateInit": {
376
322
  "type": "object",
323
+ "additionalProperties": false,
377
324
  "properties": {
378
325
  "stateType": {
379
326
  "$ref": "#/components/schemas/MachineStateInitType"
@@ -382,21 +329,18 @@
382
329
  "$ref": "#/components/schemas/MachineStateInfo"
383
330
  },
384
331
  "instanceId": {
385
- "type": "object",
386
- "properties": {},
332
+ "type": "string",
387
333
  "description": "Unique instance ID of the machine"
388
334
  },
389
335
  "machineName": {
390
- "type": "object",
391
- "properties": {},
336
+ "type": "string",
392
337
  "description": "Machine name"
393
338
  },
394
339
  "tenantId": {
395
340
  "type": "string"
396
341
  },
397
342
  "createdAt": {
398
- "type": "object",
399
- "properties": {},
343
+ "type": "string",
400
344
  "description": "Represents the creation date"
401
345
  },
402
346
  "expiresAt": {
@@ -411,101 +355,26 @@
411
355
  "stateType"
412
356
  ]
413
357
  },
414
- "MachineStateInitType": {
415
- "type": "string",
416
- "enum": [
417
- "new",
418
- "existing"
419
- ]
420
- },
421
358
  "MachineStatePersistArgs": {
422
359
  "type": "object",
360
+ "additionalProperties": false,
423
361
  "properties": {
424
362
  "cleanupOnFinalState": {
425
363
  "type": "boolean"
426
364
  },
427
365
  "updatedCount": {
428
- "type": "object",
429
- "properties": {},
366
+ "type": "number",
430
367
  "description": "Represents a counter for tracking updates."
431
368
  },
432
369
  "state": {
433
- "type": "object",
434
- "properties": {
435
- "value": {
436
- "$ref": "#/components/schemas/StateValue"
437
- },
438
- "context": {},
439
- "_event": {
440
- "$ref": "#/components/schemas/SCXML.Event<AnyEventObject>"
441
- },
442
- "_sessionid": {
443
- "type": [
444
- "string",
445
- "null"
446
- ]
447
- },
448
- "historyValue": {
449
- "$ref": "#/components/schemas/HistoryValue"
450
- },
451
- "history": {},
452
- "actions": {
453
- "type": "array",
454
- "items": {}
455
- },
456
- "activities": {},
457
- "meta": {},
458
- "events": {
459
- "type": "array",
460
- "items": {
461
- "$ref": "#/components/schemas/AnyEventObject"
462
- }
463
- },
464
- "configuration": {
465
- "type": "array",
466
- "items": {}
467
- },
468
- "transitions": {
469
- "type": "array",
470
- "items": {}
471
- },
472
- "children": {
473
- "type": "object"
474
- },
475
- "done": {
476
- "type": "boolean"
477
- },
478
- "tags": {
479
- "type": "object",
480
- "properties": {
481
- "size": {
482
- "type": "number"
483
- }
484
- },
485
- "required": [
486
- "size"
487
- ]
488
- },
489
- "machine": {}
490
- },
491
- "required": [
492
- "_event",
493
- "_sessionid",
494
- "children",
495
- "configuration",
496
- "context",
497
- "transitions",
498
- "value"
499
- ]
370
+ "$ref": "#/components/schemas/SerializableState"
500
371
  },
501
372
  "instanceId": {
502
- "type": "object",
503
- "properties": {},
373
+ "type": "string",
504
374
  "description": "Unique instance ID of the machine"
505
375
  },
506
376
  "machineName": {
507
- "type": "object",
508
- "properties": {},
377
+ "type": "string",
509
378
  "description": "Machine name"
510
379
  },
511
380
  "tenantId": {
@@ -516,76 +385,10 @@
516
385
  "description": "Represents the expiration date"
517
386
  },
518
387
  "stateType": {
519
- "anyOf": [
520
- {
521
- "type": "object",
522
- "properties": {}
523
- },
524
- {
525
- "type": "object",
526
- "properties": {}
527
- }
528
- ]
388
+ "$ref": "#/components/schemas/MachineStateInitType"
529
389
  },
530
390
  "machineState": {
531
- "type": "object",
532
- "properties": {
533
- "state": {
534
- "$ref": "#/components/schemas/SerializableState"
535
- },
536
- "instanceId": {
537
- "type": "string",
538
- "description": "Unique instance ID of the machine"
539
- },
540
- "sessionId": {
541
- "type": "string",
542
- "description": "Session Id of the machine. Not necessarily unique"
543
- },
544
- "machineName": {
545
- "type": "string",
546
- "description": "Machine name"
547
- },
548
- "latestStateName": {
549
- "type": "string",
550
- "description": "The latest state name. Can be empty for a newly initialize machine"
551
- },
552
- "latestEventType": {
553
- "type": "string",
554
- "description": "event types like SET_TOC, SET_FIRSTNAME, .... Will be xstate.init on a newly initialized machine"
555
- },
556
- "createdAt": {
557
- "type": "string",
558
- "description": "Represents the creation date"
559
- },
560
- "expiresAt": {
561
- "type": "string",
562
- "description": "Represents the expiration date"
563
- },
564
- "updatedAt": {
565
- "type": "string",
566
- "description": "Represents the update date"
567
- },
568
- "updatedCount": {
569
- "type": "number",
570
- "description": "Represents a counter for tracking updates."
571
- },
572
- "completedAt": {
573
- "type": "string",
574
- "format": "date-time"
575
- },
576
- "tenantId": {
577
- "type": "string"
578
- }
579
- },
580
- "required": [
581
- "createdAt",
582
- "instanceId",
583
- "latestEventType",
584
- "machineName",
585
- "state",
586
- "updatedAt",
587
- "updatedCount"
588
- ]
391
+ "$ref": "#/components/schemas/MachineStateInfo"
589
392
  }
590
393
  },
591
394
  "required": [
@@ -597,6 +400,10 @@
597
400
  "description": "Represents the arguments required to persist the machine state."
598
401
  },
599
402
  "DeleteExpiredStatesArgs": {
403
+ "$ref": "#/components/schemas/Pick<StoreMachineStateDeleteExpiredArgs,(\"deleteDoneStates\"|\"machineName\"|\"tenantId\")>",
404
+ "description": "Represents the arguments for deleting expired states from a machine."
405
+ },
406
+ "Pick<StoreMachineStateDeleteExpiredArgs,(\"deleteDoneStates\"|\"machineName\"|\"tenantId\")>": {
600
407
  "type": "object",
601
408
  "properties": {
602
409
  "deleteDoneStates": {
@@ -609,7 +416,7 @@
609
416
  "type": "string"
610
417
  }
611
418
  },
612
- "description": "Represents the arguments for deleting expired states from a machine."
419
+ "additionalProperties": false
613
420
  },
614
421
  "DeleteStateResult": {
615
422
  "type": "number"
@@ -619,6 +426,9 @@
619
426
  "description": "Represents the arguments for finding active states of a store machine."
620
427
  },
621
428
  "StoreMachineStatesFindActiveArgs": {
429
+ "$ref": "#/components/schemas/Partial<Pick<StoreMachineStateInfo,(\"machineName\"|\"tenantId\"|\"instanceId\")>>"
430
+ },
431
+ "Partial<Pick<StoreMachineStateInfo,(\"machineName\"|\"tenantId\"|\"instanceId\")>>": {
622
432
  "type": "object",
623
433
  "properties": {
624
434
  "machineName": {
@@ -632,7 +442,8 @@
632
442
  "type": "string",
633
443
  "description": "Unique instance ID of the machine"
634
444
  }
635
- }
445
+ },
446
+ "additionalProperties": false
636
447
  }
637
448
  },
638
449
  "methods": {
@@ -2,6 +2,7 @@ import { DataSource } from 'typeorm'
2
2
  import { createObjects, getConfig } from '@sphereon/ssi-sdk.agent-config'
3
3
 
4
4
  import machineStatePersistenceAgentLogic from './shared/MachineStatePersistenceAgentLogic'
5
+ import { describe } from 'vitest'
5
6
 
6
7
  let dbConnection: Promise<DataSource>
7
8
  let agent: any
@@ -9,6 +9,7 @@ import { DataSource } from 'typeorm'
9
9
  import { createObjects, getConfig } from '@sphereon/ssi-sdk.agent-config'
10
10
  import { IMachineStatePersistence, MachineStatePersistence, MachineStatePersistEventType } from '../index'
11
11
  import xStatePersistenceAgentLogic from './shared/MachineStatePersistenceAgentLogic'
12
+ import { describe } from 'vitest'
12
13
 
13
14
  const port = 6403
14
15
  const basePath = '/agent'
@@ -58,7 +59,9 @@ const setup = async (): Promise<boolean> => {
58
59
 
59
60
  const tearDown = async (): Promise<boolean> => {
60
61
  restServer?.close()
61
- await (await dbConnection).destroy()
62
+ if (dbConnection) {
63
+ await (await dbConnection)?.destroy()
64
+ }
62
65
  return true
63
66
  }
64
67
 
@@ -12,6 +12,7 @@ import {
12
12
  TypegenDisabled,
13
13
  } from 'xstate'
14
14
  import { IMachineStatePersistence, interpreterStartOrResume, MachineStatePersistArgs, machineStatePersistRegistration } from '../../index'
15
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest'
15
16
 
16
17
  type ConfiguredAgent = TAgent<IMachineStatePersistence>
17
18
 
@@ -1,26 +0,0 @@
1
- import { IAbstractMachineStateStore } from '@sphereon/ssi-sdk.data-store';
2
- import { IAgentPlugin } from '@veramo/core';
3
- import { IMachineStatePersistence, MachineStatePersistEvent, MachineStatePersistOpts, RequiredContext } from '../index';
4
- /**
5
- * This class implements the IMachineStatePersistence interface using a datastore.
6
- *
7
- * This allows you to store and retrieve the State of a state machine/application by their types.
8
- *
9
- * @beta This API may change without a BREAKING CHANGE notice.
10
- */
11
- export declare class MachineStatePersistence implements IAgentPlugin {
12
- readonly schema: any;
13
- readonly methods: IMachineStatePersistence | {};
14
- readonly eventTypes: Array<string>;
15
- private readonly _store?;
16
- get store(): IAbstractMachineStateStore;
17
- constructor(opts: MachineStatePersistOpts);
18
- onEvent(event: MachineStatePersistEvent, context: RequiredContext): Promise<void>;
19
- private machineStateInit;
20
- private machineStatePersist;
21
- private machineStatesFindActive;
22
- private machineStatesDeleteExpired;
23
- private machineStateGet;
24
- private machineStateDelete;
25
- }
26
- //# sourceMappingURL=MachineStatePersistence.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MachineStatePersistence.d.ts","sourceRoot":"","sources":["../../src/agent/MachineStatePersistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAyB,MAAM,8BAA8B,CAAA;AAChG,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAK3C,OAAO,EAIL,wBAAwB,EAOxB,wBAAwB,EAExB,uBAAuB,EACvB,eAAe,EAEhB,MAAM,UAAU,CAAA;AAIjB;;;;;;GAMG;AACH,qBAAa,uBAAwB,YAAW,YAAY;IAC1D,QAAQ,CAAC,MAAM,MAAkC;IACjD,QAAQ,CAAC,OAAO,EAAE,wBAAwB,GAAG,EAAE,CAAA;IAC/C,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAA4B;IAEpD,IAAI,KAAK,IAAI,0BAA0B,CAKtC;gBAEW,IAAI,EAAE,uBAAuB;IAqB5B,OAAO,CAAC,KAAK,EAAE,wBAAwB,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;YAyBhF,gBAAgB;YA2DhB,mBAAmB;YAiCnB,uBAAuB;YAWvB,0BAA0B;YAQ1B,eAAe;YASf,kBAAkB;CAOjC"}