convex 1.35.0 → 1.35.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.
Files changed (96) hide show
  1. package/dist/browser.bundle.js +2 -8
  2. package/dist/browser.bundle.js.map +3 -3
  3. package/dist/cjs/browser/index-node.js +1 -3
  4. package/dist/cjs/browser/index.js +1 -3
  5. package/dist/cjs/browser/index.js.map +2 -2
  6. package/dist/cjs/browser/query_options.js.map +2 -2
  7. package/dist/cjs/cli/codegen_templates/readme.js +1 -14
  8. package/dist/cjs/cli/codegen_templates/readme.js.map +2 -2
  9. package/dist/cjs/cli/deploy.js +1 -1
  10. package/dist/cjs/cli/deploy.js.map +1 -1
  11. package/dist/cjs/cli/lib/envvars.js +8 -1
  12. package/dist/cjs/cli/lib/envvars.js.map +2 -2
  13. package/dist/cjs/index.js +1 -1
  14. package/dist/cjs/index.js.map +1 -1
  15. package/dist/cjs/react/client.js +6 -43
  16. package/dist/cjs/react/client.js.map +2 -2
  17. package/dist/cjs/react/index.js +0 -2
  18. package/dist/cjs/react/index.js.map +2 -2
  19. package/dist/cjs/server/api.js.map +2 -2
  20. package/dist/cjs-types/browser/index.d.ts +0 -1
  21. package/dist/cjs-types/browser/index.d.ts.map +1 -1
  22. package/dist/cjs-types/browser/query_options.d.ts +9 -12
  23. package/dist/cjs-types/browser/query_options.d.ts.map +1 -1
  24. package/dist/cjs-types/cli/codegen_templates/readme.d.ts.map +1 -1
  25. package/dist/cjs-types/cli/lib/deployApi/definitionConfig.d.ts +24 -24
  26. package/dist/cjs-types/cli/lib/deployApi/modules.d.ts +2 -2
  27. package/dist/cjs-types/cli/lib/deployApi/startPush.d.ts +36 -36
  28. package/dist/cjs-types/cli/lib/envvars.d.ts.map +1 -1
  29. package/dist/cjs-types/cli/lib/mcp/tools/insights.d.ts +2 -2
  30. package/dist/cjs-types/index.d.ts +1 -1
  31. package/dist/cjs-types/react/client.d.ts +2 -54
  32. package/dist/cjs-types/react/client.d.ts.map +1 -1
  33. package/dist/cjs-types/react/index.d.ts +2 -7
  34. package/dist/cjs-types/react/index.d.ts.map +1 -1
  35. package/dist/cjs-types/server/api.d.ts +1 -5
  36. package/dist/cjs-types/server/api.d.ts.map +1 -1
  37. package/dist/cli.bundle.cjs +11 -17
  38. package/dist/cli.bundle.cjs.map +2 -2
  39. package/dist/esm/browser/index-node.js +0 -1
  40. package/dist/esm/browser/index.js +0 -1
  41. package/dist/esm/browser/index.js.map +2 -2
  42. package/dist/esm/browser/query_options.js.map +2 -2
  43. package/dist/esm/cli/codegen_templates/readme.js +1 -14
  44. package/dist/esm/cli/codegen_templates/readme.js.map +2 -2
  45. package/dist/esm/cli/deploy.js +1 -1
  46. package/dist/esm/cli/deploy.js.map +1 -1
  47. package/dist/esm/cli/lib/envvars.js +8 -1
  48. package/dist/esm/cli/lib/envvars.js.map +2 -2
  49. package/dist/esm/index.js +1 -1
  50. package/dist/esm/index.js.map +1 -1
  51. package/dist/esm/react/client.js +6 -43
  52. package/dist/esm/react/client.js.map +2 -2
  53. package/dist/esm/react/index.js +0 -1
  54. package/dist/esm/react/index.js.map +2 -2
  55. package/dist/esm/server/api.js.map +2 -2
  56. package/dist/esm-types/browser/index.d.ts +0 -1
  57. package/dist/esm-types/browser/index.d.ts.map +1 -1
  58. package/dist/esm-types/browser/query_options.d.ts +9 -12
  59. package/dist/esm-types/browser/query_options.d.ts.map +1 -1
  60. package/dist/esm-types/cli/codegen_templates/readme.d.ts.map +1 -1
  61. package/dist/esm-types/cli/lib/deployApi/definitionConfig.d.ts +24 -24
  62. package/dist/esm-types/cli/lib/deployApi/modules.d.ts +2 -2
  63. package/dist/esm-types/cli/lib/deployApi/startPush.d.ts +36 -36
  64. package/dist/esm-types/cli/lib/envvars.d.ts.map +1 -1
  65. package/dist/esm-types/cli/lib/mcp/tools/insights.d.ts +2 -2
  66. package/dist/esm-types/index.d.ts +1 -1
  67. package/dist/esm-types/react/client.d.ts +2 -54
  68. package/dist/esm-types/react/client.d.ts.map +1 -1
  69. package/dist/esm-types/react/index.d.ts +2 -7
  70. package/dist/esm-types/react/index.d.ts.map +1 -1
  71. package/dist/esm-types/server/api.d.ts +1 -5
  72. package/dist/esm-types/server/api.d.ts.map +1 -1
  73. package/dist/react.bundle.js +7 -50
  74. package/dist/react.bundle.js.map +3 -3
  75. package/package.json +1 -1
  76. package/src/browser/index.ts +0 -3
  77. package/src/browser/query_options.test.ts +9 -0
  78. package/src/browser/query_options.ts +15 -36
  79. package/src/cli/codegen_templates/readme.ts +1 -14
  80. package/src/cli/deploy.ts +1 -1
  81. package/src/cli/lib/envvars.ts +16 -1
  82. package/src/index.ts +1 -1
  83. package/src/react/client.test.tsx +0 -65
  84. package/src/react/client.ts +13 -129
  85. package/src/react/index.ts +1 -9
  86. package/src/server/api.ts +1 -5
  87. package/dist/cjs-types/react/use_query_object_options.test.d.ts +0 -5
  88. package/dist/cjs-types/react/use_query_object_options.test.d.ts.map +0 -1
  89. package/dist/cjs-types/react/use_query_result.test.d.ts +0 -5
  90. package/dist/cjs-types/react/use_query_result.test.d.ts.map +0 -1
  91. package/dist/esm-types/react/use_query_object_options.test.d.ts +0 -5
  92. package/dist/esm-types/react/use_query_object_options.test.d.ts.map +0 -1
  93. package/dist/esm-types/react/use_query_result.test.d.ts +0 -5
  94. package/dist/esm-types/react/use_query_result.test.d.ts.map +0 -1
  95. package/src/react/use_query_object_options.test.ts +0 -50
  96. package/src/react/use_query_result.test.ts +0 -41
@@ -2,5 +2,4 @@
2
2
  export { BaseConvexClient } from "./sync/client.js";
3
3
  export { ConvexClient } from "./simple_client-node.js";
4
4
  export { ConvexHttpClient } from "./http_client.js";
5
- export { convexQueryOptions } from "./query_options.js";
6
5
  //# sourceMappingURL=index.js.map
@@ -2,5 +2,4 @@
2
2
  export { BaseConvexClient } from "./sync/client.js";
3
3
  export { ConvexClient } from "./simple_client.js";
4
4
  export { ConvexHttpClient } from "./http_client.js";
5
- export { convexQueryOptions } from "./query_options.js";
6
5
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/browser/index.ts"],
4
- "sourcesContent": ["/**\n * Tools for accessing Convex in the browser.\n *\n * **If you are using React, use the {@link react} module instead.**\n *\n * ## Usage\n *\n * Create a {@link ConvexHttpClient} to connect to the Convex Cloud.\n *\n * ```typescript\n * import { ConvexHttpClient } from \"convex/browser\";\n * // typically loaded from an environment variable\n * const address = \"https://small-mouse-123.convex.cloud\";\n * const convex = new ConvexHttpClient(address);\n * ```\n *\n * @module\n */\nexport { BaseConvexClient } from \"./sync/client.js\";\nexport type {\n BaseConvexClientOptions,\n MutationOptions,\n SubscribeOptions,\n ConnectionState,\n AuthTokenFetcher,\n} from \"./sync/client.js\";\nexport type { PaginationStatus } from \"./sync/pagination.js\";\nexport type { ConvexClientOptions } from \"./simple_client.js\";\nexport { ConvexClient } from \"./simple_client.js\";\nexport type {\n OptimisticUpdate,\n OptimisticLocalStore,\n} from \"./sync/optimistic_updates.js\";\nexport type { QueryToken } from \"./sync/udf_path_utils.js\";\n/** @internal */\nexport type { PaginatedQueryToken } from \"./sync/udf_path_utils.js\";\nexport { ConvexHttpClient } from \"./http_client.js\";\nexport type { HttpMutationOptions } from \"./http_client.js\";\nexport type { QueryJournal } from \"./sync/protocol.js\";\n/** @internal */\nexport type { UserIdentityAttributes } from \"./sync/protocol.js\";\nexport type { FunctionResult } from \"./sync/function_result.js\";\n/** @internal */\nexport { convexQueryOptions } from \"./query_options.js\";\nexport type { QueryOptions } from \"./query_options.js\";\n"],
5
- "mappings": ";AAkBA,SAAS,wBAAwB;AAUjC,SAAS,oBAAoB;AAQ7B,SAAS,wBAAwB;AAOjC,SAAS,0BAA0B;",
4
+ "sourcesContent": ["/**\n * Tools for accessing Convex in the browser.\n *\n * **If you are using React, use the {@link react} module instead.**\n *\n * ## Usage\n *\n * Create a {@link ConvexHttpClient} to connect to the Convex Cloud.\n *\n * ```typescript\n * import { ConvexHttpClient } from \"convex/browser\";\n * // typically loaded from an environment variable\n * const address = \"https://small-mouse-123.convex.cloud\";\n * const convex = new ConvexHttpClient(address);\n * ```\n *\n * @module\n */\nexport { BaseConvexClient } from \"./sync/client.js\";\nexport type {\n BaseConvexClientOptions,\n MutationOptions,\n SubscribeOptions,\n ConnectionState,\n AuthTokenFetcher,\n} from \"./sync/client.js\";\nexport type { PaginationStatus } from \"./sync/pagination.js\";\nexport type { ConvexClientOptions } from \"./simple_client.js\";\nexport { ConvexClient } from \"./simple_client.js\";\nexport type {\n OptimisticUpdate,\n OptimisticLocalStore,\n} from \"./sync/optimistic_updates.js\";\nexport type { QueryToken } from \"./sync/udf_path_utils.js\";\n/** @internal */\nexport type { PaginatedQueryToken } from \"./sync/udf_path_utils.js\";\nexport { ConvexHttpClient } from \"./http_client.js\";\nexport type { HttpMutationOptions } from \"./http_client.js\";\nexport type { QueryJournal } from \"./sync/protocol.js\";\n/** @internal */\nexport type { UserIdentityAttributes } from \"./sync/protocol.js\";\nexport type { FunctionResult } from \"./sync/function_result.js\";\n"],
5
+ "mappings": ";AAkBA,SAAS,wBAAwB;AAUjC,SAAS,oBAAoB;AAQ7B,SAAS,wBAAwB;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/browser/query_options.ts"],
4
- "sourcesContent": ["// Inspired by https://tanstack.com/query/v5/docs/framework/react/guides/query-options\nimport type { FunctionArgs, FunctionReference } from \"../server/api.js\";\n\n/**\n * Options for a Convex query: the query function reference and its arguments.\n *\n * Used with the object-form overload of {@link useQuery}.\n *\n * @public\n */\nexport type QueryOptions<Query extends FunctionReference<\"query\">> = {\n /**\n * The query function to run.\n */\n query: Query;\n /**\n * The arguments to the query function.\n */\n args: FunctionArgs<Query>;\n};\n\n/**\n * Creates a type-safe {@link QueryOptions} object for a Convex query.\n *\n * This is an identity function that exists to provide type inference \u2014 passing\n * your query and args through this helper ensures TypeScript infers the correct\n * `Query` type parameter, which enables precise return types on hooks like\n * {@link useQuery}.\n *\n * ```typescript\n * const opts = convexQueryOptions({\n * query: api.users.getById,\n * args: { id: userId },\n * });\n * // opts is typed as QueryOptions<typeof api.users.getById>\n * client.prewarmQuery(opts);\n * ```\n *\n * @param options - The query and its arguments.\n * @returns The same object, typed as `QueryOptions<Query>`.\n * @internal\n */\nexport function convexQueryOptions<Query extends FunctionReference<\"query\">>(\n options: QueryOptions<Query>,\n): QueryOptions<Query> {\n return options;\n}\n"],
5
- "mappings": ";AA0CO,gBAAS,mBACd,SACqB;AACrB,SAAO;AACT;",
4
+ "sourcesContent": ["/**\n * Query options are a potential new API for a variety of functions, but in particular a new overload of the React hook for queries.\n *\n * Inspired by https://tanstack.com/query/v5/docs/framework/react/guides/query-options\n */\nimport type { FunctionArgs, FunctionReference } from \"../server/api.js\";\n\n// TODO if this type can encompass all use cases we can add not requiring args for queries\n// that don't take arguments. Goal would be that queryOptions allows leaving out args,\n// but queryOptions returns an object that always contains args. Helpers, \"middleware,\"\n// anything that intercepts these arguments\n/**\n * Query options.\n */\nexport type ConvexQueryOptions<Query extends FunctionReference<\"query\">> = {\n query: Query;\n args: FunctionArgs<Query>;\n extendSubscriptionFor?: number;\n};\n\n// This helper helps more once we have more inference happening.\nexport function convexQueryOptions<Query extends FunctionReference<\"query\">>(\n options: ConvexQueryOptions<Query>,\n): ConvexQueryOptions<Query> {\n return options;\n}\n"],
5
+ "mappings": ";AAqBO,gBAAS,mBACd,SAC2B;AAC3B,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -38,20 +38,7 @@ export const myQueryFunction = query({
38
38
  Using this query function in a React component looks like:
