@ontahi/runtime-nextjs 0.1.0-alpha.3 → 0.1.0-alpha.5

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
@@ -2,11 +2,15 @@
2
2
 
3
3
  Next.js runtime adapters for Ontahi applications.
4
4
 
5
+ See [Application Data Access](../../docs/application-data-access.md) for the shared Query, policy,
6
+ client View, and React model before choosing the Next.js route adapter below.
7
+
5
8
  This package depends on `@ontahi/core` and owns the Next.js / `next-safe-action` transport layer. It currently contains:
6
9
 
7
10
  1. `@ontahi/runtime-nextjs/actions`: compatibility re-exports for generic action runtime metadata and result helpers from `@ontahi/core/runtime/actions`.
8
11
  2. `@ontahi/runtime-nextjs/actions/server`: server-only `next-safe-action` transport and feature action factory helpers.
9
12
  3. `@ontahi/runtime-nextjs/operation-invocation`: an App Router `Request`/`Response` adapter for the transport-neutral operation invocation protocol from `@ontahi/core`.
13
+ 4. `@ontahi/runtime-nextjs/graph-read`: an App Router adapter for policy-scoped remote data graph reads.
10
14
 
11
15
  New generic consumers should import action metadata and result helpers from `@ontahi/core/runtime/actions`. React hooks and operation bridge adapters live in `@ontahi/react/actions` so this package can stay focused on Next.js runtime concerns.
12
16
 
