@tstdl/base 0.91.0-beta1 → 0.91.0-beta3
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 +2 -2
- package/schema/decorators/utils.js +3 -2
- package/schema/schemas/array.d.ts +3 -2
- package/schema/schemas/array.js +2 -2
- package/schema/schemas/bigint.d.ts +2 -1
- package/schema/schemas/bigint.js +2 -2
- package/schema/schemas/boolean.d.ts +3 -3
- package/schema/schemas/boolean.js +3 -3
- package/schema/schemas/nullable.d.ts +3 -2
- package/schema/schemas/nullable.js +2 -2
- package/schema/schemas/object.d.ts +8 -4
- package/schema/schemas/object.js +20 -11
- package/schema/schemas/optional.d.ts +3 -2
- package/schema/schemas/optional.js +3 -3
- package/schema/schemas/symbol.d.ts +3 -3
- package/schema/schemas/symbol.js +4 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.91.0-
|
|
3
|
+
"version": "0.91.0-beta3",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -142,7 +142,7 @@
|
|
|
142
142
|
"@zxcvbn-ts/language-de": "^3.0",
|
|
143
143
|
"@zxcvbn-ts/language-en": "^3.0",
|
|
144
144
|
"chroma-js": "^2.4",
|
|
145
|
-
"drizzle-orm": "^0.
|
|
145
|
+
"drizzle-orm": "^0.32",
|
|
146
146
|
"handlebars": "^4.7",
|
|
147
147
|
"koa": "^2.15",
|
|
148
148
|
"minio": "^8.0",
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
2
|
import { createPropertyOrAccessorDecorator } from '../../reflection/index.js';
|
|
3
|
-
|
|
3
|
+
import { filterUndefinedObjectProperties } from '../../utils/object/object.js';
|
|
4
|
+
export function createSchemaPropertyDecorator(data = {}) {
|
|
4
5
|
return createPropertyOrAccessorDecorator({
|
|
5
|
-
data: { schema: data },
|
|
6
|
+
data: { schema: filterUndefinedObjectProperties(data) },
|
|
6
7
|
mergeData: true
|
|
7
8
|
});
|
|
8
9
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import {
|
|
2
|
+
import type { TypedOmit } from '../../types.js';
|
|
3
|
+
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
3
4
|
import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
5
|
export declare class ArraySchema<T> extends Schema<T[]> {
|
|
5
6
|
readonly itemSchema: Schema<T>;
|
|
@@ -7,4 +8,4 @@ export declare class ArraySchema<T> extends Schema<T[]> {
|
|
|
7
8
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T[]>;
|
|
8
9
|
}
|
|
9
10
|
export declare function array<T>(schema: SchemaTestable<T>): ArraySchema<T>;
|
|
10
|
-
export declare function Array(schema: SchemaTestable): SchemaPropertyDecorator;
|
|
11
|
+
export declare function Array(schema: SchemaTestable, options?: TypedOmit<SchemaPropertyDecoratorOptions, 'array'>): SchemaPropertyDecorator;
|
package/schema/schemas/array.js
CHANGED
|
@@ -26,6 +26,6 @@ export class ArraySchema extends Schema {
|
|
|
26
26
|
export function array(schema) {
|
|
27
27
|
return new ArraySchema(schema);
|
|
28
28
|
}
|
|
29
|
-
export function Array(schema) {
|
|
30
|
-
return Property(schema, { array: true });
|
|
29
|
+
export function Array(schema, options) {
|
|
30
|
+
return Property(schema, { ...options, array: true });
|
|
31
31
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
+
import { type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
2
3
|
import type { SchemaPropertyDecorator } from '../decorators/types.js';
|
|
3
4
|
import { Schema, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
5
|
export declare class BigIntSchema extends Schema<bigint> {
|
|
5
6
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<bigint>;
|
|
6
7
|
}
|
|
7
8
|
export declare function bigint(): BigIntSchema;
|
|
8
|
-
export declare function BigInt(): SchemaPropertyDecorator;
|
|
9
|
+
export declare function BigInt(options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
package/schema/schemas/bigint.js
CHANGED
|
@@ -7,9 +7,9 @@ export declare class BooleanSchema extends SimpleSchema<boolean> {
|
|
|
7
7
|
constructor(options?: BooleanSchemaOptions);
|
|
8
8
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<boolean>;
|
|
9
9
|
}
|
|
10
|
-
export declare function boolean(): BooleanSchema;
|
|
11
|
-
export declare function Boolean(options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
10
|
+
export declare function boolean(options?: BooleanSchemaOptions): BooleanSchema;
|
|
11
|
+
export declare function Boolean(options?: BooleanSchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
12
12
|
/**
|
|
13
13
|
* @deprecated use {@link Boolean()} instead
|
|
14
14
|
*/
|
|
15
|
-
export declare function BooleanProperty(options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
15
|
+
export declare function BooleanProperty(options?: BooleanSchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
@@ -36,11 +36,11 @@ export class BooleanSchema extends SimpleSchema {
|
|
|
36
36
|
return { valid: false, error: SchemaError.expectedButGot('boolean', typeOf(value), path, { fast: options.fastErrors }) };
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
export function boolean() {
|
|
40
|
-
return new BooleanSchema();
|
|
39
|
+
export function boolean(options) {
|
|
40
|
+
return new BooleanSchema(options);
|
|
41
41
|
}
|
|
42
42
|
export function Boolean(options) {
|
|
43
|
-
return Property(boolean(), options);
|
|
43
|
+
return Property(boolean(options), options);
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
46
|
* @deprecated use {@link Boolean()} instead
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import {
|
|
2
|
+
import type { TypedOmit } from '../../types.js';
|
|
3
|
+
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
3
4
|
import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
5
|
export declare class NullableSchema<T> extends Schema<T | null> {
|
|
5
6
|
readonly schema: Schema<T>;
|
|
@@ -7,4 +8,4 @@ export declare class NullableSchema<T> extends Schema<T | null> {
|
|
|
7
8
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T | null>;
|
|
8
9
|
}
|
|
9
10
|
export declare function nullable<T>(schema: SchemaTestable<T>): NullableSchema<T>;
|
|
10
|
-
export declare function Nullable(): SchemaPropertyDecorator;
|
|
11
|
+
export declare function Nullable(schema?: SchemaTestable, options?: TypedOmit<SchemaPropertyDecoratorOptions, 'nullable'>): SchemaPropertyDecorator;
|
|
@@ -21,6 +21,6 @@ export class NullableSchema extends Schema {
|
|
|
21
21
|
export function nullable(schema) {
|
|
22
22
|
return new NullableSchema(schema);
|
|
23
23
|
}
|
|
24
|
-
export function Nullable() {
|
|
25
|
-
return createSchemaPropertyDecorator({ nullable: true });
|
|
24
|
+
export function Nullable(schema, options) {
|
|
25
|
+
return createSchemaPropertyDecorator({ schema, ...options, nullable: true });
|
|
26
26
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { EmptyObject, Merge } from 'type-fest';
|
|
2
2
|
import type { JsonPath } from '../../json-path/json-path.js';
|
|
3
3
|
import type { AbstractConstructor, OneOrMany, PartialProperty, Record, SimplifyObject, Type, TypedOmit } from '../../types.js';
|
|
4
|
+
import { type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
5
|
+
import type { SchemaPropertyDecorator } from '../decorators/types.js';
|
|
4
6
|
import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
5
7
|
export type ObjectSchemaFactoryFunction<T> = (data: T) => T;
|
|
6
8
|
export type ObjectSchemaFactory<T> = {
|
|
@@ -65,11 +67,13 @@ export declare function assign<T1 extends Record, T2 extends Record, T3 extends
|
|
|
65
67
|
export declare function assign<T1 extends Record, T2 extends Record, T3 extends Record, T4 extends Record>(a: ObjectSchemaOrType<T1>, b: ObjectSchemaOrType<T2>, c: ObjectSchemaOrType<T3>, d: ObjectSchemaOrType<T4>): ObjectSchema<Merge<Merge<Merge<T1, T2>, T3>, T4>>;
|
|
66
68
|
export declare function assign<T1 extends Record, T2 extends Record, T3 extends Record, T4 extends Record, T5 extends Record>(a: ObjectSchemaOrType<T1>, b: ObjectSchemaOrType<T2>, c: ObjectSchemaOrType<T3>, d: ObjectSchemaOrType<T4>, e: ObjectSchemaOrType<T5>): ObjectSchema<Merge<Merge<Merge<Merge<T1, T2>, T3>, T4>, T5>>;
|
|
67
69
|
export declare function assign<T1 extends Record, T2 extends Record, T3 extends Record, T4 extends Record, T5 extends Record, T6 extends Record>(a: ObjectSchemaOrType<T1>, b: ObjectSchemaOrType<T2>, c: ObjectSchemaOrType<T3>, d: ObjectSchemaOrType<T4>, e: ObjectSchemaOrType<T5>, f: ObjectSchemaOrType<T6>): ObjectSchema<Merge<Merge<Merge<Merge<Merge<T1, T2>, T3>, T4>, T5>, T6>>;
|
|
68
|
-
export declare function partial<T extends Record>(schema:
|
|
69
|
-
export declare function partial<T extends Record, K extends keyof T>(schema:
|
|
70
|
-
export declare function pick<T extends Record, K extends keyof T>(
|
|
71
|
-
export declare function omit<T extends Record, K extends keyof T>(
|
|
70
|
+
export declare function partial<T extends Record>(schema: ObjectSchemaOrType<T>): ObjectSchema<Partial<T>>;
|
|
71
|
+
export declare function partial<T extends Record, K extends keyof T>(schema: ObjectSchemaOrType<T>, keys: OneOrMany<K>): ObjectSchema<PartialProperty<T, K>>;
|
|
72
|
+
export declare function pick<T extends Record, K extends keyof T>(schemaOrType: ObjectSchemaOrType<T>, keys: OneOrMany<K>): ObjectSchema<SimplifyObject<Omit<T, K>>>;
|
|
73
|
+
export declare function omit<T extends Record, K extends keyof T>(schemaOrType: ObjectSchemaOrType<T>, keys: OneOrMany<K>): ObjectSchema<SimplifyObject<Omit<T, K>>>;
|
|
72
74
|
export declare function getSchemaFromReflection<T extends Record>(type: AbstractConstructor<T>): Schema<T>;
|
|
73
75
|
declare function _tryGetSchemaFromReflection<T extends Record>(type: AbstractConstructor<T>): Schema<T> | null;
|
|
76
|
+
export declare function getObjectSchema<T extends Record>(schemaOrType: SchemaTestable<T>): ObjectSchema<T>;
|
|
77
|
+
export declare function Record<K extends PropertyKey, V>(key: Schema<K>, value: Schema<V>, options?: TypedOmit<ObjectSchemaOptions<Record<K, V>>, 'unknownProperties' | 'unknownPropertiesKey'> & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
74
78
|
export declare const emptyObjectSchema: ObjectSchema<EmptyObject>;
|
|
75
79
|
export {};
|
package/schema/schemas/object.js
CHANGED
|
@@ -6,6 +6,7 @@ import { memoizeSingle } from '../../utils/function/memoize.js';
|
|
|
6
6
|
import { filterObject, mapObjectValues, objectKeys } from '../../utils/object/object.js';
|
|
7
7
|
import { assert, isDefined, isFunction, isLiteralObject, isNotNull, isNotNullOrUndefined, isNull, isObject, isUndefined } from '../../utils/type-guards.js';
|
|
8
8
|
import { typeOf } from '../../utils/type-of.js';
|
|
9
|
+
import { Property } from '../decorators/index.js';
|
|
9
10
|
import { Schema } from '../schema.js';
|
|
10
11
|
import { schemaTestableToSchema } from '../testable.js';
|
|
11
12
|
import { array } from './array.js';
|
|
@@ -79,21 +80,15 @@ export function record(key, value, options) {
|
|
|
79
80
|
return object({}, { ...options, unknownPropertiesKey: key, unknownProperties: value });
|
|
80
81
|
}
|
|
81
82
|
export function assign(...schemasOrTypes) {
|
|
82
|
-
const schemas = schemasOrTypes.map(
|
|
83
|
-
if (schemaOrType instanceof ObjectSchema) {
|
|
84
|
-
return schemaOrType;
|
|
85
|
-
}
|
|
86
|
-
const typeSchema = getSchemaFromReflection(schemaOrType);
|
|
87
|
-
assert(typeSchema instanceof ObjectSchema, 'assign() only works with object schemas.');
|
|
88
|
-
return typeSchema;
|
|
89
|
-
});
|
|
83
|
+
const schemas = schemasOrTypes.map(getObjectSchema);
|
|
90
84
|
return object(schemas.reduce((result, schema) => ({ ...result, ...schema.properties }), {}), {
|
|
91
85
|
mask: schemas.findLast((schema) => isNotNull(schema.mask))?.mask,
|
|
92
86
|
unknownProperties: schemas.findLast((schema) => isNotNull(schema.unknownProperties))?.unknownProperties,
|
|
93
87
|
unknownPropertiesKey: schemas.findLast((schema) => isNotNull(schema.unknownPropertiesKey))?.unknownPropertiesKey
|
|
94
88
|
});
|
|
95
89
|
}
|
|
96
|
-
export function partial(
|
|
90
|
+
export function partial(schemaOrType, keyOrKeys) {
|
|
91
|
+
const schema = getObjectSchema(schemaOrType);
|
|
97
92
|
const keys = isUndefined(keyOrKeys) ? undefined : toArray(keyOrKeys);
|
|
98
93
|
const mapper = isUndefined(keys)
|
|
99
94
|
? (propertySchema) => optional(propertySchema)
|
|
@@ -104,7 +99,8 @@ export function partial(schema, keyOrKeys) {
|
|
|
104
99
|
unknownPropertiesKey: schema.unknownPropertiesKey
|
|
105
100
|
});
|
|
106
101
|
}
|
|
107
|
-
export function pick(
|
|
102
|
+
export function pick(schemaOrType, keys) {
|
|
103
|
+
const schema = getObjectSchema(schemaOrType);
|
|
108
104
|
const keyArray = toArray(keys);
|
|
109
105
|
return object(filterObject(schema.properties, (_, key) => keyArray.includes(key)), {
|
|
110
106
|
mask: schema.mask,
|
|
@@ -112,7 +108,8 @@ export function pick(schema, keys) {
|
|
|
112
108
|
unknownPropertiesKey: schema.unknownPropertiesKey
|
|
113
109
|
});
|
|
114
110
|
}
|
|
115
|
-
export function omit(
|
|
111
|
+
export function omit(schemaOrType, keys) {
|
|
112
|
+
const schema = getObjectSchema(schemaOrType);
|
|
116
113
|
const keysArray = toArray(keys);
|
|
117
114
|
return object(filterObject(schema.properties, (_, key) => !keysArray.includes(key)), {
|
|
118
115
|
mask: schema.mask,
|
|
@@ -174,4 +171,16 @@ function getObjectSchemaPropertiesFromReflection(metadata, type) {
|
|
|
174
171
|
}
|
|
175
172
|
return properties;
|
|
176
173
|
}
|
|
174
|
+
export function getObjectSchema(schemaOrType) {
|
|
175
|
+
if (schemaOrType instanceof ObjectSchema) {
|
|
176
|
+
return schemaOrType;
|
|
177
|
+
}
|
|
178
|
+
if (isFunction(schemaOrType)) {
|
|
179
|
+
return getObjectSchema(getSchemaFromReflection(schemaOrType));
|
|
180
|
+
}
|
|
181
|
+
throw new Error('Could not infer ObjectSchema.');
|
|
182
|
+
}
|
|
183
|
+
export function Record(key, value, options) {
|
|
184
|
+
return Property(record(key, value, options), options);
|
|
185
|
+
}
|
|
177
186
|
export const emptyObjectSchema = explicitObject({});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import
|
|
2
|
+
import { TypedOmit } from '../../types.js';
|
|
3
|
+
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
3
4
|
import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
5
|
export declare class OptionalSchema<T> extends Schema<T | undefined> {
|
|
5
6
|
readonly schema: Schema<T>;
|
|
@@ -7,4 +8,4 @@ export declare class OptionalSchema<T> extends Schema<T | undefined> {
|
|
|
7
8
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T | undefined>;
|
|
8
9
|
}
|
|
9
10
|
export declare function optional<T>(schema: SchemaTestable<T>): OptionalSchema<T>;
|
|
10
|
-
export declare function Optional(schema?: SchemaTestable): SchemaPropertyDecorator;
|
|
11
|
+
export declare function Optional(schema?: SchemaTestable, options?: TypedOmit<SchemaPropertyDecoratorOptions, 'optional'>): SchemaPropertyDecorator;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isUndefined } from '../../utils/type-guards.js';
|
|
2
|
-
import { createSchemaPropertyDecorator } from '../decorators/
|
|
2
|
+
import { createSchemaPropertyDecorator } from '../decorators/index.js';
|
|
3
3
|
import { Schema } from '../schema.js';
|
|
4
4
|
import { schemaTestableToSchema } from '../testable.js';
|
|
5
5
|
export class OptionalSchema extends Schema {
|
|
@@ -21,6 +21,6 @@ export class OptionalSchema extends Schema {
|
|
|
21
21
|
export function optional(schema) {
|
|
22
22
|
return new OptionalSchema(schema);
|
|
23
23
|
}
|
|
24
|
-
export function Optional(schema) {
|
|
25
|
-
return createSchemaPropertyDecorator({ schema, optional: true });
|
|
24
|
+
export function Optional(schema, options) {
|
|
25
|
+
return createSchemaPropertyDecorator({ schema, ...options, optional: true });
|
|
26
26
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import { type SchemaPropertyDecorator } from '../decorators/index.js';
|
|
2
|
+
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
3
3
|
import { Schema, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
4
|
export declare class SymbolSchema extends Schema<symbol> {
|
|
5
5
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<symbol>;
|
|
6
6
|
}
|
|
7
7
|
export declare function symbol(): SymbolSchema;
|
|
8
|
-
export declare function Symbol(): SchemaPropertyDecorator;
|
|
8
|
+
export declare function Symbol(options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
9
9
|
/**
|
|
10
10
|
* @deprecated use {@link Symbol()} instead
|
|
11
11
|
*/
|
|
12
|
-
export declare function SymbolProperty(): SchemaPropertyDecorator;
|
|
12
|
+
export declare function SymbolProperty(options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
package/schema/schemas/symbol.js
CHANGED
|
@@ -14,12 +14,12 @@ export class SymbolSchema extends Schema {
|
|
|
14
14
|
export function symbol() {
|
|
15
15
|
return new SymbolSchema();
|
|
16
16
|
}
|
|
17
|
-
export function Symbol() {
|
|
18
|
-
return Property(symbol());
|
|
17
|
+
export function Symbol(options) {
|
|
18
|
+
return Property(symbol(), options);
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* @deprecated use {@link Symbol()} instead
|
|
22
22
|
*/
|
|
23
|
-
export function SymbolProperty() {
|
|
24
|
-
return Symbol();
|
|
23
|
+
export function SymbolProperty(options) {
|
|
24
|
+
return Symbol(options);
|
|
25
25
|
}
|