@concavejs/docstore-cf-d1 0.0.1-alpha.5 → 0.0.1-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ import type { SqliteAdapter, PreparedStatement, SqlParam, TransactionFn } from "
8
8
  */
9
9
  export declare class D1SqliteAdapter implements SqliteAdapter {
10
10
  private db;
11
- private batchStatements;
11
+ private statementCollector;
12
12
  constructor(db: D1Database);
13
13
  exec(sql: string): Promise<void>;
14
14
  prepare(sql: string): PreparedStatement;
package/dist/index.js CHANGED
@@ -50,7 +50,7 @@ function deserializeDeveloperId(developerId) {
50
50
  }
51
51
  var DOC_ID_SEPARATOR = ":", LEGACY_DOC_ID_SEPARATOR = ";";
52
52
 
53
- // ../core/node_modules/convex/dist/esm/values/base64.js
53
+ // ../../node_modules/convex/dist/esm/values/base64.js
54
54
  function getLens(b64) {
55
55
  var len2 = b64.length;
56
56
  if (len2 % 4 > 0) {
@@ -134,7 +134,7 @@ var init_base64 = __esm(() => {
134
134
  revLookup[95] = 63;
135
135
  });
136
136
 
137
- // ../core/node_modules/convex/dist/esm/common/index.js
137
+ // ../../node_modules/convex/dist/esm/common/index.js
138
138
  function parseArgs(args) {
139
139
  if (args === undefined) {
140
140
  return {};
@@ -151,7 +151,7 @@ function isSimpleObject(value) {
151
151
  return isObject && isSimple;
152
152
  }
153
153
 
154
- // ../core/node_modules/convex/dist/esm/values/value.js
154
+ // ../../node_modules/convex/dist/esm/values/value.js
155
155
  function isSpecial(n) {
156
156
  return Number.isNaN(n) || !Number.isFinite(n) || Object.is(n, -0);
157
157
  }
@@ -398,7 +398,7 @@ var init_value = __esm(() => {
398
398
  base64ToBigInt = DataView.prototype.getBigInt64 ? modernBase64ToBigInt : slowBase64ToBigInt;
399
399
  });
400
400
 
401
- // ../core/node_modules/convex/dist/esm/values/validators.js
401
+ // ../../node_modules/convex/dist/esm/values/validators.js
402
402
  function throwUndefinedValidatorError(context, fieldName) {
403
403
  const fieldInfo = fieldName !== undefined ? ` for field "${fieldName}"` : "";
404
404
  throw new Error(`A validator is undefined${fieldInfo} in ${context}. This is often caused by circular imports. See ${UNDEFINED_VALIDATOR_ERROR_URL} for details.`);
@@ -733,7 +733,7 @@ var init_validators = __esm(() => {
733
733
  };
734
734
  });
735
735
 
736
- // ../core/node_modules/convex/dist/esm/values/validator.js
736
+ // ../../node_modules/convex/dist/esm/values/validator.js
737
737
  function isValidator(v2) {
738
738
  return !!v2.isConvexValidator;
739
739
  }
@@ -812,7 +812,7 @@ var init_validator = __esm(() => {
812
812
  };
813
813
  });
814
814
 
815
- // ../core/node_modules/convex/dist/esm/values/errors.js
815
+ // ../../node_modules/convex/dist/esm/values/errors.js
816
816
  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;
817
817
  var init_errors = __esm(() => {
818
818
  init_value();
@@ -829,7 +829,7 @@ var init_errors = __esm(() => {
829
829
  };
830
830
  });
831
831
 
832
- // ../core/node_modules/convex/dist/esm/values/index.js
832
+ // ../../node_modules/convex/dist/esm/values/index.js
833
833
  var init_values = __esm(() => {
834
834
  init_value();
835
835
  init_validator();
@@ -1097,10 +1097,10 @@ var init_interface = __esm(() => {
1097
1097
  };
1098
1098
  });
1099
1099
 
1100
- // ../core/node_modules/convex/dist/esm/index.js
1100
+ // ../../node_modules/convex/dist/esm/index.js
1101
1101
  var version = "1.31.7";
1102
1102
 
1103
- // ../core/node_modules/convex/dist/esm/server/impl/syscall.js
1103
+ // ../../node_modules/convex/dist/esm/server/impl/syscall.js
1104
1104
  function performSyscall(op, arg) {
1105
1105
  if (typeof Convex === "undefined" || Convex.syscall === undefined) {
1106
1106
  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?");
@@ -1130,13 +1130,13 @@ var init_syscall = __esm(() => {
1130
1130
  init_value();
1131
1131
  });
1132
1132
 
1133
- // ../core/node_modules/convex/dist/esm/server/functionName.js
1133
+ // ../../node_modules/convex/dist/esm/server/functionName.js
1134
1134
  var functionName;
1135
1135
  var init_functionName = __esm(() => {
1136
1136
  functionName = Symbol.for("functionName");
1137
1137
  });
1138
1138
 
1139
- // ../core/node_modules/convex/dist/esm/server/components/paths.js
1139
+ // ../../node_modules/convex/dist/esm/server/components/paths.js
1140
1140
  function extractReferencePath(reference) {
1141
1141
  return reference[toReferencePath] ?? null;
1142
1142
  }
@@ -1168,7 +1168,7 @@ var init_paths = __esm(() => {
1168
1168
  toReferencePath = Symbol.for("toReferencePath");
1169
1169
  });
1170
1170
 
1171
- // ../core/node_modules/convex/dist/esm/server/impl/validate.js
1171
+ // ../../node_modules/convex/dist/esm/server/impl/validate.js
1172
1172
  function validateArg(arg, idx, method, argName) {
1173
1173
  if (arg === undefined) {
1174
1174
  throw new TypeError(`Must provide arg ${idx} \`${argName}\` to \`${method}\``);
@@ -1180,7 +1180,7 @@ function validateArgIsNonNegativeInteger(arg, idx, method, argName) {
1180
1180
  }
1181
1181
  }
1182
1182
 
1183
- // ../core/node_modules/convex/dist/esm/server/impl/authentication_impl.js
1183
+ // ../../node_modules/convex/dist/esm/server/impl/authentication_impl.js
1184
1184
  function setupAuth(requestId) {
1185
1185
  return {
1186
1186
  getUserIdentity: async () => {
@@ -1194,7 +1194,7 @@ var init_authentication_impl = __esm(() => {
1194
1194
  init_syscall();
1195
1195
  });
1196
1196
 
1197
- // ../core/node_modules/convex/dist/esm/server/filter_builder.js
1197
+ // ../../node_modules/convex/dist/esm/server/filter_builder.js
1198
1198
  class Expression {
1199
1199
  constructor() {
1200
1200
  __publicField3(this, "_isExpression");
@@ -1206,7 +1206,7 @@ var init_filter_builder = __esm(() => {
1206
1206
  __defProp4 = Object.defineProperty;
1207
1207
  });
1208
1208
 
1209
- // ../core/node_modules/convex/dist/esm/server/impl/filter_builder_impl.js
1209
+ // ../../node_modules/convex/dist/esm/server/impl/filter_builder_impl.js
1210
1210
  function serializeExpression(expr) {
1211
1211
  if (expr instanceof ExpressionImpl) {
1212
1212
  return expr.serialize();
@@ -1303,7 +1303,7 @@ var init_filter_builder_impl = __esm(() => {
1303
1303
  };
1304
1304
  });
1305
1305
 
1306
- // ../core/node_modules/convex/dist/esm/server/index_range_builder.js
1306
+ // ../../node_modules/convex/dist/esm/server/index_range_builder.js
1307
1307
  class IndexRange {
1308
1308
  constructor() {
1309
1309
  __publicField5(this, "_isIndexRange");
@@ -1314,7 +1314,7 @@ var init_index_range_builder = __esm(() => {
1314
1314
  __defProp6 = Object.defineProperty;
1315
1315
  });
1316
1316
 
1317
- // ../core/node_modules/convex/dist/esm/server/impl/index_range_builder_impl.js
1317
+ // ../../node_modules/convex/dist/esm/server/impl/index_range_builder_impl.js
1318
1318
  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;
1319
1319
  var init_index_range_builder_impl = __esm(() => {
1320
1320
  init_value();
@@ -1384,7 +1384,7 @@ var init_index_range_builder_impl = __esm(() => {
1384
1384
  };
1385
1385
  });
1386
1386
 
1387
- // ../core/node_modules/convex/dist/esm/server/search_filter_builder.js
1387
+ // ../../node_modules/convex/dist/esm/server/search_filter_builder.js
1388
1388
  class SearchFilter {
1389
1389
  constructor() {
1390
1390
  __publicField7(this, "_isSearchFilter");
@@ -1395,7 +1395,7 @@ var init_search_filter_builder = __esm(() => {
1395
1395
  __defProp8 = Object.defineProperty;
1396
1396
  });
1397
1397
 
1398
- // ../core/node_modules/convex/dist/esm/server/impl/search_filter_builder_impl.js
1398
+ // ../../node_modules/convex/dist/esm/server/impl/search_filter_builder_impl.js
1399
1399
  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;
1400
1400
  var init_search_filter_builder_impl = __esm(() => {
1401
1401
  init_value();
@@ -1447,7 +1447,7 @@ var init_search_filter_builder_impl = __esm(() => {
1447
1447
  };
1448
1448
  });
1449
1449
 
1450
- // ../core/node_modules/convex/dist/esm/server/impl/query_impl.js
1450
+ // ../../node_modules/convex/dist/esm/server/impl/query_impl.js
1451
1451
  function throwClosedError(type) {
1452
1452
  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.");
1453
1453
  }
@@ -1684,7 +1684,7 @@ var init_query_impl = __esm(() => {
1684
1684
  };
1685
1685
  });
1686
1686
 
1687
- // ../core/node_modules/convex/dist/esm/server/impl/database_impl.js
1687
+ // ../../node_modules/convex/dist/esm/server/impl/database_impl.js
1688
1688
  async function get(table, id, isSystem) {
1689
1689
  validateArg(id, 1, "get", "id");
1690
1690
  if (typeof id !== "string") {
@@ -1834,7 +1834,7 @@ var init_database_impl = __esm(() => {
1834
1834
  };
1835
1835
  });
1836
1836
 
1837
- // ../core/node_modules/convex/dist/esm/server/impl/scheduler_impl.js
1837
+ // ../../node_modules/convex/dist/esm/server/impl/scheduler_impl.js
1838
1838
  function setupMutationScheduler() {
1839
1839
  return {
1840
1840
  runAfter: async (delayMs, functionReference, args) => {
@@ -1896,7 +1896,7 @@ var init_scheduler_impl = __esm(() => {
1896
1896
  init_paths();
1897
1897
  });
1898
1898
 
1899
- // ../core/node_modules/convex/dist/esm/server/impl/storage_impl.js
1899
+ // ../../node_modules/convex/dist/esm/server/impl/storage_impl.js
1900
1900
  function setupStorageReader(requestId) {
1901
1901
  return {
1902
1902
  getUrl: async (storageId) => {
@@ -1940,7 +1940,7 @@ var init_storage_impl = __esm(() => {
1940
1940
  init_syscall();
1941
1941
  });
1942
1942
 
1943
- // ../core/node_modules/convex/dist/esm/server/impl/registration_impl.js
1943
+ // ../../node_modules/convex/dist/esm/server/impl/registration_impl.js
1944
1944
  async function invokeMutation(func, argsStr) {
1945
1945
  const requestId = "";
1946
1946
  const args = jsonToConvex(JSON.parse(argsStr));
@@ -2077,7 +2077,7 @@ var init_registration_impl = __esm(() => {
2077
2077
  init_paths();
2078
2078
  });
2079
2079
 
2080
- // ../core/node_modules/convex/dist/esm/server/pagination.js
2080
+ // ../../node_modules/convex/dist/esm/server/pagination.js
2081
2081
  var paginationOptsValidator;
2082
2082
  var init_pagination = __esm(() => {
2083
2083
  init_validator();
@@ -2091,7 +2091,7 @@ var init_pagination = __esm(() => {
2091
2091
  });
2092
2092
  });
2093
2093
 
2094
- // ../core/node_modules/convex/dist/esm/server/index.js
2094
+ // ../../node_modules/convex/dist/esm/server/index.js
2095
2095
  var init_server = __esm(() => {
2096
2096
  init_registration_impl();
2097
2097
  init_pagination();
@@ -4434,6 +4434,19 @@ function parseDeveloperId(developerId) {
4434
4434
  }
4435
4435
  return { table: parts.table, internalId: parts.internalId };
4436
4436
  }
4437
+ function parseStorageId(storageId) {
4438
+ const parsed = parseDeveloperId(storageId);
4439
+ if (parsed) {
4440
+ return parsed;
4441
+ }
4442
+ if (storageId.length === INTERNAL_ID_LENGTH * 2 && /^[0-9a-fA-F]+$/.test(storageId)) {
4443
+ return {
4444
+ table: stringToHex("_storage"),
4445
+ internalId: storageId.toLowerCase()
4446
+ };
4447
+ }
4448
+ return null;
4449
+ }
4437
4450
  function isTablePlaceholder(table) {
4438
4451
  return table.startsWith("#");
4439
4452
  }
@@ -4887,19 +4900,19 @@ class BlobStoreGateway {
4887
4900
  if (!this.storage) {
4888
4901
  return null;
4889
4902
  }
4890
- const docId = parseDeveloperId(storageId);
4903
+ const docId = parseStorageId(storageId);
4891
4904
  if (!docId) {
4892
- console.error(`[BlobStoreGateway] Failed to parse storage ID: ${storageId}`);
4905
+ console.debug(`[BlobStoreGateway] Failed to parse storage ID: ${storageId}`);
4893
4906
  return null;
4894
4907
  }
4895
4908
  const docValue = await this.queryRuntime.getVisibleDocumentById(storageId, docId);
4896
4909
  if (!docValue) {
4897
- console.error(`[BlobStoreGateway] Document not found for storage ID: ${storageId} (table: ${docId.table}, internalId: ${docId.internalId})`);
4910
+ console.debug(`[BlobStoreGateway] Document not found for storage ID: ${storageId} (table: ${docId.table}, internalId: ${docId.internalId}, ts: ${this.context.snapshotTimestamp})`);
4898
4911
  return null;
4899
4912
  }
4900
4913
  const storedBlob = await this.storage.get(docId.internalId);
4901
4914
  if (!storedBlob) {
4902
- console.error(`[BlobStoreGateway] Blob not found in storage: ${docId.internalId}`);
4915
+ console.debug(`[BlobStoreGateway] Blob not found in storage: ${docId.internalId}`);
4903
4916
  return null;
4904
4917
  }
4905
4918
  return storedBlob instanceof Blob ? storedBlob : new Blob([storedBlob]);
@@ -4908,7 +4921,7 @@ class BlobStoreGateway {
4908
4921
  if (!this.storage) {
4909
4922
  return null;
4910
4923
  }
4911
- const docId = parseDeveloperId(storageId);
4924
+ const docId = parseStorageId(storageId);
4912
4925
  if (!docId) {
4913
4926
  return null;
4914
4927
  }
@@ -4921,7 +4934,7 @@ class BlobStoreGateway {
4921
4934
  }
4922
4935
  async delete(storageId) {
4923
4936
  const storage2 = this.requireStorage();
4924
- const docId = parseDeveloperId(storageId);
4937
+ const docId = parseStorageId(storageId);
4925
4938
  if (!docId) {
4926
4939
  return;
4927
4940
  }
@@ -4983,8 +4996,9 @@ function resolveFunctionTarget(callArgs, currentComponentPath) {
4983
4996
  return parseFunctionHandleTarget(callArgs.functionHandle);
4984
4997
  }
4985
4998
  if (callArgs && typeof callArgs.functionHandle === "object" && callArgs.functionHandle !== null) {
4986
- if (typeof callArgs.functionHandle.handle === "string") {
4987
- return parseFunctionHandleTarget(callArgs.functionHandle.handle);
4999
+ const handle = callArgs.functionHandle;
5000
+ if (typeof handle.handle === "string") {
5001
+ return parseFunctionHandleTarget(handle.handle);
4988
5002
  }
4989
5003
  }
4990
5004
  if (callArgs && typeof callArgs.reference === "string") {
@@ -5230,17 +5244,15 @@ class ActionSyscalls {
5230
5244
  const type = args.udfType ?? args.type ?? "mutation";
5231
5245
  return await this.invocationManager.execute(target.udfPath, udfArguments, type, target.componentPath);
5232
5246
  }
5233
- handleCreateFunctionHandle(args) {
5247
+ async handleCreateFunctionHandle(args) {
5234
5248
  const target = resolveFunctionTarget(args, this.context.componentPath);
5235
5249
  return formatFunctionHandle(target.componentPath ?? "", target.udfPath);
5236
5250
  }
5237
5251
  async handleVectorSearch(args) {
5238
- const { query: vectorQuery } = args;
5239
- return this.queryRuntime.runVectorSearchAction(vectorQuery);
5252
+ return this.queryRuntime.runVectorSearchAction(args.query);
5240
5253
  }
5241
5254
  async handleSearchAction(args) {
5242
- const { query: searchQuery } = args;
5243
- return this.queryRuntime.runSearchAction(searchQuery);
5255
+ return this.queryRuntime.runSearchAction(args.query);
5244
5256
  }
5245
5257
  }
5246
5258
 
@@ -5552,6 +5564,8 @@ function decodeJwtClaimsToken(token) {
5552
5564
  return null;
5553
5565
  }
5554
5566
  }
5567
+ var DEFAULT_JWKS_CACHE_TTL_MS = 5 * 60 * 1000;
5568
+ var MAX_JWKS_CACHE_TTL_MS = 24 * 60 * 60 * 1000;
5555
5569
  var JWKS_CACHE = new Map;
5556
5570
  function decodeJwtUnsafe(token) {
5557
5571
  if (!token)
@@ -5635,13 +5649,13 @@ class QuerySyscalls {
5635
5649
  return { queryId };
5636
5650
  }
5637
5651
  handleQueryCleanup(args) {
5638
- const { queryId } = args;
5652
+ const queryId = args.queryId;
5639
5653
  delete this.pendingQueries[queryId];
5640
5654
  delete this.queryResults[queryId];
5641
5655
  return {};
5642
5656
  }
5643
5657
  async handleQueryStreamNext(args) {
5644
- const { queryId } = args;
5658
+ const queryId = args.queryId;
5645
5659
  if (this.pendingQueries[queryId]) {
5646
5660
  const query = this.pendingQueries[queryId];
5647
5661
  delete this.pendingQueries[queryId];
@@ -5912,53 +5926,15 @@ var __export2 = (target, all) => {
5912
5926
  });
5913
5927
  };
5914
5928
  var __esm2 = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
5915
- function hexToArrayBuffer3(hex) {
5916
- if (hex === "") {
5917
- return new Uint8Array(0).buffer;
5918
- }
5919
- const matches = hex.match(/.{1,2}/g);
5920
- if (!matches) {
5921
- throw new Error(`Invalid hex string: ${hex}`);
5922
- }
5923
- return new Uint8Array(matches.map((byte) => parseInt(byte, 16))).buffer;
5924
- }
5925
- function arrayBufferToHex3(buffer) {
5926
- return Array.from(new Uint8Array(buffer)).map((b) => b.toString(16).padStart(2, "0")).join("");
5927
- }
5928
- function stringToHex2(s) {
5929
- const buffer = new TextEncoder().encode(s);
5930
- return arrayBufferToHex3(buffer.buffer);
5931
- }
5932
- function hexToString2(hex) {
5933
- const buffer = hexToArrayBuffer3(hex);
5934
- return new TextDecoder().decode(buffer);
5935
- }
5936
- function serializeDeveloperId2(tableHex, internalIdHex) {
5937
- return `${tableHex}${DOC_ID_SEPARATOR2}${internalIdHex}`;
5938
- }
5939
- function deserializeDeveloperId2(developerId) {
5940
- if (!developerId) {
5941
- return null;
5942
- }
5943
- for (const separator of [DOC_ID_SEPARATOR2, LEGACY_DOC_ID_SEPARATOR2]) {
5944
- const parts = developerId.split(separator);
5945
- if (parts.length === 2 && parts[0] && parts[1]) {
5946
- return { table: parts[0], internalId: parts[1] };
5947
- }
5948
- }
5949
- return null;
5950
- }
5951
- var DOC_ID_SEPARATOR2 = ":";
5952
- var LEGACY_DOC_ID_SEPARATOR2 = ";";
5953
5929
  function getLens2(b64) {
5954
- var len3 = b64.length;
5955
- if (len3 % 4 > 0) {
5930
+ var len2 = b64.length;
5931
+ if (len2 % 4 > 0) {
5956
5932
  throw new Error("Invalid string. Length must be a multiple of 4");
5957
5933
  }
5958
5934
  var validLen = b64.indexOf("=");
5959
5935
  if (validLen === -1)
5960
- validLen = len3;
5961
- var placeHoldersLen = validLen === len3 ? 0 : 4 - validLen % 4;
5936
+ validLen = len2;
5937
+ var placeHoldersLen = validLen === len2 ? 0 : 4 - validLen % 4;
5962
5938
  return [validLen, placeHoldersLen];
5963
5939
  }
5964
5940
  function _byteLength2(_b64, validLen, placeHoldersLen) {
@@ -5971,20 +5947,20 @@ function toByteArray2(b64) {
5971
5947
  var placeHoldersLen = lens[1];
5972
5948
  var arr = new Arr2(_byteLength2(b64, validLen, placeHoldersLen));
5973
5949
  var curByte = 0;
5974
- var len3 = placeHoldersLen > 0 ? validLen - 4 : validLen;
5975
- var i3;
5976
- for (i3 = 0;i3 < len3; i3 += 4) {
5977
- tmp = revLookup2[b64.charCodeAt(i3)] << 18 | revLookup2[b64.charCodeAt(i3 + 1)] << 12 | revLookup2[b64.charCodeAt(i3 + 2)] << 6 | revLookup2[b64.charCodeAt(i3 + 3)];
5950
+ var len2 = placeHoldersLen > 0 ? validLen - 4 : validLen;
5951
+ var i2;
5952
+ for (i2 = 0;i2 < len2; i2 += 4) {
5953
+ tmp = revLookup2[b64.charCodeAt(i2)] << 18 | revLookup2[b64.charCodeAt(i2 + 1)] << 12 | revLookup2[b64.charCodeAt(i2 + 2)] << 6 | revLookup2[b64.charCodeAt(i2 + 3)];
5978
5954
  arr[curByte++] = tmp >> 16 & 255;
5979
5955
  arr[curByte++] = tmp >> 8 & 255;
5980
5956
  arr[curByte++] = tmp & 255;
5981
5957
  }
5982
5958
  if (placeHoldersLen === 2) {
5983
- tmp = revLookup2[b64.charCodeAt(i3)] << 2 | revLookup2[b64.charCodeAt(i3 + 1)] >> 4;
5959
+ tmp = revLookup2[b64.charCodeAt(i2)] << 2 | revLookup2[b64.charCodeAt(i2 + 1)] >> 4;
5984
5960
  arr[curByte++] = tmp & 255;
5985
5961
  }
5986
5962
  if (placeHoldersLen === 1) {
5987
- tmp = revLookup2[b64.charCodeAt(i3)] << 10 | revLookup2[b64.charCodeAt(i3 + 1)] << 4 | revLookup2[b64.charCodeAt(i3 + 2)] >> 2;
5963
+ tmp = revLookup2[b64.charCodeAt(i2)] << 10 | revLookup2[b64.charCodeAt(i2 + 1)] << 4 | revLookup2[b64.charCodeAt(i2 + 2)] >> 2;
5988
5964
  arr[curByte++] = tmp >> 8 & 255;
5989
5965
  arr[curByte++] = tmp & 255;
5990
5966
  }
@@ -5996,26 +5972,26 @@ function tripletToBase642(num) {
5996
5972
  function encodeChunk2(uint8, start, end) {
5997
5973
  var tmp;
5998
5974
  var output = [];
5999
- for (var i3 = start;i3 < end; i3 += 3) {
6000
- tmp = (uint8[i3] << 16 & 16711680) + (uint8[i3 + 1] << 8 & 65280) + (uint8[i3 + 2] & 255);
5975
+ for (var i2 = start;i2 < end; i2 += 3) {
5976
+ tmp = (uint8[i2] << 16 & 16711680) + (uint8[i2 + 1] << 8 & 65280) + (uint8[i2 + 2] & 255);
6001
5977
  output.push(tripletToBase642(tmp));
6002
5978
  }
6003
5979
  return output.join("");
6004
5980
  }
6005
5981
  function fromByteArray2(uint8) {
6006
5982
  var tmp;
6007
- var len3 = uint8.length;
6008
- var extraBytes = len3 % 3;
5983
+ var len2 = uint8.length;
5984
+ var extraBytes = len2 % 3;
6009
5985
  var parts = [];
6010
5986
  var maxChunkLength = 16383;
6011
- for (var i3 = 0, len22 = len3 - extraBytes;i3 < len22; i3 += maxChunkLength) {
6012
- parts.push(encodeChunk2(uint8, i3, i3 + maxChunkLength > len22 ? len22 : i3 + maxChunkLength));
5987
+ for (var i2 = 0, len22 = len2 - extraBytes;i2 < len22; i2 += maxChunkLength) {
5988
+ parts.push(encodeChunk2(uint8, i2, i2 + maxChunkLength > len22 ? len22 : i2 + maxChunkLength));
6013
5989
  }
6014
5990
  if (extraBytes === 1) {
6015
- tmp = uint8[len3 - 1];
5991
+ tmp = uint8[len2 - 1];
6016
5992
  parts.push(lookup2[tmp >> 2] + lookup2[tmp << 4 & 63] + "==");
6017
5993
  } else if (extraBytes === 2) {
6018
- tmp = (uint8[len3 - 2] << 8) + uint8[len3 - 1];
5994
+ tmp = (uint8[len2 - 2] << 8) + uint8[len2 - 1];
6019
5995
  parts.push(lookup2[tmp >> 10] + lookup2[tmp >> 4 & 63] + lookup2[tmp << 2 & 63] + "=");
6020
5996
  }
6021
5997
  return parts.join("");
@@ -6041,12 +6017,12 @@ function parseArgs2(args) {
6041
6017
  if (args === undefined) {
6042
6018
  return {};
6043
6019
  }
6044
- if (!isSimpleObject22(args)) {
6020
+ if (!isSimpleObject4(args)) {
6045
6021
  throw new Error(`The arguments to a Convex function must be an object. Received: ${args}`);
6046
6022
  }
6047
6023
  return args;
6048
6024
  }
6049
- function isSimpleObject22(value) {
6025
+ function isSimpleObject4(value) {
6050
6026
  const isObject = typeof value === "object";
6051
6027
  const prototype = Object.getPrototypeOf(value);
6052
6028
  const isSimple = prototype === null || prototype === Object.prototype || prototype?.constructor?.name === "Object";
@@ -6063,9 +6039,9 @@ function slowBigIntToBase642(value) {
6063
6039
  if (hex.length % 2 === 1)
6064
6040
  hex = "0" + hex;
6065
6041
  const bytes = new Uint8Array(new ArrayBuffer(8));
6066
- let i3 = 0;
6042
+ let i22 = 0;
6067
6043
  for (const hexByte of hex.match(/.{2}/g).reverse()) {
6068
- bytes.set([parseInt(hexByte, 16)], i3++);
6044
+ bytes.set([parseInt(hexByte, 16)], i22++);
6069
6045
  value >>= EIGHT2;
6070
6046
  }
6071
6047
  return fromByteArray2(bytes);
@@ -6109,10 +6085,10 @@ function validateObjectField2(k) {
6109
6085
  if (k.startsWith("$")) {
6110
6086
  throw new Error(`Field name ${k} starts with a '$', which is reserved.`);
6111
6087
  }
6112
- for (let i3 = 0;i3 < k.length; i3 += 1) {
6113
- const charCode = k.charCodeAt(i3);
6088
+ for (let i22 = 0;i22 < k.length; i22 += 1) {
6089
+ const charCode = k.charCodeAt(i22);
6114
6090
  if (charCode < 32 || charCode >= 127) {
6115
- throw new Error(`Field name ${k} has invalid character '${k[i3]}': Field names can only contain non-control ASCII characters`);
6091
+ throw new Error(`Field name ${k} has invalid character '${k[i22]}': Field names can only contain non-control ASCII characters`);
6116
6092
  }
6117
6093
  }
6118
6094
  }
@@ -6233,7 +6209,7 @@ function convexToJsonInternal2(value, originalValue, context, includeTopLevelUnd
6233
6209
  return { $bytes: fromByteArray2(new Uint8Array(value)) };
6234
6210
  }
6235
6211
  if (Array.isArray(value)) {
6236
- return value.map((value2, i3) => convexToJsonInternal2(value2, originalValue, context + `[${i3}]`, false));
6212
+ return value.map((value2, i22) => convexToJsonInternal2(value2, originalValue, context + `[${i22}]`, false));
6237
6213
  }
6238
6214
  if (value instanceof Set) {
6239
6215
  throw new Error(errorMessageForUnsupportedType2(context, "Set", [...value], originalValue));
@@ -6241,7 +6217,7 @@ function convexToJsonInternal2(value, originalValue, context, includeTopLevelUnd
6241
6217
  if (value instanceof Map) {
6242
6218
  throw new Error(errorMessageForUnsupportedType2(context, "Map", [...value], originalValue));
6243
6219
  }
6244
- if (!isSimpleObject22(value)) {
6220
+ if (!isSimpleObject4(value)) {
6245
6221
  const theType = value?.constructor?.name;
6246
6222
  const typeName = theType ? `${theType} ` : "";
6247
6223
  throw new Error(errorMessageForUnsupportedType2(context, typeName, value, originalValue));
@@ -6758,6 +6734,44 @@ var init_values2 = __esm2(() => {
6758
6734
  init_validator3();
6759
6735
  init_errors2();
6760
6736
  });
6737
+ function hexToArrayBuffer3(hex) {
6738
+ if (hex === "") {
6739
+ return new Uint8Array(0).buffer;
6740
+ }
6741
+ const matches = hex.match(/.{1,2}/g);
6742
+ if (!matches) {
6743
+ throw new Error(`Invalid hex string: ${hex}`);
6744
+ }
6745
+ return new Uint8Array(matches.map((byte) => parseInt(byte, 16))).buffer;
6746
+ }
6747
+ function arrayBufferToHex3(buffer) {
6748
+ return Array.from(new Uint8Array(buffer)).map((b) => b.toString(16).padStart(2, "0")).join("");
6749
+ }
6750
+ function stringToHex2(s) {
6751
+ const buffer = new TextEncoder().encode(s);
6752
+ return arrayBufferToHex3(buffer.buffer);
6753
+ }
6754
+ function hexToString2(hex) {
6755
+ const buffer = hexToArrayBuffer3(hex);
6756
+ return new TextDecoder().decode(buffer);
6757
+ }
6758
+ function serializeDeveloperId2(tableHex, internalIdHex) {
6759
+ return `${tableHex}${DOC_ID_SEPARATOR2}${internalIdHex}`;
6760
+ }
6761
+ function deserializeDeveloperId2(developerId) {
6762
+ if (!developerId) {
6763
+ return null;
6764
+ }
6765
+ for (const separator of [DOC_ID_SEPARATOR2, LEGACY_DOC_ID_SEPARATOR2]) {
6766
+ const parts = developerId.split(separator);
6767
+ if (parts.length === 2 && parts[0] && parts[1]) {
6768
+ return { table: parts[0], internalId: parts[1] };
6769
+ }
6770
+ }
6771
+ return null;
6772
+ }
6773
+ var DOC_ID_SEPARATOR2 = ":";
6774
+ var LEGACY_DOC_ID_SEPARATOR2 = ";";
6761
6775
  function encodeNumber2(n) {
6762
6776
  const buffer = new ArrayBuffer(8);
6763
6777
  const view = new DataView(buffer);
@@ -6766,8 +6780,8 @@ function encodeNumber2(n) {
6766
6780
  if (n >= 0) {
6767
6781
  bytes[0] ^= 128;
6768
6782
  } else {
6769
- for (let i3 = 0;i3 < 8; i3++) {
6770
- bytes[i3] ^= 255;
6783
+ for (let i22 = 0;i22 < 8; i22++) {
6784
+ bytes[i22] ^= 255;
6771
6785
  }
6772
6786
  }
6773
6787
  return bytes;
@@ -6880,10 +6894,10 @@ function compareIndexKeys2(a, b) {
6880
6894
  const viewA = new Uint8Array(a);
6881
6895
  const viewB = new Uint8Array(b);
6882
6896
  const minLen = Math.min(viewA.length, viewB.length);
6883
- for (let i3 = 0;i3 < minLen; i3++) {
6884
- if (viewA[i3] < viewB[i3])
6897
+ for (let i22 = 0;i22 < minLen; i22++) {
6898
+ if (viewA[i22] < viewB[i22])
6885
6899
  return -1;
6886
- if (viewA[i3] > viewB[i3])
6900
+ if (viewA[i22] > viewB[i22])
6887
6901
  return 1;
6888
6902
  }
6889
6903
  if (viewA.length < viewB.length)
@@ -8222,9 +8236,9 @@ async function listSystemFunctions2(options = {}) {
8222
8236
  });
8223
8237
  const analysisResults = await pooledMap2(filteredListings, (listing) => analyzeModule2(listing, componentPath), 20);
8224
8238
  const results = [];
8225
- for (let i3 = 0;i3 < filteredListings.length; i3++) {
8226
- const listing = filteredListings[i3];
8227
- const result = analysisResults[i3];
8239
+ for (let i22 = 0;i22 < filteredListings.length; i22++) {
8240
+ const listing = filteredListings[i22];
8241
+ const result = analysisResults[i22];
8228
8242
  if (result.status === "rejected") {
8229
8243
  if (!isNpmPackageError2(result.reason)) {
8230
8244
  console.warn(`Failed to analyze module "${listing.path}":`, result.reason);
@@ -9093,7 +9107,7 @@ class ModuleRegistry2 {
9093
9107
  }
9094
9108
  async load(request) {
9095
9109
  const scopes = expandComponentScopes2(request.componentPath);
9096
- const errors3 = [];
9110
+ const errors2 = [];
9097
9111
  let attempted = false;
9098
9112
  for (const scope of scopes) {
9099
9113
  const loaders = this.scopedLoaders.get(scope);
@@ -9108,7 +9122,7 @@ class ModuleRegistry2 {
9108
9122
  return result;
9109
9123
  }
9110
9124
  } catch (error2) {
9111
- errors3.push(error2);
9125
+ errors2.push(error2);
9112
9126
  }
9113
9127
  }
9114
9128
  }
@@ -9117,8 +9131,8 @@ class ModuleRegistry2 {
9117
9131
  throw new Error(`Unable to resolve ${description}. No module loaders are registered${request.componentPath ? ` for component "${request.componentPath}"` : ""}. Register a loader with runtime worker options (\`moduleLoader\`, \`moduleLoaders\`, or \`configureModuleLoaders\`).`);
9118
9132
  }
9119
9133
  const error = new Error(`Unable to resolve ${description}`);
9120
- if (errors3.length > 0) {
9121
- error.causes = errors3;
9134
+ if (errors2.length > 0) {
9135
+ error.causes = errors2;
9122
9136
  }
9123
9137
  throw error;
9124
9138
  }
@@ -9342,8 +9356,8 @@ function expandComponentScopes2(componentPath) {
9342
9356
  if (componentPath) {
9343
9357
  const normalized = normalizeComponentPath2(componentPath);
9344
9358
  const segments = normalized.split("/").filter(Boolean);
9345
- for (let i3 = segments.length;i3 > 0; i3--) {
9346
- scopes.push(segments.slice(0, i3).join("/"));
9359
+ for (let i22 = segments.length;i22 > 0; i22--) {
9360
+ scopes.push(segments.slice(0, i22).join("/"));
9347
9361
  }
9348
9362
  }
9349
9363
  scopes.push("");
@@ -9618,8 +9632,8 @@ Path: ${formatPath(path)}
9618
9632
  Value: ${formatValue(value)}
9619
9633
  Validator: v.array(...)`);
9620
9634
  }
9621
- for (let i3 = 0;i3 < value.length; i3++) {
9622
- validateValidator2(validator2.value, value[i3], `${path}[${i3}]`, options);
9635
+ for (let i22 = 0;i22 < value.length; i22++) {
9636
+ validateValidator2(validator2.value, value[i22], `${path}[${i22}]`, options);
9623
9637
  }
9624
9638
  return;
9625
9639
  }
@@ -9647,7 +9661,7 @@ Path: ${formatPath(path)}
9647
9661
  Value: ${formatValue(value)}
9648
9662
  Validator: v.object({...})`);
9649
9663
  }
9650
- if (!isSimpleObject32(value)) {
9664
+ if (!isSimpleObject22(value)) {
9651
9665
  throw new Error(`Value does not match validator.
9652
9666
  Path: ${formatPath(path)}
9653
9667
  Value: ${formatValue(value)}
@@ -9697,7 +9711,7 @@ function isMatchingValidatorTable2(idTableName, validatorTableName, componentPat
9697
9711
  }
9698
9712
  return idBareName === validatorBareName;
9699
9713
  }
9700
- function isSimpleObject32(value) {
9714
+ function isSimpleObject22(value) {
9701
9715
  const isObject = typeof value === "object";
9702
9716
  const prototype = Object.getPrototypeOf(value);
9703
9717
  const isSimple = prototype === null || prototype === Object.prototype || prototype?.constructor?.name === "Object";
@@ -9927,9 +9941,9 @@ var ALPHABET2 = "0123456789abcdefghjkmnpqrstvwxyz";
9927
9941
  var ALPHABET_MAP2;
9928
9942
  var init_base322 = __esm2(() => {
9929
9943
  ALPHABET_MAP2 = new Map;
9930
- for (let i3 = 0;i3 < ALPHABET2.length; i3++) {
9931
- ALPHABET_MAP2.set(ALPHABET2[i3], i3);
9932
- ALPHABET_MAP2.set(ALPHABET2[i3].toUpperCase(), i3);
9944
+ for (let i22 = 0;i22 < ALPHABET2.length; i22++) {
9945
+ ALPHABET_MAP2.set(ALPHABET2[i22], i22);
9946
+ ALPHABET_MAP2.set(ALPHABET2[i22].toUpperCase(), i22);
9933
9947
  }
9934
9948
  ALPHABET_MAP2.set("i", 1);
9935
9949
  ALPHABET_MAP2.set("I", 1);
@@ -10080,8 +10094,8 @@ function isValidDocumentId2(encoded) {
10080
10094
  }
10081
10095
  function internalIdToHex2(internalId) {
10082
10096
  let hex = "";
10083
- for (let i3 = 0;i3 < internalId.length; i3++) {
10084
- hex += internalId[i3].toString(16).padStart(2, "0");
10097
+ for (let i22 = 0;i22 < internalId.length; i22++) {
10098
+ hex += internalId[i22].toString(16).padStart(2, "0");
10085
10099
  }
10086
10100
  return hex;
10087
10101
  }
@@ -10093,332 +10107,7 @@ var init_document_id2 = __esm2(() => {
10093
10107
  init_base322();
10094
10108
  cryptoGetRandomValues2 = crypto.getRandomValues.bind(crypto);
10095
10109
  });
10096
- var lookup3 = [];
10097
- var revLookup3 = [];
10098
- var Arr3 = Uint8Array;
10099
- var code3 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
10100
- for (i3 = 0, len3 = code3.length;i3 < len3; ++i3) {
10101
- lookup3[i3] = code3[i3];
10102
- revLookup3[code3.charCodeAt(i3)] = i3;
10103
- }
10104
- var i3;
10105
- var len3;
10106
- revLookup3[45] = 62;
10107
- revLookup3[95] = 63;
10108
- function getLens3(b64) {
10109
- var len22 = b64.length;
10110
- if (len22 % 4 > 0) {
10111
- throw new Error("Invalid string. Length must be a multiple of 4");
10112
- }
10113
- var validLen = b64.indexOf("=");
10114
- if (validLen === -1)
10115
- validLen = len22;
10116
- var placeHoldersLen = validLen === len22 ? 0 : 4 - validLen % 4;
10117
- return [validLen, placeHoldersLen];
10118
- }
10119
- function _byteLength3(_b64, validLen, placeHoldersLen) {
10120
- return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
10121
- }
10122
- function toByteArray3(b64) {
10123
- var tmp;
10124
- var lens = getLens3(b64);
10125
- var validLen = lens[0];
10126
- var placeHoldersLen = lens[1];
10127
- var arr = new Arr3(_byteLength3(b64, validLen, placeHoldersLen));
10128
- var curByte = 0;
10129
- var len22 = placeHoldersLen > 0 ? validLen - 4 : validLen;
10130
- var i22;
10131
- for (i22 = 0;i22 < len22; i22 += 4) {
10132
- tmp = revLookup3[b64.charCodeAt(i22)] << 18 | revLookup3[b64.charCodeAt(i22 + 1)] << 12 | revLookup3[b64.charCodeAt(i22 + 2)] << 6 | revLookup3[b64.charCodeAt(i22 + 3)];
10133
- arr[curByte++] = tmp >> 16 & 255;
10134
- arr[curByte++] = tmp >> 8 & 255;
10135
- arr[curByte++] = tmp & 255;
10136
- }
10137
- if (placeHoldersLen === 2) {
10138
- tmp = revLookup3[b64.charCodeAt(i22)] << 2 | revLookup3[b64.charCodeAt(i22 + 1)] >> 4;
10139
- arr[curByte++] = tmp & 255;
10140
- }
10141
- if (placeHoldersLen === 1) {
10142
- tmp = revLookup3[b64.charCodeAt(i22)] << 10 | revLookup3[b64.charCodeAt(i22 + 1)] << 4 | revLookup3[b64.charCodeAt(i22 + 2)] >> 2;
10143
- arr[curByte++] = tmp >> 8 & 255;
10144
- arr[curByte++] = tmp & 255;
10145
- }
10146
- return arr;
10147
- }
10148
- function tripletToBase643(num) {
10149
- return lookup3[num >> 18 & 63] + lookup3[num >> 12 & 63] + lookup3[num >> 6 & 63] + lookup3[num & 63];
10150
- }
10151
- function encodeChunk3(uint8, start, end) {
10152
- var tmp;
10153
- var output = [];
10154
- for (var i22 = start;i22 < end; i22 += 3) {
10155
- tmp = (uint8[i22] << 16 & 16711680) + (uint8[i22 + 1] << 8 & 65280) + (uint8[i22 + 2] & 255);
10156
- output.push(tripletToBase643(tmp));
10157
- }
10158
- return output.join("");
10159
- }
10160
- function fromByteArray3(uint8) {
10161
- var tmp;
10162
- var len22 = uint8.length;
10163
- var extraBytes = len22 % 3;
10164
- var parts = [];
10165
- var maxChunkLength = 16383;
10166
- for (var i22 = 0, len222 = len22 - extraBytes;i22 < len222; i22 += maxChunkLength) {
10167
- parts.push(encodeChunk3(uint8, i22, i22 + maxChunkLength > len222 ? len222 : i22 + maxChunkLength));
10168
- }
10169
- if (extraBytes === 1) {
10170
- tmp = uint8[len22 - 1];
10171
- parts.push(lookup3[tmp >> 2] + lookup3[tmp << 4 & 63] + "==");
10172
- } else if (extraBytes === 2) {
10173
- tmp = (uint8[len22 - 2] << 8) + uint8[len22 - 1];
10174
- parts.push(lookup3[tmp >> 10] + lookup3[tmp >> 4 & 63] + lookup3[tmp << 2 & 63] + "=");
10175
- }
10176
- return parts.join("");
10177
- }
10178
- function isSimpleObject4(value) {
10179
- const isObject = typeof value === "object";
10180
- const prototype = Object.getPrototypeOf(value);
10181
- const isSimple = prototype === null || prototype === Object.prototype || prototype?.constructor?.name === "Object";
10182
- return isObject && isSimple;
10183
- }
10184
- var LITTLE_ENDIAN3 = true;
10185
- var MIN_INT643 = BigInt("-9223372036854775808");
10186
- var MAX_INT643 = BigInt("9223372036854775807");
10187
- var ZERO3 = BigInt("0");
10188
- var EIGHT3 = BigInt("8");
10189
- var TWOFIFTYSIX3 = BigInt("256");
10190
- function isSpecial3(n) {
10191
- return Number.isNaN(n) || !Number.isFinite(n) || Object.is(n, -0);
10192
- }
10193
- function slowBigIntToBase643(value) {
10194
- if (value < ZERO3) {
10195
- value -= MIN_INT643 + MIN_INT643;
10196
- }
10197
- let hex = value.toString(16);
10198
- if (hex.length % 2 === 1)
10199
- hex = "0" + hex;
10200
- const bytes = new Uint8Array(new ArrayBuffer(8));
10201
- let i22 = 0;
10202
- for (const hexByte of hex.match(/.{2}/g).reverse()) {
10203
- bytes.set([parseInt(hexByte, 16)], i22++);
10204
- value >>= EIGHT3;
10205
- }
10206
- return fromByteArray3(bytes);
10207
- }
10208
- function slowBase64ToBigInt3(encoded) {
10209
- const integerBytes = toByteArray3(encoded);
10210
- if (integerBytes.byteLength !== 8) {
10211
- throw new Error(`Received ${integerBytes.byteLength} bytes, expected 8 for $integer`);
10212
- }
10213
- let value = ZERO3;
10214
- let power = ZERO3;
10215
- for (const byte of integerBytes) {
10216
- value += BigInt(byte) * TWOFIFTYSIX3 ** power;
10217
- power++;
10218
- }
10219
- if (value > MAX_INT643) {
10220
- value += MIN_INT643 + MIN_INT643;
10221
- }
10222
- return value;
10223
- }
10224
- function modernBigIntToBase643(value) {
10225
- if (value < MIN_INT643 || MAX_INT643 < value) {
10226
- throw new Error(`BigInt ${value} does not fit into a 64-bit signed integer.`);
10227
- }
10228
- const buffer = new ArrayBuffer(8);
10229
- new DataView(buffer).setBigInt64(0, value, true);
10230
- return fromByteArray3(new Uint8Array(buffer));
10231
- }
10232
- function modernBase64ToBigInt3(encoded) {
10233
- const integerBytes = toByteArray3(encoded);
10234
- if (integerBytes.byteLength !== 8) {
10235
- throw new Error(`Received ${integerBytes.byteLength} bytes, expected 8 for $integer`);
10236
- }
10237
- const intBytesView = new DataView(integerBytes.buffer);
10238
- return intBytesView.getBigInt64(0, true);
10239
- }
10240
- var bigIntToBase643 = DataView.prototype.setBigInt64 ? modernBigIntToBase643 : slowBigIntToBase643;
10241
- var base64ToBigInt3 = DataView.prototype.getBigInt64 ? modernBase64ToBigInt3 : slowBase64ToBigInt3;
10242
- var MAX_IDENTIFIER_LEN3 = 1024;
10243
- function validateObjectField3(k) {
10244
- if (k.length > MAX_IDENTIFIER_LEN3) {
10245
- throw new Error(`Field name ${k} exceeds maximum field name length ${MAX_IDENTIFIER_LEN3}.`);
10246
- }
10247
- if (k.startsWith("$")) {
10248
- throw new Error(`Field name ${k} starts with a '$', which is reserved.`);
10249
- }
10250
- for (let i22 = 0;i22 < k.length; i22 += 1) {
10251
- const charCode = k.charCodeAt(i22);
10252
- if (charCode < 32 || charCode >= 127) {
10253
- throw new Error(`Field name ${k} has invalid character '${k[i22]}': Field names can only contain non-control ASCII characters`);
10254
- }
10255
- }
10256
- }
10257
- function jsonToConvex3(value) {
10258
- if (value === null) {
10259
- return value;
10260
- }
10261
- if (typeof value === "boolean") {
10262
- return value;
10263
- }
10264
- if (typeof value === "number") {
10265
- return value;
10266
- }
10267
- if (typeof value === "string") {
10268
- return value;
10269
- }
10270
- if (Array.isArray(value)) {
10271
- return value.map((value2) => jsonToConvex3(value2));
10272
- }
10273
- if (typeof value !== "object") {
10274
- throw new Error(`Unexpected type of ${value}`);
10275
- }
10276
- const entries = Object.entries(value);
10277
- if (entries.length === 1) {
10278
- const key = entries[0][0];
10279
- if (key === "$bytes") {
10280
- if (typeof value.$bytes !== "string") {
10281
- throw new Error(`Malformed $bytes field on ${value}`);
10282
- }
10283
- return toByteArray3(value.$bytes).buffer;
10284
- }
10285
- if (key === "$integer") {
10286
- if (typeof value.$integer !== "string") {
10287
- throw new Error(`Malformed $integer field on ${value}`);
10288
- }
10289
- return base64ToBigInt3(value.$integer);
10290
- }
10291
- if (key === "$float") {
10292
- if (typeof value.$float !== "string") {
10293
- throw new Error(`Malformed $float field on ${value}`);
10294
- }
10295
- const floatBytes = toByteArray3(value.$float);
10296
- if (floatBytes.byteLength !== 8) {
10297
- throw new Error(`Received ${floatBytes.byteLength} bytes, expected 8 for $float`);
10298
- }
10299
- const floatBytesView = new DataView(floatBytes.buffer);
10300
- const float = floatBytesView.getFloat64(0, LITTLE_ENDIAN3);
10301
- if (!isSpecial3(float)) {
10302
- throw new Error(`Float ${float} should be encoded as a number`);
10303
- }
10304
- return float;
10305
- }
10306
- if (key === "$set") {
10307
- throw new Error(`Received a Set which is no longer supported as a Convex type.`);
10308
- }
10309
- if (key === "$map") {
10310
- throw new Error(`Received a Map which is no longer supported as a Convex type.`);
10311
- }
10312
- }
10313
- const out = {};
10314
- for (const [k, v3] of Object.entries(value)) {
10315
- validateObjectField3(k);
10316
- out[k] = jsonToConvex3(v3);
10317
- }
10318
- return out;
10319
- }
10320
- var MAX_VALUE_FOR_ERROR_LEN3 = 16384;
10321
- function stringifyValueForError3(value) {
10322
- const str = JSON.stringify(value, (_key, value2) => {
10323
- if (value2 === undefined) {
10324
- return "undefined";
10325
- }
10326
- if (typeof value2 === "bigint") {
10327
- return `${value2.toString()}n`;
10328
- }
10329
- return value2;
10330
- });
10331
- if (str.length > MAX_VALUE_FOR_ERROR_LEN3) {
10332
- const rest = "[...truncated]";
10333
- let truncateAt = MAX_VALUE_FOR_ERROR_LEN3 - rest.length;
10334
- const codePoint = str.codePointAt(truncateAt - 1);
10335
- if (codePoint !== undefined && codePoint > 65535) {
10336
- truncateAt -= 1;
10337
- }
10338
- return str.substring(0, truncateAt) + rest;
10339
- }
10340
- return str;
10341
- }
10342
- function convexToJsonInternal3(value, originalValue, context, includeTopLevelUndefined) {
10343
- if (value === undefined) {
10344
- const contextText = context && ` (present at path ${context} in original object ${stringifyValueForError3(originalValue)})`;
10345
- throw new Error(`undefined is not a valid Convex value${contextText}. To learn about Convex's supported types, see https://docs.convex.dev/using/types.`);
10346
- }
10347
- if (value === null) {
10348
- return value;
10349
- }
10350
- if (typeof value === "bigint") {
10351
- if (value < MIN_INT643 || MAX_INT643 < value) {
10352
- throw new Error(`BigInt ${value} does not fit into a 64-bit signed integer.`);
10353
- }
10354
- return { $integer: bigIntToBase643(value) };
10355
- }
10356
- if (typeof value === "number") {
10357
- if (isSpecial3(value)) {
10358
- const buffer = new ArrayBuffer(8);
10359
- new DataView(buffer).setFloat64(0, value, LITTLE_ENDIAN3);
10360
- return { $float: fromByteArray3(new Uint8Array(buffer)) };
10361
- } else {
10362
- return value;
10363
- }
10364
- }
10365
- if (typeof value === "boolean") {
10366
- return value;
10367
- }
10368
- if (typeof value === "string") {
10369
- return value;
10370
- }
10371
- if (value instanceof ArrayBuffer) {
10372
- return { $bytes: fromByteArray3(new Uint8Array(value)) };
10373
- }
10374
- if (Array.isArray(value)) {
10375
- return value.map((value2, i22) => convexToJsonInternal3(value2, originalValue, context + `[${i22}]`, false));
10376
- }
10377
- if (value instanceof Set) {
10378
- throw new Error(errorMessageForUnsupportedType3(context, "Set", [...value], originalValue));
10379
- }
10380
- if (value instanceof Map) {
10381
- throw new Error(errorMessageForUnsupportedType3(context, "Map", [...value], originalValue));
10382
- }
10383
- if (!isSimpleObject4(value)) {
10384
- const theType = value?.constructor?.name;
10385
- const typeName = theType ? `${theType} ` : "";
10386
- throw new Error(errorMessageForUnsupportedType3(context, typeName, value, originalValue));
10387
- }
10388
- const out = {};
10389
- const entries = Object.entries(value);
10390
- entries.sort(([k1, _v1], [k2, _v2]) => k1 === k2 ? 0 : k1 < k2 ? -1 : 1);
10391
- for (const [k, v3] of entries) {
10392
- if (v3 !== undefined) {
10393
- validateObjectField3(k);
10394
- out[k] = convexToJsonInternal3(v3, originalValue, context + `.${k}`, false);
10395
- } else if (includeTopLevelUndefined) {
10396
- validateObjectField3(k);
10397
- out[k] = convexOrUndefinedToJsonInternal3(v3, originalValue, context + `.${k}`);
10398
- }
10399
- }
10400
- return out;
10401
- }
10402
- function errorMessageForUnsupportedType3(context, typeName, value, originalValue) {
10403
- if (context) {
10404
- return `${typeName}${stringifyValueForError3(value)} is not a supported Convex type (present at path ${context} in original object ${stringifyValueForError3(originalValue)}). To learn about Convex's supported types, see https://docs.convex.dev/using/types.`;
10405
- } else {
10406
- return `${typeName}${stringifyValueForError3(value)} is not a supported Convex type.`;
10407
- }
10408
- }
10409
- function convexOrUndefinedToJsonInternal3(value, originalValue, context) {
10410
- if (value === undefined) {
10411
- return { $undefined: null };
10412
- } else {
10413
- if (originalValue === undefined) {
10414
- throw new Error(`Programming error. Current value is ${stringifyValueForError3(value)} but original value is undefined`);
10415
- }
10416
- return convexToJsonInternal3(value, originalValue, context, false);
10417
- }
10418
- }
10419
- function convexToJson3(value) {
10420
- return convexToJsonInternal3(value, value, "", false);
10421
- }
10110
+ init_values2();
10422
10111
  function documentIdKey(id) {
10423
10112
  return `${id.table}:${id.internalId}`;
10424
10113
  }
@@ -10664,7 +10353,7 @@ function decodeIndexId2(indexId) {
10664
10353
  }
10665
10354
  init_schema_service2();
10666
10355
  init_index_key_codec2();
10667
- function isSimpleObject42(value) {
10356
+ function isSimpleObject32(value) {
10668
10357
  const isObject = typeof value === "object" && value !== null;
10669
10358
  if (!isObject)
10670
10359
  return false;
@@ -10678,7 +10367,7 @@ function evaluateFieldPath2(fieldPath, document) {
10678
10367
  for (const part of parts) {
10679
10368
  if (current == null)
10680
10369
  return;
10681
- if (!isSimpleObject42(current))
10370
+ if (!isSimpleObject32(current))
10682
10371
  return;
10683
10372
  current = current[part];
10684
10373
  }
@@ -10704,6 +10393,19 @@ function parseDeveloperId2(developerId) {
10704
10393
  }
10705
10394
  return { table: parts.table, internalId: parts.internalId };
10706
10395
  }
10396
+ function parseStorageId2(storageId) {
10397
+ const parsed = parseDeveloperId2(storageId);
10398
+ if (parsed) {
10399
+ return parsed;
10400
+ }
10401
+ if (storageId.length === INTERNAL_ID_LENGTH2 * 2 && /^[0-9a-fA-F]+$/.test(storageId)) {
10402
+ return {
10403
+ table: stringToHex2("_storage"),
10404
+ internalId: storageId.toLowerCase()
10405
+ };
10406
+ }
10407
+ return null;
10408
+ }
10707
10409
  function isTablePlaceholder2(table) {
10708
10410
  return table.startsWith("#");
10709
10411
  }
@@ -11146,19 +10848,19 @@ class BlobStoreGateway2 {
11146
10848
  if (!this.storage) {
11147
10849
  return null;
11148
10850
  }
11149
- const docId = parseDeveloperId2(storageId);
10851
+ const docId = parseStorageId2(storageId);
11150
10852
  if (!docId) {
11151
- console.error(`[BlobStoreGateway] Failed to parse storage ID: ${storageId}`);
10853
+ console.debug(`[BlobStoreGateway] Failed to parse storage ID: ${storageId}`);
11152
10854
  return null;
11153
10855
  }
11154
10856
  const docValue = await this.queryRuntime.getVisibleDocumentById(storageId, docId);
11155
10857
  if (!docValue) {
11156
- console.error(`[BlobStoreGateway] Document not found for storage ID: ${storageId} (table: ${docId.table}, internalId: ${docId.internalId})`);
10858
+ console.debug(`[BlobStoreGateway] Document not found for storage ID: ${storageId} (table: ${docId.table}, internalId: ${docId.internalId}, ts: ${this.context.snapshotTimestamp})`);
11157
10859
  return null;
11158
10860
  }
11159
10861
  const storedBlob = await this.storage.get(docId.internalId);
11160
10862
  if (!storedBlob) {
11161
- console.error(`[BlobStoreGateway] Blob not found in storage: ${docId.internalId}`);
10863
+ console.debug(`[BlobStoreGateway] Blob not found in storage: ${docId.internalId}`);
11162
10864
  return null;
11163
10865
  }
11164
10866
  return storedBlob instanceof Blob ? storedBlob : new Blob([storedBlob]);
@@ -11167,7 +10869,7 @@ class BlobStoreGateway2 {
11167
10869
  if (!this.storage) {
11168
10870
  return null;
11169
10871
  }
11170
- const docId = parseDeveloperId2(storageId);
10872
+ const docId = parseStorageId2(storageId);
11171
10873
  if (!docId) {
11172
10874
  return null;
11173
10875
  }
@@ -11180,7 +10882,7 @@ class BlobStoreGateway2 {
11180
10882
  }
11181
10883
  async delete(storageId) {
11182
10884
  const storage2 = this.requireStorage();
11183
- const docId = parseDeveloperId2(storageId);
10885
+ const docId = parseStorageId2(storageId);
11184
10886
  if (!docId) {
11185
10887
  return;
11186
10888
  }
@@ -11239,8 +10941,9 @@ function resolveFunctionTarget2(callArgs, currentComponentPath) {
11239
10941
  return parseFunctionHandleTarget2(callArgs.functionHandle);
11240
10942
  }
11241
10943
  if (callArgs && typeof callArgs.functionHandle === "object" && callArgs.functionHandle !== null) {
11242
- if (typeof callArgs.functionHandle.handle === "string") {
11243
- return parseFunctionHandleTarget2(callArgs.functionHandle.handle);
10944
+ const handle = callArgs.functionHandle;
10945
+ if (typeof handle.handle === "string") {
10946
+ return parseFunctionHandleTarget2(handle.handle);
11244
10947
  }
11245
10948
  }
11246
10949
  if (callArgs && typeof callArgs.reference === "string") {
@@ -11480,17 +11183,15 @@ class ActionSyscalls2 {
11480
11183
  const type = args.udfType ?? args.type ?? "mutation";
11481
11184
  return await this.invocationManager.execute(target.udfPath, udfArguments, type, target.componentPath);
11482
11185
  }
11483
- handleCreateFunctionHandle(args) {
11186
+ async handleCreateFunctionHandle(args) {
11484
11187
  const target = resolveFunctionTarget2(args, this.context.componentPath);
11485
11188
  return formatFunctionHandle2(target.componentPath ?? "", target.udfPath);
11486
11189
  }
11487
11190
  async handleVectorSearch(args) {
11488
- const { query: vectorQuery } = args;
11489
- return this.queryRuntime.runVectorSearchAction(vectorQuery);
11191
+ return this.queryRuntime.runVectorSearchAction(args.query);
11490
11192
  }
11491
11193
  async handleSearchAction(args) {
11492
- const { query: searchQuery } = args;
11493
- return this.queryRuntime.runSearchAction(searchQuery);
11194
+ return this.queryRuntime.runSearchAction(args.query);
11494
11195
  }
11495
11196
  }
11496
11197
  init_values2();
@@ -11798,6 +11499,8 @@ function decodeJwtClaimsToken2(token) {
11798
11499
  return null;
11799
11500
  }
11800
11501
  }
11502
+ var DEFAULT_JWKS_CACHE_TTL_MS2 = 5 * 60 * 1000;
11503
+ var MAX_JWKS_CACHE_TTL_MS2 = 24 * 60 * 60 * 1000;
11801
11504
  var JWKS_CACHE2 = new Map;
11802
11505
  function decodeJwtUnsafe2(token) {
11803
11506
  if (!token)
@@ -11878,13 +11581,13 @@ class QuerySyscalls2 {
11878
11581
  return { queryId };
11879
11582
  }
11880
11583
  handleQueryCleanup(args) {
11881
- const { queryId } = args;
11584
+ const queryId = args.queryId;
11882
11585
  delete this.pendingQueries[queryId];
11883
11586
  delete this.queryResults[queryId];
11884
11587
  return {};
11885
11588
  }
11886
11589
  async handleQueryStreamNext(args) {
11887
- const { queryId } = args;
11590
+ const queryId = args.queryId;
11888
11591
  if (this.pendingQueries[queryId]) {
11889
11592
  const query = this.pendingQueries[queryId];
11890
11593
  delete this.pendingQueries[queryId];
@@ -12203,7 +11906,7 @@ class BaseSqliteDocStore {
12203
11906
  const insertDocStmt = this.adapter.prepare(documentQuery);
12204
11907
  const insertSearchFts = this.fts5Available && this.searchIndexesByTable.size > 0 ? this.adapter.prepare(`INSERT INTO search_indexes (index_id, document_id, ts, deleted, search_body) VALUES (?, ?, ?, ?, ?)`) : null;
12205
11908
  for (const doc of documents) {
12206
- const { value, deleted } = doc.value ? { value: JSON.stringify(convexToJson3(doc.value.value)), deleted: 0 } : { value: null, deleted: 1 };
11909
+ const { value, deleted } = doc.value ? { value: JSON.stringify(convexToJson2(doc.value.value)), deleted: 0 } : { value: null, deleted: 1 };
12207
11910
  await insertDocStmt.run(this.adapter.hexToBuffer(doc.id.internalId), Number(doc.ts), this.adapter.hexToBuffer(doc.id.table), value, deleted, doc.prev_ts ? Number(doc.prev_ts) : null);
12208
11911
  this.timestampOracle.observeTimestamp(doc.ts);
12209
11912
  if (insertSearchFts) {
@@ -12301,7 +12004,7 @@ class BaseSqliteDocStore {
12301
12004
  ts: BigInt(row.ts),
12302
12005
  value: {
12303
12006
  id: { table: tableId, internalId: docId },
12304
- value: jsonToConvex3(JSON.parse(row.json_value))
12007
+ value: jsonToConvex2(JSON.parse(row.json_value))
12305
12008
  },
12306
12009
  prev_ts: row.prev_ts ? BigInt(row.prev_ts) : null
12307
12010
  };
@@ -12325,7 +12028,7 @@ class BaseSqliteDocStore {
12325
12028
  yield {
12326
12029
  id: { table: tableId, internalId: docId },
12327
12030
  ts: BigInt(row.ts),
12328
- value: row.deleted === 0 && row.json_value ? { id: { table: tableId, internalId: docId }, value: jsonToConvex3(JSON.parse(row.json_value)) } : null,
12031
+ value: row.deleted === 0 && row.json_value ? { id: { table: tableId, internalId: docId }, value: jsonToConvex2(JSON.parse(row.json_value)) } : null,
12329
12032
  prev_ts: row.prev_ts ? BigInt(row.prev_ts) : null
12330
12033
  };
12331
12034
  }
@@ -12354,7 +12057,7 @@ class BaseSqliteDocStore {
12354
12057
  const entry = {
12355
12058
  id: query.id,
12356
12059
  ts: BigInt(row.ts),
12357
- value: row.deleted === 0 && row.json_value ? { id: query.id, value: jsonToConvex3(JSON.parse(row.json_value)) } : null,
12060
+ value: row.deleted === 0 && row.json_value ? { id: query.id, value: jsonToConvex2(JSON.parse(row.json_value)) } : null,
12358
12061
  prev_ts: row.prev_ts ? BigInt(row.prev_ts) : null
12359
12062
  };
12360
12063
  results.set(getPrevRevQueryKey(query), entry);
@@ -12378,7 +12081,7 @@ class BaseSqliteDocStore {
12378
12081
  const entry = {
12379
12082
  id: query.id,
12380
12083
  ts: BigInt(row.ts),
12381
- value: row.deleted === 0 && row.json_value ? { id: query.id, value: jsonToConvex3(JSON.parse(row.json_value)) } : null,
12084
+ value: row.deleted === 0 && row.json_value ? { id: query.id, value: jsonToConvex2(JSON.parse(row.json_value)) } : null,
12382
12085
  prev_ts: row.prev_ts ? BigInt(row.prev_ts) : null
12383
12086
  };
12384
12087
  results.set(getExactRevQueryKey(query), entry);
@@ -12412,7 +12115,7 @@ class BaseSqliteDocStore {
12412
12115
  ts,
12413
12116
  value: {
12414
12117
  id,
12415
- value: jsonToConvex3(JSON.parse(row.json_value))
12118
+ value: jsonToConvex2(JSON.parse(row.json_value))
12416
12119
  },
12417
12120
  prev_ts: row.prev_ts ? BigInt(row.prev_ts) : null
12418
12121
  };
@@ -12458,7 +12161,7 @@ class BaseSqliteDocStore {
12458
12161
  ts,
12459
12162
  value: {
12460
12163
  id: { table, internalId: docIdHex },
12461
- value: jsonToConvex3(JSON.parse(row.json_value))
12164
+ value: jsonToConvex2(JSON.parse(row.json_value))
12462
12165
  },
12463
12166
  prev_ts: row.prev_ts ? BigInt(row.prev_ts) : null
12464
12167
  });
@@ -12506,7 +12209,7 @@ class BaseSqliteDocStore {
12506
12209
  ts,
12507
12210
  value: {
12508
12211
  id: { table, internalId: docIdHex },
12509
- value: jsonToConvex3(JSON.parse(row.json_value))
12212
+ value: jsonToConvex2(JSON.parse(row.json_value))
12510
12213
  },
12511
12214
  prev_ts: row.prev_ts ? BigInt(row.prev_ts) : null
12512
12215
  };
@@ -12610,9 +12313,9 @@ class BaseSqliteDocStore {
12610
12313
  let dot = 0;
12611
12314
  let queryMagnitude = 0;
12612
12315
  let docMagnitude = 0;
12613
- for (let i32 = 0;i32 < vector.length; i32++) {
12614
- const q = vector[i32];
12615
- const d = embedding[i32];
12316
+ for (let i22 = 0;i22 < vector.length; i22++) {
12317
+ const q = vector[i22];
12318
+ const d = embedding[i22];
12616
12319
  dot += q * d;
12617
12320
  queryMagnitude += q * q;
12618
12321
  docMagnitude += d * d;
@@ -12639,11 +12342,11 @@ class BaseSqliteDocStore {
12639
12342
  class D1StatementWrapper {
12640
12343
  db;
12641
12344
  sql;
12642
- batchStatements;
12643
- constructor(db, sql, batchStatements) {
12345
+ getCollector;
12346
+ constructor(db, sql, getCollector) {
12644
12347
  this.db = db;
12645
12348
  this.sql = sql;
12646
- this.batchStatements = batchStatements;
12349
+ this.getCollector = getCollector;
12647
12350
  }
12648
12351
  async get(...params) {
12649
12352
  const stmt = this.db.prepare(this.sql).bind(...params);
@@ -12657,13 +12360,18 @@ class D1StatementWrapper {
12657
12360
  }
12658
12361
  async run(...params) {
12659
12362
  const stmt = this.db.prepare(this.sql).bind(...params);
12660
- this.batchStatements.push(stmt);
12363
+ const collector = this.getCollector();
12364
+ if (!collector) {
12365
+ await stmt.run();
12366
+ return;
12367
+ }
12368
+ collector.push(stmt);
12661
12369
  }
12662
12370
  }
12663
12371
 
12664
12372
  class D1SqliteAdapter {
12665
12373
  db;
12666
- batchStatements = [];
12374
+ statementCollector = null;
12667
12375
  constructor(db) {
12668
12376
  this.db = db;
12669
12377
  }
@@ -12671,16 +12379,23 @@ class D1SqliteAdapter {
12671
12379
  await this.db.prepare(sql).run();
12672
12380
  }
12673
12381
  prepare(sql) {
12674
- return new D1StatementWrapper(this.db, sql, this.batchStatements);
12382
+ return new D1StatementWrapper(this.db, sql, () => this.statementCollector);
12675
12383
  }
12676
12384
  async transaction(fn) {
12677
- this.batchStatements = [];
12678
- const result = await fn();
12679
- if (this.batchStatements.length > 0) {
12680
- await this.db.batch(this.batchStatements);
12681
- this.batchStatements = [];
12385
+ if (this.statementCollector) {
12386
+ return await fn();
12387
+ }
12388
+ const collector = [];
12389
+ this.statementCollector = collector;
12390
+ try {
12391
+ const result = await fn();
12392
+ if (collector.length > 0) {
12393
+ await this.db.batch(collector);
12394
+ }
12395
+ return result;
12396
+ } finally {
12397
+ this.statementCollector = null;
12682
12398
  }
12683
- return result;
12684
12399
  }
12685
12400
  hexToBuffer(hex) {
12686
12401
  return hexToArrayBuffer(hex);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@concavejs/docstore-cf-d1",
3
- "version": "0.0.1-alpha.5",
3
+ "version": "0.0.1-alpha.7",
4
4
  "license": "FSL-1.1-Apache-2.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -21,8 +21,8 @@
21
21
  "test": "vitest --run --passWithNoTests"
22
22
  },
23
23
  "dependencies": {
24
- "@concavejs/core": "0.0.1-alpha.5",
25
- "@concavejs/docstore-sqlite-base": "0.0.1-alpha.5",
24
+ "@concavejs/core": "0.0.1-alpha.6",
25
+ "@concavejs/docstore-sqlite-base": "0.0.1-alpha.6",
26
26
  "convex": "^1.27.3"
27
27
  },
28
28
  "devDependencies": {