@twin.org/auditable-item-graph-service 0.0.2-next.8 → 0.0.3-next.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 (42) hide show
  1. package/dist/es/auditableItemGraphRoutes.js +529 -0
  2. package/dist/es/auditableItemGraphRoutes.js.map +1 -0
  3. package/dist/es/auditableItemGraphService.js +919 -0
  4. package/dist/es/auditableItemGraphService.js.map +1 -0
  5. package/dist/es/entities/auditableItemGraphAlias.js +62 -0
  6. package/dist/es/entities/auditableItemGraphAlias.js.map +1 -0
  7. package/dist/es/entities/auditableItemGraphChangeset.js +61 -0
  8. package/dist/es/entities/auditableItemGraphChangeset.js.map +1 -0
  9. package/dist/es/entities/auditableItemGraphEdge.js +70 -0
  10. package/dist/es/entities/auditableItemGraphEdge.js.map +1 -0
  11. package/dist/es/entities/auditableItemGraphPatch.js +45 -0
  12. package/dist/es/entities/auditableItemGraphPatch.js.map +1 -0
  13. package/dist/es/entities/auditableItemGraphResource.js +54 -0
  14. package/dist/es/entities/auditableItemGraphResource.js.map +1 -0
  15. package/dist/es/entities/auditableItemGraphVertex.js +99 -0
  16. package/dist/es/entities/auditableItemGraphVertex.js.map +1 -0
  17. package/dist/es/index.js +15 -0
  18. package/dist/es/index.js.map +1 -0
  19. package/dist/es/models/IAuditableItemGraphServiceConfig.js +4 -0
  20. package/dist/es/models/IAuditableItemGraphServiceConfig.js.map +1 -0
  21. package/dist/es/models/IAuditableItemGraphServiceConstructorOptions.js +2 -0
  22. package/dist/es/models/IAuditableItemGraphServiceConstructorOptions.js.map +1 -0
  23. package/dist/es/models/IAuditableItemGraphServiceContext.js +2 -0
  24. package/dist/es/models/IAuditableItemGraphServiceContext.js.map +1 -0
  25. package/dist/es/restEntryPoints.js +10 -0
  26. package/dist/es/restEntryPoints.js.map +1 -0
  27. package/dist/es/schema.js +21 -0
  28. package/dist/es/schema.js.map +1 -0
  29. package/dist/types/auditableItemGraphService.d.ts +9 -9
  30. package/dist/types/entities/auditableItemGraphChangeset.d.ts +2 -2
  31. package/dist/types/entities/auditableItemGraphVertex.d.ts +5 -5
  32. package/dist/types/index.d.ts +12 -12
  33. package/dist/types/models/IAuditableItemGraphServiceConstructorOptions.d.ts +1 -1
  34. package/dist/types/models/IAuditableItemGraphServiceContext.d.ts +3 -6
  35. package/docs/changelog.md +36 -0
  36. package/docs/open-api/spec.json +112 -136
  37. package/docs/reference/classes/AuditableItemGraphChangeset.md +2 -2
  38. package/docs/reference/classes/AuditableItemGraphService.md +21 -33
  39. package/docs/reference/classes/AuditableItemGraphVertex.md +3 -3
  40. package/package.json +7 -8
  41. package/dist/cjs/index.cjs +0 -1854
  42. package/dist/esm/index.mjs +0 -1844
