@mionjs/core 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.
Files changed (42) hide show
  1. package/.dist/cjs/index.cjs +4 -0
  2. package/.dist/cjs/index.cjs.map +1 -1
  3. package/.dist/cjs/src/binary/bodyDeserializer.cjs +5 -0
  4. package/.dist/cjs/src/binary/bodyDeserializer.cjs.map +1 -1
  5. package/.dist/cjs/src/binary/bodySerializer.cjs +1 -6
  6. package/.dist/cjs/src/binary/bodySerializer.cjs.map +1 -1
  7. package/.dist/cjs/src/constants.cjs +5 -3
  8. package/.dist/cjs/src/constants.cjs.map +1 -1
  9. package/.dist/cjs/src/constants.d.ts +1 -1
  10. package/.dist/cjs/src/pureFns/pureFn.cjs +6 -4
  11. package/.dist/cjs/src/pureFns/pureFn.cjs.map +1 -1
  12. package/.dist/cjs/src/pureFns/restoreJitFns.cjs +3 -3
  13. package/.dist/cjs/src/pureFns/restoreJitFns.cjs.map +1 -1
  14. package/.dist/cjs/src/routerUtils.cjs +16 -17
  15. package/.dist/cjs/src/routerUtils.cjs.map +1 -1
  16. package/.dist/cjs/src/routerUtils.d.ts +1 -1
  17. package/.dist/cjs/src/types/general.types.cjs +15 -5
  18. package/.dist/cjs/src/types/general.types.cjs.map +1 -1
  19. package/.dist/cjs/src/types/general.types.d.ts +17 -8
  20. package/.dist/cjs/src/types/pureFunctions.types.cjs +1 -1
  21. package/.dist/cjs/src/types/pureFunctions.types.d.ts +1 -1
  22. package/.dist/esm/index.js +5 -1
  23. package/.dist/esm/src/binary/bodyDeserializer.js +5 -0
  24. package/.dist/esm/src/binary/bodyDeserializer.js.map +1 -1
  25. package/.dist/esm/src/binary/bodySerializer.js +1 -6
  26. package/.dist/esm/src/binary/bodySerializer.js.map +1 -1
  27. package/.dist/esm/src/constants.d.ts +1 -1
  28. package/.dist/esm/src/constants.js +5 -3
  29. package/.dist/esm/src/constants.js.map +1 -1
  30. package/.dist/esm/src/pureFns/pureFn.js +6 -4
  31. package/.dist/esm/src/pureFns/pureFn.js.map +1 -1
  32. package/.dist/esm/src/pureFns/restoreJitFns.js +3 -3
  33. package/.dist/esm/src/pureFns/restoreJitFns.js.map +1 -1
  34. package/.dist/esm/src/routerUtils.d.ts +1 -1
  35. package/.dist/esm/src/routerUtils.js +16 -17
  36. package/.dist/esm/src/routerUtils.js.map +1 -1
  37. package/.dist/esm/src/types/general.types.d.ts +17 -8
  38. package/.dist/esm/src/types/general.types.js +16 -6
  39. package/.dist/esm/src/types/general.types.js.map +1 -1
  40. package/.dist/esm/src/types/pureFunctions.types.d.ts +1 -1
  41. package/.dist/esm/src/types/pureFunctions.types.js +1 -1
  42. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"routerUtils.js","sources":["../../../src/routerUtils.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 {JIT_FUNCTION_IDS, PATH_SEPARATOR, ROUTER_ITEM_SEPARATOR_CHAR, ROUTE_PATH_ROOT, EMPTY_HASH} from './constants.ts';\nimport type {RemoteMethodOpts, MethodWithOptions, MethodsCache, MethodWithOptsAndJitFns} from './types/method.types.ts';\nimport type {CoreRouterOptions, JitCompiledFn, JitCompiledFunctions, JitFunctionsHashes} from './types/general.types.ts';\nimport {getJitUtils} from './jit/jitUtils.ts';\n\nconst methodsCache: MethodsCache = {};\nconst methodsOptionsCache: Record<string, RemoteMethodOpts> = {};\n\n// Cache for JitCompiledFunctions objects keyed by jitHash\nconst jitFunctionsCache = new Map<string, JitCompiledFunctions>();\nconst headerJitFunctionsCache = new Map<string, Pick<JitCompiledFunctions, 'isType' | 'typeErrors'>>();\n\n/**\n * Utilities for accessing and modifying the router cache.\n * The router cache stores method metadata for routes registered via addRoutesToCache() or virtual modules.\n */\nexport const routesCache = {\n /**\n * Get method metadata from the router cache by id.\n * @param id - The method id\n * @returns The method metadata or undefined if not found\n */\n getMetadata(id: string): MethodWithOptions | undefined {\n return methodsCache[id] as MethodWithOptions | undefined;\n },\n\n /**\n * Set method metadata in the router cache\n * @param id - The method id\n * @param methodData - The method metadata\n */\n setMetadata(id: string, methodData: MethodWithOptions): void {\n methodsCache[id] = methodData as any;\n },\n\n /**\n * Check if the router cache contains a method by id.\n * @param id - The method id\n * @returns True if the method exists in the cache\n */\n hasMetadata(id: string): boolean {\n return id in methodsCache;\n },\n\n /**\n * Get the raw router cache object.\n * Use with caution - prefer using get/set/has methods.\n * @returns The router cache object\n */\n getCache(): MethodsCache {\n return methodsCache;\n },\n\n /**\n * Get method metadata with JIT functions restored from the router cache by id.\n * This augments the MethodWithOptions with paramsJitFns and returnJitFns.\n * JIT functions are cached in the entry after first access for performance.\n * @param id - The method id\n * @returns The method metadata with JIT functions or undefined if not found\n */\n getMethodJitFns(id: string): MethodWithOptsAndJitFns | undefined {\n if (id in methodsCache) {\n const cached = methodsCache[id] as any;\n if (cached.paramsJitFns && cached.returnJitFns) {\n return cached as MethodWithOptsAndJitFns;\n }\n }\n\n const metadata = this.getMetadata(id);\n if (!metadata) return undefined;\n\n const paramsJitFns = getJitFunctionsFromHash(metadata.paramsJitHash);\n const returnJitFns = getJitFunctionsFromHash(metadata.returnJitHash);\n const headersParam = metadata.headersParam\n ? {...metadata.headersParam, jitFns: getHeaderJitFunctionsFromHash(metadata.headersParam.jitHash)}\n : undefined;\n const headersReturn = metadata.headersReturn\n ? {...metadata.headersReturn, jitFns: getHeaderJitFunctionsFromHash(metadata.headersReturn.jitHash)}\n : undefined;\n\n const result: MethodWithOptsAndJitFns = {\n ...metadata,\n paramsJitFns,\n returnJitFns,\n headersParam,\n headersReturn,\n };\n\n methodsCache[id] = result;\n return result as MethodWithOptsAndJitFns;\n },\n\n /**\n * Get method metadata with JIT functions restored from the router cache by id.\n * @param id\n * @returns\n */\n useMethodJitFns(id: string): MethodWithOptsAndJitFns {\n const MethodWithOptsAndJitFns = this.getMethodJitFns(id);\n if (!MethodWithOptsAndJitFns) throw new Error(`Metadata for remote method ${id} not found`);\n return MethodWithOptsAndJitFns;\n },\n\n /**\n * Set method metadata with JIT functions in the router cache.\n * This stores the complete MethodWithOptsAndJitFns object directly.\n * @param id - The method id\n * @param MethodWithOptsAndJitFns - The method metadata with JIT functions\n */\n setMethodJitFns(id: string, MethodWithOptsAndJitFns: MethodWithOptsAndJitFns): void {\n methodsCache[id] = MethodWithOptsAndJitFns as any;\n },\n};\n\nexport const methodOptsCache = {\n getMethodOptions(id: string): RemoteMethodOpts | undefined {\n return methodsOptionsCache[id];\n },\n setMethodOptions(id: string, options: RemoteMethodOpts): void {\n methodsOptionsCache[id] = options;\n },\n};\n\n/**\n * Adds new routes to the router cache.\n * This is the public API for registering routes - called by virtual modules or directly.\n * @param newCache\n */\nexport function addRoutesToCache(newCache: MethodsCache) {\n for (const key in newCache) {\n if (!(key in methodsCache)) {\n // Clone the cache entry to avoid mutating the original\n methodsCache[key] = {...newCache[key]} as MethodWithOptions;\n }\n }\n}\n\nexport function getJitFnHashes(jitHash: string): JitFunctionsHashes {\n return {\n isType: `${JIT_FUNCTION_IDS.isType}_${jitHash}`,\n typeErrors: `${JIT_FUNCTION_IDS.typeErrors}_${jitHash}`,\n prepareForJson: `${JIT_FUNCTION_IDS.prepareForJson}_${jitHash}`,\n restoreFromJson: `${JIT_FUNCTION_IDS.restoreFromJson}_${jitHash}`,\n stringifyJson: `${JIT_FUNCTION_IDS.stringifyJson}_${jitHash}`,\n toBinary: `${JIT_FUNCTION_IDS.toBinary}_${jitHash}`,\n fromBinary: `${JIT_FUNCTION_IDS.fromBinary}_${jitHash}`,\n };\n}\n\n/**\n * Helper function to get JIT functions from a JIT hash\n * Returns nullJitFns for empty hash (handlers with no params or void return)\n * Results are cached to avoid creating duplicate objects.\n */\nexport function getJitFunctionsFromHash(jitHash: string): JitCompiledFunctions {\n // Empty hash means no JIT functions were generated (optimization for no params or void return)\n if (jitHash === EMPTY_HASH) return noopJitFns;\n\n // Check cache first\n const cached = jitFunctionsCache.get(jitHash);\n if (cached) return cached;\n\n const hashes = getJitFnHashes(jitHash);\n const jUtils = getJitUtils();\n const jitFns = {\n isType: jUtils.getJIT(hashes.isType),\n typeErrors: jUtils.getJIT(hashes.typeErrors),\n prepareForJson: jUtils.getJIT(hashes.prepareForJson),\n restoreFromJson: jUtils.getJIT(hashes.restoreFromJson),\n stringifyJson: jUtils.getJIT(hashes.stringifyJson),\n toBinary: jUtils.getJIT(hashes.toBinary),\n fromBinary: jUtils.getJIT(hashes.fromBinary),\n } as JitCompiledFunctions;\n for (const key in jitFns) {\n if (!jitFns[key]) throw new Error(`Jit function ${key} not found for jitHash ${jitHash}`);\n }\n\n // Cache for future calls\n jitFunctionsCache.set(jitHash, jitFns);\n return jitFns;\n}\n\n/**\n * Helper function to get header JIT functions from a JIT hash\n * Results are cached to avoid creating duplicate objects.\n */\nexport function getHeaderJitFunctionsFromHash(jitHash: string): Pick<JitCompiledFunctions, 'isType' | 'typeErrors'> {\n // Check cache first\n const cached = headerJitFunctionsCache.get(jitHash);\n if (cached) return cached;\n\n const hashes = getJitFnHashes(jitHash);\n const jUtils = getJitUtils();\n const jitFns = {\n isType: jUtils.getJIT(hashes.isType),\n typeErrors: jUtils.getJIT(hashes.typeErrors),\n } as Pick<JitCompiledFunctions, 'isType' | 'typeErrors'>;\n\n // Cache for future calls\n headerJitFunctionsCache.set(jitHash, jitFns);\n return jitFns;\n}\n\n/**\n * Get the router id for Routes or MiddleFns\n * @param itemPointer - The pointer to the item within the Routes object\n * i.e:\n * const routes = {\n * auth: () => {},\n * users: {\n * getUser: () => {}\n * }\n * login: () => {}\n * }\n *\n * then the pointer for getUser is => ['users', 'getUser']\n */\nexport function getRouterItemId(itemPointer: string[]) {\n return itemPointer.join(ROUTER_ITEM_SEPARATOR_CHAR);\n}\n\n/** Gets a route path from a route pointer */\nexport function getRoutePath(pathPointer: string[], routerOptions: CoreRouterOptions) {\n const pathId = getRouterItemId(pathPointer);\n const basePath = routerOptions.basePath.startsWith(ROUTE_PATH_ROOT)\n ? routerOptions.basePath\n : `${ROUTE_PATH_ROOT}${routerOptions.basePath}`;\n const routePath = basePath.endsWith(PATH_SEPARATOR) ? `${basePath}${pathId}` : `${basePath}${PATH_SEPARATOR}${pathId}`;\n return routerOptions.suffix ? routePath + routerOptions.suffix : routePath;\n}\n\nexport function resetRoutesCache() {\n for (const k in methodsCache) delete methodsCache[k];\n}\n\n/** Resets the JIT functions cache. Useful for testing purposes only. */\nexport function resetJitFunctionsCache(): void {\n jitFunctionsCache.clear();\n headerJitFunctionsCache.clear();\n}\n\n// Noop JIT functions used for handlers with no params or void return\n// prettier-ignore\nconst noopJitFns: JitCompiledFunctions = {\n isType: fakeJitFn(JIT_FUNCTION_IDS.isType),\n typeErrors: fakeJitFn(JIT_FUNCTION_IDS.typeErrors),\n prepareForJson: fakeJitFn(JIT_FUNCTION_IDS.prepareForJson),\n restoreFromJson: fakeJitFn(JIT_FUNCTION_IDS.restoreFromJson),\n stringifyJson: fakeJitFn(JIT_FUNCTION_IDS.stringifyJson),\n toBinary: fakeJitFn(JIT_FUNCTION_IDS.toBinary),\n fromBinary: fakeJitFn(JIT_FUNCTION_IDS.fromBinary),\n} as any;\n\n/** Creates a fake JIT function with isNoop=true for handlers with no params or void return */\nfunction fakeJitFn(fnID: string): JitCompiledFn<any> {\n return {\n typeName: 'mionNoopJit',\n fnID,\n jitFnHash: EMPTY_HASH,\n args: {vλl: 'v'},\n defaultParamValues: {vλl: 'v'},\n isNoop: true,\n code: '',\n jitDependencies: [],\n pureFnDependencies: [],\n createJitFn: () => {\n throw new Error('isNoop JIT functions should not be called, this is a function when jit is never used');\n },\n fn: () => {\n throw new Error('isNoop JIT functions should not be called, this is a function when jit is never used');\n },\n };\n}\n\nexport function getNoopJitFns(): JitCompiledFunctions {\n return noopJitFns;\n}\n"],"names":[],"mappings":";;AAYA,MAAM,eAA6B,CAAA;AACnC,MAAM,sBAAwD,CAAA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AM,aAAmC;AAAA,EACrC,QAAQ,UAAU,iBAAiB,MAAM;AAAA,EACzC,YAAY,UAAU,iBAAiB,UAAU;AAAA,EACjD,gBAAgB,UAAU,iBAAiB,cAAc;AAAA,EACzD,iBAAiB,UAAU,iBAAiB,eAAe;AAAA,EAC3D,eAAe,UAAU,iBAAiB,aAAa;AAAA,EACvD,UAAU,UAAU,iBAAiB,QAAQ;AAAA,EAC7C,YAAY,UAAU,iBAAiB,UAAU;AACrD;AAGA,SAAS,UAAU,MAAkC;AACjD,SAAO;AAAA,IACH,UAAU;AAAA,IACV;AAAA,IACA,WAAW;AAAA,IACX,MAAM,EAAC,KAAK,IAAA;AAAA,IACZ,oBAAoB,EAAC,KAAK,IAAA;AAAA,IAC1B,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,iBAAiB,CAAA;AAAA,IACjB,oBAAoB,CAAA;AAAA,IACpB,aAAa,MAAM;AACf,YAAM,IAAI,MAAM,sFAAsF;AAAA,IAC1G;AAAA,IACA,IAAI,MAAM;AACN,YAAM,IAAI,MAAM,sFAAsF;AAAA,IAC1G;AAAA,EAAA;AAER;AAEO,SAAS,gBAAsC;AAClD,SAAO;AACX;"}
