@weapp-sqlite/devtools 0.0.0-init.0 → 0.1.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/README.md +39 -4
- package/dist/client/assets/browser-agent-rpc-BXhoSh1z-B8VY0LVK.js +1 -0
- package/dist/client/assets/index-C4MpIW3V.css +1 -0
- package/dist/client/assets/index-qEaVRY93.js +6 -0
- package/dist/client/index.html +13 -0
- package/dist/client.cjs +76 -0
- package/dist/client.d.cts +14 -0
- package/dist/client.d.mts +14 -0
- package/dist/client.mjs +75 -0
- package/dist/index.cjs +451 -0
- package/dist/index.d.cts +64 -0
- package/dist/index.d.mts +64 -0
- package/dist/index.mjs +423 -0
- package/dist/protocol-BhfjLrSe.d.cts +76 -0
- package/dist/protocol-BhfjLrSe.d.mts +76 -0
- package/dist/protocol-Cl3y675u.cjs +299 -0
- package/dist/protocol-nkWp0_XO.mjs +216 -0
- package/dist/protocol.cjs +16 -0
- package/dist/protocol.d.cts +2 -0
- package/dist/protocol.d.mts +2 -0
- package/dist/protocol.mjs +2 -0
- package/dist/runtime.cjs +397 -0
- package/dist/runtime.d.cts +68 -0
- package/dist/runtime.d.mts +68 -0
- package/dist/runtime.mjs +394 -0
- package/package.json +75 -7
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
//#region src/codec.ts
|
|
2
|
+
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
3
|
+
function failure() {
|
|
4
|
+
throw new SqliteDevtoolsError("SQLITE_DEVTOOLS_INVALID_PAYLOAD", "Invalid or oversized SQLite DevTools payload.");
|
|
5
|
+
}
|
|
6
|
+
function budget(maxBytes) {
|
|
7
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1 || maxBytes > 16777216) failure();
|
|
8
|
+
let nodes = 0;
|
|
9
|
+
let bytes = 0;
|
|
10
|
+
return (depth, size = 1) => {
|
|
11
|
+
nodes += 1;
|
|
12
|
+
bytes += size;
|
|
13
|
+
if (depth > 32 || nodes > 1e5 || bytes > maxBytes) failure();
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function encodeBytes(bytes) {
|
|
17
|
+
const blocks = [];
|
|
18
|
+
for (let offset = 0; offset < bytes.length; offset += 3) {
|
|
19
|
+
const a = bytes[offset] ?? 0;
|
|
20
|
+
const b = bytes[offset + 1] ?? 0;
|
|
21
|
+
const c = bytes[offset + 2] ?? 0;
|
|
22
|
+
blocks.push(`${alphabet[a >> 2]}${alphabet[(a & 3) << 4 | b >> 4]}${offset + 1 < bytes.length ? alphabet[(b & 15) << 2 | c >> 6] : "="}${offset + 2 < bytes.length ? alphabet[c & 63] : "="}`);
|
|
23
|
+
}
|
|
24
|
+
return blocks.join("");
|
|
25
|
+
}
|
|
26
|
+
function decodeBytes(value) {
|
|
27
|
+
if (!/^(?:[A-Z\d+/]{4})*(?:[A-Z\d+/]{2}==|[A-Z\d+/]{3}=)?$/i.test(value)) failure();
|
|
28
|
+
const length = value.length / 4 * 3 - (value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0);
|
|
29
|
+
const bytes = new Uint8Array(length);
|
|
30
|
+
let cursor = 0;
|
|
31
|
+
for (let offset = 0; offset < value.length; offset += 4) {
|
|
32
|
+
const bits = alphabet.indexOf(value[offset]) << 18 | alphabet.indexOf(value[offset + 1]) << 12 | Math.max(0, alphabet.indexOf(value[offset + 2])) << 6 | Math.max(0, alphabet.indexOf(value[offset + 3]));
|
|
33
|
+
if (cursor < length) bytes[cursor++] = bits >> 16 & 255;
|
|
34
|
+
if (cursor < length) bytes[cursor++] = bits >> 8 & 255;
|
|
35
|
+
if (cursor < length) bytes[cursor++] = bits & 255;
|
|
36
|
+
}
|
|
37
|
+
if (encodeBytes(bytes) !== value) failure();
|
|
38
|
+
return bytes;
|
|
39
|
+
}
|
|
40
|
+
/** 使用显式标签保留整数和二进制值,普通对象不能伪装成协议标签。 */
|
|
41
|
+
function encodeSqliteDevtoolsValue(value, maxBytes = SQLITE_DEVTOOLS_MAX_MESSAGE_BYTES) {
|
|
42
|
+
const check = budget(maxBytes);
|
|
43
|
+
const seen = /* @__PURE__ */ new Set();
|
|
44
|
+
function visit(input, depth) {
|
|
45
|
+
check(depth);
|
|
46
|
+
if (input === void 0) return { type: "undefined" };
|
|
47
|
+
if (input === null || typeof input === "boolean") return input;
|
|
48
|
+
if (typeof input === "number") {
|
|
49
|
+
if (!Number.isFinite(input)) failure();
|
|
50
|
+
return input;
|
|
51
|
+
}
|
|
52
|
+
if (typeof input === "string") {
|
|
53
|
+
check(depth, input.length * 3);
|
|
54
|
+
return input;
|
|
55
|
+
}
|
|
56
|
+
if (typeof input === "bigint") {
|
|
57
|
+
const text = input.toString();
|
|
58
|
+
check(depth, text.length);
|
|
59
|
+
return {
|
|
60
|
+
type: "bigint",
|
|
61
|
+
value: text
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (input instanceof Uint8Array || input instanceof ArrayBuffer) {
|
|
65
|
+
const bytes = input instanceof Uint8Array ? input : new Uint8Array(input);
|
|
66
|
+
check(depth, Math.ceil(bytes.byteLength / 3) * 4);
|
|
67
|
+
return {
|
|
68
|
+
type: "bytes",
|
|
69
|
+
kind: input instanceof Uint8Array ? "uint8array" : "arraybuffer",
|
|
70
|
+
value: encodeBytes(bytes)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (typeof input !== "object" || seen.has(input)) failure();
|
|
74
|
+
seen.add(input);
|
|
75
|
+
try {
|
|
76
|
+
if (Array.isArray(input)) return {
|
|
77
|
+
type: "array",
|
|
78
|
+
value: input.map((item) => visit(item, depth + 1))
|
|
79
|
+
};
|
|
80
|
+
if (Object.getPrototypeOf(input) !== Object.prototype && Object.getPrototypeOf(input) !== null) failure();
|
|
81
|
+
return {
|
|
82
|
+
type: "object",
|
|
83
|
+
value: Object.entries(input).map(([key, entry]) => {
|
|
84
|
+
check(depth, key.length * 3);
|
|
85
|
+
return [key, visit(entry, depth + 1)];
|
|
86
|
+
})
|
|
87
|
+
};
|
|
88
|
+
} finally {
|
|
89
|
+
seen.delete(input);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const result = visit(value, 0);
|
|
93
|
+
if (JSON.stringify(result).length > maxBytes) failure();
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
function decodeSqliteDevtoolsValue(value, maxBytes = SQLITE_DEVTOOLS_MAX_MESSAGE_BYTES) {
|
|
97
|
+
const check = budget(maxBytes);
|
|
98
|
+
function visit(input, depth) {
|
|
99
|
+
check(depth);
|
|
100
|
+
if (input === null || typeof input === "boolean") return input;
|
|
101
|
+
if (typeof input === "number") {
|
|
102
|
+
if (!Number.isFinite(input)) failure();
|
|
103
|
+
return input;
|
|
104
|
+
}
|
|
105
|
+
if (typeof input === "string") {
|
|
106
|
+
check(depth, input.length * 3);
|
|
107
|
+
return input;
|
|
108
|
+
}
|
|
109
|
+
if (!isRecord(input)) failure();
|
|
110
|
+
if (input.type === "undefined") return;
|
|
111
|
+
if (input.type === "bigint" && typeof input.value === "string" && /^-?(?:0|[1-9]\d*)$/.test(input.value)) {
|
|
112
|
+
check(depth, input.value.length);
|
|
113
|
+
return BigInt(input.value);
|
|
114
|
+
}
|
|
115
|
+
if (input.type === "bytes" && typeof input.value === "string" && (input.kind === "uint8array" || input.kind === "arraybuffer")) {
|
|
116
|
+
check(depth, input.value.length);
|
|
117
|
+
const bytes = decodeBytes(input.value);
|
|
118
|
+
return input.kind === "arraybuffer" ? bytes.buffer : bytes;
|
|
119
|
+
}
|
|
120
|
+
if (input.type === "array" && Array.isArray(input.value)) return input.value.map((item) => visit(item, depth + 1));
|
|
121
|
+
if (input.type === "object" && Array.isArray(input.value)) {
|
|
122
|
+
const keys = /* @__PURE__ */ new Set();
|
|
123
|
+
return Object.fromEntries(input.value.map((entry) => {
|
|
124
|
+
if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== "string" || keys.has(entry[0])) failure();
|
|
125
|
+
check(depth, entry[0].length * 3);
|
|
126
|
+
keys.add(entry[0]);
|
|
127
|
+
return [entry[0], visit(entry[1], depth + 1)];
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
return failure();
|
|
131
|
+
}
|
|
132
|
+
return visit(value, 0);
|
|
133
|
+
}
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/protocol.ts
|
|
136
|
+
const SQLITE_DEVTOOLS_SCOPE = "weapp-sqlite";
|
|
137
|
+
const SQLITE_DEVTOOLS_PROTOCOL = 1;
|
|
138
|
+
const SQLITE_DEVTOOLS_MAX_MESSAGE_BYTES = 16777216;
|
|
139
|
+
const SQLITE_DEVTOOLS_READ_METHODS = [
|
|
140
|
+
"listTables",
|
|
141
|
+
"describeTable",
|
|
142
|
+
"getTableCapabilities",
|
|
143
|
+
"listIndexes",
|
|
144
|
+
"readTable",
|
|
145
|
+
"query",
|
|
146
|
+
"analyzeQuery",
|
|
147
|
+
"getMigrationStatus",
|
|
148
|
+
"getMigrationDiagnostics",
|
|
149
|
+
"getForeignKeyDiagnostics",
|
|
150
|
+
"exportDatabase",
|
|
151
|
+
"exportTable",
|
|
152
|
+
"previewTableImport",
|
|
153
|
+
"getUndoState"
|
|
154
|
+
];
|
|
155
|
+
const SQLITE_DEVTOOLS_WRITE_METHODS = [
|
|
156
|
+
"execute",
|
|
157
|
+
"insertRow",
|
|
158
|
+
"updateRow",
|
|
159
|
+
"deleteRows",
|
|
160
|
+
"createTable",
|
|
161
|
+
"renameTable",
|
|
162
|
+
"dropTable",
|
|
163
|
+
"truncateTable",
|
|
164
|
+
"addColumn",
|
|
165
|
+
"renameColumn",
|
|
166
|
+
"dropColumn",
|
|
167
|
+
"createIndex",
|
|
168
|
+
"dropIndex",
|
|
169
|
+
"importDatabase",
|
|
170
|
+
"importTable",
|
|
171
|
+
"undoLastDestructiveChange",
|
|
172
|
+
"resetDatabase"
|
|
173
|
+
];
|
|
174
|
+
var SqliteDevtoolsError = class extends Error {
|
|
175
|
+
code;
|
|
176
|
+
constructor(code, message) {
|
|
177
|
+
super(message);
|
|
178
|
+
this.code = code;
|
|
179
|
+
this.name = "SqliteDevtoolsError";
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
function isSqliteDevtoolsMethod(value) {
|
|
183
|
+
return typeof value === "string" && [
|
|
184
|
+
...SQLITE_DEVTOOLS_READ_METHODS,
|
|
185
|
+
...SQLITE_DEVTOOLS_WRITE_METHODS,
|
|
186
|
+
"close"
|
|
187
|
+
].includes(value);
|
|
188
|
+
}
|
|
189
|
+
function isSqliteDevtoolsWriteMethod(value) {
|
|
190
|
+
return SQLITE_DEVTOOLS_WRITE_METHODS.includes(value);
|
|
191
|
+
}
|
|
192
|
+
function isIdentifier(value) {
|
|
193
|
+
if (typeof value !== "string" || value.length === 0 || value.length > 256) return false;
|
|
194
|
+
return [...value].every((character) => character.charCodeAt(0) >= 32);
|
|
195
|
+
}
|
|
196
|
+
function serializeDevtoolsError(error) {
|
|
197
|
+
if (error instanceof Error) {
|
|
198
|
+
const candidate = "code" in error && typeof error.code === "string" ? error.code : "";
|
|
199
|
+
return {
|
|
200
|
+
code: isIdentifier(candidate) ? candidate : "SQLITE_DEVTOOLS_RUNTIME_ERROR",
|
|
201
|
+
message: (typeof error.message === "string" ? error.message : String(error.message ?? "")).slice(0, 4096)
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
code: "SQLITE_DEVTOOLS_RUNTIME_ERROR",
|
|
206
|
+
message: "SQLite runtime operation failed."
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function isRecord(value) {
|
|
210
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
211
|
+
}
|
|
212
|
+
function validDatabaseNames(value) {
|
|
213
|
+
return Array.isArray(value) && value.length <= 100 && value.every(isIdentifier) && new Set(value).size === value.length;
|
|
214
|
+
}
|
|
215
|
+
//#endregion
|
|
216
|
+
Object.defineProperty(exports, "SQLITE_DEVTOOLS_MAX_MESSAGE_BYTES", {
|
|
217
|
+
enumerable: true,
|
|
218
|
+
get: function() {
|
|
219
|
+
return SQLITE_DEVTOOLS_MAX_MESSAGE_BYTES;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
Object.defineProperty(exports, "SQLITE_DEVTOOLS_PROTOCOL", {
|
|
223
|
+
enumerable: true,
|
|
224
|
+
get: function() {
|
|
225
|
+
return SQLITE_DEVTOOLS_PROTOCOL;
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
Object.defineProperty(exports, "SQLITE_DEVTOOLS_READ_METHODS", {
|
|
229
|
+
enumerable: true,
|
|
230
|
+
get: function() {
|
|
231
|
+
return SQLITE_DEVTOOLS_READ_METHODS;
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
Object.defineProperty(exports, "SQLITE_DEVTOOLS_SCOPE", {
|
|
235
|
+
enumerable: true,
|
|
236
|
+
get: function() {
|
|
237
|
+
return SQLITE_DEVTOOLS_SCOPE;
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
Object.defineProperty(exports, "SQLITE_DEVTOOLS_WRITE_METHODS", {
|
|
241
|
+
enumerable: true,
|
|
242
|
+
get: function() {
|
|
243
|
+
return SQLITE_DEVTOOLS_WRITE_METHODS;
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
Object.defineProperty(exports, "SqliteDevtoolsError", {
|
|
247
|
+
enumerable: true,
|
|
248
|
+
get: function() {
|
|
249
|
+
return SqliteDevtoolsError;
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
Object.defineProperty(exports, "decodeSqliteDevtoolsValue", {
|
|
253
|
+
enumerable: true,
|
|
254
|
+
get: function() {
|
|
255
|
+
return decodeSqliteDevtoolsValue;
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
Object.defineProperty(exports, "encodeSqliteDevtoolsValue", {
|
|
259
|
+
enumerable: true,
|
|
260
|
+
get: function() {
|
|
261
|
+
return encodeSqliteDevtoolsValue;
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
Object.defineProperty(exports, "isIdentifier", {
|
|
265
|
+
enumerable: true,
|
|
266
|
+
get: function() {
|
|
267
|
+
return isIdentifier;
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
Object.defineProperty(exports, "isRecord", {
|
|
271
|
+
enumerable: true,
|
|
272
|
+
get: function() {
|
|
273
|
+
return isRecord;
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
Object.defineProperty(exports, "isSqliteDevtoolsMethod", {
|
|
277
|
+
enumerable: true,
|
|
278
|
+
get: function() {
|
|
279
|
+
return isSqliteDevtoolsMethod;
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
Object.defineProperty(exports, "isSqliteDevtoolsWriteMethod", {
|
|
283
|
+
enumerable: true,
|
|
284
|
+
get: function() {
|
|
285
|
+
return isSqliteDevtoolsWriteMethod;
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
Object.defineProperty(exports, "serializeDevtoolsError", {
|
|
289
|
+
enumerable: true,
|
|
290
|
+
get: function() {
|
|
291
|
+
return serializeDevtoolsError;
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
Object.defineProperty(exports, "validDatabaseNames", {
|
|
295
|
+
enumerable: true,
|
|
296
|
+
get: function() {
|
|
297
|
+
return validDatabaseNames;
|
|
298
|
+
}
|
|
299
|
+
});
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
//#region src/codec.ts
|
|
2
|
+
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
3
|
+
function failure() {
|
|
4
|
+
throw new SqliteDevtoolsError("SQLITE_DEVTOOLS_INVALID_PAYLOAD", "Invalid or oversized SQLite DevTools payload.");
|
|
5
|
+
}
|
|
6
|
+
function budget(maxBytes) {
|
|
7
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1 || maxBytes > 16777216) failure();
|
|
8
|
+
let nodes = 0;
|
|
9
|
+
let bytes = 0;
|
|
10
|
+
return (depth, size = 1) => {
|
|
11
|
+
nodes += 1;
|
|
12
|
+
bytes += size;
|
|
13
|
+
if (depth > 32 || nodes > 1e5 || bytes > maxBytes) failure();
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function encodeBytes(bytes) {
|
|
17
|
+
const blocks = [];
|
|
18
|
+
for (let offset = 0; offset < bytes.length; offset += 3) {
|
|
19
|
+
const a = bytes[offset] ?? 0;
|
|
20
|
+
const b = bytes[offset + 1] ?? 0;
|
|
21
|
+
const c = bytes[offset + 2] ?? 0;
|
|
22
|
+
blocks.push(`${alphabet[a >> 2]}${alphabet[(a & 3) << 4 | b >> 4]}${offset + 1 < bytes.length ? alphabet[(b & 15) << 2 | c >> 6] : "="}${offset + 2 < bytes.length ? alphabet[c & 63] : "="}`);
|
|
23
|
+
}
|
|
24
|
+
return blocks.join("");
|
|
25
|
+
}
|
|
26
|
+
function decodeBytes(value) {
|
|
27
|
+
if (!/^(?:[A-Z\d+/]{4})*(?:[A-Z\d+/]{2}==|[A-Z\d+/]{3}=)?$/i.test(value)) failure();
|
|
28
|
+
const length = value.length / 4 * 3 - (value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0);
|
|
29
|
+
const bytes = new Uint8Array(length);
|
|
30
|
+
let cursor = 0;
|
|
31
|
+
for (let offset = 0; offset < value.length; offset += 4) {
|
|
32
|
+
const bits = alphabet.indexOf(value[offset]) << 18 | alphabet.indexOf(value[offset + 1]) << 12 | Math.max(0, alphabet.indexOf(value[offset + 2])) << 6 | Math.max(0, alphabet.indexOf(value[offset + 3]));
|
|
33
|
+
if (cursor < length) bytes[cursor++] = bits >> 16 & 255;
|
|
34
|
+
if (cursor < length) bytes[cursor++] = bits >> 8 & 255;
|
|
35
|
+
if (cursor < length) bytes[cursor++] = bits & 255;
|
|
36
|
+
}
|
|
37
|
+
if (encodeBytes(bytes) !== value) failure();
|
|
38
|
+
return bytes;
|
|
39
|
+
}
|
|
40
|
+
/** 使用显式标签保留整数和二进制值,普通对象不能伪装成协议标签。 */
|
|
41
|
+
function encodeSqliteDevtoolsValue(value, maxBytes = SQLITE_DEVTOOLS_MAX_MESSAGE_BYTES) {
|
|
42
|
+
const check = budget(maxBytes);
|
|
43
|
+
const seen = /* @__PURE__ */ new Set();
|
|
44
|
+
function visit(input, depth) {
|
|
45
|
+
check(depth);
|
|
46
|
+
if (input === void 0) return { type: "undefined" };
|
|
47
|
+
if (input === null || typeof input === "boolean") return input;
|
|
48
|
+
if (typeof input === "number") {
|
|
49
|
+
if (!Number.isFinite(input)) failure();
|
|
50
|
+
return input;
|
|
51
|
+
}
|
|
52
|
+
if (typeof input === "string") {
|
|
53
|
+
check(depth, input.length * 3);
|
|
54
|
+
return input;
|
|
55
|
+
}
|
|
56
|
+
if (typeof input === "bigint") {
|
|
57
|
+
const text = input.toString();
|
|
58
|
+
check(depth, text.length);
|
|
59
|
+
return {
|
|
60
|
+
type: "bigint",
|
|
61
|
+
value: text
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (input instanceof Uint8Array || input instanceof ArrayBuffer) {
|
|
65
|
+
const bytes = input instanceof Uint8Array ? input : new Uint8Array(input);
|
|
66
|
+
check(depth, Math.ceil(bytes.byteLength / 3) * 4);
|
|
67
|
+
return {
|
|
68
|
+
type: "bytes",
|
|
69
|
+
kind: input instanceof Uint8Array ? "uint8array" : "arraybuffer",
|
|
70
|
+
value: encodeBytes(bytes)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (typeof input !== "object" || seen.has(input)) failure();
|
|
74
|
+
seen.add(input);
|
|
75
|
+
try {
|
|
76
|
+
if (Array.isArray(input)) return {
|
|
77
|
+
type: "array",
|
|
78
|
+
value: input.map((item) => visit(item, depth + 1))
|
|
79
|
+
};
|
|
80
|
+
if (Object.getPrototypeOf(input) !== Object.prototype && Object.getPrototypeOf(input) !== null) failure();
|
|
81
|
+
return {
|
|
82
|
+
type: "object",
|
|
83
|
+
value: Object.entries(input).map(([key, entry]) => {
|
|
84
|
+
check(depth, key.length * 3);
|
|
85
|
+
return [key, visit(entry, depth + 1)];
|
|
86
|
+
})
|
|
87
|
+
};
|
|
88
|
+
} finally {
|
|
89
|
+
seen.delete(input);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const result = visit(value, 0);
|
|
93
|
+
if (JSON.stringify(result).length > maxBytes) failure();
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
function decodeSqliteDevtoolsValue(value, maxBytes = SQLITE_DEVTOOLS_MAX_MESSAGE_BYTES) {
|
|
97
|
+
const check = budget(maxBytes);
|
|
98
|
+
function visit(input, depth) {
|
|
99
|
+
check(depth);
|
|
100
|
+
if (input === null || typeof input === "boolean") return input;
|
|
101
|
+
if (typeof input === "number") {
|
|
102
|
+
if (!Number.isFinite(input)) failure();
|
|
103
|
+
return input;
|
|
104
|
+
}
|
|
105
|
+
if (typeof input === "string") {
|
|
106
|
+
check(depth, input.length * 3);
|
|
107
|
+
return input;
|
|
108
|
+
}
|
|
109
|
+
if (!isRecord(input)) failure();
|
|
110
|
+
if (input.type === "undefined") return;
|
|
111
|
+
if (input.type === "bigint" && typeof input.value === "string" && /^-?(?:0|[1-9]\d*)$/.test(input.value)) {
|
|
112
|
+
check(depth, input.value.length);
|
|
113
|
+
return BigInt(input.value);
|
|
114
|
+
}
|
|
115
|
+
if (input.type === "bytes" && typeof input.value === "string" && (input.kind === "uint8array" || input.kind === "arraybuffer")) {
|
|
116
|
+
check(depth, input.value.length);
|
|
117
|
+
const bytes = decodeBytes(input.value);
|
|
118
|
+
return input.kind === "arraybuffer" ? bytes.buffer : bytes;
|
|
119
|
+
}
|
|
120
|
+
if (input.type === "array" && Array.isArray(input.value)) return input.value.map((item) => visit(item, depth + 1));
|
|
121
|
+
if (input.type === "object" && Array.isArray(input.value)) {
|
|
122
|
+
const keys = /* @__PURE__ */ new Set();
|
|
123
|
+
return Object.fromEntries(input.value.map((entry) => {
|
|
124
|
+
if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== "string" || keys.has(entry[0])) failure();
|
|
125
|
+
check(depth, entry[0].length * 3);
|
|
126
|
+
keys.add(entry[0]);
|
|
127
|
+
return [entry[0], visit(entry[1], depth + 1)];
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
return failure();
|
|
131
|
+
}
|
|
132
|
+
return visit(value, 0);
|
|
133
|
+
}
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/protocol.ts
|
|
136
|
+
const SQLITE_DEVTOOLS_SCOPE = "weapp-sqlite";
|
|
137
|
+
const SQLITE_DEVTOOLS_PROTOCOL = 1;
|
|
138
|
+
const SQLITE_DEVTOOLS_MAX_MESSAGE_BYTES = 16777216;
|
|
139
|
+
const SQLITE_DEVTOOLS_READ_METHODS = [
|
|
140
|
+
"listTables",
|
|
141
|
+
"describeTable",
|
|
142
|
+
"getTableCapabilities",
|
|
143
|
+
"listIndexes",
|
|
144
|
+
"readTable",
|
|
145
|
+
"query",
|
|
146
|
+
"analyzeQuery",
|
|
147
|
+
"getMigrationStatus",
|
|
148
|
+
"getMigrationDiagnostics",
|
|
149
|
+
"getForeignKeyDiagnostics",
|
|
150
|
+
"exportDatabase",
|
|
151
|
+
"exportTable",
|
|
152
|
+
"previewTableImport",
|
|
153
|
+
"getUndoState"
|
|
154
|
+
];
|
|
155
|
+
const SQLITE_DEVTOOLS_WRITE_METHODS = [
|
|
156
|
+
"execute",
|
|
157
|
+
"insertRow",
|
|
158
|
+
"updateRow",
|
|
159
|
+
"deleteRows",
|
|
160
|
+
"createTable",
|
|
161
|
+
"renameTable",
|
|
162
|
+
"dropTable",
|
|
163
|
+
"truncateTable",
|
|
164
|
+
"addColumn",
|
|
165
|
+
"renameColumn",
|
|
166
|
+
"dropColumn",
|
|
167
|
+
"createIndex",
|
|
168
|
+
"dropIndex",
|
|
169
|
+
"importDatabase",
|
|
170
|
+
"importTable",
|
|
171
|
+
"undoLastDestructiveChange",
|
|
172
|
+
"resetDatabase"
|
|
173
|
+
];
|
|
174
|
+
var SqliteDevtoolsError = class extends Error {
|
|
175
|
+
code;
|
|
176
|
+
constructor(code, message) {
|
|
177
|
+
super(message);
|
|
178
|
+
this.code = code;
|
|
179
|
+
this.name = "SqliteDevtoolsError";
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
function isSqliteDevtoolsMethod(value) {
|
|
183
|
+
return typeof value === "string" && [
|
|
184
|
+
...SQLITE_DEVTOOLS_READ_METHODS,
|
|
185
|
+
...SQLITE_DEVTOOLS_WRITE_METHODS,
|
|
186
|
+
"close"
|
|
187
|
+
].includes(value);
|
|
188
|
+
}
|
|
189
|
+
function isSqliteDevtoolsWriteMethod(value) {
|
|
190
|
+
return SQLITE_DEVTOOLS_WRITE_METHODS.includes(value);
|
|
191
|
+
}
|
|
192
|
+
function isIdentifier(value) {
|
|
193
|
+
if (typeof value !== "string" || value.length === 0 || value.length > 256) return false;
|
|
194
|
+
return [...value].every((character) => character.charCodeAt(0) >= 32);
|
|
195
|
+
}
|
|
196
|
+
function serializeDevtoolsError(error) {
|
|
197
|
+
if (error instanceof Error) {
|
|
198
|
+
const candidate = "code" in error && typeof error.code === "string" ? error.code : "";
|
|
199
|
+
return {
|
|
200
|
+
code: isIdentifier(candidate) ? candidate : "SQLITE_DEVTOOLS_RUNTIME_ERROR",
|
|
201
|
+
message: (typeof error.message === "string" ? error.message : String(error.message ?? "")).slice(0, 4096)
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
code: "SQLITE_DEVTOOLS_RUNTIME_ERROR",
|
|
206
|
+
message: "SQLite runtime operation failed."
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function isRecord(value) {
|
|
210
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
211
|
+
}
|
|
212
|
+
function validDatabaseNames(value) {
|
|
213
|
+
return Array.isArray(value) && value.length <= 100 && value.every(isIdentifier) && new Set(value).size === value.length;
|
|
214
|
+
}
|
|
215
|
+
//#endregion
|
|
216
|
+
export { SQLITE_DEVTOOLS_WRITE_METHODS as a, isRecord as c, serializeDevtoolsError as d, validDatabaseNames as f, SQLITE_DEVTOOLS_SCOPE as i, isSqliteDevtoolsMethod as l, encodeSqliteDevtoolsValue as m, SQLITE_DEVTOOLS_PROTOCOL as n, SqliteDevtoolsError as o, decodeSqliteDevtoolsValue as p, SQLITE_DEVTOOLS_READ_METHODS as r, isIdentifier as s, SQLITE_DEVTOOLS_MAX_MESSAGE_BYTES as t, isSqliteDevtoolsWriteMethod as u };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_protocol = require("./protocol-Cl3y675u.cjs");
|
|
3
|
+
exports.SQLITE_DEVTOOLS_MAX_MESSAGE_BYTES = require_protocol.SQLITE_DEVTOOLS_MAX_MESSAGE_BYTES;
|
|
4
|
+
exports.SQLITE_DEVTOOLS_PROTOCOL = require_protocol.SQLITE_DEVTOOLS_PROTOCOL;
|
|
5
|
+
exports.SQLITE_DEVTOOLS_READ_METHODS = require_protocol.SQLITE_DEVTOOLS_READ_METHODS;
|
|
6
|
+
exports.SQLITE_DEVTOOLS_SCOPE = require_protocol.SQLITE_DEVTOOLS_SCOPE;
|
|
7
|
+
exports.SQLITE_DEVTOOLS_WRITE_METHODS = require_protocol.SQLITE_DEVTOOLS_WRITE_METHODS;
|
|
8
|
+
exports.SqliteDevtoolsError = require_protocol.SqliteDevtoolsError;
|
|
9
|
+
exports.decodeSqliteDevtoolsValue = require_protocol.decodeSqliteDevtoolsValue;
|
|
10
|
+
exports.encodeSqliteDevtoolsValue = require_protocol.encodeSqliteDevtoolsValue;
|
|
11
|
+
exports.isIdentifier = require_protocol.isIdentifier;
|
|
12
|
+
exports.isRecord = require_protocol.isRecord;
|
|
13
|
+
exports.isSqliteDevtoolsMethod = require_protocol.isSqliteDevtoolsMethod;
|
|
14
|
+
exports.isSqliteDevtoolsWriteMethod = require_protocol.isSqliteDevtoolsWriteMethod;
|
|
15
|
+
exports.serializeDevtoolsError = require_protocol.serializeDevtoolsError;
|
|
16
|
+
exports.validDatabaseNames = require_protocol.validDatabaseNames;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { S as encodeSqliteDevtoolsValue, _ as isSqliteDevtoolsMethod, a as SQLITE_DEVTOOLS_WRITE_METHODS, b as validDatabaseNames, c as SqliteDevtoolsInvocation, d as SqliteDevtoolsResult, f as SqliteDevtoolsRuntime, g as isRecord, h as isIdentifier, i as SQLITE_DEVTOOLS_SCOPE, l as SqliteDevtoolsMethod, m as SqliteDevtoolsWireValue, n as SQLITE_DEVTOOLS_PROTOCOL, o as SqliteDevtoolsError, p as SqliteDevtoolsRuntimeDescriptor, r as SQLITE_DEVTOOLS_READ_METHODS, s as SqliteDevtoolsErrorData, t as SQLITE_DEVTOOLS_MAX_MESSAGE_BYTES, u as SqliteDevtoolsReleaseSession, v as isSqliteDevtoolsWriteMethod, x as decodeSqliteDevtoolsValue, y as serializeDevtoolsError } from "./protocol-BhfjLrSe.cjs";
|
|
2
|
+
export { SQLITE_DEVTOOLS_MAX_MESSAGE_BYTES, SQLITE_DEVTOOLS_PROTOCOL, SQLITE_DEVTOOLS_READ_METHODS, SQLITE_DEVTOOLS_SCOPE, SQLITE_DEVTOOLS_WRITE_METHODS, SqliteDevtoolsError, SqliteDevtoolsErrorData, SqliteDevtoolsInvocation, SqliteDevtoolsMethod, SqliteDevtoolsReleaseSession, SqliteDevtoolsResult, SqliteDevtoolsRuntime, SqliteDevtoolsRuntimeDescriptor, SqliteDevtoolsWireValue, decodeSqliteDevtoolsValue, encodeSqliteDevtoolsValue, isIdentifier, isRecord, isSqliteDevtoolsMethod, isSqliteDevtoolsWriteMethod, serializeDevtoolsError, validDatabaseNames };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { S as encodeSqliteDevtoolsValue, _ as isSqliteDevtoolsMethod, a as SQLITE_DEVTOOLS_WRITE_METHODS, b as validDatabaseNames, c as SqliteDevtoolsInvocation, d as SqliteDevtoolsResult, f as SqliteDevtoolsRuntime, g as isRecord, h as isIdentifier, i as SQLITE_DEVTOOLS_SCOPE, l as SqliteDevtoolsMethod, m as SqliteDevtoolsWireValue, n as SQLITE_DEVTOOLS_PROTOCOL, o as SqliteDevtoolsError, p as SqliteDevtoolsRuntimeDescriptor, r as SQLITE_DEVTOOLS_READ_METHODS, s as SqliteDevtoolsErrorData, t as SQLITE_DEVTOOLS_MAX_MESSAGE_BYTES, u as SqliteDevtoolsReleaseSession, v as isSqliteDevtoolsWriteMethod, x as decodeSqliteDevtoolsValue, y as serializeDevtoolsError } from "./protocol-BhfjLrSe.mjs";
|
|
2
|
+
export { SQLITE_DEVTOOLS_MAX_MESSAGE_BYTES, SQLITE_DEVTOOLS_PROTOCOL, SQLITE_DEVTOOLS_READ_METHODS, SQLITE_DEVTOOLS_SCOPE, SQLITE_DEVTOOLS_WRITE_METHODS, SqliteDevtoolsError, SqliteDevtoolsErrorData, SqliteDevtoolsInvocation, SqliteDevtoolsMethod, SqliteDevtoolsReleaseSession, SqliteDevtoolsResult, SqliteDevtoolsRuntime, SqliteDevtoolsRuntimeDescriptor, SqliteDevtoolsWireValue, decodeSqliteDevtoolsValue, encodeSqliteDevtoolsValue, isIdentifier, isRecord, isSqliteDevtoolsMethod, isSqliteDevtoolsWriteMethod, serializeDevtoolsError, validDatabaseNames };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as SQLITE_DEVTOOLS_WRITE_METHODS, c as isRecord, d as serializeDevtoolsError, f as validDatabaseNames, i as SQLITE_DEVTOOLS_SCOPE, l as isSqliteDevtoolsMethod, m as encodeSqliteDevtoolsValue, n as SQLITE_DEVTOOLS_PROTOCOL, o as SqliteDevtoolsError, p as decodeSqliteDevtoolsValue, r as SQLITE_DEVTOOLS_READ_METHODS, s as isIdentifier, t as SQLITE_DEVTOOLS_MAX_MESSAGE_BYTES, u as isSqliteDevtoolsWriteMethod } from "./protocol-nkWp0_XO.mjs";
|
|
2
|
+
export { SQLITE_DEVTOOLS_MAX_MESSAGE_BYTES, SQLITE_DEVTOOLS_PROTOCOL, SQLITE_DEVTOOLS_READ_METHODS, SQLITE_DEVTOOLS_SCOPE, SQLITE_DEVTOOLS_WRITE_METHODS, SqliteDevtoolsError, decodeSqliteDevtoolsValue, encodeSqliteDevtoolsValue, isIdentifier, isRecord, isSqliteDevtoolsMethod, isSqliteDevtoolsWriteMethod, serializeDevtoolsError, validDatabaseNames };
|