@atproto/lex-schema 0.0.12 → 0.0.13

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 (199) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/core/schema.d.ts +4 -4
  3. package/dist/core/schema.d.ts.map +1 -1
  4. package/dist/core/schema.js +1 -1
  5. package/dist/core/schema.js.map +1 -1
  6. package/dist/core/validation-issue.js +3 -1
  7. package/dist/core/validation-issue.js.map +1 -1
  8. package/dist/core/validator.d.ts +10 -2
  9. package/dist/core/validator.d.ts.map +1 -1
  10. package/dist/core/validator.js +21 -3
  11. package/dist/core/validator.js.map +1 -1
  12. package/dist/helpers.d.ts +10 -11
  13. package/dist/helpers.d.ts.map +1 -1
  14. package/dist/helpers.js.map +1 -1
  15. package/dist/schema/array.d.ts +1 -0
  16. package/dist/schema/array.d.ts.map +1 -1
  17. package/dist/schema/array.js +2 -1
  18. package/dist/schema/array.js.map +1 -1
  19. package/dist/schema/blob.d.ts +4 -2
  20. package/dist/schema/blob.d.ts.map +1 -1
  21. package/dist/schema/blob.js +5 -2
  22. package/dist/schema/blob.js.map +1 -1
  23. package/dist/schema/boolean.d.ts +1 -0
  24. package/dist/schema/boolean.d.ts.map +1 -1
  25. package/dist/schema/boolean.js +2 -1
  26. package/dist/schema/boolean.js.map +1 -1
  27. package/dist/schema/bytes.d.ts +1 -0
  28. package/dist/schema/bytes.d.ts.map +1 -1
  29. package/dist/schema/bytes.js +2 -1
  30. package/dist/schema/bytes.js.map +1 -1
  31. package/dist/schema/cid.d.ts +1 -0
  32. package/dist/schema/cid.d.ts.map +1 -1
  33. package/dist/schema/cid.js +2 -1
  34. package/dist/schema/cid.js.map +1 -1
  35. package/dist/schema/custom.d.ts +1 -0
  36. package/dist/schema/custom.d.ts.map +1 -1
  37. package/dist/schema/custom.js +1 -0
  38. package/dist/schema/custom.js.map +1 -1
  39. package/dist/schema/dict.d.ts +1 -0
  40. package/dist/schema/dict.d.ts.map +1 -1
  41. package/dist/schema/dict.js +2 -1
  42. package/dist/schema/dict.js.map +1 -1
  43. package/dist/schema/discriminated-union.d.ts +1 -0
  44. package/dist/schema/discriminated-union.d.ts.map +1 -1
  45. package/dist/schema/discriminated-union.js +2 -1
  46. package/dist/schema/discriminated-union.js.map +1 -1
  47. package/dist/schema/enum.d.ts +1 -0
  48. package/dist/schema/enum.d.ts.map +1 -1
  49. package/dist/schema/enum.js +1 -0
  50. package/dist/schema/enum.js.map +1 -1
  51. package/dist/schema/integer.d.ts +1 -0
  52. package/dist/schema/integer.d.ts.map +1 -1
  53. package/dist/schema/integer.js +2 -1
  54. package/dist/schema/integer.js.map +1 -1
  55. package/dist/schema/intersection.d.ts +1 -0
  56. package/dist/schema/intersection.d.ts.map +1 -1
  57. package/dist/schema/intersection.js +1 -0
  58. package/dist/schema/intersection.js.map +1 -1
  59. package/dist/schema/lex-map.d.ts +37 -0
  60. package/dist/schema/lex-map.d.ts.map +1 -0
  61. package/dist/schema/lex-map.js +60 -0
  62. package/dist/schema/lex-map.js.map +1 -0
  63. package/dist/schema/lex-value.d.ts +35 -0
  64. package/dist/schema/lex-value.d.ts.map +1 -0
  65. package/dist/schema/lex-value.js +87 -0
  66. package/dist/schema/lex-value.js.map +1 -0
  67. package/dist/schema/literal.d.ts +1 -0
  68. package/dist/schema/literal.d.ts.map +1 -1
  69. package/dist/schema/literal.js +1 -0
  70. package/dist/schema/literal.js.map +1 -1
  71. package/dist/schema/never.d.ts +1 -0
  72. package/dist/schema/never.d.ts.map +1 -1
  73. package/dist/schema/never.js +2 -1
  74. package/dist/schema/never.js.map +1 -1
  75. package/dist/schema/null.d.ts +1 -0
  76. package/dist/schema/null.d.ts.map +1 -1
  77. package/dist/schema/null.js +2 -1
  78. package/dist/schema/null.js.map +1 -1
  79. package/dist/schema/nullable.d.ts +1 -0
  80. package/dist/schema/nullable.d.ts.map +1 -1
  81. package/dist/schema/nullable.js +1 -0
  82. package/dist/schema/nullable.js.map +1 -1
  83. package/dist/schema/object.d.ts +1 -0
  84. package/dist/schema/object.d.ts.map +1 -1
  85. package/dist/schema/object.js +2 -1
  86. package/dist/schema/object.js.map +1 -1
  87. package/dist/schema/optional.d.ts +1 -0
  88. package/dist/schema/optional.d.ts.map +1 -1
  89. package/dist/schema/optional.js +1 -0
  90. package/dist/schema/optional.js.map +1 -1
  91. package/dist/schema/params.d.ts +14 -10
  92. package/dist/schema/params.d.ts.map +1 -1
  93. package/dist/schema/params.js +84 -24
  94. package/dist/schema/params.js.map +1 -1
  95. package/dist/schema/payload.d.ts.map +1 -1
  96. package/dist/schema/payload.js +3 -3
  97. package/dist/schema/payload.js.map +1 -1
  98. package/dist/schema/record.d.ts +13 -17
  99. package/dist/schema/record.d.ts.map +1 -1
  100. package/dist/schema/record.js +1 -0
  101. package/dist/schema/record.js.map +1 -1
  102. package/dist/schema/ref.d.ts +1 -0
  103. package/dist/schema/ref.d.ts.map +1 -1
  104. package/dist/schema/ref.js +1 -0
  105. package/dist/schema/ref.js.map +1 -1
  106. package/dist/schema/regexp.d.ts +1 -0
  107. package/dist/schema/regexp.d.ts.map +1 -1
  108. package/dist/schema/regexp.js +2 -1
  109. package/dist/schema/regexp.js.map +1 -1
  110. package/dist/schema/string.d.ts +22 -6
  111. package/dist/schema/string.d.ts.map +1 -1
  112. package/dist/schema/string.js +16 -9
  113. package/dist/schema/string.js.map +1 -1
  114. package/dist/schema/token.d.ts +1 -0
  115. package/dist/schema/token.d.ts.map +1 -1
  116. package/dist/schema/token.js +2 -1
  117. package/dist/schema/token.js.map +1 -1
  118. package/dist/schema/typed-object.d.ts +11 -15
  119. package/dist/schema/typed-object.d.ts.map +1 -1
  120. package/dist/schema/typed-object.js +2 -1
  121. package/dist/schema/typed-object.js.map +1 -1
  122. package/dist/schema/typed-ref.d.ts +1 -0
  123. package/dist/schema/typed-ref.d.ts.map +1 -1
  124. package/dist/schema/typed-ref.js +1 -0
  125. package/dist/schema/typed-ref.js.map +1 -1
  126. package/dist/schema/typed-union.d.ts +1 -0
  127. package/dist/schema/typed-union.d.ts.map +1 -1
  128. package/dist/schema/typed-union.js +2 -1
  129. package/dist/schema/typed-union.js.map +1 -1
  130. package/dist/schema/union.d.ts +1 -0
  131. package/dist/schema/union.d.ts.map +1 -1
  132. package/dist/schema/union.js +1 -0
  133. package/dist/schema/union.js.map +1 -1
  134. package/dist/schema/unknown.d.ts +1 -0
  135. package/dist/schema/unknown.d.ts.map +1 -1
  136. package/dist/schema/unknown.js +1 -0
  137. package/dist/schema/unknown.js.map +1 -1
  138. package/dist/schema/with-default.d.ts +1 -0
  139. package/dist/schema/with-default.d.ts.map +1 -1
  140. package/dist/schema/with-default.js +1 -0
  141. package/dist/schema/with-default.js.map +1 -1
  142. package/dist/schema.d.ts +2 -1
  143. package/dist/schema.d.ts.map +1 -1
  144. package/dist/schema.js +2 -1
  145. package/dist/schema.js.map +1 -1
  146. package/dist/util/if-any.d.ts +2 -0
  147. package/dist/util/if-any.d.ts.map +1 -0
  148. package/dist/util/if-any.js +3 -0
  149. package/dist/util/if-any.js.map +1 -0
  150. package/package.json +2 -2
  151. package/src/core/schema.ts +9 -3
  152. package/src/core/validation-issue.ts +3 -2
  153. package/src/core/validator.ts +23 -3
  154. package/src/helpers.test.ts +1 -1
  155. package/src/helpers.ts +53 -19
  156. package/src/schema/array.ts +3 -1
  157. package/src/schema/blob.ts +4 -1
  158. package/src/schema/boolean.ts +3 -1
  159. package/src/schema/bytes.ts +3 -1
  160. package/src/schema/cid.ts +3 -1
  161. package/src/schema/custom.ts +2 -0
  162. package/src/schema/dict.ts +3 -1
  163. package/src/schema/discriminated-union.ts +3 -1
  164. package/src/schema/enum.ts +2 -0
  165. package/src/schema/integer.ts +3 -1
  166. package/src/schema/intersection.ts +2 -0
  167. package/src/schema/{unknown-object.test.ts → lex-map.test.ts} +9 -9
  168. package/src/schema/lex-map.ts +63 -0
  169. package/src/schema/lex-value.test.ts +81 -0
  170. package/src/schema/lex-value.ts +86 -0
  171. package/src/schema/literal.ts +2 -0
  172. package/src/schema/never.ts +3 -1
  173. package/src/schema/null.ts +3 -1
  174. package/src/schema/nullable.ts +2 -0
  175. package/src/schema/object.ts +3 -1
  176. package/src/schema/optional.ts +2 -0
  177. package/src/schema/params.test.ts +82 -43
  178. package/src/schema/params.ts +133 -39
  179. package/src/schema/payload.test.ts +2 -2
  180. package/src/schema/payload.ts +3 -4
  181. package/src/schema/record.ts +19 -8
  182. package/src/schema/ref.ts +2 -0
  183. package/src/schema/regexp.ts +3 -1
  184. package/src/schema/string.test.ts +99 -2
  185. package/src/schema/string.ts +58 -15
  186. package/src/schema/token.ts +3 -1
  187. package/src/schema/typed-object.ts +19 -8
  188. package/src/schema/typed-ref.ts +2 -0
  189. package/src/schema/typed-union.ts +3 -1
  190. package/src/schema/union.ts +2 -0
  191. package/src/schema/unknown.ts +2 -0
  192. package/src/schema/with-default.ts +2 -0
  193. package/src/schema.ts +2 -1
  194. package/src/util/if-any.ts +3 -0
  195. package/dist/schema/unknown-object.d.ts +0 -42
  196. package/dist/schema/unknown-object.d.ts.map +0 -1
  197. package/dist/schema/unknown-object.js +0 -50
  198. package/dist/schema/unknown-object.js.map +0 -1
  199. package/src/schema/unknown-object.ts +0 -53
