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 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
- # schematox
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, boolean
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. Any compound schema could have any other schema type as its member including itself. Any primitive schema can have "brand" parameter.
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "schematox",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "scripts": {
5
5
  "prepublishOnly": "bash release-check.sh",
6
6
  "test": "jest",
@@ -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
  /**
@@ -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: <V extends string, W extends string>(
27
- key: V,
28
- value: W
29
- ) => Struct<T & { brand: Readonly<[V, W]> }>
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