@mionjs/router 0.8.4-alpha.0 → 0.8.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"defaultRoutes.cjs","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 startScript is configured.\n *\n * When run with MION_COMPILE=buildOnly, 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":["middleFn","initMionRouter"],"mappings":";;;;;;;AA4BA,MAAM,SAAS;AAAA;AAAA,EAEX,0BAA0BA,OAAAA,SAAQ,aAAC,MAAY,QAAS,CAAA,IAAA,MAAA,CAAA,CAAA;;AAKrD,MAAM,aAAaC,OAAAA,eAAe,QAAQ,EAAC,kBAAkB,OAAM;;;;"}
1
+ {"version":3,"file":"defaultRoutes.cjs","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 startScript is configured.\n *\n * When run with MION_COMPILE=buildOnly, 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@methodsMetadata: Methods metadata middleware (returns metadata alongside any route response)\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":["middleFn","initMionRouter"],"mappings":";;;;;;;AA4BA,MAAM,SAAS;AAAA;AAAA,EAEX,0BAA0BA,OAAAA,SAAQ,aAAC,MAAY,QAAS,CAAA,IAAA,MAAA,CAAA,CAAA;;AAKrD,MAAM,aAAaC,OAAAA,eAAe,QAAQ,EAAC,kBAAkB,OAAM;;;;"}
@@ -37,8 +37,9 @@ async function emitAOTCaches() {
37
37
  }
38
38
  emitAOTCaches.__type = ["emitAOTCaches", "P$`/!"];
