schematox 1.0.0 → 1.0.1
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 +4 -0
- package/README.md +6 -4
- package/package.json +1 -1
- package/src/types/schema.ts +1 -3
- package/src/types/struct.ts +14 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.0.1](https://github.com/incerta/schematox/compare/v1.0.0...v1.0.1)
|
|
4
|
+
|
|
5
|
+
- [FIX: struct brand assignment second argument type restriction #44](https://github.com/incerta/schematox/pull/44)
|
|
6
|
+
|
|
3
7
|
## [1.0.0](https://github.com/incerta/schematox/compare/v0.4.0...v1.0.0)
|
|
4
8
|
|
|
5
9
|
The module went through major refactoring so it could be ready for production usage:
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Schematox
|
|
2
2
|
|
|
3
3
|
Schematox is a lightweight typesafe schema defined parser. All schemas are JSON compatible.
|
|
4
4
|
|
|
@@ -142,10 +142,12 @@ const string = makeStruct(schema)
|
|
|
142
142
|
|
|
143
143
|
We distinguish two main categories of schema units:
|
|
144
144
|
|
|
145
|
-
- primitive: boolean, literal, number,
|
|
146
|
-
- compound: array, object, record, union
|
|
145
|
+
- primitive: boolean, literal, number, string
|
|
146
|
+
- compound: array, object, record, tuple, union
|
|
147
147
|
|
|
148
|
-
Any schema share optional/nullable/description parameters.
|
|
148
|
+
Any schema share optional/nullable/description parameters.
|
|
149
|
+
Any primitive schema can have "brand" parameter.
|
|
150
|
+
Any compound schema could have any other schema type as its member including itself.
|
|
149
151
|
|
|
150
152
|
### Boolean
|
|
151
153
|
|
package/package.json
CHANGED
package/src/types/schema.ts
CHANGED
|
@@ -8,9 +8,7 @@ export type Schema =
|
|
|
8
8
|
| { type: 'tuple'; of: Array<Schema> } & SchemaShared
|
|
9
9
|
| { type: 'union'; of: Array<Schema> } & SchemaShared
|
|
10
10
|
|
|
11
|
-
export type BrandSchema<T = string, U = unknown> = Readonly<
|
|
12
|
-
[category: T, subCategory: U]
|
|
13
|
-
>
|
|
11
|
+
export type BrandSchema<T = string, U = unknown> = Readonly<[T, U]>
|
|
14
12
|
|
|
15
13
|
export type SchemaShared = {
|
|
16
14
|
/**
|
package/src/types/struct.ts
CHANGED
|
@@ -9,6 +9,8 @@ import type {
|
|
|
9
9
|
TupleSchema,
|
|
10
10
|
UnionSchema,
|
|
11
11
|
//
|
|
12
|
+
BrandSchema,
|
|
13
|
+
//
|
|
12
14
|
BooleanSchema,
|
|
13
15
|
LiteralSchema,
|
|
14
16
|
NumberSchema,
|
|
@@ -23,10 +25,18 @@ export type Struct<T extends Schema> = Omit<
|
|
|
23
25
|
optional: () => Struct<T & { optional: true }>
|
|
24
26
|
nullable: () => Struct<T & { nullable: true }>
|
|
25
27
|
|
|
26
|
-
brand: <
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
brand: <
|
|
29
|
+
U extends string,
|
|
30
|
+
V extends
|
|
31
|
+
| boolean
|
|
32
|
+
| number
|
|
33
|
+
| string
|
|
34
|
+
| ReadonlyArray<unknown>
|
|
35
|
+
| Record<string, unknown>,
|
|
36
|
+
>(
|
|
37
|
+
key: U,
|
|
38
|
+
value: V
|
|
39
|
+
) => Struct<T & { brand: BrandSchema<U, V> }>
|
|
30
40
|
|
|
31
41
|
minLength: <U extends number>(
|
|
32
42
|
minLength: U
|