@twin.org/document-management-service 0.0.3-next.1 → 0.0.3-next.11

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.
@@ -1,13 +1,12 @@
1
- import { AttestationContexts } from "@twin.org/attestation-models";
2
1
  import { AuditableItemGraphContexts, AuditableItemGraphTypes } from "@twin.org/auditable-item-graph-models";
3
2
  import { BlobStorageContexts } from "@twin.org/blob-storage-models";
4
3
  import { ContextIdKeys, ContextIdStore } from "@twin.org/context";
5
4
  import { BaseError, Coerce, ComponentFactory, Converter, GeneralError, Guards, Is, NotFoundError, ObjectHelper, Urn } from "@twin.org/core";
6
- import { Sha256 } from "@twin.org/crypto";
5
+ import { IntegrityAlgorithm, IntegrityHelper, Sha256 } from "@twin.org/crypto";
7
6
  import { JsonLdProcessor } from "@twin.org/data-json-ld";
8
7
  import { DocumentContexts, DocumentTypes } from "@twin.org/document-management-models";
9
8
  import { SchemaOrgContexts, SchemaOrgDataTypes, SchemaOrgTypes } from "@twin.org/standards-schema-org";
10
- import { UneceDocumentCodes } from "@twin.org/standards-unece";
9
+ import { UneceDocumentCodeList } from "@twin.org/standards-unece";
11
10
  /**
12
11
  * Service for performing document management operations.
13
12
  */
