@3sixty/auditable-item-graph-rest-client 0.0.0-stage → 0.20.0-next.1
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/LICENSE +201 -0
- package/README.md +26 -2
- package/dist/es/auditableItemGraphRestClient.js +267 -0
- package/dist/es/auditableItemGraphRestClient.js.map +1 -0
- package/dist/es/index.js +4 -0
- package/dist/es/index.js.map +1 -0
- package/dist/types/auditableItemGraphRestClient.d.ts +143 -0
- package/dist/types/index.d.ts +1 -0
- package/docs/changelog.md +16 -0
- package/docs/examples.md +119 -0
- package/docs/reference/classes/AuditableItemGraphRestClient.md +468 -0
- package/docs/reference/index.md +5 -0
- package/locales/en.json +1 -0
- package/package.json +54 -5
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { BaseRestClient } from "@3sixty/api-core";
|
|
2
|
+
import { type IBaseRestClientConfig } from "@3sixty/api-models";
|
|
3
|
+
import type { IAuditableItemGraphChangeset, IAuditableItemGraphChangesetList, IAuditableItemGraphComponent, IAuditableItemGraphPartialVertex, IAuditableItemGraphVertex, IAuditableItemGraphVertexList, IAuditableItemGraphVertexVersionList, VerifyDepth } from "@3sixty/auditable-item-graph-models";
|
|
4
|
+
import type { EntityCondition, SortDirection } from "@3sixty/entity";
|
|
5
|
+
/**
|
|
6
|
+
* Client for performing auditable item graph through to REST endpoints.
|
|
7
|
+
*/
|
|
8
|
+
export declare class AuditableItemGraphRestClient extends BaseRestClient implements IAuditableItemGraphComponent {
|
|
9
|
+
/**
|
|
10
|
+
* Runtime name for the class.
|
|
11
|
+
*/
|
|
12
|
+
static readonly CLASS_NAME: string;
|
|
13
|
+
/**
|
|
14
|
+
* Create a new instance of AuditableItemGraphRestClient.
|
|
15
|
+
* @param config The configuration for the client.
|
|
16
|
+
*/
|
|
17
|
+
constructor(config: IBaseRestClientConfig);
|
|
18
|
+
/**
|
|
19
|
+
* Returns the class name of the component.
|
|
20
|
+
* @returns The class name of the component.
|
|
21
|
+
*/
|
|
22
|
+
className(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Create a new graph vertex.
|
|
25
|
+
* @param vertex The vertex to create.
|
|
26
|
+
* @param vertex.annotationObject The annotation object for the vertex as JSON-LD.
|
|
27
|
+
* @param vertex.aliases Alternative aliases that can be used to identify the vertex.
|
|
28
|
+
* @param vertex.resources The resources attached to the vertex.
|
|
29
|
+
* @param vertex.edges The edges connected to the vertex.
|
|
30
|
+
* @returns The id of the new graph item.
|
|
31
|
+
*/
|
|
32
|
+
create(vertex: Omit<IAuditableItemGraphVertex, "id">): Promise<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Get a graph vertex.
|
|
35
|
+
* @param id The id of the vertex to get.
|
|
36
|
+
* @param options Additional options for the get operation.
|
|
37
|
+
* @param options.includeDeleted Whether to include deleted/updated aliases, resource, edges, defaults to false.
|
|
38
|
+
* @param options.verifySignatureDepth How many signatures to verify, defaults to "none".
|
|
39
|
+
* @returns The vertex if found.
|
|
40
|
+
* @throws NotFoundError if the vertex is not found.
|
|
41
|
+
*/
|
|
42
|
+
get(id: string, options?: {
|
|
43
|
+
includeDeleted?: boolean;
|
|
44
|
+
verifySignatureDepth?: VerifyDepth;
|
|
45
|
+
}): Promise<IAuditableItemGraphVertex>;
|
|
46
|
+
/**
|
|
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.
|
|
97
|
+
* @param vertex The vertex to update.
|
|
98
|
+
* @param vertex.id The id of the vertex to update.
|
|
99
|
+
* @param vertex.annotationObject The annotation object for the vertex as JSON-LD.
|
|
100
|
+
* @param vertex.aliases Alternative aliases that can be used to identify the vertex.
|
|
101
|
+
* @param vertex.resources The resources attached to the vertex.
|
|
102
|
+
* @param vertex.edges The edges connected to the vertex.
|
|
103
|
+
* @returns A promise that resolves when the vertex has been updated.
|
|
104
|
+
*/
|
|
105
|
+
update(vertex: IAuditableItemGraphVertex): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Partially update a graph vertex (PATCH - optional scalars; list fields use `{ add, remove }`).
|
|
108
|
+
* @param partial The partial vertex update (must include `id`).
|
|
109
|
+
* @returns A promise that resolves when the partial update has been applied.
|
|
110
|
+
*/
|
|
111
|
+
updatePartial(partial: IAuditableItemGraphPartialVertex): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Remove the notarization proof from all changesets of a graph vertex.
|
|
114
|
+
* @param id The id of the vertex.
|
|
115
|
+
* @returns A promise that resolves when the proof has been removed.
|
|
116
|
+
*/
|
|
117
|
+
removeProof(id: string): Promise<void>;
|
|
118
|
+
/**
|
|
119
|
+
* Query the graph for vertices.
|
|
120
|
+
* @param options The query options.
|
|
121
|
+
* @param options.id The optional id to look for.
|
|
122
|
+
* @param options.idMode Look in id, alias or both, defaults to both.
|
|
123
|
+
* @param options.idExact Find only exact matches, default to false meaning partial matching.
|
|
124
|
+
* @param options.resourceTypes Include vertices with specific resource types.
|
|
125
|
+
* @param conditions Conditions to use in the query.
|
|
126
|
+
* @param orderBy The order for the results, defaults to created.
|
|
127
|
+
* @param orderByDirection The direction for the order, defaults to descending.
|
|
128
|
+
* @param properties The properties to return, if not provided defaults to id, created, aliases and object.
|
|
129
|
+
* @param cursor The cursor to request the next chunk of entities.
|
|
130
|
+
* @param limit The maximum number of entities to return, a page can contain fewer so follow
|
|
131
|
+
* the cursor until it is absent to read them all.
|
|
132
|
+
* @returns The entities, which can be partial if a limited keys list was provided.
|
|
133
|
+
*/
|
|
134
|
+
query(options?: {
|
|
135
|
+
id?: string;
|
|
136
|
+
idMode?: "id" | "alias" | "both";
|
|
137
|
+
idExact?: boolean;
|
|
138
|
+
resourceTypes?: string[];
|
|
139
|
+
}, conditions?: EntityCondition<IAuditableItemGraphVertex>, orderBy?: keyof Pick<IAuditableItemGraphVertex, "dateCreated" | "dateModified">, orderByDirection?: SortDirection, properties?: (keyof IAuditableItemGraphVertex)[], cursor?: string, limit?: number): Promise<{
|
|
140
|
+
entries: IAuditableItemGraphVertexList;
|
|
141
|
+
cursor?: string;
|
|
142
|
+
}>;
|
|
143
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./auditableItemGraphRestClient.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.20.0-next.1](https://github.com/3sixtyglobal/auditable-item-graph/compare/auditable-item-graph-rest-client-v0.20.0-next.0...auditable-item-graph-rest-client-v0.20.0-next.1) (2026-10-23)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* publish packages under the [@3sixty](https://github.com/3sixty) namespace ([69a615e](https://github.com/3sixtyglobal/auditable-item-graph/commit/69a615ed9a59cc91795d1f8fd65cc778cea7e783))
|
|
9
|
+
* updated ts compile ([5631c11](https://github.com/3sixtyglobal/auditable-item-graph/commit/5631c11fa969a8917e68253c50bf962c10e75814))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Dependencies
|
|
13
|
+
|
|
14
|
+
* The following workspace dependencies were updated
|
|
15
|
+
* dependencies
|
|
16
|
+
* @3sixty/auditable-item-graph-models bumped from 0.20.0-next.0 to 0.20.0-next.1
|
package/docs/examples.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Auditable Item Graph REST Client Examples
|
|
2
|
+
|
|
3
|
+
These snippets show practical request flows for creating, reading, updating, and querying graph items through HTTP endpoints.
|
|
4
|
+
|
|
5
|
+
## AuditableItemGraphRestClient
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { AuditableItemGraphRestClient } from '@3sixty/auditable-item-graph-rest-client';
|
|
9
|
+
|
|
10
|
+
const client = new AuditableItemGraphRestClient({ endpoint: 'http://localhost:8080' });
|
|
11
|
+
|
|
12
|
+
console.log(client.className()); // AuditableItemGraphRestClient
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { VerifyDepth } from '@3sixty/auditable-item-graph-models';
|
|
17
|
+
import { AuditableItemGraphRestClient } from '@3sixty/auditable-item-graph-rest-client';
|
|
18
|
+
|
|
19
|
+
const client = new AuditableItemGraphRestClient({ endpoint: 'http://localhost:8080' });
|
|
20
|
+
|
|
21
|
+
const id = await client.create({
|
|
22
|
+
annotationObject: {
|
|
23
|
+
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
24
|
+
type: 'Create',
|
|
25
|
+
actor: {
|
|
26
|
+
type: 'Person',
|
|
27
|
+
id: 'acct:alex@example.org',
|
|
28
|
+
name: 'Alex'
|
|
29
|
+
},
|
|
30
|
+
object: {
|
|
31
|
+
type: 'Note',
|
|
32
|
+
content: 'Created through the REST client'
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
aliases: [{ id: 'ticket-2026-0007', aliasFormat: 'externalRef', unique: true }],
|
|
36
|
+
resources: [
|
|
37
|
+
{ resourceObject: { '@context': 'https://schema.org', type: 'Thing', name: 'Asset A' } }
|
|
38
|
+
]
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const vertex = await client.get(id, {
|
|
42
|
+
includeDeleted: false,
|
|
43
|
+
verifySignatureDepth: VerifyDepth.Current
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
console.log(id); // aig:018f5a6cfd9444d58c7c2d4df1fd0a23
|
|
47
|
+
console.log(vertex.id); // aig:018f5a6cfd9444d58c7c2d4df1fd0a23
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { VerifyDepth } from '@3sixty/auditable-item-graph-models';
|
|
52
|
+
import { AuditableItemGraphRestClient } from '@3sixty/auditable-item-graph-rest-client';
|
|
53
|
+
|
|
54
|
+
const client = new AuditableItemGraphRestClient({ endpoint: 'http://localhost:8080' });
|
|
55
|
+
|
|
56
|
+
const id = 'aig:018f5a6cfd9444d58c7c2d4df1fd0a23';
|
|
57
|
+
|
|
58
|
+
await client.update({
|
|
59
|
+
id,
|
|
60
|
+
aliases: [{ id: 'ticket-2026-0007', aliasFormat: 'externalRef' }],
|
|
61
|
+
resources: [
|
|
62
|
+
{
|
|
63
|
+
id: 'resource-1',
|
|
64
|
+
resourceObject: { '@context': 'https://schema.org', type: 'Thing', name: 'Asset A v2' }
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
edges: [{ targetId: 'aig:018f5a6cfd9444d58c7c2d4df1fd0999', edgeRelationships: ['dependsOn'] }]
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const changesetChunk = await client.getChangesets(id, undefined, 20, {
|
|
71
|
+
verifySignatureDepth: VerifyDepth.Current
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const firstChangeset = changesetChunk.changesets.itemListElement?.[0];
|
|
75
|
+
|
|
76
|
+
if (firstChangeset?.id) {
|
|
77
|
+
const changeset = await client.getChangeset(firstChangeset.id, {
|
|
78
|
+
verifySignatureDepth: VerifyDepth.Current
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
console.log(changeset.id); // aig:018f5a6cfd9444d58c7c2d4df1fd0a23:changeset:018f5a6cfd9444d58c7c2d4df1fd0b10
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { AuditableItemGraphRestClient } from '@3sixty/auditable-item-graph-rest-client';
|
|
87
|
+
import { ComparisonOperator, SortDirection } from '@3sixty/entity';
|
|
88
|
+
|
|
89
|
+
const client = new AuditableItemGraphRestClient({ endpoint: 'http://localhost:8080' });
|
|
90
|
+
|
|
91
|
+
const result = await client.query(
|
|
92
|
+
{
|
|
93
|
+
id: 'ticket-2026',
|
|
94
|
+
idMode: 'alias',
|
|
95
|
+
idExact: false,
|
|
96
|
+
resourceTypes: ['Thing']
|
|
97
|
+
},
|
|
98
|
+
[
|
|
99
|
+
{
|
|
100
|
+
field: 'dateCreated',
|
|
101
|
+
comparison: ComparisonOperator.GreaterThan,
|
|
102
|
+
value: '2026-01-01T00:00:00.000Z'
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
'dateCreated',
|
|
106
|
+
SortDirection.Descending,
|
|
107
|
+
['id', 'dateCreated', 'aliases'],
|
|
108
|
+
undefined,
|
|
109
|
+
10
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
console.log(result.entries.itemListElement?.length ?? 0); // 2
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
await client.removeVerifiable('aig:018f5a6cfd9444d58c7c2d4df1fd0a23');
|
|
116
|
+
} catch (error) {
|
|
117
|
+
console.log(error instanceof Error ? error.message : 'Unknown error'); // Not supported on client
|
|
118
|
+
}
|
|
119
|
+
```
|