@atscript/typescript 0.1.13 → 0.1.15
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/cli.cjs +21 -1
- package/dist/index.cjs +21 -1
- package/dist/index.mjs +21 -1
- package/dist/utils.cjs +21 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.mjs +21 -1
- package/package.json +2 -2
package/dist/cli.cjs
CHANGED
|
@@ -733,7 +733,7 @@ else {
|
|
|
733
733
|
this.error(`Expected ${def.type.designType}, got ${typeOfValue}`);
|
|
734
734
|
return false;
|
|
735
735
|
}
|
|
736
|
-
return
|
|
736
|
+
return this.validateBoolean(def, value);
|
|
737
737
|
case "undefined":
|
|
738
738
|
if (value !== undefined) {
|
|
739
739
|
this.error(`Expected ${def.type.designType}, got ${typeOfValue}`);
|
|
@@ -750,6 +750,14 @@ else {
|
|
|
750
750
|
}
|
|
751
751
|
}
|
|
752
752
|
validateString(def, value) {
|
|
753
|
+
const filled = def.metadata.get("meta.required");
|
|
754
|
+
if (filled) {
|
|
755
|
+
if (value.trim().length === 0) {
|
|
756
|
+
const message = typeof filled === "object" && filled.message ? filled.message : `Must not be empty`;
|
|
757
|
+
this.error(message);
|
|
758
|
+
return false;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
753
761
|
const minLength = def.metadata.get("expect.minLength");
|
|
754
762
|
if (minLength) {
|
|
755
763
|
const length = typeof minLength === "number" ? minLength : minLength.length;
|
|
@@ -811,6 +819,17 @@ else {
|
|
|
811
819
|
}
|
|
812
820
|
return true;
|
|
813
821
|
}
|
|
822
|
+
validateBoolean(def, value) {
|
|
823
|
+
const filled = def.metadata.get("meta.required");
|
|
824
|
+
if (filled) {
|
|
825
|
+
if (value !== true) {
|
|
826
|
+
const message = typeof filled === "object" && filled.message ? filled.message : `Must be checked`;
|
|
827
|
+
this.error(message);
|
|
828
|
+
return false;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
return true;
|
|
832
|
+
}
|
|
814
833
|
constructor(def, opts) {
|
|
815
834
|
_define_property$2(this, "def", void 0);
|
|
816
835
|
_define_property$2(this, "opts", void 0);
|
|
@@ -1017,6 +1036,7 @@ function buildJsonSchema(type) {
|
|
|
1017
1036
|
if (schema.type === "number" && meta.get("expect.int")) schema.type = "integer";
|
|
1018
1037
|
}
|
|
1019
1038
|
if (schema.type === "string") {
|
|
1039
|
+
if (meta.get("meta.required")) schema.minLength = 1;
|
|
1020
1040
|
const minLength = meta.get("expect.minLength");
|
|
1021
1041
|
if (minLength) schema.minLength = typeof minLength === "number" ? minLength : minLength.length;
|
|
1022
1042
|
const maxLength = meta.get("expect.maxLength");
|
package/dist/index.cjs
CHANGED
|
@@ -730,7 +730,7 @@ else {
|
|
|
730
730
|
this.error(`Expected ${def.type.designType}, got ${typeOfValue}`);
|
|
731
731
|
return false;
|
|
732
732
|
}
|
|
733
|
-
return
|
|
733
|
+
return this.validateBoolean(def, value);
|
|
734
734
|
case "undefined":
|
|
735
735
|
if (value !== undefined) {
|
|
736
736
|
this.error(`Expected ${def.type.designType}, got ${typeOfValue}`);
|
|
@@ -747,6 +747,14 @@ else {
|
|
|
747
747
|
}
|
|
748
748
|
}
|
|
749
749
|
validateString(def, value) {
|
|
750
|
+
const filled = def.metadata.get("meta.required");
|
|
751
|
+
if (filled) {
|
|
752
|
+
if (value.trim().length === 0) {
|
|
753
|
+
const message = typeof filled === "object" && filled.message ? filled.message : `Must not be empty`;
|
|
754
|
+
this.error(message);
|
|
755
|
+
return false;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
750
758
|
const minLength = def.metadata.get("expect.minLength");
|
|
751
759
|
if (minLength) {
|
|
752
760
|
const length = typeof minLength === "number" ? minLength : minLength.length;
|
|
@@ -808,6 +816,17 @@ else {
|
|
|
808
816
|
}
|
|
809
817
|
return true;
|
|
810
818
|
}
|
|
819
|
+
validateBoolean(def, value) {
|
|
820
|
+
const filled = def.metadata.get("meta.required");
|
|
821
|
+
if (filled) {
|
|
822
|
+
if (value !== true) {
|
|
823
|
+
const message = typeof filled === "object" && filled.message ? filled.message : `Must be checked`;
|
|
824
|
+
this.error(message);
|
|
825
|
+
return false;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
return true;
|
|
829
|
+
}
|
|
811
830
|
constructor(def, opts) {
|
|
812
831
|
_define_property$1(this, "def", void 0);
|
|
813
832
|
_define_property$1(this, "opts", void 0);
|
|
@@ -1014,6 +1033,7 @@ function buildJsonSchema(type) {
|
|
|
1014
1033
|
if (schema.type === "number" && meta.get("expect.int")) schema.type = "integer";
|
|
1015
1034
|
}
|
|
1016
1035
|
if (schema.type === "string") {
|
|
1036
|
+
if (meta.get("meta.required")) schema.minLength = 1;
|
|
1017
1037
|
const minLength = meta.get("expect.minLength");
|
|
1018
1038
|
if (minLength) schema.minLength = typeof minLength === "number" ? minLength : minLength.length;
|
|
1019
1039
|
const maxLength = meta.get("expect.maxLength");
|
package/dist/index.mjs
CHANGED
|
@@ -706,7 +706,7 @@ else {
|
|
|
706
706
|
this.error(`Expected ${def.type.designType}, got ${typeOfValue}`);
|
|
707
707
|
return false;
|
|
708
708
|
}
|
|
709
|
-
return
|
|
709
|
+
return this.validateBoolean(def, value);
|
|
710
710
|
case "undefined":
|
|
711
711
|
if (value !== undefined) {
|
|
712
712
|
this.error(`Expected ${def.type.designType}, got ${typeOfValue}`);
|
|
@@ -723,6 +723,14 @@ else {
|
|
|
723
723
|
}
|
|
724
724
|
}
|
|
725
725
|
validateString(def, value) {
|
|
726
|
+
const filled = def.metadata.get("meta.required");
|
|
727
|
+
if (filled) {
|
|
728
|
+
if (value.trim().length === 0) {
|
|
729
|
+
const message = typeof filled === "object" && filled.message ? filled.message : `Must not be empty`;
|
|
730
|
+
this.error(message);
|
|
731
|
+
return false;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
726
734
|
const minLength = def.metadata.get("expect.minLength");
|
|
727
735
|
if (minLength) {
|
|
728
736
|
const length = typeof minLength === "number" ? minLength : minLength.length;
|
|
@@ -784,6 +792,17 @@ else {
|
|
|
784
792
|
}
|
|
785
793
|
return true;
|
|
786
794
|
}
|
|
795
|
+
validateBoolean(def, value) {
|
|
796
|
+
const filled = def.metadata.get("meta.required");
|
|
797
|
+
if (filled) {
|
|
798
|
+
if (value !== true) {
|
|
799
|
+
const message = typeof filled === "object" && filled.message ? filled.message : `Must be checked`;
|
|
800
|
+
this.error(message);
|
|
801
|
+
return false;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
return true;
|
|
805
|
+
}
|
|
787
806
|
constructor(def, opts) {
|
|
788
807
|
_define_property$1(this, "def", void 0);
|
|
789
808
|
_define_property$1(this, "opts", void 0);
|
|
@@ -990,6 +1009,7 @@ function buildJsonSchema(type) {
|
|
|
990
1009
|
if (schema.type === "number" && meta.get("expect.int")) schema.type = "integer";
|
|
991
1010
|
}
|
|
992
1011
|
if (schema.type === "string") {
|
|
1012
|
+
if (meta.get("meta.required")) schema.minLength = 1;
|
|
993
1013
|
const minLength = meta.get("expect.minLength");
|
|
994
1014
|
if (minLength) schema.minLength = typeof minLength === "number" ? minLength : minLength.length;
|
|
995
1015
|
const maxLength = meta.get("expect.maxLength");
|
package/dist/utils.cjs
CHANGED
|
@@ -285,7 +285,7 @@ else {
|
|
|
285
285
|
this.error(`Expected ${def.type.designType}, got ${typeOfValue}`);
|
|
286
286
|
return false;
|
|
287
287
|
}
|
|
288
|
-
return
|
|
288
|
+
return this.validateBoolean(def, value);
|
|
289
289
|
case "undefined":
|
|
290
290
|
if (value !== undefined) {
|
|
291
291
|
this.error(`Expected ${def.type.designType}, got ${typeOfValue}`);
|
|
@@ -302,6 +302,14 @@ else {
|
|
|
302
302
|
}
|
|
303
303
|
}
|
|
304
304
|
validateString(def, value) {
|
|
305
|
+
const filled = def.metadata.get("meta.required");
|
|
306
|
+
if (filled) {
|
|
307
|
+
if (value.trim().length === 0) {
|
|
308
|
+
const message = typeof filled === "object" && filled.message ? filled.message : `Must not be empty`;
|
|
309
|
+
this.error(message);
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
305
313
|
const minLength = def.metadata.get("expect.minLength");
|
|
306
314
|
if (minLength) {
|
|
307
315
|
const length = typeof minLength === "number" ? minLength : minLength.length;
|
|
@@ -363,6 +371,17 @@ else {
|
|
|
363
371
|
}
|
|
364
372
|
return true;
|
|
365
373
|
}
|
|
374
|
+
validateBoolean(def, value) {
|
|
375
|
+
const filled = def.metadata.get("meta.required");
|
|
376
|
+
if (filled) {
|
|
377
|
+
if (value !== true) {
|
|
378
|
+
const message = typeof filled === "object" && filled.message ? filled.message : `Must be checked`;
|
|
379
|
+
this.error(message);
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
366
385
|
constructor(def, opts) {
|
|
367
386
|
_define_property(this, "def", void 0);
|
|
368
387
|
_define_property(this, "opts", void 0);
|
|
@@ -582,6 +601,7 @@ function buildJsonSchema(type) {
|
|
|
582
601
|
if (schema.type === "number" && meta.get("expect.int")) schema.type = "integer";
|
|
583
602
|
}
|
|
584
603
|
if (schema.type === "string") {
|
|
604
|
+
if (meta.get("meta.required")) schema.minLength = 1;
|
|
585
605
|
const minLength = meta.get("expect.minLength");
|
|
586
606
|
if (minLength) schema.minLength = typeof minLength === "number" ? minLength : minLength.length;
|
|
587
607
|
const maxLength = meta.get("expect.maxLength");
|
package/dist/utils.d.ts
CHANGED
|
@@ -90,6 +90,7 @@ declare class Validator<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedTyp
|
|
|
90
90
|
protected validatePrimitive(def: TAtscriptAnnotatedType<TAtscriptTypeFinal>, value: any): boolean;
|
|
91
91
|
protected validateString(def: TAtscriptAnnotatedType<TAtscriptTypeFinal>, value: string): boolean;
|
|
92
92
|
protected validateNumber(def: TAtscriptAnnotatedType<TAtscriptTypeFinal>, value: number): boolean;
|
|
93
|
+
protected validateBoolean(def: TAtscriptAnnotatedType<TAtscriptTypeFinal>, value: boolean): boolean;
|
|
93
94
|
}
|
|
94
95
|
/** Error thrown by {@link Validator.validate} when validation fails. Contains structured error details. */
|
|
95
96
|
declare class ValidatorError extends Error {
|
package/dist/utils.mjs
CHANGED
|
@@ -284,7 +284,7 @@ else {
|
|
|
284
284
|
this.error(`Expected ${def.type.designType}, got ${typeOfValue}`);
|
|
285
285
|
return false;
|
|
286
286
|
}
|
|
287
|
-
return
|
|
287
|
+
return this.validateBoolean(def, value);
|
|
288
288
|
case "undefined":
|
|
289
289
|
if (value !== undefined) {
|
|
290
290
|
this.error(`Expected ${def.type.designType}, got ${typeOfValue}`);
|
|
@@ -301,6 +301,14 @@ else {
|
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
303
|
validateString(def, value) {
|
|
304
|
+
const filled = def.metadata.get("meta.required");
|
|
305
|
+
if (filled) {
|
|
306
|
+
if (value.trim().length === 0) {
|
|
307
|
+
const message = typeof filled === "object" && filled.message ? filled.message : `Must not be empty`;
|
|
308
|
+
this.error(message);
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
304
312
|
const minLength = def.metadata.get("expect.minLength");
|
|
305
313
|
if (minLength) {
|
|
306
314
|
const length = typeof minLength === "number" ? minLength : minLength.length;
|
|
@@ -362,6 +370,17 @@ else {
|
|
|
362
370
|
}
|
|
363
371
|
return true;
|
|
364
372
|
}
|
|
373
|
+
validateBoolean(def, value) {
|
|
374
|
+
const filled = def.metadata.get("meta.required");
|
|
375
|
+
if (filled) {
|
|
376
|
+
if (value !== true) {
|
|
377
|
+
const message = typeof filled === "object" && filled.message ? filled.message : `Must be checked`;
|
|
378
|
+
this.error(message);
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
365
384
|
constructor(def, opts) {
|
|
366
385
|
_define_property(this, "def", void 0);
|
|
367
386
|
_define_property(this, "opts", void 0);
|
|
@@ -581,6 +600,7 @@ function buildJsonSchema(type) {
|
|
|
581
600
|
if (schema.type === "number" && meta.get("expect.int")) schema.type = "integer";
|
|
582
601
|
}
|
|
583
602
|
if (schema.type === "string") {
|
|
603
|
+
if (meta.get("meta.required")) schema.minLength = 1;
|
|
584
604
|
const minLength = meta.get("expect.minLength");
|
|
585
605
|
if (minLength) schema.minLength = typeof minLength === "number" ? minLength : minLength.length;
|
|
586
606
|
const maxLength = meta.get("expect.maxLength");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/typescript",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "Atscript: typescript-gen support.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"homepage": "https://github.com/moostjs/atscript/tree/main/packages/typescript#readme",
|
|
71
71
|
"license": "ISC",
|
|
72
72
|
"peerDependencies": {
|
|
73
|
-
"@atscript/core": "^0.1.
|
|
73
|
+
"@atscript/core": "^0.1.15"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"@moostjs/event-cli": "^0.5.32",
|