convex 1.45.0 → 1.46.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 +48 -6
- package/dist/browser.bundle.js +1 -1
- package/dist/browser.bundle.js.map +2 -2
- package/dist/cjs/browser/http_client.js.map +2 -2
- package/dist/cjs/browser/query_options.js.map +2 -2
- package/dist/cjs/browser/simple_client.js.map +2 -2
- package/dist/cjs/browser/sync/optimistic_updates.js.map +1 -1
- package/dist/cjs/browser/sync/optimistic_updates_impl.js.map +2 -2
- package/dist/cjs/cli/codegen.js +2 -0
- package/dist/cjs/cli/codegen.js.map +2 -2
- package/dist/cjs/cli/deploy.js +1 -0
- package/dist/cjs/cli/deploy.js.map +2 -2
- package/dist/cjs/cli/docs.js +3 -36
- package/dist/cjs/cli/docs.js.map +2 -2
- package/dist/cjs/cli/lib/checkForLargeIndexDeletion.js +101 -60
- package/dist/cjs/cli/lib/checkForLargeIndexDeletion.js.map +2 -2
- package/dist/cjs/cli/lib/checkForSlowSchemaValidation.js +107 -0
- package/dist/cjs/cli/lib/checkForSlowSchemaValidation.js.map +7 -0
- package/dist/cjs/cli/lib/codegen.js.map +2 -2
- package/dist/cjs/cli/lib/components.js +12 -0
- package/dist/cjs/cli/lib/components.js.map +2 -2
- package/dist/cjs/cli/lib/deploy2.js +29 -2
- package/dist/cjs/cli/lib/deploy2.js.map +2 -2
- package/dist/cjs/cli/lib/deployApi/evaluateSchema.js +73 -0
- package/dist/cjs/cli/lib/deployApi/evaluateSchema.js.map +7 -0
- package/dist/cjs/cli/lib/deployApi/finishPush.js +1 -0
- package/dist/cjs/cli/lib/deployApi/finishPush.js.map +2 -2
- package/dist/cjs/cli/lib/deployApi/startPush.js +1 -1
- package/dist/cjs/cli/lib/deployApi/startPush.js.map +2 -2
- package/dist/cjs/cli/lib/dev.js +1 -0
- package/dist/cjs/cli/lib/dev.js.map +2 -2
- package/dist/cjs/cli/lib/generatedFunctionLogsApi.js.map +1 -1
- package/dist/cjs/cli/lib/localDeployment/run.js +30 -1
- package/dist/cjs/cli/lib/localDeployment/run.js.map +2 -2
- package/dist/cjs/cli/lib/localDeployment/upgrade.js +6 -5
- package/dist/cjs/cli/lib/localDeployment/upgrade.js.map +2 -2
- package/dist/cjs/cli/lib/localDeployment/utils.js +5 -1
- package/dist/cjs/cli/lib/localDeployment/utils.js.map +2 -2
- package/dist/cjs/cli/lib/run.js +1 -0
- package/dist/cjs/cli/lib/run.js.map +2 -2
- package/dist/cjs/cli/lib/utils/utils.js +36 -29
- package/dist/cjs/cli/lib/utils/utils.js.map +2 -2
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/nextjs/index.js.map +2 -2
- package/dist/cjs/react/client.js.map +2 -2
- package/dist/cjs/react/hydration.js.map +2 -2
- package/dist/cjs/react/queries_observer.js.map +2 -2
- package/dist/cjs/react/use_paginated_query2.js.map +2 -2
- package/dist/cjs/react/use_queries.js.map +2 -2
- package/dist/cjs/server/api.js.map +2 -2
- package/dist/cjs/server/components/index.js.map +2 -2
- package/dist/cjs/server/cron.js +10 -10
- package/dist/cjs/server/cron.js.map +2 -2
- package/dist/cjs/server/impl/actions_impl.js.map +2 -2
- package/dist/cjs/server/impl/meta_impl.js +8 -2
- package/dist/cjs/server/impl/meta_impl.js.map +2 -2
- package/dist/cjs/server/impl/scheduler_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/registration.js.map +1 -1
- package/dist/cjs/server/scheduler.js.map +1 -1
- package/dist/cjs/server/schema.js +50 -3
- package/dist/cjs/server/schema.js.map +2 -2
- package/dist/cjs/values/validator.js +1 -1
- package/dist/cjs/values/validator.js.map +2 -2
- package/dist/cjs/values/validators.js +81 -25
- package/dist/cjs/values/validators.js.map +2 -2
- package/dist/cjs-types/browser/http_client.d.ts +5 -5
- package/dist/cjs-types/browser/http_client.d.ts.map +1 -1
- package/dist/cjs-types/browser/query_options.d.ts +2 -2
- package/dist/cjs-types/browser/query_options.d.ts.map +1 -1
- package/dist/cjs-types/browser/simple_client.d.ts +6 -6
- package/dist/cjs-types/browser/simple_client.d.ts.map +1 -1
- package/dist/cjs-types/browser/sync/optimistic_updates.d.ts +4 -4
- package/dist/cjs-types/browser/sync/optimistic_updates.d.ts.map +1 -1
- package/dist/cjs-types/browser/sync/optimistic_updates_impl.d.ts.map +1 -1
- package/dist/cjs-types/cli/codegen.d.ts.map +1 -1
- package/dist/cjs-types/cli/docs.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/checkForLargeIndexDeletion.d.ts +26 -5
- package/dist/cjs-types/cli/lib/checkForLargeIndexDeletion.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/checkForSlowSchemaValidation.d.ts +14 -0
- package/dist/cjs-types/cli/lib/checkForSlowSchemaValidation.d.ts.map +1 -0
- package/dist/cjs-types/cli/lib/codegen.d.ts +1 -0
- package/dist/cjs-types/cli/lib/codegen.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/components.d.ts +1 -0
- package/dist/cjs-types/cli/lib/components.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/deploy2.d.ts +6 -0
- package/dist/cjs-types/cli/lib/deploy2.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/deployApi/evaluateSchema.d.ts +453 -0
- package/dist/cjs-types/cli/lib/deployApi/evaluateSchema.d.ts.map +1 -0
- package/dist/cjs-types/cli/lib/deployApi/finishPush.d.ts +1 -2
- package/dist/cjs-types/cli/lib/deployApi/finishPush.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/dev.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/generatedFunctionLogsApi.d.ts +2 -0
- package/dist/cjs-types/cli/lib/generatedFunctionLogsApi.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/localDeployment/run.d.ts +2 -0
- package/dist/cjs-types/cli/lib/localDeployment/run.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/localDeployment/upgrade.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/localDeployment/utils.d.ts +1 -0
- package/dist/cjs-types/cli/lib/localDeployment/utils.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/run.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/utils/utils.d.ts +5 -5
- package/dist/cjs-types/cli/lib/utils/utils.d.ts.map +1 -1
- package/dist/cjs-types/index.d.ts +1 -1
- package/dist/cjs-types/nextjs/index.d.ts +6 -6
- package/dist/cjs-types/nextjs/index.d.ts.map +1 -1
- package/dist/cjs-types/react/client.d.ts +15 -15
- package/dist/cjs-types/react/client.d.ts.map +1 -1
- package/dist/cjs-types/react/hydration.d.ts +3 -3
- package/dist/cjs-types/react/hydration.d.ts.map +1 -1
- package/dist/cjs-types/react/queries_observer.d.ts +9 -9
- package/dist/cjs-types/react/queries_observer.d.ts.map +1 -1
- package/dist/cjs-types/react/use_paginated_query2.d.ts.map +1 -1
- package/dist/cjs-types/react/use_queries.d.ts +14 -6
- package/dist/cjs-types/react/use_queries.d.ts.map +1 -1
- package/dist/cjs-types/server/api.d.ts +157 -7
- package/dist/cjs-types/server/api.d.ts.map +1 -1
- package/dist/cjs-types/server/components/index.d.ts +2 -2
- package/dist/cjs-types/server/components/index.d.ts.map +1 -1
- package/dist/cjs-types/server/cron.d.ts +21 -20
- package/dist/cjs-types/server/cron.d.ts.map +1 -1
- package/dist/cjs-types/server/impl/actions_impl.d.ts +4 -4
- package/dist/cjs-types/server/impl/actions_impl.d.ts.map +1 -1
- package/dist/cjs-types/server/impl/meta_impl.d.ts.map +1 -1
- package/dist/cjs-types/server/impl/scheduler_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.map +1 -1
- package/dist/cjs-types/server/registration.d.ts +7 -7
- package/dist/cjs-types/server/registration.d.ts.map +1 -1
- package/dist/cjs-types/server/scheduler.d.ts +9 -7
- package/dist/cjs-types/server/scheduler.d.ts.map +1 -1
- package/dist/cjs-types/server/schema.d.ts +1 -0
- package/dist/cjs-types/server/schema.d.ts.map +1 -1
- package/dist/cjs-types/values/validator.d.ts.map +1 -1
- package/dist/cjs-types/values/validators.d.ts +30 -0
- package/dist/cjs-types/values/validators.d.ts.map +1 -1
- package/dist/cli.bundle.cjs +347 -133
- package/dist/cli.bundle.cjs.map +4 -4
- package/dist/esm/browser/http_client.js.map +2 -2
- package/dist/esm/browser/query_options.js.map +2 -2
- package/dist/esm/browser/simple_client.js.map +2 -2
- package/dist/esm/browser/sync/optimistic_updates_impl.js.map +2 -2
- package/dist/esm/cli/codegen.js +2 -0
- package/dist/esm/cli/codegen.js.map +2 -2
- package/dist/esm/cli/deploy.js +1 -0
- package/dist/esm/cli/deploy.js.map +2 -2
- package/dist/esm/cli/docs.js +3 -43
- package/dist/esm/cli/docs.js.map +2 -2
- package/dist/esm/cli/lib/checkForLargeIndexDeletion.js +100 -60
- package/dist/esm/cli/lib/checkForLargeIndexDeletion.js.map +2 -2
- package/dist/esm/cli/lib/checkForSlowSchemaValidation.js +85 -0
- package/dist/esm/cli/lib/checkForSlowSchemaValidation.js.map +7 -0
- package/dist/esm/cli/lib/codegen.js.map +2 -2
- package/dist/esm/cli/lib/components.js +12 -0
- package/dist/esm/cli/lib/components.js.map +2 -2
- package/dist/esm/cli/lib/deploy2.js +30 -2
- package/dist/esm/cli/lib/deploy2.js.map +2 -2
- package/dist/esm/cli/lib/deployApi/evaluateSchema.js +46 -0
- package/dist/esm/cli/lib/deployApi/evaluateSchema.js.map +7 -0
- package/dist/esm/cli/lib/deployApi/finishPush.js +1 -1
- package/dist/esm/cli/lib/deployApi/finishPush.js.map +2 -2
- package/dist/esm/cli/lib/deployApi/startPush.js +1 -1
- package/dist/esm/cli/lib/deployApi/startPush.js.map +2 -2
- package/dist/esm/cli/lib/dev.js +1 -0
- package/dist/esm/cli/lib/dev.js.map +2 -2
- package/dist/esm/cli/lib/localDeployment/run.js +30 -2
- package/dist/esm/cli/lib/localDeployment/run.js.map +2 -2
- package/dist/esm/cli/lib/localDeployment/upgrade.js +4 -3
- package/dist/esm/cli/lib/localDeployment/upgrade.js.map +2 -2
- package/dist/esm/cli/lib/localDeployment/utils.js +3 -0
- package/dist/esm/cli/lib/localDeployment/utils.js.map +2 -2
- package/dist/esm/cli/lib/run.js +1 -0
- package/dist/esm/cli/lib/run.js.map +2 -2
- package/dist/esm/cli/lib/utils/utils.js +36 -30
- package/dist/esm/cli/lib/utils/utils.js.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/nextjs/index.js.map +2 -2
- package/dist/esm/react/client.js.map +2 -2
- package/dist/esm/react/hydration.js +3 -1
- package/dist/esm/react/hydration.js.map +2 -2
- package/dist/esm/react/queries_observer.js +3 -1
- package/dist/esm/react/queries_observer.js.map +2 -2
- package/dist/esm/react/use_paginated_query2.js +3 -1
- package/dist/esm/react/use_paginated_query2.js.map +2 -2
- package/dist/esm/react/use_queries.js.map +2 -2
- package/dist/esm/server/api.js.map +2 -2
- package/dist/esm/server/components/index.js.map +2 -2
- package/dist/esm/server/cron.js +13 -11
- package/dist/esm/server/cron.js.map +2 -2
- package/dist/esm/server/impl/actions_impl.js.map +2 -2
- package/dist/esm/server/impl/meta_impl.js +9 -3
- package/dist/esm/server/impl/meta_impl.js.map +2 -2
- package/dist/esm/server/impl/scheduler_impl.js.map +2 -2
- package/dist/esm/server/index.js.map +2 -2
- package/dist/esm/server/schema.js +50 -3
- package/dist/esm/server/schema.js.map +2 -2
- package/dist/esm/values/validator.js +1 -1
- package/dist/esm/values/validator.js.map +2 -2
- package/dist/esm/values/validators.js +81 -25
- package/dist/esm/values/validators.js.map +2 -2
- package/dist/esm-types/browser/http_client.d.ts +5 -5
- package/dist/esm-types/browser/http_client.d.ts.map +1 -1
- package/dist/esm-types/browser/query_options.d.ts +2 -2
- package/dist/esm-types/browser/query_options.d.ts.map +1 -1
- package/dist/esm-types/browser/simple_client.d.ts +6 -6
- package/dist/esm-types/browser/simple_client.d.ts.map +1 -1
- package/dist/esm-types/browser/sync/optimistic_updates.d.ts +4 -4
- package/dist/esm-types/browser/sync/optimistic_updates.d.ts.map +1 -1
- package/dist/esm-types/browser/sync/optimistic_updates_impl.d.ts.map +1 -1
- package/dist/esm-types/cli/codegen.d.ts.map +1 -1
- package/dist/esm-types/cli/docs.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/checkForLargeIndexDeletion.d.ts +26 -5
- package/dist/esm-types/cli/lib/checkForLargeIndexDeletion.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/checkForSlowSchemaValidation.d.ts +14 -0
- package/dist/esm-types/cli/lib/checkForSlowSchemaValidation.d.ts.map +1 -0
- package/dist/esm-types/cli/lib/codegen.d.ts +1 -0
- package/dist/esm-types/cli/lib/codegen.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/components.d.ts +1 -0
- package/dist/esm-types/cli/lib/components.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/deploy2.d.ts +6 -0
- package/dist/esm-types/cli/lib/deploy2.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/deployApi/evaluateSchema.d.ts +453 -0
- package/dist/esm-types/cli/lib/deployApi/evaluateSchema.d.ts.map +1 -0
- package/dist/esm-types/cli/lib/deployApi/finishPush.d.ts +1 -2
- package/dist/esm-types/cli/lib/deployApi/finishPush.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/dev.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/generatedFunctionLogsApi.d.ts +2 -0
- package/dist/esm-types/cli/lib/generatedFunctionLogsApi.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/localDeployment/run.d.ts +2 -0
- package/dist/esm-types/cli/lib/localDeployment/run.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/localDeployment/upgrade.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/localDeployment/utils.d.ts +1 -0
- package/dist/esm-types/cli/lib/localDeployment/utils.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/run.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/utils/utils.d.ts +5 -5
- package/dist/esm-types/cli/lib/utils/utils.d.ts.map +1 -1
- package/dist/esm-types/index.d.ts +1 -1
- package/dist/esm-types/nextjs/index.d.ts +6 -6
- package/dist/esm-types/nextjs/index.d.ts.map +1 -1
- package/dist/esm-types/react/client.d.ts +15 -15
- package/dist/esm-types/react/client.d.ts.map +1 -1
- package/dist/esm-types/react/hydration.d.ts +3 -3
- package/dist/esm-types/react/hydration.d.ts.map +1 -1
- package/dist/esm-types/react/queries_observer.d.ts +9 -9
- package/dist/esm-types/react/queries_observer.d.ts.map +1 -1
- package/dist/esm-types/react/use_paginated_query2.d.ts.map +1 -1
- package/dist/esm-types/react/use_queries.d.ts +14 -6
- package/dist/esm-types/react/use_queries.d.ts.map +1 -1
- package/dist/esm-types/server/api.d.ts +157 -7
- package/dist/esm-types/server/api.d.ts.map +1 -1
- package/dist/esm-types/server/components/index.d.ts +2 -2
- package/dist/esm-types/server/components/index.d.ts.map +1 -1
- package/dist/esm-types/server/cron.d.ts +21 -20
- package/dist/esm-types/server/cron.d.ts.map +1 -1
- package/dist/esm-types/server/impl/actions_impl.d.ts +4 -4
- package/dist/esm-types/server/impl/actions_impl.d.ts.map +1 -1
- package/dist/esm-types/server/impl/meta_impl.d.ts.map +1 -1
- package/dist/esm-types/server/impl/scheduler_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.map +1 -1
- package/dist/esm-types/server/registration.d.ts +7 -7
- package/dist/esm-types/server/registration.d.ts.map +1 -1
- package/dist/esm-types/server/scheduler.d.ts +9 -7
- package/dist/esm-types/server/scheduler.d.ts.map +1 -1
- package/dist/esm-types/server/schema.d.ts +1 -0
- package/dist/esm-types/server/schema.d.ts.map +1 -1
- package/dist/esm-types/values/validator.d.ts.map +1 -1
- package/dist/esm-types/values/validators.d.ts +30 -0
- package/dist/esm-types/values/validators.d.ts.map +1 -1
- package/dist/react.bundle.js +1 -1
- package/dist/react.bundle.js.map +2 -2
- package/package.json +5 -5
- package/src/browser/http_client.ts +43 -10
- package/src/browser/query_options.ts +11 -5
- package/src/browser/simple_client.ts +35 -14
- package/src/browser/sync/optimistic_updates.ts +17 -4
- package/src/browser/sync/optimistic_updates_impl.ts +17 -4
- package/src/cli/codegen.ts +1 -0
- package/src/cli/deploy.ts +1 -0
- package/src/cli/docs.ts +3 -44
- package/src/cli/lib/checkForLargeIndexDeletion.ts +154 -82
- package/src/cli/lib/checkForSlowSchemaValidation.ts +130 -0
- package/src/cli/lib/codegen.ts +1 -0
- package/src/cli/lib/components.ts +17 -0
- package/src/cli/lib/deploy2.ts +56 -1
- package/src/cli/lib/deployApi/evaluateSchema.ts +62 -0
- package/src/cli/lib/deployApi/finishPush.ts +1 -1
- package/src/cli/lib/deployApi/startPush.ts +1 -1
- package/src/cli/lib/dev.ts +1 -0
- package/src/cli/lib/generatedFunctionLogsApi.ts +2 -0
- package/src/cli/lib/localDeployment/run.ts +44 -2
- package/src/cli/lib/localDeployment/upgrade.ts +4 -6
- package/src/cli/lib/localDeployment/utils.ts +6 -0
- package/src/cli/lib/run.ts +1 -0
- package/src/cli/lib/utils/utils.ts +63 -35
- package/src/index.ts +1 -1
- package/src/nextjs/index.ts +19 -8
- package/src/react/client.ts +73 -30
- package/src/react/hydration.tsx +14 -6
- package/src/react/queries_observer.ts +19 -16
- package/src/react/use_paginated_query2.ts +10 -6
- package/src/react/use_queries.ts +23 -7
- package/src/server/api.ts +220 -14
- package/src/server/components/index.ts +4 -6
- package/src/server/cron.ts +34 -24
- package/src/server/impl/actions_impl.ts +13 -4
- package/src/server/impl/meta_impl.ts +8 -1
- package/src/server/impl/scheduler_impl.ts +13 -6
- package/src/server/index.ts +1 -0
- package/src/server/meta.ts +25 -0
- package/src/server/registration.ts +28 -7
- package/src/server/scheduler.ts +22 -7
- package/src/server/schema.ts +55 -0
- package/src/values/validator.ts +3 -1
- package/src/values/validators.ts +84 -26
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
import { convexToJson, Value } from "../values/index.js";
|
|
2
2
|
import { PaginatedWatch, Watch } from "./client.js";
|
|
3
3
|
import { QueryJournal } from "../browser/sync/protocol.js";
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
getFunctionName,
|
|
6
|
+
FunctionReference,
|
|
7
|
+
FunctionReference_future,
|
|
8
|
+
} from "../server/api.js";
|
|
6
9
|
import { PaginatedQueryResult } from "../browser/sync/pagination.js";
|
|
7
10
|
import { SubscribeToPaginatedQueryOptions } from "../browser/sync/paginated_query_client.js";
|
|
8
11
|
|
|
9
12
|
type Identifier = string;
|
|
10
13
|
|
|
14
|
+
type RequestForQueriesCompat = Record<
|
|
15
|
+
Identifier,
|
|
16
|
+
{
|
|
17
|
+
query: FunctionReference<"query"> | FunctionReference_future<"query">;
|
|
18
|
+
args: Record<string, Value>;
|
|
19
|
+
paginationOptions?: SubscribeToPaginatedQueryOptions;
|
|
20
|
+
}
|
|
21
|
+
>;
|
|
22
|
+
|
|
11
23
|
type QueryInfo = {
|
|
12
|
-
query: FunctionReference<"query">;
|
|
24
|
+
query: FunctionReference<"query"> | FunctionReference_future<"query">;
|
|
13
25
|
args: Record<string, Value>;
|
|
14
26
|
watch: Watch<Value> | PaginatedWatch<Value>;
|
|
15
27
|
unsubscribe: () => void;
|
|
@@ -18,7 +30,7 @@ type QueryInfo = {
|
|
|
18
30
|
|
|
19
31
|
export interface CreateWatch {
|
|
20
32
|
(
|
|
21
|
-
query: FunctionReference<"query">,
|
|
33
|
+
query: FunctionReference<"query"> | FunctionReference_future<"query">,
|
|
22
34
|
args: Record<string, Value>,
|
|
23
35
|
options: {
|
|
24
36
|
journal?: QueryJournal;
|
|
@@ -44,16 +56,7 @@ export class QueriesObserver {
|
|
|
44
56
|
this.listeners = new Set();
|
|
45
57
|
}
|
|
46
58
|
|
|
47
|
-
setQueries(
|
|
48
|
-
newQueries: Record<
|
|
49
|
-
Identifier,
|
|
50
|
-
{
|
|
51
|
-
query: FunctionReference<"query">;
|
|
52
|
-
args: Record<string, Value>;
|
|
53
|
-
paginationOptions?: SubscribeToPaginatedQueryOptions;
|
|
54
|
-
}
|
|
55
|
-
>,
|
|
56
|
-
) {
|
|
59
|
+
setQueries(newQueries: RequestForQueriesCompat) {
|
|
57
60
|
// Add the new queries before unsubscribing from the old ones so that
|
|
58
61
|
// the deduping in the `ConvexReactClient` can help if there are duplicates.
|
|
59
62
|
for (const identifier of Object.keys(newQueries)) {
|
|
@@ -107,7 +110,7 @@ export class QueriesObserver {
|
|
|
107
110
|
}
|
|
108
111
|
|
|
109
112
|
getLocalResults(
|
|
110
|
-
queries:
|
|
113
|
+
queries: RequestForQueriesCompat,
|
|
111
114
|
): Record<
|
|
112
115
|
Identifier,
|
|
113
116
|
Value | undefined | Error | PaginatedQueryResult<Value>
|
|
@@ -173,7 +176,7 @@ export class QueriesObserver {
|
|
|
173
176
|
|
|
174
177
|
private addQuery(
|
|
175
178
|
identifier: Identifier,
|
|
176
|
-
query: FunctionReference<"query">,
|
|
179
|
+
query: FunctionReference<"query"> | FunctionReference_future<"query">,
|
|
177
180
|
args: Record<string, Value>,
|
|
178
181
|
{
|
|
179
182
|
paginationOptions,
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
FunctionReference,
|
|
5
|
+
FunctionReturnType,
|
|
6
|
+
getFunctionName,
|
|
7
|
+
} from "../server/api.js";
|
|
4
8
|
import {
|
|
5
9
|
PaginatedQueryReference,
|
|
6
10
|
PaginatedQueryArgs,
|
|
@@ -255,7 +259,7 @@ export function usePaginatedQuery_experimental<
|
|
|
255
259
|
throw new Error("Why is it missing?");
|
|
256
260
|
}
|
|
257
261
|
const internalResult = {
|
|
258
|
-
results: [] as Query["
|
|
262
|
+
results: [] as FunctionReturnType<Query>["page"],
|
|
259
263
|
status: "LoadingFirstPage" as const,
|
|
260
264
|
isLoading: true as const,
|
|
261
265
|
loadMore: function skipNOP(_numItems: number) {
|
|
@@ -270,7 +274,7 @@ export function usePaginatedQuery_experimental<
|
|
|
270
274
|
return internalResult as unknown as UsePaginatedQueryReturnType<Query>;
|
|
271
275
|
}
|
|
272
276
|
const result = resultsObject.paginatedQuery as
|
|
273
|
-
| PaginatedQueryResult<Query["
|
|
277
|
+
| PaginatedQueryResult<FunctionReturnType<Query>["page"][number]>
|
|
274
278
|
| Error;
|
|
275
279
|
|
|
276
280
|
// TODO this is a weird mix of responsibilities:
|
|
@@ -279,7 +283,7 @@ export function usePaginatedQuery_experimental<
|
|
|
279
283
|
// It comes back to why we'd ever get undefined when asking about a query; have we not yet called subscribe for it?
|
|
280
284
|
if (result === undefined) {
|
|
281
285
|
const internalResult = {
|
|
282
|
-
results: [] as Query["
|
|
286
|
+
results: [] as FunctionReturnType<Query>["page"],
|
|
283
287
|
loadMore: () => false,
|
|
284
288
|
isLoading: true as const,
|
|
285
289
|
status: "LoadingFirstPage" as const,
|
|
@@ -313,7 +317,7 @@ export function usePaginatedQuery_experimental<
|
|
|
313
317
|
);
|
|
314
318
|
setState(createInitialState);
|
|
315
319
|
const internalResult = {
|
|
316
|
-
results: [] as Query["
|
|
320
|
+
results: [] as FunctionReturnType<Query>["page"],
|
|
317
321
|
loadMore: () => false,
|
|
318
322
|
isLoading: true as const,
|
|
319
323
|
status: "LoadingFirstPage" as const,
|
|
@@ -329,7 +333,7 @@ export function usePaginatedQuery_experimental<
|
|
|
329
333
|
throw result;
|
|
330
334
|
}
|
|
331
335
|
const internalResult = {
|
|
332
|
-
results: [] as Query["
|
|
336
|
+
results: [] as FunctionReturnType<Query>["page"],
|
|
333
337
|
loadMore: () => false,
|
|
334
338
|
isLoading: false as const,
|
|
335
339
|
status: "Error" as const,
|
package/src/react/use_queries.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { useConvex } from "./client.js";
|
|
|
4
4
|
import { CreateWatch, QueriesObserver } from "./queries_observer.js";
|
|
5
5
|
import { useSubscription } from "./use_subscription.js";
|
|
6
6
|
import { QueryJournal } from "../browser/index.js";
|
|
7
|
-
import { FunctionReference } from "../server/api.js";
|
|
7
|
+
import { FunctionReference, FunctionReference_future } from "../server/api.js";
|
|
8
8
|
import { SubscribeToPaginatedQueryOptions } from "../browser/sync/paginated_query_client.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -15,9 +15,10 @@ import { SubscribeToPaginatedQueryOptions } from "../browser/sync/paginated_quer
|
|
|
15
15
|
* of queries without violating the rules of React hooks.
|
|
16
16
|
*
|
|
17
17
|
* This hook accepts an object whose keys are identifiers for each query and the
|
|
18
|
-
* values are objects of
|
|
19
|
-
* `query
|
|
20
|
-
* the
|
|
18
|
+
* values are objects of
|
|
19
|
+
* `{ query: FunctionReference | FunctionReference_future, args: Record<string, Value> }`.
|
|
20
|
+
* The `query` is a reference to the Convex query function to load, and the
|
|
21
|
+
* `args` are the arguments to that function.
|
|
21
22
|
*
|
|
22
23
|
* The hook returns an object that maps each identifier to the result of the query,
|
|
23
24
|
* `undefined` if the query is still loading, or an instance of `Error` if the query
|
|
@@ -59,7 +60,7 @@ import { SubscribeToPaginatedQueryOptions } from "../browser/sync/paginated_quer
|
|
|
59
60
|
* @public
|
|
60
61
|
*/
|
|
61
62
|
export function useQueries(
|
|
62
|
-
queries:
|
|
63
|
+
queries: RequestForQueriesCompat,
|
|
63
64
|
): Record<string, any | undefined | Error> {
|
|
64
65
|
const convex = useConvex();
|
|
65
66
|
if (convex === undefined) {
|
|
@@ -73,7 +74,7 @@ export function useQueries(
|
|
|
73
74
|
}
|
|
74
75
|
const createWatch = useMemo(() => {
|
|
75
76
|
return (
|
|
76
|
-
query: FunctionReference<"query">,
|
|
77
|
+
query: FunctionReference<"query"> | FunctionReference_future<"query">,
|
|
77
78
|
args: Record<string, Value>,
|
|
78
79
|
{
|
|
79
80
|
journal,
|
|
@@ -97,7 +98,7 @@ export function useQueries(
|
|
|
97
98
|
* Internal version of `useQueries` that is exported for testing.
|
|
98
99
|
*/
|
|
99
100
|
export function useQueriesHelper(
|
|
100
|
-
queries:
|
|
101
|
+
queries: RequestForQueriesCompat,
|
|
101
102
|
createWatch: CreateWatch,
|
|
102
103
|
): Record<string, any | undefined | Error> {
|
|
103
104
|
const [observer] = useState(() => new QueriesObserver(createWatch));
|
|
@@ -143,3 +144,18 @@ export type RequestForQueries = Record<
|
|
|
143
144
|
paginationOptions?: SubscribeToPaginatedQueryOptions;
|
|
144
145
|
}
|
|
145
146
|
>;
|
|
147
|
+
|
|
148
|
+
// The `queries` parameter of `useQueries`: `RequestForQueries` with `query`
|
|
149
|
+
// also accepting a `FunctionReference_future`. The exported type stays a plain
|
|
150
|
+
// reference so that code reading a `query` out of one gets a
|
|
151
|
+
// `FunctionReference` it can forward anywhere. Module-local so that a
|
|
152
|
+
// consumer's declaration file inlines it rather than importing it from a path
|
|
153
|
+
// outside the package's public entry points.
|
|
154
|
+
type RequestForQueriesCompat = Record<
|
|
155
|
+
string,
|
|
156
|
+
{
|
|
157
|
+
query: FunctionReference<"query"> | FunctionReference_future<"query">;
|
|
158
|
+
args: Record<string, Value>;
|
|
159
|
+
paginationOptions?: SubscribeToPaginatedQueryOptions;
|
|
160
|
+
}
|
|
161
|
+
>;
|
package/src/server/api.ts
CHANGED
|
@@ -42,6 +42,9 @@ export type FunctionType = "query" | "mutation" | "action";
|
|
|
42
42
|
* const result = useQuery(api.myModule.myFunction);
|
|
43
43
|
* ```
|
|
44
44
|
*
|
|
45
|
+
* If you want to accept a `FunctionReference` as a callback argument, prefer
|
|
46
|
+
* typing the callback parameter as {@link FunctionReference_future}.
|
|
47
|
+
*
|
|
45
48
|
* @typeParam Type - The type of the function ("query", "mutation", or "action").
|
|
46
49
|
* @typeParam Visibility - The visibility of the function ("public" or "internal").
|
|
47
50
|
* @typeParam Args - The arguments to this function. This is an object mapping
|
|
@@ -58,9 +61,179 @@ export type FunctionReference<
|
|
|
58
61
|
> = {
|
|
59
62
|
_type: Type;
|
|
60
63
|
_visibility: Visibility;
|
|
64
|
+
/**
|
|
65
|
+
* To read the arguments for a `FunctionReference`, prefer
|
|
66
|
+
* {@link FunctionArgs}.
|
|
67
|
+
*
|
|
68
|
+
* This slot will be removed in a future version.
|
|
69
|
+
*
|
|
70
|
+
* @deprecated
|
|
71
|
+
*/
|
|
61
72
|
_args: Args;
|
|
73
|
+
/**
|
|
74
|
+
* To read the return type of a `FunctionReference`, prefer
|
|
75
|
+
* {@link FunctionReturnType}.
|
|
76
|
+
*
|
|
77
|
+
* This slot will be removed in a future version.
|
|
78
|
+
*
|
|
79
|
+
* @deprecated
|
|
80
|
+
*/
|
|
62
81
|
_returnType: ReturnType;
|
|
63
82
|
_componentPath: ComponentPath;
|
|
83
|
+
/**
|
|
84
|
+
* To read the arguments or return type of a `FunctionReference`, prefer
|
|
85
|
+
* {@link FunctionArgs} and {@link FunctionReturnType}.
|
|
86
|
+
*/
|
|
87
|
+
// This phantom slot exists so that a `FunctionReference` can be checked
|
|
88
|
+
// against a `FunctionReference_future`. It changes nothing about how two
|
|
89
|
+
// `FunctionReference`s compare with each other.
|
|
90
|
+
//
|
|
91
|
+
// The slot models the function itself: it puts `Args` in a contravariant
|
|
92
|
+
// position and `ReturnType` in a covariant one, so the slot alone is enough
|
|
93
|
+
// to compare a reference the way TypeScript compares two functions.
|
|
94
|
+
//
|
|
95
|
+
// In that comparison the `keys` parameter has an important role. It carries
|
|
96
|
+
// the keys of `Args`, so that checking a `FunctionReference` against a
|
|
97
|
+
// `FunctionReference_future` also checks that every key the consumer passes
|
|
98
|
+
// is a key the function declares. TypeScript treats a surplus property as
|
|
99
|
+
// harmless, but a Convex argument validator rejects it, so this is what
|
|
100
|
+
// makes the comparison match the runtime. See `FunctionReferenceArgKeys`.
|
|
101
|
+
_fn?(args: Args, keys: FunctionReferenceArgKeys<Args>): ReturnType;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The keys of a reference's arguments.
|
|
106
|
+
*
|
|
107
|
+
* `0 extends 1 & Args` holds only when `Args` is `any`. That maps to `any`
|
|
108
|
+
* rather than `keyof any` so that an untyped reference neither imposes nor
|
|
109
|
+
* fails the key check in either direction. Arguments with an index signature,
|
|
110
|
+
* such as `EmptyObject` and `DefaultFunctionArgs`, map to `string`, which
|
|
111
|
+
* accepts every key and leaves the decision to the first parameter.
|
|
112
|
+
*/
|
|
113
|
+
type ArgKeys<Args> = 0 extends 1 & Args ? any : keyof Args;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The second parameter of `FunctionReference._fn`.
|
|
117
|
+
*
|
|
118
|
+
* Wrapping the keys in a function of a function puts them two parameters deep,
|
|
119
|
+
* so comparing this parameter contravariantly checks that every key the
|
|
120
|
+
* consumer passes is one the function declares. That is the check a Convex
|
|
121
|
+
* argument validator performs and an ordinary function-type comparison skips.
|
|
122
|
+
*
|
|
123
|
+
* The union with {@link UncheckedArgKeys} is what keeps two
|
|
124
|
+
* `FunctionReference`s comparing as they did before this slot existed. Every
|
|
125
|
+
* `FunctionReferenceArgKeys` is assignable to `UncheckedArgKeys`, so between
|
|
126
|
+
* two `FunctionReference`s the keys always relate and only `_args` decides.
|
|
127
|
+
* {@link FunctionReference_futureArgKeys} is not assignable to it, so a
|
|
128
|
+
* `FunctionReference` compared against a `FunctionReference_future` has to
|
|
129
|
+
* satisfy the real check.
|
|
130
|
+
*/
|
|
131
|
+
type FunctionReferenceArgKeys<Args> = 0 extends 1 & Args
|
|
132
|
+
? any
|
|
133
|
+
: ((keys: (key: ArgKeys<Args>) => void) => void) | UncheckedArgKeys;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* A keys parameter that every {@link FunctionReferenceArgKeys} is assignable
|
|
137
|
+
* to, and that no {@link FunctionReference_futureArgKeys} is: `unknown` for
|
|
138
|
+
* the second parameter accepts the former's missing parameter and rejects the
|
|
139
|
+
* latter's `never`.
|
|
140
|
+
*/
|
|
141
|
+
type UncheckedArgKeys = (keys: never, unchecked?: unknown) => void;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* The second parameter of `FunctionReference_future._fn`. The same shape as
|
|
145
|
+
* {@link FunctionReferenceArgKeys} plus a `guard` parameter that keeps it out
|
|
146
|
+
* of {@link UncheckedArgKeys}.
|
|
147
|
+
*/
|
|
148
|
+
type FunctionReference_futureArgKeys<Args> = 0 extends 1 & Args
|
|
149
|
+
? any
|
|
150
|
+
: (keys: (key: ArgKeys<Args>) => void, guard?: never) => void;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* A reference to a Convex function whose arguments are checked closer to the
|
|
154
|
+
* way Convex checks them at runtime.
|
|
155
|
+
*
|
|
156
|
+
* Use this instead of {@link FunctionReference} when you accept someone else's
|
|
157
|
+
* Convex function as a callback and know which arguments you will pass it.
|
|
158
|
+
*
|
|
159
|
+
* A plain `FunctionReference` gets a couple things backwards: it accepts a
|
|
160
|
+
* function requiring arguments you never pass, and rejects a function
|
|
161
|
+
* accepting broader values than you pass. An ordinary TypeScript function type
|
|
162
|
+
* doesn't map perfectly either: it treats a surplus argument as harmless,
|
|
163
|
+
* where a Convex validator rejects it.
|
|
164
|
+
*
|
|
165
|
+
* This type melds regular TypeScript function reference behavior with top
|
|
166
|
+
* level checking of arguments to prevent surplus arguments from hitting
|
|
167
|
+
* runtime validation errors. The caveat: a surplus key inside a nested object,
|
|
168
|
+
* an array element, or one arm of a union passes the type check and fails the
|
|
169
|
+
* validator at runtime.
|
|
170
|
+
*
|
|
171
|
+
* ```ts
|
|
172
|
+
* import { FunctionReference_future } from "convex/server";
|
|
173
|
+
*
|
|
174
|
+
* declare function onComplete(
|
|
175
|
+
* fn: FunctionReference_future<
|
|
176
|
+
* "mutation",
|
|
177
|
+
* "internal",
|
|
178
|
+
* { taskId: string; force: boolean },
|
|
179
|
+
* null
|
|
180
|
+
* >,
|
|
181
|
+
* ): void;
|
|
182
|
+
*
|
|
183
|
+
* // Takes exactly `{ taskId: string; force: boolean }`.
|
|
184
|
+
* onComplete(internal.tasks.finish);
|
|
185
|
+
* // Takes `{ taskId: string | number; force?: boolean }`: calling it is safe.
|
|
186
|
+
* onComplete(internal.tasks.finishLoosely);
|
|
187
|
+
* // Requires a `reason` argument that `onComplete` never passes.
|
|
188
|
+
* onComplete(internal.tasks.finishWithReason);
|
|
189
|
+
* // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ rejected
|
|
190
|
+
* // Takes only `{ taskId: string }`: its validator would reject `force`.
|
|
191
|
+
* onComplete(internal.tasks.finishById);
|
|
192
|
+
* // ~~~~~~~~~~~~~~~~~~~~~~~~ rejected
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* A value of this type is usable with `ctx.runMutation`,
|
|
196
|
+
* `ctx.scheduler.runAfter`, `createFunctionHandle`, and everything else in
|
|
197
|
+
* this package that takes a reference, all of which accept either kind.
|
|
198
|
+
*
|
|
199
|
+
* It is *not* assignable to a plain `FunctionReference`. Code that wants to
|
|
200
|
+
* accept both kinds should take
|
|
201
|
+
* `FunctionReference<...> | FunctionReference_future<...>` and read arguments
|
|
202
|
+
* and return types through {@link FunctionArgs} and {@link FunctionReturnType}.
|
|
203
|
+
*
|
|
204
|
+
* Argument checking here relies on `strictFunctionTypes` (implied by `strict`)
|
|
205
|
+
* and is skipped for projects that disable it. Everything else about the
|
|
206
|
+
* reference is compared exactly as `FunctionReference` compares it.
|
|
207
|
+
*
|
|
208
|
+
* @typeParam Type - The type of the function ("query", "mutation", or "action").
|
|
209
|
+
* @typeParam Visibility - The visibility of the function ("public" or "internal").
|
|
210
|
+
* @typeParam Args - The arguments the consumer of the reference will pass.
|
|
211
|
+
* @typeParam ReturnType - The return type of this function.
|
|
212
|
+
* @public
|
|
213
|
+
*/
|
|
214
|
+
export type FunctionReference_future<
|
|
215
|
+
Type extends FunctionType,
|
|
216
|
+
Visibility extends FunctionVisibility = "public",
|
|
217
|
+
Args extends DefaultFunctionArgs = any,
|
|
218
|
+
ReturnType = any,
|
|
219
|
+
ComponentPath = string | undefined,
|
|
220
|
+
> = {
|
|
221
|
+
_type: Type;
|
|
222
|
+
_visibility: Visibility;
|
|
223
|
+
_componentPath: ComponentPath;
|
|
224
|
+
// Declared as a *property* rather than a method: TypeScript compares method
|
|
225
|
+
// parameters bivariantly and would not check anything. The explicit
|
|
226
|
+
// `| undefined` is needed because an optional method on the source side
|
|
227
|
+
// (`FunctionReference._fn`) carries a real `undefined` in its type, which
|
|
228
|
+
// `exactOptionalPropertyTypes` would otherwise reject.
|
|
229
|
+
//
|
|
230
|
+
// Both parameters are compared contravariantly: the first checks that the
|
|
231
|
+
// consumer's arguments satisfy the function's, the second that the consumer
|
|
232
|
+
// passes no key the function does not declare. See
|
|
233
|
+
// `FunctionReference_futureArgKeys`.
|
|
234
|
+
_fn?:
|
|
235
|
+
| ((args: Args, keys: FunctionReference_futureArgKeys<Args>) => ReturnType)
|
|
236
|
+
| undefined;
|
|
64
237
|
};
|
|
65
238
|
|
|
66
239
|
/**
|
|
@@ -76,7 +249,9 @@ export type FunctionReference<
|
|
|
76
249
|
* @public
|
|
77
250
|
*/
|
|
78
251
|
export function getFunctionName(
|
|
79
|
-
functionReference:
|
|
252
|
+
functionReference:
|
|
253
|
+
| FunctionReference<any, any>
|
|
254
|
+
| FunctionReference_future<any, any>,
|
|
80
255
|
): string {
|
|
81
256
|
const address = getFunctionAddress(functionReference);
|
|
82
257
|
|
|
@@ -431,13 +606,33 @@ export type PartialApi<API> = {
|
|
|
431
606
|
export const anyApi: AnyApi = createApi() as any;
|
|
432
607
|
|
|
433
608
|
/**
|
|
434
|
-
* Given a {@link FunctionReference}
|
|
609
|
+
* Given a {@link FunctionReference} or {@link FunctionReference_future}, get
|
|
610
|
+
* the arguments of the function.
|
|
435
611
|
*
|
|
436
612
|
* This is represented as an object mapping argument names to values.
|
|
613
|
+
*
|
|
437
614
|
* @public
|
|
438
615
|
*/
|
|
439
|
-
export type FunctionArgs<
|
|
440
|
-
FuncRef
|
|
616
|
+
export type FunctionArgs<
|
|
617
|
+
FuncRef extends
|
|
618
|
+
| FunctionReference<any, any>
|
|
619
|
+
| FunctionReference_future<any, any>,
|
|
620
|
+
> = ExtractSignature<FuncRef>["args"];
|
|
621
|
+
|
|
622
|
+
// The arguments and return type a reference declares. A `FunctionReference`
|
|
623
|
+
// declares them in `_args` and `_returnType`, a `FunctionReference_future`
|
|
624
|
+
// only in its `_fn` slot. Reading the named slots first also covers a
|
|
625
|
+
// reference typed by an older copy of this package, which has no `_fn`.
|
|
626
|
+
type ExtractSignature<FuncRef> = FuncRef extends {
|
|
627
|
+
_args: infer Args;
|
|
628
|
+
_returnType: infer R;
|
|
629
|
+
}
|
|
630
|
+
? { args: Args; returnType: R }
|
|
631
|
+
: FuncRef extends {
|
|
632
|
+
_fn?: ((args: infer Args, keys: never) => infer R) | undefined;
|
|
633
|
+
}
|
|
634
|
+
? { args: Args; returnType: R }
|
|
635
|
+
: { args: any; returnType: any };
|
|
441
636
|
|
|
442
637
|
/**
|
|
443
638
|
* A tuple type of the (maybe optional) arguments to `FuncRef`.
|
|
@@ -447,10 +642,14 @@ export type FunctionArgs<FuncRef extends AnyFunctionReference> =
|
|
|
447
642
|
*
|
|
448
643
|
* @public
|
|
449
644
|
*/
|
|
450
|
-
export type OptionalRestArgs<
|
|
451
|
-
FuncRef
|
|
645
|
+
export type OptionalRestArgs<
|
|
646
|
+
FuncRef extends
|
|
647
|
+
| FunctionReference<any, any>
|
|
648
|
+
| FunctionReference_future<any, any>,
|
|
649
|
+
> =
|
|
650
|
+
FunctionArgs<FuncRef> extends EmptyObject
|
|
452
651
|
? [args?: EmptyObject]
|
|
453
|
-
: [args: FuncRef
|
|
652
|
+
: [args: FunctionArgs<FuncRef>];
|
|
454
653
|
|
|
455
654
|
/**
|
|
456
655
|
* A tuple type of the (maybe optional) arguments to `FuncRef`, followed by an options
|
|
@@ -462,19 +661,26 @@ export type OptionalRestArgs<FuncRef extends AnyFunctionReference> =
|
|
|
462
661
|
* @public
|
|
463
662
|
*/
|
|
464
663
|
export type ArgsAndOptions<
|
|
465
|
-
FuncRef extends
|
|
664
|
+
FuncRef extends
|
|
665
|
+
| FunctionReference<any, any>
|
|
666
|
+
| FunctionReference_future<any, any>,
|
|
466
667
|
Options,
|
|
467
|
-
> =
|
|
468
|
-
|
|
469
|
-
|
|
668
|
+
> =
|
|
669
|
+
FunctionArgs<FuncRef> extends EmptyObject
|
|
670
|
+
? [args?: EmptyObject, options?: Options]
|
|
671
|
+
: [args: FunctionArgs<FuncRef>, options?: Options];
|
|
470
672
|
|
|
471
673
|
/**
|
|
472
|
-
* Given a {@link FunctionReference}
|
|
674
|
+
* Given a {@link FunctionReference} or {@link FunctionReference_future}, get
|
|
675
|
+
* the return type of the function.
|
|
473
676
|
*
|
|
474
677
|
* @public
|
|
475
678
|
*/
|
|
476
|
-
export type FunctionReturnType<
|
|
477
|
-
FuncRef
|
|
679
|
+
export type FunctionReturnType<
|
|
680
|
+
FuncRef extends
|
|
681
|
+
| FunctionReference<any, any>
|
|
682
|
+
| FunctionReference_future<any, any>,
|
|
683
|
+
> = ExtractSignature<FuncRef>["returnType"];
|
|
478
684
|
|
|
479
685
|
type UndefinedToNull<T> = T extends void ? null : T;
|
|
480
686
|
|
|
@@ -3,6 +3,7 @@ import { version } from "../../index.js";
|
|
|
3
3
|
import {
|
|
4
4
|
AnyFunctionReference,
|
|
5
5
|
FunctionReference,
|
|
6
|
+
FunctionReference_future,
|
|
6
7
|
FunctionType,
|
|
7
8
|
} from "../api.js";
|
|
8
9
|
import { performAsyncSyscall } from "../impl/syscall.js";
|
|
@@ -66,12 +67,9 @@ export async function createFunctionHandle<
|
|
|
66
67
|
Args extends DefaultFunctionArgs,
|
|
67
68
|
ReturnType,
|
|
68
69
|
>(
|
|
69
|
-
functionReference:
|
|
70
|
-
Type,
|
|
71
|
-
"public" | "internal",
|
|
72
|
-
Args,
|
|
73
|
-
ReturnType
|
|
74
|
-
>,
|
|
70
|
+
functionReference:
|
|
71
|
+
| FunctionReference<Type, "public" | "internal", Args, ReturnType>
|
|
72
|
+
| FunctionReference_future<Type, "public" | "internal", Args, ReturnType>,
|
|
75
73
|
): Promise<FunctionHandle<Type, Args, ReturnType>> {
|
|
76
74
|
const address = getFunctionAddress(functionReference);
|
|
77
75
|
return await performAsyncSyscall("1.0/createFunctionHandle", {
|
package/src/server/cron.ts
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
FunctionReference_future,
|
|
3
|
+
getFunctionName,
|
|
4
|
+
OptionalRestArgs,
|
|
5
|
+
} from "../server/api.js";
|
|
2
6
|
import { parseArgs } from "../common/index.js";
|
|
3
7
|
import { convexToJson, JSONValue, Value } from "../values/index.js";
|
|
4
8
|
import { getFunctionAddress } from "./components/paths.js";
|
|
5
9
|
import { SchedulableFunctionReference } from "./scheduler.js";
|
|
6
10
|
|
|
11
|
+
// Mirrors the constraint on `Scheduler.runAfter` and `Scheduler.runAt`, which
|
|
12
|
+
// is module-local to `scheduler.ts`.
|
|
13
|
+
type SchedulableFunctionReferenceCompat =
|
|
14
|
+
| SchedulableFunctionReference
|
|
15
|
+
| FunctionReference_future<"mutation" | "action", "public" | "internal">;
|
|
16
|
+
|
|
7
17
|
type CronSchedule = {
|
|
8
18
|
type: "cron";
|
|
9
19
|
cron: string;
|
|
@@ -238,8 +248,8 @@ function validatedOptionalMinuteOfHour(n: number | undefined) {
|
|
|
238
248
|
// call shapes apart by whether the second argument resolves to a function
|
|
239
249
|
// reference (the way the scheduler syscalls do) rather than a schedule object.
|
|
240
250
|
function isSchedulableFunctionReference(
|
|
241
|
-
arg: Hourly |
|
|
242
|
-
): arg is
|
|
251
|
+
arg: Hourly | SchedulableFunctionReferenceCompat,
|
|
252
|
+
): arg is SchedulableFunctionReferenceCompat {
|
|
243
253
|
try {
|
|
244
254
|
getFunctionAddress(arg);
|
|
245
255
|
return true;
|
|
@@ -280,7 +290,7 @@ export class Crons {
|
|
|
280
290
|
schedule(
|
|
281
291
|
cronIdentifier: string,
|
|
282
292
|
schedule: Schedule,
|
|
283
|
-
functionReference:
|
|
293
|
+
functionReference: SchedulableFunctionReferenceCompat,
|
|
284
294
|
args?: Record<string, Value>,
|
|
285
295
|
) {
|
|
286
296
|
const cronArgs = parseArgs(args);
|
|
@@ -304,11 +314,11 @@ export class Crons {
|
|
|
304
314
|
*
|
|
305
315
|
* @param identifier - A unique name for this scheduled job.
|
|
306
316
|
* @param schedule - The time between runs for this scheduled job.
|
|
307
|
-
* @param functionReference - A {@link FunctionReference}
|
|
308
|
-
* to schedule.
|
|
317
|
+
* @param functionReference - A {@link FunctionReference} or
|
|
318
|
+
* {@link FunctionReference_future} for the function to schedule.
|
|
309
319
|
* @param args - The arguments to the function.
|
|
310
320
|
*/
|
|
311
|
-
interval<FuncRef extends
|
|
321
|
+
interval<FuncRef extends SchedulableFunctionReferenceCompat>(
|
|
312
322
|
cronIdentifier: string,
|
|
313
323
|
schedule: Interval,
|
|
314
324
|
functionReference: FuncRef,
|
|
@@ -353,22 +363,22 @@ export class Crons {
|
|
|
353
363
|
* @param cronIdentifier - A unique name for this scheduled job.
|
|
354
364
|
* @param schedule - What minute (UTC) of each hour to run this function. May
|
|
355
365
|
* be omitted to let Convex pick a minute and spread runs across the hour.
|
|
356
|
-
* @param functionReference - A {@link FunctionReference}
|
|
357
|
-
* to schedule.
|
|
366
|
+
* @param functionReference - A {@link FunctionReference} or
|
|
367
|
+
* {@link FunctionReference_future} for the function to schedule.
|
|
358
368
|
* @param args - The arguments to the function.
|
|
359
369
|
*/
|
|
360
|
-
hourly<FuncRef extends
|
|
370
|
+
hourly<FuncRef extends SchedulableFunctionReferenceCompat>(
|
|
361
371
|
cronIdentifier: string,
|
|
362
372
|
functionReference: FuncRef,
|
|
363
373
|
...args: OptionalRestArgs<FuncRef>
|
|
364
374
|
): void;
|
|
365
|
-
hourly<FuncRef extends
|
|
375
|
+
hourly<FuncRef extends SchedulableFunctionReferenceCompat>(
|
|
366
376
|
cronIdentifier: string,
|
|
367
377
|
schedule: Hourly,
|
|
368
378
|
functionReference: FuncRef,
|
|
369
379
|
...args: OptionalRestArgs<FuncRef>
|
|
370
380
|
): void;
|
|
371
|
-
hourly<FuncRef extends
|
|
381
|
+
hourly<FuncRef extends SchedulableFunctionReferenceCompat>(
|
|
372
382
|
cronIdentifier: string,
|
|
373
383
|
scheduleOrFunctionReference: Hourly | FuncRef,
|
|
374
384
|
functionReferenceOrArg?: FuncRef | Record<string, Value>,
|
|
@@ -414,11 +424,11 @@ export class Crons {
|
|
|
414
424
|
*
|
|
415
425
|
* @param cronIdentifier - A unique name for this scheduled job.
|
|
416
426
|
* @param schedule - What time (UTC) each day to run this function.
|
|
417
|
-
* @param functionReference - A {@link FunctionReference}
|
|
418
|
-
* to schedule.
|
|
427
|
+
* @param functionReference - A {@link FunctionReference} or
|
|
428
|
+
* {@link FunctionReference_future} for the function to schedule.
|
|
419
429
|
* @param args - The arguments to the function.
|
|
420
430
|
*/
|
|
421
|
-
daily<FuncRef extends
|
|
431
|
+
daily<FuncRef extends SchedulableFunctionReferenceCompat>(
|
|
422
432
|
cronIdentifier: string,
|
|
423
433
|
schedule: Daily,
|
|
424
434
|
functionReference: FuncRef,
|
|
@@ -453,10 +463,10 @@ export class Crons {
|
|
|
453
463
|
*
|
|
454
464
|
* @param cronIdentifier - A unique name for this scheduled job.
|
|
455
465
|
* @param schedule - What day and time (UTC) each week to run this function.
|
|
456
|
-
* @param functionReference - A {@link FunctionReference}
|
|
457
|
-
* to schedule.
|
|
466
|
+
* @param functionReference - A {@link FunctionReference} or
|
|
467
|
+
* {@link FunctionReference_future} for the function to schedule.
|
|
458
468
|
*/
|
|
459
|
-
weekly<FuncRef extends
|
|
469
|
+
weekly<FuncRef extends SchedulableFunctionReferenceCompat>(
|
|
460
470
|
cronIdentifier: string,
|
|
461
471
|
schedule: Weekly,
|
|
462
472
|
functionReference: FuncRef,
|
|
@@ -495,11 +505,11 @@ export class Crons {
|
|
|
495
505
|
*
|
|
496
506
|
* @param cronIdentifier - A unique name for this scheduled job.
|
|
497
507
|
* @param schedule - What day and time (UTC) each month to run this function.
|
|
498
|
-
* @param functionReference - A {@link FunctionReference}
|
|
499
|
-
* to schedule.
|
|
508
|
+
* @param functionReference - A {@link FunctionReference} or
|
|
509
|
+
* {@link FunctionReference_future} for the function to schedule.
|
|
500
510
|
* @param args - The arguments to the function.
|
|
501
511
|
*/
|
|
502
|
-
monthly<FuncRef extends
|
|
512
|
+
monthly<FuncRef extends SchedulableFunctionReferenceCompat>(
|
|
503
513
|
cronIdentifier: string,
|
|
504
514
|
schedule: Monthly,
|
|
505
515
|
functionReference: FuncRef,
|
|
@@ -534,11 +544,11 @@ export class Crons {
|
|
|
534
544
|
*
|
|
535
545
|
* @param cronIdentifier - A unique name for this scheduled job.
|
|
536
546
|
* @param cron - Cron string like `"15 7 * * *"` (Every day at 7:15 UTC)
|
|
537
|
-
* @param functionReference - A {@link FunctionReference}
|
|
538
|
-
* to schedule.
|
|
547
|
+
* @param functionReference - A {@link FunctionReference} or
|
|
548
|
+
* {@link FunctionReference_future} for the function to schedule.
|
|
539
549
|
* @param args - The arguments to the function.
|
|
540
550
|
*/
|
|
541
|
-
cron<FuncRef extends
|
|
551
|
+
cron<FuncRef extends SchedulableFunctionReferenceCompat>(
|
|
542
552
|
cronIdentifier: string,
|
|
543
553
|
cron: CronString,
|
|
544
554
|
functionReference: FuncRef,
|