@bardioc/app-sdk 0.5.0 → 1.0.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.
Files changed (47) hide show
  1. package/README.md +86 -253
  2. package/dist/api/graph.d.ts +30 -0
  3. package/dist/api/graph.js +139 -0
  4. package/dist/api/os.d.ts +30 -0
  5. package/dist/api/os.js +48 -0
  6. package/dist/api/relay.d.ts +7 -0
  7. package/dist/api/relay.js +16 -0
  8. package/dist/api/request.d.ts +18 -0
  9. package/dist/api/request.js +12 -0
  10. package/dist/client.d.ts +104 -0
  11. package/dist/client.js +106 -0
  12. package/dist/contract.d.ts +294 -0
  13. package/dist/contract.js +150 -0
  14. package/dist/dev-idb.d.ts +10 -0
  15. package/dist/dev-idb.js +42 -0
  16. package/dist/dev-proxy.js +17 -3
  17. package/dist/dev.d.ts +12 -12
  18. package/dist/dev.js +101 -120
  19. package/dist/errors.d.ts +24 -25
  20. package/dist/errors.js +33 -48
  21. package/dist/index.d.ts +10 -7
  22. package/dist/index.js +2 -4
  23. package/dist/manifest.d.ts +10 -2
  24. package/dist/manifest.js +28 -24
  25. package/dist/protocol.d.ts +6 -29
  26. package/dist/protocol.js +3 -31
  27. package/dist/react.d.ts +21 -27
  28. package/dist/react.js +88 -212
  29. package/dist/serve.d.ts +26 -0
  30. package/dist/serve.js +64 -0
  31. package/dist/testing.d.ts +17 -0
  32. package/dist/testing.js +128 -0
  33. package/dist/types.d.ts +0 -250
  34. package/dist/vite.js +3 -0
  35. package/dist/wire.d.ts +46 -0
  36. package/dist/wire.js +138 -0
  37. package/package.json +12 -4
  38. package/dist/contract-matrix.d.ts +0 -148
  39. package/dist/contract-matrix.js +0 -150
  40. package/dist/host-bridge.d.ts +0 -3
  41. package/dist/host-bridge.js +0 -318
  42. package/dist/transports/backend-transport.d.ts +0 -24
  43. package/dist/transports/backend-transport.js +0 -54
  44. package/dist/transports/graph-transport.d.ts +0 -241
  45. package/dist/transports/graph-transport.js +0 -616
  46. package/dist/transports/os-transport.d.ts +0 -190
  47. package/dist/transports/os-transport.js +0 -444
