convex 1.41.0 → 1.42.0

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 (167) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/browser.bundle.js +1 -1
  3. package/dist/browser.bundle.js.map +1 -1
  4. package/dist/cjs/browser/simple_client-node.js +85 -27
  5. package/dist/cjs/browser/simple_client-node.js.map +3 -3
  6. package/dist/cjs/cli/env.js +12 -5
  7. package/dist/cjs/cli/env.js.map +2 -2
  8. package/dist/cjs/cli/envDefault.js +12 -7
  9. package/dist/cjs/cli/envDefault.js.map +2 -2
  10. package/dist/cjs/cli/insights.js +11 -1
  11. package/dist/cjs/cli/insights.js.map +2 -2
  12. package/dist/cjs/cli/lib/env.js +5 -1
  13. package/dist/cjs/cli/lib/env.js.map +2 -2
  14. package/dist/cjs/cli/lib/login.js +16 -12
  15. package/dist/cjs/cli/lib/login.js.map +2 -2
  16. package/dist/cjs/cli/lib/logs.js +4 -1
  17. package/dist/cjs/cli/lib/logs.js.map +2 -2
  18. package/dist/cjs/cli/lib/run.js +27 -2
  19. package/dist/cjs/cli/lib/run.js.map +2 -2
  20. package/dist/cjs/cli/lib/utils/utils.js +30 -0
  21. package/dist/cjs/cli/lib/utils/utils.js.map +2 -2
  22. package/dist/cjs/cli/program.js +2 -1
  23. package/dist/cjs/cli/program.js.map +2 -2
  24. package/dist/cjs/cli/project.js +27 -0
  25. package/dist/cjs/cli/project.js.map +7 -0
  26. package/dist/cjs/cli/projectCreate.js +90 -0
  27. package/dist/cjs/cli/projectCreate.js.map +7 -0
  28. package/dist/cjs/index.js +1 -1
  29. package/dist/cjs/index.js.map +1 -1
  30. package/dist/cjs/server/database.js.map +1 -1
  31. package/dist/cjs/server/impl/meta_impl.js +6 -6
  32. package/dist/cjs/server/impl/meta_impl.js.map +2 -2
  33. package/dist/cjs/server/impl/registration_impl.js +9 -2
  34. package/dist/cjs/server/impl/registration_impl.js.map +2 -2
  35. package/dist/cjs/server/index.js.map +2 -2
  36. package/dist/cjs/server/meta.js.map +1 -1
  37. package/dist/cjs/server/query.js.map +1 -1
  38. package/dist/cjs/server/registration.js.map +1 -1
  39. package/dist/cjs/server/storage.js.map +1 -1
  40. package/dist/cjs/server/system_fields.js.map +1 -1
  41. package/dist/cjs-types/cli/env.d.ts.map +1 -1
  42. package/dist/cjs-types/cli/envDefault.d.ts.map +1 -1
  43. package/dist/cjs-types/cli/insights.d.ts +1 -0
  44. package/dist/cjs-types/cli/insights.d.ts.map +1 -1
  45. package/dist/cjs-types/cli/lib/env.d.ts +3 -1
  46. package/dist/cjs-types/cli/lib/env.d.ts.map +1 -1
  47. package/dist/cjs-types/cli/lib/env.test.d.ts +2 -0
  48. package/dist/cjs-types/cli/lib/env.test.d.ts.map +1 -0
  49. package/dist/cjs-types/cli/lib/login.d.ts.map +1 -1
  50. package/dist/cjs-types/cli/lib/logs.d.ts +1 -1
  51. package/dist/cjs-types/cli/lib/logs.d.ts.map +1 -1
  52. package/dist/cjs-types/cli/lib/run.d.ts +1 -1
  53. package/dist/cjs-types/cli/lib/run.d.ts.map +1 -1
  54. package/dist/cjs-types/cli/lib/utils/utils.d.ts +10 -0
  55. package/dist/cjs-types/cli/lib/utils/utils.d.ts.map +1 -1
  56. package/dist/cjs-types/cli/program.d.ts.map +1 -1
  57. package/dist/cjs-types/cli/project.d.ts +3 -0
  58. package/dist/cjs-types/cli/project.d.ts.map +1 -0
  59. package/dist/cjs-types/cli/projectCreate.d.ts +5 -0
  60. package/dist/cjs-types/cli/projectCreate.d.ts.map +1 -0
  61. package/dist/cjs-types/index.d.ts +1 -1
  62. package/dist/cjs-types/server/database.d.ts +21 -3
  63. package/dist/cjs-types/server/database.d.ts.map +1 -1
  64. package/dist/cjs-types/server/impl/meta_impl.d.ts.map +1 -1
  65. package/dist/cjs-types/server/impl/registration_impl.d.ts.map +1 -1
  66. package/dist/cjs-types/server/index.d.ts +1 -1
  67. package/dist/cjs-types/server/index.d.ts.map +1 -1
  68. package/dist/cjs-types/server/meta.d.ts +10 -0
  69. package/dist/cjs-types/server/meta.d.ts.map +1 -1
  70. package/dist/cjs-types/server/query.d.ts +1 -1
  71. package/dist/cjs-types/server/registration.d.ts +15 -3
  72. package/dist/cjs-types/server/registration.d.ts.map +1 -1
  73. package/dist/cjs-types/server/storage.d.ts +20 -3
  74. package/dist/cjs-types/server/storage.d.ts.map +1 -1
  75. package/dist/cli.bundle.cjs +1047 -619
  76. package/dist/cli.bundle.cjs.map +4 -4
  77. package/dist/esm/browser/simple_client-node.js +85 -27
  78. package/dist/esm/browser/simple_client-node.js.map +3 -3
  79. package/dist/esm/cli/env.js +12 -5
  80. package/dist/esm/cli/env.js.map +2 -2
  81. package/dist/esm/cli/envDefault.js +12 -7
  82. package/dist/esm/cli/envDefault.js.map +2 -2
  83. package/dist/esm/cli/insights.js +11 -1
  84. package/dist/esm/cli/insights.js.map +2 -2
  85. package/dist/esm/cli/lib/env.js +5 -1
  86. package/dist/esm/cli/lib/env.js.map +2 -2
  87. package/dist/esm/cli/lib/login.js +18 -13
  88. package/dist/esm/cli/lib/login.js.map +2 -2
  89. package/dist/esm/cli/lib/logs.js +5 -2
  90. package/dist/esm/cli/lib/logs.js.map +2 -2
  91. package/dist/esm/cli/lib/run.js +32 -3
  92. package/dist/esm/cli/lib/run.js.map +2 -2
  93. package/dist/esm/cli/lib/utils/utils.js +29 -0
  94. package/dist/esm/cli/lib/utils/utils.js.map +2 -2
  95. package/dist/esm/cli/program.js +2 -1
  96. package/dist/esm/cli/program.js.map +2 -2
  97. package/dist/esm/cli/project.js +5 -0
  98. package/dist/esm/cli/project.js.map +7 -0
  99. package/dist/esm/cli/projectCreate.js +68 -0
  100. package/dist/esm/cli/projectCreate.js.map +7 -0
  101. package/dist/esm/index.js +1 -1
  102. package/dist/esm/index.js.map +1 -1
  103. package/dist/esm/server/impl/meta_impl.js +6 -6
  104. package/dist/esm/server/impl/meta_impl.js.map +2 -2
  105. package/dist/esm/server/impl/registration_impl.js +9 -2
  106. package/dist/esm/server/impl/registration_impl.js.map +2 -2
  107. package/dist/esm/server/index.js.map +2 -2
  108. package/dist/esm-types/cli/env.d.ts.map +1 -1
  109. package/dist/esm-types/cli/envDefault.d.ts.map +1 -1
  110. package/dist/esm-types/cli/insights.d.ts +1 -0
  111. package/dist/esm-types/cli/insights.d.ts.map +1 -1
  112. package/dist/esm-types/cli/lib/env.d.ts +3 -1
  113. package/dist/esm-types/cli/lib/env.d.ts.map +1 -1
  114. package/dist/esm-types/cli/lib/env.test.d.ts +2 -0
  115. package/dist/esm-types/cli/lib/env.test.d.ts.map +1 -0
  116. package/dist/esm-types/cli/lib/login.d.ts.map +1 -1
  117. package/dist/esm-types/cli/lib/logs.d.ts +1 -1
  118. package/dist/esm-types/cli/lib/logs.d.ts.map +1 -1
  119. package/dist/esm-types/cli/lib/run.d.ts +1 -1
  120. package/dist/esm-types/cli/lib/run.d.ts.map +1 -1
  121. package/dist/esm-types/cli/lib/utils/utils.d.ts +10 -0
  122. package/dist/esm-types/cli/lib/utils/utils.d.ts.map +1 -1
  123. package/dist/esm-types/cli/program.d.ts.map +1 -1
  124. package/dist/esm-types/cli/project.d.ts +3 -0
  125. package/dist/esm-types/cli/project.d.ts.map +1 -0
  126. package/dist/esm-types/cli/projectCreate.d.ts +5 -0
  127. package/dist/esm-types/cli/projectCreate.d.ts.map +1 -0
  128. package/dist/esm-types/index.d.ts +1 -1
  129. package/dist/esm-types/server/database.d.ts +21 -3
  130. package/dist/esm-types/server/database.d.ts.map +1 -1
  131. package/dist/esm-types/server/impl/meta_impl.d.ts.map +1 -1
  132. package/dist/esm-types/server/impl/registration_impl.d.ts.map +1 -1
  133. package/dist/esm-types/server/index.d.ts +1 -1
  134. package/dist/esm-types/server/index.d.ts.map +1 -1
  135. package/dist/esm-types/server/meta.d.ts +10 -0
  136. package/dist/esm-types/server/meta.d.ts.map +1 -1
  137. package/dist/esm-types/server/query.d.ts +1 -1
  138. package/dist/esm-types/server/registration.d.ts +15 -3
  139. package/dist/esm-types/server/registration.d.ts.map +1 -1
  140. package/dist/esm-types/server/storage.d.ts +20 -3
  141. package/dist/esm-types/server/storage.d.ts.map +1 -1
  142. package/dist/react.bundle.js +1 -1
  143. package/dist/react.bundle.js.map +1 -1
  144. package/package.json +4 -4
  145. package/src/cli/env.ts +16 -6
  146. package/src/cli/envDefault.ts +13 -7
  147. package/src/cli/insights.ts +12 -0
  148. package/src/cli/lib/env.test.ts +60 -0
  149. package/src/cli/lib/env.ts +9 -1
  150. package/src/cli/lib/login.ts +18 -18
  151. package/src/cli/lib/logs.ts +7 -2
  152. package/src/cli/lib/run.ts +37 -3
  153. package/src/cli/lib/utils/utils.ts +56 -0
  154. package/src/cli/program.ts +2 -0
  155. package/src/cli/project.ts +7 -0
  156. package/src/cli/projectCreate.ts +99 -0
  157. package/src/index.ts +1 -1
  158. package/src/server/database.ts +21 -3
  159. package/src/server/impl/meta_impl.ts +7 -6
  160. package/src/server/impl/registration_impl.ts +11 -3
  161. package/src/server/index.ts +1 -0
  162. package/src/server/meta.ts +10 -0
  163. package/src/server/query.ts +1 -1
  164. package/src/server/registration.test.ts +25 -1
  165. package/src/server/registration.ts +16 -1
  166. package/src/server/storage.ts +22 -3
  167. package/src/server/system_fields.ts +1 -1
