@ontahi/runtime-nextjs 1.0.0-alpha.15 → 1.0.0-alpha.17

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
@@ -50,6 +50,22 @@ export const POST = createNextRuntimeProtocolRouteHandler({
50
50
  });
51
51
  ```
52
52
 
53
+ When application composition is lazy or storage-backed, provide its already composed Runtime
54
+ Protocol receiver as a factory. The adapter validates the portable request before initializing the
55
+ application or deriving trusted context:
56
+
57
+ ```ts
58
+ export const POST = createNextRuntimeProtocolRouteHandler({
59
+ receiver: async () => (await getServerApplication()).runtimeProtocol,
60
+ context: async request => ({
61
+ principal: await resolvePrincipal(request),
62
+ }),
63
+ });
64
+ ```
65
+
66
+ The application composition owns `createApplicationRuntimeProtocol(...)`, including Graph policies
67
+ and bridge-exposed Operations. The route does not rebuild family dispatch.
68
+
53
69
  The adapter validates JSON, the common envelope, and the canonical family body before calling the
54
70
  context factory. It installs no handlers, policies, authorization, or capabilities; the host owns
55
71
  the dispatcher and derives trusted context only from the received server request. All registered
@@ -158,4 +174,6 @@ export const POST = createNextEventIngressRouteHandler({
158
174
  The provider owns authentication and normalization. Ontahi matches the accepted provider identity
159
175
  and channel against the explicit route, validates the payload against the registered declaration,
160
176
  and only then creates the Event occurrence. Rejected or ignored deliveries never materialize an
161
- occurrence.
177
+ occurrence. The App Router adapter delegates this semantic routing to
178
+ `@ontahi/runtime-http/ingress`; Next.js owns the route lifecycle and safe framework-facing failure
179
+ projection rather than a second ingress implementation.
@@ -1,5 +1,5 @@
1
1
  import type { AnyEventDeclaration, EventApplication } from '@ontahi/core/runtime/server';
2
- import { type GraphHttpEventIngressRoute, type GraphHttpIngressProviderRegistry } from '@ontahi/core/runtime/server/ingress';
2
+ import type { GraphHttpEventIngressRoute, GraphHttpIngressProviderRegistry } from '@ontahi/core/runtime/server/ingress';
3
3
  export type CreateNextEventIngressRouteHandlerOptions = {
4
4
  events: EventApplication<readonly AnyEventDeclaration[]>;
5
5
  route: GraphHttpEventIngressRoute;
@@ -1 +1 @@
1
- {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/event-ingress/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACzF,OAAO,EAGL,KAAK,0BAA0B,EAC/B,KAAK,gCAAgC,EACtC,MAAM,qCAAqC,CAAC;AAE7C,MAAM,MAAM,yCAAyC,GAAG;IACtD,MAAM,EAAE,gBAAgB,CAAC,SAAS,mBAAmB,EAAE,CAAC,CAAC;IACzD,KAAK,EAAE,0BAA0B,CAAC;IAClC,SAAS,EAAE,gCAAgC,CAAC;IAC5C,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1D,CAAC;AAUF,eAAO,MAAM,kCAAkC,GAC7C,SAAS,yCAAyC,MAapC,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CAYlD,CAAC"}
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/event-ingress/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACzF,OAAO,KAAK,EACV,0BAA0B,EAC1B,gCAAgC,EACjC,MAAM,qCAAqC,CAAC;AAG7C,MAAM,MAAM,yCAAyC,GAAG;IACtD,MAAM,EAAE,gBAAgB,CAAC,SAAS,mBAAmB,EAAE,CAAC,CAAC;IACzD,KAAK,EAAE,0BAA0B,CAAC;IAClC,SAAS,EAAE,gCAAgC,CAAC;IAC5C,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1D,CAAC;AAUF,eAAO,MAAM,kCAAkC,GAC7C,SAAS,yCAAyC,MAYpC,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CAYlD,CAAC"}
@@ -1,4 +1,4 @@
1
- import { createGraphHttpEventIngressDispatcher, createGraphHttpEventIngressRouter, } from '@ontahi/core/runtime/server/ingress';
1
+ import { createHttpIngressHandler } from '@ontahi/runtime-http/ingress';
2
2
  const unavailableResponse = () => Response.json({ ok: false, error: 'Event ingress is temporarily unavailable.' }, { status: 500 });
3
3
  const responseError = async (response) => {
4
4
  const body = (await response.clone().json());
@@ -9,14 +9,13 @@ export const createNextEventIngressRouteHandler = (options) => {
9
9
  ((error) => {
10
10
  globalThis.console.error('Ontahi Next.js Event ingress failed.', error);
11
11
  });
12
- const router = createGraphHttpEventIngressRouter({
13
- routes: [options.route],
12
+ const handler = createHttpIngressHandler({
14
13
  providers: options.providers,
15
- dispatch: createGraphHttpEventIngressDispatcher({ events: options.events }),
14
+ events: { routes: [options.route], events: options.events },
16
15
  });
17
16
  return async (request) => {
18
17
  try {
19
- const response = await router.handle(request);
18
+ const response = await handler.handle(request);
20
19
  if (response.status !== 500)
21
20
  return response;
22
21
  reportError(await responseError(response), request);
@@ -1 +1 @@
1
- {"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/event-ingress/route.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qCAAqC,EACrC,iCAAiC,GAGlC,MAAM,qCAAqC,CAAC;AAS7C,MAAM,mBAAmB,GAAG,GAAG,EAAE,CAC/B,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,2CAA2C,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;AAEpG,MAAM,aAAa,GAAG,KAAK,EAAE,QAAkB,EAAE,EAAE;IACjD,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAsB,CAAC;IAClE,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAChD,OAAkD,EAClD,EAAE;IACF,MAAM,WAAW,GACf,OAAO,CAAC,WAAW;QACnB,CAAC,CAAC,KAAc,EAAE,EAAE;YAClB,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;QAC1E,CAAC,CAAC,CAAC;IACL,MAAM,MAAM,GAAG,iCAAiC,CAAC;QAC/C,MAAM,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;QACvB,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,QAAQ,EAAE,qCAAqC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;KAC5E,CAAC,CAAC;IAEH,OAAO,KAAK,EAAE,OAAgB,EAAqB,EAAE;QACnD,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC9C,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;gBAAE,OAAO,QAAQ,CAAC;YAE7C,WAAW,CAAC,MAAM,aAAa,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC;YACpD,OAAO,mBAAmB,EAAE,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YAC5B,OAAO,mBAAmB,EAAE,CAAC;QAC/B,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { AnyEventDeclaration, EventApplication } from '@ontahi/core/runtime/server';\nimport {\n createGraphHttpEventIngressDispatcher,\n createGraphHttpEventIngressRouter,\n type GraphHttpEventIngressRoute,\n type GraphHttpIngressProviderRegistry,\n} from '@ontahi/core/runtime/server/ingress';\n\nexport type CreateNextEventIngressRouteHandlerOptions = {\n events: EventApplication<readonly AnyEventDeclaration[]>;\n route: GraphHttpEventIngressRoute;\n providers: GraphHttpIngressProviderRegistry;\n reportError?: (error: unknown, request: Request) => void;\n};\n\nconst unavailableResponse = () =>\n Response.json({ ok: false, error: 'Event ingress is temporarily unavailable.' }, { status: 500 });\n\nconst responseError = async (response: Response) => {\n const body = (await response.clone().json()) as { error: string };\n return new Error(body.error);\n};\n\nexport const createNextEventIngressRouteHandler = (\n options: CreateNextEventIngressRouteHandlerOptions,\n) => {\n const reportError =\n options.reportError ??\n ((error: unknown) => {\n globalThis.console.error('Ontahi Next.js Event ingress failed.', error);\n });\n const router = createGraphHttpEventIngressRouter({\n routes: [options.route],\n providers: options.providers,\n dispatch: createGraphHttpEventIngressDispatcher({ events: options.events }),\n });\n\n return async (request: Request): Promise<Response> => {\n try {\n const response = await router.handle(request);\n if (response.status !== 500) return response;\n\n reportError(await responseError(response), request);\n return unavailableResponse();\n } catch (error) {\n reportError(error, request);\n return unavailableResponse();\n }\n };\n};\n"]}
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/event-ingress/route.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AASxE,MAAM,mBAAmB,GAAG,GAAG,EAAE,CAC/B,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,2CAA2C,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;AAEpG,MAAM,aAAa,GAAG,KAAK,EAAE,QAAkB,EAAE,EAAE;IACjD,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAsB,CAAC;IAClE,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAChD,OAAkD,EAClD,EAAE;IACF,MAAM,WAAW,GACf,OAAO,CAAC,WAAW;QACnB,CAAC,CAAC,KAAc,EAAE,EAAE;YAClB,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;QAC1E,CAAC,CAAC,CAAC;IACL,MAAM,OAAO,GAAG,wBAAwB,CAAC;QACvC,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;KAC5D,CAAC,CAAC;IAEH,OAAO,KAAK,EAAE,OAAgB,EAAqB,EAAE;QACnD,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC/C,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;gBAAE,OAAO,QAAQ,CAAC;YAE7C,WAAW,CAAC,MAAM,aAAa,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC;YACpD,OAAO,mBAAmB,EAAE,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YAC5B,OAAO,mBAAmB,EAAE,CAAC;QAC/B,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { AnyEventDeclaration, EventApplication } from '@ontahi/core/runtime/server';\nimport type {\n GraphHttpEventIngressRoute,\n GraphHttpIngressProviderRegistry,\n} from '@ontahi/core/runtime/server/ingress';\nimport { createHttpIngressHandler } from '@ontahi/runtime-http/ingress';\n\nexport type CreateNextEventIngressRouteHandlerOptions = {\n events: EventApplication<readonly AnyEventDeclaration[]>;\n route: GraphHttpEventIngressRoute;\n providers: GraphHttpIngressProviderRegistry;\n reportError?: (error: unknown, request: Request) => void;\n};\n\nconst unavailableResponse = () =>\n Response.json({ ok: false, error: 'Event ingress is temporarily unavailable.' }, { status: 500 });\n\nconst responseError = async (response: Response) => {\n const body = (await response.clone().json()) as { error: string };\n return new Error(body.error);\n};\n\nexport const createNextEventIngressRouteHandler = (\n options: CreateNextEventIngressRouteHandlerOptions,\n) => {\n const reportError =\n options.reportError ??\n ((error: unknown) => {\n globalThis.console.error('Ontahi Next.js Event ingress failed.', error);\n });\n const handler = createHttpIngressHandler({\n providers: options.providers,\n events: { routes: [options.route], events: options.events },\n });\n\n return async (request: Request): Promise<Response> => {\n try {\n const response = await handler.handle(request);\n if (response.status !== 500) return response;\n\n reportError(await responseError(response), request);\n return unavailableResponse();\n } catch (error) {\n reportError(error, request);\n return unavailableResponse();\n }\n };\n};\n"]}
@@ -1,2 +1,2 @@
1
- export { createNextRuntimeProtocolRouteHandler, type CreateNextRuntimeProtocolRouteHandlerOptions, type NextRuntimeProtocolContextFactory, } from './route.js';
1
+ export { createNextRuntimeProtocolRouteHandler, type CreateNextRuntimeProtocolRouteHandlerOptions, type NextRuntimeProtocolContextFactory, type NextRuntimeProtocolReceiverFactory, } from './route.js';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime-protocol/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qCAAqC,EACrC,KAAK,4CAA4C,EACjD,KAAK,iCAAiC,GACvC,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime-protocol/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qCAAqC,EACrC,KAAK,4CAA4C,EACjD,KAAK,iCAAiC,EACtC,KAAK,kCAAkC,GACxC,MAAM,YAAY,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime-protocol/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qCAAqC,GAGtC,MAAM,YAAY,CAAC","sourcesContent":["export {\n createNextRuntimeProtocolRouteHandler,\n type CreateNextRuntimeProtocolRouteHandlerOptions,\n type NextRuntimeProtocolContextFactory,\n} from './route.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime-protocol/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qCAAqC,GAItC,MAAM,YAAY,CAAC","sourcesContent":["export {\n createNextRuntimeProtocolRouteHandler,\n type CreateNextRuntimeProtocolRouteHandlerOptions,\n type NextRuntimeProtocolContextFactory,\n type NextRuntimeProtocolReceiverFactory,\n} from './route.js';\n"]}
@@ -1,9 +1,10 @@
1
1
  import { type RuntimeProtocolDispatcher } from '@ontahi/core/runtime/protocol';
2
2
  import type { ApplicationRuntimeProtocol } from '@ontahi/core/runtime/server';
3
3
  export type NextRuntimeProtocolContextFactory<TContext> = (request: Request) => TContext | Promise<TContext>;
4
+ export type NextRuntimeProtocolReceiverFactory<TContext> = (request: Request) => ApplicationRuntimeProtocol<TContext> | Promise<ApplicationRuntimeProtocol<TContext>>;
4
5
  export type CreateNextRuntimeProtocolRouteHandlerOptions<TContext> = {
5
6
  dispatcher?: RuntimeProtocolDispatcher<TContext>;
6
- receiver?: ApplicationRuntimeProtocol<TContext>;
7
+ receiver?: ApplicationRuntimeProtocol<TContext> | NextRuntimeProtocolReceiverFactory<TContext>;
7
8
  context: NextRuntimeProtocolContextFactory<TContext>;
8
9
  reportError?: (error: unknown, request: Request) => void;
9
10
  };
@@ -1 +1 @@
1
- {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/runtime-protocol/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,yBAAyB,EAC/B,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AAE9E,MAAM,MAAM,iCAAiC,CAAC,QAAQ,IAAI,CACxD,OAAO,EAAE,OAAO,KACb,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAElC,MAAM,MAAM,4CAA4C,CAAC,QAAQ,IAAI;IACnE,UAAU,CAAC,EAAE,yBAAyB,CAAC,QAAQ,CAAC,CAAC;IACjD,QAAQ,CAAC,E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AAC,QAAQ,CAAC,MAIzC,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CA0BlD,CAAC"}
@@ -18,8 +18,7 @@ const responseStatus = (result) => {
18
18
  };
19
19
  const registry = createRuntimeProtocolRegistry(runtimeProtocolFamilies);
20
20
  export const createNextRuntimeProtocolRouteHandler = ({ dispatcher, receiver, context, reportError, }) => {
21
- const dispatch = receiver?.dispatcher ?? dispatcher;
22
- if (!dispatch)
21
+ if (!receiver && !dispatcher)
23
22
  throw new TypeError('Runtime Protocol requires a receiver or dispatcher.');
24
23
  return async (request) => {
25
24
  const parsed = registry.parseRequest(await request.json().catch(() => null));
@@ -27,6 +26,8 @@ export const createNextRuntimeProtocolRouteHandler = ({ dispatcher, receiver, co
27
26
  return Response.json(parsed.error, { status: responseStatus(parsed.error) });
28
27
  }
29
28
  try {
29
+ const resolvedReceiver = typeof receiver === 'function' ? await receiver(request) : receiver;
30
+ const dispatch = resolvedReceiver?.dispatcher ?? dispatcher;
30
31
  const result = await dispatch(parsed.request, await context(request), {
31
32
  signal: request.signal,
32
33
  });
@@ -1 +1 @@
1
- {"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/runtime-protocol/route.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,uBAAuB,GAGxB,MAAM,+BAA+B,CAAC;AAcvC,MAAM,cAAc,GAAG,CAAC,MAAqC,EAAE,EAAE;IAC/D,IAAI,MAAM,CAAC,IAAI,KAAK,gBAAgB;QAAE,OAAO,GAAG,CAAC;IAEjD,QAAQ,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAC1B,KAAK,kBAAkB,CAAC;QACxB,KAAK,qBAAqB,CAAC;QAC3B,KAAK,gBAAgB,CAAC;QACtB,KAAK,wBAAwB;YAC3B,OAAO,GAAG,CAAC;QACb,KAAK,oBAAoB;YACvB,OAAO,GAAG,CAAC;QACb,KAAK,sBAAsB;YACzB,OAAO,GAAG,CAAC;QACb,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AE,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,CACzD,EACD,EAAE,MAAM,EAAE,GAAG,EAAE,CAChB,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n createRuntimeProtocolRegistry,\n runtimeProtocolError,\n runtimeProtocolFamilies,\n type RuntimeProtocolDispatchResult,\n type RuntimeProtocolDispatcher,\n} from '@ontahi/core/runtime/protocol';\nimport type { ApplicationRuntimeProtocol } from '@ontahi/core/runtime/server';\n\nexport type NextRuntimeProtocolContextFactory<TContext> = (\n request: Request,\n) => TContext | Promise<TContext>;\n\nexport type CreateNextRuntimeProtocolRouteHandlerOptions<TContext> = {\n dispatcher?: RuntimeProtocolDispatcher<TContext>;\n receiver?: ApplicationRuntimeProtocol<TContext>;\n context: NextRuntimeProtocolContextFactory<TContext>;\n reportError?: (error: unknown, request: Request) => void;\n};\n\nconst responseStatus = (result: RuntimeProtocolDispatchResult) => {\n if (result.kind !== 'protocol-error') return 200;\n\n switch (result.error.code) {\n case 'invalid_envelope':\n case 'unsupported_version':\n case 'unknown_family':\n case 'invalid_family_request':\n return 400;\n case 'family_unavailable':\n return 501;\n case 'dispatch_unavailable':\n return 503;\n case 'invalid_response':\n return 502;\n }\n};\n\nconst registry = createRuntimeProtocolRegistry(runtimeProtocolFamilies);\n\nexport const createNextRuntimeProtocolRouteHandler = <TContext>({\n dispatcher,\n receiver,\n context,\n reportError,\n}: CreateNextRuntimeProtocolRouteHandlerOptions<TContext>) => {\n const dispatch = receiver?.dispatcher ?? dispatcher;\n if (!dispatch) throw new TypeError('Runtime Protocol requires a receiver or dispatcher.');\n\n return async (request: Request): Promise<Response> => {\n const parsed = registry.parseRequest(await request.json().catch(() => null));\n if (!parsed.success) {\n return Response.json(parsed.error, { status: responseStatus(parsed.error) });\n }\n\n try {\n const result = await dispatch(parsed.request, await context(request), {\n signal: request.signal,\n });\n return Response.json(result, { status: responseStatus(result) });\n } catch (error) {\n reportError?.(error, request);\n\n return Response.json(\n runtimeProtocolError(\n 'dispatch_unavailable',\n 'Runtime Protocol dispatch is temporarily unavailable.',\n { id: parsed.request.id, family: parsed.request.family },\n ),\n { status: 503 },\n );\n }\n };\n};\n"]}
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/runtime-protocol/route.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,uBAAuB,GAGxB,MAAM,+BAA+B,CAAC;AAkBvC,MAAM,cAAc,GAAG,CAAC,MAAqC,EAAE,EAAE;IAC/D,IAAI,MAAM,CAAC,IAAI,KAAK,gBAAgB;QAAE,OAAO,GAAG,CAAC;IAEjD,QAAQ,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAC1B,KAAK,kBAAkB,CAAC;QACxB,KAAK,qBAAqB,CAAC;QAC3B,KAAK,gBAAgB,CAAC;QACtB,KAAK,wBAAwB;YAC3B,OAAO,GAAG,CAAC;QACb,KAAK,oBAAoB;YACvB,OAAO,GAAG,CAAC;QACb,KAAK,sBAAsB;YACzB,OAAO,GAAG,CAAC;QACb,KAAK,kBAAkB;YACrB,OAAO,GAAG,CAAC;IACf,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,6BAA6B,CAAC,uBAAuB,CAAC,CAAC;AAExE,MAAM,CAAC,MAAM,qCAAqC,GAAG,CAAW,EAC9D,UAAU,EACV,QAAQ,EACR,OAAO,EACP,WAAW,GAC4C,EAAE,EAAE;IAC3D,IAAI,CAAC,QAAQ,IAAI,CAAC,UAAU;QAC1B,MAAM,IAAI,SAAS,CAAC,qDAAqD,CAAC,CAAC;IAE7E,OAAO,KAAK,EAAE,OAAgB,EAAqB,EAAE;QACnD,MAAM,MAAM,GAAG,QAAQ,CAAC,YAAY,CAAC,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7E,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC/E,CAAC;QAED,IAAI,CAAC;YACH,MAAM,gBAAgB,GAAG,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;YAC7F,MAAM,QAAQ,GAAG,gBAAgB,EAAE,UAAU,IAAI,UAAW,CAAC;YAC7D,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE;gBACpE,MAAM,EAAE,OAAO,CAAC,MAAM;aACvB,CAAC,CAAC;YACH,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACnE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,WAAW,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YAE9B,OAAO,QAAQ,CAAC,IAAI,CAClB,oBAAoB,CAClB,sBAAsB,EACtB,uDAAuD,EACvD,EAAE,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,CACzD,EACD,EAAE,MAAM,EAAE,GAAG,EAAE,CAChB,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n createRuntimeProtocolRegistry,\n runtimeProtocolError,\n runtimeProtocolFamilies,\n type RuntimeProtocolDispatchResult,\n type RuntimeProtocolDispatcher,\n} from '@ontahi/core/runtime/protocol';\nimport type { ApplicationRuntimeProtocol } from '@ontahi/core/runtime/server';\n\nexport type NextRuntimeProtocolContextFactory<TContext> = (\n request: Request,\n) => TContext | Promise<TContext>;\n\nexport type NextRuntimeProtocolReceiverFactory<TContext> = (\n request: Request,\n) => ApplicationRuntimeProtocol<TContext> | Promise<ApplicationRuntimeProtocol<TContext>>;\n\nexport type CreateNextRuntimeProtocolRouteHandlerOptions<TContext> = {\n dispatcher?: RuntimeProtocolDispatcher<TContext>;\n receiver?: ApplicationRuntimeProtocol<TContext> | NextRuntimeProtocolReceiverFactory<TContext>;\n context: NextRuntimeProtocolContextFactory<TContext>;\n reportError?: (error: unknown, request: Request) => void;\n};\n\nconst responseStatus = (result: RuntimeProtocolDispatchResult) => {\n if (result.kind !== 'protocol-error') return 200;\n\n switch (result.error.code) {\n case 'invalid_envelope':\n case 'unsupported_version':\n case 'unknown_family':\n case 'invalid_family_request':\n return 400;\n case 'family_unavailable':\n return 501;\n case 'dispatch_unavailable':\n return 503;\n case 'invalid_response':\n return 502;\n }\n};\n\nconst registry = createRuntimeProtocolRegistry(runtimeProtocolFamilies);\n\nexport const createNextRuntimeProtocolRouteHandler = <TContext>({\n dispatcher,\n receiver,\n context,\n reportError,\n}: CreateNextRuntimeProtocolRouteHandlerOptions<TContext>) => {\n if (!receiver && !dispatcher)\n throw new TypeError('Runtime Protocol requires a receiver or dispatcher.');\n\n return async (request: Request): Promise<Response> => {\n const parsed = registry.parseRequest(await request.json().catch(() => null));\n if (!parsed.success) {\n return Response.json(parsed.error, { status: responseStatus(parsed.error) });\n }\n\n try {\n const resolvedReceiver = typeof receiver === 'function' ? await receiver(request) : receiver;\n const dispatch = resolvedReceiver?.dispatcher ?? dispatcher!;\n const result = await dispatch(parsed.request, await context(request), {\n signal: request.signal,\n });\n return Response.json(result, { status: responseStatus(result) });\n } catch (error) {\n reportError?.(error, request);\n\n return Response.json(\n runtimeProtocolError(\n 'dispatch_unavailable',\n 'Runtime Protocol dispatch is temporarily unavailable.',\n { id: parsed.request.id, family: parsed.request.family },\n ),\n { status: 503 },\n );\n }\n };\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ontahi/runtime-nextjs",
3
- "version": "1.0.0-alpha.15",
3
+ "version": "1.0.0-alpha.17",
4
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",
@@ -60,15 +60,16 @@
60
60
  "provenance": true
61
61
  },
62
62
  "dependencies": {
63
- "@ontahi/core": "1.0.0-alpha.15",
63
+ "@ontahi/core": "1.0.0-alpha.17",
64
+ "@ontahi/runtime-http": "1.0.0-alpha.17",
64
65
  "effect": "^3.21.0",
65
66
  "next-safe-action": "^8.3.0",
66
67
  "server-only": "^0.0.1",
67
68
  "zod": "^4.3.6"
68
69
  },
69
70
  "devDependencies": {
70
- "@ontahi/react": "1.0.0-alpha.15",
71
- "@ontahi/runtime-express": "1.0.0-alpha.15",
71
+ "@ontahi/react": "1.0.0-alpha.17",
72
+ "@ontahi/runtime-express": "1.0.0-alpha.17",
72
73
  "@types/node": "^20.0.0",
73
74
  "@types/react": "^18.3.0",
74
75
  "@types/react-dom": "^18.3.0",