@atproto/lex-schema 0.0.9 → 0.0.10

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 (279) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/LICENSE.txt +1 -1
  3. package/dist/core/$type.d.ts +11 -0
  4. package/dist/core/$type.d.ts.map +1 -1
  5. package/dist/core/$type.js +4 -0
  6. package/dist/core/$type.js.map +1 -1
  7. package/dist/core/schema.d.ts +31 -24
  8. package/dist/core/schema.d.ts.map +1 -1
  9. package/dist/core/schema.js +38 -8
  10. package/dist/core/schema.js.map +1 -1
  11. package/dist/core/string-format.d.ts +35 -35
  12. package/dist/core/string-format.d.ts.map +1 -1
  13. package/dist/core/string-format.js +49 -91
  14. package/dist/core/string-format.js.map +1 -1
  15. package/dist/core/validation-issue.js +1 -1
  16. package/dist/core/validation-issue.js.map +1 -1
  17. package/dist/core/validator.d.ts +53 -32
  18. package/dist/core/validator.d.ts.map +1 -1
  19. package/dist/core/validator.js +18 -22
  20. package/dist/core/validator.js.map +1 -1
  21. package/dist/external.d.ts +0 -85
  22. package/dist/external.d.ts.map +1 -1
  23. package/dist/external.js +0 -164
  24. package/dist/external.js.map +1 -1
  25. package/dist/helpers.d.ts +10 -5
  26. package/dist/helpers.d.ts.map +1 -1
  27. package/dist/helpers.js +3 -3
  28. package/dist/helpers.js.map +1 -1
  29. package/dist/schema/array.d.ts +9 -5
  30. package/dist/schema/array.d.ts.map +1 -1
  31. package/dist/schema/array.js +14 -5
  32. package/dist/schema/array.js.map +1 -1
  33. package/dist/schema/blob.d.ts +9 -7
  34. package/dist/schema/blob.d.ts.map +1 -1
  35. package/dist/schema/blob.js +9 -5
  36. package/dist/schema/blob.js.map +1 -1
  37. package/dist/schema/boolean.d.ts +3 -7
  38. package/dist/schema/boolean.d.ts.map +1 -1
  39. package/dist/schema/boolean.js +6 -7
  40. package/dist/schema/boolean.js.map +1 -1
  41. package/dist/schema/bytes.d.ts +3 -2
  42. package/dist/schema/bytes.d.ts.map +1 -1
  43. package/dist/schema/bytes.js +7 -3
  44. package/dist/schema/bytes.js.map +1 -1
  45. package/dist/schema/cid.d.ts +7 -7
  46. package/dist/schema/cid.d.ts.map +1 -1
  47. package/dist/schema/cid.js +5 -1
  48. package/dist/schema/cid.js.map +1 -1
  49. package/dist/schema/custom.d.ts +6 -5
  50. package/dist/schema/custom.d.ts.map +1 -1
  51. package/dist/schema/custom.js +10 -4
  52. package/dist/schema/custom.js.map +1 -1
  53. package/dist/schema/dict.d.ts +8 -8
  54. package/dist/schema/dict.d.ts.map +1 -1
  55. package/dist/schema/dict.js +11 -2
  56. package/dist/schema/dict.js.map +1 -1
  57. package/dist/schema/discriminated-union.d.ts +21 -14
  58. package/dist/schema/discriminated-union.d.ts.map +1 -1
  59. package/dist/schema/discriminated-union.js +7 -0
  60. package/dist/schema/discriminated-union.js.map +1 -1
  61. package/dist/schema/enum.d.ts +7 -9
  62. package/dist/schema/enum.d.ts.map +1 -1
  63. package/dist/schema/enum.js +8 -4
  64. package/dist/schema/enum.js.map +1 -1
  65. package/dist/schema/integer.d.ts +5 -5
  66. package/dist/schema/integer.d.ts.map +1 -1
  67. package/dist/schema/integer.js +9 -5
  68. package/dist/schema/integer.js.map +1 -1
  69. package/dist/schema/intersection.d.ts +4 -4
  70. package/dist/schema/intersection.d.ts.map +1 -1
  71. package/dist/schema/intersection.js +5 -0
  72. package/dist/schema/intersection.js.map +1 -1
  73. package/dist/schema/literal.d.ts +6 -9
  74. package/dist/schema/literal.d.ts.map +1 -1
  75. package/dist/schema/literal.js +7 -4
  76. package/dist/schema/literal.js.map +1 -1
  77. package/dist/schema/never.d.ts +3 -2
  78. package/dist/schema/never.d.ts.map +1 -1
  79. package/dist/schema/never.js +5 -1
  80. package/dist/schema/never.js.map +1 -1
  81. package/dist/schema/null.d.ts +4 -3
  82. package/dist/schema/null.d.ts.map +1 -1
  83. package/dist/schema/null.js +6 -4
  84. package/dist/schema/null.js.map +1 -1
  85. package/dist/schema/nullable.d.ts +6 -5
  86. package/dist/schema/nullable.d.ts.map +1 -1
  87. package/dist/schema/nullable.js +9 -5
  88. package/dist/schema/nullable.js.map +1 -1
  89. package/dist/schema/object.d.ts +10 -8
  90. package/dist/schema/object.d.ts.map +1 -1
  91. package/dist/schema/object.js +11 -3
  92. package/dist/schema/object.js.map +1 -1
  93. package/dist/schema/optional.d.ts +7 -5
  94. package/dist/schema/optional.d.ts.map +1 -1
  95. package/dist/schema/optional.js +14 -6
  96. package/dist/schema/optional.js.map +1 -1
  97. package/dist/schema/params.d.ts +24 -13
  98. package/dist/schema/params.d.ts.map +1 -1
  99. package/dist/schema/params.js +47 -25
  100. package/dist/schema/params.js.map +1 -1
  101. package/dist/schema/payload.d.ts +12 -9
  102. package/dist/schema/payload.d.ts.map +1 -1
  103. package/dist/schema/payload.js +11 -0
  104. package/dist/schema/payload.js.map +1 -1
  105. package/dist/schema/permission-set.d.ts +1 -0
  106. package/dist/schema/permission-set.d.ts.map +1 -1
  107. package/dist/schema/permission-set.js +5 -0
  108. package/dist/schema/permission-set.js.map +1 -1
  109. package/dist/schema/permission.d.ts +6 -5
  110. package/dist/schema/permission.d.ts.map +1 -1
  111. package/dist/schema/permission.js +5 -0
  112. package/dist/schema/permission.js.map +1 -1
  113. package/dist/schema/procedure.d.ts +2 -1
  114. package/dist/schema/procedure.d.ts.map +1 -1
  115. package/dist/schema/procedure.js +5 -0
  116. package/dist/schema/procedure.js.map +1 -1
  117. package/dist/schema/query.d.ts +2 -1
  118. package/dist/schema/query.d.ts.map +1 -1
  119. package/dist/schema/query.js +5 -0
  120. package/dist/schema/query.js.map +1 -1
  121. package/dist/schema/record.d.ts +48 -30
  122. package/dist/schema/record.d.ts.map +1 -1
  123. package/dist/schema/record.js +12 -9
  124. package/dist/schema/record.js.map +1 -1
  125. package/dist/schema/ref.d.ts +9 -6
  126. package/dist/schema/ref.d.ts.map +1 -1
  127. package/dist/schema/ref.js +9 -16
  128. package/dist/schema/ref.js.map +1 -1
  129. package/dist/schema/refine.d.ts +4 -4
  130. package/dist/schema/refine.d.ts.map +1 -1
  131. package/dist/schema/refine.js.map +1 -1
  132. package/dist/schema/regexp.d.ts +4 -3
  133. package/dist/schema/regexp.d.ts.map +1 -1
  134. package/dist/schema/regexp.js +5 -0
  135. package/dist/schema/regexp.js.map +1 -1
  136. package/dist/schema/string.d.ts +7 -8
  137. package/dist/schema/string.d.ts.map +1 -1
  138. package/dist/schema/string.js +13 -19
  139. package/dist/schema/string.js.map +1 -1
  140. package/dist/schema/subscription.d.ts +2 -1
  141. package/dist/schema/subscription.d.ts.map +1 -1
  142. package/dist/schema/subscription.js +5 -0
  143. package/dist/schema/subscription.js.map +1 -1
  144. package/dist/schema/token.d.ts +6 -5
  145. package/dist/schema/token.d.ts.map +1 -1
  146. package/dist/schema/token.js +5 -0
  147. package/dist/schema/token.js.map +1 -1
  148. package/dist/schema/typed-object.d.ts +43 -26
  149. package/dist/schema/typed-object.d.ts.map +1 -1
  150. package/dist/schema/typed-object.js +6 -3
  151. package/dist/schema/typed-object.js.map +1 -1
  152. package/dist/schema/typed-ref.d.ts +16 -25
  153. package/dist/schema/typed-ref.d.ts.map +1 -1
  154. package/dist/schema/typed-ref.js +7 -17
  155. package/dist/schema/typed-ref.js.map +1 -1
  156. package/dist/schema/typed-union.d.ts +9 -21
  157. package/dist/schema/typed-union.d.ts.map +1 -1
  158. package/dist/schema/typed-union.js +15 -11
  159. package/dist/schema/typed-union.js.map +1 -1
  160. package/dist/schema/union.d.ts +6 -6
  161. package/dist/schema/union.d.ts.map +1 -1
  162. package/dist/schema/union.js +7 -5
  163. package/dist/schema/union.js.map +1 -1
  164. package/dist/schema/unknown-object.d.ts +5 -4
  165. package/dist/schema/unknown-object.d.ts.map +1 -1
  166. package/dist/schema/unknown-object.js +5 -1
  167. package/dist/schema/unknown-object.js.map +1 -1
  168. package/dist/schema/unknown.d.ts +3 -2
  169. package/dist/schema/unknown.d.ts.map +1 -1
  170. package/dist/schema/unknown.js +5 -1
  171. package/dist/schema/unknown.js.map +1 -1
  172. package/dist/schema/with-default.d.ts +9 -0
  173. package/dist/schema/with-default.d.ts.map +1 -0
  174. package/dist/schema/with-default.js +27 -0
  175. package/dist/schema/with-default.js.map +1 -0
  176. package/dist/schema.d.ts +2 -2
  177. package/dist/schema.d.ts.map +1 -1
  178. package/dist/schema.js +2 -4
  179. package/dist/schema.js.map +1 -1
  180. package/dist/util/assertion-util.d.ts +0 -6
  181. package/dist/util/assertion-util.d.ts.map +1 -1
  182. package/dist/util/assertion-util.js +0 -28
  183. package/dist/util/assertion-util.js.map +1 -1
  184. package/dist/util/memoize.d.ts +2 -2
  185. package/dist/util/memoize.d.ts.map +1 -1
  186. package/dist/util/memoize.js +23 -39
  187. package/dist/util/memoize.js.map +1 -1
  188. package/package.json +3 -3
  189. package/src/core/$type.test.ts +20 -0
  190. package/src/core/$type.ts +30 -0
  191. package/src/core/schema.ts +86 -38
  192. package/src/core/string-format.ts +119 -158
  193. package/src/core/validation-issue.ts +1 -1
  194. package/src/core/validator.ts +93 -53
  195. package/src/external.ts +0 -404
  196. package/src/helpers.test.ts +22 -21
  197. package/src/helpers.ts +14 -14
  198. package/src/schema/array.test.ts +38 -40
  199. package/src/schema/array.ts +35 -13
  200. package/src/schema/blob.test.ts +21 -21
  201. package/src/schema/blob.ts +19 -17
  202. package/src/schema/boolean.test.ts +9 -8
  203. package/src/schema/boolean.ts +7 -13
  204. package/src/schema/bytes.test.ts +13 -13
  205. package/src/schema/bytes.ts +13 -8
  206. package/src/schema/cid.test.ts +3 -3
  207. package/src/schema/cid.ts +13 -12
  208. package/src/schema/custom.test.ts +26 -26
  209. package/src/schema/custom.ts +20 -13
  210. package/src/schema/dict.test.ts +21 -39
  211. package/src/schema/dict.ts +28 -19
  212. package/src/schema/discriminated-union.test.ts +128 -128
  213. package/src/schema/discriminated-union.ts +45 -26
  214. package/src/schema/enum.test.ts +17 -16
  215. package/src/schema/enum.ts +16 -16
  216. package/src/schema/integer.test.ts +22 -21
  217. package/src/schema/integer.ts +12 -9
  218. package/src/schema/intersection.test.ts +10 -10
  219. package/src/schema/intersection.ts +17 -14
  220. package/src/schema/literal.test.ts +35 -34
  221. package/src/schema/literal.ts +12 -15
  222. package/src/schema/never.test.ts +5 -5
  223. package/src/schema/never.ts +7 -2
  224. package/src/schema/null.test.ts +3 -3
  225. package/src/schema/null.ts +9 -9
  226. package/src/schema/nullable.test.ts +31 -42
  227. package/src/schema/nullable.ts +17 -9
  228. package/src/schema/object.test.ts +10 -12
  229. package/src/schema/object.ts +27 -18
  230. package/src/schema/optional.test.ts +21 -28
  231. package/src/schema/optional.ts +27 -10
  232. package/src/schema/params.test.ts +471 -47
  233. package/src/schema/params.ts +72 -38
  234. package/src/schema/payload.test.ts +150 -156
  235. package/src/schema/payload.ts +35 -19
  236. package/src/schema/permission-set.test.ts +206 -273
  237. package/src/schema/permission-set.ts +8 -0
  238. package/src/schema/permission.test.ts +177 -177
  239. package/src/schema/permission.ts +13 -5
  240. package/src/schema/procedure.test.ts +183 -242
  241. package/src/schema/procedure.ts +18 -5
  242. package/src/schema/query.test.ts +186 -200
  243. package/src/schema/query.ts +16 -4
  244. package/src/schema/record.test.ts +121 -101
  245. package/src/schema/record.ts +74 -40
  246. package/src/schema/ref.test.ts +101 -118
  247. package/src/schema/ref.ts +33 -28
  248. package/src/schema/refine.test.ts +28 -28
  249. package/src/schema/refine.ts +23 -20
  250. package/src/schema/regexp.test.ts +29 -33
  251. package/src/schema/regexp.ts +11 -7
  252. package/src/schema/string.test.ts +35 -35
  253. package/src/schema/string.ts +24 -33
  254. package/src/schema/subscription.test.ts +259 -387
  255. package/src/schema/subscription.ts +16 -4
  256. package/src/schema/token.test.ts +47 -324
  257. package/src/schema/token.ts +14 -7
  258. package/src/schema/typed-object.test.ts +98 -81
  259. package/src/schema/typed-object.ts +68 -33
  260. package/src/schema/typed-ref.test.ts +206 -234
  261. package/src/schema/typed-ref.ts +40 -42
  262. package/src/schema/typed-union.test.ts +40 -64
  263. package/src/schema/typed-union.ts +36 -58
  264. package/src/schema/union.test.ts +17 -27
  265. package/src/schema/union.ts +20 -16
  266. package/src/schema/unknown-object.test.ts +8 -8
  267. package/src/schema/unknown-object.ts +9 -7
  268. package/src/schema/unknown.test.ts +4 -4
  269. package/src/schema/unknown.ts +7 -5
  270. package/src/schema/with-default.ts +35 -0
  271. package/src/schema.ts +2 -6
  272. package/src/util/assertion-util.ts +0 -39
  273. package/src/util/memoize.ts +26 -46
  274. package/dist/schema/_parameters.d.ts +0 -17
  275. package/dist/schema/_parameters.d.ts.map +0 -1
  276. package/dist/schema/_parameters.js +0 -20
  277. package/dist/schema/_parameters.js.map +0 -1
  278. package/src/schema/_parameters.test.ts +0 -417
  279. package/src/schema/_parameters.ts +0 -26
