@tstdl/base 0.93.57 → 0.93.58

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.93.57",
3
+ "version": "0.93.58",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -83,7 +83,7 @@ function convertToZodSchemaBase(schema, options) {
83
83
  const propertyEntries = objectEntries(s.properties);
84
84
  // Handle generic records (no specific properties, but has unknownProperties/Key)
85
85
  if ((propertyEntries.length == 0) && (isNotNull(s.unknownPropertiesKey) || isNotNull(s.unknownProperties))) {
86
- return z.record(convertToZodSchema(s.unknownPropertiesKey ?? any()), convertToZodSchema(s.unknownProperties ?? any()));
86
+ return z.record(convertToZodSchemaBase(s.unknownPropertiesKey ?? any(), options), convertToZodSchemaBase(s.unknownProperties ?? any(), options));
87
87
  }
88
88
  const shape = {};
89
89
  for (const [key, propertySchema] of propertyEntries) {
@@ -147,11 +147,11 @@ function convertToZodSchemaBase(schema, options) {
147
147
  .with(P.instanceOf(FunctionSchema), (s) => {
148
148
  let zodSchema = z.function();
149
149
  if (isNotNull(s.parameterSchemas)) {
150
- const args = s.parameterSchemas.map((parameterSchema) => convertToZodSchema(parameterSchema, options));
150
+ const args = s.parameterSchemas.map((parameterSchema) => convertToZodSchemaBase(parameterSchema, options));
151
151
  zodSchema = zodSchema.input(...args);
152
152
  }
153
153
  if (isNotNull(s.returnValueSchema)) {
154
- zodSchema = zodSchema.output(convertToZodSchema(s.returnValueSchema, options));
154
+ zodSchema = zodSchema.output(convertToZodSchemaBase(s.returnValueSchema, options));
155
155
  }
156
156
  return zodSchema;
157
157
  })
@@ -82,7 +82,7 @@ function convertToZodSchemaBase(schema, options) {
82
82
  const propertyEntries = objectEntries(s.properties);
83
83
  // Handle generic records (no specific properties, but has unknownProperties/Key)
84
84
  if ((propertyEntries.length == 0) && (isNotNull(s.unknownPropertiesKey) || isNotNull(s.unknownProperties))) {
85
- return z.record(convertToZodV3Schema(s.unknownPropertiesKey ?? any()), convertToZodV3Schema(s.unknownProperties ?? any()));
85
+ return z.record(convertToZodSchemaBase(s.unknownPropertiesKey ?? any(), options), convertToZodSchemaBase(s.unknownProperties ?? any(), options));
86
86
  }
87
87
  const shape = {};
88
88
  for (const [key, propertySchema] of propertyEntries) {
@@ -8,16 +8,19 @@ export type FunctionSchemaOptions<T extends Function> = SimpleSchemaOptions<T> &
8
8
  type MappedParameters<T> = {
9
9
  [I in keyof T]: SchemaTestable<T[I]>;
10
10
  };
11
- export declare class FunctionSchema<T extends (...args: any[]) => any> extends SimpleSchema<T> {
11
+ type NormalizedMappedParameters<T> = {
12
+ [I in keyof T]: Schema<T[I]>;
13
+ };
14
+ export declare class FunctionSchema<T extends Function> extends SimpleSchema<T> {
12
15
  readonly name = "function";
13
- readonly parameterSchemas: MappedParameters<Parameters<T>> | null;
16
+ readonly parameterSchemas: NormalizedMappedParameters<Parameters<T>> | null;
14
17
  readonly parameterNames: (string | null)[];
15
- readonly returnValueSchema: SchemaTestable<ReturnType<T>> | null;
18
+ readonly returnValueSchema: Schema<ReturnType<T>> | null;
16
19
  constructor(parameterSchemas: MappedParameters<Parameters<T>> | null, returnValueSchema: SchemaTestable<ReturnType<T>> | null, options?: FunctionSchemaOptions<T>);
17
20
  }
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;
21
+ export declare function func<T extends Function>(parameterSchemas: MappedParameters<Parameters<T>> | null, returnValueSchema: SchemaTestable<ReturnType<T>> | null, options?: FunctionSchemaOptions<T>): FunctionSchema<T>;
22
+ export declare function Method<T extends Function>(options?: FunctionSchemaOptions<T> & SchemaDecoratorOptions): CombinedSchemaDecorator;
23
+ export declare function Method<T extends Function>(parameterSchemas: MappedParameters<Parameters<T>> | null, returnValueSchema: SchemaTestable<ReturnType<T>> | null, options?: FunctionSchemaOptions<T> & SchemaDecoratorOptions): CombinedSchemaDecorator;
24
+ export declare function getFunctionSchemaFromReflection(type: AbstractConstructor, method: string | symbol): Schema<Function> | FunctionSchema<Function>;
25
+ export declare function tryGetFunctionSchemaFromReflection(type: AbstractConstructor, method: string | symbol): Schema<Function> | FunctionSchema<Function> | null;
23
26
  export {};
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-unsafe-function-type */
2
2
  import { reflectionRegistry } from '../../reflection/registry.js';
3
3
  import { createMethodDecorator } from '../../reflection/utils.js';
4
- import { isArray, isDefined, isFunction, isNull, isUndefined } from '../../utils/type-guards.js';
4
+ import { isArray, isDefined, isFunction, isNotNull, isNull, isUndefined } from '../../utils/type-guards.js';
5
5
  import { createSchemaDecorator, Property } from '../decorators/index.js';
6
6
  import { schemaReflectionDataToSchema } from '../decorators/utils.js';
7
7
  import { schemaTestableToSchema } from '../testable.js';
@@ -15,9 +15,9 @@ export class FunctionSchema extends SimpleSchema {
15
15
  returnValueSchema;
16
16
  constructor(parameterSchemas, returnValueSchema, options) {
17
17
  super('function', isFunction, options);
18
- this.parameterSchemas = parameterSchemas;
18
+ this.parameterSchemas = (parameterSchemas?.map((schema) => schemaTestableToSchema(schema)) ?? null);
19
19
  this.parameterNames = options?.parameterNames ?? [];
20
- this.returnValueSchema = returnValueSchema;
20
+ this.returnValueSchema = isNotNull(returnValueSchema) ? schemaTestableToSchema(returnValueSchema) : null;
21
21
  }
22
22
  }
23
23
  export function func(parameterSchemas, returnValueSchema, options) {