@concavejs/docstore-better-sqlite3 0.0.1-alpha.7 → 0.0.1-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +768 -802
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1,9 +1,4 @@
1
- // src/sqlite-docstore.ts
2
- import Database from "better-sqlite3";
3
-
4
- // ../docstore-sqlite-base/dist/index.js
5
- import { AsyncLocalStorage } from "async_hooks";
6
- import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
1
+ import { createRequire } from "node:module";
7
2
  var __defProp = Object.defineProperty;
8
3
  var __export = (target, all) => {
9
4
  for (var name in all)
@@ -15,6 +10,9 @@ var __export = (target, all) => {
15
10
  });
16
11
  };
17
12
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
13
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
14
+
15
+ // ../../node_modules/convex/dist/esm/values/base64.js
18
16
  function getLens(b64) {
19
17
  var len2 = b64.length;
20
18
  if (len2 % 4 > 0) {
@@ -85,12 +83,7 @@ function fromByteArray(uint8) {
85
83
  }
86
84
  return parts.join("");
87
85
  }
88
- var lookup;
89
- var revLookup;
90
- var Arr;
91
- var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
92
- var i;
93
- var len;
86
+ var lookup, revLookup, Arr, code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", i, len;
94
87
  var init_base64 = __esm(() => {
95
88
  lookup = [];
96
89
  revLookup = [];
@@ -102,6 +95,8 @@ var init_base64 = __esm(() => {
102
95
  revLookup[45] = 62;
103
96
  revLookup[95] = 63;
104
97
  });
98
+
99
+ // ../../node_modules/convex/dist/esm/common/index.js
105
100
  function parseArgs(args) {
106
101
  if (args === undefined) {
107
102
  return {};
@@ -117,6 +112,8 @@ function isSimpleObject(value) {
117
112
  const isSimple = prototype === null || prototype === Object.prototype || prototype?.constructor?.name === "Object";
118
113
  return isObject && isSimple;
119
114
  }
115
+
116
+ // ../../node_modules/convex/dist/esm/values/value.js
120
117
  function isSpecial(n) {
121
118
  return Number.isNaN(n) || !Number.isFinite(n) || Object.is(n, -0);
122
119
  }
@@ -351,16 +348,7 @@ function convexOrUndefinedToJson(value) {
351
348
  function patchValueToJson(value) {
352
349
  return convexToJsonInternal(value, value, "", true);
353
350
  }
354
- var LITTLE_ENDIAN = true;
355
- var MIN_INT64;
356
- var MAX_INT64;
357
- var ZERO;
358
- var EIGHT;
359
- var TWOFIFTYSIX;
360
- var bigIntToBase64;
361
- var base64ToBigInt;
362
- var MAX_IDENTIFIER_LEN = 1024;
363
- var MAX_VALUE_FOR_ERROR_LEN = 16384;
351
+ var LITTLE_ENDIAN = true, MIN_INT64, MAX_INT64, ZERO, EIGHT, TWOFIFTYSIX, bigIntToBase64, base64ToBigInt, MAX_IDENTIFIER_LEN = 1024, MAX_VALUE_FOR_ERROR_LEN = 16384;
364
352
  var init_value = __esm(() => {
365
353
  init_base64();
366
354
  MIN_INT64 = BigInt("-9223372036854775808");
@@ -371,6 +359,8 @@ var init_value = __esm(() => {
371
359
  bigIntToBase64 = DataView.prototype.setBigInt64 ? modernBigIntToBase64 : slowBigIntToBase64;
372
360
  base64ToBigInt = DataView.prototype.getBigInt64 ? modernBase64ToBigInt : slowBase64ToBigInt;
373
361
  });
362
+
363
+ // ../../node_modules/convex/dist/esm/values/validators.js
374
364
  function throwUndefinedValidatorError(context, fieldName) {
375
365
  const fieldInfo = fieldName !== undefined ? ` for field "${fieldName}"` : "";
376
366
  throw new Error(`A validator is undefined${fieldInfo} in ${context}. This is often caused by circular imports. See ${UNDEFINED_VALIDATOR_ERROR_URL} for details.`);
@@ -386,27 +376,11 @@ class BaseValidator {
386
376
  this.isConvexValidator = true;
387
377
  }
388
378
  }
389
- var __defProp2;
390
- var __defNormalProp = (obj, key, value) => (key in obj) ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
391
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
392
- var UNDEFINED_VALIDATOR_ERROR_URL = "https://docs.convex.dev/error#undefined-validator";
393
- var VId;
394
- var VFloat64;
395
- var VInt64;
396
- var VBoolean;
397
- var VBytes;
398
- var VString;
399
- var VNull;
400
- var VAny;
401
- var VObject;
402
- var VLiteral;
403
- var VArray;
404
- var VRecord;
405
- var VUnion;
379
+ 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;
406
380
  var init_validators = __esm(() => {
407
381
  init_value();
408
382
  __defProp2 = Object.defineProperty;
409
- VId = class VId2 extends BaseValidator {
383
+ VId = class VId extends BaseValidator {
410
384
  constructor({
411
385
  isOptional,
412
386
  tableName
@@ -423,13 +397,13 @@ var init_validators = __esm(() => {
423
397
  return { type: "id", tableName: this.tableName };
424
398
  }
425
399
  asOptional() {
426
- return new VId2({
400
+ return new VId({
427
401
  isOptional: "optional",
428
402
  tableName: this.tableName
429
403
  });
430
404
  }
431
405
  };
432
- VFloat64 = class VFloat642 extends BaseValidator {
406
+ VFloat64 = class VFloat64 extends BaseValidator {
433
407
  constructor() {
434
408
  super(...arguments);
435
409
  __publicField(this, "kind", "float64");
@@ -438,12 +412,12 @@ var init_validators = __esm(() => {
438
412
  return { type: "number" };
439
413
  }
440
414
  asOptional() {
441
- return new VFloat642({
415
+ return new VFloat64({
442
416
  isOptional: "optional"
443
417
  });
444
418
  }
445
419
  };
446
- VInt64 = class VInt642 extends BaseValidator {
420
+ VInt64 = class VInt64 extends BaseValidator {
447
421
  constructor() {
448
422
  super(...arguments);
449
423
  __publicField(this, "kind", "int64");
@@ -452,10 +426,10 @@ var init_validators = __esm(() => {
452
426
  return { type: "bigint" };
453
427
  }
454
428
  asOptional() {
455
- return new VInt642({ isOptional: "optional" });
429
+ return new VInt64({ isOptional: "optional" });
456
430
  }
457
431
  };
458
- VBoolean = class VBoolean2 extends BaseValidator {
432
+ VBoolean = class VBoolean extends BaseValidator {
459
433
  constructor() {
460
434
  super(...arguments);
461
435
  __publicField(this, "kind", "boolean");
@@ -464,12 +438,12 @@ var init_validators = __esm(() => {
464
438
  return { type: this.kind };
465
439
  }
466
440
  asOptional() {
467
- return new VBoolean2({
441
+ return new VBoolean({
468
442
  isOptional: "optional"
469
443
  });
470
444
  }
471
445
  };
472
- VBytes = class VBytes2 extends BaseValidator {
446
+ VBytes = class VBytes extends BaseValidator {
473
447
  constructor() {
474
448
  super(...arguments);
475
449
  __publicField(this, "kind", "bytes");
@@ -478,10 +452,10 @@ var init_validators = __esm(() => {
478
452
  return { type: this.kind };
479
453
  }
480
454
  asOptional() {
481
- return new VBytes2({ isOptional: "optional" });
455
+ return new VBytes({ isOptional: "optional" });
482
456
  }
483
457
  };
484
- VString = class VString2 extends BaseValidator {
458
+ VString = class VString extends BaseValidator {
485
459
  constructor() {
486
460
  super(...arguments);
487
461
  __publicField(this, "kind", "string");
@@ -490,12 +464,12 @@ var init_validators = __esm(() => {
490
464
  return { type: this.kind };
491
465
  }
492
466
  asOptional() {
493
- return new VString2({
467
+ return new VString({
494
468
  isOptional: "optional"
495
469
  });
496
470
  }
497
471
  };
498
- VNull = class VNull2 extends BaseValidator {
472
+ VNull = class VNull extends BaseValidator {
499
473
  constructor() {
500
474
  super(...arguments);
501
475
  __publicField(this, "kind", "null");
@@ -504,10 +478,10 @@ var init_validators = __esm(() => {
504
478
  return { type: this.kind };
505
479
  }
506
480
  asOptional() {
507
- return new VNull2({ isOptional: "optional" });
481
+ return new VNull({ isOptional: "optional" });
508
482
  }
509
483
  };
510
- VAny = class VAny2 extends BaseValidator {
484
+ VAny = class VAny extends BaseValidator {
511
485
  constructor() {
512
486
  super(...arguments);
513
487
  __publicField(this, "kind", "any");
@@ -518,12 +492,12 @@ var init_validators = __esm(() => {
518
492
  };
519
493
  }
520
494
  asOptional() {
521
- return new VAny2({
495
+ return new VAny({
522
496
  isOptional: "optional"
523
497
  });
524
498
  }
525
499
  };
526
- VObject = class VObject2 extends BaseValidator {
500
+ VObject = class VObject extends BaseValidator {
527
501
  constructor({
528
502
  isOptional,
529
503
  fields
@@ -554,7 +528,7 @@ var init_validators = __esm(() => {
554
528
  };
555
529
  }
556
530
  asOptional() {
557
- return new VObject2({
531
+ return new VObject({
558
532
  isOptional: "optional",
559
533
  fields: this.fields
560
534
  });
@@ -564,7 +538,7 @@ var init_validators = __esm(() => {
564
538
  for (const field of fields) {
565
539
  delete newFields[field];
566
540
  }
567
- return new VObject2({
541
+ return new VObject({
568
542
  isOptional: this.isOptional,
569
543
  fields: newFields
570
544
  });
@@ -574,7 +548,7 @@ var init_validators = __esm(() => {
574
548
  for (const field of fields) {
575
549
  newFields[field] = this.fields[field];
576
550
  }
577
- return new VObject2({
551
+ return new VObject({
578
552
  isOptional: this.isOptional,
579
553
  fields: newFields
580
554
  });
@@ -584,19 +558,19 @@ var init_validators = __esm(() => {
584
558
  for (const [key, validator] of globalThis.Object.entries(this.fields)) {
585
559
  newFields[key] = validator.asOptional();
586
560
  }
587
- return new VObject2({
561
+ return new VObject({
588
562
  isOptional: this.isOptional,
589
563
  fields: newFields
590
564
  });
591
565
  }
592
566
  extend(fields) {
593
- return new VObject2({
567
+ return new VObject({
594
568
  isOptional: this.isOptional,
595
569
  fields: { ...this.fields, ...fields }
596
570
  });
597
571
  }
598
572
  };
599
- VLiteral = class VLiteral2 extends BaseValidator {
573
+ VLiteral = class VLiteral extends BaseValidator {
600
574
  constructor({ isOptional, value }) {
601
575
  super({ isOptional });
602
576
  __publicField(this, "value");
@@ -613,13 +587,13 @@ var init_validators = __esm(() => {
613
587
  };
614
588
  }
615
589
  asOptional() {
616
- return new VLiteral2({
590
+ return new VLiteral({
617
591
  isOptional: "optional",
618
592
  value: this.value
619
593
  });
620
594
  }
621
595
  };
622
- VArray = class VArray2 extends BaseValidator {
596
+ VArray = class VArray extends BaseValidator {
623
597
  constructor({
624
598
  isOptional,
625
599
  element
@@ -639,13 +613,13 @@ var init_validators = __esm(() => {
639
613
  };
640
614
  }
641
615
  asOptional() {
642
- return new VArray2({
616
+ return new VArray({
643
617
  isOptional: "optional",
644
618
  element: this.element
645
619
  });
646
620
  }
647
621
  };
648
- VRecord = class VRecord2 extends BaseValidator {
622
+ VRecord = class VRecord extends BaseValidator {
649
623
  constructor({
650
624
  isOptional,
651
625
  key,
@@ -684,14 +658,14 @@ var init_validators = __esm(() => {
684
658
  };
685
659
  }
686
660
  asOptional() {
687
- return new VRecord2({
661
+ return new VRecord({
688
662
  isOptional: "optional",
689
663
  key: this.key,
690
664
  value: this.value
691
665
  });
692
666
  }
693
667
  };
694
- VUnion = class VUnion2 extends BaseValidator {
668
+ VUnion = class VUnion extends BaseValidator {
695
669
  constructor({ isOptional, members }) {
696
670
  super({ isOptional });
697
671
  __publicField(this, "members");
@@ -713,13 +687,15 @@ var init_validators = __esm(() => {
713
687
  };
714
688
  }
715
689
  asOptional() {
716
- return new VUnion2({
690
+ return new VUnion({
717
691
  isOptional: "optional",
718
692
  members: this.members
719
693
  });
720
694
  }
721
695
  };
722
696
  });
697
+
698
+ // ../../node_modules/convex/dist/esm/values/validator.js
723
699
  function isValidator(v2) {
724
700
  return !!v2.isConvexValidator;
725
701
  }
@@ -797,18 +773,14 @@ var init_validator = __esm(() => {
797
773
  }
798
774
  };
799
775
  });
800
- var __defProp3;
801
- var __defNormalProp2 = (obj, key, value) => (key in obj) ? __defProp3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
802
- var __publicField2 = (obj, key, value) => __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
803
- var _a;
804
- var _b;
805
- var IDENTIFYING_FIELD;
806
- var ConvexError;
776
+
777
+ // ../../node_modules/convex/dist/esm/values/errors.js
778
+ 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;
807
779
  var init_errors = __esm(() => {
808
780
  init_value();
809
781
  __defProp3 = Object.defineProperty;
810
782
  IDENTIFYING_FIELD = Symbol.for("ConvexError");
811
- ConvexError = class ConvexError2 extends (_b = Error, _a = IDENTIFYING_FIELD, _b) {
783
+ ConvexError = class ConvexError extends (_b = Error, _a = IDENTIFYING_FIELD, _b) {
812
784
  constructor(data) {
813
785
  super(typeof data === "string" ? data : stringifyValueForError(data));
814
786
  __publicField2(this, "name", "ConvexError");
@@ -818,11 +790,15 @@ var init_errors = __esm(() => {
818
790
  }
819
791
  };
820
792
  });
793
+
794
+ // ../../node_modules/convex/dist/esm/values/index.js
821
795
  var init_values = __esm(() => {
822
796
  init_value();
823
797
  init_validator();
824
798
  init_errors();
825
799
  });
800
+
801
+ // ../core/dist/utils/utils.js
826
802
  function hexToArrayBuffer(hex) {
827
803
  if (hex === "") {
828
804
  return new Uint8Array(0).buffer;
@@ -859,235 +835,9 @@ function deserializeDeveloperId(developerId) {
859
835
  }
860
836
  return null;
861
837
  }
862
- var DOC_ID_SEPARATOR = ":";
863
- var LEGACY_DOC_ID_SEPARATOR = ";";
864
- function encodeNumber(n) {
865
- const buffer = new ArrayBuffer(8);
866
- const view = new DataView(buffer);
867
- view.setFloat64(0, n, false);
868
- const bytes = new Uint8Array(buffer);
869
- if (n >= 0) {
870
- bytes[0] ^= 128;
871
- } else {
872
- for (let i2 = 0;i2 < 8; i2++) {
873
- bytes[i2] ^= 255;
874
- }
875
- }
876
- return bytes;
877
- }
878
- function encodeBigInt(n) {
879
- const INT64_MIN = -(2n ** 63n);
880
- const INT64_MAX = 2n ** 63n - 1n;
881
- if (n < INT64_MIN)
882
- n = INT64_MIN;
883
- if (n > INT64_MAX)
884
- n = INT64_MAX;
885
- const buffer = new ArrayBuffer(8);
886
- const view = new DataView(buffer);
887
- const unsigned = n < 0n ? n + 2n ** 64n : n;
888
- view.setBigUint64(0, unsigned, false);
889
- const bytes = new Uint8Array(buffer);
890
- bytes[0] ^= 128;
891
- return bytes;
892
- }
893
- function encodeString(s) {
894
- const encoder = new TextEncoder;
895
- const raw = encoder.encode(s);
896
- let nullCount = 0;
897
- for (const byte of raw) {
898
- if (byte === 0)
899
- nullCount++;
900
- }
901
- const result = new Uint8Array(raw.length + nullCount + 2);
902
- let writeIndex = 0;
903
- for (const byte of raw) {
904
- if (byte === 0) {
905
- result[writeIndex++] = 0;
906
- result[writeIndex++] = 1;
907
- } else {
908
- result[writeIndex++] = byte;
909
- }
910
- }
911
- result[writeIndex++] = 0;
912
- result[writeIndex++] = 0;
913
- return result;
914
- }
915
- function encodeValue(value) {
916
- if (value === null || value === undefined) {
917
- return new Uint8Array([TypeTag.Null]);
918
- }
919
- if (typeof value === "boolean") {
920
- return new Uint8Array([value ? TypeTag.True : TypeTag.False]);
921
- }
922
- if (typeof value === "number") {
923
- if (Number.isNaN(value)) {
924
- return new Uint8Array([TypeTag.NaN]);
925
- }
926
- if (!Number.isFinite(value)) {
927
- return new Uint8Array([value === -Infinity ? TypeTag.NegativeInfinity : TypeTag.PositiveInfinity]);
928
- }
929
- if (value === 0) {
930
- return new Uint8Array([Object.is(value, -0) ? TypeTag.NegativeZero : TypeTag.Zero]);
931
- }
932
- const tag = value > 0 ? TypeTag.PositiveNumber : TypeTag.NegativeNumber;
933
- const encoded = encodeNumber(value);
934
- const result = new Uint8Array(1 + encoded.length);
935
- result[0] = tag;
936
- result.set(encoded, 1);
937
- return result;
938
- }
939
- if (typeof value === "bigint") {
940
- if (value === 0n) {
941
- return new Uint8Array([TypeTag.ZeroBigInt]);
942
- }
943
- const tag = value > 0n ? TypeTag.PositiveBigInt : TypeTag.NegativeBigInt;
944
- const encoded = encodeBigInt(value);
945
- const result = new Uint8Array(1 + encoded.length);
946
- result[0] = tag;
947
- result.set(encoded, 1);
948
- return result;
949
- }
950
- if (typeof value === "string") {
951
- const encoded = encodeString(value);
952
- const result = new Uint8Array(1 + encoded.length);
953
- result[0] = TypeTag.String;
954
- result.set(encoded, 1);
955
- return result;
956
- }
957
- if (value instanceof ArrayBuffer || value instanceof Uint8Array) {
958
- const bytes = value instanceof Uint8Array ? value : new Uint8Array(value);
959
- const result = new Uint8Array(1 + bytes.length + 2);
960
- result[0] = TypeTag.Bytes;
961
- result.set(bytes, 1);
962
- result[result.length - 2] = 0;
963
- result[result.length - 1] = 0;
964
- return result;
965
- }
966
- throw new Error(`Cannot encode value of type ${typeof value} in index key`);
967
- }
968
- function encodeIndexKey(values) {
969
- if (values.length === 0) {
970
- return new ArrayBuffer(0);
971
- }
972
- const encoded = values.map(encodeValue);
973
- const totalLength = encoded.reduce((sum, arr) => sum + arr.length, 0);
974
- const result = new Uint8Array(totalLength);
975
- let offset = 0;
976
- for (const chunk of encoded) {
977
- result.set(chunk, offset);
978
- offset += chunk.length;
979
- }
980
- return result.buffer;
981
- }
982
- function compareIndexKeys(a, b) {
983
- const viewA = new Uint8Array(a);
984
- const viewB = new Uint8Array(b);
985
- const minLen = Math.min(viewA.length, viewB.length);
986
- for (let i2 = 0;i2 < minLen; i2++) {
987
- if (viewA[i2] < viewB[i2])
988
- return -1;
989
- if (viewA[i2] > viewB[i2])
990
- return 1;
991
- }
992
- if (viewA.length < viewB.length)
993
- return -1;
994
- if (viewA.length > viewB.length)
995
- return 1;
996
- return 0;
997
- }
998
- function indexKeysEqual(a, b) {
999
- return compareIndexKeys(a, b) === 0;
1000
- }
1001
- var TypeTag;
1002
- var init_index_key_codec = __esm(() => {
1003
- (function(TypeTag2) {
1004
- TypeTag2[TypeTag2["Null"] = 0] = "Null";
1005
- TypeTag2[TypeTag2["False"] = 16] = "False";
1006
- TypeTag2[TypeTag2["True"] = 17] = "True";
1007
- TypeTag2[TypeTag2["NegativeInfinity"] = 32] = "NegativeInfinity";
1008
- TypeTag2[TypeTag2["NegativeNumber"] = 33] = "NegativeNumber";
1009
- TypeTag2[TypeTag2["NegativeZero"] = 34] = "NegativeZero";
1010
- TypeTag2[TypeTag2["Zero"] = 35] = "Zero";
1011
- TypeTag2[TypeTag2["PositiveNumber"] = 36] = "PositiveNumber";
1012
- TypeTag2[TypeTag2["PositiveInfinity"] = 37] = "PositiveInfinity";
1013
- TypeTag2[TypeTag2["NaN"] = 38] = "NaN";
1014
- TypeTag2[TypeTag2["NegativeBigInt"] = 48] = "NegativeBigInt";
1015
- TypeTag2[TypeTag2["ZeroBigInt"] = 49] = "ZeroBigInt";
1016
- TypeTag2[TypeTag2["PositiveBigInt"] = 50] = "PositiveBigInt";
1017
- TypeTag2[TypeTag2["String"] = 64] = "String";
1018
- TypeTag2[TypeTag2["Bytes"] = 80] = "Bytes";
1019
- })(TypeTag || (TypeTag = {}));
1020
- });
1021
- function getFieldValue(doc, fieldPath) {
1022
- const parts = fieldPath.split(".");
1023
- let current = doc;
1024
- for (const part of parts) {
1025
- if (current === null || current === undefined) {
1026
- return;
1027
- }
1028
- if (typeof current !== "object" || Array.isArray(current)) {
1029
- return;
1030
- }
1031
- current = current[part];
1032
- }
1033
- return current;
1034
- }
1035
- function extractIndexKey(doc, fields) {
1036
- const values = [];
1037
- for (const field of fields) {
1038
- const value = getFieldValue(doc, field);
1039
- if (value === undefined) {
1040
- return null;
1041
- }
1042
- values.push(value);
1043
- }
1044
- return encodeIndexKey(values);
1045
- }
1046
- function generateIndexUpdates(tableName, docId, newValue, oldValue, indexes) {
1047
- const updates = [];
1048
- for (const index of indexes) {
1049
- const indexId = stringToHex(`${tableName}:${index.name}`);
1050
- const oldKey = oldValue !== null ? extractIndexKey(oldValue, index.fields) : null;
1051
- const newKey = newValue !== null ? extractIndexKey(newValue, index.fields) : null;
1052
- const keyChanged = oldKey === null && newKey !== null || oldKey !== null && newKey === null || oldKey !== null && newKey !== null && !indexKeysEqual(oldKey, newKey);
1053
- if (!keyChanged) {
1054
- continue;
1055
- }
1056
- if (oldKey !== null) {
1057
- updates.push({
1058
- index_id: indexId,
1059
- key: oldKey,
1060
- value: { type: "Deleted" }
1061
- });
1062
- }
1063
- if (newKey !== null) {
1064
- updates.push({
1065
- index_id: indexId,
1066
- key: newKey,
1067
- value: {
1068
- type: "NonClustered",
1069
- doc_id: docId
1070
- }
1071
- });
1072
- }
1073
- }
1074
- return updates;
1075
- }
1076
- function getStandardIndexes() {
1077
- return [
1078
- {
1079
- name: "by_creation_time",
1080
- fields: ["_creationTime", "_id"]
1081
- },
1082
- {
1083
- name: "by_id",
1084
- fields: ["_id"]
1085
- }
1086
- ];
1087
- }
1088
- var init_index_manager = __esm(() => {
1089
- init_index_key_codec();
1090
- });
838
+ var DOC_ID_SEPARATOR = ":", LEGACY_DOC_ID_SEPARATOR = ";";
839
+
840
+ // ../core/dist/tables/interface.js
1091
841
  function getFullTableName(tableName, componentPath) {
1092
842
  if (!componentPath || componentPath === "") {
1093
843
  return tableName;
@@ -1107,8 +857,7 @@ function parseFullTableName(fullName) {
1107
857
  function isSystemTable(tableName) {
1108
858
  return tableName.startsWith("_");
1109
859
  }
1110
- var SYSTEM_TABLE_NUMBERS;
1111
- var FIRST_USER_TABLE_NUMBER = 100;
860
+ var SYSTEM_TABLE_NUMBERS, FIRST_USER_TABLE_NUMBER = 100;
1112
861
  var init_interface = __esm(() => {
1113
862
  SYSTEM_TABLE_NUMBERS = {
1114
863
  _tables: 1,
@@ -1117,39 +866,111 @@ var init_interface = __esm(() => {
1117
866
  _crons: 4
1118
867
  };
1119
868
  });
1120
- var version = "1.31.7";
1121
- function performSyscall(op, arg) {
1122
- if (typeof Convex === "undefined" || Convex.syscall === undefined) {
1123
- 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?");
869
+
870
+ // ../core/dist/kernel/context-storage.js
871
+ function resolveFromRequire(req) {
872
+ for (const specifier of ["node:async_hooks", "async_hooks"]) {
873
+ try {
874
+ const mod = req(specifier);
875
+ if (mod?.AsyncLocalStorage) {
876
+ return mod.AsyncLocalStorage;
877
+ }
878
+ } catch {}
1124
879
  }
1125
- const resultStr = Convex.syscall(op, JSON.stringify(arg));
1126
- return JSON.parse(resultStr);
880
+ return;
1127
881
  }
1128
- async function performAsyncSyscall(op, arg) {
1129
- if (typeof Convex === "undefined" || Convex.asyncSyscall === undefined) {
1130
- 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?");
1131
- }
1132
- let resultStr;
1133
- try {
1134
- resultStr = await Convex.asyncSyscall(op, JSON.stringify(arg));
1135
- } catch (e) {
1136
- if (e.data !== undefined) {
1137
- const rethrown = new ConvexError(e.message);
1138
- rethrown.data = jsonToConvex(e.data);
1139
- throw rethrown;
882
+
883
+ class ContextStorage {
884
+ als;
885
+ stack = [];
886
+ constructor() {
887
+ if (AsyncLocalStorageCtor) {
888
+ this.als = new AsyncLocalStorageCtor;
1140
889
  }
1141
- throw new Error(e.message);
1142
890
  }
1143
- return JSON.parse(resultStr);
1144
- }
1145
- var init_syscall = __esm(() => {
891
+ getStore() {
892
+ if (this.als) {
893
+ return this.als.getStore() ?? undefined;
894
+ }
895
+ return this.stack.length > 0 ? this.stack[this.stack.length - 1] : undefined;
896
+ }
897
+ run(value, callback) {
898
+ if (this.als) {
899
+ return this.als.run(value, callback);
900
+ }
901
+ this.stack.push(value);
902
+ const result = callback();
903
+ if (result && typeof result.then === "function") {
904
+ return result.finally(() => {
905
+ this.stack.pop();
906
+ });
907
+ }
908
+ this.stack.pop();
909
+ return result;
910
+ }
911
+ }
912
+ var resolveAsyncLocalStorage = () => {
913
+ const globalCtor = globalThis?.AsyncLocalStorage;
914
+ if (globalCtor) {
915
+ return globalCtor;
916
+ }
917
+ const runtimeRequire = __require;
918
+ if (runtimeRequire) {
919
+ const ctor = resolveFromRequire(runtimeRequire);
920
+ if (ctor) {
921
+ return ctor;
922
+ }
923
+ }
924
+ const globalRequire = globalThis?.require;
925
+ if (typeof globalRequire === "function") {
926
+ return resolveFromRequire(globalRequire);
927
+ }
928
+ return;
929
+ }, AsyncLocalStorageCtor;
930
+ var init_context_storage = __esm(() => {
931
+ AsyncLocalStorageCtor = resolveAsyncLocalStorage();
932
+ });
933
+
934
+ // ../../node_modules/convex/dist/esm/index.js
935
+ var version = "1.31.7";
936
+
937
+ // ../../node_modules/convex/dist/esm/server/impl/syscall.js
938
+ function performSyscall(op, arg) {
939
+ if (typeof Convex === "undefined" || Convex.syscall === undefined) {
940
+ 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?");
941
+ }
942
+ const resultStr = Convex.syscall(op, JSON.stringify(arg));
943
+ return JSON.parse(resultStr);
944
+ }
945
+ async function performAsyncSyscall(op, arg) {
946
+ if (typeof Convex === "undefined" || Convex.asyncSyscall === undefined) {
947
+ 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?");
948
+ }
949
+ let resultStr;
950
+ try {
951
+ resultStr = await Convex.asyncSyscall(op, JSON.stringify(arg));
952
+ } catch (e) {
953
+ if (e.data !== undefined) {
954
+ const rethrown = new ConvexError(e.message);
955
+ rethrown.data = jsonToConvex(e.data);
956
+ throw rethrown;
957
+ }
958
+ throw new Error(e.message);
959
+ }
960
+ return JSON.parse(resultStr);
961
+ }
962
+ var init_syscall = __esm(() => {
1146
963
  init_errors();
1147
964
  init_value();
1148
965
  });
966
+
967
+ // ../../node_modules/convex/dist/esm/server/functionName.js
1149
968
  var functionName;
1150
969
  var init_functionName = __esm(() => {
1151
970
  functionName = Symbol.for("functionName");
1152
971
  });
972
+
973
+ // ../../node_modules/convex/dist/esm/server/components/paths.js
1153
974
  function extractReferencePath(reference) {
1154
975
  return reference[toReferencePath] ?? null;
1155
976
  }
@@ -1180,6 +1001,8 @@ var init_paths = __esm(() => {
1180
1001
  init_functionName();
1181
1002
  toReferencePath = Symbol.for("toReferencePath");
1182
1003
  });
1004
+
1005
+ // ../../node_modules/convex/dist/esm/server/impl/validate.js
1183
1006
  function validateArg(arg, idx, method, argName) {
1184
1007
  if (arg === undefined) {
1185
1008
  throw new TypeError(`Must provide arg ${idx} \`${argName}\` to \`${method}\``);
@@ -1190,6 +1013,8 @@ function validateArgIsNonNegativeInteger(arg, idx, method, argName) {
1190
1013
  throw new TypeError(`Arg ${idx} \`${argName}\` to \`${method}\` must be a non-negative integer`);
1191
1014
  }
1192
1015
  }
1016
+
1017
+ // ../../node_modules/convex/dist/esm/server/impl/authentication_impl.js
1193
1018
  function setupAuth(requestId) {
1194
1019
  return {
1195
1020
  getUserIdentity: async () => {
@@ -1203,18 +1028,19 @@ var init_authentication_impl = __esm(() => {
1203
1028
  init_syscall();
1204
1029
  });
1205
1030
 
1031
+ // ../../node_modules/convex/dist/esm/server/filter_builder.js
1206
1032
  class Expression {
1207
1033
  constructor() {
1208
1034
  __publicField3(this, "_isExpression");
1209
1035
  __publicField3(this, "_value");
1210
1036
  }
1211
1037
  }
1212
- var __defProp4;
1213
- var __defNormalProp3 = (obj, key, value) => (key in obj) ? __defProp4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1214
- var __publicField3 = (obj, key, value) => __defNormalProp3(obj, typeof key !== "symbol" ? key + "" : key, value);
1038
+ 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);
1215
1039
  var init_filter_builder = __esm(() => {
1216
1040
  __defProp4 = Object.defineProperty;
1217
1041
  });
1042
+
1043
+ // ../../node_modules/convex/dist/esm/server/impl/filter_builder_impl.js
1218
1044
  function serializeExpression(expr) {
1219
1045
  if (expr instanceof ExpressionImpl) {
1220
1046
  return expr.serialize();
@@ -1222,16 +1048,12 @@ function serializeExpression(expr) {
1222
1048
  return { $literal: convexOrUndefinedToJson(expr) };
1223
1049
  }
1224
1050
  }
1225
- var __defProp5;
1226
- var __defNormalProp4 = (obj, key, value) => (key in obj) ? __defProp5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1227
- var __publicField4 = (obj, key, value) => __defNormalProp4(obj, typeof key !== "symbol" ? key + "" : key, value);
1228
- var ExpressionImpl;
1229
- var filterBuilderImpl;
1051
+ 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;
1230
1052
  var init_filter_builder_impl = __esm(() => {
1231
1053
  init_value();
1232
1054
  init_filter_builder();
1233
1055
  __defProp5 = Object.defineProperty;
1234
- ExpressionImpl = class ExpressionImpl2 extends Expression {
1056
+ ExpressionImpl = class ExpressionImpl extends Expression {
1235
1057
  constructor(inner) {
1236
1058
  super();
1237
1059
  __publicField4(this, "inner");
@@ -1315,26 +1137,24 @@ var init_filter_builder_impl = __esm(() => {
1315
1137
  };
1316
1138
  });
1317
1139
 
1140
+ // ../../node_modules/convex/dist/esm/server/index_range_builder.js
1318
1141
  class IndexRange {
1319
1142
  constructor() {
1320
1143
  __publicField5(this, "_isIndexRange");
1321
1144
  }
1322
1145
  }
1323
- var __defProp6;
1324
- var __defNormalProp5 = (obj, key, value) => (key in obj) ? __defProp6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1325
- var __publicField5 = (obj, key, value) => __defNormalProp5(obj, typeof key !== "symbol" ? key + "" : key, value);
1146
+ 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);
1326
1147
  var init_index_range_builder = __esm(() => {
1327
1148
  __defProp6 = Object.defineProperty;
1328
1149
  });
1329
- var __defProp7;
1330
- var __defNormalProp6 = (obj, key, value) => (key in obj) ? __defProp7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1331
- var __publicField6 = (obj, key, value) => __defNormalProp6(obj, typeof key !== "symbol" ? key + "" : key, value);
1332
- var IndexRangeBuilderImpl;
1150
+
1151
+ // ../../node_modules/convex/dist/esm/server/impl/index_range_builder_impl.js
1152
+ 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;
1333
1153
  var init_index_range_builder_impl = __esm(() => {
1334
1154
  init_value();
1335
1155
  init_index_range_builder();
1336
1156
  __defProp7 = Object.defineProperty;
1337
- IndexRangeBuilderImpl = class IndexRangeBuilderImpl2 extends IndexRange {
1157
+ IndexRangeBuilderImpl = class IndexRangeBuilderImpl extends IndexRange {
1338
1158
  constructor(rangeExpressions) {
1339
1159
  super();
1340
1160
  __publicField6(this, "rangeExpressions");
@@ -1343,7 +1163,7 @@ var init_index_range_builder_impl = __esm(() => {
1343
1163
  this.isConsumed = false;
1344
1164
  }
1345
1165
  static new() {
1346
- return new IndexRangeBuilderImpl2([]);
1166
+ return new IndexRangeBuilderImpl([]);
1347
1167
  }
1348
1168
  consume() {
1349
1169
  if (this.isConsumed) {
@@ -1353,7 +1173,7 @@ var init_index_range_builder_impl = __esm(() => {
1353
1173
  }
1354
1174
  eq(fieldName, value) {
1355
1175
  this.consume();
1356
- return new IndexRangeBuilderImpl2(this.rangeExpressions.concat({
1176
+ return new IndexRangeBuilderImpl(this.rangeExpressions.concat({
1357
1177
  type: "Eq",
1358
1178
  fieldPath: fieldName,
1359
1179
  value: convexOrUndefinedToJson(value)
@@ -1361,7 +1181,7 @@ var init_index_range_builder_impl = __esm(() => {
1361
1181
  }
1362
1182
  gt(fieldName, value) {
1363
1183
  this.consume();
1364
- return new IndexRangeBuilderImpl2(this.rangeExpressions.concat({
1184
+ return new IndexRangeBuilderImpl(this.rangeExpressions.concat({
1365
1185
  type: "Gt",
1366
1186
  fieldPath: fieldName,
1367
1187
  value: convexOrUndefinedToJson(value)
@@ -1369,7 +1189,7 @@ var init_index_range_builder_impl = __esm(() => {
1369
1189
  }
1370
1190
  gte(fieldName, value) {
1371
1191
  this.consume();
1372
- return new IndexRangeBuilderImpl2(this.rangeExpressions.concat({
1192
+ return new IndexRangeBuilderImpl(this.rangeExpressions.concat({
1373
1193
  type: "Gte",
1374
1194
  fieldPath: fieldName,
1375
1195
  value: convexOrUndefinedToJson(value)
@@ -1377,7 +1197,7 @@ var init_index_range_builder_impl = __esm(() => {
1377
1197
  }
1378
1198
  lt(fieldName, value) {
1379
1199
  this.consume();
1380
- return new IndexRangeBuilderImpl2(this.rangeExpressions.concat({
1200
+ return new IndexRangeBuilderImpl(this.rangeExpressions.concat({
1381
1201
  type: "Lt",
1382
1202
  fieldPath: fieldName,
1383
1203
  value: convexOrUndefinedToJson(value)
@@ -1385,7 +1205,7 @@ var init_index_range_builder_impl = __esm(() => {
1385
1205
  }
1386
1206
  lte(fieldName, value) {
1387
1207
  this.consume();
1388
- return new IndexRangeBuilderImpl2(this.rangeExpressions.concat({
1208
+ return new IndexRangeBuilderImpl(this.rangeExpressions.concat({
1389
1209
  type: "Lte",
1390
1210
  fieldPath: fieldName,
1391
1211
  value: convexOrUndefinedToJson(value)
@@ -1398,26 +1218,24 @@ var init_index_range_builder_impl = __esm(() => {
1398
1218
  };
1399
1219
  });
1400
1220
 
1221
+ // ../../node_modules/convex/dist/esm/server/search_filter_builder.js
1401
1222
  class SearchFilter {
1402
1223
  constructor() {
1403
1224
  __publicField7(this, "_isSearchFilter");
1404
1225
  }
1405
1226
  }
1406
- var __defProp8;
1407
- var __defNormalProp7 = (obj, key, value) => (key in obj) ? __defProp8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1408
- var __publicField7 = (obj, key, value) => __defNormalProp7(obj, typeof key !== "symbol" ? key + "" : key, value);
1227
+ 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);
1409
1228
  var init_search_filter_builder = __esm(() => {
1410
1229
  __defProp8 = Object.defineProperty;
1411
1230
  });
1412
- var __defProp9;
1413
- var __defNormalProp8 = (obj, key, value) => (key in obj) ? __defProp9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1414
- var __publicField8 = (obj, key, value) => __defNormalProp8(obj, typeof key !== "symbol" ? key + "" : key, value);
1415
- var SearchFilterBuilderImpl;
1231
+
1232
+ // ../../node_modules/convex/dist/esm/server/impl/search_filter_builder_impl.js
1233
+ 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;
1416
1234
  var init_search_filter_builder_impl = __esm(() => {
1417
1235
  init_value();
1418
1236
  init_search_filter_builder();
1419
1237
  __defProp9 = Object.defineProperty;
1420
- SearchFilterBuilderImpl = class SearchFilterBuilderImpl2 extends SearchFilter {
1238
+ SearchFilterBuilderImpl = class SearchFilterBuilderImpl extends SearchFilter {
1421
1239
  constructor(filters) {
1422
1240
  super();
1423
1241
  __publicField8(this, "filters");
@@ -1426,7 +1244,7 @@ var init_search_filter_builder_impl = __esm(() => {
1426
1244
  this.isConsumed = false;
1427
1245
  }
1428
1246
  static new() {
1429
- return new SearchFilterBuilderImpl2([]);
1247
+ return new SearchFilterBuilderImpl([]);
1430
1248
  }
1431
1249
  consume() {
1432
1250
  if (this.isConsumed) {
@@ -1438,7 +1256,7 @@ var init_search_filter_builder_impl = __esm(() => {
1438
1256
  validateArg(fieldName, 1, "search", "fieldName");
1439
1257
  validateArg(query, 2, "search", "query");
1440
1258
  this.consume();
1441
- return new SearchFilterBuilderImpl2(this.filters.concat({
1259
+ return new SearchFilterBuilderImpl(this.filters.concat({
1442
1260
  type: "Search",
1443
1261
  fieldPath: fieldName,
1444
1262
  value: query
@@ -1450,7 +1268,7 @@ var init_search_filter_builder_impl = __esm(() => {
1450
1268
  validateArg(value, 2, "search", "value");
1451
1269
  }
1452
1270
  this.consume();
1453
- return new SearchFilterBuilderImpl2(this.filters.concat({
1271
+ return new SearchFilterBuilderImpl(this.filters.concat({
1454
1272
  type: "Eq",
1455
1273
  fieldPath: fieldName,
1456
1274
  value: convexOrUndefinedToJson(value)
@@ -1462,15 +1280,12 @@ var init_search_filter_builder_impl = __esm(() => {
1462
1280
  }
1463
1281
  };
1464
1282
  });
1283
+
1284
+ // ../../node_modules/convex/dist/esm/server/impl/query_impl.js
1465
1285
  function throwClosedError(type) {
1466
1286
  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.");
1467
1287
  }
1468
- var __defProp10;
1469
- var __defNormalProp9 = (obj, key, value) => (key in obj) ? __defProp10(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1470
- var __publicField9 = (obj, key, value) => __defNormalProp9(obj, typeof key !== "symbol" ? key + "" : key, value);
1471
- var MAX_QUERY_OPERATORS = 256;
1472
- var QueryInitializerImpl;
1473
- var QueryImpl;
1288
+ 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;
1474
1289
  var init_query_impl = __esm(() => {
1475
1290
  init_values();
1476
1291
  init_syscall();
@@ -1478,7 +1293,7 @@ var init_query_impl = __esm(() => {
1478
1293
  init_index_range_builder_impl();
1479
1294
  init_search_filter_builder_impl();
1480
1295
  __defProp10 = Object.defineProperty;
1481
- QueryInitializerImpl = class QueryInitializerImpl2 {
1296
+ QueryInitializerImpl = class QueryInitializerImpl {
1482
1297
  constructor(tableName) {
1483
1298
  __publicField9(this, "tableName");
1484
1299
  this.tableName = tableName;
@@ -1557,7 +1372,7 @@ var init_query_impl = __esm(() => {
1557
1372
  return this.fullTableScan()[Symbol.asyncIterator]();
1558
1373
  }
1559
1374
  };
1560
- QueryImpl = class QueryImpl2 {
1375
+ QueryImpl = class QueryImpl {
1561
1376
  constructor(query) {
1562
1377
  __publicField9(this, "state");
1563
1378
  __publicField9(this, "tableNameForErrorMessages");
@@ -1605,7 +1420,7 @@ var init_query_impl = __esm(() => {
1605
1420
  throw new Error("Queries may only specify order at most once");
1606
1421
  }
1607
1422
  query.source.order = order;
1608
- return new QueryImpl2(query);
1423
+ return new QueryImpl(query);
1609
1424
  }
1610
1425
  filter(predicate) {
1611
1426
  validateArg(predicate, 1, "filter", "predicate");
@@ -1616,13 +1431,13 @@ var init_query_impl = __esm(() => {
1616
1431
  query.operators.push({
1617
1432
  filter: serializeExpression(predicate(filterBuilderImpl))
1618
1433
  });
1619
- return new QueryImpl2(query);
1434
+ return new QueryImpl(query);
1620
1435
  }
1621
1436
  limit(n) {
1622
1437
  validateArg(n, 1, "limit", "n");
1623
1438
  const query = this.takeQuery();
1624
1439
  query.operators.push({ limit: n });
1625
- return new QueryImpl2(query);
1440
+ return new QueryImpl(query);
1626
1441
  }
1627
1442
  [Symbol.asyncIterator]() {
1628
1443
  this.startQuery();
@@ -1702,6 +1517,8 @@ var init_query_impl = __esm(() => {
1702
1517
  }
1703
1518
  };
1704
1519
  });
1520
+
1521
+ // ../../node_modules/convex/dist/esm/server/impl/database_impl.js
1705
1522
  async function get(table, id, isSystem) {
1706
1523
  validateArg(id, 1, "get", "id");
1707
1524
  if (typeof id !== "string") {
@@ -1835,7 +1652,7 @@ var init_database_impl = __esm(() => {
1835
1652
  init_syscall();
1836
1653
  init_query_impl();
1837
1654
  init_value();
1838
- TableWriter = class TableWriter2 extends TableReader {
1655
+ TableWriter = class TableWriter extends TableReader {
1839
1656
  async insert(value) {
1840
1657
  return insert(this.tableName, value);
1841
1658
  }
@@ -1850,6 +1667,8 @@ var init_database_impl = __esm(() => {
1850
1667
  }
1851
1668
  };
1852
1669
  });
1670
+
1671
+ // ../../node_modules/convex/dist/esm/server/impl/scheduler_impl.js
1853
1672
  function setupMutationScheduler() {
1854
1673
  return {
1855
1674
  runAfter: async (delayMs, functionReference, args) => {
@@ -1910,6 +1729,8 @@ var init_scheduler_impl = __esm(() => {
1910
1729
  init_syscall();
1911
1730
  init_paths();
1912
1731
  });
1732
+
1733
+ // ../../node_modules/convex/dist/esm/server/impl/storage_impl.js
1913
1734
  function setupStorageReader(requestId) {
1914
1735
  return {
1915
1736
  getUrl: async (storageId) => {
@@ -1952,6 +1773,8 @@ function setupStorageWriter(requestId) {
1952
1773
  var init_storage_impl = __esm(() => {
1953
1774
  init_syscall();
1954
1775
  });
1776
+
1777
+ // ../../node_modules/convex/dist/esm/server/impl/registration_impl.js
1955
1778
  async function invokeMutation(func, argsStr) {
1956
1779
  const requestId = "";
1957
1780
  const args = jsonToConvex(JSON.parse(argsStr));
@@ -2064,8 +1887,7 @@ var mutationGeneric = (functionDefinition) => {
2064
1887
  func.exportReturns = exportReturns(functionDefinition);
2065
1888
  func._handler = handler;
2066
1889
  return func;
2067
- };
2068
- var queryGeneric = (functionDefinition) => {
1890
+ }, queryGeneric = (functionDefinition) => {
2069
1891
  const handler = typeof functionDefinition === "function" ? functionDefinition : functionDefinition.handler;
2070
1892
  const func = dontCallDirectly("query", handler);
2071
1893
  assertNotBrowser();
@@ -2088,6 +1910,8 @@ var init_registration_impl = __esm(() => {
2088
1910
  init_validator();
2089
1911
  init_paths();
2090
1912
  });
1913
+
1914
+ // ../../node_modules/convex/dist/esm/server/pagination.js
2091
1915
  var paginationOptsValidator;
2092
1916
  var init_pagination = __esm(() => {
2093
1917
  init_validator();
@@ -2100,11 +1924,34 @@ var init_pagination = __esm(() => {
2100
1924
  maximumBytesRead: v.optional(v.number())
2101
1925
  });
2102
1926
  });
1927
+
1928
+ // ../../node_modules/convex/dist/esm/server/index.js
2103
1929
  var init_server = __esm(() => {
2104
1930
  init_registration_impl();
2105
1931
  init_pagination();
2106
1932
  init_search_filter_builder();
2107
1933
  });
1934
+
1935
+ // ../core/dist/kernel/missing-schema-error.js
1936
+ function isMissingSchemaModuleError(error) {
1937
+ if (!error)
1938
+ return false;
1939
+ const errorString = String(error);
1940
+ const isMissing = errorString.includes('Unable to resolve module "schema"') || errorString.includes("Module not found: schema") || errorString.includes('Unable to resolve module "convex/schema"');
1941
+ if (isMissing)
1942
+ return true;
1943
+ const causes = error.causes;
1944
+ if (Array.isArray(causes)) {
1945
+ return causes.some(isMissingSchemaModuleError);
1946
+ }
1947
+ const cause = error.cause;
1948
+ if (cause) {
1949
+ return isMissingSchemaModuleError(cause);
1950
+ }
1951
+ return false;
1952
+ }
1953
+
1954
+ // ../core/dist/udf/analysis/udf-analyze.js
2108
1955
  function invalidUdfError(message) {
2109
1956
  return new UdfAnalysisError(message);
2110
1957
  }
@@ -2295,17 +2142,21 @@ function analyzeCrons(crons) {
2295
2142
  }
2296
2143
  var UdfAnalysisError;
2297
2144
  var init_udf_analyze = __esm(() => {
2298
- UdfAnalysisError = class UdfAnalysisError2 extends Error {
2145
+ UdfAnalysisError = class UdfAnalysisError extends Error {
2299
2146
  constructor(message) {
2300
2147
  super(message);
2301
2148
  this.name = "UdfAnalysisError";
2302
2149
  }
2303
2150
  };
2304
2151
  });
2152
+
2153
+ // ../core/dist/udf/analysis/index.js
2305
2154
  var init_analysis = __esm(() => {
2306
2155
  init_udf_analyze();
2307
2156
  init_validator2();
2308
2157
  });
2158
+
2159
+ // ../core/dist/system/function-introspection.js
2309
2160
  async function listSystemFunctions(options = {}) {
2310
2161
  const componentPath = options.componentPath;
2311
2162
  const moduleLoader = await ensureModuleLoaderApi();
@@ -2456,14 +2307,13 @@ function isNpmPackageError(error) {
2456
2307
  return !modulePath.startsWith(".") && !modulePath.startsWith("/");
2457
2308
  });
2458
2309
  }
2459
- var moduleAnalysisCache;
2460
- var moduleLoaderApiPromise = null;
2461
- var unsubscribeModuleLoader = null;
2310
+ var moduleAnalysisCache, moduleLoaderApiPromise = null, unsubscribeModuleLoader = null;
2462
2311
  var init_function_introspection = __esm(() => {
2463
2312
  init_analysis();
2464
2313
  moduleAnalysisCache = new Map;
2465
2314
  });
2466
2315
 
2316
+ // ../core/dist/system/execution-log.js
2467
2317
  class InMemoryLogSink {
2468
2318
  entries = [];
2469
2319
  nextId = 1;
@@ -2512,11 +2362,12 @@ function queryExecutionLog(filter = {}) {
2512
2362
  function clearExecutionLog() {
2513
2363
  defaultSink.clear();
2514
2364
  }
2515
- var MAX_ENTRIES = 1000;
2516
- var defaultSink;
2365
+ var MAX_ENTRIES = 1000, defaultSink;
2517
2366
  var init_execution_log = __esm(() => {
2518
2367
  defaultSink = new InMemoryLogSink;
2519
2368
  });
2369
+
2370
+ // ../core/dist/system/internal.js
2520
2371
  function createSystemFunctions(deps) {
2521
2372
  const { query, mutation } = deps;
2522
2373
  return {
@@ -2908,8 +2759,9 @@ function createSystemFunctions(deps) {
2908
2759
  systemListFunctions: query({
2909
2760
  args: { componentPath: v.optional(v.string()) },
2910
2761
  handler: async (ctx, args) => {
2911
- const componentPath = args.componentPath ?? ctx?.componentPath ?? undefined;
2912
- const functions = await listSystemFunctions({ componentPath });
2762
+ const requestedComponentPath = args.componentPath ?? ctx?.componentPath ?? undefined;
2763
+ const normalizedComponentPath = typeof requestedComponentPath === "string" && requestedComponentPath.trim().length === 0 ? undefined : requestedComponentPath;
2764
+ const functions = await listSystemFunctions({ componentPath: normalizedComponentPath });
2913
2765
  return functions.map((fn) => ({
2914
2766
  name: fn.name,
2915
2767
  path: fn.path,
@@ -3108,11 +2960,16 @@ function describeFieldType(node) {
3108
2960
  var init_internal = __esm(() => {
3109
2961
  init_values();
3110
2962
  init_module_loader();
3111
- init_schema_service();
3112
2963
  init_function_introspection();
3113
2964
  init_interface();
3114
2965
  init_execution_log();
3115
2966
  });
2967
+
2968
+ // ../core/dist/system/system-functions-module.js
2969
+ var exports_system_functions_module = {};
2970
+ __export(exports_system_functions_module, {
2971
+ getSystemFunctionsModule: () => getSystemFunctionsModule
2972
+ });
3116
2973
  function getSystemFunctionsModule() {
3117
2974
  return systemFunctions;
3118
2975
  }
@@ -3125,6 +2982,8 @@ var init_system_functions_module = __esm(() => {
3125
2982
  mutation: mutationGeneric
3126
2983
  });
3127
2984
  });
2985
+
2986
+ // ../core/dist/udf/module-loader/module-loader.js
3128
2987
  var exports_module_loader = {};
3129
2988
  __export(exports_module_loader, {
3130
2989
  withModuleRegistry: () => withModuleRegistry,
@@ -3143,6 +3002,23 @@ __export(exports_module_loader, {
3143
3002
  clearModuleLoader: () => clearModuleLoader,
3144
3003
  ModuleRegistry: () => ModuleRegistry
3145
3004
  });
3005
+ function allowConvexFunctionsInBrowser() {
3006
+ if (browserConvexFunctionsAllowed) {
3007
+ return;
3008
+ }
3009
+ browserConvexFunctionsAllowed = true;
3010
+ const globalAny = globalThis;
3011
+ if (globalAny.window && typeof globalAny.window === "object") {
3012
+ globalAny.window.__convexAllowFunctionsInBrowser = true;
3013
+ }
3014
+ }
3015
+ async function getBuiltInSystemFunctionsModule() {
3016
+ if (!builtInSystemFunctionsModulePromise) {
3017
+ allowConvexFunctionsInBrowser();
3018
+ builtInSystemFunctionsModulePromise = Promise.resolve().then(() => (init_system_functions_module(), exports_system_functions_module)).then((mod) => mod.getSystemFunctionsModule());
3019
+ }
3020
+ return builtInSystemFunctionsModulePromise;
3021
+ }
3146
3022
 
3147
3023
  class ModuleRegistry {
3148
3024
  scopedLoaders = new Map;
@@ -3195,6 +3071,7 @@ class ModuleRegistry {
3195
3071
  };
3196
3072
  }
3197
3073
  async load(request) {
3074
+ allowConvexFunctionsInBrowser();
3198
3075
  const scopes = expandComponentScopes(request.componentPath);
3199
3076
  const errors2 = [];
3200
3077
  let attempted = false;
@@ -3286,6 +3163,8 @@ function getModuleState() {
3286
3163
  function resetModuleState() {
3287
3164
  const globalAny = globalThis;
3288
3165
  delete globalAny[MODULE_STATE_SYMBOL];
3166
+ builtInSystemFunctionsModulePromise = undefined;
3167
+ browserConvexFunctionsAllowed = false;
3289
3168
  }
3290
3169
  function getModuleRegistry() {
3291
3170
  return MODULE_REGISTRY_CONTEXT.getStore() ?? getModuleState().registry;
@@ -3320,7 +3199,7 @@ async function loadConvexModule(specifier, options = {}) {
3320
3199
  return await getModuleRegistry().load(request);
3321
3200
  } catch (error) {
3322
3201
  if (error?.message?.includes("Unable to resolve")) {
3323
- return getSystemFunctionsModule();
3202
+ return await getBuiltInSystemFunctionsModule();
3324
3203
  }
3325
3204
  throw error;
3326
3205
  }
@@ -3549,16 +3428,15 @@ function isIterable(value) {
3549
3428
  function isAsyncIterable(value) {
3550
3429
  return value && typeof value[Symbol.asyncIterator] === "function";
3551
3430
  }
3552
- var MODULE_STATE_SYMBOL;
3553
- var MODULE_LOADER_METADATA_SYMBOL;
3554
- var MODULE_REGISTRY_CONTEXT;
3431
+ var MODULE_STATE_SYMBOL, MODULE_LOADER_METADATA_SYMBOL, MODULE_REGISTRY_CONTEXT, builtInSystemFunctionsModulePromise, browserConvexFunctionsAllowed = false;
3555
3432
  var init_module_loader = __esm(() => {
3556
- init_system_functions_module();
3433
+ init_context_storage();
3557
3434
  MODULE_STATE_SYMBOL = Symbol.for("concave.moduleLoader.state");
3558
3435
  MODULE_LOADER_METADATA_SYMBOL = Symbol.for("concave.moduleLoader.metadata");
3559
- MODULE_REGISTRY_CONTEXT = new AsyncLocalStorage;
3436
+ MODULE_REGISTRY_CONTEXT = new ContextStorage;
3560
3437
  });
3561
3438
 
3439
+ // ../core/dist/udf/analysis/validator.js
3562
3440
  class SchemaValidator {
3563
3441
  schemaCache = new Map;
3564
3442
  componentPath;
@@ -3810,8 +3688,7 @@ var ValidatorError;
3810
3688
  var init_validator2 = __esm(() => {
3811
3689
  init_interface();
3812
3690
  init_module_loader();
3813
- init_schema_service();
3814
- ValidatorError = class ValidatorError2 extends Error {
3691
+ ValidatorError = class ValidatorError extends Error {
3815
3692
  path;
3816
3693
  constructor(message, path = "") {
3817
3694
  super(message);
@@ -3821,160 +3698,7 @@ var init_validator2 = __esm(() => {
3821
3698
  };
3822
3699
  });
3823
3700
 
3824
- class SchemaService {
3825
- cachedSchemaDefinition = undefined;
3826
- tableCache = new Map;
3827
- schemaValidator;
3828
- componentPath;
3829
- constructor(componentPath) {
3830
- this.componentPath = componentPath;
3831
- this.schemaValidator = new SchemaValidator(componentPath);
3832
- }
3833
- async validate(tableName, document) {
3834
- try {
3835
- await this.schemaValidator.validateDocument(tableName, document);
3836
- } catch (error) {
3837
- if (error instanceof ValidatorError) {
3838
- throw new Error(error.message);
3839
- }
3840
- throw error;
3841
- }
3842
- }
3843
- async getTableSchema(tableName) {
3844
- if (this.tableCache.has(tableName)) {
3845
- return this.tableCache.get(tableName) ?? null;
3846
- }
3847
- const schemaDefinition = await this.getSchemaDefinition();
3848
- const tableSchema = schemaDefinition?.tables?.[tableName] ?? null;
3849
- this.tableCache.set(tableName, tableSchema);
3850
- return tableSchema;
3851
- }
3852
- async getIndexFieldsForTable(tableName, indexDescriptor) {
3853
- if (indexDescriptor === "by_creation_time") {
3854
- return ["_creationTime", "_id"];
3855
- }
3856
- if (indexDescriptor === "by_id") {
3857
- return ["_id"];
3858
- }
3859
- const tableSchema = await this.getTableSchema(tableName);
3860
- const dbIndexes = tableSchema?.indexes;
3861
- const matchingIndex = dbIndexes?.find((idx) => idx.indexDescriptor === indexDescriptor);
3862
- if (!matchingIndex) {
3863
- return null;
3864
- }
3865
- return [...matchingIndex.fields, "_creationTime", "_id"];
3866
- }
3867
- async getAllIndexesForTable(tableName) {
3868
- const indexes = [...getStandardIndexes()];
3869
- const tableSchema = await this.getTableSchema(tableName);
3870
- const schemaIndexes = tableSchema?.indexes;
3871
- if (schemaIndexes) {
3872
- for (const idx of schemaIndexes) {
3873
- indexes.push({
3874
- name: idx.indexDescriptor,
3875
- fields: [...idx.fields, "_creationTime", "_id"]
3876
- });
3877
- }
3878
- }
3879
- return indexes;
3880
- }
3881
- async getSearchIndexConfig(tableName, indexDescriptor) {
3882
- const tableSchema = await this.getTableSchema(tableName);
3883
- const searchIndexes = tableSchema?.searchIndexes;
3884
- return searchIndexes?.find((idx) => idx.indexDescriptor === indexDescriptor) ?? null;
3885
- }
3886
- async getVectorIndexConfig(tableName, indexDescriptor) {
3887
- const tableSchema = await this.getTableSchema(tableName);
3888
- const vectorIndexes = tableSchema?.vectorIndexes;
3889
- return vectorIndexes?.find((idx) => idx.indexDescriptor === indexDescriptor) ?? null;
3890
- }
3891
- async getAllVectorIndexes() {
3892
- const schemaDefinition = await this.getSchemaDefinition();
3893
- if (!schemaDefinition?.tables) {
3894
- return [];
3895
- }
3896
- const allVectorIndexes = [];
3897
- for (const [tableName, tableSchema] of Object.entries(schemaDefinition.tables)) {
3898
- const vectorIndexes = tableSchema?.vectorIndexes;
3899
- if (vectorIndexes) {
3900
- for (const vectorIndex of vectorIndexes) {
3901
- allVectorIndexes.push({
3902
- tableName,
3903
- indexDescriptor: vectorIndex.indexDescriptor,
3904
- vectorField: vectorIndex.vectorField,
3905
- filterFields: vectorIndex.filterFields ?? []
3906
- });
3907
- }
3908
- }
3909
- }
3910
- return allVectorIndexes;
3911
- }
3912
- async getAllSearchIndexes() {
3913
- const schemaDefinition = await this.getSchemaDefinition();
3914
- if (!schemaDefinition?.tables) {
3915
- return [];
3916
- }
3917
- const allSearchIndexes = [];
3918
- for (const [tableName, tableSchema] of Object.entries(schemaDefinition.tables)) {
3919
- const searchIndexes = tableSchema?.searchIndexes;
3920
- if (searchIndexes) {
3921
- for (const searchIndex of searchIndexes) {
3922
- allSearchIndexes.push({
3923
- tableName,
3924
- indexDescriptor: searchIndex.indexDescriptor,
3925
- searchField: searchIndex.searchField,
3926
- filterFields: searchIndex.filterFields ?? []
3927
- });
3928
- }
3929
- }
3930
- }
3931
- return allSearchIndexes;
3932
- }
3933
- async getTableNames() {
3934
- const schemaDefinition = await this.getSchemaDefinition();
3935
- if (!schemaDefinition?.tables) {
3936
- return [];
3937
- }
3938
- return Object.keys(schemaDefinition.tables);
3939
- }
3940
- async getSchemaDefinition() {
3941
- if (this.cachedSchemaDefinition !== undefined) {
3942
- return this.cachedSchemaDefinition;
3943
- }
3944
- try {
3945
- const schemaModule = await loadConvexModule("schema", { hint: "schema", componentPath: this.componentPath });
3946
- this.cachedSchemaDefinition = schemaModule.default ?? null;
3947
- } catch (error) {
3948
- if (!isMissingSchemaModuleError(error)) {
3949
- console.warn("Failed to load Convex schema definition:", error);
3950
- }
3951
- this.cachedSchemaDefinition = null;
3952
- }
3953
- return this.cachedSchemaDefinition;
3954
- }
3955
- }
3956
- function isMissingSchemaModuleError(error) {
3957
- if (!error)
3958
- return false;
3959
- const errorString = String(error);
3960
- const isMissing = errorString.includes('Unable to resolve module "schema"') || errorString.includes("Module not found: schema") || errorString.includes('Unable to resolve module "convex/schema"');
3961
- if (isMissing)
3962
- return true;
3963
- const causes = error.causes;
3964
- if (Array.isArray(causes)) {
3965
- return causes.some(isMissingSchemaModuleError);
3966
- }
3967
- const cause = error.cause;
3968
- if (cause) {
3969
- return isMissingSchemaModuleError(cause);
3970
- }
3971
- return false;
3972
- }
3973
- var init_schema_service = __esm(() => {
3974
- init_index_manager();
3975
- init_validator2();
3976
- init_module_loader();
3977
- });
3701
+ // ../core/dist/id-codec/base32.js
3978
3702
  function base32Encode(data) {
3979
3703
  if (data.length === 0)
3980
3704
  return "";
@@ -4026,8 +3750,7 @@ function isValidBase32(str) {
4026
3750
  }
4027
3751
  return true;
4028
3752
  }
4029
- var ALPHABET = "0123456789abcdefghjkmnpqrstvwxyz";
4030
- var ALPHABET_MAP;
3753
+ var ALPHABET = "0123456789abcdefghjkmnpqrstvwxyz", ALPHABET_MAP;
4031
3754
  var init_base32 = __esm(() => {
4032
3755
  ALPHABET_MAP = new Map;
4033
3756
  for (let i2 = 0;i2 < ALPHABET.length; i2++) {
@@ -4041,6 +3764,8 @@ var init_base32 = __esm(() => {
4041
3764
  ALPHABET_MAP.set("o", 0);
4042
3765
  ALPHABET_MAP.set("O", 0);
4043
3766
  });
3767
+
3768
+ // ../core/dist/id-codec/vint.js
4044
3769
  function vintEncode(value) {
4045
3770
  if (value < 0) {
4046
3771
  throw new Error("VInt cannot encode negative numbers");
@@ -4118,6 +3843,8 @@ function vintDecode(data, offset = 0) {
4118
3843
  }
4119
3844
  throw new Error("VInt decode: invalid prefix");
4120
3845
  }
3846
+
3847
+ // ../core/dist/id-codec/fletcher16.js
4121
3848
  function fletcher16(data) {
4122
3849
  let sum1 = 0;
4123
3850
  let sum2 = 0;
@@ -4133,6 +3860,14 @@ function verifyFletcher16(data, checksum) {
4133
3860
  const computed = fletcher16(data);
4134
3861
  return computed[0] === checksum[0] && computed[1] === checksum[1];
4135
3862
  }
3863
+
3864
+ // ../core/dist/utils/crypto.js
3865
+ var weakRandomState;
3866
+ var init_crypto = __esm(() => {
3867
+ weakRandomState = (Date.now() ^ 2654435769) >>> 0;
3868
+ });
3869
+
3870
+ // ../core/dist/id-codec/document-id.js
4136
3871
  function encodeDocumentId(tableNumber, internalId) {
4137
3872
  if (internalId.length !== INTERNAL_ID_LENGTH) {
4138
3873
  throw new Error(`Internal ID must be exactly ${INTERNAL_ID_LENGTH} bytes, got ${internalId.length}`);
@@ -4188,15 +3923,19 @@ function internalIdToHex(internalId) {
4188
3923
  }
4189
3924
  return hex;
4190
3925
  }
4191
- var INTERNAL_ID_LENGTH = 16;
4192
- var MIN_ENCODED_LENGTH = 31;
4193
- var MAX_ENCODED_LENGTH = 37;
4194
- var cryptoGetRandomValues;
3926
+ var INTERNAL_ID_LENGTH = 16, MIN_ENCODED_LENGTH = 31, MAX_ENCODED_LENGTH = 37;
4195
3927
  var init_document_id = __esm(() => {
4196
3928
  init_base32();
4197
- cryptoGetRandomValues = crypto.getRandomValues.bind(crypto);
3929
+ init_crypto();
4198
3930
  });
3931
+
3932
+ // src/sqlite-docstore.ts
3933
+ import Database from "better-sqlite3";
3934
+
3935
+ // ../docstore-sqlite-base/dist/base.js
4199
3936
  init_values();
3937
+
3938
+ // ../core/dist/docstore/interface.js
4200
3939
  function documentIdKey(id) {
4201
3940
  return `${id.table}:${id.internalId}`;
4202
3941
  }
@@ -4211,6 +3950,7 @@ function getPrevRevQueryKey(query) {
4211
3950
  function getExactRevQueryKey(query) {
4212
3951
  return `${documentIdKey(query.id)}:${query.ts}:${query.prev_ts}`;
4213
3952
  }
3953
+ // ../core/dist/docstore/sql/search-schema.js
4214
3954
  var SEARCH_INDEXES_FTS_SCHEMA = `
4215
3955
  CREATE VIRTUAL TABLE IF NOT EXISTS search_indexes USING fts5(
4216
3956
  index_id UNINDEXED,
@@ -4243,6 +3983,8 @@ function extractSearchContent(docValue, searchField) {
4243
3983
  }
4244
3984
  return null;
4245
3985
  }
3986
+
3987
+ // ../core/dist/docstore/sql/schema.js
4246
3988
  var DOCUMENTS_TABLE_SCHEMA = `
4247
3989
  CREATE TABLE IF NOT EXISTS documents (
4248
3990
  id BLOB NOT NULL,
@@ -4275,7 +4017,7 @@ var GLOBALS_TABLE_SCHEMA = `
4275
4017
  json_value TEXT NOT NULL
4276
4018
  );
4277
4019
  `;
4278
-
4020
+ // ../core/dist/utils/long.js
4279
4021
  class Long {
4280
4022
  low;
4281
4023
  high;
@@ -4363,7 +4105,7 @@ var TWO_PWR_16_DBL = 1 << 16;
4363
4105
  var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
4364
4106
  var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
4365
4107
  var MAX_UNSIGNED_VALUE = new Long(4294967295 | 0, 4294967295 | 0);
4366
-
4108
+ // ../core/dist/utils/timestamp.js
4367
4109
  class TimestampOracle {
4368
4110
  logicalClock;
4369
4111
  allocationQueue = Promise.resolve();
@@ -4389,59 +4131,421 @@ class TimestampOracle {
4389
4131
  if (this.logicalClock === 0n) {
4390
4132
  return BigInt(Date.now());
4391
4133
  }
4392
- return this.logicalClock;
4134
+ return this.logicalClock;
4135
+ }
4136
+ observeTimestamp(ts) {
4137
+ if (ts > this.logicalClock) {
4138
+ this.logicalClock = ts;
4139
+ }
4140
+ }
4141
+ reset(ts = 0n) {
4142
+ this.logicalClock = ts;
4143
+ }
4144
+ }
4145
+ // ../core/dist/utils/keyspace.js
4146
+ var TABLE_PREFIX = "table";
4147
+ var INDEX_PREFIX = "index";
4148
+ function encodeComponent(component) {
4149
+ return encodeURIComponent(component);
4150
+ }
4151
+ function tableKeyspace(table) {
4152
+ return { kind: "table", table };
4153
+ }
4154
+ function indexKeyspace(table, index) {
4155
+ return { kind: "index", table, index };
4156
+ }
4157
+ function keyspaceId(namespace) {
4158
+ if (namespace.kind === "table") {
4159
+ return `${TABLE_PREFIX}:${encodeComponent(namespace.table)}`;
4160
+ }
4161
+ return `${INDEX_PREFIX}:${encodeComponent(namespace.table)}:${encodeComponent(namespace.index)}`;
4162
+ }
4163
+ function tableKeyspaceId(table) {
4164
+ return keyspaceId(tableKeyspace(table));
4165
+ }
4166
+ function indexKeyspaceId(table, index) {
4167
+ return keyspaceId(indexKeyspace(table, index));
4168
+ }
4169
+ function decodeIndexId(indexId) {
4170
+ const decoded = (() => {
4171
+ try {
4172
+ return hexToString(indexId);
4173
+ } catch {
4174
+ return indexId;
4175
+ }
4176
+ })();
4177
+ const separatorIndex = decoded.indexOf(":");
4178
+ if (separatorIndex === -1) {
4179
+ throw new Error(`Invalid index id: ${indexId}`);
4180
+ }
4181
+ return {
4182
+ table: decoded.slice(0, separatorIndex),
4183
+ index: decoded.slice(separatorIndex + 1)
4184
+ };
4185
+ }
4186
+ // ../core/dist/queryengine/indexing/index-key-codec.js
4187
+ var TypeTag;
4188
+ (function(TypeTag2) {
4189
+ TypeTag2[TypeTag2["Null"] = 0] = "Null";
4190
+ TypeTag2[TypeTag2["False"] = 16] = "False";
4191
+ TypeTag2[TypeTag2["True"] = 17] = "True";
4192
+ TypeTag2[TypeTag2["NegativeInfinity"] = 32] = "NegativeInfinity";
4193
+ TypeTag2[TypeTag2["NegativeNumber"] = 33] = "NegativeNumber";
4194
+ TypeTag2[TypeTag2["NegativeZero"] = 34] = "NegativeZero";
4195
+ TypeTag2[TypeTag2["Zero"] = 35] = "Zero";
4196
+ TypeTag2[TypeTag2["PositiveNumber"] = 36] = "PositiveNumber";
4197
+ TypeTag2[TypeTag2["PositiveInfinity"] = 37] = "PositiveInfinity";
4198
+ TypeTag2[TypeTag2["NaN"] = 38] = "NaN";
4199
+ TypeTag2[TypeTag2["NegativeBigInt"] = 48] = "NegativeBigInt";
4200
+ TypeTag2[TypeTag2["ZeroBigInt"] = 49] = "ZeroBigInt";
4201
+ TypeTag2[TypeTag2["PositiveBigInt"] = 50] = "PositiveBigInt";
4202
+ TypeTag2[TypeTag2["String"] = 64] = "String";
4203
+ TypeTag2[TypeTag2["Bytes"] = 80] = "Bytes";
4204
+ })(TypeTag || (TypeTag = {}));
4205
+ function encodeNumber(n) {
4206
+ const buffer = new ArrayBuffer(8);
4207
+ const view = new DataView(buffer);
4208
+ view.setFloat64(0, n, false);
4209
+ const bytes = new Uint8Array(buffer);
4210
+ if (n >= 0) {
4211
+ bytes[0] ^= 128;
4212
+ } else {
4213
+ for (let i2 = 0;i2 < 8; i2++) {
4214
+ bytes[i2] ^= 255;
4215
+ }
4216
+ }
4217
+ return bytes;
4218
+ }
4219
+ function encodeBigInt(n) {
4220
+ const INT64_MIN = -(2n ** 63n);
4221
+ const INT64_MAX = 2n ** 63n - 1n;
4222
+ if (n < INT64_MIN)
4223
+ n = INT64_MIN;
4224
+ if (n > INT64_MAX)
4225
+ n = INT64_MAX;
4226
+ const buffer = new ArrayBuffer(8);
4227
+ const view = new DataView(buffer);
4228
+ const unsigned = n < 0n ? n + 2n ** 64n : n;
4229
+ view.setBigUint64(0, unsigned, false);
4230
+ const bytes = new Uint8Array(buffer);
4231
+ bytes[0] ^= 128;
4232
+ return bytes;
4233
+ }
4234
+ function encodeString(s) {
4235
+ const encoder = new TextEncoder;
4236
+ const raw = encoder.encode(s);
4237
+ let nullCount = 0;
4238
+ for (const byte of raw) {
4239
+ if (byte === 0)
4240
+ nullCount++;
4241
+ }
4242
+ const result = new Uint8Array(raw.length + nullCount + 2);
4243
+ let writeIndex = 0;
4244
+ for (const byte of raw) {
4245
+ if (byte === 0) {
4246
+ result[writeIndex++] = 0;
4247
+ result[writeIndex++] = 1;
4248
+ } else {
4249
+ result[writeIndex++] = byte;
4250
+ }
4251
+ }
4252
+ result[writeIndex++] = 0;
4253
+ result[writeIndex++] = 0;
4254
+ return result;
4255
+ }
4256
+ function encodeValue(value) {
4257
+ if (value === null || value === undefined) {
4258
+ return new Uint8Array([TypeTag.Null]);
4259
+ }
4260
+ if (typeof value === "boolean") {
4261
+ return new Uint8Array([value ? TypeTag.True : TypeTag.False]);
4262
+ }
4263
+ if (typeof value === "number") {
4264
+ if (Number.isNaN(value)) {
4265
+ return new Uint8Array([TypeTag.NaN]);
4266
+ }
4267
+ if (!Number.isFinite(value)) {
4268
+ return new Uint8Array([value === -Infinity ? TypeTag.NegativeInfinity : TypeTag.PositiveInfinity]);
4269
+ }
4270
+ if (value === 0) {
4271
+ return new Uint8Array([Object.is(value, -0) ? TypeTag.NegativeZero : TypeTag.Zero]);
4272
+ }
4273
+ const tag = value > 0 ? TypeTag.PositiveNumber : TypeTag.NegativeNumber;
4274
+ const encoded = encodeNumber(value);
4275
+ const result = new Uint8Array(1 + encoded.length);
4276
+ result[0] = tag;
4277
+ result.set(encoded, 1);
4278
+ return result;
4279
+ }
4280
+ if (typeof value === "bigint") {
4281
+ if (value === 0n) {
4282
+ return new Uint8Array([TypeTag.ZeroBigInt]);
4283
+ }
4284
+ const tag = value > 0n ? TypeTag.PositiveBigInt : TypeTag.NegativeBigInt;
4285
+ const encoded = encodeBigInt(value);
4286
+ const result = new Uint8Array(1 + encoded.length);
4287
+ result[0] = tag;
4288
+ result.set(encoded, 1);
4289
+ return result;
4290
+ }
4291
+ if (typeof value === "string") {
4292
+ const encoded = encodeString(value);
4293
+ const result = new Uint8Array(1 + encoded.length);
4294
+ result[0] = TypeTag.String;
4295
+ result.set(encoded, 1);
4296
+ return result;
4297
+ }
4298
+ if (value instanceof ArrayBuffer || value instanceof Uint8Array) {
4299
+ const bytes = value instanceof Uint8Array ? value : new Uint8Array(value);
4300
+ const result = new Uint8Array(1 + bytes.length + 2);
4301
+ result[0] = TypeTag.Bytes;
4302
+ result.set(bytes, 1);
4303
+ result[result.length - 2] = 0;
4304
+ result[result.length - 1] = 0;
4305
+ return result;
4306
+ }
4307
+ throw new Error(`Cannot encode value of type ${typeof value} in index key`);
4308
+ }
4309
+ function encodeIndexKey(values) {
4310
+ if (values.length === 0) {
4311
+ return new ArrayBuffer(0);
4312
+ }
4313
+ const encoded = values.map(encodeValue);
4314
+ const totalLength = encoded.reduce((sum, arr) => sum + arr.length, 0);
4315
+ const result = new Uint8Array(totalLength);
4316
+ let offset = 0;
4317
+ for (const chunk of encoded) {
4318
+ result.set(chunk, offset);
4319
+ offset += chunk.length;
4320
+ }
4321
+ return result.buffer;
4322
+ }
4323
+ function compareIndexKeys(a, b) {
4324
+ const viewA = new Uint8Array(a);
4325
+ const viewB = new Uint8Array(b);
4326
+ const minLen = Math.min(viewA.length, viewB.length);
4327
+ for (let i2 = 0;i2 < minLen; i2++) {
4328
+ if (viewA[i2] < viewB[i2])
4329
+ return -1;
4330
+ if (viewA[i2] > viewB[i2])
4331
+ return 1;
4332
+ }
4333
+ if (viewA.length < viewB.length)
4334
+ return -1;
4335
+ if (viewA.length > viewB.length)
4336
+ return 1;
4337
+ return 0;
4338
+ }
4339
+ function indexKeysEqual(a, b) {
4340
+ return compareIndexKeys(a, b) === 0;
4341
+ }
4342
+
4343
+ // ../core/dist/queryengine/indexing/index-manager.js
4344
+ function getFieldValue(doc, fieldPath) {
4345
+ const parts = fieldPath.split(".");
4346
+ let current = doc;
4347
+ for (const part of parts) {
4348
+ if (current === null || current === undefined) {
4349
+ return;
4350
+ }
4351
+ if (typeof current !== "object" || Array.isArray(current)) {
4352
+ return;
4353
+ }
4354
+ current = current[part];
4355
+ }
4356
+ return current;
4357
+ }
4358
+ function extractIndexKey(doc, fields) {
4359
+ const values = [];
4360
+ for (const field of fields) {
4361
+ const value = getFieldValue(doc, field);
4362
+ if (value === undefined) {
4363
+ return null;
4364
+ }
4365
+ values.push(value);
4366
+ }
4367
+ return encodeIndexKey(values);
4368
+ }
4369
+ function generateIndexUpdates(tableName, docId, newValue, oldValue, indexes) {
4370
+ const updates = [];
4371
+ for (const index of indexes) {
4372
+ const indexId = stringToHex(`${tableName}:${index.name}`);
4373
+ const oldKey = oldValue !== null ? extractIndexKey(oldValue, index.fields) : null;
4374
+ const newKey = newValue !== null ? extractIndexKey(newValue, index.fields) : null;
4375
+ const keyChanged = oldKey === null && newKey !== null || oldKey !== null && newKey === null || oldKey !== null && newKey !== null && !indexKeysEqual(oldKey, newKey);
4376
+ if (!keyChanged) {
4377
+ continue;
4378
+ }
4379
+ if (oldKey !== null) {
4380
+ updates.push({
4381
+ index_id: indexId,
4382
+ key: oldKey,
4383
+ value: { type: "Deleted" }
4384
+ });
4385
+ }
4386
+ if (newKey !== null) {
4387
+ updates.push({
4388
+ index_id: indexId,
4389
+ key: newKey,
4390
+ value: {
4391
+ type: "NonClustered",
4392
+ doc_id: docId
4393
+ }
4394
+ });
4395
+ }
4396
+ }
4397
+ return updates;
4398
+ }
4399
+ function getStandardIndexes() {
4400
+ return [
4401
+ {
4402
+ name: "by_creation_time",
4403
+ fields: ["_creationTime", "_id"]
4404
+ },
4405
+ {
4406
+ name: "by_id",
4407
+ fields: ["_id"]
4408
+ }
4409
+ ];
4410
+ }
4411
+
4412
+ // ../core/dist/kernel/schema-service.js
4413
+ init_validator2();
4414
+ init_module_loader();
4415
+
4416
+ class SchemaService {
4417
+ cachedSchemaDefinition = undefined;
4418
+ tableCache = new Map;
4419
+ schemaValidator;
4420
+ componentPath;
4421
+ constructor(componentPath) {
4422
+ this.componentPath = componentPath;
4423
+ this.schemaValidator = new SchemaValidator(componentPath);
4424
+ }
4425
+ async validate(tableName, document) {
4426
+ try {
4427
+ await this.schemaValidator.validateDocument(tableName, document);
4428
+ } catch (error) {
4429
+ if (error instanceof ValidatorError) {
4430
+ throw new Error(error.message);
4431
+ }
4432
+ throw error;
4433
+ }
4434
+ }
4435
+ async getTableSchema(tableName) {
4436
+ if (this.tableCache.has(tableName)) {
4437
+ return this.tableCache.get(tableName) ?? null;
4438
+ }
4439
+ const schemaDefinition = await this.getSchemaDefinition();
4440
+ const tableSchema = schemaDefinition?.tables?.[tableName] ?? null;
4441
+ this.tableCache.set(tableName, tableSchema);
4442
+ return tableSchema;
4443
+ }
4444
+ async getIndexFieldsForTable(tableName, indexDescriptor) {
4445
+ if (indexDescriptor === "by_creation_time") {
4446
+ return ["_creationTime", "_id"];
4447
+ }
4448
+ if (indexDescriptor === "by_id") {
4449
+ return ["_id"];
4450
+ }
4451
+ const tableSchema = await this.getTableSchema(tableName);
4452
+ const dbIndexes = tableSchema?.indexes;
4453
+ const matchingIndex = dbIndexes?.find((idx) => idx.indexDescriptor === indexDescriptor);
4454
+ if (!matchingIndex) {
4455
+ return null;
4456
+ }
4457
+ return [...matchingIndex.fields, "_creationTime", "_id"];
4458
+ }
4459
+ async getAllIndexesForTable(tableName) {
4460
+ const indexes = [...getStandardIndexes()];
4461
+ const tableSchema = await this.getTableSchema(tableName);
4462
+ const schemaIndexes = tableSchema?.indexes;
4463
+ if (schemaIndexes) {
4464
+ for (const idx of schemaIndexes) {
4465
+ indexes.push({
4466
+ name: idx.indexDescriptor,
4467
+ fields: [...idx.fields, "_creationTime", "_id"]
4468
+ });
4469
+ }
4470
+ }
4471
+ return indexes;
4472
+ }
4473
+ async getSearchIndexConfig(tableName, indexDescriptor) {
4474
+ const tableSchema = await this.getTableSchema(tableName);
4475
+ const searchIndexes = tableSchema?.searchIndexes;
4476
+ return searchIndexes?.find((idx) => idx.indexDescriptor === indexDescriptor) ?? null;
4477
+ }
4478
+ async getVectorIndexConfig(tableName, indexDescriptor) {
4479
+ const tableSchema = await this.getTableSchema(tableName);
4480
+ const vectorIndexes = tableSchema?.vectorIndexes;
4481
+ return vectorIndexes?.find((idx) => idx.indexDescriptor === indexDescriptor) ?? null;
4482
+ }
4483
+ async getAllVectorIndexes() {
4484
+ const schemaDefinition = await this.getSchemaDefinition();
4485
+ if (!schemaDefinition?.tables) {
4486
+ return [];
4487
+ }
4488
+ const allVectorIndexes = [];
4489
+ for (const [tableName, tableSchema] of Object.entries(schemaDefinition.tables)) {
4490
+ const vectorIndexes = tableSchema?.vectorIndexes;
4491
+ if (vectorIndexes) {
4492
+ for (const vectorIndex of vectorIndexes) {
4493
+ allVectorIndexes.push({
4494
+ tableName,
4495
+ indexDescriptor: vectorIndex.indexDescriptor,
4496
+ vectorField: vectorIndex.vectorField,
4497
+ filterFields: vectorIndex.filterFields ?? []
4498
+ });
4499
+ }
4500
+ }
4501
+ }
4502
+ return allVectorIndexes;
4393
4503
  }
4394
- observeTimestamp(ts) {
4395
- if (ts > this.logicalClock) {
4396
- this.logicalClock = ts;
4504
+ async getAllSearchIndexes() {
4505
+ const schemaDefinition = await this.getSchemaDefinition();
4506
+ if (!schemaDefinition?.tables) {
4507
+ return [];
4397
4508
  }
4509
+ const allSearchIndexes = [];
4510
+ for (const [tableName, tableSchema] of Object.entries(schemaDefinition.tables)) {
4511
+ const searchIndexes = tableSchema?.searchIndexes;
4512
+ if (searchIndexes) {
4513
+ for (const searchIndex of searchIndexes) {
4514
+ allSearchIndexes.push({
4515
+ tableName,
4516
+ indexDescriptor: searchIndex.indexDescriptor,
4517
+ searchField: searchIndex.searchField,
4518
+ filterFields: searchIndex.filterFields ?? []
4519
+ });
4520
+ }
4521
+ }
4522
+ }
4523
+ return allSearchIndexes;
4398
4524
  }
4399
- reset(ts = 0n) {
4400
- this.logicalClock = ts;
4401
- }
4402
- }
4403
- var TABLE_PREFIX = "table";
4404
- var INDEX_PREFIX = "index";
4405
- function encodeComponent(component) {
4406
- return encodeURIComponent(component);
4407
- }
4408
- function tableKeyspace(table) {
4409
- return { kind: "table", table };
4410
- }
4411
- function indexKeyspace(table, index) {
4412
- return { kind: "index", table, index };
4413
- }
4414
- function keyspaceId(namespace) {
4415
- if (namespace.kind === "table") {
4416
- return `${TABLE_PREFIX}:${encodeComponent(namespace.table)}`;
4525
+ async getTableNames() {
4526
+ const schemaDefinition = await this.getSchemaDefinition();
4527
+ if (!schemaDefinition?.tables) {
4528
+ return [];
4529
+ }
4530
+ return Object.keys(schemaDefinition.tables);
4417
4531
  }
4418
- return `${INDEX_PREFIX}:${encodeComponent(namespace.table)}:${encodeComponent(namespace.index)}`;
4419
- }
4420
- function tableKeyspaceId(table) {
4421
- return keyspaceId(tableKeyspace(table));
4422
- }
4423
- function indexKeyspaceId(table, index) {
4424
- return keyspaceId(indexKeyspace(table, index));
4425
- }
4426
- function decodeIndexId(indexId) {
4427
- const decoded = (() => {
4532
+ async getSchemaDefinition() {
4533
+ if (this.cachedSchemaDefinition !== undefined) {
4534
+ return this.cachedSchemaDefinition;
4535
+ }
4428
4536
  try {
4429
- return hexToString(indexId);
4430
- } catch {
4431
- return indexId;
4537
+ const schemaModule = await loadConvexModule("schema", { hint: "schema", componentPath: this.componentPath });
4538
+ this.cachedSchemaDefinition = schemaModule.default ?? null;
4539
+ } catch (error) {
4540
+ if (!isMissingSchemaModuleError(error)) {
4541
+ console.warn("Failed to load Convex schema definition:", error);
4542
+ }
4543
+ this.cachedSchemaDefinition = null;
4432
4544
  }
4433
- })();
4434
- const separatorIndex = decoded.indexOf(":");
4435
- if (separatorIndex === -1) {
4436
- throw new Error(`Invalid index id: ${indexId}`);
4545
+ return this.cachedSchemaDefinition;
4437
4546
  }
4438
- return {
4439
- table: decoded.slice(0, separatorIndex),
4440
- index: decoded.slice(separatorIndex + 1)
4441
- };
4442
4547
  }
4443
- init_schema_service();
4444
- init_index_key_codec();
4548
+ // ../core/dist/queryengine/filters.js
4445
4549
  function isSimpleObject3(value) {
4446
4550
  const isObject = typeof value === "object" && value !== null;
4447
4551
  if (!isObject)
@@ -4462,9 +4566,13 @@ function evaluateFieldPath(fieldPath, document) {
4462
4566
  }
4463
4567
  return current;
4464
4568
  }
4569
+ // ../core/dist/id-codec/index.js
4465
4570
  init_base32();
4466
4571
  init_document_id();
4572
+
4573
+ // ../core/dist/id-codec/id-conversion.js
4467
4574
  init_document_id();
4575
+ // ../core/dist/queryengine/developer-id.js
4468
4576
  function parseDeveloperId(developerId) {
4469
4577
  if (isValidDocumentId(developerId)) {
4470
4578
  try {
@@ -4498,10 +4606,12 @@ function parseStorageId(storageId) {
4498
4606
  function isTablePlaceholder(table) {
4499
4607
  return table.startsWith("#");
4500
4608
  }
4609
+ // ../core/dist/query/planner.js
4501
4610
  init_interface();
4611
+ // ../core/dist/query/actions.js
4502
4612
  init_interface();
4503
- init_index_key_codec();
4504
4613
 
4614
+ // ../core/dist/queryengine/indexing/read-write-set.js
4505
4615
  class RangeSet {
4506
4616
  ranges = new Map;
4507
4617
  addDocument(docId) {
@@ -4611,6 +4721,7 @@ function deserializeKeyRange(serialized) {
4611
4721
  };
4612
4722
  }
4613
4723
 
4724
+ // ../core/dist/kernel/access-log.js
4614
4725
  class AccessLog {
4615
4726
  ranges = new RangeSet;
4616
4727
  addDocument(docId) {
@@ -4634,6 +4745,7 @@ class AccessLog {
4634
4745
  return this.ranges.getRanges().map(serializeKeyRange);
4635
4746
  }
4636
4747
  }
4748
+ // ../core/dist/tables/memory-table-registry.js
4637
4749
  init_interface();
4638
4750
 
4639
4751
  class MemoryTableRegistry {
@@ -4730,6 +4842,7 @@ function getGlobalTableRegistry() {
4730
4842
  return globalRegistry;
4731
4843
  }
4732
4844
 
4845
+ // ../core/dist/kernel/kernel-context.js
4733
4846
  class KernelContext {
4734
4847
  authContext;
4735
4848
  componentPath;
@@ -4839,56 +4952,14 @@ class KernelContext {
4839
4952
  return this.writeLog.serialize();
4840
4953
  }
4841
4954
  }
4842
- var resolveAsyncLocalStorage = () => {
4843
- if (typeof globalThis !== "undefined" && globalThis.AsyncLocalStorage) {
4844
- return globalThis.AsyncLocalStorage;
4845
- }
4846
- try {
4847
- const req = Function("return typeof require !== 'undefined' ? require : undefined")();
4848
- if (!req) {
4849
- return;
4850
- }
4851
- const mod = req("node:async_hooks");
4852
- return mod.AsyncLocalStorage;
4853
- } catch {
4854
- return;
4855
- }
4856
- };
4857
- var AsyncLocalStorageCtor = resolveAsyncLocalStorage();
4858
4955
 
4859
- class ContextStorage {
4860
- als;
4861
- stack = [];
4862
- constructor() {
4863
- if (AsyncLocalStorageCtor) {
4864
- this.als = new AsyncLocalStorageCtor;
4865
- }
4866
- }
4867
- getStore() {
4868
- if (this.als) {
4869
- return this.als.getStore() ?? undefined;
4870
- }
4871
- return this.stack.length > 0 ? this.stack[this.stack.length - 1] : undefined;
4872
- }
4873
- run(value, callback) {
4874
- if (this.als) {
4875
- return this.als.run(value, callback);
4876
- }
4877
- this.stack.push(value);
4878
- const result = callback();
4879
- if (result && typeof result.then === "function") {
4880
- return result.finally(() => {
4881
- this.stack.pop();
4882
- });
4883
- }
4884
- this.stack.pop();
4885
- return result;
4886
- }
4887
- }
4956
+ // ../core/dist/kernel/contexts.js
4957
+ init_context_storage();
4888
4958
  var snapshotContext = new ContextStorage;
4889
4959
  var transactionContext = new ContextStorage;
4890
4960
  var idGeneratorContext = new ContextStorage;
4891
4961
 
4962
+ // ../core/dist/kernel/blob-store-gateway.js
4892
4963
  class BlobStoreGateway {
4893
4964
  context;
4894
4965
  docStore;
@@ -4992,7 +5063,10 @@ class BlobStoreGateway {
4992
5063
  return this.storage;
4993
5064
  }
4994
5065
  }
5066
+
5067
+ // ../core/dist/kernel/scheduler-gateway.js
4995
5068
  init_values();
5069
+ // ../core/dist/kernel/syscalls/utils.js
4996
5070
  init_values();
4997
5071
  async function resolveTableName(docId, tableRegistry) {
4998
5072
  if (docId.tableNumber !== undefined) {
@@ -5130,6 +5204,7 @@ function evaluatePatchValue(value) {
5130
5204
  return jsonToConvex(value);
5131
5205
  }
5132
5206
 
5207
+ // ../core/dist/kernel/scheduler-gateway.js
5133
5208
  class SchedulerGateway {
5134
5209
  context;
5135
5210
  docStore;
@@ -5198,9 +5273,12 @@ class SchedulerGateway {
5198
5273
  this.context.recordLocalWrite(id, tableName, resolvedDocument.value, docId);
5199
5274
  }
5200
5275
  }
5276
+
5277
+ // ../core/dist/udf/module-loader/call-context.js
5278
+ init_context_storage();
5201
5279
  var CALL_CONTEXT_SYMBOL = Symbol.for("@concavejs/core/call-context");
5202
5280
  var globalCallContext = globalThis;
5203
- var callContext = globalCallContext[CALL_CONTEXT_SYMBOL] ?? new AsyncLocalStorage2;
5281
+ var callContext = globalCallContext[CALL_CONTEXT_SYMBOL] ?? new ContextStorage;
5204
5282
  if (!globalCallContext[CALL_CONTEXT_SYMBOL]) {
5205
5283
  globalCallContext[CALL_CONTEXT_SYMBOL] = callContext;
5206
5284
  }
@@ -5208,6 +5286,7 @@ async function runAsServerCall(fn, functionPath) {
5208
5286
  return callContext.run({ caller: "server", functionPath }, fn);
5209
5287
  }
5210
5288
 
5289
+ // ../core/dist/kernel/udf-invocation-manager.js
5211
5290
  class UdfInvocationManager {
5212
5291
  context;
5213
5292
  udfExecutor;
@@ -5234,6 +5313,7 @@ class UdfInvocationManager {
5234
5313
  }
5235
5314
  }
5236
5315
 
5316
+ // ../core/dist/kernel/syscalls/action-syscalls.js
5237
5317
  class ActionSyscalls {
5238
5318
  context;
5239
5319
  queryRuntime;
@@ -5283,8 +5363,9 @@ class ActionSyscalls {
5283
5363
  return this.queryRuntime.runSearchAction(args.query);
5284
5364
  }
5285
5365
  }
5366
+
5367
+ // ../core/dist/kernel/syscalls/database-syscalls.js
5286
5368
  init_values();
5287
- init_index_manager();
5288
5369
  init_interface();
5289
5370
 
5290
5371
  class DatabaseSyscalls {
@@ -5508,6 +5589,8 @@ class DatabaseSyscalls {
5508
5589
  return {};
5509
5590
  }
5510
5591
  }
5592
+
5593
+ // ../core/dist/auth/jwt.js
5511
5594
  function claims2identity(claims) {
5512
5595
  const {
5513
5596
  sub,
@@ -5597,6 +5680,7 @@ function decodeJwtUnsafe(token) {
5597
5680
  return decodeJwtClaimsToken(token);
5598
5681
  }
5599
5682
 
5683
+ // ../core/dist/kernel/syscalls/identity-syscalls.js
5600
5684
  class IdentitySyscalls {
5601
5685
  context;
5602
5686
  constructor(options) {
@@ -5629,6 +5713,7 @@ class IdentitySyscalls {
5629
5713
  }
5630
5714
  }
5631
5715
 
5716
+ // ../core/dist/kernel/syscalls/js-router.js
5632
5717
  class JsSyscallRouter {
5633
5718
  handlers = new Map;
5634
5719
  register(op, handler) {
@@ -5649,6 +5734,7 @@ class JsSyscallRouter {
5649
5734
  }
5650
5735
  }
5651
5736
 
5737
+ // ../core/dist/kernel/syscalls/query-syscalls.js
5652
5738
  class QuerySyscalls {
5653
5739
  queryRuntime;
5654
5740
  nextQueryId = 1;
@@ -5712,6 +5798,7 @@ class QuerySyscalls {
5712
5798
  }
5713
5799
  }
5714
5800
 
5801
+ // ../core/dist/kernel/syscalls/schedule-syscalls.js
5715
5802
  class ScheduleSyscalls {
5716
5803
  context;
5717
5804
  scheduler;
@@ -5746,6 +5833,7 @@ class ScheduleSyscalls {
5746
5833
  }
5747
5834
  }
5748
5835
 
5836
+ // ../core/dist/kernel/syscalls/blobstore-syscalls.js
5749
5837
  class BlobStoreSyscalls {
5750
5838
  blobStore;
5751
5839
  constructor(options) {
@@ -5809,6 +5897,8 @@ class BlobStoreSyscalls {
5809
5897
  return "http://localhost:8799";
5810
5898
  }
5811
5899
  }
5900
+
5901
+ // ../core/dist/kernel/syscalls/router.js
5812
5902
  init_values();
5813
5903
 
5814
5904
  class SyscallRouter {
@@ -5850,6 +5940,7 @@ class SyscallRouter {
5850
5940
  }
5851
5941
  }
5852
5942
 
5943
+ // ../core/dist/kernel/syscalls/kernel-syscalls.js
5853
5944
  class KernelSyscalls {
5854
5945
  router = new SyscallRouter;
5855
5946
  jsRouter = new JsSyscallRouter;
@@ -5900,9 +5991,8 @@ class KernelSyscalls {
5900
5991
  return this.jsRouter.dispatch(op, args);
5901
5992
  }
5902
5993
  }
5903
- init_schema_service();
5994
+ // ../core/dist/queryengine/convex-ops.js
5904
5995
  var debug = () => {};
5905
-
5906
5996
  class CfConvex {
5907
5997
  syscall(op, jsonArgs) {
5908
5998
  debug("CfConvex::syscall", op, jsonArgs);
@@ -5922,8 +6012,22 @@ class CfConvex {
5922
6012
  }
5923
6013
  }
5924
6014
  var Convex2 = new CfConvex;
5925
- init_index_manager();
5926
- init_index_key_codec();
6015
+ // ../docstore-sqlite-base/dist/base.js
6016
+ function toSqlBlob(value) {
6017
+ return value instanceof Uint8Array ? value : new Uint8Array(value);
6018
+ }
6019
+ function toArrayBuffer(value) {
6020
+ if (value instanceof ArrayBuffer) {
6021
+ return value;
6022
+ }
6023
+ if (ArrayBuffer.isView(value)) {
6024
+ return new Uint8Array(value.buffer, value.byteOffset, value.byteLength).slice().buffer;
6025
+ }
6026
+ if (Array.isArray(value)) {
6027
+ return new Uint8Array(value).buffer;
6028
+ }
6029
+ throw new Error("Expected SQL blob value to be an ArrayBuffer or typed array");
6030
+ }
5927
6031
 
5928
6032
  class BaseSqliteDocStore {
5929
6033
  adapter;
@@ -6025,9 +6129,9 @@ class BaseSqliteDocStore {
6025
6129
  const insertIndexStmt = this.adapter.prepare(indexQuery);
6026
6130
  for (const { ts, update } of indexes) {
6027
6131
  if (update.value.type === "Deleted") {
6028
- await insertIndexStmt.run(this.adapter.hexToBuffer(update.index_id), Number(ts), Buffer.from(update.key), 1, Buffer.alloc(0), Buffer.alloc(0));
6132
+ await insertIndexStmt.run(this.adapter.hexToBuffer(update.index_id), Number(ts), toSqlBlob(update.key), 1, new Uint8Array(0), new Uint8Array(0));
6029
6133
  } else {
6030
- await insertIndexStmt.run(this.adapter.hexToBuffer(update.index_id), Number(ts), Buffer.from(update.key), 0, this.adapter.hexToBuffer(update.value.doc_id.table), this.adapter.hexToBuffer(update.value.doc_id.internalId));
6134
+ await insertIndexStmt.run(this.adapter.hexToBuffer(update.index_id), Number(ts), toSqlBlob(update.key), 0, this.adapter.hexToBuffer(update.value.doc_id.table), this.adapter.hexToBuffer(update.value.doc_id.internalId));
6031
6135
  }
6032
6136
  }
6033
6137
  }
@@ -6048,11 +6152,11 @@ class BaseSqliteDocStore {
6048
6152
  const params = [this.adapter.hexToBuffer(indexId), Number(readTimestamp)];
6049
6153
  if (start && start.byteLength > 0) {
6050
6154
  query += ` AND key >= ?`;
6051
- params.push(Buffer.from(start));
6155
+ params.push(toSqlBlob(start));
6052
6156
  }
6053
6157
  if (end) {
6054
6158
  query += ` AND key < ?`;
6055
- params.push(Buffer.from(end));
6159
+ params.push(toSqlBlob(end));
6056
6160
  }
6057
6161
  query += `
6058
6162
  ),
@@ -6086,7 +6190,7 @@ class BaseSqliteDocStore {
6086
6190
  const stmt = this.adapter.prepare(query);
6087
6191
  const rows = await stmt.all(...params);
6088
6192
  for (const row of rows) {
6089
- const key = row.key;
6193
+ const key = toArrayBuffer(row.key);
6090
6194
  const tableId = this.adapter.bufferToHex(row.table_id);
6091
6195
  const docId = this.adapter.bufferToHex(row.document_id);
6092
6196
  const doc = {
@@ -6426,6 +6530,7 @@ class BaseSqliteDocStore {
6426
6530
  return scored.slice(0, limit);
6427
6531
  }
6428
6532
  }
6533
+ // ../docstore-sqlite-base/dist/transaction-runner.js
6429
6534
  function createSerializedTransactionRunner(hooks) {
6430
6535
  let queue = Promise.resolve();
6431
6536
  return async function runInTransaction(fn) {
@@ -6450,145 +6555,6 @@ function createSerializedTransactionRunner(hooks) {
6450
6555
  return run;
6451
6556
  };
6452
6557
  }
6453
- // ../core/dist/utils/long.js
6454
- class Long2 {
6455
- low;
6456
- high;
6457
- __isUnsignedLong__;
6458
- static isLong(obj) {
6459
- return obj?.__isUnsignedLong__ === true;
6460
- }
6461
- constructor(low, high) {
6462
- this.low = low | 0;
6463
- this.high = high | 0;
6464
- this.__isUnsignedLong__ = true;
6465
- }
6466
- static fromBytesLE(bytes) {
6467
- return new Long2(bytes[0] | bytes[1] << 8 | bytes[2] << 16 | bytes[3] << 24, bytes[4] | bytes[5] << 8 | bytes[6] << 16 | bytes[7] << 24);
6468
- }
6469
- toBytesLE() {
6470
- const hi = this.high;
6471
- const lo = this.low;
6472
- return [
6473
- lo & 255,
6474
- lo >>> 8 & 255,
6475
- lo >>> 16 & 255,
6476
- lo >>> 24,
6477
- hi & 255,
6478
- hi >>> 8 & 255,
6479
- hi >>> 16 & 255,
6480
- hi >>> 24
6481
- ];
6482
- }
6483
- static fromNumber(value) {
6484
- if (Number.isNaN(value))
6485
- return UZERO2;
6486
- if (value < 0)
6487
- return UZERO2;
6488
- if (value >= TWO_PWR_64_DBL2)
6489
- return MAX_UNSIGNED_VALUE2;
6490
- return new Long2(value % TWO_PWR_32_DBL2 | 0, value / TWO_PWR_32_DBL2 | 0);
6491
- }
6492
- toString() {
6493
- return (BigInt(this.high) * BigInt(TWO_PWR_32_DBL2) + BigInt(this.low)).toString();
6494
- }
6495
- equals(other) {
6496
- if (!Long2.isLong(other))
6497
- other = Long2.fromValue(other);
6498
- if (this.high >>> 31 === 1 && other.high >>> 31 === 1)
6499
- return false;
6500
- return this.high === other.high && this.low === other.low;
6501
- }
6502
- notEquals(other) {
6503
- return !this.equals(other);
6504
- }
6505
- comp(other) {
6506
- if (!Long2.isLong(other))
6507
- other = Long2.fromValue(other);
6508
- if (this.equals(other))
6509
- return 0;
6510
- return other.high >>> 0 > this.high >>> 0 || other.high === this.high && other.low >>> 0 > this.low >>> 0 ? -1 : 1;
6511
- }
6512
- lessThanOrEqual(other) {
6513
- return this.comp(other) <= 0;
6514
- }
6515
- static fromValue(val) {
6516
- if (typeof val === "number")
6517
- return Long2.fromNumber(val);
6518
- if (typeof val === "bigint") {
6519
- if (val < 0n)
6520
- return UZERO2;
6521
- const max = (1n << 64n) - 1n;
6522
- if (val > max)
6523
- return MAX_UNSIGNED_VALUE2;
6524
- const low = Number(val & 0xffffffffn);
6525
- const high = Number(val >> 32n & 0xffffffffn);
6526
- return new Long2(low | 0, high | 0);
6527
- }
6528
- if (typeof val === "string") {
6529
- try {
6530
- return Long2.fromValue(BigInt(val));
6531
- } catch {}
6532
- }
6533
- return new Long2(val.low, val.high);
6534
- }
6535
- }
6536
- var UZERO2 = new Long2(0, 0);
6537
- var TWO_PWR_16_DBL2 = 1 << 16;
6538
- var TWO_PWR_32_DBL2 = TWO_PWR_16_DBL2 * TWO_PWR_16_DBL2;
6539
- var TWO_PWR_64_DBL2 = TWO_PWR_32_DBL2 * TWO_PWR_32_DBL2;
6540
- var MAX_UNSIGNED_VALUE2 = new Long2(4294967295 | 0, 4294967295 | 0);
6541
- // ../core/dist/utils/timestamp.js
6542
- class TimestampOracle2 {
6543
- logicalClock;
6544
- allocationQueue = Promise.resolve();
6545
- constructor(initialTimestamp = 0n) {
6546
- this.logicalClock = initialTimestamp;
6547
- }
6548
- getCurrentTimestamp() {
6549
- return this.logicalClock;
6550
- }
6551
- allocateTimestamp() {
6552
- const wallClock = BigInt(Date.now());
6553
- this.logicalClock = this.logicalClock >= wallClock ? this.logicalClock + 1n : wallClock;
6554
- return this.logicalClock;
6555
- }
6556
- async allocateTimestampAsync() {
6557
- const result = this.allocationQueue.then(() => {
6558
- return this.allocateTimestamp();
6559
- });
6560
- this.allocationQueue = result.then(() => {}, () => {});
6561
- return result;
6562
- }
6563
- beginSnapshot() {
6564
- if (this.logicalClock === 0n) {
6565
- return BigInt(Date.now());
6566
- }
6567
- return this.logicalClock;
6568
- }
6569
- observeTimestamp(ts) {
6570
- if (ts > this.logicalClock) {
6571
- this.logicalClock = ts;
6572
- }
6573
- }
6574
- reset(ts = 0n) {
6575
- this.logicalClock = ts;
6576
- }
6577
- }
6578
- // ../core/dist/utils/utils.js
6579
- function hexToArrayBuffer3(hex) {
6580
- if (hex === "") {
6581
- return new Uint8Array(0).buffer;
6582
- }
6583
- const matches = hex.match(/.{1,2}/g);
6584
- if (!matches) {
6585
- throw new Error(`Invalid hex string: ${hex}`);
6586
- }
6587
- return new Uint8Array(matches.map((byte) => parseInt(byte, 16))).buffer;
6588
- }
6589
- function arrayBufferToHex3(buffer) {
6590
- return Array.from(new Uint8Array(buffer)).map((b) => b.toString(16).padStart(2, "0")).join("");
6591
- }
6592
6558
  // src/better-sqlite3-adapter.ts
6593
6559
  class BetterSqlite3PreparedStatement {
6594
6560
  stmt;
@@ -6633,13 +6599,13 @@ class BetterSqlite3Adapter {
6633
6599
  return this.runSerializedTransaction(fn);
6634
6600
  }
6635
6601
  hexToBuffer(hex) {
6636
- return Buffer.from(hexToArrayBuffer3(hex));
6602
+ return Buffer.from(hexToArrayBuffer(hex));
6637
6603
  }
6638
6604
  bufferToHex(buffer) {
6639
6605
  if (buffer instanceof Buffer) {
6640
- return arrayBufferToHex3(buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength));
6606
+ return arrayBufferToHex(buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength));
6641
6607
  }
6642
- return arrayBufferToHex3(buffer);
6608
+ return arrayBufferToHex(buffer);
6643
6609
  }
6644
6610
  }
6645
6611