@tstdl/base 0.88.0-alpha4 → 0.88.0-alpha6

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.88.0-alpha4",
3
+ "version": "0.88.0-alpha6",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -4,7 +4,7 @@ import { SchemaValueConstraint } from '../types/schema-value-constraint.js';
4
4
  import type { ConstraintContext, ConstraintResult } from '../types/types.js';
5
5
  export declare class MaximumLengthConstraint extends SchemaValueConstraint {
6
6
  private readonly maximumLength;
7
- readonly suitableTypes: (ArrayConstructor | ArrayBufferConstructor | Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor | BigInt64ArrayConstructor | BigUint64ArrayConstructor | StringConstructor)[];
7
+ readonly suitableTypes: (ArrayBufferConstructor | Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor | BigInt64ArrayConstructor | BigUint64ArrayConstructor | ArrayConstructor | StringConstructor)[];
8
8
  readonly expects: string;
9
9
  constructor(maximumLength: number);
10
10
  validate(value: string, path: JsonPath, context: ConstraintContext): ConstraintResult;
@@ -4,7 +4,7 @@ import { SchemaValueConstraint } from '../types/schema-value-constraint.js';
4
4
  import type { ConstraintContext, ConstraintResult } from '../types/types.js';
5
5
  export declare class MinimumLengthConstraint extends SchemaValueConstraint {
6
6
  private readonly minimumLength;
7
- readonly suitableTypes: (ArrayConstructor | ArrayBufferConstructor | Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor | BigInt64ArrayConstructor | BigUint64ArrayConstructor | StringConstructor)[];
7
+ readonly suitableTypes: (ArrayBufferConstructor | Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor | BigInt64ArrayConstructor | BigUint64ArrayConstructor | ArrayConstructor | StringConstructor)[];
8
8
  readonly expects: string;
9
9
  constructor(minimumLength: number);
10
10
  validate(value: string | ArrayLike<any> | ArrayBuffer, path: JsonPath, context: ConstraintContext): ConstraintResult;
@@ -39,12 +39,11 @@ export function isTypeSchema(schema) {
39
39
  return false;
40
40
  }
41
41
  const type = schema.type;
42
- return isObject(schema)
43
- && (isFunction(type)
44
- || (isObject(type) && isFunction(type.deferred))
45
- || (type == 'undefined')
46
- || (type == 'null')
47
- || (type == 'any'));
42
+ return isFunction(type)
43
+ || (isObject(type) && isFunction(type.deferred))
44
+ || (type == 'undefined')
45
+ || (type == 'null')
46
+ || (type == 'any');
48
47
  }
49
48
  export function isDeferredValueType(value) {
50
49
  return isObject(value) && isFunction(value.deferred);
@@ -190,11 +190,11 @@ export function enumerationLocalization(enumeration, nameOrLocalization, localiz
190
190
  return [enumeration, isLocalizeItem(nameOrLocalization) ? nameOrLocalization : undefined, localizationOrNothing ?? nameOrLocalization];
191
191
  }
192
192
  function _autoEnumerationLocalization(enumeration, name) {
193
- if (isObject(enumeration)) {
194
- return [enumeration, name, Object.fromEntries(enumEntries(enumeration).map(([key, value]) => [value, key]))];
193
+ if (isArray(enumeration)) {
194
+ const arrayEntries = enumeration.map((value) => [value, value]);
195
+ return [enumeration, name, Object.fromEntries(arrayEntries)];
195
196
  }
196
- const arrayEntries = enumeration.map((value) => [value, value]);
197
- return [enumeration, name, Object.fromEntries(arrayEntries)];
197
+ return [enumeration, name, Object.fromEntries(enumEntries(enumeration).map(([key, value]) => [value, key]))];
198
198
  }
199
199
  function buildMappedLocalization({ language, keys, enums }) {
200
200
  const enumsEntries = enums.map((entry) => [entry[0], { name: entry[1], values: entry[2] }]);
package/types.d.ts CHANGED
@@ -21,7 +21,7 @@ export type NestedObject<T> = {
21
21
  export type NestedArray<T> = T[];
22
22
  export type FilledArray<T> = [T, ...(T)[]];
23
23
  export type FilledReadonlyArray<T> = readonly [T, ...(T)[]];
24
- export type Primitive = string | number | boolean | bigint | null | undefined | symbol;
24
+ export type Primitive = string | number | boolean | bigint | symbol | null | undefined;
25
25
  export type PrimitiveValue = Primitive | PrimitiveObject | PrimitiveArray;
26
26
  export type PrimitiveObject = {
27
27
  [key: string]: PrimitiveValue;
package/utils/merge.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-unsafe-return */
2
- import { assertArray, assertMap, assertObject, assertSet, isArray, isMap, isObject, isSet, isUndefined } from './type-guards.js';
2
+ import { assertArray, assertLiteralObject, assertMap, assertSet, isArray, isLiteralObject, isMap, isSet, isUndefined } from './type-guards.js';
3
3
  export function merge(a, b) {
4
4
  if (isUndefined(a)) {
5
5
  return b;
@@ -7,8 +7,8 @@ export function merge(a, b) {
7
7
  if (isUndefined(b)) {
8
8
  return a;
9
9
  }
10
- if (isObject(a)) {
11
- assertObject(b, 'Cannot merge object into non-object.');
10
+ if (isLiteralObject(a)) {
11
+ assertLiteralObject(b, 'Cannot merge object into non-object.');
12
12
  return { ...a, ...b };
13
13
  }
14
14
  else if (isArray(a)) {
@@ -1,6 +1,6 @@
1
1
  import { JsonPath } from '../../json-path/json-path.js';
2
2
  import { clone } from '../clone.js';
3
- import { isArray, isDate, isDefined, isFunction, isNotNull, isObject, isPrimitive, isRegExp, isString, isWritableArray } from '../type-guards.js';
3
+ import { isArray, isDate, isDefined, isFunction, isObject, isPrimitive, isRegExp, isString, isWritableArray } from '../type-guards.js';
4
4
  import { getCachedDereference } from './dereference.js';
5
5
  import { hasOwnProperty, mapObjectValues, objectKeys } from './object.js';
6
6
  export function decycle(_value, replacer) {
@@ -47,7 +47,7 @@ export function recycle(_value, _clone = true) {
47
47
  }
48
48
  }
49
49
  }
50
- else if (isObject(node) && isNotNull(node)) {
50
+ else if (isObject(node)) {
51
51
  for (const key of objectKeys(node)) {
52
52
  const ref = getRef(node[key]);
53
53
  if (isDefined(ref)) {
package/utils/repl.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { dynamicImport } from '../import.js';
1
2
  import { objectEntries } from './object/object.js';
2
3
  import { isDefined } from './type-guards.js';
3
4
  /**
@@ -5,7 +6,7 @@ import { isDefined } from './type-guards.js';
5
6
  * @param context context to set the repl context to
6
7
  */
7
8
  export async function repl(options) {
8
- const { start: startRepl } = await import('node:repl');
9
+ const { start: startRepl } = await dynamicImport('node:repl');
9
10
  const replServer = startRepl(options);
10
11
  if (isDefined(options?.context)) {
11
12
  for (const [key, value] of objectEntries(options.context)) {