@tstdl/base 0.92.8 → 0.92.9

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.
Files changed (57) hide show
  1. package/ai/ai.service.d.ts +19 -4
  2. package/ai/ai.service.js +241 -3
  3. package/ai/functions.d.ts +5 -0
  4. package/ai/functions.js +40 -0
  5. package/ai/types.d.ts +27 -0
  6. package/ai/types.js +3 -0
  7. package/orm/schemas/json.d.ts +2 -2
  8. package/orm/schemas/numeric-date.d.ts +2 -2
  9. package/orm/schemas/timestamp.d.ts +2 -2
  10. package/orm/schemas/uuid.d.ts +2 -2
  11. package/package.json +5 -4
  12. package/reflection/registry.js +2 -2
  13. package/reflection/utils.d.ts +1 -3
  14. package/schema/decorators/index.d.ts +2 -3
  15. package/schema/decorators/index.js +1 -3
  16. package/schema/decorators/schema.d.ts +21 -0
  17. package/schema/decorators/schema.js +36 -0
  18. package/schema/decorators/types.d.ts +10 -2
  19. package/schema/decorators/utils.d.ts +7 -2
  20. package/schema/decorators/utils.js +26 -7
  21. package/schema/schema.d.ts +2 -2
  22. package/schema/schemas/any.d.ts +2 -2
  23. package/schema/schemas/array.d.ts +2 -2
  24. package/schema/schemas/bigint.d.ts +2 -2
  25. package/schema/schemas/boolean.d.ts +2 -2
  26. package/schema/schemas/date.d.ts +2 -2
  27. package/schema/schemas/defaulted.d.ts +2 -2
  28. package/schema/schemas/deferred.d.ts +2 -2
  29. package/schema/schemas/enumeration.d.ts +2 -2
  30. package/schema/schemas/function.d.ts +20 -6
  31. package/schema/schemas/function.js +58 -7
  32. package/schema/schemas/instance.d.ts +2 -2
  33. package/schema/schemas/literal.d.ts +2 -2
  34. package/schema/schemas/never.d.ts +1 -1
  35. package/schema/schemas/nullable.d.ts +2 -2
  36. package/schema/schemas/nullable.js +2 -2
  37. package/schema/schemas/number.d.ts +4 -4
  38. package/schema/schemas/object.d.ts +2 -2
  39. package/schema/schemas/object.js +7 -18
  40. package/schema/schemas/one-or-many.d.ts +2 -2
  41. package/schema/schemas/optional.d.ts +2 -2
  42. package/schema/schemas/optional.js +2 -2
  43. package/schema/schemas/readable-stream.d.ts +2 -2
  44. package/schema/schemas/regexp.d.ts +2 -2
  45. package/schema/schemas/string.d.ts +2 -2
  46. package/schema/schemas/symbol.d.ts +2 -2
  47. package/schema/schemas/uint8-array.d.ts +2 -2
  48. package/schema/schemas/union.d.ts +2 -2
  49. package/schema/schemas/unknown.d.ts +2 -2
  50. package/schema/testable.d.ts +2 -2
  51. package/schema/testable.js +9 -9
  52. package/templates/resolvers/jsx.template-resolver.js +2 -2
  53. package/types.d.ts +1 -1
  54. package/utils/object/lazy-property.d.ts +2 -2
  55. package/utils/object/object.d.ts +2 -1
  56. package/schema/decorators/property.d.ts +0 -12
  57. package/schema/decorators/property.js +0 -21
@@ -1,9 +1,28 @@
1
1
  /* eslint-disable @typescript-eslint/naming-convention */