@@ -34,7 +34,10 @@ async function getFunctionMetadata(): Promise<{
34
34
  "1.0/getFunctionMetadata",
35
35
  {},
36
36
  );
37
- return { name, componentPath };
37
+ return {
38
+ name,
39
+ componentPath,
40
+ };
38
41
  }
39
42
 
40
43
  async function getDeploymentMetadata(): Promise<DeploymentMetadata> {
@@ -51,11 +54,9 @@ async function getDeploymentMetadata(): Promise<DeploymentMetadata> {
51
54
  }
52
55
 
53
56
  async function getRequestMetadata(): Promise<RequestMetadata> {
54
- const { ip, userAgent, requestId } = await performAsyncSyscall(
55
- "1.0/getRequestMetadata",
56
- {},
57
- );
58
- return { ip, userAgent, requestId };
57
+ const { ip, userAgent, requestId, scheduledFunctionId } =
58
+ await performAsyncSyscall("1.0/getRequestMetadata", {});
59
+ return { ip, userAgent, requestId, scheduledFunctionId };
59
60
  }
60
61
 
61
62
  export function setupQueryMeta(
@@ -61,7 +61,9 @@ async function invokeMutation<
61
61
  meta: setupMutationMeta(visibility),
62
62
 
63
63
  runQuery: (reference: any, args?: any, options?: any) =>
64
- runUdf("query", reference, args, options?.transactionLimits),
64
+ options?.useStaleSnapshot
65
+ ? runUdf("snapshotQuery", reference, args, options?.transactionLimits)
66
+ : runUdf("query", reference, args, options?.transactionLimits),
65
67
  runMutation: (reference: any, args?: any, options?: any) =>
66
68
  runUdf("mutation", reference, args, options?.transactionLimits),
67
69
  };
@@ -336,8 +338,14 @@ async function invokeQuery<
336
338
  auth: setupAuth(requestId),
337
339
  storage: setupStorageReader(requestId),
338
340
  meta: setupQueryMeta(visibility),
339
- runQuery: (reference: any, args?: any, options?: any) =>
340
- runUdf("query", reference, args, options?.transactionLimits),
341
+ runQuery: (reference: any, args?: any, options?: any) => {
342
+ if (options?.useStaleSnapshot) {
343
+ throw new Error(
344
+ "`useStaleSnapshot` is only supported in mutations, not queries.",
345
+ );
346
+ }
347
+ return runUdf("query", reference, args, options?.transactionLimits);
348
+ },
341
349
  };
