@gaganref/confect-test 10.3.1-fork.88 → 10.3.1-fork.89

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 (46) hide show
  1. package/dist/internal/Attempt.d.ts +77 -0
  2. package/dist/internal/Attempt.d.ts.map +1 -0
  3. package/dist/internal/Attempt.js +154 -0
  4. package/dist/internal/Attempt.js.map +1 -0
  5. package/dist/internal/ConvexTest.d.ts +34 -0
  6. package/dist/internal/ConvexTest.d.ts.map +1 -0
  7. package/dist/internal/ConvexTest.js +59 -0
  8. package/dist/internal/ConvexTest.js.map +1 -0
  9. package/dist/internal/Execution.d.ts +167 -0
  10. package/dist/internal/Execution.d.ts.map +1 -0
  11. package/dist/internal/Execution.js +790 -0
  12. package/dist/internal/Execution.js.map +1 -0
  13. package/dist/internal/Globals.d.ts +11 -0
  14. package/dist/internal/Globals.d.ts.map +1 -0
  15. package/dist/internal/Globals.js +76 -0
  16. package/dist/internal/Globals.js.map +1 -0
  17. package/dist/internal/Kernel.d.ts +93 -0
  18. package/dist/internal/Kernel.d.ts.map +1 -0
  19. package/dist/internal/Kernel.js +91 -0
  20. package/dist/internal/Kernel.js.map +1 -0
  21. package/dist/internal/KernelQuery.d.ts +55 -0
  22. package/dist/internal/KernelQuery.d.ts.map +1 -0
  23. package/dist/internal/KernelQuery.js +205 -0
  24. package/dist/internal/KernelQuery.js.map +1 -0
  25. package/dist/internal/KernelRefusal.d.ts +77 -0
  26. package/dist/internal/KernelRefusal.d.ts.map +1 -0
  27. package/dist/internal/KernelRefusal.js +73 -0
  28. package/dist/internal/KernelRefusal.js.map +1 -0
  29. package/dist/internal/KernelValues.d.ts +136 -0
  30. package/dist/internal/KernelValues.d.ts.map +1 -0
  31. package/dist/internal/KernelValues.js +266 -0
  32. package/dist/internal/KernelValues.js.map +1 -0
  33. package/dist/internal/ReadSet.d.ts +55 -0
  34. package/dist/internal/ReadSet.d.ts.map +1 -0
  35. package/dist/internal/ReadSet.js +29 -0
  36. package/dist/internal/ReadSet.js.map +1 -0
  37. package/package.json +3 -3
  38. package/src/internal/Attempt.ts +185 -0
  39. package/src/internal/ConvexTest.ts +118 -0
  40. package/src/internal/Execution.ts +1430 -0
  41. package/src/internal/Globals.ts +93 -0
  42. package/src/internal/Kernel.ts +190 -0
  43. package/src/internal/KernelQuery.ts +405 -0
  44. package/src/internal/KernelRefusal.ts +88 -0
  45. package/src/internal/KernelValues.ts +725 -0
  46. package/src/internal/ReadSet.ts +108 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Execution.js","names":["Globals.own","KernelQuery.exportSchema","Kernel.empty","Kernel.wallClock","KernelRefusal.RegisteredAfterOpen","Invocation.current","KernelRefusal.StaleAttempt","Invocation.bind","Kernel.conflict","KernelRefusal.OptimisticConcurrencyControlFailure","KernelRefusal.CommitTsNotIncreasing","Kernel.apply","KernelQuery.stream","KernelQuery.paginate","KernelRefusal.rowPending","KernelRefusal.requiresBinary","KernelRefusal.ClosedAttempt"],"sources":["../../src/internal/Execution.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport {\n actionGeneric,\n getFunctionAddress,\n mutationGeneric,\n queryGeneric,\n type FunctionReference,\n type GenericSchema,\n type SchemaDefinition,\n type UserIdentity,\n} from \"convex/server\";\nimport { convexToJson, jsonToConvex, type Value } from \"convex/values\";\nimport { KernelAttempt } from \"./Attempt.js\";\nimport * as Globals from \"./Globals.js\";\nimport * as Invocation from \"./Invocation.js\";\nimport * as Kernel from \"./Kernel.js\";\nimport * as KernelQuery from \"./KernelQuery.js\";\nimport * as KernelRefusal from \"./KernelRefusal.js\";\nimport type * as ReadSet from \"./ReadSet.js\";\nimport type {\n DocumentId,\n FunctionPath,\n StoredDocument,\n ValidatorJSON,\n} from \"./KernelValues.js\";\nimport {\n createFunctionHandle,\n createTestJwt,\n deserializeConvexErrorData,\n evaluateValue,\n hasPendingValues,\n parseArgs,\n parseFunctionHandle,\n resolveCommittedValues,\n simpleHash,\n tableNameFromId,\n validateFunctionArgs,\n validateReturnValue,\n} from \"./KernelValues.js\";\n\nconst ROOT = \"\";\nconst TYPICAL_CONVEX_ID_LENGTH = 32;\n\ntype Modules = Record<string, () => Promise<any>>;\n\n/**\n * One registered component: its schema and its function modules, each loaded\n * once when the world opens.\n */\ninterface Component {\n readonly path: string;\n readonly schema: KernelQuery.KernelSchema | null;\n readonly loaders: ReadonlyMap<string, () => Promise<any>>;\n readonly loaded: Map<string, any>;\n}\n\n/**\n * Who is calling: the identity and the request attributes a test accessor set.\n */\nexport interface Caller {\n readonly identity: UserIdentity | null;\n readonly token: string | null;\n readonly ip: string | null;\n readonly userAgent: string | null;\n}\n\nexport const anonymous: Caller = {\n identity: null,\n token: null,\n ip: null,\n userAgent: null,\n};\n\nexport const withIdentity = (\n caller: Caller,\n identity: Partial<UserIdentity>,\n): Caller => {\n const subject = identity.subject ?? \"\" + simpleHash(JSON.stringify(identity));\n const issuer = identity.issuer ?? \"https://convex.test\";\n const tokenIdentifier = identity.tokenIdentifier ?? `${issuer}|${subject}`;\n const full = { ...identity, subject, issuer, tokenIdentifier };\n return { ...caller, identity: full, token: createTestJwt(full) };\n};\n\ninterface Request {\n readonly ip: string | null;\n readonly userAgent: string | null;\n readonly requestId: string;\n readonly scheduledFunctionId: string | null;\n readonly authToken: string | null;\n}\n\ntype UdfType = \"query\" | \"mutation\" | \"action\";\n\n/**\n * How a prepared attempt's function ended.\n */\nexport type Outcome =\n | { readonly _tag: \"returned\"; readonly value: Value }\n | { readonly _tag: \"failed\"; readonly error: unknown };\n\n/**\n * A mutation attempt run to its commit point and held until `apply`.\n */\nexport interface HeldAttempt {\n readonly id: string;\n readonly request: string;\n readonly number: Invocation.Attempt;\n readonly snapshot: Kernel.Version;\n readonly reads: ReadonlyArray<ReadSet.Read>;\n readonly outcome: Outcome;\n}\n\n/**\n * What `apply` did with a held attempt. A conflict discards the attempt and\n * holds exactly one next attempt, run against the latest commit. Nothing is\n * retried until that one is applied in turn.\n */\nexport type KernelApply =\n | {\n readonly kind: \"applied\";\n readonly version: Kernel.Version;\n readonly commitTs: bigint;\n readonly result: Value;\n }\n | { readonly kind: \"conflict\"; readonly next: HeldAttempt }\n | {\n readonly kind: \"exhausted\";\n readonly error: KernelRefusal.OptimisticConcurrencyControlFailure;\n }\n | { readonly kind: \"refused\"; readonly tag: string; readonly error: unknown };\n\ninterface Held {\n readonly view: HeldAttempt;\n readonly attempt: KernelAttempt;\n readonly again: (number: Invocation.Attempt) => Promise<Held>;\n}\n\nconst lastAttempt: Invocation.Attempt = 5;\n\nconst tagOf = (error: unknown): string => {\n const tagged = (value: unknown): value is { readonly _tag: string } =>\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as { _tag?: unknown })._tag === \"string\";\n const data = (error as { data?: unknown } | null)?.data;\n if (tagged(data)) return data._tag;\n if (tagged(error)) return error._tag;\n return error instanceof Error ? error.name : \"Error\";\n};\n\n/**\n * One running function. Queries and mutations read and write through their\n * attempt. Every async syscall of a query or a mutation, nested calls included,\n * takes its turn on `turn` in the order the function made it.\n */\ninterface Execution {\n readonly world: World;\n readonly componentPath: string;\n readonly udfPath: string;\n readonly udfType: UdfType;\n readonly attempt: KernelAttempt | undefined;\n readonly identity: UserIdentity | null;\n readonly request: Request;\n readonly pagination: { calls: number } | undefined;\n readonly turn: Turn;\n}\n\n/**\n * A queue that runs one task at a time, in the order they were taken.\n */\nclass Turn {\n private tail: Promise<unknown> = Promise.resolve();\n\n take<A>(task: () => A | Promise<A>): Promise<A> {\n const result = this.tail.then(task);\n this.tail = result.then(\n () => undefined,\n () => undefined,\n );\n return result;\n }\n\n /**\n * Resolves once every task taken so far has settled, including the tasks\n * taken while waiting.\n */\n idle(): Promise<void> {\n const tail = this.tail;\n return tail.then(() => (this.tail === tail ? undefined : this.idle()));\n }\n}\n\n/**\n * A function's invocation finishes once its handler returned and every syscall\n * it started has run. On the binary a query or mutation keeps running the\n * syscalls in its queue after its promise resolves, then returns (`run_inner`\n * in `crates/isolate/src/environment/udf/mod.rs`, 1.49), so an unawaited write\n * still lands in its own transaction.\n */\nconst settled = <A>(execution: Execution, result: A): Promise<A> =>\n execution.turn.idle().then(() => result);\n\nconst executions = new AsyncLocalStorage<Execution>();\n\n/**\n * Run a function's code as `execution`, with its own copy of the globals a test\n * invocation pins.\n */\nconst enter = <A>(execution: Execution, run: () => A): A =>\n Globals.own(() => executions.run(execution, run));\nconst kernelBrand = Symbol.for(\"@confect/test/Kernel\");\n\nconst current = (): Execution => {\n const execution = executions.getStore();\n if (execution === undefined) {\n throw new Error(\n \"A Convex syscall ran outside any function the test kernel started.\",\n );\n }\n return execution;\n};\n\nlet nextRequestId = 0;\nconst newRequest = (caller: Caller): Request => ({\n ip: caller.ip,\n userAgent: caller.userAgent,\n requestId: `kernel-request-${nextRequestId++}`,\n scheduledFunctionId: null,\n authToken: caller.token,\n});\n\nconst findModulesRoot = (paths: ReadonlyArray<string>): string => {\n const generated = paths.find((path) => path.includes(\"_generated\"));\n if (generated === undefined) {\n throw new Error(\n 'Could not find the \"_generated\" directory, make sure to run ' +\n \"`npx convex dev` or `npx convex codegen`. Make sure your \" +\n '`import.meta.glob` includes the files in the \"_generated\" directory',\n );\n }\n return generated.split(\"_generated\", 2)[0]!;\n};\n\nconst makeComponent = (\n path: string,\n schema: SchemaDefinition<GenericSchema, boolean> | null | undefined,\n modules: Modules,\n): Component => {\n const root = findModulesRoot(Object.keys(modules));\n const relative = Object.entries(modules)\n .filter(([key]) => key.startsWith(root))\n .map(([key, load]) => [key.slice(root.length), load] as const);\n const nested = relative\n .map(([file]) => file)\n .filter((file) => file.endsWith(\"/convex.config.ts\"))\n .map((file) => file.slice(0, -\"convex.config.ts\".length));\n return {\n path,\n schema: KernelQuery.exportSchema(schema),\n loaders: new Map(\n relative\n .filter(\n ([file]) =>\n isFunctionModule(file) &&\n !nested.some((dir) => file.startsWith(dir)),\n )\n .map(([file, load]) => [file.replace(/\\.[^.]+$/, \"\"), load]),\n ),\n loaded: new Map(),\n };\n};\n\nconst entryExtensions = [\n \".js\",\n \".mjs\",\n \".cjs\",\n \".ts\",\n \".tsx\",\n \".mts\",\n \".cts\",\n \".jsx\",\n];\n\n/**\n * Whether Convex's bundler deploys this file as a function module, by the rule\n * `entryPoints` applies in `convex/src/bundler/index.ts` (1.49). A test file, a\n * schema, a config and `_generated` never reach the binary, so the kernel\n * neither loads them nor resolves a function in them.\n */\nconst isFunctionModule = (file: string): boolean => {\n const base = file.split(\"/\").pop()!;\n return (\n entryExtensions.some((extension) => file.endsWith(extension)) &&\n !file.startsWith(\"_generated/\") &&\n !base.startsWith(\".\") &&\n !base.startsWith(\"#\") &&\n base !== \"schema.ts\" &&\n base !== \"schema.js\" &&\n (base.match(/\\./g) ?? []).length <= 1 &&\n !file.includes(\" \")\n );\n};\n\nconst unregistered = (world: World, componentPath: string) => {\n const registered = [...world.components.keys()].filter((p) => p !== ROOT);\n return new Error(\n `Component \"${componentPath}\" is not registered on this test backend. ` +\n (registered.length === 0\n ? \"No components have been registered.\"\n : `Registered components: ${registered.map((p) => `\"${p}\"`).join(\", \")}.`),\n );\n};\n\ntype FunctionAddress = {\n readonly name?: string | undefined;\n readonly reference?: string | undefined;\n readonly functionHandle?: string | undefined;\n};\n\n/**\n * Where an address points, read from the calling component.\n */\nconst functionPathOf = (\n address: FunctionAddress,\n from: string,\n): FunctionPath => {\n if (address.functionHandle !== undefined) {\n return parseFunctionHandle(address.functionHandle) as FunctionPath;\n }\n if (address.name !== undefined) {\n return { udfPath: address.name, componentPath: from };\n }\n if (address.reference !== undefined) {\n // \"_reference/childComponent/<child>/path/to/file/fn\"\n const parts = address.reference.split(\"/\");\n const child = parts[2]!;\n const rest = parts.slice(3);\n return {\n componentPath: from.length > 0 ? `${from}/${child}` : child,\n udfPath: `${rest.slice(0, -1).join(\"/\")}:${rest[rest.length - 1]}`,\n };\n }\n throw new Error(\"Function address not supported\");\n};\n\nconst pathOfReference = (\n reference: FunctionReference<any, any, any, any> | string,\n from: string,\n) =>\n functionPathOf(getFunctionAddress(reference as any) as FunctionAddress, from);\n\ninterface Resolved {\n readonly func: any;\n readonly handler: (ctx: any, args: any) => any;\n readonly args: ValidatorJSON;\n readonly returns: ValidatorJSON | null;\n}\n\nconst kindCheck = {\n query: \"isQuery\",\n mutation: \"isMutation\",\n action: \"isAction\",\n} as const;\n\n/**\n * A test backend: its registered components and the kernel state they share.\n */\nexport class World {\n readonly components = new Map<string, Component>();\n state: Kernel.State = Kernel.empty;\n private opened: Promise<void> | undefined;\n private nextDocId = 10000;\n private lastCreationTime = 0;\n private nextQueryId = 1;\n private readonly queries = new Map<number, Iterator<any>>();\n private readonly holding = new Map<string, Held>();\n private nextAttemptId = 1;\n\n constructor(\n schema: SchemaDefinition<GenericSchema, boolean> | null | undefined,\n modules: Modules,\n private readonly runtime: Kernel.KernelRuntime = Kernel.wallClock(),\n ) {\n installConvexGlobal();\n this.components.set(ROOT, makeComponent(ROOT, schema, modules));\n }\n\n register(\n componentPath: string,\n schema: SchemaDefinition<GenericSchema, boolean>,\n modules: Modules,\n ) {\n if (this.opened !== undefined) {\n throw new KernelRefusal.RegisteredAfterOpen({\n componentPath,\n message: `Component \"${componentPath}\" was registered after the test backend opened. Register every component before the first call.`,\n });\n }\n this.components.set(\n componentPath,\n makeComponent(componentPath, schema, modules),\n );\n }\n\n /**\n * Load every registered module of every component, once, before any function\n * runs.\n */\n open(): Promise<void> {\n this.opened ??= Promise.all(\n Array.from(this.components.values(), (component) =>\n Promise.all(\n Array.from(component.loaders, ([path, load]) =>\n load().then((module) => component.loaded.set(path, module)),\n ),\n ),\n ),\n ).then(() => undefined);\n return this.opened;\n }\n\n private component(componentPath: string): Component {\n const component = this.components.get(componentPath);\n if (component === undefined) throw unregistered(this, componentPath);\n return component;\n }\n\n private resolve(functionPath: FunctionPath, kind: UdfType | \"any\"): Resolved {\n const [modulePath, maybeExport] = functionPath.udfPath.split(\":\") as [\n string,\n string | undefined,\n ];\n const exportName = maybeExport ?? \"default\";\n const component = this.component(functionPath.componentPath);\n const module = component.loaded.get(modulePath);\n if (module === undefined) {\n throw new Error(`Could not find module for: \"${modulePath}\"`);\n }\n const func = module[exportName];\n if (func === undefined) {\n throw new Error(\n `Expected a Convex function exported from module \"${modulePath}\" as \\`${exportName}\\`, but there is no such export.`,\n );\n }\n const handler = \"_handler\" in func ? func._handler : func;\n if (typeof handler !== \"function\") {\n throw new Error(\n `Expected a Convex function exported from module \"${modulePath}\" as \\`${exportName}\\`, but got: ${func}`,\n );\n }\n if (kind !== \"any\" && !func[kindCheck[kind]]) {\n throw new Error(\n `Expected a ${kind} function, but the function exported from module \"${modulePath}\" as \\`${exportName}\\` is not a ${kind}.`,\n );\n }\n const args = JSON.parse(func.exportArgs()) as ValidatorJSON;\n if (args.type !== \"object\" && args.type !== \"any\") {\n throw new Error(\n `Invalid JSON returned from ${modulePath}.js:${exportName}.exportArgs(): ` +\n `Args validator must be an object or any`,\n );\n }\n return { func, handler, args, returns: JSON.parse(func.exportReturns()) };\n }\n\n // Calls from the test.\n\n query(caller: Caller, reference: any, args: any): Promise<any> {\n return this.open().then(() => {\n const from = { caller, request: newRequest(caller) };\n return typeof reference === \"function\"\n ? this.runQuery(\n { componentPath: ROOT, udfPath: \"inline\" },\n { handler: reference, args: { type: \"any\" }, returns: null },\n args ?? {},\n from,\n )\n : this.queryAt(pathOfReference(reference, ROOT), args, from);\n });\n }\n\n mutation(caller: Caller, reference: any, args: any): Promise<any> {\n return this.open().then(() => {\n const from = { caller, request: newRequest(caller) };\n return typeof reference === \"function\"\n ? this.runMutation(\n { componentPath: ROOT, udfPath: \"inline\" },\n { handler: reference, args: { type: \"any\" }, returns: null },\n args ?? {},\n from,\n )\n : this.mutationAt(pathOfReference(reference, ROOT), args, from);\n });\n }\n\n action(caller: Caller, reference: any, args: any): Promise<any> {\n return this.open().then(() => {\n const from = { caller, request: newRequest(caller) };\n return typeof reference === \"function\"\n ? this.runAction(\n { componentPath: ROOT, udfPath: \"inline\" },\n { handler: reference, args: { type: \"any\" }, returns: null },\n args ?? {},\n from,\n )\n : this.actionAt(pathOfReference(reference, ROOT), args, from);\n });\n }\n\n run(\n caller: Caller,\n componentPath: string,\n handler: (ctx: any) => any,\n ): Promise<any> {\n return this.open().then(() => {\n this.component(componentPath);\n return this.runMutation(\n { componentPath, udfPath: \"custom\" },\n { handler, args: { type: \"any\" }, returns: null },\n {},\n { caller, request: newRequest(caller) },\n );\n });\n }\n\n // Held attempts.\n\n /**\n * Run a mutation to its commit point and hold it as attempt 1.\n */\n prepare(caller: Caller, reference: any, args: any): Promise<HeldAttempt> {\n return this.open().then(() => {\n const functionPath = pathOfReference(reference, ROOT);\n const resolved = this.resolve(functionPath, \"mutation\");\n validateFunctionArgs(resolved.args, args ?? {}, functionPath, false);\n return this.prepareMutation(\n functionPath,\n resolved,\n args,\n { caller, request: newRequest(caller) },\n 1,\n Invocation.current(),\n ).then((held) => held.view);\n });\n }\n\n apply(id: string): Promise<KernelApply> {\n const held = this.holding.get(id);\n return held === undefined\n ? Promise.reject(\n new KernelRefusal.StaleAttempt({\n id,\n message: `The test kernel holds no attempt \"${id}\". It was already applied, or never prepared.`,\n }),\n )\n : this.applyHeld(held);\n }\n\n /**\n * The held attempts, oldest first.\n */\n held(): ReadonlyArray<HeldAttempt> {\n return Array.from(this.holding.values(), (held) => held.view);\n }\n\n // Calls by address, from the test or from a running function.\n\n private queryAt(\n functionPath: FunctionPath,\n args: any,\n from: From,\n snapshotOnly = false,\n ) {\n const resolved = this.resolve(functionPath, \"query\");\n validateFunctionArgs(\n resolved.args,\n args ?? {},\n functionPath,\n from.parent?.attempt !== undefined,\n );\n return this.runQuery(functionPath, resolved, args, from, snapshotOnly);\n }\n\n private mutationAt(functionPath: FunctionPath, args: any, from: From) {\n const resolved = this.resolve(functionPath, \"mutation\");\n validateFunctionArgs(\n resolved.args,\n args ?? {},\n functionPath,\n from.parent?.attempt !== undefined,\n );\n return this.runMutation(functionPath, resolved, args, from);\n }\n\n private actionAt(functionPath: FunctionPath, args: any, from: From) {\n const resolved = this.resolve(functionPath, \"action\");\n validateFunctionArgs(resolved.args, args ?? {}, functionPath, false);\n return this.runAction(functionPath, resolved, args, from);\n }\n\n // Runners.\n\n private execution(\n functionPath: FunctionPath,\n udfType: UdfType,\n attempt: KernelAttempt | undefined,\n from: From,\n pagination: { calls: number } | undefined,\n ): Execution {\n // A function in a component runs with no identity, whoever called it, as\n // Convex gives a component no `ctx.auth` of the caller's. A nested call in\n // the host takes its parent's identity, even when that is none.\n const identity =\n functionPath.componentPath !== ROOT\n ? null\n : from.parent !== undefined\n ? from.parent.identity\n : from.caller.identity;\n return {\n world: this,\n componentPath: functionPath.componentPath,\n udfPath: functionPath.udfPath,\n udfType,\n attempt,\n identity,\n request: from.request,\n pagination,\n turn: new Turn(),\n };\n }\n\n private runQuery(\n functionPath: FunctionPath,\n resolved: Pick<Resolved, \"handler\" | \"args\" | \"returns\">,\n args: any,\n from: From,\n snapshotOnly = false,\n ): Promise<any> {\n const parentAttempt = from.parent?.attempt;\n const isNested = parentAttempt !== undefined;\n const attempt =\n parentAttempt === undefined\n ? new KernelAttempt(this.state)\n : snapshotOnly\n ? new KernelAttempt(parentAttempt.snapshot)\n : parentAttempt;\n const execution = this.execution(\n functionPath,\n \"query\",\n attempt,\n from,\n (isNested && from.parent?.pagination) || { calls: 0 },\n );\n const q = queryGeneric({\n handler: (ctx: any, a: any) =>\n resolved.handler({ ...ctx, auth: queryAuth(execution) }, a),\n }) as unknown as { invokeQuery: (args: string) => Promise<string> };\n return enter(execution, () =>\n q.invokeQuery(JSON.stringify(convexToJson([parseArgs(args)]))),\n )\n .then((raw) => settled(execution, raw))\n .then((raw) => {\n const result = jsonToConvex(JSON.parse(raw));\n if (!isNested && hasPendingValues(result)) {\n throw new Error(\n `Function ${functionPath.udfPath} return value invalid: queries ` +\n `cannot return an unresolved placeholder value.`,\n );\n }\n validateReturnValue(resolved.returns, result, \"query\", functionPath);\n return result;\n })\n .catch((error: unknown) => {\n throw deserializeConvexErrorData(error);\n });\n }\n\n private invokeMutation(\n execution: Execution,\n resolved: Pick<Resolved, \"handler\" | \"returns\">,\n args: any,\n ): Promise<Value> {\n const m = mutationGeneric({\n handler: (ctx: any, a: any) =>\n resolved.handler({ ...ctx, auth: mutationAuth(execution) }, a),\n }) as unknown as { invokeMutation: (args: string) => Promise<string> };\n return enter(execution, () =>\n m.invokeMutation(JSON.stringify(convexToJson([parseArgs(args)]))),\n )\n .then((raw) => settled(execution, raw))\n .then((raw) => {\n const result = jsonToConvex(JSON.parse(raw));\n validateReturnValue(resolved.returns, result, \"mutation\", {\n componentPath: execution.componentPath,\n udfPath: execution.udfPath,\n });\n return result;\n });\n }\n\n private runMutation(\n functionPath: FunctionPath,\n resolved: Pick<Resolved, \"handler\" | \"args\" | \"returns\">,\n args: any,\n from: From,\n ): Promise<any> {\n const parentAttempt = from.parent?.attempt;\n if (parentAttempt !== undefined) {\n const frame = parentAttempt.child();\n const execution = this.execution(\n functionPath,\n \"mutation\",\n frame,\n from,\n undefined,\n );\n // As at the top level, a nested mutation ends once its function has\n // returned and every syscall it started has settled. Convex runs a\n // nested function's syscall queue to the end before it commits its\n // subtransaction, so a detached fiber's late write lands in this frame\n // and merges with it. A failed one ends at once and rolls back.\n return this.invokeMutation(execution, resolved, args).then(\n (result) =>\n frame.drained().then(() => {\n frame.close();\n frame.merge();\n return result;\n }),\n (error: unknown) => {\n frame.close();\n throw deserializeConvexErrorData(error);\n },\n );\n }\n return this.prepareMutation(\n functionPath,\n resolved,\n args,\n from,\n 1,\n Invocation.current(),\n ).then((held) => this.publish(held));\n }\n\n /**\n * Run one attempt of a top-level mutation against the latest commit, then\n * hold it. The commit point is once the function has returned and every\n * syscall it started has settled. A test invocation bound when the mutation\n * was first called reaches each attempt's handler with that attempt's\n * number.\n */\n private prepareMutation(\n functionPath: FunctionPath,\n resolved: Pick<Resolved, \"handler\" | \"returns\">,\n args: any,\n from: From,\n number: Invocation.Attempt,\n bound: Invocation.Invocation | undefined,\n ): Promise<Held> {\n const attempt = new KernelAttempt(this.state, number);\n const execution = this.execution(\n functionPath,\n \"mutation\",\n attempt,\n from,\n undefined,\n );\n const run = () => this.invokeMutation(execution, resolved, args);\n const started =\n bound === undefined\n ? run()\n : Invocation.bind({ ...bound, attempt: number }, run);\n return started\n .then(\n (value) =>\n attempt.drained().then((): Outcome => ({ _tag: \"returned\", value })),\n (error: unknown): Outcome => ({\n _tag: \"failed\",\n error: deserializeConvexErrorData(error),\n }),\n )\n .then((outcome) => {\n attempt.close();\n const held: Held = {\n view: {\n id: `attempt-${this.nextAttemptId++}`,\n request: from.request.requestId,\n number,\n snapshot: attempt.snapshot.version,\n reads: attempt.reads,\n outcome,\n },\n attempt,\n again: (next) =>\n this.prepareMutation(\n functionPath,\n resolved,\n args,\n from,\n next,\n bound,\n ),\n };\n this.holding.set(held.view.id, held);\n return held;\n });\n }\n\n /**\n * Validate a held attempt's reads against every commit since its snapshot,\n * then publish its writes or prepare its next attempt. An attempt that wrote\n * nothing publishes nothing and has nothing to validate. It answers its\n * snapshot's version and commit timestamp.\n */\n private applyHeld({ view, attempt, again }: Held): Promise<KernelApply> {\n this.holding.delete(view.id);\n const { outcome } = view;\n if (outcome._tag === \"failed\") {\n return Promise.resolve({\n kind: \"refused\",\n tag: tagOf(outcome.error),\n error: outcome.error,\n });\n }\n const writes = attempt.writes();\n if (writes.length === 0) {\n // As on the binary, a mutation that wrote nothing is serialized at its\n // snapshot and allocates no timestamp for a later commit.\n const { version, commitTs } = attempt.snapshot;\n return Promise.resolve({\n kind: \"applied\",\n version,\n commitTs,\n result: resolveCommittedValues(outcome.value, commitTs),\n });\n }\n if (\n Kernel.conflict(this.state, view.snapshot, attempt.reads) !== undefined\n ) {\n if (view.number === lastAttempt) {\n return Promise.resolve({\n kind: \"exhausted\",\n error: new KernelRefusal.OptimisticConcurrencyControlFailure({\n attempts: lastAttempt,\n message: `Documents read by the mutation changed before each of its ${lastAttempt} attempts could commit.`,\n }),\n });\n }\n return again((view.number + 1) as Invocation.Attempt).then(\n (next): KernelApply => ({ kind: \"conflict\", next: next.view }),\n );\n }\n const commitTs = this.runtime.commitTs(this.state.version + 1);\n if (commitTs <= this.state.commitTs) {\n return Promise.reject(\n new KernelRefusal.CommitTsNotIncreasing({\n version: this.state.version + 1,\n previous: this.state.commitTs,\n commitTs,\n message: `The runtime answered commit timestamp ${commitTs} for version ${this.state.version + 1}, which is not greater than the previous commit's ${this.state.commitTs}.`,\n }),\n );\n }\n this.state = Kernel.apply(this.state, writes, commitTs);\n return Promise.resolve({\n kind: \"applied\",\n version: this.state.version,\n commitTs,\n result: resolveCommittedValues(outcome.value, commitTs),\n });\n }\n\n /**\n * Apply until the mutation publishes, is refused or is exhausted, as the\n * binary retries a mutation that conflicts.\n */\n private publish(held: Held): Promise<Value> {\n return this.applyHeld(held).then((applied) => {\n if (applied.kind === \"applied\") return applied.result;\n if (applied.kind === \"conflict\") {\n return this.publish(this.holding.get(applied.next.id)!);\n }\n throw applied.error;\n });\n }\n\n private runAction(\n functionPath: FunctionPath,\n resolved: Pick<Resolved, \"handler\" | \"args\" | \"returns\">,\n args: any,\n from: From,\n ): Promise<any> {\n const execution = this.execution(\n functionPath,\n \"action\",\n undefined,\n from,\n undefined,\n );\n const inner: From = { request: from.request, parent: execution };\n const a = actionGeneric({\n handler: (ctx: any, innerArgs: any) =>\n resolved.handler(\n {\n ...ctx,\n runQuery: (reference: any, queryArgs: any) =>\n this.queryAt(\n pathOfReference(reference, functionPath.componentPath),\n queryArgs,\n inner,\n ),\n runMutation: (reference: any, mutationArgs: any) =>\n this.mutationAt(\n pathOfReference(reference, functionPath.componentPath),\n mutationArgs,\n inner,\n ),\n runAction: (reference: any, actionArgs: any) =>\n this.actionAt(\n pathOfReference(reference, functionPath.componentPath),\n actionArgs,\n inner,\n ),\n auth: queryAuth(execution),\n },\n innerArgs,\n ),\n }) as unknown as {\n invokeAction: (requestId: string, args: string) => Promise<string>;\n };\n const run = () =>\n enter(execution, () =>\n a.invokeAction(\n from.request.requestId,\n JSON.stringify(convexToJson([parseArgs(args)])),\n ),\n );\n // An action another function calls is an invocation of its own, with its\n // world's services, a start time read from its world's clock and its\n // world's random stream, as a scheduled job is.\n const bound = from.parent === undefined ? undefined : Invocation.current();\n const { ip, userAgent, requestId, scheduledFunctionId } = from.request;\n const started =\n bound === undefined\n ? run()\n : Invocation.bind(\n {\n world: bound.world,\n componentPath: functionPath.componentPath,\n attempt: 1,\n request: { ip, userAgent, requestId, scheduledFunctionId },\n services: bound.world.services,\n startedAt: bound.world.clock(),\n random: bound.world.random,\n },\n run,\n );\n return started\n .then((raw) => {\n const result = jsonToConvex(JSON.parse(raw));\n validateReturnValue(resolved.returns, result, \"action\", functionPath);\n return result;\n })\n .catch((error: unknown) => {\n throw deserializeConvexErrorData(error);\n });\n }\n\n // Syscalls.\n\n private schema(componentPath: string) {\n return this.component(componentPath).schema;\n }\n\n private view(execution: Execution): KernelQuery.TableView {\n const attempt = transaction(execution);\n return {\n schema: this.schema(execution.componentPath),\n scan: (tableName) => attempt.scan(execution.componentPath, tableName),\n read: (interval, after) =>\n attempt.readInterval({\n ...interval,\n componentPath: execution.componentPath,\n after,\n }),\n };\n }\n\n private generateId(table: string): DocumentId {\n const counter = String(this.nextDocId++).padStart(\n TYPICAL_CONVEX_ID_LENGTH - table.length,\n \"0\",\n );\n return (counter + table) as DocumentId;\n }\n\n syscall(op: string, jsonArgs: string): string {\n const args = JSON.parse(jsonArgs);\n const execution = current();\n if (execution.attempt?.closed === true) throw closed(execution, op);\n switch (op) {\n case \"1.0/getSnapshotTs\":\n return JSON.stringify(\n convexToJson(transaction(execution).snapshot.commitTs),\n );\n case \"1.0/queryStream\": {\n // The binary reads a query at each `1.0/queryStreamNext`, which waits\n // its turn in the queue, so the stream opens at its first read and sees\n // every write made before it.\n const queryId = this.nextQueryId++;\n const view = this.view(execution);\n let results: Iterator<any> | undefined;\n this.queries.set(queryId, {\n next: () => (results ??= KernelQuery.stream(view, args.query)).next(),\n });\n return JSON.stringify({ queryId });\n }\n case \"1.0/queryCleanup\":\n this.queries.delete(args.queryId);\n return JSON.stringify({});\n case \"1.0/db/normalizeId\": {\n const tableName = tableNameFromId(args.idString);\n return JSON.stringify({\n id: tableName === args.table ? args.idString : null,\n });\n }\n default:\n throw new Error(`The test kernel does not support syscall: \"${op}\"`);\n }\n }\n\n /**\n * The binary queues a query's or mutation's async syscalls and runs them one\n * at a time, oldest first (`start_async_syscall` and `run_inner` in\n * `crates/isolate/src/environment/udf/mod.rs`, 1.49). A write and a nested\n * call never share a batch (`AsyncSyscallBatch::can_push` in\n * `async_syscall.rs`), and a nested call holds the queue until it has\n * committed or rolled back its subtransaction (`run_udf` in\n * `async_syscall.rs`). So a caller's write made after its nested call runs\n * after that call, and a nested mutation sees every write made before it. An\n * action's calls run side by side.\n */\n asyncSyscall(op: string, jsonArgs: string): Promise<string> {\n const execution = current();\n const attempt = execution.attempt;\n if (attempt === undefined) {\n return Promise.resolve().then(() =>\n this.dispatchAsync(op, JSON.parse(jsonArgs), execution),\n );\n }\n if (attempt.closed) return Promise.reject(closed(execution, op));\n // A syscall counts toward its frame's lifetime from the moment it is\n // queued, so a frame never closes with a write still waiting its turn.\n const end = attempt.begin();\n return execution.turn\n .take(() => this.dispatchAsync(op, JSON.parse(jsonArgs), execution))\n .finally(end);\n }\n\n private dispatchAsync(\n op: string,\n args: any,\n execution: Execution,\n ): string | Promise<string> {\n switch (op) {\n case \"1.0/get\": {\n const { table, id } = args;\n return JSON.stringify(convexToJson(this.get(execution, table, id)));\n }\n case \"1.0/queryStreamNext\": {\n const results = this.queries.get(args.queryId);\n if (results === undefined) throw new Error(\"Bad queryId\");\n const { value, done } = results.next();\n return JSON.stringify(\n convexToJson(\n done ? { value: null, done: true } : { value, done: false },\n ),\n );\n }\n case \"1.0/queryPage\": {\n const pagination = execution.pagination;\n if (pagination) {\n pagination.calls += 1;\n if (pagination.calls > 1) {\n throw new Error(\n \"Only a single paginated query (`.paginate()`) is allowed per \" +\n \"query, including nested query calls and component calls. \" +\n \"This is a Convex limit: https://docs.convex.dev/database/pagination\",\n );\n }\n }\n return JSON.stringify(\n convexToJson(KernelQuery.paginate(this.view(execution), args) as any),\n );\n }\n case \"1.0/insert\":\n return JSON.stringify({\n _id: this.insert(execution, args.table, jsonToConvex(args.value)),\n });\n case \"1.0/shallowMerge\":\n this.patch(execution, args.table, args.id, args.value);\n return JSON.stringify({});\n case \"1.0/replace\":\n this.replace(execution, args.table, args.id, args.value);\n return JSON.stringify({});\n case \"1.0/remove\":\n this.remove(execution, args.table, args.id);\n return JSON.stringify({});\n case \"1.0/count\": {\n const attempt = transaction(execution);\n attempt.readInterval({\n kind: \"interval\",\n componentPath: execution.componentPath,\n table: args.table,\n fields: [\"_creationTime\", \"_id\"],\n order: \"asc\",\n range: [],\n after: null,\n })(\"end\");\n return JSON.stringify(\n attempt.scan(execution.componentPath, args.table).length,\n );\n }\n case \"1.0/getFunctionMetadata\":\n return JSON.stringify(\n convexToJson({\n name: execution.udfPath,\n componentPath: execution.componentPath,\n }),\n );\n case \"1.0/getRequestMetadata\":\n if (execution.udfType === \"query\") {\n throw new Error(\n \"getRequestMetadata() can only be called from a mutation, action \" +\n \"or HTTP action. It is not available in queries.\",\n );\n }\n return JSON.stringify(convexToJson(execution.request as any));\n case \"1.0/getDeploymentMetadata\":\n return JSON.stringify(\n convexToJson({ name: \"test\", region: null, class: \"s16\" }),\n );\n case \"1.0/actions/query\":\n case \"1.0/actions/mutation\":\n case \"1.0/actions/action\": {\n const from: From = { request: execution.request, parent: execution };\n const functionPath = functionPathOf(args, execution.componentPath);\n const run =\n op === \"1.0/actions/query\"\n ? this.queryAt(functionPath, args.args, from)\n : op === \"1.0/actions/mutation\"\n ? this.mutationAt(functionPath, args.args, from)\n : this.actionAt(functionPath, args.args, from);\n return run.then((value) => JSON.stringify(convexToJson(value)));\n }\n case \"1.0/runUdf\": {\n const { udfType, args: udfArgs } = args;\n const from: From = { request: execution.request, parent: execution };\n const functionPath = functionPathOf(args, execution.componentPath);\n const value = jsonToConvex(udfArgs);\n const run =\n udfType === \"query\"\n ? this.queryAt(functionPath, value, from)\n : udfType === \"snapshotQuery\"\n ? this.queryAt(functionPath, value, from, true)\n : udfType === \"mutation\"\n ? this.mutationAt(functionPath, value, from)\n : Promise.reject(\n new Error(\n `The test kernel does not support udf type: \"${udfType}\"`,\n ),\n );\n return run.then((result) => JSON.stringify(convexToJson(result)));\n }\n case \"1.0/createFunctionHandle\": {\n const functionPath = functionPathOf(args, execution.componentPath);\n this.component(functionPath.componentPath);\n return JSON.stringify(createFunctionHandle(functionPath));\n }\n case \"1.0/auditLog\":\n return JSON.stringify(null);\n case \"1.0/schedule\":\n case \"1.0/actions/schedule\":\n case \"1.0/cancel_job\":\n case \"1.0/actions/cancel_job\":\n throw KernelRefusal.rowPending(\"the scheduler\", 5);\n case \"1.0/storageDelete\":\n case \"1.0/storageGetUrl\":\n case \"1.0/storageGenerateUploadUrl\":\n throw KernelRefusal.rowPending(\"storage\", 6);\n case \"1.0/getTransactionMetrics\":\n throw KernelRefusal.rowPending(\"transaction limits\", 6);\n case \"1.0/actions/vectorSearch\":\n throw KernelRefusal.requiresBinary(\"vectorSearch\");\n default:\n throw new Error(\n `The test kernel does not support async syscall: \"${op}\"`,\n );\n }\n }\n\n jsSyscall(op: string): Promise<never> {\n return Promise.reject(\n op.startsWith(\"storage/\")\n ? KernelRefusal.rowPending(\"storage\", 6)\n : new Error(`The test kernel does not support js syscall: \"${op}\"`),\n );\n }\n\n // Documents. The checks and messages are convex-test's.\n\n private get(execution: Execution, tableName: unknown, id: unknown) {\n validateId(tableName, id);\n const attempt = transaction(execution);\n attempt.readDocument(execution.componentPath, id);\n return attempt.get(execution.componentPath, id);\n }\n\n private insert(execution: Execution, table: string, value: any): DocumentId {\n const attempt = transaction(execution);\n KernelQuery.validateDocument(\n this.schema(execution.componentPath),\n table,\n value,\n );\n const _id = this.generateId(table);\n const now = this.runtime.now();\n const _creationTime =\n now <= this.lastCreationTime ? this.lastCreationTime + 0.001 : now;\n this.lastCreationTime = _creationTime;\n attempt.write(execution.componentPath, _id, {\n ...value,\n _id,\n _creationTime,\n });\n return _id;\n }\n\n private existing(\n execution: Execution,\n tableName: unknown,\n id: unknown,\n write: string,\n value: unknown,\n ): StoredDocument {\n validateId(tableName, id);\n if (value !== undefined && typeof value !== \"object\") {\n throw new Error(\n `Invalid argument \\`value\\` in \\`db.${write}\\`, expected object but got '${typeof value}': ${value as any}`,\n );\n }\n const attempt = transaction(execution);\n attempt.readDocument(execution.componentPath, id);\n const document = attempt.get(execution.componentPath, id);\n if (document === null) {\n throw new Error(\n write === \"delete\"\n ? \"Delete on non-existent doc\"\n : `${write === \"patch\" ? \"Patch\" : \"Replace\"} on non-existent document with ID \"${id}\"`,\n );\n }\n return document;\n }\n\n private fields(document: StoredDocument, value: Record<string, any>) {\n if (value._id !== undefined && value._id !== document._id) {\n throw new Error(\n `Provided \\`_id\\` field value \"${value._id}\" ` +\n `does not match the document ID \"${document._id}\"`,\n );\n }\n if (\n value._creationTime !== undefined &&\n value._creationTime !== document._creationTime\n ) {\n throw new Error(\n `Provided \\`_creationTime\\` field value ${value._creationTime} ` +\n `does not match the document's creation time ${document._creationTime}`,\n );\n }\n const convexValue: Record<string, Value | undefined> = {};\n for (const [key, v] of Object.entries(value)) {\n if (key !== \"_id\" && key !== \"_creationTime\") {\n convexValue[key] = evaluateValue(v);\n }\n }\n return convexValue;\n }\n\n private patch(\n execution: Execution,\n tableName: unknown,\n id: unknown,\n value: Record<string, any>,\n ) {\n const document = this.existing(execution, tableName, id, \"patch\", value);\n const { _id, _creationTime, ...fields } = document;\n const merged = { ...fields, ...this.fields(document, value) };\n KernelQuery.validateDocument(\n this.schema(execution.componentPath),\n tableNameFromId(_id)!,\n merged,\n );\n transaction(execution).write(execution.componentPath, _id, {\n _id,\n _creationTime,\n ...merged,\n } as StoredDocument);\n }\n\n private replace(\n execution: Execution,\n tableName: unknown,\n id: unknown,\n value: Record<string, any>,\n ) {\n const document = this.existing(execution, tableName, id, \"replace\", value);\n const fields = this.fields(document, value);\n KernelQuery.validateDocument(\n this.schema(execution.componentPath),\n tableNameFromId(document._id)!,\n fields,\n );\n transaction(execution).write(execution.componentPath, document._id, {\n ...fields,\n _id: document._id,\n _creationTime: document._creationTime,\n } as StoredDocument);\n }\n\n private remove(execution: Execution, tableName: unknown, id: unknown) {\n const document = this.existing(\n execution,\n tableName,\n id,\n \"delete\",\n undefined,\n );\n transaction(execution).write(execution.componentPath, document._id, null);\n }\n}\n\n/**\n * Where a call comes from. A call from the test carries its accessor's caller.\n * A nested call carries its parent execution and takes its identity from it.\n */\ntype From =\n | {\n readonly caller: Caller;\n readonly request: Request;\n readonly parent?: undefined;\n }\n | { readonly parent: Execution; readonly request: Request };\n\nconst closed = (execution: Execution, operation: string) =>\n new KernelRefusal.ClosedAttempt({\n operation,\n message: `\"${operation}\" reached mutation ${execution.udfPath} after it returned and its syscalls settled. Await every read and write inside the handler.`,\n });\n\nconst transaction = (execution: Execution): KernelAttempt => {\n if (execution.attempt === undefined) {\n throw new Error(\n \"The database is only available in queries and mutations. An action reads and writes through `ctx.runQuery` and `ctx.runMutation`.\",\n );\n }\n return execution.attempt;\n};\n\nconst queryAuth = (execution: Execution) => ({\n getUserIdentity: () => Promise.resolve(execution.identity),\n});\n\nconst mutationAuth = (execution: Execution) => ({\n ...queryAuth(execution),\n signJwt: () => Promise.reject(KernelRefusal.rowPending(\"JWT signing\", 6)),\n});\n\nfunction validateId(\n expectedTableName: unknown,\n id: unknown,\n): asserts id is DocumentId {\n if (typeof id !== \"string\") {\n throw new Error(\n `Invalid argument \\`id\\`, expected string but got '${typeof id}': ${id as any}`,\n );\n }\n if (expectedTableName === undefined) return;\n if (typeof expectedTableName !== \"string\") {\n throw new Error(\n `Invalid argument \\`tableName\\`, expected string but got '${typeof expectedTableName}': ${expectedTableName as any}`,\n );\n }\n const actualTableName = tableNameFromId(id);\n if (actualTableName === null) {\n throw new Error(\n `Invalid argument \\`id\\`, expected ID value but got '${id}'`,\n );\n }\n if (actualTableName !== expectedTableName) {\n throw new Error(\n `Invalid argument \\`id\\`, expected ID in table '${expectedTableName}' but got ID in table '${actualTableName}'`,\n );\n }\n}\n\n/**\n * Convex's server library reaches the backend through `globalThis.Convex`. The\n * kernel answers each syscall for the function that made it.\n */\nconst installConvexGlobal = () => {\n const global = globalThis as { Convex?: { [kernelBrand]?: true } };\n if (global.Convex?.[kernelBrand] === true) return;\n global.Convex = {\n [kernelBrand]: true,\n syscall: (op: string, args: string) => current().world.syscall(op, args),\n asyncSyscall: (op: string, args: string) =>\n current().world.asyncSyscall(op, args),\n jsSyscall: (op: string) => current().world.jsSyscall(op),\n } as any;\n};\n\n/**\n * Whether `globalThis.Convex` is the kernel's, so no other backend answered.\n */\nexport const ownsConvexGlobal = (): boolean =>\n (globalThis as { Convex?: { [kernelBrand]?: true } }).Convex?.[\n kernelBrand\n ] === true;\n"],"mappings":";;;;;;;;;;;AAwCA,MAAM,OAAO;AACb,MAAM,2BAA2B;AAyBjC,MAAa,YAAoB;CAC/B,UAAU;CACV,OAAO;CACP,IAAI;CACJ,WAAW;AACb;AAEA,MAAa,gBACX,QACA,aACW;CACX,MAAM,UAAU,SAAS,WAAW,KAAK,WAAW,KAAK,UAAU,QAAQ,CAAC;CAC5E,MAAM,SAAS,SAAS,UAAU;CAClC,MAAM,kBAAkB,SAAS,mBAAmB,GAAG,OAAO,GAAG;CACjE,MAAM,OAAO;EAAE,GAAG;EAAU;EAAS;EAAQ;CAAgB;CAC7D,OAAO;EAAE,GAAG;EAAQ,UAAU;EAAM,OAAO,cAAc,IAAI;CAAE;AACjE;AAwDA,MAAM,cAAkC;AAExC,MAAM,SAAS,UAA2B;CACxC,MAAM,UAAU,UACd,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAA6B,SAAS;CAChD,MAAM,OAAQ,OAAqC;CACnD,IAAI,OAAO,IAAI,GAAG,OAAO,KAAK;CA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,gBAAgB,EAAE;CAC1C,IAAI,oBAAoB,MACtB,MAAM,IAAI,MACR,uDAAuD,GAAG,EAC5D;CAEF,IAAI,oBAAoB,mBACtB,MAAM,IAAI,MACR,kDAAkD,kBAAkB,yBAAyB,gBAAgB,EAC/G;AAEJ;;;;;AAMA,MAAM,4BAA4B;CAChC,MAAM,SAAS;CACf,IAAI,OAAO,SAAS,iBAAiB,MAAM;CAC3C,OAAO,SAAS;GACb,cAAc;EACf,UAAU,IAAY,SAAiB,QAAQ,CAAC,CAAC,MAAM,QAAQ,IAAI,IAAI;EACvE,eAAe,IAAY,SACzB,QAAQ,CAAC,CAAC,MAAM,aAAa,IAAI,IAAI;EACvC,YAAY,OAAe,QAAQ,CAAC,CAAC,MAAM,UAAU,EAAE;CACzD;AACF;;;;AAKA,MAAa,yBACV,WAAqD,SACpD,iBACI"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Run `call` with a fresh copy of the globals. It starts from the test
