@tstdl/base 0.91.46 → 0.91.47

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.91.46",
3
+ "version": "0.91.47",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -115,7 +115,7 @@
115
115
  "luxon": "^3.5",
116
116
  "reflect-metadata": "^0.2",
117
117
  "rxjs": "^7.8",
118
- "type-fest": "4.28"
118
+ "type-fest": "4.29"
119
119
  },
120
120
  "devDependencies": {
121
121
  "@mxssfd/typedoc-theme": "1.1",
@@ -135,7 +135,7 @@
135
135
  "eslint-import-resolver-typescript": "3.6",
136
136
  "eslint-plugin-import": "2.31",
137
137
  "tsc-alias": "1.8",
138
- "typedoc": "0.26",
138
+ "typedoc": "0.27",
139
139
  "typedoc-plugin-missing-exports": "3.1",
140
140
  "typescript": "5.6"
141
141
  },
@@ -2,11 +2,11 @@ import type { Enumeration as EnumerationType, EnumerationValue } from '../../typ
2
2
  import { type SchemaPropertyDecorator, type SchemaPropertyDecoratorOptions } from '../decorators/index.js';
3
3
  import { SimpleSchema, type SimpleSchemaOptions } from './simple.js';
4
4
  export type EnumerationSchemaOptions = SimpleSchemaOptions;
5
- export declare class EnumerationSchema<T extends EnumerationType> extends SimpleSchema<EnumerationValue<T>> {
5
+ export declare class EnumerationSchema<const T extends EnumerationType> extends SimpleSchema<EnumerationValue<T>> {
6
6
  #private;
7
7
  readonly name: string;
8
8
  readonly enumeration: EnumerationType;
9
9
  constructor(enumeration: T, options?: EnumerationSchemaOptions);
10
10
  }
11
- export declare function enumeration<T extends EnumerationType>(enumeration: T, options?: EnumerationSchemaOptions): EnumerationSchema<T>;
11
+ export declare function enumeration<const T extends EnumerationType>(enumeration: T, options?: EnumerationSchemaOptions): EnumerationSchema<T>;
12
12
  export declare function Enumeration(enumeration: EnumerationType, options?: EnumerationSchemaOptions & SchemaPropertyDecoratorOptions): SchemaPropertyDecorator;
@@ -18,8 +18,8 @@ export type NormalizedObjectSchemaProperties<T extends Record> = {
18
18
  export type ObjectSchemaOptions<T extends Record = Record, K extends PropertyKey = PropertyKey, V = unknown> = {
19
19
  name?: string;
20
20
  mask?: boolean | null;
21
- unknownProperties?: SchemaTestable<V> | null;
22
21
  unknownPropertiesKey?: SchemaTestable<K> | null;
22
+ unknownProperties?: SchemaTestable<V> | null;
23
23
  factory?: ObjectSchemaFactory<T> | null;
24
24
  };
25
25
  export type ObjectSchemaOrType<T extends Record = any> = ObjectSchema<T> | AbstractConstructor<T>;
@@ -47,32 +47,33 @@ export declare class ObjectSchema<T extends Record = Record> extends Schema<T> {
47
47
  export declare function object<const K extends PropertyKey, const V>(properties: Record<never>, options: ObjectSchemaOptions<Record<K, V>> & {
48
48
  unknownProperties: SchemaTestable<V>;
49
49
  unknownPropertiesKey: SchemaTestable<K>;
50
- }): ObjectSchema<Record<K, V>>;
50
+ }): ObjectSchema<Partial<Record<K, V>>>;
51
51
  export declare function object<const K extends PropertyKey>(properties: Record<never>, options: ObjectSchemaOptions<Record<K, unknown>> & {
52
52
  unknownProperties?: undefined;
53
53
  unknownPropertiesKey: SchemaTestable<K>;
54
- }): ObjectSchema<Record<K, unknown>>;
54
+ }): ObjectSchema<Partial<Record<K, unknown>>>;
55
55
  export declare function object<const V>(properties: Record<never>, options: ObjectSchemaOptions<Record<PropertyKey, V>> & {
56
56
  unknownProperties: SchemaTestable<V>;
57
57
  unknownPropertiesKey?: undefined;
58
- }): ObjectSchema<Record<PropertyKey, V>>;
58
+ }): ObjectSchema<Partial<Record<PropertyKey, V>>>;
59
59
  export declare function object<const TP extends ObjectSchemaProperties, const K extends PropertyKey, const V>(properties: TP, options: ObjectSchemaOptions<ObjectSchemaPropertiesType<TP> & Record<K, V>> & {
60
60
  unknownProperties: SchemaTestable<V>;
61
61
  unknownPropertiesKey: SchemaTestable<K>;
62
- }): ObjectSchema<ObjectSchemaPropertiesType<TP> & Record<K, V>>;
62
+ }): ObjectSchema<ObjectSchemaPropertiesType<TP> & Partial<Record<K, V>>>;
63
63
  export declare function object<const TP extends ObjectSchemaProperties, const K extends PropertyKey>(properties: TP, options: ObjectSchemaOptions<ObjectSchemaPropertiesType<TP> & Record<K, unknown>> & {
64
64
  unknownPropertiesKey: SchemaTestable<K>;
65
- }): ObjectSchema<ObjectSchemaPropertiesType<TP> & Record<K, unknown>>;
65
+ }): ObjectSchema<ObjectSchemaPropertiesType<TP> & Partial<Record<K, unknown>>>;
66
66
  export declare function object<const TP extends ObjectSchemaProperties, const V>(properties: TP, options: ObjectSchemaOptions<ObjectSchemaPropertiesType<TP> & Record<PropertyKey, V>> & {
67
67
  unknownProperties: SchemaTestable<V>;
68
- }): ObjectSchema<ObjectSchemaPropertiesType<TP> & Record<PropertyKey, V>>;
68
+ }): ObjectSchema<ObjectSchemaPropertiesType<TP> & Partial<Record<PropertyKey, V>>>;
69
69
  export declare function object<const TP extends ObjectSchemaProperties>(properties: TP, options?: ObjectSchemaOptions<ObjectSchemaPropertiesType<TP>> & {
70
70
  unknownProperties?: undefined;
71
71
  unknownPropertiesKey?: undefined;
72
72
  }): ObjectSchema<ObjectSchemaPropertiesType<TP>>;
