@atproto/lex-schema 0.1.5 → 0.1.6
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 +14 -0
- package/dist/core/$type.d.ts +2 -2
- package/dist/core/$type.d.ts.map +1 -1
- package/dist/core/$type.js.map +1 -1
- package/dist/core/record-key.d.ts +1 -1
- package/dist/core/record-key.d.ts.map +1 -1
- package/dist/core/record-key.js.map +1 -1
- package/dist/core/schema.d.ts +3 -2
- package/dist/core/schema.d.ts.map +1 -1
- package/dist/core/schema.js +1 -1
- package/dist/core/schema.js.map +1 -1
- package/dist/core/standard-schema.d.ts +2 -2
- package/dist/core/standard-schema.d.ts.map +1 -1
- package/dist/core/standard-schema.js.map +1 -1
- package/dist/core/string-format.d.ts +2 -2
- package/dist/core/string-format.d.ts.map +1 -1
- package/dist/core/string-format.js.map +1 -1
- package/dist/core/validation-error.d.ts +1 -1
- package/dist/core/validation-error.d.ts.map +1 -1
- package/dist/core/validation-error.js +1 -1
- package/dist/core/validation-error.js.map +1 -1
- package/dist/core/validator.d.ts +1 -1
- package/dist/core/validator.d.ts.map +1 -1
- package/dist/core/validator.js +1 -1
- package/dist/core/validator.js.map +1 -1
- package/dist/helpers.d.ts +2 -2
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +2 -2
- package/dist/helpers.js.map +1 -1
- package/dist/schema/array.d.ts +1 -1
- package/dist/schema/array.d.ts.map +1 -1
- package/dist/schema/array.js +1 -1
- package/dist/schema/array.js.map +1 -1
- package/dist/schema/blob.d.ts +1 -1
- package/dist/schema/blob.d.ts.map +1 -1
- package/dist/schema/blob.js +2 -2
- package/dist/schema/blob.js.map +1 -1
- package/dist/schema/boolean.js +1 -1
- package/dist/schema/boolean.js.map +1 -1
- package/dist/schema/bytes.js +1 -1
- package/dist/schema/bytes.js.map +1 -1
- package/dist/schema/cid.d.ts +1 -1
- package/dist/schema/cid.d.ts.map +1 -1
- package/dist/schema/cid.js +3 -3
- package/dist/schema/cid.js.map +1 -1
- package/dist/schema/custom.js +1 -1
- package/dist/schema/custom.js.map +1 -1
- package/dist/schema/dict.d.ts +1 -1
- package/dist/schema/dict.d.ts.map +1 -1
- package/dist/schema/dict.js +1 -1
- package/dist/schema/dict.js.map +1 -1
- package/dist/schema/discriminated-union.d.ts +1 -1
- package/dist/schema/discriminated-union.d.ts.map +1 -1
- package/dist/schema/discriminated-union.js +2 -1
- package/dist/schema/discriminated-union.js.map +1 -1
- package/dist/schema/enum.js +1 -1
- package/dist/schema/enum.js.map +1 -1
- package/dist/schema/integer.js +1 -1
- package/dist/schema/integer.js.map +1 -1
- package/dist/schema/intersection.d.ts +1 -1
- package/dist/schema/intersection.d.ts.map +1 -1
- package/dist/schema/intersection.js +3 -1
- package/dist/schema/intersection.js.map +1 -1
- package/dist/schema/lex-map.d.ts +1 -1
- package/dist/schema/lex-map.d.ts.map +1 -1
- package/dist/schema/lex-map.js +1 -1
- package/dist/schema/lex-map.js.map +1 -1
- package/dist/schema/lex-value.d.ts +1 -1
- package/dist/schema/lex-value.d.ts.map +1 -1
- package/dist/schema/lex-value.js +1 -1
- package/dist/schema/lex-value.js.map +1 -1
- package/dist/schema/literal.js +1 -1
- package/dist/schema/literal.js.map +1 -1
- package/dist/schema/never.js +1 -1
- package/dist/schema/never.js.map +1 -1
- package/dist/schema/null.js +1 -1
- package/dist/schema/null.js.map +1 -1
- package/dist/schema/nullable.d.ts +1 -1
- package/dist/schema/nullable.d.ts.map +1 -1
- package/dist/schema/nullable.js +1 -1
- package/dist/schema/nullable.js.map +1 -1
- package/dist/schema/object.d.ts +2 -1
- package/dist/schema/object.d.ts.map +1 -1
- package/dist/schema/object.js +1 -1
- package/dist/schema/object.js.map +1 -1
- package/dist/schema/optional.d.ts +2 -1
- package/dist/schema/optional.d.ts.map +1 -1
- package/dist/schema/optional.js +2 -1
- package/dist/schema/optional.js.map +1 -1
- package/dist/schema/params.d.ts +1 -1
- package/dist/schema/params.d.ts.map +1 -1
- package/dist/schema/params.js +1 -1
- package/dist/schema/params.js.map +1 -1
- package/dist/schema/payload.d.ts +3 -2
- package/dist/schema/payload.d.ts.map +1 -1
- package/dist/schema/payload.js +2 -1
- package/dist/schema/payload.js.map +1 -1
- package/dist/schema/permission-set.d.ts +1 -1
- package/dist/schema/permission-set.d.ts.map +1 -1
- package/dist/schema/permission-set.js +1 -0
- package/dist/schema/permission-set.js.map +1 -1
- package/dist/schema/permission.d.ts +1 -1
- package/dist/schema/permission.d.ts.map +1 -1
- package/dist/schema/permission.js.map +1 -1
- package/dist/schema/procedure.d.ts +1 -1
- package/dist/schema/procedure.d.ts.map +1 -1
- package/dist/schema/procedure.js +2 -0
- package/dist/schema/procedure.js.map +1 -1
- package/dist/schema/query.d.ts +1 -1
- package/dist/schema/query.d.ts.map +1 -1
- package/dist/schema/query.js +2 -0
- package/dist/schema/query.js.map +1 -1
- package/dist/schema/record.d.ts +2 -2
- package/dist/schema/record.d.ts.map +1 -1
- package/dist/schema/record.js +1 -1
- package/dist/schema/record.js.map +1 -1
- package/dist/schema/ref.d.ts +1 -1
- package/dist/schema/ref.d.ts.map +1 -1
- package/dist/schema/ref.js +1 -1
- package/dist/schema/ref.js.map +1 -1
- package/dist/schema/refine.d.ts +2 -2
- package/dist/schema/refine.d.ts.map +1 -1
- package/dist/schema/refine.js +1 -1
- package/dist/schema/refine.js.map +1 -1
- package/dist/schema/regexp.js +1 -1
- package/dist/schema/regexp.js.map +1 -1
- package/dist/schema/string.d.ts +2 -2
- package/dist/schema/string.d.ts.map +1 -1
- package/dist/schema/string.js +1 -1
- package/dist/schema/string.js.map +1 -1
- package/dist/schema/subscription.d.ts +3 -2
- package/dist/schema/subscription.d.ts.map +1 -1
- package/dist/schema/subscription.js +2 -0
- package/dist/schema/subscription.js.map +1 -1
- package/dist/schema/token.d.ts +1 -1
- package/dist/schema/token.d.ts.map +1 -1
- package/dist/schema/token.js +1 -1
- package/dist/schema/token.js.map +1 -1
- package/dist/schema/typed-object.d.ts +2 -2
- package/dist/schema/typed-object.d.ts.map +1 -1
- package/dist/schema/typed-object.js +1 -1
- package/dist/schema/typed-object.js.map +1 -1
- package/dist/schema/typed-ref.d.ts +1 -1
- package/dist/schema/typed-ref.d.ts.map +1 -1
- package/dist/schema/typed-ref.js +1 -1
- package/dist/schema/typed-ref.js.map +1 -1
- package/dist/schema/typed-union.d.ts +1 -1
- package/dist/schema/typed-union.d.ts.map +1 -1
- package/dist/schema/typed-union.js +3 -1
- package/dist/schema/typed-union.js.map +1 -1
- package/dist/schema/union.d.ts +1 -1
- package/dist/schema/union.d.ts.map +1 -1
- package/dist/schema/union.js +1 -1
- package/dist/schema/union.js.map +1 -1
- package/dist/schema/unknown.js +1 -1
- package/dist/schema/unknown.js.map +1 -1
- package/dist/schema/with-default.d.ts +1 -1
- package/dist/schema/with-default.d.ts.map +1 -1
- package/dist/schema/with-default.js +1 -1
- package/dist/schema/with-default.js.map +1 -1
- package/package.json +6 -10
- package/src/core/$type.test.ts +0 -24
- package/src/core/$type.ts +0 -199
- package/src/core/record-key.ts +0 -85
- package/src/core/result.ts +0 -15
- package/src/core/schema.ts +0 -412
- package/src/core/standard-schema.test.ts +0 -124
- package/src/core/standard-schema.ts +0 -31
- package/src/core/string-format.ts +0 -411
- package/src/core/types.ts +0 -120
- package/src/core/validation-error.ts +0 -134
- package/src/core/validation-issue.ts +0 -340
- package/src/core/validator.ts +0 -636
- package/src/core.ts +0 -9
- package/src/external.ts +0 -3
- package/src/helpers.test.ts +0 -694
- package/src/helpers.ts +0 -222
- package/src/index.ts +0 -3
- package/src/schema/array.test.ts +0 -251
- package/src/schema/array.ts +0 -126
- package/src/schema/blob.test.ts +0 -733
- package/src/schema/blob.ts +0 -150
- package/src/schema/boolean.test.ts +0 -118
- package/src/schema/boolean.ts +0 -46
- package/src/schema/bytes.test.ts +0 -227
- package/src/schema/bytes.ts +0 -81
- package/src/schema/cid.test.ts +0 -125
- package/src/schema/cid.ts +0 -69
- package/src/schema/custom.test.ts +0 -414
- package/src/schema/custom.ts +0 -106
- package/src/schema/dict.test.ts +0 -181
- package/src/schema/dict.ts +0 -122
- package/src/schema/discriminated-union.test.ts +0 -676
- package/src/schema/discriminated-union.ts +0 -196
- package/src/schema/enum.test.ts +0 -398
- package/src/schema/enum.ts +0 -77
- package/src/schema/integer.test.ts +0 -314
- package/src/schema/integer.ts +0 -86
- package/src/schema/intersection.test.ts +0 -33
- package/src/schema/intersection.ts +0 -113
- package/src/schema/lex-map.test.ts +0 -593
- package/src/schema/lex-map.ts +0 -63
- package/src/schema/lex-value.test.ts +0 -81
- package/src/schema/lex-value.ts +0 -86
- package/src/schema/literal.test.ts +0 -533
- package/src/schema/literal.ts +0 -70
- package/src/schema/never.test.ts +0 -175
- package/src/schema/never.ts +0 -56
- package/src/schema/null.test.ts +0 -80
- package/src/schema/null.ts +0 -49
- package/src/schema/nullable.test.ts +0 -470
- package/src/schema/nullable.ts +0 -74
- package/src/schema/object.test.ts +0 -69
- package/src/schema/object.ts +0 -136
- package/src/schema/optional.test.ts +0 -479
- package/src/schema/optional.ts +0 -92
- package/src/schema/params.test.ts +0 -1118
- package/src/schema/params.ts +0 -371
- package/src/schema/payload.test.ts +0 -340
- package/src/schema/payload.ts +0 -204
- package/src/schema/permission-set.test.ts +0 -613
- package/src/schema/permission-set.ts +0 -86
- package/src/schema/permission.test.ts +0 -537
- package/src/schema/permission.ts +0 -63
- package/src/schema/procedure.test.ts +0 -324
- package/src/schema/procedure.ts +0 -98
- package/src/schema/query.test.ts +0 -348
- package/src/schema/query.ts +0 -86
- package/src/schema/record.test.ts +0 -812
- package/src/schema/record.ts +0 -217
- package/src/schema/ref.test.ts +0 -349
- package/src/schema/ref.ts +0 -103
- package/src/schema/refine.test.ts +0 -579
- package/src/schema/refine.ts +0 -153
- package/src/schema/regexp.test.ts +0 -577
- package/src/schema/regexp.ts +0 -82
- package/src/schema/string.test.ts +0 -773
- package/src/schema/string.ts +0 -229
- package/src/schema/subscription.test.ts +0 -499
- package/src/schema/subscription.ts +0 -108
- package/src/schema/token.test.ts +0 -152
- package/src/schema/token.ts +0 -103
- package/src/schema/typed-object.test.ts +0 -745
- package/src/schema/typed-object.ts +0 -181
- package/src/schema/typed-ref.test.ts +0 -796
- package/src/schema/typed-ref.ts +0 -126
- package/src/schema/typed-union.test.ts +0 -355
- package/src/schema/typed-union.ts +0 -130
- package/src/schema/union.test.ts +0 -191
- package/src/schema/union.ts +0 -89
- package/src/schema/unknown.test.ts +0 -313
- package/src/schema/unknown.ts +0 -47
- package/src/schema/with-default.ts +0 -81
- package/src/schema.ts +0 -43
- package/src/util/array-agg.test.ts +0 -42
- package/src/util/array-agg.ts +0 -44
- package/src/util/assertion-util.ts +0 -1
- package/src/util/if-any.ts +0 -3
- package/src/util/lazy-property.ts +0 -14
- package/src/util/memoize.ts +0 -37
- package/tsconfig.build.json +0 -12
- package/tsconfig.json +0 -7
- package/tsconfig.tests.json +0 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/core/validator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,EAEL,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,EACX,aAAa,GAEd,MAAM,uBAAuB,CAAA;AAkL9B;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,OAAO,iBAAiB;IAqD5B,MAAM,CAAC,QAAQ,CACb,KAAc,EACd,SAAY,EACZ,OAA2B;QAE3B,MAAM,OAAO,GAAG,IAAI,iBAAiB,CAAC;YACpC,IAAI,EAAE,OAAO,EAAE,IAAI,IAAI,EAAE;YACzB,IAAI,EAAE,OAAO,EAAE,IAAI,IAAI,UAAU;YACjC,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,IAAI;SAChC,CAAC,CAAA;QACF,OAAO,OAAO,CAAC,QAAQ,CAA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Q,EACR,QAA+B,EAC/B,MAA0B;QAE1B,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAA;QAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;QACtC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,iBAAiB,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAA;IAC/D,CAAC;IAED;;;;;;;;;;;OAWG;IACH,wBAAwB,CACtB,KAAQ,EACR,QAA+B,EAC/B,QAAgB;QAEhB,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAA;QAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;QACtC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,gBAAgB,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;IAClE,CAAC;CACF","sourcesContent":["import type * as Result from './result.js'\nimport { LexValidationError } from './validation-error.js'\nimport {\n Issue,\n IssueInvalidFormat,\n IssueInvalidType,\n IssueInvalidValue,\n IssueRequiredKey,\n IssueTooBig,\n IssueTooSmall,\n MeasurableType,\n} from './validation-issue.js'\n\n/**\n * Represents a successful validation result.\n *\n * @typeParam TValue - The type of the validated value\n * @extends Result.ResultSuccess<TValue>\n */\nexport type ValidationSuccess<TValue = unknown> = Result.ResultSuccess<TValue>\n\n/**\n * Represents a failed validation result containing a {@link LexValidationError}.\n *\n * @see {@link LexValidationError}\n * @extends Result.ResultFailure<LexValidationError>\n */\nexport type ValidationFailure = LexValidationError\n\n/**\n * Discriminated union representing the outcome of a validation operation.\n *\n * Check the `success` property to determine if validation passed or failed:\n * - If `success` is `true`, the `value` property contains the validated data\n * - If `success` is `false`, the `reason` property contains the {@link LexValidationError}\n *\n * @typeParam Value - The type of the validated value on success\n *\n * @example\n * ```typescript\n * const result: ValidationResult<string> = schema.safeParse(data)\n * if (result.success) {\n * // result.value is string\n * } else {\n * // result.reason is LexValidationError\n * }\n * ```\n */\nexport type ValidationResult<Value = unknown> =\n | ValidationSuccess<Value>\n | ValidationFailure\n\n/**\n * Extracts the input type that a validator accepts.\n *\n * Use this utility type to infer what type a schema will accept during validation.\n *\n * @typeParam V - A validator type\n *\n * @example\n * ```typescript\n * const userSchema = new ObjectSchema({ name: stringSchema, age: numberSchema })\n * type UserInput = InferInput<typeof userSchema>\n * // { name: string; age: number }\n * ```\n */\nexport type InferInput<V extends Validator> = V['__lex']['input']\n\n/**\n * Extracts the output type that a validator produces after parsing.\n *\n * The output type may differ from the input type when the schema applies\n * transformations such as default values or type coercion during parsing.\n *\n * @typeParam V - A validator type\n *\n * @example\n * ```typescript\n * const schema = new StringSchema().default('hello')\n * type Input = InferInput<typeof schema> // string | undefined\n * type Output = InferOutput<typeof schema> // string\n * ```\n */\nexport type InferOutput<V extends Validator> = V['__lex']['output']\n\n/**\n * Alias for {@link InferInput} for convenient type inference.\n *\n * @typeParam V - A validator type\n */\nexport type { InferInput as Infer }\n\nexport interface Validator<TInput = unknown, TOutput = TInput> {\n /**\n * This property is used for type inference purposes and does not actually\n * exist at runtime.\n *\n * @internal\n * @deprecated **INTERNAL API, DO NOT USE**.\n */\n readonly ['__lex']: {\n input: TInput\n output: TOutput\n }\n\n /**\n * @internal **INTERNAL API**: use {@link ValidationContext.validate} instead\n *\n * This method is implemented by subclasses to perform transformation and\n * validation of the input value. Do not call this method directly; as the\n * {@link ValidationContext.options.mode} option will **not** be enforced. See\n * {@link ValidationContext.validate} for details. When delegating validation\n * from one validator sub-class implementation to another schema,\n * {@link ValidationContext.validate} must be used instead of calling\n * {@link Validator.validateInContext}. This will allow to stop the validation\n * process if the value was transformed (by the other schema) but\n * transformations are not allowed.\n *\n * By convention, the {@link ValidationResult} must return the original input\n * value if validation was successful and no transformation was applied (i.e.\n * the input already conformed to the schema). If a default value, or any\n * other transformation was applied, the returned value can be different from\n * the input.\n *\n * This convention allows the {@link Validator.check check} and\n * {@link Validator.assert assert} methods to check whether the input value\n * exactly matches the schema (without defaults or transformations), by\n * checking if the returned value is strictly equal to the input.\n *\n * @see {@link ValidationContext.validate}\n */\n validateInContext(input: unknown, ctx: ValidationContext): ValidationResult\n}\n\n/**\n * Configuration options for validation and parsing operations.\n *\n * @example\n * ```typescript\n * // Validate mode (strict, no transformations)\n * ValidationContext.validate(data, schema, { mode: 'validate' })\n *\n * // Parse mode (allows transformations like defaults)\n * ValidationContext.validate(data, schema, { mode: 'parse' })\n *\n * // With initial path for nested validation\n * ValidationContext.validate(data, schema, { path: ['user', 'profile'] })\n * ```\n */\nexport type ValidationOptions = {\n /**\n * The validation mode determining how transformations are handled.\n *\n * - `\"validate\"`: Strict validation where the result must be\n * strictly equal to the input value. No transformations such as applying\n * default values are allowed.\n * - `\"parse\"`: Allows the schema to transform the input value, such as\n * applying default values or performing type coercion.\n *\n * @default \"validate\"\n */\n mode?: 'validate' | 'parse'\n\n /**\n * The initial path to the value being validated.\n *\n * This is used to provide context in validation issues when validating\n * nested structures. The path is prepended to all issue paths.\n *\n * @example\n * ```typescript\n * // Issues will be reported at paths like \"user.name\" instead of just \"name\"\n * ValidationContext.validate(data, schema, { path: ['user'] })\n * ```\n */\n path?: readonly PropertyKey[]\n\n /**\n * Whether to enforce strict validation rules (e.g., MIME type matching, size\n * limits, datetime format).\n *\n * This is typically useful to allow more lax validation when parsing server\n * responses, while enforcing strict validation for user input.\n *\n * @default true\n */\n strict?: boolean\n}\n\n/**\n * Manages the state and context for validation operations.\n *\n * The `ValidationContext` class is responsible for:\n * - Tracking the current path in nested structures for error reporting\n * - Collecting validation issues during traversal\n * - Enforcing validation mode (validate vs parse)\n * - Providing factory methods for creating validation results\n *\n * Use the static {@link ValidationContext.validate} method as the primary entry point\n * for validation. This ensures proper mode enforcement and issue aggregation.\n *\n * @example\n * ```typescript\n * // Primary usage via static method\n * const result = ValidationContext.validate(data, schema, { mode: 'parse' })\n *\n * // Within a custom validator implementation\n * class MyValidator implements Validator {\n * validateInContext(input: unknown, ctx: ValidationContext): ValidationResult {\n * if (typeof input !== 'string') {\n * return ctx.issueUnexpectedType(input, 'string')\n * }\n * return ctx.success(input)\n * }\n * }\n * ```\n */\nexport class ValidationContext {\n /**\n * Validates input against a validator in parse mode.\n *\n * In parse mode, the schema may transform the input (e.g., apply defaults).\n *\n * @param input - The value to validate\n * @param validator - The validator to use\n * @param options - Validation options with mode set to 'parse'\n * @returns A validation result with the parsed output type\n */\n static validate<V extends Validator>(\n input: unknown,\n validator: V,\n options: ValidationOptions & {\n mode: 'parse'\n },\n ): ValidationResult<InferOutput<V>>\n\n /**\n * Validates input against a validator in validate mode (default).\n *\n * In validate mode, the result must be strictly equal to the input.\n * No transformations are allowed.\n *\n * @typeParam V - The validator type\n * @typeParam I - The input type\n * @param input - The value to validate\n * @param validator - The validator to use\n * @param options - Optional validation options (defaults to validate mode)\n * @returns A validation result preserving the input type intersected with the schema type\n */\n static validate<V extends Validator, I = unknown>(\n input: I,\n validator: V,\n options?: ValidationOptions & {\n mode?: 'validate'\n },\n ): ValidationResult<I & InferInput<V>>\n\n /**\n * Validates input against a validator with configurable options.\n *\n * @param input - The value to validate\n * @param validator - The validator to use\n * @param options - Optional validation options\n * @returns A validation result with either the input or output type\n */\n static validate<V extends Validator>(\n input: unknown,\n validator: V,\n options?: ValidationOptions,\n ): ValidationResult<InferOutput<V> | InferInput<V>>\n static validate<V extends Validator>(\n input: unknown,\n validator: V,\n options?: ValidationOptions,\n ): ValidationResult<InferOutput<V> | InferInput<V>> {\n const context = new ValidationContext({\n path: options?.path ?? [],\n mode: options?.mode ?? 'validate',\n strict: options?.strict ?? true,\n })\n return context.validate(input, validator)\n }\n\n /**\n * The current path being validated, used for error reporting.\n */\n protected readonly currentPath: PropertyKey[]\n\n /**\n * Accumulated validation issues collected during traversal.\n */\n protected readonly issues: Issue[] = []\n\n /**\n * Creates a new validation context with the specified options.\n *\n * @param options - The validation options (path and mode are required)\n */\n constructor(readonly options: Required<ValidationOptions>) {\n // Create a copy because we will be mutating the array during validation.\n this.currentPath = Array.from(options.path)\n }\n\n /**\n * Returns a copy of the current validation path.\n *\n * The path represents the location in the data structure being validated,\n * used for constructing meaningful error messages.\n */\n get path() {\n return Array.from(this.currentPath)\n }\n\n /**\n * Creates a new path by appending segments to the current path.\n *\n * @param path - Optional path segment(s) to append\n * @returns A new path array with the segment(s) appended\n */\n concatPath(path?: PropertyKey | readonly PropertyKey[]) {\n if (path == null) return this.path\n return this.currentPath.concat(path)\n }\n\n /**\n * Validates input against a validator within this context.\n *\n * This is the primary entry point for validation within a context. Always use\n * this method instead of calling {@link Validator.validateInContext} directly,\n * as this method enforces validation mode rules and handles transformation detection.\n *\n * @typeParam V - The validator type\n * @param input - The value to validate\n * @param validator - The validator to use\n * @returns A validation result with the validated value or error\n */\n validate<V extends Validator>(\n input: unknown,\n validator: V,\n ): ValidationResult<InferInput<V>> {\n // This is the only place where validateInContext should be called.\n const result = validator.validateInContext(input, this)\n\n if (result.success) {\n if (this.issues.length > 0) {\n // Validator returned a success but issues were added via the context.\n // This means the overall validation failed.\n return new LexValidationError(Array.from(this.issues))\n }\n\n if (this.options.mode !== 'parse' && !Object.is(result.value, input)) {\n // If the value changed, it means that a default (or some other\n // transformation) was applied, meaning that the original value did\n // *not* match the (output) schema. When not in \"parse\" mode, we\n // consider this a failure.\n\n // This check is the reason why Validator.validateInContext should not\n // be used directly, and ValidatorContext.validate should be used\n // instead, even when delegating validation from one validator to\n // another.\n\n // This if block comes before the next one because 'this.issues' will\n // end-up being appended to the returned LexValidationError (see the\n // \"failure\" method below), resulting in a more complete error report.\n return this.issueInvalidValue(input, [result.value])\n }\n }\n\n return result as ValidationResult<InferInput<V>>\n }\n\n /**\n * Validates a child property of an object within this context.\n *\n * This method automatically manages the path stack, pushing the property key\n * before validation and popping it afterward. Use this for validating object\n * properties to ensure proper path tracking in error messages.\n *\n * @typeParam I - The input object type\n * @typeParam K - The property key type\n * @typeParam V - The validator type\n * @param input - The parent object containing the property\n * @param key - The property key to validate\n * @param validator - The validator to use for the property value\n * @returns A validation result for the property value\n *\n * @example\n * ```typescript\n * // In a custom object validator\n * const result = ctx.validateChild(input, 'name', stringSchema)\n * // If validation fails, error path will include 'name'\n * ```\n */\n validateChild<\n I extends object,\n K extends PropertyKey & keyof I,\n V extends Validator,\n >(input: I, key: K, validator: V): ValidationResult<InferInput<V>> {\n // @NOTE we could add support for recursive schemas by keeping track of\n // \"parent\" objects in the context and checking for circular references\n // here. This would allow us to validate recursive structures without\n // hitting maximum call stack errors, and would also allow us to provide\n // better error messages for circular reference issues. However, this is not\n // a priority at the moment as recursive structures are not supported in\n // the context of AT Protocol lexicons, and we can always add this in the\n // future if needed.\n\n // Instead of creating a new context, we just push/pop the path segment.\n this.currentPath.push(key)\n try {\n return this.validate(input[key], validator)\n } finally {\n this.currentPath.length--\n }\n }\n\n /**\n * Adds a validation issue to the context without immediately failing.\n *\n * Use this method to collect multiple issues during validation before\n * determining the final result. Issues added this way will be included\n * in the final error if validation fails.\n *\n * @param issue - The validation issue to add\n */\n addIssue(issue: Issue): void {\n this.issues.push(issue)\n }\n\n /**\n * Helper method to create a successful validation result.\n *\n * @typeParam V - The value type\n * @param value - The validated value\n * @returns A successful validation result\n */\n success<V>(value: V): ValidationSuccess<V> {\n return { success: true, value }\n }\n\n /**\n * Creates a failed validation result from a single issue.\n *\n * Any previously accumulated issues in the context are included in the error.\n *\n * @param issue - The validation issue that caused the failure\n * @returns A failed validation result\n */\n issue(issue: Issue): ValidationFailure {\n return new LexValidationError([...this.issues, issue])\n }\n\n /**\n * Creates a failure for an invalid value that doesn't match expected values.\n *\n * @param input - The actual value that was received\n * @param values - The expected valid values\n * @returns A failed validation result with an invalid value issue\n */\n issueInvalidValue(input: unknown, values: readonly unknown[]) {\n return this.issue(new IssueInvalidValue(this.path, input, values))\n }\n\n /**\n * Creates a failure for an invalid type.\n *\n * @param input - The actual value that was received\n * @param expected - An array of expected type names\n * @returns A failed validation result with an invalid type issue\n */\n issueInvalidType(input: unknown, expected: readonly string[]) {\n return this.issue(new IssueInvalidType(this.path, input, expected))\n }\n\n /**\n * Creates a failure for an invalid type.\n *\n * @param input - The actual value that was received\n * @param expected - The expected type name\n * @returns A failed validation result with an invalid type issue\n */\n issueUnexpectedType(input: unknown, expected: string) {\n return this.issueInvalidType(input, [expected])\n }\n\n /**\n * Creates a failure for a missing required key in an object.\n *\n * @param input - The object missing the required key\n * @param key - The name of the required key\n * @returns A failed validation result with a required key issue\n */\n issueRequiredKey(input: object, key: PropertyKey) {\n return this.issue(new IssueRequiredKey(this.path, input, key))\n }\n\n /**\n * Creates a failure for an invalid string format.\n *\n * @param input - The actual value that was received\n * @param format - The expected format name (e.g., 'did', 'handle', 'uri')\n * @param msg - Optional additional message describing the format error\n * @returns A failed validation result with an invalid format issue\n */\n issueInvalidFormat(input: unknown, format: string, msg?: string) {\n return this.issue(new IssueInvalidFormat(this.path, input, format, msg))\n }\n\n /**\n * Creates a failure for a value that exceeds a maximum constraint.\n *\n * @param input - The actual value that was received\n * @param type - The type of measurement (e.g., 'string', 'array', 'bytes')\n * @param max - The maximum allowed value\n * @param actual - The actual measured value\n * @returns A failed validation result with a too big issue\n */\n issueTooBig(\n input: unknown,\n type: MeasurableType,\n max: number,\n actual: number,\n ) {\n return this.issue(new IssueTooBig(this.path, input, max, type, actual))\n }\n\n /**\n * Creates a failure for a value that is below a minimum constraint.\n *\n * @param input - The actual value that was received\n * @param type - The type of measurement (e.g., 'string', 'array', 'bytes')\n * @param min - The minimum required value\n * @param actual - The actual measured value\n * @returns A failed validation result with a too small issue\n */\n issueTooSmall(\n input: unknown,\n type: MeasurableType,\n min: number,\n actual: number,\n ) {\n return this.issue(new IssueTooSmall(this.path, input, min, type, actual))\n }\n\n /**\n * Creates a failure for an invalid property value within an object.\n *\n * This is a convenience method that automatically extracts the property value\n * and constructs the appropriate path.\n *\n * @typeParam I - The input object type\n * @param input - The object containing the invalid property\n * @param property - The property key with the invalid value\n * @param values - The expected valid values\n * @returns A failed validation result with an invalid value issue at the property path\n */\n issueInvalidPropertyValue<I>(\n input: I,\n property: keyof I & PropertyKey,\n values: readonly unknown[],\n ) {\n const value = input[property]\n const path = this.concatPath(property)\n return this.issue(new IssueInvalidValue(path, value, values))\n }\n\n /**\n * Creates a failure for an invalid property type within an object.\n *\n * This is a convenience method that automatically extracts the property value\n * and constructs the appropriate path.\n *\n * @typeParam I - The input object type\n * @param input - The object containing the invalid property\n * @param property - The property key with the invalid type\n * @param expected - The expected type name\n * @returns A failed validation result with an invalid type issue at the property path\n */\n issueInvalidPropertyType<I>(\n input: I,\n property: keyof I & PropertyKey,\n expected: string,\n ) {\n const value = input[property]\n const path = this.concatPath(property)\n return this.issue(new IssueInvalidType(path, value, [expected]))\n }\n}\n\n/**\n * Recursively unwraps a wrapped validator to its innermost validator type.\n *\n * Some validators wrap other validators (e.g., optional, nullable). This type\n * utility recursively unwraps such wrappers to reveal the core validator.\n *\n * @typeParam T - A validator type, possibly wrapped\n *\n * @example\n * ```typescript\n * type Inner = UnwrapValidator<OptionalValidator<NullableValidator<StringSchema>>>\n * // Result: StringSchema\n * ```\n */\nexport type UnwrapValidator<T extends Validator> = T extends {\n unwrap(): infer U extends Validator\n}\n ? UnwrapValidator<U>\n : T\n\n/**\n * Interface for validators that wrap another validator.\n *\n * Implement this interface when creating validators that wrap or modify\n * the behavior of another validator (e.g., optional, nullable, transform).\n *\n * @typeParam Validator - The type of the wrapped validator\n *\n * @example\n * ```typescript\n * class OptionalSchema<V extends Validator> implements WrappedValidator<V> {\n * constructor(private inner: V) {}\n *\n * unwrap(): V {\n * return this.inner\n * }\n * }\n * ```\n */\nexport interface WrappedValidator<out Validator> {\n /**\n * Returns the inner wrapped validator.\n *\n * @returns The wrapped validator\n */\n unwrap(): Validator\n}\n"]}
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/core/validator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kB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E,GAAG,CAAC,CAAC,CAAA;IAC1E,CAAC;IAED;;;;;;;;OAQG;IACH,WAAW,CACT,KAAc,EACd,IAAoB,EACpB,GAAW,EACX,MAAc;QAEd,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAA;IACzE,CAAC;IAED;;;;;;;;OAQG;IACH,aAAa,CACX,KAAc,EACd,IAAoB,EACpB,GAAW,EACX,MAAc;QAEd,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAA;IAC3E,CAAC;IAED;;;;;;;;;;;OAWG;IACH,yBAAyB,CACvB,KAAQ,EACR,QAA+B,EAC/B,MAA0B;QAE1B,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAA;QAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;QACtC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,iBAAiB,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAA;IAC/D,CAAC;IAED;;;;;;;;;;;OAWG;IACH,wBAAwB,CACtB,KAAQ,EACR,QAA+B,EAC/B,QAAgB;QAEhB,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAA;QAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;QACtC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,gBAAgB,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;IAClE,CAAC;CACF","sourcesContent":["import type * as Result from './result.js'\nimport { LexValidationError } from './validation-error.js'\nimport {\n Issue,\n IssueInvalidFormat,\n IssueInvalidType,\n IssueInvalidValue,\n IssueRequiredKey,\n IssueTooBig,\n IssueTooSmall,\n type MeasurableType,\n} from './validation-issue.js'\n\n/**\n * Represents a successful validation result.\n *\n * @typeParam TValue - The type of the validated value\n * @extends Result.ResultSuccess<TValue>\n */\nexport type ValidationSuccess<TValue = unknown> = Result.ResultSuccess<TValue>\n\n/**\n * Represents a failed validation result containing a {@link LexValidationError}.\n *\n * @see {@link LexValidationError}\n * @extends Result.ResultFailure<LexValidationError>\n */\nexport type ValidationFailure = LexValidationError\n\n/**\n * Discriminated union representing the outcome of a validation operation.\n *\n * Check the `success` property to determine if validation passed or failed:\n * - If `success` is `true`, the `value` property contains the validated data\n * - If `success` is `false`, the `reason` property contains the {@link LexValidationError}\n *\n * @typeParam Value - The type of the validated value on success\n *\n * @example\n * ```typescript\n * const result: ValidationResult<string> = schema.safeParse(data)\n * if (result.success) {\n * // result.value is string\n * } else {\n * // result.reason is LexValidationError\n * }\n * ```\n */\nexport type ValidationResult<Value = unknown> =\n | ValidationSuccess<Value>\n | ValidationFailure\n\n/**\n * Extracts the input type that a validator accepts.\n *\n * Use this utility type to infer what type a schema will accept during validation.\n *\n * @typeParam V - A validator type\n *\n * @example\n * ```typescript\n * const userSchema = new ObjectSchema({ name: stringSchema, age: numberSchema })\n * type UserInput = InferInput<typeof userSchema>\n * // { name: string; age: number }\n * ```\n */\nexport type InferInput<V extends Validator> = V['__lex']['input']\n\n/**\n * Extracts the output type that a validator produces after parsing.\n *\n * The output type may differ from the input type when the schema applies\n * transformations such as default values or type coercion during parsing.\n *\n * @typeParam V - A validator type\n *\n * @example\n * ```typescript\n * const schema = new StringSchema().default('hello')\n * type Input = InferInput<typeof schema> // string | undefined\n * type Output = InferOutput<typeof schema> // string\n * ```\n */\nexport type InferOutput<V extends Validator> = V['__lex']['output']\n\n/**\n * Alias for {@link InferInput} for convenient type inference.\n *\n * @typeParam V - A validator type\n */\nexport type { InferInput as Infer }\n\nexport interface Validator<TInput = unknown, TOutput = TInput> {\n /**\n * This property is used for type inference purposes and does not actually\n * exist at runtime.\n *\n * @internal\n * @deprecated **INTERNAL API, DO NOT USE**.\n */\n readonly ['__lex']: {\n input: TInput\n output: TOutput\n }\n\n /**\n * @internal **INTERNAL API**: use {@link ValidationContext.validate} instead\n *\n * This method is implemented by subclasses to perform transformation and\n * validation of the input value. Do not call this method directly; as the\n * {@link ValidationContext.options.mode} option will **not** be enforced. See\n * {@link ValidationContext.validate} for details. When delegating validation\n * from one validator sub-class implementation to another schema,\n * {@link ValidationContext.validate} must be used instead of calling\n * {@link Validator.validateInContext}. This will allow to stop the validation\n * process if the value was transformed (by the other schema) but\n * transformations are not allowed.\n *\n * By convention, the {@link ValidationResult} must return the original input\n * value if validation was successful and no transformation was applied (i.e.\n * the input already conformed to the schema). If a default value, or any\n * other transformation was applied, the returned value can be different from\n * the input.\n *\n * This convention allows the {@link Validator.check check} and\n * {@link Validator.assert assert} methods to check whether the input value\n * exactly matches the schema (without defaults or transformations), by\n * checking if the returned value is strictly equal to the input.\n *\n * @see {@link ValidationContext.validate}\n */\n validateInContext(input: unknown, ctx: ValidationContext): ValidationResult\n}\n\n/**\n * Configuration options for validation and parsing operations.\n *\n * @example\n * ```typescript\n * // Validate mode (strict, no transformations)\n * ValidationContext.validate(data, schema, { mode: 'validate' })\n *\n * // Parse mode (allows transformations like defaults)\n * ValidationContext.validate(data, schema, { mode: 'parse' })\n *\n * // With initial path for nested validation\n * ValidationContext.validate(data, schema, { path: ['user', 'profile'] })\n * ```\n */\nexport type ValidationOptions = {\n /**\n * The validation mode determining how transformations are handled.\n *\n * - `\"validate\"`: Strict validation where the result must be\n * strictly equal to the input value. No transformations such as applying\n * default values are allowed.\n * - `\"parse\"`: Allows the schema to transform the input value, such as\n * applying default values or performing type coercion.\n *\n * @default \"validate\"\n */\n mode?: 'validate' | 'parse'\n\n /**\n * The initial path to the value being validated.\n *\n * This is used to provide context in validation issues when validating\n * nested structures. The path is prepended to all issue paths.\n *\n * @example\n * ```typescript\n * // Issues will be reported at paths like \"user.name\" instead of just \"name\"\n * ValidationContext.validate(data, schema, { path: ['user'] })\n * ```\n */\n path?: readonly PropertyKey[]\n\n /**\n * Whether to enforce strict validation rules (e.g., MIME type matching, size\n * limits, datetime format).\n *\n * This is typically useful to allow more lax validation when parsing server\n * responses, while enforcing strict validation for user input.\n *\n * @default true\n */\n strict?: boolean\n}\n\n/**\n * Manages the state and context for validation operations.\n *\n * The `ValidationContext` class is responsible for:\n * - Tracking the current path in nested structures for error reporting\n * - Collecting validation issues during traversal\n * - Enforcing validation mode (validate vs parse)\n * - Providing factory methods for creating validation results\n *\n * Use the static {@link ValidationContext.validate} method as the primary entry point\n * for validation. This ensures proper mode enforcement and issue aggregation.\n *\n * @example\n * ```typescript\n * // Primary usage via static method\n * const result = ValidationContext.validate(data, schema, { mode: 'parse' })\n *\n * // Within a custom validator implementation\n * class MyValidator implements Validator {\n * validateInContext(input: unknown, ctx: ValidationContext): ValidationResult {\n * if (typeof input !== 'string') {\n * return ctx.issueUnexpectedType(input, 'string')\n * }\n * return ctx.success(input)\n * }\n * }\n * ```\n */\nexport class ValidationContext {\n /**\n * Validates input against a validator in parse mode.\n *\n * In parse mode, the schema may transform the input (e.g., apply defaults).\n *\n * @param input - The value to validate\n * @param validator - The validator to use\n * @param options - Validation options with mode set to 'parse'\n * @returns A validation result with the parsed output type\n */\n static validate<V extends Validator>(\n input: unknown,\n validator: V,\n options: ValidationOptions & {\n mode: 'parse'\n },\n ): ValidationResult<InferOutput<V>>\n\n /**\n * Validates input against a validator in validate mode (default).\n *\n * In validate mode, the result must be strictly equal to the input.\n * No transformations are allowed.\n *\n * @typeParam V - The validator type\n * @typeParam I - The input type\n * @param input - The value to validate\n * @param validator - The validator to use\n * @param options - Optional validation options (defaults to validate mode)\n * @returns A validation result preserving the input type intersected with the schema type\n */\n static validate<V extends Validator, I = unknown>(\n input: I,\n validator: V,\n options?: ValidationOptions & {\n mode?: 'validate'\n },\n ): ValidationResult<I & InferInput<V>>\n\n /**\n * Validates input against a validator with configurable options.\n *\n * @param input - The value to validate\n * @param validator - The validator to use\n * @param options - Optional validation options\n * @returns A validation result with either the input or output type\n */\n static validate<V extends Validator>(\n input: unknown,\n validator: V,\n options?: ValidationOptions,\n ): ValidationResult<InferOutput<V> | InferInput<V>>\n static validate<V extends Validator>(\n input: unknown,\n validator: V,\n options?: ValidationOptions,\n ): ValidationResult<InferOutput<V> | InferInput<V>> {\n const context = new ValidationContext({\n path: options?.path ?? [],\n mode: options?.mode ?? 'validate',\n strict: options?.strict ?? true,\n })\n return context.validate(input, validator)\n }\n\n /**\n * The current path being validated, used for error reporting.\n */\n protected readonly currentPath: PropertyKey[]\n\n /**\n * Accumulated validation issues collected during traversal.\n */\n protected readonly issues: Issue[] = []\n\n /**\n * Creates a new validation context with the specified options.\n *\n * @param options - The validation options (path and mode are required)\n */\n constructor(readonly options: Required<ValidationOptions>) {\n // Create a copy because we will be mutating the array during validation.\n this.currentPath = Array.from(options.path)\n }\n\n /**\n * Returns a copy of the current validation path.\n *\n * The path represents the location in the data structure being validated,\n * used for constructing meaningful error messages.\n */\n get path() {\n return Array.from(this.currentPath)\n }\n\n /**\n * Creates a new path by appending segments to the current path.\n *\n * @param path - Optional path segment(s) to append\n * @returns A new path array with the segment(s) appended\n */\n concatPath(path?: PropertyKey | readonly PropertyKey[]) {\n if (path == null) return this.path\n return this.currentPath.concat(path)\n }\n\n /**\n * Validates input against a validator within this context.\n *\n * This is the primary entry point for validation within a context. Always use\n * this method instead of calling {@link Validator.validateInContext} directly,\n * as this method enforces validation mode rules and handles transformation detection.\n *\n * @typeParam V - The validator type\n * @param input - The value to validate\n * @param validator - The validator to use\n * @returns A validation result with the validated value or error\n */\n validate<V extends Validator>(\n input: unknown,\n validator: V,\n ): ValidationResult<InferInput<V>> {\n // This is the only place where validateInContext should be called.\n const result = validator.validateInContext(input, this)\n\n if (result.success) {\n if (this.issues.length > 0) {\n // Validator returned a success but issues were added via the context.\n // This means the overall validation failed.\n return new LexValidationError(Array.from(this.issues))\n }\n\n if (this.options.mode !== 'parse' && !Object.is(result.value, input)) {\n // If the value changed, it means that a default (or some other\n // transformation) was applied, meaning that the original value did\n // *not* match the (output) schema. When not in \"parse\" mode, we\n // consider this a failure.\n\n // This check is the reason why Validator.validateInContext should not\n // be used directly, and ValidatorContext.validate should be used\n // instead, even when delegating validation from one validator to\n // another.\n\n // This if block comes before the next one because 'this.issues' will\n // end-up being appended to the returned LexValidationError (see the\n // \"failure\" method below), resulting in a more complete error report.\n return this.issueInvalidValue(input, [result.value])\n }\n }\n\n return result as ValidationResult<InferInput<V>>\n }\n\n /**\n * Validates a child property of an object within this context.\n *\n * This method automatically manages the path stack, pushing the property key\n * before validation and popping it afterward. Use this for validating object\n * properties to ensure proper path tracking in error messages.\n *\n * @typeParam I - The input object type\n * @typeParam K - The property key type\n * @typeParam V - The validator type\n * @param input - The parent object containing the property\n * @param key - The property key to validate\n * @param validator - The validator to use for the property value\n * @returns A validation result for the property value\n *\n * @example\n * ```typescript\n * // In a custom object validator\n * const result = ctx.validateChild(input, 'name', stringSchema)\n * // If validation fails, error path will include 'name'\n * ```\n */\n validateChild<\n I extends object,\n K extends PropertyKey & keyof I,\n V extends Validator,\n >(input: I, key: K, validator: V): ValidationResult<InferInput<V>> {\n // @NOTE we could add support for recursive schemas by keeping track of\n // \"parent\" objects in the context and checking for circular references\n // here. This would allow us to validate recursive structures without\n // hitting maximum call stack errors, and would also allow us to provide\n // better error messages for circular reference issues. However, this is not\n // a priority at the moment as recursive structures are not supported in\n // the context of AT Protocol lexicons, and we can always add this in the\n // future if needed.\n\n // Instead of creating a new context, we just push/pop the path segment.\n this.currentPath.push(key)\n try {\n return this.validate(input[key], validator)\n } finally {\n this.currentPath.length--\n }\n }\n\n /**\n * Adds a validation issue to the context without immediately failing.\n *\n * Use this method to collect multiple issues during validation before\n * determining the final result. Issues added this way will be included\n * in the final error if validation fails.\n *\n * @param issue - The validation issue to add\n */\n addIssue(issue: Issue): void {\n this.issues.push(issue)\n }\n\n /**\n * Helper method to create a successful validation result.\n *\n * @typeParam V - The value type\n * @param value - The validated value\n * @returns A successful validation result\n */\n success<V>(value: V): ValidationSuccess<V> {\n return { success: true, value }\n }\n\n /**\n * Creates a failed validation result from a single issue.\n *\n * Any previously accumulated issues in the context are included in the error.\n *\n * @param issue - The validation issue that caused the failure\n * @returns A failed validation result\n */\n issue(issue: Issue): ValidationFailure {\n return new LexValidationError([...this.issues, issue])\n }\n\n /**\n * Creates a failure for an invalid value that doesn't match expected values.\n *\n * @param input - The actual value that was received\n * @param values - The expected valid values\n * @returns A failed validation result with an invalid value issue\n */\n issueInvalidValue(input: unknown, values: readonly unknown[]) {\n return this.issue(new IssueInvalidValue(this.path, input, values))\n }\n\n /**\n * Creates a failure for an invalid type.\n *\n * @param input - The actual value that was received\n * @param expected - An array of expected type names\n * @returns A failed validation result with an invalid type issue\n */\n issueInvalidType(input: unknown, expected: readonly string[]) {\n return this.issue(new IssueInvalidType(this.path, input, expected))\n }\n\n /**\n * Creates a failure for an invalid type.\n *\n * @param input - The actual value that was received\n * @param expected - The expected type name\n * @returns A failed validation result with an invalid type issue\n */\n issueUnexpectedType(input: unknown, expected: string) {\n return this.issueInvalidType(input, [expected])\n }\n\n /**\n * Creates a failure for a missing required key in an object.\n *\n * @param input - The object missing the required key\n * @param key - The name of the required key\n * @returns A failed validation result with a required key issue\n */\n issueRequiredKey(input: object, key: PropertyKey) {\n return this.issue(new IssueRequiredKey(this.path, input, key))\n }\n\n /**\n * Creates a failure for an invalid string format.\n *\n * @param input - The actual value that was received\n * @param format - The expected format name (e.g., 'did', 'handle', 'uri')\n * @param msg - Optional additional message describing the format error\n * @returns A failed validation result with an invalid format issue\n */\n issueInvalidFormat(input: unknown, format: string, msg?: string) {\n return this.issue(new IssueInvalidFormat(this.path, input, format, msg))\n }\n\n /**\n * Creates a failure for a value that exceeds a maximum constraint.\n *\n * @param input - The actual value that was received\n * @param type - The type of measurement (e.g., 'string', 'array', 'bytes')\n * @param max - The maximum allowed value\n * @param actual - The actual measured value\n * @returns A failed validation result with a too big issue\n */\n issueTooBig(\n input: unknown,\n type: MeasurableType,\n max: number,\n actual: number,\n ) {\n return this.issue(new IssueTooBig(this.path, input, max, type, actual))\n }\n\n /**\n * Creates a failure for a value that is below a minimum constraint.\n *\n * @param input - The actual value that was received\n * @param type - The type of measurement (e.g., 'string', 'array', 'bytes')\n * @param min - The minimum required value\n * @param actual - The actual measured value\n * @returns A failed validation result with a too small issue\n */\n issueTooSmall(\n input: unknown,\n type: MeasurableType,\n min: number,\n actual: number,\n ) {\n return this.issue(new IssueTooSmall(this.path, input, min, type, actual))\n }\n\n /**\n * Creates a failure for an invalid property value within an object.\n *\n * This is a convenience method that automatically extracts the property value\n * and constructs the appropriate path.\n *\n * @typeParam I - The input object type\n * @param input - The object containing the invalid property\n * @param property - The property key with the invalid value\n * @param values - The expected valid values\n * @returns A failed validation result with an invalid value issue at the property path\n */\n issueInvalidPropertyValue<I>(\n input: I,\n property: keyof I & PropertyKey,\n values: readonly unknown[],\n ) {\n const value = input[property]\n const path = this.concatPath(property)\n return this.issue(new IssueInvalidValue(path, value, values))\n }\n\n /**\n * Creates a failure for an invalid property type within an object.\n *\n * This is a convenience method that automatically extracts the property value\n * and constructs the appropriate path.\n *\n * @typeParam I - The input object type\n * @param input - The object containing the invalid property\n * @param property - The property key with the invalid type\n * @param expected - The expected type name\n * @returns A failed validation result with an invalid type issue at the property path\n */\n issueInvalidPropertyType<I>(\n input: I,\n property: keyof I & PropertyKey,\n expected: string,\n ) {\n const value = input[property]\n const path = this.concatPath(property)\n return this.issue(new IssueInvalidType(path, value, [expected]))\n }\n}\n\n/**\n * Recursively unwraps a wrapped validator to its innermost validator type.\n *\n * Some validators wrap other validators (e.g., optional, nullable). This type\n * utility recursively unwraps such wrappers to reveal the core validator.\n *\n * @typeParam T - A validator type, possibly wrapped\n *\n * @example\n * ```typescript\n * type Inner = UnwrapValidator<OptionalValidator<NullableValidator<StringSchema>>>\n * // Result: StringSchema\n * ```\n */\nexport type UnwrapValidator<T extends Validator> = T extends {\n unwrap(): infer U extends Validator\n}\n ? UnwrapValidator<U>\n : T\n\n/**\n * Interface for validators that wrap another validator.\n *\n * Implement this interface when creating validators that wrap or modify\n * the behavior of another validator (e.g., optional, nullable, transform).\n *\n * @typeParam Validator - The type of the wrapped validator\n *\n * @example\n * ```typescript\n * class OptionalSchema<V extends Validator> implements WrappedValidator<V> {\n * constructor(private inner: V) {}\n *\n * unwrap(): V {\n * return this.inner\n * }\n * }\n * ```\n */\nexport interface WrappedValidator<out Validator> {\n /**\n * Returns the inner wrapped validator.\n *\n * @returns The wrapped validator\n */\n unwrap(): Validator\n}\n"]}
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AtIdentifierString, InferOutput, NsidString, RecordKeyValue, Restricted } from './core.js';
|
|
2
|
-
import { InferPayload, InferPayloadBody, InferPayloadEncoding, InferRecordKey, Procedure, Query, RecordSchema, Subscription } from './schema.js';
|
|
1
|
+
import { type AtIdentifierString, type InferOutput, type NsidString, type RecordKeyValue, type Restricted } from './core.js';
|
|
2
|
+
import { type InferPayload, type InferPayloadBody, type InferPayloadEncoding, type InferRecordKey, Procedure, Query, RecordSchema, Subscription } from './schema.js';
|
|
3
3
|
export type Main<T> = T | {
|
|
4
4
|
main: T;
|
|
5
5
|
};
|
package/dist/helpers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,UAAU,EAIhB,MAAM,WAAW,CAAA;AAClB,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,CAAA;AACvB,wBAAgB,KAAK,CACnB,KAAK,CAAC,UAAU,SAAS,kBAAkB,EAC3C,KAAK,CAAC,WAAW,SAAS,UAAU,EACpC,KAAK,CAAC,UAAU,SAAS,cAAc,EAEvC,SAAS,EAAE,UAAU,EACrB,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,UAAU,SAAS,IAAI,GAAG,GAAG,GAAG,KAAK,GAAG,UAAU,GACvD,QAAQ,UAAU,IAAI,WAAW,IAAI,UAAU,EAAE,CAAA;AACpD,wBAAgB,KAAK,CACnB,KAAK,CAAC,UAAU,SAAS,kBAAkB,EAC3C,KAAK,CAAC,OAAO,SAAS,YAAY,EAElC,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,SAAS,WAAW,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,KAAK,GACzE,QAAQ,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,IAAI,cAAc,CAAC,OAAO,CAAC,EAAE,CAAA;AACtE,wBAAgB,KAAK,CACnB,KAAK,CAAC,UAAU,SAAS,kBAAkB,EAC3C,KAAK,CAAC,OAAO,SAAS,YAAY,EAClC,KAAK,CAAC,UAAU,SAAS,cAAc,CAAC,OAAO,CAAC,EAEhD,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,EACrB,IAAI,EAAE,UAAU,SAAS,IAAI,GAAG,GAAG,GAAG,KAAK,GAAG,UAAU,GACvD,QAAQ,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,IAAI,UAAU,EAAE,CAAA"}
|
package/dist/helpers.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { assertAtIdentifierString, assertStringFormat, } from './core.js';
|
|
2
|
-
import { object, optional, regexp, string, } from './schema.js';
|
|
1
|
+
import { Schema, assertAtIdentifierString, assertStringFormat, } from './core.js';
|
|
2
|
+
import { Procedure, Query, RecordSchema, Subscription, object, optional, regexp, string, } from './schema.js';
|
|
3
3
|
export function getMain(ns) {
|
|
4
4
|
return 'main' in ns ? ns.main : ns;
|
|
5
5
|
}
|
package/dist/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAML,MAAM,EACN,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,WAAW,CAAA;AAClB,OAAO,EAKL,SAAS,EACT,KAAK,EACL,YAAY,EACZ,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,GACP,MAAM,aAAa,CAAA;AAIpB,MAAM,UAAU,OAAO,CAAmB,EAAW;IACnD,OAAO,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAA;AACpC,CAAC;AAuFD;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;IACvC,iEAAiE;IACjE,KAAK,EAAE,MAAM,CAAC,WAAW,EAAE,4CAA4C,CAAC;IACxE,8DAA8D;IAC9D,OAAO,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;CAC5B,CAAgC,CAAA;AA2DjC,MAAM,UAAU,KAAK,CACnB,SAA6B,EAC7B,MAAoC,EACpC,IAAa;IAEb;;;;OAIG;IACH,QAAQ,OAAO,MAAM,EAAE,CAAC;QACtB,KAAK,WAAW,EAAE,CAAC;YACjB,wBAAwB,CAAC,SAAS,CAAC,CAAA;YACnC,OAAO,QAAQ,SAAS,EAAE,CAAA;QAC5B,CAAC;QAED,KAAK,QAAQ,EAAE,CAAC;YACd,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,MAAM,IAAI,SAAS,CAAC,gDAAgD,CAAC,CAAA;YACvE,CAAC;YACD,wBAAwB,CAAC,SAAS,CAAC,CAAA;YACnC,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;YAClC,kBAAkB,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;YACtC,OAAO,QAAQ,SAAS,IAAI,MAAM,IAAI,IAAI,EAAE,CAAA;QAC9C,CAAC;QAED,SAAS,CAAC;YACR,qEAAqE;YACrE,uEAAuE;YACvE,UAAU;YACV,wBAAwB,CAAC,SAAS,CAAC,CAAA;YACnC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;YAC9B,kEAAkE;YAClE,8CAA8C;YAC9C,OAAO,QAAQ,SAAS,IAAI,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAA;QAC5E,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { LexErrorData } from '@atproto/lex-data'\nimport {\n type AtIdentifierString,\n type InferOutput,\n type NsidString,\n type RecordKeyValue,\n type Restricted,\n Schema,\n assertAtIdentifierString,\n assertStringFormat,\n} from './core.js'\nimport {\n type InferPayload,\n type InferPayloadBody,\n type InferPayloadEncoding,\n type InferRecordKey,\n Procedure,\n Query,\n RecordSchema,\n Subscription,\n object,\n optional,\n regexp,\n string,\n} from './schema.js'\n\nexport type Main<T> = T | { main: T }\n\nexport function getMain<T extends object>(ns: Main<T>): T {\n return 'main' in ns ? ns.main : ns\n}\n\n/**\n * Every XRPC implementation should translate `application/json` and `text/*`\n * payloads into their native equivalent ({@link LexValue} or string). Binary\n * data payloads, however, can be represented differently depending on the\n * environment and use case (e.g. `Uint8Array`, `Blob`, `Buffer`,\n * `ReadableStream`, etc.). This type is a placeholder to represent binary data\n * when not explicitly provided.\n */\nexport type BinaryData = Restricted<'Binary data'>\n\nexport type InferMethodParams<\n M extends Procedure | Query | Subscription = Procedure | Query | Subscription,\n> =\n M extends Procedure<any, infer TParams, any, any, any>\n ? InferOutput<TParams>\n : M extends Query<any, infer TParams, any, any>\n ? InferOutput<TParams>\n : M extends Subscription<any, infer TParams, any, any>\n ? InferOutput<TParams>\n : never\n\nexport type InferMethodInput<\n M extends Procedure | Query | Subscription = Procedure | Query | Subscription,\n B = BinaryData,\n> =\n M extends Procedure<any, any, infer TInput, any, any>\n ? InferPayload<TInput, B>\n : undefined\n\nexport type InferMethodInputBody<\n M extends Procedure | Query | Subscription = Procedure | Query | Subscription,\n B = BinaryData,\n> =\n M extends Procedure<any, any, infer TInput, any, any>\n ? InferPayloadBody<TInput, B>\n : undefined\n\nexport type InferMethodInputEncoding<\n M extends Procedure | Query | Subscription = Procedure | Query | Subscription,\n> =\n M extends Procedure<any, any, infer TInput, any, any>\n ? InferPayloadEncoding<TInput>\n : undefined\n\nexport type InferMethodOutput<\n M extends Procedure | Query | Subscription = Procedure | Query | Subscription,\n B = BinaryData,\n> =\n M extends Procedure<any, any, any, infer TOutput, any>\n ? InferPayload<TOutput, B>\n : M extends Query<any, any, infer TOutput, any>\n ? InferPayload<TOutput, B>\n : undefined\n\nexport type InferMethodOutputBody<\n M extends Procedure | Query | Subscription = Procedure | Query | Subscription,\n B = BinaryData,\n> =\n M extends Procedure<any, any, any, infer TOutput, any>\n ? InferPayloadBody<TOutput, B>\n : M extends Query<any, any, infer TOutput, any>\n ? InferPayloadBody<TOutput, B>\n : undefined\n\nexport type InferMethodOutputEncoding<\n M extends Procedure | Query | Subscription = Procedure | Query | Subscription,\n> =\n M extends Procedure<any, any, any, infer TOutput, any>\n ? InferPayloadEncoding<TOutput>\n : M extends Query<any, any, infer TOutput, any>\n ? InferPayloadEncoding<TOutput>\n : undefined\n\nexport type InferMethodMessage<\n M extends Procedure | Query | Subscription = Procedure | Query | Subscription,\n> =\n M extends Subscription<any, any, infer TMessage, any>\n ? InferOutput<TMessage>\n : undefined\n\nexport type InferMethodError<\n //\n M extends Procedure | Query | Subscription = Procedure | Query | Subscription,\n> = M extends { errors: readonly (infer E extends string)[] } ? E : never\n\n/**\n * @see {@link https://atproto.com/specs/xrpc#error-responses}\n */\nexport const lexErrorDataSchema = object({\n // type name of the error (generic ASCII constant, no whitespace)\n error: regexp(/^[\\w_-]+$/, 'Expected ASCII constant with no whitespace'),\n // description of the error, appropriate for display to humans\n message: optional(string()),\n}) satisfies Schema<LexErrorData>\n\n/**\n * Helper function to construct AT Protocol URIs with compile-time & runtime\n * validation of their components. This function supports different use cases,\n * including constructing URIs from raw strings or from RecordSchema instances,\n * ensuring that the resulting URI adheres to the expected format.\n *\n * @throws {TypeError} If the arguments do not match the interface\n * @throws {Error} If AT-URI components are invalid\n *\n * @example\n * ```typescript\n * import { atUri } from '@atproto/lex'\n * import { app } from '#/lexicons/index.js'\n *\n * // Constructing a URI from raw components\n * const uri1 = atUri('did:example:123', 'app.bsky.feed.post', 'my-post')\n *\n * // Constructing a URI from a RecordSchema instance\n * const uri2 = atUri('did:example:123', app.bsky.feed.post, 'my-post')\n *\n * // Literal rkey can be omitted\n * const uri3 = atUri('did:example:123', app.bsky.actor.profile) // rkey 'self' is implied\n *\n * // Invalid URIs will throw errors\n * atUri('invalid authority', 'app.bsky.feed.post', 'my-post') // throws\n * atUri('did:example:123', 'invalid collection', 'my-post') // throws\n * atUri('did:example:123', 'app.bsky.feed.post', '..') // throws\n * ```\n */\nexport function atUri<const TAuthority extends AtIdentifierString>(\n authority: TAuthority,\n): `at://${TAuthority}`\nexport function atUri<\n const TAuthority extends AtIdentifierString,\n const TCollection extends NsidString,\n const TRecordKey extends RecordKeyValue,\n>(\n authority: TAuthority,\n nsid: TCollection,\n rkey: TRecordKey extends '..' | '.' ? never : TRecordKey,\n): `at://${TAuthority}/${TCollection}/${TRecordKey}`\nexport function atUri<\n const TAuthority extends AtIdentifierString,\n const TRecord extends RecordSchema,\n>(\n authority: TAuthority,\n record: TRecord['key'] extends `literal:${string}` ? Main<TRecord> : never,\n): `at://${TAuthority}/${TRecord['$type']}/${InferRecordKey<TRecord>}`\nexport function atUri<\n const TAuthority extends AtIdentifierString,\n const TRecord extends RecordSchema,\n const TRecordKey extends InferRecordKey<TRecord>,\n>(\n authority: TAuthority,\n record: Main<TRecord>,\n rkey: TRecordKey extends '..' | '.' ? never : TRecordKey,\n): `at://${TAuthority}/${TRecord['$type']}/${TRecordKey}`\nexport function atUri(\n authority: AtIdentifierString,\n record?: string | Main<RecordSchema>,\n rkey?: string,\n) {\n /**\n * @NOTE because we are encoding potentially untrusted input into a URI, we\n * validate the input against the AT Protocol constraints, ensuring that no\n * invalid URIs can be generated.\n */\n switch (typeof record) {\n case 'undefined': {\n assertAtIdentifierString(authority)\n return `at://${authority}`\n }\n\n case 'string': {\n if (!rkey) {\n throw new TypeError('Record key is required when record is a string')\n }\n assertAtIdentifierString(authority)\n assertStringFormat(record, 'nsid')\n assertStringFormat(rkey, 'record-key')\n return `at://${authority}/${record}/${rkey}`\n }\n\n default: {\n // @NOTE The use of a schema assumes that the collection ($type) is a\n // valid NSID that can safely be included in the URI without additional\n // checks.\n assertAtIdentifierString(authority)\n const schema = getMain(record)\n // @NOTE parsing will apply defaults, so that literal keys will be\n // properly validated and included in the URI.\n return `at://${authority}/${schema.$type}/${schema.keySchema.parse(rkey)}`\n }\n }\n}\n"]}
|
package/dist/schema/array.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/schema/array.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,
|
|
1
|
+
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/schema/array.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,MAAM,EACN,iBAAiB,EACjB,KAAK,SAAS,EACf,MAAM,YAAY,CAAA;AAGnB;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,WAAW,CAAC,KAAK,CAAC,KAAK,SAAS,SAAS,CAAE,SAAQ,MAAM,CACpE,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EACxB,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAC1B;IAIG,QAAQ,CAAC,SAAS,EAAE,KAAK;IACzB,QAAQ,CAAC,OAAO,EAAE,kBAAkB;IAJtC,QAAQ,CAAC,IAAI,EAAG,OAAO,CAAS;IAEhC,YACW,SAAS,EAAE,KAAK,EAChB,OAAO,GAAE,kBAAuB,EAG1C;IAED,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB,2FAkCvD;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,iBAAS,WAAW,CAAC,KAAK,CAAC,UAAU,SAAS,SAAS,EACrD,KAAK,EAAE,UAAU,EACjB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,WAAW,CAAC,UAAU,CAAC,CAAA;AAC1B,iBAAS,WAAW,CAClB,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,UAAU,SAAS,SAAS,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,EAC9D,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,WAAW,CAAC,UAAU,CAAC,CAAA;AAQ3E,eAAO,MAAM,KAAK,oBAAiD,CAAA"}
|
package/dist/schema/array.js
CHANGED
package/dist/schema/array.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../src/schema/array.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,MAAM,
|
|
1
|
+
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../src/schema/array.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,MAAM,EACN,iBAAiB,GAElB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,mBAAmB,EA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AAK,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC9B,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;oBACpC,sEAAsE;oBACtE,OAAO,GAAG,CAAC,yBAAyB,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;gBAChE,CAAC;gBAED,6DAA6D;gBAC7D,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;gBAC1B,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAA;YACxB,CAAC;QACH,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,KAAK,CAAC,CAAA;IACnC,CAAC;CACF;AAoCD,SAAS,WAAW,CAClB,KAAiB,EACjB,OAA4B;IAE5B,OAAO,IAAI,WAAW,CAAa,KAAK,EAAE,OAAO,CAAC,CAAA;AACpD,CAAC;AAED,MAAM,CAAC,MAAM,KAAK,GAAG,aAAa,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAA","sourcesContent":["import {\n type InferInput,\n type InferOutput,\n Schema,\n ValidationContext,\n type Validator,\n} from '../core.js'\nimport { memoizedTransformer } from '../util/memoize.js'\n\n/**\n * Configuration options for array schema validation.\n *\n * @property minLength - Minimum number of items in the array\n * @property maxLength - Maximum number of items in the array\n */\nexport type ArraySchemaOptions = {\n minLength?: number\n maxLength?: number\n}\n\n/**\n * Schema for validating arrays where all items match a given schema.\n *\n * Validates that the input is an array, checks length constraints, and\n * validates each item against the provided item schema.\n *\n * @template TItem - The validator type for array items\n *\n * @example\n * ```ts\n * const schema = new ArraySchema(l.string(), { maxLength: 10 })\n * const result = schema.validate(['a', 'b', 'c'])\n * ```\n */\nexport class ArraySchema<const TItem extends Validator> extends Schema<\n Array<InferInput<TItem>>,\n Array<InferOutput<TItem>>\n> {\n readonly type = 'array' as const\n\n constructor(\n readonly validator: TItem,\n readonly options: ArraySchemaOptions = {},\n ) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (!Array.isArray(input)) {\n return ctx.issueUnexpectedType(input, 'array')\n }\n\n const { minLength, maxLength } = this.options\n\n if (minLength != null && input.length < minLength) {\n return ctx.issueTooSmall(input, 'array', minLength, input.length)\n }\n\n if (maxLength != null && input.length > maxLength) {\n return ctx.issueTooBig(input, 'array', maxLength, input.length)\n }\n\n let copy: undefined | unknown[]\n\n for (let i = 0; i < input.length; i++) {\n const result = ctx.validateChild(input, i, this.validator)\n if (!result.success) return result\n\n if (result.value !== input[i]) {\n if (ctx.options.mode === 'validate') {\n // In \"validate\" mode, we can't modify the input, so we issue an error\n return ctx.issueInvalidPropertyValue(input, i, [result.value])\n }\n\n // Copy on write (but only if we did not already make a copy)\n copy ??= Array.from(input)\n copy[i] = result.value\n }\n }\n\n return ctx.success(copy ?? input)\n }\n}\n\n/**\n * Creates an array schema that validates each item against the provided schema.\n *\n * @param items - Schema to validate each array item against\n * @param options - Optional length constraints\n * @returns A new {@link ArraySchema} instance\n *\n * @example\n * ```ts\n * // Array of strings\n * const tagsSchema = l.array(l.string())\n *\n * // Array with length constraints\n * const limitedSchema = l.array(l.integer(), { maxLength: 100 })\n *\n * // Array of objects\n * const usersSchema = l.array(l.object({\n * name: l.string(),\n * age: l.integer(),\n * }))\n *\n * // Non-empty array\n * const nonEmptySchema = l.array(l.string(), { minLength: 1 })\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nfunction arraySchema<const TValidator extends Validator>(\n items: TValidator,\n options?: ArraySchemaOptions,\n): ArraySchema<TValidator>\nfunction arraySchema<\n const TValue,\n const TValidator extends Validator<TValue> = Validator<TValue>,\n>(items: TValidator, options?: ArraySchemaOptions): ArraySchema<TValidator>\nfunction arraySchema<const TValidator extends Validator>(\n items: TValidator,\n options?: ArraySchemaOptions,\n) {\n return new ArraySchema<TValidator>(items, options)\n}\n\nexport const array = /*#__PURE__*/ memoizedTransformer(arraySchema)\n"]}
|
package/dist/schema/blob.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BlobRef, LegacyBlobRef, TypedBlobRef, isBlobRef, isLegacyBlobRef, isTypedBlobRef } from '@atproto/lex-data';
|
|
1
|
+
import { type BlobRef, type LegacyBlobRef, type TypedBlobRef, isBlobRef, isLegacyBlobRef, isTypedBlobRef } from '@atproto/lex-data';
|
|
2
2
|
import { Schema, ValidationContext } from '../core.js';
|
|
3
3
|
/**
|
|
4
4
|
* Configuration options for blob schema validation.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../../src/schema/blob.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,
|
|
1
|
+
{"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../../src/schema/blob.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,YAAY,EAEjB,SAAS,EACT,eAAe,EACf,cAAc,EACf,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAGtD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IAEjB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,cAAc,EAAE,CAAA;AAErD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,UAAU,CACrB,KAAK,CAAC,QAAQ,SAAS,iBAAiB,GAAG,WAAW,CAAC,OAAO,CAAC,CAC/D,SAAQ,MAAM,CAAC,OAAO,CAAC;IAGX,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ;IAFvC,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAS;IAE/B,YAAqB,OAAO,CAAC,EAAE,QAAQ,YAAA,EAEtC;IAED,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB,6FA4BvD;IAED,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAIjC;CACF;AA+BD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,IAAI,GACf,CAAC,SAAS,iBAAiB,iBAClB,CAAC,KAAa,UAAU,CAAC,CAAC,CAEnC,CAAA"}
|
package/dist/schema/blob.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getBlobSize, isBlobRef, isLegacyBlobRef, isTypedBlobRef, } from '@atproto/lex-data';
|
|
2
|
-
import { Schema } from '../core.js';
|
|
2
|
+
import { Schema, ValidationContext } from '../core.js';
|
|
3
3
|
import { memoizedOptions } from '../util/memoize.js';
|
|
4
4
|
export { isBlobRef, isLegacyBlobRef, isTypedBlobRef };
|
|
5
5
|
/**
|
|
@@ -106,7 +106,7 @@ function matchesMime(mime, accepted) {
|
|
|
106
106
|
* const avatarSchema = l.blob({ accept: ['image/*'], maxSize: 1000000 })
|
|
107
107
|
* ```
|
|
108
108
|
*/
|
|
109
|
-
export const blob = /*#__PURE__*/ memoizedOptions(function (options) {
|
|
109
|
+
export const blob = /*#__PURE__*/ memoizedOptions(function (options = {}) {
|
|
110
110
|
return new BlobSchema(options);
|
|
111
111
|
});
|
|
112
112
|
//# sourceMappingURL=blob.js.map
|
package/dist/schema/blob.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blob.js","sourceRoot":"","sources":["../../src/schema/blob.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,WAAW,EACX,SAAS,EACT,eAAe,EACf,cAAc,GACf,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"blob.js","sourceRoot":"","sources":["../../src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C,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAA;IACxC,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;QAC7B,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAChE,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,aAAa,CAAC,eAAe,CAAC,UAEhD,OAAO,GAAM,EAAO;IACpB,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAA;AAChC,CAAC,CAAC,CAAA","sourcesContent":["import {\n type BlobRef,\n type LegacyBlobRef,\n type TypedBlobRef,\n getBlobSize,\n isBlobRef,\n isLegacyBlobRef,\n isTypedBlobRef,\n} from '@atproto/lex-data'\nimport { Schema, ValidationContext } from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\n\n/**\n * Configuration options for blob schema validation.\n */\nexport type BlobSchemaOptions = {\n /**\n * List of accepted MIME types (supports wildcards like 'image/*' or '*\\/*')\n *\n * @default undefined // accepts all MIME types\n */\n accept?: string[]\n\n /**\n * Maximum blob size in bytes\n *\n * @default undefined // no size limit\n */\n maxSize?: number\n}\n\nexport type { BlobRef, LegacyBlobRef, TypedBlobRef }\nexport { isBlobRef, isLegacyBlobRef, isTypedBlobRef }\n\n/**\n * Schema for validating blob references in AT Protocol.\n *\n * Validates BlobRef objects which contain a CID reference to binary data,\n * along with metadata like MIME type and size. Can optionally accept\n * legacy blob reference format.\n *\n * @template TOptions - The configuration options type\n *\n * @example\n * ```ts\n * const schema = new BlobSchema({ accept: ['image/*'], maxSize: 1000000 })\n * const result = schema.validate(blobRef)\n * ```\n */\nexport class BlobSchema<\n const TOptions extends BlobSchemaOptions = NonNullable<unknown>,\n> extends Schema<BlobRef> {\n readonly type = 'blob' as const\n\n constructor(readonly options?: TOptions) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n const blob = parseValue.call(ctx, input)\n if (!blob) {\n return ctx.issueUnexpectedType(input, 'blob')\n }\n\n // In non-strict mode, we allow blob refs to pass through without MIME\n // type or size checks.\n if (ctx.options.strict && this.options != null) {\n const { accept } = this.options\n if (accept && !matchesMime(blob.mimeType, accept)) {\n return ctx.issueInvalidPropertyValue(blob, 'mimeType', accept)\n }\n\n const { maxSize } = this.options\n if (maxSize != null) {\n const size = getBlobSize(blob)\n if (size === undefined) {\n // Unable to enforce size constraint if size is not available (legacy\n // blob ref), so we treat it as a validation failure in strict mode.\n return ctx.issueInvalidPropertyType(blob, 'size' as any, 'integer')\n } else if (size > maxSize) {\n return ctx.issueTooBig(blob, 'blob', maxSize, size)\n }\n }\n }\n\n return ctx.success(blob)\n }\n\n matchesMime(mime: string): boolean {\n const accept = this.options?.accept\n if (!accept) return true\n return matchesMime(mime, accept)\n }\n}\n\nfunction parseValue(this: ValidationContext, input: unknown): BlobRef | null {\n // If there is a $type property, we treat if as a potential TypedBlobRef and\n // validate accordingly.\n if ((input as any)?.$type !== undefined) {\n // Use the context's option for the \"strict\" check\n return isTypedBlobRef(input, this.options) ? input : null\n }\n\n // If there is no $type property, we may be dealing with a legacy blob ref. If\n // legacy refs are allowed (non-strict mode), we check if the input matches\n // the legacy format.\n if (!this.options.strict) {\n if (isLegacyBlobRef(input, this.options)) return input\n }\n\n return null\n}\n\nfunction matchesMime(mime: string, accepted: string[]): boolean {\n if (accepted.includes('*/*')) return true\n if (accepted.includes(mime)) return true\n for (const value of accepted) {\n if (value.endsWith('/*') && mime.startsWith(value.slice(0, -1))) {\n return true\n }\n }\n return false\n}\n\n/**\n * Creates a blob schema for validating blob references with optional constraints.\n *\n * Blob references are used in AT Protocol to reference binary data stored\n * separately from records. They contain a CID, MIME type, and size information.\n *\n * @param options - Optional configuration for MIME type filtering and size limits\n * @returns A new {@link BlobSchema} instance\n *\n * @example\n * ```ts\n * // Basic blob reference\n * const fileSchema = l.blob()\n *\n * // Image files only\n * const imageSchema = l.blob({ accept: ['image/png', 'image/jpeg', 'image/gif'] })\n *\n * // Any image type with size limit\n * const avatarSchema = l.blob({ accept: ['image/*'], maxSize: 1000000 })\n * ```\n */\nexport const blob = /*#__PURE__*/ memoizedOptions(function <\n O extends BlobSchemaOptions = NonNullable<unknown>,\n>(options: O = {} as O): BlobSchema<O> {\n return new BlobSchema(options)\n})\n"]}
|
package/dist/schema/boolean.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../src/schema/boolean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../src/schema/boolean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEpD;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,aAAc,SAAQ,MAAe;IAAlD;;QACW,SAAI,GAAG,SAAkB,CAAA;IASpC,CAAC;IAPC,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;YAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAC3B,CAAC;QAED,OAAO,GAAG,CAAC,mBAAmB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;IAClD,CAAC;CACF;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC,eAAe,CAAC;IACnD,OAAO,IAAI,aAAa,EAAE,CAAA;AAC5B,CAAC,CAAC,CAAA","sourcesContent":["import { Schema, ValidationContext } from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\n\n/**\n * Schema for validating boolean values.\n *\n * Only accepts JavaScript `true` or `false` values. Does not perform\n * any coercion from strings or numbers.\n *\n * @example\n * ```ts\n * const schema = new BooleanSchema()\n * schema.validate(true) // success\n * schema.validate(false) // success\n * schema.validate('true') // fails - no string coercion\n * ```\n */\nexport class BooleanSchema extends Schema<boolean> {\n readonly type = 'boolean' as const\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (typeof input === 'boolean') {\n return ctx.success(input)\n }\n\n return ctx.issueUnexpectedType(input, 'boolean')\n }\n}\n\n/**\n * Creates a boolean schema that validates true/false values.\n *\n * @returns A new {@link BooleanSchema} instance\n *\n * @example\n * ```ts\n * const enabledSchema = l.boolean()\n *\n * enabledSchema.parse(true) // true\n * enabledSchema.parse(false) // false\n * enabledSchema.parse('true') // throws - strings not accepted\n * ```\n */\nexport const boolean = /*#__PURE__*/ memoizedOptions(function () {\n return new BooleanSchema()\n})\n"]}
|
package/dist/schema/bytes.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { asUint8Array, ifUint8Array } from '@atproto/lex-data';
|
|
2
|
-
import { Schema } from '../core.js';
|
|
2
|
+
import { Schema, ValidationContext } from '../core.js';
|
|
3
3
|
import { memoizedOptions } from '../util/memoize.js';
|
|
4
4
|
/**
|
|
5
5
|
* Schema for validating binary data as Uint8Array with optional length constraints.
|
package/dist/schema/bytes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../src/schema/bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC9D,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../src/schema/bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA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;;;GAmBG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,aAAa,CAAC,eAAe,CAAC,UACjD,OAA4B;IAE5B,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,CAAA;AACjC,CAAC,CAAC,CAAA","sourcesContent":["import { asUint8Array, ifUint8Array } from '@atproto/lex-data'\nimport { Schema, ValidationContext } from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\n\n/**\n * Configuration options for bytes schema validation.\n *\n * @property minLength - Minimum length in bytes\n * @property maxLength - Maximum length in bytes\n */\nexport type BytesSchemaOptions = {\n minLength?: number\n maxLength?: number\n}\n\n/**\n * Schema for validating binary data as Uint8Array with optional length constraints.\n *\n * In \"parse\" mode, coerces various binary formats (Buffer, ArrayBuffer, etc.)\n * into Uint8Array. In \"validate\" mode, only accepts Uint8Array directly.\n *\n * @example\n * ```ts\n * const schema = new BytesSchema({ maxLength: 1024 })\n * const result = schema.validate(new Uint8Array([1, 2, 3]))\n * ```\n */\nexport class BytesSchema extends Schema<Uint8Array> {\n readonly type = 'bytes' as const\n\n constructor(readonly options: BytesSchemaOptions = {}) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n // In \"parse\" mode, coerce different binary formats into Uint8Array\n const bytes =\n ctx.options.mode === 'parse' ? asUint8Array(input) : ifUint8Array(input)\n if (!bytes) {\n return ctx.issueUnexpectedType(input, 'bytes')\n }\n\n const { minLength } = this.options\n if (minLength != null && bytes.length < minLength) {\n return ctx.issueTooSmall(bytes, 'bytes', minLength, bytes.length)\n }\n\n const { maxLength } = this.options\n if (maxLength != null && bytes.length > maxLength) {\n return ctx.issueTooBig(bytes, 'bytes', maxLength, bytes.length)\n }\n\n return ctx.success(bytes)\n }\n}\n\n/**\n * Creates a bytes schema for validating binary data with optional length constraints.\n *\n * Validates Uint8Array values and can coerce other binary formats in parse mode.\n *\n * @param options - Optional configuration for minimum and maximum byte length\n * @returns A new {@link BytesSchema} instance\n *\n * @example\n * ```ts\n * // Basic bytes schema\n * const dataSchema = l.bytes()\n *\n * // With size constraints\n * const avatarSchema = l.bytes({ maxLength: 1000000 }) // 1MB max\n *\n * // With minimum size\n * const hashSchema = l.bytes({ minLength: 32, maxLength: 32 }) // Exactly 32 bytes\n * ```\n */\nexport const bytes = /*#__PURE__*/ memoizedOptions(function (\n options?: BytesSchemaOptions,\n) {\n return new BytesSchema(options)\n})\n"]}
|
package/dist/schema/cid.d.ts
CHANGED
package/dist/schema/cid.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cid.d.ts","sourceRoot":"","sources":["../../src/schema/cid.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"cid.d.ts","sourceRoot":"","sources":["../../src/schema/cid.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,GAAG,EACR,KAAK,eAAe,EAErB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAGtD,YAAY,EAAE,GAAG,EAAE,CAAA;AAEnB;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,eAAe,CAAA;AAE9C;;;;;;;;;;;;;;GAcG;AACH,qBAAa,SAAS,CACpB,KAAK,CAAC,QAAQ,SAAS,gBAAgB,GAAG;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,CAC/D,SAAQ,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;IAG7B,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ;IAFvC,QAAQ,CAAC,IAAI,EAAG,KAAK,CAAS;IAE9B,YAAqB,OAAO,CAAC,EAAE,QAAQ,YAAA,EAEtC;IAED,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB,gHAMvD;CACF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,GAAG,GACd,CAAC,SAAS,gBAAgB,iBACjB,CAAC,KAAa,SAAS,CAAC,CAAC,CAElC,CAAA"}
|
package/dist/schema/cid.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isCid } from '@atproto/lex-data';
|
|
2
|
-
import { Schema } from '../core.js';
|
|
1
|
+
import { isCid, } from '@atproto/lex-data';
|
|
2
|
+
import { Schema, ValidationContext } from '../core.js';
|
|
3
3
|
import { memoizedOptions } from '../util/memoize.js';
|
|
4
4
|
/**
|
|
5
5
|
* Schema for validating Content Identifiers (CIDs).
|
|
@@ -47,7 +47,7 @@ export class CidSchema extends Schema {
|
|
|
47
47
|
* const result = cidSchema.validate(blobRef.ref)
|
|
48
48
|
* ```
|
|
49
49
|
*/
|
|
50
|
-
export const cid = /*#__PURE__*/ memoizedOptions(function (options) {
|
|
50
|
+
export const cid = /*#__PURE__*/ memoizedOptions(function (options = {}) {
|
|
51
51
|
return new CidSchema(options);
|
|
52
52
|
});
|
|
53
53
|
//# sourceMappingURL=cid.js.map
|
package/dist/schema/cid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cid.js","sourceRoot":"","sources":["../../src/schema/cid.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"cid.js","sourceRoot":"","sources":["../../src/schema/cid.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,GACN,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAWpD;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,SAEX,SAAQ,MAAiC;IAGzC,YAAqB,OAAkB;QACrC,KAAK,EAAE,CAAA;QADY,YAAO,GAAP,OAAO,CAAW;QAF9B,SAAI,GAAG,KAAc,CAAA;IAI9B,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAChC,OAAO,GAAG,CAAC,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;QAC9C,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC3B,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,aAAa,CAAC,eAAe,CAAC,UAE/C,OAAO,GAAM,EAAO;IACpB,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC,CAAA;AAC/B,CAAC,CAAC,CAAA","sourcesContent":["import {\n type CheckCidOptions,\n type Cid,\n type InferCheckedCid,\n isCid,\n} from '@atproto/lex-data'\nimport { Schema, ValidationContext } from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\n\nexport type { Cid }\n\n/**\n * Configuration options for CID schema validation.\n *\n * @see CheckCidOptions from @atproto/lex-data for available options\n */\nexport type CidSchemaOptions = CheckCidOptions\n\n/**\n * Schema for validating Content Identifiers (CIDs).\n *\n * CIDs are self-describing content-addressed identifiers used in AT Protocol\n * to reference data by its cryptographic hash. This schema validates that\n * the input is a valid CID object.\n *\n * @template TOptions - The configuration options type\n *\n * @example\n * ```ts\n * const schema = new CidSchema()\n * const result = schema.validate(someCid)\n * ```\n */\nexport class CidSchema<\n const TOptions extends CidSchemaOptions = { flavor: undefined },\n> extends Schema<InferCheckedCid<TOptions>> {\n readonly type = 'cid' as const\n\n constructor(readonly options?: TOptions) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (!isCid(input, this.options)) {\n return ctx.issueUnexpectedType(input, 'cid')\n }\n\n return ctx.success(input)\n }\n}\n\n/**\n * Creates a CID schema for validating Content Identifiers.\n *\n * CIDs are used throughout AT Protocol to reference content by its hash.\n * This is commonly used for referencing blobs, commits, and other data.\n *\n * @param options - Optional configuration for CID validation\n * @returns A new {@link CidSchema} instance\n *\n * @example\n * ```ts\n * // Basic CID validation\n * const cidSchema = l.cid()\n *\n * // Validate a CID from a blob reference\n * const result = cidSchema.validate(blobRef.ref)\n * ```\n */\nexport const cid = /*#__PURE__*/ memoizedOptions(function <\n O extends CidSchemaOptions = NonNullable<unknown>,\n>(options: O = {} as O): CidSchema<O> {\n return new CidSchema(options)\n})\n"]}
|
package/dist/schema/custom.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom.js","sourceRoot":"","sources":["../../src/schema/custom.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"custom.js","sourceRoot":"","sources":["../../src/schema/custom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAwB1E;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,YAAmC,SAAQ,MAAc;IAGpE,YACmB,SAAkC,EAClC,OAAe,EACf,IAA2C;QAE5D,KAAK,EAAE,CAAA;QAJU,cAAS,GAAT,SAAS,CAAyB;QAClC,YAAO,GAAP,OAAO,CAAQ;QACf,SAAI,GAAJ,IAAI,CAAuC;QALrD,SAAI,GAAG,QAAiB,CAAA;IAQjC,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACtC,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;QAC9D,CAAC;QACD,OAAO,GAAG,CAAC,OAAO,CAAC,KAAe,CAAC,CAAA;IACrC,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAwB;AACxB,MAAM,UAAU,MAAM,CACpB,SAAkC,EAClC,OAAe,EACf,IAA2C;IAE3C,OAAO,IAAI,YAAY,CAAS,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;AAC3D,CAAC","sourcesContent":["import { Issue, IssueCustom, Schema, ValidationContext } from '../core.js'\n\n/**\n * Context object provided to custom assertion functions.\n *\n * @property path - Current validation path as an array of property keys\n * @property addIssue - Function to add additional validation issues\n */\nexport type CustomAssertionContext = {\n path: PropertyKey[]\n addIssue(issue: Issue): void\n}\n\n/**\n * Type guard function for custom schema validation.\n *\n * @template TValue - The type to validate/narrow to\n */\nexport type CustomAssertion<TValue> = (\n this: null,\n input: unknown,\n ctx: CustomAssertionContext,\n) => input is TValue\n\n/**\n * Schema with a custom validation function.\n *\n * Allows defining completely custom validation logic using a type guard\n * assertion function. The function receives the input and validation context,\n * and must return whether the input is valid.\n *\n * @template TValue - The validated output type\n *\n * @example\n * ```ts\n * const schema = new CustomSchema(\n * (input): input is Date => input instanceof Date,\n * 'Expected a Date instance'\n * )\n * ```\n */\nexport class CustomSchema<out TValue = unknown> extends Schema<TValue> {\n readonly type = 'custom' as const\n\n constructor(\n private readonly assertion: CustomAssertion<TValue>,\n private readonly message: string,\n private readonly path?: PropertyKey | readonly PropertyKey[],\n ) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (!this.assertion.call(null, input, ctx)) {\n const path = ctx.concatPath(this.path)\n return ctx.issue(new IssueCustom(path, input, this.message))\n }\n return ctx.success(input as TValue)\n }\n}\n\n/**\n * Creates a custom schema with a user-defined validation function.\n *\n * Use this when the built-in schemas don't cover your validation needs.\n * The assertion function must be a type guard that narrows the input type.\n *\n * @param assertion - Type guard function that validates the input\n * @param message - Error message when validation fails\n * @param path - Optional path to associate with validation errors\n * @returns A new {@link CustomSchema} instance\n *\n * @example\n * ```ts\n * // Validate Date instances\n * const dateSchema = l.custom(\n * (input): input is Date => input instanceof Date && !isNaN(input.getTime()),\n * 'Expected a valid Date'\n * )\n *\n * // Validate specific object shape\n * const pointSchema = l.custom(\n * (input): input is { x: number; y: number } =>\n * typeof input === 'object' &&\n * input !== null &&\n * typeof (input as any).x === 'number' &&\n * typeof (input as any).y === 'number',\n * 'Expected a point with x and y coordinates'\n * )\n *\n * // With custom path\n * const validConfig = l.custom(\n * (input): input is Config => validateConfig(input),\n * 'Invalid configuration',\n * ['config']\n * )\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function custom<TValue>(\n assertion: CustomAssertion<TValue>,\n message: string,\n path?: PropertyKey | readonly PropertyKey[],\n) {\n return new CustomSchema<TValue>(assertion, message, path)\n}\n"]}
|
package/dist/schema/dict.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InferInput, InferOutput, Schema, ValidationContext, Validator } from '../core.js';
|
|
1
|
+
import { type InferInput, type InferOutput, Schema, ValidationContext, type Validator } from '../core.js';
|
|
2
2
|
/**
|
|
3
3
|
* Schema for validating dictionary/map-like objects with dynamic keys.
|
|
4
4
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dict.d.ts","sourceRoot":"","sources":["../../src/schema/dict.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,
|
|
1
|
+
{"version":3,"file":"dict.d.ts","sourceRoot":"","sources":["../../src/schema/dict.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,MAAM,EACN,iBAAiB,EACjB,KAAK,SAAS,EACf,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,UAAU,CACrB,KAAK,CAAC,IAAI,SAAS,SAAS,CAAC,MAAM,CAAC,GAAG,GAAG,EAC1C,KAAK,CAAC,MAAM,SAAS,SAAS,GAAG,GAAG,CACpC,SAAQ,MAAM,CACd,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,EAC5C,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAC9C;IAIG,QAAQ,CAAC,SAAS,EAAE,IAAI;IACxB,QAAQ,CAAC,WAAW,EAAE,MAAM;IAJ9B,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAS;IAE/B,YACW,SAAS,EAAE,IAAI,EACf,WAAW,EAAE,MAAM,EAG7B;IAED,iBAAiB,CACf,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,iBAAiB,EACtB,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE;YAAE,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;SAAE,CAAA;KAAE,6GAmCxD;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,wBAAgB,IAAI,CAClB,KAAK,CAAC,IAAI,SAAS,SAAS,CAAC,MAAM,CAAC,EACpC,KAAK,CAAC,MAAM,SAAS,SAAS,EAC9B,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,4BAEzB"}
|
package/dist/schema/dict.js
CHANGED
package/dist/schema/dict.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dict.js","sourceRoot":"","sources":["../../src/schema/dict.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAGL,MAAM,
|
|
1
|
+
{"version":3,"file":"dict.js","sourceRoot":"","sources":["../../src/schema/dict.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAGL,MAAM,EACN,iBAAiB,GAElB,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,UAGX,SAAQ,MAGT;IAGC,YACW,SAAe,EACf,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,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAA;gBACvE,CAAC;gBAED,IAAI,KAAK,EAAE,GAAG,KAAK,EAAE,CAAA;gBACrB,IAAI,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,KAAK,CAAA;YAC/B,CAAC;QACH,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,KAAK,CAAC,CAAA;IACnC,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAwB;AACxB,MAAM,UAAU,IAAI,CAGlB,GAAS,EAAE,KAAa;IACxB,OAAO,IAAI,UAAU,CAAe,GAAG,EAAE,KAAK,CAAC,CAAA;AACjD,CAAC","sourcesContent":["import { isPlainObject } from '@atproto/lex-data'\nimport {\n type InferInput,\n type InferOutput,\n Schema,\n ValidationContext,\n type Validator,\n} from '../core.js'\n\n/**\n * Schema for validating dictionary/map-like objects with dynamic keys.\n *\n * Unlike `ObjectSchema` which validates a fixed set of properties, `DictSchema`\n * validates objects where any string key is allowed, with both keys and values\n * validated against their respective schemas.\n *\n * @note There is no dictionary in Lexicon schemas. This is a custom extension\n * to allow map-like objects when using the lex library programmatically (i.e.\n * not code generated from a lexicon schema).\n *\n * @template TKey - The validator type for dictionary keys (must validate strings)\n * @template TValue - The validator type for dictionary values\n *\n * @example\n * ```ts\n * const schema = new DictSchema(l.string(), l.integer())\n * const result = schema.validate({ a: 1, b: 2, c: 3 })\n * ```\n */\nexport class DictSchema<\n const TKey extends Validator<string> = any,\n const TValue extends Validator = any,\n> extends Schema<\n Record<InferInput<TKey>, InferInput<TValue>>,\n Record<InferInput<TKey>, InferOutput<TValue>>\n> {\n readonly type = 'dict' as const\n\n constructor(\n readonly keySchema: TKey,\n readonly valueSchema: TValue,\n ) {\n super()\n }\n\n validateInContext(\n input: unknown,\n ctx: ValidationContext,\n options?: { ignoredKeys?: { has(k: string): boolean } },\n ) {\n if (!isPlainObject(input)) {\n return ctx.issueUnexpectedType(input, 'dict')\n }\n\n let copy: undefined | Record<string, unknown>\n\n for (const key in input) {\n if (options?.ignoredKeys?.has(key)) continue\n\n const keyResult = ctx.validate(key, this.keySchema)\n if (!keyResult.success) return keyResult\n if (keyResult.value !== key) {\n // We can't safely \"move\" the key to a different name in the output\n // object (because there may already be something there), so we issue a\n // \"required key\" error if the key validation changes the key\n return ctx.issueRequiredKey(input, key)\n }\n\n const valueResult = ctx.validateChild(input, key, this.valueSchema)\n if (!valueResult.success) return valueResult\n\n if (!Object.is(valueResult.value, input[key])) {\n if (ctx.options.mode === 'validate') {\n // In \"validate\" mode, we can't modify the input, so we issue an error\n return ctx.issueInvalidPropertyValue(input, key, [valueResult.value])\n }\n\n copy ??= { ...input }\n copy[key] = valueResult.value\n }\n }\n\n return ctx.success(copy ?? input)\n }\n}\n\n/**\n * Creates a dictionary schema for validating map-like objects.\n *\n * Validates objects where all keys match the key schema and all values\n * match the value schema. Useful for dynamic key-value mappings.\n *\n * @param key - Schema to validate each key (must be a string validator)\n * @param value - Schema to validate each value\n * @returns A new {@link DictSchema} instance\n *\n * @example\n * ```ts\n * // String to number mapping\n * const scoresSchema = l.dict(l.string(), l.integer())\n * scoresSchema.parse({ alice: 100, bob: 85 })\n *\n * // Constrained keys\n * const langSchema = l.dict(\n * l.string({ minLength: 2, maxLength: 5 }), // Language codes\n * l.string() // Translations\n * )\n *\n * // Complex values\n * const usersById = l.dict(\n * l.string({ format: 'did' }),\n * l.object({ name: l.string(), age: l.integer() })\n * )\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function dict<\n const TKey extends Validator<string>,\n const TValue extends Validator,\n>(key: TKey, value: TValue) {\n return new DictSchema<TKey, TValue>(key, value)\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InferInput, InferOutput, Schema, ValidationContext, ValidationResult, Validator } from '../core.js';
|
|
1
|
+
import { type InferInput, type InferOutput, Schema, ValidationContext, type ValidationResult, type Validator } from '../core.js';
|
|
2
2
|
import { EnumSchema } from './enum.js';
|
|
3
3
|
import { LiteralSchema } from './literal.js';
|
|
4
4
|
import { ObjectSchema } from './object.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discriminated-union.d.ts","sourceRoot":"","sources":["../../src/schema/discriminated-union.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,
|
|
1
|
+
{"version":3,"file":"discriminated-union.d.ts","sourceRoot":"","sources":["../../src/schema/discriminated-union.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,MAAM,EACN,iBAAiB,EACjB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACf,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C;;;;;;;GAOG;AACH,MAAM,MAAM,yBAAyB,CAAC,aAAa,SAAS,MAAM,GAAG,MAAM,IACzE,YAAY,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AAE3E;;;;GAIG;AACH,MAAM,MAAM,0BAA0B,CAAC,cAAc,SAAS,MAAM,IAClE,SAAS;IACP,yBAAyB,CAAC,cAAc,CAAC;IACzC,GAAG,yBAAyB,CAAC,cAAc,CAAC,EAAE;CAC/C,CAAA;AAEH,KAAK,6BAA6B,CAAC,SAAS,SAAS,SAAS,SAAS,EAAE,IACvE,SAAS,SAAS,SAAS;IACzB,MAAM,UAAU,SAAS,SAAS;IAClC,GAAG,MAAM,KAAK,SAAS,SAAS,SAAS,EAAE;CAC5C,GACG,UAAU,CAAC,UAAU,CAAC,GAAG,6BAA6B,CAAC,KAAK,CAAC,GAC7D,KAAK,CAAA;AAEX,KAAK,8BAA8B,CAAC,SAAS,SAAS,SAAS,SAAS,EAAE,IACxE,SAAS,SAAS,SAAS;IACzB,MAAM,UAAU,SAAS,SAAS;IAClC,GAAG,MAAM,KAAK,SAAS,SAAS,SAAS,EAAE;CAC5C,GACG,WAAW,CAAC,UAAU,CAAC,GAAG,8BAA8B,CAAC,KAAK,CAAC,GAC/D,KAAK,CAAA;AAEX;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,wBAAwB,CACnC,KAAK,CAAC,cAAc,SAAS,MAAM,EACnC,KAAK,CAAC,SAAS,SAAS,0BAA0B,CAAC,cAAc,CAAC,CAClE,SAAQ,MAAM,CACd,6BAA6B,CAAC,SAAS,CAAC,EACxC,8BAA8B,CAAC,SAAS,CAAC,CAC1C;IAMG,QAAQ,CAAC,aAAa,EAAE,cAAc;IACtC,QAAQ,CAAC,QAAQ,EAAE,SAAS;IAN9B,QAAQ,CAAC,IAAI,EAAG,oBAAoB,CAAS;IAE7C,QAAQ,CAAC,WAAW,EAAE,GAAG,CAAC,OAAO,EAAE,yBAAyB,CAAC,cAAc,CAAC,CAAC,CAAA;IAE7E,YACW,aAAa,EAAE,cAAc,EAC7B,QAAQ,EAAE,SAAS,EAQ7B;IAED,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB,8DAuBvD;CACF;AAsCD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,wBAAgB,kBAAkB,CAChC,KAAK,CAAC,aAAa,SAAS,MAAM,EAClC,KAAK,CAAC,OAAO,SAAS,0BAA0B,CAAC,aAAa,CAAC,EAC/D,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,oDAKhD"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { isPlainObject } from '@atproto/lex-data';
|
|
2
|
-
import { Schema, } from '../core.js';
|
|
2
|
+
import { Schema, ValidationContext, } from '../core.js';
|
|
3
3
|
import { EnumSchema } from './enum.js';
|
|
4
4
|
import { LiteralSchema } from './literal.js';
|
|
5
|
+
import { ObjectSchema } from './object.js';
|
|
5
6
|
/**
|
|
6
7
|
* Schema for validating discriminated unions of objects.
|
|
7
8
|
*
|