1
+ {"version":3,"file":"routerUtils.js","sources":["../../../src/routerUtils.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 {JIT_FUNCTION_IDS, PATH_SEPARATOR, ROUTER_ITEM_SEPARATOR_CHAR, ROUTE_PATH_ROOT, EMPTY_HASH} from './constants.ts';\nimport type {RemoteMethodOpts, MethodWithOptions, MethodsCache, MethodWithOptsAndJitFns} from './types/method.types.ts';\nimport type {CoreRouterOptions, JitCompiledFn, JitCompiledFunctions, JitFunctionsHashes} from './types/general.types.ts';\nimport {getJitUtils} from './jit/jitUtils.ts';\n\nconst methodsCache: MethodsCache = {};\nconst methodsOptionsCache: Record<string, RemoteMethodOpts> = {};\n\n// Cache for JitCompiledFunctions objects keyed by jitHash\nconst jitFunctionsCache = new Map<string, JitCompiledFunctions>();\nconst headerJitFunctionsCache = new Map<string, Pick<JitCompiledFunctions, 'isType' | 'typeErrors'>>();\n\n/**\n * Utilities for accessing and modifying the router cache.\n * The router cache stores method metadata for routes registered via addRoutesToCache() or virtual modules.\n */\nexport const routesCache = {\n /**\n * Get method metadata from the router cache by id.\n * @param id - The method id\n * @returns The method metadata or undefined if not found\n */\n getMetadata(id: string): MethodWithOptions | undefined {\n return methodsCache[id] as MethodWithOptions | undefined;\n },\n\n /**\n * Set method metadata in the router cache\n * @param id - The method id\n * @param methodData - The method metadata\n */\n setMetadata(id: string, methodData: MethodWithOptions): void {\n methodsCache[id] = methodData as any;\n },\n\n /**\n * Check if the router cache contains a method by id.\n * @param id - The method id\n * @returns True if the method exists in the cache\n */\n hasMetadata(id: string): boolean {\n return id in methodsCache;\n },\n\n /**\n * Get the raw router cache object.\n * Use with caution - prefer using get/set/has methods.\n * @returns The router cache object\n */\n getCache(): MethodsCache {\n return methodsCache;\n },\n\n /**\n * Get method metadata with JIT functions restored from the router cache by id.\n * This augments the MethodWithOptions with paramsJitFns and returnJitFns.\n * JIT functions are cached in the entry after first access for performance.\n * @param id - The method id\n * @returns The method metadata with JIT functions or undefined if not found\n */\n getMethodJitFns(id: string): MethodWithOptsAndJitFns | undefined {\n if (id in methodsCache) {\n const cached = methodsCache[id] as any;\n if (cached.paramsJitFns && cached.returnJitFns) {\n return cached as MethodWithOptsAndJitFns;\n }\n }\n\n const metadata = this.getMetadata(id);\n if (!metadata) return undefined;\n\n const paramsJitFns = getJitFunctionsFromHash(metadata.paramsJitHash);\n const returnJitFns = getJitFunctionsFromHash(metadata.returnJitHash);\n const headersParam = metadata.headersParam\n ? {...metadata.headersParam, jitFns: getHeaderJitFunctionsFromHash(metadata.headersParam.jitHash)}\n : undefined;\n const headersReturn = metadata.headersReturn\n ? {...metadata.headersReturn, jitFns: getHeaderJitFunctionsFromHash(metadata.headersReturn.jitHash)}\n : undefined;\n\n const result: MethodWithOptsAndJitFns = {\n ...metadata,\n paramsJitFns,\n returnJitFns,\n headersParam,\n headersReturn,\n };\n\n methodsCache[id] = result;\n return result as MethodWithOptsAndJitFns;\n },\n\n /**\n * Get method metadata with JIT functions restored from the router cache by id.\n * @param id\n * @returns\n */\n useMethodJitFns(id: string): MethodWithOptsAndJitFns {\n const MethodWithOptsAndJitFns = this.getMethodJitFns(id);\n if (!MethodWithOptsAndJitFns) throw new Error(`Metadata for remote method ${id} not found`);\n return MethodWithOptsAndJitFns;\n },\n\n /**\n * Set method metadata with JIT functions in the router cache.\n * This stores the complete MethodWithOptsAndJitFns object directly.\n * @param id - The method id\n * @param MethodWithOptsAndJitFns - The method metadata with JIT functions\n */\n setMethodJitFns(id: string, MethodWithOptsAndJitFns: MethodWithOptsAndJitFns): void {\n methodsCache[id] = MethodWithOptsAndJitFns as any;\n },\n};\n\nexport const methodOptsCache = {\n getMethodOptions(id: string): RemoteMethodOpts | undefined {\n return methodsOptionsCache[id];\n },\n setMethodOptions(id: string, options: RemoteMethodOpts): void {\n methodsOptionsCache[id] = options;\n },\n};\n\n/**\n * Adds new routes to the router cache.\n * This is the public API for registering routes - called by virtual modules or directly.\n * @param newCache\n */\nexport function addRoutesToCache(newCache: MethodsCache) {\n for (const key in newCache) {\n if (!(key in methodsCache)) {\n // Clone the cache entry to avoid mutating the original\n methodsCache[key] = {...newCache[key]} as MethodWithOptions;\n }\n }\n}\n\nexport function getJitFnHashes(jitHash: string, needsBinary: boolean = false): JitFunctionsHashes {\n return {\n isType: `${JIT_FUNCTION_IDS.isType}_${jitHash}`,\n typeErrors: `${JIT_FUNCTION_IDS.typeErrors}_${jitHash}`,\n prepareForJson: `${JIT_FUNCTION_IDS.prepareForJson}_${jitHash}`,\n restoreFromJson: `${JIT_FUNCTION_IDS.restoreFromJson}_${jitHash}`,\n stringifyJson: `${JIT_FUNCTION_IDS.stringifyJson}_${jitHash}`,\n ...(needsBinary\n ? {\n toBinary: `${JIT_FUNCTION_IDS.toBinary}_${jitHash}`,\n fromBinary: `${JIT_FUNCTION_IDS.fromBinary}_${jitHash}`,\n }\n : {}),\n };\n}\n\n/**\n * Helper function to get JIT functions from a JIT hash\n * Returns nullJitFns for empty hash (handlers with no params or void return)\n * Results are cached to avoid creating duplicate objects.\n */\nexport function getJitFunctionsFromHash(jitHash: string): JitCompiledFunctions {\n // Empty hash means no JIT functions were generated (optimization for no params or void return)\n if (jitHash === EMPTY_HASH) return noopJitFns;\n\n // Check cache first\n const cached = jitFunctionsCache.get(jitHash);\n if (cached) return cached;\n\n const jUtils = getJitUtils();\n const jitFns = {\n isType: jUtils.getJIT(`${JIT_FUNCTION_IDS.isType}_${jitHash}`),\n typeErrors: jUtils.getJIT(`${JIT_FUNCTION_IDS.typeErrors}_${jitHash}`),\n prepareForJson: jUtils.getJIT(`${JIT_FUNCTION_IDS.prepareForJson}_${jitHash}`),\n restoreFromJson: jUtils.getJIT(`${JIT_FUNCTION_IDS.restoreFromJson}_${jitHash}`),\n stringifyJson: jUtils.getJIT(`${JIT_FUNCTION_IDS.stringifyJson}_${jitHash}`),\n } as JitCompiledFunctions;\n // Only include binary functions if they exist in the store\n const toBinaryJit = jUtils.getJIT(`${JIT_FUNCTION_IDS.toBinary}_${jitHash}`);\n const fromBinaryJit = jUtils.getJIT(`${JIT_FUNCTION_IDS.fromBinary}_${jitHash}`);\n if (toBinaryJit) jitFns.toBinary = toBinaryJit;\n if (fromBinaryJit) jitFns.fromBinary = fromBinaryJit;\n\n for (const key of ['isType', 'typeErrors', 'prepareForJson', 'restoreFromJson', 'stringifyJson'] as const) {\n if (!jitFns[key]) throw new Error(`Jit function ${key} not found for jitHash ${jitHash}`);\n }\n\n // Cache for future calls\n jitFunctionsCache.set(jitHash, jitFns);\n return jitFns;\n}\n\n/**\n * Helper function to get header JIT functions from a JIT hash\n * Results are cached to avoid creating duplicate objects.\n */\nexport function getHeaderJitFunctionsFromHash(jitHash: string): Pick<JitCompiledFunctions, 'isType' | 'typeErrors'> {\n // Check cache first\n const cached = headerJitFunctionsCache.get(jitHash);\n if (cached) return cached;\n\n const hashes = getJitFnHashes(jitHash);\n const jUtils = getJitUtils();\n const jitFns = {\n isType: jUtils.getJIT(hashes.isType),\n typeErrors: jUtils.getJIT(hashes.typeErrors),\n } as Pick<JitCompiledFunctions, 'isType' | 'typeErrors'>;\n\n // Cache for future calls\n headerJitFunctionsCache.set(jitHash, jitFns);\n return jitFns;\n}\n\n/**\n * Get the router id for Routes or MiddleFns\n * @param itemPointer - The pointer to the item within the Routes object\n * i.e:\n * const routes = {\n * auth: () => {},\n * users: {\n * getUser: () => {}\n * }\n * login: () => {}\n * }\n *\n * then the pointer for getUser is => ['users', 'getUser']\n */\nexport function getRouterItemId(itemPointer: string[]) {\n return itemPointer.join(ROUTER_ITEM_SEPARATOR_CHAR);\n}\n\n/** Gets a route path from a route pointer */\nexport function getRoutePath(pathPointer: string[], routerOptions: CoreRouterOptions) {\n const pathId = getRouterItemId(pathPointer);\n const basePath = routerOptions.basePath.startsWith(ROUTE_PATH_ROOT)\n ? routerOptions.basePath\n : `${ROUTE_PATH_ROOT}${routerOptions.basePath}`;\n const routePath = basePath.endsWith(PATH_SEPARATOR) ? `${basePath}${pathId}` : `${basePath}${PATH_SEPARATOR}${pathId}`;\n return routerOptions.suffix ? routePath + routerOptions.suffix : routePath;\n}\n\nexport function resetRoutesCache() {\n for (const k in methodsCache) delete methodsCache[k];\n}\n\n/** Resets the JIT functions cache. Useful for testing purposes only. */\nexport function resetJitFunctionsCache(): void {\n jitFunctionsCache.clear();\n headerJitFunctionsCache.clear();\n}\n\n// Noop JIT functions used for handlers with no params or void return\n// prettier-ignore\nconst noopJitFns: JitCompiledFunctions = {\n isType: fakeJitFn(JIT_FUNCTION_IDS.isType),\n typeErrors: fakeJitFn(JIT_FUNCTION_IDS.typeErrors),\n prepareForJson: fakeJitFn(JIT_FUNCTION_IDS.prepareForJson),\n restoreFromJson: fakeJitFn(JIT_FUNCTION_IDS.restoreFromJson),\n stringifyJson: fakeJitFn(JIT_FUNCTION_IDS.stringifyJson),\n} as any;\n\n/** Creates a fake JIT function with isNoop=true for handlers with no params or void return */\nfunction fakeJitFn(fnID: string): JitCompiledFn<any> {\n return {\n typeName: 'mionNoopJit',\n fnID,\n jitFnHash: EMPTY_HASH,\n args: {vλl: 'v'},\n defaultParamValues: {vλl: 'v'},\n isNoop: true,\n code: '',\n createJitFn: () => {\n throw new Error('isNoop JIT functions should not be called, this is a function when jit is never used');\n },\n fn: () => {\n throw new Error('isNoop JIT functions should not be called, this is a function when jit is never used');\n },\n };\n}\n\nexport function getNoopJitFns(): JitCompiledFunctions {\n return noopJitFns;\n}\n"],"names":[],"mappings":";;AAYA,MAAM,eAA6B,CAAA;AACnC,MAAM,sBAAwD,CAAA;AAG9D,MAAM,wCAAwB,IAAA;AAC9B,MAAM,8CAA8B,IAAA;AAM7B,MAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMvB,YAAY,IAA2C;AACnD,WAAO,aAAa,EAAE;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,YAAY,IAAY,YAAqC;AACzD,iBAAa,EAAE,IAAI;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,YAAY,IAAqB;AAC7B,WAAO,MAAM;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAyB;AACrB,WAAO;AAAA,EACX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,gBAAgB,IAAiD;AAC7D,QAAI,MAAM,cAAc;AACpB,YAAM,SAAS,aAAa,EAAE;AAC9B,UAAI,OAAO,gBAAgB,OAAO,cAAc;AAC5C,eAAO;AAAA,MACX;AAAA,IACJ;AAEA,UAAM,WAAW,KAAK,YAAY,EAAE;AACpC,QAAI,CAAC,SAAU,QAAO;AAEtB,UAAM,eAAe,wBAAwB,SAAS,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;AAAA,IACN,aAAa,MAAM;AACf,YAAM,IAAI,MAAM,sFAAsF;AAAA,IAC1G;AAAA,IACA,IAAI,MAAM;AACN,YAAM,IAAI,MAAM,sFAAsF;AAAA,IAC1G;AAAA,EAAA;AAER;AAEO,SAAS,gBAAsC;AAClD,SAAO;AACX;"}
@@ -6,6 +6,7 @@ export declare const SerializerModes: {
6
6
  readonly json: 1;
7
7
  readonly binary: 2;
8
8
  readonly stringifyJson: 3;
9
+ readonly optimistic: 4;
9
10
  };