73
- export declare function object<const TP extends ObjectSchemaProperties, const K extends PropertyKey, const V>(properties: TP, options?: ObjectSchemaOptions<ObjectSchemaPropertiesType<TP>, K, V>): ObjectSchema<ObjectSchemaPropertiesType<TP> & Record<K, V>>;
73
+ export declare function object<const TP extends ObjectSchemaProperties, const K extends PropertyKey, const V>(properties: TP, options?: ObjectSchemaOptions<ObjectSchemaPropertiesType<TP>, K, V>): ObjectSchema<ObjectSchemaPropertiesType<TP> & Partial<Record<K, V>>>;
74
74
  export declare function explicitObject<const T extends Record>(properties: ObjectSchemaProperties<T>, options?: ObjectSchemaOptions<T>): ObjectSchema<T>;
75
- export declare function record<const K extends PropertyKey, const V>(key: Schema<K>, value: Schema<V>, options?: TypedOmit<ObjectSchemaOptions<Record<K, V>>, 'unknownProperties' | 'unknownPropertiesKey'>): ObjectSchema<Record<K, V>>;
75
+ export declare function record<const K extends PropertyKey, const V>(keys: K[], value: SchemaTestable<V>, options?: TypedOmit<ObjectSchemaOptions<Record<K, V>>, 'unknownProperties' | 'unknownPropertiesKey'>): ObjectSchema<Record<K, V>>;
76
+ export declare function record<const K extends PropertyKey, const V>(key: SchemaTestable<K>, value: SchemaTestable<V>, options?: TypedOmit<ObjectSchemaOptions<Record<K, V>>, 'unknownProperties' | 'unknownPropertiesKey'>): ObjectSchema<Partial<Record<K, V>>>;
76
77
  export declare function assign<const T1 extends Record, const T2 extends Record>(a: ObjectSchemaOrType<T1>, b: ObjectSchemaOrType<T2>): ObjectSchema<Merge<T1, T2>>;
77
78
  export declare function assign<const T1 extends Record, const T2 extends Record, const T3 extends Record>(a: ObjectSchemaOrType<T1>, b: ObjectSchemaOrType<T2>, c: ObjectSchemaOrType<T3>): ObjectSchema<Merge<Merge<T1, T2>, T3>>;
78
79
  export declare function assign<const T1 extends Record, const T2 extends Record, const T3 extends Record, const T4 extends Record>(a: ObjectSchemaOrType<T1>, b: ObjectSchemaOrType<T2>, c: ObjectSchemaOrType<T3>, d: ObjectSchemaOrType<T4>): ObjectSchema<Merge<Merge<Merge<T1, T2>, T3>, T4>>;
@@ -3,8 +3,8 @@ import { createDecorator, reflectionRegistry } from '../../reflection/index.js';
3
3
  import { SchemaError } from '../../schema/schema.error.js';
4
4
  import { toArray } from '../../utils/array/array.js';
5
5
  import { memoizeSingle } from '../../utils/function/memoize.js';
6
- import { filterObject, mapObjectValues, objectKeys } from '../../utils/object/object.js';
7
- import { assert, isDefined, isFunction, isLiteralObject, isNotNull, isNotNullOrUndefined, isNull, isObject, isUndefined } from '../../utils/type-guards.js';
6
+ import { filterObject, fromEntries, mapObjectValues, objectKeys } from '../../utils/object/object.js';
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, Property } from '../decorators/index.js';
10
10
  import { Schema } from '../schema.js';
@@ -78,8 +78,13 @@ export function object(properties, options) {
78
78
  export function explicitObject(properties, options) {
79
79
  return object(properties, options);
80
80
  }
81
- export function record(key, value, options) {
82
- return object({}, { ...options, unknownPropertiesKey: key, unknownProperties: value });
81
+ export function record(keysOrKeySchema, value, options) {
82
+ if (isArray(keysOrKeySchema)) {
83
+ const entries = keysOrKeySchema.map((key) => [key, value]);
84
+ const properties = fromEntries(entries);
85
+ return new ObjectSchema(properties, options);
86
+ }
87
+ return new ObjectSchema({}, { ...options, unknownPropertiesKey: keysOrKeySchema, unknownProperties: value });
83
88
  }
84
89
  export function assign(...schemasOrTypes) {
85
90
  const schemas = schemasOrTypes.map(getObjectSchema);