@adep/runtime 0.3.5 → 0.3.7

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 CHANGED
@@ -1024,6 +1024,20 @@ var CLOUD_DB_SPEC = {
1024
1024
  };
1025
1025
  var WRITE_TERMINALS = /* @__PURE__ */ new Set(["insert", "insertMany", "update", "delete"]);
1026
1026
  function errorWithCode(error) {
1027
+ if (error instanceof Error) {
1028
+ const sqlite = /no such table: (\S+)/.exec(error.message);
1029
+ if (sqlite !== null) {
1030
+ return new Error(
1031
+ `[DB_TABLE_MISSING] \u9879\u76EE\u5E93\u5DF2\u542F\u52A8\u4F46\u7F3A\u8868 "${sqlite[1]}"\uFF1A\u8BF7\u6267\u884C adep db migrate <schema.sql> \u5EFA\u8868\uFF08\u53D1\u5E03\u4E0D\u542B\u5EFA\u8868\uFF09\u3002\u539F\u59CB\u9519\u8BEF\uFF1A${error.message}`
1032
+ );
1033
+ }
1034
+ const pg = /relation "([^"]+)" does not exist/.exec(error.message);
1035
+ if (pg !== null) {
1036
+ return new Error(
1037
+ `[DB_TABLE_MISSING] \u9879\u76EE\u5E93\u5DF2\u542F\u52A8\u4F46\u7F3A\u8868\uFF08\u6216\u5173\u7CFB\uFF09"${pg[1]}"\uFF1A\u8BF7\u6267\u884C adep db migrate <schema.sql> \u5EFA\u8868\uFF08\u53D1\u5E03\u4E0D\u542B\u5EFA\u8868\uFF09\u3002\u539F\u59CB\u9519\u8BEF\uFF1A${error.message}`
1038
+ );
1039
+ }
1040
+ }
1027
1041
  const code = typeof error === "object" && error !== null && typeof error.code === "string" ? error.code : void 0;
1028
1042
  if (code !== void 0 && error instanceof Error) {
1029
1043
  return new Error(`[${code}] ${error.message}`);
@@ -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/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.5",
10
+ "version": "0.3.7",
11
11
  "private": false,
12
12
  "type": "module",
13
13
  "sideEffects": false,