39
39
 
40
40
  \`\`\`ts
41
- const state = useQuery({
42
- query: api.myFunctions.myQueryFunction,
43
- args: { first: 10, second: "hello" },
44
- });
45
-
46
- if (state.status === "pending") {
47
- return <div>Loading...</div>;
48
- }
49
-
50
- if (state.status === "error") {
51
- return <div>Error: {state.error.message}</div>;
52
- }
53
-
54
- const data = state.data;
41
+ const data = useQuery(api.myFunctions.myQueryFunction, { first: 10, second: "hello" });
55
42
  \`\`\`
56
43
 
57
44
 
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/cli/codegen_templates/readme.ts"],
4
- "sourcesContent": ["export function readmeCodegen() {\n return `# Welcome to your Convex functions directory!\n\nWrite your Convex functions here.\nSee https://docs.convex.dev/functions for more.\n\nA query function that takes two arguments looks like:\n\n\\`\\`\\`ts\n// convex/myFunctions.ts\nimport { query } from \"./_generated/server\";\nimport { v } from \"convex/values\";\n\nexport const myQueryFunction = query({\n // Validators for arguments.\n args: {\n first: v.number(),\n second: v.string(),\n },\n\n // Function implementation.\n handler: async (ctx, args) => {\n // Read the database as many times as you need here.\n // See https://docs.convex.dev/database/reading-data.\n const documents = await ctx.db.query(\"tablename\").collect();\n\n // Arguments passed from the client are properties of the args object.\n console.log(args.first, args.second)\n\n // Write arbitrary JavaScript here: filter, aggregate, build derived data,\n // remove non-public properties, or create new objects.\n return documents;\n },\n});\n\\`\\`\\`\n\nUsing this query function in a React component looks like:\n\n\\`\\`\\`ts\nconst state = useQuery({\n query: api.myFunctions.myQueryFunction,\n args: { first: 10, second: \"hello\" },\n});\n\nif (state.status === \"pending\") {\n return <div>Loading...</div>;\n}\n\nif (state.status === \"error\") {\n return <div>Error: {state.error.message}</div>;\n}\n\nconst data = state.data;\n\\`\\`\\`\n\n\nA mutation function looks like:\n\n\\`\\`\\`ts\n// convex/myFunctions.ts\nimport { mutation } from \"./_generated/server\";\nimport { v } from \"convex/values\";\n\nexport const myMutationFunction = mutation({\n // Validators for arguments.\n args: {\n first: v.string(),\n second: v.string(),\n },\n\n // Function implementation.\n handler: async (ctx, args) => {\n // Insert or modify documents in the database here.\n // Mutations can also read from the database like queries.\n // See https://docs.convex.dev/database/writing-data.\n const message = { body: args.first, author: args.second };\n const id = await ctx.db.insert(\"messages\", message);\n\n // Optionally, return a value from your mutation.\n return await ctx.db.get(\"messages\", id);\n },\n});\n\\`\\`\\`\n\nUsing this mutation function in a React component looks like:\n\n\\`\\`\\`ts\nconst mutation = useMutation(api.myFunctions.myMutationFunction);\nfunction handleButtonPress() {\n // fire and forget, the most common way to use mutations\n mutation({ first: \"Hello!\", second: \"me\" });\n // OR\n // use the result once the mutation has completed\n mutation({ first: \"Hello!\", second: \"me\" }).then(result => console.log(result));\n}\n\\`\\`\\`\n\nUse the Convex CLI to push your functions to a deployment. See everything\nthe Convex CLI can do by running \\`npx convex -h\\` in your project root\ndirectory. To learn more, launch the docs with \\`npx convex docs\\`.\n`;\n}\n"],
5
- "mappings": ";AAAO,gBAAS,gBAAgB;AAC9B,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoGT;",
4
+ "sourcesContent": ["export function readmeCodegen() {\n return `# Welcome to your Convex functions directory!\n\nWrite your Convex functions here.\nSee https://docs.convex.dev/functions for more.\n\nA query function that takes two arguments looks like:\n\n\\`\\`\\`ts\n// convex/myFunctions.ts\nimport { query } from \"./_generated/server\";\nimport { v } from \"convex/values\";\n\nexport const myQueryFunction = query({\n // Validators for arguments.\n args: {\n first: v.number(),\n second: v.string(),\n },\n\n // Function implementation.\n handler: async (ctx, args) => {\n // Read the database as many times as you need here.\n // See https://docs.convex.dev/database/reading-data.\n const documents = await ctx.db.query(\"tablename\").collect();\n\n // Arguments passed from the client are properties of the args object.\n console.log(args.first, args.second)\n\n // Write arbitrary JavaScript here: filter, aggregate, build derived data,\n // remove non-public properties, or create new objects.\n return documents;\n },\n});\n\\`\\`\\`\n\nUsing this query function in a React component looks like:\n\n\\`\\`\\`ts\nconst data = useQuery(api.myFunctions.myQueryFunction, { first: 10, second: \"hello\" });\n\\`\\`\\`\n\n\nA mutation function looks like:\n\n\\`\\`\\`ts\n// convex/myFunctions.ts\nimport { mutation } from \"./_generated/server\";\nimport { v } from \"convex/values\";\n\nexport const myMutationFunction = mutation({\n // Validators for arguments.\n args: {\n first: v.string(),\n second: v.string(),\n },\n\n // Function implementation.\n handler: async (ctx, args) => {\n // Insert or modify documents in the database here.\n // Mutations can also read from the database like queries.\n // See https://docs.convex.dev/database/writing-data.\n const message = { body: args.first, author: args.second };\n const id = await ctx.db.insert(\"messages\", message);\n\n // Optionally, return a value from your mutation.\n return await ctx.db.get(\"messages\", id);\n },\n});\n\\`\\`\\`\n\nUsing this mutation function in a React component looks like:\n\n\\`\\`\\`ts\nconst mutation = useMutation(api.myFunctions.myMutationFunction);\nfunction handleButtonPress() {\n // fire and forget, the most common way to use mutations\n mutation({ first: \"Hello!\", second: \"me\" });\n // OR\n // use the result once the mutation has completed\n mutation({ first: \"Hello!\", second: \"me\" }).then(result => console.log(result));\n}\n\\`\\`\\`\n\nUse the Convex CLI to push your functions to a deployment. See everything\nthe Convex CLI can do by running \\`npx convex -h\\` in your project root\ndirectory. To learn more, launch the docs with \\`npx convex docs\\`.\n`;\n}\n"],
5
+ "mappings": ";AAAO,gBAAS,gBAAgB;AAC9B,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuFT;",
6
6
  "names": []
7
7
  }
