@twin.org/auditable-item-graph-rest-client 0.0.3-next.2 → 0.0.3-next.21
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 +3 -1
- package/dist/es/auditableItemGraphRestClient.js +130 -12
- package/dist/es/auditableItemGraphRestClient.js.map +1 -1
- package/dist/types/auditableItemGraphRestClient.d.ts +61 -49
- package/docs/changelog.md +339 -54
- package/docs/examples.md +119 -1
- package/docs/reference/classes/AuditableItemGraphRestClient.md +181 -69
- package/locales/en.json +1 -7
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# TWIN Auditable Item Graph REST Client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package offers a straightforward client for sending auditable graph requests to compatible HTTP endpoints.
|
|
4
|
+
|
|
5
|
+
It helps applications consume graph, changeset, and query operations without reimplementing request and response handling.
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
3
|
import { BaseRestClient } from "@twin.org/api-core";
|
|
4
4
|
import { HttpParameterHelper } from "@twin.org/api-models";
|
|
5
|
-
import { Coerce, Guards,
|
|
6
|
-
import { HeaderTypes, MimeTypes } from "@twin.org/web";
|
|
5
|
+
import { Coerce, Guards, Urn } from "@twin.org/core";
|
|
6
|
+
import { HeaderHelper, HeaderTypes, MimeTypes } from "@twin.org/web";
|
|
7
7
|
/**
|
|
8
8
|
* Client for performing auditable item graph through to REST endpoints.
|
|
9
9
|
*/
|
|
@@ -46,7 +46,6 @@ export class AuditableItemGraphRestClient extends BaseRestClient {
|
|
|
46
46
|
* @param id The id of the vertex to get.
|
|
47
47
|
* @param options Additional options for the get operation.
|
|
48
48
|
* @param options.includeDeleted Whether to include deleted/updated aliases, resource, edges, defaults to false.
|
|
49
|
-
* @param options.includeChangesets Whether to include the changesets of the vertex, defaults to false.
|
|
50
49
|
* @param options.verifySignatureDepth How many signatures to verify, defaults to "none".
|
|
51
50
|
* @returns The vertex if found.
|
|
52
51
|
* @throws NotFoundError if the vertex is not found.
|
|
@@ -62,14 +61,124 @@ export class AuditableItemGraphRestClient extends BaseRestClient {
|
|
|
62
61
|
},
|
|
63
62
|
query: {
|
|
64
63
|
includeDeleted: Coerce.string(options?.includeDeleted),
|
|
65
|
-
includeChangesets: Coerce.string(options?.includeChangesets),
|
|
66
64
|
verifySignatureDepth: options?.verifySignatureDepth
|
|
67
65
|
}
|
|
68
66
|
});
|
|
69
67
|
return response.body;
|
|
70
68
|
}
|
|
71
69
|
/**
|
|
72
|
-
*
|
|
70
|
+
* Get a graph vertex changeset list.
|
|
71
|
+
* @param id The id of the vertex to get.
|
|
72
|
+
* @param cursor The optional cursor to get next chunk.
|
|
73
|
+
* @param limit Limit the number of entities to return.
|
|
74
|
+
* @param options Additional options for the get operation.
|
|
75
|
+
* @param options.verifySignatureDepth How many signatures to verify, defaults to "none".
|
|
76
|
+
* @returns The changesets if found.
|
|
77
|
+
*/
|
|
78
|
+
async getChangesets(id, cursor, limit, options) {
|
|
79
|
+
Guards.stringValue(AuditableItemGraphRestClient.CLASS_NAME, "id", id);
|
|
80
|
+
const response = await this.fetch("/:id/changesets", "GET", {
|
|
81
|
+
headers: {
|
|
82
|
+
[HeaderTypes.Accept]: MimeTypes.JsonLd
|
|
83
|
+
},
|
|
84
|
+
pathParams: {
|
|
85
|
+
id
|
|
86
|
+
},
|
|
87
|
+
query: {
|
|
88
|
+
cursor,
|
|
89
|
+
limit: Coerce.string(limit),
|
|
90
|
+
verifySignatureDepth: options?.verifySignatureDepth
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
changesets: response.body,
|
|
95
|
+
cursor: HeaderHelper.extractLinkHeaderRelation(response.headers?.[HeaderTypes.Link], "next")
|
|
96
|
+
?.urlQueryParams?.cursor
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get a graph vertex changeset.
|
|
101
|
+
* @param id The id of the vertex to get.
|
|
102
|
+
* @param options Additional options for the get operation.
|
|
103
|
+
* @param options.verifySignatureDepth How many signatures to verify, defaults to "none".
|
|
104
|
+
* @returns The changeset if found.
|
|
105
|
+
* @throws NotFoundError if the vertex or changeset is not found.
|
|
106
|
+
*/
|
|
107
|
+
async getChangeset(id, options) {
|
|
108
|
+
Guards.stringValue(AuditableItemGraphRestClient.CLASS_NAME, "id", id);
|
|
109
|
+
const urnParsed = Urn.fromValidString(id);
|
|
110
|
+
const namespaceSpecificParts = urnParsed.namespaceSpecificParts();
|
|
111
|
+
const vertexId = namespaceSpecificParts[0];
|
|
112
|
+
const changesetId = namespaceSpecificParts[2];
|
|
113
|
+
Guards.stringValue(AuditableItemGraphRestClient.CLASS_NAME, "vertexId", vertexId);
|
|
114
|
+
Guards.stringValue(AuditableItemGraphRestClient.CLASS_NAME, "changesetId", changesetId);
|
|
115
|
+
const response = await this.fetch("/:id/changesets/:changesetId", "GET", {
|
|
116
|
+
headers: {
|
|
117
|
+
[HeaderTypes.Accept]: MimeTypes.JsonLd
|
|
118
|
+
},
|
|
119
|
+
pathParams: {
|
|
120
|
+
id: vertexId,
|
|
121
|
+
changesetId
|
|
122
|
+
},
|
|
123
|
+
query: {
|
|
124
|
+
verifySignatureDepth: options?.verifySignatureDepth
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
return response.body;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get a graph vertex at a specific version.
|
|
131
|
+
* @param id The id of the vertex.
|
|
132
|
+
* @param version The version number to retrieve.
|
|
133
|
+
* @returns The vertex reconstructed at that version.
|
|
134
|
+
* @throws NotFoundError if the vertex or version is not found.
|
|
135
|
+
*/
|
|
136
|
+
async getVersion(id, version) {
|
|
137
|
+
Guards.stringValue(AuditableItemGraphRestClient.CLASS_NAME, "id", id);
|
|
138
|
+
Guards.integer(AuditableItemGraphRestClient.CLASS_NAME, "version", version);
|
|
139
|
+
const urnParsed = Urn.fromValidString(id);
|
|
140
|
+
const vertexId = urnParsed.namespaceSpecific(0);
|
|
141
|
+
Guards.stringValue(AuditableItemGraphRestClient.CLASS_NAME, "vertexId", vertexId);
|
|
142
|
+
const response = await this.fetch("/:id/versions/:version", "GET", {
|
|
143
|
+
headers: {
|
|
144
|
+
[HeaderTypes.Accept]: MimeTypes.JsonLd
|
|
145
|
+
},
|
|
146
|
+
pathParams: {
|
|
147
|
+
id: vertexId,
|
|
148
|
+
version: version.toString()
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
return response.body;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get all versions of a graph vertex.
|
|
155
|
+
* @param id The id of the vertex.
|
|
156
|
+
* @param options Additional options for the operation.
|
|
157
|
+
* @param options.after Only return versions created after this ISO 8601 timestamp (exclusive).
|
|
158
|
+
* @param options.before Only return versions created before this ISO 8601 timestamp (exclusive).
|
|
159
|
+
* @returns The list of vertex versions.
|
|
160
|
+
* @throws NotFoundError if the vertex is not found.
|
|
161
|
+
*/
|
|
162
|
+
async getVersions(id, options) {
|
|
163
|
+
Guards.stringValue(AuditableItemGraphRestClient.CLASS_NAME, "id", id);
|
|
164
|
+
const response = await this.fetch("/:id/versions", "GET", {
|
|
165
|
+
headers: {
|
|
166
|
+
[HeaderTypes.Accept]: MimeTypes.JsonLd
|
|
167
|
+
},
|
|
168
|
+
pathParams: {
|
|
169
|
+
id
|
|
170
|
+
},
|
|
171
|
+
query: {
|
|
172
|
+
after: options?.after,
|
|
173
|
+
before: options?.before
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
return response.body;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Update a graph vertex (PUT — full replacement of vertex state).
|
|
180
|
+
* The server serializes concurrent updates for the same vertex via `Mutex` on the vertex id;
|
|
181
|
+
* requests load-balanced across replicas can still race.
|
|
73
182
|
* @param vertex The vertex to update.
|
|
74
183
|
* @param vertex.id The id of the vertex to update.
|
|
75
184
|
* @param vertex.annotationObject The annotation object for the vertex as JSON-LD.
|
|
@@ -90,14 +199,19 @@ export class AuditableItemGraphRestClient extends BaseRestClient {
|
|
|
90
199
|
});
|
|
91
200
|
}
|
|
92
201
|
/**
|
|
93
|
-
*
|
|
94
|
-
* @param
|
|
202
|
+
* Partially update a graph vertex (PATCH — optional scalars; list fields use `{ add, remove }`).
|
|
203
|
+
* @param partial The partial vertex update (must include `id`).
|
|
95
204
|
* @returns Nothing.
|
|
96
|
-
* @throws NotFoundError if the vertex is not found.
|
|
97
205
|
*/
|
|
98
|
-
async
|
|
99
|
-
|
|
100
|
-
|
|
206
|
+
async updatePartial(partial) {
|
|
207
|
+
Guards.object(AuditableItemGraphRestClient.CLASS_NAME, "partial", partial);
|
|
208
|
+
Guards.stringValue(AuditableItemGraphRestClient.CLASS_NAME, "partial.id", partial.id);
|
|
209
|
+
const { id, ...body } = partial;
|
|
210
|
+
await this.fetch("/:id", "PATCH", {
|
|
211
|
+
pathParams: {
|
|
212
|
+
id
|
|
213
|
+
},
|
|
214
|
+
body
|
|
101
215
|
});
|
|
102
216
|
}
|
|
103
217
|
/**
|
|
@@ -133,7 +247,11 @@ export class AuditableItemGraphRestClient extends BaseRestClient {
|
|
|
133
247
|
limit: Coerce.string(limit)
|
|
134
248
|
}
|
|
135
249
|
});
|
|
136
|
-
return
|
|
250
|
+
return {
|
|
251
|
+
entries: response.body,
|
|
252
|
+
cursor: HeaderHelper.extractLinkHeaderRelation(response.headers?.[HeaderTypes.Link], "next")
|
|
253
|
+
?.urlQueryParams?.cursor
|
|
254
|
+
};
|
|
137
255
|
}
|
|
138
256
|
}
|
|
139
257
|
//# sourceMappingURL=auditableItemGraphRestClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auditableItemGraphRestClient.js","sourceRoot":"","sources":["../../src/auditableItemGraphRestClient.ts"],"names":[],"mappings":"AAAA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E,OAAO,CAAC;gBACxC,aAAa,EAAE,mBAAmB,CAAC,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC;gBACxE,UAAU,EAAE,mBAAmB,CAAC,cAAc,CAAC,UAAU,CAAC;gBAC1D,OAAO;gBACP,gBAAgB;gBAChB,UAAU,EAAE,mBAAmB,CAAC,aAAa,CAAC,UAAU,CAAC;gBACzD,MAAM;gBACN,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;aAC3B;SACD,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC,IAAI,CAAC;IACtB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseRestClient } from \"@twin.org/api-core\";\nimport {\n\tHttpParameterHelper,\n\ttype IBaseRestClientConfig,\n\ttype ICreatedResponse,\n\ttype INoContentResponse\n} from \"@twin.org/api-models\";\nimport type {\n\tIAuditableItemGraphComponent,\n\tIAuditableItemGraphCreateRequest,\n\tIAuditableItemGraphGetRequest,\n\tIAuditableItemGraphGetResponse,\n\tIAuditableItemGraphListRequest,\n\tIAuditableItemGraphListResponse,\n\tIAuditableItemGraphUpdateRequest,\n\tIAuditableItemGraphVertex,\n\tIAuditableItemGraphVertexList,\n\tVerifyDepth\n} from \"@twin.org/auditable-item-graph-models\";\nimport { Coerce, Guards, NotSupportedError } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport type { IComparator, SortDirection } from \"@twin.org/entity\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { HeaderTypes, MimeTypes } from \"@twin.org/web\";\n\n/**\n * Client for performing auditable item graph through to REST endpoints.\n */\nexport class AuditableItemGraphRestClient\n\textends BaseRestClient\n\timplements IAuditableItemGraphComponent\n{\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<AuditableItemGraphRestClient>();\n\n\t/**\n\t * Create a new instance of AuditableItemGraphRestClient.\n\t * @param config The configuration for the client.\n\t */\n\tconstructor(config: IBaseRestClientConfig) {\n\t\tsuper(nameof<AuditableItemGraphRestClient>(), config, \"auditable-item-graph\");\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 AuditableItemGraphRestClient.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create a new graph vertex.\n\t * @param vertex The vertex to create.\n\t * @param vertex.annotationObject The annotation object for the vertex as JSON-LD.\n\t * @param vertex.aliases Alternative aliases that can be used to identify the vertex.\n\t * @param vertex.resources The resources attached to the vertex.\n\t * @param vertex.edges The edges connected to the vertex.\n\t * @returns The id of the new graph item.\n\t */\n\tpublic async create(vertex: {\n\t\tannotationObject?: IJsonLdNodeObject;\n\t\taliases?: {\n\t\t\tid: string;\n\t\t\taliasFormat?: string;\n\t\t\tunique?: boolean;\n\t\t\tannotationObject?: IJsonLdNodeObject;\n\t\t}[];\n\t\tresources?: {\n\t\t\tid?: string;\n\t\t\tresourceObject?: IJsonLdNodeObject;\n\t\t}[];\n\t\tedges?: {\n\t\t\ttargetId: string;\n\t\t\tedgeRelationships: string[];\n\t\t\tannotationObject?: IJsonLdNodeObject;\n\t\t}[];\n\t}): Promise<string> {\n\t\tconst response = await this.fetch<IAuditableItemGraphCreateRequest, ICreatedResponse>(\n\t\t\t\"/\",\n\t\t\t\"POST\",\n\t\t\t{\n\t\t\t\tbody: vertex\n\t\t\t}\n\t\t);\n\n\t\treturn response.headers[HeaderTypes.Location];\n\t}\n\n\t/**\n\t * Get a graph vertex.\n\t * @param id The id of the vertex to get.\n\t * @param options Additional options for the get operation.\n\t * @param options.includeDeleted Whether to include deleted/updated aliases, resource, edges, defaults to false.\n\t * @param options.includeChangesets Whether to include the changesets of the vertex, defaults to false.\n\t * @param options.verifySignatureDepth How many signatures to verify, defaults to \"none\".\n\t * @returns The vertex if found.\n\t * @throws NotFoundError if the vertex is not found.\n\t */\n\tpublic async get(\n\t\tid: string,\n\t\toptions?: {\n\t\t\tincludeDeleted?: boolean;\n\t\t\tincludeChangesets?: boolean;\n\t\t\tverifySignatureDepth?: VerifyDepth;\n\t\t}\n\t): Promise<IAuditableItemGraphVertex> {\n\t\tGuards.stringValue(AuditableItemGraphRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tconst response = await this.fetch<\n\t\t\tIAuditableItemGraphGetRequest,\n\t\t\tIAuditableItemGraphGetResponse\n\t\t>(\"/:id\", \"GET\", {\n\t\t\theaders: {\n\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t},\n\t\t\tpathParams: {\n\t\t\t\tid\n\t\t\t},\n\t\t\tquery: {\n\t\t\t\tincludeDeleted: Coerce.string(options?.includeDeleted),\n\t\t\t\tincludeChangesets: Coerce.string(options?.includeChangesets),\n\t\t\t\tverifySignatureDepth: options?.verifySignatureDepth\n\t\t\t}\n\t\t});\n\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Update a graph vertex.\n\t * @param vertex The vertex to update.\n\t * @param vertex.id The id of the vertex to update.\n\t * @param vertex.annotationObject The annotation object for the vertex as JSON-LD.\n\t * @param vertex.aliases Alternative aliases that can be used to identify the vertex.\n\t * @param vertex.resources The resources attached to the vertex.\n\t * @param vertex.edges The edges connected to the vertex.\n\t * @returns Nothing.\n\t */\n\tpublic async update(vertex: {\n\t\tid: string;\n\t\tannotationObject?: IJsonLdNodeObject;\n\t\taliases?: {\n\t\t\tid: string;\n\t\t\taliasFormat?: string;\n\t\t\tunique?: boolean;\n\t\t\tannotationObject?: IJsonLdNodeObject;\n\t\t}[];\n\t\tresources?: {\n\t\t\tid?: string;\n\t\t\tresourceObject?: IJsonLdNodeObject;\n\t\t}[];\n\t\tedges?: {\n\t\t\tid?: string;\n\t\t\ttargetId: string;\n\t\t\tedgeRelationships: string[];\n\t\t\tannotationObject?: IJsonLdNodeObject;\n\t\t}[];\n\t}): Promise<void> {\n\t\tGuards.object(AuditableItemGraphRestClient.CLASS_NAME, nameof(vertex), vertex);\n\t\tGuards.stringValue(AuditableItemGraphRestClient.CLASS_NAME, nameof(vertex.id), vertex.id);\n\n\t\tconst { id, ...rest } = vertex;\n\n\t\tawait this.fetch<IAuditableItemGraphUpdateRequest, INoContentResponse>(\"/:id\", \"PUT\", {\n\t\t\tpathParams: {\n\t\t\t\tid\n\t\t\t},\n\t\t\tbody: rest\n\t\t});\n\t}\n\n\t/**\n\t * Remove the verifiable storage for an item, not supported on client.\n\t * @param id The id of the vertex to get.\n\t * @returns Nothing.\n\t * @throws NotFoundError if the vertex is not found.\n\t */\n\tpublic async removeVerifiable(id: string): Promise<void> {\n\t\tthrow new NotSupportedError(AuditableItemGraphRestClient.CLASS_NAME, \"notSupportedOnClient\", {\n\t\t\tmethodName: \"removeVerifiable\"\n\t\t});\n\t}\n\n\t/**\n\t * Query the graph for vertices.\n\t * @param options The query options.\n\t * @param options.id The optional id to look for.\n\t * @param options.idMode Look in id, alias or both, defaults to both.\n\t * @param options.idExact Find only exact matches, default to false meaning partial matching.\n\t * @param options.resourceTypes Include vertices with specific resource types.\n\t * @param conditions Conditions to use in the query.\n\t * @param orderBy The order for the results, defaults to created.\n\t * @param orderByDirection The direction for the order, defaults to descending.\n\t * @param properties The properties to return, if not provided defaults to id, created, aliases and object.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit Limit the number of entities to return.\n\t * @returns The entities, which can be partial if a limited keys list was provided.\n\t */\n\tpublic async query(\n\t\toptions?: {\n\t\t\tid?: string;\n\t\t\tidMode?: \"id\" | \"alias\" | \"both\";\n\t\t\tidExact?: boolean;\n\t\t\tresourceTypes?: string[];\n\t\t},\n\t\tconditions?: IComparator[],\n\t\torderBy?: keyof Pick<IAuditableItemGraphVertex, \"dateCreated\" | \"dateModified\">,\n\t\torderByDirection?: SortDirection,\n\t\tproperties?: (keyof IAuditableItemGraphVertex)[],\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<IAuditableItemGraphVertexList> {\n\t\tconst response = await this.fetch<\n\t\t\tIAuditableItemGraphListRequest,\n\t\t\tIAuditableItemGraphListResponse\n\t\t>(\"/\", \"GET\", {\n\t\t\theaders: {\n\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t},\n\t\t\tquery: {\n\t\t\t\tid: options?.id,\n\t\t\t\tidMode: options?.idMode,\n\t\t\t\tidExact: Coerce.string(options?.idExact),\n\t\t\t\tresourceTypes: HttpParameterHelper.arrayToString(options?.resourceTypes),\n\t\t\t\tconditions: HttpParameterHelper.objectToString(conditions),\n\t\t\t\torderBy,\n\t\t\t\torderByDirection,\n\t\t\t\tproperties: HttpParameterHelper.arrayToString(properties),\n\t\t\t\tcursor,\n\t\t\t\tlimit: Coerce.string(limit)\n\t\t\t}\n\t\t});\n\n\t\treturn response.body;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"auditableItemGraphRestClient.js","sourceRoot":"","sources":["../../src/auditableItemGraphRestClient.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EACN,mBAAmB,EAInB,MAAM,sBAAsB,CAAC;AA0B9B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAGrD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAErE;;GAEG;AACH,MAAM,OAAO,4BACZ,SAAQ,cAAc;IAGtB;;OAEG;IACI,MAAM,CAAU,UAAU,kCAAkD;IAEnF;;;OAGG;IACH,YAAY,MAA6B;QACxC,KAAK,iCAAyC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IAC/E,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,4BAA4B,CAAC,UAAU,CAAC;IAChD,CAAC;IAED;;;;;;;;OAQG;IACI,KAAK,CAAC,MAAM,CAAC,MAA6C;QAChE,MAAM,QAAQ,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AAC,OAAO,EAAE,OAAO,CAAC;gBACxC,aAAa,EAAE,mBAAmB,CAAC,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC;gBACxE,UAAU,EAAE,mBAAmB,CAAC,cAAc,CAAC,UAAU,CAAC;gBAC1D,OAAO;gBACP,gBAAgB;gBAChB,UAAU,EAAE,mBAAmB,CAAC,aAAa,CAAC,UAAU,CAAC;gBACzD,MAAM;gBACN,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;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 {\n\tHttpParameterHelper,\n\ttype IBaseRestClientConfig,\n\ttype ICreatedResponse,\n\ttype INoContentResponse\n} from \"@twin.org/api-models\";\nimport type {\n\tIAuditableItemGraphChangeset,\n\tIAuditableItemGraphChangesetGetRequest,\n\tIAuditableItemGraphChangesetGetResponse,\n\tIAuditableItemGraphChangesetList,\n\tIAuditableItemGraphChangesetListRequest,\n\tIAuditableItemGraphChangesetListResponse,\n\tIAuditableItemGraphComponent,\n\tIAuditableItemGraphCreateRequest,\n\tIAuditableItemGraphGetRequest,\n\tIAuditableItemGraphGetResponse,\n\tIAuditableItemGraphListRequest,\n\tIAuditableItemGraphListResponse,\n\tIAuditableItemGraphPartialVertex,\n\tIAuditableItemGraphUpdatePartialRequest,\n\tIAuditableItemGraphUpdateRequest,\n\tIAuditableItemGraphVersionGetRequest,\n\tIAuditableItemGraphVersionGetResponse,\n\tIAuditableItemGraphVersionListRequest,\n\tIAuditableItemGraphVersionListResponse,\n\tIAuditableItemGraphVertex,\n\tIAuditableItemGraphVertexList,\n\tIAuditableItemGraphVertexVersionList,\n\tVerifyDepth\n} from \"@twin.org/auditable-item-graph-models\";\nimport { Coerce, Guards, Urn } from \"@twin.org/core\";\nimport type { IComparator, SortDirection } from \"@twin.org/entity\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { HeaderHelper, HeaderTypes, MimeTypes } from \"@twin.org/web\";\n\n/**\n * Client for performing auditable item graph through to REST endpoints.\n */\nexport class AuditableItemGraphRestClient\n\textends BaseRestClient\n\timplements Omit<IAuditableItemGraphComponent, \"removeProof\">\n{\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<AuditableItemGraphRestClient>();\n\n\t/**\n\t * Create a new instance of AuditableItemGraphRestClient.\n\t * @param config The configuration for the client.\n\t */\n\tconstructor(config: IBaseRestClientConfig) {\n\t\tsuper(nameof<AuditableItemGraphRestClient>(), config, \"auditable-item-graph\");\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 AuditableItemGraphRestClient.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create a new graph vertex.\n\t * @param vertex The vertex to create.\n\t * @param vertex.annotationObject The annotation object for the vertex as JSON-LD.\n\t * @param vertex.aliases Alternative aliases that can be used to identify the vertex.\n\t * @param vertex.resources The resources attached to the vertex.\n\t * @param vertex.edges The edges connected to the vertex.\n\t * @returns The id of the new graph item.\n\t */\n\tpublic async create(vertex: Omit<IAuditableItemGraphVertex, \"id\">): Promise<string> {\n\t\tconst response = await this.fetch<IAuditableItemGraphCreateRequest, ICreatedResponse>(\n\t\t\t\"/\",\n\t\t\t\"POST\",\n\t\t\t{\n\t\t\t\tbody: vertex\n\t\t\t}\n\t\t);\n\n\t\treturn response.headers[HeaderTypes.Location];\n\t}\n\n\t/**\n\t * Get a graph vertex.\n\t * @param id The id of the vertex to get.\n\t * @param options Additional options for the get operation.\n\t * @param options.includeDeleted Whether to include deleted/updated aliases, resource, edges, defaults to false.\n\t * @param options.verifySignatureDepth How many signatures to verify, defaults to \"none\".\n\t * @returns The vertex if found.\n\t * @throws NotFoundError if the vertex is not found.\n\t */\n\tpublic async get(\n\t\tid: string,\n\t\toptions?: {\n\t\t\tincludeDeleted?: boolean;\n\t\t\tverifySignatureDepth?: VerifyDepth;\n\t\t}\n\t): Promise<IAuditableItemGraphVertex> {\n\t\tGuards.stringValue(AuditableItemGraphRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tconst response = await this.fetch<\n\t\t\tIAuditableItemGraphGetRequest,\n\t\t\tIAuditableItemGraphGetResponse\n\t\t>(\"/:id\", \"GET\", {\n\t\t\theaders: {\n\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t},\n\t\t\tpathParams: {\n\t\t\t\tid\n\t\t\t},\n\t\t\tquery: {\n\t\t\t\tincludeDeleted: Coerce.string(options?.includeDeleted),\n\t\t\t\tverifySignatureDepth: options?.verifySignatureDepth\n\t\t\t}\n\t\t});\n\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Get a graph vertex changeset list.\n\t * @param id The id of the vertex to get.\n\t * @param cursor The optional cursor to get next chunk.\n\t * @param limit Limit the number of entities to return.\n\t * @param options Additional options for the get operation.\n\t * @param options.verifySignatureDepth How many signatures to verify, defaults to \"none\".\n\t * @returns The changesets if found.\n\t */\n\tpublic async getChangesets(\n\t\tid: string,\n\t\tcursor?: string,\n\t\tlimit?: number,\n\t\toptions?: {\n\t\t\tverifySignatureDepth?: VerifyDepth;\n\t\t}\n\t): Promise<{\n\t\tchangesets: IAuditableItemGraphChangesetList;\n\t\tcursor?: string;\n\t}> {\n\t\tGuards.stringValue(AuditableItemGraphRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tconst response = await this.fetch<\n\t\t\tIAuditableItemGraphChangesetListRequest,\n\t\t\tIAuditableItemGraphChangesetListResponse\n\t\t>(\"/:id/changesets\", \"GET\", {\n\t\t\theaders: {\n\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t},\n\t\t\tpathParams: {\n\t\t\t\tid\n\t\t\t},\n\t\t\tquery: {\n\t\t\t\tcursor,\n\t\t\t\tlimit: Coerce.string(limit),\n\t\t\t\tverifySignatureDepth: options?.verifySignatureDepth\n\t\t\t}\n\t\t});\n\n\t\treturn {\n\t\t\tchangesets: 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 graph vertex changeset.\n\t * @param id The id of the vertex to get.\n\t * @param options Additional options for the get operation.\n\t * @param options.verifySignatureDepth How many signatures to verify, defaults to \"none\".\n\t * @returns The changeset if found.\n\t * @throws NotFoundError if the vertex or changeset is not found.\n\t */\n\tpublic async getChangeset(\n\t\tid: string,\n\t\toptions?: { verifySignatureDepth?: VerifyDepth }\n\t): Promise<IAuditableItemGraphChangeset> {\n\t\tGuards.stringValue(AuditableItemGraphRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tconst urnParsed = Urn.fromValidString(id);\n\t\tconst namespaceSpecificParts = urnParsed.namespaceSpecificParts();\n\t\tconst vertexId = namespaceSpecificParts[0];\n\t\tconst changesetId = namespaceSpecificParts[2];\n\n\t\tGuards.stringValue(AuditableItemGraphRestClient.CLASS_NAME, \"vertexId\", vertexId);\n\t\tGuards.stringValue(AuditableItemGraphRestClient.CLASS_NAME, \"changesetId\", changesetId);\n\n\t\tconst response = await this.fetch<\n\t\t\tIAuditableItemGraphChangesetGetRequest,\n\t\t\tIAuditableItemGraphChangesetGetResponse\n\t\t>(\"/:id/changesets/:changesetId\", \"GET\", {\n\t\t\theaders: {\n\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t},\n\t\t\tpathParams: {\n\t\t\t\tid: vertexId,\n\t\t\t\tchangesetId\n\t\t\t},\n\t\t\tquery: {\n\t\t\t\tverifySignatureDepth: options?.verifySignatureDepth\n\t\t\t}\n\t\t});\n\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Get a graph vertex at a specific version.\n\t * @param id The id of the vertex.\n\t * @param version The version number to retrieve.\n\t * @returns The vertex reconstructed at that version.\n\t * @throws NotFoundError if the vertex or version is not found.\n\t */\n\tpublic async getVersion(id: string, version: number): Promise<IAuditableItemGraphVertex> {\n\t\tGuards.stringValue(AuditableItemGraphRestClient.CLASS_NAME, nameof(id), id);\n\t\tGuards.integer(AuditableItemGraphRestClient.CLASS_NAME, nameof(version), version);\n\n\t\tconst urnParsed = Urn.fromValidString(id);\n\t\tconst vertexId = urnParsed.namespaceSpecific(0);\n\n\t\tGuards.stringValue(AuditableItemGraphRestClient.CLASS_NAME, \"vertexId\", vertexId);\n\n\t\tconst response = await this.fetch<\n\t\t\tIAuditableItemGraphVersionGetRequest,\n\t\t\tIAuditableItemGraphVersionGetResponse\n\t\t>(\"/:id/versions/:version\", \"GET\", {\n\t\t\theaders: {\n\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t},\n\t\t\tpathParams: {\n\t\t\t\tid: vertexId,\n\t\t\t\tversion: version.toString()\n\t\t\t}\n\t\t});\n\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Get all versions of a graph vertex.\n\t * @param id The id of the vertex.\n\t * @param options Additional options for the operation.\n\t * @param options.after Only return versions created after this ISO 8601 timestamp (exclusive).\n\t * @param options.before Only return versions created before this ISO 8601 timestamp (exclusive).\n\t * @returns The list of vertex versions.\n\t * @throws NotFoundError if the vertex is not found.\n\t */\n\tpublic async getVersions(\n\t\tid: string,\n\t\toptions?: {\n\t\t\tafter?: string;\n\t\t\tbefore?: string;\n\t\t}\n\t): Promise<IAuditableItemGraphVertexVersionList> {\n\t\tGuards.stringValue(AuditableItemGraphRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tconst response = await this.fetch<\n\t\t\tIAuditableItemGraphVersionListRequest,\n\t\t\tIAuditableItemGraphVersionListResponse\n\t\t>(\"/:id/versions\", \"GET\", {\n\t\t\theaders: {\n\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t},\n\t\t\tpathParams: {\n\t\t\t\tid\n\t\t\t},\n\t\t\tquery: {\n\t\t\t\tafter: options?.after,\n\t\t\t\tbefore: options?.before\n\t\t\t}\n\t\t});\n\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Update a graph vertex (PUT — full replacement of vertex state).\n\t * The server serializes concurrent updates for the same vertex via `Mutex` on the vertex id;\n\t * requests load-balanced across replicas can still race.\n\t * @param vertex The vertex to update.\n\t * @param vertex.id The id of the vertex to update.\n\t * @param vertex.annotationObject The annotation object for the vertex as JSON-LD.\n\t * @param vertex.aliases Alternative aliases that can be used to identify the vertex.\n\t * @param vertex.resources The resources attached to the vertex.\n\t * @param vertex.edges The edges connected to the vertex.\n\t * @returns Nothing.\n\t */\n\tpublic async update(vertex: IAuditableItemGraphVertex): Promise<void> {\n\t\tGuards.object(AuditableItemGraphRestClient.CLASS_NAME, nameof(vertex), vertex);\n\t\tGuards.stringValue(AuditableItemGraphRestClient.CLASS_NAME, nameof(vertex.id), vertex.id);\n\n\t\tconst { id, ...rest } = vertex;\n\n\t\tawait this.fetch<IAuditableItemGraphUpdateRequest, INoContentResponse>(\"/:id\", \"PUT\", {\n\t\t\tpathParams: {\n\t\t\t\tid\n\t\t\t},\n\t\t\tbody: rest\n\t\t});\n\t}\n\n\t/**\n\t * Partially update a graph vertex (PATCH — optional scalars; list fields use `{ add, remove }`).\n\t * @param partial The partial vertex update (must include `id`).\n\t * @returns Nothing.\n\t */\n\tpublic async updatePartial(partial: IAuditableItemGraphPartialVertex): Promise<void> {\n\t\tGuards.object(AuditableItemGraphRestClient.CLASS_NAME, nameof(partial), partial);\n\t\tGuards.stringValue(AuditableItemGraphRestClient.CLASS_NAME, nameof(partial.id), partial.id);\n\n\t\tconst { id, ...body } = partial;\n\n\t\tawait this.fetch<IAuditableItemGraphUpdatePartialRequest, INoContentResponse>(\"/:id\", \"PATCH\", {\n\t\t\tpathParams: {\n\t\t\t\tid\n\t\t\t},\n\t\t\tbody\n\t\t});\n\t}\n\n\t/**\n\t * Query the graph for vertices.\n\t * @param options The query options.\n\t * @param options.id The optional id to look for.\n\t * @param options.idMode Look in id, alias or both, defaults to both.\n\t * @param options.idExact Find only exact matches, default to false meaning partial matching.\n\t * @param options.resourceTypes Include vertices with specific resource types.\n\t * @param conditions Conditions to use in the query.\n\t * @param orderBy The order for the results, defaults to created.\n\t * @param orderByDirection The direction for the order, defaults to descending.\n\t * @param properties The properties to return, if not provided defaults to id, created, aliases and object.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit Limit the number of entities to return.\n\t * @returns The entities, which can be partial if a limited keys list was provided.\n\t */\n\tpublic async query(\n\t\toptions?: {\n\t\t\tid?: string;\n\t\t\tidMode?: \"id\" | \"alias\" | \"both\";\n\t\t\tidExact?: boolean;\n\t\t\tresourceTypes?: string[];\n\t\t},\n\t\tconditions?: IComparator[],\n\t\torderBy?: keyof Pick<IAuditableItemGraphVertex, \"dateCreated\" | \"dateModified\">,\n\t\torderByDirection?: SortDirection,\n\t\tproperties?: (keyof IAuditableItemGraphVertex)[],\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\tentries: IAuditableItemGraphVertexList;\n\t\tcursor?: string;\n\t}> {\n\t\tconst response = await this.fetch<\n\t\t\tIAuditableItemGraphListRequest,\n\t\t\tIAuditableItemGraphListResponse\n\t\t>(\"/\", \"GET\", {\n\t\t\theaders: {\n\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t},\n\t\t\tquery: {\n\t\t\t\tid: options?.id,\n\t\t\t\tidMode: options?.idMode,\n\t\t\t\tidExact: Coerce.string(options?.idExact),\n\t\t\t\tresourceTypes: HttpParameterHelper.arrayToString(options?.resourceTypes),\n\t\t\t\tconditions: HttpParameterHelper.objectToString(conditions),\n\t\t\t\torderBy,\n\t\t\t\torderByDirection,\n\t\t\t\tproperties: HttpParameterHelper.arrayToString(properties),\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,12 +1,11 @@
|
|
|
1
1
|
import { BaseRestClient } from "@twin.org/api-core";
|
|
2
2
|
import { type IBaseRestClientConfig } from "@twin.org/api-models";
|
|
3
|
-
import type { IAuditableItemGraphComponent, IAuditableItemGraphVertex, IAuditableItemGraphVertexList, VerifyDepth } from "@twin.org/auditable-item-graph-models";
|
|
4
|
-
import type { IJsonLdNodeObject } from "@twin.org/data-json-ld";
|
|
3
|
+
import type { IAuditableItemGraphChangeset, IAuditableItemGraphChangesetList, IAuditableItemGraphComponent, IAuditableItemGraphPartialVertex, IAuditableItemGraphVertex, IAuditableItemGraphVertexList, IAuditableItemGraphVertexVersionList, VerifyDepth } from "@twin.org/auditable-item-graph-models";
|
|
5
4
|
import type { IComparator, SortDirection } from "@twin.org/entity";
|
|
6
5
|
/**
|
|
7
6
|
* Client for performing auditable item graph through to REST endpoints.
|
|
8
7
|
*/
|
|
9
|
-
export declare class AuditableItemGraphRestClient extends BaseRestClient implements IAuditableItemGraphComponent {
|
|
8
|
+
export declare class AuditableItemGraphRestClient extends BaseRestClient implements Omit<IAuditableItemGraphComponent, "removeProof"> {
|
|
10
9
|
/**
|
|
11
10
|
* Runtime name for the class.
|
|
12
11
|
*/
|
|
@@ -30,41 +29,71 @@ export declare class AuditableItemGraphRestClient extends BaseRestClient impleme
|
|
|
30
29
|
* @param vertex.edges The edges connected to the vertex.
|
|
31
30
|
* @returns The id of the new graph item.
|
|
32
31
|
*/
|
|
33
|
-
create(vertex:
|
|
34
|
-
annotationObject?: IJsonLdNodeObject;
|
|
35
|
-
aliases?: {
|
|
36
|
-
id: string;
|
|
37
|
-
aliasFormat?: string;
|
|
38
|
-
unique?: boolean;
|
|
39
|
-
annotationObject?: IJsonLdNodeObject;
|
|
40
|
-
}[];
|
|
41
|
-
resources?: {
|
|
42
|
-
id?: string;
|
|
43
|
-
resourceObject?: IJsonLdNodeObject;
|
|
44
|
-
}[];
|
|
45
|
-
edges?: {
|
|
46
|
-
targetId: string;
|
|
47
|
-
edgeRelationships: string[];
|
|
48
|
-
annotationObject?: IJsonLdNodeObject;
|
|
49
|
-
}[];
|
|
50
|
-
}): Promise<string>;
|
|
32
|
+
create(vertex: Omit<IAuditableItemGraphVertex, "id">): Promise<string>;
|
|
51
33
|
/**
|
|
52
34
|
* Get a graph vertex.
|
|
53
35
|
* @param id The id of the vertex to get.
|
|
54
36
|
* @param options Additional options for the get operation.
|
|
55
37
|
* @param options.includeDeleted Whether to include deleted/updated aliases, resource, edges, defaults to false.
|
|
56
|
-
* @param options.includeChangesets Whether to include the changesets of the vertex, defaults to false.
|
|
57
38
|
* @param options.verifySignatureDepth How many signatures to verify, defaults to "none".
|
|
58
39
|
* @returns The vertex if found.
|
|
59
40
|
* @throws NotFoundError if the vertex is not found.
|
|
60
41
|
*/
|
|
61
42
|
get(id: string, options?: {
|
|
62
43
|
includeDeleted?: boolean;
|
|
63
|
-
includeChangesets?: boolean;
|
|
64
44
|
verifySignatureDepth?: VerifyDepth;
|
|
65
45
|
}): Promise<IAuditableItemGraphVertex>;
|
|
66
46
|
/**
|
|
67
|
-
*
|
|
47
|
+
* Get a graph vertex changeset list.
|
|
48
|
+
* @param id The id of the vertex to get.
|
|
49
|
+
* @param cursor The optional cursor to get next chunk.
|
|
50
|
+
* @param limit Limit the number of entities to return.
|
|
51
|
+
* @param options Additional options for the get operation.
|
|
52
|
+
* @param options.verifySignatureDepth How many signatures to verify, defaults to "none".
|
|
53
|
+
* @returns The changesets if found.
|
|
54
|
+
*/
|
|
55
|
+
getChangesets(id: string, cursor?: string, limit?: number, options?: {
|
|
56
|
+
verifySignatureDepth?: VerifyDepth;
|
|
57
|
+
}): Promise<{
|
|
58
|
+
changesets: IAuditableItemGraphChangesetList;
|
|
59
|
+
cursor?: string;
|
|
60
|
+
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Get a graph vertex changeset.
|
|
63
|
+
* @param id The id of the vertex to get.
|
|
64
|
+
* @param options Additional options for the get operation.
|
|
65
|
+
* @param options.verifySignatureDepth How many signatures to verify, defaults to "none".
|
|
66
|
+
* @returns The changeset if found.
|
|
67
|
+
* @throws NotFoundError if the vertex or changeset is not found.
|
|
68
|
+
*/
|
|
69
|
+
getChangeset(id: string, options?: {
|
|
70
|
+
verifySignatureDepth?: VerifyDepth;
|
|
71
|
+
}): Promise<IAuditableItemGraphChangeset>;
|
|
72
|
+
/**
|
|
73
|
+
* Get a graph vertex at a specific version.
|
|
74
|
+
* @param id The id of the vertex.
|
|
75
|
+
* @param version The version number to retrieve.
|
|
76
|
+
* @returns The vertex reconstructed at that version.
|
|
77
|
+
* @throws NotFoundError if the vertex or version is not found.
|
|
78
|
+
*/
|
|
79
|
+
getVersion(id: string, version: number): Promise<IAuditableItemGraphVertex>;
|
|
80
|
+
/**
|
|
81
|
+
* Get all versions of a graph vertex.
|
|
82
|
+
* @param id The id of the vertex.
|
|
83
|
+
* @param options Additional options for the operation.
|
|
84
|
+
* @param options.after Only return versions created after this ISO 8601 timestamp (exclusive).
|
|
85
|
+
* @param options.before Only return versions created before this ISO 8601 timestamp (exclusive).
|
|
86
|
+
* @returns The list of vertex versions.
|
|
87
|
+
* @throws NotFoundError if the vertex is not found.
|
|
88
|
+
*/
|
|
89
|
+
getVersions(id: string, options?: {
|
|
90
|
+
after?: string;
|
|
91
|
+
before?: string;
|
|
92
|
+
}): Promise<IAuditableItemGraphVertexVersionList>;
|
|
93
|
+
/**
|
|
94
|
+
* Update a graph vertex (PUT — full replacement of vertex state).
|
|
95
|
+
* The server serializes concurrent updates for the same vertex via `Mutex` on the vertex id;
|
|
96
|
+
* requests load-balanced across replicas can still race.
|
|
68
97
|
* @param vertex The vertex to update.
|
|
69
98
|
* @param vertex.id The id of the vertex to update.
|
|
70
99
|
* @param vertex.annotationObject The annotation object for the vertex as JSON-LD.
|
|
@@ -73,33 +102,13 @@ export declare class AuditableItemGraphRestClient extends BaseRestClient impleme
|
|
|
73
102
|
* @param vertex.edges The edges connected to the vertex.
|
|
74
103
|
* @returns Nothing.
|
|
75
104
|
*/
|
|
76
|
-
update(vertex:
|
|
77
|
-
id: string;
|
|
78
|
-
annotationObject?: IJsonLdNodeObject;
|
|
79
|
-
aliases?: {
|
|
80
|
-
id: string;
|
|
81
|
-
aliasFormat?: string;
|
|
82
|
-
unique?: boolean;
|
|
83
|
-
annotationObject?: IJsonLdNodeObject;
|
|
84
|
-
}[];
|
|
85
|
-
resources?: {
|
|
86
|
-
id?: string;
|
|
87
|
-
resourceObject?: IJsonLdNodeObject;
|
|
88
|
-
}[];
|
|
89
|
-
edges?: {
|
|
90
|
-
id?: string;
|
|
91
|
-
targetId: string;
|
|
92
|
-
edgeRelationships: string[];
|
|
93
|
-
annotationObject?: IJsonLdNodeObject;
|
|
94
|
-
}[];
|
|
95
|
-
}): Promise<void>;
|
|
105
|
+
update(vertex: IAuditableItemGraphVertex): Promise<void>;
|
|
96
106
|
/**
|
|
97
|
-
*
|
|
98
|
-
* @param
|
|
107
|
+
* Partially update a graph vertex (PATCH — optional scalars; list fields use `{ add, remove }`).
|
|
108
|
+
* @param partial The partial vertex update (must include `id`).
|
|
99
109
|
* @returns Nothing.
|
|
100
|
-
* @throws NotFoundError if the vertex is not found.
|
|
101
110
|
*/
|
|
102
|
-
|
|
111
|
+
updatePartial(partial: IAuditableItemGraphPartialVertex): Promise<void>;
|
|
103
112
|
/**
|
|
104
113
|
* Query the graph for vertices.
|
|
105
114
|
* @param options The query options.
|
|
@@ -120,5 +129,8 @@ export declare class AuditableItemGraphRestClient extends BaseRestClient impleme
|
|
|
120
129
|
idMode?: "id" | "alias" | "both";
|
|
121
130
|
idExact?: boolean;
|
|
122
131
|
resourceTypes?: string[];
|
|
123
|
-
}, conditions?: IComparator[], orderBy?: keyof Pick<IAuditableItemGraphVertex, "dateCreated" | "dateModified">, orderByDirection?: SortDirection, properties?: (keyof IAuditableItemGraphVertex)[], cursor?: string, limit?: number): Promise<
|
|
132
|
+
}, conditions?: IComparator[], orderBy?: keyof Pick<IAuditableItemGraphVertex, "dateCreated" | "dateModified">, orderByDirection?: SortDirection, properties?: (keyof IAuditableItemGraphVertex)[], cursor?: string, limit?: number): Promise<{
|
|
133
|
+
entries: IAuditableItemGraphVertexList;
|
|
134
|
+
cursor?: string;
|
|
135
|
+
}>;
|
|
124
136
|
}
|