@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/dist/graph/executor.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type { GraphCommandSpec, GraphOperationDeclaration, GraphReadExpression, GraphReadIntent, GraphSchemaLike, InferGraphSchemaClientInput, QueryOrView, QuerySpec, ManyToManyRelationshipCommand, RelationshipCommand,
|
|
1
|
+
import type { GraphCommandSpec, GraphOperationDeclaration, GraphReadExpression, GraphReadIntent, GraphSchemaLike, InferGraphSchemaClientInput, QueryOrView, QuerySpec, ManyToManyRelationshipCommand, RelationshipCommand, RelationshipCommandResult, EntityMutationCommand, EntityMutationDelta } from '@ontahi/core/data-graph';
|
|
2
2
|
import type { QueryKey, UseMutationOptions, UseQueryOptions } from '@tanstack/react-query';
|
|
3
3
|
export interface ReactGraphExecutor<TReadOptions = unknown, TCommandOptions = TReadOptions> {
|
|
4
4
|
get<TParams, TResult>(read: QueryOrView<TParams, TResult>, params: TParams, options?: TReadOptions): Promise<TResult | null>;
|
|
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<
|
|
9
|
-
runManyToManyRelationshipCommand?(command: ManyToManyRelationshipCommand, options?: TCommandOptions): Promise<
|
|
8
|
+
runRelationshipCommand?(command: RelationshipCommand, options?: TCommandOptions): Promise<RelationshipCommandResult>;
|
|
9
|
+
runManyToManyRelationshipCommand?(command: ManyToManyRelationshipCommand, options?: TCommandOptions): Promise<RelationshipCommandResult>;
|
|
10
|
+
runEntityMutationCommand?(command: EntityMutationCommand, options?: TCommandOptions): Promise<EntityMutationDelta>;
|
|
10
11
|
}
|
|
11
12
|
export type BuildableRead<TResult> = {
|
|
12
13
|
build: () => QuerySpec<any, TResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/graph/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,yBAAyB,EACzB,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,2BAA2B,EAC3B,WAAW,EACX,SAAS,EACT,6BAA6B,EAC7B,mBAAmB,EACnB,
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/graph/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,yBAAyB,EACzB,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,2BAA2B,EAC3B,WAAW,EACX,SAAS,EACT,6BAA6B,EAC7B,mBAAmB,EACnB,yBAAyB,EACzB,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,uBA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AO,CAAC,CACrB,GAAG;IACF,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,yBAAyB,CAAC,UAAU,IAAI,UAAU,SAAS;IACrE,KAAK,EAAE,MAAM,OAAO,SAAS,eAAe,CAAC;CAC9C,GACG,2BAA2B,CAAC,OAAO,CAAC,GACpC,UAAU,SAAS,yBAAyB,CAAC,MAAM,MAAM,EAAE,GAAG,CAAC,GAC7D,MAAM,GACN,KAAK,CAAC;AAEZ,MAAM,MAAM,oBAAoB,CAAC,UAAU,IAAI,UAAU,SAAS;IAChE,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,WAAW,CAAC,MAAM,OAAO,CAAC,CAAC;CACrD,GACG,OAAO,GACP,KAAK,CAAC;AAEV,MAAM,MAAM,uBAAuB,CACjC,OAAO,EACP,UAAU,EACV,QAAQ,EACR,eAAe,GAAG,OAAO,IACvB,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,YAAY,CAAC,GAAG;IACjF,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB,cAAc,CAAC,EAAE,eAAe,CAAC;IACjC,mBAAmB,CAAC,EAAE,QAAQ,EAAE,CAAC;CAClC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../src/graph/executor.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n GraphCommandSpec,\n GraphOperationDeclaration,\n GraphReadExpression,\n GraphReadIntent,\n GraphSchemaLike,\n InferGraphSchemaClientInput,\n QueryOrView,\n QuerySpec,\n ManyToManyRelationshipCommand,\n RelationshipCommand,\n
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../src/graph/executor.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n GraphCommandSpec,\n GraphOperationDeclaration,\n GraphReadExpression,\n GraphReadIntent,\n GraphSchemaLike,\n InferGraphSchemaClientInput,\n QueryOrView,\n QuerySpec,\n ManyToManyRelationshipCommand,\n RelationshipCommand,\n RelationshipCommandResult,\n EntityMutationCommand,\n EntityMutationDelta,\n} from '@ontahi/core/data-graph';\nimport type { QueryKey, UseMutationOptions, UseQueryOptions } from '@tanstack/react-query';\n\nexport interface ReactGraphExecutor<TReadOptions = unknown, TCommandOptions = TReadOptions> {\n get<TParams, TResult>(\n read: QueryOrView<TParams, TResult>,\n params: TParams,\n options?: TReadOptions,\n ): Promise<TResult | null>;\n run<TParams, TResult>(\n read: QueryOrView<TParams, TResult>,\n params: TParams,\n options?: TReadOptions,\n ): Promise<TResult[]>;\n count<TParams, TResult>(\n read: QueryOrView<TParams, TResult>,\n params: TParams,\n options?: TReadOptions,\n ): Promise<number>;\n runCommand<TResult = void>(\n command: GraphCommandSpec<any, any, TResult>,\n options?: TCommandOptions,\n ): Promise<TResult>;\n runRelationshipCommand?(\n command: RelationshipCommand,\n options?: TCommandOptions,\n ): Promise<RelationshipCommandResult>;\n runManyToManyRelationshipCommand?(\n command: ManyToManyRelationshipCommand,\n options?: TCommandOptions,\n ): Promise<RelationshipCommandResult>;\n runEntityMutationCommand?(\n command: EntityMutationCommand,\n options?: TCommandOptions,\n ): Promise<EntityMutationDelta>;\n}\n\nexport type BuildableRead<TResult> = {\n build: () => QuerySpec<any, TResult>;\n};\n\ntype PlainGraphReadSource<TResult> = QueryOrView<any, TResult> | BuildableRead<TResult>;\n\nexport type GraphReadSource<TResult = unknown> =\n | PlainGraphReadSource<TResult>\n | GraphReadExpression<PlainGraphReadSource<TResult>, GraphReadIntent, TResult>;\n\nexport type ReadParams<TRead> =\n TRead extends GraphReadExpression<infer TSource, any, any>\n ? ReadParams<TSource>\n : TRead extends QueryOrView<infer TParams, any>\n ? TParams\n : undefined;\n\nexport type ReadResult<TRead> =\n TRead extends GraphReadExpression<any, any, infer TResult>\n ? TResult\n : TRead extends QueryOrView<any, infer TResult>\n ? TResult\n : TRead extends BuildableRead<infer TResult>\n ? TResult\n : never;\n\nexport type GraphQueryMode = 'get' | 'run' | 'count' | 'exists';\n\ntype GraphReadIntentData<TRead, TIntent extends GraphReadIntent> = TIntent extends 'count'\n ? number\n : TIntent extends 'exists'\n ? boolean\n : TIntent extends 'one'\n ? ReadResult<TRead>\n : ReadResult<TRead> | null;\n\nexport type GraphQueryData<TRead, TMode extends GraphQueryMode = 'run'> =\n TRead extends GraphReadExpression<any, infer TIntent, any>\n ? GraphReadIntentData<TRead, TIntent>\n : TMode extends 'get'\n ? ReadResult<TRead> | null\n : TMode extends 'run'\n ? ReadResult<TRead>[]\n : TMode extends 'count'\n ? number\n : boolean;\n\nexport type GraphQueryOptions<\n TRead,\n TMode extends GraphQueryMode = 'run',\n TReadOptions = unknown,\n> = Omit<\n UseQueryOptions<GraphQueryData<TRead, TMode>, Error, GraphQueryData<TRead, TMode>, QueryKey>,\n 'queryKey' | 'queryFn'\n> & {\n mode?: TRead extends GraphReadExpression<any, any, any> ? never : TMode;\n params?: ReadParams<TRead>;\n queryKey?: QueryKey;\n runtimeOptions?: TReadOptions;\n};\n\nexport type CommandLike<TResult> =\n | GraphCommandSpec<any, any, TResult>\n | {\n build: () => GraphCommandSpec<any, any, TResult>;\n };\n\nexport type GraphCommandBuilder<TVariables, TResult> = (\n variables: TVariables,\n) => CommandLike<TResult>;\n\nexport type GraphOperationLike<TVariables, TResult> = GraphOperationDeclaration<\n TVariables,\n CommandLike<TResult>\n> & {\n id: string;\n};\n\nexport type GraphOperationClientInput<TOperation> = TOperation extends {\n input: infer TSchema extends GraphSchemaLike;\n}\n ? InferGraphSchemaClientInput<TSchema>\n : TOperation extends GraphOperationDeclaration<infer TInput, any>\n ? TInput\n : never;\n\nexport type GraphOperationResult<TOperation> = TOperation extends {\n run: (...args: any[]) => CommandLike<infer TResult>;\n}\n ? TResult\n : never;\n\nexport type GraphCommandHookOptions<\n TResult,\n TVariables,\n TContext,\n TCommandOptions = unknown,\n> = Omit<UseMutationOptions<TResult, Error, TVariables, TContext>, 'mutationFn'> & {\n mutationKey?: QueryKey;\n runtimeOptions?: TCommandOptions;\n invalidateQueryKeys?: QueryKey[];\n};\n"]}
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import type { ReflectedEntityDataReader, ReflectedOperationInvoker, RemoteDataGraphError, RuntimeBoundDataGraphApi } from '@ontahi/core/data-graph';
|
|
1
|
+
import type { ReflectedEntityDataReader, ReflectedRelatedEntityDataReader, ReflectedOperationInvoker, RemoteDataGraphError, RuntimeBoundDataGraphApi } from '@ontahi/core/data-graph';
|
|
2
|
+
import type { RuntimeTransport } from '@ontahi/core/runtime/protocol';
|
|
2
3
|
import { type AnyOperationBridgeAdapter, type FetchOperationBridgeOptions } from '../actions/index.js';
|
|
3
4
|
import type { ReactGraphExecutor } from './executor.js';
|
|
4
5
|
import type { FetchGraphReadExecutorOptions } from './fetch-graph-read-executor.js';
|
|
6
|
+
import { type FetchRuntimeTransportOptions } from './fetch-runtime-transport.js';
|
|
5
7
|
export type FetchReflectedEntityDataReaderOptions = {
|
|
6
8
|
endpoint?: string;
|
|
7
9
|
fetch?: typeof globalThis.fetch;
|
|
8
10
|
};
|
|
11
|
+
export type FetchReflectedRelatedEntityDataReaderOptions = FetchReflectedEntityDataReaderOptions;
|
|
9
12
|
export type OntahiGraphClient<TReadOptions = unknown, TCommandOptions = TReadOptions> = {
|
|
10
13
|
graph?: RuntimeBoundDataGraphApi<RemoteDataGraphError, TReadOptions, TCommandOptions, RemoteDataGraphError>;
|
|
11
14
|
graphExecutor?: ReactGraphExecutor<TReadOptions, TCommandOptions>;
|
|
15
|
+
runtimeTransport?: RuntimeTransport;
|
|
12
16
|
operationBridgeAdapters?: AnyOperationBridgeAdapter[];
|
|
13
17
|
reflectedEntityDataReader?: ReflectedEntityDataReader;
|
|
18
|
+
reflectedRelatedEntityDataReader?: ReflectedRelatedEntityDataReader;
|
|
14
19
|
reflectedOperationInvoker?: ReflectedOperationInvoker;
|
|
15
20
|
};
|
|
16
21
|
export type FetchGraphClient<TOptions = undefined> = OntahiGraphClient<TOptions, TOptions> & {
|
|
@@ -20,9 +25,12 @@ export type FetchGraphClient<TOptions = undefined> = OntahiGraphClient<TOptions,
|
|
|
20
25
|
export type FetchGraphClientOptions<TOptions = undefined> = {
|
|
21
26
|
graphRead?: false | FetchGraphReadExecutorOptions<TOptions>;
|
|
22
27
|
operations?: false | FetchOperationBridgeOptions;
|
|
28
|
+
runtimeTransport?: false | FetchRuntimeTransportOptions;
|
|
23
29
|
reflectedEntityData?: false | FetchReflectedEntityDataReaderOptions;
|
|
30
|
+
reflectedRelatedEntityData?: false | FetchReflectedRelatedEntityDataReaderOptions;
|
|
24
31
|
};
|
|
25
32
|
export declare const createFetchReflectedEntityDataReader: ({ endpoint, fetch: fetchRequest, }?: FetchReflectedEntityDataReaderOptions) => ReflectedEntityDataReader;
|
|
33
|
+
export declare const createFetchReflectedRelatedEntityDataReader: ({ endpoint, fetch: fetchRequest, }?: FetchReflectedRelatedEntityDataReaderOptions) => ReflectedRelatedEntityDataReader;
|
|
26
34
|
export declare function createFetchGraphClient<TOptions = undefined>(): FetchGraphClient<TOptions>;
|
|
27
35
|
export declare function createFetchGraphClient<TOptions = undefined>(options: FetchGraphClientOptions<TOptions> & {
|
|
28
36
|
graphRead: false;
|
|
@@ -1 +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;
|
|
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,gCAAgC,EAEhC,yBAAyB,EACzB,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,yBAAyB,C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AC,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,uBAAuB,CAAC,QAAQ,GAAG,SAAS,IAAI;IAC1D,SAAS,CAAC,EAAE,KAAK,GAAG,6BAA6B,CAAC,QAAQ,CAAC,CAAC;IAC5D,UAAU,CAAC,EAAE,KAAK,GAAG,2BAA2B,CAAC;IACjD,gBAAgB,CAAC,EAAE,KAAK,GAAG,4BAA4B,CAAC;IACxD,mBAAmB,CAAC,EAAE,KAAK,GAAG,qCAAqC,CAAC;IACpE,0BAA0B,CAAC,EAAE,KAAK,GAAG,4CAA4C,CAAC;CACnF,CAAC;AAqCF,eAAO,MAAM,oCAAoC,GAAI,qCAGlD,qCAA0C,KAAG,yBAE9C,CAAC;AAEH,eAAO,MAAM,2CAA2C,GAAI,qCAGzD,4CAAiD,KAAG,gCAErD,CAAC;AAEH,wBAAgB,sBAAsB,CAAC,QAAQ,GAAG,SAAS,KAAK,gBAAgB,CAAC,QAAQ,CAAC,CAAC;AAC3F,wBAAgB,sBAAsB,CAAC,QAAQ,GAAG,SAAS,EACzD,OAAO,EAAE,uBAAuB,CAAC,QAAQ,CAAC,GAAG;IAAE,SAAS,EAAE,KAAK,CAAA;CAAE,GAChE,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,CAAC,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"}
|
|
@@ -2,31 +2,35 @@
|
|
|
2
2
|
import { createRuntimeBoundDataGraphApi } from '@ontahi/core/data-graph';
|
|
3
3
|
import { createFetchOperationBridgeAdapter, createFetchReflectedOperationInvoker, } from '../actions/index.js';
|
|
4
4
|
import { createFetchGraphReadCapability } from './fetch-graph-runtime.js';
|
|
5
|
+
import { createFetchRuntimeTransport, } from './fetch-runtime-transport.js';
|
|
5
6
|
const DEFAULT_OPERATIONS_ENDPOINT = '/operations';
|
|
6
|
-
const DEFAULT_TASKS_ENDPOINT = '/operations/tasks';
|
|
7
7
|
const DEFAULT_REFLECTED_ENTITY_DATA_ENDPOINT = '/explorer/entities';
|
|
8
|
+
const DEFAULT_REFLECTED_RELATED_ENTITY_DATA_ENDPOINT = '/explorer/related-entities';
|
|
9
|
+
const postReflectedEntityDataQuery = async (endpoint, query, fetchRequest) => {
|
|
10
|
+
const response = await fetchRequest(endpoint, {
|
|
11
|
+
method: 'POST',
|
|
12
|
+
headers: { 'content-type': 'application/json' },
|
|
13
|
+
credentials: 'same-origin',
|
|
14
|
+
body: JSON.stringify(query),
|
|
15
|
+
});
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
throw new Error(`Reflected entity data request failed with status ${response.status}.`);
|
|
18
|
+
}
|
|
19
|
+
return response.json();
|
|
20
|
+
};
|
|
8
21
|
const conventionalOperationOptions = (options) => options.mountPath === undefined
|
|
9
22
|
? {
|
|
10
23
|
endpoint: DEFAULT_OPERATIONS_ENDPOINT,
|
|
11
|
-
taskEndpoint: DEFAULT_TASKS_ENDPOINT,
|
|
12
24
|
...options,
|
|
13
25
|
}
|
|
14
26
|
: options;
|
|
15
27
|
export const createFetchReflectedEntityDataReader = ({ endpoint = DEFAULT_REFLECTED_ENTITY_DATA_ENDPOINT, fetch: fetchRequest = globalThis.fetch, } = {}) => ({
|
|
16
|
-
readEntityData:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
readEntityData: query => postReflectedEntityDataQuery(endpoint, query, fetchRequest),
|
|
29
|
+
});
|
|
30
|
+
export const createFetchReflectedRelatedEntityDataReader = ({ endpoint = DEFAULT_REFLECTED_RELATED_ENTITY_DATA_ENDPOINT, fetch: fetchRequest = globalThis.fetch, } = {}) => ({
|
|
31
|
+
readRelatedEntityData: query => postReflectedEntityDataQuery(endpoint, query, fetchRequest),
|
|
28
32
|
});
|
|
29
|
-
export function createFetchGraphClient({ graphRead = {}, operations = {}, reflectedEntityData = {}, } = {}) {
|
|
33
|
+
export function createFetchGraphClient({ graphRead = {}, operations = {}, runtimeTransport = {}, reflectedEntityData = {}, reflectedRelatedEntityData = {}, } = {}) {
|
|
30
34
|
const operationOptions = operations === false ? undefined : conventionalOperationOptions(operations);
|
|
31
35
|
const graphReadCapability = graphRead === false ? undefined : createFetchGraphReadCapability(graphRead);
|
|
32
36
|
return {
|
|
@@ -36,6 +40,9 @@ export function createFetchGraphClient({ graphRead = {}, operations = {}, reflec
|
|
|
36
40
|
graphExecutor: graphReadCapability.graphExecutor,
|
|
37
41
|
}
|
|
38
42
|
: {}),
|
|
43
|
+
...(runtimeTransport === false
|
|
44
|
+
? {}
|
|
45
|
+
: { runtimeTransport: createFetchRuntimeTransport(runtimeTransport) }),
|
|
39
46
|
...(operationOptions
|
|
40
47
|
? {
|
|
41
48
|
operationBridgeAdapters: [createFetchOperationBridgeAdapter(operationOptions)],
|
|
@@ -45,6 +52,11 @@ export function createFetchGraphClient({ graphRead = {}, operations = {}, reflec
|
|
|
45
52
|
...(reflectedEntityData === false
|
|
46
53
|
? {}
|
|
47
54
|
: { reflectedEntityDataReader: createFetchReflectedEntityDataReader(reflectedEntityData) }),
|
|
55
|
+
...(reflectedRelatedEntityData === false
|
|
56
|
+
? {}
|
|
57
|
+
: {
|
|
58
|
+
reflectedRelatedEntityDataReader: createFetchReflectedRelatedEntityDataReader(reflectedRelatedEntityData),
|
|
59
|
+
}),
|
|
48
60
|
};
|
|
49
61
|
}
|
|
50
62
|
//# sourceMappingURL=fetch-graph-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-graph-client.js","sourceRoot":"","sources":["../../src/graph/fetch-graph-client.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"fetch-graph-client.js","sourceRoot":"","sources":["../../src/graph/fetch-graph-client.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAWb,OAAO,EAAE,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AAGzE,OAAO,EACL,iCAAiC,EACjC,oCAAoC,GAGrC,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAC1E,OAAO,EACL,2BAA2B,GAE5B,MAAM,8BAA8B,CAAC;AAqCtC,MAAM,2BAA2B,GAAG,aAAa,CAAC;AAClD,MAAM,sCAAsC,GAAG,oBAAoB,CAAC;AACpE,MAAM,8CAA8C,GAAG,4BAA4B,CAAC;AAEpF,MAAM,4BAA4B,GAAG,KAAK,EACxC,QAAgB,EAChB,KAE8D,EAC9D,YAAqC,EACrC,EAAE;IACF,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,QAAQ,EAAE;QAC5C,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/C,WAAW,EAAE,aAAa;QAC1B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;KAC5B,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,oDAAoD,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAC1F,CAAC;IAED,OAAO,QAAQ,CAAC,IAAI,EAAwC,CAAC;AAC/D,CAAC,CAAC;AAEF,MAAM,4BAA4B,GAAG,CACnC,OAAoC,EACP,EAAE,CAC/B,OAAO,CAAC,SAAS,KAAK,SAAS;IAC7B,CAAC,CAAC;QACE,QAAQ,EAAE,2BAA2B;QACrC,GAAG,OAAO;KACX;IACH,C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AC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,gBAAgB,EAAE,2BAA2B,CAAC,gBAAgB,CAAC,EAAE,CAAC;QACxE,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;QAC7F,GAAG,CAAC,0BAA0B,KAAK,KAAK;YACtC,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC;gBACE,gCAAgC,EAAE,2CAA2C,CAC3E,0BAA0B,CAC3B;aACF,CAAC;KACP,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport type {\n ReflectedEntityDataReader,\n ReflectedEntityDataResult,\n ReflectedRelatedEntityDataReader,\n ReflectedRelatedEntityDataQuery,\n ReflectedOperationInvoker,\n RemoteDataGraphError,\n RuntimeBoundDataGraphApi,\n} from '@ontahi/core/data-graph';\nimport { createRuntimeBoundDataGraphApi } from '@ontahi/core/data-graph';\nimport type { RuntimeTransport } from '@ontahi/core/runtime/protocol';\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';\nimport {\n createFetchRuntimeTransport,\n type FetchRuntimeTransportOptions,\n} from './fetch-runtime-transport.js';\n\nexport type FetchReflectedEntityDataReaderOptions = {\n endpoint?: string;\n fetch?: typeof globalThis.fetch;\n};\n\nexport type FetchReflectedRelatedEntityDataReaderOptions = FetchReflectedEntityDataReaderOptions;\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 runtimeTransport?: RuntimeTransport;\n operationBridgeAdapters?: AnyOperationBridgeAdapter[];\n reflectedEntityDataReader?: ReflectedEntityDataReader;\n reflectedRelatedEntityDataReader?: ReflectedRelatedEntityDataReader;\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 runtimeTransport?: false | FetchRuntimeTransportOptions;\n reflectedEntityData?: false | FetchReflectedEntityDataReaderOptions;\n reflectedRelatedEntityData?: false | FetchReflectedRelatedEntityDataReaderOptions;\n};\n\nconst DEFAULT_OPERATIONS_ENDPOINT = '/operations';\nconst DEFAULT_REFLECTED_ENTITY_DATA_ENDPOINT = '/explorer/entities';\nconst DEFAULT_REFLECTED_RELATED_ENTITY_DATA_ENDPOINT = '/explorer/related-entities';\n\nconst postReflectedEntityDataQuery = async (\n endpoint: string,\n query:\n | ReflectedRelatedEntityDataQuery\n | Parameters<ReflectedEntityDataReader['readEntityData']>[0],\n fetchRequest: typeof globalThis.fetch,\n) => {\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\nconst conventionalOperationOptions = (\n options: FetchOperationBridgeOptions,\n): FetchOperationBridgeOptions =>\n options.mountPath === undefined\n ? {\n endpoint: DEFAULT_OPERATIONS_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: query => postReflectedEntityDataQuery(endpoint, query, fetchRequest),\n});\n\nexport const createFetchReflectedRelatedEntityDataReader = ({\n endpoint = DEFAULT_REFLECTED_RELATED_ENTITY_DATA_ENDPOINT,\n fetch: fetchRequest = globalThis.fetch,\n}: FetchReflectedRelatedEntityDataReaderOptions = {}): ReflectedRelatedEntityDataReader => ({\n readRelatedEntityData: query => postReflectedEntityDataQuery(endpoint, query, fetchRequest),\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 runtimeTransport = {},\n reflectedEntityData = {},\n reflectedRelatedEntityData = {},\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 ...(runtimeTransport === false\n ? {}\n : { runtimeTransport: createFetchRuntimeTransport(runtimeTransport) }),\n ...(operationOptions\n ? {\n operationBridgeAdapters: [createFetchOperationBridgeAdapter(operationOptions)],\n reflectedOperationInvoker: createFetchReflectedOperationInvoker(operationOptions),\n }\n : {}),\n ...(reflectedEntityData === false\n ? {}\n : { reflectedEntityDataReader: createFetchReflectedEntityDataReader(reflectedEntityData) }),\n ...(reflectedRelatedEntityData === false\n ? {}\n : {\n reflectedRelatedEntityDataReader: createFetchReflectedRelatedEntityDataReader(\n reflectedRelatedEntityData,\n ),\n }),\n };\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type DataGraphExecutionRuntime, type RemoteDataGraphError, type ManyToManyRelationshipCommandExecutionRuntime, type RelationshipCommandExecutionRuntime } from '@ontahi/core/data-graph';
|
|
1
|
+
import { type DataGraphExecutionRuntime, type EntityMutationCommandExecutionRuntime, type RemoteDataGraphError, type ManyToManyRelationshipCommandExecutionRuntime, type RelationshipCommandExecutionRuntime } from '@ontahi/core/data-graph';
|
|
2
2
|
import type { ReactGraphExecutor } from './executor.js';
|
|
3
3
|
export type FetchGraphReadExecutorOptions<TOptions = undefined> = {
|
|
4
4
|
endpoint?: string;
|
|
@@ -8,8 +8,9 @@ export type FetchGraphReadExecutorOptions<TOptions = undefined> = {
|
|
|
8
8
|
};
|
|
9
9
|
export type FetchGraphRuntime<TOptions = undefined> = DataGraphExecutionRuntime<RemoteDataGraphError, TOptions, TOptions, RemoteDataGraphError>;
|
|
10
10
|
export type FetchRelationshipRuntime<TOptions = undefined> = RelationshipCommandExecutionRuntime<RemoteDataGraphError, TOptions> & ManyToManyRelationshipCommandExecutionRuntime<RemoteDataGraphError, TOptions>;
|
|
11
|
+
export type FetchEntityMutationRuntime<TOptions = undefined> = EntityMutationCommandExecutionRuntime<RemoteDataGraphError, TOptions>;
|
|
11
12
|
export type FetchGraphReadCapability<TOptions = undefined> = {
|
|
12
|
-
runtime: FetchGraphRuntime<TOptions> & FetchRelationshipRuntime<TOptions>;
|
|
13
|
+
runtime: FetchGraphRuntime<TOptions> & FetchRelationshipRuntime<TOptions> & FetchEntityMutationRuntime<TOptions>;
|
|
13
14
|
graphExecutor: ReactGraphExecutor<TOptions, TOptions>;
|
|
14
15
|
};
|
|
15
16
|
export declare const createFetchGraphReadCapability: <TOptions = undefined>({ endpoint, commandEndpoint, fetch: fetchRequest, requestInit, }?: FetchGraphReadExecutorOptions<TOptions>) => FetchGraphReadCapability<TOptions>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-graph-runtime.d.ts","sourceRoot":"","sources":["../../src/graph/fetch-graph-runtime.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"fetch-graph-runtime.d.ts","sourceRoot":"","sources":["../../src/graph/fetch-graph-runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,yBAAyB,EAC9B,KAAK,qCAAqC,EAC1C,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,mCAAmC,CAC9F,oBAAoB,EACpB,QAAQ,CACT,GACC,6CAA6C,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAC;AAChF,MAAM,MAAM,0BAA0B,CAAC,QAAQ,GAAG,SAAS,IACzD,qCAAqC,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAC;AAExE,MAAM,MAAM,wBAAwB,CAAC,QAAQ,GAAG,SAAS,IAAI;IAC3D,OAAO,EAAE,iBAAiB,CAAC,QAAQ,CAAC,GAClC,wBAAwB,CAAC,QAAQ,CAAC,GAClC,0BAA0B,CAAC,QAAQ,CAAC,CAAC;IACvC,aAAa,EAAE,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;CACvD,CAAC;AAKF,eAAO,MAAM,8BAA8B,GAAI,QAAQ,GAAG,SAAS,EAAE,mEAKlE,6BAA6B,CAAC,QAAQ,CAAM,KAAG,wBAAwB,CAAC,QAAQ,CA8DlF,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { createRemoteDataGraphRuntime, isGraphCommandProtocolError, isGraphReadProtocolError, } from '@ontahi/core/data-graph';
|
|
2
|
+
import { createRemoteDataGraphRuntime, isGraphCommandRejection, isGraphCommandProtocolError, isGraphReadProtocolError, } from '@ontahi/core/data-graph';
|
|
3
3
|
import { runBrowserEffect } from '@ontahi/core/runtime/browser';
|
|
4
4
|
const DEFAULT_GRAPH_READ_ENDPOINT = '/graph/reads';
|
|
5
5
|
const DEFAULT_GRAPH_COMMAND_ENDPOINT = '/graph/commands';
|
|
@@ -40,7 +40,9 @@ export const createFetchGraphReadCapability = ({ endpoint = DEFAULT_GRAPH_READ_E
|
|
|
40
40
|
body: JSON.stringify(request),
|
|
41
41
|
});
|
|
42
42
|
const payload = await response.json();
|
|
43
|
-
if (!response.ok &&
|
|
43
|
+
if (!response.ok &&
|
|
44
|
+
!isGraphCommandProtocolError(payload) &&
|
|
45
|
+
!isGraphCommandRejection(payload)) {
|
|
44
46
|
throw new Error(`Graph Command request failed with status ${response.status}.`);
|
|
45
47
|
}
|
|
46
48
|
return payload;
|
|
@@ -55,6 +57,7 @@ export const createFetchGraphReadCapability = ({ endpoint = DEFAULT_GRAPH_READ_E
|
|
|
55
57
|
runCommand: (command, options) => runBrowserEffect(runtime.runCommand(command, options)),
|
|
56
58
|
runRelationshipCommand: (command, options) => runBrowserEffect(runtime.runRelationshipCommand(command, options)),
|
|
57
59
|
runManyToManyRelationshipCommand: (command, options) => runBrowserEffect(runtime.runManyToManyRelationshipCommand(command, options)),
|
|
60
|
+
runEntityMutationCommand: (command, options) => runBrowserEffect(runtime.runEntityMutationCommand(command, options)),
|
|
58
61
|
},
|
|
59
62
|
};
|
|
60
63
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-graph-runtime.js","sourceRoot":"","sources":["../../src/graph/fetch-graph-runtime.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EACL,4BAA4B,EAC5B,2BAA2B,EAC3B,wBAAwB,
|
|
1
|
+
{"version":3,"file":"fetch-graph-runtime.js","sourceRoot":"","sources":["../../src/graph/fetch-graph-runtime.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EACL,4BAA4B,EAC5B,uBAAuB,EACvB,2BAA2B,EAC3B,wBAAwB,GAQzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAgChE,MAAM,2BAA2B,GAAG,cAAc,CAAC;AACnD,MAAM,8BAA8B,GAAG,iBAAiB,CAAC;AAEzD,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAuB,EACnE,QAAQ,GAAG,2BAA2B,EACtC,eAAe,GAAG,8BAA8B,EAChD,KAAK,EAAE,YAAY,GAAG,UAAU,CAAC,KAAK,EACtC,WAAW,MACgC,EAAE,EAAsC,EAAE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EAAE,OAAO,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACxF,sBAAsB,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAC3C,gBAAgB,CAAC,OAAO,CAAC,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACpE,gCAAgC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CACrD,gBAAgB,CAAC,OAAO,CAAC,gCAAgC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC9E,wBAAwB,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAC7C,gBAAgB,CAAC,OAAO,CAAC,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;SACvE;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["'use client';\n\nimport {\n createRemoteDataGraphRuntime,\n isGraphCommandRejection,\n isGraphCommandProtocolError,\n isGraphReadProtocolError,\n type DataGraphExecutionRuntime,\n type EntityMutationCommandExecutionRuntime,\n type RemoteDataGraphError,\n type RemoteGraphCommandTransport,\n type RemoteGraphReadTransport,\n type ManyToManyRelationshipCommandExecutionRuntime,\n type RelationshipCommandExecutionRuntime,\n} from '@ontahi/core/data-graph';\nimport { runBrowserEffect } from '@ontahi/core/runtime/browser';\n\nimport type { ReactGraphExecutor } from './executor.js';\n\nexport type FetchGraphReadExecutorOptions<TOptions = undefined> = {\n endpoint?: string;\n commandEndpoint?: string;\n fetch?: typeof globalThis.fetch;\n requestInit?: (options?: TOptions) => Omit<RequestInit, 'body' | 'method'>;\n};\n\nexport type FetchGraphRuntime<TOptions = undefined> = DataGraphExecutionRuntime<\n RemoteDataGraphError,\n TOptions,\n TOptions,\n RemoteDataGraphError\n>;\nexport type FetchRelationshipRuntime<TOptions = undefined> = RelationshipCommandExecutionRuntime<\n RemoteDataGraphError,\n TOptions\n> &\n ManyToManyRelationshipCommandExecutionRuntime<RemoteDataGraphError, TOptions>;\nexport type FetchEntityMutationRuntime<TOptions = undefined> =\n EntityMutationCommandExecutionRuntime<RemoteDataGraphError, TOptions>;\n\nexport type FetchGraphReadCapability<TOptions = undefined> = {\n runtime: FetchGraphRuntime<TOptions> &\n FetchRelationshipRuntime<TOptions> &\n FetchEntityMutationRuntime<TOptions>;\n graphExecutor: ReactGraphExecutor<TOptions, TOptions>;\n};\n\nconst DEFAULT_GRAPH_READ_ENDPOINT = '/graph/reads';\nconst DEFAULT_GRAPH_COMMAND_ENDPOINT = '/graph/commands';\n\nexport const createFetchGraphReadCapability = <TOptions = undefined>({\n endpoint = DEFAULT_GRAPH_READ_ENDPOINT,\n commandEndpoint = DEFAULT_GRAPH_COMMAND_ENDPOINT,\n fetch: fetchRequest = globalThis.fetch,\n requestInit,\n}: FetchGraphReadExecutorOptions<TOptions> = {}): FetchGraphReadCapability<TOptions> => {\n const transport: RemoteGraphReadTransport<TOptions> = async (request, options) => {\n const init = requestInit?.(options) ?? {};\n const headers = new Headers(init.headers);\n if (!headers.has('content-type')) headers.set('content-type', 'application/json');\n\n const response = await fetchRequest(endpoint, {\n ...init,\n method: 'POST',\n headers,\n credentials: init.credentials ?? 'same-origin',\n body: JSON.stringify(request),\n });\n\n try {\n const payload: unknown = await response.json();\n if (!response.ok && !isGraphReadProtocolError(payload)) {\n throw new Error(`Graph read request failed with status ${response.status}.`);\n }\n return payload;\n } catch {\n throw new Error(`Graph read request failed with status ${response.status}.`);\n }\n };\n const commandTransport: RemoteGraphCommandTransport<TOptions> = async (request, options) => {\n const init = requestInit?.(options) ?? {};\n const headers = new Headers(init.headers);\n if (!headers.has('content-type')) headers.set('content-type', 'application/json');\n const response = await fetchRequest(commandEndpoint, {\n ...init,\n method: 'POST',\n headers,\n credentials: init.credentials ?? 'same-origin',\n body: JSON.stringify(request),\n });\n const payload: unknown = await response.json();\n if (\n !response.ok &&\n !isGraphCommandProtocolError(payload) &&\n !isGraphCommandRejection(payload)\n ) {\n throw new Error(`Graph Command request failed with status ${response.status}.`);\n }\n return payload;\n };\n const runtime = createRemoteDataGraphRuntime({ transport, commandTransport });\n\n return {\n runtime,\n graphExecutor: {\n get: (read, params, options) => runBrowserEffect(runtime.get(read, params, options)),\n run: (read, params, options) => runBrowserEffect(runtime.run(read, params, options)),\n count: (read, params, options) => runBrowserEffect(runtime.count(read, params, options)),\n runCommand: (command, options) => runBrowserEffect(runtime.runCommand(command, options)),\n runRelationshipCommand: (command, options) =>\n runBrowserEffect(runtime.runRelationshipCommand(command, options)),\n runManyToManyRelationshipCommand: (command, options) =>\n runBrowserEffect(runtime.runManyToManyRelationshipCommand(command, options)),\n runEntityMutationCommand: (command, options) =>\n runBrowserEffect(runtime.runEntityMutationCommand(command, options)),\n },\n };\n};\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type DurableOperationObservationCapability, type RuntimeTransport } from '@ontahi/core/runtime/protocol';
|
|
2
|
+
export type FetchRuntimeTransportOptions = {
|
|
3
|
+
endpoint?: string;
|
|
4
|
+
fetch?: typeof globalThis.fetch;
|
|
5
|
+
requestId?: () => string;
|
|
6
|
+
requestInit?: () => Omit<RequestInit, 'body' | 'method' | 'signal'>;
|
|
7
|
+
durableOperation?: {
|
|
8
|
+
pollIntervalMs?: number;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export type FetchRuntimeTransport = RuntimeTransport & {
|
|
12
|
+
readonly durableOperation: DurableOperationObservationCapability;
|
|
13
|
+
};
|
|
14
|
+
export declare const createFetchRuntimeTransport: ({ endpoint, fetch: fetchRequest, requestId, requestInit, durableOperation, }?: FetchRuntimeTransportOptions) => FetchRuntimeTransport;
|
|
15
|
+
//# sourceMappingURL=fetch-runtime-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-runtime-transport.d.ts","sourceRoot":"","sources":["../../src/graph/fetch-runtime-transport.ts"],"names":[],"mappings":"AAGA,OAAO,EAML,KAAK,qCAAqC,EAE1C,KAAK,gBAAgB,EAEtB,MAAM,+BAA+B,CAAC;AAEvC,MAAM,MAAM,4BAA4B,GAAG;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,SAAS,CAAC,EAAE,MAAM,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC,CAAC;IACpE,gBAAgB,CAAC,EAAE;QACjB,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,GAAG;IACrD,QAAQ,CAAC,gBAAgB,EAAE,qCAAqC,CAAC;CAClE,CAAC;AAiCF,eAAO,MAAM,2BAA2B,GAAI,+EAMzC,4BAAiC,KAAG,qBAiEtC,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { createRuntimeProtocolRequest, isRuntimeProtocolError, parseDurableOperationProtocolResponse, parseRuntimeProtocolResponse, toDurableOperationProtocolRequest, } from '@ontahi/core/runtime/protocol';
|
|
3
|
+
const DEFAULT_RUNTIME_ENDPOINT = '/runtime';
|
|
4
|
+
const DEFAULT_POLL_INTERVAL_MS = 500;
|
|
5
|
+
const terminalTaskStatuses = new Set(['completed', 'failed', 'cancelled']);
|
|
6
|
+
let fallbackRequestSequence = 0;
|
|
7
|
+
const defaultRequestId = () => globalThis.crypto?.randomUUID?.() ??
|
|
8
|
+
`ontahi-runtime-${Date.now()}-${(fallbackRequestSequence += 1)}`;
|
|
9
|
+
const waitForNextInspection = (intervalMs, signal) => {
|
|
10
|
+
if (signal?.aborted)
|
|
11
|
+
return Promise.resolve(false);
|
|
12
|
+
if (intervalMs === 0)
|
|
13
|
+
return Promise.resolve(true);
|
|
14
|
+
return new Promise(resolve => {
|
|
15
|
+
let settled = false;
|
|
16
|
+
const finish = (shouldContinue) => {
|
|
17
|
+
if (settled)
|
|
18
|
+
return;
|
|
19
|
+
settled = true;
|
|
20
|
+
clearTimeout(timeout);
|
|
21
|
+
signal?.removeEventListener('abort', abort);
|
|
22
|
+
resolve(shouldContinue);
|
|
23
|
+
};
|
|
24
|
+
const abort = () => finish(false);
|
|
25
|
+
const timeout = setTimeout(() => finish(true), intervalMs);
|
|
26
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
export const createFetchRuntimeTransport = ({ endpoint = DEFAULT_RUNTIME_ENDPOINT, fetch: fetchRequest = globalThis.fetch, requestId = defaultRequestId, requestInit, durableOperation = {}, } = {}) => {
|
|
30
|
+
const pollIntervalMs = durableOperation.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
31
|
+
if (!Number.isFinite(pollIntervalMs) || pollIntervalMs < 0) {
|
|
32
|
+
throw new TypeError('Durable Operation poll interval must be a non-negative finite number.');
|
|
33
|
+
}
|
|
34
|
+
const request = async (runtimeRequest, options) => {
|
|
35
|
+
const init = requestInit?.() ?? {};
|
|
36
|
+
const headers = new Headers(init.headers);
|
|
37
|
+
if (!headers.has('content-type'))
|
|
38
|
+
headers.set('content-type', 'application/json');
|
|
39
|
+
const response = await fetchRequest(endpoint, {
|
|
40
|
+
...init,
|
|
41
|
+
method: 'POST',
|
|
42
|
+
headers,
|
|
43
|
+
credentials: init.credentials ?? 'same-origin',
|
|
44
|
+
body: JSON.stringify(runtimeRequest),
|
|
45
|
+
...(options?.signal ? { signal: options.signal } : {}),
|
|
46
|
+
});
|
|
47
|
+
const payload = await response.json().catch(() => null);
|
|
48
|
+
const parsed = parseRuntimeProtocolResponse(payload, runtimeRequest);
|
|
49
|
+
if (!parsed.success)
|
|
50
|
+
throw new Error(parsed.error.error.message);
|
|
51
|
+
if (!response.ok && !isRuntimeProtocolError(parsed.response)) {
|
|
52
|
+
throw new Error(`Runtime Protocol request failed with status ${response.status}.`);
|
|
53
|
+
}
|
|
54
|
+
return parsed.response;
|
|
55
|
+
};
|
|
56
|
+
const observe = async function* (run, options) {
|
|
57
|
+
while (!options?.signal?.aborted) {
|
|
58
|
+
const runtimeRequest = createRuntimeProtocolRequest({
|
|
59
|
+
id: requestId(),
|
|
60
|
+
family: 'durable.operation',
|
|
61
|
+
body: toDurableOperationProtocolRequest(run),
|
|
62
|
+
});
|
|
63
|
+
const runtimeResponse = await request(runtimeRequest, options);
|
|
64
|
+
if (isRuntimeProtocolError(runtimeResponse)) {
|
|
65
|
+
throw new Error(runtimeResponse.error.message);
|
|
66
|
+
}
|
|
67
|
+
const parsed = parseDurableOperationProtocolResponse(runtimeResponse.body);
|
|
68
|
+
if (!parsed.success)
|
|
69
|
+
throw new Error(parsed.error.error.message);
|
|
70
|
+
if (parsed.response.kind === 'protocol-error') {
|
|
71
|
+
throw new Error(parsed.response.error.message);
|
|
72
|
+
}
|
|
73
|
+
const snapshot = parsed.response.snapshot;
|
|
74
|
+
if (snapshot.taskId !== run.taskId || snapshot.runId !== run.runId) {
|
|
75
|
+
throw new Error('Durable Operation snapshot identity does not match the observed run.');
|
|
76
|
+
}
|
|
77
|
+
yield snapshot;
|
|
78
|
+
if (terminalTaskStatuses.has(snapshot.status))
|
|
79
|
+
return;
|
|
80
|
+
if (!(await waitForNextInspection(pollIntervalMs, options?.signal)))
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
request,
|
|
86
|
+
durableOperation: { observe },
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=fetch-runtime-transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-runtime-transport.js","sourceRoot":"","sources":["../../src/graph/fetch-runtime-transport.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAGb,OAAO,EACL,4BAA4B,EAC5B,sBAAsB,EACtB,qCAAqC,EACrC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jE,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;gBAC9C,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACjD,CAAC;YAED,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAiC,CAAC;YACnE,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,CAAC,MAAM,IAAI,QAAQ,CAAC,KAAK,KAAK,GAAG,CAAC,KAAK,EAAE,CAAC;gBACnE,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;YAC1F,CAAC;YACD,MAAM,QAAQ,CAAC;YACf,IAAI,oBAAoB,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAAE,OAAO;YACtD,IAAI,CAAC,CAAC,MAAM,qBAAqB,CAAC,cAAc,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;gBAAE,OAAO;QAC9E,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,OAAO;QACP,gBAAgB,EAAE,EAAE,OAAO,EAAE;KAC9B,CAAC;AACJ,CAAC,CAAC","sourcesContent":["'use client';\n\nimport type { TaskRunIdentity, TaskSnapshot } from '@ontahi/core/runtime/contracts';\nimport {\n createRuntimeProtocolRequest,\n isRuntimeProtocolError,\n parseDurableOperationProtocolResponse,\n parseRuntimeProtocolResponse,\n toDurableOperationProtocolRequest,\n type DurableOperationObservationCapability,\n type RuntimeProtocolRequestEnvelope,\n type RuntimeTransport,\n type RuntimeTransportRequestOptions,\n} from '@ontahi/core/runtime/protocol';\n\nexport type FetchRuntimeTransportOptions = {\n endpoint?: string;\n fetch?: typeof globalThis.fetch;\n requestId?: () => string;\n requestInit?: () => Omit<RequestInit, 'body' | 'method' | 'signal'>;\n durableOperation?: {\n pollIntervalMs?: number;\n };\n};\n\nexport type FetchRuntimeTransport = RuntimeTransport & {\n readonly durableOperation: DurableOperationObservationCapability;\n};\n\nconst DEFAULT_RUNTIME_ENDPOINT = '/runtime';\nconst DEFAULT_POLL_INTERVAL_MS = 500;\nconst terminalTaskStatuses = new Set(['completed', 'failed', 'cancelled']);\nlet fallbackRequestSequence = 0;\n\nconst defaultRequestId = () =>\n globalThis.crypto?.randomUUID?.() ??\n `ontahi-runtime-${Date.now()}-${(fallbackRequestSequence += 1)}`;\n\nconst waitForNextInspection = (\n intervalMs: number,\n signal: AbortSignal | undefined,\n): Promise<boolean> => {\n if (signal?.aborted) return Promise.resolve(false);\n if (intervalMs === 0) return Promise.resolve(true);\n\n return new Promise(resolve => {\n let settled = false;\n const finish = (shouldContinue: boolean) => {\n if (settled) return;\n settled = true;\n clearTimeout(timeout);\n signal?.removeEventListener('abort', abort);\n resolve(shouldContinue);\n };\n const abort = () => finish(false);\n const timeout = setTimeout(() => finish(true), intervalMs);\n signal?.addEventListener('abort', abort, { once: true });\n });\n};\n\nexport const createFetchRuntimeTransport = ({\n endpoint = DEFAULT_RUNTIME_ENDPOINT,\n fetch: fetchRequest = globalThis.fetch,\n requestId = defaultRequestId,\n requestInit,\n durableOperation = {},\n}: FetchRuntimeTransportOptions = {}): FetchRuntimeTransport => {\n const pollIntervalMs = durableOperation.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n if (!Number.isFinite(pollIntervalMs) || pollIntervalMs < 0) {\n throw new TypeError('Durable Operation poll interval must be a non-negative finite number.');\n }\n\n const request = async (\n runtimeRequest: RuntimeProtocolRequestEnvelope,\n options?: RuntimeTransportRequestOptions,\n ) => {\n const init = requestInit?.() ?? {};\n const headers = new Headers(init.headers);\n if (!headers.has('content-type')) headers.set('content-type', 'application/json');\n const response = await fetchRequest(endpoint, {\n ...init,\n method: 'POST',\n headers,\n credentials: init.credentials ?? 'same-origin',\n body: JSON.stringify(runtimeRequest),\n ...(options?.signal ? { signal: options.signal } : {}),\n });\n const payload: unknown = await response.json().catch(() => null);\n const parsed = parseRuntimeProtocolResponse(payload, runtimeRequest);\n if (!parsed.success) throw new Error(parsed.error.error.message);\n if (!response.ok && !isRuntimeProtocolError(parsed.response)) {\n throw new Error(`Runtime Protocol request failed with status ${response.status}.`);\n }\n return parsed.response;\n };\n\n const observe: DurableOperationObservationCapability['observe'] = async function* <TResult>(\n run: TaskRunIdentity,\n options?: RuntimeTransportRequestOptions,\n ): AsyncIterable<TaskSnapshot<TResult>> {\n while (!options?.signal?.aborted) {\n const runtimeRequest = createRuntimeProtocolRequest({\n id: requestId(),\n family: 'durable.operation',\n body: toDurableOperationProtocolRequest(run),\n });\n const runtimeResponse = await request(runtimeRequest, options);\n if (isRuntimeProtocolError(runtimeResponse)) {\n throw new Error(runtimeResponse.error.message);\n }\n\n const parsed = parseDurableOperationProtocolResponse(runtimeResponse.body);\n if (!parsed.success) throw new Error(parsed.error.error.message);\n if (parsed.response.kind === 'protocol-error') {\n throw new Error(parsed.response.error.message);\n }\n\n const snapshot = parsed.response.snapshot as TaskSnapshot<TResult>;\n if (snapshot.taskId !== run.taskId || snapshot.runId !== run.runId) {\n throw new Error('Durable Operation snapshot identity does not match the observed run.');\n }\n yield snapshot;\n if (terminalTaskStatuses.has(snapshot.status)) return;\n if (!(await waitForNextInspection(pollIntervalMs, options?.signal))) return;\n }\n };\n\n return {\n request,\n durableOperation: { observe },\n };\n};\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type ManyToManyRelationshipCommand, type
|
|
1
|
+
import { type ManyToManyRelationshipCommand, type RelationshipCommandResult } from '@ontahi/core/data-graph';
|
|
2
2
|
import { type UseMutationResult, type UseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
import type { GraphCommandBuilder, GraphCommandHookOptions, GraphOperationLike, GraphOperationClientInput, GraphOperationResult, GraphQueryData, GraphQueryMode, GraphQueryOptions, GraphReadSource } from './executor.js';
|
|
4
4
|
export declare function useGraphQuery<TRead extends GraphReadSource<any>, TMode extends GraphQueryMode = 'run', TReadOptions = unknown, TCommandOptions = TReadOptions>(read: TRead, options?: GraphQueryOptions<TRead, TMode, TReadOptions>): UseQueryResult<GraphQueryData<TRead, TMode>, Error>;
|
|
5
5
|
export declare function useGraphCommand<TVariables, TResult = void, TContext = unknown, TReadOptions = unknown, TCommandOptions = TReadOptions>(buildCommand: GraphCommandBuilder<TVariables, TResult>, options?: GraphCommandHookOptions<TResult, TVariables, TContext, TCommandOptions>): UseMutationResult<TResult, Error, TVariables, TContext>;
|
|
6
|
-
export declare function useManyToManyRelationshipCommand<TVariables, TContext = unknown, TReadOptions = unknown, TCommandOptions = TReadOptions>(buildCommand: (variables: TVariables) => ManyToManyRelationshipCommand, options?: GraphCommandHookOptions<
|
|
6
|
+
export declare function useManyToManyRelationshipCommand<TVariables, TContext = unknown, TReadOptions = unknown, TCommandOptions = TReadOptions>(buildCommand: (variables: TVariables) => ManyToManyRelationshipCommand, options?: GraphCommandHookOptions<RelationshipCommandResult, TVariables, TContext, TCommandOptions>): UseMutationResult<RelationshipCommandResult, Error, TVariables, TContext>;
|
|
7
7
|
export declare function useGraphOperation<TOperation extends GraphOperationLike<any, any>, TContext = unknown, TReadOptions = unknown, TCommandOptions = TReadOptions>(operation: TOperation, options?: GraphCommandHookOptions<GraphOperationResult<TOperation>, GraphOperationClientInput<TOperation>, TContext, TCommandOptions>): UseMutationResult<GraphOperationResult<TOperation>, Error, GraphOperationClientInput<TOperation>, TContext>;
|
|
8
8
|
//# sourceMappingURL=graph-hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-hooks.d.ts","sourceRoot":"","sources":["../../src/graph/graph-hooks.ts"],"names":[],"mappings":"AAEA,OAAO,EAOL,KAAK,6BAA6B,EAClC,KAAK,
|
|
1
|
+
{"version":3,"file":"graph-hooks.d.ts","sourceRoot":"","sources":["../../src/graph/graph-hooks.ts"],"names":[],"mappings":"AAEA,OAAO,EAOL,KAAK,6BAA6B,EAClC,KAAK,yBAAyB,EAG/B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAK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EACZ;QACE,WAAW,EAAE,OAAO,EAAE,WAAW,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,EAAE,CAAC;QACtE,GAAG,OAAO;KACX,CACF,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport {\n isGraphReadExpression,\n normalizeGraphSchemaClientInput,\n resolveQuerySpec,\n toGraphReadRequest,\n type GraphCommandSpec,\n type GraphReadIntent,\n type ManyToManyRelationshipCommand,\n type RelationshipDelta,\n type QueryOrView,\n type ViewDefinition,\n} from '@ontahi/core/data-graph';\nimport { executionIdentityCacheKey } from '@ontahi/core/runtime/identity';\nimport {\n useMutation,\n useQuery,\n useQueryClient,\n type QueryKey,\n type UseMutationResult,\n type UseQueryResult,\n} from '@tanstack/react-query';\n\nimport { useExecutionIdentity, useGraphExecutor } from './context.js';\nimport type {\n BuildableRead,\n CommandLike,\n GraphCommandBuilder,\n GraphCommandHookOptions,\n GraphOperationLike,\n GraphOperationClientInput,\n GraphOperationResult,\n GraphQueryData,\n GraphQueryMode,\n GraphQueryOptions,\n GraphReadSource,\n ReadParams,\n ReadResult,\n} from './executor.js';\n\nconst isQueryOrView = <TResult>(\n read: Exclude<GraphReadSource<TResult>, { kind: 'graph-read-expression' }>,\n): read is QueryOrView<any, TResult> => 'kind' in read;\n\nconst isBuildableRead = <TResult>(\n read: Exclude<GraphReadSource<TResult>, { kind: 'graph-read-expression' }>,\n): read is BuildableRead<TResult> => typeof (read as BuildableRead<TResult>).build === 'function';\n\nconst isNamedView = <TResult>(\n read: QueryOrView<any, TResult>,\n): read is ViewDefinition<any, any, TResult> => 'kind' in read && read.kind === 'view';\n\ntype PlainGraphReadSource<TResult> = Exclude<\n GraphReadSource<TResult>,\n { kind: 'graph-read-expression' }\n>;\n\nconst resolveGraphRead = <TResult>(read: PlainGraphReadSource<TResult>) =>\n (isQueryOrView(read) ? read : isBuildableRead(read) ? read.build() : read) as QueryOrView<\n any,\n TResult\n >;\n\nconst resolveGraphCommand = <TResult>(command: CommandLike<TResult>) =>\n ('build' in command ? command.build() : command) as GraphCommandSpec<any, any, TResult>;\n\nconst intentFromMode = (mode: GraphQueryMode): GraphReadIntent | 'many' =>\n mode === 'get' ? 'first' : mode === 'run' ? 'many' : mode;\n\nconst modeFromIntent = (intent: GraphReadIntent | 'many'): Exclude<GraphQueryMode, 'exists'> =>\n intent === 'many' ? 'run' : intent === 'count' ? 'count' : 'get';\n\nconst deriveGraphQueryKey = <TRead>(\n read: PlainGraphReadSource<ReadResult<TRead>>,\n intent: GraphReadIntent | 'many',\n params: ReadParams<TRead> | undefined,\n identityKey: readonly unknown[],\n): QueryKey => {\n const resolved = isQueryOrView(read) ? read : resolveGraphRead(read);\n\n if (isNamedView(resolved)) {\n return [\n resolved.root.name,\n 'graph-read',\n identityKey,\n intent,\n 'view',\n resolved.name,\n params ?? null,\n ];\n }\n\n try {\n const request = toGraphReadRequest(resolveQuerySpec(resolved, params), modeFromIntent(intent));\n return [request.selection.entityName, 'graph-read', identityKey, intent, request];\n } catch (error) {\n const message =\n 'useGraphQuery could not infer a transport-safe queryKey; provide queryKey explicitly';\n throw new Error(`${message}: ${error instanceof Error ? error.message : String(error)}`);\n }\n};\n\nexport function useGraphQuery<\n TRead extends GraphReadSource<any>,\n TMode extends GraphQueryMode = 'run',\n TReadOptions = unknown,\n TCommandOptions = TReadOptions,\n>(\n read: TRead,\n options?: GraphQueryOptions<TRead, TMode, TReadOptions>,\n): UseQueryResult<GraphQueryData<TRead, TMode>, Error> {\n const graphExecutor = useGraphExecutor<TReadOptions, TCommandOptions>();\n const identity = useExecutionIdentity();\n const expression = isGraphReadExpression(read) ? read : undefined;\n const source = (expression?.read ?? read) as PlainGraphReadSource<ReadResult<TRead>>;\n const mode = options?.mode ?? 'run';\n const intent = expression?.intent ?? intentFromMode(mode);\n\n return useQuery({\n ...options,\n queryKey:\n options?.queryKey ??\n deriveGraphQueryKey(source, intent, options?.params, executionIdentityCacheKey(identity)),\n queryFn: async () => {\n const resolved = resolveGraphRead(source);\n const params = options?.params as any;\n\n const value =\n intent === 'many'\n ? await graphExecutor.run(resolved, params, options?.runtimeOptions)\n : intent === 'count'\n ? await graphExecutor.count(resolved, params, options?.runtimeOptions)\n : intent === 'exists'\n ? (await graphExecutor.get(resolved, params, options?.runtimeOptions)) != null\n : await graphExecutor.get(resolved, params, options?.runtimeOptions);\n\n return value as GraphQueryData<TRead, TMode>;\n },\n });\n}\n\nexport function useGraphCommand<\n TVariables,\n TResult = void,\n TContext = unknown,\n TReadOptions = unknown,\n TCommandOptions = TReadOptions,\n>(\n buildCommand: GraphCommandBuilder<TVariables, TResult>,\n options?: GraphCommandHookOptions<TResult, TVariables, TContext, TCommandOptions>,\n): UseMutationResult<TResult, Error, TVariables, TContext> {\n const graphExecutor = useGraphExecutor<TReadOptions, TCommandOptions>();\n const queryClient = useQueryClient();\n\n return useMutation({\n ...options,\n mutationKey: options?.mutationKey,\n mutationFn: variables =>\n graphExecutor.runCommand(\n resolveGraphCommand(buildCommand(variables)),\n options?.runtimeOptions,\n ),\n onSuccess: async (data, variables, onMutateResult, context) => {\n for (const queryKey of options?.invalidateQueryKeys ?? []) {\n await queryClient.invalidateQueries({ queryKey });\n }\n\n await options?.onSuccess?.(data, variables, onMutateResult, context);\n },\n });\n}\n\nexport function useManyToManyRelationshipCommand<\n TVariables,\n TContext = unknown,\n TReadOptions = unknown,\n TCommandOptions = TReadOptions,\n>(\n buildCommand: (variables: TVariables) => ManyToManyRelationshipCommand,\n options?: GraphCommandHookOptions<RelationshipDelta, TVariables, TContext, TCommandOptions>,\n): UseMutationResult<RelationshipDelta, Error, TVariables, TContext> {\n const graphExecutor = useGraphExecutor<TReadOptions, TCommandOptions>();\n const queryClient = useQueryClient();\n\n return useMutation({\n ...options,\n mutationKey: options?.mutationKey,\n mutationFn: variables => {\n if (!graphExecutor.runManyToManyRelationshipCommand) {\n throw new Error('Graph executor does not support many-to-many Relationship Commands.');\n }\n return graphExecutor.runManyToManyRelationshipCommand(\n buildCommand(variables),\n options?.runtimeOptions,\n );\n },\n onSuccess: async (data, variables, onMutateResult, context) => {\n for (const queryKey of options?.invalidateQueryKeys ?? []) {\n await queryClient.invalidateQueries({ queryKey });\n }\n await options?.onSuccess?.(data, variables, onMutateResult, context);\n },\n });\n}\n\nexport function useGraphOperation<\n TOperation extends GraphOperationLike<any, any>,\n TContext = unknown,\n TReadOptions = unknown,\n TCommandOptions = TReadOptions,\n>(\n operation: TOperation,\n options?: GraphCommandHookOptions<\n GraphOperationResult<TOperation>,\n GraphOperationClientInput<TOperation>,\n TContext,\n TCommandOptions\n >,\n): UseMutationResult<\n GraphOperationResult<TOperation>,\n Error,\n GraphOperationClientInput<TOperation>,\n TContext\n> {\n type TVariables = GraphOperationClientInput<TOperation>;\n type TResult = GraphOperationResult<TOperation>;\n const buildCommand = (variables: TVariables) =>\n operation.run(\n (operation.input\n ? normalizeGraphSchemaClientInput(operation.input, variables)\n : variables) as never,\n );\n\n return useGraphCommand<TVariables, TResult, TContext, TReadOptions, TCommandOptions>(\n buildCommand,\n {\n mutationKey: options?.mutationKey ?? ['graph-operation', operation.id],\n ...options,\n },\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"graph-hooks.js","sourceRoot":"","sources":["../../src/graph/graph-hooks.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EACL,qBAAqB,EACrB,+BAA+B,EAC/B,gBAAgB,EAChB,kBAAkB,GAOnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EACL,WAAW,EACX,QAAQ,EACR,cAAc,GAIf,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAiBtE,MAAM,aAAa,GAAG,CACpB,IAA0E,EACvC,EAAE,CAAC,MAAM,IAAI,IAAI,CAAC;AAEvD,MAAM,eAAe,GAAG,CACtB,IAA0E,EAC1C,EAAE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KC;IASD,MAAM,YAAY,GAAG,CAAC,SAAqB,EAAE,EAAE,CAC7C,SAAS,CAAC,GAAG,CACX,CAAC,SAAS,CAAC,KAAK;QACd,CAAC,CAAC,+BAA+B,CAAC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC;QAC7D,CAAC,CAAC,SAAS,CAAU,CACxB,CAAC;IAEJ,OAAO,eAAe,CACpB,YAAY,EACZ;QACE,WAAW,EAAE,OAAO,EAAE,WAAW,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,EAAE,CAAC;QACtE,GAAG,OAAO;KACX,CACF,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport {\n isGraphReadExpression,\n normalizeGraphSchemaClientInput,\n resolveQuerySpec,\n toGraphReadRequest,\n type GraphCommandSpec,\n type GraphReadIntent,\n type ManyToManyRelationshipCommand,\n type RelationshipCommandResult,\n type QueryOrView,\n type ViewDefinition,\n} from '@ontahi/core/data-graph';\nimport { executionIdentityCacheKey } from '@ontahi/core/runtime/identity';\nimport {\n useMutation,\n useQuery,\n useQueryClient,\n type QueryKey,\n type UseMutationResult,\n type UseQueryResult,\n} from '@tanstack/react-query';\n\nimport { useExecutionIdentity, useGraphExecutor } from './context.js';\nimport type {\n BuildableRead,\n CommandLike,\n GraphCommandBuilder,\n GraphCommandHookOptions,\n GraphOperationLike,\n GraphOperationClientInput,\n GraphOperationResult,\n GraphQueryData,\n GraphQueryMode,\n GraphQueryOptions,\n GraphReadSource,\n ReadParams,\n ReadResult,\n} from './executor.js';\n\nconst isQueryOrView = <TResult>(\n read: Exclude<GraphReadSource<TResult>, { kind: 'graph-read-expression' }>,\n): read is QueryOrView<any, TResult> => 'kind' in read;\n\nconst isBuildableRead = <TResult>(\n read: Exclude<GraphReadSource<TResult>, { kind: 'graph-read-expression' }>,\n): read is BuildableRead<TResult> => typeof (read as BuildableRead<TResult>).build === 'function';\n\nconst isNamedView = <TResult>(\n read: QueryOrView<any, TResult>,\n): read is ViewDefinition<any, any, TResult> => 'kind' in read && read.kind === 'view';\n\ntype PlainGraphReadSource<TResult> = Exclude<\n GraphReadSource<TResult>,\n { kind: 'graph-read-expression' }\n>;\n\nconst resolveGraphRead = <TResult>(read: PlainGraphReadSource<TResult>) =>\n (isQueryOrView(read) ? read : isBuildableRead(read) ? read.build() : read) as QueryOrView<\n any,\n TResult\n >;\n\nconst resolveGraphCommand = <TResult>(command: CommandLike<TResult>) =>\n ('build' in command ? command.build() : command) as GraphCommandSpec<any, any, TResult>;\n\nconst intentFromMode = (mode: GraphQueryMode): GraphReadIntent | 'many' =>\n mode === 'get' ? 'first' : mode === 'run' ? 'many' : mode;\n\nconst modeFromIntent = (intent: GraphReadIntent | 'many'): Exclude<GraphQueryMode, 'exists'> =>\n intent === 'many' ? 'run' : intent === 'count' ? 'count' : 'get';\n\nconst deriveGraphQueryKey = <TRead>(\n read: PlainGraphReadSource<ReadResult<TRead>>,\n intent: GraphReadIntent | 'many',\n params: ReadParams<TRead> | undefined,\n identityKey: readonly unknown[],\n): QueryKey => {\n const resolved = isQueryOrView(read) ? read : resolveGraphRead(read);\n\n if (isNamedView(resolved)) {\n return [\n resolved.root.name,\n 'graph-read',\n identityKey,\n intent,\n 'view',\n resolved.name,\n params ?? null,\n ];\n }\n\n try {\n const request = toGraphReadRequest(resolveQuerySpec(resolved, params), modeFromIntent(intent));\n return [request.selection.entityName, 'graph-read', identityKey, intent, request];\n } catch (error) {\n const message =\n 'useGraphQuery could not infer a transport-safe queryKey; provide queryKey explicitly';\n throw new Error(`${message}: ${error instanceof Error ? error.message : String(error)}`);\n }\n};\n\nexport function useGraphQuery<\n TRead extends GraphReadSource<any>,\n TMode extends GraphQueryMode = 'run',\n TReadOptions = unknown,\n TCommandOptions = TReadOptions,\n>(\n read: TRead,\n options?: GraphQueryOptions<TRead, TMode, TReadOptions>,\n): UseQueryResult<GraphQueryData<TRead, TMode>, Error> {\n const graphExecutor = useGraphExecutor<TReadOptions, TCommandOptions>();\n const identity = useExecutionIdentity();\n const expression = isGraphReadExpression(read) ? read : undefined;\n const source = (expression?.read ?? read) as PlainGraphReadSource<ReadResult<TRead>>;\n const mode = options?.mode ?? 'run';\n const intent = expression?.intent ?? intentFromMode(mode);\n\n return useQuery({\n ...options,\n queryKey:\n options?.queryKey ??\n deriveGraphQueryKey(source, intent, options?.params, executionIdentityCacheKey(identity)),\n queryFn: async () => {\n const resolved = resolveGraphRead(source);\n const params = options?.params as any;\n\n const value =\n intent === 'many'\n ? await graphExecutor.run(resolved, params, options?.runtimeOptions)\n : intent === 'count'\n ? await graphExecutor.count(resolved, params, options?.runtimeOptions)\n : intent === 'exists'\n ? (await graphExecutor.get(resolved, params, options?.runtimeOptions)) != null\n : await graphExecutor.get(resolved, params, options?.runtimeOptions);\n\n return value as GraphQueryData<TRead, TMode>;\n },\n });\n}\n\nexport function useGraphCommand<\n TVariables,\n TResult = void,\n TContext = unknown,\n TReadOptions = unknown,\n TCommandOptions = TReadOptions,\n>(\n buildCommand: GraphCommandBuilder<TVariables, TResult>,\n options?: GraphCommandHookOptions<TResult, TVariables, TContext, TCommandOptions>,\n): UseMutationResult<TResult, Error, TVariables, TContext> {\n const graphExecutor = useGraphExecutor<TReadOptions, TCommandOptions>();\n const queryClient = useQueryClient();\n\n return useMutation({\n ...options,\n mutationKey: options?.mutationKey,\n mutationFn: variables =>\n graphExecutor.runCommand(\n resolveGraphCommand(buildCommand(variables)),\n options?.runtimeOptions,\n ),\n onSuccess: async (data, variables, onMutateResult, context) => {\n for (const queryKey of options?.invalidateQueryKeys ?? []) {\n await queryClient.invalidateQueries({ queryKey });\n }\n\n await options?.onSuccess?.(data, variables, onMutateResult, context);\n },\n });\n}\n\nexport function useManyToManyRelationshipCommand<\n TVariables,\n TContext = unknown,\n TReadOptions = unknown,\n TCommandOptions = TReadOptions,\n>(\n buildCommand: (variables: TVariables) => ManyToManyRelationshipCommand,\n options?: GraphCommandHookOptions<\n RelationshipCommandResult,\n TVariables,\n TContext,\n TCommandOptions\n >,\n): UseMutationResult<RelationshipCommandResult, Error, TVariables, TContext> {\n const graphExecutor = useGraphExecutor<TReadOptions, TCommandOptions>();\n const queryClient = useQueryClient();\n\n return useMutation({\n ...options,\n mutationKey: options?.mutationKey,\n mutationFn: variables => {\n if (!graphExecutor.runManyToManyRelationshipCommand) {\n throw new Error('Graph executor does not support many-to-many Relationship Commands.');\n }\n return graphExecutor.runManyToManyRelationshipCommand(\n buildCommand(variables),\n options?.runtimeOptions,\n );\n },\n onSuccess: async (data, variables, onMutateResult, context) => {\n for (const queryKey of options?.invalidateQueryKeys ?? []) {\n await queryClient.invalidateQueries({ queryKey });\n }\n await options?.onSuccess?.(data, variables, onMutateResult, context);\n },\n });\n}\n\nexport function useGraphOperation<\n TOperation extends GraphOperationLike<any, any>,\n TContext = unknown,\n TReadOptions = unknown,\n TCommandOptions = TReadOptions,\n>(\n operation: TOperation,\n options?: GraphCommandHookOptions<\n GraphOperationResult<TOperation>,\n GraphOperationClientInput<TOperation>,\n TContext,\n TCommandOptions\n >,\n): UseMutationResult<\n GraphOperationResult<TOperation>,\n Error,\n GraphOperationClientInput<TOperation>,\n TContext\n> {\n type TVariables = GraphOperationClientInput<TOperation>;\n type TResult = GraphOperationResult<TOperation>;\n const buildCommand = (variables: TVariables) =>\n operation.run(\n (operation.input\n ? normalizeGraphSchemaClientInput(operation.input, variables)\n : variables) as never,\n );\n\n return useGraphCommand<TVariables, TResult, TContext, TReadOptions, TCommandOptions>(\n buildCommand,\n {\n mutationKey: options?.mutationKey ?? ['graph-operation', operation.id],\n ...options,\n },\n );\n}\n"]}
|
package/dist/graph/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './context.js';
|
|
2
2
|
export * from './executor.js';
|
|
3
3
|
export * from './fetch-graph-read-executor.js';
|
|
4
|
+
export * from './fetch-runtime-transport.js';
|
|
4
5
|
export * from './fetch-graph-client.js';
|
|
5
6
|
export * from './graph-hooks.js';
|
|
6
7
|
export * from './operation-cache.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/graph/index.tsx"],"names":[],"mappings":"AAEA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/graph/index.tsx"],"names":[],"mappings":"AAEA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC"}
|
package/dist/graph/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
export * from './context.js';
|
|
3
3
|
export * from './executor.js';
|
|
4
4
|
export * from './fetch-graph-read-executor.js';
|
|
5
|
+
export * from './fetch-runtime-transport.js';
|
|
5
6
|
export * from './fetch-graph-client.js';
|
|
6
7
|
export * from './graph-hooks.js';
|
|
7
8
|
export * from './operation-cache.js';
|
package/dist/graph/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/graph/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC","sourcesContent":["'use client';\n\nexport * from './context.js';\nexport * from './executor.js';\nexport * from './fetch-graph-read-executor.js';\nexport * from './fetch-graph-client.js';\nexport * from './graph-hooks.js';\nexport * from './operation-cache.js';\nexport * from './operation-hooks.js';\nexport * from './operation-types.js';\nexport * from './reflected-entity-data-hooks.js';\nexport * from './reflected-operation-invoker.js';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/graph/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC","sourcesContent":["'use client';\n\nexport * from './context.js';\nexport * from './executor.js';\nexport * from './fetch-graph-read-executor.js';\nexport * from './fetch-runtime-transport.js';\nexport * from './fetch-graph-client.js';\nexport * from './graph-hooks.js';\nexport * from './operation-cache.js';\nexport * from './operation-hooks.js';\nexport * from './operation-types.js';\nexport * from './reflected-entity-data-hooks.js';\nexport * from './reflected-operation-invoker.js';\n"]}
|