@twin.org/auditable-item-stream-service 0.0.1-next.8 → 0.0.1

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 (29) hide show
  1. package/dist/cjs/index.cjs +510 -305
  2. package/dist/esm/index.mjs +512 -308
  3. package/dist/types/auditableItemStreamRoutes.d.ts +9 -1
  4. package/dist/types/auditableItemStreamService.d.ts +45 -38
  5. package/dist/types/entities/auditableItemStream.d.ts +1 -1
  6. package/dist/types/index.d.ts +2 -1
  7. package/dist/types/models/IAuditableItemStreamServiceConstructorOptions.d.ts +29 -0
  8. package/docs/changelog.md +199 -1
  9. package/docs/open-api/spec.json +2272 -2123
  10. package/docs/reference/classes/AuditableItemStream.md +5 -5
  11. package/docs/reference/classes/AuditableItemStreamEntry.md +3 -3
  12. package/docs/reference/classes/AuditableItemStreamService.md +233 -95
  13. package/docs/reference/functions/auditableItemStreamCreate.md +9 -3
  14. package/docs/reference/functions/auditableItemStreamCreateEntry.md +9 -3
  15. package/docs/reference/functions/auditableItemStreamDelete.md +31 -0
  16. package/docs/reference/functions/auditableItemStreamDeleteEntry.md +9 -3
  17. package/docs/reference/functions/auditableItemStreamGet.md +9 -3
  18. package/docs/reference/functions/auditableItemStreamGetEntry.md +9 -3
  19. package/docs/reference/functions/auditableItemStreamGetEntryObject.md +9 -3
  20. package/docs/reference/functions/auditableItemStreamList.md +9 -3
  21. package/docs/reference/functions/auditableItemStreamListEntries.md +9 -3
  22. package/docs/reference/functions/auditableItemStreamListEntryObjects.md +9 -3
  23. package/docs/reference/functions/auditableItemStreamUpdate.md +9 -3
  24. package/docs/reference/functions/auditableItemStreamUpdateEntry.md +9 -3
  25. package/docs/reference/functions/generateRestRoutesAuditableItemStream.md +8 -4
  26. package/docs/reference/index.md +2 -0
  27. package/docs/reference/interfaces/IAuditableItemStreamServiceConstructorOptions.md +61 -0
  28. package/locales/en.json +3 -1
  29. package/package.json +59 -18
@@ -3,9 +3,9 @@
3
3
  var apiModels = require('@twin.org/api-models');
4
4
  var auditableItemStreamModels = require('@twin.org/auditable-item-stream-models');
5
5
  var core = require('@twin.org/core');
6
+ var standardsSchemaOrg = require('@twin.org/standards-schema-org');
6
7
  var web = require('@twin.org/web');
7
8
  var dataJsonLd = require('@twin.org/data-json-ld');
8
- var dataSchemaOrg = require('@twin.org/data-schema-org');
9
9
  var entity = require('@twin.org/entity');
10
10
  var entityStorageModels = require('@twin.org/entity-storage-models');
11
11
  var immutableProofModels = require('@twin.org/immutable-proof-models');
@@ -46,15 +46,15 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
46
46
  id: "auditableItemStreamCreateRequestExample",