@@ -42,7 +42,7 @@ Deploys to a preview deployment if the \`${CONVEX_DEPLOY_KEY_ENV_VAR_NAME}\` env
42
42
  ).addOption(
43
43
  new Option(
44
44
  "--preview-create <name>",
45
- "The name to associate with this deployment if deploying to a newly created preview deployment. Defaults to the current Git branch name in Vercel, Netlify and GitHub CI. This parameter can only be used with a preview deploy key (when used with another type of key, the command will return an error)."
45
+ "The name to associate with this deployment if deploying to a newly created preview deployment. Defaults to the current Git branch name in Vercel, Netlify, Cloudflare Pages and GitHub CI. This parameter can only be used with a preview deploy key (when used with another type of key, the command will return an error)."
46
46
  ).conflicts("preview-name")
47
47
  ).addOption(
48
48
  new Option(
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/cli/deploy.ts"],
4
- "sourcesContent": ["import { chalkStderr } from \"chalk\";\nimport { Command, Option } from \"@commander-js/extra-typings\";\nimport { Context, oneoffContext } from \"../bundler/context.js\";\nimport { logFinishedStep, logMessage, showSpinner } from \"../bundler/log.js\";\nimport { loadSelectedDeploymentCredentials } from \"./lib/api.js\";\nimport {\n gitBranchFromEnvironment,\n isNonProdBuildEnvironment,\n suggestedEnvVarNames,\n} from \"./lib/envvars.js\";\nimport { PushOptions } from \"./lib/components.js\";\nimport {\n CONVEX_DEPLOY_KEY_ENV_VAR_NAME,\n CONVEX_SELF_HOSTED_URL_VAR_NAME,\n CONVEX_DEPLOYMENT_ENV_VAR_NAME,\n bigBrainAPI,\n} from \"./lib/utils/utils.js\";\nimport { runFunctionAndLog } from \"./lib/run.js\";\nimport { usageStateWarning } from \"./lib/usage.js\";\nimport { getTeamAndProjectFromPreviewAdminKey } from \"./lib/deployment.js\";\nimport { runPush } from \"./lib/components.js\";\nimport { promptYesNo } from \"./lib/utils/prompts.js\";\nimport { deployToDeployment, runCommand } from \"./lib/deploy2.js\";\nimport {\n DeploymentSelection,\n getDeploymentSelection,\n} from \"./lib/deploymentSelection.js\";\nimport { deploymentNameAndTypeFromSelection } from \"./lib/deploymentSelection.js\";\nimport { checkVersionAndAiFilesStaleness } from \"./lib/updates.js\";\nimport { readProjectConfig, getAuthKitConfig } from \"./lib/config.js\";\nimport { ensureAuthKitProvisionedBeforeBuild } from \"./lib/workos/workos.js\";\nimport { DASHBOARD_HOST } from \"./lib/dashboard.js\";\nimport { extractDeploymentNameForWorkOS } from \"./lib/extractDeploymentNameForWorkOS.js\";\n\nexport const deploy = new Command(\"deploy\")\n .summary(\"Deploy to your prod deployment\")\n .description(\n \"Deploy to your deployment. By default, this deploys to your prod deployment.\\n\\n\" +\n `Deploys to a preview deployment if the \\`${CONVEX_DEPLOY_KEY_ENV_VAR_NAME}\\` environment variable is set to a Preview Deploy Key.`,\n )\n .allowExcessArguments(false)\n .addDeployOptions()\n .addOption(\n new Option(\n \"--preview-run <functionName>\",\n \"Function to run if deploying to a preview deployment. This is ignored if deploying to a production deployment.\",\n ),\n )\n .addOption(\n new Option(\n \"--preview-create <name>\",\n \"The name to associate with this deployment if deploying to a newly created preview deployment. Defaults to the current Git branch name in Vercel, Netlify and GitHub CI. This parameter can only be used with a preview deploy key (when used with another type of key, the command will return an error).\",\n ).conflicts(\"preview-name\"),\n )\n .addOption(\n new Option(\n \"--check-build-environment <mode>\",\n \"Whether to check for a non-production build environment before deploying to a production Convex deployment.\",\n )\n .choices([\"enable\", \"disable\"] as const)\n .default(\"enable\" as const)\n .hideHelp(),\n )\n // Hidden options to pass in admin key and url for tests and local development\n .addOption(new Option(\"--admin-key <adminKey>\").hideHelp())\n .addOption(new Option(\"--url <url>\").hideHelp())\n .addOption(\n new Option(\n \"--preview-name <name>\",\n \"[deprecated] Use `--preview-create` instead. The name to associate with this deployment if deploying to a preview deployment.\",\n )\n .hideHelp()\n .conflicts(\"preview-create\"),\n )\n .addOption(\n new Option(\n \"--env-file <envFile>\",\n `Path to a custom file of environment variables, for choosing the \\\ndeployment, e.g. ${CONVEX_DEPLOYMENT_ENV_VAR_NAME} or ${CONVEX_SELF_HOSTED_URL_VAR_NAME}. \\\nSame format as .env.local or .env files, and overrides them.`,\n ),\n )\n .addOption(\n new Option(\n \"--skip-workos-check\",\n \"Skip WorkOS AuthKit provisioning and credential checks during deploy.\",\n ).hideHelp(),\n )\n .addOption(\n new Option(\"--allow-deleting-large-indexes\")\n .hideHelp()\n .conflicts(\"preview-create\")\n .conflicts(\"preview-name\"),\n )\n .showHelpAfterError()\n .action(async (cmdOptions) => {\n const ctx = await oneoffContext(cmdOptions);\n\n const deploymentSelection = await getDeploymentSelection(ctx, {\n ...cmdOptions,\n implicitProd: true,\n });\n if (\n cmdOptions.checkBuildEnvironment === \"enable\" &&\n isNonProdBuildEnvironment() &&\n deploymentSelection.kind === \"existingDeployment\" &&\n deploymentSelection.deploymentToActOn.source === \"deployKey\" &&\n deploymentSelection.deploymentToActOn.deploymentFields?.deploymentType ===\n \"prod\"\n ) {\n await ctx.crash({\n exitCode: 1,\n errorType: \"invalid filesystem data\",\n printedMessage: `Detected a non-production build environment and \"${CONVEX_DEPLOY_KEY_ENV_VAR_NAME}\" for a production Convex deployment.\\n\n This is probably unintentional.\n `,\n });\n }\n\n if (deploymentSelection.kind === \"anonymous\") {\n logMessage(\n \"You are currently developing anonymously with a locally running project.\\n\" +\n \"To deploy your Convex app to the cloud, log in by running `npx convex login`.\\n\" +\n \"See https://docs.convex.dev/production for more information on how Convex cloud works and instructions on how to set up hosting.\",\n );\n return await ctx.crash({\n exitCode: 1,\n errorType: \"fatal\",\n printedMessage: null,\n });\n }\n\n if (deploymentSelection.kind === \"preview\") {\n // TODO -- add usage state warnings here too once we can do it without a deployment name\n // await usageStateWarning(ctx);\n if (cmdOptions.previewName !== undefined) {\n await ctx.crash({\n exitCode: 1,\n errorType: \"fatal\",\n printedMessage:\n \"The `--preview-name` flag has been deprecated in favor of `--preview-create`. Please re-run the command using `--preview-create` instead.\",\n });\n }\n\n const teamAndProjectSlugs = await getTeamAndProjectFromPreviewAdminKey(\n ctx,\n deploymentSelection.previewDeployKey,\n );\n await deployToNewPreviewDeployment(\n ctx,\n {\n previewDeployKey: deploymentSelection.previewDeployKey,\n projectSelection: {\n kind: \"teamAndProjectSlugs\",\n teamSlug: teamAndProjectSlugs.teamSlug,\n projectSlug: teamAndProjectSlugs.projectSlug,\n },\n },\n {\n ...cmdOptions,\n },\n );\n } else {\n if (cmdOptions.previewCreate !== undefined) {\n const source =\n deploymentSelection.kind === \"deploymentWithinProject\" &&\n deploymentSelection.targetProject.kind === \"deploymentName\"\n ? `at ${chalkStderr.blue.underline(`${DASHBOARD_HOST}/dp/${deploymentSelection.targetProject.deploymentName}/settings#preview-deploy-keys`)}`\n : deploymentSelection.kind === \"existingDeployment\" &&\n deploymentSelection.deploymentToActOn.deploymentFields !== null\n ? `at ${chalkStderr.blue.underline(`${DASHBOARD_HOST}/dp/${deploymentSelection.deploymentToActOn.deploymentFields.deploymentName}/settings#preview-deploy-keys`)}`\n : \"on the dashboard\";\n await ctx.crash({\n exitCode: 1,\n errorType: \"fatal\",\n printedMessage: `Preview deployments can only be created with preview deploy keys. Generate a preview deploy key ${source} and set the ${chalkStderr.bold(`CONVEX_DEPLOY_KEY`)} environment variable with it.`,\n });\n }\n\n await deployToExistingDeployment(ctx, deploymentSelection, {\n ...cmdOptions,\n skipWorkosCheck: cmdOptions.skipWorkosCheck ?? false,\n allowDeletingLargeIndexes:\n cmdOptions.allowDeletingLargeIndexes ?? false,\n });\n }\n });\n\nasync function deployToNewPreviewDeployment(\n ctx: Context,\n deploymentSelection: {\n previewDeployKey: string;\n projectSelection: {\n kind: \"teamAndProjectSlugs\";\n teamSlug: string;\n projectSlug: string;\n };\n },\n options: {\n dryRun?: boolean | undefined;\n previewCreate?: string | undefined;\n previewRun?: string | undefined;\n cmdUrlEnvVarName?: string | undefined;\n cmd?: string | undefined;\n verbose?: boolean | undefined;\n typecheck: \"enable\" | \"try\" | \"disable\";\n typecheckComponents: boolean;\n codegen: \"enable\" | \"disable\";\n pushAllModules?: boolean;\n\n debug?: boolean | undefined;\n debugBundlePath?: string | undefined;\n skipWorkosCheck?: boolean | undefined;\n },\n) {\n const previewName = options.previewCreate ?? gitBranchFromEnvironment();\n if (previewName === null) {\n await ctx.crash({\n exitCode: 1,\n errorType: \"fatal\",\n printedMessage:\n \"`npx convex deploy` to a preview deployment could not determine the preview name. Provide one using `--preview-create`\",\n });\n }\n\n if (options.dryRun) {\n logFinishedStep(\n `Would have claimed preview deployment for \"${previewName}\"`,\n );\n await runCommand(ctx, {\n cmdUrlEnvVarName: options.cmdUrlEnvVarName,\n cmd: options.cmd,\n dryRun: !!options.dryRun,\n url: \"https://<PREVIEW DEPLOYMENT>.convex.cloud\",\n adminKey: \"preview-deployment-admin-key\",\n });\n logFinishedStep(\n `Would have deployed Convex functions to preview deployment for \"${previewName}\"`,\n );\n if (options.previewRun !== undefined) {\n logMessage(`Would have run function \"${options.previewRun}\"`);\n }\n return;\n }\n const data = await bigBrainAPI({\n ctx,\n method: \"POST\",\n path: \"claim_preview_deployment\",\n data: {\n projectSelection: deploymentSelection.projectSelection,\n identifier: previewName,\n },\n });\n\n const previewAdminKey = data.adminKey;\n const previewUrl = data.instanceUrl;\n\n // Extract deployment name from URL for WorkOS provisioning\n const deploymentNameForWorkOS = extractDeploymentNameForWorkOS(previewUrl);\n\n // Provision WorkOS before building the client bundle (if configured)\n const { projectConfig } = await readProjectConfig(ctx);\n const authKitConfig = await getAuthKitConfig(ctx, projectConfig);\n\n if (authKitConfig && deploymentNameForWorkOS && !options.skipWorkosCheck) {\n await ensureAuthKitProvisionedBeforeBuild(\n ctx,\n deploymentNameForWorkOS,\n { deploymentUrl: previewUrl, adminKey: previewAdminKey },\n \"preview\",\n );\n }\n\n await runCommand(ctx, {\n ...options,\n url: previewUrl,\n adminKey: previewAdminKey,\n });\n\n const pushOptions: PushOptions = {\n deploymentName: null,\n adminKey: previewAdminKey,\n verbose: !!options.verbose,\n dryRun: false,\n typecheck: options.typecheck,\n typecheckComponents: options.typecheckComponents,\n debug: !!options.debug,\n debugBundlePath: options.debugBundlePath,\n debugNodeApis: false,\n codegen: options.codegen === \"enable\",\n url: previewUrl,\n liveComponentSources: false,\n pushAllModules: !!options.pushAllModules,\n largeIndexDeletionCheck: \"no verification\", // fine for preview deployments\n };\n showSpinner(`Deploying to ${previewUrl}...`);\n await runPush(ctx, pushOptions);\n logFinishedStep(`Deployed Convex functions to ${previewUrl}`);\n\n if (options.previewRun !== undefined) {\n await runFunctionAndLog(ctx, {\n deploymentUrl: previewUrl,\n adminKey: previewAdminKey,\n functionName: options.previewRun,\n argsString: \"{}\",\n componentPath: undefined,\n callbacks: {\n onSuccess: () => {\n logFinishedStep(`Finished running function \"${options.previewRun}\"`);\n },\n },\n });\n }\n}\n\nasync function deployToExistingDeployment(\n ctx: Context,\n deploymentSelection: DeploymentSelection,\n options: {\n verbose?: boolean | undefined;\n dryRun?: boolean | undefined;\n yes?: boolean | undefined;\n typecheck: \"enable\" | \"try\" | \"disable\";\n typecheckComponents: boolean;\n codegen: \"enable\" | \"disable\";\n cmd?: string | undefined;\n cmdUrlEnvVarName?: string | undefined;\n pushAllModules?: boolean;\n\n debugBundlePath?: string | undefined;\n debug?: boolean | undefined;\n adminKey?: string | undefined;\n url?: string | undefined;\n writePushRequest?: string | undefined;\n liveComponentSources?: boolean | undefined;\n envFile?: string | undefined;\n skipWorkosCheck?: boolean | undefined;\n allowDeletingLargeIndexes: boolean;\n },\n) {\n const deploymentToActOn = await loadSelectedDeploymentCredentials(\n ctx,\n deploymentSelection,\n );\n const { deploymentFields } = deploymentToActOn;\n\n const configuredDeployment =\n deploymentNameAndTypeFromSelection(deploymentSelection);\n if (configuredDeployment !== null && configuredDeployment.name !== null) {\n const shouldPushToProd =\n configuredDeployment.name === deploymentFields?.deploymentName ||\n (options.yes ??\n (await askToConfirmPush(\n ctx,\n {\n configuredName: configuredDeployment.name,\n configuredType: configuredDeployment.type,\n requestedName: deploymentFields?.deploymentName!,\n requestedType: deploymentFields?.deploymentType!,\n },\n deploymentToActOn.url,\n )));\n if (!shouldPushToProd) {\n await ctx.crash({\n exitCode: 1,\n printedMessage: null,\n errorType: \"fatal\",\n });\n }\n }\n\n const isCloudDeployment = deploymentFields !== null;\n await Promise.all([\n deployToDeployment(\n ctx,\n {\n url: deploymentToActOn.url,\n adminKey: deploymentToActOn.adminKey,\n deploymentName: deploymentFields?.deploymentName ?? null,\n ...(deploymentFields?.deploymentType !== undefined\n ? { deploymentType: deploymentFields.deploymentType }\n : {}),\n },\n { ...options, skipWorkosCheck: options.skipWorkosCheck },\n ),\n ...(isCloudDeployment\n ? [\n usageStateWarning(ctx, deploymentFields.deploymentName),\n checkVersionAndAiFilesStaleness(ctx),\n ]\n : []),\n ]);\n}\n\nasync function askToConfirmPush(\n ctx: Context,\n deployment: {\n configuredName: string;\n configuredType: string | null;\n requestedName: string;\n requestedType: string;\n },\n prodUrl: string,\n) {\n logMessage(\n `\\\nYou're currently developing against your ${chalkStderr.bold(\n deployment.configuredType ?? \"dev\",\n )} deployment\n\n ${deployment.configuredName} (set in CONVEX_DEPLOYMENT)\n\nYour ${chalkStderr.bold(deployment.requestedType)} deployment ${chalkStderr.bold(\n deployment.requestedName,\n )} serves traffic at:\n\n ${(await suggestedEnvVarNames(ctx)).convexUrlEnvVar}=${chalkStderr.bold(prodUrl)}\n\nMake sure that your published client is configured with this URL (for instructions see https://docs.convex.dev/hosting)\\n`,\n );\n return promptYesNo(ctx, {\n message: `Do you want to push your code to your ${deployment.requestedType} deployment ${deployment.requestedName} now?`,\n default: true,\n });\n}\n"],
4
+ "sourcesContent": ["import { chalkStderr } from \"chalk\";\nimport { Command, Option } from \"@commander-js/extra-typings\";\nimport { Context, oneoffContext } from \"../bundler/context.js\";\nimport { logFinishedStep, logMessage, showSpinner } from \"../bundler/log.js\";\nimport { loadSelectedDeploymentCredentials } from \"./lib/api.js\";\nimport {\n gitBranchFromEnvironment,\n isNonProdBuildEnvironment,\n suggestedEnvVarNames,\n} from \"./lib/envvars.js\";\nimport { PushOptions } from \"./lib/components.js\";\nimport {\n CONVEX_DEPLOY_KEY_ENV_VAR_NAME,\n CONVEX_SELF_HOSTED_URL_VAR_NAME,\n CONVEX_DEPLOYMENT_ENV_VAR_NAME,\n bigBrainAPI,\n} from \"./lib/utils/utils.js\";\nimport { runFunctionAndLog } from \"./lib/run.js\";\nimport { usageStateWarning } from \"./lib/usage.js\";\nimport { getTeamAndProjectFromPreviewAdminKey } from \"./lib/deployment.js\";\nimport { runPush } from \"./lib/components.js\";\nimport { promptYesNo } from \"./lib/utils/prompts.js\";\nimport { deployToDeployment, runCommand } from \"./lib/deploy2.js\";\nimport {\n DeploymentSelection,\n getDeploymentSelection,\n} from \"./lib/deploymentSelection.js\";\nimport { deploymentNameAndTypeFromSelection } from \"./lib/deploymentSelection.js\";\nimport { checkVersionAndAiFilesStaleness } from \"./lib/updates.js\";\nimport { readProjectConfig, getAuthKitConfig } from \"./lib/config.js\";\nimport { ensureAuthKitProvisionedBeforeBuild } from \"./lib/workos/workos.js\";\nimport { DASHBOARD_HOST } from \"./lib/dashboard.js\";\nimport { extractDeploymentNameForWorkOS } from \"./lib/extractDeploymentNameForWorkOS.js\";\n\nexport const deploy = new Command(\"deploy\")\n .summary(\"Deploy to your prod deployment\")\n .description(\n \"Deploy to your deployment. By default, this deploys to your prod deployment.\\n\\n\" +\n `Deploys to a preview deployment if the \\`${CONVEX_DEPLOY_KEY_ENV_VAR_NAME}\\` environment variable is set to a Preview Deploy Key.`,\n )\n .allowExcessArguments(false)\n .addDeployOptions()\n .addOption(\n new Option(\n \"--preview-run <functionName>\",\n \"Function to run if deploying to a preview deployment. This is ignored if deploying to a production deployment.\",\n ),\n )\n .addOption(\n new Option(\n \"--preview-create <name>\",\n \"The name to associate with this deployment if deploying to a newly created preview deployment. Defaults to the current Git branch name in Vercel, Netlify, Cloudflare Pages and GitHub CI. This parameter can only be used with a preview deploy key (when used with another type of key, the command will return an error).\",\n ).conflicts(\"preview-name\"),\n )\n .addOption(\n new Option(\n \"--check-build-environment <mode>\",\n \"Whether to check for a non-production build environment before deploying to a production Convex deployment.\",\n )\n .choices([\"enable\", \"disable\"] as const)\n .default(\"enable\" as const)\n .hideHelp(),\n )\n // Hidden options to pass in admin key and url for tests and local development\n .addOption(new Option(\"--admin-key <adminKey>\").hideHelp())\n .addOption(new Option(\"--url <url>\").hideHelp())\n .addOption(\n new Option(\n \"--preview-name <name>\",\n \"[deprecated] Use `--preview-create` instead. The name to associate with this deployment if deploying to a preview deployment.\",\n )\n .hideHelp()\n .conflicts(\"preview-create\"),\n )\n .addOption(\n new Option(\n \"--env-file <envFile>\",\n `Path to a custom file of environment variables, for choosing the \\\ndeployment, e.g. ${CONVEX_DEPLOYMENT_ENV_VAR_NAME} or ${CONVEX_SELF_HOSTED_URL_VAR_NAME}. \\\nSame format as .env.local or .env files, and overrides them.`,\n ),\n )\n .addOption(\n new Option(\n \"--skip-workos-check\",\n \"Skip WorkOS AuthKit provisioning and credential checks during deploy.\",\n ).hideHelp(),\n )\n .addOption(\n new Option(\"--allow-deleting-large-indexes\")\n .hideHelp()\n .conflicts(\"preview-create\")\n .conflicts(\"preview-name\"),\n )\n .showHelpAfterError()\n .action(async (cmdOptions) => {\n const ctx = await oneoffContext(cmdOptions);\n\n const deploymentSelection = await getDeploymentSelection(ctx, {\n ...cmdOptions,\n implicitProd: true,\n });\n if (\n cmdOptions.checkBuildEnvironment === \"enable\" &&\n isNonProdBuildEnvironment() &&\n deploymentSelection.kind === \"existingDeployment\" &&\n deploymentSelection.deploymentToActOn.source === \"deployKey\" &&\n deploymentSelection.deploymentToActOn.deploymentFields?.deploymentType ===\n \"prod\"\n ) {\n await ctx.crash({\n exitCode: 1,\n errorType: \"invalid filesystem data\",\n printedMessage: `Detected a non-production build environment and \"${CONVEX_DEPLOY_KEY_ENV_VAR_NAME}\" for a production Convex deployment.\\n\n This is probably unintentional.\n `,\n });\n }\n\n if (deploymentSelection.kind === \"anonymous\") {\n logMessage(\n \"You are currently developing anonymously with a locally running project.\\n\" +\n \"To deploy your Convex app to the cloud, log in by running `npx convex login`.\\n\" +\n \"See https://docs.convex.dev/production for more information on how Convex cloud works and instructions on how to set up hosting.\",\n );\n return await ctx.crash({\n exitCode: 1,\n errorType: \"fatal\",\n printedMessage: null,\n });\n }\n\n if (deploymentSelection.kind === \"preview\") {\n // TODO -- add usage state warnings here too once we can do it without a deployment name\n // await usageStateWarning(ctx);\n if (cmdOptions.previewName !== undefined) {\n await ctx.crash({\n exitCode: 1,\n errorType: \"fatal\",\n printedMessage:\n \"The `--preview-name` flag has been deprecated in favor of `--preview-create`. Please re-run the command using `--preview-create` instead.\",\n });\n }\n\n const teamAndProjectSlugs = await getTeamAndProjectFromPreviewAdminKey(\n ctx,\n deploymentSelection.previewDeployKey,\n );\n await deployToNewPreviewDeployment(\n ctx,\n {\n previewDeployKey: deploymentSelection.previewDeployKey,\n projectSelection: {\n kind: \"teamAndProjectSlugs\",\n teamSlug: teamAndProjectSlugs.teamSlug,\n projectSlug: teamAndProjectSlugs.projectSlug,\n },\n },\n {\n ...cmdOptions,\n },\n );\n } else {\n if (cmdOptions.previewCreate !== undefined) {\n const source =\n deploymentSelection.kind === \"deploymentWithinProject\" &&\n deploymentSelection.targetProject.kind === \"deploymentName\"\n ? `at ${chalkStderr.blue.underline(`${DASHBOARD_HOST}/dp/${deploymentSelection.targetProject.deploymentName}/settings#preview-deploy-keys`)}`\n : deploymentSelection.kind === \"existingDeployment\" &&\n deploymentSelection.deploymentToActOn.deploymentFields !== null\n ? `at ${chalkStderr.blue.underline(`${DASHBOARD_HOST}/dp/${deploymentSelection.deploymentToActOn.deploymentFields.deploymentName}/settings#preview-deploy-keys`)}`\n : \"on the dashboard\";\n await ctx.crash({\n exitCode: 1,\n errorType: \"fatal\",\n printedMessage: `Preview deployments can only be created with preview deploy keys. Generate a preview deploy key ${source} and set the ${chalkStderr.bold(`CONVEX_DEPLOY_KEY`)} environment variable with it.`,\n });\n }\n\n await deployToExistingDeployment(ctx, deploymentSelection, {\n ...cmdOptions,\n skipWorkosCheck: cmdOptions.skipWorkosCheck ?? false,\n allowDeletingLargeIndexes:\n cmdOptions.allowDeletingLargeIndexes ?? false,\n });\n }\n });\n\nasync function deployToNewPreviewDeployment(\n ctx: Context,\n deploymentSelection: {\n previewDeployKey: string;\n projectSelection: {\n kind: \"teamAndProjectSlugs\";\n teamSlug: string;\n projectSlug: string;\n };\n },\n options: {\n dryRun?: boolean | undefined;\n previewCreate?: string | undefined;\n previewRun?: string | undefined;\n cmdUrlEnvVarName?: string | undefined;\n cmd?: string | undefined;\n verbose?: boolean | undefined;\n typecheck: \"enable\" | \"try\" | \"disable\";\n typecheckComponents: boolean;\n codegen: \"enable\" | \"disable\";\n pushAllModules?: boolean;\n\n debug?: boolean | undefined;\n debugBundlePath?: string | undefined;\n skipWorkosCheck?: boolean | undefined;\n },\n) {\n const previewName = options.previewCreate ?? gitBranchFromEnvironment();\n if (previewName === null) {\n await ctx.crash({\n exitCode: 1,\n errorType: \"fatal\",\n printedMessage:\n \"`npx convex deploy` to a preview deployment could not determine the preview name. Provide one using `--preview-create`\",\n });\n }\n\n if (options.dryRun) {\n logFinishedStep(\n `Would have claimed preview deployment for \"${previewName}\"`,\n );\n await runCommand(ctx, {\n cmdUrlEnvVarName: options.cmdUrlEnvVarName,\n cmd: options.cmd,\n dryRun: !!options.dryRun,\n url: \"https://<PREVIEW DEPLOYMENT>.convex.cloud\",\n adminKey: \"preview-deployment-admin-key\",\n });\n logFinishedStep(\n `Would have deployed Convex functions to preview deployment for \"${previewName}\"`,\n );\n if (options.previewRun !== undefined) {\n logMessage(`Would have run function \"${options.previewRun}\"`);\n }\n return;\n }\n const data = await bigBrainAPI({\n ctx,\n method: \"POST\",\n path: \"claim_preview_deployment\",\n data: {\n projectSelection: deploymentSelection.projectSelection,\n identifier: previewName,\n },\n });\n\n const previewAdminKey = data.adminKey;\n const previewUrl = data.instanceUrl;\n\n // Extract deployment name from URL for WorkOS provisioning\n const deploymentNameForWorkOS = extractDeploymentNameForWorkOS(previewUrl);\n\n // Provision WorkOS before building the client bundle (if configured)\n const { projectConfig } = await readProjectConfig(ctx);\n const authKitConfig = await getAuthKitConfig(ctx, projectConfig);\n\n if (authKitConfig && deploymentNameForWorkOS && !options.skipWorkosCheck) {\n await ensureAuthKitProvisionedBeforeBuild(\n ctx,\n deploymentNameForWorkOS,\n { deploymentUrl: previewUrl, adminKey: previewAdminKey },\n \"preview\",\n );\n }\n\n await runCommand(ctx, {\n ...options,\n url: previewUrl,\n adminKey: previewAdminKey,\n });\n\n const pushOptions: PushOptions = {\n deploymentName: null,\n adminKey: previewAdminKey,\n verbose: !!options.verbose,\n dryRun: false,\n typecheck: options.typecheck,\n typecheckComponents: options.typecheckComponents,\n debug: !!options.debug,\n debugBundlePath: options.debugBundlePath,\n debugNodeApis: false,\n codegen: options.codegen === \"enable\",\n url: previewUrl,\n liveComponentSources: false,\n pushAllModules: !!options.pushAllModules,\n largeIndexDeletionCheck: \"no verification\", // fine for preview deployments\n };\n showSpinner(`Deploying to ${previewUrl}...`);\n await runPush(ctx, pushOptions);\n logFinishedStep(`Deployed Convex functions to ${previewUrl}`);\n\n if (options.previewRun !== undefined) {\n await runFunctionAndLog(ctx, {\n deploymentUrl: previewUrl,\n adminKey: previewAdminKey,\n functionName: options.previewRun,\n argsString: \"{}\",\n componentPath: undefined,\n callbacks: {\n onSuccess: () => {\n logFinishedStep(`Finished running function \"${options.previewRun}\"`);\n },\n },\n });\n }\n}\n\nasync function deployToExistingDeployment(\n ctx: Context,\n deploymentSelection: DeploymentSelection,\n options: {\n verbose?: boolean | undefined;\n dryRun?: boolean | undefined;\n yes?: boolean | undefined;\n typecheck: \"enable\" | \"try\" | \"disable\";\n typecheckComponents: boolean;\n codegen: \"enable\" | \"disable\";\n cmd?: string | undefined;\n cmdUrlEnvVarName?: string | undefined;\n pushAllModules?: boolean;\n\n debugBundlePath?: string | undefined;\n debug?: boolean | undefined;\n adminKey?: string | undefined;\n url?: string | undefined;\n writePushRequest?: string | undefined;\n liveComponentSources?: boolean | undefined;\n envFile?: string | undefined;\n skipWorkosCheck?: boolean | undefined;\n allowDeletingLargeIndexes: boolean;\n },\n) {\n const deploymentToActOn = await loadSelectedDeploymentCredentials(\n ctx,\n deploymentSelection,\n );\n const { deploymentFields } = deploymentToActOn;\n\n const configuredDeployment =\n deploymentNameAndTypeFromSelection(deploymentSelection);\n if (configuredDeployment !== null && configuredDeployment.name !== null) {\n const shouldPushToProd =\n configuredDeployment.name === deploymentFields?.deploymentName ||\n (options.yes ??\n (await askToConfirmPush(\n ctx,\n {\n configuredName: configuredDeployment.name,\n configuredType: configuredDeployment.type,\n requestedName: deploymentFields?.deploymentName!,\n requestedType: deploymentFields?.deploymentType!,\n },\n deploymentToActOn.url,\n )));\n if (!shouldPushToProd) {\n await ctx.crash({\n exitCode: 1,\n printedMessage: null,\n errorType: \"fatal\",\n });\n }\n }\n\n const isCloudDeployment = deploymentFields !== null;\n await Promise.all([\n deployToDeployment(\n ctx,\n {\n url: deploymentToActOn.url,\n adminKey: deploymentToActOn.adminKey,\n deploymentName: deploymentFields?.deploymentName ?? null,\n ...(deploymentFields?.deploymentType !== undefined\n ? { deploymentType: deploymentFields.deploymentType }\n : {}),\n },\n { ...options, skipWorkosCheck: options.skipWorkosCheck },\n ),\n ...(isCloudDeployment\n ? [\n usageStateWarning(ctx, deploymentFields.deploymentName),\n checkVersionAndAiFilesStaleness(ctx),\n ]\n : []),\n ]);\n}\n\nasync function askToConfirmPush(\n ctx: Context,\n deployment: {\n configuredName: string;\n configuredType: string | null;\n requestedName: string;\n requestedType: string;\n },\n prodUrl: string,\n) {\n logMessage(\n `\\\nYou're currently developing against your ${chalkStderr.bold(\n deployment.configuredType ?? \"dev\",\n )} deployment\n\n ${deployment.configuredName} (set in CONVEX_DEPLOYMENT)\n\nYour ${chalkStderr.bold(deployment.requestedType)} deployment ${chalkStderr.bold(\n deployment.requestedName,\n )} serves traffic at:\n\n ${(await suggestedEnvVarNames(ctx)).convexUrlEnvVar}=${chalkStderr.bold(prodUrl)}\n\nMake sure that your published client is configured with this URL (for instructions see https://docs.convex.dev/hosting)\\n`,\n );\n return promptYesNo(ctx, {\n message: `Do you want to push your code to your ${deployment.requestedType} deployment ${deployment.requestedName} now?`,\n default: true,\n });\n}\n"],
5
5
  "mappings": ";AAAA,SAAS,mBAAmB;AAC5B,SAAS,SAAS,cAAc;AAChC,SAAkB,qBAAqB;AACvC,SAAS,iBAAiB,YAAY,mBAAmB;AACzD,SAAS,yCAAyC;AAClD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAAyB;AAClC,SAAS,yBAAyB;AAClC,SAAS,4CAA4C;AACrD,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB,kBAAkB;AAC/C;AAAA,EAEE;AAAA,OACK;AACP,SAAS,0CAA0C;AACnD,SAAS,uCAAuC;AAChD,SAAS,mBAAmB,wBAAwB;AACpD,SAAS,2CAA2C;AACpD,SAAS,sBAAsB;AAC/B,SAAS,sCAAsC;AAExC,aAAM,SAAS,IAAI,QAAQ,QAAQ,EACvC,QAA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, ignoreSuspicious
