@mionjs/client 0.8.0-alpha.0 → 0.8.4
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 +1 -1
- package/.dist/cjs/index.d.ts +7 -6
- package/.dist/cjs/src/client.cjs +1 -1
- package/.dist/cjs/src/client.cjs.map +1 -1
- package/.dist/cjs/src/client.d.ts +9 -7
- package/.dist/cjs/src/constants.cjs +1 -1
- package/.dist/cjs/src/constants.cjs.map +1 -1
- package/.dist/cjs/src/constants.d.ts +1 -1
- package/.dist/cjs/src/lib/clientMethodsMetadata.cjs +2 -0
- package/.dist/cjs/src/lib/clientMethodsMetadata.cjs.map +1 -0
- package/.dist/cjs/src/lib/clientMethodsMetadata.d.ts +10 -0
- package/.dist/cjs/src/lib/fetchRemoteMethodsMetadata.cjs +2 -0
- package/.dist/cjs/src/lib/fetchRemoteMethodsMetadata.cjs.map +1 -0
- package/.dist/cjs/src/lib/fetchRemoteMethodsMetadata.d.ts +2 -0
- package/.dist/cjs/src/{handlersRegistry.cjs → lib/handlersRegistry.cjs} +1 -1
- package/.dist/cjs/src/lib/handlersRegistry.cjs.map +1 -0
- package/.dist/cjs/src/{handlersRegistry.d.ts → lib/handlersRegistry.d.ts} +1 -1
- package/.dist/cjs/src/lib/serializer.cjs +2 -0
- package/.dist/cjs/src/lib/serializer.cjs.map +1 -0
- package/.dist/{esm/src → cjs/src/lib}/serializer.d.ts +3 -5
- package/.dist/cjs/src/lib/storage.cjs +2 -0
- package/.dist/cjs/src/lib/storage.cjs.map +1 -0
- package/.dist/cjs/src/lib/testUtils.cjs +2 -0
- package/.dist/cjs/src/lib/testUtils.cjs.map +1 -0
- package/.dist/cjs/src/lib/typedEvent.cjs +2 -0
- package/.dist/cjs/src/lib/typedEvent.cjs.map +1 -0
- package/.dist/{esm/src → cjs/src/lib}/typedEvent.d.ts +1 -1
- package/.dist/cjs/src/lib/validation.cjs +2 -0
- package/.dist/cjs/src/lib/validation.cjs.map +1 -0
- package/.dist/cjs/src/{validation.d.ts → lib/validation.d.ts} +2 -2
- package/.dist/cjs/src/request.cjs +1 -1
- package/.dist/cjs/src/request.cjs.map +1 -1
- package/.dist/cjs/src/request.d.ts +10 -4
- package/.dist/cjs/src/routesFlow.cjs +1 -1
- package/.dist/cjs/src/routesFlow.cjs.map +1 -1
- package/.dist/cjs/src/routesFlow.d.ts +2 -2
- package/.dist/cjs/src/subRequest.cjs +1 -1
- package/.dist/cjs/src/subRequest.cjs.map +1 -1
- package/.dist/cjs/src/subRequest.d.ts +5 -6
- package/.dist/cjs/src/types.cjs +1 -1
- package/.dist/cjs/src/types.d.ts +55 -64
- package/.dist/esm/index.d.ts +7 -6
- package/.dist/esm/index.js +10 -48
- package/.dist/esm/src/client.d.ts +9 -7
- package/.dist/esm/src/client.js +32 -58
- package/.dist/esm/src/client.js.map +1 -1
- package/.dist/esm/src/constants.d.ts +1 -1
- package/.dist/esm/src/constants.js +1 -1
- package/.dist/esm/src/constants.js.map +1 -1
- package/.dist/esm/src/lib/clientMethodsMetadata.d.ts +10 -0
- package/.dist/esm/src/lib/clientMethodsMetadata.js +125 -0
- package/.dist/esm/src/lib/clientMethodsMetadata.js.map +1 -0
- package/.dist/esm/src/lib/fetchRemoteMethodsMetadata.d.ts +2 -0
- package/.dist/esm/src/lib/fetchRemoteMethodsMetadata.js +31 -0
- package/.dist/esm/src/lib/fetchRemoteMethodsMetadata.js.map +1 -0
- package/.dist/esm/src/{handlersRegistry.d.ts → lib/handlersRegistry.d.ts} +1 -1
- package/.dist/esm/src/{handlersRegistry.js → lib/handlersRegistry.js} +0 -5
- package/.dist/esm/src/lib/handlersRegistry.js.map +1 -0
- package/.dist/{cjs/src → esm/src/lib}/serializer.d.ts +3 -5
- package/.dist/esm/src/{serializer.js → lib/serializer.js} +88 -72
- package/.dist/esm/src/lib/serializer.js.map +1 -0
- package/.dist/esm/src/{storage.js → lib/storage.js} +1 -6
- package/.dist/esm/src/lib/storage.js.map +1 -0
- package/.dist/esm/src/lib/testUtils.js +11 -0
- package/.dist/esm/src/lib/testUtils.js.map +1 -0
- package/.dist/{cjs/src → esm/src/lib}/typedEvent.d.ts +1 -1
- package/.dist/esm/src/{typedEvent.js → lib/typedEvent.js} +0 -2
- package/.dist/esm/src/lib/typedEvent.js.map +1 -0
- package/.dist/esm/src/{validation.d.ts → lib/validation.d.ts} +2 -2
- package/.dist/esm/src/{validation.js → lib/validation.js} +3 -10
- package/.dist/esm/src/lib/validation.js.map +1 -0
- package/.dist/esm/src/request.d.ts +10 -4
- package/.dist/esm/src/request.js +123 -78
- package/.dist/esm/src/request.js.map +1 -1
- package/.dist/esm/src/routesFlow.d.ts +2 -2
- package/.dist/esm/src/routesFlow.js +13 -14
- package/.dist/esm/src/routesFlow.js.map +1 -1
- package/.dist/esm/src/subRequest.d.ts +5 -6
- package/.dist/esm/src/subRequest.js +13 -28
- package/.dist/esm/src/subRequest.js.map +1 -1
- package/.dist/esm/src/types.d.ts +55 -64
- package/.dist/esm/src/types.js +1 -41
- package/.dist/esm/src/types.js.map +1 -1
- package/package.json +8 -14
- package/.dist/cjs/_virtual/jit-fns.cjs +0 -315
- package/.dist/cjs/_virtual/jit-fns.cjs.map +0 -1
- package/.dist/cjs/_virtual/pure-fns.cjs +0 -56
- package/.dist/cjs/_virtual/pure-fns.cjs.map +0 -1
- package/.dist/cjs/_virtual/router-cache.cjs +0 -2
- package/.dist/cjs/_virtual/router-cache.cjs.map +0 -1
- package/.dist/cjs/src/aot/loadClientAOTCaches.cjs +0 -2
- package/.dist/cjs/src/aot/loadClientAOTCaches.cjs.map +0 -1
- package/.dist/cjs/src/aot/loadClientAOTCaches.d.ts +0 -8
- package/.dist/cjs/src/clientMethodsMetadata.cjs +0 -2
- package/.dist/cjs/src/clientMethodsMetadata.cjs.map +0 -1
- package/.dist/cjs/src/clientMethodsMetadata.d.ts +0 -10
- package/.dist/cjs/src/handlersRegistry.cjs.map +0 -1
- package/.dist/cjs/src/serializer.cjs +0 -2
- package/.dist/cjs/src/serializer.cjs.map +0 -1
- package/.dist/cjs/src/storage.cjs +0 -2
- package/.dist/cjs/src/storage.cjs.map +0 -1
- package/.dist/cjs/src/testUtils.cjs +0 -2
- package/.dist/cjs/src/testUtils.cjs.map +0 -1
- package/.dist/cjs/src/typedEvent.cjs +0 -2
- package/.dist/cjs/src/typedEvent.cjs.map +0 -1
- package/.dist/cjs/src/validation.cjs +0 -2
- package/.dist/cjs/src/validation.cjs.map +0 -1
- package/.dist/esm/_virtual/jit-fns.js +0 -1391
- package/.dist/esm/_virtual/jit-fns.js.map +0 -1
- package/.dist/esm/_virtual/pure-fns.js +0 -109
- package/.dist/esm/_virtual/pure-fns.js.map +0 -1
- package/.dist/esm/_virtual/router-cache.js +0 -5
- package/.dist/esm/_virtual/router-cache.js.map +0 -1
- package/.dist/esm/src/aot/loadClientAOTCaches.d.ts +0 -8
- package/.dist/esm/src/aot/loadClientAOTCaches.js +0 -19
- package/.dist/esm/src/aot/loadClientAOTCaches.js.map +0 -1
- package/.dist/esm/src/clientMethodsMetadata.d.ts +0 -10
- package/.dist/esm/src/clientMethodsMetadata.js +0 -162
- package/.dist/esm/src/clientMethodsMetadata.js.map +0 -1
- package/.dist/esm/src/handlersRegistry.js.map +0 -1
- package/.dist/esm/src/serializer.js.map +0 -1
- package/.dist/esm/src/storage.js.map +0 -1
- package/.dist/esm/src/testUtils.js +0 -48
- package/.dist/esm/src/testUtils.js.map +0 -1
- package/.dist/esm/src/typedEvent.js.map +0 -1
- package/.dist/esm/src/validation.js.map +0 -1
- /package/.dist/cjs/src/{storage.d.ts → lib/storage.d.ts} +0 -0
- /package/.dist/cjs/src/{testUtils.d.ts → lib/testUtils.d.ts} +0 -0
- /package/.dist/esm/src/{storage.d.ts → lib/storage.d.ts} +0 -0
- /package/.dist/esm/src/{testUtils.d.ts → lib/testUtils.d.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"request.cjs","sources":["../../../src/request.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 {ResponseBody} from '@mionjs/router';\nimport {\n ClientOptions,\n MiddlewareSubRequest,\n SubRequest,\n RouteSubRequest,\n RequestErrors,\n PrefilledMiddleFnsCache,\n} from './types.ts';\nimport type {RunTypeError, RoutesFlowQuery, RoutesFlowMapping} from '@mionjs/core';\nimport {RpcError, isRpcError, routesCache, MION_ROUTES, HandlerType, HeadersSubset, toBase64Url} from '@mionjs/core';\nimport type {SerializerMode} from '@mionjs/core';\nimport {getRoutePath} from '@mionjs/core';\nimport {fetchRemoteMethodsMetadata} from './lib/fetchRemoteMethodsMetadata.ts';\nimport {createMetadataSubRequest} from './lib/clientMethodsMetadata.ts';\nimport {validateSubRequests} from './lib/validation.ts';\nimport {serializeRequestBody, deserializeResponseBody} from './lib/serializer.ts';\nimport {ROUTES_FLOW_KEY, MAX_GET_URL_LENGTH} from './constants.ts';\n\nexport class MionClientRequest<RR extends RouteSubRequest<any>, MiddleFnRequestsList extends MiddlewareSubRequest<any>[]> {\n readonly path: string;\n readonly requestId: string;\n readonly subRequestList: {[key: string]: SubRequest<any>} = {};\n response: Response | undefined;\n\n constructor(\n public readonly options: ClientOptions,\n private readonly prefilledMiddleFnsCache: PrefilledMiddleFnsCache,\n public readonly route?: RR,\n public readonly middleFns?: MiddleFnRequestsList,\n /** Array of routesFlow subrequests when executing a routesFlow */\n public readonly workflowSubRequests?: RouteSubRequest<any>[],\n /** Composed abort signal for this request */\n public readonly signal?: AbortSignal\n ) {\n if (workflowSubRequests && workflowSubRequests.length > 0) {\n const routePaths = workflowSubRequests.map((sr) => getRoutePath(sr.pointer, this.options));\n const query = buildRoutesFlowQuery(routePaths, workflowSubRequests);\n const flowPath = getRoutePath([ROUTES_FLOW_KEY], this.options);\n this.path = `${flowPath}?data=${toBase64Url(JSON.stringify(query))}`;\n this.requestId = 'mion-routes-flow';\n workflowSubRequests.forEach((sr) => this.addSubRequest(sr));\n } else {\n this.path = route ? getRoutePath(route.pointer, this.options) : 'no-route';\n this.requestId = route ? route.id : 'no-route';\n if (route) this.addSubRequest(route);\n }\n if (middleFns) middleFns.forEach((middleFn) => this.addSubRequest(middleFn));\n }\n\n /** Calls a remote route */\n async call(): Promise<ResponseBody> {\n if (this.signal?.aborted) {\n const errors: RequestErrors = new Map();\n this.onError(\n this.signal.reason ?? new DOMException('This operation was aborted', 'AbortError'),\n 'Request aborted',\n errors\n );\n return Promise.reject(errors);\n }\n return this.makeCall(this.options.serializer);\n }\n\n /** Call flow that auto-detects missing metadata and uses optimistic serialization when needed */\n private async makeCall(originalSerializer: SerializerMode, skipOptimistic?: boolean): Promise<ResponseBody> {\n const errors: RequestErrors = new Map();\n const subRequestIds = Object.keys(this.subRequestList);\n const allCached = subRequestIds.every((id) => routesCache.hasMetadata(id));\n const isOptimistic = !allCached && !skipOptimistic;\n\n try {\n if (isOptimistic) {\n (this.options as any).serializer = 'optimistic';\n this.restorePrefilledMiddleFns();\n // Add metadata subrequest (after prefilled restore so we include all IDs)\n const allSubRequestIds = Object.keys(this.subRequestList);\n this.addSubRequest(createMetadataSubRequest(allSubRequestIds));\n } else {\n (this.options as any).serializer = originalSerializer;\n await fetchRemoteMethodsMetadata(subRequestIds, this.options, this.signal);\n this.restorePrefilledMiddleFns(errors);\n if (errors.size) return Promise.reject(errors);\n validateSubRequests(subRequestIds, this, errors);\n if (errors.size) return Promise.reject(errors);\n }\n } catch (error: any) {\n this.onError(error, 'Error preparing request', errors);\n return Promise.reject(errors);\n }\n\n try {\n let serialized: ReturnType<typeof serializeRequestBody>;\n try {\n serialized = serializeRequestBody(this);\n } catch (serializeError) {\n if (isOptimistic) {\n // JSON.stringify failed → fall back to standard, will fetch metadata\n delete this.subRequestList[MION_ROUTES.methodsMetadata];\n return this.makeCall(originalSerializer, true);\n }\n throw serializeError;\n }\n\n const headersFromParams = extractRequestHeaders(this);\n const url = new URL(this.path, this.options.baseURL);\n const fetchOptions = buildFetchOptions(\n url,\n serialized,\n headersFromParams,\n this.options,\n isOptimistic,\n this.isQueryRoute(),\n this.signal\n );\n this.response = await fetch(url, fetchOptions);\n } catch (error: any) {\n this.onError(error, 'Error executing request', errors);\n return Promise.reject(errors);\n }\n\n try {\n // If the signal already aborted while fetch was in flight, don't try to read a possibly\n // truncated response body — surface the abort directly.\n if (this.signal?.aborted) {\n this.onError(this.signal.reason, 'Request aborted', errors);\n return Promise.reject(errors);\n }\n const deserialized = await deserializeResponseBody(this.response, this.options);\n if (this.handlePlatformError(deserialized, errors)) return Promise.reject(errors);\n\n // Never retry an aborted request — the user explicitly canceled it.\n if (isOptimistic && !this.signal?.aborted && this.shouldRetryWithProperSerialization(deserialized)) {\n return this.retryWithProperSerialization(originalSerializer);\n }\n\n this.resolveSubRequests(deserialized, errors, isOptimistic ? MION_ROUTES.methodsMetadata : undefined);\n if (errors.size) return Promise.reject(errors);\n return deserialized;\n } catch (error) {\n this.onError(error, 'Error parsing response', errors);\n return Promise.reject(errors);\n }\n }\n\n /** Checks if the response contains errors that require retry with proper JIT serialization */\n private shouldRetryWithProperSerialization(deserialized: ResponseBody): boolean {\n return Object.values(deserialized).some(\n (value) =>\n isRpcError(value) &&\n (value.type === 'serialization-error' ||\n value.type === 'validation-error' ||\n value.type === 'parsing-json-request-error')\n );\n }\n\n /** Retries the request with proper JIT serialization after metadata has been cached */\n private async retryWithProperSerialization(originalSerializer: SerializerMode): Promise<ResponseBody> {\n delete this.subRequestList[MION_ROUTES.methodsMetadata];\n Object.values(this.subRequestList).forEach((sr) => {\n sr.isResolved = false;\n sr.resolvedValue = undefined;\n sr.error = undefined;\n });\n return this.makeCall(originalSerializer);\n }\n\n /** Validate params */\n async validateParams(subReqList?: SubRequest<any>[]): Promise<RunTypeError[]> {\n if (subReqList) subReqList.forEach((subRequest) => this.addSubRequest(subRequest));\n const errors: RequestErrors = new Map();\n try {\n const subRequestIds = Object.keys(this.subRequestList);\n await fetchRemoteMethodsMetadata(subRequestIds, this.options);\n validateSubRequests(subRequestIds, this, errors, false);\n return Object.values(this.subRequestList)\n .map((subRequest) => subRequest.error?.errorData || [])\n .flat();\n } catch (error: any) {\n this.onError(error, 'Error preparing request', errors);\n return Promise.reject(errors);\n }\n }\n\n /** Prefills and stores SubRequest */\n async prefill(subReqList?: SubRequest<any>[]): Promise<void> {\n if (subReqList) subReqList.forEach((subRequest) => this.addSubRequest(subRequest));\n const errors: RequestErrors = new Map();\n try {\n const subRequestIds = Object.keys(this.subRequestList);\n await fetchRemoteMethodsMetadata(subRequestIds, this.options);\n\n validateSubRequests(subRequestIds, this, errors, false);\n if (errors.size) return Promise.reject(errors);\n\n serializeRequestBody(this);\n\n this.storePrefilledMiddleFns(errors);\n if (errors.size) return Promise.reject(errors);\n\n return;\n } catch (error: any) {\n this.onError(error, 'Error preparing request', errors);\n return Promise.reject(errors);\n }\n }\n\n /** Removes Prefills and stores SubRequest */\n async removePrefill(subRequests?: SubRequest<any>[]): Promise<void> {\n if (subRequests) subRequests.forEach((subRequest) => this.addSubRequest(subRequest));\n this.removePrefilledMiddleFns();\n }\n\n addSubRequest(subRequest: SubRequest<any>) {\n if (subRequest.isResolved) throw new Error(`SubRequest ${subRequest.id} is already resolved`);\n this.subRequestList[subRequest.id] = subRequest;\n }\n\n /** Checks for platform-level errors and propagates them to all subrequests. Returns true if a platform error was found */\n private handlePlatformError(deserialized: ResponseBody, errors: RequestErrors): boolean {\n if (!(MION_ROUTES.platformError in deserialized)) return false;\n const platformError = deserialized[MION_ROUTES.platformError];\n Object.entries(this.subRequestList).forEach(([id, methodMeta]) => {\n methodMeta.isResolved = true;\n methodMeta.error = platformError as RpcError<string>;\n errors.set(id, platformError as RpcError<string>);\n });\n return true;\n }\n\n /** Resolves sub request values from the deserialized response body and collects errors */\n private resolveSubRequests(deserialized: ResponseBody, errors: RequestErrors, skipId?: string): void {\n Object.entries(this.subRequestList).forEach(([id, methodMeta]) => {\n if (id === skipId) return;\n const resp = this.getResponseValueFromBodyOrHeader(id, deserialized, (this.response as Response).headers);\n methodMeta.isResolved = true;\n if (isRpcError(resp)) {\n methodMeta.error = resp;\n errors.set(id, resp);\n } else {\n methodMeta.resolvedValue = resp;\n }\n });\n\n Object.entries(deserialized).forEach(([id, value]) => {\n if (!(id in this.subRequestList) && isRpcError(value)) {\n errors.set(id, value);\n }\n });\n }\n\n private onError(error: any, stageMessage: string, errors: RequestErrors): void {\n // Detect abort/timeout via signal.reason FIRST. We must do this before the isRpcError early return\n // because errors that surface from later stages (deserialization, retry, etc.) may already be\n // wrapped as RpcError but the user-facing reason is still abort/timeout.\n const reason = this.signal?.aborted ? this.signal.reason : undefined;\n if (reason instanceof DOMException) {\n if (reason.name === 'TimeoutError') {\n errors.set(\n this.requestId,\n new RpcError({\n type: 'request-timeout',\n publicMessage: 'Request timed out',\n originalError: error instanceof Error ? error : undefined,\n })\n );\n return;\n }\n if (reason.name === 'AbortError') {\n errors.set(\n this.requestId,\n new RpcError({\n type: 'request-aborted',\n publicMessage: 'Request was aborted',\n originalError: error instanceof Error ? error : undefined,\n })\n );\n return;\n }\n }\n if (isRpcError(error)) {\n errors.set(this.requestId, error);\n return;\n }\n const message = error?.message ? `${stageMessage}: ${error.message}` : `${stageMessage}: Unknown Error`;\n errors.set(\n this.requestId,\n new RpcError({\n type: error?.name || 'unknown-error',\n publicMessage: message,\n originalError: error instanceof Error ? error : undefined,\n })\n );\n }\n\n private getResponseValueFromBodyOrHeader(id: string, respBody: ResponseBody, headers: Headers): any {\n const headersSubset = reconstructHeadersSubsetFromResponse(id, headers);\n if (headersSubset) return headersSubset;\n return respBody[id];\n }\n\n /** When errors is omitted, silently skips routes without cached metadata (used by optimistic flow) */\n private restorePrefilledMiddleFns(errors?: RequestErrors): void {\n if (this.workflowSubRequests && this.workflowSubRequests.length > 0) {\n this.restorePrefilledMiddleFnsForWorkflow(errors);\n return;\n }\n\n const methodMeta = routesCache.getMetadata(this.requestId);\n if (!methodMeta) {\n if (errors) {\n errors.set(\n this.requestId,\n new RpcError({\n type: 'route-metadata-not-found',\n publicMessage: `Metadata for Route '${this.requestId} not found.'.`,\n })\n );\n }\n return;\n }\n const missingIds = methodMeta.middleFnIds?.filter((id) => !!id && this.requestId !== id) || [];\n missingIds.forEach((id) => {\n const subRequest = this.subRequestList[id];\n if (subRequest) return;\n const cacheKey = this.getPrefilledMiddleFnCacheKey(id);\n const cachedSubRequest = this.prefilledMiddleFnsCache.get(cacheKey);\n if (cachedSubRequest) {\n const clonedSubRequest: SubRequest<any> = {\n ...cachedSubRequest,\n isResolved: false,\n resolvedValue: undefined,\n error: undefined,\n };\n this.addSubRequest(clonedSubRequest);\n }\n });\n }\n\n /** Restore prefilled middleFns for all routes in a routesFlow, deduplicating by ID */\n private restorePrefilledMiddleFnsForWorkflow(errors?: RequestErrors): void {\n const workflowRouteIds = new Set(this.workflowSubRequests!.map((sr) => sr.id));\n\n for (const routeSubRequest of this.workflowSubRequests!) {\n const methodMeta = routesCache.getMetadata(routeSubRequest.id);\n if (!methodMeta) {\n if (errors) {\n errors.set(\n routeSubRequest.id,\n new RpcError({\n type: 'route-metadata-not-found',\n publicMessage: `Metadata for Route '${routeSubRequest.id}' not found.`,\n })\n );\n }\n continue;\n }\n const missingIds = methodMeta.middleFnIds?.filter((id) => !!id && !workflowRouteIds.has(id)) || [];\n missingIds.forEach((id) => {\n const subRequest = this.subRequestList[id];\n if (subRequest) return;\n const cacheKey = this.getPrefilledMiddleFnCacheKey(id);\n const cachedSubRequest = this.prefilledMiddleFnsCache.get(cacheKey);\n if (cachedSubRequest) {\n const clonedSubRequest: SubRequest<any> = {\n ...cachedSubRequest,\n isResolved: false,\n resolvedValue: undefined,\n error: undefined,\n };\n this.addSubRequest(clonedSubRequest);\n }\n });\n }\n }\n\n private storePrefilledMiddleFns(errors: RequestErrors): void {\n Object.keys(this.subRequestList).forEach((id) => {\n const subRequest = this.subRequestList[id];\n const methodMeta = routesCache.getMetadata(id);\n if (!methodMeta) throw new Error(`Remote method ${id} not found.`);\n if (methodMeta.type === HandlerType.route) {\n errors.set(\n id,\n new RpcError({\n type: 'routes-cant-be-prefilled',\n publicMessage: `Remote method ${id} is a route and can't be prefilled.`,\n })\n );\n return;\n }\n const cacheKey = this.getPrefilledMiddleFnCacheKey(id);\n this.prefilledMiddleFnsCache.set(cacheKey, subRequest);\n });\n }\n\n private removePrefilledMiddleFns(): void {\n Object.keys(this.subRequestList).forEach((id) => {\n const cacheKey = this.getPrefilledMiddleFnCacheKey(id);\n this.prefilledMiddleFnsCache.delete(cacheKey);\n });\n }\n\n /** Returns true if the route is a query (isMutation === false) and not a routesFlow */\n private isQueryRoute(): boolean {\n if (this.workflowSubRequests) return false;\n const meta = routesCache.getMetadata(this.requestId);\n // strict false value required for queries\n return meta?.options?.isMutation === false;\n }\n\n private getPrefilledMiddleFnCacheKey(id: string): string {\n return `${this.options.baseURL}:${id}`;\n }\n}\n\n/**\n * Builds the RequestInit options for the fetch call, choosing between GET and POST:\n * - GET (query): Used for non-mutation routes (isMutation === false) with JSON serialization,\n * where the base64url-encoded body fits within the URL length limit. The serialized data is\n * sent as a `?data=` query parameter, with no request body.\n * - POST (mutation/route call): Used for all other cases: mutations, optimistic requests,\n * routesFlow calls, non-JSON serializers, or when the GET URL would exceed MAX_GET_URL_LENGTH.\n * The serialized data is sent in the request body with the appropriate Content-Type header.\n */\nfunction buildFetchOptions(\n url: URL,\n serialized: ReturnType<typeof serializeRequestBody>,\n headersFromParams: Record<string, string>,\n options: ClientOptions,\n isOptimistic: boolean,\n isQuery: boolean,\n signal?: AbortSignal\n): RequestInit {\n if (!isOptimistic && isQuery && serialized.contentType.includes('json')) {\n const encoded = toBase64Url(serialized.body as string);\n const testUrl = new URL(url.pathname + url.search, url.origin);\n testUrl.searchParams.set('data', encoded);\n\n if (testUrl.toString().length <= MAX_GET_URL_LENGTH) {\n url.searchParams.set('data', encoded);\n return {\n ...options.fetchOptions,\n method: 'GET',\n headers: {...options.fetchOptions.headers, ...headersFromParams},\n body: undefined,\n signal,\n };\n }\n }\n\n return {\n ...options.fetchOptions,\n method: 'POST',\n headers: {...options.fetchOptions.headers, ...headersFromParams, 'Content-Type': serialized.contentType},\n body: serialized.body as BodyInit,\n signal,\n };\n}\n\n/** Extracts headers from HeadersSubset params in headersFn methods */\nfunction extractRequestHeaders(req: MionClientRequest<any, any>): Record<string, string> {\n const headers: Record<string, string> = {};\n const subRequestIds = Object.keys(req.subRequestList);\n\n for (let i = 0; i < subRequestIds.length; i++) {\n const id = subRequestIds[i];\n const subRequest = req.subRequestList[id];\n if (!subRequest) continue;\n\n const method = routesCache.getMetadata(id);\n if (!method || method.type !== HandlerType.headersMiddleFn || !method.headersParam) continue;\n\n const params = subRequest.params;\n const extracted = extractHeadersFromParams(params);\n Object.assign(headers, extracted);\n }\n\n return headers;\n}\n\n/** Extracts headers from a HeadersSubset parameter */\nfunction extractHeadersFromParams(params: any[]): Record<string, string> {\n if (!params || params.length === 0) {\n throw new RpcError({\n type: 'missing-headers-param',\n publicMessage: 'HeadersFn requires a HeadersSubset parameter.',\n });\n }\n\n const firstParam = params[0];\n\n if (firstParam instanceof HeadersSubset) {\n return firstParam.headers as Record<string, string>;\n }\n\n if (firstParam && typeof firstParam === 'object' && 'headers' in firstParam && typeof firstParam.headers === 'object') {\n return firstParam.headers as Record<string, string>;\n }\n\n throw new RpcError({\n type: 'invalid-headers-param',\n publicMessage: 'HeadersFn first parameter must be a HeadersSubset instance or object with headers property.',\n });\n}\n\n/** Reconstructs a HeadersSubset from HTTP response headers for methods that return HeadersSubset */\nfunction reconstructHeadersSubsetFromResponse(\n methodId: string,\n responseHeaders: Headers\n): HeadersSubset<string, string> | undefined {\n const method = routesCache.getMetadata(methodId);\n\n if (!method?.headersReturn?.headerNames || method.headersReturn.headerNames.length === 0) {\n return undefined;\n }\n\n const headerNames = method.headersReturn.headerNames;\n const headersMap: Record<string, string> = {};\n\n for (const name of headerNames) {\n const value = responseHeaders.get(name);\n if (value !== undefined && value !== null) {\n headersMap[name] = value;\n }\n }\n\n if (Object.keys(headersMap).length > 0) {\n return new HeadersSubset(headersMap);\n }\n\n return undefined;\n}\n\n/** Builds a RoutesFlowQuery from route paths and subrequests, collecting any mapFrom mappings */\nfunction buildRoutesFlowQuery(routePaths: string[], workflowSubRequests: RouteSubRequest<any>[]): RoutesFlowQuery {\n const allMappings: RoutesFlowMapping[] = [];\n for (const sr of workflowSubRequests) {\n // Duck-type check for mappings array (avoids circular import of MionSubRequest)\n const mappings = (sr as any).mappings;\n if (Array.isArray(mappings) && mappings.length > 0) {\n for (const ref of mappings) {\n allMappings.push({\n fromId: ref.fromRequestId,\n toId: ref.toRequestId,\n bodyHash: ref.bodyHash,\n paramIndex: ref.paramIndex,\n });\n }\n }\n }\n return {\n routes: routePaths,\n mappings: allMappings.length > 0 ? allMappings : undefined,\n };\n}\n"],"names":["getRoutePath","ROUTES_FLOW_KEY","toBase64Url","routesCache","createMetadataSubRequest","fetchRemoteMethodsMetadata","validateSubRequests","serializeRequestBody","MION_ROUTES","deserializeResponseBody","isRpcError","RpcError","HandlerType","MAX_GET_URL_LENGTH","HeadersSubset"],"mappings":"oaA0Ba,iBAAiB,CAON,QACC,wBACD,MACA,UAEA,oBAEA,OAbX,KACA,UACA,eAAmD,CAAA,EAC5D,SAEA,YACoB,QACC,wBACD,MACA,UAEA,oBAEA,OAAoB,CAEpC,GATgB,KAAA,QAAA,QACC,KAAA,wBAAA,wBACD,KAAA,MAAA,MACA,KAAA,UAAA,UAEA,KAAA,oBAAA,oBAEA,KAAA,OAAA,OAEZ,qBAAuB,oBAAoB,OAAS,EAAG,CACvD,MAAM,WAAa,oBAAoB,IAAK,IAAOA,kBAAa,GAAG,QAAS,KAAK,OAAO,CAAC,EACnF,MAAQ,qBAAqB,WAAY,mBAAmB,EAC5D,SAAWA,KAAAA,aAAa,CAACC,cAAAA,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{ ResponseBody } from '@mionjs/router';
|
|
2
|
-
import { ClientOptions,
|
|
2
|
+
import { ClientOptions, MiddlewareSubRequest, SubRequest, RouteSubRequest, PrefilledMiddleFnsCache } from './types.ts';
|
|
3
3
|
import { RunTypeError } from '@mionjs/core';
|
|
4
|
-
export declare class MionClientRequest<RR extends
|
|
4
|
+
export declare class MionClientRequest<RR extends RouteSubRequest<any>, MiddleFnRequestsList extends MiddlewareSubRequest<any>[]> {
|
|
5
5
|
readonly options: ClientOptions;
|
|
6
6
|
private readonly prefilledMiddleFnsCache;
|
|
7
7
|
readonly route?: RR | undefined;
|
|
8
8
|
readonly middleFns?: MiddleFnRequestsList | undefined;
|
|
9
|
-
readonly workflowSubRequests?:
|
|
9
|
+
readonly workflowSubRequests?: RouteSubRequest<any>[] | undefined;
|
|
10
|
+
readonly signal?: AbortSignal | undefined;
|
|
10
11
|
readonly path: string;
|
|
11
12
|
readonly requestId: string;
|
|
12
13
|
readonly subRequestList: {
|
|
13
14
|
[key: string]: SubRequest<any>;
|
|
14
15
|
};
|
|
15
16
|
response: Response | undefined;
|
|
16
|
-
constructor(options: ClientOptions, prefilledMiddleFnsCache: PrefilledMiddleFnsCache, route?: RR | undefined, middleFns?: MiddleFnRequestsList | undefined, workflowSubRequests?:
|
|
17
|
+
constructor(options: ClientOptions, prefilledMiddleFnsCache: PrefilledMiddleFnsCache, route?: RR | undefined, middleFns?: MiddleFnRequestsList | undefined, workflowSubRequests?: RouteSubRequest<any>[] | undefined, signal?: AbortSignal | undefined);
|
|
17
18
|
call(): Promise<ResponseBody>;
|
|
19
|
+
private makeCall;
|
|
20
|
+
private shouldRetryWithProperSerialization;
|
|
21
|
+
private retryWithProperSerialization;
|
|
18
22
|
validateParams(subReqList?: SubRequest<any>[]): Promise<RunTypeError[]>;
|
|
19
23
|
prefill(subReqList?: SubRequest<any>[]): Promise<void>;
|
|
20
24
|
removePrefill(subRequests?: SubRequest<any>[]): Promise<void>;
|
|
21
25
|
addSubRequest(subRequest: SubRequest<any>): void;
|
|
26
|
+
private handlePlatformError;
|
|
27
|
+
private resolveSubRequests;
|
|
22
28
|
private onError;
|
|
23
29
|
private getResponseValueFromBodyOrHeader;
|
|
24
30
|
private restorePrefilledMiddleFns;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@mionjs/core");function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@mionjs/core");function routesFlow(routeSubRequests){if(!routeSubRequests||routeSubRequests.length===0)throw new core.RpcError({type:"routesFlow-empty-routes",publicMessage:"RoutesFlow requires at least one route subrequest."});const firstSubRequest=routeSubRequests[0];if(!firstSubRequest.client)throw new core.RpcError({type:"routesFlow-missing-client",publicMessage:"Could not extract MionClient from subrequest. Ensure subrequests are created via routes proxy."});const client=firstSubRequest.client;for(let i=1;i<routeSubRequests.length;i++)if(routeSubRequests[i].client!==client)throw new core.RpcError({type:"routesFlow-client-mismatch",publicMessage:`All subrequests in a routesFlow must use the same client instance. Subrequest at index ${i} has a different client.`});return{async call(setup){const middleFns=setup?.middleFns??{},[results,errors,middleFnResults,middleFnErrors]=await client.execute(void 0,routeSubRequests,middleFns,setup?.signal,setup?.timeout),emptyResults=routeSubRequests.map(()=>{}),emptyErrors=routeSubRequests.map(()=>{});return[results??emptyResults,errors??emptyErrors,middleFnResults,middleFnErrors]}}}const mapFromSymbol=Symbol("MapFromServerFnRef");function mapFrom(source,mapper,bodyHash){if(!bodyHash)throw new Error("mapFrom() requires mion vite plugin transform to inject bodyHash");const ref={mapFromSymbol,namespace:core.PURE_SERVER_FN_NAMESPACE,fnName:bodyHash,bodyHash,pureFn:mapper,isFactory:!1,fromRequestId:source.id,toRequestId:"",paramIndex:-1,type(){return ref}};return ref}function isMapFromRef(ref){return ref&&ref.mapFromSymbol===mapFromSymbol}exports.isMapFromRef=isMapFromRef;exports.mapFrom=mapFrom;exports.mapFromSymbol=mapFromSymbol;exports.routesFlow=routesFlow;
|
|
2
2
|
//# sourceMappingURL=routesFlow.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routesFlow.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"routesFlow.cjs","sources":["../../../src/routesFlow.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {PURE_SERVER_FN_NAMESPACE, RpcError} from '@mionjs/core';\nimport type {MiddlewareSubRequest, RouteSubRequest, RoutesFlowBuilder, SubRequest} from './types.ts';\nimport type {MionSubRequest} from './subRequest.ts';\nimport {MapFromServerFnRef} from '@mionjs/core';\n\n/** Creates a RoutesFlowBuilder for deferred execution of multiple routes in a single HTTP request */\nexport function routesFlow<Routes extends RouteSubRequest<any>[]>(routeSubRequests: [...Routes]): RoutesFlowBuilder<Routes> {\n if (!routeSubRequests || routeSubRequests.length === 0) {\n throw new RpcError({\n type: 'routesFlow-empty-routes',\n publicMessage: 'RoutesFlow requires at least one route subrequest.',\n });\n }\n\n const firstSubRequest = routeSubRequests[0] as MionSubRequest;\n if (!firstSubRequest.client) {\n throw new RpcError({\n type: 'routesFlow-missing-client',\n publicMessage: 'Could not extract MionClient from subrequest. Ensure subrequests are created via routes proxy.',\n });\n }\n\n const client = firstSubRequest.client;\n\n // Validate all subrequests use the same client instance\n for (let i = 1; i < routeSubRequests.length; i++) {\n const subRequest = routeSubRequests[i] as MionSubRequest;\n if (subRequest.client !== client) {\n throw new RpcError({\n type: 'routesFlow-client-mismatch',\n publicMessage: `All subrequests in a routesFlow must use the same client instance. Subrequest at index ${i} has a different client.`,\n });\n }\n }\n\n return {\n async call(setup?: {middleFns?: Record<string, MiddlewareSubRequest<any>>; signal?: AbortSignal; timeout?: number}) {\n const middleFns = setup?.middleFns ?? {};\n const [results, errors, middleFnResults, middleFnErrors] = await client.execute(\n undefined,\n routeSubRequests as any,\n middleFns as any,\n setup?.signal,\n setup?.timeout\n );\n const emptyResults = routeSubRequests.map(() => undefined);\n const emptyErrors = routeSubRequests.map(() => undefined);\n return [results ?? emptyResults, errors ?? emptyErrors, middleFnResults, middleFnErrors] as any;\n },\n };\n}\n\nexport const mapFromSymbol = Symbol('MapFromServerFnRef');\n\n// ╔══════════════════════════════════════════════════════════════════════════════╗\n// ║ WARNING: This function's call signature is parsed by the mion vite plugin ║\n// ║ at build time (see devtools/src/vite-plugin/extractPureFn.ts). ║\n// ║ Do NOT rename, change the parameter order, or modify the function ║\n// ║ signature without updating the corresponding AST extraction and ║\n// ║ transformer logic in @mionjs/devtools. ║\n// ╚══════════════════════════════════════════════════════════════════════════════╝\n/**\n * Maps the output of one route SubRequest to the input of another within a routesFlow.\n * The mapper function must be pure (same rules as pureServerFn).\n * The bodyHash is injected at build time by the mion vite plugin.\n */\n\nexport function mapFrom<FromSR extends SubRequest<any>, MappedInput>(\n source: FromSR,\n mapper: (value: FromSR['resolvedValue']) => MappedInput,\n bodyHash?: string // injected by mion vite plugin\n): MapFromServerFnRef<(value: FromSR['resolvedValue']) => MappedInput> {\n // Important: bodyHash is injected at build time by mion vite plugin\n if (!bodyHash) throw new Error('mapFrom() requires mion vite plugin transform to inject bodyHash');\n const ref: MapFromServerFnRef<(value: FromSR['resolvedValue']) => MappedInput> = {\n mapFromSymbol,\n namespace: PURE_SERVER_FN_NAMESPACE,\n fnName: bodyHash,\n bodyHash,\n pureFn: mapper,\n isFactory: false,\n fromRequestId: source.id,\n toRequestId: '',\n paramIndex: -1, // set by MionSubRequest constructor when passed as a parameter\n type() {\n return ref as unknown as MappedInput;\n },\n };\n return ref;\n}\n\nexport function isMapFromRef(ref: any): ref is MapFromServerFnRef<any> {\n return ref && ref.mapFromSymbol === mapFromSymbol;\n}\n"],"names":["RpcError","PURE_SERVER_FN_NAMESPACE"],"mappings":"mHAaM,SAAU,WAAkD,iBAA6B,CAC3F,GAAI,CAAC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ionjs/core';
|
|
3
|
-
export declare function routesFlow<Routes extends
|
|
3
|
+
export declare function routesFlow<Routes extends RouteSubRequest<any>[]>(routeSubRequests: [...Routes]): RoutesFlowBuilder<Routes>;
|
|
4
4
|
export declare const mapFromSymbol: unique symbol;
|
|
5
5
|
export declare function mapFrom<FromSR extends SubRequest<any>, MappedInput>(source: FromSR, mapper: (value: FromSR['resolvedValue']) => MappedInput, bodyHash?: string): MapFromServerFnRef<(value: FromSR['resolvedValue']) => MappedInput>;
|
|
6
6
|
export declare function isMapFromRef(ref: any): ref is MapFromServerFnRef<any>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@mionjs/core"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@mionjs/core"),src_lib_typedEvent=require("./lib/typedEvent.cjs"),src_routesFlow=require("./routesFlow.cjs");class MionSubRequest{client;pointer;id;isResolved=!1;params;resolvedValue;error;serializedParams;mappings=[];constructor(parentProps,handlerId,argArray,client){this.client=client,this.pointer=[...parentProps],this.id=handlerId,this.params=argArray.map((arg,index)=>src_routesFlow.isMapFromRef(arg)?(arg.toRequestId=this.id,arg.paramIndex=index,this.mappings.push(arg),null):arg)}prefill(){const typedEvent=new src_lib_typedEvent.TypedEvent(this.id,this.client.handlersRegistry);return this.client.prefill(this).catch(errors=>{console.error("Prefill error:",findSubRequestError(this,errors))}),typedEvent}removePrefill(){return this.client.handlersRegistry.clearHandlers(this.id),this.client.removePrefill(this)}call(setup){const signal=setup?.signal,timeout=setup?.timeout;return!setup||!setup.otherRoutes&&!setup.middleFns?this.client.execute(this,void 0,void 0,signal,timeout):setup.otherRoutes&&setup.otherRoutes.length>0?this.executeWithOtherRoutes(setup.otherRoutes,setup.middleFns,signal,timeout):this.client.execute(this,void 0,setup.middleFns,signal,timeout)}async executeWithOtherRoutes(otherRoutes,middleFns,signal,timeout){const allRoutes=[this,...otherRoutes],[results,errors,mfR,mfE]=await this.client.execute(void 0,allRoutes,middleFns??{},signal,timeout),emptyResults=allRoutes.map(()=>{}),emptyErrors=allRoutes.map(()=>{});return[results??emptyResults,errors??emptyErrors,mfR,mfE]}typeErrors(){return this.client.typeErrors(this).catch(errors=>Promise.reject(findSubRequestError(this,errors)))}}function findSubRequestError(subRequest,errors){const specificError=errors.get(subRequest.id);if(specificError)return specificError;const firstError=errors.values().next().value;return firstError||new core.RpcError({type:"unknown-error",publicMessage:"An unknown error occurred"})}exports.MionSubRequest=MionSubRequest;exports.findSubRequestError=findSubRequestError;
|
|
2
2
|
//# sourceMappingURL=subRequest.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subRequest.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"subRequest.cjs","sources":["../../../src/subRequest.ts"],"sourcesContent":["/* ########\n * 2025 mion\n * Author: Ma-jerez\n * License: MIT\n * The software is provided \"as is\", without warranty of any kind.\n * ######## */\n\nimport {RpcError} from '@mionjs/core';\nimport type {RunTypeError} from '@mionjs/core';\nimport type {CallSetup, MiddlewareSubRequest, RequestErrors, RouteSubRequest, SubRequest} from './types.ts';\nimport type {MapFromServerFnRef} from '@mionjs/core';\nimport type {MionClient} from './client.ts';\nimport {TypedEvent} from './lib/typedEvent.ts';\nimport {isMapFromRef} from './routesFlow.ts';\n\n/** Implementation of both RouteSubRequest and MiddleFnSubRequest interfaces */\nexport class MionSubRequest<S = any, E extends RpcError<string, any> = any>\n implements RouteSubRequest<any>, MiddlewareSubRequest<any>\n{\n pointer: string[];\n id: string;\n isResolved: boolean = false;\n params: any[];\n resolvedValue?: S;\n error?: E;\n serializedParams?: any[];\n mappings: MapFromServerFnRef[] = [];\n\n constructor(\n parentProps: string[],\n handlerId: string,\n argArray: any[],\n readonly client: MionClient\n ) {\n this.pointer = [...parentProps];\n this.id = handlerId;\n this.params = argArray.map((arg, index) => {\n if (isMapFromRef(arg)) {\n arg.toRequestId = this.id;\n arg.paramIndex = index;\n this.mappings.push(arg);\n return null;\n }\n return arg;\n });\n }\n\n /** Prefills MiddleFn's parameters and returns TypedEvent for event handler registration */\n prefill(): TypedEvent<S, E> {\n const typedEvent = new TypedEvent<S, E>(this.id, this.client.handlersRegistry);\n\n this.client.prefill(this as MiddlewareSubRequest<any>).catch((errors: RequestErrors) => {\n console.error('Prefill error:', findSubRequestError(this, errors));\n });\n\n return typedEvent;\n }\n\n /** Removes prefilled value and clears any registered error handlers for this middleFn */\n removePrefill(): Promise<void> {\n this.client.handlersRegistry.clearHandlers(this.id);\n return this.client.removePrefill(this as MiddlewareSubRequest<any>);\n }\n\n /** Calls a remote route with optional setup (middleFns, otherRoutes, signal, timeout) */\n call(setup?: CallSetup<any, any>): Promise<any> {\n const signal = setup?.signal;\n const timeout = setup?.timeout;\n if (!setup || (!setup.otherRoutes && !setup.middleFns)) {\n return this.client.execute(this as unknown as RouteSubRequest<any>, undefined, undefined, signal, timeout);\n }\n if (setup.otherRoutes && setup.otherRoutes.length > 0) {\n return this.executeWithOtherRoutes(setup.otherRoutes, setup.middleFns, signal, timeout);\n }\n return this.client.execute(this as unknown as RouteSubRequest<any>, undefined, setup.middleFns, signal, timeout);\n }\n\n private async executeWithOtherRoutes(\n otherRoutes: RouteSubRequest<any>[],\n middleFns?: Record<string, MiddlewareSubRequest<any>>,\n signal?: AbortSignal,\n timeout?: number\n ): Promise<any> {\n const allRoutes = [this as unknown as RouteSubRequest<any>, ...otherRoutes];\n const [results, errors, mfR, mfE] = await this.client.execute(undefined, allRoutes, middleFns ?? {}, signal, timeout);\n const emptyResults = allRoutes.map(() => undefined);\n const emptyErrors = allRoutes.map(() => undefined);\n return [results ?? emptyResults, errors ?? emptyErrors, mfR, mfE];\n }\n\n /** Validates parameters and returns type errors */\n typeErrors(): Promise<RunTypeError[]> {\n return this.client\n .typeErrors(this as SubRequest<any>)\n .catch((errors: RequestErrors) => Promise.reject(findSubRequestError(this, errors)));\n }\n}\n\n/** Finds the most relevant error from the errors map for a given sub-request */\nexport function findSubRequestError(subRequest: SubRequest<any>, errors: RequestErrors): RpcError<string> {\n const specificError = errors.get(subRequest.id);\n if (specificError) return specificError;\n\n const firstError = errors.values().next().value;\n if (firstError) return firstError;\n\n return new RpcError({\n type: 'unknown-error',\n publicMessage: 'An unknown error occurred',\n });\n}\n"],"names":["isMapFromRef","TypedEvent","RpcError"],"mappings":"uNAgBa,cAAc,CAgBV,OAbb,QACA,GACA,WAAsB,GACtB,OACA,cACA,MACA,iBACA,SAAiC,CAAA,EAEjC,YACI,YACA,UACA,SACS,OAAkB,CAAlB,KAAA,OAAA,OAET,KAAK,QAAU,CAAC,GAAG,WAAW,EAC9B,KAAK,GAAK,UACV,KAAK,OAAS,SAAS,IAAI,CAAC,IAAK,QACzBA,eAAAA,aAAa,GAAG,GAChB,IAAI,YAAc,KAAK,GACvB,IAAI,WAAa,MACjB,KAAK,SAAS,KAAK,GAAG,EACf,MAEJ,GACV,CACL,CAGA,SAAO,CACH,MAAM,WAAa,IAAIC,8BAAiB,KAAK,GAAI,KAAK,OAAO,gBAAgB,EAE7E,YAAK,OAAO,QAAQ,IAAiC,EAAE,MAAO,QAAyB,CACnF,QAAQ,MAAM,iBAAkB,oBAAoB,KAAM,MAAM,CAAC,CACrE,CAAC,EAEM,UACX,CAGA,eAAa,CACT,YAAK,OAAO,iBAAiB,cAAc,KAAK,EAAE,EAC3C,KAAK,OAAO,cAAc,IAAiC,CACtE,CAGA,KAAK,MAA2B,CAC5B,MAAM,OAAS,OAAO,OAChB,QAAU,OAAO,QACvB,MAAI,CAAC,OAAU,CAAC,MAAM,aAAe,CAAC,MAAM,UACjC,KAAK,OAAO,QAAQ,KAAyC,OAAW,OAAW,OAAQ,OAAO,EAEzG,MAAM,aAAe,MAAM,YAAY,OAAS,EACzC,KAAK,uBAAuB,MAAM,YAAa,MAAM,UAAW,OAAQ,OAAO,EAEnF,KAAK,OAAO,QAAQ,KAAyC,OAAW,MAAM,UAAW,OAAQ,OAAO,CACnH,CAEQ,MAAM,uBACV,YACA,UACA,OACA,QAAgB,CAEhB,MAAM,UAAY,CAAC,KAAyC,GAAG,WAAW,EACpE,CAAC,QAAS,OAAQ,IAAK,GAAG,EAAI,MAAM,KAAK,OAAO,QAAQ,OAAW,UAAW,WAAa,CAAA,EAAI,OAAQ,OAAO,EAC9G,aAAe,UAAU,IAAI,IAAA,EAAe,EAC5C,YAAc,UAAU,IAAI,IAAA,EAAe,EACjD,MAAO,CAAC,SAAW,aAAc,QAAU,YAAa,IAAK,GAAG,CACpE,CAGA,YAAU,CACN,OAAO,KAAK,OACP,WAAW,IAAuB,EAClC,MAAO,QAA0B,QAAQ,OAAO,oBAAoB,KAAM,MAAM,CAAC,CAAC,CAC3F,CACH,CAGK,SAAU,oBAAoB,WAA6B,OAAqB,CAClF,MAAM,cAAgB,OAAO,IAAI,WAAW,EAAE,EAC9C,GAAI,cAAe,OAAO,cAE1B,MAAM,WAAa,OAAO,OAAA,EAAS,OAAO,MAC1C,OAAI,YAEG,IAAIC,KAAAA,SAAS,CAChB,KAAM,gBACN,cAAe,2BAAA,CAClB,CACL"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { RpcError, RunTypeError, MapFromServerFnRef } from '@mionjs/core';
|
|
2
|
-
import {
|
|
2
|
+
import { CallSetup, MiddlewareSubRequest, RequestErrors, RouteSubRequest, SubRequest } from './types.ts';
|
|
3
3
|
import { MionClient } from './client.ts';
|
|
4
|
-
import { TypedEvent } from './typedEvent.ts';
|
|
5
|
-
export declare class MionSubRequest<S = any, E extends RpcError<string, any> = any> implements
|
|
4
|
+
import { TypedEvent } from './lib/typedEvent.ts';
|
|
5
|
+
export declare class MionSubRequest<S = any, E extends RpcError<string, any> = any> implements RouteSubRequest<any>, MiddlewareSubRequest<any> {
|
|
6
6
|
readonly client: MionClient;
|
|
7
7
|
pointer: string[];
|
|
8
8
|
id: string;
|
|
@@ -15,9 +15,8 @@ export declare class MionSubRequest<S = any, E extends RpcError<string, any> = a
|
|
|
15
15
|
constructor(parentProps: string[], handlerId: string, argArray: any[], client: MionClient);
|
|
16
16
|
prefill(): TypedEvent<S, E>;
|
|
17
17
|
removePrefill(): Promise<void>;
|
|
18
|
-
call(): Promise<
|
|
19
|
-
|
|
20
|
-
callWithWorkflow<OtherRoutes extends RSubRequest<any>[], H extends Record<string, HSubRequest<any>>>(otherRoutes: [...OtherRoutes], middleFns?: H): Promise<WorkflowResult<[RSubRequest<any>, ...OtherRoutes], H>>;
|
|
18
|
+
call(setup?: CallSetup<any, any>): Promise<any>;
|
|
19
|
+
private executeWithOtherRoutes;
|
|
21
20
|
typeErrors(): Promise<RunTypeError[]>;
|
|
22
21
|
}
|
|
23
22
|
export declare function findSubRequestError(subRequest: SubRequest<any>, errors: RequestErrors): RpcError<string>;
|
package/.dist/cjs/src/types.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
2
|
//# sourceMappingURL=types.cjs.map
|
package/.dist/cjs/src/types.d.ts
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
import { RpcError, CoreRouterOptions, Prettify, RunTypeError, SerializerMode, ValidationError } from '@mionjs/core';
|
|
2
2
|
import { PublicHeadersFn, PublicMiddleFn, RemoteApi, PublicRoute } from '@mionjs/router';
|
|
3
|
-
import { TypedEvent } from './typedEvent.ts';
|
|
4
|
-
export type Result<RouteSuccess, RouteError, MiddleFnsResults extends Record<string, unknown> = Record<string, unknown>, MiddleFnsErrors extends Record<string,
|
|
5
|
-
export type MiddleFnSuccess<H> = H extends
|
|
6
|
-
export type MiddleFnError<H> = H extends
|
|
7
|
-
export type
|
|
8
|
-
RouteSuccess | undefined,
|
|
9
|
-
RouteError | ValidationError | undefined,
|
|
10
|
-
{
|
|
11
|
-
[K in keyof MiddleFns]?: MiddleFnSuccess<MiddleFns[K]>;
|
|
12
|
-
} | undefined,
|
|
13
|
-
{
|
|
14
|
-
[K in keyof MiddleFns]?: MiddleFnError<MiddleFns[K]>;
|
|
15
|
-
} | undefined
|
|
16
|
-
];
|
|
17
|
-
export type WorkflowResult<Routes extends RSubRequest<any>[], MiddleFns extends Record<string, HSubRequest<any>> = Record<string, HSubRequest<any>>> = [
|
|
3
|
+
import { TypedEvent } from './lib/typedEvent.ts';
|
|
4
|
+
export type Result<RouteSuccess, RouteError, MiddleFnsResults extends Record<string, unknown> = Record<string, unknown>, MiddleFnsErrors extends Record<string, unknown> = Record<string, RpcError<string, unknown>>> = [RouteSuccess | undefined, RouteError | undefined, MiddleFnsResults | undefined, MiddleFnsErrors | undefined];
|
|
5
|
+
export type MiddleFnSuccess<H> = H extends MiddlewareSubRequest<infer PH> ? HandlerSuccessResponse<PH> : never;
|
|
6
|
+
export type MiddleFnError<H> = H extends MiddlewareSubRequest<infer PH> ? Simplify<HandlerErrors<PH>> : never;
|
|
7
|
+
export type WorkflowResult<Routes extends RouteSubRequest<any>[], MiddleFns extends Record<string, MiddlewareSubRequest<any>> = Record<string, MiddlewareSubRequest<any>>> = [
|
|
18
8
|
WorkflowRouteResults<Routes>,
|
|
19
9
|
WorkflowRouteErrors<Routes>,
|
|
20
10
|
{
|
|
@@ -24,11 +14,11 @@ export type WorkflowResult<Routes extends RSubRequest<any>[], MiddleFns extends
|
|
|
24
14
|
[K in keyof MiddleFns]?: MiddleFnError<MiddleFns[K]>;
|
|
25
15
|
} | undefined
|
|
26
16
|
];
|
|
27
|
-
export type WorkflowRouteResults<Routes extends
|
|
28
|
-
[K in keyof Routes]: Routes[K] extends
|
|
17
|
+
export type WorkflowRouteResults<Routes extends RouteSubRequest<any>[]> = {
|
|
18
|
+
[K in keyof Routes]: Routes[K] extends RouteSubRequest<infer PH> ? HandlerSuccessResponse<PH> | undefined : never;
|
|
29
19
|
};
|
|
30
|
-
export type WorkflowRouteErrors<Routes extends
|
|
31
|
-
[K in keyof Routes]: Routes[K] extends
|
|
20
|
+
export type WorkflowRouteErrors<Routes extends RouteSubRequest<any>[]> = {
|
|
21
|
+
[K in keyof Routes]: Routes[K] extends RouteSubRequest<infer PH> ? Simplify<HandlerErrors<PH>> | undefined : never;
|
|
32
22
|
};
|
|
33
23
|
export interface ClientOptions extends CoreRouterOptions {
|
|
34
24
|
baseURL: string;
|
|
@@ -38,6 +28,7 @@ export interface ClientOptions extends CoreRouterOptions {
|
|
|
38
28
|
fetchOptions: RequestInit;
|
|
39
29
|
validateParams: boolean;
|
|
40
30
|
serializer: SerializerMode;
|
|
31
|
+
timeout?: number;
|
|
41
32
|
}
|
|
42
33
|
type PublicHandler = (...args: any[]) => Promise<any>;
|
|
43
34
|
type PublicMethod = PublicRoute | PublicMiddleFn | PublicHeadersFn;
|
|
@@ -83,70 +74,70 @@ export interface SubRequest<PH extends PublicHandler> {
|
|
|
83
74
|
error?: HandlerFailResponse<PH>;
|
|
84
75
|
serializedParams?: any[];
|
|
85
76
|
}
|
|
86
|
-
export interface
|
|
77
|
+
export interface CallSetup<H extends Record<string, MiddlewareSubRequest<any>> = Record<string, never>, OtherRoutes extends RouteSubRequest<any>[] = []> {
|
|
78
|
+
middleFns?: H;
|
|
79
|
+
otherRoutes?: [...OtherRoutes];
|
|
80
|
+
signal?: AbortSignal;
|
|
81
|
+
timeout?: number;
|
|
82
|
+
}
|
|
83
|
+
export interface RoutesFlowBuilder<Routes extends RouteSubRequest<any>[]> {
|
|
84
|
+
call(setup?: {
|
|
85
|
+
middleFns?: never;
|
|
86
|
+
signal?: AbortSignal;
|
|
87
|
+
timeout?: number;
|
|
88
|
+
}): Promise<WorkflowResult<Routes>>;
|
|
89
|
+
call<H extends Record<string, MiddlewareSubRequest<any>>>(setup: {
|
|
90
|
+
middleFns: H;
|
|
91
|
+
signal?: AbortSignal;
|
|
92
|
+
timeout?: number;
|
|
93
|
+
}): Promise<WorkflowResult<Routes, H>>;
|
|
94
|
+
}
|
|
95
|
+
export interface RouteSubRequest<PH extends PublicHandler> extends SubRequest<PH> {
|
|
87
96
|
typeErrors: () => Promise<RunTypeError[]>;
|
|
88
|
-
call
|
|
89
|
-
|
|
90
|
-
|
|
97
|
+
call(setup?: {
|
|
98
|
+
middleFns?: never;
|
|
99
|
+
otherRoutes?: never;
|
|
100
|
+
signal?: AbortSignal;
|
|
101
|
+
timeout?: number;
|
|
102
|
+
}): Promise<Result<HandlerSuccessResponse<PH>, Simplify<HandlerErrors<PH>>>>;
|
|
103
|
+
call<H extends Record<string, MiddlewareSubRequest<any>>>(setup: {
|
|
104
|
+
middleFns: H;
|
|
105
|
+
otherRoutes?: never;
|
|
106
|
+
signal?: AbortSignal;
|
|
107
|
+
timeout?: number;
|
|
108
|
+
}): Promise<Result<HandlerSuccessResponse<PH>, Simplify<HandlerErrors<PH>>, {
|
|
109
|
+
[K in keyof H]?: MiddleFnSuccess<H[K]>;
|
|
110
|
+
}, {
|
|
111
|
+
[K in keyof H]?: MiddleFnError<H[K]>;
|
|
112
|
+
}>>;
|
|
113
|
+
call<OtherRoutes extends RouteSubRequest<any>[], H extends Record<string, MiddlewareSubRequest<any>> = Record<string, never>>(setup: {
|
|
114
|
+
otherRoutes: [...OtherRoutes];
|
|
115
|
+
middleFns?: H;
|
|
116
|
+
signal?: AbortSignal;
|
|
117
|
+
timeout?: number;
|
|
118
|
+
}): Promise<WorkflowResult<any, H>>;
|
|
91
119
|
}
|
|
92
|
-
export interface
|
|
120
|
+
export interface MiddlewareSubRequest<PH extends PublicHandler> extends SubRequest<PH> {
|
|
93
121
|
typeErrors: () => Promise<RunTypeError[]>;
|
|
94
122
|
prefill: () => TypedEvent<HandlerSuccessResponse<PH>, Simplify<HandlerErrors<PH>>>;
|
|
95
123
|
removePrefill: () => Promise<void>;
|
|
96
124
|
}
|
|
97
125
|
export type NonClientRoute = never | PublicMiddleFn | PublicHeadersFn;
|
|
98
126
|
export type ClientRoutes<RA extends RemoteApi> = Prettify<{
|
|
99
|
-
[Property in keyof RA as RA[Property] extends NonClientRoute ? never : Property]: RA[Property] extends PublicRoute ? (...params: Parameters<RA[Property]['handler']>) =>
|
|
127
|
+
[Property in keyof RA as RA[Property] extends NonClientRoute ? never : Property]: RA[Property] extends PublicRoute ? (...params: Parameters<RA[Property]['handler']>) => RouteSubRequest<RA[Property]['handler']> : RA[Property] extends RemoteApi ? ClientRoutes<RA[Property]> : never;
|
|
100
128
|
}>;
|
|
101
129
|
export type NonClientMiddleFn = never | PublicRoute | {
|
|
102
130
|
[key: string]: PublicRoute;
|
|
103
131
|
};
|
|
104
132
|
export type ClientMiddleFns<RA extends RemoteApi> = Prettify<{
|
|
105
|
-
[Property in keyof RA as RA[Property] extends NonClientMiddleFn ? never : Property]: RA[Property] extends PublicMiddleFn | PublicHeadersFn ? (...params: Parameters<RA[Property]['handler']>) =>
|
|
133
|
+
[Property in keyof RA as RA[Property] extends NonClientMiddleFn ? never : Property]: RA[Property] extends PublicMiddleFn | PublicHeadersFn ? (...params: Parameters<RA[Property]['handler']>) => MiddlewareSubRequest<RA[Property]['handler']> : RA[Property] extends RemoteApi ? ClientMiddleFns<RA[Property]> : never;
|
|
106
134
|
}>;
|
|
107
135
|
export type Cleaned<RMS extends RemoteApi> = {
|
|
108
136
|
[Property in keyof RMS as RMS[Property] extends never ? never : Property]: RMS[Property];
|
|
109
137
|
};
|
|
110
|
-
export type SuccessClientResponse<RS extends
|
|
138
|
+
export type SuccessClientResponse<RS extends RouteSubRequest<any>, RHList extends MiddlewareSubRequest<any>[]> = [
|
|
111
139
|
SuccessResponse<RS>,
|
|
112
140
|
...SuccessResponses<RHList>
|
|
113
141
|
];
|
|
114
142
|
export type PrefilledMiddleFnsCache = Map<string, SubRequest<any>>;
|
|
115
143
|
export {};
|
|
116
|
-
export declare type __ΩResult = any[];
|
|
117
|
-
export declare type __ΩMiddleFnSuccess = any[];
|
|
118
|
-
export declare type __ΩMiddleFnError = any[];
|
|
119
|
-
export declare type __ΩCallWithMiddleFnsResult = any[];
|
|
120
|
-
export declare type __ΩWorkflowResult = any[];
|
|
121
|
-
export declare type __ΩWorkflowRouteResults = any[];
|
|
122
|
-
export declare type __ΩWorkflowRouteErrors = any[];
|
|
123
|
-
export declare type __ΩClientOptions = any[];
|
|
124
|
-
export declare type __ΩInitClientOptions = any[];
|
|
125
|
-
export declare type __ΩRequestHeaders = any[];
|
|
126
|
-
export declare type __ΩRequestBody = any[];
|
|
127
|
-
export declare type __ΩRouteParamsType = any[];
|
|
128
|
-
export declare type __ΩRouteParamType = any[];
|
|
129
|
-
export declare type __ΩHeadersParamsType = any[];
|
|
130
|
-
export declare type __ΩRouteReturnType = any[];
|
|
131
|
-
export declare type __ΩHandlerResponse = any[];
|
|
132
|
-
export declare type __ΩHandlerSuccessResponse = any[];
|
|
133
|
-
export declare type __ΩHandlerFailResponse = any[];
|
|
134
|
-
export declare type __ΩSuccessResponse = any[];
|
|
135
|
-
export declare type __ΩSuccessResponses = any[];
|
|
136
|
-
export declare type __ΩFailResponse = any[];
|
|
137
|
-
export declare type __ΩFailResponses = any[];
|
|
138
|
-
export declare type __ΩRequestErrors = any[];
|
|
139
|
-
export declare type __ΩErrorHandler = any[];
|
|
140
|
-
export declare type __ΩUnknownErrorHandler = any[];
|
|
141
|
-
export declare type __ΩSuccessHandler = any[];
|
|
142
|
-
export declare type __ΩHandlerErrors = any[];
|
|
143
|
-
export declare type __ΩSubRequest = any[];
|
|
144
|
-
export declare type __ΩRSubRequest = any[];
|
|
145
|
-
export declare type __ΩHSubRequest = any[];
|
|
146
|
-
export declare type __ΩNonClientRoute = any[];
|
|
147
|
-
export declare type __ΩClientRoutes = any[];
|
|
148
|
-
export declare type __ΩNonClientMiddleFn = any[];
|
|
149
|
-
export declare type __ΩClientMiddleFns = any[];
|
|
150
|
-
export declare type __ΩCleaned = any[];
|
|
151
|
-
export declare type __ΩSuccessClientResponse = any[];
|
|
152
|
-
export declare type __ΩPrefilledMiddleFnsCache = any[];
|
package/.dist/esm/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export * from './src/types.ts';
|
|
2
2
|
export * from './src/constants.ts';
|
|
3
|
-
export * from './src/storage.ts';
|
|
4
|
-
export * from './src/validation.ts';
|
|
5
|
-
export * from './src/serializer.ts';
|
|
6
|
-
export * from './src/clientMethodsMetadata.ts';
|
|
3
|
+
export * from './src/lib/storage.ts';
|
|
4
|
+
export * from './src/lib/validation.ts';
|
|
5
|
+
export * from './src/lib/serializer.ts';
|
|
6
|
+
export * from './src/lib/clientMethodsMetadata.ts';
|
|
7
|
+
export * from './src/lib/fetchRemoteMethodsMetadata.ts';
|
|
7
8
|
export * from './src/request.ts';
|
|
8
9
|
export * from './src/client.ts';
|
|
9
|
-
export * from './src/typedEvent.ts';
|
|
10
|
-
export * from './src/handlersRegistry.ts';
|
|
10
|
+
export * from './src/lib/typedEvent.ts';
|
|
11
|
+
export * from './src/lib/handlersRegistry.ts';
|
|
11
12
|
export * from './src/routesFlow.ts';
|
package/.dist/esm/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { __ΩCallWithMiddleFnsResult, __ΩCleaned, __ΩClientMiddleFns, __ΩClientOptions, __ΩClientRoutes, __ΩErrorHandler, __ΩFailResponse, __ΩFailResponses, __ΩHSubRequest, __ΩHandlerErrors, __ΩHandlerFailResponse, __ΩHandlerResponse, __ΩHandlerSuccessResponse, __ΩHeadersParamsType, __ΩInitClientOptions, __ΩMiddleFnError, __ΩMiddleFnSuccess, __ΩNonClientMiddleFn, __ΩNonClientRoute, __ΩPrefilledMiddleFnsCache, __ΩRSubRequest, __ΩRequestBody, __ΩRequestErrors, __ΩRequestHeaders, __ΩResult, __ΩRouteParamType, __ΩRouteParamsType, __ΩRouteReturnType, __ΩSubRequest, __ΩSuccessClientResponse, __ΩSuccessHandler, __ΩSuccessResponse, __ΩSuccessResponses, __ΩUnknownErrorHandler, __ΩWorkflowResult, __ΩWorkflowRouteErrors, __ΩWorkflowRouteResults } from "./src/types.js";
|
|
2
1
|
import { DEFAULT_PREFILL_OPTIONS, MAX_GET_URL_LENGTH, ROUTES_FLOW_KEY, ROUTES_FLOW_PATH, STORAGE_KEY } from "./src/constants.js";
|
|
3
|
-
import { MemoryStorage, getStorage, resetStorageInstance } from "./src/storage.js";
|
|
4
|
-
import { validateSubRequest, validateSubRequests } from "./src/validation.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { MemoryStorage, getStorage, resetStorageInstance } from "./src/lib/storage.js";
|
|
3
|
+
import { validateSubRequest, validateSubRequests } from "./src/lib/validation.js";
|
|
4
|
+
import { deserializeResponseBody, serializeRequestBody } from "./src/lib/serializer.js";
|
|
5
|
+
import { createMetadataSubRequest, extractAndProcessMetadata, restoreAllDependencies, restoreFromLocalStorage, storeDependencies, storeMethodsMetadata } from "./src/lib/clientMethodsMetadata.js";
|
|
6
|
+
import { fetchRemoteMethodsMetadata } from "./src/lib/fetchRemoteMethodsMetadata.js";
|
|
7
7
|
import { MionClientRequest } from "./src/request.js";
|
|
8
8
|
import { MionClient, initClient } from "./src/client.js";
|
|
9
|
-
import { TypedEvent } from "./src/typedEvent.js";
|
|
10
|
-
import { HandlersRegistry } from "./src/handlersRegistry.js";
|
|
9
|
+
import { TypedEvent } from "./src/lib/typedEvent.js";
|
|
10
|
+
import { HandlersRegistry } from "./src/lib/handlersRegistry.js";
|
|
11
11
|
import { isMapFromRef, mapFrom, mapFromSymbol, routesFlow } from "./src/routesFlow.js";
|
|
12
12
|
export {
|
|
13
13
|
DEFAULT_PREFILL_OPTIONS,
|
|
@@ -20,49 +20,10 @@ export {
|
|
|
20
20
|
ROUTES_FLOW_PATH,
|
|
21
21
|
STORAGE_KEY,
|
|
22
22
|
TypedEvent,
|
|
23
|
-
|
|
24
|
-
__ΩCleaned,
|
|
25
|
-
__ΩClientMiddleFns,
|
|
26
|
-
__ΩClientOptions,
|
|
27
|
-
__ΩClientRoutes,
|
|
28
|
-
__ΩContentType,
|
|
29
|
-
__ΩErrorHandler,
|
|
30
|
-
__ΩFailResponse,
|
|
31
|
-
__ΩFailResponses,
|
|
32
|
-
__ΩHSubRequest,
|
|
33
|
-
__ΩHandlerErrors,
|
|
34
|
-
__ΩHandlerFailResponse,
|
|
35
|
-
__ΩHandlerResponse,
|
|
36
|
-
__ΩHandlerSuccessResponse,
|
|
37
|
-
__ΩHeadersParamsType,
|
|
38
|
-
__ΩInitClientOptions,
|
|
39
|
-
__ΩMiddleFnError,
|
|
40
|
-
__ΩMiddleFnSuccess,
|
|
41
|
-
__ΩNonClientMiddleFn,
|
|
42
|
-
__ΩNonClientRoute,
|
|
43
|
-
__ΩPrefilledMiddleFnsCache,
|
|
44
|
-
__ΩRSubRequest,
|
|
45
|
-
__ΩRequestBody,
|
|
46
|
-
__ΩRequestErrors,
|
|
47
|
-
__ΩRequestHeaders,
|
|
48
|
-
__ΩResult,
|
|
49
|
-
__ΩRouteParamType,
|
|
50
|
-
__ΩRouteParamsType,
|
|
51
|
-
__ΩRouteReturnType,
|
|
52
|
-
__ΩSerializedBody,
|
|
53
|
-
__ΩSerializedRequest,
|
|
54
|
-
__ΩSubRequest,
|
|
55
|
-
__ΩSuccessClientResponse,
|
|
56
|
-
__ΩSuccessHandler,
|
|
57
|
-
__ΩSuccessResponse,
|
|
58
|
-
__ΩSuccessResponses,
|
|
59
|
-
__ΩUnknownErrorHandler,
|
|
60
|
-
__ΩWorkflowResult,
|
|
61
|
-
__ΩWorkflowRouteErrors,
|
|
62
|
-
__ΩWorkflowRouteResults,
|
|
23
|
+
createMetadataSubRequest,
|
|
63
24
|
deserializeResponseBody,
|
|
25
|
+
extractAndProcessMetadata,
|
|
64
26
|
fetchRemoteMethodsMetadata,
|
|
65
|
-
getAOTCaches,
|
|
66
27
|
getStorage,
|
|
67
28
|
initClient,
|
|
68
29
|
isMapFromRef,
|
|
@@ -70,6 +31,7 @@ export {
|
|
|
70
31
|
mapFromSymbol,
|
|
71
32
|
resetStorageInstance,
|
|
72
33
|
restoreAllDependencies,
|
|
34
|
+
restoreFromLocalStorage,
|
|
73
35
|
routesFlow,
|
|
74
36
|
serializeRequestBody,
|
|
75
37
|
storeDependencies,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ClientOptions, MiddlewareSubRequest, InitClientOptions, RouteSubRequest, SubRequest, ClientRoutes, ClientMiddleFns } from './types.ts';
|
|
2
2
|
import { RemoteApi } from '@mionjs/router';
|
|
3
3
|
import { RunTypeError } from '@mionjs/core';
|
|
4
|
-
import { HandlersRegistry } from './handlersRegistry.ts';
|
|
4
|
+
import { HandlersRegistry } from './lib/handlersRegistry.ts';
|
|
5
5
|
export declare function initClient<RM extends RemoteApi>(options: InitClientOptions): {
|
|
6
6
|
client: MionClient;
|
|
7
7
|
routes: ClientRoutes<RM>;
|
|
@@ -12,17 +12,19 @@ export declare class MionClient {
|
|
|
12
12
|
readonly handlersRegistry: HandlersRegistry;
|
|
13
13
|
readonly prefilledMiddleFnsCache: Map<string, SubRequest<any>>;
|
|
14
14
|
private pendingPrefills;
|
|
15
|
+
private globalAbortController;
|
|
16
|
+
private get globalSignal();
|
|
15
17
|
constructor(clientOptions: ClientOptions);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
abort(): void;
|
|
19
|
+
private composeSignal;
|
|
20
|
+
execute(routeSubRequest?: RouteSubRequest<any>, workflowSubRequests?: RouteSubRequest<any>[], middleFnsRecord?: Record<string, MiddlewareSubRequest<any>>, signal?: AbortSignal, timeout?: number): Promise<any>;
|
|
19
21
|
private executeRequest;
|
|
20
22
|
private getRouteIds;
|
|
21
23
|
private getAllMiddleFnsFromRequest;
|
|
22
24
|
private processMiddleFnsResponses;
|
|
23
25
|
private buildResult;
|
|
24
26
|
typeErrors<List extends SubRequest<any>[]>(...subRequest: List): Promise<RunTypeError[]>;
|
|
25
|
-
prefill<List extends
|
|
26
|
-
removePrefill<List extends
|
|
27
|
+
prefill<List extends MiddlewareSubRequest<any>[]>(...subRequest: List): Promise<void>;
|
|
28
|
+
removePrefill<List extends MiddlewareSubRequest<any>[]>(...subRequest: List): Promise<void>;
|
|
27
29
|
destroy(): void;
|
|
28
30
|
}
|