@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 +1 -1
- package/schema/constraints/maximum-length.d.ts +1 -1
- package/schema/constraints/minimum-length.d.ts +1 -1
- package/schema/types/types.js +5 -6
- package/text/localization.service.js +4 -4
- package/types.d.ts +1 -1
- package/utils/merge.js +3 -3
- package/utils/object/decycle.js +2 -2
- package/utils/repl.js +2 -1
- package/utils/type-guards.d.ts +263 -243
- package/utils/type-guards.js +319 -243
- package/utils/url-builder.js +5 -3
package/package.json
CHANGED
|
@@ -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: (
|
|
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: (
|
|
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;
|
package/schema/types/types.js
CHANGED
|
@@ -39,12 +39,11 @@ export function isTypeSchema(schema) {
|
|
|
39
39
|
return false;
|
|
40
40
|
}
|
|
41
41
|
const type = schema.type;
|
|
42
|
-
return
|
|
43
|
-
&&
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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 (
|
|
194
|
-
|
|
193
|
+
if (isArray(enumeration)) {
|
|
194
|
+
const arrayEntries = enumeration.map((value) => [value, value]);
|
|
195
|
+
return [enumeration, name, Object.fromEntries(arrayEntries)];
|
|
195
196
|
}
|
|
196
|
-
|
|
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 |
|
|
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,
|
|
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 (
|
|
11
|
-
|
|
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)) {
|
package/utils/object/decycle.js
CHANGED
|
@@ -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,
|
|
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)
|
|
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
|
|
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)) {
|