@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
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { lazyProperty } from '../../utils/object/lazy-property.js';
|
|
2
2
|
import { typeOf } from '../../utils/type-of.js';
|
|
3
|
-
import {
|
|
3
|
+
import { PropertySchema } from '../decorators/index.js';
|
|
4
4
|
import { SchemaError } from '../schema.error.js';
|
|
5
5
|
import { Schema } from '../schema.js';
|
|
6
6
|
export class InstanceSchema extends Schema {
|
|
7
7
|
name;
|
|
8
8
|
type;
|
|
9
|
-
constructor(type) {
|
|
10
|
-
super();
|
|
9
|
+
constructor(type, options) {
|
|
10
|
+
super(options);
|
|
11
11
|
this.type = type;
|
|
12
12
|
lazyProperty(this, 'name', () => `Instance[${type.name}]`);
|
|
13
13
|
}
|
|
@@ -21,9 +21,9 @@ export class InstanceSchema extends Schema {
|
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
export function instance(type) {
|
|
25
|
-
return new InstanceSchema(type);
|
|
24
|
+
export function instance(type, options) {
|
|
25
|
+
return new InstanceSchema(type, options);
|
|
26
26
|
}
|
|
27
27
|
export function Instance(type, options) {
|
|
28
|
-
return
|
|
28
|
+
return PropertySchema((data) => instance(type, { description: data.description, example: data.example, ...options }), options);
|
|
29
29
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
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 SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
3
|
+
import { Schema, SchemaOptions, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
|
+
export type LiteralSchemaOptions<T> = SchemaOptions<T>;
|
|
4
5
|
export declare class LiteralSchema<const T> extends Schema<T> {
|
|
5
6
|
readonly name: string;
|
|
6
7
|
readonly value: T;
|
|
7
|
-
constructor(value: T);
|
|
8
|
+
constructor(value: T, options?: LiteralSchemaOptions<T>);
|
|
8
9
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T>;
|
|
9
10
|
}
|
|
10
|
-
export declare function literal<const T>(value: T): LiteralSchema<T>;
|
|
11
|
-
export declare function Literal(value:
|
|
11
|
+
export declare function literal<const T>(value: T, options?: LiteralSchemaOptions<T>): LiteralSchema<T>;
|
|
12
|
+
export declare function Literal<const T>(value: T, options?: LiteralSchemaOptions<T> & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { lazyProperty } from '../../utils/object/lazy-property.js';
|
|
2
2
|
import { isPrimitive } from '../../utils/type-guards.js';
|
|
3
3
|
import { typeOf } from '../../utils/type-of.js';
|
|
4
|
-
import {
|
|
4
|
+
import { PropertySchema } from '../decorators/index.js';
|
|
5
5
|
import { SchemaError } from '../schema.error.js';
|
|
6
6
|
import { Schema } from '../schema.js';
|
|
7
7
|
export class LiteralSchema extends Schema {
|
|
8
8
|
name;
|
|
9
9
|
value;
|
|
10
|
-
constructor(value) {
|
|
11
|
-
super();
|
|
10
|
+
constructor(value, options) {
|
|
11
|
+
super(options);
|
|
12
12
|
this.value = value;
|
|
13
13
|
lazyProperty(this, 'name', () => `Literal[${String(value)}]`);
|
|
14
14
|
}
|
|
@@ -22,9 +22,9 @@ export class LiteralSchema extends Schema {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
export function literal(value) {
|
|
26
|
-
return new LiteralSchema(value);
|
|
25
|
+
export function literal(value, options) {
|
|
26
|
+
return new LiteralSchema(value, options);
|
|
27
27
|
}
|
|
28
28
|
export function Literal(value, options) {
|
|
29
|
-
return
|
|
29
|
+
return PropertySchema((data) => literal(value, { description: data.description, example: data.example, ...options }), options);
|
|
30
30
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
-
import { Schema, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
2
|
+
import { Schema, SchemaOptions, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
3
|
+
export type NeverSchemaOptions = SchemaOptions<never>;
|
|
3
4
|
export declare class NeverSchema extends Schema<never> {
|
|
4
5
|
readonly name = "never";
|
|
5
6
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<never>;
|
|
6
7
|
}
|
|
7
|
-
export declare function never(): NeverSchema;
|
|
8
|
+
export declare function never(options?: NeverSchemaOptions): NeverSchema;
|
package/schema/schemas/never.js
CHANGED
|
@@ -7,6 +7,6 @@ export class NeverSchema extends Schema {
|
|
|
7
7
|
return { valid: false, error: SchemaError.expectedButGot('never', typeOf(value), path, { fast: options.fastErrors }) };
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
export function never() {
|
|
11
|
-
return new NeverSchema();
|
|
10
|
+
export function never(options) {
|
|
11
|
+
return new NeverSchema(options);
|
|
12
12
|
}
|
|
@@ -9,4 +9,4 @@ export declare class NullableSchema<T> extends Schema<T | null> {
|
|
|
9
9
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T | null>;
|
|
10
10
|
}
|
|
11
11
|
export declare function nullable<T>(schema: SchemaTestable<T>): NullableSchema<T>;
|
|
12
|
-
export declare function Nullable(schema?: SchemaTestable
|
|
12
|
+
export declare function Nullable<T>(schema?: SchemaTestable<T>, options?: TypedOmit<SchemaPropertyDecoratorOptions, 'nullable'>): SchemaPropertyDecorator;
|
|
@@ -25,5 +25,5 @@ export function nullable(schema) {
|
|
|
25
25
|
return new NullableSchema(schema);
|
|
26
26
|
}
|
|
27
27
|
export function Nullable(schema, options) {
|
|
28
|
-
return createSchemaPropertyDecorator({ schema, ...options, nullable: true });
|
|
28
|
+
return createSchemaPropertyDecorator({ schema: () => schema, ...options, nullable: true });
|
|
29
29
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { TypedOmit } from '../../types.js';
|
|
1
2
|
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
2
3
|
import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
|
|
3
|
-
export type NumberSchemaOptions = SimpleSchemaOptions & {
|
|
4
|
+
export type NumberSchemaOptions = SimpleSchemaOptions<number> & {
|
|
4
5
|
integer?: boolean;
|
|
5
6
|
minimum?: number;
|
|
6
7
|
maximum?: number;
|
|
@@ -13,5 +14,6 @@ export declare class NumberSchema extends SimpleSchema<number> {
|
|
|
13
14
|
constructor(options?: NumberSchemaOptions);
|
|
14
15
|
}
|
|
15
16
|
export declare function number(options?: NumberSchemaOptions): NumberSchema;
|
|
17
|
+
export declare function integer(options?: TypedOmit<NumberSchemaOptions, 'integer'>): NumberSchema;
|
|
16
18
|
export declare function NumberProperty(options?: SchemaPropertyDecoratorOptions & NumberSchemaOptions): SchemaPropertyDecorator;
|
|
17
|
-
export declare function Integer(options?: SchemaPropertyDecoratorOptions & NumberSchemaOptions): SchemaPropertyDecorator;
|
|
19
|
+
export declare function Integer(options?: SchemaPropertyDecoratorOptions & TypedOmit<NumberSchemaOptions, 'integer'>): SchemaPropertyDecorator;
|
package/schema/schemas/number.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isNumber } 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 NumberSchema extends SimpleSchema {
|
|
@@ -33,9 +33,12 @@ export class NumberSchema extends SimpleSchema {
|
|
|
33
33
|
export function number(options) {
|
|
34
34
|
return new NumberSchema(options);
|
|
35
35
|
}
|
|
36
|
+
export function integer(options) {
|
|
37
|
+
return number({ ...options, integer: true });
|
|
38
|
+
}
|
|
36
39
|
export function NumberProperty(options) {
|
|
37
|
-
return
|
|
40
|
+
return PropertySchema((data) => number({ description: data.description, example: data.example, ...options }), options);
|
|
38
41
|
}
|
|
39
42
|
export function Integer(options) {
|
|
40
|
-
return
|
|
43
|
+
return PropertySchema((data) => number({ description: data.description, example: data.example, ...options, integer: true }), options);
|
|
41
44
|
}
|
|
@@ -3,7 +3,7 @@ import type { JsonPath } from '../../json-path/json-path.js';
|
|
|
3
3
|
import { type Decorator } from '../../reflection/index.js';
|
|
4
4
|
import type { AbstractConstructor, OneOrMany, PartialProperty, Record as RecordType, SimplifyObject, Type, TypedOmit } from '../../types.js';
|
|
5
5
|
import { type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
6
|
-
import { type OPTIONAL, Schema, type SchemaOutput, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
6
|
+
import { type OPTIONAL, Schema, type SchemaOptions, type SchemaOutput, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
7
7
|
export type Record<K extends PropertyKey = PropertyKey, V = any> = RecordType<K, V>;
|
|
8
8
|
export type ObjectSchemaFactoryFunction<T> = (data: T) => T;
|
|
9
9
|
export type ObjectSchemaFactory<T> = {
|
|
@@ -15,7 +15,7 @@ export type ObjectSchemaProperties<T extends Record = Record> = {
|
|
|
15
15
|
export type NormalizedObjectSchemaProperties<T extends Record> = {
|
|
16
16
|
[P in keyof T]-?: Schema<T[P]>;
|
|
17
17
|
};
|
|
18
|
-
export type ObjectSchemaOptions<T extends Record = Record, K extends PropertyKey = PropertyKey, V = unknown> = {
|
|
18
|
+
export type ObjectSchemaOptions<T extends Record = Record, K extends PropertyKey = PropertyKey, V = unknown> = SchemaOptions<T> & {
|
|
19
19
|
name?: string;
|
|
20
20
|
mask?: boolean | null;
|
|
21
21
|
unknownPropertiesKey?: SchemaTestable<K> | null;
|
package/schema/schemas/object.js
CHANGED
|
@@ -6,7 +6,7 @@ import { memoizeSingle } from '../../utils/function/memoize.js';
|
|
|
6
6
|
import { filterObject, fromEntries, mapObjectValues, objectKeys } from '../../utils/object/object.js';
|
|
7
7
|
import { assert, isArray, isDefined, isFunction, isLiteralObject, isNotNull, isNotNullOrUndefined, isNull, isObject, isUndefined } from '../../utils/type-guards.js';
|
|
8
8
|
import { typeOf } from '../../utils/type-of.js';
|
|
9
|
-
import { Class,
|
|
9
|
+
import { Class, PropertySchema } from '../decorators/index.js';
|
|
10
10
|
import { Schema } from '../schema.js';
|
|
11
11
|
import { schemaTestableToSchema } from '../testable.js';
|
|
12
12
|
import { array } from './array.js';
|
|
@@ -23,7 +23,7 @@ export class ObjectSchema extends Schema {
|
|
|
23
23
|
unknownPropertiesKey;
|
|
24
24
|
factory;
|
|
25
25
|
constructor(properties, options = {}) {
|
|
26
|
-
super();
|
|
26
|
+
super(options);
|
|
27
27
|
this.properties = mapObjectValues(properties, (value) => schemaTestableToSchema(value));
|
|
28
28
|
this.mask = options.mask ?? null;
|
|
29
29
|
this.unknownProperties = isNotNullOrUndefined(options.unknownProperties) ? schemaTestableToSchema(options.unknownProperties) : null;
|
|
@@ -92,7 +92,8 @@ export function assign(...schemasOrTypes) {
|
|
|
92
92
|
name: schemas.at(-1)?.name,
|
|
93
93
|
mask: schemas.findLast((schema) => isNotNull(schema.mask))?.mask,
|
|
94
94
|
unknownProperties: schemas.findLast((schema) => isNotNull(schema.unknownProperties))?.unknownProperties,
|
|
95
|
-
unknownPropertiesKey: schemas.findLast((schema) => isNotNull(schema.unknownPropertiesKey))?.unknownPropertiesKey
|
|
95
|
+
unknownPropertiesKey: schemas.findLast((schema) => isNotNull(schema.unknownPropertiesKey))?.unknownPropertiesKey,
|
|
96
|
+
description: schemas.findLast((schema) => isNotNull(schema.description))?.description
|
|
96
97
|
});
|
|
97
98
|
}
|
|
98
99
|
export function partial(schemaOrType, keyOrKeys) {
|
|
@@ -149,13 +150,17 @@ function _tryGetSchemaFromReflection(type) {
|
|
|
149
150
|
factory: isDefined(typeData.factory) ? typeData.factory : { type: type },
|
|
150
151
|
mask: typeData.mask,
|
|
151
152
|
unknownProperties: typeData.unknownProperties,
|
|
152
|
-
unknownPropertiesKey: typeData.unknownPropertiesKey
|
|
153
|
+
unknownPropertiesKey: typeData.unknownPropertiesKey,
|
|
154
|
+
description: typeData.description,
|
|
155
|
+
example: typeData.example
|
|
153
156
|
});
|
|
154
157
|
const prototype = Reflect.getPrototypeOf(type);
|
|
155
158
|
if (isNotNull(prototype) && reflectionRegistry.hasType(prototype)) {
|
|
156
159
|
const parentSchema = getSchemaFromReflection(prototype);
|
|
157
160
|
assert(parentSchema instanceof ObjectSchema, 'Can not infer an ObjectSchema from reflection when parent class has an explicit non-object schema defined.');
|
|
158
|
-
|
|
161
|
+
const extendedSchema = assign(parentSchema, schema);
|
|
162
|
+
extendedSchema.factory = schema.factory;
|
|
163
|
+
return extendedSchema;
|
|
159
164
|
}
|
|
160
165
|
return schema;
|
|
161
166
|
}
|
|
@@ -166,7 +171,7 @@ function getObjectSchemaPropertiesFromReflection(metadata, type) {
|
|
|
166
171
|
if (isUndefined(reflectionData?.schema) && (propertyMetadata.type == Object)) {
|
|
167
172
|
throw new Error(`Schema of property "${String(key)}" on type ${type.name} is inferred as Object. This is most likely unwanted and happens if the property is defined as partial or the type is an union. Use an explicit @Property(Object) if this is wanted.`);
|
|
168
173
|
}
|
|
169
|
-
let propertySchema = reflectionData?.schema
|
|
174
|
+
let propertySchema = isDefined(reflectionData?.schema) ? reflectionData.schema(reflectionData) : propertyMetadata.type;
|
|
170
175
|
if (isUndefined(propertySchema)) {
|
|
171
176
|
throw new Error(`Could not infer schema for property "${String(key)}" on type ${type.name}. This happens if neither explicit @Property(type) is used nor reflection metadata is available.`);
|
|
172
177
|
}
|
|
@@ -199,7 +204,7 @@ export function Record(key, value, options) {
|
|
|
199
204
|
if (data.type == 'class') {
|
|
200
205
|
return Class({ unknownPropertiesKey: keySchema, unknownProperties: valueSchema })(args[0]);
|
|
201
206
|
}
|
|
202
|
-
return
|
|
207
|
+
return PropertySchema((reflectionData) => record(keySchema, valueSchema, { description: reflectionData.description, example: reflectionData.example, ...options }), options)(args[0], args[1], args[2]);
|
|
203
208
|
});
|
|
204
209
|
}
|
|
205
210
|
export const emptyObjectSchema = explicitObject({});
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
2
|
import type { OneOrMany as OneOrManyType } 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
|
+
export type OneOrManySchemaOptions<T> = SchemaOptions<T | T[]>;
|
|
5
6
|
export type OneOrMany<T> = OneOrManyType<T>;
|
|
6
7
|
export declare class OneOrManySchema<T> extends Schema<T | T[]> {
|
|
7
8
|
readonly name: string;
|
|
8
9
|
readonly schema: Schema<T | T[]>;
|
|
9
|
-
constructor(schema: SchemaTestable<T>);
|
|
10
|
+
constructor(schema: SchemaTestable<T>, options?: OneOrManySchemaOptions<T>);
|
|
10
11
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T | T[]>;
|
|
11
12
|
}
|
|
12
|
-
export declare function oneOrMany<T>(schema: SchemaTestable<T>): OneOrManySchema<T>;
|
|
13
|
-
export declare function OneOrMany(schema: SchemaTestable
|
|
13
|
+
export declare function oneOrMany<T>(schema: SchemaTestable<T>, options?: OneOrManySchemaOptions<T>): OneOrManySchema<T>;
|
|
14
|
+
export declare function OneOrMany<T>(schema: SchemaTestable<T>, options?: OneOrManySchemaOptions<T> & 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
|
import { array } from './array.js';
|
|
@@ -7,8 +7,8 @@ import { union } from './union.js';
|
|
|
7
7
|
export class OneOrManySchema extends Schema {
|
|
8
8
|
name;
|
|
9
9
|
schema;
|
|
10
|
-
constructor(schema) {
|
|
11
|
-
super();
|
|
10
|
+
constructor(schema, options) {
|
|
11
|
+
super(options);
|
|
12
12
|
const oneSchema = schemaTestableToSchema(schema);
|
|
13
13
|
this.schema = union(oneSchema, array(oneSchema));
|
|
14
14
|
lazyProperty(this, 'name', () => `OneOrMany[${oneSchema.name}]`);
|
|
@@ -17,9 +17,9 @@ export class OneOrManySchema extends Schema {
|
|
|
17
17
|
return this.schema._test(value, path, options);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
export function oneOrMany(schema) {
|
|
21
|
-
return new OneOrManySchema(schema);
|
|
20
|
+
export function oneOrMany(schema, options) {
|
|
21
|
+
return new OneOrManySchema(schema, options);
|
|
22
22
|
}
|
|
23
23
|
export function OneOrMany(schema, options) {
|
|
24
|
-
return
|
|
24
|
+
return PropertySchema((data) => oneOrMany(schema, { description: data.description, example: data.example, ...options }), options);
|
|
25
25
|
}
|
|
@@ -10,4 +10,4 @@ export declare class OptionalSchema<T> extends Schema<T | undefined> {
|
|
|
10
10
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T | undefined>;
|
|
11
11
|
}
|
|
12
12
|
export declare function optional<T>(schema: SchemaTestable<T>): OptionalSchema<T>;
|
|
13
|
-
export declare function Optional(schema?: SchemaTestable
|
|
13
|
+
export declare function Optional<T>(schema?: SchemaTestable<T>, options?: TypedOmit<SchemaPropertyDecoratorOptions, 'optional'>): SchemaPropertyDecorator;
|
|
@@ -25,5 +25,5 @@ export function optional(schema) {
|
|
|
25
25
|
return new OptionalSchema(schema);
|
|
26
26
|
}
|
|
27
27
|
export function Optional(schema, options) {
|
|
28
|
-
return createSchemaPropertyDecorator({ schema, ...options, optional: true });
|
|
28
|
+
return createSchemaPropertyDecorator({ schema: () => schema, ...options, optional: true });
|
|
29
29
|
}
|
|
@@ -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 ReadableStreamSchemaOptions = SimpleSchemaOptions
|
|
3
|
+
export type ReadableStreamSchemaOptions = SimpleSchemaOptions<ReadableStream>;
|
|
4
4
|
export declare class ReadableStreamSchema extends SimpleSchema<ReadableStream> {
|
|
5
5
|
readonly name = "ReadableStream";
|
|
6
6
|
constructor(options?: ReadableStreamSchemaOptions);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isReadableStream } 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 ReadableStreamSchema extends SimpleSchema {
|
|
5
5
|
name = 'ReadableStream';
|
|
@@ -11,5 +11,5 @@ export function readableStream(options) {
|
|
|
11
11
|
return new ReadableStreamSchema(options);
|
|
12
12
|
}
|
|
13
13
|
export function ReadableStreamProperty(options) {
|
|
14
|
-
return
|
|
14
|
+
return PropertySchema((data) => readableStream({ description: data.description, example: data.example, ...options }), options);
|
|
15
15
|
}
|
|
@@ -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 RegExpSchemaOptions = SimpleSchemaOptions
|
|
3
|
+
export type RegExpSchemaOptions = SimpleSchemaOptions<RegExp>;
|
|
4
4
|
export declare class RegExpSchema extends SimpleSchema<RegExp> {
|
|
5
5
|
readonly name = "RegExp";
|
|
6
6
|
constructor(options?: RegExpSchemaOptions);
|
package/schema/schemas/regexp.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isRegExp } 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 RegExpSchema extends SimpleSchema {
|
|
@@ -24,5 +24,5 @@ export function regExp(options) {
|
|
|
24
24
|
return new RegExpSchema(options);
|
|
25
25
|
}
|
|
26
26
|
export function RegExpProperty(options) {
|
|
27
|
-
return
|
|
27
|
+
return PropertySchema((data) => regExp({ description: data.description, example: data.example, ...options }), options);
|
|
28
28
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
2
|
import type { AbstractConstructor, OneOrMany } from '../../types.js';
|
|
3
|
-
import { Schema, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
3
|
+
import { Schema, type SchemaOptions, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
4
|
import type { CoerceResult, Coercible, ConstraintResult } from '../types.js';
|
|
5
|
-
export type SimpleSchemaOptions = Coercible;
|
|
5
|
+
export type SimpleSchemaOptions<T> = SchemaOptions<T> & Coercible;
|
|
6
6
|
type SimpleSchemaRefinements<T> = {
|
|
7
7
|
coercers?: SimpleSchemaCoercers<T>;
|
|
8
8
|
constraints?: (SimpleSchemaConstraint<T> | null)[];
|
|
@@ -21,7 +21,7 @@ export type SimpleSchemaConstraint<T> = (value: T) => ConstraintResult;
|
|
|
21
21
|
export type SimpleSchemaGotValueFormatter = (value: unknown) => string;
|
|
22
22
|
export declare abstract class SimpleSchema<T> extends Schema<T> {
|
|
23
23
|
#private;
|
|
24
|
-
constructor(expected: OneOrMany<string | AbstractConstructor>, guardFn: (value: any) => value is T, options?: SimpleSchemaOptions
|
|
24
|
+
constructor(expected: OneOrMany<string | AbstractConstructor>, guardFn: (value: any) => value is T, options?: SimpleSchemaOptions<T>, refinements?: SimpleSchemaRefinements<T>);
|
|
25
25
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T>;
|
|
26
26
|
}
|
|
27
27
|
export {};
|
package/schema/schemas/simple.js
CHANGED
|
@@ -10,7 +10,7 @@ export class SimpleSchema extends Schema {
|
|
|
10
10
|
#constraints;
|
|
11
11
|
#gotValueFormatter;
|
|
12
12
|
constructor(expected, guardFn, options = {}, refinements = {}) {
|
|
13
|
-
super();
|
|
13
|
+
super(options);
|
|
14
14
|
this.#expected = expected;
|
|
15
15
|
this.#guardFn = guardFn;
|
|
16
16
|
this.#options = options;
|
|
@@ -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 StringSchemaOptions = SimpleSchemaOptions & {
|
|
3
|
+
export type StringSchemaOptions = SimpleSchemaOptions<string> & {
|
|
4
4
|
pattern?: RegExp | string;
|
|
5
5
|
lowercase?: boolean;
|
|
6
6
|
};
|
package/schema/schemas/string.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isDefined, isRegExp, 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 StringSchema extends SimpleSchema {
|
|
5
5
|
name = 'string';
|
|
@@ -27,5 +27,5 @@ export function string(options) {
|
|
|
27
27
|
return new StringSchema(options);
|
|
28
28
|
}
|
|
29
29
|
export function StringProperty(options) {
|
|
30
|
-
return
|
|
30
|
+
return PropertySchema((data) => string({ description: data.description, example: data.example, ...options }), options);
|
|
31
31
|
}
|
|
@@ -1,9 +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 {
|
|
4
|
-
export
|
|
2
|
+
import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
|
|
3
|
+
export type SymbolSchemaOptions = SimpleSchemaOptions<symbol>;
|
|
4
|
+
export declare class SymbolSchema extends SimpleSchema<symbol> {
|
|
5
5
|
readonly name = "symbol";
|
|
6
|
-
|
|
6
|
+
constructor(options?: SymbolSchemaOptions);
|
|
7
7
|
}
|
|
8
|
-
export declare function symbol(): SymbolSchema;
|
|
9
|
-
export declare function SymbolProperty(options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
8
|
+
export declare function symbol(options?: SymbolSchemaOptions): SymbolSchema;
|
|
9
|
+
export declare function SymbolProperty(options?: SymbolSchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
package/schema/schemas/symbol.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
import { SchemaError } from '../../schema/schema.error.js';
|
|
2
1
|
import { isSymbol } from '../../utils/type-guards.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export class SymbolSchema extends Schema {
|
|
2
|
+
import { PropertySchema } from '../decorators/index.js';
|
|
3
|
+
import { SimpleSchema } from './simple.js';
|
|
4
|
+
export class SymbolSchema extends SimpleSchema {
|
|
7
5
|
name = 'symbol';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return { valid: true, value };
|
|
11
|
-
}
|
|
12
|
-
return { valid: false, error: SchemaError.expectedButGot('symbol', typeOf(value), path, { fast: options.fastErrors }) };
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super('symbol', isSymbol, options);
|
|
13
8
|
}
|
|
14
9
|
}
|
|
15
|
-
export function symbol() {
|
|
16
|
-
return new SymbolSchema();
|
|
10
|
+
export function symbol(options) {
|
|
11
|
+
return new SymbolSchema(options);
|
|
17
12
|
}
|
|
18
13
|
export function SymbolProperty(options) {
|
|
19
|
-
return
|
|
14
|
+
return PropertySchema((data) => symbol({ description: data.description, example: data.example, ...options }), options);
|
|
20
15
|
}
|
|
@@ -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 Uint8ArraySchemaOptions = SimpleSchemaOptions & {
|
|
3
|
+
export type Uint8ArraySchemaOptions = SimpleSchemaOptions<Uint8Array> & {
|
|
4
4
|
/** Minimum byte length */
|
|
5
5
|
minimumLength?: number;
|
|
6
6
|
/** Maximum byte length */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isDefined, isUint8Array } 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 Uint8ArraySchema extends SimpleSchema {
|
|
5
5
|
name = 'Uint8Array';
|
|
@@ -20,5 +20,5 @@ export function uint8Array(options) {
|
|
|
20
20
|
return new Uint8ArraySchema(options);
|
|
21
21
|
}
|
|
22
22
|
export function Uint8ArrayProperty(options) {
|
|
23
|
-
return
|
|
23
|
+
return PropertySchema((data) => uint8Array({ description: data.description, example: data.example, ...options }), options);
|
|
24
24
|
}
|
package/schema/schemas/union.js
CHANGED
|
@@ -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 { SchemaError } from '../schema.error.js';
|
|
4
4
|
import { Schema } from '../schema.js';
|
|
5
5
|
import { isSchemaTestable, schemaTestableToSchema } from '../testable.js';
|
|
@@ -35,8 +35,8 @@ export function union(...schemas) {
|
|
|
35
35
|
export function Union(...schemasAndOptions) {
|
|
36
36
|
const schemaOrOptions = schemasAndOptions.at(-1);
|
|
37
37
|
if (isSchemaTestable(schemaOrOptions)) {
|
|
38
|
-
return
|
|
38
|
+
return PropertySchema(() => union(...schemasAndOptions));
|
|
39
39
|
}
|
|
40
40
|
const schemas = schemasAndOptions.slice(0, -1);
|
|
41
|
-
return
|
|
41
|
+
return PropertySchema(() => union(...schemas), schemaOrOptions);
|
|
42
42
|
}
|
|
@@ -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 UnknownSchemaOptions = SchemaOptions<unknown>;
|
|
3
4
|
export declare class UnknownSchema extends Schema<unknown> {
|
|
4
5
|
readonly name = "unknown";
|
|
5
6
|
_test(value: unknown): SchemaTestResult<unknown>;
|
|
6
7
|
}
|
|
7
|
-
export declare function unknown(): UnknownSchema;
|
|
8
|
-
export declare function Unknown(options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
8
|
+
export declare function unknown(options?: UnknownSchemaOptions): UnknownSchema;
|
|
9
|
+
export declare function Unknown(options?: UnknownSchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PropertySchema } from '../decorators/index.js';
|
|
2
2
|
import { Schema } from '../schema.js';
|
|
3
3
|
export class UnknownSchema extends Schema {
|
|
4
4
|
name = 'unknown';
|
|
@@ -6,9 +6,9 @@ export class UnknownSchema extends Schema {
|
|
|
6
6
|
return { valid: true, value };
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
export function unknown() {
|
|
10
|
-
return new UnknownSchema();
|
|
9
|
+
export function unknown(options) {
|
|
10
|
+
return new UnknownSchema(options);
|
|
11
11
|
}
|
|
12
12
|
export function Unknown(options) {
|
|
13
|
-
return
|
|
13
|
+
return PropertySchema((data) => unknown({ description: data.description, example: data.example, ...options }), options);
|
|
14
14
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { compareByValueSelectionOrdered } from '../../utils/comparison.js';
|
|
2
2
|
import { FactoryMap } from '../../utils/factory-map.js';
|
|
3
|
-
import { normalizeText } from '../../utils/helpers.js';
|
|
4
3
|
import { objectEntries } from '../../utils/object/object.js';
|
|
5
4
|
import { intersectSets, unionSets } from '../../utils/set.js';
|
|
5
|
+
import { normalizeText } from '../../utils/string/index.js';
|
|
6
6
|
import { Timer } from '../../utils/timer.js';
|
|
7
7
|
import { isDefined, isNullOrUndefined, isString } from '../../utils/type-guards.js';
|
|
8
8
|
import { SearchIndex } from '../search-index.js';
|
package/types.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export type JsonPrimitive = string | number | boolean | null;
|
|
|
34
34
|
export type JsonObject = {
|
|
35
35
|
[key: string]: Json;
|
|
36
36
|
};
|
|
37
|
-
export type JsonArray = Json[];
|
|
37
|
+
export type JsonArray = Json[] | readonly Json[];
|
|
38
38
|
export type UndefinableJson = JsonPrimitive | UndefinableJsonObject | UndefinableJsonArray;
|
|
39
39
|
export type UndefinableJsonInnerNode = UndefinableJsonPrimitive | UndefinableJsonObject | UndefinableJsonArray;
|
|
40
40
|
export type UndefinableJsonPrimitive = JsonPrimitive | undefined;
|
package/utils/helpers.d.ts
CHANGED
|
@@ -25,44 +25,4 @@ export declare function parseFirstAndFamilyName(name: string): {
|
|
|
25
25
|
firstName: string | undefined;
|
|
26
26
|
familyName: string | undefined;
|
|
27
27
|
};
|
|
28
|
-
export type NormalizeTextOptions = {
|
|
29
|
-
/**
|
|
30
|
-
* Remove leading and trailing whitespace
|
|
31
|
-
*/
|
|
32
|
-
trim?: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Lowercase all characters
|
|
35
|
-
*/
|
|
36
|
-
lowercase?: boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Remove multiple consecutive whitespace characters
|
|
39
|
-
*/
|
|
40
|
-
multipleWhitespace?: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Remove diacritics (è -> e)
|
|
43
|
-
*
|
|
44
|
-
* applies unicode NFD normalization and removes diacritics
|
|
45
|
-
* @see unicode option
|
|
46
|
-
*/
|
|
47
|
-
diacritics?: boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Replace ligatures with their consecutive characters (æ -> ae)
|
|
50
|
-
*
|
|
51
|
-
* applies unicode NFKC normalization
|
|
52
|
-
* @see unicode option
|
|
53
|
-
*/
|
|
54
|
-
ligatures?: boolean;
|
|
55
|
-
/**
|
|
56
|
-
* Unicode normalization
|
|
57
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize
|
|
58
|
-
*/
|
|
59
|
-
unicode?: 'NFC' | 'NFD' | 'NFKC' | 'NFKD';
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* Trims, lowercases, replaces multi-character whitespace with a single space and unicode normalization
|
|
63
|
-
* @param text text to normalize
|
|
64
|
-
* @param options specify what to normalize. Defaults to all except unicode
|
|
65
|
-
* @returns normalized text
|
|
66
|
-
*/
|
|
67
|
-
export declare function normalizeText(text: string, options?: NormalizeTextOptions): string;
|
|
68
28
|
export declare function iif<T, F>(condition: boolean, trueFn: () => T, falseFn: () => F): T | F;
|