@atproto/lex-schema 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/core/$type.d.ts +2 -2
- package/dist/core/$type.d.ts.map +1 -1
- package/dist/core/$type.js.map +1 -1
- package/dist/core/record-key.d.ts +1 -1
- package/dist/core/record-key.d.ts.map +1 -1
- package/dist/core/record-key.js.map +1 -1
- package/dist/core/schema.d.ts +3 -2
- package/dist/core/schema.d.ts.map +1 -1
- package/dist/core/schema.js +1 -1
- package/dist/core/schema.js.map +1 -1
- package/dist/core/standard-schema.d.ts +2 -2
- package/dist/core/standard-schema.d.ts.map +1 -1
- package/dist/core/standard-schema.js.map +1 -1
- package/dist/core/string-format.d.ts +2 -2
- package/dist/core/string-format.d.ts.map +1 -1
- package/dist/core/string-format.js.map +1 -1
- package/dist/core/validation-error.d.ts +1 -1
- package/dist/core/validation-error.d.ts.map +1 -1
- package/dist/core/validation-error.js +1 -1
- package/dist/core/validation-error.js.map +1 -1
- package/dist/core/validator.d.ts +1 -1
- package/dist/core/validator.d.ts.map +1 -1
- package/dist/core/validator.js +1 -1
- package/dist/core/validator.js.map +1 -1
- package/dist/helpers.d.ts +2 -2
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +2 -2
- package/dist/helpers.js.map +1 -1
- package/dist/schema/array.d.ts +1 -1
- package/dist/schema/array.d.ts.map +1 -1
- package/dist/schema/array.js +1 -1
- package/dist/schema/array.js.map +1 -1
- package/dist/schema/blob.d.ts +1 -1
- package/dist/schema/blob.d.ts.map +1 -1
- package/dist/schema/blob.js +2 -2
- package/dist/schema/blob.js.map +1 -1
- package/dist/schema/boolean.js +1 -1
- package/dist/schema/boolean.js.map +1 -1
- package/dist/schema/bytes.js +1 -1
- package/dist/schema/bytes.js.map +1 -1
- package/dist/schema/cid.d.ts +1 -1
- package/dist/schema/cid.d.ts.map +1 -1
- package/dist/schema/cid.js +3 -3
- package/dist/schema/cid.js.map +1 -1
- package/dist/schema/custom.js +1 -1
- package/dist/schema/custom.js.map +1 -1
- package/dist/schema/dict.d.ts +1 -1
- package/dist/schema/dict.d.ts.map +1 -1
- package/dist/schema/dict.js +1 -1
- package/dist/schema/dict.js.map +1 -1
- package/dist/schema/discriminated-union.d.ts +1 -1
- package/dist/schema/discriminated-union.d.ts.map +1 -1
- package/dist/schema/discriminated-union.js +2 -1
- package/dist/schema/discriminated-union.js.map +1 -1
- package/dist/schema/enum.js +1 -1
- package/dist/schema/enum.js.map +1 -1
- package/dist/schema/integer.js +1 -1
- package/dist/schema/integer.js.map +1 -1
- package/dist/schema/intersection.d.ts +1 -1
- package/dist/schema/intersection.d.ts.map +1 -1
- package/dist/schema/intersection.js +3 -1
- package/dist/schema/intersection.js.map +1 -1
- package/dist/schema/lex-map.d.ts +1 -1
- package/dist/schema/lex-map.d.ts.map +1 -1
- package/dist/schema/lex-map.js +1 -1
- package/dist/schema/lex-map.js.map +1 -1
- package/dist/schema/lex-value.d.ts +1 -1
- package/dist/schema/lex-value.d.ts.map +1 -1
- package/dist/schema/lex-value.js +1 -1
- package/dist/schema/lex-value.js.map +1 -1
- package/dist/schema/literal.js +1 -1
- package/dist/schema/literal.js.map +1 -1
- package/dist/schema/never.js +1 -1
- package/dist/schema/never.js.map +1 -1
- package/dist/schema/null.js +1 -1
- package/dist/schema/null.js.map +1 -1
- package/dist/schema/nullable.d.ts +1 -1
- package/dist/schema/nullable.d.ts.map +1 -1
- package/dist/schema/nullable.js +1 -1
- package/dist/schema/nullable.js.map +1 -1
- package/dist/schema/object.d.ts +2 -1
- package/dist/schema/object.d.ts.map +1 -1
- package/dist/schema/object.js +1 -1
- package/dist/schema/object.js.map +1 -1
- package/dist/schema/optional.d.ts +2 -1
- package/dist/schema/optional.d.ts.map +1 -1
- package/dist/schema/optional.js +2 -1
- package/dist/schema/optional.js.map +1 -1
- package/dist/schema/params.d.ts +1 -1
- package/dist/schema/params.d.ts.map +1 -1
- package/dist/schema/params.js +1 -1
- package/dist/schema/params.js.map +1 -1
- package/dist/schema/payload.d.ts +3 -2
- package/dist/schema/payload.d.ts.map +1 -1
- package/dist/schema/payload.js +2 -1
- package/dist/schema/payload.js.map +1 -1
- package/dist/schema/permission-set.d.ts +1 -1
- package/dist/schema/permission-set.d.ts.map +1 -1
- package/dist/schema/permission-set.js +1 -0
- package/dist/schema/permission-set.js.map +1 -1
- package/dist/schema/permission.d.ts +1 -1
- package/dist/schema/permission.d.ts.map +1 -1
- package/dist/schema/permission.js.map +1 -1
- package/dist/schema/procedure.d.ts +1 -1
- package/dist/schema/procedure.d.ts.map +1 -1
- package/dist/schema/procedure.js +2 -0
- package/dist/schema/procedure.js.map +1 -1
- package/dist/schema/query.d.ts +1 -1
- package/dist/schema/query.d.ts.map +1 -1
- package/dist/schema/query.js +2 -0
- package/dist/schema/query.js.map +1 -1
- package/dist/schema/record.d.ts +2 -2
- package/dist/schema/record.d.ts.map +1 -1
- package/dist/schema/record.js +1 -1
- package/dist/schema/record.js.map +1 -1
- package/dist/schema/ref.d.ts +1 -1
- package/dist/schema/ref.d.ts.map +1 -1
- package/dist/schema/ref.js +1 -1
- package/dist/schema/ref.js.map +1 -1
- package/dist/schema/refine.d.ts +2 -2
- package/dist/schema/refine.d.ts.map +1 -1
- package/dist/schema/refine.js +1 -1
- package/dist/schema/refine.js.map +1 -1
- package/dist/schema/regexp.js +1 -1
- package/dist/schema/regexp.js.map +1 -1
- package/dist/schema/string.d.ts +2 -2
- package/dist/schema/string.d.ts.map +1 -1
- package/dist/schema/string.js +1 -1
- package/dist/schema/string.js.map +1 -1
- package/dist/schema/subscription.d.ts +3 -2
- package/dist/schema/subscription.d.ts.map +1 -1
- package/dist/schema/subscription.js +2 -0
- package/dist/schema/subscription.js.map +1 -1
- package/dist/schema/token.d.ts +1 -1
- package/dist/schema/token.d.ts.map +1 -1
- package/dist/schema/token.js +1 -1
- package/dist/schema/token.js.map +1 -1
- package/dist/schema/typed-object.d.ts +2 -2
- package/dist/schema/typed-object.d.ts.map +1 -1
- package/dist/schema/typed-object.js +1 -1
- package/dist/schema/typed-object.js.map +1 -1
- package/dist/schema/typed-ref.d.ts +1 -1
- package/dist/schema/typed-ref.d.ts.map +1 -1
- package/dist/schema/typed-ref.js +1 -1
- package/dist/schema/typed-ref.js.map +1 -1
- package/dist/schema/typed-union.d.ts +1 -1
- package/dist/schema/typed-union.d.ts.map +1 -1
- package/dist/schema/typed-union.js +3 -1
- package/dist/schema/typed-union.js.map +1 -1
- package/dist/schema/union.d.ts +1 -1
- package/dist/schema/union.d.ts.map +1 -1
- package/dist/schema/union.js +1 -1
- package/dist/schema/union.js.map +1 -1
- package/dist/schema/unknown.js +1 -1
- package/dist/schema/unknown.js.map +1 -1
- package/dist/schema/with-default.d.ts +1 -1
- package/dist/schema/with-default.d.ts.map +1 -1
- package/dist/schema/with-default.js +1 -1
- package/dist/schema/with-default.js.map +1 -1
- package/package.json +6 -10
- package/src/core/$type.test.ts +0 -24
- package/src/core/$type.ts +0 -199
- package/src/core/record-key.ts +0 -85
- package/src/core/result.ts +0 -15
- package/src/core/schema.ts +0 -412
- package/src/core/standard-schema.test.ts +0 -124
- package/src/core/standard-schema.ts +0 -31
- package/src/core/string-format.ts +0 -411
- package/src/core/types.ts +0 -120
- package/src/core/validation-error.ts +0 -134
- package/src/core/validation-issue.ts +0 -340
- package/src/core/validator.ts +0 -636
- package/src/core.ts +0 -9
- package/src/external.ts +0 -3
- package/src/helpers.test.ts +0 -694
- package/src/helpers.ts +0 -222
- package/src/index.ts +0 -3
- package/src/schema/array.test.ts +0 -251
- package/src/schema/array.ts +0 -126
- package/src/schema/blob.test.ts +0 -733
- package/src/schema/blob.ts +0 -150
- package/src/schema/boolean.test.ts +0 -118
- package/src/schema/boolean.ts +0 -46
- package/src/schema/bytes.test.ts +0 -227
- package/src/schema/bytes.ts +0 -81
- package/src/schema/cid.test.ts +0 -125
- package/src/schema/cid.ts +0 -69
- package/src/schema/custom.test.ts +0 -414
- package/src/schema/custom.ts +0 -106
- package/src/schema/dict.test.ts +0 -181
- package/src/schema/dict.ts +0 -122
- package/src/schema/discriminated-union.test.ts +0 -676
- package/src/schema/discriminated-union.ts +0 -196
- package/src/schema/enum.test.ts +0 -398
- package/src/schema/enum.ts +0 -77
- package/src/schema/integer.test.ts +0 -314
- package/src/schema/integer.ts +0 -86
- package/src/schema/intersection.test.ts +0 -33
- package/src/schema/intersection.ts +0 -113
- package/src/schema/lex-map.test.ts +0 -593
- package/src/schema/lex-map.ts +0 -63
- package/src/schema/lex-value.test.ts +0 -81
- package/src/schema/lex-value.ts +0 -86
- package/src/schema/literal.test.ts +0 -533
- package/src/schema/literal.ts +0 -70
- package/src/schema/never.test.ts +0 -175
- package/src/schema/never.ts +0 -56
- package/src/schema/null.test.ts +0 -80
- package/src/schema/null.ts +0 -49
- package/src/schema/nullable.test.ts +0 -470
- package/src/schema/nullable.ts +0 -74
- package/src/schema/object.test.ts +0 -69
- package/src/schema/object.ts +0 -136
- package/src/schema/optional.test.ts +0 -479
- package/src/schema/optional.ts +0 -92
- package/src/schema/params.test.ts +0 -1118
- package/src/schema/params.ts +0 -371
- package/src/schema/payload.test.ts +0 -340
- package/src/schema/payload.ts +0 -204
- package/src/schema/permission-set.test.ts +0 -613
- package/src/schema/permission-set.ts +0 -86
- package/src/schema/permission.test.ts +0 -537
- package/src/schema/permission.ts +0 -63
- package/src/schema/procedure.test.ts +0 -324
- package/src/schema/procedure.ts +0 -98
- package/src/schema/query.test.ts +0 -348
- package/src/schema/query.ts +0 -86
- package/src/schema/record.test.ts +0 -812
- package/src/schema/record.ts +0 -217
- package/src/schema/ref.test.ts +0 -349
- package/src/schema/ref.ts +0 -103
- package/src/schema/refine.test.ts +0 -579
- package/src/schema/refine.ts +0 -153
- package/src/schema/regexp.test.ts +0 -577
- package/src/schema/regexp.ts +0 -82
- package/src/schema/string.test.ts +0 -773
- package/src/schema/string.ts +0 -229
- package/src/schema/subscription.test.ts +0 -499
- package/src/schema/subscription.ts +0 -108
- package/src/schema/token.test.ts +0 -152
- package/src/schema/token.ts +0 -103
- package/src/schema/typed-object.test.ts +0 -745
- package/src/schema/typed-object.ts +0 -181
- package/src/schema/typed-ref.test.ts +0 -796
- package/src/schema/typed-ref.ts +0 -126
- package/src/schema/typed-union.test.ts +0 -355
- package/src/schema/typed-union.ts +0 -130
- package/src/schema/union.test.ts +0 -191
- package/src/schema/union.ts +0 -89
- package/src/schema/unknown.test.ts +0 -313
- package/src/schema/unknown.ts +0 -47
- package/src/schema/with-default.ts +0 -81
- package/src/schema.ts +0 -43
- package/src/util/array-agg.test.ts +0 -42
- package/src/util/array-agg.ts +0 -44
- package/src/util/assertion-util.ts +0 -1
- package/src/util/if-any.ts +0 -3
- package/src/util/lazy-property.ts +0 -14
- package/src/util/memoize.ts +0 -37
- package/tsconfig.build.json +0 -12
- package/tsconfig.json +0 -7
- package/tsconfig.tests.json +0 -8
|
@@ -1,773 +0,0 @@
|
|
|
1
|
-
import { describe, expect, expectTypeOf, it } from 'vitest'
|
|
2
|
-
import { Infer, UnknownString } from '../core.js'
|
|
3
|
-
import { StringSchemaOptions, string } from './string.js'
|
|
4
|
-
import { token } from './token.js'
|
|
5
|
-
import { withDefault } from './with-default.js'
|
|
6
|
-
|
|
7
|
-
describe('StringSchema', () => {
|
|
8
|
-
describe('basic validation', () => {
|
|
9
|
-
const schema = string()
|
|
10
|
-
|
|
11
|
-
it('validates plain strings', () => {
|
|
12
|
-
const result = schema.safeParse('hello world')
|
|
13
|
-
expect(result.success).toBe(true)
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
it('validates empty strings', () => {
|
|
17
|
-
const result = schema.safeParse('')
|
|
18
|
-
expect(result.success).toBe(true)
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('rejects non-strings', () => {
|
|
22
|
-
const result = schema.safeParse(123)
|
|
23
|
-
expect(result.success).toBe(false)
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('rejects null', () => {
|
|
27
|
-
const result = schema.safeParse(null)
|
|
28
|
-
expect(result.success).toBe(false)
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
it('rejects undefined', () => {
|
|
32
|
-
const result = schema.safeParse(undefined)
|
|
33
|
-
expect(result.success).toBe(false)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('rejects booleans', () => {
|
|
37
|
-
const result = schema.safeParse(true)
|
|
38
|
-
expect(result.success).toBe(false)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it('rejects arrays', () => {
|
|
42
|
-
const result = schema.safeParse(['hello'])
|
|
43
|
-
expect(result.success).toBe(false)
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
it('rejects plain objects', () => {
|
|
47
|
-
const result = schema.safeParse({ value: 'hello' })
|
|
48
|
-
expect(result.success).toBe(false)
|
|
49
|
-
})
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
describe('default values', () => {
|
|
53
|
-
it('uses default value when no input provided', () => {
|
|
54
|
-
const schema = withDefault(string(), 'default value')
|
|
55
|
-
const result = schema.safeParse(undefined)
|
|
56
|
-
expect(result.success).toBe(true)
|
|
57
|
-
if (result.success) {
|
|
58
|
-
expect(result.value).toBe('default value')
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
it('validates default value against constraints', () => {
|
|
63
|
-
const schema = string({ default: 'hi', minLength: 5 })
|
|
64
|
-
const result = schema.safeParse(undefined)
|
|
65
|
-
expect(result.success).toBe(false)
|
|
66
|
-
})
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
describe('minLength constraint', () => {
|
|
70
|
-
const schema = string({ minLength: 5 })
|
|
71
|
-
|
|
72
|
-
it('accepts strings meeting minimum length', () => {
|
|
73
|
-
const result = schema.safeParse('hello')
|
|
74
|
-
expect(result.success).toBe(true)
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
it('accepts strings exceeding minimum length', () => {
|
|
78
|
-
const result = schema.safeParse('hello world')
|
|
79
|
-
expect(result.success).toBe(true)
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
it('rejects strings below minimum length', () => {
|
|
83
|
-
const result = schema.safeParse('hi')
|
|
84
|
-
expect(result.success).toBe(false)
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
it('rejects empty strings when minLength is set', () => {
|
|
88
|
-
const result = schema.safeParse('')
|
|
89
|
-
expect(result.success).toBe(false)
|
|
90
|
-
})
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
describe('maxLength constraint', () => {
|
|
94
|
-
const schema = string({ maxLength: 10 })
|
|
95
|
-
|
|
96
|
-
it('accepts strings meeting maximum length', () => {
|
|
97
|
-
const result = schema.safeParse('1234567890')
|
|
98
|
-
expect(result.success).toBe(true)
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
it('accepts strings below maximum length', () => {
|
|
102
|
-
const result = schema.safeParse('hello')
|
|
103
|
-
expect(result.success).toBe(true)
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
it('rejects strings exceeding maximum length', () => {
|
|
107
|
-
const result = schema.safeParse('hello world!')
|
|
108
|
-
expect(result.success).toBe(false)
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
it('accepts empty strings', () => {
|
|
112
|
-
const result = schema.safeParse('')
|
|
113
|
-
expect(result.success).toBe(true)
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
it('correctly handles UTF-8 multi-byte characters', () => {
|
|
117
|
-
// Emoji takes 4 bytes in UTF-8
|
|
118
|
-
const schema = string({ maxLength: 4 })
|
|
119
|
-
const result = schema.safeParse('😀')
|
|
120
|
-
expect(result.success).toBe(true)
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
it('rejects when multi-byte characters exceed maxLength', () => {
|
|
124
|
-
const schema = string({ maxLength: 3 })
|
|
125
|
-
const result = schema.safeParse('😀')
|
|
126
|
-
expect(result.success).toBe(false)
|
|
127
|
-
})
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
describe('combined min and max length', () => {
|
|
131
|
-
const schema = string({ minLength: 3, maxLength: 10 })
|
|
132
|
-
|
|
133
|
-
it('accepts strings within range', () => {
|
|
134
|
-
const result = schema.safeParse('hello')
|
|
135
|
-
expect(result.success).toBe(true)
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
it('accepts strings at minimum boundary', () => {
|
|
139
|
-
const result = schema.safeParse('abc')
|
|
140
|
-
expect(result.success).toBe(true)
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
it('accepts strings at maximum boundary', () => {
|
|
144
|
-
const result = schema.safeParse('1234567890')
|
|
145
|
-
expect(result.success).toBe(true)
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
it('rejects strings below minimum', () => {
|
|
149
|
-
const result = schema.safeParse('hi')
|
|
150
|
-
expect(result.success).toBe(false)
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
it('rejects strings above maximum', () => {
|
|
154
|
-
const result = schema.safeParse('hello world!')
|
|
155
|
-
expect(result.success).toBe(false)
|
|
156
|
-
})
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
describe('minGraphemes constraint', () => {
|
|
160
|
-
const schema = string({ minGraphemes: 3 })
|
|
161
|
-
|
|
162
|
-
it('accepts strings meeting minimum graphemes', () => {
|
|
163
|
-
const result = schema.safeParse('abc')
|
|
164
|
-
expect(result.success).toBe(true)
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
it('accepts strings exceeding minimum graphemes', () => {
|
|
168
|
-
const result = schema.safeParse('hello')
|
|
169
|
-
expect(result.success).toBe(true)
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
it('rejects strings below minimum graphemes', () => {
|
|
173
|
-
const result = schema.safeParse('ab')
|
|
174
|
-
expect(result.success).toBe(false)
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
it('counts emoji as single graphemes', () => {
|
|
178
|
-
const result = schema.safeParse('😀😀😀')
|
|
179
|
-
expect(result.success).toBe(true)
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
it('rejects when emoji count is below minimum', () => {
|
|
183
|
-
const result = schema.safeParse('😀😀')
|
|
184
|
-
expect(result.success).toBe(false)
|
|
185
|
-
})
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
describe('maxGraphemes constraint', () => {
|
|
189
|
-
const schema = string({ maxGraphemes: 5 })
|
|
190
|
-
|
|
191
|
-
it('accepts strings meeting maximum graphemes', () => {
|
|
192
|
-
const result = schema.safeParse('hello')
|
|
193
|
-
expect(result.success).toBe(true)
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
it('accepts strings below maximum graphemes', () => {
|
|
197
|
-
const result = schema.safeParse('hi')
|
|
198
|
-
expect(result.success).toBe(true)
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
it('rejects strings exceeding maximum graphemes', () => {
|
|
202
|
-
const result = schema.safeParse('hello world')
|
|
203
|
-
expect(result.success).toBe(false)
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
it('counts emoji as single graphemes', () => {
|
|
207
|
-
const result = schema.safeParse('😀😀😀😀😀')
|
|
208
|
-
expect(result.success).toBe(true)
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
it('rejects when emoji count exceeds maximum', () => {
|
|
212
|
-
const result = schema.safeParse('😀😀😀😀😀😀')
|
|
213
|
-
expect(result.success).toBe(false)
|
|
214
|
-
})
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
describe('combined grapheme constraints', () => {
|
|
218
|
-
const schema = string({ minGraphemes: 2, maxGraphemes: 5 })
|
|
219
|
-
|
|
220
|
-
it('accepts strings within grapheme range', () => {
|
|
221
|
-
const result = schema.safeParse('hello')
|
|
222
|
-
expect(result.success).toBe(true)
|
|
223
|
-
})
|
|
224
|
-
|
|
225
|
-
it('accepts strings at minimum boundary', () => {
|
|
226
|
-
const result = schema.safeParse('hi')
|
|
227
|
-
expect(result.success).toBe(true)
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
it('accepts strings at maximum boundary', () => {
|
|
231
|
-
const result = schema.safeParse('world')
|
|
232
|
-
expect(result.success).toBe(true)
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
it('rejects strings below minimum graphemes', () => {
|
|
236
|
-
const result = schema.safeParse('a')
|
|
237
|
-
expect(result.success).toBe(false)
|
|
238
|
-
})
|
|
239
|
-
|
|
240
|
-
it('rejects strings above maximum graphemes', () => {
|
|
241
|
-
const result = schema.safeParse('hello!')
|
|
242
|
-
expect(result.success).toBe(false)
|
|
243
|
-
})
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
describe('format: datetime', () => {
|
|
247
|
-
const schema = string({ format: 'datetime' })
|
|
248
|
-
|
|
249
|
-
it('accepts valid ISO datetime strings', () => {
|
|
250
|
-
const result = schema.safeParse('2023-12-25T12:00:00Z')
|
|
251
|
-
expect(result.success).toBe(true)
|
|
252
|
-
})
|
|
253
|
-
|
|
254
|
-
it('accepts datetime with milliseconds', () => {
|
|
255
|
-
const result = schema.safeParse('2023-12-25T12:00:00.123Z')
|
|
256
|
-
expect(result.success).toBe(true)
|
|
257
|
-
})
|
|
258
|
-
|
|
259
|
-
it('rejects invalid datetime strings', () => {
|
|
260
|
-
const result = schema.safeParse('not a date')
|
|
261
|
-
expect(result.success).toBe(false)
|
|
262
|
-
})
|
|
263
|
-
|
|
264
|
-
it('rejects invalid date format', () => {
|
|
265
|
-
const result = schema.safeParse('12/25/2023')
|
|
266
|
-
expect(result.success).toBe(false)
|
|
267
|
-
})
|
|
268
|
-
|
|
269
|
-
it('rejects datetime without timezone', () => {
|
|
270
|
-
const result = schema.safeParse('2023-12-25T12:00:00')
|
|
271
|
-
expect(result.success).toBe(false)
|
|
272
|
-
})
|
|
273
|
-
|
|
274
|
-
it('rejects date-only strings', () => {
|
|
275
|
-
// Date-only is not a valid datetime in either strict or loose mode
|
|
276
|
-
const result = schema.safeParse('2023-12-25')
|
|
277
|
-
expect(result.success).toBe(false)
|
|
278
|
-
})
|
|
279
|
-
|
|
280
|
-
describe('loose validation', () => {
|
|
281
|
-
it('accepts datetime without timezone', () => {
|
|
282
|
-
const result = schema.safeParse('2023-12-25T12:00:00', {
|
|
283
|
-
strict: false,
|
|
284
|
-
})
|
|
285
|
-
expect(result.success).toBe(true)
|
|
286
|
-
})
|
|
287
|
-
|
|
288
|
-
it('accepts datetime without separator', () => {
|
|
289
|
-
const result = schema.safeParse('20231225T120000', { strict: false })
|
|
290
|
-
expect(result.success).toBe(true)
|
|
291
|
-
})
|
|
292
|
-
|
|
293
|
-
it('rejects datetime with "-00:00" timezone offset', () => {
|
|
294
|
-
const result = schema.safeParse('2023-12-25T12:00:00-00:00', {
|
|
295
|
-
strict: false,
|
|
296
|
-
})
|
|
297
|
-
expect(result.success).toBe(false)
|
|
298
|
-
})
|
|
299
|
-
|
|
300
|
-
it('rejects date-only strings', () => {
|
|
301
|
-
const result = schema.safeParse('2023-12-25', { strict: false })
|
|
302
|
-
expect(result.success).toBe(false)
|
|
303
|
-
})
|
|
304
|
-
|
|
305
|
-
it('accepts datetime with timezone offset', () => {
|
|
306
|
-
const result = schema.safeParse('2023-12-25T12:00:00+05:30', {
|
|
307
|
-
strict: false,
|
|
308
|
-
})
|
|
309
|
-
expect(result.success).toBe(true)
|
|
310
|
-
})
|
|
311
|
-
|
|
312
|
-
it('still rejects completely invalid strings', () => {
|
|
313
|
-
expect(schema.safeParse('not a date', { strict: false }).success).toBe(
|
|
314
|
-
false,
|
|
315
|
-
)
|
|
316
|
-
expect(schema.safeParse('12/25/2023', { strict: false }).success).toBe(
|
|
317
|
-
false,
|
|
318
|
-
)
|
|
319
|
-
expect(schema.safeParse('', { strict: false }).success).toBe(false)
|
|
320
|
-
})
|
|
321
|
-
|
|
322
|
-
it('uses strict mode by default', () => {
|
|
323
|
-
// Datetime without timezone is not AT Protocol compliant
|
|
324
|
-
expect(schema.safeParse('2023-12-25T12:00:00').success).toBe(false)
|
|
325
|
-
// Date-only is not AT Protocol compliant
|
|
326
|
-
expect(schema.safeParse('2023-12-25').success).toBe(false)
|
|
327
|
-
// With timezone offset (AT Protocol compliant)
|
|
328
|
-
expect(schema.safeParse('2023-12-25T12:00:00+05:30').success).toBe(true)
|
|
329
|
-
})
|
|
330
|
-
})
|
|
331
|
-
})
|
|
332
|
-
|
|
333
|
-
describe('format: uri', () => {
|
|
334
|
-
const schema = string({ format: 'uri' })
|
|
335
|
-
|
|
336
|
-
it('accepts valid HTTP URIs', () => {
|
|
337
|
-
const result = schema.safeParse('https://example.com')
|
|
338
|
-
expect(result.success).toBe(true)
|
|
339
|
-
})
|
|
340
|
-
|
|
341
|
-
it('accepts valid URIs with paths', () => {
|
|
342
|
-
const result = schema.safeParse('https://example.com/path/to/resource')
|
|
343
|
-
expect(result.success).toBe(true)
|
|
344
|
-
})
|
|
345
|
-
|
|
346
|
-
it('accepts URIs with different schemes', () => {
|
|
347
|
-
const result = schema.safeParse('ftp://files.example.com')
|
|
348
|
-
expect(result.success).toBe(true)
|
|
349
|
-
})
|
|
350
|
-
|
|
351
|
-
it('rejects invalid URIs', () => {
|
|
352
|
-
const result = schema.safeParse('not a uri')
|
|
353
|
-
expect(result.success).toBe(false)
|
|
354
|
-
})
|
|
355
|
-
|
|
356
|
-
it('rejects URIs without scheme', () => {
|
|
357
|
-
const result = schema.safeParse('example.com')
|
|
358
|
-
expect(result.success).toBe(false)
|
|
359
|
-
})
|
|
360
|
-
})
|
|
361
|
-
|
|
362
|
-
describe('format: at-uri', () => {
|
|
363
|
-
const schema = string({ format: 'at-uri' })
|
|
364
|
-
|
|
365
|
-
it('accepts valid AT URI', () => {
|
|
366
|
-
const result = schema.safeParse(
|
|
367
|
-
'at://did:plc:abc123/app.bsky.feed.post/xyz',
|
|
368
|
-
)
|
|
369
|
-
expect(result.success).toBe(true)
|
|
370
|
-
})
|
|
371
|
-
|
|
372
|
-
it('rejects invalid AT URI', () => {
|
|
373
|
-
const result = schema.safeParse('https://example.com')
|
|
374
|
-
expect(result.success).toBe(false)
|
|
375
|
-
})
|
|
376
|
-
|
|
377
|
-
it('rejects plain strings', () => {
|
|
378
|
-
const result = schema.safeParse('not an at-uri')
|
|
379
|
-
expect(result.success).toBe(false)
|
|
380
|
-
})
|
|
381
|
-
})
|
|
382
|
-
|
|
383
|
-
describe('format: did', () => {
|
|
384
|
-
const schema = string({ format: 'did' })
|
|
385
|
-
|
|
386
|
-
it('accepts valid DID with plc method', () => {
|
|
387
|
-
const result = schema.safeParse('did:plc:abc123')
|
|
388
|
-
expect(result.success).toBe(true)
|
|
389
|
-
})
|
|
390
|
-
|
|
391
|
-
it('accepts valid DID with web method', () => {
|
|
392
|
-
const result = schema.safeParse('did:web:example.com')
|
|
393
|
-
expect(result.success).toBe(true)
|
|
394
|
-
})
|
|
395
|
-
|
|
396
|
-
it('rejects invalid DID format', () => {
|
|
397
|
-
const result = schema.safeParse('not-a-did')
|
|
398
|
-
expect(result.success).toBe(false)
|
|
399
|
-
})
|
|
400
|
-
|
|
401
|
-
it('rejects DID without method', () => {
|
|
402
|
-
const result = schema.safeParse('did:')
|
|
403
|
-
expect(result.success).toBe(false)
|
|
404
|
-
})
|
|
405
|
-
})
|
|
406
|
-
|
|
407
|
-
describe('format: handle', () => {
|
|
408
|
-
const schema = string({ format: 'handle' })
|
|
409
|
-
|
|
410
|
-
it('accepts valid handle', () => {
|
|
411
|
-
const result = schema.safeParse('user.bsky.social')
|
|
412
|
-
expect(result.success).toBe(true)
|
|
413
|
-
})
|
|
414
|
-
|
|
415
|
-
it('accepts handle with subdomain', () => {
|
|
416
|
-
const result = schema.safeParse('alice.test.example.com')
|
|
417
|
-
expect(result.success).toBe(true)
|
|
418
|
-
})
|
|
419
|
-
|
|
420
|
-
it('rejects invalid handle format', () => {
|
|
421
|
-
const result = schema.safeParse('invalid handle!')
|
|
422
|
-
expect(result.success).toBe(false)
|
|
423
|
-
})
|
|
424
|
-
|
|
425
|
-
it('rejects handle with spaces', () => {
|
|
426
|
-
const result = schema.safeParse('user name.bsky.social')
|
|
427
|
-
expect(result.success).toBe(false)
|
|
428
|
-
})
|
|
429
|
-
})
|
|
430
|
-
|
|
431
|
-
describe('format: at-identifier', () => {
|
|
432
|
-
const schema = string({ format: 'at-identifier' })
|
|
433
|
-
|
|
434
|
-
it('accepts valid DID as at-identifier', () => {
|
|
435
|
-
const result = schema.safeParse('did:plc:abc123')
|
|
436
|
-
expect(result.success).toBe(true)
|
|
437
|
-
})
|
|
438
|
-
|
|
439
|
-
it('accepts valid handle as at-identifier', () => {
|
|
440
|
-
const result = schema.safeParse('user.bsky.social')
|
|
441
|
-
expect(result.success).toBe(true)
|
|
442
|
-
})
|
|
443
|
-
|
|
444
|
-
it('rejects invalid at-identifier', () => {
|
|
445
|
-
const result = schema.safeParse('invalid!')
|
|
446
|
-
expect(result.success).toBe(false)
|
|
447
|
-
})
|
|
448
|
-
})
|
|
449
|
-
|
|
450
|
-
describe('format: nsid', () => {
|
|
451
|
-
const schema = string({ format: 'nsid' })
|
|
452
|
-
|
|
453
|
-
it('accepts valid NSID', () => {
|
|
454
|
-
const result = schema.safeParse('app.bsky.feed.post')
|
|
455
|
-
expect(result.success).toBe(true)
|
|
456
|
-
})
|
|
457
|
-
|
|
458
|
-
it('accepts NSID with multiple segments', () => {
|
|
459
|
-
const result = schema.safeParse('com.example.app.feature.action')
|
|
460
|
-
expect(result.success).toBe(true)
|
|
461
|
-
})
|
|
462
|
-
|
|
463
|
-
it('rejects invalid NSID format', () => {
|
|
464
|
-
const result = schema.safeParse('not-an-nsid')
|
|
465
|
-
expect(result.success).toBe(false)
|
|
466
|
-
})
|
|
467
|
-
|
|
468
|
-
it('rejects NSID with invalid characters', () => {
|
|
469
|
-
const result = schema.safeParse('app.bsky.feed!')
|
|
470
|
-
expect(result.success).toBe(false)
|
|
471
|
-
})
|
|
472
|
-
})
|
|
473
|
-
|
|
474
|
-
describe('format: cid', () => {
|
|
475
|
-
const schema = string({ format: 'cid' })
|
|
476
|
-
|
|
477
|
-
it('accepts valid CID v1', () => {
|
|
478
|
-
const result = schema.safeParse(
|
|
479
|
-
'bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi',
|
|
480
|
-
)
|
|
481
|
-
expect(result.success).toBe(true)
|
|
482
|
-
})
|
|
483
|
-
|
|
484
|
-
it('rejects invalid CID format', () => {
|
|
485
|
-
const result = schema.safeParse('not-a-cid')
|
|
486
|
-
expect(result.success).toBe(false)
|
|
487
|
-
})
|
|
488
|
-
|
|
489
|
-
it('rejects plain strings', () => {
|
|
490
|
-
const result = schema.safeParse('abc123')
|
|
491
|
-
expect(result.success).toBe(false)
|
|
492
|
-
})
|
|
493
|
-
})
|
|
494
|
-
|
|
495
|
-
describe('format: language', () => {
|
|
496
|
-
const schema = string({ format: 'language' })
|
|
497
|
-
|
|
498
|
-
it('accepts valid BCP 47 language code', () => {
|
|
499
|
-
const result = schema.safeParse('en')
|
|
500
|
-
expect(result.success).toBe(true)
|
|
501
|
-
})
|
|
502
|
-
|
|
503
|
-
it('accepts language code with region', () => {
|
|
504
|
-
const result = schema.safeParse('en-US')
|
|
505
|
-
expect(result.success).toBe(true)
|
|
506
|
-
})
|
|
507
|
-
|
|
508
|
-
it('accepts language code with script and region', () => {
|
|
509
|
-
const result = schema.safeParse('zh-Hans-CN')
|
|
510
|
-
expect(result.success).toBe(true)
|
|
511
|
-
})
|
|
512
|
-
|
|
513
|
-
it('rejects invalid language code', () => {
|
|
514
|
-
const result = schema.safeParse('not valid')
|
|
515
|
-
expect(result.success).toBe(false)
|
|
516
|
-
})
|
|
517
|
-
})
|
|
518
|
-
|
|
519
|
-
describe('format: tid', () => {
|
|
520
|
-
const schema = string({ format: 'tid' })
|
|
521
|
-
|
|
522
|
-
it('accepts valid TID', () => {
|
|
523
|
-
const result = schema.safeParse('3jzfcijpj2z2a')
|
|
524
|
-
expect(result.success).toBe(true)
|
|
525
|
-
})
|
|
526
|
-
|
|
527
|
-
it('rejects invalid TID format', () => {
|
|
528
|
-
const result = schema.safeParse('not-a-tid')
|
|
529
|
-
expect(result.success).toBe(false)
|
|
530
|
-
})
|
|
531
|
-
|
|
532
|
-
it('rejects TID with invalid characters', () => {
|
|
533
|
-
const result = schema.safeParse('3jzfcijpj2z2!')
|
|
534
|
-
expect(result.success).toBe(false)
|
|
535
|
-
})
|
|
536
|
-
})
|
|
537
|
-
|
|
538
|
-
describe('format: record-key', () => {
|
|
539
|
-
const schema = string({ format: 'record-key' })
|
|
540
|
-
|
|
541
|
-
it('accepts valid record key', () => {
|
|
542
|
-
const result = schema.safeParse('3jzfcijpj2z2a')
|
|
543
|
-
expect(result.success).toBe(true)
|
|
544
|
-
})
|
|
545
|
-
|
|
546
|
-
it('accepts alphanumeric record key', () => {
|
|
547
|
-
const result = schema.safeParse('myRecordKey123')
|
|
548
|
-
expect(result.success).toBe(true)
|
|
549
|
-
})
|
|
550
|
-
|
|
551
|
-
it('rejects record key with invalid characters', () => {
|
|
552
|
-
const result = schema.safeParse('invalid/key')
|
|
553
|
-
expect(result.success).toBe(false)
|
|
554
|
-
})
|
|
555
|
-
|
|
556
|
-
it('rejects record key with spaces', () => {
|
|
557
|
-
const result = schema.safeParse('invalid key')
|
|
558
|
-
expect(result.success).toBe(false)
|
|
559
|
-
})
|
|
560
|
-
})
|
|
561
|
-
|
|
562
|
-
describe('type coercion', () => {
|
|
563
|
-
const schema = string()
|
|
564
|
-
|
|
565
|
-
it('coerces Date objects to ISO strings', () => {
|
|
566
|
-
const date = new Date('2023-12-25T12:00:00Z')
|
|
567
|
-
const result = schema.safeParse(date)
|
|
568
|
-
expect(result.success).toBe(true)
|
|
569
|
-
if (result.success) {
|
|
570
|
-
expect(result.value).toBe('2023-12-25T12:00:00.000Z')
|
|
571
|
-
}
|
|
572
|
-
})
|
|
573
|
-
|
|
574
|
-
it('rejects invalid Date objects', () => {
|
|
575
|
-
const invalidDate = new Date('invalid')
|
|
576
|
-
const result = schema.safeParse(invalidDate)
|
|
577
|
-
expect(result.success).toBe(false)
|
|
578
|
-
})
|
|
579
|
-
|
|
580
|
-
it('coerces URL objects to strings', () => {
|
|
581
|
-
const url = new URL('https://example.com/path')
|
|
582
|
-
const result = schema.safeParse(url)
|
|
583
|
-
expect(result.success).toBe(true)
|
|
584
|
-
if (result.success) {
|
|
585
|
-
expect(result.value).toBe('https://example.com/path')
|
|
586
|
-
}
|
|
587
|
-
})
|
|
588
|
-
|
|
589
|
-
it('coerces String objects to primitive strings', () => {
|
|
590
|
-
const stringObj = new String('hello')
|
|
591
|
-
const result = schema.safeParse(stringObj)
|
|
592
|
-
expect(result.success).toBe(true)
|
|
593
|
-
if (result.success) {
|
|
594
|
-
expect(result.value).toBe('hello')
|
|
595
|
-
}
|
|
596
|
-
})
|
|
597
|
-
|
|
598
|
-
it('coerces TokenSchema instances to strings', () => {
|
|
599
|
-
const result = schema.safeParse(token('my.to.ken', 'main'))
|
|
600
|
-
expect(result.success).toBe(true)
|
|
601
|
-
if (result.success) {
|
|
602
|
-
expect(result.value).toBe('my.to.ken')
|
|
603
|
-
}
|
|
604
|
-
})
|
|
605
|
-
})
|
|
606
|
-
|
|
607
|
-
describe('combined constraints and format', () => {
|
|
608
|
-
const schema = string({
|
|
609
|
-
format: 'handle',
|
|
610
|
-
minLength: 5,
|
|
611
|
-
maxLength: 50,
|
|
612
|
-
})
|
|
613
|
-
|
|
614
|
-
it('validates both format and length constraints', () => {
|
|
615
|
-
const result = schema.safeParse('user.bsky.social')
|
|
616
|
-
expect(result.success).toBe(true)
|
|
617
|
-
})
|
|
618
|
-
|
|
619
|
-
it('rejects when length is valid but format is invalid', () => {
|
|
620
|
-
const result = schema.safeParse('invalid handle!')
|
|
621
|
-
expect(result.success).toBe(false)
|
|
622
|
-
})
|
|
623
|
-
|
|
624
|
-
it('rejects when format is valid but length is too short', () => {
|
|
625
|
-
const result = schema.safeParse('a.bc')
|
|
626
|
-
expect(result.success).toBe(false)
|
|
627
|
-
})
|
|
628
|
-
|
|
629
|
-
it('rejects when format is valid but length is too long', () => {
|
|
630
|
-
const longHandle =
|
|
631
|
-
'very.long.subdomain.name.that.exceeds.maximum.length.example.com'
|
|
632
|
-
const result = schema.safeParse(longHandle)
|
|
633
|
-
expect(result.success).toBe(false)
|
|
634
|
-
})
|
|
635
|
-
})
|
|
636
|
-
|
|
637
|
-
describe('edge cases', () => {
|
|
638
|
-
it('handles strings with special characters', () => {
|
|
639
|
-
const schema = string()
|
|
640
|
-
const result = schema.safeParse('hello\nworld\ttab')
|
|
641
|
-
expect(result.success).toBe(true)
|
|
642
|
-
})
|
|
643
|
-
|
|
644
|
-
it('handles strings with unicode characters', () => {
|
|
645
|
-
const schema = string()
|
|
646
|
-
const result = schema.safeParse('Hello 世界 🌍')
|
|
647
|
-
expect(result.success).toBe(true)
|
|
648
|
-
})
|
|
649
|
-
|
|
650
|
-
it('handles very long strings', () => {
|
|
651
|
-
const schema = string({ maxLength: 10000 })
|
|
652
|
-
const longString = 'a'.repeat(10000)
|
|
653
|
-
const result = schema.safeParse(longString)
|
|
654
|
-
expect(result.success).toBe(true)
|
|
655
|
-
})
|
|
656
|
-
|
|
657
|
-
it('rejects very long strings exceeding maxLength', () => {
|
|
658
|
-
const schema = string({ maxLength: 100 })
|
|
659
|
-
const longString = 'a'.repeat(101)
|
|
660
|
-
const result = schema.safeParse(longString)
|
|
661
|
-
expect(result.success).toBe(false)
|
|
662
|
-
})
|
|
663
|
-
|
|
664
|
-
it('handles zero as minLength', () => {
|
|
665
|
-
const schema = string({ minLength: 0 })
|
|
666
|
-
const result = schema.safeParse('')
|
|
667
|
-
expect(result.success).toBe(true)
|
|
668
|
-
})
|
|
669
|
-
|
|
670
|
-
it('handles complex emoji sequences', () => {
|
|
671
|
-
const schema = string({ maxGraphemes: 5 })
|
|
672
|
-
// Family emoji is a single grapheme cluster
|
|
673
|
-
const result = schema.safeParse('👨👩👧👦')
|
|
674
|
-
expect(result.success).toBe(true)
|
|
675
|
-
})
|
|
676
|
-
})
|
|
677
|
-
|
|
678
|
-
describe('knownValues option', () => {
|
|
679
|
-
it('allows omitting knownValues at runtime', () => {
|
|
680
|
-
string<{ knownValues: ['active', 'inactive'] }>()
|
|
681
|
-
|
|
682
|
-
// @ts-expect-error format requires options to be set
|
|
683
|
-
string<{ knownValues: ['active', 'inactive']; format: 'did' }>()
|
|
684
|
-
|
|
685
|
-
// @ts-expect-error any options, besides knownValues, must be provided
|
|
686
|
-
string<{ knownValues: ['active', 'inactive']; minLength: 5 }>()
|
|
687
|
-
|
|
688
|
-
string<{
|
|
689
|
-
knownValues: ['john.doe', 'someone.else']
|
|
690
|
-
format: 'handle'
|
|
691
|
-
}>({
|
|
692
|
-
format: 'handle',
|
|
693
|
-
})
|
|
694
|
-
|
|
695
|
-
string<{
|
|
696
|
-
knownValues: ['john.doe', 'someone.else']
|
|
697
|
-
}>({
|
|
698
|
-
// Being *more* precise than the generic if fine
|
|
699
|
-
format: 'handle',
|
|
700
|
-
})
|
|
701
|
-
|
|
702
|
-
string<{
|
|
703
|
-
knownValues: ['did', 'inactive']
|
|
704
|
-
format: 'did'
|
|
705
|
-
}>({
|
|
706
|
-
// @ts-expect-error does not match format form generic constraint
|
|
707
|
-
format: 'handle',
|
|
708
|
-
})
|
|
709
|
-
|
|
710
|
-
string<{
|
|
711
|
-
knownValues: ['active', 'inactive']
|
|
712
|
-
minLength: 10
|
|
713
|
-
}>({
|
|
714
|
-
minLength: 10,
|
|
715
|
-
})
|
|
716
|
-
|
|
717
|
-
string<{
|
|
718
|
-
knownValues: ['active', 'inactive']
|
|
719
|
-
minLength: 5
|
|
720
|
-
}>({
|
|
721
|
-
// @ts-expect-error mismatch
|
|
722
|
-
minLength: 10,
|
|
723
|
-
})
|
|
724
|
-
})
|
|
725
|
-
})
|
|
726
|
-
|
|
727
|
-
it('properly types knownValues in parameters', () => {
|
|
728
|
-
const _schema = string({
|
|
729
|
-
knownValues: ['active', 'inactive'],
|
|
730
|
-
})
|
|
731
|
-
type SchemaType = Infer<typeof _schema>
|
|
732
|
-
expectTypeOf<{
|
|
733
|
-
foo: SchemaType
|
|
734
|
-
}>().toMatchObjectType<{
|
|
735
|
-
foo: 'active' | 'inactive' | UnknownString
|
|
736
|
-
}>()
|
|
737
|
-
expectTypeOf<{
|
|
738
|
-
foo: SchemaType
|
|
739
|
-
}>().not.toMatchObjectType<{
|
|
740
|
-
foo: string
|
|
741
|
-
}>()
|
|
742
|
-
expectTypeOf<{
|
|
743
|
-
foo: SchemaType
|
|
744
|
-
}>().not.toMatchObjectType<{
|
|
745
|
-
foo: 'active' | 'inactive'
|
|
746
|
-
}>()
|
|
747
|
-
expectTypeOf<{
|
|
748
|
-
foo: SchemaType
|
|
749
|
-
}>().not.toMatchObjectType<{
|
|
750
|
-
foo: UnknownString
|
|
751
|
-
}>()
|
|
752
|
-
})
|
|
753
|
-
|
|
754
|
-
it('type string<any>() as string', () => {
|
|
755
|
-
const _schema = string<any>()
|
|
756
|
-
type SchemaType = Infer<typeof _schema>
|
|
757
|
-
expectTypeOf<{
|
|
758
|
-
foo: SchemaType
|
|
759
|
-
}>().toMatchObjectType<{
|
|
760
|
-
foo: string
|
|
761
|
-
}>()
|
|
762
|
-
})
|
|
763
|
-
|
|
764
|
-
it('type string<StringSchemaOptions>({}) as string', () => {
|
|
765
|
-
const _schema = string<StringSchemaOptions>({})
|
|
766
|
-
type SchemaType = Infer<typeof _schema>
|
|
767
|
-
expectTypeOf<{
|
|
768
|
-
foo: SchemaType
|
|
769
|
-
}>().toMatchObjectType<{
|
|
770
|
-
foo: string
|
|
771
|
-
}>()
|
|
772
|
-
})
|
|
773
|
-
})
|