2
- import { createPropertyOrAccessorDecorator } from '../../reflection/index.js';
3
- import { filterUndefinedObjectProperties } from '../../utils/object/object.js';
4
- export function createSchemaPropertyDecorator(data = {}) {
5
- return createPropertyOrAccessorDecorator({
6
- data: { schema: filterUndefinedObjectProperties(data) },
7
- mergeData: true
8
- });
2
+ import { isDefined, isFunction, isNullOrUndefined, isUndefined } from '../../utils/type-guards.js';
3
+ import { array } from '../schemas/array.js';
4
+ import { nullable } from '../schemas/nullable.js';
5
+ import { optional } from '../schemas/optional.js';
6
+ import { schemaTestableToSchema } from '../testable.js';
7
+ export function schemaReflectionDataToSchema(reflectionData, fallbackType, source) {
8
+ if (isUndefined(reflectionData?.schema) && (fallbackType == Object)) {
9
+ throw new Error(`Schema of property "${String(source.key)}" on type ${source.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.`);
10
+ }
11
+ let propertySchema = isDefined(reflectionData?.schema) ? reflectionData.schema(reflectionData) : fallbackType;
12
+ if (isNullOrUndefined(propertySchema)) {
13
+ throw new Error(`Could not infer schema for property "${String(source.key)}" on type ${source.type.name}. This happens if neither explicit @Property(type) is used nor reflection metadata is available.`);
14
+ }
15
+ if (isFunction(propertySchema)) {
16
+ propertySchema = schemaTestableToSchema(propertySchema, { description: reflectionData?.description, example: reflectionData?.example });
17
+ }
18
+ if (reflectionData?.array == true) {
19
+ propertySchema = array(propertySchema);
20
+ }
21
+ if (reflectionData?.nullable == true) {
22
+ propertySchema = nullable(propertySchema);
23
+ }
24
+ if (reflectionData?.optional == true) {
25
+ propertySchema = optional(propertySchema);
26
+ }
27
+ return propertySchema;
9
28
  }
@@ -22,9 +22,9 @@ type NormalizePrimitiveToConstructor<T> = Or<IsEqual<T, string>, IsEqual<T, Stri
22
22
  export type SchemaTestable<T = unknown> = Schema<T> | AbstractConstructor<T> | NormalizePrimitiveToConstructor<T>;
23
23
  export type SchemaOutput<T extends SchemaTestable> = T extends SchemaTestable<infer U> ? U : never;
24
24
  export declare const OPTIONAL: unique symbol;
25
- export type SchemaOptions<T> = {
25
+ export type SchemaOptions<_T> = {
26
26
  description?: string | null;
27
- example?: T | undefined;
27
+ example?: any;
28
28
  };
29
29
  export declare abstract class Schema<T = unknown> {
30
30
  readonly [OPTIONAL]: boolean;
@@ -1,4 +1,4 @@
1
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
1
+ import { type SchemaPropertyDecorator, type SchemaDecoratorOptions } from '../decorators/index.js';
2
2
  import { Schema, type SchemaOptions, type SchemaTestResult } from '../schema.js';
3
3
  export type AnySchemaOptions = SchemaOptions<any>;
4
4
  export declare class AnySchema extends Schema<any> {
@@ -6,4 +6,4 @@ export declare class AnySchema extends Schema<any> {
6
6
  _test(value: any): SchemaTestResult<any>;
7
7
  }
8
8
  export declare function any(options?: AnySchemaOptions): AnySchema;
9
- export declare function Any(options?: AnySchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
9
+ export declare function Any(options?: AnySchemaOptions & SchemaDecoratorOptions): SchemaPropertyDecorator;
@@ -1,6 +1,6 @@
1
1
  import type { JsonPath } from '../../json-path/json-path.js';
2
2
  import type { TypedOmit } from '../../types.js';
3
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
3
+ import { type SchemaDecoratorOptions, type SchemaPropertyDecorator } from '../decorators/index.js';
4
4
  import { Schema, type SchemaOptions, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
5
5
  import type { Coercible } from '../types.js';
6
6
  export type ArraySchemaOptions<T> = SchemaOptions<T[]> & Coercible & {
@@ -17,4 +17,4 @@ export declare class ArraySchema<T> extends Schema<T[]> {
17
17
  _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T[]>;
18
18
  }
19
19
  export declare function array<T>(schema: SchemaTestable<T>, options?: ArraySchemaOptions<T>): ArraySchema<T>;
20
- export declare function Array(schema: SchemaTestable, options?: ArraySchemaOptions<unknown> & TypedOmit<SchemaPropertyDecoratorOptions, 'array'>): SchemaPropertyDecorator;
20
+ export declare function Array(schema: SchemaTestable, options?: ArraySchemaOptions<unknown> & TypedOmit<SchemaDecoratorOptions, 'array'>): SchemaPropertyDecorator;
@@ -1,4 +1,4 @@
1
- import { type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
1
+ import { type SchemaDecoratorOptions } from '../decorators/index.js';
2
2
  import type { SchemaPropertyDecorator } from '../decorators/types.js';
3
3
  import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
4
4
  export type BigIntSchemaOptions = SimpleSchemaOptions<bigint>;
@@ -7,4 +7,4 @@ export declare class BigIntSchema extends SimpleSchema<bigint> {
7
7
  constructor(options?: BigIntSchemaOptions);
8
8
  }
9
9
  export declare function bigint(options?: BigIntSchemaOptions): BigIntSchema;
10
- export declare function BigIntProperty(options?: BigIntSchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
10
+ export declare function BigIntProperty(options?: BigIntSchemaOptions & SchemaDecoratorOptions): SchemaPropertyDecorator;
@@ -1,4 +1,4 @@
1
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
1
+ import { type SchemaPropertyDecorator, type SchemaDecoratorOptions } from '../decorators/index.js';
2
2
  import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
3
3
  export type BooleanSchemaOptions = SimpleSchemaOptions<boolean>;
4
4
  export declare class BooleanSchema extends SimpleSchema<boolean> {
@@ -6,4 +6,4 @@ export declare class BooleanSchema extends SimpleSchema<boolean> {
6
6
  constructor(options?: BooleanSchemaOptions);
7
7
  }
8
8
  export declare function boolean(options?: BooleanSchemaOptions): BooleanSchema;
9
- export declare function BooleanProperty(options?: BooleanSchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
9
+ export declare function BooleanProperty(options?: BooleanSchemaOptions & SchemaDecoratorOptions): SchemaPropertyDecorator;
@@ -1,4 +1,4 @@
1
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
1
+ import { type SchemaPropertyDecorator, type SchemaDecoratorOptions } from '../decorators/index.js';
2
2
  import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
3
3
  export type DateSchemaOptions = SimpleSchemaOptions<globalThis.Date> & {
4
4
  integer?: boolean;
@@ -8,4 +8,4 @@ export declare class DateSchema extends SimpleSchema<globalThis.Date> {
8
8
  constructor(options?: DateSchemaOptions);
9
9
  }
10
10
  export declare function date(options?: DateSchemaOptions): DateSchema;
11
- export declare function DateProperty(options?: SchemaPropertyDecoratorOptions & DateSchemaOptions): SchemaPropertyDecorator;
11
+ export declare function DateProperty(options?: SchemaDecoratorOptions & DateSchemaOptions): SchemaPropertyDecorator;
@@ -1,5 +1,5 @@
1
1
  import type { JsonPath } from '../../json-path/json-path.js';
2
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
2
+ import { type SchemaPropertyDecorator, type SchemaDecoratorOptions } from '../decorators/index.js';
3
3
  import { Schema, type SchemaOptions, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
4
4
  export type DefaultSchemaOptions<T, D> = SchemaOptions<T | D>;
5
5
  export declare class DefaultSchema<T, D> extends Schema<T | D> {
@@ -10,4 +10,4 @@ export declare class DefaultSchema<T, D> extends Schema<T | D> {
10
10
  _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T | D>;
11
11
  }
12
12
  export declare function defaulted<T, D>(schema: SchemaTestable<T>, defaultValue: D, options?: DefaultSchemaOptions<T, D>): DefaultSchema<T, D>;
13
- export declare function Defaulted<T, D>(schema: SchemaTestable<T>, defaultValue: D, options?: DefaultSchemaOptions<T, D> & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
13
+ export declare function Defaulted<T, D>(schema: SchemaTestable<T>, defaultValue: D, options?: DefaultSchemaOptions<T, D> & SchemaDecoratorOptions): SchemaPropertyDecorator;
@@ -1,5 +1,5 @@
1
1
  import type { JsonPath } from '../../json-path/json-path.js';
2
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
2
+ import { type SchemaPropertyDecorator, type SchemaDecoratorOptions } from '../decorators/index.js';
3
3
  import { Schema, type SchemaOutput, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
4
4
  export declare class DeferredSchema<T extends SchemaTestable> extends Schema<SchemaOutput<T>> {
5
5
  readonly name: string;
@@ -9,4 +9,4 @@ export declare class DeferredSchema<T extends SchemaTestable> extends Schema<Sch
9
9
  _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<SchemaOutput<T>>;
10
10
  }
11
11
  export declare function deferred<T extends SchemaTestable>(schema: () => T): DeferredSchema<T>;
12
- export declare function Deferred(schema: () => SchemaTestable, options?: SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
12
+ export declare function Deferred(schema: () => SchemaTestable, options?: SchemaDecoratorOptions): SchemaPropertyDecorator;
@@ -1,5 +1,5 @@
1
1
  import type { Enumeration as EnumerationType, EnumerationValue } from '../../types.js';
2
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
2
+ import { type SchemaPropertyDecorator, type SchemaDecoratorOptions } from '../decorators/index.js';
3
3
  import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
4
4
  export type EnumerationSchemaOptions<T extends EnumerationType> = SimpleSchemaOptions<EnumerationValue<T>>;
5
5
  export declare class EnumerationSchema<const T extends EnumerationType> extends SimpleSchema<EnumerationValue<T>> {
@@ -10,4 +10,4 @@ export declare class EnumerationSchema<const T extends EnumerationType> extends
10
10
  constructor(enumeration: T, options?: EnumerationSchemaOptions<T>);
11
11
  }
12
12
  export declare function enumeration<const T extends EnumerationType>(enumeration: T, options?: EnumerationSchemaOptions<T>): EnumerationSchema<T>;
13
- export declare function Enumeration<const T extends EnumerationType>(enumeration: T, options?: EnumerationSchemaOptions<T> & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
13
+ export declare function Enumeration<const T extends EnumerationType>(enumeration: T, options?: EnumerationSchemaOptions<T> & SchemaDecoratorOptions): SchemaPropertyDecorator;
@@ -1,9 +1,23 @@
1
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
1
+ import type { AbstractConstructor, Function } from '../../types.js';
2
+ import { type CombinedSchemaDecorator, type SchemaDecoratorOptions } from '../decorators/index.js';
3
+ import type { Schema, SchemaTestable } from '../schema.js';
2
4
  import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
3
- export type FunctionSchemaOptions = SimpleSchemaOptions<Function>;
4
- export declare class FunctionSchema extends SimpleSchema<Function> {
5
+ export type FunctionSchemaOptions<T extends Function> = SimpleSchemaOptions<T> & {
6
+ parameterNames?: (string | null)[];
7
+ };
8
+ type MappedParameters<T> = {
9
+ [I in keyof T]: SchemaTestable<T[I]>;
10
+ };
11
+ export declare class FunctionSchema<T extends (...args: any[]) => any> extends SimpleSchema<T> {
5
12
  readonly name = "function";
6
- constructor(options?: FunctionSchemaOptions);
13
+ readonly parameterSchemas: MappedParameters<Parameters<T>> | null;
14
+ readonly parameterNames: (string | null)[];
15
+ readonly returnValueSchema: SchemaTestable<ReturnType<T>> | null;
16
+ constructor(parameterSchemas: MappedParameters<Parameters<T>> | null, returnValueSchema: SchemaTestable<ReturnType<T>> | null, options?: FunctionSchemaOptions<T>);
7
17
  }
8
- export declare function func(options?: FunctionSchemaOptions): FunctionSchema;
9
- export declare function FunctionProperty(options?: FunctionSchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
18
+ export declare function func<T extends (...args: any[]) => any>(parameterSchemas: MappedParameters<Parameters<T>> | null, returnValueSchema: SchemaTestable<ReturnType<T>> | null, options?: FunctionSchemaOptions<T>): FunctionSchema<T>;
19
+ export declare function Method<T extends (...args: any[]) => any>(options?: FunctionSchemaOptions<T> & SchemaDecoratorOptions): CombinedSchemaDecorator;
20
+ export declare function Method<T extends (...args: any[]) => any>(parameterSchemas: MappedParameters<Parameters<T>> | null, returnValueSchema: SchemaTestable<ReturnType<T>> | null, options?: FunctionSchemaOptions<T> & SchemaDecoratorOptions): CombinedSchemaDecorator;
21
+ export declare function getFunctionSchemaFromReflection(type: AbstractConstructor, method: string | symbol): Schema<Function> | FunctionSchema<(...args: any[]) => any>;
22
+ export declare function tryGetFunctionSchemaFromReflection(type: AbstractConstructor, method: string | symbol): Schema<Function> | FunctionSchema<(...args: any[]) => any> | null;
23
+ export {};
@@ -1,16 +1,67 @@
1
1
  /* eslint-disable @typescript-eslint/no-unsafe-function-type */
2
- import { isFunction } from '../../utils/type-guards.js';
3
- import { PropertySchema } from '../decorators/index.js';
2
+ import { reflectionRegistry } from '../../reflection/registry.js';
3
+ import { createMethodDecorator } from '../../reflection/utils.js';
4
+ import { isArray, isDefined, isFunction, isNull, isUndefined } from '../../utils/type-guards.js';
5
+ import { createSchemaDecorator, Property } from '../decorators/index.js';
6
+ import { schemaReflectionDataToSchema } from '../decorators/utils.js';
7
+ import { schemaTestableToSchema } from '../testable.js';
8
+ import { never } from './never.js';
9
+ import { optional } from './optional.js';
4
10
  import { SimpleSchema } from './simple.js';
5
11
  export class FunctionSchema extends SimpleSchema {
6
12
  name = 'function';
7
- constructor(options) {
13
+ parameterSchemas;
14
+ parameterNames;
15
+ returnValueSchema;
16
+ constructor(parameterSchemas, returnValueSchema, options) {
8
17
  super('function', isFunction, options);
18
+ this.parameterSchemas = parameterSchemas;
19
+ this.parameterNames = options?.parameterNames ?? [];
20
+ this.returnValueSchema = returnValueSchema;
9
21
  }
10
22
  }
11
- export function func(options) {
12
- return new FunctionSchema(options);
23
+ export function func(parameterSchemas, returnValueSchema, options) {
24
+ return new FunctionSchema(parameterSchemas, returnValueSchema, options);
13
25
  }
14
- export function FunctionProperty(options) {
15
- return PropertySchema((data) => func({ description: data.description, example: data.example, ...options }), options);
26
+ export function Method(parameterSchemasOrOptions, returnValueSchema, optionsOrNothing) {
27
+ if (isArray(parameterSchemasOrOptions) || isNull(parameterSchemasOrOptions)) {
28
+ return Property({
29
+ ...optionsOrNothing,
30
+ schema: (data) => func(parameterSchemasOrOptions, returnValueSchema, { description: data.description, example: data.example, ...optionsOrNothing })
31
+ });
32
+ }
33
+ return createMethodDecorator({
34
+ handler: (data, _metdata, originalArguments) => {
35
+ createSchemaDecorator(parameterSchemasOrOptions)(...originalArguments);
36
+ Property(getFunctionSchemaFromReflection(data.constructor, data.methodKey), parameterSchemasOrOptions);
37
+ }
38
+ });
39
+ }
40
+ export function getFunctionSchemaFromReflection(type, method) {
41
+ const schema = tryGetFunctionSchemaFromReflection(type, method);
42
+ if (isNull(schema)) {
43
+ throw new Error(`Could not get functions schema for ${type.name}["${String(method)}"] from reflection data.`);
44
+ }
45
+ return schema;
46
+ }
47
+ export function tryGetFunctionSchemaFromReflection(type, method) {
48
+ const typeMetadata = reflectionRegistry.getMetadata(type);
49
+ const methodMetadata = typeMetadata?.methods.get(method);
50
+ if (isUndefined(methodMetadata)) {
51
+ return null;
52
+ }
53
+ const methodData = methodMetadata.data.tryGet('schema') ?? {};
54
+ if (isFunction(methodData.schema)) {
55
+ return schemaTestableToSchema(methodData.schema(methodData));
56
+ }
57
+ const parameterSchemas = methodMetadata.parameters.map((parameterMetadata) => {
58
+ const parameterData = parameterMetadata.data.tryGet('schema') ?? {};
59
+ return schemaReflectionDataToSchema(parameterData, parameterMetadata.type, { type, key: `${String(method)}(parameter:${parameterMetadata.index})` });
60
+ });
61
+ const parameterNames = methodMetadata.parameters.map((parameterMetadata) => {
62
+ const parameterData = parameterMetadata.data.tryGet('schema') ?? {};
63
+ return parameterData.parameter?.name ?? null;
64
+ });
65
+ const returnTypeSchema = isDefined(methodData.method?.returnType) ? methodData.method.returnType(methodData) : (methodMetadata.returnType ?? optional(never()));
66
+ return func(parameterSchemas, returnTypeSchema, { parameterNames, description: methodData.description, example: methodData.example });
16
67
  }
@@ -1,6 +1,6 @@
1
1
  import type { JsonPath } from '../../json-path/json-path.js';
2
2
  import type { AbstractConstructor } from '../../types.js';
3
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
3
+ import { type SchemaPropertyDecorator, type SchemaDecoratorOptions } from '../decorators/index.js';
4
4
  import { Schema, type SchemaOptions, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
5
5
  export type InstanceSchemaOptions<T extends AbstractConstructor> = SchemaOptions<InstanceType<T>>;
6
6
  export declare class InstanceSchema<T extends AbstractConstructor> extends Schema<InstanceType<T>> {
@@ -10,4 +10,4 @@ export declare class InstanceSchema<T extends AbstractConstructor> extends Schem
10
10
  _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<InstanceType<T>>;
11
11
  }
12
12
  export declare function instance<T extends AbstractConstructor>(type: T, options?: InstanceSchemaOptions<T>): InstanceSchema<T>;
13
- export declare function Instance<T extends AbstractConstructor>(type: T, options?: InstanceSchemaOptions<T> & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
13
+ export declare function Instance<T extends AbstractConstructor>(type: T, options?: InstanceSchemaOptions<T> & SchemaDecoratorOptions): SchemaPropertyDecorator;
@@ -1,5 +1,5 @@
1
1
  import type { JsonPath } from '../../json-path/json-path.js';
2
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
2
+ import { type SchemaPropertyDecorator, type SchemaDecoratorOptions } from '../decorators/index.js';
3
3
  import { Schema, SchemaOptions, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
4
4
  export type LiteralSchemaOptions<T> = SchemaOptions<T>;
5
5
  export declare class LiteralSchema<const T> extends Schema<T> {
@@ -9,4 +9,4 @@ export declare class LiteralSchema<const T> extends Schema<T> {
9
9
  _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T>;
10
10
  }
11
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;
12
+ export declare function Literal<const T>(value: T, options?: LiteralSchemaOptions<T> & SchemaDecoratorOptions): SchemaPropertyDecorator;
@@ -1,5 +1,5 @@
1
1
  import type { JsonPath } from '../../json-path/json-path.js';
2
- import { Schema, SchemaOptions, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
2
+ import { Schema, type SchemaOptions, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
3
3
  export type NeverSchemaOptions = SchemaOptions<never>;
4
4
  export declare class NeverSchema extends Schema<never> {
5
5
  readonly name = "never";
@@ -1,6 +1,6 @@
1
1
  import type { JsonPath } from '../../json-path/json-path.js';
2
2
  import type { TypedOmit } from '../../types.js';
3
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
3
+ import { type SchemaDecoratorOptions, type SchemaPropertyDecorator } from '../decorators/index.js';
4
4
  import { Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
5
5
  export declare class NullableSchema<T> extends Schema<T | null> {
6
6
  readonly name: string;
@@ -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<T>(schema?: SchemaTestable<T>, options?: TypedOmit<SchemaPropertyDecoratorOptions, 'nullable'>): SchemaPropertyDecorator;
12
+ export declare function Nullable<T>(schema?: SchemaTestable<T>, options?: TypedOmit<SchemaDecoratorOptions, 'nullable'>): SchemaPropertyDecorator;
@@ -1,6 +1,6 @@
1
1
  import { lazyProperty } from '../../utils/object/lazy-property.js';
2
2
  import { isNull } from '../../utils/type-guards.js';
3
- import { createSchemaPropertyDecorator } from '../decorators/index.js';
3
+ import { createSchemaDecorator } from '../decorators/index.js';
4
4
  import { Schema } from '../schema.js';
5
5
  import { schemaTestableToSchema } from '../testable.js';
6
6
  export class NullableSchema extends Schema {
@@ -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: () => schema, ...options, nullable: true });
28
+ return createSchemaDecorator({ schema: () => schema, ...options, nullable: true });
29
29
  }
@@ -1,5 +1,5 @@
1
- import { TypedOmit } from '../../types.js';
2
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
1
+ import type { TypedOmit } from '../../types.js';
2
+ import { type SchemaDecoratorOptions, type SchemaPropertyDecorator } from '../decorators/index.js';
3
3
  import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
4
4
  export type NumberSchemaOptions = SimpleSchemaOptions<number> & {
5
5
  integer?: boolean;
@@ -15,5 +15,5 @@ export declare class NumberSchema extends SimpleSchema<number> {
15
15
  }
16
16
  export declare function number(options?: NumberSchemaOptions): NumberSchema;
17
17
  export declare function integer(options?: TypedOmit<NumberSchemaOptions, 'integer'>): NumberSchema;
18
- export declare function NumberProperty(options?: SchemaPropertyDecoratorOptions & NumberSchemaOptions): SchemaPropertyDecorator;
19
- export declare function Integer(options?: SchemaPropertyDecoratorOptions & TypedOmit<NumberSchemaOptions, 'integer'>): SchemaPropertyDecorator;
18
+ export declare function NumberProperty(options?: SchemaDecoratorOptions & NumberSchemaOptions): SchemaPropertyDecorator;
19
+ export declare function Integer(options?: SchemaDecoratorOptions & TypedOmit<NumberSchemaOptions, 'integer'>): SchemaPropertyDecorator;
@@ -2,7 +2,7 @@ import type { EmptyObject, Merge } from 'type-fest';
2
2
  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
- import { type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
5
+ import { type SchemaDecoratorOptions } from '../decorators/index.js';
6
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;
@@ -86,6 +86,6 @@ export declare function omit<const T extends Record, const K extends keyof T>(sc
86
86
  export declare function getSchemaFromReflection<T extends Record>(type: AbstractConstructor<T>): Schema<T>;
87
87
  declare function _tryGetSchemaFromReflection<T extends Record>(type: AbstractConstructor<T>): Schema<T> | ObjectSchema<T> | null;
88
88
  export declare function getObjectSchema<T extends Record>(schemaOrType: SchemaTestable<T>): ObjectSchema<T>;
89
- export declare function Record<K extends PropertyKey, V>(key: SchemaTestable<K>, value: SchemaTestable<V>, options?: TypedOmit<ObjectSchemaOptions<Record<K, V>>, 'unknownProperties' | 'unknownPropertiesKey'> & SchemaPropertyDecoratorOptions): Decorator<'class' | 'property' | 'accessor'>;
89
+ export declare function Record<K extends PropertyKey, V>(key: SchemaTestable<K>, value: SchemaTestable<V>, options?: TypedOmit<ObjectSchemaOptions<Record<K, V>>, 'unknownProperties' | 'unknownPropertiesKey'> & SchemaDecoratorOptions): Decorator<'class' | 'property' | 'accessor'>;
90
90
  export declare const emptyObjectSchema: ObjectSchema<EmptyObject>;
91
91
  export {};
@@ -7,10 +7,10 @@ import { filterObject, fromEntries, mapObjectValues, objectKeys } from '../../ut
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
9
  import { Class, PropertySchema } from '../decorators/index.js';
10
+ import { schemaReflectionDataToSchema } from '../decorators/utils.js';
10
11
  import { Schema } from '../schema.js';
11
12
  import { schemaTestableToSchema } from '../testable.js';
12
- import { array } from './array.js';
13
- import { nullable } from './nullable.js';
13
+ import { getFunctionSchemaFromReflection } from './function.js';
14
14
  import { optional } from './optional.js';
15
15
  export const tryGetSchemaFromReflection = memoizeSingle(_tryGetSchemaFromReflection, { weak: true });
16
16
  export class ObjectSchema extends Schema {
@@ -168,22 +168,11 @@ function getObjectSchemaPropertiesFromReflection(metadata, type) {
168
168
  const properties = {};
169
169
  for (const [key, propertyMetadata] of metadata.properties) {
170
170
  const reflectionData = propertyMetadata.data.tryGet('schema');
171
- if (isUndefined(reflectionData?.schema) && (propertyMetadata.type == Object)) {
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.`);
173
- }
174
- let propertySchema = isDefined(reflectionData?.schema) ? reflectionData.schema(reflectionData) : propertyMetadata.type;
175
- if (isUndefined(propertySchema)) {
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.`);
177
- }
178
- if (reflectionData?.array == true) {
179
- propertySchema = array(propertySchema);
180
- }
181
- if (reflectionData?.nullable == true) {
182
- propertySchema = nullable(propertySchema);
183
- }
184
- if (reflectionData?.optional == true) {
185
- propertySchema = optional(propertySchema);
186
- }
171
+ const propertySchema = schemaReflectionDataToSchema(reflectionData, type, { type, key });
172
+ properties[key] = propertySchema;
173
+ }
174
+ for (const [key] of metadata.methods) {
175
+ const propertySchema = getFunctionSchemaFromReflection(type, key);
187
176
  properties[key] = propertySchema;
188
177
  }
189
178
  return properties;
@@ -1,6 +1,6 @@
1
1
  import type { JsonPath } from '../../json-path/json-path.js';
2
2
  import type { OneOrMany as OneOrManyType } from '../../types.js';
3
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
3
+ import { type SchemaPropertyDecorator, type SchemaDecoratorOptions } from '../decorators/index.js';
4
4
  import { Schema, type SchemaOptions, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
5
5
  export type OneOrManySchemaOptions<T> = SchemaOptions<T | T[]>;
6
6
  export type OneOrMany<T> = OneOrManyType<T>;
@@ -11,4 +11,4 @@ export declare class OneOrManySchema<T> extends Schema<T | T[]> {
11
11
  _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T | T[]>;
12
12
  }
13
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;
14
+ export declare function OneOrMany<T>(schema: SchemaTestable<T>, options?: OneOrManySchemaOptions<T> & SchemaDecoratorOptions): SchemaPropertyDecorator;
@@ -1,6 +1,6 @@
1
1
  import type { JsonPath } from '../../json-path/json-path.js';
2
2
  import type { TypedOmit } from '../../types.js';
3
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
3
+ import { type SchemaDecoratorOptions, type SchemaPropertyDecorator } from '../decorators/index.js';
4
4
  import { type OPTIONAL, Schema, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
5
5
  export declare class OptionalSchema<T> extends Schema<T | undefined> {
6
6
  readonly name: string;
@@ -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<T>(schema?: SchemaTestable<T>, options?: TypedOmit<SchemaPropertyDecoratorOptions, 'optional'>): SchemaPropertyDecorator;
13
+ export declare function Optional<T>(schema?: SchemaTestable<T>, options?: TypedOmit<SchemaDecoratorOptions, 'optional'>): SchemaPropertyDecorator;
@@ -1,6 +1,6 @@
1
1
  import { lazyProperty } from '../../utils/object/lazy-property.js';
2
2
  import { isUndefined } from '../../utils/type-guards.js';
3
- import { createSchemaPropertyDecorator } from '../decorators/index.js';
3
+ import { createSchemaDecorator } from '../decorators/index.js';
4
4
  import { Schema } from '../schema.js';
5
5
  import { schemaTestableToSchema } from '../testable.js';
6
6
  export class OptionalSchema extends Schema {
@@ -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: () => schema, ...options, optional: true });
28
+ return createSchemaDecorator({ schema: () => schema, ...options, optional: true });
29
29
  }
@@ -1,4 +1,4 @@
1
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
1
+ import { type SchemaPropertyDecorator, type SchemaDecoratorOptions } from '../decorators/index.js';
2
2
  import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
3
3
  export type ReadableStreamSchemaOptions = SimpleSchemaOptions<ReadableStream>;
4
4
  export declare class ReadableStreamSchema extends SimpleSchema<ReadableStream> {
@@ -6,4 +6,4 @@ export declare class ReadableStreamSchema extends SimpleSchema<ReadableStream> {
6
6
  constructor(options?: ReadableStreamSchemaOptions);
7
7
  }
8
8
  export declare function readableStream(options?: ReadableStreamSchemaOptions): ReadableStreamSchema;
9
- export declare function ReadableStreamProperty(options?: SchemaPropertyDecoratorOptions & ReadableStreamSchemaOptions): SchemaPropertyDecorator;
9
+ export declare function ReadableStreamProperty(options?: SchemaDecoratorOptions & ReadableStreamSchemaOptions): SchemaPropertyDecorator;
@@ -1,4 +1,4 @@
1
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
1
+ import { type SchemaPropertyDecorator, type SchemaDecoratorOptions } from '../decorators/index.js';
2
2
  import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
3
3
  export type RegExpSchemaOptions = SimpleSchemaOptions<RegExp>;
4
4
  export declare class RegExpSchema extends SimpleSchema<RegExp> {
@@ -6,4 +6,4 @@ export declare class RegExpSchema extends SimpleSchema<RegExp> {
6
6
  constructor(options?: RegExpSchemaOptions);
7
7
  }
8
8
  export declare function regExp(options?: RegExpSchemaOptions): RegExpSchema;
9
- export declare function RegExpProperty(options?: SchemaPropertyDecoratorOptions & RegExpSchemaOptions): SchemaPropertyDecorator;
9
+ export declare function RegExpProperty(options?: SchemaDecoratorOptions & RegExpSchemaOptions): SchemaPropertyDecorator;
@@ -1,4 +1,4 @@
1
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
1
+ import { type SchemaPropertyDecorator, type SchemaDecoratorOptions } from '../decorators/index.js';
2
2
  import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
3
3
  export type StringSchemaOptions = SimpleSchemaOptions<string> & {
4
4
  pattern?: RegExp | string;
@@ -11,4 +11,4 @@ export declare class StringSchema extends SimpleSchema<string> {
11
11
  constructor(options?: StringSchemaOptions);
12
12
  }
13
13
  export declare function string(options?: StringSchemaOptions): StringSchema;
14
- export declare function StringProperty(options?: SchemaPropertyDecoratorOptions & StringSchemaOptions): SchemaPropertyDecorator;
14
+ export declare function StringProperty(options?: SchemaDecoratorOptions & StringSchemaOptions): SchemaPropertyDecorator;
@@ -1,4 +1,4 @@
1
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
1
+ import { type SchemaPropertyDecorator, type SchemaDecoratorOptions } from '../decorators/index.js';
2
2
  import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
3
3
  export type SymbolSchemaOptions = SimpleSchemaOptions<symbol>;
4
4
  export declare class SymbolSchema extends SimpleSchema<symbol> {
@@ -6,4 +6,4 @@ export declare class SymbolSchema extends SimpleSchema<symbol> {
6
6
  constructor(options?: SymbolSchemaOptions);
7
7
  }
8
8
  export declare function symbol(options?: SymbolSchemaOptions): SymbolSchema;
9
- export declare function SymbolProperty(options?: SymbolSchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
9
+ export declare function SymbolProperty(options?: SymbolSchemaOptions & SchemaDecoratorOptions): SchemaPropertyDecorator;
@@ -1,4 +1,4 @@
1
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
1
+ import { type SchemaPropertyDecorator, type SchemaDecoratorOptions } from '../decorators/index.js';
2
2
  import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
3
3
  export type Uint8ArraySchemaOptions = SimpleSchemaOptions<Uint8Array> & {
4
4
  /** Minimum byte length */
@@ -13,4 +13,4 @@ export declare class Uint8ArraySchema extends SimpleSchema<Uint8Array> {
13
13
  constructor(options?: Uint8ArraySchemaOptions);
14
14
  }
15
15
  export declare function uint8Array(options?: Uint8ArraySchemaOptions): Uint8ArraySchema;
16
- export declare function Uint8ArrayProperty(options?: Uint8ArraySchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
16
+ export declare function Uint8ArrayProperty(options?: Uint8ArraySchemaOptions & SchemaDecoratorOptions): SchemaPropertyDecorator;
@@ -1,5 +1,5 @@
1
1
  import type { JsonPath } from '../../json-path/json-path.js';
2
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
2
+ import { type SchemaPropertyDecorator, type SchemaDecoratorOptions } from '../decorators/index.js';
3
3
  import { Schema, type SchemaOutput, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../schema.js';
4
4
  type UnionSchemaType<T extends [SchemaTestable, ...SchemaTestable[]]> = T[number] extends SchemaTestable<infer V> ? V : never;
5
5
  export declare class UnionSchema<T extends [SchemaTestable, ...SchemaTestable[]]> extends Schema<UnionSchemaType<T>> {
@@ -11,5 +11,5 @@ export declare class UnionSchema<T extends [SchemaTestable, ...SchemaTestable[]]
11
11
  _test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<UnionSchemaType<T>>;
12
12
  }
13
13
  export declare function union<T extends [SchemaTestable, ...SchemaTestable[]]>(...schemas: T): UnionSchema<T>;
14
- export declare function Union(...schemasAndOptions: [SchemaTestable, ...SchemaTestable[]] | [SchemaTestable, ...SchemaTestable[], options: SchemaPropertyDecoratorOptions]): SchemaPropertyDecorator;
14
+ export declare function Union(...schemasAndOptions: [SchemaTestable, ...SchemaTestable[]] | [SchemaTestable, ...SchemaTestable[], options: SchemaDecoratorOptions]): SchemaPropertyDecorator;
15
15
  export {};
@@ -1,4 +1,4 @@
1
- import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
1
+ import { type SchemaPropertyDecorator, type SchemaDecoratorOptions } from '../decorators/index.js';
2
2
  import { Schema, type SchemaOptions, type SchemaTestResult } from '../schema.js';
3
3
  export type UnknownSchemaOptions = SchemaOptions<unknown>;
4
4
  export declare class UnknownSchema extends Schema<unknown> {
@@ -6,4 +6,4 @@ export declare class UnknownSchema extends Schema<unknown> {
6
6
  _test(value: unknown): SchemaTestResult<unknown>;
7
7
  }
8
8
  export declare function unknown(options?: UnknownSchemaOptions): UnknownSchema;
9
- export declare function Unknown(options?: UnknownSchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
9
+ export declare function Unknown(options?: UnknownSchemaOptions & SchemaDecoratorOptions): SchemaPropertyDecorator;
@@ -1,3 +1,3 @@
1
- import { Schema, type SchemaTestable } from './schema.js';
2
- export declare function schemaTestableToSchema<T>(testable: SchemaTestable<T>): Schema<T>;
1
+ import { Schema, type SchemaOptions, type SchemaTestable } from './schema.js';
2
+ export declare function schemaTestableToSchema<T>(testable: SchemaTestable<T>, options?: SchemaOptions<T>): Schema<T>;
3
3
  export declare function isSchemaTestable(value: any): value is SchemaTestable;
@@ -9,27 +9,27 @@ import { readableStream } from './schemas/readable-stream.js';
9
9
  import { string } from './schemas/string.js';
10
10
  import { symbol } from './schemas/symbol.js';
11
11
  import { uint8Array } from './schemas/uint8-array.js';
12
- export function schemaTestableToSchema(testable) {
12
+ export function schemaTestableToSchema(testable, options) {
13
13
  if (testable instanceof Schema) {
14
14
  return testable;
15
15
  }
16
16
  switch (testable) {
17
17
  case String:
18
- return string();
18
+ return string(options);
19
19
  case Number:
20
- return number();
20
+ return number(options);
21
21
  case Boolean:
22
- return boolean();
22
+ return boolean(options);
23
23
  case BigInt:
24
- return bigint();
24
+ return bigint(options);
25
25
  case Symbol:
26
- return symbol();
26
+ return symbol(options);
27
27
  case Function:
28
- return func();
28
+ return func(null, null);
29
29
  case Uint8Array:
30
- return uint8Array();
30
+ return uint8Array(options);
31
31
  case ReadableStream:
32
- return readableStream();
32
+ return readableStream(options);
33
33
  default:
34
34
  return getSchemaFromReflection(testable);
35
35
  }