@twin.org/auditable-item-stream-service 0.0.3-next.10 → 0.0.3-next.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/es/auditableItemStreamRoutes.js +84 -60
- package/dist/es/auditableItemStreamRoutes.js.map +1 -1
- package/dist/es/auditableItemStreamService.js +73 -61
- package/dist/es/auditableItemStreamService.js.map +1 -1
- package/dist/types/auditableItemStreamService.d.ts +15 -27
- package/docs/changelog.md +29 -1
- package/docs/examples.md +211 -1
- package/docs/open-api/spec.json +127 -117
- package/docs/reference/classes/AuditableItemStream.md +14 -14
- package/docs/reference/classes/AuditableItemStreamEntry.md +13 -13
- package/docs/reference/classes/AuditableItemStreamService.md +51 -70
- package/docs/reference/interfaces/IAuditableItemStreamServiceConfig.md +2 -2
- package/docs/reference/interfaces/IAuditableItemStreamServiceConstructorOptions.md +10 -10
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Auditable Item Stream Service
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package provides the service layer for auditable item streams, including stream and entry lifecycle operations, entity schema initialisation, and REST route generation for API hosts.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -39,21 +39,31 @@ export function generateRestRoutesAuditableItemStream(baseRouteName, componentNa
|
|
|
39
39
|
id: "auditableItemStreamCreateRequestExample",
|
|
40
40
|
request: {
|
|
41
41
|
body: {
|
|
42
|
+
"@context": [
|
|
43
|
+
SchemaOrgContexts.Context,
|
|
44
|
+
AuditableItemStreamContexts.Context,
|
|
45
|
+
AuditableItemStreamContexts.ContextCommon
|
|
46
|
+
],
|
|
47
|
+
type: AuditableItemStreamTypes.Stream,
|
|
42
48
|
annotationObject: {
|
|
43
49
|
"@context": "https://schema.org",
|
|
44
50
|
"@type": "Note",
|
|
45
51
|
content: "This is a simple note"
|
|
46
52
|
},
|
|
47
|
-
entries:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
entries: {
|
|
54
|
+
type: SchemaOrgTypes.ItemList,
|
|
55
|
+
[SchemaOrgTypes.ItemListElement]: [
|
|
56
|
+
{
|
|
57
|
+
type: AuditableItemStreamTypes.StreamEntry,
|
|
58
|
+
entryObject: {
|
|
59
|
+
"@context": "https://schema.org",
|
|
60
|
+
"@type": "Event",
|
|
61
|
+
startDate: "2011-04-09T20:00:00Z",
|
|
62
|
+
description: "A description of the event"
|
|
63
|
+
}
|
|
54
64
|
}
|
|
55
|
-
|
|
56
|
-
|
|
65
|
+
]
|
|
66
|
+
}
|
|
57
67
|
}
|
|
58
68
|
}
|
|
59
69
|
}
|
|
@@ -109,6 +119,7 @@ export function generateRestRoutesAuditableItemStream(baseRouteName, componentNa
|
|
|
109
119
|
response: {
|
|
110
120
|
body: {
|
|
111
121
|
"@context": [
|
|
122
|
+
SchemaOrgContexts.Context,
|
|
112
123
|
AuditableItemStreamContexts.Context,
|
|
113
124
|
AuditableItemStreamContexts.ContextCommon
|
|
114
125
|
],
|
|
@@ -125,25 +136,28 @@ export function generateRestRoutesAuditableItemStream(baseRouteName, componentNa
|
|
|
125
136
|
proofId: "0101010101010101010101010101010101010101010101010101010101010101",
|
|
126
137
|
immutableInterval: 10,
|
|
127
138
|
numberOfItems: 1,
|
|
128
|
-
entries:
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
entries: {
|
|
140
|
+
type: SchemaOrgTypes.ItemList,
|
|
141
|
+
[SchemaOrgTypes.ItemListElement]: [
|
|
142
|
+
{
|
|
143
|
+
"@context": [
|
|
144
|
+
AuditableItemStreamContexts.Context,
|
|
145
|
+
AuditableItemStreamContexts.ContextCommon
|
|
146
|
+
],
|
|
147
|
+
type: AuditableItemStreamTypes.StreamEntry,
|
|
148
|
+
id: "tst:1234567890",
|
|
149
|
+
dateCreated: "2024-08-22T11:55:16.271Z",
|
|
150
|
+
proofId: "0101010101010101010101010101010101010101010101010101010101010101",
|
|
151
|
+
index: 0,
|
|
152
|
+
entryObject: {
|
|
153
|
+
"@context": "https://schema.org",
|
|
154
|
+
"@type": "Event",
|
|
155
|
+
startDate: "2011-04-09T20:00:00Z",
|
|
156
|
+
description: "A description of the event"
|
|
157
|
+
}
|
|
144
158
|
}
|
|
145
|
-
|
|
146
|
-
|
|
159
|
+
]
|
|
160
|
+
}
|
|
147
161
|
}
|
|
148
162
|
}
|
|
149
163
|
}
|
|
@@ -161,6 +175,7 @@ export function generateRestRoutesAuditableItemStream(baseRouteName, componentNa
|
|
|
161
175
|
},
|
|
162
176
|
body: {
|
|
163
177
|
"@context": [
|
|
178
|
+
SchemaOrgContexts.Context,
|
|
164
179
|
AuditableItemStreamContexts.Context,
|
|
165
180
|
AuditableItemStreamContexts.ContextCommon
|
|
166
181
|
],
|
|
@@ -177,25 +192,28 @@ export function generateRestRoutesAuditableItemStream(baseRouteName, componentNa
|
|
|
177
192
|
proofId: "0101010101010101010101010101010101010101010101010101010101010101",
|
|
178
193
|
immutableInterval: 10,
|
|
179
194
|
numberOfItems: 1,
|
|
180
|
-
entries:
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
195
|
+
entries: {
|
|
196
|
+
type: SchemaOrgTypes.ItemList,
|
|
197
|
+
[SchemaOrgTypes.ItemListElement]: [
|
|
198
|
+
{
|
|
199
|
+
"@context": [
|
|
200
|
+
AuditableItemStreamContexts.Context,
|
|
201
|
+
AuditableItemStreamContexts.ContextCommon
|
|
202
|
+
],
|
|
203
|
+
type: AuditableItemStreamTypes.StreamEntry,
|
|
204
|
+
id: "tst:1234567890",
|
|
205
|
+
dateCreated: "2024-08-22T11:55:16.271Z",
|
|
206
|
+
proofId: "0101010101010101010101010101010101010101010101010101010101010101",
|
|
207
|
+
index: 0,
|
|
208
|
+
entryObject: {
|
|
209
|
+
"@context": "https://schema.org",
|
|
210
|
+
"@type": "Event",
|
|
211
|
+
startDate: "2011-04-09T20:00:00Z",
|
|
212
|
+
description: "A description of the event"
|
|
213
|
+
}
|
|
196
214
|
}
|
|
197
|
-
|
|
198
|
-
|
|
215
|
+
]
|
|
216
|
+
}
|
|
199
217
|
}
|
|
200
218
|
}
|
|
201
219
|
}
|
|
@@ -223,6 +241,12 @@ export function generateRestRoutesAuditableItemStream(baseRouteName, componentNa
|
|
|
223
241
|
id: "ais:1234567890"
|
|
224
242
|
},
|
|
225
243
|
body: {
|
|
244
|
+
"@context": [
|
|
245
|
+
SchemaOrgContexts.Context,
|
|
246
|
+
AuditableItemStreamContexts.Context,
|
|
247
|
+
AuditableItemStreamContexts.ContextCommon
|
|
248
|
+
],
|
|
249
|
+
type: AuditableItemStreamTypes.Stream,
|
|
226
250
|
annotationObject: {
|
|
227
251
|
"@context": "https://schema.org",
|
|
228
252
|
"@type": "Note",
|
|
@@ -304,6 +328,7 @@ export function generateRestRoutesAuditableItemStream(baseRouteName, componentNa
|
|
|
304
328
|
[SchemaOrgTypes.ItemListElement]: [
|
|
305
329
|
{
|
|
306
330
|
"@context": [
|
|
331
|
+
SchemaOrgContexts.Context,
|
|
307
332
|
AuditableItemStreamContexts.Context,
|
|
308
333
|
AuditableItemStreamContexts.ContextCommon
|
|
309
334
|
],
|
|
@@ -347,6 +372,7 @@ export function generateRestRoutesAuditableItemStream(baseRouteName, componentNa
|
|
|
347
372
|
[SchemaOrgTypes.ItemListElement]: [
|
|
348
373
|
{
|
|
349
374
|
"@context": [
|
|
375
|
+
SchemaOrgContexts.Context,
|
|
350
376
|
AuditableItemStreamContexts.Context,
|
|
351
377
|
AuditableItemStreamContexts.ContextCommon
|
|
352
378
|
],
|
|
@@ -948,12 +974,7 @@ export async function auditableItemStreamCreate(httpRequestContext, componentNam
|
|
|
948
974
|
Guards.object(ROUTES_SOURCE, "request", request);
|
|
949
975
|
Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
950
976
|
const component = ComponentFactory.get(componentName);
|
|
951
|
-
const id = await component.create(
|
|
952
|
-
annotationObject: request.body.annotationObject,
|
|
953
|
-
entries: request.body.entries
|
|
954
|
-
}, {
|
|
955
|
-
immutableInterval: request.body?.immutableInterval
|
|
956
|
-
});
|
|
977
|
+
const id = await component.create(request.body);
|
|
957
978
|
return {
|
|
958
979
|
statusCode: HttpStatusCode.created,
|
|
959
980
|
headers: {
|
|
@@ -972,20 +993,23 @@ export async function auditableItemStreamGet(httpRequestContext, componentName,
|
|
|
972
993
|
Guards.object(ROUTES_SOURCE, "request", request);
|
|
973
994
|
Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
974
995
|
Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
|
|
996
|
+
const hostingComponent = ComponentFactory.get(httpRequestContext.hostingComponentType ?? "hosting");
|
|
975
997
|
const component = ComponentFactory.get(componentName);
|
|
976
|
-
const result = await component.get(request.pathParams.id, {
|
|
998
|
+
const result = await component.get(request.pathParams.id, request.query?.cursor, Coerce.integer(request.query?.limit), {
|
|
977
999
|
includeEntries: Coerce.boolean(request.query?.includeEntries),
|
|
978
1000
|
includeDeleted: Coerce.boolean(request.query?.includeDeleted),
|
|
979
1001
|
verifyStream: Coerce.boolean(request.query?.verifyStream),
|
|
980
1002
|
verifyEntries: Coerce.boolean(request.query?.verifyEntries)
|
|
981
1003
|
});
|
|
1004
|
+
const headers = {
|
|
1005
|
+
[HeaderTypes.ContentType]: request.headers?.[HeaderTypes.Accept] === MimeTypes.JsonLd ? MimeTypes.JsonLd : MimeTypes.Json
|
|
1006
|
+
};
|
|
1007
|
+
if (Is.stringValue(result.cursor)) {
|
|
1008
|
+
headers[HeaderTypes.Link] = HeaderHelper.createLinkHeader(await hostingComponent.buildPublicUrl(httpRequestContext.serverRequest.url), { cursor: result.cursor }, "next");
|
|
1009
|
+
}
|
|
982
1010
|
return {
|
|
983
|
-
headers
|
|
984
|
-
|
|
985
|
-
? MimeTypes.JsonLd
|
|
986
|
-
: MimeTypes.Json
|
|
987
|
-
},
|
|
988
|
-
body: result
|
|
1011
|
+
headers,
|
|
1012
|
+
body: result.stream
|
|
989
1013
|
};
|
|
990
1014
|
}
|
|
991
1015
|
/**
|
|
@@ -1002,8 +1026,8 @@ export async function auditableItemStreamUpdate(httpRequestContext, componentNam
|
|
|
1002
1026
|
Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
1003
1027
|
const component = ComponentFactory.get(componentName);
|
|
1004
1028
|
await component.update({
|
|
1005
|
-
|
|
1006
|
-
|
|
1029
|
+
...request.body,
|
|
1030
|
+
id: request.pathParams.id
|
|
1007
1031
|
});
|
|
1008
1032
|
return {
|
|
1009
1033
|
statusCode: HttpStatusCode.noContent
|