@@ -15,6 +15,13 @@ import {
15
15
  Validator,
16
16
  } from '../core.js'
17
17
 
18
+ export type MaybeTypedObject<
19
+ TType extends $Type,
20
+ TValue extends { $type?: unknown } = { $type?: unknown },
21
+ > = TValue extends { $type?: TType }
22
+ ? TValue
23
+ : $TypedMaybe<Exclude<TValue, Unknown$TypedObject>, TType>
24
+
18
25
  /**
19
26
  * Schema for typed objects in Lexicon unions.
20
27
  *
@@ -40,6 +47,8 @@ export class TypedObjectSchema<
40
47
  $TypedMaybe<InferInput<TShape>, TType>,
41
48
  $TypedMaybe<InferOutput<TShape>, TType>
42
49
  > {
50
+ readonly type = 'typedObject' as const
51
+
43
52
  constructor(
44
53
  readonly $type: TType,
45
54
  readonly schema: TShape,
@@ -47,11 +56,9 @@ export class TypedObjectSchema<
47
56
  super()
48
57
  }
49
58
 
50
- isTypeOf<X extends Record<string, unknown>>(
51
- value: X,
52
- ): value is X extends { $type?: TType }
53
- ? X
54
- : $TypedMaybe<Exclude<X, Unknown$TypedObject>, TType> {
59
+ isTypeOf<TValue extends Record<string, unknown>>(
60
+ value: TValue,
61
+ ): value is MaybeTypedObject<TType, TValue> {
55
62
  return value.$type === undefined || value.$type === this.$type
56
63
  }
57
64
 
@@ -64,17 +71,21 @@ export class TypedObjectSchema<
64
71
  >
65
72
  }
66
73
 
67
- $isTypeOf<X extends Record<string, unknown>>(value: X) {
74
+ $isTypeOf<TValue extends Record<string, unknown>>(
75
+ value: TValue,
76
+ ): value is MaybeTypedObject<TType, TValue> {
68
77
  return this.isTypeOf(value)
69
78
  }
70
79
 
71
- $build(input: Omit<InferInput<this>, '$type'>) {
80
+ $build(
81
+ input: Omit<InferInput<this>, '$type'>,
82
+ ): $Typed<InferOutput<this>, TType> {
72
83
  return this.build(input)
73
84
  }
74
85
 
75
86
  validateInContext(input: unknown, ctx: ValidationContext) {
76
87
  if (!isPlainObject(input)) {
77
- return ctx.issueInvalidType(input, 'object')
88
+ return ctx.issueUnexpectedType(input, 'object')
78
89
  }
79
90
 
80
91
  if (
@@ -51,6 +51,8 @@ export class TypedRefSchema<
51
51
  $Typed<InferInput<TValidator>>,
52
52
  $Typed<InferOutput<TValidator>>
53
53
  > {
54
+ readonly type = 'typedRef' as const
55
+
54
56
  #getter: TypedRefGetter<TValidator>
55
57
 
56
58
  constructor(getter: TypedRefGetter<TValidator>) {
@@ -42,6 +42,8 @@ export class TypedUnionSchema<
42
42
  ? InferOutput<TValidators[number]>
43
43
  : InferOutput<TValidators[number]> | Unknown$TypedObject
44
44
  > {
45
+ readonly type = 'typedUnion' as const
46
+
45
47
  constructor(
46
48
  protected readonly validators: TValidators,
47
49
  public readonly closed: TClosed,
@@ -67,7 +69,7 @@ export class TypedUnionSchema<
67
69
 
68
70
  validateInContext(input: unknown, ctx: ValidationContext) {
69
71
  if (!isPlainObject(input) || !('$type' in input)) {
70
- return ctx.issueInvalidType(input, '$typed')
72
+ return ctx.issueUnexpectedType(input, '$typed')
71
73
  }
72
74
 
73
75
  const { $type } = input
@@ -37,6 +37,8 @@ export class UnionSchema<
37
37
  InferInput<TValidators[number]>,
38
38
  InferOutput<TValidators[number]>
39
39
  > {
40
+ readonly type = 'union' as const
41
+
40
42
  constructor(protected readonly validators: TValidators) {
41
43
  super()
42
44
  }
@@ -15,6 +15,8 @@ import { memoizedOptions } from '../util/memoize.js'
15
15
  * ```
16
16
  */
