@mionjs/router 0.8.0-alpha.0
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/.dist/cjs/index.cjs +154 -0
- package/.dist/cjs/index.cjs.map +1 -0
- package/.dist/cjs/index.d.ts +19 -0
- package/.dist/cjs/package.json +1 -0
- package/.dist/cjs/src/callContext.cjs +125 -0
- package/.dist/cjs/src/callContext.cjs.map +1 -0
- package/.dist/cjs/src/callContext.d.ts +10 -0
- package/.dist/cjs/src/constants.cjs +45 -0
- package/.dist/cjs/src/constants.cjs.map +1 -0
- package/.dist/cjs/src/constants.d.ts +10 -0
- package/.dist/cjs/src/defaultRoutes.cjs +16 -0
- package/.dist/cjs/src/defaultRoutes.cjs.map +1 -0
- package/.dist/cjs/src/defaultRoutes.d.ts +3 -0
- package/.dist/cjs/src/dispatch.cjs +141 -0
- package/.dist/cjs/src/dispatch.cjs.map +1 -0
- package/.dist/cjs/src/dispatch.d.ts +3 -0
- package/.dist/cjs/src/lib/aotCacheLoader.cjs +13 -0
- package/.dist/cjs/src/lib/aotCacheLoader.cjs.map +1 -0
- package/.dist/cjs/src/lib/aotCacheLoader.d.ts +1 -0
- package/.dist/cjs/src/lib/aotEmitter.cjs +70 -0
- package/.dist/cjs/src/lib/aotEmitter.cjs.map +1 -0
- package/.dist/cjs/src/lib/aotEmitter.d.ts +17 -0
- package/.dist/cjs/src/lib/dispatchError.cjs +39 -0
- package/.dist/cjs/src/lib/dispatchError.cjs.map +1 -0
- package/.dist/cjs/src/lib/dispatchError.d.ts +5 -0
- package/.dist/cjs/src/lib/handlers.cjs +52 -0
- package/.dist/cjs/src/lib/handlers.cjs.map +1 -0
- package/.dist/cjs/src/lib/handlers.d.ts +9 -0
- package/.dist/cjs/src/lib/headers.cjs +64 -0
- package/.dist/cjs/src/lib/headers.cjs.map +1 -0
- package/.dist/cjs/src/lib/headers.d.ts +2 -0
- package/.dist/cjs/src/lib/methodsCache.cjs +55 -0
- package/.dist/cjs/src/lib/methodsCache.cjs.map +1 -0
- package/.dist/cjs/src/lib/methodsCache.d.ts +11 -0
- package/.dist/cjs/src/lib/queryBody.cjs +34 -0
- package/.dist/cjs/src/lib/queryBody.cjs.map +1 -0
- package/.dist/cjs/src/lib/queryBody.d.ts +7 -0
- package/.dist/cjs/src/lib/reflection.cjs +342 -0
- package/.dist/cjs/src/lib/reflection.cjs.map +1 -0
- package/.dist/cjs/src/lib/reflection.d.ts +12 -0
- package/.dist/cjs/src/lib/remoteMethods.cjs +109 -0
- package/.dist/cjs/src/lib/remoteMethods.cjs.map +1 -0
- package/.dist/cjs/src/lib/remoteMethods.d.ts +10 -0
- package/.dist/cjs/src/lib/test/aotEmitter-test-router.cjs +24 -0
- package/.dist/cjs/src/lib/test/aotEmitter-test-router.cjs.map +1 -0
- package/.dist/cjs/src/lib/test/aotEmitter-test-router.d.ts +4 -0
- package/.dist/cjs/src/router.cjs +429 -0
- package/.dist/cjs/src/router.cjs.map +1 -0
- package/.dist/cjs/src/router.d.ts +30 -0
- package/.dist/cjs/src/routes/client.routes.cjs +76 -0
- package/.dist/cjs/src/routes/client.routes.cjs.map +1 -0
- package/.dist/cjs/src/routes/client.routes.d.ts +16 -0
- package/.dist/cjs/src/routes/errors.routes.cjs +49 -0
- package/.dist/cjs/src/routes/errors.routes.cjs.map +1 -0
- package/.dist/cjs/src/routes/errors.routes.d.ts +7 -0
- package/.dist/cjs/src/routes/mion.routes.cjs +13 -0
- package/.dist/cjs/src/routes/mion.routes.cjs.map +1 -0
- package/.dist/cjs/src/routes/mion.routes.d.ts +10 -0
- package/.dist/cjs/src/routes/serializer.routes.cjs +191 -0
- package/.dist/cjs/src/routes/serializer.routes.cjs.map +1 -0
- package/.dist/cjs/src/routes/serializer.routes.d.ts +9 -0
- package/.dist/cjs/src/routesFlow.cjs +227 -0
- package/.dist/cjs/src/routesFlow.cjs.map +1 -0
- package/.dist/cjs/src/routesFlow.d.ts +7 -0
- package/.dist/cjs/src/types/context.cjs +31 -0
- package/.dist/cjs/src/types/context.cjs.map +1 -0
- package/.dist/cjs/src/types/context.d.ts +57 -0
- package/.dist/cjs/src/types/definitions.cjs +15 -0
- package/.dist/cjs/src/types/definitions.cjs.map +1 -0
- package/.dist/cjs/src/types/definitions.d.ts +20 -0
- package/.dist/cjs/src/types/general.cjs +14 -0
- package/.dist/cjs/src/types/general.cjs.map +1 -0
- package/.dist/cjs/src/types/general.d.ts +27 -0
- package/.dist/cjs/src/types/guards.cjs +66 -0
- package/.dist/cjs/src/types/guards.cjs.map +1 -0
- package/.dist/cjs/src/types/guards.d.ts +17 -0
- package/.dist/cjs/src/types/handlers.cjs +13 -0
- package/.dist/cjs/src/types/handlers.cjs.map +1 -0
- package/.dist/cjs/src/types/handlers.d.ts +12 -0
- package/.dist/cjs/src/types/publicMethods.cjs +24 -0
- package/.dist/cjs/src/types/publicMethods.cjs.map +1 -0
- package/.dist/cjs/src/types/publicMethods.d.ts +45 -0
- package/.dist/cjs/src/types/remoteMethods.cjs +25 -0
- package/.dist/cjs/src/types/remoteMethods.cjs.map +1 -0
- package/.dist/cjs/src/types/remoteMethods.d.ts +44 -0
- package/.dist/esm/index.d.ts +19 -0
- package/.dist/esm/index.js +145 -0
- package/.dist/esm/index.js.map +1 -0
- package/.dist/esm/src/callContext.d.ts +10 -0
- package/.dist/esm/src/callContext.js +125 -0
- package/.dist/esm/src/callContext.js.map +1 -0
- package/.dist/esm/src/constants.d.ts +10 -0
- package/.dist/esm/src/constants.js +45 -0
- package/.dist/esm/src/constants.js.map +1 -0
- package/.dist/esm/src/defaultRoutes.d.ts +3 -0
- package/.dist/esm/src/defaultRoutes.js +16 -0
- package/.dist/esm/src/defaultRoutes.js.map +1 -0
- package/.dist/esm/src/dispatch.d.ts +3 -0
- package/.dist/esm/src/dispatch.js +141 -0
- package/.dist/esm/src/dispatch.js.map +1 -0
- package/.dist/esm/src/lib/aotCacheLoader.d.ts +1 -0
- package/.dist/esm/src/lib/aotCacheLoader.js +13 -0
- package/.dist/esm/src/lib/aotCacheLoader.js.map +1 -0
- package/.dist/esm/src/lib/aotEmitter.d.ts +17 -0
- package/.dist/esm/src/lib/aotEmitter.js +70 -0
- package/.dist/esm/src/lib/aotEmitter.js.map +1 -0
- package/.dist/esm/src/lib/dispatchError.d.ts +5 -0
- package/.dist/esm/src/lib/dispatchError.js +39 -0
- package/.dist/esm/src/lib/dispatchError.js.map +1 -0
- package/.dist/esm/src/lib/handlers.d.ts +9 -0
- package/.dist/esm/src/lib/handlers.js +52 -0
- package/.dist/esm/src/lib/handlers.js.map +1 -0
- package/.dist/esm/src/lib/headers.d.ts +2 -0
- package/.dist/esm/src/lib/headers.js +64 -0
- package/.dist/esm/src/lib/headers.js.map +1 -0
- package/.dist/esm/src/lib/methodsCache.d.ts +11 -0
- package/.dist/esm/src/lib/methodsCache.js +56 -0
- package/.dist/esm/src/lib/methodsCache.js.map +1 -0
- package/.dist/esm/src/lib/queryBody.d.ts +7 -0
- package/.dist/esm/src/lib/queryBody.js +34 -0
- package/.dist/esm/src/lib/queryBody.js.map +1 -0
- package/.dist/esm/src/lib/reflection.d.ts +12 -0
- package/.dist/esm/src/lib/reflection.js +320 -0
- package/.dist/esm/src/lib/reflection.js.map +1 -0
- package/.dist/esm/src/lib/remoteMethods.d.ts +10 -0
- package/.dist/esm/src/lib/remoteMethods.js +109 -0
- package/.dist/esm/src/lib/remoteMethods.js.map +1 -0
- package/.dist/esm/src/lib/test/aotEmitter-test-router.d.ts +4 -0
- package/.dist/esm/src/lib/test/aotEmitter-test-router.js +24 -0
- package/.dist/esm/src/lib/test/aotEmitter-test-router.js.map +1 -0
- package/.dist/esm/src/router.d.ts +30 -0
- package/.dist/esm/src/router.js +431 -0
- package/.dist/esm/src/router.js.map +1 -0
- package/.dist/esm/src/routes/client.routes.d.ts +16 -0
- package/.dist/esm/src/routes/client.routes.js +76 -0
- package/.dist/esm/src/routes/client.routes.js.map +1 -0
- package/.dist/esm/src/routes/errors.routes.d.ts +7 -0
- package/.dist/esm/src/routes/errors.routes.js +49 -0
- package/.dist/esm/src/routes/errors.routes.js.map +1 -0
- package/.dist/esm/src/routes/mion.routes.d.ts +10 -0
- package/.dist/esm/src/routes/mion.routes.js +13 -0
- package/.dist/esm/src/routes/mion.routes.js.map +1 -0
- package/.dist/esm/src/routes/serializer.routes.d.ts +9 -0
- package/.dist/esm/src/routes/serializer.routes.js +191 -0
- package/.dist/esm/src/routes/serializer.routes.js.map +1 -0
- package/.dist/esm/src/routesFlow.d.ts +7 -0
- package/.dist/esm/src/routesFlow.js +227 -0
- package/.dist/esm/src/routesFlow.js.map +1 -0
- package/.dist/esm/src/types/context.d.ts +57 -0
- package/.dist/esm/src/types/context.js +31 -0
- package/.dist/esm/src/types/context.js.map +1 -0
- package/.dist/esm/src/types/definitions.d.ts +20 -0
- package/.dist/esm/src/types/definitions.js +15 -0
- package/.dist/esm/src/types/definitions.js.map +1 -0
- package/.dist/esm/src/types/general.d.ts +27 -0
- package/.dist/esm/src/types/general.js +14 -0
- package/.dist/esm/src/types/general.js.map +1 -0
- package/.dist/esm/src/types/guards.d.ts +17 -0
- package/.dist/esm/src/types/guards.js +66 -0
- package/.dist/esm/src/types/guards.js.map +1 -0
- package/.dist/esm/src/types/handlers.d.ts +12 -0
- package/.dist/esm/src/types/handlers.js +13 -0
- package/.dist/esm/src/types/handlers.js.map +1 -0
- package/.dist/esm/src/types/publicMethods.d.ts +45 -0
- package/.dist/esm/src/types/publicMethods.js +24 -0
- package/.dist/esm/src/types/publicMethods.js.map +1 -0
- package/.dist/esm/src/types/remoteMethods.d.ts +44 -0
- package/.dist/esm/src/types/remoteMethods.js +25 -0
- package/.dist/esm/src/types/remoteMethods.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +34 -0
- package/package.json +67 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const core = require("@mionjs/core");
|
|
4
|
+
const src_lib_handlers = require("../lib/handlers.cjs");
|
|
5
|
+
const __ΩRecord = ["K", "T", "Record", `l'e#"Rb!b"Pde"!N#!w#y`];
|
|
6
|
+
function __assignType(fn, args) {
|
|
7
|
+
fn.__type = args;
|
|
8
|
+
return fn;
|
|
9
|
+
}
|
|
10
|
+
const mionErrorsRoutes = {
|
|
11
|
+
/**
|
|
12
|
+
* !IMPORTANT!
|
|
13
|
+
* This is declared as route mostly to reuse existing router serialization/deserialization functionality.
|
|
14
|
+
* But "@thrownErrors" is expected to be a field in response body that contain all thrown errors from other executables.
|
|
15
|
+
* thrown Errors are not strongly typed and are all serialized/deserialized as RpcError<string>.
|
|
16
|
+
* this also prevents users to register a route with the same name.
|
|
17
|
+
*/
|
|
18
|
+
[core.MION_ROUTES.thrownErrors]: src_lib_handlers.route(__assignType((ctx) => {
|
|
19
|
+
return ctx.request.thrownErrors || {};
|
|
20
|
+
}, ["CallContext", "ctx", () => __ΩRecord, () => core.RpcError, "", 'P"w!2"&P&7$o##/%'])),
|
|
21
|
+
/**
|
|
22
|
+
* Route that handles not-found scenarios when a requested route doesn't exist.
|
|
23
|
+
* This route is registered as an internal mion route.
|
|
24
|
+
* The route is called by dispatch logic when no matching route is found.
|
|
25
|
+
* Throws an RpcError that will be caught and stored in thrownErrors by the router.
|
|
26
|
+
*/
|
|
27
|
+
[core.MION_ROUTES.notFound]: src_lib_handlers.route(__assignType((ctx) => {
|
|
28
|
+
throw new core.RpcError({
|
|
29
|
+
statusCode: core.StatusCodes.NOT_FOUND,
|
|
30
|
+
publicMessage: `Route not found`,
|
|
31
|
+
type: "route-not-found"
|
|
32
|
+
});
|
|
33
|
+
}, ["CallContext", "ctx", "route-not-found", () => core.RpcError, "", 'P"w!2"P.#7$/%'])),
|
|
34
|
+
/**
|
|
35
|
+
* Platform error route for strongly typing platform/adapter errors.
|
|
36
|
+
* Platform errors occur before reaching the router or outside the router
|
|
37
|
+
* and are platform/adapter related (e.g., HTTP server errors, connection issues).
|
|
38
|
+
* This route is used for serialization/deserialization of platform errors.
|
|
39
|
+
* This also prevents users to register a route with the same name.
|
|
40
|
+
*/
|
|
41
|
+
[core.MION_ROUTES.platformError]: src_lib_handlers.route(__assignType((_ctx) => {
|
|
42
|
+
return new core.RpcError({
|
|
43
|
+
publicMessage: "Platform error",
|
|
44
|
+
type: "platform-error"
|
|
45
|
+
});
|
|
46
|
+
}, ["CallContext", "_ctx", () => core.RpcError, "", 'P"w!2"P&7#/$']))
|
|
47
|
+
};
|
|
48
|
+
exports.mionErrorsRoutes = mionErrorsRoutes;
|
|
49
|
+
//# sourceMappingURL=errors.routes.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.routes.cjs","sources":["../../../../src/routes/errors.routes.ts"],"sourcesContent":["/* ########\n * 2023 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport type {Routes} from '../types/general.ts';\nimport type {CallContext} from '../types/context.ts';\nimport {RpcError, MION_ROUTES, StatusCodes} from '@mionjs/core';\nimport {route} from '../lib/handlers.ts';\n\nexport const mionErrorsRoutes = {\n /**\n * !IMPORTANT!\n * This is declared as route mostly to reuse existing router serialization/deserialization functionality.\n * But \"@thrownErrors\" is expected to be a field in response body that contain all thrown errors from other executables.\n * thrown Errors are not strongly typed and are all serialized/deserialized as RpcError<string>.\n * this also prevents users to register a route with the same name.\n */\n [MION_ROUTES.thrownErrors]: route((ctx: CallContext): Record<string, RpcError<string>> => {\n return ctx.request.thrownErrors || {};\n }),\n /**\n * Route that handles not-found scenarios when a requested route doesn't exist.\n * This route is registered as an internal mion route.\n * The route is called by dispatch logic when no matching route is found.\n * Throws an RpcError that will be caught and stored in thrownErrors by the router.\n */\n [MION_ROUTES.notFound]: route((ctx: CallContext): RpcError<'route-not-found'> => {\n throw new RpcError({\n statusCode: StatusCodes.NOT_FOUND,\n publicMessage: `Route not found`,\n type: 'route-not-found',\n });\n }),\n /**\n * Platform error route for strongly typing platform/adapter errors.\n * Platform errors occur before reaching the router or outside the router\n * and are platform/adapter related (e.g., HTTP server errors, connection issues).\n * This route is used for serialization/deserialization of platform errors.\n * This also prevents users to register a route with the same name.\n */\n [MION_ROUTES.platformError]: route((_ctx: CallContext): RpcError<string> => {\n // Platform errors are passed through context, this route is for type serialization\n return new RpcError({\n publicMessage: 'Platform error',\n type: 'platform-error',\n });\n }),\n} as const satisfies Routes;\n"],"names":["MION_ROUTES","route","RpcError","StatusCodes"],"mappings":";;;;;;;;;AAYO,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ5B,CAACA,KAAAA,YAAY,YAAY,GAAGC,iBAAAA,MAAK,aAAC,CAAC,QAAsD;AACrF,WAAO,IAAI,QAAQ,gBAAgB,CAAA;AAAA,EACvC,GAAC,CAAA,eAAA,OAAA,MAAA,WAAA,MAAAC,eAAA,IAAA,kBAAA,CAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOD,CAACF,KAAAA,YAAY,QAAQ,GAAGC,iBAAAA,MAAK,aAAC,CAAC,QAAiD;AAC5E,UAAM,IAAIC,KAAAA,SAAS;AAAA,MACf,YAAYC,KAAAA,YAAY;AAAA,MACxB,eAAe;AAAA,MACf,MAAM;AAAA,IAAA,CACT;AAAA,EACL,GAAC,CAAA,eAAA,OAAA,mBAAA,MAAAD,eAAA,IAAA,eAAA,CAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQD,CAACF,KAAAA,YAAY,aAAa,GAAGC,iBAAAA,MAAK,aAAC,CAAC,SAAuC;AAEvE,WAAO,IAAIC,KAAAA,SAAS;AAAA,MAChB,eAAe;AAAA,MACf,MAAM;AAAA,IAAA,CACT;AAAA,EACL,GAAC,CAAA,eAAA,QAAA,MAAAA,KAAAA,UAAA,IAAA,cAAA,CAAA,CAAA;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CallContext } from '../types/context.ts';
|
|
2
|
+
import { RpcError } from '@mionjs/core';
|
|
3
|
+
export declare const mionErrorsRoutes: {
|
|
4
|
+
readonly "@thrownErrors": import('../types/definitions.ts').RouteDef<(ctx: CallContext) => Record<string, RpcError<string>>>;
|
|
5
|
+
readonly "mion@notFound": import('../types/definitions.ts').RouteDef<(ctx: CallContext) => RpcError<"route-not-found">>;
|
|
6
|
+
readonly "mion@platformError": import('../types/definitions.ts').RouteDef<(_ctx: CallContext) => RpcError<string>>;
|
|
7
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const src_types_publicMethods = require("../types/publicMethods.cjs");
|
|
4
|
+
const src_routes_client_routes = require("./client.routes.cjs");
|
|
5
|
+
const src_routes_errors_routes = require("./errors.routes.cjs");
|
|
6
|
+
const mionRoutes = {
|
|
7
|
+
...src_routes_client_routes.mionClientRoutes,
|
|
8
|
+
...src_routes_errors_routes.mionErrorsRoutes
|
|
9
|
+
};
|
|
10
|
+
const __ΩMionRoutes = [() => src_types_publicMethods.__ΩPublicApi, () => mionRoutes, "MionRoutes", 'i"o!"w#y'];
|
|
11
|
+
exports.__ΩMionRoutes = __ΩMionRoutes;
|
|
12
|
+
exports.mionRoutes = mionRoutes;
|
|
13
|
+
//# sourceMappingURL=mion.routes.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mion.routes.cjs","sources":["../../../../src/routes/mion.routes.ts"],"sourcesContent":["import {Routes} from '../types/general.ts';\nimport {PublicApi} from '../types/publicMethods.ts';\nimport {mionClientRoutes} from './client.routes.ts';\nimport {mionErrorsRoutes} from './errors.routes.ts';\n\nexport const mionRoutes = {\n ...mionClientRoutes,\n ...mionErrorsRoutes,\n} as const satisfies Routes;\n\nexport type MionRoutes = PublicApi<typeof mionRoutes>;\n"],"names":["mionClientRoutes","mionErrorsRoutes"],"mappings":";;;;;AAKO,MAAM,aAAa;AAAA,EACtB,GAAGA,yBAAAA;AAAAA,EACH,GAAGC,yBAAAA;;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PublicApi } from '../types/publicMethods.ts';
|
|
2
|
+
export declare const mionRoutes: {
|
|
3
|
+
readonly "@thrownErrors": import('../types/definitions.ts').RouteDef<(ctx: import('../types/context.ts').CallContext) => Record<string, import('@mionjs/core/.dist/esm/index.js').RpcError<string>>>;
|
|
4
|
+
readonly "mion@notFound": import('../types/definitions.ts').RouteDef<(ctx: import('../types/context.ts').CallContext) => import('@mionjs/core/.dist/esm/index.js').RpcError<"route-not-found">>;
|
|
5
|
+
readonly "mion@platformError": import('../types/definitions.ts').RouteDef<(_ctx: import('../types/context.ts').CallContext) => import('@mionjs/core/.dist/esm/index.js').RpcError<string>>;
|
|
6
|
+
readonly "mion@methodsMetadataById": import('../types/definitions.ts').RouteDef<(ctx: any, methodsIds: string[], getAllRemoteMethods?: boolean) => import('@mionjs/core/.dist/esm/index.js').SerializableMethodsData | import('@mionjs/core/.dist/esm/index.js').RpcError<"rpc-metadata-not-found">>;
|
|
7
|
+
readonly "mion@methodsMetadataByPath": import('../types/definitions.ts').RouteDef<(ctx: any, path: string, getAllRemoteMethods?: boolean) => import('@mionjs/core/.dist/esm/index.js').SerializableMethodsData | import('@mionjs/core/.dist/esm/index.js').RpcError<"rpc-metadata-not-found">>;
|
|
8
|
+
};
|
|
9
|
+
export type MionRoutes = PublicApi<typeof mionRoutes>;
|
|
10
|
+
export declare type __ΩMionRoutes = any[];
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const src_types_context = require("../types/context.cjs");
|
|
4
|
+
const src_types_general = require("../types/general.cjs");
|
|
5
|
+
const src_types_publicMethods = require("../types/publicMethods.cjs");
|
|
6
|
+
const core = require("@mionjs/core");
|
|
7
|
+
const src_lib_handlers = require("../lib/handlers.cjs");
|
|
8
|
+
const src_router = require("../router.cjs");
|
|
9
|
+
const src_types_remoteMethods = require("../types/remoteMethods.cjs");
|
|
10
|
+
const src_lib_dispatchError = require("../lib/dispatchError.cjs");
|
|
11
|
+
function deserializeRequestBody(context) {
|
|
12
|
+
if (!context.request.rawBody)
|
|
13
|
+
return;
|
|
14
|
+
let parsedBody;
|
|
15
|
+
switch (context.request.bodyType) {
|
|
16
|
+
case core.SerializerModes.stringifyJson:
|
|
17
|
+
try {
|
|
18
|
+
parsedBody = JSON.parse(context.request.rawBody);
|
|
19
|
+
} catch (err) {
|
|
20
|
+
throw new core.RpcError({
|
|
21
|
+
statusCode: core.StatusCodes.UNEXPECTED_ERROR,
|
|
22
|
+
type: "parsing-json-request-error",
|
|
23
|
+
publicMessage: `Invalid json request body: ${err?.message || "unknown parsing error."}`
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
break;
|
|
27
|
+
case core.SerializerModes.binary: {
|
|
28
|
+
const rawBody = context.request.rawBody;
|
|
29
|
+
const { body } = core.deserializeBinaryBody(context.path, rawBody, false);
|
|
30
|
+
parsedBody = body;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
case core.SerializerModes.json:
|
|
34
|
+
parsedBody = context.request.rawBody;
|
|
35
|
+
break;
|
|
36
|
+
default:
|
|
37
|
+
throw new Error(`Invalid body type ${context.request.bodyType}`);
|
|
38
|
+
}
|
|
39
|
+
if (parsedBody) {
|
|
40
|
+
if (Array.isArray(parsedBody)) {
|
|
41
|
+
parsedBody = { [src_router.getRouteExecutableFromPath(context.path).id]: parsedBody };
|
|
42
|
+
}
|
|
43
|
+
if (typeof parsedBody !== "object")
|
|
44
|
+
throw new core.RpcError({
|
|
45
|
+
statusCode: core.StatusCodes.UNEXPECTED_ERROR,
|
|
46
|
+
type: "invalid-request-body",
|
|
47
|
+
publicMessage: "Wrong request body. Expecting a body containing the route name and parameters."
|
|
48
|
+
});
|
|
49
|
+
context.request.body = parsedBody;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
deserializeRequestBody.__type = [() => src_types_context.__ΩCallContext, "context", () => src_types_publicMethods.__ΩMayReturnError, "deserializeRequestBody", 'Pn!2"n#/$'];
|
|
53
|
+
function serializeResponseBody(context, opts) {
|
|
54
|
+
const response = context.response;
|
|
55
|
+
const respBody = response.body;
|
|
56
|
+
const bodyType = context.response.serializer;
|
|
57
|
+
const thrownErrors = context.request.thrownErrors;
|
|
58
|
+
if (thrownErrors)
|
|
59
|
+
response.body["@thrownErrors"] = thrownErrors;
|
|
60
|
+
switch (bodyType) {
|
|
61
|
+
case core.SerializerModes.stringifyJson: {
|
|
62
|
+
response.headers.set("content-type", "application/json; charset=utf-8");
|
|
63
|
+
const body = stringifyBody(context, context.executionChain.methods, respBody);
|
|
64
|
+
response.rawBody = body;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case core.SerializerModes.json: {
|
|
68
|
+
response.headers.set("content-type", "application/json; charset=utf-8");
|
|
69
|
+
prepareBodyForJson(context, context.executionChain.methods, respBody);
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case core.SerializerModes.binary: {
|
|
73
|
+
response.headers.set("content-type", "application/octet-stream");
|
|
74
|
+
serializeBinaryBody(context, context.executionChain.methods, respBody);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
default:
|
|
78
|
+
throw new Error(`Invalid body type ${context.request.bodyType}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
serializeResponseBody.__type = [() => src_types_context.__ΩCallContext, "context", () => src_types_general.__ΩRouterOptions, "opts", () => src_types_publicMethods.__ΩMayReturnError, "serializeResponseBody", 'Pn!2"n#2$n%/&'];
|
|
82
|
+
function serializeBinaryBody(context, executionChain, respBody) {
|
|
83
|
+
const response = context.response;
|
|
84
|
+
const { serializer, buffer } = core.serializeBinaryBody(context.path, executionChain, respBody, true, context.routesFlowRouteIds);
|
|
85
|
+
response.binSerializer = serializer;
|
|
86
|
+
response.rawBody = new Uint8Array(buffer);
|
|
87
|
+
}
|
|
88
|
+
serializeBinaryBody.__type = [() => src_types_context.__ΩCallContext, "context", () => src_types_remoteMethods.__ΩRemoteMethod, "executionChain", () => src_types_context.__ΩResponseBody, "respBody", "serializeBinaryBody", `Pn!2"n#F2$n%2&$/'`];
|
|
89
|
+
function stringifyBody(context, executionChain, respBody) {
|
|
90
|
+
const props = [];
|
|
91
|
+
for (let i = 0; i < executionChain.length; i++) {
|
|
92
|
+
const method = executionChain[i];
|
|
93
|
+
const returnValue = respBody[method.id];
|
|
94
|
+
if (!method.hasReturnData || typeof returnValue === "undefined")
|
|
95
|
+
continue;
|
|
96
|
+
try {
|
|
97
|
+
const jsonValue = stringifyHandlerReturnValue(method, returnValue);
|
|
98
|
+
if (!jsonValue)
|
|
99
|
+
continue;
|
|
100
|
+
props.push(`${JSON.stringify(method.id)}:${jsonValue}`);
|
|
101
|
+
} catch (e) {
|
|
102
|
+
onStringifyExecutableError(context, method, e);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const thrownErrors = respBody["@thrownErrors"];
|
|
106
|
+
if (thrownErrors) {
|
|
107
|
+
const method = src_router.getRouteExecutable(core.MION_ROUTES.thrownErrors);
|
|
108
|
+
try {
|
|
109
|
+
const jsonValue = stringifyHandlerReturnValue(method, thrownErrors);
|
|
110
|
+
if (jsonValue)
|
|
111
|
+
props.push(`${JSON.stringify(method.id)}:${jsonValue}`);
|
|
112
|
+
} catch (e) {
|
|
113
|
+
onStringifyExecutableError(context, method, e);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return `{${props.join(",")}}`;
|
|
117
|
+
}
|
|
118
|
+
stringifyBody.__type = [() => src_types_context.__ΩCallContext, "context", () => src_types_remoteMethods.__ΩRemoteMethod, "executionChain", () => src_types_context.__ΩResponseBody, "respBody", "stringifyBody", `Pn!2"n#F2$n%2&&/'`];
|
|
119
|
+
function onStringifyExecutableError(context, method, e) {
|
|
120
|
+
const err = new core.RpcError({
|
|
121
|
+
statusCode: core.StatusCodes.UNEXPECTED_ERROR,
|
|
122
|
+
type: "json-stringify-response-error",
|
|
123
|
+
publicMessage: `Failed to stringify return value for handler ${method.id}, expected response type: ${method.returnJitFns.stringifyJson.typeName}`,
|
|
124
|
+
originalError: e,
|
|
125
|
+
errorData: { methodId: method.id }
|
|
126
|
+
});
|
|
127
|
+
src_lib_dispatchError.onExecutableError(context, method, err);
|
|
128
|
+
}
|
|
129
|
+
onStringifyExecutableError.__type = [() => src_types_context.__ΩCallContext, "context", () => src_types_remoteMethods.__ΩRemoteMethod, "method", "e", "onStringifyExecutableError", 'Pn!2"n#2$"2%"/&'];
|
|
130
|
+
function stringifyHandlerReturnValue(method, returnValue) {
|
|
131
|
+
if (!method.hasReturnData)
|
|
132
|
+
return "";
|
|
133
|
+
if (method.returnJitFns.prepareForJson.isNoop)
|
|
134
|
+
JSON.stringify(returnValue);
|
|
135
|
+
return method.returnJitFns.stringifyJson.fn(returnValue);
|
|
136
|
+
}
|
|
137
|
+
stringifyHandlerReturnValue.__type = [() => src_types_remoteMethods.__ΩRemoteMethod, "method", "returnValue", "stringifyHandlerReturnValue", 'Pn!2""2#&/$'];
|
|
138
|
+
function prepareBodyForJson(context, executionChain, respBody) {
|
|
139
|
+
for (let i = 0; i < executionChain.length; i++) {
|
|
140
|
+
const method = executionChain[i];
|
|
141
|
+
const returnValue = respBody[method.id];
|
|
142
|
+
if (!method.hasReturnData || typeof returnValue === "undefined")
|
|
143
|
+
continue;
|
|
144
|
+
try {
|
|
145
|
+
const preparedValue = prepareHandlerReturnValue(method, returnValue);
|
|
146
|
+
if (preparedValue !== void 0)
|
|
147
|
+
respBody[method.id] = preparedValue;
|
|
148
|
+
} catch (e) {
|
|
149
|
+
onPrepareForJsonExecutableError(context, method, e);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const thrownErrors = respBody["@thrownErrors"];
|
|
153
|
+
if (thrownErrors) {
|
|
154
|
+
const method = src_router.getRouteExecutable(core.MION_ROUTES.thrownErrors);
|
|
155
|
+
try {
|
|
156
|
+
const preparedValue = prepareHandlerReturnValue(method, thrownErrors);
|
|
157
|
+
if (preparedValue !== void 0)
|
|
158
|
+
respBody[method.id] = preparedValue;
|
|
159
|
+
} catch (e) {
|
|
160
|
+
onPrepareForJsonExecutableError(context, method, e);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
prepareBodyForJson.__type = [() => src_types_context.__ΩCallContext, "context", () => src_types_remoteMethods.__ΩRemoteMethod, "executionChain", () => src_types_context.__ΩResponseBody, "respBody", "prepareBodyForJson", `Pn!2"n#F2$n%2&$/'`];
|
|
165
|
+
function onPrepareForJsonExecutableError(context, method, e) {
|
|
166
|
+
const err = new core.RpcError({
|
|
167
|
+
statusCode: core.StatusCodes.UNEXPECTED_ERROR,
|
|
168
|
+
type: "prepare-for-json-response-error",
|
|
169
|
+
publicMessage: `Failed to prepare return value for JSON for handler ${method.id}, expected response type: ${method.returnJitFns.prepareForJson.typeName}`,
|
|
170
|
+
originalError: e,
|
|
171
|
+
errorData: { methodId: method.id }
|
|
172
|
+
});
|
|
173
|
+
src_lib_dispatchError.onExecutableError(context, method, err);
|
|
174
|
+
}
|
|
175
|
+
onPrepareForJsonExecutableError.__type = [() => src_types_context.__ΩCallContext, "context", () => src_types_remoteMethods.__ΩRemoteMethod, "method", "e", "onPrepareForJsonExecutableError", 'Pn!2"n#2$"2%"/&'];
|
|
176
|
+
function prepareHandlerReturnValue(method, returnValue) {
|
|
177
|
+
if (!method.hasReturnData)
|
|
178
|
+
return void 0;
|
|
179
|
+
if (method.returnJitFns.prepareForJson.isNoop)
|
|
180
|
+
return returnValue;
|
|
181
|
+
return method.returnJitFns.prepareForJson.fn(returnValue);
|
|
182
|
+
}
|
|
183
|
+
prepareHandlerReturnValue.__type = [() => src_types_remoteMethods.__ΩRemoteMethod, "method", "returnValue", "prepareHandlerReturnValue", 'Pn!2""2#"/$'];
|
|
184
|
+
const serializerMiddleFns = {
|
|
185
|
+
mionDeserializeRequest: src_lib_handlers.rawMiddleFn(deserializeRequestBody, { runOnError: true }),
|
|
186
|
+
mionSerializeResponse: src_lib_handlers.rawMiddleFn(serializeResponseBody, { runOnError: true })
|
|
187
|
+
};
|
|
188
|
+
exports.deserializeRequestBody = deserializeRequestBody;
|
|
189
|
+
exports.serializeResponseBody = serializeResponseBody;
|
|
190
|
+
exports.serializerMiddleFns = serializerMiddleFns;
|
|
191
|
+
//# sourceMappingURL=serializer.routes.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer.routes.cjs","sources":["../../../../src/routes/serializer.routes.ts"],"sourcesContent":["/* ########\n * 2023 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {MionResponse, MionRequest, CallContext, ResponseBody} from '../types/context.ts';\nimport {RouterOptions} from '../types/general.ts';\nimport {MiddleFnsCollection, MayReturnError} from '../types/publicMethods.ts';\nimport {\n AnyObject,\n Mutable,\n MION_ROUTES,\n StatusCodes,\n serializeBinaryBody as coreSerializeBinaryBody,\n deserializeBinaryBody as coreDeserializeBinaryBody,\n SerializerModes,\n} from '@mionjs/core';\nimport {rawMiddleFn} from '../lib/handlers.ts';\nimport {getRouteExecutableFromPath, getRouteExecutable} from '../router.ts';\nimport {RpcError} from '@mionjs/core';\nimport {RemoteMethod} from '../types/remoteMethods.ts';\nimport {onExecutableError} from '../lib/dispatchError.ts';\n\n// ############# PUBLIC METHODS #############\n\n/**\n * Deserializes the request body and stores it in the request body property.\n * This method is called before any other middleFn or route handler.\n * For binary requests, the body is parsed lazily per-method in dispatch.ts.\n * @mion:middleFn\n */\nexport function deserializeRequestBody(context: CallContext): MayReturnError {\n if (!context.request.rawBody) return; // empty body\n let parsedBody: any;\n switch (context.request.bodyType) {\n case SerializerModes.stringifyJson: // jit stringify json\n try {\n parsedBody = JSON.parse(context.request.rawBody as string);\n } catch (err: any) {\n throw new RpcError({\n statusCode: StatusCodes.UNEXPECTED_ERROR,\n type: 'parsing-json-request-error',\n publicMessage: `Invalid json request body: ${err?.message || 'unknown parsing error.'}`,\n });\n }\n break;\n case SerializerModes.binary: {\n // binary\n const rawBody = context.request.rawBody as Uint8Array;\n const {body} = coreDeserializeBinaryBody(context.path, rawBody, false);\n parsedBody = body;\n break;\n }\n case SerializerModes.json: // Object (pre-parsed body from platforms like Google Cloud Functions where Express auto-parses JSON)\n parsedBody = context.request.rawBody;\n break;\n default:\n throw new Error(`Invalid body type ${context.request.bodyType}`);\n }\n if (parsedBody) {\n if (Array.isArray(parsedBody)) {\n // when the body is an array we assume it's a single route call and we have to reconstruct the body\n // http://my-api.com/route1 [p1, p2, p3] => {route1: [p1, p2, p3]}\n parsedBody = {[getRouteExecutableFromPath(context.path).id]: parsedBody};\n }\n if (typeof parsedBody !== 'object')\n throw new RpcError({\n statusCode: StatusCodes.UNEXPECTED_ERROR,\n type: 'invalid-request-body',\n publicMessage: 'Wrong request body. Expecting a body containing the route name and parameters.',\n });\n (context.request as Mutable<MionRequest>).body = parsedBody;\n }\n}\n\n/**\n * Serializes the response body and stores it in the response rawBody property.\n * This method is called after any other middleFn or route handler.\n * @mion:middleFn\n */\nexport function serializeResponseBody(context: CallContext, opts: RouterOptions): MayReturnError {\n const response = context.response as Mutable<MionResponse>;\n const respBody: AnyObject = response.body;\n const bodyType = context.response.serializer;\n const thrownErrors = context.request.thrownErrors as Record<string, RpcError<string>> | undefined;\n // Add thrownErrors to response body before the serializer runs\n if (thrownErrors) (response.body as Mutable<AnyObject>)['@thrownErrors'] = thrownErrors;\n switch (bodyType) {\n case SerializerModes.stringifyJson: {\n // json - use stringifyJson JIT function\n response.headers.set('content-type', 'application/json; charset=utf-8');\n const body = stringifyBody(context, context.executionChain.methods, respBody);\n response.rawBody = body;\n break;\n }\n case SerializerModes.json: {\n // pre-serialized object - only prepare for JSON, don't stringify\n // Platform adapters will handle the actual JSON stringification\n // prepareForJson mutates response.body in place, so we don't set rawBody\n response.headers.set('content-type', 'application/json; charset=utf-8');\n prepareBodyForJson(context, context.executionChain.methods, respBody);\n break;\n }\n case SerializerModes.binary: {\n // binary - use toBinary JIT function\n response.headers.set('content-type', 'application/octet-stream');\n serializeBinaryBody(context, context.executionChain.methods, respBody);\n break;\n }\n default:\n throw new Error(`Invalid body type ${context.request.bodyType}`);\n }\n}\n\n/** Serializes response body to binary format using the core serializeBinaryBody function */\nfunction serializeBinaryBody(context: CallContext, executionChain: RemoteMethod[], respBody: ResponseBody): void {\n const response = context.response as Mutable<MionResponse>;\n // For routesFlow, use routesFlowRouteIds from context for proper buffer sizing\n const {serializer, buffer} = coreSerializeBinaryBody(\n context.path,\n executionChain,\n respBody,\n true,\n context.routesFlowRouteIds\n );\n response.binSerializer = serializer;\n response.rawBody = new Uint8Array(buffer);\n}\n\nfunction stringifyBody(context: CallContext, executionChain: RemoteMethod[], respBody: ResponseBody): string {\n const props: string[] = [];\n for (let i = 0; i < executionChain.length; i++) {\n const method = executionChain[i];\n const returnValue = respBody[method.id];\n if (!method.hasReturnData || typeof returnValue === 'undefined') continue;\n try {\n const jsonValue = stringifyHandlerReturnValue(method, returnValue);\n if (!jsonValue) continue;\n props.push(`${JSON.stringify(method.id)}:${jsonValue}`);\n } catch (e: any) {\n onStringifyExecutableError(context, method, e);\n }\n }\n\n // Serialize thrownErrors if they exist\n const thrownErrors = respBody['@thrownErrors'];\n if (thrownErrors) {\n const method = getRouteExecutable(MION_ROUTES.thrownErrors)!;\n try {\n const jsonValue = stringifyHandlerReturnValue(method, thrownErrors);\n if (jsonValue) props.push(`${JSON.stringify(method.id)}:${jsonValue}`);\n } catch (e: any) {\n onStringifyExecutableError(context, method, e);\n }\n }\n return `{${props.join(',')}}`;\n}\n\nfunction onStringifyExecutableError(context: CallContext, method: RemoteMethod, e: any) {\n const err = new RpcError({\n statusCode: StatusCodes.UNEXPECTED_ERROR,\n type: 'json-stringify-response-error',\n publicMessage: `Failed to stringify return value for handler ${method.id}, expected response type: ${method.returnJitFns.stringifyJson.typeName}`,\n originalError: e,\n errorData: {methodId: method.id},\n });\n onExecutableError(context, method, err);\n}\n\nfunction stringifyHandlerReturnValue(method: RemoteMethod, returnValue: any): string {\n if (!method.hasReturnData) return '';\n // id data does not require custom encoding then we use native json\n if (method.returnJitFns.prepareForJson.isNoop) JSON.stringify(returnValue);\n return method.returnJitFns.stringifyJson.fn(returnValue);\n}\n\nfunction prepareBodyForJson(context: CallContext, executionChain: RemoteMethod[], respBody: ResponseBody): void {\n // prepareForJson mutates the response body in place\n for (let i = 0; i < executionChain.length; i++) {\n const method = executionChain[i];\n const returnValue = respBody[method.id];\n if (!method.hasReturnData || typeof returnValue === 'undefined') continue;\n try {\n const preparedValue = prepareHandlerReturnValue(method, returnValue);\n if (preparedValue !== undefined) (respBody as Mutable<ResponseBody>)[method.id] = preparedValue;\n } catch (e: any) {\n onPrepareForJsonExecutableError(context, method, e);\n }\n }\n // Prepare thrownErrors if they exist\n const thrownErrors = respBody['@thrownErrors'];\n if (thrownErrors) {\n const method = getRouteExecutable(MION_ROUTES.thrownErrors)!;\n try {\n const preparedValue = prepareHandlerReturnValue(method, thrownErrors);\n if (preparedValue !== undefined) (respBody as Mutable<ResponseBody>)[method.id] = preparedValue;\n } catch (e: any) {\n onPrepareForJsonExecutableError(context, method, e);\n }\n }\n}\n\nfunction onPrepareForJsonExecutableError(context: CallContext, method: RemoteMethod, e: any) {\n const err = new RpcError({\n statusCode: StatusCodes.UNEXPECTED_ERROR,\n type: 'prepare-for-json-response-error',\n publicMessage: `Failed to prepare return value for JSON for handler ${method.id}, expected response type: ${method.returnJitFns.prepareForJson.typeName}`,\n originalError: e,\n errorData: {methodId: method.id},\n });\n onExecutableError(context, method, err);\n}\n\nfunction prepareHandlerReturnValue(method: RemoteMethod, returnValue: any): any {\n if (!method.hasReturnData) return undefined;\n if (method.returnJitFns.prepareForJson.isNoop) return returnValue;\n return method.returnJitFns.prepareForJson.fn(returnValue);\n}\n\nexport const serializerMiddleFns = {\n mionDeserializeRequest: rawMiddleFn(deserializeRequestBody, {runOnError: true}),\n mionSerializeResponse: rawMiddleFn(serializeResponseBody, {runOnError: true}),\n} satisfies MiddleFnsCollection;\n"],"names":["SerializerModes","RpcError","StatusCodes","coreDeserializeBinaryBody","getRouteExecutableFromPath","coreSerializeBinaryBody","getRouteExecutable","MION_ROUTES","onExecutableError","rawMiddleFn"],"mappings":";;;;;;;;;;AAiCM,SAAU,uBAAuB,SAAoB;AACvD,MAAI,CAAC,QAAQ,QAAQ;AAAS;AAC9B,MAAI;AACJ,UAAQ,QAAQ,QAAQ,UAAA;AAAA,IACpB,KAAKA,KAAAA,gBAAgB;AACjB,UAAI;AACA,qBAAa,KAAK,MAAM,QAAQ,QAAQ,OAAiB;AAAA,MAC7D,SAAS,KAAU;AACf,cAAM,IAAIC,KAAAA,SAAS;AAAA,UACf,YAAYC,KAAAA,YAAY;AAAA,UACxB,MAAM;AAAA,UACN,eAAe,8BAA8B,KAAK,WAAW,wBAAwB;AAAA,QAAA,CACxF;AAAA,MACL;AACA;AAAA,IACJ,KAAKF,KAAAA,gBAAgB,QAAQ;AAEzB,YAAM,UAAU,QAAQ,QAAQ;AAChC,YAAM,EAAC,KAAA,IAAQG,KAAAA,sBAA0B,QAAQ,MAAM,SAAS,KAAK;AACrE,mBAAa;AACb;AAAA,IACJ;AAAA,IACA,KAAKH,KAAAA,gBAAgB;AACjB,mBAAa,QAAQ,QAAQ;AAC7B;AAAA,IACJ;AACI,YAAM,IAAI,MAAM,qBAAqB,QAAQ,QAAQ,QAAQ,EAAE;AAAA,EAAA;AAEvE,MAAI,YAAY;AACZ,QAAI,MAAM,QAAQ,UAAU,GAAG;AAG3B,mBAAa,EAAC,CAACI,sCAA2B,QAAQ,IAAI,EAAE,EAAE,GAAG,WAAA;AAAA,IACjE;AACA,QAAI,OAAO,eAAe;AACtB,YAAM,IAAIH,KA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BAAwBC,iBAAAA,YAAY,wBAAwB,EAAC,YAAY,MAAK;AAAA,EAC9E,uBAAuBA,iBAAAA,YAAY,uBAAuB,EAAC,YAAY,MAAK;;;;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CallContext } from '../types/context.ts';
|
|
2
|
+
import { RouterOptions } from '../types/general.ts';
|
|
3
|
+
import { MayReturnError } from '../types/publicMethods.ts';
|
|
4
|
+
export declare function deserializeRequestBody(context: CallContext): MayReturnError;
|
|
5
|
+
export declare function serializeResponseBody(context: CallContext, opts: RouterOptions): MayReturnError;
|
|
6
|
+
export declare const serializerMiddleFns: {
|
|
7
|
+
mionDeserializeRequest: import('../types/definitions.ts').RawMiddleFnDef<typeof deserializeRequestBody>;
|
|
8
|
+
mionSerializeResponse: import('../types/definitions.ts').RawMiddleFnDef<typeof serializeResponseBody>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const core = require("@mionjs/core");
|
|
4
|
+
const virtual_mionServerPureFns = require("virtual:mion-server-pure-fns");
|
|
5
|
+
const src_router = require("./router.cjs");
|
|
6
|
+
const src_types_general = require("./types/general.cjs");
|
|
7
|
+
const src_types_remoteMethods = require("./types/remoteMethods.cjs");
|
|
8
|
+
const src_types_context = require("./types/context.cjs");
|
|
9
|
+
function __assignType(fn, args) {
|
|
10
|
+
fn.__type = args;
|
|
11
|
+
return fn;
|
|
12
|
+
}
|
|
13
|
+
const routesFlowCache = (Map.Ω = [["&"], [() => src_types_remoteMethods.__ΩMethodsExecutionChain, "n!"]], /* @__PURE__ */ new Map());
|
|
14
|
+
const cacheOrder = [];
|
|
15
|
+
const mappingMethodCache = (Map.Ω = [["&"], [() => src_types_remoteMethods.__ΩRemoteMethod, "n!"]], /* @__PURE__ */ new Map());
|
|
16
|
+
function clearRoutesFlowCache() {
|
|
17
|
+
routesFlowCache.clear();
|
|
18
|
+
cacheOrder.length = 0;
|
|
19
|
+
mappingMethodCache.clear();
|
|
20
|
+
}
|
|
21
|
+
clearRoutesFlowCache.__type = ["clearRoutesFlowCache", "P$/!"];
|
|
22
|
+
function getRoutesFlowCacheSize() {
|
|
23
|
+
return routesFlowCache.size;
|
|
24
|
+
}
|
|
25
|
+
getRoutesFlowCacheSize.__type = ["getRoutesFlowCacheSize", "P'/!"];
|
|
26
|
+
function getCachedRoutesFlow(query) {
|
|
27
|
+
return routesFlowCache.get(query);
|
|
28
|
+
}
|
|
29
|
+
getCachedRoutesFlow.__type = ["query", () => src_types_remoteMethods.__ΩMethodsExecutionChain, "getCachedRoutesFlow", 'P&2!Pn"-J/#'];
|
|
30
|
+
function addToRoutesFlowCache(query, chain) {
|
|
31
|
+
const routerOpts = src_router.getRouterOptions();
|
|
32
|
+
const maxSize = routerOpts.maxRoutesFlowsCacheSize;
|
|
33
|
+
if (maxSize <= 0)
|
|
34
|
+
return;
|
|
35
|
+
while (cacheOrder.length >= maxSize) {
|
|
36
|
+
const oldestKey = cacheOrder.shift();
|
|
37
|
+
if (oldestKey)
|
|
38
|
+
routesFlowCache.delete(oldestKey);
|
|
39
|
+
}
|
|
40
|
+
routesFlowCache.set(query, chain);
|
|
41
|
+
cacheOrder.push(query);
|
|
42
|
+
}
|
|
43
|
+
addToRoutesFlowCache.__type = ["query", () => src_types_remoteMethods.__ΩMethodsExecutionChain, "chain", "addToRoutesFlowCache", 'P&2!n"2#$/$'];
|
|
44
|
+
function decodeRoutesFlowQuery(urlQuery) {
|
|
45
|
+
try {
|
|
46
|
+
const dataParam = urlQuery.startsWith("data=") ? urlQuery.slice(5) : urlQuery;
|
|
47
|
+
const jsonString = core.fromBase64Url(dataParam);
|
|
48
|
+
return JSON.parse(jsonString);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
throw new core.RpcError({
|
|
51
|
+
statusCode: core.StatusCodes.UNEXPECTED_ERROR,
|
|
52
|
+
type: "routesFlow-invalid-query",
|
|
53
|
+
publicMessage: "RoutesFlow query string is not valid base64url-encoded JSON.",
|
|
54
|
+
errorData: { parseError: e?.message || "Unknown error" }
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
decodeRoutesFlowQuery.__type = ["urlQuery", "RoutesFlowQuery", "decodeRoutesFlowQuery", 'P&2!"w"/#'];
|
|
59
|
+
function getRoutesFlowExecutionChain(rawRequest, opts, urlQuery) {
|
|
60
|
+
if (!urlQuery) {
|
|
61
|
+
throw new core.RpcError({
|
|
62
|
+
statusCode: core.StatusCodes.UNEXPECTED_ERROR,
|
|
63
|
+
type: "routesFlow-missing-query",
|
|
64
|
+
publicMessage: "RoutesFlow request requires a query string with route paths."
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
const query = decodeRoutesFlowQuery(urlQuery);
|
|
68
|
+
const routePaths = query.routes;
|
|
69
|
+
const mappings = query.mappings;
|
|
70
|
+
if (!routePaths || routePaths.length === 0) {
|
|
71
|
+
throw new core.RpcError({
|
|
72
|
+
statusCode: core.StatusCodes.UNEXPECTED_ERROR,
|
|
73
|
+
type: "routesFlow-empty-routes",
|
|
74
|
+
publicMessage: "RoutesFlow request requires at least one route path in query string."
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
const routeIds = routePaths.map(__assignType((path) => path.startsWith("/") ? path.slice(1) : path, ["path", "", 'P"2!"/"']));
|
|
78
|
+
let executionChain = routesFlowCache.get(urlQuery);
|
|
79
|
+
if (executionChain)
|
|
80
|
+
return { executionChain, routesFlowRouteIds: routeIds, mappings };
|
|
81
|
+
executionChain = buildMergedExecutionChain(routePaths, rawRequest, opts, mappings);
|
|
82
|
+
addToRoutesFlowCache(urlQuery, executionChain);
|
|
83
|
+
return { executionChain, routesFlowRouteIds: routeIds, mappings };
|
|
84
|
+
}
|
|
85
|
+
getRoutesFlowExecutionChain.__type = ["rawRequest", () => src_types_general.__ΩRouterOptions, "opts", "urlQuery", () => src_types_context.__ΩRoutesFlowExecutionResult, "getRoutesFlowExecutionChain", 'P#2!n"2#&2$8n%/&'];
|
|
86
|
+
function buildMergedExecutionChain(routePaths, rawRequest, opts, mappings) {
|
|
87
|
+
const seenIds = (Set.Ω = [["&"]], /* @__PURE__ */ new Set());
|
|
88
|
+
const middleMethods = [];
|
|
89
|
+
let resolvedSerializer;
|
|
90
|
+
let firstRouteIndex = -1;
|
|
91
|
+
const defaultSerializerCode = core.SerializerModes[opts.serializer];
|
|
92
|
+
const startMiddleFnIds = new Set(src_router.startMiddleFns.map(__assignType((m) => m.id, ["m", "", 'P"2!"/"'])));
|
|
93
|
+
const endMiddleFnIds = new Set(src_router.endMiddleFns.map(__assignType((m) => m.id, ["m", "", 'P"2!"/"'])));
|
|
94
|
+
for (const routePath of routePaths) {
|
|
95
|
+
const transformedPath = opts.pathTransform?.(rawRequest, routePath) || routePath;
|
|
96
|
+
const chain = src_router.getRouteExecutionChain(transformedPath);
|
|
97
|
+
if (!chain) {
|
|
98
|
+
throw new core.RpcError({
|
|
99
|
+
statusCode: core.StatusCodes.UNEXPECTED_ERROR,
|
|
100
|
+
type: "routesFlow-route-not-found",
|
|
101
|
+
publicMessage: `Route not found in routesFlow: ${routePath}`,
|
|
102
|
+
errorData: { routePath }
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (!resolvedSerializer) {
|
|
106
|
+
resolvedSerializer = chain.serializer;
|
|
107
|
+
firstRouteIndex = chain.routeIndex;
|
|
108
|
+
} else if (resolvedSerializer !== chain.serializer) {
|
|
109
|
+
resolvedSerializer = defaultSerializerCode;
|
|
110
|
+
}
|
|
111
|
+
for (const method of chain.methods) {
|
|
112
|
+
if (seenIds.has(method.id))
|
|
113
|
+
continue;
|
|
114
|
+
if (startMiddleFnIds.has(method.id))
|
|
115
|
+
continue;
|
|
116
|
+
if (endMiddleFnIds.has(method.id))
|
|
117
|
+
continue;
|
|
118
|
+
seenIds.add(method.id);
|
|
119
|
+
middleMethods.push(method);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (mappings && mappings.length > 0) {
|
|
123
|
+
insertMappingMethods(middleMethods, mappings);
|
|
124
|
+
}
|
|
125
|
+
const mergedMethods = [...src_router.startMiddleFns, ...middleMethods, ...src_router.endMiddleFns];
|
|
126
|
+
return {
|
|
127
|
+
// Use the first route's routeIndex since that's where the first route handler is
|
|
128
|
+
routeIndex: firstRouteIndex,
|
|
129
|
+
methods: mergedMethods,
|
|
130
|
+
serializer: resolvedSerializer ?? defaultSerializerCode
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
buildMergedExecutionChain.__type = ["routePaths", "rawRequest", () => src_types_general.__ΩRouterOptions, "opts", "RoutesFlowMapping", "mappings", () => src_types_remoteMethods.__ΩMethodsExecutionChain, "buildMergedExecutionChain", `P&F2!#2"n#2$"w%F2&8n'/(`];
|
|
134
|
+
function insertMappingMethods(middleMethods, mappings) {
|
|
135
|
+
const idToIndex = (Map.Ω = [["&"], ["'"]], /* @__PURE__ */ new Map());
|
|
136
|
+
for (let i = 0; i < middleMethods.length; i++) {
|
|
137
|
+
idToIndex.set(middleMethods[i].id, i);
|
|
138
|
+
}
|
|
139
|
+
const insertions = [];
|
|
140
|
+
for (const mapping of mappings) {
|
|
141
|
+
const fromIndex = idToIndex.get(mapping.fromId);
|
|
142
|
+
const toIndex = idToIndex.get(mapping.toId);
|
|
143
|
+
if (fromIndex === void 0) {
|
|
144
|
+
throw new core.RpcError({
|
|
145
|
+
statusCode: core.StatusCodes.UNEXPECTED_ERROR,
|
|
146
|
+
type: "routesFlow-mapping-invalid-source",
|
|
147
|
+
publicMessage: `Mapping source route '${mapping.fromId}' not found in routesFlow execution chain.`,
|
|
148
|
+
errorData: { mapping }
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
if (toIndex === void 0) {
|
|
152
|
+
throw new core.RpcError({
|
|
153
|
+
statusCode: core.StatusCodes.UNEXPECTED_ERROR,
|
|
154
|
+
type: "routesFlow-mapping-invalid-target",
|
|
155
|
+
publicMessage: `Mapping target route '${mapping.toId}' not found in routesFlow execution chain.`,
|
|
156
|
+
errorData: { mapping }
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
if (!virtual_mionServerPureFns.serverPureFnsCache[core.PURE_SERVER_FN_NAMESPACE]?.[mapping.bodyHash]?.fn) {
|
|
160
|
+
throw new core.RpcError({
|
|
161
|
+
statusCode: core.StatusCodes.UNEXPECTED_ERROR,
|
|
162
|
+
type: "routesFlow-mapping-missing-pure-fn",
|
|
163
|
+
publicMessage: `Mapping pure function '${mapping.bodyHash}' not found. Ensure the function is registered on the server.`,
|
|
164
|
+
errorData: { mapping }
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
insertions.push({
|
|
168
|
+
index: fromIndex + 1,
|
|
169
|
+
method: createMappingMethod(mapping)
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
insertions.sort(__assignType((a, b) => b.index - a.index, ["a", "b", "", 'P"2!"2""/#']));
|
|
173
|
+
for (const { index, method } of insertions) {
|
|
174
|
+
middleMethods.splice(index, 0, method);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
insertMappingMethods.__type = [() => src_types_remoteMethods.__ΩRemoteMethod, "middleMethods", "RoutesFlowMapping", "mappings", "insertMappingMethods", 'Pn!F2""w#F2$$/%'];
|
|
178
|
+
function createMappingMethod(mapping) {
|
|
179
|
+
const id = `mionMapFrom_${mapping.fromId}_${mapping.bodyHash}_to_${mapping.toId}`;
|
|
180
|
+
const cached = mappingMethodCache.get(id);
|
|
181
|
+
if (cached)
|
|
182
|
+
return cached;
|
|
183
|
+
const noopJitFns = core.getNoopJitFns();
|
|
184
|
+
const method = {
|
|
185
|
+
type: core.HandlerType.rawMiddleFn,
|
|
186
|
+
id,
|
|
187
|
+
isAsync: false,
|
|
188
|
+
hasReturnData: false,
|
|
189
|
+
paramsJitHash: "",
|
|
190
|
+
returnJitHash: "",
|
|
191
|
+
paramsJitFns: noopJitFns,
|
|
192
|
+
returnJitFns: noopJitFns,
|
|
193
|
+
handler: createMappingHandler(mapping),
|
|
194
|
+
options: { runOnError: false, validateParams: false },
|
|
195
|
+
methodCaller: runMappingHandler
|
|
196
|
+
};
|
|
197
|
+
mappingMethodCache.set(id, method);
|
|
198
|
+
return method;
|
|
199
|
+
}
|
|
200
|
+
createMappingMethod.__type = ["RoutesFlowMapping", "mapping", () => src_types_remoteMethods.__ΩRemoteMethod, "createMappingMethod", 'P"w!2"n#/$'];
|
|
201
|
+
function createMappingHandler(mapping) {
|
|
202
|
+
return __assignType((ctx) => {
|
|
203
|
+
const sourceOutput = ctx.response.body[mapping.fromId];
|
|
204
|
+
const entry = virtual_mionServerPureFns.serverPureFnsCache[core.PURE_SERVER_FN_NAMESPACE]?.[mapping.bodyHash];
|
|
205
|
+
if (!entry?.fn) {
|
|
206
|
+
throw new core.RpcError({
|
|
207
|
+
statusCode: core.StatusCodes.UNEXPECTED_ERROR,
|
|
208
|
+
type: "routesFlow-mapping-missing-pure-fn",
|
|
209
|
+
publicMessage: `Mapping pure function '${mapping.bodyHash}' not found at runtime.`
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
const mappedValue = entry.fn(sourceOutput);
|
|
213
|
+
const targetParams = ctx.request.body[mapping.toId];
|
|
214
|
+
if (targetParams)
|
|
215
|
+
targetParams[mapping.paramIndex] = mappedValue;
|
|
216
|
+
}, ["CallContext", "ctx", "", 'P"w!2""/#']);
|
|
217
|
+
}
|
|
218
|
+
createMappingHandler.__type = ["RoutesFlowMapping", "mapping", "createMappingHandler", 'P"w!2""/#'];
|
|
219
|
+
async function runMappingHandler(context, executable, ...args) {
|
|
220
|
+
return executable.handler(context);
|
|
221
|
+
}
|
|
222
|
+
runMappingHandler.__type = ["CallContext", "context", () => src_types_remoteMethods.__ΩRemoteMethod, "executable", "args", "runMappingHandler", 'P"w!2"n#2$#@2%"/&'];
|
|
223
|
+
exports.clearRoutesFlowCache = clearRoutesFlowCache;
|
|
224
|
+
exports.getCachedRoutesFlow = getCachedRoutesFlow;
|
|
225
|
+
exports.getRoutesFlowCacheSize = getRoutesFlowCacheSize;
|
|
226
|
+
exports.getRoutesFlowExecutionChain = getRoutesFlowExecutionChain;
|
|
227
|
+
//# sourceMappingURL=routesFlow.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routesFlow.cjs","sources":["../../../src/routesFlow.ts"],"sourcesContent":["/* ########\n * 2023 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {\n RpcError,\n SerializerCode,\n SerializerModes,\n StatusCodes,\n HandlerType,\n getNoopJitFns,\n PURE_SERVER_FN_NAMESPACE,\n fromBase64Url,\n} from '@mionjs/core';\nimport {serverPureFnsCache} from 'virtual:mion-server-pure-fns';\nimport {getRouteExecutionChain, getRouterOptions, startMiddleFns, endMiddleFns} from './router.ts';\nimport {RouterOptions} from './types/general.ts';\nimport {MethodsExecutionChain, RemoteMethod} from './types/remoteMethods.ts';\nimport {RoutesFlowExecutionResult} from './types/context.ts';\nimport type {CallContext} from './types/context.ts';\nimport type {RoutesFlowQuery, RoutesFlowMapping} from '@mionjs/core';\n\n// ############# ROUTES_FLOW CACHE #############\n\n/** FILO cache for merged execution chains. Key is the query string, value is the cached chain. */\nconst routesFlowCache = new Map<string, MethodsExecutionChain>();\nconst cacheOrder: string[] = [];\n/** Cache for mapping RemoteMethods keyed by their unique ID */\nconst mappingMethodCache = new Map<string, RemoteMethod>();\n\n/** Clears the routesFlow cache and mapping method cache - useful for testing */\nexport function clearRoutesFlowCache(): void {\n routesFlowCache.clear();\n cacheOrder.length = 0;\n mappingMethodCache.clear();\n}\n\n/** Returns the current routesFlow cache size */\nexport function getRoutesFlowCacheSize(): number {\n return routesFlowCache.size;\n}\n\n/** Returns a cached routesFlow chain by query string */\nexport function getCachedRoutesFlow(query: string): MethodsExecutionChain | undefined {\n return routesFlowCache.get(query);\n}\n\n/** Adds a merged chain to the cache with FILO eviction */\nfunction addToRoutesFlowCache(query: string, chain: MethodsExecutionChain): void {\n const routerOpts = getRouterOptions();\n const maxSize = routerOpts.maxRoutesFlowsCacheSize;\n // Caching disabled\n if (maxSize <= 0) return;\n // Evict oldest entries if cache is full (FILO - First In, Last Out)\n while (cacheOrder.length >= maxSize) {\n const oldestKey = cacheOrder.shift();\n if (oldestKey) routesFlowCache.delete(oldestKey);\n }\n routesFlowCache.set(query, chain);\n cacheOrder.push(query);\n}\n\n// ############# QUERY PARSING #############\n\n/** Decodes a base64url-encoded JSON routesFlow query string, expects `data=<base64url>` format */\nfunction decodeRoutesFlowQuery(urlQuery: string): RoutesFlowQuery {\n try {\n const dataParam = urlQuery.startsWith('data=') ? urlQuery.slice(5) : urlQuery;\n const jsonString = fromBase64Url(dataParam);\n return JSON.parse(jsonString) as RoutesFlowQuery;\n } catch (e: any) {\n throw new RpcError({\n statusCode: StatusCodes.UNEXPECTED_ERROR,\n type: 'routesFlow-invalid-query',\n publicMessage: 'RoutesFlow query string is not valid base64url-encoded JSON.',\n errorData: {parseError: e?.message || 'Unknown error'},\n });\n }\n}\n\n// ############# ROUTES_FLOW #############\n\n/** Builds or retrieves a cached merged execution chain for routesFlow requests */\nexport function getRoutesFlowExecutionChain(\n rawRequest: unknown,\n opts: RouterOptions,\n urlQuery?: string\n): RoutesFlowExecutionResult {\n // Validate urlQuery is provided\n if (!urlQuery) {\n throw new RpcError({\n statusCode: StatusCodes.UNEXPECTED_ERROR,\n type: 'routesFlow-missing-query',\n publicMessage: 'RoutesFlow request requires a query string with route paths.',\n });\n }\n\n // Decode base64+JSON query\n const query = decodeRoutesFlowQuery(urlQuery);\n const routePaths = query.routes;\n const mappings = query.mappings;\n\n if (!routePaths || routePaths.length === 0) {\n throw new RpcError({\n statusCode: StatusCodes.UNEXPECTED_ERROR,\n type: 'routesFlow-empty-routes',\n publicMessage: 'RoutesFlow request requires at least one route path in query string.',\n });\n }\n\n // Convert paths to route IDs (remove leading slash)\n const routeIds = routePaths.map((path) => (path.startsWith('/') ? path.slice(1) : path));\n\n // Check cache first\n let executionChain = routesFlowCache.get(urlQuery);\n if (executionChain) return {executionChain, routesFlowRouteIds: routeIds, mappings};\n\n // Build merged execution chain\n executionChain = buildMergedExecutionChain(routePaths, rawRequest, opts, mappings);\n addToRoutesFlowCache(urlQuery, executionChain);\n return {executionChain, routesFlowRouteIds: routeIds, mappings};\n}\n\n/**\n * Builds a merged execution chain from multiple route paths.\n * The merged chain includes all methods from all routes, with deduplication by ID.\n *\n * The chain is structured as:\n * 1. Start middleFns (e.g., mionDeserializeRequest) - from first route, at the beginning\n * 2. Middle methods (routes and their middleFns) - merged from all routes, with mapping steps inserted\n * 3. End middleFns (e.g., mionSerializeResponse) - from first route, at the end\n *\n * When mappings are provided, mapping steps are inserted after the source route\n * and before the target route to transform output → input.\n */\nfunction buildMergedExecutionChain(\n routePaths: string[],\n rawRequest: unknown,\n opts: RouterOptions,\n mappings?: RoutesFlowMapping[]\n): MethodsExecutionChain {\n const seenIds = new Set<string>();\n const middleMethods: RemoteMethod[] = [];\n let resolvedSerializer: SerializerCode | undefined;\n let firstRouteIndex = -1;\n const defaultSerializerCode = SerializerModes[opts.serializer];\n\n // Build sets of start and end middleFn IDs for filtering\n const startMiddleFnIds = new Set(startMiddleFns.map((m) => m.id));\n const endMiddleFnIds = new Set(endMiddleFns.map((m) => m.id));\n\n // Process each route path\n for (const routePath of routePaths) {\n // Apply path transform if configured\n const transformedPath = opts.pathTransform?.(rawRequest, routePath) || routePath;\n const chain = getRouteExecutionChain(transformedPath);\n if (!chain) {\n throw new RpcError({\n statusCode: StatusCodes.UNEXPECTED_ERROR,\n type: 'routesFlow-route-not-found',\n publicMessage: `Route not found in routesFlow: ${routePath}`,\n errorData: {routePath},\n });\n }\n\n // Resolve serializer - use first route's serializer, or fall back to default if conflicting\n if (!resolvedSerializer) {\n resolvedSerializer = chain.serializer;\n // Track the route index from the first route (relative to start middleFns)\n firstRouteIndex = chain.routeIndex;\n } else if (resolvedSerializer !== chain.serializer) {\n resolvedSerializer = defaultSerializerCode;\n }\n\n // Add middle methods from this route's chain, deduplicating by ID\n // Skip start and end middleFns - they will be added separately\n for (const method of chain.methods) {\n if (seenIds.has(method.id)) continue;\n if (startMiddleFnIds.has(method.id)) continue;\n if (endMiddleFnIds.has(method.id)) continue;\n seenIds.add(method.id);\n middleMethods.push(method);\n }\n }\n\n // Insert mapping methods between source and target routes\n if (mappings && mappings.length > 0) {\n insertMappingMethods(middleMethods, mappings);\n }\n\n // Build final chain: start middleFns + middle methods + end middleFns\n const mergedMethods = [...startMiddleFns, ...middleMethods, ...endMiddleFns];\n\n return {\n // Use the first route's routeIndex since that's where the first route handler is\n routeIndex: firstRouteIndex,\n methods: mergedMethods,\n serializer: resolvedSerializer ?? defaultSerializerCode,\n };\n}\n\n// ############# MAPPING METHODS #############\n\n/**\n * Inserts mapping methods into the middleMethods array in the correct position.\n * Each mapping method is inserted after the source route (fromId) and before the target route (toId).\n * Mappings are processed in reverse insertion order to maintain correct indices.\n */\nfunction insertMappingMethods(middleMethods: RemoteMethod[], mappings: RoutesFlowMapping[]): void {\n // Build a map of route ID → index in middleMethods for quick lookup\n const idToIndex = new Map<string, number>();\n for (let i = 0; i < middleMethods.length; i++) {\n idToIndex.set(middleMethods[i].id, i);\n }\n\n // Collect insertions: each mapping creates one insertion point\n const insertions: Array<{index: number; method: RemoteMethod}> = [];\n\n for (const mapping of mappings) {\n const fromIndex = idToIndex.get(mapping.fromId);\n const toIndex = idToIndex.get(mapping.toId);\n\n if (fromIndex === undefined) {\n throw new RpcError({\n statusCode: StatusCodes.UNEXPECTED_ERROR,\n type: 'routesFlow-mapping-invalid-source',\n publicMessage: `Mapping source route '${mapping.fromId}' not found in routesFlow execution chain.`,\n errorData: {mapping},\n });\n }\n if (toIndex === undefined) {\n throw new RpcError({\n statusCode: StatusCodes.UNEXPECTED_ERROR,\n type: 'routesFlow-mapping-invalid-target',\n publicMessage: `Mapping target route '${mapping.toId}' not found in routesFlow execution chain.`,\n errorData: {mapping},\n });\n }\n\n // Validate the pure function exists in the serverPureFnsCache (populated by mion vite plugin)\n if (!serverPureFnsCache[PURE_SERVER_FN_NAMESPACE]?.[mapping.bodyHash]?.fn) {\n throw new RpcError({\n statusCode: StatusCodes.UNEXPECTED_ERROR,\n type: 'routesFlow-mapping-missing-pure-fn',\n publicMessage: `Mapping pure function '${mapping.bodyHash}' not found. Ensure the function is registered on the server.`,\n errorData: {mapping},\n });\n }\n\n // Insert after the source route (fromIndex + 1)\n insertions.push({\n index: fromIndex + 1,\n method: createMappingMethod(mapping),\n });\n }\n\n // Sort insertions by index descending so splice doesn't shift subsequent indices\n insertions.sort((a, b) => b.index - a.index);\n\n for (const {index, method} of insertions) {\n middleMethods.splice(index, 0, method);\n }\n}\n\n/** Creates or retrieves a cached RemoteMethod that acts as a raw middleFn to execute a mapping between routes */\nfunction createMappingMethod(mapping: RoutesFlowMapping): RemoteMethod {\n const id = `mionMapFrom_${mapping.fromId}_${mapping.bodyHash}_to_${mapping.toId}`;\n const cached = mappingMethodCache.get(id);\n if (cached) return cached;\n\n const noopJitFns = getNoopJitFns();\n const method = {\n type: HandlerType.rawMiddleFn,\n id,\n isAsync: false,\n hasReturnData: false,\n paramsJitHash: '',\n returnJitHash: '',\n paramsJitFns: noopJitFns,\n returnJitFns: noopJitFns,\n handler: createMappingHandler(mapping),\n options: {runOnError: false, validateParams: false},\n methodCaller: runMappingHandler,\n } as RemoteMethod;\n\n mappingMethodCache.set(id, method);\n return method;\n}\n\n/** Creates the handler function for a mapping step */\nfunction createMappingHandler(mapping: RoutesFlowMapping) {\n return (ctx: CallContext) => {\n // Get the output from the source route\n const sourceOutput = ctx.response.body[mapping.fromId];\n\n // Resolve and execute the pure function from serverPureFnsCache (populated by mion vite plugin)\n const entry = serverPureFnsCache[PURE_SERVER_FN_NAMESPACE]?.[mapping.bodyHash];\n if (!entry?.fn) {\n throw new RpcError({\n statusCode: StatusCodes.UNEXPECTED_ERROR,\n type: 'routesFlow-mapping-missing-pure-fn',\n publicMessage: `Mapping pure function '${mapping.bodyHash}' not found at runtime.`,\n });\n }\n const mappedValue = entry.fn(sourceOutput);\n\n // Replace null at paramIndex in target route's params\n const targetParams = ctx.request.body[mapping.toId] as any[];\n if (targetParams) (targetParams as any[])[mapping.paramIndex] = mappedValue;\n };\n}\n\n/** Custom method caller for mapping handlers — only passes the context */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nasync function runMappingHandler(context: CallContext, executable: RemoteMethod, ...args: unknown[]) {\n return executable.handler(context);\n}\n"],"names":["__ΩMethodsExecutionChain","__ΩRemoteMethod","getRouterOptions","fromBase64Url","RpcError","StatusCodes","SerializerModes","startMiddleFns","endMiddleFns","getRouteExecutionChain","serverPureFnsCache","PURE_SERVER_FN_NAMESPACE","getNoopJitFns","HandlerType"],"mappings":";;;;;;;;;;;;AA4BA,MAAM,mBAAsB,IAAG,IAAA,CAAA,CAAA,GAAA,GAAA,CAAA,MAAAA,wBAAAA,0BAAA,IAAA,CAAA,uBAAH,IAAA;AAC5B,MAAM,aAAuB,CAAA;AAE7B,MAAM,sBAAyB,IAAG,IAAA,CAAA,CAAA,GAAA,GAAA,CAAA,MAAAC,wBAAAA,iBAAA,IAAA,CAAA,uBAAH,IAAA;SAGf,uBAAoB;AAChC,kBAAgB,MAAA;AAChB,aAAW,SAAS;AACpB,qBAAmB,MAAA;AACvB;;SAGgB,yBAAsB;AAClC,SAAO,gBAAgB;AAC3B;;AAGM,SAAU,oBAAoB,OAAa;AAC7C,SAAO,gBAAgB,IAAI,KAAK;AACpC;;AAGA,SAAS,qBAAqB,OAAe,OAA4B;AACrE,QAAM,aAAaC,WAAAA,iBAAA;AACnB,QAAM,UAAU,WAAW;AAE3B,MAAI,WAAW;AAAG;AAElB,SAAO,WAAW,UAAU,SAAS;AACjC,UAAM,YAAY,WAAW,MAAA;AAC7B,QAAI;AAAW,sBAAgB,OAAO,SAAS;AAAA,EACnD;AACA,kBA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;AAAe,mBAAuB,QAAQ,UAAU,IAAI;AAAA,EACpE,GAAC,CAAA,eAAA,OAAA,IAAA,WAAA,CAAA;AACL;;AAIA,eAAe,kBAAkB,SAAsB,eAA6B,MAAe;AAC/F,SAAO,WAAW,QAAQ,OAAO;AACrC;;;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RouterOptions } from './types/general.ts';
|
|
2
|
+
import { MethodsExecutionChain } from './types/remoteMethods.ts';
|
|
3
|
+
import { RoutesFlowExecutionResult } from './types/context.ts';
|
|
4
|
+
export declare function clearRoutesFlowCache(): void;
|
|
5
|
+
export declare function getRoutesFlowCacheSize(): number;
|
|
6
|
+
export declare function getCachedRoutesFlow(query: string): MethodsExecutionChain | undefined;
|
|
7
|
+
export declare function getRoutesFlowExecutionChain(rawRequest: unknown, opts: RouterOptions, urlQuery?: string): RoutesFlowExecutionResult;
|