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.
- package/CHANGELOG.md +31 -0
- package/dist/browser.bundle.js +1 -1
- package/dist/browser.bundle.js.map +1 -1
- package/dist/cjs/browser/simple_client-node.js +85 -27
- package/dist/cjs/browser/simple_client-node.js.map +3 -3
- package/dist/cjs/cli/env.js +12 -5
- package/dist/cjs/cli/env.js.map +2 -2
- package/dist/cjs/cli/envDefault.js +12 -7
- package/dist/cjs/cli/envDefault.js.map +2 -2
- package/dist/cjs/cli/insights.js +11 -1
- package/dist/cjs/cli/insights.js.map +2 -2
- package/dist/cjs/cli/lib/env.js +5 -1
- package/dist/cjs/cli/lib/env.js.map +2 -2
- package/dist/cjs/cli/lib/login.js +16 -12
- package/dist/cjs/cli/lib/login.js.map +2 -2
- package/dist/cjs/cli/lib/logs.js +4 -1
- package/dist/cjs/cli/lib/logs.js.map +2 -2
- package/dist/cjs/cli/lib/run.js +27 -2
- package/dist/cjs/cli/lib/run.js.map +2 -2
- package/dist/cjs/cli/lib/utils/utils.js +30 -0
- package/dist/cjs/cli/lib/utils/utils.js.map +2 -2
- package/dist/cjs/cli/program.js +2 -1
- package/dist/cjs/cli/program.js.map +2 -2
- package/dist/cjs/cli/project.js +27 -0
- package/dist/cjs/cli/project.js.map +7 -0
- package/dist/cjs/cli/projectCreate.js +90 -0
- package/dist/cjs/cli/projectCreate.js.map +7 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/server/database.js.map +1 -1
- package/dist/cjs/server/impl/meta_impl.js +6 -6
- package/dist/cjs/server/impl/meta_impl.js.map +2 -2
- package/dist/cjs/server/impl/registration_impl.js +9 -2
- package/dist/cjs/server/impl/registration_impl.js.map +2 -2
- package/dist/cjs/server/index.js.map +2 -2
- package/dist/cjs/server/meta.js.map +1 -1
- package/dist/cjs/server/query.js.map +1 -1
- package/dist/cjs/server/registration.js.map +1 -1
- package/dist/cjs/server/storage.js.map +1 -1
- package/dist/cjs/server/system_fields.js.map +1 -1
- package/dist/cjs-types/cli/env.d.ts.map +1 -1
- package/dist/cjs-types/cli/envDefault.d.ts.map +1 -1
- package/dist/cjs-types/cli/insights.d.ts +1 -0
- package/dist/cjs-types/cli/insights.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/env.d.ts +3 -1
- package/dist/cjs-types/cli/lib/env.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/env.test.d.ts +2 -0
- package/dist/cjs-types/cli/lib/env.test.d.ts.map +1 -0
- package/dist/cjs-types/cli/lib/login.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/logs.d.ts +1 -1
- package/dist/cjs-types/cli/lib/logs.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/run.d.ts +1 -1
- package/dist/cjs-types/cli/lib/run.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/utils/utils.d.ts +10 -0
- package/dist/cjs-types/cli/lib/utils/utils.d.ts.map +1 -1
- package/dist/cjs-types/cli/program.d.ts.map +1 -1
- package/dist/cjs-types/cli/project.d.ts +3 -0
- package/dist/cjs-types/cli/project.d.ts.map +1 -0
- package/dist/cjs-types/cli/projectCreate.d.ts +5 -0
- package/dist/cjs-types/cli/projectCreate.d.ts.map +1 -0
- package/dist/cjs-types/index.d.ts +1 -1
- package/dist/cjs-types/server/database.d.ts +21 -3
- package/dist/cjs-types/server/database.d.ts.map +1 -1
- package/dist/cjs-types/server/impl/meta_impl.d.ts.map +1 -1
- package/dist/cjs-types/server/impl/registration_impl.d.ts.map +1 -1
- package/dist/cjs-types/server/index.d.ts +1 -1
- package/dist/cjs-types/server/index.d.ts.map +1 -1
- package/dist/cjs-types/server/meta.d.ts +10 -0
- package/dist/cjs-types/server/meta.d.ts.map +1 -1
- package/dist/cjs-types/server/query.d.ts +1 -1
- package/dist/cjs-types/server/registration.d.ts +15 -3
- package/dist/cjs-types/server/registration.d.ts.map +1 -1
- package/dist/cjs-types/server/storage.d.ts +20 -3
- package/dist/cjs-types/server/storage.d.ts.map +1 -1
- package/dist/cli.bundle.cjs +1047 -619
- package/dist/cli.bundle.cjs.map +4 -4
- package/dist/esm/browser/simple_client-node.js +85 -27
- package/dist/esm/browser/simple_client-node.js.map +3 -3
- package/dist/esm/cli/env.js +12 -5
- package/dist/esm/cli/env.js.map +2 -2
- package/dist/esm/cli/envDefault.js +12 -7
- package/dist/esm/cli/envDefault.js.map +2 -2
- package/dist/esm/cli/insights.js +11 -1
- package/dist/esm/cli/insights.js.map +2 -2
- package/dist/esm/cli/lib/env.js +5 -1
- package/dist/esm/cli/lib/env.js.map +2 -2
- package/dist/esm/cli/lib/login.js +18 -13
- package/dist/esm/cli/lib/login.js.map +2 -2
- package/dist/esm/cli/lib/logs.js +5 -2
- package/dist/esm/cli/lib/logs.js.map +2 -2
- package/dist/esm/cli/lib/run.js +32 -3
- package/dist/esm/cli/lib/run.js.map +2 -2
- package/dist/esm/cli/lib/utils/utils.js +29 -0
- package/dist/esm/cli/lib/utils/utils.js.map +2 -2
- package/dist/esm/cli/program.js +2 -1
- package/dist/esm/cli/program.js.map +2 -2
- package/dist/esm/cli/project.js +5 -0
- package/dist/esm/cli/project.js.map +7 -0
- package/dist/esm/cli/projectCreate.js +68 -0
- package/dist/esm/cli/projectCreate.js.map +7 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/server/impl/meta_impl.js +6 -6
- package/dist/esm/server/impl/meta_impl.js.map +2 -2
- package/dist/esm/server/impl/registration_impl.js +9 -2
- package/dist/esm/server/impl/registration_impl.js.map +2 -2
- package/dist/esm/server/index.js.map +2 -2
- package/dist/esm-types/cli/env.d.ts.map +1 -1
- package/dist/esm-types/cli/envDefault.d.ts.map +1 -1
- package/dist/esm-types/cli/insights.d.ts +1 -0
- package/dist/esm-types/cli/insights.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/env.d.ts +3 -1
- package/dist/esm-types/cli/lib/env.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/env.test.d.ts +2 -0
- package/dist/esm-types/cli/lib/env.test.d.ts.map +1 -0
- package/dist/esm-types/cli/lib/login.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/logs.d.ts +1 -1
- package/dist/esm-types/cli/lib/logs.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/run.d.ts +1 -1
- package/dist/esm-types/cli/lib/run.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/utils/utils.d.ts +10 -0
- package/dist/esm-types/cli/lib/utils/utils.d.ts.map +1 -1
- package/dist/esm-types/cli/program.d.ts.map +1 -1
- package/dist/esm-types/cli/project.d.ts +3 -0
- package/dist/esm-types/cli/project.d.ts.map +1 -0
- package/dist/esm-types/cli/projectCreate.d.ts +5 -0
- package/dist/esm-types/cli/projectCreate.d.ts.map +1 -0
- package/dist/esm-types/index.d.ts +1 -1
- package/dist/esm-types/server/database.d.ts +21 -3
- package/dist/esm-types/server/database.d.ts.map +1 -1
- package/dist/esm-types/server/impl/meta_impl.d.ts.map +1 -1
- package/dist/esm-types/server/impl/registration_impl.d.ts.map +1 -1
- package/dist/esm-types/server/index.d.ts +1 -1
- package/dist/esm-types/server/index.d.ts.map +1 -1
- package/dist/esm-types/server/meta.d.ts +10 -0
- package/dist/esm-types/server/meta.d.ts.map +1 -1
- package/dist/esm-types/server/query.d.ts +1 -1
- package/dist/esm-types/server/registration.d.ts +15 -3
- package/dist/esm-types/server/registration.d.ts.map +1 -1
- package/dist/esm-types/server/storage.d.ts +20 -3
- package/dist/esm-types/server/storage.d.ts.map +1 -1
- package/dist/react.bundle.js +1 -1
- package/dist/react.bundle.js.map +1 -1
- package/package.json +4 -4
- package/src/cli/env.ts +16 -6
- package/src/cli/envDefault.ts +13 -7
- package/src/cli/insights.ts +12 -0
- package/src/cli/lib/env.test.ts +60 -0
- package/src/cli/lib/env.ts +9 -1
- package/src/cli/lib/login.ts +18 -18
- package/src/cli/lib/logs.ts +7 -2
- package/src/cli/lib/run.ts +37 -3
- package/src/cli/lib/utils/utils.ts +56 -0
- package/src/cli/program.ts +2 -0
- package/src/cli/project.ts +7 -0
- package/src/cli/projectCreate.ts +99 -0
- package/src/index.ts +1 -1
- package/src/server/database.ts +21 -3
- package/src/server/impl/meta_impl.ts +7 -6
- package/src/server/impl/registration_impl.ts +11 -3
- package/src/server/index.ts +1 -0
- package/src/server/meta.ts +10 -0
- package/src/server/query.ts +1 -1
- package/src/server/registration.test.ts +25 -1
- package/src/server/registration.ts +16 -1
- package/src/server/storage.ts +22 -3
- 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 {
|
|
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 } =
|
|
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
|
-
|
|
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
|
-
|
|
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);
|
package/src/server/index.ts
CHANGED
|
@@ -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,
|
package/src/server/meta.ts
CHANGED
|
@@ -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
|
/**
|
package/src/server/query.ts
CHANGED
|
@@ -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,
|
|
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
|
+
}
|
package/src/server/storage.ts
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
import { GenericId } from "../values/index.js";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* @deprecated This ID format is no longer returned by stable file storage APIs. Use `Id<"_storage">` instead.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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
|
|