convex 1.42.0 → 1.42.1
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.
- package/CHANGELOG.md +7 -0
- package/dist/browser.bundle.js +24 -6
- package/dist/browser.bundle.js.map +2 -2
- package/dist/cjs/browser/sync/authentication_manager.js +21 -4
- package/dist/cjs/browser/sync/authentication_manager.js.map +2 -2
- package/dist/cjs/browser/sync/client.js +2 -1
- package/dist/cjs/browser/sync/client.js.map +2 -2
- package/dist/cjs/cli/lib/typecheck.js +28 -10
- package/dist/cjs/cli/lib/typecheck.js.map +2 -2
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/server/impl/registration_impl.js +0 -2
- package/dist/cjs/server/impl/registration_impl.js.map +2 -2
- package/dist/cjs-types/browser/sync/authentication_manager.d.ts +2 -0
- package/dist/cjs-types/browser/sync/authentication_manager.d.ts.map +1 -1
- package/dist/cjs-types/browser/sync/client.d.ts +16 -0
- package/dist/cjs-types/browser/sync/client.d.ts.map +1 -1
- package/dist/cjs-types/index.d.ts +1 -1
- package/dist/cjs-types/server/impl/registration_impl.d.ts.map +1 -1
- package/dist/cli.bundle.cjs +53 -16
- package/dist/cli.bundle.cjs.map +3 -3
- package/dist/esm/browser/sync/authentication_manager.js +21 -4
- package/dist/esm/browser/sync/authentication_manager.js.map +2 -2
- package/dist/esm/browser/sync/client.js +2 -1
- package/dist/esm/browser/sync/client.js.map +2 -2
- package/dist/esm/cli/lib/typecheck.js +28 -10
- package/dist/esm/cli/lib/typecheck.js.map +3 -3
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/server/impl/registration_impl.js +0 -2
- package/dist/esm/server/impl/registration_impl.js.map +2 -2
- package/dist/esm-types/browser/sync/authentication_manager.d.ts +2 -0
- package/dist/esm-types/browser/sync/authentication_manager.d.ts.map +1 -1
- package/dist/esm-types/browser/sync/client.d.ts +16 -0
- package/dist/esm-types/browser/sync/client.d.ts.map +1 -1
- package/dist/esm-types/index.d.ts +1 -1
- package/dist/esm-types/server/impl/registration_impl.d.ts.map +1 -1
- package/dist/react.bundle.js +24 -6
- package/dist/react.bundle.js.map +2 -2
- package/package.json +1 -1
- package/src/browser/sync/authentication_manager.ts +42 -14
- package/src/browser/sync/client.ts +17 -0
- package/src/cli/lib/typecheck.ts +26 -10
- package/src/index.ts +1 -1
- package/src/react/ConvexAuthState.test.tsx +145 -0
- package/src/server/impl/registration_impl.ts +0 -2
|
@@ -204,7 +204,6 @@ const internalQueryGeneric = ((functionDefinition) => {
|
|
|
204
204
|
return func;
|
|
205
205
|
});
|
|
206
206
|
async function invokeAction(func, requestId, argsStr, visibility) {
|
|
207
|
-
globalThis.Convex?.setupPerformance?.();
|
|
208
207
|
const args = (0, import_values.jsonToConvex)(JSON.parse(argsStr));
|
|
209
208
|
const calls = (0, import_actions_impl.setupActionCalls)(requestId);
|
|
210
209
|
const ctx = {
|
|
@@ -243,7 +242,6 @@ const internalActionGeneric = ((functionDefinition) => {
|
|
|
243
242
|
return func;
|
|
244
243
|
});
|
|
245
244
|
async function invokeHttpAction(func, request) {
|
|
246
|
-
globalThis.Convex?.setupPerformance?.();
|
|
247
245
|
const requestId = "";
|
|
248
246
|
const calls = (0, import_actions_impl.setupActionCalls)(requestId);
|
|
249
247
|
const ctx = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/server/impl/registration_impl.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n ConvexError,\n convexToJson,\n GenericValidator,\n jsonToConvex,\n v,\n Validator,\n Value,\n} from \"../../values/index.js\";\nimport { GenericDataModel } from \"../data_model.js\";\nimport {\n ActionBuilder,\n DefaultFunctionArgs,\n FunctionVisibility,\n GenericActionCtx,\n GenericMutationCtx,\n GenericQueryCtx,\n MutationBuilder,\n PublicHttpAction,\n QueryBuilder,\n RegisteredAction,\n RegisteredMutation,\n RegisteredQuery,\n} from \"../registration.js\";\nimport { setupActionCalls } from \"./actions_impl.js\";\nimport { setupActionVectorSearch } from \"./vector_search_impl.js\";\nimport { setupAuth } from \"./authentication_impl.js\";\nimport { setupReader, setupWriter } from \"./database_impl.js\";\nimport { QueryImpl, QueryInitializerImpl } from \"./query_impl.js\";\nimport {\n setupActionScheduler,\n setupMutationScheduler,\n} from \"./scheduler_impl.js\";\nimport {\n setupStorageActionWriter,\n setupStorageReader,\n setupStorageWriter,\n} from \"./storage_impl.js\";\nimport { parseArgs } from \"../../common/index.js\";\nimport { performAsyncSyscall } from \"./syscall.js\";\nimport { asObjectValidator } from \"../../values/validator.js\";\nimport { getFunctionAddress } from \"../components/paths.js\";\nimport {\n setupQueryMeta,\n setupMutationMeta,\n setupActionMeta,\n} from \"./meta_impl.js\";\n\nasync function invokeMutation<\n F extends (ctx: GenericMutationCtx<GenericDataModel>, ...args: any) => any,\n>(func: F, argsStr: string, visibility: FunctionVisibility) {\n // TODO(presley): Change the function signature and propagate the requestId from Rust.\n // Ok, to mock it out for now, since queries are only running in V8.\n const requestId = \"\";\n const args = jsonToConvex(JSON.parse(argsStr));\n const mutationCtx = {\n db: setupWriter(),\n auth: setupAuth(requestId),\n storage: setupStorageWriter(requestId),\n scheduler: setupMutationScheduler(),\n meta: setupMutationMeta(visibility),\n\n runQuery: (reference: any, args?: any, options?: any) =>\n options?.useStaleSnapshot\n ? runUdf(\"snapshotQuery\", reference, args, options?.transactionLimits)\n : runUdf(\"query\", reference, args, options?.transactionLimits),\n runMutation: (reference: any, args?: any, options?: any) =>\n runUdf(\"mutation\", reference, args, options?.transactionLimits),\n };\n const result = await invokeFunction(func, mutationCtx, args as any);\n validateReturnValue(result);\n return JSON.stringify(convexToJson(result === undefined ? null : result));\n}\n\nexport function validateReturnValue(v: any) {\n if (v instanceof QueryInitializerImpl || v instanceof QueryImpl) {\n throw new Error(\n \"Return value is a Query. Results must be retrieved with `.collect()`, `.take(n), `.unique()`, or `.first()`.\",\n );\n }\n}\n\nexport async function invokeFunction<\n Ctx,\n Args extends any[],\n F extends (ctx: Ctx, ...args: Args) => any,\n>(func: F, ctx: Ctx, args: Args) {\n let result;\n try {\n result = await Promise.resolve(func(ctx, ...args));\n } catch (thrown: unknown) {\n throw serializeConvexErrorData(thrown);\n }\n return result;\n}\n\nfunction dontCallDirectly(\n funcType: string,\n handler: (ctx: any, args: any) => any,\n): unknown {\n return (ctx: any, args: any) => {\n globalThis.console.warn(\n \"Convex functions should not directly call other Convex functions. Consider calling a helper function instead. \" +\n `e.g. \\`export const foo = ${funcType}(...); await foo(ctx);\\` is not supported. ` +\n \"See https://docs.convex.dev/production/best-practices/#use-helper-functions-to-write-shared-code\",\n );\n return handler(ctx, args);\n };\n}\n\n// Keep in sync with node executor\nfunction serializeConvexErrorData(thrown: unknown) {\n if (\n typeof thrown === \"object\" &&\n thrown !== null &&\n Symbol.for(\"ConvexError\") in thrown\n ) {\n const error = thrown as ConvexError<any>;\n error.data = JSON.stringify(\n convexToJson(error.data === undefined ? null : error.data),\n );\n (error as any).ConvexErrorSymbol = Symbol.for(\"ConvexError\");\n return error;\n } else {\n return thrown;\n }\n}\n\n/**\n * Guard against Convex functions accidentally getting included in a browser bundle.\n * Convex functions may include secret logic or credentials that should not be\n * send to untrusted clients (browsers).\n */\nfunction assertNotBrowser() {\n if (\n typeof window === \"undefined\" ||\n (window as any).__convexAllowFunctionsInBrowser\n ) {\n return;\n }\n // JSDom doesn't count, developers are allowed to use JSDom in Convex functions.\n const isRealBrowser =\n Object.getOwnPropertyDescriptor(globalThis, \"window\")\n ?.get?.toString()\n .includes(\"[native code]\") ?? false;\n if (isRealBrowser) {\n // eslint-disable-next-line no-console\n console.error(\n \"Convex functions should not be imported in the browser. This will throw an error in future versions of `convex`. If this is a false negative, please report it to Convex support.\",\n );\n }\n}\n\ntype FunctionDefinition =\n | ((ctx: any, args: DefaultFunctionArgs) => any)\n | {\n args?: GenericValidator | Record<string, GenericValidator>;\n returns?: GenericValidator | Record<string, GenericValidator>;\n handler: (ctx: any, args: DefaultFunctionArgs) => any;\n };\n\nfunction strictReplacer(key: string, value: any) {\n if (value === undefined) {\n throw new Error(\n `A validator is undefined for field \"${key}\". ` +\n `This is often caused by circular imports. ` +\n `See https://docs.convex.dev/error#undefined-validator for details.`,\n );\n }\n return value;\n}\nfunction exportArgs(functionDefinition: FunctionDefinition) {\n return () => {\n let args: GenericValidator = v.any();\n if (\n typeof functionDefinition === \"object\" &&\n functionDefinition.args !== undefined\n ) {\n args = asObjectValidator(functionDefinition.args);\n }\n return JSON.stringify(args.json, strictReplacer);\n };\n}\n\nfunction exportReturns(functionDefinition: FunctionDefinition) {\n return () => {\n let returns: Validator<any, any, any> | undefined;\n if (\n typeof functionDefinition === \"object\" &&\n functionDefinition.returns !== undefined\n ) {\n returns = asObjectValidator(functionDefinition.returns);\n }\n return JSON.stringify(returns ? returns.json : null, strictReplacer);\n };\n}\n\n/**\n * Define a mutation in this Convex app's public API.\n *\n * You should generally use the `mutation` function from\n * `\"./_generated/server\"`.\n *\n * Mutations can read from and write to the database, and are accessible from\n * the client. They run **transactionally**, all database reads and writes\n * within a single mutation are atomic and isolated from other mutations.\n *\n * @example\n * ```typescript\n * import { mutation } from \"./_generated/server\";\n * import { v } from \"convex/values\";\n *\n * export const createTask = mutation({\n * args: { text: v.string() },\n * returns: v.id(\"tasks\"),\n * handler: async (ctx, args) => {\n * const taskId = await ctx.db.insert(\"tasks\", {\n * text: args.text,\n * completed: false,\n * });\n * return taskId;\n * },\n * });\n * ```\n *\n * **Best practice:** Always include `args` and `returns` validators on all\n * mutations. If the function doesn't return a value, use `returns: v.null()`.\n * Argument validation is critical for security since public mutations are\n * exposed to the internet.\n *\n * **Common mistake:** Mutations cannot call third-party APIs or use `fetch`.\n * They must be deterministic. Use actions for external API calls.\n *\n * **Common mistake:** Do not use `mutation` for sensitive internal functions\n * that should not be called by clients. Use `internalMutation` instead.\n *\n * @param func - The mutation function. It receives a {@link GenericMutationCtx} as its first argument.\n * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.\n *\n * @see https://docs.convex.dev/functions/mutation-functions\n * @public\n */\nexport const mutationGeneric: MutationBuilder<any, \"public\"> = ((\n functionDefinition: FunctionDefinition,\n) => {\n const handler = (\n typeof functionDefinition === \"function\"\n ? functionDefinition\n : functionDefinition.handler\n ) as (ctx: GenericMutationCtx<any>, args: any) => any;\n const func = dontCallDirectly(\"mutation\", handler) as RegisteredMutation<\n \"public\",\n any,\n any\n >;\n\n assertNotBrowser();\n func.isMutation = true;\n func.isPublic = true;\n func.invokeMutation = (argsStr) => invokeMutation(handler, argsStr, \"public\");\n func.exportArgs = exportArgs(functionDefinition);\n func.exportReturns = exportReturns(functionDefinition);\n func._handler = handler;\n return func;\n}) as MutationBuilder<any, \"public\">;\n\n/**\n * Define a mutation that is only accessible from other Convex functions (but not from the client).\n *\n * You should generally use the `internalMutation` function from\n * `\"./_generated/server\"`.\n *\n * Internal mutations can read from and write to the database but are **not**\n * exposed as part of your app's public API. They can only be called by other\n * Convex functions using `ctx.runMutation` or by the scheduler. Like public\n * mutations, they run transactionally.\n *\n * @example\n * ```typescript\n * import { internalMutation } from \"./_generated/server\";\n * import { v } from \"convex/values\";\n *\n * // This mutation can only be called from other Convex functions:\n * export const markTaskCompleted = internalMutation({\n * args: { taskId: v.id(\"tasks\") },\n * returns: v.null(),\n * handler: async (ctx, args) => {\n * await ctx.db.patch(\"tasks\", args.taskId, { completed: true });\n * return null;\n * },\n * });\n * ```\n *\n * **Best practice:** Use `internalMutation` for any mutation that should not\n * be directly callable by clients, such as write-back functions from actions\n * or scheduled background work. Reference it via the `internal` object:\n * `await ctx.runMutation(internal.myModule.markTaskCompleted, { taskId })`.\n *\n * @param func - The mutation function. It receives a {@link GenericMutationCtx} as its first argument.\n * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.\n *\n * @see https://docs.convex.dev/functions/internal-functions\n * @public\n */\nexport const internalMutationGeneric: MutationBuilder<any, \"internal\"> = ((\n functionDefinition: FunctionDefinition,\n) => {\n const handler = (\n typeof functionDefinition === \"function\"\n ? functionDefinition\n : functionDefinition.handler\n ) as (ctx: GenericMutationCtx<any>, args: any) => any;\n const func = dontCallDirectly(\n \"internalMutation\",\n handler,\n ) as RegisteredMutation<\"internal\", any, any>;\n\n assertNotBrowser();\n func.isMutation = true;\n func.isInternal = true;\n func.invokeMutation = (argsStr) =>\n invokeMutation(handler, argsStr, \"internal\");\n func.exportArgs = exportArgs(functionDefinition);\n func.exportReturns = exportReturns(functionDefinition);\n func._handler = handler;\n return func;\n}) as MutationBuilder<any, \"internal\">;\n\nasync function invokeQuery<\n F extends (ctx: GenericQueryCtx<GenericDataModel>, ...args: any) => any,\n>(func: F, argsStr: string, visibility: FunctionVisibility) {\n // TODO(presley): Change the function signature and propagate the requestId from Rust.\n // Ok, to mock it out for now, since queries are only running in V8.\n const requestId = \"\";\n const args = jsonToConvex(JSON.parse(argsStr));\n const queryCtx = {\n db: setupReader(),\n auth: setupAuth(requestId),\n storage: setupStorageReader(requestId),\n meta: setupQueryMeta(visibility),\n runQuery: (reference: any, args?: any, options?: any) => {\n if (options?.useStaleSnapshot) {\n throw new Error(\n \"`useStaleSnapshot` is only supported in mutations, not queries.\",\n );\n }\n return runUdf(\"query\", reference, args, options?.transactionLimits);\n },\n };\n const result = await invokeFunction(func, queryCtx, args as any);\n validateReturnValue(result);\n return JSON.stringify(convexToJson(result === undefined ? null : result));\n}\n\n/**\n * Define a query in this Convex app's public API.\n *\n * You should generally use the `query` function from\n * `\"./_generated/server\"`.\n *\n * Queries can read from the database and are accessible from the client. They\n * are **reactive**, when used with `useQuery` in React, the component\n * automatically re-renders whenever the underlying data changes. Queries\n * cannot modify the database.\n * Query results are automatically cached by the Convex client and kept\n * consistent via WebSocket subscriptions.\n *\n *\n * @example\n * ```typescript\n * import { query } from \"./_generated/server\";\n * import { v } from \"convex/values\";\n *\n * export const listTasks = query({\n * args: { completed: v.optional(v.boolean()) },\n * returns: v.array(v.object({\n * _id: v.id(\"tasks\"),\n * _creationTime: v.number(),\n * text: v.string(),\n * completed: v.boolean(),\n * })),\n * handler: async (ctx, args) => {\n * if (args.completed !== undefined) {\n * return await ctx.db\n * .query(\"tasks\")\n * .withIndex(\"by_completed\", (q) => q.eq(\"completed\", args.completed))\n * .collect();\n * }\n * return await ctx.db.query(\"tasks\").collect();\n * },\n * });\n * ```\n *\n * **Best practice:** Always include `args` and `returns` validators. Use\n * `.withIndex()` instead of `.filter()` for efficient database queries.\n * Queries should be fast since they run on every relevant data change.\n *\n * **Common mistake:** Queries are pure reads, they cannot write to the\n * database, call external APIs, or schedule functions. Use actions for HTTP\n * calls and mutations for database writes and scheduling.\n *\n * @param func - The query function. It receives a {@link GenericQueryCtx} as its first argument.\n * @returns The wrapped query. Include this as an `export` to name it and make it accessible.\n *\n * @see https://docs.convex.dev/functions/query-functions\n * @public\n */\nexport const queryGeneric: QueryBuilder<any, \"public\"> = ((\n functionDefinition: FunctionDefinition,\n) => {\n const handler = (\n typeof functionDefinition === \"function\"\n ? functionDefinition\n : functionDefinition.handler\n ) as (ctx: GenericQueryCtx<any>, args: any) => any;\n const func = dontCallDirectly(\"query\", handler) as RegisteredQuery<\n \"public\",\n any,\n any\n >;\n\n assertNotBrowser();\n func.isQuery = true;\n func.isPublic = true;\n func.invokeQuery = (argsStr) => invokeQuery(handler, argsStr, \"public\");\n func.exportArgs = exportArgs(functionDefinition);\n func.exportReturns = exportReturns(functionDefinition);\n func._handler = handler;\n return func;\n}) as QueryBuilder<any, \"public\">;\n\n/**\n * Define a query that is only accessible from other Convex functions (but not from the client).\n *\n * You should generally use the `internalQuery` function from\n * `\"./_generated/server\"`.\n *\n * Internal queries can read from the database but are **not** exposed as part\n * of your app's public API. They can only be called by other Convex functions\n * using `ctx.runQuery`. This is useful for loading data in actions or for\n * helper queries that shouldn't be client-facing.\n *\n * @example\n * ```typescript\n * import { internalQuery } from \"./_generated/server\";\n * import { v } from \"convex/values\";\n *\n * // Only callable from other Convex functions:\n * export const getUser = internalQuery({\n * args: { userId: v.id(\"users\") },\n * returns: v.union(\n * v.object({\n * _id: v.id(\"users\"),\n * _creationTime: v.number(),\n * name: v.string(),\n * email: v.string(),\n * }),\n * v.null(),\n * ),\n * handler: async (ctx, args) => {\n * return await ctx.db.get(\"users\", args.userId);\n * },\n * });\n * ```\n *\n * **Best practice:** Use `internalQuery` for data-loading in actions via\n * `ctx.runQuery(internal.myModule.getUser, { userId })`.\n *\n * @param func - The query function. It receives a {@link GenericQueryCtx} as its first argument.\n * @returns The wrapped query. Include this as an `export` to name it and make it accessible.\n *\n * @see https://docs.convex.dev/functions/internal-functions\n * @public\n */\nexport const internalQueryGeneric: QueryBuilder<any, \"internal\"> = ((\n functionDefinition: FunctionDefinition,\n) => {\n const handler = (\n typeof functionDefinition === \"function\"\n ? functionDefinition\n : functionDefinition.handler\n ) as (ctx: GenericQueryCtx<any>, args: any) => any;\n const func = dontCallDirectly(\"internalQuery\", handler) as RegisteredQuery<\n \"internal\",\n any,\n any\n >;\n\n assertNotBrowser();\n func.isQuery = true;\n func.isInternal = true;\n func.invokeQuery = (argsStr) =>\n invokeQuery(handler as any, argsStr, \"internal\");\n func.exportArgs = exportArgs(functionDefinition);\n func.exportReturns = exportReturns(functionDefinition);\n func._handler = handler;\n return func;\n}) as QueryBuilder<any, \"internal\">;\n\nasync function invokeAction<\n F extends (ctx: GenericActionCtx<GenericDataModel>, ...args: any) => any,\n>(func: F, requestId: string, argsStr: string, visibility: FunctionVisibility) {\n (globalThis as any).Convex?.setupPerformance?.();\n const args = jsonToConvex(JSON.parse(argsStr));\n const calls = setupActionCalls(requestId);\n const ctx = {\n ...calls,\n auth: setupAuth(requestId),\n scheduler: setupActionScheduler(requestId),\n storage: setupStorageActionWriter(requestId),\n vectorSearch: setupActionVectorSearch(requestId) as any,\n meta: setupActionMeta(visibility),\n };\n const result = await invokeFunction(func, ctx, args as any);\n return JSON.stringify(convexToJson(result === undefined ? null : result));\n}\n\n/**\n * Define an action in this Convex app's public API.\n *\n * Actions can call third-party APIs, use Node.js libraries, and perform other\n * side effects. Unlike queries and mutations, actions do **not** have direct\n * database access (`ctx.db` is not available). Instead, use `ctx.runQuery`\n * and `ctx.runMutation` to read and write data.\n *\n * You should generally use the `action` function from\n * `\"./_generated/server\"`.\n *\n * Actions are accessible from the client and run outside of the database\n * transaction, so they are not atomic. They are best for integrating with\n * external services.\n *\n * @example\n * ```typescript\n * // Add \"use node\"; at the top of the file if using Node.js built-in modules.\n * import { action } from \"./_generated/server\";\n * import { v } from \"convex/values\";\n * import { internal } from \"./_generated/api\";\n *\n * export const generateSummary = action({\n * args: { text: v.string() },\n * returns: v.string(),\n * handler: async (ctx, args) => {\n * // Call an external API:\n * const response = await fetch(\"https://api.example.com/summarize\", {\n * method: \"POST\",\n * body: JSON.stringify({ text: args.text }),\n * });\n * const { summary } = await response.json();\n *\n * // Write results back via a mutation:\n * await ctx.runMutation(internal.myModule.saveSummary, {\n * text: args.text,\n * summary,\n * });\n *\n * return summary;\n * },\n * });\n * ```\n *\n * **Best practice:** Minimize the number of `ctx.runQuery` and\n * `ctx.runMutation` calls from actions. Each call is a separate transaction,\n * so splitting logic across multiple calls introduces the risk of race\n * conditions. Try to batch reads/writes into single query/mutation calls.\n *\n * **`\"use node\"` runtime:** Actions run in Convex's default JavaScript\n * runtime, which supports `fetch` and most NPM packages. Only add\n * `\"use node\";` at the top of the file if a third-party library specifically\n * requires Node.js built-in APIs, it is a last resort, not the default.\n * Node.js actions have slower cold starts, and **only actions can be defined\n * in `\"use node\"` files** (no queries or mutations), so prefer the default\n * runtime whenever possible.\n *\n * **Common mistake:** Do not try to access `ctx.db` in an action, it is\n * not available. Use `ctx.runQuery` and `ctx.runMutation` instead.\n *\n * @param func - The function. It receives a {@link GenericActionCtx} as its first argument.\n * @returns The wrapped function. Include this as an `export` to name it and make it accessible.\n *\n * @see https://docs.convex.dev/functions/actions\n * @public\n */\nexport const actionGeneric: ActionBuilder<any, \"public\"> = ((\n functionDefinition: FunctionDefinition,\n) => {\n const handler = (\n typeof functionDefinition === \"function\"\n ? functionDefinition\n : functionDefinition.handler\n ) as (ctx: GenericActionCtx<any>, args: any) => any;\n const func = dontCallDirectly(\"action\", handler) as RegisteredAction<\n \"public\",\n any,\n any\n >;\n\n assertNotBrowser();\n func.isAction = true;\n func.isPublic = true;\n func.invokeAction = (requestId, argsStr) =>\n invokeAction(handler, requestId, argsStr, \"public\");\n func.exportArgs = exportArgs(functionDefinition);\n func.exportReturns = exportReturns(functionDefinition);\n func._handler = handler;\n return func;\n}) as ActionBuilder<any, \"public\">;\n\n/**\n * Define an action that is only accessible from other Convex functions (but not from the client).\n *\n * You should generally use the `internalAction` function from\n * `\"./_generated/server\"`.\n *\n * Internal actions behave like public actions (they can call external APIs and\n * use Node.js libraries) but are **not** exposed in your app's public API. They\n * can only be called by other Convex functions using `ctx.runAction` or via the\n * scheduler.\n *\n * @example\n * ```typescript\n * import { internalAction } from \"./_generated/server\";\n * import { v } from \"convex/values\";\n *\n * export const sendEmail = internalAction({\n * args: { to: v.string(), subject: v.string(), body: v.string() },\n * returns: v.null(),\n * handler: async (ctx, args) => {\n * // Call an external email service (fetch works in the default runtime):\n * await fetch(\"https://api.email-service.com/send\", {\n * method: \"POST\",\n * headers: { \"Content-Type\": \"application/json\" },\n * body: JSON.stringify(args),\n * });\n * return null;\n * },\n * });\n * ```\n *\n * **Best practice:** Use `internalAction` for background work scheduled from\n * mutations: `await ctx.scheduler.runAfter(0, internal.myModule.sendEmail, { ... })`.\n * Only use `ctx.runAction` from another action if you need to cross runtimes\n * (e.g., default Convex runtime to Node.js). Otherwise, extract shared code\n * into a helper function.\n *\n * **`\"use node\"` runtime:** Only add `\"use node\";` at the top of the file\n * as a last resort when a third-party library requires Node.js APIs. Node.js\n * actions have slower cold starts, and **only actions can be defined in\n * `\"use node\"` files** (no queries or mutations).\n *\n * @param func - The function. It receives a {@link GenericActionCtx} as its first argument.\n * @returns The wrapped function. Include this as an `export` to name it and make it accessible.\n *\n * @see https://docs.convex.dev/functions/internal-functions\n * @public\n */\nexport const internalActionGeneric: ActionBuilder<any, \"internal\"> = ((\n functionDefinition: FunctionDefinition,\n) => {\n const handler = (\n typeof functionDefinition === \"function\"\n ? functionDefinition\n : functionDefinition.handler\n ) as (ctx: GenericActionCtx<any>, args: any) => any;\n const func = dontCallDirectly(\"internalAction\", handler) as RegisteredAction<\n \"internal\",\n any,\n any\n >;\n\n assertNotBrowser();\n func.isAction = true;\n func.isInternal = true;\n func.invokeAction = (requestId, argsStr) =>\n invokeAction(handler, requestId, argsStr, \"internal\");\n func.exportArgs = exportArgs(functionDefinition);\n func.exportReturns = exportReturns(functionDefinition);\n func._handler = handler;\n return func;\n}) as ActionBuilder<any, \"internal\">;\n\nasync function invokeHttpAction<\n F extends (ctx: GenericActionCtx<GenericDataModel>, request: Request) => any,\n>(func: F, request: Request) {\n (globalThis as any).Convex?.setupPerformance?.();\n // TODO(presley): Change the function signature and propagate the requestId from Rust.\n // Ok, to mock it out for now, since http endpoints are only running in V8.\n const requestId = \"\";\n const calls = setupActionCalls(requestId);\n const ctx = {\n ...calls,\n auth: setupAuth(requestId),\n storage: setupStorageActionWriter(requestId),\n scheduler: setupActionScheduler(requestId),\n vectorSearch: setupActionVectorSearch(requestId) as any,\n meta: setupActionMeta(\"public\"),\n };\n return await invokeFunction(func, ctx, [request]);\n}\n\n/**\n * Define a Convex HTTP action.\n *\n * HTTP actions handle raw HTTP requests and return HTTP responses. They are\n * registered by routing URL paths to them in `convex/http.ts` using\n * {@link HttpRouter}. Like regular actions, they can call external APIs and\n * use `ctx.runQuery` / `ctx.runMutation` but do not have direct `ctx.db` access.\n *\n * @example\n * ```typescript\n * // convex/http.ts\n * import { httpRouter } from \"convex/server\";\n * import { httpAction } from \"./_generated/server\";\n *\n * const http = httpRouter();\n *\n * http.route({\n * path: \"/api/webhook\",\n * method: \"POST\",\n * handler: httpAction(async (ctx, request) => {\n * const body = await request.json();\n * // Process the webhook payload...\n * return new Response(JSON.stringify({ ok: true }), {\n * status: 200,\n * headers: { \"Content-Type\": \"application/json\" },\n * });\n * }),\n * });\n *\n * export default http;\n * ```\n *\n * **Best practice:** HTTP actions are registered at the exact path specified.\n * For example, `path: \"/api/webhook\"` registers at `/api/webhook`.\n *\n * @param func - The function. It receives a {@link GenericActionCtx} as its first argument, and a `Request` object\n * as its second.\n * @returns The wrapped function. Route a URL path to this function in `convex/http.ts`.\n *\n * @see https://docs.convex.dev/functions/http-actions\n * @public\n */\nexport const httpActionGeneric = (\n func: (\n ctx: GenericActionCtx<GenericDataModel>,\n request: Request,\n ) => Promise<Response>,\n): PublicHttpAction => {\n const q = dontCallDirectly(\"httpAction\", func) as PublicHttpAction;\n assertNotBrowser();\n q.isHttp = true;\n q.invokeHttpAction = (request) => invokeHttpAction(func as any, request);\n q._handler = func;\n return q;\n};\n\nasync function runUdf(\n udfType: \"query\" | \"mutation\" | \"snapshotQuery\",\n f: any,\n args?: Record<string, Value>,\n transactionLimits?: Record<string, number>,\n): Promise<any> {\n const queryArgs = parseArgs(args);\n const syscallArgs: Record<string, any> = {\n udfType,\n args: convexToJson(queryArgs),\n ...getFunctionAddress(f),\n };\n if (transactionLimits) {\n syscallArgs.transactionLimits = transactionLimits;\n }\n const result = await performAsyncSyscall(\"1.0/runUdf\", syscallArgs);\n return jsonToConvex(result);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAQO;AAgBP,0BAAiC;AACjC,gCAAwC;AACxC,iCAA0B;AAC1B,2BAAyC;AACzC,wBAAgD;AAChD,4BAGO;AACP,0BAIO;AACP,oBAA0B;AAC1B,qBAAoC;AACpC,uBAAkC;AAClC,mBAAmC;AACnC,uBAIO;AAEP,eAAe,eAEb,MAAS,SAAiB,YAAgC;AAG1D,QAAM,YAAY;AAClB,QAAM,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,CAAC,YAAY,YAAY,SAAS,SAAS,QAAQ;AACtE,OAAK,aAAa,WAAW,kBAAkB;AAC/C,OAAK,gBAAgB,cAAc,kBAAkB;AACrD,OAAK,WAAW;AAChB,SAAO;AACT;AA6CO,MAAM,wBAAuD,CAClE,uBACG;AACH,QAAM,UACJ,OAAO,uBAAuB,aAC1B,qBACA,mBAAmB;AAEzB,QAAM,OAAO,iBAAiB,iBAAiB,OAAO;AAMtD,mBAAiB;AACjB,OAAK,UAAU;AACf,OAAK,aAAa;AAClB,OAAK,cAAc,CAAC,YAClB,YAAY,SAAgB,SAAS,UAAU;AACjD,OAAK,aAAa,WAAW,kBAAkB;AAC/C,OAAK,gBAAgB,cAAc,kBAAkB;AACrD,OAAK,WAAW;AAChB,SAAO;AACT;AAEA,eAAe,aAEb,MAAS,WAAmB,SAAiB,YAAgC;AAC7E,
|
|
4
|
+
"sourcesContent": ["import {\n ConvexError,\n convexToJson,\n GenericValidator,\n jsonToConvex,\n v,\n Validator,\n Value,\n} from \"../../values/index.js\";\nimport { GenericDataModel } from \"../data_model.js\";\nimport {\n ActionBuilder,\n DefaultFunctionArgs,\n FunctionVisibility,\n GenericActionCtx,\n GenericMutationCtx,\n GenericQueryCtx,\n MutationBuilder,\n PublicHttpAction,\n QueryBuilder,\n RegisteredAction,\n RegisteredMutation,\n RegisteredQuery,\n} from \"../registration.js\";\nimport { setupActionCalls } from \"./actions_impl.js\";\nimport { setupActionVectorSearch } from \"./vector_search_impl.js\";\nimport { setupAuth } from \"./authentication_impl.js\";\nimport { setupReader, setupWriter } from \"./database_impl.js\";\nimport { QueryImpl, QueryInitializerImpl } from \"./query_impl.js\";\nimport {\n setupActionScheduler,\n setupMutationScheduler,\n} from \"./scheduler_impl.js\";\nimport {\n setupStorageActionWriter,\n setupStorageReader,\n setupStorageWriter,\n} from \"./storage_impl.js\";\nimport { parseArgs } from \"../../common/index.js\";\nimport { performAsyncSyscall } from \"./syscall.js\";\nimport { asObjectValidator } from \"../../values/validator.js\";\nimport { getFunctionAddress } from \"../components/paths.js\";\nimport {\n setupQueryMeta,\n setupMutationMeta,\n setupActionMeta,\n} from \"./meta_impl.js\";\n\nasync function invokeMutation<\n F extends (ctx: GenericMutationCtx<GenericDataModel>, ...args: any) => any,\n>(func: F, argsStr: string, visibility: FunctionVisibility) {\n // TODO(presley): Change the function signature and propagate the requestId from Rust.\n // Ok, to mock it out for now, since queries are only running in V8.\n const requestId = \"\";\n const args = jsonToConvex(JSON.parse(argsStr));\n const mutationCtx = {\n db: setupWriter(),\n auth: setupAuth(requestId),\n storage: setupStorageWriter(requestId),\n scheduler: setupMutationScheduler(),\n meta: setupMutationMeta(visibility),\n\n runQuery: (reference: any, args?: any, options?: any) =>\n options?.useStaleSnapshot\n ? runUdf(\"snapshotQuery\", reference, args, options?.transactionLimits)\n : runUdf(\"query\", reference, args, options?.transactionLimits),\n runMutation: (reference: any, args?: any, options?: any) =>\n runUdf(\"mutation\", reference, args, options?.transactionLimits),\n };\n const result = await invokeFunction(func, mutationCtx, args as any);\n validateReturnValue(result);\n return JSON.stringify(convexToJson(result === undefined ? null : result));\n}\n\nexport function validateReturnValue(v: any) {\n if (v instanceof QueryInitializerImpl || v instanceof QueryImpl) {\n throw new Error(\n \"Return value is a Query. Results must be retrieved with `.collect()`, `.take(n), `.unique()`, or `.first()`.\",\n );\n }\n}\n\nexport async function invokeFunction<\n Ctx,\n Args extends any[],\n F extends (ctx: Ctx, ...args: Args) => any,\n>(func: F, ctx: Ctx, args: Args) {\n let result;\n try {\n result = await Promise.resolve(func(ctx, ...args));\n } catch (thrown: unknown) {\n throw serializeConvexErrorData(thrown);\n }\n return result;\n}\n\nfunction dontCallDirectly(\n funcType: string,\n handler: (ctx: any, args: any) => any,\n): unknown {\n return (ctx: any, args: any) => {\n globalThis.console.warn(\n \"Convex functions should not directly call other Convex functions. Consider calling a helper function instead. \" +\n `e.g. \\`export const foo = ${funcType}(...); await foo(ctx);\\` is not supported. ` +\n \"See https://docs.convex.dev/production/best-practices/#use-helper-functions-to-write-shared-code\",\n );\n return handler(ctx, args);\n };\n}\n\n// Keep in sync with node executor\nfunction serializeConvexErrorData(thrown: unknown) {\n if (\n typeof thrown === \"object\" &&\n thrown !== null &&\n Symbol.for(\"ConvexError\") in thrown\n ) {\n const error = thrown as ConvexError<any>;\n error.data = JSON.stringify(\n convexToJson(error.data === undefined ? null : error.data),\n );\n (error as any).ConvexErrorSymbol = Symbol.for(\"ConvexError\");\n return error;\n } else {\n return thrown;\n }\n}\n\n/**\n * Guard against Convex functions accidentally getting included in a browser bundle.\n * Convex functions may include secret logic or credentials that should not be\n * send to untrusted clients (browsers).\n */\nfunction assertNotBrowser() {\n if (\n typeof window === \"undefined\" ||\n (window as any).__convexAllowFunctionsInBrowser\n ) {\n return;\n }\n // JSDom doesn't count, developers are allowed to use JSDom in Convex functions.\n const isRealBrowser =\n Object.getOwnPropertyDescriptor(globalThis, \"window\")\n ?.get?.toString()\n .includes(\"[native code]\") ?? false;\n if (isRealBrowser) {\n // eslint-disable-next-line no-console\n console.error(\n \"Convex functions should not be imported in the browser. This will throw an error in future versions of `convex`. If this is a false negative, please report it to Convex support.\",\n );\n }\n}\n\ntype FunctionDefinition =\n | ((ctx: any, args: DefaultFunctionArgs) => any)\n | {\n args?: GenericValidator | Record<string, GenericValidator>;\n returns?: GenericValidator | Record<string, GenericValidator>;\n handler: (ctx: any, args: DefaultFunctionArgs) => any;\n };\n\nfunction strictReplacer(key: string, value: any) {\n if (value === undefined) {\n throw new Error(\n `A validator is undefined for field \"${key}\". ` +\n `This is often caused by circular imports. ` +\n `See https://docs.convex.dev/error#undefined-validator for details.`,\n );\n }\n return value;\n}\nfunction exportArgs(functionDefinition: FunctionDefinition) {\n return () => {\n let args: GenericValidator = v.any();\n if (\n typeof functionDefinition === \"object\" &&\n functionDefinition.args !== undefined\n ) {\n args = asObjectValidator(functionDefinition.args);\n }\n return JSON.stringify(args.json, strictReplacer);\n };\n}\n\nfunction exportReturns(functionDefinition: FunctionDefinition) {\n return () => {\n let returns: Validator<any, any, any> | undefined;\n if (\n typeof functionDefinition === \"object\" &&\n functionDefinition.returns !== undefined\n ) {\n returns = asObjectValidator(functionDefinition.returns);\n }\n return JSON.stringify(returns ? returns.json : null, strictReplacer);\n };\n}\n\n/**\n * Define a mutation in this Convex app's public API.\n *\n * You should generally use the `mutation` function from\n * `\"./_generated/server\"`.\n *\n * Mutations can read from and write to the database, and are accessible from\n * the client. They run **transactionally**, all database reads and writes\n * within a single mutation are atomic and isolated from other mutations.\n *\n * @example\n * ```typescript\n * import { mutation } from \"./_generated/server\";\n * import { v } from \"convex/values\";\n *\n * export const createTask = mutation({\n * args: { text: v.string() },\n * returns: v.id(\"tasks\"),\n * handler: async (ctx, args) => {\n * const taskId = await ctx.db.insert(\"tasks\", {\n * text: args.text,\n * completed: false,\n * });\n * return taskId;\n * },\n * });\n * ```\n *\n * **Best practice:** Always include `args` and `returns` validators on all\n * mutations. If the function doesn't return a value, use `returns: v.null()`.\n * Argument validation is critical for security since public mutations are\n * exposed to the internet.\n *\n * **Common mistake:** Mutations cannot call third-party APIs or use `fetch`.\n * They must be deterministic. Use actions for external API calls.\n *\n * **Common mistake:** Do not use `mutation` for sensitive internal functions\n * that should not be called by clients. Use `internalMutation` instead.\n *\n * @param func - The mutation function. It receives a {@link GenericMutationCtx} as its first argument.\n * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.\n *\n * @see https://docs.convex.dev/functions/mutation-functions\n * @public\n */\nexport const mutationGeneric: MutationBuilder<any, \"public\"> = ((\n functionDefinition: FunctionDefinition,\n) => {\n const handler = (\n typeof functionDefinition === \"function\"\n ? functionDefinition\n : functionDefinition.handler\n ) as (ctx: GenericMutationCtx<any>, args: any) => any;\n const func = dontCallDirectly(\"mutation\", handler) as RegisteredMutation<\n \"public\",\n any,\n any\n >;\n\n assertNotBrowser();\n func.isMutation = true;\n func.isPublic = true;\n func.invokeMutation = (argsStr) => invokeMutation(handler, argsStr, \"public\");\n func.exportArgs = exportArgs(functionDefinition);\n func.exportReturns = exportReturns(functionDefinition);\n func._handler = handler;\n return func;\n}) as MutationBuilder<any, \"public\">;\n\n/**\n * Define a mutation that is only accessible from other Convex functions (but not from the client).\n *\n * You should generally use the `internalMutation` function from\n * `\"./_generated/server\"`.\n *\n * Internal mutations can read from and write to the database but are **not**\n * exposed as part of your app's public API. They can only be called by other\n * Convex functions using `ctx.runMutation` or by the scheduler. Like public\n * mutations, they run transactionally.\n *\n * @example\n * ```typescript\n * import { internalMutation } from \"./_generated/server\";\n * import { v } from \"convex/values\";\n *\n * // This mutation can only be called from other Convex functions:\n * export const markTaskCompleted = internalMutation({\n * args: { taskId: v.id(\"tasks\") },\n * returns: v.null(),\n * handler: async (ctx, args) => {\n * await ctx.db.patch(\"tasks\", args.taskId, { completed: true });\n * return null;\n * },\n * });\n * ```\n *\n * **Best practice:** Use `internalMutation` for any mutation that should not\n * be directly callable by clients, such as write-back functions from actions\n * or scheduled background work. Reference it via the `internal` object:\n * `await ctx.runMutation(internal.myModule.markTaskCompleted, { taskId })`.\n *\n * @param func - The mutation function. It receives a {@link GenericMutationCtx} as its first argument.\n * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.\n *\n * @see https://docs.convex.dev/functions/internal-functions\n * @public\n */\nexport const internalMutationGeneric: MutationBuilder<any, \"internal\"> = ((\n functionDefinition: FunctionDefinition,\n) => {\n const handler = (\n typeof functionDefinition === \"function\"\n ? functionDefinition\n : functionDefinition.handler\n ) as (ctx: GenericMutationCtx<any>, args: any) => any;\n const func = dontCallDirectly(\n \"internalMutation\",\n handler,\n ) as RegisteredMutation<\"internal\", any, any>;\n\n assertNotBrowser();\n func.isMutation = true;\n func.isInternal = true;\n func.invokeMutation = (argsStr) =>\n invokeMutation(handler, argsStr, \"internal\");\n func.exportArgs = exportArgs(functionDefinition);\n func.exportReturns = exportReturns(functionDefinition);\n func._handler = handler;\n return func;\n}) as MutationBuilder<any, \"internal\">;\n\nasync function invokeQuery<\n F extends (ctx: GenericQueryCtx<GenericDataModel>, ...args: any) => any,\n>(func: F, argsStr: string, visibility: FunctionVisibility) {\n // TODO(presley): Change the function signature and propagate the requestId from Rust.\n // Ok, to mock it out for now, since queries are only running in V8.\n const requestId = \"\";\n const args = jsonToConvex(JSON.parse(argsStr));\n const queryCtx = {\n db: setupReader(),\n auth: setupAuth(requestId),\n storage: setupStorageReader(requestId),\n meta: setupQueryMeta(visibility),\n runQuery: (reference: any, args?: any, options?: any) => {\n if (options?.useStaleSnapshot) {\n throw new Error(\n \"`useStaleSnapshot` is only supported in mutations, not queries.\",\n );\n }\n return runUdf(\"query\", reference, args, options?.transactionLimits);\n },\n };\n const result = await invokeFunction(func, queryCtx, args as any);\n validateReturnValue(result);\n return JSON.stringify(convexToJson(result === undefined ? null : result));\n}\n\n/**\n * Define a query in this Convex app's public API.\n *\n * You should generally use the `query` function from\n * `\"./_generated/server\"`.\n *\n * Queries can read from the database and are accessible from the client. They\n * are **reactive**, when used with `useQuery` in React, the component\n * automatically re-renders whenever the underlying data changes. Queries\n * cannot modify the database.\n * Query results are automatically cached by the Convex client and kept\n * consistent via WebSocket subscriptions.\n *\n *\n * @example\n * ```typescript\n * import { query } from \"./_generated/server\";\n * import { v } from \"convex/values\";\n *\n * export const listTasks = query({\n * args: { completed: v.optional(v.boolean()) },\n * returns: v.array(v.object({\n * _id: v.id(\"tasks\"),\n * _creationTime: v.number(),\n * text: v.string(),\n * completed: v.boolean(),\n * })),\n * handler: async (ctx, args) => {\n * if (args.completed !== undefined) {\n * return await ctx.db\n * .query(\"tasks\")\n * .withIndex(\"by_completed\", (q) => q.eq(\"completed\", args.completed))\n * .collect();\n * }\n * return await ctx.db.query(\"tasks\").collect();\n * },\n * });\n * ```\n *\n * **Best practice:** Always include `args` and `returns` validators. Use\n * `.withIndex()` instead of `.filter()` for efficient database queries.\n * Queries should be fast since they run on every relevant data change.\n *\n * **Common mistake:** Queries are pure reads, they cannot write to the\n * database, call external APIs, or schedule functions. Use actions for HTTP\n * calls and mutations for database writes and scheduling.\n *\n * @param func - The query function. It receives a {@link GenericQueryCtx} as its first argument.\n * @returns The wrapped query. Include this as an `export` to name it and make it accessible.\n *\n * @see https://docs.convex.dev/functions/query-functions\n * @public\n */\nexport const queryGeneric: QueryBuilder<any, \"public\"> = ((\n functionDefinition: FunctionDefinition,\n) => {\n const handler = (\n typeof functionDefinition === \"function\"\n ? functionDefinition\n : functionDefinition.handler\n ) as (ctx: GenericQueryCtx<any>, args: any) => any;\n const func = dontCallDirectly(\"query\", handler) as RegisteredQuery<\n \"public\",\n any,\n any\n >;\n\n assertNotBrowser();\n func.isQuery = true;\n func.isPublic = true;\n func.invokeQuery = (argsStr) => invokeQuery(handler, argsStr, \"public\");\n func.exportArgs = exportArgs(functionDefinition);\n func.exportReturns = exportReturns(functionDefinition);\n func._handler = handler;\n return func;\n}) as QueryBuilder<any, \"public\">;\n\n/**\n * Define a query that is only accessible from other Convex functions (but not from the client).\n *\n * You should generally use the `internalQuery` function from\n * `\"./_generated/server\"`.\n *\n * Internal queries can read from the database but are **not** exposed as part\n * of your app's public API. They can only be called by other Convex functions\n * using `ctx.runQuery`. This is useful for loading data in actions or for\n * helper queries that shouldn't be client-facing.\n *\n * @example\n * ```typescript\n * import { internalQuery } from \"./_generated/server\";\n * import { v } from \"convex/values\";\n *\n * // Only callable from other Convex functions:\n * export const getUser = internalQuery({\n * args: { userId: v.id(\"users\") },\n * returns: v.union(\n * v.object({\n * _id: v.id(\"users\"),\n * _creationTime: v.number(),\n * name: v.string(),\n * email: v.string(),\n * }),\n * v.null(),\n * ),\n * handler: async (ctx, args) => {\n * return await ctx.db.get(\"users\", args.userId);\n * },\n * });\n * ```\n *\n * **Best practice:** Use `internalQuery` for data-loading in actions via\n * `ctx.runQuery(internal.myModule.getUser, { userId })`.\n *\n * @param func - The query function. It receives a {@link GenericQueryCtx} as its first argument.\n * @returns The wrapped query. Include this as an `export` to name it and make it accessible.\n *\n * @see https://docs.convex.dev/functions/internal-functions\n * @public\n */\nexport const internalQueryGeneric: QueryBuilder<any, \"internal\"> = ((\n functionDefinition: FunctionDefinition,\n) => {\n const handler = (\n typeof functionDefinition === \"function\"\n ? functionDefinition\n : functionDefinition.handler\n ) as (ctx: GenericQueryCtx<any>, args: any) => any;\n const func = dontCallDirectly(\"internalQuery\", handler) as RegisteredQuery<\n \"internal\",\n any,\n any\n >;\n\n assertNotBrowser();\n func.isQuery = true;\n func.isInternal = true;\n func.invokeQuery = (argsStr) =>\n invokeQuery(handler as any, argsStr, \"internal\");\n func.exportArgs = exportArgs(functionDefinition);\n func.exportReturns = exportReturns(functionDefinition);\n func._handler = handler;\n return func;\n}) as QueryBuilder<any, \"internal\">;\n\nasync function invokeAction<\n F extends (ctx: GenericActionCtx<GenericDataModel>, ...args: any) => any,\n>(func: F, requestId: string, argsStr: string, visibility: FunctionVisibility) {\n const args = jsonToConvex(JSON.parse(argsStr));\n const calls = setupActionCalls(requestId);\n const ctx = {\n ...calls,\n auth: setupAuth(requestId),\n scheduler: setupActionScheduler(requestId),\n storage: setupStorageActionWriter(requestId),\n vectorSearch: setupActionVectorSearch(requestId) as any,\n meta: setupActionMeta(visibility),\n };\n const result = await invokeFunction(func, ctx, args as any);\n return JSON.stringify(convexToJson(result === undefined ? null : result));\n}\n\n/**\n * Define an action in this Convex app's public API.\n *\n * Actions can call third-party APIs, use Node.js libraries, and perform other\n * side effects. Unlike queries and mutations, actions do **not** have direct\n * database access (`ctx.db` is not available). Instead, use `ctx.runQuery`\n * and `ctx.runMutation` to read and write data.\n *\n * You should generally use the `action` function from\n * `\"./_generated/server\"`.\n *\n * Actions are accessible from the client and run outside of the database\n * transaction, so they are not atomic. They are best for integrating with\n * external services.\n *\n * @example\n * ```typescript\n * // Add \"use node\"; at the top of the file if using Node.js built-in modules.\n * import { action } from \"./_generated/server\";\n * import { v } from \"convex/values\";\n * import { internal } from \"./_generated/api\";\n *\n * export const generateSummary = action({\n * args: { text: v.string() },\n * returns: v.string(),\n * handler: async (ctx, args) => {\n * // Call an external API:\n * const response = await fetch(\"https://api.example.com/summarize\", {\n * method: \"POST\",\n * body: JSON.stringify({ text: args.text }),\n * });\n * const { summary } = await response.json();\n *\n * // Write results back via a mutation:\n * await ctx.runMutation(internal.myModule.saveSummary, {\n * text: args.text,\n * summary,\n * });\n *\n * return summary;\n * },\n * });\n * ```\n *\n * **Best practice:** Minimize the number of `ctx.runQuery` and\n * `ctx.runMutation` calls from actions. Each call is a separate transaction,\n * so splitting logic across multiple calls introduces the risk of race\n * conditions. Try to batch reads/writes into single query/mutation calls.\n *\n * **`\"use node\"` runtime:** Actions run in Convex's default JavaScript\n * runtime, which supports `fetch` and most NPM packages. Only add\n * `\"use node\";` at the top of the file if a third-party library specifically\n * requires Node.js built-in APIs, it is a last resort, not the default.\n * Node.js actions have slower cold starts, and **only actions can be defined\n * in `\"use node\"` files** (no queries or mutations), so prefer the default\n * runtime whenever possible.\n *\n * **Common mistake:** Do not try to access `ctx.db` in an action, it is\n * not available. Use `ctx.runQuery` and `ctx.runMutation` instead.\n *\n * @param func - The function. It receives a {@link GenericActionCtx} as its first argument.\n * @returns The wrapped function. Include this as an `export` to name it and make it accessible.\n *\n * @see https://docs.convex.dev/functions/actions\n * @public\n */\nexport const actionGeneric: ActionBuilder<any, \"public\"> = ((\n functionDefinition: FunctionDefinition,\n) => {\n const handler = (\n typeof functionDefinition === \"function\"\n ? functionDefinition\n : functionDefinition.handler\n ) as (ctx: GenericActionCtx<any>, args: any) => any;\n const func = dontCallDirectly(\"action\", handler) as RegisteredAction<\n \"public\",\n any,\n any\n >;\n\n assertNotBrowser();\n func.isAction = true;\n func.isPublic = true;\n func.invokeAction = (requestId, argsStr) =>\n invokeAction(handler, requestId, argsStr, \"public\");\n func.exportArgs = exportArgs(functionDefinition);\n func.exportReturns = exportReturns(functionDefinition);\n func._handler = handler;\n return func;\n}) as ActionBuilder<any, \"public\">;\n\n/**\n * Define an action that is only accessible from other Convex functions (but not from the client).\n *\n * You should generally use the `internalAction` function from\n * `\"./_generated/server\"`.\n *\n * Internal actions behave like public actions (they can call external APIs and\n * use Node.js libraries) but are **not** exposed in your app's public API. They\n * can only be called by other Convex functions using `ctx.runAction` or via the\n * scheduler.\n *\n * @example\n * ```typescript\n * import { internalAction } from \"./_generated/server\";\n * import { v } from \"convex/values\";\n *\n * export const sendEmail = internalAction({\n * args: { to: v.string(), subject: v.string(), body: v.string() },\n * returns: v.null(),\n * handler: async (ctx, args) => {\n * // Call an external email service (fetch works in the default runtime):\n * await fetch(\"https://api.email-service.com/send\", {\n * method: \"POST\",\n * headers: { \"Content-Type\": \"application/json\" },\n * body: JSON.stringify(args),\n * });\n * return null;\n * },\n * });\n * ```\n *\n * **Best practice:** Use `internalAction` for background work scheduled from\n * mutations: `await ctx.scheduler.runAfter(0, internal.myModule.sendEmail, { ... })`.\n * Only use `ctx.runAction` from another action if you need to cross runtimes\n * (e.g., default Convex runtime to Node.js). Otherwise, extract shared code\n * into a helper function.\n *\n * **`\"use node\"` runtime:** Only add `\"use node\";` at the top of the file\n * as a last resort when a third-party library requires Node.js APIs. Node.js\n * actions have slower cold starts, and **only actions can be defined in\n * `\"use node\"` files** (no queries or mutations).\n *\n * @param func - The function. It receives a {@link GenericActionCtx} as its first argument.\n * @returns The wrapped function. Include this as an `export` to name it and make it accessible.\n *\n * @see https://docs.convex.dev/functions/internal-functions\n * @public\n */\nexport const internalActionGeneric: ActionBuilder<any, \"internal\"> = ((\n functionDefinition: FunctionDefinition,\n) => {\n const handler = (\n typeof functionDefinition === \"function\"\n ? functionDefinition\n : functionDefinition.handler\n ) as (ctx: GenericActionCtx<any>, args: any) => any;\n const func = dontCallDirectly(\"internalAction\", handler) as RegisteredAction<\n \"internal\",\n any,\n any\n >;\n\n assertNotBrowser();\n func.isAction = true;\n func.isInternal = true;\n func.invokeAction = (requestId, argsStr) =>\n invokeAction(handler, requestId, argsStr, \"internal\");\n func.exportArgs = exportArgs(functionDefinition);\n func.exportReturns = exportReturns(functionDefinition);\n func._handler = handler;\n return func;\n}) as ActionBuilder<any, \"internal\">;\n\nasync function invokeHttpAction<\n F extends (ctx: GenericActionCtx<GenericDataModel>, request: Request) => any,\n>(func: F, request: Request) {\n // TODO(presley): Change the function signature and propagate the requestId from Rust.\n // Ok, to mock it out for now, since http endpoints are only running in V8.\n const requestId = \"\";\n const calls = setupActionCalls(requestId);\n const ctx = {\n ...calls,\n auth: setupAuth(requestId),\n storage: setupStorageActionWriter(requestId),\n scheduler: setupActionScheduler(requestId),\n vectorSearch: setupActionVectorSearch(requestId) as any,\n meta: setupActionMeta(\"public\"),\n };\n return await invokeFunction(func, ctx, [request]);\n}\n\n/**\n * Define a Convex HTTP action.\n *\n * HTTP actions handle raw HTTP requests and return HTTP responses. They are\n * registered by routing URL paths to them in `convex/http.ts` using\n * {@link HttpRouter}. Like regular actions, they can call external APIs and\n * use `ctx.runQuery` / `ctx.runMutation` but do not have direct `ctx.db` access.\n *\n * @example\n * ```typescript\n * // convex/http.ts\n * import { httpRouter } from \"convex/server\";\n * import { httpAction } from \"./_generated/server\";\n *\n * const http = httpRouter();\n *\n * http.route({\n * path: \"/api/webhook\",\n * method: \"POST\",\n * handler: httpAction(async (ctx, request) => {\n * const body = await request.json();\n * // Process the webhook payload...\n * return new Response(JSON.stringify({ ok: true }), {\n * status: 200,\n * headers: { \"Content-Type\": \"application/json\" },\n * });\n * }),\n * });\n *\n * export default http;\n * ```\n *\n * **Best practice:** HTTP actions are registered at the exact path specified.\n * For example, `path: \"/api/webhook\"` registers at `/api/webhook`.\n *\n * @param func - The function. It receives a {@link GenericActionCtx} as its first argument, and a `Request` object\n * as its second.\n * @returns The wrapped function. Route a URL path to this function in `convex/http.ts`.\n *\n * @see https://docs.convex.dev/functions/http-actions\n * @public\n */\nexport const httpActionGeneric = (\n func: (\n ctx: GenericActionCtx<GenericDataModel>,\n request: Request,\n ) => Promise<Response>,\n): PublicHttpAction => {\n const q = dontCallDirectly(\"httpAction\", func) as PublicHttpAction;\n assertNotBrowser();\n q.isHttp = true;\n q.invokeHttpAction = (request) => invokeHttpAction(func as any, request);\n q._handler = func;\n return q;\n};\n\nasync function runUdf(\n udfType: \"query\" | \"mutation\" | \"snapshotQuery\",\n f: any,\n args?: Record<string, Value>,\n transactionLimits?: Record<string, number>,\n): Promise<any> {\n const queryArgs = parseArgs(args);\n const syscallArgs: Record<string, any> = {\n udfType,\n args: convexToJson(queryArgs),\n ...getFunctionAddress(f),\n };\n if (transactionLimits) {\n syscallArgs.transactionLimits = transactionLimits;\n }\n const result = await performAsyncSyscall(\"1.0/runUdf\", syscallArgs);\n return jsonToConvex(result);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAQO;AAgBP,0BAAiC;AACjC,gCAAwC;AACxC,iCAA0B;AAC1B,2BAAyC;AACzC,wBAAgD;AAChD,4BAGO;AACP,0BAIO;AACP,oBAA0B;AAC1B,qBAAoC;AACpC,uBAAkC;AAClC,mBAAmC;AACnC,uBAIO;AAEP,eAAe,eAEb,MAAS,SAAiB,YAAgC;AAG1D,QAAM,YAAY;AAClB,QAAM,WAAO,4BAAa,KAAK,MAAM,OAAO,CAAC;AAC7C,QAAM,cAAc;AAAA,IAClB,QAAI,kCAAY;AAAA,IAChB,UAAM,sCAAU,SAAS;AAAA,IACzB,aAAS,wCAAmB,SAAS;AAAA,IACrC,eAAW,8CAAuB;AAAA,IAClC,UAAM,oCAAkB,UAAU;AAAA,IAElC,UAAU,CAAC,WAAgBA,OAAY,YACrC,SAAS,mBACL,OAAO,iBAAiB,WAAWA,OAAM,SAAS,iBAAiB,IACnE,OAAO,SAAS,WAAWA,OAAM,SAAS,iBAAiB;AAAA,IACjE,aAAa,CAAC,WAAgBA,OAAY,YACxC,OAAO,YAAY,WAAWA,OAAM,SAAS,iBAAiB;AAAA,EAClE;AACA,QAAM,SAAS,MAAM,eAAe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YAAQ,sCAAiB,SAAS;AACxC,QAAM,MAAM;AAAA,IACV,GAAG;AAAA,IACH,UAAM,sCAAU,SAAS;AAAA,IACzB,aAAS,8CAAyB,SAAS;AAAA,IAC3C,eAAW,4CAAqB,SAAS;AAAA,IACzC,kBAAc,mDAAwB,SAAS;AAAA,IAC/C,UAAM,kCAAgB,QAAQ;AAAA,EAChC;AACA,SAAO,MAAM,eAAe,MAAM,KAAK,CAAC,OAAO,CAAC;AAClD;AA4CO,MAAM,oBAAoB,CAC/B,SAIqB;AACrB,QAAM,IAAI,iBAAiB,cAAc,IAAI;AAC7C,mBAAiB;AACjB,IAAE,SAAS;AACX,IAAE,mBAAmB,CAAC,YAAY,iBAAiB,MAAa,OAAO;AACvE,IAAE,WAAW;AACb,SAAO;AACT;AAEA,eAAe,OACb,SACA,GACA,MACA,mBACc;AACd,QAAM,gBAAY,yBAAU,IAAI;AAChC,QAAM,cAAmC;AAAA,IACvC;AAAA,IACA,UAAM,4BAAa,SAAS;AAAA,IAC5B,OAAG,iCAAmB,CAAC;AAAA,EACzB;AACA,MAAI,mBAAmB;AACrB,gBAAY,oBAAoB;AAAA,EAClC;AACA,QAAM,SAAS,UAAM,oCAAoB,cAAc,WAAW;AAClE,aAAO,4BAAa,MAAM;AAC5B;",
|
|
6
6
|
"names": ["args", "v"]
|
|
7
7
|
}
|
|
@@ -33,6 +33,7 @@ export declare class AuthenticationManager {
|
|
|
33
33
|
private readonly clearAuth;
|
|
34
34
|
private readonly logger;
|
|
35
35
|
private readonly refreshTokenLeewaySeconds;
|
|
36
|
+
private readonly initialAuthTokenReuse;
|
|
36
37
|
private lastRefreshChange;
|
|
37
38
|
private tokenConfirmationAttempts;
|
|
38
39
|
constructor(syncState: LocalSyncState, callbacks: {
|
|
@@ -45,6 +46,7 @@ export declare class AuthenticationManager {
|
|
|
45
46
|
}, config: {
|
|
46
47
|
refreshTokenLeewaySeconds: number;
|
|
47
48
|
logger: Logger;
|
|
49
|
+
initialAuthTokenReuse: boolean;
|
|
48
50
|
});
|
|
49
51
|
private notifyRefreshChange;
|
|
50
52
|
setConfig(fetchToken: AuthTokenFetcher, onChange: (isAuthenticated: boolean) => void, onRefreshChange?: (isRefreshing: boolean) => void): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication_manager.d.ts","sourceRoot":"","sources":["../../../../src/browser/sync/authentication_manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AASvE;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE;IACpC,iBAAiB,EAAE,OAAO,CAAC;CAC5B,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"authentication_manager.d.ts","sourceRoot":"","sources":["../../../../src/browser/sync/authentication_manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AASvE;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE;IACpC,iBAAiB,EAAE,OAAO,CAAC;CAC5B,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAuDzC;;;GAGG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,SAAS,CAAkC;IAGnD,OAAO,CAAC,aAAa,CAAK;IAE1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAiB;IAE3C,OAAO,CAAC,QAAQ,CAAC,YA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sBAAsB;IAU9B,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,YAAY;IAiCpB,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,WAAW;CAGpB"}
|
|
@@ -91,6 +91,22 @@ export interface BaseConvexClientOptions {
|
|
|
91
91
|
* Defaults to false, not waiting for an auth token.
|
|
92
92
|
*/
|
|
93
93
|
expectAuth?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* This API is experimental: it may change or disappear.
|
|
96
|
+
*
|
|
97
|
+
* When true, the client reuses the initial cached auth token instead
|
|
98
|
+
* of immediately fetching a fresh one. This avoids a second
|
|
99
|
+
* Authenticate message that causes the server to re-execute all
|
|
100
|
+
* authenticated queries.
|
|
101
|
+
*
|
|
102
|
+
* The cached token's remaining lifetime is estimated using the
|
|
103
|
+
* server's clock skew measurement, and a refresh is scheduled
|
|
104
|
+
* before it expires.
|
|
105
|
+
*
|
|
106
|
+
* Defaults to false, preserving the original behavior of immediately
|
|
107
|
+
* fetching a fresh token after the cached token is confirmed.
|
|
108
|
+
*/
|
|
109
|
+
initialAuthTokenReuse?: boolean;
|
|
94
110
|
}
|
|
95
111
|
/**
|
|
96
112
|
* State describing the client's connection with the Convex backend.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/browser/sync/client.ts"],"names":[],"mappings":"AAUA,OAAO,EAAgB,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAML,MAAM,EACP,MAAM,eAAe,CAAC;AAGvB,OAAO,EAEL,gBAAgB,EACjB,MAAM,yBAAyB,CAAC;AAKjC,OAAO,EAIL,YAAY,EAEZ,SAAS,EACT,EAAE,EAEH,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,UAAU,EAAwB,MAAM,qBAAqB,CAAC;AAGvE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAEL,gBAAgB,EACjB,MAAM,6BAA6B,C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AG,SAAS;IAM3B;;;;;OAKG;IACH,eAAe,IAAI,eAAe;IAelC;;;OAGG;IACH,OAAO,CAAC,wBAAwB,CAe9B;IAEF;;;;;;;;;OASG;IACH,0BAA0B,CACxB,EAAE,EAAE,CAAC,eAAe,EAAE,eAAe,KAAK,IAAI,GAC7C,MAAM,IAAI;IAQb;;;;;;;;;OASG;IACG,QAAQ,CACZ,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAC5B,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,GAAG,CAAC;IA6Gf;;;;;;;OAOG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;IAuCtE;;;;;;;OAOG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAK5B;;;;;OAKG;IACH,IAAI,GAAG,WAEN;IAiBD,OAAO,CAAC,IAAI,CAIV;IAEF;;;OAGG;IACH,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,uBAAuB;CAiChC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "1.42.
|
|
1
|
+
export declare const version = "1.42.1";
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registration_impl.d.ts","sourceRoot":"","sources":["../../../../src/server/impl/registration_impl.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,aAAa,EAGb,gBAAgB,EAGhB,eAAe,EACf,gBAAgB,EAChB,YAAY,EAIb,MAAM,oBAAoB,CAAC;AAmD5B,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,GAAG,QAMzC;AAED,wBAAsB,cAAc,CAClC,GAAG,EACH,IAAI,SAAS,GAA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47529
|
-
version = "1.42.
|
|
47529
|
+
version = "1.42.1";
|
|
47530
47530
|
}
|
|
47531
47531
|
});
|
|
47532
47532
|
|
|
@@ -119524,6 +119524,7 @@ var AuthenticationManager = class {
|
|
|
119524
119524
|
clearAuth;
|
|
119525
119525
|
logger;
|
|
119526
119526
|
refreshTokenLeewaySeconds;
|
|
119527
|
+
initialAuthTokenReuse;
|
|
119527
119528
|
// Track last value to avoid redundant calls
|
|
119528
119529
|
lastRefreshChange;
|
|
119529
119530
|
// Number of times we have attempted to confirm the latest token. We retry up
|
|
@@ -119539,6 +119540,7 @@ var AuthenticationManager = class {
|
|
|
119539
119540
|
this.clearAuth = callbacks.clearAuth;
|
|
119540
119541
|
this.logger = config3.logger;
|
|
119541
119542
|
this.refreshTokenLeewaySeconds = config3.refreshTokenLeewaySeconds;
|
|
119543
|
+
this.initialAuthTokenReuse = config3.initialAuthTokenReuse;
|
|
119542
119544
|
this.lastRefreshChange = false;
|
|
119543
119545
|
}
|
|
119544
119546
|
notifyRefreshChange(isRefreshing) {
|
|
@@ -119580,6 +119582,7 @@ var AuthenticationManager = class {
|
|
|
119580
119582
|
this.resumeSocket();
|
|
119581
119583
|
}
|
|
119582
119584
|
onTransition(serverMessage) {
|
|
119585
|
+
var _a2;
|
|
119583
119586
|
if (!this.syncState.isCurrentOrNewerAuthVersion(
|
|
119584
119587
|
serverMessage.endVersion.identity
|
|
119585
119588
|
)) {
|
|
@@ -119594,7 +119597,12 @@ var AuthenticationManager = class {
|
|
|
119594
119597
|
this.syncState.markAuthCompletion();
|
|
119595
119598
|
if (this.authState.state === "waitingForServerConfirmationOfCachedToken") {
|
|
119596
119599
|
this._logVerbose("server confirmed auth token is valid");
|
|
119597
|
-
|
|
119600
|
+
const cachedToken = (_a2 = this.syncState.getAuth()) == null ? void 0 : _a2.value;
|
|
119601
|
+
if (this.initialAuthTokenReuse && cachedToken) {
|
|
119602
|
+
this.scheduleTokenRefetch(cachedToken, serverMessage.clientClockSkew);
|
|
119603
|
+
} else {
|
|
119604
|
+
void this.refetchToken();
|
|
119605
|
+
}
|
|
119598
119606
|
this.authState.config.onAuthChange(true);
|
|
119599
119607
|
return;
|
|
119600
119608
|
}
|
|
@@ -119725,7 +119733,7 @@ var AuthenticationManager = class {
|
|
|
119725
119733
|
);
|
|
119726
119734
|
this.tryRestartSocket();
|
|
119727
119735
|
}
|
|
119728
|
-
scheduleTokenRefetch(token) {
|
|
119736
|
+
scheduleTokenRefetch(token, clientClockSkewMs) {
|
|
119729
119737
|
if (this.authState.state === "noAuth") {
|
|
119730
119738
|
return;
|
|
119731
119739
|
}
|
|
@@ -119743,13 +119751,23 @@ var AuthenticationManager = class {
|
|
|
119743
119751
|
);
|
|
119744
119752
|
return;
|
|
119745
119753
|
}
|
|
119746
|
-
const
|
|
119747
|
-
if (
|
|
119754
|
+
const fullLifetimeSeconds = exp - iat;
|
|
119755
|
+
if (fullLifetimeSeconds <= 2) {
|
|
119748
119756
|
this.logger.error(
|
|
119749
119757
|
"Auth token does not live long enough, cannot refetch the token"
|
|
119750
119758
|
);
|
|
119751
119759
|
return;
|
|
119752
119760
|
}
|
|
119761
|
+
let tokenValiditySeconds;
|
|
119762
|
+
if (clientClockSkewMs !== void 0) {
|
|
119763
|
+
const estimatedServerNowSeconds = (Date.now() - clientClockSkewMs) / 1e3;
|
|
119764
|
+
tokenValiditySeconds = exp - estimatedServerNowSeconds;
|
|
119765
|
+
if (tokenValiditySeconds <= 0) {
|
|
119766
|
+
tokenValiditySeconds = 0;
|
|
119767
|
+
}
|
|
119768
|
+
} else {
|
|
119769
|
+
tokenValiditySeconds = fullLifetimeSeconds;
|
|
119770
|
+
}
|
|
119753
119771
|
let delay = Math.min(
|
|
119754
119772
|
MAXIMUM_REFRESH_DELAY,
|
|
119755
119773
|
(tokenValiditySeconds - this.refreshTokenLeewaySeconds) * 1e3
|
|
@@ -119974,7 +119992,8 @@ var BaseConvexClient = class {
|
|
|
119974
119992
|
},
|
|
119975
119993
|
{
|
|
119976
119994
|
logger: this.logger,
|
|
119977
|
-
refreshTokenLeewaySeconds: authRefreshTokenLeewaySeconds
|
|
119995
|
+
refreshTokenLeewaySeconds: authRefreshTokenLeewaySeconds,
|
|
119996
|
+
initialAuthTokenReuse: options.initialAuthTokenReuse ?? false
|
|
119978
119997
|
}
|
|
119979
119998
|
);
|
|
119980
119999
|
this.optimisticQueryResults = new OptimisticQueryResults();
|
|
@@ -124722,14 +124741,32 @@ async function typeCheckFunctions(ctx, typescriptCompiler, functionsDir2, handle
|
|
|
124722
124741
|
}
|
|
124723
124742
|
async function runTsc(ctx, typescriptCompiler, tscArgs, handleResult2) {
|
|
124724
124743
|
var _a2;
|
|
124725
|
-
|
|
124726
|
-
|
|
124727
|
-
"
|
|
124728
|
-
|
|
124729
|
-
|
|
124730
|
-
|
|
124731
|
-
|
|
124732
|
-
|
|
124744
|
+
let compilerPath;
|
|
124745
|
+
switch (typescriptCompiler) {
|
|
124746
|
+
case "tsgo": {
|
|
124747
|
+
const tsgoPaths = ["tsgo", "tsgo.js"].map(
|
|
124748
|
+
(filename) => import_path15.default.join(
|
|
124749
|
+
"node_modules",
|
|
124750
|
+
"@typescript",
|
|
124751
|
+
"native-preview",
|
|
124752
|
+
"bin",
|
|
124753
|
+
filename
|
|
124754
|
+
)
|
|
124755
|
+
);
|
|
124756
|
+
compilerPath = tsgoPaths.find((path39) => ctx.fs.exists(path39));
|
|
124757
|
+
break;
|
|
124758
|
+
}
|
|
124759
|
+
case "tsc": {
|
|
124760
|
+
const tscPath = import_path15.default.join("node_modules", "typescript", "bin", "tsc");
|
|
124761
|
+
if (ctx.fs.exists(tscPath)) {
|
|
124762
|
+
compilerPath = tscPath;
|
|
124763
|
+
}
|
|
124764
|
+
break;
|
|
124765
|
+
}
|
|
124766
|
+
default:
|
|
124767
|
+
typescriptCompiler;
|
|
124768
|
+
}
|
|
124769
|
+
if (!compilerPath) {
|
|
124733
124770
|
return handleResult2("cantTypeCheck", () => {
|
|
124734
124771
|
logError(
|
|
124735
124772
|
chalkStderr.gray(
|
|
@@ -124739,12 +124776,12 @@ async function runTsc(ctx, typescriptCompiler, tscArgs, handleResult2) {
|
|
|
124739
124776
|
});
|
|
124740
124777
|
}
|
|
124741
124778
|
const versionResult = await spawnAsync(ctx, process.execPath, [
|
|
124742
|
-
|
|
124779
|
+
compilerPath,
|
|
124743
124780
|
"--version"
|
|
124744
124781
|
]);
|
|
124745
124782
|
const version4 = ((_a2 = versionResult.stdout.match(/Version (.*)/)) == null ? void 0 : _a2[1]) ?? null;
|
|
124746
124783
|
const hasOlderTypeScriptVersion = version4 && semver.lt(version4, "4.8.4");
|
|
124747
|
-
await runTscInner(ctx,
|
|
124784
|
+
await runTscInner(ctx, compilerPath, tscArgs, handleResult2);
|
|
124748
124785
|
if (hasOlderTypeScriptVersion) {
|
|
124749
124786
|
logError(
|
|
124750
124787
|
chalkStderr.yellow(
|