17
17
  export class UnknownSchema extends Schema<unknown> {
18
+ readonly type = 'unknown' as const
19
+
18
20
  validateInContext(input: unknown, ctx: ValidationContext) {
19
21
  return ctx.success(input)
20
22
  }
@@ -25,6 +25,8 @@ import {
25
25
  export class WithDefaultSchema<
26
26
  const TValidator extends Validator,
27
27
  > extends Schema<InferInput<TValidator>, InferOutput<TValidator>> {
28
+ readonly type = 'withDefault' as const
29
+
28
30
  constructor(
29
31
  readonly validator: TValidator,
30
32
  readonly defaultValue: InferInput<TValidator>,
package/src/schema.ts CHANGED
@@ -7,13 +7,14 @@ export * from './schema/cid.js'
7
7
  export * from './schema/dict.js'
8
8
  export * from './schema/enum.js'
9
9
  export * from './schema/integer.js'
10
+ export * from './schema/lex-map.js'
11
+ export * from './schema/lex-value.js'
10
12
  export * from './schema/literal.js'
11
13
  export * from './schema/never.js'
12
14
  export * from './schema/null.js'
13
15
  export * from './schema/object.js'
14
16
  export * from './schema/regexp.js'
15
17
  export * from './schema/string.js'
16
- export * from './schema/unknown-object.js'
17
18
  export * from './schema/unknown.js'
18
19
 
19
20
  // Composite Types
@@ -0,0 +1,3 @@
1
+ export type IfAny<T, TrueValue, FalseValue> = 0 extends 1 & T
2
+ ? TrueValue
3
+ : FalseValue
@@ -1,42 +0,0 @@
1
- import { LexMap } from '@atproto/lex-data';
2
- import { Schema, ValidationContext } from '../core.js';
3
- /**
4
- * Type alias for a plain object with unknown values.
5
- */
6
- export type UnknownObject = LexMap;
7
- /**
8
- * Schema that accepts any plain object without validating its properties.
9
- *
10
- * Validates that the input is a plain object (not an array, Date, or other
11
- * special object type), but does not validate the object's properties.
12
- *
13
- * @example
14
- * ```ts
15
- * const schema = new UnknownObjectSchema()
16
- * schema.validate({ any: 'props' }) // success
17
- * schema.validate([1, 2, 3]) // fails - arrays not accepted
18
- * ```
19
- */
20
- export declare class UnknownObjectSchema extends Schema<UnknownObject> {
21
- validateInContext(input: unknown, ctx: ValidationContext): import("../core.js").ValidationResult<LexMap>;
22
- }
23
- /**
24
- * Creates a schema that accepts any plain object.
25
- *
26
- * Unlike `l.unknown()` which accepts any value, this validates that the input
27
- * is specifically a plain object (not an array, null, or primitive).
28
- *
29
- * @returns A new {@link UnknownObjectSchema} instance
30
- *
31
- * @example
32
- * ```ts
33
- * // Accept any object shape
34
- * const metadataSchema = l.unknownObject()
35
- *
36
- * metadataSchema.parse({ foo: 1, bar: 'baz' }) // success
37
- * metadataSchema.parse([1, 2, 3]) // throws - not a plain object
38
- * metadataSchema.parse(null) // throws
39
- * ```
40
- */
41
- export declare const unknownObject: () => UnknownObjectSchema;
42
- //# sourceMappingURL=unknown-object.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unknown-object.d.ts","sourceRoot":"","sources":["../../src/schema/unknown-object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAY,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAGtD;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAA;AAElC;;;;;;;;;;;;GAYG;AACH,qBAAa,mBAAoB,SAAQ,MAAM,CAAC,aAAa,CAAC;IAC5D,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB;CAOzD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,aAAa,2BAExB,CAAA"}
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unknownObject = exports.UnknownObjectSchema = 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");
7
- /**
8
- * Schema that accepts any plain object without validating its properties.
9
- *
10
- * Validates that the input is a plain object (not an array, Date, or other
11
- * special object type), but does not validate the object's properties.
12
- *
13
- * @example
14
- * ```ts
15
- * const schema = new UnknownObjectSchema()
16
- * schema.validate({ any: 'props' }) // success
17
- * schema.validate([1, 2, 3]) // fails - arrays not accepted
18
- * ```
19
- */
20
- class UnknownObjectSchema extends core_js_1.Schema {
21
- validateInContext(input, ctx) {
22
- if ((0, lex_data_1.isLexMap)(input)) {
23
- return ctx.success(input);
24
- }
25
- return ctx.issueInvalidType(input, 'unknown');
26
- }
27
- }
28
- exports.UnknownObjectSchema = UnknownObjectSchema;
29
- /**
30
- * Creates a schema that accepts any plain object.
31
- *
32
- * Unlike `l.unknown()` which accepts any value, this validates that the input
33
- * is specifically a plain object (not an array, null, or primitive).
34
- *
35
- * @returns A new {@link UnknownObjectSchema} instance
36
- *
37
- * @example
38
- * ```ts
39
- * // Accept any object shape
40
- * const metadataSchema = l.unknownObject()
41
- *
42
- * metadataSchema.parse({ foo: 1, bar: 'baz' }) // success
43
- * metadataSchema.parse([1, 2, 3]) // throws - not a plain object
44
- * metadataSchema.parse(null) // throws
45
- * ```
46
- */
47
- exports.unknownObject = (0, memoize_js_1.memoizedOptions)(function () {
48
- return new UnknownObjectSchema();
49
- });
50
- //# sourceMappingURL=unknown-object.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unknown-object.js","sourceRoot":"","sources":["../../src/schema/unknown-object.ts"],"names":[],"mappings":";;;AAAA,gDAAoD;AACpD,wCAAsD;AACtD,mDAAoD;AAOpD;;;;;;;;;;;;GAYG;AACH,MAAa,mBAAoB,SAAQ,gBAAqB;IAC5D,iBAAiB,CAAC,KAAc,EAAE,GAAsB;QACtD,IAAI,IAAA,mBAAQ,EAAC,KAAK,CAAC,EAAE,CAAC;YACpB,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAC3B,CAAC;QAED,OAAO,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;IAC/C,CAAC;CACF;AARD,kDAQC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACU,QAAA,aAAa,GAAiB,IAAA,4BAAe,EAAC;IACzD,OAAO,IAAI,mBAAmB,EAAE,CAAA;AAClC,CAAC,CAAC,CAAA","sourcesContent":["import { LexMap, isLexMap } from '@atproto/lex-data'\nimport { Schema, ValidationContext } from '../core.js'\nimport { memoizedOptions } from '../util/memoize.js'\n\n/**\n * Type alias for a plain object with unknown values.\n */\nexport type UnknownObject = LexMap\n\n/**\n * Schema that accepts any plain object without validating its properties.\n *\n * Validates that the input is a plain object (not an array, Date, or other\n * special object type), but does not validate the object's properties.\n *\n * @example\n * ```ts\n * const schema = new UnknownObjectSchema()\n * schema.validate({ any: 'props' }) // success\n * schema.validate([1, 2, 3]) // fails - arrays not accepted\n * ```\n */\nexport class UnknownObjectSchema extends Schema<UnknownObject> {\n validateInContext(input: unknown, ctx: ValidationContext) {\n if (isLexMap(input)) {\n return ctx.success(input)\n }\n\n return ctx.issueInvalidType(input, 'unknown')\n }\n}\n\n/**\n * Creates a schema that accepts any plain object.\n *\n * Unlike `l.unknown()` which accepts any value, this validates that the input\n * is specifically a plain object (not an array, null, or primitive).\n *\n * @returns A new {@link UnknownObjectSchema} instance\n *\n * @example\n * ```ts\n * // Accept any object shape\n * const metadataSchema = l.unknownObject()\n *\n * metadataSchema.parse({ foo: 1, bar: 'baz' }) // success\n * metadataSchema.parse([1, 2, 3]) // throws - not a plain object\n * metadataSchema.parse(null) // throws\n * ```\n */\nexport const unknownObject = /*#__PURE__*/ memoizedOptions(function () {\n return new UnknownObjectSchema()\n})\n"]}
@@ -1,53 +0,0 @@
1
- import { LexMap, isLexMap } from '@atproto/lex-data'
2
- import { Schema, ValidationContext } from '../core.js'
3
- import { memoizedOptions } from '../util/memoize.js'
4
-
5
- /**
6
- * Type alias for a plain object with unknown values.
7
- */
8
- export type UnknownObject = LexMap
9
-
10
- /**
11
- * Schema that accepts any plain object without validating its properties.
12
- *
13
- * Validates that the input is a plain object (not an array, Date, or other
14
- * special object type), but does not validate the object's properties.
15
- *
16
- * @example
17
- * ```ts
18
- * const schema = new UnknownObjectSchema()
19
- * schema.validate({ any: 'props' }) // success
20
- * schema.validate([1, 2, 3]) // fails - arrays not accepted
21
- * ```
22
- */
23
- export class UnknownObjectSchema extends Schema<UnknownObject> {
24
- validateInContext(input: unknown, ctx: ValidationContext) {
25
- if (isLexMap(input)) {
26
- return ctx.success(input)
27
- }
28
-
29
- return ctx.issueInvalidType(input, 'unknown')
30
- }
31
- }
32
-
33
- /**
34
- * Creates a schema that accepts any plain object.
35
- *
36
- * Unlike `l.unknown()` which accepts any value, this validates that the input
37
- * is specifically a plain object (not an array, null, or primitive).
38
- *
39
- * @returns A new {@link UnknownObjectSchema} instance
40
- *
41
- * @example
42
- * ```ts
43
- * // Accept any object shape
44
- * const metadataSchema = l.unknownObject()
45
- *
46
- * metadataSchema.parse({ foo: 1, bar: 'baz' }) // success
47
- * metadataSchema.parse([1, 2, 3]) // throws - not a plain object
48
- * metadataSchema.parse(null) // throws
49
- * ```
50
- */
51
- export const unknownObject = /*#__PURE__*/ memoizedOptions(function () {
52
- return new UnknownObjectSchema()
53
- })