@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.
Files changed (172) hide show
  1. package/.dist/cjs/index.cjs +154 -0
  2. package/.dist/cjs/index.cjs.map +1 -0
  3. package/.dist/cjs/index.d.ts +19 -0
  4. package/.dist/cjs/package.json +1 -0
  5. package/.dist/cjs/src/callContext.cjs +125 -0
  6. package/.dist/cjs/src/callContext.cjs.map +1 -0
  7. package/.dist/cjs/src/callContext.d.ts +10 -0
  8. package/.dist/cjs/src/constants.cjs +45 -0
  9. package/.dist/cjs/src/constants.cjs.map +1 -0
  10. package/.dist/cjs/src/constants.d.ts +10 -0
  11. package/.dist/cjs/src/defaultRoutes.cjs +16 -0
  12. package/.dist/cjs/src/defaultRoutes.cjs.map +1 -0
  13. package/.dist/cjs/src/defaultRoutes.d.ts +3 -0
  14. package/.dist/cjs/src/dispatch.cjs +141 -0
  15. package/.dist/cjs/src/dispatch.cjs.map +1 -0
  16. package/.dist/cjs/src/dispatch.d.ts +3 -0
  17. package/.dist/cjs/src/lib/aotCacheLoader.cjs +13 -0
  18. package/.dist/cjs/src/lib/aotCacheLoader.cjs.map +1 -0
  19. package/.dist/cjs/src/lib/aotCacheLoader.d.ts +1 -0
  20. package/.dist/cjs/src/lib/aotEmitter.cjs +70 -0
  21. package/.dist/cjs/src/lib/aotEmitter.cjs.map +1 -0
  22. package/.dist/cjs/src/lib/aotEmitter.d.ts +17 -0
  23. package/.dist/cjs/src/lib/dispatchError.cjs +39 -0
  24. package/.dist/cjs/src/lib/dispatchError.cjs.map +1 -0
  25. package/.dist/cjs/src/lib/dispatchError.d.ts +5 -0
  26. package/.dist/cjs/src/lib/handlers.cjs +52 -0
  27. package/.dist/cjs/src/lib/handlers.cjs.map +1 -0
  28. package/.dist/cjs/src/lib/handlers.d.ts +9 -0
  29. package/.dist/cjs/src/lib/headers.cjs +64 -0
  30. package/.dist/cjs/src/lib/headers.cjs.map +1 -0
  31. package/.dist/cjs/src/lib/headers.d.ts +2 -0
  32. package/.dist/cjs/src/lib/methodsCache.cjs +55 -0
  33. package/.dist/cjs/src/lib/methodsCache.cjs.map +1 -0
  34. package/.dist/cjs/src/lib/methodsCache.d.ts +11 -0
  35. package/.dist/cjs/src/lib/queryBody.cjs +34 -0
  36. package/.dist/cjs/src/lib/queryBody.cjs.map +1 -0
  37. package/.dist/cjs/src/lib/queryBody.d.ts +7 -0
  38. package/.dist/cjs/src/lib/reflection.cjs +342 -0
  39. package/.dist/cjs/src/lib/reflection.cjs.map +1 -0
  40. package/.dist/cjs/src/lib/reflection.d.ts +12 -0
  41. package/.dist/cjs/src/lib/remoteMethods.cjs +109 -0
  42. package/.dist/cjs/src/lib/remoteMethods.cjs.map +1 -0
  43. package/.dist/cjs/src/lib/remoteMethods.d.ts +10 -0
  44. package/.dist/cjs/src/lib/test/aotEmitter-test-router.cjs +24 -0
  45. package/.dist/cjs/src/lib/test/aotEmitter-test-router.cjs.map +1 -0
  46. package/.dist/cjs/src/lib/test/aotEmitter-test-router.d.ts +4 -0
  47. package/.dist/cjs/src/router.cjs +429 -0
  48. package/.dist/cjs/src/router.cjs.map +1 -0
  49. package/.dist/cjs/src/router.d.ts +30 -0
  50. package/.dist/cjs/src/routes/client.routes.cjs +76 -0
  51. package/.dist/cjs/src/routes/client.routes.cjs.map +1 -0
  52. package/.dist/cjs/src/routes/client.routes.d.ts +16 -0
  53. package/.dist/cjs/src/routes/errors.routes.cjs +49 -0
  54. package/.dist/cjs/src/routes/errors.routes.cjs.map +1 -0
  55. package/.dist/cjs/src/routes/errors.routes.d.ts +7 -0
  56. package/.dist/cjs/src/routes/mion.routes.cjs +13 -0
  57. package/.dist/cjs/src/routes/mion.routes.cjs.map +1 -0
  58. package/.dist/cjs/src/routes/mion.routes.d.ts +10 -0
  59. package/.dist/cjs/src/routes/serializer.routes.cjs +191 -0
  60. package/.dist/cjs/src/routes/serializer.routes.cjs.map +1 -0
  61. package/.dist/cjs/src/routes/serializer.routes.d.ts +9 -0
  62. package/.dist/cjs/src/routesFlow.cjs +227 -0
  63. package/.dist/cjs/src/routesFlow.cjs.map +1 -0
  64. package/.dist/cjs/src/routesFlow.d.ts +7 -0
  65. package/.dist/cjs/src/types/context.cjs +31 -0
  66. package/.dist/cjs/src/types/context.cjs.map +1 -0
  67. package/.dist/cjs/src/types/context.d.ts +57 -0
  68. package/.dist/cjs/src/types/definitions.cjs +15 -0
  69. package/.dist/cjs/src/types/definitions.cjs.map +1 -0
  70. package/.dist/cjs/src/types/definitions.d.ts +20 -0
  71. package/.dist/cjs/src/types/general.cjs +14 -0
  72. package/.dist/cjs/src/types/general.cjs.map +1 -0
  73. package/.dist/cjs/src/types/general.d.ts +27 -0
  74. package/.dist/cjs/src/types/guards.cjs +66 -0
  75. package/.dist/cjs/src/types/guards.cjs.map +1 -0
  76. package/.dist/cjs/src/types/guards.d.ts +17 -0
  77. package/.dist/cjs/src/types/handlers.cjs +13 -0
  78. package/.dist/cjs/src/types/handlers.cjs.map +1 -0
  79. package/.dist/cjs/src/types/handlers.d.ts +12 -0
  80. package/.dist/cjs/src/types/publicMethods.cjs +24 -0
  81. package/.dist/cjs/src/types/publicMethods.cjs.map +1 -0
  82. package/.dist/cjs/src/types/publicMethods.d.ts +45 -0
  83. package/.dist/cjs/src/types/remoteMethods.cjs +25 -0
  84. package/.dist/cjs/src/types/remoteMethods.cjs.map +1 -0
  85. package/.dist/cjs/src/types/remoteMethods.d.ts +44 -0
  86. package/.dist/esm/index.d.ts +19 -0
  87. package/.dist/esm/index.js +145 -0
  88. package/.dist/esm/index.js.map +1 -0
  89. package/.dist/esm/src/callContext.d.ts +10 -0
  90. package/.dist/esm/src/callContext.js +125 -0
  91. package/.dist/esm/src/callContext.js.map +1 -0
  92. package/.dist/esm/src/constants.d.ts +10 -0
  93. package/.dist/esm/src/constants.js +45 -0
  94. package/.dist/esm/src/constants.js.map +1 -0
  95. package/.dist/esm/src/defaultRoutes.d.ts +3 -0
  96. package/.dist/esm/src/defaultRoutes.js +16 -0
  97. package/.dist/esm/src/defaultRoutes.js.map +1 -0
  98. package/.dist/esm/src/dispatch.d.ts +3 -0
  99. package/.dist/esm/src/dispatch.js +141 -0
  100. package/.dist/esm/src/dispatch.js.map +1 -0
  101. package/.dist/esm/src/lib/aotCacheLoader.d.ts +1 -0
  102. package/.dist/esm/src/lib/aotCacheLoader.js +13 -0
  103. package/.dist/esm/src/lib/aotCacheLoader.js.map +1 -0
  104. package/.dist/esm/src/lib/aotEmitter.d.ts +17 -0
  105. package/.dist/esm/src/lib/aotEmitter.js +70 -0
  106. package/.dist/esm/src/lib/aotEmitter.js.map +1 -0
  107. package/.dist/esm/src/lib/dispatchError.d.ts +5 -0
  108. package/.dist/esm/src/lib/dispatchError.js +39 -0
  109. package/.dist/esm/src/lib/dispatchError.js.map +1 -0
  110. package/.dist/esm/src/lib/handlers.d.ts +9 -0
  111. package/.dist/esm/src/lib/handlers.js +52 -0
  112. package/.dist/esm/src/lib/handlers.js.map +1 -0
  113. package/.dist/esm/src/lib/headers.d.ts +2 -0
  114. package/.dist/esm/src/lib/headers.js +64 -0
  115. package/.dist/esm/src/lib/headers.js.map +1 -0
  116. package/.dist/esm/src/lib/methodsCache.d.ts +11 -0
  117. package/.dist/esm/src/lib/methodsCache.js +56 -0
  118. package/.dist/esm/src/lib/methodsCache.js.map +1 -0
  119. package/.dist/esm/src/lib/queryBody.d.ts +7 -0
  120. package/.dist/esm/src/lib/queryBody.js +34 -0
  121. package/.dist/esm/src/lib/queryBody.js.map +1 -0
  122. package/.dist/esm/src/lib/reflection.d.ts +12 -0
  123. package/.dist/esm/src/lib/reflection.js +320 -0
  124. package/.dist/esm/src/lib/reflection.js.map +1 -0
  125. package/.dist/esm/src/lib/remoteMethods.d.ts +10 -0
  126. package/.dist/esm/src/lib/remoteMethods.js +109 -0
  127. package/.dist/esm/src/lib/remoteMethods.js.map +1 -0
  128. package/.dist/esm/src/lib/test/aotEmitter-test-router.d.ts +4 -0
  129. package/.dist/esm/src/lib/test/aotEmitter-test-router.js +24 -0
  130. package/.dist/esm/src/lib/test/aotEmitter-test-router.js.map +1 -0
  131. package/.dist/esm/src/router.d.ts +30 -0
  132. package/.dist/esm/src/router.js +431 -0
  133. package/.dist/esm/src/router.js.map +1 -0
  134. package/.dist/esm/src/routes/client.routes.d.ts +16 -0
  135. package/.dist/esm/src/routes/client.routes.js +76 -0
  136. package/.dist/esm/src/routes/client.routes.js.map +1 -0
  137. package/.dist/esm/src/routes/errors.routes.d.ts +7 -0
  138. package/.dist/esm/src/routes/errors.routes.js +49 -0
  139. package/.dist/esm/src/routes/errors.routes.js.map +1 -0
  140. package/.dist/esm/src/routes/mion.routes.d.ts +10 -0
  141. package/.dist/esm/src/routes/mion.routes.js +13 -0
  142. package/.dist/esm/src/routes/mion.routes.js.map +1 -0
  143. package/.dist/esm/src/routes/serializer.routes.d.ts +9 -0
  144. package/.dist/esm/src/routes/serializer.routes.js +191 -0
  145. package/.dist/esm/src/routes/serializer.routes.js.map +1 -0
  146. package/.dist/esm/src/routesFlow.d.ts +7 -0
  147. package/.dist/esm/src/routesFlow.js +227 -0
  148. package/.dist/esm/src/routesFlow.js.map +1 -0
  149. package/.dist/esm/src/types/context.d.ts +57 -0
  150. package/.dist/esm/src/types/context.js +31 -0
  151. package/.dist/esm/src/types/context.js.map +1 -0
  152. package/.dist/esm/src/types/definitions.d.ts +20 -0
  153. package/.dist/esm/src/types/definitions.js +15 -0
  154. package/.dist/esm/src/types/definitions.js.map +1 -0
  155. package/.dist/esm/src/types/general.d.ts +27 -0
  156. package/.dist/esm/src/types/general.js +14 -0
  157. package/.dist/esm/src/types/general.js.map +1 -0
  158. package/.dist/esm/src/types/guards.d.ts +17 -0
  159. package/.dist/esm/src/types/guards.js +66 -0
  160. package/.dist/esm/src/types/guards.js.map +1 -0
  161. package/.dist/esm/src/types/handlers.d.ts +12 -0
  162. package/.dist/esm/src/types/handlers.js +13 -0
  163. package/.dist/esm/src/types/handlers.js.map +1 -0
  164. package/.dist/esm/src/types/publicMethods.d.ts +45 -0
  165. package/.dist/esm/src/types/publicMethods.js +24 -0
  166. package/.dist/esm/src/types/publicMethods.js.map +1 -0
  167. package/.dist/esm/src/types/remoteMethods.d.ts +44 -0
  168. package/.dist/esm/src/types/remoteMethods.js +25 -0
  169. package/.dist/esm/src/types/remoteMethods.js.map +1 -0
  170. package/LICENSE +21 -0
  171. package/README.md +34 -0
  172. package/package.json +67 -0
