@atproto/lex-schema 0.0.8 → 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.
- package/CHANGELOG.md +41 -0
- package/LICENSE.txt +1 -1
- package/dist/core/$type.d.ts +11 -0
- package/dist/core/$type.d.ts.map +1 -1
- package/dist/core/$type.js +4 -0
- package/dist/core/$type.js.map +1 -1
- package/dist/core/schema.d.ts +31 -24
- package/dist/core/schema.d.ts.map +1 -1
- package/dist/core/schema.js +38 -8
- package/dist/core/schema.js.map +1 -1
- package/dist/core/string-format.d.ts +35 -35
- package/dist/core/string-format.d.ts.map +1 -1
- package/dist/core/string-format.js +49 -91
- package/dist/core/string-format.js.map +1 -1
- package/dist/core/validation-issue.js +1 -1
- package/dist/core/validation-issue.js.map +1 -1
- package/dist/core/validator.d.ts +53 -32
- package/dist/core/validator.d.ts.map +1 -1
- package/dist/core/validator.js +18 -22
- package/dist/core/validator.js.map +1 -1
- package/dist/external.d.ts +0 -85
- package/dist/external.d.ts.map +1 -1
- package/dist/external.js +0 -164
- package/dist/external.js.map +1 -1
- package/dist/helpers.d.ts +10 -5
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +3 -3
- package/dist/helpers.js.map +1 -1
- package/dist/schema/array.d.ts +9 -5
- package/dist/schema/array.d.ts.map +1 -1
- package/dist/schema/array.js +14 -5
- package/dist/schema/array.js.map +1 -1
- package/dist/schema/blob.d.ts +9 -7
- package/dist/schema/blob.d.ts.map +1 -1
- package/dist/schema/blob.js +9 -5
- package/dist/schema/blob.js.map +1 -1
- package/dist/schema/boolean.d.ts +3 -7
- package/dist/schema/boolean.d.ts.map +1 -1
- package/dist/schema/boolean.js +6 -7
- package/dist/schema/boolean.js.map +1 -1
- package/dist/schema/bytes.d.ts +3 -2
- package/dist/schema/bytes.d.ts.map +1 -1
- package/dist/schema/bytes.js +7 -3
- package/dist/schema/bytes.js.map +1 -1
- package/dist/schema/cid.d.ts +10 -8
- package/dist/schema/cid.d.ts.map +1 -1
- package/dist/schema/cid.js +5 -1
- package/dist/schema/cid.js.map +1 -1
- package/dist/schema/custom.d.ts +6 -5
- package/dist/schema/custom.d.ts.map +1 -1
- package/dist/schema/custom.js +10 -4
- package/dist/schema/custom.js.map +1 -1
- package/dist/schema/dict.d.ts +8 -8
- package/dist/schema/dict.d.ts.map +1 -1
- package/dist/schema/dict.js +11 -2
- package/dist/schema/dict.js.map +1 -1
- package/dist/schema/discriminated-union.d.ts +21 -14
- package/dist/schema/discriminated-union.d.ts.map +1 -1
- package/dist/schema/discriminated-union.js +7 -0
- package/dist/schema/discriminated-union.js.map +1 -1
- package/dist/schema/enum.d.ts +7 -9
- package/dist/schema/enum.d.ts.map +1 -1
- package/dist/schema/enum.js +8 -4
- package/dist/schema/enum.js.map +1 -1
- package/dist/schema/integer.d.ts +5 -5
- package/dist/schema/integer.d.ts.map +1 -1
- package/dist/schema/integer.js +9 -5
- package/dist/schema/integer.js.map +1 -1
- package/dist/schema/intersection.d.ts +4 -4
- package/dist/schema/intersection.d.ts.map +1 -1
- package/dist/schema/intersection.js +5 -0
- package/dist/schema/intersection.js.map +1 -1
- package/dist/schema/literal.d.ts +6 -9
- package/dist/schema/literal.d.ts.map +1 -1
- package/dist/schema/literal.js +7 -4
- package/dist/schema/literal.js.map +1 -1
- package/dist/schema/never.d.ts +3 -2
- package/dist/schema/never.d.ts.map +1 -1
- package/dist/schema/never.js +5 -1
- package/dist/schema/never.js.map +1 -1
- package/dist/schema/null.d.ts +4 -3
- package/dist/schema/null.d.ts.map +1 -1
- package/dist/schema/null.js +6 -4
- package/dist/schema/null.js.map +1 -1
- package/dist/schema/nullable.d.ts +6 -5
- package/dist/schema/nullable.d.ts.map +1 -1
- package/dist/schema/nullable.js +9 -5
- package/dist/schema/nullable.js.map +1 -1
- package/dist/schema/object.d.ts +10 -8
- package/dist/schema/object.d.ts.map +1 -1
- package/dist/schema/object.js +11 -3
- package/dist/schema/object.js.map +1 -1
- package/dist/schema/optional.d.ts +7 -5
- package/dist/schema/optional.d.ts.map +1 -1
- package/dist/schema/optional.js +14 -6
- package/dist/schema/optional.js.map +1 -1
- package/dist/schema/params.d.ts +24 -13
- package/dist/schema/params.d.ts.map +1 -1
- package/dist/schema/params.js +47 -25
- package/dist/schema/params.js.map +1 -1
- package/dist/schema/payload.d.ts +12 -9
- package/dist/schema/payload.d.ts.map +1 -1
- package/dist/schema/payload.js +11 -0
- package/dist/schema/payload.js.map +1 -1
- package/dist/schema/permission-set.d.ts +1 -0
- package/dist/schema/permission-set.d.ts.map +1 -1
- package/dist/schema/permission-set.js +5 -0
- package/dist/schema/permission-set.js.map +1 -1
- package/dist/schema/permission.d.ts +6 -5
- package/dist/schema/permission.d.ts.map +1 -1
- package/dist/schema/permission.js +5 -0
- package/dist/schema/permission.js.map +1 -1
- package/dist/schema/procedure.d.ts +2 -1
- package/dist/schema/procedure.d.ts.map +1 -1
- package/dist/schema/procedure.js +5 -0
- package/dist/schema/procedure.js.map +1 -1
- package/dist/schema/query.d.ts +2 -1
- package/dist/schema/query.d.ts.map +1 -1
- package/dist/schema/query.js +5 -0
- package/dist/schema/query.js.map +1 -1
- package/dist/schema/record.d.ts +48 -30
- package/dist/schema/record.d.ts.map +1 -1
- package/dist/schema/record.js +12 -9
- package/dist/schema/record.js.map +1 -1
- package/dist/schema/ref.d.ts +9 -6
- package/dist/schema/ref.d.ts.map +1 -1
- package/dist/schema/ref.js +9 -16
- package/dist/schema/ref.js.map +1 -1
- package/dist/schema/refine.d.ts +4 -4
- package/dist/schema/refine.d.ts.map +1 -1
- package/dist/schema/refine.js.map +1 -1
- package/dist/schema/regexp.d.ts +4 -3
- package/dist/schema/regexp.d.ts.map +1 -1
- package/dist/schema/regexp.js +5 -0
- package/dist/schema/regexp.js.map +1 -1
- package/dist/schema/string.d.ts +7 -8
- package/dist/schema/string.d.ts.map +1 -1
- package/dist/schema/string.js +13 -19
- package/dist/schema/string.js.map +1 -1
- package/dist/schema/subscription.d.ts +2 -1
- package/dist/schema/subscription.d.ts.map +1 -1
- package/dist/schema/subscription.js +5 -0
- package/dist/schema/subscription.js.map +1 -1
- package/dist/schema/token.d.ts +6 -5
- package/dist/schema/token.d.ts.map +1 -1
- package/dist/schema/token.js +5 -0
- package/dist/schema/token.js.map +1 -1
- package/dist/schema/typed-object.d.ts +43 -26
- package/dist/schema/typed-object.d.ts.map +1 -1
- package/dist/schema/typed-object.js +6 -3
- package/dist/schema/typed-object.js.map +1 -1
- package/dist/schema/typed-ref.d.ts +16 -25
- package/dist/schema/typed-ref.d.ts.map +1 -1
- package/dist/schema/typed-ref.js +7 -17
- package/dist/schema/typed-ref.js.map +1 -1
- package/dist/schema/typed-union.d.ts +9 -21
- package/dist/schema/typed-union.d.ts.map +1 -1
- package/dist/schema/typed-union.js +15 -11
- package/dist/schema/typed-union.js.map +1 -1
- package/dist/schema/union.d.ts +6 -6
- package/dist/schema/union.d.ts.map +1 -1
- package/dist/schema/union.js +7 -5
- package/dist/schema/union.js.map +1 -1
- package/dist/schema/unknown-object.d.ts +5 -4
- package/dist/schema/unknown-object.d.ts.map +1 -1
- package/dist/schema/unknown-object.js +5 -1
- package/dist/schema/unknown-object.js.map +1 -1
- package/dist/schema/unknown.d.ts +3 -2
- package/dist/schema/unknown.d.ts.map +1 -1
- package/dist/schema/unknown.js +5 -1
- package/dist/schema/unknown.js.map +1 -1
- package/dist/schema/with-default.d.ts +9 -0
- package/dist/schema/with-default.d.ts.map +1 -0
- package/dist/schema/with-default.js +27 -0
- package/dist/schema/with-default.js.map +1 -0
- package/dist/schema.d.ts +2 -2
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +2 -4
- package/dist/schema.js.map +1 -1
- package/dist/util/assertion-util.d.ts +0 -6
- package/dist/util/assertion-util.d.ts.map +1 -1
- package/dist/util/assertion-util.js +0 -28
- package/dist/util/assertion-util.js.map +1 -1
- package/dist/util/memoize.d.ts +2 -2
- package/dist/util/memoize.d.ts.map +1 -1
- package/dist/util/memoize.js +23 -39
- package/dist/util/memoize.js.map +1 -1
- package/package.json +3 -3
- package/src/core/$type.test.ts +20 -0
- package/src/core/$type.ts +30 -0
- package/src/core/schema.ts +86 -38
- package/src/core/string-format.ts +119 -158
- package/src/core/validation-issue.ts +1 -1
- package/src/core/validator.ts +93 -53
- package/src/external.ts +0 -404
- package/src/helpers.test.ts +22 -21
- package/src/helpers.ts +14 -14
- package/src/schema/array.test.ts +38 -40
- package/src/schema/array.ts +35 -13
- package/src/schema/blob.test.ts +21 -21
- package/src/schema/blob.ts +19 -17
- package/src/schema/boolean.test.ts +9 -8
- package/src/schema/boolean.ts +7 -13
- package/src/schema/bytes.test.ts +13 -13
- package/src/schema/bytes.ts +13 -8
- package/src/schema/cid.test.ts +3 -3
- package/src/schema/cid.ts +15 -13
- package/src/schema/custom.test.ts +26 -26
- package/src/schema/custom.ts +20 -13
- package/src/schema/dict.test.ts +21 -39
- package/src/schema/dict.ts +28 -19
- package/src/schema/discriminated-union.test.ts +128 -128
- package/src/schema/discriminated-union.ts +45 -26
- package/src/schema/enum.test.ts +17 -16
- package/src/schema/enum.ts +16 -16
- package/src/schema/integer.test.ts +22 -21
- package/src/schema/integer.ts +12 -9
- package/src/schema/intersection.test.ts +10 -10
- package/src/schema/intersection.ts +17 -14
- package/src/schema/literal.test.ts +35 -34
- package/src/schema/literal.ts +12 -15
- package/src/schema/never.test.ts +5 -5
- package/src/schema/never.ts +7 -2
- package/src/schema/null.test.ts +3 -3
- package/src/schema/null.ts +9 -9
- package/src/schema/nullable.test.ts +31 -42
- package/src/schema/nullable.ts +17 -9
- package/src/schema/object.test.ts +10 -12
- package/src/schema/object.ts +27 -18
- package/src/schema/optional.test.ts +21 -28
- package/src/schema/optional.ts +27 -10
- package/src/schema/params.test.ts +471 -47
- package/src/schema/params.ts +72 -38
- package/src/schema/payload.test.ts +150 -156
- package/src/schema/payload.ts +35 -19
- package/src/schema/permission-set.test.ts +206 -273
- package/src/schema/permission-set.ts +8 -0
- package/src/schema/permission.test.ts +177 -177
- package/src/schema/permission.ts +13 -5
- package/src/schema/procedure.test.ts +183 -242
- package/src/schema/procedure.ts +18 -5
- package/src/schema/query.test.ts +186 -200
- package/src/schema/query.ts +16 -4
- package/src/schema/record.test.ts +121 -101
- package/src/schema/record.ts +74 -40
- package/src/schema/ref.test.ts +101 -118
- package/src/schema/ref.ts +33 -28
- package/src/schema/refine.test.ts +28 -28
- package/src/schema/refine.ts +23 -20
- package/src/schema/regexp.test.ts +29 -33
- package/src/schema/regexp.ts +11 -7
- package/src/schema/string.test.ts +35 -35
- package/src/schema/string.ts +24 -33
- package/src/schema/subscription.test.ts +259 -387
- package/src/schema/subscription.ts +16 -4
- package/src/schema/token.test.ts +47 -324
- package/src/schema/token.ts +14 -7
- package/src/schema/typed-object.test.ts +98 -81
- package/src/schema/typed-object.ts +68 -33
- package/src/schema/typed-ref.test.ts +206 -234
- package/src/schema/typed-ref.ts +40 -42
- package/src/schema/typed-union.test.ts +40 -64
- package/src/schema/typed-union.ts +36 -58
- package/src/schema/union.test.ts +17 -27
- package/src/schema/union.ts +20 -16
- package/src/schema/unknown-object.test.ts +8 -8
- package/src/schema/unknown-object.ts +9 -7
- package/src/schema/unknown.test.ts +4 -4
- package/src/schema/unknown.ts +7 -5
- package/src/schema/with-default.ts +35 -0
- package/src/schema.ts +2 -6
- package/src/util/assertion-util.ts +0 -39
- package/src/util/memoize.ts +26 -46
- package/dist/schema/_parameters.d.ts +0 -17
- package/dist/schema/_parameters.d.ts.map +0 -1
- package/dist/schema/_parameters.js +0 -20
- package/dist/schema/_parameters.js.map +0 -1
- package/src/schema/_parameters.test.ts +0 -417
- package/src/schema/_parameters.ts +0 -26
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# @atproto/lex-schema
|
|
2
2
|
|
|
3
|
+
## 0.0.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#4571](https://github.com/bluesky-social/atproto/pull/4571) [`99963d0`](https://github.com/bluesky-social/atproto/commit/99963d002a9e030e79aed5fba700e0a68f31e101) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Remove `asX` and `assertX` string format assertion utilities
|
|
8
|
+
|
|
9
|
+
- [#4562](https://github.com/bluesky-social/atproto/pull/4562) [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Memoize array schemas (without options)
|
|
10
|
+
|
|
11
|
+
- [#4562](https://github.com/bluesky-social/atproto/pull/4562) [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Remove `default` option from `string`, `integer`, `boolean`, `enum` and `literal` types. These are replace with a new `withDefault()` type wrapper.
|
|
12
|
+
|
|
13
|
+
- [#4562](https://github.com/bluesky-social/atproto/pull/4562) [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - `TypedObject` and `Record`'s `build()` method now performs parsing of the input data (ensuring that defaults are applied).
|
|
14
|
+
|
|
15
|
+
- [#4562](https://github.com/bluesky-social/atproto/pull/4562) [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Rename `TypedObject` to `Unknown$TypedObject`
|
|
16
|
+
|
|
17
|
+
- [#4562](https://github.com/bluesky-social/atproto/pull/4562) [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Distinguish "parse" and "validation" modes when checking against a schema. Validation (`validate()` and `safeValidate()`) only ensures that a value matches the input schema, while parsing (`parse()` and `safeParse()`) will also apply defaults and coerce input values into the expected output type.
|
|
18
|
+
|
|
19
|
+
- [#4562](https://github.com/bluesky-social/atproto/pull/4562) [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Rename `cidLink()` to `cid()`
|
|
20
|
+
|
|
21
|
+
- [#4562](https://github.com/bluesky-social/atproto/pull/4562) [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Memoize empty `params` schemas
|
|
22
|
+
|
|
23
|
+
- [#4571](https://github.com/bluesky-social/atproto/pull/4571) [`99963d0`](https://github.com/bluesky-social/atproto/commit/99963d002a9e030e79aed5fba700e0a68f31e101) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Improve performance of string format checking
|
|
24
|
+
|
|
25
|
+
- [#4562](https://github.com/bluesky-social/atproto/pull/4562) [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Fix inability to assign (object containing) open union results to `LexMap` type
|
|
26
|
+
|
|
27
|
+
- [#4562](https://github.com/bluesky-social/atproto/pull/4562) [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add new `Unknown$Type` type to represent records an object's unknown `$type` property (typically from open unions).
|
|
28
|
+
|
|
29
|
+
- [#4562](https://github.com/bluesky-social/atproto/pull/4562) [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Rename `UnknownObjectOutput` to `UnknownObject`
|
|
30
|
+
|
|
31
|
+
- [#4562](https://github.com/bluesky-social/atproto/pull/4562) [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Fail early when validating nested structures
|
|
32
|
+
|
|
33
|
+
- Updated dependencies [[`99963d0`](https://github.com/bluesky-social/atproto/commit/99963d002a9e030e79aed5fba700e0a68f31e101), [`99963d0`](https://github.com/bluesky-social/atproto/commit/99963d002a9e030e79aed5fba700e0a68f31e101), [`99963d0`](https://github.com/bluesky-social/atproto/commit/99963d002a9e030e79aed5fba700e0a68f31e101), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`99963d0`](https://github.com/bluesky-social/atproto/commit/99963d002a9e030e79aed5fba700e0a68f31e101), [`99963d0`](https://github.com/bluesky-social/atproto/commit/99963d002a9e030e79aed5fba700e0a68f31e101), [`99963d0`](https://github.com/bluesky-social/atproto/commit/99963d002a9e030e79aed5fba700e0a68f31e101)]:
|
|
34
|
+
- @atproto/syntax@0.4.3
|
|
35
|
+
- @atproto/lex-data@0.0.9
|
|
36
|
+
|
|
37
|
+
## 0.0.9
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- Updated dependencies [[`dfd4bee`](https://github.com/bluesky-social/atproto/commit/dfd4bee4abbc1a3e53531bb499a6f3169c13ed9e), [`dfd4bee`](https://github.com/bluesky-social/atproto/commit/dfd4bee4abbc1a3e53531bb499a6f3169c13ed9e), [`dfd4bee`](https://github.com/bluesky-social/atproto/commit/dfd4bee4abbc1a3e53531bb499a6f3169c13ed9e), [`dfd4bee`](https://github.com/bluesky-social/atproto/commit/dfd4bee4abbc1a3e53531bb499a6f3169c13ed9e)]:
|
|
42
|
+
- @atproto/lex-data@0.0.8
|
|
43
|
+
|
|
3
44
|
## 0.0.8
|
|
4
45
|
|
|
5
46
|
### Patch Changes
|
package/LICENSE.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Dual MIT/Apache-2.0 License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2022-
|
|
3
|
+
Copyright (c) 2022-2026 Bluesky Social PBC, and Contributors
|
|
4
4
|
|
|
5
5
|
Except as otherwise noted in individual files, this software is licensed under the MIT license (<http://opensource.org/licenses/MIT>), or the Apache License, Version 2.0 (<http://www.apache.org/licenses/LICENSE-2.0>).
|
|
6
6
|
|
package/dist/core/$type.d.ts
CHANGED
|
@@ -8,10 +8,21 @@ export declare function $type<N extends NsidString, H extends string>(nsid: N, h
|
|
|
8
8
|
export type $Typed<V, T extends string = string> = Simplify<V & {
|
|
9
9
|
$type: T;
|
|
10
10
|
}>;
|
|
11
|
+
export declare function $typed<V extends {
|
|
12
|
+
$type?: unknown;
|
|
13
|
+
}, T extends string>(value: V, $type: T): $Typed<V, T>;
|
|
11
14
|
export type $TypedMaybe<V, T extends string = string> = Simplify<V & {
|
|
12
15
|
$type?: T;
|
|
13
16
|
}>;
|
|
14
17
|
export type Un$Typed<V extends {
|
|
15
18
|
$type?: string;
|
|
16
19
|
}> = OmitKey<V, '$type'>;
|
|
20
|
+
declare const unknown$TypeSymbol: unique symbol;
|
|
21
|
+
export type Unknown$Type = string & {
|
|
22
|
+
[unknown$TypeSymbol]: true;
|
|
23
|
+
};
|
|
24
|
+
export type Unknown$TypedObject = {
|
|
25
|
+
$type: Unknown$Type;
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
17
28
|
//# sourceMappingURL=$type.d.ts.map
|
package/dist/core/$type.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"$type.d.ts","sourceRoot":"","sources":["../../src/core/$type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE9C,MAAM,MAAM,KAAK,CACf,CAAC,SAAS,UAAU,GAAG,UAAU,EACjC,CAAC,SAAS,MAAM,GAAG,MAAM,IACvB,CAAC,SAAS,UAAU,GACpB,MAAM,SAAS,CAAC,GACd,CAAC,GAAG,GAAG,CAAC,IAAI,MAAM,EAAE,GACpB,CAAC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.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.$type = $type;
|
|
4
|
+
exports.$typed = $typed;
|
|
4
5
|
/*@__NO_SIDE_EFFECTS__*/
|
|
5
6
|
function $type(nsid, hash) {
|
|
6
7
|
return (hash === 'main' ? nsid : `${nsid}#${hash}`);
|
|
7
8
|
}
|
|
9
|
+
function $typed(value, $type) {
|
|
10
|
+
return value.$type === $type ? value : { ...value, $type };
|
|
11
|
+
}
|
|
8
12
|
//# sourceMappingURL=$type.js.map
|
package/dist/core/$type.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"$type.js","sourceRoot":"","sources":["../../src/core/$type.ts"],"names":[],"mappings":";;AAiBA,sBAKC;
|
|
1
|
+
{"version":3,"file":"$type.js","sourceRoot":"","sources":["../../src/core/$type.ts"],"names":[],"mappings":";;AAiBA,sBAKC;AAQD,wBAKC;AAnBD,wBAAwB;AACxB,SAAgB,KAAK,CACnB,IAAO,EACP,IAAO;IAEP,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAgB,CAAA;AACpE,CAAC;AAQD,SAAgB,MAAM,CACpB,KAAQ,EACR,KAAQ;IAER,OAAO,KAAK,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC,CAAE,KAAsB,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,CAAA;AAC9E,CAAC","sourcesContent":["import { NsidString } from './string-format.js'\nimport { OmitKey, Simplify } from './types.js'\n\nexport type $Type<\n N extends NsidString = NsidString,\n H extends string = string,\n> = N extends NsidString\n ? string extends H\n ? N | `${N}#${string}`\n : H extends 'main'\n ? N\n : `${N}#${H}`\n : never\n\nexport type $TypeOf<O extends { $type?: string }> = NonNullable<O['$type']>\n\n/*@__NO_SIDE_EFFECTS__*/\nexport function $type<N extends NsidString, H extends string>(\n nsid: N,\n hash: H,\n): $Type<N, H> {\n return (hash === 'main' ? nsid : `${nsid}#${hash}`) as $Type<N, H>\n}\n\nexport type $Typed<V, T extends string = string> = Simplify<\n V & {\n $type: T\n }\n>\n\nexport function $typed<V extends { $type?: unknown }, T extends string>(\n value: V,\n $type: T,\n): $Typed<V, T> {\n return value.$type === $type ? (value as $Typed<V, T>) : { ...value, $type }\n}\n\nexport type $TypedMaybe<V, T extends string = string> = Simplify<\n V & {\n $type?: T\n }\n>\n\nexport type Un$Typed<V extends { $type?: string }> = OmitKey<V, '$type'>\n\ndeclare const unknown$TypeSymbol: unique symbol\nexport type Unknown$Type = string & { [unknown$TypeSymbol]: true }\n\n// In order to prevent places that expect a union of known and unknown $typed\n// objects (like lexicons schema open unions), from accepting an invalid version\n// of the known $typed objects, we need to prevent any other properties from\n// being present.\n//\n// For example, if we expect:\n// ```ts\n// type MyOpenUnion = { $type: 'A'; a: number } | Unknown$TypedObject\n// ```\n// we want to make that that the following is rejected:\n// ```ts\n// { $type: 'A' }\n// ```\n//\n// If we typed `Unknown$TypedObject` as `{ $type: string }`, `{ $type: 'A' }`\n// would be a valid `MyOpenUnion` as it would match the `Unknown$TypedObject`.\n// By using a $type property that uniquely describes unknown values, we ensure\n// that only valid known typed objects, or a type casted value, can be used.\nexport type Unknown$TypedObject = { $type: Unknown$Type }\n"]}
|
package/dist/core/schema.d.ts
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import { ValidationOptions, ValidationResult, Validator
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { InferInput, InferOutput, ValidationContext, ValidationOptions, ValidationResult, Validator } from './validator.js';
|
|
2
|
+
type ParseOptions = Omit<ValidationOptions, 'mode'>;
|
|
3
|
+
type ValidateOptions = Omit<ValidationOptions, 'mode'>;
|
|
4
|
+
export interface SchemaInternals<out TInput = unknown, out TOutput = TInput> {
|
|
5
|
+
/** @internal The inferred validation type */
|
|
6
|
+
input: TInput;
|
|
7
|
+
/** @internal The inferred parse type */
|
|
8
|
+
output: TOutput;
|
|
9
|
+
}
|
|
10
|
+
export declare abstract class Schema<out TInput = unknown, out TOutput = TInput, out TInternals extends SchemaInternals<TInput, TOutput> = SchemaInternals<TInput, TOutput>> implements Validator<TInternals['input'], TInternals['output']> {
|
|
11
|
+
readonly ['__lex']: TInternals;
|
|
12
|
+
abstract validateInContext(input: unknown, ctx: ValidationContext): ValidationResult;
|
|
7
13
|
/**
|
|
8
14
|
* @note use {@link check}() instead of {@link assert}() if you encounter a
|
|
9
15
|
* `ts(2775)` error and you are not able to fully type the validator. This
|
|
10
16
|
* will typically arise in generic contexts, where the narrowed type is not
|
|
11
17
|
* needed.
|
|
12
18
|
*/
|
|
13
|
-
assert(input: unknown): asserts input is
|
|
19
|
+
assert(input: unknown): asserts input is InferInput<this>;
|
|
14
20
|
/**
|
|
15
21
|
* Alias for {@link assert}(). Most useful in generic contexts where the
|
|
16
22
|
* validator is not exactly typed, allowing to avoid "_Assertions require
|
|
@@ -21,23 +27,24 @@ export declare abstract class Schema<Output = any> implements Validator<Output>
|
|
|
21
27
|
/**
|
|
22
28
|
* Casts the input (by validating it) to the output type if it matches the
|
|
23
29
|
* schema, otherwise throws. This is the same as calling {@link parse}() with
|
|
24
|
-
* `
|
|
30
|
+
* `mode: "validate"`.
|
|
25
31
|
*/
|
|
26
|
-
cast<I>(input: I): I &
|
|
27
|
-
matches(input:
|
|
28
|
-
ifMatches<I>(input: I): (I &
|
|
29
|
-
parse
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
$
|
|
38
|
-
$
|
|
39
|
-
$
|
|
40
|
-
$
|
|
41
|
-
$
|
|
32
|
+
cast<I>(input: I): I & InferInput<this>;
|
|
33
|
+
matches<I>(input: I): input is I & InferInput<this>;
|
|
34
|
+
ifMatches<I>(input: I): (I & InferInput<this>) | undefined;
|
|
35
|
+
parse(input: unknown, options?: ParseOptions): InferOutput<this>;
|
|
36
|
+
safeParse(input: unknown, options?: ParseOptions): ValidationResult<InferOutput<this>>;
|
|
37
|
+
validate<I>(input: I, options?: ValidateOptions): I & InferInput<this>;
|
|
38
|
+
safeValidate<I>(input: I, options?: ValidateOptions): ValidationResult<I & InferInput<this>>;
|
|
39
|
+
$assert(input: unknown): asserts input is InferInput<this>;
|
|
40
|
+
$check(input: unknown): void;
|
|
41
|
+
$cast<I>(input: I): I & InferInput<this>;
|
|
42
|
+
$matches(input: unknown): input is InferInput<this>;
|
|
43
|
+
$ifMatches<I>(input: I): (I & InferInput<this>) | undefined;
|
|
44
|
+
$parse(input: unknown, options?: ValidateOptions): InferOutput<this>;
|
|
45
|
+
$safeParse(input: unknown, options?: ValidateOptions): ValidationResult<InferOutput<this>>;
|
|
46
|
+
$validate<I>(input: I, options?: ValidateOptions): I & InferInput<this>;
|
|
47
|
+
$safeValidate<I>(input: I, options?: ValidateOptions): ValidationResult<I & InferInput<this>>;
|
|
42
48
|
}
|
|
49
|
+
export {};
|
|
43
50
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/core/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,SAAS,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/core/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,SAAS,EACV,MAAM,gBAAgB,CAAA;AAEvB,KAAK,YAAY,GAAG,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAA;AACnD,KAAK,eAAe,GAAG,IAAI,CAAC,iBAAiB,EAAE,MAAM,CA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AC,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;CAG1C"}
|
package/dist/core/schema.js
CHANGED
|
@@ -10,7 +10,7 @@ class Schema {
|
|
|
10
10
|
* needed.
|
|
11
11
|
*/
|
|
12
12
|
assert(input) {
|
|
13
|
-
const result =
|
|
13
|
+
const result = validator_js_1.ValidationContext.validate(input, this);
|
|
14
14
|
if (!result.success)
|
|
15
15
|
throw result.reason;
|
|
16
16
|
}
|
|
@@ -26,13 +26,16 @@ class Schema {
|
|
|
26
26
|
/**
|
|
27
27
|
* Casts the input (by validating it) to the output type if it matches the
|
|
28
28
|
* schema, otherwise throws. This is the same as calling {@link parse}() with
|
|
29
|
-
* `
|
|
29
|
+
* `mode: "validate"`.
|
|
30
30
|
*/
|
|
31
31
|
cast(input) {
|
|
32
|
-
|
|
32
|
+
const result = validator_js_1.ValidationContext.validate(input, this);
|
|
33
|
+
if (result.success)
|
|
34
|
+
return result.value;
|
|
35
|
+
throw result.reason;
|
|
33
36
|
}
|
|
34
37
|
matches(input) {
|
|
35
|
-
const result =
|
|
38
|
+
const result = validator_js_1.ValidationContext.validate(input, this);
|
|
36
39
|
return result.success;
|
|
37
40
|
}
|
|
38
41
|
ifMatches(input) {
|
|
@@ -40,12 +43,27 @@ class Schema {
|
|
|
40
43
|
}
|
|
41
44
|
parse(input, options) {
|
|
42
45
|
const result = this.safeParse(input, options);
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
if (result.success)
|
|
47
|
+
return result.value;
|
|
48
|
+
throw result.reason;
|
|
46
49
|
}
|
|
47
50
|
safeParse(input, options) {
|
|
48
|
-
return validator_js_1.
|
|
51
|
+
return validator_js_1.ValidationContext.validate(input, this, {
|
|
52
|
+
...options,
|
|
53
|
+
mode: 'parse',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
validate(input, options) {
|
|
57
|
+
const result = this.safeValidate(input, options);
|
|
58
|
+
if (result.success)
|
|
59
|
+
return result.value;
|
|
60
|
+
throw result.reason;
|
|
61
|
+
}
|
|
62
|
+
safeValidate(input, options) {
|
|
63
|
+
return validator_js_1.ValidationContext.validate(input, this, {
|
|
64
|
+
...options,
|
|
65
|
+
mode: 'validate',
|
|
66
|
+
});
|
|
49
67
|
}
|
|
50
68
|
// @NOTE The built lexicons namespaces will export utility functions that
|
|
51
69
|
// allow accessing the schema's methods without the need to specify ".main."
|
|
@@ -63,6 +81,12 @@ class Schema {
|
|
|
63
81
|
$assert(input) {
|
|
64
82
|
return this.assert(input);
|
|
65
83
|
}
|
|
84
|
+
$check(input) {
|
|
85
|
+
return this.check(input);
|
|
86
|
+
}
|
|
87
|
+
$cast(input) {
|
|
88
|
+
return this.cast(input);
|
|
89
|
+
}
|
|
66
90
|
$matches(input) {
|
|
67
91
|
return this.matches(input);
|
|
68
92
|
}
|
|
@@ -75,6 +99,12 @@ class Schema {
|
|
|
75
99
|
$safeParse(input, options) {
|
|
76
100
|
return this.safeParse(input, options);
|
|
77
101
|
}
|
|
102
|
+
$validate(input, options) {
|
|
103
|
+
return this.validate(input, options);
|
|
104
|
+
}
|
|
105
|
+
$safeValidate(input, options) {
|
|
106
|
+
return this.safeValidate(input, options);
|
|
107
|
+
}
|
|
78
108
|
}
|
|
79
109
|
exports.Schema = Schema;
|
|
80
110
|
//# sourceMappingURL=schema.js.map
|
package/dist/core/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/core/schema.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/core/schema.ts"],"names":[],"mappings":";;;AAAA,iDAOuB;AAavB,MAAsB,MAAM;IAgB1B;;;;;OAKG;IACH,MAAM,CAAC,KAAc;QACnB,MAAM,MAAM,GAAG,gCAAiB,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QACtD,IAAI,CAAC,MAAM,CAAC,OAAO;YAAE,MAAM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AAa,CACX,KAAQ,EACR,OAAyB;QAEzB,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IAC1C,CAAC;CACF;AAhJD,wBAgJC","sourcesContent":["import {\n InferInput,\n InferOutput,\n ValidationContext,\n ValidationOptions,\n ValidationResult,\n Validator,\n} from './validator.js'\n\ntype ParseOptions = Omit<ValidationOptions, 'mode'>\ntype ValidateOptions = Omit<ValidationOptions, 'mode'>\n\nexport interface SchemaInternals<out TInput = unknown, out TOutput = TInput> {\n /** @internal The inferred validation type */\n input: TInput\n\n /** @internal The inferred parse type */\n output: TOutput\n}\n\nexport abstract class Schema<\n out TInput = unknown,\n out TOutput = TInput,\n out TInternals extends SchemaInternals<TInput, TOutput> = SchemaInternals<\n TInput,\n TOutput\n >,\n> implements Validator<TInternals['input'], TInternals['output']>\n{\n declare readonly ['__lex']: TInternals\n\n abstract validateInContext(\n input: unknown,\n ctx: ValidationContext,\n ): ValidationResult\n\n /**\n * @note use {@link check}() instead of {@link assert}() if you encounter a\n * `ts(2775)` error and you are not able to fully type the validator. This\n * will typically arise in generic contexts, where the narrowed type is not\n * needed.\n */\n assert(input: unknown): asserts input is InferInput<this> {\n const result = ValidationContext.validate(input, this)\n if (!result.success) throw result.reason\n }\n\n /**\n * Alias for {@link assert}(). Most useful in generic contexts where the\n * validator is not exactly typed, allowing to avoid \"_Assertions require\n * every name in the call target to be declared with an explicit type\n * annotation. ts(2775)_\" errors.\n */\n check(input: unknown): void {\n this.assert(input)\n }\n\n /**\n * Casts the input (by validating it) to the output type if it matches the\n * schema, otherwise throws. This is the same as calling {@link parse}() with\n * `mode: \"validate\"`.\n */\n cast<I>(input: I): I & InferInput<this> {\n const result = ValidationContext.validate(input, this)\n if (result.success) return result.value\n throw result.reason\n }\n\n matches<I>(input: I): input is I & InferInput<this> {\n const result = ValidationContext.validate(input, this)\n return result.success\n }\n\n ifMatches<I>(input: I): (I & InferInput<this>) | undefined {\n return this.matches(input) ? input : undefined\n }\n\n parse(input: unknown, options?: ParseOptions): InferOutput<this> {\n const result = this.safeParse(input, options)\n if (result.success) return result.value\n throw result.reason\n }\n\n safeParse(\n input: unknown,\n options?: ParseOptions,\n ): ValidationResult<InferOutput<this>> {\n return ValidationContext.validate(input, this, {\n ...options,\n mode: 'parse',\n })\n }\n\n validate<I>(input: I, options?: ValidateOptions): I & InferInput<this> {\n const result = this.safeValidate(input, options)\n if (result.success) return result.value\n throw result.reason\n }\n\n safeValidate<I>(\n input: I,\n options?: ValidateOptions,\n ): ValidationResult<I & InferInput<this>> {\n return ValidationContext.validate(input, this, {\n ...options,\n mode: 'validate',\n })\n }\n\n // @NOTE The built lexicons namespaces will export utility functions that\n // allow accessing the schema's methods without the need to specify \".main.\"\n // as part of the namespace. This way, a utility for a particular record type\n // can be called like \"app.bsky.feed.post.<utility>()\" instead of\n // \"app.bsky.feed.post.main.<utility>()\". Because those utilities could\n // conflict with other schemas (e.g. if there is a lexicon definition at\n // \"#<utility>\"), those exported utilities will be prefixed with \"$\". In order\n // to be able to consistently call the utilities, when using the \"main\" and\n // non \"main\" definitions, we also expose the same methods with a \"$\" prefix.\n // Thanks to this, both of the following call will be possible:\n //\n // - \"app.bsky.feed.post.$parse(...)\" // calls a utility function created by \"lex build\"\n // - \"app.bsky.feed.defs.postView.$parse(...)\" // uses the alias defined below on the schema instance\n\n $assert(input: unknown): asserts input is InferInput<this> {\n return this.assert(input)\n }\n\n $check(input: unknown): void {\n return this.check(input)\n }\n\n $cast<I>(input: I): I & InferInput<this> {\n return this.cast(input)\n }\n\n $matches(input: unknown): input is InferInput<this> {\n return this.matches(input)\n }\n\n $ifMatches<I>(input: I): (I & InferInput<this>) | undefined {\n return this.ifMatches(input)\n }\n\n $parse(input: unknown, options?: ValidateOptions): InferOutput<this> {\n return this.parse(input, options)\n }\n\n $safeParse(\n input: unknown,\n options?: ValidateOptions,\n ): ValidationResult<InferOutput<this>> {\n return this.safeParse(input, options)\n }\n\n $validate<I>(input: I, options?: ValidateOptions): I & InferInput<this> {\n return this.validate(input, options)\n }\n\n $safeValidate<I>(\n input: I,\n options?: ValidateOptions,\n ): ValidationResult<I & InferInput<this>> {\n return this.safeValidate(input, options)\n }\n}\n"]}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export type CidString = string;
|
|
5
|
-
export type LanguageString = string;
|
|
6
|
-
export type UriString = `${string}:${string}`;
|
|
7
|
-
export declare function isUriString<T extends string>(input: T): input is T & UriString;
|
|
8
|
-
export type { AtIdentifierString, AtUriString, DatetimeString, DidString, HandleString, NsidString, RecordKeyString, TidString, } from '@atproto/syntax';
|
|
9
|
-
export declare const assertAtIdentifierString: AssertFn<AtIdentifierString>;
|
|
10
|
-
export declare const assertAtUriString: AssertFn<AtUriString>;
|
|
11
|
-
export declare const assertCidString: AssertFn<CidString>;
|
|
12
|
-
export declare const assertDatetimeString: AssertFn<DatetimeString>;
|
|
13
|
-
export declare const assertDidString: AssertFn<DidString>;
|
|
14
|
-
export declare const assertHandleString: AssertFn<HandleString>;
|
|
15
|
-
export declare const assertLanguageString: AssertFn<LanguageString>;
|
|
16
|
-
export declare const assertNsidString: AssertFn<NsidString>;
|
|
17
|
-
export declare const assertRecordKeyString: AssertFn<RecordKeyString>;
|
|
18
|
-
export declare const assertTidString: AssertFn<TidString>;
|
|
19
|
-
export declare const assertUriString: AssertFn<UriString>;
|
|
20
|
-
export declare const asAtIdentifierString: CastFn<AtIdentifierString>;
|
|
21
|
-
export declare const asAtUriString: CastFn<AtUriString>;
|
|
22
|
-
export declare const asCidString: CastFn<CidString>;
|
|
23
|
-
export declare const asDatetimeString: CastFn<DatetimeString>;
|
|
24
|
-
export declare const asDidString: CastFn<DidString>;
|
|
25
|
-
export declare const asHandleString: CastFn<HandleString>;
|
|
26
|
-
export declare const asLanguageString: CastFn<LanguageString>;
|
|
27
|
-
export declare const asNsidString: CastFn<NsidString>;
|
|
28
|
-
export declare const asRecordKeyString: CastFn<RecordKeyString>;
|
|
29
|
-
export declare const asTidString: CastFn<TidString>;
|
|
30
|
-
export declare const asUriString: CastFn<UriString>;
|
|
31
|
-
export { isLanguageString };
|
|
1
|
+
import { AtIdentifierString, AtUriString, DatetimeString, DidString, HandleString, NsidString, RecordKeyString, TidString, UriString } from '@atproto/syntax';
|
|
2
|
+
import { CheckFn } from '../util/assertion-util.js';
|
|
3
|
+
export type { AtIdentifierString };
|
|
32
4
|
export declare const isAtIdentifierString: CheckFn<AtIdentifierString>;
|
|
5
|
+
export type { AtUriString };
|
|
33
6
|
export declare const isAtUriString: CheckFn<AtUriString>;
|
|
7
|
+
export type CidString = string;
|
|
34
8
|
export declare const isCidString: CheckFn<CidString>;
|
|
9
|
+
export type { DatetimeString };
|
|
35
10
|
export declare const isDatetimeString: CheckFn<DatetimeString>;
|
|
11
|
+
export type { DidString };
|
|
36
12
|
export declare const isDidString: CheckFn<DidString>;
|
|
13
|
+
export type { HandleString };
|
|
37
14
|
export declare const isHandleString: CheckFn<HandleString>;
|
|
15
|
+
export type LanguageString = string;
|
|
16
|
+
export declare const isLanguageString: CheckFn<LanguageString>;
|
|
17
|
+
export type { NsidString };
|
|
38
18
|
export declare const isNsidString: CheckFn<NsidString>;
|
|
19
|
+
export type { RecordKeyString };
|
|
39
20
|
export declare const isRecordKeyString: CheckFn<RecordKeyString>;
|
|
21
|
+
export type { TidString };
|
|
40
22
|
export declare const isTidString: CheckFn<TidString>;
|
|
41
|
-
export
|
|
42
|
-
export
|
|
43
|
-
|
|
44
|
-
|
|
23
|
+
export type { UriString };
|
|
24
|
+
export declare const isUriString: CheckFn<UriString>;
|
|
25
|
+
type StringFormats = {
|
|
26
|
+
'at-identifier': AtIdentifierString;
|
|
27
|
+
'at-uri': AtUriString;
|
|
28
|
+
cid: CidString;
|
|
29
|
+
datetime: DatetimeString;
|
|
30
|
+
did: DidString;
|
|
31
|
+
handle: HandleString;
|
|
32
|
+
language: LanguageString;
|
|
33
|
+
nsid: NsidString;
|
|
34
|
+
'record-key': RecordKeyString;
|
|
35
|
+
tid: TidString;
|
|
36
|
+
uri: UriString;
|
|
37
|
+
};
|
|
38
|
+
export type StringFormat = Extract<keyof StringFormats, string>;
|
|
39
|
+
export type InferStringFormat<F extends StringFormat> = F extends StringFormat ? StringFormats[F] : never;
|
|
40
|
+
export declare function isStringFormat<I extends string, F extends StringFormat>(input: I, format: F): input is I & StringFormats[F];
|
|
41
|
+
export declare function assertStringFormat<I extends string, F extends StringFormat>(input: I, format: F): asserts input is I & StringFormats[F];
|
|
42
|
+
export declare function asStringFormat<I extends string, F extends StringFormat>(input: I, format: F): I & StringFormats[F];
|
|
43
|
+
export declare function ifStringFormat<I extends string, F extends StringFormat>(input: I, format: F): undefined | (I & StringFormats[F]);
|
|
44
|
+
export declare const STRING_FORMATS: readonly StringFormat[];
|
|
45
45
|
//# sourceMappingURL=string-format.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-format.d.ts","sourceRoot":"","sources":["../../src/core/string-format.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"string-format.d.ts","sourceRoot":"","sources":["../../src/core/string-format.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,SAAS,EACT,YAAY,EACZ,UAAU,EACV,eAAe,EACf,SAAS,EACT,SAAS,EAWV,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAInD,YAAY,EAAE,kBAAkB,EAAE,CAAA;AAClC,eAAO,MAAM,oBAAoB,EAAE,OAAO,CAAC,kBAAkB,CAAe,CAAA;AAE5E,YAAY,EAAE,WAAW,EAAE,CAAA;AAC3B,eAAO,MAAM,aAAa,EAAE,OAAO,CAAC,WAAW,CAAgB,CAAA;AAE/D,MAAM,MAAM,SAAS,GAAG,MAAM,CAAA;AAC9B,eAAO,MAAM,WAAW,EAAoC,OAAO,CAAC,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AM,aAAa,EAAE,MAAM,CAAC,CAAA;AAoB/D,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,YAAY,IAAI,CAAC,SAAS,YAAY,GAC1E,aAAa,CAAC,CAAC,CAAC,GAChB,KAAK,CAAA;AAGT,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,YAAY,EACrE,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,CAAC,GACR,KAAK,IAAI,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAM/B;AAGD,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,YAAY,EACzE,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,CAAC,GACR,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAIvC;AAGD,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,YAAY,EACrE,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,CAAC,GACR,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAGtB;AAGD,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,YAAY,EACrE,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,CAAC,GACR,SAAS,GAAG,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAEpC;AAED,eAAO,MAAM,cAAc,EAEtB,SAAS,YAAY,EAAE,CAAA"}
|
|
@@ -1,102 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.STRING_FORMATS = exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.STRING_FORMATS = exports.isUriString = exports.isTidString = exports.isRecordKeyString = exports.isNsidString = exports.isLanguageString = exports.isHandleString = exports.isDidString = exports.isDatetimeString = exports.isCidString = exports.isAtUriString = exports.isAtIdentifierString = void 0;
|
|
4
|
+
exports.isStringFormat = isStringFormat;
|
|
5
5
|
exports.assertStringFormat = assertStringFormat;
|
|
6
|
+
exports.asStringFormat = asStringFormat;
|
|
7
|
+
exports.ifStringFormat = ifStringFormat;
|
|
6
8
|
const lex_data_1 = require("@atproto/lex-data");
|
|
7
|
-
Object.defineProperty(exports, "isLanguageString", { enumerable: true, get: function () { return lex_data_1.isLanguageString; } });
|
|
8
9
|
const syntax_1 = require("@atproto/syntax");
|
|
9
|
-
|
|
10
|
+
exports.isAtIdentifierString = syntax_1.isValidAtIdentifier;
|
|
11
|
+
exports.isAtUriString = syntax_1.isValidAtUri;
|
|
12
|
+
exports.isCidString = ((v) => (0, lex_data_1.validateCidString)(v));
|
|
13
|
+
exports.isDatetimeString = syntax_1.isValidDatetime;
|
|
14
|
+
exports.isDidString = syntax_1.isValidDid;
|
|
15
|
+
exports.isHandleString = syntax_1.isValidHandle;
|
|
16
|
+
exports.isLanguageString = syntax_1.isValidLanguage;
|
|
17
|
+
exports.isNsidString = syntax_1.isValidNsid;
|
|
18
|
+
exports.isRecordKeyString = syntax_1.isValidRecordKey;
|
|
19
|
+
exports.isTidString = syntax_1.isValidTid;
|
|
20
|
+
exports.isUriString = syntax_1.isValidUri;
|
|
21
|
+
const stringFormatVerifiers = /*#__PURE__*/ Object.freeze({
|
|
22
|
+
__proto__: null,
|
|
23
|
+
'at-identifier': exports.isAtIdentifierString,
|
|
24
|
+
'at-uri': exports.isAtUriString,
|
|
25
|
+
cid: exports.isCidString,
|
|
26
|
+
datetime: exports.isDatetimeString,
|
|
27
|
+
did: exports.isDidString,
|
|
28
|
+
handle: exports.isHandleString,
|
|
29
|
+
language: exports.isLanguageString,
|
|
30
|
+
nsid: exports.isNsidString,
|
|
31
|
+
'record-key': exports.isRecordKeyString,
|
|
32
|
+
tid: exports.isTidString,
|
|
33
|
+
uri: exports.isUriString,
|
|
34
|
+
});
|
|
10
35
|
/*@__NO_SIDE_EFFECTS__*/
|
|
11
|
-
function
|
|
12
|
-
|
|
36
|
+
function isStringFormat(input, format) {
|
|
37
|
+
const formatVerifier = stringFormatVerifiers[format];
|
|
38
|
+
// Fool-proof
|
|
39
|
+
if (!formatVerifier)
|
|
40
|
+
throw new TypeError(`Unknown string format: ${format}`);
|
|
41
|
+
return formatVerifier(input);
|
|
13
42
|
}
|
|
14
|
-
// Export utilities for formats missing from @atproto/syntax
|
|
15
|
-
exports.assertAtIdentifierString = syntax_1.ensureValidAtIdentifier;
|
|
16
|
-
exports.assertAtUriString = syntax_1.ensureValidAtUri;
|
|
17
|
-
exports.assertCidString = lex_data_1.ensureValidCidString;
|
|
18
|
-
exports.assertDatetimeString = syntax_1.ensureValidDatetime;
|
|
19
|
-
exports.assertDidString = syntax_1.ensureValidDid;
|
|
20
|
-
exports.assertHandleString = syntax_1.ensureValidHandle;
|
|
21
|
-
exports.assertLanguageString = (0, assertion_util_js_1.createAssertFunction)(lex_data_1.isLanguageString, 'Invalid BCP 47 string');
|
|
22
|
-
exports.assertNsidString = syntax_1.ensureValidNsid;
|
|
23
|
-
exports.assertRecordKeyString = syntax_1.ensureValidRecordKey;
|
|
24
|
-
exports.assertTidString = syntax_1.ensureValidTid;
|
|
25
|
-
exports.assertUriString = (0, assertion_util_js_1.createAssertFunction)(isUriString, 'Invalid URI');
|
|
26
|
-
exports.asAtIdentifierString =
|
|
27
|
-
/*#__PURE__*/ (0, assertion_util_js_1.createCastFunction)(exports.assertAtIdentifierString);
|
|
28
|
-
exports.asAtUriString =
|
|
29
|
-
/*#__PURE__*/ (0, assertion_util_js_1.createCastFunction)(syntax_1.ensureValidAtUri);
|
|
30
|
-
exports.asCidString =
|
|
31
|
-
/*#__PURE__*/ (0, assertion_util_js_1.createCastFunction)(lex_data_1.ensureValidCidString);
|
|
32
|
-
exports.asDatetimeString =
|
|
33
|
-
/*#__PURE__*/ (0, assertion_util_js_1.createCastFunction)(syntax_1.ensureValidDatetime);
|
|
34
|
-
exports.asDidString =
|
|
35
|
-
/*#__PURE__*/ (0, assertion_util_js_1.createCastFunction)(syntax_1.ensureValidDid);
|
|
36
|
-
exports.asHandleString =
|
|
37
|
-
/*#__PURE__*/ (0, assertion_util_js_1.createCastFunction)(syntax_1.ensureValidHandle);
|
|
38
|
-
exports.asLanguageString =
|
|
39
|
-
/*#__PURE__*/ (0, assertion_util_js_1.createCastFunction)(exports.assertLanguageString);
|
|
40
|
-
exports.asNsidString =
|
|
41
|
-
/*#__PURE__*/ (0, assertion_util_js_1.createCastFunction)(syntax_1.ensureValidNsid);
|
|
42
|
-
exports.asRecordKeyString =
|
|
43
|
-
/*#__PURE__*/ (0, assertion_util_js_1.createCastFunction)(syntax_1.ensureValidRecordKey);
|
|
44
|
-
exports.asTidString =
|
|
45
|
-
/*#__PURE__*/ (0, assertion_util_js_1.createCastFunction)(syntax_1.ensureValidTid);
|
|
46
|
-
exports.asUriString =
|
|
47
|
-
/*#__PURE__*/ (0, assertion_util_js_1.createCastFunction)(exports.assertUriString);
|
|
48
|
-
exports.isAtIdentifierString =
|
|
49
|
-
/*#__PURE__*/ (0, assertion_util_js_1.createCheckFunction)(exports.assertAtIdentifierString);
|
|
50
|
-
exports.isAtUriString =
|
|
51
|
-
/*#__PURE__*/ (0, assertion_util_js_1.createCheckFunction)(exports.assertAtIdentifierString);
|
|
52
|
-
exports.isCidString =
|
|
53
|
-
/*#__PURE__*/ (0, assertion_util_js_1.createCheckFunction)(exports.assertCidString);
|
|
54
|
-
exports.isDatetimeString =
|
|
55
|
-
/*#__PURE__*/ (0, assertion_util_js_1.createCheckFunction)(exports.assertDatetimeString);
|
|
56
|
-
exports.isDidString =
|
|
57
|
-
/*#__PURE__*/ (0, assertion_util_js_1.createCheckFunction)(exports.assertDidString);
|
|
58
|
-
exports.isHandleString =
|
|
59
|
-
/*#__PURE__*/ (0, assertion_util_js_1.createCheckFunction)(exports.assertHandleString);
|
|
60
|
-
exports.isNsidString =
|
|
61
|
-
/*#__PURE__*/ (0, assertion_util_js_1.createCheckFunction)(exports.assertNsidString);
|
|
62
|
-
exports.isRecordKeyString =
|
|
63
|
-
/*#__PURE__*/ (0, assertion_util_js_1.createCheckFunction)(exports.assertRecordKeyString);
|
|
64
|
-
exports.isTidString =
|
|
65
|
-
/*#__PURE__*/ (0, assertion_util_js_1.createCheckFunction)(exports.assertTidString);
|
|
66
|
-
// String formatting types and utilities
|
|
67
|
-
exports.STRING_FORMATS = Object.freeze([
|
|
68
|
-
'datetime',
|
|
69
|
-
'uri',
|
|
70
|
-
'at-uri',
|
|
71
|
-
'did',
|
|
72
|
-
'handle',
|
|
73
|
-
'at-identifier',
|
|
74
|
-
'nsid',
|
|
75
|
-
'cid',
|
|
76
|
-
'language',
|
|
77
|
-
'tid',
|
|
78
|
-
'record-key',
|
|
79
|
-
]);
|
|
80
|
-
const formatters = /*#__PURE__*/ new Map([
|
|
81
|
-
['at-identifier', exports.assertAtIdentifierString],
|
|
82
|
-
['at-uri', exports.assertAtUriString],
|
|
83
|
-
['cid', exports.assertCidString],
|
|
84
|
-
['datetime', exports.assertDatetimeString],
|
|
85
|
-
['did', exports.assertDidString],
|
|
86
|
-
['handle', exports.assertHandleString],
|
|
87
|
-
['language', exports.assertLanguageString],
|
|
88
|
-
['nsid', exports.assertNsidString],
|
|
89
|
-
['record-key', exports.assertRecordKeyString],
|
|
90
|
-
['tid', exports.assertTidString],
|
|
91
|
-
['uri', exports.assertUriString],
|
|
92
|
-
]);
|
|
93
43
|
/*@__NO_SIDE_EFFECTS__*/
|
|
94
44
|
function assertStringFormat(input, format) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
45
|
+
if (!isStringFormat(input, format)) {
|
|
46
|
+
throw new TypeError(`Invalid string format (${format}): ${input}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
50
|
+
function asStringFormat(input, format) {
|
|
51
|
+
assertStringFormat(input, format);
|
|
52
|
+
return input;
|
|
53
|
+
}
|
|
54
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
55
|
+
function ifStringFormat(input, format) {
|
|
56
|
+
return isStringFormat(input, format) ? input : undefined;
|
|
101
57
|
}
|
|
58
|
+
exports.STRING_FORMATS = Object.freeze(
|
|
59
|
+
/*#__PURE__*/ Object.keys(stringFormatVerifiers));
|
|
102
60
|
//# sourceMappingURL=string-format.js.map
|