@concavejs/core 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.
Files changed (36) hide show
  1. package/dist/auth/jwt.d.ts +5 -0
  2. package/dist/auth/jwt.js +37 -5
  3. package/dist/http/api-router.d.ts +3 -1
  4. package/dist/http/api-router.js +62 -15
  5. package/dist/http/http-handler.js +53 -4
  6. package/dist/interfaces/execution-context.d.ts +2 -1
  7. package/dist/kernel/blob-store-gateway.js +7 -7
  8. package/dist/kernel/context-storage.js +6 -0
  9. package/dist/kernel/syscalls/action-syscalls.js +4 -6
  10. package/dist/kernel/syscalls/database-syscalls.js +1 -1
  11. package/dist/kernel/syscalls/js-router.d.ts +2 -2
  12. package/dist/kernel/syscalls/kernel-syscalls.d.ts +1 -1
  13. package/dist/kernel/syscalls/query-syscalls.js +2 -2
  14. package/dist/kernel/syscalls/router.d.ts +3 -2
  15. package/dist/kernel/syscalls/utils.d.ts +3 -3
  16. package/dist/kernel/syscalls/utils.js +3 -2
  17. package/dist/queryengine/developer-id.d.ts +8 -0
  18. package/dist/queryengine/developer-id.js +23 -2
  19. package/dist/router/router.d.ts +8 -3
  20. package/dist/runtime/runtime-context.d.ts +1 -1
  21. package/dist/scheduler/cron-executor.d.ts +6 -2
  22. package/dist/scheduler/cron-executor.js +54 -26
  23. package/dist/scheduler/scheduled-function-executor.d.ts +6 -2
  24. package/dist/scheduler/scheduled-function-executor.js +58 -36
  25. package/dist/sync/protocol-handler.d.ts +25 -0
  26. package/dist/sync/protocol-handler.js +111 -1
  27. package/dist/transactor/occ-transaction.js +3 -3
  28. package/dist/udf/execution-adapter.d.ts +1 -1
  29. package/dist/udf/execution-adapter.js +2 -2
  30. package/dist/udf/executor/inline.d.ts +1 -1
  31. package/dist/udf/executor/inline.js +3 -3
  32. package/dist/udf/executor/interface.d.ts +5 -2
  33. package/dist/udf/runtime/udf-setup.d.ts +4 -4
  34. package/dist/udf/runtime/udf-setup.js +11 -9
  35. package/dist/utils/long.d.ts +1 -1
  36. package/package.json +1 -1
@@ -68,9 +68,9 @@ function patchGlobals() {
68
68
  globalThis.Date.now = udfDateNow;
69
69
  globalThis.fetch = udfFetch;
70
70
  globalThis.Math.random = udfMathRandom;
71
- globalThis.setInterval = udfSetInterval;
72
- globalThis.setTimeout = udfSetTimeout;
73
71
  const globalAny = globalThis;
72
+ globalAny.setInterval = udfSetInterval;
73
+ globalAny.setTimeout = udfSetTimeout;
74
74
  globalAny.crypto.randomUUID = udfCryptoRandomUUID;
75
75
  globalAny.crypto.getRandomValues = udfCryptoGetRandomValues;
76
76
  globalAny.console = udfConsole;
@@ -116,7 +116,7 @@ class ForbiddenInQueriesOrMutations extends Error {
116
116
  }
117
117
  }
