@twin.org/auditable-item-stream-rest-client 0.0.3-next.11 → 0.0.3-next.13
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 +2 -2
- package/dist/es/auditableItemStreamRestClient.js +27 -18
- package/dist/es/auditableItemStreamRestClient.js.map +1 -1
- package/dist/types/auditableItemStreamRestClient.d.ts +17 -23
- package/docs/changelog.md +29 -1
- package/docs/examples.md +183 -1
- package/docs/reference/classes/AuditableItemStreamRestClient.md +58 -51
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Auditable Item Stream REST Client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package provides a client for calling auditable item stream REST endpoints, with helper methods for creating streams, managing entries, querying results, and handling paging.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -29,26 +29,20 @@ export class AuditableItemStreamRestClient extends BaseRestClient {
|
|
|
29
29
|
/**
|
|
30
30
|
* Create a new stream.
|
|
31
31
|
* @param stream The stream to create.
|
|
32
|
-
* @param stream.annotationObject The object for the stream as JSON-LD.
|
|
33
|
-
* @param stream.entries Entries to store in the stream.
|
|
34
|
-
* @param options Options for creating the stream.
|
|
35
|
-
* @param options.immutableInterval After how many entries do we add immutable checks, defaults to service configured value.
|
|
36
|
-
* A value of 0 will disable integrity checks, 1 will be every item, or any other integer for an interval.
|
|
37
32
|
* @returns The id of the new stream item.
|
|
38
33
|
*/
|
|
39
|
-
async create(stream
|
|
34
|
+
async create(stream) {
|
|
40
35
|
Guards.object(AuditableItemStreamRestClient.CLASS_NAME, "stream", stream);
|
|
41
36
|
const response = await this.fetch("/", "POST", {
|
|
42
|
-
body:
|
|
43
|
-
...stream,
|
|
44
|
-
immutableInterval: options?.immutableInterval
|
|
45
|
-
}
|
|
37
|
+
body: stream
|
|
46
38
|
});
|
|
47
39
|
return response.headers[HeaderTypes.Location];
|
|
48
40
|
}
|
|
49
41
|
/**
|
|
50
42
|
* Get a stream header without the entries.
|
|
51
43
|
* @param id The id of the stream to get.
|
|
44
|
+
* @param cursor Cursor to use for next chunk of entries.
|
|
45
|
+
* @param limit Limit the number of entries to return, only applicable if includeEntries is true.
|
|
52
46
|
* @param options Additional options for the get operation.
|
|
53
47
|
* @param options.includeEntries Whether to include the entries, defaults to false.
|
|
54
48
|
* @param options.includeDeleted Whether to include deleted entries, defaults to false.
|
|
@@ -57,7 +51,7 @@ export class AuditableItemStreamRestClient extends BaseRestClient {
|
|
|
57
51
|
* @returns The stream and entries if found.
|
|
58
52
|
* @throws NotFoundError if the stream is not found
|
|
59
53
|
*/
|
|
60
|
-
async get(id, options) {
|
|
54
|
+
async get(id, cursor, limit, options) {
|
|
61
55
|
Guards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, "id", id);
|
|
62
56
|
const response = await this.fetch("/:id", "GET", {
|
|
63
57
|
headers: {
|
|
@@ -67,31 +61,46 @@ export class AuditableItemStreamRestClient extends BaseRestClient {
|
|
|
67
61
|
id
|
|
68
62
|
},
|
|
69
63
|
query: {
|
|
64
|
+
cursor,
|
|
65
|
+
limit: Coerce.string(limit),
|
|
70
66
|
includeEntries: Coerce.string(options?.includeEntries),
|
|
71
67
|
includeDeleted: Coerce.string(options?.includeDeleted),
|
|
72
68
|
verifyStream: Coerce.string(options?.verifyStream),
|
|
73
69
|
verifyEntries: Coerce.string(options?.verifyEntries)
|
|
74
70
|
}
|
|
75
71
|
});
|
|
76
|
-
return
|
|
72
|
+
return {
|
|
73
|
+
stream: response.body,
|
|
74
|
+
cursor: HeaderHelper.extractLinkHeaderRelation(response.headers?.[HeaderTypes.Link], "next")
|
|
75
|
+
?.urlQueryParams?.cursor
|
|
76
|
+
};
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
79
|
* Update a stream.
|
|
80
|
-
* @param stream The stream to update.
|
|
81
|
-
* @param stream.id The id of the stream to update.
|
|
82
|
-
* @param stream.annotationObject The object for the stream as JSON-LD.
|
|
80
|
+
* @param stream The stream to update, does not update entries.
|
|
83
81
|
* @returns Nothing.
|
|
84
82
|
*/
|
|
85
83
|
async update(stream) {
|
|
86
84
|
Guards.object(AuditableItemStreamRestClient.CLASS_NAME, "stream", stream);
|
|
87
85
|
Guards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, "stream.id", stream.id);
|
|
88
|
-
const { id,
|
|
86
|
+
const { id, ...rest } = stream;
|
|
89
87
|
await this.fetch("/:id", "PUT", {
|
|
90
88
|
pathParams: {
|
|
91
89
|
id
|
|
92
90
|
},
|
|
93
|
-
body:
|
|
94
|
-
|
|
91
|
+
body: rest
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Close the stream.
|
|
96
|
+
* @param id The id of the stream to close.
|
|
97
|
+
* @returns Nothing.
|
|
98
|
+
*/
|
|
99
|
+
async close(id) {
|
|
100
|
+
Guards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, "id", id);
|
|
101
|
+
await this.fetch("/:id/close", "POST", {
|
|
102
|
+
pathParams: {
|
|
103
|
+
id
|
|
95
104
|
}
|
|
96
105
|
});
|
|
97
106
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auditableItemStreamRestClient.js","sourceRoot":"","sources":["../../src/auditableItemStreamRestClient.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EACN,mBAAmB,EAInB,MAAM,sBAAsB,CAAC;AA6B9B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAIvE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAErE;;GAEG;AACH,MAAM,OAAO,6BACZ,SAAQ,cAAc;IAGtB;;OAEG;IACI,MAAM,C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,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;gBAC3F,EAAE,cAAc,EAAE,MAAM;SACzB,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,gBAAgB,CAAC,EAAU;QACvC,MAAM,IAAI,iBAAiB,CAAC,6BAA6B,CAAC,UAAU,EAAE,sBAAsB,EAAE;YAC7F,UAAU,EAAE,kBAAkB;SAC9B,CAAC,CAAC;IACJ,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\tIAuditableItemStream,\n\tIAuditableItemStreamComponent,\n\tIAuditableItemStreamCreateEntryRequest,\n\tIAuditableItemStreamCreateRequest,\n\tIAuditableItemStreamDeleteEntryRequest,\n\tIAuditableItemStreamDeleteRequest,\n\tIAuditableItemStreamEntry,\n\tIAuditableItemStreamEntryList,\n\tIAuditableItemStreamEntryObjectList,\n\tIAuditableItemStreamGetEntryObjectRequest,\n\tIAuditableItemStreamGetEntryObjectResponse,\n\tIAuditableItemStreamGetEntryRequest,\n\tIAuditableItemStreamGetEntryResponse,\n\tIAuditableItemStreamGetRequest,\n\tIAuditableItemStreamGetResponse,\n\tIAuditableItemStreamList,\n\tIAuditableItemStreamListEntriesNoStreamRequest,\n\tIAuditableItemStreamListEntriesRequest,\n\tIAuditableItemStreamListEntriesResponse,\n\tIAuditableItemStreamListEntryObjectsNoStreamRequest,\n\tIAuditableItemStreamListEntryObjectsRequest,\n\tIAuditableItemStreamListEntryObjectsResponse,\n\tIAuditableItemStreamListRequest,\n\tIAuditableItemStreamListResponse,\n\tIAuditableItemStreamUpdateEntryRequest,\n\tIAuditableItemStreamUpdateRequest\n} from \"@twin.org/auditable-item-stream-models\";\nimport { Coerce, Guards, Is, 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 { HeaderHelper, HeaderTypes, MimeTypes } from \"@twin.org/web\";\n\n/**\n * Client for performing auditable item stream through to REST endpoints.\n */\nexport class AuditableItemStreamRestClient\n\textends BaseRestClient\n\timplements IAuditableItemStreamComponent\n{\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<AuditableItemStreamRestClient>();\n\n\t/**\n\t * Create a new instance of AuditableItemStreamRestClient.\n\t * @param config The configuration for the client.\n\t */\n\tconstructor(config: IBaseRestClientConfig) {\n\t\tsuper(nameof<AuditableItemStreamRestClient>(), config, \"auditable-item-stream\");\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 AuditableItemStreamRestClient.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create a new stream.\n\t * @param stream The stream to create.\n\t * @param stream.annotationObject The object for the stream as JSON-LD.\n\t * @param stream.entries Entries to store in the stream.\n\t * @param options Options for creating the stream.\n\t * @param options.immutableInterval After how many entries do we add immutable checks, defaults to service configured value.\n\t * A value of 0 will disable integrity checks, 1 will be every item, or any other integer for an interval.\n\t * @returns The id of the new stream item.\n\t */\n\tpublic async create(\n\t\tstream: {\n\t\t\tannotationObject?: IJsonLdNodeObject;\n\t\t\tentries?: {\n\t\t\t\tentryObject: IJsonLdNodeObject;\n\t\t\t}[];\n\t\t},\n\t\toptions?: {\n\t\t\timmutableInterval?: number;\n\t\t}\n\t): Promise<string> {\n\t\tGuards.object(AuditableItemStreamRestClient.CLASS_NAME, nameof(stream), stream);\n\t\tconst response = await this.fetch<IAuditableItemStreamCreateRequest, ICreatedResponse>(\n\t\t\t\"/\",\n\t\t\t\"POST\",\n\t\t\t{\n\t\t\t\tbody: {\n\t\t\t\t\t...stream,\n\t\t\t\t\timmutableInterval: options?.immutableInterval\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn response.headers[HeaderTypes.Location];\n\t}\n\n\t/**\n\t * Get a stream header without the entries.\n\t * @param id The id of the stream to get.\n\t * @param options Additional options for the get operation.\n\t * @param options.includeEntries Whether to include the entries, defaults to false.\n\t * @param options.includeDeleted Whether to include deleted entries, defaults to false.\n\t * @param options.verifyStream Should the stream be verified, defaults to false.\n\t * @param options.verifyEntries Should the entries be verified, defaults to false.\n\t * @returns The stream and entries if found.\n\t * @throws NotFoundError if the stream is not found\n\t */\n\tpublic async get(\n\t\tid: string,\n\t\toptions?: {\n\t\t\tincludeEntries?: boolean;\n\t\t\tincludeDeleted?: boolean;\n\t\t\tverifyStream?: boolean;\n\t\t\tverifyEntries?: boolean;\n\t\t}\n\t): Promise<IAuditableItemStream> {\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tconst response = await this.fetch<\n\t\t\tIAuditableItemStreamGetRequest,\n\t\t\tIAuditableItemStreamGetResponse\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\tincludeEntries: Coerce.string(options?.includeEntries),\n\t\t\t\tincludeDeleted: Coerce.string(options?.includeDeleted),\n\t\t\t\tverifyStream: Coerce.string(options?.verifyStream),\n\t\t\t\tverifyEntries: Coerce.string(options?.verifyEntries)\n\t\t\t}\n\t\t});\n\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Update a stream.\n\t * @param stream The stream to update.\n\t * @param stream.id The id of the stream to update.\n\t * @param stream.annotationObject The object for the stream as JSON-LD.\n\t * @returns Nothing.\n\t */\n\tpublic async update(stream: { id: string; annotationObject?: IJsonLdNodeObject }): Promise<void> {\n\t\tGuards.object(AuditableItemStreamRestClient.CLASS_NAME, nameof(stream), stream);\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(stream.id), stream.id);\n\n\t\tconst { id, annotationObject } = stream;\n\t\tawait this.fetch<IAuditableItemStreamUpdateRequest, INoContentResponse>(\"/:id\", \"PUT\", {\n\t\t\tpathParams: {\n\t\t\t\tid\n\t\t\t},\n\t\t\tbody: {\n\t\t\t\tannotationObject\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Delete the stream.\n\t * @param id The id of the stream to remove.\n\t * @returns Nothing.\n\t */\n\tpublic async remove(id: string): Promise<void> {\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tawait this.fetch<IAuditableItemStreamDeleteRequest, INoContentResponse>(\"/:id\", \"DELETE\", {\n\t\t\tpathParams: {\n\t\t\t\tid\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Query all the streams, will not return entries.\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 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\tconditions?: IComparator[],\n\t\torderBy?: keyof Pick<IAuditableItemStream, \"dateCreated\" | \"dateModified\">,\n\t\torderByDirection?: SortDirection,\n\t\tproperties?: (keyof IAuditableItemStream)[],\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\tentries: IAuditableItemStreamList;\n\t\tcursor?: string;\n\t}> {\n\t\tconst response = await this.fetch<\n\t\t\tIAuditableItemStreamListRequest,\n\t\t\tIAuditableItemStreamListResponse\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\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\t/**\n\t * Create an entry in the stream.\n\t * @param id The id of the stream to update.\n\t * @param entryObject The object for the stream as JSON-LD.\n\t * @returns The id of the created entry, if not provided.\n\t */\n\tpublic async createEntry(id: string, entryObject: IJsonLdNodeObject): Promise<string> {\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tconst response = await this.fetch<IAuditableItemStreamCreateEntryRequest, ICreatedResponse>(\n\t\t\t\"/:id/entries\",\n\t\t\t\"POST\",\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tid\n\t\t\t\t},\n\t\t\t\tbody: {\n\t\t\t\t\tentryObject\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn response.headers[HeaderTypes.Location];\n\t}\n\n\t/**\n\t * Get the entry from the stream.\n\t * @param id The id of the stream to get.\n\t * @param entryId The id of the stream entry to get.\n\t * @param options Additional options for the get operation.\n\t * @param options.verifyEntry Should the entry be verified, defaults to false.\n\t * @returns The stream and entries if found.\n\t * @throws NotFoundError if the stream is not found.\n\t */\n\tpublic async getEntry(\n\t\tid: string,\n\t\tentryId: string,\n\t\toptions?: {\n\t\t\tverifyEntry?: boolean;\n\t\t}\n\t): Promise<IAuditableItemStreamEntry> {\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(entryId), entryId);\n\n\t\tconst response = await this.fetch<\n\t\t\tIAuditableItemStreamGetEntryRequest,\n\t\t\tIAuditableItemStreamGetEntryResponse\n\t\t>(\"/:id/entries/:entryId\", \"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\tverifyEntry: Coerce.string(options?.verifyEntry)\n\t\t\t},\n\t\t\tpathParams: {\n\t\t\t\tid,\n\t\t\t\tentryId\n\t\t\t}\n\t\t});\n\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Get the entry object from the stream.\n\t * @param id The id of the stream to get.\n\t * @param entryId The id of the stream entry to get.\n\t * @returns The stream and entries if found.\n\t * @throws NotFoundError if the stream is not found.\n\t */\n\tpublic async getEntryObject(id: string, entryId: string): Promise<IJsonLdNodeObject> {\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(entryId), entryId);\n\n\t\tconst response = await this.fetch<\n\t\t\tIAuditableItemStreamGetEntryObjectRequest,\n\t\t\tIAuditableItemStreamGetEntryObjectResponse\n\t\t>(\"/:id/entries/:entryId/object\", \"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\tentryId\n\t\t\t}\n\t\t});\n\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Update an entry in the stream.\n\t * @param id The id of the stream to update.\n\t * @param entryId The id of the entry to update.\n\t * @param entryObject The object for the entry as JSON-LD.\n\t * @returns Nothing.\n\t */\n\tpublic async updateEntry(\n\t\tid: string,\n\t\tentryId: string,\n\t\tentryObject: IJsonLdNodeObject\n\t): Promise<void> {\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(entryId), entryId);\n\n\t\tawait this.fetch<IAuditableItemStreamUpdateEntryRequest, INoContentResponse>(\n\t\t\t\"/:id/entries/:entryId\",\n\t\t\t\"PUT\",\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tid,\n\t\t\t\t\tentryId\n\t\t\t\t},\n\t\t\t\tbody: {\n\t\t\t\t\tentryObject\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Remove from the stream.\n\t * @param id The id of the stream to remove from.\n\t * @param entryId The id of the entry to remove.\n\t * @returns Nothing.\n\t */\n\tpublic async removeEntry(id: string, entryId: string): Promise<void> {\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(entryId), entryId);\n\n\t\tawait this.fetch<IAuditableItemStreamDeleteEntryRequest, INoContentResponse>(\n\t\t\t\"/:id/entries/:entryId\",\n\t\t\t\"DELETE\",\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tid,\n\t\t\t\t\tentryId\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Get the entries for the stream.\n\t * @param id The id of the stream to get, if undefined returns all matching entries.\n\t * @param options Additional options for the get operation.\n\t * @param options.conditions The conditions to filter the stream.\n\t * @param options.includeDeleted Whether to include deleted entries, defaults to false.\n\t * @param options.verifyEntries Should the entries be verified, defaults to false.\n\t * @param options.limit How many entries to return.\n\t * @param options.cursor Cursor to use for next chunk of data.\n\t * @param options.order Retrieve the entries in ascending/descending time order, defaults to Ascending.\n\t * @returns The stream and entries if found.\n\t * @throws NotFoundError if the stream is not found.\n\t */\n\tpublic async getEntries(\n\t\tid?: string,\n\t\toptions?: {\n\t\t\tconditions?: IComparator[];\n\t\t\tincludeDeleted?: boolean;\n\t\t\tverifyEntries?: boolean;\n\t\t\tlimit?: number;\n\t\t\tcursor?: string;\n\t\t\torder?: SortDirection;\n\t\t}\n\t): Promise<{\n\t\tentries: IAuditableItemStreamEntryList;\n\t\tcursor?: string;\n\t}> {\n\t\tconst queryParams = {\n\t\t\tconditions: HttpParameterHelper.objectToString(options?.conditions),\n\t\t\tincludeDeleted: Coerce.string(options?.includeDeleted),\n\t\t\tverifyEntries: Coerce.string(options?.verifyEntries),\n\t\t\tlimit: Coerce.string(options?.limit),\n\t\t\tcursor: options?.cursor,\n\t\t\torder: options?.order\n\t\t};\n\n\t\tlet response;\n\t\tif (!Is.empty(id)) {\n\t\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(id), id);\n\n\t\t\tresponse = await this.fetch<\n\t\t\t\tIAuditableItemStreamListEntriesRequest,\n\t\t\t\tIAuditableItemStreamListEntriesResponse\n\t\t\t>(\"/:id/entries\", \"GET\", {\n\t\t\t\theaders: {\n\t\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t\t},\n\t\t\t\tpathParams: {\n\t\t\t\t\tid\n\t\t\t\t},\n\t\t\t\tquery: queryParams\n\t\t\t});\n\t\t} else {\n\t\t\tresponse = await this.fetch<\n\t\t\t\tIAuditableItemStreamListEntriesNoStreamRequest,\n\t\t\t\tIAuditableItemStreamListEntriesResponse\n\t\t\t>(\"/entries\", \"GET\", {\n\t\t\t\theaders: {\n\t\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t\t},\n\t\t\t\tquery: queryParams\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 the entry objects for the stream.\n\t * @param id The id of the stream to get, if undefined returns all matching entries.\n\t * @param options Additional options for the get operation.\n\t * @param options.conditions The conditions to filter the stream.\n\t * @param options.includeDeleted Whether to include deleted entries, defaults to false.\n\t * @param options.limit How many entries to return.\n\t * @param options.cursor Cursor to use for next chunk of data.\n\t * @param options.order Retrieve the entries in ascending/descending time order, defaults to Ascending.\n\t * @returns The stream and entries if found.\n\t * @throws NotFoundError if the stream is not found.\n\t */\n\tpublic async getEntryObjects(\n\t\tid?: string,\n\t\toptions?: {\n\t\t\tconditions?: IComparator[];\n\t\t\tincludeDeleted?: boolean;\n\t\t\tlimit?: number;\n\t\t\tcursor?: string;\n\t\t\torder?: SortDirection;\n\t\t}\n\t): Promise<{\n\t\tentries: IAuditableItemStreamEntryObjectList;\n\t\tcursor?: string;\n\t}> {\n\t\tconst queryParams = {\n\t\t\tconditions: HttpParameterHelper.objectToString(options?.conditions),\n\t\t\tincludeDeleted: Coerce.string(options?.includeDeleted),\n\t\t\tlimit: Coerce.string(options?.limit),\n\t\t\tcursor: options?.cursor,\n\t\t\torder: options?.order\n\t\t};\n\n\t\tlet response;\n\t\tif (!Is.empty(id)) {\n\t\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(id), id);\n\t\t\tresponse = await this.fetch<\n\t\t\t\tIAuditableItemStreamListEntryObjectsRequest,\n\t\t\t\tIAuditableItemStreamListEntryObjectsResponse\n\t\t\t>(\"/:id/entries/objects\", \"GET\", {\n\t\t\t\theaders: {\n\t\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t\t},\n\t\t\t\tpathParams: {\n\t\t\t\t\tid\n\t\t\t\t},\n\t\t\t\tquery: queryParams\n\t\t\t});\n\t\t} else {\n\t\t\tresponse = await this.fetch<\n\t\t\t\tIAuditableItemStreamListEntryObjectsNoStreamRequest,\n\t\t\t\tIAuditableItemStreamListEntryObjectsResponse\n\t\t\t>(\"/entries/objects\", \"GET\", {\n\t\t\t\theaders: {\n\t\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t\t},\n\t\t\t\tquery: queryParams\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 * Remove the verifiable storage for the stream and entries, not supported on client.\n\t * @param id The id of the stream to remove the storage from.\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(AuditableItemStreamRestClient.CLASS_NAME, \"notSupportedOnClient\", {\n\t\t\tmethodName: \"removeVerifiable\"\n\t\t});\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"auditableItemStreamRestClient.js","sourceRoot":"","sources":["../../src/auditableItemStreamRestClient.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EACN,mBAAmB,EAInB,MAAM,sBAAsB,CAAC;AA+B9B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAIvE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAErE;;GAEG;AACH,MAAM,OAAO,6BACZ,SAAQ,cAAc;IAGtB;;OAEG;IACI,MAAM,CAAU,UAAU,mCAAmD;IAEpF;;;OAGG;IACH,YAAY,MAA6B;QACxC,KAAK,kCAA0C,MAAM,EAAE,uBAAuB,CAAC,CAAC;IACjF,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,6BAA6B,CAAC,UAAU,CAAC;IACjD,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,MAAM,CAAC,MAAgC;QACnD,MAAM,CAAC,MAAM,CAAC,6BAA6B,CAAC,UAAU,YAAkB,MAAM,CAAC,CAAC;QAChF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAChC,GAAG,EACH,MAAM,EACN;YACC,IAAI,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AY,CAAC,yBAAyB,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;gBAC3F,EAAE,cAAc,EAAE,MAAM;SACzB,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,gBAAgB,CAAC,EAAU;QACvC,MAAM,IAAI,iBAAiB,CAAC,6BAA6B,CAAC,UAAU,EAAE,sBAAsB,EAAE;YAC7F,UAAU,EAAE,kBAAkB;SAC9B,CAAC,CAAC;IACJ,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\tIAuditableItemStream,\n\tIAuditableItemStreamBase,\n\tIAuditableItemStreamCloseRequest,\n\tIAuditableItemStreamComponent,\n\tIAuditableItemStreamCreateEntryRequest,\n\tIAuditableItemStreamCreateRequest,\n\tIAuditableItemStreamDeleteEntryRequest,\n\tIAuditableItemStreamDeleteRequest,\n\tIAuditableItemStreamEntry,\n\tIAuditableItemStreamEntryList,\n\tIAuditableItemStreamEntryObjectList,\n\tIAuditableItemStreamGetEntryObjectRequest,\n\tIAuditableItemStreamGetEntryObjectResponse,\n\tIAuditableItemStreamGetEntryRequest,\n\tIAuditableItemStreamGetEntryResponse,\n\tIAuditableItemStreamGetRequest,\n\tIAuditableItemStreamGetResponse,\n\tIAuditableItemStreamList,\n\tIAuditableItemStreamListEntriesNoStreamRequest,\n\tIAuditableItemStreamListEntriesRequest,\n\tIAuditableItemStreamListEntriesResponse,\n\tIAuditableItemStreamListEntryObjectsNoStreamRequest,\n\tIAuditableItemStreamListEntryObjectsRequest,\n\tIAuditableItemStreamListEntryObjectsResponse,\n\tIAuditableItemStreamListRequest,\n\tIAuditableItemStreamListResponse,\n\tIAuditableItemStreamUpdateEntryRequest,\n\tIAuditableItemStreamUpdateRequest\n} from \"@twin.org/auditable-item-stream-models\";\nimport { Coerce, Guards, Is, 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 { HeaderHelper, HeaderTypes, MimeTypes } from \"@twin.org/web\";\n\n/**\n * Client for performing auditable item stream through to REST endpoints.\n */\nexport class AuditableItemStreamRestClient\n\textends BaseRestClient\n\timplements IAuditableItemStreamComponent\n{\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<AuditableItemStreamRestClient>();\n\n\t/**\n\t * Create a new instance of AuditableItemStreamRestClient.\n\t * @param config The configuration for the client.\n\t */\n\tconstructor(config: IBaseRestClientConfig) {\n\t\tsuper(nameof<AuditableItemStreamRestClient>(), config, \"auditable-item-stream\");\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 AuditableItemStreamRestClient.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create a new stream.\n\t * @param stream The stream to create.\n\t * @returns The id of the new stream item.\n\t */\n\tpublic async create(stream: IAuditableItemStreamBase): Promise<string> {\n\t\tGuards.object(AuditableItemStreamRestClient.CLASS_NAME, nameof(stream), stream);\n\t\tconst response = await this.fetch<IAuditableItemStreamCreateRequest, ICreatedResponse>(\n\t\t\t\"/\",\n\t\t\t\"POST\",\n\t\t\t{\n\t\t\t\tbody: stream\n\t\t\t}\n\t\t);\n\n\t\treturn response.headers[HeaderTypes.Location];\n\t}\n\n\t/**\n\t * Get a stream header without the entries.\n\t * @param id The id of the stream to get.\n\t * @param cursor Cursor to use for next chunk of entries.\n\t * @param limit Limit the number of entries to return, only applicable if includeEntries is true.\n\t * @param options Additional options for the get operation.\n\t * @param options.includeEntries Whether to include the entries, defaults to false.\n\t * @param options.includeDeleted Whether to include deleted entries, defaults to false.\n\t * @param options.verifyStream Should the stream be verified, defaults to false.\n\t * @param options.verifyEntries Should the entries be verified, defaults to false.\n\t * @returns The stream and entries if found.\n\t * @throws NotFoundError if the stream is not found\n\t */\n\tpublic async get(\n\t\tid: string,\n\t\tcursor?: string,\n\t\tlimit?: number,\n\t\toptions?: {\n\t\t\tincludeEntries?: boolean;\n\t\t\tincludeDeleted?: boolean;\n\t\t\tverifyStream?: boolean;\n\t\t\tverifyEntries?: boolean;\n\t\t}\n\t): Promise<{\n\t\tstream: IAuditableItemStream;\n\t\tcursor?: string;\n\t}> {\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tconst response = await this.fetch<\n\t\t\tIAuditableItemStreamGetRequest,\n\t\t\tIAuditableItemStreamGetResponse\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\tcursor,\n\t\t\t\tlimit: Coerce.string(limit),\n\t\t\t\tincludeEntries: Coerce.string(options?.includeEntries),\n\t\t\t\tincludeDeleted: Coerce.string(options?.includeDeleted),\n\t\t\t\tverifyStream: Coerce.string(options?.verifyStream),\n\t\t\t\tverifyEntries: Coerce.string(options?.verifyEntries)\n\t\t\t}\n\t\t});\n\n\t\treturn {\n\t\t\tstream: 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 * Update a stream.\n\t * @param stream The stream to update, does not update entries.\n\t * @returns Nothing.\n\t */\n\tpublic async update(\n\t\tstream: Pick<IAuditableItemStream, \"@context\" | \"type\" | \"id\" | \"annotationObject\">\n\t): Promise<void> {\n\t\tGuards.object(AuditableItemStreamRestClient.CLASS_NAME, nameof(stream), stream);\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(stream.id), stream.id);\n\n\t\tconst { id, ...rest } = stream;\n\t\tawait this.fetch<IAuditableItemStreamUpdateRequest, 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 * Close the stream.\n\t * @param id The id of the stream to close.\n\t * @returns Nothing.\n\t */\n\tpublic async close(id: string): Promise<void> {\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tawait this.fetch<IAuditableItemStreamCloseRequest, INoContentResponse>(\"/:id/close\", \"POST\", {\n\t\t\tpathParams: {\n\t\t\t\tid\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Delete the stream.\n\t * @param id The id of the stream to remove.\n\t * @returns Nothing.\n\t */\n\tpublic async remove(id: string): Promise<void> {\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tawait this.fetch<IAuditableItemStreamDeleteRequest, INoContentResponse>(\"/:id\", \"DELETE\", {\n\t\t\tpathParams: {\n\t\t\t\tid\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Query all the streams, will not return entries.\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 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\tconditions?: IComparator[],\n\t\torderBy?: keyof Pick<IAuditableItemStream, \"dateCreated\" | \"dateModified\">,\n\t\torderByDirection?: SortDirection,\n\t\tproperties?: (keyof IAuditableItemStream)[],\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\tentries: IAuditableItemStreamList;\n\t\tcursor?: string;\n\t}> {\n\t\tconst response = await this.fetch<\n\t\t\tIAuditableItemStreamListRequest,\n\t\t\tIAuditableItemStreamListResponse\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\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\t/**\n\t * Create an entry in the stream.\n\t * @param id The id of the stream to update.\n\t * @param entryObject The object for the stream as JSON-LD.\n\t * @returns The id of the created entry, if not provided.\n\t */\n\tpublic async createEntry(id: string, entryObject: IJsonLdNodeObject): Promise<string> {\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tconst response = await this.fetch<IAuditableItemStreamCreateEntryRequest, ICreatedResponse>(\n\t\t\t\"/:id/entries\",\n\t\t\t\"POST\",\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tid\n\t\t\t\t},\n\t\t\t\tbody: {\n\t\t\t\t\tentryObject\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn response.headers[HeaderTypes.Location];\n\t}\n\n\t/**\n\t * Get the entry from the stream.\n\t * @param id The id of the stream to get.\n\t * @param entryId The id of the stream entry to get.\n\t * @param options Additional options for the get operation.\n\t * @param options.verifyEntry Should the entry be verified, defaults to false.\n\t * @returns The stream and entries if found.\n\t * @throws NotFoundError if the stream is not found.\n\t */\n\tpublic async getEntry(\n\t\tid: string,\n\t\tentryId: string,\n\t\toptions?: {\n\t\t\tverifyEntry?: boolean;\n\t\t}\n\t): Promise<IAuditableItemStreamEntry> {\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(entryId), entryId);\n\n\t\tconst response = await this.fetch<\n\t\t\tIAuditableItemStreamGetEntryRequest,\n\t\t\tIAuditableItemStreamGetEntryResponse\n\t\t>(\"/:id/entries/:entryId\", \"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\tverifyEntry: Coerce.string(options?.verifyEntry)\n\t\t\t},\n\t\t\tpathParams: {\n\t\t\t\tid,\n\t\t\t\tentryId\n\t\t\t}\n\t\t});\n\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Get the entry object from the stream.\n\t * @param id The id of the stream to get.\n\t * @param entryId The id of the stream entry to get.\n\t * @returns The stream and entries if found.\n\t * @throws NotFoundError if the stream is not found.\n\t */\n\tpublic async getEntryObject(id: string, entryId: string): Promise<IJsonLdNodeObject> {\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(entryId), entryId);\n\n\t\tconst response = await this.fetch<\n\t\t\tIAuditableItemStreamGetEntryObjectRequest,\n\t\t\tIAuditableItemStreamGetEntryObjectResponse\n\t\t>(\"/:id/entries/:entryId/object\", \"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\tentryId\n\t\t\t}\n\t\t});\n\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Update an entry in the stream.\n\t * @param id The id of the stream to update.\n\t * @param entryId The id of the entry to update.\n\t * @param entryObject The object for the entry as JSON-LD.\n\t * @returns Nothing.\n\t */\n\tpublic async updateEntry(\n\t\tid: string,\n\t\tentryId: string,\n\t\tentryObject: IJsonLdNodeObject\n\t): Promise<void> {\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(entryId), entryId);\n\n\t\tawait this.fetch<IAuditableItemStreamUpdateEntryRequest, INoContentResponse>(\n\t\t\t\"/:id/entries/:entryId\",\n\t\t\t\"PUT\",\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tid,\n\t\t\t\t\tentryId\n\t\t\t\t},\n\t\t\t\tbody: {\n\t\t\t\t\tentryObject\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Remove from the stream.\n\t * @param id The id of the stream to remove from.\n\t * @param entryId The id of the entry to remove.\n\t * @returns Nothing.\n\t */\n\tpublic async removeEntry(id: string, entryId: string): Promise<void> {\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(entryId), entryId);\n\n\t\tawait this.fetch<IAuditableItemStreamDeleteEntryRequest, INoContentResponse>(\n\t\t\t\"/:id/entries/:entryId\",\n\t\t\t\"DELETE\",\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tid,\n\t\t\t\t\tentryId\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Get the entries for the stream.\n\t * @param id The id of the stream to get, if undefined returns all matching entries.\n\t * @param options Additional options for the get operation.\n\t * @param options.conditions The conditions to filter the stream.\n\t * @param options.includeDeleted Whether to include deleted entries, defaults to false.\n\t * @param options.verifyEntries Should the entries be verified, defaults to false.\n\t * @param options.limit How many entries to return.\n\t * @param options.cursor Cursor to use for next chunk of data.\n\t * @param options.order Retrieve the entries in ascending/descending time order, defaults to Ascending.\n\t * @returns The stream and entries if found.\n\t * @throws NotFoundError if the stream is not found.\n\t */\n\tpublic async getEntries(\n\t\tid?: string,\n\t\toptions?: {\n\t\t\tconditions?: IComparator[];\n\t\t\tincludeDeleted?: boolean;\n\t\t\tverifyEntries?: boolean;\n\t\t\tlimit?: number;\n\t\t\tcursor?: string;\n\t\t\torder?: SortDirection;\n\t\t}\n\t): Promise<{\n\t\tentries: IAuditableItemStreamEntryList;\n\t\tcursor?: string;\n\t}> {\n\t\tconst queryParams = {\n\t\t\tconditions: HttpParameterHelper.objectToString(options?.conditions),\n\t\t\tincludeDeleted: Coerce.string(options?.includeDeleted),\n\t\t\tverifyEntries: Coerce.string(options?.verifyEntries),\n\t\t\tlimit: Coerce.string(options?.limit),\n\t\t\tcursor: options?.cursor,\n\t\t\torder: options?.order\n\t\t};\n\n\t\tlet response;\n\t\tif (!Is.empty(id)) {\n\t\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(id), id);\n\n\t\t\tresponse = await this.fetch<\n\t\t\t\tIAuditableItemStreamListEntriesRequest,\n\t\t\t\tIAuditableItemStreamListEntriesResponse\n\t\t\t>(\"/:id/entries\", \"GET\", {\n\t\t\t\theaders: {\n\t\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t\t},\n\t\t\t\tpathParams: {\n\t\t\t\t\tid\n\t\t\t\t},\n\t\t\t\tquery: queryParams\n\t\t\t});\n\t\t} else {\n\t\t\tresponse = await this.fetch<\n\t\t\t\tIAuditableItemStreamListEntriesNoStreamRequest,\n\t\t\t\tIAuditableItemStreamListEntriesResponse\n\t\t\t>(\"/entries\", \"GET\", {\n\t\t\t\theaders: {\n\t\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t\t},\n\t\t\t\tquery: queryParams\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 the entry objects for the stream.\n\t * @param id The id of the stream to get, if undefined returns all matching entries.\n\t * @param options Additional options for the get operation.\n\t * @param options.conditions The conditions to filter the stream.\n\t * @param options.includeDeleted Whether to include deleted entries, defaults to false.\n\t * @param options.limit How many entries to return.\n\t * @param options.cursor Cursor to use for next chunk of data.\n\t * @param options.order Retrieve the entries in ascending/descending time order, defaults to Ascending.\n\t * @returns The stream and entries if found.\n\t * @throws NotFoundError if the stream is not found.\n\t */\n\tpublic async getEntryObjects(\n\t\tid?: string,\n\t\toptions?: {\n\t\t\tconditions?: IComparator[];\n\t\t\tincludeDeleted?: boolean;\n\t\t\tlimit?: number;\n\t\t\tcursor?: string;\n\t\t\torder?: SortDirection;\n\t\t}\n\t): Promise<{\n\t\tentries: IAuditableItemStreamEntryObjectList;\n\t\tcursor?: string;\n\t}> {\n\t\tconst queryParams = {\n\t\t\tconditions: HttpParameterHelper.objectToString(options?.conditions),\n\t\t\tincludeDeleted: Coerce.string(options?.includeDeleted),\n\t\t\tlimit: Coerce.string(options?.limit),\n\t\t\tcursor: options?.cursor,\n\t\t\torder: options?.order\n\t\t};\n\n\t\tlet response;\n\t\tif (!Is.empty(id)) {\n\t\t\tGuards.stringValue(AuditableItemStreamRestClient.CLASS_NAME, nameof(id), id);\n\t\t\tresponse = await this.fetch<\n\t\t\t\tIAuditableItemStreamListEntryObjectsRequest,\n\t\t\t\tIAuditableItemStreamListEntryObjectsResponse\n\t\t\t>(\"/:id/entries/objects\", \"GET\", {\n\t\t\t\theaders: {\n\t\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t\t},\n\t\t\t\tpathParams: {\n\t\t\t\t\tid\n\t\t\t\t},\n\t\t\t\tquery: queryParams\n\t\t\t});\n\t\t} else {\n\t\t\tresponse = await this.fetch<\n\t\t\t\tIAuditableItemStreamListEntryObjectsNoStreamRequest,\n\t\t\t\tIAuditableItemStreamListEntryObjectsResponse\n\t\t\t>(\"/entries/objects\", \"GET\", {\n\t\t\t\theaders: {\n\t\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t\t},\n\t\t\t\tquery: queryParams\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 * Remove the verifiable storage for the stream and entries, not supported on client.\n\t * @param id The id of the stream to remove the storage from.\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(AuditableItemStreamRestClient.CLASS_NAME, \"notSupportedOnClient\", {\n\t\t\tmethodName: \"removeVerifiable\"\n\t\t});\n\t}\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseRestClient } from "@twin.org/api-core";
|
|
2
2
|
import { type IBaseRestClientConfig } from "@twin.org/api-models";
|
|
3
|
-
import type { IAuditableItemStream, IAuditableItemStreamComponent, IAuditableItemStreamEntry, IAuditableItemStreamEntryList, IAuditableItemStreamEntryObjectList, IAuditableItemStreamList } from "@twin.org/auditable-item-stream-models";
|
|
3
|
+
import type { IAuditableItemStream, IAuditableItemStreamBase, IAuditableItemStreamComponent, IAuditableItemStreamEntry, IAuditableItemStreamEntryList, IAuditableItemStreamEntryObjectList, IAuditableItemStreamList } from "@twin.org/auditable-item-stream-models";
|
|
4
4
|
import type { IJsonLdNodeObject } from "@twin.org/data-json-ld";
|
|
5
5
|
import type { IComparator, SortDirection } from "@twin.org/entity";
|
|
6
6
|
/**
|
|
@@ -24,24 +24,14 @@ export declare class AuditableItemStreamRestClient extends BaseRestClient implem
|
|
|
24
24
|
/**
|
|
25
25
|
* Create a new stream.
|
|
26
26
|
* @param stream The stream to create.
|
|
27
|
-
* @param stream.annotationObject The object for the stream as JSON-LD.
|
|
28
|
-
* @param stream.entries Entries to store in the stream.
|
|
29
|
-
* @param options Options for creating the stream.
|
|
30
|
-
* @param options.immutableInterval After how many entries do we add immutable checks, defaults to service configured value.
|
|
31
|
-
* A value of 0 will disable integrity checks, 1 will be every item, or any other integer for an interval.
|
|
32
27
|
* @returns The id of the new stream item.
|
|
33
28
|
*/
|
|
34
|
-
create(stream:
|
|
35
|
-
annotationObject?: IJsonLdNodeObject;
|
|
36
|
-
entries?: {
|
|
37
|
-
entryObject: IJsonLdNodeObject;
|
|
38
|
-
}[];
|
|
39
|
-
}, options?: {
|
|
40
|
-
immutableInterval?: number;
|
|
41
|
-
}): Promise<string>;
|
|
29
|
+
create(stream: IAuditableItemStreamBase): Promise<string>;
|
|
42
30
|
/**
|
|
43
31
|
* Get a stream header without the entries.
|
|
44
32
|
* @param id The id of the stream to get.
|
|
33
|
+
* @param cursor Cursor to use for next chunk of entries.
|
|
34
|
+
* @param limit Limit the number of entries to return, only applicable if includeEntries is true.
|
|
45
35
|
* @param options Additional options for the get operation.
|
|
46
36
|
* @param options.includeEntries Whether to include the entries, defaults to false.
|
|
47
37
|
* @param options.includeDeleted Whether to include deleted entries, defaults to false.
|
|
@@ -50,23 +40,27 @@ export declare class AuditableItemStreamRestClient extends BaseRestClient implem
|
|
|
50
40
|
* @returns The stream and entries if found.
|
|
51
41
|
* @throws NotFoundError if the stream is not found
|
|
52
42
|
*/
|
|
53
|
-
get(id: string, options?: {
|
|
43
|
+
get(id: string, cursor?: string, limit?: number, options?: {
|
|
54
44
|
includeEntries?: boolean;
|
|
55
45
|
includeDeleted?: boolean;
|
|
56
46
|
verifyStream?: boolean;
|
|
57
47
|
verifyEntries?: boolean;
|
|
58
|
-
}): Promise<
|
|
48
|
+
}): Promise<{
|
|
49
|
+
stream: IAuditableItemStream;
|
|
50
|
+
cursor?: string;
|
|
51
|
+
}>;
|
|
59
52
|
/**
|
|
60
53
|
* Update a stream.
|
|
61
|
-
* @param stream The stream to update.
|
|
62
|
-
* @
|
|
63
|
-
|
|
54
|
+
* @param stream The stream to update, does not update entries.
|
|
55
|
+
* @returns Nothing.
|
|
56
|
+
*/
|
|
57
|
+
update(stream: Pick<IAuditableItemStream, "@context" | "type" | "id" | "annotationObject">): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Close the stream.
|
|
60
|
+
* @param id The id of the stream to close.
|
|
64
61
|
* @returns Nothing.
|
|
65
62
|
*/
|
|
66
|
-
|
|
67
|
-
id: string;
|
|
68
|
-
annotationObject?: IJsonLdNodeObject;
|
|
69
|
-
}): Promise<void>;
|
|
63
|
+
close(id: string): Promise<void>;
|
|
70
64
|
/**
|
|
71
65
|
* Delete the stream.
|
|
72
66
|
* @param id The id of the stream to remove.
|
package/docs/changelog.md
CHANGED
|
@@ -1,4 +1,32 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.0.3-next.13](https://github.com/twinfoundation/auditable-item-stream/compare/auditable-item-stream-rest-client-v0.0.3-next.12...auditable-item-stream-rest-client-v0.0.3-next.13) (2026-04-15)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add closable stream ([#59](https://github.com/twinfoundation/auditable-item-stream/issues/59)) ([26d3d08](https://github.com/twinfoundation/auditable-item-stream/commit/26d3d0887e1e57ca81859be5b56e853335a88d78))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/auditable-item-stream-models bumped from 0.0.3-next.12 to 0.0.3-next.13
|
|
16
|
+
|
|
17
|
+
## [0.0.3-next.12](https://github.com/twinfoundation/auditable-item-stream/compare/auditable-item-stream-rest-client-v0.0.3-next.11...auditable-item-stream-rest-client-v0.0.3-next.12) (2026-03-25)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* add validation and create structural changes ([#56](https://github.com/twinfoundation/auditable-item-stream/issues/56)) ([f7183b4](https://github.com/twinfoundation/auditable-item-stream/commit/f7183b42bf9563f8aa015476b82959fba2936bcd))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Dependencies
|
|
26
|
+
|
|
27
|
+
* The following workspace dependencies were updated
|
|
28
|
+
* dependencies
|
|
29
|
+
* @twin.org/auditable-item-stream-models bumped from 0.0.3-next.11 to 0.0.3-next.12
|
|
2
30
|
|
|
3
31
|
## [0.0.3-next.11](https://github.com/twinfoundation/auditable-item-stream/compare/auditable-item-stream-rest-client-v0.0.3-next.10...auditable-item-stream-rest-client-v0.0.3-next.11) (2026-02-25)
|
|
4
32
|
|
package/docs/examples.md
CHANGED
|
@@ -1 +1,183 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Auditable Item Stream REST Client Examples
|
|
2
|
+
|
|
3
|
+
These snippets show practical client-side workflows for creating streams, managing entries, and paging through results.
|
|
4
|
+
|
|
5
|
+
## AuditableItemStreamRestClient
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { AuditableItemStreamRestClient } from '@twin.org/auditable-item-stream-rest-client';
|
|
9
|
+
import type { IBaseRestClientConfig } from '@twin.org/api-models';
|
|
10
|
+
|
|
11
|
+
const config: IBaseRestClientConfig = {
|
|
12
|
+
endpoint: 'http://localhost:3000'
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const client = new AuditableItemStreamRestClient(config);
|
|
16
|
+
console.log(client.className()); // AuditableItemStreamRestClient
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { AuditableItemStreamRestClient } from '@twin.org/auditable-item-stream-rest-client';
|
|
21
|
+
import type { IBaseRestClientConfig } from '@twin.org/api-models';
|
|
22
|
+
|
|
23
|
+
const config: IBaseRestClientConfig = {
|
|
24
|
+
endpoint: 'http://localhost:3000'
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const client = new AuditableItemStreamRestClient(config);
|
|
28
|
+
|
|
29
|
+
const streamId = await client.create(
|
|
30
|
+
{
|
|
31
|
+
annotationObject: {
|
|
32
|
+
'@context': 'https://schema.org',
|
|
33
|
+
'@type': 'CreativeWork',
|
|
34
|
+
name: 'Monthly Compliance Report'
|
|
35
|
+
},
|
|
36
|
+
entries: [
|
|
37
|
+
{
|
|
38
|
+
entryObject: {
|
|
39
|
+
'@context': 'https://schema.org',
|
|
40
|
+
'@type': 'Event',
|
|
41
|
+
name: 'Report created'
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
immutableInterval: 5
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const stream = await client.get(streamId, {
|
|
52
|
+
includeEntries: true,
|
|
53
|
+
verifyStream: true,
|
|
54
|
+
verifyEntries: true
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
await client.update({
|
|
58
|
+
id: streamId,
|
|
59
|
+
annotationObject: {
|
|
60
|
+
'@context': 'https://schema.org',
|
|
61
|
+
'@type': 'CreativeWork',
|
|
62
|
+
name: 'Monthly Compliance Report v2'
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
console.log(stream.id); // ais:...
|
|
67
|
+
console.log(stream.numberOfItems); // 1
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { AuditableItemStreamRestClient } from '@twin.org/auditable-item-stream-rest-client';
|
|
72
|
+
import type { IBaseRestClientConfig } from '@twin.org/api-models';
|
|
73
|
+
import { ComparisonOperator, SortDirection } from '@twin.org/entity';
|
|
74
|
+
|
|
75
|
+
const config: IBaseRestClientConfig = {
|
|
76
|
+
endpoint: 'http://localhost:3000'
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const client = new AuditableItemStreamRestClient(config);
|
|
80
|
+
|
|
81
|
+
const firstPage = await client.query(
|
|
82
|
+
[
|
|
83
|
+
{
|
|
84
|
+
property: 'organizationIdentity',
|
|
85
|
+
comparison: ComparisonOperator.Equals,
|
|
86
|
+
value: 'did:iota:org:123'
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
'dateCreated',
|
|
90
|
+
SortDirection.Descending,
|
|
91
|
+
['id', 'dateCreated', 'dateModified', 'numberOfItems'],
|
|
92
|
+
'cursor:page-1',
|
|
93
|
+
10
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
console.log(firstPage.entries.itemListElement.length); // 10
|
|
97
|
+
console.log(firstPage.cursor); // eyJjdXJzb3IiOiIuLi4ifQ==
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { AuditableItemStreamRestClient } from '@twin.org/auditable-item-stream-rest-client';
|
|
102
|
+
import type { IBaseRestClientConfig } from '@twin.org/api-models';
|
|
103
|
+
|
|
104
|
+
const config: IBaseRestClientConfig = {
|
|
105
|
+
endpoint: 'http://localhost:3000'
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const client = new AuditableItemStreamRestClient(config);
|
|
109
|
+
const streamId = 'ais:0f4f9de65dc44f31b4a474a0cc93ce69';
|
|
110
|
+
|
|
111
|
+
const entryId = await client.createEntry(streamId, {
|
|
112
|
+
'@context': 'https://schema.org',
|
|
113
|
+
'@type': 'Message',
|
|
114
|
+
text: 'Status changed to approved'
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const entry = await client.getEntry(streamId, entryId, {
|
|
118
|
+
verifyEntry: true
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
await client.updateEntry(streamId, entryId, {
|
|
122
|
+
'@context': 'https://schema.org',
|
|
123
|
+
'@type': 'Message',
|
|
124
|
+
text: 'Status changed to approved by reviewer'
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const entryObject = await client.getEntryObject(streamId, entryId);
|
|
128
|
+
console.log(entry.id); // ais:0f4f9de65dc44f31b4a474a0cc93ce69:...
|
|
129
|
+
console.log(entryObject['@type']); // Message
|
|
130
|
+
|
|
131
|
+
await client.removeEntry(streamId, entryId);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import { AuditableItemStreamRestClient } from '@twin.org/auditable-item-stream-rest-client';
|
|
136
|
+
import type { IBaseRestClientConfig } from '@twin.org/api-models';
|
|
137
|
+
import { SortDirection } from '@twin.org/entity';
|
|
138
|
+
|
|
139
|
+
const config: IBaseRestClientConfig = {
|
|
140
|
+
endpoint: 'http://localhost:3000'
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const client = new AuditableItemStreamRestClient(config);
|
|
144
|
+
const streamId = 'ais:0f4f9de65dc44f31b4a474a0cc93ce69';
|
|
145
|
+
|
|
146
|
+
const entryList = await client.getEntries(streamId, {
|
|
147
|
+
includeDeleted: false,
|
|
148
|
+
verifyEntries: false,
|
|
149
|
+
limit: 20,
|
|
150
|
+
order: SortDirection.Ascending
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const entryObjectList = await client.getEntryObjects(streamId, {
|
|
154
|
+
includeDeleted: true,
|
|
155
|
+
limit: 20,
|
|
156
|
+
order: SortDirection.Descending
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
console.log(entryList.entries.itemListElement.length); // 20
|
|
160
|
+
console.log(entryObjectList.entries.itemListElement.length); // 20
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
import { AuditableItemStreamRestClient } from '@twin.org/auditable-item-stream-rest-client';
|
|
165
|
+
import type { IBaseRestClientConfig } from '@twin.org/api-models';
|
|
166
|
+
|
|
167
|
+
const config: IBaseRestClientConfig = {
|
|
168
|
+
endpoint: 'http://localhost:3000'
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const client = new AuditableItemStreamRestClient(config);
|
|
172
|
+
const streamId = 'ais:0f4f9de65dc44f31b4a474a0cc93ce69';
|
|
173
|
+
|
|
174
|
+
try {
|
|
175
|
+
await client.removeVerifiable(streamId);
|
|
176
|
+
} catch (error) {
|
|
177
|
+
if (error instanceof Error) {
|
|
178
|
+
console.log(error.name); // NotSupportedError
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
await client.remove(streamId);
|
|
183
|
+
```
|
|
@@ -36,7 +36,7 @@ The configuration for the client.
|
|
|
36
36
|
|
|
37
37
|
## Properties
|
|
38
38
|
|
|
39
|
-
### CLASS\_NAME
|
|
39
|
+
### CLASS\_NAME {#class_name}
|
|
40
40
|
|
|
41
41
|
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
42
42
|
|
|
@@ -44,7 +44,7 @@ Runtime name for the class.
|
|
|
44
44
|
|
|
45
45
|
## Methods
|
|
46
46
|
|
|
47
|
-
### className()
|
|
47
|
+
### className() {#classname}
|
|
48
48
|
|
|
49
49
|
> **className**(): `string`
|
|
50
50
|
|
|
@@ -62,9 +62,9 @@ The class name of the component.
|
|
|
62
62
|
|
|
63
63
|
***
|
|
64
64
|
|
|
65
|
-
### create()
|
|
65
|
+
### create() {#create}
|
|
66
66
|
|
|
67
|
-
> **create**(`stream
|
|
67
|
+
> **create**(`stream`): `Promise`\<`string`\>
|
|
68
68
|
|
|
69
69
|
Create a new stream.
|
|
70
70
|
|
|
@@ -72,30 +72,9 @@ Create a new stream.
|
|
|
72
72
|
|
|
73
73
|
##### stream
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
###### annotationObject?
|
|
78
|
-
|
|
79
|
-
`IJsonLdNodeObject`
|
|
80
|
-
|
|
81
|
-
The object for the stream as JSON-LD.
|
|
82
|
-
|
|
83
|
-
###### entries?
|
|
84
|
-
|
|
85
|
-
`object`[]
|
|
86
|
-
|
|
87
|
-
Entries to store in the stream.
|
|
88
|
-
|
|
89
|
-
##### options?
|
|
90
|
-
|
|
91
|
-
Options for creating the stream.
|
|
92
|
-
|
|
93
|
-
###### immutableInterval?
|
|
75
|
+
`IAuditableItemStreamBase`
|
|
94
76
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
After how many entries do we add immutable checks, defaults to service configured value.
|
|
98
|
-
A value of 0 will disable integrity checks, 1 will be every item, or any other integer for an interval.
|
|
77
|
+
The stream to create.
|
|
99
78
|
|
|
100
79
|
#### Returns
|
|
101
80
|
|
|
@@ -109,9 +88,9 @@ The id of the new stream item.
|
|
|
109
88
|
|
|
110
89
|
***
|
|
111
90
|
|
|
112
|
-
### get()
|
|
91
|
+
### get() {#get}
|
|
113
92
|
|
|
114
|
-
> **get**(`id`, `options?`): `Promise
|
|
93
|
+
> **get**(`id`, `cursor?`, `limit?`, `options?`): `Promise`\<\{ `stream`: `IAuditableItemStream`; `cursor?`: `string`; \}\>
|
|
115
94
|
|
|
116
95
|
Get a stream header without the entries.
|
|
117
96
|
|
|
@@ -123,6 +102,18 @@ Get a stream header without the entries.
|
|
|
123
102
|
|
|
124
103
|
The id of the stream to get.
|
|
125
104
|
|
|
105
|
+
##### cursor?
|
|
106
|
+
|
|
107
|
+
`string`
|
|
108
|
+
|
|
109
|
+
Cursor to use for next chunk of entries.
|
|
110
|
+
|
|
111
|
+
##### limit?
|
|
112
|
+
|
|
113
|
+
`number`
|
|
114
|
+
|
|
115
|
+
Limit the number of entries to return, only applicable if includeEntries is true.
|
|
116
|
+
|
|
126
117
|
##### options?
|
|
127
118
|
|
|
128
119
|
Additional options for the get operation.
|
|
@@ -153,7 +144,7 @@ Should the entries be verified, defaults to false.
|
|
|
153
144
|
|
|
154
145
|
#### Returns
|
|
155
146
|
|
|
156
|
-
`Promise
|
|
147
|
+
`Promise`\<\{ `stream`: `IAuditableItemStream`; `cursor?`: `string`; \}\>
|
|
157
148
|
|
|
158
149
|
The stream and entries if found.
|
|
159
150
|
|
|
@@ -167,7 +158,7 @@ NotFoundError if the stream is not found
|
|
|
167
158
|
|
|
168
159
|
***
|
|
169
160
|
|
|
170
|
-
### update()
|
|
161
|
+
### update() {#update}
|
|
171
162
|
|
|
172
163
|
> **update**(`stream`): `Promise`\<`void`\>
|
|
173
164
|
|
|
@@ -177,19 +168,35 @@ Update a stream.
|
|
|
177
168
|
|
|
178
169
|
##### stream
|
|
179
170
|
|
|
180
|
-
|
|
171
|
+
`Pick`\<`IAuditableItemStream`, `"@context"` \| `"type"` \| `"id"` \| `"annotationObject"`\>
|
|
181
172
|
|
|
182
|
-
|
|
173
|
+
The stream to update, does not update entries.
|
|
183
174
|
|
|
184
|
-
|
|
175
|
+
#### Returns
|
|
185
176
|
|
|
186
|
-
|
|
177
|
+
`Promise`\<`void`\>
|
|
187
178
|
|
|
188
|
-
|
|
179
|
+
Nothing.
|
|
189
180
|
|
|
190
|
-
|
|
181
|
+
#### Implementation of
|
|
191
182
|
|
|
192
|
-
|
|
183
|
+
`IAuditableItemStreamComponent.update`
|
|
184
|
+
|
|
185
|
+
***
|
|
186
|
+
|
|
187
|
+
### close() {#close}
|
|
188
|
+
|
|
189
|
+
> **close**(`id`): `Promise`\<`void`\>
|
|
190
|
+
|
|
191
|
+
Close the stream.
|
|
192
|
+
|
|
193
|
+
#### Parameters
|
|
194
|
+
|
|
195
|
+
##### id
|
|
196
|
+
|
|
197
|
+
`string`
|
|
198
|
+
|
|
199
|
+
The id of the stream to close.
|
|
193
200
|
|
|
194
201
|
#### Returns
|
|
195
202
|
|
|
@@ -199,11 +206,11 @@ Nothing.
|
|
|
199
206
|
|
|
200
207
|
#### Implementation of
|
|
201
208
|
|
|
202
|
-
`IAuditableItemStreamComponent.
|
|
209
|
+
`IAuditableItemStreamComponent.close`
|
|
203
210
|
|
|
204
211
|
***
|
|
205
212
|
|
|
206
|
-
### remove()
|
|
213
|
+
### remove() {#remove}
|
|
207
214
|
|
|
208
215
|
> **remove**(`id`): `Promise`\<`void`\>
|
|
209
216
|
|
|
@@ -229,7 +236,7 @@ Nothing.
|
|
|
229
236
|
|
|
230
237
|
***
|
|
231
238
|
|
|
232
|
-
### query()
|
|
239
|
+
### query() {#query}
|
|
233
240
|
|
|
234
241
|
> **query**(`conditions?`, `orderBy?`, `orderByDirection?`, `properties?`, `cursor?`, `limit?`): `Promise`\<\{ `entries`: `IAuditableItemStreamList`; `cursor?`: `string`; \}\>
|
|
235
242
|
|
|
@@ -245,9 +252,9 @@ Conditions to use in the query.
|
|
|
245
252
|
|
|
246
253
|
##### orderBy?
|
|
247
254
|
|
|
248
|
-
|
|
255
|
+
`"dateCreated"` \| `"dateModified"`
|
|
249
256
|
|
|
250
|
-
|
|
257
|
+
The order for the results, defaults to created.
|
|
251
258
|
|
|
252
259
|
##### orderByDirection?
|
|
253
260
|
|
|
@@ -285,7 +292,7 @@ The entities, which can be partial if a limited keys list was provided.
|
|
|
285
292
|
|
|
286
293
|
***
|
|
287
294
|
|
|
288
|
-
### createEntry()
|
|
295
|
+
### createEntry() {#createentry}
|
|
289
296
|
|
|
290
297
|
> **createEntry**(`id`, `entryObject`): `Promise`\<`string`\>
|
|
291
298
|
|
|
@@ -317,7 +324,7 @@ The id of the created entry, if not provided.
|
|
|
317
324
|
|
|
318
325
|
***
|
|
319
326
|
|
|
320
|
-
### getEntry()
|
|
327
|
+
### getEntry() {#getentry}
|
|
321
328
|
|
|
322
329
|
> **getEntry**(`id`, `entryId`, `options?`): `Promise`\<`IAuditableItemStreamEntry`\>
|
|
323
330
|
|
|
@@ -363,7 +370,7 @@ NotFoundError if the stream is not found.
|
|
|
363
370
|
|
|
364
371
|
***
|
|
365
372
|
|
|
366
|
-
### getEntryObject()
|
|
373
|
+
### getEntryObject() {#getentryobject}
|
|
367
374
|
|
|
368
375
|
> **getEntryObject**(`id`, `entryId`): `Promise`\<`IJsonLdNodeObject`\>
|
|
369
376
|
|
|
@@ -399,7 +406,7 @@ NotFoundError if the stream is not found.
|
|
|
399
406
|
|
|
400
407
|
***
|
|
401
408
|
|
|
402
|
-
### updateEntry()
|
|
409
|
+
### updateEntry() {#updateentry}
|
|
403
410
|
|
|
404
411
|
> **updateEntry**(`id`, `entryId`, `entryObject`): `Promise`\<`void`\>
|
|
405
412
|
|
|
@@ -437,7 +444,7 @@ Nothing.
|
|
|
437
444
|
|
|
438
445
|
***
|
|
439
446
|
|
|
440
|
-
### removeEntry()
|
|
447
|
+
### removeEntry() {#removeentry}
|
|
441
448
|
|
|
442
449
|
> **removeEntry**(`id`, `entryId`): `Promise`\<`void`\>
|
|
443
450
|
|
|
@@ -469,7 +476,7 @@ Nothing.
|
|
|
469
476
|
|
|
470
477
|
***
|
|
471
478
|
|
|
472
|
-
### getEntries()
|
|
479
|
+
### getEntries() {#getentries}
|
|
473
480
|
|
|
474
481
|
> **getEntries**(`id?`, `options?`): `Promise`\<\{ `entries`: `IAuditableItemStreamEntryList`; `cursor?`: `string`; \}\>
|
|
475
482
|
|
|
@@ -539,7 +546,7 @@ NotFoundError if the stream is not found.
|
|
|
539
546
|
|
|
540
547
|
***
|
|
541
548
|
|
|
542
|
-
### getEntryObjects()
|
|
549
|
+
### getEntryObjects() {#getentryobjects}
|
|
543
550
|
|
|
544
551
|
> **getEntryObjects**(`id?`, `options?`): `Promise`\<\{ `entries`: `IAuditableItemStreamEntryObjectList`; `cursor?`: `string`; \}\>
|
|
545
552
|
|
|
@@ -603,7 +610,7 @@ NotFoundError if the stream is not found.
|
|
|
603
610
|
|
|
604
611
|
***
|
|
605
612
|
|
|
606
|
-
### removeVerifiable()
|
|
613
|
+
### removeVerifiable() {#removeverifiable}
|
|
607
614
|
|
|
608
615
|
> **removeVerifiable**(`id`): `Promise`\<`void`\>
|
|
609
616
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/auditable-item-stream-rest-client",
|
|
3
|
-
"version": "0.0.3-next.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.3-next.13",
|
|
4
|
+
"description": "HTTP client for interacting with auditable stream service endpoints.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/twinfoundation/auditable-item-stream.git",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@twin.org/api-core": "next",
|
|
18
18
|
"@twin.org/api-models": "next",
|
|
19
|
-
"@twin.org/auditable-item-stream-models": "0.0.3-next.
|
|
19
|
+
"@twin.org/auditable-item-stream-models": "0.0.3-next.13",
|
|
20
20
|
"@twin.org/core": "next",
|
|
21
21
|
"@twin.org/data-json-ld": "next",
|
|
22
22
|
"@twin.org/entity": "next",
|