@@ -24,3 +28,40 @@ const POST = createNextOperationInvocationRouteHandler({
24
28
 
25
29
  The Principal and resource map remain scoped to that invocation and are visible to operation
26
30
  requirements, execution, nested operations, and permission checks.
31
+
32
+ ## Data graph reads
33
+
34
+ Create one dispatcher from the server application and its explicit read policies, then export the
35
+ handler from an App Router Route Handler such as `app/api/graph/reads/route.ts`:
36
+
37
+ ```ts
38
+ import { createNextGraphReadRouteHandler } from '@ontahi/runtime-nextjs/graph-read';
39
+
40
+ import { TodoApplication } from '@/application';
41
+ import { todoReadPolicies } from '@/todo-read-policies';
42
+ import { resolvePrincipal } from '@/authentication';
43
+
44
+ const dispatcher = TodoApplication.createGraphReadDispatcher(todoReadPolicies);
45
+
46
+ export const POST = createNextGraphReadRouteHandler({
47
+ dispatcher,
48
+ invocationContext: async request => ({
49
+ principal: await resolvePrincipal(request),
50
+ }),
51
+ });
52
+ ```
53
+
54
+ Policies using a specialized authority can derive it only from the trusted invocation context and
55
+ request metadata:
56
+
57
+ ```ts
58
+ export const POST = createNextGraphReadRouteHandler({
59
+ dispatcher,
60
+ invocationContext,
61
+ authority: context => ({ ownerId: context.principal?.subject }),
62
+ });
63
+ ```
64
+
65
+ Malformed graph programs return `400`, denied reads return `403`, unavailable execution returns
66
+ `503`, and successful reads return `200`. Caller-provided authority in the request body is never
67
+ used to authorize dispatch.
@@ -0,0 +1,3 @@
1
+ export { createNextGraphReadRouteHandler, type CreateNextGraphReadRouteHandlerOptions, type NextGraphReadAuthorityFactory, } from './route.js';
2
+ export type { NextInvocationContextFactory } from '../request-context.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/graph-read/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,KAAK,sCAAsC,EAC3C,KAAK,6BAA6B,GACnC,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { createNextGraphReadRouteHandler, } from './route.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/graph-read/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,GAGhC,MAAM,YAAY,CAAC","sourcesContent":["export {\n createNextGraphReadRouteHandler,\n type CreateNextGraphReadRouteHandlerOptions,\n type NextGraphReadAuthorityFactory,\n} from './route.js';\n\nexport type { NextInvocationContextFactory } from '../request-context.js';\n"]}
@@ -0,0 +1,18 @@
1
+ import { type GraphReadDispatcher } from '@ontahi/core/data-graph';
2
+ import { type InvocationContext } from '@ontahi/core/runtime/server';
3
+ import type { NextInvocationContextFactory } from '../request-context.js';
4
+ export type NextGraphReadAuthorityFactory<TAuthority> = (context: InvocationContext, request: Request) => TAuthority | Promise<TAuthority>;
5
+ type NextGraphReadRouteHandlerCommonOptions = {
6
+ invocationContext?: NextInvocationContextFactory;
7
+ reportError?: (error: unknown, request: Request) => void;
8
+ };
9
+ export type CreateNextGraphReadRouteHandlerOptions<TAuthority = InvocationContext> = NextGraphReadRouteHandlerCommonOptions & ({
10
+ dispatcher: GraphReadDispatcher<InvocationContext>;
11
+ authority?: never;
12
+ } | {
13
+ dispatcher: GraphReadDispatcher<TAuthority>;
14
+ authority: NextGraphReadAuthorityFactory<TAuthority>;
15
+ });
16
+ export declare const createNextGraphReadRouteHandler: <TAuthority>(options: CreateNextGraphReadRouteHandlerOptions<TAuthority>) => (request: Request) => Promise<Response>;
17
+ export {};
18
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/graph-read/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,mBAAmB,EAEzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,6BAA6B,CAAC;AAErC,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAE1E,MAAM,MAAM,6BAA6B,CAAC,UAAU,IAAI,CACtD,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,OAAO,KACb,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC,KAAK,sCAAsC,GAAG;IAC5C,iBAAiB,CAAC,EAAE,4BAA4B,CAAC;IACjD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1D,CAAC;AAEF,MAAM,MAAM,sCAAsC,CAAC,UAAU,GAAG,iBAAiB,IAC/E,sCAAsC,GACpC,CACI;IACE,UAAU,EAAE,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;IACnD,SAAS,CAAC,EAAE,KAAK,CAAC;CACnB,GACD;IACE,UAAU,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC5C,SAAS,EAAE,6BAA6B,CAAC,UAAU,CAAC,CAAC;CACtD,CACJ,CAAC;AASN,eAAO,MAAM,+BAA+B,GACzC,UAAU,EAAE,SAAS,sCAAsC,CAAC,UAAU,CAAC,MACjE,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CAoCzC,CAAC"}
@@ -0,0 +1,38 @@
1
+ import { graphReadProtocolError, parseGraphReadRequest, } from '@ontahi/core/data-graph';
2
+ import { getCurrentInvocationContext, withInvocationContext, } from '@ontahi/core/runtime/server';
3
+ const responseStatus = (response) => {
4
+ if (response.kind === 'graph-read-result')
5
+ return 200;
6
+ if (response.error.code === 'access_denied')
7
+ return 403;
8
+ if (response.error.code === 'execution_unavailable')
9
+ return 503;
10
+ return 400;
11
+ };
12
+ export const createNextGraphReadRouteHandler = (options) => async (request) => {
13
+ const parsed = parseGraphReadRequest(await request.json().catch(() => null));
14
+ if (!parsed.success) {
15
+ return Response.json(parsed.error, { status: 400 });
16
+ }
17
+ try {
18
+ const dispatch = async () => {
19
+ const currentContext = getCurrentInvocationContext();
20
+ if (!currentContext) {
21
+ throw new Error('Next.js graph read invocation context is unavailable.');
22
+ }
23
+ if (options.authority) {
24
+ return options.dispatcher(parsed.request, {
25
+ authority: await options.authority(currentContext, request),
26
+ });
27
+ }
28
+ return options.dispatcher(parsed.request, { authority: currentContext });
29
+ };
30
+ const protocolResponse = await withInvocationContext(options.invocationContext ? await options.invocationContext(request) : {}, dispatch);
31
+ return Response.json(protocolResponse, { status: responseStatus(protocolResponse) });
32
+ }
33
+ catch (error) {
34
+ options.reportError?.(error, request);
35
+ return Response.json(graphReadProtocolError('execution_unavailable', 'Data graph read execution is temporarily unavailable.'), { status: 503 });
36
+ }
37
+ };
38
+ //# sourceMappingURL=route.js.map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AAM,CAAC,OAAO,EAAE;oBACxC,SAAS,EAAE,MAAM,OAAO,CAAC,SAAS,CAAC,cAAc,EAAE,OAAO,CAAC;iBAC5D,CAAC,CAAC;YACL,CAAC;YACD,OAAO,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC,CAAC;QAC3E,CAAC,CAAC;QACF,MAAM,gBAAgB,GAAG,MAAM,qBAAqB,CAClD,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,EACzE,QAAQ,CACT,CAAC;QAEF,OAAO,QAAQ,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,MAAM,EAAE,cAAc,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC;IACvF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAEtC,OAAO,QAAQ,CAAC,IAAI,CAClB,sBAAsB,CACpB,uBAAuB,EACvB,uDAAuD,CACxD,EACD,EAAE,MAAM,EAAE,GAAG,EAAE,CAChB,CAAC;IACJ,CAAC;AACH,CAAC,CAAC","sourcesContent":["import {\n graphReadProtocolError,\n parseGraphReadRequest,\n type GraphReadDispatcher,\n type GraphReadDispatchResponse,\n} from '@ontahi/core/data-graph';\nimport {\n getCurrentInvocationContext,\n withInvocationContext,\n type InvocationContext,\n} from '@ontahi/core/runtime/server';\n\nimport type { NextInvocationContextFactory } from '../request-context.js';\n\nexport type NextGraphReadAuthorityFactory<TAuthority> = (\n context: InvocationContext,\n request: Request,\n) => TAuthority | Promise<TAuthority>;\n\ntype NextGraphReadRouteHandlerCommonOptions = {\n invocationContext?: NextInvocationContextFactory;\n reportError?: (error: unknown, request: Request) => void;\n};\n\nexport type CreateNextGraphReadRouteHandlerOptions<TAuthority = InvocationContext> =\n NextGraphReadRouteHandlerCommonOptions &\n (\n | {\n dispatcher: GraphReadDispatcher<InvocationContext>;\n authority?: never;\n }\n | {\n dispatcher: GraphReadDispatcher<TAuthority>;\n authority: NextGraphReadAuthorityFactory<TAuthority>;\n }\n );\n\nconst responseStatus = (response: GraphReadDispatchResponse) => {\n if (response.kind === 'graph-read-result') return 200;\n if (response.error.code === 'access_denied') return 403;\n if (response.error.code === 'execution_unavailable') return 503;\n return 400;\n};\n\nexport const createNextGraphReadRouteHandler =\n <TAuthority>(options: CreateNextGraphReadRouteHandlerOptions<TAuthority>) =>\n async (request: Request): Promise<Response> => {\n const parsed = parseGraphReadRequest(await request.json().catch(() => null));\n if (!parsed.success) {\n return Response.json(parsed.error, { status: 400 });\n }\n\n try {\n const dispatch = async () => {\n const currentContext = getCurrentInvocationContext();\n if (!currentContext) {\n throw new Error('Next.js graph read invocation context is unavailable.');\n }\n if (options.authority) {\n return options.dispatcher(parsed.request, {\n authority: await options.authority(currentContext, request),\n });\n }\n return options.dispatcher(parsed.request, { authority: currentContext });\n };\n const protocolResponse = await withInvocationContext(\n options.invocationContext ? await options.invocationContext(request) : {},\n dispatch,\n );\n\n return Response.json(protocolResponse, { status: responseStatus(protocolResponse) });\n } catch (error) {\n options.reportError?.(error, request);\n\n return Response.json(\n graphReadProtocolError(\n 'execution_unavailable',\n 'Data graph read execution is temporarily unavailable.',\n ),\n { status: 503 },\n );\n }\n };\n"]}
@@ -1,2 +1,3 @@
1
- export { createNextOperationInvocationRouteHandler, type CreateNextOperationInvocationRouteHandlerOptions, type NextInvocationContextFactory, } from './route.js';
1
+ export { createNextOperationInvocationRouteHandler, type CreateNextOperationInvocationRouteHandlerOptions, } from './route.js';
2
+ export type { NextInvocationContextFactory } from '../request-context.js';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/operation-invocation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yCAAyC,EACzC,KAAK,gDAAgD,EACrD,KAAK,4BAA4B,GAClC,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/operation-invocation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yCAAyC,EACzC,KAAK,gDAAgD,GACtD,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/operation-invocation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yCAAyC,GAG1C,MAAM,YAAY,CAAC","sourcesContent":["export {\n createNextOperationInvocationRouteHandler,\n type CreateNextOperationInvocationRouteHandlerOptions,\n type NextInvocationContextFactory,\n} from './route.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/operation-invocation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yCAAyC,GAE1C,MAAM,YAAY,CAAC","sourcesContent":["export {\n createNextOperationInvocationRouteHandler,\n type CreateNextOperationInvocationRouteHandlerOptions,\n} from './route.js';\n\nexport type { NextInvocationContextFactory } from '../request-context.js';\n"]}
@@ -1,6 +1,5 @@
1
1
  import { type OperationInvocationDispatcher } from '@ontahi/core/runtime/operation-invocation';
2
- import { type InvocationContextInput } from '@ontahi/core/runtime/server';
3
- export type NextInvocationContextFactory = (request: Request) => InvocationContextInput | Promise<InvocationContextInput>;
2
+ import type { NextInvocationContextFactory } from '../request-context.js';
4
3
  export type CreateNextOperationInvocationRouteHandlerOptions = {
5
4
  dispatcher: OperationInvocationDispatcher;
6
5
  invocationContext?: NextInvocationContextFactory;
@@ -1 +1 @@
1
- {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/operation-invocation/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,6BAA6B,EAEnC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAyB,KAAK,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAEjG,MAAM,MAAM,4BAA4B,GAAG,CACzC,OAAO,EAAE,OAAO,KACb,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;AAE9D,MAAM,MAAM,gDAAgD,GAAG;IAC7D,UAAU,EAAE,6BAA6B,CAAC;IAC1C,iBAAiB,CAAC,EAAE,4BAA4B,CAAC;IACjD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1D,CAAC;AAKF,eAAO,MAAM,yCAAyC,GACnD,iDAIE,gDAAgD,MAC5C,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CAyBzC,CAAC"}
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/operation-invocation/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,6BAA6B,EAEnC,MAAM,2CAA2C,CAAC;AAGnD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAE1E,MAAM,MAAM,gDAAgD,GAAG;IAC7D,UAAU,EAAE,6BAA6B,CAAC;IAC1C,iBAAiB,CAAC,EAAE,4BAA4B,CAAC;IACjD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1D,CAAC;AAKF,eAAO,MAAM,yCAAyC,GACnD,iDAIE,gDAAgD,MAC5C,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CAyBzC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/operation-invocation/route.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gCAAgC,EAChC,+BAA+B,GAGhC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAA+B,MAAM,6BAA6B,CAAC;AAYjG,MAAM,cAAc,GAAG,CAAC,QAA6C,EAAE,EAAE,C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OperationInvocationProtocolResponse,\n} from '@ontahi/core/runtime/operation-invocation';\nimport { withInvocationContext, type InvocationContextInput } from '@ontahi/core/runtime/server';\n\nexport type NextInvocationContextFactory = (\n request: Request,\n) => InvocationContextInput | Promise<InvocationContextInput>;\n\nexport type CreateNextOperationInvocationRouteHandlerOptions = {\n dispatcher: OperationInvocationDispatcher;\n invocationContext?: NextInvocationContextFactory;\n reportError?: (error: unknown, request: Request) => void;\n};\n\nconst responseStatus = (response: OperationInvocationProtocolResponse) =>\n response.kind === 'protocol-error' ? 500 : 200;\n\nexport const createNextOperationInvocationRouteHandler =\n ({\n dispatcher,\n invocationContext,\n reportError,\n }: CreateNextOperationInvocationRouteHandlerOptions) =>\n async (request: Request): Promise<Response> => {\n const parsedRequest = parseOperationInvocationRequest(await request.json().catch(() => null));\n\n if (!parsedRequest.success) {\n return Response.json(parsedRequest.error, { status: 400 });\n }\n\n try {\n const dispatch = () => dispatcher(parsedRequest.request);\n const response = invocationContext\n ? await withInvocationContext(await invocationContext(request), dispatch)\n : await dispatch();\n\n return Response.json(response, { status: responseStatus(response) });\n } catch (error) {\n reportError?.(error, request);\n\n return Response.json(\n operationInvocationProtocolError(\n 'invocation_unavailable',\n 'Operation invocation is temporarily unavailable.',\n ),\n { status: 500 },\n );\n }\n };\n"]}
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/operation-invocation/route.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gCAAgC,EAChC,+BAA+B,GAGhC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAUpE,MAAM,cAAc,GAAG,CAAC,QAA6C,EAAE,EAAE,CACvE,QAAQ,CAAC,IAAI,KAAK,gBAAgB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AAEjD,MAAM,CAAC,MAAM,yCAAyC,GACpD,CAAC,EACC,UAAU,EACV,iBAAiB,EACjB,WAAW,GACsC,EAAE,EAAE,CACvD,KAAK,EAAE,OAAgB,EAAqB,EAAE;IAC5C,MAAM,aAAa,GAAG,+BAA+B,CAAC,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAE9F,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;QAC3B,OAAO,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACzD,MAAM,QAAQ,GAAG,iBAAiB;YAChC,CAAC,CAAC,MAAM,qBAAqB,CAAC,MAAM,iBAAiB,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC;YACzE,CAAC,CAAC,MAAM,QAAQ,EAAE,CAAC;QAErB,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACvE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,WAAW,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAE9B,OAAO,QAAQ,CAAC,IAAI,CAClB,gCAAgC,CAC9B,wBAAwB,EACxB,kDAAkD,CACnD,EACD,EAAE,MAAM,EAAE,GAAG,EAAE,CAChB,CAAC;IACJ,CAAC;AACH,CAAC,CAAC","sourcesContent":["import {\n operationInvocationProtocolError,\n parseOperationInvocationRequest,\n type OperationInvocationDispatcher,\n type OperationInvocationProtocolResponse,\n} from '@ontahi/core/runtime/operation-invocation';\nimport { withInvocationContext } from '@ontahi/core/runtime/server';\n\nimport type { NextInvocationContextFactory } from '../request-context.js';\n\nexport type CreateNextOperationInvocationRouteHandlerOptions = {\n dispatcher: OperationInvocationDispatcher;\n invocationContext?: NextInvocationContextFactory;\n reportError?: (error: unknown, request: Request) => void;\n};\n\nconst responseStatus = (response: OperationInvocationProtocolResponse) =>\n response.kind === 'protocol-error' ? 500 : 200;\n\nexport const createNextOperationInvocationRouteHandler =\n ({\n dispatcher,\n invocationContext,\n reportError,\n }: CreateNextOperationInvocationRouteHandlerOptions) =>\n async (request: Request): Promise<Response> => {\n const parsedRequest = parseOperationInvocationRequest(await request.json().catch(() => null));\n\n if (!parsedRequest.success) {\n return Response.json(parsedRequest.error, { status: 400 });\n }\n\n try {\n const dispatch = () => dispatcher(parsedRequest.request);\n const response = invocationContext\n ? await withInvocationContext(await invocationContext(request), dispatch)\n : await dispatch();\n\n return Response.json(response, { status: responseStatus(response) });\n } catch (error) {\n reportError?.(error, request);\n\n return Response.json(\n operationInvocationProtocolError(\n 'invocation_unavailable',\n 'Operation invocation is temporarily unavailable.',\n ),\n { status: 500 },\n );\n }\n };\n"]}
@@ -0,0 +1,3 @@
1
+ import type { InvocationContextInput } from '@ontahi/core/runtime/server';
2
+ export type NextInvocationContextFactory = (request: Request) => InvocationContextInput | Promise<InvocationContextInput>;
3
+ //# sourceMappingURL=request-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-context.d.ts","sourceRoot":"","sources":["../src/request-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAE1E,MAAM,MAAM,4BAA4B,GAAG,CACzC,OAAO,EAAE,OAAO,KACb,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=request-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-context.js","sourceRoot":"","sources":["../src/request-context.ts"],"names":[],"mappings":"","sourcesContent":["import type { InvocationContextInput } from '@ontahi/core/runtime/server';\n\nexport type NextInvocationContextFactory = (\n request: Request,\n) => InvocationContextInput | Promise<InvocationContextInput>;\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ontahi/runtime-nextjs",
3
- "version": "0.1.0-alpha.3",
4
- "description": "Next.js action runtime and transport helpers for Ontahi applications",
3
+ "version": "0.1.0-alpha.5",
4
+ "description": "Next.js runtime and transport adapters for Ontahi applications",
5
5
  "homepage": "https://github.com/javifernandes/ontahi/tree/main/packages/runtime-nextjs",
6
6
  "license": "Apache-2.0",
7
7
  "author": "Javier Fernandes",
@@ -38,6 +38,11 @@
38
38
  "types": "./dist/operation-invocation/index.d.ts",
39
39
  "import": "./dist/operation-invocation/index.js",
40
40
  "require": "./dist/operation-invocation/index.js"
41
+ },
42
+ "./graph-read": {
43
+ "types": "./dist/graph-read/index.d.ts",
44
+ "import": "./dist/graph-read/index.js",
45
+ "require": "./dist/graph-read/index.js"
41
46
  }
42
47
  },
43
48
  "publishConfig": {
@@ -49,7 +54,7 @@
49
54
  "next-safe-action": "^8.3.0",
50
55
  "server-only": "^0.0.1",
51
56
  "zod": "^4.3.6",
52
- "@ontahi/core": "0.1.0-alpha.3"
57
+ "@ontahi/core": "0.1.0-alpha.5"
53
58
  },
54
59
  "devDependencies": {
55
60
  "@types/node": "^20.0.0",