342
350
  const result = await invokeFunction(func, queryCtx, args as any);
343
351
  validateReturnValue(result);
@@ -118,6 +118,7 @@ export type { IndexRange, IndexRangeBuilder } from "./index_range_builder.js";
118
118
  export * from "./pagination.js";
119
119
  export type { OrderedQuery, Query, QueryInitializer } from "./query.js";
120
120
  export type {
121
+ AdvancedRunQueryOptions,
121
122
  ArgsArray,
122
123
  DefaultFunctionArgs,
123
124
  FunctionVisibility,
@@ -104,6 +104,16 @@ export type RequestMetadata = {
104
104
  ip: string | null;
105
105
  userAgent: string | null;
106
106
  requestId: string;
107
+ /**
108
+ * The ID of the scheduled function document (in `_scheduled_functions`) that
109
+ * this execution belongs to, or `null` otherwise.
110
+ *
111
+ * This is set for the scheduled function itself and for any functions it
112
+ * calls (e.g. a mutation invoked via `runMutation` by a scheduled action),
113
+ * propagating the top-level scheduled function's ID down the call tree. It is
114
+ * `null` when the function was not scheduled.
115
+ */
116
+ scheduledFunctionId: string | null;
107
117
  };
108
118
 
109
119
  /**
@@ -106,7 +106,7 @@ export interface QueryInitializer<TableInfo extends GenericTableInfo>
106
106
  /**
107
107
  * The {@link Query} interface allows functions to read values out of the database.
108
108
  *
109
- * **If you only need to load an object by ID, use `db.get(id)` instead.**
109
+ * **If you only need to load an object by ID, use `db.get(tableName, id)` instead.**
110
110
  *
111
111
  * Executing a query consists of calling
112
112
  * 1. (Optional) {@link Query.order} to define the order
@@ -1,11 +1,14 @@
1
1
  /* eslint-disable @typescript-eslint/no-unused-vars */
2
2
  import { test, describe, expect } from "vitest";
3
- import { assert, Equals } from "../test/type_testing.js";
3
+ import { assert, assertFalse, Equals } from "../test/type_testing.js";
4
4
  import { v } from "../values/validator.js";
5
5
  import {
6
6
  ActionBuilder,
7
7
  ApiFromModules,
8
8
  DefaultFunctionArgs,
9
+ GenericDataModel,
10
+ GenericMutationCtx,
11
+ GenericQueryCtx,
9
12
  QueryBuilder,
10
13
  actionGeneric,
11
14
  mutationGeneric,
@@ -563,3 +566,24 @@ describe("argument and return value validators can be objects or validators", ()
563
566
  expect(JSON.parse(returnString)).toEqual(expectedReturnsExport);
564
567
  });
565
568
  });
