@ontahi/react 0.1.0-alpha.4 → 0.1.0-alpha.6
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 +92 -2
- package/dist/actions/operation-bridge.d.ts.map +1 -1
- package/dist/actions/operation-bridge.js +1 -1
- package/dist/actions/operation-bridge.js.map +1 -1
- package/dist/graph/context.d.ts +6 -1
- package/dist/graph/context.d.ts.map +1 -1
- package/dist/graph/context.js +16 -6
- package/dist/graph/context.js.map +1 -1
- package/dist/graph/executor.d.ts +12 -7
- 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 +33 -0
- package/dist/graph/fetch-graph-client.d.ts.map +1 -0
- package/dist/graph/fetch-graph-client.js +50 -0
- package/dist/graph/fetch-graph-client.js.map +1 -0
- package/dist/graph/fetch-graph-read-executor.d.ts +5 -0
- package/dist/graph/fetch-graph-read-executor.d.ts.map +1 -0
- package/dist/graph/fetch-graph-read-executor.js +4 -0
- package/dist/graph/fetch-graph-read-executor.js.map +1 -0
- package/dist/graph/fetch-graph-runtime.d.ts +16 -0
- package/dist/graph/fetch-graph-runtime.d.ts.map +1 -0
- package/dist/graph/fetch-graph-runtime.js +61 -0
- package/dist/graph/fetch-graph-runtime.js.map +1 -0
- package/dist/graph/graph-hooks.d.ts +4 -2
- package/dist/graph/graph-hooks.d.ts.map +1 -1
- package/dist/graph/graph-hooks.js +59 -16
- 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 +2 -1
- package/dist/graph/operation-hooks.d.ts.map +1 -1
- package/dist/graph/operation-hooks.js +31 -13
- package/dist/graph/operation-hooks.js.map +1 -1
- package/dist/graph/operation-types.d.ts +7 -1
- package/dist/graph/operation-types.d.ts.map +1 -1
- package/dist/graph/operation-types.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -5,8 +5,98 @@ Non-visual React integration for Ontahi applications.
|
|
|
5
5
|
This package depends on `@ontahi/core`. It owns React hooks and bridge adapters that are generic to React clients:
|
|
6
6
|
|
|
7
7
|
1. `@ontahi/react/actions`: action execution hooks, React Query integration, and operation bridge adapters.
|
|
8
|
-
2. `@ontahi/react/graph`: graph runtime provider,
|
|
8
|
+
2. `@ontahi/react/graph`: graph runtime provider, Query and Command hooks, Fetch graph-read execution,
|
|
9
|
+
client cache hooks, and operation bridge adapter lookup hooks.
|
|
9
10
|
|
|
10
11
|
The generic action metadata and result protocol comes from `@ontahi/core/runtime/actions`; Next.js-specific transport remains in `@ontahi/runtime-nextjs`.
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
Application-specific graph declarations, domain entities, runtime assembly, and policy stay in the
|
|
14
|
+
host application. Reusable reflective UI lives in `@ontahi/explorer-react`; hosts contribute their
|
|
15
|
+
own routes, access control, theme/auth composition, and application-specific UI enrichments.
|
|
16
|
+
|
|
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. This README is the package-level reference.
|
|
19
|
+
|
|
20
|
+
Projectable Operations keep population on the server and shape in the caller:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
const TripList = Trip.view('TripList', { id: true, driver: { name: true } });
|
|
24
|
+
const operation = Trip.domain.available.as(TripList);
|
|
25
|
+
const result = useOperationQuery(operation, input);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
React cache identity includes the transported View AST. The View remains client-owned and does not
|
|
29
|
+
need a server registry entry.
|
|
30
|
+
|
|
31
|
+
Caller-authored Queries can use the remote graph-read protocol directly:
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
const TodoListItem = TodoItem.view('TodoListItem', { id: true, title: true });
|
|
35
|
+
const openTodos = TodoItem.all()
|
|
36
|
+
.where(todo => todo.completed.eq(false))
|
|
37
|
+
.as(TodoListItem);
|
|
38
|
+
|
|
39
|
+
<OntahiGraphProvider
|
|
40
|
+
runtime={{ name: 'browser' }}
|
|
41
|
+
identity={{ principal: session.principal ?? null, cacheScope: session.workspaceId }}
|
|
42
|
+
>
|
|
43
|
+
<TodoApp />
|
|
44
|
+
</OntahiGraphProvider>;
|
|
45
|
+
|
|
46
|
+
const todos = useGraphQuery(openTodos);
|
|
47
|
+
const total = useGraphQuery(openTodos.count());
|
|
48
|
+
const first = useGraphQuery(openTodos.first());
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`OntahiGraphProvider` installs a conventional same-origin Fetch client by default. It connects
|
|
52
|
+
graph reads to `/graph/reads`, Operations and task snapshots to `/operations`, and reflected
|
|
53
|
+
Explorer data to `/explorer/entities`. These capabilities are lazy: declaring the provider does
|
|
54
|
+
not issue a request until the application uses one of them.
|
|
55
|
+
|
|
56
|
+
Hosts can replace any individual capability through the existing provider props, install a
|
|
57
|
+
configured client with `client={createFetchGraphClient(...)}`, or set `client={false}` for a fully
|
|
58
|
+
explicit provider. Server routes, read policies, and authorization remain opt-in and authoritative;
|
|
59
|
+
the default removes client wiring, not the server security boundary.
|
|
60
|
+
|
|
61
|
+
The same client supports fluent execution outside React hooks:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
const client = createFetchGraphClient();
|
|
65
|
+
const Todo = client.graph.bindClientEntity(GeneratedTodo);
|
|
66
|
+
|
|
67
|
+
const rows = await runBrowserEffect(Todo.all().as(TodoListItem).run());
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The bound facade is a new value and retains the generated Entity's Views, Refs, and Domain
|
|
71
|
+
Operations. Its portable source facade and schema remain unchanged.
|
|
72
|
+
|
|
73
|
+
Generated client Entities expose portable `all()` and `where(...)` Query entry points. A Query
|
|
74
|
+
returns many rows by default; terminal `first()`, `one()`, `count()`, and `exists()` expressions
|
|
75
|
+
make the result contract explicit and let `useGraphQuery` select the executor method. `one()` is
|
|
76
|
+
strict cardinality, while `first()` may return `null`.
|
|
77
|
+
|
|
78
|
+
For transport-safe Queries, React derives a canonical key from the Entity, Selection, View,
|
|
79
|
+
ordering, limit, cardinality, and read intent. The key is also partitioned by the provider's
|
|
80
|
+
`ExecutionIdentity`. `principal` and optional JSON-safe `cacheScope` describe distributed client
|
|
81
|
+
state; they are not credentials and are never trusted for server authorization. The authoritative
|
|
82
|
+
runtime still derives its Principal from the request. Hosts should change identity when login,
|
|
83
|
+
logout, service identity, tenant, or workspace changes. An explicit `queryKey` remains available
|
|
84
|
+
for lower-level reads that cannot be encoded by the graph-read protocol, and the legacy explicit
|
|
85
|
+
`mode` API remains compatible.
|
|
86
|
+
|
|
87
|
+
First-class Operation invocations bind render-owned input without losing the declaration form:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
const createTodo = useOperation(TodoItem.domain.create);
|
|
91
|
+
const completeVisible = useOperation(TodoItem.domain.complete({ todos: visibleTodos }));
|
|
92
|
+
|
|
93
|
+
await createTodo.executeAsync(newTodo);
|
|
94
|
+
await completeVisible.executeAsync();
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The bound invocation always uses the latest render input. Passing the Operation declaration itself
|
|
98
|
+
keeps the lower-level reusable mutation form, where each execution supplies its input.
|
|
99
|
+
|
|
100
|
+
The Fetch executor sends only the canonical graph-read request. Credentials and other trusted
|
|
101
|
+
request state remain in Fetch initialization and are never embedded in the Query AST. Remote
|
|
102
|
+
Commands remain unsupported until the graph Command protocol and its policy boundary are defined.
|
|
@@ -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;AAEjC,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EACV,yBAAyB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;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,cAWF,CAAC;AAEF,eAAO,MAAM,2CAA2C,GAAI,MAAM,EAAE,KAAK,EACvE,WAAW,oBAAoB,CAAC,MAAM,EAAE,KAAK,CAAC,EAC9C,OAAO,MAAM,KACZ,cAAc,EAUhB,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,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { normalizeEntityRefQueryInput } from '@ontahi/core/data-graph';
|
|
3
3
|
import { attachActionRuntime, getActionErrorMessage, hasActionError, } from '@ontahi/core/runtime/actions';
|
|
4
|
+
import { isRecord } from '@ontahi/core/value/object';
|
|
4
5
|
export class OperationInvocationResultError extends Error {
|
|
5
6
|
constructor(result) {
|
|
6
7
|
super(result.message);
|
|
@@ -22,7 +23,6 @@ export class OperationInvocationResultError extends Error {
|
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
|
-
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
26
26
|
export const isOperationInvocationResult = (value) => isRecord(value) && typeof value.ok === 'boolean' && typeof value.kind === 'string';
|
|
27
27
|
export const operationBridgeErrored = (message) => ({
|
|
28
28
|
ok: false,
|
|
@@ -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;AAyBtC,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,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;YAC1D,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC;IACJ,CAAC;CACF;AAED,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CACpE,OAAO,KAAK,KAAK,QAAQ,IAAI,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,CACtE,CACF,IAAI,EAAE,CACR,CAAC;AACJ,CAAC,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 { 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 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\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\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","sourceR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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 { 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"]}
|
package/dist/graph/context.d.ts
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { type GraphClientCache, type ReflectedEntityDataReader, type ReflectedOperationDescriptor, type ReflectedOperationInvoker } from '@ontahi/core/data-graph';
|
|
2
|
+
import { type ExecutionIdentity } from '@ontahi/core/runtime/identity';
|
|
2
3
|
import { type ReactNode } from 'react';
|
|
3
4
|
import type { AnyOperationBridgeAdapter } from '../actions/index.js';
|
|
4
5
|
import type { ReactGraphExecutor } from './executor.js';
|
|
6
|
+
import { type OntahiGraphClient } from './fetch-graph-client.js';
|
|
5
7
|
import { type ReflectedGraphOperationLike } from './reflected-operation-invoker.js';
|
|
6
8
|
export type OntahiGraphProviderProps<TGraphRuntime = unknown, TReadOptions = unknown, TCommandOptions = TReadOptions> = {
|
|
7
9
|
children: ReactNode;
|
|
8
10
|
runtime: TGraphRuntime;
|
|
9
11
|
graphExecutor?: ReactGraphExecutor<TReadOptions, TCommandOptions>;
|
|
12
|
+
client?: OntahiGraphClient<TReadOptions, TCommandOptions> | false;
|
|
10
13
|
operationBridgeAdapters?: AnyOperationBridgeAdapter[];
|
|
11
14
|
reflectedEntityDataReader?: ReflectedEntityDataReader;
|
|
12
15
|
reflectedOperationInvoker?: ReflectedOperationInvoker;
|
|
13
16
|
reflectedGraphOperations?: readonly ReflectedGraphOperationLike[];
|
|
14
17
|
clientCache?: GraphClientCache;
|
|
18
|
+
identity?: ExecutionIdentity;
|
|
15
19
|
};
|
|
16
|
-
export declare function OntahiGraphProvider<TGraphRuntime = unknown, TReadOptions = unknown, TCommandOptions = TReadOptions>({ children, runtime, graphExecutor, operationBridgeAdapters, reflectedEntityDataReader, reflectedOperationInvoker, reflectedGraphOperations, clientCache, }: OntahiGraphProviderProps<TGraphRuntime, TReadOptions, TCommandOptions>): import("react/jsx-runtime").JSX.Element;
|
|
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;
|
|
21
|
+
export declare const useExecutionIdentity: () => ExecutionIdentity;
|
|
17
22
|
export declare function useGraphRuntime<TGraphRuntime = unknown>(): TGraphRuntime;
|
|
18
23
|
export declare function useGraphExecutor<TReadOptions = unknown, TCommandOptions = TReadOptions>(): ReactGraphExecutor<TReadOptions, TCommandOptions>;
|
|
19
24
|
export declare function useGraphClientCache(): {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/graph/context.tsx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BAAgB,EAAE,CAAC"}
|
package/dist/graph/context.js
CHANGED
|
@@ -1,28 +1,38 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { createGraphClientCache, } from '@ontahi/core/data-graph';
|
|
4
|
+
import { anonymousExecutionIdentity } from '@ontahi/core/runtime/identity';
|
|
4
5
|
import { createContext, useCallback, useContext, useMemo, useState, useSyncExternalStore, } from 'react';
|
|
6
|
+
import { createFetchGraphClient } from './fetch-graph-client.js';
|
|
5
7
|
import { createReflectedOperationInvoker, } from './reflected-operation-invoker.js';
|
|
6
8
|
const noReflectedGraphOperations = [];
|
|
7
9
|
const GraphRuntimeContext = createContext(null);
|
|
10
|
+
const ExecutionIdentityContext = createContext(anonymousExecutionIdentity);
|
|
8
11
|
const GraphExecutorContext = createContext(null);
|
|
9
12
|
const GraphClientCacheContext = createContext(null);
|
|
10
13
|
const OperationBridgeAdaptersContext = createContext(null);
|
|
11
14
|
const ReflectedEntityDataReaderContext = createContext(null);
|
|
12
15
|
const ReflectedOperationInvokerContext = createContext(null);
|
|
13
|
-
export function OntahiGraphProvider({ children, runtime, graphExecutor, operationBridgeAdapters
|
|
16
|
+
export function OntahiGraphProvider({ children, runtime, graphExecutor, client, operationBridgeAdapters, reflectedEntityDataReader, reflectedOperationInvoker, reflectedGraphOperations = noReflectedGraphOperations, clientCache, identity = anonymousExecutionIdentity, }) {
|
|
17
|
+
const [defaultGraphClient] = useState(() => createFetchGraphClient());
|
|
14
18
|
const [defaultClientCache] = useState(() => createGraphClientCache());
|
|
19
|
+
const graphClient = client === false ? undefined : (client ?? defaultGraphClient);
|
|
20
|
+
const resolvedGraphExecutor = graphExecutor ?? graphClient?.graphExecutor;
|
|
21
|
+
const resolvedOperationBridgeAdapters = operationBridgeAdapters ?? graphClient?.operationBridgeAdapters ?? [];
|
|
22
|
+
const resolvedReflectedEntityDataReader = reflectedEntityDataReader ?? graphClient?.reflectedEntityDataReader;
|
|
23
|
+
const configuredReflectedOperationInvoker = reflectedOperationInvoker ?? graphClient?.reflectedOperationInvoker;
|
|
15
24
|
const graphClientCache = clientCache ?? defaultClientCache;
|
|
16
|
-
const bridgeAdapterMap = useMemo(() => new Map(
|
|
25
|
+
const bridgeAdapterMap = useMemo(() => new Map(resolvedOperationBridgeAdapters.map(adapter => [adapter.name, adapter])), [resolvedOperationBridgeAdapters]);
|
|
17
26
|
const resolvedReflectedOperationInvoker = useMemo(() => reflectedGraphOperations.length > 0
|
|
18
27
|
? createReflectedOperationInvoker({
|
|
19
|
-
fallback:
|
|
20
|
-
graphExecutor,
|
|
28
|
+
fallback: configuredReflectedOperationInvoker,
|
|
29
|
+
graphExecutor: resolvedGraphExecutor,
|
|
21
30
|
graphOperations: reflectedGraphOperations,
|
|
22
31
|
})
|
|
23
|
-
: (
|
|
24
|
-
return (_jsx(ReflectedOperationInvokerContext.Provider, { value: resolvedReflectedOperationInvoker, children: _jsx(ReflectedEntityDataReaderContext.Provider, { value:
|
|
32
|
+
: (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 }) }) }) }) }) }) }));
|
|
25
34
|
}
|
|
35
|
+
export const useExecutionIdentity = () => useContext(ExecutionIdentityContext);
|
|
26
36
|
export function useGraphRuntime() {
|
|
27
37
|
const runtime = useContext(GraphRuntimeContext);
|
|
28
38
|
if (runtime === null) {
|
|
@@ -1 +1 @@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,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 {\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 {\n createReflectedOperationInvoker,\n type ReflectedGraphOperationLike,\n} from './reflected-operation-invoker.js';\n\nconst noReflectedGraphOperations: readonly ReflectedGraphOperationLike[] = [];\n\nconst GraphRuntimeContext = createContext<unknown | null>(null);\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 operationBridgeAdapters?: AnyOperationBridgeAdapter[];\n reflectedEntityDataReader?: ReflectedEntityDataReader;\n reflectedOperationInvoker?: ReflectedOperationInvoker;\n reflectedGraphOperations?: readonly ReflectedGraphOperationLike[];\n clientCache?: GraphClientCache;\n};\n\nexport function OntahiGraphProvider<\n TGraphRuntime = unknown,\n TReadOptions = unknown,\n TCommandOptions = TReadOptions,\n>({\n children,\n runtime,\n graphExecutor,\n operationBridgeAdapters = [],\n reflectedEntityDataReader,\n reflectedOperationInvoker,\n reflectedGraphOperations = noReflectedGraphOperations,\n clientCache,\n}: OntahiGraphProviderProps<TGraphRuntime, TReadOptions, TCommandOptions>) {\n const [defaultClientCache] = useState(() => createGraphClientCache());\n const graphClientCache = clientCache ?? defaultClientCache;\n const bridgeAdapterMap = useMemo(\n () => new Map(operationBridgeAdapters.map(adapter => [adapter.name, adapter])),\n [operationBridgeAdapters],\n );\n const resolvedReflectedOperationInvoker = useMemo(\n () =>\n reflectedGraphOperations.length > 0\n ? createReflectedOperationInvoker({\n fallback: reflectedOperationInvoker,\n graphExecutor,\n graphOperations: reflectedGraphOperations,\n })\n : (reflectedOperationInvoker ?? null),\n [graphExecutor, reflectedGraphOperations, reflectedOperationInvoker],\n );\n\n return (\n <ReflectedOperationInvokerContext.Provider value={resolvedReflectedOperationInvoker}>\n <ReflectedEntityDataReaderContext.Provider value={reflectedEntityDataReader ?? null}>\n <OperationBridgeAdaptersContext.Provider value={bridgeAdapterMap}>\n <GraphClientCacheContext.Provider value={graphClientCache}>\n <GraphExecutorContext.Provider value={graphExecutor ?? 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 );\n}\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,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,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,8BAA8B,GAAG,aAAa,CAClD,IAAI,CACL,CAAC;AACF,MAAM,gCAAgC,GAAG,aAAa,CAAmC,IAAI,CAAC,CAAC;AAC/F,MAAM,gCAAgC,GAAG,aAAa,CAAmC,IAAI,CAAC,CAAC;AAmB/F,MAAM,UAAU,mBAAmB,CAIjC,EACA,QAAQ,EACR,OAAO,EACP,aAAa,EACb,MAAM,EACN,uBAAuB,EACvB,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,GAAG,0BAA0B,EACrD,WAAW,EACX,QAAQ,GAA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O,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,4BAA4B;IAC1C,MAAM,QAAQ,GAAG,UAAU,CAAC,8BAA8B,CAAC,CAAC;IAC5D,OAAO,QAAQ,KAAK,IAAI,IAAI,QAAQ,CAAC,IAAI,GAAG,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,4BAA4B;IAC1C,MAAM,MAAM,GAAG,UAAU,CAAC,gCAAgC,CAAC,CAAC;IAE5D,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,wGAAwG,CACzG,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,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,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"]}
|
package/dist/graph/executor.d.ts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
import type { GraphCommandSpec, GraphOperationDeclaration, GraphSchemaLike, InferGraphSchemaClientInput, QueryOrView, QuerySpec } from '@ontahi/core/data-graph';
|
|
1
|
+
import type { GraphCommandSpec, GraphOperationDeclaration, GraphReadExpression, GraphReadIntent, GraphSchemaLike, InferGraphSchemaClientInput, QueryOrView, QuerySpec, ManyToManyRelationshipCommand, RelationshipCommand, RelationshipDelta } 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>;
|
|
5
5
|
run<TParams, TResult>(read: QueryOrView<TParams, TResult>, params: TParams, options?: TReadOptions): Promise<TResult[]>;
|
|
6
6
|
count<TParams, TResult>(read: QueryOrView<TParams, TResult>, params: TParams, options?: TReadOptions): Promise<number>;
|
|
7
7
|
runCommand<TResult = void>(command: GraphCommandSpec<any, any, TResult>, options?: TCommandOptions): Promise<TResult>;
|
|
8
|
+
runRelationshipCommand?(command: RelationshipCommand, options?: TCommandOptions): Promise<RelationshipDelta>;
|
|
9
|
+
runManyToManyRelationshipCommand?(command: ManyToManyRelationshipCommand, options?: TCommandOptions): Promise<RelationshipDelta>;
|
|
8
10
|
}
|
|
9
11
|
export type BuildableRead<TResult> = {
|
|
10
12
|
build: () => QuerySpec<any, TResult>;
|
|
11
13
|
};
|
|
12
|
-
|
|
13
|
-
export type
|
|
14
|
-
export type
|
|
14
|
+
type PlainGraphReadSource<TResult> = QueryOrView<any, TResult> | BuildableRead<TResult>;
|
|
15
|
+
export type GraphReadSource<TResult = unknown> = PlainGraphReadSource<TResult> | GraphReadExpression<PlainGraphReadSource<TResult>, GraphReadIntent, TResult>;
|
|
16
|
+
export type ReadParams<TRead> = TRead extends GraphReadExpression<infer TSource, any, any> ? ReadParams<TSource> : TRead extends QueryOrView<infer TParams, any> ? TParams : undefined;
|
|
17
|
+
export type ReadResult<TRead> = TRead extends GraphReadExpression<any, any, infer TResult> ? TResult : TRead extends QueryOrView<any, infer TResult> ? TResult : TRead extends BuildableRead<infer TResult> ? TResult : never;
|
|
15
18
|
export type GraphQueryMode = 'get' | 'run' | 'count' | 'exists';
|
|
16
|
-
|
|
17
|
-
export type
|
|
18
|
-
|
|
19
|
+
type GraphReadIntentData<TRead, TIntent extends GraphReadIntent> = TIntent extends 'count' ? number : TIntent extends 'exists' ? boolean : TIntent extends 'one' ? ReadResult<TRead> : ReadResult<TRead> | null;
|
|
20
|
+
export type GraphQueryData<TRead, TMode extends GraphQueryMode = 'run'> = TRead extends GraphReadExpression<any, infer TIntent, any> ? GraphReadIntentData<TRead, TIntent> : TMode extends 'get' ? ReadResult<TRead> | null : TMode extends 'run' ? ReadResult<TRead>[] : TMode extends 'count' ? number : boolean;
|
|
21
|
+
export type GraphQueryOptions<TRead, TMode extends GraphQueryMode = 'run', TReadOptions = unknown> = Omit<UseQueryOptions<GraphQueryData<TRead, TMode>, Error, GraphQueryData<TRead, TMode>, QueryKey>, 'queryKey' | 'queryFn'> & {
|
|
22
|
+
mode?: TRead extends GraphReadExpression<any, any, any> ? never : TMode;
|
|
19
23
|
params?: ReadParams<TRead>;
|
|
20
24
|
queryKey?: QueryKey;
|
|
21
25
|
runtimeOptions?: TReadOptions;
|
|
@@ -38,4 +42,5 @@ export type GraphCommandHookOptions<TResult, TVariables, TContext, TCommandOptio
|
|
|
38
42
|
runtimeOptions?: TCommandOptions;
|
|
39
43
|
invalidateQueryKeys?: QueryKey[];
|
|
40
44
|
};
|
|
45
|
+
export {};
|
|
41
46
|
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -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,eAAe,EACf,2BAA2B,EAC3B,WAAW,EACX,SAAS,
|
|
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,iBAAiB,EAClB,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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AA2B,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 GraphSchemaLike,\n InferGraphSchemaClientInput,\n QueryOrView,\n QuerySpec,\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}\n\nexport type BuildableRead<TResult> = {\n build: () => QuerySpec<any, TResult>;\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 RelationshipCommand,\n RelationshipDelta,\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<RelationshipDelta>;\n runManyToManyRelationshipCommand?(\n command: ManyToManyRelationshipCommand,\n options?: TCommandOptions,\n ): Promise<RelationshipDelta>;\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"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ReflectedEntityDataReader, ReflectedOperationInvoker, RemoteDataGraphError, RuntimeBoundDataGraphApi } from '@ontahi/core/data-graph';
|
|
2
|
+
import { type AnyOperationBridgeAdapter, type FetchOperationBridgeOptions } from '../actions/index.js';
|
|
3
|
+
import type { ReactGraphExecutor } from './executor.js';
|
|
4
|
+
import type { FetchGraphReadExecutorOptions } from './fetch-graph-read-executor.js';
|
|
5
|
+
export type FetchReflectedEntityDataReaderOptions = {
|
|
6
|
+
endpoint?: string;
|
|
7
|
+
fetch?: typeof globalThis.fetch;
|
|
8
|
+
};
|
|
9
|
+
export type OntahiGraphClient<TReadOptions = unknown, TCommandOptions = TReadOptions> = {
|
|
10
|
+
graph?: RuntimeBoundDataGraphApi<RemoteDataGraphError, TReadOptions, TCommandOptions, RemoteDataGraphError>;
|
|
11
|
+
graphExecutor?: ReactGraphExecutor<TReadOptions, TCommandOptions>;
|
|
12
|
+
operationBridgeAdapters?: AnyOperationBridgeAdapter[];
|
|
13
|
+
reflectedEntityDataReader?: ReflectedEntityDataReader;
|
|
14
|
+
reflectedOperationInvoker?: ReflectedOperationInvoker;
|
|
15
|
+
};
|
|
16
|
+
export type FetchGraphClient<TOptions = undefined> = OntahiGraphClient<TOptions, TOptions> & {
|
|
17
|
+
graph: RuntimeBoundDataGraphApi<RemoteDataGraphError, TOptions, TOptions, RemoteDataGraphError>;
|
|
18
|
+
graphExecutor: ReactGraphExecutor<TOptions, TOptions>;
|
|
19
|
+
};
|
|
20
|
+
export type FetchGraphClientOptions<TOptions = undefined> = {
|
|
21
|
+
graphRead?: false | FetchGraphReadExecutorOptions<TOptions>;
|
|
22
|
+
operations?: false | FetchOperationBridgeOptions;
|
|
23
|
+
reflectedEntityData?: false | FetchReflectedEntityDataReaderOptions;
|
|
24
|
+
};
|
|
25
|
+
export declare const createFetchReflectedEntityDataReader: ({ endpoint, fetch: fetchRequest, }?: FetchReflectedEntityDataReaderOptions) => ReflectedEntityDataReader;
|
|
26
|
+
export declare function createFetchGraphClient<TOptions = undefined>(): FetchGraphClient<TOptions>;
|
|
27
|
+
export declare function createFetchGraphClient<TOptions = undefined>(options: FetchGraphClientOptions<TOptions> & {
|
|
28
|
+
graphRead: false;
|
|
29
|
+
}): OntahiGraphClient<TOptions, TOptions>;
|
|
30
|
+
export declare function createFetchGraphClient<TOptions = undefined>(options: FetchGraphClientOptions<TOptions> & {
|
|
31
|
+
graphRead?: FetchGraphReadExecutorOptions<TOptions>;
|
|
32
|
+
}): FetchGraphClient<TOptions>;
|
|
33
|
+
//# sourceMappingURL=fetch-graph-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-graph-client.d.ts","sourceRoot":"","sources":["../../src/graph/fetch-graph-client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,yBAAyB,EAEzB,yBAAyB,EACzB,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAGL,KAAK,yBAAyB,EAC9B,KAAK,2BAA2B,EACjC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAGpF,MAAM,MAAM,qCAAqC,GAAG;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,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,CAAC;AACzC,wBAAgB,sBAAsB,CAAC,QAAQ,GAAG,SAAS,EACzD,OAAO,EAAE,uBAAuB,CAAC,QAAQ,CAAC,GAAG;IAC3C,SAAS,CAAC,EAAE,6BAA6B,CAAC,QAAQ,CAAC,CAAC;CACrD,GACA,gBAAgB,CAAC,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { createRuntimeBoundDataGraphApi } from '@ontahi/core/data-graph';
|
|
3
|
+
import { createFetchOperationBridgeAdapter, createFetchReflectedOperationInvoker, } from '../actions/index.js';
|
|
4
|
+
import { createFetchGraphReadCapability } from './fetch-graph-runtime.js';
|
|
5
|
+
const DEFAULT_OPERATIONS_ENDPOINT = '/operations';
|
|
6
|
+
const DEFAULT_TASKS_ENDPOINT = '/operations/tasks';
|
|
7
|
+
const DEFAULT_REFLECTED_ENTITY_DATA_ENDPOINT = '/explorer/entities';
|
|
8
|
+
const conventionalOperationOptions = (options) => options.mountPath === undefined
|
|
9
|
+
? {
|
|
10
|
+
endpoint: DEFAULT_OPERATIONS_ENDPOINT,
|
|
11
|
+
taskEndpoint: DEFAULT_TASKS_ENDPOINT,
|
|
12
|
+
...options,
|
|
13
|
+
}
|
|
14
|
+
: options;
|
|
15
|
+
export const createFetchReflectedEntityDataReader = ({ endpoint = DEFAULT_REFLECTED_ENTITY_DATA_ENDPOINT, fetch: fetchRequest = globalThis.fetch, } = {}) => ({
|
|
16
|
+
readEntityData: async (query) => {
|
|
17
|
+
const response = await fetchRequest(endpoint, {
|
|
18
|
+
method: 'POST',
|
|
19
|
+
headers: { 'content-type': 'application/json' },
|
|
20
|
+
credentials: 'same-origin',
|
|
21
|
+
body: JSON.stringify(query),
|
|
22
|
+
});
|
|
23
|
+
if (!response.ok) {
|
|
24
|
+
throw new Error(`Reflected entity data request failed with status ${response.status}.`);
|
|
25
|
+
}
|
|
26
|
+
return response.json();
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
export function createFetchGraphClient({ graphRead = {}, operations = {}, reflectedEntityData = {}, } = {}) {
|
|
30
|
+
const operationOptions = operations === false ? undefined : conventionalOperationOptions(operations);
|
|
31
|
+
const graphReadCapability = graphRead === false ? undefined : createFetchGraphReadCapability(graphRead);
|
|
32
|
+
return {
|
|
33
|
+
...(graphReadCapability
|
|
34
|
+
? {
|
|
35
|
+
graph: createRuntimeBoundDataGraphApi(() => graphReadCapability.runtime),
|
|
36
|
+
graphExecutor: graphReadCapability.graphExecutor,
|
|
37
|
+
}
|
|
38
|
+
: {}),
|
|
39
|
+
...(operationOptions
|
|
40
|
+
? {
|
|
41
|
+
operationBridgeAdapters: [createFetchOperationBridgeAdapter(operationOptions)],
|
|
42
|
+
reflectedOperationInvoker: createFetchReflectedOperationInvoker(operationOptions),
|
|
43
|
+
}
|
|
44
|
+
: {}),
|
|
45
|
+
...(reflectedEntityData === false
|
|
46
|
+
? {}
|
|
47
|
+
: { reflectedEntityDataReader: createFetchReflectedEntityDataReader(reflectedEntityData) }),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=fetch-graph-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-graph-client.js","sourceRoot":"","sources":["../../src/graph/fetch-graph-client.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AASb,OAAO,EAAE,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AAEzE,OAAO,EACL,iCAAiC,EACjC,oCAAoC,GAGrC,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AA+B1E,MAAM,2BAA2B,GAAG,aAAa,CAAC;AAClD,MAAM,sBAAsB,GAAG,mBAAmB,CAAC;AACnD,MAAM,sCAAsC,GAAG,oBAAoB,CAAC;AAEpE,MAAM,4BAA4B,GAAG,CACnC,OAAoC,EACP,EAAE,CAC/B,OAAO,CAAC,SAAS,KAAK,SAAS;IA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AC,mBAAmB,CAAC,OAAO,CAAC;gBACxE,aAAa,EAAE,mBAAmB,CAAC,aAAa;aACjD;YACH,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,gBAAgB;YAClB,CAAC,CAAC;gBACE,uBAAuB,EAAE,CAAC,iCAAiC,CAAC,gBAAgB,CAAC,CAAC;gBAC9E,yBAAyB,EAAE,oCAAoC,CAAC,gBAAgB,CAAC;aAClF;YACH,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,mBAAmB,KAAK,KAAK;YAC/B,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,yBAAyB,EAAE,oCAAoC,CAAC,mBAAmB,CAAC,EAAE,CAAC;KAC9F,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport type {\n ReflectedEntityDataReader,\n ReflectedEntityDataResult,\n ReflectedOperationInvoker,\n RemoteDataGraphError,\n RuntimeBoundDataGraphApi,\n} from '@ontahi/core/data-graph';\nimport { createRuntimeBoundDataGraphApi } from '@ontahi/core/data-graph';\n\nimport {\n createFetchOperationBridgeAdapter,\n createFetchReflectedOperationInvoker,\n type AnyOperationBridgeAdapter,\n type FetchOperationBridgeOptions,\n} from '../actions/index.js';\n\nimport type { ReactGraphExecutor } from './executor.js';\nimport type { FetchGraphReadExecutorOptions } from './fetch-graph-read-executor.js';\nimport { createFetchGraphReadCapability } from './fetch-graph-runtime.js';\n\nexport type FetchReflectedEntityDataReaderOptions = {\n endpoint?: string;\n fetch?: typeof globalThis.fetch;\n};\n\nexport type OntahiGraphClient<TReadOptions = unknown, TCommandOptions = TReadOptions> = {\n graph?: RuntimeBoundDataGraphApi<\n RemoteDataGraphError,\n TReadOptions,\n TCommandOptions,\n RemoteDataGraphError\n >;\n graphExecutor?: ReactGraphExecutor<TReadOptions, TCommandOptions>;\n operationBridgeAdapters?: AnyOperationBridgeAdapter[];\n reflectedEntityDataReader?: ReflectedEntityDataReader;\n reflectedOperationInvoker?: ReflectedOperationInvoker;\n};\n\nexport type FetchGraphClient<TOptions = undefined> = OntahiGraphClient<TOptions, TOptions> & {\n graph: RuntimeBoundDataGraphApi<RemoteDataGraphError, TOptions, TOptions, RemoteDataGraphError>;\n graphExecutor: ReactGraphExecutor<TOptions, TOptions>;\n};\n\nexport type FetchGraphClientOptions<TOptions = undefined> = {\n graphRead?: false | FetchGraphReadExecutorOptions<TOptions>;\n operations?: false | FetchOperationBridgeOptions;\n reflectedEntityData?: false | FetchReflectedEntityDataReaderOptions;\n};\n\nconst DEFAULT_OPERATIONS_ENDPOINT = '/operations';\nconst DEFAULT_TASKS_ENDPOINT = '/operations/tasks';\nconst DEFAULT_REFLECTED_ENTITY_DATA_ENDPOINT = '/explorer/entities';\n\nconst conventionalOperationOptions = (\n options: FetchOperationBridgeOptions,\n): FetchOperationBridgeOptions =>\n options.mountPath === undefined\n ? {\n endpoint: DEFAULT_OPERATIONS_ENDPOINT,\n taskEndpoint: DEFAULT_TASKS_ENDPOINT,\n ...options,\n }\n : options;\n\nexport const createFetchReflectedEntityDataReader = ({\n endpoint = DEFAULT_REFLECTED_ENTITY_DATA_ENDPOINT,\n fetch: fetchRequest = globalThis.fetch,\n}: FetchReflectedEntityDataReaderOptions = {}): ReflectedEntityDataReader => ({\n readEntityData: async query => {\n const response = await fetchRequest(endpoint, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n credentials: 'same-origin',\n body: JSON.stringify(query),\n });\n\n if (!response.ok) {\n throw new Error(`Reflected entity data request failed with status ${response.status}.`);\n }\n\n return response.json() as Promise<ReflectedEntityDataResult>;\n },\n});\n\nexport function createFetchGraphClient<TOptions = undefined>(): FetchGraphClient<TOptions>;\nexport function createFetchGraphClient<TOptions = undefined>(\n options: FetchGraphClientOptions<TOptions> & { graphRead: false },\n): OntahiGraphClient<TOptions, TOptions>;\nexport function createFetchGraphClient<TOptions = undefined>(\n options: FetchGraphClientOptions<TOptions> & {\n graphRead?: FetchGraphReadExecutorOptions<TOptions>;\n },\n): FetchGraphClient<TOptions>;\nexport function createFetchGraphClient<TOptions = undefined>({\n graphRead = {},\n operations = {},\n reflectedEntityData = {},\n}: FetchGraphClientOptions<TOptions> = {}): OntahiGraphClient<TOptions, TOptions> {\n const operationOptions =\n operations === false ? undefined : conventionalOperationOptions(operations);\n const graphReadCapability =\n graphRead === false ? undefined : createFetchGraphReadCapability(graphRead);\n\n return {\n ...(graphReadCapability\n ? {\n graph: createRuntimeBoundDataGraphApi(() => graphReadCapability.runtime),\n graphExecutor: graphReadCapability.graphExecutor,\n }\n : {}),\n ...(operationOptions\n ? {\n operationBridgeAdapters: [createFetchOperationBridgeAdapter(operationOptions)],\n reflectedOperationInvoker: createFetchReflectedOperationInvoker(operationOptions),\n }\n : {}),\n ...(reflectedEntityData === false\n ? {}\n : { reflectedEntityDataReader: createFetchReflectedEntityDataReader(reflectedEntityData) }),\n };\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ReactGraphExecutor } from './executor.js';
|
|
2
|
+
import { type FetchGraphReadExecutorOptions } from './fetch-graph-runtime.js';
|
|
3
|
+
export type { FetchGraphReadExecutorOptions } from './fetch-graph-runtime.js';
|
|
4
|
+
export declare const createFetchGraphReadExecutor: <TOptions = undefined>(options?: FetchGraphReadExecutorOptions<TOptions>) => ReactGraphExecutor<TOptions, TOptions>;
|
|
5
|
+
//# sourceMappingURL=fetch-graph-read-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-graph-read-executor.d.ts","sourceRoot":"","sources":["../../src/graph/fetch-graph-read-executor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAEL,KAAK,6BAA6B,EACnC,MAAM,0BAA0B,CAAC;AAElC,YAAY,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AAE9E,eAAO,MAAM,4BAA4B,GAAI,QAAQ,GAAG,SAAS,EAC/D,UAAS,6BAA6B,CAAC,QAAQ,CAAM,KACpD,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,CAA0D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-graph-read-executor.js","sourceRoot":"","sources":["../../src/graph/fetch-graph-read-executor.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAGb,OAAO,EACL,8BAA8B,GAE/B,MAAM,0BAA0B,CAAC;AAIlC,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,UAAmD,EAAE,EACb,EAAE,CAAC,8BAA8B,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC","sourcesContent":["'use client';\n\nimport type { ReactGraphExecutor } from './executor.js';\nimport {\n createFetchGraphReadCapability,\n type FetchGraphReadExecutorOptions,\n} from './fetch-graph-runtime.js';\n\nexport type { FetchGraphReadExecutorOptions } from './fetch-graph-runtime.js';\n\nexport const createFetchGraphReadExecutor = <TOptions = undefined>(\n options: FetchGraphReadExecutorOptions<TOptions> = {},\n): ReactGraphExecutor<TOptions, TOptions> => createFetchGraphReadCapability(options).graphExecutor;\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type DataGraphExecutionRuntime, type RemoteDataGraphError, type ManyToManyRelationshipCommandExecutionRuntime, type RelationshipCommandExecutionRuntime } from '@ontahi/core/data-graph';
|
|
2
|
+
import type { ReactGraphExecutor } from './executor.js';
|
|
3
|
+
export type FetchGraphReadExecutorOptions<TOptions = undefined> = {
|
|
4
|
+
endpoint?: string;
|
|
5
|
+
commandEndpoint?: string;
|
|
6
|
+
fetch?: typeof globalThis.fetch;
|
|
7
|
+
requestInit?: (options?: TOptions) => Omit<RequestInit, 'body' | 'method'>;
|
|
8
|
+
};
|
|
9
|
+
export type FetchGraphRuntime<TOptions = undefined> = DataGraphExecutionRuntime<RemoteDataGraphError, TOptions, TOptions, RemoteDataGraphError>;
|
|
10
|
+
export type FetchRelationshipRuntime<TOptions = undefined> = RelationshipCommandExecutionRuntime<RemoteDataGraphError, TOptions> & ManyToManyRelationshipCommandExecutionRuntime<RemoteDataGraphError, TOptions>;
|
|
11
|
+
export type FetchGraphReadCapability<TOptions = undefined> = {
|
|
12
|
+
runtime: FetchGraphRuntime<TOptions> & FetchRelationshipRuntime<TOptions>;
|
|
13
|
+
graphExecutor: ReactGraphExecutor<TOptions, TOptions>;
|
|
14
|
+
};
|
|
15
|
+
export declare const createFetchGraphReadCapability: <TOptions = undefined>({ endpoint, commandEndpoint, fetch: fetchRequest, requestInit, }?: FetchGraphReadExecutorOptions<TOptions>) => FetchGraphReadCapability<TOptions>;
|
|
16
|
+
//# sourceMappingURL=fetch-graph-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-graph-runtime.d.ts","sourceRoot":"","sources":["../../src/graph/fetch-graph-runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,yBAAyB,EAC9B,KAAK,oBAAoB,EAGzB,KAAK,6CAA6C,EAClD,KAAK,mCAAmC,EACzC,MAAM,yBAAyB,CAAC;AAGjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAExD,MAAM,MAAM,6BAA6B,CAAC,QAAQ,GAAG,SAAS,IAAI;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,WAAW,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,QAAQ,KAAK,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC;CAC5E,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,QAAQ,GAAG,SAAS,IAAI,yBAAyB,CAC7E,oBAAoB,EACpB,QAAQ,EACR,QAAQ,EACR,oBAAoB,CACrB,CAAC;AACF,MAAM,MAAM,wBAAwB,CAAC,QAAQ,GAAG,SAAS,IAAI,m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