3
+ * environment's, whatever the caller assigned in its own copy.
4
+ */
5
+ export declare const own: <A>(call: () => A) => A;
6
+ /**
7
+ * Read `read` against the test environment's globals, never a function call's
8
+ * copy, as the kernel's own clock must.
9
+ */
10
+ export declare const host: <A>(read: () => A) => A;
11
+ //# sourceMappingURL=Globals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Globals.d.ts","sourceRoot":"","sources":["../../src/internal/Globals.ts"],"names":[],"mappings":"AA8EA;;;GAGG;AACH,eAAO,MAAM,GAAG,GAAI,CAAC,QAAQ,MAAM,CAAC,KAAG,CAItC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,QAAQ,MAAM,CAAC,KAAG,CAA8B,CAAC"}
@@ -0,0 +1,76 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ //#region src/internal/Globals.ts
3
+ /**
4
+ * Convex gives every function execution its own globals. The kernel gives each
5
+ * function call it starts its own copy of the globals a test invocation pins,
6
+ * as convex-test 0.0.65 does for every handler (its `dist/index.js:1744`,
7
+ * `:1883-1905` and `:1927-1930`). An assignment inside the call lands in its
8
+ * copy only, so the invocation bridge's pins stay with the handler that made
9
+ * them, and overlapping or nested calls keep their own.
10
+ */
11
+ const names = [
12
+ "Date",
13
+ "Math",
14
+ "crypto"
15
+ ];
16
+ const key = Symbol.for("@confect/test/Globals");
17
+ const state = () => globalThis[key] ??= {
18
+ copies: new AsyncLocalStorage(),
19
+ getters: /* @__PURE__ */ new WeakSet()
20
+ };
21
+ /**
22
+ * Point each global at the calling function's copy, falling back to the
23
+ * global's own value outside one. A test that redefines a global, as
24
+ * `vi.stubGlobal` does, removes the accessor, so every call installs it again
25
+ * over what the test left.
26
+ */
27
+ const install = ({ copies, getters }) => {
28
+ const global = globalThis;
29
+ for (const name of names) {
30
+ const own = Object.getOwnPropertyDescriptor(global, name);
31
+ if (own?.get !== void 0 && getters.has(own.get)) continue;
32
+ const base = own ?? {
33
+ value: void 0,
34
+ writable: true
35
+ };
36
+ const get = () => {
37
+ const copy = copies.getStore();
38
+ if (copy !== void 0 && name in copy) return copy[name];
39
+ return "value" in base ? base.value : base.get?.call(global);
40
+ };
41
+ const set = (value) => {
42
+ const copy = copies.getStore();
43
+ if (copy !== void 0) copy[name] = value;
44
+ else if ("value" in base && base.writable === true) base.value = value;
45
+ else if (base.set !== void 0) base.set.call(global, value);
46
+ else throw new TypeError(`Cannot assign to read only global '${name}'`);
47
+ };
48
+ try {
49
+ Object.defineProperty(global, name, {
50
+ get,
51
+ set,
52
+ configurable: true,
53
+ enumerable: own?.enumerable ?? false
54
+ });
55
+ getters.add(get);
56
+ } catch {}
57
+ }
58
+ };
59
+ /**
60
+ * Run `call` with a fresh copy of the globals. It starts from the test
61
+ * environment's, whatever the caller assigned in its own copy.
62
+ */
63
+ const own = (call) => {
64
+ const current = state();
65
+ install(current);
66
+ return current.copies.run({}, call);
67
+ };
68
+ /**
69
+ * Read `read` against the test environment's globals, never a function call's
70
+ * copy, as the kernel's own clock must.
71
+ */
72
+ const host = (read) => state().copies.exit(read);
73
+ //#endregion
74
+ export { host, own };
75
+
76
+ //# sourceMappingURL=Globals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Globals.js","names":[],"sources":["../../src/internal/Globals.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\n/**\n * Convex gives every function execution its own globals. The kernel gives each\n * function call it starts its own copy of the globals a test invocation pins,\n * as convex-test 0.0.65 does for every handler (its `dist/index.js:1744`,\n * `:1883-1905` and `:1927-1930`). An assignment inside the call lands in its\n * copy only, so the invocation bridge's pins stay with the handler that made\n * them, and overlapping or nested calls keep their own.\n */\n\nconst names = [\"Date\", \"Math\", \"crypto\"] as const;\n\ntype Name = (typeof names)[number];\n\ntype Copies = { [name in Name]?: unknown };\n\ninterface State {\n readonly copies: AsyncLocalStorage<Copies>;\n /**\n * The getters this module installed, so a later install skips them.\n */\n readonly getters: WeakSet<() => unknown>;\n}\n\nconst key = Symbol.for(\"@confect/test/Globals\");\n\n// One store per test runtime, so every copy of this module reads the same\n// copies.\nconst state = (): State =>\n ((globalThis as { [key]?: State })[key] ??= {\n copies: new AsyncLocalStorage(),\n getters: new WeakSet(),\n });\n\n/**\n * Point each global at the calling function's copy, falling back to the\n * global's own value outside one. A test that redefines a global, as\n * `vi.stubGlobal` does, removes the accessor, so every call installs it again\n * over what the test left.\n */\nconst install = ({ copies, getters }: State) => {\n const global = globalThis as unknown as Record<Name, unknown>;\n for (const name of names) {\n const own = Object.getOwnPropertyDescriptor(global, name);\n // oxlint-disable-next-line typescript/unbound-method -- Compared by identity, never called.\n if (own?.get !== undefined && getters.has(own.get)) continue;\n const base: PropertyDescriptor = own ?? {\n value: undefined,\n writable: true,\n };\n const get = () => {\n const copy = copies.getStore();\n if (copy !== undefined && name in copy) return copy[name];\n return \"value\" in base ? base.value : base.get?.call(global);\n };\n const set = (value: unknown) => {\n const copy = copies.getStore();\n if (copy !== undefined) copy[name] = value;\n else if (\"value\" in base && base.writable === true) base.value = value;\n else if (base.set !== undefined) base.set.call(global, value);\n else throw new TypeError(`Cannot assign to read only global '${name}'`);\n };\n try {\n Object.defineProperty(global, name, {\n get,\n set,\n configurable: true,\n enumerable: own?.enumerable ?? false,\n });\n getters.add(get);\n } catch {\n // A global that cannot be redefined keeps no copy, and the bridge\n // refuses to pin it.\n }\n }\n};\n\n/**\n * Run `call` with a fresh copy of the globals. It starts from the test\n * environment's, whatever the caller assigned in its own copy.\n */\nexport const own = <A>(call: () => A): A => {\n const current = state();\n install(current);\n return current.copies.run({}, call);\n};\n\n/**\n * Read `read` against the test environment's globals, never a function call's\n * copy, as the kernel's own clock must.\n */\nexport const host = <A>(read: () => A): A => state().copies.exit(read);\n"],"mappings":";;;;;;;;;;AAWA,MAAM,QAAQ;CAAC;CAAQ;CAAQ;AAAQ;AAcvC,MAAM,MAAM,OAAO,IAAI,uBAAuB;AAI9C,MAAM,cACH,WAAkC,SAAS;CAC1C,QAAQ,IAAI,kBAAkB;CAC9B,yBAAS,IAAI,QAAQ;AACvB;;;;;;;AAQF,MAAM,WAAW,EAAE,QAAQ,cAAqB;CAC9C,MAAM,SAAS;CACf,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,MAAM,OAAO,yBAAyB,QAAQ,IAAI;EAExD,IAAI,KAAK,QAAQ,KAAA,KAAa,QAAQ,IAAI,IAAI,GAAG,GAAG;EACpD,MAAM,OAA2B,OAAO;GACtC,OAAO,KAAA;GACP,UAAU;EACZ;EACA,MAAM,YAAY;GAChB,MAAM,OAAO,OAAO,SAAS;GAC7B,IAAI,SAAS,KAAA,KAAa,QAAQ,MAAM,OAAO,KAAK;GACpD,OAAO,WAAW,OAAO,KAAK,QAAQ,KAAK,KAAK,KAAK,MAAM;EAC7D;EACA,MAAM,OAAO,UAAmB;GAC9B,MAAM,OAAO,OAAO,SAAS;GAC7B,IAAI,SAAS,KAAA,GAAW,KAAK,QAAQ;QAChC,IAAI,WAAW,QAAQ,KAAK,aAAa,MAAM,KAAK,QAAQ;QAC5D,IAAI,KAAK,QAAQ,KAAA,GAAW,KAAK,IAAI,KAAK,QAAQ,KAAK;QACvD,MAAM,IAAI,UAAU,sCAAsC,KAAK,EAAE;EACxE;EACA,IAAI;GACF,OAAO,eAAe,QAAQ,MAAM;IAClC;IACA;IACA,cAAc;IACd,YAAY,KAAK,cAAc;GACjC,CAAC;GACD,QAAQ,IAAI,GAAG;EACjB,QAAQ,CAGR;CACF;AACF;;;;;AAMA,MAAa,OAAU,SAAqB;CAC1C,MAAM,UAAU,MAAM;CACtB,QAAQ,OAAO;CACf,OAAO,QAAQ,OAAO,IAAI,CAAC,GAAG,IAAI;AACpC;;;;;AAMA,MAAa,QAAW,SAAqB,MAAM,CAAC,CAAC,OAAO,KAAK,IAAI"}
@@ -0,0 +1,93 @@
1
+ import type { DocumentId, StoredDocument } from "./KernelValues.js";
2
+ import * as ReadSet from "./ReadSet.js";
3
+ /**
4
+ * The number of commits the kernel has published. The empty world is 0.
5
+ */
6
+ export type Version = number;
7
+ /**
8
+ * A committed document and the version that wrote it.
9
+ */
10
+ export interface Row {
11
+ readonly doc: StoredDocument;
12
+ readonly version: Version;
13
+ }
14
+ /**
15
+ * Committed rows, keyed by component path, then table name, then document ID. A
16
+ * published state is never changed. A commit makes a new one.
17
+ */
18
+ export type Tables = ReadonlyMap<string, ReadonlyMap<string, ReadonlyMap<DocumentId, Row>>>;
19
+ /**
20
+ * One document's final value in a commit. `null` deletes it.
21
+ */
22
+ export interface Write {
23
+ readonly componentPath: string;
24
+ readonly id: DocumentId;
25
+ readonly doc: StoredDocument | null;
26
+ }
27
+ /**
28
+ * One document a commit changed: its value before and after. `null` is absent.
29
+ */
30
+ export interface Change {
31
+ readonly componentPath: string;
32
+ readonly id: DocumentId;
33
+ readonly before: StoredDocument | null;
34
+ readonly after: StoredDocument | null;
35
+ }
36
+ export interface Commit {
37
+ readonly version: Version;
38
+ readonly commitTs: bigint;
39
+ readonly changes: ReadonlyArray<Change>;
40
+ }
41
+ /**
42
+ * The kernel's committed state: rows, the latest version and commit timestamp,
43
+ * and the write log, oldest first.
44
+ */
45
+ export interface State {
46
+ readonly tables: Tables;
47
+ readonly version: Version;
48
+ readonly commitTs: bigint;
49
+ readonly log: ReadonlyArray<Commit>;
50
+ }
51
+ export declare const empty: State;
52
+ /**
53
+ * The committed row for `id` in `componentPath`, if any.
54
+ */
55
+ export declare const get: (state: State, componentPath: string, id: DocumentId) => Row | undefined;
56
+ /**
57
+ * Every committed row of one table in one component.
58
+ */
59
+ export declare const rows: (state: State, componentPath: string, tableName: string) => Iterable<Row>;
60
+ /**
61
+ * Publish one attempt's writes as a single commit at `commitTs`. Every
62
+ * component's writes land in the same version, so a reader sees all of them or
63
+ * none. A commit with no writes publishes nothing and leaves the state as it
64
+ * was.
65
+ */
66
+ export declare const apply: (state: State, writes: ReadonlyArray<Write>, commitTs: bigint) => State;
67
+ /**
68
+ * The first change published after version `snapshot` that invalidates one of
69
+ * `reads`, if any.
70
+ */
71
+ export declare const conflict: (state: State, snapshot: Version, reads: ReadonlyArray<ReadSet.Read>) => Change | undefined;
72
+ /**
73
+ * What the driver supplies. The kernel holds no clock of its own.
74
+ */
75
+ export interface KernelRuntime {
76
+ /**
77
+ * The time in milliseconds, for each inserted document's creation time.
78
+ */
79
+ readonly now: () => number;
80
+ /**
81
+ * The commit timestamp of `version`, asked once as it is published. The
82
+ * answers strictly increase. A mutation that wrote nothing publishes no
83
+ * version and asks nothing.
84
+ */
85
+ readonly commitTs: (version: Version) => bigint;
86
+ }
87
+ /**
88
+ * The wall clock, as convex-test reads it. Each answer is the time in
89
+ * nanoseconds when it is asked for, bumped past the previous answer when the
90
+ * clock stands still.
91
+ */
92
+ export declare const wallClock: () => KernelRuntime;
93
+ //# sourceMappingURL=Kernel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Kernel.d.ts","sourceRoot":"","sources":["../../src/internal/Kernel.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,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AAM,CAAC,CAAC;CACrC;AAED,eAAO,MAAM,KAAK,EAAE,KAKnB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,GAAG,UACP,KAAK,iBACG,MAAM,MACjB,UAAU,KACb,GAAG,GAAG,SAKR,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,IAAI,UACR,KAAK,iBACG,MAAM,aACV,MAAM,KAChB,QAAQ,CAAC,GAAG,CACkD,CAAC;AAElE;;;;;GAKG;AACH,eAAO,MAAM,KAAK,UACT,KAAK,UACJ,aAAa,CAAC,KAAK,CAAC,YAClB,MAAM,KACf,KAgCF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,QAAQ,UACZ,KAAK,YACF,OAAO,SACV,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,KACjC,MAAM,GAAG,SAOX,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,MAAM,CAAC;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC;CACjD;AAED;;;;GAIG;AACH,eAAO,MAAM,SAAS,QAAO,aAa5B,CAAC"}
@@ -0,0 +1,91 @@
1
+ import { host } from "./Globals.js";
2
+ import { resolveCommittedValues, tableNameFromId } from "./KernelValues.js";
3
+ import { covers } from "./ReadSet.js";
4
+ //#region src/internal/Kernel.ts
5
+ const empty = {
6
+ tables: /* @__PURE__ */ new Map(),
7
+ version: 0,
8
+ commitTs: 0n,
9
+ log: []
10
+ };
11
+ /**
12
+ * The committed row for `id` in `componentPath`, if any.
13
+ */
14
+ const get = (state, componentPath, id) => {
15
+ const tableName = tableNameFromId(id);
16
+ return tableName === null ? void 0 : state.tables.get(componentPath)?.get(tableName)?.get(id);
17
+ };
18
+ /**
19
+ * Every committed row of one table in one component.
20
+ */
21
+ const rows = (state, componentPath, tableName) => state.tables.get(componentPath)?.get(tableName)?.values() ?? [];
22
+ /**
23
+ * Publish one attempt's writes as a single commit at `commitTs`. Every
24
+ * component's writes land in the same version, so a reader sees all of them or
25
+ * none. A commit with no writes publishes nothing and leaves the state as it
26
+ * was.
27
+ */
28
+ const apply = (state, writes, commitTs) => {
29
+ if (writes.length === 0) return state;
30
+ const version = state.version + 1;
31
+ const tables = new Map(Array.from(state.tables, ([path, byTable]) => [path, new Map(byTable)]));
32
+ const changes = writes.map(({ componentPath, id, doc }) => ({
33
+ componentPath,
34
+ id,
35
+ before: get(state, componentPath, id)?.doc ?? null,
36
+ after: doc === null ? null : resolveCommittedValues(doc, commitTs)
37
+ }));
38
+ const touched = /* @__PURE__ */ new Set();
39
+ for (const { componentPath, id, after } of changes) {
40
+ const tableName = tableNameFromId(id);
41
+ const byTable = tables.get(componentPath) ?? /* @__PURE__ */ new Map();
42
+ tables.set(componentPath, byTable);
43
+ const key = `${componentPath}\u0000${tableName}`;
44
+ const table = touched.has(key) ? byTable.get(tableName) : new Map(byTable.get(tableName) ?? []);
45
+ touched.add(key);
46
+ byTable.set(tableName, table);
47
+ if (after === null) table.delete(id);
48
+ else table.set(id, {
49
+ doc: after,
50
+ version
51
+ });
52
+ }
53
+ return {
54
+ tables,
55
+ version,
56
+ commitTs,
57
+ log: [...state.log, {
58
+ version,
59
+ commitTs,
60
+ changes
61
+ }]
62
+ };
63
+ };
64
+ /**
65
+ * The first change published after version `snapshot` that invalidates one of
66
+ * `reads`, if any.
67
+ */
68
+ const conflict = (state, snapshot, reads) => {
69
+ for (const commit of state.log.slice(snapshot)) for (const change of commit.changes) if (reads.some((read) => covers(read, change))) return change;
70
+ };
71
+ /**
72
+ * The wall clock, as convex-test reads it. Each answer is the time in
73
+ * nanoseconds when it is asked for, bumped past the previous answer when the
74
+ * clock stands still.
75
+ */
76
+ const wallClock = () => {
77
+ let latest = 0n;
78
+ const now = () => host(() => Date.now());
79
+ return {
80
+ now,
81
+ commitTs: () => {
82
+ const nanos = BigInt(now()) * 1000000n;
83
+ latest = nanos > latest ? nanos : latest + 1n;
84
+ return latest;
85
+ }
86
+ };
87
+ };
88
+ //#endregion
89
+ export { apply, conflict, empty, get, rows, wallClock };
90
+
91
+ //# sourceMappingURL=Kernel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Kernel.js","names":["ReadSet.covers","Globals.host"],"sources":["../../src/internal/Kernel.ts"],"sourcesContent":["import * as Globals from \"./Globals.js\";\nimport type { DocumentId, StoredDocument } from \"./KernelValues.js\";\nimport { resolveCommittedValues, tableNameFromId } from \"./KernelValues.js\";\nimport * as ReadSet from \"./ReadSet.js\";\n\n/**\n * The number of commits the kernel has published. The empty world is 0.\n */\nexport type Version = number;\n\n/**\n * A committed document and the version that wrote it.\n */\nexport interface Row {\n readonly doc: StoredDocument;\n readonly version: Version;\n}\n\n/**\n * Committed rows, keyed by component path, then table name, then document ID. A\n * published state is never changed. A commit makes a new one.\n */\nexport type Tables = ReadonlyMap<\n string,\n ReadonlyMap<string, ReadonlyMap<DocumentId, Row>>\n>;\n\n/**\n * One document's final value in a commit. `null` deletes it.\n */\nexport interface Write {\n readonly componentPath: string;\n readonly id: DocumentId;\n readonly doc: StoredDocument | null;\n}\n\n/**\n * One document a commit changed: its value before and after. `null` is absent.\n */\nexport interface Change {\n readonly componentPath: string;\n readonly id: DocumentId;\n readonly before: StoredDocument | null;\n readonly after: StoredDocument | null;\n}\n\nexport interface Commit {\n readonly version: Version;\n readonly commitTs: bigint;\n readonly changes: ReadonlyArray<Change>;\n}\n\n/**\n * The kernel's committed state: rows, the latest version and commit timestamp,\n * and the write log, oldest first.\n */\nexport interface State {\n readonly tables: Tables;\n readonly version: Version;\n readonly commitTs: bigint;\n readonly log: ReadonlyArray<Commit>;\n}\n\nexport const empty: State = {\n tables: new Map(),\n version: 0,\n commitTs: 0n,\n log: [],\n};\n\n/**\n * The committed row for `id` in `componentPath`, if any.\n */\nexport const get = (\n state: State,\n componentPath: string,\n id: DocumentId,\n): Row | undefined => {\n const tableName = tableNameFromId(id);\n return tableName === null\n ? undefined\n : state.tables.get(componentPath)?.get(tableName)?.get(id);\n};\n\n/**\n * Every committed row of one table in one component.\n */\nexport const rows = (\n state: State,\n componentPath: string,\n tableName: string,\n): Iterable<Row> =>\n state.tables.get(componentPath)?.get(tableName)?.values() ?? [];\n\n/**\n * Publish one attempt's writes as a single commit at `commitTs`. Every\n * component's writes land in the same version, so a reader sees all of them or\n * none. A commit with no writes publishes nothing and leaves the state as it\n * was.\n */\nexport const apply = (\n state: State,\n writes: ReadonlyArray<Write>,\n commitTs: bigint,\n): State => {\n if (writes.length === 0) return state;\n const version = state.version + 1;\n const tables = new Map(\n Array.from(state.tables, ([path, byTable]) => [path, new Map(byTable)]),\n );\n const changes = writes.map(({ componentPath, id, doc }): Change => ({\n componentPath,\n id,\n before: get(state, componentPath, id)?.doc ?? null,\n after: doc === null ? null : resolveCommittedValues(doc, commitTs),\n }));\n const touched = new Set<string>();\n for (const { componentPath, id, after } of changes) {\n const tableName = tableNameFromId(id)!;\n const byTable = tables.get(componentPath) ?? new Map();\n tables.set(componentPath, byTable);\n const key = `${componentPath}\\u0000${tableName}`;\n const table = touched.has(key)\n ? byTable.get(tableName)!\n : new Map(byTable.get(tableName) ?? []);\n touched.add(key);\n byTable.set(tableName, table);\n if (after === null) table.delete(id);\n else table.set(id, { doc: after, version });\n }\n return {\n tables,\n version,\n commitTs,\n log: [...state.log, { version, commitTs, changes }],\n };\n};\n\n/**\n * The first change published after version `snapshot` that invalidates one of\n * `reads`, if any.\n */\nexport const conflict = (\n state: State,\n snapshot: Version,\n reads: ReadonlyArray<ReadSet.Read>,\n): Change | undefined => {\n for (const commit of state.log.slice(snapshot)) {\n for (const change of commit.changes) {\n if (reads.some((read) => ReadSet.covers(read, change))) return change;\n }\n }\n return undefined;\n};\n\n/**\n * What the driver supplies. The kernel holds no clock of its own.\n */\nexport interface KernelRuntime {\n /**\n * The time in milliseconds, for each inserted document's creation time.\n */\n readonly now: () => number;\n /**\n * The commit timestamp of `version`, asked once as it is published. The\n * answers strictly increase. A mutation that wrote nothing publishes no\n * version and asks nothing.\n */\n readonly commitTs: (version: Version) => bigint;\n}\n\n/**\n * The wall clock, as convex-test reads it. Each answer is the time in\n * nanoseconds when it is asked for, bumped past the previous answer when the\n * clock stands still.\n */\nexport const wallClock = (): KernelRuntime => {\n let latest = 0n;\n // The host's clock, never the copy a bound handler pinned.\n // oxlint-disable-next-line effecttsgo/global-date -- The default runtime is the wall clock. A driver that replays supplies its own.\n const now = () => Globals.host(() => Date.now());\n return {\n now,\n commitTs: () => {\n const nanos = BigInt(now()) * 1_000_000n;\n latest = nanos > latest ? nanos : latest + 1n;\n return latest;\n },\n };\n};\n"],"mappings":";;;;AA+DA,MAAa,QAAe;CAC1B,wBAAQ,IAAI,IAAI;CAChB,SAAS;CACT,UAAU;CACV,KAAK,CAAC;AACR;;;;AAKA,MAAa,OACX,OACA,eACA,OACoB;CACpB,MAAM,YAAY,gBAAgB,EAAE;CACpC,OAAO,cAAc,OACjB,KAAA,IACA,MAAM,OAAO,IAAI,aAAa,CAAC,EAAE,IAAI,SAAS,CAAC,EAAE,IAAI,EAAE;AAC7D;;;;AAKA,MAAa,QACX,OACA,eACA,cAEA,MAAM,OAAO,IAAI,aAAa,CAAC,EAAE,IAAI,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;;;;;;;AAQhE,MAAa,SACX,OACA,QACA,aACU;CACV,IAAI,OAAO,WAAW,GAAG,OAAO;CAChC,MAAM,UAAU,MAAM,UAAU;CAChC,MAAM,SAAS,IAAI,IACjB,MAAM,KAAK,MAAM,SAAS,CAAC,MAAM,aAAa,CAAC,MAAM,IAAI,IAAI,OAAO,CAAC,CAAC,CACxE;CACA,MAAM,UAAU,OAAO,KAAK,EAAE,eAAe,IAAI,WAAmB;EAClE;EACA;EACA,QAAQ,IAAI,OAAO,eAAe,EAAE,CAAC,EAAE,OAAO;EAC9C,OAAO,QAAQ,OAAO,OAAO,uBAAuB,KAAK,QAAQ;CACnE,EAAE;CACF,MAAM,0BAAU,IAAI,IAAY;CAChC,KAAK,MAAM,EAAE,eAAe,IAAI,WAAW,SAAS;EAClD,MAAM,YAAY,gBAAgB,EAAE;EACpC,MAAM,UAAU,OAAO,IAAI,aAAa,qBAAK,IAAI,IAAI;EACrD,OAAO,IAAI,eAAe,OAAO;EACjC,MAAM,MAAM,GAAG,cAAc,QAAQ;EACrC,MAAM,QAAQ,QAAQ,IAAI,GAAG,IACzB,QAAQ,IAAI,SAAS,IACrB,IAAI,IAAI,QAAQ,IAAI,SAAS,KAAK,CAAC,CAAC;EACxC,QAAQ,IAAI,GAAG;EACf,QAAQ,IAAI,WAAW,KAAK;EAC5B,IAAI,UAAU,MAAM,MAAM,OAAO,EAAE;OAC9B,MAAM,IAAI,IAAI;GAAE,KAAK;GAAO;EAAQ,CAAC;CAC5C;CACA,OAAO;EACL;EACA;EACA;EACA,KAAK,CAAC,GAAG,MAAM,KAAK;GAAE;GAAS;GAAU;EAAQ,CAAC;CACpD;AACF;;;;;AAMA,MAAa,YACX,OACA,UACA,UACuB;CACvB,KAAK,MAAM,UAAU,MAAM,IAAI,MAAM,QAAQ,GAC3C,KAAK,MAAM,UAAU,OAAO,SAC1B,IAAI,MAAM,MAAM,SAASA,OAAe,MAAM,MAAM,CAAC,GAAG,OAAO;AAIrE;;;;;;AAuBA,MAAa,kBAAiC;CAC5C,IAAI,SAAS;CAGb,MAAM,YAAYC,WAAmB,KAAK,IAAI,CAAC;CAC/C,OAAO;EACL;EACA,gBAAgB;GACd,MAAM,QAAQ,OAAO,IAAI,CAAC,IAAI;GAC9B,SAAS,QAAQ,SAAS,QAAQ,SAAS;GAC3C,OAAO;EACT;CACF;AACF"}
@@ -0,0 +1,55 @@
1
+ import type { GenericDocument, GenericSchema, SchemaDefinition } from "convex/server";
2
+ import * as ReadSet from "./ReadSet.js";
3
+ import type { Index, SerializedQuery, StoredDocument, ValidatorJSON } from "./KernelValues.js";
4
+ /**
5
+ * A component's tables as its schema declares them.
6
+ */
7
+ export interface KernelSchema {
8
+ readonly schemaValidation: boolean;
9
+ readonly tables: ReadonlyMap<string, {
10
+ readonly indexes: ReadonlyArray<Index>;
11
+ readonly documentType: ValidatorJSON;
12
+ }>;
13
+ }
14
+ export declare const exportSchema: (schema: SchemaDefinition<GenericSchema, boolean> | null | undefined) => KernelSchema | null;
15
+ /**
16
+ * Check a document against its table's declared type, as the backend does
17
+ * before a write.
18
+ */
19
+ export declare const validateDocument: (schema: KernelSchema | null, tableName: string, doc: Record<string, unknown>) => void;
20
+ /**
21
+ * An interval a query reads, before it says where it starts and how far it got.
22
+ */
23
+ export type Interval = Omit<ReadSet.IntervalRead, "componentPath" | "after" | "through">;
24
+ /**
25
+ * What a query reads: one table of one component, as the running attempt sees
26
+ * it. `read` records an interval in the attempt's read set and returns how to
27
+ * advance it.
28
+ */
29
+ export interface TableView {
30
+ readonly schema: KernelSchema | null;
31
+ readonly scan: (tableName: string) => ReadonlyArray<StoredDocument>;
32
+ readonly read: (interval: Interval, after: ReadSet.Key | null) => (through: ReadSet.Key | "end") => void;
33
+ }
34
+ /**
35
+ * A query's documents in order. The source is read when the query starts, as a
36
+ * snapshot, and consumed lazily. The read set holds the prefix the stream has
37
+ * examined, filtered documents included, or the whole range once it ends.
38
+ */
39
+ export declare const stream: (view: TableView, query: SerializedQuery) => Iterator<GenericDocument>;
40
+ export interface PageRequest {
41
+ readonly query: SerializedQuery;
42
+ readonly cursor: string | null;
43
+ readonly endCursor?: string | null;
44
+ readonly pageSize: number;
45
+ readonly maximumRowsRead?: number | null;
46
+ readonly maximumBytesRead?: number | null;
47
+ }
48
+ export declare const paginate: (view: TableView, { query, cursor, endCursor, pageSize, maximumRowsRead, maximumBytesRead, }: PageRequest) => {
49
+ page: GenericDocument[];
50
+ isDone: boolean;
51
+ continueCursor: string;
52
+ splitCursor: string | null;
53
+ pageStatus: "SplitRecommended" | "SplitRequired" | null;
54
+ };
55
+ //# sourceMappingURL=KernelQuery.d.ts.map
@@ -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