@adep/cli 0.4.11 → 0.5.1
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/README.md +18 -0
- package/dist/index.js +992 -109
- package/dist/vite.js +312 -17
- package/dist/worker-entry.js +85 -1
- package/package.json +4 -4
package/dist/vite.js
CHANGED
|
@@ -51,6 +51,8 @@ var ExecutorError = class extends Error {
|
|
|
51
51
|
this.code = code;
|
|
52
52
|
this.name = "ExecutorError";
|
|
53
53
|
}
|
|
54
|
+
status;
|
|
55
|
+
code;
|
|
54
56
|
};
|
|
55
57
|
var TIMEOUT_CODE = "FN_EXEC_TIMEOUT";
|
|
56
58
|
var OOM_CODE = "FN_EXEC_OOM";
|
|
@@ -430,6 +432,8 @@ var DbError = class extends Error {
|
|
|
430
432
|
this.code = code;
|
|
431
433
|
this.name = "DbError";
|
|
432
434
|
}
|
|
435
|
+
status;
|
|
436
|
+
code;
|
|
433
437
|
};
|
|
434
438
|
var IDENTIFIER_PATTERN = /^[A-Za-z_][A-Za-z0-9_]{0,62}$/;
|
|
435
439
|
function assertIdentifier(name) {
|
|
@@ -1212,11 +1216,13 @@ var SimDbError = class extends Error {
|
|
|
1212
1216
|
this.code = code;
|
|
1213
1217
|
this.name = "SimDbError";
|
|
1214
1218
|
}
|
|
1219
|
+
code;
|
|
1215
1220
|
};
|
|
1216
1221
|
var ParamCursor = class {
|
|
1217
1222
|
constructor(params) {
|
|
1218
1223
|
this.params = params;
|
|
1219
1224
|
}
|
|
1225
|
+
params;
|
|
1220
1226
|
index = 0;
|
|
1221
1227
|
take() {
|
|
1222
1228
|
const v = this.params[this.index];
|
|
@@ -1398,16 +1404,19 @@ var ExcludedRef = class {
|
|
|
1398
1404
|
constructor(column) {
|
|
1399
1405
|
this.column = column;
|
|
1400
1406
|
}
|
|
1407
|
+
column;
|
|
1401
1408
|
};
|
|
1402
1409
|
var ColumnRef = class {
|
|
1403
1410
|
constructor(column) {
|
|
1404
1411
|
this.column = column;
|
|
1405
1412
|
}
|
|
1413
|
+
column;
|
|
1406
1414
|
};
|
|
1407
1415
|
var ExprRef = class {
|
|
1408
1416
|
constructor(source) {
|
|
1409
1417
|
this.source = source;
|
|
1410
1418
|
}
|
|
1419
|
+
source;
|
|
1411
1420
|
};
|
|
1412
1421
|
function resolveSetValue(value, existing, row) {
|
|
1413
1422
|
if (value instanceof ExcludedRef) return row[value.column];
|
|
@@ -2064,9 +2073,12 @@ var StorageError = class extends Error {
|
|
|
2064
2073
|
this.code = code;
|
|
2065
2074
|
this.name = "StorageError";
|
|
2066
2075
|
}
|
|
2076
|
+
status;
|
|
2077
|
+
code;
|
|
2067
2078
|
};
|
|
2068
2079
|
var STORAGE_CODES = {
|
|
2069
2080
|
invalidPath: "STORAGE_INVALID_PATH",
|
|
2081
|
+
invalidData: "STORAGE_INVALID_DATA",
|
|
2070
2082
|
notFound: "STORAGE_NOT_FOUND",
|
|
2071
2083
|
quotaExceeded: "STORAGE_QUOTA_EXCEEDED"
|
|
2072
2084
|
};
|
|
@@ -2294,11 +2306,33 @@ function signDownloadUrl(config, projectId, path, ttlSeconds = DEFAULT_SIGN_TTL_
|
|
|
2294
2306
|
var DEFAULT_VISIBILITY = "private";
|
|
2295
2307
|
function asBytes(data) {
|
|
2296
2308
|
if (typeof data === "string") return new TextEncoder().encode(data);
|
|
2297
|
-
if (data
|
|
2298
|
-
if (data
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2309
|
+
if (isArrayBufferLike(data)) return new Uint8Array(data);
|
|
2310
|
+
if (isBytes(data)) return toByteView(data);
|
|
2311
|
+
if (isFunctionFile(data)) {
|
|
2312
|
+
if (isBytes(data.data)) return toByteView(data.data);
|
|
2313
|
+
if (isArrayBufferLike(data.data)) return new Uint8Array(data.data);
|
|
2314
|
+
if (typeof data.data === "string") return new TextEncoder().encode(data.data);
|
|
2315
|
+
}
|
|
2316
|
+
throw new StorageError(400, STORAGE_CODES.invalidData, describeUnsupportedUploadData(data));
|
|
2317
|
+
}
|
|
2318
|
+
function isArrayBufferLike(value) {
|
|
2319
|
+
return Object.prototype.toString.call(value) === "[object ArrayBuffer]";
|
|
2320
|
+
}
|
|
2321
|
+
function isBytes(value) {
|
|
2322
|
+
return ArrayBuffer.isView(value) && !(Object.prototype.toString.call(value) === "[object DataView]");
|
|
2323
|
+
}
|
|
2324
|
+
function toByteView(view) {
|
|
2325
|
+
return new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
|
|
2326
|
+
}
|
|
2327
|
+
function isFunctionFile(value) {
|
|
2328
|
+
if (typeof value !== "object" || value === null) return false;
|
|
2329
|
+
const candidate = value;
|
|
2330
|
+
return typeof candidate.name === "string" && "data" in candidate;
|
|
2331
|
+
}
|
|
2332
|
+
function describeUnsupportedUploadData(data) {
|
|
2333
|
+
const tag = Object.prototype.toString.call(data);
|
|
2334
|
+
const constructorName = typeof data === "object" && data !== null ? data.constructor?.name ?? "unknown" : "none";
|
|
2335
|
+
return `\u4E0D\u652F\u6301\u7684\u5B58\u50A8\u6570\u636E\u7C7B\u578B\uFF08\u80FD\u529B cloud.storage\uFF0C\u65B9\u6CD5 upload\uFF09\uFF1Atypeof=${typeof data}\uFF0CtoString=${tag}\uFF0Cconstructor=${constructorName}\u3002\u652F\u6301\uFF1Astring / Uint8Array / ArrayBuffer / ctx.files\uFF08FunctionFile\uFF09\u3002\u82E5\u6570\u636E\u6765\u81EA\u5BB9\u5668\u6267\u884C\u5668\uFF0C\u8BF7\u786E\u8BA4\u5DF2\u5347\u7EA7\u5230\u5305\u542B RPC typed-array \u7F16\u89E3\u7801\u7684\u8FD0\u884C\u65F6\u955C\u50CF\u3002`;
|
|
2302
2336
|
}
|
|
2303
2337
|
function toStoredFile(meta) {
|
|
2304
2338
|
return {
|
|
@@ -3001,6 +3035,189 @@ async function applyLocalSchema(driver, options) {
|
|
|
3001
3035
|
log(`[${tag}] \u5DF2\u5E94\u7528\u6570\u636E\u5E93\u7ED3\u6784\uFF08--schema ${schemaFile}\uFF09\uFF1A${applied} \u6761\u8BED\u53E5${skipNote}`);
|
|
3002
3036
|
}
|
|
3003
3037
|
|
|
3038
|
+
// packages/runtime/src/shared/fetch-blocked-ports.ts
|
|
3039
|
+
var FETCH_BLOCKED_PORTS = /* @__PURE__ */ new Set([
|
|
3040
|
+
1,
|
|
3041
|
+
7,
|
|
3042
|
+
9,
|
|
3043
|
+
11,
|
|
3044
|
+
13,
|
|
3045
|
+
15,
|
|
3046
|
+
17,
|
|
3047
|
+
19,
|
|
3048
|
+
20,
|
|
3049
|
+
21,
|
|
3050
|
+
22,
|
|
3051
|
+
23,
|
|
3052
|
+
25,
|
|
3053
|
+
37,
|
|
3054
|
+
42,
|
|
3055
|
+
43,
|
|
3056
|
+
53,
|
|
3057
|
+
69,
|
|
3058
|
+
77,
|
|
3059
|
+
79,
|
|
3060
|
+
87,
|
|
3061
|
+
95,
|
|
3062
|
+
101,
|
|
3063
|
+
102,
|
|
3064
|
+
103,
|
|
3065
|
+
104,
|
|
3066
|
+
109,
|
|
3067
|
+
110,
|
|
3068
|
+
111,
|
|
3069
|
+
113,
|
|
3070
|
+
115,
|
|
3071
|
+
117,
|
|
3072
|
+
119,
|
|
3073
|
+
123,
|
|
3074
|
+
135,
|
|
3075
|
+
137,
|
|
3076
|
+
139,
|
|
3077
|
+
143,
|
|
3078
|
+
161,
|
|
3079
|
+
179,
|
|
3080
|
+
389,
|
|
3081
|
+
427,
|
|
3082
|
+
465,
|
|
3083
|
+
512,
|
|
3084
|
+
513,
|
|
3085
|
+
514,
|
|
3086
|
+
515,
|
|
3087
|
+
526,
|
|
3088
|
+
530,
|
|
3089
|
+
531,
|
|
3090
|
+
532,
|
|
3091
|
+
540,
|
|
3092
|
+
548,
|
|
3093
|
+
554,
|
|
3094
|
+
556,
|
|
3095
|
+
563,
|
|
3096
|
+
587,
|
|
3097
|
+
601,
|
|
3098
|
+
636,
|
|
3099
|
+
989,
|
|
3100
|
+
990,
|
|
3101
|
+
993,
|
|
3102
|
+
995,
|
|
3103
|
+
1719,
|
|
3104
|
+
1720,
|
|
3105
|
+
1723,
|
|
3106
|
+
2049,
|
|
3107
|
+
3659,
|
|
3108
|
+
4045,
|
|
3109
|
+
4190,
|
|
3110
|
+
5060,
|
|
3111
|
+
5061,
|
|
3112
|
+
6e3,
|
|
3113
|
+
6566,
|
|
3114
|
+
6665,
|
|
3115
|
+
6666,
|
|
3116
|
+
6667,
|
|
3117
|
+
6668,
|
|
3118
|
+
6669,
|
|
3119
|
+
6679,
|
|
3120
|
+
6697,
|
|
3121
|
+
10080
|
|
3122
|
+
]);
|
|
3123
|
+
function isFetchBlockedPort(port) {
|
|
3124
|
+
if (!Number.isInteger(port)) {
|
|
3125
|
+
throw new TypeError(`[fetch-blocked-ports] \u7AEF\u53E3\u5FC5\u987B\u662F\u6574\u6570\uFF1A\u6536\u5230 ${String(port)}`);
|
|
3126
|
+
}
|
|
3127
|
+
return FETCH_BLOCKED_PORTS.has(port);
|
|
3128
|
+
}
|
|
3129
|
+
|
|
3130
|
+
// packages/cli/src/serve/fetch-safe-port.ts
|
|
3131
|
+
var MAX_FETCH_SAFE_LISTEN_ATTEMPTS = 8;
|
|
3132
|
+
function listenOnce(server, port, host) {
|
|
3133
|
+
return new Promise((resolve5, reject) => {
|
|
3134
|
+
const onError = (error) => {
|
|
3135
|
+
server.off("error", onError);
|
|
3136
|
+
reject(error);
|
|
3137
|
+
};
|
|
3138
|
+
server.once("error", onError);
|
|
3139
|
+
server.listen(port, host, () => {
|
|
3140
|
+
server.off("error", onError);
|
|
3141
|
+
resolve5();
|
|
3142
|
+
});
|
|
3143
|
+
});
|
|
3144
|
+
}
|
|
3145
|
+
function closeServer(server) {
|
|
3146
|
+
return new Promise((resolve5, reject) => {
|
|
3147
|
+
server.close((error) => error === void 0 ? resolve5() : reject(error));
|
|
3148
|
+
});
|
|
3149
|
+
}
|
|
3150
|
+
async function closeQuietly(server) {
|
|
3151
|
+
try {
|
|
3152
|
+
await closeServer(server);
|
|
3153
|
+
} catch (error) {
|
|
3154
|
+
if (error.code !== "ERR_SERVER_NOT_RUNNING") throw error;
|
|
3155
|
+
}
|
|
3156
|
+
}
|
|
3157
|
+
function readTcpPort(server, host) {
|
|
3158
|
+
const address = server.address();
|
|
3159
|
+
if (address === null || typeof address === "string") {
|
|
3160
|
+
throw new Error(
|
|
3161
|
+
`[adep] ${host} listen \u6210\u529F\u540E address() \u8FD4\u56DE ${JSON.stringify(address)}\uFF0C\u65E0\u6CD5\u5224\u5B9A\u7AEF\u53E3\uFF1B\u672C\u5730 dev / serve \u5FC5\u987B\u662F Internet \u57DF socket\u3002`
|
|
3162
|
+
);
|
|
3163
|
+
}
|
|
3164
|
+
return address.port;
|
|
3165
|
+
}
|
|
3166
|
+
function buildExhaustedMessage(input) {
|
|
3167
|
+
return [
|
|
3168
|
+
`[adep] ${input.host} \u4E0A\u8FDE\u7EED ${input.maxAttempts} \u6B21 listen(0) \u90FD\u843D\u5728 undici \u62D2\u7EDD\u8BBF\u95EE\u7684\u7AEF\u53E3\u5185\uFF08\u547D\u4E2D\uFF1A${input.hits.join(", ")}\uFF09\uFF0C\u6700\u540E\u4E00\u6B21\u5DF2 close\u3002`,
|
|
3169
|
+
"\u8FD9\u4E9B\u7AEF\u53E3\u7684\u8BF7\u6C42\u5728\u5EFA\u7ACB\u8FDE\u63A5\u4E4B\u524D\u5C31\u4F1A\u88AB fetch \u62D2\u7EDD\uFF08TypeError: fetch failed / cause: bad port\uFF09\uFF0C\u6D4F\u89C8\u5668\u5BFC\u822A\u5219\u662F ERR_UNSAFE_PORT\u2014\u2014\u670D\u52A1\u8D77\u6765\u4E86\u4F46\u9875\u9762\u6253\u4E0D\u5F00\u3002",
|
|
3170
|
+
"\u53EF\u80FD\u539F\u56E0\uFF1A\u7CFB\u7EDF\u4E34\u65F6\u7AEF\u53E3\u8D77\u59CB\u503C\u88AB\u8C03\u4F4E\uFF08Windows \u7528 netsh int ipv4 show dynamicport tcp \u6838\u5BF9\uFF0CHyper-V / \u5BB9\u5668\u7F51\u7EDC\u4F1A\u6539\u5B83\uFF09\u3002\u53EF\u7528 --port \u6307\u5B9A\u4E00\u4E2A\u672A\u5360\u7528\u7684\u7AEF\u53E3\u7ED5\u8FC7\u3002"
|
|
3171
|
+
].join("\n");
|
|
3172
|
+
}
|
|
3173
|
+
async function listenOnFetchSafePort(server, options) {
|
|
3174
|
+
const isBlocked = options.isBlocked ?? isFetchBlockedPort;
|
|
3175
|
+
const warn = options.warn ?? (() => {
|
|
3176
|
+
});
|
|
3177
|
+
const notifyListenError = async (error) => {
|
|
3178
|
+
try {
|
|
3179
|
+
await options.onListenError?.(error);
|
|
3180
|
+
} catch {
|
|
3181
|
+
}
|
|
3182
|
+
};
|
|
3183
|
+
if (options.port !== 0) {
|
|
3184
|
+
try {
|
|
3185
|
+
await listenOnce(server, options.port, options.host);
|
|
3186
|
+
} catch (error) {
|
|
3187
|
+
await notifyListenError(error);
|
|
3188
|
+
throw error;
|
|
3189
|
+
}
|
|
3190
|
+
const actual = readTcpPort(server, options.host);
|
|
3191
|
+
if (isBlocked(actual)) {
|
|
3192
|
+
warn(
|
|
3193
|
+
`[adep] \u7AEF\u53E3 ${actual} \u5728 undici / \u6D4F\u89C8\u5668\u7684\u300C\u4E0D\u5B89\u5168\u7AEF\u53E3\u300D\u540D\u5355\u5185\uFF1A\u670D\u52A1\u53EF\u4EE5\u8D77\u6765\uFF0C\u4F46 fetch \u4F1A\u5728\u5EFA\u7ACB\u8FDE\u63A5\u524D\u62A5 bad port\u3001\u6D4F\u89C8\u5668\u5BFC\u822A\u62A5 ERR_UNSAFE_PORT\u3002\u5EFA\u8BAE\u6362\u4E2A\u7AEF\u53E3\u3002`
|
|
3194
|
+
);
|
|
3195
|
+
}
|
|
3196
|
+
return actual;
|
|
3197
|
+
}
|
|
3198
|
+
const maxAttempts = options.maxAttempts ?? MAX_FETCH_SAFE_LISTEN_ATTEMPTS;
|
|
3199
|
+
const hits = [];
|
|
3200
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
3201
|
+
try {
|
|
3202
|
+
await listenOnce(server, 0, options.host);
|
|
3203
|
+
} catch (error) {
|
|
3204
|
+
await notifyListenError(error);
|
|
3205
|
+
throw error;
|
|
3206
|
+
}
|
|
3207
|
+
let actual;
|
|
3208
|
+
try {
|
|
3209
|
+
actual = readTcpPort(server, options.host);
|
|
3210
|
+
} catch (error) {
|
|
3211
|
+
await closeQuietly(server);
|
|
3212
|
+
throw error;
|
|
3213
|
+
}
|
|
3214
|
+
if (!isBlocked(actual)) return actual;
|
|
3215
|
+
hits.push(actual);
|
|
3216
|
+
await closeQuietly(server);
|
|
3217
|
+
}
|
|
3218
|
+
throw new Error(buildExhaustedMessage({ host: options.host, hits, maxAttempts }));
|
|
3219
|
+
}
|
|
3220
|
+
|
|
3004
3221
|
// packages/cli/src/sim/env.ts
|
|
3005
3222
|
import { readFile as readFile4 } from "node:fs/promises";
|
|
3006
3223
|
import { join as join6 } from "node:path";
|
|
@@ -4548,6 +4765,90 @@ function createRpcClient(capability, port, pending, nextId) {
|
|
|
4548
4765
|
});
|
|
4549
4766
|
}
|
|
4550
4767
|
|
|
4768
|
+
// packages/runtime/src/functions/runtime/rpc-codec.ts
|
|
4769
|
+
var RPC_VALUE_TAG_KEY = "__adepRpcType";
|
|
4770
|
+
var RPC_VALUE_TAGS = {
|
|
4771
|
+
typedArray: "Uint8Array",
|
|
4772
|
+
arrayBuffer: "ArrayBuffer",
|
|
4773
|
+
date: "Date",
|
|
4774
|
+
map: "Map",
|
|
4775
|
+
set: "Set",
|
|
4776
|
+
undefined: "undefined",
|
|
4777
|
+
number: "Number",
|
|
4778
|
+
bigint: "BigInt",
|
|
4779
|
+
/** 转义:用户对象自身带 `RPC_VALUE_TAG_KEY` 键时的包装形态。 */
|
|
4780
|
+
object: "Object"
|
|
4781
|
+
};
|
|
4782
|
+
var RPC_VALUE_MAX_BYTES = 8 * 1024 * 1024;
|
|
4783
|
+
function base64ToBytes(base64) {
|
|
4784
|
+
const binary = atob(base64);
|
|
4785
|
+
const bytes = new Uint8Array(binary.length);
|
|
4786
|
+
for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.charCodeAt(index);
|
|
4787
|
+
return bytes;
|
|
4788
|
+
}
|
|
4789
|
+
function decodeRpcValue(value) {
|
|
4790
|
+
if (Array.isArray(value)) return value.map((entry) => decodeRpcValue(entry));
|
|
4791
|
+
if (typeof value !== "object" || value === null) return value;
|
|
4792
|
+
const nativeTag = Object.prototype.toString.call(value);
|
|
4793
|
+
if (ArrayBuffer.isView(value) || nativeTag === "[object ArrayBuffer]" || nativeTag === "[object Date]" || nativeTag === "[object Map]" || nativeTag === "[object Set]") {
|
|
4794
|
+
return value;
|
|
4795
|
+
}
|
|
4796
|
+
const candidate = value;
|
|
4797
|
+
const tag = candidate[RPC_VALUE_TAG_KEY];
|
|
4798
|
+
if (typeof tag !== "string") {
|
|
4799
|
+
const output = {};
|
|
4800
|
+
for (const [key, entry] of Object.entries(candidate)) output[key] = decodeRpcValue(entry);
|
|
4801
|
+
return output;
|
|
4802
|
+
}
|
|
4803
|
+
switch (tag) {
|
|
4804
|
+
case RPC_VALUE_TAGS.typedArray:
|
|
4805
|
+
return base64ToBytes(String(candidate["data"] ?? ""));
|
|
4806
|
+
case RPC_VALUE_TAGS.arrayBuffer: {
|
|
4807
|
+
const bytes = base64ToBytes(String(candidate["data"] ?? ""));
|
|
4808
|
+
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
4809
|
+
}
|
|
4810
|
+
case RPC_VALUE_TAGS.date:
|
|
4811
|
+
return new Date(String(candidate["data"] ?? ""));
|
|
4812
|
+
case RPC_VALUE_TAGS.map: {
|
|
4813
|
+
const entries = Array.isArray(candidate["data"]) ? candidate["data"] : [];
|
|
4814
|
+
const map = /* @__PURE__ */ new Map();
|
|
4815
|
+
for (const entry of entries) {
|
|
4816
|
+
if (!Array.isArray(entry) || entry.length < 2) continue;
|
|
4817
|
+
map.set(decodeRpcValue(entry[0]), decodeRpcValue(entry[1]));
|
|
4818
|
+
}
|
|
4819
|
+
return map;
|
|
4820
|
+
}
|
|
4821
|
+
case RPC_VALUE_TAGS.set: {
|
|
4822
|
+
const values = Array.isArray(candidate["data"]) ? candidate["data"] : [];
|
|
4823
|
+
return new Set(values.map((entry) => decodeRpcValue(entry)));
|
|
4824
|
+
}
|
|
4825
|
+
case RPC_VALUE_TAGS.undefined:
|
|
4826
|
+
return void 0;
|
|
4827
|
+
case RPC_VALUE_TAGS.number: {
|
|
4828
|
+
const raw = String(candidate["data"] ?? "");
|
|
4829
|
+
if (raw === "NaN") return Number.NaN;
|
|
4830
|
+
if (raw === "Infinity") return Number.POSITIVE_INFINITY;
|
|
4831
|
+
if (raw === "-Infinity") return Number.NEGATIVE_INFINITY;
|
|
4832
|
+
return Number(raw);
|
|
4833
|
+
}
|
|
4834
|
+
case RPC_VALUE_TAGS.bigint:
|
|
4835
|
+
return BigInt(String(candidate["data"] ?? "0"));
|
|
4836
|
+
case RPC_VALUE_TAGS.object: {
|
|
4837
|
+
const escaped = candidate["data"];
|
|
4838
|
+
if (typeof escaped !== "object" || escaped === null) return {};
|
|
4839
|
+
const output = {};
|
|
4840
|
+
for (const [key, entry] of Object.entries(escaped)) {
|
|
4841
|
+
output[key] = decodeRpcValue(entry);
|
|
4842
|
+
}
|
|
4843
|
+
return output;
|
|
4844
|
+
}
|
|
4845
|
+
default:
|
|
4846
|
+
return Object.fromEntries(
|
|
4847
|
+
Object.entries(candidate).filter(([key]) => key !== RPC_VALUE_TAG_KEY).map(([key, entry]) => [key, decodeRpcValue(entry)])
|
|
4848
|
+
);
|
|
4849
|
+
}
|
|
4850
|
+
}
|
|
4851
|
+
|
|
4551
4852
|
// packages/runtime/src/functions/runtime/rpc-wire.ts
|
|
4552
4853
|
function wireRpcResponses(port, pending) {
|
|
4553
4854
|
port.on?.((message) => {
|
|
@@ -4556,7 +4857,7 @@ function wireRpcResponses(port, pending) {
|
|
|
4556
4857
|
const entry = pending.get(reply.id);
|
|
4557
4858
|
if (entry === void 0) return;
|
|
4558
4859
|
pending.delete(reply.id);
|
|
4559
|
-
if (reply.ok === true) entry.resolve(reply.result);
|
|
4860
|
+
if (reply.ok === true) entry.resolve(decodeRpcValue(reply.result));
|
|
4560
4861
|
else entry.reject(new Error(reply.error ?? "RPC \u80FD\u529B\u8C03\u7528\u5931\u8D25"));
|
|
4561
4862
|
});
|
|
4562
4863
|
}
|
|
@@ -5427,18 +5728,12 @@ async function startDevServer(options) {
|
|
|
5427
5728
|
} catch {
|
|
5428
5729
|
}
|
|
5429
5730
|
};
|
|
5430
|
-
await
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
server.listen(port, "127.0.0.1", () => {
|
|
5436
|
-
server.off("error", onListenError);
|
|
5437
|
-
resolveListen();
|
|
5438
|
-
});
|
|
5731
|
+
const actualPort = await listenOnFetchSafePort(server, {
|
|
5732
|
+
port,
|
|
5733
|
+
host: "127.0.0.1",
|
|
5734
|
+
warn: log,
|
|
5735
|
+
onListenError: disposeAfterListenError
|
|
5439
5736
|
});
|
|
5440
|
-
const address = server.address();
|
|
5441
|
-
const actualPort = typeof address === "object" && address !== null ? address.port : port;
|
|
5442
5737
|
const baseUrl = `http://127.0.0.1:${actualPort}`;
|
|
5443
5738
|
const coldStartMs = Date.now() - coldStartAt;
|
|
5444
5739
|
const curlPath = config.functionsPrefix.length === 0 ? "/hello" : `/${config.functionsPrefix}/hello`;
|
package/dist/worker-entry.js
CHANGED
|
@@ -812,6 +812,90 @@ function createRpcClient(capability, port, pending, nextId) {
|
|
|
812
812
|
});
|
|
813
813
|
}
|
|
814
814
|
|
|
815
|
+
// packages/runtime/src/functions/runtime/rpc-codec.ts
|
|
816
|
+
var RPC_VALUE_TAG_KEY = "__adepRpcType";
|
|
817
|
+
var RPC_VALUE_TAGS = {
|
|
818
|
+
typedArray: "Uint8Array",
|
|
819
|
+
arrayBuffer: "ArrayBuffer",
|
|
820
|
+
date: "Date",
|
|
821
|
+
map: "Map",
|
|
822
|
+
set: "Set",
|
|
823
|
+
undefined: "undefined",
|
|
824
|
+
number: "Number",
|
|
825
|
+
bigint: "BigInt",
|
|
826
|
+
/** 转义:用户对象自身带 `RPC_VALUE_TAG_KEY` 键时的包装形态。 */
|
|
827
|
+
object: "Object"
|
|
828
|
+
};
|
|
829
|
+
var RPC_VALUE_MAX_BYTES = 8 * 1024 * 1024;
|
|
830
|
+
function base64ToBytes(base64) {
|
|
831
|
+
const binary = atob(base64);
|
|
832
|
+
const bytes = new Uint8Array(binary.length);
|
|
833
|
+
for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.charCodeAt(index);
|
|
834
|
+
return bytes;
|
|
835
|
+
}
|
|
836
|
+
function decodeRpcValue(value) {
|
|
837
|
+
if (Array.isArray(value)) return value.map((entry) => decodeRpcValue(entry));
|
|
838
|
+
if (typeof value !== "object" || value === null) return value;
|
|
839
|
+
const nativeTag = Object.prototype.toString.call(value);
|
|
840
|
+
if (ArrayBuffer.isView(value) || nativeTag === "[object ArrayBuffer]" || nativeTag === "[object Date]" || nativeTag === "[object Map]" || nativeTag === "[object Set]") {
|
|
841
|
+
return value;
|
|
842
|
+
}
|
|
843
|
+
const candidate = value;
|
|
844
|
+
const tag = candidate[RPC_VALUE_TAG_KEY];
|
|
845
|
+
if (typeof tag !== "string") {
|
|
846
|
+
const output = {};
|
|
847
|
+
for (const [key, entry] of Object.entries(candidate)) output[key] = decodeRpcValue(entry);
|
|
848
|
+
return output;
|
|
849
|
+
}
|
|
850
|
+
switch (tag) {
|
|
851
|
+
case RPC_VALUE_TAGS.typedArray:
|
|
852
|
+
return base64ToBytes(String(candidate["data"] ?? ""));
|
|
853
|
+
case RPC_VALUE_TAGS.arrayBuffer: {
|
|
854
|
+
const bytes = base64ToBytes(String(candidate["data"] ?? ""));
|
|
855
|
+
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
856
|
+
}
|
|
857
|
+
case RPC_VALUE_TAGS.date:
|
|
858
|
+
return new Date(String(candidate["data"] ?? ""));
|
|
859
|
+
case RPC_VALUE_TAGS.map: {
|
|
860
|
+
const entries = Array.isArray(candidate["data"]) ? candidate["data"] : [];
|
|
861
|
+
const map = /* @__PURE__ */ new Map();
|
|
862
|
+
for (const entry of entries) {
|
|
863
|
+
if (!Array.isArray(entry) || entry.length < 2) continue;
|
|
864
|
+
map.set(decodeRpcValue(entry[0]), decodeRpcValue(entry[1]));
|
|
865
|
+
}
|
|
866
|
+
return map;
|
|
867
|
+
}
|
|
868
|
+
case RPC_VALUE_TAGS.set: {
|
|
869
|
+
const values = Array.isArray(candidate["data"]) ? candidate["data"] : [];
|
|
870
|
+
return new Set(values.map((entry) => decodeRpcValue(entry)));
|
|
871
|
+
}
|
|
872
|
+
case RPC_VALUE_TAGS.undefined:
|
|
873
|
+
return void 0;
|
|
874
|
+
case RPC_VALUE_TAGS.number: {
|
|
875
|
+
const raw = String(candidate["data"] ?? "");
|
|
876
|
+
if (raw === "NaN") return Number.NaN;
|
|
877
|
+
if (raw === "Infinity") return Number.POSITIVE_INFINITY;
|
|
878
|
+
if (raw === "-Infinity") return Number.NEGATIVE_INFINITY;
|
|
879
|
+
return Number(raw);
|
|
880
|
+
}
|
|
881
|
+
case RPC_VALUE_TAGS.bigint:
|
|
882
|
+
return BigInt(String(candidate["data"] ?? "0"));
|
|
883
|
+
case RPC_VALUE_TAGS.object: {
|
|
884
|
+
const escaped = candidate["data"];
|
|
885
|
+
if (typeof escaped !== "object" || escaped === null) return {};
|
|
886
|
+
const output = {};
|
|
887
|
+
for (const [key, entry] of Object.entries(escaped)) {
|
|
888
|
+
output[key] = decodeRpcValue(entry);
|
|
889
|
+
}
|
|
890
|
+
return output;
|
|
891
|
+
}
|
|
892
|
+
default:
|
|
893
|
+
return Object.fromEntries(
|
|
894
|
+
Object.entries(candidate).filter(([key]) => key !== RPC_VALUE_TAG_KEY).map(([key, entry]) => [key, decodeRpcValue(entry)])
|
|
895
|
+
);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
|
|
815
899
|
// packages/runtime/src/functions/runtime/rpc-wire.ts
|
|
816
900
|
function wireRpcResponses(port, pending) {
|
|
817
901
|
port.on?.((message) => {
|
|
@@ -820,7 +904,7 @@ function wireRpcResponses(port, pending) {
|
|
|
820
904
|
const entry = pending.get(reply.id);
|
|
821
905
|
if (entry === void 0) return;
|
|
822
906
|
pending.delete(reply.id);
|
|
823
|
-
if (reply.ok === true) entry.resolve(reply.result);
|
|
907
|
+
if (reply.ok === true) entry.resolve(decodeRpcValue(reply.result));
|
|
824
908
|
else entry.reject(new Error(reply.error ?? "RPC \u80FD\u529B\u8C03\u7528\u5931\u8D25"));
|
|
825
909
|
});
|
|
826
910
|
}
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
},
|
|
8
8
|
"homepage": "https://adep.top",
|
|
9
9
|
"bugs": "https://gitcode.com/yunqiang_wu/ai-yunke/issues",
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.5.1",
|
|
11
11
|
"type": "module",
|
|
12
12
|
"description": "`adep` 命令行工具包位:登录 / 初始化 / 本地调试 / 部署 / 数据库维护 / 云存储 / 静态托管 / 微前端组件(widget),实现见任务单 CLI-001 ~ CLI-003 与 FE-002;子路径 `@adep/cli/vite` 提供云函数 vite 插件(CLI-014)",
|
|
13
13
|
"bin": {
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
"zod": "^4.6.6",
|
|
33
33
|
"@adep/app-runtime": "0.1.1",
|
|
34
34
|
"@adep/cf-compat": "0.1.4",
|
|
35
|
-
"@adep/vite-plugin": "0.1.11",
|
|
36
35
|
"@adep/crypto": "0.1.1",
|
|
37
|
-
"@adep/
|
|
36
|
+
"@adep/vite-plugin": "0.1.11",
|
|
37
|
+
"@adep/runtime": "0.3.8"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@adep/types": "0.
|
|
40
|
+
"@adep/types": "0.4.1"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"test": "vitest run",
|