@mionjs/router 0.8.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dist/cjs/index.cjs +154 -0
- package/.dist/cjs/index.cjs.map +1 -0
- package/.dist/cjs/index.d.ts +19 -0
- package/.dist/cjs/package.json +1 -0
- package/.dist/cjs/src/callContext.cjs +125 -0
- package/.dist/cjs/src/callContext.cjs.map +1 -0
- package/.dist/cjs/src/callContext.d.ts +10 -0
- package/.dist/cjs/src/constants.cjs +45 -0
- package/.dist/cjs/src/constants.cjs.map +1 -0
- package/.dist/cjs/src/constants.d.ts +10 -0
- package/.dist/cjs/src/defaultRoutes.cjs +16 -0
- package/.dist/cjs/src/defaultRoutes.cjs.map +1 -0
- package/.dist/cjs/src/defaultRoutes.d.ts +3 -0
- package/.dist/cjs/src/dispatch.cjs +141 -0
- package/.dist/cjs/src/dispatch.cjs.map +1 -0
- package/.dist/cjs/src/dispatch.d.ts +3 -0
- package/.dist/cjs/src/lib/aotCacheLoader.cjs +13 -0
- package/.dist/cjs/src/lib/aotCacheLoader.cjs.map +1 -0
- package/.dist/cjs/src/lib/aotCacheLoader.d.ts +1 -0
- package/.dist/cjs/src/lib/aotEmitter.cjs +70 -0
- package/.dist/cjs/src/lib/aotEmitter.cjs.map +1 -0
- package/.dist/cjs/src/lib/aotEmitter.d.ts +17 -0
- package/.dist/cjs/src/lib/dispatchError.cjs +39 -0
- package/.dist/cjs/src/lib/dispatchError.cjs.map +1 -0
- package/.dist/cjs/src/lib/dispatchError.d.ts +5 -0
- package/.dist/cjs/src/lib/handlers.cjs +52 -0
- package/.dist/cjs/src/lib/handlers.cjs.map +1 -0
- package/.dist/cjs/src/lib/handlers.d.ts +9 -0
- package/.dist/cjs/src/lib/headers.cjs +64 -0
- package/.dist/cjs/src/lib/headers.cjs.map +1 -0
- package/.dist/cjs/src/lib/headers.d.ts +2 -0
- package/.dist/cjs/src/lib/methodsCache.cjs +55 -0
- package/.dist/cjs/src/lib/methodsCache.cjs.map +1 -0
- package/.dist/cjs/src/lib/methodsCache.d.ts +11 -0
- package/.dist/cjs/src/lib/queryBody.cjs +34 -0
- package/.dist/cjs/src/lib/queryBody.cjs.map +1 -0
- package/.dist/cjs/src/lib/queryBody.d.ts +7 -0
- package/.dist/cjs/src/lib/reflection.cjs +342 -0
- package/.dist/cjs/src/lib/reflection.cjs.map +1 -0
- package/.dist/cjs/src/lib/reflection.d.ts +12 -0
- package/.dist/cjs/src/lib/remoteMethods.cjs +109 -0
- package/.dist/cjs/src/lib/remoteMethods.cjs.map +1 -0
- package/.dist/cjs/src/lib/remoteMethods.d.ts +10 -0
- package/.dist/cjs/src/lib/test/aotEmitter-test-router.cjs +24 -0
- package/.dist/cjs/src/lib/test/aotEmitter-test-router.cjs.map +1 -0
- package/.dist/cjs/src/lib/test/aotEmitter-test-router.d.ts +4 -0
- package/.dist/cjs/src/router.cjs +429 -0
- package/.dist/cjs/src/router.cjs.map +1 -0
- package/.dist/cjs/src/router.d.ts +30 -0
- package/.dist/cjs/src/routes/client.routes.cjs +76 -0
- package/.dist/cjs/src/routes/client.routes.cjs.map +1 -0
- package/.dist/cjs/src/routes/client.routes.d.ts +16 -0
- package/.dist/cjs/src/routes/errors.routes.cjs +49 -0
- package/.dist/cjs/src/routes/errors.routes.cjs.map +1 -0
- package/.dist/cjs/src/routes/errors.routes.d.ts +7 -0
- package/.dist/cjs/src/routes/mion.routes.cjs +13 -0
- package/.dist/cjs/src/routes/mion.routes.cjs.map +1 -0
- package/.dist/cjs/src/routes/mion.routes.d.ts +10 -0
- package/.dist/cjs/src/routes/serializer.routes.cjs +191 -0
- package/.dist/cjs/src/routes/serializer.routes.cjs.map +1 -0
- package/.dist/cjs/src/routes/serializer.routes.d.ts +9 -0
- package/.dist/cjs/src/routesFlow.cjs +227 -0
- package/.dist/cjs/src/routesFlow.cjs.map +1 -0
- package/.dist/cjs/src/routesFlow.d.ts +7 -0
- package/.dist/cjs/src/types/context.cjs +31 -0
- package/.dist/cjs/src/types/context.cjs.map +1 -0
- package/.dist/cjs/src/types/context.d.ts +57 -0
- package/.dist/cjs/src/types/definitions.cjs +15 -0
- package/.dist/cjs/src/types/definitions.cjs.map +1 -0
- package/.dist/cjs/src/types/definitions.d.ts +20 -0
- package/.dist/cjs/src/types/general.cjs +14 -0
- package/.dist/cjs/src/types/general.cjs.map +1 -0
- package/.dist/cjs/src/types/general.d.ts +27 -0
- package/.dist/cjs/src/types/guards.cjs +66 -0
- package/.dist/cjs/src/types/guards.cjs.map +1 -0
- package/.dist/cjs/src/types/guards.d.ts +17 -0
- package/.dist/cjs/src/types/handlers.cjs +13 -0
- package/.dist/cjs/src/types/handlers.cjs.map +1 -0
- package/.dist/cjs/src/types/handlers.d.ts +12 -0
- package/.dist/cjs/src/types/publicMethods.cjs +24 -0
- package/.dist/cjs/src/types/publicMethods.cjs.map +1 -0
- package/.dist/cjs/src/types/publicMethods.d.ts +45 -0
- package/.dist/cjs/src/types/remoteMethods.cjs +25 -0
- package/.dist/cjs/src/types/remoteMethods.cjs.map +1 -0
- package/.dist/cjs/src/types/remoteMethods.d.ts +44 -0
- package/.dist/esm/index.d.ts +19 -0
- package/.dist/esm/index.js +145 -0
- package/.dist/esm/index.js.map +1 -0
- package/.dist/esm/src/callContext.d.ts +10 -0
- package/.dist/esm/src/callContext.js +125 -0
- package/.dist/esm/src/callContext.js.map +1 -0
- package/.dist/esm/src/constants.d.ts +10 -0
- package/.dist/esm/src/constants.js +45 -0
- package/.dist/esm/src/constants.js.map +1 -0
- package/.dist/esm/src/defaultRoutes.d.ts +3 -0
- package/.dist/esm/src/defaultRoutes.js +16 -0
- package/.dist/esm/src/defaultRoutes.js.map +1 -0
- package/.dist/esm/src/dispatch.d.ts +3 -0
- package/.dist/esm/src/dispatch.js +141 -0
- package/.dist/esm/src/dispatch.js.map +1 -0
- package/.dist/esm/src/lib/aotCacheLoader.d.ts +1 -0
- package/.dist/esm/src/lib/aotCacheLoader.js +13 -0
- package/.dist/esm/src/lib/aotCacheLoader.js.map +1 -0
- package/.dist/esm/src/lib/aotEmitter.d.ts +17 -0
- package/.dist/esm/src/lib/aotEmitter.js +70 -0
- package/.dist/esm/src/lib/aotEmitter.js.map +1 -0
- package/.dist/esm/src/lib/dispatchError.d.ts +5 -0
- package/.dist/esm/src/lib/dispatchError.js +39 -0
- package/.dist/esm/src/lib/dispatchError.js.map +1 -0
- package/.dist/esm/src/lib/handlers.d.ts +9 -0
- package/.dist/esm/src/lib/handlers.js +52 -0
- package/.dist/esm/src/lib/handlers.js.map +1 -0
- package/.dist/esm/src/lib/headers.d.ts +2 -0
- package/.dist/esm/src/lib/headers.js +64 -0
- package/.dist/esm/src/lib/headers.js.map +1 -0
- package/.dist/esm/src/lib/methodsCache.d.ts +11 -0
- package/.dist/esm/src/lib/methodsCache.js +56 -0
- package/.dist/esm/src/lib/methodsCache.js.map +1 -0
- package/.dist/esm/src/lib/queryBody.d.ts +7 -0
- package/.dist/esm/src/lib/queryBody.js +34 -0
- package/.dist/esm/src/lib/queryBody.js.map +1 -0
- package/.dist/esm/src/lib/reflection.d.ts +12 -0
- package/.dist/esm/src/lib/reflection.js +320 -0
- package/.dist/esm/src/lib/reflection.js.map +1 -0
- package/.dist/esm/src/lib/remoteMethods.d.ts +10 -0
- package/.dist/esm/src/lib/remoteMethods.js +109 -0
- package/.dist/esm/src/lib/remoteMethods.js.map +1 -0
- package/.dist/esm/src/lib/test/aotEmitter-test-router.d.ts +4 -0
- package/.dist/esm/src/lib/test/aotEmitter-test-router.js +24 -0
- package/.dist/esm/src/lib/test/aotEmitter-test-router.js.map +1 -0
- package/.dist/esm/src/router.d.ts +30 -0
- package/.dist/esm/src/router.js +431 -0
- package/.dist/esm/src/router.js.map +1 -0
- package/.dist/esm/src/routes/client.routes.d.ts +16 -0
- package/.dist/esm/src/routes/client.routes.js +76 -0
- package/.dist/esm/src/routes/client.routes.js.map +1 -0
- package/.dist/esm/src/routes/errors.routes.d.ts +7 -0
- package/.dist/esm/src/routes/errors.routes.js +49 -0
- package/.dist/esm/src/routes/errors.routes.js.map +1 -0
- package/.dist/esm/src/routes/mion.routes.d.ts +10 -0
- package/.dist/esm/src/routes/mion.routes.js +13 -0
- package/.dist/esm/src/routes/mion.routes.js.map +1 -0
- package/.dist/esm/src/routes/serializer.routes.d.ts +9 -0
- package/.dist/esm/src/routes/serializer.routes.js +191 -0
- package/.dist/esm/src/routes/serializer.routes.js.map +1 -0
- package/.dist/esm/src/routesFlow.d.ts +7 -0
- package/.dist/esm/src/routesFlow.js +227 -0
- package/.dist/esm/src/routesFlow.js.map +1 -0
- package/.dist/esm/src/types/context.d.ts +57 -0
- package/.dist/esm/src/types/context.js +31 -0
- package/.dist/esm/src/types/context.js.map +1 -0
- package/.dist/esm/src/types/definitions.d.ts +20 -0
- package/.dist/esm/src/types/definitions.js +15 -0
- package/.dist/esm/src/types/definitions.js.map +1 -0
- package/.dist/esm/src/types/general.d.ts +27 -0
- package/.dist/esm/src/types/general.js +14 -0
- package/.dist/esm/src/types/general.js.map +1 -0
- package/.dist/esm/src/types/guards.d.ts +17 -0
- package/.dist/esm/src/types/guards.js +66 -0
- package/.dist/esm/src/types/guards.js.map +1 -0
- package/.dist/esm/src/types/handlers.d.ts +12 -0
- package/.dist/esm/src/types/handlers.js +13 -0
- package/.dist/esm/src/types/handlers.js.map +1 -0
- package/.dist/esm/src/types/publicMethods.d.ts +45 -0
- package/.dist/esm/src/types/publicMethods.js +24 -0
- package/.dist/esm/src/types/publicMethods.js.map +1 -0
- package/.dist/esm/src/types/remoteMethods.d.ts +44 -0
- package/.dist/esm/src/types/remoteMethods.js +25 -0
- package/.dist/esm/src/types/remoteMethods.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +34 -0
- package/package.json +67 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { __ΩHandler as ___Handler } from "../types/handlers.js";
|
|
2
|
+
import { __ΩRouterOptions as ___RouterOptions } from "../types/general.js";
|
|
3
|
+
import { DEFAULT_ROUTE_OPTIONS, HEADER_HOOK_DEFAULT_PARAMS, ROUTE_DEFAULT_PARAMS } from "../constants.js";
|
|
4
|
+
import { getJitFunctionsFromHash, EMPTY_HASH, getNoopJitFns, HeadersSubset } from "@mionjs/core";
|
|
5
|
+
import { getPersistedMethodMetadata } from "./methodsCache.js";
|
|
6
|
+
const __ΩOmit = ["T", "K", () => __ΩPick, () => __ΩExclude, "Omit", 'b!b"e!!e!!ge!"o$#o##w%y'];
|
|
7
|
+
const __ΩPick = ["T", "K", "Pick", 'l+e#!e"!fRb!b"Pde""N#!w#y'];
|
|
8
|
+
const __ΩExclude = ["T", "U", "Exclude", 'l6!Re$!RPe#!e$"qk#%QRb!b"Pde"!p)w#y'];
|
|
9
|
+
function __assignType(fn, args) {
|
|
10
|
+
fn.__type = args;
|
|
11
|
+
return fn;
|
|
12
|
+
}
|
|
13
|
+
const __ΩMethodReflect = [() => __ΩOmit, "MethodWithJitFns", "id", "type", "nestLevel", "pointer", "options", "MethodReflect", `"w"P.#.$.%.&.'Jo!#w(y`];
|
|
14
|
+
class AOTCacheError extends Error {
|
|
15
|
+
constructor(routeId, type = "route") {
|
|
16
|
+
const typeLabel = type === "rawMiddleFn" ? "Raw middleFn" : type === "middleFn" ? "MiddleFn" : "Route/middleFn";
|
|
17
|
+
super(`${typeLabel} "${routeId}" not found in AOT cache.
|
|
18
|
+
Regenerate AOT caches using 'mion-build-aot' command.`);
|
|
19
|
+
this.name = "AOTCacheError";
|
|
20
|
+
}
|
|
21
|
+
static __type = [() => Error, "routeId", "route", "middleFn", "rawMiddleFn", "type", () => "route", "constructor", "AOTCacheError", `P7!P&2"P.#.$.%J2&>'"0(5w)`];
|
|
22
|
+
}
|
|
23
|
+
const __ΩRunTypesModule = ["RunTypesModule", "!w!y"];
|
|
24
|
+
const __ΩRunTypesFunctions = [() => __ΩRunTypesModule, "JitFunctions", "JitFunctions", () => __ΩRunTypesModule, "reflectFunction", "reflectFunction", () => __ΩRunTypesModule, "isUnionRunType", "isUnionRunType", () => __ΩRunTypesModule, "isClassRunType", "isClassRunType", () => __ΩRunTypesModule, "isLiteralRunType", "isLiteralRunType", () => __ΩRunTypesModule, "isNeverRunType", "isNeverRunType", "RunTypesFunctions", `Pn!."f4#n$.%f4&n'.(f4)n*.+f4,n-..f4/n0.1f42Mw3y`];
|
|
25
|
+
let runTypesModule = null;
|
|
26
|
+
let runTypesLoadPromise = null;
|
|
27
|
+
async function loadRunTypesModule() {
|
|
28
|
+
if (runTypesModule)
|
|
29
|
+
return runTypesModule;
|
|
30
|
+
if (runTypesLoadPromise)
|
|
31
|
+
return runTypesLoadPromise;
|
|
32
|
+
runTypesLoadPromise = import("@mionjs/run-types").then(__assignType((module) => {
|
|
33
|
+
runTypesModule = {
|
|
34
|
+
JitFunctions: module.JitFunctions,
|
|
35
|
+
reflectFunction: module.reflectFunction,
|
|
36
|
+
isUnionRunType: module.isUnionRunType,
|
|
37
|
+
isClassRunType: module.isClassRunType,
|
|
38
|
+
isLiteralRunType: module.isLiteralRunType,
|
|
39
|
+
isNeverRunType: module.isNeverRunType
|
|
40
|
+
};
|
|
41
|
+
return runTypesModule;
|
|
42
|
+
}, ["module", "", 'P"2!"/"']));
|
|
43
|
+
return runTypesLoadPromise;
|
|
44
|
+
}
|
|
45
|
+
loadRunTypesModule.__type = [() => __ΩRunTypesFunctions, "loadRunTypesModule", 'Pn!`/"'];
|
|
46
|
+
function resetRunTypesCache() {
|
|
47
|
+
runTypesModule = null;
|
|
48
|
+
runTypesLoadPromise = null;
|
|
49
|
+
}
|
|
50
|
+
resetRunTypesCache.__type = ["resetRunTypesCache", "P$/!"];
|
|
51
|
+
function resetReflectionCaches() {
|
|
52
|
+
rawMiddleFnReflectionCache.clear();
|
|
53
|
+
}
|
|
54
|
+
resetReflectionCaches.__type = ["resetReflectionCaches", "P$/!"];
|
|
55
|
+
const rawMiddleFnReflectionCache = (Map.Ω = [["&"], [() => __ΩMethodReflect, "n!"]], /* @__PURE__ */ new Map());
|
|
56
|
+
function createRawMiddleFnReflection(isAsync, hasReturnData = false, paramNames = []) {
|
|
57
|
+
const cacheKey = `${isAsync}_${hasReturnData}_${paramNames.join(",")}`;
|
|
58
|
+
const cached = rawMiddleFnReflectionCache.get(cacheKey);
|
|
59
|
+
if (cached)
|
|
60
|
+
return cached;
|
|
61
|
+
const reflection = {
|
|
62
|
+
paramNames,
|
|
63
|
+
paramsJitFns: getNoopJitFns(),
|
|
64
|
+
returnJitFns: getNoopJitFns(),
|
|
65
|
+
paramsJitHash: EMPTY_HASH,
|
|
66
|
+
returnJitHash: EMPTY_HASH,
|
|
67
|
+
hasReturnData,
|
|
68
|
+
isAsync
|
|
69
|
+
};
|
|
70
|
+
rawMiddleFnReflectionCache.set(cacheKey, reflection);
|
|
71
|
+
return reflection;
|
|
72
|
+
}
|
|
73
|
+
createRawMiddleFnReflection.__type = ["isAsync", "hasReturnData", () => false, "paramNames", () => [], () => __ΩMethodReflect, "createRawMiddleFnReflection", `P)2!)2">#&F2$>%n&/'`];
|
|
74
|
+
const __ΩCachedMethodMetadata = ["MethodMetadata", () => __ΩMethodReflect, "_cachedReflection", "CachedMethodMetadata", 'P"w!Pn"4#8MKw$y'];
|
|
75
|
+
function extractReflectionFromCached(cached) {
|
|
76
|
+
if (cached._cachedReflection)
|
|
77
|
+
return cached._cachedReflection;
|
|
78
|
+
const reflectionItems = {
|
|
79
|
+
paramNames: cached.paramNames || [],
|
|
80
|
+
paramsJitFns: getJitFunctionsFromHash(cached.paramsJitHash),
|
|
81
|
+
returnJitFns: getJitFunctionsFromHash(cached.returnJitHash),
|
|
82
|
+
paramsJitHash: cached.paramsJitHash,
|
|
83
|
+
returnJitHash: cached.returnJitHash,
|
|
84
|
+
hasReturnData: cached.hasReturnData,
|
|
85
|
+
isAsync: cached.isAsync
|
|
86
|
+
};
|
|
87
|
+
if (cached.headersParam) {
|
|
88
|
+
reflectionItems.headersParam = {
|
|
89
|
+
headerNames: cached.headersParam.headerNames,
|
|
90
|
+
jitFns: getJitFunctionsFromHash(cached.headersParam.jitHash),
|
|
91
|
+
jitHash: cached.headersParam.jitHash
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
if (cached.headersReturn) {
|
|
95
|
+
reflectionItems.headersReturn = {
|
|
96
|
+
headerNames: cached.headersReturn.headerNames,
|
|
97
|
+
jitFns: getJitFunctionsFromHash(cached.headersReturn.jitHash),
|
|
98
|
+
jitHash: cached.headersReturn.jitHash
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
cached._cachedReflection = reflectionItems;
|
|
102
|
+
return reflectionItems;
|
|
103
|
+
}
|
|
104
|
+
extractReflectionFromCached.__type = [() => __ΩCachedMethodMetadata, "cached", () => __ΩMethodReflect, "extractReflectionFromCached", 'Pn!2"n#/$'];
|
|
105
|
+
async function getHandlerReflection(handler, routeId, routerOptions, isHeadersMiddleFn = false) {
|
|
106
|
+
const cached = getPersistedMethodMetadata(routeId);
|
|
107
|
+
if (cached)
|
|
108
|
+
return extractReflectionFromCached(cached);
|
|
109
|
+
if (routerOptions.aot)
|
|
110
|
+
throw new AOTCacheError(routeId, isHeadersMiddleFn ? "middleFn" : "route");
|
|
111
|
+
const rt = await loadRunTypesModule();
|
|
112
|
+
return generateHandlerReflection(handler, routeId, routerOptions, isHeadersMiddleFn, rt);
|
|
113
|
+
}
|
|
114
|
+
getHandlerReflection.__type = [() => ___Handler, "handler", "routeId", () => ___RouterOptions, "routerOptions", "isHeadersMiddleFn", () => false, () => __ΩMethodReflect, "getHandlerReflection", "Pn!2\"&2#n$2%)2&>'n(`/)"];
|
|
115
|
+
async function getRawMethodReflection(handler, routeId, routerOptions) {
|
|
116
|
+
const cached = getPersistedMethodMetadata(routeId);
|
|
117
|
+
if (cached)
|
|
118
|
+
return createRawMiddleFnReflection(cached.isAsync, cached.hasReturnData, cached.paramNames || []);
|
|
119
|
+
if (routerOptions.aot)
|
|
120
|
+
return createRawMiddleFnReflection(true);
|
|
121
|
+
const rt = await loadRunTypesModule();
|
|
122
|
+
return generateRawMethodReflection(handler, routeId, rt);
|
|
123
|
+
}
|
|
124
|
+
getRawMethodReflection.__type = [() => ___Handler, "handler", "routeId", () => ___RouterOptions, "routerOptions", () => __ΩMethodReflect, "getRawMethodReflection", "Pn!2\"&2#n$2%n&`/'"];
|
|
125
|
+
function generateHandlerReflection(handler, routeId, routerOptions, isHeadersMiddleFn, rt) {
|
|
126
|
+
const reflectionItems = {};
|
|
127
|
+
let handlerRunType;
|
|
128
|
+
const runTypeOptions = routerOptions?.runTypeOptions || DEFAULT_ROUTE_OPTIONS.runTypeOptions;
|
|
129
|
+
try {
|
|
130
|
+
handlerRunType = rt.reflectFunction(handler);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
throw new Error(`Can not get RunType of handler for route/middleFn "${routeId}." Error: ${error?.message}`);
|
|
133
|
+
}
|
|
134
|
+
const paramsSlice = isHeadersMiddleFn ? { start: HEADER_HOOK_DEFAULT_PARAMS.length } : { start: ROUTE_DEFAULT_PARAMS.length };
|
|
135
|
+
const paramsOpts = { ...runTypeOptions, paramsSlice };
|
|
136
|
+
try {
|
|
137
|
+
reflectionItems.paramNames = handlerRunType.getParameterNames(paramsOpts);
|
|
138
|
+
if (reflectionItems.paramNames.length === 0) {
|
|
139
|
+
reflectionItems.paramsJitHash = EMPTY_HASH;
|
|
140
|
+
reflectionItems.paramsJitFns = getNoopJitFns();
|
|
141
|
+
} else {
|
|
142
|
+
reflectionItems.paramsJitFns = getFunctionJitFns(handler, paramsOpts, rt, false);
|
|
143
|
+
reflectionItems.paramsJitHash = handlerRunType.getParameters().getJitHash(paramsOpts);
|
|
144
|
+
}
|
|
145
|
+
} catch (error) {
|
|
146
|
+
throw new Error(`Can not compile Jit Functions for Parameters of route/middleFn "${routeId}." Error: ${error?.message}`);
|
|
147
|
+
}
|
|
148
|
+
if (isHeadersMiddleFn) {
|
|
149
|
+
const headersRunType = getParamsHeadersRunType(handlerRunType, routeId, routerOptions, rt);
|
|
150
|
+
const headerNames = getHeaderNames(headersRunType, routeId, rt);
|
|
151
|
+
try {
|
|
152
|
+
const opts = {
|
|
153
|
+
...runTypeOptions,
|
|
154
|
+
paramsSlice: void 0
|
|
155
|
+
};
|
|
156
|
+
const jitFns = getTypeJitFunctions(headersRunType, opts, rt);
|
|
157
|
+
const jitHash = headersRunType.getJitHash(opts);
|
|
158
|
+
reflectionItems.headersParam = { headerNames, jitFns, jitHash };
|
|
159
|
+
} catch (error) {
|
|
160
|
+
throw new Error(`Can not compile Jit Functions for Headers of Headers MiddleFn "${routeId}." Error: ${error?.message}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const returnHeadersRunType = getReturnHeadersRunType(handlerRunType, rt);
|
|
164
|
+
if (returnHeadersRunType) {
|
|
165
|
+
const opts = {};
|
|
166
|
+
const headerNames = getHeaderNames(returnHeadersRunType, routeId, rt);
|
|
167
|
+
const jitFns = getFunctionJitFns(handler, opts, rt, true);
|
|
168
|
+
const jitHash = returnHeadersRunType.getJitHash(opts);
|
|
169
|
+
reflectionItems.headersReturn = { headerNames, jitFns, jitHash };
|
|
170
|
+
}
|
|
171
|
+
const returnOpts = runTypeOptions;
|
|
172
|
+
reflectionItems.hasReturnData = handlerRunType.hasReturnData();
|
|
173
|
+
try {
|
|
174
|
+
if (!reflectionItems.hasReturnData) {
|
|
175
|
+
reflectionItems.returnJitFns = getNoopJitFns();
|
|
176
|
+
reflectionItems.returnJitHash = EMPTY_HASH;
|
|
177
|
+
} else {
|
|
178
|
+
reflectionItems.returnJitFns = getFunctionJitFns(handler, returnOpts, rt, true);
|
|
179
|
+
reflectionItems.returnJitHash = handlerRunType.getReturnType().getJitHash(returnOpts);
|
|
180
|
+
}
|
|
181
|
+
} catch (error) {
|
|
182
|
+
throw new Error(`Can not get Jit Functions for Return of route/middleFn "${routeId}." Error: ${error?.message}`);
|
|
183
|
+
}
|
|
184
|
+
reflectionItems.isAsync = handlerRunType.isAsync();
|
|
185
|
+
return reflectionItems;
|
|
186
|
+
}
|
|
187
|
+
generateHandlerReflection.__type = [() => ___Handler, "handler", "routeId", () => ___RouterOptions, "routerOptions", "isHeadersMiddleFn", () => __ΩRunTypesFunctions, "rt", () => __ΩMethodReflect, "generateHandlerReflection", `Pn!2"&2#n$2%)2&n'2(n)/*`];
|
|
188
|
+
function generateRawMethodReflection(handler, routeId, rt) {
|
|
189
|
+
let handlerRunType;
|
|
190
|
+
try {
|
|
191
|
+
handlerRunType = rt.reflectFunction(handler);
|
|
192
|
+
} catch (error) {
|
|
193
|
+
throw new Error(`Can not get RunType of handler for route/middleFn "${routeId}." Error: ${error?.message}`);
|
|
194
|
+
}
|
|
195
|
+
const isAsync = handlerRunType?.isAsync() || true;
|
|
196
|
+
return createRawMiddleFnReflection(isAsync);
|
|
197
|
+
}
|
|
198
|
+
generateRawMethodReflection.__type = [() => ___Handler, "handler", "routeId", () => __ΩRunTypesFunctions, "rt", () => __ΩMethodReflect, "generateRawMethodReflection", `Pn!2"&2#n$2%n&/'`];
|
|
199
|
+
function getParamsHeadersRunType(handlerRunType, routeId, routerOptions, rt) {
|
|
200
|
+
const paramRunTypes = handlerRunType.getParameters().getParamRunTypes(getFakeCompiler(routerOptions));
|
|
201
|
+
const headersSubset = paramRunTypes[1]?.getMemberType?.();
|
|
202
|
+
if (!isHeaderSubSetRunType(headersSubset, rt)) {
|
|
203
|
+
throw new Error(`Headers MiddleFn '${routeId}' second parameter must be a HeadersSubset.`);
|
|
204
|
+
}
|
|
205
|
+
return headersSubset;
|
|
206
|
+
}
|
|
207
|
+
getParamsHeadersRunType.__type = ["FunctionRunType", "handlerRunType", "routeId", () => ___RouterOptions, "routerOptions", () => __ΩRunTypesFunctions, "rt", "BaseRunType", "getParamsHeadersRunType", `P"w!2"&2#n$2%n&2'"w(/)`];
|
|
208
|
+
function getReturnHeadersRunType(handlerRunType, rt) {
|
|
209
|
+
const returnRunType = handlerRunType.getReturnType();
|
|
210
|
+
if (rt.isUnionRunType(returnRunType)) {
|
|
211
|
+
const headersSubset = returnRunType.getChildRunTypes().find(__assignType((child) => isHeaderSubSetRunType(child, rt), ["child", "", 'P"2!"/"']));
|
|
212
|
+
if (!headersSubset)
|
|
213
|
+
return void 0;
|
|
214
|
+
return headersSubset;
|
|
215
|
+
}
|
|
216
|
+
if (!isHeaderSubSetRunType(returnRunType, rt))
|
|
217
|
+
return void 0;
|
|
218
|
+
return returnRunType;
|
|
219
|
+
}
|
|
220
|
+
getReturnHeadersRunType.__type = ["FunctionRunType", "handlerRunType", () => __ΩRunTypesFunctions, "rt", "BaseRunType", "getReturnHeadersRunType", 'P"w!2"n#2$P"w%-J/&'];
|
|
221
|
+
function isHeaderSubSetRunType(runType, rt) {
|
|
222
|
+
if (!runType)
|
|
223
|
+
return false;
|
|
224
|
+
return rt.isClassRunType(runType, HeadersSubset);
|
|
225
|
+
}
|
|
226
|
+
isHeaderSubSetRunType.__type = ["BaseRunType", "runType", () => __ΩRunTypesFunctions, "rt", "isHeaderSubSetRunType", 'PP"w!-J2"n#2$!/%'];
|
|
227
|
+
function getHeaderNames(runType, routeId, rt) {
|
|
228
|
+
const typeArguments = runType.src.typeArguments;
|
|
229
|
+
if (!typeArguments || typeArguments.length === 0) {
|
|
230
|
+
throw new Error(`HeadersSubset must have type arguments in route/middleFn ${routeId}`);
|
|
231
|
+
}
|
|
232
|
+
const headerNames = [];
|
|
233
|
+
const requiredArg = typeArguments[0];
|
|
234
|
+
if (requiredArg) {
|
|
235
|
+
const requiredNames = extractLiteralStringsFromType(requiredArg._rt, rt);
|
|
236
|
+
headerNames.push(...requiredNames);
|
|
237
|
+
}
|
|
238
|
+
if (typeArguments.length > 1) {
|
|
239
|
+
const optionalArg = typeArguments[1];
|
|
240
|
+
if (optionalArg) {
|
|
241
|
+
const optionalNames = extractLiteralStringsFromType(optionalArg._rt, rt);
|
|
242
|
+
headerNames.push(...optionalNames);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (headerNames.length === 0)
|
|
246
|
+
throw new Error(`Header names array cannot be empty in route/middleFn ${routeId}`);
|
|
247
|
+
return headerNames;
|
|
248
|
+
}
|
|
249
|
+
getHeaderNames.__type = ["BaseRunType", "runType", "routeId", () => __ΩRunTypesFunctions, "rt", "getHeaderNames", 'P"w!2"&2#n$2%&F/&'];
|
|
250
|
+
function extractLiteralStringsFromTypeRecursive(runType, rt) {
|
|
251
|
+
if (rt.isLiteralRunType(runType)) {
|
|
252
|
+
const literal = runType.getLiteralValue();
|
|
253
|
+
if (typeof literal === "string") {
|
|
254
|
+
return [literal];
|
|
255
|
+
}
|
|
256
|
+
return [];
|
|
257
|
+
}
|
|
258
|
+
if (rt.isUnionRunType(runType)) {
|
|
259
|
+
const children = runType.getChildRunTypes();
|
|
260
|
+
const literals = [];
|
|
261
|
+
for (const child of children) {
|
|
262
|
+
const childLiterals = extractLiteralStringsFromTypeRecursive(child, rt);
|
|
263
|
+
literals.push(...childLiterals);
|
|
264
|
+
}
|
|
265
|
+
return literals;
|
|
266
|
+
}
|
|
267
|
+
return [];
|
|
268
|
+
}
|
|
269
|
+
extractLiteralStringsFromTypeRecursive.__type = ["BaseRunType", "runType", () => __ΩRunTypesFunctions, "rt", "extractLiteralStringsFromTypeRecursive", 'P"w!2"n#2$&F/%'];
|
|
270
|
+
function extractLiteralStringsFromType(runType, rt) {
|
|
271
|
+
if (rt.isNeverRunType(runType))
|
|
272
|
+
return [];
|
|
273
|
+
return extractLiteralStringsFromTypeRecursive(runType, rt);
|
|
274
|
+
}
|
|
275
|
+
extractLiteralStringsFromType.__type = ["BaseRunType", "runType", () => __ΩRunTypesFunctions, "rt", "extractLiteralStringsFromType", 'P"w!2"n#2$&F/%'];
|
|
276
|
+
function getFakeCompiler(routerOptions) {
|
|
277
|
+
return { opts: routerOptions };
|
|
278
|
+
}
|
|
279
|
+
getFakeCompiler.__type = [() => ___RouterOptions, "routerOptions", "JitFnCompiler", "getFakeCompiler", 'Pn!2""w#/$'];
|
|
280
|
+
function getTypeJitFunctions(runType, opts, rtModule) {
|
|
281
|
+
const jitFns = {
|
|
282
|
+
isType: runType.createJitCompiledFunction(rtModule.JitFunctions.isType.id, void 0, opts),
|
|
283
|
+
typeErrors: runType.createJitCompiledFunction(rtModule.JitFunctions.typeErrors.id, void 0, opts),
|
|
284
|
+
prepareForJson: runType.createJitCompiledFunction(rtModule.JitFunctions.prepareForJson.id, void 0, opts),
|
|
285
|
+
restoreFromJson: runType.createJitCompiledFunction(rtModule.JitFunctions.restoreFromJson.id, void 0, opts),
|
|
286
|
+
stringifyJson: runType.createJitCompiledFunction(rtModule.JitFunctions.stringifyJson.id, void 0, opts),
|
|
287
|
+
toBinary: runType.createJitCompiledFunction(rtModule.JitFunctions.toBinary.id, void 0, opts),
|
|
288
|
+
fromBinary: runType.createJitCompiledFunction(rtModule.JitFunctions.fromBinary.id, void 0, opts)
|
|
289
|
+
};
|
|
290
|
+
return jitFns;
|
|
291
|
+
}
|
|
292
|
+
getTypeJitFunctions.__type = ["BaseRunType", "runType", "RunTypeOptions", "opts", () => __ΩRunTypesFunctions, "rtModule", "JitCompiledFunctions", "getTypeJitFunctions", `P"w!2"P"w#-J2$n%2&"w'/(`];
|
|
293
|
+
const functionRunTypeCache = (WeakMap.Ω = [["AnyFn", '"w!'], ["FunctionRunType", '"w!']], /* @__PURE__ */ new WeakMap());
|
|
294
|
+
function getFunctionJitFns(fn, opts, rtModule, isReturn) {
|
|
295
|
+
let runType = functionRunTypeCache.get(fn);
|
|
296
|
+
if (!runType) {
|
|
297
|
+
runType = rtModule.reflectFunction(fn);
|
|
298
|
+
functionRunTypeCache.set(fn, runType);
|
|
299
|
+
}
|
|
300
|
+
const createFn = isReturn ? runType.createJitCompiledReturnFunction.bind(runType) : runType.createJitCompiledParamsFunction.bind(runType);
|
|
301
|
+
const jitFunctions = {
|
|
302
|
+
isType: createFn(rtModule.JitFunctions.isType, opts),
|
|
303
|
+
typeErrors: createFn(rtModule.JitFunctions.typeErrors, opts),
|
|
304
|
+
prepareForJson: createFn(rtModule.JitFunctions.prepareForJson, opts),
|
|
305
|
+
restoreFromJson: createFn(rtModule.JitFunctions.restoreFromJson, opts),
|
|
306
|
+
stringifyJson: createFn(rtModule.JitFunctions.stringifyJson, opts),
|
|
307
|
+
toBinary: createFn(rtModule.JitFunctions.toBinary, opts),
|
|
308
|
+
fromBinary: createFn(rtModule.JitFunctions.fromBinary, opts)
|
|
309
|
+
};
|
|
310
|
+
return jitFunctions;
|
|
311
|
+
}
|
|
312
|
+
getFunctionJitFns.__type = ["fn", "RunTypeOptions", "opts", () => __ΩRunTypesFunctions, "rtModule", "isReturn", "JitCompiledFunctions", "getFunctionJitFns", `P"2!P"w"-J2#n$2%)2&"w'/(`];
|
|
313
|
+
export {
|
|
314
|
+
AOTCacheError,
|
|
315
|
+
getHandlerReflection,
|
|
316
|
+
getRawMethodReflection,
|
|
317
|
+
resetReflectionCaches,
|
|
318
|
+
resetRunTypesCache
|
|
319
|
+
};
|
|
320
|
+
//# sourceMappingURL=reflection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reflection.js","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): 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);\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): MethodReflect {\n const reflectionItems: Partial<MethodReflect> = {};\n let handlerRunType: FunctionRunType;\n const runTypeOptions = routerOptions?.runTypeOptions || DEFAULT_ROUTE_OPTIONS.runTypeOptions;\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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AAA,CAAA,CAAA,SAAA,KAAA,GAAA,CAAA,mBAAA,KAAA,CAAA,uBAAP,QAAA;AAEjC,SAAS,kBACL,IACA,MACA,UACA,UAAiB;AAGjB,MAAI,UAAU,qBAAqB,IAAI,EAAE;AACzC,MAAI,CAAC,SAAS;AACV,cAAU,SAAS,gBAAgB,EAAE;AACrC,yBAAqB,IAAI,IAAI,OAAO;AAAA,EACxC;AAEA,QAAM,WAAW,WACX,QAAQ,gCAAgC,KAAK,OAAO,IACpD,QAAQ,gCAAgC,KAAK,OAAO;AAC1D,QAAM,eAAqC;AAAA,IACvC,QAAQ,SAAS,SAAS,aAAa,QAAQ,IAAI;AAAA,IACnD,YAAY,SAAS,SAAS,aAAa,YAAY,IAAI;AAAA,IAC3D,gBAAgB,SAAS,SAAS,aAAa,gBAAgB,IAAI;AAAA,IACnE,iBAAiB,SAAS,SAAS,aAAa,iBAAiB,IAAI;AAAA,IACrE,eAAe,SAAS,SAAS,aAAa,eAAe,IAAI;AAAA,IACjE,UAAU,SAAS,SAAS,aAAa,UAAU,IAAI;AAAA,IACvD,YAAY,SAAS,SAAS,aAAa,YAAY,IAAI;AAAA,EAAA;AAE/D,SAAO;AACX;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Routes } from '../types/general.ts';
|
|
2
|
+
import { RemoteMethod } from '../types/remoteMethods.ts';
|
|
3
|
+
import { PublicApi } from '../types/publicMethods.ts';
|
|
4
|
+
import { JitCompiledFnData, MethodWithOptions, PureFnsDataCache } from '@mionjs/core';
|
|
5
|
+
export declare function resetRemoteMethodsMetadata(): void;
|
|
6
|
+
export declare function getPublicApi<R extends Routes>(routes: R): PublicApi<R>;
|
|
7
|
+
export declare function getSerializableMethod(executable: RemoteMethod): MethodWithOptions;
|
|
8
|
+
export declare function serializePureDeps(namespacedDepHash: string, purFnDeps: PureFnsDataCache, depth?: number): void;
|
|
9
|
+
export declare function serializeJitFn(jitFnHash: string, deps: Record<string, JitCompiledFnData>, purFnDeps: PureFnsDataCache, depth?: number): void;
|
|
10
|
+
export declare function serializeMethodDeps(method: MethodWithOptions, deps: Record<string, JitCompiledFnData>, purFnDeps: PureFnsDataCache): void;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { isMiddleFnDef, isHeadersMiddleFnDef, isRoute } from "../types/guards.js";
|
|
2
|
+
import { isPrivateDefinition, getMiddleFnExecutable, getRouteExecutable } from "../router.js";
|
|
3
|
+
import { MAX_STACK_DEPTH, getJitUtils, EMPTY_HASH, getJitFnHashes, getRouterItemId } from "@mionjs/core";
|
|
4
|
+
const publicMethods = /* @__PURE__ */ new Map();
|
|
5
|
+
function resetRemoteMethodsMetadata() {
|
|
6
|
+
publicMethods.clear();
|
|
7
|
+
}
|
|
8
|
+
function getPublicApi(routes) {
|
|
9
|
+
return recursiveGetSerializableRoutes(routes);
|
|
10
|
+
}
|
|
11
|
+
function recursiveGetSerializableRoutes(routes, currentPointer = [], publicData = {}) {
|
|
12
|
+
const entries = Object.entries(routes);
|
|
13
|
+
entries.forEach(([key, item]) => {
|
|
14
|
+
const itemPointer = [...currentPointer, key];
|
|
15
|
+
const id = getRouterItemId(itemPointer);
|
|
16
|
+
if (isPrivateDefinition(item, id)) {
|
|
17
|
+
publicData[key] = null;
|
|
18
|
+
} else if (isMiddleFnDef(item) || isHeadersMiddleFnDef(item) || isRoute(item)) {
|
|
19
|
+
const executable = getMiddleFnExecutable(id) || getRouteExecutable(id);
|
|
20
|
+
if (!executable)
|
|
21
|
+
throw new Error(`Route or MiddleFn ${id} not found. Please check you have called router.registerRoutes first.`);
|
|
22
|
+
publicData[key] = getSerializableMethod(executable);
|
|
23
|
+
} else {
|
|
24
|
+
const subRoutes = routes[key];
|
|
25
|
+
publicData[key] = recursiveGetSerializableRoutes(subRoutes, itemPointer);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return publicData;
|
|
29
|
+
}
|
|
30
|
+
function getSerializableMethod(executable) {
|
|
31
|
+
const existing = publicMethods.get(executable.id);
|
|
32
|
+
if (existing) return existing;
|
|
33
|
+
const newRemoteMethod = {
|
|
34
|
+
type: executable.type,
|
|
35
|
+
id: executable.id,
|
|
36
|
+
nestLevel: executable.nestLevel,
|
|
37
|
+
isAsync: executable.isAsync,
|
|
38
|
+
hasReturnData: executable.hasReturnData,
|
|
39
|
+
paramsJitHash: executable.paramsJitHash,
|
|
40
|
+
returnJitHash: executable.returnJitHash,
|
|
41
|
+
pointer: executable.pointer,
|
|
42
|
+
...executable.paramNames ? { paramNames: executable.paramNames } : {},
|
|
43
|
+
options: executable.options
|
|
44
|
+
};
|
|
45
|
+
if (executable.headersParam) newRemoteMethod.headersParam = executable.headersParam;
|
|
46
|
+
if (executable.middleFnIds) newRemoteMethod.middleFnIds = executable.middleFnIds;
|
|
47
|
+
publicMethods.set(executable.id, newRemoteMethod);
|
|
48
|
+
return newRemoteMethod;
|
|
49
|
+
}
|
|
50
|
+
function serializePureDeps(namespacedDepHash, purFnDeps, depth = 0) {
|
|
51
|
+
if (depth >= MAX_STACK_DEPTH)
|
|
52
|
+
throw new Error(`Max depth reached serializing pure function dependencies, for: ${namespacedDepHash}`);
|
|
53
|
+
const parts = namespacedDepHash.split("::");
|
|
54
|
+
if (parts.length !== 2)
|
|
55
|
+
throw new Error(`Invalid pure function dependency format: ${namespacedDepHash}, expected "namespace::fnHash"`);
|
|
56
|
+
const [namespace, fnHash] = parts;
|
|
57
|
+
if (!purFnDeps[namespace]) purFnDeps[namespace] = {};
|
|
58
|
+
if (purFnDeps[namespace][fnHash]) return;
|
|
59
|
+
const pureDep = getJitUtils().getCompiledPureFn(namespace, fnHash);
|
|
60
|
+
if (!pureDep) throw new Error(`Pure function ${fnHash} not found in namespace ${namespace}`);
|
|
61
|
+
const serializedPureDep = { ...pureDep, pureFnDependencies: [...pureDep.pureFnDependencies] };
|
|
62
|
+
purFnDeps[namespace][fnHash] = serializedPureDep;
|
|
63
|
+
pureDep.pureFnDependencies.forEach((depFnHash) => serializePureDeps(`${namespace}::${depFnHash}`, purFnDeps, depth + 1));
|
|
64
|
+
}
|
|
65
|
+
function serializeJitFn(jitFnHash, deps, purFnDeps, depth = 0) {
|
|
66
|
+
if (depth >= MAX_STACK_DEPTH)
|
|
67
|
+
throw new Error(`Max depth reached serializing jit function dependencies for jitHash: ${jitFnHash}`);
|
|
68
|
+
const jitFn = getJitUtils().getJIT(jitFnHash);
|
|
69
|
+
if (!jitFn) throw new Error(`Jit function ${jitFnHash} not found`);
|
|
70
|
+
if (deps[jitFnHash]) return;
|
|
71
|
+
const serializedJitFn = getSerializableJitCompiler(jitFn);
|
|
72
|
+
deps[jitFnHash] = serializedJitFn;
|
|
73
|
+
jitFn.jitDependencies.forEach((h) => serializeJitFn(h, deps, purFnDeps, depth + 1));
|
|
74
|
+
jitFn.pureFnDependencies.forEach((h) => serializePureDeps(h, purFnDeps));
|
|
75
|
+
}
|
|
76
|
+
function serializeMethodDeps(method, deps, purFnDeps) {
|
|
77
|
+
const { paramsJitHash, returnJitHash } = method;
|
|
78
|
+
if (paramsJitHash !== EMPTY_HASH) {
|
|
79
|
+
const paramsJitHashes = getJitFnHashes(paramsJitHash);
|
|
80
|
+
for (const k in paramsJitHashes) serializeJitFn(paramsJitHashes[k], deps, purFnDeps);
|
|
81
|
+
}
|
|
82
|
+
if (returnJitHash !== EMPTY_HASH) {
|
|
83
|
+
const returnJitHashes = getJitFnHashes(returnJitHash);
|
|
84
|
+
for (const k in returnJitHashes) serializeJitFn(returnJitHashes[k], deps, purFnDeps);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function getSerializableJitCompiler(comp) {
|
|
88
|
+
return {
|
|
89
|
+
typeName: comp.typeName,
|
|
90
|
+
fnID: comp.fnID,
|
|
91
|
+
jitFnHash: comp.jitFnHash,
|
|
92
|
+
args: structuredClone(comp.args),
|
|
93
|
+
isNoop: comp.isNoop,
|
|
94
|
+
defaultParamValues: structuredClone(comp.defaultParamValues),
|
|
95
|
+
code: comp.code,
|
|
96
|
+
jitDependencies: [...comp.jitDependencies],
|
|
97
|
+
pureFnDependencies: [...comp.pureFnDependencies],
|
|
98
|
+
...comp.paramNames ? { paramNames: [...comp.paramNames] } : {}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
export {
|
|
102
|
+
getPublicApi,
|
|
103
|
+
getSerializableMethod,
|
|
104
|
+
resetRemoteMethodsMetadata,
|
|
105
|
+
serializeJitFn,
|
|
106
|
+
serializeMethodDeps,
|
|
107
|
+
serializePureDeps
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=remoteMethods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remoteMethods.js","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":[],"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,KAAK,gBAAgB,WAAW;AAEtC,QAAI,oBAAoB,MAAM,EAAE,GAAG;AAC/B,iBAAW,GAAG,IAAI;AAAA,IACtB,WAAW,cAAc,IAAI,KAAK,qBAAqB,IAAI,KAAK,QAAQ,IAAI,GAAG;AAC3E,YAAM,aAAa,sBAAsB,EAAE,KAAK,mBAAmB,EAAE;AACrE,UAAI,CAAC;AACD,cAAM,IAAI,MAAM,qBAAqB,EAAE,uEAAuE;AAClH,iBAAW,GAAG,IAAI,sBAAsB,UAA0B;AAAA,IACtE,OAAO;AACH,YAAM,YAAoB,OAAO,GAAG;AACpC,iBAAW,GAAG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B,CAAC,GAAG,KAAK,kBAAkB;AAAA,IAC/C,GAAI,KAAK,aAAa,EAAC,YAAY,CAAC,GAAG,KAAK,UAAU,MAAK,CAAA;AAAA,EAAC;AAEpE;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { middleFn, route, initMionRouter } from "@mionjs/router";
|
|
2
|
+
function __assignType(fn, args) {
|
|
3
|
+
fn.__type = args;
|
|
4
|
+
return fn;
|
|
5
|
+
}
|
|
6
|
+
const __ΩUser = ["id", "name", "User", 'P&4!&4"Mw#y'];
|
|
7
|
+
const routes = {
|
|
8
|
+
users: {
|
|
9
|
+
getUser: route(__assignType((ctx, id) => ({ id, name: "Test User" }), ["ctx", "id", () => __ΩUser, "", 'P"2!&2"n#/$'])),
|
|
10
|
+
createUser: route(__assignType((ctx, user) => `Created user ${user.name}`, ["ctx", () => __ΩUser, "user", "", 'P"2!n"2#&/$']))
|
|
11
|
+
},
|
|
12
|
+
utils: {
|
|
13
|
+
sum: route(__assignType((ctx, a, b) => a + b, ["ctx", "a", "b", "", `P"2!'2"'2#'/$`]))
|
|
14
|
+
},
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
+
log: middleFn(__assignType((ctx) => {
|
|
17
|
+
}, ["ctx", "", 'P"2!$/"']))
|
|
18
|
+
};
|
|
19
|
+
const testApiPromise = initMionRouter(routes, { basePath: "api/v1" });
|
|
20
|
+
export {
|
|
21
|
+
routes,
|
|
22
|
+
testApiPromise
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=aotEmitter-test-router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aotEmitter-test-router.js","sources":["../../../../../src/lib/test/aotEmitter-test-router.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 * Test router script for AOT emitter tests.\n * This script is spawned as a child process with MION_COMPILE=true\n * to test that emitAOTCaches() correctly sends IPC messages.\n *\n * Uses initMionRouter which automatically calls emitAOTCaches() when MION_COMPILE=true.\n */\n\nimport {initMionRouter, route, middleFn, Routes, PublicApi} from '@mionjs/router';\n\ninterface User {\n id: string;\n name: string;\n}\n\nconst routes = {\n users: {\n getUser: route((ctx, id: string): User => ({id, name: 'Test User'})),\n createUser: route((ctx, user: User): string => `Created user ${user.name}`),\n },\n utils: {\n sum: route((ctx, a: number, b: number): number => a + b),\n },\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n log: middleFn((ctx): void => {\n // Log middleFn\n }),\n} satisfies Routes;\n\n// Initialize the router - this will call emitAOTCaches() automatically when MION_COMPILE=true\nexport const testApiPromise: Promise<PublicApi<typeof routes>> = initMionRouter(routes, {basePath: 'api/v1'});\n\nexport {routes};\n"],"names":[],"mappings":";;;;;;AAsBA,MAAM,SAAS;AAAA,EACX,OAAO;AAAA,IACH,SAAS,MAAK,aAAC,CAAC,KAAK,QAAsB,EAAC,IAAI,MAAM,gBAAa,CAAA,OAAA,MAAA,MAAA,SAAA,IAAA,aAAA,CAAA,CAAA;AAAA,IACnE,YAAY,MAAK,aAAC,CAAC,KAAK,SAAuB,gBAAgB,KAAK,IAAI,IAAE,CAAA,OAAA,MAAA,SAAA,QAAA,IAAA,aAAA,CAAA,CAAA;AAAA,EAAA;AAAA,EAE9E,OAAO;AAAA,IACH,KAAK,MAAK,aAAC,CAAC,KAAK,GAAW,MAAsB,IAAI,GAAC,CAAA,OAAA,KAAA,KAAA,IAAA,eAAA,CAAA,CAAA;AAAA,EAAA;AAAA;AAAA,EAG3D,KAAK,SAAQ,aAAC,CAAC,QAAa;AAAA,EAE5B,GAAC,CAAA,OAAA,IAAA,SAAA,CAAA,CAAA;;AAIE,MAAM,iBAAoD,eAAe,QAAQ,EAAC,UAAU,UAAS;"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Route, RouterOptions, Routes, RouterEntry } from './types/general.ts';
|
|
2
|
+
import { RemoteMethod, MethodsExecutionChain, RawMethod, HeadersMethod, MiddleFnMethod, RouteMethod } from './types/remoteMethods.ts';
|
|
3
|
+
import { PublicApi, PrivateDef, MiddleFnsCollection } from './types/publicMethods.ts';
|
|
4
|
+
import { HeadersMiddleFnDef, MiddleFnDef, RawMiddleFnDef } from './types/definitions.ts';
|
|
5
|
+
export declare let startMiddleFns: RemoteMethod[];
|
|
6
|
+
export declare let endMiddleFns: RemoteMethod[];
|
|
7
|
+
export declare const getRouteExecutionChain: (path: string) => MethodsExecutionChain | undefined;
|
|
8
|
+
export declare const getRouteEntries: () => MapIterator<[string, MethodsExecutionChain]>;
|
|
9
|
+
export declare const geRoutesSize: () => number;
|
|
10
|
+
export declare const getRouteExecutable: (id: string) => RouteMethod<any> | undefined;
|
|
11
|
+
export declare const getMiddleFnExecutable: (id: string) => MiddleFnMethod<any> | HeadersMethod<any> | RawMethod<any> | undefined;
|
|
12
|
+
export declare const geMiddleFnsSize: () => number;
|
|
13
|
+
export declare const getComplexity: () => number;
|
|
14
|
+
export declare const getRouterOptions: <Opts extends RouterOptions>() => Readonly<Opts>;
|
|
15
|
+
export declare const getAnyExecutable: (id: string) => RouteMethod<any> | MiddleFnMethod<any> | HeadersMethod<any> | RawMethod<any> | undefined;
|
|
16
|
+
export declare const resetRouter: () => void;
|
|
17
|
+
export declare function initMionRouter<R extends Routes>(routes: R, opts?: Partial<RouterOptions>): Promise<PublicApi<R>>;
|
|
18
|
+
export declare function initRouter(opts?: Partial<RouterOptions>): Promise<Readonly<RouterOptions>>;
|
|
19
|
+
export declare function registerRoutes<R extends Routes>(routes: R): Promise<PublicApi<R>>;
|
|
20
|
+
export declare function addStartMiddleFns(middleFnsDef: MiddleFnsCollection, appendBeforeExisting?: boolean): void;
|
|
21
|
+
export declare function addEndMiddleFns(middleFnsDef: MiddleFnsCollection, prependAfterExisting?: boolean): void;
|
|
22
|
+
export declare function isPrivateDefinition(entry: RouterEntry, id: string): entry is PrivateDef;
|
|
23
|
+
export declare function isPrivateExecutable(executable: RemoteMethod): boolean;
|
|
24
|
+
export declare function getTotalExecutables(): number;
|
|
25
|
+
export declare function getAllExecutablesIds(): string[];
|
|
26
|
+
export declare function shouldFullGenerateSpec(): boolean;
|
|
27
|
+
export declare function getRouteExecutableFromPath(path: string): RouteMethod;
|
|
28
|
+
export declare function getExecutableFromMiddleFn(middleFn: MiddleFnDef | HeadersMiddleFnDef, middleFnPointer: string[], nestLevel: number): Promise<MiddleFnMethod | HeadersMethod>;
|
|
29
|
+
export declare function getExecutableFromRawMiddleFn(middleFn: RawMiddleFnDef, middleFnPointer: string[], nestLevel: number): Promise<RawMethod>;
|
|
30
|
+
export declare function getExecutableFromRoute(route: Route, routePointer: string[], nestLevel: number): Promise<RouteMethod>;
|