@dzeio/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/dist/Schema.d.mts CHANGED
@@ -43,6 +43,7 @@ declare abstract class SchemaItem<Type = any> implements StandardSchemaV1<Type>
43
43
  attr(...attributes: Array<string>): this;
44
44
  setInvalidError(err: string): this;
45
45
  clone(): this;
46
+ nullable(): SchemaNullable<this>;
46
47
  /**
47
48
  * schemas implementing unwrap can return their child component (mostly the value)
48
49
  *
@@ -83,6 +84,16 @@ type ValidationResult<T> = {
83
84
  errors: Array<ValidationError>
84
85
  }
85
86
 
87
+ type ValidationResultOld<T> = {
88
+ object: T
89
+ valid: true
90
+ error?: undefined
91
+ } | {
92
+ valid: false
93
+ object?: (T extends object ? Partial<T> : T) | undefined
94
+ error: Array<ValidationError>
95
+ }
96
+
86
97
  interface SchemaJSON {
87
98
  i: string
88
99
  a?: Array<string> | undefined
@@ -110,6 +121,10 @@ type ModelInfer$1<M extends Model> = {
110
121
  [key in keyof M]: SchemaInfer<M[key]>
111
122
  }
112
123
 
124
+ declare class SchemaAny extends SchemaItem {
125
+ isOfType(input: unknown): input is any;
126
+ }
127
+
113
128
  declare class SchemaDate extends SchemaItem<Date> {
114
129
  isOfType(input: unknown): input is Date;
115
130
  }
@@ -274,6 +289,7 @@ declare function parseForm<T extends SchemaObject>(model: T, form: HTMLFormEleme
274
289
  declare function parceable(): (target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>) => TypedPropertyDescriptor<any>;
275
290
  type SchemaItemStatic = new (...args: Array<any>) => SchemaItem;
276
291
  declare const Types: {
292
+ readonly Any: typeof SchemaAny;
277
293
  readonly Array: typeof SchemaArray;
278
294
  readonly Boolean: typeof SchemaBoolean;
279
295
  readonly Date: typeof SchemaDate;
@@ -289,6 +305,7 @@ declare class Schema<T extends Record<string, SchemaItem> = Record<string, Schem
289
305
  private static registeredModules;
290
306
  static register(module: SchemaItemStatic): void;
291
307
  static getModule(name: string): SchemaItemStatic | undefined;
308
+ static any(): SchemaAny;
292
309
  static array<Type extends SchemaItem>(...inputs: ConstructorParameters<typeof SchemaArray<Type>>): SchemaArray<Type>;
293
310
  static boolean(...inputs: ConstructorParameters<typeof SchemaBoolean>): SchemaBoolean;
294
311
  static date(...inputs: ConstructorParameters<typeof SchemaDate>): SchemaDate;
@@ -329,4 +346,4 @@ declare class Schema<T extends Record<string, SchemaItem> = Record<string, Schem
329
346
  }
330
347
  declare const s: typeof Schema;
331
348
 
332
- export { type Infer, type Model, type ModelInfer$1 as ModelInfer, SchemaArray, SchemaBoolean, SchemaDate, SchemaEnum, type SchemaInfer, SchemaItem, type SchemaItemJSON, type SchemaJSON, SchemaLiteral, SchemaNullable, SchemaNumber, SchemaObject, SchemaRecord, SchemaString, SchemaUnion, Types, type ValidationError, type ValidationResult, Schema as default, parceable, parseForm, parseFormData, parseQuery, s };
349
+ export { type Infer, type Model, type ModelInfer$1 as ModelInfer, SchemaAny, SchemaArray, SchemaBoolean, SchemaDate, SchemaEnum, type SchemaInfer, SchemaItem, type SchemaItemJSON, type SchemaJSON, SchemaLiteral, SchemaNullable, SchemaNumber, SchemaObject, SchemaRecord, SchemaString, SchemaUnion, Types, type ValidationError, type ValidationResult, type ValidationResultOld, Schema as default, parceable, parseForm, parseFormData, parseQuery, s };
package/dist/Schema.d.ts CHANGED
@@ -43,6 +43,7 @@ declare abstract class SchemaItem<Type = any> implements StandardSchemaV1<Type>
43
43
  attr(...attributes: Array<string>): this;
44
44
  setInvalidError(err: string): this;
45
45
  clone(): this;
46
+ nullable(): SchemaNullable<this>;
46
47
  /**
47
48
  * schemas implementing unwrap can return their child component (mostly the value)
48
49
  *
@@ -83,6 +84,16 @@ type ValidationResult<T> = {
83
84
  errors: Array<ValidationError>
84
85
  }
85
86
 
87
+ type ValidationResultOld<T> = {
88
+ object: T
89
+ valid: true
90
+ error?: undefined
91
+ } | {
92
+ valid: false
93
+ object?: (T extends object ? Partial<T> : T) | undefined
94
+ error: Array<ValidationError>
95
+ }
96
+
86
97
  interface SchemaJSON {
87
98
  i: string
88
99
  a?: Array<string> | undefined
@@ -110,6 +121,10 @@ type ModelInfer$1<M extends Model> = {
110
121
  [key in keyof M]: SchemaInfer<M[key]>
111
122
  }
112
123
 
124
+ declare class SchemaAny extends SchemaItem {
125
+ isOfType(input: unknown): input is any;
126
+ }
127
+
113
128
  declare class SchemaDate extends SchemaItem<Date> {
114
129
  isOfType(input: unknown): input is Date;
115
130
  }
@@ -274,6 +289,7 @@ declare function parseForm<T extends SchemaObject>(model: T, form: HTMLFormEleme
274
289
  declare function parceable(): (target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>) => TypedPropertyDescriptor<any>;
275
290
  type SchemaItemStatic = new (...args: Array<any>) => SchemaItem;
276
291
  declare const Types: {
292
+ readonly Any: typeof SchemaAny;
277
293
  readonly Array: typeof SchemaArray;
278
294
  readonly Boolean: typeof SchemaBoolean;
279
295
  readonly Date: typeof SchemaDate;
@@ -289,6 +305,7 @@ declare class Schema<T extends Record<string, SchemaItem> = Record<string, Schem
289
305
  private static registeredModules;
290
306
  static register(module: SchemaItemStatic): void;
291
307
  static getModule(name: string): SchemaItemStatic | undefined;
308
+ static any(): SchemaAny;
292
309
  static array<Type extends SchemaItem>(...inputs: ConstructorParameters<typeof SchemaArray<Type>>): SchemaArray<Type>;
293
310
  static boolean(...inputs: ConstructorParameters<typeof SchemaBoolean>): SchemaBoolean;
294
311
  static date(...inputs: ConstructorParameters<typeof SchemaDate>): SchemaDate;
@@ -329,4 +346,4 @@ declare class Schema<T extends Record<string, SchemaItem> = Record<string, Schem
329
346
  }
330
347
  declare const s: typeof Schema;
331
348
 
332
- export { type Infer, type Model, type ModelInfer$1 as ModelInfer, SchemaArray, SchemaBoolean, SchemaDate, SchemaEnum, type SchemaInfer, SchemaItem, type SchemaItemJSON, type SchemaJSON, SchemaLiteral, SchemaNullable, SchemaNumber, SchemaObject, SchemaRecord, SchemaString, SchemaUnion, Types, type ValidationError, type ValidationResult, Schema as default, parceable, parseForm, parseFormData, parseQuery, s };
349
+ export { type Infer, type Model, type ModelInfer$1 as ModelInfer, SchemaAny, SchemaArray, SchemaBoolean, SchemaDate, SchemaEnum, type SchemaInfer, SchemaItem, type SchemaItemJSON, type SchemaJSON, SchemaLiteral, SchemaNullable, SchemaNumber, SchemaObject, SchemaRecord, SchemaString, SchemaUnion, Types, type ValidationError, type ValidationResult, type ValidationResultOld, Schema as default, parceable, parseForm, parseFormData, parseQuery, s };
package/dist/Schema.js CHANGED
@@ -28,6 +28,7 @@ var __decorateClass = (decorators, target, key, kind) => {
28
28
  // src/Schema.ts
29
29
  var Schema_exports = {};
30
30
  __export(Schema_exports, {
31
+ SchemaAny: () => SchemaAny,
31
32
  SchemaArray: () => SchemaArray,
32
33
  SchemaBoolean: () => SchemaBoolean,
33
34
  SchemaDate: () => SchemaDate,
@@ -122,6 +123,9 @@ var SchemaItem = class _SchemaItem {
122
123
  clone() {
123
124
  return Schema.fromJSON(this.toJSON());
124
125
  }
126
+ nullable() {
127
+ return new SchemaNullable(this);
128
+ }
125
129
  parse(input, options) {
126
130
  var _a;
127
131
  for (const preProcess of this.preProcess) {
@@ -390,6 +394,14 @@ function parseForm(model, form, opts) {
390
394
  return parseFormData(model, new FormData(form), opts);
391
395
  }
392
396
 
397
+ // src/items/any.ts
398
+ var SchemaAny = class extends SchemaItem {
399
+ // @ts-expect-error input while not used is necessary for the `override to work`
400
+ isOfType(input) {
401
+ return true;
402
+ }
403
+ };
404
+
393
405
  // src/items/date.ts
394
406
  var SchemaDate = class extends SchemaItem {
395
407
  isOfType(input) {
@@ -664,6 +676,7 @@ function parceable() {
664
676
  };
665
677
  }
666
678
  var Types = {
679
+ Any: SchemaAny,
667
680
  Array: SchemaArray,
668
681
  Boolean: SchemaBoolean,
669
682
  Date: SchemaDate,
@@ -682,6 +695,9 @@ var _Schema = class _Schema extends SchemaObject {
682
695
  static getModule(name) {
683
696
  return this.registeredModules.find((it) => it.name === name);
684
697
  }
698
+ static any() {
699
+ return new SchemaAny();
700
+ }
685
701
  static array(...inputs) {
686
702
  return new SchemaArray(...inputs);
687
703
  }
@@ -789,6 +805,7 @@ var Schema = _Schema;
789
805
  var s = Schema;
790
806
  // Annotate the CommonJS export names for ESM import in node:
791
807
  0 && (module.exports = {
808
+ SchemaAny,
792
809
  SchemaArray,
793
810
  SchemaBoolean,
794
811
  SchemaDate,
package/dist/Schema.mjs CHANGED
@@ -81,6 +81,9 @@ var SchemaItem = class _SchemaItem {
81
81
  clone() {
82
82
  return Schema.fromJSON(this.toJSON());
83
83
  }
84
+ nullable() {
85
+ return new SchemaNullable(this);
86
+ }
84
87
  parse(input, options) {
85
88
  var _a;
86
89
  for (const preProcess of this.preProcess) {
@@ -349,6 +352,14 @@ function parseForm(model, form, opts) {
349
352
  return parseFormData(model, new FormData(form), opts);
350
353
  }
351
354
 
355
+ // src/items/any.ts
356
+ var SchemaAny = class extends SchemaItem {
357
+ // @ts-expect-error input while not used is necessary for the `override to work`
358
+ isOfType(input) {
359
+ return true;
360
+ }
361
+ };
362
+
352
363
  // src/items/date.ts
353
364
  var SchemaDate = class extends SchemaItem {
354
365
  isOfType(input) {
@@ -623,6 +634,7 @@ function parceable() {
623
634
  };
624
635
  }
625
636
  var Types = {
637
+ Any: SchemaAny,
626
638
  Array: SchemaArray,
627
639
  Boolean: SchemaBoolean,
628
640
  Date: SchemaDate,
@@ -641,6 +653,9 @@ var _Schema = class _Schema extends SchemaObject {
641
653
  static getModule(name) {
642
654
  return this.registeredModules.find((it) => it.name === name);
643
655
  }
656
+ static any() {
657
+ return new SchemaAny();
658
+ }
644
659
  static array(...inputs) {
645
660
  return new SchemaArray(...inputs);
646
661
  }
@@ -747,6 +762,7 @@ _Schema.registeredModules = [
747
762
  var Schema = _Schema;
748
763
  var s = Schema;
749
764
  export {
765
+ SchemaAny,
750
766
  SchemaArray,
751
767
  SchemaBoolean,
752
768
  SchemaDate,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dzeio/schema",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "dependencies": {
5
5
  "@dzeio/object-util": "^1.8.3"
6
6
  },
@@ -37,6 +37,7 @@
37
37
  "scripts": {
38
38
  "test": "bun test",
39
39
  "lint": "eslint",
40
- "build": "rm -rf dist && tsup ./src/Schema.ts --format cjs,esm --dts --clean"
40
+ "build": "rm -rf dist && tsup ./src/Schema.ts --format cjs,esm --dts --clean",
41
+ "prepublishOnly": "rm -rf dist && tsup ./src/Schema.ts --format cjs,esm --dts --clean"
41
42
  }
42
43
  }