@@ -72,7 +71,7 @@ export class DocumentManagementService {
72
71
  */
73
72
  async create(documentId, documentIdFormat, documentCode, blob, annotationObject, auditableItemGraphEdges, options) {
74
73
  Guards.stringValue(DocumentManagementService.CLASS_NAME, "documentId", documentId);
75
- Guards.arrayOneOf(DocumentManagementService.CLASS_NAME, "documentCode", documentCode, Object.values(UneceDocumentCodes));
74
+ Guards.arrayOneOf(DocumentManagementService.CLASS_NAME, "documentCode", documentCode, Object.values(UneceDocumentCodeList));
76
75
  Guards.uint8Array(DocumentManagementService.CLASS_NAME, "blob", blob);
77
76
  const contextIds = await ContextIdStore.getContextIds();
78
77
  try {
@@ -87,7 +86,7 @@ export class DocumentManagementService {
87
86
  if (options?.addAlias ?? true) {
88
87
  documentVertex.aliases ??= [];
89
88
  documentVertex.aliases.push({
90
- "@context": AuditableItemGraphContexts.ContextRoot,
89
+ "@context": AuditableItemGraphContexts.Context,
91
90
  type: AuditableItemGraphTypes.Alias,
92
91
  id: documentId,
93
92
  aliasFormat: documentIdFormat,
@@ -98,9 +97,9 @@ export class DocumentManagementService {
98
97
  const blobStorageId = await this._blobStorageComponent.create(Converter.bytesToBase64(blob));
99
98
  const currentRevision = {
100
99
  "@context": [
101
- DocumentContexts.ContextRoot,
102
- DocumentContexts.ContextRootCommon,
103
- SchemaOrgContexts.ContextRoot
100
+ SchemaOrgContexts.Context,
101
+ DocumentContexts.Context,
102
+ DocumentContexts.ContextCommon
104
103
  ],
105
104
  type: DocumentTypes.Document,
106
105
  id: this.createDocumentId(documentId, 0),
@@ -109,7 +108,7 @@ export class DocumentManagementService {
109
108
  documentCode,
110
109
  documentRevision: 0,
111
110
  annotationObject,
112
- blobHash: this.generateBlobHash(blob),
111
+ integrity: IntegrityHelper.generate(IntegrityAlgorithm.Sha256, blob),
113
112
  blobStorageId,
114
113
  dateCreated: new Date(Date.now()).toISOString(),
115
114
  organizationIdentity: contextIds?.[ContextIdKeys.Organization],
@@ -121,7 +120,7 @@ export class DocumentManagementService {
121
120
  // Add the new revision in to the vertex
122
121
  documentVertex.resources ??= [];
123
122
  documentVertex.resources.push({
124
- "@context": AuditableItemGraphContexts.ContextRoot,
123
+ "@context": AuditableItemGraphContexts.Context,
125
124
  type: AuditableItemGraphTypes.Resource,
126
125
  resourceObject: currentRevision
127
126
  });
@@ -158,7 +157,7 @@ export class DocumentManagementService {
158
157
  throw new NotFoundError(DocumentManagementService.CLASS_NAME, "documentRevisionNone");
159
158
  }
160
159
  const documents = await this.getDocumentsFromVertex(documentVertex);
161
- const latestRevision = documents.itemListElement[0];
160
+ const latestRevision = documents.entries.itemListElement[0];
162
161
  documentVertex.resources = documentVertex.resources.filter(r => Is.empty(r.dateDeleted));
163
162
  if (Is.empty(latestRevision)) {
164
163
  throw new NotFoundError(DocumentManagementService.CLASS_NAME, "documentRevisionNone");
@@ -172,8 +171,8 @@ export class DocumentManagementService {
172
171
  connectedVertices[edge.targetId] = await this._auditableItemGraphComponent.get(edge.targetId);
173
172
  }
174
173
  // Also get the current edges in case some need disconnecting
175
- if (Is.arrayValue(documents.edges)) {
176
- for (const edgeId of documents.edges) {
174
+ if (Is.arrayValue(documents.entries.edges)) {
175
+ for (const edgeId of documents.entries.edges) {
177
176
  // If we haven't retrieved the edge then it must be one that needs removing
178
177
  if (Is.empty(connectedVertices[edgeId])) {
179
178
  connectedVertices[edgeId] = await this._auditableItemGraphComponent.get(edgeId);
@@ -184,21 +183,21 @@ export class DocumentManagementService {
184
183
  let updatedVertex = false;
185
184
  // If the blob is set and its hash has changed then we create a new revision
186
185
  if (Is.uint8Array(blob)) {
187
- const newBlobHash = this.generateBlobHash(blob);
188
- if (latestRevision.blobHash !== newBlobHash) {
186
+ const newIntegrity = IntegrityHelper.generate(IntegrityAlgorithm.Sha256, blob);
187
+ if (latestRevision.integrity !== newIntegrity) {
189
188
  // Add the blob to blob storage
190
189
  const blobStorageId = await this._blobStorageComponent.create(Converter.bytesToBase64(blob));
191
190
  const newRevision = ObjectHelper.clone(latestRevision);
192
191
  newRevision.documentRevision++;
193
192
  newRevision.id = this.createDocumentId(newRevision.documentId, newRevision.documentRevision);
194
- newRevision.blobHash = newBlobHash;
193
+ newRevision.integrity = newIntegrity;
195
194
  newRevision.blobStorageId = blobStorageId;
196
195
  newRevision.annotationObject = annotationObject;
197
196
  if (Is.stringValue(latestRevision.attestationId)) {
198
197
  newRevision.attestationId = await this.createAttestation(newRevision);
199
198
  }
200
199
  documentVertex.resources.push({
201
- "@context": AuditableItemGraphContexts.ContextRoot,
200
+ "@context": AuditableItemGraphContexts.Context,
202
201
  type: AuditableItemGraphTypes.Resource,
203
202
  resourceObject: newRevision
204
203
  });
@@ -253,8 +252,11 @@ export class DocumentManagementService {
253
252
  const documentVertex = await this._auditableItemGraphComponent.get(auditableItemGraphDocumentId, { includeDeleted: options?.includeRemoved });
254
253
  // Populate the document and revisions with the options set
255
254
  const documents = await this.getDocumentsFromVertex(documentVertex, options, cursor, limit);
256
- const result = await JsonLdProcessor.compact(documents, documents["@context"]);
257
- return result;
255
+ const result = await JsonLdProcessor.compact(documents.entries, documents.entries["@context"]);
256
+ return {
257
+ entries: result,
258
+ cursor: documents.cursor
259
+ };
258
260
  }
259
261
  catch (error) {
260
262
  if (BaseError.someErrorName(error, "NotFoundError")) {
@@ -289,7 +291,7 @@ export class DocumentManagementService {
289
291
  }
290
292
  // Populate the document and revisions with the options set
291
293
  const docList = await this.getDocumentsFromVertex(documentVertex, options);
292
- const result = await JsonLdProcessor.compact(docList.itemListElement[0], docList.itemListElement[0]["@context"]);
294
+ const result = await JsonLdProcessor.compact(docList.entries.itemListElement[0], docList.entries.itemListElement[0]["@context"]);
293
295
  return result;
294
296
  }
295
297
  catch (error) {
@@ -373,7 +375,7 @@ export class DocumentManagementService {
373
375
  }
374
376
  else {
375
377
  const vertexEdge = {
376
- "@context": AuditableItemGraphContexts.ContextRoot,
378
+ "@context": AuditableItemGraphContexts.Context,
377
379
  type: AuditableItemGraphTypes.Edge,
378
380
  targetId: aigEdge.targetId,
379
381
  edgeRelationships: ["document"]
@@ -422,7 +424,7 @@ export class DocumentManagementService {
422
424
  const hasEdge = connected.edges?.some(e => e.targetId === auditableItemGraphDocumentId);
423
425
  if (!hasEdge) {
424
426
  const vertexEdge = {
425
- "@context": AuditableItemGraphContexts.ContextRoot,
427
+ "@context": AuditableItemGraphContexts.Context,
426
428
  type: AuditableItemGraphTypes.Edge,
427
429
  targetId: auditableItemGraphDocumentId,
428
430
  edgeRelationships: ["document"]
@@ -437,7 +439,7 @@ export class DocumentManagementService {
437
439
  if (Is.empty(alias)) {
438
440
  // No existing alias, so create one
439
441
  const vertexAlias = {
440
- "@context": AuditableItemGraphContexts.ContextRoot,
442
+ "@context": AuditableItemGraphContexts.Context,
441
443
  type: AuditableItemGraphTypes.Alias,
442
444
  id: documentId,
443
445
  aliasFormat: documentIdFormat,
@@ -490,15 +492,6 @@ export class DocumentManagementService {
490
492
  }
491
493
  }
492
494
  }
493
- /**
494
- * Generate a hash for the blob data.
495
- * @param blob The blob data to hash.
496
- * @returns The hash.
497
- * @internal
498
- */
499
- generateBlobHash(blob) {
500
- return `sha256:${Converter.bytesToBase64(Sha256.sum256(blob))}`;
501
- }
502
495
  /**
503
496
  * Get the documents from the auditable item graph vertex.
504
497
  * @param documentVertex The vertex containing the documents.
@@ -516,13 +509,14 @@ export class DocumentManagementService {
516
509
  async getDocumentsFromVertex(documentVertex, options, cursor, limit) {
517
510
  const docList = {
518
511
  "@context": [
519
- SchemaOrgContexts.ContextRoot,
520
- DocumentContexts.ContextRoot,
521
- DocumentContexts.ContextRootCommon
512
+ SchemaOrgContexts.Context,
513
+ DocumentContexts.Context,
514
+ DocumentContexts.ContextCommon
522
515
  ],
523
516
  type: SchemaOrgTypes.ItemList,
524
517
  [SchemaOrgTypes.ItemListElement]: []
525
518
  };
519
+ let nextCursor;
526
520
  if (Is.arrayValue(documentVertex.resources)) {
527
521
  // Sort by newest revision first
528
522
  documentVertex.resources.sort((a, b) => (Coerce.number(b.resourceObject?.documentRevision) ?? 0) -
@@ -530,8 +524,7 @@ export class DocumentManagementService {
530
524
  const startIndex = Coerce.integer(cursor) ?? 0;
531
525
  const endIndex = Math.min(startIndex + (limit ?? 1), documentVertex.resources.length);
532
526
  const slicedResources = documentVertex.resources.slice(startIndex, endIndex);
533
- docList[SchemaOrgTypes.NextItem] =
534
- documentVertex.resources.length > endIndex ? (endIndex + 1).toString() : undefined;
527
+ nextCursor = documentVertex.resources.length > endIndex ? endIndex.toString() : undefined;
535
528
  const includeBlobStorageMetadata = options?.includeBlobStorageMetadata ?? false;
536
529
  const includeBlobStorageData = options?.includeBlobStorageData ?? false;
537
530
  const includeAttestation = options?.includeAttestation ?? false;
@@ -548,8 +541,11 @@ export class DocumentManagementService {
548
541
  });
549
542
  if (blobRequired) {
550
543
  document.blobStorageEntry = blobEntry;
551
- if (!docList["@context"].includes(BlobStorageContexts.ContextRoot)) {
552
- docList["@context"].push(BlobStorageContexts.ContextRoot);
544
+ if (Is.object(document.blobStorageEntry)) {
545
+ ObjectHelper.propertyDelete(document.blobStorageEntry, "@context");
546
+ }
547
+ if (!docList["@context"].includes(BlobStorageContexts.Context)) {
548
+ docList["@context"].push(BlobStorageContexts.Context);
553
549
  }
554
550
  }
555
551
  if (Is.stringValue(options?.extractRuleGroupId) && Is.stringValue(blobEntry.blob)) {
@@ -568,8 +564,8 @@ export class DocumentManagementService {
568
564
  if (includeAttestation && Is.stringValue(document.attestationId)) {
569
565
  const attestationInformation = await this._attestationComponent.get(document.attestationId);
570
566
  document.attestationInformation = attestationInformation;
571
- if (!docList["@context"].includes(AttestationContexts.ContextRoot)) {
572
- docList["@context"].push(AttestationContexts.ContextRoot);
567
+ if (Is.object(document.attestationInformation)) {
568
+ ObjectHelper.propertyDelete(document.attestationInformation, "@context");
573
569
  }
574
570
  }
575
571
  }
@@ -583,7 +579,10 @@ export class DocumentManagementService {
583
579
  }
584
580
  }
585
581
  }
586
- return docList;
582
+ return {
583
+ entries: docList,
584
+ cursor: nextCursor
585
+ };
587
586
  }
588
587
  /**
589
588
  * Create an attestation for the document.
@@ -593,9 +592,9 @@ export class DocumentManagementService {
593
592
  async createAttestation(document) {
594
593
  const documentAttestation = {
595
594
  "@context": [
596
- DocumentContexts.ContextRoot,
597
- DocumentContexts.ContextRootCommon,
598
- SchemaOrgContexts.ContextRoot
595
+ SchemaOrgContexts.Context,
596
+ DocumentContexts.Context,
597
+ DocumentContexts.ContextCommon
599
598
  ],
600
599
  type: DocumentTypes.DocumentAttestation,
601
600
  id: document.id,
@@ -603,7 +602,7 @@ export class DocumentManagementService {
603
602
  documentCode: document.documentCode,
604
603
  documentRevision: document.documentRevision,
605
604
  dateCreated: document.dateCreated,
606
- blobHash: document.blobHash
605
+ integrity: document.integrity
607
606
  };
608
607
  return this._attestationComponent.create(documentAttestation);
609
608
  }
@@ -1 +1 @@
1
- {"version":3,"file":"documentManagementService.js","sourceRoot":"","sources":["../../src/documentManagementService.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EACN,0BAA0B,EAC1B,uBAAuB,EAMvB,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EACN,SAAS,EACT,MAAM,EACN,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,MAAM,EACN,EAAE,EACF,aAAa,EACb,YAAY,EACZ,GAAG,EACH,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,eAAe,EAA0B,MAAM,wBAAwB,CAAC;AAEjF,OAAO,EACN,gBAAgB,EAChB,aAAa,EAKb,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EACN,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAG/D;;GAEG;AACH,MAAM,OAAO,yBAAyB;IACrC;;OAEG;IACI,MAAM,CAAU,UAAU,+BAA+C;IAEhF;;;OAGG;IACc,4BAA4B,CAA+B;IAE5E;;;OAGG;IACc,qBAAqB,CAAwB;IAE9D;;;OAGG;IACc,qBAAqB,CAAwB;IAE9D;;;OAGG;IACc,wBAAwB,CAA2B;IAEpE;;;OAGG;IACH,YAAY,OAAsD;QACjE,IAAI,CAAC,4BAA4B,GAAG,gBAAgB,CAAC,GAAG,CACvD,OAAO,EAAE,+BAA+B,IAAI,sBAAsB,CAClE,CAAC;QACF,IAAI,CAAC,qBAAqB,GAAG,gBAAgB,CAAC,GAAG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,CAAC,mBAAmB;YACvC,EAAE,EAAE,QAAQ,CAAC,EAAE;YACf,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,YAAY,EAAE,QAAQ,CAAC,YAAY;YACnC,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;YAC3C,WAAW,EAAE,QAAQ,CAAC,WAAW;YACjC,QAAQ,EAAE,QAAQ,CAAC,QAAQ;SAC3B,CAAC;QACF,OAAO,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAC/D,CAAC;IAED;;;;;;OAMG;IACK,gBAAgB,CAAC,UAAkB,EAAE,QAAgB;QAC5D,MAAM,cAAc,GAAG,SAAS,CAAC,gBAAgB,CAChD,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAChD,CAAC;QACF,OAAO,YAAY,cAAc,IAAI,QAAQ,EAAE,CAAC;IACjD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IAttestationComponent } from \"@twin.org/attestation-models\";\nimport { AttestationContexts } from \"@twin.org/attestation-models\";\nimport {\n\tAuditableItemGraphContexts,\n\tAuditableItemGraphTypes,\n\ttype IAuditableItemGraphVertexList,\n\ttype IAuditableItemGraphAlias,\n\ttype IAuditableItemGraphComponent,\n\ttype IAuditableItemGraphEdge,\n\ttype IAuditableItemGraphVertex\n} from \"@twin.org/auditable-item-graph-models\";\nimport type { IBlobStorageComponent } from \"@twin.org/blob-storage-models\";\nimport { BlobStorageContexts } from \"@twin.org/blob-storage-models\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport {\n\tBaseError,\n\tCoerce,\n\tComponentFactory,\n\tConverter,\n\tGeneralError,\n\tGuards,\n\tIs,\n\tNotFoundError,\n\tObjectHelper,\n\tUrn\n} from \"@twin.org/core\";\nimport { Sha256 } from \"@twin.org/crypto\";\nimport { JsonLdProcessor, type IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport type { IDataProcessingComponent } from \"@twin.org/data-processing-models\";\nimport {\n\tDocumentContexts,\n\tDocumentTypes,\n\ttype IDocument,\n\ttype IDocumentAttestation,\n\ttype IDocumentList,\n\ttype IDocumentManagementComponent\n} from \"@twin.org/document-management-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tSchemaOrgContexts,\n\tSchemaOrgDataTypes,\n\tSchemaOrgTypes\n} from \"@twin.org/standards-schema-org\";\nimport { UneceDocumentCodes } from \"@twin.org/standards-unece\";\nimport type { IDocumentManagementServiceConstructorOptions } from \"./models/IDocumentManagementStorageServiceConstructorOptions.js\";\n\n/**\n * Service for performing document management operations.\n */\nexport class DocumentManagementService implements IDocumentManagementComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<DocumentManagementService>();\n\n\t/**\n\t * The component for the auditable item graph.\n\t * @internal\n\t */\n\tprivate readonly _auditableItemGraphComponent: IAuditableItemGraphComponent;\n\n\t/**\n\t * The connector for the blob component.\n\t * @internal\n\t */\n\tprivate readonly _blobStorageComponent: IBlobStorageComponent;\n\n\t/**\n\t * The connector for the attestation.\n\t * @internal\n\t */\n\tprivate readonly _attestationComponent: IAttestationComponent;\n\n\t/**\n\t * The connector for the data processing.\n\t * @internal\n\t */\n\tprivate readonly _dataProcessingComponent: IDataProcessingComponent;\n\n\t/**\n\t * Create a new instance of DocumentManagementService.\n\t * @param options The options for the service.\n\t */\n\tconstructor(options?: IDocumentManagementServiceConstructorOptions) {\n\t\tthis._auditableItemGraphComponent = ComponentFactory.get<IAuditableItemGraphComponent>(\n\t\t\toptions?.auditableItemGraphComponentType ?? \"auditable-item-graph\"\n\t\t);\n\t\tthis._blobStorageComponent = ComponentFactory.get<IBlobStorageComponent>(\n\t\t\toptions?.blobStorageComponentType ?? \"blob-storage\"\n\t\t);\n\t\tthis._attestationComponent = ComponentFactory.get<IAttestationComponent>(\n\t\t\toptions?.attestationComponentType ?? \"attestation\"\n\t\t);\n\t\tthis._dataProcessingComponent = ComponentFactory.get<IDataProcessingComponent>(\n\t\t\toptions?.dataProcessingComponentType ?? \"data-processing\"\n\t\t);\n\n\t\tSchemaOrgDataTypes.registerRedirects();\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn DocumentManagementService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Store a document as an auditable item graph vertex and add its content to blob storage.\n\t * If the document id already exists and the blob data is different a new revision will be created.\n\t * For any other changes the current revision will be updated.\n\t * @param documentId The document id to create.\n\t * @param documentIdFormat The format of the document identifier.\n\t * @param documentCode The code for the document type.\n\t * @param blob The data to create the document with.\n\t * @param annotationObject Additional information to associate with the document.\n\t * @param auditableItemGraphEdges The auditable item graph vertices to connect the document to.\n\t * @param options Additional options for the set operation.\n\t * @param options.createAttestation Flag to create an attestation for the document, defaults to false.\n\t * @param options.addAlias Flag to add the document id as an alias to the aig vertex, defaults to true.\n\t * @param options.aliasAnnotationObject Annotation object for the alias.\n\t * @returns The auditable item graph vertex created for the document including its revision.\n\t */\n\tpublic async create(\n\t\tdocumentId: string,\n\t\tdocumentIdFormat: string | undefined,\n\t\tdocumentCode: UneceDocumentCodes,\n\t\tblob: Uint8Array,\n\t\tannotationObject?: IJsonLdNodeObject,\n\t\tauditableItemGraphEdges?: {\n\t\t\ttargetId: string;\n\t\t\taddAlias?: boolean;\n\t\t\taliasAnnotationObject?: IJsonLdNodeObject;\n\t\t}[],\n\t\toptions?: {\n\t\t\tcreateAttestation?: boolean;\n\t\t\taddAlias?: boolean;\n\t\t\taliasAnnotationObject?: IJsonLdNodeObject;\n\t\t}\n\t): Promise<string> {\n\t\tGuards.stringValue(DocumentManagementService.CLASS_NAME, nameof(documentId), documentId);\n\t\tGuards.arrayOneOf(\n\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\tnameof(documentCode),\n\t\t\tdocumentCode,\n\t\t\tObject.values(UneceDocumentCodes)\n\t\t);\n\t\tGuards.uint8Array(DocumentManagementService.CLASS_NAME, nameof(blob), blob);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\n\t\ttry {\n\t\t\t// Get the connected vertices first, if one fails we abort the create\n\t\t\tconst connectedVertices: { [id: string]: IAuditableItemGraphVertex } = {};\n\t\t\tif (Is.arrayValue(auditableItemGraphEdges)) {\n\t\t\t\tfor (const edge of auditableItemGraphEdges) {\n\t\t\t\t\tconnectedVertices[edge.targetId] = await this._auditableItemGraphComponent.get(\n\t\t\t\t\t\tedge.targetId\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst documentVertex: Omit<IAuditableItemGraphVertex, \"@context\" | \"id\" | \"type\"> = {};\n\n\t\t\tif (options?.addAlias ?? true) {\n\t\t\t\tdocumentVertex.aliases ??= [];\n\t\t\t\tdocumentVertex.aliases.push({\n\t\t\t\t\t\"@context\": AuditableItemGraphContexts.ContextRoot,\n\t\t\t\t\ttype: AuditableItemGraphTypes.Alias,\n\t\t\t\t\tid: documentId,\n\t\t\t\t\taliasFormat: documentIdFormat,\n\t\t\t\t\tannotationObject: options?.aliasAnnotationObject\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Add the blob to blob storage\n\t\t\tconst blobStorageId = await this._blobStorageComponent.create(Converter.bytesToBase64(blob));\n\n\t\t\tconst currentRevision: IDocument & IJsonLdNodeObject = {\n\t\t\t\t\"@context\": [\n\t\t\t\t\tDocumentContexts.ContextRoot,\n\t\t\t\t\tDocumentContexts.ContextRootCommon,\n\t\t\t\t\tSchemaOrgContexts.ContextRoot\n\t\t\t\t],\n\t\t\t\ttype: DocumentTypes.Document,\n\t\t\t\tid: this.createDocumentId(documentId, 0),\n\t\t\t\tdocumentId,\n\t\t\t\tdocumentIdFormat,\n\t\t\t\tdocumentCode,\n\t\t\t\tdocumentRevision: 0,\n\t\t\t\tannotationObject,\n\t\t\t\tblobHash: this.generateBlobHash(blob),\n\t\t\t\tblobStorageId,\n\t\t\t\tdateCreated: new Date(Date.now()).toISOString(),\n\t\t\t\torganizationIdentity: contextIds?.[ContextIdKeys.Organization],\n\t\t\t\tuserIdentity: contextIds?.[ContextIdKeys.User]\n\t\t\t};\n\n\t\t\tif (options?.createAttestation ?? false) {\n\t\t\t\tcurrentRevision.attestationId = await this.createAttestation(currentRevision);\n\t\t\t}\n\n\t\t\t// Add the new revision in to the vertex\n\t\t\tdocumentVertex.resources ??= [];\n\t\t\tdocumentVertex.resources.push({\n\t\t\t\t\"@context\": AuditableItemGraphContexts.ContextRoot,\n\t\t\t\ttype: AuditableItemGraphTypes.Resource,\n\t\t\t\tresourceObject: currentRevision\n\t\t\t});\n\n\t\t\t// Add the edges from the document to the items\n\t\t\tthis.updateEdges(documentVertex, auditableItemGraphEdges);\n\n\t\t\t// And create the vertex\n\t\t\tconst vertexId = await this._auditableItemGraphComponent.create(documentVertex);\n\n\t\t\t// Now add the edges to the connected vertices\n\t\t\tawait this.updateConnectedEdges(\n\t\t\t\tconnectedVertices,\n\t\t\t\tvertexId,\n\t\t\t\t[],\n\t\t\t\tauditableItemGraphEdges,\n\t\t\t\tdocumentId,\n\t\t\t\tdocumentIdFormat\n\t\t\t);\n\n\t\t\treturn vertexId;\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorName(error, nameof<NotFoundError>())) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\t\t\"createFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Update a document as an auditable item graph vertex and add its content to blob storage.\n\t * If the blob data is different a new revision will be created.\n\t * For any other changes the current revision will be updated.\n\t * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.\n\t * @param blob The data to update the document with.\n\t * @param annotationObject Additional information to associate with the document.\n\t * @param auditableItemGraphEdges The auditable item graph vertices to connect the document to, if undefined retains current connections.\n\t * @returns Nothing.\n\t */\n\tpublic async update(\n\t\tauditableItemGraphDocumentId: string,\n\t\tblob?: Uint8Array,\n\t\tannotationObject?: IJsonLdNodeObject,\n\t\tauditableItemGraphEdges?: {\n\t\t\ttargetId: string;\n\t\t\taddAlias?: boolean;\n\t\t\taliasAnnotationObject?: IJsonLdNodeObject;\n\t\t}[]\n\t): Promise<void> {\n\t\tUrn.guard(\n\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\n\t\ttry {\n\t\t\tconst documentVertex = await this._auditableItemGraphComponent.get(\n\t\t\t\tauditableItemGraphDocumentId,\n\t\t\t\t{ includeDeleted: true }\n\t\t\t);\n\n\t\t\tif (Is.empty(documentVertex.resources)) {\n\t\t\t\tthrow new NotFoundError(DocumentManagementService.CLASS_NAME, \"documentRevisionNone\");\n\t\t\t}\n\n\t\t\tconst documents = await this.getDocumentsFromVertex(documentVertex);\n\t\t\tconst latestRevision: IDocument | undefined = documents.itemListElement[0];\n\n\t\t\tdocumentVertex.resources = documentVertex.resources.filter(r => Is.empty(r.dateDeleted));\n\n\t\t\tif (Is.empty(latestRevision)) {\n\t\t\t\tthrow new NotFoundError(DocumentManagementService.CLASS_NAME, \"documentRevisionNone\");\n\t\t\t}\n\n\t\t\t// If auditableItemGraphEdges is undefined we are not updating the edges\n\t\t\t// an empty array can be passed to remove all edges\n\t\t\tconst connectedVertices: { [targetId: string]: IAuditableItemGraphVertex } = {};\n\t\t\tif (Is.array(auditableItemGraphEdges)) {\n\t\t\t\t// Get the updated connected vertices first, if one fails we abort the update\n\t\t\t\tfor (const edge of auditableItemGraphEdges) {\n\t\t\t\t\tconnectedVertices[edge.targetId] = await this._auditableItemGraphComponent.get(\n\t\t\t\t\t\tedge.targetId\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// Also get the current edges in case some need disconnecting\n\t\t\t\tif (Is.arrayValue(documents.edges)) {\n\t\t\t\t\tfor (const edgeId of documents.edges) {\n\t\t\t\t\t\t// If we haven't retrieved the edge then it must be one that needs removing\n\t\t\t\t\t\tif (Is.empty(connectedVertices[edgeId])) {\n\t\t\t\t\t\t\tconnectedVertices[edgeId] = await this._auditableItemGraphComponent.get(edgeId);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet updatedVertex = false;\n\n\t\t\t// If the blob is set and its hash has changed then we create a new revision\n\t\t\tif (Is.uint8Array(blob)) {\n\t\t\t\tconst newBlobHash = this.generateBlobHash(blob);\n\n\t\t\t\tif (latestRevision.blobHash !== newBlobHash) {\n\t\t\t\t\t// Add the blob to blob storage\n\t\t\t\t\tconst blobStorageId = await this._blobStorageComponent.create(\n\t\t\t\t\t\tConverter.bytesToBase64(blob)\n\t\t\t\t\t);\n\n\t\t\t\t\tconst newRevision = ObjectHelper.clone(latestRevision);\n\n\t\t\t\t\tnewRevision.documentRevision++;\n\t\t\t\t\tnewRevision.id = this.createDocumentId(\n\t\t\t\t\t\tnewRevision.documentId,\n\t\t\t\t\t\tnewRevision.documentRevision\n\t\t\t\t\t);\n\t\t\t\t\tnewRevision.blobHash = newBlobHash;\n\t\t\t\t\tnewRevision.blobStorageId = blobStorageId;\n\t\t\t\t\tnewRevision.annotationObject = annotationObject;\n\n\t\t\t\t\tif (Is.stringValue(latestRevision.attestationId)) {\n\t\t\t\t\t\tnewRevision.attestationId = await this.createAttestation(newRevision);\n\t\t\t\t\t}\n\n\t\t\t\t\tdocumentVertex.resources.push({\n\t\t\t\t\t\t\"@context\": AuditableItemGraphContexts.ContextRoot,\n\t\t\t\t\t\ttype: AuditableItemGraphTypes.Resource,\n\t\t\t\t\t\tresourceObject: newRevision as unknown as IJsonLdNodeObject\n\t\t\t\t\t});\n\n\t\t\t\t\tupdatedVertex = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If the blob wasn't updated but the annotation object has then update the current revision\n\t\t\t// instead of creating a new one\n\t\t\tif (\n\t\t\t\t!updatedVertex &&\n\t\t\t\t!ObjectHelper.equal(latestRevision.annotationObject, annotationObject)\n\t\t\t) {\n\t\t\t\tupdatedVertex = true;\n\t\t\t\tlatestRevision.annotationObject = annotationObject;\n\t\t\t\tlatestRevision.dateModified = new Date(Date.now()).toISOString();\n\t\t\t}\n\n\t\t\tconst existingEdgeIds = documentVertex.edges?.map(e => e.targetId) ?? [];\n\n\t\t\t// Update the edges from the document to the items\n\t\t\tconst edgesUpdated = this.updateEdges(documentVertex, auditableItemGraphEdges);\n\t\t\tif (edgesUpdated) {\n\t\t\t\tupdatedVertex = true;\n\t\t\t}\n\n\t\t\tif (updatedVertex) {\n\t\t\t\tawait this._auditableItemGraphComponent.update(documentVertex);\n\t\t\t}\n\n\t\t\tif (edgesUpdated) {\n\t\t\t\tawait this.updateConnectedEdges(\n\t\t\t\t\tconnectedVertices,\n\t\t\t\t\tauditableItemGraphDocumentId,\n\t\t\t\t\texistingEdgeIds,\n\t\t\t\t\tauditableItemGraphEdges,\n\t\t\t\t\tlatestRevision.documentId,\n\t\t\t\t\tlatestRevision.documentIdFormat\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorName(error, nameof<NotFoundError>())) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\t\t\"updateFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Get a document using it's auditable item graph vertex id and optional revision.\n\t * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.\n\t * @param options Additional options for the get operation.\n\t * @param options.includeBlobStorageMetadata Flag to include the blob storage metadata for the document, defaults to false.\n\t * @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.\n\t * @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.\n\t * @param options.includeRemoved Flag to include deleted documents, defaults to false.\n\t * @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.\n\t * @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.\n\t * @param cursor The cursor to get the next chunk of revisions.\n\t * @param limit Limit the number of items to return, defaults to 1 so only most recent is returned.\n\t * @returns The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.\n\t */\n\tpublic async get(\n\t\tauditableItemGraphDocumentId: string,\n\t\toptions?: {\n\t\t\tincludeBlobStorageMetadata?: boolean;\n\t\t\tincludeBlobStorageData?: boolean;\n\t\t\tincludeAttestation?: boolean;\n\t\t\tincludeRemoved?: boolean;\n\t\t\textractRuleGroupId?: string;\n\t\t\textractMimeType?: string;\n\t\t},\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<IDocumentList> {\n\t\tUrn.guard(\n\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\n\t\ttry {\n\t\t\tconst documentVertex = await this._auditableItemGraphComponent.get(\n\t\t\t\tauditableItemGraphDocumentId,\n\t\t\t\t{ includeDeleted: options?.includeRemoved }\n\t\t\t);\n\n\t\t\t// Populate the document and revisions with the options set\n\t\t\tconst documents = await this.getDocumentsFromVertex(documentVertex, options, cursor, limit);\n\n\t\t\tconst result = await JsonLdProcessor.compact(documents, documents[\"@context\"]);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorName(error, nameof<NotFoundError>())) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(DocumentManagementService.CLASS_NAME, \"getFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Get a document revision using it's auditable item graph vertex id.\n\t * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.\n\t * @param revision The revision id for the document.\n\t * @param options Additional options for the get operation.\n\t * @param options.includeBlobStorageMetadata Flag to include the blob storage metadata for the document, defaults to false.\n\t * @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.\n\t * @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.\n\t * @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.\n\t * @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.\n\t * @returns The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.\n\t */\n\tpublic async getRevision(\n\t\tauditableItemGraphDocumentId: string,\n\t\trevision: number,\n\t\toptions?: {\n\t\t\tincludeBlobStorageMetadata?: boolean;\n\t\t\tincludeBlobStorageData?: boolean;\n\t\t\tincludeAttestation?: boolean;\n\t\t\textractRuleGroupId?: string;\n\t\t\textractMimeType?: string;\n\t\t}\n\t): Promise<IDocument> {\n\t\tUrn.guard(\n\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\t\tGuards.integer(DocumentManagementService.CLASS_NAME, nameof(revision), revision);\n\n\t\ttry {\n\t\t\tconst documentVertex = await this._auditableItemGraphComponent.get(\n\t\t\t\tauditableItemGraphDocumentId,\n\t\t\t\t{ includeDeleted: true }\n\t\t\t);\n\n\t\t\tif (Is.empty(documentVertex.resources)) {\n\t\t\t\tthrow new NotFoundError(DocumentManagementService.CLASS_NAME, \"documentRevisionNone\");\n\t\t\t}\n\n\t\t\tdocumentVertex.resources = documentVertex.resources.filter(\n\t\t\t\td => d.resourceObject?.documentRevision === revision\n\t\t\t);\n\n\t\t\tif (documentVertex.resources.length === 0) {\n\t\t\t\tthrow new NotFoundError(\n\t\t\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\t\t\t\"documentRevisionNotFound\",\n\t\t\t\t\trevision.toString()\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Populate the document and revisions with the options set\n\t\t\tconst docList = await this.getDocumentsFromVertex(documentVertex, options);\n\n\t\t\tconst result = await JsonLdProcessor.compact(\n\t\t\t\tdocList.itemListElement[0],\n\t\t\t\tdocList.itemListElement[0][\"@context\"]\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorName(error, nameof<NotFoundError>())) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\t\t\"getRevisionFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Remove an auditable item graph vertex using it's id.\n\t * The document dateDeleted will be set, but can still be queried with the includeRemoved flag.\n\t * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.\n\t * @param revision The revision of the document to remove.\n\t * @returns Nothing.\n\t */\n\tpublic async removeRevision(\n\t\tauditableItemGraphDocumentId: string,\n\t\trevision: number\n\t): Promise<void> {\n\t\tUrn.guard(\n\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\t\tGuards.number(DocumentManagementService.CLASS_NAME, nameof(revision), revision);\n\n\t\ttry {\n\t\t\tconst documentVertex = await this._auditableItemGraphComponent.get(\n\t\t\t\tauditableItemGraphDocumentId\n\t\t\t);\n\n\t\t\tif (Is.empty(documentVertex.resources)) {\n\t\t\t\tthrow new NotFoundError(DocumentManagementService.CLASS_NAME, \"documentRevisionNone\");\n\t\t\t}\n\n\t\t\tconst docRevisionIndex = documentVertex.resources.findIndex(\n\t\t\t\td => d.resourceObject?.documentRevision === revision\n\t\t\t);\n\n\t\t\tif (docRevisionIndex === -1) {\n\t\t\t\tthrow new NotFoundError(\n\t\t\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\t\t\t\"documentRevisionNotFound\",\n\t\t\t\t\trevision.toString()\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tdocumentVertex.resources.splice(docRevisionIndex, 1);\n\n\t\t\tawait this._auditableItemGraphComponent.update(documentVertex);\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorName(error, nameof<NotFoundError>())) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\t\t\"removeRevisionFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Find all the document with a specific id.\n\t * @param documentId The document id to find in the graph.\n\t * @param cursor The cursor to get the next chunk of documents.\n\t * @param limit The limit to get the next chunk of documents.\n\t * @returns The graph vertices that contain documents referencing the specified document id.\n\t */\n\tpublic async query(\n\t\tdocumentId: string,\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<IAuditableItemGraphVertexList> {\n\t\tGuards.stringValue(DocumentManagementService.CLASS_NAME, nameof(documentId), documentId);\n\n\t\ttry {\n\t\t\tconst result = await this._auditableItemGraphComponent.query(\n\t\t\t\t{\n\t\t\t\t\tid: documentId,\n\t\t\t\t\tidMode: \"both\",\n\t\t\t\t\tresourceTypes: [DocumentTypes.Document]\n\t\t\t\t},\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[\"id\", \"dateCreated\", \"dateModified\", \"aliases\", \"annotationObject\", \"resources\", \"edges\"],\n\t\t\t\tcursor,\n\t\t\t\tlimit\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorName(error, nameof<NotFoundError>())) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(DocumentManagementService.CLASS_NAME, \"queryFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Update the edges of the document vertex.\n\t * @param documentVertex The document vertex to update.\n\t * @param auditableItemGraphEdges The list of edges to use.\n\t * @returns True if the edges were updated.\n\t * @internal\n\t */\n\tprivate updateEdges(\n\t\tdocumentVertex: Omit<IAuditableItemGraphVertex, \"@context\" | \"id\" | \"type\">,\n\t\tauditableItemGraphEdges:\n\t\t\t| { targetId: string; addAlias?: boolean; aliasAnnotationObject?: IJsonLdNodeObject }[]\n\t\t\t| undefined\n\t): boolean {\n\t\tlet changed = false;\n\n\t\tconst existingEdgeIds = documentVertex.edges?.map(e => e.targetId) ?? [];\n\n\t\tif (Is.array(auditableItemGraphEdges)) {\n\t\t\tfor (const aigEdge of auditableItemGraphEdges) {\n\t\t\t\tconst existingIndex = existingEdgeIds.indexOf(aigEdge.targetId);\n\t\t\t\tif (existingIndex !== -1) {\n\t\t\t\t\t// If the edge already exists then we don't need to add it again\n\t\t\t\t\t// We just need to remove it from the list of existing ids\n\t\t\t\t\t// any remaining after this loop will be need to be removed\n\t\t\t\t\texistingEdgeIds.splice(existingIndex, 1);\n\t\t\t\t} else {\n\t\t\t\t\tconst vertexEdge: IAuditableItemGraphEdge = {\n\t\t\t\t\t\t\"@context\": AuditableItemGraphContexts.ContextRoot,\n\t\t\t\t\t\ttype: AuditableItemGraphTypes.Edge,\n\t\t\t\t\t\ttargetId: aigEdge.targetId,\n\t\t\t\t\t\tedgeRelationships: [\"document\"]\n\t\t\t\t\t};\n\n\t\t\t\t\tdocumentVertex.edges ??= [];\n\t\t\t\t\tdocumentVertex.edges?.push(vertexEdge);\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Anything left in the existingEdgeIds array means they need to be removed\n\t\t\tif (existingEdgeIds.length > 0 && Is.array(documentVertex.edges)) {\n\t\t\t\tfor (const existingEdgeId of existingEdgeIds) {\n\t\t\t\t\tconst existingIndex = documentVertex.edges.findIndex(e => e.targetId === existingEdgeId);\n\t\t\t\t\tif (existingIndex !== -1) {\n\t\t\t\t\t\tdocumentVertex.edges.splice(existingIndex, 1);\n\t\t\t\t\t\tchanged = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn changed;\n\t}\n\n\t/**\n\t * Update the edges.\n\t * @param connectedVertices The connected vertices for the edges.\n\t * @param auditableItemGraphDocumentId The document id to use.\n\t * @param documentVertex The document vertex to update.\n\t * @param auditableItemGraphEdges The list of edges to use.\n\t * @param documentId The document identifier.\n\t * @param documentIdFormat The format of the document identifier.\n\t * @internal\n\t */\n\tprivate async updateConnectedEdges(\n\t\tconnectedVertices: { [id: string]: IAuditableItemGraphVertex },\n\t\tauditableItemGraphDocumentId: string,\n\t\texistingEdgeIds: string[],\n\t\tauditableItemGraphEdges:\n\t\t\t| { targetId: string; addAlias?: boolean; aliasAnnotationObject?: IJsonLdNodeObject }[]\n\t\t\t| undefined,\n\t\tdocumentId: string,\n\t\tdocumentIdFormat: string | undefined\n\t): Promise<void> {\n\t\tif (Is.array(auditableItemGraphEdges)) {\n\t\t\tfor (const aigEdge of auditableItemGraphEdges) {\n\t\t\t\tconst connected = connectedVertices[aigEdge.targetId];\n\n\t\t\t\tif (!Is.empty(connected)) {\n\t\t\t\t\tlet updatedConnected = false;\n\n\t\t\t\t\tconst existingIndex = existingEdgeIds.indexOf(aigEdge.targetId);\n\t\t\t\t\tif (existingIndex !== -1) {\n\t\t\t\t\t\t// If the edge already exists we remove it from the list of existing ids\n\t\t\t\t\t\t// any remaining after this loop will be need to be disconnected\n\t\t\t\t\t\texistingEdgeIds.splice(existingIndex, 1);\n\t\t\t\t\t}\n\n\t\t\t\t\t// Add the edge with the document vertex id if it doesn't already exist\n\t\t\t\t\tconst hasEdge = connected.edges?.some(e => e.targetId === auditableItemGraphDocumentId);\n\t\t\t\t\tif (!hasEdge) {\n\t\t\t\t\t\tconst vertexEdge: IAuditableItemGraphEdge = {\n\t\t\t\t\t\t\t\"@context\": AuditableItemGraphContexts.ContextRoot,\n\t\t\t\t\t\t\ttype: AuditableItemGraphTypes.Edge,\n\t\t\t\t\t\t\ttargetId: auditableItemGraphDocumentId,\n\t\t\t\t\t\t\tedgeRelationships: [\"document\"]\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tconnected.edges ??= [];\n\t\t\t\t\t\tconnected.edges?.push(vertexEdge);\n\t\t\t\t\t\tupdatedConnected = true;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Add alias with the document id if option flag is set and it doesn't already exist\n\t\t\t\t\tif (aigEdge.addAlias) {\n\t\t\t\t\t\tconst alias = connected.aliases?.find(a => a.id === documentId);\n\t\t\t\t\t\tif (Is.empty(alias)) {\n\t\t\t\t\t\t\t// No existing alias, so create one\n\t\t\t\t\t\t\tconst vertexAlias: IAuditableItemGraphAlias = {\n\t\t\t\t\t\t\t\t\"@context\": AuditableItemGraphContexts.ContextRoot,\n\t\t\t\t\t\t\t\ttype: AuditableItemGraphTypes.Alias,\n\t\t\t\t\t\t\t\tid: documentId,\n\t\t\t\t\t\t\t\taliasFormat: documentIdFormat,\n\t\t\t\t\t\t\t\tannotationObject: aigEdge.aliasAnnotationObject\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\tconnected.aliases ??= [];\n\t\t\t\t\t\t\tconnected.aliases?.push(vertexAlias);\n\t\t\t\t\t\t\tupdatedConnected = true;\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\t!ObjectHelper.equal(alias.annotationObject, aigEdge.aliasAnnotationObject) ||\n\t\t\t\t\t\t\tdocumentIdFormat !== alias.aliasFormat\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// The alias already exists, but the format or annotation object has changed\n\t\t\t\t\t\t\talias.annotationObject = aigEdge.aliasAnnotationObject;\n\t\t\t\t\t\t\talias.aliasFormat = documentIdFormat;\n\t\t\t\t\t\t\tupdatedConnected = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (updatedConnected) {\n\t\t\t\t\t\tawait this._auditableItemGraphComponent.update(connected);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Anything left in the existingEdgeIds array means they need to be removed\n\t\tif (existingEdgeIds.length > 0) {\n\t\t\tfor (const existingEdgeId of existingEdgeIds) {\n\t\t\t\tconst connected = connectedVertices[existingEdgeId];\n\n\t\t\t\tif (!Is.empty(connected)) {\n\t\t\t\t\tlet updatedConnected = false;\n\n\t\t\t\t\t// Remove the edge from the connected vertex\n\t\t\t\t\tif (Is.arrayValue(connected.edges)) {\n\t\t\t\t\t\tconst existingIndex = connected.edges.findIndex(\n\t\t\t\t\t\t\te => e.targetId === auditableItemGraphDocumentId\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (existingIndex !== -1) {\n\t\t\t\t\t\t\tconnected.edges.splice(existingIndex, 1);\n\t\t\t\t\t\t\tupdatedConnected = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Remove the alias from the connected vertex\n\t\t\t\t\tif (Is.arrayValue(connected.aliases)) {\n\t\t\t\t\t\tconst existingIndex = connected.aliases.findIndex(e => e.id === documentId);\n\t\t\t\t\t\tif (existingIndex !== -1) {\n\t\t\t\t\t\t\tconnected.aliases.splice(existingIndex, 1);\n\t\t\t\t\t\t\tupdatedConnected = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (updatedConnected) {\n\t\t\t\t\t\tawait this._auditableItemGraphComponent.update(connected);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Generate a hash for the blob data.\n\t * @param blob The blob data to hash.\n\t * @returns The hash.\n\t * @internal\n\t */\n\tprivate generateBlobHash(blob: Uint8Array): string {\n\t\treturn `sha256:${Converter.bytesToBase64(Sha256.sum256(blob))}`;\n\t}\n\n\t/**\n\t * Get the documents from the auditable item graph vertex.\n\t * @param documentVertex The vertex containing the documents.\n\t * @param options Additional options for the get operation.\n\t * @param options.includeBlobStorageMetadata Flag to include the blob storage metadata for the document, defaults to false.\n\t * @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.\n\t * @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.\n\t * @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.\n\t * @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.\n\t * @param cursor The cursor to get the next chunk of revisions.\n\t * @param limit Limit the number of items to return, defaults to 1 so only most recent is returned.\n\t * @returns The finalised list of documents.\n\t * @internal\n\t */\n\tprivate async getDocumentsFromVertex(\n\t\tdocumentVertex: IAuditableItemGraphVertex,\n\t\toptions?: {\n\t\t\tincludeBlobStorageMetadata?: boolean;\n\t\t\tincludeBlobStorageData?: boolean;\n\t\t\tincludeAttestation?: boolean;\n\t\t\textractRuleGroupId?: string;\n\t\t\textractMimeType?: string;\n\t\t},\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<IDocumentList> {\n\t\tconst docList: IDocumentList = {\n\t\t\t\"@context\": [\n\t\t\t\tSchemaOrgContexts.ContextRoot,\n\t\t\t\tDocumentContexts.ContextRoot,\n\t\t\t\tDocumentContexts.ContextRootCommon\n\t\t\t],\n\t\t\ttype: SchemaOrgTypes.ItemList,\n\t\t\t[SchemaOrgTypes.ItemListElement]: []\n\t\t};\n\n\t\tif (Is.arrayValue(documentVertex.resources)) {\n\t\t\t// Sort by newest revision first\n\t\t\tdocumentVertex.resources.sort(\n\t\t\t\t(a, b) =>\n\t\t\t\t\t(Coerce.number(b.resourceObject?.documentRevision) ?? 0) -\n\t\t\t\t\t(Coerce.number(a.resourceObject?.documentRevision) ?? 0)\n\t\t\t);\n\n\t\t\tconst startIndex = Coerce.integer(cursor) ?? 0;\n\t\t\tconst endIndex = Math.min(startIndex + (limit ?? 1), documentVertex.resources.length);\n\t\t\tconst slicedResources = documentVertex.resources.slice(startIndex, endIndex);\n\t\t\tdocList[SchemaOrgTypes.NextItem] =\n\t\t\t\tdocumentVertex.resources.length > endIndex ? (endIndex + 1).toString() : undefined;\n\n\t\t\tconst includeBlobStorageMetadata = options?.includeBlobStorageMetadata ?? false;\n\t\t\tconst includeBlobStorageData = options?.includeBlobStorageData ?? false;\n\t\t\tconst includeAttestation = options?.includeAttestation ?? false;\n\t\t\tconst extractData = Is.stringValue(options?.extractRuleGroupId);\n\n\t\t\tfor (let i = 0; i < slicedResources.length; i++) {\n\t\t\t\tconst document = slicedResources[i].resourceObject as unknown as IDocument;\n\t\t\t\tif (Is.object(document)) {\n\t\t\t\t\tdocument.dateDeleted = slicedResources[i].dateDeleted;\n\n\t\t\t\t\tdocList[SchemaOrgTypes.ItemListElement].push(document);\n\n\t\t\t\t\tconst blobRequired = includeBlobStorageMetadata || includeBlobStorageData;\n\t\t\t\t\tif (blobRequired || extractData) {\n\t\t\t\t\t\tconst blobEntry = await this._blobStorageComponent.get(document.blobStorageId, {\n\t\t\t\t\t\t\tincludeContent: includeBlobStorageData || extractData\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (blobRequired) {\n\t\t\t\t\t\t\tdocument.blobStorageEntry = blobEntry;\n\n\t\t\t\t\t\t\tif (!docList[\"@context\"].includes(BlobStorageContexts.ContextRoot)) {\n\t\t\t\t\t\t\t\tdocList[\"@context\"].push(BlobStorageContexts.ContextRoot);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (Is.stringValue(options?.extractRuleGroupId) && Is.stringValue(blobEntry.blob)) {\n\t\t\t\t\t\t\tconst binaryBlob = Converter.base64ToBytes(blobEntry.blob);\n\t\t\t\t\t\t\tdocument.extractedData = await this._dataProcessingComponent.extract(\n\t\t\t\t\t\t\t\toptions.extractRuleGroupId,\n\t\t\t\t\t\t\t\tbinaryBlob,\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\toptions?.extractMimeType\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// If we have the blob data due to extraction but we weren't asked for it\n\t\t\t\t\t\t// then we remove it from the document\n\t\t\t\t\t\tif (!blobRequired) {\n\t\t\t\t\t\t\tdelete document.blobStorageEntry;\n\t\t\t\t\t\t} else if (!includeBlobStorageData) {\n\t\t\t\t\t\t\tdelete document.blobStorageEntry?.blob;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (includeAttestation && Is.stringValue(document.attestationId)) {\n\t\t\t\t\t\tconst attestationInformation = await this._attestationComponent.get(\n\t\t\t\t\t\t\tdocument.attestationId\n\t\t\t\t\t\t);\n\t\t\t\t\t\tdocument.attestationInformation = attestationInformation;\n\t\t\t\t\t\tif (!docList[\"@context\"].includes(AttestationContexts.ContextRoot)) {\n\t\t\t\t\t\t\tdocList[\"@context\"].push(AttestationContexts.ContextRoot);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (Is.arrayValue(documentVertex.edges)) {\n\t\t\tdocList.edges ??= [];\n\n\t\t\tfor (const edge of documentVertex.edges) {\n\t\t\t\tif (Is.object(edge)) {\n\t\t\t\t\tdocList.edges.push(edge.targetId);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn docList;\n\t}\n\n\t/**\n\t * Create an attestation for the document.\n\t * @param document The document to create the attestation for.\n\t * @returns The attestation identifier.\n\t */\n\tprivate async createAttestation(document: IDocument): Promise<string> {\n\t\tconst documentAttestation: IDocumentAttestation & IJsonLdNodeObject = {\n\t\t\t\"@context\": [\n\t\t\t\tDocumentContexts.ContextRoot,\n\t\t\t\tDocumentContexts.ContextRootCommon,\n\t\t\t\tSchemaOrgContexts.ContextRoot\n\t\t\t],\n\t\t\ttype: DocumentTypes.DocumentAttestation,\n\t\t\tid: document.id,\n\t\t\tdocumentId: document.documentId,\n\t\t\tdocumentCode: document.documentCode,\n\t\t\tdocumentRevision: document.documentRevision,\n\t\t\tdateCreated: document.dateCreated,\n\t\t\tblobHash: document.blobHash\n\t\t};\n\t\treturn this._attestationComponent.create(documentAttestation);\n\t}\n\n\t/**\n\t * Create a document id from the document id and revision.\n\t * @param documentId The document id to create.\n\t * @param revision The revision of the document.\n\t * @returns The document id.\n\t * @internal\n\t */\n\tprivate createDocumentId(documentId: string, revision: number): string {\n\t\tconst documentIdHash = Converter.bytesToBase64Url(\n\t\t\tSha256.sum256(Converter.utf8ToBytes(documentId))\n\t\t);\n\t\treturn `document:${documentIdHash}:${revision}`;\n\t}\n}\n"]}
1
+ {"version":3,"file":"documentManagementService.js","sourceRoot":"","sources":["../../src/documentManagementService.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,0BAA0B,EAC1B,uBAAuB,EAMvB,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EACN,SAAS,EACT,MAAM,EACN,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,MAAM,EACN,EAAE,EACF,aAAa,EACb,YAAY,EACZ,GAAG,EACH,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAA0B,MAAM,wBAAwB,CAAC;AAEjF,OAAO,EACN,gBAAgB,EAChB,aAAa,EAKb,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EACN,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAGlE;;GAEG;AACH,MAAM,OAAO,yBAAyB;IACrC;;OAEG;IACI,MAAM,CAAU,UAAU,+BAA+C;IAEhF;;;OAGG;IACc,4BAA4B,CAA+B;IAE5E;;;OAGG;IACc,qBAAqB,CAAwB;IAE9D;;;OAGG;IACc,qBAAqB,CAAwB;IAE9D;;;OAGG;IACc,wBAAwB,CAA2B;IAEpE;;;OAGG;IACH,YAAY,OAAsD;QACjE,IAAI,CAAC,4BAA4B,GAAG,gBAAgB,CAAC,GAAG,CACvD,OAAO,EAAE,+BAA+B,IAAI,sBAAsB,CAClE,CAAC;QACF,IAAI,CAAC,qBAA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ACH,CAAC;IAED;;;;OAIG;IACK,KAAK,CAAC,iBAAiB,CAAC,QAAmB;QAClD,MAAM,mBAAmB,GAA6C;YACrE,UAAU,EAAE;gBACX,iBAAiB,CAAC,OAAO;gBACzB,gBAAgB,CAAC,OAAO;gBACxB,gBAAgB,CAAC,aAAa;aAC9B;YACD,IAAI,EAAE,aAAa,CAAC,mBAAmB;YACvC,EAAE,EAAE,QAAQ,CAAC,EAAE;YACf,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,YAAY,EAAE,QAAQ,CAAC,YAAY;YACnC,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;YAC3C,WAAW,EAAE,QAAQ,CAAC,WAAW;YACjC,SAAS,EAAE,QAAQ,CAAC,SAAS;SAC7B,CAAC;QACF,OAAO,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAC/D,CAAC;IAED;;;;;;OAMG;IACK,gBAAgB,CAAC,UAAkB,EAAE,QAAgB;QAC5D,MAAM,cAAc,GAAG,SAAS,CAAC,gBAAgB,CAChD,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAChD,CAAC;QACF,OAAO,YAAY,cAAc,IAAI,QAAQ,EAAE,CAAC;IACjD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IAttestationComponent } from \"@twin.org/attestation-models\";\nimport {\n\tAuditableItemGraphContexts,\n\tAuditableItemGraphTypes,\n\ttype IAuditableItemGraphVertexList,\n\ttype IAuditableItemGraphAlias,\n\ttype IAuditableItemGraphComponent,\n\ttype IAuditableItemGraphEdge,\n\ttype IAuditableItemGraphVertex\n} from \"@twin.org/auditable-item-graph-models\";\nimport type { IBlobStorageComponent } from \"@twin.org/blob-storage-models\";\nimport { BlobStorageContexts } from \"@twin.org/blob-storage-models\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport {\n\tBaseError,\n\tCoerce,\n\tComponentFactory,\n\tConverter,\n\tGeneralError,\n\tGuards,\n\tIs,\n\tNotFoundError,\n\tObjectHelper,\n\tUrn\n} from \"@twin.org/core\";\nimport { IntegrityAlgorithm, IntegrityHelper, Sha256 } from \"@twin.org/crypto\";\nimport { JsonLdProcessor, type IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport type { IDataProcessingComponent } from \"@twin.org/data-processing-models\";\nimport {\n\tDocumentContexts,\n\tDocumentTypes,\n\ttype IDocument,\n\ttype IDocumentAttestation,\n\ttype IDocumentList,\n\ttype IDocumentManagementComponent\n} from \"@twin.org/document-management-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tSchemaOrgContexts,\n\tSchemaOrgDataTypes,\n\tSchemaOrgTypes\n} from \"@twin.org/standards-schema-org\";\nimport { UneceDocumentCodeList } from \"@twin.org/standards-unece\";\nimport type { IDocumentManagementServiceConstructorOptions } from \"./models/IDocumentManagementStorageServiceConstructorOptions.js\";\n\n/**\n * Service for performing document management operations.\n */\nexport class DocumentManagementService implements IDocumentManagementComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<DocumentManagementService>();\n\n\t/**\n\t * The component for the auditable item graph.\n\t * @internal\n\t */\n\tprivate readonly _auditableItemGraphComponent: IAuditableItemGraphComponent;\n\n\t/**\n\t * The connector for the blob component.\n\t * @internal\n\t */\n\tprivate readonly _blobStorageComponent: IBlobStorageComponent;\n\n\t/**\n\t * The connector for the attestation.\n\t * @internal\n\t */\n\tprivate readonly _attestationComponent: IAttestationComponent;\n\n\t/**\n\t * The connector for the data processing.\n\t * @internal\n\t */\n\tprivate readonly _dataProcessingComponent: IDataProcessingComponent;\n\n\t/**\n\t * Create a new instance of DocumentManagementService.\n\t * @param options The options for the service.\n\t */\n\tconstructor(options?: IDocumentManagementServiceConstructorOptions) {\n\t\tthis._auditableItemGraphComponent = ComponentFactory.get<IAuditableItemGraphComponent>(\n\t\t\toptions?.auditableItemGraphComponentType ?? \"auditable-item-graph\"\n\t\t);\n\t\tthis._blobStorageComponent = ComponentFactory.get<IBlobStorageComponent>(\n\t\t\toptions?.blobStorageComponentType ?? \"blob-storage\"\n\t\t);\n\t\tthis._attestationComponent = ComponentFactory.get<IAttestationComponent>(\n\t\t\toptions?.attestationComponentType ?? \"attestation\"\n\t\t);\n\t\tthis._dataProcessingComponent = ComponentFactory.get<IDataProcessingComponent>(\n\t\t\toptions?.dataProcessingComponentType ?? \"data-processing\"\n\t\t);\n\n\t\tSchemaOrgDataTypes.registerRedirects();\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn DocumentManagementService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Store a document as an auditable item graph vertex and add its content to blob storage.\n\t * If the document id already exists and the blob data is different a new revision will be created.\n\t * For any other changes the current revision will be updated.\n\t * @param documentId The document id to create.\n\t * @param documentIdFormat The format of the document identifier.\n\t * @param documentCode The code for the document type.\n\t * @param blob The data to create the document with.\n\t * @param annotationObject Additional information to associate with the document.\n\t * @param auditableItemGraphEdges The auditable item graph vertices to connect the document to.\n\t * @param options Additional options for the set operation.\n\t * @param options.createAttestation Flag to create an attestation for the document, defaults to false.\n\t * @param options.addAlias Flag to add the document id as an alias to the aig vertex, defaults to true.\n\t * @param options.aliasAnnotationObject Annotation object for the alias.\n\t * @returns The auditable item graph vertex created for the document including its revision.\n\t */\n\tpublic async create(\n\t\tdocumentId: string,\n\t\tdocumentIdFormat: string | undefined,\n\t\tdocumentCode: UneceDocumentCodeList,\n\t\tblob: Uint8Array,\n\t\tannotationObject?: IJsonLdNodeObject,\n\t\tauditableItemGraphEdges?: {\n\t\t\ttargetId: string;\n\t\t\taddAlias?: boolean;\n\t\t\taliasAnnotationObject?: IJsonLdNodeObject;\n\t\t}[],\n\t\toptions?: {\n\t\t\tcreateAttestation?: boolean;\n\t\t\taddAlias?: boolean;\n\t\t\taliasAnnotationObject?: IJsonLdNodeObject;\n\t\t}\n\t): Promise<string> {\n\t\tGuards.stringValue(DocumentManagementService.CLASS_NAME, nameof(documentId), documentId);\n\t\tGuards.arrayOneOf(\n\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\tnameof(documentCode),\n\t\t\tdocumentCode,\n\t\t\tObject.values(UneceDocumentCodeList)\n\t\t);\n\t\tGuards.uint8Array(DocumentManagementService.CLASS_NAME, nameof(blob), blob);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\n\t\ttry {\n\t\t\t// Get the connected vertices first, if one fails we abort the create\n\t\t\tconst connectedVertices: { [id: string]: IAuditableItemGraphVertex } = {};\n\t\t\tif (Is.arrayValue(auditableItemGraphEdges)) {\n\t\t\t\tfor (const edge of auditableItemGraphEdges) {\n\t\t\t\t\tconnectedVertices[edge.targetId] = await this._auditableItemGraphComponent.get(\n\t\t\t\t\t\tedge.targetId\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst documentVertex: Omit<IAuditableItemGraphVertex, \"@context\" | \"id\" | \"type\"> = {};\n\n\t\t\tif (options?.addAlias ?? true) {\n\t\t\t\tdocumentVertex.aliases ??= [];\n\t\t\t\tdocumentVertex.aliases.push({\n\t\t\t\t\t\"@context\": AuditableItemGraphContexts.Context,\n\t\t\t\t\ttype: AuditableItemGraphTypes.Alias,\n\t\t\t\t\tid: documentId,\n\t\t\t\t\taliasFormat: documentIdFormat,\n\t\t\t\t\tannotationObject: options?.aliasAnnotationObject\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Add the blob to blob storage\n\t\t\tconst blobStorageId = await this._blobStorageComponent.create(Converter.bytesToBase64(blob));\n\n\t\t\tconst currentRevision: IDocument & IJsonLdNodeObject = {\n\t\t\t\t\"@context\": [\n\t\t\t\t\tSchemaOrgContexts.Context,\n\t\t\t\t\tDocumentContexts.Context,\n\t\t\t\t\tDocumentContexts.ContextCommon\n\t\t\t\t],\n\t\t\t\ttype: DocumentTypes.Document,\n\t\t\t\tid: this.createDocumentId(documentId, 0),\n\t\t\t\tdocumentId,\n\t\t\t\tdocumentIdFormat,\n\t\t\t\tdocumentCode,\n\t\t\t\tdocumentRevision: 0,\n\t\t\t\tannotationObject,\n\t\t\t\tintegrity: IntegrityHelper.generate(IntegrityAlgorithm.Sha256, blob),\n\t\t\t\tblobStorageId,\n\t\t\t\tdateCreated: new Date(Date.now()).toISOString(),\n\t\t\t\torganizationIdentity: contextIds?.[ContextIdKeys.Organization],\n\t\t\t\tuserIdentity: contextIds?.[ContextIdKeys.User]\n\t\t\t};\n\n\t\t\tif (options?.createAttestation ?? false) {\n\t\t\t\tcurrentRevision.attestationId = await this.createAttestation(currentRevision);\n\t\t\t}\n\n\t\t\t// Add the new revision in to the vertex\n\t\t\tdocumentVertex.resources ??= [];\n\t\t\tdocumentVertex.resources.push({\n\t\t\t\t\"@context\": AuditableItemGraphContexts.Context,\n\t\t\t\ttype: AuditableItemGraphTypes.Resource,\n\t\t\t\tresourceObject: currentRevision\n\t\t\t});\n\n\t\t\t// Add the edges from the document to the items\n\t\t\tthis.updateEdges(documentVertex, auditableItemGraphEdges);\n\n\t\t\t// And create the vertex\n\t\t\tconst vertexId = await this._auditableItemGraphComponent.create(documentVertex);\n\n\t\t\t// Now add the edges to the connected vertices\n\t\t\tawait this.updateConnectedEdges(\n\t\t\t\tconnectedVertices,\n\t\t\t\tvertexId,\n\t\t\t\t[],\n\t\t\t\tauditableItemGraphEdges,\n\t\t\t\tdocumentId,\n\t\t\t\tdocumentIdFormat\n\t\t\t);\n\n\t\t\treturn vertexId;\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorName(error, nameof<NotFoundError>())) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\t\t\"createFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Update a document as an auditable item graph vertex and add its content to blob storage.\n\t * If the blob data is different a new revision will be created.\n\t * For any other changes the current revision will be updated.\n\t * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.\n\t * @param blob The data to update the document with.\n\t * @param annotationObject Additional information to associate with the document.\n\t * @param auditableItemGraphEdges The auditable item graph vertices to connect the document to, if undefined retains current connections.\n\t * @returns Nothing.\n\t */\n\tpublic async update(\n\t\tauditableItemGraphDocumentId: string,\n\t\tblob?: Uint8Array,\n\t\tannotationObject?: IJsonLdNodeObject,\n\t\tauditableItemGraphEdges?: {\n\t\t\ttargetId: string;\n\t\t\taddAlias?: boolean;\n\t\t\taliasAnnotationObject?: IJsonLdNodeObject;\n\t\t}[]\n\t): Promise<void> {\n\t\tUrn.guard(\n\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\n\t\ttry {\n\t\t\tconst documentVertex = await this._auditableItemGraphComponent.get(\n\t\t\t\tauditableItemGraphDocumentId,\n\t\t\t\t{ includeDeleted: true }\n\t\t\t);\n\n\t\t\tif (Is.empty(documentVertex.resources)) {\n\t\t\t\tthrow new NotFoundError(DocumentManagementService.CLASS_NAME, \"documentRevisionNone\");\n\t\t\t}\n\n\t\t\tconst documents = await this.getDocumentsFromVertex(documentVertex);\n\t\t\tconst latestRevision: IDocument | undefined = documents.entries.itemListElement[0];\n\n\t\t\tdocumentVertex.resources = documentVertex.resources.filter(r => Is.empty(r.dateDeleted));\n\n\t\t\tif (Is.empty(latestRevision)) {\n\t\t\t\tthrow new NotFoundError(DocumentManagementService.CLASS_NAME, \"documentRevisionNone\");\n\t\t\t}\n\n\t\t\t// If auditableItemGraphEdges is undefined we are not updating the edges\n\t\t\t// an empty array can be passed to remove all edges\n\t\t\tconst connectedVertices: { [targetId: string]: IAuditableItemGraphVertex } = {};\n\t\t\tif (Is.array(auditableItemGraphEdges)) {\n\t\t\t\t// Get the updated connected vertices first, if one fails we abort the update\n\t\t\t\tfor (const edge of auditableItemGraphEdges) {\n\t\t\t\t\tconnectedVertices[edge.targetId] = await this._auditableItemGraphComponent.get(\n\t\t\t\t\t\tedge.targetId\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// Also get the current edges in case some need disconnecting\n\t\t\t\tif (Is.arrayValue(documents.entries.edges)) {\n\t\t\t\t\tfor (const edgeId of documents.entries.edges) {\n\t\t\t\t\t\t// If we haven't retrieved the edge then it must be one that needs removing\n\t\t\t\t\t\tif (Is.empty(connectedVertices[edgeId])) {\n\t\t\t\t\t\t\tconnectedVertices[edgeId] = await this._auditableItemGraphComponent.get(edgeId);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet updatedVertex = false;\n\n\t\t\t// If the blob is set and its hash has changed then we create a new revision\n\t\t\tif (Is.uint8Array(blob)) {\n\t\t\t\tconst newIntegrity = IntegrityHelper.generate(IntegrityAlgorithm.Sha256, blob);\n\n\t\t\t\tif (latestRevision.integrity !== newIntegrity) {\n\t\t\t\t\t// Add the blob to blob storage\n\t\t\t\t\tconst blobStorageId = await this._blobStorageComponent.create(\n\t\t\t\t\t\tConverter.bytesToBase64(blob)\n\t\t\t\t\t);\n\n\t\t\t\t\tconst newRevision = ObjectHelper.clone(latestRevision);\n\n\t\t\t\t\tnewRevision.documentRevision++;\n\t\t\t\t\tnewRevision.id = this.createDocumentId(\n\t\t\t\t\t\tnewRevision.documentId,\n\t\t\t\t\t\tnewRevision.documentRevision\n\t\t\t\t\t);\n\t\t\t\t\tnewRevision.integrity = newIntegrity;\n\t\t\t\t\tnewRevision.blobStorageId = blobStorageId;\n\t\t\t\t\tnewRevision.annotationObject = annotationObject;\n\n\t\t\t\t\tif (Is.stringValue(latestRevision.attestationId)) {\n\t\t\t\t\t\tnewRevision.attestationId = await this.createAttestation(newRevision);\n\t\t\t\t\t}\n\n\t\t\t\t\tdocumentVertex.resources.push({\n\t\t\t\t\t\t\"@context\": AuditableItemGraphContexts.Context,\n\t\t\t\t\t\ttype: AuditableItemGraphTypes.Resource,\n\t\t\t\t\t\tresourceObject: newRevision as unknown as IJsonLdNodeObject\n\t\t\t\t\t});\n\n\t\t\t\t\tupdatedVertex = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If the blob wasn't updated but the annotation object has then update the current revision\n\t\t\t// instead of creating a new one\n\t\t\tif (\n\t\t\t\t!updatedVertex &&\n\t\t\t\t!ObjectHelper.equal(latestRevision.annotationObject, annotationObject)\n\t\t\t) {\n\t\t\t\tupdatedVertex = true;\n\t\t\t\tlatestRevision.annotationObject = annotationObject;\n\t\t\t\tlatestRevision.dateModified = new Date(Date.now()).toISOString();\n\t\t\t}\n\n\t\t\tconst existingEdgeIds = documentVertex.edges?.map(e => e.targetId) ?? [];\n\n\t\t\t// Update the edges from the document to the items\n\t\t\tconst edgesUpdated = this.updateEdges(documentVertex, auditableItemGraphEdges);\n\t\t\tif (edgesUpdated) {\n\t\t\t\tupdatedVertex = true;\n\t\t\t}\n\n\t\t\tif (updatedVertex) {\n\t\t\t\tawait this._auditableItemGraphComponent.update(documentVertex);\n\t\t\t}\n\n\t\t\tif (edgesUpdated) {\n\t\t\t\tawait this.updateConnectedEdges(\n\t\t\t\t\tconnectedVertices,\n\t\t\t\t\tauditableItemGraphDocumentId,\n\t\t\t\t\texistingEdgeIds,\n\t\t\t\t\tauditableItemGraphEdges,\n\t\t\t\t\tlatestRevision.documentId,\n\t\t\t\t\tlatestRevision.documentIdFormat\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorName(error, nameof<NotFoundError>())) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\t\t\"updateFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Get a document using it's auditable item graph vertex id and optional revision.\n\t * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.\n\t * @param options Additional options for the get operation.\n\t * @param options.includeBlobStorageMetadata Flag to include the blob storage metadata for the document, defaults to false.\n\t * @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.\n\t * @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.\n\t * @param options.includeRemoved Flag to include deleted documents, defaults to false.\n\t * @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.\n\t * @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.\n\t * @param cursor The cursor to get the next chunk of revisions.\n\t * @param limit Limit the number of items to return, defaults to 1 so only most recent is returned.\n\t * @returns The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.\n\t */\n\tpublic async get(\n\t\tauditableItemGraphDocumentId: string,\n\t\toptions?: {\n\t\t\tincludeBlobStorageMetadata?: boolean;\n\t\t\tincludeBlobStorageData?: boolean;\n\t\t\tincludeAttestation?: boolean;\n\t\t\tincludeRemoved?: boolean;\n\t\t\textractRuleGroupId?: string;\n\t\t\textractMimeType?: string;\n\t\t},\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\tentries: IDocumentList;\n\t\tcursor?: string;\n\t}> {\n\t\tUrn.guard(\n\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\n\t\ttry {\n\t\t\tconst documentVertex = await this._auditableItemGraphComponent.get(\n\t\t\t\tauditableItemGraphDocumentId,\n\t\t\t\t{ includeDeleted: options?.includeRemoved }\n\t\t\t);\n\n\t\t\t// Populate the document and revisions with the options set\n\t\t\tconst documents = await this.getDocumentsFromVertex(documentVertex, options, cursor, limit);\n\n\t\t\tconst result = await JsonLdProcessor.compact(\n\t\t\t\tdocuments.entries,\n\t\t\t\tdocuments.entries[\"@context\"]\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tentries: result,\n\t\t\t\tcursor: documents.cursor\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorName(error, nameof<NotFoundError>())) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(DocumentManagementService.CLASS_NAME, \"getFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Get a document revision using it's auditable item graph vertex id.\n\t * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.\n\t * @param revision The revision id for the document.\n\t * @param options Additional options for the get operation.\n\t * @param options.includeBlobStorageMetadata Flag to include the blob storage metadata for the document, defaults to false.\n\t * @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.\n\t * @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.\n\t * @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.\n\t * @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.\n\t * @returns The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.\n\t */\n\tpublic async getRevision(\n\t\tauditableItemGraphDocumentId: string,\n\t\trevision: number,\n\t\toptions?: {\n\t\t\tincludeBlobStorageMetadata?: boolean;\n\t\t\tincludeBlobStorageData?: boolean;\n\t\t\tincludeAttestation?: boolean;\n\t\t\textractRuleGroupId?: string;\n\t\t\textractMimeType?: string;\n\t\t}\n\t): Promise<IDocument> {\n\t\tUrn.guard(\n\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\t\tGuards.integer(DocumentManagementService.CLASS_NAME, nameof(revision), revision);\n\n\t\ttry {\n\t\t\tconst documentVertex = await this._auditableItemGraphComponent.get(\n\t\t\t\tauditableItemGraphDocumentId,\n\t\t\t\t{ includeDeleted: true }\n\t\t\t);\n\n\t\t\tif (Is.empty(documentVertex.resources)) {\n\t\t\t\tthrow new NotFoundError(DocumentManagementService.CLASS_NAME, \"documentRevisionNone\");\n\t\t\t}\n\n\t\t\tdocumentVertex.resources = documentVertex.resources.filter(\n\t\t\t\td => d.resourceObject?.documentRevision === revision\n\t\t\t);\n\n\t\t\tif (documentVertex.resources.length === 0) {\n\t\t\t\tthrow new NotFoundError(\n\t\t\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\t\t\t\"documentRevisionNotFound\",\n\t\t\t\t\trevision.toString()\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Populate the document and revisions with the options set\n\t\t\tconst docList = await this.getDocumentsFromVertex(documentVertex, options);\n\n\t\t\tconst result = await JsonLdProcessor.compact(\n\t\t\t\tdocList.entries.itemListElement[0],\n\t\t\t\tdocList.entries.itemListElement[0][\"@context\"]\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorName(error, nameof<NotFoundError>())) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\t\t\"getRevisionFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Remove an auditable item graph vertex using it's id.\n\t * The document dateDeleted will be set, but can still be queried with the includeRemoved flag.\n\t * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.\n\t * @param revision The revision of the document to remove.\n\t * @returns Nothing.\n\t */\n\tpublic async removeRevision(\n\t\tauditableItemGraphDocumentId: string,\n\t\trevision: number\n\t): Promise<void> {\n\t\tUrn.guard(\n\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\t\tGuards.number(DocumentManagementService.CLASS_NAME, nameof(revision), revision);\n\n\t\ttry {\n\t\t\tconst documentVertex = await this._auditableItemGraphComponent.get(\n\t\t\t\tauditableItemGraphDocumentId\n\t\t\t);\n\n\t\t\tif (Is.empty(documentVertex.resources)) {\n\t\t\t\tthrow new NotFoundError(DocumentManagementService.CLASS_NAME, \"documentRevisionNone\");\n\t\t\t}\n\n\t\t\tconst docRevisionIndex = documentVertex.resources.findIndex(\n\t\t\t\td => d.resourceObject?.documentRevision === revision\n\t\t\t);\n\n\t\t\tif (docRevisionIndex === -1) {\n\t\t\t\tthrow new NotFoundError(\n\t\t\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\t\t\t\"documentRevisionNotFound\",\n\t\t\t\t\trevision.toString()\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tdocumentVertex.resources.splice(docRevisionIndex, 1);\n\n\t\t\tawait this._auditableItemGraphComponent.update(documentVertex);\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorName(error, nameof<NotFoundError>())) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\t\t\"removeRevisionFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Find all the document with a specific id.\n\t * @param documentId The document id to find in the graph.\n\t * @param cursor The cursor to get the next chunk of documents.\n\t * @param limit The limit to get the next chunk of documents.\n\t * @returns The graph vertices that contain documents referencing the specified document id.\n\t */\n\tpublic async query(\n\t\tdocumentId: string,\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\tentries: IAuditableItemGraphVertexList;\n\t\tcursor?: string;\n\t}> {\n\t\tGuards.stringValue(DocumentManagementService.CLASS_NAME, nameof(documentId), documentId);\n\n\t\ttry {\n\t\t\tconst result = await this._auditableItemGraphComponent.query(\n\t\t\t\t{\n\t\t\t\t\tid: documentId,\n\t\t\t\t\tidMode: \"both\",\n\t\t\t\t\tresourceTypes: [DocumentTypes.Document]\n\t\t\t\t},\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[\"id\", \"dateCreated\", \"dateModified\", \"aliases\", \"annotationObject\", \"resources\", \"edges\"],\n\t\t\t\tcursor,\n\t\t\t\tlimit\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorName(error, nameof<NotFoundError>())) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(DocumentManagementService.CLASS_NAME, \"queryFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Update the edges of the document vertex.\n\t * @param documentVertex The document vertex to update.\n\t * @param auditableItemGraphEdges The list of edges to use.\n\t * @returns True if the edges were updated.\n\t * @internal\n\t */\n\tprivate updateEdges(\n\t\tdocumentVertex: Omit<IAuditableItemGraphVertex, \"@context\" | \"id\" | \"type\">,\n\t\tauditableItemGraphEdges:\n\t\t\t| { targetId: string; addAlias?: boolean; aliasAnnotationObject?: IJsonLdNodeObject }[]\n\t\t\t| undefined\n\t): boolean {\n\t\tlet changed = false;\n\n\t\tconst existingEdgeIds = documentVertex.edges?.map(e => e.targetId) ?? [];\n\n\t\tif (Is.array(auditableItemGraphEdges)) {\n\t\t\tfor (const aigEdge of auditableItemGraphEdges) {\n\t\t\t\tconst existingIndex = existingEdgeIds.indexOf(aigEdge.targetId);\n\t\t\t\tif (existingIndex !== -1) {\n\t\t\t\t\t// If the edge already exists then we don't need to add it again\n\t\t\t\t\t// We just need to remove it from the list of existing ids\n\t\t\t\t\t// any remaining after this loop will be need to be removed\n\t\t\t\t\texistingEdgeIds.splice(existingIndex, 1);\n\t\t\t\t} else {\n\t\t\t\t\tconst vertexEdge: IAuditableItemGraphEdge = {\n\t\t\t\t\t\t\"@context\": AuditableItemGraphContexts.Context,\n\t\t\t\t\t\ttype: AuditableItemGraphTypes.Edge,\n\t\t\t\t\t\ttargetId: aigEdge.targetId,\n\t\t\t\t\t\tedgeRelationships: [\"document\"]\n\t\t\t\t\t};\n\n\t\t\t\t\tdocumentVertex.edges ??= [];\n\t\t\t\t\tdocumentVertex.edges?.push(vertexEdge);\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Anything left in the existingEdgeIds array means they need to be removed\n\t\t\tif (existingEdgeIds.length > 0 && Is.array(documentVertex.edges)) {\n\t\t\t\tfor (const existingEdgeId of existingEdgeIds) {\n\t\t\t\t\tconst existingIndex = documentVertex.edges.findIndex(e => e.targetId === existingEdgeId);\n\t\t\t\t\tif (existingIndex !== -1) {\n\t\t\t\t\t\tdocumentVertex.edges.splice(existingIndex, 1);\n\t\t\t\t\t\tchanged = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn changed;\n\t}\n\n\t/**\n\t * Update the edges.\n\t * @param connectedVertices The connected vertices for the edges.\n\t * @param auditableItemGraphDocumentId The document id to use.\n\t * @param documentVertex The document vertex to update.\n\t * @param auditableItemGraphEdges The list of edges to use.\n\t * @param documentId The document identifier.\n\t * @param documentIdFormat The format of the document identifier.\n\t * @internal\n\t */\n\tprivate async updateConnectedEdges(\n\t\tconnectedVertices: { [id: string]: IAuditableItemGraphVertex },\n\t\tauditableItemGraphDocumentId: string,\n\t\texistingEdgeIds: string[],\n\t\tauditableItemGraphEdges:\n\t\t\t| { targetId: string; addAlias?: boolean; aliasAnnotationObject?: IJsonLdNodeObject }[]\n\t\t\t| undefined,\n\t\tdocumentId: string,\n\t\tdocumentIdFormat: string | undefined\n\t): Promise<void> {\n\t\tif (Is.array(auditableItemGraphEdges)) {\n\t\t\tfor (const aigEdge of auditableItemGraphEdges) {\n\t\t\t\tconst connected = connectedVertices[aigEdge.targetId];\n\n\t\t\t\tif (!Is.empty(connected)) {\n\t\t\t\t\tlet updatedConnected = false;\n\n\t\t\t\t\tconst existingIndex = existingEdgeIds.indexOf(aigEdge.targetId);\n\t\t\t\t\tif (existingIndex !== -1) {\n\t\t\t\t\t\t// If the edge already exists we remove it from the list of existing ids\n\t\t\t\t\t\t// any remaining after this loop will be need to be disconnected\n\t\t\t\t\t\texistingEdgeIds.splice(existingIndex, 1);\n\t\t\t\t\t}\n\n\t\t\t\t\t// Add the edge with the document vertex id if it doesn't already exist\n\t\t\t\t\tconst hasEdge = connected.edges?.some(e => e.targetId === auditableItemGraphDocumentId);\n\t\t\t\t\tif (!hasEdge) {\n\t\t\t\t\t\tconst vertexEdge: IAuditableItemGraphEdge = {\n\t\t\t\t\t\t\t\"@context\": AuditableItemGraphContexts.Context,\n\t\t\t\t\t\t\ttype: AuditableItemGraphTypes.Edge,\n\t\t\t\t\t\t\ttargetId: auditableItemGraphDocumentId,\n\t\t\t\t\t\t\tedgeRelationships: [\"document\"]\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tconnected.edges ??= [];\n\t\t\t\t\t\tconnected.edges?.push(vertexEdge);\n\t\t\t\t\t\tupdatedConnected = true;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Add alias with the document id if option flag is set and it doesn't already exist\n\t\t\t\t\tif (aigEdge.addAlias) {\n\t\t\t\t\t\tconst alias = connected.aliases?.find(a => a.id === documentId);\n\t\t\t\t\t\tif (Is.empty(alias)) {\n\t\t\t\t\t\t\t// No existing alias, so create one\n\t\t\t\t\t\t\tconst vertexAlias: IAuditableItemGraphAlias = {\n\t\t\t\t\t\t\t\t\"@context\": AuditableItemGraphContexts.Context,\n\t\t\t\t\t\t\t\ttype: AuditableItemGraphTypes.Alias,\n\t\t\t\t\t\t\t\tid: documentId,\n\t\t\t\t\t\t\t\taliasFormat: documentIdFormat,\n\t\t\t\t\t\t\t\tannotationObject: aigEdge.aliasAnnotationObject\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\tconnected.aliases ??= [];\n\t\t\t\t\t\t\tconnected.aliases?.push(vertexAlias);\n\t\t\t\t\t\t\tupdatedConnected = true;\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\t!ObjectHelper.equal(alias.annotationObject, aigEdge.aliasAnnotationObject) ||\n\t\t\t\t\t\t\tdocumentIdFormat !== alias.aliasFormat\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// The alias already exists, but the format or annotation object has changed\n\t\t\t\t\t\t\talias.annotationObject = aigEdge.aliasAnnotationObject;\n\t\t\t\t\t\t\talias.aliasFormat = documentIdFormat;\n\t\t\t\t\t\t\tupdatedConnected = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (updatedConnected) {\n\t\t\t\t\t\tawait this._auditableItemGraphComponent.update(connected);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Anything left in the existingEdgeIds array means they need to be removed\n\t\tif (existingEdgeIds.length > 0) {\n\t\t\tfor (const existingEdgeId of existingEdgeIds) {\n\t\t\t\tconst connected = connectedVertices[existingEdgeId];\n\n\t\t\t\tif (!Is.empty(connected)) {\n\t\t\t\t\tlet updatedConnected = false;\n\n\t\t\t\t\t// Remove the edge from the connected vertex\n\t\t\t\t\tif (Is.arrayValue(connected.edges)) {\n\t\t\t\t\t\tconst existingIndex = connected.edges.findIndex(\n\t\t\t\t\t\t\te => e.targetId === auditableItemGraphDocumentId\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (existingIndex !== -1) {\n\t\t\t\t\t\t\tconnected.edges.splice(existingIndex, 1);\n\t\t\t\t\t\t\tupdatedConnected = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Remove the alias from the connected vertex\n\t\t\t\t\tif (Is.arrayValue(connected.aliases)) {\n\t\t\t\t\t\tconst existingIndex = connected.aliases.findIndex(e => e.id === documentId);\n\t\t\t\t\t\tif (existingIndex !== -1) {\n\t\t\t\t\t\t\tconnected.aliases.splice(existingIndex, 1);\n\t\t\t\t\t\t\tupdatedConnected = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (updatedConnected) {\n\t\t\t\t\t\tawait this._auditableItemGraphComponent.update(connected);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Get the documents from the auditable item graph vertex.\n\t * @param documentVertex The vertex containing the documents.\n\t * @param options Additional options for the get operation.\n\t * @param options.includeBlobStorageMetadata Flag to include the blob storage metadata for the document, defaults to false.\n\t * @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.\n\t * @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.\n\t * @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.\n\t * @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.\n\t * @param cursor The cursor to get the next chunk of revisions.\n\t * @param limit Limit the number of items to return, defaults to 1 so only most recent is returned.\n\t * @returns The finalised list of documents.\n\t * @internal\n\t */\n\tprivate async getDocumentsFromVertex(\n\t\tdocumentVertex: IAuditableItemGraphVertex,\n\t\toptions?: {\n\t\t\tincludeBlobStorageMetadata?: boolean;\n\t\t\tincludeBlobStorageData?: boolean;\n\t\t\tincludeAttestation?: boolean;\n\t\t\textractRuleGroupId?: string;\n\t\t\textractMimeType?: string;\n\t\t},\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\tentries: IDocumentList;\n\t\tcursor?: string;\n\t}> {\n\t\tconst docList: IDocumentList = {\n\t\t\t\"@context\": [\n\t\t\t\tSchemaOrgContexts.Context,\n\t\t\t\tDocumentContexts.Context,\n\t\t\t\tDocumentContexts.ContextCommon\n\t\t\t],\n\t\t\ttype: SchemaOrgTypes.ItemList,\n\t\t\t[SchemaOrgTypes.ItemListElement]: []\n\t\t};\n\n\t\tlet nextCursor: string | undefined;\n\n\t\tif (Is.arrayValue(documentVertex.resources)) {\n\t\t\t// Sort by newest revision first\n\t\t\tdocumentVertex.resources.sort(\n\t\t\t\t(a, b) =>\n\t\t\t\t\t(Coerce.number(b.resourceObject?.documentRevision) ?? 0) -\n\t\t\t\t\t(Coerce.number(a.resourceObject?.documentRevision) ?? 0)\n\t\t\t);\n\n\t\t\tconst startIndex = Coerce.integer(cursor) ?? 0;\n\t\t\tconst endIndex = Math.min(startIndex + (limit ?? 1), documentVertex.resources.length);\n\t\t\tconst slicedResources = documentVertex.resources.slice(startIndex, endIndex);\n\t\t\tnextCursor = documentVertex.resources.length > endIndex ? endIndex.toString() : undefined;\n\n\t\t\tconst includeBlobStorageMetadata = options?.includeBlobStorageMetadata ?? false;\n\t\t\tconst includeBlobStorageData = options?.includeBlobStorageData ?? false;\n\t\t\tconst includeAttestation = options?.includeAttestation ?? false;\n\t\t\tconst extractData = Is.stringValue(options?.extractRuleGroupId);\n\n\t\t\tfor (let i = 0; i < slicedResources.length; i++) {\n\t\t\t\tconst document = slicedResources[i].resourceObject as unknown as IDocument;\n\t\t\t\tif (Is.object(document)) {\n\t\t\t\t\tdocument.dateDeleted = slicedResources[i].dateDeleted;\n\n\t\t\t\t\tdocList[SchemaOrgTypes.ItemListElement].push(document);\n\n\t\t\t\t\tconst blobRequired = includeBlobStorageMetadata || includeBlobStorageData;\n\t\t\t\t\tif (blobRequired || extractData) {\n\t\t\t\t\t\tconst blobEntry = await this._blobStorageComponent.get(document.blobStorageId, {\n\t\t\t\t\t\t\tincludeContent: includeBlobStorageData || extractData\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (blobRequired) {\n\t\t\t\t\t\t\tdocument.blobStorageEntry = blobEntry;\n\t\t\t\t\t\t\tif (Is.object(document.blobStorageEntry)) {\n\t\t\t\t\t\t\t\tObjectHelper.propertyDelete(document.blobStorageEntry, \"@context\");\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (!docList[\"@context\"].includes(BlobStorageContexts.Context)) {\n\t\t\t\t\t\t\t\tdocList[\"@context\"].push(BlobStorageContexts.Context);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (Is.stringValue(options?.extractRuleGroupId) && Is.stringValue(blobEntry.blob)) {\n\t\t\t\t\t\t\tconst binaryBlob = Converter.base64ToBytes(blobEntry.blob);\n\t\t\t\t\t\t\tdocument.extractedData = await this._dataProcessingComponent.extract(\n\t\t\t\t\t\t\t\toptions.extractRuleGroupId,\n\t\t\t\t\t\t\t\tbinaryBlob,\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\toptions?.extractMimeType\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// If we have the blob data due to extraction but we weren't asked for it\n\t\t\t\t\t\t// then we remove it from the document\n\t\t\t\t\t\tif (!blobRequired) {\n\t\t\t\t\t\t\tdelete document.blobStorageEntry;\n\t\t\t\t\t\t} else if (!includeBlobStorageData) {\n\t\t\t\t\t\t\tdelete document.blobStorageEntry?.blob;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (includeAttestation && Is.stringValue(document.attestationId)) {\n\t\t\t\t\t\tconst attestationInformation = await this._attestationComponent.get(\n\t\t\t\t\t\t\tdocument.attestationId\n\t\t\t\t\t\t);\n\t\t\t\t\t\tdocument.attestationInformation = attestationInformation;\n\t\t\t\t\t\tif (Is.object(document.attestationInformation)) {\n\t\t\t\t\t\t\tObjectHelper.propertyDelete(document.attestationInformation, \"@context\");\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (Is.arrayValue(documentVertex.edges)) {\n\t\t\tdocList.edges ??= [];\n\n\t\t\tfor (const edge of documentVertex.edges) {\n\t\t\t\tif (Is.object(edge)) {\n\t\t\t\t\tdocList.edges.push(edge.targetId);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tentries: docList,\n\t\t\tcursor: nextCursor\n\t\t};\n\t}\n\n\t/**\n\t * Create an attestation for the document.\n\t * @param document The document to create the attestation for.\n\t * @returns The attestation identifier.\n\t */\n\tprivate async createAttestation(document: IDocument): Promise<string> {\n\t\tconst documentAttestation: IDocumentAttestation & IJsonLdNodeObject = {\n\t\t\t\"@context\": [\n\t\t\t\tSchemaOrgContexts.Context,\n\t\t\t\tDocumentContexts.Context,\n\t\t\t\tDocumentContexts.ContextCommon\n\t\t\t],\n\t\t\ttype: DocumentTypes.DocumentAttestation,\n\t\t\tid: document.id,\n\t\t\tdocumentId: document.documentId,\n\t\t\tdocumentCode: document.documentCode,\n\t\t\tdocumentRevision: document.documentRevision,\n\t\t\tdateCreated: document.dateCreated,\n\t\t\tintegrity: document.integrity\n\t\t};\n\t\treturn this._attestationComponent.create(documentAttestation);\n\t}\n\n\t/**\n\t * Create a document id from the document id and revision.\n\t * @param documentId The document id to create.\n\t * @param revision The revision of the document.\n\t * @returns The document id.\n\t * @internal\n\t */\n\tprivate createDocumentId(documentId: string, revision: number): string {\n\t\tconst documentIdHash = Converter.bytesToBase64Url(\n\t\t\tSha256.sum256(Converter.utf8ToBytes(documentId))\n\t\t);\n\t\treturn `document:${documentIdHash}:${revision}`;\n\t}\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { type IAuditableItemGraphVertexList } from "@twin.org/auditable-item-graph-models";
2
2
  import { type IJsonLdNodeObject } from "@twin.org/data-json-ld";
3
3
  import { type IDocument, type IDocumentList, type IDocumentManagementComponent } from "@twin.org/document-management-models";
4
- import { UneceDocumentCodes } from "@twin.org/standards-unece";
4
+ import { UneceDocumentCodeList } from "@twin.org/standards-unece";
5
5
  import type { IDocumentManagementServiceConstructorOptions } from "./models/IDocumentManagementStorageServiceConstructorOptions.js";
6
6
  /**
7
7
  * Service for performing document management operations.
@@ -37,7 +37,7 @@ export declare class DocumentManagementService implements IDocumentManagementCom
37
37
  * @param options.aliasAnnotationObject Annotation object for the alias.
38
38
  * @returns The auditable item graph vertex created for the document including its revision.
39
39
  */
40
- create(documentId: string, documentIdFormat: string | undefined, documentCode: UneceDocumentCodes, blob: Uint8Array, annotationObject?: IJsonLdNodeObject, auditableItemGraphEdges?: {
40
+ create(documentId: string, documentIdFormat: string | undefined, documentCode: UneceDocumentCodeList, blob: Uint8Array, annotationObject?: IJsonLdNodeObject, auditableItemGraphEdges?: {
41
41
  targetId: string;
42
42
  addAlias?: boolean;
43
43
  aliasAnnotationObject?: IJsonLdNodeObject;
@@ -82,7 +82,10 @@ export declare class DocumentManagementService implements IDocumentManagementCom
82
82
  includeRemoved?: boolean;
83
83
  extractRuleGroupId?: string;
84
84
  extractMimeType?: string;
85
- }, cursor?: string, limit?: number): Promise<IDocumentList>;
85
+ }, cursor?: string, limit?: number): Promise<{
86
+ entries: IDocumentList;
87
+ cursor?: string;
88
+ }>;
86
89
  /**
87
90
  * Get a document revision using it's auditable item graph vertex id.
88
91
  * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
@@ -117,7 +120,10 @@ export declare class DocumentManagementService implements IDocumentManagementCom
117
120
  * @param limit The limit to get the next chunk of documents.
118
121
  * @returns The graph vertices that contain documents referencing the specified document id.
119
122
  */
120
- query(documentId: string, cursor?: string, limit?: number): Promise<IAuditableItemGraphVertexList>;
123
+ query(documentId: string, cursor?: string, limit?: number): Promise<{
124
+ entries: IAuditableItemGraphVertexList;
125
+ cursor?: string;
126
+ }>;
121
127
  /**
122
128
  * Create an attestation for the document.
123
129
  * @param document The document to create the attestation for.