@ontahi/react 1.0.0-alpha.10 → 1.0.0-alpha.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +83 -5
  2. package/dist/actions/fetch-operation-bridge-adapter.d.ts +10 -3
  3. package/dist/actions/fetch-operation-bridge-adapter.d.ts.map +1 -1
  4. package/dist/actions/fetch-operation-bridge-adapter.js +74 -28
  5. package/dist/actions/fetch-operation-bridge-adapter.js.map +1 -1
  6. package/dist/graph/context.d.ts +1 -1
  7. package/dist/graph/context.d.ts.map +1 -1
  8. package/dist/graph/context.js +1 -1
  9. package/dist/graph/context.js.map +1 -1
  10. package/dist/graph/executor.d.ts +2 -1
  11. package/dist/graph/executor.d.ts.map +1 -1
  12. package/dist/graph/executor.js.map +1 -1
  13. package/dist/graph/fetch-graph-client.d.ts +19 -4
  14. package/dist/graph/fetch-graph-client.d.ts.map +1 -1
  15. package/dist/graph/fetch-graph-client.js +87 -17
  16. package/dist/graph/fetch-graph-client.js.map +1 -1
  17. package/dist/graph/fetch-graph-runtime.d.ts +9 -4
  18. package/dist/graph/fetch-graph-runtime.d.ts.map +1 -1
  19. package/dist/graph/fetch-graph-runtime.js +31 -6
  20. package/dist/graph/fetch-graph-runtime.js.map +1 -1
  21. package/dist/graph/fetch-runtime-transport.d.ts +4 -4
  22. package/dist/graph/fetch-runtime-transport.d.ts.map +1 -1
  23. package/dist/graph/fetch-runtime-transport.js +10 -14
  24. package/dist/graph/fetch-runtime-transport.js.map +1 -1
  25. package/dist/graph/graph-hooks.d.ts +2 -1
  26. package/dist/graph/graph-hooks.d.ts.map +1 -1
  27. package/dist/graph/graph-hooks.js +32 -4
  28. package/dist/graph/graph-hooks.js.map +1 -1
  29. package/dist/graph/index.d.ts +2 -0
  30. package/dist/graph/index.d.ts.map +1 -1
  31. package/dist/graph/index.js +2 -0
  32. package/dist/graph/index.js.map +1 -1
  33. package/dist/graph/operation-hooks.d.ts +4 -2
  34. package/dist/graph/operation-hooks.d.ts.map +1 -1
  35. package/dist/graph/operation-hooks.js +4 -2
  36. package/dist/graph/operation-hooks.js.map +1 -1
  37. package/dist/graph/operation-types.d.ts +4 -1
  38. package/dist/graph/operation-types.d.ts.map +1 -1
  39. package/dist/graph/operation-types.js.map +1 -1
  40. package/dist/graph/runtime-graph-client.d.ts +12 -0
  41. package/dist/graph/runtime-graph-client.d.ts.map +1 -0
  42. package/dist/graph/runtime-graph-client.js +34 -0
  43. package/dist/graph/runtime-graph-client.js.map +1 -0
  44. package/dist/graph/websocket-runtime-transport.d.ts +29 -0
  45. package/dist/graph/websocket-runtime-transport.d.ts.map +1 -0
  46. package/dist/graph/websocket-runtime-transport.js +491 -0
  47. package/dist/graph/websocket-runtime-transport.js.map +1 -0
  48. package/package.json +2 -2
@@ -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,gCAAgC,EAEhC,yBAAyB,EACzB,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO,EAGL,KAAK,yBAAyB,EAC9B,KAAK,2BAA2B,EACjC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAEpF,OAAO,EAEL,KAAK,4BAA4B,EAClC,MAAM,8BAA8B,CAAC;AAEtC,MAAM,MAAM,qCAAqC,GAAG;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,4CAA4C,GAAG,qCAAqC,CAAC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CAAC,EAAE,KAAK,GAAG,6BAA6B,CAAC,QAAQ,CAAC,CAAC;IAC5D,UAAU,CAAC,EAAE,KAAK,GAAG,2BAA2B,CAAC,QAAQ,CAAC,CAAC;IAC3D,gBAAgB,CAAC,EAAE,KAAK,GAAG,4BAA4B,CAAC,QAAQ,CAAC,CAAC;IAClE,mBAAmB,CAAC,EAAE,KAAK,GAAG,qCAAqC,CAAC;IACpE,0BAA0B,CAAC,EAAE,KAAK,GAAG,4CAA4C,CAAC;CACnF,CAAC;AA6BF,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"}
@@ -1,9 +1,11 @@
1
1
  'use client';
