@twin.org/document-management-rest-client 0.0.3-next.15 → 0.0.3-next.17

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.
@@ -68,12 +68,18 @@ export class DocumentManagementRestClient extends BaseRestClient {
68
68
  * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
69
69
  * @param blob The data to update the document with.
70
70
  * @param annotationObject Additional information to associate with the document.
71
- * @param auditableItemGraphEdges The auditable item graph vertices to connect the document to, if undefined retains current connections.
72
- * @returns Nothing.
71
+ * @param auditableItemGraphEdges Explicit edge delta to apply. If undefined, existing connections
72
+ * are retained unchanged. Use `add` to create new connections and `remove` to disconnect existing
73
+ * ones by their target vertex id. To update alias metadata on an already-connected vertex, include
74
+ * it in `add` with the updated `aliasAnnotationObject` — AIG's alias patch is an upsert, so the
75
+ * alias is updated in place without creating a duplicate back-edge.
76
+ * @param auditableItemGraphEdges.add Connections to add; each creates a back-edge on the connected vertex.
77
+ * @param auditableItemGraphEdges.remove Target vertex IDs to disconnect; their back-edges are removed.
78
+ * @returns A promise that resolves when the document has been updated.
73
79
  */
74
- async update(auditableItemGraphDocumentId, blob, annotationObject, auditableItemGraphEdges) {
80
+ async updatePartial(auditableItemGraphDocumentId, blob, annotationObject, auditableItemGraphEdges) {
75
81
  Urn.guard(DocumentManagementRestClient.CLASS_NAME, "auditableItemGraphDocumentId", auditableItemGraphDocumentId);
76
- await this.fetch("/:auditableItemGraphDocumentId", "PUT", {
82
+ await this.fetch("/:auditableItemGraphDocumentId", "PATCH", {
77
83
  pathParams: {
78
84
  auditableItemGraphDocumentId
79
85
  },
@@ -92,6 +98,7 @@ export class DocumentManagementRestClient extends BaseRestClient {
92
98
  * @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.
93
99
  * @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.
94
100
  * @param options.includeRemoved Flag to include deleted documents, defaults to false.
101
+ * @param options.includeDeletedEdges Flag to include soft-deleted edges in the response, defaults to false.
95
102
  * @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.
96
103
  * @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.
97
104
  * @param cursor The cursor to get the next chunk of revisions.
@@ -109,6 +116,7 @@ export class DocumentManagementRestClient extends BaseRestClient {
109
116
  includeBlobStorageData: Coerce.string(options?.includeBlobStorageData),
110
117
  includeAttestation: Coerce.string(options?.includeAttestation),
111
118
  includeRemoved: Coerce.string(options?.includeRemoved),
119
+ includeDeletedEdges: Coerce.string(options?.includeDeletedEdges),
112
120
  extractRuleGroupId: options?.extractRuleGroupId,
113
121
  extractMimeType: options?.extractMimeType,
114
122
  cursor,
@@ -131,7 +139,7 @@ export class DocumentManagementRestClient extends BaseRestClient {
131
139
  * @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.
132
140
  * @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.
133
141
  * @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.
134
- * @returns The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.
142
+ * @returns The document for the specified revision.
135
143
  */
136
144
  async getRevision(auditableItemGraphDocumentId, revision, options) {
137
145
  Urn.guard(DocumentManagementRestClient.CLASS_NAME, "auditableItemGraphDocumentId", auditableItemGraphDocumentId);
@@ -156,11 +164,11 @@ export class DocumentManagementRestClient extends BaseRestClient {
156
164
  * The document dateDeleted will be set, but can still be queried with the includeRemoved flag.
157
165
  * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
158
166
  * @param revision The revision of the document to remove.
159
- * @returns Nothing.
167
+ * @returns A promise that resolves when the revision has been removed.
160
168
  */
161
169
  async removeRevision(auditableItemGraphDocumentId, revision) {
162
170
  Urn.guard(DocumentManagementRestClient.CLASS_NAME, "auditableItemGraphDocumentId", auditableItemGraphDocumentId);
163
- Guards.number(DocumentManagementRestClient.CLASS_NAME, "revision", revision);
171
+ Guards.integer(DocumentManagementRestClient.CLASS_NAME, "revision", revision);
164
172
  await this.fetch("/:auditableItemGraphDocumentId/:revision", "DELETE", {
165
173
  pathParams: {
166
174
  auditableItemGraphDocumentId,
@@ -1 +1 @@
1
- {"version":3,"file":"documentManagementRestClient.js","sourceRoot":"","sources":["../../src/documentManagementRestClient.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAOpD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAiBpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE1D;;GAEG;AACH,MAAM,OAAO,4BACZ,SAAQ,cAAc;IAGtB;;OAEG;IACI,MAAM,CAAU,UAAU,kCAAkD;IAEnF;;;OAGG;IACH,YAAY,MAA6B;QACxC,KAAK,CAAC,4BAA4B,CAAC,UAAU,EAAE,MAAM,EAAE,qBAAqB,CAAC,CAAC;IAC/E,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,4BAA4B,CAAC,UAAU,CAAC;IAChD,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACI,KAAK,CAAC,MAAM,CAClB,UAAkB,EAClB,gBAAoC,EACpC,YAAmC,EACnC,IAAgB,EAChB,gBAAoC,EACpC,uBAIG,EACH,OAIC;QAED,MAAM,CAAC,WAAW,CAAC,4BAA4B,CAAC,UAAU,gBAAsB,UAAU,CAAC,CAAC;QAC5F,MAAM,CAAC,UAAU,CAChB,4BAA4B,CAAC,UAAU,kBAEvC,YAAY,EACZ,MAAM,CAAC,MAAM,CAAC,qBAAqB,CAAC,CACpC,CAAC;QACF,MAAM,CAAC,UAAU,CAAC,4BAA4B,CAAC,UAAU,UAAgB,IAAI,CAAC,CAAC;QAE/E,MAAM,QAAQ,GAAG,MA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// SPDX-License-Identifier: Apache-2.0.\nimport { BaseRestClient } from \"@twin.org/api-core\";\nimport type {\n\tIBaseRestClientConfig,\n\tICreatedResponse,\n\tINoContentResponse\n} from \"@twin.org/api-models\";\nimport type { IAuditableItemGraphVertexList } from \"@twin.org/auditable-item-graph-models\";\nimport { Coerce, Converter, Guards, Is, Urn } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport type {\n\tIDocument,\n\tIDocumentList,\n\tIDocumentManagementComponent,\n\tIDocumentManagementCreateRequest,\n\tIDocumentManagementGetRequest,\n\tIDocumentManagementGetResponse,\n\tIDocumentManagementGetRevisionRequest,\n\tIDocumentManagementGetRevisionResponse,\n\tIDocumentManagementQueryRequest,\n\tIDocumentManagementQueryResponse,\n\tIDocumentManagementRemoveRequest,\n\tIDocumentManagementUpdateRequest\n} from \"@twin.org/document-management-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { UneceDocumentCodeList } from \"@twin.org/standards-unece\";\nimport { HeaderHelper, HeaderTypes } from \"@twin.org/web\";\n\n/**\n * Client for performing document management through to REST endpoints.\n */\nexport class DocumentManagementRestClient\n\textends BaseRestClient\n\timplements IDocumentManagementComponent\n{\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<DocumentManagementRestClient>();\n\n\t/**\n\t * Create a new instance of DocumentManagementRestClient.\n\t * @param config The configuration for the client.\n\t */\n\tconstructor(config: IBaseRestClientConfig) {\n\t\tsuper(DocumentManagementRestClient.CLASS_NAME, config, \"document-management\");\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 DocumentManagementRestClient.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(DocumentManagementRestClient.CLASS_NAME, nameof(documentId), documentId);\n\t\tGuards.arrayOneOf(\n\t\t\tDocumentManagementRestClient.CLASS_NAME,\n\t\t\tnameof(documentCode),\n\t\t\tdocumentCode,\n\t\t\tObject.values(UneceDocumentCodeList)\n\t\t);\n\t\tGuards.uint8Array(DocumentManagementRestClient.CLASS_NAME, nameof(blob), blob);\n\n\t\tconst response = await this.fetch<IDocumentManagementCreateRequest, ICreatedResponse>(\n\t\t\t\"/\",\n\t\t\t\"POST\",\n\t\t\t{\n\t\t\t\tbody: {\n\t\t\t\t\tdocumentId,\n\t\t\t\t\tdocumentIdFormat,\n\t\t\t\t\tdocumentCode,\n\t\t\t\t\tblob: Converter.bytesToBase64(blob),\n\t\t\t\t\tannotationObject,\n\t\t\t\t\tauditableItemGraphEdges,\n\t\t\t\t\tcreateAttestation: options?.createAttestation,\n\t\t\t\t\taddAlias: options?.addAlias,\n\t\t\t\t\taliasAnnotationObject: options?.aliasAnnotationObject\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn response.headers.location;\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\tDocumentManagementRestClient.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\n\t\tawait this.fetch<IDocumentManagementUpdateRequest, INoContentResponse>(\n\t\t\t\"/:auditableItemGraphDocumentId\",\n\t\t\t\"PUT\",\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tauditableItemGraphDocumentId\n\t\t\t\t},\n\t\t\t\tbody: {\n\t\t\t\t\tblob: Is.uint8Array(blob) ? Converter.bytesToBase64(blob) : undefined,\n\t\t\t\t\tannotationObject,\n\t\t\t\t\tauditableItemGraphEdges\n\t\t\t\t}\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 The limit 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\tDocumentManagementRestClient.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\n\t\tconst response = await this.fetch<\n\t\t\tIDocumentManagementGetRequest,\n\t\t\tIDocumentManagementGetResponse\n\t\t>(\"/:auditableItemGraphDocumentId\", \"GET\", {\n\t\t\tpathParams: {\n\t\t\t\tauditableItemGraphDocumentId\n\t\t\t},\n\t\t\tquery: {\n\t\t\t\tincludeBlobStorageMetadata: Coerce.string(options?.includeBlobStorageMetadata),\n\t\t\t\tincludeBlobStorageData: Coerce.string(options?.includeBlobStorageData),\n\t\t\t\tincludeAttestation: Coerce.string(options?.includeAttestation),\n\t\t\t\tincludeRemoved: Coerce.string(options?.includeRemoved),\n\t\t\t\textractRuleGroupId: options?.extractRuleGroupId,\n\t\t\t\textractMimeType: options?.extractMimeType,\n\t\t\t\tcursor,\n\t\t\t\tlimit: Coerce.string(limit)\n\t\t\t}\n\t\t});\n\n\t\treturn {\n\t\t\tentries: response.body,\n\t\t\tcursor: HeaderHelper.extractLinkHeaderRelation(response.headers?.[HeaderTypes.Link], \"next\")\n\t\t\t\t?.urlQueryParams?.cursor\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\tDocumentManagementRestClient.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\t\tGuards.integer(DocumentManagementRestClient.CLASS_NAME, nameof(revision), revision);\n\n\t\tconst response = await this.fetch<\n\t\t\tIDocumentManagementGetRevisionRequest,\n\t\t\tIDocumentManagementGetRevisionResponse\n\t\t>(\"/:auditableItemGraphDocumentId/:revision\", \"GET\", {\n\t\t\tpathParams: {\n\t\t\t\tauditableItemGraphDocumentId,\n\t\t\t\trevision: revision.toString()\n\t\t\t},\n\t\t\tquery: {\n\t\t\t\tincludeBlobStorageMetadata: Coerce.string(options?.includeBlobStorageMetadata),\n\t\t\t\tincludeBlobStorageData: Coerce.string(options?.includeBlobStorageData),\n\t\t\t\tincludeAttestation: Coerce.string(options?.includeAttestation),\n\t\t\t\textractRuleGroupId: options?.extractRuleGroupId,\n\t\t\t\textractMimeType: options?.extractMimeType\n\t\t\t}\n\t\t});\n\n\t\treturn response.body;\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\tDocumentManagementRestClient.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\t\tGuards.number(DocumentManagementRestClient.CLASS_NAME, nameof(revision), revision);\n\n\t\tawait this.fetch<IDocumentManagementRemoveRequest, INoContentResponse>(\n\t\t\t\"/:auditableItemGraphDocumentId/:revision\",\n\t\t\t\"DELETE\",\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tauditableItemGraphDocumentId,\n\t\t\t\t\trevision: revision.toString()\n\t\t\t\t}\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(DocumentManagementRestClient.CLASS_NAME, nameof(documentId), documentId);\n\n\t\tconst response = await this.fetch<\n\t\t\tIDocumentManagementQueryRequest,\n\t\t\tIDocumentManagementQueryResponse\n\t\t>(\"/\", \"GET\", {\n\t\t\tquery: {\n\t\t\t\tdocumentId,\n\t\t\t\tcursor,\n\t\t\t\tlimit: Coerce.string(limit)\n\t\t\t}\n\t\t});\n\n\t\treturn {\n\t\t\tentries: response.body,\n\t\t\tcursor: HeaderHelper.extractLinkHeaderRelation(response.headers?.[HeaderTypes.Link], \"next\")\n\t\t\t\t?.urlQueryParams?.cursor\n\t\t};\n\t}\n}\n"]}
1
+ {"version":3,"file":"documentManagementRestClient.js","sourceRoot":"","sources":["../../src/documentManagementRestClient.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAOpD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAkBpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE1D;;GAEG;AACH,MAAM,OAAO,4BACZ,SAAQ,cAAc;IAGtB;;OAEG;IACI,MAAM,CAAU,UAAU,kCAAkD;IAEnF;;;OAGG;IACH,YAAY,MAA6B;QACxC,KAAK,CAAC,4BAA4B,CAAC,UAAU,EAAE,MAAM,EAAE,qBAAqB,CAAC,CAAC;IAC/E,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,4BAA4B,CAAC,UAAU,CAAC;IAChD,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACI,KAAK,CAAC,MAAM,CAClB,UAAkB,EAClB,gBAAoC,EACpC,YAAmC,EACnC,IAAgB,EAChB,gBAAoC,EACpC,uBAAwD,EACxD,OAIC;QAED,MAAM,CAAC,WAAW,CAAC,4BAA4B,CAAC,UAAU,gBAAsB,UAAU,CAAC,CAAC;QAC5F,MAAM,CAAC,UAAU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C;aAC3B;SACD,CAAC,CAAC;QAEH,OAAO;YACN,OAAO,EAAE,QAAQ,CAAC,IAAI;YACtB,MAAM,EAAE,YAAY,CAAC,yBAAyB,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;gBAC3F,EAAE,cAAc,EAAE,MAAM;SACzB,CAAC;IACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseRestClient } from \"@twin.org/api-core\";\nimport type {\n\tIBaseRestClientConfig,\n\tICreatedResponse,\n\tINoContentResponse\n} from \"@twin.org/api-models\";\nimport type { IAuditableItemGraphVertexList } from \"@twin.org/auditable-item-graph-models\";\nimport { Coerce, Converter, Guards, Is, Urn } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport type {\n\tIDocument,\n\tIDocumentList,\n\tIDocumentManagementComponent,\n\tIDocumentManagementCreateRequest,\n\tIDocumentManagementEdgeEntry,\n\tIDocumentManagementGetRequest,\n\tIDocumentManagementGetResponse,\n\tIDocumentManagementGetRevisionRequest,\n\tIDocumentManagementGetRevisionResponse,\n\tIDocumentManagementQueryRequest,\n\tIDocumentManagementQueryResponse,\n\tIDocumentManagementRemoveRequest,\n\tIDocumentManagementUpdatePartialRequest\n} from \"@twin.org/document-management-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { UneceDocumentCodeList } from \"@twin.org/standards-unece\";\nimport { HeaderHelper, HeaderTypes } from \"@twin.org/web\";\n\n/**\n * Client for performing document management through to REST endpoints.\n */\nexport class DocumentManagementRestClient\n\textends BaseRestClient\n\timplements IDocumentManagementComponent\n{\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<DocumentManagementRestClient>();\n\n\t/**\n\t * Create a new instance of DocumentManagementRestClient.\n\t * @param config The configuration for the client.\n\t */\n\tconstructor(config: IBaseRestClientConfig) {\n\t\tsuper(DocumentManagementRestClient.CLASS_NAME, config, \"document-management\");\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 DocumentManagementRestClient.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?: IDocumentManagementEdgeEntry[],\n\t\toptions?: {\n\t\t\tcreateAttestation?: boolean;\n\t\t\taddAlias?: boolean;\n\t\t\taliasAnnotationObject?: IJsonLdNodeObject;\n\t\t}\n\t): Promise<string> {\n\t\tGuards.stringValue(DocumentManagementRestClient.CLASS_NAME, nameof(documentId), documentId);\n\t\tGuards.arrayOneOf(\n\t\t\tDocumentManagementRestClient.CLASS_NAME,\n\t\t\tnameof(documentCode),\n\t\t\tdocumentCode,\n\t\t\tObject.values(UneceDocumentCodeList)\n\t\t);\n\t\tGuards.uint8Array(DocumentManagementRestClient.CLASS_NAME, nameof(blob), blob);\n\n\t\tconst response = await this.fetch<IDocumentManagementCreateRequest, ICreatedResponse>(\n\t\t\t\"/\",\n\t\t\t\"POST\",\n\t\t\t{\n\t\t\t\tbody: {\n\t\t\t\t\tdocumentId,\n\t\t\t\t\tdocumentIdFormat,\n\t\t\t\t\tdocumentCode,\n\t\t\t\t\tblob: Converter.bytesToBase64(blob),\n\t\t\t\t\tannotationObject,\n\t\t\t\t\tauditableItemGraphEdges,\n\t\t\t\t\tcreateAttestation: options?.createAttestation,\n\t\t\t\t\taddAlias: options?.addAlias,\n\t\t\t\t\taliasAnnotationObject: options?.aliasAnnotationObject\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn response.headers.location;\n\t}\n\n\t/**\n\t * Update a document as an auditable item graph vertex and add its content to blob storage.\n\t * If the blob data is different a new revision will be created.\n\t * For any other changes the current revision will be updated.\n\t * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.\n\t * @param blob The data to update the document with.\n\t * @param annotationObject Additional information to associate with the document.\n\t * @param auditableItemGraphEdges Explicit edge delta to apply. If undefined, existing connections\n\t * are retained unchanged. Use `add` to create new connections and `remove` to disconnect existing\n\t * ones by their target vertex id. To update alias metadata on an already-connected vertex, include\n\t * it in `add` with the updated `aliasAnnotationObject` — AIG's alias patch is an upsert, so the\n\t * alias is updated in place without creating a duplicate back-edge.\n\t * @param auditableItemGraphEdges.add Connections to add; each creates a back-edge on the connected vertex.\n\t * @param auditableItemGraphEdges.remove Target vertex IDs to disconnect; their back-edges are removed.\n\t * @returns A promise that resolves when the document has been updated.\n\t */\n\tpublic async updatePartial(\n\t\tauditableItemGraphDocumentId: string,\n\t\tblob?: Uint8Array,\n\t\tannotationObject?: IJsonLdNodeObject,\n\t\tauditableItemGraphEdges?: {\n\t\t\tadd?: IDocumentManagementEdgeEntry[];\n\t\t\tremove?: string[];\n\t\t}\n\t): Promise<void> {\n\t\tUrn.guard(\n\t\t\tDocumentManagementRestClient.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\n\t\tawait this.fetch<IDocumentManagementUpdatePartialRequest, INoContentResponse>(\n\t\t\t\"/:auditableItemGraphDocumentId\",\n\t\t\t\"PATCH\",\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tauditableItemGraphDocumentId\n\t\t\t\t},\n\t\t\t\tbody: {\n\t\t\t\t\tblob: Is.uint8Array(blob) ? Converter.bytesToBase64(blob) : undefined,\n\t\t\t\t\tannotationObject,\n\t\t\t\t\tauditableItemGraphEdges\n\t\t\t\t}\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.includeDeletedEdges Flag to include soft-deleted edges in the response, defaults to false.\n\t * @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.\n\t * @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.\n\t * @param cursor The cursor to get the next chunk of revisions.\n\t * @param limit The limit of items to return, defaults to 1 so only most recent is returned.\n\t * @returns The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.\n\t */\n\tpublic async get(\n\t\tauditableItemGraphDocumentId: string,\n\t\toptions?: {\n\t\t\tincludeBlobStorageMetadata?: boolean;\n\t\t\tincludeBlobStorageData?: boolean;\n\t\t\tincludeAttestation?: boolean;\n\t\t\tincludeRemoved?: boolean;\n\t\t\tincludeDeletedEdges?: boolean;\n\t\t\textractRuleGroupId?: string;\n\t\t\textractMimeType?: string;\n\t\t},\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\tentries: IDocumentList;\n\t\tcursor?: string;\n\t}> {\n\t\tUrn.guard(\n\t\t\tDocumentManagementRestClient.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\n\t\tconst response = await this.fetch<\n\t\t\tIDocumentManagementGetRequest,\n\t\t\tIDocumentManagementGetResponse\n\t\t>(\"/:auditableItemGraphDocumentId\", \"GET\", {\n\t\t\tpathParams: {\n\t\t\t\tauditableItemGraphDocumentId\n\t\t\t},\n\t\t\tquery: {\n\t\t\t\tincludeBlobStorageMetadata: Coerce.string(options?.includeBlobStorageMetadata),\n\t\t\t\tincludeBlobStorageData: Coerce.string(options?.includeBlobStorageData),\n\t\t\t\tincludeAttestation: Coerce.string(options?.includeAttestation),\n\t\t\t\tincludeRemoved: Coerce.string(options?.includeRemoved),\n\t\t\t\tincludeDeletedEdges: Coerce.string(options?.includeDeletedEdges),\n\t\t\t\textractRuleGroupId: options?.extractRuleGroupId,\n\t\t\t\textractMimeType: options?.extractMimeType,\n\t\t\t\tcursor,\n\t\t\t\tlimit: Coerce.string(limit)\n\t\t\t}\n\t\t});\n\n\t\treturn {\n\t\t\tentries: response.body,\n\t\t\tcursor: HeaderHelper.extractLinkHeaderRelation(response.headers?.[HeaderTypes.Link], \"next\")\n\t\t\t\t?.urlQueryParams?.cursor\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 document for the specified revision.\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\tDocumentManagementRestClient.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\t\tGuards.integer(DocumentManagementRestClient.CLASS_NAME, nameof(revision), revision);\n\n\t\tconst response = await this.fetch<\n\t\t\tIDocumentManagementGetRevisionRequest,\n\t\t\tIDocumentManagementGetRevisionResponse\n\t\t>(\"/:auditableItemGraphDocumentId/:revision\", \"GET\", {\n\t\t\tpathParams: {\n\t\t\t\tauditableItemGraphDocumentId,\n\t\t\t\trevision: revision.toString()\n\t\t\t},\n\t\t\tquery: {\n\t\t\t\tincludeBlobStorageMetadata: Coerce.string(options?.includeBlobStorageMetadata),\n\t\t\t\tincludeBlobStorageData: Coerce.string(options?.includeBlobStorageData),\n\t\t\t\tincludeAttestation: Coerce.string(options?.includeAttestation),\n\t\t\t\textractRuleGroupId: options?.extractRuleGroupId,\n\t\t\t\textractMimeType: options?.extractMimeType\n\t\t\t}\n\t\t});\n\n\t\treturn response.body;\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 A promise that resolves when the revision has been removed.\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\tDocumentManagementRestClient.CLASS_NAME,\n\t\t\tnameof(auditableItemGraphDocumentId),\n\t\t\tauditableItemGraphDocumentId\n\t\t);\n\t\tGuards.integer(DocumentManagementRestClient.CLASS_NAME, nameof(revision), revision);\n\n\t\tawait this.fetch<IDocumentManagementRemoveRequest, INoContentResponse>(\n\t\t\t\"/:auditableItemGraphDocumentId/:revision\",\n\t\t\t\"DELETE\",\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tauditableItemGraphDocumentId,\n\t\t\t\t\trevision: revision.toString()\n\t\t\t\t}\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(DocumentManagementRestClient.CLASS_NAME, nameof(documentId), documentId);\n\n\t\tconst response = await this.fetch<\n\t\t\tIDocumentManagementQueryRequest,\n\t\t\tIDocumentManagementQueryResponse\n\t\t>(\"/\", \"GET\", {\n\t\t\tquery: {\n\t\t\t\tdocumentId,\n\t\t\t\tcursor,\n\t\t\t\tlimit: Coerce.string(limit)\n\t\t\t}\n\t\t});\n\n\t\treturn {\n\t\t\tentries: response.body,\n\t\t\tcursor: HeaderHelper.extractLinkHeaderRelation(response.headers?.[HeaderTypes.Link], \"next\")\n\t\t\t\t?.urlQueryParams?.cursor\n\t\t};\n\t}\n}\n"]}
@@ -2,7 +2,7 @@ import { BaseRestClient } from "@twin.org/api-core";
2
2
  import type { IBaseRestClientConfig } from "@twin.org/api-models";
3
3
  import type { IAuditableItemGraphVertexList } from "@twin.org/auditable-item-graph-models";
4
4
  import type { IJsonLdNodeObject } from "@twin.org/data-json-ld";
5
- import type { IDocument, IDocumentList, IDocumentManagementComponent } from "@twin.org/document-management-models";
5
+ import type { IDocument, IDocumentList, IDocumentManagementComponent, IDocumentManagementEdgeEntry } from "@twin.org/document-management-models";
6
6
  import { UneceDocumentCodeList } from "@twin.org/standards-unece";
7
7
  /**
8
8
  * Client for performing document management through to REST endpoints.
@@ -38,11 +38,7 @@ export declare class DocumentManagementRestClient extends BaseRestClient impleme
38
38
  * @param options.aliasAnnotationObject Annotation object for the alias.
39
39
  * @returns The auditable item graph vertex created for the document including its revision.
40
40
  */
41
- create(documentId: string, documentIdFormat: string | undefined, documentCode: UneceDocumentCodeList, blob: Uint8Array, annotationObject?: IJsonLdNodeObject, auditableItemGraphEdges?: {
42
- targetId: string;
43
- addAlias?: boolean;
44
- aliasAnnotationObject?: IJsonLdNodeObject;
45
- }[], options?: {
41
+ create(documentId: string, documentIdFormat: string | undefined, documentCode: UneceDocumentCodeList, blob: Uint8Array, annotationObject?: IJsonLdNodeObject, auditableItemGraphEdges?: IDocumentManagementEdgeEntry[], options?: {
46
42
  createAttestation?: boolean;
47
43
  addAlias?: boolean;
48
44
  aliasAnnotationObject?: IJsonLdNodeObject;
@@ -54,14 +50,19 @@ export declare class DocumentManagementRestClient extends BaseRestClient impleme
54
50
  * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
55
51
  * @param blob The data to update the document with.
56
52
  * @param annotationObject Additional information to associate with the document.
57
- * @param auditableItemGraphEdges The auditable item graph vertices to connect the document to, if undefined retains current connections.
58
- * @returns Nothing.
53
+ * @param auditableItemGraphEdges Explicit edge delta to apply. If undefined, existing connections
54
+ * are retained unchanged. Use `add` to create new connections and `remove` to disconnect existing
55
+ * ones by their target vertex id. To update alias metadata on an already-connected vertex, include
56
+ * it in `add` with the updated `aliasAnnotationObject` — AIG's alias patch is an upsert, so the
57
+ * alias is updated in place without creating a duplicate back-edge.
58
+ * @param auditableItemGraphEdges.add Connections to add; each creates a back-edge on the connected vertex.
59
+ * @param auditableItemGraphEdges.remove Target vertex IDs to disconnect; their back-edges are removed.
60
+ * @returns A promise that resolves when the document has been updated.
59
61
  */
60
- update(auditableItemGraphDocumentId: string, blob?: Uint8Array, annotationObject?: IJsonLdNodeObject, auditableItemGraphEdges?: {
61
- targetId: string;
62
- addAlias?: boolean;
63
- aliasAnnotationObject?: IJsonLdNodeObject;
64
- }[]): Promise<void>;
62
+ updatePartial(auditableItemGraphDocumentId: string, blob?: Uint8Array, annotationObject?: IJsonLdNodeObject, auditableItemGraphEdges?: {
63
+ add?: IDocumentManagementEdgeEntry[];
64
+ remove?: string[];
65
+ }): Promise<void>;
65
66
  /**
66
67
  * Get a document using it's auditable item graph vertex id and optional revision.
67
68
  * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
@@ -70,6 +71,7 @@ export declare class DocumentManagementRestClient extends BaseRestClient impleme
70
71
  * @param options.includeBlobStorageData Flag to include the blob storage data for the document, defaults to false.
71
72
  * @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.
72
73
  * @param options.includeRemoved Flag to include deleted documents, defaults to false.
74
+ * @param options.includeDeletedEdges Flag to include soft-deleted edges in the response, defaults to false.
73
75
  * @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.
74
76
  * @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.
75
77
  * @param cursor The cursor to get the next chunk of revisions.
@@ -81,6 +83,7 @@ export declare class DocumentManagementRestClient extends BaseRestClient impleme
81
83
  includeBlobStorageData?: boolean;
82
84
  includeAttestation?: boolean;
83
85
  includeRemoved?: boolean;
86
+ includeDeletedEdges?: boolean;
84
87
  extractRuleGroupId?: string;
85
88
  extractMimeType?: string;
86
89
  }, cursor?: string, limit?: number): Promise<{
@@ -97,7 +100,7 @@ export declare class DocumentManagementRestClient extends BaseRestClient impleme
97
100
  * @param options.includeAttestation Flag to include the attestation information for the document, defaults to false.
98
101
  * @param options.extractRuleGroupId If provided will extract data from the document using the specified rule group id.
99
102
  * @param options.extractMimeType By default extraction will auto detect the mime type of the document, this can be used to override the detection.
100
- * @returns The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.
103
+ * @returns The document for the specified revision.
101
104
  */
102
105
  getRevision(auditableItemGraphDocumentId: string, revision: number, options?: {
103
106
  includeBlobStorageMetadata?: boolean;
@@ -111,7 +114,7 @@ export declare class DocumentManagementRestClient extends BaseRestClient impleme
111
114
  * The document dateDeleted will be set, but can still be queried with the includeRemoved flag.
112
115
  * @param auditableItemGraphDocumentId The auditable item graph vertex id which contains the document.
113
116
  * @param revision The revision of the document to remove.
114
- * @returns Nothing.
117
+ * @returns A promise that resolves when the revision has been removed.
115
118
  */
116
119
  removeRevision(auditableItemGraphDocumentId: string, revision: number): Promise<void>;
117
120
  /**
package/docs/changelog.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.17](https://github.com/iotaledger/twin-document-management/compare/document-management-rest-client-v0.0.3-next.16...document-management-rest-client-v0.0.3-next.17) (2026-06-18)
4
+
5
+
6
+ ### Miscellaneous Chores
7
+
8
+ * **document-management-rest-client:** Synchronize repo versions
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.16 to 0.0.3-next.17
16
+
17
+ ## [0.0.3-next.16](https://github.com/iotaledger/twin-document-management/compare/document-management-rest-client-v0.0.3-next.15...document-management-rest-client-v0.0.3-next.16) (2026-06-04)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * replace destructive update() with updatePartial() for edge linking ([#50](https://github.com/iotaledger/twin-document-management/issues/50)) ([c1d2c33](https://github.com/iotaledger/twin-document-management/commit/c1d2c337c371bdcc1f23cac482393468ef84f0d7))
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.15 to 0.0.3-next.16
30
+
3
31
  ## [0.0.3-next.15](https://github.com/iotaledger/twin-document-management/compare/document-management-rest-client-v0.0.3-next.14...document-management-rest-client-v0.0.3-next.15) (2026-05-22)
4
32
 
5
33
 
@@ -104,7 +104,7 @@ Additional information to associate with the document.
104
104
 
105
105
  ##### auditableItemGraphEdges?
106
106
 
107
- `object`[]
107
+ `IDocumentManagementEdgeEntry`[]
108
108
 
109
109
  The auditable item graph vertices to connect the document to.
110
110
 
@@ -142,9 +142,9 @@ The auditable item graph vertex created for the document including its revision.
142
142
 
143
143
  ***
144
144
 
145
- ### update() {#update}
145
+ ### updatePartial() {#updatepartial}
146
146
 
147
- > **update**(`auditableItemGraphDocumentId`, `blob?`, `annotationObject?`, `auditableItemGraphEdges?`): `Promise`\<`void`\>
147
+ > **updatePartial**(`auditableItemGraphDocumentId`, `blob?`, `annotationObject?`, `auditableItemGraphEdges?`): `Promise`\<`void`\>
148
148
 
149
149
  Update a document as an auditable item graph vertex and add its content to blob storage.
150
150
  If the blob data is different a new revision will be created.
@@ -172,19 +172,33 @@ Additional information to associate with the document.
172
172
 
173
173
  ##### auditableItemGraphEdges?
174
174
 
175
- `object`[]
175
+ Explicit edge delta to apply. If undefined, existing connections
176
+ are retained unchanged. Use `add` to create new connections and `remove` to disconnect existing
177
+ ones by their target vertex id. To update alias metadata on an already-connected vertex, include
178
+ it in `add` with the updated `aliasAnnotationObject` — AIG's alias patch is an upsert, so the
179
+ alias is updated in place without creating a duplicate back-edge.
176
180
 
177
- The auditable item graph vertices to connect the document to, if undefined retains current connections.
181
+ ###### add?
182
+
183
+ `IDocumentManagementEdgeEntry`[]
184
+
185
+ Connections to add; each creates a back-edge on the connected vertex.
186
+
187
+ ###### remove?
188
+
189
+ `string`[]
190
+
191
+ Target vertex IDs to disconnect; their back-edges are removed.
178
192
 
179
193
  #### Returns
180
194
 
181
195
  `Promise`\<`void`\>
182
196
 
183
- Nothing.
197
+ A promise that resolves when the document has been updated.
184
198
 
185
199
  #### Implementation of
186
200
 
187
- `IDocumentManagementComponent.update`
201
+ `IDocumentManagementComponent.updatePartial`
188
202
 
189
203
  ***
190
204
 
@@ -230,6 +244,12 @@ Flag to include the attestation information for the document, defaults to false.
230
244
 
231
245
  Flag to include deleted documents, defaults to false.
232
246
 
247
+ ###### includeDeletedEdges?
248
+
249
+ `boolean`
250
+
251
+ Flag to include soft-deleted edges in the response, defaults to false.
252
+
233
253
  ###### extractRuleGroupId?
234
254
 
235
255
  `string`
@@ -324,7 +344,7 @@ By default extraction will auto detect the mime type of the document, this can b
324
344
 
325
345
  `Promise`\<`IDocument`\>
326
346
 
327
- The documents and revisions if requested, ordered by revision descending, cursor is set if there are more document revisions.
347
+ The document for the specified revision.
328
348
 
329
349
  #### Implementation of
330
350
 
@@ -357,7 +377,7 @@ The revision of the document to remove.
357
377
 
358
378
  `Promise`\<`void`\>
359
379
 
360
- Nothing.
380
+ A promise that resolves when the revision has been removed.
361
381
 
362
382
  #### Implementation of
363
383
 
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@twin.org/document-management-rest-client",
3
- "version": "0.0.3-next.15",
3
+ "version": "0.0.3-next.17",
4
4
  "description": "REST client operations for creating, updating, retrieving, and querying managed documents.",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/iotaledger/document-management.git",
7
+ "url": "git+https://github.com/iotaledger/twin-document-management.git",
8
8
  "directory": "packages/document-management-rest-client"
9
9
  },
10
10
  "author": "martyn.janes@iota.org",
@@ -19,7 +19,7 @@
19
19
  "@twin.org/auditable-item-graph-models": "next",
20
20
  "@twin.org/core": "next",
21
21
  "@twin.org/data-json-ld": "next",
22
- "@twin.org/document-management-models": "0.0.3-next.15",
22
+ "@twin.org/document-management-models": "0.0.3-next.17",
23
23
  "@twin.org/entity": "next",
24
24
  "@twin.org/nameof": "next",
25
25
  "@twin.org/standards-unece": "next",
@@ -54,7 +54,7 @@
54
54
  "rest-api"
55
55
  ],
56
56
  "bugs": {
57
- "url": "git+https://github.com/iotaledger/document-management/issues"
57
+ "url": "git+https://github.com/iotaledger/twin-document-management/issues"
58
58
  },
59
59
  "homepage": "https://twindev.org"
60
60
  }