281
281
  }
282
282
  }
283
283
  export function getBuildEnvironment() {
284
- return process.env.VERCEL ? "Vercel" : process.env.NETLIFY ? "Netlify" : false;
284
+ return process.env.VERCEL ? "Vercel" : process.env.NETLIFY ? "Netlify" : process.env.CF_PAGES || process.env.WORKERS_CI ? "Cloudflare" : false;
285
285
  }
286
286
  export function gitBranchFromEnvironment() {
287
287
  if (process.env.VERCEL) {
@@ -290,6 +290,9 @@ export function gitBranchFromEnvironment() {
290
290
  if (process.env.NETLIFY) {
291
291
  return process.env.HEAD ?? null;
292
292
  }
293
+ if (process.env.CF_PAGES || process.env.WORKERS_CI) {
294
+ return process.env.CF_PAGES_BRANCH ?? process.env.WORKERS_CI_BRANCH ?? null;
295
+ }
293
296
  if (process.env.CI) {
294
297
  return process.env.GITHUB_HEAD_REF ?? process.env.CI_COMMIT_REF_NAME ?? null;
295
298
  }
@@ -302,6 +305,10 @@ export function isNonProdBuildEnvironment() {
302
305
  if (process.env.NETLIFY) {
303
306
  return process.env.CONTEXT !== "production";
304
307
  }
308
+ if (process.env.CF_PAGES || process.env.WORKERS_CI) {
309
+ const branch = process.env.CF_PAGES_BRANCH ?? process.env.WORKERS_CI_BRANCH;
310
+ return branch !== "main";
311
+ }
305
312
  return false;
306
313
  }
307
314
  //# sourceMappingURL=envvars.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/cli/lib/envvars.ts"],
4
- "sourcesContent": ["/**\n * Help the developer store the CONVEX_URL environment variable.\n */\nimport { chalkStderr } from \"chalk\";\nimport * as dotenv from \"dotenv\";\n\nimport { Context } from \"../../bundler/context.js\";\nimport { logWarning } from \"../../bundler/log.js\";\nimport { loadPackageJson } from \"./utils/utils.js\";\n\nconst _FRAMEWORKS = [\n \"create-react-app\",\n \"Next.js\",\n \"Vite\",\n \"Remix\",\n \"SvelteKit\",\n \"Expo\",\n \"TanStackStart\",\n] as const;\ntype Framework = (typeof _FRAMEWORKS)[number];\n\n/**\n * A configuration for writing the actual (framework specific) `CONVEX_URL`\n * and `CONVEX_SITE_URL` environment variables to a \".env\" type file.\n *\n * May be `null` if there was an error determining any of the field values.\n */\ntype EnvFileUrlConfig = {\n /** The name of the file - typically `.env.local` */\n envFile: string;\n /**\n * The framework specific `CONVEX_URL`\n *\n * If `null`, ignore and don't update that environment variable.\n */\n convexUrlEnvVar: string | null;\n /**\n * The framework specific `CONVEX_SITE_URL`\n *\n * If `null`, ignore and don't update that environment variable.\n */\n siteUrlEnvVar: string | null;\n /** Existing content loaded from the `envFile`, if it exists */\n existingFileContent: string | null;\n} | null;\n\nexport async function writeUrlsToEnvFile(\n ctx: Context,\n options: {\n convexUrl: string;\n siteUrl?: string | null | undefined;\n },\n): Promise<EnvFileUrlConfig> {\n const envFileConfig = await loadEnvFileUrlConfig(ctx, options);\n\n if (envFileConfig === null) {\n return null;\n }\n\n const { envFile, convexUrlEnvVar, siteUrlEnvVar, existingFileContent } =\n envFileConfig;\n let updatedFileContent: string | null = null;\n if (convexUrlEnvVar) {\n updatedFileContent = changedEnvVarFile({\n existingFileContent,\n envVarName: convexUrlEnvVar,\n envVarValue: options.convexUrl,\n commentAfterValue: null,\n commentOnPreviousLine: null,\n })!;\n }\n if (siteUrlEnvVar && options.siteUrl) {\n updatedFileContent = changedEnvVarFile({\n existingFileContent: updatedFileContent ?? existingFileContent,\n envVarName: siteUrlEnvVar,\n envVarValue: options.siteUrl,\n commentAfterValue: null,\n commentOnPreviousLine: null,\n })!;\n }\n if (updatedFileContent) {\n ctx.fs.writeUtf8File(envFile, updatedFileContent);\n }\n\n return envFileConfig;\n}\n\nexport function changedEnvVarFile({\n existingFileContent,\n envVarName,\n envVarValue,\n commentAfterValue,\n commentOnPreviousLine,\n}: {\n existingFileContent: string | null;\n envVarName: string;\n envVarValue: string;\n commentAfterValue: string | null;\n commentOnPreviousLine: string | null;\n}): string | null {\n const varAssignment = `${envVarName}=${envVarValue}${\n commentAfterValue === null ? \"\" : ` # ${commentAfterValue}`\n }`;\n const commentOnPreviousLineWithLineBreak =\n commentOnPreviousLine === null ? \"\" : `${commentOnPreviousLine}\\n`;\n if (existingFileContent === null) {\n return `${commentOnPreviousLineWithLineBreak}${varAssignment}\\n`;\n }\n const config = dotenv.parse(existingFileContent);\n const existing = config[envVarName];\n if (existing === envVarValue) {\n return null;\n }\n if (existing !== undefined) {\n return existingFileContent.replace(\n getEnvVarRegex(envVarName),\n `${varAssignment}`,\n );\n } else {\n const doubleLineBreak = existingFileContent.endsWith(\"\\n\") ? \"\\n\" : \"\\n\\n\";\n return (\n existingFileContent +\n doubleLineBreak +\n commentOnPreviousLineWithLineBreak +\n varAssignment +\n \"\\n\"\n );\n }\n}\n\nexport function getEnvVarRegex(envVarName: string) {\n return new RegExp(`^${envVarName}.*$`, \"m\");\n}\n\nexport async function suggestedEnvVarNames(ctx: Context): Promise<{\n detectedFramework?: Framework;\n convexUrlEnvVar: ConvexUrlEnvVar;\n convexSiteEnvVar: ConvexSiteUrlEnvVar;\n frontendDevUrl?: string;\n publicPrefix?: string;\n}> {\n // no package.json, that's fine, just guess\n if (!ctx.fs.exists(\"package.json\")) {\n return {\n convexUrlEnvVar: \"CONVEX_URL\",\n convexSiteEnvVar: \"CONVEX_SITE_URL\",\n };\n }\n\n const packages = await loadPackageJson(ctx);\n\n // Is it create-react-app?\n const isCreateReactApp = \"react-scripts\" in packages;\n if (isCreateReactApp) {\n return {\n detectedFramework: \"create-react-app\",\n convexUrlEnvVar: \"REACT_APP_CONVEX_URL\",\n convexSiteEnvVar: \"REACT_APP_CONVEX_SITE_URL\",\n frontendDevUrl: \"http://localhost:3000\",\n publicPrefix: \"REACT_APP_\",\n };\n }\n\n const isNextJs = \"next\" in packages;\n if (isNextJs) {\n return {\n detectedFramework: \"Next.js\",\n convexUrlEnvVar: \"NEXT_PUBLIC_CONVEX_URL\",\n convexSiteEnvVar: \"NEXT_PUBLIC_CONVEX_SITE_URL\",\n frontendDevUrl: \"http://localhost:3000\",\n publicPrefix: \"NEXT_PUBLIC_\",\n };\n }\n\n const isExpo = \"expo\" in packages;\n if (isExpo) {\n return {\n detectedFramework: \"Expo\",\n convexUrlEnvVar: \"EXPO_PUBLIC_CONVEX_URL\",\n convexSiteEnvVar: \"EXPO_PUBLIC_CONVEX_SITE_URL\",\n publicPrefix: \"EXPO_PUBLIC_\",\n };\n }\n\n const isSvelteKit = \"@sveltejs/kit\" in packages;\n if (isSvelteKit) {\n return {\n detectedFramework: \"SvelteKit\",\n convexUrlEnvVar: \"PUBLIC_CONVEX_URL\",\n convexSiteEnvVar: \"PUBLIC_CONVEX_SITE_URL\",\n frontendDevUrl: \"http://localhost:5173\",\n publicPrefix: \"PUBLIC_\",\n };\n }\n\n // TanStackStart currently supports VITE_FOO for browser-side envvars.\n const isTanStackStart =\n \"@tanstack/start\" in packages || \"@tanstack/react-start\" in packages;\n\n if (isTanStackStart) {\n return {\n detectedFramework: \"TanStackStart\",\n convexUrlEnvVar: \"VITE_CONVEX_URL\",\n convexSiteEnvVar: \"VITE_CONVEX_SITE_URL\",\n frontendDevUrl: \"http://localhost:3000\",\n publicPrefix: \"VITE_\",\n };\n }\n\n // Vite is a dependency of a lot of things; vite appearing in dependencies is not a strong indicator.\n const isVite = \"vite\" in packages;\n\n if (isVite) {\n return {\n detectedFramework: \"Vite\",\n convexUrlEnvVar: \"VITE_CONVEX_URL\",\n convexSiteEnvVar: \"VITE_CONVEX_SITE_URL\",\n frontendDevUrl: \"http://localhost:5173\",\n publicPrefix: \"VITE_\",\n };\n }\n\n // We detect Remix after Vite because when using Remix as a plugin of Vite\n // (Remix Vite), we want to use Vite-style environment variables.\n const isRemix = \"@remix-run/dev\" in packages;\n if (isRemix) {\n return {\n detectedFramework: \"Remix\",\n convexUrlEnvVar: \"CONVEX_URL\",\n convexSiteEnvVar: \"CONVEX_SITE_URL\",\n frontendDevUrl: \"http://localhost:3000\",\n };\n }\n\n return {\n convexUrlEnvVar: \"CONVEX_URL\",\n convexSiteEnvVar: \"CONVEX_SITE_URL\",\n };\n}\n\nasync function loadEnvFileUrlConfig(\n ctx: Context,\n options: {\n convexUrl: string;\n siteUrl?: string | null | undefined;\n },\n): Promise<EnvFileUrlConfig> {\n const { detectedFramework, convexUrlEnvVar, convexSiteEnvVar } =\n await suggestedEnvVarNames(ctx);\n\n const { envFile, existing } = suggestedDevEnvFile(ctx, detectedFramework);\n\n if (!existing) {\n return {\n envFile,\n convexUrlEnvVar,\n siteUrlEnvVar: convexSiteEnvVar,\n existingFileContent: null,\n };\n }\n\n const existingFileContent = ctx.fs.readUtf8File(envFile);\n const config = dotenv.parse(existingFileContent);\n\n const resolvedConvexUrlEnvVar = resolveEnvVarName(\n convexUrlEnvVar,\n options.convexUrl,\n envFile,\n config,\n EXPECTED_CONVEX_URL_NAMES,\n );\n const resolvedSiteUrlEnvVar = resolveEnvVarName(\n convexSiteEnvVar,\n options.siteUrl ?? \"\",\n envFile,\n config,\n EXPECTED_SITE_URL_NAMES,\n );\n if (\n resolvedConvexUrlEnvVar.kind === \"invalid\" ||\n resolvedSiteUrlEnvVar.kind === \"invalid\"\n ) {\n return null;\n }\n return {\n envFile,\n convexUrlEnvVar: resolvedConvexUrlEnvVar.envVarName,\n siteUrlEnvVar: resolvedSiteUrlEnvVar.envVarName,\n existingFileContent,\n };\n}\n\nfunction resolveEnvVarName(\n envVarName: string,\n envVarValue: string,\n envFile: string,\n config: dotenv.DotenvParseOutput,\n expectedNames: Set<string>,\n):\n | {\n kind: \"invalid\";\n }\n | {\n kind: \"valid\";\n envVarName: string | null;\n } {\n const matching = Object.keys(config).filter((key) => expectedNames.has(key));\n if (matching.length > 1) {\n logWarning(\n chalkStderr.yellow(\n `Found multiple ${envVarName} environment variables in ${envFile} so cannot update automatically.`,\n ),\n );\n return { kind: \"invalid\" };\n }\n if (matching.length === 1) {\n const [existingEnvVarName, oldValue] = [matching[0], config[matching[0]]];\n if (oldValue === envVarValue) {\n // Set envVarName to null to indicate that it shouldn't be updated.\n return { kind: \"valid\", envVarName: null };\n }\n if (\n oldValue !== \"\" &&\n Object.values(config).filter((v) => v === oldValue).length !== 1\n ) {\n logWarning(\n chalkStderr.yellow(\n `Can't safely modify ${envFile} for ${envVarName}, please edit manually.`,\n ),\n );\n return { kind: \"invalid\" };\n }\n return { kind: \"valid\", envVarName: existingEnvVarName };\n }\n return { kind: \"valid\", envVarName };\n}\n\nfunction suggestedDevEnvFile(\n ctx: Context,\n framework?: Framework,\n): {\n existing: boolean;\n envFile: string;\n} {\n // If a .env.local file exists, that's unequivocally the right file\n if (ctx.fs.exists(\".env.local\")) {\n return {\n existing: true,\n envFile: \".env.local\",\n };\n }\n\n // Remix is on team \"don't commit the .env file,\" so .env is for dev.\n if (framework === \"Remix\") {\n return {\n existing: ctx.fs.exists(\".env\"),\n envFile: \".env\",\n };\n }\n\n // The most dev-looking env file that exists, or .env.local\n return {\n existing: ctx.fs.exists(\".env.local\"),\n envFile: \".env.local\",\n };\n}\n\nexport const EXPECTED_CONVEX_URL_NAMES = new Set([\n \"CONVEX_URL\" as const,\n \"PUBLIC_CONVEX_URL\" as const,\n \"NEXT_PUBLIC_CONVEX_URL\" as const,\n \"VITE_CONVEX_URL\" as const,\n \"REACT_APP_CONVEX_URL\" as const,\n \"EXPO_PUBLIC_CONVEX_URL\" as const,\n]);\ntype ConvexUrlEnvVar =\n typeof EXPECTED_CONVEX_URL_NAMES extends Set<infer T> ? T : never;\n\nexport const EXPECTED_SITE_URL_NAMES = new Set([\n \"CONVEX_SITE_URL\" as const,\n \"PUBLIC_CONVEX_SITE_URL\" as const,\n \"NEXT_PUBLIC_CONVEX_SITE_URL\" as const,\n \"VITE_CONVEX_SITE_URL\" as const,\n \"REACT_APP_CONVEX_SITE_URL\" as const,\n \"EXPO_PUBLIC_CONVEX_SITE_URL\" as const,\n]);\ntype ConvexSiteUrlEnvVar =\n typeof EXPECTED_SITE_URL_NAMES extends Set<infer T> ? T : never;\n\n// Crash or warn on\n// CONVEX_DEPLOY_KEY=project:me:new-project|eyABCD0= npx convex\n// which parses as\n// CONVEX_DEPLOY_KEY=project:me:new-project | eyABCD0='' npx convex\n// when what was intended was\n// CONVEX_DEPLOY_KEY=project:me:new-project|eyABCD0= npx convex\n// This only fails so catastrophically when the key ends with `=`.\nexport async function detectSuspiciousEnvironmentVariables(\n ctx: Context,\n ignoreSuspiciousEnvVars = false,\n) {\n for (const [key, value] of Object.entries(process.env)) {\n if (value === \"\" && key.startsWith(\"ey\")) {\n try {\n // add a \"=\" to the end and try to base64 decode (expected format of Convex keys)\n const decoded = JSON.parse(\n Buffer.from(key + \"=\", \"base64\").toString(\"utf8\"),\n );\n // Only parseable v2 tokens to be sure this is a Convex token before complaining.\n if (!(\"v2\" in decoded)) {\n continue;\n }\n } catch {\n continue;\n }\n\n if (ignoreSuspiciousEnvVars) {\n logWarning(\n `ignoring suspicious environment variable ${key}, did you mean to use quotes like CONVEX_DEPLOY_KEY='...'?`,\n );\n } else {\n return await ctx.crash({\n exitCode: 1,\n errorType: \"fatal\",\n printedMessage: `Quotes are required around environment variable values by your shell: CONVEX_DEPLOY_KEY='project:name:project|${key.slice(0, 4)}...${key.slice(key.length - 4)}=' npx convex dev`,\n });\n }\n }\n }\n}\n\nexport function getBuildEnvironment(): string | false {\n return process.env.VERCEL\n ? \"Vercel\"\n : process.env.NETLIFY\n ? \"Netlify\"\n : false;\n}\n\nexport function gitBranchFromEnvironment(): string | null {\n if (process.env.VERCEL) {\n // https://vercel.com/docs/projects/environment-variables/system-environment-variables\n return process.env.VERCEL_GIT_COMMIT_REF ?? null;\n }\n if (process.env.NETLIFY) {\n // https://docs.netlify.com/configure-builds/environment-variables/\n return process.env.HEAD ?? null;\n }\n\n if (process.env.CI) {\n // https://docs.github.com/en/actions/learn-github-actions/variables\n // https://docs.gitlab.com/ee/ci/variables/predefined_variables.html\n return (\n process.env.GITHUB_HEAD_REF ?? process.env.CI_COMMIT_REF_NAME ?? null\n );\n }\n\n return null;\n}\n\nexport function isNonProdBuildEnvironment(): boolean {\n if (process.env.VERCEL) {\n // https://vercel.com/docs/projects/environment-variables/system-environment-variables\n return process.env.VERCEL_ENV !== \"production\";\n }\n if (process.env.NETLIFY) {\n // https://docs.netlify.com/configure-builds/environment-variables/\n return process.env.CONTEXT !== \"production\";\n }\n return false;\n}\n"],
5
- "mappings": ";AAGA,SAAS,mBAAmB;AAC5B,YAAY,YAAY;AAGxB,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAEhC,MAAM,cAAc;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AA4BA,sBAAsB,mBACpB,KACA,SAI2B;AAC3B,QAAM,gBAAgB,MAAM,qBAAqB,KAAK,OAAO;AAE7D,MAAI,kBAAkB,MAAM;AAC1B,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,SAAS,iBAAiB,eAAe,oBAAoB,IACnE;AACF,MAAI,qBAAoC;AACxC,MAAI,iBAAiB;AACnB,yBAAqB,kBAAkB;AAAA,MACrC;AAAA,MACA,YAAY;AAAA,MACZ,aAAa,QAAQ;AAAA,MACrB,mBAAmB;AAAA,MACnB,uBAAuB;AAAA,IACzB,CAAC;AAAA,EACH;AACA,MAAI,iBAAiB,QAAQ,SAAS;AACpC,yBAAqB,kBAAkB;AAAA,MACrC,qBAAqB,sBAAsB;AAAA,MAC3C,YAAY;AAAA,MACZ,aAAa,QAAQ;AAAA,MACrB,mBAAmB;AAAA,MACnB,uBAAuB;AAAA,IACzB,CAAC;AAAA,EACH;AACA,MAAI,oBAAoB;AACtB,QAAI,GAAG,cAAc,SAAS,kBAAkB;AAAA,EAClD;AAEA,SAAO;AACT;AAEO,gBAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAMkB;AAChB,QAAM,gBAAgB,GAAG,UAAU,IAAI,WAAW,GAChD,sBAAsB,OAAO,KAAK,MAAM,iBAAiB,EAC3D;AACA,QAAM,q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AAI,QAAQ;AAEtB,WAAO,QAAQ,IAAI,yBAAyB;AAAA,EAC9C;AACA,MAAI,QAAQ,IAAI,SAAS;AAEvB,WAAO,QAAQ,IAAI,QAAQ;AAAA,EAC7B;AAEA,MAAI,QAAQ,IAAI,IAAI;AAGlB,WACE,QAAQ,IAAI,mBAAmB,QAAQ,IAAI,sBAAsB;AAAA,EAErE;AAEA,SAAO;AACT;AAEO,gBAAS,4BAAqC;AACnD,MAAI,QAAQ,IAAI,QAAQ;AAEtB,WAAO,QAAQ,IAAI,eAAe;AAAA,EACpC;AACA,MAAI,QAAQ,IAAI,SAAS;AAEvB,WAAO,QAAQ,IAAI,YAAY;AAAA,EACjC;AACA,SAAO;AACT;",
4
+ "sourcesContent": ["/**\n * Help the developer store the CONVEX_URL environment variable.\n */\nimport { chalkStderr } from \"chalk\";\nimport * as dotenv from \"dotenv\";\n\nimport { Context } from \"../../bundler/context.js\";\nimport { logWarning } from \"../../bundler/log.js\";\nimport { loadPackageJson } from \"./utils/utils.js\";\n\nconst _FRAMEWORKS = [\n \"create-react-app\",\n \"Next.js\",\n \"Vite\",\n \"Remix\",\n \"SvelteKit\",\n \"Expo\",\n \"TanStackStart\",\n] as const;\ntype Framework = (typeof _FRAMEWORKS)[number];\n\n/**\n * A configuration for writing the actual (framework specific) `CONVEX_URL`\n * and `CONVEX_SITE_URL` environment variables to a \".env\" type file.\n *\n * May be `null` if there was an error determining any of the field values.\n */\ntype EnvFileUrlConfig = {\n /** The name of the file - typically `.env.local` */\n envFile: string;\n /**\n * The framework specific `CONVEX_URL`\n *\n * If `null`, ignore and don't update that environment variable.\n */\n convexUrlEnvVar: string | null;\n /**\n * The framework specific `CONVEX_SITE_URL`\n *\n * If `null`, ignore and don't update that environment variable.\n */\n siteUrlEnvVar: string | null;\n /** Existing content loaded from the `envFile`, if it exists */\n existingFileContent: string | null;\n} | null;\n\nexport async function writeUrlsToEnvFile(\n ctx: Context,\n options: {\n convexUrl: string;\n siteUrl?: string | null | undefined;\n },\n): Promise<EnvFileUrlConfig> {\n const envFileConfig = await loadEnvFileUrlConfig(ctx, options);\n\n if (envFileConfig === null) {\n return null;\n }\n\n const { envFile, convexUrlEnvVar, siteUrlEnvVar, existingFileContent } =\n envFileConfig;\n let updatedFileContent: string | null = null;\n if (convexUrlEnvVar) {\n updatedFileContent = changedEnvVarFile({\n existingFileContent,\n envVarName: convexUrlEnvVar,\n envVarValue: options.convexUrl,\n commentAfterValue: null,\n commentOnPreviousLine: null,\n })!;\n }\n if (siteUrlEnvVar && options.siteUrl) {\n updatedFileContent = changedEnvVarFile({\n existingFileContent: updatedFileContent ?? existingFileContent,\n envVarName: siteUrlEnvVar,\n envVarValue: options.siteUrl,\n commentAfterValue: null,\n commentOnPreviousLine: null,\n })!;\n }\n if (updatedFileContent) {\n ctx.fs.writeUtf8File(envFile, updatedFileContent);\n }\n\n return envFileConfig;\n}\n\nexport function changedEnvVarFile({\n existingFileContent,\n envVarName,\n envVarValue,\n commentAfterValue,\n commentOnPreviousLine,\n}: {\n existingFileContent: string | null;\n envVarName: string;\n envVarValue: string;\n commentAfterValue: string | null;\n commentOnPreviousLine: string | null;\n}): string | null {\n const varAssignment = `${envVarName}=${envVarValue}${\n commentAfterValue === null ? \"\" : ` # ${commentAfterValue}`\n }`;\n const commentOnPreviousLineWithLineBreak =\n commentOnPreviousLine === null ? \"\" : `${commentOnPreviousLine}\\n`;\n if (existingFileContent === null) {\n return `${commentOnPreviousLineWithLineBreak}${varAssignment}\\n`;\n }\n const config = dotenv.parse(existingFileContent);\n const existing = config[envVarName];\n if (existing === envVarValue) {\n return null;\n }\n if (existing !== undefined) {\n return existingFileContent.replace(\n getEnvVarRegex(envVarName),\n `${varAssignment}`,\n );\n } else {\n const doubleLineBreak = existingFileContent.endsWith(\"\\n\") ? \"\\n\" : \"\\n\\n\";\n return (\n existingFileContent +\n doubleLineBreak +\n commentOnPreviousLineWithLineBreak +\n varAssignment +\n \"\\n\"\n );\n }\n}\n\nexport function getEnvVarRegex(envVarName: string) {\n return new RegExp(`^${envVarName}.*$`, \"m\");\n}\n\nexport async function suggestedEnvVarNames(ctx: Context): Promise<{\n detectedFramework?: Framework;\n convexUrlEnvVar: ConvexUrlEnvVar;\n convexSiteEnvVar: ConvexSiteUrlEnvVar;\n frontendDevUrl?: string;\n publicPrefix?: string;\n}> {\n // no package.json, that's fine, just guess\n if (!ctx.fs.exists(\"package.json\")) {\n return {\n convexUrlEnvVar: \"CONVEX_URL\",\n convexSiteEnvVar: \"CONVEX_SITE_URL\",\n };\n }\n\n const packages = await loadPackageJson(ctx);\n\n // Is it create-react-app?\n const isCreateReactApp = \"react-scripts\" in packages;\n if (isCreateReactApp) {\n return {\n detectedFramework: \"create-react-app\",\n convexUrlEnvVar: \"REACT_APP_CONVEX_URL\",\n convexSiteEnvVar: \"REACT_APP_CONVEX_SITE_URL\",\n frontendDevUrl: \"http://localhost:3000\",\n publicPrefix: \"REACT_APP_\",\n };\n }\n\n const isNextJs = \"next\" in packages;\n if (isNextJs) {\n return {\n detectedFramework: \"Next.js\",\n convexUrlEnvVar: \"NEXT_PUBLIC_CONVEX_URL\",\n convexSiteEnvVar: \"NEXT_PUBLIC_CONVEX_SITE_URL\",\n frontendDevUrl: \"http://localhost:3000\",\n publicPrefix: \"NEXT_PUBLIC_\",\n };\n }\n\n const isExpo = \"expo\" in packages;\n if (isExpo) {\n return {\n detectedFramework: \"Expo\",\n convexUrlEnvVar: \"EXPO_PUBLIC_CONVEX_URL\",\n convexSiteEnvVar: \"EXPO_PUBLIC_CONVEX_SITE_URL\",\n publicPrefix: \"EXPO_PUBLIC_\",\n };\n }\n\n const isSvelteKit = \"@sveltejs/kit\" in packages;\n if (isSvelteKit) {\n return {\n detectedFramework: \"SvelteKit\",\n convexUrlEnvVar: \"PUBLIC_CONVEX_URL\",\n convexSiteEnvVar: \"PUBLIC_CONVEX_SITE_URL\",\n frontendDevUrl: \"http://localhost:5173\",\n publicPrefix: \"PUBLIC_\",\n };\n }\n\n // TanStackStart currently supports VITE_FOO for browser-side envvars.\n const isTanStackStart =\n \"@tanstack/start\" in packages || \"@tanstack/react-start\" in packages;\n\n if (isTanStackStart) {\n return {\n detectedFramework: \"TanStackStart\",\n convexUrlEnvVar: \"VITE_CONVEX_URL\",\n convexSiteEnvVar: \"VITE_CONVEX_SITE_URL\",\n frontendDevUrl: \"http://localhost:3000\",\n publicPrefix: \"VITE_\",\n };\n }\n\n // Vite is a dependency of a lot of things; vite appearing in dependencies is not a strong indicator.\n const isVite = \"vite\" in packages;\n\n if (isVite) {\n return {\n detectedFramework: \"Vite\",\n convexUrlEnvVar: \"VITE_CONVEX_URL\",\n convexSiteEnvVar: \"VITE_CONVEX_SITE_URL\",\n frontendDevUrl: \"http://localhost:5173\",\n publicPrefix: \"VITE_\",\n };\n }\n\n // We detect Remix after Vite because when using Remix as a plugin of Vite\n // (Remix Vite), we want to use Vite-style environment variables.\n const isRemix = \"@remix-run/dev\" in packages;\n if (isRemix) {\n return {\n detectedFramework: \"Remix\",\n convexUrlEnvVar: \"CONVEX_URL\",\n convexSiteEnvVar: \"CONVEX_SITE_URL\",\n frontendDevUrl: \"http://localhost:3000\",\n };\n }\n\n return {\n convexUrlEnvVar: \"CONVEX_URL\",\n convexSiteEnvVar: \"CONVEX_SITE_URL\",\n };\n}\n\nasync function loadEnvFileUrlConfig(\n ctx: Context,\n options: {\n convexUrl: string;\n siteUrl?: string | null | undefined;\n },\n): Promise<EnvFileUrlConfig> {\n const { detectedFramework, convexUrlEnvVar, convexSiteEnvVar } =\n await suggestedEnvVarNames(ctx);\n\n const { envFile, existing } = suggestedDevEnvFile(ctx, detectedFramework);\n\n if (!existing) {\n return {\n envFile,\n convexUrlEnvVar,\n siteUrlEnvVar: convexSiteEnvVar,\n existingFileContent: null,\n };\n }\n\n const existingFileContent = ctx.fs.readUtf8File(envFile);\n const config = dotenv.parse(existingFileContent);\n\n const resolvedConvexUrlEnvVar = resolveEnvVarName(\n convexUrlEnvVar,\n options.convexUrl,\n envFile,\n config,\n EXPECTED_CONVEX_URL_NAMES,\n );\n const resolvedSiteUrlEnvVar = resolveEnvVarName(\n convexSiteEnvVar,\n options.siteUrl ?? \"\",\n envFile,\n config,\n EXPECTED_SITE_URL_NAMES,\n );\n if (\n resolvedConvexUrlEnvVar.kind === \"invalid\" ||\n resolvedSiteUrlEnvVar.kind === \"invalid\"\n ) {\n return null;\n }\n return {\n envFile,\n convexUrlEnvVar: resolvedConvexUrlEnvVar.envVarName,\n siteUrlEnvVar: resolvedSiteUrlEnvVar.envVarName,\n existingFileContent,\n };\n}\n\nfunction resolveEnvVarName(\n envVarName: string,\n envVarValue: string,\n envFile: string,\n config: dotenv.DotenvParseOutput,\n expectedNames: Set<string>,\n):\n | {\n kind: \"invalid\";\n }\n | {\n kind: \"valid\";\n envVarName: string | null;\n } {\n const matching = Object.keys(config).filter((key) => expectedNames.has(key));\n if (matching.length > 1) {\n logWarning(\n chalkStderr.yellow(\n `Found multiple ${envVarName} environment variables in ${envFile} so cannot update automatically.`,\n ),\n );\n return { kind: \"invalid\" };\n }\n if (matching.length === 1) {\n const [existingEnvVarName, oldValue] = [matching[0], config[matching[0]]];\n if (oldValue === envVarValue) {\n // Set envVarName to null to indicate that it shouldn't be updated.\n return { kind: \"valid\", envVarName: null };\n }\n if (\n oldValue !== \"\" &&\n Object.values(config).filter((v) => v === oldValue).length !== 1\n ) {\n logWarning(\n chalkStderr.yellow(\n `Can't safely modify ${envFile} for ${envVarName}, please edit manually.`,\n ),\n );\n return { kind: \"invalid\" };\n }\n return { kind: \"valid\", envVarName: existingEnvVarName };\n }\n return { kind: \"valid\", envVarName };\n}\n\nfunction suggestedDevEnvFile(\n ctx: Context,\n framework?: Framework,\n): {\n existing: boolean;\n envFile: string;\n} {\n // If a .env.local file exists, that's unequivocally the right file\n if (ctx.fs.exists(\".env.local\")) {\n return {\n existing: true,\n envFile: \".env.local\",\n };\n }\n\n // Remix is on team \"don't commit the .env file,\" so .env is for dev.\n if (framework === \"Remix\") {\n return {\n existing: ctx.fs.exists(\".env\"),\n envFile: \".env\",\n };\n }\n\n // The most dev-looking env file that exists, or .env.local\n return {\n existing: ctx.fs.exists(\".env.local\"),\n envFile: \".env.local\",\n };\n}\n\nexport const EXPECTED_CONVEX_URL_NAMES = new Set([\n \"CONVEX_URL\" as const,\n \"PUBLIC_CONVEX_URL\" as const,\n \"NEXT_PUBLIC_CONVEX_URL\" as const,\n \"VITE_CONVEX_URL\" as const,\n \"REACT_APP_CONVEX_URL\" as const,\n \"EXPO_PUBLIC_CONVEX_URL\" as const,\n]);\ntype ConvexUrlEnvVar =\n typeof EXPECTED_CONVEX_URL_NAMES extends Set<infer T> ? T : never;\n\nexport const EXPECTED_SITE_URL_NAMES = new Set([\n \"CONVEX_SITE_URL\" as const,\n \"PUBLIC_CONVEX_SITE_URL\" as const,\n \"NEXT_PUBLIC_CONVEX_SITE_URL\" as const,\n \"VITE_CONVEX_SITE_URL\" as const,\n \"REACT_APP_CONVEX_SITE_URL\" as const,\n \"EXPO_PUBLIC_CONVEX_SITE_URL\" as const,\n]);\ntype ConvexSiteUrlEnvVar =\n typeof EXPECTED_SITE_URL_NAMES extends Set<infer T> ? T : never;\n\n// Crash or warn on\n// CONVEX_DEPLOY_KEY=project:me:new-project|eyABCD0= npx convex\n// which parses as\n// CONVEX_DEPLOY_KEY=project:me:new-project | eyABCD0='' npx convex\n// when what was intended was\n// CONVEX_DEPLOY_KEY=project:me:new-project|eyABCD0= npx convex\n// This only fails so catastrophically when the key ends with `=`.\nexport async function detectSuspiciousEnvironmentVariables(\n ctx: Context,\n ignoreSuspiciousEnvVars = false,\n) {\n for (const [key, value] of Object.entries(process.env)) {\n if (value === \"\" && key.startsWith(\"ey\")) {\n try {\n // add a \"=\" to the end and try to base64 decode (expected format of Convex keys)\n const decoded = JSON.parse(\n Buffer.from(key + \"=\", \"base64\").toString(\"utf8\"),\n );\n // Only parseable v2 tokens to be sure this is a Convex token before complaining.\n if (!(\"v2\" in decoded)) {\n continue;\n }\n } catch {\n continue;\n }\n\n if (ignoreSuspiciousEnvVars) {\n logWarning(\n `ignoring suspicious environment variable ${key}, did you mean to use quotes like CONVEX_DEPLOY_KEY='...'?`,\n );\n } else {\n return await ctx.crash({\n exitCode: 1,\n errorType: \"fatal\",\n printedMessage: `Quotes are required around environment variable values by your shell: CONVEX_DEPLOY_KEY='project:name:project|${key.slice(0, 4)}...${key.slice(key.length - 4)}=' npx convex dev`,\n });\n }\n }\n }\n}\n\nexport function getBuildEnvironment(): string | false {\n return process.env.VERCEL\n ? \"Vercel\"\n : process.env.NETLIFY\n ? \"Netlify\"\n : process.env.CF_PAGES || process.env.WORKERS_CI\n ? \"Cloudflare\"\n : false;\n}\n\nexport function gitBranchFromEnvironment(): string | null {\n if (process.env.VERCEL) {\n // https://vercel.com/docs/projects/environment-variables/system-environment-variables\n return process.env.VERCEL_GIT_COMMIT_REF ?? null;\n }\n if (process.env.NETLIFY) {\n // https://docs.netlify.com/configure-builds/environment-variables/\n return process.env.HEAD ?? null;\n }\n if (process.env.CF_PAGES || process.env.WORKERS_CI) {\n // https://developers.cloudflare.com/pages/configuration/build-configuration/#environment-variables\n // https://developers.cloudflare.com/workers/ci-cd/builds/configuration/#environment-variables\n return process.env.CF_PAGES_BRANCH ?? process.env.WORKERS_CI_BRANCH ?? null;\n }\n\n if (process.env.CI) {\n // https://docs.github.com/en/actions/learn-github-actions/variables\n // https://docs.gitlab.com/ee/ci/variables/predefined_variables.html\n return (\n process.env.GITHUB_HEAD_REF ?? process.env.CI_COMMIT_REF_NAME ?? null\n );\n }\n\n return null;\n}\n\nexport function isNonProdBuildEnvironment(): boolean {\n if (process.env.VERCEL) {\n // https://vercel.com/docs/projects/environment-variables/system-environment-variables\n return process.env.VERCEL_ENV !== \"production\";\n }\n if (process.env.NETLIFY) {\n // https://docs.netlify.com/configure-builds/environment-variables/\n return process.env.CONTEXT !== \"production\";\n }\n if (process.env.CF_PAGES || process.env.WORKERS_CI) {\n // https://developers.cloudflare.com/pages/configuration/build-configuration/#environment-variables\n // https://developers.cloudflare.com/workers/ci-cd/builds/configuration/#environment-variables\n // Branch !== \"main\" is the closest heuristic; Cloudflare Pages\n // does not expose a dedicated production/preview flag.\n const branch = process.env.CF_PAGES_BRANCH ?? process.env.WORKERS_CI_BRANCH;\n return branch !== \"main\";\n }\n return false;\n}\n"],
5
+ "mappings": ";AAGA,SAAS,mBAAmB;AAC5B,YAAY,YAAY;AAGxB,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAEhC,MAAM,cAAc;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AA4BA,sBAAsB,mBACpB,KACA,SAI2B;AAC3B,QAAM,gBAAgB,MAAM,qBAAqB,KAAK,OAAO;AAE7D,MAAI,kBAAkB,MAAM;AAC1B,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,SAAS,iBAAiB,eAAe,oBAAoB,IACnE;AACF,MAAI,qBAAoC;AACxC,MAAI,iBAAiB;AACnB,yBAAqB,kBAAkB;AAAA,MACrC;AAAA,MACA,YAAY;AAAA,MACZ,aAAa,QAAQ;AAAA,MACrB,mBAAmB;AAAA,MACnB,uBAAuB;AAAA,IACzB,CAAC;AAAA,EACH;AACA,MAAI,iBAAiB,QAAQ,SAAS;AACpC,yBAAqB,kBAAkB;AAAA,MACrC,qBAAqB,sBAAsB;AAAA,MAC3C,YAAY;AAAA,MACZ,aAAa,QAAQ;AAAA,MACrB,mBAAmB;AAAA,MACnB,uBAAuB;AAAA,IACzB,CAAC;AAAA,EACH;AACA,MAAI,oBAAoB;AACtB,QAAI,GAAG,cAAc,SAAS,kBAAkB;AAAA,EAClD;AAEA,SAAO;AACT;AAEO,gBAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAMkB;AAChB,QAAM,gBAAgB,GAAG,UAAU,IAAI,WAAW,GAChD,sBAAsB,OAAO,KAAK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,YAAY,QAAQ,IAAI,aAClC,eACA;AACV;AAEO,gBAAS,2BAA0C;AACxD,MAAI,QAAQ,IAAI,QAAQ;AAEtB,WAAO,QAAQ,IAAI,yBAAyB;AAAA,EAC9C;AACA,MAAI,QAAQ,IAAI,SAAS;AAEvB,WAAO,QAAQ,IAAI,QAAQ;AAAA,EAC7B;AACA,MAAI,QAAQ,IAAI,YAAY,QAAQ,IAAI,YAAY;AAGlD,WAAO,QAAQ,IAAI,mBAAmB,QAAQ,IAAI,qBAAqB;AAAA,EACzE;AAEA,MAAI,QAAQ,IAAI,IAAI;AAGlB,WACE,QAAQ,IAAI,mBAAmB,QAAQ,IAAI,sBAAsB;AAAA,EAErE;AAEA,SAAO;AACT;AAEO,gBAAS,4BAAqC;AACnD,MAAI,QAAQ,IAAI,QAAQ;AAEtB,WAAO,QAAQ,IAAI,eAAe;AAAA,EACpC;AACA,MAAI,QAAQ,IAAI,SAAS;AAEvB,WAAO,QAAQ,IAAI,YAAY;AAAA,EACjC;AACA,MAAI,QAAQ,IAAI,YAAY,QAAQ,IAAI,YAAY;AAKlD,UAAM,SAAS,QAAQ,IAAI,mBAAmB,QAAQ,IAAI;AAC1D,WAAO,WAAW;AAAA,EACpB;AACA,SAAO;AACT;",
6
6
  "names": []
7
7
  }
package/dist/esm/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
- export const version = "1.35.0";
2
+ export const version = "1.35.1";
3
3
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["export const version = \"1.35.0\";\n"],
4
+ "sourcesContent": ["export const version = \"1.35.1\";\n"],
5
5
  "mappings": ";AAAO,aAAM,UAAU;",
6
6
  "names": []
7
7
  }
@@ -445,26 +445,13 @@ export const ConvexProvider = ({ client, children }) => {
445
445
  children
446
446
  );
447
447
  };