118
118
  async function runUdfAndGetLogs(docstore, fn, ops, auth, // Still accept for backwards compatibility, but prefer ambient context
119
- udfType, storage, deterministicSeed, mutationTransaction, udfExecutor, componentPath) {
119
+ udfType, storage, deterministicSeed, mutationTransaction, udfExecutor, componentPath, snapshotOverride) {
120
120
  // Get auth from ambient context (set by execution adapter) or fallback to explicit param
121
121
  const ambientIdentity = getAuthContext();
122
122
  let effectiveAuth;
@@ -133,7 +133,7 @@ udfType, storage, deterministicSeed, mutationTransaction, udfExecutor, component
133
133
  const inheritedSnapshot = snapshotContext.getStore() ?? null;
134
134
  const existingIdGenerator = idGeneratorContext.getStore() ?? undefined;
135
135
  const idGenerator = existingIdGenerator ?? (deterministicSeed ? createDeterministicIdGenerator(deterministicSeed) : undefined);
136
- const convex = new UdfKernel(docstore, effectiveAuth, storage, inheritedSnapshot, mutationTransaction, udfExecutor, componentPath, idGenerator);
136
+ const convex = new UdfKernel(docstore, effectiveAuth, storage, snapshotOverride ?? inheritedSnapshot, mutationTransaction, udfExecutor, componentPath, idGenerator);
137
137
  convex.clearAccessLogs();
138
138
  const logLines = [];
139
139
  const logger = (level) => {
@@ -196,7 +196,7 @@ udfType, storage, deterministicSeed, mutationTransaction, udfExecutor, component
196
196
  // Globals are unpatched in runWithUdfRuntime
197
197
  }
198
198
  }
199
- export function runUdfQuery(docstore, fn, auth, storage, requestId, udfExecutor, componentPath) {
199
+ export function runUdfQuery(docstore, fn, auth, storage, requestId, udfExecutor, componentPath, snapshotOverride) {
200
200
  const tnow = Date.now();
201
201
  const seed = resolveSeed("query", requestId, tnow);
202
202
  const rng = udfRng(seed);
@@ -210,7 +210,7 @@ export function runUdfQuery(docstore, fn, auth, storage, requestId, udfExecutor,
210
210
  fetch: forbiddenAsyncOp("fetch"),
211
211
  setInterval: forbiddenAsyncOp("setInterval"),
212
212
  setTimeout: forbiddenAsyncOp("setTimeout"),
213
- }, auth, "query", storage, seed, undefined, udfExecutor, componentPath);
213
+ }, auth, "query", storage, seed, undefined, udfExecutor, componentPath, snapshotOverride);
214
214
  }
215
215
  export function runUdfMutation(docstore, fn, auth, storage, requestId, udfExecutor, componentPath) {
216
216
  const tnow = Date.now();
@@ -274,9 +274,11 @@ export function runUdfMutation(docstore, fn, auth, storage, requestId, udfExecut
274
274
  // execute within the same transaction scope
275
275
  const existingIdGenerator = idGeneratorContext.getStore();
276
276
  const idGenerator = existingIdGenerator ?? createDeterministicIdGenerator(seed);
277
- return transactionContext
278
- .run(parentTransaction, () => idGeneratorContext.run(idGenerator, () => runUdfAndGetLogs(docstore, fn, ops, auth, "mutation", storage, seed, parentTransaction, udfExecutor, componentPath)))
279
- .catch((error) => {
277
+ // ContextStorage.run returns R (UdfResult here) but in practice the async
278
+ // callback produces a Promise<UdfResult>. We need to attach a .catch for
279
+ // savepoint rollback, so cast to the runtime-accurate Promise type.
280
+ const nestedResult = transactionContext.run(parentTransaction, () => idGeneratorContext.run(idGenerator, () => runUdfAndGetLogs(docstore, fn, ops, auth, "mutation", storage, seed, parentTransaction, udfExecutor, componentPath)));
281
+ return nestedResult.catch((error) => {
280
282
  parentTransaction.restoreSavepoint(savepoint);
281
283
  throw error;
282
284
  });
@@ -12,5 +12,5 @@ export declare class Long {
12
12
  notEquals(other: Long): boolean;
13
13
  comp(other: Long): 1 | 0 | -1;
14
14
  lessThanOrEqual(other: Long): boolean;
15
- static fromValue(val: any): any;
15
+ static fromValue(val: any): Long;
16
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@concavejs/core",
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"