convex 1.42.2 → 1.43.0-alpha.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 +8 -1
- package/bin/main-dev +6 -1
- package/dist/browser.bundle.js +49 -10
- package/dist/browser.bundle.js.map +2 -2
- package/dist/cjs/browser/index.js.map +2 -2
- package/dist/cjs/browser/simple_client-node.js +35 -35
- package/dist/cjs/browser/simple_client-node.js.map +2 -2
- package/dist/cjs/browser/sync/client.js.map +1 -1
- package/dist/cjs/browser/sync/paginated_query_client.js +20 -9
- package/dist/cjs/browser/sync/paginated_query_client.js.map +2 -2
- package/dist/cjs/cli/codegen_templates/component_api.js +2 -2
- package/dist/cjs/cli/codegen_templates/component_api.js.map +2 -2
- package/dist/cjs/cli/codegen_templates/validator_helpers.js +2 -0
- package/dist/cjs/cli/codegen_templates/validator_helpers.js.map +2 -2
- package/dist/cjs/cli/deployment.js +2 -1
- package/dist/cjs/cli/deployment.js.map +2 -2
- package/dist/cjs/cli/deploymentCreate.js.map +2 -2
- package/dist/cjs/cli/generatedApi.js.map +1 -1
- package/dist/cjs/cli/lib/deployApi/validator.js +1 -0
- package/dist/cjs/cli/lib/deployApi/validator.js.map +2 -2
- package/dist/cjs/cli/lib/deploymentSelection.js.map +2 -2
- package/dist/cjs/cli/lib/generateDocs.js +1 -1
- package/dist/cjs/cli/lib/generateDocs.js.map +2 -2
- package/dist/cjs/cli/lib/generatedFunctionLogsApi.js.map +1 -1
- package/dist/cjs/cli/lib/localDeployment/projectMismatch.js.map +2 -2
- package/dist/cjs/cli/lib/login.js +23 -23
- package/dist/cjs/cli/lib/login.js.map +2 -2
- package/dist/cjs/cli/lib/typecheck.js +28 -25
- package/dist/cjs/cli/lib/typecheck.js.map +2 -2
- package/dist/cjs/cli/lib/usageLimits.js +164 -0
- package/dist/cjs/cli/lib/usageLimits.js.map +7 -0
- package/dist/cjs/cli/usageLimits.js +326 -0
- package/dist/cjs/cli/usageLimits.js.map +7 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/react/client.js.map +2 -2
- package/dist/cjs/server/components/index.js.map +2 -2
- package/dist/cjs/server/cron.js +33 -29
- package/dist/cjs/server/cron.js.map +2 -2
- package/dist/cjs/server/database.js.map +1 -1
- package/dist/cjs/server/impl/database_impl.js +3 -0
- package/dist/cjs/server/impl/database_impl.js.map +2 -2
- package/dist/cjs/server/log.js +2 -1
- package/dist/cjs/server/log.js.map +2 -2
- package/dist/cjs/server/logVars.js +12 -1
- package/dist/cjs/server/logVars.js.map +2 -2
- package/dist/cjs/server/meta.js.map +1 -1
- package/dist/cjs/values/compare.js +5 -1
- package/dist/cjs/values/compare.js.map +2 -2
- package/dist/cjs/values/index.js +1 -0
- package/dist/cjs/values/index.js.map +2 -2
- package/dist/cjs/values/size.js +4 -0
- package/dist/cjs/values/size.js.map +2 -2
- package/dist/cjs/values/validator.js +11 -0
- package/dist/cjs/values/validator.js.map +2 -2
- package/dist/cjs/values/validators.js +20 -0
- package/dist/cjs/values/validators.js.map +2 -2
- package/dist/cjs/values/value.js +31 -0
- package/dist/cjs/values/value.js.map +2 -2
- package/dist/cjs-types/browser/index.d.ts.map +1 -1
- package/dist/cjs-types/browser/sync/paginated_query_client.d.ts +1 -38
- package/dist/cjs-types/browser/sync/paginated_query_client.d.ts.map +1 -1
- package/dist/cjs-types/cli/codegen_templates/component_api.d.ts.map +1 -1
- package/dist/cjs-types/cli/codegen_templates/validator_helpers.d.ts.map +1 -1
- package/dist/cjs-types/cli/codegen_templates/validator_helpers.test.d.ts +2 -0
- package/dist/cjs-types/cli/codegen_templates/validator_helpers.test.d.ts.map +1 -0
- package/dist/cjs-types/cli/deployment.d.ts.map +1 -1
- package/dist/cjs-types/cli/deploymentCreate.d.ts +2 -2
- package/dist/cjs-types/cli/generatedApi.d.ts +43 -43
- package/dist/cjs-types/cli/generatedApi.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/deployApi/validator.d.ts +6 -0
- package/dist/cjs-types/cli/lib/deployApi/validator.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/deploymentSelection.d.ts +2 -2
- package/dist/cjs-types/cli/lib/deploymentSelection.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/generatedFunctionLogsApi.d.ts +45 -45
- package/dist/cjs-types/cli/lib/generatedFunctionLogsApi.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/localDeployment/projectMismatch.d.ts +2 -2
- package/dist/cjs-types/cli/lib/localDeployment/projectMismatch.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/login.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/mcp/tools/insights.d.ts +24 -24
- package/dist/cjs-types/cli/lib/typecheck.d.ts +2 -0
- package/dist/cjs-types/cli/lib/typecheck.d.ts.map +1 -1
- package/dist/cjs-types/cli/lib/typecheck.test.d.ts +2 -0
- package/dist/cjs-types/cli/lib/typecheck.test.d.ts.map +1 -0
- package/dist/cjs-types/cli/lib/usageLimits.d.ts +46 -0
- package/dist/cjs-types/cli/lib/usageLimits.d.ts.map +1 -0
- package/dist/cjs-types/cli/usageLimits.d.ts +22 -0
- package/dist/cjs-types/cli/usageLimits.d.ts.map +1 -0
- package/dist/cjs-types/index.d.ts +1 -1
- package/dist/cjs-types/index.d.ts.map +1 -1
- package/dist/cjs-types/react/client.d.ts.map +1 -1
- package/dist/cjs-types/server/components/index.d.ts +26 -8
- package/dist/cjs-types/server/components/index.d.ts.map +1 -1
- package/dist/cjs-types/server/cron.d.ts +20 -11
- package/dist/cjs-types/server/cron.d.ts.map +1 -1
- package/dist/cjs-types/server/cron.test.d.ts +2 -0
- package/dist/cjs-types/server/cron.test.d.ts.map +1 -0
- package/dist/cjs-types/server/database.d.ts.map +1 -1
- package/dist/cjs-types/server/impl/database_impl.d.ts.map +1 -1
- package/dist/cjs-types/server/log.d.ts.map +1 -1
- package/dist/cjs-types/server/logVars.d.ts +14 -1
- package/dist/cjs-types/server/logVars.d.ts.map +1 -1
- package/dist/cjs-types/server/meta.d.ts +2 -2
- package/dist/cjs-types/server/meta.d.ts.map +1 -1
- package/dist/cjs-types/values/compare.d.ts.map +1 -1
- package/dist/cjs-types/values/index.d.ts +2 -2
- package/dist/cjs-types/values/index.d.ts.map +1 -1
- package/dist/cjs-types/values/size.d.ts +1 -1
- package/dist/cjs-types/values/size.d.ts.map +1 -1
- package/dist/cjs-types/values/validator.d.ts +10 -1
- package/dist/cjs-types/values/validator.d.ts.map +1 -1
- package/dist/cjs-types/values/validators.d.ts +14 -3
- package/dist/cjs-types/values/validators.d.ts.map +1 -1
- package/dist/cjs-types/values/value.d.ts +18 -1
- package/dist/cjs-types/values/value.d.ts.map +1 -1
- package/dist/cli.bundle.cjs +2327 -1866
- package/dist/cli.bundle.cjs.map +4 -4
- package/dist/esm/browser/index.js.map +2 -2
- package/dist/esm/browser/simple_client-node.js +35 -35
- package/dist/esm/browser/simple_client-node.js.map +1 -1
- package/dist/esm/browser/sync/client.js.map +1 -1
- package/dist/esm/browser/sync/paginated_query_client.js +20 -9
- package/dist/esm/browser/sync/paginated_query_client.js.map +2 -2
- package/dist/esm/cli/codegen_templates/component_api.js +8 -3
- package/dist/esm/cli/codegen_templates/component_api.js.map +2 -2
- package/dist/esm/cli/codegen_templates/validator_helpers.js +2 -0
- package/dist/esm/cli/codegen_templates/validator_helpers.js.map +2 -2
- package/dist/esm/cli/deployment.js +2 -1
- package/dist/esm/cli/deployment.js.map +2 -2
- package/dist/esm/cli/deploymentCreate.js.map +2 -2
- package/dist/esm/cli/lib/deployApi/validator.js +1 -0
- package/dist/esm/cli/lib/deployApi/validator.js.map +2 -2
- package/dist/esm/cli/lib/deploymentSelection.js.map +2 -2
- package/dist/esm/cli/lib/generateDocs.js +1 -1
- package/dist/esm/cli/lib/generateDocs.js.map +2 -2
- package/dist/esm/cli/lib/localDeployment/projectMismatch.js.map +2 -2
- package/dist/esm/cli/lib/login.js +23 -23
- package/dist/esm/cli/lib/login.js.map +2 -2
- package/dist/esm/cli/lib/typecheck.js +27 -25
- package/dist/esm/cli/lib/typecheck.js.map +2 -2
- package/dist/esm/cli/lib/usageLimits.js +129 -0
- package/dist/esm/cli/lib/usageLimits.js.map +7 -0
- package/dist/esm/cli/usageLimits.js +316 -0
- package/dist/esm/cli/usageLimits.js.map +7 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/react/client.js.map +2 -2
- package/dist/esm/server/components/index.js.map +2 -2
- package/dist/esm/server/cron.js +33 -29
- package/dist/esm/server/cron.js.map +2 -2
- package/dist/esm/server/impl/database_impl.js +4 -1
- package/dist/esm/server/impl/database_impl.js.map +2 -2
- package/dist/esm/server/log.js +3 -2
- package/dist/esm/server/log.js.map +2 -2
- package/dist/esm/server/logVars.js +11 -1
- package/dist/esm/server/logVars.js.map +2 -2
- package/dist/esm/values/compare.js +5 -1
- package/dist/esm/values/compare.js.map +2 -2
- package/dist/esm/values/index.js +1 -1
- package/dist/esm/values/index.js.map +2 -2
- package/dist/esm/values/size.js +4 -0
- package/dist/esm/values/size.js.map +2 -2
- package/dist/esm/values/validator.js +12 -0
- package/dist/esm/values/validator.js.map +2 -2
- package/dist/esm/values/validators.js +19 -0
- package/dist/esm/values/validators.js.map +2 -2
- package/dist/esm/values/value.js +29 -1
- package/dist/esm/values/value.js.map +2 -2
- package/dist/esm-types/browser/index.d.ts.map +1 -1
- package/dist/esm-types/browser/sync/paginated_query_client.d.ts +1 -38
- package/dist/esm-types/browser/sync/paginated_query_client.d.ts.map +1 -1
- package/dist/esm-types/cli/codegen_templates/component_api.d.ts.map +1 -1
- package/dist/esm-types/cli/codegen_templates/validator_helpers.d.ts.map +1 -1
- package/dist/esm-types/cli/codegen_templates/validator_helpers.test.d.ts +2 -0
- package/dist/esm-types/cli/codegen_templates/validator_helpers.test.d.ts.map +1 -0
- package/dist/esm-types/cli/deployment.d.ts.map +1 -1
- package/dist/esm-types/cli/deploymentCreate.d.ts +2 -2
- package/dist/esm-types/cli/generatedApi.d.ts +43 -43
- package/dist/esm-types/cli/generatedApi.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/deployApi/validator.d.ts +6 -0
- package/dist/esm-types/cli/lib/deployApi/validator.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/deploymentSelection.d.ts +2 -2
- package/dist/esm-types/cli/lib/deploymentSelection.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/generatedFunctionLogsApi.d.ts +45 -45
- package/dist/esm-types/cli/lib/generatedFunctionLogsApi.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/localDeployment/projectMismatch.d.ts +2 -2
- package/dist/esm-types/cli/lib/localDeployment/projectMismatch.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/login.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/mcp/tools/insights.d.ts +24 -24
- package/dist/esm-types/cli/lib/typecheck.d.ts +2 -0
- package/dist/esm-types/cli/lib/typecheck.d.ts.map +1 -1
- package/dist/esm-types/cli/lib/typecheck.test.d.ts +2 -0
- package/dist/esm-types/cli/lib/typecheck.test.d.ts.map +1 -0
- package/dist/esm-types/cli/lib/usageLimits.d.ts +46 -0
- package/dist/esm-types/cli/lib/usageLimits.d.ts.map +1 -0
- package/dist/esm-types/cli/usageLimits.d.ts +22 -0
- package/dist/esm-types/cli/usageLimits.d.ts.map +1 -0
- package/dist/esm-types/index.d.ts +1 -1
- package/dist/esm-types/index.d.ts.map +1 -1
- package/dist/esm-types/react/client.d.ts.map +1 -1
- package/dist/esm-types/server/components/index.d.ts +26 -8
- package/dist/esm-types/server/components/index.d.ts.map +1 -1
- package/dist/esm-types/server/cron.d.ts +20 -11
- package/dist/esm-types/server/cron.d.ts.map +1 -1
- package/dist/esm-types/server/cron.test.d.ts +2 -0
- package/dist/esm-types/server/cron.test.d.ts.map +1 -0
- package/dist/esm-types/server/database.d.ts.map +1 -1
- package/dist/esm-types/server/impl/database_impl.d.ts.map +1 -1
- package/dist/esm-types/server/log.d.ts.map +1 -1
- package/dist/esm-types/server/logVars.d.ts +14 -1
- package/dist/esm-types/server/logVars.d.ts.map +1 -1
- package/dist/esm-types/server/meta.d.ts +2 -2
- package/dist/esm-types/server/meta.d.ts.map +1 -1
- package/dist/esm-types/values/compare.d.ts.map +1 -1
- package/dist/esm-types/values/index.d.ts +2 -2
- package/dist/esm-types/values/index.d.ts.map +1 -1
- package/dist/esm-types/values/size.d.ts +1 -1
- package/dist/esm-types/values/size.d.ts.map +1 -1
- package/dist/esm-types/values/validator.d.ts +10 -1
- package/dist/esm-types/values/validator.d.ts.map +1 -1
- package/dist/esm-types/values/validators.d.ts +14 -3
- package/dist/esm-types/values/validators.d.ts.map +1 -1
- package/dist/esm-types/values/value.d.ts +18 -1
- package/dist/esm-types/values/value.d.ts.map +1 -1
- package/dist/react.bundle.js +53 -11
- package/dist/react.bundle.js.map +2 -2
- package/package.json +8 -8
- package/schemas/convex.schema.json +2 -1
- package/src/browser/index.ts +2 -0
- package/src/browser/sync/client.test.ts +8 -1
- package/src/browser/sync/client.ts +63 -0
- package/src/browser/sync/paginated_query_client.test.ts +209 -1
- package/src/browser/sync/paginated_query_client.ts +29 -11
- package/src/cli/codegen_templates/component_api.ts +8 -3
- package/src/cli/codegen_templates/validator_helpers.test.ts +31 -0
- package/src/cli/codegen_templates/validator_helpers.ts +6 -0
- package/src/cli/deployment.ts +4 -1
- package/src/cli/deploymentCreate.test.ts +2 -2
- package/src/cli/deploymentCreate.ts +2 -2
- package/src/cli/generatedApi.ts +43 -43
- package/src/cli/lib/deployApi/validator.ts +1 -0
- package/src/cli/lib/deploymentSelection.ts +2 -2
- package/src/cli/lib/generateDocs.test.ts +1 -1
- package/src/cli/lib/generateDocs.ts +3 -3
- package/src/cli/lib/generatedFunctionLogsApi.ts +45 -45
- package/src/cli/lib/localDeployment/projectMismatch.ts +2 -2
- package/src/cli/lib/login.ts +33 -30
- package/src/cli/lib/typecheck.test.ts +71 -0
- package/src/cli/lib/typecheck.ts +33 -27
- package/src/cli/lib/usageLimits.ts +242 -0
- package/src/cli/usageLimits.ts +420 -0
- package/src/index.ts +1 -1
- package/src/react/ConvexAuthState.test.tsx +24 -8
- package/src/react/auth_websocket.test.tsx +39 -29
- package/src/react/client.ts +3 -2
- package/src/react/client_provided_base_client.test.tsx +154 -36
- package/src/server/audit_logging.test.ts +2 -0
- package/src/server/components/index.test.ts +33 -1
- package/src/server/components/index.ts +41 -14
- package/src/server/cron.test.ts +58 -0
- package/src/server/cron.ts +82 -21
- package/src/server/database.ts +17 -0
- package/src/server/impl/database_impl.ts +4 -1
- package/src/server/log.ts +4 -1
- package/src/server/logVars.ts +17 -1
- package/src/server/meta.ts +2 -2
- package/src/server/schema.test.ts +6 -1
- package/src/values/compare.ts +5 -2
- package/src/values/index.ts +2 -1
- package/src/values/size.test.ts +5 -0
- package/src/values/size.ts +5 -1
- package/src/values/validator.test.ts +16 -1
- package/src/values/validator.ts +13 -0
- package/src/values/validators.ts +29 -1
- package/src/values/value.test.ts +35 -0
- package/src/values/value.ts +56 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/values/validators.ts"],
|
|
4
|
-
"sourcesContent": ["import { Expand } from \"../type_utils.js\";\nimport { GenericId } from \"./index.js\";\nimport { GenericValidator, ObjectType } from \"./validator.js\";\nimport { JSONValue, convexToJson } from \"./value.js\";\n\ntype TableNameFromType<T> =\n T extends GenericId<infer TableName> ? TableName : string;\n\nconst UNDEFINED_VALIDATOR_ERROR_URL =\n \"https://docs.convex.dev/error#undefined-validator\";\n\nfunction throwUndefinedValidatorError(\n context: string,\n fieldName?: string,\n): never {\n const fieldInfo = fieldName !== undefined ? ` for field \"${fieldName}\"` : \"\";\n throw new Error(\n `A validator is undefined${fieldInfo} in ${context}. ` +\n `This is often caused by circular imports. ` +\n `See ${UNDEFINED_VALIDATOR_ERROR_URL} for details.`,\n );\n}\n\n/**\n * Avoid using `instanceof BaseValidator`; this is inheritence for code reuse\n * not type heirarchy.\n */\nabstract class BaseValidator<\n Type,\n IsOptional extends OptionalProperty = \"required\",\n FieldPaths extends string = never,\n> {\n /**\n * Only for TypeScript, the TS type of the JS values validated\n * by this validator.\n */\n readonly type!: Type;\n /**\n * Only for TypeScript, if this an Object validator, then\n * this is the TS type of its property names.\n */\n readonly fieldPaths!: FieldPaths;\n\n /**\n * Whether this is an optional Object property value validator.\n */\n readonly isOptional: IsOptional;\n\n /**\n * Always `\"true\"`.\n */\n readonly isConvexValidator: true;\n\n constructor({ isOptional }: { isOptional: IsOptional }) {\n this.isOptional = isOptional;\n this.isConvexValidator = true;\n }\n /** @internal */\n abstract get json(): ValidatorJSON;\n /** @internal */\n abstract asOptional(): Validator<Type | undefined, \"optional\", FieldPaths>;\n}\n\n/**\n * The type of the `v.id(tableName)` validator.\n */\nexport class VId<\n Type,\n IsOptional extends OptionalProperty = \"required\",\n> extends BaseValidator<Type, IsOptional> {\n /**\n * The name of the table that the validated IDs must belong to.\n */\n readonly tableName: TableNameFromType<Type>;\n\n /**\n * The kind of validator, `\"id\"`.\n */\n readonly kind = \"id\" as const;\n\n /**\n * Usually you'd use `v.id(tableName)` instead.\n */\n constructor({\n isOptional,\n tableName,\n }: {\n isOptional: IsOptional;\n tableName: TableNameFromType<Type>;\n }) {\n super({ isOptional });\n if (typeof tableName !== \"string\") {\n throw new Error(\"v.id(tableName) requires a string\");\n }\n this.tableName = tableName;\n }\n /** @internal */\n get json(): ValidatorJSON {\n return { type: \"id\", tableName: this.tableName };\n }\n /** @internal */\n asOptional() {\n return new VId<Type | undefined, \"optional\">({\n isOptional: \"optional\",\n tableName: this.tableName,\n });\n }\n}\n\n/**\n * The type of the `v.float64()` validator.\n */\nexport class VFloat64<\n Type = number,\n IsOptional extends OptionalProperty = \"required\",\n> extends BaseValidator<Type, IsOptional> {\n /**\n * The kind of validator, `\"float64\"`.\n */\n readonly kind = \"float64\" as const;\n\n /** @internal */\n get json(): ValidatorJSON {\n // Server expects the old name `number` string instead of `float64`.\n return { type: \"number\" };\n }\n /** @internal */\n asOptional() {\n return new VFloat64<Type | undefined, \"optional\">({\n isOptional: \"optional\",\n });\n }\n}\n\n/**\n * The type of the `v.int64()` validator.\n */\nexport class VInt64<\n Type = bigint,\n IsOptional extends OptionalProperty = \"required\",\n> extends BaseValidator<Type, IsOptional> {\n /**\n * The kind of validator, `\"int64\"`.\n */\n readonly kind = \"int64\" as const;\n\n /** @internal */\n get json(): ValidatorJSON {\n // Server expects the old name `bigint`.\n return { type: \"bigint\" };\n }\n /** @internal */\n asOptional() {\n return new VInt64<Type | undefined, \"optional\">({ isOptional: \"optional\" });\n }\n}\n\n/**\n * The type of the `v.boolean()` validator.\n */\nexport class VBoolean<\n Type = boolean,\n IsOptional extends OptionalProperty = \"required\",\n> extends BaseValidator<Type, IsOptional> {\n /**\n * The kind of validator, `\"boolean\"`.\n */\n readonly kind = \"boolean\" as const;\n\n /** @internal */\n get json(): ValidatorJSON {\n return { type: this.kind };\n }\n /** @internal */\n asOptional() {\n return new VBoolean<Type | undefined, \"optional\">({\n isOptional: \"optional\",\n });\n }\n}\n\n/**\n * The type of the `v.bytes()` validator.\n */\nexport class VBytes<\n Type = ArrayBuffer,\n IsOptional extends OptionalProperty = \"required\",\n> extends BaseValidator<Type, IsOptional> {\n /**\n * The kind of validator, `\"bytes\"`.\n */\n readonly kind = \"bytes\" as const;\n\n /** @internal */\n get json(): ValidatorJSON {\n return { type: this.kind };\n }\n /** @internal */\n asOptional() {\n return new VBytes<Type | undefined, \"optional\">({ isOptional: \"optional\" });\n }\n}\n\n/**\n * The type of the `v.string()` validator.\n */\nexport class VString<\n Type = string,\n IsOptional extends OptionalProperty = \"required\",\n> extends BaseValidator<Type, IsOptional> {\n /**\n * The kind of validator, `\"string\"`.\n */\n readonly kind = \"string\" as const;\n\n /** @internal */\n get json(): ValidatorJSON {\n return { type: this.kind };\n }\n /** @internal */\n asOptional() {\n return new VString<Type | undefined, \"optional\">({\n isOptional: \"optional\",\n });\n }\n}\n\n/**\n * The type of the `v.null()` validator.\n */\nexport class VNull<\n Type = null,\n IsOptional extends OptionalProperty = \"required\",\n> extends BaseValidator<Type, IsOptional> {\n /**\n * The kind of validator, `\"null\"`.\n */\n readonly kind = \"null\" as const;\n\n /** @internal */\n get json(): ValidatorJSON {\n return { type: this.kind };\n }\n /** @internal */\n asOptional() {\n return new VNull<Type | undefined, \"optional\">({ isOptional: \"optional\" });\n }\n}\n\n/**\n * The type of the `v.any()` validator.\n */\nexport class VAny<\n Type = any,\n IsOptional extends OptionalProperty = \"required\",\n FieldPaths extends string = string,\n> extends BaseValidator<Type, IsOptional, FieldPaths> {\n /**\n * The kind of validator, `\"any\"`.\n */\n readonly kind = \"any\" as const;\n\n /** @internal */\n get json(): ValidatorJSON {\n return {\n type: this.kind,\n };\n }\n /** @internal */\n asOptional() {\n return new VAny<Type | undefined, \"optional\", FieldPaths>({\n isOptional: \"optional\",\n });\n }\n}\n\n/**\n * The type of the `v.object()` validator.\n */\nexport class VObject<\n Type,\n Fields extends Record<string, GenericValidator>,\n IsOptional extends OptionalProperty = \"required\",\n FieldPaths extends string = {\n [Property in keyof Fields]:\n | JoinFieldPaths<Property & string, Fields[Property][\"fieldPaths\"]>\n | Property;\n }[keyof Fields] &\n string,\n> extends BaseValidator<Type, IsOptional, FieldPaths> {\n /**\n * An object with the validator for each property.\n */\n readonly fields: Fields;\n\n /**\n * The kind of validator, `\"object\"`.\n */\n readonly kind = \"object\" as const;\n\n /**\n * Usually you'd use `v.object({ ... })` instead.\n */\n constructor({\n isOptional,\n fields,\n }: {\n isOptional: IsOptional;\n fields: Fields;\n }) {\n super({ isOptional });\n globalThis.Object.entries(fields).forEach(([fieldName, validator]) => {\n if (validator === undefined) {\n throwUndefinedValidatorError(\"v.object()\", fieldName);\n }\n if (!validator.isConvexValidator) {\n throw new Error(\"v.object() entries must be validators\");\n }\n });\n this.fields = fields;\n }\n /** @internal */\n get json(): ValidatorJSON {\n return {\n type: this.kind,\n value: globalThis.Object.fromEntries(\n globalThis.Object.entries(this.fields).map(([k, v]) => [\n k,\n {\n fieldType: v.json,\n optional: v.isOptional === \"optional\" ? true : false,\n },\n ]),\n ),\n };\n }\n /** @internal */\n asOptional() {\n return new VObject<Type | undefined, Fields, \"optional\", FieldPaths>({\n isOptional: \"optional\",\n fields: this.fields,\n });\n }\n\n /**\n * Create a new VObject with the specified fields omitted.\n * @param fields The field names to omit from this VObject.\n */\n omit<K extends keyof Fields & string>(\n ...fields: K[]\n ): VObject<Expand<Omit<Type, K>>, Expand<Omit<Fields, K>>, IsOptional> {\n const newFields = { ...this.fields };\n for (const field of fields) {\n delete newFields[field];\n }\n return new VObject({\n isOptional: this.isOptional,\n fields: newFields as any,\n });\n }\n\n /**\n * Create a new VObject with only the specified fields.\n * @param fields The field names to pick from this VObject.\n */\n pick<K extends keyof Fields & string>(\n ...fields: K[]\n ): VObject<\n Expand<Pick<Type, Extract<keyof Type, K>>>,\n Expand<Pick<Fields, K>>,\n IsOptional\n > {\n const newFields: Record<string, GenericValidator> = {};\n for (const field of fields) {\n newFields[field] = this.fields[field];\n }\n return new VObject({\n isOptional: this.isOptional,\n fields: newFields as Expand<Pick<Fields, K>>,\n });\n }\n\n /**\n * Create a new VObject with all fields marked as optional.\n */\n partial(): VObject<\n { [K in keyof Type]?: Type[K] },\n { [K in keyof Fields]: VOptional<Fields[K]> },\n IsOptional\n > {\n const newFields: Record<string, GenericValidator> = {};\n for (const [key, validator] of globalThis.Object.entries(this.fields)) {\n newFields[key] = validator.asOptional();\n }\n return new VObject({\n isOptional: this.isOptional,\n fields: newFields as {\n [K in keyof Fields]: VOptional<Fields[K]>;\n },\n });\n }\n\n /**\n * Create a new VObject with additional fields merged in.\n * @param fields An object with additional validators to merge into this VObject.\n */\n extend<NewFields extends Record<string, GenericValidator>>(\n fields: NewFields,\n ): VObject<\n Expand<Type & ObjectType<NewFields>>,\n Expand<Fields & NewFields>,\n IsOptional\n > {\n return new VObject({\n isOptional: this.isOptional,\n fields: { ...this.fields, ...fields } as Expand<Fields & NewFields>,\n });\n }\n}\n\n/**\n * The type of the `v.literal()` validator.\n */\nexport class VLiteral<\n Type,\n IsOptional extends OptionalProperty = \"required\",\n> extends BaseValidator<Type, IsOptional> {\n /**\n * The value that the validated values must be equal to.\n */\n readonly value: Type;\n\n /**\n * The kind of validator, `\"literal\"`.\n */\n readonly kind = \"literal\" as const;\n\n /**\n * Usually you'd use `v.literal(value)` instead.\n */\n constructor({ isOptional, value }: { isOptional: IsOptional; value: Type }) {\n super({ isOptional });\n if (\n typeof value !== \"string\" &&\n typeof value !== \"boolean\" &&\n typeof value !== \"number\" &&\n typeof value !== \"bigint\"\n ) {\n throw new Error(\"v.literal(value) must be a string, number, or boolean\");\n }\n this.value = value;\n }\n /** @internal */\n get json(): ValidatorJSON {\n return {\n type: this.kind,\n value: convexToJson(this.value as string | boolean | number | bigint),\n };\n }\n /** @internal */\n asOptional() {\n return new VLiteral<Type | undefined, \"optional\">({\n isOptional: \"optional\",\n value: this.value,\n });\n }\n}\n\n/**\n * The type of the `v.array()` validator.\n */\nexport class VArray<\n Type,\n Element extends Validator<any, \"required\", any>,\n IsOptional extends OptionalProperty = \"required\",\n> extends BaseValidator<Type, IsOptional> {\n /**\n * The validator for the elements of the array.\n */\n readonly element: Element;\n\n /**\n * The kind of validator, `\"array\"`.\n */\n readonly kind = \"array\" as const;\n\n /**\n * Usually you'd use `v.array(element)` instead.\n */\n constructor({\n isOptional,\n element,\n }: {\n isOptional: IsOptional;\n element: Element;\n }) {\n super({ isOptional });\n if (element === undefined) {\n throwUndefinedValidatorError(\"v.array()\");\n }\n this.element = element;\n }\n /** @internal */\n get json(): ValidatorJSON {\n return {\n type: this.kind,\n value: this.element.json,\n };\n }\n /** @internal */\n asOptional() {\n return new VArray<Type | undefined, Element, \"optional\">({\n isOptional: \"optional\",\n element: this.element,\n });\n }\n}\n\n/**\n * The type of the `v.record()` validator.\n */\nexport class VRecord<\n Type,\n Key extends Validator<string, \"required\", any>,\n Value extends Validator<any, \"required\", any>,\n IsOptional extends OptionalProperty = \"required\",\n FieldPaths extends string = string,\n> extends BaseValidator<Type, IsOptional, FieldPaths> {\n /**\n * The validator for the keys of the record.\n */\n readonly key: Key;\n\n /**\n * The validator for the values of the record.\n */\n readonly value: Value;\n\n /**\n * The kind of validator, `\"record\"`.\n */\n readonly kind = \"record\" as const;\n\n /**\n * Usually you'd use `v.record(key, value)` instead.\n */\n constructor({\n isOptional,\n key,\n value,\n }: {\n isOptional: IsOptional;\n key: Key;\n value: Value;\n }) {\n super({ isOptional });\n if (key === undefined) {\n throwUndefinedValidatorError(\"v.record()\", \"key\");\n }\n if (value === undefined) {\n throwUndefinedValidatorError(\"v.record()\", \"value\");\n }\n if ((key.isOptional as OptionalProperty) === \"optional\") {\n throw new Error(\"Record validator cannot have optional keys\");\n }\n if ((value.isOptional as OptionalProperty) === \"optional\") {\n throw new Error(\"Record validator cannot have optional values\");\n }\n if (!key.isConvexValidator || !value.isConvexValidator) {\n throw new Error(\"Key and value of v.record() but be validators\");\n }\n this.key = key;\n this.value = value;\n }\n /** @internal */\n get json(): ValidatorJSON {\n return {\n type: this.kind,\n // This cast is needed because TypeScript thinks the key type is too wide\n keys: this.key.json as RecordKeyValidatorJSON,\n values: {\n fieldType: this.value.json,\n optional: false,\n },\n };\n }\n /** @internal */\n asOptional() {\n return new VRecord<Type | undefined, Key, Value, \"optional\", FieldPaths>({\n isOptional: \"optional\",\n key: this.key,\n value: this.value,\n });\n }\n}\n\n/**\n * The type of the `v.union()` validator.\n */\nexport class VUnion<\n Type,\n T extends Validator<any, \"required\", any>[],\n IsOptional extends OptionalProperty = \"required\",\n FieldPaths extends string = T[number][\"fieldPaths\"],\n> extends BaseValidator<Type, IsOptional, FieldPaths> {\n /**\n * The array of validators, one of which must match the value.\n */\n readonly members: T;\n\n /**\n * The kind of validator, `\"union\"`.\n */\n readonly kind = \"union\" as const;\n\n /**\n * Usually you'd use `v.union(...members)` instead.\n */\n constructor({ isOptional, members }: { isOptional: IsOptional; members: T }) {\n super({ isOptional });\n members.forEach((member, index) => {\n if (member === undefined) {\n throwUndefinedValidatorError(\"v.union()\", `member at index ${index}`);\n }\n if (!member.isConvexValidator) {\n throw new Error(\"All members of v.union() must be validators\");\n }\n });\n this.members = members;\n }\n /** @internal */\n get json(): ValidatorJSON {\n return {\n type: this.kind,\n value: this.members.map((v) => v.json),\n };\n }\n /** @internal */\n asOptional() {\n return new VUnion<Type | undefined, T, \"optional\">({\n isOptional: \"optional\",\n members: this.members,\n });\n }\n}\n\n// prettier-ignore\nexport type VOptional<T extends Validator<any, OptionalProperty, any>> =\n T extends VId<infer Type, OptionalProperty> ? VId<Type | undefined, \"optional\">\n : T extends VString<infer Type, OptionalProperty>\n ? VString<Type | undefined, \"optional\">\n : T extends VFloat64<infer Type, OptionalProperty>\n ? VFloat64<Type | undefined, \"optional\">\n : T extends VInt64<infer Type, OptionalProperty>\n ? VInt64<Type | undefined, \"optional\">\n : T extends VBoolean<infer Type, OptionalProperty>\n ? VBoolean<Type | undefined, \"optional\">\n : T extends VNull<infer Type, OptionalProperty>\n ? VNull<Type | undefined, \"optional\">\n : T extends VAny<infer Type, OptionalProperty>\n ? VAny<Type | undefined, \"optional\">\n : T extends VLiteral<infer Type, OptionalProperty>\n ? VLiteral<Type | undefined, \"optional\">\n : T extends VBytes<infer Type, OptionalProperty>\n ? VBytes<Type | undefined, \"optional\">\n : T extends VObject< infer Type, infer Fields, OptionalProperty, infer FieldPaths>\n ? VObject<Type | undefined, Fields, \"optional\", FieldPaths>\n : T extends VArray<infer Type, infer Element, OptionalProperty>\n ? VArray<Type | undefined, Element, \"optional\">\n : T extends VRecord< infer Type, infer Key, infer Value, OptionalProperty, infer FieldPaths>\n ? VRecord<Type | undefined, Key, Value, \"optional\", FieldPaths>\n : T extends VUnion<infer Type, infer Members, OptionalProperty, infer FieldPaths>\n ? VUnion<Type | undefined, Members, \"optional\", FieldPaths>\n : never\n\n/**\n * Type representing whether a property in an object is optional or required.\n *\n * @public\n */\nexport type OptionalProperty = \"optional\" | \"required\";\n\n/**\n * A validator for a Convex value.\n *\n * This should be constructed using the validator builder, {@link v}.\n *\n * A validator encapsulates:\n * - The TypeScript type of this value.\n * - Whether this field should be optional if it's included in an object.\n * - The TypeScript type for the set of index field paths that can be used to\n * build indexes on this value.\n * - A JSON representation of the validator.\n *\n * Specific types of validators contain additional information: for example\n * an `ArrayValidator` contains an `element` property with the validator\n * used to validate each element of the list. Use the shared 'kind' property\n * to identity the type of validator.\n *\n * More validators can be added in future releases so an exhaustive\n * switch statement on validator `kind` should be expected to break\n * in future releases of Convex.\n *\n * @public\n */\nexport type Validator<\n Type,\n IsOptional extends OptionalProperty = \"required\",\n FieldPaths extends string = never,\n> =\n | VId<Type, IsOptional>\n | VString<Type, IsOptional>\n | VFloat64<Type, IsOptional>\n | VInt64<Type, IsOptional>\n | VBoolean<Type, IsOptional>\n | VNull<Type, IsOptional>\n | VAny<Type, IsOptional>\n | VLiteral<Type, IsOptional>\n | VBytes<Type, IsOptional>\n | VObject<\n Type,\n Record<string, Validator<any, OptionalProperty, any>>,\n IsOptional,\n FieldPaths\n >\n | VArray<Type, Validator<any, \"required\", any>, IsOptional>\n | VRecord<\n Type,\n Validator<string, \"required\", any>,\n Validator<any, \"required\", any>,\n IsOptional,\n FieldPaths\n >\n | VUnion<Type, Validator<any, \"required\", any>[], IsOptional, FieldPaths>;\n\n/**\n * Join together two index field paths.\n *\n * This is used within the validator builder, {@link v}.\n * @public\n */\nexport type JoinFieldPaths<\n Start extends string,\n End extends string,\n> = `${Start}.${End}`;\n\nexport type ObjectFieldType = { fieldType: ValidatorJSON; optional: boolean };\n\nexport type ValidatorJSON =\n | { type: \"null\" }\n | { type: \"number\" }\n | { type: \"bigint\" }\n | { type: \"boolean\" }\n | { type: \"string\" }\n | { type: \"bytes\" }\n | { type: \"any\" }\n | { type: \"literal\"; value: JSONValue }\n | { type: \"id\"; tableName: string }\n | { type: \"array\"; value: ValidatorJSON }\n | {\n type: \"record\";\n keys: RecordKeyValidatorJSON;\n values: RecordValueValidatorJSON;\n }\n | { type: \"object\"; value: Record<string, ObjectFieldType> }\n | { type: \"union\"; value: ValidatorJSON[] };\n\nexport type RecordKeyValidatorJSON =\n | { type: \"string\" }\n | { type: \"id\"; tableName: string }\n | { type: \"union\"; value: RecordKeyValidatorJSON[] };\n\nexport type RecordValueValidatorJSON = ObjectFieldType & { optional: false };\n"],
|
|
5
|
-
"mappings": ";;;;AAGA,
|
|
4
|
+
"sourcesContent": ["import { Expand } from \"../type_utils.js\";\nimport { GenericId } from \"./index.js\";\nimport { GenericValidator, ObjectType } from \"./validator.js\";\nimport { CommitTsPlaceholder, JSONValue, convexToJson } from \"./value.js\";\n\ntype TableNameFromType<T> =\n T extends GenericId<infer TableName> ? TableName : string;\n\nconst UNDEFINED_VALIDATOR_ERROR_URL =\n \"https://docs.convex.dev/error#undefined-validator\";\n\nfunction throwUndefinedValidatorError(\n context: string,\n fieldName?: string,\n): never {\n const fieldInfo = fieldName !== undefined ? ` for field \"${fieldName}\"` : \"\";\n throw new Error(\n `A validator is undefined${fieldInfo} in ${context}. ` +\n `This is often caused by circular imports. ` +\n `See ${UNDEFINED_VALIDATOR_ERROR_URL} for details.`,\n );\n}\n\n/**\n * Avoid using `instanceof BaseValidator`; this is inheritence for code reuse\n * not type heirarchy.\n */\nabstract class BaseValidator<\n Type,\n IsOptional extends OptionalProperty = \"required\",\n FieldPaths extends string = never,\n> {\n /**\n * Only for TypeScript, the TS type of the JS values validated\n * by this validator.\n */\n readonly type!: Type;\n /**\n * Only for TypeScript, if this an Object validator, then\n * this is the TS type of its property names.\n */\n readonly fieldPaths!: FieldPaths;\n\n /**\n * Whether this is an optional Object property value validator.\n */\n readonly isOptional: IsOptional;\n\n /**\n * Always `\"true\"`.\n */\n readonly isConvexValidator: true;\n\n constructor({ isOptional }: { isOptional: IsOptional }) {\n this.isOptional = isOptional;\n this.isConvexValidator = true;\n }\n /** @internal */\n abstract get json(): ValidatorJSON;\n /** @internal */\n abstract asOptional(): Validator<Type | undefined, \"optional\", FieldPaths>;\n}\n\n/**\n * The type of the `v.id(tableName)` validator.\n */\nexport class VId<\n Type,\n IsOptional extends OptionalProperty = \"required\",\n> extends BaseValidator<Type, IsOptional> {\n /**\n * The name of the table that the validated IDs must belong to.\n */\n readonly tableName: TableNameFromType<Type>;\n\n /**\n * The kind of validator, `\"id\"`.\n */\n readonly kind = \"id\" as const;\n\n /**\n * Usually you'd use `v.id(tableName)` instead.\n */\n constructor({\n isOptional,\n tableName,\n }: {\n isOptional: IsOptional;\n tableName: TableNameFromType<Type>;\n }) {\n super({ isOptional });\n if (typeof tableName !== \"string\") {\n throw new Error(\"v.id(tableName) requires a string\");\n }\n this.tableName = tableName;\n }\n /** @internal */\n get json(): ValidatorJSON {\n return { type: \"id\", tableName: this.tableName };\n }\n /** @internal */\n asOptional() {\n return new VId<Type | undefined, \"optional\">({\n isOptional: \"optional\",\n tableName: this.tableName,\n });\n }\n}\n\n/**\n * The type of the `v.float64()` validator.\n */\nexport class VFloat64<\n Type = number,\n IsOptional extends OptionalProperty = \"required\",\n> extends BaseValidator<Type, IsOptional> {\n /**\n * The kind of validator, `\"float64\"`.\n */\n readonly kind = \"float64\" as const;\n\n /** @internal */\n get json(): ValidatorJSON {\n // Server expects the old name `number` string instead of `float64`.\n return { type: \"number\" };\n }\n /** @internal */\n asOptional() {\n return new VFloat64<Type | undefined, \"optional\">({\n isOptional: \"optional\",\n });\n }\n}\n\n/**\n * The type of the `v.int64()` validator.\n */\nexport class VInt64<\n Type = bigint,\n IsOptional extends OptionalProperty = \"required\",\n> extends BaseValidator<Type, IsOptional> {\n /**\n * The kind of validator, `\"int64\"`.\n */\n readonly kind = \"int64\" as const;\n\n /** @internal */\n get json(): ValidatorJSON {\n // Server expects the old name `bigint`.\n return { type: \"bigint\" };\n }\n /** @internal */\n asOptional() {\n return new VInt64<Type | undefined, \"optional\">({ isOptional: \"optional\" });\n }\n}\n\n/**\n * The type of the `v.commitTs()` validator.\n */\nexport class VCommitTs<\n Type = bigint | CommitTsPlaceholder,\n IsOptional extends OptionalProperty = \"required\",\n> extends BaseValidator<Type, IsOptional> {\n /**\n * The kind of validator, `\"commitTs\"`.\n */\n readonly kind = \"commitTs\" as const;\n\n /** @internal */\n get json(): ValidatorJSON {\n return { type: this.kind };\n }\n /** @internal */\n asOptional() {\n return new VCommitTs<Type | undefined, \"optional\">({\n isOptional: \"optional\",\n });\n }\n}\n\n/**\n * The type of the `v.boolean()` validator.\n */\nexport class VBoolean<\n Type = boolean,\n IsOptional extends OptionalProperty = \"required\",\n> extends BaseValidator<Type, IsOptional> {\n /**\n * The kind of validator, `\"boolean\"`.\n */\n readonly kind = \"boolean\" as const;\n\n /** @internal */\n get json(): ValidatorJSON {\n return { type: this.kind };\n }\n /** @internal */\n asOptional() {\n return new VBoolean<Type | undefined, \"optional\">({\n isOptional: \"optional\",\n });\n }\n}\n\n/**\n * The type of the `v.bytes()` validator.\n */\nexport class VBytes<\n Type = ArrayBuffer,\n IsOptional extends OptionalProperty = \"required\",\n> extends BaseValidator<Type, IsOptional> {\n /**\n * The kind of validator, `\"bytes\"`.\n */\n readonly kind = \"bytes\" as const;\n\n /** @internal */\n get json(): ValidatorJSON {\n return { type: this.kind };\n }\n /** @internal */\n asOptional() {\n return new VBytes<Type | undefined, \"optional\">({ isOptional: \"optional\" });\n }\n}\n\n/**\n * The type of the `v.string()` validator.\n */\nexport class VString<\n Type = string,\n IsOptional extends OptionalProperty = \"required\",\n> extends BaseValidator<Type, IsOptional> {\n /**\n * The kind of validator, `\"string\"`.\n */\n readonly kind = \"string\" as const;\n\n /** @internal */\n get json(): ValidatorJSON {\n return { type: this.kind };\n }\n /** @internal */\n asOptional() {\n return new VString<Type | undefined, \"optional\">({\n isOptional: \"optional\",\n });\n }\n}\n\n/**\n * The type of the `v.null()` validator.\n */\nexport class VNull<\n Type = null,\n IsOptional extends OptionalProperty = \"required\",\n> extends BaseValidator<Type, IsOptional> {\n /**\n * The kind of validator, `\"null\"`.\n */\n readonly kind = \"null\" as const;\n\n /** @internal */\n get json(): ValidatorJSON {\n return { type: this.kind };\n }\n /** @internal */\n asOptional() {\n return new VNull<Type | undefined, \"optional\">({ isOptional: \"optional\" });\n }\n}\n\n/**\n * The type of the `v.any()` validator.\n */\nexport class VAny<\n Type = any,\n IsOptional extends OptionalProperty = \"required\",\n FieldPaths extends string = string,\n> extends BaseValidator<Type, IsOptional, FieldPaths> {\n /**\n * The kind of validator, `\"any\"`.\n */\n readonly kind = \"any\" as const;\n\n /** @internal */\n get json(): ValidatorJSON {\n return {\n type: this.kind,\n };\n }\n /** @internal */\n asOptional() {\n return new VAny<Type | undefined, \"optional\", FieldPaths>({\n isOptional: \"optional\",\n });\n }\n}\n\n/**\n * The type of the `v.object()` validator.\n */\nexport class VObject<\n Type,\n Fields extends Record<string, GenericValidator>,\n IsOptional extends OptionalProperty = \"required\",\n FieldPaths extends string = {\n [Property in keyof Fields]:\n | JoinFieldPaths<Property & string, Fields[Property][\"fieldPaths\"]>\n | Property;\n }[keyof Fields] &\n string,\n> extends BaseValidator<Type, IsOptional, FieldPaths> {\n /**\n * An object with the validator for each property.\n */\n readonly fields: Fields;\n\n /**\n * The kind of validator, `\"object\"`.\n */\n readonly kind = \"object\" as const;\n\n /**\n * Usually you'd use `v.object({ ... })` instead.\n */\n constructor({\n isOptional,\n fields,\n }: {\n isOptional: IsOptional;\n fields: Fields;\n }) {\n super({ isOptional });\n globalThis.Object.entries(fields).forEach(([fieldName, validator]) => {\n if (validator === undefined) {\n throwUndefinedValidatorError(\"v.object()\", fieldName);\n }\n if (!validator.isConvexValidator) {\n throw new Error(\"v.object() entries must be validators\");\n }\n });\n this.fields = fields;\n }\n /** @internal */\n get json(): ValidatorJSON {\n return {\n type: this.kind,\n value: globalThis.Object.fromEntries(\n globalThis.Object.entries(this.fields).map(([k, v]) => [\n k,\n {\n fieldType: v.json,\n optional: v.isOptional === \"optional\" ? true : false,\n },\n ]),\n ),\n };\n }\n /** @internal */\n asOptional() {\n return new VObject<Type | undefined, Fields, \"optional\", FieldPaths>({\n isOptional: \"optional\",\n fields: this.fields,\n });\n }\n\n /**\n * Create a new VObject with the specified fields omitted.\n * @param fields The field names to omit from this VObject.\n */\n omit<K extends keyof Fields & string>(\n ...fields: K[]\n ): VObject<Expand<Omit<Type, K>>, Expand<Omit<Fields, K>>, IsOptional> {\n const newFields = { ...this.fields };\n for (const field of fields) {\n delete newFields[field];\n }\n return new VObject({\n isOptional: this.isOptional,\n fields: newFields as any,\n });\n }\n\n /**\n * Create a new VObject with only the specified fields.\n * @param fields The field names to pick from this VObject.\n */\n pick<K extends keyof Fields & string>(\n ...fields: K[]\n ): VObject<\n Expand<Pick<Type, Extract<keyof Type, K>>>,\n Expand<Pick<Fields, K>>,\n IsOptional\n > {\n const newFields: Record<string, GenericValidator> = {};\n for (const field of fields) {\n newFields[field] = this.fields[field];\n }\n return new VObject({\n isOptional: this.isOptional,\n fields: newFields as Expand<Pick<Fields, K>>,\n });\n }\n\n /**\n * Create a new VObject with all fields marked as optional.\n */\n partial(): VObject<\n { [K in keyof Type]?: Type[K] },\n { [K in keyof Fields]: VOptional<Fields[K]> },\n IsOptional\n > {\n const newFields: Record<string, GenericValidator> = {};\n for (const [key, validator] of globalThis.Object.entries(this.fields)) {\n newFields[key] = validator.asOptional();\n }\n return new VObject({\n isOptional: this.isOptional,\n fields: newFields as {\n [K in keyof Fields]: VOptional<Fields[K]>;\n },\n });\n }\n\n /**\n * Create a new VObject with additional fields merged in.\n * @param fields An object with additional validators to merge into this VObject.\n */\n extend<NewFields extends Record<string, GenericValidator>>(\n fields: NewFields,\n ): VObject<\n Expand<Type & ObjectType<NewFields>>,\n Expand<Fields & NewFields>,\n IsOptional\n > {\n return new VObject({\n isOptional: this.isOptional,\n fields: { ...this.fields, ...fields } as Expand<Fields & NewFields>,\n });\n }\n}\n\n/**\n * The type of the `v.literal()` validator.\n */\nexport class VLiteral<\n Type,\n IsOptional extends OptionalProperty = \"required\",\n> extends BaseValidator<Type, IsOptional> {\n /**\n * The value that the validated values must be equal to.\n */\n readonly value: Type;\n\n /**\n * The kind of validator, `\"literal\"`.\n */\n readonly kind = \"literal\" as const;\n\n /**\n * Usually you'd use `v.literal(value)` instead.\n */\n constructor({ isOptional, value }: { isOptional: IsOptional; value: Type }) {\n super({ isOptional });\n if (\n typeof value !== \"string\" &&\n typeof value !== \"boolean\" &&\n typeof value !== \"number\" &&\n typeof value !== \"bigint\"\n ) {\n throw new Error(\"v.literal(value) must be a string, number, or boolean\");\n }\n this.value = value;\n }\n /** @internal */\n get json(): ValidatorJSON {\n return {\n type: this.kind,\n value: convexToJson(this.value as string | boolean | number | bigint),\n };\n }\n /** @internal */\n asOptional() {\n return new VLiteral<Type | undefined, \"optional\">({\n isOptional: \"optional\",\n value: this.value,\n });\n }\n}\n\n/**\n * The type of the `v.array()` validator.\n */\nexport class VArray<\n Type,\n Element extends Validator<any, \"required\", any>,\n IsOptional extends OptionalProperty = \"required\",\n> extends BaseValidator<Type, IsOptional> {\n /**\n * The validator for the elements of the array.\n */\n readonly element: Element;\n\n /**\n * The kind of validator, `\"array\"`.\n */\n readonly kind = \"array\" as const;\n\n /**\n * Usually you'd use `v.array(element)` instead.\n */\n constructor({\n isOptional,\n element,\n }: {\n isOptional: IsOptional;\n element: Element;\n }) {\n super({ isOptional });\n if (element === undefined) {\n throwUndefinedValidatorError(\"v.array()\");\n }\n this.element = element;\n }\n /** @internal */\n get json(): ValidatorJSON {\n return {\n type: this.kind,\n value: this.element.json,\n };\n }\n /** @internal */\n asOptional() {\n return new VArray<Type | undefined, Element, \"optional\">({\n isOptional: \"optional\",\n element: this.element,\n });\n }\n}\n\n/**\n * The type of the `v.record()` validator.\n */\nexport class VRecord<\n Type,\n Key extends Validator<string, \"required\", any>,\n Value extends Validator<any, \"required\", any>,\n IsOptional extends OptionalProperty = \"required\",\n FieldPaths extends string = string,\n> extends BaseValidator<Type, IsOptional, FieldPaths> {\n /**\n * The validator for the keys of the record.\n */\n readonly key: Key;\n\n /**\n * The validator for the values of the record.\n */\n readonly value: Value;\n\n /**\n * The kind of validator, `\"record\"`.\n */\n readonly kind = \"record\" as const;\n\n /**\n * Usually you'd use `v.record(key, value)` instead.\n */\n constructor({\n isOptional,\n key,\n value,\n }: {\n isOptional: IsOptional;\n key: Key;\n value: Value;\n }) {\n super({ isOptional });\n if (key === undefined) {\n throwUndefinedValidatorError(\"v.record()\", \"key\");\n }\n if (value === undefined) {\n throwUndefinedValidatorError(\"v.record()\", \"value\");\n }\n if ((key.isOptional as OptionalProperty) === \"optional\") {\n throw new Error(\"Record validator cannot have optional keys\");\n }\n if ((value.isOptional as OptionalProperty) === \"optional\") {\n throw new Error(\"Record validator cannot have optional values\");\n }\n if (!key.isConvexValidator || !value.isConvexValidator) {\n throw new Error(\"Key and value of v.record() but be validators\");\n }\n this.key = key;\n this.value = value;\n }\n /** @internal */\n get json(): ValidatorJSON {\n return {\n type: this.kind,\n // This cast is needed because TypeScript thinks the key type is too wide\n keys: this.key.json as RecordKeyValidatorJSON,\n values: {\n fieldType: this.value.json,\n optional: false,\n },\n };\n }\n /** @internal */\n asOptional() {\n return new VRecord<Type | undefined, Key, Value, \"optional\", FieldPaths>({\n isOptional: \"optional\",\n key: this.key,\n value: this.value,\n });\n }\n}\n\n/**\n * The type of the `v.union()` validator.\n */\nexport class VUnion<\n Type,\n T extends Validator<any, \"required\", any>[],\n IsOptional extends OptionalProperty = \"required\",\n FieldPaths extends string = T[number][\"fieldPaths\"],\n> extends BaseValidator<Type, IsOptional, FieldPaths> {\n /**\n * The array of validators, one of which must match the value.\n */\n readonly members: T;\n\n /**\n * The kind of validator, `\"union\"`.\n */\n readonly kind = \"union\" as const;\n\n /**\n * Usually you'd use `v.union(...members)` instead.\n */\n constructor({ isOptional, members }: { isOptional: IsOptional; members: T }) {\n super({ isOptional });\n members.forEach((member, index) => {\n if (member === undefined) {\n throwUndefinedValidatorError(\"v.union()\", `member at index ${index}`);\n }\n if (!member.isConvexValidator) {\n throw new Error(\"All members of v.union() must be validators\");\n }\n });\n this.members = members;\n }\n /** @internal */\n get json(): ValidatorJSON {\n return {\n type: this.kind,\n value: this.members.map((v) => v.json),\n };\n }\n /** @internal */\n asOptional() {\n return new VUnion<Type | undefined, T, \"optional\">({\n isOptional: \"optional\",\n members: this.members,\n });\n }\n}\n\n// prettier-ignore\nexport type VOptional<T extends Validator<any, OptionalProperty, any>> =\n T extends VId<infer Type, OptionalProperty> ? VId<Type | undefined, \"optional\">\n : T extends VString<infer Type, OptionalProperty>\n ? VString<Type | undefined, \"optional\">\n : T extends VFloat64<infer Type, OptionalProperty>\n ? VFloat64<Type | undefined, \"optional\">\n : T extends VInt64<infer Type, OptionalProperty>\n ? VInt64<Type | undefined, \"optional\">\n : T extends VCommitTs<infer Type, OptionalProperty>\n ? VCommitTs<Type | undefined, \"optional\">\n : T extends VBoolean<infer Type, OptionalProperty>\n ? VBoolean<Type | undefined, \"optional\">\n : T extends VNull<infer Type, OptionalProperty>\n ? VNull<Type | undefined, \"optional\">\n : T extends VAny<infer Type, OptionalProperty>\n ? VAny<Type | undefined, \"optional\">\n : T extends VLiteral<infer Type, OptionalProperty>\n ? VLiteral<Type | undefined, \"optional\">\n : T extends VBytes<infer Type, OptionalProperty>\n ? VBytes<Type | undefined, \"optional\">\n : T extends VObject< infer Type, infer Fields, OptionalProperty, infer FieldPaths>\n ? VObject<Type | undefined, Fields, \"optional\", FieldPaths>\n : T extends VArray<infer Type, infer Element, OptionalProperty>\n ? VArray<Type | undefined, Element, \"optional\">\n : T extends VRecord< infer Type, infer Key, infer Value, OptionalProperty, infer FieldPaths>\n ? VRecord<Type | undefined, Key, Value, \"optional\", FieldPaths>\n : T extends VUnion<infer Type, infer Members, OptionalProperty, infer FieldPaths>\n ? VUnion<Type | undefined, Members, \"optional\", FieldPaths>\n : never\n\n/**\n * Type representing whether a property in an object is optional or required.\n *\n * @public\n */\nexport type OptionalProperty = \"optional\" | \"required\";\n\n/**\n * A validator for a Convex value.\n *\n * This should be constructed using the validator builder, {@link v}.\n *\n * A validator encapsulates:\n * - The TypeScript type of this value.\n * - Whether this field should be optional if it's included in an object.\n * - The TypeScript type for the set of index field paths that can be used to\n * build indexes on this value.\n * - A JSON representation of the validator.\n *\n * Specific types of validators contain additional information: for example\n * an `ArrayValidator` contains an `element` property with the validator\n * used to validate each element of the list. Use the shared 'kind' property\n * to identity the type of validator.\n *\n * More validators can be added in future releases so an exhaustive\n * switch statement on validator `kind` should be expected to break\n * in future releases of Convex.\n *\n * @public\n */\nexport type Validator<\n Type,\n IsOptional extends OptionalProperty = \"required\",\n FieldPaths extends string = never,\n> =\n | VId<Type, IsOptional>\n | VString<Type, IsOptional>\n | VFloat64<Type, IsOptional>\n | VInt64<Type, IsOptional>\n | VCommitTs<Type, IsOptional>\n | VBoolean<Type, IsOptional>\n | VNull<Type, IsOptional>\n | VAny<Type, IsOptional>\n | VLiteral<Type, IsOptional>\n | VBytes<Type, IsOptional>\n | VObject<\n Type,\n Record<string, Validator<any, OptionalProperty, any>>,\n IsOptional,\n FieldPaths\n >\n | VArray<Type, Validator<any, \"required\", any>, IsOptional>\n | VRecord<\n Type,\n Validator<string, \"required\", any>,\n Validator<any, \"required\", any>,\n IsOptional,\n FieldPaths\n >\n | VUnion<Type, Validator<any, \"required\", any>[], IsOptional, FieldPaths>;\n\n/**\n * Join together two index field paths.\n *\n * This is used within the validator builder, {@link v}.\n * @public\n */\nexport type JoinFieldPaths<\n Start extends string,\n End extends string,\n> = `${Start}.${End}`;\n\nexport type ObjectFieldType = { fieldType: ValidatorJSON; optional: boolean };\n\nexport type ValidatorJSON =\n | { type: \"null\" }\n | { type: \"number\" }\n | { type: \"bigint\" }\n | { type: \"commitTs\" }\n | { type: \"boolean\" }\n | { type: \"string\" }\n | { type: \"bytes\" }\n | { type: \"any\" }\n | { type: \"literal\"; value: JSONValue }\n | { type: \"id\"; tableName: string }\n | { type: \"array\"; value: ValidatorJSON }\n | {\n type: \"record\";\n keys: RecordKeyValidatorJSON;\n values: RecordValueValidatorJSON;\n }\n | { type: \"object\"; value: Record<string, ObjectFieldType> }\n | { type: \"union\"; value: ValidatorJSON[] };\n\nexport type RecordKeyValidatorJSON =\n | { type: \"string\" }\n | { type: \"id\"; tableName: string }\n | { type: \"union\"; value: RecordKeyValidatorJSON[] };\n\nexport type RecordValueValidatorJSON = ObjectFieldType & { optional: false };\n"],
|
|
5
|
+
"mappings": ";;;;AAGA,SAAyC,oBAAoB;AAK7D,MAAM,gCACJ;AAEF,SAAS,6BACP,SACA,WACO;AACP,QAAM,YAAY,cAAc,SAAY,eAAe,SAAS,MAAM;AAC1E,QAAM,IAAI;AAAA,IACR,2BAA2B,SAAS,OAAO,OAAO,mDAEzC,6BAA6B;AAAA,EACxC;AACF;AAMA,MAAe,cAIb;AAAA,EAsBA,YAAY,EAAE,WAAW,GAA+B;AAjBxD;AAAA;AAAA;AAAA;AAAA,wBAAS;AAKT;AAAA;AAAA;AAAA;AAAA,wBAAS;AAKT;AAAA;AAAA;AAAA,wBAAS;AAKT;AAAA;AAAA;AAAA,wBAAS;AAGP,SAAK,aAAa;AAClB,SAAK,oBAAoB;AAAA,EAC3B;AAKF;AAKO,aAAM,YAGH,cAAgC;AAAA;AAAA;AAAA;AAAA,EAcxC,YAAY;AAAA,IACV;AAAA,IACA;AAAA,EACF,GAGG;AACD,UAAM,EAAE,WAAW,CAAC;AAjBtB;AAAA;AAAA;AAAA,wBAAS;AAKT;AAAA;AAAA;AAAA,wBAAS,QAAO;AAad,QAAI,OAAO,cAAc,UAAU;AACjC,YAAM,IAAI,MAAM,mCAAmC;AAAA,IACrD;AACA,SAAK,YAAY;AAAA,EACnB;AAAA;AAAA,EAEA,IAAI,OAAsB;AACxB,WAAO,EAAE,MAAM,MAAM,WAAW,KAAK,UAAU;AAAA,EACjD;AAAA;AAAA,EAEA,aAAa;AACX,WAAO,IAAI,IAAkC;AAAA,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AAAA,IACd,CAAC;AAAA,EACH;AACF;AAKO,aAAM,eAKH,cAA4C;AAAA;AAAA;AAAA;AAAA,EAcpD,YAAY,EAAE,YAAY,QAAQ,GAA2C;AAC3E,UAAM,EAAE,WAAW,CAAC;AAXtB;AAAA;AAAA;AAAA,wBAAS;AAKT;AAAA;AAAA;AAAA,wBAAS,QAAO;AAOd,YAAQ,QAAQ,CAAC,QAAQ,UAAU;AACjC,UAAI,WAAW,QAAW;AACxB,qCAA6B,aAAa,mBAAmB,KAAK,EAAE;AAAA,MACtE;AACA,UAAI,CAAC,OAAO,mBAAmB;AAC7B,cAAM,IAAI,MAAM,6CAA6C;AAAA,MAC/D;AAAA,IACF,CAAC;AACD,SAAK,UAAU;AAAA,EACjB;AAAA;AAAA,EAEA,IAAI,OAAsB;AACxB,WAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,OAAO,KAAK,QAAQ,IAAI,CAAC,MAAM,EAAE,IAAI;AAAA,IACvC;AAAA,EACF;AAAA;AAAA,EAEA,aAAa;AACX,WAAO,IAAI,OAAwC;AAAA,MACjD,YAAY;AAAA,MACZ,SAAS,KAAK;AAAA,IAChB,CAAC;AAAA,EACH;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/values/value.js
CHANGED
|
@@ -3,10 +3,29 @@ import * as Base64 from "./base64.js";
|
|
|
3
3
|
import { isSimpleObject } from "../common/index.js";
|
|
4
4
|
const LITTLE_ENDIAN = true;
|
|
5
5
|
const MIN_INT64 = BigInt("-9223372036854775808");
|
|
6
|
-
const MAX_INT64 = BigInt("9223372036854775807");
|
|
6
|
+
export const MAX_INT64 = BigInt("9223372036854775807");
|
|
7
7
|
const ZERO = BigInt("0");
|
|
8
8
|
const EIGHT = BigInt("8");
|
|
9
9
|
const TWOFIFTYSIX = BigInt("256");
|
|
10
|
+
const COMMIT_TS_UNRESOLVED = "This commit timestamp is unresolved: its value is assigned when the mutation commits. Read the document after the mutation completes to get its value.";
|
|
11
|
+
export class CommitTsPlaceholder {
|
|
12
|
+
[Symbol.toPrimitive](hint) {
|
|
13
|
+
if (hint === "string") {
|
|
14
|
+
return this.toString();
|
|
15
|
+
}
|
|
16
|
+
throw new Error(COMMIT_TS_UNRESOLVED);
|
|
17
|
+
}
|
|
18
|
+
valueOf() {
|
|
19
|
+
throw new Error(COMMIT_TS_UNRESOLVED);
|
|
20
|
+
}
|
|
21
|
+
toJSON() {
|
|
22
|
+
throw new Error(COMMIT_TS_UNRESOLVED);
|
|
23
|
+
}
|
|
24
|
+
toString() {
|
|
25
|
+
return "[unresolved commit timestamp]";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export const commitTsPlaceholder = new CommitTsPlaceholder();
|
|
10
29
|
function isSpecial(n) {
|
|
11
30
|
return Number.isNaN(n) || !Number.isFinite(n) || Object.is(n, -0);
|
|
12
31
|
}
|
|
@@ -134,6 +153,12 @@ export function jsonToConvex(value) {
|
|
|
134
153
|
}
|
|
135
154
|
return float;
|
|
136
155
|
}
|
|
156
|
+
if (key === "$commitTs") {
|
|
157
|
+
if (value.$commitTs !== null) {
|
|
158
|
+
throw new Error(`Malformed $commitTs field on ${value}`);
|
|
159
|
+
}
|
|
160
|
+
return commitTsPlaceholder;
|
|
161
|
+
}
|
|
137
162
|
if (key === "$set") {
|
|
138
163
|
throw new Error(
|
|
139
164
|
`Received a Set which is no longer supported as a Convex type.`
|
|
@@ -212,6 +237,9 @@ function convexToJsonInternal(value, originalValue, context, includeTopLevelUnde
|
|
|
212
237
|
if (value instanceof ArrayBuffer) {
|
|
213
238
|
return { $bytes: Base64.fromByteArray(new Uint8Array(value)) };
|
|
214
239
|
}
|
|
240
|
+
if (value instanceof CommitTsPlaceholder) {
|
|
241
|
+
return { $commitTs: null };
|
|
242
|
+
}
|
|
215
243
|
if (Array.isArray(value)) {
|
|
216
244
|
return value.map(
|
|
217
245
|
(value2, i) => convexToJsonInternal(value2, originalValue, context + `[${i}]`, false)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/values/value.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Utilities for working with values stored in Convex.\n *\n * You can see the full set of supported types at\n * [Types](https://docs.convex.dev/using/types).\n * @module\n */\nimport * as Base64 from \"./base64.js\";\nimport { isSimpleObject } from \"../common/index.js\";\n\nconst LITTLE_ENDIAN = true;\n// This code is used by code that may not have bigint literals.\nconst MIN_INT64 = BigInt(\"-9223372036854775808\");\nconst MAX_INT64 = BigInt(\"9223372036854775807\");\nconst ZERO = BigInt(\"0\");\nconst EIGHT = BigInt(\"8\");\nconst TWOFIFTYSIX = BigInt(\"256\");\n\n/**\n * The type of JavaScript values serializable to JSON.\n *\n * @public\n */\nexport type JSONValue =\n | null\n | boolean\n | number\n | string\n | JSONValue[]\n | { [key: string]: JSONValue };\n\n/**\n * An identifier for a document in Convex.\n *\n * Convex documents are uniquely identified by their `Id`, which is accessible\n * on the `_id` field. To learn more, see [Document IDs](https://docs.convex.dev/database/document-ids).\n *\n * Documents can be loaded using `db.get(tableName, id)` in query and mutation functions.\n *\n * IDs are base 32 encoded strings which are URL safe.\n *\n * IDs are just strings at runtime, but this type can be used to distinguish them from other\n * strings at compile time.\n *\n * If you're using code generation, use the `Id` type generated for your data model in\n * `convex/_generated/dataModel.d.ts`.\n *\n * @typeParam TableName - A string literal type of the table name (like \"users\").\n *\n * @public\n */\nexport type Id<TableName extends string> = string & { __tableName: TableName };\n\n/**\n * A value supported by Convex.\n *\n * Values can be:\n * - stored inside of documents.\n * - used as arguments and return types to queries and mutation functions.\n *\n * You can see the full set of supported types at\n * [Types](https://docs.convex.dev/using/types).\n *\n * @public\n */\nexport type Value =\n | null\n | bigint\n | number\n | boolean\n | string\n | ArrayBuffer\n | Value[]\n | { [key: string]: undefined | Value };\n\n/**\n * The types of {@link Value} that can be used to represent numbers.\n *\n * @public\n */\nexport type NumericValue = bigint | number;\n\nfunction isSpecial(n: number) {\n return Number.isNaN(n) || !Number.isFinite(n) || Object.is(n, -0);\n}\n\nexport function slowBigIntToBase64(value: bigint): string {\n // the conversion is easy if we pretend it's unsigned\n if (value < ZERO) {\n value -= MIN_INT64 + MIN_INT64;\n }\n let hex = value.toString(16);\n if (hex.length % 2 === 1) hex = \"0\" + hex;\n\n const bytes = new Uint8Array(new ArrayBuffer(8));\n let i = 0;\n for (const hexByte of hex.match(/.{2}/g)!.reverse()) {\n bytes.set([parseInt(hexByte, 16)], i++);\n value >>= EIGHT;\n }\n return Base64.fromByteArray(bytes);\n}\n\nexport function slowBase64ToBigInt(encoded: string): bigint {\n const integerBytes = Base64.toByteArray(encoded);\n if (integerBytes.byteLength !== 8) {\n throw new Error(\n `Received ${integerBytes.byteLength} bytes, expected 8 for $integer`,\n );\n }\n let value = ZERO;\n let power = ZERO;\n for (const byte of integerBytes) {\n value += BigInt(byte) * TWOFIFTYSIX ** power;\n power++;\n }\n if (value > MAX_INT64) {\n value += MIN_INT64 + MIN_INT64;\n }\n return value;\n}\n\nexport function modernBigIntToBase64(value: bigint): string {\n if (value < MIN_INT64 || MAX_INT64 < value) {\n throw new Error(\n `BigInt ${value} does not fit into a 64-bit signed integer.`,\n );\n }\n const buffer = new ArrayBuffer(8);\n new DataView(buffer).setBigInt64(0, value, true);\n return Base64.fromByteArray(new Uint8Array(buffer));\n}\n\nexport function modernBase64ToBigInt(encoded: string): bigint {\n const integerBytes = Base64.toByteArray(encoded);\n if (integerBytes.byteLength !== 8) {\n throw new Error(\n `Received ${integerBytes.byteLength} bytes, expected 8 for $integer`,\n );\n }\n const intBytesView = new DataView(integerBytes.buffer);\n return intBytesView.getBigInt64(0, true);\n}\n\n// Fall back to a slower version on Safari 14 which lacks these APIs.\nexport const bigIntToBase64 = (DataView.prototype as any).setBigInt64\n ? modernBigIntToBase64\n : slowBigIntToBase64;\nexport const base64ToBigInt = (DataView.prototype as any).getBigInt64\n ? modernBase64ToBigInt\n : slowBase64ToBigInt;\n\nconst MAX_IDENTIFIER_LEN = 1024;\n\nfunction validateObjectField(k: string) {\n if (k.length > MAX_IDENTIFIER_LEN) {\n throw new Error(\n `Field name ${k} exceeds maximum field name length ${MAX_IDENTIFIER_LEN}.`,\n );\n }\n if (k.startsWith(\"$\")) {\n throw new Error(`Field name ${k} starts with a '$', which is reserved.`);\n }\n for (let i = 0; i < k.length; i += 1) {\n const charCode = k.charCodeAt(i);\n // Non-control ASCII characters\n if (charCode < 32 || charCode >= 127) {\n throw new Error(\n `Field name ${k} has invalid character '${k[i]}': Field names can only contain non-control ASCII characters`,\n );\n }\n }\n}\n\n/**\n * Parse a Convex value from its JSON representation.\n *\n * This function will deserialize serialized Int64s to `BigInt`s, Bytes to `ArrayBuffer`s etc.\n *\n * To learn more about Convex values, see [Types](https://docs.convex.dev/using/types).\n *\n * @param value - The JSON representation of a Convex value previously created with {@link convexToJson}.\n * @returns The JavaScript representation of the Convex value.\n *\n * @public\n */\nexport function jsonToConvex(value: JSONValue): Value {\n if (value === null) {\n return value;\n }\n if (typeof value === \"boolean\") {\n return value;\n }\n if (typeof value === \"number\") {\n return value;\n }\n if (typeof value === \"string\") {\n return value;\n }\n if (Array.isArray(value)) {\n return value.map((value) => jsonToConvex(value));\n }\n if (typeof value !== \"object\") {\n throw new Error(`Unexpected type of ${value as any}`);\n }\n const entries = Object.entries(value);\n if (entries.length === 1) {\n const key = entries[0][0];\n if (key === \"$bytes\") {\n if (typeof value.$bytes !== \"string\") {\n throw new Error(`Malformed $bytes field on ${value as any}`);\n }\n return Base64.toByteArray(value.$bytes).buffer;\n }\n if (key === \"$integer\") {\n if (typeof value.$integer !== \"string\") {\n throw new Error(`Malformed $integer field on ${value as any}`);\n }\n return base64ToBigInt(value.$integer);\n }\n if (key === \"$float\") {\n if (typeof value.$float !== \"string\") {\n throw new Error(`Malformed $float field on ${value as any}`);\n }\n const floatBytes = Base64.toByteArray(value.$float);\n if (floatBytes.byteLength !== 8) {\n throw new Error(\n `Received ${floatBytes.byteLength} bytes, expected 8 for $float`,\n );\n }\n const floatBytesView = new DataView(floatBytes.buffer);\n const float = floatBytesView.getFloat64(0, LITTLE_ENDIAN);\n if (!isSpecial(float)) {\n throw new Error(`Float ${float} should be encoded as a number`);\n }\n return float;\n }\n if (key === \"$set\") {\n throw new Error(\n `Received a Set which is no longer supported as a Convex type.`,\n );\n }\n if (key === \"$map\") {\n throw new Error(\n `Received a Map which is no longer supported as a Convex type.`,\n );\n }\n }\n const out: { [key: string]: Value } = {};\n for (const [k, v] of Object.entries(value)) {\n validateObjectField(k);\n out[k] = jsonToConvex(v);\n }\n return out;\n}\n\nconst MAX_VALUE_FOR_ERROR_LEN = 16384;\n\nexport function stringifyValueForError(value: any) {\n const str = JSON.stringify(value, (_key, value) => {\n if (value === undefined) {\n // By default `JSON.stringify` converts undefined, functions, symbols,\n // Infinity, and NaN to null which produces a confusing error message.\n // We deal with `undefined` specifically because it's the most common.\n // Ideally we'd use a pretty-printing library that prints `undefined`\n // (no quotes), but it might not be worth the bundle size cost.\n return \"undefined\";\n }\n if (typeof value === \"bigint\") {\n // `JSON.stringify` throws on bigints by default.\n return `${value.toString()}n`;\n }\n return value;\n });\n if (str.length > MAX_VALUE_FOR_ERROR_LEN) {\n const rest = \"[...truncated]\";\n let truncateAt = MAX_VALUE_FOR_ERROR_LEN - rest.length;\n const codePoint = str.codePointAt(truncateAt - 1);\n if (codePoint !== undefined && codePoint > 0xffff) {\n // don't split a surrogate pair in half\n truncateAt -= 1;\n }\n return str.substring(0, truncateAt) + rest;\n }\n return str;\n}\n\nfunction convexToJsonInternal(\n value: Value,\n originalValue: Value,\n context: string,\n includeTopLevelUndefined: boolean,\n): JSONValue {\n if (value === undefined) {\n const contextText =\n context &&\n ` (present at path ${context} in original object ${stringifyValueForError(\n originalValue,\n )})`;\n throw new Error(\n `undefined is not a valid Convex value${contextText}. To learn about Convex's supported types, see https://docs.convex.dev/using/types.`,\n );\n }\n if (value === null) {\n return value;\n }\n if (typeof value === \"bigint\") {\n if (value < MIN_INT64 || MAX_INT64 < value) {\n throw new Error(\n `BigInt ${value} does not fit into a 64-bit signed integer.`,\n );\n }\n return { $integer: bigIntToBase64(value) };\n }\n if (typeof value === \"number\") {\n if (isSpecial(value)) {\n const buffer = new ArrayBuffer(8);\n new DataView(buffer).setFloat64(0, value, LITTLE_ENDIAN);\n return { $float: Base64.fromByteArray(new Uint8Array(buffer)) };\n } else {\n return value;\n }\n }\n if (typeof value === \"boolean\") {\n return value;\n }\n if (typeof value === \"string\") {\n return value;\n }\n if (value instanceof ArrayBuffer) {\n return { $bytes: Base64.fromByteArray(new Uint8Array(value)) };\n }\n if (Array.isArray(value)) {\n return value.map((value, i) =>\n convexToJsonInternal(value, originalValue, context + `[${i}]`, false),\n );\n }\n if (value instanceof Set) {\n throw new Error(\n errorMessageForUnsupportedType(context, \"Set\", [...value], originalValue),\n );\n }\n if (value instanceof Map) {\n throw new Error(\n errorMessageForUnsupportedType(context, \"Map\", [...value], originalValue),\n );\n }\n\n if (!isSimpleObject(value)) {\n const theType = value?.constructor?.name;\n const typeName = theType ? `${theType} ` : \"\";\n throw new Error(\n errorMessageForUnsupportedType(context, typeName, value, originalValue),\n );\n }\n\n const out: { [key: string]: JSONValue } = {};\n const entries = Object.entries(value);\n entries.sort(([k1, _v1], [k2, _v2]) => (k1 === k2 ? 0 : k1 < k2 ? -1 : 1));\n for (const [k, v] of entries) {\n if (v !== undefined) {\n validateObjectField(k);\n out[k] = convexToJsonInternal(v, originalValue, context + `.${k}`, false);\n } else if (includeTopLevelUndefined) {\n validateObjectField(k);\n out[k] = convexOrUndefinedToJsonInternal(\n v,\n originalValue,\n context + `.${k}`,\n );\n }\n }\n return out;\n}\n\nfunction errorMessageForUnsupportedType(\n context: string,\n typeName: string,\n value: any,\n originalValue: any,\n) {\n if (context) {\n return `${typeName}${stringifyValueForError(\n value,\n )} is not a supported Convex type (present at path ${context} in original object ${stringifyValueForError(\n originalValue,\n )}). To learn about Convex's supported types, see https://docs.convex.dev/using/types.`;\n } else {\n return `${typeName}${stringifyValueForError(\n value,\n )} is not a supported Convex type.`;\n }\n}\n\n// convexOrUndefinedToJsonInternal wrapper exists so we can pipe through the\n// `originalValue` and `context` through for better error messaging.\nfunction convexOrUndefinedToJsonInternal(\n value: Value | undefined,\n originalValue: Value | undefined,\n context: string,\n): JSONValue {\n if (value === undefined) {\n return { $undefined: null };\n } else {\n if (originalValue === undefined) {\n // This should not happen.\n throw new Error(\n `Programming error. Current value is ${stringifyValueForError(\n value,\n )} but original value is undefined`,\n );\n }\n return convexToJsonInternal(value, originalValue, context, false);\n }\n}\n\n/**\n * Convert a Convex value to its JSON representation.\n *\n * Use {@link jsonToConvex} to recreate the original value.\n *\n * To learn more about Convex values, see [Types](https://docs.convex.dev/using/types).\n *\n * @param value - A Convex value to convert into JSON.\n * @returns The JSON representation of `value`.\n *\n * @public\n */\nexport function convexToJson(value: Value): JSONValue {\n return convexToJsonInternal(value, value, \"\", false);\n}\n\n// Convert a Convex value or `undefined` into its JSON representation.\n// `undefined` is used in filters to represent a missing object field.\nexport function convexOrUndefinedToJson(value: Value | undefined): JSONValue {\n return convexOrUndefinedToJsonInternal(value, value, \"\");\n}\n\n/**\n * Similar to convexToJson but also serializes top level undefined fields\n * using convexOrUndefinedToJson().\n *\n * @param value - A Convex value to convert into JSON.\n * @returns The JSON representation of `value`.\n */\nexport function patchValueToJson(value: Value): JSONValue {\n return convexToJsonInternal(value, value, \"\", true);\n}\n"],
|
|
5
|
-
"mappings": ";AAOA,YAAY,YAAY;AACxB,SAAS,sBAAsB;AAE/B,MAAM,gBAAgB;AAEtB,MAAM,YAAY,OAAO,sBAAsB;
|
|
4
|
+
"sourcesContent": ["/**\n * Utilities for working with values stored in Convex.\n *\n * You can see the full set of supported types at\n * [Types](https://docs.convex.dev/using/types).\n * @module\n */\nimport * as Base64 from \"./base64.js\";\nimport { isSimpleObject } from \"../common/index.js\";\n\nconst LITTLE_ENDIAN = true;\n// This code is used by code that may not have bigint literals.\nconst MIN_INT64 = BigInt(\"-9223372036854775808\");\nexport const MAX_INT64 = BigInt(\"9223372036854775807\");\nconst ZERO = BigInt(\"0\");\nconst EIGHT = BigInt(\"8\");\nconst TWOFIFTYSIX = BigInt(\"256\");\n\n/**\n * The type of JavaScript values serializable to JSON.\n *\n * @public\n */\nexport type JSONValue =\n | null\n | boolean\n | number\n | string\n | JSONValue[]\n | { [key: string]: JSONValue };\n\n/**\n * An identifier for a document in Convex.\n *\n * Convex documents are uniquely identified by their `Id`, which is accessible\n * on the `_id` field. To learn more, see [Document IDs](https://docs.convex.dev/database/document-ids).\n *\n * Documents can be loaded using `db.get(tableName, id)` in query and mutation functions.\n *\n * IDs are base 32 encoded strings which are URL safe.\n *\n * IDs are just strings at runtime, but this type can be used to distinguish them from other\n * strings at compile time.\n *\n * If you're using code generation, use the `Id` type generated for your data model in\n * `convex/_generated/dataModel.d.ts`.\n *\n * @typeParam TableName - A string literal type of the table name (like \"users\").\n *\n * @public\n */\nexport type Id<TableName extends string> = string & { __tableName: TableName };\n\n/**\n * A value supported by Convex.\n *\n * Values can be:\n * - stored inside of documents.\n * - used as arguments and return types to queries and mutation functions.\n *\n * You can see the full set of supported types at\n * [Types](https://docs.convex.dev/using/types).\n *\n * @public\n */\nexport type Value =\n | null\n | bigint\n | number\n | boolean\n | string\n | ArrayBuffer\n | CommitTsPlaceholder\n | Value[]\n | { [key: string]: undefined | Value };\n\n/**\n * The types of {@link Value} that can be used to represent numbers.\n *\n * @public\n */\nexport type NumericValue = bigint | number;\n\nconst COMMIT_TS_UNRESOLVED =\n \"This commit timestamp is unresolved: its value is assigned when the \" +\n \"mutation commits. Read the document after the mutation completes to get \" +\n \"its value.\";\n\n/**\n * The placeholder for a transaction's commit timestamp, which is not known\n * until the mutation commits. Write it into a document field via\n * `db.vars.commitTs` and it resolves to an int64 (`bigint`) at commit,\n * ordered by commit order. Reading the field back within the writing\n * mutation yields the placeholder, which cannot be used as a number.\n *\n * @public\n */\nexport class CommitTsPlaceholder {\n // A private member makes the class nominal: no structurally-similar object\n // type-checks as a placeholder.\n declare private readonly __isCommitTsPlaceholder: undefined;\n [Symbol.toPrimitive](hint: string): string {\n // Allow string conversion so logging a read-back document doesn't throw.\n if (hint === \"string\") {\n return this.toString();\n }\n throw new Error(COMMIT_TS_UNRESOLVED);\n }\n valueOf(): never {\n throw new Error(COMMIT_TS_UNRESOLVED);\n }\n toJSON(): never {\n throw new Error(COMMIT_TS_UNRESOLVED);\n }\n toString(): string {\n return \"[unresolved commit timestamp]\";\n }\n}\n\n/**\n * The placeholder for a commit timestamp that is not yet known, exposed as\n * `db.vars.commitTs`. A singleton so that a value read back within the\n * writing mutation compares equal to `db.vars.commitTs`.\n *\n * @internal\n */\nexport const commitTsPlaceholder = new CommitTsPlaceholder();\n\nfunction isSpecial(n: number) {\n return Number.isNaN(n) || !Number.isFinite(n) || Object.is(n, -0);\n}\n\nexport function slowBigIntToBase64(value: bigint): string {\n // the conversion is easy if we pretend it's unsigned\n if (value < ZERO) {\n value -= MIN_INT64 + MIN_INT64;\n }\n let hex = value.toString(16);\n if (hex.length % 2 === 1) hex = \"0\" + hex;\n\n const bytes = new Uint8Array(new ArrayBuffer(8));\n let i = 0;\n for (const hexByte of hex.match(/.{2}/g)!.reverse()) {\n bytes.set([parseInt(hexByte, 16)], i++);\n value >>= EIGHT;\n }\n return Base64.fromByteArray(bytes);\n}\n\nexport function slowBase64ToBigInt(encoded: string): bigint {\n const integerBytes = Base64.toByteArray(encoded);\n if (integerBytes.byteLength !== 8) {\n throw new Error(\n `Received ${integerBytes.byteLength} bytes, expected 8 for $integer`,\n );\n }\n let value = ZERO;\n let power = ZERO;\n for (const byte of integerBytes) {\n value += BigInt(byte) * TWOFIFTYSIX ** power;\n power++;\n }\n if (value > MAX_INT64) {\n value += MIN_INT64 + MIN_INT64;\n }\n return value;\n}\n\nexport function modernBigIntToBase64(value: bigint): string {\n if (value < MIN_INT64 || MAX_INT64 < value) {\n throw new Error(\n `BigInt ${value} does not fit into a 64-bit signed integer.`,\n );\n }\n const buffer = new ArrayBuffer(8);\n new DataView(buffer).setBigInt64(0, value, true);\n return Base64.fromByteArray(new Uint8Array(buffer));\n}\n\nexport function modernBase64ToBigInt(encoded: string): bigint {\n const integerBytes = Base64.toByteArray(encoded);\n if (integerBytes.byteLength !== 8) {\n throw new Error(\n `Received ${integerBytes.byteLength} bytes, expected 8 for $integer`,\n );\n }\n const intBytesView = new DataView(integerBytes.buffer);\n return intBytesView.getBigInt64(0, true);\n}\n\n// Fall back to a slower version on Safari 14 which lacks these APIs.\nexport const bigIntToBase64 = (DataView.prototype as any).setBigInt64\n ? modernBigIntToBase64\n : slowBigIntToBase64;\nexport const base64ToBigInt = (DataView.prototype as any).getBigInt64\n ? modernBase64ToBigInt\n : slowBase64ToBigInt;\n\nconst MAX_IDENTIFIER_LEN = 1024;\n\nfunction validateObjectField(k: string) {\n if (k.length > MAX_IDENTIFIER_LEN) {\n throw new Error(\n `Field name ${k} exceeds maximum field name length ${MAX_IDENTIFIER_LEN}.`,\n );\n }\n if (k.startsWith(\"$\")) {\n throw new Error(`Field name ${k} starts with a '$', which is reserved.`);\n }\n for (let i = 0; i < k.length; i += 1) {\n const charCode = k.charCodeAt(i);\n // Non-control ASCII characters\n if (charCode < 32 || charCode >= 127) {\n throw new Error(\n `Field name ${k} has invalid character '${k[i]}': Field names can only contain non-control ASCII characters`,\n );\n }\n }\n}\n\n/**\n * Parse a Convex value from its JSON representation.\n *\n * This function will deserialize serialized Int64s to `BigInt`s, Bytes to `ArrayBuffer`s etc.\n *\n * To learn more about Convex values, see [Types](https://docs.convex.dev/using/types).\n *\n * @param value - The JSON representation of a Convex value previously created with {@link convexToJson}.\n * @returns The JavaScript representation of the Convex value.\n *\n * @public\n */\nexport function jsonToConvex(value: JSONValue): Value {\n if (value === null) {\n return value;\n }\n if (typeof value === \"boolean\") {\n return value;\n }\n if (typeof value === \"number\") {\n return value;\n }\n if (typeof value === \"string\") {\n return value;\n }\n if (Array.isArray(value)) {\n return value.map((value) => jsonToConvex(value));\n }\n if (typeof value !== \"object\") {\n throw new Error(`Unexpected type of ${value as any}`);\n }\n const entries = Object.entries(value);\n if (entries.length === 1) {\n const key = entries[0][0];\n if (key === \"$bytes\") {\n if (typeof value.$bytes !== \"string\") {\n throw new Error(`Malformed $bytes field on ${value as any}`);\n }\n return Base64.toByteArray(value.$bytes).buffer;\n }\n if (key === \"$integer\") {\n if (typeof value.$integer !== \"string\") {\n throw new Error(`Malformed $integer field on ${value as any}`);\n }\n return base64ToBigInt(value.$integer);\n }\n if (key === \"$float\") {\n if (typeof value.$float !== \"string\") {\n throw new Error(`Malformed $float field on ${value as any}`);\n }\n const floatBytes = Base64.toByteArray(value.$float);\n if (floatBytes.byteLength !== 8) {\n throw new Error(\n `Received ${floatBytes.byteLength} bytes, expected 8 for $float`,\n );\n }\n const floatBytesView = new DataView(floatBytes.buffer);\n const float = floatBytesView.getFloat64(0, LITTLE_ENDIAN);\n if (!isSpecial(float)) {\n throw new Error(`Float ${float} should be encoded as a number`);\n }\n return float;\n }\n if (key === \"$commitTs\") {\n if (value.$commitTs !== null) {\n throw new Error(`Malformed $commitTs field on ${value as any}`);\n }\n return commitTsPlaceholder;\n }\n if (key === \"$set\") {\n throw new Error(\n `Received a Set which is no longer supported as a Convex type.`,\n );\n }\n if (key === \"$map\") {\n throw new Error(\n `Received a Map which is no longer supported as a Convex type.`,\n );\n }\n }\n const out: { [key: string]: Value } = {};\n for (const [k, v] of Object.entries(value)) {\n validateObjectField(k);\n out[k] = jsonToConvex(v);\n }\n return out;\n}\n\nconst MAX_VALUE_FOR_ERROR_LEN = 16384;\n\nexport function stringifyValueForError(value: any) {\n const str = JSON.stringify(value, (_key, value) => {\n if (value === undefined) {\n // By default `JSON.stringify` converts undefined, functions, symbols,\n // Infinity, and NaN to null which produces a confusing error message.\n // We deal with `undefined` specifically because it's the most common.\n // Ideally we'd use a pretty-printing library that prints `undefined`\n // (no quotes), but it might not be worth the bundle size cost.\n return \"undefined\";\n }\n if (typeof value === \"bigint\") {\n // `JSON.stringify` throws on bigints by default.\n return `${value.toString()}n`;\n }\n return value;\n });\n if (str.length > MAX_VALUE_FOR_ERROR_LEN) {\n const rest = \"[...truncated]\";\n let truncateAt = MAX_VALUE_FOR_ERROR_LEN - rest.length;\n const codePoint = str.codePointAt(truncateAt - 1);\n if (codePoint !== undefined && codePoint > 0xffff) {\n // don't split a surrogate pair in half\n truncateAt -= 1;\n }\n return str.substring(0, truncateAt) + rest;\n }\n return str;\n}\n\nfunction convexToJsonInternal(\n value: Value,\n originalValue: Value,\n context: string,\n includeTopLevelUndefined: boolean,\n): JSONValue {\n if (value === undefined) {\n const contextText =\n context &&\n ` (present at path ${context} in original object ${stringifyValueForError(\n originalValue,\n )})`;\n throw new Error(\n `undefined is not a valid Convex value${contextText}. To learn about Convex's supported types, see https://docs.convex.dev/using/types.`,\n );\n }\n if (value === null) {\n return value;\n }\n if (typeof value === \"bigint\") {\n if (value < MIN_INT64 || MAX_INT64 < value) {\n throw new Error(\n `BigInt ${value} does not fit into a 64-bit signed integer.`,\n );\n }\n return { $integer: bigIntToBase64(value) };\n }\n if (typeof value === \"number\") {\n if (isSpecial(value)) {\n const buffer = new ArrayBuffer(8);\n new DataView(buffer).setFloat64(0, value, LITTLE_ENDIAN);\n return { $float: Base64.fromByteArray(new Uint8Array(buffer)) };\n } else {\n return value;\n }\n }\n if (typeof value === \"boolean\") {\n return value;\n }\n if (typeof value === \"string\") {\n return value;\n }\n if (value instanceof ArrayBuffer) {\n return { $bytes: Base64.fromByteArray(new Uint8Array(value)) };\n }\n if (value instanceof CommitTsPlaceholder) {\n return { $commitTs: null };\n }\n if (Array.isArray(value)) {\n return value.map((value, i) =>\n convexToJsonInternal(value, originalValue, context + `[${i}]`, false),\n );\n }\n if (value instanceof Set) {\n throw new Error(\n errorMessageForUnsupportedType(context, \"Set\", [...value], originalValue),\n );\n }\n if (value instanceof Map) {\n throw new Error(\n errorMessageForUnsupportedType(context, \"Map\", [...value], originalValue),\n );\n }\n\n if (!isSimpleObject(value)) {\n const theType = value?.constructor?.name;\n const typeName = theType ? `${theType} ` : \"\";\n throw new Error(\n errorMessageForUnsupportedType(context, typeName, value, originalValue),\n );\n }\n\n const out: { [key: string]: JSONValue } = {};\n const entries = Object.entries(value);\n entries.sort(([k1, _v1], [k2, _v2]) => (k1 === k2 ? 0 : k1 < k2 ? -1 : 1));\n for (const [k, v] of entries) {\n if (v !== undefined) {\n validateObjectField(k);\n out[k] = convexToJsonInternal(v, originalValue, context + `.${k}`, false);\n } else if (includeTopLevelUndefined) {\n validateObjectField(k);\n out[k] = convexOrUndefinedToJsonInternal(\n v,\n originalValue,\n context + `.${k}`,\n );\n }\n }\n return out;\n}\n\nfunction errorMessageForUnsupportedType(\n context: string,\n typeName: string,\n value: any,\n originalValue: any,\n) {\n if (context) {\n return `${typeName}${stringifyValueForError(\n value,\n )} is not a supported Convex type (present at path ${context} in original object ${stringifyValueForError(\n originalValue,\n )}). To learn about Convex's supported types, see https://docs.convex.dev/using/types.`;\n } else {\n return `${typeName}${stringifyValueForError(\n value,\n )} is not a supported Convex type.`;\n }\n}\n\n// convexOrUndefinedToJsonInternal wrapper exists so we can pipe through the\n// `originalValue` and `context` through for better error messaging.\nfunction convexOrUndefinedToJsonInternal(\n value: Value | undefined,\n originalValue: Value | undefined,\n context: string,\n): JSONValue {\n if (value === undefined) {\n return { $undefined: null };\n } else {\n if (originalValue === undefined) {\n // This should not happen.\n throw new Error(\n `Programming error. Current value is ${stringifyValueForError(\n value,\n )} but original value is undefined`,\n );\n }\n return convexToJsonInternal(value, originalValue, context, false);\n }\n}\n\n/**\n * Convert a Convex value to its JSON representation.\n *\n * Use {@link jsonToConvex} to recreate the original value.\n *\n * To learn more about Convex values, see [Types](https://docs.convex.dev/using/types).\n *\n * @param value - A Convex value to convert into JSON.\n * @returns The JSON representation of `value`.\n *\n * @public\n */\nexport function convexToJson(value: Value): JSONValue {\n return convexToJsonInternal(value, value, \"\", false);\n}\n\n// Convert a Convex value or `undefined` into its JSON representation.\n// `undefined` is used in filters to represent a missing object field.\nexport function convexOrUndefinedToJson(value: Value | undefined): JSONValue {\n return convexOrUndefinedToJsonInternal(value, value, \"\");\n}\n\n/**\n * Similar to convexToJson but also serializes top level undefined fields\n * using convexOrUndefinedToJson().\n *\n * @param value - A Convex value to convert into JSON.\n * @returns The JSON representation of `value`.\n */\nexport function patchValueToJson(value: Value): JSONValue {\n return convexToJsonInternal(value, value, \"\", true);\n}\n"],
|
|
5
|
+
"mappings": ";AAOA,YAAY,YAAY;AACxB,SAAS,sBAAsB;AAE/B,MAAM,gBAAgB;AAEtB,MAAM,YAAY,OAAO,sBAAsB;AACxC,aAAM,YAAY,OAAO,qBAAqB;AACrD,MAAM,OAAO,OAAO,GAAG;AACvB,MAAM,QAAQ,OAAO,GAAG;AACxB,MAAM,cAAc,OAAO,KAAK;AAmEhC,MAAM,uBACJ;AAaK,aAAM,oBAAoB;AAAA,EAI/B,CAAC,OAAO,WAAW,EAAE,MAAsB;AAEzC,QAAI,SAAS,UAAU;AACrB,aAAO,KAAK,SAAS;AAAA,IACvB;AACA,UAAM,IAAI,MAAM,oBAAoB;AAAA,EACtC;AAAA,EACA,UAAiB;AACf,UAAM,IAAI,MAAM,oBAAoB;AAAA,EACtC;AAAA,EACA,SAAgB;AACd,UAAM,IAAI,MAAM,oBAAoB;AAAA,EACtC;AAAA,EACA,WAAmB;AACjB,WAAO;AAAA,EACT;AACF;AASO,aAAM,sBAAsB,IAAI,oBAAoB;AAE3D,SAAS,UAAU,GAAW;AAC5B,SAAO,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,KAAK,OAAO,GAAG,GAAG,EAAE;AAClE;AAEO,gBAAS,mBAAmB,OAAuB;AAExD,MAAI,QAAQ,MAAM;AAChB,aAAS,YAAY;AAAA,EACvB;AACA,MAAI,MAAM,MAAM,SAAS,EAAE;AAC3B,MAAI,IAAI,SAAS,MAAM,EAAG,OAAM,MAAM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ACA,eACA;AACA,MAAI,SAAS;AACX,WAAO,GAAG,QAAQ,GAAG;AAAA,MACnB;AAAA,IACF,CAAC,oDAAoD,OAAO,uBAAuB;AAAA,MACjF;AAAA,IACF,CAAC;AAAA,EACH,OAAO;AACL,WAAO,GAAG,QAAQ,GAAG;AAAA,MACnB;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAIA,SAAS,gCACP,OACA,eACA,SACW;AACX,MAAI,UAAU,QAAW;AACvB,WAAO,EAAE,YAAY,KAAK;AAAA,EAC5B,OAAO;AACL,QAAI,kBAAkB,QAAW;AAE/B,YAAM,IAAI;AAAA,QACR,uCAAuC;AAAA,UACrC;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AACA,WAAO,qBAAqB,OAAO,eAAe,SAAS,KAAK;AAAA,EAClE;AACF;AAcO,gBAAS,aAAa,OAAyB;AACpD,SAAO,qBAAqB,OAAO,OAAO,IAAI,KAAK;AACrD;AAIO,gBAAS,wBAAwB,OAAqC;AAC3E,SAAO,gCAAgC,OAAO,OAAO,EAAE;AACzD;AASO,gBAAS,iBAAiB,OAAyB;AACxD,SAAO,qBAAqB,OAAO,OAAO,IAAI,IAAI;AACpD;",
|
|
6
6
|
"names": ["value"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/browser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,YAAY,EACV,uBAAuB,EACvB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/browser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,YAAY,EACV,uBAAuB,EACvB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAG1B,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EACV,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAG3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGvD,YAAY,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAGhE,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { Value } from "../../values/index.js";
|
|
13
13
|
import { PaginatedQueryToken } from "./udf_path_utils.js";
|
|
14
|
-
import {
|
|
14
|
+
import { Transition } from "./client.js";
|
|
15
15
|
import { PaginatedQueryResult } from "./pagination.js";
|
|
16
16
|
export interface SubscribeToPaginatedQueryOptions {
|
|
17
17
|
initialNumItems: number;
|
|
@@ -30,42 +30,5 @@ export type ExtendedTransition = Transition & {
|
|
|
30
30
|
modification: PaginatedQueryModification;
|
|
31
31
|
}>;
|
|
32
32
|
};
|
|
33
|
-
export declare class PaginatedQueryClient {
|
|
34
|
-
private client;
|
|
35
|
-
private onTransition;
|
|
36
|
-
private paginatedQuerySet;
|
|
37
|
-
private lastTransitionTs;
|
|
38
|
-
constructor(client: BaseConvexClient, onTransition: (transition: ExtendedTransition) => void);
|
|
39
|
-
/**
|
|
40
|
-
* Subscribe to a paginated query.
|
|
41
|
-
*
|
|
42
|
-
* @param name - The name of the paginated query function
|
|
43
|
-
* @param args - Arguments for the query (excluding paginationOpts)
|
|
44
|
-
* @param options - Pagination options including initialNumItems
|
|
45
|
-
* @returns Object with paginatedQueryToken and unsubscribe function
|
|
46
|
-
*/
|
|
47
|
-
subscribe(name: string, args: Record<string, Value>, options: SubscribeToPaginatedQueryOptions): {
|
|
48
|
-
paginatedQueryToken: PaginatedQueryToken;
|
|
49
|
-
unsubscribe: () => void;
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Get current results for a paginated query based on local state.
|
|
53
|
-
*
|
|
54
|
-
* Throws an error when one of the pages has errored.
|
|
55
|
-
*/
|
|
56
|
-
localQueryResult(name: string, args: Record<string, Value>, options: {
|
|
57
|
-
initialNumItems: number;
|
|
58
|
-
id: number;
|
|
59
|
-
}): AnyPaginatedQueryResult | undefined;
|
|
60
|
-
private onBaseTransition;
|
|
61
|
-
private splitPaginatedQueryPage;
|
|
62
|
-
private removePaginatedQuerySubscriber;
|
|
63
|
-
private completePaginatedQuerySplit;
|
|
64
|
-
/** The query tokens for all active pages, in result order */
|
|
65
|
-
private activePageQueryTokens;
|
|
66
|
-
private allQueryTokens;
|
|
67
|
-
private queryTokenForLastPageOfPaginatedQuery;
|
|
68
|
-
private mustGetPaginatedQuery;
|
|
69
|
-
}
|
|
70
33
|
export {};
|
|
71
34
|
//# sourceMappingURL=paginated_query_client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paginated_query_client.d.ts","sourceRoot":"","sources":["../../../../src/browser/sync/paginated_query_client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EACL,mBAAmB,EAIpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,
|
|
1
|
+
{"version":3,"file":"paginated_query_client.d.ts","sourceRoot":"","sources":["../../../../src/browser/sync/paginated_query_client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EACL,mBAAmB,EAIpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAA6B,UAAU,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EACL,oBAAoB,EAGrB,MAAM,iBAAiB,CAAC;AAkCzB,MAAM,WAAW,gCAAgC;IAC/C,eAAe,EAAE,MAAM,CAAC;IACxB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,KAAK,uBAAuB,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;AAE3D,MAAM,MAAM,0BAA0B,GAClC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,uBAAuB,GAAG,SAAS,CAAA;CAAE,GAChE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAExB,MAAM,MAAM,kBAAkB,GAAG,UAAU,GAAG;IAC5C,gBAAgB,EAAE,KAAK,CAAC;QACtB,KAAK,EAAE,mBAAmB,CAAC;QAC3B,YAAY,EAAE,0BAA0B,CAAC;KAC1C,CAAC,CAAC;CACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component_api.d.ts","sourceRoot":"","sources":["../../../../src/cli/codegen_templates/component_api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,EACL,kBAAkB,EAInB,MAAM,oDAAoD,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"component_api.d.ts","sourceRoot":"","sources":["../../../../src/cli/codegen_templates/component_api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,EACL,kBAAkB,EAInB,MAAM,oDAAoD,CAAC;AAC5D,OAAO,EA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/codegen_templates/validator_helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,GAAG,IAAI,GACvB,eAAe,GAAG,IAAI,CAMxB;AAED,wBAAgB,eAAe,CAC7B,SAAS,EAAE,eAAe,EAC1B,SAAS,EAAE,OAAO,GACjB,MAAM,
|
|
1
|
+
{"version":3,"file":"validator_helpers.d.ts","sourceRoot":"","sources":["../../../../src/cli/codegen_templates/validator_helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,GAAG,IAAI,GACvB,eAAe,GAAG,IAAI,CAMxB;AAED,wBAAgB,eAAe,CAC7B,SAAS,EAAE,eAAe,EAC1B,SAAS,EAAE,OAAO,GACjB,MAAM,CAwCR"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator_helpers.test.d.ts","sourceRoot":"","sources":["../../../../src/cli/codegen_templates/validator_helpers.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deployment.d.ts","sourceRoot":"","sources":["../../../src/cli/deployment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"deployment.d.ts","sourceRoot":"","sources":["../../../src/cli/deployment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAMtD,eAAO,MAAM,UAAU,qBAOG,CAAC"}
|
|
@@ -28,12 +28,12 @@ export declare function resolveRegionDetails(availableRegions: AvailableRegion[]
|
|
|
28
28
|
} | null;
|
|
29
29
|
export declare function fetchAvailableClasses(ctx: Context, teamId: number): Promise<{
|
|
30
30
|
available: boolean;
|
|
31
|
-
type: "s16" | "s256" | "d1024";
|
|
31
|
+
type: "s16" | "s256" | "d1024" | "d2048";
|
|
32
32
|
}[]>;
|
|
33
33
|
type AvailableClass = Awaited<ReturnType<typeof fetchAvailableClasses>>[number];
|
|
34
34
|
export declare function resolveClassDetails(availableClasses: AvailableClass[], className: string): {
|
|
35
35
|
available: boolean;
|
|
36
|
-
type: "s16" | "s256" | "d1024";
|
|
36
|
+
type: "s16" | "s256" | "d1024" | "d2048";
|
|
37
37
|
} | null;
|
|
38
38
|
export {};
|
|
39
39
|
//# sourceMappingURL=deploymentCreate.d.ts.map
|