@@ -0,0 +1,145 @@
1
+ import { __ΩCallContext, __ΩContextDataFactory, __ΩMionHeaders, __ΩMionRequest, __ΩMionResponse, __ΩRawRequestBody, __ΩRawResponseBody, __ΩResponseBody, __ΩRoutesFlowExecutionResult } from "./src/types/context.js";
2
+ import { __ΩAnyHandlerDef, __ΩHeadersMiddleFnDef, __ΩMiddleFnDef, __ΩRawMiddleFnDef, __ΩRouteDef } from "./src/types/definitions.js";
3
+ import { __ΩHeadersMethod, __ΩHeadersMiddleFnOptions, __ΩMethodsExecutionChain, __ΩMiddleFnMethod, __ΩMiddleFnOptions, __ΩRawMethod, __ΩRawMiddleFnOptions, __ΩRemoteMethod, __ΩRouteMethod, __ΩRouteOptions } from "./src/types/remoteMethods.js";
4
+ import { __ΩRoute, __ΩRouterEntry, __ΩRouterOptions, __ΩRoutes } from "./src/types/general.js";
5
+ import { isAnyMiddleFnDef, isExecutable, isHeaderExecutable, isHeadersMiddleFnDef, isMiddleFnDef, isPublicExecutable, isRawExecutable, isRawMiddleFnDef, isRoute, isRouteDef, isRouteExecutable, isRoutes } from "./src/types/guards.js";
6
+ import { __ΩAnyHandler, __ΩHandler, __ΩHeaderHandler, __ΩRawMiddleFnHandler } from "./src/types/handlers.js";
7
+ import { __ΩMayReturnError, __ΩMiddleFnsCollection, __ΩPrivateDef, __ΩPrivateMiddleFnDef, __ΩPublicApi, __ΩPublicHandler, __ΩPublicHeadersFn, __ΩPublicMiddleFn, __ΩPublicRoute, __ΩRemoteApi } from "./src/types/publicMethods.js";
8
+ import { DEFAULT_ROUTE_OPTIONS, HEADER_HOOK_DEFAULT_PARAMS, IS_TEST_ENV, MAX_ROUTE_NESTING, NOT_FOUND_HOOK_NAME, NOT_FOUND_PATH, ROUTE_DEFAULT_PARAMS, WORKFLOW_KEY, WORKFLOW_PATH } from "./src/constants.js";
9
+ import { addEndMiddleFns, addStartMiddleFns, endMiddleFns, geMiddleFnsSize, geRoutesSize, getAllExecutablesIds, getAnyExecutable, getComplexity, getExecutableFromMiddleFn, getExecutableFromRawMiddleFn, getExecutableFromRoute, getMiddleFnExecutable, getRouteEntries, getRouteExecutable, getRouteExecutableFromPath, getRouteExecutionChain, getRouterOptions, getTotalExecutables, initMionRouter, initRouter, isPrivateDefinition, isPrivateExecutable, registerRoutes, resetRouter, shouldFullGenerateSpec, startMiddleFns } from "./src/router.js";
10
+ import { dispatchRoute } from "./src/dispatch.js";
11
+ import { acquireCallContext, clearContextPool, createCallContext, getContextPoolStats, releaseCallContext } from "./src/callContext.js";
12
+ import { getRouterFatalErrorResponse, onExecutableError } from "./src/lib/dispatchError.js";
13
+ import { headersFromRecord } from "./src/lib/headers.js";
14
+ import { getPublicApi, getSerializableMethod, resetRemoteMethodsMetadata, serializeJitFn, serializeMethodDeps, serializePureDeps } from "./src/lib/remoteMethods.js";
15
+ import { headersFn, middleFn, mutation, query, rawMiddleFn, route } from "./src/lib/handlers.js";
16
+ import { __ΩQueryBodyResult, decodeQueryBody } from "./src/lib/queryBody.js";
17
+ import { addToPersistedMethods, getPersistedMethod, getPersistedMethodMetadata, getPersistedMethods, loadCompiledMethods, persistedMethods, resetPersistedMethods, setPersistedMethods } from "./src/lib/methodsCache.js";
18
+ import { mionErrorsRoutes } from "./src/routes/errors.routes.js";
19
+ import { __ΩMionRoutes, mionRoutes } from "./src/routes/mion.routes.js";
20
+ export {
21
+ DEFAULT_ROUTE_OPTIONS,
22
+ HEADER_HOOK_DEFAULT_PARAMS,
23
+ IS_TEST_ENV,
24
+ MAX_ROUTE_NESTING,
25
+ NOT_FOUND_HOOK_NAME,
26
+ NOT_FOUND_PATH,
27
+ ROUTE_DEFAULT_PARAMS,
28
+ WORKFLOW_KEY,
29
+ WORKFLOW_PATH,
30
+ __ΩAnyHandler,
31
+ __ΩAnyHandlerDef,
32
+ __ΩCallContext,
33
+ __ΩContextDataFactory,
34
+ __ΩHandler,
35
+ __ΩHeaderHandler,
36
+ __ΩHeadersMethod,
37
+ __ΩHeadersMiddleFnDef,
38
+ __ΩHeadersMiddleFnOptions,
39
+ __ΩMayReturnError,
40
+ __ΩMethodsExecutionChain,
41
+ __ΩMiddleFnDef,
42
+ __ΩMiddleFnMethod,
43
+ __ΩMiddleFnOptions,
44
+ __ΩMiddleFnsCollection,
45
+ __ΩMionHeaders,
46
+ __ΩMionRequest,
47
+ __ΩMionResponse,
48
+ __ΩMionRoutes,
49
+ __ΩPrivateDef,
50
+ __ΩPrivateMiddleFnDef,
51
+ __ΩPublicApi,
52
+ __ΩPublicHandler,
53
+ __ΩPublicHeadersFn,
54
+ __ΩPublicMiddleFn,
55
+ __ΩPublicRoute,
56
+ __ΩQueryBodyResult,
57
+ __ΩRawMethod,
58
+ __ΩRawMiddleFnDef,
59
+ __ΩRawMiddleFnHandler,
60
+ __ΩRawMiddleFnOptions,
61
+ __ΩRawRequestBody,
62
+ __ΩRawResponseBody,
63
+ __ΩRemoteApi,
64
+ __ΩRemoteMethod,
65
+ __ΩResponseBody,
66
+ __ΩRoute,
67
+ __ΩRouteDef,
68
+ __ΩRouteMethod,
69
+ __ΩRouteOptions,
70
+ __ΩRouterEntry,
71
+ __ΩRouterOptions,
72
+ __ΩRoutes,
73
+ __ΩRoutesFlowExecutionResult,
74
+ acquireCallContext,
75
+ addEndMiddleFns,
76
+ addStartMiddleFns,
77
+ addToPersistedMethods,
78
+ clearContextPool,
79
+ createCallContext,
80
+ decodeQueryBody,
81
+ dispatchRoute,
82
+ endMiddleFns,
83
+ geMiddleFnsSize,
84
+ geRoutesSize,
85
+ getAllExecutablesIds,
86
+ getAnyExecutable,
87
+ getComplexity,
88
+ getContextPoolStats,
89
+ getExecutableFromMiddleFn,
90
+ getExecutableFromRawMiddleFn,
91
+ getExecutableFromRoute,
92
+ getMiddleFnExecutable,
93
+ getPersistedMethod,
94
+ getPersistedMethodMetadata,
95
+ getPersistedMethods,
96
+ getPublicApi,
97
+ getRouteEntries,
98
+ getRouteExecutable,
99
+ getRouteExecutableFromPath,
100
+ getRouteExecutionChain,
101
+ getRouterFatalErrorResponse,
102
+ getRouterOptions,
103
+ getSerializableMethod,
104
+ getTotalExecutables,
105
+ headersFn,
106
+ headersFromRecord,
107
+ initMionRouter,
108
+ initRouter,
109
+ isAnyMiddleFnDef,
110
+ isExecutable,
111
+ isHeaderExecutable,
112
+ isHeadersMiddleFnDef,
113
+ isMiddleFnDef,
114
+ isPrivateDefinition,
115
+ isPrivateExecutable,
116
+ isPublicExecutable,
117
+ isRawExecutable,
118
+ isRawMiddleFnDef,
119
+ isRoute,
120
+ isRouteDef,
121
+ isRouteExecutable,
122
+ isRoutes,
123
+ loadCompiledMethods,
124
+ middleFn,
125
+ mionErrorsRoutes,
126
+ mionRoutes,
127
+ mutation,
128
+ onExecutableError,
129
+ persistedMethods,
130
+ query,
131
+ rawMiddleFn,
132
+ registerRoutes,
133
+ releaseCallContext,
134
+ resetPersistedMethods,
135
+ resetRemoteMethodsMetadata,
136
+ resetRouter,
137
+ route,
138
+ serializeJitFn,
139
+ serializeMethodDeps,
140
+ serializePureDeps,
141
+ setPersistedMethods,
142
+ shouldFullGenerateSpec,
143
+ startMiddleFns
144
+ };
145
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,10 @@
1
+ import { CallContext, MionHeaders, RawRequestBody } from './types/context.ts';
2
+ import { RouterOptions } from './types/general.ts';
3
+ import { SerializerCode } from '@mionjs/core';
4
+ export declare function getContextPoolStats(): {
5
+ poolSize: number;
6
+ };
7
+ export declare function clearContextPool(): void;
8
+ export declare function createCallContext(path: string, opts: RouterOptions, reqRawBody: RawRequestBody, rawRequest: unknown, reqHeaders: MionHeaders, respHeaders: MionHeaders, reqBodyType?: SerializerCode, urlQuery?: string): CallContext;
9
+ export declare function acquireCallContext(usePooling: boolean, path: string, opts: RouterOptions, reqRawBody: RawRequestBody, rawRequest: unknown, reqHeaders: MionHeaders, respHeaders: MionHeaders, reqBodyType?: SerializerCode, urlQuery?: string): CallContext;
10
+ export declare function releaseCallContext(ctx: CallContext, maxPoolSize: number): void;
@@ -0,0 +1,125 @@
1
+ import { WORKFLOW_PATH } from "./constants.js";
2
+ import { getRouteExecutionChain } from "./router.js";
3
+ import { StatusCodes, SerializerModes, getRoutePath, MION_ROUTES, RpcError } from "@mionjs/core";
4
+ import { getRoutesFlowExecutionChain } from "./routesFlow.js";
5
+ let contextPool = [];
6
+ function getContextPoolStats() {
7
+ return {
8
+ poolSize: contextPool.length
9
+ };
10
+ }
11
+ function clearContextPool() {
12
+ contextPool = [];
13
+ }
14
+ function createCallContext(path, opts, reqRawBody, rawRequest, reqHeaders, respHeaders, reqBodyType, urlQuery) {
15
+ const transformedPath = opts.pathTransform?.(rawRequest, path) || path;
16
+ const { executionChain, routesFlowRouteIds } = getExecutionChain(path, transformedPath, urlQuery, rawRequest, opts);
17
+ return {
18
+ path: transformedPath,
19
+ request: {
20
+ headers: reqHeaders,
21
+ rawBody: reqRawBody,
22
+ bodyType: reqBodyType ?? getRequestBodyType(reqRawBody),
23
+ body: {},
24
+ thrownErrors: void 0
25
+ },
26
+ response: {
27
+ statusCode: StatusCodes.OK,
28
+ hasErrors: false,
29
+ headers: respHeaders,
30
+ body: {},
31
+ rawBody: "",
32
+ serializer: SerializerModes.json,
33
+ binSerializer: void 0
34
+ },
35
+ executionChain,
36
+ shared: opts.contextDataFactory ? opts.contextDataFactory() : {},
37
+ urlQuery,
38
+ routesFlowRouteIds
39
+ };
40
+ }
41
+ function acquireCallContext(usePooling, path, opts, reqRawBody, rawRequest, reqHeaders, respHeaders, reqBodyType, urlQuery) {
42
+ if (!usePooling) return createCallContext(path, opts, reqRawBody, rawRequest, reqHeaders, respHeaders, reqBodyType, urlQuery);
43
+ const pooledContext = contextPool.pop();
44
+ const transformedPath = opts.pathTransform?.(rawRequest, path) || path;
45
+ if (pooledContext) {
46
+ const ctx = pooledContext;
47
+ ctx.path = transformedPath;
48
+ const req = ctx.request;
49
+ req.headers = reqHeaders;
50
+ req.rawBody = reqRawBody;
51
+ req.bodyType = reqBodyType ?? getRequestBodyType(reqRawBody);
52
+ req.body = {};
53
+ req.thrownErrors = void 0;
54
+ const resp = ctx.response;
55
+ resp.statusCode = StatusCodes.OK;
56
+ resp.hasErrors = false;
57
+ resp.headers = respHeaders;
58
+ resp.body = {};
59
+ resp.rawBody = "";
60
+ resp.serializer = SerializerModes.json;
61
+ resp.binSerializer = void 0;
62
+ const { executionChain, routesFlowRouteIds } = getExecutionChain(path, transformedPath, urlQuery, rawRequest, opts);
63
+ ctx.executionChain = executionChain;
64
+ ctx.routesFlowRouteIds = routesFlowRouteIds;
65
+ ctx.shared = opts.contextDataFactory ? opts.contextDataFactory() : {};
66
+ ctx.urlQuery = urlQuery;
67
+ return ctx;
68
+ }
69
+ return createCallContext(path, opts, reqRawBody, rawRequest, reqHeaders, respHeaders, reqBodyType, urlQuery);
70
+ }
71
+ function releaseCallContext(ctx, maxPoolSize) {
72
+ if (contextPool.length < maxPoolSize) {
73
+ const mutableCtx = ctx;
74
+ const req = mutableCtx.request;
75
+ req.rawBody = "";
76
+ req.body = null;
77
+ req.thrownErrors = void 0;
78
+ mutableCtx.response = {
79
+ statusCode: StatusCodes.OK,
80
+ hasErrors: false,
81
+ headers: null,
82
+ // Will be set when context is acquired
83
+ body: null,
84
+ // Will be set when context is acquired
85
+ rawBody: "",
86
+ serializer: SerializerModes.json,
87
+ binSerializer: void 0
88
+ };
89
+ mutableCtx.shared = null;
90
+ mutableCtx.executionChain = null;
91
+ mutableCtx.routesFlowRouteIds = void 0;
92
+ contextPool.push(ctx);
93
+ }
94
+ }
95
+ function getRequestBodyType(rawBody) {
96
+ if (typeof rawBody === "string") return SerializerModes.stringifyJson;
97
+ if (rawBody instanceof ArrayBuffer || rawBody instanceof Uint8Array) return SerializerModes.binary;
98
+ return SerializerModes.json;
99
+ }
100
+ function getExecutionChain(originalPath, transformedPath, urlQuery, rawRequest, opts) {
101
+ const hasPrefix = !!opts.basePath;
102
+ const isRoutesFlowPath = hasPrefix ? originalPath.endsWith(WORKFLOW_PATH) : originalPath === WORKFLOW_PATH;
103
+ if (isRoutesFlowPath) return getRoutesFlowExecutionChain(rawRequest, opts, urlQuery);
104
+ let executionChain = getRouteExecutionChain(transformedPath);
105
+ if (!executionChain) {
106
+ const notFoundPath = getRoutePath([MION_ROUTES.notFound], opts);
107
+ executionChain = getRouteExecutionChain(notFoundPath);
108
+ if (!executionChain) {
109
+ throw new RpcError({
110
+ statusCode: StatusCodes.UNEXPECTED_ERROR,
111
+ type: "not-found",
112
+ publicMessage: "Not-found route is not registered. This should never happen."
113
+ });
114
+ }
115
+ }
116
+ return { executionChain };
117
+ }
118
+ export {
119
+ acquireCallContext,
120
+ clearContextPool,
121
+ createCallContext,
122
+ getContextPoolStats,
123
+ releaseCallContext
124
+ };
125
+ //# sourceMappingURL=callContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callContext.js","sources":["../../../src/callContext.ts"],"sourcesContent":["/* ########\n * 2026 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {WORKFLOW_PATH} from './constants.ts';\nimport {getRouteExecutionChain} from './router.ts';\nimport type {\n CallContext,\n MionResponse,\n MionRequest,\n MionHeaders,\n RawRequestBody,\n RoutesFlowExecutionResult,\n} from './types/context.ts';\nimport type {RouterOptions} from './types/general.ts';\nimport {Mutable, StatusCodes, SerializerModes, SerializerCode, RpcError, MION_ROUTES, getRoutePath} from '@mionjs/core';\nimport {getRoutesFlowExecutionChain} from './routesFlow.ts';\n\n// ############# POOL STATE #############\n\nlet contextPool: CallContext[] = [];\n\n/** Get current pool statistics for monitoring */\nexport function getContextPoolStats(): {poolSize: number} {\n return {\n poolSize: contextPool.length,\n };\n}\n\n/** Clear the context pool - useful for testing */\nexport function clearContextPool(): void {\n contextPool = [];\n}\n\n// ############# CONTEXT CREATION #############\n\n/** Creates a new CallContext without pooling (original behavior) */\nexport function createCallContext(\n path: string,\n opts: RouterOptions,\n reqRawBody: RawRequestBody,\n rawRequest: unknown,\n reqHeaders: MionHeaders,\n respHeaders: MionHeaders,\n reqBodyType?: SerializerCode,\n urlQuery?: string\n): CallContext {\n const transformedPath = opts.pathTransform?.(rawRequest, path) || path;\n const {executionChain, routesFlowRouteIds} = getExecutionChain(path, transformedPath, urlQuery, rawRequest, opts);\n return {\n path: transformedPath,\n request: {\n headers: reqHeaders,\n rawBody: reqRawBody,\n bodyType: reqBodyType ?? getRequestBodyType(reqRawBody),\n body: {},\n thrownErrors: undefined,\n },\n response: {\n statusCode: StatusCodes.OK,\n hasErrors: false,\n headers: respHeaders,\n body: {},\n rawBody: '',\n serializer: SerializerModes.json,\n binSerializer: undefined,\n },\n executionChain,\n shared: opts.contextDataFactory ? opts.contextDataFactory() : {},\n urlQuery,\n routesFlowRouteIds,\n } as CallContext;\n}\n\n/** Acquires a CallContext from the pool or creates a new one */\nexport function acquireCallContext(\n usePooling: boolean,\n path: string,\n opts: RouterOptions,\n reqRawBody: RawRequestBody,\n rawRequest: unknown,\n reqHeaders: MionHeaders,\n respHeaders: MionHeaders,\n reqBodyType?: SerializerCode,\n urlQuery?: string\n): CallContext {\n if (!usePooling) return createCallContext(path, opts, reqRawBody, rawRequest, reqHeaders, respHeaders, reqBodyType, urlQuery);\n const pooledContext = contextPool.pop();\n const transformedPath = opts.pathTransform?.(rawRequest, path) || path;\n\n if (pooledContext) {\n // Reuse the pooled context shell, but create fresh body objects\n const ctx = pooledContext as Mutable<CallContext>;\n ctx.path = transformedPath;\n // Reset request - reuse the request object shell\n const req = ctx.request as Mutable<MionRequest>;\n req.headers = reqHeaders;\n req.rawBody = reqRawBody;\n req.bodyType = reqBodyType ?? getRequestBodyType(reqRawBody);\n req.body = {}; // Must be fresh - handlers write to this\n req.thrownErrors = undefined;\n // Reset response - reuse the response object shell\n const resp = ctx.response as Mutable<MionResponse>;\n resp.statusCode = StatusCodes.OK;\n resp.hasErrors = false;\n resp.headers = respHeaders;\n resp.body = {}; // Must be fresh - handlers write to this\n resp.rawBody = '';\n resp.serializer = SerializerModes.json;\n resp.binSerializer = undefined;\n // Reset execution chain and routesFlow route IDs\n const {executionChain, routesFlowRouteIds} = getExecutionChain(path, transformedPath, urlQuery, rawRequest, opts);\n ctx.executionChain = executionChain;\n ctx.routesFlowRouteIds = routesFlowRouteIds;\n // Reset shared data\n ctx.shared = opts.contextDataFactory ? opts.contextDataFactory() : {};\n // Reset urlQuery\n ctx.urlQuery = urlQuery;\n return ctx;\n }\n // No pooled context available, create new one\n return createCallContext(path, opts, reqRawBody, rawRequest, reqHeaders, respHeaders, reqBodyType, urlQuery);\n}\n\n/** Releases a CallContext back to the pool for reuse */\nexport function releaseCallContext(ctx: CallContext, maxPoolSize: number): void {\n if (contextPool.length < maxPoolSize) {\n const mutableCtx = ctx as Mutable<CallContext>;\n const req = mutableCtx.request as Mutable<MionRequest>;\n // Clear request data - safe to mutate since request is not returned to caller\n req.rawBody = '';\n req.body = null as any; // Will be set when context is acquired\n req.thrownErrors = undefined;\n // Create fresh response object - the old one may still be referenced by the caller\n // IMPORTANT: We must NOT mutate the existing response object because it's returned\n // to the platform wrapper (e.g., HTTP handler) which may still be using it\n mutableCtx.response = {\n statusCode: StatusCodes.OK,\n hasErrors: false,\n headers: null as any, // Will be set when context is acquired\n body: null as any, // Will be set when context is acquired\n rawBody: '',\n serializer: SerializerModes.json,\n binSerializer: undefined,\n };\n mutableCtx.shared = null as any;\n mutableCtx.executionChain = null as any;\n mutableCtx.routesFlowRouteIds = undefined;\n contextPool.push(ctx);\n }\n // If pool is full, let the context be garbage collected\n}\n\n// ############# HELPER FUNCTIONS #############\n\nfunction getRequestBodyType(rawBody: RawRequestBody): SerializerCode {\n if (typeof rawBody === 'string') return SerializerModes.stringifyJson;\n if (rawBody instanceof ArrayBuffer || rawBody instanceof Uint8Array) return SerializerModes.binary;\n return SerializerModes.json;\n}\n\n/** Gets the execution chain for a path, handling routesFlow paths specially */\nfunction getExecutionChain(\n originalPath: string,\n transformedPath: string,\n urlQuery: string | undefined,\n rawRequest: unknown,\n opts: RouterOptions\n): RoutesFlowExecutionResult {\n const hasPrefix = !!opts.basePath;\n // Handle routesFlow path - check if the original path ends with the workflow key\n // This works with any prefix (e.g., /mion-routes-flow, /api/v1/mion-routes-flow)\n const isRoutesFlowPath = hasPrefix ? originalPath.endsWith(WORKFLOW_PATH) : originalPath === WORKFLOW_PATH;\n if (isRoutesFlowPath) return getRoutesFlowExecutionChain(rawRequest, opts, urlQuery);\n\n // Normal path - get execution chain from router using transformed path\n let executionChain = getRouteExecutionChain(transformedPath);\n if (!executionChain) {\n const notFoundPath = getRoutePath([MION_ROUTES.notFound], opts);\n executionChain = getRouteExecutionChain(notFoundPath);\n if (!executionChain) {\n throw new RpcError({\n statusCode: StatusCodes.UNEXPECTED_ERROR,\n type: 'not-found',\n publicMessage: 'Not-found route is not registered. This should never happen.',\n });\n }\n }\n return {executionChain};\n}\n"],"names":[],"mappings":";;;;AAuBA,IAAI,cAA6B,CAAA;AAG1B,SAAS,sBAA0C;AACtD,SAAO;AAAA,IACH,UAAU,YAAY;AAAA,EAAA;AAE9B;AAGO,SAAS,mBAAyB;AACrC,gBAAc,CAAA;AAClB;AAKO,SAAS,kBACZ,MACA,MACA,YACA,YACA,YACA,aACA,aACA,UACW;AACX,QAAM,kBAAkB,KAAK,gBAAgB,YAAY,IAAI,KAAK;AAClE,QAAM,EAAC,gBAAgB,mBAAA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,MAAA,CAClB;AAAA,IACL;AAAA,EACJ;AACA,SAAO,EAAC,eAAA;AACZ;"}
@@ -0,0 +1,10 @@
1
+ import { RouterOptions } from './types/general.ts';
2
+ export declare const IS_TEST_ENV: boolean;
3
+ export declare const ROUTE_DEFAULT_PARAMS: string[];
4
+ export declare const HEADER_HOOK_DEFAULT_PARAMS: string[];
5
+ export declare const DEFAULT_ROUTE_OPTIONS: Readonly<RouterOptions>;
6
+ export declare const MAX_ROUTE_NESTING = 10;
7
+ export declare const NOT_FOUND_HOOK_NAME = "_mi\u03A6n404N\u03A6tf\u03A6undH\u03A6\u03A6k_";
8
+ export declare const NOT_FOUND_PATH: string;
9
+ export declare const WORKFLOW_KEY = "mion-routes-flow";
10
+ export declare const WORKFLOW_PATH = "/mion-routes-flow";
@@ -0,0 +1,45 @@
1
+ import { getENV, PATH_SEPARATOR, MION_ROUTES } from "@mionjs/core";
2
+ const IS_TEST_ENV = getENV("JEST_WORKER_ID") !== void 0 || getENV("NODE_ENV") === "test";
3
+ const ROUTE_DEFAULT_PARAMS = ["context"];
4
+ const HEADER_HOOK_DEFAULT_PARAMS = ["context", "headers"];
5
+ const DEFAULT_ROUTE_OPTIONS = {
6
+ /** Prefix for all routes, i.e: api/v1. Path separator is added between the prefix and the route */
7
+ basePath: "",
8
+ /** Suffix for all routes, i.e: .json. No path separator is added between the route and the suffix */
9
+ suffix: "",
10
+ /** Function that transforms the path before finding a route */
11
+ pathTransform: void 0,
12
+ /** Default serializer mode - json as default native serializer, and minimum overhead to transform just required fields */
13
+ serializer: "json",
14
+ /** Default run type compiling options for routes and middleFns, can't be configured by the user as would break functionality */
15
+ runTypeOptions: {},
16
+ /** set to true to generate router spec for clients. */
17
+ getPublicRoutesData: process.env.GENERATE_ROUTER_SPEC === "true",
18
+ /** Set true to automatically generate and id for every error. */
19
+ autoGenerateErrorId: false,
20
+ /** client routes are initialized by default */
21
+ skipClientRoutes: IS_TEST_ENV,
22
+ /** AOT mode is disabled by default */
23
+ aot: false,
24
+ /** Context pooling size == 100 by default */
25
+ maxContextPoolSize: 100,
26
+ /** RoutesFlow cache size == 100 by default */
27
+ maxRoutesFlowsCacheSize: 100
28
+ };
29
+ const MAX_ROUTE_NESTING = 10;
30
+ const NOT_FOUND_HOOK_NAME = "_miΦn404NΦtfΦundHΦΦk_";
31
+ const NOT_FOUND_PATH = `${PATH_SEPARATOR}${MION_ROUTES.notFound}`;
32
+ const WORKFLOW_KEY = `mion-routes-flow`;
33
+ const WORKFLOW_PATH = `${PATH_SEPARATOR}${WORKFLOW_KEY}`;
34
+ export {
35
+ DEFAULT_ROUTE_OPTIONS,
36
+ HEADER_HOOK_DEFAULT_PARAMS,
37
+ IS_TEST_ENV,
38
+ MAX_ROUTE_NESTING,
39
+ NOT_FOUND_HOOK_NAME,
40
+ NOT_FOUND_PATH,
41
+ ROUTE_DEFAULT_PARAMS,
42
+ WORKFLOW_KEY,
43
+ WORKFLOW_PATH
44
+ };
45
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sources":["../../../src/constants.ts"],"sourcesContent":["/* ########\n * 2022 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {RouterOptions} from './types/general.ts';\nimport {getENV, MION_ROUTES, PATH_SEPARATOR} from '@mionjs/core';\n\nexport const IS_TEST_ENV = getENV('JEST_WORKER_ID') !== undefined || getENV('NODE_ENV') === 'test';\n\nexport const ROUTE_DEFAULT_PARAMS = ['context'];\nexport const HEADER_HOOK_DEFAULT_PARAMS = ['context', 'headers'];\n\nexport const DEFAULT_ROUTE_OPTIONS = {\n /** Prefix for all routes, i.e: api/v1. Path separator is added between the prefix and the route */\n basePath: '',\n /** Suffix for all routes, i.e: .json. No path separator is added between the route and the suffix */\n suffix: '',\n /** Function that transforms the path before finding a route */\n pathTransform: undefined,\n /** Default serializer mode - json as default native serializer, and minimum overhead to transform just required fields */\n serializer: 'json',\n /** Default run type compiling options for routes and middleFns, can't be configured by the user as would break functionality */\n runTypeOptions: {},\n /** set to true to generate router spec for clients. */\n getPublicRoutesData: process.env.GENERATE_ROUTER_SPEC === 'true',\n /** Set true to automatically generate and id for every error. */\n autoGenerateErrorId: false,\n /** client routes are initialized by default */\n skipClientRoutes: IS_TEST_ENV,\n /** AOT mode is disabled by default */\n aot: false,\n /** Context pooling size == 100 by default */\n maxContextPoolSize: 100,\n /** RoutesFlow cache size == 100 by default */\n maxRoutesFlowsCacheSize: 100,\n} as Readonly<RouterOptions>;\n\nexport const MAX_ROUTE_NESTING = 10;\nexport const NOT_FOUND_HOOK_NAME = '_miΦn404NΦtfΦundHΦΦk_';\nexport const NOT_FOUND_PATH = `${PATH_SEPARATOR}${MION_ROUTES.notFound}`;\nexport const WORKFLOW_KEY = `mion-routes-flow`;\nexport const WORKFLOW_PATH = `${PATH_SEPARATOR}${WORKFLOW_KEY}`;\n"],"names":[],"mappings":";AAUO,MAAM,cAAc,OAAO,gBAAgB,MAAM,UAAa,OAAO,UAAU,MAAM;AAErF,MAAM,uBAAuB,CAAC,SAAS;AACvC,MAAM,6BAA6B,CAAC,WAAW,SAAS;AAExD,MAAM,wBAAwB;AAAA;AAAA,EAEjC,UAAU;AAAA;AAAA,EAEV,QAAQ;AAAA;AAAA,EAER,eAAe;AAAA;AAAA,EAEf,YAAY;AAAA;AAAA,EAEZ,gBAAgB,CAAA;AAAA;AAAA,EAEhB,qBAAqB,QAAQ,IAAI,yBAAyB;AAAA;AAAA,EAE1D,qBAAqB;AAAA;AAAA,EAErB,kBAAkB;AAAA;AAAA,EAElB,KAAK;AAAA;AAAA,EAEL,oBAAoB;AAAA;AAAA,EAEpB,yBAAyB;;AAGtB,MAAM,oBAAoB;AAC1B,MAAM,sBAAsB;AAC5B,MAAM,iBAAiB,GAAG,cAAc,GAAG,YAAY,QAAQ;AAC/D,MAAM,eAAe;AACrB,MAAM,gBAAgB,GAAG,cAAc,GAAG,YAAY;"}
@@ -0,0 +1,3 @@
1
+ export declare const defaultApi: any;
2
+ export type DefaultApi = typeof defaultApi;
3
+ export declare type __ΩDefaultApi = any[];
@@ -0,0 +1,16 @@
1
+ import { middleFn, initMionRouter } from "@mionjs/router";
2
+ function __assignType(fn, args) {
3
+ fn.__type = args;
4
+ return fn;
5
+ }
6
+ const routes = {
7
+ // Only required as initMionRouter needs at least one route/middleFn
8
+ "mion@mionEmptyMiddleFn": middleFn(__assignType(() => void 0, ["", "P$/!"]))
9
+ };
10
+ const defaultApi = initMionRouter(routes, { skipClientRoutes: false });
11
+ const __ΩDefaultApi = [() => defaultApi, "DefaultApi", 'i!w"y'];
12
+ export {
13
+ __ΩDefaultApi,
14
+ defaultApi
15
+ };
16
+ //# sourceMappingURL=defaultRoutes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaultRoutes.js","sources":["../../../src/defaultRoutes.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\n/**\n * Default routes script for AOT cache generation.\n *\n * This script initializes the mion router with only the built-in internal routes\n * (error routes, metadata routes, etc.). It is used by the Vite plugin as a fallback\n * when no user-provided startServerScript is configured.\n *\n * When run with MION_COMPILE=true, the router's emitAOTCaches() will automatically\n * collect and send the serialized caches for these internal routes via IPC.\n *\n * Internal routes included:\n * - @thrownErrors: Error serialization route\n * - mion@notFound: Not-found handler\n * - mion@platformError: Platform error handler\n * - mion@methodsMetadataById: Remote methods metadata by ID\n * - mion@methodsMetadataByPath: Remote methods metadata by path\n */\n\nimport {middleFn, initMionRouter} from '@mionjs/router';\nimport type {Routes} from '@mionjs/router';\n\nconst routes = {\n // Only required as initMionRouter needs at least one route/middleFn\n 'mion@mionEmptyMiddleFn': middleFn((): void => undefined),\n} satisfies Routes;\n\n// Initialize the router — this registers all internal routes and emits AOT caches\n// skipClientRoutes must be false to ensure metadata routes are included in AOT caches\nexport const defaultApi = initMionRouter(routes, {skipClientRoutes: false});\nexport type DefaultApi = typeof defaultApi;\n"],"names":[],"mappings":";;;;;AA4BA,MAAM,SAAS;AAAA;AAAA,EAEX,0BAA0B,SAAQ,aAAC,MAAY,QAAS,CAAA,IAAA,MAAA,CAAA,CAAA;;AAKrD,MAAM,aAAa,eAAe,QAAQ,EAAC,kBAAkB,OAAM;;"}
@@ -0,0 +1,3 @@
1
+ import { MionResponse, MionHeaders, RawRequestBody } from './types/context.ts';
2
+ import { SerializerCode } from '@mionjs/core';
3
+ export declare function dispatchRoute<Req, Resp>(path: string, reqRawBody: RawRequestBody, reqHeaders: MionHeaders, respHeaders: MionHeaders, rawRequest: Req, rawResponse?: Resp, reqBodyType?: SerializerCode, urlQuery?: string): Promise<MionResponse>;
@@ -0,0 +1,141 @@
1
+ import { getRouterOptions } from "./router.js";
2
+ import { HeadersSubset, HandlerType, SerializerModes, RpcError, StatusCodes } from "@mionjs/core";
3
+ import { onExecutableError } from "./lib/dispatchError.js";
4
+ import { acquireCallContext, releaseCallContext } from "./callContext.js";
5
+ async function dispatchRoute(path, reqRawBody, reqHeaders, respHeaders, rawRequest, rawResponse, reqBodyType, urlQuery) {
6
+ const opts = getRouterOptions();
7
+ const usePooling = opts.maxContextPoolSize > 0;
8
+ const context = acquireCallContext(
9
+ usePooling,
10
+ path,
11
+ opts,
12
+ reqRawBody,
13
+ rawRequest,
14
+ reqHeaders,
15
+ respHeaders,
16
+ reqBodyType,
17
+ urlQuery
18
+ );
19
+ try {
20
+ await runExecutionChain(context, rawRequest, rawResponse, opts);
21
+ return context.response;
22
+ } catch (err) {
23
+ return Promise.reject(err);
24
+ } finally {
25
+ if (usePooling) {
26
+ releaseCallContext(context, opts.maxContextPoolSize);
27
+ }
28
+ }
29
+ }
30
+ async function runExecutionChain(context, rawRequest, rawResponse, opts) {
31
+ const { response, request } = context;
32
+ const executionList = context.executionChain.methods;
33
+ response.serializer = context.executionChain.serializer;
34
+ for (let i = 0; i < executionList.length; i++) {
35
+ const executable = executionList[i];
36
+ if (response.hasErrors && !executable.options.runOnError) continue;
37
+ try {
38
+ const methodCaller = executable.methodCaller || getMethodCaller(executable);
39
+ const result = await methodCaller(context, executable, request, response, opts, rawRequest, rawResponse);
40
+ if (result === void 0 || !executable.hasReturnData) continue;
41
+ if (executable.headersReturn && result instanceof HeadersSubset) {
42
+ const headersMap = result.headers;
43
+ for (const name in headersMap) {
44
+ const value = headersMap[name];
45
+ if (value !== void 0 && value !== null) {
46
+ response.headers.set(name, value);
47
+ }
48
+ }
49
+ continue;
50
+ }
51
+ response.body[executable.id] = result;
52
+ } catch (err) {
53
+ onExecutableError(context, executable, err);
54
+ }
55
+ }
56
+ return context.response;
57
+ }
58
+ async function runRawMiddleFn(context, executable, req, resp, opts, rawRequest, rawResponse) {
59
+ const result = await executable.handler(context, rawRequest, rawResponse, opts);
60
+ return result;
61
+ }
62
+ async function runHeadersMiddleFn(context, executable, request) {
63
+ const headerNames = executable.headersParam.headerNames;
64
+ const params = deserializeBodyParamsOrThrow(request, executable);
65
+ const headersMap = {};
66
+ headerNames.forEach((name) => {
67
+ const value = request.headers.get(name);
68
+ if (value) headersMap[name] = value;
69
+ });
70
+ const headersSubset = new HeadersSubset(headersMap);
71
+ validateHeaderParamsOrThrow(headersSubset, executable);
72
+ if (executable.options.validateParams) validateParametersOrThrow(params, executable);
73
+ const result = await executable.handler(context, headersSubset, ...params);
74
+ return result;
75
+ }
76
+ async function runRouteOrMiddleFn(context, executable, request) {
77
+ const params = deserializeBodyParamsOrThrow(request, executable);
78
+ if (executable.options.validateParams) validateParametersOrThrow(params, executable);
79
+ const result = await executable.handler(context, ...params);
80
+ return result;
81
+ }
82
+ function getMethodCaller(executable) {
83
+ if (executable.type === HandlerType.rawMiddleFn) {
84
+ executable.methodCaller = runRawMiddleFn;
85
+ } else if (executable.type === HandlerType.headersMiddleFn) {
86
+ executable.methodCaller = runHeadersMiddleFn;
87
+ } else {
88
+ executable.methodCaller = runRouteOrMiddleFn;
89
+ }
90
+ return executable.methodCaller;
91
+ }
92
+ function deserializeBodyParamsOrThrow(request, executable) {
93
+ const params = request.body[executable.id] || [];
94
+ if (request.bodyType === SerializerModes.binary) return params;
95
+ if (executable.paramsJitFns.restoreFromJson.isNoop) return params;
96
+ try {
97
+ request.body[executable.id] = executable.paramsJitFns.restoreFromJson.fn(params);
98
+ return request.body[executable.id];
99
+ } catch (e) {
100
+ throw new RpcError({
101
+ statusCode: StatusCodes.UNEXPECTED_ERROR,
102
+ type: "serialization-error",
103
+ publicMessage: `Invalid params '${executable.id}', can not deserialize. Parameters might be of the wrong type.`,
104
+ originalError: e,
105
+ errorData: {
106
+ deserializeError: e?.message || "Unknown error"
107
+ }
108
+ });
109
+ }
110
+ }
111
+ function validateParametersOrThrow(params, executable) {
112
+ if (executable.paramsJitFns.isType.isNoop) return;
113
+ if (!executable.paramsJitFns.isType.fn(params)) {
114
+ const validationError = new RpcError({
115
+ statusCode: StatusCodes.UNEXPECTED_ERROR,
116
+ type: "validation-error",
117
+ publicMessage: `Invalid params in '${executable.id}', validation failed.`,
118
+ errorData: {
119
+ typeErrors: executable.paramsJitFns.typeErrors.fn(params)
120
+ }
121
+ });
122
+ throw validationError;
123
+ }
124
+ }
125
+ function validateHeaderParamsOrThrow(headers, executable) {
126
+ if (!executable.headersParam.jitFns.isType.fn(headers)) {
127
+ const validationError = new RpcError({
128
+ statusCode: StatusCodes.UNEXPECTED_ERROR,
129
+ type: "validation-error",
130
+ publicMessage: `Invalid params in '${executable.id}', validation failed.`,
131
+ errorData: {
132
+ typeErrors: executable.headersParam.jitFns.typeErrors.fn(headers)
133
+ }
134
+ });
135
+ throw validationError;
136
+ }
137
+ }
138
+ export {
139
+ dispatchRoute
140
+ };
141
+ //# sourceMappingURL=dispatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatch.js","sources":["../../../src/dispatch.ts"],"sourcesContent":["/* ########\n * 2022 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport type {CallContext, MionResponse, MionRequest, MionHeaders, RawRequestBody} from './types/context.ts';\nimport {type RouterOptions} from './types/general.ts';\nimport {HeadersMethod, RemoteMethod, RawMethod} from './types/remoteMethods.ts';\nimport {getRouterOptions} from './router.ts';\nimport {Mutable, AnyObject, StatusCodes, HeadersSubset, SerializerModes, SerializerCode} from '@mionjs/core';\nimport {RpcError, HandlerType, ValidationError} from '@mionjs/core';\nimport {onExecutableError} from './lib/dispatchError.ts';\nimport {acquireCallContext, releaseCallContext} from './callContext.ts';\n\n/*\n * PERFORMANCE PROFILING NOTE:\n * different options has been tested to improve performance but were discarded due to worst or no noticeable improvements\n * - using promisify(setImmediate): worst or no improvement\n * - using queueMicrotask instead of setImmediate: definitely worst\n * - using callback instead promises: seems to be more slow but use less memory in some scenarios.\n */\n\n// ############# PUBLIC METHODS #############\n\nexport async function dispatchRoute<Req, Resp>(\n path: string,\n reqRawBody: RawRequestBody,\n reqHeaders: MionHeaders,\n respHeaders: MionHeaders,\n rawRequest: Req,\n rawResponse?: Resp,\n reqBodyType?: SerializerCode,\n urlQuery?: string\n): Promise<MionResponse> {\n const opts = getRouterOptions();\n const usePooling = opts.maxContextPoolSize > 0;\n const context = acquireCallContext(\n usePooling,\n path,\n opts,\n reqRawBody,\n rawRequest,\n reqHeaders,\n respHeaders,\n reqBodyType,\n urlQuery\n );\n\n try {\n await runExecutionChain(context, rawRequest, rawResponse, opts);\n return context.response;\n } catch (err: any | RpcError<string> | Error) {\n // this should never happen, exceptions should be handled inside runExecutionChain\n return Promise.reject(err);\n } finally {\n // Release context back to pool if pooling is enabled\n if (usePooling) {\n releaseCallContext(context, opts.maxContextPoolSize);\n }\n }\n}\n\n// ############# PRIVATE METHODS #############\n\n// runs the ExecutionChain of a route\nasync function runExecutionChain(\n context: CallContext,\n rawRequest: unknown,\n rawResponse: unknown,\n opts: RouterOptions\n): Promise<MionResponse> {\n const {response, request} = context;\n const executionList = context.executionChain.methods;\n (response as Mutable<MionResponse>).serializer = context.executionChain.serializer;\n for (let i = 0; i < executionList.length; i++) {\n const executable = executionList[i];\n if (response.hasErrors && !executable.options.runOnError) continue;\n\n try {\n const methodCaller = executable.methodCaller || getMethodCaller(executable);\n // runRawMiddleFn , runHeadersMiddleFn & runRouteOrMiddleFn must always accept the same parameters in the same order\n const result = await methodCaller(context, executable, request, response, opts, rawRequest, rawResponse);\n\n if (result === undefined || !executable.hasReturnData) continue;\n if (executable.headersReturn && result instanceof HeadersSubset) {\n const headersMap = result.headers;\n for (const name in headersMap) {\n const value = headersMap[name];\n if (value !== undefined && value !== null) {\n response.headers.set(name, value);\n }\n }\n continue;\n }\n (response.body as Mutable<AnyObject>)[executable.id] = result;\n } catch (err: any | RpcError<string> | Error) {\n // All thrown errors are unexpected\n onExecutableError(context, executable, err);\n }\n }\n return context.response;\n}\n\nasync function runRawMiddleFn(\n context: CallContext,\n executable: RawMethod,\n req,\n resp,\n opts: RouterOptions,\n rawRequest: unknown,\n rawResponse: unknown\n) {\n const result = await executable.handler(context, rawRequest, rawResponse, opts);\n return result;\n}\n\nasync function runHeadersMiddleFn(context: CallContext, executable: HeadersMethod, request: MionRequest) {\n const headerNames = executable.headersParam.headerNames;\n const params = deserializeBodyParamsOrThrow(request, executable as RemoteMethod);\n const headersMap: Record<string, string> = {};\n headerNames.forEach((name) => {\n const value = request.headers.get(name);\n if (value) headersMap[name] = value;\n });\n const headersSubset = new HeadersSubset(headersMap);\n validateHeaderParamsOrThrow(headersSubset, executable as HeadersMethod);\n if (executable.options.validateParams) validateParametersOrThrow(params, executable as HeadersMethod);\n\n const result = await executable.handler(context, headersSubset, ...params);\n return result;\n}\n\nasync function runRouteOrMiddleFn(context: CallContext, executable: HeadersMethod, request: MionRequest) {\n const params = deserializeBodyParamsOrThrow(request, executable as RemoteMethod);\n if (executable.options.validateParams) validateParametersOrThrow(params, executable as RemoteMethod);\n const result = await executable.handler(context, ...params);\n return result;\n}\n\nfunction getMethodCaller(executable: RemoteMethod) {\n if (executable.type === HandlerType.rawMiddleFn) {\n executable.methodCaller = runRawMiddleFn;\n } else if (executable.type === HandlerType.headersMiddleFn) {\n executable.methodCaller = runHeadersMiddleFn;\n } else {\n executable.methodCaller = runRouteOrMiddleFn;\n }\n return executable.methodCaller;\n}\n\nfunction deserializeBodyParamsOrThrow(request: MionRequest, executable: RemoteMethod): any[] {\n const params: any[] = (request.body[executable.id] as any[]) || [];\n // For binary requests, params are already deserialized in the serializer middleFn\n // (deserializeBinaryRequestBody in serializer.routes.ts)\n if (request.bodyType === SerializerModes.binary) return params;\n\n // For JSON requests, use restoreFromJson to deserialize\n if (executable.paramsJitFns.restoreFromJson.isNoop) return params;\n try {\n (request.body as Mutable<MionRequest['body']>)[executable.id] = executable.paramsJitFns.restoreFromJson.fn(params);\n return request.body[executable.id] as any[];\n } catch (e: any) {\n throw new RpcError({\n statusCode: StatusCodes.UNEXPECTED_ERROR,\n type: 'serialization-error',\n publicMessage: `Invalid params '${executable.id}', can not deserialize. Parameters might be of the wrong type.`,\n originalError: e,\n errorData: {\n deserializeError: e?.message || 'Unknown error',\n },\n });\n }\n}\n\nfunction validateParametersOrThrow(params: any[], executable: RemoteMethod): void {\n if (executable.paramsJitFns.isType.isNoop) return;\n if (!executable.paramsJitFns.isType.fn(params)) {\n const validationError: ValidationError = new RpcError({\n statusCode: StatusCodes.UNEXPECTED_ERROR,\n type: 'validation-error',\n publicMessage: `Invalid params in '${executable.id}', validation failed.`,\n errorData: {\n typeErrors: executable.paramsJitFns.typeErrors.fn(params),\n },\n });\n throw validationError;\n }\n}\n\nfunction validateHeaderParamsOrThrow(headers: HeadersSubset<string, string>, executable: HeadersMethod): void {\n if (!executable.headersParam.jitFns.isType.fn(headers)) {\n const validationError: ValidationError = new RpcError({\n statusCode: StatusCodes.UNEXPECTED_ERROR,\n type: 'validation-error',\n publicMessage: `Invalid params in '${executable.id}', validation failed.`,\n errorData: {\n typeErrors: executable.headersParam.jitFns.typeErrors.fn(headers),\n },\n });\n throw validationError;\n }\n}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itFnsCache, pureFnsCache, routerCache } from "virtual:mion-aot/caches";
2
+ import { addAOTCaches, addRoutesToCache } from "@mionjs/core";
3
+ import { loadCompiledMethods } from "./methodsCache.js";
4
+ function loadAOTCaches() {
5
+ addAOTCaches(jitFnsCache, pureFnsCache);
6
+ addRoutesToCache(routerCache);
7
+ loadCompiledMethods(routerCache);
8
+ }
9
+ loadAOTCaches.__type = ["loadAOTCaches", "P$/!"];
10
+ export {
11
+ loadAOTCaches
12
+ };
13
+ //# sourceMappingURL=aotCacheLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aotCacheLoader.js","sources":["../../../../src/lib/aotCacheLoader.ts"],"sourcesContent":["/* ########\n * 2026 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {jitFnsCache, pureFnsCache, routerCache} from 'virtual:mion-aot/caches';\nimport {addAOTCaches, addRoutesToCache} from '@mionjs/core';\nimport {loadCompiledMethods} from './methodsCache.ts';\n\n/** Loads pre-compiled AOT caches from virtual modules and registers them in the global caches. */\nexport function loadAOTCaches(): void {\n addAOTCaches(jitFnsCache, pureFnsCache);\n addRoutesToCache(routerCache);\n loadCompiledMethods(routerCache);\n}\n"],"names":[],"mappings":";;;SAYgB,gBAAa;AACzB,eAAa,aAAa,YAAY;AACtC,mBAAiB,WAAW;AAC5B,sBAAoB,WAAW;AACnC;;"}
@@ -0,0 +1,17 @@
1
+ import { JitFunctionsCache, PureFunctionsCache, MethodsCache } from '@mionjs/core';
2
+ export interface AOTCacheMessage {
3
+ type: 'mion-aot-caches';
4
+ jitFnsCode: string;
5
+ pureFnsCode: string;
6
+ routerCacheCode: string;
7
+ }
8
+ export interface SerializedCaches {
9
+ jitFnsCode: string;
10
+ pureFnsCode: string;
11
+ routerCacheCode: string;
12
+ }
13
+ export declare function getSerializedCaches(): Promise<SerializedCaches>;
14
+ export declare function emitAOTCaches(): Promise<void>;
15
+ export declare function serializeCachesToCode(jitFnsCache: JitFunctionsCache, pureFnsCache: PureFunctionsCache, routerCache: MethodsCache): Promise<SerializedCaches>;
16
+ export declare type __ΩAOTCacheMessage = any[];
17
+ export declare type __ΩSerializedCaches = any[];