@@ -1,1854 +0,0 @@
1
- 'use strict';
2
-
3
- var apiModels = require('@twin.org/api-models');
4
- var auditableItemGraphModels = require('@twin.org/auditable-item-graph-models');
5
- var core = require('@twin.org/core');
6
- var standardsSchemaOrg = require('@twin.org/standards-schema-org');
7
- var web = require('@twin.org/web');
8
- var dataJsonLd = require('@twin.org/data-json-ld');
9
- var entity = require('@twin.org/entity');
10
- var entityStorageModels = require('@twin.org/entity-storage-models');
11
- var immutableProofModels = require('@twin.org/immutable-proof-models');
12
-
13
- // Copyright 2024 IOTA Stiftung.
14
- // SPDX-License-Identifier: Apache-2.0.
15
- /**
16
- * The source used when communicating about these routes.
17
- */
18
- const ROUTES_SOURCE = "auditableItemGraphRoutes";
19
- /**
20
- * The tag to associate with the routes.
21
- */
22
- const tagsAuditableItemGraph = [
23
- {
24
- name: "Auditable Item Graph",
25
- description: "Endpoints which are modelled to access an auditable item graph contract."
26
- }
27
- ];
28
- /**
29
- * The REST routes for auditable item graph.
30
- * @param baseRouteName Prefix to prepend to the paths.
31
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
32
- * @returns The generated routes.
33
- */
34
- function generateRestRoutesAuditableItemGraph(baseRouteName, componentName) {
35
- const createRoute = {
36
- operationId: "auditableItemGraphCreate",
37
- summary: "Create a new graph vertex",
38
- tag: tagsAuditableItemGraph[0].name,
39
- method: "POST",
40
- path: `${baseRouteName}/`,
41
- handler: async (httpRequestContext, request) => auditableItemGraphCreate(httpRequestContext, componentName, request),
42
- requestType: {
43
- type: "IAuditableItemGraphCreateRequest",
44
- examples: [
45
- {
46
- id: "auditableItemGraphCreateRequestExample",
47
- request: {
48
- body: {
49
- annotationObject: {
50
- "@context": "https://schema.org",
51
- "@type": "Note",
52
- content: "This is a simple note"
53
- },
54
- aliases: [
55
- {
56
- id: "bar456",
57
- annotationObject: {
58
- "@context": "https://schema.org",
59
- "@type": "Note",
60
- content: "This is a simple note"
61
- }
62
- },
63
- {
64
- id: "foo321",
65
- annotationObject: {
66
- "@context": "https://schema.org",
67
- "@type": "Note",
68
- content: "This is a simple note"
69
- }
70
- }
71
- ],
72
- resources: [
73
- {
74
- id: "resource1",
75
- resourceObject: {
76
- "@context": "https://schema.org",
77
- "@type": "Note",
78
- content: "This is a simple note"
79
- }
80
- },
81
- {
82
- id: "resource2",
83
- resourceObject: {
84
- "@context": "https://schema.org",
85
- "@type": "Note",
86
- content: "This is a simple note"
87
- }
88
- }
89
- ],
90
- edges: [
91
- {
92
- targetId: "aig:1234567890",
93
- edgeRelationships: ["frenemy"],
94
- annotationObject: {
95
- "@context": "https://schema.org",
96
- "@type": "Note",
97
- content: "This is a simple note"
98
- }
99
- },
100
- {
101
- targetId: "aig:45678901234",
102
- edgeRelationships: ["end"],
103
- annotationObject: {
104
- "@context": "https://schema.org",
105
- "@type": "Note",
106
- content: "This is a simple note"
107
- }
108
- }
109
- ]
110
- }
111
- }
112
- }
113
- ]
114
- },
115
- responseType: [
116
- {
117
- type: "ICreatedResponse",
118
- examples: [
119
- {
120
- id: "auditableItemGraphCreateResponseExample",
121
- description: "The response when a new graph vertex is created.",
122
- response: {
123
- statusCode: web.HttpStatusCode.created,
124
- headers: {
125
- [web.HeaderTypes.Location]: "aig:1234567890"
126
- }
127
- }
128
- }
129
- ]
130
- }
131
- ]
132
- };
133
- const getRoute = {
134
- operationId: "auditableItemGraphGet",
135
- summary: "Get a graph vertex",
136
- tag: tagsAuditableItemGraph[0].name,
137
- method: "GET",
138
- path: `${baseRouteName}/:id`,
139
- handler: async (httpRequestContext, request) => auditableItemGraphGet(httpRequestContext, componentName, request),
140
- requestType: {
141
- type: "IAuditableItemGraphGetRequest",
142
- examples: [
143
- {
144
- id: "auditableItemGraphGetRequestExample",
145
- request: {
146
- headers: {
147
- [web.HeaderTypes.Accept]: web.MimeTypes.Json
148
- },
149
- pathParams: {
150
- id: "aig:1234567890"
151
- }
152
- }
153
- }
154
- ]
155
- },
156
- responseType: [
157
- {
158
- type: "IAuditableItemGraphGetResponse",
159
- examples: [
160
- {
161
- id: "auditableItemGraphGetResponseExample",
162
- response: {
163
- body: {
164
- "@context": [
165
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot,
166
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRootCommon,
167
- standardsSchemaOrg.SchemaOrgContexts.ContextRoot
168
- ],
169
- type: auditableItemGraphModels.AuditableItemGraphTypes.Vertex,
170
- id: "aig:1234567890",
171
- dateCreated: "2024-08-22T11:55:16.271Z",
172
- dateModified: "2024-08-22T11:55:16.271Z",
173
- annotationObject: {
174
- "@context": "https://schema.org",
175
- "@type": "Note",
176
- content: "This is a simple note"
177
- },
178
- aliases: [
179
- {
180
- "@context": [
181
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot,
182
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRootCommon,
183
- standardsSchemaOrg.SchemaOrgContexts.ContextRoot
184
- ],
185
- type: auditableItemGraphModels.AuditableItemGraphTypes.Alias,
186
- id: "tst:1234567890",
187
- dateCreated: "2024-08-22T11:55:16.271Z"
188
- }
189
- ]
190
- }
191
- }
192
- }
193
- ]
194
- },
195
- {
196
- type: "IAuditableItemGraphGetResponse",
197
- mimeType: web.MimeTypes.JsonLd,
198
- examples: [
199
- {
200
- id: "auditableItemGraphJsonLdGetResponseExample",
201
- response: {
202
- headers: {
203
- [web.HeaderTypes.ContentType]: web.MimeTypes.JsonLd
204
- },
205
- body: {
206
- "@context": [
207
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot,
208
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRootCommon,
209
- standardsSchemaOrg.SchemaOrgContexts.ContextRoot
210
- ],
211
- type: auditableItemGraphModels.AuditableItemGraphTypes.Vertex,
212
- id: "aig:1234567890",
213
- dateCreated: "2024-08-22T11:55:16.271Z",
214
- dateModified: "2024-08-22T11:55:16.271Z",
215
- annotationObject: {
216
- "@context": "https://schema.org",
217
- "@type": "Note",
218
- content: "This is a simple note"
219
- },
220
- aliases: [
221
- {
222
- "@context": [
223
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot,
224
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRootCommon,
225
- standardsSchemaOrg.SchemaOrgContexts.ContextRoot
226
- ],
227
- type: auditableItemGraphModels.AuditableItemGraphTypes.Alias,
228
- dateCreated: "2024-08-22T11:55:16.271Z",
229
- id: "tst:1234567890"
230
- }
231
- ]
232
- }
233
- }
234
- }
235
- ]
236
- }
237
- ]
238
- };
239
- const updateRoute = {
240
- operationId: "auditableItemGraphUpdate",
241
- summary: "Update a graph vertex",
242
- tag: tagsAuditableItemGraph[0].name,
243
- method: "PUT",
244
- path: `${baseRouteName}/:id`,
245
- handler: async (httpRequestContext, request) => auditableItemGraphUpdate(httpRequestContext, componentName, request),
246
- requestType: {
247
- type: "IAuditableItemGraphUpdateRequest",
248
- examples: [
249
- {
250
- id: "auditableItemGraphUpdateRequestExample",
251
- request: {
252
- pathParams: {
253
- id: "aig:1234567890"
254
- },
255
- body: {
256
- annotationObject: {
257
- "@context": "https://schema.org",
258
- "@type": "Note",
259
- content: "This is a simple note"
260
- },
261
- aliases: [
262
- {
263
- id: "bar456",
264
- annotationObject: {
265
- "@context": "https://schema.org",
266
- "@type": "Note",
267
- content: "This is a simple note"
268
- }
269
- },
270
- {
271
- id: "foo321",
272
- annotationObject: {
273
- "@context": "https://schema.org",
274
- "@type": "Note",
275
- content: "This is a simple note"
276
- }
277
- }
278
- ],
279
- resources: [
280
- {
281
- id: "resource1",
282
- resourceObject: {
283
- "@context": "https://schema.org",
284
- "@type": "Note",
285
- content: "This is a simple note"
286
- }
287
- },
288
- {
289
- id: "resource2",
290
- resourceObject: {
291
- "@context": "https://schema.org",
292
- "@type": "Note",
293
- content: "This is a simple note"
294
- }
295
- }
296
- ],
297
- edges: [
298
- {
299
- id: "edge1",
300
- targetId: "aig:1234567890",
301
- edgeRelationships: ["frenemy"],
302
- annotationObject: {
303
- "@context": "https://schema.org",
304
- "@type": "Note",
305
- content: "This is a simple note"
306
- }
307
- },
308
- {
309
- id: "edge2",
310
- targetId: "aig:45678901234",
311
- edgeRelationships: ["end"],
312
- annotationObject: {
313
- "@context": "https://schema.org",
314
- "@type": "Note",
315
- content: "This is a simple note"
316
- }
317
- }
318
- ]
319
- }
320
- }
321
- }
322
- ]
323
- },
324
- responseType: [
325
- {
326
- type: "INoContentResponse"
327
- }
328
- ]
329
- };
330
- const listRoute = {
331
- operationId: "auditableItemGraphList",
332
- summary: "Query graph vertices by id or alias",
333
- tag: tagsAuditableItemGraph[0].name,
334
- method: "GET",
335
- path: `${baseRouteName}/`,
336
- handler: async (httpRequestContext, request) => auditableItemGraphList(httpRequestContext, componentName, request),
337
- requestType: {
338
- type: "IAuditableItemGraphListRequest",
339
- examples: [
340
- {
341
- id: "IAuditableItemGraphListAllRequest",
342
- request: {}
343
- },
344
- {
345
- id: "IAuditableItemGraphListIdRequest",
346
- request: {
347
- query: {
348
- id: "1234567890"
349
- }
350
- }
351
- }
352
- ]
353
- },
354
- responseType: [
355
- {
356
- type: "IAuditableItemGraphListResponse",
357
- examples: [
358
- {
359
- id: "auditableItemGraphListResponseExample",
360
- response: {
361
- body: {
362
- "@context": [
363
- standardsSchemaOrg.SchemaOrgContexts.ContextRoot,
364
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot,
365
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRootCommon
366
- ],
367
- type: [standardsSchemaOrg.SchemaOrgTypes.ItemList, auditableItemGraphModels.AuditableItemGraphTypes.VertexList],
368
- [standardsSchemaOrg.SchemaOrgTypes.ItemListElement]: [
369
- {
370
- "@context": [
371
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot,
372
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRootCommon,
373
- standardsSchemaOrg.SchemaOrgContexts.ContextRoot
374
- ],
375
- type: auditableItemGraphModels.AuditableItemGraphTypes.Vertex,
376
- id: "0101010101010101010101010101010101010101010101010101010101010101",
377
- dateCreated: "2024-08-22T11:55:16.271Z",
378
- aliases: [
379
- {
380
- "@context": [
381
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot,
382
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRootCommon,
383
- standardsSchemaOrg.SchemaOrgContexts.ContextRoot
384
- ],
385
- type: auditableItemGraphModels.AuditableItemGraphTypes.Alias,
386
- id: "foo4",
387
- dateCreated: "2024-08-22T11:55:16.271Z"
388
- }
389
- ]
390
- }
391
- ],
392
- [standardsSchemaOrg.SchemaOrgTypes.NextItem]: "1"
393
- }
394
- }
395
- }
396
- ]
397
- },
398
- {
399
- type: "IAuditableItemGraphListResponse",
400
- mimeType: web.MimeTypes.JsonLd,
401
- examples: [
402
- {
403
- id: "auditableItemGraphJsonLdListResponseExample",
404
- response: {
405
- headers: {
406
- [web.HeaderTypes.ContentType]: web.MimeTypes.JsonLd
407
- },
408
- body: {
409
- "@context": [
410
- standardsSchemaOrg.SchemaOrgContexts.ContextRoot,
411
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot,
412
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRootCommon
413
- ],
414
- type: [standardsSchemaOrg.SchemaOrgTypes.ItemList, auditableItemGraphModels.AuditableItemGraphTypes.VertexList],
415
- [standardsSchemaOrg.SchemaOrgTypes.ItemListElement]: [
416
- {
417
- "@context": [
418
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot,
419
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRootCommon,
420
- standardsSchemaOrg.SchemaOrgContexts.ContextRoot
421
- ],
422
- type: auditableItemGraphModels.AuditableItemGraphTypes.Vertex,
423
- id: "0101010101010101010101010101010101010101010101010101010101010101",
424
- dateCreated: "2024-08-22T11:55:16.271Z",
425
- aliases: [
426
- {
427
- "@context": [
428
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot,
429
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRootCommon,
430
- standardsSchemaOrg.SchemaOrgContexts.ContextRoot
431
- ],
432
- type: auditableItemGraphModels.AuditableItemGraphTypes.Alias,
433
- id: "foo4",
434
- dateCreated: "2024-08-22T11:55:16.271Z"
435
- }
436
- ]
437
- }
438
- ],
439
- [standardsSchemaOrg.SchemaOrgTypes.NextItem]: "1"
440
- }
441
- }
442
- }
443
- ]
444
- }
445
- ]
446
- };
447
- return [createRoute, getRoute, updateRoute, listRoute];
448
- }
449
- /**
450
- * Create the graph vertex.
451
- * @param httpRequestContext The request context for the API.
452
- * @param componentName The name of the component to use in the routes.
453
- * @param request The request.
454
- * @returns The response object with additional http response properties.
455
- */
456
- async function auditableItemGraphCreate(httpRequestContext, componentName, request) {
457
- core.Guards.object(ROUTES_SOURCE, "request", request);
458
- core.Guards.object(ROUTES_SOURCE, "request.body", request.body);
459
- const component = core.ComponentFactory.get(componentName);
460
- const id = await component.create(request.body, httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
461
- return {
462
- statusCode: web.HttpStatusCode.created,
463
- headers: {
464
- [web.HeaderTypes.Location]: id
465
- }
466
- };
467
- }
468
- /**
469
- * Get the graph vertex.
470
- * @param httpRequestContext The request context for the API.
471
- * @param componentName The name of the component to use in the routes.
472
- * @param request The request.
473
- * @returns The response object with additional http response properties.
474
- */
475
- async function auditableItemGraphGet(httpRequestContext, componentName, request) {
476
- core.Guards.object(ROUTES_SOURCE, "request", request);
477
- core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
478
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
479
- const mimeType = request.headers?.[web.HeaderTypes.Accept] === web.MimeTypes.JsonLd ? "jsonld" : "json";
480
- const component = core.ComponentFactory.get(componentName);
481
- const result = await component.get(request.pathParams.id, {
482
- includeDeleted: core.Coerce.boolean(request.query?.includeDeleted),
483
- includeChangesets: core.Coerce.boolean(request.query?.includeChangesets),
484
- verifySignatureDepth: request.query?.verifySignatureDepth
485
- });
486
- return {
487
- headers: {
488
- [web.HeaderTypes.ContentType]: mimeType === "json" ? web.MimeTypes.Json : web.MimeTypes.JsonLd
489
- },
490
- body: result
491
- };
492
- }
493
- /**
494
- * Update the graph vertex.
495
- * @param httpRequestContext The request context for the API.
496
- * @param componentName The name of the component to use in the routes.
497
- * @param request The request.
498
- * @returns The response object with additional http response properties.
499
- */
500
- async function auditableItemGraphUpdate(httpRequestContext, componentName, request) {
501
- core.Guards.object(ROUTES_SOURCE, "request", request);
502
- core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
503
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
504
- core.Guards.object(ROUTES_SOURCE, "request.body", request.body);
505
- const component = core.ComponentFactory.get(componentName);
506
- await component.update({ ...request.body, id: request.pathParams.id }, httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
507
- return {
508
- statusCode: web.HttpStatusCode.noContent
509
- };
510
- }
511
- /**
512
- * Query the graph vertices.
513
- * @param httpRequestContext The request context for the API.
514
- * @param componentName The name of the component to use in the routes.
515
- * @param request The request.
516
- * @returns The response object with additional http response properties.
517
- */
518
- async function auditableItemGraphList(httpRequestContext, componentName, request) {
519
- core.Guards.object(ROUTES_SOURCE, "request", request);
520
- core.Guards.object(ROUTES_SOURCE, "request.query", request.query);
521
- const mimeType = request.headers?.[web.HeaderTypes.Accept] === web.MimeTypes.JsonLd ? "jsonld" : "json";
522
- const component = core.ComponentFactory.get(componentName);
523
- const result = await component.query({
524
- id: request.query?.id,
525
- idMode: request.query?.idMode,
526
- idExact: core.Coerce.boolean(request.query?.idExact),
527
- resourceTypes: apiModels.HttpParameterHelper.arrayFromString(request.query?.resourceTypes)
528
- }, 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?.limit));
529
- return {
530
- headers: {
531
- [web.HeaderTypes.ContentType]: mimeType === "json" ? web.MimeTypes.Json : web.MimeTypes.JsonLd
532
- },
533
- body: result
534
- };
535
- }
536
-
537
- // Copyright 2024 IOTA Stiftung.
538
- // SPDX-License-Identifier: Apache-2.0.
539
- /**
540
- * Class for performing auditable item graph operations.
541
- */
542
- class AuditableItemGraphService {
543
- /**
544
- * Runtime name for the class.
545
- */
546
- static CLASS_NAME = "AuditableItemGraphService";
547
- /**
548
- * The namespace for the service.
549
- * @internal
550
- */
551
- static NAMESPACE = "aig";
552
- /**
553
- * The namespace for the service changeset.
554
- */
555
- static NAMESPACE_CHANGESET = "changeset";
556
- /**
557
- * The namespace for the service edge.
558
- */
559
- static NAMESPACE_EDGE = "edge";
560
- /**
561
- * The keys to pick when creating the proof for the stream.
562
- * @internal
563
- */
564
- static _PROOF_KEYS_CHANGESET = [
565
- "id",
566
- "vertexId",
567
- "userIdentity",
568
- "dateCreated",
569
- "patches"
570
- ];
571
- /**
572
- * The immutable proof component.
573
- * @internal
574
- */
575
- _immutableProofComponent;
576
- /**
577
- * The entity storage for vertices.
578
- * @internal
579
- */
580
- _vertexStorage;
581
- /**
582
- * The entity storage for changesets.
583
- * @internal
584
- */
585
- _changesetStorage;
586
- /**
587
- * The event bus component.
588
- * @internal
589
- */
590
- _eventBusComponent;
591
- /**
592
- * Create a new instance of AuditableItemGraphService.
593
- * @param options The dependencies for the auditable item graph connector.
594
- */
595
- constructor(options) {
596
- this._immutableProofComponent = core.ComponentFactory.get(options?.immutableProofComponentType ?? "immutable-proof");
597
- this._vertexStorage = entityStorageModels.EntityStorageConnectorFactory.get(options?.vertexEntityStorageType ?? "auditable-item-graph-vertex");
598
- this._changesetStorage = entityStorageModels.EntityStorageConnectorFactory.get(options?.changesetEntityStorageType ?? "auditable-item-graph-changeset");
599
- if (core.Is.stringValue(options?.eventBusComponentType)) {
600
- this._eventBusComponent = core.ComponentFactory.get(options.eventBusComponentType);
601
- }
602
- standardsSchemaOrg.SchemaOrgDataTypes.registerRedirects();
603
- }
604
- /**
605
- * Create a new graph vertex.
606
- * @param vertex The vertex to create.
607
- * @param vertex.annotationObject The annotation object for the vertex as JSON-LD.
608
- * @param vertex.aliases Alternative aliases that can be used to identify the vertex.
609
- * @param vertex.resources The resources attached to the vertex.
610
- * @param vertex.edges The edges connected to the vertex.
611
- * @param userIdentity The identity to create the auditable item graph operation with.
612
- * @param nodeIdentity The node identity to include in the auditable item graph.
613
- * @returns The id of the new graph item.
614
- */
615
- async create(vertex, userIdentity, nodeIdentity) {
616
- core.Guards.object(AuditableItemGraphService.CLASS_NAME, "vertex", vertex);
617
- core.Guards.stringValue(AuditableItemGraphService.CLASS_NAME, "userIdentity", userIdentity);
618
- core.Guards.stringValue(AuditableItemGraphService.CLASS_NAME, "nodeIdentity", nodeIdentity);
619
- try {
620
- if (core.Is.object(vertex.annotationObject)) {
621
- const validationFailures = [];
622
- await dataJsonLd.JsonLdHelper.validate(vertex.annotationObject, validationFailures);
623
- core.Validation.asValidationError(AuditableItemGraphService.CLASS_NAME, "vertex.annotationObject", validationFailures);
624
- }
625
- const id = core.Converter.bytesToHex(core.RandomHelper.generate(32), false);
626
- const context = {
627
- now: new Date(Date.now()).toISOString(),
628
- userIdentity,
629
- nodeIdentity
630
- };
631
- const vertexModel = {
632
- id,
633
- nodeIdentity,
634
- dateCreated: context.now
635
- };
636
- const originalEntity = core.ObjectHelper.clone(vertexModel);
637
- vertexModel.annotationObject = vertex.annotationObject;
638
- await this.updateAliasList(context, vertexModel, vertex.aliases);
639
- await this.updateResourceList(context, vertexModel, vertex.resources);
640
- await this.updateEdgeList(context, vertexModel, vertex.edges);
641
- delete originalEntity.aliasIndex;
642
- delete originalEntity.resourceTypeIndex;
643
- await this.addChangeset(context, originalEntity, vertexModel, true);
644
- await this._vertexStorage.set({
645
- ...vertexModel,
646
- ...this.buildIndexes(vertexModel)
647
- });
648
- const fullId = new core.Urn(AuditableItemGraphService.NAMESPACE, id).toString();
649
- await this._eventBusComponent?.publish(auditableItemGraphModels.AuditableItemGraphTopics.VertexCreated, { id: fullId });
650
- return fullId;
651
- }
652
- catch (error) {
653
- throw new core.GeneralError(AuditableItemGraphService.CLASS_NAME, "createFailed", undefined, error);
654
- }
655
- }
656
- /**
657
- * Get a graph vertex.
658
- * @param id The id of the vertex to get.
659
- * @param options Additional options for the get operation.
660
- * @param options.includeDeleted Whether to include deleted/updated aliases, resource, edges, defaults to false.
661
- * @param options.includeChangesets Whether to include the changesets of the vertex, defaults to false.
662
- * @param options.verifySignatureDepth How many signatures to verify, defaults to "none".
663
- * @returns The vertex if found.
664
- * @throws NotFoundError if the vertex is not found.
665
- */
666
- async get(id, options) {
667
- core.Guards.stringValue(AuditableItemGraphService.CLASS_NAME, "id", id);
668
- const urnParsed = core.Urn.fromValidString(id);
669
- if (urnParsed.namespaceIdentifier() !== AuditableItemGraphService.NAMESPACE) {
670
- throw new core.GeneralError(AuditableItemGraphService.CLASS_NAME, "namespaceMismatch", {
671
- namespace: AuditableItemGraphService.NAMESPACE,
672
- id
673
- });
674
- }
675
- try {
676
- const vertexId = urnParsed.namespaceSpecific(0);
677
- const vertexEntity = await this._vertexStorage.get(vertexId);
678
- if (core.Is.empty(vertexEntity)) {
679
- throw new core.NotFoundError(AuditableItemGraphService.CLASS_NAME, "vertexNotFound", id);
680
- }
681
- const vertexModel = this.vertexEntityToJsonLd(vertexEntity);
682
- const includeChangesets = options?.includeChangesets ?? false;
683
- const verifySignatureDepth = options?.verifySignatureDepth ?? "none";
684
- let verified;
685
- let changesets;
686
- if (verifySignatureDepth === auditableItemGraphModels.VerifyDepth.Current ||
687
- verifySignatureDepth === auditableItemGraphModels.VerifyDepth.All ||
688
- includeChangesets) {
689
- const verifyResult = await this.verifyChangesets(vertexModel, verifySignatureDepth);
690
- verified = verifyResult.verified;
691
- changesets = verifyResult.changesets;
692
- vertexModel["@context"].push(immutableProofModels.ImmutableProofContexts.ContextRoot);
693
- }
694
- if (!(options?.includeDeleted ?? false)) {
695
- if (core.Is.arrayValue(vertexModel.aliases)) {
696
- vertexModel.aliases = vertexModel.aliases.filter(a => core.Is.undefined(a.dateDeleted));
697
- if (vertexModel.aliases.length === 0) {
698
- delete vertexModel.aliases;
699
- }
700
- }
701
- if (core.Is.arrayValue(vertexModel.resources)) {
702
- vertexModel.resources = vertexModel.resources.filter(r => core.Is.undefined(r.dateDeleted));
703
- if (vertexModel.resources.length === 0) {
704
- delete vertexModel.resources;
705
- }
706
- }
707
- if (core.Is.arrayValue(vertexModel.edges)) {
708
- vertexModel.edges = vertexModel.edges.filter(r => core.Is.undefined(r.dateDeleted));
709
- if (vertexModel.edges.length === 0) {
710
- delete vertexModel.edges;
711
- }
712
- }
713
- }
714
- if (includeChangesets) {
715
- vertexModel.changesets = changesets;
716
- }
717
- if (verifySignatureDepth !== auditableItemGraphModels.VerifyDepth.None) {
718
- vertexModel.verified = verified;
719
- }
720
- return dataJsonLd.JsonLdProcessor.compact(vertexModel, vertexModel["@context"]);
721
- }
722
- catch (error) {
723
- throw new core.GeneralError(AuditableItemGraphService.CLASS_NAME, "getFailed", undefined, error);
724
- }
725
- }
726
- /**
727
- * Update a graph vertex.
728
- * @param vertex The vertex to update.
729
- * @param vertex.id The id of the vertex to update.
730
- * @param vertex.annotationObject The annotation object for the vertex as JSON-LD.
731
- * @param vertex.aliases Alternative aliases that can be used to identify the vertex.
732
- * @param vertex.resources The resources attached to the vertex.
733
- * @param vertex.edges The edges connected to the vertex.
734
- * @param userIdentity The identity to create the auditable item graph operation with.
735
- * @param nodeIdentity The node identity to include in the auditable item graph.
736
- * @returns Nothing.
737
- */
738
- async update(vertex, userIdentity, nodeIdentity) {
739
- core.Guards.object(AuditableItemGraphService.CLASS_NAME, "vertex", vertex);
740
- core.Guards.stringValue(AuditableItemGraphService.CLASS_NAME, "vertex.id", vertex.id);
741
- core.Guards.stringValue(AuditableItemGraphService.CLASS_NAME, "userIdentity", userIdentity);
742
- core.Guards.stringValue(AuditableItemGraphService.CLASS_NAME, "nodeIdentity", nodeIdentity);
743
- const urnParsed = core.Urn.fromValidString(vertex.id);
744
- if (urnParsed.namespaceIdentifier() !== AuditableItemGraphService.NAMESPACE) {
745
- throw new core.GeneralError(AuditableItemGraphService.CLASS_NAME, "namespaceMismatch", {
746
- namespace: AuditableItemGraphService.NAMESPACE,
747
- id: vertex.id
748
- });
749
- }
750
- try {
751
- const vertexId = urnParsed.namespaceSpecific(0);
752
- const vertexEntity = await this._vertexStorage.get(vertexId);
753
- if (core.Is.empty(vertexEntity)) {
754
- throw new core.NotFoundError(AuditableItemGraphService.CLASS_NAME, "vertexNotFound", vertex.id);
755
- }
756
- if (core.Is.object(vertex.annotationObject)) {
757
- const validationFailures = [];
758
- await dataJsonLd.JsonLdHelper.validate(vertex.annotationObject, validationFailures);
759
- core.Validation.asValidationError(AuditableItemGraphService.CLASS_NAME, "vertex.annotationObject", validationFailures);
760
- }
761
- const context = {
762
- now: new Date(Date.now()).toISOString(),
763
- userIdentity,
764
- nodeIdentity
765
- };
766
- delete vertexEntity.aliasIndex;
767
- const originalEntity = core.ObjectHelper.clone(vertexEntity);
768
- const newEntity = core.ObjectHelper.clone(vertexEntity);
769
- newEntity.annotationObject = vertex.annotationObject;
770
- await this.updateAliasList(context, newEntity, vertex.aliases);
771
- await this.updateResourceList(context, newEntity, vertex.resources);
772
- await this.updateEdgeList(context, newEntity, vertex.edges);
773
- const patches = await this.addChangeset(context, originalEntity, newEntity, false);
774
- if (patches.length > 0) {
775
- newEntity.dateModified = context.now;
776
- const indexes = this.buildIndexes(newEntity);
777
- await this._vertexStorage.set({
778
- ...newEntity,
779
- ...indexes
780
- });
781
- await this._eventBusComponent?.publish(auditableItemGraphModels.AuditableItemGraphTopics.VertexUpdated, { id: vertex.id, patches });
782
- }
783
- }
784
- catch (error) {
785
- throw new core.GeneralError(AuditableItemGraphService.CLASS_NAME, "updatingFailed", undefined, error);
786
- }
787
- }
788
- /**
789
- * Remove the verifiable storage for an item.
790
- * @param id The id of the vertex to get.
791
- * @param nodeIdentity The node identity to use for vault operations.
792
- * @returns Nothing.
793
- * @throws NotFoundError if the vertex is not found.
794
- */
795
- async removeVerifiable(id, nodeIdentity) {
796
- core.Guards.stringValue(AuditableItemGraphService.CLASS_NAME, "id", id);
797
- core.Guards.stringValue(AuditableItemGraphService.CLASS_NAME, "nodeIdentity", nodeIdentity);
798
- const urnParsed = core.Urn.fromValidString(id);
799
- if (urnParsed.namespaceIdentifier() !== AuditableItemGraphService.NAMESPACE) {
800
- throw new core.GeneralError(AuditableItemGraphService.CLASS_NAME, "namespaceMismatch", {
801
- namespace: AuditableItemGraphService.NAMESPACE,
802
- id
803
- });
804
- }
805
- try {
806
- const vertexId = urnParsed.namespaceSpecific(0);
807
- const vertexEntity = await this._vertexStorage.get(vertexId);
808
- if (core.Is.empty(vertexEntity)) {
809
- throw new core.NotFoundError(AuditableItemGraphService.CLASS_NAME, "vertexNotFound", id);
810
- }
811
- let changesetsResult;
812
- do {
813
- changesetsResult = await this._changesetStorage.query({
814
- property: "vertexId",
815
- value: vertexId,
816
- comparison: entity.ComparisonOperator.Equals
817
- }, [
818
- {
819
- property: "dateCreated",
820
- sortDirection: entity.SortDirection.Ascending
821
- }
822
- ], undefined, changesetsResult?.cursor);
823
- for (const changeset of changesetsResult.entities) {
824
- if (core.Is.stringValue(changeset.proofId)) {
825
- await this._immutableProofComponent.removeVerifiable(changeset.proofId, nodeIdentity);
826
- delete changeset.proofId;
827
- await this._changesetStorage.set(changeset);
828
- }
829
- }
830
- } while (core.Is.stringValue(changesetsResult.cursor));
831
- }
832
- catch (error) {
833
- throw new core.GeneralError(AuditableItemGraphService.CLASS_NAME, "removeVerifiableFailed", undefined, error);
834
- }
835
- }
836
- /**
837
- * Query the graph for vertices.
838
- * @param options The query options.
839
- * @param options.id The optional id to look for.
840
- * @param options.idMode Look in id, alias or both, defaults to both.
841
- * @param options.idExact Find only exact matches, default to false meaning partial matching.
842
- * @param options.includesResourceTypes Include vertices with specific resource types.
843
- * @param conditions Conditions to use in the query.
844
- * @param orderBy The order for the results, defaults to created.
845
- * @param orderByDirection The direction for the order, defaults to desc.
846
- * @param properties The properties to return, if not provided defaults to id, created, aliases and object.
847
- * @param cursor The cursor to request the next chunk of entities.
848
- * @param limit Limit the number of entities to return.
849
- * @returns The entities, which can be partial if a limited keys list was provided.
850
- */
851
- async query(options, conditions, orderBy, orderByDirection, properties, cursor, limit) {
852
- try {
853
- const propertiesToReturn = properties ?? [
854
- "id",
855
- "dateCreated",
856
- "dateModified",
857
- "aliases",
858
- "annotationObject"
859
- ];
860
- const combinedConditions = conditions ?? [];
861
- const orderProperty = orderBy ?? "dateCreated";
862
- const orderDirection = orderByDirection ?? entity.SortDirection.Descending;
863
- const idExact = options?.idExact ?? false;
864
- const idOrAlias = options?.id;
865
- if (core.Is.stringValue(idOrAlias)) {
866
- const idMode = options?.idMode ?? "both";
867
- if (idMode === "id" || idMode === "both") {
868
- combinedConditions.push({
869
- property: "id",
870
- comparison: idExact ? entity.ComparisonOperator.Equals : entity.ComparisonOperator.Includes,
871
- value: idOrAlias
872
- });
873
- }
874
- if (idMode === "alias" || idMode === "both") {
875
- combinedConditions.push({
876
- property: "aliasIndex",
877
- comparison: entity.ComparisonOperator.Includes,
878
- value: idExact ? `||${idOrAlias.toLowerCase()}||` : idOrAlias.toLowerCase()
879
- });
880
- }
881
- }
882
- if (core.Is.arrayValue(options?.includesResourceTypes)) {
883
- for (const resourceType of options.includesResourceTypes) {
884
- combinedConditions.push({
885
- property: "resourceTypeIndex",
886
- comparison: entity.ComparisonOperator.Includes,
887
- value: `||${resourceType.toLowerCase()}||`
888
- });
889
- }
890
- }
891
- if (!propertiesToReturn.includes("id")) {
892
- propertiesToReturn.unshift("id");
893
- }
894
- const results = await this._vertexStorage.query(combinedConditions.length > 0
895
- ? {
896
- conditions: combinedConditions,
897
- logicalOperator: entity.LogicalOperator.Or
898
- }
899
- : undefined, [
900
- {
901
- property: orderProperty,
902
- sortDirection: orderDirection
903
- }
904
- ], propertiesToReturn, cursor, limit);
905
- const models = results.entities.map(e => this.vertexEntityToJsonLd(e));
906
- const vertexList = {
907
- "@context": [
908
- standardsSchemaOrg.SchemaOrgContexts.ContextRoot,
909
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot,
910
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRootCommon
911
- ],
912
- type: [standardsSchemaOrg.SchemaOrgTypes.ItemList, auditableItemGraphModels.AuditableItemGraphTypes.VertexList],
913
- [standardsSchemaOrg.SchemaOrgTypes.ItemListElement]: models,
914
- [standardsSchemaOrg.SchemaOrgTypes.NextItem]: results.cursor
915
- };
916
- return dataJsonLd.JsonLdProcessor.compact(vertexList, vertexList["@context"]);
917
- }
918
- catch (error) {
919
- throw new core.GeneralError(AuditableItemGraphService.CLASS_NAME, "queryingFailed", undefined, error);
920
- }
921
- }
922
- /**
923
- * Map the vertex entity to JSON-LD.
924
- * @param vertexEntity The vertex entity.
925
- * @returns The model.
926
- * @internal
927
- */
928
- vertexEntityToJsonLd(vertexEntity) {
929
- const model = {
930
- "@context": [
931
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot,
932
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRootCommon,
933
- standardsSchemaOrg.SchemaOrgContexts.ContextRoot
934
- ],
935
- type: auditableItemGraphModels.AuditableItemGraphTypes.Vertex,
936
- id: new core.Urn(AuditableItemGraphService.NAMESPACE, vertexEntity.id).toString(),
937
- dateCreated: vertexEntity.dateCreated,
938
- dateModified: vertexEntity.dateModified,
939
- nodeIdentity: vertexEntity.nodeIdentity,
940
- annotationObject: vertexEntity.annotationObject
941
- };
942
- if (core.Is.arrayValue(vertexEntity.aliases)) {
943
- model.aliases ??= [];
944
- for (const aliasEntity of vertexEntity.aliases) {
945
- const aliasModel = {
946
- "@context": [
947
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot,
948
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRootCommon,
949
- standardsSchemaOrg.SchemaOrgContexts.ContextRoot
950
- ],
951
- type: auditableItemGraphModels.AuditableItemGraphTypes.Alias,
952
- id: aliasEntity.id,
953
- aliasFormat: aliasEntity.aliasFormat,
954
- dateCreated: aliasEntity.dateCreated,
955
- dateModified: aliasEntity.dateModified,
956
- dateDeleted: aliasEntity.dateDeleted,
957
- annotationObject: aliasEntity.annotationObject
958
- };
959
- model.aliases.push(aliasModel);
960
- }
961
- }
962
- if (core.Is.arrayValue(vertexEntity.resources)) {
963
- model.resources ??= [];
964
- for (const resourceEntity of vertexEntity.resources) {
965
- const resourceModel = {
966
- "@context": [
967
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot,
968
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRootCommon,
969
- standardsSchemaOrg.SchemaOrgContexts.ContextRoot
970
- ],
971
- type: auditableItemGraphModels.AuditableItemGraphTypes.Resource,
972
- id: resourceEntity.id,
973
- dateCreated: resourceEntity.dateCreated,
974
- dateModified: resourceEntity.dateModified,
975
- dateDeleted: resourceEntity.dateDeleted,
976
- resourceObject: resourceEntity.resourceObject
977
- };
978
- model.resources.push(resourceModel);
979
- }
980
- }
981
- if (core.Is.arrayValue(vertexEntity.edges)) {
982
- model.edges ??= [];
983
- for (const edgeEntity of vertexEntity.edges) {
984
- const edgeModel = {
985
- "@context": [
986
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot,
987
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRootCommon,
988
- standardsSchemaOrg.SchemaOrgContexts.ContextRoot
989
- ],
990
- type: auditableItemGraphModels.AuditableItemGraphTypes.Edge,
991
- id: this.fullEdgeId(vertexEntity.id, edgeEntity.id),
992
- targetId: edgeEntity.targetId,
993
- dateCreated: edgeEntity.dateCreated,
994
- dateModified: edgeEntity.dateModified,
995
- dateDeleted: edgeEntity.dateDeleted,
996
- edgeRelationships: edgeEntity.edgeRelationships,
997
- annotationObject: edgeEntity.annotationObject
998
- };
999
- model.edges.push(edgeModel);
1000
- }
1001
- }
1002
- return model;
1003
- }
1004
- /**
1005
- * Map the changeset entity to a JSON-LD.
1006
- * @param vertexId The id of the vertex the changeset belongs to.
1007
- * @param changesetEntity The changeset entity.
1008
- * @returns The model.
1009
- * @internal
1010
- */
1011
- changesetEntityToJsonLd(vertexId, changesetEntity) {
1012
- const model = {
1013
- "@context": [
1014
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot,
1015
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRootCommon,
1016
- standardsSchemaOrg.SchemaOrgContexts.ContextRoot
1017
- ],
1018
- type: auditableItemGraphModels.AuditableItemGraphTypes.Changeset,
1019
- id: new core.Urn(AuditableItemGraphService.NAMESPACE, [
1020
- vertexId,
1021
- AuditableItemGraphService.NAMESPACE_CHANGESET,
1022
- changesetEntity.id
1023
- ]).toString(),
1024
- dateCreated: changesetEntity.dateCreated,
1025
- userIdentity: changesetEntity.userIdentity,
1026
- patches: changesetEntity.patches.map(p => ({
1027
- "@context": [
1028
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRoot,
1029
- auditableItemGraphModels.AuditableItemGraphContexts.ContextRootCommon,
1030
- standardsSchemaOrg.SchemaOrgContexts.ContextRoot
1031
- ],
1032
- type: auditableItemGraphModels.AuditableItemGraphTypes.PatchOperation,
1033
- patchOperation: p.op,
1034
- patchPath: p.path,
1035
- patchFrom: p.from,
1036
- patchValue: p.value
1037
- })),
1038
- proofId: changesetEntity.proofId
1039
- };
1040
- return model;
1041
- }
1042
- /**
1043
- * Update the aliases of a vertex model.
1044
- * @param context The context for the operation.
1045
- * @param vertex The vertex.
1046
- * @param aliases The aliases to update.
1047
- * @internal
1048
- */
1049
- async updateAliasList(context, vertex, aliases) {
1050
- const active = vertex.aliases?.filter(a => core.Is.empty(a.dateDeleted)) ?? [];
1051
- // The active aliases that are not in the update list should be marked as deleted.
1052
- if (core.Is.arrayValue(active)) {
1053
- for (const alias of active) {
1054
- if (!aliases?.find(a => a.id === alias.id)) {
1055
- alias.dateDeleted = context.now;
1056
- }
1057
- }
1058
- }
1059
- if (core.Is.arrayValue(aliases)) {
1060
- for (const alias of aliases) {
1061
- await this.updateAlias(context, vertex, alias);
1062
- }
1063
- }
1064
- }
1065
- /**
1066
- * Update an alias in the vertex.
1067
- * @param context The context for the operation.
1068
- * @param vertex The vertex.
1069
- * @param alias The alias.
1070
- * @internal
1071
- */
1072
- async updateAlias(context, vertex, alias) {
1073
- core.Guards.object(AuditableItemGraphService.CLASS_NAME, "alias", alias);
1074
- core.Guards.stringValue(AuditableItemGraphService.CLASS_NAME, "alias.id", alias.id);
1075
- if (alias.unique ?? false) {
1076
- const existingVertices = await this.findMatchingVertices(vertex.id, alias.id);
1077
- if (existingVertices) {
1078
- throw new core.GeneralError(AuditableItemGraphService.CLASS_NAME, "aliasNotUnique", {
1079
- aliasId: alias.id
1080
- });
1081
- }
1082
- }
1083
- if (core.Is.object(alias.annotationObject)) {
1084
- const validationFailures = [];
1085
- await dataJsonLd.JsonLdHelper.validate(alias.annotationObject, validationFailures);
1086
- core.Validation.asValidationError(AuditableItemGraphService.CLASS_NAME, "alias.annotationObject", validationFailures);
1087
- }
1088
- // Try to find an existing alias with the same id.
1089
- const existing = vertex.aliases?.find(a => a.id === alias.id);
1090
- if (core.Is.empty(existing) || !core.Is.empty(existing?.dateDeleted)) {
1091
- // Did not find a matching item, or found one which is deleted.
1092
- vertex.aliases ??= [];
1093
- const model = {
1094
- id: alias.id,
1095
- aliasFormat: alias.aliasFormat,
1096
- dateCreated: context.now,
1097
- annotationObject: alias.annotationObject
1098
- };
1099
- vertex.aliases.push(model);
1100
- }
1101
- else if (existing.aliasFormat !== alias.aliasFormat ||
1102
- !core.ObjectHelper.equal(existing.annotationObject, alias.annotationObject, false)) {
1103
- // Existing alias found, update the annotationObject.
1104
- existing.dateModified = context.now;
1105
- existing.aliasFormat = alias.aliasFormat;
1106
- existing.annotationObject = alias.annotationObject;
1107
- }
1108
- }
1109
- /**
1110
- * Update the resources of a vertex.
1111
- * @param context The context for the operation.
1112
- * @param vertex The vertex.
1113
- * @param resources The resources to update.
1114
- * @internal
1115
- */
1116
- async updateResourceList(context, vertex, resources) {
1117
- if (core.Is.arrayValue(resources)) {
1118
- for (let i = 0; i < resources.length; i++) {
1119
- const id = this.getResourceId(resources[i]);
1120
- if (core.Is.empty(id)) {
1121
- throw new core.GeneralError(AuditableItemGraphService.CLASS_NAME, "resourceIdMissing", {
1122
- index: i
1123
- });
1124
- }
1125
- }
1126
- }
1127
- const active = vertex.resources?.filter(r => core.Is.empty(r.dateDeleted)) ?? [];
1128
- // The active resources that are not in the update list should be marked as deleted.
1129
- if (core.Is.arrayValue(active)) {
1130
- for (const resource of active) {
1131
- if (!resources?.find(a => this.getResourceId(a) === this.getResourceId(resource))) {
1132
- resource.dateDeleted = context.now;
1133
- }
1134
- }
1135
- }
1136
- if (core.Is.arrayValue(resources)) {
1137
- for (const resource of resources) {
1138
- await this.updateResource(context, vertex, resource);
1139
- }
1140
- }
1141
- }
1142
- /**
1143
- * Add a resource to the vertex.
1144
- * @param context The context for the operation.
1145
- * @param vertex The vertex.
1146
- * @param resource The resource.
1147
- * @internal
1148
- */
1149
- async updateResource(context, vertex, resource) {
1150
- core.Guards.object(AuditableItemGraphService.CLASS_NAME, "resource", resource);
1151
- if (core.Is.object(resource.resourceObject)) {
1152
- const validationFailures = [];
1153
- await dataJsonLd.JsonLdHelper.validate(resource.resourceObject, validationFailures);
1154
- core.Validation.asValidationError(AuditableItemGraphService.CLASS_NAME, "resource.resourceObject", validationFailures);
1155
- }
1156
- // Try to find an existing resource with the same id.
1157
- const existing = vertex.resources?.find(r => this.getResourceId(r) === this.getResourceId(resource));
1158
- if (core.Is.empty(existing) || !core.Is.empty(existing?.dateDeleted)) {
1159
- // Did not find a matching item, or found one which is deleted.
1160
- vertex.resources ??= [];
1161
- const model = {
1162
- id: resource.id,
1163
- dateCreated: context.now,
1164
- resourceObject: resource.resourceObject
1165
- };
1166
- vertex.resources.push(model);
1167
- }
1168
- else if (!core.ObjectHelper.equal(existing.resourceObject, resource.resourceObject, false)) {
1169
- // Existing resource found, update the resourceObject.
1170
- existing.dateModified = context.now;
1171
- existing.resourceObject = resource.resourceObject;
1172
- }
1173
- }
1174
- /**
1175
- * Update the edges of a vertex.
1176
- * @param context The context for the operation.
1177
- * @param vertex The vertex.
1178
- * @param edges The edges to update.
1179
- * @internal
1180
- */
1181
- async updateEdgeList(context, vertex, edges) {
1182
- const active = vertex.edges?.filter(e => core.Is.empty(e.dateDeleted)) ?? [];
1183
- // The active edges that are not in the update list should be marked as deleted.
1184
- if (core.Is.arrayValue(active)) {
1185
- for (const edge of active) {
1186
- if (!edges?.find(e => core.Is.stringValue(e.id) && this.reduceEdgeId(e.id) === edge.id)) {
1187
- edge.dateDeleted = context.now;
1188
- }
1189
- }
1190
- }
1191
- if (core.Is.arrayValue(edges)) {
1192
- for (const edge of edges) {
1193
- await this.updateEdge(context, vertex, edge);
1194
- }
1195
- }
1196
- }
1197
- /**
1198
- * Add an edge to the vertex.
1199
- * @param context The context for the operation.
1200
- * @param vertex The vertex.
1201
- * @param edge The edge.
1202
- * @internal
1203
- */
1204
- async updateEdge(context, vertex, edge) {
1205
- core.Guards.object(AuditableItemGraphService.CLASS_NAME, "edge", edge);
1206
- core.Guards.stringValue(AuditableItemGraphService.CLASS_NAME, "edge.targetId", edge.targetId);
1207
- core.Guards.arrayValue(AuditableItemGraphService.CLASS_NAME, "edge.edgeRelationships", edge.edgeRelationships);
1208
- const validationFailures = [];
1209
- if (edge.targetId === vertex.id) {
1210
- validationFailures.push({
1211
- property: "id",
1212
- reason: `validation.${core.StringHelper.camelCase(AuditableItemGraphService.CLASS_NAME)}.edgeIdSameAsVertexId`,
1213
- properties: {
1214
- targetId: edge.targetId
1215
- }
1216
- });
1217
- }
1218
- if (core.Is.object(edge.annotationObject)) {
1219
- await dataJsonLd.JsonLdHelper.validate(edge.annotationObject, validationFailures);
1220
- }
1221
- core.Validation.asValidationError(AuditableItemGraphService.CLASS_NAME, "edge.annotationObject", validationFailures);
1222
- let findId = core.Is.stringValue(edge.id) ? this.reduceEdgeId(edge.id) : undefined;
1223
- if (core.Is.empty(findId)) {
1224
- findId = core.Converter.bytesToHex(core.RandomHelper.generate(32), false);
1225
- }
1226
- // Try to find an existing edge with the same id.
1227
- const existing = vertex.edges?.find(r => r.id === findId);
1228
- if (core.Is.empty(existing) || !core.Is.empty(existing?.dateDeleted)) {
1229
- // Did not find a matching item, or found one which is deleted.
1230
- vertex.edges ??= [];
1231
- const model = {
1232
- id: findId,
1233
- targetId: edge.targetId,
1234
- dateCreated: context.now,
1235
- annotationObject: edge.annotationObject,
1236
- edgeRelationships: edge.edgeRelationships
1237
- };
1238
- vertex.edges.push(model);
1239
- }
1240
- else if (existing.targetId !== edge.targetId ||
1241
- !core.ArrayHelper.matches(existing.edgeRelationships, edge.edgeRelationships) ||
1242
- !core.ObjectHelper.equal(existing.annotationObject, edge.annotationObject, false)) {
1243
- // Existing edge found, update the properties.
1244
- existing.targetId = edge.targetId;
1245
- existing.dateModified = context.now;
1246
- existing.edgeRelationships = edge.edgeRelationships;
1247
- existing.annotationObject = edge.annotationObject;
1248
- }
1249
- }
1250
- /**
1251
- * Add a changeset to the vertex and generate the associated verifications.
1252
- * @param context The context for the operation.
1253
- * @param original The original vertex.
1254
- * @param updated The updated vertex.
1255
- * @param isNew Whether this is a new item.
1256
- * @returns True if there were changes.
1257
- * @internal
1258
- */
1259
- async addChangeset(context, original, updated, isNew) {
1260
- const patches = core.JsonHelper.diff(original, updated);
1261
- // If there is a diff set or this is the first time the item is created.
1262
- if (patches.length > 0 || isNew) {
1263
- const changesetEntity = {
1264
- id: core.Converter.bytesToHex(core.RandomHelper.generate(32), false),
1265
- vertexId: updated.id,
1266
- dateCreated: context.now,
1267
- userIdentity: context.userIdentity,
1268
- patches
1269
- };
1270
- // Create the JSON-LD object we want to use for the proof
1271
- // this is a subset of fixed properties from the changeset object.
1272
- const reducedChangesetJsonLd = await this.changesetEntityToJsonLd(original.id, core.ObjectHelper.pick(changesetEntity, AuditableItemGraphService._PROOF_KEYS_CHANGESET));
1273
- // Create the proof for the changeset object
1274
- changesetEntity.proofId = await this._immutableProofComponent.create(reducedChangesetJsonLd, context.userIdentity, context.nodeIdentity);
1275
- // Link the verifiable storage id to the changeset
1276
- await this._changesetStorage.set(changesetEntity);
1277
- return patches;
1278
- }
1279
- return [];
1280
- }
1281
- /**
1282
- * Verify the changesets of a vertex.
1283
- * @param nodeIdentity The node identity to verify the changesets with.
1284
- * @param vertex The vertex to verify.
1285
- * @param verifySignatureDepth How many signatures to verify.
1286
- * @internal
1287
- */
1288
- async verifyChangesets(vertex, verifySignatureDepth) {
1289
- const changesets = [];
1290
- let changesetsResult;
1291
- let verified = true;
1292
- const vertexId = core.Urn.fromValidString(vertex.id);
1293
- do {
1294
- changesetsResult = await this._changesetStorage.query({
1295
- property: "vertexId",
1296
- value: vertexId.namespaceSpecific(),
1297
- comparison: entity.ComparisonOperator.Equals
1298
- }, [
1299
- {
1300
- property: "dateCreated",
1301
- sortDirection: entity.SortDirection.Ascending
1302
- }
1303
- ], undefined, changesetsResult?.cursor);
1304
- const storedChangesets = changesetsResult.entities;
1305
- if (core.Is.arrayValue(storedChangesets)) {
1306
- for (let i = 0; i < storedChangesets.length; i++) {
1307
- const storedChangeset = storedChangesets[i];
1308
- const storedChangesetJsonLd = this.changesetEntityToJsonLd(vertexId.namespaceSpecific(), storedChangeset);
1309
- changesets.push(storedChangesetJsonLd);
1310
- // If we are verifying all signatures
1311
- // or this is the last changeset (cursor is empty)
1312
- // and the changeset has a proofId, then verify the proof.
1313
- if (verifySignatureDepth === auditableItemGraphModels.VerifyDepth.All ||
1314
- (verifySignatureDepth === auditableItemGraphModels.VerifyDepth.Current &&
1315
- !core.Is.stringValue(changesetsResult.cursor) &&
1316
- i === storedChangesets.length - 1)) {
1317
- if (!core.Is.stringValue(storedChangeset.proofId)) {
1318
- verified = false;
1319
- storedChangesetJsonLd.verification = {
1320
- "@context": immutableProofModels.ImmutableProofContexts.ContextRoot,
1321
- type: immutableProofModels.ImmutableProofTypes.ImmutableProofVerification,
1322
- verified: false,
1323
- failure: immutableProofModels.ImmutableProofFailure.ProofMissing
1324
- };
1325
- }
1326
- else {
1327
- // Verify the proof for the changeset object
1328
- storedChangesetJsonLd.verification = await this._immutableProofComponent.verify(storedChangeset.proofId);
1329
- if (!storedChangesetJsonLd.verification.verified) {
1330
- verified = false;
1331
- }
1332
- }
1333
- }
1334
- }
1335
- }
1336
- } while (core.Is.stringValue(changesetsResult.cursor));
1337
- return {
1338
- verified,
1339
- changesets
1340
- };
1341
- }
1342
- /**
1343
- * Get the resource id from a resource object.
1344
- * @param resource The resource.
1345
- * @param resource.id The id of the resource.
1346
- * @param resource.resourceObject The resource object.
1347
- * @returns The resource id if it can find one.
1348
- */
1349
- getResourceId(resource) {
1350
- return (resource.id ??
1351
- core.ObjectHelper.extractProperty(resource.resourceObject, ["id", "@id"], false));
1352
- }
1353
- /**
1354
- * Build the indexes for the vertex.
1355
- * @param vertex The vertex to build the indexes for.
1356
- * @returns The indexes.
1357
- * @internal
1358
- */
1359
- buildIndexes(vertex) {
1360
- const aliasIndex = vertex.aliases
1361
- ?.filter(a => core.Is.empty(a.dateDeleted))
1362
- .map(a => a.id)
1363
- .join("||")
1364
- .toLowerCase();
1365
- const resourceTypes = [];
1366
- if (core.Is.arrayValue(vertex.resources)) {
1367
- for (const resource of vertex.resources) {
1368
- const resourceType = core.ObjectHelper.extractProperty(resource.resourceObject, ["@type", "type"], false);
1369
- if (core.Is.stringValue(resourceType) && !resourceTypes.includes(resourceType)) {
1370
- resourceTypes.push(resourceType);
1371
- }
1372
- }
1373
- }
1374
- const resourceTypeIndex = resourceTypes.join("||").toLowerCase();
1375
- return {
1376
- aliasIndex: core.Is.stringValue(aliasIndex) ? `||${aliasIndex}||` : undefined,
1377
- resourceTypeIndex: core.Is.stringValue(resourceTypeIndex) ? `||${resourceTypeIndex}||` : undefined
1378
- };
1379
- }
1380
- /**
1381
- * Find vertices with matching aliases.
1382
- * @param vertexId The id of the vertex to exclude from the search.
1383
- * @param aliasId The alias id to try and find.
1384
- * @returns True if any other vertices have matching aliases.
1385
- * @internal
1386
- */
1387
- async findMatchingVertices(vertexId, aliasId) {
1388
- const results = await this._vertexStorage.query({
1389
- conditions: [
1390
- {
1391
- property: "aliasIndex",
1392
- comparison: entity.ComparisonOperator.Includes,
1393
- value: `||${aliasId.toLowerCase()}||`
1394
- },
1395
- {
1396
- property: "id",
1397
- value: vertexId,
1398
- comparison: entity.ComparisonOperator.NotEquals
1399
- }
1400
- ],
1401
- logicalOperator: entity.LogicalOperator.And
1402
- });
1403
- return results.entities.length > 0;
1404
- }
1405
- /**
1406
- * Reduce the edge ID from a URN.
1407
- * @param urn The URN to reduce.
1408
- * @returns The edge ID.
1409
- * @throws GeneralError if the URN is not valid or not an edge URN.
1410
- * @internal
1411
- */
1412
- reduceEdgeId(urn) {
1413
- const urnParsed = core.Urn.fromValidString(urn);
1414
- if (urnParsed.namespaceIdentifier() !== AuditableItemGraphService.NAMESPACE) {
1415
- throw new core.GeneralError(AuditableItemGraphService.CLASS_NAME, "namespaceMismatch", {
1416
- namespace: AuditableItemGraphService.NAMESPACE,
1417
- id: urn
1418
- });
1419
- }
1420
- if (urnParsed.namespaceSpecificParts().length !== 3) {
1421
- throw new core.GeneralError(AuditableItemGraphService.CLASS_NAME, "invalidEdgeId", {
1422
- edgeId: urn
1423
- });
1424
- }
1425
- if (urnParsed.namespaceSpecificParts()[1] !== AuditableItemGraphService.NAMESPACE_EDGE) {
1426
- throw new core.GeneralError(AuditableItemGraphService.CLASS_NAME, "invalidEdgeId", {
1427
- edgeId: urn
1428
- });
1429
- }
1430
- return urnParsed.namespaceSpecificParts()[2];
1431
- }
1432
- /**
1433
- * Create a full edge ID URN from a vertex ID and edge ID.
1434
- * @param vertexId The vertex id the edge belongs to.
1435
- * @param edgeId The edge id.
1436
- * @returns The full edge ID URN.
1437
- * @internal
1438
- */
1439
- fullEdgeId(vertexId, edgeId) {
1440
- return new core.Urn(AuditableItemGraphService.NAMESPACE, [
1441
- vertexId,
1442
- AuditableItemGraphService.NAMESPACE_EDGE,
1443
- edgeId
1444
- ]).toString();
1445
- }
1446
- }
1447
-
1448
- // Copyright 2024 IOTA Stiftung.
1449
- // SPDX-License-Identifier: Apache-2.0.
1450
- /**
1451
- * Class describing the auditable item graph alias.
1452
- */
1453
- exports.AuditableItemGraphAlias = class AuditableItemGraphAlias {
1454
- /**
1455
- * The alternative alias for the vertex.
1456
- */
1457
- id;
1458
- /**
1459
- * The format of the alias for the vertex.
1460
- */
1461
- aliasFormat;
1462
- /**
1463
- * The date/time of when the alias was created.
1464
- */
1465
- dateCreated;
1466
- /**
1467
- * The date/time of when the alias was last modified.
1468
- */
1469
- dateModified;
1470
- /**
1471
- * The timestamp of when the alias was deleted, as we never actually remove items.
1472
- */
1473
- dateDeleted;
1474
- /**
1475
- * Object to associate with the alias as JSON-LD.
1476
- */
1477
- annotationObject;
1478
- };
1479
- __decorate([
1480
- entity.property({ type: "string" }),
1481
- __metadata("design:type", String)
1482
- ], exports.AuditableItemGraphAlias.prototype, "id", void 0);
1483
- __decorate([
1484
- entity.property({ type: "string", optional: true }),
1485
- __metadata("design:type", String)
1486
- ], exports.AuditableItemGraphAlias.prototype, "aliasFormat", void 0);
1487
- __decorate([
1488
- entity.property({ type: "string", format: "date-time" }),
1489
- __metadata("design:type", String)
1490
- ], exports.AuditableItemGraphAlias.prototype, "dateCreated", void 0);
1491
- __decorate([
1492
- entity.property({ type: "string", format: "date-time", optional: true }),
1493
- __metadata("design:type", String)
1494
- ], exports.AuditableItemGraphAlias.prototype, "dateModified", void 0);
1495
- __decorate([
1496
- entity.property({ type: "string", format: "date-time", optional: true }),
1497
- __metadata("design:type", String)
1498
- ], exports.AuditableItemGraphAlias.prototype, "dateDeleted", void 0);
1499
- __decorate([
1500
- entity.property({ type: "object", itemTypeRef: dataJsonLd.JsonLdTypes.NodeObject, optional: true }),
1501
- __metadata("design:type", Object)
1502
- ], exports.AuditableItemGraphAlias.prototype, "annotationObject", void 0);
1503
- exports.AuditableItemGraphAlias = __decorate([
1504
- entity.entity()
1505
- ], exports.AuditableItemGraphAlias);
1506
-
1507
- // Copyright 2024 IOTA Stiftung.
1508
- // SPDX-License-Identifier: Apache-2.0.
1509
- /**
1510
- * Class describing a set of updates to the vertex.
1511
- */
1512
- exports.AuditableItemGraphChangeset = class AuditableItemGraphChangeset {
1513
- /**
1514
- * The id of the changeset.
1515
- */
1516
- id;
1517
- /**
1518
- * The vertex the changeset belongs to.
1519
- */
1520
- vertexId;
1521
- /**
1522
- * The date/time of when the changeset was created.
1523
- */
1524
- dateCreated;
1525
- /**
1526
- * The identity of the user who made the changeset.
1527
- */
1528
- userIdentity;
1529
- /**
1530
- * The patches in the changeset.
1531
- */
1532
- patches;
1533
- /**
1534
- * The immutable proof id which contains the signature for this changeset.
1535
- */
1536
- proofId;
1537
- };
1538
- __decorate([
1539
- entity.property({ type: "string", isPrimary: true }),
1540
- __metadata("design:type", String)
1541
- ], exports.AuditableItemGraphChangeset.prototype, "id", void 0);
1542
- __decorate([
1543
- entity.property({ type: "string", isSecondary: true }),
1544
- __metadata("design:type", String)
1545
- ], exports.AuditableItemGraphChangeset.prototype, "vertexId", void 0);
1546
- __decorate([
1547
- entity.property({ type: "string", format: "date-time", sortDirection: entity.SortDirection.Descending }),
1548
- __metadata("design:type", String)
1549
- ], exports.AuditableItemGraphChangeset.prototype, "dateCreated", void 0);
1550
- __decorate([
1551
- entity.property({ type: "string" }),
1552
- __metadata("design:type", String)
1553
- ], exports.AuditableItemGraphChangeset.prototype, "userIdentity", void 0);
1554
- __decorate([
1555
- entity.property({ type: "array", itemTypeRef: "AuditableItemGraphPatch" }),
1556
- __metadata("design:type", Array)
1557
- ], exports.AuditableItemGraphChangeset.prototype, "patches", void 0);
1558
- __decorate([
1559
- entity.property({ type: "string", optional: true }),
1560
- __metadata("design:type", String)
1561
- ], exports.AuditableItemGraphChangeset.prototype, "proofId", void 0);
1562
- exports.AuditableItemGraphChangeset = __decorate([
1563
- entity.entity()
1564
- ], exports.AuditableItemGraphChangeset);
1565
-
1566
- // Copyright 2024 IOTA Stiftung.
1567
- // SPDX-License-Identifier: Apache-2.0.
1568
- /**
1569
- * Class describing the auditable item graph edge.
1570
- */
1571
- exports.AuditableItemGraphEdge = class AuditableItemGraphEdge {
1572
- /**
1573
- * The id of the edge.
1574
- */
1575
- id;
1576
- /**
1577
- * The date/time of when the edge was created.
1578
- */
1579
- dateCreated;
1580
- /**
1581
- * The date/time of when the edge was last modified.
1582
- */
1583
- dateModified;
1584
- /**
1585
- * The timestamp of when the edge was deleted, as we never actually remove items.
1586
- */
1587
- dateDeleted;
1588
- /**
1589
- * The target id of the edge.
1590
- */
1591
- targetId;
1592
- /**
1593
- * The relationships between the two vertices.
1594
- */
1595
- edgeRelationships;
1596
- /**
1597
- * Object to associate with the edge as JSON-LD.
1598
- */
1599
- annotationObject;
1600
- };
1601
- __decorate([
1602
- entity.property({ type: "string" }),
1603
- __metadata("design:type", String)
1604
- ], exports.AuditableItemGraphEdge.prototype, "id", void 0);
1605
- __decorate([
1606
- entity.property({ type: "string", format: "date-time" }),
1607
- __metadata("design:type", String)
1608
- ], exports.AuditableItemGraphEdge.prototype, "dateCreated", void 0);
1609
- __decorate([
1610
- entity.property({ type: "string", format: "date-time", optional: true }),
1611
- __metadata("design:type", String)
1612
- ], exports.AuditableItemGraphEdge.prototype, "dateModified", void 0);
1613
- __decorate([
1614
- entity.property({ type: "string", format: "date-time", optional: true }),
1615
- __metadata("design:type", String)
1616
- ], exports.AuditableItemGraphEdge.prototype, "dateDeleted", void 0);
1617
- __decorate([
1618
- entity.property({ type: "string" }),
1619
- __metadata("design:type", String)
1620
- ], exports.AuditableItemGraphEdge.prototype, "targetId", void 0);
1621
- __decorate([
1622
- entity.property({ type: "array" }),
1623
- __metadata("design:type", Array)
1624
- ], exports.AuditableItemGraphEdge.prototype, "edgeRelationships", void 0);
1625
- __decorate([
1626
- entity.property({ type: "object", itemTypeRef: dataJsonLd.JsonLdTypes.NodeObject, optional: true }),
1627
- __metadata("design:type", Object)
1628
- ], exports.AuditableItemGraphEdge.prototype, "annotationObject", void 0);
1629
- exports.AuditableItemGraphEdge = __decorate([
1630
- entity.entity()
1631
- ], exports.AuditableItemGraphEdge);
1632
-
1633
- // Copyright 2024 IOTA Stiftung.
1634
- // SPDX-License-Identifier: Apache-2.0.
1635
- /**
1636
- * Class describing the auditable item graph patches.
1637
- */
1638
- exports.AuditableItemGraphPatch = class AuditableItemGraphPatch {
1639
- /**
1640
- * The operation for the patch.
1641
- */
1642
- op;
1643
- /**
1644
- * The path for the patch.
1645
- */
1646
- path;
1647
- /**
1648
- * The from for the patch.
1649
- */
1650
- from;
1651
- /**
1652
- * The value for the patch.
1653
- */
1654
- value;
1655
- };
1656
- __decorate([
1657
- entity.property({ type: "string" }),
1658
- __metadata("design:type", String)
1659
- ], exports.AuditableItemGraphPatch.prototype, "op", void 0);
1660
- __decorate([
1661
- entity.property({ type: "string" }),
1662
- __metadata("design:type", String)
1663
- ], exports.AuditableItemGraphPatch.prototype, "path", void 0);
1664
- __decorate([
1665
- entity.property({ type: "string", optional: true }),
1666
- __metadata("design:type", String)
1667
- ], exports.AuditableItemGraphPatch.prototype, "from", void 0);
1668
- __decorate([
1669
- entity.property({ type: "object", optional: true }),
1670
- __metadata("design:type", Object)
1671
- ], exports.AuditableItemGraphPatch.prototype, "value", void 0);
1672
- exports.AuditableItemGraphPatch = __decorate([
1673
- entity.entity()
1674
- ], exports.AuditableItemGraphPatch);
1675
-
1676
- // Copyright 2024 IOTA Stiftung.
1677
- // SPDX-License-Identifier: Apache-2.0.
1678
- /**
1679
- * Class describing the auditable item graph vertex resource.
1680
- */
1681
- exports.AuditableItemGraphResource = class AuditableItemGraphResource {
1682
- /**
1683
- * The id of the resource.
1684
- */
1685
- id;
1686
- /**
1687
- * The date/time of when the resource was created.
1688
- */
1689
- dateCreated;
1690
- /**
1691
- * The date/time of when the resource was last modified.
1692
- */
1693
- dateModified;
1694
- /**
1695
- * The timestamp of when the resource was deleted, as we never actually remove items.
1696
- */
1697
- dateDeleted;
1698
- /**
1699
- * Object to associate with the resource as JSON-LD.
1700
- */
1701
- resourceObject;
1702
- };
1703
- __decorate([
1704
- entity.property({ type: "string", optional: true }),
1705
- __metadata("design:type", String)
1706
- ], exports.AuditableItemGraphResource.prototype, "id", void 0);
1707
- __decorate([
1708
- entity.property({ type: "string", format: "date-time" }),
1709
- __metadata("design:type", String)
1710
- ], exports.AuditableItemGraphResource.prototype, "dateCreated", void 0);
1711
- __decorate([
1712
- entity.property({ type: "string", format: "date-time", optional: true }),
1713
- __metadata("design:type", String)
1714
- ], exports.AuditableItemGraphResource.prototype, "dateModified", void 0);
1715
- __decorate([
1716
- entity.property({ type: "string", format: "date-time", optional: true }),
1717
- __metadata("design:type", String)
1718
- ], exports.AuditableItemGraphResource.prototype, "dateDeleted", void 0);
1719
- __decorate([
1720
- entity.property({ type: "object", itemTypeRef: dataJsonLd.JsonLdTypes.NodeObject, optional: true }),
1721
- __metadata("design:type", Object)
1722
- ], exports.AuditableItemGraphResource.prototype, "resourceObject", void 0);
1723
- exports.AuditableItemGraphResource = __decorate([
1724
- entity.entity()
1725
- ], exports.AuditableItemGraphResource);
1726
-
1727
- // Copyright 2024 IOTA Stiftung.
1728
- // SPDX-License-Identifier: Apache-2.0.
1729
- /**
1730
- * Class describing the auditable item graph vertex.
1731
- */
1732
- exports.AuditableItemGraphVertex = class AuditableItemGraphVertex {
1733
- /**
1734
- * The id of the vertex.
1735
- */
1736
- id;
1737
- /**
1738
- * The identity of the node which controls the vertex.
1739
- */
1740
- nodeIdentity;
1741
- /**
1742
- * The date/time of when the vertex was created.
1743
- */
1744
- dateCreated;
1745
- /**
1746
- * The date/time of when the vertex was last modified.
1747
- */
1748
- dateModified;
1749
- /**
1750
- * Combined alias index for the vertex used for querying.
1751
- */
1752
- aliasIndex;
1753
- /**
1754
- * Combined resource type index for the vertex used for querying.
1755
- */
1756
- resourceTypeIndex;
1757
- /**
1758
- * Object to associate with the vertex as JSON-LD.
1759
- */
1760
- annotationObject;
1761
- /**
1762
- * Alternative aliases that can be used to identify the vertex.
1763
- */
1764
- aliases;
1765
- /**
1766
- * The resources attached to the vertex.
1767
- */
1768
- resources;
1769
- /**
1770
- * Edges connected to the vertex.
1771
- */
1772
- edges;
1773
- };
1774
- __decorate([
1775
- entity.property({ type: "string", isPrimary: true }),
1776
- __metadata("design:type", String)
1777
- ], exports.AuditableItemGraphVertex.prototype, "id", void 0);
1778
- __decorate([
1779
- entity.property({ type: "string", optional: true }),
1780
- __metadata("design:type", String)
1781
- ], exports.AuditableItemGraphVertex.prototype, "nodeIdentity", void 0);
1782
- __decorate([
1783
- entity.property({ type: "string", format: "date-time", sortDirection: entity.SortDirection.Descending }),
1784
- __metadata("design:type", String)
1785
- ], exports.AuditableItemGraphVertex.prototype, "dateCreated", void 0);
1786
- __decorate([
1787
- entity.property({
1788
- type: "string",
1789
- format: "date-time",
1790
- sortDirection: entity.SortDirection.Descending,
1791
- optional: true
1792
- }),
1793
- __metadata("design:type", String)
1794
- ], exports.AuditableItemGraphVertex.prototype, "dateModified", void 0);
1795
- __decorate([
1796
- entity.property({ type: "string", isSecondary: true, optional: true }),
1797
- __metadata("design:type", String)
1798
- ], exports.AuditableItemGraphVertex.prototype, "aliasIndex", void 0);
1799
- __decorate([
1800
- entity.property({ type: "string", isSecondary: true, optional: true }),
1801
- __metadata("design:type", String)
1802
- ], exports.AuditableItemGraphVertex.prototype, "resourceTypeIndex", void 0);
1803
- __decorate([
1804
- entity.property({ type: "object", itemTypeRef: dataJsonLd.JsonLdTypes.NodeObject, optional: true }),
1805
- __metadata("design:type", Object)
1806
- ], exports.AuditableItemGraphVertex.prototype, "annotationObject", void 0);
1807
- __decorate([
1808
- entity.property({ type: "array", itemType: "string", optional: true }),
1809
- __metadata("design:type", Array)
1810
- ], exports.AuditableItemGraphVertex.prototype, "aliases", void 0);
1811
- __decorate([
1812
- entity.property({ type: "array", itemTypeRef: "AuditableItemGraphResource", optional: true }),
1813
- __metadata("design:type", Array)
1814
- ], exports.AuditableItemGraphVertex.prototype, "resources", void 0);
1815
- __decorate([
1816
- entity.property({ type: "array", itemTypeRef: "AuditableItemGraphEdge", optional: true }),
1817
- __metadata("design:type", Array)
1818
- ], exports.AuditableItemGraphVertex.prototype, "edges", void 0);
1819
- exports.AuditableItemGraphVertex = __decorate([
1820
- entity.entity()
1821
- ], exports.AuditableItemGraphVertex);
1822
-
1823
- const restEntryPoints = [
1824
- {
1825
- name: "auditable-item-graph",
1826
- defaultBaseRoute: "auditable-item-graph",
1827
- tags: tagsAuditableItemGraph,
1828
- generateRoutes: generateRestRoutesAuditableItemGraph
1829
- }
1830
- ];
1831
-
1832
- // Copyright 2024 IOTA Stiftung.
1833
- // SPDX-License-Identifier: Apache-2.0.
1834
- /**
1835
- * Initialize the schema for the auditable item graph entity storage connector.
1836
- */
1837
- function initSchema() {
1838
- entity.EntitySchemaFactory.register("AuditableItemGraphVertex", () => entity.EntitySchemaHelper.getSchema(exports.AuditableItemGraphVertex));
1839
- entity.EntitySchemaFactory.register("AuditableItemGraphAlias", () => entity.EntitySchemaHelper.getSchema(exports.AuditableItemGraphAlias));
1840
- entity.EntitySchemaFactory.register("AuditableItemGraphResource", () => entity.EntitySchemaHelper.getSchema(exports.AuditableItemGraphResource));
1841
- entity.EntitySchemaFactory.register("AuditableItemGraphEdge", () => entity.EntitySchemaHelper.getSchema(exports.AuditableItemGraphEdge));
1842
- entity.EntitySchemaFactory.register("AuditableItemGraphChangeset", () => entity.EntitySchemaHelper.getSchema(exports.AuditableItemGraphChangeset));
1843
- entity.EntitySchemaFactory.register("AuditableItemGraphPatch", () => entity.EntitySchemaHelper.getSchema(exports.AuditableItemGraphPatch));
1844
- }
1845
-
1846
- exports.AuditableItemGraphService = AuditableItemGraphService;
1847
- exports.auditableItemGraphCreate = auditableItemGraphCreate;
1848
- exports.auditableItemGraphGet = auditableItemGraphGet;
1849
- exports.auditableItemGraphList = auditableItemGraphList;
1850
- exports.auditableItemGraphUpdate = auditableItemGraphUpdate;
1851
- exports.generateRestRoutesAuditableItemGraph = generateRestRoutesAuditableItemGraph;
1852
- exports.initSchema = initSchema;
1853
- exports.restEntryPoints = restEntryPoints;
1854
- exports.tagsAuditableItemGraph = tagsAuditableItemGraph;