569
+
570
+ describe("useStaleSnapshot availability", () => {
571
+ type MutationRunQueryOptions = NonNullable<
572
+ Parameters<GenericMutationCtx<GenericDataModel>["runQuery"]>[2]
573
+ >;
574
+ type QueryRunQueryOptions = NonNullable<
575
+ Parameters<GenericQueryCtx<GenericDataModel>["runQuery"]>[2]
576
+ >;
577
+
578
+ test("available on mutation ctx runQuery options", () => {
579
+ assert<
580
+ "useStaleSnapshot" extends keyof MutationRunQueryOptions ? true : false
581
+ >();
582
+ });
583
+
584
+ test("not available on query ctx runQuery options", () => {
585
+ assertFalse<
586
+ "useStaleSnapshot" extends keyof QueryRunQueryOptions ? true : false
587
+ >();
588
+ });
589
+ });
@@ -135,7 +135,7 @@ export interface GenericMutationCtx<DataModel extends GenericDataModel> {
135
135
  */
136
136
  runQuery: <Query extends FunctionReference<"query", "public" | "internal">>(
137
137
  query: Query,
138
- ...args: ArgsAndOptions<Query, { transactionLimits?: TransactionLimits }>
138
+ ...args: ArgsAndOptions<Query, AdvancedRunQueryOptions>
139
139
  ) => Promise<FunctionReturnType<Query>>;
140
140
 
141
141
  /**
@@ -1211,3 +1211,18 @@ export type ActionBuilder<
1211
1211
  export type HttpActionBuilder = (
1212
1212
  func: (ctx: GenericActionCtx<any>, request: Request) => Promise<Response>,
1213
1213
  ) => PublicHttpAction;
1214
+
1215
+ export interface AdvancedRunQueryOptions {
1216
+ transactionLimits?: TransactionLimits;
1217
+ /**
1218
+ * Run a query on a recent snapshot of the database that is not guaranteed
1219
+ * to be up-to-date when this transaction commits.
1220
+ *
1221
+ * This is an advanced feature which can introduce subtle race conditions,
1222
+ * so its use is generally discouraged except for specific use-cases where
1223
+ * database read conflicts are expected, e.g. reading from an append-only
1224
+ * table with immutable records where the only read conflicts are from
1225
+ * concurrent appends.
1226
+ */
1227
+ useStaleSnapshot?: boolean;
1228
+ }
@@ -1,16 +1,28 @@
1
1
  import { GenericId } from "../values/index.js";
