@ontahi/react 0.1.0-alpha.5 → 0.1.0-alpha.7

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 CHANGED
@@ -58,6 +58,18 @@ configured client with `client={createFetchGraphClient(...)}`, or set `client={f
58
58
  explicit provider. Server routes, read policies, and authorization remain opt-in and authoritative;
59
59
  the default removes client wiring, not the server security boundary.
60
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
+
61
73
  Generated client Entities expose portable `all()` and `where(...)` Query entry points. A Query
62
74
  returns many rows by default; terminal `first()`, `one()`, `count()`, and `exists()` expressions
63
75
  make the result contract explicit and let `useGraphQuery` select the executor method. `one()` is
@@ -1,10 +1,12 @@
1
- import type { GraphCommandSpec, GraphOperationDeclaration, GraphReadExpression, GraphReadIntent, 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>;
@@ -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,EACV,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE3F,MAAM,WAAW,kBAAkB,CAAC,YAAY,GAAG,OAAO,EAAE,eAAe,GAAG,YAAY;IACxF,GAAG,CAAC,OAAO,EAAE,OAAO,EAClB,IAAI,EAAE,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,EACnC,MAAM,EAAE,OAAO,EACf,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;IAC3B,GAAG,CAAC,OAAO,EAAE,OAAO,EAClB,IAAI,EAAE,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,EACnC,MAAM,EAAE,OAAO,EACf,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IACtB,KAAK,CAAC,OAAO,EAAE,OAAO,EACpB,IAAI,EAAE,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,EACnC,MAAM,EAAE,OAAO,EACf,OAAO,CAAC,EAAE,YAAY,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B,CAAC,UAAU,EAAE,OAAO,IAAI,yBAAyB,CAC7E,UAAU,EACV,WAAW,CAAC,OAAO,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} 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\ntype PlainGraphReadSource<TResult> = QueryOrView<any, TResult> | BuildableRead<TResult>;\n\nexport type GraphReadSource<TResult = unknown> =\n | PlainGraphReadSource<TResult>\n | GraphReadExpression<PlainGraphReadSource<TResult>, GraphReadIntent, TResult>;\n\nexport type ReadParams<TRead> =\n TRead extends GraphReadExpression<infer TSource, any, any>\n ? ReadParams<TSource>\n : TRead extends QueryOrView<infer TParams, any>\n ? TParams\n : undefined;\n\nexport type ReadResult<TRead> =\n TRead extends GraphReadExpression<any, any, infer TResult>\n ? TResult\n : TRead extends QueryOrView<any, infer TResult>\n ? TResult\n : TRead extends BuildableRead<infer TResult>\n ? TResult\n : never;\n\nexport type GraphQueryMode = 'get' | 'run' | 'count' | 'exists';\n\ntype GraphReadIntentData<TRead, TIntent extends GraphReadIntent> = TIntent extends 'count'\n ? number\n : TIntent extends 'exists'\n ? boolean\n : TIntent extends 'one'\n ? ReadResult<TRead>\n : ReadResult<TRead> | null;\n\nexport type GraphQueryData<TRead, TMode extends GraphQueryMode = 'run'> =\n TRead extends GraphReadExpression<any, infer TIntent, any>\n ? GraphReadIntentData<TRead, TIntent>\n : TMode extends 'get'\n ? ReadResult<TRead> | null\n : TMode extends 'run'\n ? ReadResult<TRead>[]\n : TMode extends 'count'\n ? number\n : boolean;\n\nexport type GraphQueryOptions<\n TRead,\n TMode extends GraphQueryMode = 'run',\n TReadOptions = unknown,\n> = Omit<\n UseQueryOptions<GraphQueryData<TRead, TMode>, Error, GraphQueryData<TRead, TMode>, QueryKey>,\n 'queryKey' | 'queryFn'\n> & {\n mode?: TRead extends GraphReadExpression<any, any, any> ? never : TMode;\n params?: ReadParams<TRead>;\n queryKey?: QueryKey;\n runtimeOptions?: TReadOptions;\n};\n\nexport type CommandLike<TResult> =\n | GraphCommandSpec<any, any, TResult>\n | {\n build: () => GraphCommandSpec<any, any, TResult>;\n };\n\nexport type GraphCommandBuilder<TVariables, TResult> = (\n variables: TVariables,\n) => CommandLike<TResult>;\n\nexport type GraphOperationLike<TVariables, TResult> = GraphOperationDeclaration<\n TVariables,\n CommandLike<TResult>\n> & {\n id: string;\n};\n\nexport type GraphOperationClientInput<TOperation> = TOperation extends {\n input: infer TSchema extends GraphSchemaLike;\n}\n ? InferGraphSchemaClientInput<TSchema>\n : TOperation extends GraphOperationDeclaration<infer TInput, any>\n ? TInput\n : never;\n\nexport type GraphOperationResult<TOperation> = TOperation extends {\n run: (...args: any[]) => CommandLike<infer TResult>;\n}\n ? TResult\n : never;\n\nexport type GraphCommandHookOptions<\n TResult,\n TVariables,\n TContext,\n TCommandOptions = unknown,\n> = Omit<UseMutationOptions<TResult, Error, TVariables, TContext>, 'mutationFn'> & {\n mutationKey?: QueryKey;\n runtimeOptions?: TCommandOptions;\n invalidateQueryKeys?: QueryKey[];\n};\n"]}
1
+ {"version":3,"file":"executor.js","sourceRoot":"","sources":["../../src/graph/executor.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n GraphCommandSpec,\n GraphOperationDeclaration,\n GraphReadExpression,\n GraphReadIntent,\n GraphSchemaLike,\n InferGraphSchemaClientInput,\n QueryOrView,\n QuerySpec,\n ManyToManyRelationshipCommand,\n 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"]}
@@ -1,22 +1,33 @@
1
- import type { ReflectedEntityDataReader, ReflectedOperationInvoker } from '@ontahi/core/data-graph';
1
+ import type { ReflectedEntityDataReader, ReflectedOperationInvoker, RemoteDataGraphError, RuntimeBoundDataGraphApi } from '@ontahi/core/data-graph';
2
2
  import { type AnyOperationBridgeAdapter, type FetchOperationBridgeOptions } from '../actions/index.js';
3
3
  import type { ReactGraphExecutor } from './executor.js';
4
- import { type FetchGraphReadExecutorOptions } from './fetch-graph-read-executor.js';
4
+ import type { FetchGraphReadExecutorOptions } from './fetch-graph-read-executor.js';
5
5
  export type FetchReflectedEntityDataReaderOptions = {
6
6
  endpoint?: string;
7
7
  fetch?: typeof globalThis.fetch;
8
8
  };
9
9
  export type OntahiGraphClient<TReadOptions = unknown, TCommandOptions = TReadOptions> = {
10
+ graph?: RuntimeBoundDataGraphApi<RemoteDataGraphError, TReadOptions, TCommandOptions, RemoteDataGraphError>;
10
11
  graphExecutor?: ReactGraphExecutor<TReadOptions, TCommandOptions>;
11
12
  operationBridgeAdapters?: AnyOperationBridgeAdapter[];
12
13
  reflectedEntityDataReader?: ReflectedEntityDataReader;
13
14
  reflectedOperationInvoker?: ReflectedOperationInvoker;
14
15
  };
16
+ export type FetchGraphClient<TOptions = undefined> = OntahiGraphClient<TOptions, TOptions> & {
17
+ graph: RuntimeBoundDataGraphApi<RemoteDataGraphError, TOptions, TOptions, RemoteDataGraphError>;
18
+ graphExecutor: ReactGraphExecutor<TOptions, TOptions>;
19
+ };
15
20
  export type FetchGraphClientOptions<TOptions = undefined> = {
16
21
  graphRead?: false | FetchGraphReadExecutorOptions<TOptions>;
17
22
  operations?: false | FetchOperationBridgeOptions;
18
23
  reflectedEntityData?: false | FetchReflectedEntityDataReaderOptions;
19
24
  };
20
25
  export declare const createFetchReflectedEntityDataReader: ({ endpoint, fetch: fetchRequest, }?: FetchReflectedEntityDataReaderOptions) => ReflectedEntityDataReader;
21
- export declare const createFetchGraphClient: <TOptions = undefined>({ graphRead, operations, reflectedEntityData, }?: FetchGraphClientOptions<TOptions>) => OntahiGraphClient<TOptions, TOptions>;
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>;
22
33
  //# sourceMappingURL=fetch-graph-client.d.ts.map
@@ -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,EAC1B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAGL,KAAK,yBAAyB,EAC9B,KAAK,2BAA2B,EACjC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAEL,KAAK,6BAA6B,EACnC,MAAM,gCAAgC,CAAC;AAExC,MAAM,MAAM,qCAAqC,GAAG;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,YAAY,GAAG,OAAO,EAAE,eAAe,GAAG,YAAY,IAAI;IACtF,aAAa,CAAC,EAAE,kBAAkB,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;IAClE,uBAAuB,CAAC,EAAE,yBAAyB,EAAE,CAAC;IACtD,yBAAyB,CAAC,EAAE,yBAAyB,CAAC;IACtD,yBAAyB,CAAC,EAAE,yBAAyB,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,mBAAmB,CAAC,EAAE,KAAK,GAAG,qCAAqC,CAAC;CACrE,CAAC;AAiBF,eAAO,MAAM,oCAA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,wBAAwB,CAAC,oBAAoB,EAAE,QAAQ,EAAE,QAAQ,EAAE,oBAAoB,CAAC,CAAC;IAChG,aAAa,EAAE,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,CAAC,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,mBAAmB,CAAC,EAAE,KAAK,GAAG,qCAAqC,CAAC;CACrE,CAAC;AAiBF,eAAO,MAAM,oCAAoC,GAAI,qCAGlD,qCAA0C,KAAG,yBAe9C,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"}
@@ -1,6 +1,7 @@
1
1
  'use client';
2
+ import { createRuntimeBoundDataGraphApi } from '@ontahi/core/data-graph';
2
3
  import { createFetchOperationBridgeAdapter, createFetchReflectedOperationInvoker, } from '../actions/index.js';
3
- import { createFetchGraphReadExecutor, } from './fetch-graph-read-executor.js';
4
+ import { createFetchGraphReadCapability } from './fetch-graph-runtime.js';
4
5
  const DEFAULT_OPERATIONS_ENDPOINT = '/operations';
5
6
  const DEFAULT_TASKS_ENDPOINT = '/operations/tasks';
6
7
  const DEFAULT_REFLECTED_ENTITY_DATA_ENDPOINT = '/explorer/entities';
@@ -25,10 +26,16 @@ export const createFetchReflectedEntityDataReader = ({ endpoint = DEFAULT_REFLEC
25
26
  return response.json();
26
27
  },
27
28
  });
28
- export const createFetchGraphClient = ({ graphRead = {}, operations = {}, reflectedEntityData = {}, } = {}) => {
29
+ export function createFetchGraphClient({ graphRead = {}, operations = {}, reflectedEntityData = {}, } = {}) {
29
30
  const operationOptions = operations === false ? undefined : conventionalOperationOptions(operations);
31
+ const graphReadCapability = graphRead === false ? undefined : createFetchGraphReadCapability(graphRead);
30
32
  return {
31
- ...(graphRead === false ? {} : { graphExecutor: createFetchGraphReadExecutor(graphRead) }),
33
+ ...(graphReadCapability
34
+ ? {
35
+ graph: createRuntimeBoundDataGraphApi(() => graphReadCapability.runtime),
36
+ graphExecutor: graphReadCapability.graphExecutor,
37
+ }
38
+ : {}),
32
39
  ...(operationOptions
33
40
  ? {
34
41
  operationBridgeAdapters: [createFetchOperationBridgeAdapter(operationOptions)],
@@ -39,5 +46,5 @@ export const createFetchGraphClient = ({ graphRead = {}, operations = {}, reflec
39
46
  ? {}
40
47
  : { reflectedEntityDataReader: createFetchReflectedEntityDataReader(reflectedEntityData) }),
41
48
  };
42
- };
49
+ }
43
50
  //# 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;AAQb,OAAO,EACL,iCAAiC,EACjC,oCAAoC,GAGrC,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,4BAA4B,GAE7B,MAAM,gCAAgC,CAAC;AAoBxC,MAAM,2BAA2B,GAAG,aAAa,CAAC;AAClD,MAAM,sBAAsB,GAAG,mBAAmB,CAAC;AACnD,MAAM,sCAAsC,GAAG,oBAAoB,CAAC;AAEpE,MAAM,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C,SAAS,CAAC,EAAE,CAAC;QAC1F,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,CAAC","sourcesContent":["'use client';\n\nimport type {\n ReflectedEntityDataReader,\n ReflectedEntityDataResult,\n ReflectedOperationInvoker,\n} 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 {\n createFetchGraphReadExecutor,\n type FetchGraphReadExecutorOptions,\n} from './fetch-graph-read-executor.js';\n\nexport type FetchReflectedEntityDataReaderOptions = {\n endpoint?: string;\n fetch?: typeof globalThis.fetch;\n};\n\nexport type OntahiGraphClient<TReadOptions = unknown, TCommandOptions = TReadOptions> = {\n graphExecutor?: ReactGraphExecutor<TReadOptions, TCommandOptions>;\n operationBridgeAdapters?: AnyOperationBridgeAdapter[];\n reflectedEntityDataReader?: ReflectedEntityDataReader;\n reflectedOperationInvoker?: ReflectedOperationInvoker;\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 const 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\n return {\n ...(graphRead === false ? {} : { graphExecutor: createFetchGraphReadExecutor(graphRead) }),\n ...(operationOptions\n ? {\n operationBridgeAdapters: [createFetchOperationBridgeAdapter(operationOptions)],\n reflectedOperationInvoker: createFetchReflectedOperationInvoker(operationOptions),\n }\n : {}),\n ...(reflectedEntityData === false\n ? {}\n : { reflectedEntityDataReader: createFetchReflectedEntityDataReader(reflectedEntityData) }),\n };\n};\n"]}
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,E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AA4B,CAAC,UAAU,CAAC,CAAC;IAC9E,MAAM,mBAAmB,GACvB,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,8BAA8B,CAAC,SAAS,CAAC,CAAC;IAE9E,OAAO;QACL,GAAG,CAAC,mBAAmB;YACrB,CAAC,CAAC;gBACE,KAAK,EAAE,8BAA8B,CAAC,GAAG,EAAE,CAAC,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"]}
@@ -1,8 +1,5 @@
1
1
  import type { ReactGraphExecutor } from './executor.js';
2
- export type FetchGraphReadExecutorOptions<TOptions = undefined> = {
3
- endpoint?: string;
4
- fetch?: typeof globalThis.fetch;
5
- requestInit?: (options?: TOptions) => Omit<RequestInit, 'body' | 'method'>;
6
- };
7
- export declare const createFetchGraphReadExecutor: <TOptions = undefined>({ endpoint, fetch: fetchRequest, requestInit, }?: FetchGraphReadExecutorOptions<TOptions>) => ReactGraphExecutor<TOptions, TOptions>;
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>;
8
5
  //# sourceMappingURL=fetch-graph-read-executor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch-graph-read-executor.d.ts","sourceRoot":"","sources":["../../src/graph/fetch-graph-read-executor.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAExD,MAAM,MAAM,6BAA6B,CAAC,QAAQ,GAAG,SAAS,IAAI;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,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;AAIF,eAAO,MAAM,4BAA4B,GAAI,QAAQ,GAAG,SAAS,EAAE,kDAIhE,6BAA6B,CAAC,QAAQ,CAAM,KAAG,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,CAgCtF,CAAC"}
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"}
@@ -1,37 +1,4 @@
1
1
  'use client';
2
- import { createRemoteDataGraphRuntime, isGraphReadProtocolError, } from '@ontahi/core/data-graph';
3
- import { runBrowserEffect } from '@ontahi/core/runtime/browser';
4
- const DEFAULT_GRAPH_READ_ENDPOINT = '/graph/reads';
5
- export const createFetchGraphReadExecutor = ({ endpoint = DEFAULT_GRAPH_READ_ENDPOINT, fetch: fetchRequest = globalThis.fetch, requestInit, } = {}) => {
6
- const transport = async (request, options) => {
7
- const init = requestInit?.(options) ?? {};
8
- const headers = new Headers(init.headers);
9
- if (!headers.has('content-type'))
10
- headers.set('content-type', 'application/json');
11
- const response = await fetchRequest(endpoint, {
12
- ...init,
13
- method: 'POST',
14
- headers,
15
- credentials: init.credentials ?? 'same-origin',
16
- body: JSON.stringify(request),
17
- });
18
- try {
19
- const payload = await response.json();
20
- if (!response.ok && !isGraphReadProtocolError(payload)) {
21
- throw new Error(`Graph read request failed with status ${response.status}.`);
22
- }
23
- return payload;
24
- }
25
- catch {
26
- throw new Error(`Graph read request failed with status ${response.status}.`);
27
- }
28
- };
29
- const runtime = createRemoteDataGraphRuntime({ transport });
30
- return {
31
- get: (read, params, options) => runBrowserEffect(runtime.get(read, params, options)),
32
- run: (read, params, options) => runBrowserEffect(runtime.run(read, params, options)),
33
- count: (read, params, options) => runBrowserEffect(runtime.count(read, params, options)),
34
- runCommand: (command, options) => runBrowserEffect(runtime.runCommand(command, options)),
35
- };
36
- };
2
+ import { createFetchGraphReadCapability, } from './fetch-graph-runtime.js';
3
+ export const createFetchGraphReadExecutor = (options = {}) => createFetchGraphReadCapability(options).graphExecutor;
37
4
  //# sourceMappingURL=fetch-graph-read-executor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch-graph-read-executor.js","sourceRoot":"","sources":["../../src/graph/fetch-graph-read-executor.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EACL,4BAA4B,EAC5B,wBAAwB,GAEzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAUhE,MAAM,2BAA2B,GAAG,cAAc,CAAC;AAEnD,MAAM,CAAC,MAAM,4BAA4B,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OAAO,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACpF,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACpF,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACxF,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;KACzF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["'use client';\n\nimport {\n createRemoteDataGraphRuntime,\n isGraphReadProtocolError,\n type RemoteGraphReadTransport,\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 fetch?: typeof globalThis.fetch;\n requestInit?: (options?: TOptions) => Omit<RequestInit, 'body' | 'method'>;\n};\n\nconst DEFAULT_GRAPH_READ_ENDPOINT = '/graph/reads';\n\nexport const createFetchGraphReadExecutor = <TOptions = undefined>({\n endpoint = DEFAULT_GRAPH_READ_ENDPOINT,\n fetch: fetchRequest = globalThis.fetch,\n requestInit,\n}: FetchGraphReadExecutorOptions<TOptions> = {}): ReactGraphExecutor<TOptions, 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 runtime = createRemoteDataGraphRuntime({ transport });\n\n return {\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 };\n};\n"]}
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,mCAAmC,CAC9F,oBAAoB,EACpB,QAAQ,CACT,GACC,6CAA6C,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAC;AAEhF,MAAM,MAAM,wBAAwB,CAAC,QAAQ,GAAG,SAAS,IAAI;IAC3D,OAAO,EAAE,iBAAiB,CAAC,QAAQ,CAAC,GAAG,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IAC1E,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,CAwDlF,CAAC"}
@@ -0,0 +1,61 @@
1
+ 'use client';
2
+ import { createRemoteDataGraphRuntime, isGraphCommandProtocolError, isGraphReadProtocolError, } from '@ontahi/core/data-graph';
3
+ import { runBrowserEffect } from '@ontahi/core/runtime/browser';
4
+ const DEFAULT_GRAPH_READ_ENDPOINT = '/graph/reads';
5
+ const DEFAULT_GRAPH_COMMAND_ENDPOINT = '/graph/commands';
6
+ export const createFetchGraphReadCapability = ({ endpoint = DEFAULT_GRAPH_READ_ENDPOINT, commandEndpoint = DEFAULT_GRAPH_COMMAND_ENDPOINT, fetch: fetchRequest = globalThis.fetch, requestInit, } = {}) => {
7
+ const transport = async (request, options) => {
8
+ const init = requestInit?.(options) ?? {};
9
+ const headers = new Headers(init.headers);
10
+ if (!headers.has('content-type'))
11
+ headers.set('content-type', 'application/json');
12
+ const response = await fetchRequest(endpoint, {
13
+ ...init,
14
+ method: 'POST',
15
+ headers,
16
+ credentials: init.credentials ?? 'same-origin',
17
+ body: JSON.stringify(request),
18
+ });
19
+ try {
20
+ const payload = await response.json();
21
+ if (!response.ok && !isGraphReadProtocolError(payload)) {
22
+ throw new Error(`Graph read request failed with status ${response.status}.`);
23
+ }
24
+ return payload;
25
+ }
26
+ catch {
27
+ throw new Error(`Graph read request failed with status ${response.status}.`);
28
+ }
29
+ };
30
+ const commandTransport = async (request, options) => {
31
+ const init = requestInit?.(options) ?? {};
32
+ const headers = new Headers(init.headers);
33
+ if (!headers.has('content-type'))
34
+ headers.set('content-type', 'application/json');
35
+ const response = await fetchRequest(commandEndpoint, {
36
+ ...init,
37
+ method: 'POST',
38
+ headers,
39
+ credentials: init.credentials ?? 'same-origin',
40
+ body: JSON.stringify(request),
41
+ });
42
+ const payload = await response.json();
43
+ if (!response.ok && !isGraphCommandProtocolError(payload)) {
44
+ throw new Error(`Graph Command request failed with status ${response.status}.`);
45
+ }
46
+ return payload;
47
+ };
48
+ const runtime = createRemoteDataGraphRuntime({ transport, commandTransport });
49
+ return {
50
+ runtime,
51
+ graphExecutor: {
52
+ get: (read, params, options) => runBrowserEffect(runtime.get(read, params, options)),
53
+ run: (read, params, options) => runBrowserEffect(runtime.run(read, params, options)),
54
+ count: (read, params, options) => runBrowserEffect(runtime.count(read, params, options)),
55
+ runCommand: (command, options) => runBrowserEffect(runtime.runCommand(command, options)),
56
+ runRelationshipCommand: (command, options) => runBrowserEffect(runtime.runRelationshipCommand(command, options)),
57
+ runManyToManyRelationshipCommand: (command, options) => runBrowserEffect(runtime.runManyToManyRelationshipCommand(command, options)),
58
+ },
59
+ };
60
+ };
61
+ //# sourceMappingURL=fetch-graph-runtime.js.map
@@ -0,0 +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,GAOzB,MAAM,yBAAyB,CAAC;AACjC,OAA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EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YACpF,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YACxF,UAAU,EAAE,CAAC,OAAO,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;SAC/E;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["'use client';\n\nimport {\n createRemoteDataGraphRuntime,\n isGraphCommandProtocolError,\n isGraphReadProtocolError,\n type DataGraphExecutionRuntime,\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>;\n\nexport type FetchGraphReadCapability<TOptions = undefined> = {\n runtime: FetchGraphRuntime<TOptions> & FetchRelationshipRuntime<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 (!response.ok && !isGraphCommandProtocolError(payload)) {\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 },\n };\n};\n"]}
@@ -1,6 +1,8 @@
1
+ import { type ManyToManyRelationshipCommand, type RelationshipDelta } from '@ontahi/core/data-graph';
1
2
  import { type UseMutationResult, type UseQueryResult } from '@tanstack/react-query';
2
3
  import type { GraphCommandBuilder, GraphCommandHookOptions, GraphOperationLike, GraphOperationClientInput, GraphOperationResult, GraphQueryData, GraphQueryMode, GraphQueryOptions, GraphReadSource } from './executor.js';
3
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>;
4
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<RelationshipDelta, TVariables, TContext, TCommandOptions>): UseMutationResult<RelationshipDelta, Error, TVariables, TContext>;
5
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>;
6
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":"AAaA,OAAO,EAKL,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACpB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAGV,mBAAmB,EACnB,uBAAuB,EACvB,kBAAkB,EAClB,yBAAyB,EACzB,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,eAAe,EAGhB,MAAM,eAAe,CAAC;AAgEvB,wBAAgB,aAAa,CAC3B,KAAK,SAAS,eAAe,CAAC,GAAG,CAAC,EAClC,KAAK,SAAS,cAAc,GAAG,KAAK,EACpC,YAAY,GAAG,OAAO,EACtB,eAAe,GAAG,YAAY,EAE9B,IAAI,EAAE,KAAK,EACX,OAAO,CAAC,EAAE,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,YAAY,CAAC,GACtD,cAAc,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,CA6BrD;AAED,wBAAgB,eAAe,CAC7B,UAAU,EACV,OAAO,GAAG,IAAI,EACd,QAAQ,GAAG,OAAO,EAClB,YAAY,GAAG,OAAO,EACtB,eAAe,GAAG,YAAY,EAE9B,YAAY,EAAE,mBAAmB,CAAC,UAAU,EAAE,OAAO,CAAC,EACtD,OAAO,CAAC,EAAE,uBAAuB,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,eAAe,CAAC,GAChF,iBAAiB,CAAC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,CA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,GAAG,OAAO,EAClB,YAAY,GAAG,OAAO,EACtB,eAAe,GAAG,YAAY,EAE9B,YAAY,EAAE,mBAAmB,CAAC,UAAU,EAAE,OAAO,CAAC,EACtD,OAAO,CAAC,EAAE,uBAAuB,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,eAAe,CAAC,GAChF,iBAAiB,CAAC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,CAoBzD;AAED,wBAAgB,gCAAgC,CAC9C,UAAU,EACV,QAAQ,GAAG,OAAO,EAClB,YAAY,GAAG,OAAO,EACtB,eAAe,GAAG,YAAY,EAE9B,YAAY,EAAE,CAAC,SAAS,EAAE,UAAU,KAAK,6BAA6B,EACtE,OAAO,CAAC,EAAE,uBAAuB,CAAC,iBAAiB,EAAE,UAAU,EAAE,QAAQ,EAAE,eAAe,CAAC,GAC1F,iBAAiB,CAAC,iBAAiB,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,CAuBnE;AAED,wBAAgB,iBAAiB,CAC/B,UAAU,SAAS,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,EAC/C,QAAQ,GAAG,OAAO,EAClB,YAAY,GAAG,OAAO,EACtB,eAAe,GAAG,YAAY,EAE9B,SAAS,EAAE,UAAU,EACrB,OAAO,CAAC,EAAE,uBAAuB,CAC/B,oBAAoB,CAAC,UAAU,CAAC,EAChC,yBAAyB,CAAC,UAAU,CAAC,EACrC,QAAQ,EACR,eAAe,CAChB,GACA,iBAAiB,CAClB,oBAAoB,CAAC,UAAU,CAAC,EAChC,KAAK,EACL,yBAAyB,CAAC,UAAU,CAAC,EACrC,QAAQ,CACT,CAiBA"}
@@ -72,6 +72,26 @@ export function useGraphCommand(buildCommand, options) {
72
72
  },
73
73
  });
74
74
  }
75
+ export function useManyToManyRelationshipCommand(buildCommand, options) {
76
+ const graphExecutor = useGraphExecutor();
77
+ const queryClient = useQueryClient();
78
+ return useMutation({
79
+ ...options,
80
+ mutationKey: options?.mutationKey,
81
+ mutationFn: variables => {
82
+ if (!graphExecutor.runManyToManyRelationshipCommand) {
83
+ throw new Error('Graph executor does not support many-to-many Relationship Commands.');
84
+ }
85
+ return graphExecutor.runManyToManyRelationshipCommand(buildCommand(variables), options?.runtimeOptions);
86
+ },
87
+ onSuccess: async (data, variables, onMutateResult, context) => {
88
+ for (const queryKey of options?.invalidateQueryKeys ?? []) {
89
+ await queryClient.invalidateQueries({ queryKey });
90
+ }
91
+ await options?.onSuccess?.(data, variables, onMutateResult, context);
92
+ },
93
+ });
94
+ }
75
95
  export function useGraphOperation(operation, options) {
76
96
  const buildCommand = (variables) => operation.run((operation.input
77
97
  ? normalizeGraphSchemaClientInput(operation.input, variables)
@@ -1 +1 @@
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,GAKnB,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,CAAC,OAAQ,IAA+B,CAAC,KAAK,KAAK,UAAU,CAAC;AAElG,MAAM,WAAW,GAAG,CAClB,IAA+B,EACY,EAAE,CAAC,MAAM,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC;AAOvF,MAAM,gBAAgB,GAAG,CAAU,IAAmC,EAAE,EAAE,CACxE,CAAC,aAAa,CAAC,IAAI,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AAS,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;QACvE,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,iBAAiB,CAM/B,SAAqB,EACrB,OAKC;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 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 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,CAAC,OAAQ,IAA+B,CAAC,KAAK,KAAK,UAAU,CAAC;AAElG,MAAM,WAAW,GAAG,CAClB,IAA+B,EACY,EAAE,CAAC,MAAM,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC;AAOvF,MAAM,gBAAgB,GAAG,CAAU,IAAmC,EAAE,EAAE,CACxE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CA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AAE,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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ontahi/react",
3
- "version": "0.1.0-alpha.5",
3
+ "version": "0.1.0-alpha.7",
4
4
  "description": "Non-visual React hooks and bridge adapters for Ontahi applications",
5
5
  "homepage": "https://github.com/javifernandes/ontahi/tree/main/packages/react",
6
6
  "license": "Apache-2.0",
@@ -40,7 +40,7 @@
40
40
  "provenance": true
41
41
  },
42
42
  "dependencies": {
43
- "@ontahi/core": "0.1.0-alpha.5"
43
+ "@ontahi/core": "0.1.0-alpha.7"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@tanstack/react-query": "^5.51.0",