@tstdl/base 0.91.33 → 0.91.35

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.91.33",
3
+ "version": "0.91.35",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,4 +1,5 @@
1
1
  import { SchemaError } from '../../schema/schema.error.js';
2
+ import { lazyProperty } from '../../utils/object/lazy-property.js';
2
3
  import { isArray } from '../../utils/type-guards.js';
3
4
  import { typeOf } from '../../utils/type-of.js';
4
5
  import { Property } from '../decorators/index.js';
@@ -12,7 +13,7 @@ export class ArraySchema extends Schema {
12
13
  super();
13
14
  this.#options = options;
14
15
  this.itemSchema = schemaTestableToSchema(itemSchema);
15
- this.name = `Array[${this.itemSchema.name}]`;
16
+ lazyProperty(this, 'name', () => `Array[${this.itemSchema.name}]`);
16
17
  }
17
18
  _test(value, path, options) {
18
19
  if (!isArray(value)) {
@@ -1,12 +1,9 @@
1
- import type { JsonPath } from '../../json-path/json-path.js';
2
1
  import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
3
- import type { SchemaTestOptions, SchemaTestResult } from '../schema.js';
4
2
  import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
5
3
  export type BooleanSchemaOptions = SimpleSchemaOptions;
6
4
  export declare class BooleanSchema extends SimpleSchema<boolean> {
7
5
  readonly name = "boolean";
8
6
  constructor(options?: BooleanSchemaOptions);
9
- _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<boolean>;
10
7
  }
11
8
  export declare function boolean(options?: BooleanSchemaOptions): BooleanSchema;
12
9
  export declare function BooleanProperty(options?: BooleanSchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
@@ -1,6 +1,4 @@
1
- import { SchemaError } from '../../schema/schema.error.js';
2
1
  import { isBoolean, isString } from '../../utils/type-guards.js';
3
- import { typeOf } from '../../utils/type-of.js';
4
2
  import { Property } from '../decorators/index.js';
5
3
  import { SimpleSchema } from './simple.js';
6
4
  export class BooleanSchema extends SimpleSchema {
@@ -30,12 +28,6 @@ export class BooleanSchema extends SimpleSchema {
30
28
  }
31
29
  });
32
30
  }
33
- _test(value, path, options) {
34
- if (isBoolean(value)) {
35
- return { valid: true, value };
36
- }
37
- return { valid: false, error: SchemaError.expectedButGot('boolean', typeOf(value), path, { fast: options.fastErrors }) };
38
- }
39
31
  }
40
32
  export function boolean(options) {
41
33
  return new BooleanSchema(options);
@@ -1,3 +1,4 @@
1
+ import { lazyProperty } from '../../utils/object/lazy-property.js';
1
2
  import { isNullOrUndefined } from '../../utils/type-guards.js';
2
3
  import { Property } from '../decorators/index.js';
3
4
  import { Schema } from '../schema.js';
@@ -10,7 +11,7 @@ export class DefaultSchema extends Schema {
10
11
  super();
11
12
  this.schema = schemaTestableToSchema(schema);
12
13
  this.defaultValue = defaultValue;
13
- this.name = `Defaulted[${this.schema.name}]`;
14
+ lazyProperty(this, 'name', () => `Defaulted[${this.schema.name}]`);
14
15
  }
15
16
  _test(value, path, options) {
16
17
  if (isNullOrUndefined(value)) {
@@ -1,4 +1,5 @@
1
1
  import { enumValues } from '../../utils/enum.js';
2
+ import { lazyProperty } from '../../utils/object/lazy-property.js';
2
3
  import { isArray, isString } from '../../utils/type-guards.js';
3
4
  import { Property } from '../decorators/index.js';
4
5
  import { SimpleSchema } from './simple.js';
@@ -18,7 +19,7 @@ export class EnumerationSchema extends SimpleSchema {
18
19
  });
19
20
  this.enumeration = enumeration;
20
21
  this.#allowedValuesSet = new Set(allowedValues);
21
- this.name = `Enumeration[${allowedValuesString}]`;
22
+ lazyProperty(this, 'name', () => `Enumeration[${allowedValuesString}]`);
22
23
  }
23
24
  }