2
2
 
3
3
  /**
4
- * A reference to a file in storage.
4
+ * @deprecated This ID format is no longer returned by stable file storage APIs. Use `Id<"_storage">` instead.
5
5
  *
6
- * This is used in the {@link StorageReader} and {@link StorageWriter} which are accessible in
7
- * Convex queries and mutations via {@link QueryCtx} and {@link MutationCtx} respectively.
6
+ * The old ID format used by Convex file storage.
7
+ *
8
+ * ⚠️ Security warning: Anyone that has knows to this ID can download the underlying file
9
+ * from `https://<deployment>.convex.cloud/api/storage/<storageId>`.
10
+ * (Note that it’s safe to share the new ID format, `Id<"_storage">`, to anyone).
8
11
  *
9
12
  * @public
10
13
  */
11
14
  export type StorageId = string;
15
+
16
+ /**
17
+ * @deprecated This type is only necessary for backwards compatibility with Convex versions that
18
+ * pre-date `convex@1.6.0`. Use `Id<"_storage">` instead.
19
+ */
12
20
  export type FileStorageId = GenericId<"_storage"> | StorageId;
21
+
13
22
  /**
23
+ * @deprecated This type is only returned by {@link StorageReader.getUrl | storage.getUrl}.
24
+ * To get the details of a document, use `ctx.db.system.get("_storage", storageId)` instead.
25
+ *
14
26
  * Metadata for a single file as returned by {@link StorageReader.getMetadata | storage.getMetadata}.
15
27
  *
16
28
  * @public
@@ -18,6 +30,13 @@ export type FileStorageId = GenericId<"_storage"> | StorageId;
18
30
  export type FileMetadata = {
19
31
  /**
20
32
  * ID for referencing the file (eg. via {@link StorageReader.getUrl | storage.getUrl})
33
+ *
34
+ * This is an older ID format that is no longer returned by stable file storage APIs.
35
+ * Consider using `Id<"_storage">` instead.
36
+ *
37
+ * ⚠️ Security warning: Anyone that has knows to this ID can download the underlying file
38
+ * from `https://<deployment>.convex.cloud/api/storage/<storageId>`.
39
+ * (Note that it’s safe to share the new ID format, `Id<"_storage">`, to anyone).
21
40
  */
22
41
  storageId: StorageId;
23
42
  /**
@@ -46,7 +46,7 @@ export type WithOptionalSystemFields<Document extends GenericDocument> = Expand<
46
46
  * @public
47
47
  */
48
48
  export type SystemIndexes = {
49
- // Note `db.get(id)` is simpler and equivalent to a query on `by_id`.
49
+ // Note `db.get(tableName, id)` is simpler and equivalent to a query on `by_id`.
50
50
  // Unless the query is being built dynamically, or doing manual pagination.
51
51
  by_id: ["_id"];
52
52