@atscript/typescript 0.1.9 → 0.1.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/dist/cli.cjs CHANGED
@@ -519,12 +519,14 @@ var Validator = class {
519
519
  * @param safe - If `true`, returns `false` on failure instead of throwing.
520
520
  * @returns `true` if the value matches the type definition.
521
521
  * @throws {ValidatorError} When validation fails and `safe` is not `true`.
522
- */ validate(value, safe) {
522
+ */ validate(value, safe, context) {
523
523
  this.push("");
524
524
  this.errors = [];
525
525
  this.stackErrors = [];
526
+ this.context = context;
526
527
  const passed = this.validateSafe(this.def, value);
527
528
  this.pop(!passed);
529
+ this.context = undefined;
528
530
  if (!passed) {
529
531
  if (safe) return false;
530
532
  this.throw();
@@ -814,6 +816,7 @@ else {
814
816
  /** Validation errors collected during the last {@link validate} call. */ _define_property$2(this, "errors", void 0);
815
817
  _define_property$2(this, "stackErrors", void 0);
816
818
  _define_property$2(this, "stackPath", void 0);
819
+ _define_property$2(this, "context", void 0);
817
820
  this.def = def;
818
821
  this.errors = [];
819
822
  this.stackErrors = [];
package/dist/index.cjs CHANGED
@@ -516,12 +516,14 @@ var Validator = class {
516
516
  * @param safe - If `true`, returns `false` on failure instead of throwing.
517
517
  * @returns `true` if the value matches the type definition.
518
518
  * @throws {ValidatorError} When validation fails and `safe` is not `true`.
519
- */ validate(value, safe) {
519
+ */ validate(value, safe, context) {
520
520
  this.push("");
521
521
  this.errors = [];
522
522
  this.stackErrors = [];
523
+ this.context = context;
523
524
  const passed = this.validateSafe(this.def, value);
524
525
  this.pop(!passed);
526
+ this.context = undefined;
525
527
  if (!passed) {
526
528
  if (safe) return false;
527
529
  this.throw();
@@ -811,6 +813,7 @@ else {
811
813
  /** Validation errors collected during the last {@link validate} call. */ _define_property$1(this, "errors", void 0);
812
814
  _define_property$1(this, "stackErrors", void 0);
813
815
  _define_property$1(this, "stackPath", void 0);
816
+ _define_property$1(this, "context", void 0);
814
817
  this.def = def;
815
818
  this.errors = [];
816
819
  this.stackErrors = [];
package/dist/index.mjs CHANGED
@@ -492,12 +492,14 @@ var Validator = class {
492
492
  * @param safe - If `true`, returns `false` on failure instead of throwing.
493
493
  * @returns `true` if the value matches the type definition.
494
494
  * @throws {ValidatorError} When validation fails and `safe` is not `true`.
495
- */ validate(value, safe) {
495
+ */ validate(value, safe, context) {
496
496
  this.push("");
497
497
  this.errors = [];
498
498
  this.stackErrors = [];
499
+ this.context = context;
499
500
  const passed = this.validateSafe(this.def, value);
500
501
  this.pop(!passed);
502
+ this.context = undefined;
501
503
  if (!passed) {
502
504
  if (safe) return false;
503
505
  this.throw();
@@ -787,6 +789,7 @@ else {
787
789
  /** Validation errors collected during the last {@link validate} call. */ _define_property$1(this, "errors", void 0);
788
790
  _define_property$1(this, "stackErrors", void 0);
789
791
  _define_property$1(this, "stackPath", void 0);
792
+ _define_property$1(this, "context", void 0);
790
793
  this.def = def;
791
794
  this.errors = [];
792
795
  this.stackErrors = [];
package/dist/utils.cjs CHANGED
@@ -72,12 +72,14 @@ var Validator = class {
72
72
  * @param safe - If `true`, returns `false` on failure instead of throwing.
73
73
  * @returns `true` if the value matches the type definition.
74
74
  * @throws {ValidatorError} When validation fails and `safe` is not `true`.
75
- */ validate(value, safe) {
75
+ */ validate(value, safe, context) {
76
76
  this.push("");
77
77
  this.errors = [];
78
78
  this.stackErrors = [];
79
+ this.context = context;
79
80
  const passed = this.validateSafe(this.def, value);
80
81
  this.pop(!passed);
82
+ this.context = undefined;
81
83
  if (!passed) {
82
84
  if (safe) return false;
83
85
  this.throw();
@@ -367,6 +369,7 @@ else {
367
369
  /** Validation errors collected during the last {@link validate} call. */ _define_property(this, "errors", void 0);
368
370
  _define_property(this, "stackErrors", void 0);
369
371
  _define_property(this, "stackPath", void 0);
372
+ _define_property(this, "context", void 0);
370
373
  this.def = def;
371
374
  this.errors = [];
372
375
  this.stackErrors = [];
package/dist/utils.d.ts CHANGED
@@ -25,6 +25,7 @@ interface TValidatorPluginContext {
25
25
  validateAnnotatedType: Validator<any>['validateAnnotatedType'];
26
26
  error: Validator<any>['error'];
27
27
  path: Validator<any>['path'];
28
+ context: unknown;
28
29
  }
29
30
  /**
30
31
  * Validates values against an {@link TAtscriptAnnotatedType} definition.
@@ -59,6 +60,7 @@ declare class Validator<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedTyp
59
60
  errors: TError[];
60
61
  protected stackErrors: TError[][];
61
62
  protected stackPath: string[];
63
+ protected context: unknown;
62
64
  protected isLimitExceeded(): boolean;
63
65
  protected push(name: string): void;
64
66
  protected pop(saveErrors: boolean): TError[] | undefined;
@@ -76,7 +78,7 @@ declare class Validator<T extends TAtscriptAnnotatedType = TAtscriptAnnotatedTyp
76
78
  * @returns `true` if the value matches the type definition.
77
79
  * @throws {ValidatorError} When validation fails and `safe` is not `true`.
78
80
  */
79
- validate<TT = DataType>(value: any, safe?: boolean): value is TT;
81
+ validate<TT = DataType>(value: any, safe?: boolean, context?: unknown): value is TT;
80
82
  protected validateSafe(def: TAtscriptAnnotatedType, value: any): boolean;
81
83
  protected get path(): string;
82
84
  protected validateAnnotatedType(def: TAtscriptAnnotatedType, value: any): boolean;
package/dist/utils.mjs CHANGED
@@ -71,12 +71,14 @@ var Validator = class {
71
71
  * @param safe - If `true`, returns `false` on failure instead of throwing.
72
72
  * @returns `true` if the value matches the type definition.
73
73
  * @throws {ValidatorError} When validation fails and `safe` is not `true`.
74
- */ validate(value, safe) {
74
+ */ validate(value, safe, context) {
75
75
  this.push("");
76
76
  this.errors = [];
77
77
  this.stackErrors = [];
78
+ this.context = context;
78
79
  const passed = this.validateSafe(this.def, value);
79
80
  this.pop(!passed);
81
+ this.context = undefined;
80
82
  if (!passed) {
81
83
  if (safe) return false;
82
84
  this.throw();
@@ -366,6 +368,7 @@ else {
366
368
  /** Validation errors collected during the last {@link validate} call. */ _define_property(this, "errors", void 0);
367
369
  _define_property(this, "stackErrors", void 0);
368
370
  _define_property(this, "stackPath", void 0);
371
+ _define_property(this, "context", void 0);
369
372
  this.def = def;
370
373
  this.errors = [];
371
374
  this.stackErrors = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/typescript",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
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.9"
73
+ "@atscript/core": "^0.1.10"
74
74
  },
75
75
  "dependencies": {
76
76
  "@moostjs/event-cli": "^0.5.32",