39
39
  async function serializeCachesToCode(jitFnsCache, pureFnsCache, routerCache) {
40
- const jitToJSCode = (runTypes.createToJavascriptFn.Ω = [[() => core.__ΩSrcCodeJITCompiledFnsCache, "n!"]], runTypes.createToJavascriptFn());
41
- const pureToJSCode = (runTypes.createToJavascriptFn.Ω = [[() => core.__ΩSrcCodePureFunctionsCache, "n!"]], runTypes.createToJavascriptFn());
40
+ const isClient = core.getENV("MION_AOT_IS_CLIENT") === "true";
41
+ const jitToJSCode = isClient ? (runTypes.createToJavascriptFn.Ω = [[() => core.__ΩClientSrcCodeJITCompiledFnsCache, "n!"]], runTypes.createToJavascriptFn()) : (runTypes.createToJavascriptFn.Ω = [[() => core.__ΩSrcCodeJITCompiledFnsCache, "n!"]], runTypes.createToJavascriptFn());
42
+ const pureToJSCode = isClient ? (runTypes.createToJavascriptFn.Ω = [[() => core.__ΩClientSrcCodePureFunctionsCache, "n!"]], runTypes.createToJavascriptFn()) : (runTypes.createToJavascriptFn.Ω = [[() => core.__ΩSrcCodePureFunctionsCache, "n!"]], runTypes.createToJavascriptFn());
42
43
  const routerToJSCode = (runTypes.createToJavascriptFn.Ω = [[() => core.__ΩMethodsCache, "n!"]], runTypes.createToJavascriptFn());
43
44
  const finalJitFns = filterExcludedJitFns(jitFnsCache, EXCLUDED_JIT_FN_IDS);
44
45
  const finalPureFns = filterExcludedPureFns(pureFnsCache, EXCLUDED_PURE_FN_NAMES);
@@ -1 +1 @@
1
- {"version":3,"file":"aotEmitter.cjs","sources":["../../../../src/lib/aotEmitter.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\nimport {\n getJitFnCaches,\n getENV,\n isMionAOTEmitMode,\n JitFunctionsCache,\n PureFunctionsCache,\n MethodsCache,\n SrcCodeJITCompiledFnsCache,\n SrcCodePureFunctionsCache,\n JIT_FUNCTION_IDS,\n} from '@mionjs/core';\nimport {getPersistedMethods} from './methodsCache.ts';\nimport {createToJavascriptFn} from '@mionjs/run-types';\n\n/** IPC message type for AOT cache emission */\nexport interface AOTCacheMessage {\n type: 'mion-aot-caches';\n jitFnsCode: string;\n pureFnsCode: string;\n routerCacheCode: string;\n}\n\n/** IPC message sent by setPlatformConfig() to signal server readiness */\nexport interface PlatformReadyMessage {\n type: 'mion-platform-ready';\n routerConfig: Record<string, unknown>;\n platformConfig: Record<string, unknown>;\n}\n\n/** Serialized cache data before converting to JS code */\nexport interface SerializedCaches {\n jitFnsCode: string;\n pureFnsCode: string;\n routerCacheCode: string;\n}\n\n/** JIT function IDs to exclude from AOT caches (toJSCode is only needed at compile time) */\nconst EXCLUDED_JIT_FN_IDS = [JIT_FUNCTION_IDS.toJSCode];\n\n/** Pure function names to exclude from AOT caches */\nconst EXCLUDED_PURE_FN_NAMES = ['sanitizeCompiledFn'];\n\n/** Returns serialized caches for in-process AOT generation (no IPC needed). Call after initMionRouter(). */\nexport async function getSerializedCaches(): Promise<SerializedCaches> {\n const {jitFnsCache, pureFnsCache} = getJitFnCaches();\n const routerCache = getPersistedMethods();\n return serializeCachesToCode(jitFnsCache, pureFnsCache, routerCache);\n}\n\n/**\n * Emits AOT caches to the parent process via IPC when running in MION_COMPILE mode.\n * This function is called automatically at the end of initMionRouter() and can also\n * be called manually for multi-step route registration patterns.\n */\nexport async function emitAOTCaches(): Promise<void> {\n // Only emit in AOT generation mode (compile, SSR, or serve)\n if (!isMionAOTEmitMode()) return;\n // middleware mode: caches remain in global state, read directly via getSerializedCaches()\n if (getENV('MION_COMPILE') === 'middleware') return;\n\n // IPC mode: send to parent process\n if (typeof process.send !== 'function') return;\n\n // Get the caches\n const {jitFnsCache, pureFnsCache} = getJitFnCaches();\n const routerCache = getPersistedMethods();\n\n // Serialize caches to JS code (filtering happens inside, after createToJavascriptFn)\n const serialized = await serializeCachesToCode(jitFnsCache, pureFnsCache, routerCache);\n\n // Send to parent process\n const message: AOTCacheMessage = {\n type: 'mion-aot-caches',\n ...serialized,\n };\n\n process.send(message);\n}\n\n/**\n * Serializes the caches to JavaScript code strings using run-types toJSCode.\n * Filtering is done AFTER createToJavascriptFn because it adds compile-time-only JIT functions\n * to the global caches that should be excluded from the serialized output.\n */\nexport async function serializeCachesToCode(\n jitFnsCache: JitFunctionsCache,\n pureFnsCache: PureFunctionsCache,\n routerCache: MethodsCache\n): Promise<SerializedCaches> {\n const jitToJSCode = createToJavascriptFn<SrcCodeJITCompiledFnsCache>();\n const pureToJSCode = createToJavascriptFn<SrcCodePureFunctionsCache>();\n const routerToJSCode = createToJavascriptFn<MethodsCache>();\n // Filter AFTER createToJavascriptFn to exclude compile-time-only items (including those just added)\n const finalJitFns = filterExcludedJitFns(jitFnsCache, EXCLUDED_JIT_FN_IDS);\n const finalPureFns = filterExcludedPureFns(pureFnsCache, EXCLUDED_PURE_FN_NAMES);\n return {\n jitFnsCode: jitToJSCode(finalJitFns as unknown as SrcCodeJITCompiledFnsCache),\n pureFnsCode: pureToJSCode(finalPureFns as unknown as SrcCodePureFunctionsCache),\n routerCacheCode: routerToJSCode(routerCache),\n };\n}\n\n/**\n * Filters out excluded JIT functions by their function ID.\n * toJSCode is excluded because it's only needed at compile time.\n */\nfunction filterExcludedJitFns(jitFnsCache: JitFunctionsCache, excludedFnIds: string[]): JitFunctionsCache {\n if (!excludedFnIds.length) return jitFnsCache;\n return Object.fromEntries(\n Object.entries(jitFnsCache).filter(([, value]) => !excludedFnIds.includes(value.fnID as string))\n ) as JitFunctionsCache;\n}\n\n/**\n * Filters out excluded pure functions by their function name.\n * sanitizeCompiledFn is excluded because it's only needed at compile time.\n */\nfunction filterExcludedPureFns(pureFnsCache: PureFunctionsCache, excludedFnNames: string[]): PureFunctionsCache {\n if (!excludedFnNames.length) return pureFnsCache;\n return Object.fromEntries(\n Object.entries(pureFnsCache).map(([namespace, nsCache]) => [\n namespace,\n Object.fromEntries(Object.entries(nsCache).filter(([, value]) => !excludedFnNames.includes(value.fnName))),\n ])\n ) as PureFunctionsCache;\n}\n"],"names":["JIT_FUNCTION_IDS","getJitFnCaches","getPersistedMethods","isMionAOTEmitMode","getENV","createToJavascriptFn"],"mappings":";;;;;;;;;;;;;AA4CA,MAAM,sBAAsB,CAACA,KAAAA,iBAAiB,QAAQ;AAGtD,MAAM,yBAAyB,CAAC,oBAAoB;AAGpD,eAAsB,sBAAmB;AACrC,QAAM,EAAC,aAAa,aAAA,IAA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O,MAAM;AAAA,IACvD;AAAA,IACA,OAAO,YAAY,OAAO,QAAQ,OAAO,EAAE,OAAM,aAAC,CAAC,GAAG,KAAK,MAAM,CAAC,gBAAgB,SAAS,MAAM,MAAM,8BAAE;AAAA,EAAA,GAC5G,CAAA,UAAA,IAAA,SAAA,CAAA,CAAA,CAAC;AAEV;;;;;;;;"}
1
+ {"version":3,"file":"aotEmitter.cjs","sources":["../../../../src/lib/aotEmitter.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\nimport {\n getJitFnCaches,\n getENV,\n isMionAOTEmitMode,\n JitFunctionsCache,\n PureFunctionsCache,\n MethodsCache,\n SrcCodeJITCompiledFnsCache,\n SrcCodePureFunctionsCache,\n ClientSrcCodeJITCompiledFnsCache,\n ClientSrcCodePureFunctionsCache,\n JIT_FUNCTION_IDS,\n} from '@mionjs/core';\nimport {getPersistedMethods} from './methodsCache.ts';\nimport {createToJavascriptFn} from '@mionjs/run-types';\n\n/** IPC message type for AOT cache emission */\nexport interface AOTCacheMessage {\n type: 'mion-aot-caches';\n jitFnsCode: string;\n pureFnsCode: string;\n routerCacheCode: string;\n}\n\n/** IPC message sent by setPlatformConfig() to signal server readiness */\nexport interface PlatformReadyMessage {\n type: 'mion-platform-ready';\n routerConfig: Record<string, unknown>;\n platformConfig: Record<string, unknown>;\n}\n\n/** Serialized cache data before converting to JS code */\nexport interface SerializedCaches {\n jitFnsCode: string;\n pureFnsCode: string;\n routerCacheCode: string;\n}\n\n/** JIT function IDs to exclude from AOT caches (toJSCode is only needed at compile time) */\nconst EXCLUDED_JIT_FN_IDS = [JIT_FUNCTION_IDS.toJSCode];\n\n/** Pure function names to exclude from AOT caches */\nconst EXCLUDED_PURE_FN_NAMES = ['sanitizeCompiledFn'];\n\n/** Returns serialized caches for in-process AOT generation (no IPC needed). Call after initMionRouter(). */\nexport async function getSerializedCaches(): Promise<SerializedCaches> {\n const {jitFnsCache, pureFnsCache} = getJitFnCaches();\n const routerCache = getPersistedMethods();\n return serializeCachesToCode(jitFnsCache, pureFnsCache, routerCache);\n}\n\n/**\n * Emits AOT caches to the parent process via IPC when running in MION_COMPILE mode.\n * This function is called automatically at the end of initMionRouter() and can also\n * be called manually for multi-step route registration patterns.\n */\nexport async function emitAOTCaches(): Promise<void> {\n // Only emit in AOT generation mode (compile, SSR, or serve)\n if (!isMionAOTEmitMode()) return;\n // middleware mode: caches remain in global state, read directly via getSerializedCaches()\n if (getENV('MION_COMPILE') === 'middleware') return;\n\n // IPC mode: send to parent process\n if (typeof process.send !== 'function') return;\n\n // Get the caches\n const {jitFnsCache, pureFnsCache} = getJitFnCaches();\n const routerCache = getPersistedMethods();\n\n // Serialize caches to JS code (filtering happens inside, after createToJavascriptFn)\n const serialized = await serializeCachesToCode(jitFnsCache, pureFnsCache, routerCache);\n\n // Send to parent process\n const message: AOTCacheMessage = {\n type: 'mion-aot-caches',\n ...serialized,\n };\n\n process.send(message);\n}\n\n/**\n * Serializes the caches to JavaScript code strings using run-types toJSCode.\n * Filtering is done AFTER createToJavascriptFn because it adds compile-time-only JIT functions\n * to the global caches that should be excluded from the serialized output.\n */\nexport async function serializeCachesToCode(\n jitFnsCache: JitFunctionsCache,\n pureFnsCache: PureFunctionsCache,\n routerCache: MethodsCache\n): Promise<SerializedCaches> {\n const isClient = getENV('MION_AOT_IS_CLIENT') === 'true';\n const jitToJSCode = isClient\n ? createToJavascriptFn<ClientSrcCodeJITCompiledFnsCache>()\n : createToJavascriptFn<SrcCodeJITCompiledFnsCache>();\n const pureToJSCode = isClient\n ? createToJavascriptFn<ClientSrcCodePureFunctionsCache>()\n : createToJavascriptFn<SrcCodePureFunctionsCache>();\n const routerToJSCode = createToJavascriptFn<MethodsCache>();\n // Filter AFTER createToJavascriptFn to exclude compile-time-only items (including those just added)\n const finalJitFns = filterExcludedJitFns(jitFnsCache, EXCLUDED_JIT_FN_IDS);\n const finalPureFns = filterExcludedPureFns(pureFnsCache, EXCLUDED_PURE_FN_NAMES);\n return {\n jitFnsCode: jitToJSCode(finalJitFns as unknown as SrcCodeJITCompiledFnsCache),\n pureFnsCode: pureToJSCode(finalPureFns as unknown as SrcCodePureFunctionsCache),\n routerCacheCode: routerToJSCode(routerCache),\n };\n}\n\n/**\n * Filters out excluded JIT functions by their function ID.\n * toJSCode is excluded because it's only needed at compile time.\n */\nfunction filterExcludedJitFns(jitFnsCache: JitFunctionsCache, excludedFnIds: string[]): JitFunctionsCache {\n if (!excludedFnIds.length) return jitFnsCache;\n return Object.fromEntries(\n Object.entries(jitFnsCache).filter(([, value]) => !excludedFnIds.includes(value.fnID as string))\n ) as JitFunctionsCache;\n}\n\n/**\n * Filters out excluded pure functions by their function name.\n * sanitizeCompiledFn is excluded because it's only needed at compile time.\n */\nfunction filterExcludedPureFns(pureFnsCache: PureFunctionsCache, excludedFnNames: string[]): PureFunctionsCache {\n if (!excludedFnNames.length) return pureFnsCache;\n return Object.fromEntries(\n Object.entries(pureFnsCache).map(([namespace, nsCache]) => [\n namespace,\n Object.fromEntries(Object.entries(nsCache).filter(([, value]) => !excludedFnNames.includes(value.fnName))),\n ])\n ) as PureFunctionsCache;\n}\n"],"names":["JIT_FUNCTION_IDS","getJitFnCaches","getPersistedMethods","isMionAOTEmitMode","getENV","createToJavascriptFn","__ΩClientSrcCodeJITCompiledFnsCache","__ΩSrcCodeJITCompiledFnsCache","__ΩClientSrcCodePureFunctionsCache","__ΩSrcCodePureFunctionsCache"],"mappings":";;;;;;;;;;;;;AA8CA,MAAM,sBAAsB,CAACA,KAAAA,iBAAiB,QAAQ;AAGtD,MAAM,yBAAyB,CAAC,oBAAoB;AAGpD,eAAsB,sBAAmB;AACrC,QAAM,EAAC,aAAa,aAAA,IAAgBC,oBAAA;AACpC,QAAM,cAAcC,qBAAAA,oBAAA;AACpB,SAAO,sBAAsB,aAAa,cAAc,WAAW;AACvE;;AAOA,eAAsB,gBAAa;AAE/B,MAAI,CAAC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,IAAc,GAAC,CAAA,UAAA,IAAA,SAAA,CAAA,CAAA,CAAC;AAExG;;AAMA,SAAS,sBAAsB,cAAkC,iBAAyB;AACtF,MAAI,CAAC,gBAAgB;AAAQ,WAAO;AACpC,SAAO,OAAO,YACV,OAAO,QAAQ,YAAY,EAAE,IAAG,aAAC,CAAC,CAAC,WAAW,OAAO,MAAM;AAAA,IACvD;AAAA,IACA,OAAO,YAAY,OAAO,QAAQ,OAAO,EAAE,OAAM,aAAC,CAAC,GAAG,KAAK,MAAM,CAAC,gBAAgB,SAAS,MAAM,MAAM,8BAAE;AAAA,EAAA,GAC5G,CAAA,UAAA,IAAA,SAAA,CAAA,CAAA,CAAC;AAEV;;;;;;;;"}
@@ -27,6 +27,7 @@ const src_types_general = require("../types/general.cjs");
27
27
  const src_constants = require("../constants.cjs");
28
28
  const core = require("@mionjs/core");
29
29
  const src_lib_methodsCache = require("./methodsCache.cjs");
30
+ const src_types_remoteMethods = require("../types/remoteMethods.cjs");
30
31
  const __ΩOmit = ["T", "K", () => __ΩPick, () => __ΩExclude, "Omit", 'b!b"e!!e!!ge!"o$#o##w%y'];
31
32
  const __ΩPick = ["T", "K", "Pick", 'l+e#!e"!fRb!b"Pde""N#!w#y'];
32
33
  const __ΩExclude = ["T", "U", "Exclude", 'l6!Re$!RPe#!e$"qk#%QRb!b"Pde"!p)w#y'];
@@ -126,16 +127,16 @@ function extractReflectionFromCached(cached) {
126
127
  return reflectionItems;
127
128
  }
128
129
  extractReflectionFromCached.__type = [() => __ΩCachedMethodMetadata, "cached", () => __ΩMethodReflect, "extractReflectionFromCached", 'Pn!2"n#/$'];
129
- async function getHandlerReflection(handler, routeId, routerOptions, isHeadersMiddleFn = false, methodStrictTypes) {
130
+ async function getHandlerReflection(handler, routeId, routerOptions, handlerOptions = {}, isHeadersMiddleFn = false, methodStrictTypes) {
130
131
  const cached = src_lib_methodsCache.getPersistedMethodMetadata(routeId);
131
132
  if (cached)
132
133
  return extractReflectionFromCached(cached);
133
134
  if (routerOptions.aot)
134
135
  throw new AOTCacheError(routeId, isHeadersMiddleFn ? "middleFn" : "route");
135
136
  const rt = await loadRunTypesModule();
136
- return generateHandlerReflection(handler, routeId, routerOptions, isHeadersMiddleFn, rt, methodStrictTypes);
137
+ return generateHandlerReflection(handler, routeId, routerOptions, handlerOptions, isHeadersMiddleFn, rt, methodStrictTypes);
137
138
  }
138
- getHandlerReflection.__type = [() => src_types_handlers.__ΩHandler, "handler", "routeId", () => src_types_general.__ΩRouterOptions, "routerOptions", "isHeadersMiddleFn", () => false, "methodStrictTypes", () => __ΩMethodReflect, "getHandlerReflection", "Pn!2\"&2#n$2%)2&>')2(8n)`/*"];
139
+ getHandlerReflection.__type = [() => src_types_handlers.__ΩHandler, "handler", "routeId", () => src_types_general.__ΩRouterOptions, "routerOptions", () => src_types_remoteMethods.__ΩRouteOptions, () => src_types_remoteMethods.__ΩMiddleFnOptions, () => src_types_remoteMethods.__ΩHeadersMiddleFnOptions, "handlerOptions", () => ({}), "isHeadersMiddleFn", () => false, "methodStrictTypes", () => __ΩMethodReflect, "getHandlerReflection", "Pn!2\"&2#n$2%Pn&n'n(J2)>*)2+>,)2-8n.`//"];
139
140
  async function getRawMethodReflection(handler, routeId, routerOptions) {
140
141
  const cached = src_lib_methodsCache.getPersistedMethodMetadata(routeId);
141
142
  if (cached)
@@ -146,9 +147,10 @@ async function getRawMethodReflection(handler, routeId, routerOptions) {
146
147
  return generateRawMethodReflection(handler, routeId, rt);
147
148
  }
148
149
  getRawMethodReflection.__type = [() => src_types_handlers.__ΩHandler, "handler", "routeId", () => src_types_general.__ΩRouterOptions, "routerOptions", () => __ΩMethodReflect, "getRawMethodReflection", "Pn!2\"&2#n$2%n&`/'"];
149
- function generateHandlerReflection(handler, routeId, routerOptions, isHeadersMiddleFn, rt, methodStrictTypes) {
150
+ function generateHandlerReflection(handler, routeId, routerOptions, handlerOptions, isHeadersMiddleFn, rt, methodStrictTypes) {
150
151
  const reflectionItems = {};
151
152
  let handlerRunType;
153
+ const needsBinary = (handlerOptions?.serializer ?? routerOptions.serializer) === "binary";
152
154
  const effectiveStrictTypes = methodStrictTypes ?? routerOptions.strictTypes;
153
155
  const runTypeOptions = {
154
156
  ...routerOptions?.runTypeOptions || src_constants.DEFAULT_ROUTE_OPTIONS.runTypeOptions,
@@ -167,7 +169,7 @@ function generateHandlerReflection(handler, routeId, routerOptions, isHeadersMid
167
169
  reflectionItems.paramsJitHash = core.EMPTY_HASH;
168
170
  reflectionItems.paramsJitFns = core.getNoopJitFns();
169
171
  } else {
170
- reflectionItems.paramsJitFns = getFunctionJitFns(handler, paramsOpts, rt, false);
172
+ reflectionItems.paramsJitFns = getFunctionJitFns(handler, paramsOpts, rt, false, needsBinary);
171
173
  reflectionItems.paramsJitHash = handlerRunType.getParameters().getJitHash(paramsOpts);
172
174
  }
173
175
  } catch (error) {
@@ -181,7 +183,7 @@ function generateHandlerReflection(handler, routeId, routerOptions, isHeadersMid
181
183
  ...runTypeOptions,
182
184
  paramsSlice: void 0
183
185
  };
184
- const jitFns = getTypeJitFunctions(headersRunType, opts, rt);
186
+ const jitFns = getTypeJitFunctions(headersRunType, opts, rt, false);
185
187
  const jitHash = headersRunType.getJitHash(opts);
186
188
  reflectionItems.headersParam = { headerNames, jitFns, jitHash };
187
189
  } catch (error) {
@@ -192,7 +194,7 @@ function generateHandlerReflection(handler, routeId, routerOptions, isHeadersMid
192
194
  if (returnHeadersRunType) {
193
195
  const opts = {};
194
196
  const headerNames = getHeaderNames(returnHeadersRunType, routeId, rt);
195
- const jitFns = getFunctionJitFns(handler, opts, rt, true);
197
+ const jitFns = getFunctionJitFns(handler, opts, rt, true, false);
196
198
  const jitHash = returnHeadersRunType.getJitHash(opts);
197
199
  reflectionItems.headersReturn = { headerNames, jitFns, jitHash };
198
200
  }
@@ -203,8 +205,8 @@ function generateHandlerReflection(handler, routeId, routerOptions, isHeadersMid
203
205
  reflectionItems.returnJitFns = core.getNoopJitFns();
204
206
  reflectionItems.returnJitHash = core.EMPTY_HASH;
205
207
  } else {
206
- reflectionItems.returnJitFns = getFunctionJitFns(handler, returnOpts, rt, true);
207
- reflectionItems.returnJitHash = handlerRunType.getReturnType().getJitHash(returnOpts);
208
+ reflectionItems.returnJitFns = getFunctionJitFns(handler, returnOpts, rt, true, needsBinary);
209
+ reflectionItems.returnJitHash = handlerRunType.getResolvedReturnType().getJitHash(returnOpts);
208
210
  }
209
211
  } catch (error) {
210
212
  throw new Error(`Can not get Jit Functions for Return of route/middleFn "${routeId}." Error: ${error?.message}`);
@@ -212,7 +214,7 @@ function generateHandlerReflection(handler, routeId, routerOptions, isHeadersMid
212
214
  reflectionItems.isAsync = handlerRunType.isAsync();
213
215
  return reflectionItems;
214
216
  }
215
- generateHandlerReflection.__type = [() => src_types_handlers.__ΩHandler, "handler", "routeId", () => src_types_general.__ΩRouterOptions, "routerOptions", "isHeadersMiddleFn", () => __ΩRunTypesFunctions, "rt", "methodStrictTypes", () => __ΩMethodReflect, "generateHandlerReflection", `Pn!2"&2#n$2%)2&n'2()2)8n*/+`];
217
+ generateHandlerReflection.__type = [() => src_types_handlers.__ΩHandler, "handler", "routeId", () => src_types_general.__ΩRouterOptions, "routerOptions", () => src_types_remoteMethods.__ΩRouteOptions, () => src_types_remoteMethods.__ΩMiddleFnOptions, () => src_types_remoteMethods.__ΩHeadersMiddleFnOptions, "handlerOptions", "isHeadersMiddleFn", () => __ΩRunTypesFunctions, "rt", "methodStrictTypes", () => __ΩMethodReflect, "generateHandlerReflection", `Pn!2"&2#n$2%Pn&n'n(J2))2*n+2,)2-8n.//`];
216
218
  function generateRawMethodReflection(handler, routeId, rt) {
217
219
  let handlerRunType;
218
220
  try {
@@ -305,21 +307,23 @@ function getFakeCompiler(routerOptions) {
305
307
  return { opts: routerOptions };
306
308
  }
307
309
  getFakeCompiler.__type = [() => src_types_general.__ΩRouterOptions, "routerOptions", "JitFnCompiler", "getFakeCompiler", 'Pn!2""w#/$'];
308
- function getTypeJitFunctions(runType, opts, rtModule) {
310
+ function getTypeJitFunctions(runType, opts, rtModule, needsBinary = false) {
309
311
  const jitFns = {
310
312
  isType: runType.createJitCompiledFunction(rtModule.JitFunctions.isType.id, void 0, opts),
311
313
  typeErrors: runType.createJitCompiledFunction(rtModule.JitFunctions.typeErrors.id, void 0, opts),
312
314
  prepareForJson: runType.createJitCompiledFunction(rtModule.JitFunctions.prepareForJson.id, void 0, opts),
313
315
  restoreFromJson: runType.createJitCompiledFunction(rtModule.JitFunctions.restoreFromJson.id, void 0, opts),
314
316
  stringifyJson: runType.createJitCompiledFunction(rtModule.JitFunctions.stringifyJson.id, void 0, opts),
315
- toBinary: runType.createJitCompiledFunction(rtModule.JitFunctions.toBinary.id, void 0, opts),
316
- fromBinary: runType.createJitCompiledFunction(rtModule.JitFunctions.fromBinary.id, void 0, opts)
317
+ ...needsBinary ? {
318
+ toBinary: runType.createJitCompiledFunction(rtModule.JitFunctions.toBinary.id, void 0, opts),
319
+ fromBinary: runType.createJitCompiledFunction(rtModule.JitFunctions.fromBinary.id, void 0, opts)
320
+ } : {}
317
321
  };
318
322
  return jitFns;
319
323
  }
320
- getTypeJitFunctions.__type = ["BaseRunType", "runType", "RunTypeOptions", "opts", () => __ΩRunTypesFunctions, "rtModule", "JitCompiledFunctions", "getTypeJitFunctions", `P"w!2"P"w#-J2$n%2&"w'/(`];
324
+ getTypeJitFunctions.__type = ["BaseRunType", "runType", "RunTypeOptions", "opts", () => __ΩRunTypesFunctions, "rtModule", "needsBinary", () => false, "JitCompiledFunctions", "getTypeJitFunctions", `P"w!2"P"w#-J2$n%2&)2'>("w)/*`];
321
325
  const functionRunTypeCache = (WeakMap.Ω = [["AnyFn", '"w!'], ["FunctionRunType", '"w!']], /* @__PURE__ */ new WeakMap());
322
- function getFunctionJitFns(fn, opts, rtModule, isReturn) {
326
+ function getFunctionJitFns(fn, opts, rtModule, isReturn, needsBinary = false) {
323
327
  let runType = functionRunTypeCache.get(fn);
324
328
  if (!runType) {
325
329
  runType = rtModule.reflectFunction(fn);
@@ -332,13 +336,37 @@ function getFunctionJitFns(fn, opts, rtModule, isReturn) {
332
336
  prepareForJson: createFn(rtModule.JitFunctions.prepareForJson, opts),
333
337
  restoreFromJson: createFn(rtModule.JitFunctions.restoreFromJson, opts),
334
338
  stringifyJson: createFn(rtModule.JitFunctions.stringifyJson, opts),
335
- toBinary: createFn(rtModule.JitFunctions.toBinary, opts),
336
- fromBinary: createFn(rtModule.JitFunctions.fromBinary, opts)
339
+ ...needsBinary ? {
340
+ toBinary: createFn(rtModule.JitFunctions.toBinary, opts),
341
+ fromBinary: createFn(rtModule.JitFunctions.fromBinary, opts)
342
+ } : {}
337
343
  };
338
344
  return jitFunctions;
339
345
  }
340
- getFunctionJitFns.__type = ["fn", "RunTypeOptions", "opts", () => __ΩRunTypesFunctions, "rtModule", "isReturn", "JitCompiledFunctions", "getFunctionJitFns", `P"2!P"w"-J2#n$2%)2&"w'/(`];
346
+ getFunctionJitFns.__type = ["fn", "RunTypeOptions", "opts", () => __ΩRunTypesFunctions, "rtModule", "isReturn", "needsBinary", () => false, "JitCompiledFunctions", "getFunctionJitFns", `P"2!P"w"-J2#n$2%)2&)2'>("w)/*`];
347
+ async function ensureBinaryJitFns(method) {
348
+ if (method.paramsJitFns.toBinary && method.returnJitFns.toBinary)
349
+ return;
350
+ const rt = await loadRunTypesModule();
351
+ const isHeader = method.type === core.HandlerType.headersMiddleFn;
352
+ const paramsSlice = isHeader ? { start: src_constants.HEADER_HOOK_DEFAULT_PARAMS.length } : { start: src_constants.ROUTE_DEFAULT_PARAMS.length };
353
+ const opts = { paramsSlice };
354
+ if (!method.paramsJitFns.toBinary && method.paramsJitHash !== core.EMPTY_HASH) {
355
+ const runType = rt.reflectFunction(method.handler);
356
+ const createFn = runType.createJitCompiledParamsFunction.bind(runType);
357
+ method.paramsJitFns.toBinary = createFn(rt.JitFunctions.toBinary, opts);
358
+ method.paramsJitFns.fromBinary = createFn(rt.JitFunctions.fromBinary, opts);
359
+ }
360
+ if (!method.returnJitFns.toBinary && method.returnJitHash !== core.EMPTY_HASH && method.hasReturnData) {
361
+ const runType = rt.reflectFunction(method.handler);
362
+ const createFn = runType.createJitCompiledReturnFunction.bind(runType);
363
+ method.returnJitFns.toBinary = createFn(rt.JitFunctions.toBinary);
364
+ method.returnJitFns.fromBinary = createFn(rt.JitFunctions.fromBinary);
365
+ }
366
+ }
367
+ ensureBinaryJitFns.__type = [() => src_types_remoteMethods.__ΩMiddleFnMethod, () => src_types_remoteMethods.__ΩHeadersMethod, "method", "ensureBinaryJitFns", 'PPn!n"J2#$`/$'];
341
368
  exports.AOTCacheError = AOTCacheError;
369
+ exports.ensureBinaryJitFns = ensureBinaryJitFns;
342
370
  exports.getHandlerReflection = getHandlerReflection;
343
371
  exports.getRawMethodReflection = getRawMethodReflection;
344
372
  exports.resetReflectionCaches = resetReflectionCaches;
@@ -1 +1 @@
1
- {"version":3,"file":"reflection.cjs","sources":["../../../../src/lib/reflection.ts"],"sourcesContent":["/* ########\n * 2024 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport type {MethodWithJitFns, AnyFn, JitCompiledFunctions, MethodMetadata} from '@mionjs/core';\n// Type-only imports from run-types - these don't load the module at runtime\nimport type {FunctionRunType, BaseRunType, MemberRunType, RunTypeOptions, JitFnCompiler} from '@mionjs/run-types';\nimport {Handler} from '../types/handlers.ts';\nimport {RouterOptions} from '../types/general.ts';\nimport {DEFAULT_ROUTE_OPTIONS, HEADER_HOOK_DEFAULT_PARAMS, ROUTE_DEFAULT_PARAMS} from '../constants.ts';\nimport {EMPTY_HASH, HeadersSubset, getJitFunctionsFromHash, getNoopJitFns} from '@mionjs/core';\nimport {getPersistedMethodMetadata} from './methodsCache.ts';\n\n// ############ This file is the only one importing '@mionjs/run-types' within the router ########\n// In AOT mode, run-types is NOT loaded - all reflection data comes from the AOT cache\n\ntype MethodReflect = Omit<MethodWithJitFns, 'id' | 'type' | 'nestLevel' | 'pointer' | 'options'>;\n\n// ############ AOT Cache Error ############\n\n/**\n * Error thrown when AOT mode is enabled but required data is missing from the AOT cache.\n * This indicates that the AOT caches need to be regenerated using 'mion-build-aot' command.\n */\nexport class AOTCacheError extends Error {\n constructor(routeId: string, type: 'route' | 'middleFn' | 'rawMiddleFn' = 'route') {\n const typeLabel = type === 'rawMiddleFn' ? 'Raw middleFn' : type === 'middleFn' ? 'MiddleFn' : 'Route/middleFn';\n super(`${typeLabel} \"${routeId}\" not found in AOT cache.\\n` + `Regenerate AOT caches using 'mion-build-aot' command.`);\n this.name = 'AOTCacheError';\n }\n}\n\n// ############ Run-Types Module Loading ############\ntype RunTypesModule = typeof import('@mionjs/run-types');\n// Type definition for the dynamically imported run-types module\ninterface RunTypesFunctions {\n JitFunctions: RunTypesModule['JitFunctions'];\n reflectFunction: RunTypesModule['reflectFunction'];\n isUnionRunType: RunTypesModule['isUnionRunType'];\n isClassRunType: RunTypesModule['isClassRunType'];\n isLiteralRunType: RunTypesModule['isLiteralRunType'];\n isNeverRunType: RunTypesModule['isNeverRunType'];\n}\n\n// Cached run-types module - loaded once and reused\nlet runTypesModule: RunTypesFunctions | null = null;\nlet runTypesLoadPromise: Promise<RunTypesFunctions> | null = null;\n\n/** Dynamically loads the @mionjs/run-types module. The module is cached after first load. */\nasync function loadRunTypesModule(): Promise<RunTypesFunctions> {\n // Return cached module if already loaded\n if (runTypesModule) return runTypesModule;\n\n // Return existing promise if load is in progress\n if (runTypesLoadPromise) return runTypesLoadPromise;\n\n // Start loading the module\n runTypesLoadPromise = import('@mionjs/run-types').then((module) => {\n runTypesModule = {\n JitFunctions: module.JitFunctions,\n reflectFunction: module.reflectFunction,\n isUnionRunType: module.isUnionRunType,\n isClassRunType: module.isClassRunType,\n isLiteralRunType: module.isLiteralRunType,\n isNeverRunType: module.isNeverRunType,\n };\n return runTypesModule;\n });\n\n return runTypesLoadPromise;\n}\n\n/** Resets the run-types module cache. Useful for testing purposes only. */\nexport function resetRunTypesCache(): void {\n runTypesModule = null;\n runTypesLoadPromise = null;\n}\n\n/** Resets all reflection caches. Useful for testing purposes only. */\nexport function resetReflectionCaches(): void {\n rawMiddleFnReflectionCache.clear();\n // Note: functionRunTypeCache uses WeakMap so it doesn't need explicit clearing\n // Note: _cachedReflection on MethodMetadata objects will be cleared when persistedMethods is reset\n}\n\n// ############ Raw MiddleFn Reflection Helper ############\n\n// Cache for common raw middleFn reflections\nconst rawMiddleFnReflectionCache = new Map<string, MethodReflect>();\n\n/**\n * Creates a MethodReflect for raw middleFns.\n * Raw middleFns don't need JIT functions - they always use NoopJitFns.\n * Results are cached to avoid creating duplicate objects.\n */\nfunction createRawMiddleFnReflection(isAsync: boolean, hasReturnData: boolean = false, paramNames: string[] = []): MethodReflect {\n // Create cache key from parameters\n const cacheKey = `${isAsync}_${hasReturnData}_${paramNames.join(',')}`;\n\n const cached = rawMiddleFnReflectionCache.get(cacheKey);\n if (cached) return cached;\n\n const reflection: MethodReflect = {\n paramNames,\n paramsJitFns: getNoopJitFns(),\n returnJitFns: getNoopJitFns(),\n paramsJitHash: EMPTY_HASH,\n returnJitHash: EMPTY_HASH,\n hasReturnData,\n isAsync,\n };\n\n rawMiddleFnReflectionCache.set(cacheKey, reflection);\n return reflection;\n}\n\n// ############ AOT Cache Extraction ############\n\n// Extend MethodMetadata type to include cached reflection\ntype CachedMethodMetadata = MethodMetadata & {\n _cachedReflection?: MethodReflect;\n};\n\n/**\n * Extracts reflection data from a cached method.\n * Used in AOT mode to restore method reflection without loading run-types.\n * Results are cached on the metadata object to avoid creating duplicate objects.\n */\nfunction extractReflectionFromCached(cached: CachedMethodMetadata): MethodReflect {\n // Return cached reflection if available\n if (cached._cachedReflection) return cached._cachedReflection;\n\n const reflectionItems: MethodReflect = {\n paramNames: cached.paramNames || [],\n paramsJitFns: getJitFunctionsFromHash(cached.paramsJitHash),\n returnJitFns: getJitFunctionsFromHash(cached.returnJitHash),\n paramsJitHash: cached.paramsJitHash,\n returnJitHash: cached.returnJitHash,\n hasReturnData: cached.hasReturnData,\n isAsync: cached.isAsync,\n };\n\n // Restore headers param if present\n if (cached.headersParam) {\n reflectionItems.headersParam = {\n headerNames: cached.headersParam.headerNames,\n jitFns: getJitFunctionsFromHash(cached.headersParam.jitHash) as Pick<JitCompiledFunctions, 'isType' | 'typeErrors'>,\n jitHash: cached.headersParam.jitHash,\n };\n }\n\n // Restore headers return if present\n if (cached.headersReturn) {\n reflectionItems.headersReturn = {\n headerNames: cached.headersReturn.headerNames,\n jitFns: getJitFunctionsFromHash(cached.headersReturn.jitHash) as Pick<JitCompiledFunctions, 'isType' | 'typeErrors'>,\n jitHash: cached.headersReturn.jitHash,\n };\n }\n\n // Cache for future calls\n cached._cachedReflection = reflectionItems;\n return reflectionItems;\n}\n\n// ############ Main Reflection Functions ############\n\n/**\n * Gets reflection data for a handler (route or middleFn).\n * In AOT mode, returns cached data without loading run-types.\n * In non-AOT mode, dynamically loads run-types and generates reflection.\n * Throws AOTCacheError if AOT mode is enabled and route is not in cache.\n */\nexport async function getHandlerReflection(\n handler: Handler,\n routeId: string,\n routerOptions: RouterOptions,\n isHeadersMiddleFn: boolean = false,\n methodStrictTypes?: boolean\n): Promise<MethodReflect> {\n // Check AOT cache first\n const cached = getPersistedMethodMetadata(routeId);\n if (cached) return extractReflectionFromCached(cached);\n if (routerOptions.aot) throw new AOTCacheError(routeId, isHeadersMiddleFn ? 'middleFn' : 'route');\n // Non-AOT mode: dynamically load run-types and generate reflection\n const rt = await loadRunTypesModule();\n return generateHandlerReflection(handler, routeId, routerOptions, isHeadersMiddleFn, rt, methodStrictTypes);\n}\n\n/**\n * Gets reflection data for a raw middleFn.\n * Raw middleFns don't use full reflection - they don't need JIT functions.\n * Raw middleFns don't NEED to be in the AOT cache, but if they are, we can use\n * the cached data (especially the isAsync flag).\n * In AOT mode, this function does NOT load run-types.\n */\nexport async function getRawMethodReflection(\n handler: Handler,\n routeId: string,\n routerOptions: RouterOptions\n): Promise<MethodReflect> {\n // Check if raw middleFn is in cache - if so, use cached data (especially isAsync)\n const cached = getPersistedMethodMetadata(routeId);\n if (cached) return createRawMiddleFnReflection(cached.isAsync, cached.hasReturnData, cached.paramNames || []);\n // Raw middleFns don't need JIT functions, so we don't need to load run-types in AOT mode\n if (routerOptions.aot) return createRawMiddleFnReflection(true);\n // Non-AOT mode: dynamically load run-types to properly detect if handler is async\n const rt = await loadRunTypesModule();\n return generateRawMethodReflection(handler, routeId, rt);\n}\n\n// ############ Reflection Generation (requires run-types) ############\n\n/**\n * Generates reflection data for a handler using run-types.\n * This function is only called in non-AOT mode.\n */\nfunction generateHandlerReflection(\n handler: Handler,\n routeId: string,\n routerOptions: RouterOptions,\n isHeadersMiddleFn: boolean,\n rt: RunTypesFunctions,\n methodStrictTypes?: boolean\n): MethodReflect {\n const reflectionItems: Partial<MethodReflect> = {};\n let handlerRunType: FunctionRunType;\n const effectiveStrictTypes = methodStrictTypes ?? routerOptions.strictTypes;\n const runTypeOptions: RunTypeOptions = {\n ...(routerOptions?.runTypeOptions || DEFAULT_ROUTE_OPTIONS.runTypeOptions),\n ...(effectiveStrictTypes !== undefined ? {strictTypes: effectiveStrictTypes} : {}),\n };\n try {\n handlerRunType = rt.reflectFunction(handler);\n } catch (error: any) {\n throw new Error(`Can not get RunType of handler for route/middleFn \"${routeId}.\" Error: ${error?.message}`);\n }\n const paramsSlice = isHeadersMiddleFn ? {start: HEADER_HOOK_DEFAULT_PARAMS.length} : {start: ROUTE_DEFAULT_PARAMS.length};\n const paramsOpts: RunTypeOptions = {...runTypeOptions, paramsSlice};\n\n try {\n reflectionItems.paramNames = handlerRunType.getParameterNames(paramsOpts);\n // Skip JIT generation if handler has no params (optimization for AOT cache size)\n if (reflectionItems.paramNames.length === 0) {\n reflectionItems.paramsJitHash = EMPTY_HASH;\n reflectionItems.paramsJitFns = getNoopJitFns();\n } else {\n reflectionItems.paramsJitFns = getFunctionJitFns(handler, paramsOpts, rt, false);\n reflectionItems.paramsJitHash = handlerRunType.getParameters().getJitHash(paramsOpts);\n }\n } catch (error: any) {\n throw new Error(`Can not compile Jit Functions for Parameters of route/middleFn \"${routeId}.\" Error: ${error?.message}`);\n }\n\n if (isHeadersMiddleFn) {\n const headersRunType = getParamsHeadersRunType(handlerRunType, routeId, routerOptions, rt);\n const headerNames: string[] = getHeaderNames(headersRunType, routeId, rt);\n\n try {\n const opts: RunTypeOptions = {\n ...runTypeOptions,\n paramsSlice: undefined,\n };\n\n const jitFns: JitCompiledFunctions = getTypeJitFunctions(headersRunType, opts, rt);\n const jitHash = headersRunType.getJitHash(opts);\n reflectionItems.headersParam = {headerNames, jitFns, jitHash};\n } catch (error: any) {\n throw new Error(\n `Can not compile Jit Functions for Headers of Headers MiddleFn \"${routeId}.\" Error: ${error?.message}`\n );\n }\n }\n\n const returnHeadersRunType = getReturnHeadersRunType(handlerRunType, rt);\n if (returnHeadersRunType) {\n const opts: RunTypeOptions = {};\n const headerNames: string[] = getHeaderNames(returnHeadersRunType, routeId, rt);\n const jitFns: JitCompiledFunctions = getFunctionJitFns(handler, opts, rt, true);\n const jitHash: string = returnHeadersRunType.getJitHash(opts);\n reflectionItems.headersReturn = {headerNames, jitFns, jitHash};\n }\n\n const returnOpts: RunTypeOptions = runTypeOptions;\n // If the return type is HeadersSubset or if it's a headersFn with array return, don't treat it as return data\n reflectionItems.hasReturnData = handlerRunType.hasReturnData();\n\n try {\n // Skip JIT generation if handler has void return (optimization for AOT cache size)\n if (!reflectionItems.hasReturnData) {\n reflectionItems.returnJitFns = getNoopJitFns();\n reflectionItems.returnJitHash = EMPTY_HASH;\n } else {\n // returnJitFns contains all run type functionality for the return value, it compiles when the property is first accessed\n reflectionItems.returnJitFns = getFunctionJitFns(handler, returnOpts, rt, true);\n reflectionItems.returnJitHash = handlerRunType.getReturnType().getJitHash(returnOpts);\n }\n } catch (error: any) {\n throw new Error(`Can not get Jit Functions for Return of route/middleFn \"${routeId}.\" Error: ${error?.message}`);\n }\n\n reflectionItems.isAsync = handlerRunType.isAsync();\n\n return reflectionItems as MethodReflect;\n}\n\n/**\n * Generates reflection data for a raw middleFn using run-types.\n * This function is only called in non-AOT mode.\n */\nfunction generateRawMethodReflection(handler: Handler, routeId: string, rt: RunTypesFunctions): MethodReflect {\n let handlerRunType: FunctionRunType;\n try {\n handlerRunType = rt.reflectFunction(handler);\n } catch (error: any) {\n throw new Error(`Can not get RunType of handler for route/middleFn \"${routeId}.\" Error: ${error?.message}`);\n }\n const isAsync = handlerRunType?.isAsync() || true;\n return createRawMiddleFnReflection(isAsync);\n}\n\n// ############ Helper Functions (require run-types module) ############\n\nfunction getParamsHeadersRunType(\n handlerRunType: FunctionRunType,\n routeId: string,\n routerOptions: RouterOptions,\n rt: RunTypesFunctions\n): BaseRunType {\n const paramRunTypes = handlerRunType.getParameters().getParamRunTypes(getFakeCompiler(routerOptions));\n const headersSubset = (paramRunTypes[1] as MemberRunType<any>)?.getMemberType?.(); // HeadersSubset is always index 1 after context\n\n if (!isHeaderSubSetRunType(headersSubset, rt)) {\n throw new Error(`Headers MiddleFn '${routeId}' second parameter must be a HeadersSubset.`);\n }\n return headersSubset;\n}\n\nfunction getReturnHeadersRunType(handlerRunType: FunctionRunType, rt: RunTypesFunctions): BaseRunType | undefined {\n const returnRunType = handlerRunType.getReturnType();\n if (rt.isUnionRunType(returnRunType)) {\n const headersSubset = returnRunType.getChildRunTypes().find((child) => isHeaderSubSetRunType(child, rt));\n if (!headersSubset) return undefined;\n return headersSubset;\n }\n if (!isHeaderSubSetRunType(returnRunType, rt)) return undefined;\n return returnRunType;\n}\n\nfunction isHeaderSubSetRunType(runType: BaseRunType | undefined, rt: RunTypesFunctions): runType is BaseRunType {\n if (!runType) return false;\n return rt.isClassRunType(runType, HeadersSubset);\n}\n\nfunction getHeaderNames(runType: BaseRunType, routeId: string, rt: RunTypesFunctions): string[] {\n // HeadersSubset is a generic class: HeadersSubset<Required, Optional>\n // We need to extract the literal string values from the Required and Optional type arguments\n // Use 'typeArguments' (not 'arguments') to get both Required and Optional with their defaults\n const typeArguments = (runType.src as any).typeArguments;\n if (!typeArguments || typeArguments.length === 0) {\n throw new Error(`HeadersSubset must have type arguments in route/middleFn ${routeId}`);\n }\n const headerNames: string[] = [];\n // Extract header names from Required type argument (first argument)\n const requiredArg = typeArguments[0];\n if (requiredArg) {\n const requiredNames = extractLiteralStringsFromType(requiredArg._rt, rt);\n headerNames.push(...requiredNames);\n }\n // Extract header names from Optional type argument (second argument, if present)\n if (typeArguments.length > 1) {\n const optionalArg = typeArguments[1];\n if (optionalArg) {\n const optionalNames = extractLiteralStringsFromType(optionalArg._rt, rt);\n headerNames.push(...optionalNames);\n }\n }\n if (headerNames.length === 0) throw new Error(`Header names array cannot be empty in route/middleFn ${routeId}`);\n return headerNames;\n}\n\n/**\n * Internal recursive function to extract literal string values from a type.\n * Handles single literal strings and union types (including nested unions).\n */\nfunction extractLiteralStringsFromTypeRecursive(runType: BaseRunType, rt: RunTypesFunctions): string[] {\n // Handle single literal string\n if (rt.isLiteralRunType(runType)) {\n const literal = (runType as any).getLiteralValue();\n if (typeof literal === 'string') {\n return [literal];\n }\n return [];\n }\n\n // Handle union of literal strings (recursively for nested unions)\n if (rt.isUnionRunType(runType)) {\n const children = runType.getChildRunTypes();\n const literals: string[] = [];\n for (const child of children) {\n // Recursively extract from each child (handles nested unions)\n const childLiterals = extractLiteralStringsFromTypeRecursive(child, rt);\n literals.push(...childLiterals);\n }\n return literals;\n }\n\n return [];\n}\n\n/**\n * Extracts literal string values from a type.\n * Handles 'never' type only at the root level, then delegates to recursive extraction.\n */\nfunction extractLiteralStringsFromType(runType: BaseRunType, rt: RunTypesFunctions): string[] {\n // Handle 'never' type at root level only (no headers)\n if (rt.isNeverRunType(runType)) return [];\n return extractLiteralStringsFromTypeRecursive(runType, rt);\n}\n\n// Create a fake compiler object with just the opts property needed by getParamRunTypes.\n// getParamRunTypes() requires a JitFnCompiler but we only need the opts property to slice parameters.\n// This is a workaround to avoid updating getParamRunTypes() signature\nfunction getFakeCompiler(routerOptions: RouterOptions): JitFnCompiler {\n return {opts: routerOptions} as any as JitFnCompiler;\n}\n\nfunction getTypeJitFunctions(\n runType: BaseRunType,\n opts: RunTypeOptions | undefined,\n rtModule: RunTypesFunctions\n): JitCompiledFunctions {\n const jitFns: JitCompiledFunctions = {\n isType: runType.createJitCompiledFunction(rtModule.JitFunctions.isType.id, undefined, opts),\n typeErrors: runType.createJitCompiledFunction(rtModule.JitFunctions.typeErrors.id, undefined, opts),\n prepareForJson: runType.createJitCompiledFunction(rtModule.JitFunctions.prepareForJson.id, undefined, opts),\n restoreFromJson: runType.createJitCompiledFunction(rtModule.JitFunctions.restoreFromJson.id, undefined, opts),\n stringifyJson: runType.createJitCompiledFunction(rtModule.JitFunctions.stringifyJson.id, undefined, opts),\n toBinary: runType.createJitCompiledFunction(rtModule.JitFunctions.toBinary.id, undefined, opts),\n fromBinary: runType.createJitCompiledFunction(rtModule.JitFunctions.fromBinary.id, undefined, opts),\n };\n return jitFns;\n}\n\n// Cache for function RunTypes to avoid duplicate reflectFunction calls\nconst functionRunTypeCache = new WeakMap<AnyFn, FunctionRunType>();\n\nfunction getFunctionJitFns<Fn extends AnyFn>(\n fn: Fn,\n opts: RunTypeOptions | undefined,\n rtModule: RunTypesFunctions,\n isReturn: boolean\n): JitCompiledFunctions {\n // Check cache first\n let runType = functionRunTypeCache.get(fn);\n if (!runType) {\n runType = rtModule.reflectFunction(fn);\n functionRunTypeCache.set(fn, runType);\n }\n\n const createFn = isReturn\n ? runType.createJitCompiledReturnFunction.bind(runType)\n : runType.createJitCompiledParamsFunction.bind(runType);\n const jitFunctions: JitCompiledFunctions = {\n isType: createFn(rtModule.JitFunctions.isType, opts),\n typeErrors: createFn(rtModule.JitFunctions.typeErrors, opts),\n prepareForJson: createFn(rtModule.JitFunctions.prepareForJson, opts),\n restoreFromJson: createFn(rtModule.JitFunctions.restoreFromJson, opts),\n stringifyJson: createFn(rtModule.JitFunctions.stringifyJson, opts),\n toBinary: createFn(rtModule.JitFunctions.toBinary, opts),\n fromBinary: createFn(rtModule.JitFunctions.fromBinary, opts),\n };\n return jitFunctions;\n}\n\n// ############ Null JIT Functions ############\n"],"names":["module","getNoopJitFns","EMPTY_HASH","getJitFunctionsFromHash","getPersistedMethodMetadata","DEFAULT_ROUTE_OPTIONS","HEADER_HOOK_DEFAULT_PARAMS","ROUTE_DEFAULT_PARAMS","HeadersSubset"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BM,MAAO,sBAAsB,MAAK;AAAA,EACpC,YAAY,SAAiB,OAA6C,SAAO;AAC7E,UAAM,YAAY,SAAS,gBAAgB,iBAAiB,SAAS,aAAa,aAAa;AAC/F,UAAM,GAAG,SAAS,KAAK,OAAO;AAAA,sDAAuF;AACrH,SAAK,OAAO;AAAA,EAChB;AAAA;;;;AAgBJ,IAAI,iBAA2C;AAC/C,IAAI,sBAAyD;AAG7D,eAAe,qBAAkB;AAE7B,MAAI;AAAgB,WAAO;AAG3B,MAAI;AAAqB,WAAO;AAGhC,wBAAsB,OAAO,mBAAmB,EAAE,KAAI,aAAC,CAACA,YAAU;AAC9D,qBAAiB;AAAA,MACb,cAAcA,QAAO;AAAA,MACrB,iBAAiBA,QAAO;AAAA,MACxB,gBAAgBA,QAAO;AAAA,MACvB,gBAAgBA,QAAO;AAAA,MACvB,kBAAkBA,QAAO;AAAA,MACzB,gBAAgBA,QAAO;AAAA,IAAA;AAE3B,WAAO;AAAA,EACX;AAEA,SAAO;AACX;;SAGgB,qBAAkB;AAC9B,mBAAiB;AACjB,wBAAsB;AAC1B;;SAGgB,wBAAqB;AACjC,6BAA2B,MAAA;AAG/B;;AAKA,MAAM,8BAAiC,IAAG,IAAA,CAAA,CAAA,GAAA,GAAA,CAAA,MAAA,kBAAA,IAAA,CAAA,uBAAH,IAAA;AAOvC,SAAS,4BAA4B,SAAkB,gBAAyB,OAAO,aAAuB,CAAA,GAAE;AAE5G,QAAM,WAAW,GAAG,OAAO,I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Y,IAAI;AAAA,EAAA;AAE/D,SAAO;AACX;;;;;;;"}
1
+ {"version":3,"file":"reflection.cjs","sources":["../../../../src/lib/reflection.ts"],"sourcesContent":["/* ########\n * 2024 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport type {MethodWithJitFns, AnyFn, JitCompiledFunctions, MethodMetadata} from '@mionjs/core';\n// Type-only imports from run-types - these don't load the module at runtime\nimport type {FunctionRunType, BaseRunType, MemberRunType, RunTypeOptions, JitFnCompiler} from '@mionjs/run-types';\nimport {Handler} from '../types/handlers.ts';\nimport {RouterOptions} from '../types/general.ts';\nimport {DEFAULT_ROUTE_OPTIONS, HEADER_HOOK_DEFAULT_PARAMS, ROUTE_DEFAULT_PARAMS} from '../constants.ts';\nimport {EMPTY_HASH, HeadersSubset, getJitFunctionsFromHash, getNoopJitFns, HandlerType} from '@mionjs/core';\nimport {getPersistedMethodMetadata} from './methodsCache.ts';\nimport {RouteOptions, MiddleFnOptions, HeadersMiddleFnOptions, MiddleFnMethod, HeadersMethod} from '../types/remoteMethods.ts';\n\n// ############ This file is the only one importing '@mionjs/run-types' within the router ########\n// In AOT mode, run-types is NOT loaded - all reflection data comes from the AOT cache\n\ntype MethodReflect = Omit<MethodWithJitFns, 'id' | 'type' | 'nestLevel' | 'pointer' | 'options'>;\n\n// ############ AOT Cache Error ############\n\n/**\n * Error thrown when AOT mode is enabled but required data is missing from the AOT cache.\n * This indicates that the AOT caches need to be regenerated using 'mion-build-aot' command.\n */\nexport class AOTCacheError extends Error {\n constructor(routeId: string, type: 'route' | 'middleFn' | 'rawMiddleFn' = 'route') {\n const typeLabel = type === 'rawMiddleFn' ? 'Raw middleFn' : type === 'middleFn' ? 'MiddleFn' : 'Route/middleFn';\n super(`${typeLabel} \"${routeId}\" not found in AOT cache.\\n` + `Regenerate AOT caches using 'mion-build-aot' command.`);\n this.name = 'AOTCacheError';\n }\n}\n\n// ############ Run-Types Module Loading ############\ntype RunTypesModule = typeof import('@mionjs/run-types');\n// Type definition for the dynamically imported run-types module\ninterface RunTypesFunctions {\n JitFunctions: RunTypesModule['JitFunctions'];\n reflectFunction: RunTypesModule['reflectFunction'];\n isUnionRunType: RunTypesModule['isUnionRunType'];\n isClassRunType: RunTypesModule['isClassRunType'];\n isLiteralRunType: RunTypesModule['isLiteralRunType'];\n isNeverRunType: RunTypesModule['isNeverRunType'];\n}\n\n// Cached run-types module - loaded once and reused\nlet runTypesModule: RunTypesFunctions | null = null;\nlet runTypesLoadPromise: Promise<RunTypesFunctions> | null = null;\n\n/** Dynamically loads the @mionjs/run-types module. The module is cached after first load. */\nasync function loadRunTypesModule(): Promise<RunTypesFunctions> {\n // Return cached module if already loaded\n if (runTypesModule) return runTypesModule;\n\n // Return existing promise if load is in progress\n if (runTypesLoadPromise) return runTypesLoadPromise;\n\n // Start loading the module\n runTypesLoadPromise = import('@mionjs/run-types').then((module) => {\n runTypesModule = {\n JitFunctions: module.JitFunctions,\n reflectFunction: module.reflectFunction,\n isUnionRunType: module.isUnionRunType,\n isClassRunType: module.isClassRunType,\n isLiteralRunType: module.isLiteralRunType,\n isNeverRunType: module.isNeverRunType,\n };\n return runTypesModule;\n });\n\n return runTypesLoadPromise;\n}\n\n/** Resets the run-types module cache. Useful for testing purposes only. */\nexport function resetRunTypesCache(): void {\n runTypesModule = null;\n runTypesLoadPromise = null;\n}\n\n/** Resets all reflection caches. Useful for testing purposes only. */\nexport function resetReflectionCaches(): void {\n rawMiddleFnReflectionCache.clear();\n // Note: functionRunTypeCache uses WeakMap so it doesn't need explicit clearing\n // Note: _cachedReflection on MethodMetadata objects will be cleared when persistedMethods is reset\n}\n\n// ############ Raw MiddleFn Reflection Helper ############\n\n// Cache for common raw middleFn reflections\nconst rawMiddleFnReflectionCache = new Map<string, MethodReflect>();\n\n/**\n * Creates a MethodReflect for raw middleFns.\n * Raw middleFns don't need JIT functions - they always use NoopJitFns.\n * Results are cached to avoid creating duplicate objects.\n */\nfunction createRawMiddleFnReflection(isAsync: boolean, hasReturnData: boolean = false, paramNames: string[] = []): MethodReflect {\n // Create cache key from parameters\n const cacheKey = `${isAsync}_${hasReturnData}_${paramNames.join(',')}`;\n\n const cached = rawMiddleFnReflectionCache.get(cacheKey);\n if (cached) return cached;\n\n const reflection: MethodReflect = {\n paramNames,\n paramsJitFns: getNoopJitFns(),\n returnJitFns: getNoopJitFns(),\n paramsJitHash: EMPTY_HASH,\n returnJitHash: EMPTY_HASH,\n hasReturnData,\n isAsync,\n };\n\n rawMiddleFnReflectionCache.set(cacheKey, reflection);\n return reflection;\n}\n\n// ############ AOT Cache Extraction ############\n\n// Extend MethodMetadata type to include cached reflection\ntype CachedMethodMetadata = MethodMetadata & {\n _cachedReflection?: MethodReflect;\n};\n\n/**\n * Extracts reflection data from a cached method.\n * Used in AOT mode to restore method reflection without loading run-types.\n * Results are cached on the metadata object to avoid creating duplicate objects.\n */\nfunction extractReflectionFromCached(cached: CachedMethodMetadata): MethodReflect {\n // Return cached reflection if available\n if (cached._cachedReflection) return cached._cachedReflection;\n\n const reflectionItems: MethodReflect = {\n paramNames: cached.paramNames || [],\n paramsJitFns: getJitFunctionsFromHash(cached.paramsJitHash),\n returnJitFns: getJitFunctionsFromHash(cached.returnJitHash),\n paramsJitHash: cached.paramsJitHash,\n returnJitHash: cached.returnJitHash,\n hasReturnData: cached.hasReturnData,\n isAsync: cached.isAsync,\n };\n\n // Restore headers param if present\n if (cached.headersParam) {\n reflectionItems.headersParam = {\n headerNames: cached.headersParam.headerNames,\n jitFns: getJitFunctionsFromHash(cached.headersParam.jitHash) as Pick<JitCompiledFunctions, 'isType' | 'typeErrors'>,\n jitHash: cached.headersParam.jitHash,\n };\n }\n\n // Restore headers return if present\n if (cached.headersReturn) {\n reflectionItems.headersReturn = {\n headerNames: cached.headersReturn.headerNames,\n jitFns: getJitFunctionsFromHash(cached.headersReturn.jitHash) as Pick<JitCompiledFunctions, 'isType' | 'typeErrors'>,\n jitHash: cached.headersReturn.jitHash,\n };\n }\n\n // Cache for future calls\n cached._cachedReflection = reflectionItems;\n return reflectionItems;\n}\n\n// ############ Main Reflection Functions ############\n\n/**\n * Gets reflection data for a handler (route or middleFn).\n * In AOT mode, returns cached data without loading run-types.\n * In non-AOT mode, dynamically loads run-types and generates reflection.\n * Throws AOTCacheError if AOT mode is enabled and route is not in cache.\n */\nexport async function getHandlerReflection(\n handler: Handler,\n routeId: string,\n routerOptions: RouterOptions,\n handlerOptions: RouteOptions | MiddleFnOptions | HeadersMiddleFnOptions = {},\n isHeadersMiddleFn: boolean = false,\n methodStrictTypes?: boolean\n): Promise<MethodReflect> {\n // Check AOT cache first\n const cached = getPersistedMethodMetadata(routeId);\n if (cached) return extractReflectionFromCached(cached);\n if (routerOptions.aot) throw new AOTCacheError(routeId, isHeadersMiddleFn ? 'middleFn' : 'route');\n // Non-AOT mode: dynamically load run-types and generate reflection\n const rt = await loadRunTypesModule();\n return generateHandlerReflection(handler, routeId, routerOptions, handlerOptions, isHeadersMiddleFn, rt, methodStrictTypes);\n}\n\n/**\n * Gets reflection data for a raw middleFn.\n * Raw middleFns don't use full reflection - they don't need JIT functions.\n * Raw middleFns don't NEED to be in the AOT cache, but if they are, we can use\n * the cached data (especially the isAsync flag).\n * In AOT mode, this function does NOT load run-types.\n */\nexport async function getRawMethodReflection(\n handler: Handler,\n routeId: string,\n routerOptions: RouterOptions\n): Promise<MethodReflect> {\n // Check if raw middleFn is in cache - if so, use cached data (especially isAsync)\n const cached = getPersistedMethodMetadata(routeId);\n if (cached) return createRawMiddleFnReflection(cached.isAsync, cached.hasReturnData, cached.paramNames || []);\n // Raw middleFns don't need JIT functions, so we don't need to load run-types in AOT mode\n if (routerOptions.aot) return createRawMiddleFnReflection(true);\n // Non-AOT mode: dynamically load run-types to properly detect if handler is async\n const rt = await loadRunTypesModule();\n return generateRawMethodReflection(handler, routeId, rt);\n}\n\n// ############ Reflection Generation (requires run-types) ############\n\n/**\n * Generates reflection data for a handler using run-types.\n * This function is only called in non-AOT mode.\n */\nfunction generateHandlerReflection(\n handler: Handler,\n routeId: string,\n routerOptions: RouterOptions,\n handlerOptions: RouteOptions | MiddleFnOptions | HeadersMiddleFnOptions,\n isHeadersMiddleFn: boolean,\n rt: RunTypesFunctions,\n methodStrictTypes?: boolean\n): MethodReflect {\n const reflectionItems: Partial<MethodReflect> = {};\n let handlerRunType: FunctionRunType;\n const needsBinary = ((handlerOptions as RouteOptions)?.serializer ?? routerOptions.serializer) === 'binary';\n const effectiveStrictTypes = methodStrictTypes ?? routerOptions.strictTypes;\n const runTypeOptions: RunTypeOptions = {\n ...(routerOptions?.runTypeOptions || DEFAULT_ROUTE_OPTIONS.runTypeOptions),\n ...(effectiveStrictTypes !== undefined ? {strictTypes: effectiveStrictTypes} : {}),\n };\n try {\n handlerRunType = rt.reflectFunction(handler);\n } catch (error: any) {\n throw new Error(`Can not get RunType of handler for route/middleFn \"${routeId}.\" Error: ${error?.message}`);\n }\n const paramsSlice = isHeadersMiddleFn ? {start: HEADER_HOOK_DEFAULT_PARAMS.length} : {start: ROUTE_DEFAULT_PARAMS.length};\n const paramsOpts: RunTypeOptions = {...runTypeOptions, paramsSlice};\n\n try {\n reflectionItems.paramNames = handlerRunType.getParameterNames(paramsOpts);\n // Skip JIT generation if handler has no params (optimization for AOT cache size)\n if (reflectionItems.paramNames.length === 0) {\n reflectionItems.paramsJitHash = EMPTY_HASH;\n reflectionItems.paramsJitFns = getNoopJitFns();\n } else {\n reflectionItems.paramsJitFns = getFunctionJitFns(handler, paramsOpts, rt, false, needsBinary);\n reflectionItems.paramsJitHash = handlerRunType.getParameters().getJitHash(paramsOpts);\n }\n } catch (error: any) {\n throw new Error(`Can not compile Jit Functions for Parameters of route/middleFn \"${routeId}.\" Error: ${error?.message}`);\n }\n\n if (isHeadersMiddleFn) {\n const headersRunType = getParamsHeadersRunType(handlerRunType, routeId, routerOptions, rt);\n const headerNames: string[] = getHeaderNames(headersRunType, routeId, rt);\n\n try {\n const opts: RunTypeOptions = {\n ...runTypeOptions,\n paramsSlice: undefined,\n };\n\n const jitFns: JitCompiledFunctions = getTypeJitFunctions(headersRunType, opts, rt, false);\n const jitHash = headersRunType.getJitHash(opts);\n reflectionItems.headersParam = {headerNames, jitFns, jitHash};\n } catch (error: any) {\n throw new Error(\n `Can not compile Jit Functions for Headers of Headers MiddleFn \"${routeId}.\" Error: ${error?.message}`\n );\n }\n }\n\n const returnHeadersRunType = getReturnHeadersRunType(handlerRunType, rt);\n if (returnHeadersRunType) {\n const opts: RunTypeOptions = {};\n const headerNames: string[] = getHeaderNames(returnHeadersRunType, routeId, rt);\n const jitFns: JitCompiledFunctions = getFunctionJitFns(handler, opts, rt, true, false);\n const jitHash: string = returnHeadersRunType.getJitHash(opts);\n reflectionItems.headersReturn = {headerNames, jitFns, jitHash};\n }\n\n const returnOpts: RunTypeOptions = runTypeOptions;\n // If the return type is HeadersSubset or if it's a headersFn with array return, don't treat it as return data\n reflectionItems.hasReturnData = handlerRunType.hasReturnData();\n\n try {\n // Skip JIT generation if handler has void return (optimization for AOT cache size)\n if (!reflectionItems.hasReturnData) {\n reflectionItems.returnJitFns = getNoopJitFns();\n reflectionItems.returnJitHash = EMPTY_HASH;\n } else {\n // returnJitFns contains all run type functionality for the return value, it compiles when the property is first accessed\n reflectionItems.returnJitFns = getFunctionJitFns(handler, returnOpts, rt, true, needsBinary);\n reflectionItems.returnJitHash = handlerRunType.getResolvedReturnType().getJitHash(returnOpts);\n }\n } catch (error: any) {\n throw new Error(`Can not get Jit Functions for Return of route/middleFn \"${routeId}.\" Error: ${error?.message}`);\n }\n\n reflectionItems.isAsync = handlerRunType.isAsync();\n\n return reflectionItems as MethodReflect;\n}\n\n/**\n * Generates reflection data for a raw middleFn using run-types.\n * This function is only called in non-AOT mode.\n */\nfunction generateRawMethodReflection(handler: Handler, routeId: string, rt: RunTypesFunctions): MethodReflect {\n let handlerRunType: FunctionRunType;\n try {\n handlerRunType = rt.reflectFunction(handler);\n } catch (error: any) {\n throw new Error(`Can not get RunType of handler for route/middleFn \"${routeId}.\" Error: ${error?.message}`);\n }\n const isAsync = handlerRunType?.isAsync() || true;\n return createRawMiddleFnReflection(isAsync);\n}\n\n// ############ Helper Functions (require run-types module) ############\n\nfunction getParamsHeadersRunType(\n handlerRunType: FunctionRunType,\n routeId: string,\n routerOptions: RouterOptions,\n rt: RunTypesFunctions\n): BaseRunType {\n const paramRunTypes = handlerRunType.getParameters().getParamRunTypes(getFakeCompiler(routerOptions));\n const headersSubset = (paramRunTypes[1] as MemberRunType<any>)?.getMemberType?.(); // HeadersSubset is always index 1 after context\n\n if (!isHeaderSubSetRunType(headersSubset, rt)) {\n throw new Error(`Headers MiddleFn '${routeId}' second parameter must be a HeadersSubset.`);\n }\n return headersSubset;\n}\n\nfunction getReturnHeadersRunType(handlerRunType: FunctionRunType, rt: RunTypesFunctions): BaseRunType | undefined {\n const returnRunType = handlerRunType.getReturnType();\n if (rt.isUnionRunType(returnRunType)) {\n const headersSubset = returnRunType.getChildRunTypes().find((child) => isHeaderSubSetRunType(child, rt));\n if (!headersSubset) return undefined;\n return headersSubset;\n }\n if (!isHeaderSubSetRunType(returnRunType, rt)) return undefined;\n return returnRunType;\n}\n\nfunction isHeaderSubSetRunType(runType: BaseRunType | undefined, rt: RunTypesFunctions): runType is BaseRunType {\n if (!runType) return false;\n return rt.isClassRunType(runType, HeadersSubset);\n}\n\nfunction getHeaderNames(runType: BaseRunType, routeId: string, rt: RunTypesFunctions): string[] {\n // HeadersSubset is a generic class: HeadersSubset<Required, Optional>\n // We need to extract the literal string values from the Required and Optional type arguments\n // Use 'typeArguments' (not 'arguments') to get both Required and Optional with their defaults\n const typeArguments = (runType.src as any).typeArguments;\n if (!typeArguments || typeArguments.length === 0) {\n throw new Error(`HeadersSubset must have type arguments in route/middleFn ${routeId}`);\n }\n const headerNames: string[] = [];\n // Extract header names from Required type argument (first argument)\n const requiredArg = typeArguments[0];\n if (requiredArg) {\n const requiredNames = extractLiteralStringsFromType(requiredArg._rt, rt);\n headerNames.push(...requiredNames);\n }\n // Extract header names from Optional type argument (second argument, if present)\n if (typeArguments.length > 1) {\n const optionalArg = typeArguments[1];\n if (optionalArg) {\n const optionalNames = extractLiteralStringsFromType(optionalArg._rt, rt);\n headerNames.push(...optionalNames);\n }\n }\n if (headerNames.length === 0) throw new Error(`Header names array cannot be empty in route/middleFn ${routeId}`);\n return headerNames;\n}\n\n/**\n * Internal recursive function to extract literal string values from a type.\n * Handles single literal strings and union types (including nested unions).\n */\nfunction extractLiteralStringsFromTypeRecursive(runType: BaseRunType, rt: RunTypesFunctions): string[] {\n // Handle single literal string\n if (rt.isLiteralRunType(runType)) {\n const literal = (runType as any).getLiteralValue();\n if (typeof literal === 'string') {\n return [literal];\n }\n return [];\n }\n\n // Handle union of literal strings (recursively for nested unions)\n if (rt.isUnionRunType(runType)) {\n const children = runType.getChildRunTypes();\n const literals: string[] = [];\n for (const child of children) {\n // Recursively extract from each child (handles nested unions)\n const childLiterals = extractLiteralStringsFromTypeRecursive(child, rt);\n literals.push(...childLiterals);\n }\n return literals;\n }\n\n return [];\n}\n\n/**\n * Extracts literal string values from a type.\n * Handles 'never' type only at the root level, then delegates to recursive extraction.\n */\nfunction extractLiteralStringsFromType(runType: BaseRunType, rt: RunTypesFunctions): string[] {\n // Handle 'never' type at root level only (no headers)\n if (rt.isNeverRunType(runType)) return [];\n return extractLiteralStringsFromTypeRecursive(runType, rt);\n}\n\n// Create a fake compiler object with just the opts property needed by getParamRunTypes.\n// getParamRunTypes() requires a JitFnCompiler but we only need the opts property to slice parameters.\n// This is a workaround to avoid updating getParamRunTypes() signature\nfunction getFakeCompiler(routerOptions: RouterOptions): JitFnCompiler {\n return {opts: routerOptions} as any as JitFnCompiler;\n}\n\nfunction getTypeJitFunctions(\n runType: BaseRunType,\n opts: RunTypeOptions | undefined,\n rtModule: RunTypesFunctions,\n needsBinary: boolean = false\n): JitCompiledFunctions {\n const jitFns: JitCompiledFunctions = {\n isType: runType.createJitCompiledFunction(rtModule.JitFunctions.isType.id, undefined, opts),\n typeErrors: runType.createJitCompiledFunction(rtModule.JitFunctions.typeErrors.id, undefined, opts),\n prepareForJson: runType.createJitCompiledFunction(rtModule.JitFunctions.prepareForJson.id, undefined, opts),\n restoreFromJson: runType.createJitCompiledFunction(rtModule.JitFunctions.restoreFromJson.id, undefined, opts),\n stringifyJson: runType.createJitCompiledFunction(rtModule.JitFunctions.stringifyJson.id, undefined, opts),\n ...(needsBinary\n ? {\n toBinary: runType.createJitCompiledFunction(rtModule.JitFunctions.toBinary.id, undefined, opts),\n fromBinary: runType.createJitCompiledFunction(rtModule.JitFunctions.fromBinary.id, undefined, opts),\n }\n : {}),\n };\n return jitFns;\n}\n\n// Cache for function RunTypes to avoid duplicate reflectFunction calls\nconst functionRunTypeCache = new WeakMap<AnyFn, FunctionRunType>();\n\nfunction getFunctionJitFns<Fn extends AnyFn>(\n fn: Fn,\n opts: RunTypeOptions | undefined,\n rtModule: RunTypesFunctions,\n isReturn: boolean,\n needsBinary: boolean = false\n): JitCompiledFunctions {\n // Check cache first\n let runType = functionRunTypeCache.get(fn);\n if (!runType) {\n runType = rtModule.reflectFunction(fn);\n functionRunTypeCache.set(fn, runType);\n }\n\n const createFn = isReturn\n ? runType.createJitCompiledReturnFunction.bind(runType)\n : runType.createJitCompiledParamsFunction.bind(runType);\n const jitFunctions: JitCompiledFunctions = {\n isType: createFn(rtModule.JitFunctions.isType, opts),\n typeErrors: createFn(rtModule.JitFunctions.typeErrors, opts),\n prepareForJson: createFn(rtModule.JitFunctions.prepareForJson, opts),\n restoreFromJson: createFn(rtModule.JitFunctions.restoreFromJson, opts),\n stringifyJson: createFn(rtModule.JitFunctions.stringifyJson, opts),\n ...(needsBinary\n ? {\n toBinary: createFn(rtModule.JitFunctions.toBinary, opts),\n fromBinary: createFn(rtModule.JitFunctions.fromBinary, opts),\n }\n : {}),\n };\n return jitFunctions;\n}\n\n// ############ Retroactive Binary JIT Compilation ############\n\n/** Compiles toBinary/fromBinary JIT functions for middleware that was initially compiled without binary support */\nexport async function ensureBinaryJitFns(method: MiddleFnMethod | HeadersMethod): Promise<void> {\n if (method.paramsJitFns.toBinary && method.returnJitFns.toBinary) return;\n const rt = await loadRunTypesModule();\n const isHeader = method.type === HandlerType.headersMiddleFn;\n const paramsSlice = isHeader ? {start: HEADER_HOOK_DEFAULT_PARAMS.length} : {start: ROUTE_DEFAULT_PARAMS.length};\n const opts: RunTypeOptions = {paramsSlice};\n\n if (!method.paramsJitFns.toBinary && method.paramsJitHash !== EMPTY_HASH) {\n const runType = rt.reflectFunction(method.handler);\n const createFn = runType.createJitCompiledParamsFunction.bind(runType);\n method.paramsJitFns.toBinary = createFn(rt.JitFunctions.toBinary, opts);\n method.paramsJitFns.fromBinary = createFn(rt.JitFunctions.fromBinary, opts);\n }\n if (!method.returnJitFns.toBinary && method.returnJitHash !== EMPTY_HASH && method.hasReturnData) {\n const runType = rt.reflectFunction(method.handler);\n const createFn = runType.createJitCompiledReturnFunction.bind(runType);\n method.returnJitFns.toBinary = createFn(rt.JitFunctions.toBinary);\n method.returnJitFns.fromBinary = createFn(rt.JitFunctions.fromBinary);\n }\n}\n\n// ############ Null JIT Functions ############\n"],"names":["module","getNoopJitFns","EMPTY_HASH","getJitFunctionsFromHash","getPersistedMethodMetadata","DEFAULT_ROUTE_OPTIONS","HEADER_HOOK_DEFAULT_PARAMS","ROUTE_DEFAULT_PARAMS","HeadersSubset","HandlerType"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BM,MAAO,sBAAsB,MAAK;AAAA,EACpC,YAAY,SAAiB,OAA6C,SAAO;AAC7E,UAAM,YAAY,SAAS,gBAAgB,iBAAiB,SAAS,aAAa,aAAa;AAC/F,UAAM,GAAG,SAAS,KAAK,OAAO;AAAA,sDAAuF;AACrH,SAAK,OAAO;AAAA,EAChB;AAAA;;;;AAgBJ,IAAI,iBAA2C;AAC/C,IAAI,sBAAyD;AAG7D,eAAe,qBA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,UAAM,UAAU,GAAG,gBAAgB,OAAO,OAAO;AACjD,UAAM,WAAW,QAAQ,gCAAgC,KAAK,OAAO;AACrE,WAAO,aAAa,WAAW,SAAS,GAAG,aAAa,UAAU,IAAI;AACtE,WAAO,aAAa,aAAa,SAAS,GAAG,aAAa,YAAY,IAAI;AAAA,EAC9E;AACA,MAAI,CAAC,OAAO,aAAa,YAAY,OAAO,kBAAkBA,KAAAA,cAAc,OAAO,eAAe;AAC9F,UAAM,UAAU,GAAG,gBAAgB,OAAO,OAAO;AACjD,UAAM,WAAW,QAAQ,gCAAgC,KAAK,OAAO;AACrE,WAAO,aAAa,WAAW,SAAS,GAAG,aAAa,QAAQ;AAChE,WAAO,aAAa,aAAa,SAAS,GAAG,aAAa,UAAU;AAAA,EACxE;AACJ;;;;;;;;"}
@@ -1,12 +1,14 @@
1
1
  import { MethodWithJitFns } from '@mionjs/core';
2
2
  import { Handler } from '../types/handlers.ts';
3
3
  import { RouterOptions } from '../types/general.ts';
4
+ import { RouteOptions, MiddleFnOptions, HeadersMiddleFnOptions, MiddleFnMethod, HeadersMethod } from '../types/remoteMethods.ts';
4
5
  type MethodReflect = Omit<MethodWithJitFns, 'id' | 'type' | 'nestLevel' | 'pointer' | 'options'>;
5
6
  export declare class AOTCacheError extends Error {
6
7
  constructor(routeId: string, type?: 'route' | 'middleFn' | 'rawMiddleFn');
7
8
  }
8
9
  export declare function resetRunTypesCache(): void;
9
10
  export declare function resetReflectionCaches(): void;
10
- export declare function getHandlerReflection(handler: Handler, routeId: string, routerOptions: RouterOptions, isHeadersMiddleFn?: boolean, methodStrictTypes?: boolean): Promise<MethodReflect>;
11
+ export declare function getHandlerReflection(handler: Handler, routeId: string, routerOptions: RouterOptions, handlerOptions?: RouteOptions | MiddleFnOptions | HeadersMiddleFnOptions, isHeadersMiddleFn?: boolean, methodStrictTypes?: boolean): Promise<MethodReflect>;
11
12
  export declare function getRawMethodReflection(handler: Handler, routeId: string, routerOptions: RouterOptions): Promise<MethodReflect>;
13
+ export declare function ensureBinaryJitFns(method: MiddleFnMethod | HeadersMethod): Promise<void>;
12
14
  export {};
@@ -60,9 +60,12 @@ function serializePureDeps(namespacedDepHash, purFnDeps, depth = 0) {
60
60
  if (purFnDeps[namespace][fnHash]) return;
61
61
  const pureDep = core.getJitUtils().getCompiledPureFn(namespace, fnHash);
62
62
  if (!pureDep) throw new Error(`Pure function ${fnHash} not found in namespace ${namespace}`);
63
- const serializedPureDep = { ...pureDep, pureFnDependencies: [...pureDep.pureFnDependencies] };
63
+ const serializedPureDep = {
64
+ ...pureDep,
65
+ pureFnDependencies: pureDep.pureFnDependencies ? [...pureDep.pureFnDependencies] : void 0
66
+ };
64
67
  purFnDeps[namespace][fnHash] = serializedPureDep;
65
- pureDep.pureFnDependencies.forEach((depFnHash) => serializePureDeps(`${namespace}::${depFnHash}`, purFnDeps, depth + 1));
68
+ pureDep.pureFnDependencies?.forEach((depFnHash) => serializePureDeps(`${namespace}::${depFnHash}`, purFnDeps, depth + 1));
66
69
  }
67
70
  function serializeJitFn(jitFnHash, deps, purFnDeps, depth = 0) {
68
71
  if (depth >= core.MAX_STACK_DEPTH)
@@ -72,18 +75,31 @@ function serializeJitFn(jitFnHash, deps, purFnDeps, depth = 0) {
72
75
  if (deps[jitFnHash]) return;
73
76
  const serializedJitFn = getSerializableJitCompiler(jitFn);
74
77
  deps[jitFnHash] = serializedJitFn;
75
- jitFn.jitDependencies.forEach((h) => serializeJitFn(h, deps, purFnDeps, depth + 1));
76
- jitFn.pureFnDependencies.forEach((h) => serializePureDeps(h, purFnDeps));
78
+ jitFn.jitDependencies?.forEach((h) => serializeJitFn(h, deps, purFnDeps, depth + 1));
79
+ jitFn.pureFnDependencies?.forEach((h) => serializePureDeps(h, purFnDeps));
77
80
  }
78
81
  function serializeMethodDeps(method, deps, purFnDeps) {
79
82
  const { paramsJitHash, returnJitHash } = method;
80
83
  if (paramsJitHash !== core.EMPTY_HASH) {
81
- const paramsJitHashes = core.getJitFnHashes(paramsJitHash);
82
- for (const k in paramsJitHashes) serializeJitFn(paramsJitHashes[k], deps, purFnDeps);
84
+ const paramsJitHashes = core.getJitFnHashes(paramsJitHash, true);
85
+ for (const k in paramsJitHashes) {
86
+ if (core.getJitUtils().getJIT(paramsJitHashes[k])) serializeJitFn(paramsJitHashes[k], deps, purFnDeps);
87
+ }
83
88
  }
84
89
  if (returnJitHash !== core.EMPTY_HASH) {
85
- const returnJitHashes = core.getJitFnHashes(returnJitHash);
86
- for (const k in returnJitHashes) serializeJitFn(returnJitHashes[k], deps, purFnDeps);
90
+ const returnJitHashes = core.getJitFnHashes(returnJitHash, true);
91
+ let foundAny = false;
92
+ for (const k in returnJitHashes) {
93
+ if (core.getJitUtils().getJIT(returnJitHashes[k])) {
94
+ serializeJitFn(returnJitHashes[k], deps, purFnDeps);
95
+ foundAny = true;
96
+ }
97
+ }
98
+ if (!foundAny) {
99
+ throw new Error(
100
+ `Method "${method.id}" declares returnJitHash="${returnJitHash}" but no JIT functions are registered under that hash. This usually means a Promise/Function return type was not unwrapped before computing the hash.`
101
+ );
102
+ }
87
103
  }
88
104
  }
89
105
  function getSerializableJitCompiler(comp) {
@@ -95,8 +111,8 @@ function getSerializableJitCompiler(comp) {
95
111
  isNoop: comp.isNoop,
96
112
  defaultParamValues: structuredClone(comp.defaultParamValues),
97
113
  code: comp.code,
98
- jitDependencies: [...comp.jitDependencies],
99
- pureFnDependencies: [...comp.pureFnDependencies],
114
+ jitDependencies: comp.jitDependencies ? [...comp.jitDependencies] : void 0,
115
+ pureFnDependencies: comp.pureFnDependencies ? [...comp.pureFnDependencies] : void 0,
100
116
  ...comp.paramNames ? { paramNames: [...comp.paramNames] } : {}
101
117
  };
102
118
  }
@@ -1 +1 @@
1
- {"version":3,"file":"remoteMethods.cjs","sources":["../../../../src/lib/remoteMethods.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 RouterEntry, type Routes} from '../types/general.ts';\nimport {type RemoteMethod} from '../types/remoteMethods.ts';\nimport type {PublicApi} from '../types/publicMethods.ts';\nimport type {\n AnyObject,\n JitCompiledFn,\n JitCompiledFnData,\n PureFunctionData,\n MethodWithOptions,\n PureFnsDataCache,\n} from '@mionjs/core';\nimport {isRoute, isHeadersMiddleFnDef, isMiddleFnDef} from '../types/guards.ts';\nimport {getMiddleFnExecutable, getRouteExecutable, isPrivateDefinition} from '../router.ts';\nimport {getRouterItemId, MAX_STACK_DEPTH, getJitFnHashes, getJitUtils, EMPTY_HASH} from '@mionjs/core';\n\n// ############# PRIVATE STATE #############\nconst publicMethods: Map<string, MethodWithOptions> = new Map();\n\n// ############# PUBLIC METHODS #############\nexport function resetRemoteMethodsMetadata() {\n publicMethods.clear();\n}\n\n/**\n * Returns a data structure containing all public information and types of the routes.\n * This data and types can be used to generate router clients, etc...\n */\nexport function getPublicApi<R extends Routes>(routes: R): PublicApi<R> {\n return recursiveGetSerializableRoutes(routes) as PublicApi<R>;\n}\n\n// ############# PRIVATE METHODS #############\n\nfunction recursiveGetSerializableRoutes<R extends Routes>(\n routes: R,\n currentPointer: string[] = [],\n publicData: AnyObject = {}\n): AnyObject {\n const entries = Object.entries(routes);\n entries.forEach(([key, item]: [string, RouterEntry]) => {\n const itemPointer = [...currentPointer, key];\n const id = getRouterItemId(itemPointer);\n\n if (isPrivateDefinition(item, id)) {\n publicData[key] = null; // middleFns that don't receive or return data are not public\n } else if (isMiddleFnDef(item) || isHeadersMiddleFnDef(item) || isRoute(item)) {\n const executable = getMiddleFnExecutable(id) || getRouteExecutable(id);\n if (!executable)\n throw new Error(`Route or MiddleFn ${id} not found. Please check you have called router.registerRoutes first.`);\n publicData[key] = getSerializableMethod(executable as RemoteMethod);\n } else {\n const subRoutes: Routes = routes[key] as Routes;\n publicData[key] = recursiveGetSerializableRoutes(subRoutes, itemPointer);\n }\n });\n\n return publicData;\n}\n\nexport function getSerializableMethod(executable: RemoteMethod): MethodWithOptions {\n const existing = publicMethods.get(executable.id);\n if (existing) return existing as MethodWithOptions;\n\n const newRemoteMethod: MethodWithOptions = {\n type: executable.type,\n id: executable.id,\n nestLevel: executable.nestLevel,\n isAsync: executable.isAsync,\n hasReturnData: executable.hasReturnData,\n paramsJitHash: executable.paramsJitHash,\n returnJitHash: executable.returnJitHash,\n pointer: executable.pointer,\n ...(executable.paramNames ? {paramNames: executable.paramNames} : {}),\n options: executable.options,\n };\n if (executable.headersParam) newRemoteMethod.headersParam = executable.headersParam;\n if (executable.middleFnIds) newRemoteMethod.middleFnIds = executable.middleFnIds;\n publicMethods.set(executable.id, newRemoteMethod);\n return newRemoteMethod as MethodWithOptions;\n}\n\n/** Serializes pure function dependencies into a namespaced cache structure.\n * @param namespacedDepHash - Pure function dependency in format \"namespace::fnHash\"\n * @param purFnDeps - Namespaced cache to store serialized pure functions\n * @param depth - Current recursion depth for stack overflow protection\n */\nexport function serializePureDeps(namespacedDepHash: string, purFnDeps: PureFnsDataCache, depth = 0) {\n if (depth >= MAX_STACK_DEPTH)\n throw new Error(`Max depth reached serializing pure function dependencies, for: ${namespacedDepHash}`);\n // Parse \"namespace::fnHash\" format\n const parts = namespacedDepHash.split('::');\n if (parts.length !== 2)\n throw new Error(`Invalid pure function dependency format: ${namespacedDepHash}, expected \"namespace::fnHash\"`);\n const [namespace, fnHash] = parts;\n // Ensure namespace exists in the cache\n if (!purFnDeps[namespace]) purFnDeps[namespace] = {};\n // Check if already serialized (prevent infinite recursion on circular dependencies)\n if (purFnDeps[namespace][fnHash]) return;\n const pureDep = getJitUtils().getCompiledPureFn(namespace, fnHash);\n if (!pureDep) throw new Error(`Pure function ${fnHash} not found in namespace ${namespace}`);\n const serializedPureDep: PureFunctionData = {...pureDep, pureFnDependencies: [...pureDep.pureFnDependencies]};\n purFnDeps[namespace][fnHash] = serializedPureDep;\n // Dependencies within the same namespace are stored as just fnHash, not namespaced\n pureDep.pureFnDependencies.forEach((depFnHash) => serializePureDeps(`${namespace}::${depFnHash}`, purFnDeps, depth + 1));\n}\n\nexport function serializeJitFn(\n jitFnHash: string,\n deps: Record<string, JitCompiledFnData>,\n purFnDeps: PureFnsDataCache,\n depth = 0\n) {\n if (depth >= MAX_STACK_DEPTH)\n throw new Error(`Max depth reached serializing jit function dependencies for jitHash: ${jitFnHash}`);\n const jitFn = getJitUtils().getJIT(jitFnHash);\n if (!jitFn) throw new Error(`Jit function ${jitFnHash} not found`);\n if (deps[jitFnHash]) return; // already serialized and prevent infinite recursion on circular dependencies\n const serializedJitFn = getSerializableJitCompiler(jitFn);\n deps[jitFnHash] = serializedJitFn;\n jitFn.jitDependencies.forEach((h) => serializeJitFn(h, deps, purFnDeps, depth + 1));\n jitFn.pureFnDependencies.forEach((h) => serializePureDeps(h, purFnDeps));\n}\n\nexport function serializeMethodDeps(\n method: MethodWithOptions,\n deps: Record<string, JitCompiledFnData>,\n purFnDeps: PureFnsDataCache\n) {\n const {paramsJitHash, returnJitHash} = method;\n // Skip serialization for empty hashes (no params or void return)\n if (paramsJitHash !== EMPTY_HASH) {\n const paramsJitHashes = getJitFnHashes(paramsJitHash);\n for (const k in paramsJitHashes) serializeJitFn(paramsJitHashes[k], deps, purFnDeps);\n }\n if (returnJitHash !== EMPTY_HASH) {\n const returnJitHashes = getJitFnHashes(returnJitHash);\n for (const k in returnJitHashes) serializeJitFn(returnJitHashes[k], deps, purFnDeps);\n }\n}\n\nfunction getSerializableJitCompiler(comp: JitCompiledFn): JitCompiledFnData {\n return {\n typeName: comp.typeName,\n fnID: comp.fnID,\n jitFnHash: comp.jitFnHash,\n args: structuredClone(comp.args),\n isNoop: comp.isNoop,\n defaultParamValues: structuredClone(comp.defaultParamValues),\n code: comp.code,\n jitDependencies: [...comp.jitDependencies],\n pureFnDependencies: [...comp.pureFnDependencies],\n ...(comp.paramNames ? {paramNames: [...comp.paramNames]} : {}),\n };\n}\n"],"names":["getRouterItemId","isPrivateDefinition","isMiddleFnDef","isHeadersMiddleFnDef","isRoute","get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AACjE,MAAI,KAAK,SAAS,EAAG;AACrB,QAAM,kBAAkB,2BAA2B,KAAK;AACxD,OAAK,SAAS,IAAI;AAClB,QAAM,gBAAgB,QAAQ,CAAC,MAAM,eAAe,GAAG,MAAM,WAAW,QAAQ,CAAC,CAAC;AAClF,QAAM,mBAAmB,QAAQ,CAAC,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAC3E;AAEO,SAAS,oBACZ,QACA,MACA,WACF;AACE,QAAM,EAAC,eAAe,cAAA,IAAiB;AAEvC,MAAI,kBAAkBC,KAAAA,YAAY;AAC9B,UAAM,kBAAkBC,KAAAA,eAAe,aAAa;AACpD,eAAW,KAAK,gBAAiB,gBAAe,gBAAgB,CAAC,GAAG,MAAM,SAAS;AAAA,EACvF;AACA,MAAI,kBAAkBD,KAAAA,YAAY;AAC9B,UAAM,kBAAkBC,KAAAA,eAAe,aAAa;AACpD,eAAW,KAAK,gBAAiB,gBAAe,gBAAgB,CAAC,GAAG,MAAM,SAAS;AAAA,EACvF;AACJ;AAEA,SAAS,2BAA2B,MAAwC;AACxE,SAAO;AAAA,IACH,UAAU,KAAK;AAAA,IACf,MAAM,KAAK;AAAA,IACX,WAAW,KAAK;AAAA,IAChB,MAAM,gBAAgB,KAAK,IAAI;AAAA,IAC/B,QAAQ,KAAK;AAAA,IACb,oBAAoB,gBAAgB,KAAK,kBAAkB;AAAA,IAC3D,MAAM,KAAK;AAAA,IACX,iBAAiB,CAAC,GAAG,KAAK,eAAe;AAAA,IACzC,oBAAoB,CAAC,GAAG,KAAK,kBAAkB;AAAA,IAC/C,GAAI,KAAK,aAAa,EAAC,YAAY,CAAC,GAAG,KAAK,UAAU,MAAK,CAAA;AAAA,EAAC;AAEpE;;;;;;;"}
1
+ {"version":3,"file":"remoteMethods.cjs","sources":["../../../../src/lib/remoteMethods.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 RouterEntry, type Routes} from '../types/general.ts';\nimport {type RemoteMethod} from '../types/remoteMethods.ts';\nimport type {PublicApi} from '../types/publicMethods.ts';\nimport type {\n AnyObject,\n JitCompiledFn,\n JitCompiledFnData,\n PureFunctionData,\n MethodWithOptions,\n PureFnsDataCache,\n} from '@mionjs/core';\nimport {isRoute, isHeadersMiddleFnDef, isMiddleFnDef} from '../types/guards.ts';\nimport {getMiddleFnExecutable, getRouteExecutable, isPrivateDefinition} from '../router.ts';\nimport {getRouterItemId, MAX_STACK_DEPTH, getJitFnHashes, getJitUtils, EMPTY_HASH} from '@mionjs/core';\n\n// ############# PRIVATE STATE #############\nconst publicMethods: Map<string, MethodWithOptions> = new Map();\n\n// ############# PUBLIC METHODS #############\nexport function resetRemoteMethodsMetadata() {\n publicMethods.clear();\n}\n\n/**\n * Returns a data structure containing all public information and types of the routes.\n * This data and types can be used to generate router clients, etc...\n */\nexport function getPublicApi<R extends Routes>(routes: R): PublicApi<R> {\n return recursiveGetSerializableRoutes(routes) as PublicApi<R>;\n}\n\n// ############# PRIVATE METHODS #############\n\nfunction recursiveGetSerializableRoutes<R extends Routes>(\n routes: R,\n currentPointer: string[] = [],\n publicData: AnyObject = {}\n): AnyObject {\n const entries = Object.entries(routes);\n entries.forEach(([key, item]: [string, RouterEntry]) => {\n const itemPointer = [...currentPointer, key];\n const id = getRouterItemId(itemPointer);\n\n if (isPrivateDefinition(item, id)) {\n publicData[key] = null; // middleFns that don't receive or return data are not public\n } else if (isMiddleFnDef(item) || isHeadersMiddleFnDef(item) || isRoute(item)) {\n const executable = getMiddleFnExecutable(id) || getRouteExecutable(id);\n if (!executable)\n throw new Error(`Route or MiddleFn ${id} not found. Please check you have called router.registerRoutes first.`);\n publicData[key] = getSerializableMethod(executable as RemoteMethod);\n } else {\n const subRoutes: Routes = routes[key] as Routes;\n publicData[key] = recursiveGetSerializableRoutes(subRoutes, itemPointer);\n }\n });\n\n return publicData;\n}\n\nexport function getSerializableMethod(executable: RemoteMethod): MethodWithOptions {\n const existing = publicMethods.get(executable.id);\n if (existing) return existing as MethodWithOptions;\n\n const newRemoteMethod: MethodWithOptions = {\n type: executable.type,\n id: executable.id,\n nestLevel: executable.nestLevel,\n isAsync: executable.isAsync,\n hasReturnData: executable.hasReturnData,\n paramsJitHash: executable.paramsJitHash,\n returnJitHash: executable.returnJitHash,\n pointer: executable.pointer,\n ...(executable.paramNames ? {paramNames: executable.paramNames} : {}),\n options: executable.options,\n };\n if (executable.headersParam) newRemoteMethod.headersParam = executable.headersParam;\n if (executable.middleFnIds) newRemoteMethod.middleFnIds = executable.middleFnIds;\n publicMethods.set(executable.id, newRemoteMethod);\n return newRemoteMethod as MethodWithOptions;\n}\n\n/** Serializes pure function dependencies into a namespaced cache structure.\n * @param namespacedDepHash - Pure function dependency in format \"namespace::fnHash\"\n * @param purFnDeps - Namespaced cache to store serialized pure functions\n * @param depth - Current recursion depth for stack overflow protection\n */\nexport function serializePureDeps(namespacedDepHash: string, purFnDeps: PureFnsDataCache, depth = 0) {\n if (depth >= MAX_STACK_DEPTH)\n throw new Error(`Max depth reached serializing pure function dependencies, for: ${namespacedDepHash}`);\n // Parse \"namespace::fnHash\" format\n const parts = namespacedDepHash.split('::');\n if (parts.length !== 2)\n throw new Error(`Invalid pure function dependency format: ${namespacedDepHash}, expected \"namespace::fnHash\"`);\n const [namespace, fnHash] = parts;\n // Ensure namespace exists in the cache\n if (!purFnDeps[namespace]) purFnDeps[namespace] = {};\n // Check if already serialized (prevent infinite recursion on circular dependencies)\n if (purFnDeps[namespace][fnHash]) return;\n const pureDep = getJitUtils().getCompiledPureFn(namespace, fnHash);\n if (!pureDep) throw new Error(`Pure function ${fnHash} not found in namespace ${namespace}`);\n const serializedPureDep: PureFunctionData = {\n ...pureDep,\n pureFnDependencies: pureDep.pureFnDependencies ? [...pureDep.pureFnDependencies] : undefined,\n };\n purFnDeps[namespace][fnHash] = serializedPureDep;\n // Dependencies within the same namespace are stored as just fnHash, not namespaced\n pureDep.pureFnDependencies?.forEach((depFnHash) => serializePureDeps(`${namespace}::${depFnHash}`, purFnDeps, depth + 1));\n}\n\nexport function serializeJitFn(\n jitFnHash: string,\n deps: Record<string, JitCompiledFnData>,\n purFnDeps: PureFnsDataCache,\n depth = 0\n) {\n if (depth >= MAX_STACK_DEPTH)\n throw new Error(`Max depth reached serializing jit function dependencies for jitHash: ${jitFnHash}`);\n const jitFn = getJitUtils().getJIT(jitFnHash);\n if (!jitFn) throw new Error(`Jit function ${jitFnHash} not found`);\n if (deps[jitFnHash]) return; // already serialized and prevent infinite recursion on circular dependencies\n const serializedJitFn = getSerializableJitCompiler(jitFn);\n deps[jitFnHash] = serializedJitFn;\n jitFn.jitDependencies?.forEach((h) => serializeJitFn(h, deps, purFnDeps, depth + 1));\n jitFn.pureFnDependencies?.forEach((h) => serializePureDeps(h, purFnDeps));\n}\n\nexport function serializeMethodDeps(\n method: MethodWithOptions,\n deps: Record<string, JitCompiledFnData>,\n purFnDeps: PureFnsDataCache\n) {\n const {paramsJitHash, returnJitHash} = method;\n // Skip serialization for empty hashes (no params or void return)\n // Always request binary hashes so they are included when available (e.g. middleware in binary routes).\n // serializeJitFn is only called when the JIT function exists in the store, so non-binary methods are unaffected.\n if (paramsJitHash !== EMPTY_HASH) {\n const paramsJitHashes = getJitFnHashes(paramsJitHash, true);\n for (const k in paramsJitHashes) {\n if (getJitUtils().getJIT(paramsJitHashes[k])) serializeJitFn(paramsJitHashes[k], deps, purFnDeps);\n }\n }\n if (returnJitHash !== EMPTY_HASH) {\n const returnJitHashes = getJitFnHashes(returnJitHash, true);\n let foundAny = false;\n for (const k in returnJitHashes) {\n if (getJitUtils().getJIT(returnJitHashes[k])) {\n serializeJitFn(returnJitHashes[k], deps, purFnDeps);\n foundAny = true;\n }\n }\n if (!foundAny) {\n throw new Error(\n `Method \"${method.id}\" declares returnJitHash=\"${returnJitHash}\" but no JIT functions are registered under that hash. ` +\n `This usually means a Promise/Function return type was not unwrapped before computing the hash.`\n );\n }\n }\n}\n\nfunction getSerializableJitCompiler(comp: JitCompiledFn): JitCompiledFnData {\n return {\n typeName: comp.typeName,\n fnID: comp.fnID,\n jitFnHash: comp.jitFnHash,\n args: structuredClone(comp.args),\n isNoop: comp.isNoop,\n defaultParamValues: structuredClone(comp.defaultParamValues),\n code: comp.code,\n jitDependencies: comp.jitDependencies ? [...comp.jitDependencies] : undefined,\n pureFnDependencies: comp.pureFnDependencies ? [...comp.pureFnDependencies] : undefined,\n ...(comp.paramNames ? {paramNames: [...comp.paramNames]} : {}),\n };\n}\n"],"names":["getRouterItemId","isPrivateDefinition","isMiddleFnDef","isHeadersMiddleFnDef","isRoute","getMiddleFnExecutable","getRouteExecutable","MAX_STACK_DEPTH","getJitUtils","EMPTY_HASH","getJitFnHashes"],"mappings":";;;;;AAuBA,MAAM,oCAAoD,IAAA;AAGnD,SAAS,6BAA6B;AACzC,gBAAc,MAAA;AAClB;AAMO,SAAS,aAA+B,QAAyB;AACpE,SAAO,+BAA+B,MAAM;AAChD;AAIA,SAAS,+BACL,QACA,iBAA2B,CAAA,GAC3B,aAAwB,CAAA,GACf;AACT,QAAM,UAAU,OAAO,QAAQ,MAAM;AACrC,UAAQ,QAAQ,CAAC,CAAC,KAAK,IAAI,MAA6B;AACpD,UAAM,cAAc,CAAC,GAAG,gBAAgB,GAAG;AAC3C,UAAM,KAAKA,KAAAA,gBAAgB,WAAW;AAEtC,QAAIC,WAAAA,oBAAoB,MAAM,EAAE,GAAG;AAC/B,iBAAW,GAAG,IAAI;AAAA,IACtB,WAAWC,iBAAAA,cAAc,IAAI,KAAKC,iBAAAA,qBAAqB,IAAI,KAAKC,yBAAQ,IAAI,GAAG;AAC3E,YAAM,aAAaC,WAAAA,sBAAsB,EAAE,KAAKC,WAAAA,mBAAmB,EAAE;AACrE,UAAI,CAAC;AACD,cAAM,IAAI,MAAM,qBAAqB,EAAE,uEAAuE;AAClH,iBAAW,GAAG,IAAI,sBAAsB,UAA0B;AAAA,IACtE,OAAO;AACH,YAAM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