47
47
  request: {
48
48
  body: {
49
- streamObject: {
50
- "@context": "http://schema.org/",
49
+ annotationObject: {
50
+ "@context": "https://schema.org",
51
51
  "@type": "Note",
52
52
  content: "This is a simple note"
53
53
  },
54
54
  entries: [
55
55
  {
56
56
  entryObject: {
57
- "@context": "http://schema.org/",
57
+ "@context": "https://schema.org",
58
58
  "@type": "Event",
59
59
  startDate: "2011-04-09T20:00:00Z",
60
60
  description: "A description of the event"
@@ -115,13 +115,16 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
115
115
  id: "auditableItemStreamGetResponseExample",
116
116
  response: {
117
117
  body: {
118
- "@context": auditableItemStreamModels.AuditableItemStreamTypes.ContextRoot,
118
+ "@context": [
119
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRoot,
120
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRootCommon
121
+ ],
119
122
  type: auditableItemStreamModels.AuditableItemStreamTypes.Stream,
120
123
  id: "ais:1234567890",
121
124
  dateCreated: "2024-08-22T11:55:16.271Z",
122
125
  dateModified: "2024-08-22T11:55:16.271Z",
123
- streamObject: {
124
- "@context": "http://schema.org/",
126
+ annotationObject: {
127
+ "@context": "https://schema.org",
125
128
  "@type": "Note",
126
129
  content: "This is a simple note"
127
130
  },
@@ -131,14 +134,17 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
131
134
  immutableInterval: 10,
132
135
  entries: [
133
136
  {
134
- "@context": auditableItemStreamModels.AuditableItemStreamTypes.ContextRoot,
137
+ "@context": [
138
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRoot,
139
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRootCommon
140
+ ],
135
141
  type: auditableItemStreamModels.AuditableItemStreamTypes.StreamEntry,
136
142
  id: "tst:1234567890",
137
143
  dateCreated: "2024-08-22T11:55:16.271Z",
138
144
  proofId: "0101010101010101010101010101010101010101010101010101010101010101",
139
145
  index: 0,
140
146
  entryObject: {
141
- "@context": "http://schema.org/",
147
+ "@context": "https://schema.org",
142
148
  "@type": "Event",
143
149
  startDate: "2011-04-09T20:00:00Z",
144
150
  description: "A description of the event"
@@ -161,13 +167,16 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
161
167
  [web.HeaderTypes.ContentType]: web.MimeTypes.JsonLd
162
168
  },
163
169
  body: {
164
- "@context": auditableItemStreamModels.AuditableItemStreamTypes.ContextRoot,
170
+ "@context": [
171
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRoot,
172
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRootCommon
173
+ ],
165
174
  type: auditableItemStreamModels.AuditableItemStreamTypes.Stream,
166
175
  id: "ais:1234567890",
167
176
  dateCreated: "2024-08-22T11:55:16.271Z",
168
177
  dateModified: "2024-08-22T11:55:16.271Z",
169
- streamObject: {
170
- "@context": "http://schema.org/",
178
+ annotationObject: {
179
+ "@context": "https://schema.org",
171
180
  "@type": "Note",
172
181
  content: "This is a simple note"
173
182
  },
@@ -177,14 +186,17 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
177
186
  immutableInterval: 10,
178
187
  entries: [
179
188
  {
180
- "@context": auditableItemStreamModels.AuditableItemStreamTypes.ContextRoot,
189
+ "@context": [
190
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRoot,
191
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRootCommon
192
+ ],
181
193
  type: auditableItemStreamModels.AuditableItemStreamTypes.StreamEntry,
182
194
  id: "tst:1234567890",
183
195
  dateCreated: "2024-08-22T11:55:16.271Z",
184
196
  proofId: "0101010101010101010101010101010101010101010101010101010101010101",
185
197
  index: 0,
186
198
  entryObject: {
187
- "@context": "http://schema.org/",
199
+ "@context": "https://schema.org",
188
200
  "@type": "Event",
189
201
  startDate: "2011-04-09T20:00:00Z",
190
202
  description: "A description of the event"
@@ -218,8 +230,8 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
218
230
  id: "ais:1234567890"
219
231
  },
220
232
  body: {
221
- streamObject: {
222
- "@context": "http://schema.org/",
233
+ annotationObject: {
234
+ "@context": "https://schema.org",
223
235
  "@type": "Note",
224
236
  content: "This is a simple note"
225
237
  }
@@ -237,6 +249,35 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
237
249
  }
238
250
  ]
239
251
  };
252
+ const deleteRoute = {
253
+ operationId: "auditableItemStreamDelete",
254
+ summary: "Delete a stream",
255
+ tag: tagsAuditableItemStream[0].name,
256
+ method: "DELETE",
257
+ path: `${baseRouteName}/:id`,
258
+ handler: async (httpRequestContext, request) => auditableItemStreamDelete(httpRequestContext, componentName, request),
259
+ requestType: {
260
+ type: "IAuditableItemStreamDeleteRequest",
261
+ examples: [
262
+ {
263
+ id: "auditableItemStreamDeleteRequestExample",
264
+ request: {
265
+ pathParams: {
266
+ id: "ais:1234567890"
267
+ }
268
+ }
269
+ }
270
+ ]
271
+ },
272
+ responseType: [
273
+ {
274
+ type: "INoContentResponse"
275
+ },
276
+ {
277
+ type: "INotFoundResponse"
278
+ }
279
+ ]
280
+ };
240
281
  const listRoute = {
241
282
  operationId: "auditableItemStreamList",
242
283
  summary: "Query streams",
@@ -261,17 +302,24 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
261
302
  id: "auditableItemStreamListResponseExample",
262
303
  response: {
263
304
  body: {
264
- "@context": auditableItemStreamModels.AuditableItemStreamTypes.ContextRoot,
265
- type: auditableItemStreamModels.AuditableItemStreamTypes.StreamList,
266
- streams: [
305
+ "@context": [
306
+ standardsSchemaOrg.SchemaOrgContexts.ContextRoot,
307
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRoot,
308
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRootCommon
309
+ ],
310
+ type: [standardsSchemaOrg.SchemaOrgTypes.ItemList, auditableItemStreamModels.AuditableItemStreamTypes.StreamList],
311
+ [standardsSchemaOrg.SchemaOrgTypes.ItemListElement]: [
267
312
  {
268
- "@context": auditableItemStreamModels.AuditableItemStreamTypes.ContextRoot,
313
+ "@context": [
314
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRoot,
315
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRootCommon
316
+ ],
269
317
  type: auditableItemStreamModels.AuditableItemStreamTypes.Stream,
270
318
  id: "ais:1234567890",
271
319
  dateCreated: "2024-08-22T11:55:16.271Z",
272
320
  dateModified: "2024-08-22T11:55:16.271Z",
273
- streamObject: {
274
- "@context": "http://schema.org/",
321
+ annotationObject: {
322
+ "@context": "https://schema.org",
275
323
  "@type": "Note",
276
324
  content: "This is a simple note"
277
325
  },
@@ -281,7 +329,7 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
281
329
  immutableInterval: 10
282
330
  }
283
331
  ],
284
- cursor: "1"
332
+ [standardsSchemaOrg.SchemaOrgTypes.NextItem]: "1"
285
333
  }
286
334
  }
287
335
  }
@@ -298,17 +346,24 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
298
346
  [web.HeaderTypes.ContentType]: web.MimeTypes.JsonLd
299
347
  },
300
348
  body: {
301
- "@context": auditableItemStreamModels.AuditableItemStreamTypes.ContextRoot,
302
- type: auditableItemStreamModels.AuditableItemStreamTypes.StreamList,
303
- streams: [
349
+ "@context": [
350
+ standardsSchemaOrg.SchemaOrgContexts.ContextRoot,
351
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRoot,
352
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRootCommon
353
+ ],
354
+ type: [standardsSchemaOrg.SchemaOrgTypes.ItemList, auditableItemStreamModels.AuditableItemStreamTypes.StreamList],
355
+ [standardsSchemaOrg.SchemaOrgTypes.ItemListElement]: [
304
356
  {
305
- "@context": auditableItemStreamModels.AuditableItemStreamTypes.ContextRoot,
357
+ "@context": [
358
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRoot,
359
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRootCommon
360
+ ],
306
361
  type: auditableItemStreamModels.AuditableItemStreamTypes.Stream,
307
362
  id: "ais:1234567890",
308
363
  dateCreated: "2024-08-22T11:55:16.271Z",
309
364
  dateModified: "2024-08-22T11:55:16.271Z",
310
- streamObject: {
311
- "@context": "http://schema.org/",
365
+ annotationObject: {
366
+ "@context": "https://schema.org",
312
367
  "@type": "Note",
313
368
  content: "This is a simple note"
314
369
  },
@@ -318,7 +373,7 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
318
373
  immutableInterval: 10
319
374
  }
320
375
  ],
321
- cursor: "1"
376
+ [standardsSchemaOrg.SchemaOrgTypes.NextItem]: "1"
322
377
  }
323
378
  }
324
379
  }
@@ -347,7 +402,7 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
347
402
  },
348
403
  body: {
349
404
  entryObject: {
350
- "@context": "http://schema.org/",
405
+ "@context": "https://schema.org",
351
406
  "@type": "Event",
352
407
  startDate: "2011-04-09T20:00:00Z",
353
408
  description: "A description of the event"
@@ -383,7 +438,7 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
383
438
  path: `${baseRouteName}/:id/:entryId`,
384
439
  handler: async (httpRequestContext, request) => auditableItemStreamDeleteEntry(httpRequestContext, componentName, request),
385
440
  requestType: {
386
- type: "IAuditableItemStreamGetRequest",
441
+ type: "IAuditableItemStreamDeleteRequest",
387
442
  examples: [
388
443
  {
389
444
  id: "auditableItemStreamDeleteEntryRequestExample",
@@ -424,7 +479,7 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
424
479
  },
425
480
  body: {
426
481
  entryObject: {
427
- "@context": "http://schema.org/",
482
+ "@context": "https://schema.org",
428
483
  "@type": "Note",
429
484
  content: "This is a simple note"
430
485
  }
@@ -471,14 +526,17 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
471
526
  id: "auditableItemStreamGetEntryResponseExample",
472
527
  response: {
473
528
  body: {
474
- "@context": auditableItemStreamModels.AuditableItemStreamTypes.ContextRoot,
529
+ "@context": [
530
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRoot,
531
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRootCommon
532
+ ],
475
533
  type: auditableItemStreamModels.AuditableItemStreamTypes.StreamEntry,
476
534
  id: "tst:1234567890",
477
535
  dateCreated: "2024-08-22T11:55:16.271Z",
478
536
  proofId: "0101010101010101010101010101010101010101010101010101010101010101",
479
537
  index: 0,
480
538
  entryObject: {
481
- "@context": "http://schema.org/",
539
+ "@context": "https://schema.org",
482
540
  "@type": "Event",
483
541
  startDate: "2011-04-09T20:00:00Z",
484
542
  description: "A description of the event"
@@ -499,14 +557,17 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
499
557
  [web.HeaderTypes.ContentType]: web.MimeTypes.JsonLd
500
558
  },
501
559
  body: {
502
- "@context": auditableItemStreamModels.AuditableItemStreamTypes.ContextRoot,
560
+ "@context": [
561
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRoot,
562
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRootCommon
563
+ ],
503
564
  type: auditableItemStreamModels.AuditableItemStreamTypes.StreamEntry,
504
565
  id: "tst:1234567890",
505
566
  dateCreated: "2024-08-22T11:55:16.271Z",
506
567
  proofId: "0101010101010101010101010101010101010101010101010101010101010101",
507
568
  index: 0,
508
569
  entryObject: {
509
- "@context": "http://schema.org/",
570
+ "@context": "https://schema.org",
510
571
  "@type": "Event",
511
572
  startDate: "2011-04-09T20:00:00Z",
512
573
  description: "A description of the event"
@@ -550,7 +611,7 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
550
611
  id: "auditableItemStreamGetEntryObjectResponseExample",
551
612
  response: {
552
613
  body: {
553
- "@context": "http://schema.org/",
614
+ "@context": "https://schema.org",
554
615
  "@type": "Event",
555
616
  startDate: "2011-04-09T20:00:00Z",
556
617
  description: "A description of the event"
@@ -592,25 +653,32 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
592
653
  id: "auditableItemStreamListEntriesResponseExample",
593
654
  response: {
594
655
  body: {
595
- "@context": auditableItemStreamModels.AuditableItemStreamTypes.ContextRoot,
596
- type: auditableItemStreamModels.AuditableItemStreamTypes.StreamEntryList,
597
- entries: [
656
+ "@context": [
657
+ standardsSchemaOrg.SchemaOrgContexts.ContextRoot,
658
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRoot,
659
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRootCommon
660
+ ],
661
+ type: [standardsSchemaOrg.SchemaOrgTypes.ItemList, auditableItemStreamModels.AuditableItemStreamTypes.StreamEntryList],
662
+ [standardsSchemaOrg.SchemaOrgTypes.ItemListElement]: [
598
663
  {
599
- "@context": auditableItemStreamModels.AuditableItemStreamTypes.ContextRoot,
664
+ "@context": [
665
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRoot,
666
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRootCommon
667
+ ],
600
668
  type: auditableItemStreamModels.AuditableItemStreamTypes.StreamEntry,
601
669
  id: "tst:1234567890",
602
670
  dateCreated: "2024-08-22T11:55:16.271Z",
603
671
  proofId: "0101010101010101010101010101010101010101010101010101010101010101",
604
672
  index: 0,
605
673
  entryObject: {
606
- "@context": "http://schema.org/",
674
+ "@context": "https://schema.org",
607
675
  "@type": "Event",
608
676
  startDate: "2011-04-09T20:00:00Z",
609
677
  description: "A description of the event"
610
678
  }
611
679
  }
612
680
  ],
613
- cursor: "1"
681
+ [standardsSchemaOrg.SchemaOrgTypes.NextItem]: "1"
614
682
  }
615
683
  }
616
684
  }
@@ -627,25 +695,32 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
627
695
  [web.HeaderTypes.ContentType]: web.MimeTypes.JsonLd
628
696
  },
629
697
  body: {
630
- "@context": auditableItemStreamModels.AuditableItemStreamTypes.ContextRoot,
631
- type: auditableItemStreamModels.AuditableItemStreamTypes.StreamEntryList,
632
- entries: [
698
+ "@context": [
699
+ standardsSchemaOrg.SchemaOrgContexts.ContextRoot,
700
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRoot,
701
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRootCommon
702
+ ],
703
+ type: [standardsSchemaOrg.SchemaOrgTypes.ItemList, auditableItemStreamModels.AuditableItemStreamTypes.StreamEntryList],
704
+ [standardsSchemaOrg.SchemaOrgTypes.ItemListElement]: [
633
705
  {
634
- "@context": auditableItemStreamModels.AuditableItemStreamTypes.ContextRoot,
706
+ "@context": [
707
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRoot,
708
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRootCommon
709
+ ],
635
710
  type: auditableItemStreamModels.AuditableItemStreamTypes.StreamEntry,
636
711
  id: "tst:1234567890",
637
712
  dateCreated: "2024-08-22T11:55:16.271Z",
638
713
  proofId: "0101010101010101010101010101010101010101010101010101010101010101",
639
714
  index: 0,
640
715
  entryObject: {
641
- "@context": "http://schema.org/",
716
+ "@context": "https://schema.org",
642
717
  "@type": "Event",
643
718
  startDate: "2011-04-09T20:00:00Z",
644
719
  description: "A description of the event"
645
720
  }
646
721
  }
647
722
  ],
648
- cursor: "1"
723
+ [standardsSchemaOrg.SchemaOrgTypes.NextItem]: "1"
649
724
  }
650
725
  }
651
726
  }
@@ -684,17 +759,21 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
684
759
  id: "auditableItemStreamListEntryObjectsResponseExample",
685
760
  response: {
686
761
  body: {
687
- "@context": auditableItemStreamModels.AuditableItemStreamTypes.ContextRoot,
688
- type: auditableItemStreamModels.AuditableItemStreamTypes.StreamEntryObjectList,
689
- entryObjects: [
762
+ "@context": [
763
+ standardsSchemaOrg.SchemaOrgContexts.ContextRoot,
764
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRoot,
765
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRootCommon
766
+ ],
767
+ type: [standardsSchemaOrg.SchemaOrgTypes.ItemList, auditableItemStreamModels.AuditableItemStreamTypes.StreamEntryObjectList],
768
+ [standardsSchemaOrg.SchemaOrgTypes.ItemListElement]: [
690
769
  {
691
- "@context": "http://schema.org/",
770
+ "@context": "https://schema.org",
692
771
  "@type": "Event",
693
772
  startDate: "2011-04-09T20:00:00Z",
694
773
  description: "A description of the event"
695
774
  }
696
775
  ],
697
- cursor: "1"
776
+ [standardsSchemaOrg.SchemaOrgTypes.NextItem]: "1"
698
777
  }
699
778
  }
700
779
  }
@@ -709,6 +788,7 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
709
788
  createRoute,
710
789
  getRoute,
711
790
  updateRoute,
791
+ deleteRoute,
712
792
  listRoute,
713
793
  createEntryRoute,
714
794
  getEntryRoute,
@@ -728,8 +808,12 @@ function generateRestRoutesAuditableItemStream(baseRouteName, componentName) {
728
808
  */
729
809
  async function auditableItemStreamCreate(httpRequestContext, componentName, request) {
730
810
  core.Guards.object(ROUTES_SOURCE, "request", request);
811
+ core.Guards.object(ROUTES_SOURCE, "request.body", request.body);
731
812
  const component = core.ComponentFactory.get(componentName);
732
- const id = await component.create(request.body?.streamObject, request.body?.entries, {
813
+ const id = await component.create({
814
+ annotationObject: request.body.annotationObject,
815
+ entries: request.body.entries
816
+ }, {
733
817
  immutableInterval: request.body?.immutableInterval
734
818
  }, httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
735
819
  return {
@@ -753,10 +837,10 @@ async function auditableItemStreamGet(httpRequestContext, componentName, request
753
837
  const mimeType = request.headers?.[web.HeaderTypes.Accept] === web.MimeTypes.JsonLd ? "jsonld" : "json";
754
838
  const component = core.ComponentFactory.get(componentName);
755
839
  const result = await component.get(request.pathParams.id, {
756
- includeEntries: request.query?.includeEntries,
757
- includeDeleted: request.query?.includeDeleted,
758
- verifyStream: request.query?.verifyStream,
759
- verifyEntries: request.query?.verifyEntries
840
+ includeEntries: core.Coerce.boolean(request.query?.includeEntries),
841
+ includeDeleted: core.Coerce.boolean(request.query?.includeDeleted),
842
+ verifyStream: core.Coerce.boolean(request.query?.verifyStream),
843
+ verifyEntries: core.Coerce.boolean(request.query?.verifyEntries)
760
844
  });
761
845
  return {
762
846
  headers: {
@@ -773,11 +857,32 @@ async function auditableItemStreamGet(httpRequestContext, componentName, request
773
857
  * @returns The response object with additional http response properties.
774
858
  */
775
859
  async function auditableItemStreamUpdate(httpRequestContext, componentName, request) {
860
+ core.Guards.object(ROUTES_SOURCE, "request", request);
861
+ core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
862
+ core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
863
+ core.Guards.object(ROUTES_SOURCE, "request.body", request.body);
864
+ const component = core.ComponentFactory.get(componentName);
865
+ await component.update({
866
+ id: request.pathParams.id,
867
+ annotationObject: request.body.annotationObject
868
+ }, httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
869
+ return {
870
+ statusCode: web.HttpStatusCode.noContent
871
+ };
872
+ }
873
+ /**
874
+ * Delete the stream.
875
+ * @param httpRequestContext The request context for the API.
876
+ * @param componentName The name of the component to use in the routes.
877
+ * @param request The request.
878
+ * @returns The response object with additional http response properties.
879
+ */
880
+ async function auditableItemStreamDelete(httpRequestContext, componentName, request) {
776
881
  core.Guards.object(ROUTES_SOURCE, "request", request);
777
882
  core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
778
883
  core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
779
884
  const component = core.ComponentFactory.get(componentName);
780
- await component.update(request.pathParams.id, request.body?.streamObject, httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
885
+ await component.remove(request.pathParams.id, httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
781
886
  return {
782
887
  statusCode: web.HttpStatusCode.noContent
783
888
  };
@@ -794,7 +899,7 @@ async function auditableItemStreamList(httpRequestContext, componentName, reques
794
899
  core.Guards.object(ROUTES_SOURCE, "request.query", request.query);
795
900
  const component = core.ComponentFactory.get(componentName);
796
901
  const mimeType = request.headers?.[web.HeaderTypes.Accept] === web.MimeTypes.JsonLd ? "jsonld" : "json";
797
- const result = await component.query(apiModels.HttpParameterHelper.conditionsFromString(request.query?.conditions), request.query?.orderBy, request.query?.orderByDirection, apiModels.HttpParameterHelper.arrayFromString(request.query?.properties), request.query?.cursor, request.query?.pageSize);
902
+ const result = await component.query(apiModels.HttpParameterHelper.objectFromString(request.query?.conditions), request.query?.orderBy, request.query?.orderByDirection, apiModels.HttpParameterHelper.arrayFromString(request.query?.properties), request.query?.cursor, core.Coerce.integer(request.query?.pageSize));
798
903
  return {
799
904
  headers: {
800
905
  [web.HeaderTypes.ContentType]: mimeType === "json" ? web.MimeTypes.Json : web.MimeTypes.JsonLd
@@ -877,7 +982,7 @@ async function auditableItemStreamGetEntry(httpRequestContext, componentName, re
877
982
  const mimeType = request.headers?.[web.HeaderTypes.Accept] === web.MimeTypes.JsonLd ? "jsonld" : "json";
878
983
  const component = core.ComponentFactory.get(componentName);
879
984
  const result = await component.getEntry(request.pathParams.id, request.pathParams.entryId, {
880
- verifyEntry: request.query?.verifyEntry
985
+ verifyEntry: core.Coerce.boolean(request.query?.verifyEntry)
881
986
  });
882
987
  return {
883
988
  headers: {
@@ -922,11 +1027,11 @@ async function auditableItemStreamListEntries(httpRequestContext, componentName,
922
1027
  const component = core.ComponentFactory.get(componentName);
923
1028
  const mimeType = request.headers?.[web.HeaderTypes.Accept] === web.MimeTypes.JsonLd ? "jsonld" : "json";
924
1029
  const result = await component.getEntries(request.pathParams.id, {
925
- conditions: apiModels.HttpParameterHelper.conditionsFromString(request.query?.conditions),
926
- includeDeleted: request.query?.includeDeleted,
927
- verifyEntries: request.query?.verifyEntries,
1030
+ conditions: apiModels.HttpParameterHelper.objectFromString(request.query?.conditions),
1031
+ includeDeleted: core.Coerce.boolean(request.query?.includeDeleted),
1032
+ verifyEntries: core.Coerce.boolean(request.query?.verifyEntries),
928
1033
  order: request.query?.order,
929
- pageSize: request.query?.pageSize,
1034
+ pageSize: core.Coerce.integer(request.query?.pageSize),
930
1035
  cursor: request.query?.cursor
931
1036
  });
932
1037
  return {
@@ -950,10 +1055,10 @@ async function auditableItemStreamListEntryObjects(httpRequestContext, component
950
1055
  const component = core.ComponentFactory.get(componentName);
951
1056
  const mimeType = request.headers?.[web.HeaderTypes.Accept] === web.MimeTypes.JsonLd ? "jsonld" : "json";
952
1057
  const result = await component.getEntryObjects(request.pathParams.id, {
953
- conditions: apiModels.HttpParameterHelper.conditionsFromString(request.query?.conditions),
954
- includeDeleted: request.query?.includeDeleted,
1058
+ conditions: apiModels.HttpParameterHelper.objectFromString(request.query?.conditions),
1059
+ includeDeleted: core.Coerce.boolean(request.query?.includeDeleted),
955
1060
  order: request.query?.order,
956
- pageSize: request.query?.pageSize,
1061
+ pageSize: core.Coerce.integer(request.query?.pageSize),
957
1062
  cursor: request.query?.cursor
958
1063
  });
959
1064
  return {
@@ -1018,6 +1123,11 @@ class AuditableItemStreamService {
1018
1123
  * @internal
1019
1124
  */
1020
1125
  _streamEntryStorage;
1126
+ /**
1127
+ * The event bus component.
1128
+ * @internal
1129
+ */
1130
+ _eventBusComponent;
1021
1131
  /**
1022
1132
  * The default interval for the integrity checks.
1023
1133
  * @internal
@@ -1026,24 +1136,24 @@ class AuditableItemStreamService {
1026
1136
  /**
1027
1137
  * Create a new instance of AuditableItemStreamService.
1028
1138
  * @param options The dependencies for the auditable item stream connector.
1029
- * @param options.config The configuration for the connector.
1030
- * @param options.immutableProofComponentType The immutable proof component type, defaults to "immutable-proof".
1031
- * @param options.streamEntityStorageType The entity storage for stream, defaults to "auditable-item-stream".
1032
- * @param options.streamEntryEntityStorageType The entity storage for stream entries, defaults to "auditable-item-stream-entry".
1033
1139
  */
1034
1140
  constructor(options) {
1035
1141
  this._immutableProofComponent = core.ComponentFactory.get(options?.immutableProofComponentType ?? "immutable-proof");
1036
1142
  this._streamStorage = entityStorageModels.EntityStorageConnectorFactory.get(options?.streamEntityStorageType ?? core.StringHelper.kebabCase("AuditableItemStream"));
1037
1143
  this._streamEntryStorage = entityStorageModels.EntityStorageConnectorFactory.get(options?.streamEntryEntityStorageType ??
1038
1144
  core.StringHelper.kebabCase("AuditableItemStreamEntry"));
1145
+ if (core.Is.stringValue(options?.eventBusComponentType)) {
1146
+ this._eventBusComponent = core.ComponentFactory.get(options.eventBusComponentType);
1147
+ }
1039
1148
  this._config = options?.config ?? {};
1040
1149
  this._defaultImmutableInterval = this._config.defaultImmutableInterval ?? 10;
1041
- dataSchemaOrg.SchemaOrgDataTypes.registerRedirects();
1150
+ standardsSchemaOrg.SchemaOrgDataTypes.registerRedirects();
1042
1151
  }
1043
1152
  /**
1044
1153
  * Create a new stream.
1045
- * @param streamObject The object for the stream as JSON-LD.
1046
- * @param entries Entries to store in the stream.
1154
+ * @param stream The stream to create.
1155
+ * @param stream.annotationObject The object for the stream as JSON-LD.
1156
+ * @param stream.entries Entries to store in the stream.
1047
1157
  * @param options Options for creating the stream.
1048
1158
  * @param options.immutableInterval After how many entries do we add immutable checks, defaults to service configured value.
1049
1159
  * A value of 0 will disable integrity checks, 1 will be every item, or any other integer for an interval.
@@ -1051,14 +1161,15 @@ class AuditableItemStreamService {
1051
1161
  * @param nodeIdentity The node identity to use for vault operations.
1052
1162
  * @returns The id of the new stream item.
1053
1163
  */
1054
- async create(streamObject, entries, options, userIdentity, nodeIdentity) {
1164
+ async create(stream, options, userIdentity, nodeIdentity) {
1165
+ core.Guards.object(this.CLASS_NAME, "stream", stream);
1055
1166
  core.Guards.stringValue(this.CLASS_NAME, "userIdentity", userIdentity);
1056
1167
  core.Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
1057
1168
  try {
1058
- if (core.Is.object(streamObject)) {
1169
+ if (core.Is.object(stream.annotationObject)) {
1059
1170
  const validationFailures = [];
1060
- await dataJsonLd.JsonLdHelper.validate(streamObject, validationFailures);
1061
- core.Validation.asValidationError(this.CLASS_NAME, "streamObject", validationFailures);
1171
+ await dataJsonLd.JsonLdHelper.validate(stream.annotationObject, validationFailures);
1172
+ core.Validation.asValidationError(this.CLASS_NAME, "stream.annotationObject", validationFailures);
1062
1173
  }
1063
1174
  const id = core.Converter.bytesToHex(core.RandomHelper.generate(32), false);
1064
1175
  const context = {
@@ -1077,25 +1188,23 @@ class AuditableItemStreamService {
1077
1188
  indexCounter: 0,
1078
1189
  proofId: ""
1079
1190
  };
1080
- const fullId = new core.Urn(AuditableItemStreamService.NAMESPACE, id).toString();
1081
1191
  // Create the JSON-LD object we want to use for the proof
1082
1192
  // this is a subset of fixed properties from the stream object.
1083
1193
  const streamModel = await this.streamEntityToJsonLd(core.ObjectHelper.pick(streamEntity, AuditableItemStreamService._PROOF_KEYS_STREAM));
1084
- // Use the full id which will appear in the proof
1085
- streamModel.id = fullId;
1086
1194
  // Create the proof for the stream object
1087
1195
  streamEntity.proofId = await this._immutableProofComponent.create(streamModel, userIdentity, nodeIdentity);
1088
- if (core.Is.arrayValue(entries)) {
1089
- for (const entry of entries) {
1196
+ if (core.Is.arrayValue(stream.entries)) {
1197
+ for (const entry of stream.entries) {
1090
1198
  await this.setEntry(context, id, entry);
1091
1199
  }
1092
1200
  }
1093
1201
  // Add these dynamic properties to the stream object after the proof has been created.
1094
1202
  streamEntity.dateModified = context.now;
1095
- streamEntity.streamObject = streamObject;
1203
+ streamEntity.annotationObject = stream.annotationObject;
1096
1204
  streamEntity.indexCounter = context.indexCounter;
1097
1205
  await this._streamStorage.set(streamEntity);
1098
- return fullId;
1206
+ await this._eventBusComponent?.publish(auditableItemStreamModels.AuditableItemStreamTopics.StreamCreated, { id: streamModel.id });
1207
+ return streamModel.id;
1099
1208
  }
1100
1209
  catch (error) {
1101
1210
  throw new core.GeneralError(this.CLASS_NAME, "createFailed", undefined, error);
@@ -1127,20 +1236,21 @@ class AuditableItemStreamService {
1127
1236
  if (core.Is.empty(streamEntity)) {
1128
1237
  throw new core.NotFoundError(this.CLASS_NAME, "streamNotFound", id);
1129
1238
  }
1239
+ const verifyStream = options?.verifyStream ?? false;
1240
+ const verifyEntries = options?.verifyEntries ?? false;
1130
1241
  const streamModel = await this.streamEntityToJsonLd(streamEntity);
1131
1242
  if (options?.includeEntries) {
1132
- const result = await this.findEntries(streamEntity.nodeIdentity, streamModel.id, options?.includeDeleted, options?.verifyEntries);
1243
+ const result = await this.findEntries(streamId, options?.includeDeleted, verifyEntries);
1133
1244
  streamModel.entries = result.entries;
1134
1245
  streamModel.cursor = result.cursor;
1135
1246
  }
1136
- if (options?.verifyStream ?? false) {
1137
- const fixedStreamModel = await this.streamEntityToJsonLd(core.ObjectHelper.pick(streamEntity, AuditableItemStreamService._PROOF_KEYS_STREAM));
1138
- if (core.Is.stringValue(streamEntity.proofId)) {
1139
- streamModel.verification = await this._immutableProofComponent.verify(streamEntity.proofId, fixedStreamModel);
1140
- }
1247
+ if (verifyStream && core.Is.stringValue(streamEntity.proofId)) {
1248
+ streamModel.verification = await this._immutableProofComponent.verify(streamEntity.proofId);
1249
+ }
1250
+ if (verifyStream || verifyEntries) {
1251
+ streamModel["@context"].push(immutableProofModels.ImmutableProofContexts.ContextRoot);
1141
1252
  }
1142
- const compacted = await dataJsonLd.JsonLdProcessor.compact(streamModel, streamModel["@context"]);
1143
- return compacted;
1253
+ return dataJsonLd.JsonLdProcessor.compact(streamModel, streamModel["@context"]);
1144
1254
  }
1145
1255
  catch (error) {
1146
1256
  throw new core.GeneralError(this.CLASS_NAME, "getFailed", undefined, error);
@@ -1148,44 +1258,79 @@ class AuditableItemStreamService {
1148
1258
  }
1149
1259
  /**
1150
1260
  * Update a stream.
1151
- * @param id The id of the stream to update.
1152
- * @param streamObject The object for the stream as JSON-LD.
1261
+ * @param stream The stream to update.
1262
+ * @param stream.id The id of the stream to update.
1263
+ * @param stream.annotationObject The object for the stream as JSON-LD.
1153
1264
  * @param userIdentity The identity to create the auditable item stream operation with.
1154
1265
  * @param nodeIdentity The node identity to use for vault operations.
1155
1266
  * @returns Nothing.
1156
1267
  */
1157
- async update(id, streamObject, userIdentity, nodeIdentity) {
1158
- core.Guards.stringValue(this.CLASS_NAME, "id", id);
1268
+ async update(stream, userIdentity, nodeIdentity) {
1269
+ core.Guards.object(this.CLASS_NAME, "stream", stream);
1270
+ core.Guards.stringValue(this.CLASS_NAME, "stream.id", stream.id);
1159
1271
  core.Guards.stringValue(this.CLASS_NAME, "userIdentity", userIdentity);
1160
1272
  core.Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
1161
- const urnParsed = core.Urn.fromValidString(id);
1273
+ const urnParsed = core.Urn.fromValidString(stream.id);
1162
1274
  if (urnParsed.namespaceIdentifier() !== AuditableItemStreamService.NAMESPACE) {
1163
1275
  throw new core.GeneralError(this.CLASS_NAME, "namespaceMismatch", {
1164
1276
  namespace: AuditableItemStreamService.NAMESPACE,
1165
- id
1277
+ id: stream.id
1166
1278
  });
1167
1279
  }
1168
1280
  try {
1169
1281
  const streamId = urnParsed.namespaceSpecific(0);
1170
1282
  const streamEntity = await this._streamStorage.get(streamId);
1171
1283
  if (core.Is.empty(streamEntity)) {
1172
- throw new core.NotFoundError(this.CLASS_NAME, "streamNotFound", id);
1284
+ throw new core.NotFoundError(this.CLASS_NAME, "streamNotFound", stream.id);
1173
1285
  }
1174
- if (core.Is.object(streamObject)) {
1286
+ if (core.Is.object(stream.annotationObject)) {
1175
1287
  const validationFailures = [];
1176
- await dataJsonLd.JsonLdHelper.validate(streamObject, validationFailures);
1177
- core.Validation.asValidationError(this.CLASS_NAME, "streamObject", validationFailures);
1288
+ await dataJsonLd.JsonLdHelper.validate(stream.annotationObject, validationFailures);
1289
+ core.Validation.asValidationError(this.CLASS_NAME, "stream.annotationObject", validationFailures);
1178
1290
  }
1179
- if (!core.ObjectHelper.equal(streamEntity.streamObject, streamObject, false)) {
1180
- streamEntity.streamObject = streamObject;
1291
+ if (!core.ObjectHelper.equal(streamEntity.annotationObject, stream.annotationObject, false)) {
1292
+ streamEntity.annotationObject = stream.annotationObject;
1181
1293
  streamEntity.dateModified = new Date(Date.now()).toISOString();
1182
1294
  await this._streamStorage.set(streamEntity);
1295
+ await this._eventBusComponent?.publish(auditableItemStreamModels.AuditableItemStreamTopics.StreamUpdated, { id: stream.id });
1183
1296
  }
1184
1297
  }
1185
1298
  catch (error) {
1186
1299
  throw new core.GeneralError(this.CLASS_NAME, "updateFailed", undefined, error);
1187
1300
  }
1188
1301
  }
1302
+ /**
1303
+ * Delete the stream.
1304
+ * @param id The id of the stream to remove.
1305
+ * @param userIdentity The identity to create the auditable item stream operation with.
1306
+ * @param nodeIdentity The node identity to use for vault operations.
1307
+ * @returns Nothing.
1308
+ */
1309
+ async remove(id, userIdentity, nodeIdentity) {
1310
+ core.Guards.stringValue(this.CLASS_NAME, "id", id);
1311
+ core.Guards.stringValue(this.CLASS_NAME, "userIdentity", userIdentity);
1312
+ core.Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
1313
+ const urnParsed = core.Urn.fromValidString(id);
1314
+ if (urnParsed.namespaceIdentifier() !== AuditableItemStreamService.NAMESPACE) {
1315
+ throw new core.GeneralError(this.CLASS_NAME, "namespaceMismatch", {
1316
+ namespace: AuditableItemStreamService.NAMESPACE,
1317
+ id
1318
+ });
1319
+ }
1320
+ try {
1321
+ const streamId = urnParsed.namespaceSpecific(0);
1322
+ const streamEntity = await this._streamStorage.get(streamId);
1323
+ if (core.Is.empty(streamEntity)) {
1324
+ throw new core.NotFoundError(this.CLASS_NAME, "streamNotFound", id);
1325
+ }
1326
+ await this.internalRemoveEntries(streamEntity, false, nodeIdentity);
1327
+ await this._streamStorage.remove(streamEntity.id);
1328
+ await this._eventBusComponent?.publish(auditableItemStreamModels.AuditableItemStreamTopics.StreamDeleted, { id });
1329
+ }
1330
+ catch (error) {
1331
+ throw new core.GeneralError(this.CLASS_NAME, "removingFailed", undefined, error);
1332
+ }
1333
+ }
1189
1334
  /**
1190
1335
  * Query all the streams, will not return entries.
1191
1336
  * @param conditions Conditions to use in the query.
@@ -1202,7 +1347,7 @@ class AuditableItemStreamService {
1202
1347
  "id",
1203
1348
  "dateCreated",
1204
1349
  "dateModified",
1205
- "streamObject"
1350
+ "annotationObject"
1206
1351
  ];
1207
1352
  const orderProperty = orderBy ?? "dateCreated";
1208
1353
  const orderDirection = orderByDirection ?? entity.SortDirection.Descending;
@@ -1224,13 +1369,16 @@ class AuditableItemStreamService {
1224
1369
  }
1225
1370
  ], propertiesToReturn, cursor, pageSize);
1226
1371
  const list = {
1227
- "@context": auditableItemStreamModels.AuditableItemStreamTypes.ContextRoot,
1228
- type: auditableItemStreamModels.AuditableItemStreamTypes.StreamList,
1229
- streams: results.entities.map(e => this.streamEntityToJsonLd(e)),
1230
- cursor: results.cursor
1372
+ "@context": [
1373
+ standardsSchemaOrg.SchemaOrgContexts.ContextRoot,
1374
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRoot,
1375
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRootCommon
1376
+ ],
1377
+ type: [standardsSchemaOrg.SchemaOrgTypes.ItemList, auditableItemStreamModels.AuditableItemStreamTypes.StreamList],
1378
+ [standardsSchemaOrg.SchemaOrgTypes.ItemListElement]: results.entities.map(e => this.streamEntityToJsonLd(e)),
1379
+ [standardsSchemaOrg.SchemaOrgTypes.NextItem]: results.cursor
1231
1380
  };
1232
- const compacted = await dataJsonLd.JsonLdProcessor.compact(list, list["@context"]);
1233
- return compacted;
1381
+ return dataJsonLd.JsonLdProcessor.compact(list, list["@context"]);
1234
1382
  }
1235
1383
  catch (error) {
1236
1384
  throw new core.GeneralError(this.CLASS_NAME, "queryingFailed", undefined, error);
@@ -1238,28 +1386,28 @@ class AuditableItemStreamService {
1238
1386
  }
1239
1387
  /**
1240
1388
  * Create an entry in the stream.
1241
- * @param id The id of the stream to update.
1389
+ * @param streamId The id of the stream to update.
1242
1390
  * @param entryObject The object for the stream as JSON-LD.
1243
1391
  * @param userIdentity The identity to create the auditable item stream operation with.
1244
1392
  * @param nodeIdentity The node identity to use for vault operations.
1245
1393
  * @returns The id of the created entry, if not provided.
1246
1394
  */
1247
- async createEntry(id, entryObject, userIdentity, nodeIdentity) {
1248
- core.Guards.stringValue(this.CLASS_NAME, "id", id);
1395
+ async createEntry(streamId, entryObject, userIdentity, nodeIdentity) {
1396
+ core.Guards.stringValue(this.CLASS_NAME, "streamId", streamId);
1249
1397
  core.Guards.stringValue(this.CLASS_NAME, "userIdentity", userIdentity);
1250
1398
  core.Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
1251
- const urnParsed = core.Urn.fromValidString(id);
1399
+ const urnParsed = core.Urn.fromValidString(streamId);
1252
1400
  if (urnParsed.namespaceIdentifier() !== AuditableItemStreamService.NAMESPACE) {
1253
1401
  throw new core.GeneralError(this.CLASS_NAME, "namespaceMismatch", {
1254
1402
  namespace: AuditableItemStreamService.NAMESPACE,
1255
- id
1403
+ id: streamId
1256
1404
  });
1257
1405
  }
1258
1406
  try {
1259
- const streamId = urnParsed.namespaceSpecific(0);
1260
- const streamEntity = await this._streamStorage.get(streamId);
1407
+ const streamIdParts = urnParsed.namespaceSpecific(0);
1408
+ const streamEntity = await this._streamStorage.get(streamIdParts);
1261
1409
  if (core.Is.empty(streamEntity)) {
1262
- throw new core.NotFoundError(this.CLASS_NAME, "streamNotFound", id);
1410
+ throw new core.NotFoundError(this.CLASS_NAME, "streamNotFound", streamIdParts);
1263
1411
  }
1264
1412
  const context = {
1265
1413
  now: new Date(Date.now()).toISOString(),
@@ -1274,7 +1422,12 @@ class AuditableItemStreamService {
1274
1422
  streamEntity.dateModified = context.now;
1275
1423
  streamEntity.indexCounter = context.indexCounter;
1276
1424
  await this._streamStorage.set(streamEntity);
1277
- return new core.Urn(AuditableItemStreamService.NAMESPACE, [streamEntity.id, createdId]).toString();
1425
+ const fullId = new core.Urn(AuditableItemStreamService.NAMESPACE, [
1426
+ streamEntity.id,
1427
+ createdId
1428
+ ]).toString();
1429
+ await this._eventBusComponent?.publish(auditableItemStreamModels.AuditableItemStreamTopics.StreamEntryCreated, { id: streamId, entryId: fullId });
1430
+ return fullId;
1278
1431
  }
1279
1432
  catch (error) {
1280
1433
  throw new core.GeneralError(this.CLASS_NAME, "creatingEntryFailed", undefined, error);
@@ -1282,21 +1435,21 @@ class AuditableItemStreamService {
1282
1435
  }
1283
1436
  /**
1284
1437
  * Get the entry from the stream.
1285
- * @param id The id of the stream to get.
1438
+ * @param streamId The id of the stream to get.
1286
1439
  * @param entryId The id of the stream entry to get.
1287
1440
  * @param options Additional options for the get operation.
1288
1441
  * @param options.verifyEntry Should the entry be verified, defaults to false.
1289
1442
  * @returns The stream and entries if found.
1290
1443
  * @throws NotFoundError if the stream is not found.
1291
1444
  */
1292
- async getEntry(id, entryId, options) {
1293
- core.Guards.stringValue(this.CLASS_NAME, "id", id);
1445
+ async getEntry(streamId, entryId, options) {
1446
+ core.Guards.stringValue(this.CLASS_NAME, "streamId", streamId);
1294
1447
  core.Guards.stringValue(this.CLASS_NAME, "entryId", entryId);
1295
- const urnParsed = core.Urn.fromValidString(id);
1448
+ const urnParsed = core.Urn.fromValidString(streamId);
1296
1449
  if (urnParsed.namespaceIdentifier() !== AuditableItemStreamService.NAMESPACE) {
1297
1450
  throw new core.GeneralError(this.CLASS_NAME, "namespaceMismatch", {
1298
1451
  namespace: AuditableItemStreamService.NAMESPACE,
1299
- id
1452
+ id: streamId
1300
1453
  });
1301
1454
  }
1302
1455
  const urnParsedEntry = core.Urn.fromValidString(entryId);
@@ -1310,16 +1463,20 @@ class AuditableItemStreamService {
1310
1463
  const streamNamespaceId = urnParsed.namespaceSpecific(0);
1311
1464
  const streamEntity = await this._streamStorage.get(streamNamespaceId);
1312
1465
  if (core.Is.empty(streamEntity)) {
1313
- throw new core.NotFoundError(this.CLASS_NAME, "streamNotFound", id);
1466
+ throw new core.NotFoundError(this.CLASS_NAME, "streamNotFound", streamId);
1314
1467
  }
1468
+ const verifyEntry = options?.verifyEntry ?? false;
1315
1469
  const entryNamespaceId = urnParsedEntry.namespaceSpecific(1);
1316
- const result = await this.findEntry(streamEntity.nodeIdentity, streamEntity.id, entryNamespaceId, options?.verifyEntry);
1470
+ const result = await this.findEntry(streamEntity.nodeIdentity, streamEntity.id, entryNamespaceId, verifyEntry);
1317
1471
  if (core.Is.empty(result)) {
1318
1472
  throw new core.NotFoundError(this.CLASS_NAME, "streamEntryNotFound", entryId);
1319
1473
  }
1320
1474
  const entry = this.streamEntryEntityToJsonLd(result.entity);
1321
- const compacted = await dataJsonLd.JsonLdProcessor.compact(entry, entry["@context"]);
1322
- return compacted;
1475
+ if (verifyEntry) {
1476
+ entry["@context"].push(immutableProofModels.ImmutableProofContexts.ContextRoot);
1477
+ entry.verification = result.verification;
1478
+ }
1479
+ return dataJsonLd.JsonLdProcessor.compact(entry, entry["@context"]);
1323
1480
  }
1324
1481
  catch (error) {
1325
1482
  throw new core.GeneralError(this.CLASS_NAME, "gettingEntryFailed", undefined, error);
@@ -1327,19 +1484,19 @@ class AuditableItemStreamService {
1327
1484
  }
1328
1485
  /**
1329
1486
  * Get the entry object from the stream.
1330
- * @param id The id of the stream to get.
1487
+ * @param streamId The id of the stream to get.
1331
1488
  * @param entryId The id of the stream entry to get.
1332
1489
  * @returns The stream and entries if found.
1333
1490
  * @throws NotFoundError if the stream is not found.
1334
1491
  */
1335
- async getEntryObject(id, entryId) {
1336
- core.Guards.stringValue(this.CLASS_NAME, "id", id);
1492
+ async getEntryObject(streamId, entryId) {
1493
+ core.Guards.stringValue(this.CLASS_NAME, "streamId", streamId);
1337
1494
  core.Guards.stringValue(this.CLASS_NAME, "entryId", entryId);
1338
- const urnParsed = core.Urn.fromValidString(id);
1495
+ const urnParsed = core.Urn.fromValidString(streamId);
1339
1496
  if (urnParsed.namespaceIdentifier() !== AuditableItemStreamService.NAMESPACE) {
1340
1497
  throw new core.GeneralError(this.CLASS_NAME, "namespaceMismatch", {
1341
1498
  namespace: AuditableItemStreamService.NAMESPACE,
1342
- id
1499
+ id: streamId
1343
1500
  });
1344
1501
  }
1345
1502
  const urnParsedEntry = core.Urn.fromValidString(entryId);
@@ -1353,7 +1510,7 @@ class AuditableItemStreamService {
1353
1510
  const streamNamespaceId = urnParsed.namespaceSpecific(0);
1354
1511
  const streamEntity = await this._streamStorage.get(streamNamespaceId);
1355
1512
  if (core.Is.empty(streamEntity)) {
1356
- throw new core.NotFoundError(this.CLASS_NAME, "streamNotFound", id);
1513
+ throw new core.NotFoundError(this.CLASS_NAME, "streamNotFound", streamId);
1357
1514
  }
1358
1515
  const entryNamespaceId = urnParsedEntry.namespaceSpecific(1);
1359
1516
  const result = await this.findEntry(streamEntity.nodeIdentity, streamEntity.id, entryNamespaceId);
@@ -1368,23 +1525,23 @@ class AuditableItemStreamService {
1368
1525
  }
1369
1526
  /**
1370
1527
  * Update an entry in the stream.
1371
- * @param id The id of the stream to update.
1528
+ * @param streamId The id of the stream to update.
1372
1529
  * @param entryId The id of the entry to update.
1373
1530
  * @param entryObject The object for the entry as JSON-LD.
1374
1531
  * @param userIdentity The identity to create the auditable item stream operation with.
1375
1532
  * @param nodeIdentity The node identity to use for vault operations.
1376
1533
  * @returns Nothing.
1377
1534
  */
1378
- async updateEntry(id, entryId, entryObject, userIdentity, nodeIdentity) {
1379
- core.Guards.stringValue(this.CLASS_NAME, "id", id);
1535
+ async updateEntry(streamId, entryId, entryObject, userIdentity, nodeIdentity) {
1536
+ core.Guards.stringValue(this.CLASS_NAME, "streamId", streamId);
1380
1537
  core.Guards.stringValue(this.CLASS_NAME, "entryId", entryId);
1381
1538
  core.Guards.stringValue(this.CLASS_NAME, "userIdentity", userIdentity);
1382
1539
  core.Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
1383
- const urnParsed = core.Urn.fromValidString(id);
1540
+ const urnParsed = core.Urn.fromValidString(streamId);
1384
1541
  if (urnParsed.namespaceIdentifier() !== AuditableItemStreamService.NAMESPACE) {
1385
1542
  throw new core.GeneralError(this.CLASS_NAME, "namespaceMismatch", {
1386
1543
  namespace: AuditableItemStreamService.NAMESPACE,
1387
- id
1544
+ id: streamId
1388
1545
  });
1389
1546
  }
1390
1547
  const urnParsedEntry = core.Urn.fromValidString(entryId);
@@ -1395,10 +1552,17 @@ class AuditableItemStreamService {
1395
1552
  });
1396
1553
  }
1397
1554
  try {
1398
- const streamNamespaceId = urnParsed.namespaceSpecific(0);
1555
+ const streamNamespaceId = urnParsed.namespaceMethod();
1556
+ const streamEntryNamespaceId = urnParsedEntry.namespaceMethod();
1557
+ if (streamNamespaceId !== streamEntryNamespaceId) {
1558
+ throw new core.GeneralError(this.CLASS_NAME, "namespaceMismatch", {
1559
+ streamNamespaceId,
1560
+ streamEntryNamespaceId
1561
+ });
1562
+ }
1399
1563
  const streamEntity = await this._streamStorage.get(streamNamespaceId);
1400
1564
  if (core.Is.empty(streamEntity)) {
1401
- throw new core.NotFoundError(this.CLASS_NAME, "streamNotFound", id);
1565
+ throw new core.NotFoundError(this.CLASS_NAME, "streamNotFound", streamId);
1402
1566
  }
1403
1567
  const entryNamespaceId = urnParsedEntry.namespaceSpecific(1);
1404
1568
  const existing = await this.findEntry(nodeIdentity, streamEntity.id, entryNamespaceId);
@@ -1413,12 +1577,13 @@ class AuditableItemStreamService {
1413
1577
  immutableInterval: streamEntity.immutableInterval
1414
1578
  };
1415
1579
  await this.setEntry(context, streamEntity.id, {
1416
- ...existing,
1580
+ ...existing.entity,
1417
1581
  entryObject
1418
1582
  });
1419
1583
  streamEntity.dateModified = context.now;
1420
1584
  streamEntity.indexCounter = context.indexCounter;
1421
1585
  await this._streamStorage.set(streamEntity);
1586
+ await this._eventBusComponent?.publish(auditableItemStreamModels.AuditableItemStreamTopics.StreamEntryUpdated, { id: streamId, entryId });
1422
1587
  }
1423
1588
  catch (error) {
1424
1589
  throw new core.GeneralError(this.CLASS_NAME, "updatingEntryFailed", undefined, error);
@@ -1426,22 +1591,22 @@ class AuditableItemStreamService {
1426
1591
  }
1427
1592
  /**
1428
1593
  * Delete from the stream.
1429
- * @param id The id of the stream to update.
1430
- * @param entryId The id of the entry to delete.
1594
+ * @param streamId The id of the stream to remove from.
1595
+ * @param entryId The id of the entry to remove.
1431
1596
  * @param userIdentity The identity to create the auditable item stream operation with.
1432
1597
  * @param nodeIdentity The node identity to use for vault operations.
1433
1598
  * @returns Nothing.
1434
1599
  */
1435
- async removeEntry(id, entryId, userIdentity, nodeIdentity) {
1436
- core.Guards.stringValue(this.CLASS_NAME, "id", id);
1600
+ async removeEntry(streamId, entryId, userIdentity, nodeIdentity) {
1601
+ core.Guards.stringValue(this.CLASS_NAME, "streamId", streamId);
1437
1602
  core.Guards.stringValue(this.CLASS_NAME, "entryId", entryId);
1438
1603
  core.Guards.stringValue(this.CLASS_NAME, "userIdentity", userIdentity);
1439
1604
  core.Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
1440
- const urnParsed = core.Urn.fromValidString(id);
1605
+ const urnParsed = core.Urn.fromValidString(streamId);
1441
1606
  if (urnParsed.namespaceIdentifier() !== AuditableItemStreamService.NAMESPACE) {
1442
1607
  throw new core.GeneralError(this.CLASS_NAME, "namespaceMismatch", {
1443
1608
  namespace: AuditableItemStreamService.NAMESPACE,
1444
- id
1609
+ id: streamId
1445
1610
  });
1446
1611
  }
1447
1612
  const urnParsedEntry = core.Urn.fromValidString(entryId);
@@ -1452,10 +1617,17 @@ class AuditableItemStreamService {
1452
1617
  });
1453
1618
  }
1454
1619
  try {
1455
- const streamNamespaceId = urnParsed.namespaceSpecific(0);
1620
+ const streamNamespaceId = urnParsed.namespaceMethod();
1621
+ const streamEntryNamespaceId = urnParsedEntry.namespaceMethod();
1622
+ if (streamNamespaceId !== streamEntryNamespaceId) {
1623
+ throw new core.GeneralError(this.CLASS_NAME, "namespaceMismatch", {
1624
+ streamNamespaceId,
1625
+ streamEntryNamespaceId
1626
+ });
1627
+ }
1456
1628
  const streamEntity = await this._streamStorage.get(streamNamespaceId);
1457
1629
  if (core.Is.empty(streamEntity)) {
1458
- throw new core.NotFoundError(this.CLASS_NAME, "streamNotFound", id);
1630
+ throw new core.NotFoundError(this.CLASS_NAME, "streamNotFound", streamId);
1459
1631
  }
1460
1632
  const entryNamespaceId = urnParsedEntry.namespaceSpecific(1);
1461
1633
  const result = await this.findEntry(streamEntity.nodeIdentity, streamNamespaceId, entryNamespaceId);
@@ -1477,6 +1649,7 @@ class AuditableItemStreamService {
1477
1649
  streamEntity.dateModified = context.now;
1478
1650
  streamEntity.indexCounter = context.indexCounter;
1479
1651
  await this._streamStorage.set(streamEntity);
1652
+ await this._eventBusComponent?.publish(auditableItemStreamModels.AuditableItemStreamTopics.StreamEntryDeleted, { id: streamId, entryId });
1480
1653
  }
1481
1654
  }
1482
1655
  catch (error) {
@@ -1485,7 +1658,7 @@ class AuditableItemStreamService {
1485
1658
  }
1486
1659
  /**
1487
1660
  * Get the entries for the stream.
1488
- * @param id The id of the stream to get.
1661
+ * @param streamId The id of the stream to get.
1489
1662
  * @param options Additional options for the get operation.
1490
1663
  * @param options.conditions The conditions to filter the stream.
1491
1664
  * @param options.includeDeleted Whether to include deleted entries, defaults to false.
@@ -1496,34 +1669,37 @@ class AuditableItemStreamService {
1496
1669
  * @returns The stream and entries if found.
1497
1670
  * @throws NotFoundError if the stream is not found.
1498
1671
  */
1499
- async getEntries(id, options) {
1500
- core.Guards.stringValue(this.CLASS_NAME, "id", id);
1501
- const urnParsed = core.Urn.fromValidString(id);
1672
+ async getEntries(streamId, options) {
1673
+ core.Guards.stringValue(this.CLASS_NAME, "streamId", streamId);
1674
+ const urnParsed = core.Urn.fromValidString(streamId);
1502
1675
  if (urnParsed.namespaceIdentifier() !== AuditableItemStreamService.NAMESPACE) {
1503
1676
  throw new core.GeneralError(this.CLASS_NAME, "namespaceMismatch", {
1504
1677
  namespace: AuditableItemStreamService.NAMESPACE,
1505
- id
1678
+ id: streamId
1506
1679
  });
1507
1680
  }
1508
1681
  try {
1509
1682
  const streamNamespaceId = urnParsed.namespaceSpecific(0);
1510
1683
  const streamEntity = await this._streamStorage.get(streamNamespaceId);
1511
1684
  if (core.Is.empty(streamEntity)) {
1512
- throw new core.NotFoundError(this.CLASS_NAME, "streamNotFound", id);
1685
+ throw new core.NotFoundError(this.CLASS_NAME, "streamNotFound", streamId);
1513
1686
  }
1514
- const result = await this.findEntries(streamEntity.nodeIdentity, streamNamespaceId, options?.includeDeleted, options?.verifyEntries, options?.conditions, options?.order, undefined, options?.pageSize, options?.cursor);
1687
+ const verifyEntries = options?.verifyEntries ?? false;
1688
+ const result = await this.findEntries(streamNamespaceId, options?.includeDeleted, verifyEntries, options?.conditions, options?.order, undefined, options?.pageSize, options?.cursor);
1515
1689
  const list = {
1516
1690
  "@context": [
1517
- auditableItemStreamModels.AuditableItemStreamTypes.ContextRoot,
1518
- immutableProofModels.ImmutableProofTypes.ContextRoot,
1519
- dataSchemaOrg.SchemaOrgTypes.ContextRoot
1691
+ standardsSchemaOrg.SchemaOrgContexts.ContextRoot,
1692
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRoot,
1693
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRootCommon
1520
1694
  ],
1521
- type: auditableItemStreamModels.AuditableItemStreamTypes.StreamEntryList,
1522
- entries: result.entries,
1523
- cursor: result.cursor
1695
+ type: [standardsSchemaOrg.SchemaOrgTypes.ItemList, auditableItemStreamModels.AuditableItemStreamTypes.StreamEntryList],
1696
+ [standardsSchemaOrg.SchemaOrgTypes.ItemListElement]: result.entries,
1697
+ [standardsSchemaOrg.SchemaOrgTypes.NextItem]: result.cursor
1524
1698
  };
1525
- const compacted = await dataJsonLd.JsonLdProcessor.compact(list, list["@context"]);
1526
- return compacted;
1699
+ if (verifyEntries) {
1700
+ list["@context"].push(immutableProofModels.ImmutableProofContexts.ContextRoot);
1701
+ }
1702
+ return dataJsonLd.JsonLdProcessor.compact(list, list["@context"]);
1527
1703
  }
1528
1704
  catch (error) {
1529
1705
  throw new core.GeneralError(this.CLASS_NAME, "gettingEntriesFailed", undefined, error);
@@ -1531,7 +1707,7 @@ class AuditableItemStreamService {
1531
1707
  }
1532
1708
  /**
1533
1709
  * Get the entry objects for the stream.
1534
- * @param id The id of the stream to get.
1710
+ * @param streamId The id of the stream to get.
1535
1711
  * @param options Additional options for the get operation.
1536
1712
  * @param options.conditions The conditions to filter the stream.
1537
1713
  * @param options.includeDeleted Whether to include deleted entries, defaults to false.
@@ -1541,86 +1717,65 @@ class AuditableItemStreamService {
1541
1717
  * @returns The stream and entries if found.
1542
1718
  * @throws NotFoundError if the stream is not found.
1543
1719
  */
1544
- async getEntryObjects(id, options) {
1545
- core.Guards.stringValue(this.CLASS_NAME, "id", id);
1546
- const urnParsed = core.Urn.fromValidString(id);
1720
+ async getEntryObjects(streamId, options) {
1721
+ core.Guards.stringValue(this.CLASS_NAME, "streamId", streamId);
1722
+ const urnParsed = core.Urn.fromValidString(streamId);
1547
1723
  if (urnParsed.namespaceIdentifier() !== AuditableItemStreamService.NAMESPACE) {
1548
1724
  throw new core.GeneralError(this.CLASS_NAME, "namespaceMismatch", {
1549
1725
  namespace: AuditableItemStreamService.NAMESPACE,
1550
- id
1726
+ id: streamId
1551
1727
  });
1552
1728
  }
1553
1729
  try {
1554
1730
  const streamNamespaceId = urnParsed.namespaceSpecific(0);
1555
1731
  const streamEntity = await this._streamStorage.get(streamNamespaceId);
1556
1732
  if (core.Is.empty(streamEntity)) {
1557
- throw new core.NotFoundError(this.CLASS_NAME, "streamNotFound", id);
1733
+ throw new core.NotFoundError(this.CLASS_NAME, "streamNotFound", streamId);
1558
1734
  }
1559
- const result = await this.findEntries(streamEntity.nodeIdentity, streamNamespaceId, options?.includeDeleted, false, options?.conditions, options?.order, undefined, options?.pageSize, options?.cursor);
1735
+ const result = await this.findEntries(streamNamespaceId, options?.includeDeleted, false, options?.conditions, options?.order, undefined, options?.pageSize, options?.cursor);
1560
1736
  const list = {
1561
- "@context": auditableItemStreamModels.AuditableItemStreamTypes.ContextRoot,
1562
- type: auditableItemStreamModels.AuditableItemStreamTypes.StreamEntryObjectList,
1563
- entryObjects: result.entries.map(m => m.entryObject),
1564
- cursor: result.cursor
1737
+ "@context": [
1738
+ standardsSchemaOrg.SchemaOrgContexts.ContextRoot,
1739
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRoot,
1740
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRootCommon
1741
+ ],
1742
+ type: [standardsSchemaOrg.SchemaOrgTypes.ItemList, auditableItemStreamModels.AuditableItemStreamTypes.StreamEntryObjectList],
1743
+ [standardsSchemaOrg.SchemaOrgTypes.ItemListElement]: result.entries.map(m => m.entryObject),
1744
+ [standardsSchemaOrg.SchemaOrgTypes.NextItem]: result.cursor
1565
1745
  };
1566
- const compacted = await dataJsonLd.JsonLdProcessor.compact(list, list["@context"]);
1567
- return compacted;
1746
+ return dataJsonLd.JsonLdProcessor.compact(list, list["@context"]);
1568
1747
  }
1569
1748
  catch (error) {
1570
1749
  throw new core.GeneralError(this.CLASS_NAME, "gettingEntryObjectsFailed", undefined, error);
1571
1750
  }
1572
1751
  }
1573
1752
  /**
1574
- * Remove the immutable storage for the stream and entries.
1575
- * @param id The id of the stream to remove the storage from.
1753
+ * Remove the verifiable storage for the stream and entries.
1754
+ * @param streamId The id of the stream to remove the storage from.
1576
1755
  * @param nodeIdentity The node identity to use for vault operations.
1577
1756
  * @returns Nothing.
1578
1757
  * @throws NotFoundError if the vertex is not found.
1579
1758
  */
1580
- async removeImmutable(id, nodeIdentity) {
1581
- core.Guards.stringValue(this.CLASS_NAME, "id", id);
1759
+ async removeVerifiable(streamId, nodeIdentity) {
1760
+ core.Guards.stringValue(this.CLASS_NAME, "streamId", streamId);
1582
1761
  core.Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
1583
- const urnParsed = core.Urn.fromValidString(id);
1762
+ const urnParsed = core.Urn.fromValidString(streamId);
1584
1763
  if (urnParsed.namespaceIdentifier() !== AuditableItemStreamService.NAMESPACE) {
1585
1764
  throw new core.GeneralError(this.CLASS_NAME, "namespaceMismatch", {
1586
1765
  namespace: AuditableItemStreamService.NAMESPACE,
1587
- id
1766
+ id: streamId
1588
1767
  });
1589
1768
  }
1590
1769
  try {
1591
- const streamId = urnParsed.namespaceSpecific(0);
1592
- const streamEntity = await this._streamStorage.get(streamId);
1770
+ const streamIdParts = urnParsed.namespaceSpecific(0);
1771
+ const streamEntity = await this._streamStorage.get(streamIdParts);
1593
1772
  if (core.Is.empty(streamEntity)) {
1594
- throw new core.NotFoundError(this.CLASS_NAME, "streamNotFound", id);
1595
- }
1596
- if (core.Is.stringValue(streamEntity.proofId)) {
1597
- await this._immutableProofComponent.removeImmutable(streamEntity.proofId, nodeIdentity);
1598
- delete streamEntity.proofId;
1599
- await this._streamStorage.set(streamEntity);
1773
+ throw new core.NotFoundError(this.CLASS_NAME, "streamNotFound", streamIdParts);
1600
1774
  }
1601
- let entriesResult;
1602
- do {
1603
- entriesResult = await this._streamEntryStorage.query({
1604
- property: "streamId",
1605
- value: streamId,
1606
- comparison: entity.ComparisonOperator.Equals
1607
- }, [
1608
- {
1609
- property: "dateCreated",
1610
- sortDirection: entity.SortDirection.Ascending
1611
- }
1612
- ], undefined, entriesResult?.cursor);
1613
- for (const streamEntry of entriesResult.entities) {
1614
- if (core.Is.stringValue(streamEntry.proofId)) {
1615
- await this._immutableProofComponent.removeImmutable(nodeIdentity, streamEntry.proofId);
1616
- delete streamEntry.proofId;
1617
- await this._streamEntryStorage.set(streamEntry);
1618
- }
1619
- }
1620
- } while (core.Is.stringValue(entriesResult.cursor));
1775
+ await this.internalRemoveEntries(streamEntity, true, nodeIdentity);
1621
1776
  }
1622
1777
  catch (error) {
1623
- throw new core.GeneralError(this.CLASS_NAME, "removeImmutableFailed", undefined, error);
1778
+ throw new core.GeneralError(this.CLASS_NAME, "removeVerifiableFailed", undefined, error);
1624
1779
  }
1625
1780
  }
1626
1781
  /**
@@ -1632,17 +1787,17 @@ class AuditableItemStreamService {
1632
1787
  streamEntityToJsonLd(streamEntity) {
1633
1788
  const model = {
1634
1789
  "@context": [
1635
- auditableItemStreamModels.AuditableItemStreamTypes.ContextRoot,
1636
- immutableProofModels.ImmutableProofTypes.ContextRoot,
1637
- dataSchemaOrg.SchemaOrgTypes.ContextRoot
1790
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRoot,
1791
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRootCommon,
1792
+ standardsSchemaOrg.SchemaOrgContexts.ContextRoot
1638
1793
  ],
1639
1794
  type: auditableItemStreamModels.AuditableItemStreamTypes.Stream,
1640
- id: streamEntity.id,
1795
+ id: `${AuditableItemStreamService.NAMESPACE}:${streamEntity.id}`,
1641
1796
  dateCreated: streamEntity.dateCreated,
1642
1797
  dateModified: streamEntity.dateModified,
1643
1798
  nodeIdentity: streamEntity.nodeIdentity,
1644
1799
  userIdentity: streamEntity.userIdentity,
1645
- streamObject: streamEntity.streamObject,
1800
+ annotationObject: streamEntity.annotationObject,
1646
1801
  immutableInterval: streamEntity.immutableInterval,
1647
1802
  proofId: streamEntity.proofId
1648
1803
  };
@@ -1657,9 +1812,9 @@ class AuditableItemStreamService {
1657
1812
  streamEntryEntityToJsonLd(streamEntryEntity) {
1658
1813
  const streamEntryModel = {
1659
1814
  "@context": [
1660
- auditableItemStreamModels.AuditableItemStreamTypes.ContextRoot,
1661
- immutableProofModels.ImmutableProofTypes.ContextRoot,
1662
- dataSchemaOrg.SchemaOrgTypes.ContextRoot
1815
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRoot,
1816
+ auditableItemStreamModels.AuditableItemStreamContexts.ContextRootCommon,
1817
+ standardsSchemaOrg.SchemaOrgContexts.ContextRoot
1663
1818
  ],
1664
1819
  type: auditableItemStreamModels.AuditableItemStreamTypes.StreamEntry,
1665
1820
  id: `${AuditableItemStreamService.NAMESPACE}:${streamEntryEntity.streamId}:${streamEntryEntity.id}`,
@@ -1745,10 +1900,7 @@ class AuditableItemStreamService {
1745
1900
  const entity = result.entities[0];
1746
1901
  let verification;
1747
1902
  if ((verifyEntry ?? false) && core.Is.stringValue(entity.proofId)) {
1748
- // Create the JSON-LD object we want to use for the proof
1749
- // this is a subset of fixed properties from the stream entry object.
1750
- const streamEntryModel = await this.streamEntryEntityToJsonLd(core.ObjectHelper.pick(entity, AuditableItemStreamService._PROOF_KEYS_STREAM_ENTRY));
1751
- verification = await this._immutableProofComponent.verify(entity.proofId, streamEntryModel);
1903
+ verification = await this._immutableProofComponent.verify(entity.proofId);
1752
1904
  }
1753
1905
  return {
1754
1906
  entity,
@@ -1758,7 +1910,6 @@ class AuditableItemStreamService {
1758
1910
  }
1759
1911
  /**
1760
1912
  * Find stream entries.
1761
- * @param nodeIdentity The node identity.
1762
1913
  * @param streamId The stream id.
1763
1914
  * @param includeDeleted Should deleted entries be included.
1764
1915
  * @param verifyEntries Should the entries be verified.
@@ -1769,7 +1920,7 @@ class AuditableItemStreamService {
1769
1920
  * @param cursor The cursor.
1770
1921
  * @internal
1771
1922
  */
1772
- async findEntries(nodeIdentity, streamId, includeDeleted, verifyEntries, conditions, sortDirection, propertiesToReturn, pageSize, cursor) {
1923
+ async findEntries(streamId, includeDeleted, verifyEntries, conditions, sortDirection, propertiesToReturn, pageSize, cursor) {
1773
1924
  const needToVerify = verifyEntries ?? false;
1774
1925
  const combinedConditions = [
1775
1926
  {
@@ -1825,10 +1976,7 @@ class AuditableItemStreamService {
1825
1976
  for (const entry of result.entities) {
1826
1977
  const entryModel = this.streamEntryEntityToJsonLd(entry);
1827
1978
  if (needToVerify && core.Is.stringValue(entry.proofId)) {
1828
- // Create the JSON-LD object we want to use for the proof
1829
- // this is a subset of fixed properties from the stream entry object.
1830
- const streamEntryModel = await this.streamEntryEntityToJsonLd(core.ObjectHelper.pick(entry, AuditableItemStreamService._PROOF_KEYS_STREAM_ENTRY));
1831
- entryModel.verification = await this._immutableProofComponent.verify(entry.proofId, streamEntryModel);
1979
+ entryModel.verification = await this._immutableProofComponent.verify(entry.proofId);
1832
1980
  }
1833
1981
  entryModels.push(entryModel);
1834
1982
  }
@@ -1837,46 +1985,92 @@ class AuditableItemStreamService {
1837
1985
  cursor: returnCursor
1838
1986
  };
1839
1987
  }
1988
+ /**
1989
+ * Remove the verifiable storage for the stream and entries.
1990
+ * @param streamEntity The stream entity.
1991
+ * @param removeOnlyProof Should only the proof be removed.
1992
+ * @param nodeIdentity The node identity to use for vault operations.
1993
+ * @returns Nothing.
1994
+ * @internal
1995
+ */
1996
+ async internalRemoveEntries(streamEntity, removeOnlyProof, nodeIdentity) {
1997
+ if (core.Is.stringValue(streamEntity.proofId)) {
1998
+ await this._immutableProofComponent.removeVerifiable(streamEntity.proofId, nodeIdentity);
1999
+ delete streamEntity.proofId;
2000
+ await this._streamStorage.set(streamEntity);
2001
+ }
2002
+ const entryIds = [];
2003
+ let entriesResult;
2004
+ do {
2005
+ entriesResult = await this._streamEntryStorage.query({
2006
+ property: "streamId",
2007
+ value: streamEntity.id,
2008
+ comparison: entity.ComparisonOperator.Equals
2009
+ }, [
2010
+ {
2011
+ property: "dateCreated",
2012
+ sortDirection: entity.SortDirection.Ascending
2013
+ }
2014
+ ], undefined, entriesResult?.cursor);
2015
+ for (const streamEntry of entriesResult.entities) {
2016
+ entryIds.push(streamEntry.id);
2017
+ if (core.Is.stringValue(streamEntry.proofId)) {
2018
+ await this._immutableProofComponent.removeVerifiable(streamEntry.proofId, nodeIdentity);
2019
+ delete streamEntry.proofId;
2020
+ // If we are only removing the proof, we need to set the entry
2021
+ // otherwise the entry is going to be removed later anyway.
2022
+ if (removeOnlyProof) {
2023
+ await this._streamEntryStorage.set(streamEntry);
2024
+ }
2025
+ }
2026
+ }
2027
+ } while (core.Is.stringValue(entriesResult.cursor));
2028
+ if (!removeOnlyProof) {
2029
+ for (const entryId of entryIds) {
2030
+ await this._streamEntryStorage.remove(entryId);
2031
+ }
2032
+ }
2033
+ }
1840
2034
  }
1841
2035
 
1842
2036
  // Copyright 2024 IOTA Stiftung.
1843
2037
  // SPDX-License-Identifier: Apache-2.0.
1844
2038
  /**
1845
- * Class describing the auditable item stream entry.
2039
+ * Class describing the auditable item stream.
1846
2040
  */
1847
- exports.AuditableItemStreamEntry = class AuditableItemStreamEntry {
2041
+ exports.AuditableItemStream = class AuditableItemStream {
1848
2042
  /**
1849
- * The id of the entry.
2043
+ * The id of the stream.
1850
2044
  */
1851
2045
  id;
1852
2046
  /**
1853
- * The stream that the entry belongs to.
1854
- */
1855
- streamId;
1856
- /**
1857
- * The date/time of when the entry was created.
2047
+ * The date/time of when the stream was created.
1858
2048
  */
1859
2049
  dateCreated;
1860
2050
  /**
1861
- * The date/time of when the entry was modified.
2051
+ * The date/time of when the stream was modified.
1862
2052
  */
1863
2053
  dateModified;
1864
2054
  /**
1865
- * The date/time of when the entry was deleted, as we never actually remove items.
2055
+ * The identity of the node which controls the stream.
1866
2056
  */
1867
- dateDeleted;
2057
+ nodeIdentity;
1868
2058
  /**
1869
- * The identity of the user that added the entry.
2059
+ * The identity of the user which created the stream.
1870
2060
  */
1871
2061
  userIdentity;
1872
2062
  /**
1873
- * Object to associate with the entry as JSON-LD.
2063
+ * Object to associate with the stream as JSON-LD.
1874
2064
  */
1875
- entryObject;
2065
+ annotationObject;
1876
2066
  /**
1877
- * The index of the entry in the stream.
2067
+ * The counter for the entry index.
1878
2068
  */
1879
- index;
2069
+ indexCounter;
2070
+ /**
2071
+ * After how many entries do we add immutable checks.
2072
+ */
2073
+ immutableInterval;
1880
2074
  /**
1881
2075
  * The immutable proof id.
1882
2076
  */
@@ -1885,81 +2079,86 @@ exports.AuditableItemStreamEntry = class AuditableItemStreamEntry {
1885
2079
  __decorate([
1886
2080
  entity.property({ type: "string", isPrimary: true }),
1887
2081
  __metadata("design:type", String)
1888
- ], exports.AuditableItemStreamEntry.prototype, "id", void 0);
1889
- __decorate([
1890
- entity.property({ type: "string" }),
1891
- __metadata("design:type", String)
1892
- ], exports.AuditableItemStreamEntry.prototype, "streamId", void 0);
2082
+ ], exports.AuditableItemStream.prototype, "id", void 0);
1893
2083
  __decorate([
1894
- entity.property({ type: "string", format: "date-time", sortDirection: entity.SortDirection.Ascending }),
2084
+ entity.property({ type: "string", format: "date-time", sortDirection: entity.SortDirection.Descending }),
1895
2085
  __metadata("design:type", String)
1896
- ], exports.AuditableItemStreamEntry.prototype, "dateCreated", void 0);
2086
+ ], exports.AuditableItemStream.prototype, "dateCreated", void 0);
1897
2087
  __decorate([
1898
- entity.property({ type: "string", format: "date-time" }),
2088
+ entity.property({
2089
+ type: "string",
2090
+ format: "date-time",
2091
+ sortDirection: entity.SortDirection.Descending,
2092
+ optional: true
2093
+ }),
1899
2094
  __metadata("design:type", String)
1900
- ], exports.AuditableItemStreamEntry.prototype, "dateModified", void 0);
2095
+ ], exports.AuditableItemStream.prototype, "dateModified", void 0);
1901
2096
  __decorate([
1902
- entity.property({ type: "string", format: "date-time" }),
2097
+ entity.property({ type: "string" }),
1903
2098
  __metadata("design:type", String)
1904
- ], exports.AuditableItemStreamEntry.prototype, "dateDeleted", void 0);
2099
+ ], exports.AuditableItemStream.prototype, "nodeIdentity", void 0);
1905
2100
  __decorate([
1906
2101
  entity.property({ type: "string" }),
1907
2102
  __metadata("design:type", String)
1908
- ], exports.AuditableItemStreamEntry.prototype, "userIdentity", void 0);
2103
+ ], exports.AuditableItemStream.prototype, "userIdentity", void 0);
1909
2104
  __decorate([
1910
- entity.property({ type: "object", itemTypeRef: dataJsonLd.JsonLdTypes.Object }),
2105
+ entity.property({ type: "object", itemTypeRef: dataJsonLd.JsonLdTypes.Object, optional: true }),
1911
2106
  __metadata("design:type", Object)
1912
- ], exports.AuditableItemStreamEntry.prototype, "entryObject", void 0);
2107
+ ], exports.AuditableItemStream.prototype, "annotationObject", void 0);
1913
2108
  __decorate([
1914
2109
  entity.property({ type: "integer" }),
1915
2110
  __metadata("design:type", Number)
1916
- ], exports.AuditableItemStreamEntry.prototype, "index", void 0);
2111
+ ], exports.AuditableItemStream.prototype, "indexCounter", void 0);
1917
2112
  __decorate([
1918
- entity.property({ type: "string" }),
2113
+ entity.property({ type: "integer" }),
2114
+ __metadata("design:type", Number)
2115
+ ], exports.AuditableItemStream.prototype, "immutableInterval", void 0);
2116
+ __decorate([
2117
+ entity.property({ type: "string", optional: true }),
1919
2118
  __metadata("design:type", String)
1920
- ], exports.AuditableItemStreamEntry.prototype, "proofId", void 0);
1921
- exports.AuditableItemStreamEntry = __decorate([
2119
+ ], exports.AuditableItemStream.prototype, "proofId", void 0);
2120
+ exports.AuditableItemStream = __decorate([
1922
2121
  entity.entity()
1923
- ], exports.AuditableItemStreamEntry);
2122
+ ], exports.AuditableItemStream);
1924
2123
 
1925
2124
  // Copyright 2024 IOTA Stiftung.
1926
2125
  // SPDX-License-Identifier: Apache-2.0.
1927
2126
  /**
1928
- * Class describing the auditable item stream.
2127
+ * Class describing the auditable item stream entry.
1929
2128
  */
1930
- exports.AuditableItemStream = class AuditableItemStream {
2129
+ exports.AuditableItemStreamEntry = class AuditableItemStreamEntry {
1931
2130
  /**
1932
- * The id of the stream.
2131
+ * The id of the entry.
1933
2132
  */
1934
2133
  id;
1935
2134
  /**
1936
- * The date/time of when the stream was created.
2135
+ * The stream that the entry belongs to.
2136
+ */
2137
+ streamId;
2138
+ /**
2139
+ * The date/time of when the entry was created.
1937
2140
  */
1938
2141
  dateCreated;
1939
2142
  /**
1940
- * The date/time of when the stream was modified.
2143
+ * The date/time of when the entry was modified.
1941
2144
  */
1942
2145
  dateModified;
1943
2146
  /**
1944
- * The identity of the node which controls the stream.
2147
+ * The date/time of when the entry was deleted, as we never actually remove items.
1945
2148
  */
1946
- nodeIdentity;
2149
+ dateDeleted;
1947
2150
  /**
1948
- * The identity of the user which created the stream.
2151
+ * The identity of the user that added the entry.
1949
2152
  */
1950
2153
  userIdentity;
1951
2154
  /**
1952
- * Object to associate with the stream as JSON-LD.
1953
- */
1954
- streamObject;
1955
- /**
1956
- * The counter for the entry index.
2155
+ * Object to associate with the entry as JSON-LD.
1957
2156
  */
1958
- indexCounter;
2157
+ entryObject;
1959
2158
  /**
1960
- * After how many entries do we add immutable checks.
2159
+ * The index of the entry in the stream.
1961
2160
  */
1962
- immutableInterval;
2161
+ index;
1963
2162
  /**
1964
2163
  * The immutable proof id.
1965
2164
  */
@@ -1968,42 +2167,47 @@ exports.AuditableItemStream = class AuditableItemStream {
1968
2167
  __decorate([
1969
2168
  entity.property({ type: "string", isPrimary: true }),
1970
2169
  __metadata("design:type", String)
1971
- ], exports.AuditableItemStream.prototype, "id", void 0);
2170
+ ], exports.AuditableItemStreamEntry.prototype, "id", void 0);
1972
2171
  __decorate([
1973
- entity.property({ type: "string", format: "date-time", sortDirection: entity.SortDirection.Descending }),
2172
+ entity.property({ type: "string" }),
1974
2173
  __metadata("design:type", String)
1975
- ], exports.AuditableItemStream.prototype, "dateCreated", void 0);
2174
+ ], exports.AuditableItemStreamEntry.prototype, "streamId", void 0);
1976
2175
  __decorate([
1977
- entity.property({ type: "string", format: "date-time" }),
2176
+ entity.property({ type: "string", format: "date-time", sortDirection: entity.SortDirection.Ascending }),
1978
2177
  __metadata("design:type", String)
1979
- ], exports.AuditableItemStream.prototype, "dateModified", void 0);
2178
+ ], exports.AuditableItemStreamEntry.prototype, "dateCreated", void 0);
1980
2179
  __decorate([
1981
- entity.property({ type: "string" }),
2180
+ entity.property({
2181
+ type: "string",
2182
+ format: "date-time",
2183
+ sortDirection: entity.SortDirection.Descending,
2184
+ optional: true
2185
+ }),
1982
2186
  __metadata("design:type", String)
1983
- ], exports.AuditableItemStream.prototype, "nodeIdentity", void 0);
2187
+ ], exports.AuditableItemStreamEntry.prototype, "dateModified", void 0);
2188
+ __decorate([
2189
+ entity.property({ type: "string", format: "date-time", optional: true }),
2190
+ __metadata("design:type", String)
2191
+ ], exports.AuditableItemStreamEntry.prototype, "dateDeleted", void 0);
1984
2192
  __decorate([
1985
2193
  entity.property({ type: "string" }),
1986
2194
  __metadata("design:type", String)
1987
- ], exports.AuditableItemStream.prototype, "userIdentity", void 0);
2195
+ ], exports.AuditableItemStreamEntry.prototype, "userIdentity", void 0);
1988
2196
  __decorate([
1989
2197
  entity.property({ type: "object", itemTypeRef: dataJsonLd.JsonLdTypes.Object }),
1990
2198
  __metadata("design:type", Object)
1991
- ], exports.AuditableItemStream.prototype, "streamObject", void 0);
1992
- __decorate([
1993
- entity.property({ type: "integer" }),
1994
- __metadata("design:type", Number)
1995
- ], exports.AuditableItemStream.prototype, "indexCounter", void 0);
2199
+ ], exports.AuditableItemStreamEntry.prototype, "entryObject", void 0);
1996
2200
  __decorate([
1997
2201
  entity.property({ type: "integer" }),
1998
2202
  __metadata("design:type", Number)
1999
- ], exports.AuditableItemStream.prototype, "immutableInterval", void 0);
2203
+ ], exports.AuditableItemStreamEntry.prototype, "index", void 0);
2000
2204
  __decorate([
2001
- entity.property({ type: "string" }),
2205
+ entity.property({ type: "string", optional: true }),
2002
2206
  __metadata("design:type", String)
2003
- ], exports.AuditableItemStream.prototype, "proofId", void 0);
2004
- exports.AuditableItemStream = __decorate([
2207
+ ], exports.AuditableItemStreamEntry.prototype, "proofId", void 0);
2208
+ exports.AuditableItemStreamEntry = __decorate([
2005
2209
  entity.entity()
2006
- ], exports.AuditableItemStream);
2210
+ ], exports.AuditableItemStreamEntry);
2007
2211
 
2008
2212
  const restEntryPoints = [
2009
2213
  {
@@ -2027,6 +2231,7 @@ function initSchema() {
2027
2231
  exports.AuditableItemStreamService = AuditableItemStreamService;
2028
2232
  exports.auditableItemStreamCreate = auditableItemStreamCreate;
2029
2233
  exports.auditableItemStreamCreateEntry = auditableItemStreamCreateEntry;
2234
+ exports.auditableItemStreamDelete = auditableItemStreamDelete;
2030
2235
  exports.auditableItemStreamDeleteEntry = auditableItemStreamDeleteEntry;
2031
2236
  exports.auditableItemStreamGet = auditableItemStreamGet;
2032
2237
  exports.auditableItemStreamGetEntry = auditableItemStreamGetEntry;