@twin.org/document-management-service 0.0.3-next.10 → 0.0.3-next.12
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.
- package/README.md +1 -1
- package/dist/es/documentManagementService.js +6 -3
- package/dist/es/documentManagementService.js.map +1 -1
- package/docs/changelog.md +29 -1
- package/docs/examples.md +121 -1
- package/docs/open-api/spec.json +33 -71
- package/docs/reference/classes/DocumentManagementService.md +10 -10
- package/docs/reference/interfaces/IDocumentManagementServiceConstructorOptions.md +10 -10
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# TWIN Document Management Service
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package delivers the service-side implementation for document lifecycle operations, including create, update, revision access, and search behaviour. It also exposes REST route generation so APIs can present a consistent contract for document handling.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -82,7 +82,10 @@ export class DocumentManagementService {
|
|
|
82
82
|
connectedVertices[edge.targetId] = await this._auditableItemGraphComponent.get(edge.targetId);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
const documentVertex = {
|
|
85
|
+
const documentVertex = {
|
|
86
|
+
"@context": [AuditableItemGraphContexts.Context, AuditableItemGraphContexts.ContextCommon],
|
|
87
|
+
type: AuditableItemGraphTypes.Vertex
|
|
88
|
+
};
|
|
86
89
|
if (options?.addAlias ?? true) {
|
|
87
90
|
documentVertex.aliases ??= [];
|
|
88
91
|
documentVertex.aliases.push({
|
|
@@ -127,7 +130,7 @@ export class DocumentManagementService {
|
|
|
127
130
|
// Add the edges from the document to the items
|
|
128
131
|
this.updateEdges(documentVertex, auditableItemGraphEdges);
|
|
129
132
|
// And create the vertex
|
|
130
|
-
const vertexId = await this._auditableItemGraphComponent.create(documentVertex);
|
|
133
|
+
const vertexId = await this._auditableItemGraphComponent.create(ObjectHelper.removeEmptyProperties(documentVertex));
|
|
131
134
|
// Now add the edges to the connected vertices
|
|
132
135
|
await this.updateConnectedEdges(connectedVertices, vertexId, [], auditableItemGraphEdges, documentId, documentIdFormat);
|
|
133
136
|
return vertexId;
|
|
@@ -219,7 +222,7 @@ export class DocumentManagementService {
|
|
|
219
222
|
updatedVertex = true;
|
|
220
223
|
}
|
|
221
224
|
if (updatedVertex) {
|
|
222
|
-
await this._auditableItemGraphComponent.update(documentVertex);
|
|
225
|
+
await this._auditableItemGraphComponent.update(ObjectHelper.removeEmptyProperties(documentVertex));
|
|
223
226
|
}
|
|
224
227
|
if (edgesUpdated) {
|
|
225
228
|
await this.updateConnectedEdges(connectedVertices, auditableItemGraphDocumentId, existingEdgeIds, auditableItemGraphEdges, latestRevision.documentId, latestRevision.documentIdFormat);
|
|
@@ -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;;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-Identifier: Apache-2.0.\nimport type { IAttestationComponent } from \"@twin.org/attestation-models\";\nimport {\n\tAuditableItemGraphContexts,\n\tAuditableItemGraphTypes,\n\ttype IAuditableItemGraphVertexList,\n\ttype IAuditableItemGraphAlias,\n\ttype IAuditableItemGraphComponent,\n\ttype IAuditableItemGraphEdge,\n\ttype IAuditableItemGraphVertex\n} from \"@twin.org/auditable-item-graph-models\";\nimport type { IBlobStorageComponent } from \"@twin.org/blob-storage-models\";\nimport { BlobStorageContexts } from \"@twin.org/blob-storage-models\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport {\n\tBaseError,\n\tCoerce,\n\tComponentFactory,\n\tConverter,\n\tGeneralError,\n\tGuards,\n\tIs,\n\tNotFoundError,\n\tObjectHelper,\n\tUrn\n} from \"@twin.org/core\";\nimport { IntegrityAlgorithm, IntegrityHelper, Sha256 } from \"@twin.org/crypto\";\nimport { JsonLdProcessor, type IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport type { IDataProcessingComponent } from \"@twin.org/data-processing-models\";\nimport {\n\tDocumentContexts,\n\tDocumentTypes,\n\ttype IDocument,\n\ttype IDocumentAttestation,\n\ttype IDocumentList,\n\ttype IDocumentManagementComponent\n} from \"@twin.org/document-management-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tSchemaOrgContexts,\n\tSchemaOrgDataTypes,\n\tSchemaOrgTypes\n} from \"@twin.org/standards-schema-org\";\nimport { UneceDocumentCodeList } from \"@twin.org/standards-unece\";\nimport type { IDocumentManagementServiceConstructorOptions } from \"./models/IDocumentManagementStorageServiceConstructorOptions.js\";\n\n/**\n * Service for performing document management operations.\n */\nexport class DocumentManagementService implements IDocumentManagementComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<DocumentManagementService>();\n\n\t/**\n\t * The component for the auditable item graph.\n\t * @internal\n\t */\n\tprivate readonly _auditableItemGraphComponent: IAuditableItemGraphComponent;\n\n\t/**\n\t * The connector for the blob component.\n\t * @internal\n\t */\n\tprivate readonly _blobStorageComponent: IBlobStorageComponent;\n\n\t/**\n\t * The connector for the attestation.\n\t * @internal\n\t */\n\tprivate readonly _attestationComponent: IAttestationComponent;\n\n\t/**\n\t * The connector for the data processing.\n\t * @internal\n\t */\n\tprivate readonly _dataProcessingComponent: IDataProcessingComponent;\n\n\t/**\n\t * Create a new instance of DocumentManagementService.\n\t * @param options The options for the service.\n\t */\n\tconstructor(options?: IDocumentManagementServiceConstructorOptions) {\n\t\tthis._auditableItemGraphComponent = ComponentFactory.get<IAuditableItemGraphComponent>(\n\t\t\toptions?.auditableItemGraphComponentType ?? \"auditable-item-graph\"\n\t\t);\n\t\tthis._blobStorageComponent = ComponentFactory.get<IBlobStorageComponent>(\n\t\t\toptions?.blobStorageComponentType ?? \"blob-storage\"\n\t\t);\n\t\tthis._attestationComponent = ComponentFactory.get<IAttestationComponent>(\n\t\t\toptions?.attestationComponentType ?? \"attestation\"\n\t\t);\n\t\tthis._dataProcessingComponent = ComponentFactory.get<IDataProcessingComponent>(\n\t\t\toptions?.dataProcessingComponentType ?? \"data-processing\"\n\t\t);\n\n\t\tSchemaOrgDataTypes.registerRedirects();\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn DocumentManagementService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Store a document as an auditable item graph vertex and add its content to blob storage.\n\t * If the document id already exists and the blob data is different a new revision will be created.\n\t * For any other changes the current revision will be updated.\n\t * @param documentId The document id to create.\n\t * @param documentIdFormat The format of the document identifier.\n\t * @param documentCode The code for the document type.\n\t * @param blob The data to create the document with.\n\t * @param annotationObject Additional information to associate with the document.\n\t * @param auditableItemGraphEdges The auditable item graph vertices to connect the document to.\n\t * @param options Additional options for the set operation.\n\t * @param options.createAttestation Flag to create an attestation for the document, defaults to false.\n\t * @param options.addAlias Flag to add the document id as an alias to the aig vertex, defaults to true.\n\t * @param options.aliasAnnotationObject Annotation object for the alias.\n\t * @returns The auditable item graph vertex created for the document including its revision.\n\t */\n\tpublic async create(\n\t\tdocumentId: string,\n\t\tdocumentIdFormat: string | undefined,\n\t\tdocumentCode: UneceDocumentCodeList,\n\t\tblob: Uint8Array,\n\t\tannotationObject?: IJsonLdNodeObject,\n\t\tauditableItemGraphEdges?: {\n\t\t\ttargetId: string;\n\t\t\taddAlias?: boolean;\n\t\t\taliasAnnotationObject?: IJsonLdNodeObject;\n\t\t}[],\n\t\toptions?: {\n\t\t\tcreateAttestation?: boolean;\n\t\t\taddAlias?: boolean;\n\t\t\taliasAnnotationObject?: IJsonLdNodeObject;\n\t\t}\n\t): Promise<string> {\n\t\tGuards.stringValue(DocumentManagementService.CLASS_NAME, nameof(documentId), documentId);\n\t\tGuards.arrayOneOf(\n\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\tnameof(documentCode),\n\t\t\tdocumentCode,\n\t\t\tObject.values(UneceDocumentCodeList)\n\t\t);\n\t\tGuards.uint8Array(DocumentManagementService.CLASS_NAME, nameof(blob), blob);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\n\t\ttry {\n\t\t\t// Get the connected vertices first, if one fails we abort the create\n\t\t\tconst connectedVertices: { [id: string]: IAuditableItemGraphVertex } = {};\n\t\t\tif (Is.arrayValue(auditableItemGraphEdges)) {\n\t\t\t\tfor (const edge of auditableItemGraphEdges) {\n\t\t\t\t\tconnectedVertices[edge.targetId] = await this._auditableItemGraphComponent.get(\n\t\t\t\t\t\tedge.targetId\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst documentVertex: Omit<IAuditableItemGraphVertex, \"@context\" | \"id\" | \"type\"> = {};\n\n\t\t\tif (options?.addAlias ?? true) {\n\t\t\t\tdocumentVertex.aliases ??= [];\n\t\t\t\tdocumentVertex.aliases.push({\n\t\t\t\t\t\"@context\": AuditableItemGraphContexts.Context,\n\t\t\t\t\ttype: AuditableItemGraphTypes.Alias,\n\t\t\t\t\tid: documentId,\n\t\t\t\t\taliasFormat: documentIdFormat,\n\t\t\t\t\tannotationObject: options?.aliasAnnotationObject\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Add the blob to blob storage\n\t\t\tconst blobStorageId = await this._blobStorageComponent.create(Converter.bytesToBase64(blob));\n\n\t\t\tconst currentRevision: IDocument & IJsonLdNodeObject = {\n\t\t\t\t\"@context\": [\n\t\t\t\t\tSchemaOrgContexts.Context,\n\t\t\t\t\tDocumentContexts.Context,\n\t\t\t\t\tDocumentContexts.ContextCommon\n\t\t\t\t],\n\t\t\t\ttype: DocumentTypes.Document,\n\t\t\t\tid: this.createDocumentId(documentId, 0),\n\t\t\t\tdocumentId,\n\t\t\t\tdocumentIdFormat,\n\t\t\t\tdocumentCode,\n\t\t\t\tdocumentRevision: 0,\n\t\t\t\tannotationObject,\n\t\t\t\tintegrity: IntegrityHelper.generate(IntegrityAlgorithm.Sha256, blob),\n\t\t\t\tblobStorageId,\n\t\t\t\tdateCreated: new Date(Date.now()).toISOString(),\n\t\t\t\torganizationIdentity: contextIds?.[ContextIdKeys.Organization],\n\t\t\t\tuserIdentity: contextIds?.[ContextIdKeys.User]\n\t\t\t};\n\n\t\t\tif (options?.createAttestation ?? false) {\n\t\t\t\tcurrentRevision.attestationId = await this.createAttestation(currentRevision);\n\t\t\t}\n\n\t\t\t// Add the new revision in to the vertex\n\t\t\tdocumentVertex.resources ??= [];\n\t\t\tdocumentVertex.resources.push({\n\t\t\t\t\"@context\": AuditableItemGraphContexts.Context,\n\t\t\t\ttype: AuditableItemGraphTypes.Resource,\n\t\t\t\tresourceObject: currentRevision\n\t\t\t});\n\n\t\t\t// Add the edges from the document to the items\n\t\t\tthis.updateEdges(documentVertex, auditableItemGraphEdges);\n\n\t\t\t// And create the vertex\n\t\t\tconst vertexId = await this._auditableItemGraphComponent.create(documentVertex);\n\n\t\t\t// Now add the edges to the connected vertices\n\t\t\tawait this.updateConnectedEdges(\n\t\t\t\tconnectedVertices,\n\t\t\t\tvertexId,\n\t\t\t\t[],\n\t\t\t\tauditableItemGraphEdges,\n\t\t\t\tdocumentId,\n\t\t\t\tdocumentIdFormat\n\t\t\t);\n\n\t\t\treturn vertexId;\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorName(error, nameof<NotFoundError>())) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\t\t\"createFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Update a document as an auditable item graph vertex and add its content to blob storage.\n\t * If the blob data is different a new revision will be created.\n\t * For any other changes the current revision will be updated.\n\t * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.\n\t * @param blob The data to update the document with.\n\t * @param annotationObject Additional information to associate with the document.\n\t * @param auditableItemGraphEdges The auditable item graph vertices to connect the document to, if undefined retains current connections.\n\t * @returns Nothing.\n\t */\n\tpublic async update(\n\t\tauditableItemGraphDocumentId: string,\n\t\tblob?: Uint8Array,\n\t\tannotationObject?: IJsonLdNodeObject,\n\t\tauditableItemGraphEdges?: {\n\t\t\ttargetId: string;\n\t\t\taddAlias?: boolean;\n\t\t\taliasAnnotationObject?: IJsonLdNodeObject;\n\t\t}[]\n\t): Promise<void> {\n\t\tUrn.guard(\n\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\n\t\ttry {\n\t\t\tconst documentVertex = await this._auditableItemGraphComponent.get(\n\t\t\t\tauditableItemGraphDocumentId,\n\t\t\t\t{ includeDeleted: true }\n\t\t\t);\n\n\t\t\tif (Is.empty(documentVertex.resources)) {\n\t\t\t\tthrow new NotFoundError(DocumentManagementService.CLASS_NAME, \"documentRevisionNone\");\n\t\t\t}\n\n\t\t\tconst documents = await this.getDocumentsFromVertex(documentVertex);\n\t\t\tconst latestRevision: IDocument | undefined = documents.entries.itemListElement[0];\n\n\t\t\tdocumentVertex.resources = documentVertex.resources.filter(r => Is.empty(r.dateDeleted));\n\n\t\t\tif (Is.empty(latestRevision)) {\n\t\t\t\tthrow new NotFoundError(DocumentManagementService.CLASS_NAME, \"documentRevisionNone\");\n\t\t\t}\n\n\t\t\t// If auditableItemGraphEdges is undefined we are not updating the edges\n\t\t\t// an empty array can be passed to remove all edges\n\t\t\tconst connectedVertices: { [targetId: string]: IAuditableItemGraphVertex } = {};\n\t\t\tif (Is.array(auditableItemGraphEdges)) {\n\t\t\t\t// Get the updated connected vertices first, if one fails we abort the update\n\t\t\t\tfor (const edge of auditableItemGraphEdges) {\n\t\t\t\t\tconnectedVertices[edge.targetId] = await this._auditableItemGraphComponent.get(\n\t\t\t\t\t\tedge.targetId\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// Also get the current edges in case some need disconnecting\n\t\t\t\tif (Is.arrayValue(documents.entries.edges)) {\n\t\t\t\t\tfor (const edgeId of documents.entries.edges) {\n\t\t\t\t\t\t// If we haven't retrieved the edge then it must be one that needs removing\n\t\t\t\t\t\tif (Is.empty(connectedVertices[edgeId])) {\n\t\t\t\t\t\t\tconnectedVertices[edgeId] = await this._auditableItemGraphComponent.get(edgeId);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet updatedVertex = false;\n\n\t\t\t// If the blob is set and its hash has changed then we create a new revision\n\t\t\tif (Is.uint8Array(blob)) {\n\t\t\t\tconst newIntegrity = IntegrityHelper.generate(IntegrityAlgorithm.Sha256, blob);\n\n\t\t\t\tif (latestRevision.integrity !== newIntegrity) {\n\t\t\t\t\t// Add the blob to blob storage\n\t\t\t\t\tconst blobStorageId = await this._blobStorageComponent.create(\n\t\t\t\t\t\tConverter.bytesToBase64(blob)\n\t\t\t\t\t);\n\n\t\t\t\t\tconst newRevision = ObjectHelper.clone(latestRevision);\n\n\t\t\t\t\tnewRevision.documentRevision++;\n\t\t\t\t\tnewRevision.id = this.createDocumentId(\n\t\t\t\t\t\tnewRevision.documentId,\n\t\t\t\t\t\tnewRevision.documentRevision\n\t\t\t\t\t);\n\t\t\t\t\tnewRevision.integrity = newIntegrity;\n\t\t\t\t\tnewRevision.blobStorageId = blobStorageId;\n\t\t\t\t\tnewRevision.annotationObject = annotationObject;\n\n\t\t\t\t\tif (Is.stringValue(latestRevision.attestationId)) {\n\t\t\t\t\t\tnewRevision.attestationId = await this.createAttestation(newRevision);\n\t\t\t\t\t}\n\n\t\t\t\t\tdocumentVertex.resources.push({\n\t\t\t\t\t\t\"@context\": AuditableItemGraphContexts.Context,\n\t\t\t\t\t\ttype: AuditableItemGraphTypes.Resource,\n\t\t\t\t\t\tresourceObject: newRevision as unknown as IJsonLdNodeObject\n\t\t\t\t\t});\n\n\t\t\t\t\tupdatedVertex = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If the blob wasn't updated but the annotation object has then update the current revision\n\t\t\t// instead of creating a new one\n\t\t\tif (\n\t\t\t\t!updatedVertex &&\n\t\t\t\t!ObjectHelper.equal(latestRevision.annotationObject, annotationObject)\n\t\t\t) {\n\t\t\t\tupdatedVertex = true;\n\t\t\t\tlatestRevision.annotationObject = annotationObject;\n\t\t\t\tlatestRevision.dateModified = new Date(Date.now()).toISOString();\n\t\t\t}\n\n\t\t\tconst existingEdgeIds = documentVertex.edges?.map(e => e.targetId) ?? [];\n\n\t\t\t// Update the edges from the document to the items\n\t\t\tconst edgesUpdated = this.updateEdges(documentVertex, auditableItemGraphEdges);\n\t\t\tif (edgesUpdated) {\n\t\t\t\tupdatedVertex = true;\n\t\t\t}\n\n\t\t\tif (updatedVertex) {\n\t\t\t\tawait this._auditableItemGraphComponent.update(documentVertex);\n\t\t\t}\n\n\t\t\tif (edgesUpdated) {\n\t\t\t\tawait this.updateConnectedEdges(\n\t\t\t\t\tconnectedVertices,\n\t\t\t\t\tauditableItemGraphDocumentId,\n\t\t\t\t\texistingEdgeIds,\n\t\t\t\t\tauditableItemGraphEdges,\n\t\t\t\t\tlatestRevision.documentId,\n\t\t\t\t\tlatestRevision.documentIdFormat\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorName(error, nameof<NotFoundError>())) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\t\t\"updateFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Get a document using it's auditable item graph vertex id and optional revision.\n\t * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.\n\t * @param options Additional options for the get operation.\n\t * @param options.includeBlobStorageMetadata Flag to include the blob storage metadata for the document, defaults to false.\n\t * @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.\n\t * @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.\n\t * @param options.includeRemoved Flag to include deleted documents, defaults to false.\n\t * @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.\n\t * @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.\n\t * @param cursor The cursor to get the next chunk of revisions.\n\t * @param limit Limit the number of items to return, defaults to 1 so only most recent is returned.\n\t * @returns The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.\n\t */\n\tpublic async get(\n\t\tauditableItemGraphDocumentId: string,\n\t\toptions?: {\n\t\t\tincludeBlobStorageMetadata?: boolean;\n\t\t\tincludeBlobStorageData?: boolean;\n\t\t\tincludeAttestation?: boolean;\n\t\t\tincludeRemoved?: boolean;\n\t\t\textractRuleGroupId?: string;\n\t\t\textractMimeType?: string;\n\t\t},\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\tentries: IDocumentList;\n\t\tcursor?: string;\n\t}> {\n\t\tUrn.guard(\n\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\n\t\ttry {\n\t\t\tconst documentVertex = await this._auditableItemGraphComponent.get(\n\t\t\t\tauditableItemGraphDocumentId,\n\t\t\t\t{ includeDeleted: options?.includeRemoved }\n\t\t\t);\n\n\t\t\t// Populate the document and revisions with the options set\n\t\t\tconst documents = await this.getDocumentsFromVertex(documentVertex, options, cursor, limit);\n\n\t\t\tconst result = await JsonLdProcessor.compact(\n\t\t\t\tdocuments.entries,\n\t\t\t\tdocuments.entries[\"@context\"]\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tentries: result,\n\t\t\t\tcursor: documents.cursor\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorName(error, nameof<NotFoundError>())) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(DocumentManagementService.CLASS_NAME, \"getFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Get a document revision using it's auditable item graph vertex id.\n\t * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.\n\t * @param revision The revision id for the document.\n\t * @param options Additional options for the get operation.\n\t * @param options.includeBlobStorageMetadata Flag to include the blob storage metadata for the document, defaults to false.\n\t * @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.\n\t * @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.\n\t * @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.\n\t * @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.\n\t * @returns The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.\n\t */\n\tpublic async getRevision(\n\t\tauditableItemGraphDocumentId: string,\n\t\trevision: number,\n\t\toptions?: {\n\t\t\tincludeBlobStorageMetadata?: boolean;\n\t\t\tincludeBlobStorageData?: boolean;\n\t\t\tincludeAttestation?: boolean;\n\t\t\textractRuleGroupId?: string;\n\t\t\textractMimeType?: string;\n\t\t}\n\t): Promise<IDocument> {\n\t\tUrn.guard(\n\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\t\tGuards.integer(DocumentManagementService.CLASS_NAME, nameof(revision), revision);\n\n\t\ttry {\n\t\t\tconst documentVertex = await this._auditableItemGraphComponent.get(\n\t\t\t\tauditableItemGraphDocumentId,\n\t\t\t\t{ includeDeleted: true }\n\t\t\t);\n\n\t\t\tif (Is.empty(documentVertex.resources)) {\n\t\t\t\tthrow new NotFoundError(DocumentManagementService.CLASS_NAME, \"documentRevisionNone\");\n\t\t\t}\n\n\t\t\tdocumentVertex.resources = documentVertex.resources.filter(\n\t\t\t\td => d.resourceObject?.documentRevision === revision\n\t\t\t);\n\n\t\t\tif (documentVertex.resources.length === 0) {\n\t\t\t\tthrow new NotFoundError(\n\t\t\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\t\t\t\"documentRevisionNotFound\",\n\t\t\t\t\trevision.toString()\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Populate the document and revisions with the options set\n\t\t\tconst docList = await this.getDocumentsFromVertex(documentVertex, options);\n\n\t\t\tconst result = await JsonLdProcessor.compact(\n\t\t\t\tdocList.entries.itemListElement[0],\n\t\t\t\tdocList.entries.itemListElement[0][\"@context\"]\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorName(error, nameof<NotFoundError>())) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\t\t\"getRevisionFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Remove an auditable item graph vertex using it's id.\n\t * The document dateDeleted will be set, but can still be queried with the includeRemoved flag.\n\t * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.\n\t * @param revision The revision of the document to remove.\n\t * @returns Nothing.\n\t */\n\tpublic async removeRevision(\n\t\tauditableItemGraphDocumentId: string,\n\t\trevision: number\n\t): Promise<void> {\n\t\tUrn.guard(\n\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\t\tGuards.number(DocumentManagementService.CLASS_NAME, nameof(revision), revision);\n\n\t\ttry {\n\t\t\tconst documentVertex = await this._auditableItemGraphComponent.get(\n\t\t\t\tauditableItemGraphDocumentId\n\t\t\t);\n\n\t\t\tif (Is.empty(documentVertex.resources)) {\n\t\t\t\tthrow new NotFoundError(DocumentManagementService.CLASS_NAME, \"documentRevisionNone\");\n\t\t\t}\n\n\t\t\tconst docRevisionIndex = documentVertex.resources.findIndex(\n\t\t\t\td => d.resourceObject?.documentRevision === revision\n\t\t\t);\n\n\t\t\tif (docRevisionIndex === -1) {\n\t\t\t\tthrow new NotFoundError(\n\t\t\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\t\t\t\"documentRevisionNotFound\",\n\t\t\t\t\trevision.toString()\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tdocumentVertex.resources.splice(docRevisionIndex, 1);\n\n\t\t\tawait this._auditableItemGraphComponent.update(documentVertex);\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorName(error, nameof<NotFoundError>())) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(\n\t\t\t\tDocumentManagementService.CLASS_NAME,\n\t\t\t\t\"removeRevisionFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Find all the document with a specific id.\n\t * @param documentId The document id to find in the graph.\n\t * @param cursor The cursor to get the next chunk of documents.\n\t * @param limit The limit to get the next chunk of documents.\n\t * @returns The graph vertices that contain documents referencing the specified document id.\n\t */\n\tpublic async query(\n\t\tdocumentId: string,\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\tentries: IAuditableItemGraphVertexList;\n\t\tcursor?: string;\n\t}> {\n\t\tGuards.stringValue(DocumentManagementService.CLASS_NAME, nameof(documentId), documentId);\n\n\t\ttry {\n\t\t\tconst result = await this._auditableItemGraphComponent.query(\n\t\t\t\t{\n\t\t\t\t\tid: documentId,\n\t\t\t\t\tidMode: \"both\",\n\t\t\t\t\tresourceTypes: [DocumentTypes.Document]\n\t\t\t\t},\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[\"id\", \"dateCreated\", \"dateModified\", \"aliases\", \"annotationObject\", \"resources\", \"edges\"],\n\t\t\t\tcursor,\n\t\t\t\tlimit\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tif (BaseError.someErrorName(error, nameof<NotFoundError>())) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new GeneralError(DocumentManagementService.CLASS_NAME, \"queryFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Update the edges of the document vertex.\n\t * @param documentVertex The document vertex to update.\n\t * @param auditableItemGraphEdges The list of edges to use.\n\t * @returns True if the edges were updated.\n\t * @internal\n\t */\n\tprivate updateEdges(\n\t\tdocumentVertex: Omit<IAuditableItemGraphVertex, \"@context\" | \"id\" | \"type\">,\n\t\tauditableItemGraphEdges:\n\t\t\t| { targetId: string; addAlias?: boolean; aliasAnnotationObject?: IJsonLdNodeObject }[]\n\t\t\t| undefined\n\t): boolean {\n\t\tlet changed = false;\n\n\t\tconst existingEdgeIds = documentVertex.edges?.map(e => e.targetId) ?? [];\n\n\t\tif (Is.array(auditableItemGraphEdges)) {\n\t\t\tfor (const aigEdge of auditableItemGraphEdges) {\n\t\t\t\tconst existingIndex = existingEdgeIds.indexOf(aigEdge.targetId);\n\t\t\t\tif (existingIndex !== -1) {\n\t\t\t\t\t// If the edge already exists then we don't need to add it again\n\t\t\t\t\t// We just need to remove it from the list of existing ids\n\t\t\t\t\t// any remaining after this loop will be need to be removed\n\t\t\t\t\texistingEdgeIds.splice(existingIndex, 1);\n\t\t\t\t} else {\n\t\t\t\t\tconst vertexEdge: IAuditableItemGraphEdge = {\n\t\t\t\t\t\t\"@context\": AuditableItemGraphContexts.Context,\n\t\t\t\t\t\ttype: AuditableItemGraphTypes.Edge,\n\t\t\t\t\t\ttargetId: aigEdge.targetId,\n\t\t\t\t\t\tedgeRelationships: [\"document\"]\n\t\t\t\t\t};\n\n\t\t\t\t\tdocumentVertex.edges ??= [];\n\t\t\t\t\tdocumentVertex.edges?.push(vertexEdge);\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Anything left in the existingEdgeIds array means they need to be removed\n\t\t\tif (existingEdgeIds.length > 0 && Is.array(documentVertex.edges)) {\n\t\t\t\tfor (const existingEdgeId of existingEdgeIds) {\n\t\t\t\t\tconst existingIndex = documentVertex.edges.findIndex(e => e.targetId === existingEdgeId);\n\t\t\t\t\tif (existingIndex !== -1) {\n\t\t\t\t\t\tdocumentVertex.edges.splice(existingIndex, 1);\n\t\t\t\t\t\tchanged = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn changed;\n\t}\n\n\t/**\n\t * Update the edges.\n\t * @param connectedVertices The connected vertices for the edges.\n\t * @param auditableItemGraphDocumentId The document id to use.\n\t * @param documentVertex The document vertex to update.\n\t * @param auditableItemGraphEdges The list of edges to use.\n\t * @param documentId The document identifier.\n\t * @param documentIdFormat The format of the document identifier.\n\t * @internal\n\t */\n\tprivate async updateConnectedEdges(\n\t\tconnectedVertices: { [id: string]: IAuditableItemGraphVertex },\n\t\tauditableItemGraphDocumentId: string,\n\t\texistingEdgeIds: string[],\n\t\tauditableItemGraphEdges:\n\t\t\t| { targetId: string; addAlias?: boolean; aliasAnnotationObject?: IJsonLdNodeObject }[]\n\t\t\t| undefined,\n\t\tdocumentId: string,\n\t\tdocumentIdFormat: string | undefined\n\t): Promise<void> {\n\t\tif (Is.array(auditableItemGraphEdges)) {\n\t\t\tfor (const aigEdge of auditableItemGraphEdges) {\n\t\t\t\tconst connected = connectedVertices[aigEdge.targetId];\n\n\t\t\t\tif (!Is.empty(connected)) {\n\t\t\t\t\tlet updatedConnected = false;\n\n\t\t\t\t\tconst existingIndex = existingEdgeIds.indexOf(aigEdge.targetId);\n\t\t\t\t\tif (existingIndex !== -1) {\n\t\t\t\t\t\t// If the edge already exists we remove it from the list of existing ids\n\t\t\t\t\t\t// any remaining after this loop will be need to be disconnected\n\t\t\t\t\t\texistingEdgeIds.splice(existingIndex, 1);\n\t\t\t\t\t}\n\n\t\t\t\t\t// Add the edge with the document vertex id if it doesn't already exist\n\t\t\t\t\tconst hasEdge = connected.edges?.some(e => e.targetId === auditableItemGraphDocumentId);\n\t\t\t\t\tif (!hasEdge) {\n\t\t\t\t\t\tconst vertexEdge: IAuditableItemGraphEdge = {\n\t\t\t\t\t\t\t\"@context\": AuditableItemGraphContexts.Context,\n\t\t\t\t\t\t\ttype: AuditableItemGraphTypes.Edge,\n\t\t\t\t\t\t\ttargetId: auditableItemGraphDocumentId,\n\t\t\t\t\t\t\tedgeRelationships: [\"document\"]\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tconnected.edges ??= [];\n\t\t\t\t\t\tconnected.edges?.push(vertexEdge);\n\t\t\t\t\t\tupdatedConnected = true;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Add alias with the document id if option flag is set and it doesn't already exist\n\t\t\t\t\tif (aigEdge.addAlias) {\n\t\t\t\t\t\tconst alias = connected.aliases?.find(a => a.id === documentId);\n\t\t\t\t\t\tif (Is.empty(alias)) {\n\t\t\t\t\t\t\t// No existing alias, so create one\n\t\t\t\t\t\t\tconst vertexAlias: IAuditableItemGraphAlias = {\n\t\t\t\t\t\t\t\t\"@context\": AuditableItemGraphContexts.Context,\n\t\t\t\t\t\t\t\ttype: AuditableItemGraphTypes.Alias,\n\t\t\t\t\t\t\t\tid: documentId,\n\t\t\t\t\t\t\t\taliasFormat: documentIdFormat,\n\t\t\t\t\t\t\t\tannotationObject: aigEdge.aliasAnnotationObject\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\tconnected.aliases ??= [];\n\t\t\t\t\t\t\tconnected.aliases?.push(vertexAlias);\n\t\t\t\t\t\t\tupdatedConnected = true;\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\t!ObjectHelper.equal(alias.annotationObject, aigEdge.aliasAnnotationObject) ||\n\t\t\t\t\t\t\tdocumentIdFormat !== alias.aliasFormat\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// The alias already exists, but the format or annotation object has changed\n\t\t\t\t\t\t\talias.annotationObject = aigEdge.aliasAnnotationObject;\n\t\t\t\t\t\t\talias.aliasFormat = documentIdFormat;\n\t\t\t\t\t\t\tupdatedConnected = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (updatedConnected) {\n\t\t\t\t\t\tawait this._auditableItemGraphComponent.update(connected);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Anything left in the existingEdgeIds array means they need to be removed\n\t\tif (existingEdgeIds.length > 0) {\n\t\t\tfor (const existingEdgeId of existingEdgeIds) {\n\t\t\t\tconst connected = connectedVertices[existingEdgeId];\n\n\t\t\t\tif (!Is.empty(connected)) {\n\t\t\t\t\tlet updatedConnected = false;\n\n\t\t\t\t\t// Remove the edge from the connected vertex\n\t\t\t\t\tif (Is.arrayValue(connected.edges)) {\n\t\t\t\t\t\tconst existingIndex = connected.edges.findIndex(\n\t\t\t\t\t\t\te => e.targetId === auditableItemGraphDocumentId\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (existingIndex !== -1) {\n\t\t\t\t\t\t\tconnected.edges.splice(existingIndex, 1);\n\t\t\t\t\t\t\tupdatedConnected = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Remove the alias from the connected vertex\n\t\t\t\t\tif (Is.arrayValue(connected.aliases)) {\n\t\t\t\t\t\tconst existingIndex = connected.aliases.findIndex(e => e.id === documentId);\n\t\t\t\t\t\tif (existingIndex !== -1) {\n\t\t\t\t\t\t\tconnected.aliases.splice(existingIndex, 1);\n\t\t\t\t\t\t\tupdatedConnected = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (updatedConnected) {\n\t\t\t\t\t\tawait this._auditableItemGraphComponent.update(connected);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Get the documents from the auditable item graph vertex.\n\t * @param documentVertex The vertex containing the documents.\n\t * @param options Additional options for the get operation.\n\t * @param options.includeBlobStorageMetadata Flag to include the blob storage metadata for the document, defaults to false.\n\t * @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.\n\t * @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.\n\t * @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.\n\t * @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.\n\t * @param cursor The cursor to get the next chunk of revisions.\n\t * @param limit Limit the number of items to return, defaults to 1 so only most recent is returned.\n\t * @returns The finalised list of documents.\n\t * @internal\n\t */\n\tprivate async getDocumentsFromVertex(\n\t\tdocumentVertex: IAuditableItemGraphVertex,\n\t\toptions?: {\n\t\t\tincludeBlobStorageMetadata?: boolean;\n\t\t\tincludeBlobStorageData?: boolean;\n\t\t\tincludeAttestation?: boolean;\n\t\t\textractRuleGroupId?: string;\n\t\t\textractMimeType?: string;\n\t\t},\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\tentries: IDocumentList;\n\t\tcursor?: string;\n\t}> {\n\t\tconst docList: IDocumentList = {\n\t\t\t\"@context\": [\n\t\t\t\tSchemaOrgContexts.Context,\n\t\t\t\tDocumentContexts.Context,\n\t\t\t\tDocumentContexts.ContextCommon\n\t\t\t],\n\t\t\ttype: SchemaOrgTypes.ItemList,\n\t\t\t[SchemaOrgTypes.ItemListElement]: []\n\t\t};\n\n\t\tlet nextCursor: string | undefined;\n\n\t\tif (Is.arrayValue(documentVertex.resources)) {\n\t\t\t// Sort by newest revision first\n\t\t\tdocumentVertex.resources.sort(\n\t\t\t\t(a, b) =>\n\t\t\t\t\t(Coerce.number(b.resourceObject?.documentRevision) ?? 0) -\n\t\t\t\t\t(Coerce.number(a.resourceObject?.documentRevision) ?? 0)\n\t\t\t);\n\n\t\t\tconst startIndex = Coerce.integer(cursor) ?? 0;\n\t\t\tconst endIndex = Math.min(startIndex + (limit ?? 1), documentVertex.resources.length);\n\t\t\tconst slicedResources = documentVertex.resources.slice(startIndex, endIndex);\n\t\t\tnextCursor = documentVertex.resources.length > endIndex ? endIndex.toString() : undefined;\n\n\t\t\tconst includeBlobStorageMetadata = options?.includeBlobStorageMetadata ?? false;\n\t\t\tconst includeBlobStorageData = options?.includeBlobStorageData ?? false;\n\t\t\tconst includeAttestation = options?.includeAttestation ?? false;\n\t\t\tconst extractData = Is.stringValue(options?.extractRuleGroupId);\n\n\t\t\tfor (let i = 0; i < slicedResources.length; i++) {\n\t\t\t\tconst document = slicedResources[i].resourceObject as unknown as IDocument;\n\t\t\t\tif (Is.object(document)) {\n\t\t\t\t\tdocument.dateDeleted = slicedResources[i].dateDeleted;\n\n\t\t\t\t\tdocList[SchemaOrgTypes.ItemListElement].push(document);\n\n\t\t\t\t\tconst blobRequired = includeBlobStorageMetadata || includeBlobStorageData;\n\t\t\t\t\tif (blobRequired || extractData) {\n\t\t\t\t\t\tconst blobEntry = await this._blobStorageComponent.get(document.blobStorageId, {\n\t\t\t\t\t\t\tincludeContent: includeBlobStorageData || extractData\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (blobRequired) {\n\t\t\t\t\t\t\tdocument.blobStorageEntry = blobEntry;\n\t\t\t\t\t\t\tif (Is.object(document.blobStorageEntry)) {\n\t\t\t\t\t\t\t\tObjectHelper.propertyDelete(document.blobStorageEntry, \"@context\");\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (!docList[\"@context\"].includes(BlobStorageContexts.Context)) {\n\t\t\t\t\t\t\t\tdocList[\"@context\"].push(BlobStorageContexts.Context);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (Is.stringValue(options?.extractRuleGroupId) && Is.stringValue(blobEntry.blob)) {\n\t\t\t\t\t\t\tconst binaryBlob = Converter.base64ToBytes(blobEntry.blob);\n\t\t\t\t\t\t\tdocument.extractedData = await this._dataProcessingComponent.extract(\n\t\t\t\t\t\t\t\toptions.extractRuleGroupId,\n\t\t\t\t\t\t\t\tbinaryBlob,\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\toptions?.extractMimeType\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// If we have the blob data due to extraction but we weren't asked for it\n\t\t\t\t\t\t// then we remove it from the document\n\t\t\t\t\t\tif (!blobRequired) {\n\t\t\t\t\t\t\tdelete document.blobStorageEntry;\n\t\t\t\t\t\t} else if (!includeBlobStorageData) {\n\t\t\t\t\t\t\tdelete document.blobStorageEntry?.blob;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (includeAttestation && Is.stringValue(document.attestationId)) {\n\t\t\t\t\t\tconst attestationInformation = await this._attestationComponent.get(\n\t\t\t\t\t\t\tdocument.attestationId\n\t\t\t\t\t\t);\n\t\t\t\t\t\tdocument.attestationInformation = attestationInformation;\n\t\t\t\t\t\tif (Is.object(document.attestationInformation)) {\n\t\t\t\t\t\t\tObjectHelper.propertyDelete(document.attestationInformation, \"@context\");\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (Is.arrayValue(documentVertex.edges)) {\n\t\t\tdocList.edges ??= [];\n\n\t\t\tfor (const edge of documentVertex.edges) {\n\t\t\t\tif (Is.object(edge)) {\n\t\t\t\t\tdocList.edges.push(edge.targetId);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tentries: docList,\n\t\t\tcursor: nextCursor\n\t\t};\n\t}\n\n\t/**\n\t * Create an attestation for the document.\n\t * @param document The document to create the attestation for.\n\t * @returns The attestation identifier.\n\t */\n\tprivate async createAttestation(document: IDocument): Promise<string> {\n\t\tconst documentAttestation: IDocumentAttestation & IJsonLdNodeObject = {\n\t\t\t\"@context\": [\n\t\t\t\tSchemaOrgContexts.Context,\n\t\t\t\tDocumentContexts.Context,\n\t\t\t\tDocumentContexts.ContextCommon\n\t\t\t],\n\t\t\ttype: DocumentTypes.DocumentAttestation,\n\t\t\tid: document.id,\n\t\t\tdocumentId: document.documentId,\n\t\t\tdocumentCode: document.documentCode,\n\t\t\tdocumentRevision: document.documentRevision,\n\t\t\tdateCreated: document.dateCreated,\n\t\t\tintegrity: document.integrity\n\t\t};\n\t\treturn this._attestationComponent.create(documentAttestation);\n\t}\n\n\t/**\n\t * Create a document id from the document id and revision.\n\t * @param documentId The document id to create.\n\t * @param revision The revision of the document.\n\t * @returns The document id.\n\t * @internal\n\t */\n\tprivate createDocumentId(documentId: string, revision: number): string {\n\t\tconst documentIdHash = Converter.bytesToBase64Url(\n\t\t\tSha256.sum256(Converter.utf8ToBytes(documentId))\n\t\t);\n\t\treturn `document:${documentIdHash}:${revision}`;\n\t}\n}\n"]}
|
|
1
|
+
{"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,YA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AQ,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"]}
|
package/docs/changelog.md
CHANGED
|
@@ -1,4 +1,32 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.0.3-next.12](https://github.com/twinfoundation/document-management/compare/document-management-service-v0.0.3-next.11...document-management-service-v0.0.3-next.12) (2026-03-26)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* update to latest aig method shapes ([497e895](https://github.com/twinfoundation/document-management/commit/497e8954f24774db628e057ebb9d158a1fd9d92a))
|
|
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.11 to 0.0.3-next.12
|
|
16
|
+
|
|
17
|
+
## [0.0.3-next.11](https://github.com/twinfoundation/document-management/compare/document-management-service-v0.0.3-next.10...document-management-service-v0.0.3-next.11) (2026-02-25)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* update schemas ([310261d](https://github.com/twinfoundation/document-management/commit/310261d620254d9c00dfa8fbb470948af9101778))
|
|
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.10 to 0.0.3-next.11
|
|
2
30
|
|
|
3
31
|
## [0.0.3-next.10](https://github.com/twinfoundation/document-management/compare/document-management-service-v0.0.3-next.9...document-management-service-v0.0.3-next.10) (2026-02-11)
|
|
4
32
|
|
package/docs/examples.md
CHANGED
|
@@ -1 +1,121 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Document Management Service Examples
|
|
2
|
+
|
|
3
|
+
Use these snippets to wire the service into existing components and handle a full document lifecycle from creation through querying.
|
|
4
|
+
|
|
5
|
+
## DocumentManagementService
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { ComponentFactory, Converter } from '@twin.org/core';
|
|
9
|
+
import { DocumentManagementService } from '@twin.org/document-management-service';
|
|
10
|
+
import { UneceDocumentCodeList } from '@twin.org/standards-unece';
|
|
11
|
+
|
|
12
|
+
// Register concrete components before constructing the service.
|
|
13
|
+
ComponentFactory.register('auditable-item-graph', () => auditableItemGraphComponent);
|
|
14
|
+
ComponentFactory.register('blob-storage', () => blobStorageComponent);
|
|
15
|
+
ComponentFactory.register('attestation', () => attestationComponent);
|
|
16
|
+
ComponentFactory.register('data-processing', () => dataProcessingComponent);
|
|
17
|
+
|
|
18
|
+
const service = new DocumentManagementService();
|
|
19
|
+
const newBlob = Converter.utf8ToBytes('Initial customs document payload');
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
const className = service.className();
|
|
24
|
+
console.log(className); // DocumentManagementService
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
const vertexId = await service.create(
|
|
29
|
+
'CUS-2026-0100',
|
|
30
|
+
'customs',
|
|
31
|
+
UneceDocumentCodeList.CustomsDeclaration,
|
|
32
|
+
newBlob,
|
|
33
|
+
{
|
|
34
|
+
'@context': 'https://schema.org',
|
|
35
|
+
'@type': 'DigitalDocument',
|
|
36
|
+
name: 'customs-2026-0100.xml'
|
|
37
|
+
},
|
|
38
|
+
[
|
|
39
|
+
{
|
|
40
|
+
targetId: 'aig:shipment-123',
|
|
41
|
+
addAlias: true,
|
|
42
|
+
aliasAnnotationObject: {
|
|
43
|
+
'@context': 'https://schema.org',
|
|
44
|
+
'@type': 'Thing',
|
|
45
|
+
name: 'Shipment reference'
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
{
|
|
50
|
+
createAttestation: true,
|
|
51
|
+
addAlias: true,
|
|
52
|
+
aliasAnnotationObject: {
|
|
53
|
+
'@context': 'https://schema.org',
|
|
54
|
+
'@type': 'Thing',
|
|
55
|
+
name: 'Primary document alias'
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
console.log(vertexId); // aig:document-vertex-2
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
await service.update(
|
|
65
|
+
'aig:document-vertex-2',
|
|
66
|
+
Converter.utf8ToBytes('Customs document payload revision 1'),
|
|
67
|
+
{
|
|
68
|
+
'@context': 'https://schema.org',
|
|
69
|
+
'@type': 'CreativeWork',
|
|
70
|
+
name: 'customs-2026-0100-rev1.xml'
|
|
71
|
+
},
|
|
72
|
+
[
|
|
73
|
+
{
|
|
74
|
+
targetId: 'aig:shipment-123',
|
|
75
|
+
addAlias: true,
|
|
76
|
+
aliasAnnotationObject: {
|
|
77
|
+
'@context': 'https://schema.org',
|
|
78
|
+
'@type': 'Thing',
|
|
79
|
+
name: 'Updated shipment alias'
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
const latestDocuments = await service.get(
|
|
88
|
+
'aig:document-vertex-2',
|
|
89
|
+
{
|
|
90
|
+
includeBlobStorageMetadata: true,
|
|
91
|
+
includeAttestation: true,
|
|
92
|
+
includeRemoved: false
|
|
93
|
+
},
|
|
94
|
+
'0',
|
|
95
|
+
2
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
console.log(latestDocuments.entries.itemListElement.length); // 2
|
|
99
|
+
console.log(latestDocuments.cursor); // 2
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
const revision = await service.getRevision('aig:document-vertex-2', 1, {
|
|
104
|
+
includeBlobStorageData: true,
|
|
105
|
+
includeAttestation: true
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
console.log(revision.documentRevision); // 1
|
|
109
|
+
console.log(revision.documentCode); // Cusdec
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
await service.removeRevision('aig:document-vertex-2', 1);
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
const queryResult = await service.query('CUS-2026-0100', '0', 10);
|
|
118
|
+
|
|
119
|
+
console.log(queryResult.entries.vertices.length); // 1
|
|
120
|
+
console.log(queryResult.cursor); // undefined
|
|
121
|
+
```
|
package/docs/open-api/spec.json
CHANGED
|
@@ -1013,32 +1013,29 @@
|
|
|
1013
1013
|
"components": {
|
|
1014
1014
|
"schemas": {
|
|
1015
1015
|
"Document": {
|
|
1016
|
+
"description": "Interface describing a document.",
|
|
1016
1017
|
"type": "object",
|
|
1017
1018
|
"properties": {
|
|
1018
1019
|
"@context": {
|
|
1019
1020
|
"type": "array",
|
|
1020
|
-
"minItems": 3,
|
|
1021
|
-
"description": "JSON-LD Context.",
|
|
1022
1021
|
"prefixItems": [
|
|
1023
1022
|
{
|
|
1024
|
-
"type": "string",
|
|
1025
1023
|
"const": "https://schema.org"
|
|
1026
1024
|
},
|
|
1027
1025
|
{
|
|
1028
|
-
"type": "string",
|
|
1029
1026
|
"const": "https://schema.twindev.org/documents/"
|
|
1030
1027
|
},
|
|
1031
1028
|
{
|
|
1032
|
-
"type": "string",
|
|
1033
1029
|
"const": "https://schema.twindev.org/common/"
|
|
1034
1030
|
}
|
|
1035
1031
|
],
|
|
1036
1032
|
"items": {
|
|
1037
1033
|
"$ref": "https://schema.twindev.org/json-ld/JsonLdContextDefinitionElement"
|
|
1038
|
-
}
|
|
1034
|
+
},
|
|
1035
|
+
"minItems": 3,
|
|
1036
|
+
"description": "JSON-LD Context."
|
|
1039
1037
|
},
|
|
1040
1038
|
"type": {
|
|
1041
|
-
"type": "string",
|
|
1042
1039
|
"const": "Document",
|
|
1043
1040
|
"description": "JSON-LD Type."
|
|
1044
1041
|
},
|
|
@@ -1048,62 +1045,62 @@
|
|
|
1048
1045
|
},
|
|
1049
1046
|
"documentId": {
|
|
1050
1047
|
"type": "string",
|
|
1051
|
-
"description": "The id of the document.
|
|
1048
|
+
"description": "The id of the document."
|
|
1052
1049
|
},
|
|
1053
1050
|
"documentIdFormat": {
|
|
1054
1051
|
"type": "string",
|
|
1055
|
-
"description": "The format of the document id.
|
|
1052
|
+
"description": "The format of the document id."
|
|
1056
1053
|
},
|
|
1057
1054
|
"documentCode": {
|
|
1058
1055
|
"$ref": "https://schema.twindev.org/unece/UneceDocumentCodeList"
|
|
1059
1056
|
},
|
|
1060
1057
|
"documentRevision": {
|
|
1061
1058
|
"type": "number",
|
|
1062
|
-
"description": "The revision of the document as a 0 based index.
|
|
1059
|
+
"description": "The revision of the document as a 0 based index."
|
|
1063
1060
|
},
|
|
1064
1061
|
"annotationObject": {
|
|
1065
1062
|
"$ref": "https://schema.twindev.org/json-ld/JsonLdNodeObject"
|
|
1066
1063
|
},
|
|
1067
1064
|
"blobStorageId": {
|
|
1068
1065
|
"type": "string",
|
|
1069
|
-
"description": "The blob storage id for the document.
|
|
1066
|
+
"description": "The blob storage id for the document."
|
|
1070
1067
|
},
|
|
1071
1068
|
"integrity": {
|
|
1072
1069
|
"type": "string",
|
|
1073
|
-
"description": "The integrity of the blob data.
|
|
1070
|
+
"description": "The integrity of the blob data."
|
|
1074
1071
|
},
|
|
1075
1072
|
"blobStorageEntry": {
|
|
1076
1073
|
"$ref": "https://schema.twindev.org/blob-storage/BlobStorageEntry"
|
|
1077
1074
|
},
|
|
1078
1075
|
"extractedData": {
|
|
1079
|
-
"description": "The data extracted from the document using data extraction services.
|
|
1076
|
+
"description": "The data extracted from the document using data extraction services."
|
|
1080
1077
|
},
|
|
1081
1078
|
"attestationId": {
|
|
1082
1079
|
"type": "string",
|
|
1083
|
-
"description": "The attestation for the document if one was created.
|
|
1080
|
+
"description": "The attestation for the document if one was created."
|
|
1084
1081
|
},
|
|
1085
1082
|
"attestationInformation": {
|
|
1086
1083
|
"$ref": "https://schema.twindev.org/attestation/AttestationInformation"
|
|
1087
1084
|
},
|
|
1088
1085
|
"dateCreated": {
|
|
1089
1086
|
"type": "string",
|
|
1090
|
-
"description": "The date/time of when the document was created.
|
|
1087
|
+
"description": "The date/time of when the document was created."
|
|
1091
1088
|
},
|
|
1092
1089
|
"dateModified": {
|
|
1093
1090
|
"type": "string",
|
|
1094
|
-
"description": "The date/time of when the document was modified.
|
|
1091
|
+
"description": "The date/time of when the document was modified."
|
|
1095
1092
|
},
|
|
1096
1093
|
"dateDeleted": {
|
|
1097
1094
|
"type": "string",
|
|
1098
|
-
"description": "The date/time of when the document was deleted, as we never actually remove items.
|
|
1095
|
+
"description": "The date/time of when the document was deleted, as we never actually remove items."
|
|
1099
1096
|
},
|
|
1100
1097
|
"organizationIdentity": {
|
|
1101
1098
|
"type": "string",
|
|
1102
|
-
"description": "The organization which added the document to the graph.
|
|
1099
|
+
"description": "The organization which added the document to the graph."
|
|
1103
1100
|
},
|
|
1104
1101
|
"userIdentity": {
|
|
1105
1102
|
"type": "string",
|
|
1106
|
-
"description": "The user who added the document to the graph.
|
|
1103
|
+
"description": "The user who added the document to the graph."
|
|
1107
1104
|
}
|
|
1108
1105
|
},
|
|
1109
1106
|
"required": [
|
|
@@ -1116,37 +1113,32 @@
|
|
|
1116
1113
|
"blobStorageId",
|
|
1117
1114
|
"integrity",
|
|
1118
1115
|
"dateCreated"
|
|
1119
|
-
]
|
|
1120
|
-
"additionalProperties": false,
|
|
1121
|
-
"description": "Interface describing a document."
|
|
1116
|
+
]
|
|
1122
1117
|
},
|
|
1123
1118
|
"DocumentList": {
|
|
1119
|
+
"description": "Interface describing a list of document entries.",
|
|
1124
1120
|
"type": "object",
|
|
1125
1121
|
"properties": {
|
|
1126
1122
|
"@context": {
|
|
1127
1123
|
"type": "array",
|
|
1128
|
-
"minItems": 3,
|
|
1129
|
-
"description": "JSON-LD Context.",
|
|
1130
1124
|
"prefixItems": [
|
|
1131
1125
|
{
|
|
1132
|
-
"type": "string",
|
|
1133
1126
|
"const": "https://schema.org"
|
|
1134
1127
|
},
|
|
1135
1128
|
{
|
|
1136
|
-
"type": "string",
|
|
1137
1129
|
"const": "https://schema.twindev.org/documents/"
|
|
1138
1130
|
},
|
|
1139
1131
|
{
|
|
1140
|
-
"type": "string",
|
|
1141
1132
|
"const": "https://schema.twindev.org/common/"
|
|
1142
1133
|
}
|
|
1143
1134
|
],
|
|
1144
1135
|
"items": {
|
|
1145
1136
|
"$ref": "https://schema.twindev.org/json-ld/JsonLdContextDefinitionElement"
|
|
1146
|
-
}
|
|
1137
|
+
},
|
|
1138
|
+
"minItems": 3,
|
|
1139
|
+
"description": "JSON-LD Context."
|
|
1147
1140
|
},
|
|
1148
1141
|
"type": {
|
|
1149
|
-
"type": "string",
|
|
1150
1142
|
"const": "ItemList",
|
|
1151
1143
|
"description": "JSON-LD Type."
|
|
1152
1144
|
},
|
|
@@ -1155,23 +1147,21 @@
|
|
|
1155
1147
|
"items": {
|
|
1156
1148
|
"$ref": "#/components/schemas/Document"
|
|
1157
1149
|
},
|
|
1158
|
-
"description": "The list of documents.
|
|
1150
|
+
"description": "The list of documents."
|
|
1159
1151
|
},
|
|
1160
1152
|
"edges": {
|
|
1161
1153
|
"type": "array",
|
|
1162
1154
|
"items": {
|
|
1163
1155
|
"type": "string"
|
|
1164
1156
|
},
|
|
1165
|
-
"description": "The ids of the other vertices which are connected to the document.
|
|
1157
|
+
"description": "The ids of the other vertices which are connected to the document."
|
|
1166
1158
|
}
|
|
1167
1159
|
},
|
|
1168
1160
|
"required": [
|
|
1169
1161
|
"@context",
|
|
1170
1162
|
"type",
|
|
1171
1163
|
"itemListElement"
|
|
1172
|
-
]
|
|
1173
|
-
"additionalProperties": false,
|
|
1174
|
-
"description": "Interface describing a list of document entries."
|
|
1164
|
+
]
|
|
1175
1165
|
},
|
|
1176
1166
|
"DocumentManagementCreateRequest": {
|
|
1177
1167
|
"type": "object",
|
|
@@ -1211,8 +1201,7 @@
|
|
|
1211
1201
|
},
|
|
1212
1202
|
"required": [
|
|
1213
1203
|
"targetId"
|
|
1214
|
-
]
|
|
1215
|
-
"additionalProperties": false
|
|
1204
|
+
]
|
|
1216
1205
|
},
|
|
1217
1206
|
"description": "The auditable item graph vertices to connect the document to."
|
|
1218
1207
|
},
|
|
@@ -1230,10 +1219,10 @@
|
|
|
1230
1219
|
},
|
|
1231
1220
|
"required": [
|
|
1232
1221
|
"documentId",
|
|
1222
|
+
"documentIdFormat",
|
|
1233
1223
|
"documentCode",
|
|
1234
1224
|
"blob"
|
|
1235
1225
|
],
|
|
1236
|
-
"additionalProperties": false,
|
|
1237
1226
|
"description": "The body parameters."
|
|
1238
1227
|
},
|
|
1239
1228
|
"DocumentManagementUpdateRequest": {
|
|
@@ -1263,16 +1252,15 @@
|
|
|
1263
1252
|
},
|
|
1264
1253
|
"required": [
|
|
1265
1254
|
"targetId"
|
|
1266
|
-
]
|
|
1267
|
-
"additionalProperties": false
|
|
1255
|
+
]
|
|
1268
1256
|
},
|
|
1269
1257
|
"description": "The auditable item graph vertices to connect the document to."
|
|
1270
1258
|
}
|
|
1271
1259
|
},
|
|
1272
|
-
"additionalProperties": false,
|
|
1273
1260
|
"description": "The body parameters."
|
|
1274
1261
|
},
|
|
1275
1262
|
"Error": {
|
|
1263
|
+
"description": "Model to describe serialized error.",
|
|
1276
1264
|
"type": "object",
|
|
1277
1265
|
"properties": {
|
|
1278
1266
|
"name": {
|
|
@@ -1303,46 +1291,20 @@
|
|
|
1303
1291
|
"required": [
|
|
1304
1292
|
"name",
|
|
1305
1293
|
"message"
|
|
1306
|
-
]
|
|
1307
|
-
"additionalProperties": false,
|
|
1308
|
-
"description": "Model to describe serialized error."
|
|
1294
|
+
]
|
|
1309
1295
|
},
|
|
1310
1296
|
"NotFoundResponse": {
|
|
1311
1297
|
"type": "object",
|
|
1312
|
-
"additionalProperties": false,
|
|
1313
1298
|
"properties": {
|
|
1314
1299
|
"notFoundId": {
|
|
1315
1300
|
"type": "string",
|
|
1316
1301
|
"description": "The id if the item that was not found."
|
|
1317
|
-
},
|
|
1318
|
-
"name": {
|
|
1319
|
-
"type": "string",
|
|
1320
|
-
"description": "The name for the error."
|
|
1321
|
-
},
|
|
1322
|
-
"message": {
|
|
1323
|
-
"type": "string",
|
|
1324
|
-
"description": "The message for the error."
|
|
1325
|
-
},
|
|
1326
|
-
"source": {
|
|
1327
|
-
"type": "string",
|
|
1328
|
-
"description": "The source of the error."
|
|
1329
|
-
},
|
|
1330
|
-
"properties": {
|
|
1331
|
-
"type": "object",
|
|
1332
|
-
"additionalProperties": {},
|
|
1333
|
-
"description": "Any additional information for the error."
|
|
1334
|
-
},
|
|
1335
|
-
"stack": {
|
|
1336
|
-
"type": "string",
|
|
1337
|
-
"description": "The stack trace for the error."
|
|
1338
|
-
},
|
|
1339
|
-
"cause": {
|
|
1340
|
-
"$ref": "#/components/schemas/Error"
|
|
1341
1302
|
}
|
|
1342
1303
|
},
|
|
1343
|
-
"
|
|
1344
|
-
|
|
1345
|
-
|
|
1304
|
+
"allOf": [
|
|
1305
|
+
{
|
|
1306
|
+
"$ref": "#/components/schemas/Error"
|
|
1307
|
+
}
|
|
1346
1308
|
],
|
|
1347
1309
|
"description": "The body which contains the error."
|
|
1348
1310
|
}
|
|
@@ -28,7 +28,7 @@ The options for the service.
|
|
|
28
28
|
|
|
29
29
|
## Properties
|
|
30
30
|
|
|
31
|
-
### CLASS\_NAME
|
|
31
|
+
### CLASS\_NAME {#class_name}
|
|
32
32
|
|
|
33
33
|
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
34
34
|
|
|
@@ -36,7 +36,7 @@ Runtime name for the class.
|
|
|
36
36
|
|
|
37
37
|
## Methods
|
|
38
38
|
|
|
39
|
-
### className()
|
|
39
|
+
### className() {#classname}
|
|
40
40
|
|
|
41
41
|
> **className**(): `string`
|
|
42
42
|
|
|
@@ -54,7 +54,7 @@ The class name of the component.
|
|
|
54
54
|
|
|
55
55
|
***
|
|
56
56
|
|
|
57
|
-
### create()
|
|
57
|
+
### create() {#create}
|
|
58
58
|
|
|
59
59
|
> **create**(`documentId`, `documentIdFormat`, `documentCode`, `blob`, `annotationObject?`, `auditableItemGraphEdges?`, `options?`): `Promise`\<`string`\>
|
|
60
60
|
|
|
@@ -72,9 +72,9 @@ The document id to create.
|
|
|
72
72
|
|
|
73
73
|
##### documentIdFormat
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
`string` \| `undefined`
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
The format of the document identifier.
|
|
78
78
|
|
|
79
79
|
##### documentCode
|
|
80
80
|
|
|
@@ -134,7 +134,7 @@ The auditable item graph vertex created for the document including its revision.
|
|
|
134
134
|
|
|
135
135
|
***
|
|
136
136
|
|
|
137
|
-
### update()
|
|
137
|
+
### update() {#update}
|
|
138
138
|
|
|
139
139
|
> **update**(`auditableItemGraphDocumentId`, `blob?`, `annotationObject?`, `auditableItemGraphEdges?`): `Promise`\<`void`\>
|
|
140
140
|
|
|
@@ -180,7 +180,7 @@ Nothing.
|
|
|
180
180
|
|
|
181
181
|
***
|
|
182
182
|
|
|
183
|
-
### get()
|
|
183
|
+
### get() {#get}
|
|
184
184
|
|
|
185
185
|
> **get**(`auditableItemGraphDocumentId`, `options?`, `cursor?`, `limit?`): `Promise`\<\{ `entries`: `IDocumentList`; `cursor?`: `string`; \}\>
|
|
186
186
|
|
|
@@ -258,7 +258,7 @@ The documents and revisions if requested, ordered by revision descending, cursor
|
|
|
258
258
|
|
|
259
259
|
***
|
|
260
260
|
|
|
261
|
-
### getRevision()
|
|
261
|
+
### getRevision() {#getrevision}
|
|
262
262
|
|
|
263
263
|
> **getRevision**(`auditableItemGraphDocumentId`, `revision`, `options?`): `Promise`\<`IDocument`\>
|
|
264
264
|
|
|
@@ -324,7 +324,7 @@ The documents and revisions if requested, ordered by revision descending, cursor
|
|
|
324
324
|
|
|
325
325
|
***
|
|
326
326
|
|
|
327
|
-
### removeRevision()
|
|
327
|
+
### removeRevision() {#removerevision}
|
|
328
328
|
|
|
329
329
|
> **removeRevision**(`auditableItemGraphDocumentId`, `revision`): `Promise`\<`void`\>
|
|
330
330
|
|
|
@@ -357,7 +357,7 @@ Nothing.
|
|
|
357
357
|
|
|
358
358
|
***
|
|
359
359
|
|
|
360
|
-
### query()
|
|
360
|
+
### query() {#query}
|
|
361
361
|
|
|
362
362
|
> **query**(`documentId`, `cursor?`, `limit?`): `Promise`\<\{ `entries`: `IAuditableItemGraphVertexList`; `cursor?`: `string`; \}\>
|
|
363
363
|
|
|
@@ -4,9 +4,9 @@ Options for the document management Service constructor.
|
|
|
4
4
|
|
|
5
5
|
## Properties
|
|
6
6
|
|
|
7
|
-
### auditableItemGraphComponentType?
|
|
7
|
+
### auditableItemGraphComponentType? {#auditableitemgraphcomponenttype}
|
|
8
8
|
|
|
9
|
-
> `optional` **auditableItemGraphComponentType
|
|
9
|
+
> `optional` **auditableItemGraphComponentType?**: `string`
|
|
10
10
|
|
|
11
11
|
The type of the auditable item graph component.
|
|
12
12
|
|
|
@@ -18,9 +18,9 @@ auditable-item-graph
|
|
|
18
18
|
|
|
19
19
|
***
|
|
20
20
|
|
|
21
|
-
### blobStorageComponentType?
|
|
21
|
+
### blobStorageComponentType? {#blobstoragecomponenttype}
|
|
22
22
|
|
|
23
|
-
> `optional` **blobStorageComponentType
|
|
23
|
+
> `optional` **blobStorageComponentType?**: `string`
|
|
24
24
|
|
|
25
25
|
The type of the blob storage component.
|
|
26
26
|
|
|
@@ -32,9 +32,9 @@ blob-storage
|
|
|
32
32
|
|
|
33
33
|
***
|
|
34
34
|
|
|
35
|
-
### attestationComponentType?
|
|
35
|
+
### attestationComponentType? {#attestationcomponenttype}
|
|
36
36
|
|
|
37
|
-
> `optional` **attestationComponentType
|
|
37
|
+
> `optional` **attestationComponentType?**: `string`
|
|
38
38
|
|
|
39
39
|
The type of the attestation component.
|
|
40
40
|
|
|
@@ -46,9 +46,9 @@ attestation
|
|
|
46
46
|
|
|
47
47
|
***
|
|
48
48
|
|
|
49
|
-
### dataProcessingComponentType?
|
|
49
|
+
### dataProcessingComponentType? {#dataprocessingcomponenttype}
|
|
50
50
|
|
|
51
|
-
> `optional` **dataProcessingComponentType
|
|
51
|
+
> `optional` **dataProcessingComponentType?**: `string`
|
|
52
52
|
|
|
53
53
|
The type of the data processing component.
|
|
54
54
|
|
|
@@ -60,8 +60,8 @@ data-processing
|
|
|
60
60
|
|
|
61
61
|
***
|
|
62
62
|
|
|
63
|
-
### config?
|
|
63
|
+
### config? {#config}
|
|
64
64
|
|
|
65
|
-
> `optional` **config
|
|
65
|
+
> `optional` **config?**: [`IDocumentManagementServiceConfig`](IDocumentManagementServiceConfig.md)
|
|
66
66
|
|
|
67
67
|
The configuration for the service.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/document-management-service",
|
|
3
|
-
"version": "0.0.3-next.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.3-next.12",
|
|
4
|
+
"description": "Service-side document lifecycle operations and REST route generation for server integrations.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/twinfoundation/document-management.git",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@twin.org/crypto": "next",
|
|
24
24
|
"@twin.org/data-json-ld": "next",
|
|
25
25
|
"@twin.org/data-processing-models": "next",
|
|
26
|
-
"@twin.org/document-management-models": "0.0.3-next.
|
|
26
|
+
"@twin.org/document-management-models": "0.0.3-next.12",
|
|
27
27
|
"@twin.org/entity": "next",
|
|
28
28
|
"@twin.org/entity-storage-models": "next",
|
|
29
29
|
"@twin.org/nameof": "next",
|