@tstdl/base 0.91.51 → 0.92.0
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/ai/data-extracting.d.ts +35 -0
- package/ai/data-extracting.js +195 -41
- package/document-management/api/document-management.api.d.ts +377 -0
- package/document-management/api/document-management.api.js +15 -1
- package/document-management/index.d.ts +3 -0
- package/document-management/index.js +3 -0
- package/file/mime-type.d.ts +1 -1
- package/file/mime-type.js +8 -6
- package/file/mime-types.js +5 -32
- package/orm/schemas/numeric-date.d.ts +1 -1
- package/orm/schemas/timestamp.d.ts +1 -1
- package/package.json +2 -1
- package/schema/converters/index.d.ts +1 -0
- package/schema/converters/index.js +1 -0
- package/schema/converters/openapi-converter.d.ts +3 -0
- package/schema/converters/openapi-converter.js +113 -0
- package/schema/decorators/description.d.ts +3 -0
- package/schema/decorators/description.js +10 -0
- package/schema/decorators/property.d.ts +3 -1
- package/schema/decorators/property.js +13 -5
- package/schema/decorators/types.d.ts +5 -5
- package/schema/schema.d.ts +7 -0
- package/schema/schema.js +6 -0
- package/schema/schemas/any.d.ts +4 -3
- package/schema/schemas/any.js +4 -4
- package/schema/schemas/array.d.ts +10 -5
- package/schema/schemas/array.js +7 -3
- package/schema/schemas/bigint.d.ts +6 -6
- package/schema/schemas/bigint.js +30 -13
- package/schema/schemas/boolean.d.ts +1 -1
- package/schema/schemas/boolean.js +2 -2
- package/schema/schemas/date.d.ts +1 -1
- package/schema/schemas/date.js +2 -2
- package/schema/schemas/defaulted.d.ts +5 -4
- package/schema/schemas/defaulted.js +6 -6
- package/schema/schemas/deferred.d.ts +1 -1
- package/schema/schemas/deferred.js +2 -2
- package/schema/schemas/enumeration.d.ts +5 -4
- package/schema/schemas/enumeration.js +4 -2
- package/schema/schemas/function.d.ts +3 -3
- package/schema/schemas/function.js +5 -4
- package/schema/schemas/instance.d.ts +5 -4
- package/schema/schemas/instance.js +6 -6
- package/schema/schemas/literal.d.ts +5 -4
- package/schema/schemas/literal.js +6 -6
- package/schema/schemas/never.d.ts +3 -2
- package/schema/schemas/never.js +2 -2
- package/schema/schemas/nullable.d.ts +1 -1
- package/schema/schemas/nullable.js +1 -1
- package/schema/schemas/number.d.ts +4 -2
- package/schema/schemas/number.js +6 -3
- package/schema/schemas/object.d.ts +2 -2
- package/schema/schemas/object.js +12 -7
- package/schema/schemas/one-or-many.d.ts +5 -4
- package/schema/schemas/one-or-many.js +6 -6
- package/schema/schemas/optional.d.ts +1 -1
- package/schema/schemas/optional.js +1 -1
- package/schema/schemas/readable-stream.d.ts +1 -1
- package/schema/schemas/readable-stream.js +2 -2
- package/schema/schemas/regexp.d.ts +1 -1
- package/schema/schemas/regexp.js +2 -2
- package/schema/schemas/simple.d.ts +3 -3
- package/schema/schemas/simple.js +1 -1
- package/schema/schemas/string.d.ts +1 -1
- package/schema/schemas/string.js +2 -2
- package/schema/schemas/symbol.d.ts +6 -6
- package/schema/schemas/symbol.js +8 -13
- package/schema/schemas/uint8-array.d.ts +1 -1
- package/schema/schemas/uint8-array.js +2 -2
- package/schema/schemas/union.js +3 -3
- package/schema/schemas/unknown.d.ts +4 -3
- package/schema/schemas/unknown.js +4 -4
- package/search-index/memory/memory-search-index.js +1 -1
- package/types.d.ts +1 -1
- package/utils/helpers.d.ts +0 -40
- package/utils/helpers.js +0 -29
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/string/index.d.ts +1 -0
- package/utils/string/index.js +1 -0
- package/utils/string/normalize.d.ts +50 -0
- package/utils/string/normalize.js +39 -0
- package/utils/try-ignore.d.ts +2 -0
- package/utils/try-ignore.js +12 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { NotSupportedError } from '../../errors/not-supported.error.js';
|
|
2
|
+
import { fromEntries, objectEntries } from '../../utils/object/object.js';
|
|
3
|
+
import { isDefined, isNotNull, isNumber, isString } from '../../utils/type-guards.js';
|
|
4
|
+
import { ArraySchema } from '../schemas/array.js';
|
|
5
|
+
import { BooleanSchema } from '../schemas/boolean.js';
|
|
6
|
+
import { DateSchema } from '../schemas/date.js';
|
|
7
|
+
import { EnumerationSchema } from '../schemas/enumeration.js';
|
|
8
|
+
import { LiteralSchema } from '../schemas/literal.js';
|
|
9
|
+
import { nullable, NullableSchema } from '../schemas/nullable.js';
|
|
10
|
+
import { NumberSchema } from '../schemas/number.js';
|
|
11
|
+
import { ObjectSchema } from '../schemas/object.js';
|
|
12
|
+
import { OptionalSchema } from '../schemas/optional.js';
|
|
13
|
+
import { StringSchema } from '../schemas/string.js';
|
|
14
|
+
import { UnionSchema } from '../schemas/union.js';
|
|
15
|
+
import { schemaTestableToSchema } from '../testable.js';
|
|
16
|
+
export function convertToOpenApiSchema(testable) {
|
|
17
|
+
const schema = schemaTestableToSchema(testable);
|
|
18
|
+
return {
|
|
19
|
+
...convertToOpenApiSchemaBase(schema),
|
|
20
|
+
...(isNotNull(schema.description) ? { description: schema.description } : undefined),
|
|
21
|
+
...(isDefined(schema.example) ? { example: schema.example } : undefined)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function convertToOpenApiSchemaBase(schema) {
|
|
25
|
+
if (schema instanceof ObjectSchema) {
|
|
26
|
+
const entries = objectEntries(schema.properties);
|
|
27
|
+
const convertedEntries = entries.map(([property, propertySchema]) => [property, convertToOpenApiSchema(stripOptional(propertySchema))]);
|
|
28
|
+
return {
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties: fromEntries(convertedEntries),
|
|
31
|
+
required: entries
|
|
32
|
+
.filter(([, propertySchema]) => !(propertySchema instanceof OptionalSchema) && !((propertySchema instanceof NullableSchema) && (propertySchema.schema instanceof OptionalSchema)))
|
|
33
|
+
.map(([property]) => property)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (schema instanceof StringSchema) {
|
|
37
|
+
return {
|
|
38
|
+
type: 'string'
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (schema instanceof DateSchema) {
|
|
42
|
+
return {
|
|
43
|
+
type: 'string',
|
|
44
|
+
format: 'date-time'
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (schema instanceof NumberSchema) {
|
|
48
|
+
return {
|
|
49
|
+
type: schema.integer ? 'integer' : 'number',
|
|
50
|
+
...(isNumber(schema.minimum) ? { minimum: schema.minimum } : undefined),
|
|
51
|
+
...(isNumber(schema.maximum) ? { maximum: schema.maximum } : undefined)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if (schema instanceof BooleanSchema) {
|
|
55
|
+
return {
|
|
56
|
+
type: 'boolean'
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (schema instanceof LiteralSchema) {
|
|
60
|
+
return {
|
|
61
|
+
type: typeof schema.value,
|
|
62
|
+
enum: [schema.value]
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (schema instanceof ArraySchema) {
|
|
66
|
+
return {
|
|
67
|
+
type: 'array',
|
|
68
|
+
items: convertToOpenApiSchema(schema.itemSchema),
|
|
69
|
+
...(isNumber(schema.minimum) ? { minItems: schema.minimum } : undefined),
|
|
70
|
+
...(isNumber(schema.maximum) ? { maxItems: schema.maximum } : undefined)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (schema instanceof EnumerationSchema) {
|
|
74
|
+
const hasString = schema.allowedValues.some(isString);
|
|
75
|
+
const hasNumber = schema.allowedValues.some(isNumber);
|
|
76
|
+
if (hasString && hasNumber) {
|
|
77
|
+
throw new NotSupportedError('Enum must be either string or number but not both.');
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
type: hasString ? 'string' : 'number',
|
|
81
|
+
enum: schema.allowedValues
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (schema instanceof NullableSchema) {
|
|
85
|
+
if (schema.schema instanceof EnumerationSchema) {
|
|
86
|
+
const enumSchema = convertToOpenApiSchema(schema.schema);
|
|
87
|
+
return {
|
|
88
|
+
...enumSchema,
|
|
89
|
+
enum: [...enumSchema.enum, null],
|
|
90
|
+
nullable: true
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
...convertToOpenApiSchema(schema.schema),
|
|
95
|
+
nullable: true
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (schema instanceof UnionSchema) {
|
|
99
|
+
return {
|
|
100
|
+
oneOf: schema.schemas.map((innerSchema) => convertToOpenApiSchema(innerSchema))
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
throw new NotSupportedError(`Schema "${schema.name}" not supported.`);
|
|
104
|
+
}
|
|
105
|
+
function stripOptional(schema) {
|
|
106
|
+
if ((schema instanceof OptionalSchema)) {
|
|
107
|
+
return schema.schema;
|
|
108
|
+
}
|
|
109
|
+
if ((schema instanceof NullableSchema) && (schema.schema instanceof OptionalSchema)) {
|
|
110
|
+
return nullable(schema.schema.schema);
|
|
111
|
+
}
|
|
112
|
+
return schema;
|
|
113
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
+
import { createDecorator } from '../../reflection/index.js';
|
|
3
|
+
export function Description(options = {}) {
|
|
4
|
+
return createDecorator({
|
|
5
|
+
class: true,
|
|
6
|
+
property: true,
|
|
7
|
+
data: { schema: options },
|
|
8
|
+
mergeData: true
|
|
9
|
+
});
|
|
10
|
+
}
|
|
@@ -2,9 +2,11 @@ import type { SetRequired } from 'type-fest';
|
|
|
2
2
|
import type { Decorator } from '../../reflection/index.js';
|
|
3
3
|
import type { TypedOmit } from '../../types.js';
|
|
4
4
|
import type { SchemaTestable } from '../schema.js';
|
|
5
|
-
import type { SchemaPropertyReflectionData } from './types.js';
|
|
5
|
+
import type { SchemaPropertyReflectionData, SchemaTestableProvider } from './types.js';
|
|
6
6
|
export type SchemaPropertyDecoratorOptions = SchemaPropertyReflectionData;
|
|
7
7
|
export type SchemaPropertyDecoratorOptionsWithRequiredSchema = SetRequired<SchemaPropertyReflectionData, 'schema'>;
|
|
8
8
|
export type SchemaPropertyDecoratorOptionsWithoutSchema = TypedOmit<SchemaPropertyReflectionData, 'schema'>;
|
|
9
9
|
export declare function Property(schema: SchemaTestable, options?: SchemaPropertyDecoratorOptionsWithoutSchema): Decorator<'property' | 'accessor'>;
|
|
10
10
|
export declare function Property(options: SchemaPropertyDecoratorOptionsWithRequiredSchema): Decorator<'property' | 'accessor'>;
|
|
11
|
+
export declare function PropertySchema(schemaProvider: SchemaTestableProvider, options?: SchemaPropertyDecoratorOptionsWithoutSchema): Decorator<'property' | 'accessor'>;
|
|
12
|
+
export declare function PropertySchema(options: SchemaPropertyDecoratorOptionsWithRequiredSchema): Decorator<'property' | 'accessor'>;
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
-
import { isDefined } from '../../utils/type-guards.js';
|
|
3
|
-
import { isSchemaTestable } from '../testable.js';
|
|
2
|
+
import { isDefined, isFunction } from '../../utils/type-guards.js';
|
|
4
3
|
import { createSchemaPropertyDecorator } from './utils.js';
|
|
5
4
|
export function Property(schemaOrOptions, optionsOrNothing) {
|
|
6
5
|
if (isDefined(optionsOrNothing)) {
|
|
7
|
-
return createSchemaPropertyDecorator({ ...optionsOrNothing, schema: schemaOrOptions });
|
|
6
|
+
return createSchemaPropertyDecorator({ ...optionsOrNothing, schema: () => schemaOrOptions });
|
|
8
7
|
}
|
|
9
|
-
if (
|
|
10
|
-
return createSchemaPropertyDecorator({ schema: schemaOrOptions });
|
|
8
|
+
if (isFunction(schemaOrOptions)) {
|
|
9
|
+
return createSchemaPropertyDecorator({ schema: () => schemaOrOptions });
|
|
11
10
|
}
|
|
12
11
|
return createSchemaPropertyDecorator(schemaOrOptions);
|
|
13
12
|
}
|
|
13
|
+
export function PropertySchema(schemaProviderOrOptions, optionsOrNothing) {
|
|
14
|
+
if (isDefined(optionsOrNothing)) {
|
|
15
|
+
return createSchemaPropertyDecorator({ ...optionsOrNothing, schema: schemaProviderOrOptions });
|
|
16
|
+
}
|
|
17
|
+
if (isFunction(schemaProviderOrOptions)) {
|
|
18
|
+
return createSchemaPropertyDecorator({ schema: schemaProviderOrOptions });
|
|
19
|
+
}
|
|
20
|
+
return createSchemaPropertyDecorator(schemaProviderOrOptions);
|
|
21
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { Decorator } from '../../reflection/types.js';
|
|
2
|
-
import type { SchemaTestable } from '../schema.js';
|
|
2
|
+
import type { SchemaOptions, SchemaTestable } from '../schema.js';
|
|
3
3
|
import type { ObjectSchemaFactory, ObjectSchemaOptions } from '../schemas/object.js';
|
|
4
4
|
export type SchemaClassDecorator = Decorator<'class'>;
|
|
5
5
|
export type SchemaPropertyDecorator = Decorator<'property' | 'accessor'>;
|
|
6
|
-
export type SchemaTypeReflectionData = Partial<Pick<ObjectSchemaOptions, 'mask' | 'unknownProperties' | 'unknownPropertiesKey'>> & {
|
|
6
|
+
export type SchemaTypeReflectionData = Partial<Pick<ObjectSchemaOptions, 'mask' | 'unknownProperties' | 'unknownPropertiesKey' | 'description' | 'example'>> & {
|
|
7
7
|
schema?: SchemaTestable;
|
|
8
8
|
factory?: ObjectSchemaFactory<any>;
|
|
9
9
|
};
|
|
10
|
-
export type
|
|
11
|
-
|
|
10
|
+
export type SchemaTestableProvider = (data: SchemaPropertyReflectionData) => SchemaTestable;
|
|
11
|
+
export type SchemaPropertyReflectionData = Partial<Pick<SchemaOptions<any>, 'description' | 'example'>> & {
|
|
12
|
+
schema?: SchemaTestableProvider;
|
|
12
13
|
array?: boolean;
|
|
13
14
|
optional?: boolean;
|
|
14
15
|
nullable?: boolean;
|
|
15
|
-
data?: Record<PropertyKey, any>;
|
|
16
16
|
};
|
package/schema/schema.d.ts
CHANGED
|
@@ -22,9 +22,16 @@ type NormalizePrimitiveToConstructor<T> = Or<IsEqual<T, string>, IsEqual<T, Stri
|
|
|
22
22
|
export type SchemaTestable<T = unknown> = Schema<T> | AbstractConstructor<T> | NormalizePrimitiveToConstructor<T>;
|
|
23
23
|
export type SchemaOutput<T extends SchemaTestable> = T extends SchemaTestable<infer U> ? U : never;
|
|
24
24
|
export declare const OPTIONAL: unique symbol;
|
|
25
|
+
export type SchemaOptions<T> = {
|
|
26
|
+
description?: string | null;
|
|
27
|
+
example?: T | undefined;
|
|
28
|
+
};
|
|
25
29
|
export declare abstract class Schema<T = unknown> {
|
|
26
30
|
readonly [OPTIONAL]: boolean;
|
|
31
|
+
readonly description: string | null;
|
|
32
|
+
readonly example: T | undefined;
|
|
27
33
|
abstract readonly name: string;
|
|
34
|
+
constructor(options?: SchemaOptions<T>);
|
|
28
35
|
/**
|
|
29
36
|
* Test an unknown value to see whether it corresponds to the schema.
|
|
30
37
|
* @param schema schema to test against
|
package/schema/schema.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { JsonPath } from '../json-path/json-path.js';
|
|
2
2
|
export class Schema {
|
|
3
|
+
description;
|
|
4
|
+
example;
|
|
5
|
+
constructor(options) {
|
|
6
|
+
this.description = options?.description ?? null;
|
|
7
|
+
this.example = options?.example;
|
|
8
|
+
}
|
|
3
9
|
/**
|
|
4
10
|
* Test an unknown value to see whether it corresponds to the schema.
|
|
5
11
|
* @param schema schema to test against
|
package/schema/schemas/any.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
2
|
-
import { Schema, type SchemaTestResult } from '../schema.js';
|
|
2
|
+
import { Schema, type SchemaOptions, type SchemaTestResult } from '../schema.js';
|
|
3
|
+
export type AnySchemaOptions = SchemaOptions<any>;
|
|
3
4
|
export declare class AnySchema extends Schema<any> {
|
|
4
5
|
readonly name = "any";
|
|
5
6
|
_test(value: any): SchemaTestResult<any>;
|
|
6
7
|
}
|
|
7
|
-
export declare function any(): AnySchema;
|
|
8
|
-
export declare function Any(options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
8
|
+
export declare function any(options?: AnySchemaOptions): AnySchema;
|
|
9
|
+
export declare function Any(options?: AnySchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
package/schema/schemas/any.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PropertySchema } from '../decorators/index.js';
|
|
2
2
|
import { Schema } from '../schema.js';
|
|
3
3
|
export class AnySchema extends Schema {
|
|
4
4
|
name = 'any';
|
|
@@ -6,9 +6,9 @@ export class AnySchema extends Schema {
|
|
|
6
6
|
return { valid: true, value };
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
export function any() {
|
|
10
|
-
return new AnySchema();
|
|
9
|
+
export function any(options) {
|
|
10
|
+
return new AnySchema(options);
|
|
11
11
|
}
|
|
12
12
|
export function Any(options) {
|
|
13
|
-
return
|
|
13
|
+
return PropertySchema((data) => any({ description: data.description, example: data.example, ...options }), options);
|
|
14
14
|
}
|
|
@@ -1,15 +1,20 @@
|
|
|
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 { Schema, type SchemaOptions, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
5
5
|
import type { Coercible } from '../types.js';
|
|
6
|
-
export type ArraySchemaOptions = Coercible
|
|
6
|
+
export type ArraySchemaOptions<T> = SchemaOptions<T[]> & Coercible & {
|
|
7
|
+
minimum?: number;
|
|
8
|
+
maximum?: number;
|
|
9
|
+
};
|
|
7
10
|
export declare class ArraySchema<T> extends Schema<T[]> {
|
|
8
11
|
#private;
|
|
9
12
|
readonly name: string;
|
|
10
13
|
readonly itemSchema: Schema<T>;
|
|
11
|
-
|
|
14
|
+
readonly minimum: number | null;
|
|
15
|
+
readonly maximum: number | null;
|
|
16
|
+
constructor(itemSchema: SchemaTestable<T>, options?: ArraySchemaOptions<T>);
|
|
12
17
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T[]>;
|
|
13
18
|
}
|
|
14
|
-
export declare function array<T>(schema: SchemaTestable<T>, options?: ArraySchemaOptions): ArraySchema<T>;
|
|
15
|
-
export declare function Array(schema: SchemaTestable, options?: ArraySchemaOptions & TypedOmit<SchemaPropertyDecoratorOptions, 'array'>): SchemaPropertyDecorator;
|
|
19
|
+
export declare function array<T>(schema: SchemaTestable<T>, options?: ArraySchemaOptions<T>): ArraySchema<T>;
|
|
20
|
+
export declare function Array(schema: SchemaTestable, options?: ArraySchemaOptions<unknown> & TypedOmit<SchemaPropertyDecoratorOptions, 'array'>): SchemaPropertyDecorator;
|
package/schema/schemas/array.js
CHANGED
|
@@ -2,17 +2,21 @@ import { SchemaError } from '../../schema/schema.error.js';
|
|
|
2
2
|
import { lazyProperty } from '../../utils/object/lazy-property.js';
|
|
3
3
|
import { isArray } from '../../utils/type-guards.js';
|
|
4
4
|
import { typeOf } from '../../utils/type-of.js';
|
|
5
|
-
import {
|
|
5
|
+
import { PropertySchema } from '../decorators/index.js';
|
|
6
6
|
import { Schema } from '../schema.js';
|
|
7
7
|
import { schemaTestableToSchema } from '../testable.js';
|
|
8
8
|
export class ArraySchema extends Schema {
|
|
9
9
|
#options;
|
|
10
10
|
name;
|
|
11
11
|
itemSchema;
|
|
12
|
+
minimum;
|
|
13
|
+
maximum;
|
|
12
14
|
constructor(itemSchema, options = {}) {
|
|
13
|
-
super();
|
|
15
|
+
super(options);
|
|
14
16
|
this.#options = options;
|
|
15
17
|
this.itemSchema = schemaTestableToSchema(itemSchema);
|
|
18
|
+
this.minimum = options.minimum ?? null;
|
|
19
|
+
this.maximum = options.maximum ?? null;
|
|
16
20
|
lazyProperty(this, 'name', () => `Array[${this.itemSchema.name}]`);
|
|
17
21
|
}
|
|
18
22
|
_test(value, path, options) {
|
|
@@ -37,5 +41,5 @@ export function array(schema, options) {
|
|
|
37
41
|
return new ArraySchema(schema, options);
|
|
38
42
|
}
|
|
39
43
|
export function Array(schema, options) {
|
|
40
|
-
return
|
|
44
|
+
return PropertySchema((data) => array(schema, { description: data.description, example: data.example, ...options }), options);
|
|
41
45
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
1
|
import { type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
3
2
|
import type { SchemaPropertyDecorator } from '../decorators/types.js';
|
|
4
|
-
import {
|
|
5
|
-
export
|
|
3
|
+
import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
|
|
4
|
+
export type BigIntSchemaOptions = SimpleSchemaOptions<bigint>;
|
|
5
|
+
export declare class BigIntSchema extends SimpleSchema<bigint> {
|
|
6
6
|
readonly name = "bigint";
|
|
7
|
-
|
|
7
|
+
constructor(options?: BigIntSchemaOptions);
|
|
8
8
|
}
|
|
9
|
-
export declare function bigint(): BigIntSchema;
|
|
10
|
-
export declare function BigIntProperty(options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
9
|
+
export declare function bigint(options?: BigIntSchemaOptions): BigIntSchema;
|
|
10
|
+
export declare function BigIntProperty(options?: BigIntSchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
package/schema/schemas/bigint.js
CHANGED
|
@@ -1,20 +1,37 @@
|
|
|
1
|
-
import { SchemaError } from '../../schema/schema.error.js';
|
|
2
1
|
import { isBigInt } from '../../utils/type-guards.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
export class BigIntSchema extends
|
|
2
|
+
import { PropertySchema } from '../decorators/index.js';
|
|
3
|
+
import { SchemaError } from '../schema.error.js';
|
|
4
|
+
import { SimpleSchema } from './simple.js';
|
|
5
|
+
export class BigIntSchema extends SimpleSchema {
|
|
7
6
|
name = 'bigint';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
constructor(options) {
|
|
8
|
+
super('bigint', isBigInt, options, {
|
|
9
|
+
coercers: {
|
|
10
|
+
number(value, path, coerceOptions) {
|
|
11
|
+
try {
|
|
12
|
+
const bigIntValue = BigInt(value);
|
|
13
|
+
return { success: true, value: bigIntValue, valid: true };
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
return { success: false, error: SchemaError.couldNotCoerce('bigint', 'number', path, { fast: coerceOptions.fastErrors, customMessage: error.message }) };
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
string(value, path, coerceOptions) {
|
|
20
|
+
try {
|
|
21
|
+
const bigIntValue = BigInt(value);
|
|
22
|
+
return { success: true, value: bigIntValue, valid: true };
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
return { success: false, error: SchemaError.couldNotCoerce('bigint', 'string', path, { fast: coerceOptions.fastErrors, customMessage: error.message }) };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
13
30
|
}
|
|
14
31
|
}
|
|
15
|
-
export function bigint() {
|
|
16
|
-
return new BigIntSchema();
|
|
32
|
+
export function bigint(options) {
|
|
33
|
+
return new BigIntSchema(options);
|
|
17
34
|
}
|
|
18
35
|
export function BigIntProperty(options) {
|
|
19
|
-
return
|
|
36
|
+
return PropertySchema((data) => bigint({ description: data.description, example: data.example, ...options }), options);
|
|
20
37
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
2
2
|
import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
|
|
3
|
-
export type BooleanSchemaOptions = SimpleSchemaOptions
|
|
3
|
+
export type BooleanSchemaOptions = SimpleSchemaOptions<boolean>;
|
|
4
4
|
export declare class BooleanSchema extends SimpleSchema<boolean> {
|
|
5
5
|
readonly name = "boolean";
|
|
6
6
|
constructor(options?: BooleanSchemaOptions);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isBoolean, isString } from '../../utils/type-guards.js';
|
|
2
|
-
import {
|
|
2
|
+
import { PropertySchema } from '../decorators/index.js';
|
|
3
3
|
import { SimpleSchema } from './simple.js';
|
|
4
4
|
export class BooleanSchema extends SimpleSchema {
|
|
5
5
|
name = 'boolean';
|
|
@@ -33,5 +33,5 @@ export function boolean(options) {
|
|
|
33
33
|
return new BooleanSchema(options);
|
|
34
34
|
}
|
|
35
35
|
export function BooleanProperty(options) {
|
|
36
|
-
return
|
|
36
|
+
return PropertySchema((data) => boolean({ description: data.description, example: data.example, ...options }), options);
|
|
37
37
|
}
|
package/schema/schemas/date.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
2
2
|
import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
|
|
3
|
-
export type DateSchemaOptions = SimpleSchemaOptions & {
|
|
3
|
+
export type DateSchemaOptions = SimpleSchemaOptions<globalThis.Date> & {
|
|
4
4
|
integer?: boolean;
|
|
5
5
|
};
|
|
6
6
|
export declare class DateSchema extends SimpleSchema<globalThis.Date> {
|
package/schema/schemas/date.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isValidDate } from '../../utils/type-guards.js';
|
|
2
|
-
import {
|
|
2
|
+
import { PropertySchema } from '../decorators/index.js';
|
|
3
3
|
import { SchemaError } from '../schema.error.js';
|
|
4
4
|
import { SimpleSchema } from './simple.js';
|
|
5
5
|
export class DateSchema extends SimpleSchema {
|
|
@@ -25,5 +25,5 @@ export function date(options) {
|
|
|
25
25
|
return new DateSchema(options);
|
|
26
26
|
}
|
|
27
27
|
export function DateProperty(options) {
|
|
28
|
-
return
|
|
28
|
+
return PropertySchema((data) => date({ description: data.description, example: data.example, ...options }), options);
|
|
29
29
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
2
|
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
3
|
-
import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
3
|
+
import { Schema, type SchemaOptions, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
|
+
export type DefaultSchemaOptions<T, D> = SchemaOptions<T | D>;
|
|
4
5
|
export declare class DefaultSchema<T, D> extends Schema<T | D> {
|
|
5
6
|
readonly name: string;
|
|
6
7
|
readonly schema: Schema<T>;
|
|
7
8
|
readonly defaultValue: D;
|
|
8
|
-
constructor(schema: SchemaTestable<T>, defaultValue: D);
|
|
9
|
+
constructor(schema: SchemaTestable<T>, defaultValue: D, options?: DefaultSchemaOptions<T, D>);
|
|
9
10
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T | D>;
|
|
10
11
|
}
|
|
11
|
-
export declare function defaulted<T, D>(schema: SchemaTestable<T>, defaultValue: D): DefaultSchema<T, D>;
|
|
12
|
-
export declare function Defaulted<T, D>(schema: SchemaTestable<T>, defaultValue: D, options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
12
|
+
export declare function defaulted<T, D>(schema: SchemaTestable<T>, defaultValue: D, options?: DefaultSchemaOptions<T, D>): DefaultSchema<T, D>;
|
|
13
|
+
export declare function Defaulted<T, D>(schema: SchemaTestable<T>, defaultValue: D, options?: DefaultSchemaOptions<T, D> & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { lazyProperty } from '../../utils/object/lazy-property.js';
|
|
2
2
|
import { isNullOrUndefined } from '../../utils/type-guards.js';
|
|
3
|
-
import {
|
|
3
|
+
import { PropertySchema } from '../decorators/index.js';
|
|
4
4
|
import { Schema } from '../schema.js';
|
|
5
5
|
import { schemaTestableToSchema } from '../testable.js';
|
|
6
6
|
export class DefaultSchema extends Schema {
|
|
7
7
|
name;
|
|
8
8
|
schema;
|
|
9
9
|
defaultValue;
|
|
10
|
-
constructor(schema, defaultValue) {
|
|
11
|
-
super();
|
|
10
|
+
constructor(schema, defaultValue, options) {
|
|
11
|
+
super(options);
|
|
12
12
|
this.schema = schemaTestableToSchema(schema);
|
|
13
13
|
this.defaultValue = defaultValue;
|
|
14
14
|
lazyProperty(this, 'name', () => `Defaulted[${this.schema.name}]`);
|
|
@@ -20,9 +20,9 @@ export class DefaultSchema extends Schema {
|
|
|
20
20
|
return this.schema._test(value, path, options);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
export function defaulted(schema, defaultValue) {
|
|
24
|
-
return new DefaultSchema(schema, defaultValue);
|
|
23
|
+
export function defaulted(schema, defaultValue, options) {
|
|
24
|
+
return new DefaultSchema(schema, defaultValue, options);
|
|
25
25
|
}
|
|
26
26
|
export function Defaulted(schema, defaultValue, options) {
|
|
27
|
-
return
|
|
27
|
+
return PropertySchema((data) => defaulted(schema, defaultValue, { description: data.description, example: data.example, ...options }), options);
|
|
28
28
|
}
|
|
@@ -9,4 +9,4 @@ export declare class DeferredSchema<T extends SchemaTestable> extends Schema<Sch
|
|
|
9
9
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<SchemaOutput<T>>;
|
|
10
10
|
}
|
|
11
11
|
export declare function deferred<T extends SchemaTestable>(schema: () => T): DeferredSchema<T>;
|
|
12
|
-
export declare function Deferred
|
|
12
|
+
export declare function Deferred(schema: () => SchemaTestable, options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { lazyProperty } from '../../utils/object/lazy-property.js';
|
|
2
|
-
import {
|
|
2
|
+
import { PropertySchema } from '../decorators/index.js';
|
|
3
3
|
import { Schema } from '../schema.js';
|
|
4
4
|
import { schemaTestableToSchema } from '../testable.js';
|
|
5
5
|
export class DeferredSchema extends Schema {
|
|
@@ -19,5 +19,5 @@ export function deferred(schema) {
|
|
|
19
19
|
return new DeferredSchema(schema);
|
|
20
20
|
}
|
|
21
21
|
export function Deferred(schema, options) {
|
|
22
|
-
return
|
|
22
|
+
return PropertySchema(() => deferred(schema), options);
|
|
23
23
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { Enumeration as EnumerationType, EnumerationValue } from '../../types.js';
|
|
2
2
|
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
3
3
|
import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
|
|
4
|
-
export type EnumerationSchemaOptions = SimpleSchemaOptions
|
|
4
|
+
export type EnumerationSchemaOptions<T extends EnumerationType> = SimpleSchemaOptions<EnumerationValue<T>>;
|
|
5
5
|
export declare class EnumerationSchema<const T extends EnumerationType> extends SimpleSchema<EnumerationValue<T>> {
|
|
6
6
|
#private;
|
|
7
7
|
readonly name: string;
|
|
8
8
|
readonly enumeration: EnumerationType;
|
|
9
|
-
|
|
9
|
+
readonly allowedValues: readonly EnumerationValue<T>[];
|
|
10
|
+
constructor(enumeration: T, options?: EnumerationSchemaOptions<T>);
|
|
10
11
|
}
|
|
11
|
-
export declare function enumeration<const T extends EnumerationType>(enumeration: T, options?: EnumerationSchemaOptions): EnumerationSchema<T>;
|
|
12
|
-
export declare function Enumeration(enumeration:
|
|
12
|
+
export declare function enumeration<const T extends EnumerationType>(enumeration: T, options?: EnumerationSchemaOptions<T>): EnumerationSchema<T>;
|
|
13
|
+
export declare function Enumeration<const T extends EnumerationType>(enumeration: T, options?: EnumerationSchemaOptions<T> & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { enumValues } from '../../utils/enum.js';
|
|
2
2
|
import { lazyProperty } from '../../utils/object/lazy-property.js';
|
|
3
3
|
import { isArray, isString } from '../../utils/type-guards.js';
|
|
4
|
-
import {
|
|
4
|
+
import { PropertySchema } from '../decorators/index.js';
|
|
5
5
|
import { SimpleSchema } from './simple.js';
|
|
6
6
|
export class EnumerationSchema extends SimpleSchema {
|
|
7
7
|
#allowedValuesSet;
|
|
8
8
|
name;
|
|
9
9
|
enumeration;
|
|
10
|
+
allowedValues;
|
|
10
11
|
constructor(enumeration, options) {
|
|
11
12
|
const allowedValues = isArray(enumeration) ? enumeration : enumValues(enumeration);
|
|
12
13
|
const allowedValuesString = allowedValues.map((value) => (isString(value) ? `"${value}"` : String(value))).join(', ');
|
|
@@ -18,6 +19,7 @@ export class EnumerationSchema extends SimpleSchema {
|
|
|
18
19
|
gotValueFormatter: (value) => isString(value) ? `"${value}"` : String(value)
|
|
19
20
|
});
|
|
20
21
|
this.enumeration = enumeration;
|
|
22
|
+
this.allowedValues = allowedValues;
|
|
21
23
|
this.#allowedValuesSet = new Set(allowedValues);
|
|
22
24
|
lazyProperty(this, 'name', () => `Enumeration[${allowedValuesString}]`);
|
|
23
25
|
}
|
|
@@ -26,5 +28,5 @@ export function enumeration(enumeration, options) {
|
|
|
26
28
|
return new EnumerationSchema(enumeration, options);
|
|
27
29
|
}
|
|
28
30
|
export function Enumeration(enums, options) {
|
|
29
|
-
return
|
|
31
|
+
return PropertySchema((data) => enumeration(enums, { description: data.description, example: data.example, ...options }), options);
|
|
30
32
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
2
2
|
import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
|
|
3
|
-
export type FunctionSchemaOptions = SimpleSchemaOptions
|
|
3
|
+
export type FunctionSchemaOptions = SimpleSchemaOptions<Function>;
|
|
4
4
|
export declare class FunctionSchema extends SimpleSchema<Function> {
|
|
5
5
|
readonly name = "function";
|
|
6
6
|
constructor(options?: FunctionSchemaOptions);
|
|
7
7
|
}
|
|
8
|
-
export declare function func(): FunctionSchema;
|
|
9
|
-
export declare function FunctionProperty(options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
8
|
+
export declare function func(options?: FunctionSchemaOptions): FunctionSchema;
|
|
9
|
+
export declare function FunctionProperty(options?: FunctionSchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-function-type */
|
|
1
2
|
import { isFunction } from '../../utils/type-guards.js';
|
|
2
|
-
import {
|
|
3
|
+
import { PropertySchema } from '../decorators/index.js';
|
|
3
4
|
import { SimpleSchema } from './simple.js';
|
|
4
5
|
export class FunctionSchema extends SimpleSchema {
|
|
5
6
|
name = 'function';
|
|
@@ -7,9 +8,9 @@ export class FunctionSchema extends SimpleSchema {
|
|
|
7
8
|
super('function', isFunction, options);
|
|
8
9
|
}
|
|
9
10
|
}
|
|
10
|
-
export function func() {
|
|
11
|
-
return new FunctionSchema();
|
|
11
|
+
export function func(options) {
|
|
12
|
+
return new FunctionSchema(options);
|
|
12
13
|
}
|
|
13
14
|
export function FunctionProperty(options) {
|
|
14
|
-
return
|
|
15
|
+
return PropertySchema((data) => func({ description: data.description, example: data.example, ...options }), options);
|
|
15
16
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
2
|
import type { AbstractConstructor } from '../../types.js';
|
|
3
3
|
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
4
|
-
import { Schema, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
|
+
import { Schema, type SchemaOptions, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
5
|
+
export type InstanceSchemaOptions<T extends AbstractConstructor> = SchemaOptions<InstanceType<T>>;
|
|
5
6
|
export declare class InstanceSchema<T extends AbstractConstructor> extends Schema<InstanceType<T>> {
|
|
6
7
|
readonly name: string;
|
|
7
8
|
readonly type: T;
|
|
8
|
-
constructor(type: T);
|
|
9
|
+
constructor(type: T, options?: InstanceSchemaOptions<T>);
|
|
9
10
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<InstanceType<T>>;
|
|
10
11
|
}
|
|
11
|
-
export declare function instance<T extends AbstractConstructor>(type: T): InstanceSchema<T>;
|
|
12
|
-
export declare function Instance(type:
|
|
12
|
+
export declare function instance<T extends AbstractConstructor>(type: T, options?: InstanceSchemaOptions<T>): InstanceSchema<T>;
|
|
13
|
+
export declare function Instance<T extends AbstractConstructor>(type: T, options?: InstanceSchemaOptions<T> & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|