@twin.org/document-management-service 0.0.3-next.14 → 0.0.3-next.16

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 +1 @@
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,C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MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;oBACrB,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACnC,CAAC;YACF,CAAC;QACF,CAAC;QAED,OAAO;YACN,OAAO,EAAE,OAAO;YAChB,MAAM,EAAE,UAAU;SAClB,CAAC;IACH,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, \"id\"> = {\n\t\t\t\t\"@context\": [AuditableItemGraphContexts.Context, AuditableItemGraphContexts.ContextCommon],\n\t\t\t\ttype: AuditableItemGraphTypes.Vertex\n\t\t\t};\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(\n\t\t\t\tObjectHelper.removeEmptyProperties(documentVertex)\n\t\t\t);\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(\n\t\t\t\t\tObjectHelper.removeEmptyProperties(documentVertex)\n\t\t\t\t);\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
+ {"version":3,"file":"documentManagementService.js","sourceRoot":"","sources":["../../src/documentManagementService.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,0BAA0B,EAC1B,uBAAuB,EAOvB,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,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iB,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,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;QACnF,MAAM,YAAY,CAAC,eAAe,CACjC,IAAI,CAAC,mBAAmB,EACxB,2BAA2B,CAAC,mBAAmB,CAC/C,CAAC;QACF,OAAO,aAAa,CAAC;IACtB,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 IAuditableItemGraphComponent,\n\ttype IAuditableItemGraphEdge,\n\ttype IAuditableItemGraphPartialVertex,\n\ttype IAuditableItemGraphResource,\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\tMutex,\n\tNotFoundError,\n\tObjectHelper,\n\tUrn\n} from \"@twin.org/core\";\nimport { IntegrityAlgorithm, IntegrityHelper, Sha256 } from \"@twin.org/crypto\";\nimport { JsonLdHelper, JsonLdProcessor, type IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport type { IDataProcessingComponent } from \"@twin.org/data-processing-models\";\nimport {\n\tDocumentContexts,\n\tDocumentManagementMetricIds,\n\tDocumentManagementMetrics,\n\tDocumentTypes,\n\ttype IDocumentManagementEdgeEntry,\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 { MetricHelper, type ITelemetryComponent } from \"@twin.org/telemetry-models\";\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 * The optional telemetry component used for event metrics.\n\t * @internal\n\t */\n\tprivate readonly _telemetryComponent?: ITelemetryComponent;\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\t\tthis._telemetryComponent = ComponentFactory.getIfExists<ITelemetryComponent>(\n\t\t\toptions?.telemetryComponentType\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 * Register all document management metrics with the telemetry component.\n\t */\n\tpublic async start(): Promise<void> {\n\t\tif (Is.undefined(this._telemetryComponent)) {\n\t\t\treturn;\n\t\t}\n\t\tawait MetricHelper.createMetrics(this._telemetryComponent, DocumentManagementMetrics);\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?: IDocumentManagementEdgeEntry[],\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\tconst documentVertex: Omit<IAuditableItemGraphVertex, \"id\"> = {\n\t\t\t\t\"@context\": [AuditableItemGraphContexts.Context, AuditableItemGraphContexts.ContextCommon],\n\t\t\t\ttype: AuditableItemGraphTypes.Vertex\n\t\t\t};\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 outgoing edges from the document vertex to each connected item\n\t\t\tif (Is.arrayValue(auditableItemGraphEdges)) {\n\t\t\t\tdocumentVertex.edges ??= [];\n\t\t\t\tfor (const aigEdge of auditableItemGraphEdges) {\n\t\t\t\t\tdocumentVertex.edges.push({\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\t\t\t\t}\n\t\t\t}\n\n\t\t\t// And create the vertex\n\t\t\tconst vertexId = await this._auditableItemGraphComponent.create(\n\t\t\t\tObjectHelper.removeEmptyProperties(documentVertex)\n\t\t\t);\n\n\t\t\t// Now add the edges to the connected vertices.\n\t\t\t// isCreatePath = true enables fail-fast + rollback if a target vertex is missing.\n\t\t\tconst failingVertexId = await this.updateConnectedEdges(\n\t\t\t\tvertexId,\n\t\t\t\tauditableItemGraphEdges ?? [],\n\t\t\t\t[],\n\t\t\t\tdocumentId,\n\t\t\t\tdocumentIdFormat,\n\t\t\t\ttrue\n\t\t\t);\n\n\t\t\tif (Is.stringValue(failingVertexId)) {\n\t\t\t\t// At least one connected vertex was missing. Back-edges already written have been\n\t\t\t\t// rolled back by updateConnectedEdges. Best-effort cleanup: remove the orphaned\n\t\t\t\t// blob and soft-delete the document resource so the vertex is left empty.\n\t\t\t\ttry {\n\t\t\t\t\tawait this._blobStorageComponent.remove(blobStorageId);\n\t\t\t\t} catch {}\n\t\t\t\ttry {\n\t\t\t\t\tawait this._auditableItemGraphComponent.updatePartial({\n\t\t\t\t\t\t\"@context\": [\n\t\t\t\t\t\t\tAuditableItemGraphContexts.Context,\n\t\t\t\t\t\t\tAuditableItemGraphContexts.ContextCommon\n\t\t\t\t\t\t],\n\t\t\t\t\t\tid: vertexId,\n\t\t\t\t\t\tresourcePatches: { remove: [currentRevision.id] }\n\t\t\t\t\t});\n\t\t\t\t} catch {}\n\t\t\t\tthrow new NotFoundError(\n\t\t\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\t\t\t\"connectedVertexNotFound\",\n\t\t\t\t\tfailingVertexId\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tawait MetricHelper.metricIncrement(\n\t\t\t\tthis._telemetryComponent,\n\t\t\t\tDocumentManagementMetricIds.DocumentsCreated,\n\t\t\t\t{ hasAttestation: Is.stringValue(currentRevision.attestationId) }\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 Explicit edge delta to apply. If undefined, existing connections\n\t * are retained unchanged. Use `add` to create new connections and `remove` to disconnect existing\n\t * ones by their target vertex id. To update alias metadata on an already-connected vertex, include\n\t * it in `add` with the updated `aliasAnnotationObject` — AIG's alias patch is an upsert, so the\n\t * alias is updated in place without creating a duplicate back-edge.\n\t * @param auditableItemGraphEdges.add Connections to add; each creates a back-edge on the connected vertex.\n\t * @param auditableItemGraphEdges.remove Target vertex IDs to disconnect; their back-edges are removed.\n\t * @returns Nothing.\n\t */\n\tpublic async updatePartial(\n\t\tauditableItemGraphDocumentId: string,\n\t\tblob?: Uint8Array,\n\t\tannotationObject?: IJsonLdNodeObject,\n\t\tauditableItemGraphEdges?: {\n\t\t\tadd?: IDocumentManagementEdgeEntry[];\n\t\t\tremove?: string[];\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\tawait Mutex.lock(auditableItemGraphDocumentId, { throwOnTimeout: true });\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\n\t\t\tconst resourcePatchesAdd: IAuditableItemGraphResource[] = [];\n\t\t\tlet blobRevisionCreated = false;\n\t\t\tlet newRevisionHasAttestation = 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\tif (!Is.empty(annotationObject)) {\n\t\t\t\t\t\tnewRevision.annotationObject = annotationObject;\n\t\t\t\t\t}\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\tresourcePatchesAdd.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: JsonLdHelper.toNodeObject(newRevision)\n\t\t\t\t\t});\n\n\t\t\t\t\tnewRevisionHasAttestation = Is.stringValue(newRevision.attestationId);\n\t\t\t\t\tblobRevisionCreated = true;\n\t\t\t\t} else if (Is.stringValue(latestRevision.dateDeleted)) {\n\t\t\t\t\t// Same content as the most recent (soft-deleted) revision — restore it.\n\t\t\t\t\tconst restoredRevision = ObjectHelper.clone(latestRevision);\n\t\t\t\t\tdelete restoredRevision.dateDeleted;\n\t\t\t\t\tif (!Is.empty(annotationObject)) {\n\t\t\t\t\t\trestoredRevision.annotationObject = annotationObject;\n\t\t\t\t\t}\n\t\t\t\t\tresourcePatchesAdd.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: JsonLdHelper.toNodeObject(restoredRevision)\n\t\t\t\t\t});\n\t\t\t\t\tblobRevisionCreated = 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 was explicitly provided and has\n\t\t\t// changed, update the current revision instead of creating a new one.\n\t\t\t// Undefined means \"no change\" in patch semantics — it does not clear the annotation.\n\t\t\tif (\n\t\t\t\t!blobRevisionCreated &&\n\t\t\t\t!Is.empty(annotationObject) &&\n\t\t\t\t!ObjectHelper.equal(latestRevision.annotationObject, annotationObject)\n\t\t\t) {\n\t\t\t\tlatestRevision.annotationObject = annotationObject;\n\t\t\t\tlatestRevision.dateModified = new Date(Date.now()).toISOString();\n\t\t\t\tresourcePatchesAdd.push(\n\t\t\t\t\tObjectHelper.removeEmptyProperties({\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: JsonLdHelper.toNodeObject(latestRevision)\n\t\t\t\t\t})\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Build document-vertex edge patches directly from the explicit delta.\n\t\t\tconst edgesToAdd = auditableItemGraphEdges?.add ?? [];\n\t\t\tconst edgeTargetIdsToRemove = auditableItemGraphEdges?.remove ?? [];\n\t\t\tconst hasEdgeChanges =\n\t\t\t\t!Is.empty(auditableItemGraphEdges) &&\n\t\t\t\t(edgesToAdd.length > 0 || edgeTargetIdsToRemove.length > 0);\n\n\t\t\tconst documentEdgePatchesAdd: IAuditableItemGraphEdge[] = edgesToAdd.map(aigEdge => ({\n\t\t\t\t\"@context\": AuditableItemGraphContexts.Context,\n\t\t\t\ttype: AuditableItemGraphTypes.Edge,\n\t\t\t\ttargetId: aigEdge.targetId,\n\t\t\t\tedgeRelationships: [\"document\"]\n\t\t\t}));\n\n\t\t\t// Resolve remove targetIds to stored edge IDs for the document vertex patch.\n\t\t\tconst documentEdgePatchesRemove: string[] = edgeTargetIdsToRemove\n\t\t\t\t.map(\n\t\t\t\t\ttargetId =>\n\t\t\t\t\t\tdocumentVertex.edges?.find(e => e.targetId === targetId && Is.empty(e.dateDeleted))?.id\n\t\t\t\t)\n\t\t\t\t.filter((id): id is string => Is.stringValue(id));\n\n\t\t\tif (resourcePatchesAdd.length > 0 || hasEdgeChanges) {\n\t\t\t\tconst partial: IAuditableItemGraphPartialVertex = {\n\t\t\t\t\t\"@context\": [\n\t\t\t\t\t\tAuditableItemGraphContexts.Context,\n\t\t\t\t\t\tAuditableItemGraphContexts.ContextCommon\n\t\t\t\t\t],\n\t\t\t\t\tid: auditableItemGraphDocumentId\n\t\t\t\t};\n\t\t\t\tif (resourcePatchesAdd.length > 0) {\n\t\t\t\t\tpartial.resourcePatches = { add: resourcePatchesAdd };\n\t\t\t\t}\n\t\t\t\tif (hasEdgeChanges) {\n\t\t\t\t\tpartial.edgePatches = {\n\t\t\t\t\t\t...(documentEdgePatchesAdd.length > 0 ? { add: documentEdgePatchesAdd } : {}),\n\t\t\t\t\t\t...(documentEdgePatchesRemove.length > 0 ? { remove: documentEdgePatchesRemove } : {})\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tawait this._auditableItemGraphComponent.updatePartial(partial);\n\t\t\t}\n\n\t\t\tif (hasEdgeChanges) {\n\t\t\t\tawait this.updateConnectedEdges(\n\t\t\t\t\tauditableItemGraphDocumentId,\n\t\t\t\t\tedgesToAdd,\n\t\t\t\t\tedgeTargetIdsToRemove,\n\t\t\t\t\tlatestRevision.documentId,\n\t\t\t\t\tlatestRevision.documentIdFormat\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst updatedVertex = resourcePatchesAdd.length > 0 || hasEdgeChanges;\n\t\t\tif (blobRevisionCreated) {\n\t\t\t\tawait MetricHelper.metricIncrement(\n\t\t\t\t\tthis._telemetryComponent,\n\t\t\t\t\tDocumentManagementMetricIds.RevisionsCreated,\n\t\t\t\t\t{ hasAttestation: newRevisionHasAttestation }\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (updatedVertex) {\n\t\t\t\tawait MetricHelper.metricIncrement(\n\t\t\t\t\tthis._telemetryComponent,\n\t\t\t\t\tDocumentManagementMetricIds.DocumentsUpdated,\n\t\t\t\t\t{ hasNewRevision: blobRevisionCreated }\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} finally {\n\t\t\tMutex.unlock(auditableItemGraphDocumentId);\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.includeDeletedEdges Flag to include soft-deleted edges in the response, 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\tincludeDeletedEdges?: 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{\n\t\t\t\t\tincludeDeleted:\n\t\t\t\t\t\t(options?.includeRemoved ?? false) || (options?.includeDeletedEdges ?? false)\n\t\t\t\t}\n\t\t\t);\n\n\t\t\t// If we fetched deleted items to expose edges but the caller did not ask for deleted\n\t\t\t// documents, strip the deleted resources so they don't appear in the output.\n\t\t\tif ((options?.includeDeletedEdges ?? false) && !(options?.includeRemoved ?? false)) {\n\t\t\t\tdocumentVertex.resources = documentVertex.resources?.filter(r => Is.empty(r.dateDeleted));\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.integer(DocumentManagementService.CLASS_NAME, nameof(revision), revision);\n\n\t\tawait Mutex.lock(auditableItemGraphDocumentId, { throwOnTimeout: true });\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\tconst revisionResourceId =\n\t\t\t\t(documentVertex.resources[docRevisionIndex].resourceObject?.id as string | undefined) ??\n\t\t\t\t(documentVertex.resources[docRevisionIndex].resourceObject?.[\"@id\"] as string | undefined);\n\n\t\t\tif (!Is.stringValue(revisionResourceId)) {\n\t\t\t\t// The revision exists but its stored resource-id is unresolvable — integrity anomaly.\n\t\t\t\tthrow new GeneralError(DocumentManagementService.CLASS_NAME, \"documentRevisionMissingId\", {\n\t\t\t\t\trevision\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tawait this._auditableItemGraphComponent.updatePartial({\n\t\t\t\t\"@context\": [AuditableItemGraphContexts.Context, AuditableItemGraphContexts.ContextCommon],\n\t\t\t\tid: auditableItemGraphDocumentId,\n\t\t\t\tresourcePatches: { remove: [revisionResourceId] }\n\t\t\t});\n\t\t\tawait MetricHelper.metricIncrement(\n\t\t\t\tthis._telemetryComponent,\n\t\t\t\tDocumentManagementMetricIds.RevisionsRemoved\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\"removeRevisionFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t} finally {\n\t\t\tMutex.unlock(auditableItemGraphDocumentId);\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 on connected vertices using non-destructive patch operations.\n\t * Uses updatePartial so AIG's per-vertex Mutex serialises concurrent callers.\n\t *\n\t * On the **create path** (`isCreatePath = true`) the method is fail-fast:\n\t * if any back-edge write fails (target vertex does not exist), all back-edges\n\t * already written in this call are removed (best-effort rollback) and the\n\t * failing target vertex ID is returned so the caller can surface a meaningful error.\n\t *\n\t * On the **update path** each missing vertex is caught individually; the remaining\n\t * updates continue and `undefined` is always returned.\n\t * @param auditableItemGraphDocumentId The document id to use.\n\t * @param edgesToAdd Connections to add — each connected vertex receives a new back-edge.\n\t * @param edgeTargetIdsToRemove Target vertex IDs to disconnect — their back-edges are removed.\n\t * @param documentId The document identifier.\n\t * @param documentIdFormat The format of the document identifier.\n\t * @param isCreatePath When true, enables fail-fast + rollback semantics.\n\t * @returns The failing target vertex ID when `isCreatePath` is true and a write fails;\n\t * `undefined` on success or when called from the update path.\n\t * @internal\n\t */\n\tprivate async updateConnectedEdges(\n\t\tauditableItemGraphDocumentId: string,\n\t\tedgesToAdd: IDocumentManagementEdgeEntry[],\n\t\tedgeTargetIdsToRemove: string[],\n\t\tdocumentId: string,\n\t\tdocumentIdFormat: string | undefined,\n\t\tisCreatePath: boolean = false\n\t): Promise<string | undefined> {\n\t\t// Track which target IDs received a successful back-edge write so we can roll back\n\t\t// if a later write fails (create path only).\n\t\tconst writtenTargetIds: string[] = [];\n\n\t\t// Add back-edges to each newly connected vertex.\n\t\tfor (const aigEdge of edgesToAdd) {\n\t\t\tconst partial: IAuditableItemGraphPartialVertex = {\n\t\t\t\t\"@context\": [AuditableItemGraphContexts.Context, AuditableItemGraphContexts.ContextCommon],\n\t\t\t\tid: aigEdge.targetId,\n\t\t\t\tedgePatches: {\n\t\t\t\t\tadd: [\n\t\t\t\t\t\t{\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\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tif (aigEdge.addAlias) {\n\t\t\t\tpartial.aliasPatches = {\n\t\t\t\t\tadd: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"@context\": AuditableItemGraphContexts.Context,\n\t\t\t\t\t\t\ttype: AuditableItemGraphTypes.Alias,\n\t\t\t\t\t\t\tid: documentId,\n\t\t\t\t\t\t\taliasFormat: documentIdFormat,\n\t\t\t\t\t\t\tannotationObject: aigEdge.aliasAnnotationObject\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\tif (isCreatePath) {\n\t\t\t\ttry {\n\t\t\t\t\tawait this._auditableItemGraphComponent.updatePartial(partial);\n\t\t\t\t\twrittenTargetIds.push(aigEdge.targetId);\n\t\t\t\t} catch {\n\t\t\t\t\t// Rollback all back-edges already written before this failure.\n\t\t\t\t\tawait this.rollbackConnectedEdges(\n\t\t\t\t\t\tauditableItemGraphDocumentId,\n\t\t\t\t\t\twrittenTargetIds,\n\t\t\t\t\t\tdocumentId\n\t\t\t\t\t);\n\t\t\t\t\treturn aigEdge.targetId;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tawait this._auditableItemGraphComponent.updatePartial(partial);\n\t\t\t\t} catch {\n\t\t\t\t\t// Best-effort on the update path — swallow to avoid interrupting remaining back-edge writes.\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Remove back-edges from disconnected vertices.\n\t\tfor (const staleTargetId of edgeTargetIdsToRemove) {\n\t\t\t// Fetch to resolve the stored edge ID; the write is still Mutex-protected.\n\t\t\tconst connected = await this._auditableItemGraphComponent.get(staleTargetId);\n\n\t\t\tconst edgeId = connected.edges?.find(\n\t\t\t\te => Is.empty(e.dateDeleted) && e.targetId === auditableItemGraphDocumentId\n\t\t\t)?.id;\n\n\t\t\tconst hasAlias =\n\t\t\t\tIs.arrayValue(connected.aliases) &&\n\t\t\t\tconnected.aliases.some(a => Is.empty(a.dateDeleted) && a.id === documentId);\n\n\t\t\tconst partial: IAuditableItemGraphPartialVertex = {\n\t\t\t\t\"@context\": [AuditableItemGraphContexts.Context, AuditableItemGraphContexts.ContextCommon],\n\t\t\t\tid: staleTargetId\n\t\t\t};\n\n\t\t\tif (hasAlias) {\n\t\t\t\tpartial.aliasPatches = { remove: [documentId] };\n\t\t\t}\n\n\t\t\tif (Is.stringValue(edgeId)) {\n\t\t\t\tpartial.edgePatches = { remove: [edgeId] };\n\t\t\t}\n\n\t\t\tif (hasAlias || Is.stringValue(edgeId)) {\n\t\t\t\tawait this._auditableItemGraphComponent.updatePartial(partial);\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Best-effort removal of back-edges that were written during a failed create operation.\n\t * Errors are silently swallowed to avoid masking the original failure.\n\t * @param auditableItemGraphDocumentId The document vertex whose back-edges should be removed.\n\t * @param targetIds The connected vertex IDs that received a back-edge.\n\t * @param documentId The document identifier used for alias cleanup.\n\t * @internal\n\t */\n\tprivate async rollbackConnectedEdges(\n\t\tauditableItemGraphDocumentId: string,\n\t\ttargetIds: string[],\n\t\tdocumentId: string\n\t): Promise<void> {\n\t\tfor (const targetId of targetIds) {\n\t\t\ttry {\n\t\t\t\tconst connected = await this._auditableItemGraphComponent.get(targetId);\n\n\t\t\t\tconst edgeId = connected.edges?.find(\n\t\t\t\t\te => Is.empty(e.dateDeleted) && e.targetId === auditableItemGraphDocumentId\n\t\t\t\t)?.id;\n\n\t\t\t\tconst hasAlias =\n\t\t\t\t\tIs.arrayValue(connected.aliases) &&\n\t\t\t\t\tconnected.aliases.some(a => Is.empty(a.dateDeleted) && a.id === documentId);\n\n\t\t\t\tconst partial: IAuditableItemGraphPartialVertex = {\n\t\t\t\t\t\"@context\": [\n\t\t\t\t\t\tAuditableItemGraphContexts.Context,\n\t\t\t\t\t\tAuditableItemGraphContexts.ContextCommon\n\t\t\t\t\t],\n\t\t\t\t\tid: targetId\n\t\t\t\t};\n\n\t\t\t\tif (hasAlias) {\n\t\t\t\t\tpartial.aliasPatches = { remove: [documentId] };\n\t\t\t\t}\n\n\t\t\t\tif (Is.stringValue(edgeId)) {\n\t\t\t\t\tpartial.edgePatches = { remove: [edgeId] };\n\t\t\t\t}\n\n\t\t\t\tif (hasAlias || Is.stringValue(edgeId)) {\n\t\t\t\t\tawait this._auditableItemGraphComponent.updatePartial(partial);\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// Best-effort — do not let cleanup errors mask the original failure.\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.includeDeletedEdges Flag to include soft-deleted edges in the response, 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\tincludeDeletedEdges?: 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 (\n\t\t\t\t\tIs.object(edge) &&\n\t\t\t\t\t((options?.includeDeletedEdges ?? false) || Is.empty(edge.dateDeleted))\n\t\t\t\t) {\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\tconst attestationId = await this._attestationComponent.create(documentAttestation);\n\t\tawait MetricHelper.metricIncrement(\n\t\t\tthis._telemetryComponent,\n\t\t\tDocumentManagementMetricIds.AttestationsCreated\n\t\t);\n\t\treturn attestationId;\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 +1 @@
1
- {"version":3,"file":"IDocumentManagementStorageServiceConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IDocumentManagementStorageServiceConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IDocumentManagementServiceConfig } from \"./IDocumentManagementServiceConfig.js\";\n\n/**\n * Options for the document management Service constructor.\n */\nexport interface IDocumentManagementServiceConstructorOptions {\n\t/**\n\t * The type of the auditable item graph component.\n\t * @default auditable-item-graph\n\t */\n\tauditableItemGraphComponentType?: string;\n\n\t/**\n\t * The type of the blob storage component.\n\t * @default blob-storage\n\t */\n\tblobStorageComponentType?: string;\n\n\t/**\n\t * The type of the attestation component.\n\t * @default attestation\n\t */\n\tattestationComponentType?: string;\n\n\t/**\n\t * The type of the data processing component.\n\t * @default data-processing\n\t */\n\tdataProcessingComponentType?: string;\n\n\t/**\n\t * The configuration for the service.\n\t */\n\tconfig?: IDocumentManagementServiceConfig;\n}\n"]}
1
+ {"version":3,"file":"IDocumentManagementStorageServiceConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IDocumentManagementStorageServiceConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IDocumentManagementServiceConfig } from \"./IDocumentManagementServiceConfig.js\";\n\n/**\n * Options for the document management Service constructor.\n */\nexport interface IDocumentManagementServiceConstructorOptions {\n\t/**\n\t * The type of the auditable item graph component.\n\t * @default auditable-item-graph\n\t */\n\tauditableItemGraphComponentType?: string;\n\n\t/**\n\t * The type of the blob storage component.\n\t * @default blob-storage\n\t */\n\tblobStorageComponentType?: string;\n\n\t/**\n\t * The type of the attestation component.\n\t * @default attestation\n\t */\n\tattestationComponentType?: string;\n\n\t/**\n\t * The type of the data processing component.\n\t * @default data-processing\n\t */\n\tdataProcessingComponentType?: string;\n\n\t/**\n\t * The type of the telemetry component used for event metrics.\n\t */\n\ttelemetryComponentType?: string;\n\n\t/**\n\t * The configuration for the service.\n\t */\n\tconfig?: IDocumentManagementServiceConfig;\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { ICreatedResponse, IHttpRequestContext, INoContentResponse, IRestRoute, ITag } from "@twin.org/api-models";
2
- import { type IDocumentManagementGetRevisionRequest, type IDocumentManagementGetRevisionResponse, type IDocumentManagementCreateRequest, type IDocumentManagementGetRequest, type IDocumentManagementGetResponse, type IDocumentManagementQueryRequest, type IDocumentManagementQueryResponse, type IDocumentManagementRemoveRequest, type IDocumentManagementUpdateRequest } from "@twin.org/document-management-models";
2
+ import { type IDocumentManagementGetRevisionRequest, type IDocumentManagementGetRevisionResponse, type IDocumentManagementCreateRequest, type IDocumentManagementGetRequest, type IDocumentManagementGetResponse, type IDocumentManagementQueryRequest, type IDocumentManagementQueryResponse, type IDocumentManagementRemoveRequest, type IDocumentManagementUpdatePartialRequest } from "@twin.org/document-management-models";
3
3
  /**
4
4
  * The tag to associate with the routes.
5
5
  */
@@ -42,7 +42,7 @@ export declare function documentManagementGetRevision(httpRequestContext: IHttpR
42
42
  * @param request The request.
43
43
  * @returns The response object with additional http response properties.
44
44
  */
45
- export declare function documentManagementUpdate(httpRequestContext: IHttpRequestContext, componentName: string, request: IDocumentManagementUpdateRequest): Promise<INoContentResponse>;
45
+ export declare function documentManagementUpdatePartial(httpRequestContext: IHttpRequestContext, componentName: string, request: IDocumentManagementUpdatePartialRequest): Promise<INoContentResponse>;
46
46
  /**
47
47
  * Remove the document from the auditable item graph vertex.
48
48
  * @param httpRequestContext The request context for the API.
@@ -1,6 +1,6 @@
1
1
  import { type IAuditableItemGraphVertexList } from "@twin.org/auditable-item-graph-models";
2
2
  import { type IJsonLdNodeObject } from "@twin.org/data-json-ld";
3
- import { type IDocument, type IDocumentList, type IDocumentManagementComponent } from "@twin.org/document-management-models";
3
+ import { type IDocumentManagementEdgeEntry, type IDocument, type IDocumentList, type IDocumentManagementComponent } from "@twin.org/document-management-models";
4
4
  import { UneceDocumentCodeList } from "@twin.org/standards-unece";
5
5
  import type { IDocumentManagementServiceConstructorOptions } from "./models/IDocumentManagementStorageServiceConstructorOptions.js";
6
6
  /**
@@ -21,6 +21,10 @@ export declare class DocumentManagementService implements IDocumentManagementCom
21
21
  * @returns The class name of the component.
22
22
  */
23
23
  className(): string;
24
+ /**
25
+ * Register all document management metrics with the telemetry component.
26
+ */
27
+ start(): Promise<void>;
24
28
  /**
25
29
  * Store a document as an auditable item graph vertex and add its content to blob storage.
26
30
  * If the document id already exists and the blob data is different a new revision will be created.
@@ -37,11 +41,7 @@ export declare class DocumentManagementService implements IDocumentManagementCom
37
41
  * @param options.aliasAnnotationObject Annotation object for the alias.
38
42
  * @returns The auditable item graph vertex created for the document including its revision.
39
43
  */
40
- create(documentId: string, documentIdFormat: string | undefined, documentCode: UneceDocumentCodeList, blob: Uint8Array, annotationObject?: IJsonLdNodeObject, auditableItemGraphEdges?: {
41
- targetId: string;
42
- addAlias?: boolean;
43
- aliasAnnotationObject?: IJsonLdNodeObject;
44
- }[], options?: {
44
+ create(documentId: string, documentIdFormat: string | undefined, documentCode: UneceDocumentCodeList, blob: Uint8Array, annotationObject?: IJsonLdNodeObject, auditableItemGraphEdges?: IDocumentManagementEdgeEntry[], options?: {
45
45
  createAttestation?: boolean;
46
46
  addAlias?: boolean;
47
47
  aliasAnnotationObject?: IJsonLdNodeObject;
@@ -53,14 +53,19 @@ export declare class DocumentManagementService implements IDocumentManagementCom
53
53
  * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
54
54
  * @param blob The data to update the document with.
55
55
  * @param annotationObject Additional information to associate with the document.
56
- * @param auditableItemGraphEdges The auditable item graph vertices to connect the document to, if undefined retains current connections.
56
+ * @param auditableItemGraphEdges Explicit edge delta to apply. If undefined, existing connections
57
+ * are retained unchanged. Use `add` to create new connections and `remove` to disconnect existing
58
+ * ones by their target vertex id. To update alias metadata on an already-connected vertex, include
59
+ * it in `add` with the updated `aliasAnnotationObject` — AIG's alias patch is an upsert, so the
60
+ * alias is updated in place without creating a duplicate back-edge.
61
+ * @param auditableItemGraphEdges.add Connections to add; each creates a back-edge on the connected vertex.
62
+ * @param auditableItemGraphEdges.remove Target vertex IDs to disconnect; their back-edges are removed.
57
63
  * @returns Nothing.
58
64
  */
59
- update(auditableItemGraphDocumentId: string, blob?: Uint8Array, annotationObject?: IJsonLdNodeObject, auditableItemGraphEdges?: {
60
- targetId: string;
61
- addAlias?: boolean;
62
- aliasAnnotationObject?: IJsonLdNodeObject;
63
- }[]): Promise<void>;
65
+ updatePartial(auditableItemGraphDocumentId: string, blob?: Uint8Array, annotationObject?: IJsonLdNodeObject, auditableItemGraphEdges?: {
66
+ add?: IDocumentManagementEdgeEntry[];
67
+ remove?: string[];
68
+ }): Promise<void>;
64
69
  /**
65
70
  * Get a document using it's auditable item graph vertex id and optional revision.
66
71
  * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
@@ -69,6 +74,7 @@ export declare class DocumentManagementService implements IDocumentManagementCom
69
74
  * @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.
70
75
  * @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.
71
76
  * @param options.includeRemoved Flag to include deleted documents, defaults to false.
77
+ * @param options.includeDeletedEdges Flag to include soft-deleted edges in the response, defaults to false.
72
78
  * @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.
73
79
  * @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.
74
80
  * @param cursor The cursor to get the next chunk of revisions.
@@ -80,6 +86,7 @@ export declare class DocumentManagementService implements IDocumentManagementCom
80
86
  includeBlobStorageData?: boolean;
81
87
  includeAttestation?: boolean;
82
88
  includeRemoved?: boolean;
89
+ includeDeletedEdges?: boolean;
83
90
  extractRuleGroupId?: string;
84
91
  extractMimeType?: string;
85
92
  }, cursor?: string, limit?: number): Promise<{
@@ -23,6 +23,10 @@ export interface IDocumentManagementServiceConstructorOptions {
23
23
  * @default data-processing
24
24
  */
25
25
  dataProcessingComponentType?: string;
26
+ /**
27
+ * The type of the telemetry component used for event metrics.
28
+ */
29
+ telemetryComponentType?: string;
26
30
  /**
27
31
  * The configuration for the service.
28
32
  */
package/docs/changelog.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.16](https://github.com/iotaledger/twin-document-management/compare/document-management-service-v0.0.3-next.15...document-management-service-v0.0.3-next.16) (2026-06-04)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * replace destructive update() with updatePartial() for edge linking ([#50](https://github.com/iotaledger/twin-document-management/issues/50)) ([c1d2c33](https://github.com/iotaledger/twin-document-management/commit/c1d2c337c371bdcc1f23cac482393468ef84f0d7))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/document-management-models bumped from 0.0.3-next.15 to 0.0.3-next.16
16
+
17
+ ## [0.0.3-next.15](https://github.com/iotaledger/twin-document-management/compare/document-management-service-v0.0.3-next.14...document-management-service-v0.0.3-next.15) (2026-05-22)
18
+
19
+
20
+ ### Features
21
+
22
+ * add event-driven telemetry metrics ([#46](https://github.com/iotaledger/twin-document-management/issues/46)) ([2cc4933](https://github.com/iotaledger/twin-document-management/commit/2cc49338a05972279ee8e68027506a796e96766e))
23
+
24
+
25
+ ### Dependencies
26
+
27
+ * The following workspace dependencies were updated
28
+ * dependencies
29
+ * @twin.org/document-management-models bumped from 0.0.3-next.14 to 0.0.3-next.15
30
+
3
31
  ## [0.0.3-next.14](https://github.com/iotaledger/twin-document-management/compare/document-management-service-v0.0.3-next.13...document-management-service-v0.0.3-next.14) (2026-05-20)
4
32
 
5
33
 
@@ -317,16 +317,16 @@
317
317
  }
318
318
  },
319
319
  "/document-management/{auditableItemGraphDocumentId}": {
320
- "put": {
321
- "operationId": "DocumentManagementUpdate",
322
- "summary": "Update a document in an auditable item graph vertex and add its content to blob storage.",
320
+ "patch": {
321
+ "operationId": "DocumentManagementUpdatePartial",
322
+ "summary": "Partially update a document in an auditable item graph vertex and add its content to blob storage.",
323
323
  "tags": [
324
324
  "Document Management"
325
325
  ],
326
326
  "parameters": [
327
327
  {
328
328
  "name": "auditableItemGraphDocumentId",
329
- "description": "The full id of the document to get.",
329
+ "description": "The full id of the document to update.",
330
330
  "in": "path",
331
331
  "required": true,
332
332
  "schema": {
@@ -342,15 +342,15 @@
342
342
  }
343
343
  ],
344
344
  "requestBody": {
345
- "description": "Request to update a document as an auditable item graph vertex.",
345
+ "description": "Request to partially update a document as an auditable item graph vertex.",
346
346
  "required": true,
347
347
  "content": {
348
348
  "application/json": {
349
349
  "schema": {
350
- "$ref": "#/components/schemas/DocumentManagementUpdateRequest"
350
+ "$ref": "#/components/schemas/DocumentManagementUpdatePartialRequest"
351
351
  },
352
352
  "examples": {
353
- "DocumentManagementUpdateRequestExample": {
353
+ "DocumentManagementUpdatePartialRequestExample": {
354
354
  "value": {
355
355
  "blob": "SGVsbG8gV29ybGQ=",
356
356
  "annotationObject": {
@@ -481,6 +481,15 @@
481
481
  "type": "string"
482
482
  }
483
483
  },
484
+ {
485
+ "name": "includeDeletedEdges",
486
+ "description": "Include soft-deleted edges in the response.",
487
+ "in": "query",
488
+ "required": false,
489
+ "schema": {
490
+ "type": "string"
491
+ }
492
+ },
484
493
  {
485
494
  "name": "extractRuleGroupId",
486
495
  "description": "If provided will extract data from the document using the specified rule group id.",
@@ -1187,21 +1196,7 @@
1187
1196
  "auditableItemGraphEdges": {
1188
1197
  "type": "array",
1189
1198
  "items": {
1190
- "type": "object",
1191
- "properties": {
1192
- "targetId": {
1193
- "type": "string"
1194
- },
1195
- "addAlias": {
1196
- "type": "boolean"
1197
- },
1198
- "aliasAnnotationObject": {
1199
- "$ref": "https://schema.twindev.org/json-ld/JsonLdNodeObject"
1200
- }
1201
- },
1202
- "required": [
1203
- "targetId"
1204
- ]
1199
+ "$ref": "#/components/schemas/DocumentManagementEdgeEntry"
1205
1200
  },
1206
1201
  "description": "The auditable item graph vertices to connect the document to."
1207
1202
  },
@@ -1225,36 +1220,55 @@
1225
1220
  ],
1226
1221
  "description": "The body parameters."
1227
1222
  },
1228
- "DocumentManagementUpdateRequest": {
1223
+ "DocumentManagementEdgeEntry": {
1224
+ "description": "A single edge entry used when connecting a document to an AIG vertex.",
1225
+ "type": "object",
1226
+ "properties": {
1227
+ "targetId": {
1228
+ "type": "string",
1229
+ "description": "The target AIG vertex id to connect to."
1230
+ },
1231
+ "addAlias": {
1232
+ "type": "boolean",
1233
+ "description": "Whether to add the document id as an alias on the connected vertex, defaults to false."
1234
+ },
1235
+ "aliasAnnotationObject": {
1236
+ "$ref": "https://schema.twindev.org/json-ld/JsonLdNodeObject"
1237
+ }
1238
+ },
1239
+ "required": [
1240
+ "targetId"
1241
+ ]
1242
+ },
1243
+ "DocumentManagementUpdatePartialRequest": {
1229
1244
  "type": "object",
1230
1245
  "properties": {
1231
1246
  "blob": {
1232
1247
  "type": "string",
1233
- "description": "The data to create the document with, in base64."
1248
+ "description": "The data to update the document with, in base64."
1234
1249
  },
1235
1250
  "annotationObject": {
1236
1251
  "$ref": "https://schema.twindev.org/json-ld/JsonLdNodeObject"
1237
1252
  },
1238
1253
  "auditableItemGraphEdges": {
1239
- "type": "array",
1240
- "items": {
1241
- "type": "object",
1242
- "properties": {
1243
- "targetId": {
1244
- "type": "string"
1245
- },
1246
- "addAlias": {
1247
- "type": "boolean"
1254
+ "type": "object",
1255
+ "properties": {
1256
+ "add": {
1257
+ "type": "array",
1258
+ "items": {
1259
+ "$ref": "#/components/schemas/DocumentManagementEdgeEntry"
1248
1260
  },
1249
- "aliasAnnotationObject": {
1250
- "$ref": "https://schema.twindev.org/json-ld/JsonLdNodeObject"
1251
- }
1261
+ "description": "Connections to add; each entry creates a back-edge on the connected vertex."
1252
1262
  },
1253
- "required": [
1254
- "targetId"
1255
- ]
1263
+ "remove": {
1264
+ "type": "array",
1265
+ "items": {
1266
+ "type": "string"
1267
+ },
1268
+ "description": "Target vertex IDs to disconnect; their back-edges are removed."
1269
+ }
1256
1270
  },
1257
- "description": "The auditable item graph vertices to connect the document to."
1271
+ "description": "Explicit edge delta to apply. Use `add` to create new connections and `remove` to\ndisconnect existing ones by their target vertex id."
1258
1272
  }
1259
1273
  },
1260
1274
  "description": "The body parameters."