@concavejs/runtime-cf 0.0.1-alpha.4
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.
Potentially problematic release.
This version of @concavejs/runtime-cf might be problematic. Click here for more details.
- package/README.md +53 -0
- package/dist/index.js +34902 -0
- package/dist/internal.js +3773 -0
- package/package.json +42 -0
package/dist/internal.js
ADDED
|
@@ -0,0 +1,3773 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
set: (newValue) => all[name] = () => newValue
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
13
|
+
|
|
14
|
+
// ../core/node_modules/convex/dist/esm/values/base64.js
|
|
15
|
+
function getLens(b64) {
|
|
16
|
+
var len2 = b64.length;
|
|
17
|
+
if (len2 % 4 > 0) {
|
|
18
|
+
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
19
|
+
}
|
|
20
|
+
var validLen = b64.indexOf("=");
|
|
21
|
+
if (validLen === -1)
|
|
22
|
+
validLen = len2;
|
|
23
|
+
var placeHoldersLen = validLen === len2 ? 0 : 4 - validLen % 4;
|
|
24
|
+
return [validLen, placeHoldersLen];
|
|
25
|
+
}
|
|
26
|
+
function _byteLength(_b64, validLen, placeHoldersLen) {
|
|
27
|
+
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
28
|
+
}
|
|
29
|
+
function toByteArray(b64) {
|
|
30
|
+
var tmp;
|
|
31
|
+
var lens = getLens(b64);
|
|
32
|
+
var validLen = lens[0];
|
|
33
|
+
var placeHoldersLen = lens[1];
|
|
34
|
+
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
|
|
35
|
+
var curByte = 0;
|
|
36
|
+
var len2 = placeHoldersLen > 0 ? validLen - 4 : validLen;
|
|
37
|
+
var i2;
|
|
38
|
+
for (i2 = 0;i2 < len2; i2 += 4) {
|
|
39
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 18 | revLookup[b64.charCodeAt(i2 + 1)] << 12 | revLookup[b64.charCodeAt(i2 + 2)] << 6 | revLookup[b64.charCodeAt(i2 + 3)];
|
|
40
|
+
arr[curByte++] = tmp >> 16 & 255;
|
|
41
|
+
arr[curByte++] = tmp >> 8 & 255;
|
|
42
|
+
arr[curByte++] = tmp & 255;
|
|
43
|
+
}
|
|
44
|
+
if (placeHoldersLen === 2) {
|
|
45
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 2 | revLookup[b64.charCodeAt(i2 + 1)] >> 4;
|
|
46
|
+
arr[curByte++] = tmp & 255;
|
|
47
|
+
}
|
|
48
|
+
if (placeHoldersLen === 1) {
|
|
49
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 10 | revLookup[b64.charCodeAt(i2 + 1)] << 4 | revLookup[b64.charCodeAt(i2 + 2)] >> 2;
|
|
50
|
+
arr[curByte++] = tmp >> 8 & 255;
|
|
51
|
+
arr[curByte++] = tmp & 255;
|
|
52
|
+
}
|
|
53
|
+
return arr;
|
|
54
|
+
}
|
|
55
|
+
function tripletToBase64(num) {
|
|
56
|
+
return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
|
|
57
|
+
}
|
|
58
|
+
function encodeChunk(uint8, start, end) {
|
|
59
|
+
var tmp;
|
|
60
|
+
var output = [];
|
|
61
|
+
for (var i2 = start;i2 < end; i2 += 3) {
|
|
62
|
+
tmp = (uint8[i2] << 16 & 16711680) + (uint8[i2 + 1] << 8 & 65280) + (uint8[i2 + 2] & 255);
|
|
63
|
+
output.push(tripletToBase64(tmp));
|
|
64
|
+
}
|
|
65
|
+
return output.join("");
|
|
66
|
+
}
|
|
67
|
+
function fromByteArray(uint8) {
|
|
68
|
+
var tmp;
|
|
69
|
+
var len2 = uint8.length;
|
|
70
|
+
var extraBytes = len2 % 3;
|
|
71
|
+
var parts = [];
|
|
72
|
+
var maxChunkLength = 16383;
|
|
73
|
+
for (var i2 = 0, len22 = len2 - extraBytes;i2 < len22; i2 += maxChunkLength) {
|
|
74
|
+
parts.push(encodeChunk(uint8, i2, i2 + maxChunkLength > len22 ? len22 : i2 + maxChunkLength));
|
|
75
|
+
}
|
|
76
|
+
if (extraBytes === 1) {
|
|
77
|
+
tmp = uint8[len2 - 1];
|
|
78
|
+
parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "==");
|
|
79
|
+
} else if (extraBytes === 2) {
|
|
80
|
+
tmp = (uint8[len2 - 2] << 8) + uint8[len2 - 1];
|
|
81
|
+
parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "=");
|
|
82
|
+
}
|
|
83
|
+
return parts.join("");
|
|
84
|
+
}
|
|
85
|
+
var lookup, revLookup, Arr, code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", i, len;
|
|
86
|
+
var init_base64 = __esm(() => {
|
|
87
|
+
lookup = [];
|
|
88
|
+
revLookup = [];
|
|
89
|
+
Arr = Uint8Array;
|
|
90
|
+
for (i = 0, len = code.length;i < len; ++i) {
|
|
91
|
+
lookup[i] = code[i];
|
|
92
|
+
revLookup[code.charCodeAt(i)] = i;
|
|
93
|
+
}
|
|
94
|
+
revLookup[45] = 62;
|
|
95
|
+
revLookup[95] = 63;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// ../core/node_modules/convex/dist/esm/common/index.js
|
|
99
|
+
function parseArgs(args) {
|
|
100
|
+
if (args === undefined) {
|
|
101
|
+
return {};
|
|
102
|
+
}
|
|
103
|
+
if (!isSimpleObject(args)) {
|
|
104
|
+
throw new Error(`The arguments to a Convex function must be an object. Received: ${args}`);
|
|
105
|
+
}
|
|
106
|
+
return args;
|
|
107
|
+
}
|
|
108
|
+
function isSimpleObject(value) {
|
|
109
|
+
const isObject = typeof value === "object";
|
|
110
|
+
const prototype = Object.getPrototypeOf(value);
|
|
111
|
+
const isSimple = prototype === null || prototype === Object.prototype || prototype?.constructor?.name === "Object";
|
|
112
|
+
return isObject && isSimple;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// ../core/node_modules/convex/dist/esm/values/value.js
|
|
116
|
+
function isSpecial(n) {
|
|
117
|
+
return Number.isNaN(n) || !Number.isFinite(n) || Object.is(n, -0);
|
|
118
|
+
}
|
|
119
|
+
function slowBigIntToBase64(value) {
|
|
120
|
+
if (value < ZERO) {
|
|
121
|
+
value -= MIN_INT64 + MIN_INT64;
|
|
122
|
+
}
|
|
123
|
+
let hex = value.toString(16);
|
|
124
|
+
if (hex.length % 2 === 1)
|
|
125
|
+
hex = "0" + hex;
|
|
126
|
+
const bytes = new Uint8Array(new ArrayBuffer(8));
|
|
127
|
+
let i2 = 0;
|
|
128
|
+
for (const hexByte of hex.match(/.{2}/g).reverse()) {
|
|
129
|
+
bytes.set([parseInt(hexByte, 16)], i2++);
|
|
130
|
+
value >>= EIGHT;
|
|
131
|
+
}
|
|
132
|
+
return fromByteArray(bytes);
|
|
133
|
+
}
|
|
134
|
+
function slowBase64ToBigInt(encoded) {
|
|
135
|
+
const integerBytes = toByteArray(encoded);
|
|
136
|
+
if (integerBytes.byteLength !== 8) {
|
|
137
|
+
throw new Error(`Received ${integerBytes.byteLength} bytes, expected 8 for $integer`);
|
|
138
|
+
}
|
|
139
|
+
let value = ZERO;
|
|
140
|
+
let power = ZERO;
|
|
141
|
+
for (const byte of integerBytes) {
|
|
142
|
+
value += BigInt(byte) * TWOFIFTYSIX ** power;
|
|
143
|
+
power++;
|
|
144
|
+
}
|
|
145
|
+
if (value > MAX_INT64) {
|
|
146
|
+
value += MIN_INT64 + MIN_INT64;
|
|
147
|
+
}
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
function modernBigIntToBase64(value) {
|
|
151
|
+
if (value < MIN_INT64 || MAX_INT64 < value) {
|
|
152
|
+
throw new Error(`BigInt ${value} does not fit into a 64-bit signed integer.`);
|
|
153
|
+
}
|
|
154
|
+
const buffer = new ArrayBuffer(8);
|
|
155
|
+
new DataView(buffer).setBigInt64(0, value, true);
|
|
156
|
+
return fromByteArray(new Uint8Array(buffer));
|
|
157
|
+
}
|
|
158
|
+
function modernBase64ToBigInt(encoded) {
|
|
159
|
+
const integerBytes = toByteArray(encoded);
|
|
160
|
+
if (integerBytes.byteLength !== 8) {
|
|
161
|
+
throw new Error(`Received ${integerBytes.byteLength} bytes, expected 8 for $integer`);
|
|
162
|
+
}
|
|
163
|
+
const intBytesView = new DataView(integerBytes.buffer);
|
|
164
|
+
return intBytesView.getBigInt64(0, true);
|
|
165
|
+
}
|
|
166
|
+
function validateObjectField(k) {
|
|
167
|
+
if (k.length > MAX_IDENTIFIER_LEN) {
|
|
168
|
+
throw new Error(`Field name ${k} exceeds maximum field name length ${MAX_IDENTIFIER_LEN}.`);
|
|
169
|
+
}
|
|
170
|
+
if (k.startsWith("$")) {
|
|
171
|
+
throw new Error(`Field name ${k} starts with a '$', which is reserved.`);
|
|
172
|
+
}
|
|
173
|
+
for (let i2 = 0;i2 < k.length; i2 += 1) {
|
|
174
|
+
const charCode = k.charCodeAt(i2);
|
|
175
|
+
if (charCode < 32 || charCode >= 127) {
|
|
176
|
+
throw new Error(`Field name ${k} has invalid character '${k[i2]}': Field names can only contain non-control ASCII characters`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function jsonToConvex(value) {
|
|
181
|
+
if (value === null) {
|
|
182
|
+
return value;
|
|
183
|
+
}
|
|
184
|
+
if (typeof value === "boolean") {
|
|
185
|
+
return value;
|
|
186
|
+
}
|
|
187
|
+
if (typeof value === "number") {
|
|
188
|
+
return value;
|
|
189
|
+
}
|
|
190
|
+
if (typeof value === "string") {
|
|
191
|
+
return value;
|
|
192
|
+
}
|
|
193
|
+
if (Array.isArray(value)) {
|
|
194
|
+
return value.map((value2) => jsonToConvex(value2));
|
|
195
|
+
}
|
|
196
|
+
if (typeof value !== "object") {
|
|
197
|
+
throw new Error(`Unexpected type of ${value}`);
|
|
198
|
+
}
|
|
199
|
+
const entries = Object.entries(value);
|
|
200
|
+
if (entries.length === 1) {
|
|
201
|
+
const key = entries[0][0];
|
|
202
|
+
if (key === "$bytes") {
|
|
203
|
+
if (typeof value.$bytes !== "string") {
|
|
204
|
+
throw new Error(`Malformed $bytes field on ${value}`);
|
|
205
|
+
}
|
|
206
|
+
return toByteArray(value.$bytes).buffer;
|
|
207
|
+
}
|
|
208
|
+
if (key === "$integer") {
|
|
209
|
+
if (typeof value.$integer !== "string") {
|
|
210
|
+
throw new Error(`Malformed $integer field on ${value}`);
|
|
211
|
+
}
|
|
212
|
+
return base64ToBigInt(value.$integer);
|
|
213
|
+
}
|
|
214
|
+
if (key === "$float") {
|
|
215
|
+
if (typeof value.$float !== "string") {
|
|
216
|
+
throw new Error(`Malformed $float field on ${value}`);
|
|
217
|
+
}
|
|
218
|
+
const floatBytes = toByteArray(value.$float);
|
|
219
|
+
if (floatBytes.byteLength !== 8) {
|
|
220
|
+
throw new Error(`Received ${floatBytes.byteLength} bytes, expected 8 for $float`);
|
|
221
|
+
}
|
|
222
|
+
const floatBytesView = new DataView(floatBytes.buffer);
|
|
223
|
+
const float = floatBytesView.getFloat64(0, LITTLE_ENDIAN);
|
|
224
|
+
if (!isSpecial(float)) {
|
|
225
|
+
throw new Error(`Float ${float} should be encoded as a number`);
|
|
226
|
+
}
|
|
227
|
+
return float;
|
|
228
|
+
}
|
|
229
|
+
if (key === "$set") {
|
|
230
|
+
throw new Error(`Received a Set which is no longer supported as a Convex type.`);
|
|
231
|
+
}
|
|
232
|
+
if (key === "$map") {
|
|
233
|
+
throw new Error(`Received a Map which is no longer supported as a Convex type.`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const out = {};
|
|
237
|
+
for (const [k, v] of Object.entries(value)) {
|
|
238
|
+
validateObjectField(k);
|
|
239
|
+
out[k] = jsonToConvex(v);
|
|
240
|
+
}
|
|
241
|
+
return out;
|
|
242
|
+
}
|
|
243
|
+
function stringifyValueForError(value) {
|
|
244
|
+
const str = JSON.stringify(value, (_key, value2) => {
|
|
245
|
+
if (value2 === undefined) {
|
|
246
|
+
return "undefined";
|
|
247
|
+
}
|
|
248
|
+
if (typeof value2 === "bigint") {
|
|
249
|
+
return `${value2.toString()}n`;
|
|
250
|
+
}
|
|
251
|
+
return value2;
|
|
252
|
+
});
|
|
253
|
+
if (str.length > MAX_VALUE_FOR_ERROR_LEN) {
|
|
254
|
+
const rest = "[...truncated]";
|
|
255
|
+
let truncateAt = MAX_VALUE_FOR_ERROR_LEN - rest.length;
|
|
256
|
+
const codePoint = str.codePointAt(truncateAt - 1);
|
|
257
|
+
if (codePoint !== undefined && codePoint > 65535) {
|
|
258
|
+
truncateAt -= 1;
|
|
259
|
+
}
|
|
260
|
+
return str.substring(0, truncateAt) + rest;
|
|
261
|
+
}
|
|
262
|
+
return str;
|
|
263
|
+
}
|
|
264
|
+
function convexToJsonInternal(value, originalValue, context, includeTopLevelUndefined) {
|
|
265
|
+
if (value === undefined) {
|
|
266
|
+
const contextText = context && ` (present at path ${context} in original object ${stringifyValueForError(originalValue)})`;
|
|
267
|
+
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.`);
|
|
268
|
+
}
|
|
269
|
+
if (value === null) {
|
|
270
|
+
return value;
|
|
271
|
+
}
|
|
272
|
+
if (typeof value === "bigint") {
|
|
273
|
+
if (value < MIN_INT64 || MAX_INT64 < value) {
|
|
274
|
+
throw new Error(`BigInt ${value} does not fit into a 64-bit signed integer.`);
|
|
275
|
+
}
|
|
276
|
+
return { $integer: bigIntToBase64(value) };
|
|
277
|
+
}
|
|
278
|
+
if (typeof value === "number") {
|
|
279
|
+
if (isSpecial(value)) {
|
|
280
|
+
const buffer = new ArrayBuffer(8);
|
|
281
|
+
new DataView(buffer).setFloat64(0, value, LITTLE_ENDIAN);
|
|
282
|
+
return { $float: fromByteArray(new Uint8Array(buffer)) };
|
|
283
|
+
} else {
|
|
284
|
+
return value;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (typeof value === "boolean") {
|
|
288
|
+
return value;
|
|
289
|
+
}
|
|
290
|
+
if (typeof value === "string") {
|
|
291
|
+
return value;
|
|
292
|
+
}
|
|
293
|
+
if (value instanceof ArrayBuffer) {
|
|
294
|
+
return { $bytes: fromByteArray(new Uint8Array(value)) };
|
|
295
|
+
}
|
|
296
|
+
if (Array.isArray(value)) {
|
|
297
|
+
return value.map((value2, i2) => convexToJsonInternal(value2, originalValue, context + `[${i2}]`, false));
|
|
298
|
+
}
|
|
299
|
+
if (value instanceof Set) {
|
|
300
|
+
throw new Error(errorMessageForUnsupportedType(context, "Set", [...value], originalValue));
|
|
301
|
+
}
|
|
302
|
+
if (value instanceof Map) {
|
|
303
|
+
throw new Error(errorMessageForUnsupportedType(context, "Map", [...value], originalValue));
|
|
304
|
+
}
|
|
305
|
+
if (!isSimpleObject(value)) {
|
|
306
|
+
const theType = value?.constructor?.name;
|
|
307
|
+
const typeName = theType ? `${theType} ` : "";
|
|
308
|
+
throw new Error(errorMessageForUnsupportedType(context, typeName, value, originalValue));
|
|
309
|
+
}
|
|
310
|
+
const out = {};
|
|
311
|
+
const entries = Object.entries(value);
|
|
312
|
+
entries.sort(([k1, _v1], [k2, _v2]) => k1 === k2 ? 0 : k1 < k2 ? -1 : 1);
|
|
313
|
+
for (const [k, v] of entries) {
|
|
314
|
+
if (v !== undefined) {
|
|
315
|
+
validateObjectField(k);
|
|
316
|
+
out[k] = convexToJsonInternal(v, originalValue, context + `.${k}`, false);
|
|
317
|
+
} else if (includeTopLevelUndefined) {
|
|
318
|
+
validateObjectField(k);
|
|
319
|
+
out[k] = convexOrUndefinedToJsonInternal(v, originalValue, context + `.${k}`);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return out;
|
|
323
|
+
}
|
|
324
|
+
function errorMessageForUnsupportedType(context, typeName, value, originalValue) {
|
|
325
|
+
if (context) {
|
|
326
|
+
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.`;
|
|
327
|
+
} else {
|
|
328
|
+
return `${typeName}${stringifyValueForError(value)} is not a supported Convex type.`;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
function convexOrUndefinedToJsonInternal(value, originalValue, context) {
|
|
332
|
+
if (value === undefined) {
|
|
333
|
+
return { $undefined: null };
|
|
334
|
+
} else {
|
|
335
|
+
if (originalValue === undefined) {
|
|
336
|
+
throw new Error(`Programming error. Current value is ${stringifyValueForError(value)} but original value is undefined`);
|
|
337
|
+
}
|
|
338
|
+
return convexToJsonInternal(value, originalValue, context, false);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
function convexToJson(value) {
|
|
342
|
+
return convexToJsonInternal(value, value, "", false);
|
|
343
|
+
}
|
|
344
|
+
function convexOrUndefinedToJson(value) {
|
|
345
|
+
return convexOrUndefinedToJsonInternal(value, value, "");
|
|
346
|
+
}
|
|
347
|
+
function patchValueToJson(value) {
|
|
348
|
+
return convexToJsonInternal(value, value, "", true);
|
|
349
|
+
}
|
|
350
|
+
var LITTLE_ENDIAN = true, MIN_INT64, MAX_INT64, ZERO, EIGHT, TWOFIFTYSIX, bigIntToBase64, base64ToBigInt, MAX_IDENTIFIER_LEN = 1024, MAX_VALUE_FOR_ERROR_LEN = 16384;
|
|
351
|
+
var init_value = __esm(() => {
|
|
352
|
+
init_base64();
|
|
353
|
+
MIN_INT64 = BigInt("-9223372036854775808");
|
|
354
|
+
MAX_INT64 = BigInt("9223372036854775807");
|
|
355
|
+
ZERO = BigInt("0");
|
|
356
|
+
EIGHT = BigInt("8");
|
|
357
|
+
TWOFIFTYSIX = BigInt("256");
|
|
358
|
+
bigIntToBase64 = DataView.prototype.setBigInt64 ? modernBigIntToBase64 : slowBigIntToBase64;
|
|
359
|
+
base64ToBigInt = DataView.prototype.getBigInt64 ? modernBase64ToBigInt : slowBase64ToBigInt;
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
// ../core/node_modules/convex/dist/esm/values/validators.js
|
|
363
|
+
function throwUndefinedValidatorError(context, fieldName) {
|
|
364
|
+
const fieldInfo = fieldName !== undefined ? ` for field "${fieldName}"` : "";
|
|
365
|
+
throw new Error(`A validator is undefined${fieldInfo} in ${context}. This is often caused by circular imports. See ${UNDEFINED_VALIDATOR_ERROR_URL} for details.`);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
class BaseValidator {
|
|
369
|
+
constructor({ isOptional }) {
|
|
370
|
+
__publicField(this, "type");
|
|
371
|
+
__publicField(this, "fieldPaths");
|
|
372
|
+
__publicField(this, "isOptional");
|
|
373
|
+
__publicField(this, "isConvexValidator");
|
|
374
|
+
this.isOptional = isOptional;
|
|
375
|
+
this.isConvexValidator = true;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
var __defProp2, __defNormalProp = (obj, key, value) => (key in obj) ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value, __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value), UNDEFINED_VALIDATOR_ERROR_URL = "https://docs.convex.dev/error#undefined-validator", VId, VFloat64, VInt64, VBoolean, VBytes, VString, VNull, VAny, VObject, VLiteral, VArray, VRecord, VUnion;
|
|
379
|
+
var init_validators = __esm(() => {
|
|
380
|
+
init_value();
|
|
381
|
+
__defProp2 = Object.defineProperty;
|
|
382
|
+
VId = class VId extends BaseValidator {
|
|
383
|
+
constructor({
|
|
384
|
+
isOptional,
|
|
385
|
+
tableName
|
|
386
|
+
}) {
|
|
387
|
+
super({ isOptional });
|
|
388
|
+
__publicField(this, "tableName");
|
|
389
|
+
__publicField(this, "kind", "id");
|
|
390
|
+
if (typeof tableName !== "string") {
|
|
391
|
+
throw new Error("v.id(tableName) requires a string");
|
|
392
|
+
}
|
|
393
|
+
this.tableName = tableName;
|
|
394
|
+
}
|
|
395
|
+
get json() {
|
|
396
|
+
return { type: "id", tableName: this.tableName };
|
|
397
|
+
}
|
|
398
|
+
asOptional() {
|
|
399
|
+
return new VId({
|
|
400
|
+
isOptional: "optional",
|
|
401
|
+
tableName: this.tableName
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
VFloat64 = class VFloat64 extends BaseValidator {
|
|
406
|
+
constructor() {
|
|
407
|
+
super(...arguments);
|
|
408
|
+
__publicField(this, "kind", "float64");
|
|
409
|
+
}
|
|
410
|
+
get json() {
|
|
411
|
+
return { type: "number" };
|
|
412
|
+
}
|
|
413
|
+
asOptional() {
|
|
414
|
+
return new VFloat64({
|
|
415
|
+
isOptional: "optional"
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
VInt64 = class VInt64 extends BaseValidator {
|
|
420
|
+
constructor() {
|
|
421
|
+
super(...arguments);
|
|
422
|
+
__publicField(this, "kind", "int64");
|
|
423
|
+
}
|
|
424
|
+
get json() {
|
|
425
|
+
return { type: "bigint" };
|
|
426
|
+
}
|
|
427
|
+
asOptional() {
|
|
428
|
+
return new VInt64({ isOptional: "optional" });
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
VBoolean = class VBoolean extends BaseValidator {
|
|
432
|
+
constructor() {
|
|
433
|
+
super(...arguments);
|
|
434
|
+
__publicField(this, "kind", "boolean");
|
|
435
|
+
}
|
|
436
|
+
get json() {
|
|
437
|
+
return { type: this.kind };
|
|
438
|
+
}
|
|
439
|
+
asOptional() {
|
|
440
|
+
return new VBoolean({
|
|
441
|
+
isOptional: "optional"
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
VBytes = class VBytes extends BaseValidator {
|
|
446
|
+
constructor() {
|
|
447
|
+
super(...arguments);
|
|
448
|
+
__publicField(this, "kind", "bytes");
|
|
449
|
+
}
|
|
450
|
+
get json() {
|
|
451
|
+
return { type: this.kind };
|
|
452
|
+
}
|
|
453
|
+
asOptional() {
|
|
454
|
+
return new VBytes({ isOptional: "optional" });
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
VString = class VString extends BaseValidator {
|
|
458
|
+
constructor() {
|
|
459
|
+
super(...arguments);
|
|
460
|
+
__publicField(this, "kind", "string");
|
|
461
|
+
}
|
|
462
|
+
get json() {
|
|
463
|
+
return { type: this.kind };
|
|
464
|
+
}
|
|
465
|
+
asOptional() {
|
|
466
|
+
return new VString({
|
|
467
|
+
isOptional: "optional"
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
VNull = class VNull extends BaseValidator {
|
|
472
|
+
constructor() {
|
|
473
|
+
super(...arguments);
|
|
474
|
+
__publicField(this, "kind", "null");
|
|
475
|
+
}
|
|
476
|
+
get json() {
|
|
477
|
+
return { type: this.kind };
|
|
478
|
+
}
|
|
479
|
+
asOptional() {
|
|
480
|
+
return new VNull({ isOptional: "optional" });
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
VAny = class VAny extends BaseValidator {
|
|
484
|
+
constructor() {
|
|
485
|
+
super(...arguments);
|
|
486
|
+
__publicField(this, "kind", "any");
|
|
487
|
+
}
|
|
488
|
+
get json() {
|
|
489
|
+
return {
|
|
490
|
+
type: this.kind
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
asOptional() {
|
|
494
|
+
return new VAny({
|
|
495
|
+
isOptional: "optional"
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
VObject = class VObject extends BaseValidator {
|
|
500
|
+
constructor({
|
|
501
|
+
isOptional,
|
|
502
|
+
fields
|
|
503
|
+
}) {
|
|
504
|
+
super({ isOptional });
|
|
505
|
+
__publicField(this, "fields");
|
|
506
|
+
__publicField(this, "kind", "object");
|
|
507
|
+
globalThis.Object.entries(fields).forEach(([fieldName, validator]) => {
|
|
508
|
+
if (validator === undefined) {
|
|
509
|
+
throwUndefinedValidatorError("v.object()", fieldName);
|
|
510
|
+
}
|
|
511
|
+
if (!validator.isConvexValidator) {
|
|
512
|
+
throw new Error("v.object() entries must be validators");
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
this.fields = fields;
|
|
516
|
+
}
|
|
517
|
+
get json() {
|
|
518
|
+
return {
|
|
519
|
+
type: this.kind,
|
|
520
|
+
value: globalThis.Object.fromEntries(globalThis.Object.entries(this.fields).map(([k, v]) => [
|
|
521
|
+
k,
|
|
522
|
+
{
|
|
523
|
+
fieldType: v.json,
|
|
524
|
+
optional: v.isOptional === "optional" ? true : false
|
|
525
|
+
}
|
|
526
|
+
]))
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
asOptional() {
|
|
530
|
+
return new VObject({
|
|
531
|
+
isOptional: "optional",
|
|
532
|
+
fields: this.fields
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
omit(...fields) {
|
|
536
|
+
const newFields = { ...this.fields };
|
|
537
|
+
for (const field of fields) {
|
|
538
|
+
delete newFields[field];
|
|
539
|
+
}
|
|
540
|
+
return new VObject({
|
|
541
|
+
isOptional: this.isOptional,
|
|
542
|
+
fields: newFields
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
pick(...fields) {
|
|
546
|
+
const newFields = {};
|
|
547
|
+
for (const field of fields) {
|
|
548
|
+
newFields[field] = this.fields[field];
|
|
549
|
+
}
|
|
550
|
+
return new VObject({
|
|
551
|
+
isOptional: this.isOptional,
|
|
552
|
+
fields: newFields
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
partial() {
|
|
556
|
+
const newFields = {};
|
|
557
|
+
for (const [key, validator] of globalThis.Object.entries(this.fields)) {
|
|
558
|
+
newFields[key] = validator.asOptional();
|
|
559
|
+
}
|
|
560
|
+
return new VObject({
|
|
561
|
+
isOptional: this.isOptional,
|
|
562
|
+
fields: newFields
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
extend(fields) {
|
|
566
|
+
return new VObject({
|
|
567
|
+
isOptional: this.isOptional,
|
|
568
|
+
fields: { ...this.fields, ...fields }
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
VLiteral = class VLiteral extends BaseValidator {
|
|
573
|
+
constructor({ isOptional, value }) {
|
|
574
|
+
super({ isOptional });
|
|
575
|
+
__publicField(this, "value");
|
|
576
|
+
__publicField(this, "kind", "literal");
|
|
577
|
+
if (typeof value !== "string" && typeof value !== "boolean" && typeof value !== "number" && typeof value !== "bigint") {
|
|
578
|
+
throw new Error("v.literal(value) must be a string, number, or boolean");
|
|
579
|
+
}
|
|
580
|
+
this.value = value;
|
|
581
|
+
}
|
|
582
|
+
get json() {
|
|
583
|
+
return {
|
|
584
|
+
type: this.kind,
|
|
585
|
+
value: convexToJson(this.value)
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
asOptional() {
|
|
589
|
+
return new VLiteral({
|
|
590
|
+
isOptional: "optional",
|
|
591
|
+
value: this.value
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
VArray = class VArray extends BaseValidator {
|
|
596
|
+
constructor({
|
|
597
|
+
isOptional,
|
|
598
|
+
element
|
|
599
|
+
}) {
|
|
600
|
+
super({ isOptional });
|
|
601
|
+
__publicField(this, "element");
|
|
602
|
+
__publicField(this, "kind", "array");
|
|
603
|
+
if (element === undefined) {
|
|
604
|
+
throwUndefinedValidatorError("v.array()");
|
|
605
|
+
}
|
|
606
|
+
this.element = element;
|
|
607
|
+
}
|
|
608
|
+
get json() {
|
|
609
|
+
return {
|
|
610
|
+
type: this.kind,
|
|
611
|
+
value: this.element.json
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
asOptional() {
|
|
615
|
+
return new VArray({
|
|
616
|
+
isOptional: "optional",
|
|
617
|
+
element: this.element
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
VRecord = class VRecord extends BaseValidator {
|
|
622
|
+
constructor({
|
|
623
|
+
isOptional,
|
|
624
|
+
key,
|
|
625
|
+
value
|
|
626
|
+
}) {
|
|
627
|
+
super({ isOptional });
|
|
628
|
+
__publicField(this, "key");
|
|
629
|
+
__publicField(this, "value");
|
|
630
|
+
__publicField(this, "kind", "record");
|
|
631
|
+
if (key === undefined) {
|
|
632
|
+
throwUndefinedValidatorError("v.record()", "key");
|
|
633
|
+
}
|
|
634
|
+
if (value === undefined) {
|
|
635
|
+
throwUndefinedValidatorError("v.record()", "value");
|
|
636
|
+
}
|
|
637
|
+
if (key.isOptional === "optional") {
|
|
638
|
+
throw new Error("Record validator cannot have optional keys");
|
|
639
|
+
}
|
|
640
|
+
if (value.isOptional === "optional") {
|
|
641
|
+
throw new Error("Record validator cannot have optional values");
|
|
642
|
+
}
|
|
643
|
+
if (!key.isConvexValidator || !value.isConvexValidator) {
|
|
644
|
+
throw new Error("Key and value of v.record() but be validators");
|
|
645
|
+
}
|
|
646
|
+
this.key = key;
|
|
647
|
+
this.value = value;
|
|
648
|
+
}
|
|
649
|
+
get json() {
|
|
650
|
+
return {
|
|
651
|
+
type: this.kind,
|
|
652
|
+
keys: this.key.json,
|
|
653
|
+
values: {
|
|
654
|
+
fieldType: this.value.json,
|
|
655
|
+
optional: false
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
asOptional() {
|
|
660
|
+
return new VRecord({
|
|
661
|
+
isOptional: "optional",
|
|
662
|
+
key: this.key,
|
|
663
|
+
value: this.value
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
VUnion = class VUnion extends BaseValidator {
|
|
668
|
+
constructor({ isOptional, members }) {
|
|
669
|
+
super({ isOptional });
|
|
670
|
+
__publicField(this, "members");
|
|
671
|
+
__publicField(this, "kind", "union");
|
|
672
|
+
members.forEach((member, index) => {
|
|
673
|
+
if (member === undefined) {
|
|
674
|
+
throwUndefinedValidatorError("v.union()", `member at index ${index}`);
|
|
675
|
+
}
|
|
676
|
+
if (!member.isConvexValidator) {
|
|
677
|
+
throw new Error("All members of v.union() must be validators");
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
this.members = members;
|
|
681
|
+
}
|
|
682
|
+
get json() {
|
|
683
|
+
return {
|
|
684
|
+
type: this.kind,
|
|
685
|
+
value: this.members.map((v) => v.json)
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
asOptional() {
|
|
689
|
+
return new VUnion({
|
|
690
|
+
isOptional: "optional",
|
|
691
|
+
members: this.members
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
// ../core/node_modules/convex/dist/esm/values/validator.js
|
|
698
|
+
function isValidator(v2) {
|
|
699
|
+
return !!v2.isConvexValidator;
|
|
700
|
+
}
|
|
701
|
+
function asObjectValidator(obj) {
|
|
702
|
+
if (isValidator(obj)) {
|
|
703
|
+
return obj;
|
|
704
|
+
} else {
|
|
705
|
+
return v.object(obj);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
var v;
|
|
709
|
+
var init_validator = __esm(() => {
|
|
710
|
+
init_validators();
|
|
711
|
+
v = {
|
|
712
|
+
id: (tableName) => {
|
|
713
|
+
return new VId({
|
|
714
|
+
isOptional: "required",
|
|
715
|
+
tableName
|
|
716
|
+
});
|
|
717
|
+
},
|
|
718
|
+
null: () => {
|
|
719
|
+
return new VNull({ isOptional: "required" });
|
|
720
|
+
},
|
|
721
|
+
number: () => {
|
|
722
|
+
return new VFloat64({ isOptional: "required" });
|
|
723
|
+
},
|
|
724
|
+
float64: () => {
|
|
725
|
+
return new VFloat64({ isOptional: "required" });
|
|
726
|
+
},
|
|
727
|
+
bigint: () => {
|
|
728
|
+
return new VInt64({ isOptional: "required" });
|
|
729
|
+
},
|
|
730
|
+
int64: () => {
|
|
731
|
+
return new VInt64({ isOptional: "required" });
|
|
732
|
+
},
|
|
733
|
+
boolean: () => {
|
|
734
|
+
return new VBoolean({ isOptional: "required" });
|
|
735
|
+
},
|
|
736
|
+
string: () => {
|
|
737
|
+
return new VString({ isOptional: "required" });
|
|
738
|
+
},
|
|
739
|
+
bytes: () => {
|
|
740
|
+
return new VBytes({ isOptional: "required" });
|
|
741
|
+
},
|
|
742
|
+
literal: (literal) => {
|
|
743
|
+
return new VLiteral({ isOptional: "required", value: literal });
|
|
744
|
+
},
|
|
745
|
+
array: (element) => {
|
|
746
|
+
return new VArray({ isOptional: "required", element });
|
|
747
|
+
},
|
|
748
|
+
object: (fields) => {
|
|
749
|
+
return new VObject({ isOptional: "required", fields });
|
|
750
|
+
},
|
|
751
|
+
record: (keys, values) => {
|
|
752
|
+
return new VRecord({
|
|
753
|
+
isOptional: "required",
|
|
754
|
+
key: keys,
|
|
755
|
+
value: values
|
|
756
|
+
});
|
|
757
|
+
},
|
|
758
|
+
union: (...members) => {
|
|
759
|
+
return new VUnion({
|
|
760
|
+
isOptional: "required",
|
|
761
|
+
members
|
|
762
|
+
});
|
|
763
|
+
},
|
|
764
|
+
any: () => {
|
|
765
|
+
return new VAny({ isOptional: "required" });
|
|
766
|
+
},
|
|
767
|
+
optional: (value) => {
|
|
768
|
+
return value.asOptional();
|
|
769
|
+
},
|
|
770
|
+
nullable: (value) => {
|
|
771
|
+
return v.union(value, v.null());
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
// ../core/node_modules/convex/dist/esm/values/errors.js
|
|
777
|
+
var __defProp3, __defNormalProp2 = (obj, key, value) => (key in obj) ? __defProp3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value, __publicField2 = (obj, key, value) => __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value), _a, _b, IDENTIFYING_FIELD, ConvexError;
|
|
778
|
+
var init_errors = __esm(() => {
|
|
779
|
+
init_value();
|
|
780
|
+
__defProp3 = Object.defineProperty;
|
|
781
|
+
IDENTIFYING_FIELD = Symbol.for("ConvexError");
|
|
782
|
+
ConvexError = class ConvexError extends (_b = Error, _a = IDENTIFYING_FIELD, _b) {
|
|
783
|
+
constructor(data) {
|
|
784
|
+
super(typeof data === "string" ? data : stringifyValueForError(data));
|
|
785
|
+
__publicField2(this, "name", "ConvexError");
|
|
786
|
+
__publicField2(this, "data");
|
|
787
|
+
__publicField2(this, _a, true);
|
|
788
|
+
this.data = data;
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
});
|
|
792
|
+
|
|
793
|
+
// ../core/node_modules/convex/dist/esm/values/index.js
|
|
794
|
+
var init_values = __esm(() => {
|
|
795
|
+
init_value();
|
|
796
|
+
init_validator();
|
|
797
|
+
init_errors();
|
|
798
|
+
});
|
|
799
|
+
|
|
800
|
+
// ../core/node_modules/convex/dist/esm/index.js
|
|
801
|
+
var version = "1.31.7";
|
|
802
|
+
|
|
803
|
+
// ../core/node_modules/convex/dist/esm/server/impl/syscall.js
|
|
804
|
+
function performSyscall(op, arg) {
|
|
805
|
+
if (typeof Convex === "undefined" || Convex.syscall === undefined) {
|
|
806
|
+
throw new Error("The Convex database and auth objects are being used outside of a Convex backend. Did you mean to use `useQuery` or `useMutation` to call a Convex function?");
|
|
807
|
+
}
|
|
808
|
+
const resultStr = Convex.syscall(op, JSON.stringify(arg));
|
|
809
|
+
return JSON.parse(resultStr);
|
|
810
|
+
}
|
|
811
|
+
async function performAsyncSyscall(op, arg) {
|
|
812
|
+
if (typeof Convex === "undefined" || Convex.asyncSyscall === undefined) {
|
|
813
|
+
throw new Error("The Convex database and auth objects are being used outside of a Convex backend. Did you mean to use `useQuery` or `useMutation` to call a Convex function?");
|
|
814
|
+
}
|
|
815
|
+
let resultStr;
|
|
816
|
+
try {
|
|
817
|
+
resultStr = await Convex.asyncSyscall(op, JSON.stringify(arg));
|
|
818
|
+
} catch (e) {
|
|
819
|
+
if (e.data !== undefined) {
|
|
820
|
+
const rethrown = new ConvexError(e.message);
|
|
821
|
+
rethrown.data = jsonToConvex(e.data);
|
|
822
|
+
throw rethrown;
|
|
823
|
+
}
|
|
824
|
+
throw new Error(e.message);
|
|
825
|
+
}
|
|
826
|
+
return JSON.parse(resultStr);
|
|
827
|
+
}
|
|
828
|
+
var init_syscall = __esm(() => {
|
|
829
|
+
init_errors();
|
|
830
|
+
init_value();
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
// ../core/node_modules/convex/dist/esm/server/functionName.js
|
|
834
|
+
var functionName;
|
|
835
|
+
var init_functionName = __esm(() => {
|
|
836
|
+
functionName = Symbol.for("functionName");
|
|
837
|
+
});
|
|
838
|
+
|
|
839
|
+
// ../core/node_modules/convex/dist/esm/server/components/paths.js
|
|
840
|
+
function extractReferencePath(reference) {
|
|
841
|
+
return reference[toReferencePath] ?? null;
|
|
842
|
+
}
|
|
843
|
+
function isFunctionHandle(s) {
|
|
844
|
+
return s.startsWith("function://");
|
|
845
|
+
}
|
|
846
|
+
function getFunctionAddress(functionReference) {
|
|
847
|
+
let functionAddress;
|
|
848
|
+
if (typeof functionReference === "string") {
|
|
849
|
+
if (isFunctionHandle(functionReference)) {
|
|
850
|
+
functionAddress = { functionHandle: functionReference };
|
|
851
|
+
} else {
|
|
852
|
+
functionAddress = { name: functionReference };
|
|
853
|
+
}
|
|
854
|
+
} else if (functionReference[functionName]) {
|
|
855
|
+
functionAddress = { name: functionReference[functionName] };
|
|
856
|
+
} else {
|
|
857
|
+
const referencePath = extractReferencePath(functionReference);
|
|
858
|
+
if (!referencePath) {
|
|
859
|
+
throw new Error(`${functionReference} is not a functionReference`);
|
|
860
|
+
}
|
|
861
|
+
functionAddress = { reference: referencePath };
|
|
862
|
+
}
|
|
863
|
+
return functionAddress;
|
|
864
|
+
}
|
|
865
|
+
var toReferencePath;
|
|
866
|
+
var init_paths = __esm(() => {
|
|
867
|
+
init_functionName();
|
|
868
|
+
toReferencePath = Symbol.for("toReferencePath");
|
|
869
|
+
});
|
|
870
|
+
|
|
871
|
+
// ../core/node_modules/convex/dist/esm/server/impl/validate.js
|
|
872
|
+
function validateArg(arg, idx, method, argName) {
|
|
873
|
+
if (arg === undefined) {
|
|
874
|
+
throw new TypeError(`Must provide arg ${idx} \`${argName}\` to \`${method}\``);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
function validateArgIsNonNegativeInteger(arg, idx, method, argName) {
|
|
878
|
+
if (!Number.isInteger(arg) || arg < 0) {
|
|
879
|
+
throw new TypeError(`Arg ${idx} \`${argName}\` to \`${method}\` must be a non-negative integer`);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
// ../core/node_modules/convex/dist/esm/server/impl/authentication_impl.js
|
|
884
|
+
function setupAuth(requestId) {
|
|
885
|
+
return {
|
|
886
|
+
getUserIdentity: async () => {
|
|
887
|
+
return await performAsyncSyscall("1.0/getUserIdentity", {
|
|
888
|
+
requestId
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
var init_authentication_impl = __esm(() => {
|
|
894
|
+
init_syscall();
|
|
895
|
+
});
|
|
896
|
+
|
|
897
|
+
// ../core/node_modules/convex/dist/esm/server/filter_builder.js
|
|
898
|
+
class Expression {
|
|
899
|
+
constructor() {
|
|
900
|
+
__publicField3(this, "_isExpression");
|
|
901
|
+
__publicField3(this, "_value");
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
var __defProp4, __defNormalProp3 = (obj, key, value) => (key in obj) ? __defProp4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value, __publicField3 = (obj, key, value) => __defNormalProp3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
905
|
+
var init_filter_builder = __esm(() => {
|
|
906
|
+
__defProp4 = Object.defineProperty;
|
|
907
|
+
});
|
|
908
|
+
|
|
909
|
+
// ../core/node_modules/convex/dist/esm/server/impl/filter_builder_impl.js
|
|
910
|
+
function serializeExpression(expr) {
|
|
911
|
+
if (expr instanceof ExpressionImpl) {
|
|
912
|
+
return expr.serialize();
|
|
913
|
+
} else {
|
|
914
|
+
return { $literal: convexOrUndefinedToJson(expr) };
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
var __defProp5, __defNormalProp4 = (obj, key, value) => (key in obj) ? __defProp5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value, __publicField4 = (obj, key, value) => __defNormalProp4(obj, typeof key !== "symbol" ? key + "" : key, value), ExpressionImpl, filterBuilderImpl;
|
|
918
|
+
var init_filter_builder_impl = __esm(() => {
|
|
919
|
+
init_value();
|
|
920
|
+
init_filter_builder();
|
|
921
|
+
__defProp5 = Object.defineProperty;
|
|
922
|
+
ExpressionImpl = class ExpressionImpl extends Expression {
|
|
923
|
+
constructor(inner) {
|
|
924
|
+
super();
|
|
925
|
+
__publicField4(this, "inner");
|
|
926
|
+
this.inner = inner;
|
|
927
|
+
}
|
|
928
|
+
serialize() {
|
|
929
|
+
return this.inner;
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
filterBuilderImpl = {
|
|
933
|
+
eq(l, r) {
|
|
934
|
+
return new ExpressionImpl({
|
|
935
|
+
$eq: [serializeExpression(l), serializeExpression(r)]
|
|
936
|
+
});
|
|
937
|
+
},
|
|
938
|
+
neq(l, r) {
|
|
939
|
+
return new ExpressionImpl({
|
|
940
|
+
$neq: [serializeExpression(l), serializeExpression(r)]
|
|
941
|
+
});
|
|
942
|
+
},
|
|
943
|
+
lt(l, r) {
|
|
944
|
+
return new ExpressionImpl({
|
|
945
|
+
$lt: [serializeExpression(l), serializeExpression(r)]
|
|
946
|
+
});
|
|
947
|
+
},
|
|
948
|
+
lte(l, r) {
|
|
949
|
+
return new ExpressionImpl({
|
|
950
|
+
$lte: [serializeExpression(l), serializeExpression(r)]
|
|
951
|
+
});
|
|
952
|
+
},
|
|
953
|
+
gt(l, r) {
|
|
954
|
+
return new ExpressionImpl({
|
|
955
|
+
$gt: [serializeExpression(l), serializeExpression(r)]
|
|
956
|
+
});
|
|
957
|
+
},
|
|
958
|
+
gte(l, r) {
|
|
959
|
+
return new ExpressionImpl({
|
|
960
|
+
$gte: [serializeExpression(l), serializeExpression(r)]
|
|
961
|
+
});
|
|
962
|
+
},
|
|
963
|
+
add(l, r) {
|
|
964
|
+
return new ExpressionImpl({
|
|
965
|
+
$add: [serializeExpression(l), serializeExpression(r)]
|
|
966
|
+
});
|
|
967
|
+
},
|
|
968
|
+
sub(l, r) {
|
|
969
|
+
return new ExpressionImpl({
|
|
970
|
+
$sub: [serializeExpression(l), serializeExpression(r)]
|
|
971
|
+
});
|
|
972
|
+
},
|
|
973
|
+
mul(l, r) {
|
|
974
|
+
return new ExpressionImpl({
|
|
975
|
+
$mul: [serializeExpression(l), serializeExpression(r)]
|
|
976
|
+
});
|
|
977
|
+
},
|
|
978
|
+
div(l, r) {
|
|
979
|
+
return new ExpressionImpl({
|
|
980
|
+
$div: [serializeExpression(l), serializeExpression(r)]
|
|
981
|
+
});
|
|
982
|
+
},
|
|
983
|
+
mod(l, r) {
|
|
984
|
+
return new ExpressionImpl({
|
|
985
|
+
$mod: [serializeExpression(l), serializeExpression(r)]
|
|
986
|
+
});
|
|
987
|
+
},
|
|
988
|
+
neg(x) {
|
|
989
|
+
return new ExpressionImpl({ $neg: serializeExpression(x) });
|
|
990
|
+
},
|
|
991
|
+
and(...exprs) {
|
|
992
|
+
return new ExpressionImpl({ $and: exprs.map(serializeExpression) });
|
|
993
|
+
},
|
|
994
|
+
or(...exprs) {
|
|
995
|
+
return new ExpressionImpl({ $or: exprs.map(serializeExpression) });
|
|
996
|
+
},
|
|
997
|
+
not(x) {
|
|
998
|
+
return new ExpressionImpl({ $not: serializeExpression(x) });
|
|
999
|
+
},
|
|
1000
|
+
field(fieldPath) {
|
|
1001
|
+
return new ExpressionImpl({ $field: fieldPath });
|
|
1002
|
+
}
|
|
1003
|
+
};
|
|
1004
|
+
});
|
|
1005
|
+
|
|
1006
|
+
// ../core/node_modules/convex/dist/esm/server/index_range_builder.js
|
|
1007
|
+
class IndexRange {
|
|
1008
|
+
constructor() {
|
|
1009
|
+
__publicField5(this, "_isIndexRange");
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
var __defProp6, __defNormalProp5 = (obj, key, value) => (key in obj) ? __defProp6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value, __publicField5 = (obj, key, value) => __defNormalProp5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1013
|
+
var init_index_range_builder = __esm(() => {
|
|
1014
|
+
__defProp6 = Object.defineProperty;
|
|
1015
|
+
});
|
|
1016
|
+
|
|
1017
|
+
// ../core/node_modules/convex/dist/esm/server/impl/index_range_builder_impl.js
|
|
1018
|
+
var __defProp7, __defNormalProp6 = (obj, key, value) => (key in obj) ? __defProp7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value, __publicField6 = (obj, key, value) => __defNormalProp6(obj, typeof key !== "symbol" ? key + "" : key, value), IndexRangeBuilderImpl;
|
|
1019
|
+
var init_index_range_builder_impl = __esm(() => {
|
|
1020
|
+
init_value();
|
|
1021
|
+
init_index_range_builder();
|
|
1022
|
+
__defProp7 = Object.defineProperty;
|
|
1023
|
+
IndexRangeBuilderImpl = class IndexRangeBuilderImpl extends IndexRange {
|
|
1024
|
+
constructor(rangeExpressions) {
|
|
1025
|
+
super();
|
|
1026
|
+
__publicField6(this, "rangeExpressions");
|
|
1027
|
+
__publicField6(this, "isConsumed");
|
|
1028
|
+
this.rangeExpressions = rangeExpressions;
|
|
1029
|
+
this.isConsumed = false;
|
|
1030
|
+
}
|
|
1031
|
+
static new() {
|
|
1032
|
+
return new IndexRangeBuilderImpl([]);
|
|
1033
|
+
}
|
|
1034
|
+
consume() {
|
|
1035
|
+
if (this.isConsumed) {
|
|
1036
|
+
throw new Error("IndexRangeBuilder has already been used! Chain your method calls like `q => q.eq(...).eq(...)`. See https://docs.convex.dev/using/indexes");
|
|
1037
|
+
}
|
|
1038
|
+
this.isConsumed = true;
|
|
1039
|
+
}
|
|
1040
|
+
eq(fieldName, value) {
|
|
1041
|
+
this.consume();
|
|
1042
|
+
return new IndexRangeBuilderImpl(this.rangeExpressions.concat({
|
|
1043
|
+
type: "Eq",
|
|
1044
|
+
fieldPath: fieldName,
|
|
1045
|
+
value: convexOrUndefinedToJson(value)
|
|
1046
|
+
}));
|
|
1047
|
+
}
|
|
1048
|
+
gt(fieldName, value) {
|
|
1049
|
+
this.consume();
|
|
1050
|
+
return new IndexRangeBuilderImpl(this.rangeExpressions.concat({
|
|
1051
|
+
type: "Gt",
|
|
1052
|
+
fieldPath: fieldName,
|
|
1053
|
+
value: convexOrUndefinedToJson(value)
|
|
1054
|
+
}));
|
|
1055
|
+
}
|
|
1056
|
+
gte(fieldName, value) {
|
|
1057
|
+
this.consume();
|
|
1058
|
+
return new IndexRangeBuilderImpl(this.rangeExpressions.concat({
|
|
1059
|
+
type: "Gte",
|
|
1060
|
+
fieldPath: fieldName,
|
|
1061
|
+
value: convexOrUndefinedToJson(value)
|
|
1062
|
+
}));
|
|
1063
|
+
}
|
|
1064
|
+
lt(fieldName, value) {
|
|
1065
|
+
this.consume();
|
|
1066
|
+
return new IndexRangeBuilderImpl(this.rangeExpressions.concat({
|
|
1067
|
+
type: "Lt",
|
|
1068
|
+
fieldPath: fieldName,
|
|
1069
|
+
value: convexOrUndefinedToJson(value)
|
|
1070
|
+
}));
|
|
1071
|
+
}
|
|
1072
|
+
lte(fieldName, value) {
|
|
1073
|
+
this.consume();
|
|
1074
|
+
return new IndexRangeBuilderImpl(this.rangeExpressions.concat({
|
|
1075
|
+
type: "Lte",
|
|
1076
|
+
fieldPath: fieldName,
|
|
1077
|
+
value: convexOrUndefinedToJson(value)
|
|
1078
|
+
}));
|
|
1079
|
+
}
|
|
1080
|
+
export() {
|
|
1081
|
+
this.consume();
|
|
1082
|
+
return this.rangeExpressions;
|
|
1083
|
+
}
|
|
1084
|
+
};
|
|
1085
|
+
});
|
|
1086
|
+
|
|
1087
|
+
// ../core/node_modules/convex/dist/esm/server/search_filter_builder.js
|
|
1088
|
+
class SearchFilter {
|
|
1089
|
+
constructor() {
|
|
1090
|
+
__publicField7(this, "_isSearchFilter");
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
var __defProp8, __defNormalProp7 = (obj, key, value) => (key in obj) ? __defProp8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value, __publicField7 = (obj, key, value) => __defNormalProp7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1094
|
+
var init_search_filter_builder = __esm(() => {
|
|
1095
|
+
__defProp8 = Object.defineProperty;
|
|
1096
|
+
});
|
|
1097
|
+
|
|
1098
|
+
// ../core/node_modules/convex/dist/esm/server/impl/search_filter_builder_impl.js
|
|
1099
|
+
var __defProp9, __defNormalProp8 = (obj, key, value) => (key in obj) ? __defProp9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value, __publicField8 = (obj, key, value) => __defNormalProp8(obj, typeof key !== "symbol" ? key + "" : key, value), SearchFilterBuilderImpl;
|
|
1100
|
+
var init_search_filter_builder_impl = __esm(() => {
|
|
1101
|
+
init_value();
|
|
1102
|
+
init_search_filter_builder();
|
|
1103
|
+
__defProp9 = Object.defineProperty;
|
|
1104
|
+
SearchFilterBuilderImpl = class SearchFilterBuilderImpl extends SearchFilter {
|
|
1105
|
+
constructor(filters) {
|
|
1106
|
+
super();
|
|
1107
|
+
__publicField8(this, "filters");
|
|
1108
|
+
__publicField8(this, "isConsumed");
|
|
1109
|
+
this.filters = filters;
|
|
1110
|
+
this.isConsumed = false;
|
|
1111
|
+
}
|
|
1112
|
+
static new() {
|
|
1113
|
+
return new SearchFilterBuilderImpl([]);
|
|
1114
|
+
}
|
|
1115
|
+
consume() {
|
|
1116
|
+
if (this.isConsumed) {
|
|
1117
|
+
throw new Error("SearchFilterBuilder has already been used! Chain your method calls like `q => q.search(...).eq(...)`.");
|
|
1118
|
+
}
|
|
1119
|
+
this.isConsumed = true;
|
|
1120
|
+
}
|
|
1121
|
+
search(fieldName, query) {
|
|
1122
|
+
validateArg(fieldName, 1, "search", "fieldName");
|
|
1123
|
+
validateArg(query, 2, "search", "query");
|
|
1124
|
+
this.consume();
|
|
1125
|
+
return new SearchFilterBuilderImpl(this.filters.concat({
|
|
1126
|
+
type: "Search",
|
|
1127
|
+
fieldPath: fieldName,
|
|
1128
|
+
value: query
|
|
1129
|
+
}));
|
|
1130
|
+
}
|
|
1131
|
+
eq(fieldName, value) {
|
|
1132
|
+
validateArg(fieldName, 1, "eq", "fieldName");
|
|
1133
|
+
if (arguments.length !== 2) {
|
|
1134
|
+
validateArg(value, 2, "search", "value");
|
|
1135
|
+
}
|
|
1136
|
+
this.consume();
|
|
1137
|
+
return new SearchFilterBuilderImpl(this.filters.concat({
|
|
1138
|
+
type: "Eq",
|
|
1139
|
+
fieldPath: fieldName,
|
|
1140
|
+
value: convexOrUndefinedToJson(value)
|
|
1141
|
+
}));
|
|
1142
|
+
}
|
|
1143
|
+
export() {
|
|
1144
|
+
this.consume();
|
|
1145
|
+
return this.filters;
|
|
1146
|
+
}
|
|
1147
|
+
};
|
|
1148
|
+
});
|
|
1149
|
+
|
|
1150
|
+
// ../core/node_modules/convex/dist/esm/server/impl/query_impl.js
|
|
1151
|
+
function throwClosedError(type) {
|
|
1152
|
+
throw new Error(type === "consumed" ? "This query is closed and can't emit any more values." : "This query has been chained with another operator and can't be reused.");
|
|
1153
|
+
}
|
|
1154
|
+
var __defProp10, __defNormalProp9 = (obj, key, value) => (key in obj) ? __defProp10(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value, __publicField9 = (obj, key, value) => __defNormalProp9(obj, typeof key !== "symbol" ? key + "" : key, value), MAX_QUERY_OPERATORS = 256, QueryInitializerImpl, QueryImpl;
|
|
1155
|
+
var init_query_impl = __esm(() => {
|
|
1156
|
+
init_values();
|
|
1157
|
+
init_syscall();
|
|
1158
|
+
init_filter_builder_impl();
|
|
1159
|
+
init_index_range_builder_impl();
|
|
1160
|
+
init_search_filter_builder_impl();
|
|
1161
|
+
__defProp10 = Object.defineProperty;
|
|
1162
|
+
QueryInitializerImpl = class QueryInitializerImpl {
|
|
1163
|
+
constructor(tableName) {
|
|
1164
|
+
__publicField9(this, "tableName");
|
|
1165
|
+
this.tableName = tableName;
|
|
1166
|
+
}
|
|
1167
|
+
withIndex(indexName, indexRange) {
|
|
1168
|
+
validateArg(indexName, 1, "withIndex", "indexName");
|
|
1169
|
+
let rangeBuilder = IndexRangeBuilderImpl.new();
|
|
1170
|
+
if (indexRange !== undefined) {
|
|
1171
|
+
rangeBuilder = indexRange(rangeBuilder);
|
|
1172
|
+
}
|
|
1173
|
+
return new QueryImpl({
|
|
1174
|
+
source: {
|
|
1175
|
+
type: "IndexRange",
|
|
1176
|
+
indexName: this.tableName + "." + indexName,
|
|
1177
|
+
range: rangeBuilder.export(),
|
|
1178
|
+
order: null
|
|
1179
|
+
},
|
|
1180
|
+
operators: []
|
|
1181
|
+
});
|
|
1182
|
+
}
|
|
1183
|
+
withSearchIndex(indexName, searchFilter) {
|
|
1184
|
+
validateArg(indexName, 1, "withSearchIndex", "indexName");
|
|
1185
|
+
validateArg(searchFilter, 2, "withSearchIndex", "searchFilter");
|
|
1186
|
+
const searchFilterBuilder = SearchFilterBuilderImpl.new();
|
|
1187
|
+
return new QueryImpl({
|
|
1188
|
+
source: {
|
|
1189
|
+
type: "Search",
|
|
1190
|
+
indexName: this.tableName + "." + indexName,
|
|
1191
|
+
filters: searchFilter(searchFilterBuilder).export()
|
|
1192
|
+
},
|
|
1193
|
+
operators: []
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
fullTableScan() {
|
|
1197
|
+
return new QueryImpl({
|
|
1198
|
+
source: {
|
|
1199
|
+
type: "FullTableScan",
|
|
1200
|
+
tableName: this.tableName,
|
|
1201
|
+
order: null
|
|
1202
|
+
},
|
|
1203
|
+
operators: []
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
order(order) {
|
|
1207
|
+
return this.fullTableScan().order(order);
|
|
1208
|
+
}
|
|
1209
|
+
async count() {
|
|
1210
|
+
const syscallJSON = await performAsyncSyscall("1.0/count", {
|
|
1211
|
+
table: this.tableName
|
|
1212
|
+
});
|
|
1213
|
+
const syscallResult = jsonToConvex(syscallJSON);
|
|
1214
|
+
return syscallResult;
|
|
1215
|
+
}
|
|
1216
|
+
filter(predicate) {
|
|
1217
|
+
return this.fullTableScan().filter(predicate);
|
|
1218
|
+
}
|
|
1219
|
+
limit(n) {
|
|
1220
|
+
return this.fullTableScan().limit(n);
|
|
1221
|
+
}
|
|
1222
|
+
collect() {
|
|
1223
|
+
return this.fullTableScan().collect();
|
|
1224
|
+
}
|
|
1225
|
+
take(n) {
|
|
1226
|
+
return this.fullTableScan().take(n);
|
|
1227
|
+
}
|
|
1228
|
+
paginate(paginationOpts) {
|
|
1229
|
+
return this.fullTableScan().paginate(paginationOpts);
|
|
1230
|
+
}
|
|
1231
|
+
first() {
|
|
1232
|
+
return this.fullTableScan().first();
|
|
1233
|
+
}
|
|
1234
|
+
unique() {
|
|
1235
|
+
return this.fullTableScan().unique();
|
|
1236
|
+
}
|
|
1237
|
+
[Symbol.asyncIterator]() {
|
|
1238
|
+
return this.fullTableScan()[Symbol.asyncIterator]();
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1241
|
+
QueryImpl = class QueryImpl {
|
|
1242
|
+
constructor(query) {
|
|
1243
|
+
__publicField9(this, "state");
|
|
1244
|
+
__publicField9(this, "tableNameForErrorMessages");
|
|
1245
|
+
this.state = { type: "preparing", query };
|
|
1246
|
+
if (query.source.type === "FullTableScan") {
|
|
1247
|
+
this.tableNameForErrorMessages = query.source.tableName;
|
|
1248
|
+
} else {
|
|
1249
|
+
this.tableNameForErrorMessages = query.source.indexName.split(".")[0];
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
takeQuery() {
|
|
1253
|
+
if (this.state.type !== "preparing") {
|
|
1254
|
+
throw new Error("A query can only be chained once and can't be chained after iteration begins.");
|
|
1255
|
+
}
|
|
1256
|
+
const query = this.state.query;
|
|
1257
|
+
this.state = { type: "closed" };
|
|
1258
|
+
return query;
|
|
1259
|
+
}
|
|
1260
|
+
startQuery() {
|
|
1261
|
+
if (this.state.type === "executing") {
|
|
1262
|
+
throw new Error("Iteration can only begin on a query once.");
|
|
1263
|
+
}
|
|
1264
|
+
if (this.state.type === "closed" || this.state.type === "consumed") {
|
|
1265
|
+
throwClosedError(this.state.type);
|
|
1266
|
+
}
|
|
1267
|
+
const query = this.state.query;
|
|
1268
|
+
const { queryId } = performSyscall("1.0/queryStream", { query, version });
|
|
1269
|
+
this.state = { type: "executing", queryId };
|
|
1270
|
+
return queryId;
|
|
1271
|
+
}
|
|
1272
|
+
closeQuery() {
|
|
1273
|
+
if (this.state.type === "executing") {
|
|
1274
|
+
const queryId = this.state.queryId;
|
|
1275
|
+
performSyscall("1.0/queryCleanup", { queryId });
|
|
1276
|
+
}
|
|
1277
|
+
this.state = { type: "consumed" };
|
|
1278
|
+
}
|
|
1279
|
+
order(order) {
|
|
1280
|
+
validateArg(order, 1, "order", "order");
|
|
1281
|
+
const query = this.takeQuery();
|
|
1282
|
+
if (query.source.type === "Search") {
|
|
1283
|
+
throw new Error("Search queries must always be in relevance order. Can not set order manually.");
|
|
1284
|
+
}
|
|
1285
|
+
if (query.source.order !== null) {
|
|
1286
|
+
throw new Error("Queries may only specify order at most once");
|
|
1287
|
+
}
|
|
1288
|
+
query.source.order = order;
|
|
1289
|
+
return new QueryImpl(query);
|
|
1290
|
+
}
|
|
1291
|
+
filter(predicate) {
|
|
1292
|
+
validateArg(predicate, 1, "filter", "predicate");
|
|
1293
|
+
const query = this.takeQuery();
|
|
1294
|
+
if (query.operators.length >= MAX_QUERY_OPERATORS) {
|
|
1295
|
+
throw new Error(`Can't construct query with more than ${MAX_QUERY_OPERATORS} operators`);
|
|
1296
|
+
}
|
|
1297
|
+
query.operators.push({
|
|
1298
|
+
filter: serializeExpression(predicate(filterBuilderImpl))
|
|
1299
|
+
});
|
|
1300
|
+
return new QueryImpl(query);
|
|
1301
|
+
}
|
|
1302
|
+
limit(n) {
|
|
1303
|
+
validateArg(n, 1, "limit", "n");
|
|
1304
|
+
const query = this.takeQuery();
|
|
1305
|
+
query.operators.push({ limit: n });
|
|
1306
|
+
return new QueryImpl(query);
|
|
1307
|
+
}
|
|
1308
|
+
[Symbol.asyncIterator]() {
|
|
1309
|
+
this.startQuery();
|
|
1310
|
+
return this;
|
|
1311
|
+
}
|
|
1312
|
+
async next() {
|
|
1313
|
+
if (this.state.type === "closed" || this.state.type === "consumed") {
|
|
1314
|
+
throwClosedError(this.state.type);
|
|
1315
|
+
}
|
|
1316
|
+
const queryId = this.state.type === "preparing" ? this.startQuery() : this.state.queryId;
|
|
1317
|
+
const { value, done } = await performAsyncSyscall("1.0/queryStreamNext", {
|
|
1318
|
+
queryId
|
|
1319
|
+
});
|
|
1320
|
+
if (done) {
|
|
1321
|
+
this.closeQuery();
|
|
1322
|
+
}
|
|
1323
|
+
const convexValue = jsonToConvex(value);
|
|
1324
|
+
return { value: convexValue, done };
|
|
1325
|
+
}
|
|
1326
|
+
return() {
|
|
1327
|
+
this.closeQuery();
|
|
1328
|
+
return Promise.resolve({ done: true, value: undefined });
|
|
1329
|
+
}
|
|
1330
|
+
async paginate(paginationOpts) {
|
|
1331
|
+
validateArg(paginationOpts, 1, "paginate", "options");
|
|
1332
|
+
if (typeof paginationOpts?.numItems !== "number" || paginationOpts.numItems < 0) {
|
|
1333
|
+
throw new Error(`\`options.numItems\` must be a positive number. Received \`${paginationOpts?.numItems}\`.`);
|
|
1334
|
+
}
|
|
1335
|
+
const query = this.takeQuery();
|
|
1336
|
+
const pageSize = paginationOpts.numItems;
|
|
1337
|
+
const cursor = paginationOpts.cursor;
|
|
1338
|
+
const endCursor = paginationOpts?.endCursor ?? null;
|
|
1339
|
+
const maximumRowsRead = paginationOpts.maximumRowsRead ?? null;
|
|
1340
|
+
const { page, isDone, continueCursor, splitCursor, pageStatus } = await performAsyncSyscall("1.0/queryPage", {
|
|
1341
|
+
query,
|
|
1342
|
+
cursor,
|
|
1343
|
+
endCursor,
|
|
1344
|
+
pageSize,
|
|
1345
|
+
maximumRowsRead,
|
|
1346
|
+
maximumBytesRead: paginationOpts.maximumBytesRead,
|
|
1347
|
+
version
|
|
1348
|
+
});
|
|
1349
|
+
return {
|
|
1350
|
+
page: page.map((json) => jsonToConvex(json)),
|
|
1351
|
+
isDone,
|
|
1352
|
+
continueCursor,
|
|
1353
|
+
splitCursor,
|
|
1354
|
+
pageStatus
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
async collect() {
|
|
1358
|
+
const out = [];
|
|
1359
|
+
for await (const item of this) {
|
|
1360
|
+
out.push(item);
|
|
1361
|
+
}
|
|
1362
|
+
return out;
|
|
1363
|
+
}
|
|
1364
|
+
async take(n) {
|
|
1365
|
+
validateArg(n, 1, "take", "n");
|
|
1366
|
+
validateArgIsNonNegativeInteger(n, 1, "take", "n");
|
|
1367
|
+
return this.limit(n).collect();
|
|
1368
|
+
}
|
|
1369
|
+
async first() {
|
|
1370
|
+
const first_array = await this.take(1);
|
|
1371
|
+
return first_array.length === 0 ? null : first_array[0];
|
|
1372
|
+
}
|
|
1373
|
+
async unique() {
|
|
1374
|
+
const first_two_array = await this.take(2);
|
|
1375
|
+
if (first_two_array.length === 0) {
|
|
1376
|
+
return null;
|
|
1377
|
+
}
|
|
1378
|
+
if (first_two_array.length === 2) {
|
|
1379
|
+
throw new Error(`unique() query returned more than one result from table ${this.tableNameForErrorMessages}:
|
|
1380
|
+
[${first_two_array[0]._id}, ${first_two_array[1]._id}, ...]`);
|
|
1381
|
+
}
|
|
1382
|
+
return first_two_array[0];
|
|
1383
|
+
}
|
|
1384
|
+
};
|
|
1385
|
+
});
|
|
1386
|
+
|
|
1387
|
+
// ../core/node_modules/convex/dist/esm/server/impl/database_impl.js
|
|
1388
|
+
async function get(table, id, isSystem) {
|
|
1389
|
+
validateArg(id, 1, "get", "id");
|
|
1390
|
+
if (typeof id !== "string") {
|
|
1391
|
+
throw new Error(`Invalid argument \`id\` for \`db.get\`, expected string but got '${typeof id}': ${id}`);
|
|
1392
|
+
}
|
|
1393
|
+
const args = {
|
|
1394
|
+
id: convexToJson(id),
|
|
1395
|
+
isSystem,
|
|
1396
|
+
version,
|
|
1397
|
+
table
|
|
1398
|
+
};
|
|
1399
|
+
const syscallJSON = await performAsyncSyscall("1.0/get", args);
|
|
1400
|
+
return jsonToConvex(syscallJSON);
|
|
1401
|
+
}
|
|
1402
|
+
function setupReader() {
|
|
1403
|
+
const reader = (isSystem = false) => {
|
|
1404
|
+
return {
|
|
1405
|
+
get: async (arg0, arg1) => {
|
|
1406
|
+
return arg1 !== undefined ? await get(arg0, arg1, isSystem) : await get(undefined, arg0, isSystem);
|
|
1407
|
+
},
|
|
1408
|
+
query: (tableName) => {
|
|
1409
|
+
return new TableReader(tableName, isSystem).query();
|
|
1410
|
+
},
|
|
1411
|
+
normalizeId: (tableName, id) => {
|
|
1412
|
+
validateArg(tableName, 1, "normalizeId", "tableName");
|
|
1413
|
+
validateArg(id, 2, "normalizeId", "id");
|
|
1414
|
+
const accessingSystemTable = tableName.startsWith("_");
|
|
1415
|
+
if (accessingSystemTable !== isSystem) {
|
|
1416
|
+
throw new Error(`${accessingSystemTable ? "System" : "User"} tables can only be accessed from db.${isSystem ? "" : "system."}normalizeId().`);
|
|
1417
|
+
}
|
|
1418
|
+
const syscallJSON = performSyscall("1.0/db/normalizeId", {
|
|
1419
|
+
table: tableName,
|
|
1420
|
+
idString: id
|
|
1421
|
+
});
|
|
1422
|
+
const syscallResult = jsonToConvex(syscallJSON);
|
|
1423
|
+
return syscallResult.id;
|
|
1424
|
+
},
|
|
1425
|
+
system: null,
|
|
1426
|
+
table: (tableName) => {
|
|
1427
|
+
return new TableReader(tableName, isSystem);
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
};
|
|
1431
|
+
const { system: _, ...rest } = reader(true);
|
|
1432
|
+
const r = reader();
|
|
1433
|
+
r.system = rest;
|
|
1434
|
+
return r;
|
|
1435
|
+
}
|
|
1436
|
+
async function insert(tableName, value) {
|
|
1437
|
+
if (tableName.startsWith("_")) {
|
|
1438
|
+
throw new Error("System tables (prefixed with `_`) are read-only.");
|
|
1439
|
+
}
|
|
1440
|
+
validateArg(tableName, 1, "insert", "table");
|
|
1441
|
+
validateArg(value, 2, "insert", "value");
|
|
1442
|
+
const syscallJSON = await performAsyncSyscall("1.0/insert", {
|
|
1443
|
+
table: tableName,
|
|
1444
|
+
value: convexToJson(value)
|
|
1445
|
+
});
|
|
1446
|
+
const syscallResult = jsonToConvex(syscallJSON);
|
|
1447
|
+
return syscallResult._id;
|
|
1448
|
+
}
|
|
1449
|
+
async function patch(table, id, value) {
|
|
1450
|
+
validateArg(id, 1, "patch", "id");
|
|
1451
|
+
validateArg(value, 2, "patch", "value");
|
|
1452
|
+
await performAsyncSyscall("1.0/shallowMerge", {
|
|
1453
|
+
id: convexToJson(id),
|
|
1454
|
+
value: patchValueToJson(value),
|
|
1455
|
+
table
|
|
1456
|
+
});
|
|
1457
|
+
}
|
|
1458
|
+
async function replace(table, id, value) {
|
|
1459
|
+
validateArg(id, 1, "replace", "id");
|
|
1460
|
+
validateArg(value, 2, "replace", "value");
|
|
1461
|
+
await performAsyncSyscall("1.0/replace", {
|
|
1462
|
+
id: convexToJson(id),
|
|
1463
|
+
value: convexToJson(value),
|
|
1464
|
+
table
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
async function delete_(table, id) {
|
|
1468
|
+
validateArg(id, 1, "delete", "id");
|
|
1469
|
+
await performAsyncSyscall("1.0/remove", {
|
|
1470
|
+
id: convexToJson(id),
|
|
1471
|
+
table
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
function setupWriter() {
|
|
1475
|
+
const reader = setupReader();
|
|
1476
|
+
return {
|
|
1477
|
+
get: reader.get,
|
|
1478
|
+
query: reader.query,
|
|
1479
|
+
normalizeId: reader.normalizeId,
|
|
1480
|
+
system: reader.system,
|
|
1481
|
+
insert: async (table, value) => {
|
|
1482
|
+
return await insert(table, value);
|
|
1483
|
+
},
|
|
1484
|
+
patch: async (arg0, arg1, arg2) => {
|
|
1485
|
+
return arg2 !== undefined ? await patch(arg0, arg1, arg2) : await patch(undefined, arg0, arg1);
|
|
1486
|
+
},
|
|
1487
|
+
replace: async (arg0, arg1, arg2) => {
|
|
1488
|
+
return arg2 !== undefined ? await replace(arg0, arg1, arg2) : await replace(undefined, arg0, arg1);
|
|
1489
|
+
},
|
|
1490
|
+
delete: async (arg0, arg1) => {
|
|
1491
|
+
return arg1 !== undefined ? await delete_(arg0, arg1) : await delete_(undefined, arg0);
|
|
1492
|
+
},
|
|
1493
|
+
table: (tableName) => {
|
|
1494
|
+
return new TableWriter(tableName, false);
|
|
1495
|
+
}
|
|
1496
|
+
};
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
class TableReader {
|
|
1500
|
+
constructor(tableName, isSystem) {
|
|
1501
|
+
this.tableName = tableName;
|
|
1502
|
+
this.isSystem = isSystem;
|
|
1503
|
+
}
|
|
1504
|
+
async get(id) {
|
|
1505
|
+
return get(this.tableName, id, this.isSystem);
|
|
1506
|
+
}
|
|
1507
|
+
query() {
|
|
1508
|
+
const accessingSystemTable = this.tableName.startsWith("_");
|
|
1509
|
+
if (accessingSystemTable !== this.isSystem) {
|
|
1510
|
+
throw new Error(`${accessingSystemTable ? "System" : "User"} tables can only be accessed from db.${this.isSystem ? "" : "system."}query().`);
|
|
1511
|
+
}
|
|
1512
|
+
return new QueryInitializerImpl(this.tableName);
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
var TableWriter;
|
|
1516
|
+
var init_database_impl = __esm(() => {
|
|
1517
|
+
init_values();
|
|
1518
|
+
init_syscall();
|
|
1519
|
+
init_query_impl();
|
|
1520
|
+
init_value();
|
|
1521
|
+
TableWriter = class TableWriter extends TableReader {
|
|
1522
|
+
async insert(value) {
|
|
1523
|
+
return insert(this.tableName, value);
|
|
1524
|
+
}
|
|
1525
|
+
async patch(id, value) {
|
|
1526
|
+
return patch(this.tableName, id, value);
|
|
1527
|
+
}
|
|
1528
|
+
async replace(id, value) {
|
|
1529
|
+
return replace(this.tableName, id, value);
|
|
1530
|
+
}
|
|
1531
|
+
async delete(id) {
|
|
1532
|
+
return delete_(this.tableName, id);
|
|
1533
|
+
}
|
|
1534
|
+
};
|
|
1535
|
+
});
|
|
1536
|
+
|
|
1537
|
+
// ../core/node_modules/convex/dist/esm/server/impl/scheduler_impl.js
|
|
1538
|
+
function setupMutationScheduler() {
|
|
1539
|
+
return {
|
|
1540
|
+
runAfter: async (delayMs, functionReference, args) => {
|
|
1541
|
+
const syscallArgs = runAfterSyscallArgs(delayMs, functionReference, args);
|
|
1542
|
+
return await performAsyncSyscall("1.0/schedule", syscallArgs);
|
|
1543
|
+
},
|
|
1544
|
+
runAt: async (ms_since_epoch_or_date, functionReference, args) => {
|
|
1545
|
+
const syscallArgs = runAtSyscallArgs(ms_since_epoch_or_date, functionReference, args);
|
|
1546
|
+
return await performAsyncSyscall("1.0/schedule", syscallArgs);
|
|
1547
|
+
},
|
|
1548
|
+
cancel: async (id) => {
|
|
1549
|
+
validateArg(id, 1, "cancel", "id");
|
|
1550
|
+
const args = { id: convexToJson(id) };
|
|
1551
|
+
await performAsyncSyscall("1.0/cancel_job", args);
|
|
1552
|
+
}
|
|
1553
|
+
};
|
|
1554
|
+
}
|
|
1555
|
+
function runAfterSyscallArgs(delayMs, functionReference, args) {
|
|
1556
|
+
if (typeof delayMs !== "number") {
|
|
1557
|
+
throw new Error("`delayMs` must be a number");
|
|
1558
|
+
}
|
|
1559
|
+
if (!isFinite(delayMs)) {
|
|
1560
|
+
throw new Error("`delayMs` must be a finite number");
|
|
1561
|
+
}
|
|
1562
|
+
if (delayMs < 0) {
|
|
1563
|
+
throw new Error("`delayMs` must be non-negative");
|
|
1564
|
+
}
|
|
1565
|
+
const functionArgs = parseArgs(args);
|
|
1566
|
+
const address = getFunctionAddress(functionReference);
|
|
1567
|
+
const ts = (Date.now() + delayMs) / 1000;
|
|
1568
|
+
return {
|
|
1569
|
+
...address,
|
|
1570
|
+
ts,
|
|
1571
|
+
args: convexToJson(functionArgs),
|
|
1572
|
+
version
|
|
1573
|
+
};
|
|
1574
|
+
}
|
|
1575
|
+
function runAtSyscallArgs(ms_since_epoch_or_date, functionReference, args) {
|
|
1576
|
+
let ts;
|
|
1577
|
+
if (ms_since_epoch_or_date instanceof Date) {
|
|
1578
|
+
ts = ms_since_epoch_or_date.valueOf() / 1000;
|
|
1579
|
+
} else if (typeof ms_since_epoch_or_date === "number") {
|
|
1580
|
+
ts = ms_since_epoch_or_date / 1000;
|
|
1581
|
+
} else {
|
|
1582
|
+
throw new Error("The invoke time must a Date or a timestamp");
|
|
1583
|
+
}
|
|
1584
|
+
const address = getFunctionAddress(functionReference);
|
|
1585
|
+
const functionArgs = parseArgs(args);
|
|
1586
|
+
return {
|
|
1587
|
+
...address,
|
|
1588
|
+
ts,
|
|
1589
|
+
args: convexToJson(functionArgs),
|
|
1590
|
+
version
|
|
1591
|
+
};
|
|
1592
|
+
}
|
|
1593
|
+
var init_scheduler_impl = __esm(() => {
|
|
1594
|
+
init_values();
|
|
1595
|
+
init_syscall();
|
|
1596
|
+
init_paths();
|
|
1597
|
+
});
|
|
1598
|
+
|
|
1599
|
+
// ../core/node_modules/convex/dist/esm/server/impl/storage_impl.js
|
|
1600
|
+
function setupStorageReader(requestId) {
|
|
1601
|
+
return {
|
|
1602
|
+
getUrl: async (storageId) => {
|
|
1603
|
+
validateArg(storageId, 1, "getUrl", "storageId");
|
|
1604
|
+
return await performAsyncSyscall("1.0/storageGetUrl", {
|
|
1605
|
+
requestId,
|
|
1606
|
+
version,
|
|
1607
|
+
storageId
|
|
1608
|
+
});
|
|
1609
|
+
},
|
|
1610
|
+
getMetadata: async (storageId) => {
|
|
1611
|
+
return await performAsyncSyscall("1.0/storageGetMetadata", {
|
|
1612
|
+
requestId,
|
|
1613
|
+
version,
|
|
1614
|
+
storageId
|
|
1615
|
+
});
|
|
1616
|
+
}
|
|
1617
|
+
};
|
|
1618
|
+
}
|
|
1619
|
+
function setupStorageWriter(requestId) {
|
|
1620
|
+
const reader = setupStorageReader(requestId);
|
|
1621
|
+
return {
|
|
1622
|
+
generateUploadUrl: async () => {
|
|
1623
|
+
return await performAsyncSyscall("1.0/storageGenerateUploadUrl", {
|
|
1624
|
+
requestId,
|
|
1625
|
+
version
|
|
1626
|
+
});
|
|
1627
|
+
},
|
|
1628
|
+
delete: async (storageId) => {
|
|
1629
|
+
await performAsyncSyscall("1.0/storageDelete", {
|
|
1630
|
+
requestId,
|
|
1631
|
+
version,
|
|
1632
|
+
storageId
|
|
1633
|
+
});
|
|
1634
|
+
},
|
|
1635
|
+
getUrl: reader.getUrl,
|
|
1636
|
+
getMetadata: reader.getMetadata
|
|
1637
|
+
};
|
|
1638
|
+
}
|
|
1639
|
+
var init_storage_impl = __esm(() => {
|
|
1640
|
+
init_syscall();
|
|
1641
|
+
});
|
|
1642
|
+
|
|
1643
|
+
// ../core/node_modules/convex/dist/esm/server/impl/registration_impl.js
|
|
1644
|
+
async function invokeMutation(func, argsStr) {
|
|
1645
|
+
const requestId = "";
|
|
1646
|
+
const args = jsonToConvex(JSON.parse(argsStr));
|
|
1647
|
+
const mutationCtx = {
|
|
1648
|
+
db: setupWriter(),
|
|
1649
|
+
auth: setupAuth(requestId),
|
|
1650
|
+
storage: setupStorageWriter(requestId),
|
|
1651
|
+
scheduler: setupMutationScheduler(),
|
|
1652
|
+
runQuery: (reference, args2) => runUdf("query", reference, args2),
|
|
1653
|
+
runMutation: (reference, args2) => runUdf("mutation", reference, args2)
|
|
1654
|
+
};
|
|
1655
|
+
const result = await invokeFunction(func, mutationCtx, args);
|
|
1656
|
+
validateReturnValue(result);
|
|
1657
|
+
return JSON.stringify(convexToJson(result === undefined ? null : result));
|
|
1658
|
+
}
|
|
1659
|
+
function validateReturnValue(v2) {
|
|
1660
|
+
if (v2 instanceof QueryInitializerImpl || v2 instanceof QueryImpl) {
|
|
1661
|
+
throw new Error("Return value is a Query. Results must be retrieved with `.collect()`, `.take(n), `.unique()`, or `.first()`.");
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
async function invokeFunction(func, ctx, args) {
|
|
1665
|
+
let result;
|
|
1666
|
+
try {
|
|
1667
|
+
result = await Promise.resolve(func(ctx, ...args));
|
|
1668
|
+
} catch (thrown) {
|
|
1669
|
+
throw serializeConvexErrorData(thrown);
|
|
1670
|
+
}
|
|
1671
|
+
return result;
|
|
1672
|
+
}
|
|
1673
|
+
function dontCallDirectly(funcType, handler) {
|
|
1674
|
+
return (ctx, args) => {
|
|
1675
|
+
globalThis.console.warn(`Convex functions should not directly call other Convex functions. Consider calling a helper function instead. e.g. \`export const foo = ${funcType}(...); await foo(ctx);\` is not supported. See https://docs.convex.dev/production/best-practices/#use-helper-functions-to-write-shared-code`);
|
|
1676
|
+
return handler(ctx, args);
|
|
1677
|
+
};
|
|
1678
|
+
}
|
|
1679
|
+
function serializeConvexErrorData(thrown) {
|
|
1680
|
+
if (typeof thrown === "object" && thrown !== null && Symbol.for("ConvexError") in thrown) {
|
|
1681
|
+
const error = thrown;
|
|
1682
|
+
error.data = JSON.stringify(convexToJson(error.data === undefined ? null : error.data));
|
|
1683
|
+
error.ConvexErrorSymbol = Symbol.for("ConvexError");
|
|
1684
|
+
return error;
|
|
1685
|
+
} else {
|
|
1686
|
+
return thrown;
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
function assertNotBrowser() {
|
|
1690
|
+
if (typeof window === "undefined" || window.__convexAllowFunctionsInBrowser) {
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
const isRealBrowser = Object.getOwnPropertyDescriptor(globalThis, "window")?.get?.toString().includes("[native code]") ?? false;
|
|
1694
|
+
if (isRealBrowser) {
|
|
1695
|
+
console.error("Convex functions should not be imported in the browser. This will throw an error in future versions of `convex`. If this is a false negative, please report it to Convex support.");
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
function strictReplacer(key, value) {
|
|
1699
|
+
if (value === undefined) {
|
|
1700
|
+
throw new Error(`A validator is undefined for field "${key}". This is often caused by circular imports. See https://docs.convex.dev/error#undefined-validator for details.`);
|
|
1701
|
+
}
|
|
1702
|
+
return value;
|
|
1703
|
+
}
|
|
1704
|
+
function exportArgs(functionDefinition) {
|
|
1705
|
+
return () => {
|
|
1706
|
+
let args = v.any();
|
|
1707
|
+
if (typeof functionDefinition === "object" && functionDefinition.args !== undefined) {
|
|
1708
|
+
args = asObjectValidator(functionDefinition.args);
|
|
1709
|
+
}
|
|
1710
|
+
return JSON.stringify(args.json, strictReplacer);
|
|
1711
|
+
};
|
|
1712
|
+
}
|
|
1713
|
+
function exportReturns(functionDefinition) {
|
|
1714
|
+
return () => {
|
|
1715
|
+
let returns;
|
|
1716
|
+
if (typeof functionDefinition === "object" && functionDefinition.returns !== undefined) {
|
|
1717
|
+
returns = asObjectValidator(functionDefinition.returns);
|
|
1718
|
+
}
|
|
1719
|
+
return JSON.stringify(returns ? returns.json : null, strictReplacer);
|
|
1720
|
+
};
|
|
1721
|
+
}
|
|
1722
|
+
async function invokeQuery(func, argsStr) {
|
|
1723
|
+
const requestId = "";
|
|
1724
|
+
const args = jsonToConvex(JSON.parse(argsStr));
|
|
1725
|
+
const queryCtx = {
|
|
1726
|
+
db: setupReader(),
|
|
1727
|
+
auth: setupAuth(requestId),
|
|
1728
|
+
storage: setupStorageReader(requestId),
|
|
1729
|
+
runQuery: (reference, args2) => runUdf("query", reference, args2)
|
|
1730
|
+
};
|
|
1731
|
+
const result = await invokeFunction(func, queryCtx, args);
|
|
1732
|
+
validateReturnValue(result);
|
|
1733
|
+
return JSON.stringify(convexToJson(result === undefined ? null : result));
|
|
1734
|
+
}
|
|
1735
|
+
async function runUdf(udfType, f, args) {
|
|
1736
|
+
const queryArgs = parseArgs(args);
|
|
1737
|
+
const syscallArgs = {
|
|
1738
|
+
udfType,
|
|
1739
|
+
args: convexToJson(queryArgs),
|
|
1740
|
+
...getFunctionAddress(f)
|
|
1741
|
+
};
|
|
1742
|
+
const result = await performAsyncSyscall("1.0/runUdf", syscallArgs);
|
|
1743
|
+
return jsonToConvex(result);
|
|
1744
|
+
}
|
|
1745
|
+
var mutationGeneric = (functionDefinition) => {
|
|
1746
|
+
const handler = typeof functionDefinition === "function" ? functionDefinition : functionDefinition.handler;
|
|
1747
|
+
const func = dontCallDirectly("mutation", handler);
|
|
1748
|
+
assertNotBrowser();
|
|
1749
|
+
func.isMutation = true;
|
|
1750
|
+
func.isPublic = true;
|
|
1751
|
+
func.invokeMutation = (argsStr) => invokeMutation(handler, argsStr);
|
|
1752
|
+
func.exportArgs = exportArgs(functionDefinition);
|
|
1753
|
+
func.exportReturns = exportReturns(functionDefinition);
|
|
1754
|
+
func._handler = handler;
|
|
1755
|
+
return func;
|
|
1756
|
+
}, queryGeneric = (functionDefinition) => {
|
|
1757
|
+
const handler = typeof functionDefinition === "function" ? functionDefinition : functionDefinition.handler;
|
|
1758
|
+
const func = dontCallDirectly("query", handler);
|
|
1759
|
+
assertNotBrowser();
|
|
1760
|
+
func.isQuery = true;
|
|
1761
|
+
func.isPublic = true;
|
|
1762
|
+
func.invokeQuery = (argsStr) => invokeQuery(handler, argsStr);
|
|
1763
|
+
func.exportArgs = exportArgs(functionDefinition);
|
|
1764
|
+
func.exportReturns = exportReturns(functionDefinition);
|
|
1765
|
+
func._handler = handler;
|
|
1766
|
+
return func;
|
|
1767
|
+
};
|
|
1768
|
+
var init_registration_impl = __esm(() => {
|
|
1769
|
+
init_values();
|
|
1770
|
+
init_authentication_impl();
|
|
1771
|
+
init_database_impl();
|
|
1772
|
+
init_query_impl();
|
|
1773
|
+
init_scheduler_impl();
|
|
1774
|
+
init_storage_impl();
|
|
1775
|
+
init_syscall();
|
|
1776
|
+
init_validator();
|
|
1777
|
+
init_paths();
|
|
1778
|
+
});
|
|
1779
|
+
|
|
1780
|
+
// ../core/node_modules/convex/dist/esm/server/pagination.js
|
|
1781
|
+
var paginationOptsValidator;
|
|
1782
|
+
var init_pagination = __esm(() => {
|
|
1783
|
+
init_validator();
|
|
1784
|
+
paginationOptsValidator = v.object({
|
|
1785
|
+
numItems: v.number(),
|
|
1786
|
+
cursor: v.union(v.string(), v.null()),
|
|
1787
|
+
endCursor: v.optional(v.union(v.string(), v.null())),
|
|
1788
|
+
id: v.optional(v.number()),
|
|
1789
|
+
maximumRowsRead: v.optional(v.number()),
|
|
1790
|
+
maximumBytesRead: v.optional(v.number())
|
|
1791
|
+
});
|
|
1792
|
+
});
|
|
1793
|
+
|
|
1794
|
+
// ../core/node_modules/convex/dist/esm/server/index.js
|
|
1795
|
+
var init_server = __esm(() => {
|
|
1796
|
+
init_registration_impl();
|
|
1797
|
+
init_pagination();
|
|
1798
|
+
init_search_filter_builder();
|
|
1799
|
+
});
|
|
1800
|
+
|
|
1801
|
+
// ../core/dist/system/system-functions-module.js
|
|
1802
|
+
function getSystemFunctionsModule() {
|
|
1803
|
+
return systemFunctions;
|
|
1804
|
+
}
|
|
1805
|
+
var systemFunctions;
|
|
1806
|
+
var init_system_functions_module = __esm(() => {
|
|
1807
|
+
init_server();
|
|
1808
|
+
init_internal();
|
|
1809
|
+
systemFunctions = createSystemFunctions({
|
|
1810
|
+
query: queryGeneric,
|
|
1811
|
+
mutation: mutationGeneric
|
|
1812
|
+
});
|
|
1813
|
+
});
|
|
1814
|
+
|
|
1815
|
+
// ../core/dist/udf/module-loader/module-loader.js
|
|
1816
|
+
var exports_module_loader = {};
|
|
1817
|
+
__export(exports_module_loader, {
|
|
1818
|
+
withModuleRegistry: () => withModuleRegistry,
|
|
1819
|
+
setModuleLoaderMetadata: () => setModuleLoaderMetadata,
|
|
1820
|
+
setDefaultModuleRegistry: () => setDefaultModuleRegistry,
|
|
1821
|
+
setConcaveModuleLoader: () => setConcaveModuleLoader,
|
|
1822
|
+
resetModuleState: () => resetModuleState,
|
|
1823
|
+
registerModuleLoader: () => registerModuleLoader,
|
|
1824
|
+
onModuleLoadersChanged: () => onModuleLoadersChanged,
|
|
1825
|
+
loadConvexModule: () => loadConvexModule,
|
|
1826
|
+
listRegisteredModules: () => listRegisteredModules,
|
|
1827
|
+
getModuleRegistry: () => getModuleRegistry,
|
|
1828
|
+
getModuleLoaderMetadata: () => getModuleLoaderMetadata,
|
|
1829
|
+
getConcaveModuleLoader: () => getConcaveModuleLoader,
|
|
1830
|
+
createModuleLoaderFromGlob: () => createModuleLoaderFromGlob,
|
|
1831
|
+
clearModuleLoader: () => clearModuleLoader,
|
|
1832
|
+
ModuleRegistry: () => ModuleRegistry
|
|
1833
|
+
});
|
|
1834
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
1835
|
+
|
|
1836
|
+
class ModuleRegistry {
|
|
1837
|
+
scopedLoaders = new Map;
|
|
1838
|
+
constructor(defaults = []) {
|
|
1839
|
+
this.reset(defaults, { suppressEmit: true });
|
|
1840
|
+
}
|
|
1841
|
+
reset(defaults, options = {}) {
|
|
1842
|
+
this.scopedLoaders.clear();
|
|
1843
|
+
this.scopedLoaders.set("", defaults.map(createRegisteredLoader));
|
|
1844
|
+
if (!options.suppressEmit) {
|
|
1845
|
+
emitModuleLoadersChanged();
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
clone() {
|
|
1849
|
+
const next = new ModuleRegistry;
|
|
1850
|
+
for (const [scope, loaders] of this.scopedLoaders.entries()) {
|
|
1851
|
+
next.scopedLoaders.set(scope, loaders.map(cloneRegisteredLoader));
|
|
1852
|
+
}
|
|
1853
|
+
return next;
|
|
1854
|
+
}
|
|
1855
|
+
setScopeLoaders(scope, loaders) {
|
|
1856
|
+
const normalizedScope = normalizeComponentPath(scope);
|
|
1857
|
+
this.scopedLoaders.set(normalizedScope, loaders.map(createRegisteredLoader));
|
|
1858
|
+
emitModuleLoadersChanged();
|
|
1859
|
+
}
|
|
1860
|
+
setRootLoaders(loaders) {
|
|
1861
|
+
this.setScopeLoaders("", loaders);
|
|
1862
|
+
}
|
|
1863
|
+
register(loader, options = {}) {
|
|
1864
|
+
const scope = normalizeComponentPath(options.componentPath ?? "");
|
|
1865
|
+
const list = this.scopedLoaders.get(scope) ?? [];
|
|
1866
|
+
const entry = createRegisteredLoader(loader);
|
|
1867
|
+
if (options.prepend) {
|
|
1868
|
+
list.unshift(entry);
|
|
1869
|
+
} else {
|
|
1870
|
+
list.push(entry);
|
|
1871
|
+
}
|
|
1872
|
+
this.scopedLoaders.set(scope, list);
|
|
1873
|
+
emitModuleLoadersChanged();
|
|
1874
|
+
return () => {
|
|
1875
|
+
const current = this.scopedLoaders.get(scope);
|
|
1876
|
+
if (!current)
|
|
1877
|
+
return;
|
|
1878
|
+
const index = current.indexOf(entry);
|
|
1879
|
+
if (index >= 0) {
|
|
1880
|
+
current.splice(index, 1);
|
|
1881
|
+
}
|
|
1882
|
+
this.scopedLoaders.set(scope, current);
|
|
1883
|
+
emitModuleLoadersChanged();
|
|
1884
|
+
};
|
|
1885
|
+
}
|
|
1886
|
+
async load(request) {
|
|
1887
|
+
const scopes = expandComponentScopes(request.componentPath);
|
|
1888
|
+
const errors2 = [];
|
|
1889
|
+
let attempted = false;
|
|
1890
|
+
for (const scope of scopes) {
|
|
1891
|
+
const loaders = this.scopedLoaders.get(scope);
|
|
1892
|
+
if (!loaders || loaders.length === 0) {
|
|
1893
|
+
continue;
|
|
1894
|
+
}
|
|
1895
|
+
for (const entry of loaders) {
|
|
1896
|
+
attempted = true;
|
|
1897
|
+
try {
|
|
1898
|
+
const result = await entry.loader(request.path, { ...request, scope: scope || undefined });
|
|
1899
|
+
if (result !== undefined) {
|
|
1900
|
+
return result;
|
|
1901
|
+
}
|
|
1902
|
+
} catch (error2) {
|
|
1903
|
+
errors2.push(error2);
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
const description = request.componentPath ? `module "${request.path}" for component "${request.componentPath}"` : `module "${request.path}"`;
|
|
1908
|
+
if (!attempted) {
|
|
1909
|
+
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\`).`);
|
|
1910
|
+
}
|
|
1911
|
+
const error = new Error(`Unable to resolve ${description}`);
|
|
1912
|
+
if (errors2.length > 0) {
|
|
1913
|
+
error.causes = errors2;
|
|
1914
|
+
}
|
|
1915
|
+
throw error;
|
|
1916
|
+
}
|
|
1917
|
+
async enumerate(request = {}) {
|
|
1918
|
+
const scopes = request.componentPath ? expandComponentScopes(request.componentPath) : Array.from(this.scopedLoaders.keys());
|
|
1919
|
+
const results = new Map;
|
|
1920
|
+
for (const scope of scopes) {
|
|
1921
|
+
const loaders = this.scopedLoaders.get(scope);
|
|
1922
|
+
if (!loaders || loaders.length === 0) {
|
|
1923
|
+
continue;
|
|
1924
|
+
}
|
|
1925
|
+
for (const entry of loaders) {
|
|
1926
|
+
const enumerate = entry.metadata?.enumerate;
|
|
1927
|
+
if (!enumerate)
|
|
1928
|
+
continue;
|
|
1929
|
+
try {
|
|
1930
|
+
const listings = await collectEnumerationResults(enumerate({ componentPath: request.componentPath, hint: request.hint, scope: scope || undefined }));
|
|
1931
|
+
for (const listing of listings) {
|
|
1932
|
+
const normalized = normalizeModuleListing(listing);
|
|
1933
|
+
if (!normalized)
|
|
1934
|
+
continue;
|
|
1935
|
+
if (!results.has(normalized.path)) {
|
|
1936
|
+
results.set(normalized.path, {
|
|
1937
|
+
...normalized,
|
|
1938
|
+
scope: scope || undefined,
|
|
1939
|
+
componentPath: normalized.componentPath ?? (scope || undefined)
|
|
1940
|
+
});
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
} catch (error) {
|
|
1944
|
+
console.debug("[ModuleLoader] Failed to enumerate modules:", error);
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
return Array.from(results.values());
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
function emitModuleLoadersChanged() {
|
|
1952
|
+
const state = getModuleState();
|
|
1953
|
+
for (const listener of Array.from(state.listeners)) {
|
|
1954
|
+
try {
|
|
1955
|
+
listener();
|
|
1956
|
+
} catch (error) {
|
|
1957
|
+
console.error("Error in module loader change listener:", error);
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
function getModuleState() {
|
|
1962
|
+
const globalAny = globalThis;
|
|
1963
|
+
let state = globalAny[MODULE_STATE_SYMBOL];
|
|
1964
|
+
if (!state) {
|
|
1965
|
+
const defaults = [];
|
|
1966
|
+
state = {
|
|
1967
|
+
registry: new ModuleRegistry(defaults),
|
|
1968
|
+
defaults,
|
|
1969
|
+
listeners: new Set
|
|
1970
|
+
};
|
|
1971
|
+
globalAny[MODULE_STATE_SYMBOL] = state;
|
|
1972
|
+
}
|
|
1973
|
+
return state;
|
|
1974
|
+
}
|
|
1975
|
+
function resetModuleState() {
|
|
1976
|
+
const globalAny = globalThis;
|
|
1977
|
+
delete globalAny[MODULE_STATE_SYMBOL];
|
|
1978
|
+
}
|
|
1979
|
+
function getModuleRegistry() {
|
|
1980
|
+
return MODULE_REGISTRY_CONTEXT.getStore() ?? getModuleState().registry;
|
|
1981
|
+
}
|
|
1982
|
+
function withModuleRegistry(registry, fn) {
|
|
1983
|
+
return MODULE_REGISTRY_CONTEXT.run(registry, fn);
|
|
1984
|
+
}
|
|
1985
|
+
function setDefaultModuleRegistry(registry) {
|
|
1986
|
+
getModuleState().registry = registry;
|
|
1987
|
+
}
|
|
1988
|
+
function setConcaveModuleLoader(loader, options = {}) {
|
|
1989
|
+
const loaders = Array.isArray(loader) ? loader : [loader];
|
|
1990
|
+
const state = getModuleState();
|
|
1991
|
+
const registry = state.registry;
|
|
1992
|
+
if (options.componentPath) {
|
|
1993
|
+
registry.setScopeLoaders(options.componentPath, loaders);
|
|
1994
|
+
} else {
|
|
1995
|
+
registry.setRootLoaders(loaders);
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
function registerModuleLoader(loader, options = {}) {
|
|
1999
|
+
return getModuleRegistry().register(loader, options);
|
|
2000
|
+
}
|
|
2001
|
+
function clearModuleLoader() {
|
|
2002
|
+
const state = getModuleState();
|
|
2003
|
+
state.registry.reset(state.defaults);
|
|
2004
|
+
}
|
|
2005
|
+
async function loadConvexModule(specifier, options = {}) {
|
|
2006
|
+
const request = normalizeModuleRequest(specifier, options);
|
|
2007
|
+
if (request.path === "_system") {
|
|
2008
|
+
try {
|
|
2009
|
+
return await getModuleRegistry().load(request);
|
|
2010
|
+
} catch (error) {
|
|
2011
|
+
if (error?.message?.includes("Unable to resolve")) {
|
|
2012
|
+
return getSystemFunctionsModule();
|
|
2013
|
+
}
|
|
2014
|
+
throw error;
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
return getModuleRegistry().load(request);
|
|
2018
|
+
}
|
|
2019
|
+
function getConcaveModuleLoader() {
|
|
2020
|
+
return async (modulePath, context) => {
|
|
2021
|
+
const request = normalizeModuleRequest(modulePath, {
|
|
2022
|
+
componentPath: context?.componentPath,
|
|
2023
|
+
hint: context?.hint
|
|
2024
|
+
});
|
|
2025
|
+
const scope = context?.scope;
|
|
2026
|
+
if (scope) {
|
|
2027
|
+
request.scope = scope;
|
|
2028
|
+
}
|
|
2029
|
+
return getModuleRegistry().load(request);
|
|
2030
|
+
};
|
|
2031
|
+
}
|
|
2032
|
+
async function listRegisteredModules(options = {}) {
|
|
2033
|
+
const listings = await getModuleRegistry().enumerate(options);
|
|
2034
|
+
return listings.map(({ scope, ...rest }) => ({
|
|
2035
|
+
...rest,
|
|
2036
|
+
componentPath: rest.componentPath ?? scope ?? undefined
|
|
2037
|
+
}));
|
|
2038
|
+
}
|
|
2039
|
+
function setModuleLoaderMetadata(loader, metadata) {
|
|
2040
|
+
loader[MODULE_LOADER_METADATA_SYMBOL] = metadata;
|
|
2041
|
+
}
|
|
2042
|
+
function getModuleLoaderMetadata(loader) {
|
|
2043
|
+
return loader[MODULE_LOADER_METADATA_SYMBOL];
|
|
2044
|
+
}
|
|
2045
|
+
function onModuleLoadersChanged(listener) {
|
|
2046
|
+
const state = getModuleState();
|
|
2047
|
+
state.listeners.add(listener);
|
|
2048
|
+
return () => {
|
|
2049
|
+
state.listeners.delete(listener);
|
|
2050
|
+
};
|
|
2051
|
+
}
|
|
2052
|
+
function createModuleLoaderFromGlob(registry, options = {}) {
|
|
2053
|
+
const normalizedEntries = new Map;
|
|
2054
|
+
const canonicalEntries = new Map;
|
|
2055
|
+
for (const [rawKey, entry] of Object.entries(registry)) {
|
|
2056
|
+
const key = normalizeRegistryKey(rawKey, options.trimPrefix);
|
|
2057
|
+
const loader2 = memoizeEntry(entry);
|
|
2058
|
+
normalizedEntries.set(key, loader2);
|
|
2059
|
+
normalizedEntries.set(removeExtension(key), loader2);
|
|
2060
|
+
const canonical = removeExtension(key);
|
|
2061
|
+
if (!canonicalEntries.has(canonical)) {
|
|
2062
|
+
canonicalEntries.set(canonical, {
|
|
2063
|
+
loader: loader2,
|
|
2064
|
+
source: key
|
|
2065
|
+
});
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
const loader = async (modulePath) => {
|
|
2069
|
+
const normalized = ensureExtension(normalizeModulePath(modulePath));
|
|
2070
|
+
const load = normalizedEntries.get(normalized) ?? normalizedEntries.get(removeExtension(normalized));
|
|
2071
|
+
if (!load) {
|
|
2072
|
+
return;
|
|
2073
|
+
}
|
|
2074
|
+
return load();
|
|
2075
|
+
};
|
|
2076
|
+
setModuleLoaderMetadata(loader, {
|
|
2077
|
+
enumerate: () => Array.from(canonicalEntries.entries()).map(([path, info]) => ({
|
|
2078
|
+
path,
|
|
2079
|
+
source: normalizeSourcePath(info.source)
|
|
2080
|
+
}))
|
|
2081
|
+
});
|
|
2082
|
+
return loader;
|
|
2083
|
+
}
|
|
2084
|
+
function memoizeEntry(entry) {
|
|
2085
|
+
if (typeof entry === "function") {
|
|
2086
|
+
let cached;
|
|
2087
|
+
return () => {
|
|
2088
|
+
if (!cached) {
|
|
2089
|
+
cached = Promise.resolve(entry());
|
|
2090
|
+
}
|
|
2091
|
+
return cached;
|
|
2092
|
+
};
|
|
2093
|
+
}
|
|
2094
|
+
const resolved = Promise.resolve(entry);
|
|
2095
|
+
return () => resolved;
|
|
2096
|
+
}
|
|
2097
|
+
function normalizeModuleRequest(specifier, options) {
|
|
2098
|
+
if (typeof specifier === "string") {
|
|
2099
|
+
return {
|
|
2100
|
+
path: normalizeModulePath(specifier),
|
|
2101
|
+
componentPath: options.componentPath,
|
|
2102
|
+
hint: options.hint
|
|
2103
|
+
};
|
|
2104
|
+
}
|
|
2105
|
+
return {
|
|
2106
|
+
path: normalizeModulePath(specifier.path),
|
|
2107
|
+
componentPath: specifier.componentPath ?? options.componentPath,
|
|
2108
|
+
hint: specifier.hint ?? options.hint,
|
|
2109
|
+
scope: specifier.scope
|
|
2110
|
+
};
|
|
2111
|
+
}
|
|
2112
|
+
function normalizeModulePath(path) {
|
|
2113
|
+
const trimmed = path.trim();
|
|
2114
|
+
if (!trimmed) {
|
|
2115
|
+
throw new Error("Module path must be a non-empty string");
|
|
2116
|
+
}
|
|
2117
|
+
let sanitized = trimmed.replace(/\\/g, "/");
|
|
2118
|
+
while (sanitized.startsWith("./") || sanitized.startsWith("../")) {
|
|
2119
|
+
sanitized = sanitized.startsWith("./") ? sanitized.slice(2) : sanitized.slice(3);
|
|
2120
|
+
}
|
|
2121
|
+
if (sanitized.startsWith("convex/")) {
|
|
2122
|
+
sanitized = sanitized.slice("convex/".length);
|
|
2123
|
+
}
|
|
2124
|
+
return sanitized.replace(/^\/+/, "");
|
|
2125
|
+
}
|
|
2126
|
+
function normalizeComponentPath(componentPath) {
|
|
2127
|
+
if (!componentPath) {
|
|
2128
|
+
return "";
|
|
2129
|
+
}
|
|
2130
|
+
return normalizeModulePath(componentPath);
|
|
2131
|
+
}
|
|
2132
|
+
function expandComponentScopes(componentPath) {
|
|
2133
|
+
const scopes = [];
|
|
2134
|
+
if (componentPath) {
|
|
2135
|
+
const normalized = normalizeComponentPath(componentPath);
|
|
2136
|
+
const segments = normalized.split("/").filter(Boolean);
|
|
2137
|
+
for (let i2 = segments.length;i2 > 0; i2--) {
|
|
2138
|
+
scopes.push(segments.slice(0, i2).join("/"));
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
scopes.push("");
|
|
2142
|
+
return scopes;
|
|
2143
|
+
}
|
|
2144
|
+
function ensureExtension(path) {
|
|
2145
|
+
if (/\.[a-zA-Z0-9]+$/.test(path)) {
|
|
2146
|
+
return path;
|
|
2147
|
+
}
|
|
2148
|
+
return `${path}.ts`;
|
|
2149
|
+
}
|
|
2150
|
+
function removeExtension(path) {
|
|
2151
|
+
return path.replace(/\.[^.]+$/, "");
|
|
2152
|
+
}
|
|
2153
|
+
function normalizeRegistryKey(key, trimPrefix) {
|
|
2154
|
+
let normalized = key.replace(/\\/g, "/");
|
|
2155
|
+
while (normalized.startsWith("./") || normalized.startsWith("../")) {
|
|
2156
|
+
normalized = normalized.startsWith("./") ? normalized.slice(2) : normalized.slice(3);
|
|
2157
|
+
}
|
|
2158
|
+
if (trimPrefix) {
|
|
2159
|
+
const prefix = normalizeModulePath(trimPrefix);
|
|
2160
|
+
if (prefix && normalized.startsWith(prefix)) {
|
|
2161
|
+
normalized = normalized.slice(prefix.length);
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
if (normalized.startsWith("convex/")) {
|
|
2165
|
+
normalized = normalized.slice("convex/".length);
|
|
2166
|
+
}
|
|
2167
|
+
return normalizeModulePath(normalized);
|
|
2168
|
+
}
|
|
2169
|
+
function createRegisteredLoader(loader) {
|
|
2170
|
+
return {
|
|
2171
|
+
loader,
|
|
2172
|
+
metadata: getModuleLoaderMetadata(loader)
|
|
2173
|
+
};
|
|
2174
|
+
}
|
|
2175
|
+
function cloneRegisteredLoader(entry) {
|
|
2176
|
+
return {
|
|
2177
|
+
loader: entry.loader,
|
|
2178
|
+
metadata: entry.metadata
|
|
2179
|
+
};
|
|
2180
|
+
}
|
|
2181
|
+
async function collectEnumerationResults(result) {
|
|
2182
|
+
const awaited = result instanceof Promise ? await result : result;
|
|
2183
|
+
if (!awaited) {
|
|
2184
|
+
return [];
|
|
2185
|
+
}
|
|
2186
|
+
if (typeof awaited === "string" || isModuleListingLike(awaited)) {
|
|
2187
|
+
return [awaited];
|
|
2188
|
+
}
|
|
2189
|
+
if (isAsyncIterable(awaited)) {
|
|
2190
|
+
const collected = [];
|
|
2191
|
+
for await (const item of awaited) {
|
|
2192
|
+
if (typeof item === "string" || isModuleListingLike(item)) {
|
|
2193
|
+
collected.push(item);
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
return collected;
|
|
2197
|
+
}
|
|
2198
|
+
if (isIterable(awaited)) {
|
|
2199
|
+
const collected = [];
|
|
2200
|
+
for (const item of awaited) {
|
|
2201
|
+
if (typeof item === "string" || isModuleListingLike(item)) {
|
|
2202
|
+
collected.push(item);
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
return collected;
|
|
2206
|
+
}
|
|
2207
|
+
return [];
|
|
2208
|
+
}
|
|
2209
|
+
function normalizeModuleListing(listing) {
|
|
2210
|
+
if (typeof listing === "string") {
|
|
2211
|
+
const canonical = removeExtension(normalizeModulePath(listing));
|
|
2212
|
+
return { path: canonical };
|
|
2213
|
+
}
|
|
2214
|
+
if (!listing || typeof listing.path !== "string") {
|
|
2215
|
+
return null;
|
|
2216
|
+
}
|
|
2217
|
+
const normalizedPath = removeExtension(normalizeModulePath(listing.path));
|
|
2218
|
+
const normalizedSource = listing.source ? normalizeSourcePath(listing.source) : undefined;
|
|
2219
|
+
return {
|
|
2220
|
+
path: normalizedPath,
|
|
2221
|
+
source: normalizedSource,
|
|
2222
|
+
componentPath: listing.componentPath ? normalizeComponentPath(listing.componentPath) : undefined,
|
|
2223
|
+
hint: listing.hint
|
|
2224
|
+
};
|
|
2225
|
+
}
|
|
2226
|
+
function normalizeSourcePath(path) {
|
|
2227
|
+
if (!path)
|
|
2228
|
+
return;
|
|
2229
|
+
const normalized = ensureExtension(normalizeModulePath(path));
|
|
2230
|
+
return normalized.startsWith("convex/") ? normalized : `convex/${normalized}`;
|
|
2231
|
+
}
|
|
2232
|
+
function isModuleListingLike(value) {
|
|
2233
|
+
return value && typeof value === "object" && typeof value.path === "string";
|
|
2234
|
+
}
|
|
2235
|
+
function isIterable(value) {
|
|
2236
|
+
return value && typeof value[Symbol.iterator] === "function";
|
|
2237
|
+
}
|
|
2238
|
+
function isAsyncIterable(value) {
|
|
2239
|
+
return value && typeof value[Symbol.asyncIterator] === "function";
|
|
2240
|
+
}
|
|
2241
|
+
var MODULE_STATE_SYMBOL, MODULE_LOADER_METADATA_SYMBOL, MODULE_REGISTRY_CONTEXT;
|
|
2242
|
+
var init_module_loader = __esm(() => {
|
|
2243
|
+
init_system_functions_module();
|
|
2244
|
+
MODULE_STATE_SYMBOL = Symbol.for("concave.moduleLoader.state");
|
|
2245
|
+
MODULE_LOADER_METADATA_SYMBOL = Symbol.for("concave.moduleLoader.metadata");
|
|
2246
|
+
MODULE_REGISTRY_CONTEXT = new AsyncLocalStorage;
|
|
2247
|
+
});
|
|
2248
|
+
|
|
2249
|
+
// ../core/dist/utils/utils.js
|
|
2250
|
+
function hexToArrayBuffer(hex) {
|
|
2251
|
+
if (hex === "") {
|
|
2252
|
+
return new Uint8Array(0).buffer;
|
|
2253
|
+
}
|
|
2254
|
+
const matches = hex.match(/.{1,2}/g);
|
|
2255
|
+
if (!matches) {
|
|
2256
|
+
throw new Error(`Invalid hex string: ${hex}`);
|
|
2257
|
+
}
|
|
2258
|
+
return new Uint8Array(matches.map((byte) => parseInt(byte, 16))).buffer;
|
|
2259
|
+
}
|
|
2260
|
+
function hexToString(hex) {
|
|
2261
|
+
const buffer = hexToArrayBuffer(hex);
|
|
2262
|
+
return new TextDecoder().decode(buffer);
|
|
2263
|
+
}
|
|
2264
|
+
function deserializeDeveloperId(developerId) {
|
|
2265
|
+
if (!developerId) {
|
|
2266
|
+
return null;
|
|
2267
|
+
}
|
|
2268
|
+
for (const separator of [DOC_ID_SEPARATOR, LEGACY_DOC_ID_SEPARATOR]) {
|
|
2269
|
+
const parts = developerId.split(separator);
|
|
2270
|
+
if (parts.length === 2 && parts[0] && parts[1]) {
|
|
2271
|
+
return { table: parts[0], internalId: parts[1] };
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
return null;
|
|
2275
|
+
}
|
|
2276
|
+
var DOC_ID_SEPARATOR = ":", LEGACY_DOC_ID_SEPARATOR = ";";
|
|
2277
|
+
|
|
2278
|
+
// ../core/dist/queryengine/indexing/index-key-codec.js
|
|
2279
|
+
var TypeTag;
|
|
2280
|
+
var init_index_key_codec = __esm(() => {
|
|
2281
|
+
(function(TypeTag2) {
|
|
2282
|
+
TypeTag2[TypeTag2["Null"] = 0] = "Null";
|
|
2283
|
+
TypeTag2[TypeTag2["False"] = 16] = "False";
|
|
2284
|
+
TypeTag2[TypeTag2["True"] = 17] = "True";
|
|
2285
|
+
TypeTag2[TypeTag2["NegativeInfinity"] = 32] = "NegativeInfinity";
|
|
2286
|
+
TypeTag2[TypeTag2["NegativeNumber"] = 33] = "NegativeNumber";
|
|
2287
|
+
TypeTag2[TypeTag2["NegativeZero"] = 34] = "NegativeZero";
|
|
2288
|
+
TypeTag2[TypeTag2["Zero"] = 35] = "Zero";
|
|
2289
|
+
TypeTag2[TypeTag2["PositiveNumber"] = 36] = "PositiveNumber";
|
|
2290
|
+
TypeTag2[TypeTag2["PositiveInfinity"] = 37] = "PositiveInfinity";
|
|
2291
|
+
TypeTag2[TypeTag2["NaN"] = 38] = "NaN";
|
|
2292
|
+
TypeTag2[TypeTag2["NegativeBigInt"] = 48] = "NegativeBigInt";
|
|
2293
|
+
TypeTag2[TypeTag2["ZeroBigInt"] = 49] = "ZeroBigInt";
|
|
2294
|
+
TypeTag2[TypeTag2["PositiveBigInt"] = 50] = "PositiveBigInt";
|
|
2295
|
+
TypeTag2[TypeTag2["String"] = 64] = "String";
|
|
2296
|
+
TypeTag2[TypeTag2["Bytes"] = 80] = "Bytes";
|
|
2297
|
+
})(TypeTag || (TypeTag = {}));
|
|
2298
|
+
});
|
|
2299
|
+
|
|
2300
|
+
// ../core/dist/queryengine/indexing/index-manager.js
|
|
2301
|
+
function getStandardIndexes() {
|
|
2302
|
+
return [
|
|
2303
|
+
{
|
|
2304
|
+
name: "by_creation_time",
|
|
2305
|
+
fields: ["_creationTime", "_id"]
|
|
2306
|
+
},
|
|
2307
|
+
{
|
|
2308
|
+
name: "by_id",
|
|
2309
|
+
fields: ["_id"]
|
|
2310
|
+
}
|
|
2311
|
+
];
|
|
2312
|
+
}
|
|
2313
|
+
var init_index_manager = __esm(() => {
|
|
2314
|
+
init_index_key_codec();
|
|
2315
|
+
});
|
|
2316
|
+
|
|
2317
|
+
// ../core/dist/tables/interface.js
|
|
2318
|
+
function getFullTableName(tableName, componentPath) {
|
|
2319
|
+
if (!componentPath || componentPath === "") {
|
|
2320
|
+
return tableName;
|
|
2321
|
+
}
|
|
2322
|
+
return `${componentPath}/${tableName}`;
|
|
2323
|
+
}
|
|
2324
|
+
function parseFullTableName(fullName) {
|
|
2325
|
+
const lastSlash = fullName.lastIndexOf("/");
|
|
2326
|
+
if (lastSlash === -1) {
|
|
2327
|
+
return { tableName: fullName, componentPath: "" };
|
|
2328
|
+
}
|
|
2329
|
+
return {
|
|
2330
|
+
componentPath: fullName.substring(0, lastSlash),
|
|
2331
|
+
tableName: fullName.substring(lastSlash + 1)
|
|
2332
|
+
};
|
|
2333
|
+
}
|
|
2334
|
+
var init_interface = () => {};
|
|
2335
|
+
|
|
2336
|
+
// ../core/dist/udf/analysis/validator.js
|
|
2337
|
+
class SchemaValidator {
|
|
2338
|
+
schemaCache = new Map;
|
|
2339
|
+
componentPath;
|
|
2340
|
+
constructor(componentPath) {
|
|
2341
|
+
this.componentPath = componentPath;
|
|
2342
|
+
}
|
|
2343
|
+
async loadTableSchema(tableName) {
|
|
2344
|
+
if (this.schemaCache.has(tableName)) {
|
|
2345
|
+
return this.schemaCache.get(tableName);
|
|
2346
|
+
}
|
|
2347
|
+
try {
|
|
2348
|
+
const schemaModule = await loadConvexModule("schema", { hint: "schema", componentPath: this.componentPath });
|
|
2349
|
+
const schema = schemaModule.default;
|
|
2350
|
+
if (schema?.schemaValidation === false) {
|
|
2351
|
+
return null;
|
|
2352
|
+
}
|
|
2353
|
+
if (!schema || !schema.tables || !schema.tables[tableName]) {
|
|
2354
|
+
return null;
|
|
2355
|
+
}
|
|
2356
|
+
const tableSchema = schema.tables[tableName];
|
|
2357
|
+
let validator;
|
|
2358
|
+
if (typeof tableSchema.export === "function") {
|
|
2359
|
+
const exportedSchema = tableSchema.export();
|
|
2360
|
+
validator = exportedSchema.documentType;
|
|
2361
|
+
} else if (tableSchema.validator) {
|
|
2362
|
+
validator = tableSchema.validator;
|
|
2363
|
+
} else {
|
|
2364
|
+
return null;
|
|
2365
|
+
}
|
|
2366
|
+
this.schemaCache.set(tableName, validator);
|
|
2367
|
+
return validator;
|
|
2368
|
+
} catch (error) {
|
|
2369
|
+
if (!isMissingSchemaModuleError(error)) {
|
|
2370
|
+
console.debug(`Failed to load schema for table ${tableName}:`, error);
|
|
2371
|
+
}
|
|
2372
|
+
return null;
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
async validateDocument(tableName, document) {
|
|
2376
|
+
if (tableName.startsWith("_")) {
|
|
2377
|
+
return;
|
|
2378
|
+
}
|
|
2379
|
+
const tableSchema = await this.loadTableSchema(tableName);
|
|
2380
|
+
if (!tableSchema) {
|
|
2381
|
+
return;
|
|
2382
|
+
}
|
|
2383
|
+
try {
|
|
2384
|
+
validateValidator(tableSchema, omit(document, ["_id", "_creationTime"]), "", {
|
|
2385
|
+
componentPath: this.componentPath ?? ""
|
|
2386
|
+
});
|
|
2387
|
+
} catch (error) {
|
|
2388
|
+
throw new ValidatorError(`Failed to insert or update a document in table "${tableName}" because it does not match the schema: ${error.message}`);
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
clearCache() {
|
|
2392
|
+
this.schemaCache.clear();
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
function omit(obj, keys) {
|
|
2396
|
+
return Object.fromEntries(Object.entries(obj).filter(([key]) => !keys.includes(key)));
|
|
2397
|
+
}
|
|
2398
|
+
function validateValidator(validator, value, path = "", options = {}) {
|
|
2399
|
+
const formatPath = (p) => p || ".";
|
|
2400
|
+
const formatValue = (v2) => {
|
|
2401
|
+
if (v2 === null)
|
|
2402
|
+
return "null";
|
|
2403
|
+
if (v2 === undefined)
|
|
2404
|
+
return "undefined";
|
|
2405
|
+
if (typeof v2 === "string")
|
|
2406
|
+
return `"${v2}"`;
|
|
2407
|
+
return String(v2);
|
|
2408
|
+
};
|
|
2409
|
+
switch (validator.type) {
|
|
2410
|
+
case "null": {
|
|
2411
|
+
if (value !== null) {
|
|
2412
|
+
throw new Error(`Value does not match validator.
|
|
2413
|
+
Path: ${formatPath(path)}
|
|
2414
|
+
Value: ${formatValue(value)}
|
|
2415
|
+
Validator: v.null()`);
|
|
2416
|
+
}
|
|
2417
|
+
return;
|
|
2418
|
+
}
|
|
2419
|
+
case "number": {
|
|
2420
|
+
if (typeof value !== "number") {
|
|
2421
|
+
throw new Error(`Value does not match validator.
|
|
2422
|
+
Path: ${formatPath(path)}
|
|
2423
|
+
Value: ${formatValue(value)}
|
|
2424
|
+
Validator: v.float64()`);
|
|
2425
|
+
}
|
|
2426
|
+
return;
|
|
2427
|
+
}
|
|
2428
|
+
case "bigint": {
|
|
2429
|
+
if (typeof value !== "bigint") {
|
|
2430
|
+
throw new Error(`Value does not match validator.
|
|
2431
|
+
Path: ${formatPath(path)}
|
|
2432
|
+
Value: ${formatValue(value)}
|
|
2433
|
+
Validator: v.int64()`);
|
|
2434
|
+
}
|
|
2435
|
+
return;
|
|
2436
|
+
}
|
|
2437
|
+
case "boolean": {
|
|
2438
|
+
if (typeof value !== "boolean") {
|
|
2439
|
+
throw new Error(`Value does not match validator.
|
|
2440
|
+
Path: ${formatPath(path)}
|
|
2441
|
+
Value: ${formatValue(value)}
|
|
2442
|
+
Validator: v.boolean()`);
|
|
2443
|
+
}
|
|
2444
|
+
return;
|
|
2445
|
+
}
|
|
2446
|
+
case "string": {
|
|
2447
|
+
if (typeof value !== "string") {
|
|
2448
|
+
throw new Error(`Value does not match validator.
|
|
2449
|
+
Path: ${formatPath(path)}
|
|
2450
|
+
Value: ${formatValue(value)}
|
|
2451
|
+
Validator: v.string()`);
|
|
2452
|
+
}
|
|
2453
|
+
return;
|
|
2454
|
+
}
|
|
2455
|
+
case "bytes": {
|
|
2456
|
+
if (!(value instanceof ArrayBuffer)) {
|
|
2457
|
+
throw new Error(`Value does not match validator.
|
|
2458
|
+
Path: ${formatPath(path)}
|
|
2459
|
+
Value: ${formatValue(value)}
|
|
2460
|
+
Validator: v.bytes()`);
|
|
2461
|
+
}
|
|
2462
|
+
return;
|
|
2463
|
+
}
|
|
2464
|
+
case "any": {
|
|
2465
|
+
return;
|
|
2466
|
+
}
|
|
2467
|
+
case "literal": {
|
|
2468
|
+
if (value !== validator.value) {
|
|
2469
|
+
throw new Error(`Value does not match validator.
|
|
2470
|
+
Path: ${formatPath(path)}
|
|
2471
|
+
Value: ${formatValue(value)}
|
|
2472
|
+
Validator: v.literal(${formatValue(validator.value)})`);
|
|
2473
|
+
}
|
|
2474
|
+
return;
|
|
2475
|
+
}
|
|
2476
|
+
case "id": {
|
|
2477
|
+
if (typeof value !== "string") {
|
|
2478
|
+
throw new Error(`Value does not match validator.
|
|
2479
|
+
Path: ${formatPath(path)}
|
|
2480
|
+
Value: ${formatValue(value)}
|
|
2481
|
+
Validator: v.id("${validator.tableName}")`);
|
|
2482
|
+
}
|
|
2483
|
+
const tableName = tableNameFromId(value);
|
|
2484
|
+
if (!tableName || !isMatchingValidatorTable(tableName, validator.tableName, options.componentPath)) {
|
|
2485
|
+
throw new Error(`Value does not match validator.
|
|
2486
|
+
Path: ${formatPath(path)}
|
|
2487
|
+
Value: ${formatValue(value)}
|
|
2488
|
+
Validator: v.id("${validator.tableName}")`);
|
|
2489
|
+
}
|
|
2490
|
+
return;
|
|
2491
|
+
}
|
|
2492
|
+
case "array": {
|
|
2493
|
+
if (!Array.isArray(value)) {
|
|
2494
|
+
throw new Error(`Value does not match validator.
|
|
2495
|
+
Path: ${formatPath(path)}
|
|
2496
|
+
Value: ${formatValue(value)}
|
|
2497
|
+
Validator: v.array(...)`);
|
|
2498
|
+
}
|
|
2499
|
+
for (let i2 = 0;i2 < value.length; i2++) {
|
|
2500
|
+
validateValidator(validator.value, value[i2], `${path}[${i2}]`, options);
|
|
2501
|
+
}
|
|
2502
|
+
return;
|
|
2503
|
+
}
|
|
2504
|
+
case "union": {
|
|
2505
|
+
let isValid = false;
|
|
2506
|
+
for (const v2 of validator.value) {
|
|
2507
|
+
try {
|
|
2508
|
+
validateValidator(v2, value, path, options);
|
|
2509
|
+
isValid = true;
|
|
2510
|
+
break;
|
|
2511
|
+
} catch (_e) {}
|
|
2512
|
+
}
|
|
2513
|
+
if (!isValid) {
|
|
2514
|
+
throw new Error(`Value does not match validator.
|
|
2515
|
+
Path: ${formatPath(path)}
|
|
2516
|
+
Value: ${formatValue(value)}
|
|
2517
|
+
Validator: v.union(...)`);
|
|
2518
|
+
}
|
|
2519
|
+
return;
|
|
2520
|
+
}
|
|
2521
|
+
case "object": {
|
|
2522
|
+
if (typeof value !== "object") {
|
|
2523
|
+
throw new Error(`Value does not match validator.
|
|
2524
|
+
Path: ${formatPath(path)}
|
|
2525
|
+
Value: ${formatValue(value)}
|
|
2526
|
+
Validator: v.object({...})`);
|
|
2527
|
+
}
|
|
2528
|
+
if (!isSimpleObject2(value)) {
|
|
2529
|
+
throw new Error(`Value does not match validator.
|
|
2530
|
+
Path: ${formatPath(path)}
|
|
2531
|
+
Value: ${formatValue(value)}
|
|
2532
|
+
Validator: v.object({...})`);
|
|
2533
|
+
}
|
|
2534
|
+
for (const [k, { fieldType, optional }] of Object.entries(validator.value)) {
|
|
2535
|
+
if (value[k] === undefined) {
|
|
2536
|
+
if (!optional) {
|
|
2537
|
+
throw new Error(`Object is missing the required field \`${k}\`. Consider wrapping the field validator in \`v.optional(...)\` if this is expected.
|
|
2538
|
+
|
|
2539
|
+
Object: ${JSON.stringify(value)}
|
|
2540
|
+
Validator: v.object({...})`);
|
|
2541
|
+
}
|
|
2542
|
+
} else {
|
|
2543
|
+
const fieldPath = path ? `${path}.${k}` : `.${k}`;
|
|
2544
|
+
validateValidator(fieldType, value[k], fieldPath, options);
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
for (const k of Object.keys(value)) {
|
|
2548
|
+
if (validator.value[k] === undefined) {
|
|
2549
|
+
throw new Error(`Object contains extra field \`${k}\` that is not in the validator.
|
|
2550
|
+
|
|
2551
|
+
Object: ${JSON.stringify(value)}
|
|
2552
|
+
Validator: v.object({...})`);
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
return;
|
|
2556
|
+
}
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
2559
|
+
function tableNameFromId(id) {
|
|
2560
|
+
const parts = deserializeDeveloperId(id);
|
|
2561
|
+
if (!parts) {
|
|
2562
|
+
return null;
|
|
2563
|
+
}
|
|
2564
|
+
return hexToString(parts.table);
|
|
2565
|
+
}
|
|
2566
|
+
function isMatchingValidatorTable(idTableName, validatorTableName, componentPath) {
|
|
2567
|
+
if (idTableName === validatorTableName) {
|
|
2568
|
+
return true;
|
|
2569
|
+
}
|
|
2570
|
+
const { tableName: validatorBareName } = parseFullTableName(validatorTableName);
|
|
2571
|
+
const { tableName: idBareName } = parseFullTableName(idTableName);
|
|
2572
|
+
if (componentPath !== undefined) {
|
|
2573
|
+
const expectedFullName = getFullTableName(validatorBareName, componentPath);
|
|
2574
|
+
return idTableName === expectedFullName;
|
|
2575
|
+
}
|
|
2576
|
+
return idBareName === validatorBareName;
|
|
2577
|
+
}
|
|
2578
|
+
function isSimpleObject2(value) {
|
|
2579
|
+
const isObject = typeof value === "object";
|
|
2580
|
+
const prototype = Object.getPrototypeOf(value);
|
|
2581
|
+
const isSimple = prototype === null || prototype === Object.prototype || prototype?.constructor?.name === "Object";
|
|
2582
|
+
return isObject && isSimple;
|
|
2583
|
+
}
|
|
2584
|
+
var ValidatorError;
|
|
2585
|
+
var init_validator2 = __esm(() => {
|
|
2586
|
+
init_interface();
|
|
2587
|
+
init_module_loader();
|
|
2588
|
+
init_schema_service();
|
|
2589
|
+
ValidatorError = class ValidatorError extends Error {
|
|
2590
|
+
path;
|
|
2591
|
+
constructor(message, path = "") {
|
|
2592
|
+
super(message);
|
|
2593
|
+
this.path = path;
|
|
2594
|
+
this.name = "ValidatorError";
|
|
2595
|
+
}
|
|
2596
|
+
};
|
|
2597
|
+
});
|
|
2598
|
+
|
|
2599
|
+
// ../core/dist/kernel/schema-service.js
|
|
2600
|
+
class SchemaService {
|
|
2601
|
+
cachedSchemaDefinition = undefined;
|
|
2602
|
+
tableCache = new Map;
|
|
2603
|
+
schemaValidator;
|
|
2604
|
+
componentPath;
|
|
2605
|
+
constructor(componentPath) {
|
|
2606
|
+
this.componentPath = componentPath;
|
|
2607
|
+
this.schemaValidator = new SchemaValidator(componentPath);
|
|
2608
|
+
}
|
|
2609
|
+
async validate(tableName, document) {
|
|
2610
|
+
try {
|
|
2611
|
+
await this.schemaValidator.validateDocument(tableName, document);
|
|
2612
|
+
} catch (error) {
|
|
2613
|
+
if (error instanceof ValidatorError) {
|
|
2614
|
+
throw new Error(error.message);
|
|
2615
|
+
}
|
|
2616
|
+
throw error;
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
async getTableSchema(tableName) {
|
|
2620
|
+
if (this.tableCache.has(tableName)) {
|
|
2621
|
+
return this.tableCache.get(tableName) ?? null;
|
|
2622
|
+
}
|
|
2623
|
+
const schemaDefinition = await this.getSchemaDefinition();
|
|
2624
|
+
const tableSchema = schemaDefinition?.tables?.[tableName] ?? null;
|
|
2625
|
+
this.tableCache.set(tableName, tableSchema);
|
|
2626
|
+
return tableSchema;
|
|
2627
|
+
}
|
|
2628
|
+
async getIndexFieldsForTable(tableName, indexDescriptor) {
|
|
2629
|
+
if (indexDescriptor === "by_creation_time") {
|
|
2630
|
+
return ["_creationTime", "_id"];
|
|
2631
|
+
}
|
|
2632
|
+
if (indexDescriptor === "by_id") {
|
|
2633
|
+
return ["_id"];
|
|
2634
|
+
}
|
|
2635
|
+
const tableSchema = await this.getTableSchema(tableName);
|
|
2636
|
+
const dbIndexes = tableSchema?.indexes;
|
|
2637
|
+
const matchingIndex = dbIndexes?.find((idx) => idx.indexDescriptor === indexDescriptor);
|
|
2638
|
+
if (!matchingIndex) {
|
|
2639
|
+
return null;
|
|
2640
|
+
}
|
|
2641
|
+
return [...matchingIndex.fields, "_creationTime", "_id"];
|
|
2642
|
+
}
|
|
2643
|
+
async getAllIndexesForTable(tableName) {
|
|
2644
|
+
const indexes = [...getStandardIndexes()];
|
|
2645
|
+
const tableSchema = await this.getTableSchema(tableName);
|
|
2646
|
+
const schemaIndexes = tableSchema?.indexes;
|
|
2647
|
+
if (schemaIndexes) {
|
|
2648
|
+
for (const idx of schemaIndexes) {
|
|
2649
|
+
indexes.push({
|
|
2650
|
+
name: idx.indexDescriptor,
|
|
2651
|
+
fields: [...idx.fields, "_creationTime", "_id"]
|
|
2652
|
+
});
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
return indexes;
|
|
2656
|
+
}
|
|
2657
|
+
async getSearchIndexConfig(tableName, indexDescriptor) {
|
|
2658
|
+
const tableSchema = await this.getTableSchema(tableName);
|
|
2659
|
+
const searchIndexes = tableSchema?.searchIndexes;
|
|
2660
|
+
return searchIndexes?.find((idx) => idx.indexDescriptor === indexDescriptor) ?? null;
|
|
2661
|
+
}
|
|
2662
|
+
async getVectorIndexConfig(tableName, indexDescriptor) {
|
|
2663
|
+
const tableSchema = await this.getTableSchema(tableName);
|
|
2664
|
+
const vectorIndexes = tableSchema?.vectorIndexes;
|
|
2665
|
+
return vectorIndexes?.find((idx) => idx.indexDescriptor === indexDescriptor) ?? null;
|
|
2666
|
+
}
|
|
2667
|
+
async getAllVectorIndexes() {
|
|
2668
|
+
const schemaDefinition = await this.getSchemaDefinition();
|
|
2669
|
+
if (!schemaDefinition?.tables) {
|
|
2670
|
+
return [];
|
|
2671
|
+
}
|
|
2672
|
+
const allVectorIndexes = [];
|
|
2673
|
+
for (const [tableName, tableSchema] of Object.entries(schemaDefinition.tables)) {
|
|
2674
|
+
const vectorIndexes = tableSchema?.vectorIndexes;
|
|
2675
|
+
if (vectorIndexes) {
|
|
2676
|
+
for (const vectorIndex of vectorIndexes) {
|
|
2677
|
+
allVectorIndexes.push({
|
|
2678
|
+
tableName,
|
|
2679
|
+
indexDescriptor: vectorIndex.indexDescriptor,
|
|
2680
|
+
vectorField: vectorIndex.vectorField,
|
|
2681
|
+
filterFields: vectorIndex.filterFields ?? []
|
|
2682
|
+
});
|
|
2683
|
+
}
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
return allVectorIndexes;
|
|
2687
|
+
}
|
|
2688
|
+
async getAllSearchIndexes() {
|
|
2689
|
+
const schemaDefinition = await this.getSchemaDefinition();
|
|
2690
|
+
if (!schemaDefinition?.tables) {
|
|
2691
|
+
return [];
|
|
2692
|
+
}
|
|
2693
|
+
const allSearchIndexes = [];
|
|
2694
|
+
for (const [tableName, tableSchema] of Object.entries(schemaDefinition.tables)) {
|
|
2695
|
+
const searchIndexes = tableSchema?.searchIndexes;
|
|
2696
|
+
if (searchIndexes) {
|
|
2697
|
+
for (const searchIndex of searchIndexes) {
|
|
2698
|
+
allSearchIndexes.push({
|
|
2699
|
+
tableName,
|
|
2700
|
+
indexDescriptor: searchIndex.indexDescriptor,
|
|
2701
|
+
searchField: searchIndex.searchField,
|
|
2702
|
+
filterFields: searchIndex.filterFields ?? []
|
|
2703
|
+
});
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
return allSearchIndexes;
|
|
2708
|
+
}
|
|
2709
|
+
async getTableNames() {
|
|
2710
|
+
const schemaDefinition = await this.getSchemaDefinition();
|
|
2711
|
+
if (!schemaDefinition?.tables) {
|
|
2712
|
+
return [];
|
|
2713
|
+
}
|
|
2714
|
+
return Object.keys(schemaDefinition.tables);
|
|
2715
|
+
}
|
|
2716
|
+
async getSchemaDefinition() {
|
|
2717
|
+
if (this.cachedSchemaDefinition !== undefined) {
|
|
2718
|
+
return this.cachedSchemaDefinition;
|
|
2719
|
+
}
|
|
2720
|
+
try {
|
|
2721
|
+
const schemaModule = await loadConvexModule("schema", { hint: "schema", componentPath: this.componentPath });
|
|
2722
|
+
this.cachedSchemaDefinition = schemaModule.default ?? null;
|
|
2723
|
+
} catch (error) {
|
|
2724
|
+
if (!isMissingSchemaModuleError(error)) {
|
|
2725
|
+
console.warn("Failed to load Convex schema definition:", error);
|
|
2726
|
+
}
|
|
2727
|
+
this.cachedSchemaDefinition = null;
|
|
2728
|
+
}
|
|
2729
|
+
return this.cachedSchemaDefinition;
|
|
2730
|
+
}
|
|
2731
|
+
}
|
|
2732
|
+
function isMissingSchemaModuleError(error) {
|
|
2733
|
+
if (!error)
|
|
2734
|
+
return false;
|
|
2735
|
+
const errorString = String(error);
|
|
2736
|
+
const isMissing = errorString.includes('Unable to resolve module "schema"') || errorString.includes("Module not found: schema") || errorString.includes('Unable to resolve module "convex/schema"');
|
|
2737
|
+
if (isMissing)
|
|
2738
|
+
return true;
|
|
2739
|
+
const causes = error.causes;
|
|
2740
|
+
if (Array.isArray(causes)) {
|
|
2741
|
+
return causes.some(isMissingSchemaModuleError);
|
|
2742
|
+
}
|
|
2743
|
+
const cause = error.cause;
|
|
2744
|
+
if (cause) {
|
|
2745
|
+
return isMissingSchemaModuleError(cause);
|
|
2746
|
+
}
|
|
2747
|
+
return false;
|
|
2748
|
+
}
|
|
2749
|
+
var init_schema_service = __esm(() => {
|
|
2750
|
+
init_index_manager();
|
|
2751
|
+
init_validator2();
|
|
2752
|
+
init_module_loader();
|
|
2753
|
+
});
|
|
2754
|
+
|
|
2755
|
+
// ../core/dist/udf/analysis/udf-analyze.js
|
|
2756
|
+
function invalidUdfError(message) {
|
|
2757
|
+
return new UdfAnalysisError(message);
|
|
2758
|
+
}
|
|
2759
|
+
function analyzeFunction(exported_function, exportName, modulePath) {
|
|
2760
|
+
if (typeof exported_function !== "object" && typeof exported_function !== "function" || exported_function === null) {
|
|
2761
|
+
return null;
|
|
2762
|
+
}
|
|
2763
|
+
const isQuery = !!exported_function.isQuery;
|
|
2764
|
+
const isMutation = !!exported_function.isMutation;
|
|
2765
|
+
const isAction = !!exported_function.isAction;
|
|
2766
|
+
let udfType;
|
|
2767
|
+
if (isQuery && !isMutation && !isAction) {
|
|
2768
|
+
udfType = "query";
|
|
2769
|
+
} else if (!isQuery && isMutation && !isAction) {
|
|
2770
|
+
udfType = "mutation";
|
|
2771
|
+
} else if (!isQuery && !isMutation && isAction) {
|
|
2772
|
+
udfType = "action";
|
|
2773
|
+
} else {
|
|
2774
|
+
return null;
|
|
2775
|
+
}
|
|
2776
|
+
const isPublic = !!exported_function.isPublic;
|
|
2777
|
+
const isInternal = !!exported_function.isInternal;
|
|
2778
|
+
let visibility = null;
|
|
2779
|
+
if (isPublic && !isInternal) {
|
|
2780
|
+
visibility = "public";
|
|
2781
|
+
} else if (!isPublic && isInternal) {
|
|
2782
|
+
visibility = "internal";
|
|
2783
|
+
} else if (isPublic && isInternal) {
|
|
2784
|
+
console.warn(`Function ${exportName} is marked as both public and internal. Skipping.`);
|
|
2785
|
+
return null;
|
|
2786
|
+
} else if (!isPublic && !isInternal) {
|
|
2787
|
+
visibility = null;
|
|
2788
|
+
}
|
|
2789
|
+
const functionIdentifierForError = `${modulePath}:${exportName}`;
|
|
2790
|
+
let args = "Unvalidated";
|
|
2791
|
+
if (typeof exported_function.exportArgs === "function") {
|
|
2792
|
+
try {
|
|
2793
|
+
const argsJson = exported_function.exportArgs();
|
|
2794
|
+
if (typeof argsJson !== "string") {
|
|
2795
|
+
throw invalidUdfError(`${functionIdentifierForError}.exportArgs() didn't return a string.`);
|
|
2796
|
+
}
|
|
2797
|
+
args = JSON.parse(argsJson);
|
|
2798
|
+
} catch (e) {
|
|
2799
|
+
throw invalidUdfError(`Invalid JSON returned from ${functionIdentifierForError}.exportArgs(): ${e.message}`);
|
|
2800
|
+
}
|
|
2801
|
+
} else if (exported_function.exportArgs !== undefined) {
|
|
2802
|
+
throw invalidUdfError(`${functionIdentifierForError}.exportArgs is not a function or \`undefined\`.`);
|
|
2803
|
+
}
|
|
2804
|
+
let returns = "Unvalidated";
|
|
2805
|
+
if (typeof exported_function.exportReturns === "function") {
|
|
2806
|
+
try {
|
|
2807
|
+
const returnsJson = exported_function.exportReturns();
|
|
2808
|
+
if (typeof returnsJson !== "string") {
|
|
2809
|
+
throw invalidUdfError(`${functionIdentifierForError}.exportReturns() didn't return a string.`);
|
|
2810
|
+
}
|
|
2811
|
+
returns = JSON.parse(returnsJson);
|
|
2812
|
+
} catch (e) {
|
|
2813
|
+
throw invalidUdfError(`Invalid JSON returned from ${functionIdentifierForError}.exportReturns(): ${e.message}`);
|
|
2814
|
+
}
|
|
2815
|
+
} else if (exported_function.exportReturns !== undefined) {
|
|
2816
|
+
throw invalidUdfError(`${functionIdentifierForError}.exportReturns is not a function or \`undefined\`.`);
|
|
2817
|
+
}
|
|
2818
|
+
return {
|
|
2819
|
+
name: exportName,
|
|
2820
|
+
udfType,
|
|
2821
|
+
visibility,
|
|
2822
|
+
args,
|
|
2823
|
+
returns,
|
|
2824
|
+
pos: null
|
|
2825
|
+
};
|
|
2826
|
+
}
|
|
2827
|
+
function analyzeUdfModule(module, modulePath) {
|
|
2828
|
+
const functions = [];
|
|
2829
|
+
let httpRoutes = null;
|
|
2830
|
+
let cronSpecs = null;
|
|
2831
|
+
if (isHttpModule(modulePath)) {
|
|
2832
|
+
if (!module.default) {
|
|
2833
|
+
throw invalidUdfError(`\`convex/http.js\` must have a default export of a Router.`);
|
|
2834
|
+
}
|
|
2835
|
+
httpRoutes = analyzeHttp(module.default);
|
|
2836
|
+
} else if (isCronsModule(modulePath)) {
|
|
2837
|
+
if (!module.default) {
|
|
2838
|
+
throw invalidUdfError(`\`convex/crons.js\` must have a default export of a Crons object.`);
|
|
2839
|
+
}
|
|
2840
|
+
cronSpecs = analyzeCrons(module.default);
|
|
2841
|
+
} else {
|
|
2842
|
+
for (const exportName in module) {
|
|
2843
|
+
if (!Object.hasOwn(module, exportName)) {
|
|
2844
|
+
continue;
|
|
2845
|
+
}
|
|
2846
|
+
let exportedValue;
|
|
2847
|
+
try {
|
|
2848
|
+
exportedValue = module[exportName];
|
|
2849
|
+
} catch (error) {
|
|
2850
|
+
console.warn(`Skipping export "${exportName}" in module "${modulePath}":`, error);
|
|
2851
|
+
continue;
|
|
2852
|
+
}
|
|
2853
|
+
const analyzedFunc = analyzeFunction(exportedValue, exportName, modulePath);
|
|
2854
|
+
if (analyzedFunc) {
|
|
2855
|
+
functions.push(analyzedFunc);
|
|
2856
|
+
}
|
|
2857
|
+
}
|
|
2858
|
+
}
|
|
2859
|
+
functions.sort((a, b) => a.name.localeCompare(b.name));
|
|
2860
|
+
if (httpRoutes) {
|
|
2861
|
+
httpRoutes.routes.sort((a, b) => a.route.path.localeCompare(b.route.path));
|
|
2862
|
+
}
|
|
2863
|
+
return {
|
|
2864
|
+
functions,
|
|
2865
|
+
httpRoutes,
|
|
2866
|
+
cronSpecs
|
|
2867
|
+
};
|
|
2868
|
+
}
|
|
2869
|
+
function isHttpModule(modulePath) {
|
|
2870
|
+
return matchesModuleSpecifier(modulePath, "http");
|
|
2871
|
+
}
|
|
2872
|
+
function isCronsModule(modulePath) {
|
|
2873
|
+
return matchesModuleSpecifier(modulePath, "crons");
|
|
2874
|
+
}
|
|
2875
|
+
function matchesModuleSpecifier(modulePath, moduleName) {
|
|
2876
|
+
const normalized = normalizeModuleSpecifier(modulePath);
|
|
2877
|
+
return normalized === moduleName || normalized.endsWith(`/${moduleName}`);
|
|
2878
|
+
}
|
|
2879
|
+
function normalizeModuleSpecifier(modulePath) {
|
|
2880
|
+
return modulePath.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\.(?:cjs|mjs|js|jsx|ts|tsx)$/i, "");
|
|
2881
|
+
}
|
|
2882
|
+
function analyzeHttp(router) {
|
|
2883
|
+
if (typeof router !== "object" || router === null) {
|
|
2884
|
+
throw invalidUdfError("The default export of `convex/http.js` is not a Router.");
|
|
2885
|
+
}
|
|
2886
|
+
if (!router.isRouter) {
|
|
2887
|
+
throw invalidUdfError("The default export of `convex/http.js` is not a Router.");
|
|
2888
|
+
}
|
|
2889
|
+
if (typeof router.getRoutes !== "function") {
|
|
2890
|
+
throw invalidUdfError(".getRoutes property on Router not found");
|
|
2891
|
+
}
|
|
2892
|
+
const routesArr = router.getRoutes();
|
|
2893
|
+
if (!Array.isArray(routesArr)) {
|
|
2894
|
+
throw invalidUdfError("The `getRoutes()` method of Router did not return an array.");
|
|
2895
|
+
}
|
|
2896
|
+
const http_routes = [];
|
|
2897
|
+
for (const entry of routesArr) {
|
|
2898
|
+
if (!Array.isArray(entry) || entry.length < 3) {
|
|
2899
|
+
throw invalidUdfError("Invalid entry in routes array: must be [path, method, handler]");
|
|
2900
|
+
}
|
|
2901
|
+
const [path, method, handler] = entry;
|
|
2902
|
+
if (typeof path !== "string" || typeof method !== "string") {
|
|
2903
|
+
throw invalidUdfError("Invalid entry in routes array: path and method must be strings.");
|
|
2904
|
+
}
|
|
2905
|
+
const upperMethod = method.toUpperCase();
|
|
2906
|
+
if (!["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"].includes(upperMethod)) {
|
|
2907
|
+
throw invalidUdfError(`'${method}' is not not a routable method.`);
|
|
2908
|
+
}
|
|
2909
|
+
const handlerType = typeof handler;
|
|
2910
|
+
const handlerIsObjectLike = handlerType === "object" && handler !== null || handlerType === "function";
|
|
2911
|
+
if (!handlerIsObjectLike || !handler?.isHttp) {
|
|
2912
|
+
throw invalidUdfError("Invalid entry in routes array: handler is not an HTTP action.");
|
|
2913
|
+
}
|
|
2914
|
+
http_routes.push({
|
|
2915
|
+
route: {
|
|
2916
|
+
path,
|
|
2917
|
+
method: upperMethod
|
|
2918
|
+
},
|
|
2919
|
+
pos: null
|
|
2920
|
+
});
|
|
2921
|
+
}
|
|
2922
|
+
return { routes: http_routes };
|
|
2923
|
+
}
|
|
2924
|
+
function analyzeCrons(crons) {
|
|
2925
|
+
if (typeof crons !== "object" || crons === null) {
|
|
2926
|
+
throw invalidUdfError("The default export of `convex/crons.js` is not a Crons object.");
|
|
2927
|
+
}
|
|
2928
|
+
if (!crons.isCrons) {
|
|
2929
|
+
throw invalidUdfError("The default export of `convex/crons.js` is not a Crons object.");
|
|
2930
|
+
}
|
|
2931
|
+
if (typeof crons.export !== "function") {
|
|
2932
|
+
throw invalidUdfError(".export property on Crons object not found");
|
|
2933
|
+
}
|
|
2934
|
+
const exportedJson = crons.export();
|
|
2935
|
+
if (typeof exportedJson !== "string") {
|
|
2936
|
+
throw invalidUdfError(".export() of Crons object did not return a string.");
|
|
2937
|
+
}
|
|
2938
|
+
try {
|
|
2939
|
+
return JSON.parse(exportedJson);
|
|
2940
|
+
} catch (e) {
|
|
2941
|
+
throw invalidUdfError(`Invalid JSON returned from .export() of Crons object: ${e.message}`);
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
var UdfAnalysisError;
|
|
2945
|
+
var init_udf_analyze = __esm(() => {
|
|
2946
|
+
UdfAnalysisError = class UdfAnalysisError extends Error {
|
|
2947
|
+
constructor(message) {
|
|
2948
|
+
super(message);
|
|
2949
|
+
this.name = "UdfAnalysisError";
|
|
2950
|
+
}
|
|
2951
|
+
};
|
|
2952
|
+
});
|
|
2953
|
+
|
|
2954
|
+
// ../core/dist/udf/analysis/index.js
|
|
2955
|
+
var init_analysis = __esm(() => {
|
|
2956
|
+
init_udf_analyze();
|
|
2957
|
+
init_validator2();
|
|
2958
|
+
});
|
|
2959
|
+
|
|
2960
|
+
// ../core/dist/system/function-introspection.js
|
|
2961
|
+
async function listSystemFunctions(options = {}) {
|
|
2962
|
+
const componentPath = options.componentPath;
|
|
2963
|
+
const moduleLoader = await ensureModuleLoaderApi();
|
|
2964
|
+
const listings = await moduleLoader.listRegisteredModules({
|
|
2965
|
+
componentPath,
|
|
2966
|
+
hint: "udf"
|
|
2967
|
+
});
|
|
2968
|
+
const filteredListings = listings.filter((listing) => {
|
|
2969
|
+
if (listing.path.startsWith("_generated/") || listing.path.startsWith("_system")) {
|
|
2970
|
+
return false;
|
|
2971
|
+
}
|
|
2972
|
+
const listingComponentPath = listing.componentPath || undefined;
|
|
2973
|
+
if (componentPath === undefined) {
|
|
2974
|
+
return listingComponentPath === undefined;
|
|
2975
|
+
}
|
|
2976
|
+
return listingComponentPath === componentPath;
|
|
2977
|
+
});
|
|
2978
|
+
const analysisResults = await pooledMap(filteredListings, (listing) => analyzeModule(listing, componentPath), 20);
|
|
2979
|
+
const results = [];
|
|
2980
|
+
for (let i2 = 0;i2 < filteredListings.length; i2++) {
|
|
2981
|
+
const listing = filteredListings[i2];
|
|
2982
|
+
const result = analysisResults[i2];
|
|
2983
|
+
if (result.status === "rejected") {
|
|
2984
|
+
if (!isNpmPackageError(result.reason)) {
|
|
2985
|
+
console.warn(`Failed to analyze module "${listing.path}":`, result.reason);
|
|
2986
|
+
}
|
|
2987
|
+
continue;
|
|
2988
|
+
}
|
|
2989
|
+
const { analyzed } = result.value;
|
|
2990
|
+
const sourcePath = listing.source ?? buildFallbackSourcePath(listing.path);
|
|
2991
|
+
const owningComponent = listing.componentPath || undefined;
|
|
2992
|
+
const functions = analyzed.functions ?? [];
|
|
2993
|
+
const httpRoutes = analyzed.httpRoutes?.routes ?? [];
|
|
2994
|
+
if (functions.length === 0 && httpRoutes.length === 0) {
|
|
2995
|
+
continue;
|
|
2996
|
+
}
|
|
2997
|
+
for (const fn of functions) {
|
|
2998
|
+
results.push({
|
|
2999
|
+
name: fn.name,
|
|
3000
|
+
module: listing.path,
|
|
3001
|
+
path: `${listing.path}:${fn.name}`,
|
|
3002
|
+
type: fn.udfType,
|
|
3003
|
+
visibility: fn.visibility ?? null,
|
|
3004
|
+
args: fn.args,
|
|
3005
|
+
returns: fn.returns,
|
|
3006
|
+
source: sourcePath,
|
|
3007
|
+
componentPath: owningComponent
|
|
3008
|
+
});
|
|
3009
|
+
}
|
|
3010
|
+
for (const route of httpRoutes) {
|
|
3011
|
+
const method = route.route.method;
|
|
3012
|
+
const routePath = route.route.path;
|
|
3013
|
+
results.push({
|
|
3014
|
+
name: `${method} ${routePath}`,
|
|
3015
|
+
module: listing.path,
|
|
3016
|
+
path: `${listing.path}:${method}:${routePath}`,
|
|
3017
|
+
type: "http",
|
|
3018
|
+
visibility: null,
|
|
3019
|
+
source: sourcePath,
|
|
3020
|
+
componentPath: owningComponent,
|
|
3021
|
+
httpMethod: method,
|
|
3022
|
+
httpPath: routePath
|
|
3023
|
+
});
|
|
3024
|
+
}
|
|
3025
|
+
}
|
|
3026
|
+
results.sort((a, b) => {
|
|
3027
|
+
const moduleComparison = a.module.localeCompare(b.module);
|
|
3028
|
+
if (moduleComparison !== 0) {
|
|
3029
|
+
return moduleComparison;
|
|
3030
|
+
}
|
|
3031
|
+
return a.name.localeCompare(b.name);
|
|
3032
|
+
});
|
|
3033
|
+
return results;
|
|
3034
|
+
}
|
|
3035
|
+
async function ensureModuleLoaderApi() {
|
|
3036
|
+
if (!moduleLoaderApiPromise) {
|
|
3037
|
+
moduleLoaderApiPromise = Promise.resolve().then(() => (init_module_loader(), exports_module_loader));
|
|
3038
|
+
}
|
|
3039
|
+
const api = await moduleLoaderApiPromise;
|
|
3040
|
+
if (!unsubscribeModuleLoader) {
|
|
3041
|
+
unsubscribeModuleLoader = api.onModuleLoadersChanged(() => moduleAnalysisCache.clear());
|
|
3042
|
+
}
|
|
3043
|
+
return api;
|
|
3044
|
+
}
|
|
3045
|
+
async function analyzeModule(listing, componentPath) {
|
|
3046
|
+
const cacheKey = makeCacheKey(componentPath, listing.path);
|
|
3047
|
+
let cached = moduleAnalysisCache.get(cacheKey);
|
|
3048
|
+
if (!cached) {
|
|
3049
|
+
cached = loadAndAnalyzeModule(listing, componentPath);
|
|
3050
|
+
cached.catch(() => moduleAnalysisCache.delete(cacheKey));
|
|
3051
|
+
moduleAnalysisCache.set(cacheKey, cached);
|
|
3052
|
+
}
|
|
3053
|
+
return cached;
|
|
3054
|
+
}
|
|
3055
|
+
async function loadAndAnalyzeModule(listing, componentPath) {
|
|
3056
|
+
const moduleLoader = await ensureModuleLoaderApi();
|
|
3057
|
+
const module = await moduleLoader.loadConvexModule(listing.path, {
|
|
3058
|
+
componentPath,
|
|
3059
|
+
hint: listing.hint ?? "udf"
|
|
3060
|
+
});
|
|
3061
|
+
const sourcePath = listing.source ?? buildFallbackSourcePath(listing.path);
|
|
3062
|
+
const analyzed = analyzeUdfModule(module, sourcePath);
|
|
3063
|
+
return {
|
|
3064
|
+
listing: {
|
|
3065
|
+
...listing,
|
|
3066
|
+
source: sourcePath
|
|
3067
|
+
},
|
|
3068
|
+
analyzed
|
|
3069
|
+
};
|
|
3070
|
+
}
|
|
3071
|
+
function makeCacheKey(componentPath, modulePath) {
|
|
3072
|
+
return `${componentPath ?? ""}::${modulePath}`;
|
|
3073
|
+
}
|
|
3074
|
+
function buildFallbackSourcePath(modulePath) {
|
|
3075
|
+
const trimmed = modulePath.replace(/\\/g, "/").replace(/^\//, "");
|
|
3076
|
+
const withConvex = trimmed.startsWith("convex/") ? trimmed : `convex/${trimmed}`;
|
|
3077
|
+
return withConvex.endsWith(".ts") || withConvex.endsWith(".js") ? withConvex : `${withConvex}.ts`;
|
|
3078
|
+
}
|
|
3079
|
+
async function pooledMap(items, fn, concurrency) {
|
|
3080
|
+
const results = new Array(items.length);
|
|
3081
|
+
let next = 0;
|
|
3082
|
+
async function worker() {
|
|
3083
|
+
while (next < items.length) {
|
|
3084
|
+
const idx = next++;
|
|
3085
|
+
try {
|
|
3086
|
+
results[idx] = { status: "fulfilled", value: await fn(items[idx]) };
|
|
3087
|
+
} catch (reason) {
|
|
3088
|
+
results[idx] = { status: "rejected", reason };
|
|
3089
|
+
}
|
|
3090
|
+
}
|
|
3091
|
+
}
|
|
3092
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, () => worker()));
|
|
3093
|
+
return results;
|
|
3094
|
+
}
|
|
3095
|
+
function isNpmPackageError(error) {
|
|
3096
|
+
if (!(error instanceof Error))
|
|
3097
|
+
return false;
|
|
3098
|
+
const causes = error.causes;
|
|
3099
|
+
if (!Array.isArray(causes))
|
|
3100
|
+
return false;
|
|
3101
|
+
return causes.some((cause) => {
|
|
3102
|
+
if (!(cause instanceof Error))
|
|
3103
|
+
return false;
|
|
3104
|
+
const match = cause.message.match(/Module not found: ([^\s]+)/);
|
|
3105
|
+
if (!match)
|
|
3106
|
+
return false;
|
|
3107
|
+
const modulePath = match[1];
|
|
3108
|
+
return !modulePath.startsWith(".") && !modulePath.startsWith("/");
|
|
3109
|
+
});
|
|
3110
|
+
}
|
|
3111
|
+
var moduleAnalysisCache, moduleLoaderApiPromise = null, unsubscribeModuleLoader = null;
|
|
3112
|
+
var init_function_introspection = __esm(() => {
|
|
3113
|
+
init_analysis();
|
|
3114
|
+
moduleAnalysisCache = new Map;
|
|
3115
|
+
});
|
|
3116
|
+
|
|
3117
|
+
// ../core/dist/system/execution-log.js
|
|
3118
|
+
class InMemoryLogSink {
|
|
3119
|
+
entries = [];
|
|
3120
|
+
nextId = 1;
|
|
3121
|
+
maxEntries;
|
|
3122
|
+
constructor(maxEntries = MAX_ENTRIES) {
|
|
3123
|
+
this.maxEntries = maxEntries;
|
|
3124
|
+
}
|
|
3125
|
+
record(entry) {
|
|
3126
|
+
const logEntry = {
|
|
3127
|
+
...entry,
|
|
3128
|
+
id: `log_${this.nextId++}`
|
|
3129
|
+
};
|
|
3130
|
+
if (this.entries.length >= this.maxEntries) {
|
|
3131
|
+
this.entries.shift();
|
|
3132
|
+
}
|
|
3133
|
+
this.entries.push(logEntry);
|
|
3134
|
+
}
|
|
3135
|
+
query(filter = {}) {
|
|
3136
|
+
let result = this.entries;
|
|
3137
|
+
if (filter.functionType) {
|
|
3138
|
+
result = result.filter((e) => e.functionType === filter.functionType);
|
|
3139
|
+
}
|
|
3140
|
+
if (filter.status) {
|
|
3141
|
+
result = result.filter((e) => e.status === filter.status);
|
|
3142
|
+
}
|
|
3143
|
+
if (filter.search) {
|
|
3144
|
+
const search = filter.search.toLowerCase();
|
|
3145
|
+
result = result.filter((e) => e.functionName.toLowerCase().includes(search) || e.logLines.some((l) => l.toLowerCase().includes(search)) || e.error && e.error.toLowerCase().includes(search));
|
|
3146
|
+
}
|
|
3147
|
+
const reversed = [...result].reverse();
|
|
3148
|
+
if (filter.limit && filter.limit > 0) {
|
|
3149
|
+
return reversed.slice(0, filter.limit);
|
|
3150
|
+
}
|
|
3151
|
+
return reversed;
|
|
3152
|
+
}
|
|
3153
|
+
clear() {
|
|
3154
|
+
this.entries = [];
|
|
3155
|
+
}
|
|
3156
|
+
get size() {
|
|
3157
|
+
return this.entries.length;
|
|
3158
|
+
}
|
|
3159
|
+
}
|
|
3160
|
+
function queryExecutionLog(filter = {}) {
|
|
3161
|
+
return defaultSink.query(filter);
|
|
3162
|
+
}
|
|
3163
|
+
function clearExecutionLog() {
|
|
3164
|
+
defaultSink.clear();
|
|
3165
|
+
}
|
|
3166
|
+
var MAX_ENTRIES = 1000, defaultSink;
|
|
3167
|
+
var init_execution_log = __esm(() => {
|
|
3168
|
+
defaultSink = new InMemoryLogSink;
|
|
3169
|
+
});
|
|
3170
|
+
|
|
3171
|
+
// ../core/dist/system/internal.js
|
|
3172
|
+
function createSystemFunctions(deps) {
|
|
3173
|
+
const { query, mutation } = deps;
|
|
3174
|
+
return {
|
|
3175
|
+
systemListComponents: query({
|
|
3176
|
+
args: {},
|
|
3177
|
+
handler: async (_ctx) => {
|
|
3178
|
+
const modules = await listRegisteredModules();
|
|
3179
|
+
const componentPaths = new Set;
|
|
3180
|
+
componentPaths.add("");
|
|
3181
|
+
for (const module of modules) {
|
|
3182
|
+
if (module.componentPath) {
|
|
3183
|
+
componentPaths.add(module.componentPath);
|
|
3184
|
+
}
|
|
3185
|
+
}
|
|
3186
|
+
const components = [];
|
|
3187
|
+
for (const path of componentPaths) {
|
|
3188
|
+
const componentModules = modules.filter((m) => path === "" ? !m.componentPath || m.componentPath === "" : m.componentPath === path);
|
|
3189
|
+
const functions = await listSystemFunctions({ componentPath: path || undefined });
|
|
3190
|
+
components.push({
|
|
3191
|
+
path: path || "(root)",
|
|
3192
|
+
isRoot: path === "",
|
|
3193
|
+
moduleCount: componentModules.length,
|
|
3194
|
+
functionCount: functions.length
|
|
3195
|
+
});
|
|
3196
|
+
}
|
|
3197
|
+
return components.sort((a, b) => {
|
|
3198
|
+
if (a.isRoot)
|
|
3199
|
+
return -1;
|
|
3200
|
+
if (b.isRoot)
|
|
3201
|
+
return 1;
|
|
3202
|
+
return a.path.localeCompare(b.path);
|
|
3203
|
+
});
|
|
3204
|
+
}
|
|
3205
|
+
}),
|
|
3206
|
+
systemListTables: query({
|
|
3207
|
+
args: { componentPath: v.optional(v.string()) },
|
|
3208
|
+
handler: async (ctx, { componentPath }) => {
|
|
3209
|
+
const targetComponent = componentPath ?? "";
|
|
3210
|
+
const schema = await loadSchemaDefinition(targetComponent);
|
|
3211
|
+
let tableEntries = [];
|
|
3212
|
+
if (schema?.tables) {
|
|
3213
|
+
tableEntries = extractTablesFromSchema(schema);
|
|
3214
|
+
} else {
|
|
3215
|
+
try {
|
|
3216
|
+
const systemTables = await ctx.db.system.query("_tables").collect();
|
|
3217
|
+
tableEntries = systemTables.map((table) => ({
|
|
3218
|
+
name: table.name,
|
|
3219
|
+
exported: {
|
|
3220
|
+
indexes: table.indexes || [],
|
|
3221
|
+
searchIndexes: table.searchIndexes || [],
|
|
3222
|
+
vectorIndexes: table.vectorIndexes || [],
|
|
3223
|
+
documentType: null
|
|
3224
|
+
}
|
|
3225
|
+
}));
|
|
3226
|
+
} catch {
|
|
3227
|
+
tableEntries = [];
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
const tableInfo = await Promise.all(tableEntries.map(async (table) => {
|
|
3231
|
+
const fullName = getFullTableName(table.name, targetComponent);
|
|
3232
|
+
const documentCount = await countDocuments(ctx, fullName);
|
|
3233
|
+
const exported = table.exported;
|
|
3234
|
+
const searchIndexes = exported?.searchIndexes ?? [];
|
|
3235
|
+
const vectorIndexes = exported?.vectorIndexes ?? [];
|
|
3236
|
+
return {
|
|
3237
|
+
name: table.name,
|
|
3238
|
+
fullName,
|
|
3239
|
+
componentPath: targetComponent || undefined,
|
|
3240
|
+
documentCount,
|
|
3241
|
+
indexes: buildIndexList(exported?.indexes),
|
|
3242
|
+
searchIndexes: searchIndexes.map((idx) => typeof idx === "string" ? idx : idx.indexDescriptor),
|
|
3243
|
+
vectorIndexes: vectorIndexes.map((idx) => typeof idx === "string" ? idx : idx.indexDescriptor)
|
|
3244
|
+
};
|
|
3245
|
+
}));
|
|
3246
|
+
return tableInfo.sort((a, b) => a.name.localeCompare(b.name));
|
|
3247
|
+
}
|
|
3248
|
+
}),
|
|
3249
|
+
systemGetTableSchema: query({
|
|
3250
|
+
args: { tableName: v.string(), componentPath: v.optional(v.string()) },
|
|
3251
|
+
handler: async (ctx, { tableName, componentPath }) => {
|
|
3252
|
+
const targetComponent = componentPath ?? "";
|
|
3253
|
+
const schema = await loadSchemaDefinition(targetComponent);
|
|
3254
|
+
const tableMeta = schema ? extractTableMetadata(schema, tableName) : null;
|
|
3255
|
+
if (tableMeta?.exported) {
|
|
3256
|
+
const exported = tableMeta.exported;
|
|
3257
|
+
const fields = extractFieldsFromDocumentType(exported.documentType, tableName);
|
|
3258
|
+
return {
|
|
3259
|
+
tableName,
|
|
3260
|
+
componentPath: targetComponent || undefined,
|
|
3261
|
+
fields,
|
|
3262
|
+
indexes: buildIndexList(exported.indexes).map((name) => ({
|
|
3263
|
+
name,
|
|
3264
|
+
fields: findIndexFields(exported.indexes, name)
|
|
3265
|
+
})),
|
|
3266
|
+
searchIndexes: buildSearchIndexMetadata(exported.searchIndexes),
|
|
3267
|
+
vectorIndexes: buildVectorIndexMetadata(exported.vectorIndexes)
|
|
3268
|
+
};
|
|
3269
|
+
}
|
|
3270
|
+
try {
|
|
3271
|
+
const fullName = getFullTableName(tableName, targetComponent);
|
|
3272
|
+
const sampleDoc = await ctx.db.query(fullName).first();
|
|
3273
|
+
const fields = sampleDoc ? Object.keys(sampleDoc).map((key) => ({
|
|
3274
|
+
name: key,
|
|
3275
|
+
type: typeof sampleDoc[key],
|
|
3276
|
+
optional: false
|
|
3277
|
+
})) : [];
|
|
3278
|
+
return {
|
|
3279
|
+
tableName,
|
|
3280
|
+
componentPath: targetComponent || undefined,
|
|
3281
|
+
fields,
|
|
3282
|
+
indexes: [
|
|
3283
|
+
{ name: "by_id", fields: ["_id"] },
|
|
3284
|
+
{ name: "by_creation_time", fields: ["_creationTime"] }
|
|
3285
|
+
],
|
|
3286
|
+
searchIndexes: [],
|
|
3287
|
+
vectorIndexes: []
|
|
3288
|
+
};
|
|
3289
|
+
} catch (error) {
|
|
3290
|
+
console.warn(`Failed to resolve schema for table ${tableName}:`, error);
|
|
3291
|
+
return null;
|
|
3292
|
+
}
|
|
3293
|
+
}
|
|
3294
|
+
}),
|
|
3295
|
+
systemGetTableData: query({
|
|
3296
|
+
args: {
|
|
3297
|
+
tableName: v.string(),
|
|
3298
|
+
componentPath: v.optional(v.string()),
|
|
3299
|
+
page: v.number(),
|
|
3300
|
+
pageSize: v.number(),
|
|
3301
|
+
orderBy: v.optional(v.string()),
|
|
3302
|
+
order: v.optional(v.string())
|
|
3303
|
+
},
|
|
3304
|
+
handler: async (ctx, args) => {
|
|
3305
|
+
const fullName = getFullTableName(args.tableName, args.componentPath ?? "");
|
|
3306
|
+
let query2 = ctx.db.query(fullName);
|
|
3307
|
+
if (args.orderBy && args.orderBy !== "_creationTime") {
|
|
3308
|
+
const allDocs2 = await query2.collect();
|
|
3309
|
+
const sorted = allDocs2.sort((a, b) => {
|
|
3310
|
+
const aVal = a[args.orderBy];
|
|
3311
|
+
const bVal = b[args.orderBy];
|
|
3312
|
+
if (aVal < bVal)
|
|
3313
|
+
return args.order === "desc" ? 1 : -1;
|
|
3314
|
+
if (aVal > bVal)
|
|
3315
|
+
return args.order === "desc" ? -1 : 1;
|
|
3316
|
+
return 0;
|
|
3317
|
+
});
|
|
3318
|
+
const start2 = (args.page - 1) * args.pageSize;
|
|
3319
|
+
const end2 = start2 + args.pageSize;
|
|
3320
|
+
const paginatedData2 = sorted.slice(start2, end2);
|
|
3321
|
+
return {
|
|
3322
|
+
data: paginatedData2,
|
|
3323
|
+
total: sorted.length,
|
|
3324
|
+
page: args.page,
|
|
3325
|
+
pageSize: args.pageSize,
|
|
3326
|
+
hasMore: end2 < sorted.length
|
|
3327
|
+
};
|
|
3328
|
+
}
|
|
3329
|
+
if (args.order === "desc") {
|
|
3330
|
+
query2 = query2.order("desc");
|
|
3331
|
+
}
|
|
3332
|
+
const allDocs = await query2.collect();
|
|
3333
|
+
const start = (args.page - 1) * args.pageSize;
|
|
3334
|
+
const end = start + args.pageSize;
|
|
3335
|
+
const paginatedData = allDocs.slice(start, end);
|
|
3336
|
+
return {
|
|
3337
|
+
data: paginatedData,
|
|
3338
|
+
total: allDocs.length,
|
|
3339
|
+
page: args.page,
|
|
3340
|
+
pageSize: args.pageSize,
|
|
3341
|
+
hasMore: end < allDocs.length
|
|
3342
|
+
};
|
|
3343
|
+
}
|
|
3344
|
+
}),
|
|
3345
|
+
systemDeleteDocument: mutation({
|
|
3346
|
+
args: { tableName: v.string(), documentId: v.string() },
|
|
3347
|
+
handler: async (ctx, { documentId }) => {
|
|
3348
|
+
await ctx.db.delete(documentId);
|
|
3349
|
+
}
|
|
3350
|
+
}),
|
|
3351
|
+
systemClearTable: mutation({
|
|
3352
|
+
args: { tableName: v.string(), componentPath: v.optional(v.string()) },
|
|
3353
|
+
handler: async (ctx, args) => {
|
|
3354
|
+
const fullName = getFullTableName(args.tableName, args.componentPath ?? "");
|
|
3355
|
+
const docs = await ctx.db.query(fullName).collect();
|
|
3356
|
+
for (const doc of docs) {
|
|
3357
|
+
await ctx.db.delete(doc._id);
|
|
3358
|
+
}
|
|
3359
|
+
return { deleted: docs.length };
|
|
3360
|
+
}
|
|
3361
|
+
}),
|
|
3362
|
+
systemUpdateDocument: mutation({
|
|
3363
|
+
args: {
|
|
3364
|
+
tableName: v.string(),
|
|
3365
|
+
documentId: v.string(),
|
|
3366
|
+
data: v.any()
|
|
3367
|
+
},
|
|
3368
|
+
handler: async (ctx, { documentId, data }) => {
|
|
3369
|
+
await ctx.db.patch(documentId, data);
|
|
3370
|
+
}
|
|
3371
|
+
}),
|
|
3372
|
+
systemGetLogs: query({
|
|
3373
|
+
args: {
|
|
3374
|
+
limit: v.number(),
|
|
3375
|
+
functionType: v.optional(v.string()),
|
|
3376
|
+
status: v.optional(v.string()),
|
|
3377
|
+
search: v.optional(v.string())
|
|
3378
|
+
},
|
|
3379
|
+
handler: async (_ctx, args) => {
|
|
3380
|
+
return queryExecutionLog({
|
|
3381
|
+
limit: args.limit,
|
|
3382
|
+
functionType: args.functionType,
|
|
3383
|
+
status: args.status,
|
|
3384
|
+
search: args.search
|
|
3385
|
+
});
|
|
3386
|
+
}
|
|
3387
|
+
}),
|
|
3388
|
+
systemClearLogs: mutation({
|
|
3389
|
+
args: {},
|
|
3390
|
+
handler: async () => {
|
|
3391
|
+
clearExecutionLog();
|
|
3392
|
+
return { cleared: true };
|
|
3393
|
+
}
|
|
3394
|
+
}),
|
|
3395
|
+
systemGetAnalytics: query({
|
|
3396
|
+
args: { timeRange: v.string() },
|
|
3397
|
+
handler: async (ctx, { timeRange }) => {
|
|
3398
|
+
const now = Date.now();
|
|
3399
|
+
const ranges = {
|
|
3400
|
+
"24h": 24 * 60 * 60 * 1000,
|
|
3401
|
+
"7d": 7 * 24 * 60 * 60 * 1000,
|
|
3402
|
+
"30d": 30 * 24 * 60 * 60 * 1000
|
|
3403
|
+
};
|
|
3404
|
+
const cutoff = now - (ranges[timeRange] || ranges["24h"]);
|
|
3405
|
+
try {
|
|
3406
|
+
const scheduled = await ctx.db.system.query("_scheduled_functions").filter((q) => q.gte(q.field("_creationTime"), cutoff)).collect();
|
|
3407
|
+
const failed = scheduled.filter((s) => s.state?.kind === "failed").length;
|
|
3408
|
+
const total = scheduled.length;
|
|
3409
|
+
return {
|
|
3410
|
+
totalRequests: total,
|
|
3411
|
+
errorRate: total > 0 ? failed / total * 100 : 0,
|
|
3412
|
+
p50Latency: 50,
|
|
3413
|
+
p95Latency: 100,
|
|
3414
|
+
p99Latency: 200,
|
|
3415
|
+
activeConnections: 0,
|
|
3416
|
+
requestsOverTime: [],
|
|
3417
|
+
functionCallsByType: {
|
|
3418
|
+
query: 0,
|
|
3419
|
+
mutation: scheduled.length,
|
|
3420
|
+
action: 0
|
|
3421
|
+
},
|
|
3422
|
+
tableOperations: {},
|
|
3423
|
+
storageUsed: 0
|
|
3424
|
+
};
|
|
3425
|
+
} catch (e) {
|
|
3426
|
+
console.debug("[systemGetAnalytics] Failed to query system tables:", e);
|
|
3427
|
+
return {
|
|
3428
|
+
totalRequests: 0,
|
|
3429
|
+
errorRate: 0,
|
|
3430
|
+
p50Latency: 0,
|
|
3431
|
+
p95Latency: 0,
|
|
3432
|
+
p99Latency: 0,
|
|
3433
|
+
activeConnections: 0,
|
|
3434
|
+
requestsOverTime: [],
|
|
3435
|
+
functionCallsByType: {},
|
|
3436
|
+
tableOperations: {},
|
|
3437
|
+
storageUsed: 0
|
|
3438
|
+
};
|
|
3439
|
+
}
|
|
3440
|
+
}
|
|
3441
|
+
}),
|
|
3442
|
+
systemListScheduledFunctions: query({
|
|
3443
|
+
args: {},
|
|
3444
|
+
handler: async (ctx) => {
|
|
3445
|
+
try {
|
|
3446
|
+
const jobs = await ctx.db.system.query("_scheduled_functions").collect();
|
|
3447
|
+
return jobs.map((job) => ({
|
|
3448
|
+
_id: job._id,
|
|
3449
|
+
_creationTime: job._creationTime,
|
|
3450
|
+
name: job.name,
|
|
3451
|
+
args: job.args,
|
|
3452
|
+
state: job.state,
|
|
3453
|
+
scheduledTime: job.scheduledTime,
|
|
3454
|
+
completedTime: job.completedTime,
|
|
3455
|
+
error: job.state?.kind === "failed" ? job.state.error : undefined
|
|
3456
|
+
}));
|
|
3457
|
+
} catch (e) {
|
|
3458
|
+
console.debug("[systemListScheduledFunctions] Failed to query scheduled functions:", e);
|
|
3459
|
+
return [];
|
|
3460
|
+
}
|
|
3461
|
+
}
|
|
3462
|
+
}),
|
|
3463
|
+
systemCancelScheduledFunction: mutation({
|
|
3464
|
+
args: { id: v.id("_scheduled_functions") },
|
|
3465
|
+
handler: async (ctx, { id }) => {
|
|
3466
|
+
await ctx.db.system.delete(id);
|
|
3467
|
+
}
|
|
3468
|
+
}),
|
|
3469
|
+
systemListCrons: query({
|
|
3470
|
+
args: {},
|
|
3471
|
+
handler: async (ctx) => {
|
|
3472
|
+
try {
|
|
3473
|
+
const jobs = await ctx.db.system.query("_crons").collect();
|
|
3474
|
+
return jobs.map((job) => ({
|
|
3475
|
+
_id: job._id,
|
|
3476
|
+
_creationTime: job._creationTime,
|
|
3477
|
+
name: job.name,
|
|
3478
|
+
schedule: job.schedule,
|
|
3479
|
+
functionPath: job.functionPath,
|
|
3480
|
+
args: job.args,
|
|
3481
|
+
componentPath: job.componentPath,
|
|
3482
|
+
lastRun: job.lastRun,
|
|
3483
|
+
nextRun: job.nextRun,
|
|
3484
|
+
lastRunState: job.lastRunState
|
|
3485
|
+
}));
|
|
3486
|
+
} catch (e) {
|
|
3487
|
+
console.debug("[systemListCronJobs] Failed to query cron jobs:", e);
|
|
3488
|
+
return [];
|
|
3489
|
+
}
|
|
3490
|
+
}
|
|
3491
|
+
}),
|
|
3492
|
+
systemListStorage: query({
|
|
3493
|
+
args: {
|
|
3494
|
+
page: v.number(),
|
|
3495
|
+
pageSize: v.number(),
|
|
3496
|
+
sortBy: v.optional(v.union(v.literal("uploadedAt"), v.literal("size"), v.literal("contentType"))),
|
|
3497
|
+
sortOrder: v.optional(v.union(v.literal("asc"), v.literal("desc")))
|
|
3498
|
+
},
|
|
3499
|
+
handler: async (ctx, args) => {
|
|
3500
|
+
try {
|
|
3501
|
+
const allFiles = await ctx.db.system.query("_storage").collect();
|
|
3502
|
+
const sortBy = args.sortBy || "uploadedAt";
|
|
3503
|
+
const sortOrder = args.sortOrder || "desc";
|
|
3504
|
+
const sortedFiles = allFiles.sort((a, b) => {
|
|
3505
|
+
const aVal = a[sortBy] ?? 0;
|
|
3506
|
+
const bVal = b[sortBy] ?? 0;
|
|
3507
|
+
if (typeof aVal === "string" && typeof bVal === "string") {
|
|
3508
|
+
return sortOrder === "asc" ? aVal.localeCompare(bVal) : bVal.localeCompare(aVal);
|
|
3509
|
+
}
|
|
3510
|
+
if (sortOrder === "asc") {
|
|
3511
|
+
return aVal - bVal;
|
|
3512
|
+
} else {
|
|
3513
|
+
return bVal - aVal;
|
|
3514
|
+
}
|
|
3515
|
+
});
|
|
3516
|
+
const start = (args.page - 1) * args.pageSize;
|
|
3517
|
+
const end = start + args.pageSize;
|
|
3518
|
+
const paginatedFiles = sortedFiles.slice(start, end);
|
|
3519
|
+
const totalSize = allFiles.reduce((sum, file) => sum + (file.size || 0), 0);
|
|
3520
|
+
return {
|
|
3521
|
+
files: paginatedFiles.map((file) => ({
|
|
3522
|
+
_id: file._id,
|
|
3523
|
+
_creationTime: file._creationTime,
|
|
3524
|
+
sha256: file.sha256,
|
|
3525
|
+
size: file.size,
|
|
3526
|
+
contentType: file.contentType
|
|
3527
|
+
})),
|
|
3528
|
+
total: allFiles.length,
|
|
3529
|
+
page: args.page,
|
|
3530
|
+
pageSize: args.pageSize,
|
|
3531
|
+
hasMore: end < allFiles.length,
|
|
3532
|
+
totalSize
|
|
3533
|
+
};
|
|
3534
|
+
} catch (e) {
|
|
3535
|
+
console.debug("[systemListStorageFiles] Failed to query storage files:", e);
|
|
3536
|
+
return {
|
|
3537
|
+
files: [],
|
|
3538
|
+
total: 0,
|
|
3539
|
+
page: args.page,
|
|
3540
|
+
pageSize: args.pageSize,
|
|
3541
|
+
hasMore: false,
|
|
3542
|
+
totalSize: 0
|
|
3543
|
+
};
|
|
3544
|
+
}
|
|
3545
|
+
}
|
|
3546
|
+
}),
|
|
3547
|
+
systemDeleteStorage: mutation({
|
|
3548
|
+
args: { storageId: v.id("_storage") },
|
|
3549
|
+
handler: async (ctx, { storageId }) => {
|
|
3550
|
+
await ctx.storage.delete(storageId);
|
|
3551
|
+
}
|
|
3552
|
+
}),
|
|
3553
|
+
systemGetStorageMetadata: query({
|
|
3554
|
+
args: { storageId: v.id("_storage") },
|
|
3555
|
+
handler: async (ctx, { storageId }) => {
|
|
3556
|
+
const file = await ctx.db.system.get(storageId);
|
|
3557
|
+
return file;
|
|
3558
|
+
}
|
|
3559
|
+
}),
|
|
3560
|
+
systemListFunctions: query({
|
|
3561
|
+
args: { componentPath: v.optional(v.string()) },
|
|
3562
|
+
handler: async (ctx, args) => {
|
|
3563
|
+
const componentPath = args.componentPath ?? ctx?.componentPath ?? undefined;
|
|
3564
|
+
const functions = await listSystemFunctions({ componentPath });
|
|
3565
|
+
return functions.map((fn) => ({
|
|
3566
|
+
name: fn.name,
|
|
3567
|
+
path: fn.path,
|
|
3568
|
+
type: fn.type,
|
|
3569
|
+
module: fn.module,
|
|
3570
|
+
visibility: fn.visibility,
|
|
3571
|
+
args: fn.args,
|
|
3572
|
+
returns: fn.returns,
|
|
3573
|
+
source: fn.source,
|
|
3574
|
+
componentPath: fn.componentPath,
|
|
3575
|
+
httpMethod: fn.httpMethod,
|
|
3576
|
+
httpPath: fn.httpPath
|
|
3577
|
+
}));
|
|
3578
|
+
}
|
|
3579
|
+
}),
|
|
3580
|
+
systemExecuteFunction: mutation({
|
|
3581
|
+
args: {
|
|
3582
|
+
functionPath: v.string(),
|
|
3583
|
+
args: v.any(),
|
|
3584
|
+
functionType: v.union(v.literal("query"), v.literal("mutation"), v.literal("action"), v.literal("http")),
|
|
3585
|
+
componentPath: v.optional(v.string())
|
|
3586
|
+
},
|
|
3587
|
+
handler: async (ctx, { functionPath, args, functionType, componentPath }) => {
|
|
3588
|
+
if (typeof functionPath !== "string" || !functionPath.includes(":")) {
|
|
3589
|
+
throw new Error(`Invalid function path: ${functionPath}`);
|
|
3590
|
+
}
|
|
3591
|
+
const executorArgs = args ?? {};
|
|
3592
|
+
const target = resolveFunctionReference(functionPath, componentPath);
|
|
3593
|
+
try {
|
|
3594
|
+
switch (functionType) {
|
|
3595
|
+
case "query": {
|
|
3596
|
+
return await ctx.runQuery(target, executorArgs);
|
|
3597
|
+
}
|
|
3598
|
+
case "mutation": {
|
|
3599
|
+
return await ctx.runMutation(target, executorArgs);
|
|
3600
|
+
}
|
|
3601
|
+
case "action": {
|
|
3602
|
+
return await ctx.runAction(target, executorArgs);
|
|
3603
|
+
}
|
|
3604
|
+
case "http": {
|
|
3605
|
+
throw new Error("HTTP actions can be tested via HTTP requests but not executed directly here.");
|
|
3606
|
+
}
|
|
3607
|
+
default: {
|
|
3608
|
+
throw new Error(`Unsupported function type: ${functionType}`);
|
|
3609
|
+
}
|
|
3610
|
+
}
|
|
3611
|
+
} catch (error) {
|
|
3612
|
+
const message = error?.message ?? String(error);
|
|
3613
|
+
throw new Error(`Failed to execute ${functionPath}: ${message}`);
|
|
3614
|
+
}
|
|
3615
|
+
}
|
|
3616
|
+
})
|
|
3617
|
+
};
|
|
3618
|
+
}
|
|
3619
|
+
function resolveFunctionReference(functionPath, componentPath) {
|
|
3620
|
+
if (componentPath && componentPath.trim().length > 0) {
|
|
3621
|
+
const normalizedComponent = componentPath.replace(/^\/+|\/+$/g, "");
|
|
3622
|
+
return `function://${normalizedComponent};${functionPath}`;
|
|
3623
|
+
}
|
|
3624
|
+
return functionPath;
|
|
3625
|
+
}
|
|
3626
|
+
async function loadSchemaDefinition(componentPath) {
|
|
3627
|
+
try {
|
|
3628
|
+
const module = await loadConvexModule("schema", {
|
|
3629
|
+
hint: "schema",
|
|
3630
|
+
componentPath: componentPath || undefined
|
|
3631
|
+
});
|
|
3632
|
+
return module?.default ?? null;
|
|
3633
|
+
} catch (error) {
|
|
3634
|
+
if (!isMissingSchemaModuleError(error)) {
|
|
3635
|
+
console.debug("Failed to load schema module:", error);
|
|
3636
|
+
}
|
|
3637
|
+
return null;
|
|
3638
|
+
}
|
|
3639
|
+
}
|
|
3640
|
+
function extractTablesFromSchema(schema) {
|
|
3641
|
+
const entries = Object.entries(schema.tables ?? {});
|
|
3642
|
+
return entries.map(([name, definition]) => ({
|
|
3643
|
+
name,
|
|
3644
|
+
exported: typeof definition?.export === "function" ? definition.export() : null
|
|
3645
|
+
}));
|
|
3646
|
+
}
|
|
3647
|
+
function extractTableMetadata(schema, tableName) {
|
|
3648
|
+
const definition = schema.tables?.[tableName];
|
|
3649
|
+
if (!definition) {
|
|
3650
|
+
return null;
|
|
3651
|
+
}
|
|
3652
|
+
return {
|
|
3653
|
+
name: tableName,
|
|
3654
|
+
exported: typeof definition?.export === "function" ? definition.export() : null
|
|
3655
|
+
};
|
|
3656
|
+
}
|
|
3657
|
+
async function countDocuments(ctx, tableName) {
|
|
3658
|
+
try {
|
|
3659
|
+
const documents = await ctx.db.query(tableName).collect();
|
|
3660
|
+
return documents.length;
|
|
3661
|
+
} catch (error) {
|
|
3662
|
+
console.warn(`Failed to count documents for table ${tableName}:`, error);
|
|
3663
|
+
return 0;
|
|
3664
|
+
}
|
|
3665
|
+
}
|
|
3666
|
+
function buildIndexList(indexes) {
|
|
3667
|
+
const base = ["by_id", "by_creation_time"];
|
|
3668
|
+
if (!indexes || indexes.length === 0) {
|
|
3669
|
+
return base;
|
|
3670
|
+
}
|
|
3671
|
+
const extras = indexes.map((idx) => {
|
|
3672
|
+
if (typeof idx === "string")
|
|
3673
|
+
return idx;
|
|
3674
|
+
return idx?.indexDescriptor;
|
|
3675
|
+
}).filter((value) => typeof value === "string" && value.length > 0);
|
|
3676
|
+
return Array.from(new Set([...base, ...extras]));
|
|
3677
|
+
}
|
|
3678
|
+
function findIndexFields(indexes, descriptor) {
|
|
3679
|
+
if (descriptor === "by_id") {
|
|
3680
|
+
return ["_id"];
|
|
3681
|
+
}
|
|
3682
|
+
if (descriptor === "by_creation_time") {
|
|
3683
|
+
return ["_creationTime", "_id"];
|
|
3684
|
+
}
|
|
3685
|
+
const match = indexes?.find((idx) => idx.indexDescriptor === descriptor);
|
|
3686
|
+
return match?.fields ?? [];
|
|
3687
|
+
}
|
|
3688
|
+
function buildSearchIndexMetadata(searchIndexes) {
|
|
3689
|
+
if (!searchIndexes) {
|
|
3690
|
+
return [];
|
|
3691
|
+
}
|
|
3692
|
+
return searchIndexes.map((idx) => {
|
|
3693
|
+
if (typeof idx === "string") {
|
|
3694
|
+
return { name: idx, searchField: "", filterFields: undefined };
|
|
3695
|
+
}
|
|
3696
|
+
return {
|
|
3697
|
+
name: idx.indexDescriptor,
|
|
3698
|
+
searchField: idx.searchField,
|
|
3699
|
+
filterFields: idx.filterFields
|
|
3700
|
+
};
|
|
3701
|
+
}).filter((entry) => typeof entry.name === "string" && entry.name.length > 0);
|
|
3702
|
+
}
|
|
3703
|
+
function buildVectorIndexMetadata(vectorIndexes) {
|
|
3704
|
+
if (!vectorIndexes) {
|
|
3705
|
+
return [];
|
|
3706
|
+
}
|
|
3707
|
+
return vectorIndexes.map((idx) => {
|
|
3708
|
+
if (typeof idx === "string") {
|
|
3709
|
+
return { name: idx, vectorField: "", dimension: undefined, filterFields: undefined };
|
|
3710
|
+
}
|
|
3711
|
+
return {
|
|
3712
|
+
name: idx.indexDescriptor,
|
|
3713
|
+
vectorField: idx.vectorField,
|
|
3714
|
+
dimension: idx.dimension,
|
|
3715
|
+
filterFields: idx.filterFields
|
|
3716
|
+
};
|
|
3717
|
+
}).filter((entry) => typeof entry.name === "string" && entry.name.length > 0);
|
|
3718
|
+
}
|
|
3719
|
+
function extractFieldsFromDocumentType(documentType, tableName) {
|
|
3720
|
+
const fields = [
|
|
3721
|
+
{ name: "_id", type: `Id<${tableName}>`, optional: false },
|
|
3722
|
+
{ name: "_creationTime", type: "number", optional: false }
|
|
3723
|
+
];
|
|
3724
|
+
if (!documentType || documentType.type !== "object" || !documentType.value) {
|
|
3725
|
+
return fields;
|
|
3726
|
+
}
|
|
3727
|
+
for (const [name, fieldDef] of Object.entries(documentType.value)) {
|
|
3728
|
+
const definition = fieldDef;
|
|
3729
|
+
fields.push({
|
|
3730
|
+
name,
|
|
3731
|
+
type: describeFieldType(definition.fieldType),
|
|
3732
|
+
optional: Boolean(definition.optional)
|
|
3733
|
+
});
|
|
3734
|
+
}
|
|
3735
|
+
return fields;
|
|
3736
|
+
}
|
|
3737
|
+
function describeFieldType(node) {
|
|
3738
|
+
if (!node || typeof node !== "object") {
|
|
3739
|
+
return "unknown";
|
|
3740
|
+
}
|
|
3741
|
+
if (node.type === "object") {
|
|
3742
|
+
const childFields = node.value ? Object.keys(node.value) : [];
|
|
3743
|
+
return `object{${childFields.join(", ")}}`;
|
|
3744
|
+
}
|
|
3745
|
+
if (node.type === "array") {
|
|
3746
|
+
return `array<${describeFieldType(node.value)}>`;
|
|
3747
|
+
}
|
|
3748
|
+
if (node.type === "union") {
|
|
3749
|
+
const members = Array.isArray(node.value) ? node.value.map(describeFieldType) : [];
|
|
3750
|
+
return `union<${members.join(" | ")}>`;
|
|
3751
|
+
}
|
|
3752
|
+
if (node.type === "literal") {
|
|
3753
|
+
return `literal(${JSON.stringify(node.value)})`;
|
|
3754
|
+
}
|
|
3755
|
+
if (node.type === "id") {
|
|
3756
|
+
return `Id<${node.tableName ?? "unknown"}>`;
|
|
3757
|
+
}
|
|
3758
|
+
return node.type ?? "unknown";
|
|
3759
|
+
}
|
|
3760
|
+
var init_internal = __esm(() => {
|
|
3761
|
+
init_values();
|
|
3762
|
+
init_module_loader();
|
|
3763
|
+
init_schema_service();
|
|
3764
|
+
init_function_introspection();
|
|
3765
|
+
init_interface();
|
|
3766
|
+
init_execution_log();
|
|
3767
|
+
});
|
|
3768
|
+
|
|
3769
|
+
// src/internal.ts
|
|
3770
|
+
init_internal();
|
|
3771
|
+
export {
|
|
3772
|
+
createSystemFunctions
|
|
3773
|
+
};
|