448
- export function useQuery(queryOrOptions, ...args) {
449
- const isObjectOptions = typeof queryOrOptions === "object" && queryOrOptions !== null && "query" in queryOrOptions;
450
- const throwOnError = isObjectOptions ? queryOrOptions.throwOnError ?? false : true;
451
- let queryReference;
452
- let argsObject = {};
453
- if (isObjectOptions) {
454
- const query = queryOrOptions.query;
455
- queryReference = typeof query === "string" ? makeFunctionReference(query) : query;
456
- if (queryOrOptions.args !== "skip") {
457
- argsObject = parseArgs(queryOrOptions.args);
458
- }
459
- } else {
460
- const query = queryOrOptions;
461
- queryReference = typeof query === "string" ? makeFunctionReference(query) : query;
462
- argsObject = args[0] === "skip" ? {} : parseArgs(args[0]);
463
- }
464
- const queryName = queryReference ? getFunctionName(queryReference) : void 0;
465
- const skip = isObjectOptions && queryOrOptions.args === "skip" || !isObjectOptions && args[0] === "skip";
448
+ export function useQuery(query, ...args) {
449
+ const skip = args[0] === "skip";
450
+ const argsObject = args[0] === "skip" ? {} : parseArgs(args[0]);
451
+ const queryReference = typeof query === "string" ? makeFunctionReference(query) : query;
452
+ const queryName = getFunctionName(queryReference);
466
453
  const queries = useMemo(
467
- () => skip || !queryReference ? {} : { query: { query: queryReference, args: argsObject } },
454
+ () => skip ? {} : { query: { query: queryReference, args: argsObject } },
468
455
  // Stringify args so args that are semantically the same don't trigger a
469
456
  // rerender. Saves developers from adding `useMemo` on every args usage.
470
457
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -472,30 +459,6 @@ export function useQuery(queryOrOptions, ...args) {
472
459
  );
473
460
  const results = useQueries(queries);
474
461
  const result = results["query"];
475
- if (isObjectOptions) {
476
- if (result instanceof Error) {
477
- if (throwOnError) {
478
- throw result;
479
- }
480
- return {
481
- data: void 0,
482
- error: result,
483
- status: "error"
484
- };
485
- }
486
- if (result === void 0) {
487
- return {
488
- data: void 0,
489
- error: void 0,
490
- status: "pending"
491
- };
492
- }
493
- return {
494
- data: result,
495
- error: void 0,
496
- status: "success"
497
- };
498
- }
499
462
  if (result instanceof Error) {
500
463
  throw result;
501
464
  }