@@ -1,54 +0,0 @@
1
- import { ValidationError } from '../errors.js';
2
- import { parseOsError } from './os-transport.js';
3
- const RELAY_BASE = '/relay';
4
- // Mirrors the BFF's route key rule: one path segment, "." and ".." excluded.
5
- const ROUTE_KEY_PATTERN = /^[A-Za-z0-9._-]+$/;
6
- export function isRouteKey(routeKey) {
7
- return routeKey !== '.' && routeKey !== '..' && ROUTE_KEY_PATTERN.test(routeKey);
8
- }
9
- /**
10
- * Client for an application's own REST backend, reached through the BFF relay at
11
- * `/relay/{routeKey}`. The host stamps the calling app id and scope; the BFF checks the
12
- * app against the route's whitelist and forwards the request with an app-scoped token.
13
- */
14
- export class BackendTransport {
15
- _request;
16
- routeKey;
17
- constructor(_request, routeKey) {
18
- this._request = _request;
19
- this.routeKey = routeKey;
20
- if (!isRouteKey(routeKey)) {
21
- throw new ValidationError(`Invalid relay route key: "${routeKey}"`, 'routeKey');
22
- }
23
- }
24
- /**
25
- * Send a request to the backend. `path` is what the backend sees, after the relay
26
- * stripped `/relay/{routeKey}`. Scope is required unless stated otherwise: the relay
27
- * refuses an app-scoped call without one.
28
- *
29
- * @throws {EntityNotFoundError} on 404 errors
30
- * @throws {ValidationError} on 400 errors
31
- * @throws {PermissionError} on 403 errors (app not whitelisted for the route)
32
- * @throws {NetworkError} on HTTP errors, including 502 when the backend is unreachable
33
- * @throws {TimeoutError} on request timeout
34
- */
35
- async request(options) {
36
- const path = options.path.startsWith('/') ? options.path : `/${options.path}`;
37
- try {
38
- return await this._request({
39
- path: `${RELAY_BASE}/${this.routeKey}${path}`,
40
- method: options.method || 'GET',
41
- body: options.body,
42
- contentType: options.contentType,
43
- scopeId: options.scopeId,
44
- scopePolicy: options.scopePolicy ?? 'required',
45
- });
46
- }
47
- catch (error) {
48
- throw parseOsError(error, `backend.${this.routeKey}.request`, {
49
- path: options.path,
50
- method: options.method,
51
- });
52
- }
53
- }
54
- }
@@ -1,241 +0,0 @@
1
- import type { BatchResult, CombinedQueryOptions, DeleteOptions, GetNodeOptions, GraphEdgeRaw, GraphNodeRaw, GremlinOptions, HistoryEntry, HistoryOptions, MutationOptions, QueryOptions, SdkTransportPayload, TimeseriesHistory, TimeseriesHistoryOptions, TimeseriesOptions, TimeseriesQueryOptions, TimeseriesValue, TransportScopeOptions } from '../types.js';
2
- /** Graph transport class providing graph database operations */
3
- export declare class GraphTransport {
4
- private _request;
5
- private _debug;
6
- constructor(_request: <T = unknown>(payload: SdkTransportPayload) => Promise<T>, options?: {
7
- debug?: boolean;
8
- });
9
- private log;
10
- private withScope;
11
- /**
12
- * Get single node by ID
13
- * Returns raw backend format (ogit/* fields)
14
- *
15
- * @throws {EntityNotFoundError} if node doesn't exist
16
- * @throws {NetworkError} on HTTP errors
17
- * @throws {TimeoutError} on request timeout
18
- */
19
- get<T = GraphNodeRaw>(id: string, options?: GetNodeOptions): Promise<T>;
20
- /**
21
- * Get multiple nodes by IDs (batched request)
22
- * Uses /query/ids endpoint
23
- *
24
- * @returns Array in same order as input IDs (missing nodes = undefined)
25
- * @throws {ValidationError} if ids array is empty or invalid
26
- * @throws {NetworkError} on HTTP errors
27
- * @throws {TimeoutError} on request timeout
28
- */
29
- getMany<T = GraphNodeRaw>(ids: string[], options?: GetNodeOptions): Promise<(T | undefined)[]>;
30
- /**
31
- * Get node by external ID
32
- *
33
- * @throws {EntityNotFoundError} if XID doesn't exist
34
- * @throws {NetworkError} on HTTP errors
35
- * @throws {TimeoutError} on request timeout
36
- */
37
- getByXid<T = GraphNodeRaw>(xid: string, options?: GetNodeOptions): Promise<T>;
38
- /**
39
- * Query nodes using Lucene syntax
40
- * Returns raw backend format (ogit/* fields)
41
- *
42
- * @example
43
- * const people = await graph.query<GraphNodeRaw>(
44
- * 'ogit/_type:ogit/Person',
45
- * { limit: 50, offset: 0 }
46
- * );
47
- *
48
- * @throws {ValidationError} if query syntax is invalid
49
- * @throws {NetworkError} on HTTP errors
50
- * @throws {TimeoutError} on request timeout
51
- */
52
- query<T = GraphNodeRaw>(lucene: string, options?: QueryOptions): Promise<T[]>;
53
- /**
54
- * Execute Gremlin traversal query
55
- * Returns raw results (structure varies by query)
56
- *
57
- * @example
58
- * const edges = await graph.gremlin(rootId, "outE('ogit/relates')");
59
- *
60
- * @throws {EntityNotFoundError} if root node doesn't exist
61
- * @throws {ValidationError} if query syntax is invalid
62
- * @throws {NetworkError} on HTTP errors
63
- * @throws {TimeoutError} on request timeout
64
- */
65
- gremlin<T = unknown>(rootId: string, query: string, options?: GremlinOptions): Promise<T[]>;
66
- /**
67
- * Execute combined query: Elasticsearch selects the start vertices, the Gremlin traversal
68
- * runs from their IDs. Returns raw results (structure varies by the traversal).
69
- *
70
- * The result is one flat set for all start vertices — it carries no marker for which start
71
- * vertex a row came from. Label and select in the traversal when attribution is needed.
72
- *
73
- * @example
74
- * const speeches = await graph.combined(
75
- * '+(ogit\\/_type: "ogit/Politics/AgendaItem")',
76
- * "inE().outV().has('ogit/_type', 'ogit/Politics/Discussion')",
77
- * { limit: 1000 }
78
- * );
79
- *
80
- * @throws {ValidationError} if either query is invalid
81
- * @throws {NetworkError} on HTTP errors
82
- * @throws {TimeoutError} on request timeout
83
- */
84
- combined<T = unknown>(elasticsearchQuery: string, gremlinQuery: string, options?: CombinedQueryOptions): Promise<T[]>;
85
- /**
86
- * Create new graph node
87
- *
88
- * @param type - OGIT type (e.g., 'ogit/Person')
89
- * @param data - Node attributes (ogit/* format)
90
- * @returns Created node (raw backend format)
91
- *
92
- * @throws {ValidationError} if data is invalid or missing required fields
93
- * @throws {PermissionError} if user lacks permission to create this type
94
- * @throws {NetworkError} on HTTP errors
95
- * @throws {TimeoutError} on request timeout
96
- */
97
- create<T = GraphNodeRaw>(type: string, data: Record<string, unknown>, options?: MutationOptions): Promise<T>;
98
- /**
99
- * Update existing node
100
- *
101
- * @param id - Node ID
102
- * @param data - Fields to update (ogit/* format)
103
- * @returns Updated node (raw backend format)
104
- *
105
- * @throws {EntityNotFoundError} if node doesn't exist
106
- * @throws {ValidationError} if data is invalid
107
- * @throws {PermissionError} if user lacks permission to update this node
108
- * @throws {NetworkError} on HTTP errors
109
- * @throws {TimeoutError} on request timeout
110
- */
111
- update<T = GraphNodeRaw>(id: string, data: Record<string, unknown>, options?: MutationOptions): Promise<T>;
112
- /**
113
- * Delete node (soft delete by default)
114
- *
115
- * @throws {EntityNotFoundError} if node doesn't exist
116
- * @throws {PermissionError} if user lacks permission to delete this node
117
- * @throws {NetworkError} on HTTP errors
118
- * @throws {TimeoutError} on request timeout
119
- */
120
- delete(id: string, options?: DeleteOptions): Promise<void>;
121
- /**
122
- * Create edge between two nodes
123
- *
124
- * @param from - Source node ID
125
- * @param to - Target node ID
126
- * @param type - Edge type (e.g., 'ogit/relates')
127
- * @returns Created edge (raw backend format)
128
- *
129
- * @throws {EntityNotFoundError} if either node doesn't exist
130
- * @throws {ValidationError} if edge type is invalid or not allowed
131
- * @throws {PermissionError} if user lacks permission to create this edge
132
- * @throws {NetworkError} on HTTP errors
133
- * @throws {TimeoutError} on request timeout
134
- */
135
- connect<T = GraphEdgeRaw>(from: string, to: string, type: string, options?: MutationOptions): Promise<T>;
136
- /**
137
- * Get node history
138
- *
139
- * @param nodeId - Node ID
140
- * @param options - Time range, limit, etc.
141
- * @returns Array of historical versions
142
- *
143
- * @throws {EntityNotFoundError} if node doesn't exist
144
- * @throws {NetworkError} on HTTP errors
145
- * @throws {TimeoutError} on request timeout
146
- */
147
- history(nodeId: string, options?: HistoryOptions): Promise<HistoryEntry[]>;
148
- /**
149
- * Batch operations
150
- */
151
- batch: {
152
- /**
153
- * Delete multiple nodes in parallel
154
- * Continues deleting even if some fail
155
- *
156
- * @param ids - Array of node IDs to delete
157
- * @param options - Delete options (hard delete, etc.)
158
- * @returns BatchResult with succeeded and failed IDs
159
- *
160
- * @example
161
- * const result = await graph.batch.delete(['id1', 'id2', 'id3'], { hard: false });
162
- * console.log(`Deleted: ${result.succeeded.length}, Failed: ${result.failed.length}`);
163
- * result.failed.forEach(f => console.error(`Failed ${f.id}: ${f.error}`));
164
- */
165
- delete: (ids: string[], options?: DeleteOptions) => Promise<BatchResult>;
166
- };
167
- /**
168
- * Time series operations
169
- */
170
- timeseries: {
171
- /**
172
- * Get time series values.
173
- *
174
- * `withIds` pulls further time series into the same request and `aggregate` combines the
175
- * values sharing a timestamp. Entries carry only timestamp and value, so a multi-ID request
176
- * yields one merged series — read a single ID per request when values must stay attributable.
177
- *
178
- * @throws {EntityNotFoundError} if time series doesn't exist
179
- * @throws {NetworkError} on HTTP errors
180
- * @throws {TimeoutError} on request timeout
181
- */
182
- get: (id: string, options?: TimeseriesOptions) => Promise<TimeseriesValue[]>;
183
- /**
184
- * Add time series values
185
- *
186
- * @throws {EntityNotFoundError} if time series doesn't exist
187
- * @throws {ValidationError} if values format is invalid
188
- * @throws {NetworkError} on HTTP errors
189
- * @throws {TimeoutError} on request timeout
190
- */
191
- add: (id: string, values: TimeseriesValue[], options?: TransportScopeOptions) => Promise<void>;
192
- /**
193
- * Query time series with filters
194
- *
195
- * @throws {ValidationError} if query options are invalid
196
- * @throws {NetworkError} on HTTP errors
197
- * @throws {TimeoutError} on request timeout
198
- */
199
- query: (options: TimeseriesQueryOptions) => Promise<TimeseriesValue[]>;
200
- /**
201
- * Get every value ever written for one timestamp of a time series.
202
- * Keyed by timestamp, so a single-timestamp request returns a single-entry map.
203
- *
204
- * @throws {EntityNotFoundError} if time series doesn't exist
205
- * @throws {NetworkError} on HTTP errors
206
- * @throws {TimeoutError} on request timeout
207
- */
208
- history: (id: string, timestamp: number, options?: TimeseriesHistoryOptions) => Promise<TimeseriesHistory>;
209
- };
210
- /**
211
- * Content/blob operations
212
- */
213
- content: {
214
- /**
215
- * Upload binary content to a node
216
- *
217
- * @param nodeId - Node ID to attach content to
218
- * @param data - Binary content as Blob
219
- * @param contentType - MIME type (e.g., 'image/png', 'application/pdf')
220
- * @returns Content ID for later retrieval
221
- *
222
- * @throws {EntityNotFoundError} if node doesn't exist
223
- * @throws {ValidationError} if content is invalid
224
- * @throws {NetworkError} on HTTP errors
225
- * @throws {TimeoutError} on request timeout
226
- */
227
- set: (nodeId: string, data: Blob, contentType: string, options?: TransportScopeOptions) => Promise<string>;
228
- /**
229
- * Download binary content from a node
230
- *
231
- * @param nodeId - Node ID
232
- * @param contentId - Content ID returned from set operation
233
- * @returns Binary content as Blob
234
- *
235
- * @throws {EntityNotFoundError} if node or content doesn't exist
236
- * @throws {NetworkError} on HTTP errors
237
- * @throws {TimeoutError} on request timeout
238
- */
239
- get: (nodeId: string, contentId: string, options?: TransportScopeOptions) => Promise<Blob>;
240
- };
241
- }