@ontahi/react 1.0.0-alpha.11 → 1.0.0-alpha.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 +83 -5
- package/dist/actions/fetch-operation-bridge-adapter.d.ts +10 -3
- package/dist/actions/fetch-operation-bridge-adapter.d.ts.map +1 -1
- package/dist/actions/fetch-operation-bridge-adapter.js +74 -28
- package/dist/actions/fetch-operation-bridge-adapter.js.map +1 -1
- package/dist/graph/context.d.ts +1 -1
- package/dist/graph/context.d.ts.map +1 -1
- package/dist/graph/context.js +1 -1
- package/dist/graph/context.js.map +1 -1
- package/dist/graph/executor.d.ts +2 -1
- package/dist/graph/executor.d.ts.map +1 -1
- package/dist/graph/executor.js.map +1 -1
- package/dist/graph/fetch-graph-client.d.ts +19 -4
- package/dist/graph/fetch-graph-client.d.ts.map +1 -1
- package/dist/graph/fetch-graph-client.js +87 -17
- package/dist/graph/fetch-graph-client.js.map +1 -1
- package/dist/graph/fetch-graph-runtime.d.ts +9 -4
- package/dist/graph/fetch-graph-runtime.d.ts.map +1 -1
- package/dist/graph/fetch-graph-runtime.js +31 -6
- package/dist/graph/fetch-graph-runtime.js.map +1 -1
- package/dist/graph/fetch-runtime-transport.d.ts +4 -4
- package/dist/graph/fetch-runtime-transport.d.ts.map +1 -1
- package/dist/graph/fetch-runtime-transport.js +10 -14
- package/dist/graph/fetch-runtime-transport.js.map +1 -1
- package/dist/graph/graph-hooks.d.ts +2 -1
- package/dist/graph/graph-hooks.d.ts.map +1 -1
- package/dist/graph/graph-hooks.js +32 -4
- package/dist/graph/graph-hooks.js.map +1 -1
- package/dist/graph/index.d.ts +2 -0
- package/dist/graph/index.d.ts.map +1 -1
- package/dist/graph/index.js +2 -0
- package/dist/graph/index.js.map +1 -1
- package/dist/graph/operation-hooks.d.ts +4 -2
- package/dist/graph/operation-hooks.d.ts.map +1 -1
- package/dist/graph/operation-hooks.js +4 -2
- package/dist/graph/operation-hooks.js.map +1 -1
- package/dist/graph/operation-types.d.ts +4 -1
- package/dist/graph/operation-types.d.ts.map +1 -1
- package/dist/graph/operation-types.js.map +1 -1
- package/dist/graph/runtime-graph-client.d.ts +12 -0
- package/dist/graph/runtime-graph-client.d.ts.map +1 -0
- package/dist/graph/runtime-graph-client.js +34 -0
- package/dist/graph/runtime-graph-client.js.map +1 -0
- package/dist/graph/websocket-runtime-transport.d.ts +29 -0
- package/dist/graph/websocket-runtime-transport.d.ts.map +1 -0
- package/dist/graph/websocket-runtime-transport.js +491 -0
- package/dist/graph/websocket-runtime-transport.js.map +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -50,9 +50,10 @@ const total = useGraphQuery(openTodos.count());
|
|
|
50
50
|
const first = useGraphQuery(openTodos.first());
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
`OntahiGraphProvider` installs a conventional same-origin Fetch client by default.
|
|
54
|
-
|
|
55
|
-
Runtime
|
|
53
|
+
`OntahiGraphProvider` installs a conventional same-origin Fetch client by default. Operation
|
|
54
|
+
invocation and permission, Graph Read, Graph Command, and Durable Operation inspection all use one
|
|
55
|
+
Runtime Transport at `POST /runtime`. Reflected Explorer data remains outside the registered
|
|
56
|
+
Runtime Protocol families at `/explorer/entities` and `/explorer/related-entities`. These
|
|
56
57
|
capabilities are lazy: declaring the provider does not issue a request until the application uses
|
|
57
58
|
one of them.
|
|
58
59
|
|
|
@@ -61,6 +62,30 @@ configured client with `client={createFetchGraphClient(...)}`, or set `client={f
|
|
|
61
62
|
explicit provider. Server routes, read policies, and authorization remain opt-in and authoritative;
|
|
62
63
|
the default removes client wiring, not the server security boundary.
|
|
63
64
|
|
|
65
|
+
Contextual Selection reads (for example `Book.by(...).parts.chapters.toQuery()`) negotiate Graph
|
|
66
|
+
Read v2 through the same transport before execution, with the same request options/credentials.
|
|
67
|
+
The server must use supporting storage and grant each outgoing `selectionRelations` hop. Discovery
|
|
68
|
+
does not authorize the read or fetch source IDs; missing support fails explicitly without fallback.
|
|
69
|
+
Plain reads remain v1 with no discovery round trip. Contextual observation is not supported yet.
|
|
70
|
+
|
|
71
|
+
Classified reads lower to the canonical base Entity before reaching these providers. Use
|
|
72
|
+
`useGraphQuery(Chapter.all().many())` (or a runtime-bound variant's `.many()`) and the usual scalar
|
|
73
|
+
intents. Base and sibling variant reads have distinct membership keys under the same base-Entity
|
|
74
|
+
prefix, so host-triggered `invalidateQueries({ queryKey: [ContentNode.name] })` refetches all of them.
|
|
75
|
+
`useGraphQuery` does not automatically subscribe to `observe()`.
|
|
76
|
+
|
|
77
|
+
With an observation-capable Runtime Transport, `client.graph.bindVariantSelection(Chapter.all())`
|
|
78
|
+
supports `.exec().observe()`. Complete snapshots recalculate membership, ordering and limits;
|
|
79
|
+
the Runtime Graph client reconciles them through base Entity identity. Leaving a variant is not
|
|
80
|
+
deleting its base record. Removing an Entity from a snapshot does not globally evict it: the host
|
|
81
|
+
still owns confirmed-delete invalidation, cache scoping and lifetime. A simultaneously observed
|
|
82
|
+
base Query can update the shared cached record when its classification changes.
|
|
83
|
+
|
|
84
|
+
Cancelling an observation now aborts its transport signal before waiting for the iterator to close,
|
|
85
|
+
releasing idle subscriptions without affecting other readers. Transports must honor that signal.
|
|
86
|
+
These contracts have an in-process receiver/in-memory provider/React integration proof; they do
|
|
87
|
+
not yet establish a variant mutation lifecycle or live SQL change-feed support.
|
|
88
|
+
|
|
64
89
|
The same client supports fluent execution outside React hooks:
|
|
65
90
|
|
|
66
91
|
```ts
|
|
@@ -87,6 +112,14 @@ logout, service identity, tenant, or workspace changes. An explicit `queryKey` r
|
|
|
87
112
|
for lower-level reads that cannot be encoded by the graph-read protocol, and the legacy explicit
|
|
88
113
|
`mode` API remains compatible.
|
|
89
114
|
|
|
115
|
+
Successful `useGraphQuery` reads and refetches also populate the provider's `clientCache`.
|
|
116
|
+
Selected entity identities, including nested relations described by the View, are reconciled into
|
|
117
|
+
canonical records; the output is stored under the query key. Singular reads retain their singular
|
|
118
|
+
shape, and count/exists outputs remain scalars. Failed reads do not write cache entries. The hook
|
|
119
|
+
continues returning the executor's result through React Query; this does not turn direct executor
|
|
120
|
+
calls or optimistic component state into cache writes. A row disappearing from a filtered result
|
|
121
|
+
does not imply that its canonical entity was deleted.
|
|
122
|
+
|
|
90
123
|
First-class Operation invocations bind render-owned input without losing the declaration form:
|
|
91
124
|
|
|
92
125
|
```ts
|
|
@@ -123,11 +156,56 @@ const client = createFetchGraphClient({
|
|
|
123
156
|
});
|
|
124
157
|
```
|
|
125
158
|
|
|
126
|
-
|
|
127
|
-
|
|
159
|
+
The endpoint, Fetch implementation, credentials, headers, per-call request initialization, abort
|
|
160
|
+
signal, and request-id generator configured there serve every common request/response family.
|
|
161
|
+
For a WebSocket host, compose the same graph client around the push-capable transport:
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
const runtimeTransport = createWebSocketRuntimeTransport({ url: 'wss://app.example/runtime' });
|
|
165
|
+
const client = createRuntimeGraphClient({ runtimeTransport });
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
The transport opens one lazy session, correlates concurrent Runtime Protocol requests, and sends
|
|
169
|
+
one Durable observation control frame per run. Sequenced snapshots are pushed over that socket;
|
|
170
|
+
the browser does not issue repeated `inspect` requests. Aborting the hook sends an unsubscribe and
|
|
171
|
+
releases both sides. A disconnected observation fails and is not silently resumed; a later request
|
|
172
|
+
may open a new connection, but the application or a future resume contract must explicitly
|
|
173
|
+
re-establish observation. `useDurableOperation` itself is unchanged.
|
|
174
|
+
|
|
175
|
+
An application may compose Fetch and WebSocket behind its own `RuntimeTransport` and route each
|
|
176
|
+
request from `request.family`; it can select the Durable observer independently. Operation bridge
|
|
177
|
+
inputs backed by a Graph schema are converted to their portable Selection AST before strict
|
|
178
|
+
Runtime Protocol validation, so the same `useOperation(Entity.domain.operation)` authoring works
|
|
179
|
+
through either transport. The Todo example includes an interactive per-family routing lab.
|
|
180
|
+
|
|
181
|
+
Legacy family routes are opt-in migration surfaces:
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
const client = createFetchGraphClient({
|
|
185
|
+
runtimeTransport: { endpoint: '/runtime' },
|
|
186
|
+
compatibility: {
|
|
187
|
+
operation: { endpoint: '/operations' },
|
|
188
|
+
graphRead: { endpoint: '/graph/reads' },
|
|
189
|
+
graphCommand: { endpoint: '/graph/commands' },
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
An entry in `compatibility` selects that family’s legacy body and endpoint; every unlisted family
|
|
195
|
+
stays on Runtime Transport. It takes precedence over the deprecated `operations.endpoint`,
|
|
196
|
+
`operations.mountPath`, `graphRead.endpoint`, and `graphRead.commandEndpoint` aliases. Selection is
|
|
197
|
+
deterministic before transmission. A common request is never retried against a legacy endpoint
|
|
198
|
+
after a network or server failure, because replaying an Operation or Command could duplicate its
|
|
199
|
+
effect.
|
|
128
200
|
|
|
129
201
|
The Fetch executor sends only canonical graph-read and graph-Command requests. Credentials and
|
|
130
202
|
other trusted request state remain in Fetch initialization and are never embedded in a Query AST or
|
|
131
203
|
Command. The executor supports policy-bounded Relationship Commands and identity-scoped Entity
|
|
132
204
|
Mutation Commands; `useGraphExecutorCapability()` lets optional reflective UI discover whether the
|
|
133
205
|
host installed that execution surface without making it mandatory for read-only hosts.
|
|
206
|
+
|
|
207
|
+
`useOrderedRelationshipCommand` executes `move`/`before`/`after`/`prepend`/`append` commands through
|
|
208
|
+
the same Fetch or WebSocket Runtime Transport. Its result includes an exact `moved` delta, while a
|
|
209
|
+
stale exact-neighborhood precondition follows the command's fail-or-skip policy. Optimistic UI may
|
|
210
|
+
project the requested order temporarily, but the authoritative sequence should be refetched from
|
|
211
|
+
the ordered Relation after completion.
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import type { ReflectedOperationInvoker } from '@ontahi/core/data-graph';
|
|
2
|
+
import { type RuntimeTransport } from '@ontahi/core/runtime/protocol';
|
|
2
3
|
import type * as OperationBridge from './operation-bridge.js';
|
|
3
|
-
export type FetchOperationBridgeOptions = {
|
|
4
|
+
export type FetchOperationBridgeOptions<TTransportOptions = undefined> = {
|
|
5
|
+
/** @deprecated Select the legacy Operation route through createFetchGraphClient compatibility. */
|
|
4
6
|
mountPath?: string;
|
|
7
|
+
/** @deprecated Select the legacy Operation route through createFetchGraphClient compatibility. */
|
|
5
8
|
endpoint?: string;
|
|
9
|
+
fetch?: typeof globalThis.fetch;
|
|
10
|
+
requestInit?: (options?: TTransportOptions) => Omit<RequestInit, 'body' | 'method'>;
|
|
11
|
+
runtimeTransport?: RuntimeTransport<TTransportOptions>;
|
|
12
|
+
requestId?: () => string;
|
|
6
13
|
};
|
|
7
|
-
export declare const createFetchReflectedOperationInvoker: (options?: FetchOperationBridgeOptions) => ReflectedOperationInvoker;
|
|
8
|
-
export declare const createFetchOperationBridgeAdapter: (options?: FetchOperationBridgeOptions) => OperationBridge.AnyOperationBridgeAdapter;
|
|
14
|
+
export declare const createFetchReflectedOperationInvoker: <TTransportOptions = undefined>(options?: FetchOperationBridgeOptions<TTransportOptions>) => ReflectedOperationInvoker;
|
|
15
|
+
export declare const createFetchOperationBridgeAdapter: <TTransportOptions = undefined>(options?: FetchOperationBridgeOptions<TTransportOptions>) => OperationBridge.AnyOperationBridgeAdapter;
|
|
9
16
|
//# sourceMappingURL=fetch-operation-bridge-adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-operation-bridge-adapter.d.ts","sourceRoot":"","sources":["../../src/actions/fetch-operation-bridge-adapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,yBAAyB,EAC1B,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"fetch-operation-bridge-adapter.d.ts","sourceRoot":"","sources":["../../src/actions/fetch-operation-bridge-adapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,yBAAyB,EAC1B,MAAM,yBAAyB,CAAC;AAUjC,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,+BAA+B,CAAC;AAUvC,OAAO,KAAK,KAAK,eAAe,MAAM,uBAAuB,CAAC;AAI9D,MAAM,MAAM,2BAA2B,CAAC,iBAAiB,GAAG,SAAS,IAAI;IACvE,kGAAkG;IAClG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kGAAkG;IAClG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,WAAW,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC;IACpF,gBAAgB,CAAC,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;IACvD,SAAS,CAAC,EAAE,MAAM,MAAM,CAAC;CAC1B,CAAC;AAsJF,eAAO,MAAM,oCAAoC,GAAI,iBAAiB,GAAG,SAAS,EAChF,UAAS,2BAA2B,CAAC,iBAAiB,CAAM,KAC3D,yBAoCF,CAAC;AAEF,eAAO,MAAM,iCAAiC,GAAI,iBAAiB,GAAG,SAAS,EAC7E,UAAS,2BAA2B,CAAC,iBAAiB,CAAM,KAC3D,eAAe,CAAC,yBAyClB,CAAC"}
|
|
@@ -1,36 +1,71 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { resolveOperationExecutionAffordance } from '@ontahi/core/data-graph';
|
|
2
|
+
import { normalizeGraphSchemaClientInput, resolveOperationExecutionAffordance, } from '@ontahi/core/data-graph';
|
|
3
3
|
import { isOperationInvocationProtocolResponse, } from '@ontahi/core/runtime/operation-invocation';
|
|
4
|
+
import { createRuntimeProtocolExchange, toOperationProtocolRequest, } from '@ontahi/core/runtime/protocol';
|
|
4
5
|
import { useMemo } from 'react';
|
|
6
|
+
import { createFetchRuntimeTransport } from '../graph/fetch-runtime-transport.js';
|
|
5
7
|
import { attachOperationBridgeActionRuntime, toOperationInvocationResult, unwrapOperationInvocationValue, } from './operation-bridge.js';
|
|
6
8
|
import { useServerMutation, useServerQuery } from './react-query.js';
|
|
7
|
-
const DEFAULT_ENDPOINT = '/api/data-graph/domain-operations';
|
|
8
9
|
const normalizeMountPath = (value) => {
|
|
9
10
|
const path = value.startsWith('/') ? value : `/${value}`;
|
|
10
|
-
|
|
11
|
+
let end = path.length;
|
|
12
|
+
while (end > 0 && path.charCodeAt(end - 1) === 47)
|
|
13
|
+
end -= 1;
|
|
14
|
+
return path.slice(0, end);
|
|
11
15
|
};
|
|
12
16
|
const mountedEndpoint = (mountPath, endpoint) => `${normalizeMountPath(mountPath)}/${endpoint}`;
|
|
13
17
|
const operationEndpoint = (options) => options.endpoint ??
|
|
14
|
-
(options.mountPath ? mountedEndpoint(options.mountPath, 'operations') :
|
|
18
|
+
(options.mountPath ? mountedEndpoint(options.mountPath, 'operations') : undefined);
|
|
15
19
|
const attachFetchBridgeRuntime = (operation, action) => attachOperationBridgeActionRuntime(operation, action, {
|
|
16
20
|
requiresAuth: operation.authority !== 'server' ? false : operation.exposure !== 'bridge',
|
|
17
21
|
});
|
|
18
|
-
const
|
|
19
|
-
const
|
|
22
|
+
const postLegacyBridgeRequest = async (endpoint, request, fetchRequest, requestInit) => {
|
|
23
|
+
const init = requestInit?.() ?? {};
|
|
24
|
+
const headers = new Headers(init.headers);
|
|
25
|
+
if (!headers.has('content-type'))
|
|
26
|
+
headers.set('content-type', 'application/json');
|
|
27
|
+
const response = await fetchRequest(endpoint, {
|
|
28
|
+
...init,
|
|
20
29
|
method: 'POST',
|
|
21
|
-
headers
|
|
22
|
-
|
|
23
|
-
},
|
|
24
|
-
credentials: 'same-origin',
|
|
30
|
+
headers,
|
|
31
|
+
credentials: init.credentials ?? 'same-origin',
|
|
25
32
|
body: JSON.stringify(request),
|
|
26
33
|
});
|
|
27
34
|
const payload = await response.json().catch(() => null);
|
|
35
|
+
if (!response.ok && !isOperationInvocationProtocolResponse(payload)) {
|
|
36
|
+
throw new Error(`Graph bridge request failed with status ${response.status}.`);
|
|
37
|
+
}
|
|
38
|
+
return payload;
|
|
39
|
+
};
|
|
40
|
+
const createOperationRequest = (options) => {
|
|
41
|
+
const endpoint = operationEndpoint(options);
|
|
42
|
+
if (endpoint) {
|
|
43
|
+
return request => postLegacyBridgeRequest(endpoint, request, options.fetch ?? globalThis.fetch, options.requestInit);
|
|
44
|
+
}
|
|
45
|
+
const exchange = createRuntimeProtocolExchange({
|
|
46
|
+
transport: options.runtimeTransport ??
|
|
47
|
+
createFetchRuntimeTransport({
|
|
48
|
+
...(options.fetch ? { fetch: options.fetch } : {}),
|
|
49
|
+
...(options.requestInit ? { requestInit: options.requestInit } : {}),
|
|
50
|
+
}),
|
|
51
|
+
requestId: options.requestId,
|
|
52
|
+
});
|
|
53
|
+
return request => exchange({
|
|
54
|
+
family: 'operation',
|
|
55
|
+
body: toOperationProtocolRequest(request),
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
const errorMessage = (error) => error instanceof Error ? error.message : 'Graph bridge request failed.';
|
|
59
|
+
const postBridgeRequest = async (requestOperation, request) => {
|
|
60
|
+
let payload;
|
|
61
|
+
try {
|
|
62
|
+
payload = await requestOperation(request);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
return { serverError: errorMessage(error) };
|
|
66
|
+
}
|
|
28
67
|
if (!isOperationInvocationProtocolResponse(payload)) {
|
|
29
|
-
return {
|
|
30
|
-
serverError: response.ok
|
|
31
|
-
? 'Graph bridge returned an invalid response.'
|
|
32
|
-
: `Graph bridge request failed with status ${response.status}.`,
|
|
33
|
-
};
|
|
68
|
+
return { serverError: 'Graph bridge returned an invalid response.' };
|
|
34
69
|
}
|
|
35
70
|
if (payload.kind === 'protocol-error') {
|
|
36
71
|
return { serverError: payload.error.message };
|
|
@@ -43,19 +78,30 @@ const postBridgeRequest = async (endpoint, request) => {
|
|
|
43
78
|
}
|
|
44
79
|
return { serverError: 'Graph bridge returned an invalid response.' };
|
|
45
80
|
};
|
|
46
|
-
const createFetchBridgeAction = (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
81
|
+
const createFetchBridgeAction = (requestOperation, operation) => attachFetchBridgeRuntime(operation, (input) => {
|
|
82
|
+
const portableInput = operation.input
|
|
83
|
+
? normalizeGraphSchemaClientInput(operation.input, input, {
|
|
84
|
+
bindSelection: selection => selection.toAst(),
|
|
85
|
+
})
|
|
86
|
+
: input;
|
|
87
|
+
return postBridgeRequest(requestOperation, {
|
|
88
|
+
kind: 'invoke',
|
|
89
|
+
operationId: operation.id,
|
|
90
|
+
input: portableInput,
|
|
91
|
+
...(operation.view ? { view: operation.view } : {}),
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
const createFetchPermissionAction = (requestOperation, operation) => (input) => postBridgeRequest(requestOperation, {
|
|
53
95
|
kind: 'check-permission',
|
|
54
96
|
operationId: operation.id,
|
|
55
|
-
input
|
|
97
|
+
input: operation.input
|
|
98
|
+
? normalizeGraphSchemaClientInput(operation.input, input, {
|
|
99
|
+
bindSelection: selection => selection.toAst(),
|
|
100
|
+
})
|
|
101
|
+
: input,
|
|
56
102
|
});
|
|
57
103
|
export const createFetchReflectedOperationInvoker = (options = {}) => {
|
|
58
|
-
const
|
|
104
|
+
const requestOperation = createOperationRequest(options);
|
|
59
105
|
const canInvokeOperation = operation => operation.kind === undefined
|
|
60
106
|
? operation.exposure === undefined || operation.exposure === 'bridge'
|
|
61
107
|
: operation.kind !== 'graph' && operation.exposure === 'bridge';
|
|
@@ -71,7 +117,7 @@ export const createFetchReflectedOperationInvoker = (options = {}) => {
|
|
|
71
117
|
}
|
|
72
118
|
: {}),
|
|
73
119
|
}),
|
|
74
|
-
invokeOperation: async ({ input, operationId, view, }) => toOperationInvocationResult(await postBridgeRequest(
|
|
120
|
+
invokeOperation: async ({ input, operationId, view, }) => toOperationInvocationResult(await postBridgeRequest(requestOperation, {
|
|
75
121
|
kind: 'invoke',
|
|
76
122
|
operationId,
|
|
77
123
|
input,
|
|
@@ -80,8 +126,8 @@ export const createFetchReflectedOperationInvoker = (options = {}) => {
|
|
|
80
126
|
};
|
|
81
127
|
};
|
|
82
128
|
export const createFetchOperationBridgeAdapter = (options = {}) => {
|
|
83
|
-
const
|
|
84
|
-
const buildRuntimeAction = (operation) => createFetchBridgeAction(
|
|
129
|
+
const requestOperation = createOperationRequest(options);
|
|
130
|
+
const buildRuntimeAction = (operation) => createFetchBridgeAction(requestOperation, operation);
|
|
85
131
|
return {
|
|
86
132
|
name: 'fetch',
|
|
87
133
|
useBridgeAction: operation => useMemo(() => buildRuntimeAction(operation), [operation]),
|
|
@@ -100,7 +146,7 @@ export const createFetchOperationBridgeAdapter = (options = {}) => {
|
|
|
100
146
|
},
|
|
101
147
|
usePermission: (operation, input, args) => useServerQuery({
|
|
102
148
|
enabled: args?.enabled,
|
|
103
|
-
action: createFetchPermissionAction(
|
|
149
|
+
action: createFetchPermissionAction(requestOperation, operation),
|
|
104
150
|
input,
|
|
105
151
|
key: args?.queryKey ?? ['graph-permission', operation.id, input],
|
|
106
152
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-operation-bridge-adapter.js","sourceRoot":"","sources":["../../src/actions/fetch-operation-bridge-adapter.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAMb,OAAO,EAAE,mCAAmC,EAAE,MAAM,yBAAyB,CAAC;AAE9E,OAAO,EACL,qCAAqC,GAEtC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,EACL,kCAAkC,EAClC,2BAA2B,EAC3B,8BAA8B,GAC/B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAQrE,MAAM,gBAAgB,GAAG,mCAAmC,CAAC;AAE7D,MAAM,kBAAkB,GAAG,CAAC,KAAa,EAAE,EAAE;IAC3C,MAAM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C;SACjE,CAAC;KACL,CAAC;AACJ,CAAC,CAAC","sourcesContent":["'use client';\n\nimport type {\n ReflectedOperationInvocation,\n ReflectedOperationInvoker,\n} from '@ontahi/core/data-graph';\nimport { resolveOperationExecutionAffordance } from '@ontahi/core/data-graph';\nimport type { OperationInvocationResult } from '@ontahi/core/runtime/contracts';\nimport {\n isOperationInvocationProtocolResponse,\n type OperationInvocationRequest,\n} from '@ontahi/core/runtime/operation-invocation';\nimport { useMemo } from 'react';\n\nimport {\n attachOperationBridgeActionRuntime,\n toOperationInvocationResult,\n unwrapOperationInvocationValue,\n} from './operation-bridge.js';\nimport type * as OperationBridge from './operation-bridge.js';\nimport { useServerMutation, useServerQuery } from './react-query.js';\nimport type { ActionResultLike } from './use-action.js';\n\nexport type FetchOperationBridgeOptions = {\n mountPath?: string;\n endpoint?: string;\n};\n\nconst DEFAULT_ENDPOINT = '/api/data-graph/domain-operations';\n\nconst normalizeMountPath = (value: string) => {\n const path = value.startsWith('/') ? value : `/${value}`;\n return path === '/' ? '' : path.replace(/\\/+$/, '');\n};\n\nconst mountedEndpoint = (mountPath: string, endpoint: string) =>\n `${normalizeMountPath(mountPath)}/${endpoint}`;\n\nconst operationEndpoint = (options: FetchOperationBridgeOptions) =>\n options.endpoint ??\n (options.mountPath ? mountedEndpoint(options.mountPath, 'operations') : DEFAULT_ENDPOINT);\n\nconst attachFetchBridgeRuntime = <TInput, TData>(\n operation: OperationBridge.BridgedOperationLike<TInput, TData>,\n action: OperationBridge.OperationBridgeAction<TInput, TData>,\n) =>\n attachOperationBridgeActionRuntime(operation, action, {\n requiresAuth: operation.authority !== 'server' ? false : operation.exposure !== 'bridge',\n });\n\nconst postBridgeRequest = async <TData>(\n endpoint: string,\n request: OperationInvocationRequest,\n): Promise<ActionResultLike & { data?: TData }> => {\n const response = await fetch(endpoint, {\n method: 'POST',\n headers: {\n 'content-type': 'application/json',\n },\n credentials: 'same-origin',\n body: JSON.stringify(request),\n });\n const payload: unknown = await response.json().catch(() => null);\n\n if (!isOperationInvocationProtocolResponse(payload)) {\n return {\n serverError: response.ok\n ? 'Graph bridge returned an invalid response.'\n : `Graph bridge request failed with status ${response.status}.`,\n };\n }\n\n if (payload.kind === 'protocol-error') {\n return { serverError: payload.error.message };\n }\n\n if (request.kind === 'invoke' && payload.kind === 'invocation-result') {\n return { data: payload.result as TData };\n }\n\n if (request.kind === 'check-permission' && payload.kind === 'permission-result') {\n return { data: payload.result as TData };\n }\n\n return { serverError: 'Graph bridge returned an invalid response.' };\n};\n\nconst createFetchBridgeAction = <TInput, TData>(\n endpoint: string,\n operation: OperationBridge.BridgedOperationLike<TInput, TData>,\n): OperationBridge.OperationBridgeAction<TInput, TData> =>\n attachFetchBridgeRuntime(operation, (input: TInput) =>\n postBridgeRequest<OperationInvocationResult<TData>>(endpoint, {\n kind: 'invoke',\n operationId: operation.id,\n input,\n ...(operation.view ? { view: operation.view } : {}),\n }),\n ) as OperationBridge.OperationBridgeAction<TInput, TData>;\n\nconst createFetchPermissionAction =\n <TInput, TData>(\n endpoint: string,\n operation: OperationBridge.BridgedOperationLike<TInput, TData>,\n ): ((\n input: TInput,\n ) => Promise<OperationBridge.OperationBridgeActionResult<OperationBridge.GraphPermission>>) =>\n (input: TInput) =>\n postBridgeRequest<OperationBridge.GraphPermission>(endpoint, {\n kind: 'check-permission',\n operationId: operation.id,\n input,\n });\n\nexport const createFetchReflectedOperationInvoker = (\n options: FetchOperationBridgeOptions = {},\n): ReflectedOperationInvoker => {\n const endpoint = operationEndpoint(options);\n const canInvokeOperation: NonNullable<\n ReflectedOperationInvoker['canInvokeOperation']\n > = operation =>\n operation.kind === undefined\n ? operation.exposure === undefined || operation.exposure === 'bridge'\n : operation.kind !== 'graph' && operation.exposure === 'bridge';\n\n return {\n canInvokeOperation,\n getOperationExecutionAffordance: operation =>\n resolveOperationExecutionAffordance(operation, {\n ...(canInvokeOperation(operation)\n ? {\n bridge: {\n authority: operation.authority ?? 'server',\n bridge: 'fetch',\n },\n }\n : {}),\n }),\n invokeOperation: async <TInput = unknown, TData = unknown>({\n input,\n operationId,\n view,\n }: ReflectedOperationInvocation<TInput>) =>\n toOperationInvocationResult<TData>(\n await postBridgeRequest<OperationInvocationResult<TData>>(endpoint, {\n kind: 'invoke',\n operationId,\n input,\n ...(view ? { view } : {}),\n }),\n ),\n };\n};\n\nexport const createFetchOperationBridgeAdapter = (\n options: FetchOperationBridgeOptions = {},\n): OperationBridge.AnyOperationBridgeAdapter => {\n const endpoint = operationEndpoint(options);\n const buildRuntimeAction = <TInput, TData>(\n operation: OperationBridge.BridgedOperationLike<TInput, TData>,\n ) => createFetchBridgeAction(endpoint, operation);\n\n return {\n name: 'fetch',\n useBridgeAction: operation =>\n useMemo(\n () => buildRuntimeAction(operation) as OperationBridge.OperationBridgeAction<any, any>,\n [operation],\n ) as OperationBridge.OperationBridgeAction<any, any>,\n useBridgeMutation: (operation, options) => {\n const action = useMemo(() => buildRuntimeAction(operation), [operation]);\n\n return useServerMutation(\n action as OperationBridge.OperationBridgeAction<unknown, unknown>,\n options as Parameters<\n typeof useServerMutation<OperationBridge.OperationBridgeAction<unknown, unknown>>\n >[1],\n ) as ReturnType<typeof useServerMutation<OperationBridge.OperationBridgeAction<any, any>>>;\n },\n useBridgeQuery: (operation, args) => {\n const action = useMemo(() => buildRuntimeAction(operation), [operation]);\n\n return useServerQuery({\n action: action as OperationBridge.OperationBridgeAction<unknown, unknown>,\n input: args.input as unknown,\n key: args.key,\n select: unwrapOperationInvocationValue,\n }) as any;\n },\n usePermission: (operation, input, args) =>\n useServerQuery({\n enabled: args?.enabled,\n action: createFetchPermissionAction(endpoint, operation),\n input,\n key: args?.queryKey ?? ['graph-permission', operation.id, input],\n }),\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"fetch-operation-bridge-adapter.js","sourceRoot":"","sources":["../../src/actions/fetch-operation-bridge-adapter.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAMb,OAAO,EACL,+BAA+B,EAC/B,mCAA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ACZ,CAAC;QACD,aAAa,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CACxC,cAAc,CAAC;YACb,OAAO,EAAE,IAAI,EAAE,OAAO;YACtB,MAAM,EAAE,2BAA2B,CAAC,gBAAgB,EAAE,SAAS,CAAC;YAChE,KAAK;YACL,GAAG,EAAE,IAAI,EAAE,QAAQ,IAAI,CAAC,kBAAkB,EAAE,SAAS,CAAC,EAAE,EAAE,KAAK,CAAC;SACjE,CAAC;KACL,CAAC;AACJ,CAAC,CAAC","sourcesContent":["'use client';\n\nimport type {\n ReflectedOperationInvocation,\n ReflectedOperationInvoker,\n} from '@ontahi/core/data-graph';\nimport {\n normalizeGraphSchemaClientInput,\n resolveOperationExecutionAffordance,\n} from '@ontahi/core/data-graph';\nimport type { OperationInvocationResult } from '@ontahi/core/runtime/contracts';\nimport {\n isOperationInvocationProtocolResponse,\n type OperationInvocationRequest,\n} from '@ontahi/core/runtime/operation-invocation';\nimport {\n createRuntimeProtocolExchange,\n toOperationProtocolRequest,\n type RuntimeTransport,\n} from '@ontahi/core/runtime/protocol';\nimport { useMemo } from 'react';\n\nimport { createFetchRuntimeTransport } from '../graph/fetch-runtime-transport.js';\n\nimport {\n attachOperationBridgeActionRuntime,\n toOperationInvocationResult,\n unwrapOperationInvocationValue,\n} from './operation-bridge.js';\nimport type * as OperationBridge from './operation-bridge.js';\nimport { useServerMutation, useServerQuery } from './react-query.js';\nimport type { ActionResultLike } from './use-action.js';\n\nexport type FetchOperationBridgeOptions<TTransportOptions = undefined> = {\n /** @deprecated Select the legacy Operation route through createFetchGraphClient compatibility. */\n mountPath?: string;\n /** @deprecated Select the legacy Operation route through createFetchGraphClient compatibility. */\n endpoint?: string;\n fetch?: typeof globalThis.fetch;\n requestInit?: (options?: TTransportOptions) => Omit<RequestInit, 'body' | 'method'>;\n runtimeTransport?: RuntimeTransport<TTransportOptions>;\n requestId?: () => string;\n};\n\nconst normalizeMountPath = (value: string) => {\n const path = value.startsWith('/') ? value : `/${value}`;\n let end = path.length;\n while (end > 0 && path.charCodeAt(end - 1) === 47) end -= 1;\n return path.slice(0, end);\n};\n\nconst mountedEndpoint = (mountPath: string, endpoint: string) =>\n `${normalizeMountPath(mountPath)}/${endpoint}`;\n\nconst operationEndpoint = <TTransportOptions>(\n options: FetchOperationBridgeOptions<TTransportOptions>,\n) =>\n options.endpoint ??\n (options.mountPath ? mountedEndpoint(options.mountPath, 'operations') : undefined);\n\nconst attachFetchBridgeRuntime = <TInput, TData>(\n operation: OperationBridge.BridgedOperationLike<TInput, TData>,\n action: OperationBridge.OperationBridgeAction<TInput, TData>,\n) =>\n attachOperationBridgeActionRuntime(operation, action, {\n requiresAuth: operation.authority !== 'server' ? false : operation.exposure !== 'bridge',\n });\n\ntype OperationRequest = (request: OperationInvocationRequest) => Promise<unknown>;\n\nconst postLegacyBridgeRequest = async <TTransportOptions>(\n endpoint: string,\n request: OperationInvocationRequest,\n fetchRequest: typeof globalThis.fetch,\n requestInit: ((options?: TTransportOptions) => Omit<RequestInit, 'body' | 'method'>) | undefined,\n): Promise<unknown> => {\n const init = requestInit?.() ?? {};\n const headers = new Headers(init.headers);\n if (!headers.has('content-type')) headers.set('content-type', 'application/json');\n const response = await fetchRequest(endpoint, {\n ...init,\n method: 'POST',\n headers,\n credentials: init.credentials ?? 'same-origin',\n body: JSON.stringify(request),\n });\n const payload: unknown = await response.json().catch(() => null);\n if (!response.ok && !isOperationInvocationProtocolResponse(payload)) {\n throw new Error(`Graph bridge request failed with status ${response.status}.`);\n }\n return payload;\n};\n\nconst createOperationRequest = <TTransportOptions>(\n options: FetchOperationBridgeOptions<TTransportOptions>,\n): OperationRequest => {\n const endpoint = operationEndpoint(options);\n if (endpoint) {\n return request =>\n postLegacyBridgeRequest(\n endpoint,\n request,\n options.fetch ?? globalThis.fetch,\n options.requestInit,\n );\n }\n\n const exchange = createRuntimeProtocolExchange({\n transport:\n options.runtimeTransport ??\n createFetchRuntimeTransport<TTransportOptions>({\n ...(options.fetch ? { fetch: options.fetch } : {}),\n ...(options.requestInit ? { requestInit: options.requestInit } : {}),\n }),\n requestId: options.requestId,\n });\n return request =>\n exchange({\n family: 'operation',\n body: toOperationProtocolRequest(request),\n });\n};\n\nconst errorMessage = (error: unknown) =>\n error instanceof Error ? error.message : 'Graph bridge request failed.';\n\nconst postBridgeRequest = async <TData>(\n requestOperation: OperationRequest,\n request: OperationInvocationRequest,\n): Promise<ActionResultLike & { data?: TData }> => {\n let payload: unknown;\n try {\n payload = await requestOperation(request);\n } catch (error) {\n return { serverError: errorMessage(error) };\n }\n\n if (!isOperationInvocationProtocolResponse(payload)) {\n return { serverError: 'Graph bridge returned an invalid response.' };\n }\n\n if (payload.kind === 'protocol-error') {\n return { serverError: payload.error.message };\n }\n\n if (request.kind === 'invoke' && payload.kind === 'invocation-result') {\n return { data: payload.result as TData };\n }\n\n if (request.kind === 'check-permission' && payload.kind === 'permission-result') {\n return { data: payload.result as TData };\n }\n\n return { serverError: 'Graph bridge returned an invalid response.' };\n};\n\nconst createFetchBridgeAction = <TInput, TData>(\n requestOperation: OperationRequest,\n operation: OperationBridge.BridgedOperationLike<TInput, TData>,\n): OperationBridge.OperationBridgeAction<TInput, TData> =>\n attachFetchBridgeRuntime(operation, (input: TInput) => {\n const portableInput = operation.input\n ? normalizeGraphSchemaClientInput(operation.input, input, {\n bindSelection: selection => selection.toAst(),\n })\n : input;\n return postBridgeRequest<OperationInvocationResult<TData>>(requestOperation, {\n kind: 'invoke',\n operationId: operation.id,\n input: portableInput,\n ...(operation.view ? { view: operation.view } : {}),\n });\n }) as OperationBridge.OperationBridgeAction<TInput, TData>;\n\nconst createFetchPermissionAction =\n <TInput, TData>(\n requestOperation: OperationRequest,\n operation: OperationBridge.BridgedOperationLike<TInput, TData>,\n ): ((\n input: TInput,\n ) => Promise<OperationBridge.OperationBridgeActionResult<OperationBridge.GraphPermission>>) =>\n (input: TInput) =>\n postBridgeRequest<OperationBridge.GraphPermission>(requestOperation, {\n kind: 'check-permission',\n operationId: operation.id,\n input: operation.input\n ? normalizeGraphSchemaClientInput(operation.input, input, {\n bindSelection: selection => selection.toAst(),\n })\n : input,\n });\n\nexport const createFetchReflectedOperationInvoker = <TTransportOptions = undefined>(\n options: FetchOperationBridgeOptions<TTransportOptions> = {},\n): ReflectedOperationInvoker => {\n const requestOperation = createOperationRequest(options);\n const canInvokeOperation: NonNullable<\n ReflectedOperationInvoker['canInvokeOperation']\n > = operation =>\n operation.kind === undefined\n ? operation.exposure === undefined || operation.exposure === 'bridge'\n : operation.kind !== 'graph' && operation.exposure === 'bridge';\n\n return {\n canInvokeOperation,\n getOperationExecutionAffordance: operation =>\n resolveOperationExecutionAffordance(operation, {\n ...(canInvokeOperation(operation)\n ? {\n bridge: {\n authority: operation.authority ?? 'server',\n bridge: 'fetch',\n },\n }\n : {}),\n }),\n invokeOperation: async <TInput = unknown, TData = unknown>({\n input,\n operationId,\n view,\n }: ReflectedOperationInvocation<TInput>) =>\n toOperationInvocationResult<TData>(\n await postBridgeRequest<OperationInvocationResult<TData>>(requestOperation, {\n kind: 'invoke',\n operationId,\n input,\n ...(view ? { view } : {}),\n }),\n ),\n };\n};\n\nexport const createFetchOperationBridgeAdapter = <TTransportOptions = undefined>(\n options: FetchOperationBridgeOptions<TTransportOptions> = {},\n): OperationBridge.AnyOperationBridgeAdapter => {\n const requestOperation = createOperationRequest(options);\n const buildRuntimeAction = <TInput, TData>(\n operation: OperationBridge.BridgedOperationLike<TInput, TData>,\n ) => createFetchBridgeAction(requestOperation, operation);\n\n return {\n name: 'fetch',\n useBridgeAction: operation =>\n useMemo(\n () => buildRuntimeAction(operation) as OperationBridge.OperationBridgeAction<any, any>,\n [operation],\n ) as OperationBridge.OperationBridgeAction<any, any>,\n useBridgeMutation: (operation, options) => {\n const action = useMemo(() => buildRuntimeAction(operation), [operation]);\n\n return useServerMutation(\n action as OperationBridge.OperationBridgeAction<unknown, unknown>,\n options as Parameters<\n typeof useServerMutation<OperationBridge.OperationBridgeAction<unknown, unknown>>\n >[1],\n ) as ReturnType<typeof useServerMutation<OperationBridge.OperationBridgeAction<any, any>>>;\n },\n useBridgeQuery: (operation, args) => {\n const action = useMemo(() => buildRuntimeAction(operation), [operation]);\n\n return useServerQuery({\n action: action as OperationBridge.OperationBridgeAction<unknown, unknown>,\n input: args.input as unknown,\n key: args.key,\n select: unwrapOperationInvocationValue,\n }) as any;\n },\n usePermission: (operation, input, args) =>\n useServerQuery({\n enabled: args?.enabled,\n action: createFetchPermissionAction(requestOperation, operation),\n input,\n key: args?.queryKey ?? ['graph-permission', operation.id, input],\n }),\n };\n};\n"]}
|
package/dist/graph/context.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export declare function useGraphClientCache(): {
|
|
|
40
40
|
resolveEntityRef: <TRef extends import("@ontahi/core/data-graph").AnyEntityRef>(ref: TRef) => import("@ontahi/core/data-graph").AnyEntityRef | TRef;
|
|
41
41
|
subscribe: (listener: import("@ontahi/core/data-graph").GraphClientCacheListener) => (() => void);
|
|
42
42
|
writeEntity: <TEntity extends import("@ontahi/core/data-graph").AnyEntityDefinition, TSnapshot extends Record<string, unknown>>(entityDefinition: TEntity, snapshot: TSnapshot) => import("@ontahi/core/data-graph").GraphClientCacheWriteResult<TSnapshot> | undefined;
|
|
43
|
-
writeOutput: (key: readonly unknown[], descriptor: import("@ontahi/core/data-graph").GraphOutputDescriptor | undefined, value: unknown) => import("@ontahi/core/data-graph").GraphClientCacheOutputNormalizationResult;
|
|
43
|
+
writeOutput: (key: readonly unknown[], descriptor: import("@ontahi/core/data-graph").GraphOutputDescriptor | undefined, value: unknown, source?: import("@ontahi/core/data-graph").GraphClientCacheOutputSource) => import("@ontahi/core/data-graph").GraphClientCacheOutputNormalizationResult;
|
|
44
44
|
};
|
|
45
45
|
export declare function useGraphClientCacheSnapshot(): import("@ontahi/core/data-graph").GraphClientCacheSnapshot;
|
|
46
46
|
export declare const useGraphClientCacheVersion: (clientCache: GraphClientCache) => number;
|
|
@@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GACtC,EAAE,wBAAwB,CAAC,aAAa,EAAE,YAAY,EAAE,eAAe,CAAC,2CAwDxE;AAED,eAAO,MAAM,oBAAoB,yBAA6C,CAAC;AAE/E,wBAAgB,eAAe,CAAC,aAAa,GAAG,OAAO,KAOnC,aAAa,CAChC;AAED,wBAAgB,gBAAgB,CAAC,YAAY,GAAG,OAAO,EAAE,eAAe,GAAG,YAAY,KAS7D,kBAAkB,CAAC,YAAY,EAAE,eAAe,CAAC,CAC1E;AAED,wBAAgB,0BAA0B,CACxC,YAAY,GAAG,OAAO,EACtB,eAAe,GAAG,YAAY,KAG1B,kBAAkB,CAAC,YAAY,EAAE,eAAe,CAAC,GACjD,SAAS,CACd;AAED,eAAO,MAAM,6BAA6B,oCAAyD,CAAC;AAEpG,wBAAgB,mBAAmB,qBAMlC;AAED,wBAAgB,mBAAmB;;;;;;;;;;;;;kJApFJ,CAAC;EA4F/B;AAED,wBAAgB,2BAA2B,+DAM1C;AAED,eAAO,MAAM,0BAA0B,GAAI,aAAa,gBAAgB,WAKrE,CAAC;AAEJ,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,MAAM,6BAc5D;AAED,wBAAgB,gCAAgC,8BAc/C;AAED,wBAAgB,4BAA4B,YAG3C;AAED,wBAAgB,4BAA4B,8BAU3C;AAED,wBAAgB,+BAA+B,YAE9C;AAED,wBAAgB,mCAAmC,qCAUlD;AAED,eAAO,MAAM,sCAAsC,eACW,CAAC;AAE/D,wBAAgB,4BAA4B,8BAU3C;AAED,wBAAgB,+BAA+B,YAE9C;AAED,wBAAgB,4BAA4B,gBAI5B,4BAA4B,aAI3C;AAED,wBAAgB,wCAAwC,CACtD,SAAS,EAAE,4BAA4B,GACtC,4BAA4B,GAAG,SAAS,CAI1C;AAED,YAAY,EAAE,gBAAgB,EAAE,CAAC"}
|
package/dist/graph/context.js
CHANGED
|
@@ -25,7 +25,7 @@ export function OntahiGraphProvider({ children, runtime, graphExecutor, runtimeT
|
|
|
25
25
|
const resolvedReflectedEntityDataReader = reflectedEntityDataReader ?? graphClient?.reflectedEntityDataReader;
|
|
26
26
|
const resolvedReflectedRelatedEntityDataReader = reflectedRelatedEntityDataReader ?? graphClient?.reflectedRelatedEntityDataReader;
|
|
27
27
|
const configuredReflectedOperationInvoker = reflectedOperationInvoker ?? graphClient?.reflectedOperationInvoker;
|
|
28
|
-
const graphClientCache = clientCache ?? defaultClientCache;
|
|
28
|
+
const graphClientCache = clientCache ?? graphClient?.clientCache ?? defaultClientCache;
|
|
29
29
|
const bridgeAdapterMap = useMemo(() => new Map(resolvedOperationBridgeAdapters.map(adapter => [adapter.name, adapter])), [resolvedOperationBridgeAdapters]);
|
|
30
30
|
const resolvedReflectedOperationInvoker = useMemo(() => reflectedGraphOperations.length > 0
|
|
31
31
|
? createReflectedOperationInvoker({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/graph/context.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EACL,sBAAsB,GAOvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,0BAA0B,EAA0B,MAAM,+BAA+B,CAAC;AAEnG,OAAO,EACL,aAAa,EACb,WAAW,EACX,UAAU,EACV,OAAO,EACP,QAAQ,EACR,oBAAoB,GAErB,MAAM,OAAO,CAAC;AAKf,OAAO,EAAE,sBAAsB,EAA0B,MAAM,yBAAyB,CAAC;AACzF,OAAO,EACL,+BAA+B,GAEhC,MAAM,kCAAkC,CAAC;AAE1C,MAAM,0BAA0B,GAA2C,EAAE,CAAC;AAE9E,MAAM,mBAAmB,GAAG,aAAa,CAAiB,IAAI,CAAC,CAAC;AAChE,MAAM,wBAAwB,GAAG,aAAa,CAAoB,0BAA0B,CAAC,CAAC;AAC9F,MAAM,oBAAoB,GAAG,aAAa,CAAsC,IAAI,CAAC,CAAC;AACtF,MAAM,uBAAuB,GAAG,aAAa,CAA0B,IAAI,CAAC,CAAC;AAC7E,MAAM,uBAAuB,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EAAE,CAC1C,OAAO,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,CAAC,EACvE,CAAC,OAAO,CAAC,CACV,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,wCAAwC,CACtD,SAAuC;IAEvC,MAAM,OAAO,GAAG,UAAU,CAAC,gCAAgC,CAAC,CAAC;IAE7D,OAAO,OAAO,EAAE,+BAA+B,EAAE,CAAC,SAAS,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["'use client';\n\nimport {\n createGraphClientCache,\n type GraphClientCache,\n type OperationExecutionAffordance,\n type ReflectedEntityDataReader,\n type ReflectedRelatedEntityDataReader,\n type ReflectedOperationDescriptor,\n type ReflectedOperationInvoker,\n} from '@ontahi/core/data-graph';\nimport { anonymousExecutionIdentity, type ExecutionIdentity } from '@ontahi/core/runtime/identity';\nimport type { RuntimeTransport } from '@ontahi/core/runtime/protocol';\nimport {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useState,\n useSyncExternalStore,\n type ReactNode,\n} from 'react';\n\nimport type { AnyOperationBridgeAdapter } from '../actions/index.js';\n\nimport type { ReactGraphExecutor } from './executor.js';\nimport { createFetchGraphClient, type OntahiGraphClient } from './fetch-graph-client.js';\nimport {\n createReflectedOperationInvoker,\n type ReflectedGraphOperationLike,\n} from './reflected-operation-invoker.js';\n\nconst noReflectedGraphOperations: readonly ReflectedGraphOperationLike[] = [];\n\nconst GraphRuntimeContext = createContext<unknown | null>(null);\nconst ExecutionIdentityContext = createContext<ExecutionIdentity>(anonymousExecutionIdentity);\nconst GraphExecutorContext = createContext<ReactGraphExecutor<any, any> | null>(null);\nconst GraphClientCacheContext = createContext<GraphClientCache | null>(null);\nconst RuntimeTransportContext = createContext<RuntimeTransport | null>(null);\nconst OperationBridgeAdaptersContext = createContext<Map<string, AnyOperationBridgeAdapter> | null>(\n null,\n);\nconst ReflectedEntityDataReaderContext = createContext<ReflectedEntityDataReader | null>(null);\nconst ReflectedRelatedEntityDataReaderContext =\n createContext<ReflectedRelatedEntityDataReader | null>(null);\nconst ReflectedOperationInvokerContext = createContext<ReflectedOperationInvoker | null>(null);\n\nexport type OntahiGraphProviderProps<\n TGraphRuntime = unknown,\n TReadOptions = unknown,\n TCommandOptions = TReadOptions,\n> = {\n children: ReactNode;\n runtime: TGraphRuntime;\n graphExecutor?: ReactGraphExecutor<TReadOptions, TCommandOptions>;\n runtimeTransport?: RuntimeTransport;\n client?: OntahiGraphClient<TReadOptions, TCommandOptions> | false;\n operationBridgeAdapters?: AnyOperationBridgeAdapter[];\n reflectedEntityDataReader?: ReflectedEntityDataReader;\n reflectedRelatedEntityDataReader?: ReflectedRelatedEntityDataReader;\n reflectedOperationInvoker?: ReflectedOperationInvoker;\n reflectedGraphOperations?: readonly ReflectedGraphOperationLike[];\n clientCache?: GraphClientCache;\n identity?: ExecutionIdentity;\n};\n\nexport function OntahiGraphProvider<\n TGraphRuntime = unknown,\n TReadOptions = unknown,\n TCommandOptions = TReadOptions,\n>({\n children,\n runtime,\n graphExecutor,\n runtimeTransport,\n client,\n operationBridgeAdapters,\n reflectedEntityDataReader,\n reflectedRelatedEntityDataReader,\n reflectedOperationInvoker,\n reflectedGraphOperations = noReflectedGraphOperations,\n clientCache,\n identity = anonymousExecutionIdentity,\n}: OntahiGraphProviderProps<TGraphRuntime, TReadOptions, TCommandOptions>) {\n const [defaultGraphClient] = useState(() => createFetchGraphClient());\n const [defaultClientCache] = useState(() => createGraphClientCache());\n const graphClient = client === false ? undefined : (client ?? defaultGraphClient);\n const resolvedGraphExecutor = graphExecutor ?? graphClient?.graphExecutor;\n const resolvedRuntimeTransport = runtimeTransport ?? graphClient?.runtimeTransport;\n const resolvedOperationBridgeAdapters =\n operationBridgeAdapters ?? graphClient?.operationBridgeAdapters ?? [];\n const resolvedReflectedEntityDataReader =\n reflectedEntityDataReader ?? graphClient?.reflectedEntityDataReader;\n const resolvedReflectedRelatedEntityDataReader =\n reflectedRelatedEntityDataReader ?? graphClient?.reflectedRelatedEntityDataReader;\n const configuredReflectedOperationInvoker =\n reflectedOperationInvoker ?? graphClient?.reflectedOperationInvoker;\n const graphClientCache = clientCache ?? defaultClientCache;\n const bridgeAdapterMap = useMemo(\n () => new Map(resolvedOperationBridgeAdapters.map(adapter => [adapter.name, adapter])),\n [resolvedOperationBridgeAdapters],\n );\n const resolvedReflectedOperationInvoker = useMemo(\n () =>\n reflectedGraphOperations.length > 0\n ? createReflectedOperationInvoker({\n fallback: configuredReflectedOperationInvoker,\n graphExecutor: resolvedGraphExecutor,\n graphOperations: reflectedGraphOperations,\n })\n : (configuredReflectedOperationInvoker ?? null),\n [configuredReflectedOperationInvoker, reflectedGraphOperations, resolvedGraphExecutor],\n );\n\n return (\n <ExecutionIdentityContext.Provider value={identity}>\n <ReflectedOperationInvokerContext.Provider value={resolvedReflectedOperationInvoker}>\n <ReflectedRelatedEntityDataReaderContext.Provider\n value={resolvedReflectedRelatedEntityDataReader ?? null}\n >\n <ReflectedEntityDataReaderContext.Provider\n value={resolvedReflectedEntityDataReader ?? null}\n >\n <OperationBridgeAdaptersContext.Provider value={bridgeAdapterMap}>\n <RuntimeTransportContext.Provider value={resolvedRuntimeTransport ?? null}>\n <GraphClientCacheContext.Provider value={graphClientCache}>\n <GraphExecutorContext.Provider value={resolvedGraphExecutor ?? null}>\n <GraphRuntimeContext.Provider value={runtime}>\n {children}\n </GraphRuntimeContext.Provider>\n </GraphExecutorContext.Provider>\n </GraphClientCacheContext.Provider>\n </RuntimeTransportContext.Provider>\n </OperationBridgeAdaptersContext.Provider>\n </ReflectedEntityDataReaderContext.Provider>\n </ReflectedRelatedEntityDataReaderContext.Provider>\n </ReflectedOperationInvokerContext.Provider>\n </ExecutionIdentityContext.Provider>\n );\n}\n\nexport const useExecutionIdentity = () => useContext(ExecutionIdentityContext);\n\nexport function useGraphRuntime<TGraphRuntime = unknown>() {\n const runtime = useContext(GraphRuntimeContext);\n\n if (runtime === null) {\n throw new Error('useGraphRuntime must be used within an OntahiGraphProvider');\n }\n\n return runtime as TGraphRuntime;\n}\n\nexport function useGraphExecutor<TReadOptions = unknown, TCommandOptions = TReadOptions>() {\n const graphExecutor = useContext(GraphExecutorContext);\n\n if (graphExecutor === null) {\n throw new Error(\n 'useGraphExecutor must be used within an OntahiGraphProvider with graphExecutor',\n );\n }\n\n return graphExecutor as ReactGraphExecutor<TReadOptions, TCommandOptions>;\n}\n\nexport function useGraphExecutorCapability<\n TReadOptions = unknown,\n TCommandOptions = TReadOptions,\n>() {\n return (useContext(GraphExecutorContext) ?? undefined) as\n | ReactGraphExecutor<TReadOptions, TCommandOptions>\n | undefined;\n}\n\nexport const useRuntimeTransportCapability = () => useContext(RuntimeTransportContext) ?? undefined;\n\nexport function useRuntimeTransport() {\n const transport = useRuntimeTransportCapability();\n if (!transport) {\n throw new Error('useRuntimeTransport requires an OntahiGraphProvider with runtimeTransport');\n }\n return transport;\n}\n\nexport function useGraphClientCache() {\n const clientCache = useContext(GraphClientCacheContext);\n\n if (clientCache === null) {\n throw new Error('useGraphClientCache must be used within an OntahiGraphProvider');\n }\n\n return clientCache;\n}\n\nexport function useGraphClientCacheSnapshot() {\n const clientCache = useGraphClientCache();\n\n useGraphClientCacheVersion(clientCache);\n\n return clientCache.inspect();\n}\n\nexport const useGraphClientCacheVersion = (clientCache: GraphClientCache) =>\n useSyncExternalStore(\n clientCache.subscribe,\n () => clientCache.inspect().version,\n () => clientCache.inspect().version,\n );\n\nexport function useOperationBridgeAdapter(adapterName: string) {\n const adapters = useContext(OperationBridgeAdaptersContext);\n\n if (adapters === null) {\n throw new Error('useOperationBridgeAdapter must be used within an OntahiGraphProvider');\n }\n\n const adapter = adapters.get(adapterName);\n\n if (!adapter) {\n throw new Error(`No operation bridge adapter registered for \"${adapterName}\"`);\n }\n\n return adapter;\n}\n\nexport function useDefaultOperationBridgeAdapter() {\n const adapters = useContext(OperationBridgeAdaptersContext);\n\n if (adapters === null) {\n throw new Error('useDefaultOperationBridgeAdapter must be used within an OntahiGraphProvider');\n }\n\n const [adapter] = adapters.values();\n\n if (!adapter) {\n throw new Error('No operation bridge adapter registered.');\n }\n\n return adapter;\n}\n\nexport function useHasOperationBridgeRuntime() {\n const adapters = useContext(OperationBridgeAdaptersContext);\n return adapters !== null && adapters.size > 0;\n}\n\nexport function useReflectedEntityDataReader() {\n const reader = useContext(ReflectedEntityDataReaderContext);\n\n if (reader === null) {\n throw new Error(\n 'useReflectedEntityDataReader must be used within an OntahiGraphProvider with reflectedEntityDataReader',\n );\n }\n\n return reader;\n}\n\nexport function useHasReflectedEntityDataReader() {\n return useContext(ReflectedEntityDataReaderContext) !== null;\n}\n\nexport function useReflectedRelatedEntityDataReader() {\n const reader = useContext(ReflectedRelatedEntityDataReaderContext);\n\n if (reader === null) {\n throw new Error(\n 'useReflectedRelatedEntityDataReader must be used within an OntahiGraphProvider with reflectedRelatedEntityDataReader',\n );\n }\n\n return reader;\n}\n\nexport const useHasReflectedRelatedEntityDataReader = () =>\n useContext(ReflectedRelatedEntityDataReaderContext) !== null;\n\nexport function useReflectedOperationInvoker() {\n const invoker = useContext(ReflectedOperationInvokerContext);\n\n if (invoker === null) {\n throw new Error(\n 'useReflectedOperationInvoker must be used within an OntahiGraphProvider with reflectedOperationInvoker',\n );\n }\n\n return invoker;\n}\n\nexport function useHasReflectedOperationInvoker() {\n return useContext(ReflectedOperationInvokerContext) !== null;\n}\n\nexport function useReflectedOperationSupport() {\n const invoker = useContext(ReflectedOperationInvokerContext);\n\n return useCallback(\n (operation: ReflectedOperationDescriptor) =>\n Boolean(invoker && (invoker.canInvokeOperation?.(operation) ?? true)),\n [invoker],\n );\n}\n\nexport function useReflectedOperationExecutionAffordance(\n operation: ReflectedOperationDescriptor,\n): OperationExecutionAffordance | undefined {\n const invoker = useContext(ReflectedOperationInvokerContext);\n\n return invoker?.getOperationExecutionAffordance?.(operation);\n}\n\nexport type { GraphClientCache };\n"]}
|
|
1
|
+
{"version":3,"file":"context.js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CAAuC,CAAC,CAAC;IAEnE,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,sHAAsH,CACvH,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,MAAM,sCAAsC,GAAG,GAAG,EAAE,CACzD,UAAU,CAAC,uCAAuC,CAAC,KAAK,IAAI,CAAC;AAE/D,MAAM,UAAU,4BAA4B;IAC1C,MAAM,OAAO,GAAG,UAAU,CAAC,gCAAgC,CAAC,CAAC;IAE7D,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,wGAAwG,CACzG,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,+BAA+B;IAC7C,OAAO,UAAU,CAAC,gCAAgC,CAAC,KAAK,IAAI,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,4BAA4B;IAC1C,MAAM,OAAO,GAAG,UAAU,CAAC,gCAAgC,CAAC,CAAC;IAE7D,OAAO,WAAW,CAChB,CAAC,SAAuC,EAAE,EAAE,CAC1C,OAAO,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,CAAC,EACvE,CAAC,OAAO,CAAC,CACV,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,wCAAwC,CACtD,SAAuC;IAEvC,MAAM,OAAO,GAAG,UAAU,CAAC,gCAAgC,CAAC,CAAC;IAE7D,OAAO,OAAO,EAAE,+BAA+B,EAAE,CAAC,SAAS,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["'use client';\n\nimport {\n createGraphClientCache,\n type GraphClientCache,\n type OperationExecutionAffordance,\n type ReflectedEntityDataReader,\n type ReflectedRelatedEntityDataReader,\n type ReflectedOperationDescriptor,\n type ReflectedOperationInvoker,\n} from '@ontahi/core/data-graph';\nimport { anonymousExecutionIdentity, type ExecutionIdentity } from '@ontahi/core/runtime/identity';\nimport type { RuntimeTransport } from '@ontahi/core/runtime/protocol';\nimport {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useState,\n useSyncExternalStore,\n type ReactNode,\n} from 'react';\n\nimport type { AnyOperationBridgeAdapter } from '../actions/index.js';\n\nimport type { ReactGraphExecutor } from './executor.js';\nimport { createFetchGraphClient, type OntahiGraphClient } from './fetch-graph-client.js';\nimport {\n createReflectedOperationInvoker,\n type ReflectedGraphOperationLike,\n} from './reflected-operation-invoker.js';\n\nconst noReflectedGraphOperations: readonly ReflectedGraphOperationLike[] = [];\n\nconst GraphRuntimeContext = createContext<unknown | null>(null);\nconst ExecutionIdentityContext = createContext<ExecutionIdentity>(anonymousExecutionIdentity);\nconst GraphExecutorContext = createContext<ReactGraphExecutor<any, any> | null>(null);\nconst GraphClientCacheContext = createContext<GraphClientCache | null>(null);\nconst RuntimeTransportContext = createContext<RuntimeTransport | null>(null);\nconst OperationBridgeAdaptersContext = createContext<Map<string, AnyOperationBridgeAdapter> | null>(\n null,\n);\nconst ReflectedEntityDataReaderContext = createContext<ReflectedEntityDataReader | null>(null);\nconst ReflectedRelatedEntityDataReaderContext =\n createContext<ReflectedRelatedEntityDataReader | null>(null);\nconst ReflectedOperationInvokerContext = createContext<ReflectedOperationInvoker | null>(null);\n\nexport type OntahiGraphProviderProps<\n TGraphRuntime = unknown,\n TReadOptions = unknown,\n TCommandOptions = TReadOptions,\n> = {\n children: ReactNode;\n runtime: TGraphRuntime;\n graphExecutor?: ReactGraphExecutor<TReadOptions, TCommandOptions>;\n runtimeTransport?: RuntimeTransport;\n client?: OntahiGraphClient<TReadOptions, TCommandOptions> | false;\n operationBridgeAdapters?: AnyOperationBridgeAdapter[];\n reflectedEntityDataReader?: ReflectedEntityDataReader;\n reflectedRelatedEntityDataReader?: ReflectedRelatedEntityDataReader;\n reflectedOperationInvoker?: ReflectedOperationInvoker;\n reflectedGraphOperations?: readonly ReflectedGraphOperationLike[];\n clientCache?: GraphClientCache;\n identity?: ExecutionIdentity;\n};\n\nexport function OntahiGraphProvider<\n TGraphRuntime = unknown,\n TReadOptions = unknown,\n TCommandOptions = TReadOptions,\n>({\n children,\n runtime,\n graphExecutor,\n runtimeTransport,\n client,\n operationBridgeAdapters,\n reflectedEntityDataReader,\n reflectedRelatedEntityDataReader,\n reflectedOperationInvoker,\n reflectedGraphOperations = noReflectedGraphOperations,\n clientCache,\n identity = anonymousExecutionIdentity,\n}: OntahiGraphProviderProps<TGraphRuntime, TReadOptions, TCommandOptions>) {\n const [defaultGraphClient] = useState(() => createFetchGraphClient());\n const [defaultClientCache] = useState(() => createGraphClientCache());\n const graphClient = client === false ? undefined : (client ?? defaultGraphClient);\n const resolvedGraphExecutor = graphExecutor ?? graphClient?.graphExecutor;\n const resolvedRuntimeTransport = runtimeTransport ?? graphClient?.runtimeTransport;\n const resolvedOperationBridgeAdapters =\n operationBridgeAdapters ?? graphClient?.operationBridgeAdapters ?? [];\n const resolvedReflectedEntityDataReader =\n reflectedEntityDataReader ?? graphClient?.reflectedEntityDataReader;\n const resolvedReflectedRelatedEntityDataReader =\n reflectedRelatedEntityDataReader ?? graphClient?.reflectedRelatedEntityDataReader;\n const configuredReflectedOperationInvoker =\n reflectedOperationInvoker ?? graphClient?.reflectedOperationInvoker;\n const graphClientCache = clientCache ?? graphClient?.clientCache ?? defaultClientCache;\n const bridgeAdapterMap = useMemo(\n () => new Map(resolvedOperationBridgeAdapters.map(adapter => [adapter.name, adapter])),\n [resolvedOperationBridgeAdapters],\n );\n const resolvedReflectedOperationInvoker = useMemo(\n () =>\n reflectedGraphOperations.length > 0\n ? createReflectedOperationInvoker({\n fallback: configuredReflectedOperationInvoker,\n graphExecutor: resolvedGraphExecutor,\n graphOperations: reflectedGraphOperations,\n })\n : (configuredReflectedOperationInvoker ?? null),\n [configuredReflectedOperationInvoker, reflectedGraphOperations, resolvedGraphExecutor],\n );\n\n return (\n <ExecutionIdentityContext.Provider value={identity}>\n <ReflectedOperationInvokerContext.Provider value={resolvedReflectedOperationInvoker}>\n <ReflectedRelatedEntityDataReaderContext.Provider\n value={resolvedReflectedRelatedEntityDataReader ?? null}\n >\n <ReflectedEntityDataReaderContext.Provider\n value={resolvedReflectedEntityDataReader ?? null}\n >\n <OperationBridgeAdaptersContext.Provider value={bridgeAdapterMap}>\n <RuntimeTransportContext.Provider value={resolvedRuntimeTransport ?? null}>\n <GraphClientCacheContext.Provider value={graphClientCache}>\n <GraphExecutorContext.Provider value={resolvedGraphExecutor ?? null}>\n <GraphRuntimeContext.Provider value={runtime}>\n {children}\n </GraphRuntimeContext.Provider>\n </GraphExecutorContext.Provider>\n </GraphClientCacheContext.Provider>\n </RuntimeTransportContext.Provider>\n </OperationBridgeAdaptersContext.Provider>\n </ReflectedEntityDataReaderContext.Provider>\n </ReflectedRelatedEntityDataReaderContext.Provider>\n </ReflectedOperationInvokerContext.Provider>\n </ExecutionIdentityContext.Provider>\n );\n}\n\nexport const useExecutionIdentity = () => useContext(ExecutionIdentityContext);\n\nexport function useGraphRuntime<TGraphRuntime = unknown>() {\n const runtime = useContext(GraphRuntimeContext);\n\n if (runtime === null) {\n throw new Error('useGraphRuntime must be used within an OntahiGraphProvider');\n }\n\n return runtime as TGraphRuntime;\n}\n\nexport function useGraphExecutor<TReadOptions = unknown, TCommandOptions = TReadOptions>() {\n const graphExecutor = useContext(GraphExecutorContext);\n\n if (graphExecutor === null) {\n throw new Error(\n 'useGraphExecutor must be used within an OntahiGraphProvider with graphExecutor',\n );\n }\n\n return graphExecutor as ReactGraphExecutor<TReadOptions, TCommandOptions>;\n}\n\nexport function useGraphExecutorCapability<\n TReadOptions = unknown,\n TCommandOptions = TReadOptions,\n>() {\n return (useContext(GraphExecutorContext) ?? undefined) as\n | ReactGraphExecutor<TReadOptions, TCommandOptions>\n | undefined;\n}\n\nexport const useRuntimeTransportCapability = () => useContext(RuntimeTransportContext) ?? undefined;\n\nexport function useRuntimeTransport() {\n const transport = useRuntimeTransportCapability();\n if (!transport) {\n throw new Error('useRuntimeTransport requires an OntahiGraphProvider with runtimeTransport');\n }\n return transport;\n}\n\nexport function useGraphClientCache() {\n const clientCache = useContext(GraphClientCacheContext);\n\n if (clientCache === null) {\n throw new Error('useGraphClientCache must be used within an OntahiGraphProvider');\n }\n\n return clientCache;\n}\n\nexport function useGraphClientCacheSnapshot() {\n const clientCache = useGraphClientCache();\n\n useGraphClientCacheVersion(clientCache);\n\n return clientCache.inspect();\n}\n\nexport const useGraphClientCacheVersion = (clientCache: GraphClientCache) =>\n useSyncExternalStore(\n clientCache.subscribe,\n () => clientCache.inspect().version,\n () => clientCache.inspect().version,\n );\n\nexport function useOperationBridgeAdapter(adapterName: string) {\n const adapters = useContext(OperationBridgeAdaptersContext);\n\n if (adapters === null) {\n throw new Error('useOperationBridgeAdapter must be used within an OntahiGraphProvider');\n }\n\n const adapter = adapters.get(adapterName);\n\n if (!adapter) {\n throw new Error(`No operation bridge adapter registered for \"${adapterName}\"`);\n }\n\n return adapter;\n}\n\nexport function useDefaultOperationBridgeAdapter() {\n const adapters = useContext(OperationBridgeAdaptersContext);\n\n if (adapters === null) {\n throw new Error('useDefaultOperationBridgeAdapter must be used within an OntahiGraphProvider');\n }\n\n const [adapter] = adapters.values();\n\n if (!adapter) {\n throw new Error('No operation bridge adapter registered.');\n }\n\n return adapter;\n}\n\nexport function useHasOperationBridgeRuntime() {\n const adapters = useContext(OperationBridgeAdaptersContext);\n return adapters !== null && adapters.size > 0;\n}\n\nexport function useReflectedEntityDataReader() {\n const reader = useContext(ReflectedEntityDataReaderContext);\n\n if (reader === null) {\n throw new Error(\n 'useReflectedEntityDataReader must be used within an OntahiGraphProvider with reflectedEntityDataReader',\n );\n }\n\n return reader;\n}\n\nexport function useHasReflectedEntityDataReader() {\n return useContext(ReflectedEntityDataReaderContext) !== null;\n}\n\nexport function useReflectedRelatedEntityDataReader() {\n const reader = useContext(ReflectedRelatedEntityDataReaderContext);\n\n if (reader === null) {\n throw new Error(\n 'useReflectedRelatedEntityDataReader must be used within an OntahiGraphProvider with reflectedRelatedEntityDataReader',\n );\n }\n\n return reader;\n}\n\nexport const useHasReflectedRelatedEntityDataReader = () =>\n useContext(ReflectedRelatedEntityDataReaderContext) !== null;\n\nexport function useReflectedOperationInvoker() {\n const invoker = useContext(ReflectedOperationInvokerContext);\n\n if (invoker === null) {\n throw new Error(\n 'useReflectedOperationInvoker must be used within an OntahiGraphProvider with reflectedOperationInvoker',\n );\n }\n\n return invoker;\n}\n\nexport function useHasReflectedOperationInvoker() {\n return useContext(ReflectedOperationInvokerContext) !== null;\n}\n\nexport function useReflectedOperationSupport() {\n const invoker = useContext(ReflectedOperationInvokerContext);\n\n return useCallback(\n (operation: ReflectedOperationDescriptor) =>\n Boolean(invoker && (invoker.canInvokeOperation?.(operation) ?? true)),\n [invoker],\n );\n}\n\nexport function useReflectedOperationExecutionAffordance(\n operation: ReflectedOperationDescriptor,\n): OperationExecutionAffordance | undefined {\n const invoker = useContext(ReflectedOperationInvokerContext);\n\n return invoker?.getOperationExecutionAffordance?.(operation);\n}\n\nexport type { GraphClientCache };\n"]}
|
package/dist/graph/executor.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GraphCommandSpec, GraphOperationDeclaration, GraphReadExpression, GraphReadIntent, GraphSchemaLike, InferGraphSchemaClientInput, QueryOrView, QuerySpec, ManyToManyRelationshipCommand, RelationshipCommand, RelationshipCommandResult, EntityMutationCommand, EntityMutationDelta } from '@ontahi/core/data-graph';
|
|
1
|
+
import type { GraphCommandSpec, GraphOperationDeclaration, GraphReadExpression, GraphReadIntent, GraphSchemaLike, InferGraphSchemaClientInput, QueryOrView, QuerySpec, ManyToManyRelationshipCommand, OrderedRelationshipCommand, RelationshipCommand, RelationshipCommandResult, EntityMutationCommand, EntityMutationDelta } from '@ontahi/core/data-graph';
|
|
2
2
|
import type { QueryKey, UseMutationOptions, UseQueryOptions } from '@tanstack/react-query';
|
|
3
3
|
export interface ReactGraphExecutor<TReadOptions = unknown, TCommandOptions = TReadOptions> {
|
|
4
4
|
get<TParams, TResult>(read: QueryOrView<TParams, TResult>, params: TParams, options?: TReadOptions): Promise<TResult | null>;
|
|
@@ -7,6 +7,7 @@ export interface ReactGraphExecutor<TReadOptions = unknown, TCommandOptions = TR
|
|
|
7
7
|
runCommand<TResult = void>(command: GraphCommandSpec<any, any, TResult>, options?: TCommandOptions): Promise<TResult>;
|
|
8
8
|
runRelationshipCommand?(command: RelationshipCommand, options?: TCommandOptions): Promise<RelationshipCommandResult>;
|
|
9
9
|
runManyToManyRelationshipCommand?(command: ManyToManyRelationshipCommand, options?: TCommandOptions): Promise<RelationshipCommandResult>;
|
|
10
|
+
runOrderedRelationshipCommand?(command: OrderedRelationshipCommand, options?: TCommandOptions): Promise<RelationshipCommandResult>;
|
|
10
11
|
runEntityMutationCommand?(command: EntityMutationCommand, options?: TCommandOptions): Promise<EntityMutationDelta>;
|
|
11
12
|
}
|
|
12
13
|
export type BuildableRead<TResult> = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/graph/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,yBAAyB,EACzB,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,2BAA2B,EAC3B,WAAW,EACX,SAAS,EACT,6BAA6B,EAC7B,mBAAmB,EACnB,yBAAyB,EACzB,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE3F,MAAM,WAAW,kBAAkB,CAAC,YAAY,GAAG,OAAO,EAAE,eAAe,GAAG,YAAY;IACxF,GAAG,CAAC,OAAO,EAAE,OAAO,EAClB,IAAI,EAAE,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,EACnC,MAAM,EAAE,OAAO,EACf,OA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AAK,EAAE,MAAM,OAAO,SAAS,eAAe,CAAC;CAC9C,GACG,2BAA2B,CAAC,OAAO,CAAC,GACpC,UAAU,SAAS,yBAAyB,CAAC,MAAM,MAAM,EAAE,GAAG,CAAC,GAC7D,MAAM,GACN,KAAK,CAAC;AAEZ,MAAM,MAAM,oBAAoB,CAAC,UAAU,IAAI,UAAU,SAAS;IAChE,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,WAAW,CAAC,MAAM,OAAO,CAAC,CAAC;CACrD,GACG,OAAO,GACP,KAAK,CAAC;AAEV,MAAM,MAAM,uBAAuB,CACjC,OAAO,EACP,UAAU,EACV,QAAQ,EACR,eAAe,GAAG,OAAO,IACvB,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,YAAY,CAAC,GAAG;IACjF,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB,cAAc,CAAC,EAAE,eAAe,CAAC;IACjC,mBAAmB,CAAC,EAAE,QAAQ,EAAE,CAAC;CAClC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../src/graph/executor.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n GraphCommandSpec,\n GraphOperationDeclaration,\n GraphReadExpression,\n GraphReadIntent,\n GraphSchemaLike,\n InferGraphSchemaClientInput,\n QueryOrView,\n QuerySpec,\n ManyToManyRelationshipCommand,\n RelationshipCommand,\n RelationshipCommandResult,\n EntityMutationCommand,\n EntityMutationDelta,\n} from '@ontahi/core/data-graph';\nimport type { QueryKey, UseMutationOptions, UseQueryOptions } from '@tanstack/react-query';\n\nexport interface ReactGraphExecutor<TReadOptions = unknown, TCommandOptions = TReadOptions> {\n get<TParams, TResult>(\n read: QueryOrView<TParams, TResult>,\n params: TParams,\n options?: TReadOptions,\n ): Promise<TResult | null>;\n run<TParams, TResult>(\n read: QueryOrView<TParams, TResult>,\n params: TParams,\n options?: TReadOptions,\n ): Promise<TResult[]>;\n count<TParams, TResult>(\n read: QueryOrView<TParams, TResult>,\n params: TParams,\n options?: TReadOptions,\n ): Promise<number>;\n runCommand<TResult = void>(\n command: GraphCommandSpec<any, any, TResult>,\n options?: TCommandOptions,\n ): Promise<TResult>;\n runRelationshipCommand?(\n command: RelationshipCommand,\n options?: TCommandOptions,\n ): Promise<RelationshipCommandResult>;\n runManyToManyRelationshipCommand?(\n command: ManyToManyRelationshipCommand,\n options?: TCommandOptions,\n ): Promise<RelationshipCommandResult>;\n runEntityMutationCommand?(\n command: EntityMutationCommand,\n options?: TCommandOptions,\n ): Promise<EntityMutationDelta>;\n}\n\nexport type BuildableRead<TResult> = {\n build: () => QuerySpec<any, TResult>;\n};\n\ntype PlainGraphReadSource<TResult> = QueryOrView<any, TResult> | BuildableRead<TResult>;\n\nexport type GraphReadSource<TResult = unknown> =\n | PlainGraphReadSource<TResult>\n | GraphReadExpression<PlainGraphReadSource<TResult>, GraphReadIntent, TResult>;\n\nexport type ReadParams<TRead> =\n TRead extends GraphReadExpression<infer TSource, any, any>\n ? ReadParams<TSource>\n : TRead extends QueryOrView<infer TParams, any>\n ? TParams\n : undefined;\n\nexport type ReadResult<TRead> =\n TRead extends GraphReadExpression<any, any, infer TResult>\n ? TResult\n : TRead extends QueryOrView<any, infer TResult>\n ? TResult\n : TRead extends BuildableRead<infer TResult>\n ? TResult\n : never;\n\nexport type GraphQueryMode = 'get' | 'run' | 'count' | 'exists';\n\ntype GraphReadIntentData<TRead, TIntent extends GraphReadIntent> = TIntent extends 'count'\n ? number\n : TIntent extends 'exists'\n ? boolean\n : TIntent extends 'one'\n ? ReadResult<TRead>\n : ReadResult<TRead> | null;\n\nexport type GraphQueryData<TRead, TMode extends GraphQueryMode = 'run'> =\n TRead extends GraphReadExpression<any, infer TIntent, any>\n ? GraphReadIntentData<TRead, TIntent>\n : TMode extends 'get'\n ? ReadResult<TRead> | null\n : TMode extends 'run'\n ? ReadResult<TRead>[]\n : TMode extends 'count'\n ? number\n : boolean;\n\nexport type GraphQueryOptions<\n TRead,\n TMode extends GraphQueryMode = 'run',\n TReadOptions = unknown,\n> = Omit<\n UseQueryOptions<GraphQueryData<TRead, TMode>, Error, GraphQueryData<TRead, TMode>, QueryKey>,\n 'queryKey' | 'queryFn'\n> & {\n mode?: TRead extends GraphReadExpression<any, any, any> ? never : TMode;\n params?: ReadParams<TRead>;\n queryKey?: QueryKey;\n runtimeOptions?: TReadOptions;\n};\n\nexport type CommandLike<TResult> =\n | GraphCommandSpec<any, any, TResult>\n | {\n build: () => GraphCommandSpec<any, any, TResult>;\n };\n\nexport type GraphCommandBuilder<TVariables, TResult> = (\n variables: TVariables,\n) => CommandLike<TResult>;\n\nexport type GraphOperationLike<TVariables, TResult> = GraphOperationDeclaration<\n TVariables,\n CommandLike<TResult>\n> & {\n id: string;\n};\n\nexport type GraphOperationClientInput<TOperation> = TOperation extends {\n input: infer TSchema extends GraphSchemaLike;\n}\n ? InferGraphSchemaClientInput<TSchema>\n : TOperation extends GraphOperationDeclaration<infer TInput, any>\n ? TInput\n : never;\n\nexport type GraphOperationResult<TOperation> = TOperation extends {\n run: (...args: any[]) => CommandLike<infer TResult>;\n}\n ? TResult\n : never;\n\nexport type GraphCommandHookOptions<\n TResult,\n TVariables,\n TContext,\n TCommandOptions = unknown,\n> = Omit<UseMutationOptions<TResult, Error, TVariables, TContext>, 'mutationFn'> & {\n mutationKey?: QueryKey;\n runtimeOptions?: TCommandOptions;\n invalidateQueryKeys?: QueryKey[];\n};\n"]}
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../src/graph/executor.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n GraphCommandSpec,\n GraphOperationDeclaration,\n GraphReadExpression,\n GraphReadIntent,\n GraphSchemaLike,\n InferGraphSchemaClientInput,\n QueryOrView,\n QuerySpec,\n ManyToManyRelationshipCommand,\n OrderedRelationshipCommand,\n RelationshipCommand,\n RelationshipCommandResult,\n EntityMutationCommand,\n EntityMutationDelta,\n} from '@ontahi/core/data-graph';\nimport type { QueryKey, UseMutationOptions, UseQueryOptions } from '@tanstack/react-query';\n\nexport interface ReactGraphExecutor<TReadOptions = unknown, TCommandOptions = TReadOptions> {\n get<TParams, TResult>(\n read: QueryOrView<TParams, TResult>,\n params: TParams,\n options?: TReadOptions,\n ): Promise<TResult | null>;\n run<TParams, TResult>(\n read: QueryOrView<TParams, TResult>,\n params: TParams,\n options?: TReadOptions,\n ): Promise<TResult[]>;\n count<TParams, TResult>(\n read: QueryOrView<TParams, TResult>,\n params: TParams,\n options?: TReadOptions,\n ): Promise<number>;\n runCommand<TResult = void>(\n command: GraphCommandSpec<any, any, TResult>,\n options?: TCommandOptions,\n ): Promise<TResult>;\n runRelationshipCommand?(\n command: RelationshipCommand,\n options?: TCommandOptions,\n ): Promise<RelationshipCommandResult>;\n runManyToManyRelationshipCommand?(\n command: ManyToManyRelationshipCommand,\n options?: TCommandOptions,\n ): Promise<RelationshipCommandResult>;\n runOrderedRelationshipCommand?(\n command: OrderedRelationshipCommand,\n options?: TCommandOptions,\n ): Promise<RelationshipCommandResult>;\n runEntityMutationCommand?(\n command: EntityMutationCommand,\n options?: TCommandOptions,\n ): Promise<EntityMutationDelta>;\n}\n\nexport type BuildableRead<TResult> = {\n build: () => QuerySpec<any, TResult>;\n};\n\ntype PlainGraphReadSource<TResult> = QueryOrView<any, TResult> | BuildableRead<TResult>;\n\nexport type GraphReadSource<TResult = unknown> =\n | PlainGraphReadSource<TResult>\n | GraphReadExpression<PlainGraphReadSource<TResult>, GraphReadIntent, TResult>;\n\nexport type ReadParams<TRead> =\n TRead extends GraphReadExpression<infer TSource, any, any>\n ? ReadParams<TSource>\n : TRead extends QueryOrView<infer TParams, any>\n ? TParams\n : undefined;\n\nexport type ReadResult<TRead> =\n TRead extends GraphReadExpression<any, any, infer TResult>\n ? TResult\n : TRead extends QueryOrView<any, infer TResult>\n ? TResult\n : TRead extends BuildableRead<infer TResult>\n ? TResult\n : never;\n\nexport type GraphQueryMode = 'get' | 'run' | 'count' | 'exists';\n\ntype GraphReadIntentData<TRead, TIntent extends GraphReadIntent> = TIntent extends 'count'\n ? number\n : TIntent extends 'exists'\n ? boolean\n : TIntent extends 'one'\n ? ReadResult<TRead>\n : ReadResult<TRead> | null;\n\nexport type GraphQueryData<TRead, TMode extends GraphQueryMode = 'run'> =\n TRead extends GraphReadExpression<any, infer TIntent, any>\n ? GraphReadIntentData<TRead, TIntent>\n : TMode extends 'get'\n ? ReadResult<TRead> | null\n : TMode extends 'run'\n ? ReadResult<TRead>[]\n : TMode extends 'count'\n ? number\n : boolean;\n\nexport type GraphQueryOptions<\n TRead,\n TMode extends GraphQueryMode = 'run',\n TReadOptions = unknown,\n> = Omit<\n UseQueryOptions<GraphQueryData<TRead, TMode>, Error, GraphQueryData<TRead, TMode>, QueryKey>,\n 'queryKey' | 'queryFn'\n> & {\n mode?: TRead extends GraphReadExpression<any, any, any> ? never : TMode;\n params?: ReadParams<TRead>;\n queryKey?: QueryKey;\n runtimeOptions?: TReadOptions;\n};\n\nexport type CommandLike<TResult> =\n | GraphCommandSpec<any, any, TResult>\n | {\n build: () => GraphCommandSpec<any, any, TResult>;\n };\n\nexport type GraphCommandBuilder<TVariables, TResult> = (\n variables: TVariables,\n) => CommandLike<TResult>;\n\nexport type GraphOperationLike<TVariables, TResult> = GraphOperationDeclaration<\n TVariables,\n CommandLike<TResult>\n> & {\n id: string;\n};\n\nexport type GraphOperationClientInput<TOperation> = TOperation extends {\n input: infer TSchema extends GraphSchemaLike;\n}\n ? InferGraphSchemaClientInput<TSchema>\n : TOperation extends GraphOperationDeclaration<infer TInput, any>\n ? TInput\n : never;\n\nexport type GraphOperationResult<TOperation> = TOperation extends {\n run: (...args: any[]) => CommandLike<infer TResult>;\n}\n ? TResult\n : never;\n\nexport type GraphCommandHookOptions<\n TResult,\n TVariables,\n TContext,\n TCommandOptions = unknown,\n> = Omit<UseMutationOptions<TResult, Error, TVariables, TContext>, 'mutationFn'> & {\n mutationKey?: QueryKey;\n runtimeOptions?: TCommandOptions;\n invalidateQueryKeys?: QueryKey[];\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReflectedEntityDataReader, ReflectedRelatedEntityDataReader, ReflectedOperationInvoker, RemoteDataGraphError, RuntimeBoundDataGraphApi } from '@ontahi/core/data-graph';
|
|
1
|
+
import type { GraphClientCache, ReflectedEntityDataReader, ReflectedRelatedEntityDataReader, ReflectedOperationInvoker, RemoteDataGraphError, RuntimeBoundDataGraphApi } from '@ontahi/core/data-graph';
|
|
2
2
|
import type { RuntimeTransport } from '@ontahi/core/runtime/protocol';
|
|
3
3
|
import { type AnyOperationBridgeAdapter, type FetchOperationBridgeOptions } from '../actions/index.js';
|
|
4
4
|
import type { ReactGraphExecutor } from './executor.js';
|
|
@@ -12,7 +12,8 @@ export type FetchReflectedRelatedEntityDataReaderOptions = FetchReflectedEntityD
|
|
|
12
12
|
export type OntahiGraphClient<TReadOptions = unknown, TCommandOptions = TReadOptions> = {
|
|
13
13
|
graph?: RuntimeBoundDataGraphApi<RemoteDataGraphError, TReadOptions, TCommandOptions, RemoteDataGraphError>;
|
|
14
14
|
graphExecutor?: ReactGraphExecutor<TReadOptions, TCommandOptions>;
|
|
15
|
-
|
|
15
|
+
clientCache?: GraphClientCache;
|
|
16
|
+
runtimeTransport?: RuntimeTransport<TReadOptions | TCommandOptions>;
|
|
16
17
|
operationBridgeAdapters?: AnyOperationBridgeAdapter[];
|
|
17
18
|
reflectedEntityDataReader?: ReflectedEntityDataReader;
|
|
18
19
|
reflectedRelatedEntityDataReader?: ReflectedRelatedEntityDataReader;
|
|
@@ -21,11 +22,25 @@ export type OntahiGraphClient<TReadOptions = unknown, TCommandOptions = TReadOpt
|
|
|
21
22
|
export type FetchGraphClient<TOptions = undefined> = OntahiGraphClient<TOptions, TOptions> & {
|
|
22
23
|
graph: RuntimeBoundDataGraphApi<RemoteDataGraphError, TOptions, TOptions, RemoteDataGraphError>;
|
|
23
24
|
graphExecutor: ReactGraphExecutor<TOptions, TOptions>;
|
|
25
|
+
clientCache: GraphClientCache;
|
|
26
|
+
};
|
|
27
|
+
export type FetchGraphClientCompatibilityOptions = {
|
|
28
|
+
operation?: {
|
|
29
|
+
endpoint?: string;
|
|
30
|
+
mountPath?: string;
|
|
31
|
+
};
|
|
32
|
+
graphRead?: {
|
|
33
|
+
endpoint?: string;
|
|
34
|
+
};
|
|
35
|
+
graphCommand?: {
|
|
36
|
+
endpoint?: string;
|
|
37
|
+
};
|
|
24
38
|
};
|
|
25
39
|
export type FetchGraphClientOptions<TOptions = undefined> = {
|
|
40
|
+
compatibility?: FetchGraphClientCompatibilityOptions;
|
|
26
41
|
graphRead?: false | FetchGraphReadExecutorOptions<TOptions>;
|
|
27
|
-
operations?: false | FetchOperationBridgeOptions
|
|
28
|
-
runtimeTransport?: false | FetchRuntimeTransportOptions
|
|
42
|
+
operations?: false | FetchOperationBridgeOptions<TOptions>;
|
|
43
|
+
runtimeTransport?: false | FetchRuntimeTransportOptions<TOptions>;
|
|
29
44
|
reflectedEntityData?: false | FetchReflectedEntityDataReaderOptions;
|
|
30
45
|
reflectedRelatedEntityData?: false | FetchReflectedRelatedEntityDataReaderOptions;
|
|
31
46
|
};
|