@mionjs/client 0.8.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dist/cjs/_virtual/jit-fns.cjs +315 -0
- package/.dist/cjs/_virtual/jit-fns.cjs.map +1 -0
- package/.dist/cjs/_virtual/pure-fns.cjs +56 -0
- package/.dist/cjs/_virtual/pure-fns.cjs.map +1 -0
- package/.dist/cjs/_virtual/router-cache.cjs +2 -0
- package/.dist/cjs/_virtual/router-cache.cjs.map +1 -0
- package/.dist/cjs/index.cjs +2 -0
- package/.dist/cjs/index.cjs.map +1 -0
- package/.dist/cjs/index.d.ts +11 -0
- package/.dist/cjs/package.json +1 -0
- package/.dist/cjs/src/aot/loadClientAOTCaches.cjs +2 -0
- package/.dist/cjs/src/aot/loadClientAOTCaches.cjs.map +1 -0
- package/.dist/cjs/src/aot/loadClientAOTCaches.d.ts +8 -0
- package/.dist/cjs/src/client.cjs +2 -0
- package/.dist/cjs/src/client.cjs.map +1 -0
- package/.dist/cjs/src/client.d.ts +28 -0
- package/.dist/cjs/src/clientMethodsMetadata.cjs +2 -0
- package/.dist/cjs/src/clientMethodsMetadata.cjs.map +1 -0
- package/.dist/cjs/src/clientMethodsMetadata.d.ts +10 -0
- package/.dist/cjs/src/constants.cjs +2 -0
- package/.dist/cjs/src/constants.cjs.map +1 -0
- package/.dist/cjs/src/constants.d.ts +6 -0
- package/.dist/cjs/src/handlersRegistry.cjs +2 -0
- package/.dist/cjs/src/handlersRegistry.cjs.map +1 -0
- package/.dist/cjs/src/handlersRegistry.d.ts +18 -0
- package/.dist/cjs/src/request.cjs +2 -0
- package/.dist/cjs/src/request.cjs.map +1 -0
- package/.dist/cjs/src/request.d.ts +30 -0
- package/.dist/cjs/src/routesFlow.cjs +2 -0
- package/.dist/cjs/src/routesFlow.cjs.map +1 -0
- package/.dist/cjs/src/routesFlow.d.ts +6 -0
- package/.dist/cjs/src/serializer.cjs +2 -0
- package/.dist/cjs/src/serializer.cjs.map +1 -0
- package/.dist/cjs/src/serializer.d.ts +13 -0
- package/.dist/cjs/src/storage.cjs +2 -0
- package/.dist/cjs/src/storage.cjs.map +1 -0
- package/.dist/cjs/src/storage.d.ts +11 -0
- package/.dist/cjs/src/subRequest.cjs +2 -0
- package/.dist/cjs/src/subRequest.cjs.map +1 -0
- package/.dist/cjs/src/subRequest.d.ts +23 -0
- package/.dist/cjs/src/testUtils.cjs +2 -0
- package/.dist/cjs/src/testUtils.cjs.map +1 -0
- package/.dist/cjs/src/testUtils.d.ts +1 -0
- package/.dist/cjs/src/typedEvent.cjs +2 -0
- package/.dist/cjs/src/typedEvent.cjs.map +1 -0
- package/.dist/cjs/src/typedEvent.d.ts +17 -0
- package/.dist/cjs/src/types.cjs +2 -0
- package/.dist/cjs/src/types.cjs.map +1 -0
- package/.dist/cjs/src/types.d.ts +152 -0
- package/.dist/cjs/src/validation.cjs +2 -0
- package/.dist/cjs/src/validation.cjs.map +1 -0
- package/.dist/cjs/src/validation.d.ts +4 -0
- package/.dist/esm/_virtual/jit-fns.js +1391 -0
- package/.dist/esm/_virtual/jit-fns.js.map +1 -0
- package/.dist/esm/_virtual/pure-fns.js +109 -0
- package/.dist/esm/_virtual/pure-fns.js.map +1 -0
- package/.dist/esm/_virtual/router-cache.js +5 -0
- package/.dist/esm/_virtual/router-cache.js.map +1 -0
- package/.dist/esm/index.d.ts +11 -0
- package/.dist/esm/index.js +80 -0
- package/.dist/esm/index.js.map +1 -0
- package/.dist/esm/src/aot/loadClientAOTCaches.d.ts +8 -0
- package/.dist/esm/src/aot/loadClientAOTCaches.js +19 -0
- package/.dist/esm/src/aot/loadClientAOTCaches.js.map +1 -0
- package/.dist/esm/src/client.d.ts +28 -0
- package/.dist/esm/src/client.js +185 -0
- package/.dist/esm/src/client.js.map +1 -0
- package/.dist/esm/src/clientMethodsMetadata.d.ts +10 -0
- package/.dist/esm/src/clientMethodsMetadata.js +162 -0
- package/.dist/esm/src/clientMethodsMetadata.js.map +1 -0
- package/.dist/esm/src/constants.d.ts +6 -0
- package/.dist/esm/src/constants.js +25 -0
- package/.dist/esm/src/constants.js.map +1 -0
- package/.dist/esm/src/handlersRegistry.d.ts +18 -0
- package/.dist/esm/src/handlersRegistry.js +70 -0
- package/.dist/esm/src/handlersRegistry.js.map +1 -0
- package/.dist/esm/src/request.d.ts +30 -0
- package/.dist/esm/src/request.js +289 -0
- package/.dist/esm/src/request.js.map +1 -0
- package/.dist/esm/src/routesFlow.d.ts +6 -0
- package/.dist/esm/src/routesFlow.js +61 -0
- package/.dist/esm/src/routesFlow.js.map +1 -0
- package/.dist/esm/src/serializer.d.ts +13 -0
- package/.dist/esm/src/serializer.js +139 -0
- package/.dist/esm/src/serializer.js.map +1 -0
- package/.dist/esm/src/storage.d.ts +11 -0
- package/.dist/esm/src/storage.js +48 -0
- package/.dist/esm/src/storage.js.map +1 -0
- package/.dist/esm/src/subRequest.d.ts +23 -0
- package/.dist/esm/src/subRequest.js +73 -0
- package/.dist/esm/src/subRequest.js.map +1 -0
- package/.dist/esm/src/testUtils.d.ts +1 -0
- package/.dist/esm/src/testUtils.js +48 -0
- package/.dist/esm/src/testUtils.js.map +1 -0
- package/.dist/esm/src/typedEvent.d.ts +17 -0
- package/.dist/esm/src/typedEvent.js +41 -0
- package/.dist/esm/src/typedEvent.js.map +1 -0
- package/.dist/esm/src/types.d.ts +152 -0
- package/.dist/esm/src/types.js +42 -0
- package/.dist/esm/src/types.js.map +1 -0
- package/.dist/esm/src/validation.d.ts +4 -0
- package/.dist/esm/src/validation.js +57 -0
- package/.dist/esm/src/validation.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +34 -0
- package/package.json +74 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { PURE_SERVER_FN_NAMESPACE, RpcError, __ΩMapFromServerFnRef as ___MapFromServerFnRef } from "@mionjs/core";
|
|
2
|
+
function __assignType(fn, args) {
|
|
3
|
+
return fn.__type = args, fn;
|
|
4
|
+
}
|
|
5
|
+
async function routesFlow(routeSubRequests, middleFns) {
|
|
6
|
+
if (!routeSubRequests || routeSubRequests.length === 0)
|
|
7
|
+
throw new RpcError({
|
|
8
|
+
type: "routesFlow-empty-routes",
|
|
9
|
+
publicMessage: "RoutesFlow requires at least one route subrequest."
|
|
10
|
+
});
|
|
11
|
+
const firstSubRequest = routeSubRequests[0];
|
|
12
|
+
if (!firstSubRequest.client)
|
|
13
|
+
throw new RpcError({
|
|
14
|
+
type: "routesFlow-missing-client",
|
|
15
|
+
publicMessage: "Could not extract MionClient from subrequest. Ensure subrequests are created via routes proxy."
|
|
16
|
+
});
|
|
17
|
+
const client = firstSubRequest.client;
|
|
18
|
+
for (let i = 1; i < routeSubRequests.length; i++)
|
|
19
|
+
if (routeSubRequests[i].client !== client)
|
|
20
|
+
throw new RpcError({
|
|
21
|
+
type: "routesFlow-client-mismatch",
|
|
22
|
+
publicMessage: `All subrequests in a routesFlow must use the same client instance. Subrequest at index ${i} has a different client.`
|
|
23
|
+
});
|
|
24
|
+
const [results, errors, middleFnResults, middleFnErrors] = await client.executeCallWithWorkflow(routeSubRequests, middleFns ?? {}), emptyResults = routeSubRequests.map(() => {
|
|
25
|
+
}), emptyErrors = routeSubRequests.map(() => {
|
|
26
|
+
});
|
|
27
|
+
return [results ?? emptyResults, errors ?? emptyErrors, middleFnResults, middleFnErrors];
|
|
28
|
+
}
|
|
29
|
+
routesFlow.__type = ["routeSubRequests", "middleFns", "WorkflowResult", "routesFlow", 'PP"@G2!"2"8"w#`/$'];
|
|
30
|
+
const mapFromSymbol = /* @__PURE__ */ Symbol("MapFromServerFnRef");
|
|
31
|
+
function mapFrom(source, mapper, bodyHash) {
|
|
32
|
+
if (!bodyHash)
|
|
33
|
+
throw new Error("mapFrom() requires mion vite plugin transform to inject bodyHash");
|
|
34
|
+
const ref = {
|
|
35
|
+
mapFromSymbol,
|
|
36
|
+
namespace: PURE_SERVER_FN_NAMESPACE,
|
|
37
|
+
fnName: bodyHash,
|
|
38
|
+
bodyHash,
|
|
39
|
+
pureFn: mapper,
|
|
40
|
+
isFactory: !1,
|
|
41
|
+
fromRequestId: source.id,
|
|
42
|
+
toRequestId: "",
|
|
43
|
+
paramIndex: -1,
|
|
44
|
+
type: __assignType(function() {
|
|
45
|
+
return ref;
|
|
46
|
+
}, ["type", 'P"/!'])
|
|
47
|
+
};
|
|
48
|
+
return ref;
|
|
49
|
+
}
|
|
50
|
+
mapFrom.__type = ["source", "resolvedValue", "value", "", "mapper", "bodyHash", () => ___MapFromServerFnRef, "resolvedValue", "mapFrom", `P"2!P"."f2#"/$2%&2&8P".(f2#"/$o'"/)`];
|
|
51
|
+
function isMapFromRef(ref) {
|
|
52
|
+
return ref && ref.mapFromSymbol === mapFromSymbol;
|
|
53
|
+
}
|
|
54
|
+
isMapFromRef.__type = ["ref", "isMapFromRef", 'P"2!!/"'];
|
|
55
|
+
export {
|
|
56
|
+
isMapFromRef,
|
|
57
|
+
mapFrom,
|
|
58
|
+
mapFromSymbol,
|
|
59
|
+
routesFlow
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=routesFlow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routesFlow.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ResponseBody } from '@mionjs/router';
|
|
2
|
+
import { MionClientRequest } from './request.ts';
|
|
3
|
+
export type SerializedBody = string | Uint8Array;
|
|
4
|
+
export type ContentType = 'application/json; charset=utf-8' | 'application/octet-stream';
|
|
5
|
+
export interface SerializedRequest {
|
|
6
|
+
body: SerializedBody;
|
|
7
|
+
contentType: ContentType;
|
|
8
|
+
}
|
|
9
|
+
export declare function serializeRequestBody(req: MionClientRequest<any, any>): SerializedRequest;
|
|
10
|
+
export declare function deserializeResponseBody(response: Response): Promise<ResponseBody>;
|
|
11
|
+
export declare type __ΩSerializedBody = any[];
|
|
12
|
+
export declare type __ΩContentType = any[];
|
|
13
|
+
export declare type __ΩSerializedRequest = any[];
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { MION_ROUTES, isRpcError, RpcError, deserializeBinaryBody, routesCache, HandlerType, serializeBinaryBody as serializeBinaryBody$1 } from "@mionjs/core";
|
|
2
|
+
import { DEFAULT_PREFILL_OPTIONS } from "./constants.js";
|
|
3
|
+
function __assignType(fn, args) {
|
|
4
|
+
return fn.__type = args, fn;
|
|
5
|
+
}
|
|
6
|
+
const __ΩSerializedBody = ["SerializedBody", "P&WJw!y"], __ΩContentType = ["application/json; charset=utf-8", "application/octet-stream", "ContentType", 'P.!."Jw#y'], __ΩSerializedRequest = [() => __ΩSerializedBody, "body", () => __ΩContentType, "contentType", "SerializedRequest", 'Pn!4"n#4$Mw%y'];
|
|
7
|
+
function getSerializerMode(req) {
|
|
8
|
+
const methodId = req.route?.id ?? req.workflowSubRequests?.[0]?.id, serializerMode = routesCache.getMethodJitFns(methodId)?.options.serializer || DEFAULT_PREFILL_OPTIONS.serializer;
|
|
9
|
+
return serializerMode === "json" ? DEFAULT_PREFILL_OPTIONS.serializer : serializerMode;
|
|
10
|
+
}
|
|
11
|
+
getSerializerMode.__type = ["MionClientRequest", "req", "SerializerMode", "getSerializerMode", 'P"w!2""w#/$'];
|
|
12
|
+
function serializeRequestBody(req) {
|
|
13
|
+
const serializerMode = getSerializerMode(req);
|
|
14
|
+
switch (serializerMode) {
|
|
15
|
+
case "json":
|
|
16
|
+
case "stringifyJson":
|
|
17
|
+
return {
|
|
18
|
+
body: stringifyBody(req),
|
|
19
|
+
contentType: "application/json; charset=utf-8"
|
|
20
|
+
};
|
|
21
|
+
case "binary":
|
|
22
|
+
return {
|
|
23
|
+
body: serializeBinaryBody(req),
|
|
24
|
+
contentType: "application/octet-stream"
|
|
25
|
+
};
|
|
26
|
+
default:
|
|
27
|
+
throw new Error(`Invalid serializer mode ${serializerMode}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
serializeRequestBody.__type = ["MionClientRequest", "req", () => __ΩSerializedRequest, "serializeRequestBody", 'P"w!2"n#/$'];
|
|
31
|
+
function serializeBinaryBody(req) {
|
|
32
|
+
const subRequestIds = Object.keys(req.subRequestList), body = {}, executionChain = [];
|
|
33
|
+
for (const id of subRequestIds) {
|
|
34
|
+
let params = req.subRequestList[id].params;
|
|
35
|
+
const method = routesCache.useMethodJitFns(id);
|
|
36
|
+
method.type === HandlerType.headersMiddleFn && method.headersParam && (params = getParamsWithoutHeadersSubset(params)), body[id] = params, executionChain.push(method);
|
|
37
|
+
}
|
|
38
|
+
const workflowRouteIds = req.workflowSubRequests?.map(__assignType((sr) => sr.id, ["sr", "", 'P"2!"/"'])), { buffer } = serializeBinaryBody$1(req.path, executionChain, body, !1, workflowRouteIds);
|
|
39
|
+
return new Uint8Array(buffer);
|
|
40
|
+
}
|
|
41
|
+
serializeBinaryBody.__type = ["MionClientRequest", "req", "serializeBinaryBody", 'P"w!2"W/#'];
|
|
42
|
+
async function deserializeResponseBody(response) {
|
|
43
|
+
const contentType = response.headers.get("content-type"), isJson = contentType?.includes("application/json"), isBinary = contentType?.includes("application/octet-stream");
|
|
44
|
+
let parsedBody;
|
|
45
|
+
if (isJson ? parsedBody = await deserializeJsonResponseBody(response) : isBinary ? parsedBody = await deserializeBinaryResponseBody(response) : parsedBody = await deserializeJsonResponseBody(response), MION_ROUTES.thrownErrors in parsedBody) {
|
|
46
|
+
const unexpectedErrors = parsedBody[MION_ROUTES.thrownErrors];
|
|
47
|
+
if (MION_ROUTES.platformError in unexpectedErrors) {
|
|
48
|
+
const globalErrorValue = unexpectedErrors[MION_ROUTES.platformError], platformError = isRpcError(globalErrorValue) ? new RpcError(globalErrorValue) : globalErrorValue;
|
|
49
|
+
return { [MION_ROUTES.platformError]: platformError };
|
|
50
|
+
}
|
|
51
|
+
Object.assign(parsedBody, unexpectedErrors), delete parsedBody[MION_ROUTES.thrownErrors];
|
|
52
|
+
}
|
|
53
|
+
if (isJson || !isJson && !isBinary) {
|
|
54
|
+
const deserializedBody = {};
|
|
55
|
+
return Object.entries(parsedBody).forEach(__assignType(([methodId, returnValue]) => {
|
|
56
|
+
const method = routesCache.useMethodJitFns(methodId), deserialized = parseHandlerReturnValue(method, returnValue);
|
|
57
|
+
deserializedBody[methodId] = deserialized;
|
|
58
|
+
}, ["param0", "", 'P"2!"/"'])), deserializedBody;
|
|
59
|
+
}
|
|
60
|
+
return parsedBody;
|
|
61
|
+
}
|
|
62
|
+
deserializeResponseBody.__type = ["response", "ResponseBody", "deserializeResponseBody", 'P!2!"w"`/#'];
|
|
63
|
+
async function deserializeJsonResponseBody(response) {
|
|
64
|
+
try {
|
|
65
|
+
return await response.json();
|
|
66
|
+
} catch (err) {
|
|
67
|
+
throw new RpcError({
|
|
68
|
+
type: "parsing-json-response-error",
|
|
69
|
+
publicMessage: `Invalid json response body: ${err?.message || "unknown parsing error."}`
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
deserializeJsonResponseBody.__type = ["response", "deserializeJsonResponseBody", 'P!2!"`/"'];
|
|
74
|
+
async function deserializeBinaryResponseBody(response) {
|
|
75
|
+
const arrayBuffer = await response.arrayBuffer(), { body } = deserializeBinaryBody("client-response", arrayBuffer, !0);
|
|
76
|
+
return body;
|
|
77
|
+
}
|
|
78
|
+
deserializeBinaryResponseBody.__type = ["response", "ResponseBody", "deserializeBinaryResponseBody", 'P!2!"w"`/#'];
|
|
79
|
+
function stringifyBody(req) {
|
|
80
|
+
const props = [], subRequestIds = Object.keys(req.subRequestList);
|
|
81
|
+
for (let i = 0; i < subRequestIds.length; i++) {
|
|
82
|
+
const id = subRequestIds[i], subRequest = req.subRequestList[id];
|
|
83
|
+
if (!subRequest)
|
|
84
|
+
continue;
|
|
85
|
+
let params = subRequest.params;
|
|
86
|
+
const method = routesCache.useMethodJitFns(id);
|
|
87
|
+
method.type === HandlerType.headersMiddleFn && method.headersParam && (params = getParamsWithoutHeadersSubset(params));
|
|
88
|
+
try {
|
|
89
|
+
const jsonValue = stringifyHandlerParams(method, params);
|
|
90
|
+
if (!jsonValue)
|
|
91
|
+
continue;
|
|
92
|
+
props.push(`${JSON.stringify(id)}:${jsonValue}`);
|
|
93
|
+
} catch (e) {
|
|
94
|
+
throw new RpcError({
|
|
95
|
+
type: "json-stringify-request-error",
|
|
96
|
+
publicMessage: `Failed to stringify params for handler ${id}`,
|
|
97
|
+
originalError: e
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return `{${props.join(",")}}`;
|
|
102
|
+
}
|
|
103
|
+
stringifyBody.__type = ["MionClientRequest", "req", "stringifyBody", 'P"w!2"&/#'];
|
|
104
|
+
function getParamsWithoutHeadersSubset(params) {
|
|
105
|
+
return !params || params.length === 0 ? [] : params.slice(1);
|
|
106
|
+
}
|
|
107
|
+
getParamsWithoutHeadersSubset.__type = ["params", "getParamsWithoutHeadersSubset", 'P"F2!"F/"'];
|
|
108
|
+
function stringifyHandlerParams(method, params) {
|
|
109
|
+
if (!method.paramNames || method.paramNames.length === 0)
|
|
110
|
+
return "";
|
|
111
|
+
const paramsJit = method.paramsJitFns;
|
|
112
|
+
return paramsJit.prepareForJson.isNoop ? JSON.stringify(params) : paramsJit.stringifyJson.fn(params);
|
|
113
|
+
}
|
|
114
|
+
stringifyHandlerParams.__type = ["MethodWithJitFns", "method", "params", "stringifyHandlerParams", 'P"w!2""F2#&/$'];
|
|
115
|
+
function parseHandlerReturnValue(method, returnValue) {
|
|
116
|
+
if (!method.hasReturnData)
|
|
117
|
+
return returnValue;
|
|
118
|
+
const returnJit = method.returnJitFns;
|
|
119
|
+
if (returnJit.restoreFromJson.isNoop || !returnValue)
|
|
120
|
+
return returnValue;
|
|
121
|
+
try {
|
|
122
|
+
return returnValue instanceof RpcError ? returnValue : isRpcError(returnValue) ? new RpcError(returnValue) : returnJit.restoreFromJson.fn(returnValue);
|
|
123
|
+
} catch (e) {
|
|
124
|
+
return new RpcError({
|
|
125
|
+
type: "deserialization-error",
|
|
126
|
+
publicMessage: `Invalid response from Route or MiddleFn '${method.id}', can not deserialize return value: ${e.message}`,
|
|
127
|
+
errorData: e?.errors
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
parseHandlerReturnValue.__type = ["MethodWithJitFns", "method", "returnValue", "parseHandlerReturnValue", 'P"w!2""2#"/$'];
|
|
132
|
+
export {
|
|
133
|
+
__ΩContentType,
|
|
134
|
+
__ΩSerializedBody,
|
|
135
|
+
__ΩSerializedRequest,
|
|
136
|
+
deserializeResponseBody,
|
|
137
|
+
serializeRequestBody
|
|
138
|
+
};
|
|
139
|
+
//# sourceMappingURL=serializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class MemoryStorage {
|
|
2
|
+
private data;
|
|
3
|
+
get length(): number;
|
|
4
|
+
getItem(key: string): string | null;
|
|
5
|
+
setItem(key: string, value: string): void;
|
|
6
|
+
removeItem(key: string): void;
|
|
7
|
+
clear(): void;
|
|
8
|
+
key(index: number): string | null;
|
|
9
|
+
}
|
|
10
|
+
export declare function getStorage(): Storage | MemoryStorage;
|
|
11
|
+
export declare function resetStorageInstance(): void;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const STORAGE_GLOBAL_KEY = "__mion_storage__";
|
|
2
|
+
class MemoryStorage {
|
|
3
|
+
data = (Map.Ω = [["&"], ["&"]], /* @__PURE__ */ new Map());
|
|
4
|
+
get length() {
|
|
5
|
+
return this.data.size;
|
|
6
|
+
}
|
|
7
|
+
getItem(key) {
|
|
8
|
+
return this.data.get(key) ?? null;
|
|
9
|
+
}
|
|
10
|
+
setItem(key, value) {
|
|
11
|
+
this.data.set(key, value);
|
|
12
|
+
}
|
|
13
|
+
removeItem(key) {
|
|
14
|
+
this.data.delete(key);
|
|
15
|
+
}
|
|
16
|
+
clear() {
|
|
17
|
+
this.data.clear();
|
|
18
|
+
}
|
|
19
|
+
key(index) {
|
|
20
|
+
return [...this.data.keys()][index] ?? null;
|
|
21
|
+
}
|
|
22
|
+
static __type = ["data", function() {
|
|
23
|
+
return Map.Ω = [["&"], ["&"]], /* @__PURE__ */ new Map();
|
|
24
|
+
}, "key", "getItem", "value", "setItem", "removeItem", "clear", "index", "MemoryStorage", `!3!;>"!P&2#P&,J0$P&2#&2%"0&P&2#"0'P"0(P'2)P&,J0#5w*`];
|
|
25
|
+
}
|
|
26
|
+
function getStorage() {
|
|
27
|
+
const existing = globalThis[STORAGE_GLOBAL_KEY];
|
|
28
|
+
if (existing)
|
|
29
|
+
return existing;
|
|
30
|
+
let storage;
|
|
31
|
+
try {
|
|
32
|
+
typeof localStorage < "u" ? (localStorage.setItem("__mion_test__", "1"), localStorage.removeItem("__mion_test__"), storage = localStorage) : storage = new MemoryStorage();
|
|
33
|
+
} catch {
|
|
34
|
+
storage = new MemoryStorage();
|
|
35
|
+
}
|
|
36
|
+
return globalThis[STORAGE_GLOBAL_KEY] = storage, storage;
|
|
37
|
+
}
|
|
38
|
+
getStorage.__type = [() => MemoryStorage, "getStorage", 'PP!P7!J/"'];
|
|
39
|
+
function resetStorageInstance() {
|
|
40
|
+
delete globalThis[STORAGE_GLOBAL_KEY];
|
|
41
|
+
}
|
|
42
|
+
resetStorageInstance.__type = ["resetStorageInstance", 'P"/!'];
|
|
43
|
+
export {
|
|
44
|
+
MemoryStorage,
|
|
45
|
+
getStorage,
|
|
46
|
+
resetStorageInstance
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { RpcError, RunTypeError, MapFromServerFnRef } from '@mionjs/core';
|
|
2
|
+
import { CallWithMiddleFnsResult, HSubRequest, RequestErrors, Result, RSubRequest, SubRequest, WorkflowResult } from './types.ts';
|
|
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 RSubRequest<any>, HSubRequest<any> {
|
|
6
|
+
readonly client: MionClient;
|
|
7
|
+
pointer: string[];
|
|
8
|
+
id: string;
|
|
9
|
+
isResolved: boolean;
|
|
10
|
+
params: any[];
|
|
11
|
+
resolvedValue?: S;
|
|
12
|
+
error?: E;
|
|
13
|
+
serializedParams?: any[];
|
|
14
|
+
mappings: MapFromServerFnRef[];
|
|
15
|
+
constructor(parentProps: string[], handlerId: string, argArray: any[], client: MionClient);
|
|
16
|
+
prefill(): TypedEvent<S, E>;
|
|
17
|
+
removePrefill(): Promise<void>;
|
|
18
|
+
call(): Promise<Result<S, E>>;
|
|
19
|
+
callWithMiddleFns<H extends Record<string, HSubRequest<any>>>(middleFns: H): Promise<CallWithMiddleFnsResult<S, E, H>>;
|
|
20
|
+
callWithWorkflow<OtherRoutes extends RSubRequest<any>[], H extends Record<string, HSubRequest<any>>>(otherRoutes: [...OtherRoutes], middleFns?: H): Promise<WorkflowResult<[RSubRequest<any>, ...OtherRoutes], H>>;
|
|
21
|
+
typeErrors(): Promise<RunTypeError[]>;
|
|
22
|
+
}
|
|
23
|
+
export declare function findSubRequestError(subRequest: SubRequest<any>, errors: RequestErrors): RpcError<string>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { RpcError } from "@mionjs/core";
|
|
2
|
+
import { TypedEvent } from "./typedEvent.js";
|
|
3
|
+
import { isMapFromRef } from "./routesFlow.js";
|
|
4
|
+
function __assignType(fn, args) {
|
|
5
|
+
return fn.__type = args, fn;
|
|
6
|
+
}
|
|
7
|
+
class MionSubRequest {
|
|
8
|
+
client;
|
|
9
|
+
pointer;
|
|
10
|
+
id;
|
|
11
|
+
isResolved = !1;
|
|
12
|
+
params;
|
|
13
|
+
resolvedValue;
|
|
14
|
+
error;
|
|
15
|
+
serializedParams;
|
|
16
|
+
mappings = [];
|
|
17
|
+
constructor(parentProps, handlerId, argArray, client) {
|
|
18
|
+
this.client = client, this.pointer = [...parentProps], this.id = handlerId, this.params = argArray.map(__assignType((arg, index) => isMapFromRef(arg) ? (arg.toRequestId = this.id, arg.paramIndex = index, this.mappings.push(arg), null) : arg, ["arg", "index", "", 'P"2!"2""/#']));
|
|
19
|
+
}
|
|
20
|
+
/** Prefills MiddleFn's parameters and returns TypedEvent for event handler registration */
|
|
21
|
+
prefill() {
|
|
22
|
+
const typedEvent = (TypedEvent.Ω = [["!"], ["!"]], new TypedEvent(this.id, this.client.handlersRegistry));
|
|
23
|
+
return this.client.prefill(this).catch(__assignType((errors) => {
|
|
24
|
+
console.error("Prefill error:", findSubRequestError(this, errors));
|
|
25
|
+
}, ["RequestErrors", "errors", "", 'P"w!2""/#'])), typedEvent;
|
|
26
|
+
}
|
|
27
|
+
/** Removes prefilled value and clears any registered error handlers for this middleFn */
|
|
28
|
+
removePrefill() {
|
|
29
|
+
return this.client.handlersRegistry.clearHandlers(this.id), this.client.removePrefill(this);
|
|
30
|
+
}
|
|
31
|
+
/** Calls a remote route and returns a Result 4-tuple with full typing preserved */
|
|
32
|
+
call() {
|
|
33
|
+
return this.client.executeCall(this);
|
|
34
|
+
}
|
|
35
|
+
/** Calls a remote route with middleFns and returns a fully-typed 4-tuple result */
|
|
36
|
+
callWithMiddleFns(middleFns) {
|
|
37
|
+
if (Object.keys(middleFns).length === 0)
|
|
38
|
+
throw new Error("callWithMiddleFns requires at least one middleFn. Use call() instead for requests without middleFns.");
|
|
39
|
+
return this.client.executeCallWithMiddleFns(this, middleFns);
|
|
40
|
+
}
|
|
41
|
+
/** Calls this route as part of a routesFlow with other routes in a single HTTP request */
|
|
42
|
+
async callWithWorkflow(otherRoutes, middleFns) {
|
|
43
|
+
const allRoutes = [this, ...otherRoutes], [results, errors, middleFnResults, middleFnErrors] = await this.client.executeCallWithWorkflow(allRoutes, middleFns ?? {}), emptyResults = allRoutes.map(() => {
|
|
44
|
+
}), emptyErrors = allRoutes.map(() => {
|
|
45
|
+
});
|
|
46
|
+
return [results ?? emptyResults, errors ?? emptyErrors, middleFnResults, middleFnErrors];
|
|
47
|
+
}
|
|
48
|
+
/** Validates parameters and returns type errors */
|
|
49
|
+
typeErrors() {
|
|
50
|
+
return this.client.typeErrors(this).catch(__assignType((errors) => Promise.reject(findSubRequestError(this, errors)), ["RequestErrors", "errors", "", 'P"w!2""/#']));
|
|
51
|
+
}
|
|
52
|
+
static __type = ["S", "E", "pointer", "id", "isResolved", function() {
|
|
53
|
+
return !1;
|
|
54
|
+
}, "params", "resolvedValue", "error", "serializedParams", "MapFromServerFnRef", "mappings", function() {
|
|
55
|
+
return [];
|
|
56
|
+
}, "parentProps", "handlerId", "argArray", "MionClient", "client", "constructor", () => TypedEvent, "prefill", "removePrefill", "Result", "call", "middleFns", "CallWithMiddleFnsResult", "callWithMiddleFns", "otherRoutes", "WorkflowResult", "callWithWorkflow", "RunTypeError", "typeErrors", "RSubRequest", "HSubRequest", "MionSubRequest", '"c!"c"&F3#&3$)3%>&"F3\'e!!3(8e!"3)8"F3*8"w+F3,>-P&F2.&2/"F20"w1229"03PPe#!e#"7405P$`06P"w7`08P"29"w:`0;PP"@G2<"298"w=`0>P"w?F`0@5"wA"wBx#wC'];
|
|
57
|
+
}
|
|
58
|
+
function findSubRequestError(subRequest, errors) {
|
|
59
|
+
const specificError = errors.get(subRequest.id);
|
|
60
|
+
if (specificError)
|
|
61
|
+
return specificError;
|
|
62
|
+
const firstError = errors.values().next().value;
|
|
63
|
+
return firstError || new RpcError({
|
|
64
|
+
type: "unknown-error",
|
|
65
|
+
publicMessage: "An unknown error occurred"
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
findSubRequestError.__type = ["SubRequest", "subRequest", "RequestErrors", "errors", () => RpcError, "findSubRequestError", 'P"w!2""w#2$P&7%/&'];
|
|
69
|
+
export {
|
|
70
|
+
MionSubRequest,
|
|
71
|
+
findSubRequestError
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=subRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function resetClientCaches(): void;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { MION_ROUTES, routesCache, resetJitFnCaches, resetJitFunctionsCache, addAOTCaches, getJitFnHashes } from "@mionjs/core";
|
|
2
|
+
import { getAOTCaches } from "./clientMethodsMetadata.js";
|
|
3
|
+
function resetClientCaches() {
|
|
4
|
+
const { jitFnsCache, pureFnsCache } = getAOTCaches(), mionRouteIds = new Set(Object.values(MION_ROUTES)), cache = routesCache.getCache();
|
|
5
|
+
for (const key in cache)
|
|
6
|
+
mionRouteIds.has(key) || delete cache[key];
|
|
7
|
+
resetJitFnCaches(), resetJitFunctionsCache();
|
|
8
|
+
const neededJitHashes = (Set.Ω = [["&"]], /* @__PURE__ */ new Set()), neededPureFnKeys = (Set.Ω = [["&"]], /* @__PURE__ */ new Set());
|
|
9
|
+
for (const routeId of mionRouteIds) {
|
|
10
|
+
const meta = routesCache.getMetadata(routeId);
|
|
11
|
+
meta && (collectJitDepsFromParentHash(meta.paramsJitHash, neededJitHashes, neededPureFnKeys, jitFnsCache), collectJitDepsFromParentHash(meta.returnJitHash, neededJitHashes, neededPureFnKeys, jitFnsCache), meta.headersParam && collectJitDepsFromParentHash(meta.headersParam.jitHash, neededJitHashes, neededPureFnKeys, jitFnsCache), meta.headersReturn && collectJitDepsFromParentHash(meta.headersReturn.jitHash, neededJitHashes, neededPureFnKeys, jitFnsCache));
|
|
12
|
+
}
|
|
13
|
+
const filteredJitFns = {};
|
|
14
|
+
for (const hash of neededJitHashes)
|
|
15
|
+
hash in jitFnsCache && (filteredJitFns[hash] = jitFnsCache[hash]);
|
|
16
|
+
const filteredPureFns = {};
|
|
17
|
+
for (const key of neededPureFnKeys) {
|
|
18
|
+
const [ns, fnHash] = key.split("::");
|
|
19
|
+
pureFnsCache[ns]?.[fnHash] && (filteredPureFns[ns] || (filteredPureFns[ns] = {}), filteredPureFns[ns][fnHash] = pureFnsCache[ns][fnHash]);
|
|
20
|
+
}
|
|
21
|
+
(Object.keys(filteredJitFns).length > 0 || Object.keys(filteredPureFns).length > 0) && addAOTCaches(filteredJitFns, filteredPureFns);
|
|
22
|
+
}
|
|
23
|
+
resetClientCaches.__type = ["resetClientCaches", 'P"/!'];
|
|
24
|
+
function collectJitDepsFromParentHash(parentHash, jitHashes, pureFnKeys, jitFnsCache) {
|
|
25
|
+
if (!parentHash)
|
|
26
|
+
return;
|
|
27
|
+
const hashes = getJitFnHashes(parentHash);
|
|
28
|
+
for (const individualHash of Object.values(hashes))
|
|
29
|
+
collectJitDeps(individualHash, jitHashes, pureFnKeys, jitFnsCache);
|
|
30
|
+
}
|
|
31
|
+
collectJitDepsFromParentHash.__type = ["parentHash", "jitHashes", "pureFnKeys", "PersistedJitFunctionsCache", "jitFnsCache", "collectJitDepsFromParentHash", 'P&2!&D2"&D2#"w$2%"/&'];
|
|
32
|
+
function collectJitDeps(hash, jitHashes, pureFnKeys, jitFnsCache) {
|
|
33
|
+
if (!hash || jitHashes.has(hash))
|
|
34
|
+
return;
|
|
35
|
+
jitHashes.add(hash);
|
|
36
|
+
const entry = jitFnsCache[hash];
|
|
37
|
+
if (entry) {
|
|
38
|
+
for (const dep of entry.jitDependencies)
|
|
39
|
+
collectJitDeps(dep, jitHashes, pureFnKeys, jitFnsCache);
|
|
40
|
+
for (const pureDep of entry.pureFnDependencies)
|
|
41
|
+
pureFnKeys.add(pureDep);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
collectJitDeps.__type = ["hash", "jitHashes", "pureFnKeys", "PersistedJitFunctionsCache", "jitFnsCache", "collectJitDeps", 'P&2!&D2"&D2#"w$2%"/&'];
|
|
45
|
+
export {
|
|
46
|
+
resetClientCaches
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=testUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testUtils.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RpcError } from '@mionjs/core';
|
|
2
|
+
import { HandlersRegistry } from './handlersRegistry.ts';
|
|
3
|
+
import { SuccessHandler } from './types.ts';
|
|
4
|
+
export declare class TypedEvent<S = void, E extends RpcError<string, any> = never> {
|
|
5
|
+
private readonly handlerId;
|
|
6
|
+
private readonly registry;
|
|
7
|
+
constructor(handlerId: string, registry: HandlersRegistry);
|
|
8
|
+
onSuccess(handler: SuccessHandler<S>): TypedEvent<S, E>;
|
|
9
|
+
offSuccess(): TypedEvent<S, E>;
|
|
10
|
+
onError<T extends E['type']>(errorType: T, handler: (error: Extract<E, {
|
|
11
|
+
type: T;
|
|
12
|
+
}>) => void): TypedEvent<S, E>;
|
|
13
|
+
offError<T extends E['type']>(errorType: T): TypedEvent<S, E>;
|
|
14
|
+
getHandlerId(): string;
|
|
15
|
+
hasErrorHandler(errorType: string): boolean;
|
|
16
|
+
hasSuccessHandler(): boolean;
|
|
17
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const __ΩExtract = ["T", "U", "Extract", `l6e$!R!RPe#!e$"qk#'QRb!b"Pde"!p)w#y`];
|
|
2
|
+
class TypedEvent {
|
|
3
|
+
handlerId;
|
|
4
|
+
registry;
|
|
5
|
+
constructor(handlerId, registry) {
|
|
6
|
+
this.handlerId = handlerId, this.registry = registry;
|
|
7
|
+
}
|
|
8
|
+
/** Register a persistent success handler for this middleFn */
|
|
9
|
+
onSuccess(handler) {
|
|
10
|
+
return this.registry.registerSuccess(this.handlerId, handler), this;
|
|
11
|
+
}
|
|
12
|
+
/** Remove a previously registered success handler from HandlersRegistry */
|
|
13
|
+
offSuccess() {
|
|
14
|
+
return this.registry.unregisterSuccess(this.handlerId), this;
|
|
15
|
+
}
|
|
16
|
+
/** Register a persistent error handler for this middleFn */
|
|
17
|
+
onError(errorType, handler) {
|
|
18
|
+
return this.registry.register(this.handlerId, errorType, handler), this;
|
|
19
|
+
}
|
|
20
|
+
/** Remove a previously registered error handler from HandlersRegistry */
|
|
21
|
+
offError(errorType) {
|
|
22
|
+
return this.registry.unregister(this.handlerId, errorType), this;
|
|
23
|
+
}
|
|
24
|
+
/** Get the handler ID this event is associated with */
|
|
25
|
+
getHandlerId() {
|
|
26
|
+
return this.handlerId;
|
|
27
|
+
}
|
|
28
|
+
/** Check if an error handler is registered for a specific error type */
|
|
29
|
+
hasErrorHandler(errorType) {
|
|
30
|
+
return this.registry.hasHandler(this.handlerId, errorType);
|
|
31
|
+
}
|
|
32
|
+
/** Check if a success handler is registered */
|
|
33
|
+
hasSuccessHandler() {
|
|
34
|
+
return this.registry.hasSuccessHandler(this.handlerId);
|
|
35
|
+
}
|
|
36
|
+
static __type = ["S", "E", "handlerId", "HandlersRegistry", "registry", "constructor", "SuccessHandler", "handler", () => TypedEvent, "onSuccess", () => TypedEvent, "offSuccess", "errorType", () => __ΩExtract, "type", "error", "", () => TypedEvent, "onError", () => TypedEvent, "offError", "getHandlerId", "hasErrorHandler", "hasSuccessHandler", "TypedEvent", `$c!!c"P&2#;9"w$2%;9"0&P"w'2(Pe#!e#"7)0*PPe#!e#"7+0,P"2-Pe#"P"4/Mo.#20$/12(Pe#!e#"7203P"2-Pe#!e#"7405P&06P&2-)07P)085w9`];
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
TypedEvent
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=typedEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typedEvent.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|