@atproto/lex-schema 0.0.19 → 0.1.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/core/$type.js +2 -6
  3. package/dist/core/$type.js.map +1 -1
  4. package/dist/core/record-key.js +4 -8
  5. package/dist/core/record-key.js.map +1 -1
  6. package/dist/core/result.js +6 -14
  7. package/dist/core/result.js.map +1 -1
  8. package/dist/core/schema.js +16 -20
  9. package/dist/core/schema.js.map +1 -1
  10. package/dist/core/standard-schema.js +5 -10
  11. package/dist/core/standard-schema.js.map +1 -1
  12. package/dist/core/string-format.d.ts.map +1 -1
  13. package/dist/core/string-format.js +37 -61
  14. package/dist/core/string-format.js.map +1 -1
  15. package/dist/core/types.js +1 -2
  16. package/dist/core/validation-error.js +14 -25
  17. package/dist/core/validation-error.js.map +1 -1
  18. package/dist/core/validation-issue.js +13 -41
  19. package/dist/core/validation-issue.js.map +1 -1
  20. package/dist/core/validator.js +19 -28
  21. package/dist/core/validator.js.map +1 -1
  22. package/dist/core.js +9 -12
  23. package/dist/core.js.map +1 -1
  24. package/dist/external.js +3 -6
  25. package/dist/external.js.map +1 -1
  26. package/dist/helpers.js +5 -9
  27. package/dist/helpers.js.map +1 -1
  28. package/dist/index.js +3 -7
  29. package/dist/index.js.map +1 -1
  30. package/dist/schema/array.js +5 -11
  31. package/dist/schema/array.js.map +1 -1
  32. package/dist/schema/blob.js +10 -17
  33. package/dist/schema/blob.js.map +1 -1
  34. package/dist/schema/boolean.js +8 -9
  35. package/dist/schema/boolean.js.map +1 -1
  36. package/dist/schema/bytes.js +7 -12
  37. package/dist/schema/bytes.js.map +1 -1
  38. package/dist/schema/cid.js +7 -12
  39. package/dist/schema/cid.js.map +1 -1
  40. package/dist/schema/custom.js +5 -13
  41. package/dist/schema/custom.js.map +1 -1
  42. package/dist/schema/dict.js +6 -13
  43. package/dist/schema/dict.js.map +1 -1
  44. package/dist/schema/discriminated-union.js +10 -18
  45. package/dist/schema/discriminated-union.js.map +1 -1
  46. package/dist/schema/enum.js +6 -11
  47. package/dist/schema/enum.js.map +1 -1
  48. package/dist/schema/integer.js +5 -10
  49. package/dist/schema/integer.js.map +1 -1
  50. package/dist/schema/intersection.js +4 -11
  51. package/dist/schema/intersection.js.map +1 -1
  52. package/dist/schema/lex-map.js +13 -14
  53. package/dist/schema/lex-map.js.map +1 -1
  54. package/dist/schema/lex-value.js +11 -12
  55. package/dist/schema/lex-value.js.map +1 -1
  56. package/dist/schema/literal.js +4 -10
  57. package/dist/schema/literal.js.map +1 -1
  58. package/dist/schema/never.js +8 -9
  59. package/dist/schema/never.js.map +1 -1
  60. package/dist/schema/null.js +9 -10
  61. package/dist/schema/null.js.map +1 -1
  62. package/dist/schema/nullable.js +5 -10
  63. package/dist/schema/nullable.js.map +1 -1
  64. package/dist/schema/object.js +8 -14
  65. package/dist/schema/object.js.map +1 -1
  66. package/dist/schema/optional.js +5 -10
  67. package/dist/schema/optional.js.map +1 -1
  68. package/dist/schema/params.js +39 -44
  69. package/dist/schema/params.js.map +1 -1
  70. package/dist/schema/payload.js +5 -13
  71. package/dist/schema/payload.js.map +1 -1
  72. package/dist/schema/permission-set.js +2 -10
  73. package/dist/schema/permission-set.js.map +1 -1
  74. package/dist/schema/permission.js +2 -9
  75. package/dist/schema/permission.js.map +1 -1
  76. package/dist/schema/procedure.js +3 -13
  77. package/dist/schema/procedure.js.map +1 -1
  78. package/dist/schema/query.js +3 -12
  79. package/dist/schema/query.js.map +1 -1
  80. package/dist/schema/record.js +15 -24
  81. package/dist/schema/record.js.map +1 -1
  82. package/dist/schema/ref.js +4 -9
  83. package/dist/schema/ref.js.map +1 -1
  84. package/dist/schema/refine.js +3 -6
  85. package/dist/schema/refine.js.map +1 -1
  86. package/dist/schema/regexp.js +4 -11
  87. package/dist/schema/regexp.js.map +1 -1
  88. package/dist/schema/string.js +15 -26
  89. package/dist/schema/string.js.map +1 -1
  90. package/dist/schema/subscription.js +3 -12
  91. package/dist/schema/subscription.js.map +1 -1
  92. package/dist/schema/token.js +5 -11
  93. package/dist/schema/token.js.map +1 -1
  94. package/dist/schema/typed-object.js +11 -18
  95. package/dist/schema/typed-object.js.map +1 -1
  96. package/dist/schema/typed-ref.js +4 -9
  97. package/dist/schema/typed-ref.js.map +1 -1
  98. package/dist/schema/typed-union.js +8 -15
  99. package/dist/schema/typed-union.js.map +1 -1
  100. package/dist/schema/union.js +5 -11
  101. package/dist/schema/union.js.map +1 -1
  102. package/dist/schema/unknown.js +8 -9
  103. package/dist/schema/unknown.js.map +1 -1
  104. package/dist/schema/with-default.js +4 -11
  105. package/dist/schema/with-default.js.map +1 -1
  106. package/dist/schema.js +38 -41
  107. package/dist/schema.js.map +1 -1
  108. package/dist/util/array-agg.js +1 -4
  109. package/dist/util/array-agg.js.map +1 -1
  110. package/dist/util/assertion-util.js +1 -2
  111. package/dist/util/if-any.js +1 -2
  112. package/dist/util/lazy-property.js +1 -4
  113. package/dist/util/lazy-property.js.map +1 -1
  114. package/dist/util/memoize.js +2 -6
  115. package/dist/util/memoize.js.map +1 -1
  116. package/package.json +7 -8
  117. package/src/core/string-format.ts +2 -1
  118. package/src/core/validation-issue.ts +1 -1
  119. package/src/helpers.test.ts +52 -52
  120. package/src/schema/record.test.ts +2 -2
  121. package/src/schema/ref.test.ts +1 -1
  122. package/src/schema/string.test.ts +6 -6
  123. package/src/schema/subscription.test.ts +4 -4
  124. package/src/schema/typed-object.test.ts +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"blob.js","sourceRoot":"","sources":["../../src/schema/blob.ts"],"names":[],"mappings":";;;AAAA,gDAQ0B;AAwBjB,0FA3BP,oBAAS,OA2BO;AAAE,gGA1BlB,0BAAe,OA0BkB;AAAE,+FAzBnC,yBAAc,OAyBmC;AAvBnD,wCAAsD;AACtD,mDAAoD;AAwBpD;;;;;;;;;;;;;;GAcG;AACH,MAAa,UAEX,SAAQ,gBA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D,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACU,QAAA,IAAI,GAAiB,IAAA,4BAAe,EAAC,UAEhD,OAAW;IACX,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAA;AAChC,CAAC,CAAC,CAAA","sourcesContent":["import {\n BlobRef,\n LegacyBlobRef,\n 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) {\n return new BlobSchema(options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OAAO,IAAI,CAAA;IACzC,IAAI,QAAQ,CAAC,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,OAAW;IACX,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAA;AAChC,CAAC,CAAC,CAAA","sourcesContent":["import {\n BlobRef,\n LegacyBlobRef,\n 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) {\n return new BlobSchema(options)\n})\n"]}
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.boolean = exports.BooleanSchema = void 0;
4
- const core_js_1 = require("../core.js");
5
- const memoize_js_1 = require("../util/memoize.js");
1
+ import { Schema } from '../core.js';
2
+ import { memoizedOptions } from '../util/memoize.js';
6
3
  /**
7
4
  * Schema for validating boolean values.
8
5
  *
@@ -17,8 +14,11 @@ const memoize_js_1 = require("../util/memoize.js");
17
14
  * schema.validate('true') // fails - no string coercion
18
15
  * ```
19
16
  */