24
25
  export function enumeration(enumeration, options) {
@@ -1,3 +1,4 @@
1
+ import { lazyProperty } from '../../utils/object/lazy-property.js';
1
2
  import { typeOf } from '../../utils/type-of.js';
2
3
  import { Property } from '../decorators/index.js';
3
4
  import { SchemaError } from '../schema.error.js';
@@ -8,7 +9,7 @@ export class InstanceSchema extends Schema {
8
9
  constructor(type) {
9
10
  super();
10
11
  this.type = type;
11
- this.name = `Instance[${type.name}]`;
12
+ lazyProperty(this, 'name', () => `Instance[${type.name}]`);
12
13
  }
13
14
  _test(value, path, options) {
14
15
  if (value instanceof this.type) {
@@ -1,3 +1,4 @@
1
+ import { lazyProperty } from '../../utils/object/lazy-property.js';
1
2
  import { isPrimitive } from '../../utils/type-guards.js';
2
3
  import { typeOf } from '../../utils/type-of.js';
3
4
  import { Property } from '../decorators/index.js';
@@ -9,7 +10,7 @@ export class LiteralSchema extends Schema {
9
10
  constructor(value) {
10
11
  super();
11
12
  this.value = value;
12
- this.name = `Literal[${String(value)}]`;
13
+ lazyProperty(this, 'name', () => `Literal[${String(value)}]`);
13
14
  }
14
15
  _test(value, path, options) {
15
16
  if (value === this.value) {
@@ -1,3 +1,4 @@
1
+ import { lazyProperty } from '../../utils/object/lazy-property.js';
1
2
  import { isNull } from '../../utils/type-guards.js';
2
3
  import { createSchemaPropertyDecorator } from '../decorators/index.js';
3
4
  import { Schema } from '../schema.js';
@@ -11,7 +12,7 @@ export class NullableSchema extends Schema {
11
12
  }
12
13
  super();
13
14
  this.schema = schemaTestableToSchema(schema);
14
- this.name = `Nullable[${this.schema.name}]`;
15
+ lazyProperty(this, 'name', () => `Nullable[${this.schema.name}]`);
15
16
  }
16
17
  _test(value, path, options) {
17
18
  if (isNull(value)) {
@@ -1,3 +1,4 @@
1
+ import { lazyProperty } from '../../utils/object/lazy-property.js';
1
2
  import { Property } from '../decorators/index.js';
2
3
  import { Schema } from '../schema.js';
3
4
  import { schemaTestableToSchema } from '../testable.js';
@@ -10,7 +11,7 @@ export class OneOrManySchema extends Schema {
10
11
  super();
11
12
  const oneSchema = schemaTestableToSchema(schema);
12
13
  this.schema = union(oneSchema, array(oneSchema));
13
- this.name = `OneOrMany[${oneSchema.name}]`;
14
+ lazyProperty(this, 'name', () => `OneOrMany[${oneSchema.name}]`);
14
15
  }
15
16
  _test(value, path, options) {
16
17
  return this.schema._test(value, path, options);
@@ -1,3 +1,4 @@
1
+ import { lazyProperty } from '../../utils/object/lazy-property.js';
1
2
  import { isUndefined } from '../../utils/type-guards.js';
2
3
  import { createSchemaPropertyDecorator } from '../decorators/index.js';
3
4
  import { Schema } from '../schema.js';
@@ -11,7 +12,7 @@ export class OptionalSchema extends Schema {
11
12
  }
12
13
  super();
13
14
  this.schema = schemaTestableToSchema(schema);
14
- this.name = `Optional[${this.schema.name}]`;
15
+ lazyProperty(this, 'name', () => `Optional[${this.schema.name}]`);
15
16
  }
16
17
  _test(value, path, options) {
17
18
  if (isUndefined(value)) {
@@ -1,3 +1,4 @@
1
+ import { lazyProperty } from '../../utils/object/lazy-property.js';
1
2
  import { Schema } from '../schema.js';
2
3
  import { schemaTestableToSchema } from '../testable.js';
3
4
  export class TransformSchema extends Schema {
@@ -8,7 +9,7 @@ export class TransformSchema extends Schema {
8
9
  super();
9
10
  this.schema = schemaTestableToSchema(schema);
10
11
  this.transformFn = transformFn;
11
- this.name = `Transform[${schema.name}]`;
12
+ lazyProperty(this, 'name', () => `Transform[${this.schema.name}]`);
12
13
  }
13
14
  _test(value, path, options) {
14
15
  const result = this.schema._test(value, path, options);
@@ -1,3 +1,4 @@
1
+ import { lazyProperty } from '../../utils/object/lazy-property.js';
1
2
  import { Property } from '../decorators/index.js';
2
3
  import { SchemaError } from '../schema.error.js';
3
4
  import { Schema } from '../schema.js';
@@ -14,7 +15,7 @@ export class UnionSchema extends Schema {
14
15
  }
15
16
  return schema;
16
17
  });
17
- this.name = `Union[${this.schemas.map((schema) => schema.name).join(', ')}]`;
18
+ lazyProperty(this, 'name', () => `Union[${this.schemas.map((schema) => schema.name).join(', ')}]`);
18
19
  }
19
20
  _test(value, path, options) {
20
21
  const errors = [];