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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/server/components/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { PropertyValidators } from \"../../values/index.js\";\nimport { version } from \"../../index.js\";\nimport {\n AnyFunctionReference,\n FunctionReference,\n FunctionType,\n} from \"../api.js\";\nimport { performAsyncSyscall } from \"../impl/syscall.js\";\nimport { DefaultFunctionArgs } from \"../registration.js\";\nimport {\n AppDefinitionAnalysis,\n ComponentDefinitionAnalysis,\n ComponentDefinitionType,\n} from \"./definition.js\";\nimport {\n getFunctionAddress,\n setReferencePath,\n toReferencePath,\n} from \"./paths.js\";\nimport type {\n Validator,\n VLiteral,\n VOptional,\n VString,\n VUnion,\n} from \"../../values/validators.js\";\nimport type { Infer } from \"../../values/validator.js\";\nimport { isValidator } from \"../../values/validator.js\";\nimport type { Expand } from \"../../type_utils.js\";\nexport { getFunctionAddress } from \"./paths.js\";\n\n/**\n * A serializable reference to a Convex function.\n * Passing a this reference to another component allows that component to call this\n * function during the current function execution or at any later time.\n * Function handles are used like `api.folder.function` FunctionReferences,\n * e.g. `ctx.scheduler.runAfter(0, functionReference, args)`.\n *\n * A function reference is stable across code pushes but it's possible\n * the Convex function it refers to might no longer exist.\n *\n * This is a feature of components, which are in beta.\n * This API is unstable and may change in subsequent releases.\n */\nexport type FunctionHandle<\n Type extends FunctionType,\n Args extends DefaultFunctionArgs = any,\n ReturnType = any,\n> = string & FunctionReference<Type, \"internal\", Args, ReturnType>;\n\n/**\n * Create a serializable reference to a Convex function.\n * Passing a this reference to another component allows that component to call this\n * function during the current function execution or at any later time.\n * Function handles are used like `api.folder.function` FunctionReferences,\n * e.g. `ctx.scheduler.runAfter(0, functionReference, args)`.\n *\n * A function reference is stable across code pushes but it's possible\n * the Convex function it refers to might no longer exist.\n *\n * This is a feature of components, which are in beta.\n * This API is unstable and may change in subsequent releases.\n */\nexport async function createFunctionHandle<\n Type extends FunctionType,\n Args extends DefaultFunctionArgs,\n ReturnType,\n>(\n functionReference: FunctionReference<\n Type,\n \"public\" | \"internal\",\n Args,\n ReturnType\n >,\n): Promise<FunctionHandle<Type, Args, ReturnType>> {\n const address = getFunctionAddress(functionReference);\n return await performAsyncSyscall(\"1.0/createFunctionHandle\", {\n ...address,\n version,\n });\n}\n\ninterface ComponentExports {\n [key: string]: FunctionReference<any, any, any, any> | ComponentExports;\n}\n\n/**\n * An object of this type should be the default export of a\n * convex.config.ts file in a component definition directory.\n *\n * This is a feature of components, which are in beta.\n * This API is unstable and may change in subsequent releases.\n */\nexport type ComponentDefinition<\n Exports extends ComponentExports = any,\n Env extends EnvDefinition = {},\n> = {\n /**\n * Install a component with the given definition in this component definition.\n *\n * Takes a component definition and an optional name.\n *\n * For editor tooling this method expects a {@link ComponentDefinition}\n * but at runtime the object that is imported will be a {@link ImportedComponentDefinition}\n */\n use<Definition extends ComponentDefinition<any, any>>(\n definition: Definition,\n ...args: UseArgs<Definition>\n ): InstalledComponent<Definition>;\n\n /**\n * Internal type-only property tracking exports provided.\n *\n * @deprecated This is a type-only property, don't use it.\n */\n __exports: Exports;\n\n /**\n * References to this component's declared env vars. Pass one of these in\n * `app.use(child, { env: { ... } })` to bind a child's env var by\n * reference to this component's env var.\n */\n env: EnvRefFromDefinition<Env>;\n\n /**\n * Internal type-only property tracking env definition.\n *\n * @deprecated This is a type-only property, don't use it.\n */\n __env: Env;\n};\n\ntype ComponentDefinitionExports<T extends ComponentDefinition<any, any>> =\n T[\"__exports\"];\n\ntype ComponentDefinitionEnv<T extends ComponentDefinition<any, any>> =\n T[\"__env\"];\n\n/**\n * The names in an {@link EnvDefinition} whose validators are required (not\n * wrapped in `v.optional(...)`).\n */\ntype RequiredEnvKeys<E extends EnvDefinition> = {\n [K in keyof E]: E[K] extends Validator<any, \"optional\", any> ? never : K;\n}[keyof E];\n\n/**\n * Options for installing a component via `app.use()` or `component.use()`.\n *\n * If the component declares any required env vars, the `env` property is\n * required. Otherwise it is optional, so that a component with no env vars (or\n * only optional ones) can be installed without passing `env`.\n */\ntype UseOptions<Definition extends ComponentDefinition<any, any>> =\n RequiredEnvKeys<ComponentDefinitionEnv<Definition>> extends never\n ? {\n name?: string;\n httpPrefix?: string;\n env?: UseOptionsEnv<ComponentDefinitionEnv<Definition>>;\n }\n : {\n name?: string;\n httpPrefix?: string;\n env: UseOptionsEnv<ComponentDefinitionEnv<Definition>>;\n };\n\n/**\n * The arguments to `use()` after the component definition.\n *\n * When the component declares required env vars the `options` argument is\n * mandatory (so it can't be dropped to skip the required `env`); otherwise it\n * is optional.\n */\ntype UseArgs<Definition extends ComponentDefinition<any, any>> =\n RequiredEnvKeys<ComponentDefinitionEnv<Definition>> extends never\n ? [options?: UseOptions<Definition>]\n : [options: UseOptions<Definition>];\n\ntype UseOptionsEnv<E extends EnvDefinition> = Expand<\n {\n [K in keyof E as E[K] extends Validator<any, \"optional\", any> ? never : K]:\n | Infer<E[K]>\n | EnvRef;\n } & {\n [K in keyof E as E[K] extends Validator<any, \"optional\", any>\n ? K\n : never]?: Infer<E[K]> | EnvRef | undefined;\n }\n>;\n\n/**\n * A string-like validator: `v.string()`, a string `v.literal(\"...\")`, or a\n * `v.union(...)` of those (recursively). Component env vars are serialized\n * as strings on the wire, so only string-typed validators are allowed.\n *\n * @public\n */\nexport type StringLikeValidator =\n | VString<string, \"required\">\n | VLiteral<string, \"required\">\n | VUnion<string, Validator<any, \"required\", any>[], \"required\">;\n\n/**\n * A definition of environment variables for the app.\n *\n * Maps environment variable names to string-like validators. Use\n * `v.string()` for a plain string, `v.literal(\"a\")` for an enum value, or\n * `v.union(v.literal(\"a\"), v.literal(\"b\"))` for an enum. Wrap in\n * `v.optional(...)` for optional vars.\n *\n * @example\n * ```typescript\n * import { defineApp } from \"convex/server\";\n * import { v } from \"convex/values\";\n *\n * const app = defineApp({\n * env: {\n * OPENAI_API_KEY: v.string(),\n * DEBUG_MODE: v.optional(v.string()),\n * },\n * });\n * ```\n *\n * @public\n */\nexport type EnvDefinition = Record<\n string,\n StringLikeValidator | VOptional<StringLikeValidator>\n>;\n\n/**\n * Compute the typed environment object from an {@link EnvDefinition}.\n *\n * Required entries get the validator's inferred string type; optional\n * entries are `T | undefined`.\n *\n * @public\n */\nexport type EnvFromDefinition<E extends EnvDefinition> = Expand<\n {\n [K in keyof E as E[K] extends Validator<any, \"optional\", any>\n ? never\n : K]: Infer<E[K]>;\n } & {\n [K in keyof E as E[K] extends Validator<any, \"optional\", any>\n ? K\n : never]?: Infer<E[K]> | undefined;\n }\n>;\n\n/**\n * A reference to a parent-declared env var, produced by `app.env.<NAME>` or\n * `component.env.<NAME>`. Pass this in `use(child, { env: { ... } })` to\n * bind a child's declared env var to the parent's env var by reference\n * instead of snapshotting its current value.\n *\n * @public\n */\nexport type EnvRef<K extends string = string> = { __envVarRef: K };\n\n/**\n * Compute the typed `env` namespace object from an {@link EnvDefinition}.\n * Each declared name maps to an {@link EnvRef} for that name.\n *\n * @public\n */\nexport type EnvRefFromDefinition<E extends EnvDefinition> = {\n [K in keyof E & string]: EnvRef<K>;\n};\n\n/**\n * Extract the typed environment from an {@link AppDefinition}.\n *\n * @public\n */\nexport type EnvFromAppDefinition<A> =\n A extends AppDefinition<infer E>\n ? EnvFromDefinition<E>\n : Record<string, never>;\n\n/**\n * An object of this type should be the default export of a\n * convex.config.ts file in a component-aware convex directory.\n *\n * This is a feature of components, which are in beta.\n * This API is unstable and may change in subsequent releases.\n */\nexport type AppDefinition<Env extends EnvDefinition = EnvDefinition> = {\n /**\n * Install a component with the given definition in this component definition.\n *\n * Takes a component definition and an optional name.\n *\n * For editor tooling this method expects a {@link ComponentDefinition}\n * but at runtime the object that is imported will be a {@link ImportedComponentDefinition}\n */\n use<Definition extends ComponentDefinition<any, any>>(\n definition: Definition,\n ...args: UseArgs<Definition>\n ): InstalledComponent<Definition>;\n\n /**\n * References to this app's declared env vars. Pass one of these in\n * `app.use(child, { env: { ... } })` to bind a child's env var by\n * reference to this app's env var.\n */\n env: EnvRefFromDefinition<Env>;\n\n /**\n * Internal type-only property tracking env definition.\n *\n * @deprecated This is a type-only property, don't use it.\n */\n __env: Env;\n};\n\ninterface ExportTree {\n // Tree with serialized `Reference`s as leaves.\n [key: string]: string | ExportTree;\n}\n\ntype CommonDefinitionData = {\n _isRoot: boolean;\n _childComponents: [\n string,\n ImportedComponentDefinition,\n Record<string, any> | null,\n string | undefined,\n ][];\n _exportTree: ExportTree;\n};\n\ntype ComponentDefinitionData = CommonDefinitionData & {\n _env: PropertyValidators;\n _name: string;\n _onInitCallbacks: Record<string, (argsStr: string) => string>;\n};\ntype AppDefinitionData = CommonDefinitionData & {\n _httpPrefix?: string;\n _env?: EnvDefinition;\n};\n\n/**\n * Used to refer to an already-installed component.\n */\nclass InstalledComponent<Definition extends ComponentDefinition<any, any>> {\n /**\n * @internal\n */\n _definition: Definition;\n\n /**\n * @internal\n */\n _name: string;\n\n constructor(definition: Definition, name: string) {\n this._definition = definition;\n this._name = name;\n setReferencePath(this, `_reference/childComponent/${name}`);\n }\n\n get exports(): ComponentDefinitionExports<Definition> {\n return createExports(this._name, []);\n }\n}\n\nfunction createExports(name: string, pathParts: string[]): any {\n const handler: ProxyHandler<any> = {\n get(_, prop: string | symbol) {\n if (typeof prop === \"string\") {\n const newParts = [...pathParts, prop];\n return createExports(name, newParts);\n } else if (prop === toReferencePath) {\n let reference = `_reference/childComponent/${name}`;\n for (const part of pathParts) {\n reference += `/${part}`;\n }\n return reference;\n } else {\n return undefined;\n }\n },\n };\n return new Proxy({}, handler);\n}\n\nfunction createEnvRefs(\n ownerLabel: string,\n declared: Record<string, any> | undefined,\n): any {\n const handler: ProxyHandler<any> = {\n get(_, prop: string | symbol) {\n if (typeof prop !== \"string\") {\n return undefined;\n }\n if (!declared || !Object.prototype.hasOwnProperty.call(declared, prop)) {\n throw new Error(\n `Env var \"${prop}\" is not declared on ${ownerLabel}. Add it to the \\`env\\` option of ${ownerLabel === \"this app\" ? \"defineApp\" : \"defineComponent\"}.`,\n );\n }\n return { __envVarRef: prop };\n },\n };\n return new Proxy({}, handler);\n}\n\nfunction isEnvRef(value: unknown): value is EnvRef {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as EnvRef).__envVarRef === \"string\"\n );\n}\n\nfunction use<Definition extends ComponentDefinition<any, any>>(\n this: CommonDefinitionData,\n definition: Definition,\n options?: {\n name?: string;\n httpPrefix?: string;\n env?: Record<string, any>;\n },\n): InstalledComponent<Definition> {\n // At runtime an imported component will have this shape.\n const importedComponentDefinition =\n definition as unknown as ImportedComponentDefinition;\n if (typeof importedComponentDefinition.componentDefinitionPath !== \"string\") {\n throw new Error(\n \"Component definition does not have the required componentDefinitionPath property. This code only works in Convex runtime.\",\n );\n }\n const name =\n options?.name ??\n // added recently\n importedComponentDefinition.defaultName ??\n // can be removed once backend is out\n importedComponentDefinition.componentDefinitionPath.split(\"/\").pop()!;\n\n if (typeof name !== \"string\") {\n throw new Error(\n `Component name must be a string. Received: ${typeof name}`,\n );\n }\n if (name.length === 0) {\n // \"\" is used internally as the name for the root component, so\n // users shouldn't try to define child components with an empty name.\n throw new Error(\"Component name cannot be empty.\");\n }\n\n const httpPrefix = options?.httpPrefix;\n if (httpPrefix !== undefined) {\n if (!httpPrefix.startsWith(\"/\")) {\n throw new Error(\n `httpPrefix must start with \"/\". Received: \"${httpPrefix}\"`,\n );\n }\n }\n\n const envValues: Record<string, any> = {};\n if (options?.env) {\n for (const [key, value] of Object.entries(options.env)) {\n if (value !== undefined) {\n envValues[key] = value;\n }\n }\n }\n\n this._childComponents.push([\n name,\n importedComponentDefinition,\n envValues,\n httpPrefix,\n ]);\n return new InstalledComponent(definition, name);\n}\n\n/**\n * The runtime type of a ComponentDefinition. TypeScript will claim\n * the default export of a module like \"cool-component/convex.config.js\"\n * is a `@link ComponentDefinition}, but during component definition evaluation\n * this is its type instead.\n *\n * This is a feature of components, which are in beta.\n * This API is unstable and may change in subsequent releases.\n */\nexport type ImportedComponentDefinition = {\n componentDefinitionPath: string;\n defaultName: string;\n};\n\nfunction exportAppForAnalysis(\n this: ComponentDefinition<any, any> & AppDefinitionData,\n): AppDefinitionAnalysis {\n const definitionType = { type: \"app\" as const };\n const childComponents = serializeChildComponents(this._childComponents);\n const httpMounts = buildHttpMounts(this._childComponents);\n const envVars = this._env\n ? Object.entries(this._env).map(\n ([name, validator]) =>\n [\n name,\n {\n type: \"value\" as const,\n value: JSON.stringify(validator.json),\n ...(validator.isOptional === \"optional\"\n ? { optional: true }\n : {}),\n },\n ] as [string, { type: \"value\"; value: string; optional?: boolean }],\n )\n : undefined;\n return {\n definitionType,\n ...(this._httpPrefix !== undefined\n ? { httpPrefix: normalizeHttpPrefix(this._httpPrefix) }\n : {}),\n childComponents: childComponents as any,\n httpMounts,\n exports: serializeExportTree(this._exportTree),\n ...(envVars !== undefined ? { envVars } : {}),\n };\n}\n\nfunction serializeExportTree(tree: ExportTree): any {\n const branch: any[] = [];\n for (const [key, child] of Object.entries(tree)) {\n let node;\n if (typeof child === \"string\") {\n node = { type: \"leaf\", leaf: child };\n } else {\n node = serializeExportTree(child);\n }\n branch.push([key, node]);\n }\n return { type: \"branch\", branch };\n}\n\nfunction normalizeHttpPrefix(prefix: string): string {\n // Ensure the prefix ends with \"/\" as required by HttpMountPath in Rust.\n return prefix.endsWith(\"/\") ? prefix : prefix + \"/\";\n}\n\nfunction buildHttpMounts(\n childComponents: [\n string,\n ImportedComponentDefinition,\n Record<string, any> | null,\n string | undefined,\n ][],\n): Record<string, string> {\n const httpMounts: Record<string, string> = {};\n for (const [name, , , httpPrefix] of childComponents) {\n if (httpPrefix !== undefined) {\n const normalized = normalizeHttpPrefix(httpPrefix);\n httpMounts[normalized] = `_reference/childComponent/${name}`;\n }\n }\n return httpMounts;\n}\n\ntype SerializedEnvArg =\n | { type: \"value\"; value: string }\n | { type: \"envVar\"; name: string };\n\nfunction serializeChildComponents(\n childComponents: [\n string,\n ImportedComponentDefinition,\n Record<string, any> | null,\n string | undefined,\n ][],\n): {\n name: string;\n path: string;\n env: [string, SerializedEnvArg][] | null;\n}[] {\n return childComponents.map(([name, definition, p]) => {\n // Note: httpPrefix (4th element) is used separately in buildHttpMounts()\n let env: [string, SerializedEnvArg][] | null = null;\n if (p !== null) {\n env = [];\n for (const [name, value] of Object.entries(p)) {\n if (value === undefined) {\n continue;\n }\n if (isEnvRef(value)) {\n env.push([name, { type: \"envVar\", name: value.__envVarRef }]);\n } else if (typeof value === \"string\") {\n env.push([name, { type: \"value\", value }]);\n } else {\n throw new Error(\n `Env var \"${name}\" must be a string or an env var reference. ` +\n `Received: ${typeof value}`,\n );\n }\n }\n }\n // we know that components carry this extra information\n const path = definition.componentDefinitionPath;\n if (!path)\n throw new Error(\n \"no .componentPath for component definition \" +\n JSON.stringify(definition, null, 2),\n );\n\n return {\n name: name!,\n path: path!,\n args: [],\n env,\n };\n });\n}\n\nfunction exportComponentForAnalysis(\n this: ComponentDefinition<any, any> & ComponentDefinitionData,\n): ComponentDefinitionAnalysis {\n const envVars = Object.entries(this._env).map(\n ([name, validator]) =>\n [\n name,\n {\n type: \"value\" as const,\n value: JSON.stringify((validator as any).json),\n ...((validator as any).isOptional === \"optional\"\n ? { optional: true }\n : {}),\n },\n ] as [string, { type: \"value\"; value: string; optional?: boolean }],\n );\n const definitionType: ComponentDefinitionType = {\n type: \"childComponent\" as const,\n name: this._name,\n args: [],\n };\n const childComponents = serializeChildComponents(this._childComponents);\n const httpMounts = buildHttpMounts(this._childComponents);\n return {\n name: this._name,\n definitionType,\n childComponents: childComponents as any,\n httpMounts,\n exports: serializeExportTree(this._exportTree),\n ...(envVars.length > 0 ? { envVars } : {}),\n };\n}\n\n// This is what is actually contained in a ComponentDefinition.\ntype RuntimeComponentDefinition = Omit<\n ComponentDefinition<any, any>,\n \"__exports\" | \"__env\"\n> &\n ComponentDefinitionData & {\n export: () => ComponentDefinitionAnalysis;\n };\ntype RuntimeAppDefinition = Omit<AppDefinition<any>, \"__env\"> &\n AppDefinitionData & {\n export: () => AppDefinitionAnalysis;\n };\n\n/**\n * Define a component, a piece of a Convex deployment with namespaced resources.\n *\n * Optionally define typed environment variables that will be available via\n * the `env` export from `_generated/server` in all Convex functions within\n * this component. Values are passed by the parent via\n * `app.use(component, { env: { ... } })`.\n *\n * @param name Name must be alphanumeric plus underscores. Typically these are\n * lowercase with underscores like `\"onboarding_flow_tracker\"`.\n *\n * This is a feature of components, which are in beta.\n * This API is unstable and may change in subsequent releases.\n */\nexport function defineComponent<\n Exports extends ComponentExports = any,\n const Env extends EnvDefinition = {},\n>(\n name: string,\n options?: {\n env?: Env;\n },\n): ComponentDefinition<Exports, Env> {\n const envValidators: PropertyValidators = {};\n if (options?.env) {\n for (const [key, decl] of Object.entries(options.env)) {\n if (decl !== null && decl !== undefined && isValidator(decl)) {\n envValidators[key] = decl as any;\n } else {\n throw new Error(\n `Environment variable \"${key}\" must be defined with a validator (e.g. v.string()).`,\n );\n }\n }\n }\n\n const ret: RuntimeComponentDefinition = {\n _isRoot: false,\n _name: name,\n _env: envValidators,\n _childComponents: [],\n _exportTree: {},\n _onInitCallbacks: {},\n\n env: createEnvRefs(`component \"${name}\"`, options?.env),\n\n export: exportComponentForAnalysis,\n use,\n\n ...({} as { __exports: any; __env: any }),\n };\n return ret as any as ComponentDefinition<Exports, Env>;\n}\n\n/**\n * Attach components, reuseable pieces of a Convex deployment, to this Convex app.\n *\n * Optionally define typed environment variables that will be available via\n * the `env` export from `_generated/server` in all Convex functions.\n *\n * @example\n * ```typescript\n * import { defineApp } from \"convex/server\";\n * import { v } from \"convex/values\";\n *\n * const app = defineApp({\n * env: {\n * OPENAI_API_KEY: v.string(),\n * DEBUG_MODE: v.optional(v.string()),\n * },\n * });\n * export default app;\n * ```\n *\n * This is a feature of components, which are in beta.\n * This API is unstable and may change in subsequent releases.\n */\nexport function defineApp<Env extends EnvDefinition = EnvDefinition>(options?: {\n httpPrefix?: string;\n env?: Env;\n}): AppDefinition<Env> {\n const httpPrefix = options?.httpPrefix;\n if (httpPrefix !== undefined && !httpPrefix.startsWith(\"/\")) {\n throw new Error(\n `httpPrefix must start with \"/\". Received: \"${httpPrefix}\"`,\n );\n }\n const env = options?.env;\n if (env !== undefined) {\n for (const [name, validator] of Object.entries(env)) {\n if (!isValidator(validator)) {\n throw new Error(\n `Environment variable \"${name}\" must be defined with a validator (e.g. v.string()).`,\n );\n }\n }\n }\n const ret: RuntimeAppDefinition = {\n _isRoot: true,\n _childComponents: [],\n _exportTree: {},\n ...(httpPrefix !== undefined ? { _httpPrefix: httpPrefix } : {}),\n ...(env !== undefined ? { _env: env } : {}),\n\n env: createEnvRefs(\"this app\", env),\n\n export: exportAppForAnalysis,\n use,\n };\n return ret as unknown as AppDefinition<Env>;\n}\n\ntype AnyInterfaceType = {\n [key: string]: AnyInterfaceType;\n} & AnyFunctionReference;\nexport type AnyComponentReference = Record<string, AnyInterfaceType>;\n\nexport type AnyChildComponents = Record<string, AnyComponentReference>;\n\n/**\n * @internal\n */\nexport function currentSystemUdfInComponent(\n componentId: string,\n): AnyComponentReference {\n return {\n [toReferencePath]: `_reference/currentSystemUdfInComponent/${componentId}`,\n };\n}\n\nfunction createChildComponents(\n root: string,\n pathParts: string[],\n): AnyChildComponents {\n const handler: ProxyHandler<object> = {\n get(_, prop: string | symbol) {\n if (typeof prop === \"string\") {\n const newParts = [...pathParts, prop];\n return createChildComponents(root, newParts);\n } else if (prop === toReferencePath) {\n if (pathParts.length < 1) {\n const found = [root, ...pathParts].join(\".\");\n throw new Error(\n `API path is expected to be of the form \\`${root}.childComponent.functionName\\`. Found: \\`${found}\\``,\n );\n }\n return `_reference/childComponent/` + pathParts.join(\"/\");\n } else {\n return undefined;\n }\n },\n };\n return new Proxy({}, handler);\n}\n\nexport const componentsGeneric = () => createChildComponents(\"components\", []);\n\nexport type AnyComponents = AnyChildComponents;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,eAAwB;
|
|
4
|
+
"sourcesContent": ["import { PropertyValidators } from \"../../values/index.js\";\nimport { version } from \"../../index.js\";\nimport {\n AnyFunctionReference,\n FunctionReference,\n FunctionReference_future,\n FunctionType,\n} from \"../api.js\";\nimport { performAsyncSyscall } from \"../impl/syscall.js\";\nimport { DefaultFunctionArgs } from \"../registration.js\";\nimport {\n AppDefinitionAnalysis,\n ComponentDefinitionAnalysis,\n ComponentDefinitionType,\n} from \"./definition.js\";\nimport {\n getFunctionAddress,\n setReferencePath,\n toReferencePath,\n} from \"./paths.js\";\nimport type {\n Validator,\n VLiteral,\n VOptional,\n VString,\n VUnion,\n} from \"../../values/validators.js\";\nimport type { Infer } from \"../../values/validator.js\";\nimport { isValidator } from \"../../values/validator.js\";\nimport type { Expand } from \"../../type_utils.js\";\nexport { getFunctionAddress } from \"./paths.js\";\n\n/**\n * A serializable reference to a Convex function.\n * Passing a this reference to another component allows that component to call this\n * function during the current function execution or at any later time.\n * Function handles are used like `api.folder.function` FunctionReferences,\n * e.g. `ctx.scheduler.runAfter(0, functionReference, args)`.\n *\n * A function reference is stable across code pushes but it's possible\n * the Convex function it refers to might no longer exist.\n *\n * This is a feature of components, which are in beta.\n * This API is unstable and may change in subsequent releases.\n */\nexport type FunctionHandle<\n Type extends FunctionType,\n Args extends DefaultFunctionArgs = any,\n ReturnType = any,\n> = string & FunctionReference<Type, \"internal\", Args, ReturnType>;\n\n/**\n * Create a serializable reference to a Convex function.\n * Passing a this reference to another component allows that component to call this\n * function during the current function execution or at any later time.\n * Function handles are used like `api.folder.function` FunctionReferences,\n * e.g. `ctx.scheduler.runAfter(0, functionReference, args)`.\n *\n * A function reference is stable across code pushes but it's possible\n * the Convex function it refers to might no longer exist.\n *\n * This is a feature of components, which are in beta.\n * This API is unstable and may change in subsequent releases.\n */\nexport async function createFunctionHandle<\n Type extends FunctionType,\n Args extends DefaultFunctionArgs,\n ReturnType,\n>(\n functionReference:\n | FunctionReference<Type, \"public\" | \"internal\", Args, ReturnType>\n | FunctionReference_future<Type, \"public\" | \"internal\", Args, ReturnType>,\n): Promise<FunctionHandle<Type, Args, ReturnType>> {\n const address = getFunctionAddress(functionReference);\n return await performAsyncSyscall(\"1.0/createFunctionHandle\", {\n ...address,\n version,\n });\n}\n\ninterface ComponentExports {\n [key: string]: FunctionReference<any, any, any, any> | ComponentExports;\n}\n\n/**\n * An object of this type should be the default export of a\n * convex.config.ts file in a component definition directory.\n *\n * This is a feature of components, which are in beta.\n * This API is unstable and may change in subsequent releases.\n */\nexport type ComponentDefinition<\n Exports extends ComponentExports = any,\n Env extends EnvDefinition = {},\n> = {\n /**\n * Install a component with the given definition in this component definition.\n *\n * Takes a component definition and an optional name.\n *\n * For editor tooling this method expects a {@link ComponentDefinition}\n * but at runtime the object that is imported will be a {@link ImportedComponentDefinition}\n */\n use<Definition extends ComponentDefinition<any, any>>(\n definition: Definition,\n ...args: UseArgs<Definition>\n ): InstalledComponent<Definition>;\n\n /**\n * Internal type-only property tracking exports provided.\n *\n * @deprecated This is a type-only property, don't use it.\n */\n __exports: Exports;\n\n /**\n * References to this component's declared env vars. Pass one of these in\n * `app.use(child, { env: { ... } })` to bind a child's env var by\n * reference to this component's env var.\n */\n env: EnvRefFromDefinition<Env>;\n\n /**\n * Internal type-only property tracking env definition.\n *\n * @deprecated This is a type-only property, don't use it.\n */\n __env: Env;\n};\n\ntype ComponentDefinitionExports<T extends ComponentDefinition<any, any>> =\n T[\"__exports\"];\n\ntype ComponentDefinitionEnv<T extends ComponentDefinition<any, any>> =\n T[\"__env\"];\n\n/**\n * The names in an {@link EnvDefinition} whose validators are required (not\n * wrapped in `v.optional(...)`).\n */\ntype RequiredEnvKeys<E extends EnvDefinition> = {\n [K in keyof E]: E[K] extends Validator<any, \"optional\", any> ? never : K;\n}[keyof E];\n\n/**\n * Options for installing a component via `app.use()` or `component.use()`.\n *\n * If the component declares any required env vars, the `env` property is\n * required. Otherwise it is optional, so that a component with no env vars (or\n * only optional ones) can be installed without passing `env`.\n */\ntype UseOptions<Definition extends ComponentDefinition<any, any>> =\n RequiredEnvKeys<ComponentDefinitionEnv<Definition>> extends never\n ? {\n name?: string;\n httpPrefix?: string;\n env?: UseOptionsEnv<ComponentDefinitionEnv<Definition>>;\n }\n : {\n name?: string;\n httpPrefix?: string;\n env: UseOptionsEnv<ComponentDefinitionEnv<Definition>>;\n };\n\n/**\n * The arguments to `use()` after the component definition.\n *\n * When the component declares required env vars the `options` argument is\n * mandatory (so it can't be dropped to skip the required `env`); otherwise it\n * is optional.\n */\ntype UseArgs<Definition extends ComponentDefinition<any, any>> =\n RequiredEnvKeys<ComponentDefinitionEnv<Definition>> extends never\n ? [options?: UseOptions<Definition>]\n : [options: UseOptions<Definition>];\n\ntype UseOptionsEnv<E extends EnvDefinition> = Expand<\n {\n [K in keyof E as E[K] extends Validator<any, \"optional\", any> ? never : K]:\n | Infer<E[K]>\n | EnvRef;\n } & {\n [K in keyof E as E[K] extends Validator<any, \"optional\", any>\n ? K\n : never]?: Infer<E[K]> | EnvRef | undefined;\n }\n>;\n\n/**\n * A string-like validator: `v.string()`, a string `v.literal(\"...\")`, or a\n * `v.union(...)` of those (recursively). Component env vars are serialized\n * as strings on the wire, so only string-typed validators are allowed.\n *\n * @public\n */\nexport type StringLikeValidator =\n | VString<string, \"required\">\n | VLiteral<string, \"required\">\n | VUnion<string, Validator<any, \"required\", any>[], \"required\">;\n\n/**\n * A definition of environment variables for the app.\n *\n * Maps environment variable names to string-like validators. Use\n * `v.string()` for a plain string, `v.literal(\"a\")` for an enum value, or\n * `v.union(v.literal(\"a\"), v.literal(\"b\"))` for an enum. Wrap in\n * `v.optional(...)` for optional vars.\n *\n * @example\n * ```typescript\n * import { defineApp } from \"convex/server\";\n * import { v } from \"convex/values\";\n *\n * const app = defineApp({\n * env: {\n * OPENAI_API_KEY: v.string(),\n * DEBUG_MODE: v.optional(v.string()),\n * },\n * });\n * ```\n *\n * @public\n */\nexport type EnvDefinition = Record<\n string,\n StringLikeValidator | VOptional<StringLikeValidator>\n>;\n\n/**\n * Compute the typed environment object from an {@link EnvDefinition}.\n *\n * Required entries get the validator's inferred string type; optional\n * entries are `T | undefined`.\n *\n * @public\n */\nexport type EnvFromDefinition<E extends EnvDefinition> = Expand<\n {\n [K in keyof E as E[K] extends Validator<any, \"optional\", any>\n ? never\n : K]: Infer<E[K]>;\n } & {\n [K in keyof E as E[K] extends Validator<any, \"optional\", any>\n ? K\n : never]?: Infer<E[K]> | undefined;\n }\n>;\n\n/**\n * A reference to a parent-declared env var, produced by `app.env.<NAME>` or\n * `component.env.<NAME>`. Pass this in `use(child, { env: { ... } })` to\n * bind a child's declared env var to the parent's env var by reference\n * instead of snapshotting its current value.\n *\n * @public\n */\nexport type EnvRef<K extends string = string> = { __envVarRef: K };\n\n/**\n * Compute the typed `env` namespace object from an {@link EnvDefinition}.\n * Each declared name maps to an {@link EnvRef} for that name.\n *\n * @public\n */\nexport type EnvRefFromDefinition<E extends EnvDefinition> = {\n [K in keyof E & string]: EnvRef<K>;\n};\n\n/**\n * Extract the typed environment from an {@link AppDefinition}.\n *\n * @public\n */\nexport type EnvFromAppDefinition<A> =\n A extends AppDefinition<infer E>\n ? EnvFromDefinition<E>\n : Record<string, never>;\n\n/**\n * An object of this type should be the default export of a\n * convex.config.ts file in a component-aware convex directory.\n *\n * This is a feature of components, which are in beta.\n * This API is unstable and may change in subsequent releases.\n */\nexport type AppDefinition<Env extends EnvDefinition = EnvDefinition> = {\n /**\n * Install a component with the given definition in this component definition.\n *\n * Takes a component definition and an optional name.\n *\n * For editor tooling this method expects a {@link ComponentDefinition}\n * but at runtime the object that is imported will be a {@link ImportedComponentDefinition}\n */\n use<Definition extends ComponentDefinition<any, any>>(\n definition: Definition,\n ...args: UseArgs<Definition>\n ): InstalledComponent<Definition>;\n\n /**\n * References to this app's declared env vars. Pass one of these in\n * `app.use(child, { env: { ... } })` to bind a child's env var by\n * reference to this app's env var.\n */\n env: EnvRefFromDefinition<Env>;\n\n /**\n * Internal type-only property tracking env definition.\n *\n * @deprecated This is a type-only property, don't use it.\n */\n __env: Env;\n};\n\ninterface ExportTree {\n // Tree with serialized `Reference`s as leaves.\n [key: string]: string | ExportTree;\n}\n\ntype CommonDefinitionData = {\n _isRoot: boolean;\n _childComponents: [\n string,\n ImportedComponentDefinition,\n Record<string, any> | null,\n string | undefined,\n ][];\n _exportTree: ExportTree;\n};\n\ntype ComponentDefinitionData = CommonDefinitionData & {\n _env: PropertyValidators;\n _name: string;\n _onInitCallbacks: Record<string, (argsStr: string) => string>;\n};\ntype AppDefinitionData = CommonDefinitionData & {\n _httpPrefix?: string;\n _env?: EnvDefinition;\n};\n\n/**\n * Used to refer to an already-installed component.\n */\nclass InstalledComponent<Definition extends ComponentDefinition<any, any>> {\n /**\n * @internal\n */\n _definition: Definition;\n\n /**\n * @internal\n */\n _name: string;\n\n constructor(definition: Definition, name: string) {\n this._definition = definition;\n this._name = name;\n setReferencePath(this, `_reference/childComponent/${name}`);\n }\n\n get exports(): ComponentDefinitionExports<Definition> {\n return createExports(this._name, []);\n }\n}\n\nfunction createExports(name: string, pathParts: string[]): any {\n const handler: ProxyHandler<any> = {\n get(_, prop: string | symbol) {\n if (typeof prop === \"string\") {\n const newParts = [...pathParts, prop];\n return createExports(name, newParts);\n } else if (prop === toReferencePath) {\n let reference = `_reference/childComponent/${name}`;\n for (const part of pathParts) {\n reference += `/${part}`;\n }\n return reference;\n } else {\n return undefined;\n }\n },\n };\n return new Proxy({}, handler);\n}\n\nfunction createEnvRefs(\n ownerLabel: string,\n declared: Record<string, any> | undefined,\n): any {\n const handler: ProxyHandler<any> = {\n get(_, prop: string | symbol) {\n if (typeof prop !== \"string\") {\n return undefined;\n }\n if (!declared || !Object.prototype.hasOwnProperty.call(declared, prop)) {\n throw new Error(\n `Env var \"${prop}\" is not declared on ${ownerLabel}. Add it to the \\`env\\` option of ${ownerLabel === \"this app\" ? \"defineApp\" : \"defineComponent\"}.`,\n );\n }\n return { __envVarRef: prop };\n },\n };\n return new Proxy({}, handler);\n}\n\nfunction isEnvRef(value: unknown): value is EnvRef {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as EnvRef).__envVarRef === \"string\"\n );\n}\n\nfunction use<Definition extends ComponentDefinition<any, any>>(\n this: CommonDefinitionData,\n definition: Definition,\n options?: {\n name?: string;\n httpPrefix?: string;\n env?: Record<string, any>;\n },\n): InstalledComponent<Definition> {\n // At runtime an imported component will have this shape.\n const importedComponentDefinition =\n definition as unknown as ImportedComponentDefinition;\n if (typeof importedComponentDefinition.componentDefinitionPath !== \"string\") {\n throw new Error(\n \"Component definition does not have the required componentDefinitionPath property. This code only works in Convex runtime.\",\n );\n }\n const name =\n options?.name ??\n // added recently\n importedComponentDefinition.defaultName ??\n // can be removed once backend is out\n importedComponentDefinition.componentDefinitionPath.split(\"/\").pop()!;\n\n if (typeof name !== \"string\") {\n throw new Error(\n `Component name must be a string. Received: ${typeof name}`,\n );\n }\n if (name.length === 0) {\n // \"\" is used internally as the name for the root component, so\n // users shouldn't try to define child components with an empty name.\n throw new Error(\"Component name cannot be empty.\");\n }\n\n const httpPrefix = options?.httpPrefix;\n if (httpPrefix !== undefined) {\n if (!httpPrefix.startsWith(\"/\")) {\n throw new Error(\n `httpPrefix must start with \"/\". Received: \"${httpPrefix}\"`,\n );\n }\n }\n\n const envValues: Record<string, any> = {};\n if (options?.env) {\n for (const [key, value] of Object.entries(options.env)) {\n if (value !== undefined) {\n envValues[key] = value;\n }\n }\n }\n\n this._childComponents.push([\n name,\n importedComponentDefinition,\n envValues,\n httpPrefix,\n ]);\n return new InstalledComponent(definition, name);\n}\n\n/**\n * The runtime type of a ComponentDefinition. TypeScript will claim\n * the default export of a module like \"cool-component/convex.config.js\"\n * is a `@link ComponentDefinition}, but during component definition evaluation\n * this is its type instead.\n *\n * This is a feature of components, which are in beta.\n * This API is unstable and may change in subsequent releases.\n */\nexport type ImportedComponentDefinition = {\n componentDefinitionPath: string;\n defaultName: string;\n};\n\nfunction exportAppForAnalysis(\n this: ComponentDefinition<any, any> & AppDefinitionData,\n): AppDefinitionAnalysis {\n const definitionType = { type: \"app\" as const };\n const childComponents = serializeChildComponents(this._childComponents);\n const httpMounts = buildHttpMounts(this._childComponents);\n const envVars = this._env\n ? Object.entries(this._env).map(\n ([name, validator]) =>\n [\n name,\n {\n type: \"value\" as const,\n value: JSON.stringify(validator.json),\n ...(validator.isOptional === \"optional\"\n ? { optional: true }\n : {}),\n },\n ] as [string, { type: \"value\"; value: string; optional?: boolean }],\n )\n : undefined;\n return {\n definitionType,\n ...(this._httpPrefix !== undefined\n ? { httpPrefix: normalizeHttpPrefix(this._httpPrefix) }\n : {}),\n childComponents: childComponents as any,\n httpMounts,\n exports: serializeExportTree(this._exportTree),\n ...(envVars !== undefined ? { envVars } : {}),\n };\n}\n\nfunction serializeExportTree(tree: ExportTree): any {\n const branch: any[] = [];\n for (const [key, child] of Object.entries(tree)) {\n let node;\n if (typeof child === \"string\") {\n node = { type: \"leaf\", leaf: child };\n } else {\n node = serializeExportTree(child);\n }\n branch.push([key, node]);\n }\n return { type: \"branch\", branch };\n}\n\nfunction normalizeHttpPrefix(prefix: string): string {\n // Ensure the prefix ends with \"/\" as required by HttpMountPath in Rust.\n return prefix.endsWith(\"/\") ? prefix : prefix + \"/\";\n}\n\nfunction buildHttpMounts(\n childComponents: [\n string,\n ImportedComponentDefinition,\n Record<string, any> | null,\n string | undefined,\n ][],\n): Record<string, string> {\n const httpMounts: Record<string, string> = {};\n for (const [name, , , httpPrefix] of childComponents) {\n if (httpPrefix !== undefined) {\n const normalized = normalizeHttpPrefix(httpPrefix);\n httpMounts[normalized] = `_reference/childComponent/${name}`;\n }\n }\n return httpMounts;\n}\n\ntype SerializedEnvArg =\n | { type: \"value\"; value: string }\n | { type: \"envVar\"; name: string };\n\nfunction serializeChildComponents(\n childComponents: [\n string,\n ImportedComponentDefinition,\n Record<string, any> | null,\n string | undefined,\n ][],\n): {\n name: string;\n path: string;\n env: [string, SerializedEnvArg][] | null;\n}[] {\n return childComponents.map(([name, definition, p]) => {\n // Note: httpPrefix (4th element) is used separately in buildHttpMounts()\n let env: [string, SerializedEnvArg][] | null = null;\n if (p !== null) {\n env = [];\n for (const [name, value] of Object.entries(p)) {\n if (value === undefined) {\n continue;\n }\n if (isEnvRef(value)) {\n env.push([name, { type: \"envVar\", name: value.__envVarRef }]);\n } else if (typeof value === \"string\") {\n env.push([name, { type: \"value\", value }]);\n } else {\n throw new Error(\n `Env var \"${name}\" must be a string or an env var reference. ` +\n `Received: ${typeof value}`,\n );\n }\n }\n }\n // we know that components carry this extra information\n const path = definition.componentDefinitionPath;\n if (!path)\n throw new Error(\n \"no .componentPath for component definition \" +\n JSON.stringify(definition, null, 2),\n );\n\n return {\n name: name!,\n path: path!,\n args: [],\n env,\n };\n });\n}\n\nfunction exportComponentForAnalysis(\n this: ComponentDefinition<any, any> & ComponentDefinitionData,\n): ComponentDefinitionAnalysis {\n const envVars = Object.entries(this._env).map(\n ([name, validator]) =>\n [\n name,\n {\n type: \"value\" as const,\n value: JSON.stringify((validator as any).json),\n ...((validator as any).isOptional === \"optional\"\n ? { optional: true }\n : {}),\n },\n ] as [string, { type: \"value\"; value: string; optional?: boolean }],\n );\n const definitionType: ComponentDefinitionType = {\n type: \"childComponent\" as const,\n name: this._name,\n args: [],\n };\n const childComponents = serializeChildComponents(this._childComponents);\n const httpMounts = buildHttpMounts(this._childComponents);\n return {\n name: this._name,\n definitionType,\n childComponents: childComponents as any,\n httpMounts,\n exports: serializeExportTree(this._exportTree),\n ...(envVars.length > 0 ? { envVars } : {}),\n };\n}\n\n// This is what is actually contained in a ComponentDefinition.\ntype RuntimeComponentDefinition = Omit<\n ComponentDefinition<any, any>,\n \"__exports\" | \"__env\"\n> &\n ComponentDefinitionData & {\n export: () => ComponentDefinitionAnalysis;\n };\ntype RuntimeAppDefinition = Omit<AppDefinition<any>, \"__env\"> &\n AppDefinitionData & {\n export: () => AppDefinitionAnalysis;\n };\n\n/**\n * Define a component, a piece of a Convex deployment with namespaced resources.\n *\n * Optionally define typed environment variables that will be available via\n * the `env` export from `_generated/server` in all Convex functions within\n * this component. Values are passed by the parent via\n * `app.use(component, { env: { ... } })`.\n *\n * @param name Name must be alphanumeric plus underscores. Typically these are\n * lowercase with underscores like `\"onboarding_flow_tracker\"`.\n *\n * This is a feature of components, which are in beta.\n * This API is unstable and may change in subsequent releases.\n */\nexport function defineComponent<\n Exports extends ComponentExports = any,\n const Env extends EnvDefinition = {},\n>(\n name: string,\n options?: {\n env?: Env;\n },\n): ComponentDefinition<Exports, Env> {\n const envValidators: PropertyValidators = {};\n if (options?.env) {\n for (const [key, decl] of Object.entries(options.env)) {\n if (decl !== null && decl !== undefined && isValidator(decl)) {\n envValidators[key] = decl as any;\n } else {\n throw new Error(\n `Environment variable \"${key}\" must be defined with a validator (e.g. v.string()).`,\n );\n }\n }\n }\n\n const ret: RuntimeComponentDefinition = {\n _isRoot: false,\n _name: name,\n _env: envValidators,\n _childComponents: [],\n _exportTree: {},\n _onInitCallbacks: {},\n\n env: createEnvRefs(`component \"${name}\"`, options?.env),\n\n export: exportComponentForAnalysis,\n use,\n\n ...({} as { __exports: any; __env: any }),\n };\n return ret as any as ComponentDefinition<Exports, Env>;\n}\n\n/**\n * Attach components, reuseable pieces of a Convex deployment, to this Convex app.\n *\n * Optionally define typed environment variables that will be available via\n * the `env` export from `_generated/server` in all Convex functions.\n *\n * @example\n * ```typescript\n * import { defineApp } from \"convex/server\";\n * import { v } from \"convex/values\";\n *\n * const app = defineApp({\n * env: {\n * OPENAI_API_KEY: v.string(),\n * DEBUG_MODE: v.optional(v.string()),\n * },\n * });\n * export default app;\n * ```\n *\n * This is a feature of components, which are in beta.\n * This API is unstable and may change in subsequent releases.\n */\nexport function defineApp<Env extends EnvDefinition = EnvDefinition>(options?: {\n httpPrefix?: string;\n env?: Env;\n}): AppDefinition<Env> {\n const httpPrefix = options?.httpPrefix;\n if (httpPrefix !== undefined && !httpPrefix.startsWith(\"/\")) {\n throw new Error(\n `httpPrefix must start with \"/\". Received: \"${httpPrefix}\"`,\n );\n }\n const env = options?.env;\n if (env !== undefined) {\n for (const [name, validator] of Object.entries(env)) {\n if (!isValidator(validator)) {\n throw new Error(\n `Environment variable \"${name}\" must be defined with a validator (e.g. v.string()).`,\n );\n }\n }\n }\n const ret: RuntimeAppDefinition = {\n _isRoot: true,\n _childComponents: [],\n _exportTree: {},\n ...(httpPrefix !== undefined ? { _httpPrefix: httpPrefix } : {}),\n ...(env !== undefined ? { _env: env } : {}),\n\n env: createEnvRefs(\"this app\", env),\n\n export: exportAppForAnalysis,\n use,\n };\n return ret as unknown as AppDefinition<Env>;\n}\n\ntype AnyInterfaceType = {\n [key: string]: AnyInterfaceType;\n} & AnyFunctionReference;\nexport type AnyComponentReference = Record<string, AnyInterfaceType>;\n\nexport type AnyChildComponents = Record<string, AnyComponentReference>;\n\n/**\n * @internal\n */\nexport function currentSystemUdfInComponent(\n componentId: string,\n): AnyComponentReference {\n return {\n [toReferencePath]: `_reference/currentSystemUdfInComponent/${componentId}`,\n };\n}\n\nfunction createChildComponents(\n root: string,\n pathParts: string[],\n): AnyChildComponents {\n const handler: ProxyHandler<object> = {\n get(_, prop: string | symbol) {\n if (typeof prop === \"string\") {\n const newParts = [...pathParts, prop];\n return createChildComponents(root, newParts);\n } else if (prop === toReferencePath) {\n if (pathParts.length < 1) {\n const found = [root, ...pathParts].join(\".\");\n throw new Error(\n `API path is expected to be of the form \\`${root}.childComponent.functionName\\`. Found: \\`${found}\\``,\n );\n }\n return `_reference/childComponent/` + pathParts.join(\"/\");\n } else {\n return undefined;\n }\n },\n };\n return new Proxy({}, handler);\n}\n\nexport const componentsGeneric = () => createChildComponents(\"components\", []);\n\nexport type AnyComponents = AnyChildComponents;\n"],
|
|
5
|
+
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cron.js
CHANGED
|
@@ -118,8 +118,8 @@ class Crons {
|
|
|
118
118
|
*
|
|
119
119
|
* @param identifier - A unique name for this scheduled job.
|
|
120
120
|
* @param schedule - The time between runs for this scheduled job.
|
|
121
|
-
* @param functionReference - A {@link FunctionReference}
|
|
122
|
-
* to schedule.
|
|
121
|
+
* @param functionReference - A {@link FunctionReference} or
|
|
122
|
+
* {@link FunctionReference_future} for the function to schedule.
|
|
123
123
|
* @param args - The arguments to the function.
|
|
124
124
|
*/
|
|
125
125
|
interval(cronIdentifier, schedule, functionReference, ...args) {
|
|
@@ -181,8 +181,8 @@ class Crons {
|
|
|
181
181
|
*
|
|
182
182
|
* @param cronIdentifier - A unique name for this scheduled job.
|
|
183
183
|
* @param schedule - What time (UTC) each day to run this function.
|
|
184
|
-
* @param functionReference - A {@link FunctionReference}
|
|
185
|
-
* to schedule.
|
|
184
|
+
* @param functionReference - A {@link FunctionReference} or
|
|
185
|
+
* {@link FunctionReference_future} for the function to schedule.
|
|
186
186
|
* @param args - The arguments to the function.
|
|
187
187
|
*/
|
|
188
188
|
daily(cronIdentifier, schedule, functionReference, ...args) {
|
|
@@ -212,8 +212,8 @@ class Crons {
|
|
|
212
212
|
*
|
|
213
213
|
* @param cronIdentifier - A unique name for this scheduled job.
|
|
214
214
|
* @param schedule - What day and time (UTC) each week to run this function.
|
|
215
|
-
* @param functionReference - A {@link FunctionReference}
|
|
216
|
-
* to schedule.
|
|
215
|
+
* @param functionReference - A {@link FunctionReference} or
|
|
216
|
+
* {@link FunctionReference_future} for the function to schedule.
|
|
217
217
|
*/
|
|
218
218
|
weekly(cronIdentifier, schedule, functionReference, ...args) {
|
|
219
219
|
const dayOfWeek = validatedDayOfWeek(schedule.dayOfWeek);
|
|
@@ -246,8 +246,8 @@ class Crons {
|
|
|
246
246
|
*
|
|
247
247
|
* @param cronIdentifier - A unique name for this scheduled job.
|
|
248
248
|
* @param schedule - What day and time (UTC) each month to run this function.
|
|
249
|
-
* @param functionReference - A {@link FunctionReference}
|
|
250
|
-
* to schedule.
|
|
249
|
+
* @param functionReference - A {@link FunctionReference} or
|
|
250
|
+
* {@link FunctionReference_future} for the function to schedule.
|
|
251
251
|
* @param args - The arguments to the function.
|
|
252
252
|
*/
|
|
253
253
|
monthly(cronIdentifier, schedule, functionReference, ...args) {
|
|
@@ -277,8 +277,8 @@ class Crons {
|
|
|
277
277
|
*
|
|
278
278
|
* @param cronIdentifier - A unique name for this scheduled job.
|
|
279
279
|
* @param cron - Cron string like `"15 7 * * *"` (Every day at 7:15 UTC)
|
|
280
|
-
* @param functionReference - A {@link FunctionReference}
|
|
281
|
-
* to schedule.
|
|
280
|
+
* @param functionReference - A {@link FunctionReference} or
|
|
281
|
+
* {@link FunctionReference_future} for the function to schedule.
|
|
282
282
|
* @param args - The arguments to the function.
|
|
283
283
|
*/
|
|
284
284
|
cron(cronIdentifier, cron, functionReference, ...args) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/server/cron.ts"],
|
|
4
|
-
"sourcesContent": ["import { getFunctionName, OptionalRestArgs } from \"../server/api.js\";\nimport { parseArgs } from \"../common/index.js\";\nimport { convexToJson, JSONValue, Value } from \"../values/index.js\";\nimport { getFunctionAddress } from \"./components/paths.js\";\nimport { SchedulableFunctionReference } from \"./scheduler.js\";\n\ntype CronSchedule = {\n type: \"cron\";\n cron: string;\n};\n/** @public */\nexport type IntervalSchedule =\n | { type: \"interval\"; seconds: number }\n | { type: \"interval\"; minutes: number }\n | { type: \"interval\"; hours: number };\n/** @public */\nexport type HourlySchedule = {\n type: \"hourly\";\n minuteUTC?: number;\n};\n/** @public */\nexport type DailySchedule = {\n type: \"daily\";\n hourUTC: number;\n minuteUTC?: number;\n};\nconst DAYS_OF_WEEK = [\n \"sunday\",\n \"monday\",\n \"tuesday\",\n \"wednesday\",\n \"thursday\",\n \"friday\",\n \"saturday\",\n] as const;\ntype DayOfWeek = (typeof DAYS_OF_WEEK)[number];\n/** @public */\nexport type WeeklySchedule = {\n type: \"weekly\";\n dayOfWeek: DayOfWeek;\n hourUTC: number;\n minuteUTC?: number;\n};\n/** @public */\nexport type MonthlySchedule = {\n type: \"monthly\";\n day: number;\n hourUTC: number;\n minuteUTC?: number;\n};\n\n// Duplicating types so docstrings are visible in signatures:\n// `Expand<Omit<MonthlySchedule, \"type\">>` doesn't preserve docstrings.\n// When we get to TypeScript 4.9, `satisfies` would go nicely here.\n\n/** @public */\nexport type Interval =\n | {\n /**\n * Run a job every `seconds` seconds, beginning\n * when the job is first deployed to Convex.\n */\n seconds: number;\n minutes?: undefined;\n hours?: undefined;\n }\n | {\n /**\n * Run a job every `minutes` minutes, beginning\n * when the job is first deployed to Convex.\n */\n minutes: number;\n seconds?: undefined;\n hours?: undefined;\n }\n | {\n /**\n * Run a job every `hours` hours, beginning when\n * when the job is first deployed to Convex.\n */\n hours: number;\n seconds?: undefined;\n minutes?: undefined;\n };\n\n/** @public */\nexport type Hourly = {\n /**\n * Minutes past the hour, 0-59. If omitted, Convex picks a minute for you\n * and spreads runs across the hour so your job isn't tied to the busy top\n * of the hour.\n */\n minuteUTC?: number;\n};\n\n/** @public */\nexport type Daily = {\n /**\n * 0-23, hour of day. Remember, this is UTC.\n */\n hourUTC: number;\n /**\n * 0-59, minute of hour. Remember, this is UTC. If omitted, Convex picks a\n * minute for you and spreads runs across the hour.\n */\n minuteUTC?: number;\n};\n\n/** @public */\nexport type Monthly = {\n /**\n * 1-31, day of month. Days greater that 28 will not run every month.\n */\n day: number;\n /**\n * 0-23, hour of day. Remember to convert from your own time zone to UTC.\n */\n hourUTC: number;\n /**\n * 0-59, minute of hour. Remember to convert from your own time zone to UTC.\n * If omitted, Convex picks a minute for you and spreads runs across the\n * hour.\n */\n minuteUTC?: number;\n};\n/** @public */\nexport type Weekly = {\n /**\n * \"monday\", \"tuesday\", etc.\n */\n dayOfWeek: DayOfWeek;\n /**\n * 0-23, hour of day. Remember to convert from your own time zone to UTC.\n */\n hourUTC: number;\n /**\n * 0-59, minute of hour. Remember to convert from your own time zone to UTC.\n * If omitted, Convex picks a minute for you and spreads runs across the\n * hour.\n */\n minuteUTC?: number;\n};\n\n/** @public */\nexport type Schedule =\n | CronSchedule\n | IntervalSchedule\n | HourlySchedule\n | DailySchedule\n | WeeklySchedule\n | MonthlySchedule;\n\n/**\n * A schedule to run a Convex mutation or action on.\n * You can schedule Convex functions to run regularly with\n * {@link interval} and exporting it.\n *\n * @public\n **/\nexport interface CronJob {\n name: string;\n args: JSONValue;\n schedule: Schedule;\n}\n\n/**\n * Create a CronJobs object to schedule recurring tasks.\n *\n * ```js\n * // convex/crons.js\n * import { cronJobs } from 'convex/server';\n * import { api } from \"./_generated/api\";\n *\n * const crons = cronJobs();\n * crons.weekly(\n * \"weekly re-engagement email\",\n * {\n * hourUTC: 17, // (9:30am Pacific/10:30am Daylight Savings Pacific)\n * minuteUTC: 30,\n * },\n * api.emails.send\n * )\n * export default crons;\n * ```\n *\n * @public\n */\nexport const cronJobs = () => new Crons();\n\n/**\n * @public\n *\n * This is a cron string. They're complicated!\n */\ntype CronString = string;\n\nfunction validateIntervalNumber(n: number) {\n if (!Number.isInteger(n) || n <= 0) {\n throw new Error(\"Interval must be an integer greater than 0\");\n }\n}\n\nfunction validatedDayOfMonth(n: number) {\n if (!Number.isInteger(n) || n < 1 || n > 31) {\n throw new Error(\"Day of month must be an integer from 1 to 31\");\n }\n return n;\n}\n\nfunction validatedDayOfWeek(s: string) {\n if (!DAYS_OF_WEEK.includes(s as DayOfWeek)) {\n throw new Error('Day of week must be a string like \"monday\".');\n }\n return s as DayOfWeek;\n}\n\nfunction validatedHourOfDay(n: number) {\n if (!Number.isInteger(n) || n < 0 || n > 23) {\n throw new Error(\"Hour of day must be an integer from 0 to 23\");\n }\n return n;\n}\n\nfunction validatedMinuteOfHour(n: number) {\n if (!Number.isInteger(n) || n < 0 || n > 59) {\n throw new Error(\"Minute of hour must be an integer from 0 to 59\");\n }\n return n;\n}\n\n// `minuteUTC` is optional: when omitted the backend picks a minute per job and\n// spreads runs across the hour. Only validate when a minute was provided.\nfunction validatedOptionalMinuteOfHour(n: number | undefined) {\n return n === undefined ? undefined : validatedMinuteOfHour(n);\n}\n\n// `crons.hourly()` lets the schedule object be omitted entirely. Tell the two\n// call shapes apart by whether the second argument resolves to a function\n// reference (the way the scheduler syscalls do) rather than a schedule object.\nfunction isSchedulableFunctionReference(\n arg: Hourly | SchedulableFunctionReference,\n): arg is SchedulableFunctionReference {\n try {\n getFunctionAddress(arg);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction validatedCronString(s: string) {\n return s;\n}\n\nfunction validatedCronIdentifier(s: string) {\n if (!s.match(/^[ -~]*$/)) {\n throw new Error(\n `Invalid cron identifier ${s}: use ASCII letters that are not control characters`,\n );\n }\n return s;\n}\n\n/**\n * A class for scheduling cron jobs.\n *\n * To learn more see the documentation at https://docs.convex.dev/scheduling/cron-jobs\n *\n * @public\n */\nexport class Crons {\n crons: Record<string, CronJob>;\n isCrons: true;\n constructor() {\n this.isCrons = true;\n this.crons = {};\n }\n\n /** @internal */\n schedule(\n cronIdentifier: string,\n schedule: Schedule,\n functionReference: SchedulableFunctionReference,\n args?: Record<string, Value>,\n ) {\n const cronArgs = parseArgs(args);\n validatedCronIdentifier(cronIdentifier);\n if (cronIdentifier in this.crons) {\n throw new Error(`Cron identifier registered twice: ${cronIdentifier}`);\n }\n this.crons[cronIdentifier] = {\n name: getFunctionName(functionReference),\n args: [convexToJson(cronArgs)],\n schedule: schedule,\n };\n }\n\n /**\n * Schedule a mutation or action to run at some interval.\n *\n * ```js\n * crons.interval(\"Clear presence data\", {seconds: 30}, api.presence.clear);\n * ```\n *\n * @param identifier - A unique name for this scheduled job.\n * @param schedule - The time between runs for this scheduled job.\n * @param functionReference - A {@link FunctionReference} for the function\n * to schedule.\n * @param args - The arguments to the function.\n */\n interval<FuncRef extends SchedulableFunctionReference>(\n cronIdentifier: string,\n schedule: Interval,\n functionReference: FuncRef,\n ...args: OptionalRestArgs<FuncRef>\n ) {\n const s = schedule;\n const hasSeconds = +(\"seconds\" in s && s.seconds !== undefined);\n const hasMinutes = +(\"minutes\" in s && s.minutes !== undefined);\n const hasHours = +(\"hours\" in s && s.hours !== undefined);\n const total = hasSeconds + hasMinutes + hasHours;\n if (total !== 1) {\n throw new Error(\"Must specify one of seconds, minutes, or hours\");\n }\n if (hasSeconds) {\n validateIntervalNumber(schedule.seconds!);\n } else if (hasMinutes) {\n validateIntervalNumber(schedule.minutes!);\n } else if (hasHours) {\n validateIntervalNumber(schedule.hours!);\n }\n this.schedule(\n cronIdentifier,\n { ...schedule, type: \"interval\" },\n functionReference,\n ...args,\n );\n }\n\n /**\n * Schedule a mutation or action to run on an hourly basis.\n *\n * ```js\n * crons.hourly(\n * \"Reset high scores\",\n * {\n * minuteUTC: 30,\n * },\n * api.scores.reset\n * )\n * ```\n *\n * @param cronIdentifier - A unique name for this scheduled job.\n * @param schedule - What minute (UTC) of each hour to run this function. May\n * be omitted to let Convex pick a minute and spread runs across the hour.\n * @param functionReference - A {@link FunctionReference} for the function\n * to schedule.\n * @param args - The arguments to the function.\n */\n hourly<FuncRef extends SchedulableFunctionReference>(\n cronIdentifier: string,\n functionReference: FuncRef,\n ...args: OptionalRestArgs<FuncRef>\n ): void;\n hourly<FuncRef extends SchedulableFunctionReference>(\n cronIdentifier: string,\n schedule: Hourly,\n functionReference: FuncRef,\n ...args: OptionalRestArgs<FuncRef>\n ): void;\n hourly<FuncRef extends SchedulableFunctionReference>(\n cronIdentifier: string,\n scheduleOrFunctionReference: Hourly | FuncRef,\n functionReferenceOrArg?: FuncRef | Record<string, Value>,\n ...args: any[]\n ): void {\n // The schedule object may be omitted, so the second argument is either the\n // function reference (no schedule) or the schedule.\n if (isSchedulableFunctionReference(scheduleOrFunctionReference)) {\n this.schedule(\n cronIdentifier,\n { type: \"hourly\" },\n scheduleOrFunctionReference,\n functionReferenceOrArg as Record<string, Value> | undefined,\n );\n return;\n }\n const minuteUTC = validatedOptionalMinuteOfHour(\n scheduleOrFunctionReference.minuteUTC,\n );\n this.schedule(\n cronIdentifier,\n minuteUTC === undefined\n ? { type: \"hourly\" }\n : { minuteUTC, type: \"hourly\" },\n functionReferenceOrArg as FuncRef,\n ...args,\n );\n }\n\n /**\n * Schedule a mutation or action to run on a daily basis.\n *\n * ```js\n * crons.daily(\n * \"Reset high scores\",\n * {\n * hourUTC: 17, // (9:30am Pacific/10:30am Daylight Savings Pacific)\n * minuteUTC: 30,\n * },\n * api.scores.reset\n * )\n * ```\n *\n * @param cronIdentifier - A unique name for this scheduled job.\n * @param schedule - What time (UTC) each day to run this function.\n * @param functionReference - A {@link FunctionReference} for the function\n * to schedule.\n * @param args - The arguments to the function.\n */\n daily<FuncRef extends SchedulableFunctionReference>(\n cronIdentifier: string,\n schedule: Daily,\n functionReference: FuncRef,\n ...args: OptionalRestArgs<FuncRef>\n ) {\n const hourUTC = validatedHourOfDay(schedule.hourUTC);\n const minuteUTC = validatedOptionalMinuteOfHour(schedule.minuteUTC);\n this.schedule(\n cronIdentifier,\n minuteUTC === undefined\n ? { hourUTC, type: \"daily\" }\n : { hourUTC, minuteUTC, type: \"daily\" },\n functionReference,\n ...args,\n );\n }\n\n /**\n * Schedule a mutation or action to run on a weekly basis.\n *\n * ```js\n * crons.weekly(\n * \"Weekly re-engagement email\",\n * {\n * dayOfWeek: \"Tuesday\",\n * hourUTC: 17, // (9:30am Pacific/10:30am Daylight Savings Pacific)\n * minuteUTC: 30,\n * },\n * api.emails.send\n * )\n * ```\n *\n * @param cronIdentifier - A unique name for this scheduled job.\n * @param schedule - What day and time (UTC) each week to run this function.\n * @param functionReference - A {@link FunctionReference} for the function\n * to schedule.\n */\n weekly<FuncRef extends SchedulableFunctionReference>(\n cronIdentifier: string,\n schedule: Weekly,\n functionReference: FuncRef,\n ...args: OptionalRestArgs<FuncRef>\n ) {\n const dayOfWeek = validatedDayOfWeek(schedule.dayOfWeek);\n const hourUTC = validatedHourOfDay(schedule.hourUTC);\n const minuteUTC = validatedOptionalMinuteOfHour(schedule.minuteUTC);\n this.schedule(\n cronIdentifier,\n minuteUTC === undefined\n ? { dayOfWeek, hourUTC, type: \"weekly\" }\n : { dayOfWeek, hourUTC, minuteUTC, type: \"weekly\" },\n functionReference,\n ...args,\n );\n }\n\n /**\n * Schedule a mutation or action to run on a monthly basis.\n *\n * Note that some months have fewer days than others, so e.g. a function\n * scheduled to run on the 30th will not run in February.\n *\n * ```js\n * crons.monthly(\n * \"Bill customers at \",\n * {\n * hourUTC: 17, // (9:30am Pacific/10:30am Daylight Savings Pacific)\n * minuteUTC: 30,\n * day: 1,\n * },\n * api.billing.billCustomers\n * )\n * ```\n *\n * @param cronIdentifier - A unique name for this scheduled job.\n * @param schedule - What day and time (UTC) each month to run this function.\n * @param functionReference - A {@link FunctionReference} for the function\n * to schedule.\n * @param args - The arguments to the function.\n */\n monthly<FuncRef extends SchedulableFunctionReference>(\n cronIdentifier: string,\n schedule: Monthly,\n functionReference: FuncRef,\n ...args: OptionalRestArgs<FuncRef>\n ) {\n const day = validatedDayOfMonth(schedule.day);\n const hourUTC = validatedHourOfDay(schedule.hourUTC);\n const minuteUTC = validatedOptionalMinuteOfHour(schedule.minuteUTC);\n this.schedule(\n cronIdentifier,\n minuteUTC === undefined\n ? { day, hourUTC, type: \"monthly\" }\n : { day, hourUTC, minuteUTC, type: \"monthly\" },\n functionReference,\n ...args,\n );\n }\n\n /**\n * Schedule a mutation or action to run on a recurring basis.\n *\n * Like the unix command `cron`, Sunday is 0, Monday is 1, etc.\n *\n * ```\n * \u250C\u2500 minute (0 - 59)\n * \u2502 \u250C\u2500 hour (0 - 23)\n * \u2502 \u2502 \u250C\u2500 day of the month (1 - 31)\n * \u2502 \u2502 \u2502 \u250C\u2500 month (1 - 12)\n * \u2502 \u2502 \u2502 \u2502 \u250C\u2500 day of the week (0 - 6) (Sunday to Saturday)\n * \"* * * * *\"\n * ```\n *\n * @param cronIdentifier - A unique name for this scheduled job.\n * @param cron - Cron string like `\"15 7 * * *\"` (Every day at 7:15 UTC)\n * @param functionReference - A {@link FunctionReference} for the function\n * to schedule.\n * @param args - The arguments to the function.\n */\n cron<FuncRef extends SchedulableFunctionReference>(\n cronIdentifier: string,\n cron: CronString,\n functionReference: FuncRef,\n ...args: OptionalRestArgs<FuncRef>\n ) {\n const c = validatedCronString(cron);\n this.schedule(\n cronIdentifier,\n { cron: c, type: \"cron\" },\n functionReference,\n ...args,\n );\n }\n\n /** @internal */\n export() {\n return JSON.stringify(this.crons);\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import {\n FunctionReference_future,\n getFunctionName,\n OptionalRestArgs,\n} from \"../server/api.js\";\nimport { parseArgs } from \"../common/index.js\";\nimport { convexToJson, JSONValue, Value } from \"../values/index.js\";\nimport { getFunctionAddress } from \"./components/paths.js\";\nimport { SchedulableFunctionReference } from \"./scheduler.js\";\n\n// Mirrors the constraint on `Scheduler.runAfter` and `Scheduler.runAt`, which\n// is module-local to `scheduler.ts`.\ntype SchedulableFunctionReferenceCompat =\n | SchedulableFunctionReference\n | FunctionReference_future<\"mutation\" | \"action\", \"public\" | \"internal\">;\n\ntype CronSchedule = {\n type: \"cron\";\n cron: string;\n};\n/** @public */\nexport type IntervalSchedule =\n | { type: \"interval\"; seconds: number }\n | { type: \"interval\"; minutes: number }\n | { type: \"interval\"; hours: number };\n/** @public */\nexport type HourlySchedule = {\n type: \"hourly\";\n minuteUTC?: number;\n};\n/** @public */\nexport type DailySchedule = {\n type: \"daily\";\n hourUTC: number;\n minuteUTC?: number;\n};\nconst DAYS_OF_WEEK = [\n \"sunday\",\n \"monday\",\n \"tuesday\",\n \"wednesday\",\n \"thursday\",\n \"friday\",\n \"saturday\",\n] as const;\ntype DayOfWeek = (typeof DAYS_OF_WEEK)[number];\n/** @public */\nexport type WeeklySchedule = {\n type: \"weekly\";\n dayOfWeek: DayOfWeek;\n hourUTC: number;\n minuteUTC?: number;\n};\n/** @public */\nexport type MonthlySchedule = {\n type: \"monthly\";\n day: number;\n hourUTC: number;\n minuteUTC?: number;\n};\n\n// Duplicating types so docstrings are visible in signatures:\n// `Expand<Omit<MonthlySchedule, \"type\">>` doesn't preserve docstrings.\n// When we get to TypeScript 4.9, `satisfies` would go nicely here.\n\n/** @public */\nexport type Interval =\n | {\n /**\n * Run a job every `seconds` seconds, beginning\n * when the job is first deployed to Convex.\n */\n seconds: number;\n minutes?: undefined;\n hours?: undefined;\n }\n | {\n /**\n * Run a job every `minutes` minutes, beginning\n * when the job is first deployed to Convex.\n */\n minutes: number;\n seconds?: undefined;\n hours?: undefined;\n }\n | {\n /**\n * Run a job every `hours` hours, beginning when\n * when the job is first deployed to Convex.\n */\n hours: number;\n seconds?: undefined;\n minutes?: undefined;\n };\n\n/** @public */\nexport type Hourly = {\n /**\n * Minutes past the hour, 0-59. If omitted, Convex picks a minute for you\n * and spreads runs across the hour so your job isn't tied to the busy top\n * of the hour.\n */\n minuteUTC?: number;\n};\n\n/** @public */\nexport type Daily = {\n /**\n * 0-23, hour of day. Remember, this is UTC.\n */\n hourUTC: number;\n /**\n * 0-59, minute of hour. Remember, this is UTC. If omitted, Convex picks a\n * minute for you and spreads runs across the hour.\n */\n minuteUTC?: number;\n};\n\n/** @public */\nexport type Monthly = {\n /**\n * 1-31, day of month. Days greater that 28 will not run every month.\n */\n day: number;\n /**\n * 0-23, hour of day. Remember to convert from your own time zone to UTC.\n */\n hourUTC: number;\n /**\n * 0-59, minute of hour. Remember to convert from your own time zone to UTC.\n * If omitted, Convex picks a minute for you and spreads runs across the\n * hour.\n */\n minuteUTC?: number;\n};\n/** @public */\nexport type Weekly = {\n /**\n * \"monday\", \"tuesday\", etc.\n */\n dayOfWeek: DayOfWeek;\n /**\n * 0-23, hour of day. Remember to convert from your own time zone to UTC.\n */\n hourUTC: number;\n /**\n * 0-59, minute of hour. Remember to convert from your own time zone to UTC.\n * If omitted, Convex picks a minute for you and spreads runs across the\n * hour.\n */\n minuteUTC?: number;\n};\n\n/** @public */\nexport type Schedule =\n | CronSchedule\n | IntervalSchedule\n | HourlySchedule\n | DailySchedule\n | WeeklySchedule\n | MonthlySchedule;\n\n/**\n * A schedule to run a Convex mutation or action on.\n * You can schedule Convex functions to run regularly with\n * {@link interval} and exporting it.\n *\n * @public\n **/\nexport interface CronJob {\n name: string;\n args: JSONValue;\n schedule: Schedule;\n}\n\n/**\n * Create a CronJobs object to schedule recurring tasks.\n *\n * ```js\n * // convex/crons.js\n * import { cronJobs } from 'convex/server';\n * import { api } from \"./_generated/api\";\n *\n * const crons = cronJobs();\n * crons.weekly(\n * \"weekly re-engagement email\",\n * {\n * hourUTC: 17, // (9:30am Pacific/10:30am Daylight Savings Pacific)\n * minuteUTC: 30,\n * },\n * api.emails.send\n * )\n * export default crons;\n * ```\n *\n * @public\n */\nexport const cronJobs = () => new Crons();\n\n/**\n * @public\n *\n * This is a cron string. They're complicated!\n */\ntype CronString = string;\n\nfunction validateIntervalNumber(n: number) {\n if (!Number.isInteger(n) || n <= 0) {\n throw new Error(\"Interval must be an integer greater than 0\");\n }\n}\n\nfunction validatedDayOfMonth(n: number) {\n if (!Number.isInteger(n) || n < 1 || n > 31) {\n throw new Error(\"Day of month must be an integer from 1 to 31\");\n }\n return n;\n}\n\nfunction validatedDayOfWeek(s: string) {\n if (!DAYS_OF_WEEK.includes(s as DayOfWeek)) {\n throw new Error('Day of week must be a string like \"monday\".');\n }\n return s as DayOfWeek;\n}\n\nfunction validatedHourOfDay(n: number) {\n if (!Number.isInteger(n) || n < 0 || n > 23) {\n throw new Error(\"Hour of day must be an integer from 0 to 23\");\n }\n return n;\n}\n\nfunction validatedMinuteOfHour(n: number) {\n if (!Number.isInteger(n) || n < 0 || n > 59) {\n throw new Error(\"Minute of hour must be an integer from 0 to 59\");\n }\n return n;\n}\n\n// `minuteUTC` is optional: when omitted the backend picks a minute per job and\n// spreads runs across the hour. Only validate when a minute was provided.\nfunction validatedOptionalMinuteOfHour(n: number | undefined) {\n return n === undefined ? undefined : validatedMinuteOfHour(n);\n}\n\n// `crons.hourly()` lets the schedule object be omitted entirely. Tell the two\n// call shapes apart by whether the second argument resolves to a function\n// reference (the way the scheduler syscalls do) rather than a schedule object.\nfunction isSchedulableFunctionReference(\n arg: Hourly | SchedulableFunctionReferenceCompat,\n): arg is SchedulableFunctionReferenceCompat {\n try {\n getFunctionAddress(arg);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction validatedCronString(s: string) {\n return s;\n}\n\nfunction validatedCronIdentifier(s: string) {\n if (!s.match(/^[ -~]*$/)) {\n throw new Error(\n `Invalid cron identifier ${s}: use ASCII letters that are not control characters`,\n );\n }\n return s;\n}\n\n/**\n * A class for scheduling cron jobs.\n *\n * To learn more see the documentation at https://docs.convex.dev/scheduling/cron-jobs\n *\n * @public\n */\nexport class Crons {\n crons: Record<string, CronJob>;\n isCrons: true;\n constructor() {\n this.isCrons = true;\n this.crons = {};\n }\n\n /** @internal */\n schedule(\n cronIdentifier: string,\n schedule: Schedule,\n functionReference: SchedulableFunctionReferenceCompat,\n args?: Record<string, Value>,\n ) {\n const cronArgs = parseArgs(args);\n validatedCronIdentifier(cronIdentifier);\n if (cronIdentifier in this.crons) {\n throw new Error(`Cron identifier registered twice: ${cronIdentifier}`);\n }\n this.crons[cronIdentifier] = {\n name: getFunctionName(functionReference),\n args: [convexToJson(cronArgs)],\n schedule: schedule,\n };\n }\n\n /**\n * Schedule a mutation or action to run at some interval.\n *\n * ```js\n * crons.interval(\"Clear presence data\", {seconds: 30}, api.presence.clear);\n * ```\n *\n * @param identifier - A unique name for this scheduled job.\n * @param schedule - The time between runs for this scheduled job.\n * @param functionReference - A {@link FunctionReference} or\n * {@link FunctionReference_future} for the function to schedule.\n * @param args - The arguments to the function.\n */\n interval<FuncRef extends SchedulableFunctionReferenceCompat>(\n cronIdentifier: string,\n schedule: Interval,\n functionReference: FuncRef,\n ...args: OptionalRestArgs<FuncRef>\n ) {\n const s = schedule;\n const hasSeconds = +(\"seconds\" in s && s.seconds !== undefined);\n const hasMinutes = +(\"minutes\" in s && s.minutes !== undefined);\n const hasHours = +(\"hours\" in s && s.hours !== undefined);\n const total = hasSeconds + hasMinutes + hasHours;\n if (total !== 1) {\n throw new Error(\"Must specify one of seconds, minutes, or hours\");\n }\n if (hasSeconds) {\n validateIntervalNumber(schedule.seconds!);\n } else if (hasMinutes) {\n validateIntervalNumber(schedule.minutes!);\n } else if (hasHours) {\n validateIntervalNumber(schedule.hours!);\n }\n this.schedule(\n cronIdentifier,\n { ...schedule, type: \"interval\" },\n functionReference,\n ...args,\n );\n }\n\n /**\n * Schedule a mutation or action to run on an hourly basis.\n *\n * ```js\n * crons.hourly(\n * \"Reset high scores\",\n * {\n * minuteUTC: 30,\n * },\n * api.scores.reset\n * )\n * ```\n *\n * @param cronIdentifier - A unique name for this scheduled job.\n * @param schedule - What minute (UTC) of each hour to run this function. May\n * be omitted to let Convex pick a minute and spread runs across the hour.\n * @param functionReference - A {@link FunctionReference} or\n * {@link FunctionReference_future} for the function to schedule.\n * @param args - The arguments to the function.\n */\n hourly<FuncRef extends SchedulableFunctionReferenceCompat>(\n cronIdentifier: string,\n functionReference: FuncRef,\n ...args: OptionalRestArgs<FuncRef>\n ): void;\n hourly<FuncRef extends SchedulableFunctionReferenceCompat>(\n cronIdentifier: string,\n schedule: Hourly,\n functionReference: FuncRef,\n ...args: OptionalRestArgs<FuncRef>\n ): void;\n hourly<FuncRef extends SchedulableFunctionReferenceCompat>(\n cronIdentifier: string,\n scheduleOrFunctionReference: Hourly | FuncRef,\n functionReferenceOrArg?: FuncRef | Record<string, Value>,\n ...args: any[]\n ): void {\n // The schedule object may be omitted, so the second argument is either the\n // function reference (no schedule) or the schedule.\n if (isSchedulableFunctionReference(scheduleOrFunctionReference)) {\n this.schedule(\n cronIdentifier,\n { type: \"hourly\" },\n scheduleOrFunctionReference,\n functionReferenceOrArg as Record<string, Value> | undefined,\n );\n return;\n }\n const minuteUTC = validatedOptionalMinuteOfHour(\n scheduleOrFunctionReference.minuteUTC,\n );\n this.schedule(\n cronIdentifier,\n minuteUTC === undefined\n ? { type: \"hourly\" }\n : { minuteUTC, type: \"hourly\" },\n functionReferenceOrArg as FuncRef,\n ...args,\n );\n }\n\n /**\n * Schedule a mutation or action to run on a daily basis.\n *\n * ```js\n * crons.daily(\n * \"Reset high scores\",\n * {\n * hourUTC: 17, // (9:30am Pacific/10:30am Daylight Savings Pacific)\n * minuteUTC: 30,\n * },\n * api.scores.reset\n * )\n * ```\n *\n * @param cronIdentifier - A unique name for this scheduled job.\n * @param schedule - What time (UTC) each day to run this function.\n * @param functionReference - A {@link FunctionReference} or\n * {@link FunctionReference_future} for the function to schedule.\n * @param args - The arguments to the function.\n */\n daily<FuncRef extends SchedulableFunctionReferenceCompat>(\n cronIdentifier: string,\n schedule: Daily,\n functionReference: FuncRef,\n ...args: OptionalRestArgs<FuncRef>\n ) {\n const hourUTC = validatedHourOfDay(schedule.hourUTC);\n const minuteUTC = validatedOptionalMinuteOfHour(schedule.minuteUTC);\n this.schedule(\n cronIdentifier,\n minuteUTC === undefined\n ? { hourUTC, type: \"daily\" }\n : { hourUTC, minuteUTC, type: \"daily\" },\n functionReference,\n ...args,\n );\n }\n\n /**\n * Schedule a mutation or action to run on a weekly basis.\n *\n * ```js\n * crons.weekly(\n * \"Weekly re-engagement email\",\n * {\n * dayOfWeek: \"Tuesday\",\n * hourUTC: 17, // (9:30am Pacific/10:30am Daylight Savings Pacific)\n * minuteUTC: 30,\n * },\n * api.emails.send\n * )\n * ```\n *\n * @param cronIdentifier - A unique name for this scheduled job.\n * @param schedule - What day and time (UTC) each week to run this function.\n * @param functionReference - A {@link FunctionReference} or\n * {@link FunctionReference_future} for the function to schedule.\n */\n weekly<FuncRef extends SchedulableFunctionReferenceCompat>(\n cronIdentifier: string,\n schedule: Weekly,\n functionReference: FuncRef,\n ...args: OptionalRestArgs<FuncRef>\n ) {\n const dayOfWeek = validatedDayOfWeek(schedule.dayOfWeek);\n const hourUTC = validatedHourOfDay(schedule.hourUTC);\n const minuteUTC = validatedOptionalMinuteOfHour(schedule.minuteUTC);\n this.schedule(\n cronIdentifier,\n minuteUTC === undefined\n ? { dayOfWeek, hourUTC, type: \"weekly\" }\n : { dayOfWeek, hourUTC, minuteUTC, type: \"weekly\" },\n functionReference,\n ...args,\n );\n }\n\n /**\n * Schedule a mutation or action to run on a monthly basis.\n *\n * Note that some months have fewer days than others, so e.g. a function\n * scheduled to run on the 30th will not run in February.\n *\n * ```js\n * crons.monthly(\n * \"Bill customers at \",\n * {\n * hourUTC: 17, // (9:30am Pacific/10:30am Daylight Savings Pacific)\n * minuteUTC: 30,\n * day: 1,\n * },\n * api.billing.billCustomers\n * )\n * ```\n *\n * @param cronIdentifier - A unique name for this scheduled job.\n * @param schedule - What day and time (UTC) each month to run this function.\n * @param functionReference - A {@link FunctionReference} or\n * {@link FunctionReference_future} for the function to schedule.\n * @param args - The arguments to the function.\n */\n monthly<FuncRef extends SchedulableFunctionReferenceCompat>(\n cronIdentifier: string,\n schedule: Monthly,\n functionReference: FuncRef,\n ...args: OptionalRestArgs<FuncRef>\n ) {\n const day = validatedDayOfMonth(schedule.day);\n const hourUTC = validatedHourOfDay(schedule.hourUTC);\n const minuteUTC = validatedOptionalMinuteOfHour(schedule.minuteUTC);\n this.schedule(\n cronIdentifier,\n minuteUTC === undefined\n ? { day, hourUTC, type: \"monthly\" }\n : { day, hourUTC, minuteUTC, type: \"monthly\" },\n functionReference,\n ...args,\n );\n }\n\n /**\n * Schedule a mutation or action to run on a recurring basis.\n *\n * Like the unix command `cron`, Sunday is 0, Monday is 1, etc.\n *\n * ```\n * \u250C\u2500 minute (0 - 59)\n * \u2502 \u250C\u2500 hour (0 - 23)\n * \u2502 \u2502 \u250C\u2500 day of the month (1 - 31)\n * \u2502 \u2502 \u2502 \u250C\u2500 month (1 - 12)\n * \u2502 \u2502 \u2502 \u2502 \u250C\u2500 day of the week (0 - 6) (Sunday to Saturday)\n * \"* * * * *\"\n * ```\n *\n * @param cronIdentifier - A unique name for this scheduled job.\n * @param cron - Cron string like `\"15 7 * * *\"` (Every day at 7:15 UTC)\n * @param functionReference - A {@link FunctionReference} or\n * {@link FunctionReference_future} for the function to schedule.\n * @param args - The arguments to the function.\n */\n cron<FuncRef extends SchedulableFunctionReferenceCompat>(\n cronIdentifier: string,\n cron: CronString,\n functionReference: FuncRef,\n ...args: OptionalRestArgs<FuncRef>\n ) {\n const c = validatedCronString(cron);\n this.schedule(\n cronIdentifier,\n { cron: c, type: \"cron\" },\n functionReference,\n ...args,\n );\n }\n\n /** @internal */\n export() {\n return JSON.stringify(this.crons);\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAIO;AACP,oBAA0B;AAC1B,oBAA+C;AAC/C,mBAAmC;AA6BnC,MAAM,eAAe;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAyJO,MAAM,WAAW,MAAM,IAAI,MAAM;AASxC,SAAS,uBAAuB,GAAW;AACzC,MAAI,CAAC,OAAO,UAAU,CAAC,KAAK,KAAK,GAAG;AAClC,UAAM,IAAI,MAAM,4CAA4C;AAAA,EAC9D;AACF;AAEA,SAAS,oBAAoB,GAAW;AACtC,MAAI,CAAC,OAAO,UAAU,CAAC,KAAK,IAAI,KAAK,IAAI,IAAI;AAC3C,UAAM,IAAI,MAAM,8CAA8C;AAAA,EAChE;AACA,SAAO;AACT;AAEA,SAAS,mBAAmB,GAAW;AACrC,MAAI,CAAC,aAAa,SAAS,CAAc,GAAG;AAC1C,UAAM,IAAI,MAAM,6CAA6C;AAAA,EAC/D;AACA,SAAO;AACT;AAEA,SAAS,mBAAmB,GAAW;AACrC,MAAI,CAAC,OAAO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ACL;AAAA,EACF;AAAA;AAAA,EAGA,SAAS;AACP,WAAO,KAAK,UAAU,KAAK,KAAK;AAAA,EAClC;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/server/impl/actions_impl.ts"],
|
|
4
|
-
"sourcesContent": ["import { convexToJson, jsonToConvex, Value } from \"../../values/index.js\";\nimport { version } from \"../../index.js\";\nimport { performAsyncSyscall } from \"./syscall.js\";\nimport { parseArgs } from \"../../common/index.js\";\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAkD;AAClD,eAAwB;AACxB,qBAAoC;AACpC,oBAA0B;
|
|
4
|
+
"sourcesContent": ["import { convexToJson, jsonToConvex, Value } from \"../../values/index.js\";\nimport { version } from \"../../index.js\";\nimport { performAsyncSyscall } from \"./syscall.js\";\nimport { parseArgs } from \"../../common/index.js\";\nimport {\n FunctionReference,\n FunctionReference_future,\n} from \"../../server/api.js\";\nimport { getFunctionAddress } from \"../components/paths.js\";\nimport { validateArg } from \"./validate.js\";\n\nfunction syscallArgs(\n requestId: string,\n functionReference: any,\n args?: Record<string, Value>,\n) {\n const address = getFunctionAddress(functionReference);\n return {\n ...address,\n args: convexToJson(parseArgs(args)),\n version,\n requestId,\n };\n}\n\nexport function setupActionCalls(requestId: string) {\n return {\n runQuery: async (\n query:\n | FunctionReference<\"query\", \"public\" | \"internal\">\n | FunctionReference_future<\"query\", \"public\" | \"internal\">,\n args?: Record<string, Value>,\n ): Promise<any> => {\n const result = await performAsyncSyscall(\n \"1.0/actions/query\",\n syscallArgs(requestId, query, args),\n );\n return jsonToConvex(result);\n },\n runMutation: async (\n mutation:\n | FunctionReference<\"mutation\", \"public\" | \"internal\">\n | FunctionReference_future<\"mutation\", \"public\" | \"internal\">,\n args?: Record<string, Value>,\n ): Promise<any> => {\n const result = await performAsyncSyscall(\n \"1.0/actions/mutation\",\n syscallArgs(requestId, mutation, args),\n );\n return jsonToConvex(result);\n },\n runAction: async (\n action:\n | FunctionReference<\"action\", \"public\" | \"internal\">\n | FunctionReference_future<\"action\", \"public\" | \"internal\">,\n args?: Record<string, Value>,\n ): Promise<any> => {\n const result = await performAsyncSyscall(\n \"1.0/actions/action\",\n syscallArgs(requestId, action, args),\n );\n return jsonToConvex(result);\n },\n };\n}\n\n/**\n * Get a short-lived credential for calling a Convex-managed service.\n *\n * This function can only be called while an action is running. The credential\n * is scoped to the current deployment and should be sent as a bearer token.\n * Repeated calls in the same action reuse one token; a failed mint is not\n * cached, so a later call retries.\n *\n * @param service - The service the credential may access.\n * @returns A JWT to send as `Authorization: Bearer <token>`. Keep it inside\n * the action: don't return it to clients or store it in environment\n * variables.\n */\nexport async function getServiceToken(service: \"ai-gateway\"): Promise<string> {\n validateArg(service, 1, \"getServiceToken\", \"service\");\n if (service !== \"ai-gateway\") {\n throw new Error(`Unsupported service \"${String(service)}\"`);\n }\n return await performAsyncSyscall(\"1.0/createServiceToken\", {\n service,\n version,\n });\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAkD;AAClD,eAAwB;AACxB,qBAAoC;AACpC,oBAA0B;AAK1B,mBAAmC;AACnC,sBAA4B;AAE5B,SAAS,YACP,WACA,mBACA,MACA;AACA,QAAM,cAAU,iCAAmB,iBAAiB;AACpD,SAAO;AAAA,IACL,GAAG;AAAA,IACH,UAAM,gCAAa,yBAAU,IAAI,CAAC;AAAA,IAClC;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,iBAAiB,WAAmB;AAClD,SAAO;AAAA,IACL,UAAU,OACR,OAGA,SACiB;AACjB,YAAM,SAAS,UAAM;AAAA,QACnB;AAAA,QACA,YAAY,WAAW,OAAO,IAAI;AAAA,MACpC;AACA,iBAAO,4BAAa,MAAM;AAAA,IAC5B;AAAA,IACA,aAAa,OACX,UAGA,SACiB;AACjB,YAAM,SAAS,UAAM;AAAA,QACnB;AAAA,QACA,YAAY,WAAW,UAAU,IAAI;AAAA,MACvC;AACA,iBAAO,4BAAa,MAAM;AAAA,IAC5B;AAAA,IACA,WAAW,OACT,QAGA,SACiB;AACjB,YAAM,SAAS,UAAM;AAAA,QACnB;AAAA,QACA,YAAY,WAAW,QAAQ,IAAI;AAAA,MACrC;AACA,iBAAO,4BAAa,MAAM;AAAA,IAC5B;AAAA,EACF;AACF;AAeA,eAAsB,gBAAgB,SAAwC;AAC5E,mCAAY,SAAS,GAAG,mBAAmB,SAAS;AACpD,MAAI,YAAY,cAAc;AAC5B,UAAM,IAAI,MAAM,wBAAwB,OAAO,OAAO,CAAC,GAAG;AAAA,EAC5D;AACA,SAAO,UAAM,oCAAoB,0BAA0B;AAAA,IACzD;AAAA,IACA;AAAA,EACF,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -61,6 +61,10 @@ async function getDeploymentMetadata() {
|
|
|
61
61
|
class: result.class
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
+
function getSnapshotTs() {
|
|
65
|
+
const syscallJSON = (0, import_syscall.performSyscall)("1.0/getSnapshotTs", {});
|
|
66
|
+
return (0, import_values.jsonToConvex)(syscallJSON);
|
|
67
|
+
}
|
|
64
68
|
async function getRequestMetadata() {
|
|
65
69
|
const { ip, userAgent, requestId, scheduledFunctionId, authToken } = await (0, import_syscall.performAsyncSyscall)("1.0/getRequestMetadata", {});
|
|
66
70
|
return { ip, userAgent, requestId, scheduledFunctionId, authToken };
|
|
@@ -73,7 +77,8 @@ function setupQueryMeta(visibility) {
|
|
|
73
77
|
visibility
|
|
74
78
|
}),
|
|
75
79
|
getTransactionMetrics,
|
|
76
|
-
getDeploymentMetadata
|
|
80
|
+
getDeploymentMetadata,
|
|
81
|
+
getSnapshotTs
|
|
77
82
|
};
|
|
78
83
|
}
|
|
79
84
|
function setupMutationMeta(visibility) {
|
|
@@ -85,7 +90,8 @@ function setupMutationMeta(visibility) {
|
|
|
85
90
|
}),
|
|
86
91
|
getTransactionMetrics,
|
|
87
92
|
getDeploymentMetadata,
|
|
88
|
-
getRequestMetadata
|
|
93
|
+
getRequestMetadata,
|
|
94
|
+
getSnapshotTs
|
|
89
95
|
};
|
|
90
96
|
}
|
|
91
97
|
function setupActionMeta(visibility) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/server/impl/meta_impl.ts"],
|
|
4
|
-
"sourcesContent": ["import { jsonToConvex } from \"../../values/index.js\";\nimport {\n ActionMeta,\n MutationMeta,\n QueryMeta,\n RequestMetadata,\n FunctionMetadata,\n TransactionMetrics,\n DeploymentMetadata,\n} from \"../meta.js\";\nimport { performAsyncSyscall } from \"./syscall.js\";\n\nasync function getTransactionMetrics(): Promise<TransactionMetrics> {\n let syscallJSON;\n try {\n syscallJSON = await performAsyncSyscall(\"1.0/getTransactionMetrics\", {});\n } catch (e: any) {\n if (e.message?.includes(\"Unknown async operation\")) {\n throw new Error(\n \"getTransactionMetrics() can only be called from a query or mutation. \" +\n \"It is not available in actions or outside of a Convex function.\",\n );\n }\n throw e;\n }\n return jsonToConvex(syscallJSON) as any;\n}\n\nasync function getFunctionMetadata(): Promise<{\n name: string;\n componentPath: string;\n}> {\n const { name, componentPath } = await performAsyncSyscall(\n \"1.0/getFunctionMetadata\",\n {},\n );\n return {\n name,\n componentPath,\n };\n}\n\nasync function getDeploymentMetadata(): Promise<DeploymentMetadata> {\n const syscallJSON = await performAsyncSyscall(\n \"1.0/getDeploymentMetadata\",\n {},\n );\n const result = jsonToConvex(syscallJSON) as any;\n return {\n name: result.name,\n region: result.region ?? null,\n class: result.class,\n };\n}\n\nasync function getRequestMetadata(): Promise<RequestMetadata> {\n const { ip, userAgent, requestId, scheduledFunctionId, authToken } =\n await performAsyncSyscall(\"1.0/getRequestMetadata\", {});\n return { ip, userAgent, requestId, scheduledFunctionId, authToken };\n}\n\nexport function setupQueryMeta(\n visibility: FunctionMetadata[\"visibility\"],\n): QueryMeta {\n return {\n getFunctionMetadata: async () => ({\n ...(await getFunctionMetadata()),\n type: \"query\",\n visibility,\n }),\n getTransactionMetrics,\n getDeploymentMetadata,\n };\n}\n\nexport function setupMutationMeta(\n visibility: FunctionMetadata[\"visibility\"],\n): MutationMeta {\n return {\n getFunctionMetadata: async () => ({\n ...(await getFunctionMetadata()),\n type: \"mutation\",\n visibility,\n }),\n getTransactionMetrics,\n getDeploymentMetadata,\n getRequestMetadata,\n };\n}\n\nexport function setupActionMeta(\n visibility: FunctionMetadata[\"visibility\"],\n): ActionMeta {\n return {\n getFunctionMetadata: async () => ({\n ...(await getFunctionMetadata()),\n type: \"action\",\n visibility,\n }),\n getDeploymentMetadata,\n getRequestMetadata,\n };\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA6B;AAU7B,
|
|
4
|
+
"sourcesContent": ["import { jsonToConvex } from \"../../values/index.js\";\nimport {\n ActionMeta,\n MutationMeta,\n QueryMeta,\n RequestMetadata,\n FunctionMetadata,\n TransactionMetrics,\n DeploymentMetadata,\n} from \"../meta.js\";\nimport { performAsyncSyscall, performSyscall } from \"./syscall.js\";\n\nasync function getTransactionMetrics(): Promise<TransactionMetrics> {\n let syscallJSON;\n try {\n syscallJSON = await performAsyncSyscall(\"1.0/getTransactionMetrics\", {});\n } catch (e: any) {\n if (e.message?.includes(\"Unknown async operation\")) {\n throw new Error(\n \"getTransactionMetrics() can only be called from a query or mutation. \" +\n \"It is not available in actions or outside of a Convex function.\",\n );\n }\n throw e;\n }\n return jsonToConvex(syscallJSON) as any;\n}\n\nasync function getFunctionMetadata(): Promise<{\n name: string;\n componentPath: string;\n}> {\n const { name, componentPath } = await performAsyncSyscall(\n \"1.0/getFunctionMetadata\",\n {},\n );\n return {\n name,\n componentPath,\n };\n}\n\nasync function getDeploymentMetadata(): Promise<DeploymentMetadata> {\n const syscallJSON = await performAsyncSyscall(\n \"1.0/getDeploymentMetadata\",\n {},\n );\n const result = jsonToConvex(syscallJSON) as any;\n return {\n name: result.name,\n region: result.region ?? null,\n class: result.class,\n };\n}\n\nfunction getSnapshotTs(): bigint {\n const syscallJSON = performSyscall(\"1.0/getSnapshotTs\", {});\n return jsonToConvex(syscallJSON) as bigint;\n}\n\nasync function getRequestMetadata(): Promise<RequestMetadata> {\n const { ip, userAgent, requestId, scheduledFunctionId, authToken } =\n await performAsyncSyscall(\"1.0/getRequestMetadata\", {});\n return { ip, userAgent, requestId, scheduledFunctionId, authToken };\n}\n\nexport function setupQueryMeta(\n visibility: FunctionMetadata[\"visibility\"],\n): QueryMeta {\n return {\n getFunctionMetadata: async () => ({\n ...(await getFunctionMetadata()),\n type: \"query\",\n visibility,\n }),\n getTransactionMetrics,\n getDeploymentMetadata,\n getSnapshotTs,\n };\n}\n\nexport function setupMutationMeta(\n visibility: FunctionMetadata[\"visibility\"],\n): MutationMeta {\n return {\n getFunctionMetadata: async () => ({\n ...(await getFunctionMetadata()),\n type: \"mutation\",\n visibility,\n }),\n getTransactionMetrics,\n getDeploymentMetadata,\n getRequestMetadata,\n getSnapshotTs,\n };\n}\n\nexport function setupActionMeta(\n visibility: FunctionMetadata[\"visibility\"],\n): ActionMeta {\n return {\n getFunctionMetadata: async () => ({\n ...(await getFunctionMetadata()),\n type: \"action\",\n visibility,\n }),\n getDeploymentMetadata,\n getRequestMetadata,\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA6B;AAU7B,qBAAoD;AAEpD,eAAe,wBAAqD;AAClE,MAAI;AACJ,MAAI;AACF,kBAAc,UAAM,oCAAoB,6BAA6B,CAAC,CAAC;AAAA,EACzE,SAA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A,MAChC,GAAI,MAAM,oBAAoB;AAAA,MAC9B,MAAM;AAAA,MACN;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/server/impl/scheduler_impl.ts"],
|
|
4
|
-
"sourcesContent": ["import { convexToJson, Value } from \"../../values/index.js\";\nimport { version } from \"../../index.js\";\nimport { performAsyncSyscall } from \"./syscall.js\";\nimport { parseArgs } from \"../../common/index.js\";\nimport { SchedulableFunctionReference, Scheduler } from \"../scheduler.js\";\nimport { Id } from \"../../values/value.js\";\nimport { validateArg } from \"./validate.js\";\nimport { getFunctionAddress } from \"../components/paths.js\";\n\nexport function setupMutationScheduler(): Scheduler {\n return {\n runAfter: async (\n delayMs: number,\n functionReference:
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAoC;AACpC,eAAwB;AACxB,qBAAoC;AACpC,oBAA0B;
|
|
4
|
+
"sourcesContent": ["import { convexToJson, Value } from \"../../values/index.js\";\nimport { version } from \"../../index.js\";\nimport { performAsyncSyscall } from \"./syscall.js\";\nimport { parseArgs } from \"../../common/index.js\";\nimport { SchedulableFunctionReference, Scheduler } from \"../scheduler.js\";\nimport { FunctionReference_future } from \"../api.js\";\nimport { Id } from \"../../values/value.js\";\nimport { validateArg } from \"./validate.js\";\nimport { getFunctionAddress } from \"../components/paths.js\";\n\n// Mirrors the constraint on `Scheduler.runAfter` and `Scheduler.runAt`, which\n// is module-local to `scheduler.ts`.\ntype SchedulableFunctionReferenceCompat =\n | SchedulableFunctionReference\n | FunctionReference_future<\"mutation\" | \"action\", \"public\" | \"internal\">;\n\nexport function setupMutationScheduler(): Scheduler {\n return {\n runAfter: async (\n delayMs: number,\n functionReference: SchedulableFunctionReferenceCompat,\n args?: Record<string, Value>,\n ) => {\n const syscallArgs = runAfterSyscallArgs(delayMs, functionReference, args);\n return await performAsyncSyscall(\"1.0/schedule\", syscallArgs);\n },\n runAt: async (\n ms_since_epoch_or_date: number | Date,\n functionReference: SchedulableFunctionReferenceCompat,\n args?: Record<string, Value>,\n ) => {\n const syscallArgs = runAtSyscallArgs(\n ms_since_epoch_or_date,\n functionReference,\n args,\n );\n return await performAsyncSyscall(\"1.0/schedule\", syscallArgs);\n },\n cancel: async (id: Id<\"_scheduled_functions\">) => {\n validateArg(id, 1, \"cancel\", \"id\");\n const args = { id: convexToJson(id) };\n await performAsyncSyscall(\"1.0/cancel_job\", args);\n },\n };\n}\n\nexport function setupActionScheduler(requestId: string): Scheduler {\n return {\n runAfter: async (\n delayMs: number,\n functionReference: SchedulableFunctionReferenceCompat,\n args?: Record<string, Value>,\n ) => {\n const syscallArgs = {\n requestId,\n ...runAfterSyscallArgs(delayMs, functionReference, args),\n };\n return await performAsyncSyscall(\"1.0/actions/schedule\", syscallArgs);\n },\n runAt: async (\n ms_since_epoch_or_date: number | Date,\n functionReference: SchedulableFunctionReferenceCompat,\n args?: Record<string, Value>,\n ) => {\n const syscallArgs = {\n requestId,\n ...runAtSyscallArgs(ms_since_epoch_or_date, functionReference, args),\n };\n return await performAsyncSyscall(\"1.0/actions/schedule\", syscallArgs);\n },\n cancel: async (id: Id<\"_scheduled_functions\">) => {\n validateArg(id, 1, \"cancel\", \"id\");\n const syscallArgs = {\n requestId,\n id: convexToJson(id),\n };\n return await performAsyncSyscall(\"1.0/actions/cancel_job\", syscallArgs);\n },\n };\n}\n\nfunction runAfterSyscallArgs(\n delayMs: number,\n functionReference: SchedulableFunctionReferenceCompat,\n args?: Record<string, Value>,\n) {\n if (typeof delayMs !== \"number\") {\n throw new Error(\"`delayMs` must be a number\");\n }\n if (!isFinite(delayMs)) {\n throw new Error(\"`delayMs` must be a finite number\");\n }\n if (delayMs < 0) {\n throw new Error(\"`delayMs` must be non-negative\");\n }\n const functionArgs = parseArgs(args);\n const address = getFunctionAddress(functionReference);\n // Note the syscall expects a unix timestamp, measured in seconds.\n const ts = (Date.now() + delayMs) / 1000.0;\n return {\n ...address,\n ts,\n args: convexToJson(functionArgs),\n version,\n };\n}\n\nfunction runAtSyscallArgs(\n ms_since_epoch_or_date: number | Date,\n functionReference: SchedulableFunctionReferenceCompat,\n args?: Record<string, Value>,\n) {\n let ts;\n if (ms_since_epoch_or_date instanceof Date) {\n ts = ms_since_epoch_or_date.valueOf() / 1000.0;\n } else if (typeof ms_since_epoch_or_date === \"number\") {\n // The timestamp the developer passes is in milliseconds, while the syscall\n // accepts seconds since the epoch.\n ts = ms_since_epoch_or_date / 1000;\n } else {\n throw new Error(\"The invoke time must a Date or a timestamp\");\n }\n const address = getFunctionAddress(functionReference);\n const functionArgs = parseArgs(args);\n return {\n ...address,\n ts,\n args: convexToJson(functionArgs),\n version,\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAoC;AACpC,eAAwB;AACxB,qBAAoC;AACpC,oBAA0B;AAI1B,sBAA4B;AAC5B,mBAAmC;AAQ5B,SAAS,yBAAoC;AAClD,SAAO;AAAA,IACL,UAAU,OACR,SACA,mBACA,SACG;AACH,YAAM,cAAc,oBAAoB,SAAS,mBAAmB,IAAI;AACxE,aAAO,UAAM,oCAAoB,gBAAgB,WAAW;AAAA,IAC9D;AAAA,IACA,OAAO,OACL,wBACA,mBACA,SACG;AACH,YAAM,cAAc;AAAA,QAClB;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,aAAO,UAAM,oCAAoB,gBAAgB,WAAW;AAAA,IAC9D;AAAA,IACA,QAAQ,OAAO,OAAmC;AAChD,uCAAY,IAAI,GAAG,UAAU,IAAI;AACjC,YAAM,OAAO,EAAE,QAAI,4BAAa,EAAE,EAAE;AACpC,gBAAM,oCAAoB,kBAAkB,IAAI;AAAA,IAClD;AAAA,E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K,yBAAyB;AAAA,EAChC,OAAO;AACL,UAAM,IAAI,MAAM,4CAA4C;AAAA,EAC9D;AACA,QAAM,cAAU,iCAAmB,iBAAiB;AACpD,QAAM,mBAAe,yBAAU,IAAI;AACnC,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA,UAAM,4BAAa,YAAY;AAAA,IAC/B;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/server/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Utilities for implementing server-side Convex query and mutation functions.\n *\n * ## Usage\n *\n * ### Code Generation\n *\n * This module is typically used alongside generated server code.\n *\n * To generate the server code, run `npx convex dev` in your Convex project.\n * This will create a `convex/_generated/server.js` file with the following\n * functions, typed for your schema:\n * - [query](https://docs.convex.dev/generated-api/server#query)\n * - [mutation](https://docs.convex.dev/generated-api/server#mutation)\n *\n * If you aren't using TypeScript and code generation, you can use these untyped\n * functions instead:\n * - {@link queryGeneric}\n * - {@link mutationGeneric}\n *\n * ### Example\n *\n * Convex functions are defined by using either the `query` or\n * `mutation` wrappers.\n *\n * Queries receive a `db` that implements the {@link GenericDatabaseReader} interface.\n *\n * ```js\n * import { query } from \"./_generated/server\";\n *\n * export default query({\n * handler: async ({ db }, { arg1, arg2 }) => {\n * // Your (read-only) code here!\n * },\n * });\n * ```\n *\n * If your function needs to write to the database, such as inserting, updating,\n * or deleting documents, use `mutation` instead which provides a `db` that\n * implements the {@link GenericDatabaseWriter} interface.\n *\n * ```js\n * import { mutation } from \"./_generated/server\";\n *\n * export default mutation({\n * handler: async ({ db }, { arg1, arg2 }) => {\n * // Your mutation code here!\n * },\n * });\n * ```\n * @module\n */\n\nexport type {\n Auth,\n AuthConfig,\n AuthProvider,\n UserIdentity,\n UserIdentityAttributes,\n} from \"./authentication.js\";\nexport * from \"./database.js\";\nexport type {\n GenericDocument,\n GenericFieldPaths,\n GenericIndexFields,\n GenericTableIndexes,\n GenericSearchIndexConfig,\n GenericTableSearchIndexes,\n GenericVectorIndexConfig,\n GenericTableVectorIndexes,\n FieldTypeFromFieldPath,\n FieldTypeFromFieldPathInner,\n GenericTableInfo,\n DocumentByInfo,\n FieldPaths,\n Indexes,\n IndexNames,\n NamedIndex,\n SearchIndexes,\n SearchIndexNames,\n NamedSearchIndex,\n VectorIndexes,\n VectorIndexNames,\n NamedVectorIndex,\n GenericDataModel,\n AnyDataModel,\n TableNamesInDataModel,\n NamedTableInfo,\n DocumentByName,\n} from \"./data_model.js\";\n\nexport type {\n Expression,\n ExpressionOrValue,\n FilterBuilder,\n} from \"./filter_builder.js\";\nexport {\n actionGeneric,\n httpActionGeneric,\n mutationGeneric,\n queryGeneric,\n internalActionGeneric,\n internalMutationGeneric,\n internalQueryGeneric,\n} from \"./impl/registration_impl.js\";\nexport { getServiceToken } from \"./impl/actions_impl.js\";\nexport type {\n TransactionMetric,\n TransactionMetrics,\n TransactionLimits,\n FunctionMetadata,\n DeploymentMetadata,\n RequestMetadata,\n QueryMeta,\n MutationMeta,\n ActionMeta,\n} from \"./meta.js\";\nexport type { IndexRange, IndexRangeBuilder } from \"./index_range_builder.js\";\nexport * from \"./pagination.js\";\nexport type { OrderedQuery, Query, QueryInitializer } from \"./query.js\";\nexport type {\n AdvancedRunQueryOptions,\n ArgsArray,\n DefaultFunctionArgs,\n FunctionVisibility,\n ActionBuilder,\n MutationBuilder,\n MutationBuilderWithTable,\n QueryBuilder,\n QueryBuilderWithTable,\n HttpActionBuilder,\n GenericActionCtx,\n GenericMutationCtx,\n GenericMutationCtxWithTable,\n GenericQueryCtx,\n GenericQueryCtxWithTable,\n RegisteredAction,\n RegisteredMutation,\n RegisteredQuery,\n PublicHttpAction,\n UnvalidatedFunction,\n ValidatedFunction,\n ReturnValueForOptionalValidator,\n ArgsArrayForOptionalValidator,\n ArgsArrayToObject,\n DefaultArgsForOptionalValidator,\n} from \"./registration.js\";\nexport * from \"./search_filter_builder.js\";\nexport * from \"./storage.js\";\nexport type { Scheduler, SchedulableFunctionReference } from \"./scheduler.js\";\nexport { cronJobs } from \"./cron.js\";\nexport type { CronJob, Crons } from \"./cron.js\";\nexport type {\n SystemFields,\n IdField,\n WithoutSystemFields,\n WithOptionalSystemFields,\n SystemIndexes,\n IndexTiebreakerField,\n} from \"./system_fields.js\";\nexport { httpRouter, HttpRouter, ROUTABLE_HTTP_METHODS } from \"./router.js\";\nexport type {\n RoutableMethod,\n RouteSpec,\n RouteSpecWithPath,\n RouteSpecWithPathPrefix,\n} from \"./router.js\";\nexport {\n anyApi,\n getFunctionName,\n makeFunctionReference,\n filterApi,\n} from \"./api.js\";\nexport type {\n ApiFromModules,\n AnyApi,\n FilterApi,\n FunctionType,\n FunctionReference,\n FunctionArgs,\n OptionalRestArgs,\n PartialApi,\n ArgsAndOptions,\n FunctionReturnType,\n ValidatorTypeToReturnType,\n} from \"./api.js\";\nexport {\n defineApp,\n defineComponent,\n componentsGeneric,\n createFunctionHandle,\n type AnyChildComponents,\n type EnvDefinition,\n type EnvFromDefinition,\n type EnvFromAppDefinition,\n type AppDefinition,\n} from \"./components/index.js\";\n/**\n * @internal\n */\nexport { currentSystemUdfInComponent } from \"./components/index.js\";\nexport { getFunctionAddress } from \"./components/index.js\";\nexport type {\n ComponentDefinition,\n AnyComponents,\n FunctionHandle,\n} from \"./components/index.js\";\n\n/**\n * @internal\n */\nexport type { Index, SearchIndex, VectorIndex } from \"./schema.js\";\n\nexport { log } from \"./log.js\";\nexport type { AuditLogBody, AuditLogValue } from \"./audit_logging.js\";\n\nexport type {\n SearchIndexConfig,\n VectorIndexConfig,\n TableDefinition,\n SchemaDefinition,\n DefineSchemaOptions,\n GenericSchema,\n DataModelFromSchemaDefinition,\n SystemDataModel,\n SystemTableNames,\n DocValidator,\n SystemFieldValidators,\n} from \"./schema.js\";\nexport { defineTable, defineSchema, docValidator } from \"./schema.js\";\n\nexport type {\n VectorSearch,\n VectorSearchQuery,\n VectorFilterBuilder,\n FilterExpression,\n} from \"./vector_search.js\";\n\n/**\n * @public\n */\nexport type { BetterOmit, Expand } from \"../type_utils.js\";\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;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;AA4DA,2BAAc,0BA5Dd;AAgGA,+BAQO;AACP,0BAAgC;AAahC,2BAAc,4BAtHd;AAmJA,2BAAc,uCAnJd;AAoJA,2BAAc,yBApJd;AAsJA,kBAAyB;AAUzB,oBAA8D;AAO9D,iBAKO;
|
|
4
|
+
"sourcesContent": ["/**\n * Utilities for implementing server-side Convex query and mutation functions.\n *\n * ## Usage\n *\n * ### Code Generation\n *\n * This module is typically used alongside generated server code.\n *\n * To generate the server code, run `npx convex dev` in your Convex project.\n * This will create a `convex/_generated/server.js` file with the following\n * functions, typed for your schema:\n * - [query](https://docs.convex.dev/generated-api/server#query)\n * - [mutation](https://docs.convex.dev/generated-api/server#mutation)\n *\n * If you aren't using TypeScript and code generation, you can use these untyped\n * functions instead:\n * - {@link queryGeneric}\n * - {@link mutationGeneric}\n *\n * ### Example\n *\n * Convex functions are defined by using either the `query` or\n * `mutation` wrappers.\n *\n * Queries receive a `db` that implements the {@link GenericDatabaseReader} interface.\n *\n * ```js\n * import { query } from \"./_generated/server\";\n *\n * export default query({\n * handler: async ({ db }, { arg1, arg2 }) => {\n * // Your (read-only) code here!\n * },\n * });\n * ```\n *\n * If your function needs to write to the database, such as inserting, updating,\n * or deleting documents, use `mutation` instead which provides a `db` that\n * implements the {@link GenericDatabaseWriter} interface.\n *\n * ```js\n * import { mutation } from \"./_generated/server\";\n *\n * export default mutation({\n * handler: async ({ db }, { arg1, arg2 }) => {\n * // Your mutation code here!\n * },\n * });\n * ```\n * @module\n */\n\nexport type {\n Auth,\n AuthConfig,\n AuthProvider,\n UserIdentity,\n UserIdentityAttributes,\n} from \"./authentication.js\";\nexport * from \"./database.js\";\nexport type {\n GenericDocument,\n GenericFieldPaths,\n GenericIndexFields,\n GenericTableIndexes,\n GenericSearchIndexConfig,\n GenericTableSearchIndexes,\n GenericVectorIndexConfig,\n GenericTableVectorIndexes,\n FieldTypeFromFieldPath,\n FieldTypeFromFieldPathInner,\n GenericTableInfo,\n DocumentByInfo,\n FieldPaths,\n Indexes,\n IndexNames,\n NamedIndex,\n SearchIndexes,\n SearchIndexNames,\n NamedSearchIndex,\n VectorIndexes,\n VectorIndexNames,\n NamedVectorIndex,\n GenericDataModel,\n AnyDataModel,\n TableNamesInDataModel,\n NamedTableInfo,\n DocumentByName,\n} from \"./data_model.js\";\n\nexport type {\n Expression,\n ExpressionOrValue,\n FilterBuilder,\n} from \"./filter_builder.js\";\nexport {\n actionGeneric,\n httpActionGeneric,\n mutationGeneric,\n queryGeneric,\n internalActionGeneric,\n internalMutationGeneric,\n internalQueryGeneric,\n} from \"./impl/registration_impl.js\";\nexport { getServiceToken } from \"./impl/actions_impl.js\";\nexport type {\n TransactionMetric,\n TransactionMetrics,\n TransactionLimits,\n FunctionMetadata,\n DeploymentMetadata,\n RequestMetadata,\n QueryMeta,\n MutationMeta,\n ActionMeta,\n} from \"./meta.js\";\nexport type { IndexRange, IndexRangeBuilder } from \"./index_range_builder.js\";\nexport * from \"./pagination.js\";\nexport type { OrderedQuery, Query, QueryInitializer } from \"./query.js\";\nexport type {\n AdvancedRunQueryOptions,\n ArgsArray,\n DefaultFunctionArgs,\n FunctionVisibility,\n ActionBuilder,\n MutationBuilder,\n MutationBuilderWithTable,\n QueryBuilder,\n QueryBuilderWithTable,\n HttpActionBuilder,\n GenericActionCtx,\n GenericMutationCtx,\n GenericMutationCtxWithTable,\n GenericQueryCtx,\n GenericQueryCtxWithTable,\n RegisteredAction,\n RegisteredMutation,\n RegisteredQuery,\n PublicHttpAction,\n UnvalidatedFunction,\n ValidatedFunction,\n ReturnValueForOptionalValidator,\n ArgsArrayForOptionalValidator,\n ArgsArrayToObject,\n DefaultArgsForOptionalValidator,\n} from \"./registration.js\";\nexport * from \"./search_filter_builder.js\";\nexport * from \"./storage.js\";\nexport type { Scheduler, SchedulableFunctionReference } from \"./scheduler.js\";\nexport { cronJobs } from \"./cron.js\";\nexport type { CronJob, Crons } from \"./cron.js\";\nexport type {\n SystemFields,\n IdField,\n WithoutSystemFields,\n WithOptionalSystemFields,\n SystemIndexes,\n IndexTiebreakerField,\n} from \"./system_fields.js\";\nexport { httpRouter, HttpRouter, ROUTABLE_HTTP_METHODS } from \"./router.js\";\nexport type {\n RoutableMethod,\n RouteSpec,\n RouteSpecWithPath,\n RouteSpecWithPathPrefix,\n} from \"./router.js\";\nexport {\n anyApi,\n getFunctionName,\n makeFunctionReference,\n filterApi,\n} from \"./api.js\";\nexport type {\n ApiFromModules,\n AnyApi,\n FunctionReference_future,\n FilterApi,\n FunctionType,\n FunctionReference,\n FunctionArgs,\n OptionalRestArgs,\n PartialApi,\n ArgsAndOptions,\n FunctionReturnType,\n ValidatorTypeToReturnType,\n} from \"./api.js\";\nexport {\n defineApp,\n defineComponent,\n componentsGeneric,\n createFunctionHandle,\n type AnyChildComponents,\n type EnvDefinition,\n type EnvFromDefinition,\n type EnvFromAppDefinition,\n type AppDefinition,\n} from \"./components/index.js\";\n/**\n * @internal\n */\nexport { currentSystemUdfInComponent } from \"./components/index.js\";\nexport { getFunctionAddress } from \"./components/index.js\";\nexport type {\n ComponentDefinition,\n AnyComponents,\n FunctionHandle,\n} from \"./components/index.js\";\n\n/**\n * @internal\n */\nexport type { Index, SearchIndex, VectorIndex } from \"./schema.js\";\n\nexport { log } from \"./log.js\";\nexport type { AuditLogBody, AuditLogValue } from \"./audit_logging.js\";\n\nexport type {\n SearchIndexConfig,\n VectorIndexConfig,\n TableDefinition,\n SchemaDefinition,\n DefineSchemaOptions,\n GenericSchema,\n DataModelFromSchemaDefinition,\n SystemDataModel,\n SystemTableNames,\n DocValidator,\n SystemFieldValidators,\n} from \"./schema.js\";\nexport { defineTable, defineSchema, docValidator } from \"./schema.js\";\n\nexport type {\n VectorSearch,\n VectorSearchQuery,\n VectorFilterBuilder,\n FilterExpression,\n} from \"./vector_search.js\";\n\n/**\n * @public\n */\nexport type { BetterOmit, Expand } from \"../type_utils.js\";\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;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;AA4DA,2BAAc,0BA5Dd;AAgGA,+BAQO;AACP,0BAAgC;AAahC,2BAAc,4BAtHd;AAmJA,2BAAc,uCAnJd;AAoJA,2BAAc,yBApJd;AAsJA,kBAAyB;AAUzB,oBAA8D;AAO9D,iBAKO;AAeP,wBAUO;AAIP,IAAAA,qBAA4C;AAC5C,IAAAA,qBAAmC;AAYnC,iBAAoB;AAgBpB,oBAAwD;",
|
|
6
6
|
"names": ["import_components"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/server/meta.ts"],
|
|
4
|
-
"sourcesContent": ["import { FunctionType } from \"./api.js\";\nimport { FunctionVisibility } from \"./registration.js\";\n\n/**\n * Used and remaining amounts for a single transaction limit.\n *\n * @public\n */\nexport type TransactionMetric = {\n used: number;\n remaining: number;\n};\n\n/**\n * The remaining headroom for a transaction before hitting limits.\n *\n * See https://docs.convex.dev/production/state/limits\n *\n * @public\n */\nexport type TransactionMetrics = {\n bytesRead: TransactionMetric;\n bytesWritten: TransactionMetric;\n databaseQueries: TransactionMetric;\n documentsRead: TransactionMetric;\n documentsWritten: TransactionMetric;\n functionsScheduled: TransactionMetric;\n scheduledFunctionArgsBytes: TransactionMetric;\n};\n\n/**\n * Custom limits for a nested transaction. Each field specifies the absolute\n * maximum allowed for the nested function call. Values are capped at the\n * global transaction limits, so they can only lower limits, never raise them.\n *\n * @public\n */\nexport interface TransactionLimits {\n bytesRead?: number;\n bytesWritten?: number;\n databaseQueries?: number;\n documentsRead?: number;\n documentsWritten?: number;\n functionsScheduled?: number;\n scheduledFunctionArgsBytes?: number;\n}\n\n/**\n * Metadata about the currently executing Convex function.\n *\n * @public\n */\nexport type FunctionMetadata = {\n /**\n * The name of the function, in the format `\"path/to/module:functionName\"`\n */\n name: string;\n /**\n * The path of the component this function belongs to.\n * This is an empty string `\"\"` for the app.\n */\n componentPath: string;\n /** Whether it's a query, mutation, or action. */\n type: FunctionType;\n /** Whether the function is public or internal. */\n visibility: FunctionVisibility;\n};\n\n/**\n * Metadata about the deployment this function is running on.\n *\n * @public\n */\nexport type DeploymentMetadata = {\n /**\n * The deployment name, e.g. `\"tall-tiger-123\"` for cloud deployments,\n * `\"local-my_team-my_project\"` for local deployments, or\n * `\"anonymous-*\"` for anonymous deployments.\n */\n name: string;\n /**\n * The deployment region, e.g. `\"aws-us-east-1\"`.\n * `null` for local and self-hosted deployments.\n */\n region: string | null;\n /**\n * The deployment class, e.g. `\"s16\"`, `\"s256\"`, `\"d1024\"`, or `\"d2048\"`.\n */\n class: \"s16\" | \"s256\" | \"d1024\" | \"d2048\";\n};\n\n/**\n * Metadata about the HTTP request that triggered the current function execution.\n *\n * `ip` and `userAgent` are `null` when the function was not triggered by an\n * HTTP request (e.g. scheduled jobs or cron jobs).\n *\n * Functions called from within a function (i.e. using `runMutation` or\n * `runAction`) will have the same request metadata as the parent function.\n *\n * @public\n */\nexport type RequestMetadata = {\n ip: string | null;\n userAgent: string | null;\n requestId: string;\n /**\n * The ID of the scheduled function document (in `_scheduled_functions`) that\n * this execution belongs to, or `null` otherwise.\n *\n * This is set for the scheduled function itself and for any functions it\n * calls (e.g. a mutation invoked via `runMutation` by a scheduled action),\n * propagating the top-level scheduled function's ID down the call tree. It is\n * `null` when the function was not scheduled.\n */\n scheduledFunctionId: string | null;\n /**\n * The raw auth token (a JWT) the request was authenticated with, or `null`\n * when the request was unauthenticated or authenticated with an admin key.\n *\n * This is the same token that `ctx.auth.getUserIdentity()` derives its\n * attributes from.\n */\n authToken: string | null;\n};\n\n/**\n * Extra context available in Convex query functions.\n *\n * @public\n */\nexport interface QueryMeta {\n getFunctionMetadata(): Promise<FunctionMetadata>;\n getTransactionMetrics(): Promise<TransactionMetrics>;\n getDeploymentMetadata(): Promise<DeploymentMetadata>;\n}\n\n/**\n * Extra context available in Convex mutation functions.\n *\n * @public\n */\nexport interface MutationMeta extends QueryMeta {\n getRequestMetadata(): Promise<RequestMetadata>;\n}\n\n/**\n * Extra context available in Convex action functions.\n *\n * @public\n */\nexport interface ActionMeta {\n getFunctionMetadata(): Promise<FunctionMetadata>;\n getDeploymentMetadata(): Promise<DeploymentMetadata>;\n getRequestMetadata(): Promise<RequestMetadata>;\n}\n"],
|
|
4
|
+
"sourcesContent": ["import { FunctionType } from \"./api.js\";\nimport { FunctionVisibility } from \"./registration.js\";\n\n/**\n * Used and remaining amounts for a single transaction limit.\n *\n * @public\n */\nexport type TransactionMetric = {\n used: number;\n remaining: number;\n};\n\n/**\n * The remaining headroom for a transaction before hitting limits.\n *\n * See https://docs.convex.dev/production/state/limits\n *\n * @public\n */\nexport type TransactionMetrics = {\n bytesRead: TransactionMetric;\n bytesWritten: TransactionMetric;\n databaseQueries: TransactionMetric;\n documentsRead: TransactionMetric;\n documentsWritten: TransactionMetric;\n functionsScheduled: TransactionMetric;\n scheduledFunctionArgsBytes: TransactionMetric;\n};\n\n/**\n * Custom limits for a nested transaction. Each field specifies the absolute\n * maximum allowed for the nested function call. Values are capped at the\n * global transaction limits, so they can only lower limits, never raise them.\n *\n * @public\n */\nexport interface TransactionLimits {\n bytesRead?: number;\n bytesWritten?: number;\n databaseQueries?: number;\n documentsRead?: number;\n documentsWritten?: number;\n functionsScheduled?: number;\n scheduledFunctionArgsBytes?: number;\n}\n\n/**\n * Metadata about the currently executing Convex function.\n *\n * @public\n */\nexport type FunctionMetadata = {\n /**\n * The name of the function, in the format `\"path/to/module:functionName\"`\n */\n name: string;\n /**\n * The path of the component this function belongs to.\n * This is an empty string `\"\"` for the app.\n */\n componentPath: string;\n /** Whether it's a query, mutation, or action. */\n type: FunctionType;\n /** Whether the function is public or internal. */\n visibility: FunctionVisibility;\n};\n\n/**\n * Metadata about the deployment this function is running on.\n *\n * @public\n */\nexport type DeploymentMetadata = {\n /**\n * The deployment name, e.g. `\"tall-tiger-123\"` for cloud deployments,\n * `\"local-my_team-my_project\"` for local deployments, or\n * `\"anonymous-*\"` for anonymous deployments.\n */\n name: string;\n /**\n * The deployment region, e.g. `\"aws-us-east-1\"`.\n * `null` for local and self-hosted deployments.\n */\n region: string | null;\n /**\n * The deployment class, e.g. `\"s16\"`, `\"s256\"`, `\"d1024\"`, or `\"d2048\"`.\n */\n class: \"s16\" | \"s256\" | \"d1024\" | \"d2048\";\n};\n\n/**\n * Metadata about the HTTP request that triggered the current function execution.\n *\n * `ip` and `userAgent` are `null` when the function was not triggered by an\n * HTTP request (e.g. scheduled jobs or cron jobs).\n *\n * Functions called from within a function (i.e. using `runMutation` or\n * `runAction`) will have the same request metadata as the parent function.\n *\n * @public\n */\nexport type RequestMetadata = {\n ip: string | null;\n userAgent: string | null;\n requestId: string;\n /**\n * The ID of the scheduled function document (in `_scheduled_functions`) that\n * this execution belongs to, or `null` otherwise.\n *\n * This is set for the scheduled function itself and for any functions it\n * calls (e.g. a mutation invoked via `runMutation` by a scheduled action),\n * propagating the top-level scheduled function's ID down the call tree. It is\n * `null` when the function was not scheduled.\n */\n scheduledFunctionId: string | null;\n /**\n * The raw auth token (a JWT) the request was authenticated with, or `null`\n * when the request was unauthenticated or authenticated with an admin key.\n *\n * This is the same token that `ctx.auth.getUserIdentity()` derives its\n * attributes from.\n */\n authToken: string | null;\n};\n\n/**\n * Extra context available in Convex query functions.\n *\n * @public\n */\nexport interface QueryMeta {\n getFunctionMetadata(): Promise<FunctionMetadata>;\n getTransactionMetrics(): Promise<TransactionMetrics>;\n getDeploymentMetadata(): Promise<DeploymentMetadata>;\n /**\n * @internal\n * Returns the timestamp of the database snapshot this transaction reads\n * from, in nanoseconds.\n *\n * All commits at or before this timestamp are observable within the\n * transaction, and no later commits are. The value is fixed for the\n * lifetime of the transaction and shared with all nested `runMutation` and\n * `runQuery` calls.\n *\n * It is on the same clock as `db.vars.commitTs`: documents observable in\n * this transaction have `commitTs` values at or before this timestamp, and\n * no new documents will be written with a `commitTs` at or below this,\n * including from the current transaction. When reading documents with an\n * index in commitTs order, you can use this as an upper bound to prevent\n * conflicting with racing inserts.\n *\n * Since the timestamp differs on every execution, calling this in a query\n * limits caching of the query's result the same way `Date.now()` does.\n *\n * Note: this should not be compared to `_creationTime` or `Date.now()`, as\n * those are based on wall-clock time rather than the database clock, and\n * aren't guaranteed to follow commit order.\n */\n getSnapshotTs(): bigint;\n}\n\n/**\n * Extra context available in Convex mutation functions.\n *\n * @public\n */\nexport interface MutationMeta extends QueryMeta {\n getRequestMetadata(): Promise<RequestMetadata>;\n}\n\n/**\n * Extra context available in Convex action functions.\n *\n * @public\n */\nexport interface ActionMeta {\n getFunctionMetadata(): Promise<FunctionMetadata>;\n getDeploymentMetadata(): Promise<DeploymentMetadata>;\n getRequestMetadata(): Promise<RequestMetadata>;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|