@adep/runtime 0.3.6 → 0.3.8
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/index.js +39 -5
- package/dist/shared/multipart.js +106 -0
- package/dist/shared/sql-split.js +54 -0
- package/dist/storage/driver.d.ts +1 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -6,6 +6,8 @@ var ExecutorError = class extends Error {
|
|
|
6
6
|
this.code = code;
|
|
7
7
|
this.name = "ExecutorError";
|
|
8
8
|
}
|
|
9
|
+
status;
|
|
10
|
+
code;
|
|
9
11
|
};
|
|
10
12
|
var TIMEOUT_CODE = "FN_EXEC_TIMEOUT";
|
|
11
13
|
var OOM_CODE = "FN_EXEC_OOM";
|
|
@@ -364,6 +366,8 @@ var DbError = class extends Error {
|
|
|
364
366
|
this.code = code;
|
|
365
367
|
this.name = "DbError";
|
|
366
368
|
}
|
|
369
|
+
status;
|
|
370
|
+
code;
|
|
367
371
|
};
|
|
368
372
|
var IDENTIFIER_PATTERN = /^[A-Za-z_][A-Za-z0-9_]{0,62}$/;
|
|
369
373
|
function assertIdentifier(name) {
|
|
@@ -1248,9 +1252,12 @@ var StorageError = class extends Error {
|
|
|
1248
1252
|
this.code = code;
|
|
1249
1253
|
this.name = "StorageError";
|
|
1250
1254
|
}
|
|
1255
|
+
status;
|
|
1256
|
+
code;
|
|
1251
1257
|
};
|
|
1252
1258
|
var STORAGE_CODES = {
|
|
1253
1259
|
invalidPath: "STORAGE_INVALID_PATH",
|
|
1260
|
+
invalidData: "STORAGE_INVALID_DATA",
|
|
1254
1261
|
notFound: "STORAGE_NOT_FOUND",
|
|
1255
1262
|
quotaExceeded: "STORAGE_QUOTA_EXCEEDED"
|
|
1256
1263
|
};
|
|
@@ -1502,11 +1509,33 @@ function verifyDownloadSignature(config, projectId, path, query, nowSeconds2 = M
|
|
|
1502
1509
|
var DEFAULT_VISIBILITY = "private";
|
|
1503
1510
|
function asBytes(data) {
|
|
1504
1511
|
if (typeof data === "string") return new TextEncoder().encode(data);
|
|
1505
|
-
if (data
|
|
1506
|
-
if (data
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1512
|
+
if (isArrayBufferLike(data)) return new Uint8Array(data);
|
|
1513
|
+
if (isBytes(data)) return toByteView(data);
|
|
1514
|
+
if (isFunctionFile(data)) {
|
|
1515
|
+
if (isBytes(data.data)) return toByteView(data.data);
|
|
1516
|
+
if (isArrayBufferLike(data.data)) return new Uint8Array(data.data);
|
|
1517
|
+
if (typeof data.data === "string") return new TextEncoder().encode(data.data);
|
|
1518
|
+
}
|
|
1519
|
+
throw new StorageError(400, STORAGE_CODES.invalidData, describeUnsupportedUploadData(data));
|
|
1520
|
+
}
|
|
1521
|
+
function isArrayBufferLike(value) {
|
|
1522
|
+
return Object.prototype.toString.call(value) === "[object ArrayBuffer]";
|
|
1523
|
+
}
|
|
1524
|
+
function isBytes(value) {
|
|
1525
|
+
return ArrayBuffer.isView(value) && !(Object.prototype.toString.call(value) === "[object DataView]");
|
|
1526
|
+
}
|
|
1527
|
+
function toByteView(view) {
|
|
1528
|
+
return new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
|
|
1529
|
+
}
|
|
1530
|
+
function isFunctionFile(value) {
|
|
1531
|
+
if (typeof value !== "object" || value === null) return false;
|
|
1532
|
+
const candidate = value;
|
|
1533
|
+
return typeof candidate.name === "string" && "data" in candidate;
|
|
1534
|
+
}
|
|
1535
|
+
function describeUnsupportedUploadData(data) {
|
|
1536
|
+
const tag = Object.prototype.toString.call(data);
|
|
1537
|
+
const constructorName = typeof data === "object" && data !== null ? data.constructor?.name ?? "unknown" : "none";
|
|
1538
|
+
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`;
|
|
1510
1539
|
}
|
|
1511
1540
|
function toStoredFile(meta) {
|
|
1512
1541
|
return {
|
|
@@ -2069,11 +2098,13 @@ var SimDbError = class extends Error {
|
|
|
2069
2098
|
this.code = code;
|
|
2070
2099
|
this.name = "SimDbError";
|
|
2071
2100
|
}
|
|
2101
|
+
code;
|
|
2072
2102
|
};
|
|
2073
2103
|
var ParamCursor = class {
|
|
2074
2104
|
constructor(params) {
|
|
2075
2105
|
this.params = params;
|
|
2076
2106
|
}
|
|
2107
|
+
params;
|
|
2077
2108
|
index = 0;
|
|
2078
2109
|
take() {
|
|
2079
2110
|
const v = this.params[this.index];
|
|
@@ -2255,16 +2286,19 @@ var ExcludedRef = class {
|
|
|
2255
2286
|
constructor(column) {
|
|
2256
2287
|
this.column = column;
|
|
2257
2288
|
}
|
|
2289
|
+
column;
|
|
2258
2290
|
};
|
|
2259
2291
|
var ColumnRef = class {
|
|
2260
2292
|
constructor(column) {
|
|
2261
2293
|
this.column = column;
|
|
2262
2294
|
}
|
|
2295
|
+
column;
|
|
2263
2296
|
};
|
|
2264
2297
|
var ExprRef = class {
|
|
2265
2298
|
constructor(source) {
|
|
2266
2299
|
this.source = source;
|
|
2267
2300
|
}
|
|
2301
|
+
source;
|
|
2268
2302
|
};
|
|
2269
2303
|
function resolveSetValue(value, existing, row) {
|
|
2270
2304
|
if (value instanceof ExcludedRef) return row[value.column];
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// packages/runtime/src/shared/multipart.ts
|
|
2
|
+
var MultipartParseError = class extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "MultipartParseError";
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
function extractBoundary(contentType) {
|
|
9
|
+
const match = /boundary\s*=\s*(?:"([^"]+)"|([^;\s]+))/i.exec(contentType);
|
|
10
|
+
if (match === null) {
|
|
11
|
+
throw new MultipartParseError("Content-Type \u7F3A\u5C11 boundary \u53C2\u6570\uFF0C\u65E0\u6CD5\u89E3\u6790 multipart \u8BF7\u6C42\u4F53");
|
|
12
|
+
}
|
|
13
|
+
const boundary = match[1] ?? match[2];
|
|
14
|
+
if (boundary === void 0 || boundary.length === 0) {
|
|
15
|
+
throw new MultipartParseError("Content-Type \u7684 boundary \u4E3A\u7A7A");
|
|
16
|
+
}
|
|
17
|
+
return boundary;
|
|
18
|
+
}
|
|
19
|
+
var HEADER_BODY_SEP = [13, 10, 13, 10];
|
|
20
|
+
var encoder = new TextEncoder();
|
|
21
|
+
var decoder = new TextDecoder();
|
|
22
|
+
function indexOfSequence(haystack, needle, from) {
|
|
23
|
+
outer: for (let i = from; i + needle.length <= haystack.length; i++) {
|
|
24
|
+
for (let j = 0; j < needle.length; j++) {
|
|
25
|
+
if (haystack[i + j] !== needle[j]) continue outer;
|
|
26
|
+
}
|
|
27
|
+
return i;
|
|
28
|
+
}
|
|
29
|
+
return -1;
|
|
30
|
+
}
|
|
31
|
+
function unquote(value) {
|
|
32
|
+
return value.replace(/\\(.)/g, "$1");
|
|
33
|
+
}
|
|
34
|
+
function parseMultipart(contentType, raw) {
|
|
35
|
+
const boundary = extractBoundary(contentType);
|
|
36
|
+
const delim = encoder.encode(`--${boundary}`);
|
|
37
|
+
const positions = [];
|
|
38
|
+
scan: for (let i = 0; i + delim.length <= raw.length; i++) {
|
|
39
|
+
if (raw[i] !== delim[0]) continue;
|
|
40
|
+
for (let j = 1; j < delim.length; j++) {
|
|
41
|
+
if (raw[i + j] !== delim[j]) continue scan;
|
|
42
|
+
}
|
|
43
|
+
positions.push(i);
|
|
44
|
+
}
|
|
45
|
+
if (positions.length === 0) {
|
|
46
|
+
throw new MultipartParseError(
|
|
47
|
+
`\u8BF7\u6C42\u4F53\u91CC\u627E\u4E0D\u5230 boundary "${boundary}" \u7684\u5206\u9694\u7B26\u2014\u2014\u53EF\u80FD\u662F\u8BF7\u6C42\u88AB\u622A\u65AD\u6216 Content-Type \u4E0E\u8BF7\u6C42\u4F53\u4E0D\u5339\u914D`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
const lastPos = positions[positions.length - 1];
|
|
51
|
+
if (raw[lastPos + delim.length] !== 45 || raw[lastPos + delim.length + 1] !== 45) {
|
|
52
|
+
throw new MultipartParseError("multipart \u6570\u636E\u88AB\u622A\u65AD\uFF1A\u7F3A\u5C11\u7EC8\u7ED3\u5206\u9694\u7B26 --boundary--");
|
|
53
|
+
}
|
|
54
|
+
const files = [];
|
|
55
|
+
const fields = {};
|
|
56
|
+
let fieldCount = 0;
|
|
57
|
+
for (let k = 0; k + 1 < positions.length; k++) {
|
|
58
|
+
const partStart = positions[k] + delim.length + 2;
|
|
59
|
+
const partEnd = positions[k + 1] - 2;
|
|
60
|
+
if (raw[partStart - 2] !== 13 || raw[partStart - 1] !== 10) {
|
|
61
|
+
throw new MultipartParseError("multipart \u5206\u9694\u7B26\u540E\u7F3A\u5C11 CRLF\uFF0C\u8BF7\u6C42\u4F53\u683C\u5F0F\u975E\u6CD5");
|
|
62
|
+
}
|
|
63
|
+
if (partEnd < partStart) {
|
|
64
|
+
throw new MultipartParseError("multipart part \u5185\u5BB9\u4E3A\u7A7A\uFF08header \u4E0E\u6B63\u6587\u90FD\u4E0D\u5B58\u5728\uFF09");
|
|
65
|
+
}
|
|
66
|
+
const part = raw.subarray(partStart, partEnd);
|
|
67
|
+
const headerSep = indexOfSequence(part, HEADER_BODY_SEP, 0);
|
|
68
|
+
if (headerSep < 0) {
|
|
69
|
+
throw new MultipartParseError("multipart part \u7F3A\u5C11 header \u4E0E\u6B63\u6587\u4E4B\u95F4\u7684\u7A7A\u884C\u5206\u9694");
|
|
70
|
+
}
|
|
71
|
+
const headerLines = decoder.decode(part.subarray(0, headerSep)).split("\r\n");
|
|
72
|
+
const data = part.subarray(headerSep + HEADER_BODY_SEP.length);
|
|
73
|
+
const disposition = headerLines.find(
|
|
74
|
+
(line) => line.toLowerCase().startsWith("content-disposition:")
|
|
75
|
+
);
|
|
76
|
+
if (disposition === void 0) {
|
|
77
|
+
throw new MultipartParseError("multipart part \u7F3A\u5C11 Content-Disposition \u5934");
|
|
78
|
+
}
|
|
79
|
+
const nameMatch = /name="((?:[^"\\]|\\.)*)"/.exec(disposition);
|
|
80
|
+
if (nameMatch === null) {
|
|
81
|
+
throw new MultipartParseError("multipart part \u7684 Content-Disposition \u7F3A\u5C11 name \u53C2\u6570");
|
|
82
|
+
}
|
|
83
|
+
const fieldName = unquote(nameMatch[1]);
|
|
84
|
+
const filenameMatch = /filename="((?:[^"\\]|\\.)*)"/.exec(disposition);
|
|
85
|
+
if (filenameMatch !== null) {
|
|
86
|
+
const clientName = unquote(filenameMatch[1]);
|
|
87
|
+
if (clientName === "") continue;
|
|
88
|
+
const typeLine = headerLines.find((line) => line.toLowerCase().startsWith("content-type:"));
|
|
89
|
+
const type = typeLine === void 0 ? "application/octet-stream" : typeLine.slice(typeLine.indexOf(":") + 1).trim();
|
|
90
|
+
files.push({ name: clientName, type, size: data.length, data });
|
|
91
|
+
} else {
|
|
92
|
+
const value = decoder.decode(data);
|
|
93
|
+
const prev = fields[fieldName];
|
|
94
|
+
if (prev === void 0) fields[fieldName] = value;
|
|
95
|
+
else if (typeof prev === "string") fields[fieldName] = [prev, value];
|
|
96
|
+
else fields[fieldName] = [...prev, value];
|
|
97
|
+
fieldCount++;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return { fields: fieldCount > 0 ? fields : void 0, files };
|
|
101
|
+
}
|
|
102
|
+
export {
|
|
103
|
+
MultipartParseError,
|
|
104
|
+
extractBoundary,
|
|
105
|
+
parseMultipart
|
|
106
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// packages/runtime/src/shared/sql-split.ts
|
|
2
|
+
function splitSqlStatements(source) {
|
|
3
|
+
const statements = [];
|
|
4
|
+
let buffer = "";
|
|
5
|
+
let inQuote = false;
|
|
6
|
+
const lines = source.split("\n");
|
|
7
|
+
for (const rawLine of lines) {
|
|
8
|
+
const trimmed = rawLine.trim();
|
|
9
|
+
if (!inQuote && (trimmed.length === 0 || trimmed.startsWith("--"))) continue;
|
|
10
|
+
const scanLine = inQuote ? rawLine : trimmed;
|
|
11
|
+
for (let i = 0; i < scanLine.length; i++) {
|
|
12
|
+
const ch = scanLine[i];
|
|
13
|
+
if (inQuote) {
|
|
14
|
+
if (ch === "'") {
|
|
15
|
+
if (scanLine[i + 1] === "'") {
|
|
16
|
+
buffer += ch + scanLine[i + 1];
|
|
17
|
+
i++;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
inQuote = false;
|
|
21
|
+
}
|
|
22
|
+
buffer += ch;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (ch === "'") {
|
|
26
|
+
inQuote = true;
|
|
27
|
+
buffer += ch;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (ch === "-" && scanLine[i + 1] === "-") break;
|
|
31
|
+
if (ch === ";") {
|
|
32
|
+
const statement = buffer.trim();
|
|
33
|
+
if (statement.length > 0) statements.push(statement);
|
|
34
|
+
buffer = "";
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
buffer += ch;
|
|
38
|
+
}
|
|
39
|
+
if (inQuote) {
|
|
40
|
+
buffer += "\n";
|
|
41
|
+
} else if (buffer.length > 0 && !/\s$/.test(buffer)) {
|
|
42
|
+
buffer += " ";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (inQuote) {
|
|
46
|
+
throw new Error(`SQL \u811A\u672C\u5F15\u53F7\u672A\u95ED\u5408\uFF1A${buffer.trim().slice(0, 80)}\u2026`);
|
|
47
|
+
}
|
|
48
|
+
const tail = buffer.trim();
|
|
49
|
+
if (tail.length > 0) statements.push(tail);
|
|
50
|
+
return statements;
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
splitSqlStatements
|
|
54
|
+
};
|
package/dist/storage/driver.d.ts
CHANGED
|
@@ -56,6 +56,7 @@ export declare class StorageError extends Error {
|
|
|
56
56
|
}
|
|
57
57
|
export declare const STORAGE_CODES: {
|
|
58
58
|
readonly invalidPath: "STORAGE_INVALID_PATH";
|
|
59
|
+
readonly invalidData: "STORAGE_INVALID_DATA";
|
|
59
60
|
readonly notFound: "STORAGE_NOT_FOUND";
|
|
60
61
|
readonly quotaExceeded: "STORAGE_QUOTA_EXCEEDED";
|
|
61
62
|
};
|
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.3.
|
|
10
|
+
"version": "0.3.8",
|
|
11
11
|
"private": false,
|
|
12
12
|
"type": "module",
|
|
13
13
|
"sideEffects": false,
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@adep/types": "0.
|
|
35
|
+
"@adep/types": "0.4.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"test": "vitest run",
|