@@ -1,16 +1,16 @@
1
1
  import { describe, expect, it } from 'vitest'
2
- import { ArraySchema } from './array.js'
3
- import { BooleanSchema } from './boolean.js'
4
- import { IntegerSchema } from './integer.js'
5
- import { OptionalSchema } from './optional.js'
6
- import { ParamsSchema } from './params.js'
7
- import { StringSchema } from './string.js'
2
+ import { array } from './array.js'
3
+ import { boolean } from './boolean.js'
4
+ import { integer } from './integer.js'
5
+ import { optional } from './optional.js'
6
+ import { paramSchema, params, paramsSchema } from './params.js'
7
+ import { string } from './string.js'
8
8
 
9
9
  describe('ParamsSchema', () => {
10
10
  describe('basic validation', () => {
11
- const schema = new ParamsSchema({
12
- name: new StringSchema({}),
13
- age: new IntegerSchema({}),
11
+ const schema = params({
12
+ name: string(),
13
+ age: integer(),
14
14
  })
15
15
 
16
16
  it('validates plain objects with required params', () => {
@@ -58,10 +58,10 @@ describe('ParamsSchema', () => {
58
58
  })
59
59
 
60
60
  describe('optional parameters', () => {
61
- const schema = new ParamsSchema({
62
- name: new StringSchema({}),
63
- age: new OptionalSchema(new IntegerSchema({})),
64
- active: new OptionalSchema(new BooleanSchema({})),
61
+ const schema = params({
62
+ name: string(),
63
+ age: optional(integer()),
64
+ active: optional(boolean()),
65
65
  })
66
66
 
67
67
  it('validates with all parameters present', () => {
@@ -98,8 +98,8 @@ describe('ParamsSchema', () => {
98
98
  })
99
99
 
100
100
  describe('additional unspecified parameters', () => {
101
- const schema = new ParamsSchema({
102
- name: new StringSchema({}),
101
+ const schema = params({
102
+ name: string(),
103
103
  })
104
104
 
105
105
  it('accepts string values in additional params', () => {
@@ -171,8 +171,8 @@ describe('ParamsSchema', () => {
171
171
 
172
172
  describe('parameter types', () => {
173
173
  describe('string parameters', () => {
174
- const schema = new ParamsSchema({
175
- text: new StringSchema({}),
174
+ const schema = params({
175
+ text: string(),
176
176
  })
177
177
 
178
178
  it('validates string values', () => {
@@ -192,8 +192,8 @@ describe('ParamsSchema', () => {
192
192
  })
193
193
 
194
194
  describe('integer parameters', () => {
195
- const schema = new ParamsSchema({
196
- count: new IntegerSchema({}),
195
+ const schema = params({
196
+ count: integer(),
197
197
  })
198
198
 
199
199
  it('validates integer values', () => {
@@ -218,8 +218,8 @@ describe('ParamsSchema', () => {
218
218
  })
219
219
 
220
220
  describe('boolean parameters', () => {
221
- const schema = new ParamsSchema({
222
- flag: new BooleanSchema({}),
221
+ const schema = params({
222
+ flag: boolean(),
223
223
  })
224
224
 
225
225
  it('validates true', () => {
@@ -239,8 +239,8 @@ describe('ParamsSchema', () => {
239
239
  })
240
240
 
241
241
  describe('array parameters', () => {
242
- const schema = new ParamsSchema({
243
- tags: new ArraySchema(new StringSchema({})),
242
+ const schema = params({
243
+ tags: array(string()),
244
244
  })
245
245
 
246
246
  it('validates string arrays', () => {
@@ -261,10 +261,10 @@ describe('ParamsSchema', () => {
261
261
  })
262
262
 
263
263
  describe('fromURLSearchParams', () => {
264
- const schema = new ParamsSchema({
265
- name: new StringSchema({}),
266
- age: new OptionalSchema(new IntegerSchema({})),
267
- active: new OptionalSchema(new BooleanSchema({})),
264
+ const schema = params({
265
+ name: string(),
266
+ age: optional(integer()),
267
+ active: optional(boolean()),
268
268
  })
269
269
 
270
270
  it('parses string parameters', () => {
@@ -349,10 +349,10 @@ describe('ParamsSchema', () => {
349
349
  })
350
350
 
351
351
  describe('toURLSearchParams', () => {
352
- const schema = new ParamsSchema({
353
- name: new StringSchema({}),
354
- age: new OptionalSchema(new IntegerSchema({})),
355
- active: new OptionalSchema(new BooleanSchema({})),
352
+ const schema = params({
353
+ name: string(),
354
+ age: optional(integer()),
355
+ active: optional(boolean()),
356
356
  })
357
357
 
358
358
  it('converts string parameters', () => {
@@ -418,8 +418,7 @@ describe('ParamsSchema', () => {
418
418
 
419
419
  it('handles undefined input', () => {
420
420
  // @ts-expect-error
421
- const result = schema.toURLSearchParams(undefined)
422
- expect(result.toString()).toBe('')
421
+ expect(() => schema.toURLSearchParams(undefined)).toThrow()
423
422
  })
424
423
 
425
424
  it('converts negative integers', () => {
@@ -439,10 +438,10 @@ describe('ParamsSchema', () => {
439
438
  })
440
439
 
441
440
  describe('roundtrip conversion', () => {
442
- const schema = new ParamsSchema({
443
- name: new StringSchema({}),
444
- age: new OptionalSchema(new IntegerSchema({})),
445
- active: new OptionalSchema(new BooleanSchema({})),
441
+ const schema = params({
442
+ name: string(),
443
+ age: optional(integer()),
444
+ active: optional(boolean()),
446
445
  })
447
446
 
448
447
  it('roundtrips simple params correctly', () => {
@@ -475,7 +474,7 @@ describe('ParamsSchema', () => {
475
474
  })
476
475
 
477
476
  describe('empty schema', () => {
478
- const schema = new ParamsSchema({})
477
+ const schema = params()
479
478
 
480
479
  it('validates empty object', () => {
481
480
  const result = schema.safeParse({})
@@ -494,13 +493,11 @@ describe('ParamsSchema', () => {
494
493
  })
495
494
 
496
495
  describe('complex scenarios', () => {
497
- const schema = new ParamsSchema({
498
- query: new StringSchema({ minLength: 1 }),
499
- limit: new OptionalSchema(
500
- new IntegerSchema({ minimum: 1, maximum: 100 }),
501
- ),
502
- offset: new OptionalSchema(new IntegerSchema({ minimum: 0 })),
503
- filters: new OptionalSchema(new ArraySchema(new StringSchema({}))),
496
+ const schema = params({
497
+ query: string({ minLength: 1 }),
498
+ limit: optional(integer({ minimum: 1, maximum: 100 })),
499
+ offset: optional(integer({ minimum: 0 })),
500
+ filters: optional(array(string())),
504
501
  })
505
502
 
506
503
  it('validates typical query parameters', () => {
@@ -553,8 +550,8 @@ describe('ParamsSchema', () => {
553
550
  })
554
551
 
555
552
  describe('edge cases', () => {
556
- const schema = new ParamsSchema({
557
- name: new StringSchema({}),
553
+ const schema = params({
554
+ name: string(),
558
555
  })
559
556
 
560
557
  it('rejects objects with custom prototypes', () => {
@@ -580,4 +577,431 @@ describe('ParamsSchema', () => {
580
577
  expect(result.success).toBe(true)
581
578
  })
582
579
  })
580
+
581
+ describe('memoized params schema', () => {
582
+ it('returns the same instance when no shape is provided', () => {
583
+ expect(params()).toBe(params())
584
+ })
585
+
586
+ it('returns different instances when (identical) shapes are provided', () => {
587
+ const schemaA = params({ a: string() })
588
+ const schemaB = params({ a: string() })
589
+ expect(schemaA).not.toBe(schemaB)
590
+ })
591
+ })
592
+ })
593
+
594
+ describe('paramSchema', () => {
595
+ describe('scalar values', () => {
596
+ it('validates boolean values', () => {
597
+ const result = paramSchema.safeParse(true)
598
+ expect(result.success).toBe(true)
599
+ })
600
+
601
+ it('validates integer values', () => {
602
+ const result = paramSchema.safeParse(42)
603
+ expect(result.success).toBe(true)
604
+ })
605
+
606
+ it('validates string values', () => {
607
+ const result = paramSchema.safeParse('hello')
608
+ expect(result.success).toBe(true)
609
+ })
610
+
611
+ it('validates empty strings', () => {
612
+ const result = paramSchema.safeParse('')
613
+ expect(result.success).toBe(true)
614
+ })
615
+
616
+ it('validates zero', () => {
617
+ const result = paramSchema.safeParse(0)
618
+ expect(result.success).toBe(true)
619
+ })
620
+
621
+ it('validates negative integers', () => {
622
+ const result = paramSchema.safeParse(-50)
623
+ expect(result.success).toBe(true)
624
+ })
625
+
626
+ it('validates false boolean', () => {
627
+ const result = paramSchema.safeParse(false)
628
+ expect(result.success).toBe(true)
629
+ })
630
+ })
631
+
632
+ describe('array values', () => {
633
+ it('validates arrays of booleans', () => {
634
+ const result = paramSchema.safeParse([true, false, true])
635
+ expect(result.success).toBe(true)
636
+ })
637
+
638
+ it('validates arrays of integers', () => {
639
+ const result = paramSchema.safeParse([1, 2, 3, 4])
640
+ expect(result.success).toBe(true)
641
+ })
642
+
643
+ it('validates arrays of strings', () => {
644
+ const result = paramSchema.safeParse(['foo', 'bar', 'baz'])
645
+ expect(result.success).toBe(true)
646
+ })
647
+
648
+ it('validates empty arrays', () => {
649
+ const result = paramSchema.safeParse([])
650
+ expect(result.success).toBe(true)
651
+ })
652
+
653
+ it('validates arrays with single element', () => {
654
+ const result = paramSchema.safeParse(['single'])
655
+ expect(result.success).toBe(true)
656
+ })
657
+
658
+ it('validates arrays with mixed scalar types', () => {
659
+ const result = paramSchema.safeParse([true, 42, 'text'])
660
+ expect(result.success).toBe(true)
661
+ })
662
+
663
+ it('validates arrays with negative integers', () => {
664
+ const result = paramSchema.safeParse([-1, -2, -3])
665
+ expect(result.success).toBe(true)
666
+ })
667
+
668
+ it('validates arrays with empty strings', () => {
669
+ const result = paramSchema.safeParse(['', 'non-empty', ''])
670
+ expect(result.success).toBe(true)
671
+ })
672
+
673
+ it('validates arrays with zero', () => {
674
+ const result = paramSchema.safeParse([0, 1, 2])
675
+ expect(result.success).toBe(true)
676
+ })
677
+
678
+ it('rejects nested arrays', () => {
679
+ const result = paramSchema.safeParse([
680
+ [1, 2],
681
+ [3, 4],
682
+ ])
683
+ expect(result.success).toBe(false)
684
+ })
685
+
686
+ it('rejects arrays with null values', () => {
687
+ const result = paramSchema.safeParse([1, null, 3])
688
+ expect(result.success).toBe(false)
689
+ })
690
+
691
+ it('rejects arrays with undefined values', () => {
692
+ const result = paramSchema.safeParse([1, undefined, 3])
693
+ expect(result.success).toBe(false)
694
+ })
695
+
696
+ it('rejects arrays with object values', () => {
697
+ const result = paramSchema.safeParse([1, { key: 'value' }, 3])
698
+ expect(result.success).toBe(false)
699
+ })
700
+
701
+ it('rejects arrays with floating point numbers', () => {
702
+ const result = paramSchema.safeParse([1, 2.5, 3])
703
+ expect(result.success).toBe(false)
704
+ })
705
+
706
+ it('rejects arrays with NaN', () => {
707
+ const result = paramSchema.safeParse([1, NaN, 3])
708
+ expect(result.success).toBe(false)
709
+ })
710
+
711
+ it('rejects arrays with Infinity', () => {
712
+ const result = paramSchema.safeParse([1, Infinity, 3])
713
+ expect(result.success).toBe(false)
714
+ })
715
+ })
716
+
717
+ describe('invalid values', () => {
718
+ it('rejects null values', () => {
719
+ const result = paramSchema.safeParse(null)
720
+ expect(result.success).toBe(false)
721
+ })
722
+
723
+ it('rejects undefined values', () => {
724
+ const result = paramSchema.safeParse(undefined)
725
+ expect(result.success).toBe(false)
726
+ })
727
+
728
+ it('rejects object values', () => {
729
+ const result = paramSchema.safeParse({ key: 'value' })
730
+ expect(result.success).toBe(false)
731
+ })
732
+
733
+ it('rejects floating point numbers', () => {
734
+ const result = paramSchema.safeParse(3.14)
735
+ expect(result.success).toBe(false)
736
+ })
737
+
738
+ it('rejects NaN', () => {
739
+ const result = paramSchema.safeParse(NaN)
740
+ expect(result.success).toBe(false)
741
+ })
742
+
743
+ it('rejects Infinity', () => {
744
+ const result = paramSchema.safeParse(Infinity)
745
+ expect(result.success).toBe(false)
746
+ })
747
+
748
+ it('rejects -Infinity', () => {
749
+ const result = paramSchema.safeParse(-Infinity)
750
+ expect(result.success).toBe(false)
751
+ })
752
+ })
753
+ })
754
+
755
+ describe('paramsSchema', () => {
756
+ it('validates empty object', () => {
757
+ const result = paramsSchema.safeParse({})
758
+ expect(result.success).toBe(true)
759
+ })
760
+
761
+ it('validates object with boolean parameters', () => {
762
+ const result = paramsSchema.safeParse({
763
+ enabled: true,
764
+ disabled: false,
765
+ })
766
+ expect(result.success).toBe(true)
767
+ })
768
+
769
+ it('validates object with integer parameters', () => {
770
+ const result = paramsSchema.safeParse({
771
+ limit: 10,
772
+ offset: 0,
773
+ count: 100,
774
+ })
775
+ expect(result.success).toBe(true)
776
+ })
777
+
778
+ it('validates object with string parameters', () => {
779
+ const result = paramsSchema.safeParse({
780
+ name: 'Alice',
781
+ query: 'search term',
782
+ cursor: 'abc123',
783
+ })
784
+ expect(result.success).toBe(true)
785
+ })
786
+
787
+ it('validates object with array parameters', () => {
788
+ const result = paramsSchema.safeParse({
789
+ tags: ['tag1', 'tag2', 'tag3'],
790
+ ids: [1, 2, 3, 4],
791
+ flags: [true, false, true],
792
+ })
793
+ expect(result.success).toBe(true)
794
+ })
795
+
796
+ it('validates object with mixed parameter types', () => {
797
+ const result = paramsSchema.safeParse({
798
+ name: 'Alice',
799
+ age: 30,
800
+ active: true,
801
+ tags: ['user', 'admin'],
802
+ limit: 50,
803
+ })
804
+ expect(result.success).toBe(true)
805
+ })
806
+
807
+ it('validates object with empty string parameters', () => {
808
+ const result = paramsSchema.safeParse({
809
+ query: '',
810
+ cursor: '',
811
+ })
812
+ expect(result.success).toBe(true)
813
+ })
814
+
815
+ it('validates object with negative integer parameters', () => {
816
+ const result = paramsSchema.safeParse({
817
+ offset: -10,
818
+ delta: -5,
819
+ })
820
+ expect(result.success).toBe(true)
821
+ })
822
+
823
+ it('validates object with empty array parameters', () => {
824
+ const result = paramsSchema.safeParse({
825
+ tags: [],
826
+ ids: [],
827
+ })
828
+ expect(result.success).toBe(true)
829
+ })
830
+
831
+ it('validates object with arrays of mixed scalar types', () => {
832
+ const result = paramsSchema.safeParse({
833
+ values: [true, 42, 'text'],
834
+ })
835
+ expect(result.success).toBe(true)
836
+ })
837
+
838
+ it('validates object with numeric string keys', () => {
839
+ const result = paramsSchema.safeParse({
840
+ '0': 'value0',
841
+ '1': 'value1',
842
+ '2': 'value2',
843
+ })
844
+ expect(result.success).toBe(true)
845
+ })
846
+
847
+ it('rejects non-object values', () => {
848
+ const result = paramsSchema.safeParse('not an object')
849
+ expect(result.success).toBe(false)
850
+ })
851
+
852
+ it('rejects null values', () => {
853
+ const result = paramsSchema.safeParse(null)
854
+ expect(result.success).toBe(false)
855
+ })
856
+
857
+ it('rejects undefined values', () => {
858
+ const result = paramsSchema.safeParse(undefined)
859
+ expect(result.success).toBe(false)
860
+ })
861
+
862
+ it('rejects arrays', () => {
863
+ const result = paramsSchema.safeParse([1, 2, 3])
864
+ expect(result.success).toBe(false)
865
+ })
866
+
867
+ it('rejects object with null parameter values', () => {
868
+ const result = paramsSchema.safeParse({
869
+ name: 'Alice',
870
+ invalid: null,
871
+ })
872
+ expect(result.success).toBe(false)
873
+ })
874
+
875
+ it('rejects object with floating point parameter values', () => {
876
+ const result = paramsSchema.safeParse({
877
+ value: 3.14,
878
+ })
879
+ expect(result.success).toBe(false)
880
+ })
881
+
882
+ it('rejects object with NaN parameter values', () => {
883
+ const result = paramsSchema.safeParse({
884
+ value: NaN,
885
+ })
886
+ expect(result.success).toBe(false)
887
+ })
888
+
889
+ it('rejects object with Infinity parameter values', () => {
890
+ const result = paramsSchema.safeParse({
891
+ value: Infinity,
892
+ })
893
+ expect(result.success).toBe(false)
894
+ })
895
+
896
+ it('rejects object with object parameter values', () => {
897
+ const result = paramsSchema.safeParse({
898
+ nested: { key: 'value' },
899
+ })
900
+ expect(result.success).toBe(false)
901
+ })
902
+
903
+ it('rejects object with nested array parameter values', () => {
904
+ const result = paramsSchema.safeParse({
905
+ nested: [
906
+ [1, 2],
907
+ [3, 4],
908
+ ],
909
+ })
910
+ expect(result.success).toBe(false)
911
+ })
912
+
913
+ it('rejects object with arrays containing invalid values', () => {
914
+ const result = paramsSchema.safeParse({
915
+ tags: ['valid', null, 'also valid'],
916
+ })
917
+ expect(result.success).toBe(false)
918
+ })
919
+
920
+ it('rejects object with arrays containing objects', () => {
921
+ const result = paramsSchema.safeParse({
922
+ items: [1, { key: 'value' }, 3],
923
+ })
924
+ expect(result.success).toBe(false)
925
+ })
926
+
927
+ it('rejects object with arrays containing floating point numbers', () => {
928
+ const result = paramsSchema.safeParse({
929
+ values: [1, 2.5, 3],
930
+ })
931
+ expect(result.success).toBe(false)
932
+ })
933
+
934
+ it('rejects when one parameter is invalid', () => {
935
+ const result = paramsSchema.safeParse({
936
+ valid1: 'string',
937
+ valid2: 42,
938
+ invalid: null,
939
+ valid3: true,
940
+ })
941
+ expect(result.success).toBe(false)
942
+ })
943
+
944
+ describe('edge cases', () => {
945
+ it('validates single parameter', () => {
946
+ const result = paramsSchema.safeParse({
947
+ single: 'value',
948
+ })
949
+ expect(result.success).toBe(true)
950
+ })
951
+
952
+ it('validates many parameters', () => {
953
+ const manyParams: Record<string, string> = {}
954
+ for (let i = 0; i < 100; i++) {
955
+ manyParams[`param${i}`] = `value${i}`
956
+ }
957
+ const result = paramsSchema.safeParse(manyParams)
958
+ expect(result.success).toBe(true)
959
+ })
960
+
961
+ it('validates parameters with long string values', () => {
962
+ const result = paramsSchema.safeParse({
963
+ longString: 'a'.repeat(1000),
964
+ })
965
+ expect(result.success).toBe(true)
966
+ })
967
+
968
+ it('validates parameters with large integer values', () => {
969
+ const result = paramsSchema.safeParse({
970
+ largeInt: 2147483647,
971
+ negativeInt: -2147483648,
972
+ })
973
+ expect(result.success).toBe(true)
974
+ })
975
+
976
+ it('validates parameters with long arrays', () => {
977
+ const result = paramsSchema.safeParse({
978
+ longArray: Array.from({ length: 100 }, (_, i) => i),
979
+ })
980
+ expect(result.success).toBe(true)
981
+ })
982
+
983
+ it('validates parameters with special characters in keys', () => {
984
+ const result = paramsSchema.safeParse({
985
+ 'key-with-dashes': 'value',
986
+ key_with_underscores: 'value',
987
+ 'key.with.dots': 'value',
988
+ })
989
+ expect(result.success).toBe(true)
990
+ })
991
+
992
+ it('preserves original object when no transformations occur', () => {
993
+ const input = {
994
+ name: 'Alice',
995
+ age: 30,
996
+ tags: ['user'],
997
+ }
998
+ const result = paramsSchema.safeParse(input)
999
+
1000
+ if (result.success) {
1001
+ expect(result.value).toBe(input)
1002
+ } else {
1003
+ throw new Error('Expected validation to succeed')
1004
+ }
1005
+ })
1006
+ })
583
1007
  })