@tstdl/base 0.91.0-beta10 → 0.91.0-beta11
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ApiDefinition } from '../api/types.js';
|
|
2
|
-
import {
|
|
2
|
+
import { ObjectSchema, type ObjectSchemaOrType } from '../schema/index.js';
|
|
3
3
|
import type { SchemaTestable } from '../schema/schema.js';
|
|
4
4
|
import type { Record } from '../types.js';
|
|
5
5
|
import type { TokenPayload } from './index.js';
|
package/package.json
CHANGED
package/schema/schema.d.ts
CHANGED
|
@@ -19,10 +19,11 @@ export type SchemaTestResult<T> = {
|
|
|
19
19
|
error: SchemaError;
|
|
20
20
|
};
|
|
21
21
|
type NormalizePrimitiveToConstructor<T> = Or<IsEqual<T, string>, IsEqual<T, String>> extends true ? typeof String : Or<IsEqual<T, number>, IsEqual<T, Number>> extends true ? typeof Number : Or<IsEqual<T, boolean>, IsEqual<T, Boolean>> extends true ? typeof Boolean : Or<IsEqual<T, bigint>, IsEqual<T, BigInt>> extends true ? typeof BigInt : Or<IsEqual<T, symbol>, IsEqual<T, Symbol>> extends true ? typeof Symbol : never;
|
|
22
|
-
type NormalizeConstructorToPrimitve<T> = T extends String ? string : T extends Number ? number : T extends Boolean ? boolean : T extends BigInt ? bigint : T extends Symbol ? symbol : T;
|
|
23
22
|
export type SchemaTestable<T = unknown> = Schema<T> | AbstractConstructor<T> | NormalizePrimitiveToConstructor<T>;
|
|
24
|
-
export type SchemaOutput<T extends SchemaTestable> = T extends SchemaTestable<infer U> ?
|
|
23
|
+
export type SchemaOutput<T extends SchemaTestable> = T extends SchemaTestable<infer U> ? U : never;
|
|
24
|
+
export declare const OPTIONAL: unique symbol;
|
|
25
25
|
export declare abstract class Schema<T = unknown> {
|
|
26
|
+
readonly [OPTIONAL]: boolean;
|
|
26
27
|
/**
|
|
27
28
|
* Test an unknown value to see whether it corresponds to the schema.
|
|
28
29
|
* @param schema schema to test against
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { EmptyObject, Merge } from 'type-fest';
|
|
2
2
|
import type { JsonPath } from '../../json-path/json-path.js';
|
|
3
|
-
import type { AbstractConstructor, OneOrMany, PartialProperty,
|
|
3
|
+
import type { AbstractConstructor, OneOrMany, PartialProperty, Record as RecordType, SimplifyObject, Type, TypedOmit } from '../../types.js';
|
|
4
4
|
import { type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
5
5
|
import type { SchemaPropertyDecorator } from '../decorators/types.js';
|
|
6
|
-
import { Schema, type SchemaOutput, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
7
|
-
import { type OptionalSchema } from './optional.js';
|
|
6
|
+
import { type OPTIONAL, Schema, type SchemaOutput, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
8
7
|
export type Record<K extends PropertyKey = PropertyKey, V = any> = RecordType<K, V>;
|
|
9
8
|
export type ObjectSchemaFactoryFunction<T> = (data: T) => T;
|
|
10
9
|
export type ObjectSchemaFactory<T> = {
|
|
@@ -23,8 +22,13 @@ export type ObjectSchemaOptions<T extends Record = Record, K extends PropertyKey
|
|
|
23
22
|
factory?: ObjectSchemaFactory<T> | null;
|
|
24
23
|
};
|
|
25
24
|
export type ObjectSchemaOrType<T extends Record = any> = ObjectSchema<T> | AbstractConstructor<T>;
|
|
25
|
+
export type OptionalProperties<T> = {
|
|
26
|
+
[P in keyof T]: T[P] extends {
|
|
27
|
+
[OPTIONAL]: true;
|
|
28
|
+
} ? P : never;
|
|
29
|
+
}[keyof T];
|
|
26
30
|
export type ObjectSchemaPropertiesType<TP extends ObjectSchemaProperties> = SimplifyObject<{
|
|
27
|
-
[P in keyof PartialProperty<TP,
|
|
31
|
+
[P in keyof PartialProperty<TP, OptionalProperties<TP>>]: SchemaOutput<TP[P]>;
|
|
28
32
|
}>;
|
|
29
33
|
export declare const tryGetSchemaFromReflection: typeof _tryGetSchemaFromReflection;
|
|
30
34
|
export declare class ObjectSchema<T extends Record = Record> extends Schema<T> {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
2
|
import type { TypedOmit } from '../../types.js';
|
|
3
3
|
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
4
|
-
import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
|
+
import { type OPTIONAL, Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
5
5
|
export declare class OptionalSchema<T> extends Schema<T | undefined> {
|
|
6
|
+
readonly [OPTIONAL]: true;
|
|
6
7
|
readonly schema: Schema<T>;
|
|
7
8
|
constructor(schema: SchemaTestable<T>);
|
|
8
9
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T | undefined>;
|