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