@ontahi/react 0.1.0-alpha.7 → 1.0.0-alpha.9
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 +38 -7
- package/dist/actions/fetch-operation-bridge-adapter.d.ts +0 -1
- package/dist/actions/fetch-operation-bridge-adapter.d.ts.map +1 -1
- package/dist/actions/fetch-operation-bridge-adapter.js +15 -19
- package/dist/actions/fetch-operation-bridge-adapter.js.map +1 -1
- package/dist/actions/operation-bridge-adapter.d.ts +0 -2
- package/dist/actions/operation-bridge-adapter.d.ts.map +1 -1
- package/dist/actions/operation-bridge-adapter.js +0 -1
- package/dist/actions/operation-bridge-adapter.js.map +1 -1
- package/dist/actions/operation-bridge.d.ts +1 -2
- package/dist/actions/operation-bridge.d.ts.map +1 -1
- package/dist/actions/operation-bridge.js +2 -5
- package/dist/actions/operation-bridge.js.map +1 -1
- package/dist/graph/context.d.ts +11 -2
- package/dist/graph/context.d.ts.map +1 -1
- package/dist/graph/context.js +29 -2
- package/dist/graph/context.js.map +1 -1
- package/dist/graph/executor.d.ts +4 -3
- 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 +9 -1
- package/dist/graph/fetch-graph-client.d.ts.map +1 -1
- package/dist/graph/fetch-graph-client.js +27 -15
- package/dist/graph/fetch-graph-client.js.map +1 -1
- package/dist/graph/fetch-graph-runtime.d.ts +3 -2
- package/dist/graph/fetch-graph-runtime.d.ts.map +1 -1
- package/dist/graph/fetch-graph-runtime.js +5 -2
- package/dist/graph/fetch-graph-runtime.js.map +1 -1
- package/dist/graph/fetch-runtime-transport.d.ts +15 -0
- package/dist/graph/fetch-runtime-transport.d.ts.map +1 -0
- package/dist/graph/fetch-runtime-transport.js +89 -0
- package/dist/graph/fetch-runtime-transport.js.map +1 -0
- package/dist/graph/graph-hooks.d.ts +2 -2
- package/dist/graph/graph-hooks.d.ts.map +1 -1
- package/dist/graph/graph-hooks.js.map +1 -1
- package/dist/graph/index.d.ts +1 -0
- package/dist/graph/index.d.ts.map +1 -1
- package/dist/graph/index.js +1 -0
- package/dist/graph/index.js.map +1 -1
- package/dist/graph/operation-hooks.d.ts.map +1 -1
- package/dist/graph/operation-hooks.js +41 -21
- package/dist/graph/operation-hooks.js.map +1 -1
- package/dist/graph/operation-types.d.ts +1 -3
- package/dist/graph/operation-types.d.ts.map +1 -1
- package/dist/graph/operation-types.js.map +1 -1
- package/dist/graph/reflected-entity-data-hooks.d.ts +3 -1
- package/dist/graph/reflected-entity-data-hooks.d.ts.map +1 -1
- package/dist/graph/reflected-entity-data-hooks.js +10 -1
- package/dist/graph/reflected-entity-data-hooks.js.map +1 -1
- package/dist/graph/reflected-operation-invoker.d.ts.map +1 -1
- package/dist/graph/reflected-operation-invoker.js +41 -3
- package/dist/graph/reflected-operation-invoker.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -15,7 +15,9 @@ host application. Reusable reflective UI lives in `@ontahi/explorer-react`; host
|
|
|
15
15
|
own routes, access control, theme/auth composition, and application-specific UI enrichments.
|
|
16
16
|
|
|
17
17
|
Start with the end-to-end [Application Data Access](../../docs/application-data-access.md) guide for
|
|
18
|
-
the recommended server, codegen, and React composition.
|
|
18
|
+
the recommended server, codegen, and React composition. The canonical
|
|
19
|
+
[browser projection chapter](../../docs/developers/04-reflection-and-clients/02-browser-client-and-projection.md)
|
|
20
|
+
adds the model context; this README is the package-level reference.
|
|
19
21
|
|
|
20
22
|
Projectable Operations keep population on the server and shape in the caller:
|
|
21
23
|
|
|
@@ -49,9 +51,10 @@ const first = useGraphQuery(openTodos.first());
|
|
|
49
51
|
```
|
|
50
52
|
|
|
51
53
|
`OntahiGraphProvider` installs a conventional same-origin Fetch client by default. It connects
|
|
52
|
-
graph reads to `/graph/reads`, Operations
|
|
53
|
-
Explorer data to `/explorer/entities`. These
|
|
54
|
-
not issue a request until the application uses
|
|
54
|
+
graph reads to `/graph/reads`, Operations to `/operations`, Durable Operation observation to the
|
|
55
|
+
Runtime Protocol at `/runtime`, and reflected Explorer data to `/explorer/entities`. These
|
|
56
|
+
capabilities are lazy: declaring the provider does not issue a request until the application uses
|
|
57
|
+
one of them.
|
|
55
58
|
|
|
56
59
|
Hosts can replace any individual capability through the existing provider props, install a
|
|
57
60
|
configured client with `client={createFetchGraphClient(...)}`, or set `client={false}` for a fully
|
|
@@ -97,6 +100,34 @@ await completeVisible.executeAsync();
|
|
|
97
100
|
The bound invocation always uses the latest render input. Passing the Operation declaration itself
|
|
98
101
|
keeps the lower-level reusable mutation form, where each execution supplies its input.
|
|
99
102
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
Durable Operations use the same invocation bridge to start a run, then observe its lifecycle
|
|
104
|
+
through Runtime Transport:
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
const completeAll = useDurableOperation(TodoItem.domain.completeAll);
|
|
108
|
+
|
|
109
|
+
await completeAll.executeAsync();
|
|
110
|
+
// completeAll.status/progress/finalValue follow the accepted run.
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The hook consumes an asynchronous snapshot sequence and does not choose polling or push. The
|
|
114
|
+
conventional Fetch Runtime Transport implements that sequence with versioned
|
|
115
|
+
`durable.operation.inspect` requests and owns the polling cadence:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
const client = createFetchGraphClient({
|
|
119
|
+
runtimeTransport: {
|
|
120
|
+
endpoint: '/runtime/ontahi/runtime',
|
|
121
|
+
durableOperation: { pollIntervalMs: 750 },
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Hosts can replace `runtimeTransport` independently on `OntahiGraphProvider`; a future push-capable
|
|
127
|
+
transport can yield the same snapshots without changing the hook.
|
|
128
|
+
|
|
129
|
+
The Fetch executor sends only canonical graph-read and graph-Command requests. Credentials and
|
|
130
|
+
other trusted request state remain in Fetch initialization and are never embedded in a Query AST or
|
|
131
|
+
Command. The executor supports policy-bounded Relationship Commands and identity-scoped Entity
|
|
132
|
+
Mutation Commands; `useGraphExecutorCapability()` lets optional reflective UI discover whether the
|
|
133
|
+
host installed that execution surface without making it mandatory for read-only hosts.
|
|
@@ -3,7 +3,6 @@ import type * as OperationBridge from './operation-bridge.js';
|
|
|
3
3
|
export type FetchOperationBridgeOptions = {
|
|
4
4
|
mountPath?: string;
|
|
5
5
|
endpoint?: string;
|
|
6
|
-
taskEndpoint?: string;
|
|
7
6
|
};
|
|
8
7
|
export declare const createFetchReflectedOperationInvoker: (options?: FetchOperationBridgeOptions) => ReflectedOperationInvoker;
|
|
9
8
|
export declare const createFetchOperationBridgeAdapter: (options?: FetchOperationBridgeOptions) => OperationBridge.AnyOperationBridgeAdapter;
|
|
@@ -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;AAcjC,OAAO,KAAK,KAAK,eAAe,MAAM,uBAAuB,CAAC;AAI9D,MAAM,MAAM,2BAA2B,GAAG;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAwFF,eAAO,MAAM,oCAAoC,GAC/C,UAAS,2BAAgC,KACxC,yBAoCF,CAAC;AAEF,eAAO,MAAM,iCAAiC,GAC5C,UAAS,2BAAgC,KACxC,eAAe,CAAC,yBAyClB,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import { resolveOperationExecutionAffordance } from '@ontahi/core/data-graph';
|
|
2
3
|
import { isOperationInvocationProtocolResponse, } from '@ontahi/core/runtime/operation-invocation';
|
|
3
4
|
import { useMemo } from 'react';
|
|
4
5
|
import { attachOperationBridgeActionRuntime, toOperationInvocationResult, unwrapOperationInvocationValue, } from './operation-bridge.js';
|
|
@@ -11,16 +12,6 @@ const normalizeMountPath = (value) => {
|
|
|
11
12
|
const mountedEndpoint = (mountPath, endpoint) => `${normalizeMountPath(mountPath)}/${endpoint}`;
|
|
12
13
|
const operationEndpoint = (options) => options.endpoint ??
|
|
13
14
|
(options.mountPath ? mountedEndpoint(options.mountPath, 'operations') : DEFAULT_ENDPOINT);
|
|
14
|
-
const operationTaskEndpoint = (options) => options.taskEndpoint ??
|
|
15
|
-
(options.mountPath ? mountedEndpoint(options.mountPath, 'operations/tasks') : undefined);
|
|
16
|
-
const fetchTaskSnapshot = async (endpoint, ref) => {
|
|
17
|
-
const response = await fetch(`${endpoint}/${encodeURIComponent(ref.taskId)}/${encodeURIComponent(ref.runId)}`, { credentials: 'same-origin' });
|
|
18
|
-
const payload = await response.json().catch(() => null);
|
|
19
|
-
if (!response.ok || typeof payload !== 'object' || payload === null) {
|
|
20
|
-
throw new Error(`Task snapshot request failed with status ${response.status}.`);
|
|
21
|
-
}
|
|
22
|
-
return payload;
|
|
23
|
-
};
|
|
24
15
|
const attachFetchBridgeRuntime = (operation, action) => attachOperationBridgeActionRuntime(operation, action, {
|
|
25
16
|
requiresAuth: operation.authority !== 'server' ? false : operation.exposure !== 'bridge',
|
|
26
17
|
});
|
|
@@ -65,10 +56,21 @@ const createFetchPermissionAction = (endpoint, operation) => (input) => postBrid
|
|
|
65
56
|
});
|
|
66
57
|
export const createFetchReflectedOperationInvoker = (options = {}) => {
|
|
67
58
|
const endpoint = operationEndpoint(options);
|
|
59
|
+
const canInvokeOperation = operation => operation.kind === undefined
|
|
60
|
+
? operation.exposure === undefined || operation.exposure === 'bridge'
|
|
61
|
+
: operation.kind !== 'graph' && operation.exposure === 'bridge';
|
|
68
62
|
return {
|
|
69
|
-
canInvokeOperation
|
|
70
|
-
|
|
71
|
-
|
|
63
|
+
canInvokeOperation,
|
|
64
|
+
getOperationExecutionAffordance: operation => resolveOperationExecutionAffordance(operation, {
|
|
65
|
+
...(canInvokeOperation(operation)
|
|
66
|
+
? {
|
|
67
|
+
bridge: {
|
|
68
|
+
authority: operation.authority ?? 'server',
|
|
69
|
+
bridge: 'fetch',
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
: {}),
|
|
73
|
+
}),
|
|
72
74
|
invokeOperation: async ({ input, operationId, view, }) => toOperationInvocationResult(await postBridgeRequest(endpoint, {
|
|
73
75
|
kind: 'invoke',
|
|
74
76
|
operationId,
|
|
@@ -79,15 +81,9 @@ export const createFetchReflectedOperationInvoker = (options = {}) => {
|
|
|
79
81
|
};
|
|
80
82
|
export const createFetchOperationBridgeAdapter = (options = {}) => {
|
|
81
83
|
const endpoint = operationEndpoint(options);
|
|
82
|
-
const taskEndpoint = operationTaskEndpoint(options);
|
|
83
84
|
const buildRuntimeAction = (operation) => createFetchBridgeAction(endpoint, operation);
|
|
84
85
|
return {
|
|
85
86
|
name: 'fetch',
|
|
86
|
-
...(taskEndpoint
|
|
87
|
-
? {
|
|
88
|
-
getTaskSnapshot: (ref) => fetchTaskSnapshot(taskEndpoint, ref),
|
|
89
|
-
}
|
|
90
|
-
: {}),
|
|
91
87
|
useBridgeAction: operation => useMemo(() => buildRuntimeAction(operation), [operation]),
|
|
92
88
|
useBridgeMutation: (operation, options) => {
|
|
93
89
|
const action = useMemo(() => buildRuntimeAction(operation), [operation]);
|
|
@@ -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;AAWb,OAAO,EACL,qCAAqC,GAEtC,MAAM,2CAA2C,CAAC;AACnD,O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CAAC,EAAE,CAAC;QACP,eAAe,EAAE,SAAS,CAAC,EAAE,CAC3B,OAAO,CACL,GAAG,EAAE,CAAC,kBAAkB,CAAC,SAAS,CAAoD,EACtF,CAAC,SAAS,CAAC,CACuC;QACtD,iBAAiB,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE;YACxC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,kBAAkB,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;YAEzE,OAAO,iBAAiB,CACtB,MAAiE,EACjE,OAEI,CACoF,CAAC;QAC7F,CAAC;QACD,cAAc,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE;YAClC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,kBAAkB,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;YAEzE,OAAO,cAAc,CAAC;gBACpB,MAAM,EAAE,MAAiE;gBACzE,KAAK,EAAE,IAAI,CAAC,KAAgB;gBAC5B,GAAG,EAAE,IAAI,CAAC,GAAG;gBACb,MAAM,EAAE,8BAA8B;aACvC,CAAQ,CAAC;QACZ,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,QAAQ,EAAE,SAAS,CAAC;YACxD,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 type {\n OperationInvocationResult,\n TaskRunIdentity,\n TaskSnapshot,\n} 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 taskEndpoint?: 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 operationTaskEndpoint = (options: FetchOperationBridgeOptions) =>\n options.taskEndpoint ??\n (options.mountPath ? mountedEndpoint(options.mountPath, 'operations/tasks') : undefined);\n\nconst fetchTaskSnapshot = async <TResult>(\n endpoint: string,\n ref: TaskRunIdentity,\n): Promise<TaskSnapshot<TResult>> => {\n const response = await fetch(\n `${endpoint}/${encodeURIComponent(ref.taskId)}/${encodeURIComponent(ref.runId)}`,\n { credentials: 'same-origin' },\n );\n const payload: unknown = await response.json().catch(() => null);\n\n if (!response.ok || typeof payload !== 'object' || payload === null) {\n throw new Error(`Task snapshot request failed with status ${response.status}.`);\n }\n\n return payload as TaskSnapshot<TResult>;\n};\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\n return {\n canInvokeOperation: operation =>\n operation.kind === undefined\n ? operation.exposure === undefined || operation.exposure === 'bridge'\n : operation.kind !== 'graph' && operation.exposure === 'bridge',\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 taskEndpoint = operationTaskEndpoint(options);\n const buildRuntimeAction = <TInput, TData>(\n operation: OperationBridge.BridgedOperationLike<TInput, TData>,\n ) => createFetchBridgeAction(endpoint, operation);\n\n return {\n name: 'fetch',\n ...(taskEndpoint\n ? {\n getTaskSnapshot: (ref: TaskRunIdentity) => fetchTaskSnapshot(taskEndpoint, ref),\n }\n : {}),\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
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B,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;YAEzE,OAAO,cAAc,CAAC;gBACpB,MAAM,EAAE,MAAiE;gBACzE,KAAK,EAAE,IAAI,CAAC,KAAgB;gBAC5B,GAAG,EAAE,IAAI,CAAC,GAAG;gBACb,MAAM,EAAE,8BAA8B;aACvC,CAAQ,CAAC;QACZ,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,QAAQ,EAAE,SAAS,CAAC;YACxD,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 { 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,7 +1,5 @@
|
|
|
1
|
-
import type { TaskRunIdentity, TaskSnapshot } from '@ontahi/core/runtime/contracts';
|
|
2
1
|
import { type AnyOperationBridgeAdapter, type CheckDomainOperationPermissionBridgeAction, type RunDomainOperationBridgeAction } from './operation-bridge.js';
|
|
3
2
|
export declare const createNextActionOperationBridgeAdapter: (bridgeAction: RunDomainOperationBridgeAction, options?: {
|
|
4
3
|
checkPermissionAction?: CheckDomainOperationPermissionBridgeAction;
|
|
5
|
-
getTaskSnapshot?: <TResult = unknown>(ref: TaskRunIdentity) => Promise<TaskSnapshot<TResult>>;
|
|
6
4
|
}) => AnyOperationBridgeAdapter;
|
|
7
5
|
//# sourceMappingURL=operation-bridge-adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation-bridge-adapter.d.ts","sourceRoot":"","sources":["../../src/actions/operation-bridge-adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"operation-bridge-adapter.d.ts","sourceRoot":"","sources":["../../src/actions/operation-bridge-adapter.ts"],"names":[],"mappings":"AAIA,OAAO,EAIL,KAAK,yBAAyB,EAE9B,KAAK,0CAA0C,EAE/C,KAAK,8BAA8B,EACpC,MAAM,uBAAuB,CAAC;AAuB/B,eAAO,MAAM,sCAAsC,GACjD,cAAc,8BAA8B,EAC5C,UAAU;IACR,qBAAqB,CAAC,EAAE,0CAA0C,CAAC;CACpE,KACA,yBA8CF,CAAC"}
|
|
@@ -10,7 +10,6 @@ export const createNextActionOperationBridgeAdapter = (bridgeAction, options) =>
|
|
|
10
10
|
const buildRuntimeAction = (operation) => createRuntimeBridgeAction(bridgeAction, operation);
|
|
11
11
|
return {
|
|
12
12
|
name: 'next-action',
|
|
13
|
-
getTaskSnapshot: options?.getTaskSnapshot,
|
|
14
13
|
useBridgeAction: operation => useMemo(() => buildRuntimeAction(operation), [operation]),
|
|
15
14
|
useBridgeMutation: (operation, options) => {
|
|
16
15
|
const action = useMemo(() => buildRuntimeAction(operation), [operation]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation-bridge-adapter.js","sourceRoot":"","sources":["../../src/actions/operation-bridge-adapter.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"operation-bridge-adapter.js","sourceRoot":"","sources":["../../src/actions/operation-bridge-adapter.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,EACL,kCAAkC,EAClC,iCAAiC,EACjC,8BAA8B,GAM/B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAErE,MAAM,6BAA6B,GAAG,CACpC,SAA8C,EAC9C,MAA4C,EAC5C,EAAE,CACF,kCAAkC,CAAC,SAAS,EAAE,MAAM,EAAE;IACpD,YAAY,EAAE,SAAS,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,KAAK,QAAQ;CACzF,CAAC,CAAC;AAEL,MAAM,yBAAyB,GAAG,CAChC,YAA4C,EAC5C,SAA8C,EACR,EAAE,CACxC,6BAA6B,CAC3B,SAAS,EACT,iCAAiC,CAAC,YAAY,EAAE,SAAS,CAGxD,CACsC,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ACvE,CAAC;gBAED,OAAO,OAAO,CAAC,qBAAqB,CAAC;oBACnC,WAAW,EAAE,SAAS,CAAC,EAAE;oBACzB,KAAK;iBACN,CAAC,CAAC;YACL,CAAC;YACD,KAAK,EAAE,SAAS;YAChB,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 { useMemo } from 'react';\n\nimport {\n attachOperationBridgeActionRuntime,\n createDomainOperationBridgeAction,\n unwrapOperationInvocationValue,\n type AnyOperationBridgeAdapter,\n type BridgedOperationLike,\n type CheckDomainOperationPermissionBridgeAction,\n type OperationBridgeAction,\n type RunDomainOperationBridgeAction,\n} from './operation-bridge.js';\nimport { useServerMutation, useServerQuery } from './react-query.js';\n\nconst attachNextActionBridgeRuntime = <TInput, TData>(\n operation: BridgedOperationLike<TInput, TData>,\n action: OperationBridgeAction<TInput, TData>,\n) =>\n attachOperationBridgeActionRuntime(operation, action, {\n requiresAuth: operation.authority !== 'server' ? false : operation.exposure !== 'bridge',\n });\n\nconst createRuntimeBridgeAction = <TInput, TData>(\n bridgeAction: RunDomainOperationBridgeAction,\n operation: BridgedOperationLike<TInput, TData>,\n): OperationBridgeAction<TInput, TData> =>\n attachNextActionBridgeRuntime(\n operation,\n createDomainOperationBridgeAction(bridgeAction, operation) as OperationBridgeAction<\n TInput,\n TData\n >,\n ) as OperationBridgeAction<TInput, TData>;\n\nexport const createNextActionOperationBridgeAdapter = (\n bridgeAction: RunDomainOperationBridgeAction,\n options?: {\n checkPermissionAction?: CheckDomainOperationPermissionBridgeAction;\n },\n): AnyOperationBridgeAdapter => {\n const buildRuntimeAction = <TInput, TData>(operation: BridgedOperationLike<TInput, TData>) =>\n createRuntimeBridgeAction(bridgeAction, operation);\n\n return {\n name: 'next-action',\n useBridgeAction: operation =>\n useMemo(\n () => buildRuntimeAction(operation) as OperationBridgeAction<any, any>,\n [operation],\n ) as OperationBridgeAction<any, any>,\n useBridgeMutation: (operation, options) => {\n const action = useMemo(() => buildRuntimeAction(operation), [operation]);\n\n return useServerMutation(\n action as OperationBridgeAction<unknown, unknown>,\n options as Parameters<typeof useServerMutation<OperationBridgeAction<unknown, unknown>>>[1],\n ) as ReturnType<typeof useServerMutation<OperationBridgeAction<any, any>>>;\n },\n useBridgeQuery: (operation, args) => {\n const action = useMemo(() => buildRuntimeAction(operation), [operation]);\n\n return useServerQuery({\n action: action as 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: async (_input: undefined) => {\n if (!options?.checkPermissionAction) {\n throw new Error('No operation permission bridge action registered.');\n }\n\n return options.checkPermissionAction({\n operationId: operation.id,\n input,\n });\n },\n input: undefined,\n key: args?.queryKey ?? ['graph-permission', operation.id, input],\n }),\n };\n};\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ClientDomainOperationDeclaration, EntityViewAst } from '@ontahi/core/data-graph';
|
|
2
2
|
import { type ActionQueryKey } from '@ontahi/core/runtime/actions';
|
|
3
|
-
import type { OperationInvocationResult
|
|
3
|
+
import type { OperationInvocationResult } from '@ontahi/core/runtime/contracts';
|
|
4
4
|
import type { QueryKey, UseQueryResult } from '@tanstack/react-query';
|
|
5
5
|
import type { ActionResultLike, UseActionOptions, UseActionResult } from './use-action.js';
|
|
6
6
|
export type { OperationInvocationResult };
|
|
@@ -51,7 +51,6 @@ export type CheckDomainOperationPermissionBridgeAction = (input: {
|
|
|
51
51
|
}) => Promise<OperationBridgeActionResult<GraphPermission>>;
|
|
52
52
|
export type OperationBridgeAdapter<TAdapterName extends string = string> = {
|
|
53
53
|
name: TAdapterName;
|
|
54
|
-
getTaskSnapshot?: <TResult = unknown>(ref: TaskRunIdentity) => Promise<TaskSnapshot<TResult>>;
|
|
55
54
|
useBridgeAction: <TInput, TData>(operation: BridgedOperationLike<TInput, TData>) => OperationBridgeAction<TInput, TData>;
|
|
56
55
|
useBridgeMutation: <TInput, TData>(operation: BridgedOperationLike<TInput, TData>, options?: UseActionOptions<OperationBridgeAction<TInput, TData>> & {
|
|
57
56
|
invalidateOnSuccess?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation-bridge.d.ts","sourceRoot":"","sources":["../../src/actions/operation-bridge.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gCAAgC,EAChC,aAAa,EAEd,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"operation-bridge.d.ts","sourceRoot":"","sources":["../../src/actions/operation-bridge.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gCAAgC,EAChC,aAAa,EAEd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAEhF,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAE3F,YAAY,EAAE,yBAAyB,EAAE,CAAC;AAE1C,MAAM,MAAM,2BAA2B,CAAC,KAAK,IAAI,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC,GAAG;IAChF,IAAI,CAAC,EAAE,KAAK,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,qBAAqB,CAAC,MAAM,EAAE,KAAK,IAAI,CACjD,KAAK,EAAE,MAAM,KACV,OAAO,CAAC,2BAA2B,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAE5E,MAAM,MAAM,0BAA0B,CAAC,QAAQ,GAAG,OAAO,IAAI,OAAO,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CAAC,MAAM,EAAE,KAAK,CAAC,EAC9C,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,QAAQ,CAAC,EAAE,QAAQ,CAAC;KACrB,KACE,cAAc,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;AAEvE,eAAO,MAAM,+BAA+B,GAAI,MAAM,EAAE,KAAK,EAC3D,WAAW,oBAAoB,CAAC,MAAM,EAAE,KAAK,CAAC,4CACwC,CAAC;AAczF,eAAO,MAAM,8BAA8B,GAAI,MAAM,EAAE,KAAK,EAC1D,WAAW,oBAAoB,CAAC,MAAM,EAAE,KAAK,CAAC,EAC9C,OAAO,MAAM,KACZ,cASF,CAAC;AAEF,eAAO,MAAM,2CAA2C,GAAI,MAAM,EAAE,KAAK,EACvE,WAAW,oBAAoB,CAAC,MAAM,EAAE,KAAK,CAAC,EAC9C,OAAO,MAAM,KACZ,cAAc,EAMhB,CAAC;AAEF,eAAO,MAAM,iCAAiC,GAC3C,MAAM,EAAE,KAAK,EACZ,cAAc,8BAA8B,EAC5C,WAAW,oBAAoB,CAAC,MAAM,EAAE,KAAK,CAAC,KAC7C,qBAAqB,CAAC,MAAM,EAAE,KAAK,CAMwC,CAAC;AAEjF,eAAO,MAAM,kCAAkC,GAAI,MAAM,EAAE,KAAK,EAC9D,WAAW,oBAAoB,CAAC,MAAM,EAAE,KAAK,CAAC,EAC9C,QAAQ,qBAAqB,CAAC,MAAM,EAAE,KAAK,CAAC,EAC5C,SAAS;IACP,YAAY,EAAE,OAAO,CAAC;CACvB;;CAUC,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { normalizeEntityRefQueryInput } from '@ontahi/core/data-graph';
|
|
3
2
|
import { attachActionRuntime, getActionErrorMessage, hasActionError, } from '@ontahi/core/runtime/actions';
|
|
4
3
|
import { isRecord } from '@ontahi/core/value/object';
|
|
5
4
|
export class OperationInvocationResultError extends Error {
|
|
@@ -60,17 +59,15 @@ const resolveOperationBridgeQueryKeySegment = (segment, operation, input) => typ
|
|
|
60
59
|
})
|
|
61
60
|
: segment;
|
|
62
61
|
export const resolveOperationBridgeQueryKey = (operation, input) => {
|
|
63
|
-
const queryInput = normalizeEntityRefQueryInput(input, operation.inputRefs);
|
|
64
62
|
return [
|
|
65
63
|
operation.entityName,
|
|
66
64
|
operation.name,
|
|
67
65
|
...(operation.view ? [operation.view] : []),
|
|
68
|
-
...(operation.bridge?.query?.map(segment => resolveOperationBridgeQueryKeySegment(segment, operation,
|
|
66
|
+
...(operation.bridge?.query?.map(segment => resolveOperationBridgeQueryKeySegment(segment, operation, input)) ?? []),
|
|
69
67
|
];
|
|
70
68
|
};
|
|
71
69
|
export const resolveOperationBridgeInvalidationQueryKeys = (operation, input) => {
|
|
72
|
-
|
|
73
|
-
return (operation.bridge?.invalidate?.map(querySpec => querySpec.map(segment => resolveOperationBridgeQueryKeySegment(segment, operation, queryInput))) ?? []);
|
|
70
|
+
return (operation.bridge?.invalidate?.map(querySpec => querySpec.map(segment => resolveOperationBridgeQueryKeySegment(segment, operation, input))) ?? []);
|
|
74
71
|
};
|
|
75
72
|
export const createDomainOperationBridgeAction = (bridgeAction, operation) => (input) => bridgeAction({
|
|
76
73
|
operationId: operation.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation-bridge.js","sourceRoot":"","sources":["../../src/actions/operation-bridge.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAOb,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,GAEf,MAAM,8BAA8B,CAAC;AAMtC,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAoBrD,MAAM,OAAO,8BAAmD,SAAQ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,SAAS,CAAC,IAAI,CAAU;IAC/D,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,8BAA8B,CAAC,SAAS,EAAE,KAAe,CAAC;IAChF,oBAAoB,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAClC,2CAA2C,CAAC,SAAS,EAAE,KAAe,CAAC;CAC1E,CAAC,CAAC","sourcesContent":["'use client';\n\nimport type {\n ClientDomainOperationDeclaration,\n EntityViewAst,\n QueryKeySegment,\n} from '@ontahi/core/data-graph';\nimport { normalizeEntityRefQueryInput } from '@ontahi/core/data-graph';\nimport {\n attachActionRuntime,\n getActionErrorMessage,\n hasActionError,\n type ActionQueryKey,\n} from '@ontahi/core/runtime/actions';\nimport type {\n OperationInvocationResult,\n TaskRunIdentity,\n TaskSnapshot,\n} from '@ontahi/core/runtime/contracts';\nimport { isRecord } from '@ontahi/core/value/object';\nimport type { QueryKey, UseQueryResult } from '@tanstack/react-query';\n\nimport type { ActionResultLike, UseActionOptions, UseActionResult } from './use-action.js';\n\nexport type { OperationInvocationResult };\n\nexport type OperationBridgeActionResult<TData> = Omit<ActionResultLike, 'data'> & {\n data?: TData;\n};\n\nexport type OperationBridgeAction<TInput, TData> = (\n input: TInput,\n) => Promise<OperationBridgeActionResult<OperationInvocationResult<TData>>>;\n\nexport type OperationInvocationFailure<TFailure = unknown> = Exclude<\n OperationInvocationResult<unknown, TFailure>,\n { ok: true }\n>;\n\nexport class OperationInvocationResultError<TFailure = unknown> extends Error {\n readonly name = 'OperationInvocationResultError';\n declare readonly cause?: unknown;\n\n constructor(readonly result: OperationInvocationFailure<TFailure>) {\n super(result.message);\n if (result.kind === 'failed') {\n Object.defineProperty(this, 'cause', {\n configurable: true,\n value: result.failure,\n });\n }\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n ...(this.cause === undefined ? {} : { cause: this.cause }),\n result: this.result,\n };\n }\n}\n\nexport const isOperationInvocationResult = <TData = unknown, TFailure = unknown>(\n value: unknown,\n): value is OperationInvocationResult<TData, TFailure> =>\n isRecord(value) && typeof value.ok === 'boolean' && typeof value.kind === 'string';\n\nexport const operationBridgeErrored = (message: string): OperationInvocationResult => ({\n ok: false,\n kind: 'errored',\n executed: 'unknown',\n message,\n});\n\nexport const toOperationInvocationResult = <TData>(\n result: OperationBridgeActionResult<OperationInvocationResult<TData>>,\n): OperationInvocationResult<TData> => {\n if (hasActionError(result)) {\n return operationBridgeErrored(\n getActionErrorMessage(result),\n ) as OperationInvocationResult<TData>;\n }\n\n if (isOperationInvocationResult<TData>(result.data)) {\n return result.data;\n }\n\n if ('data' in result) {\n return {\n ok: true,\n kind: 'success',\n value: result.data as TData,\n };\n }\n\n return operationBridgeErrored(\n 'Graph operation bridge returned an invalid response.',\n ) as OperationInvocationResult<TData>;\n};\n\nexport const unwrapOperationInvocationValue = <TData>(\n result: OperationInvocationResult<TData>,\n): TData => {\n if (result.ok) {\n return result.value;\n }\n\n throw new OperationInvocationResultError(result);\n};\n\nexport type BridgedOperationLike<TInput, TData> = ClientDomainOperationDeclaration<\n TInput,\n TData\n> & {\n id: string;\n entityName: string;\n name: string;\n view?: EntityViewAst;\n};\n\nexport type RunDomainOperationBridgeAction = (input: {\n operationId: string;\n input: unknown;\n view?: EntityViewAst;\n}) => Promise<ActionResultLike>;\n\nexport type GraphPermission =\n | {\n allowed: true;\n }\n | {\n allowed: false;\n reason: string;\n message: string;\n };\n\nexport type CheckDomainOperationPermissionBridgeAction = (input: {\n operationId: string;\n input: unknown;\n}) => Promise<OperationBridgeActionResult<GraphPermission>>;\n\nexport type OperationBridgeAdapter<TAdapterName extends string = string> = {\n name: TAdapterName;\n getTaskSnapshot?: <TResult = unknown>(ref: TaskRunIdentity) => Promise<TaskSnapshot<TResult>>;\n useBridgeAction: <TInput, TData>(\n operation: BridgedOperationLike<TInput, TData>,\n ) => OperationBridgeAction<TInput, TData>;\n useBridgeMutation: <TInput, TData>(\n operation: BridgedOperationLike<TInput, TData>,\n options?: UseActionOptions<OperationBridgeAction<TInput, TData>> & {\n invalidateOnSuccess?: boolean;\n },\n ) => UseActionResult<OperationBridgeAction<TInput, TData>>;\n useBridgeQuery: <TInput, TData>(\n operation: BridgedOperationLike<TInput, TData>,\n args: {\n input: TInput;\n key: QueryKey;\n },\n ) => UseQueryResult<TData, Error>;\n usePermission: <TInput, TData>(\n operation: BridgedOperationLike<TInput, TData>,\n input: TInput,\n options?: {\n enabled?: boolean;\n queryKey?: QueryKey;\n },\n ) => UseQueryResult<GraphPermission, Error>;\n};\n\nexport type AnyOperationBridgeAdapter = OperationBridgeAdapter<string>;\n\nexport const resolveOperationBridgeQuerySpec = <TInput, TData>(\n operation: BridgedOperationLike<TInput, TData>,\n) => [operation.entityName, operation.name, ...(operation.bridge?.query ?? [])] as const;\n\nconst resolveOperationBridgeQueryKeySegment = <TInput, TData>(\n segment: QueryKeySegment<TInput>,\n operation: BridgedOperationLike<TInput, TData>,\n input: TInput,\n) =>\n typeof segment === 'function'\n ? segment(input, {\n input,\n operation,\n })\n : segment;\n\nexport const resolveOperationBridgeQueryKey = <TInput, TData>(\n operation: BridgedOperationLike<TInput, TData>,\n input: TInput,\n): ActionQueryKey => {\n const queryInput = normalizeEntityRefQueryInput(input, operation.inputRefs);\n\n return [\n operation.entityName,\n operation.name,\n ...(operation.view ? [operation.view] : []),\n ...(operation.bridge?.query?.map(segment =>\n resolveOperationBridgeQueryKeySegment(segment, operation, queryInput),\n ) ?? []),\n ];\n};\n\nexport const resolveOperationBridgeInvalidationQueryKeys = <TInput, TData>(\n operation: BridgedOperationLike<TInput, TData>,\n input: TInput,\n): ActionQueryKey[] => {\n const queryInput = normalizeEntityRefQueryInput(input, operation.inputRefs);\n\n return (\n operation.bridge?.invalidate?.map(querySpec =>\n querySpec.map(segment =>\n resolveOperationBridgeQueryKeySegment(segment, operation, queryInput),\n ),\n ) ?? []\n );\n};\n\nexport const createDomainOperationBridgeAction =\n <TInput, TData>(\n bridgeAction: RunDomainOperationBridgeAction,\n operation: BridgedOperationLike<TInput, TData>,\n ): OperationBridgeAction<TInput, TData> =>\n (input: TInput) =>\n bridgeAction({\n operationId: operation.id,\n input,\n ...(operation.view ? { view: operation.view } : {}),\n }) as Promise<OperationBridgeActionResult<OperationInvocationResult<TData>>>;\n\nexport const attachOperationBridgeActionRuntime = <TInput, TData>(\n operation: BridgedOperationLike<TInput, TData>,\n action: OperationBridgeAction<TInput, TData>,\n options: {\n requiresAuth: boolean;\n },\n) =>\n attachActionRuntime(action, {\n feature: operation.entityName,\n actionName: operation.name,\n requiresAuth: options.requiresAuth,\n queryKeyPrefix: [operation.entityName, operation.name] as const,\n getQueryKey: input => resolveOperationBridgeQueryKey(operation, input as TInput),\n getAffectedQueryKeys: ({ input }) =>\n resolveOperationBridgeInvalidationQueryKeys(operation, input as TInput),\n });\n"]}
|
|
1
|
+
{"version":3,"file":"operation-bridge.js","sourceRoot":"","sources":["../../src/actions/operation-bridge.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAOb,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,GAEf,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAoBrD,MAAM,OAAO,8BAAmD,SAAQ,KAAK;IAI3E,YAAqB,MAA4C;QAC/D,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QADH,WAAM,GAAN,MAAM,CAAsC;QAHxD,SAAI,GAAG,gCAAgC,CAAC;QAK/C,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE;gBACnC,YAAY,EAAE,IAAI;gBAClB,KAAK,EAAE,MAAM,CAAC,OAAO;aACtB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,GAAG,CA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,CAAC;AAEF,MAAM,CAAC,MAAM,iCAAiC,GAC5C,CACE,YAA4C,EAC5C,SAA8C,EACR,EAAE,CAC1C,CAAC,KAAa,EAAE,EAAE,CAChB,YAAY,CAAC;IACX,WAAW,EAAE,SAAS,CAAC,EAAE;IACzB,KAAK;IACL,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;CACpD,CAA2E,CAAC;AAEjF,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAChD,SAA8C,EAC9C,MAA4C,EAC5C,OAEC,EACD,EAAE,CACF,mBAAmB,CAAC,MAAM,EAAE;IAC1B,OAAO,EAAE,SAAS,CAAC,UAAU;IAC7B,UAAU,EAAE,SAAS,CAAC,IAAI;IAC1B,YAAY,EAAE,OAAO,CAAC,YAAY;IAClC,cAAc,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,SAAS,CAAC,IAAI,CAAU;IAC/D,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,8BAA8B,CAAC,SAAS,EAAE,KAAe,CAAC;IAChF,oBAAoB,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAClC,2CAA2C,CAAC,SAAS,EAAE,KAAe,CAAC;CAC1E,CAAC,CAAC","sourcesContent":["'use client';\n\nimport type {\n ClientDomainOperationDeclaration,\n EntityViewAst,\n QueryKeySegment,\n} from '@ontahi/core/data-graph';\nimport {\n attachActionRuntime,\n getActionErrorMessage,\n hasActionError,\n type ActionQueryKey,\n} from '@ontahi/core/runtime/actions';\nimport type { OperationInvocationResult } from '@ontahi/core/runtime/contracts';\nimport { isRecord } from '@ontahi/core/value/object';\nimport type { QueryKey, UseQueryResult } from '@tanstack/react-query';\n\nimport type { ActionResultLike, UseActionOptions, UseActionResult } from './use-action.js';\n\nexport type { OperationInvocationResult };\n\nexport type OperationBridgeActionResult<TData> = Omit<ActionResultLike, 'data'> & {\n data?: TData;\n};\n\nexport type OperationBridgeAction<TInput, TData> = (\n input: TInput,\n) => Promise<OperationBridgeActionResult<OperationInvocationResult<TData>>>;\n\nexport type OperationInvocationFailure<TFailure = unknown> = Exclude<\n OperationInvocationResult<unknown, TFailure>,\n { ok: true }\n>;\n\nexport class OperationInvocationResultError<TFailure = unknown> extends Error {\n readonly name = 'OperationInvocationResultError';\n declare readonly cause?: unknown;\n\n constructor(readonly result: OperationInvocationFailure<TFailure>) {\n super(result.message);\n if (result.kind === 'failed') {\n Object.defineProperty(this, 'cause', {\n configurable: true,\n value: result.failure,\n });\n }\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n ...(this.cause === undefined ? {} : { cause: this.cause }),\n result: this.result,\n };\n }\n}\n\nexport const isOperationInvocationResult = <TData = unknown, TFailure = unknown>(\n value: unknown,\n): value is OperationInvocationResult<TData, TFailure> =>\n isRecord(value) && typeof value.ok === 'boolean' && typeof value.kind === 'string';\n\nexport const operationBridgeErrored = (message: string): OperationInvocationResult => ({\n ok: false,\n kind: 'errored',\n executed: 'unknown',\n message,\n});\n\nexport const toOperationInvocationResult = <TData>(\n result: OperationBridgeActionResult<OperationInvocationResult<TData>>,\n): OperationInvocationResult<TData> => {\n if (hasActionError(result)) {\n return operationBridgeErrored(\n getActionErrorMessage(result),\n ) as OperationInvocationResult<TData>;\n }\n\n if (isOperationInvocationResult<TData>(result.data)) {\n return result.data;\n }\n\n if ('data' in result) {\n return {\n ok: true,\n kind: 'success',\n value: result.data as TData,\n };\n }\n\n return operationBridgeErrored(\n 'Graph operation bridge returned an invalid response.',\n ) as OperationInvocationResult<TData>;\n};\n\nexport const unwrapOperationInvocationValue = <TData>(\n result: OperationInvocationResult<TData>,\n): TData => {\n if (result.ok) {\n return result.value;\n }\n\n throw new OperationInvocationResultError(result);\n};\n\nexport type BridgedOperationLike<TInput, TData> = ClientDomainOperationDeclaration<\n TInput,\n TData\n> & {\n id: string;\n entityName: string;\n name: string;\n view?: EntityViewAst;\n};\n\nexport type RunDomainOperationBridgeAction = (input: {\n operationId: string;\n input: unknown;\n view?: EntityViewAst;\n}) => Promise<ActionResultLike>;\n\nexport type GraphPermission =\n | {\n allowed: true;\n }\n | {\n allowed: false;\n reason: string;\n message: string;\n };\n\nexport type CheckDomainOperationPermissionBridgeAction = (input: {\n operationId: string;\n input: unknown;\n}) => Promise<OperationBridgeActionResult<GraphPermission>>;\n\nexport type OperationBridgeAdapter<TAdapterName extends string = string> = {\n name: TAdapterName;\n useBridgeAction: <TInput, TData>(\n operation: BridgedOperationLike<TInput, TData>,\n ) => OperationBridgeAction<TInput, TData>;\n useBridgeMutation: <TInput, TData>(\n operation: BridgedOperationLike<TInput, TData>,\n options?: UseActionOptions<OperationBridgeAction<TInput, TData>> & {\n invalidateOnSuccess?: boolean;\n },\n ) => UseActionResult<OperationBridgeAction<TInput, TData>>;\n useBridgeQuery: <TInput, TData>(\n operation: BridgedOperationLike<TInput, TData>,\n args: {\n input: TInput;\n key: QueryKey;\n },\n ) => UseQueryResult<TData, Error>;\n usePermission: <TInput, TData>(\n operation: BridgedOperationLike<TInput, TData>,\n input: TInput,\n options?: {\n enabled?: boolean;\n queryKey?: QueryKey;\n },\n ) => UseQueryResult<GraphPermission, Error>;\n};\n\nexport type AnyOperationBridgeAdapter = OperationBridgeAdapter<string>;\n\nexport const resolveOperationBridgeQuerySpec = <TInput, TData>(\n operation: BridgedOperationLike<TInput, TData>,\n) => [operation.entityName, operation.name, ...(operation.bridge?.query ?? [])] as const;\n\nconst resolveOperationBridgeQueryKeySegment = <TInput, TData>(\n segment: QueryKeySegment<TInput>,\n operation: BridgedOperationLike<TInput, TData>,\n input: TInput,\n) =>\n typeof segment === 'function'\n ? segment(input, {\n input,\n operation,\n })\n : segment;\n\nexport const resolveOperationBridgeQueryKey = <TInput, TData>(\n operation: BridgedOperationLike<TInput, TData>,\n input: TInput,\n): ActionQueryKey => {\n return [\n operation.entityName,\n operation.name,\n ...(operation.view ? [operation.view] : []),\n ...(operation.bridge?.query?.map(segment =>\n resolveOperationBridgeQueryKeySegment(segment, operation, input),\n ) ?? []),\n ];\n};\n\nexport const resolveOperationBridgeInvalidationQueryKeys = <TInput, TData>(\n operation: BridgedOperationLike<TInput, TData>,\n input: TInput,\n): ActionQueryKey[] => {\n return (\n operation.bridge?.invalidate?.map(querySpec =>\n querySpec.map(segment => resolveOperationBridgeQueryKeySegment(segment, operation, input)),\n ) ?? []\n );\n};\n\nexport const createDomainOperationBridgeAction =\n <TInput, TData>(\n bridgeAction: RunDomainOperationBridgeAction,\n operation: BridgedOperationLike<TInput, TData>,\n ): OperationBridgeAction<TInput, TData> =>\n (input: TInput) =>\n bridgeAction({\n operationId: operation.id,\n input,\n ...(operation.view ? { view: operation.view } : {}),\n }) as Promise<OperationBridgeActionResult<OperationInvocationResult<TData>>>;\n\nexport const attachOperationBridgeActionRuntime = <TInput, TData>(\n operation: BridgedOperationLike<TInput, TData>,\n action: OperationBridgeAction<TInput, TData>,\n options: {\n requiresAuth: boolean;\n },\n) =>\n attachActionRuntime(action, {\n feature: operation.entityName,\n actionName: operation.name,\n requiresAuth: options.requiresAuth,\n queryKeyPrefix: [operation.entityName, operation.name] as const,\n getQueryKey: input => resolveOperationBridgeQueryKey(operation, input as TInput),\n getAffectedQueryKeys: ({ input }) =>\n resolveOperationBridgeInvalidationQueryKeys(operation, input as TInput),\n });\n"]}
|
package/dist/graph/context.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { type GraphClientCache, type ReflectedEntityDataReader, type ReflectedOperationDescriptor, type ReflectedOperationInvoker } from '@ontahi/core/data-graph';
|
|
1
|
+
import { type GraphClientCache, type OperationExecutionAffordance, type ReflectedEntityDataReader, type ReflectedRelatedEntityDataReader, type ReflectedOperationDescriptor, type ReflectedOperationInvoker } from '@ontahi/core/data-graph';
|
|
2
2
|
import { type ExecutionIdentity } from '@ontahi/core/runtime/identity';
|
|
3
|
+
import type { RuntimeTransport } from '@ontahi/core/runtime/protocol';
|
|
3
4
|
import { type ReactNode } from 'react';
|
|
4
5
|
import type { AnyOperationBridgeAdapter } from '../actions/index.js';
|
|
5
6
|
import type { ReactGraphExecutor } from './executor.js';
|
|
@@ -9,18 +10,23 @@ export type OntahiGraphProviderProps<TGraphRuntime = unknown, TReadOptions = unk
|
|
|
9
10
|
children: ReactNode;
|
|
10
11
|
runtime: TGraphRuntime;
|
|
11
12
|
graphExecutor?: ReactGraphExecutor<TReadOptions, TCommandOptions>;
|
|
13
|
+
runtimeTransport?: RuntimeTransport;
|
|
12
14
|
client?: OntahiGraphClient<TReadOptions, TCommandOptions> | false;
|
|
13
15
|
operationBridgeAdapters?: AnyOperationBridgeAdapter[];
|
|
14
16
|
reflectedEntityDataReader?: ReflectedEntityDataReader;
|
|
17
|
+
reflectedRelatedEntityDataReader?: ReflectedRelatedEntityDataReader;
|
|
15
18
|
reflectedOperationInvoker?: ReflectedOperationInvoker;
|
|
16
19
|
reflectedGraphOperations?: readonly ReflectedGraphOperationLike[];
|
|
17
20
|
clientCache?: GraphClientCache;
|
|
18
21
|
identity?: ExecutionIdentity;
|
|
19
22
|
};
|
|
20
|
-
export declare function OntahiGraphProvider<TGraphRuntime = unknown, TReadOptions = unknown, TCommandOptions = TReadOptions>({ children, runtime, graphExecutor, client, operationBridgeAdapters, reflectedEntityDataReader, reflectedOperationInvoker, reflectedGraphOperations, clientCache, identity, }: OntahiGraphProviderProps<TGraphRuntime, TReadOptions, TCommandOptions>): import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
export declare function OntahiGraphProvider<TGraphRuntime = unknown, TReadOptions = unknown, TCommandOptions = TReadOptions>({ children, runtime, graphExecutor, runtimeTransport, client, operationBridgeAdapters, reflectedEntityDataReader, reflectedRelatedEntityDataReader, reflectedOperationInvoker, reflectedGraphOperations, clientCache, identity, }: OntahiGraphProviderProps<TGraphRuntime, TReadOptions, TCommandOptions>): import("react/jsx-runtime").JSX.Element;
|
|
21
24
|
export declare const useExecutionIdentity: () => ExecutionIdentity;
|
|
22
25
|
export declare function useGraphRuntime<TGraphRuntime = unknown>(): TGraphRuntime;
|
|
23
26
|
export declare function useGraphExecutor<TReadOptions = unknown, TCommandOptions = TReadOptions>(): ReactGraphExecutor<TReadOptions, TCommandOptions>;
|
|
27
|
+
export declare function useGraphExecutorCapability<TReadOptions = unknown, TCommandOptions = TReadOptions>(): ReactGraphExecutor<TReadOptions, TCommandOptions> | undefined;
|
|
28
|
+
export declare const useRuntimeTransportCapability: () => RuntimeTransport | undefined;
|
|
29
|
+
export declare function useRuntimeTransport(): RuntimeTransport;
|
|
24
30
|
export declare function useGraphClientCache(): {
|
|
25
31
|
clear: () => void;
|
|
26
32
|
denormalizeOutput: <TValue>(descriptor: import("@ontahi/core/data-graph").GraphOutputDescriptor | undefined, value: TValue) => TValue;
|
|
@@ -43,8 +49,11 @@ export declare function useDefaultOperationBridgeAdapter(): AnyOperationBridgeAd
|
|
|
43
49
|
export declare function useHasOperationBridgeRuntime(): boolean;
|
|
44
50
|
export declare function useReflectedEntityDataReader(): ReflectedEntityDataReader;
|
|
45
51
|
export declare function useHasReflectedEntityDataReader(): boolean;
|
|
52
|
+
export declare function useReflectedRelatedEntityDataReader(): ReflectedRelatedEntityDataReader;
|
|
53
|
+
export declare const useHasReflectedRelatedEntityDataReader: () => boolean;
|
|
46
54
|
export declare function useReflectedOperationInvoker(): ReflectedOperationInvoker;
|
|
47
55
|
export declare function useHasReflectedOperationInvoker(): boolean;
|
|
48
56
|
export declare function useReflectedOperationSupport(): (operation: ReflectedOperationDescriptor) => boolean;
|
|
57
|
+
export declare function useReflectedOperationExecutionAffordance(operation: ReflectedOperationDescriptor): OperationExecutionAffordance | undefined;
|
|
49
58
|
export type { GraphClientCache };
|
|
50
59
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/graph/context.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KA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ED,eAAO,MAAM,6BAA6B,oCAAyD,CAAC;AAEpG,wBAAgB,mBAAmB,qBAMlC;AAED,wBAAgB,mBAAmB;;;;;;;;;;;;;;EAQlC;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
|
@@ -10,16 +10,20 @@ const GraphRuntimeContext = createContext(null);
|
|
|
10
10
|
const ExecutionIdentityContext = createContext(anonymousExecutionIdentity);
|
|
11
11
|
const GraphExecutorContext = createContext(null);
|
|
12
12
|
const GraphClientCacheContext = createContext(null);
|
|
13
|
+
const RuntimeTransportContext = createContext(null);
|
|
13
14
|
const OperationBridgeAdaptersContext = createContext(null);
|
|
14
15
|
const ReflectedEntityDataReaderContext = createContext(null);
|
|
16
|
+
const ReflectedRelatedEntityDataReaderContext = createContext(null);
|
|
15
17
|
const ReflectedOperationInvokerContext = createContext(null);
|
|
16
|
-
export function OntahiGraphProvider({ children, runtime, graphExecutor, client, operationBridgeAdapters, reflectedEntityDataReader, reflectedOperationInvoker, reflectedGraphOperations = noReflectedGraphOperations, clientCache, identity = anonymousExecutionIdentity, }) {
|
|
18
|
+
export function OntahiGraphProvider({ children, runtime, graphExecutor, runtimeTransport, client, operationBridgeAdapters, reflectedEntityDataReader, reflectedRelatedEntityDataReader, reflectedOperationInvoker, reflectedGraphOperations = noReflectedGraphOperations, clientCache, identity = anonymousExecutionIdentity, }) {
|
|
17
19
|
const [defaultGraphClient] = useState(() => createFetchGraphClient());
|
|
18
20
|
const [defaultClientCache] = useState(() => createGraphClientCache());
|
|
19
21
|
const graphClient = client === false ? undefined : (client ?? defaultGraphClient);
|
|
20
22
|
const resolvedGraphExecutor = graphExecutor ?? graphClient?.graphExecutor;
|
|
23
|
+
const resolvedRuntimeTransport = runtimeTransport ?? graphClient?.runtimeTransport;
|
|
21
24
|
const resolvedOperationBridgeAdapters = operationBridgeAdapters ?? graphClient?.operationBridgeAdapters ?? [];
|
|
22
25
|
const resolvedReflectedEntityDataReader = reflectedEntityDataReader ?? graphClient?.reflectedEntityDataReader;
|
|
26
|
+
const resolvedReflectedRelatedEntityDataReader = reflectedRelatedEntityDataReader ?? graphClient?.reflectedRelatedEntityDataReader;
|
|
23
27
|
const configuredReflectedOperationInvoker = reflectedOperationInvoker ?? graphClient?.reflectedOperationInvoker;
|
|
24
28
|
const graphClientCache = clientCache ?? defaultClientCache;
|
|
25
29
|
const bridgeAdapterMap = useMemo(() => new Map(resolvedOperationBridgeAdapters.map(adapter => [adapter.name, adapter])), [resolvedOperationBridgeAdapters]);
|
|
@@ -30,7 +34,7 @@ export function OntahiGraphProvider({ children, runtime, graphExecutor, client,
|
|
|
30
34
|
graphOperations: reflectedGraphOperations,
|
|
31
35
|
})
|
|
32
36
|
: (configuredReflectedOperationInvoker ?? null), [configuredReflectedOperationInvoker, reflectedGraphOperations, resolvedGraphExecutor]);
|
|
33
|
-
return (_jsx(ExecutionIdentityContext.Provider, { value: identity, children: _jsx(ReflectedOperationInvokerContext.Provider, { value: resolvedReflectedOperationInvoker, children: _jsx(ReflectedEntityDataReaderContext.Provider, { value: resolvedReflectedEntityDataReader ?? null, children: _jsx(OperationBridgeAdaptersContext.Provider, { value: bridgeAdapterMap, children: _jsx(GraphClientCacheContext.Provider, { value: graphClientCache, children: _jsx(GraphExecutorContext.Provider, { value: resolvedGraphExecutor ?? null, children: _jsx(GraphRuntimeContext.Provider, { value: runtime, children: children }) }) }) }) }) }) }));
|
|
37
|
+
return (_jsx(ExecutionIdentityContext.Provider, { value: identity, children: _jsx(ReflectedOperationInvokerContext.Provider, { value: resolvedReflectedOperationInvoker, children: _jsx(ReflectedRelatedEntityDataReaderContext.Provider, { value: resolvedReflectedRelatedEntityDataReader ?? null, children: _jsx(ReflectedEntityDataReaderContext.Provider, { value: resolvedReflectedEntityDataReader ?? null, children: _jsx(OperationBridgeAdaptersContext.Provider, { value: bridgeAdapterMap, children: _jsx(RuntimeTransportContext.Provider, { value: resolvedRuntimeTransport ?? null, children: _jsx(GraphClientCacheContext.Provider, { value: graphClientCache, children: _jsx(GraphExecutorContext.Provider, { value: resolvedGraphExecutor ?? null, children: _jsx(GraphRuntimeContext.Provider, { value: runtime, children: children }) }) }) }) }) }) }) }) }));
|
|
34
38
|
}
|
|
35
39
|
export const useExecutionIdentity = () => useContext(ExecutionIdentityContext);
|
|
36
40
|
export function useGraphRuntime() {
|
|
@@ -47,6 +51,17 @@ export function useGraphExecutor() {
|
|
|
47
51
|
}
|
|
48
52
|
return graphExecutor;
|
|
49
53
|
}
|
|
54
|
+
export function useGraphExecutorCapability() {
|
|
55
|
+
return (useContext(GraphExecutorContext) ?? undefined);
|
|
56
|
+
}
|
|
57
|
+
export const useRuntimeTransportCapability = () => useContext(RuntimeTransportContext) ?? undefined;
|
|
58
|
+
export function useRuntimeTransport() {
|
|
59
|
+
const transport = useRuntimeTransportCapability();
|
|
60
|
+
if (!transport) {
|
|
61
|
+
throw new Error('useRuntimeTransport requires an OntahiGraphProvider with runtimeTransport');
|
|
62
|
+
}
|
|
63
|
+
return transport;
|
|
64
|
+
}
|
|
50
65
|
export function useGraphClientCache() {
|
|
51
66
|
const clientCache = useContext(GraphClientCacheContext);
|
|
52
67
|
if (clientCache === null) {
|
|
@@ -96,6 +111,14 @@ export function useReflectedEntityDataReader() {
|
|
|
96
111
|
export function useHasReflectedEntityDataReader() {
|
|
97
112
|
return useContext(ReflectedEntityDataReaderContext) !== null;
|
|
98
113
|
}
|
|
114
|
+
export function useReflectedRelatedEntityDataReader() {
|
|
115
|
+
const reader = useContext(ReflectedRelatedEntityDataReaderContext);
|
|
116
|
+
if (reader === null) {
|
|
117
|
+
throw new Error('useReflectedRelatedEntityDataReader must be used within an OntahiGraphProvider with reflectedRelatedEntityDataReader');
|
|
118
|
+
}
|
|
119
|
+
return reader;
|
|
120
|
+
}
|
|
121
|
+
export const useHasReflectedRelatedEntityDataReader = () => useContext(ReflectedRelatedEntityDataReaderContext) !== null;
|
|
99
122
|
export function useReflectedOperationInvoker() {
|
|
100
123
|
const invoker = useContext(ReflectedOperationInvokerContext);
|
|
101
124
|
if (invoker === null) {
|
|
@@ -110,4 +133,8 @@ export function useReflectedOperationSupport() {
|
|
|
110
133
|
const invoker = useContext(ReflectedOperationInvokerContext);
|
|
111
134
|
return useCallback((operation) => Boolean(invoker && (invoker.canInvokeOperation?.(operation) ?? true)), [invoker]);
|
|
112
135
|
}
|
|
136
|
+
export function useReflectedOperationExecutionAffordance(operation) {
|
|
137
|
+
const invoker = useContext(ReflectedOperationInvokerContext);
|
|
138
|
+
return invoker?.getOperationExecutionAffordance?.(operation);
|
|
139
|
+
}
|
|
113
140
|
//# sourceMappingURL=context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/graph/context.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EACL,sBAAsB,GAKvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,0BAA0B,EAA0B,MAAM,+BAA+B,CAAC;AACnG,OAAO,EACL,aAAa,EACb,WAAW,EACX,UAAU,EACV,OAAO,EACP,QAAQ,EACR,oBAAoB,GAErB,M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KAAK,IAAI,CAAC;AAC/D,CAAC;AAED,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","sourcesContent":["'use client';\n\nimport {\n createGraphClientCache,\n type GraphClientCache,\n type ReflectedEntityDataReader,\n type ReflectedOperationDescriptor,\n type ReflectedOperationInvoker,\n} from '@ontahi/core/data-graph';\nimport { anonymousExecutionIdentity, type ExecutionIdentity } from '@ontahi/core/runtime/identity';\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 OperationBridgeAdaptersContext = createContext<Map<string, AnyOperationBridgeAdapter> | null>(\n null,\n);\nconst ReflectedEntityDataReaderContext = createContext<ReflectedEntityDataReader | 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 client?: OntahiGraphClient<TReadOptions, TCommandOptions> | false;\n operationBridgeAdapters?: AnyOperationBridgeAdapter[];\n reflectedEntityDataReader?: ReflectedEntityDataReader;\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 client,\n operationBridgeAdapters,\n reflectedEntityDataReader,\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 resolvedOperationBridgeAdapters =\n operationBridgeAdapters ?? graphClient?.operationBridgeAdapters ?? [];\n const resolvedReflectedEntityDataReader =\n reflectedEntityDataReader ?? graphClient?.reflectedEntityDataReader;\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 <ReflectedEntityDataReaderContext.Provider\n value={resolvedReflectedEntityDataReader ?? null}\n >\n <OperationBridgeAdaptersContext.Provider value={bridgeAdapterMap}>\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 </OperationBridgeAdaptersContext.Provider>\n </ReflectedEntityDataReaderContext.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 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 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 type { GraphClientCache };\n"]}
|
|
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,GAAG,aAAa,CAA0B,IAAI,CAAC,CAAC;AAC7E,MAAM,8BAA8B,GAAG,aAAa,CAClD,IAAI,CACL,CAAC;AACF,MAAM,gCAAgC,GAAG,aAAa,CAAmC,IAAI,CAAC,CAAC;AAC/F,MAAM,uCAAuC,GAC3C,aAAa,CAA0C,IAAI,CAAC,CAAC;AAC/D,MAAM,gCAAgC,GAAG,aAAa,CAAmC,IAAI,CAAC,CAAC;AAqB/F,MAAM,UAAU,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AAE,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"]}
|