2
- import { createRuntimeBoundDataGraphApi } from '@ontahi/core/data-graph';
2
+ import { createGraphClientCache, 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
5
  import { createFetchRuntimeTransport, } from './fetch-runtime-transport.js';
6
- const DEFAULT_OPERATIONS_ENDPOINT = '/operations';
6
+ const DEFAULT_LEGACY_OPERATION_ENDPOINT = '/operations';
7
+ const DEFAULT_LEGACY_GRAPH_READ_ENDPOINT = '/graph/reads';
8
+ const DEFAULT_LEGACY_GRAPH_COMMAND_ENDPOINT = '/graph/commands';
7
9
  const DEFAULT_REFLECTED_ENTITY_DATA_ENDPOINT = '/explorer/entities';
8
10
  const DEFAULT_REFLECTED_RELATED_ENTITY_DATA_ENDPOINT = '/explorer/related-entities';
9
11
  const postReflectedEntityDataQuery = async (endpoint, query, fetchRequest) => {
@@ -18,35 +20,103 @@ const postReflectedEntityDataQuery = async (endpoint, query, fetchRequest) => {
18
20
  }
19
21
  return response.json();
20
22
  };
21
- const conventionalOperationOptions = (options) => options.mountPath === undefined
22
- ? {
23
- endpoint: DEFAULT_OPERATIONS_ENDPOINT,
24
- ...options,
25
- }
26
- : options;
27
23
  export const createFetchReflectedEntityDataReader = ({ endpoint = DEFAULT_REFLECTED_ENTITY_DATA_ENDPOINT, fetch: fetchRequest = globalThis.fetch, } = {}) => ({
28
24
  readEntityData: query => postReflectedEntityDataQuery(endpoint, query, fetchRequest),
29
25
  });
30
26
  export const createFetchReflectedRelatedEntityDataReader = ({ endpoint = DEFAULT_REFLECTED_RELATED_ENTITY_DATA_ENDPOINT, fetch: fetchRequest = globalThis.fetch, } = {}) => ({
31
27
  readRelatedEntityData: query => postReflectedEntityDataQuery(endpoint, query, fetchRequest),
32
28
  });
33
- export function createFetchGraphClient({ graphRead = {}, operations = {}, runtimeTransport = {}, reflectedEntityData = {}, reflectedRelatedEntityData = {}, } = {}) {
34
- const operationOptions = operations === false ? undefined : conventionalOperationOptions(operations);
35
- const graphReadCapability = graphRead === false ? undefined : createFetchGraphReadCapability(graphRead);
29
+ export function createFetchGraphClient({ compatibility = {}, graphRead = {}, operations = {}, runtimeTransport = {}, reflectedEntityData = {}, reflectedRelatedEntityData = {}, } = {}) {
30
+ const graphReadOptions = graphRead === false
31
+ ? undefined
32
+ : {
33
+ ...graphRead,
34
+ ...(compatibility.graphRead === undefined
35
+ ? {}
36
+ : {
37
+ endpoint: compatibility.graphRead.endpoint ?? DEFAULT_LEGACY_GRAPH_READ_ENDPOINT,
38
+ }),
39
+ ...(compatibility.graphCommand === undefined
40
+ ? {}
41
+ : {
42
+ commandEndpoint: compatibility.graphCommand.endpoint ?? DEFAULT_LEGACY_GRAPH_COMMAND_ENDPOINT,
43
+ }),
44
+ };
45
+ const clientCache = graphReadOptions ? createGraphClientCache() : undefined;
46
+ const operationOptions = (() => {
47
+ if (operations === false)
48
+ return undefined;
49
+ if (compatibility.operation === undefined)
50
+ return operations;
51
+ const { endpoint: _endpoint, mountPath: _mountPath, ...sharedOptions } = operations;
52
+ if (compatibility.operation.endpoint !== undefined) {
53
+ return { ...sharedOptions, endpoint: compatibility.operation.endpoint };
54
+ }
55
+ if (compatibility.operation.mountPath !== undefined) {
56
+ return { ...sharedOptions, mountPath: compatibility.operation.mountPath };
57
+ }
58
+ return { ...sharedOptions, endpoint: DEFAULT_LEGACY_OPERATION_ENDPOINT };
59
+ })();
60
+ const commonTransportRequired = (graphReadOptions !== undefined &&
61
+ (graphReadOptions.endpoint === undefined ||
62
+ graphReadOptions.commandEndpoint === undefined)) ||
63
+ (operationOptions !== undefined &&
64
+ operationOptions.endpoint === undefined &&
65
+ operationOptions.mountPath === undefined);
66
+ if (runtimeTransport === false && commonTransportRequired) {
67
+ throw new TypeError('runtimeTransport cannot be disabled while a common Runtime Protocol family is enabled.');
68
+ }
69
+ const requestId = runtimeTransport === false
70
+ ? undefined
71
+ : (runtimeTransport.requestId ?? graphReadOptions?.requestId ?? operationOptions?.requestId);
72
+ const runtimeTransportOptions = runtimeTransport === false
73
+ ? undefined
74
+ : {
75
+ ...(graphReadOptions?.fetch ? { fetch: graphReadOptions.fetch } : {}),
76
+ ...(graphReadOptions?.requestInit ? { requestInit: graphReadOptions.requestInit } : {}),
77
+ ...runtimeTransport,
78
+ requestId,
79
+ };
80
+ const resolvedRuntimeTransport = runtimeTransportOptions === undefined
81
+ ? undefined
82
+ : createFetchRuntimeTransport(runtimeTransportOptions);
83
+ const graphReadCapability = graphReadOptions === undefined
84
+ ? undefined
85
+ : createFetchGraphReadCapability({
86
+ ...graphReadOptions,
87
+ ...(runtimeTransportOptions?.fetch ? { fetch: runtimeTransportOptions.fetch } : {}),
88
+ ...(runtimeTransportOptions?.requestInit
89
+ ? { requestInit: runtimeTransportOptions.requestInit }
90
+ : {}),
91
+ ...(resolvedRuntimeTransport
92
+ ? { runtimeTransport: resolvedRuntimeTransport, requestId }
93
+ : {}),
94
+ });
95
+ const resolvedOperationOptions = operationOptions === undefined
96
+ ? undefined
97
+ : {
98
+ ...operationOptions,
99
+ ...(runtimeTransportOptions?.fetch ? { fetch: runtimeTransportOptions.fetch } : {}),
100
+ ...(runtimeTransportOptions?.requestInit
101
+ ? { requestInit: runtimeTransportOptions.requestInit }
102
+ : {}),
103
+ ...(resolvedRuntimeTransport
104
+ ? { runtimeTransport: resolvedRuntimeTransport, requestId }
105
+ : {}),
106
+ };
36
107
  return {
37
108
  ...(graphReadCapability
38
109
  ? {
39
110
  graph: createRuntimeBoundDataGraphApi(() => graphReadCapability.runtime),
40
111
  graphExecutor: graphReadCapability.graphExecutor,
112
+ clientCache: clientCache,
41
113
  }
42
114
  : {}),
43
- ...(runtimeTransport === false
44
- ? {}
45
- : { runtimeTransport: createFetchRuntimeTransport(runtimeTransport) }),
46
- ...(operationOptions
115
+ ...(resolvedRuntimeTransport ? { runtimeTransport: resolvedRuntimeTransport } : {}),
116
+ ...(resolvedOperationOptions
47
117
  ? {
48
- operationBridgeAdapters: [createFetchOperationBridgeAdapter(operationOptions)],
49
- reflectedOperationInvoker: createFetchReflectedOperationInvoker(operationOptions),
118
+ operationBridgeAdapters: [createFetchOperationBridgeAdapter(resolvedOperationOptions)],
119
+ reflectedOperationInvoker: createFetchReflectedOperationInvoker(resolvedOperationOptions),
50
120
  }
51
121
  : {}),
52
122
  ...(reflectedEntityData === false
@@ -1 +1 @@
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,CAAC,CAAC,OAAO,CAAC;AAEd,MAAM,CAAC,MAAM,oCAAoC,GAAG,CAAC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C,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
+ {"version":3,"file":"fetch-graph-client.js","sourceRoot":"","sources":["../../src/graph/fetch-graph-client.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAYb,OAAO,EAAE,sBAAsB,EAAE,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AAGjG,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;AAqDtC,MAAM,iCAAiC,GAAG,aAAa,CAAC;AACxD,MAAM,kCAAkC,GAAG,cAAc,CAAC;AAC1D,MAAM,qCAAqC,GAAG,iBAAiB,CAAC;AAChE,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,E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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 GraphClientCache,\n ReflectedEntityDataReader,\n ReflectedEntityDataResult,\n ReflectedRelatedEntityDataReader,\n ReflectedRelatedEntityDataQuery,\n ReflectedOperationInvoker,\n RemoteDataGraphError,\n RuntimeBoundDataGraphApi,\n} from '@ontahi/core/data-graph';\nimport { createGraphClientCache, 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 clientCache?: GraphClientCache;\n runtimeTransport?: RuntimeTransport<TReadOptions | TCommandOptions>;\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 clientCache: GraphClientCache;\n};\n\nexport type FetchGraphClientCompatibilityOptions = {\n operation?: {\n endpoint?: string;\n mountPath?: string;\n };\n graphRead?: {\n endpoint?: string;\n };\n graphCommand?: {\n endpoint?: string;\n };\n};\n\nexport type FetchGraphClientOptions<TOptions = undefined> = {\n compatibility?: FetchGraphClientCompatibilityOptions;\n graphRead?: false | FetchGraphReadExecutorOptions<TOptions>;\n operations?: false | FetchOperationBridgeOptions<TOptions>;\n runtimeTransport?: false | FetchRuntimeTransportOptions<TOptions>;\n reflectedEntityData?: false | FetchReflectedEntityDataReaderOptions;\n reflectedRelatedEntityData?: false | FetchReflectedRelatedEntityDataReaderOptions;\n};\n\nconst DEFAULT_LEGACY_OPERATION_ENDPOINT = '/operations';\nconst DEFAULT_LEGACY_GRAPH_READ_ENDPOINT = '/graph/reads';\nconst DEFAULT_LEGACY_GRAPH_COMMAND_ENDPOINT = '/graph/commands';\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\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 compatibility = {},\n graphRead = {},\n operations = {},\n runtimeTransport = {},\n reflectedEntityData = {},\n reflectedRelatedEntityData = {},\n}: FetchGraphClientOptions<TOptions> = {}): OntahiGraphClient<TOptions, TOptions> {\n const graphReadOptions =\n graphRead === false\n ? undefined\n : {\n ...graphRead,\n ...(compatibility.graphRead === undefined\n ? {}\n : {\n endpoint: compatibility.graphRead.endpoint ?? DEFAULT_LEGACY_GRAPH_READ_ENDPOINT,\n }),\n ...(compatibility.graphCommand === undefined\n ? {}\n : {\n commandEndpoint:\n compatibility.graphCommand.endpoint ?? DEFAULT_LEGACY_GRAPH_COMMAND_ENDPOINT,\n }),\n };\n const clientCache = graphReadOptions ? createGraphClientCache() : undefined;\n const operationOptions = (() => {\n if (operations === false) return undefined;\n if (compatibility.operation === undefined) return operations;\n const { endpoint: _endpoint, mountPath: _mountPath, ...sharedOptions } = operations;\n if (compatibility.operation.endpoint !== undefined) {\n return { ...sharedOptions, endpoint: compatibility.operation.endpoint };\n }\n if (compatibility.operation.mountPath !== undefined) {\n return { ...sharedOptions, mountPath: compatibility.operation.mountPath };\n }\n return { ...sharedOptions, endpoint: DEFAULT_LEGACY_OPERATION_ENDPOINT };\n })();\n const commonTransportRequired =\n (graphReadOptions !== undefined &&\n (graphReadOptions.endpoint === undefined ||\n graphReadOptions.commandEndpoint === undefined)) ||\n (operationOptions !== undefined &&\n operationOptions.endpoint === undefined &&\n operationOptions.mountPath === undefined);\n if (runtimeTransport === false && commonTransportRequired) {\n throw new TypeError(\n 'runtimeTransport cannot be disabled while a common Runtime Protocol family is enabled.',\n );\n }\n const requestId =\n runtimeTransport === false\n ? undefined\n : (runtimeTransport.requestId ?? graphReadOptions?.requestId ?? operationOptions?.requestId);\n const runtimeTransportOptions =\n runtimeTransport === false\n ? undefined\n : {\n ...(graphReadOptions?.fetch ? { fetch: graphReadOptions.fetch } : {}),\n ...(graphReadOptions?.requestInit ? { requestInit: graphReadOptions.requestInit } : {}),\n ...runtimeTransport,\n requestId,\n };\n const resolvedRuntimeTransport =\n runtimeTransportOptions === undefined\n ? undefined\n : createFetchRuntimeTransport<TOptions>(runtimeTransportOptions);\n const graphReadCapability =\n graphReadOptions === undefined\n ? undefined\n : createFetchGraphReadCapability({\n ...graphReadOptions,\n ...(runtimeTransportOptions?.fetch ? { fetch: runtimeTransportOptions.fetch } : {}),\n ...(runtimeTransportOptions?.requestInit\n ? { requestInit: runtimeTransportOptions.requestInit }\n : {}),\n ...(resolvedRuntimeTransport\n ? { runtimeTransport: resolvedRuntimeTransport, requestId }\n : {}),\n });\n const resolvedOperationOptions =\n operationOptions === undefined\n ? undefined\n : {\n ...operationOptions,\n ...(runtimeTransportOptions?.fetch ? { fetch: runtimeTransportOptions.fetch } : {}),\n ...(runtimeTransportOptions?.requestInit\n ? { requestInit: runtimeTransportOptions.requestInit }\n : {}),\n ...(resolvedRuntimeTransport\n ? { runtimeTransport: resolvedRuntimeTransport, requestId }\n : {}),\n };\n\n return {\n ...(graphReadCapability\n ? {\n graph: createRuntimeBoundDataGraphApi(() => graphReadCapability.runtime),\n graphExecutor: graphReadCapability.graphExecutor,\n clientCache: clientCache!,\n }\n : {}),\n ...(resolvedRuntimeTransport ? { runtimeTransport: resolvedRuntimeTransport } : {}),\n ...(resolvedOperationOptions\n ? {\n operationBridgeAdapters: [createFetchOperationBridgeAdapter(resolvedOperationOptions)],\n reflectedOperationInvoker: createFetchReflectedOperationInvoker(resolvedOperationOptions),\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,17 +1,22 @@
1
- import { type DataGraphExecutionRuntime, type EntityMutationCommandExecutionRuntime, type RemoteDataGraphError, type ManyToManyRelationshipCommandExecutionRuntime, type RelationshipCommandExecutionRuntime } from '@ontahi/core/data-graph';
1
+ import { type DataGraphExecutionRuntime, type DataGraphObservationRuntime, type EntityMutationCommandExecutionRuntime, type RemoteDataGraphError, type ManyToManyRelationshipCommandExecutionRuntime, type OrderedRelationshipCommandExecutionRuntime, type RelationshipCommandExecutionRuntime } from '@ontahi/core/data-graph';
2
+ import { type RuntimeTransport } from '@ontahi/core/runtime/protocol';
2
3
  import type { ReactGraphExecutor } from './executor.js';
3
4
  export type FetchGraphReadExecutorOptions<TOptions = undefined> = {
5
+ /** @deprecated Select the legacy Graph Read route through createFetchGraphClient compatibility. */
4
6
  endpoint?: string;
7
+ /** @deprecated Select the legacy Graph Command route through createFetchGraphClient compatibility. */
5
8
  commandEndpoint?: string;
6
9
  fetch?: typeof globalThis.fetch;
10
+ requestId?: () => string;
7
11
  requestInit?: (options?: TOptions) => Omit<RequestInit, 'body' | 'method'>;
12
+ runtimeTransport?: RuntimeTransport<TOptions>;
8
13
  };
9
- export type FetchGraphRuntime<TOptions = undefined> = DataGraphExecutionRuntime<RemoteDataGraphError, TOptions, TOptions, RemoteDataGraphError>;
10
- export type FetchRelationshipRuntime<TOptions = undefined> = RelationshipCommandExecutionRuntime<RemoteDataGraphError, TOptions> & ManyToManyRelationshipCommandExecutionRuntime<RemoteDataGraphError, TOptions>;
14
+ export type FetchGraphRuntime<TOptions = undefined> = DataGraphExecutionRuntime<RemoteDataGraphError, TOptions, TOptions, RemoteDataGraphError> & DataGraphObservationRuntime<RemoteDataGraphError, TOptions>;
15
+ export type FetchRelationshipRuntime<TOptions = undefined> = RelationshipCommandExecutionRuntime<RemoteDataGraphError, TOptions> & ManyToManyRelationshipCommandExecutionRuntime<RemoteDataGraphError, TOptions> & OrderedRelationshipCommandExecutionRuntime<RemoteDataGraphError, TOptions>;
11
16
  export type FetchEntityMutationRuntime<TOptions = undefined> = EntityMutationCommandExecutionRuntime<RemoteDataGraphError, TOptions>;
12
17
  export type FetchGraphReadCapability<TOptions = undefined> = {
13
18
  runtime: FetchGraphRuntime<TOptions> & FetchRelationshipRuntime<TOptions> & FetchEntityMutationRuntime<TOptions>;
14
19
  graphExecutor: ReactGraphExecutor<TOptions, TOptions>;
15
20
  };
16
- export declare const createFetchGraphReadCapability: <TOptions = undefined>({ endpoint, commandEndpoint, fetch: fetchRequest, requestInit, }?: FetchGraphReadExecutorOptions<TOptions>) => FetchGraphReadCapability<TOptions>;
21
+ export declare const createFetchGraphReadCapability: <TOptions = undefined>({ endpoint, commandEndpoint, fetch: fetchRequest, requestId, requestInit, runtimeTransport, }?: FetchGraphReadExecutorOptions<TOptions>) => FetchGraphReadCapability<TOptions>;
17
22
  //# sourceMappingURL=fetch-graph-runtime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch-graph-runtime.d.ts","sourceRoot":"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Q,CACT,GACC,6CAA6C,CAAC,oBAAoB,EAAE,QAAQ,CAAC,GAC7E,0CAA0C,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAC;AAC7E,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;AAEF,eAAO,MAAM,8BAA8B,GAAI,QAAQ,GAAG,SAAS,EAAE,gGAOlE,6BAA6B,CAAC,QAAQ,CAAM,KAAG,wBAAwB,CAAC,QAAQ,CAoGlF,CAAC"}
@@ -1,10 +1,10 @@
1
1
  'use client';
2
2
  import { createRemoteDataGraphRuntime, isGraphCommandRejection, isGraphCommandProtocolError, isGraphReadProtocolError, } from '@ontahi/core/data-graph';
3
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) => {
4
+ import { createRuntimeProtocolExchange, } from '@ontahi/core/runtime/protocol';
5
+ import { createFetchRuntimeTransport } from './fetch-runtime-transport.js';
6
+ export const createFetchGraphReadCapability = ({ endpoint, commandEndpoint, fetch: fetchRequest = globalThis.fetch, requestId, requestInit, runtimeTransport, } = {}) => {
7
+ const legacyReadTransport = async (request, options) => {
8
8
  const init = requestInit?.(options) ?? {};
9
9
  const headers = new Headers(init.headers);
10
10
  if (!headers.has('content-type'))
@@ -27,7 +27,7 @@ export const createFetchGraphReadCapability = ({ endpoint = DEFAULT_GRAPH_READ_E
27
27
  throw new Error(`Graph read request failed with status ${response.status}.`);
28
28
  }
29
29
  };
30
- const commandTransport = async (request, options) => {
30
+ const legacyCommandTransport = async (request, options) => {
31
31
  const init = requestInit?.(options) ?? {};
32
32
  const headers = new Headers(init.headers);
33
33
  if (!headers.has('content-type'))
@@ -47,7 +47,31 @@ export const createFetchGraphReadCapability = ({ endpoint = DEFAULT_GRAPH_READ_E
47
47
  }
48
48
  return payload;
49
49
  };
50
- const runtime = createRemoteDataGraphRuntime({ transport, commandTransport });
50
+ const exchange = endpoint && commandEndpoint
51
+ ? undefined
52
+ : createRuntimeProtocolExchange({
53
+ transport: runtimeTransport ??
54
+ createFetchRuntimeTransport({ fetch: fetchRequest, requestInit }),
55
+ requestId,
56
+ });
57
+ const exchangeOptions = (options) => options === undefined ? undefined : { transportOptions: options };
58
+ const transport = endpoint
59
+ ? legacyReadTransport
60
+ : (request, options) => exchange({ family: 'graph.read', body: request }, exchangeOptions(options));
61
+ const commandTransport = commandEndpoint
62
+ ? legacyCommandTransport
63
+ : (request, options) => exchange({ family: 'graph.command', body: request }, exchangeOptions(options));
64
+ const observeTransport = runtimeTransport?.graph
65
+ ? (request, options, lifecycle) => runtimeTransport.graph.observe(request, {
66
+ ...exchangeOptions(options),
67
+ signal: lifecycle?.signal,
68
+ })
69
+ : undefined;
70
+ const runtime = createRemoteDataGraphRuntime({
71
+ transport,
72
+ commandTransport,
73
+ ...(observeTransport ? { observeTransport } : {}),
74
+ });
51
75
  return {
52
76
  runtime,
53
77
  graphExecutor: {
@@ -57,6 +81,7 @@ export const createFetchGraphReadCapability = ({ endpoint = DEFAULT_GRAPH_READ_E
57
81
  runCommand: (command, options) => runBrowserEffect(runtime.runCommand(command, options)),
58
82
  runRelationshipCommand: (command, options) => runBrowserEffect(runtime.runRelationshipCommand(command, options)),
59
83
  runManyToManyRelationshipCommand: (command, options) => runBrowserEffect(runtime.runManyToManyRelationshipCommand(command, options)),
84
+ runOrderedRelationshipCommand: (command, options) => runBrowserEffect(runtime.runOrderedRelationshipCommand(command, options)),
60
85
  runEntityMutationCommand: (command, options) => runBrowserEffect(runtime.runEntityMutationCommand(command, options)),
61
86
  },
62
87
  };
@@ -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,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;IACrF,MAAM,SAAS,GAAuC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE;QAC/E,MAAM,IAAI,GAAG,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAC1C,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;YAAE,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;QAElF,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,QAAQ,EAAE;YAC5C,GAAG,IAAI;YACP,MAAM,EAAE,MAAM;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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"]}
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,GAWzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EACL,6BAA6B,GAG9B,MAAM,+BAA+B,CAAC;AAGvC,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAoC3E,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAuB,EACnE,QAAQ,EACR,eAAe,EACf,KAAK,EAAE,YAAY,GAAG,UAAU,CAAC,KAAK,EACtC,SAAS,EACT,WAAW,EACX,gBAAgB,MAC2B,EAAE,EAAsC,EAAE;IACrF,MAAM,mBAAmB,GAAuC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE;QACzF,MAAM,IAAI,GAAG,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAC1C,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;YAAE,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;QAElF,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,QAAS,EAAE;YAC7C,GAAG,IAAI;YACP,MAAM,EAAE,MAAM;YACd,OAAO;YACP,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,aAAa;YAC9C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;SAC9B,CAAC,CAAC;QAEH,IAAI,CAAC;YACH,MAAM,OAAO,GAAY,MAAM,QAAQ,CAAC,IAAI,E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CAAC;AACJ,CAAC,CAAC","sourcesContent":["'use client';\n\nimport {\n createRemoteDataGraphRuntime,\n isGraphCommandRejection,\n isGraphCommandProtocolError,\n isGraphReadProtocolError,\n type DataGraphExecutionRuntime,\n type DataGraphObservationRuntime,\n type EntityMutationCommandExecutionRuntime,\n type RemoteDataGraphError,\n type RemoteGraphCommandTransport,\n type RemoteGraphObservationTransport,\n type RemoteGraphReadTransport,\n type ManyToManyRelationshipCommandExecutionRuntime,\n type OrderedRelationshipCommandExecutionRuntime,\n type RelationshipCommandExecutionRuntime,\n} from '@ontahi/core/data-graph';\nimport { runBrowserEffect } from '@ontahi/core/runtime/browser';\nimport {\n createRuntimeProtocolExchange,\n type RuntimeTransport,\n type RuntimeTransportRequestOptions,\n} from '@ontahi/core/runtime/protocol';\n\nimport type { ReactGraphExecutor } from './executor.js';\nimport { createFetchRuntimeTransport } from './fetch-runtime-transport.js';\n\nexport type FetchGraphReadExecutorOptions<TOptions = undefined> = {\n /** @deprecated Select the legacy Graph Read route through createFetchGraphClient compatibility. */\n endpoint?: string;\n /** @deprecated Select the legacy Graph Command route through createFetchGraphClient compatibility. */\n commandEndpoint?: string;\n fetch?: typeof globalThis.fetch;\n requestId?: () => string;\n requestInit?: (options?: TOptions) => Omit<RequestInit, 'body' | 'method'>;\n runtimeTransport?: RuntimeTransport<TOptions>;\n};\n\nexport type FetchGraphRuntime<TOptions = undefined> = DataGraphExecutionRuntime<\n RemoteDataGraphError,\n TOptions,\n TOptions,\n RemoteDataGraphError\n> &\n DataGraphObservationRuntime<RemoteDataGraphError, TOptions>;\nexport type FetchRelationshipRuntime<TOptions = undefined> = RelationshipCommandExecutionRuntime<\n RemoteDataGraphError,\n TOptions\n> &\n ManyToManyRelationshipCommandExecutionRuntime<RemoteDataGraphError, TOptions> &\n OrderedRelationshipCommandExecutionRuntime<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\nexport const createFetchGraphReadCapability = <TOptions = undefined>({\n endpoint,\n commandEndpoint,\n fetch: fetchRequest = globalThis.fetch,\n requestId,\n requestInit,\n runtimeTransport,\n}: FetchGraphReadExecutorOptions<TOptions> = {}): FetchGraphReadCapability<TOptions> => {\n const legacyReadTransport: 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 legacyCommandTransport: RemoteGraphCommandTransport<TOptions> = async (\n request,\n options,\n ) => {\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 exchange =\n endpoint && commandEndpoint\n ? undefined\n : createRuntimeProtocolExchange({\n transport:\n runtimeTransport ??\n createFetchRuntimeTransport<TOptions>({ fetch: fetchRequest, requestInit }),\n requestId,\n });\n const exchangeOptions = (\n options: TOptions | undefined,\n ): RuntimeTransportRequestOptions<TOptions> | undefined =>\n options === undefined ? undefined : { transportOptions: options };\n const transport: RemoteGraphReadTransport<TOptions> = endpoint\n ? legacyReadTransport\n : (request, options) =>\n exchange!({ family: 'graph.read', body: request }, exchangeOptions(options));\n const commandTransport: RemoteGraphCommandTransport<TOptions> = commandEndpoint\n ? legacyCommandTransport\n : (request, options) =>\n exchange!({ family: 'graph.command', body: request }, exchangeOptions(options));\n const observeTransport: RemoteGraphObservationTransport<TOptions> | undefined =\n runtimeTransport?.graph\n ? (request, options, lifecycle) =>\n runtimeTransport.graph!.observe(request, {\n ...exchangeOptions(options),\n signal: lifecycle?.signal,\n })\n : undefined;\n const runtime = createRemoteDataGraphRuntime({\n transport,\n commandTransport,\n ...(observeTransport ? { observeTransport } : {}),\n });\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 runOrderedRelationshipCommand: (command, options) =>\n runBrowserEffect(runtime.runOrderedRelationshipCommand(command, options)),\n runEntityMutationCommand: (command, options) =>\n runBrowserEffect(runtime.runEntityMutationCommand(command, options)),\n },\n };\n};\n"]}
@@ -1,15 +1,15 @@
1
1
  import { type DurableOperationObservationCapability, type RuntimeTransport } from '@ontahi/core/runtime/protocol';
2
- export type FetchRuntimeTransportOptions = {
2
+ export type FetchRuntimeTransportOptions<TTransportOptions = undefined> = {
3
3
  endpoint?: string;
4
4
  fetch?: typeof globalThis.fetch;
5
5
  requestId?: () => string;
6
- requestInit?: () => Omit<RequestInit, 'body' | 'method' | 'signal'>;
6
+ requestInit?: (options?: TTransportOptions) => Omit<RequestInit, 'body' | 'method'>;
7
7
  durableOperation?: {
8
8
  pollIntervalMs?: number;
9
9
  };
10
10
  };
11
- export type FetchRuntimeTransport = RuntimeTransport & {
11
+ export type FetchRuntimeTransport<TTransportOptions = undefined> = RuntimeTransport<TTransportOptions> & {
12
12
  readonly durableOperation: DurableOperationObservationCapability;
13
13
  };
14
- export declare const createFetchRuntimeTransport: ({ endpoint, fetch: fetchRequest, requestId, requestInit, durableOperation, }?: FetchRuntimeTransportOptions) => FetchRuntimeTransport;
14
+ export declare const createFetchRuntimeTransport: <TTransportOptions = undefined>({ endpoint, fetch: fetchRequest, requestId, requestInit, durableOperation, }?: FetchRuntimeTransportOptions<TTransportOptions>) => FetchRuntimeTransport<TTransportOptions>;
15
15
  //# sourceMappingURL=fetch-runtime-transport.d.ts.map
@@ -1 +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"}
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,CAAC,iBAAiB,GAAG,SAAS,IAAI;IACxE,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,CAAC,OAAO,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC;IACpF,gBAAgB,CAAC,EAAE;QACjB,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,qBAAqB,CAAC,iBAAiB,GAAG,SAAS,IAC7D,gBAAgB,CAAC,iBAAiB,CAAC,GAAG;IACpC,QAAQ,CAAC,gBAAgB,EAAE,qCAAqC,CAAC;CAClE,CAAC;AA4BJ,eAAO,MAAM,2BAA2B,GAAI,iBAAiB,GAAG,SAAS,EAAE,+EAMxE,4BAA4B,CAAC,iBAAiB,CAAM,KAAG,qBAAqB,CAAC,iBAAiB,CAmEhG,CAAC"}
@@ -1,11 +1,8 @@
1
1
  'use client';
2
- import { createRuntimeProtocolRequest, isRuntimeProtocolError, parseDurableOperationProtocolResponse, parseRuntimeProtocolResponse, toDurableOperationProtocolRequest, } from '@ontahi/core/runtime/protocol';
2
+ import { createRuntimeProtocolExchange, isRuntimeProtocolError, parseDurableOperationProtocolResponse, parseRuntimeProtocolResponse, toDurableOperationProtocolRequest, } from '@ontahi/core/runtime/protocol';
3
3
  const DEFAULT_RUNTIME_ENDPOINT = '/runtime';
4
4
  const DEFAULT_POLL_INTERVAL_MS = 500;
5
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
6
  const waitForNextInspection = (intervalMs, signal) => {
10
7
  if (signal?.aborted)
11
8
  return Promise.resolve(false);
@@ -26,13 +23,13 @@ const waitForNextInspection = (intervalMs, signal) => {
26
23
  signal?.addEventListener('abort', abort, { once: true });
27
24
  });
28
25
  };
29
- export const createFetchRuntimeTransport = ({ endpoint = DEFAULT_RUNTIME_ENDPOINT, fetch: fetchRequest = globalThis.fetch, requestId = defaultRequestId, requestInit, durableOperation = {}, } = {}) => {
26
+ export const createFetchRuntimeTransport = ({ endpoint = DEFAULT_RUNTIME_ENDPOINT, fetch: fetchRequest = globalThis.fetch, requestId, requestInit, durableOperation = {}, } = {}) => {
30
27
  const pollIntervalMs = durableOperation.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
31
28
  if (!Number.isFinite(pollIntervalMs) || pollIntervalMs < 0) {
32
29
  throw new TypeError('Durable Operation poll interval must be a non-negative finite number.');
33
30
  }
34
31
  const request = async (runtimeRequest, options) => {
35
- const init = requestInit?.() ?? {};
32
+ const init = requestInit?.(options?.transportOptions) ?? {};
36
33
  const headers = new Headers(init.headers);
37
34
  if (!headers.has('content-type'))
38
35
  headers.set('content-type', 'application/json');
@@ -53,18 +50,17 @@ export const createFetchRuntimeTransport = ({ endpoint = DEFAULT_RUNTIME_ENDPOIN
53
50
  }
54
51
  return parsed.response;
55
52
  };
53
+ const exchange = createRuntimeProtocolExchange({
54
+ transport: { request },
55
+ requestId,
56
+ });
56
57
  const observe = async function* (run, options) {
57
58
  while (!options?.signal?.aborted) {
58
- const runtimeRequest = createRuntimeProtocolRequest({
59
- id: requestId(),
59
+ const responseBody = await exchange({
60
60
  family: 'durable.operation',
61
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);
62
+ }, options?.signal ? { signal: options.signal } : undefined);
63
+ const parsed = parseDurableOperationProtocolResponse(responseBody);
68
64
  if (!parsed.success)
69
65
  throw new Error(parsed.error.error.message);
70
66
  if (parsed.response.kind === 'protocol-error') {
@@ -1 +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,4BAA4B,EAC5B,iCAAiC,GAKlC,MAAM,+BAA+B,CAAC;AAgBvC,MAAM,wBAAwB,GAAG,UAAU,CAAC;AAC5C,MAAM,wBAAwB,GAAG,GAAG,CAAC;AACrC,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;AAC3E,IAAI,uBAAuB,GAAG,CAAC,CAAC;AAEhC,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAC5B,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE;IACjC,kBAAkB,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,uBAAuB,IAAI,CAAC,CAAC,EAAE,CAAC;AAEnE,MAAM,qBAAqB,GAAG,CAC5B,UAAkB,EAClB,MAA+B,EACb,EAAE;IACpB,IAAI,MAAM,EAAE,OAAO;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnD,IAAI,UAAU,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnD,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QAC3B,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,MAAM,M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ahi/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
+ {"version":3,"file":"fetch-runtime-transport.js","sourceRoot":"","sources":["../../src/graph/fetch-runtime-transport.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAGb,OAAO,EACL,6BAA6B,EAC7B,sBAAsB,EACtB,qCAAqC,EACrC,4BAA4B,EAC5B,iCAAiC,GAKlC,MAAM,+BAA+B,CAAC;AAiBvC,MAAM,wBAAwB,GAAG,UAAU,CAAC;AAC5C,MAAM,wBAAwB,GAAG,GAAG,CAAC;AACrC,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;AAE3E,MAAM,qBAAqB,GAAG,CAC5B,UAAkB,EAClB,MAA+B,EACb,EAAE;IACpB,IAAI,MAAM,EAAE,OAAO;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnD,IAAI,UAAU,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnD,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QAC3B,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,MAAM,MAAM,GAAG,CAAC,cAAuB,EAAE,EAAE;YACzC,IAAI,OAAO;gBAAE,OAAO;YACpB,OAAO,GAAG,IAAI,CAAC;YACf,YAAY,CAAC,OAAO,CAAC,CAAC;YACtB,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC5C,OAAO,CAAC,cAAc,CAAC,CAAC;QAC1B,CAAC,CAAC;QACF,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAClC,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,CAAC;QAC3D,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,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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 createRuntimeProtocolExchange,\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<TTransportOptions = undefined> = {\n endpoint?: string;\n fetch?: typeof globalThis.fetch;\n requestId?: () => string;\n requestInit?: (options?: TTransportOptions) => Omit<RequestInit, 'body' | 'method'>;\n durableOperation?: {\n pollIntervalMs?: number;\n };\n};\n\nexport type FetchRuntimeTransport<TTransportOptions = undefined> =\n RuntimeTransport<TTransportOptions> & {\n readonly durableOperation: DurableOperationObservationCapability;\n };\n\nconst DEFAULT_RUNTIME_ENDPOINT = '/runtime';\nconst DEFAULT_POLL_INTERVAL_MS = 500;\nconst terminalTaskStatuses = new Set(['completed', 'failed', 'cancelled']);\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 = <TTransportOptions = undefined>({\n endpoint = DEFAULT_RUNTIME_ENDPOINT,\n fetch: fetchRequest = globalThis.fetch,\n requestId,\n requestInit,\n durableOperation = {},\n}: FetchRuntimeTransportOptions<TTransportOptions> = {}): FetchRuntimeTransport<TTransportOptions> => {\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<TTransportOptions>,\n ) => {\n const init = requestInit?.(options?.transportOptions) ?? {};\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 const exchange = createRuntimeProtocolExchange({\n transport: { request },\n requestId,\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 responseBody = await exchange(\n {\n family: 'durable.operation',\n body: toDurableOperationProtocolRequest(run),\n },\n options?.signal ? { signal: options.signal } : undefined,\n );\n\n const parsed = parseDurableOperationProtocolResponse(responseBody);\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,9 @@
1
- import { type ManyToManyRelationshipCommand, type RelationshipCommandResult } from '@ontahi/core/data-graph';
1
+ import { type ManyToManyRelationshipCommand, type OrderedRelationshipCommand, 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
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
+ export declare function useOrderedRelationshipCommand<TVariables, TContext = unknown, TReadOptions = unknown, TCommandOptions = TReadOptions>(buildCommand: (variables: TVariables) => OrderedRelationshipCommand, options?: GraphCommandHookOptions<RelationshipCommandResult, TVariables, TContext, TCommandOptions>): UseMutationResult<RelationshipCommandResult, Error, TVariables, TContext>;
7
8
  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
9
  //# 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,yBAAyB,EAG/B,MAAM,yBAAyB,CAAC;AAEjC,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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raphReadExpression, normalizeGraphSchemaClientInput, resolveQuerySpec, toGraphReadRequest, } from '@ontahi/core/data-graph';
2
+ import { getGraphReadOutputDescriptor, graphOutput, isGraphReadExpression, normalizeGraphSchemaClientInput, resolveQuerySpec, toGraphReadRequest, } from '@ontahi/core/data-graph';
3
3
  import { executionIdentityCacheKey } from '@ontahi/core/runtime/identity';
4
4
  import { useMutation, useQuery, useQueryClient, } from '@tanstack/react-query';
5
- import { useExecutionIdentity, useGraphExecutor } from './context.js';
5
+ import { useExecutionIdentity, useGraphClientCache, useGraphExecutor } from './context.js';
6
6
  const isQueryOrView = (read) => 'kind' in read;
7
7
  const isBuildableRead = (read) => typeof read.build === 'function';
8
8
  const isNamedView = (read) => 'kind' in read && read.kind === 'view';
@@ -35,14 +35,16 @@ const deriveGraphQueryKey = (read, intent, params, identityKey) => {
35
35
  export function useGraphQuery(read, options) {
36
36
  const graphExecutor = useGraphExecutor();
37
37
  const identity = useExecutionIdentity();
38
+ const clientCache = useGraphClientCache();
38
39
  const expression = isGraphReadExpression(read) ? read : undefined;
39
40
  const source = (expression?.read ?? read);
40
41
  const mode = options?.mode ?? 'run';
41
42
  const intent = expression?.intent ?? intentFromMode(mode);
43
+ const queryKey = options?.queryKey ??
44
+ deriveGraphQueryKey(source, intent, options?.params, executionIdentityCacheKey(identity));
42
45
  return useQuery({
43
46
  ...options,
44
- queryKey: options?.queryKey ??
45
- deriveGraphQueryKey(source, intent, options?.params, executionIdentityCacheKey(identity)),
47
+ queryKey,
46
48
  queryFn: async () => {
47
49
  const resolved = resolveGraphRead(source);
48
50
  const params = options?.params;
@@ -53,6 +55,12 @@ export function useGraphQuery(read, options) {
53
55
  : intent === 'exists'
54
56
  ? (await graphExecutor.get(resolved, params, options?.runtimeOptions)) != null
55
57
  : await graphExecutor.get(resolved, params, options?.runtimeOptions);
58
+ const descriptor = intent === 'count' || intent === 'exists'
59
+ ? graphOutput.opaque()
60
+ : getGraphReadOutputDescriptor(resolved, params);
61
+ clientCache.writeOutput(queryKey, descriptor.kind === 'graph-output.array' && intent !== 'many'
62
+ ? graphOutput.nullable(descriptor.item)
63
+ : descriptor, value, { kind: 'graph-read', name: resolveQuerySpec(resolved, params).root.name });
56
64
  return value;
57
65
  },
58
66
  });
@@ -92,6 +100,26 @@ export function useManyToManyRelationshipCommand(buildCommand, options) {
92
100
  },
93
101
  });
94
102
  }
103
+ export function useOrderedRelationshipCommand(buildCommand, options) {
104
+ const graphExecutor = useGraphExecutor();
105
+ const queryClient = useQueryClient();
106
+ return useMutation({
107
+ ...options,
108
+ mutationKey: options?.mutationKey,
109
+ mutationFn: variables => {
110
+ if (!graphExecutor.runOrderedRelationshipCommand) {
111
+ throw new Error('Graph executor does not support ordered Relationship Commands.');
112
+ }
113
+ return graphExecutor.runOrderedRelationshipCommand(buildCommand(variables), options?.runtimeOptions);
114
+ },
115
+ onSuccess: async (data, variables, onMutateResult, context) => {
116
+ for (const queryKey of options?.invalidateQueryKeys ?? []) {
117
+ await queryClient.invalidateQueries({ queryKey });
118
+ }
119
+ await options?.onSuccess?.(data, variables, onMutateResult, context);
120
+ },
121
+ });
122
+ }
95
123
  export function useGraphOperation(operation, options) {
96
124
  const buildCommand = (variables) => operation.run((operation.input
97
125
  ? normalizeGraphSchemaClientInput(operation.input, variables)