@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
package/src/schema/string.ts
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import { graphemeLen, ifCid, utf8Len } from '@atproto/lex-data'
|
|
2
|
-
import {
|
|
3
|
-
InferStringFormat,
|
|
4
|
-
Restricted,
|
|
5
|
-
Schema,
|
|
6
|
-
StringFormat,
|
|
7
|
-
UnknownString,
|
|
8
|
-
ValidationContext,
|
|
9
|
-
isStringFormat,
|
|
10
|
-
} from '../core.js'
|
|
11
|
-
import { IfAny } from '../util/if-any.js'
|
|
12
|
-
import { memoizedOptions } from '../util/memoize.js'
|
|
13
|
-
import { TokenSchema } from './token.js'
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Configuration options for string schema validation.
|
|
17
|
-
*
|
|
18
|
-
* @property format - Expected string format (e.g., 'datetime', 'uri', 'at-uri', 'did', 'handle', 'nsid', 'cid', 'tid', 'record-key', 'at-identifier', 'language')
|
|
19
|
-
* @property knownValues - Known string literal values for type narrowing
|
|
20
|
-
* @property minLength - Minimum length in UTF-8 bytes
|
|
21
|
-
* @property maxLength - Maximum length in UTF-8 bytes
|
|
22
|
-
* @property minGraphemes - Minimum number of grapheme clusters
|
|
23
|
-
* @property maxGraphemes - Maximum number of grapheme clusters
|
|
24
|
-
*/
|
|
25
|
-
export type StringSchemaOptions = {
|
|
26
|
-
format?: StringFormat
|
|
27
|
-
knownValues?: readonly string[]
|
|
28
|
-
minLength?: number
|
|
29
|
-
maxLength?: number
|
|
30
|
-
minGraphemes?: number
|
|
31
|
-
maxGraphemes?: number
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Schema for validating string values with optional format and length constraints.
|
|
36
|
-
*
|
|
37
|
-
* Supports various string formats defined in the Lexicon specification, as well as
|
|
38
|
-
* length constraints measured in UTF-8 bytes or grapheme clusters.
|
|
39
|
-
*
|
|
40
|
-
* @template TOptions - The configuration options type
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```ts
|
|
44
|
-
* const schema = new StringSchema({ format: 'datetime', maxLength: 64 })
|
|
45
|
-
* const result = schema.validate('2024-01-15T10:30:00Z')
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
export class StringSchema<
|
|
49
|
-
const TOptions extends StringSchemaOptions = StringSchemaOptions,
|
|
50
|
-
> extends Schema<
|
|
51
|
-
IfAny<
|
|
52
|
-
TOptions,
|
|
53
|
-
string,
|
|
54
|
-
TOptions extends { format: infer F extends StringFormat }
|
|
55
|
-
? InferStringFormat<F>
|
|
56
|
-
: TOptions extends { knownValues: readonly (infer V extends string)[] }
|
|
57
|
-
? V | UnknownString
|
|
58
|
-
: string
|
|
59
|
-
>
|
|
60
|
-
> {
|
|
61
|
-
readonly type = 'string' as const
|
|
62
|
-
|
|
63
|
-
// @NOTE since the _string utility allows omitting knownValues when TOptions
|
|
64
|
-
// *does* include it (since it's only used for typing), we cannot type options
|
|
65
|
-
// as TOptions directly since it may not actually include knownValues at
|
|
66
|
-
// runtime, making schema.options.knownValues potentially undefined even when
|
|
67
|
-
// TOptions includes it.
|
|
68
|
-
readonly options: StringSchemaOptions
|
|
69
|
-
|
|
70
|
-
constructor(options: TOptions) {
|
|
71
|
-
super()
|
|
72
|
-
this.options = options
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
validateInContext(input: unknown, ctx: ValidationContext) {
|
|
76
|
-
const str = coerceToString(input)
|
|
77
|
-
if (str == null) {
|
|
78
|
-
return ctx.issueUnexpectedType(input, 'string')
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
let lazyUtf8Len: number
|
|
82
|
-
|
|
83
|
-
const minLength = this.options.minLength
|
|
84
|
-
if (minLength != null) {
|
|
85
|
-
if ((lazyUtf8Len ??= utf8Len(str)) < minLength) {
|
|
86
|
-
return ctx.issueTooSmall(str, 'string', minLength, lazyUtf8Len)
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const maxLength = this.options.maxLength
|
|
91
|
-
if (maxLength != null) {
|
|
92
|
-
// Optimization: we can avoid computing the UTF-8 length if the maximum
|
|
93
|
-
// possible length, in bytes, of the input JS string is smaller than the
|
|
94
|
-
// maxLength (in UTF-8 string bytes).
|
|
95
|
-
if (str.length * 3 <= maxLength) {
|
|
96
|
-
// Input string so small it can't possibly exceed maxLength
|
|
97
|
-
} else if ((lazyUtf8Len ??= utf8Len(str)) > maxLength) {
|
|
98
|
-
return ctx.issueTooBig(str, 'string', maxLength, lazyUtf8Len)
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Optimization: count graphemes once
|
|
103
|
-
let lazyGraphLen: number
|
|
104
|
-
|
|
105
|
-
const minGraphemes = this.options.minGraphemes
|
|
106
|
-
if (minGraphemes != null) {
|
|
107
|
-
if (str.length < minGraphemes) {
|
|
108
|
-
// If the JavaScript string length (UTF-16) is below the minimal limit,
|
|
109
|
-
// its grapheme length (which <= .length) will also be below.
|
|
110
|
-
// Fail early.
|
|
111
|
-
return ctx.issueTooSmall(str, 'grapheme', minGraphemes, str.length)
|
|
112
|
-
} else if ((lazyGraphLen ??= graphemeLen(str)) < minGraphemes) {
|
|
113
|
-
return ctx.issueTooSmall(str, 'grapheme', minGraphemes, lazyGraphLen)
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const maxGraphemes = this.options.maxGraphemes
|
|
118
|
-
if (maxGraphemes != null) {
|
|
119
|
-
if (str.length <= maxGraphemes) {
|
|
120
|
-
// If the JavaScript string length (UTF-16) is within the maximum limit,
|
|
121
|
-
// its grapheme length (which <= .length) will also be within.
|
|
122
|
-
} else if ((lazyGraphLen ??= graphemeLen(str)) > maxGraphemes) {
|
|
123
|
-
return ctx.issueTooBig(str, 'grapheme', maxGraphemes, lazyGraphLen)
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const format = this.options.format
|
|
128
|
-
if (format != null && !isStringFormat(str, format, ctx.options)) {
|
|
129
|
-
return ctx.issueInvalidFormat(str, format)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return ctx.success(str)
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export function coerceToString(input: unknown): string | null {
|
|
137
|
-
switch (typeof input) {
|
|
138
|
-
// @NOTE We do *not* coerce numbers/booleans to strings because that can
|
|
139
|
-
// lead to them being accepted as string instead of being coerced to
|
|
140
|
-
// number/boolean when the input is a string and the expected result is
|
|
141
|
-
// number/boolean (e.g. in params).
|
|
142
|
-
case 'string':
|
|
143
|
-
return input
|
|
144
|
-
case 'object': {
|
|
145
|
-
if (input == null) return null
|
|
146
|
-
|
|
147
|
-
// @NOTE Allow using TokenSchema instances in places expecting strings,
|
|
148
|
-
// converting them to their string value.
|
|
149
|
-
if (input instanceof TokenSchema) {
|
|
150
|
-
return input.toString()
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (input instanceof Date) {
|
|
154
|
-
if (Number.isNaN(input.getTime())) return null
|
|
155
|
-
return input.toISOString()
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (input instanceof URL) {
|
|
159
|
-
return input.toString()
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const cid = ifCid(input)
|
|
163
|
-
if (cid) return cid.toString()
|
|
164
|
-
|
|
165
|
-
if (input instanceof String) {
|
|
166
|
-
return input.valueOf()
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// falls through
|
|
171
|
-
default:
|
|
172
|
-
return null
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function _string(): StringSchema<NonNullable<unknown>>
|
|
177
|
-
function _string<
|
|
178
|
-
// Allow calling `string<{ knownValues: [...] }>()` without passing an options
|
|
179
|
-
// object, since knownValues is only used for typing and has no runtime
|
|
180
|
-
// effect, so it can be safely omitted at runtime.
|
|
181
|
-
const TOptions extends {
|
|
182
|
-
knownValues: StringSchemaOptions['knownValues']
|
|
183
|
-
} & {
|
|
184
|
-
[K in Exclude<
|
|
185
|
-
keyof StringSchemaOptions,
|
|
186
|
-
'knownValues'
|
|
187
|
-
>]?: Restricted<`An options argument is required when using the "${K}" option`>
|
|
188
|
-
},
|
|
189
|
-
>(): StringSchema<
|
|
190
|
-
IfAny<TOptions, any, { knownValues: TOptions['knownValues'] }>
|
|
191
|
-
>
|
|
192
|
-
function _string<const TOptions extends StringSchemaOptions>(
|
|
193
|
-
// If TOptions is explicitly provided (e.g. `string<{ ... }>({ ... })`), we
|
|
194
|
-
// allow the actual options argument to omit the "knownValues" property since
|
|
195
|
-
// it's only used for inferring the type and has no runtime effect.
|
|
196
|
-
options: TOptions | Omit<TOptions, 'knownValues'>,
|
|
197
|
-
): StringSchema<TOptions>
|
|
198
|
-
function _string(options: StringSchemaOptions = {}) {
|
|
199
|
-
return new StringSchema(options)
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Creates a string schema with optional format and length constraints.
|
|
204
|
-
*
|
|
205
|
-
* Strings can be validated against various formats (datetime, uri, did, handle, etc.)
|
|
206
|
-
* and constrained by length in UTF-8 bytes or grapheme clusters.
|
|
207
|
-
*
|
|
208
|
-
* @param options - Optional configuration for format and length constraints
|
|
209
|
-
* @returns A new {@link StringSchema} instance
|
|
210
|
-
*
|
|
211
|
-
* @example
|
|
212
|
-
* ```ts
|
|
213
|
-
* // Basic string
|
|
214
|
-
* const nameSchema = l.string()
|
|
215
|
-
*
|
|
216
|
-
* // With format validation
|
|
217
|
-
* const dateSchema = l.string({ format: 'datetime' })
|
|
218
|
-
*
|
|
219
|
-
* // With length constraints (UTF-8 bytes)
|
|
220
|
-
* const bioSchema = l.string({ maxLength: 256 })
|
|
221
|
-
*
|
|
222
|
-
* // With grapheme constraints (user-perceived characters)
|
|
223
|
-
* const displayNameSchema = l.string({ maxGraphemes: 64 })
|
|
224
|
-
*
|
|
225
|
-
* // Combining constraints
|
|
226
|
-
* const handleSchema = l.string({ format: 'handle', minLength: 3, maxLength: 253 })
|
|
227
|
-
* ```
|
|
228
|
-
*/
|
|
229
|
-
export const string = /*#__PURE__*/ memoizedOptions(_string)
|