10
11
  export type SerializerMode = keyof typeof SerializerModes;
11
12
  export type SerializerCode = (typeof SerializerModes)[SerializerMode];
@@ -73,8 +74,8 @@ export interface JitCompiledFnData {
73
74
  readonly defaultParamValues: JitFnArgs;
74
75
  readonly isNoop?: boolean;
75
76
  readonly code: string;
76
- readonly jitDependencies: Array<string>;
77
- readonly pureFnDependencies: Array<string>;
77
+ readonly jitDependencies?: Array<string>;
78
+ readonly pureFnDependencies?: Array<string>;
78
79
  paramNames?: string[];
79
80
  }
80
81
  export interface JitCompiledFn<Fn extends AnyFn = AnyFn> extends JitCompiledFnData {
@@ -90,8 +91,8 @@ export interface JitCompiledFunctions {
90
91
  prepareForJson: JitCompiledFn<PrepareForJsonFn>;
91
92
  restoreFromJson: JitCompiledFn<RestoreFromJsonFn>;
92
93
  stringifyJson: JitCompiledFn<JsonStringifyFn>;
93
- toBinary: JitCompiledFn<ToBinaryFn>;
94
- fromBinary: JitCompiledFn<FromBinaryFn>;
94
+ toBinary?: JitCompiledFn<ToBinaryFn>;
95
+ fromBinary?: JitCompiledFn<FromBinaryFn>;
95
96
  }
96
97
  export interface SerializableJITFunctions {
97
98
  isType: JitCompiledFnData;
@@ -99,8 +100,8 @@ export interface SerializableJITFunctions {
99
100
  prepareForJson: JitCompiledFnData;
100
101
  restoreFromJson: JitCompiledFnData;
101
102
  stringifyJson: JitCompiledFnData;
102
- toBinary: JitCompiledFnData;
103
- fromBinary: JitCompiledFnData;
103
+ toBinary?: JitCompiledFnData;
104
+ fromBinary?: JitCompiledFnData;
104
105
  }
105
106
  export interface JitFunctionsHashes {
106
107
  isType: string;
@@ -108,8 +109,8 @@ export interface JitFunctionsHashes {
108
109
  prepareForJson: string;
109
110
  restoreFromJson: string;
110
111
  stringifyJson: string;
111
- toBinary: string;
112
- fromBinary: string;
112
+ toBinary?: string;
113
+ fromBinary?: string;
113
114
  }
114
115
  export type JsonStringifyFn = (value: any) => JSONString;
115
116
  export type RestoreFromJsonFn = (value: JSONValue) => any;
@@ -135,6 +136,10 @@ export interface SrcCodeCompiledPureFunction extends PureFunctionData {
135
136
  }
136
137
  export type SrcCodeJITCompiledFnsCache = Record<string, SrcCodeJitCompiledFn>;
137
138
  export type SrcCodePureFunctionsCache = Record<string, Record<string, SrcCodeCompiledPureFunction>>;
139
+ export type ClientSrcCodeJitCompiledFn = Omit<SrcCodeJitCompiledFn, 'code' | 'args' | 'defaultParamValues' | 'fnID' | 'paramNames'>;
140
+ export type ClientSrcCodeCompiledPureFunction = Omit<SrcCodeCompiledPureFunction, 'code' | 'paramNames'>;
141
+ export type ClientSrcCodeJITCompiledFnsCache = Record<string, ClientSrcCodeJitCompiledFn>;
142
+ export type ClientSrcCodePureFunctionsCache = Record<string, Record<string, ClientSrcCodeCompiledPureFunction>>;
138
143
  export type StrNumber = string | number;
139
144
  export type AnyFn = (...args: any[]) => any;
140
145
  export type AnyObject = Record<string, unknown>;
@@ -228,6 +233,10 @@ export declare type __ΩSrcCodeJitCompiledFn = any[];
228
233
  export declare type __ΩSrcCodeCompiledPureFunction = any[];
229
234
  export declare type __ΩSrcCodeJITCompiledFnsCache = any[];
230
235
  export declare type __ΩSrcCodePureFunctionsCache = any[];
236
+ export declare type __ΩClientSrcCodeJitCompiledFn = any[];
237
+ export declare type __ΩClientSrcCodeCompiledPureFunction = any[];
238
+ export declare type __ΩClientSrcCodeJITCompiledFnsCache = any[];
239
+ export declare type __ΩClientSrcCodePureFunctionsCache = any[];
231
240
  export declare type __ΩStrNumber = any[];
232
241
  export declare type __ΩAnyFn = any[];
233
242
  export declare type __ΩAnyObject = any[];
@@ -1,6 +1,6 @@
1
1
  import { MIME_TYPES } from "../constants.js";
2
2
  import { __ΩTypeFormatError as ___TypeFormatError } from "./formats/formats.types.js";
3
- import { __ΩPersistedPureFunction as ___PersistedPureFunction, __ΩPureFunctionData as ___PureFunctionData, __ΩCompiledPureFunction as ___CompiledPureFunction } from "./pureFunctions.types.js";
3
+ import { __ΩPureFunctionData as ___PureFunctionData, __ΩPersistedPureFunction as ___PersistedPureFunction, __ΩCompiledPureFunction as ___CompiledPureFunction } from "./pureFunctions.types.js";
4
4
  const __ΩError = ["name", "message", "stack", "Error", 'P&4!&4"&4#8Mw$y'];
5
5
  const __ΩOmit = ["T", "K", () => __ΩPick, () => __ΩExclude, "Omit", 'b!b"e!!e!!ge!"o$#o##w%y'];
6
6
  const __ΩRecord = ["K", "T", "Record", `l'e#"Rb!b"Pde"!N#!w#y`];
@@ -26,7 +26,9 @@ const SerializerModes = {
26
26
  /** Use toBinary JIT function for binary serialization */
27
27
  binary: 2,
28
28
  /** Use stringifyJson JIT function that do not mutates objects. */
29
- stringifyJson: 3
29
+ stringifyJson: 3,
30
+ /** Client-only: sends plain JSON without JIT, fetches metadata in the same response */
31
+ optimistic: 4
30
32
  };
31
33
  const __ΩSerializerMode = [() => SerializerModes, "SerializerMode", 'i!gw"y'];
32
34
  const __ΩSerializerCode = [() => SerializerModes, () => __ΩSerializerMode, "SerializerCode", 'i!n"fw#y'];
@@ -43,12 +45,12 @@ const __ΩSetItemPathSegment = ["key", "index", "SetItemPathSegment", `P#4!'4"Mw
43
45
  const __ΩPathSegment = [() => __ΩStrNumber, () => __ΩMapKeyPathSegment, () => __ΩMapValuePathSegment, () => __ΩSetItemPathSegment, "PathSegment", 'Pn!n"n#n$Jw%y'];
44
46
  const __ΩRunTypeError = [() => __ΩPathSegment, "path", "expected", () => ___TypeFormatError, "format", "RunTypeError", 'Pn!F4"&4#n$4%8Mw&y'];
45
47
  const __ΩJitFnArgs = ["vλl", "JitFnArgs", 'P&4!&&LMw"y'];
46
- const __ΩJitCompiledFnData = ["typeName", "fnID", "jitFnHash", () => __ΩJitFnArgs, "args", () => __ΩJitFnArgs, "defaultParamValues", "isNoop", "code", "jitDependencies", "pureFnDependencies", "paramNames", "JitCompiledFnData", `P&4!9&4"9&4#9n$4%9n&4'9)4(89&4)9&F4*9&F4+9&F4,8Mw-y`];
48
+ const __ΩJitCompiledFnData = ["typeName", "fnID", "jitFnHash", () => __ΩJitFnArgs, "args", () => __ΩJitFnArgs, "defaultParamValues", "isNoop", "code", "jitDependencies", "pureFnDependencies", "paramNames", "JitCompiledFnData", `P&4!9&4"9&4#9n$4%9n&4'9)4(89&4)9&F4*89&F4+89&F4,8Mw-y`];
47
49
  const __ΩJitCompiledFn = [() => __ΩAnyFn, "Fn", () => __ΩJitCompiledFnData, "JITUtils", "utl", "", "createJitFn", "fn", "JitCompiledFn", `n!c"Pn#P"w$2%e#!/&4'9e"!4(9Mw)y`];
48
50
  const __ΩPersistedJitFn = [() => __ΩOmit, () => __ΩJitCompiledFn, "fn", "fn", "PersistedJitFn", 'Pn".#o!#-4$9Mw%y'];
49
- const __ΩJitCompiledFunctions = [() => __ΩJitCompiledFn, () => __ΩIsTypeFn, "isType", () => __ΩJitCompiledFn, () => __ΩTypeErrorsFn, "typeErrors", () => __ΩJitCompiledFn, () => __ΩPrepareForJsonFn, "prepareForJson", () => __ΩJitCompiledFn, () => __ΩRestoreFromJsonFn, "restoreFromJson", () => __ΩJitCompiledFn, () => __ΩJsonStringifyFn, "stringifyJson", () => __ΩJitCompiledFn, () => __ΩToBinaryFn, "toBinary", () => __ΩJitCompiledFn, () => __ΩFromBinaryFn, "fromBinary", "JitCompiledFunctions", `Pn"o!"4#n%o$"4&n(o'"4)n+o*"4,n.o-"4/n1o0"42n4o3"45Mw6y`];
50
- const __ΩSerializableJITFunctions = [() => __ΩJitCompiledFnData, "isType", () => __ΩJitCompiledFnData, "typeErrors", () => __ΩJitCompiledFnData, "prepareForJson", () => __ΩJitCompiledFnData, "restoreFromJson", () => __ΩJitCompiledFnData, "stringifyJson", () => __ΩJitCompiledFnData, "toBinary", () => __ΩJitCompiledFnData, "fromBinary", "SerializableJITFunctions", `Pn!4"n#4$n%4&n'4(n)4*n+4,n-4.Mw/y`];
51
- const __ΩJitFunctionsHashes = ["isType", "typeErrors", "prepareForJson", "restoreFromJson", "stringifyJson", "toBinary", "fromBinary", "JitFunctionsHashes", `P&4!&4"&4#&4$&4%&4&&4'Mw(y`];
51
+ const __ΩJitCompiledFunctions = [() => __ΩJitCompiledFn, () => __ΩIsTypeFn, "isType", () => __ΩJitCompiledFn, () => __ΩTypeErrorsFn, "typeErrors", () => __ΩJitCompiledFn, () => __ΩPrepareForJsonFn, "prepareForJson", () => __ΩJitCompiledFn, () => __ΩRestoreFromJsonFn, "restoreFromJson", () => __ΩJitCompiledFn, () => __ΩJsonStringifyFn, "stringifyJson", () => __ΩJitCompiledFn, () => __ΩToBinaryFn, "toBinary", () => __ΩJitCompiledFn, () => __ΩFromBinaryFn, "fromBinary", "JitCompiledFunctions", `Pn"o!"4#n%o$"4&n(o'"4)n+o*"4,n.o-"4/n1o0"428n4o3"458Mw6y`];
52
+ const __ΩSerializableJITFunctions = [() => __ΩJitCompiledFnData, "isType", () => __ΩJitCompiledFnData, "typeErrors", () => __ΩJitCompiledFnData, "prepareForJson", () => __ΩJitCompiledFnData, "restoreFromJson", () => __ΩJitCompiledFnData, "stringifyJson", () => __ΩJitCompiledFnData, "toBinary", () => __ΩJitCompiledFnData, "fromBinary", "SerializableJITFunctions", `Pn!4"n#4$n%4&n'4(n)4*n+4,8n-4.8Mw/y`];
53
+ const __ΩJitFunctionsHashes = ["isType", "typeErrors", "prepareForJson", "restoreFromJson", "stringifyJson", "toBinary", "fromBinary", "JitFunctionsHashes", `P&4!&4"&4#&4$&4%&4&8&4'8Mw(y`];
52
54
  const __ΩJsonStringifyFn = ["value", () => __ΩJSONString, "", "JsonStringifyFn", 'P"2!n"/#w$y'];
53
55
  const __ΩRestoreFromJsonFn = [() => __ΩJSONValue, "value", "", "RestoreFromJsonFn", 'Pn!2""/#w$y'];
54
56
  const __ΩPrepareForJsonFn = ["value", () => __ΩJSONValue, "", "PrepareForJsonFn", 'P"2!n"/#w$y'];
@@ -67,6 +69,10 @@ const __ΩSrcCodeJitCompiledFn = [() => __ΩJitCompiledFnData, "JITUtils", "utl"
67
69
  const __ΩSrcCodeCompiledPureFunction = [() => ___PureFunctionData, "JITUtils", "utl", () => __ΩAnyFn, "", "createPureFn", "fn", "SrcCodeCompiledPureFunction", `Pn!P"w"2#n$/%4&9-4'9Mw(y`];
68
70
  const __ΩSrcCodeJITCompiledFnsCache = [() => __ΩRecord, () => __ΩSrcCodeJitCompiledFn, "SrcCodeJITCompiledFnsCache", '&n"o!#w#y'];
69
71
  const __ΩSrcCodePureFunctionsCache = [() => __ΩRecord, () => __ΩRecord, () => __ΩSrcCodeCompiledPureFunction, "SrcCodePureFunctionsCache", '&&n#o"#o!#w$y'];
72
+ const __ΩClientSrcCodeJitCompiledFn = [() => __ΩOmit, () => __ΩSrcCodeJitCompiledFn, "code", "args", "defaultParamValues", "fnID", "paramNames", "ClientSrcCodeJitCompiledFn", `n"P.#.$.%.&.'Jo!#w(y`];
73
+ const __ΩClientSrcCodeCompiledPureFunction = [() => __ΩOmit, () => __ΩSrcCodeCompiledPureFunction, "code", "paramNames", "ClientSrcCodeCompiledPureFunction", 'n"P.#.$Jo!#w%y'];
74
+ const __ΩClientSrcCodeJITCompiledFnsCache = [() => __ΩRecord, () => __ΩClientSrcCodeJitCompiledFn, "ClientSrcCodeJITCompiledFnsCache", '&n"o!#w#y'];
75
+ const __ΩClientSrcCodePureFunctionsCache = [() => __ΩRecord, () => __ΩRecord, () => __ΩClientSrcCodeCompiledPureFunction, "ClientSrcCodePureFunctionsCache", '&&n#o"#o!#w$y'];
70
76
  const __ΩStrNumber = ["StrNumber", "P&'Jw!y"];
71
77
  const __ΩAnyFn = ["args", "", "AnyFn", 'P"@2!"/"w#y'];
72
78
  const __ΩAnyObject = [() => __ΩRecord, "AnyObject", '&#o!#w"y'];
@@ -91,6 +97,10 @@ export {
91
97
  __ΩAnyFn,
92
98
  __ΩAnyObject,
93
99
  __ΩBinaryInput,
100
+ __ΩClientSrcCodeCompiledPureFunction,
101
+ __ΩClientSrcCodeJITCompiledFnsCache,
102
+ __ΩClientSrcCodeJitCompiledFn,
103
+ __ΩClientSrcCodePureFunctionsCache,
94
104
  __ΩCoreRouterOptions,
95
105
  __ΩDataOnly,
96
106
  __ΩDataViewDeserializer,
@@ -1 +1 @@
1
- {"version":3,"file":"general.types.js","sources":["../../../../src/types/general.types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-function-type */\n/* ###############\n * 2022 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ############### */\n\nimport {MIME_TYPES} from '../constants.ts';\nimport {TypeFormatError} from './formats/formats.types.ts';\nimport type {JITUtils} from '../jit/jitUtils.ts';\nimport {CompiledPureFunction, PersistedPureFunction, PureFunctionData} from './pureFunctions.types.ts';\n\n// ########################################## Serialization Modes ##########################################\n\nexport const SerializerModes = {\n /** Use prepareForJson (mutates original objects), and leaves JSON.stringify to the platform adapter */\n json: 1,\n /** Use toBinary JIT function for binary serialization */\n binary: 2,\n /** Use stringifyJson JIT function that do not mutates objects. */\n stringifyJson: 3,\n} as const;\n\n/**\n * Serializer mode for response body serialization.\n * - 'json': Use prepareForJson, platform adapter handles JSON.stringify\n * - 'binary': Use toBinary JIT function for binary serialization\n * - 'stringifyJson': Use stringifyJson JIT function that do not mutates objects.\n */\nexport type SerializerMode = keyof typeof SerializerModes;\nexport type SerializerCode = (typeof SerializerModes)[SerializerMode];\n\n// ########################################## Options ##########################################\n\nexport type CoreRouterOptions = {\n /** automatically generate and uuid */\n autoGenerateErrorId: boolean;\n /** basePath for all routes */\n basePath: string;\n /** suffix for all routes, ie file extension etc */\n suffix: string;\n};\n\n// ########################################## Errors ##########################################\n\n/** Base parameters for TypedError */\nexport interface TypedErrorParams<ErrType extends StrNumber> {\n /** Error type, can be used as discriminator in union types switch, etc*/\n type: ErrType;\n /** the error message */\n message?: string;\n /** original error used to create the TypedError */\n originalError?: Error;\n}\n\n/** Any error triggered by middleFns or routes must follow this interface, returned errors in the body also follows this interface */\nexport interface RpcErrorParams<ErrType extends StrNumber, ErrData = any> {\n /** Error type, can be used as discriminator in union types switch, etc*/\n type: ErrType;\n /** id of the error. */\n id?: number | string;\n /** the message that will be returned in the response */\n publicMessage?: string;\n /**\n * the error message, it is private and wont be returned in the response.\n * If not defined, it is assigned from originalError.message or publicMessage.\n */\n message?: string;\n /** options data related to the error, ie validation data */\n errorData?: ErrData;\n /** original error used to create the RpcError */\n originalError?: Error;\n /** optional http status code */\n statusCode?: number;\n}\n\nexport interface RpcErrorWithPublic<ErrType extends StrNumber, ErrData = any> extends RpcErrorParams<ErrType, ErrData> {\n publicMessage: string;\n}\n\nexport interface RpcErrorWithPrivate<ErrType extends StrNumber, ErrData = any> extends RpcErrorParams<ErrType, ErrData> {\n message: string;\n}\n\n/** Error data returned to the clients */\nexport interface PublicRpcError<ErrType extends StrNumber, ErrData = any> extends Omit<\n RpcErrorParams<ErrType, ErrData>,\n 'message' | 'originalError'\n> {\n readonly 'mion@isΣrrθr': true;\n type: ErrType;\n errorData?: ErrData;\n /**\n * When a RpcError gets sent to client only publicMessage is set.\n * */\n publicMessage: string;\n}\n\nexport type AnyErrorParams<ErrType extends StrNumber, ErrData = any> =\n | RpcErrorWithPublic<ErrType, ErrData>\n | RpcErrorWithPrivate<ErrType, ErrData>;\n\n/** Path segment for Map key errors */\nexport type MapKeyPathSegment = {key: unknown; index: number; failed: 'mapKey'};\n\n/** Path segment for Map value errors */\nexport type MapValuePathSegment = {key: unknown; index: number; failed: 'mapVal'};\n\n/** Path segment for Set item errors */\nexport type SetItemPathSegment = {key: unknown; index: number};\n\n/** Any path segment in a RunTypeError path */\nexport type PathSegment = StrNumber | MapKeyPathSegment | MapValuePathSegment | SetItemPathSegment;\n\nexport interface RunTypeError {\n /**\n * Path to the property that failed validation if the validated item was an object class, etc..\n * Index if item that failed validation was in an array.\n * For Maps: contains {key, index, failed: 'mapKey'|'mapVal'} objects.\n * For Sets: contains {key, index} objects.\n * Empty array if validated item was a single property */\n path: PathSegment[];\n /** the type of the expected data */\n expected: string;\n format?: TypeFormatError;\n // typeName?: string; // tyeName can not be included as two types could Have the same typeID and different names\n}\n\n// ########################################### JIT FUNCTIONS ###########################################\n\n/**\n * The argument names of the function to be compiled. The order of properties is important as must the same as the function args.\n * ie: {vλl: 'val', arg1: 'arg1', error: 'newRunTypeErr'} for the function (vλl, arg1, eArr) => any\n */\nexport type JitFnArgs = {\n /** The name of the value of to be */\n vλl: string;\n /** Other argument names */\n [key: string]: string;\n};\n\nexport interface JitCompiledFnData {\n readonly typeName: string;\n /** The id of the function (operation) to be compiled (isType, typeErrors, prepareForJson, restoreFromJson, etc) */\n readonly fnID: string;\n /** Unique id of the function */\n readonly jitFnHash: string;\n /** The names of the arguments of the function */\n readonly args: JitFnArgs;\n /** Default values for the arguments */\n readonly defaultParamValues: JitFnArgs;\n /**\n * This flag is set to true when the result of a jit compilation is a no operation (empty function).\n * if this flag is set to true, the function should not be called as it will not do anything.\n */\n readonly isNoop?: boolean;\n /** Code for the jit function. after the operation has been compiled */\n readonly code: string;\n /** The list of all jit functions that are used by this function and it's children. */\n readonly jitDependencies: Array<string>;\n /** Pure function dependencies in format \"namespace::fnHash\" */\n readonly pureFnDependencies: Array<string>;\n /** function param names if the compiled type is function params */\n paramNames?: string[];\n}\n\nexport interface JitCompiledFn<Fn extends AnyFn = AnyFn> extends JitCompiledFnData {\n /** The closure function that contains the jit function, this one contains the context code */\n readonly createJitFn: (utl: JITUtils) => Fn;\n /** The Jit Generated function once the compilation is finished */\n readonly fn: Fn;\n}\n\n/** Jit Functions serialized to src code file, it contains the create jit function\n * but not the actual fn as this one can not be serialized to code.\n */\nexport interface PersistedJitFn extends Omit<JitCompiledFn, 'fn'> {\n /** The Jit Generated function once the compilation is finished */\n readonly fn: undefined;\n}\n\nexport interface JitCompiledFunctions {\n isType: JitCompiledFn<IsTypeFn>;\n typeErrors: JitCompiledFn<TypeErrorsFn>;\n prepareForJson: JitCompiledFn<PrepareForJsonFn>;\n restoreFromJson: JitCompiledFn<RestoreFromJsonFn>;\n stringifyJson: JitCompiledFn<JsonStringifyFn>;\n toBinary: JitCompiledFn<ToBinaryFn>;\n fromBinary: JitCompiledFn<FromBinaryFn>;\n}\nexport interface SerializableJITFunctions {\n isType: JitCompiledFnData;\n typeErrors: JitCompiledFnData;\n prepareForJson: JitCompiledFnData;\n restoreFromJson: JitCompiledFnData;\n stringifyJson: JitCompiledFnData;\n toBinary: JitCompiledFnData;\n fromBinary: JitCompiledFnData;\n}\nexport interface JitFunctionsHashes {\n isType: string;\n typeErrors: string;\n prepareForJson: string;\n restoreFromJson: string;\n stringifyJson: string;\n toBinary: string;\n fromBinary: string;\n}\nexport type JsonStringifyFn = (value: any) => JSONString;\nexport type RestoreFromJsonFn = (value: JSONValue) => any;\nexport type PrepareForJsonFn = (value: any) => JSONValue;\nexport type TypeErrorsFn = (value: any) => RunTypeError[];\nexport type IsTypeFn = (value: any) => boolean;\nexport type ToCodeFn = (value: any) => string;\n/** Binary serialization function - serializes value to the serializer context */\nexport type ToBinaryFn = (value: any, serializer: DataViewSerializer) => void;\n/** Binary deserialization function - deserializes from the deserializer context and returns the value */\nexport type FromBinaryFn = (value: undefined, deserializer: DataViewDeserializer) => any;\n\n// ############################# JIT CACHES ###################################\n\n// jit and pure functions at runtime, contains both createJitFn and fn\nexport type JitFunctionsCache = Record<string, JitCompiledFn>;\n/** Namespaced cache structure for pure functions: { namespace: { fnHash: CompiledPureFunction } } */\nexport type PureFunctionsCache = Record<string, Record<string, CompiledPureFunction>>;\n\n// jit and pure functions persisted to src code, contains createJitFn but not fn\n// this allow usage in environments that can not use eval or new Function()\nexport type PersistedJitFunctionsCache = Record<string, PersistedJitFn>;\n/** Namespaced cache structure for persisted pure functions */\nexport type PersistedPureFunctionsCache = Record<string, Record<string, PersistedPureFunction>>;\n\n// jit and pure functions data, does not contain createJitFn or fn\n// this is used to serialize over the network, but requires using new Function() to restore functionality\nexport type FnsDataCache = Record<string, JitCompiledFnData>;\n/** Namespaced cache structure for pure function data */\nexport type PureFnsDataCache = Record<string, Record<string, PureFunctionData>>;\n\n// ########################################### JIT SRC CODE ####################################\n\nexport interface SrcCodeJitCompiledFn extends JitCompiledFnData {\n /** The closure function that contains the jit function, this one contains the context code */\n readonly createJitFn: (utl: JITUtils) => AnyFn;\n /** The Jit Generated function once the compilation is finished */\n readonly fn: undefined;\n}\nexport interface SrcCodeCompiledPureFunction extends PureFunctionData {\n /** The closure function that contains the pure function, this one contains the context code */\n readonly createPureFn: (utl: JITUtils) => AnyFn;\n /** The Jit Generated function once the compilation is finished */\n readonly fn: undefined;\n}\nexport type SrcCodeJITCompiledFnsCache = Record<string, SrcCodeJitCompiledFn>;\nexport type SrcCodePureFunctionsCache = Record<string, Record<string, SrcCodeCompiledPureFunction>>;\n\n// ########################################## other #########################################\n\nexport type StrNumber = string | number;\nexport type AnyFn = (...args: any[]) => any;\nexport type AnyObject = Record<string, unknown>;\nexport interface AnyClass<T = any> {\n new (...args: any[]): T;\n}\n\nexport interface SerializableClass<T = any> {\n new (): T;\n}\n\nexport type DeserializeClassFn<C extends InstanceType<AnyClass>> = (deserialized: DataOnly<C>) => C;\n\nexport type Mutable<T> = {\n -readonly [P in keyof T]: T[P];\n};\n\nexport type Prettify<T> = {\n [P in keyof T]: T[P];\n} & {};\n\n// StrNumber is already defined at the top of the file\nexport type JSONValue = StrNumber | boolean | null | {[key: string]: JSONValue} | Array<JSONValue>;\nexport type JSONString = string;\n\n// prettier-ignore\ntype Native = Date | RegExp | URL | URLSearchParams | Blob | File | FileList | FormData | ArrayBuffer | SharedArrayBuffer | DataView | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;\n\n/** Typescript mapping type that stripes methods and only keep properties.\n * it takes into account, dates, objects, classes, arrays, maps and sets.\n */\nexport type DataOnly<T> = T extends object\n ? T extends Native\n ? T\n : T extends Function\n ? never\n : T extends new (...args: any[]) => any\n ? never\n : T extends Array<infer U>\n ? Array<DataOnly<U>>\n : T extends Map<infer K, infer V>\n ? Map<DataOnly<K>, DataOnly<V>>\n : T extends Set<infer U>\n ? Set<DataOnly<U>>\n : {[K in keyof T as T[K] extends Function ? never : K]: DataOnly<T[K]>}\n : T;\n\n// TEST TYPES FOR PlainObject\n\n// class A {\n// n1?: number;\n// s?: string;\n// d?: Date;\n// map?: Map<string, RegExp>;\n// set?: Set<URL>;\n// arr?: A[];\n// method() {\n// return 'hello';\n// }\n// arrow = () => 'hello';\n// }\n\n// type PlainInterface = PlainObject<{\n// n1: number;\n// s: string;\n// d: Date;\n// a: A;\n// map: Map<string, A>;\n// set: Set<A>;\n// arr: A[];\n// method(): string;\n// arrow: () => string;\n// }>;\n\n// type PlainClass = PlainObject<A>;\n// type PlainSet = PlainObject<Set<A>>;\n// type PlainMap = PlainObject<Map<string, A>>;\n\n// ################# BINARY SERIALIZATION - IMPORTANT NOTE ##################################\n// DO NOT CHANGE THE INTERFACE NAMES AS THEY ARE HARDCODED IN THE JIT GENERATED CODE\n// ##########################################################################################\n\nexport type StrictArrayBuffer = ArrayBuffer & {buffer?: undefined};\n/** Input type for binary deserialization - accepts ArrayBuffer or any typed array view (including Node.js Buffer) */\nexport type BinaryInput = ArrayBuffer | ArrayBufferView;\nexport interface DataViewSerializer {\n index: number; // byte offset\n view: DataView;\n reset: () => void;\n getBuffer: () => StrictArrayBuffer;\n getBufferView: () => Uint8Array;\n markAsEnded: () => void;\n getLength(): number;\n // serialization functions\n serString(str: string): void;\n serFloat64(n: number): void;\n serEnum(n: number | string): void;\n setBitMask(bitMaskIndex: number, bitIndex: number): void;\n}\n\nexport interface DataViewDeserializer {\n index: number; // byte offset\n view: DataView;\n reset: () => void;\n setBuffer: (buffer: StrictArrayBuffer, byteOffset?: number, byteLength?: number) => void;\n markAsEnded: () => void;\n getLength(): number;\n // deserialization functions\n desString(): string;\n desFloat64(): number;\n desEnum(): number | string;\n}\n\nexport type MimeTypes = (typeof MIME_TYPES)[keyof typeof MIME_TYPES];\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAeO,MAAM,kBAAkB;AAAA;AAAA,EAE3B,MAAM;AAAA;AAAA,EAEN,QAAQ;AAAA;AAAA,EAER,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"general.types.js","sources":["../../../../src/types/general.types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-function-type */\n/* ###############\n * 2022 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ############### */\n\nimport {MIME_TYPES} from '../constants.ts';\nimport {TypeFormatError} from './formats/formats.types.ts';\nimport type {JITUtils} from '../jit/jitUtils.ts';\nimport {CompiledPureFunction, PersistedPureFunction, PureFunctionData} from './pureFunctions.types.ts';\n\n// ########################################## Serialization Modes ##########################################\n\nexport const SerializerModes = {\n /** Use prepareForJson (mutates original objects), and leaves JSON.stringify to the platform adapter */\n json: 1,\n /** Use toBinary JIT function for binary serialization */\n binary: 2,\n /** Use stringifyJson JIT function that do not mutates objects. */\n stringifyJson: 3,\n /** Client-only: sends plain JSON without JIT, fetches metadata in the same response */\n optimistic: 4,\n} as const;\n\n/**\n * Serializer mode for response body serialization.\n * - 'json': Use prepareForJson, platform adapter handles JSON.stringify\n * - 'binary': Use toBinary JIT function for binary serialization\n * - 'stringifyJson': Use stringifyJson JIT function that do not mutates objects.\n */\nexport type SerializerMode = keyof typeof SerializerModes;\nexport type SerializerCode = (typeof SerializerModes)[SerializerMode];\n\n// ########################################## Options ##########################################\n\nexport type CoreRouterOptions = {\n /** automatically generate and uuid */\n autoGenerateErrorId: boolean;\n /** basePath for all routes */\n basePath: string;\n /** suffix for all routes, ie file extension etc */\n suffix: string;\n};\n\n// ########################################## Errors ##########################################\n\n/** Base parameters for TypedError */\nexport interface TypedErrorParams<ErrType extends StrNumber> {\n /** Error type, can be used as discriminator in union types switch, etc*/\n type: ErrType;\n /** the error message */\n message?: string;\n /** original error used to create the TypedError */\n originalError?: Error;\n}\n\n/** Any error triggered by middleFns or routes must follow this interface, returned errors in the body also follows this interface */\nexport interface RpcErrorParams<ErrType extends StrNumber, ErrData = any> {\n /** Error type, can be used as discriminator in union types switch, etc*/\n type: ErrType;\n /** id of the error. */\n id?: number | string;\n /** the message that will be returned in the response */\n publicMessage?: string;\n /**\n * the error message, it is private and wont be returned in the response.\n * If not defined, it is assigned from originalError.message or publicMessage.\n */\n message?: string;\n /** options data related to the error, ie validation data */\n errorData?: ErrData;\n /** original error used to create the RpcError */\n originalError?: Error;\n /** optional http status code */\n statusCode?: number;\n}\n\nexport interface RpcErrorWithPublic<ErrType extends StrNumber, ErrData = any> extends RpcErrorParams<ErrType, ErrData> {\n publicMessage: string;\n}\n\nexport interface RpcErrorWithPrivate<ErrType extends StrNumber, ErrData = any> extends RpcErrorParams<ErrType, ErrData> {\n message: string;\n}\n\n/** Error data returned to the clients */\nexport interface PublicRpcError<ErrType extends StrNumber, ErrData = any> extends Omit<\n RpcErrorParams<ErrType, ErrData>,\n 'message' | 'originalError'\n> {\n readonly 'mion@isΣrrθr': true;\n type: ErrType;\n errorData?: ErrData;\n /**\n * When a RpcError gets sent to client only publicMessage is set.\n * */\n publicMessage: string;\n}\n\nexport type AnyErrorParams<ErrType extends StrNumber, ErrData = any> =\n | RpcErrorWithPublic<ErrType, ErrData>\n | RpcErrorWithPrivate<ErrType, ErrData>;\n\n/** Path segment for Map key errors */\nexport type MapKeyPathSegment = {key: unknown; index: number; failed: 'mapKey'};\n\n/** Path segment for Map value errors */\nexport type MapValuePathSegment = {key: unknown; index: number; failed: 'mapVal'};\n\n/** Path segment for Set item errors */\nexport type SetItemPathSegment = {key: unknown; index: number};\n\n/** Any path segment in a RunTypeError path */\nexport type PathSegment = StrNumber | MapKeyPathSegment | MapValuePathSegment | SetItemPathSegment;\n\nexport interface RunTypeError {\n /**\n * Path to the property that failed validation if the validated item was an object class, etc..\n * Index if item that failed validation was in an array.\n * For Maps: contains {key, index, failed: 'mapKey'|'mapVal'} objects.\n * For Sets: contains {key, index} objects.\n * Empty array if validated item was a single property */\n path: PathSegment[];\n /** the type of the expected data */\n expected: string;\n format?: TypeFormatError;\n // typeName?: string; // tyeName can not be included as two types could Have the same typeID and different names\n}\n\n// ########################################### JIT FUNCTIONS ###########################################\n\n/**\n * The argument names of the function to be compiled. The order of properties is important as must the same as the function args.\n * ie: {vλl: 'val', arg1: 'arg1', error: 'newRunTypeErr'} for the function (vλl, arg1, eArr) => any\n */\nexport type JitFnArgs = {\n /** The name of the value of to be */\n vλl: string;\n /** Other argument names */\n [key: string]: string;\n};\n\nexport interface JitCompiledFnData {\n readonly typeName: string;\n /** The id of the function (operation) to be compiled (isType, typeErrors, prepareForJson, restoreFromJson, etc) */\n readonly fnID: string;\n /** Unique id of the function */\n readonly jitFnHash: string;\n /** The names of the arguments of the function */\n readonly args: JitFnArgs;\n /** Default values for the arguments */\n readonly defaultParamValues: JitFnArgs;\n /**\n * This flag is set to true when the result of a jit compilation is a no operation (empty function).\n * if this flag is set to true, the function should not be called as it will not do anything.\n */\n readonly isNoop?: boolean;\n /** Code for the jit function. after the operation has been compiled */\n readonly code: string;\n /** The list of all jit functions that are used by this function and it's children. */\n readonly jitDependencies?: Array<string>;\n /** Pure function dependencies in format \"namespace::fnHash\" */\n readonly pureFnDependencies?: Array<string>;\n /** function param names if the compiled type is function params */\n paramNames?: string[];\n}\n\nexport interface JitCompiledFn<Fn extends AnyFn = AnyFn> extends JitCompiledFnData {\n /** The closure function that contains the jit function, this one contains the context code */\n readonly createJitFn: (utl: JITUtils) => Fn;\n /** The Jit Generated function once the compilation is finished */\n readonly fn: Fn;\n}\n\n/** Jit Functions serialized to src code file, it contains the create jit function\n * but not the actual fn as this one can not be serialized to code.\n */\nexport interface PersistedJitFn extends Omit<JitCompiledFn, 'fn'> {\n /** The Jit Generated function once the compilation is finished */\n readonly fn: undefined;\n}\n\nexport interface JitCompiledFunctions {\n isType: JitCompiledFn<IsTypeFn>;\n typeErrors: JitCompiledFn<TypeErrorsFn>;\n prepareForJson: JitCompiledFn<PrepareForJsonFn>;\n restoreFromJson: JitCompiledFn<RestoreFromJsonFn>;\n stringifyJson: JitCompiledFn<JsonStringifyFn>;\n toBinary?: JitCompiledFn<ToBinaryFn>;\n fromBinary?: JitCompiledFn<FromBinaryFn>;\n}\nexport interface SerializableJITFunctions {\n isType: JitCompiledFnData;\n typeErrors: JitCompiledFnData;\n prepareForJson: JitCompiledFnData;\n restoreFromJson: JitCompiledFnData;\n stringifyJson: JitCompiledFnData;\n toBinary?: JitCompiledFnData;\n fromBinary?: JitCompiledFnData;\n}\nexport interface JitFunctionsHashes {\n isType: string;\n typeErrors: string;\n prepareForJson: string;\n restoreFromJson: string;\n stringifyJson: string;\n toBinary?: string;\n fromBinary?: string;\n}\nexport type JsonStringifyFn = (value: any) => JSONString;\nexport type RestoreFromJsonFn = (value: JSONValue) => any;\nexport type PrepareForJsonFn = (value: any) => JSONValue;\nexport type TypeErrorsFn = (value: any) => RunTypeError[];\nexport type IsTypeFn = (value: any) => boolean;\nexport type ToCodeFn = (value: any) => string;\n/** Binary serialization function - serializes value to the serializer context */\nexport type ToBinaryFn = (value: any, serializer: DataViewSerializer) => void;\n/** Binary deserialization function - deserializes from the deserializer context and returns the value */\nexport type FromBinaryFn = (value: undefined, deserializer: DataViewDeserializer) => any;\n\n// ############################# JIT CACHES ###################################\n\n// jit and pure functions at runtime, contains both createJitFn and fn\nexport type JitFunctionsCache = Record<string, JitCompiledFn>;\n/** Namespaced cache structure for pure functions: { namespace: { fnHash: CompiledPureFunction } } */\nexport type PureFunctionsCache = Record<string, Record<string, CompiledPureFunction>>;\n\n// jit and pure functions persisted to src code, contains createJitFn but not fn\n// this allow usage in environments that can not use eval or new Function()\nexport type PersistedJitFunctionsCache = Record<string, PersistedJitFn>;\n/** Namespaced cache structure for persisted pure functions */\nexport type PersistedPureFunctionsCache = Record<string, Record<string, PersistedPureFunction>>;\n\n// jit and pure functions data, does not contain createJitFn or fn\n// this is used to serialize over the network, but requires using new Function() to restore functionality\nexport type FnsDataCache = Record<string, JitCompiledFnData>;\n/** Namespaced cache structure for pure function data */\nexport type PureFnsDataCache = Record<string, Record<string, PureFunctionData>>;\n\n// ########################################### JIT SRC CODE ####################################\n\nexport interface SrcCodeJitCompiledFn extends JitCompiledFnData {\n /** The closure function that contains the jit function, this one contains the context code */\n readonly createJitFn: (utl: JITUtils) => AnyFn;\n /** The Jit Generated function once the compilation is finished */\n readonly fn: undefined;\n}\nexport interface SrcCodeCompiledPureFunction extends PureFunctionData {\n /** The closure function that contains the pure function, this one contains the context code */\n readonly createPureFn: (utl: JITUtils) => AnyFn;\n /** The Jit Generated function once the compilation is finished */\n readonly fn: undefined;\n}\nexport type SrcCodeJITCompiledFnsCache = Record<string, SrcCodeJitCompiledFn>;\nexport type SrcCodePureFunctionsCache = Record<string, Record<string, SrcCodeCompiledPureFunction>>;\n\n/** Client version of SrcCodeJitCompiledFn - strips unused properties to reduce bundle size */\nexport type ClientSrcCodeJitCompiledFn = Omit<\n SrcCodeJitCompiledFn,\n 'code' | 'args' | 'defaultParamValues' | 'fnID' | 'paramNames'\n>;\n/** Client version of SrcCodeCompiledPureFunction - strips unused properties to reduce bundle size */\nexport type ClientSrcCodeCompiledPureFunction = Omit<SrcCodeCompiledPureFunction, 'code' | 'paramNames'>;\nexport type ClientSrcCodeJITCompiledFnsCache = Record<string, ClientSrcCodeJitCompiledFn>;\nexport type ClientSrcCodePureFunctionsCache = Record<string, Record<string, ClientSrcCodeCompiledPureFunction>>;\n\n// ########################################## other #########################################\n\nexport type StrNumber = string | number;\nexport type AnyFn = (...args: any[]) => any;\nexport type AnyObject = Record<string, unknown>;\nexport interface AnyClass<T = any> {\n new (...args: any[]): T;\n}\n\nexport interface SerializableClass<T = any> {\n new (): T;\n}\n\nexport type DeserializeClassFn<C extends InstanceType<AnyClass>> = (deserialized: DataOnly<C>) => C;\n\nexport type Mutable<T> = {\n -readonly [P in keyof T]: T[P];\n};\n\nexport type Prettify<T> = {\n [P in keyof T]: T[P];\n} & {};\n\n// StrNumber is already defined at the top of the file\nexport type JSONValue = StrNumber | boolean | null | {[key: string]: JSONValue} | Array<JSONValue>;\nexport type JSONString = string;\n\n// prettier-ignore\ntype Native = Date | RegExp | URL | URLSearchParams | Blob | File | FileList | FormData | ArrayBuffer | SharedArrayBuffer | DataView | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;\n\n/** Typescript mapping type that stripes methods and only keep properties.\n * it takes into account, dates, objects, classes, arrays, maps and sets.\n */\nexport type DataOnly<T> = T extends object\n ? T extends Native\n ? T\n : T extends Function\n ? never\n : T extends new (...args: any[]) => any\n ? never\n : T extends Array<infer U>\n ? Array<DataOnly<U>>\n : T extends Map<infer K, infer V>\n ? Map<DataOnly<K>, DataOnly<V>>\n : T extends Set<infer U>\n ? Set<DataOnly<U>>\n : {[K in keyof T as T[K] extends Function ? never : K]: DataOnly<T[K]>}\n : T;\n\n// TEST TYPES FOR PlainObject\n\n// class A {\n// n1?: number;\n// s?: string;\n// d?: Date;\n// map?: Map<string, RegExp>;\n// set?: Set<URL>;\n// arr?: A[];\n// method() {\n// return 'hello';\n// }\n// arrow = () => 'hello';\n// }\n\n// type PlainInterface = PlainObject<{\n// n1: number;\n// s: string;\n// d: Date;\n// a: A;\n// map: Map<string, A>;\n// set: Set<A>;\n// arr: A[];\n// method(): string;\n// arrow: () => string;\n// }>;\n\n// type PlainClass = PlainObject<A>;\n// type PlainSet = PlainObject<Set<A>>;\n// type PlainMap = PlainObject<Map<string, A>>;\n\n// ################# BINARY SERIALIZATION - IMPORTANT NOTE ##################################\n// DO NOT CHANGE THE INTERFACE NAMES AS THEY ARE HARDCODED IN THE JIT GENERATED CODE\n// ##########################################################################################\n\nexport type StrictArrayBuffer = ArrayBuffer & {buffer?: undefined};\n/** Input type for binary deserialization - accepts ArrayBuffer or any typed array view (including Node.js Buffer) */\nexport type BinaryInput = ArrayBuffer | ArrayBufferView;\nexport interface DataViewSerializer {\n index: number; // byte offset\n view: DataView;\n reset: () => void;\n getBuffer: () => StrictArrayBuffer;\n getBufferView: () => Uint8Array;\n markAsEnded: () => void;\n getLength(): number;\n // serialization functions\n serString(str: string): void;\n serFloat64(n: number): void;\n serEnum(n: number | string): void;\n setBitMask(bitMaskIndex: number, bitIndex: number): void;\n}\n\nexport interface DataViewDeserializer {\n index: number; // byte offset\n view: DataView;\n reset: () => void;\n setBuffer: (buffer: StrictArrayBuffer, byteOffset?: number, byteLength?: number) => void;\n markAsEnded: () => void;\n getLength(): number;\n // deserialization functions\n desString(): string;\n desFloat64(): number;\n desEnum(): number | string;\n}\n\nexport type MimeTypes = (typeof MIME_TYPES)[keyof typeof MIME_TYPES];\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAeO,MAAM,kBAAkB;AAAA;AAAA,EAE3B,MAAM;AAAA;AAAA,EAEN,QAAQ;AAAA;AAAA,EAER,eAAe;AAAA;AAAA,EAEf,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -13,7 +13,7 @@ export interface PureFunctionData {
13
13
  readonly code: string;
14
14
  readonly fnName: string;
15
15
  readonly bodyHash: string;
16
- readonly pureFnDependencies: Array<string>;
16
+ readonly pureFnDependencies?: Array<string>;
17
17
  }
18
18
  export interface CompiledPureFunction extends PureFunctionData {
19
19
  createPureFn: PureFunctionFactory;
@@ -9,7 +9,7 @@ const __ΩGenericPureFunction = ["P", "val", "formatParams", () => __ΩPureFunct
9
9
  const __ΩErrorsPureFunction = ["P", "val", () => __ΩStrNumber, "pλth", () => ___RunTypeError, "εrr", "expected", "formatName", "formatParams", () => __ΩStrNumber, "formatPath", () => __ΩPureFunctionDeps, "deps", () => __ΩStrNumber, "accessPath", () => __ΩStrNumber, "fmtAccessPath", () => ___RunTypeError, "", "ErrorsPureFunction", `b!P"2"n#F2$n%F2&&2'&2(e"!2)n*F2+n,2-n.F2/8n0F218n2F/3w4y`];
10
10
  const __ΩPureFunction = ["args", "", "PureFunction", 'P"@2!"/"w#y'];
11
11
  const __ΩPureFunctionFactory = ["JITUtils", "jitUtils", () => __ΩPureFunction, "", "PureFunctionFactory", 'P"w!2"n#/$w%y'];
12
- const __ΩPureFunctionData = ["namespace", "paramNames", "code", "fnName", "bodyHash", "pureFnDependencies", "PureFunctionData", `P&4!9&F4"9&4#9&4$9&4%9&F4&9Mw'y`];
12
+ const __ΩPureFunctionData = ["namespace", "paramNames", "code", "fnName", "bodyHash", "pureFnDependencies", "PureFunctionData", `P&4!9&F4"9&4#9&4$9&4%9&F4&89Mw'y`];
13
13
  const __ΩCompiledPureFunction = [() => __ΩPureFunctionData, () => __ΩPureFunctionFactory, "createPureFn", () => __ΩPureFunction, "fn", "CompiledPureFunction", 'Pn!n"4#n$4%8Mw&y'];
14
14
  const __ΩPersistedPureFunction = [() => __ΩCompiledPureFunction, "fn", "PersistedPureFunction", 'Pn!-4"Mw#y'];
15
15
  const __ΩPureFnDef = ["args", "", "F", "namespace", "fnName", "isFactory", "pureFn", "PureFnDef", `P"@2!"/"c#P&4$89&4%89)4&8e"!4'9Mw(y`];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mionjs/core",
3
- "version": "0.8.4-alpha.0",
3
+ "version": "0.8.6",
4
4
  "type": "module",
5
5
  "description": "Core functionality required across multiple mion packages",
6
6
  "keywords": [
@@ -66,5 +66,5 @@
66
66
  "bugs": {
67
67
  "url": "https://github.com/MionKit/mion/issues"
68
68
  },
69
- "gitHead": "26f07a965e43529d4255e6f2ac8a633513026314"
69
+ "gitHead": "612302e243365c01fadbf3351b857174bf2f3956"
70
70
  }