@tstdl/base 0.91.52 → 0.92.1
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/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 -2
- 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
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;
|
package/utils/helpers.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { supportsNotification } from '../supports.js';
|
|
2
2
|
import { DetailsError } from '../errors/details.error.js';
|
|
3
3
|
import { decycle } from './object/decycle.js';
|
|
4
|
-
import { isDefined } from './type-guards.js';
|
|
5
4
|
/**
|
|
6
5
|
* Create an structured clone of an value using Notification if available, otherwise history state (may alters history)
|
|
7
6
|
*
|
|
@@ -68,34 +67,6 @@ export function parseFirstAndFamilyName(name) {
|
|
|
68
67
|
familyName: familyName.length > 0 ? familyName : undefined
|
|
69
68
|
};
|
|
70
69
|
}
|
|
71
|
-
/**
|
|
72
|
-
* Trims, lowercases, replaces multi-character whitespace with a single space and unicode normalization
|
|
73
|
-
* @param text text to normalize
|
|
74
|
-
* @param options specify what to normalize. Defaults to all except unicode
|
|
75
|
-
* @returns normalized text
|
|
76
|
-
*/
|
|
77
|
-
export function normalizeText(text, options = { trim: true, lowercase: true, multipleWhitespace: true, diacritics: true, ligatures: true }) {
|
|
78
|
-
let normalized = text;
|
|
79
|
-
if (options.trim == true) {
|
|
80
|
-
normalized = normalized.trim();
|
|
81
|
-
}
|
|
82
|
-
if (options.lowercase == true) {
|
|
83
|
-
normalized = normalized.toLowerCase();
|
|
84
|
-
}
|
|
85
|
-
if (options.multipleWhitespace == true) {
|
|
86
|
-
normalized = normalized.replace(/\s+/ug, ' ');
|
|
87
|
-
}
|
|
88
|
-
if (options.diacritics == true) {
|
|
89
|
-
normalized = normalized.normalize('NFD').replace(/\p{Diacritic}/ug, '');
|
|
90
|
-
}
|
|
91
|
-
if (options.ligatures == true) {
|
|
92
|
-
normalized = normalized.normalize('NFKC');
|
|
93
|
-
}
|
|
94
|
-
if (isDefined(options.unicode)) {
|
|
95
|
-
normalized = normalized.normalize(options.unicode);
|
|
96
|
-
}
|
|
97
|
-
return normalized;
|
|
98
|
-
}
|
|
99
70
|
export function iif(condition, trueFn, falseFn) {
|
|
100
71
|
return condition ? trueFn() : falseFn();
|
|
101
72
|
}
|
package/utils/index.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ export * from './sort.js';
|
|
|
49
49
|
export * from './throw.js';
|
|
50
50
|
export * from './timer.js';
|
|
51
51
|
export * from './timing.js';
|
|
52
|
+
export * from './try-ignore.js';
|
|
52
53
|
export * from './type-guards.js';
|
|
53
54
|
export * from './type-of.js';
|
|
54
55
|
export * from './type/index.js';
|
package/utils/index.js
CHANGED
|
@@ -49,6 +49,7 @@ export * from './sort.js';
|
|
|
49
49
|
export * from './throw.js';
|
|
50
50
|
export * from './timer.js';
|
|
51
51
|
export * from './timing.js';
|
|
52
|
+
export * from './try-ignore.js';
|
|
52
53
|
export * from './type-guards.js';
|
|
53
54
|
export * from './type-of.js';
|
|
54
55
|
export * from './type/index.js';
|
package/utils/string/index.d.ts
CHANGED
package/utils/string/index.js
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export type NormalizeTextOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* Remove leading and trailing whitespace
|
|
4
|
+
*/
|
|
5
|
+
trim?: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Lowercase all characters
|
|
8
|
+
*/
|
|
9
|
+
lowercase?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Remove multiple consecutive whitespace characters
|
|
12
|
+
*/
|
|
13
|
+
multipleWhitespace?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Remove diacritics (è -> e)
|
|
16
|
+
*
|
|
17
|
+
* applies unicode NFD normalization and removes diacritics
|
|
18
|
+
* @see unicode option
|
|
19
|
+
*/
|
|
20
|
+
diacritics?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Replace ligatures with their consecutive characters (æ -> ae)
|
|
23
|
+
*
|
|
24
|
+
* applies unicode NFKC normalization
|
|
25
|
+
* @see unicode option
|
|
26
|
+
*/
|
|
27
|
+
ligatures?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Unicode normalization
|
|
30
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize
|
|
31
|
+
*/
|
|
32
|
+
unicode?: 'NFC' | 'NFD' | 'NFKC' | 'NFKD';
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Trims, lowercases, replaces multi-character whitespace with a single space and unicode normalization
|
|
36
|
+
* @param text text to normalize
|
|
37
|
+
* @param options specify what to normalize. Defaults to all except unicode
|
|
38
|
+
* @returns normalized text
|
|
39
|
+
*/
|
|
40
|
+
export declare function normalizeText(text: string, options?: NormalizeTextOptions): string;
|
|
41
|
+
/**
|
|
42
|
+
* Normalizes text input by trimming whitespace and returning null if text is empty.
|
|
43
|
+
*
|
|
44
|
+
* @param text The input text to normalize
|
|
45
|
+
* @param allowNull If true, null or undefined input (or input that becomes empty after trimming) will return null. If false, an error will be thrown in these cases. Defaults to true.
|
|
46
|
+
* @returns The trimmed string. If allowNull is true and the input is null, undefined, or empty after trimming, returns null.
|
|
47
|
+
* @throws {Error} If allowNull is false and the input is null, undefined, or empty after trimming.
|
|
48
|
+
*/
|
|
49
|
+
export declare function normalizeTextInput(text: string | null | undefined, allowNull?: true): string | null;
|
|
50
|
+
export declare function normalizeTextInput(text: string | null | undefined, allowNull: false): string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { isDefined, isNullOrUndefined } from '../type-guards.js';
|
|
2
|
+
/**
|
|
3
|
+
* Trims, lowercases, replaces multi-character whitespace with a single space and unicode normalization
|
|
4
|
+
* @param text text to normalize
|
|
5
|
+
* @param options specify what to normalize. Defaults to all except unicode
|
|
6
|
+
* @returns normalized text
|
|
7
|
+
*/
|
|
8
|
+
export function normalizeText(text, options = { trim: true, lowercase: true, multipleWhitespace: true, diacritics: true, ligatures: true }) {
|
|
9
|
+
let normalized = text;
|
|
10
|
+
if (options.trim == true) {
|
|
11
|
+
normalized = normalized.trim();
|
|
12
|
+
}
|
|
13
|
+
if (options.lowercase == true) {
|
|
14
|
+
normalized = normalized.toLowerCase();
|
|
15
|
+
}
|
|
16
|
+
if (options.multipleWhitespace == true) {
|
|
17
|
+
normalized = normalized.replace(/\s+/ug, ' ');
|
|
18
|
+
}
|
|
19
|
+
if (options.diacritics == true) {
|
|
20
|
+
normalized = normalized.normalize('NFD').replace(/\p{Diacritic}/ug, '');
|
|
21
|
+
}
|
|
22
|
+
if (options.ligatures == true) {
|
|
23
|
+
normalized = normalized.normalize('NFKC');
|
|
24
|
+
}
|
|
25
|
+
if (isDefined(options.unicode)) {
|
|
26
|
+
normalized = normalized.normalize(options.unicode);
|
|
27
|
+
}
|
|
28
|
+
return normalized;
|
|
29
|
+
}
|
|
30
|
+
export function normalizeTextInput(text, allowNull) {
|
|
31
|
+
const normalized = text?.trim();
|
|
32
|
+
if (isNullOrUndefined(normalized) || (normalized.length == 0)) {
|
|
33
|
+
if (allowNull == false) {
|
|
34
|
+
throw new Error('Invalid input.');
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return normalized;
|
|
39
|
+
}
|