@concavejs/docstore-better-sqlite3 0.0.1-alpha.5 → 0.0.1-alpha.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/better-sqlite3-adapter.d.ts +2 -1
- package/dist/index.js +294 -577
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -15,211 +15,173 @@ var __export = (target, all) => {
|
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
17
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
const matches = hex.match(/.{1,2}/g);
|
|
23
|
-
if (!matches) {
|
|
24
|
-
throw new Error(`Invalid hex string: ${hex}`);
|
|
25
|
-
}
|
|
26
|
-
return new Uint8Array(matches.map((byte) => parseInt(byte, 16))).buffer;
|
|
27
|
-
}
|
|
28
|
-
function arrayBufferToHex(buffer) {
|
|
29
|
-
return Array.from(new Uint8Array(buffer)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
30
|
-
}
|
|
31
|
-
function stringToHex(s) {
|
|
32
|
-
const buffer = new TextEncoder().encode(s);
|
|
33
|
-
return arrayBufferToHex(buffer.buffer);
|
|
34
|
-
}
|
|
35
|
-
function hexToString(hex) {
|
|
36
|
-
const buffer = hexToArrayBuffer(hex);
|
|
37
|
-
return new TextDecoder().decode(buffer);
|
|
38
|
-
}
|
|
39
|
-
function serializeDeveloperId(tableHex, internalIdHex) {
|
|
40
|
-
return `${tableHex}${DOC_ID_SEPARATOR}${internalIdHex}`;
|
|
41
|
-
}
|
|
42
|
-
function deserializeDeveloperId(developerId) {
|
|
43
|
-
if (!developerId) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
for (const separator of [DOC_ID_SEPARATOR, LEGACY_DOC_ID_SEPARATOR]) {
|
|
47
|
-
const parts = developerId.split(separator);
|
|
48
|
-
if (parts.length === 2 && parts[0] && parts[1]) {
|
|
49
|
-
return { table: parts[0], internalId: parts[1] };
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
var DOC_ID_SEPARATOR = ":";
|
|
55
|
-
var LEGACY_DOC_ID_SEPARATOR = ";";
|
|
56
|
-
function getLens2(b64) {
|
|
57
|
-
var len3 = b64.length;
|
|
58
|
-
if (len3 % 4 > 0) {
|
|
18
|
+
function getLens(b64) {
|
|
19
|
+
var len2 = b64.length;
|
|
20
|
+
if (len2 % 4 > 0) {
|
|
59
21
|
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
60
22
|
}
|
|
61
23
|
var validLen = b64.indexOf("=");
|
|
62
24
|
if (validLen === -1)
|
|
63
|
-
validLen =
|
|
64
|
-
var placeHoldersLen = validLen ===
|
|
25
|
+
validLen = len2;
|
|
26
|
+
var placeHoldersLen = validLen === len2 ? 0 : 4 - validLen % 4;
|
|
65
27
|
return [validLen, placeHoldersLen];
|
|
66
28
|
}
|
|
67
|
-
function
|
|
29
|
+
function _byteLength(_b64, validLen, placeHoldersLen) {
|
|
68
30
|
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
69
31
|
}
|
|
70
|
-
function
|
|
32
|
+
function toByteArray(b64) {
|
|
71
33
|
var tmp;
|
|
72
|
-
var lens =
|
|
34
|
+
var lens = getLens(b64);
|
|
73
35
|
var validLen = lens[0];
|
|
74
36
|
var placeHoldersLen = lens[1];
|
|
75
|
-
var arr = new
|
|
37
|
+
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
|
|
76
38
|
var curByte = 0;
|
|
77
|
-
var
|
|
78
|
-
var
|
|
79
|
-
for (
|
|
80
|
-
tmp =
|
|
39
|
+
var len2 = placeHoldersLen > 0 ? validLen - 4 : validLen;
|
|
40
|
+
var i2;
|
|
41
|
+
for (i2 = 0;i2 < len2; i2 += 4) {
|
|
42
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 18 | revLookup[b64.charCodeAt(i2 + 1)] << 12 | revLookup[b64.charCodeAt(i2 + 2)] << 6 | revLookup[b64.charCodeAt(i2 + 3)];
|
|
81
43
|
arr[curByte++] = tmp >> 16 & 255;
|
|
82
44
|
arr[curByte++] = tmp >> 8 & 255;
|
|
83
45
|
arr[curByte++] = tmp & 255;
|
|
84
46
|
}
|
|
85
47
|
if (placeHoldersLen === 2) {
|
|
86
|
-
tmp =
|
|
48
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 2 | revLookup[b64.charCodeAt(i2 + 1)] >> 4;
|
|
87
49
|
arr[curByte++] = tmp & 255;
|
|
88
50
|
}
|
|
89
51
|
if (placeHoldersLen === 1) {
|
|
90
|
-
tmp =
|
|
52
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 10 | revLookup[b64.charCodeAt(i2 + 1)] << 4 | revLookup[b64.charCodeAt(i2 + 2)] >> 2;
|
|
91
53
|
arr[curByte++] = tmp >> 8 & 255;
|
|
92
54
|
arr[curByte++] = tmp & 255;
|
|
93
55
|
}
|
|
94
56
|
return arr;
|
|
95
57
|
}
|
|
96
|
-
function
|
|
97
|
-
return
|
|
58
|
+
function tripletToBase64(num) {
|
|
59
|
+
return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
|
|
98
60
|
}
|
|
99
|
-
function
|
|
61
|
+
function encodeChunk(uint8, start, end) {
|
|
100
62
|
var tmp;
|
|
101
63
|
var output = [];
|
|
102
|
-
for (var
|
|
103
|
-
tmp = (uint8[
|
|
104
|
-
output.push(
|
|
64
|
+
for (var i2 = start;i2 < end; i2 += 3) {
|
|
65
|
+
tmp = (uint8[i2] << 16 & 16711680) + (uint8[i2 + 1] << 8 & 65280) + (uint8[i2 + 2] & 255);
|
|
66
|
+
output.push(tripletToBase64(tmp));
|
|
105
67
|
}
|
|
106
68
|
return output.join("");
|
|
107
69
|
}
|
|
108
|
-
function
|
|
70
|
+
function fromByteArray(uint8) {
|
|
109
71
|
var tmp;
|
|
110
|
-
var
|
|
111
|
-
var extraBytes =
|
|
72
|
+
var len2 = uint8.length;
|
|
73
|
+
var extraBytes = len2 % 3;
|
|
112
74
|
var parts = [];
|
|
113
75
|
var maxChunkLength = 16383;
|
|
114
|
-
for (var
|
|
115
|
-
parts.push(
|
|
76
|
+
for (var i2 = 0, len22 = len2 - extraBytes;i2 < len22; i2 += maxChunkLength) {
|
|
77
|
+
parts.push(encodeChunk(uint8, i2, i2 + maxChunkLength > len22 ? len22 : i2 + maxChunkLength));
|
|
116
78
|
}
|
|
117
79
|
if (extraBytes === 1) {
|
|
118
|
-
tmp = uint8[
|
|
119
|
-
parts.push(
|
|
80
|
+
tmp = uint8[len2 - 1];
|
|
81
|
+
parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "==");
|
|
120
82
|
} else if (extraBytes === 2) {
|
|
121
|
-
tmp = (uint8[
|
|
122
|
-
parts.push(
|
|
83
|
+
tmp = (uint8[len2 - 2] << 8) + uint8[len2 - 1];
|
|
84
|
+
parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "=");
|
|
123
85
|
}
|
|
124
86
|
return parts.join("");
|
|
125
87
|
}
|
|
126
|
-
var
|
|
127
|
-
var
|
|
128
|
-
var
|
|
129
|
-
var
|
|
130
|
-
var
|
|
131
|
-
var
|
|
88
|
+
var lookup;
|
|
89
|
+
var revLookup;
|
|
90
|
+
var Arr;
|
|
91
|
+
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
92
|
+
var i;
|
|
93
|
+
var len;
|
|
132
94
|
var init_base64 = __esm(() => {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
for (
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
95
|
+
lookup = [];
|
|
96
|
+
revLookup = [];
|
|
97
|
+
Arr = Uint8Array;
|
|
98
|
+
for (i = 0, len = code.length;i < len; ++i) {
|
|
99
|
+
lookup[i] = code[i];
|
|
100
|
+
revLookup[code.charCodeAt(i)] = i;
|
|
101
|
+
}
|
|
102
|
+
revLookup[45] = 62;
|
|
103
|
+
revLookup[95] = 63;
|
|
142
104
|
});
|
|
143
105
|
function parseArgs(args) {
|
|
144
106
|
if (args === undefined) {
|
|
145
107
|
return {};
|
|
146
108
|
}
|
|
147
|
-
if (!
|
|
109
|
+
if (!isSimpleObject(args)) {
|
|
148
110
|
throw new Error(`The arguments to a Convex function must be an object. Received: ${args}`);
|
|
149
111
|
}
|
|
150
112
|
return args;
|
|
151
113
|
}
|
|
152
|
-
function
|
|
114
|
+
function isSimpleObject(value) {
|
|
153
115
|
const isObject = typeof value === "object";
|
|
154
116
|
const prototype = Object.getPrototypeOf(value);
|
|
155
117
|
const isSimple = prototype === null || prototype === Object.prototype || prototype?.constructor?.name === "Object";
|
|
156
118
|
return isObject && isSimple;
|
|
157
119
|
}
|
|
158
|
-
function
|
|
120
|
+
function isSpecial(n) {
|
|
159
121
|
return Number.isNaN(n) || !Number.isFinite(n) || Object.is(n, -0);
|
|
160
122
|
}
|
|
161
|
-
function
|
|
162
|
-
if (value <
|
|
163
|
-
value -=
|
|
123
|
+
function slowBigIntToBase64(value) {
|
|
124
|
+
if (value < ZERO) {
|
|
125
|
+
value -= MIN_INT64 + MIN_INT64;
|
|
164
126
|
}
|
|
165
127
|
let hex = value.toString(16);
|
|
166
128
|
if (hex.length % 2 === 1)
|
|
167
129
|
hex = "0" + hex;
|
|
168
130
|
const bytes = new Uint8Array(new ArrayBuffer(8));
|
|
169
|
-
let
|
|
131
|
+
let i2 = 0;
|
|
170
132
|
for (const hexByte of hex.match(/.{2}/g).reverse()) {
|
|
171
|
-
bytes.set([parseInt(hexByte, 16)],
|
|
172
|
-
value >>=
|
|
133
|
+
bytes.set([parseInt(hexByte, 16)], i2++);
|
|
134
|
+
value >>= EIGHT;
|
|
173
135
|
}
|
|
174
|
-
return
|
|
136
|
+
return fromByteArray(bytes);
|
|
175
137
|
}
|
|
176
|
-
function
|
|
177
|
-
const integerBytes =
|
|
138
|
+
function slowBase64ToBigInt(encoded) {
|
|
139
|
+
const integerBytes = toByteArray(encoded);
|
|
178
140
|
if (integerBytes.byteLength !== 8) {
|
|
179
141
|
throw new Error(`Received ${integerBytes.byteLength} bytes, expected 8 for $integer`);
|
|
180
142
|
}
|
|
181
|
-
let value =
|
|
182
|
-
let power =
|
|
143
|
+
let value = ZERO;
|
|
144
|
+
let power = ZERO;
|
|
183
145
|
for (const byte of integerBytes) {
|
|
184
|
-
value += BigInt(byte) *
|
|
146
|
+
value += BigInt(byte) * TWOFIFTYSIX ** power;
|
|
185
147
|
power++;
|
|
186
148
|
}
|
|
187
|
-
if (value >
|
|
188
|
-
value +=
|
|
149
|
+
if (value > MAX_INT64) {
|
|
150
|
+
value += MIN_INT64 + MIN_INT64;
|
|
189
151
|
}
|
|
190
152
|
return value;
|
|
191
153
|
}
|
|
192
|
-
function
|
|
193
|
-
if (value <
|
|
154
|
+
function modernBigIntToBase64(value) {
|
|
155
|
+
if (value < MIN_INT64 || MAX_INT64 < value) {
|
|
194
156
|
throw new Error(`BigInt ${value} does not fit into a 64-bit signed integer.`);
|
|
195
157
|
}
|
|
196
158
|
const buffer = new ArrayBuffer(8);
|
|
197
159
|
new DataView(buffer).setBigInt64(0, value, true);
|
|
198
|
-
return
|
|
160
|
+
return fromByteArray(new Uint8Array(buffer));
|
|
199
161
|
}
|
|
200
|
-
function
|
|
201
|
-
const integerBytes =
|
|
162
|
+
function modernBase64ToBigInt(encoded) {
|
|
163
|
+
const integerBytes = toByteArray(encoded);
|
|
202
164
|
if (integerBytes.byteLength !== 8) {
|
|
203
165
|
throw new Error(`Received ${integerBytes.byteLength} bytes, expected 8 for $integer`);
|
|
204
166
|
}
|
|
205
167
|
const intBytesView = new DataView(integerBytes.buffer);
|
|
206
168
|
return intBytesView.getBigInt64(0, true);
|
|
207
169
|
}
|
|
208
|
-
function
|
|
209
|
-
if (k.length >
|
|
210
|
-
throw new Error(`Field name ${k} exceeds maximum field name length ${
|
|
170
|
+
function validateObjectField(k) {
|
|
171
|
+
if (k.length > MAX_IDENTIFIER_LEN) {
|
|
172
|
+
throw new Error(`Field name ${k} exceeds maximum field name length ${MAX_IDENTIFIER_LEN}.`);
|
|
211
173
|
}
|
|
212
174
|
if (k.startsWith("$")) {
|
|
213
175
|
throw new Error(`Field name ${k} starts with a '$', which is reserved.`);
|
|
214
176
|
}
|
|
215
|
-
for (let
|
|
216
|
-
const charCode = k.charCodeAt(
|
|
177
|
+
for (let i2 = 0;i2 < k.length; i2 += 1) {
|
|
178
|
+
const charCode = k.charCodeAt(i2);
|
|
217
179
|
if (charCode < 32 || charCode >= 127) {
|
|
218
|
-
throw new Error(`Field name ${k} has invalid character '${k[
|
|
180
|
+
throw new Error(`Field name ${k} has invalid character '${k[i2]}': Field names can only contain non-control ASCII characters`);
|
|
219
181
|
}
|
|
220
182
|
}
|
|
221
183
|
}
|
|
222
|
-
function
|
|
184
|
+
function jsonToConvex(value) {
|
|
223
185
|
if (value === null) {
|
|
224
186
|
return value;
|
|
225
187
|
}
|
|
@@ -233,7 +195,7 @@ function jsonToConvex2(value) {
|
|
|
233
195
|
return value;
|
|
234
196
|
}
|
|
235
197
|
if (Array.isArray(value)) {
|
|
236
|
-
return value.map((value2) =>
|
|
198
|
+
return value.map((value2) => jsonToConvex(value2));
|
|
237
199
|
}
|
|
238
200
|
if (typeof value !== "object") {
|
|
239
201
|
throw new Error(`Unexpected type of ${value}`);
|
|
@@ -245,25 +207,25 @@ function jsonToConvex2(value) {
|
|
|
245
207
|
if (typeof value.$bytes !== "string") {
|
|
246
208
|
throw new Error(`Malformed $bytes field on ${value}`);
|
|
247
209
|
}
|
|
248
|
-
return
|
|
210
|
+
return toByteArray(value.$bytes).buffer;
|
|
249
211
|
}
|
|
250
212
|
if (key === "$integer") {
|
|
251
213
|
if (typeof value.$integer !== "string") {
|
|
252
214
|
throw new Error(`Malformed $integer field on ${value}`);
|
|
253
215
|
}
|
|
254
|
-
return
|
|
216
|
+
return base64ToBigInt(value.$integer);
|
|
255
217
|
}
|
|
256
218
|
if (key === "$float") {
|
|
257
219
|
if (typeof value.$float !== "string") {
|
|
258
220
|
throw new Error(`Malformed $float field on ${value}`);
|
|
259
221
|
}
|
|
260
|
-
const floatBytes =
|
|
222
|
+
const floatBytes = toByteArray(value.$float);
|
|
261
223
|
if (floatBytes.byteLength !== 8) {
|
|
262
224
|
throw new Error(`Received ${floatBytes.byteLength} bytes, expected 8 for $float`);
|
|
263
225
|
}
|
|
264
226
|
const floatBytesView = new DataView(floatBytes.buffer);
|
|
265
|
-
const float = floatBytesView.getFloat64(0,
|
|
266
|
-
if (!
|
|
227
|
+
const float = floatBytesView.getFloat64(0, LITTLE_ENDIAN);
|
|
228
|
+
if (!isSpecial(float)) {
|
|
267
229
|
throw new Error(`Float ${float} should be encoded as a number`);
|
|
268
230
|
}
|
|
269
231
|
return float;
|
|
@@ -277,12 +239,12 @@ function jsonToConvex2(value) {
|
|
|
277
239
|
}
|
|
278
240
|
const out = {};
|
|
279
241
|
for (const [k, v] of Object.entries(value)) {
|
|
280
|
-
|
|
281
|
-
out[k] =
|
|
242
|
+
validateObjectField(k);
|
|
243
|
+
out[k] = jsonToConvex(v);
|
|
282
244
|
}
|
|
283
245
|
return out;
|
|
284
246
|
}
|
|
285
|
-
function
|
|
247
|
+
function stringifyValueForError(value) {
|
|
286
248
|
const str = JSON.stringify(value, (_key, value2) => {
|
|
287
249
|
if (value2 === undefined) {
|
|
288
250
|
return "undefined";
|
|
@@ -292,9 +254,9 @@ function stringifyValueForError2(value) {
|
|
|
292
254
|
}
|
|
293
255
|
return value2;
|
|
294
256
|
});
|
|
295
|
-
if (str.length >
|
|
257
|
+
if (str.length > MAX_VALUE_FOR_ERROR_LEN) {
|
|
296
258
|
const rest = "[...truncated]";
|
|
297
|
-
let truncateAt =
|
|
259
|
+
let truncateAt = MAX_VALUE_FOR_ERROR_LEN - rest.length;
|
|
298
260
|
const codePoint = str.codePointAt(truncateAt - 1);
|
|
299
261
|
if (codePoint !== undefined && codePoint > 65535) {
|
|
300
262
|
truncateAt -= 1;
|
|
@@ -303,25 +265,25 @@ function stringifyValueForError2(value) {
|
|
|
303
265
|
}
|
|
304
266
|
return str;
|
|
305
267
|
}
|
|
306
|
-
function
|
|
268
|
+
function convexToJsonInternal(value, originalValue, context, includeTopLevelUndefined) {
|
|
307
269
|
if (value === undefined) {
|
|
308
|
-
const contextText = context && ` (present at path ${context} in original object ${
|
|
270
|
+
const contextText = context && ` (present at path ${context} in original object ${stringifyValueForError(originalValue)})`;
|
|
309
271
|
throw new Error(`undefined is not a valid Convex value${contextText}. To learn about Convex's supported types, see https://docs.convex.dev/using/types.`);
|
|
310
272
|
}
|
|
311
273
|
if (value === null) {
|
|
312
274
|
return value;
|
|
313
275
|
}
|
|
314
276
|
if (typeof value === "bigint") {
|
|
315
|
-
if (value <
|
|
277
|
+
if (value < MIN_INT64 || MAX_INT64 < value) {
|
|
316
278
|
throw new Error(`BigInt ${value} does not fit into a 64-bit signed integer.`);
|
|
317
279
|
}
|
|
318
|
-
return { $integer:
|
|
280
|
+
return { $integer: bigIntToBase64(value) };
|
|
319
281
|
}
|
|
320
282
|
if (typeof value === "number") {
|
|
321
|
-
if (
|
|
283
|
+
if (isSpecial(value)) {
|
|
322
284
|
const buffer = new ArrayBuffer(8);
|
|
323
|
-
new DataView(buffer).setFloat64(0, value,
|
|
324
|
-
return { $float:
|
|
285
|
+
new DataView(buffer).setFloat64(0, value, LITTLE_ENDIAN);
|
|
286
|
+
return { $float: fromByteArray(new Uint8Array(buffer)) };
|
|
325
287
|
} else {
|
|
326
288
|
return value;
|
|
327
289
|
}
|
|
@@ -333,81 +295,81 @@ function convexToJsonInternal2(value, originalValue, context, includeTopLevelUnd
|
|
|
333
295
|
return value;
|
|
334
296
|
}
|
|
335
297
|
if (value instanceof ArrayBuffer) {
|
|
336
|
-
return { $bytes:
|
|
298
|
+
return { $bytes: fromByteArray(new Uint8Array(value)) };
|
|
337
299
|
}
|
|
338
300
|
if (Array.isArray(value)) {
|
|
339
|
-
return value.map((value2,
|
|
301
|
+
return value.map((value2, i2) => convexToJsonInternal(value2, originalValue, context + `[${i2}]`, false));
|
|
340
302
|
}
|
|
341
303
|
if (value instanceof Set) {
|
|
342
|
-
throw new Error(
|
|
304
|
+
throw new Error(errorMessageForUnsupportedType(context, "Set", [...value], originalValue));
|
|
343
305
|
}
|
|
344
306
|
if (value instanceof Map) {
|
|
345
|
-
throw new Error(
|
|
307
|
+
throw new Error(errorMessageForUnsupportedType(context, "Map", [...value], originalValue));
|
|
346
308
|
}
|
|
347
|
-
if (!
|
|
309
|
+
if (!isSimpleObject(value)) {
|
|
348
310
|
const theType = value?.constructor?.name;
|
|
349
311
|
const typeName = theType ? `${theType} ` : "";
|
|
350
|
-
throw new Error(
|
|
312
|
+
throw new Error(errorMessageForUnsupportedType(context, typeName, value, originalValue));
|
|
351
313
|
}
|
|
352
314
|
const out = {};
|
|
353
315
|
const entries = Object.entries(value);
|
|
354
316
|
entries.sort(([k1, _v1], [k2, _v2]) => k1 === k2 ? 0 : k1 < k2 ? -1 : 1);
|
|
355
317
|
for (const [k, v] of entries) {
|
|
356
318
|
if (v !== undefined) {
|
|
357
|
-
|
|
358
|
-
out[k] =
|
|
319
|
+
validateObjectField(k);
|
|
320
|
+
out[k] = convexToJsonInternal(v, originalValue, context + `.${k}`, false);
|
|
359
321
|
} else if (includeTopLevelUndefined) {
|
|
360
|
-
|
|
361
|
-
out[k] =
|
|
322
|
+
validateObjectField(k);
|
|
323
|
+
out[k] = convexOrUndefinedToJsonInternal(v, originalValue, context + `.${k}`);
|
|
362
324
|
}
|
|
363
325
|
}
|
|
364
326
|
return out;
|
|
365
327
|
}
|
|
366
|
-
function
|
|
328
|
+
function errorMessageForUnsupportedType(context, typeName, value, originalValue) {
|
|
367
329
|
if (context) {
|
|
368
|
-
return `${typeName}${
|
|
330
|
+
return `${typeName}${stringifyValueForError(value)} is not a supported Convex type (present at path ${context} in original object ${stringifyValueForError(originalValue)}). To learn about Convex's supported types, see https://docs.convex.dev/using/types.`;
|
|
369
331
|
} else {
|
|
370
|
-
return `${typeName}${
|
|
332
|
+
return `${typeName}${stringifyValueForError(value)} is not a supported Convex type.`;
|
|
371
333
|
}
|
|
372
334
|
}
|
|
373
|
-
function
|
|
335
|
+
function convexOrUndefinedToJsonInternal(value, originalValue, context) {
|
|
374
336
|
if (value === undefined) {
|
|
375
337
|
return { $undefined: null };
|
|
376
338
|
} else {
|
|
377
339
|
if (originalValue === undefined) {
|
|
378
|
-
throw new Error(`Programming error. Current value is ${
|
|
340
|
+
throw new Error(`Programming error. Current value is ${stringifyValueForError(value)} but original value is undefined`);
|
|
379
341
|
}
|
|
380
|
-
return
|
|
342
|
+
return convexToJsonInternal(value, originalValue, context, false);
|
|
381
343
|
}
|
|
382
344
|
}
|
|
383
|
-
function
|
|
384
|
-
return
|
|
345
|
+
function convexToJson(value) {
|
|
346
|
+
return convexToJsonInternal(value, value, "", false);
|
|
385
347
|
}
|
|
386
348
|
function convexOrUndefinedToJson(value) {
|
|
387
|
-
return
|
|
349
|
+
return convexOrUndefinedToJsonInternal(value, value, "");
|
|
388
350
|
}
|
|
389
351
|
function patchValueToJson(value) {
|
|
390
|
-
return
|
|
391
|
-
}
|
|
392
|
-
var
|
|
393
|
-
var
|
|
394
|
-
var
|
|
395
|
-
var
|
|
396
|
-
var
|
|
397
|
-
var
|
|
398
|
-
var
|
|
399
|
-
var
|
|
400
|
-
var
|
|
401
|
-
var
|
|
352
|
+
return convexToJsonInternal(value, value, "", true);
|
|
353
|
+
}
|
|
354
|
+
var LITTLE_ENDIAN = true;
|
|
355
|
+
var MIN_INT64;
|
|
356
|
+
var MAX_INT64;
|
|
357
|
+
var ZERO;
|
|
358
|
+
var EIGHT;
|
|
359
|
+
var TWOFIFTYSIX;
|
|
360
|
+
var bigIntToBase64;
|
|
361
|
+
var base64ToBigInt;
|
|
362
|
+
var MAX_IDENTIFIER_LEN = 1024;
|
|
363
|
+
var MAX_VALUE_FOR_ERROR_LEN = 16384;
|
|
402
364
|
var init_value = __esm(() => {
|
|
403
365
|
init_base64();
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
366
|
+
MIN_INT64 = BigInt("-9223372036854775808");
|
|
367
|
+
MAX_INT64 = BigInt("9223372036854775807");
|
|
368
|
+
ZERO = BigInt("0");
|
|
369
|
+
EIGHT = BigInt("8");
|
|
370
|
+
TWOFIFTYSIX = BigInt("256");
|
|
371
|
+
bigIntToBase64 = DataView.prototype.setBigInt64 ? modernBigIntToBase64 : slowBigIntToBase64;
|
|
372
|
+
base64ToBigInt = DataView.prototype.getBigInt64 ? modernBase64ToBigInt : slowBase64ToBigInt;
|
|
411
373
|
});
|
|
412
374
|
function throwUndefinedValidatorError(context, fieldName) {
|
|
413
375
|
const fieldInfo = fieldName !== undefined ? ` for field "${fieldName}"` : "";
|
|
@@ -647,7 +609,7 @@ var init_validators = __esm(() => {
|
|
|
647
609
|
get json() {
|
|
648
610
|
return {
|
|
649
611
|
type: this.kind,
|
|
650
|
-
value:
|
|
612
|
+
value: convexToJson(this.value)
|
|
651
613
|
};
|
|
652
614
|
}
|
|
653
615
|
asOptional() {
|
|
@@ -848,7 +810,7 @@ var init_errors = __esm(() => {
|
|
|
848
810
|
IDENTIFYING_FIELD = Symbol.for("ConvexError");
|
|
849
811
|
ConvexError = class ConvexError2 extends (_b = Error, _a = IDENTIFYING_FIELD, _b) {
|
|
850
812
|
constructor(data) {
|
|
851
|
-
super(typeof data === "string" ? data :
|
|
813
|
+
super(typeof data === "string" ? data : stringifyValueForError(data));
|
|
852
814
|
__publicField2(this, "name", "ConvexError");
|
|
853
815
|
__publicField2(this, "data");
|
|
854
816
|
__publicField2(this, _a, true);
|
|
@@ -861,6 +823,44 @@ var init_values = __esm(() => {
|
|
|
861
823
|
init_validator();
|
|
862
824
|
init_errors();
|
|
863
825
|
});
|
|
826
|
+
function hexToArrayBuffer(hex) {
|
|
827
|
+
if (hex === "") {
|
|
828
|
+
return new Uint8Array(0).buffer;
|
|
829
|
+
}
|
|
830
|
+
const matches = hex.match(/.{1,2}/g);
|
|
831
|
+
if (!matches) {
|
|
832
|
+
throw new Error(`Invalid hex string: ${hex}`);
|
|
833
|
+
}
|
|
834
|
+
return new Uint8Array(matches.map((byte) => parseInt(byte, 16))).buffer;
|
|
835
|
+
}
|
|
836
|
+
function arrayBufferToHex(buffer) {
|
|
837
|
+
return Array.from(new Uint8Array(buffer)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
838
|
+
}
|
|
839
|
+
function stringToHex(s) {
|
|
840
|
+
const buffer = new TextEncoder().encode(s);
|
|
841
|
+
return arrayBufferToHex(buffer.buffer);
|
|
842
|
+
}
|
|
843
|
+
function hexToString(hex) {
|
|
844
|
+
const buffer = hexToArrayBuffer(hex);
|
|
845
|
+
return new TextDecoder().decode(buffer);
|
|
846
|
+
}
|
|
847
|
+
function serializeDeveloperId(tableHex, internalIdHex) {
|
|
848
|
+
return `${tableHex}${DOC_ID_SEPARATOR}${internalIdHex}`;
|
|
849
|
+
}
|
|
850
|
+
function deserializeDeveloperId(developerId) {
|
|
851
|
+
if (!developerId) {
|
|
852
|
+
return null;
|
|
853
|
+
}
|
|
854
|
+
for (const separator of [DOC_ID_SEPARATOR, LEGACY_DOC_ID_SEPARATOR]) {
|
|
855
|
+
const parts = developerId.split(separator);
|
|
856
|
+
if (parts.length === 2 && parts[0] && parts[1]) {
|
|
857
|
+
return { table: parts[0], internalId: parts[1] };
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
return null;
|
|
861
|
+
}
|
|
862
|
+
var DOC_ID_SEPARATOR = ":";
|
|
863
|
+
var LEGACY_DOC_ID_SEPARATOR = ";";
|
|
864
864
|
function encodeNumber(n) {
|
|
865
865
|
const buffer = new ArrayBuffer(8);
|
|
866
866
|
const view = new DataView(buffer);
|
|
@@ -869,8 +869,8 @@ function encodeNumber(n) {
|
|
|
869
869
|
if (n >= 0) {
|
|
870
870
|
bytes[0] ^= 128;
|
|
871
871
|
} else {
|
|
872
|
-
for (let
|
|
873
|
-
bytes[
|
|
872
|
+
for (let i2 = 0;i2 < 8; i2++) {
|
|
873
|
+
bytes[i2] ^= 255;
|
|
874
874
|
}
|
|
875
875
|
}
|
|
876
876
|
return bytes;
|
|
@@ -983,10 +983,10 @@ function compareIndexKeys(a, b) {
|
|
|
983
983
|
const viewA = new Uint8Array(a);
|
|
984
984
|
const viewB = new Uint8Array(b);
|
|
985
985
|
const minLen = Math.min(viewA.length, viewB.length);
|
|
986
|
-
for (let
|
|
987
|
-
if (viewA[
|
|
986
|
+
for (let i2 = 0;i2 < minLen; i2++) {
|
|
987
|
+
if (viewA[i2] < viewB[i2])
|
|
988
988
|
return -1;
|
|
989
|
-
if (viewA[
|
|
989
|
+
if (viewA[i2] > viewB[i2])
|
|
990
990
|
return 1;
|
|
991
991
|
}
|
|
992
992
|
if (viewA.length < viewB.length)
|
|
@@ -1135,7 +1135,7 @@ async function performAsyncSyscall(op, arg) {
|
|
|
1135
1135
|
} catch (e) {
|
|
1136
1136
|
if (e.data !== undefined) {
|
|
1137
1137
|
const rethrown = new ConvexError(e.message);
|
|
1138
|
-
rethrown.data =
|
|
1138
|
+
rethrown.data = jsonToConvex(e.data);
|
|
1139
1139
|
throw rethrown;
|
|
1140
1140
|
}
|
|
1141
1141
|
throw new Error(e.message);
|
|
@@ -1529,7 +1529,7 @@ var init_query_impl = __esm(() => {
|
|
|
1529
1529
|
const syscallJSON = await performAsyncSyscall("1.0/count", {
|
|
1530
1530
|
table: this.tableName
|
|
1531
1531
|
});
|
|
1532
|
-
const syscallResult =
|
|
1532
|
+
const syscallResult = jsonToConvex(syscallJSON);
|
|
1533
1533
|
return syscallResult;
|
|
1534
1534
|
}
|
|
1535
1535
|
filter(predicate) {
|
|
@@ -1639,7 +1639,7 @@ var init_query_impl = __esm(() => {
|
|
|
1639
1639
|
if (done) {
|
|
1640
1640
|
this.closeQuery();
|
|
1641
1641
|
}
|
|
1642
|
-
const convexValue =
|
|
1642
|
+
const convexValue = jsonToConvex(value);
|
|
1643
1643
|
return { value: convexValue, done };
|
|
1644
1644
|
}
|
|
1645
1645
|
return() {
|
|
@@ -1666,7 +1666,7 @@ var init_query_impl = __esm(() => {
|
|
|
1666
1666
|
version
|
|
1667
1667
|
});
|
|
1668
1668
|
return {
|
|
1669
|
-
page: page.map((json) =>
|
|
1669
|
+
page: page.map((json) => jsonToConvex(json)),
|
|
1670
1670
|
isDone,
|
|
1671
1671
|
continueCursor,
|
|
1672
1672
|
splitCursor,
|
|
@@ -1708,13 +1708,13 @@ async function get(table, id, isSystem) {
|
|
|
1708
1708
|
throw new Error(`Invalid argument \`id\` for \`db.get\`, expected string but got '${typeof id}': ${id}`);
|
|
1709
1709
|
}
|
|
1710
1710
|
const args = {
|
|
1711
|
-
id:
|
|
1711
|
+
id: convexToJson(id),
|
|
1712
1712
|
isSystem,
|
|
1713
1713
|
version,
|
|
1714
1714
|
table
|
|
1715
1715
|
};
|
|
1716
1716
|
const syscallJSON = await performAsyncSyscall("1.0/get", args);
|
|
1717
|
-
return
|
|
1717
|
+
return jsonToConvex(syscallJSON);
|
|
1718
1718
|
}
|
|
1719
1719
|
function setupReader() {
|
|
1720
1720
|
const reader = (isSystem = false) => {
|
|
@@ -1736,7 +1736,7 @@ function setupReader() {
|
|
|
1736
1736
|
table: tableName,
|
|
1737
1737
|
idString: id
|
|
1738
1738
|
});
|
|
1739
|
-
const syscallResult =
|
|
1739
|
+
const syscallResult = jsonToConvex(syscallJSON);
|
|
1740
1740
|
return syscallResult.id;
|
|
1741
1741
|
},
|
|
1742
1742
|
system: null,
|
|
@@ -1758,16 +1758,16 @@ async function insert(tableName, value) {
|
|
|
1758
1758
|
validateArg(value, 2, "insert", "value");
|
|
1759
1759
|
const syscallJSON = await performAsyncSyscall("1.0/insert", {
|
|
1760
1760
|
table: tableName,
|
|
1761
|
-
value:
|
|
1761
|
+
value: convexToJson(value)
|
|
1762
1762
|
});
|
|
1763
|
-
const syscallResult =
|
|
1763
|
+
const syscallResult = jsonToConvex(syscallJSON);
|
|
1764
1764
|
return syscallResult._id;
|
|
1765
1765
|
}
|
|
1766
1766
|
async function patch(table, id, value) {
|
|
1767
1767
|
validateArg(id, 1, "patch", "id");
|
|
1768
1768
|
validateArg(value, 2, "patch", "value");
|
|
1769
1769
|
await performAsyncSyscall("1.0/shallowMerge", {
|
|
1770
|
-
id:
|
|
1770
|
+
id: convexToJson(id),
|
|
1771
1771
|
value: patchValueToJson(value),
|
|
1772
1772
|
table
|
|
1773
1773
|
});
|
|
@@ -1776,15 +1776,15 @@ async function replace(table, id, value) {
|
|
|
1776
1776
|
validateArg(id, 1, "replace", "id");
|
|
1777
1777
|
validateArg(value, 2, "replace", "value");
|
|
1778
1778
|
await performAsyncSyscall("1.0/replace", {
|
|
1779
|
-
id:
|
|
1780
|
-
value:
|
|
1779
|
+
id: convexToJson(id),
|
|
1780
|
+
value: convexToJson(value),
|
|
1781
1781
|
table
|
|
1782
1782
|
});
|
|
1783
1783
|
}
|
|
1784
1784
|
async function delete_(table, id) {
|
|
1785
1785
|
validateArg(id, 1, "delete", "id");
|
|
1786
1786
|
await performAsyncSyscall("1.0/remove", {
|
|
1787
|
-
id:
|
|
1787
|
+
id: convexToJson(id),
|
|
1788
1788
|
table
|
|
1789
1789
|
});
|
|
1790
1790
|
}
|
|
@@ -1862,7 +1862,7 @@ function setupMutationScheduler() {
|
|
|
1862
1862
|
},
|
|
1863
1863
|
cancel: async (id) => {
|
|
1864
1864
|
validateArg(id, 1, "cancel", "id");
|
|
1865
|
-
const args = { id:
|
|
1865
|
+
const args = { id: convexToJson(id) };
|
|
1866
1866
|
await performAsyncSyscall("1.0/cancel_job", args);
|
|
1867
1867
|
}
|
|
1868
1868
|
};
|
|
@@ -1883,7 +1883,7 @@ function runAfterSyscallArgs(delayMs, functionReference, args) {
|
|
|
1883
1883
|
return {
|
|
1884
1884
|
...address,
|
|
1885
1885
|
ts,
|
|
1886
|
-
args:
|
|
1886
|
+
args: convexToJson(functionArgs),
|
|
1887
1887
|
version
|
|
1888
1888
|
};
|
|
1889
1889
|
}
|
|
@@ -1901,7 +1901,7 @@ function runAtSyscallArgs(ms_since_epoch_or_date, functionReference, args) {
|
|
|
1901
1901
|
return {
|
|
1902
1902
|
...address,
|
|
1903
1903
|
ts,
|
|
1904
|
-
args:
|
|
1904
|
+
args: convexToJson(functionArgs),
|
|
1905
1905
|
version
|
|
1906
1906
|
};
|
|
1907
1907
|
}
|
|
@@ -1954,7 +1954,7 @@ var init_storage_impl = __esm(() => {
|
|
|
1954
1954
|
});
|
|
1955
1955
|
async function invokeMutation(func, argsStr) {
|
|
1956
1956
|
const requestId = "";
|
|
1957
|
-
const args =
|
|
1957
|
+
const args = jsonToConvex(JSON.parse(argsStr));
|
|
1958
1958
|
const mutationCtx = {
|
|
1959
1959
|
db: setupWriter(),
|
|
1960
1960
|
auth: setupAuth(requestId),
|
|
@@ -1965,7 +1965,7 @@ async function invokeMutation(func, argsStr) {
|
|
|
1965
1965
|
};
|
|
1966
1966
|
const result = await invokeFunction(func, mutationCtx, args);
|
|
1967
1967
|
validateReturnValue(result);
|
|
1968
|
-
return JSON.stringify(
|
|
1968
|
+
return JSON.stringify(convexToJson(result === undefined ? null : result));
|
|
1969
1969
|
}
|
|
1970
1970
|
function validateReturnValue(v2) {
|
|
1971
1971
|
if (v2 instanceof QueryInitializerImpl || v2 instanceof QueryImpl) {
|
|
@@ -1990,7 +1990,7 @@ function dontCallDirectly(funcType, handler) {
|
|
|
1990
1990
|
function serializeConvexErrorData(thrown) {
|
|
1991
1991
|
if (typeof thrown === "object" && thrown !== null && Symbol.for("ConvexError") in thrown) {
|
|
1992
1992
|
const error = thrown;
|
|
1993
|
-
error.data = JSON.stringify(
|
|
1993
|
+
error.data = JSON.stringify(convexToJson(error.data === undefined ? null : error.data));
|
|
1994
1994
|
error.ConvexErrorSymbol = Symbol.for("ConvexError");
|
|
1995
1995
|
return error;
|
|
1996
1996
|
} else {
|
|
@@ -2032,7 +2032,7 @@ function exportReturns(functionDefinition) {
|
|
|
2032
2032
|
}
|
|
2033
2033
|
async function invokeQuery(func, argsStr) {
|
|
2034
2034
|
const requestId = "";
|
|
2035
|
-
const args =
|
|
2035
|
+
const args = jsonToConvex(JSON.parse(argsStr));
|
|
2036
2036
|
const queryCtx = {
|
|
2037
2037
|
db: setupReader(),
|
|
2038
2038
|
auth: setupAuth(requestId),
|
|
@@ -2041,17 +2041,17 @@ async function invokeQuery(func, argsStr) {
|
|
|
2041
2041
|
};
|
|
2042
2042
|
const result = await invokeFunction(func, queryCtx, args);
|
|
2043
2043
|
validateReturnValue(result);
|
|
2044
|
-
return JSON.stringify(
|
|
2044
|
+
return JSON.stringify(convexToJson(result === undefined ? null : result));
|
|
2045
2045
|
}
|
|
2046
2046
|
async function runUdf(udfType, f, args) {
|
|
2047
2047
|
const queryArgs = parseArgs(args);
|
|
2048
2048
|
const syscallArgs = {
|
|
2049
2049
|
udfType,
|
|
2050
|
-
args:
|
|
2050
|
+
args: convexToJson(queryArgs),
|
|
2051
2051
|
...getFunctionAddress(f)
|
|
2052
2052
|
};
|
|
2053
2053
|
const result = await performAsyncSyscall("1.0/runUdf", syscallArgs);
|
|
2054
|
-
return
|
|
2054
|
+
return jsonToConvex(result);
|
|
2055
2055
|
}
|
|
2056
2056
|
var mutationGeneric = (functionDefinition) => {
|
|
2057
2057
|
const handler = typeof functionDefinition === "function" ? functionDefinition : functionDefinition.handler;
|
|
@@ -2325,9 +2325,9 @@ async function listSystemFunctions(options = {}) {
|
|
|
2325
2325
|
});
|
|
2326
2326
|
const analysisResults = await pooledMap(filteredListings, (listing) => analyzeModule(listing, componentPath), 20);
|
|
2327
2327
|
const results = [];
|
|
2328
|
-
for (let
|
|
2329
|
-
const listing = filteredListings[
|
|
2330
|
-
const result = analysisResults[
|
|
2328
|
+
for (let i2 = 0;i2 < filteredListings.length; i2++) {
|
|
2329
|
+
const listing = filteredListings[i2];
|
|
2330
|
+
const result = analysisResults[i2];
|
|
2331
2331
|
if (result.status === "rejected") {
|
|
2332
2332
|
if (!isNpmPackageError(result.reason)) {
|
|
2333
2333
|
console.warn(`Failed to analyze module "${listing.path}":`, result.reason);
|
|
@@ -3196,7 +3196,7 @@ class ModuleRegistry {
|
|
|
3196
3196
|
}
|
|
3197
3197
|
async load(request) {
|
|
3198
3198
|
const scopes = expandComponentScopes(request.componentPath);
|
|
3199
|
-
const
|
|
3199
|
+
const errors2 = [];
|
|
3200
3200
|
let attempted = false;
|
|
3201
3201
|
for (const scope of scopes) {
|
|
3202
3202
|
const loaders = this.scopedLoaders.get(scope);
|
|
@@ -3211,7 +3211,7 @@ class ModuleRegistry {
|
|
|
3211
3211
|
return result;
|
|
3212
3212
|
}
|
|
3213
3213
|
} catch (error2) {
|
|
3214
|
-
|
|
3214
|
+
errors2.push(error2);
|
|
3215
3215
|
}
|
|
3216
3216
|
}
|
|
3217
3217
|
}
|
|
@@ -3220,8 +3220,8 @@ class ModuleRegistry {
|
|
|
3220
3220
|
throw new Error(`Unable to resolve ${description}. No module loaders are registered${request.componentPath ? ` for component "${request.componentPath}"` : ""}. Register a loader with runtime worker options (\`moduleLoader\`, \`moduleLoaders\`, or \`configureModuleLoaders\`).`);
|
|
3221
3221
|
}
|
|
3222
3222
|
const error = new Error(`Unable to resolve ${description}`);
|
|
3223
|
-
if (
|
|
3224
|
-
error.causes =
|
|
3223
|
+
if (errors2.length > 0) {
|
|
3224
|
+
error.causes = errors2;
|
|
3225
3225
|
}
|
|
3226
3226
|
throw error;
|
|
3227
3227
|
}
|
|
@@ -3445,8 +3445,8 @@ function expandComponentScopes(componentPath) {
|
|
|
3445
3445
|
if (componentPath) {
|
|
3446
3446
|
const normalized = normalizeComponentPath(componentPath);
|
|
3447
3447
|
const segments = normalized.split("/").filter(Boolean);
|
|
3448
|
-
for (let
|
|
3449
|
-
scopes.push(segments.slice(0,
|
|
3448
|
+
for (let i2 = segments.length;i2 > 0; i2--) {
|
|
3449
|
+
scopes.push(segments.slice(0, i2).join("/"));
|
|
3450
3450
|
}
|
|
3451
3451
|
}
|
|
3452
3452
|
scopes.push("");
|
|
@@ -3721,8 +3721,8 @@ Path: ${formatPath(path)}
|
|
|
3721
3721
|
Value: ${formatValue(value)}
|
|
3722
3722
|
Validator: v.array(...)`);
|
|
3723
3723
|
}
|
|
3724
|
-
for (let
|
|
3725
|
-
validateValidator(validator2.value, value[
|
|
3724
|
+
for (let i2 = 0;i2 < value.length; i2++) {
|
|
3725
|
+
validateValidator(validator2.value, value[i2], `${path}[${i2}]`, options);
|
|
3726
3726
|
}
|
|
3727
3727
|
return;
|
|
3728
3728
|
}
|
|
@@ -3750,7 +3750,7 @@ Path: ${formatPath(path)}
|
|
|
3750
3750
|
Value: ${formatValue(value)}
|
|
3751
3751
|
Validator: v.object({...})`);
|
|
3752
3752
|
}
|
|
3753
|
-
if (!
|
|
3753
|
+
if (!isSimpleObject2(value)) {
|
|
3754
3754
|
throw new Error(`Value does not match validator.
|
|
3755
3755
|
Path: ${formatPath(path)}
|
|
3756
3756
|
Value: ${formatValue(value)}
|
|
@@ -3800,7 +3800,7 @@ function isMatchingValidatorTable(idTableName, validatorTableName, componentPath
|
|
|
3800
3800
|
}
|
|
3801
3801
|
return idBareName === validatorBareName;
|
|
3802
3802
|
}
|
|
3803
|
-
function
|
|
3803
|
+
function isSimpleObject2(value) {
|
|
3804
3804
|
const isObject = typeof value === "object";
|
|
3805
3805
|
const prototype = Object.getPrototypeOf(value);
|
|
3806
3806
|
const isSimple = prototype === null || prototype === Object.prototype || prototype?.constructor?.name === "Object";
|
|
@@ -4030,9 +4030,9 @@ var ALPHABET = "0123456789abcdefghjkmnpqrstvwxyz";
|
|
|
4030
4030
|
var ALPHABET_MAP;
|
|
4031
4031
|
var init_base32 = __esm(() => {
|
|
4032
4032
|
ALPHABET_MAP = new Map;
|
|
4033
|
-
for (let
|
|
4034
|
-
ALPHABET_MAP.set(ALPHABET[
|
|
4035
|
-
ALPHABET_MAP.set(ALPHABET[
|
|
4033
|
+
for (let i2 = 0;i2 < ALPHABET.length; i2++) {
|
|
4034
|
+
ALPHABET_MAP.set(ALPHABET[i2], i2);
|
|
4035
|
+
ALPHABET_MAP.set(ALPHABET[i2].toUpperCase(), i2);
|
|
4036
4036
|
}
|
|
4037
4037
|
ALPHABET_MAP.set("i", 1);
|
|
4038
4038
|
ALPHABET_MAP.set("I", 1);
|
|
@@ -4183,8 +4183,8 @@ function isValidDocumentId(encoded) {
|
|
|
4183
4183
|
}
|
|
4184
4184
|
function internalIdToHex(internalId) {
|
|
4185
4185
|
let hex = "";
|
|
4186
|
-
for (let
|
|
4187
|
-
hex += internalId[
|
|
4186
|
+
for (let i2 = 0;i2 < internalId.length; i2++) {
|
|
4187
|
+
hex += internalId[i2].toString(16).padStart(2, "0");
|
|
4188
4188
|
}
|
|
4189
4189
|
return hex;
|
|
4190
4190
|
}
|
|
@@ -4196,332 +4196,7 @@ var init_document_id = __esm(() => {
|
|
|
4196
4196
|
init_base32();
|
|
4197
4197
|
cryptoGetRandomValues = crypto.getRandomValues.bind(crypto);
|
|
4198
4198
|
});
|
|
4199
|
-
|
|
4200
|
-
var revLookup = [];
|
|
4201
|
-
var Arr = Uint8Array;
|
|
4202
|
-
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
4203
|
-
for (i = 0, len = code.length;i < len; ++i) {
|
|
4204
|
-
lookup[i] = code[i];
|
|
4205
|
-
revLookup[code.charCodeAt(i)] = i;
|
|
4206
|
-
}
|
|
4207
|
-
var i;
|
|
4208
|
-
var len;
|
|
4209
|
-
revLookup[45] = 62;
|
|
4210
|
-
revLookup[95] = 63;
|
|
4211
|
-
function getLens(b64) {
|
|
4212
|
-
var len22 = b64.length;
|
|
4213
|
-
if (len22 % 4 > 0) {
|
|
4214
|
-
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
4215
|
-
}
|
|
4216
|
-
var validLen = b64.indexOf("=");
|
|
4217
|
-
if (validLen === -1)
|
|
4218
|
-
validLen = len22;
|
|
4219
|
-
var placeHoldersLen = validLen === len22 ? 0 : 4 - validLen % 4;
|
|
4220
|
-
return [validLen, placeHoldersLen];
|
|
4221
|
-
}
|
|
4222
|
-
function _byteLength(_b64, validLen, placeHoldersLen) {
|
|
4223
|
-
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
4224
|
-
}
|
|
4225
|
-
function toByteArray(b64) {
|
|
4226
|
-
var tmp;
|
|
4227
|
-
var lens = getLens(b64);
|
|
4228
|
-
var validLen = lens[0];
|
|
4229
|
-
var placeHoldersLen = lens[1];
|
|
4230
|
-
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
|
|
4231
|
-
var curByte = 0;
|
|
4232
|
-
var len22 = placeHoldersLen > 0 ? validLen - 4 : validLen;
|
|
4233
|
-
var i22;
|
|
4234
|
-
for (i22 = 0;i22 < len22; i22 += 4) {
|
|
4235
|
-
tmp = revLookup[b64.charCodeAt(i22)] << 18 | revLookup[b64.charCodeAt(i22 + 1)] << 12 | revLookup[b64.charCodeAt(i22 + 2)] << 6 | revLookup[b64.charCodeAt(i22 + 3)];
|
|
4236
|
-
arr[curByte++] = tmp >> 16 & 255;
|
|
4237
|
-
arr[curByte++] = tmp >> 8 & 255;
|
|
4238
|
-
arr[curByte++] = tmp & 255;
|
|
4239
|
-
}
|
|
4240
|
-
if (placeHoldersLen === 2) {
|
|
4241
|
-
tmp = revLookup[b64.charCodeAt(i22)] << 2 | revLookup[b64.charCodeAt(i22 + 1)] >> 4;
|
|
4242
|
-
arr[curByte++] = tmp & 255;
|
|
4243
|
-
}
|
|
4244
|
-
if (placeHoldersLen === 1) {
|
|
4245
|
-
tmp = revLookup[b64.charCodeAt(i22)] << 10 | revLookup[b64.charCodeAt(i22 + 1)] << 4 | revLookup[b64.charCodeAt(i22 + 2)] >> 2;
|
|
4246
|
-
arr[curByte++] = tmp >> 8 & 255;
|
|
4247
|
-
arr[curByte++] = tmp & 255;
|
|
4248
|
-
}
|
|
4249
|
-
return arr;
|
|
4250
|
-
}
|
|
4251
|
-
function tripletToBase64(num) {
|
|
4252
|
-
return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
|
|
4253
|
-
}
|
|
4254
|
-
function encodeChunk(uint8, start, end) {
|
|
4255
|
-
var tmp;
|
|
4256
|
-
var output = [];
|
|
4257
|
-
for (var i22 = start;i22 < end; i22 += 3) {
|
|
4258
|
-
tmp = (uint8[i22] << 16 & 16711680) + (uint8[i22 + 1] << 8 & 65280) + (uint8[i22 + 2] & 255);
|
|
4259
|
-
output.push(tripletToBase64(tmp));
|
|
4260
|
-
}
|
|
4261
|
-
return output.join("");
|
|
4262
|
-
}
|
|
4263
|
-
function fromByteArray(uint8) {
|
|
4264
|
-
var tmp;
|
|
4265
|
-
var len22 = uint8.length;
|
|
4266
|
-
var extraBytes = len22 % 3;
|
|
4267
|
-
var parts = [];
|
|
4268
|
-
var maxChunkLength = 16383;
|
|
4269
|
-
for (var i22 = 0, len222 = len22 - extraBytes;i22 < len222; i22 += maxChunkLength) {
|
|
4270
|
-
parts.push(encodeChunk(uint8, i22, i22 + maxChunkLength > len222 ? len222 : i22 + maxChunkLength));
|
|
4271
|
-
}
|
|
4272
|
-
if (extraBytes === 1) {
|
|
4273
|
-
tmp = uint8[len22 - 1];
|
|
4274
|
-
parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "==");
|
|
4275
|
-
} else if (extraBytes === 2) {
|
|
4276
|
-
tmp = (uint8[len22 - 2] << 8) + uint8[len22 - 1];
|
|
4277
|
-
parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "=");
|
|
4278
|
-
}
|
|
4279
|
-
return parts.join("");
|
|
4280
|
-
}
|
|
4281
|
-
function isSimpleObject(value) {
|
|
4282
|
-
const isObject = typeof value === "object";
|
|
4283
|
-
const prototype = Object.getPrototypeOf(value);
|
|
4284
|
-
const isSimple = prototype === null || prototype === Object.prototype || prototype?.constructor?.name === "Object";
|
|
4285
|
-
return isObject && isSimple;
|
|
4286
|
-
}
|
|
4287
|
-
var LITTLE_ENDIAN = true;
|
|
4288
|
-
var MIN_INT64 = BigInt("-9223372036854775808");
|
|
4289
|
-
var MAX_INT64 = BigInt("9223372036854775807");
|
|
4290
|
-
var ZERO = BigInt("0");
|
|
4291
|
-
var EIGHT = BigInt("8");
|
|
4292
|
-
var TWOFIFTYSIX = BigInt("256");
|
|
4293
|
-
function isSpecial(n) {
|
|
4294
|
-
return Number.isNaN(n) || !Number.isFinite(n) || Object.is(n, -0);
|
|
4295
|
-
}
|
|
4296
|
-
function slowBigIntToBase64(value) {
|
|
4297
|
-
if (value < ZERO) {
|
|
4298
|
-
value -= MIN_INT64 + MIN_INT64;
|
|
4299
|
-
}
|
|
4300
|
-
let hex = value.toString(16);
|
|
4301
|
-
if (hex.length % 2 === 1)
|
|
4302
|
-
hex = "0" + hex;
|
|
4303
|
-
const bytes = new Uint8Array(new ArrayBuffer(8));
|
|
4304
|
-
let i22 = 0;
|
|
4305
|
-
for (const hexByte of hex.match(/.{2}/g).reverse()) {
|
|
4306
|
-
bytes.set([parseInt(hexByte, 16)], i22++);
|
|
4307
|
-
value >>= EIGHT;
|
|
4308
|
-
}
|
|
4309
|
-
return fromByteArray(bytes);
|
|
4310
|
-
}
|
|
4311
|
-
function slowBase64ToBigInt(encoded) {
|
|
4312
|
-
const integerBytes = toByteArray(encoded);
|
|
4313
|
-
if (integerBytes.byteLength !== 8) {
|
|
4314
|
-
throw new Error(`Received ${integerBytes.byteLength} bytes, expected 8 for $integer`);
|
|
4315
|
-
}
|
|
4316
|
-
let value = ZERO;
|
|
4317
|
-
let power = ZERO;
|
|
4318
|
-
for (const byte of integerBytes) {
|
|
4319
|
-
value += BigInt(byte) * TWOFIFTYSIX ** power;
|
|
4320
|
-
power++;
|
|
4321
|
-
}
|
|
4322
|
-
if (value > MAX_INT64) {
|
|
4323
|
-
value += MIN_INT64 + MIN_INT64;
|
|
4324
|
-
}
|
|
4325
|
-
return value;
|
|
4326
|
-
}
|
|
4327
|
-
function modernBigIntToBase64(value) {
|
|
4328
|
-
if (value < MIN_INT64 || MAX_INT64 < value) {
|
|
4329
|
-
throw new Error(`BigInt ${value} does not fit into a 64-bit signed integer.`);
|
|
4330
|
-
}
|
|
4331
|
-
const buffer = new ArrayBuffer(8);
|
|
4332
|
-
new DataView(buffer).setBigInt64(0, value, true);
|
|
4333
|
-
return fromByteArray(new Uint8Array(buffer));
|
|
4334
|
-
}
|
|
4335
|
-
function modernBase64ToBigInt(encoded) {
|
|
4336
|
-
const integerBytes = toByteArray(encoded);
|
|
4337
|
-
if (integerBytes.byteLength !== 8) {
|
|
4338
|
-
throw new Error(`Received ${integerBytes.byteLength} bytes, expected 8 for $integer`);
|
|
4339
|
-
}
|
|
4340
|
-
const intBytesView = new DataView(integerBytes.buffer);
|
|
4341
|
-
return intBytesView.getBigInt64(0, true);
|
|
4342
|
-
}
|
|
4343
|
-
var bigIntToBase64 = DataView.prototype.setBigInt64 ? modernBigIntToBase64 : slowBigIntToBase64;
|
|
4344
|
-
var base64ToBigInt = DataView.prototype.getBigInt64 ? modernBase64ToBigInt : slowBase64ToBigInt;
|
|
4345
|
-
var MAX_IDENTIFIER_LEN = 1024;
|
|
4346
|
-
function validateObjectField(k) {
|
|
4347
|
-
if (k.length > MAX_IDENTIFIER_LEN) {
|
|
4348
|
-
throw new Error(`Field name ${k} exceeds maximum field name length ${MAX_IDENTIFIER_LEN}.`);
|
|
4349
|
-
}
|
|
4350
|
-
if (k.startsWith("$")) {
|
|
4351
|
-
throw new Error(`Field name ${k} starts with a '$', which is reserved.`);
|
|
4352
|
-
}
|
|
4353
|
-
for (let i22 = 0;i22 < k.length; i22 += 1) {
|
|
4354
|
-
const charCode = k.charCodeAt(i22);
|
|
4355
|
-
if (charCode < 32 || charCode >= 127) {
|
|
4356
|
-
throw new Error(`Field name ${k} has invalid character '${k[i22]}': Field names can only contain non-control ASCII characters`);
|
|
4357
|
-
}
|
|
4358
|
-
}
|
|
4359
|
-
}
|
|
4360
|
-
function jsonToConvex(value) {
|
|
4361
|
-
if (value === null) {
|
|
4362
|
-
return value;
|
|
4363
|
-
}
|
|
4364
|
-
if (typeof value === "boolean") {
|
|
4365
|
-
return value;
|
|
4366
|
-
}
|
|
4367
|
-
if (typeof value === "number") {
|
|
4368
|
-
return value;
|
|
4369
|
-
}
|
|
4370
|
-
if (typeof value === "string") {
|
|
4371
|
-
return value;
|
|
4372
|
-
}
|
|
4373
|
-
if (Array.isArray(value)) {
|
|
4374
|
-
return value.map((value2) => jsonToConvex(value2));
|
|
4375
|
-
}
|
|
4376
|
-
if (typeof value !== "object") {
|
|
4377
|
-
throw new Error(`Unexpected type of ${value}`);
|
|
4378
|
-
}
|
|
4379
|
-
const entries = Object.entries(value);
|
|
4380
|
-
if (entries.length === 1) {
|
|
4381
|
-
const key = entries[0][0];
|
|
4382
|
-
if (key === "$bytes") {
|
|
4383
|
-
if (typeof value.$bytes !== "string") {
|
|
4384
|
-
throw new Error(`Malformed $bytes field on ${value}`);
|
|
4385
|
-
}
|
|
4386
|
-
return toByteArray(value.$bytes).buffer;
|
|
4387
|
-
}
|
|
4388
|
-
if (key === "$integer") {
|
|
4389
|
-
if (typeof value.$integer !== "string") {
|
|
4390
|
-
throw new Error(`Malformed $integer field on ${value}`);
|
|
4391
|
-
}
|
|
4392
|
-
return base64ToBigInt(value.$integer);
|
|
4393
|
-
}
|
|
4394
|
-
if (key === "$float") {
|
|
4395
|
-
if (typeof value.$float !== "string") {
|
|
4396
|
-
throw new Error(`Malformed $float field on ${value}`);
|
|
4397
|
-
}
|
|
4398
|
-
const floatBytes = toByteArray(value.$float);
|
|
4399
|
-
if (floatBytes.byteLength !== 8) {
|
|
4400
|
-
throw new Error(`Received ${floatBytes.byteLength} bytes, expected 8 for $float`);
|
|
4401
|
-
}
|
|
4402
|
-
const floatBytesView = new DataView(floatBytes.buffer);
|
|
4403
|
-
const float = floatBytesView.getFloat64(0, LITTLE_ENDIAN);
|
|
4404
|
-
if (!isSpecial(float)) {
|
|
4405
|
-
throw new Error(`Float ${float} should be encoded as a number`);
|
|
4406
|
-
}
|
|
4407
|
-
return float;
|
|
4408
|
-
}
|
|
4409
|
-
if (key === "$set") {
|
|
4410
|
-
throw new Error(`Received a Set which is no longer supported as a Convex type.`);
|
|
4411
|
-
}
|
|
4412
|
-
if (key === "$map") {
|
|
4413
|
-
throw new Error(`Received a Map which is no longer supported as a Convex type.`);
|
|
4414
|
-
}
|
|
4415
|
-
}
|
|
4416
|
-
const out = {};
|
|
4417
|
-
for (const [k, v2] of Object.entries(value)) {
|
|
4418
|
-
validateObjectField(k);
|
|
4419
|
-
out[k] = jsonToConvex(v2);
|
|
4420
|
-
}
|
|
4421
|
-
return out;
|
|
4422
|
-
}
|
|
4423
|
-
var MAX_VALUE_FOR_ERROR_LEN = 16384;
|
|
4424
|
-
function stringifyValueForError(value) {
|
|
4425
|
-
const str = JSON.stringify(value, (_key, value2) => {
|
|
4426
|
-
if (value2 === undefined) {
|
|
4427
|
-
return "undefined";
|
|
4428
|
-
}
|
|
4429
|
-
if (typeof value2 === "bigint") {
|
|
4430
|
-
return `${value2.toString()}n`;
|
|
4431
|
-
}
|
|
4432
|
-
return value2;
|
|
4433
|
-
});
|
|
4434
|
-
if (str.length > MAX_VALUE_FOR_ERROR_LEN) {
|
|
4435
|
-
const rest = "[...truncated]";
|
|
4436
|
-
let truncateAt = MAX_VALUE_FOR_ERROR_LEN - rest.length;
|
|
4437
|
-
const codePoint = str.codePointAt(truncateAt - 1);
|
|
4438
|
-
if (codePoint !== undefined && codePoint > 65535) {
|
|
4439
|
-
truncateAt -= 1;
|
|
4440
|
-
}
|
|
4441
|
-
return str.substring(0, truncateAt) + rest;
|
|
4442
|
-
}
|
|
4443
|
-
return str;
|
|
4444
|
-
}
|
|
4445
|
-
function convexToJsonInternal(value, originalValue, context, includeTopLevelUndefined) {
|
|
4446
|
-
if (value === undefined) {
|
|
4447
|
-
const contextText = context && ` (present at path ${context} in original object ${stringifyValueForError(originalValue)})`;
|
|
4448
|
-
throw new Error(`undefined is not a valid Convex value${contextText}. To learn about Convex's supported types, see https://docs.convex.dev/using/types.`);
|
|
4449
|
-
}
|
|
4450
|
-
if (value === null) {
|
|
4451
|
-
return value;
|
|
4452
|
-
}
|
|
4453
|
-
if (typeof value === "bigint") {
|
|
4454
|
-
if (value < MIN_INT64 || MAX_INT64 < value) {
|
|
4455
|
-
throw new Error(`BigInt ${value} does not fit into a 64-bit signed integer.`);
|
|
4456
|
-
}
|
|
4457
|
-
return { $integer: bigIntToBase64(value) };
|
|
4458
|
-
}
|
|
4459
|
-
if (typeof value === "number") {
|
|
4460
|
-
if (isSpecial(value)) {
|
|
4461
|
-
const buffer = new ArrayBuffer(8);
|
|
4462
|
-
new DataView(buffer).setFloat64(0, value, LITTLE_ENDIAN);
|
|
4463
|
-
return { $float: fromByteArray(new Uint8Array(buffer)) };
|
|
4464
|
-
} else {
|
|
4465
|
-
return value;
|
|
4466
|
-
}
|
|
4467
|
-
}
|
|
4468
|
-
if (typeof value === "boolean") {
|
|
4469
|
-
return value;
|
|
4470
|
-
}
|
|
4471
|
-
if (typeof value === "string") {
|
|
4472
|
-
return value;
|
|
4473
|
-
}
|
|
4474
|
-
if (value instanceof ArrayBuffer) {
|
|
4475
|
-
return { $bytes: fromByteArray(new Uint8Array(value)) };
|
|
4476
|
-
}
|
|
4477
|
-
if (Array.isArray(value)) {
|
|
4478
|
-
return value.map((value2, i22) => convexToJsonInternal(value2, originalValue, context + `[${i22}]`, false));
|
|
4479
|
-
}
|
|
4480
|
-
if (value instanceof Set) {
|
|
4481
|
-
throw new Error(errorMessageForUnsupportedType(context, "Set", [...value], originalValue));
|
|
4482
|
-
}
|
|
4483
|
-
if (value instanceof Map) {
|
|
4484
|
-
throw new Error(errorMessageForUnsupportedType(context, "Map", [...value], originalValue));
|
|
4485
|
-
}
|
|
4486
|
-
if (!isSimpleObject(value)) {
|
|
4487
|
-
const theType = value?.constructor?.name;
|
|
4488
|
-
const typeName = theType ? `${theType} ` : "";
|
|
4489
|
-
throw new Error(errorMessageForUnsupportedType(context, typeName, value, originalValue));
|
|
4490
|
-
}
|
|
4491
|
-
const out = {};
|
|
4492
|
-
const entries = Object.entries(value);
|
|
4493
|
-
entries.sort(([k1, _v1], [k2, _v2]) => k1 === k2 ? 0 : k1 < k2 ? -1 : 1);
|
|
4494
|
-
for (const [k, v2] of entries) {
|
|
4495
|
-
if (v2 !== undefined) {
|
|
4496
|
-
validateObjectField(k);
|
|
4497
|
-
out[k] = convexToJsonInternal(v2, originalValue, context + `.${k}`, false);
|
|
4498
|
-
} else if (includeTopLevelUndefined) {
|
|
4499
|
-
validateObjectField(k);
|
|
4500
|
-
out[k] = convexOrUndefinedToJsonInternal(v2, originalValue, context + `.${k}`);
|
|
4501
|
-
}
|
|
4502
|
-
}
|
|
4503
|
-
return out;
|
|
4504
|
-
}
|
|
4505
|
-
function errorMessageForUnsupportedType(context, typeName, value, originalValue) {
|
|
4506
|
-
if (context) {
|
|
4507
|
-
return `${typeName}${stringifyValueForError(value)} is not a supported Convex type (present at path ${context} in original object ${stringifyValueForError(originalValue)}). To learn about Convex's supported types, see https://docs.convex.dev/using/types.`;
|
|
4508
|
-
} else {
|
|
4509
|
-
return `${typeName}${stringifyValueForError(value)} is not a supported Convex type.`;
|
|
4510
|
-
}
|
|
4511
|
-
}
|
|
4512
|
-
function convexOrUndefinedToJsonInternal(value, originalValue, context) {
|
|
4513
|
-
if (value === undefined) {
|
|
4514
|
-
return { $undefined: null };
|
|
4515
|
-
} else {
|
|
4516
|
-
if (originalValue === undefined) {
|
|
4517
|
-
throw new Error(`Programming error. Current value is ${stringifyValueForError(value)} but original value is undefined`);
|
|
4518
|
-
}
|
|
4519
|
-
return convexToJsonInternal(value, originalValue, context, false);
|
|
4520
|
-
}
|
|
4521
|
-
}
|
|
4522
|
-
function convexToJson(value) {
|
|
4523
|
-
return convexToJsonInternal(value, value, "", false);
|
|
4524
|
-
}
|
|
4199
|
+
init_values();
|
|
4525
4200
|
function documentIdKey(id) {
|
|
4526
4201
|
return `${id.table}:${id.internalId}`;
|
|
4527
4202
|
}
|
|
@@ -4767,7 +4442,7 @@ function decodeIndexId(indexId) {
|
|
|
4767
4442
|
}
|
|
4768
4443
|
init_schema_service();
|
|
4769
4444
|
init_index_key_codec();
|
|
4770
|
-
function
|
|
4445
|
+
function isSimpleObject3(value) {
|
|
4771
4446
|
const isObject = typeof value === "object" && value !== null;
|
|
4772
4447
|
if (!isObject)
|
|
4773
4448
|
return false;
|
|
@@ -4781,7 +4456,7 @@ function evaluateFieldPath(fieldPath, document) {
|
|
|
4781
4456
|
for (const part of parts) {
|
|
4782
4457
|
if (current == null)
|
|
4783
4458
|
return;
|
|
4784
|
-
if (!
|
|
4459
|
+
if (!isSimpleObject3(current))
|
|
4785
4460
|
return;
|
|
4786
4461
|
current = current[part];
|
|
4787
4462
|
}
|
|
@@ -4807,6 +4482,19 @@ function parseDeveloperId(developerId) {
|
|
|
4807
4482
|
}
|
|
4808
4483
|
return { table: parts.table, internalId: parts.internalId };
|
|
4809
4484
|
}
|
|
4485
|
+
function parseStorageId(storageId) {
|
|
4486
|
+
const parsed = parseDeveloperId(storageId);
|
|
4487
|
+
if (parsed) {
|
|
4488
|
+
return parsed;
|
|
4489
|
+
}
|
|
4490
|
+
if (storageId.length === INTERNAL_ID_LENGTH * 2 && /^[0-9a-fA-F]+$/.test(storageId)) {
|
|
4491
|
+
return {
|
|
4492
|
+
table: stringToHex("_storage"),
|
|
4493
|
+
internalId: storageId.toLowerCase()
|
|
4494
|
+
};
|
|
4495
|
+
}
|
|
4496
|
+
return null;
|
|
4497
|
+
}
|
|
4810
4498
|
function isTablePlaceholder(table) {
|
|
4811
4499
|
return table.startsWith("#");
|
|
4812
4500
|
}
|
|
@@ -5249,19 +4937,19 @@ class BlobStoreGateway {
|
|
|
5249
4937
|
if (!this.storage) {
|
|
5250
4938
|
return null;
|
|
5251
4939
|
}
|
|
5252
|
-
const docId =
|
|
4940
|
+
const docId = parseStorageId(storageId);
|
|
5253
4941
|
if (!docId) {
|
|
5254
|
-
console.
|
|
4942
|
+
console.debug(`[BlobStoreGateway] Failed to parse storage ID: ${storageId}`);
|
|
5255
4943
|
return null;
|
|
5256
4944
|
}
|
|
5257
4945
|
const docValue = await this.queryRuntime.getVisibleDocumentById(storageId, docId);
|
|
5258
4946
|
if (!docValue) {
|
|
5259
|
-
console.
|
|
4947
|
+
console.debug(`[BlobStoreGateway] Document not found for storage ID: ${storageId} (table: ${docId.table}, internalId: ${docId.internalId}, ts: ${this.context.snapshotTimestamp})`);
|
|
5260
4948
|
return null;
|
|
5261
4949
|
}
|
|
5262
4950
|
const storedBlob = await this.storage.get(docId.internalId);
|
|
5263
4951
|
if (!storedBlob) {
|
|
5264
|
-
console.
|
|
4952
|
+
console.debug(`[BlobStoreGateway] Blob not found in storage: ${docId.internalId}`);
|
|
5265
4953
|
return null;
|
|
5266
4954
|
}
|
|
5267
4955
|
return storedBlob instanceof Blob ? storedBlob : new Blob([storedBlob]);
|
|
@@ -5270,7 +4958,7 @@ class BlobStoreGateway {
|
|
|
5270
4958
|
if (!this.storage) {
|
|
5271
4959
|
return null;
|
|
5272
4960
|
}
|
|
5273
|
-
const docId =
|
|
4961
|
+
const docId = parseStorageId(storageId);
|
|
5274
4962
|
if (!docId) {
|
|
5275
4963
|
return null;
|
|
5276
4964
|
}
|
|
@@ -5283,7 +4971,7 @@ class BlobStoreGateway {
|
|
|
5283
4971
|
}
|
|
5284
4972
|
async delete(storageId) {
|
|
5285
4973
|
const storage2 = this.requireStorage();
|
|
5286
|
-
const docId =
|
|
4974
|
+
const docId = parseStorageId(storageId);
|
|
5287
4975
|
if (!docId) {
|
|
5288
4976
|
return;
|
|
5289
4977
|
}
|
|
@@ -5342,8 +5030,9 @@ function resolveFunctionTarget(callArgs, currentComponentPath) {
|
|
|
5342
5030
|
return parseFunctionHandleTarget(callArgs.functionHandle);
|
|
5343
5031
|
}
|
|
5344
5032
|
if (callArgs && typeof callArgs.functionHandle === "object" && callArgs.functionHandle !== null) {
|
|
5345
|
-
|
|
5346
|
-
|
|
5033
|
+
const handle = callArgs.functionHandle;
|
|
5034
|
+
if (typeof handle.handle === "string") {
|
|
5035
|
+
return parseFunctionHandleTarget(handle.handle);
|
|
5347
5036
|
}
|
|
5348
5037
|
}
|
|
5349
5038
|
if (callArgs && typeof callArgs.reference === "string") {
|
|
@@ -5438,7 +5127,7 @@ function evaluatePatchValue(value) {
|
|
|
5438
5127
|
if (typeof value === "object" && value !== null && "$undefined" in value) {
|
|
5439
5128
|
return;
|
|
5440
5129
|
}
|
|
5441
|
-
return
|
|
5130
|
+
return jsonToConvex(value);
|
|
5442
5131
|
}
|
|
5443
5132
|
|
|
5444
5133
|
class SchedulerGateway {
|
|
@@ -5459,7 +5148,7 @@ class SchedulerGateway {
|
|
|
5459
5148
|
const docId = { table: tableHex, internalId: internalIdHex, tableNumber };
|
|
5460
5149
|
const developerId = this.context.useConvexIdFormat ? encodeDocumentId(tableNumber, internalIdBytes) : serializeDeveloperId(tableHex, internalIdHex);
|
|
5461
5150
|
const timestamp2 = this.docStore.allocateTimestamp();
|
|
5462
|
-
const argsValue =
|
|
5151
|
+
const argsValue = jsonToConvex(convexToJson(fnArgs));
|
|
5463
5152
|
const formattedName = name.replace(/\.(js|ts|mjs|mts|cjs|cts):/g, ":");
|
|
5464
5153
|
const docToInsert = {
|
|
5465
5154
|
name: formattedName,
|
|
@@ -5583,17 +5272,15 @@ class ActionSyscalls {
|
|
|
5583
5272
|
const type = args.udfType ?? args.type ?? "mutation";
|
|
5584
5273
|
return await this.invocationManager.execute(target.udfPath, udfArguments, type, target.componentPath);
|
|
5585
5274
|
}
|
|
5586
|
-
handleCreateFunctionHandle(args) {
|
|
5275
|
+
async handleCreateFunctionHandle(args) {
|
|
5587
5276
|
const target = resolveFunctionTarget(args, this.context.componentPath);
|
|
5588
5277
|
return formatFunctionHandle(target.componentPath ?? "", target.udfPath);
|
|
5589
5278
|
}
|
|
5590
5279
|
async handleVectorSearch(args) {
|
|
5591
|
-
|
|
5592
|
-
return this.queryRuntime.runVectorSearchAction(vectorQuery);
|
|
5280
|
+
return this.queryRuntime.runVectorSearchAction(args.query);
|
|
5593
5281
|
}
|
|
5594
5282
|
async handleSearchAction(args) {
|
|
5595
|
-
|
|
5596
|
-
return this.queryRuntime.runSearchAction(searchQuery);
|
|
5283
|
+
return this.queryRuntime.runSearchAction(args.query);
|
|
5597
5284
|
}
|
|
5598
5285
|
}
|
|
5599
5286
|
init_values();
|
|
@@ -5654,7 +5341,7 @@ class DatabaseSyscalls {
|
|
|
5654
5341
|
if (typeof table !== "string") {
|
|
5655
5342
|
throw new Error("`table` argument for `insert` must be a string.");
|
|
5656
5343
|
}
|
|
5657
|
-
const convexValue =
|
|
5344
|
+
const convexValue = jsonToConvex(value);
|
|
5658
5345
|
if (typeof convexValue !== "object" || convexValue === null || Array.isArray(convexValue)) {
|
|
5659
5346
|
throw new Error("The document value for `insert` must be an object.");
|
|
5660
5347
|
}
|
|
@@ -5799,7 +5486,7 @@ class DatabaseSyscalls {
|
|
|
5799
5486
|
}
|
|
5800
5487
|
const fullTableName = await resolveTableName(docId, this.context.tableRegistry);
|
|
5801
5488
|
const { tableName: bareTableName } = parseFullTableName(fullTableName);
|
|
5802
|
-
const replaceValue =
|
|
5489
|
+
const replaceValue = jsonToConvex(value);
|
|
5803
5490
|
if (typeof replaceValue !== "object" || replaceValue === null || Array.isArray(replaceValue)) {
|
|
5804
5491
|
throw new Error("The replacement value for `replace` must be an object.");
|
|
5805
5492
|
}
|
|
@@ -5901,6 +5588,8 @@ function decodeJwtClaimsToken(token) {
|
|
|
5901
5588
|
return null;
|
|
5902
5589
|
}
|
|
5903
5590
|
}
|
|
5591
|
+
var DEFAULT_JWKS_CACHE_TTL_MS = 5 * 60 * 1000;
|
|
5592
|
+
var MAX_JWKS_CACHE_TTL_MS = 24 * 60 * 60 * 1000;
|
|
5904
5593
|
var JWKS_CACHE = new Map;
|
|
5905
5594
|
function decodeJwtUnsafe(token) {
|
|
5906
5595
|
if (!token)
|
|
@@ -5981,13 +5670,13 @@ class QuerySyscalls {
|
|
|
5981
5670
|
return { queryId };
|
|
5982
5671
|
}
|
|
5983
5672
|
handleQueryCleanup(args) {
|
|
5984
|
-
const
|
|
5673
|
+
const queryId = args.queryId;
|
|
5985
5674
|
delete this.pendingQueries[queryId];
|
|
5986
5675
|
delete this.queryResults[queryId];
|
|
5987
5676
|
return {};
|
|
5988
5677
|
}
|
|
5989
5678
|
async handleQueryStreamNext(args) {
|
|
5990
|
-
const
|
|
5679
|
+
const queryId = args.queryId;
|
|
5991
5680
|
if (this.pendingQueries[queryId]) {
|
|
5992
5681
|
const query = this.pendingQueries[queryId];
|
|
5993
5682
|
delete this.pendingQueries[queryId];
|
|
@@ -6155,9 +5844,9 @@ class SyscallRouter {
|
|
|
6155
5844
|
throw new Error(`Unknown async syscall: ${op}`);
|
|
6156
5845
|
}
|
|
6157
5846
|
const parsedArgs = JSON.parse(jsonArgs);
|
|
6158
|
-
const args = entry.argsFormat === "convex" ?
|
|
5847
|
+
const args = entry.argsFormat === "convex" ? jsonToConvex(parsedArgs) : parsedArgs;
|
|
6159
5848
|
const result = await entry.handler(args);
|
|
6160
|
-
return JSON.stringify(
|
|
5849
|
+
return JSON.stringify(convexToJson(result));
|
|
6161
5850
|
}
|
|
6162
5851
|
}
|
|
6163
5852
|
|
|
@@ -6713,9 +6402,9 @@ class BaseSqliteDocStore {
|
|
|
6713
6402
|
let dot = 0;
|
|
6714
6403
|
let queryMagnitude = 0;
|
|
6715
6404
|
let docMagnitude = 0;
|
|
6716
|
-
for (let
|
|
6717
|
-
const q = vector[
|
|
6718
|
-
const d = embedding[
|
|
6405
|
+
for (let i2 = 0;i2 < vector.length; i2++) {
|
|
6406
|
+
const q = vector[i2];
|
|
6407
|
+
const d = embedding[i2];
|
|
6719
6408
|
dot += q * d;
|
|
6720
6409
|
queryMagnitude += q * q;
|
|
6721
6410
|
docMagnitude += d * d;
|
|
@@ -6737,6 +6426,30 @@ class BaseSqliteDocStore {
|
|
|
6737
6426
|
return scored.slice(0, limit);
|
|
6738
6427
|
}
|
|
6739
6428
|
}
|
|
6429
|
+
function createSerializedTransactionRunner(hooks) {
|
|
6430
|
+
let queue = Promise.resolve();
|
|
6431
|
+
return async function runInTransaction(fn) {
|
|
6432
|
+
const run = queue.then(async () => {
|
|
6433
|
+
await hooks.begin();
|
|
6434
|
+
try {
|
|
6435
|
+
const result = await fn();
|
|
6436
|
+
await hooks.commit();
|
|
6437
|
+
return result;
|
|
6438
|
+
} catch (error) {
|
|
6439
|
+
try {
|
|
6440
|
+
await hooks.rollback();
|
|
6441
|
+
} catch {}
|
|
6442
|
+
throw error;
|
|
6443
|
+
}
|
|
6444
|
+
});
|
|
6445
|
+
queue = run.then(() => {
|
|
6446
|
+
return;
|
|
6447
|
+
}, () => {
|
|
6448
|
+
return;
|
|
6449
|
+
});
|
|
6450
|
+
return run;
|
|
6451
|
+
};
|
|
6452
|
+
}
|
|
6740
6453
|
// ../core/dist/utils/long.js
|
|
6741
6454
|
class Long2 {
|
|
6742
6455
|
low;
|
|
@@ -6895,8 +6608,20 @@ class BetterSqlite3PreparedStatement {
|
|
|
6895
6608
|
|
|
6896
6609
|
class BetterSqlite3Adapter {
|
|
6897
6610
|
db;
|
|
6611
|
+
runSerializedTransaction;
|
|
6898
6612
|
constructor(db) {
|
|
6899
6613
|
this.db = db;
|
|
6614
|
+
this.runSerializedTransaction = createSerializedTransactionRunner({
|
|
6615
|
+
begin: () => {
|
|
6616
|
+
this.db.exec("BEGIN TRANSACTION");
|
|
6617
|
+
},
|
|
6618
|
+
commit: () => {
|
|
6619
|
+
this.db.exec("COMMIT");
|
|
6620
|
+
},
|
|
6621
|
+
rollback: () => {
|
|
6622
|
+
this.db.exec("ROLLBACK");
|
|
6623
|
+
}
|
|
6624
|
+
});
|
|
6900
6625
|
}
|
|
6901
6626
|
exec(sql) {
|
|
6902
6627
|
this.db.exec(sql);
|
|
@@ -6905,15 +6630,7 @@ class BetterSqlite3Adapter {
|
|
|
6905
6630
|
return new BetterSqlite3PreparedStatement(this.db.prepare(sql));
|
|
6906
6631
|
}
|
|
6907
6632
|
async transaction(fn) {
|
|
6908
|
-
|
|
6909
|
-
this.db.exec("BEGIN TRANSACTION");
|
|
6910
|
-
const result = await fn();
|
|
6911
|
-
this.db.exec("COMMIT");
|
|
6912
|
-
return result;
|
|
6913
|
-
} catch (error) {
|
|
6914
|
-
this.db.exec("ROLLBACK");
|
|
6915
|
-
throw error;
|
|
6916
|
-
}
|
|
6633
|
+
return this.runSerializedTransaction(fn);
|
|
6917
6634
|
}
|
|
6918
6635
|
hexToBuffer(hex) {
|
|
6919
6636
|
return Buffer.from(hexToArrayBuffer3(hex));
|