@atproto/lex-schema 0.0.1 → 0.0.3
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 +68 -0
- package/dist/core/$type.d.ts +6 -3
- package/dist/core/$type.d.ts.map +1 -1
- package/dist/core/$type.js +1 -0
- package/dist/core/$type.js.map +1 -1
- package/dist/core/record-key.d.ts +3 -3
- package/dist/core/record-key.d.ts.map +1 -1
- package/dist/core/record-key.js +12 -6
- package/dist/core/record-key.js.map +1 -1
- package/dist/core/result.d.ts.map +1 -1
- package/dist/core/result.js +6 -0
- package/dist/core/result.js.map +1 -1
- package/dist/core/string-format.d.ts +30 -27
- package/dist/core/string-format.d.ts.map +1 -1
- package/dist/core/string-format.js +56 -42
- package/dist/core/string-format.js.map +1 -1
- package/dist/core/types.d.ts +9 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/external.d.ts +31 -28
- package/dist/external.d.ts.map +1 -1
- package/dist/external.js +33 -17
- package/dist/external.js.map +1 -1
- package/dist/schema/_parameters.d.ts +2 -2
- package/dist/schema/_parameters.d.ts.map +1 -1
- package/dist/schema/array.d.ts +5 -6
- package/dist/schema/array.d.ts.map +1 -1
- package/dist/schema/array.js +5 -6
- package/dist/schema/array.js.map +1 -1
- package/dist/schema/blob.d.ts +2 -3
- package/dist/schema/blob.d.ts.map +1 -1
- package/dist/schema/blob.js +1 -2
- package/dist/schema/blob.js.map +1 -1
- package/dist/schema/boolean.d.ts +4 -5
- package/dist/schema/boolean.d.ts.map +1 -1
- package/dist/schema/boolean.js +2 -3
- package/dist/schema/boolean.js.map +1 -1
- package/dist/schema/bytes.d.ts +3 -4
- package/dist/schema/bytes.d.ts.map +1 -1
- package/dist/schema/bytes.js +2 -3
- package/dist/schema/bytes.js.map +1 -1
- package/dist/schema/cid.d.ts +13 -6
- package/dist/schema/cid.d.ts.map +1 -1
- package/dist/schema/cid.js +2 -4
- package/dist/schema/cid.js.map +1 -1
- package/dist/schema/custom.d.ts +3 -4
- package/dist/schema/custom.d.ts.map +1 -1
- package/dist/schema/custom.js +4 -3
- package/dist/schema/custom.js.map +1 -1
- package/dist/schema/dict.d.ts +3 -3
- 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 +15 -24
- package/dist/schema/discriminated-union.d.ts.map +1 -1
- package/dist/schema/discriminated-union.js +40 -64
- package/dist/schema/discriminated-union.js.map +1 -1
- package/dist/schema/enum.d.ts +8 -4
- package/dist/schema/enum.d.ts.map +1 -1
- package/dist/schema/enum.js +5 -3
- package/dist/schema/enum.js.map +1 -1
- package/dist/schema/integer.d.ts +3 -4
- package/dist/schema/integer.d.ts.map +1 -1
- package/dist/schema/integer.js +3 -4
- package/dist/schema/integer.js.map +1 -1
- package/dist/schema/intersection.d.ts +22 -14
- package/dist/schema/intersection.d.ts.map +1 -1
- package/dist/schema/intersection.js +12 -22
- package/dist/schema/intersection.js.map +1 -1
- package/dist/schema/literal.d.ts +8 -4
- package/dist/schema/literal.d.ts.map +1 -1
- package/dist/schema/literal.js +5 -3
- package/dist/schema/literal.js.map +1 -1
- package/dist/schema/never.d.ts +2 -2
- package/dist/schema/never.d.ts.map +1 -1
- package/dist/schema/never.js +1 -1
- package/dist/schema/never.js.map +1 -1
- package/dist/schema/null.d.ts +2 -3
- package/dist/schema/null.d.ts.map +1 -1
- package/dist/schema/null.js +1 -2
- package/dist/schema/null.js.map +1 -1
- package/dist/schema/nullable.d.ts +7 -0
- package/dist/schema/nullable.d.ts.map +1 -0
- package/dist/schema/nullable.js +19 -0
- package/dist/schema/nullable.js.map +1 -0
- package/dist/schema/object.d.ts +10 -44
- package/dist/schema/object.d.ts.map +1 -1
- package/dist/schema/object.js +13 -56
- package/dist/schema/object.js.map +1 -1
- package/dist/schema/optional.d.ts +7 -0
- package/dist/schema/optional.d.ts.map +1 -0
- package/dist/schema/optional.js +25 -0
- package/dist/schema/optional.js.map +1 -0
- package/dist/schema/params.d.ts +14 -19
- package/dist/schema/params.d.ts.map +1 -1
- package/dist/schema/params.js +10 -24
- package/dist/schema/params.js.map +1 -1
- package/dist/schema/payload.d.ts +4 -4
- package/dist/schema/payload.d.ts.map +1 -1
- package/dist/schema/payload.js.map +1 -1
- package/dist/schema/permission-set.d.ts +6 -6
- package/dist/schema/permission-set.d.ts.map +1 -1
- package/dist/schema/permission-set.js +1 -2
- package/dist/schema/permission-set.js.map +1 -1
- package/dist/schema/permission.d.ts +0 -1
- package/dist/schema/permission.d.ts.map +1 -1
- package/dist/schema/permission.js +0 -1
- package/dist/schema/permission.js.map +1 -1
- package/dist/schema/procedure.d.ts +8 -9
- package/dist/schema/procedure.d.ts.map +1 -1
- package/dist/schema/procedure.js +0 -1
- package/dist/schema/procedure.js.map +1 -1
- package/dist/schema/query.d.ts +7 -8
- package/dist/schema/query.d.ts.map +1 -1
- package/dist/schema/query.js +0 -1
- package/dist/schema/query.js.map +1 -1
- package/dist/schema/record.d.ts +34 -28
- package/dist/schema/record.d.ts.map +1 -1
- package/dist/schema/record.js +1 -2
- package/dist/schema/record.js.map +1 -1
- package/dist/schema/ref.d.ts +2 -3
- package/dist/schema/ref.d.ts.map +1 -1
- package/dist/schema/ref.js +1 -2
- package/dist/schema/ref.js.map +1 -1
- package/dist/schema/refine.d.ts +18 -0
- package/dist/schema/refine.d.ts.map +1 -0
- package/dist/schema/refine.js +33 -0
- package/dist/schema/refine.js.map +1 -0
- package/dist/schema/regexp.d.ts +7 -0
- package/dist/schema/regexp.d.ts.map +1 -0
- package/dist/schema/regexp.js +22 -0
- package/dist/schema/regexp.js.map +1 -0
- package/dist/schema/string.d.ts +4 -8
- package/dist/schema/string.d.ts.map +1 -1
- package/dist/schema/string.js +6 -3
- package/dist/schema/string.js.map +1 -1
- package/dist/schema/subscription.d.ts +7 -6
- package/dist/schema/subscription.d.ts.map +1 -1
- package/dist/schema/subscription.js.map +1 -1
- package/dist/schema/token.d.ts +2 -3
- package/dist/schema/token.d.ts.map +1 -1
- package/dist/schema/token.js +1 -2
- package/dist/schema/token.js.map +1 -1
- package/dist/schema/typed-object.d.ts +29 -27
- package/dist/schema/typed-object.d.ts.map +1 -1
- package/dist/schema/typed-object.js +1 -2
- package/dist/schema/typed-object.js.map +1 -1
- package/dist/schema/typed-ref.d.ts +2 -2
- 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 +3 -4
- package/dist/schema/typed-union.d.ts.map +1 -1
- package/dist/schema/typed-union.js +3 -10
- package/dist/schema/typed-union.js.map +1 -1
- package/dist/schema/union.d.ts +2 -2
- 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-object.d.ts +2 -3
- package/dist/schema/unknown-object.d.ts.map +1 -1
- package/dist/schema/unknown-object.js +1 -2
- package/dist/schema/unknown-object.js.map +1 -1
- package/dist/schema/unknown.d.ts +2 -2
- package/dist/schema/unknown.d.ts.map +1 -1
- package/dist/schema/unknown.js +1 -1
- package/dist/schema/unknown.js.map +1 -1
- package/dist/schema.d.ts +4 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +6 -1
- package/dist/schema.js.map +1 -1
- package/dist/util/array-agg.d.ts.map +1 -1
- package/dist/util/array-agg.js +1 -0
- package/dist/util/array-agg.js.map +1 -1
- package/dist/util/lazy-property.d.ts +2 -0
- package/dist/util/lazy-property.d.ts.map +1 -0
- package/dist/util/lazy-property.js +14 -0
- package/dist/util/lazy-property.js.map +1 -0
- package/dist/validation/schema.d.ts +24 -0
- package/dist/validation/schema.d.ts.map +1 -0
- package/dist/validation/schema.js +57 -0
- package/dist/validation/schema.js.map +1 -0
- package/dist/validation/validation-error.d.ts +3 -3
- package/dist/validation/validation-error.d.ts.map +1 -1
- package/dist/validation/validation-error.js +32 -4
- package/dist/validation/validation-error.js.map +1 -1
- package/dist/validation/validation-issue.d.ts +32 -24
- package/dist/validation/validation-issue.d.ts.map +1 -1
- package/dist/validation/validation-issue.js +136 -92
- package/dist/validation/validation-issue.js.map +1 -1
- package/dist/validation/validator.d.ts +20 -50
- package/dist/validation/validator.d.ts.map +1 -1
- package/dist/validation/validator.js +40 -134
- package/dist/validation/validator.js.map +1 -1
- package/dist/validation.d.ts +1 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +1 -0
- package/dist/validation.js.map +1 -1
- package/package.json +8 -4
- package/src/core/$type.ts +7 -4
- package/src/core/record-key.ts +12 -5
- package/src/core/result.ts +6 -0
- package/src/core/string-format.ts +97 -61
- package/src/core/types.ts +12 -6
- package/src/external.ts +92 -70
- package/src/schema/_parameters.test.ts +416 -0
- package/src/schema/array.test.ts +237 -0
- package/src/schema/array.ts +17 -11
- package/src/schema/blob.test.ts +506 -0
- package/src/schema/blob.ts +3 -5
- package/src/schema/boolean.test.ts +116 -0
- package/src/schema/boolean.ts +5 -7
- package/src/schema/bytes.test.ts +226 -0
- package/src/schema/bytes.ts +4 -6
- package/src/schema/cid.test.ts +155 -0
- package/src/schema/cid.ts +14 -8
- package/src/schema/custom.test.ts +413 -0
- package/src/schema/custom.ts +10 -8
- package/src/schema/dict.test.ts +198 -0
- package/src/schema/dict.ts +6 -8
- package/src/schema/discriminated-union.test.ts +675 -0
- package/src/schema/discriminated-union.ts +68 -95
- package/src/schema/enum.test.ts +396 -0
- package/src/schema/enum.ts +12 -5
- package/src/schema/integer.test.ts +312 -0
- package/src/schema/integer.ts +5 -7
- package/src/schema/intersection.test.ts +32 -0
- package/src/schema/intersection.ts +37 -40
- package/src/schema/literal.test.ts +531 -0
- package/src/schema/literal.ts +12 -5
- package/src/schema/never.test.ts +174 -0
- package/src/schema/never.ts +3 -10
- package/src/schema/null.test.ts +79 -0
- package/src/schema/null.ts +3 -5
- package/src/schema/nullable.test.ts +480 -0
- package/src/schema/nullable.ts +23 -0
- package/src/schema/object.test.ts +47 -115
- package/src/schema/object.ts +23 -134
- package/src/schema/optional.test.ts +485 -0
- package/src/schema/optional.ts +31 -0
- package/src/schema/params.test.ts +582 -0
- package/src/schema/params.ts +37 -55
- package/src/schema/payload.test.ts +345 -0
- package/src/schema/payload.ts +5 -5
- package/src/schema/permission-set.test.ts +679 -0
- package/src/schema/permission-set.ts +6 -8
- package/src/schema/permission.test.ts +536 -0
- package/src/schema/permission.ts +0 -2
- package/src/schema/procedure.test.ts +443 -0
- package/src/schema/procedure.ts +11 -13
- package/src/schema/query.test.ts +408 -0
- package/src/schema/query.ts +9 -11
- package/src/schema/record.test.ts +694 -0
- package/src/schema/record.ts +38 -36
- package/src/schema/ref.test.ts +365 -0
- package/src/schema/ref.ts +8 -5
- package/src/schema/refine.test.ts +578 -0
- package/src/schema/refine.ts +85 -0
- package/src/schema/regexp.test.ts +580 -0
- package/src/schema/regexp.ts +22 -0
- package/src/schema/string.test.ts +612 -0
- package/src/schema/string.ts +11 -17
- package/src/schema/subscription.test.ts +689 -0
- package/src/schema/subscription.ts +13 -8
- package/src/schema/token.test.ts +428 -0
- package/src/schema/token.ts +3 -5
- package/src/schema/typed-object.test.ts +612 -0
- package/src/schema/typed-object.ts +23 -20
- package/src/schema/typed-ref.test.ts +823 -0
- package/src/schema/typed-ref.ts +10 -5
- package/src/schema/typed-union.test.ts +378 -0
- package/src/schema/typed-union.ts +6 -15
- package/src/schema/union.test.ts +200 -0
- package/src/schema/union.ts +5 -4
- package/src/schema/unknown-object.test.ts +592 -0
- package/src/schema/unknown-object.ts +3 -5
- package/src/schema/unknown.test.ts +312 -0
- package/src/schema/unknown.ts +3 -3
- package/src/schema.ts +7 -1
- package/src/util/array-agg.ts +1 -0
- package/src/util/lazy-property.ts +14 -0
- package/src/validation/schema.ts +92 -0
- package/src/validation/validation-error.ts +60 -9
- package/src/validation/validation-issue.ts +141 -144
- package/src/validation/validator.ts +67 -206
- package/src/validation.ts +1 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.json +7 -0
- package/tsconfig.tests.json +9 -0
package/src/core/types.ts
CHANGED
|
@@ -6,12 +6,6 @@ export type UnknownString = string & NonNullable<unknown>
|
|
|
6
6
|
|
|
7
7
|
export type Simplify<T> = { [K in keyof T]: T[K] } & NonNullable<unknown>
|
|
8
8
|
|
|
9
|
-
// @NOTE there is no way to express "array containing at least one P", so we use
|
|
10
|
-
// "array that contains P at first or last position" as a workaround.
|
|
11
|
-
export type ArrayContaining<T, Items = unknown> =
|
|
12
|
-
| readonly [T, ...Items[]]
|
|
13
|
-
| readonly [...Items[], T]
|
|
14
|
-
|
|
15
9
|
declare const __restricted: unique symbol
|
|
16
10
|
/**
|
|
17
11
|
* A type that represents a value that cannot be used, with a custom
|
|
@@ -20,3 +14,15 @@ declare const __restricted: unique symbol
|
|
|
20
14
|
export type Restricted<Message extends string> = typeof __restricted & {
|
|
21
15
|
[__restricted]: Message
|
|
22
16
|
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Converts all properties of `P` that are optional (i.e. may be `undefined`)
|
|
20
|
+
* into actual optional properties on the resulting type.
|
|
21
|
+
*/
|
|
22
|
+
export type WithOptionalProperties<P> = Simplify<
|
|
23
|
+
{
|
|
24
|
+
-readonly [K in keyof P as undefined extends P[K] ? never : K]-?: P[K]
|
|
25
|
+
} & {
|
|
26
|
+
-readonly [K in keyof P as undefined extends P[K] ? K : never]?: P[K]
|
|
27
|
+
}
|
|
28
|
+
>
|
package/src/external.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $Type, $type,
|
|
1
|
+
import { $Type, $TypeOf, $type, LexiconRecordKey, NsidString } from './core.js'
|
|
2
2
|
import {
|
|
3
3
|
ArraySchema,
|
|
4
4
|
ArraySchemaOptions,
|
|
@@ -9,25 +9,27 @@ import {
|
|
|
9
9
|
BytesSchema,
|
|
10
10
|
BytesSchemaOptions,
|
|
11
11
|
CidSchema,
|
|
12
|
+
CidSchemaOptions,
|
|
12
13
|
CustomAssertion,
|
|
13
14
|
CustomSchema,
|
|
14
15
|
DictSchema,
|
|
15
16
|
DiscriminatedUnionSchema,
|
|
16
|
-
|
|
17
|
+
DiscriminatedUnionVariants,
|
|
17
18
|
EnumSchema,
|
|
19
|
+
EnumSchemaOptions,
|
|
18
20
|
IntegerSchema,
|
|
19
21
|
IntegerSchemaOptions,
|
|
20
22
|
IntersectionSchema,
|
|
21
|
-
IntersectionSchemaValidators,
|
|
22
23
|
LiteralSchema,
|
|
24
|
+
LiteralSchemaOptions,
|
|
23
25
|
NeverSchema,
|
|
24
26
|
NullSchema,
|
|
27
|
+
NullableSchema,
|
|
25
28
|
ObjectSchema,
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
ObjectSchemaShape,
|
|
30
|
+
OptionalSchema,
|
|
28
31
|
ParamsSchema,
|
|
29
|
-
|
|
30
|
-
ParamsSchemaProperties,
|
|
32
|
+
ParamsSchemaShape,
|
|
31
33
|
Payload,
|
|
32
34
|
PayloadBody,
|
|
33
35
|
Permission,
|
|
@@ -39,6 +41,7 @@ import {
|
|
|
39
41
|
RecordSchema,
|
|
40
42
|
RefSchema,
|
|
41
43
|
RefSchemaGetter,
|
|
44
|
+
RegexpSchema,
|
|
42
45
|
StringSchema,
|
|
43
46
|
StringSchemaOptions,
|
|
44
47
|
Subscription,
|
|
@@ -52,6 +55,7 @@ import {
|
|
|
52
55
|
UnknownObjectOutput,
|
|
53
56
|
UnknownObjectSchema,
|
|
54
57
|
UnknownSchema,
|
|
58
|
+
refine,
|
|
55
59
|
} from './schema.js'
|
|
56
60
|
import { Infer, PropertyKey, Validator } from './validation.js'
|
|
57
61
|
|
|
@@ -79,42 +83,46 @@ export { _null as null }
|
|
|
79
83
|
/*@__NO_SIDE_EFFECTS__*/
|
|
80
84
|
export function literal<const V extends null | string | number | boolean>(
|
|
81
85
|
value: V,
|
|
86
|
+
options?: LiteralSchemaOptions<V>,
|
|
82
87
|
) {
|
|
83
|
-
return new LiteralSchema<V>(value)
|
|
88
|
+
return new LiteralSchema<V>(value, options)
|
|
84
89
|
}
|
|
85
90
|
|
|
86
91
|
/*@__NO_SIDE_EFFECTS__*/
|
|
87
92
|
export function _enum<const V extends null | string | number | boolean>(
|
|
88
93
|
value: readonly V[],
|
|
94
|
+
options?: EnumSchemaOptions<V>,
|
|
89
95
|
) {
|
|
90
|
-
return new EnumSchema<V>(value)
|
|
96
|
+
return new EnumSchema<V>(value, options)
|
|
91
97
|
}
|
|
92
98
|
|
|
93
99
|
// @NOTE "enum" is a reserved keyword in JS/TS
|
|
94
100
|
export { _enum as enum }
|
|
95
101
|
|
|
96
102
|
/*@__NO_SIDE_EFFECTS__*/
|
|
97
|
-
export function boolean(options
|
|
103
|
+
export function boolean(options?: BooleanSchemaOptions) {
|
|
98
104
|
return new BooleanSchema(options)
|
|
99
105
|
}
|
|
100
106
|
|
|
101
107
|
/*@__NO_SIDE_EFFECTS__*/
|
|
102
|
-
export function integer(options
|
|
108
|
+
export function integer(options?: IntegerSchemaOptions) {
|
|
103
109
|
return new IntegerSchema(options)
|
|
104
110
|
}
|
|
105
111
|
|
|
106
112
|
/*@__NO_SIDE_EFFECTS__*/
|
|
107
|
-
export function cidLink() {
|
|
108
|
-
return new CidSchema()
|
|
113
|
+
export function cidLink(options?: CidSchemaOptions) {
|
|
114
|
+
return new CidSchema(options)
|
|
109
115
|
}
|
|
110
116
|
|
|
111
117
|
/*@__NO_SIDE_EFFECTS__*/
|
|
112
|
-
export function bytes(options
|
|
118
|
+
export function bytes(options?: BytesSchemaOptions) {
|
|
113
119
|
return new BytesSchema(options)
|
|
114
120
|
}
|
|
115
121
|
|
|
116
122
|
/*@__NO_SIDE_EFFECTS__*/
|
|
117
|
-
export function blob
|
|
123
|
+
export function blob<O extends BlobSchemaOptions = NonNullable<unknown>>(
|
|
124
|
+
options: O = {} as O,
|
|
125
|
+
) {
|
|
118
126
|
return new BlobSchema(options)
|
|
119
127
|
}
|
|
120
128
|
|
|
@@ -126,29 +134,36 @@ export function string<
|
|
|
126
134
|
}
|
|
127
135
|
|
|
128
136
|
/*@__NO_SIDE_EFFECTS__*/
|
|
129
|
-
export function
|
|
130
|
-
|
|
131
|
-
options: ArraySchemaOptions = {},
|
|
132
|
-
) {
|
|
133
|
-
return new ArraySchema(items, options)
|
|
137
|
+
export function regexp<T extends string = string>(pattern: RegExp) {
|
|
138
|
+
return new RegexpSchema<T>(pattern)
|
|
134
139
|
}
|
|
135
140
|
|
|
136
141
|
/*@__NO_SIDE_EFFECTS__*/
|
|
137
|
-
export function
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
>
|
|
141
|
-
|
|
142
|
-
|
|
142
|
+
export function array<const S extends Validator>(
|
|
143
|
+
items: S,
|
|
144
|
+
options?: ArraySchemaOptions,
|
|
145
|
+
): ArraySchema<S>
|
|
146
|
+
export function array<T, const S extends Validator<T> = Validator<T>>(
|
|
147
|
+
items: S,
|
|
148
|
+
options?: ArraySchemaOptions,
|
|
149
|
+
): ArraySchema<S>
|
|
150
|
+
export function array<const S extends Validator>(
|
|
151
|
+
items: S,
|
|
152
|
+
options?: ArraySchemaOptions,
|
|
143
153
|
) {
|
|
144
|
-
return new
|
|
154
|
+
return new ArraySchema<S>(items, options)
|
|
145
155
|
}
|
|
146
156
|
|
|
147
157
|
/*@__NO_SIDE_EFFECTS__*/
|
|
148
|
-
export function
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
158
|
+
export function object<const P extends ObjectSchemaShape>(properties: P) {
|
|
159
|
+
return new ObjectSchema<P>(properties)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
163
|
+
export function dict<
|
|
164
|
+
const K extends Validator<string>,
|
|
165
|
+
const V extends Validator,
|
|
166
|
+
>(key: K, value: V) {
|
|
152
167
|
return new DictSchema<K, V>(key, value)
|
|
153
168
|
}
|
|
154
169
|
|
|
@@ -174,22 +189,35 @@ export function custom<T>(
|
|
|
174
189
|
return new CustomSchema<T>(assertion, message, path)
|
|
175
190
|
}
|
|
176
191
|
|
|
192
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
193
|
+
export function nullable<const S extends Validator>(schema: S) {
|
|
194
|
+
return new NullableSchema<Infer<S>>(schema)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
198
|
+
export function optional<const S extends Validator>(schema: S) {
|
|
199
|
+
return new OptionalSchema<Infer<S>>(schema)
|
|
200
|
+
}
|
|
201
|
+
|
|
177
202
|
/*@__NO_SIDE_EFFECTS__*/
|
|
178
203
|
export function union<const V extends UnionSchemaValidators>(validators: V) {
|
|
179
204
|
return new UnionSchema<V>(validators)
|
|
180
205
|
}
|
|
181
206
|
|
|
182
207
|
/*@__NO_SIDE_EFFECTS__*/
|
|
183
|
-
export function intersection<
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
208
|
+
export function intersection<
|
|
209
|
+
const Left extends ObjectSchema,
|
|
210
|
+
const Right extends DictSchema,
|
|
211
|
+
>(left: Left, right: Right) {
|
|
212
|
+
return new IntersectionSchema<Left, Right>(left, right)
|
|
187
213
|
}
|
|
188
214
|
|
|
215
|
+
export { refine }
|
|
216
|
+
|
|
189
217
|
/*@__NO_SIDE_EFFECTS__*/
|
|
190
218
|
export function discriminatedUnion<
|
|
191
219
|
const Discriminator extends string,
|
|
192
|
-
const Options extends
|
|
220
|
+
const Options extends DiscriminatedUnionVariants<Discriminator>,
|
|
193
221
|
>(discriminator: Discriminator, variants: Options) {
|
|
194
222
|
return new DiscriminatedUnionSchema<Discriminator, Options>(
|
|
195
223
|
discriminator,
|
|
@@ -198,7 +226,7 @@ export function discriminatedUnion<
|
|
|
198
226
|
}
|
|
199
227
|
|
|
200
228
|
/*@__NO_SIDE_EFFECTS__*/
|
|
201
|
-
export function token<const N extends
|
|
229
|
+
export function token<const N extends NsidString, const H extends string>(
|
|
202
230
|
nsid: N,
|
|
203
231
|
hash: H,
|
|
204
232
|
) {
|
|
@@ -232,11 +260,11 @@ export function typedUnion<
|
|
|
232
260
|
* schemas that work even if they contain circular references.
|
|
233
261
|
*/
|
|
234
262
|
export function typedObject<
|
|
235
|
-
const N extends
|
|
263
|
+
const N extends NsidString,
|
|
236
264
|
const H extends string,
|
|
237
|
-
const
|
|
238
|
-
>(nsid: N, hash: H, schema:
|
|
239
|
-
export function typedObject<
|
|
265
|
+
const S extends Validator<{ [_ in string]?: unknown }>,
|
|
266
|
+
>(nsid: N, hash: H, schema: S): TypedObjectSchema<$Type<N, H>, S>
|
|
267
|
+
export function typedObject<V extends { $type?: $Type }>(
|
|
240
268
|
nsid: V extends { $type?: infer T extends string }
|
|
241
269
|
? T extends `${infer N}#${string}`
|
|
242
270
|
? N
|
|
@@ -248,14 +276,14 @@ export function typedObject<const V extends { $type?: $Type }>(
|
|
|
248
276
|
: 'main'
|
|
249
277
|
: never,
|
|
250
278
|
schema: Validator<Omit<V, '$type'>>,
|
|
251
|
-
): TypedObjectSchema<
|
|
279
|
+
): TypedObjectSchema<$TypeOf<V>, Validator<Omit<V, '$type'>>>
|
|
252
280
|
/*@__NO_SIDE_EFFECTS__*/
|
|
253
281
|
export function typedObject<
|
|
254
|
-
const N extends
|
|
282
|
+
const N extends NsidString,
|
|
255
283
|
const H extends string,
|
|
256
|
-
const
|
|
257
|
-
>(nsid: N, hash: H, schema:
|
|
258
|
-
return new TypedObjectSchema<$Type<N, H>,
|
|
284
|
+
const S extends Validator<{ [_ in string]?: unknown }>,
|
|
285
|
+
>(nsid: N, hash: H, schema: S) {
|
|
286
|
+
return new TypedObjectSchema<$Type<N, H>, S>($type(nsid, hash), schema)
|
|
259
287
|
}
|
|
260
288
|
|
|
261
289
|
/**
|
|
@@ -275,37 +303,32 @@ type AsNsid<T> = T extends `${string}#${string}` ? never : T
|
|
|
275
303
|
* schemas that work even if they contain circular references.
|
|
276
304
|
*/
|
|
277
305
|
export function record<
|
|
278
|
-
const K extends
|
|
279
|
-
const T extends
|
|
306
|
+
const K extends LexiconRecordKey,
|
|
307
|
+
const T extends NsidString,
|
|
280
308
|
const S extends Validator<{ [_ in string]?: unknown }>,
|
|
281
|
-
>(
|
|
282
|
-
key: K,
|
|
283
|
-
type: AsNsid<T>,
|
|
284
|
-
schema: S,
|
|
285
|
-
): RecordSchema<K, T, S, Infer<S> & { $type: T }>
|
|
309
|
+
>(key: K, type: AsNsid<T>, schema: S): RecordSchema<K, T, S>
|
|
286
310
|
export function record<
|
|
287
|
-
const K extends
|
|
288
|
-
const V extends { $type:
|
|
311
|
+
const K extends LexiconRecordKey,
|
|
312
|
+
const V extends { $type: NsidString },
|
|
289
313
|
>(
|
|
290
314
|
key: K,
|
|
291
315
|
type: AsNsid<V['$type']>,
|
|
292
316
|
schema: Validator<Omit<V, '$type'>>,
|
|
293
|
-
): RecordSchema<K, V['$type'],
|
|
317
|
+
): RecordSchema<K, V['$type'], Validator<Omit<V, '$type'>>>
|
|
294
318
|
/*@__NO_SIDE_EFFECTS__*/
|
|
295
319
|
export function record<
|
|
296
|
-
const K extends
|
|
297
|
-
const T extends
|
|
320
|
+
const K extends LexiconRecordKey,
|
|
321
|
+
const T extends NsidString,
|
|
298
322
|
const S extends Validator<{ [_ in string]?: unknown }>,
|
|
299
323
|
>(key: K, type: T, schema: S) {
|
|
300
|
-
return new RecordSchema<K, T, S
|
|
324
|
+
return new RecordSchema<K, T, S>(key, type, schema)
|
|
301
325
|
}
|
|
302
326
|
|
|
303
327
|
/*@__NO_SIDE_EFFECTS__*/
|
|
304
328
|
export function params<
|
|
305
|
-
const P extends
|
|
306
|
-
|
|
307
|
-
>(properties
|
|
308
|
-
return new ParamsSchema<P, O>(properties, options)
|
|
329
|
+
const P extends ParamsSchemaShape = NonNullable<unknown>,
|
|
330
|
+
>(properties: P = {} as P) {
|
|
331
|
+
return new ParamsSchema<P>(properties)
|
|
309
332
|
}
|
|
310
333
|
|
|
311
334
|
/*@__NO_SIDE_EFFECTS__*/
|
|
@@ -318,7 +341,7 @@ export function payload<
|
|
|
318
341
|
|
|
319
342
|
/*@__NO_SIDE_EFFECTS__*/
|
|
320
343
|
export function query<
|
|
321
|
-
const N extends
|
|
344
|
+
const N extends NsidString,
|
|
322
345
|
const P extends ParamsSchema,
|
|
323
346
|
const O extends Payload,
|
|
324
347
|
const E extends undefined | readonly string[] = undefined,
|
|
@@ -328,7 +351,7 @@ export function query<
|
|
|
328
351
|
|
|
329
352
|
/*@__NO_SIDE_EFFECTS__*/
|
|
330
353
|
export function procedure<
|
|
331
|
-
const N extends
|
|
354
|
+
const N extends NsidString,
|
|
332
355
|
const P extends ParamsSchema,
|
|
333
356
|
const I extends Payload,
|
|
334
357
|
const O extends Payload,
|
|
@@ -339,7 +362,7 @@ export function procedure<
|
|
|
339
362
|
|
|
340
363
|
/*@__NO_SIDE_EFFECTS__*/
|
|
341
364
|
export function subscription<
|
|
342
|
-
const N extends
|
|
365
|
+
const N extends NsidString,
|
|
343
366
|
const P extends ParamsSchema,
|
|
344
367
|
const M extends undefined | RefSchema | TypedUnionSchema | ObjectSchema,
|
|
345
368
|
const E extends undefined | readonly string[] = undefined,
|
|
@@ -357,9 +380,8 @@ export function permission<
|
|
|
357
380
|
|
|
358
381
|
/*@__NO_SIDE_EFFECTS__*/
|
|
359
382
|
export function permissionSet<
|
|
360
|
-
const N extends
|
|
383
|
+
const N extends NsidString,
|
|
361
384
|
const P extends readonly Permission[],
|
|
362
|
-
|
|
363
|
-
>(nsid
|
|
364
|
-
return new PermissionSet<N, P, O>(nsid, permissions, options)
|
|
385
|
+
>(nsid: N, permissions: P, options?: PermissionSetOptions) {
|
|
386
|
+
return new PermissionSet<N, P>(nsid, permissions, options)
|
|
365
387
|
}
|