@tstdl/base 0.91.28 → 0.91.31
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/.eslintrc.json +5 -1
- package/authentication/models/authentication-credentials.model.js +10 -10
- package/authentication/models/authentication-session.model.d.ts +2 -2
- package/authentication/models/authentication-session.model.js +16 -16
- package/authentication/models/init-secret-reset-data.model.js +3 -3
- package/authentication/models/token-payload-base.model.d.ts +4 -4
- package/authentication/models/token-payload-base.model.js +12 -12
- package/{reflection/reflection-data-map.d.ts → data-structures/context-data-map.d.ts} +3 -2
- package/{reflection/reflection-data-map.js → data-structures/context-data-map.js} +13 -6
- package/data-structures/index.d.ts +1 -0
- package/data-structures/index.js +1 -0
- package/examples/api/basic-overview.js +2 -2
- package/examples/api/custom-authentication.js +3 -3
- package/examples/orm/drizzle.config.d.ts +2 -0
- package/examples/orm/drizzle.config.js +5 -0
- package/examples/orm/schemas.d.ts +3 -0
- package/examples/orm/schemas.js +4 -0
- package/examples/orm/test.js +10 -0
- package/examples/orm/user.model.d.ts +9 -0
- package/examples/orm/user.model.js +39 -0
- package/key-value-store/index.d.ts +0 -1
- package/key-value-store/index.js +0 -1
- package/key-value-store/key-value.store.d.ts +9 -10
- package/key-value-store/mongo/mongo-key-value.store.js +2 -1
- package/mail/mail.client.js +5 -6
- package/orm/database-schema.d.ts +8 -0
- package/orm/database-schema.js +13 -0
- package/orm/decorators.d.ts +26 -0
- package/orm/decorators.js +21 -2
- package/orm/drizzle/schema-converter.d.ts +19 -0
- package/orm/drizzle/schema-converter.js +116 -0
- package/orm/entity.d.ts +6 -2
- package/orm/entity.js +9 -9
- package/orm/index.d.ts +1 -2
- package/orm/index.js +1 -2
- package/orm/repository.d.ts +27 -24
- package/orm/repository.js +124 -7
- package/orm/schemas/index.d.ts +1 -0
- package/orm/schemas/index.js +1 -0
- package/orm/schemas/uuid.d.ts +11 -0
- package/orm/schemas/uuid.js +16 -0
- package/orm/types.d.ts +20 -7
- package/orm/types.js +3 -5
- package/package.json +7 -4
- package/reflection/registry.d.ts +9 -6
- package/reflection/registry.js +25 -14
- package/schema/decorators/property.d.ts +2 -2
- package/schema/decorators/types.d.ts +1 -0
- package/schema/schema.d.ts +1 -1
- package/schema/schemas/array.d.ts +6 -3
- package/schema/schemas/array.js +9 -4
- package/schema/schemas/deferred.d.ts +12 -0
- package/schema/schemas/deferred.js +23 -0
- package/schema/schemas/index.d.ts +1 -0
- package/schema/schemas/index.js +1 -0
- package/schema/schemas/number.d.ts +5 -0
- package/schema/schemas/number.js +8 -1
- package/schema/schemas/string.d.ts +4 -1
- package/schema/schemas/string.js +8 -2
- package/schema/schemas/uint8-array.d.ts +3 -2
- package/schema/schemas/uint8-array.js +8 -5
- package/templates/resolvers/file.template-resolver.d.ts +1 -2
- package/templates/resolvers/file.template-resolver.js +2 -2
- package/templates/resolvers/jsx.template-resolver.d.ts +1 -3
- package/templates/resolvers/jsx.template-resolver.js +3 -7
- package/templates/template.model.d.ts +1 -1
- package/templates/template.model.js +5 -5
- package/utils/math.d.ts +11 -1
- package/utils/math.js +28 -0
- package/utils/string/index.d.ts +1 -0
- package/utils/string/index.js +1 -0
- package/utils/string/snake-case.d.ts +1 -0
- package/utils/string/snake-case.js +4 -0
- package/orm/schema-converter.d.ts +0 -99
- package/orm/schema-converter.js +0 -74
- package/orm/schema.d.ts +0 -3
- /package/{orm/schema.js → examples/orm/test.d.ts} +0 -0
package/reflection/registry.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { FactoryMap } from '../utils/factory-map.js';
|
|
2
2
|
import { lazyObject, lazyObjectValue } from '../utils/object/lazy-property.js';
|
|
3
3
|
import { getDesignType, getParameterTypes, getReturnType } from '../utils/reflection.js';
|
|
4
|
-
import { isDefined, isUndefined } from '../utils/type-guards.js';
|
|
4
|
+
import { isDefined, isNotNull, isUndefined } from '../utils/type-guards.js';
|
|
5
|
+
import { ContextDataMap } from '../data-structures/context-data-map.js';
|
|
5
6
|
import { getDecoratorData } from './decorator-data.js';
|
|
6
|
-
import { ReflectionDataMap } from './reflection-data-map.js';
|
|
7
7
|
export class ReflectionRegistry {
|
|
8
8
|
metadataMap;
|
|
9
9
|
finalizedTypesSet;
|
|
@@ -17,11 +17,7 @@ export class ReflectionRegistry {
|
|
|
17
17
|
getMetadata(type) {
|
|
18
18
|
const metadata = this.metadataMap.get(type);
|
|
19
19
|
if (isDefined(metadata) && !this.finalizedTypesSet.has(type)) {
|
|
20
|
-
|
|
21
|
-
metadata.staticProperties = new Map(metadata.staticProperties);
|
|
22
|
-
metadata.methods = new Map(metadata.methods);
|
|
23
|
-
metadata.staticMethods = new Map(metadata.staticMethods);
|
|
24
|
-
this.finalizedTypesSet.add(type);
|
|
20
|
+
this.#finalizeMetadata(metadata);
|
|
25
21
|
}
|
|
26
22
|
return metadata;
|
|
27
23
|
}
|
|
@@ -73,23 +69,38 @@ export class ReflectionRegistry {
|
|
|
73
69
|
}
|
|
74
70
|
return this.metadataMap.get(type);
|
|
75
71
|
}
|
|
72
|
+
#finalizeMetadata(metadata) {
|
|
73
|
+
const parentMetadata = isNotNull(metadata.parent) ? reflectionRegistry.getMetadata(metadata.parent) : undefined;
|
|
74
|
+
metadata.properties = new Map([...getInheritedMetadataEntries(parentMetadata?.properties), ...metadata.properties]);
|
|
75
|
+
metadata.staticProperties = new Map([...getInheritedMetadataEntries(parentMetadata?.staticProperties), ...metadata.staticProperties]);
|
|
76
|
+
metadata.methods = new Map([...getInheritedMetadataEntries(parentMetadata?.methods), ...metadata.methods]);
|
|
77
|
+
metadata.staticMethods = new Map([...getInheritedMetadataEntries(parentMetadata?.staticMethods), ...metadata.staticMethods]);
|
|
78
|
+
this.finalizedTypesSet.add(metadata.constructor);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function getInheritedMetadataEntries(metadata) {
|
|
82
|
+
return [...(metadata ?? [])].map(([key, value]) => [key, toInheritedMetadata(value)]);
|
|
83
|
+
}
|
|
84
|
+
function toInheritedMetadata(metadata) {
|
|
85
|
+
return { ...metadata, inherited: true };
|
|
76
86
|
}
|
|
77
87
|
function initializeType(type) {
|
|
88
|
+
const parent = Reflect.getPrototypeOf(type);
|
|
78
89
|
return lazyObject({
|
|
79
90
|
metadataType: 'type',
|
|
80
91
|
constructor: lazyObjectValue(type),
|
|
81
|
-
parent: lazyObjectValue(
|
|
92
|
+
parent: lazyObjectValue(parent),
|
|
82
93
|
parameters: {
|
|
83
94
|
initializer() {
|
|
84
95
|
const parametersTypes = getParameterTypes(type);
|
|
85
|
-
return parametersTypes?.map((parameterType, index) => ({ metadataType: 'constructor-parameter', index, type: parameterType, data: new
|
|
96
|
+
return parametersTypes?.map((parameterType, index) => ({ metadataType: 'constructor-parameter', index, type: parameterType, data: new ContextDataMap() }));
|
|
86
97
|
}
|
|
87
98
|
},
|
|
88
99
|
properties: {
|
|
89
|
-
initializer: () => new FactoryMap((key) => ({ metadataType: 'property', key, type: getDesignType(type.prototype, key), isAccessor: false, data: new
|
|
100
|
+
initializer: () => new FactoryMap((key) => ({ metadataType: 'property', key, type: getDesignType(type.prototype, key), isAccessor: false, data: new ContextDataMap(), inherited: false }))
|
|
90
101
|
},
|
|
91
102
|
staticProperties: {
|
|
92
|
-
initializer: () => new FactoryMap((key) => ({ metadataType: 'property', key, type: getDesignType(type, key), isAccessor: false, data: new
|
|
103
|
+
initializer: () => new FactoryMap((key) => ({ metadataType: 'property', key, type: getDesignType(type, key), isAccessor: false, data: new ContextDataMap(), inherited: false }))
|
|
93
104
|
},
|
|
94
105
|
methods: {
|
|
95
106
|
initializer: () => new FactoryMap((key) => {
|
|
@@ -98,7 +109,7 @@ function initializeType(type) {
|
|
|
98
109
|
if (isUndefined(parameters)) {
|
|
99
110
|
throw new Error(`Could not get parameters for method ${key.toString()} of type ${type.name}`);
|
|
100
111
|
}
|
|
101
|
-
return { metadataType: 'method', parameters: parameters.map((parameter, index) => ({ metadataType: 'method-parameter', index, type: parameter, data: new
|
|
112
|
+
return { metadataType: 'method', parameters: parameters.map((parameter, index) => ({ metadataType: 'method-parameter', index, type: parameter, data: new ContextDataMap() })), returnType, data: new ContextDataMap(), inherited: false };
|
|
102
113
|
})
|
|
103
114
|
},
|
|
104
115
|
staticMethods: {
|
|
@@ -108,10 +119,10 @@ function initializeType(type) {
|
|
|
108
119
|
if (isUndefined(parameters)) {
|
|
109
120
|
throw new Error(`Could not get parameters for static method ${key.toString()} of type ${type.name}`);
|
|
110
121
|
}
|
|
111
|
-
return { metadataType: 'method', parameters: parameters.map((parameter, index) => ({ metadataType: 'method-parameter', index, type: parameter, data: new
|
|
122
|
+
return { metadataType: 'method', parameters: parameters.map((parameter, index) => ({ metadataType: 'method-parameter', index, type: parameter, data: new ContextDataMap() })), returnType, data: new ContextDataMap(), inherited: false };
|
|
112
123
|
})
|
|
113
124
|
},
|
|
114
|
-
data: { initializer: () => new
|
|
125
|
+
data: { initializer: () => new ContextDataMap() }
|
|
115
126
|
});
|
|
116
127
|
}
|
|
117
128
|
export const reflectionRegistry = new ReflectionRegistry();
|
|
@@ -3,5 +3,5 @@ import type { TypedOmit } from '../../types.js';
|
|
|
3
3
|
import type { SchemaTestable } from '../schema.js';
|
|
4
4
|
import type { SchemaPropertyReflectionData } from './types.js';
|
|
5
5
|
export type SchemaPropertyDecoratorOptions = TypedOmit<SchemaPropertyReflectionData, 'schema'>;
|
|
6
|
-
export declare function Property(schema
|
|
7
|
-
export declare function Property(options
|
|
6
|
+
export declare function Property(schema: SchemaTestable, options?: SchemaPropertyDecoratorOptions): Decorator<'property' | 'accessor'>;
|
|
7
|
+
export declare function Property(options: SchemaPropertyDecoratorOptions): Decorator<'property' | 'accessor'>;
|
package/schema/schema.d.ts
CHANGED
|
@@ -23,8 +23,8 @@ export type SchemaTestable<T = unknown> = Schema<T> | AbstractConstructor<T> | N
|
|
|
23
23
|
export type SchemaOutput<T extends SchemaTestable> = T extends SchemaTestable<infer U> ? U : never;
|
|
24
24
|
export declare const OPTIONAL: unique symbol;
|
|
25
25
|
export declare abstract class Schema<T = unknown> {
|
|
26
|
-
abstract readonly name: string;
|
|
27
26
|
readonly [OPTIONAL]: boolean;
|
|
27
|
+
abstract readonly name: string;
|
|
28
28
|
/**
|
|
29
29
|
* Test an unknown value to see whether it corresponds to the schema.
|
|
30
30
|
* @param schema schema to test against
|
|
@@ -2,11 +2,14 @@ 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
4
|
import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
5
|
+
import type { Coercible } from '../types.js';
|
|
6
|
+
export type ArraySchemaOptions = Coercible;
|
|
5
7
|
export declare class ArraySchema<T> extends Schema<T[]> {
|
|
8
|
+
#private;
|
|
6
9
|
readonly name: string;
|
|
7
10
|
readonly itemSchema: Schema<T>;
|
|
8
|
-
constructor(itemSchema: SchemaTestable<T
|
|
11
|
+
constructor(itemSchema: SchemaTestable<T>, options?: ArraySchemaOptions);
|
|
9
12
|
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T[]>;
|
|
10
13
|
}
|
|
11
|
-
export declare function array<T>(schema: SchemaTestable<T
|
|
12
|
-
export declare function Array(schema: SchemaTestable, options?: TypedOmit<SchemaPropertyDecoratorOptions, 'array'>): SchemaPropertyDecorator;
|
|
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;
|
package/schema/schemas/array.js
CHANGED
|
@@ -5,15 +5,20 @@ import { Property } from '../decorators/index.js';
|
|
|
5
5
|
import { Schema } from '../schema.js';
|
|
6
6
|
import { schemaTestableToSchema } from '../testable.js';
|
|
7
7
|
export class ArraySchema extends Schema {
|
|
8
|
+
#options;
|
|
8
9
|
name;
|
|
9
10
|
itemSchema;
|
|
10
|
-
constructor(itemSchema) {
|
|
11
|
+
constructor(itemSchema, options = {}) {
|
|
11
12
|
super();
|
|
13
|
+
this.#options = options;
|
|
12
14
|
this.itemSchema = schemaTestableToSchema(itemSchema);
|
|
13
15
|
this.name = `Array[${this.itemSchema.name}]`;
|
|
14
16
|
}
|
|
15
17
|
_test(value, path, options) {
|
|
16
18
|
if (!isArray(value)) {
|
|
19
|
+
if ((this.#options.coerce ?? options.coerce) == true) {
|
|
20
|
+
return this._test([value], path, options);
|
|
21
|
+
}
|
|
17
22
|
return { valid: false, error: SchemaError.expectedButGot('array', typeOf(value), path) };
|
|
18
23
|
}
|
|
19
24
|
const values = [];
|
|
@@ -27,9 +32,9 @@ export class ArraySchema extends Schema {
|
|
|
27
32
|
return { valid: true, value: values };
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
|
-
export function array(schema) {
|
|
31
|
-
return new ArraySchema(schema);
|
|
35
|
+
export function array(schema, options) {
|
|
36
|
+
return new ArraySchema(schema, options);
|
|
32
37
|
}
|
|
33
38
|
export function Array(schema, options) {
|
|
34
|
-
return Property(schema,
|
|
39
|
+
return Property(array(schema, options), options);
|
|
35
40
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { JsonPath } from '../../json-path/json-path.js';
|
|
2
|
+
import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
|
|
3
|
+
import { Schema, type SchemaOutput, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
|
|
4
|
+
export declare class DeferredSchema<T extends SchemaTestable> extends Schema<SchemaOutput<T>> {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly testable: T;
|
|
7
|
+
readonly schema: Schema<SchemaOutput<T>>;
|
|
8
|
+
constructor(schema: () => T);
|
|
9
|
+
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<SchemaOutput<T>>;
|
|
10
|
+
}
|
|
11
|
+
export declare function deferred<T extends SchemaTestable>(schema: () => T): DeferredSchema<T>;
|
|
12
|
+
export declare function Deferred<T extends SchemaTestable>(schema: () => T, options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { lazyProperty } from '../../utils/object/lazy-property.js';
|
|
2
|
+
import { Property } from '../decorators/index.js';
|
|
3
|
+
import { Schema } from '../schema.js';
|
|
4
|
+
import { schemaTestableToSchema } from '../testable.js';
|
|
5
|
+
export class DeferredSchema extends Schema {
|
|
6
|
+
name;
|
|
7
|
+
testable;
|
|
8
|
+
schema;
|
|
9
|
+
constructor(schema) {
|
|
10
|
+
super();
|
|
11
|
+
lazyProperty(this, 'schema', () => schemaTestableToSchema(schema()));
|
|
12
|
+
lazyProperty(this, 'name', () => `Deferred[${this.schema.name}]`);
|
|
13
|
+
}
|
|
14
|
+
_test(value, path, options) {
|
|
15
|
+
return this.schema._test(value, path, options);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function deferred(schema) {
|
|
19
|
+
return new DeferredSchema(schema);
|
|
20
|
+
}
|
|
21
|
+
export function Deferred(schema, options) {
|
|
22
|
+
return Property(deferred(schema), options);
|
|
23
|
+
}
|
package/schema/schemas/index.js
CHANGED
|
@@ -2,9 +2,14 @@ import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } fro
|
|
|
2
2
|
import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
|
|
3
3
|
export type NumberSchemaOptions = SimpleSchemaOptions & {
|
|
4
4
|
integer?: boolean;
|
|
5
|
+
minimum?: number;
|
|
6
|
+
maximum?: number;
|
|
5
7
|
};
|
|
6
8
|
export declare class NumberSchema extends SimpleSchema<number> {
|
|
7
9
|
readonly name = "number";
|
|
10
|
+
readonly integer: boolean;
|
|
11
|
+
readonly minimum: number | null;
|
|
12
|
+
readonly maximum: number | null;
|
|
8
13
|
constructor(options?: NumberSchemaOptions);
|
|
9
14
|
}
|
|
10
15
|
export declare function number(options?: NumberSchemaOptions): NumberSchema;
|
package/schema/schemas/number.js
CHANGED
|
@@ -4,6 +4,9 @@ import { SchemaError } from '../schema.error.js';
|
|
|
4
4
|
import { SimpleSchema } from './simple.js';
|
|
5
5
|
export class NumberSchema extends SimpleSchema {
|
|
6
6
|
name = 'number';
|
|
7
|
+
integer;
|
|
8
|
+
minimum;
|
|
9
|
+
maximum;
|
|
7
10
|
constructor(options) {
|
|
8
11
|
super('number', isNumber, options, {
|
|
9
12
|
coercers: {
|
|
@@ -17,9 +20,13 @@ export class NumberSchema extends SimpleSchema {
|
|
|
17
20
|
bigint: (value) => ({ success: true, value: globalThis.Number(value), valid: false })
|
|
18
21
|
},
|
|
19
22
|
constraints: [
|
|
20
|
-
(options?.integer == true) ? (value) => globalThis.Number.isInteger(value) ? ({ success: true }) : ({ success: false, error: '
|
|
23
|
+
(options?.integer == true) ? (value) => globalThis.Number.isInteger(value) ? ({ success: true }) : ({ success: false, error: 'Value is not an integer.' }) : null,
|
|
24
|
+
isNumber(options?.minimum) ? (value) => (value >= this.minimum) ? ({ success: true }) : ({ success: false, error: `Value must be more than or equal to ${this.minimum}.` }) : null,
|
|
25
|
+
isNumber(options?.maximum) ? (value) => (value >= this.maximum) ? ({ success: true }) : ({ success: false, error: `Value must be less than or equal to ${this.maximum}.` }) : null
|
|
21
26
|
]
|
|
22
27
|
});
|
|
28
|
+
this.integer = options?.integer ?? false;
|
|
29
|
+
this.minimum = options?.minimum ?? null;
|
|
23
30
|
}
|
|
24
31
|
}
|
|
25
32
|
export function number(options) {
|
|
@@ -2,9 +2,12 @@ import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } fro
|
|
|
2
2
|
import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
|
|
3
3
|
export type StringSchemaOptions = SimpleSchemaOptions & {
|
|
4
4
|
pattern?: RegExp | string;
|
|
5
|
+
lowercase?: boolean;
|
|
5
6
|
};
|
|
6
7
|
export declare class StringSchema extends SimpleSchema<string> {
|
|
7
|
-
readonly name
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly pattern: RegExp | null;
|
|
10
|
+
readonly lowercase: boolean;
|
|
8
11
|
constructor(options?: StringSchemaOptions);
|
|
9
12
|
}
|
|
10
13
|
export declare function string(options?: StringSchemaOptions): StringSchema;
|
package/schema/schemas/string.js
CHANGED
|
@@ -3,8 +3,9 @@ import { Property } from '../decorators/index.js';
|
|
|
3
3
|
import { SimpleSchema } from './simple.js';
|
|
4
4
|
export class StringSchema extends SimpleSchema {
|
|
5
5
|
name = 'string';
|
|
6
|
+
pattern;
|
|
7
|
+
lowercase;
|
|
6
8
|
constructor(options) {
|
|
7
|
-
const pattern = isDefined(options?.pattern) ? isString(options.pattern) ? RegExp(options.pattern, 'u') : isRegExp(options.pattern) ? options.pattern : undefined : undefined;
|
|
8
9
|
super('string', isString, options, {
|
|
9
10
|
coercers: {
|
|
10
11
|
number: (value) => ({ success: true, value: globalThis.String(value), valid: true }),
|
|
@@ -12,9 +13,14 @@ export class StringSchema extends SimpleSchema {
|
|
|
12
13
|
bigint: (value) => ({ success: true, value: globalThis.String(value), valid: true })
|
|
13
14
|
},
|
|
14
15
|
constraints: [
|
|
15
|
-
isDefined(pattern) ? ((value) => pattern.test(value) ? ({ success: true }) : ({ success: false, error: 'Value did not match pattern.' })) : null
|
|
16
|
+
isDefined(options?.pattern) ? ((value) => this.pattern.test(value) ? ({ success: true }) : ({ success: false, error: 'Value did not match pattern.' })) : null
|
|
16
17
|
]
|
|
17
18
|
});
|
|
19
|
+
this.pattern = isString(options?.pattern)
|
|
20
|
+
? RegExp(options.pattern, 'u')
|
|
21
|
+
: isRegExp(options?.pattern)
|
|
22
|
+
? options.pattern
|
|
23
|
+
: null;
|
|
18
24
|
}
|
|
19
25
|
}
|
|
20
26
|
export function string(options) {
|
|
@@ -8,8 +8,9 @@ export type Uint8ArraySchemaOptions = SimpleSchemaOptions & {
|
|
|
8
8
|
};
|
|
9
9
|
export declare class Uint8ArraySchema extends SimpleSchema<Uint8Array> {
|
|
10
10
|
readonly name = "Uint8Array";
|
|
11
|
-
readonly
|
|
11
|
+
readonly minimumLength: number | null;
|
|
12
|
+
readonly maximumLength: number | null;
|
|
12
13
|
constructor(options?: Uint8ArraySchemaOptions);
|
|
13
14
|
}
|
|
14
15
|
export declare function uint8Array(options?: Uint8ArraySchemaOptions): Uint8ArraySchema;
|
|
15
|
-
export declare function Uint8ArrayProperty(
|
|
16
|
+
export declare function Uint8ArrayProperty(options?: Uint8ArraySchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
|
|
@@ -3,19 +3,22 @@ import { Property } from '../decorators/index.js';
|
|
|
3
3
|
import { SimpleSchema } from './simple.js';
|
|
4
4
|
export class Uint8ArraySchema extends SimpleSchema {
|
|
5
5
|
name = 'Uint8Array';
|
|
6
|
-
|
|
6
|
+
minimumLength;
|
|
7
|
+
maximumLength;
|
|
7
8
|
constructor(options) {
|
|
8
9
|
super('Uint8Array', isUint8Array, options, {
|
|
9
10
|
constraints: [
|
|
10
|
-
isDefined(options?.minimumLength) ? (value) => (value.byteLength >=
|
|
11
|
-
isDefined(options?.maximumLength) ? (value) => (value.byteLength <=
|
|
11
|
+
isDefined(options?.minimumLength) ? (value) => (value.byteLength >= this.minimumLength) ? ({ success: true }) : ({ success: false, error: `Size must be at least ${this.minimumLength} bytes.` }) : null,
|
|
12
|
+
isDefined(options?.maximumLength) ? (value) => (value.byteLength <= this.maximumLength) ? ({ success: true }) : ({ success: false, error: `Size must be at most ${this.maximumLength} bytes.` }) : null
|
|
12
13
|
]
|
|
13
14
|
});
|
|
15
|
+
this.minimumLength = options?.minimumLength ?? null;
|
|
16
|
+
this.maximumLength = options?.maximumLength ?? null;
|
|
14
17
|
}
|
|
15
18
|
}
|
|
16
19
|
export function uint8Array(options) {
|
|
17
20
|
return new Uint8ArraySchema(options);
|
|
18
21
|
}
|
|
19
|
-
export function Uint8ArrayProperty(
|
|
20
|
-
return Property(uint8Array(
|
|
22
|
+
export function Uint8ArrayProperty(options) {
|
|
23
|
+
return Property(uint8Array(options), options);
|
|
21
24
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { resolveArgumentType } from '../../injector/interfaces.js';
|
|
1
|
+
import { Resolvable, resolveArgumentType } from '../../injector/interfaces.js';
|
|
3
2
|
import type { TypedOmit } from '../../types.js';
|
|
4
3
|
import { TemplateField } from '../template.model.js';
|
|
5
4
|
import type { TemplateRenderer, TemplateRendererOptions, TemplateRendererString } from '../template.renderer.js';
|
|
@@ -14,7 +14,7 @@ import * as fs from 'node:fs/promises';
|
|
|
14
14
|
import * as path from 'node:path';
|
|
15
15
|
import { BadRequestError } from '../../errors/bad-request.error.js';
|
|
16
16
|
import { InjectArg, Singleton } from '../../injector/decorators.js';
|
|
17
|
-
import {
|
|
17
|
+
import { StringProperty } from '../../schema/index.js';
|
|
18
18
|
import { TemplateField } from '../template.model.js';
|
|
19
19
|
import { TemplateResolver } from '../template.resolver.js';
|
|
20
20
|
export const fileTemplateProviderConfig = {};
|
|
@@ -22,7 +22,7 @@ export class FileTemplateField extends TemplateField {
|
|
|
22
22
|
templateFile;
|
|
23
23
|
}
|
|
24
24
|
__decorate([
|
|
25
|
-
|
|
25
|
+
StringProperty(),
|
|
26
26
|
__metadata("design:type", String)
|
|
27
27
|
], FileTemplateField.prototype, "templateFile", void 0);
|
|
28
28
|
let FileTemplateResolver = class FileTemplateResolver extends TemplateResolver {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { PartialProperty, Record, TypedOmit } from '../../types.js';
|
|
2
2
|
import type { ComponentClass, FunctionComponent } from 'preact';
|
|
3
|
-
import
|
|
4
|
-
import { TemplateField } from '../template.model.js';
|
|
3
|
+
import { Template, TemplateField } from '../template.model.js';
|
|
5
4
|
import type { TemplateRenderer, TemplateRendererOptions, TemplateRendererString } from '../template.renderer.js';
|
|
6
5
|
import { TemplateResolver } from '../template.resolver.js';
|
|
7
6
|
export type JsxTemplate<Context extends Record = any> = FunctionComponent<Context> | ComponentClass<Context, any>;
|
|
@@ -9,7 +8,6 @@ export declare class JsxTemplateField<Renderer extends string = string, Options
|
|
|
9
8
|
template: JsxTemplate<Context>;
|
|
10
9
|
}
|
|
11
10
|
export declare class JsxTemplateResolver extends TemplateResolver<JsxTemplateField, JsxTemplate> {
|
|
12
|
-
constructor();
|
|
13
11
|
canHandle(resolver: string): boolean;
|
|
14
12
|
resolve(field: JsxTemplateField): JsxTemplate;
|
|
15
13
|
}
|
|
@@ -8,20 +8,17 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { Singleton } from '../../injector/decorators.js';
|
|
11
|
-
import {
|
|
11
|
+
import { FunctionProperty } from '../../schema/index.js';
|
|
12
12
|
import { TemplateField, simpleTemplate } from '../template.model.js';
|
|
13
13
|
import { TemplateResolver } from '../template.resolver.js';
|
|
14
14
|
export class JsxTemplateField extends TemplateField {
|
|
15
15
|
template;
|
|
16
16
|
}
|
|
17
17
|
__decorate([
|
|
18
|
-
|
|
18
|
+
FunctionProperty(),
|
|
19
19
|
__metadata("design:type", Object)
|
|
20
20
|
], JsxTemplateField.prototype, "template", void 0);
|
|
21
21
|
let JsxTemplateResolver = class JsxTemplateResolver extends TemplateResolver {
|
|
22
|
-
constructor() {
|
|
23
|
-
super();
|
|
24
|
-
}
|
|
25
22
|
canHandle(resolver) {
|
|
26
23
|
return (resolver == 'jsx');
|
|
27
24
|
}
|
|
@@ -30,8 +27,7 @@ let JsxTemplateResolver = class JsxTemplateResolver extends TemplateResolver {
|
|
|
30
27
|
}
|
|
31
28
|
};
|
|
32
29
|
JsxTemplateResolver = __decorate([
|
|
33
|
-
Singleton()
|
|
34
|
-
__metadata("design:paramtypes", [])
|
|
30
|
+
Singleton()
|
|
35
31
|
], JsxTemplateResolver);
|
|
36
32
|
export { JsxTemplateResolver };
|
|
37
33
|
export function jsxTemplateField(field) {
|
|
@@ -14,7 +14,7 @@ export type TemplateFields<Fields extends Record<string, boolean>, Resolver exte
|
|
|
14
14
|
}>;
|
|
15
15
|
export declare abstract class Template<Fields extends Record<string, boolean> = Record<string, boolean>, TemplateOptions = any, Context extends Record = any> {
|
|
16
16
|
readonly [templateContext]?: (context: Context) => void;
|
|
17
|
-
/**
|
|
17
|
+
/** Name of template */
|
|
18
18
|
name: string;
|
|
19
19
|
fields: TemplateFields<Fields, string, string, any, Context>;
|
|
20
20
|
options?: TemplateOptions;
|
|
@@ -7,18 +7,18 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { Any, any, Class, object, Optional, Property } from '../schema/index.js';
|
|
10
|
+
import { Any, any, Class, object, Optional, Property, StringProperty } from '../schema/index.js';
|
|
11
11
|
let TemplateField = class TemplateField {
|
|
12
12
|
resolver;
|
|
13
13
|
renderer;
|
|
14
14
|
options;
|
|
15
15
|
};
|
|
16
16
|
__decorate([
|
|
17
|
-
|
|
17
|
+
StringProperty(),
|
|
18
18
|
__metadata("design:type", String)
|
|
19
19
|
], TemplateField.prototype, "resolver", void 0);
|
|
20
20
|
__decorate([
|
|
21
|
-
|
|
21
|
+
StringProperty(),
|
|
22
22
|
__metadata("design:type", String)
|
|
23
23
|
], TemplateField.prototype, "renderer", void 0);
|
|
24
24
|
__decorate([
|
|
@@ -31,13 +31,13 @@ TemplateField = __decorate([
|
|
|
31
31
|
], TemplateField);
|
|
32
32
|
export { TemplateField };
|
|
33
33
|
export class Template {
|
|
34
|
-
/**
|
|
34
|
+
/** Name of template */
|
|
35
35
|
name;
|
|
36
36
|
fields;
|
|
37
37
|
options;
|
|
38
38
|
}
|
|
39
39
|
__decorate([
|
|
40
|
-
|
|
40
|
+
StringProperty(),
|
|
41
41
|
__metadata("design:type", String)
|
|
42
42
|
], Template.prototype, "name", void 0);
|
|
43
43
|
__decorate([
|
package/utils/math.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type RandomNumberGeneratorFn } from '../random/number-generator/random-number-generator-function.js';
|
|
2
2
|
/**
|
|
3
3
|
* Generate a random float in interval [min, max).
|
|
4
4
|
* @param min minimum value
|
|
@@ -81,3 +81,13 @@ export declare function clamp(value: number, minimum: number, maximum: number):
|
|
|
81
81
|
* @returns nth-root of base
|
|
82
82
|
*/
|
|
83
83
|
export declare function nthRoot(base: number, root: number): number;
|
|
84
|
+
/**
|
|
85
|
+
*
|
|
86
|
+
* @param t Time in interval [0, 1]
|
|
87
|
+
* @param attenuationExponentStart Sensible values are between 1 (linear attenuation) and ~10 (no attenuation until t = ~0.9, then sharply increasing attenuation)
|
|
88
|
+
* @param attenuationExponentEnd Sensible values are between 1 (linear attenuation) and ~10 (no attenuation until t = ~0.9, then sharply increasing attenuation)
|
|
89
|
+
* @param deadzoneWidthStart Deadzone width to add in front of 0.5. Sensible values are between 0 and 0.5
|
|
90
|
+
* @param deadzoneWidthEnd Deadzone width to add to interval [0.5, 1]. Sensible values are between 0 and 0.5
|
|
91
|
+
* @returns Coefficient in interval [0, 1]
|
|
92
|
+
*/
|
|
93
|
+
export declare function getAttenuationCoefficient(t: number, attenuationExponentStart: number | null, attenuationExponentEnd: number | null, deadzoneWidthStart?: number, deadzoneWidthEnd?: number): number;
|
package/utils/math.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NotSupportedError } from '../errors/not-supported.error.js';
|
|
2
2
|
import { defaultRandomNumberGeneratorFn } from '../random/number-generator/random-number-generator-function.js';
|
|
3
|
+
import { isNull } from './type-guards.js';
|
|
3
4
|
/**
|
|
4
5
|
* Generate a random float in interval [min, max).
|
|
5
6
|
* @param min minimum value
|
|
@@ -111,3 +112,30 @@ export function clamp(value, minimum, maximum) {
|
|
|
111
112
|
export function nthRoot(base, root) {
|
|
112
113
|
return (base < 0) ? -((-base) ** (1 / root)) : (base ** (1 / root));
|
|
113
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
*
|
|
117
|
+
* @param t Time in interval [0, 1]
|
|
118
|
+
* @param attenuationExponentStart Sensible values are between 1 (linear attenuation) and ~10 (no attenuation until t = ~0.9, then sharply increasing attenuation)
|
|
119
|
+
* @param attenuationExponentEnd Sensible values are between 1 (linear attenuation) and ~10 (no attenuation until t = ~0.9, then sharply increasing attenuation)
|
|
120
|
+
* @param deadzoneWidthStart Deadzone width to add in front of 0.5. Sensible values are between 0 and 0.5
|
|
121
|
+
* @param deadzoneWidthEnd Deadzone width to add to interval [0.5, 1]. Sensible values are between 0 and 0.5
|
|
122
|
+
* @returns Coefficient in interval [0, 1]
|
|
123
|
+
*/
|
|
124
|
+
export function getAttenuationCoefficient(t, attenuationExponentStart, attenuationExponentEnd, deadzoneWidthStart = 0, deadzoneWidthEnd = 0) {
|
|
125
|
+
if ((t < 0) || (t > 1)) {
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
128
|
+
if (t <= 0.5) {
|
|
129
|
+
if (isNull(attenuationExponentStart)) {
|
|
130
|
+
return 1;
|
|
131
|
+
}
|
|
132
|
+
if (t >= (0.5 - deadzoneWidthStart)) {
|
|
133
|
+
return 1;
|
|
134
|
+
}
|
|
135
|
+
return 1 - (-2 * (t - (0.5 - deadzoneWidthStart)) * (0.5 / (0.5 - deadzoneWidthStart))) ** (attenuationExponentStart ** 1.5);
|
|
136
|
+
}
|
|
137
|
+
if (isNull(attenuationExponentEnd) || (t <= (0.5 + deadzoneWidthEnd))) {
|
|
138
|
+
return 1;
|
|
139
|
+
}
|
|
140
|
+
return 1 - (-2 * (-(t - 1) - (0.5 - deadzoneWidthEnd)) * (0.5 / (0.5 - deadzoneWidthEnd))) ** (attenuationExponentEnd ** 1.5);
|
|
141
|
+
}
|
package/utils/string/index.d.ts
CHANGED
package/utils/string/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function toSnakeCase(value: string): string;
|