20
- class BooleanSchema extends core_js_1.Schema {
21
- type = 'boolean';
17
+ export class BooleanSchema extends Schema {
18
+ constructor() {
19
+ super(...arguments);
20
+ this.type = 'boolean';
21
+ }
22
22
  validateInContext(input, ctx) {
23
23
  if (typeof input === 'boolean') {
24
24
  return ctx.success(input);
@@ -26,7 +26,6 @@ class BooleanSchema extends core_js_1.Schema {
26
26
  return ctx.issueUnexpectedType(input, 'boolean');
27
27
  }
28
28
  }
29
- exports.BooleanSchema = BooleanSchema;
30
29
  /**
31
30
  * Creates a boolean schema that validates true/false values.
32
31
  *
@@ -41,7 +40,7 @@ exports.BooleanSchema = BooleanSchema;
41
40
  * enabledSchema.parse('true') // throws - strings not accepted
42
41
  * ```
43
42
  */
44
- exports.boolean = (0, memoize_js_1.memoizedOptions)(function () {
43
+ export const boolean = /*#__PURE__*/ memoizedOptions(function () {
45
44
  return new BooleanSchema();
46
45
  });
47
46
  //# sourceMappingURL=boolean.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../src/schema/boolean.ts"],"names":[],"mappings":";;;AAAA,wCAAsD;AACtD,mDAAoD;AAEpD;;;;;;;;;;;;;GAaG;AACH,MAAa,aAAc,SAAQ,gBAAe;IACvC,IAAI,GAAG,SAAkB,CAAA;IAElC,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;AAVD,sCAUC;AAED;;;;;;;;;;;;;GAaG;AACU,QAAA,OAAO,GAAiB,IAAA,4BAAe,EAAC;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"]}
1
+ {"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../src/schema/boolean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAqB,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"]}
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bytes = exports.BytesSchema = void 0;
4
- const lex_data_1 = require("@atproto/lex-data");
5
- const core_js_1 = require("../core.js");
6
- const memoize_js_1 = require("../util/memoize.js");
1
+ import { asUint8Array, ifUint8Array } from '@atproto/lex-data';
2
+ import { Schema } from '../core.js';
3
+ import { memoizedOptions } from '../util/memoize.js';
7
4
  /**
8
5
  * Schema for validating binary data as Uint8Array with optional length constraints.
9
6
  *
@@ -16,16 +13,15 @@ const memoize_js_1 = require("../util/memoize.js");
16
13
  * const result = schema.validate(new Uint8Array([1, 2, 3]))
17
14
  * ```
18
15
  */
19
- class BytesSchema extends core_js_1.Schema {
20
- options;
21
- type = 'bytes';
16
+ export class BytesSchema extends Schema {
22
17
  constructor(options = {}) {
23
18
  super();
24
19
  this.options = options;
20
+ this.type = 'bytes';
25
21
  }
26
22
  validateInContext(input, ctx) {
27
23
  // In "parse" mode, coerce different binary formats into Uint8Array
28
- const bytes = ctx.options.mode === 'parse' ? (0, lex_data_1.asUint8Array)(input) : (0, lex_data_1.ifUint8Array)(input);
24
+ const bytes = ctx.options.mode === 'parse' ? asUint8Array(input) : ifUint8Array(input);
29
25
  if (!bytes) {
30
26
  return ctx.issueUnexpectedType(input, 'bytes');
31
27
  }
@@ -40,7 +36,6 @@ class BytesSchema extends core_js_1.Schema {
40
36
  return ctx.success(bytes);
41
37
  }
42
38
  }
43
- exports.BytesSchema = BytesSchema;
44
39
  /**
45
40
  * Creates a bytes schema for validating binary data with optional length constraints.
46
41
  *
@@ -61,7 +56,7 @@ exports.BytesSchema = BytesSchema;
61
56
  * const hashSchema = l.bytes({ minLength: 32, maxLength: 32 }) // Exactly 32 bytes
62
57
  * ```
63
58
  */
64
- exports.bytes = (0, memoize_js_1.memoizedOptions)(function (options) {
59
+ export const bytes = /*#__PURE__*/ memoizedOptions(function (options) {
65
60
  return new BytesSchema(options);
66
61
  });
67
62
  //# sourceMappingURL=bytes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../src/schema/bytes.ts"],"names":[],"mappings":";;;AAAA,gDAA8D;AAC9D,wCAAsD;AACtD,mDAAoD;AAapD;;;;;;;;;;;GAWG;AACH,MAAa,WAAY,SAAQ,gBAAkB;IAG5B;IAFZ,IAAI,GAAG,OAAgB,CAAA;IAEhC,YAAqB,UAA8B,EAAE;QACnD,KAAK,EAAE,CAAA;QADY,YAAO,GAAP,OAAO,CAAyB;IAErD,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,mEAAmE;QACnE,MAAM,KAAK,GACT,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,IAAA,uBAAY,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAA,uBAAY,EAAC,KAAK,CAAC,CAAA;QAC1E,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,GAAG,CAAC,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAChD,CAAC;QAED,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,OAAO,CAAA;QAClC,IAAI,SAAS,IAAI,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;YAClD,OAAO,GAAG,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QACnE,CAAC;QAED,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,OAAO,CAAA;QAClC,IAAI,SAAS,IAAI,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;YAClD,OAAO,GAAG,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QACjE,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC3B,CAAC;CACF;AA3BD,kCA2BC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACU,QAAA,KAAK,GAAiB,IAAA,4BAAe,EAAC,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"]}
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,EAAqB,MAAM,YAAY,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAapD;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,WAAY,SAAQ,MAAkB;IAGjD,YAAqB,UAA8B,EAAE;QACnD,KAAK,EAAE,CAAA;QADY,YAAO,GAAP,OAAO,CAAyB;QAF5C,SAAI,GAAG,OAAgB,CAAA;IAIhC,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,mEAAmE;QACnE,MAAM,KAAK,GACT,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;QAC1E,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,GAAG,CAAC,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAChD,CAAC;QAED,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,OAAO,CAAA;QAClC,IAAI,SAAS,IAAI,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;YAClD,OAAO,GAAG,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QACnE,CAAC;QAED,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,OAAO,CAAA;QAClC,IAAI,SAAS,IAAI,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;YAClD,OAAO,GAAG,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QACjE,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC3B,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;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"]}
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cid = exports.CidSchema = void 0;
4
- const lex_data_1 = require("@atproto/lex-data");
5
- const core_js_1 = require("../core.js");
6
- const memoize_js_1 = require("../util/memoize.js");
1
+ import { isCid } from '@atproto/lex-data';
2
+ import { Schema } from '../core.js';
3
+ import { memoizedOptions } from '../util/memoize.js';
7
4
  /**
8
5
  * Schema for validating Content Identifiers (CIDs).
9
6
  *
@@ -19,21 +16,19 @@ const memoize_js_1 = require("../util/memoize.js");
19
16
  * const result = schema.validate(someCid)
20
17
  * ```
21
18
  */
22
- class CidSchema extends core_js_1.Schema {
23
- options;
24
- type = 'cid';
19
+ export class CidSchema extends Schema {
25
20
  constructor(options) {
26
21
  super();
27
22
  this.options = options;
23
+ this.type = 'cid';
28
24
  }
29
25
  validateInContext(input, ctx) {
30
- if (!(0, lex_data_1.isCid)(input, this.options)) {
26
+ if (!isCid(input, this.options)) {
31
27
  return ctx.issueUnexpectedType(input, 'cid');
32
28
  }
33
29
  return ctx.success(input);
34
30
  }
35
31
  }
36
- exports.CidSchema = CidSchema;
37
32
  /**
38
33
  * Creates a CID schema for validating Content Identifiers.
39
34
  *
@@ -52,7 +47,7 @@ exports.CidSchema = CidSchema;
52
47
  * const result = cidSchema.validate(blobRef.ref)
53
48
  * ```
54
49
  */
55
- exports.cid = (0, memoize_js_1.memoizedOptions)(function (options) {
50
+ export const cid = /*#__PURE__*/ memoizedOptions(function (options) {
56
51
  return new CidSchema(options);
57
52
  });
58
53
  //# sourceMappingURL=cid.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cid.js","sourceRoot":"","sources":["../../src/schema/cid.ts"],"names":[],"mappings":";;;AAAA,gDAAgF;AAChF,wCAAsD;AACtD,mDAAoD;AAWpD;;;;;;;;;;;;;;GAcG;AACH,MAAa,SAEX,SAAQ,gBAAiC;IAGpB;IAFZ,IAAI,GAAG,KAAc,CAAA;IAE9B,YAAqB,OAAkB;QACrC,KAAK,EAAE,CAAA;QADY,YAAO,GAAP,OAAO,CAAW;IAEvC,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,CAAC,IAAA,gBAAK,EAAC,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;AAhBD,8BAgBC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACU,QAAA,GAAG,GAAiB,IAAA,4BAAe,EAAC,UAE/C,OAAW;IACX,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC,CAAA;AAC/B,CAAC,CAAC,CAAA","sourcesContent":["import { CheckCidOptions, Cid, InferCheckedCid, isCid } 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) {\n return new CidSchema(options)\n})\n"]}
1
+ {"version":3,"file":"cid.js","sourceRoot":"","sources":["../../src/schema/cid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyC,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAChF,OAAO,EAAE,MAAM,EAAqB,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,OAAW;IACX,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC,CAAA;AAC/B,CAAC,CAAC,CAAA","sourcesContent":["import { CheckCidOptions, Cid, InferCheckedCid, isCid } 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) {\n return new CidSchema(options)\n})\n"]}
@@ -1,8 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CustomSchema = void 0;
4
- exports.custom = custom;
5
- const core_js_1 = require("../core.js");
1
+ import { IssueCustom, Schema } from '../core.js';
6
2
  /**
7
3
  * Schema with a custom validation function.
8
4
  *
@@ -20,26 +16,22 @@ const core_js_1 = require("../core.js");
20
16
  * )
21
17
  * ```
22
18
  */
23
- class CustomSchema extends core_js_1.Schema {
24
- assertion;
25
- message;
26
- path;
27
- type = 'custom';
19
+ export class CustomSchema extends Schema {
28
20
  constructor(assertion, message, path) {
29
21
  super();
30
22
  this.assertion = assertion;
31
23
  this.message = message;
32
24
  this.path = path;
25
+ this.type = 'custom';
33
26
  }
34
27
  validateInContext(input, ctx) {
35
28
  if (!this.assertion.call(null, input, ctx)) {
36
29
  const path = ctx.concatPath(this.path);
37
- return ctx.issue(new core_js_1.IssueCustom(path, input, this.message));
30
+ return ctx.issue(new IssueCustom(path, input, this.message));
38
31
  }
39
32
  return ctx.success(input);
40
33
  }
41
34
  }
42
- exports.CustomSchema = CustomSchema;
43
35
  /**
44
36
  * Creates a custom schema with a user-defined validation function.
45
37
  *
@@ -78,7 +70,7 @@ exports.CustomSchema = CustomSchema;
78
70
  * ```
79
71
  */
80
72
  /*@__NO_SIDE_EFFECTS__*/
81
- function custom(assertion, message, path) {
73
+ export function custom(assertion, message, path) {
82
74
  return new CustomSchema(assertion, message, path);
83
75
  }
84
76
  //# sourceMappingURL=custom.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"custom.js","sourceRoot":"","sources":["../../src/schema/custom.ts"],"names":[],"mappings":";;;AAmGA,wBAMC;AAzGD,wCAA0E;AAwB1E;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,YAAmC,SAAQ,gBAAc;IAIjD;IACA;IACA;IALV,IAAI,GAAG,QAAiB,CAAA;IAEjC,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;IAG9D,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,qBAAW,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;AAlBD,oCAkBC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAwB;AACxB,SAAgB,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"]}
1
+ {"version":3,"file":"custom.js","sourceRoot":"","sources":["../../src/schema/custom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,WAAW,EAAE,MAAM,EAAqB,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"]}
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DictSchema = void 0;
4
- exports.dict = dict;
5
- const lex_data_1 = require("@atproto/lex-data");
6
- const core_js_1 = require("../core.js");
1
+ import { isPlainObject } from '@atproto/lex-data';
2
+ import { Schema, } from '../core.js';
7
3
  /**
8
4
  * Schema for validating dictionary/map-like objects with dynamic keys.
9
5
  *
@@ -24,17 +20,15 @@ const core_js_1 = require("../core.js");
24
20
  * const result = schema.validate({ a: 1, b: 2, c: 3 })
25
21
  * ```
26
22
  */
27
- class DictSchema extends core_js_1.Schema {
28
- keySchema;
29
- valueSchema;
30
- type = 'dict';
23
+ export class DictSchema extends Schema {
31
24
  constructor(keySchema, valueSchema) {
32
25
  super();
33
26
  this.keySchema = keySchema;
34
27
  this.valueSchema = valueSchema;
28
+ this.type = 'dict';
35
29
  }
36
30
  validateInContext(input, ctx, options) {
37
- if (!(0, lex_data_1.isPlainObject)(input)) {
31
+ if (!isPlainObject(input)) {
38
32
  return ctx.issueUnexpectedType(input, 'dict');
39
33
  }
40
34
  let copy;
@@ -65,7 +59,6 @@ class DictSchema extends core_js_1.Schema {
65
59
  return ctx.success(copy ?? input);
66
60
  }
67
61
  }
68
- exports.DictSchema = DictSchema;
69
62
  /**
70
63
  * Creates a dictionary schema for validating map-like objects.
71
64
  *
@@ -96,7 +89,7 @@ exports.DictSchema = DictSchema;
96
89
  * ```
97
90
  */
98
91
  /*@__NO_SIDE_EFFECTS__*/
99
- function dict(key, value) {
92
+ export function dict(key, value) {
100
93
  return new DictSchema(key, value);
101
94
  }
102
95
  //# sourceMappingURL=dict.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dict.js","sourceRoot":"","sources":["../../src/schema/dict.ts"],"names":[],"mappings":";;;AAoHA,oBAKC;AAzHD,gDAAiD;AACjD,wCAMmB;AAEnB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa,UAGX,SAAQ,gBAGT;IAIY;IACA;IAJF,IAAI,GAAG,MAAe,CAAA;IAE/B,YACW,SAAe,EACf,WAAmB;QAE5B,KAAK,EAAE,CAAA;QAHE,cAAS,GAAT,SAAS,CAAM;QACf,gBAAW,GAAX,WAAW,CAAQ;IAG9B,CAAC;IAED,iBAAiB,CACf,KAAc,EACd,GAAsB,EACtB,OAAuD;QAEvD,IAAI,CAAC,IAAA,wBAAa,EAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,GAAG,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAC/C,CAAC;QAED,IAAI,IAAyC,CAAA;QAE7C,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;YACxB,IAAI,OAAO,EAAE,WAAW,EAAE,GAAG,CAAC,GAAG,CAAC;gBAAE,SAAQ;YAE5C,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;YACnD,IAAI,CAAC,SAAS,CAAC,OAAO;gBAAE,OAAO,SAAS,CAAA;YACxC,IAAI,SAAS,CAAC,KAAK,KAAK,GAAG,EAAE,CAAC;gBAC5B,mEAAmE;gBACnE,uEAAuE;gBACvE,6DAA6D;gBAC7D,OAAO,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;YACzC,CAAC;YAED,MAAM,WAAW,GAAG,GAAG,CAAC,aAAa,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;YACnE,IAAI,CAAC,WAAW,CAAC,OAAO;gBAAE,OAAO,WAAW,CAAA;YAE5C,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;gBAC9C,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;oBACpC,sEAAsE;oBACtE,OAAO,GAAG,CAAC,yBAAyB,CAAC,KAAK,EAAE,GAAG,EAAE,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;AAvDD,gCAuDC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAwB;AACxB,SAAgB,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 InferInput,\n InferOutput,\n Schema,\n ValidationContext,\n 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
+ {"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,GAGP,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,UAGX,SAAQ,MAGT;IAGC,YACW,SAAe,EACf,WAAmB;QAE5B,KAAK,EAAE,CAAA;QAHE,cAAS,GAAT,SAAS,CAAM;QACf,gBAAW,GAAX,WAAW,CAAQ;QAJrB,SAAI,GAAG,MAAe,CAAA;IAO/B,CAAC;IAED,iBAAiB,CACf,KAAc,EACd,GAAsB,EACtB,OAAuD;QAEvD,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,GAAG,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAC/C,CAAC;QAED,IAAI,IAAyC,CAAA;QAE7C,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;YACxB,IAAI,OAAO,EAAE,WAAW,EAAE,GAAG,CAAC,GAAG,CAAC;gBAAE,SAAQ;YAE5C,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;YACnD,IAAI,CAAC,SAAS,CAAC,OAAO;gBAAE,OAAO,SAAS,CAAA;YACxC,IAAI,SAAS,CAAC,KAAK,KAAK,GAAG,EAAE,CAAC;gBAC5B,mEAAmE;gBACnE,uEAAuE;gBACvE,6DAA6D;gBAC7D,OAAO,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;YACzC,CAAC;YAED,MAAM,WAAW,GAAG,GAAG,CAAC,aAAa,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;YACnE,IAAI,CAAC,WAAW,CAAC,OAAO;gBAAE,OAAO,WAAW,CAAA;YAE5C,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;gBAC9C,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;oBACpC,sEAAsE;oBACtE,OAAO,GAAG,CAAC,yBAAyB,CAAC,KAAK,EAAE,GAAG,EAAE,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 InferInput,\n InferOutput,\n Schema,\n ValidationContext,\n 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,11 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DiscriminatedUnionSchema = void 0;
4
- exports.discriminatedUnion = discriminatedUnion;
5
- const lex_data_1 = require("@atproto/lex-data");
6
- const core_js_1 = require("../core.js");
7
- const enum_js_1 = require("./enum.js");
8
- const literal_js_1 = require("./literal.js");
1
+ import { isPlainObject } from '@atproto/lex-data';
2
+ import { Schema, } from '../core.js';
3
+ import { EnumSchema } from './enum.js';
4
+ import { LiteralSchema } from './literal.js';
9
5
  /**
10
6
  * Schema for validating discriminated unions of objects.
11
7
  *
@@ -28,22 +24,19 @@ const literal_js_1 = require("./literal.js");
28
24
  * ])
29
25
  * ```
30
26
  */
31
- class DiscriminatedUnionSchema extends core_js_1.Schema {
32
- discriminator;
33
- variants;
34
- type = 'discriminatedUnion';
35
- variantsMap;
27
+ export class DiscriminatedUnionSchema extends Schema {
36
28
  constructor(discriminator, variants) {
37
29
  super();
38
30
  this.discriminator = discriminator;
39
31
  this.variants = variants;
32
+ this.type = 'discriminatedUnion';
40
33
  // Although we usually try to avoid initialization work in constructors,
41
34
  // here it is necessary to ensure that invalid discriminated throw from the
42
35
  // place of construction, rather than later during validation.
43
36
  this.variantsMap = buildVariantsMap(discriminator, variants);
44
37
  }
45
38
  validateInContext(input, ctx) {
46
- if (!(0, lex_data_1.isPlainObject)(input)) {
39
+ if (!isPlainObject(input)) {
47
40
  return ctx.issueUnexpectedType(input, 'object');
48
41
  }
49
42
  const { discriminator } = this;
@@ -60,18 +53,17 @@ class DiscriminatedUnionSchema extends core_js_1.Schema {
60
53
  ]);
61
54
  }
62
55
  }
63
- exports.DiscriminatedUnionSchema = DiscriminatedUnionSchema;
64
56
  function buildVariantsMap(discriminator, variants) {
65
57
  const variantsMap = new Map();
66
58
  for (const variant of variants) {
67
59
  const schema = variant.shape[discriminator];
68
- if (schema instanceof literal_js_1.LiteralSchema) {
60
+ if (schema instanceof LiteralSchema) {
69
61
  if (variantsMap.has(schema.value)) {
70
62
  throw new TypeError(`Overlapping discriminator value: ${schema.value}`);
71
63
  }
72
64
  variantsMap.set(schema.value, variant);
73
65
  }
74
- else if (schema instanceof enum_js_1.EnumSchema) {
66
+ else if (schema instanceof EnumSchema) {
75
67
  for (const val of schema.values) {
76
68
  if (variantsMap.has(val)) {
77
69
  throw new TypeError(`Overlapping discriminator value: ${val}`);
@@ -116,7 +108,7 @@ function buildVariantsMap(discriminator, variants) {
116
108
  * ```
117
109
  */
118
110
  /*@__NO_SIDE_EFFECTS__*/
119
- function discriminatedUnion(discriminator, variants) {
111
+ export function discriminatedUnion(discriminator, variants) {
120
112
  return new DiscriminatedUnionSchema(discriminator, variants);
121
113
  }
122
114
  //# sourceMappingURL=discriminated-union.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"discriminated-union.js","sourceRoot":"","sources":["../../src/schema/discriminated-union.ts"],"names":[],"mappings":";;;AA2LA,gDAQC;AAnMD,gDAAiD;AACjD,wCAOmB;AACnB,uCAAsC;AACtC,6CAA4C;AAyC5C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAa,wBAGX,SAAQ,gBAGT;IAMY;IACA;IANF,IAAI,GAAG,oBAA6B,CAAA;IAEpC,WAAW,CAAyD;IAE7E,YACW,aAA6B,EAC7B,QAAmB;QAE5B,KAAK,EAAE,CAAA;QAHE,kBAAa,GAAb,aAAa,CAAgB;QAC7B,aAAQ,GAAR,QAAQ,CAAW;QAI5B,w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KAAK,CAAC,EAAE,CAAC;gBAClC,MAAM,IAAI,SAAS,CAAC,oCAAoC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;YACzE,CAAC;YACD,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QACxC,CAAC;aAAM,IAAI,MAAM,YAAY,oBAAU,EAAE,CAAC;YACxC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;gBAChC,IAAI,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;oBACzB,MAAM,IAAI,SAAS,CAAC,oCAAoC,GAAG,EAAE,CAAC,CAAA;gBAChE,CAAC;gBACD,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;YAC/B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,sDAAsD;YAEtD,kDAAkD;YAClD,MAAM,IAAI,SAAS,CACjB,4DAA4D,CAC7D,CAAA;QACH,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAA;AACpB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAwB;AACxB,SAAgB,kBAAkB,CAGhC,aAA4B,EAAE,QAAiB;IAC/C,OAAO,IAAI,wBAAwB,CACjC,aAAa,EACb,QAAQ,CACT,CAAA;AACH,CAAC","sourcesContent":["import { isPlainObject } from '@atproto/lex-data'\nimport {\n InferInput,\n InferOutput,\n Schema,\n ValidationContext,\n ValidationResult,\n Validator,\n} from '../core.js'\nimport { EnumSchema } from './enum.js'\nimport { LiteralSchema } from './literal.js'\nimport { ObjectSchema } from './object.js'\n\n/**\n * Type representing a single variant in a discriminated union.\n *\n * Must be an ObjectSchema with the discriminator property using either\n * a LiteralSchema or EnumSchema.\n *\n * @template Discriminator - The discriminator property name\n */\nexport type DiscriminatedUnionVariant<Discriminator extends string = string> =\n ObjectSchema<Record<Discriminator, EnumSchema<any> | LiteralSchema<any>>>\n\n/**\n * Type representing a non-empty tuple of discriminated union variants.\n *\n * @template TDiscriminator - The discriminator property name\n */\nexport type DiscriminatedUnionVariants<TDiscriminator extends string> =\n readonly [\n DiscriminatedUnionVariant<TDiscriminator>,\n ...DiscriminatedUnionVariant<TDiscriminator>[],\n ]\n\ntype DiscriminatedUnionSchemaInput<TVariants extends readonly Validator[]> =\n TVariants extends readonly [\n infer TValidator extends Validator,\n ...infer TRest extends readonly Validator[],\n ]\n ? InferInput<TValidator> | DiscriminatedUnionSchemaInput<TRest>\n : never\n\ntype DiscriminatedUnionSchemaOutput<TVariants extends readonly Validator[]> =\n TVariants extends readonly [\n infer TValidator extends Validator,\n ...infer TRest extends readonly Validator[],\n ]\n ? InferOutput<TValidator> | DiscriminatedUnionSchemaOutput<TRest>\n : never\n\n/**\n * Schema for validating discriminated unions of objects.\n *\n * More efficient than regular union schemas when discriminating on a known\n * property. Looks up the correct variant schema directly based on the\n * discriminator value instead of trying each variant in sequence.\n *\n * @note There is no discriminated union in Lexicon schemas. This is a custom\n * extension to allow optimized validation of union of objects when using the\n * lex library programmatically (i.e. not code generated from a lexicon schema).\n *\n * @template TDiscriminator - The discriminator property name\n * @template TVariants - Tuple type of the variant schemas\n *\n * @example\n * ```ts\n * const schema = new DiscriminatedUnionSchema('type', [\n * l.object({ type: l.literal('text'), content: l.string() }),\n * l.object({ type: l.literal('image'), url: l.string() }),\n * ])\n * ```\n */\nexport class DiscriminatedUnionSchema<\n const TDiscriminator extends string,\n const TVariants extends DiscriminatedUnionVariants<TDiscriminator>,\n> extends Schema<\n DiscriminatedUnionSchemaInput<TVariants>,\n DiscriminatedUnionSchemaOutput<TVariants>\n> {\n readonly type = 'discriminatedUnion' as const\n\n readonly variantsMap: Map<unknown, DiscriminatedUnionVariant<TDiscriminator>>\n\n constructor(\n readonly discriminator: TDiscriminator,\n readonly variants: TVariants,\n ) {\n super()\n\n // Although we usually try to avoid initialization work in constructors,\n // here it is necessary to ensure that invalid discriminated throw from the\n // place of construction, rather than later during validation.\n this.variantsMap = buildVariantsMap(discriminator, variants)\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (!isPlainObject(input)) {\n return ctx.issueUnexpectedType(input, 'object')\n }\n\n const { discriminator } = this\n\n if (!Object.hasOwn(input, discriminator)) {\n return ctx.issueRequiredKey(input, discriminator)\n }\n\n const discriminatorValue = input[discriminator]\n\n const variant = this.variantsMap.get(discriminatorValue)\n if (variant) {\n return ctx.validate(input, variant) as ValidationResult<\n DiscriminatedUnionSchemaInput<TVariants>\n >\n }\n\n return ctx.issueInvalidPropertyValue(input, discriminator, [\n ...this.variantsMap.keys(),\n ])\n }\n}\n\nfunction buildVariantsMap<Discriminator extends string>(\n discriminator: Discriminator,\n variants: DiscriminatedUnionVariants<Discriminator>,\n) {\n const variantsMap = new Map<\n unknown,\n DiscriminatedUnionVariant<Discriminator>\n >()\n\n for (const variant of variants) {\n const schema = variant.shape[discriminator]\n if (schema instanceof LiteralSchema) {\n if (variantsMap.has(schema.value)) {\n throw new TypeError(`Overlapping discriminator value: ${schema.value}`)\n }\n variantsMap.set(schema.value, variant)\n } else if (schema instanceof EnumSchema) {\n for (const val of schema.values) {\n if (variantsMap.has(val)) {\n throw new TypeError(`Overlapping discriminator value: ${val}`)\n }\n variantsMap.set(val, variant)\n }\n } else {\n // Only enumerable discriminator schemas are supported\n\n // Should never happen if types are used correctly\n throw new TypeError(\n `Discriminator schema must be a LiteralSchema or EnumSchema`,\n )\n }\n }\n\n return variantsMap\n}\n\n/**\n * Creates a discriminated union schema for efficient object type switching.\n *\n * Unlike regular `union()`, this schema uses a discriminator property to\n * directly look up the correct variant, providing O(1) validation instead\n * of trying each variant sequentially.\n *\n * @param discriminator - Property name to discriminate on\n * @param variants - Non-empty array of object schemas with the discriminator property\n * @returns A new {@link DiscriminatedUnionSchema} instance\n *\n * @example\n * ```ts\n * // Message types discriminated by 'kind'\n * const messageSchema = l.discriminatedUnion('kind', [\n * l.object({ kind: l.literal('text'), text: l.string() }),\n * l.object({ kind: l.literal('image'), url: l.string(), alt: l.optional(l.string()) }),\n * l.object({ kind: l.literal('video'), url: l.string(), duration: l.integer() }),\n * ])\n *\n * // Using enums for multiple values mapping to same variant\n * const statusSchema = l.discriminatedUnion('status', [\n * l.object({ status: l.enum(['pending', 'processing']), startedAt: l.string() }),\n * l.object({ status: l.literal('completed'), completedAt: l.string() }),\n * l.object({ status: l.literal('failed'), error: l.string() }),\n * ])\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function discriminatedUnion<\n const Discriminator extends string,\n const Options extends DiscriminatedUnionVariants<Discriminator>,\n>(discriminator: Discriminator, variants: Options) {\n return new DiscriminatedUnionSchema<Discriminator, Options>(\n discriminator,\n variants,\n )\n}\n"]}
1
+ {"version":3,"file":"discriminated-union.js","sourceRoot":"","sources":["../../src/schema/discriminated-union.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAGL,MAAM,GAIP,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAyC5C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,wBAGX,SAAQ,MAGT;IAKC,YACW,aAA6B,EAC7B,QAAmB;QAE5B,KAAK,EAAE,CAAA;QAHE,kBAAa,GAAb,aAAa,CAAgB;QAC7B,aAAQ,GAAR,QAAQ,CAAW;QANrB,SAAI,GAAG,oBAA6B,CAAA;QAU3C,wEAAwE;QACxE,2EAA2E;QAC3E,8DAA8D;QAC9D,IAAI,CAAC,WAAW,GAAG,gBAAgB,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAA;IAC9D,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,GAAG,CAAC,mBAAmB,C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MAAM,EAAE,CAAC;gBAChC,IAAI,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;oBACzB,MAAM,IAAI,SAAS,CAAC,oCAAoC,GAAG,EAAE,CAAC,CAAA;gBAChE,CAAC;gBACD,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;YAC/B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,sDAAsD;YAEtD,kDAAkD;YAClD,MAAM,IAAI,SAAS,CACjB,4DAA4D,CAC7D,CAAA;QACH,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAA;AACpB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAwB;AACxB,MAAM,UAAU,kBAAkB,CAGhC,aAA4B,EAAE,QAAiB;IAC/C,OAAO,IAAI,wBAAwB,CACjC,aAAa,EACb,QAAQ,CACT,CAAA;AACH,CAAC","sourcesContent":["import { isPlainObject } from '@atproto/lex-data'\nimport {\n InferInput,\n InferOutput,\n Schema,\n ValidationContext,\n ValidationResult,\n Validator,\n} from '../core.js'\nimport { EnumSchema } from './enum.js'\nimport { LiteralSchema } from './literal.js'\nimport { ObjectSchema } from './object.js'\n\n/**\n * Type representing a single variant in a discriminated union.\n *\n * Must be an ObjectSchema with the discriminator property using either\n * a LiteralSchema or EnumSchema.\n *\n * @template Discriminator - The discriminator property name\n */\nexport type DiscriminatedUnionVariant<Discriminator extends string = string> =\n ObjectSchema<Record<Discriminator, EnumSchema<any> | LiteralSchema<any>>>\n\n/**\n * Type representing a non-empty tuple of discriminated union variants.\n *\n * @template TDiscriminator - The discriminator property name\n */\nexport type DiscriminatedUnionVariants<TDiscriminator extends string> =\n readonly [\n DiscriminatedUnionVariant<TDiscriminator>,\n ...DiscriminatedUnionVariant<TDiscriminator>[],\n ]\n\ntype DiscriminatedUnionSchemaInput<TVariants extends readonly Validator[]> =\n TVariants extends readonly [\n infer TValidator extends Validator,\n ...infer TRest extends readonly Validator[],\n ]\n ? InferInput<TValidator> | DiscriminatedUnionSchemaInput<TRest>\n : never\n\ntype DiscriminatedUnionSchemaOutput<TVariants extends readonly Validator[]> =\n TVariants extends readonly [\n infer TValidator extends Validator,\n ...infer TRest extends readonly Validator[],\n ]\n ? InferOutput<TValidator> | DiscriminatedUnionSchemaOutput<TRest>\n : never\n\n/**\n * Schema for validating discriminated unions of objects.\n *\n * More efficient than regular union schemas when discriminating on a known\n * property. Looks up the correct variant schema directly based on the\n * discriminator value instead of trying each variant in sequence.\n *\n * @note There is no discriminated union in Lexicon schemas. This is a custom\n * extension to allow optimized validation of union of objects when using the\n * lex library programmatically (i.e. not code generated from a lexicon schema).\n *\n * @template TDiscriminator - The discriminator property name\n * @template TVariants - Tuple type of the variant schemas\n *\n * @example\n * ```ts\n * const schema = new DiscriminatedUnionSchema('type', [\n * l.object({ type: l.literal('text'), content: l.string() }),\n * l.object({ type: l.literal('image'), url: l.string() }),\n * ])\n * ```\n */\nexport class DiscriminatedUnionSchema<\n const TDiscriminator extends string,\n const TVariants extends DiscriminatedUnionVariants<TDiscriminator>,\n> extends Schema<\n DiscriminatedUnionSchemaInput<TVariants>,\n DiscriminatedUnionSchemaOutput<TVariants>\n> {\n readonly type = 'discriminatedUnion' as const\n\n readonly variantsMap: Map<unknown, DiscriminatedUnionVariant<TDiscriminator>>\n\n constructor(\n readonly discriminator: TDiscriminator,\n readonly variants: TVariants,\n ) {\n super()\n\n // Although we usually try to avoid initialization work in constructors,\n // here it is necessary to ensure that invalid discriminated throw from the\n // place of construction, rather than later during validation.\n this.variantsMap = buildVariantsMap(discriminator, variants)\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (!isPlainObject(input)) {\n return ctx.issueUnexpectedType(input, 'object')\n }\n\n const { discriminator } = this\n\n if (!Object.hasOwn(input, discriminator)) {\n return ctx.issueRequiredKey(input, discriminator)\n }\n\n const discriminatorValue = input[discriminator]\n\n const variant = this.variantsMap.get(discriminatorValue)\n if (variant) {\n return ctx.validate(input, variant) as ValidationResult<\n DiscriminatedUnionSchemaInput<TVariants>\n >\n }\n\n return ctx.issueInvalidPropertyValue(input, discriminator, [\n ...this.variantsMap.keys(),\n ])\n }\n}\n\nfunction buildVariantsMap<Discriminator extends string>(\n discriminator: Discriminator,\n variants: DiscriminatedUnionVariants<Discriminator>,\n) {\n const variantsMap = new Map<\n unknown,\n DiscriminatedUnionVariant<Discriminator>\n >()\n\n for (const variant of variants) {\n const schema = variant.shape[discriminator]\n if (schema instanceof LiteralSchema) {\n if (variantsMap.has(schema.value)) {\n throw new TypeError(`Overlapping discriminator value: ${schema.value}`)\n }\n variantsMap.set(schema.value, variant)\n } else if (schema instanceof EnumSchema) {\n for (const val of schema.values) {\n if (variantsMap.has(val)) {\n throw new TypeError(`Overlapping discriminator value: ${val}`)\n }\n variantsMap.set(val, variant)\n }\n } else {\n // Only enumerable discriminator schemas are supported\n\n // Should never happen if types are used correctly\n throw new TypeError(\n `Discriminator schema must be a LiteralSchema or EnumSchema`,\n )\n }\n }\n\n return variantsMap\n}\n\n/**\n * Creates a discriminated union schema for efficient object type switching.\n *\n * Unlike regular `union()`, this schema uses a discriminator property to\n * directly look up the correct variant, providing O(1) validation instead\n * of trying each variant sequentially.\n *\n * @param discriminator - Property name to discriminate on\n * @param variants - Non-empty array of object schemas with the discriminator property\n * @returns A new {@link DiscriminatedUnionSchema} instance\n *\n * @example\n * ```ts\n * // Message types discriminated by 'kind'\n * const messageSchema = l.discriminatedUnion('kind', [\n * l.object({ kind: l.literal('text'), text: l.string() }),\n * l.object({ kind: l.literal('image'), url: l.string(), alt: l.optional(l.string()) }),\n * l.object({ kind: l.literal('video'), url: l.string(), duration: l.integer() }),\n * ])\n *\n * // Using enums for multiple values mapping to same variant\n * const statusSchema = l.discriminatedUnion('status', [\n * l.object({ status: l.enum(['pending', 'processing']), startedAt: l.string() }),\n * l.object({ status: l.literal('completed'), completedAt: l.string() }),\n * l.object({ status: l.literal('failed'), error: l.string() }),\n * ])\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function discriminatedUnion<\n const Discriminator extends string,\n const Options extends DiscriminatedUnionVariants<Discriminator>,\n>(discriminator: Discriminator, variants: Options) {\n return new DiscriminatedUnionSchema<Discriminator, Options>(\n discriminator,\n variants,\n )\n}\n"]}
@@ -1,9 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EnumSchema = void 0;
4
- exports.enumSchema = enumSchema;
5
- exports.enum = enumSchema;
6
- const core_js_1 = require("../core.js");
1
+ import { Schema } from '../core.js';
7
2
  /**
8
3
  * Schema that accepts one of several specific literal values.
9
4
  *
@@ -19,12 +14,11 @@ const core_js_1 = require("../core.js");
19
14
  * schema.validate('invalid') // fails
20
15
  * ```
21
16
  */
22
- class EnumSchema extends core_js_1.Schema {
23
- values;
24
- type = 'enum';
17
+ export class EnumSchema extends Schema {
25
18
  constructor(values) {
26
19
  super();
27
20
  this.values = values;
21
+ this.type = 'enum';
28
22
  }
29
23
  validateInContext(input, ctx) {
30
24
  if (!this.values.includes(input)) {
@@ -33,7 +27,6 @@ class EnumSchema extends core_js_1.Schema {
33
27
  return ctx.success(input);
34
28
  }
35
29
  }
36
- exports.EnumSchema = EnumSchema;
37
30
  /**
38
31
  * Creates an enum schema that accepts one of the specified values.
39
32
  *
@@ -68,7 +61,9 @@ exports.EnumSchema = EnumSchema;
68
61
  * ```
69
62
  */
70
63
  /*@__NO_SIDE_EFFECTS__*/
71
- function enumSchema(value) {
64
+ export function enumSchema(value) {
72
65
  return new EnumSchema(value);
73
66
  }
67
+ // @NOTE "enum" is a reserved keyword in JS/TS
68
+ export { enumSchema as enum };
74
69
  //# sourceMappingURL=enum.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"enum.js","sourceRoot":"","sources":["../../src/schema/enum.ts"],"names":[],"mappings":";;;AAqEA,gCAIC;AAGsB,0BAAI;AA5E3B,wCAAsD;AAEtD;;;;;;;;;;;;;;GAcG;AACH,MAAa,UAEX,SAAQ,gBAAc;IAGD;IAFZ,IAAI,GAAG,MAAe,CAAA;IAE/B,YAAqB,MAAyB;QAC5C,KAAK,EAAE,CAAA;QADY,WAAM,GAAN,MAAM,CAAmB;IAE9C,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,CAAE,IAAI,CAAC,MAA6B,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACzD,OAAO,GAAG,CAAC,iBAAiB,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;QAClD,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,KAAe,CAAC,CAAA;IACrC,CAAC;CACF;AAhBD,gCAgBC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAwB;AACxB,SAAgB,UAAU,CACxB,KAAmB;IAEnB,OAAO,IAAI,UAAU,CAAI,KAAK,CAAC,CAAA;AACjC,CAAC","sourcesContent":["import { Schema, ValidationContext } from '../core.js'\n\n/**\n * Schema that accepts one of several specific literal values.\n *\n * Validates that the input matches one of the allowed values using strict\n * equality. Similar to TypeScript union of literals.\n *\n * @template TValue - The union of literal types\n *\n * @example\n * ```ts\n * const schema = new EnumSchema(['pending', 'active', 'completed'])\n * schema.validate('active') // success\n * schema.validate('invalid') // fails\n * ```\n */\nexport class EnumSchema<\n const TValue extends null | string | number | boolean,\n> extends Schema<TValue> {\n readonly type = 'enum' as const\n\n constructor(readonly values: readonly TValue[]) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (!(this.values as readonly unknown[]).includes(input)) {\n return ctx.issueInvalidValue(input, this.values)\n }\n\n return ctx.success(input as TValue)\n }\n}\n\n/**\n * Creates an enum schema that accepts one of the specified values.\n *\n * Similar to TypeScript's union of string literals. Use `l.enum()` for\n * the namespace-friendly alias.\n *\n * @param value - Array of allowed values\n * @returns A new {@link EnumSchema} instance\n *\n * @example\n * ```ts\n * // String enum\n * const statusSchema = l.enum(['pending', 'active', 'completed', 'failed'])\n *\n * // Number enum\n * const prioritySchema = l.enum([1, 2, 3, 4, 5])\n *\n * // Mixed types\n * const mixedSchema = l.enum(['auto', 0, 1, true])\n *\n * // Use in objects\n * const taskSchema = l.object({\n * title: l.string(),\n * status: l.enum(['todo', 'in-progress', 'done']),\n * })\n *\n * // In discriminated unions\n * const resultSchema = l.discriminatedUnion('status', [\n * l.object({ status: l.enum(['pending', 'processing']), progress: l.integer() }),\n * l.object({ status: l.literal('completed'), result: l.unknown() }),\n * ])\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function enumSchema<const V extends null | string | number | boolean>(\n value: readonly V[],\n) {\n return new EnumSchema<V>(value)\n}\n\n// @NOTE \"enum\" is a reserved keyword in JS/TS\nexport { enumSchema as enum }\n"]}
1
+ {"version":3,"file":"enum.js","sourceRoot":"","sources":["../../src/schema/enum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAqB,MAAM,YAAY,CAAA;AAEtD;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,UAEX,SAAQ,MAAc;IAGtB,YAAqB,MAAyB;QAC5C,KAAK,EAAE,CAAA;QADY,WAAM,GAAN,MAAM,CAAmB;QAFrC,SAAI,GAAG,MAAe,CAAA;IAI/B,CAAC;IAED,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,CAAE,IAAI,CAAC,MAA6B,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACzD,OAAO,GAAG,CAAC,iBAAiB,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;QAClD,CAAC;QAED,OAAO,GAAG,CAAC,OAAO,CAAC,KAAe,CAAC,CAAA;IACrC,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAwB;AACxB,MAAM,UAAU,UAAU,CACxB,KAAmB;IAEnB,OAAO,IAAI,UAAU,CAAI,KAAK,CAAC,CAAA;AACjC,CAAC;AAED,8CAA8C;AAC9C,OAAO,EAAE,UAAU,IAAI,IAAI,EAAE,CAAA","sourcesContent":["import { Schema, ValidationContext } from '../core.js'\n\n/**\n * Schema that accepts one of several specific literal values.\n *\n * Validates that the input matches one of the allowed values using strict\n * equality. Similar to TypeScript union of literals.\n *\n * @template TValue - The union of literal types\n *\n * @example\n * ```ts\n * const schema = new EnumSchema(['pending', 'active', 'completed'])\n * schema.validate('active') // success\n * schema.validate('invalid') // fails\n * ```\n */\nexport class EnumSchema<\n const TValue extends null | string | number | boolean,\n> extends Schema<TValue> {\n readonly type = 'enum' as const\n\n constructor(readonly values: readonly TValue[]) {\n super()\n }\n\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (!(this.values as readonly unknown[]).includes(input)) {\n return ctx.issueInvalidValue(input, this.values)\n }\n\n return ctx.success(input as TValue)\n }\n}\n\n/**\n * Creates an enum schema that accepts one of the specified values.\n *\n * Similar to TypeScript's union of string literals. Use `l.enum()` for\n * the namespace-friendly alias.\n *\n * @param value - Array of allowed values\n * @returns A new {@link EnumSchema} instance\n *\n * @example\n * ```ts\n * // String enum\n * const statusSchema = l.enum(['pending', 'active', 'completed', 'failed'])\n *\n * // Number enum\n * const prioritySchema = l.enum([1, 2, 3, 4, 5])\n *\n * // Mixed types\n * const mixedSchema = l.enum(['auto', 0, 1, true])\n *\n * // Use in objects\n * const taskSchema = l.object({\n * title: l.string(),\n * status: l.enum(['todo', 'in-progress', 'done']),\n * })\n *\n * // In discriminated unions\n * const resultSchema = l.discriminatedUnion('status', [\n * l.object({ status: l.enum(['pending', 'processing']), progress: l.integer() }),\n * l.object({ status: l.literal('completed'), result: l.unknown() }),\n * ])\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function enumSchema<const V extends null | string | number | boolean>(\n value: readonly V[],\n) {\n return new EnumSchema<V>(value)\n}\n\n// @NOTE \"enum\" is a reserved keyword in JS/TS\nexport { enumSchema as enum }\n"]}
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.integer = exports.IntegerSchema = void 0;
4
- const core_js_1 = require("../core.js");
5
- const memoize_js_1 = require("../util/memoize.js");
1
+ import { Schema } from '../core.js';
2
+ import { memoizedOptions } from '../util/memoize.js';
6
3
  /**
7
4
  * Schema for validating integer values with optional range constraints.
8
5
  *
@@ -15,12 +12,11 @@ const memoize_js_1 = require("../util/memoize.js");
15
12
  * const result = schema.validate(42)
16
13
  * ```
17
14
  */
18
- class IntegerSchema extends core_js_1.Schema {
19
- options;
20
- type = 'integer';
15
+ export class IntegerSchema extends Schema {
21
16
  constructor(options) {
22
17
  super();
23
18
  this.options = options;
19
+ this.type = 'integer';
24
20
  }
25
21
  validateInContext(input, ctx) {
26
22
  if (!isInteger(input)) {
@@ -35,7 +31,6 @@ class IntegerSchema extends core_js_1.Schema {
35
31
  return ctx.success(input);
36
32
  }
37
33
  }
38
- exports.IntegerSchema = IntegerSchema;
39
34
  /**
40
35
  * Simple wrapper around {@link Number.isSafeInteger} that acts as a type guard.
41
36
  */
@@ -66,7 +61,7 @@ function isInteger(input) {
66
61
  * const ageSchema = l.integer({ minimum: 0, maximum: 150 })
67
62
  * ```
68
63
  */
69
- exports.integer = (0, memoize_js_1.memoizedOptions)(function (options) {
64
+ export const integer = /*#__PURE__*/ memoizedOptions(function (options) {
70
65
  return new IntegerSchema(options);
71
66
  });
72
67
  //# sourceMappingURL=integer.js.map