@naturalcycles/js-lib 15.46.0 → 15.47.0
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/dist/http/fetcher.d.ts +1 -1
- package/dist/http/fetcher.js +1 -1
- package/dist/promise/pProps.js +1 -1
- package/dist/promise/pTimeout.js +1 -1
- package/dist/semver.js +1 -0
- package/dist/web.d.ts +1 -1
- package/dist/web.js +1 -1
- package/package.json +3 -4
- package/readme.md +0 -8
- package/src/http/fetcher.ts +1 -1
- package/src/promise/pProps.ts +1 -1
- package/src/promise/pTimeout.ts +1 -1
- package/src/semver.ts +1 -0
- package/src/types.ts +4 -4
- package/src/web.ts +1 -1
- package/src/zod/zod.shared.schemas.ts +1 -1
- package/dist/json-schema/from-data/generateJsonSchemaFromData.d.ts +0 -8
- package/dist/json-schema/from-data/generateJsonSchemaFromData.js +0 -87
- package/dist/json-schema/index.d.ts +0 -5
- package/dist/json-schema/index.js +0 -5
- package/dist/json-schema/jsonSchema.cnst.d.ts +0 -2
- package/dist/json-schema/jsonSchema.cnst.js +0 -38
- package/dist/json-schema/jsonSchema.model.d.ts +0 -121
- package/dist/json-schema/jsonSchema.model.js +0 -1
- package/dist/json-schema/jsonSchema.util.d.ts +0 -8
- package/dist/json-schema/jsonSchema.util.js +0 -27
- package/dist/json-schema/jsonSchemaBuilder.d.ts +0 -159
- package/dist/json-schema/jsonSchemaBuilder.js +0 -412
- package/dist/json-schema/jsonSchemas.d.ts +0 -2
- package/dist/json-schema/jsonSchemas.js +0 -6
- package/src/json-schema/from-data/generateJsonSchemaFromData.ts +0 -121
- package/src/json-schema/index.ts +0 -5
- package/src/json-schema/jsonSchema.cnst.ts +0 -52
- package/src/json-schema/jsonSchema.model.ts +0 -172
- package/src/json-schema/jsonSchema.util.ts +0 -36
- package/src/json-schema/jsonSchemaBuilder.ts +0 -590
- package/src/json-schema/jsonSchemas.ts +0 -8
package/dist/http/fetcher.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/// <reference lib="
|
|
1
|
+
/// <reference lib="es2023" preserve="true" />
|
|
2
2
|
/// <reference lib="dom" preserve="true" />
|
|
3
3
|
/// <reference lib="dom.iterable" preserve="true" />
|
|
4
4
|
import type { ReadableStream as WebReadableStream } from 'node:stream/web';
|
package/dist/http/fetcher.js
CHANGED
package/dist/promise/pProps.js
CHANGED
|
@@ -15,6 +15,6 @@
|
|
|
15
15
|
export async function pProps(input) {
|
|
16
16
|
const keys = Object.keys(input);
|
|
17
17
|
// `as any` here is added to make it compile when `noUncheckedIndexedAccess` is false
|
|
18
|
-
//
|
|
18
|
+
// oxlint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
19
19
|
return Object.fromEntries((await Promise.all(Object.values(input))).map((v, i) => [keys[i], v]));
|
|
20
20
|
}
|
package/dist/promise/pTimeout.js
CHANGED
|
@@ -44,7 +44,7 @@ export async function pTimeout(fn, opt) {
|
|
|
44
44
|
_typeCast(err);
|
|
45
45
|
// keep original stack
|
|
46
46
|
err.stack = fakeError.stack.replace('Error: TimeoutError', err.name + ': ' + err.message);
|
|
47
|
-
//
|
|
47
|
+
// oxlint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
48
48
|
reject(_errorDataAppend(err, opt.errorData));
|
|
49
49
|
}
|
|
50
50
|
return;
|
package/dist/semver.js
CHANGED
package/dist/web.d.ts
CHANGED
package/dist/web.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/js-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "15.
|
|
4
|
+
"version": "15.47.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"tslib": "^2",
|
|
7
7
|
"undici": "^7",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"@types/semver": "^7",
|
|
14
14
|
"crypto-js": "^4",
|
|
15
15
|
"dayjs": "^1",
|
|
16
|
-
"@naturalcycles/dev-lib": "
|
|
16
|
+
"@naturalcycles/dev-lib": "18.4.2"
|
|
17
17
|
},
|
|
18
18
|
"exports": {
|
|
19
19
|
".": "./dist/index.js",
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"./error": "./dist/error/index.js",
|
|
30
30
|
"./error/*.js": "./dist/error/*.js",
|
|
31
31
|
"./http": "./dist/http/index.js",
|
|
32
|
-
"./json-schema": "./dist/json-schema/index.js",
|
|
33
32
|
"./log": "./dist/log/commonLogger.js",
|
|
34
33
|
"./math": "./dist/math/index.js",
|
|
35
34
|
"./math/*.js": "./dist/math/*.js",
|
|
@@ -55,7 +54,7 @@
|
|
|
55
54
|
"types": "dist/index.d.ts",
|
|
56
55
|
"sideEffects": false,
|
|
57
56
|
"engines": {
|
|
58
|
-
"node": ">=
|
|
57
|
+
"node": ">=24.10.0"
|
|
59
58
|
},
|
|
60
59
|
"publishConfig": {
|
|
61
60
|
"provenance": true,
|
package/readme.md
CHANGED
|
@@ -11,11 +11,3 @@
|
|
|
11
11
|
[](https://github.com/prettier/prettier)
|
|
12
12
|
|
|
13
13
|
# [Documentation](https://naturalcycles.github.io/js-libs/)
|
|
14
|
-
|
|
15
|
-
# Packaging
|
|
16
|
-
|
|
17
|
-
- `engines.node >= Node.js LTS`
|
|
18
|
-
- `main: dist/index.js`: commonjs, es2022 - targeting Node.js
|
|
19
|
-
- `module: dist-esm/index.js`: esm, es2017 - targeting Browsers
|
|
20
|
-
- `types: dist/index.d.ts`: typescript types
|
|
21
|
-
- `/src` folder with source `*.ts` files included
|
package/src/http/fetcher.ts
CHANGED
package/src/promise/pProps.ts
CHANGED
|
@@ -17,7 +17,7 @@ export async function pProps<T>(input: { [K in keyof T]: T[K] | Promise<T[K]> })
|
|
|
17
17
|
}> {
|
|
18
18
|
const keys = Object.keys(input)
|
|
19
19
|
// `as any` here is added to make it compile when `noUncheckedIndexedAccess` is false
|
|
20
|
-
//
|
|
20
|
+
// oxlint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
21
21
|
return Object.fromEntries(
|
|
22
22
|
(await Promise.all(Object.values(input))).map((v, i) => [keys[i], v]),
|
|
23
23
|
) as any
|
package/src/promise/pTimeout.ts
CHANGED
|
@@ -88,7 +88,7 @@ export async function pTimeout<T>(fn: AnyAsyncFunction<T>, opt: PTimeoutOptions)
|
|
|
88
88
|
_typeCast<Error>(err)
|
|
89
89
|
// keep original stack
|
|
90
90
|
err.stack = fakeError.stack!.replace('Error: TimeoutError', err.name + ': ' + err.message)
|
|
91
|
-
//
|
|
91
|
+
// oxlint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
92
92
|
reject(_errorDataAppend(err, opt.errorData))
|
|
93
93
|
}
|
|
94
94
|
return
|
package/src/semver.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -34,7 +34,7 @@ export type AnyEnum = NumberEnum
|
|
|
34
34
|
export type NumberEnum = Record<string, number | string>
|
|
35
35
|
export type StringEnum = Record<string, string>
|
|
36
36
|
|
|
37
|
-
//
|
|
37
|
+
// oxlint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
38
38
|
export type CreatedUpdated = {
|
|
39
39
|
created: UnixTimestamp
|
|
40
40
|
updated: UnixTimestamp
|
|
@@ -44,12 +44,12 @@ export interface CreatedUpdatedId extends CreatedUpdated {
|
|
|
44
44
|
id: string
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
//
|
|
47
|
+
// oxlint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
48
48
|
export type ObjectWithId = {
|
|
49
49
|
id: string
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
//
|
|
52
|
+
// oxlint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
53
53
|
export type PartialObjectWithId = {
|
|
54
54
|
id?: string
|
|
55
55
|
}
|
|
@@ -61,7 +61,7 @@ export interface AnyObjectWithId extends AnyObject, ObjectWithId {}
|
|
|
61
61
|
/**
|
|
62
62
|
* Base interface for any Entity that was saved to DB.
|
|
63
63
|
*/
|
|
64
|
-
//
|
|
64
|
+
// oxlint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
65
65
|
export type BaseDBEntity = {
|
|
66
66
|
id: string
|
|
67
67
|
|
package/src/web.ts
CHANGED
|
@@ -108,7 +108,7 @@ const baseDBEntitySchema = z.object({
|
|
|
108
108
|
updated: unixTimestamp2000(),
|
|
109
109
|
})
|
|
110
110
|
|
|
111
|
-
//
|
|
111
|
+
// oxlint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
112
112
|
type BaseDBEntityZodShape = {
|
|
113
113
|
id: ZodString
|
|
114
114
|
created: ZodBrandedInt<UnixTimestamp>
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type AnyObject } from '../../types.js';
|
|
2
|
-
import type { JsonSchemaObject } from '../index.js';
|
|
3
|
-
/**
|
|
4
|
-
* Each row must be an object (current limitation).
|
|
5
|
-
*
|
|
6
|
-
* `additionalProperties` is set to `true`, cause it's safer.
|
|
7
|
-
*/
|
|
8
|
-
export declare function generateJsonSchemaFromData<T extends AnyObject = AnyObject>(rows: AnyObject[]): JsonSchemaObject<T>;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { _uniq } from '../../array/index.js';
|
|
2
|
-
import { _stringMapEntries } from '../../types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Each row must be an object (current limitation).
|
|
5
|
-
*
|
|
6
|
-
* `additionalProperties` is set to `true`, cause it's safer.
|
|
7
|
-
*/
|
|
8
|
-
export function generateJsonSchemaFromData(rows) {
|
|
9
|
-
return objectToJsonSchema(rows);
|
|
10
|
-
}
|
|
11
|
-
function objectToJsonSchema(rows) {
|
|
12
|
-
const typesByKey = {};
|
|
13
|
-
rows.forEach(r => {
|
|
14
|
-
Object.keys(r).forEach(key => {
|
|
15
|
-
typesByKey[key] ||= new Set();
|
|
16
|
-
typesByKey[key].add(getTypeOfValue(r[key]));
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
const s = {
|
|
20
|
-
type: 'object',
|
|
21
|
-
properties: {},
|
|
22
|
-
required: [],
|
|
23
|
-
additionalProperties: true,
|
|
24
|
-
};
|
|
25
|
-
_stringMapEntries(typesByKey).forEach(([key, types]) => {
|
|
26
|
-
const schema = mergeTypes([...types], rows.map(r => r[key]));
|
|
27
|
-
if (!schema)
|
|
28
|
-
return;
|
|
29
|
-
s.properties[key] = schema;
|
|
30
|
-
});
|
|
31
|
-
// console.log(typesByKey)
|
|
32
|
-
return s;
|
|
33
|
-
}
|
|
34
|
-
function mergeTypes(types, samples) {
|
|
35
|
-
// skip "undefined" types
|
|
36
|
-
types = types.filter(t => t !== 'undefined');
|
|
37
|
-
if (!types.length)
|
|
38
|
-
return undefined;
|
|
39
|
-
if (types.length > 1) {
|
|
40
|
-
// oneOf
|
|
41
|
-
const s = {
|
|
42
|
-
oneOf: types.map(type => mergeTypes([type], samples)),
|
|
43
|
-
};
|
|
44
|
-
return s;
|
|
45
|
-
}
|
|
46
|
-
const type = types[0];
|
|
47
|
-
if (type === 'null') {
|
|
48
|
-
return {
|
|
49
|
-
type: 'null',
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
if (type === 'boolean') {
|
|
53
|
-
return {
|
|
54
|
-
type: 'boolean',
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
if (type === 'string') {
|
|
58
|
-
return {
|
|
59
|
-
type: 'string',
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
if (type === 'number') {
|
|
63
|
-
return {
|
|
64
|
-
type: 'number',
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
if (type === 'object') {
|
|
68
|
-
return objectToJsonSchema(samples.filter((r) => r && typeof r === 'object'));
|
|
69
|
-
}
|
|
70
|
-
if (type === 'array') {
|
|
71
|
-
// possible feature: detect if it's a tuple
|
|
72
|
-
// currently assume no-tuple
|
|
73
|
-
const items = samples.filter(r => Array.isArray(r)).flat();
|
|
74
|
-
const itemTypes = _uniq(items.map(i => getTypeOfValue(i)));
|
|
75
|
-
return {
|
|
76
|
-
type: 'array',
|
|
77
|
-
items: mergeTypes(itemTypes, items),
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function getTypeOfValue(v) {
|
|
82
|
-
if (v === null)
|
|
83
|
-
return 'null';
|
|
84
|
-
if (Array.isArray(v))
|
|
85
|
-
return 'array';
|
|
86
|
-
return typeof v;
|
|
87
|
-
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import type { JsonSchema, JsonSchemaAny, JsonSchemaNumber, JsonSchemaObject, JsonSchemaString } from './jsonSchema.model.js';
|
|
2
|
-
export declare const JSON_SCHEMA_ORDER: (keyof JsonSchema | keyof JsonSchemaAny | keyof JsonSchemaObject | keyof JsonSchemaString | keyof JsonSchemaNumber)[];
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export const JSON_SCHEMA_ORDER = [
|
|
2
|
-
'$schema',
|
|
3
|
-
'$id',
|
|
4
|
-
'title',
|
|
5
|
-
'description',
|
|
6
|
-
'deprecated',
|
|
7
|
-
'readOnly',
|
|
8
|
-
'writeOnly',
|
|
9
|
-
'type',
|
|
10
|
-
'default',
|
|
11
|
-
// Object,
|
|
12
|
-
'properties',
|
|
13
|
-
'required',
|
|
14
|
-
'minProperties',
|
|
15
|
-
'maxProperties',
|
|
16
|
-
'patternProperties',
|
|
17
|
-
'propertyNames',
|
|
18
|
-
// Array
|
|
19
|
-
'properties',
|
|
20
|
-
'required',
|
|
21
|
-
'minProperties',
|
|
22
|
-
'maxProperties',
|
|
23
|
-
'patternProperties',
|
|
24
|
-
'propertyNames',
|
|
25
|
-
// String
|
|
26
|
-
'pattern',
|
|
27
|
-
'minLength',
|
|
28
|
-
'maxLength',
|
|
29
|
-
'format',
|
|
30
|
-
'transform',
|
|
31
|
-
// Number
|
|
32
|
-
'format',
|
|
33
|
-
'multipleOf',
|
|
34
|
-
'minimum',
|
|
35
|
-
'exclusiveMinimum',
|
|
36
|
-
'maximum',
|
|
37
|
-
'exclusiveMaximum',
|
|
38
|
-
];
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import type { AnyObject, StringMap } from '../types.js';
|
|
2
|
-
export type JsonSchema<T = unknown> = JsonSchemaAny<T> | JsonSchemaOneOf<T> | JsonSchemaAllOf<T> | JsonSchemaAnyOf<T> | JsonSchemaNot<T> | JsonSchemaRef<T> | JsonSchemaConst<T> | JsonSchemaEnum<T> | JsonSchemaString | JsonSchemaNumber | JsonSchemaBoolean | JsonSchemaNull | JsonSchemaObject<T extends AnyObject ? T : AnyObject> | JsonSchemaArray<T> | JsonSchemaTuple<T>;
|
|
3
|
-
export interface JsonSchemaAny<T = unknown> {
|
|
4
|
-
$schema?: string;
|
|
5
|
-
$id?: string;
|
|
6
|
-
title?: string;
|
|
7
|
-
description?: string;
|
|
8
|
-
deprecated?: boolean;
|
|
9
|
-
readOnly?: boolean;
|
|
10
|
-
writeOnly?: boolean;
|
|
11
|
-
type?: string | string[];
|
|
12
|
-
default?: T;
|
|
13
|
-
if?: JsonSchema;
|
|
14
|
-
then?: JsonSchema;
|
|
15
|
-
else?: JsonSchema;
|
|
16
|
-
/**
|
|
17
|
-
* https://ajv.js.org/packages/ajv-keywords.html#instanceof
|
|
18
|
-
*
|
|
19
|
-
* Useful for Node.js Buffer, you can use it like:
|
|
20
|
-
* `instanceof: 'Buffer'`
|
|
21
|
-
*/
|
|
22
|
-
instanceof?: string | string[];
|
|
23
|
-
/**
|
|
24
|
-
* This is a temporary "intermediate AST" field that is used inside the parser.
|
|
25
|
-
* In the final schema this field will NOT be present.
|
|
26
|
-
*/
|
|
27
|
-
optionalField?: true;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Union type
|
|
31
|
-
*/
|
|
32
|
-
export interface JsonSchemaOneOf<T = unknown> extends JsonSchemaAny<T> {
|
|
33
|
-
oneOf: JsonSchema[];
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Intersection type
|
|
37
|
-
*/
|
|
38
|
-
export interface JsonSchemaAllOf<T = unknown> extends JsonSchemaAny<T> {
|
|
39
|
-
allOf: JsonSchema[];
|
|
40
|
-
}
|
|
41
|
-
export interface JsonSchemaAnyOf<T = unknown> extends JsonSchemaAny<T> {
|
|
42
|
-
anyOf: JsonSchema[];
|
|
43
|
-
}
|
|
44
|
-
export interface JsonSchemaNot<T = unknown> extends JsonSchemaAny<T> {
|
|
45
|
-
not: JsonSchema;
|
|
46
|
-
}
|
|
47
|
-
export interface JsonSchemaConst<T = unknown> extends JsonSchemaAny<T> {
|
|
48
|
-
const: T;
|
|
49
|
-
}
|
|
50
|
-
export interface JsonSchemaString<T extends string = string> extends JsonSchemaAny<T> {
|
|
51
|
-
type: 'string';
|
|
52
|
-
pattern?: string;
|
|
53
|
-
minLength?: number;
|
|
54
|
-
maxLength?: number;
|
|
55
|
-
format?: string;
|
|
56
|
-
contentMediaType?: string;
|
|
57
|
-
contentEncoding?: string;
|
|
58
|
-
/**
|
|
59
|
-
* https://ajv.js.org/packages/ajv-keywords.html#transform
|
|
60
|
-
*/
|
|
61
|
-
transform?: ('trim' | 'toLowerCase' | 'toUpperCase')[];
|
|
62
|
-
}
|
|
63
|
-
export interface JsonSchemaNumber<T extends number = number> extends JsonSchemaAny<T> {
|
|
64
|
-
type: 'number' | 'integer';
|
|
65
|
-
format?: string;
|
|
66
|
-
multipleOf?: number;
|
|
67
|
-
minimum?: number;
|
|
68
|
-
exclusiveMinimum?: number;
|
|
69
|
-
maximum?: number;
|
|
70
|
-
exclusiveMaximum?: number;
|
|
71
|
-
}
|
|
72
|
-
export interface JsonSchemaBoolean extends JsonSchemaAny<boolean> {
|
|
73
|
-
type: 'boolean';
|
|
74
|
-
}
|
|
75
|
-
export interface JsonSchemaNull extends JsonSchemaAny<null> {
|
|
76
|
-
type: 'null';
|
|
77
|
-
}
|
|
78
|
-
export interface JsonSchemaEnum<T = unknown> extends JsonSchemaAny<T> {
|
|
79
|
-
enum: T[];
|
|
80
|
-
}
|
|
81
|
-
export interface JsonSchemaRef<T = unknown> extends JsonSchemaAny<T> {
|
|
82
|
-
$ref: string;
|
|
83
|
-
}
|
|
84
|
-
export interface JsonSchemaRootObject<T extends AnyObject = AnyObject> extends JsonSchemaObject<T> {
|
|
85
|
-
$id: string;
|
|
86
|
-
}
|
|
87
|
-
export interface JsonSchemaObject<T extends AnyObject = AnyObject> extends JsonSchemaAny<T> {
|
|
88
|
-
type: 'object';
|
|
89
|
-
properties: {
|
|
90
|
-
[k in keyof T]: JsonSchema;
|
|
91
|
-
};
|
|
92
|
-
required: (keyof T)[];
|
|
93
|
-
additionalProperties: boolean;
|
|
94
|
-
minProperties?: number;
|
|
95
|
-
maxProperties?: number;
|
|
96
|
-
patternProperties?: StringMap<JsonSchema>;
|
|
97
|
-
propertyNames?: JsonSchema;
|
|
98
|
-
/**
|
|
99
|
-
* @example
|
|
100
|
-
*
|
|
101
|
-
* dependentRequired: {
|
|
102
|
-
* credit_card: ['billing_address']
|
|
103
|
-
* }
|
|
104
|
-
*/
|
|
105
|
-
dependentRequired?: StringMap<string[]>;
|
|
106
|
-
dependentSchemas?: StringMap<JsonSchema>;
|
|
107
|
-
dependencies?: StringMap<string[]>;
|
|
108
|
-
}
|
|
109
|
-
export interface JsonSchemaArray<ITEM = unknown> extends JsonSchemaAny<ITEM[]> {
|
|
110
|
-
type: 'array';
|
|
111
|
-
items: JsonSchema<ITEM>;
|
|
112
|
-
minItems?: number;
|
|
113
|
-
maxItems?: number;
|
|
114
|
-
uniqueItems?: boolean;
|
|
115
|
-
}
|
|
116
|
-
export interface JsonSchemaTuple<T = unknown> extends JsonSchemaAny<T> {
|
|
117
|
-
type: 'array';
|
|
118
|
-
items: JsonSchema[];
|
|
119
|
-
minItems: number;
|
|
120
|
-
maxItems: number;
|
|
121
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { AnyObject } from '../types.js';
|
|
2
|
-
import type { JsonSchemaObject } from './jsonSchema.model.js';
|
|
3
|
-
/**
|
|
4
|
-
* Merges s2 into s1 (mutates s1) and returns s1.
|
|
5
|
-
* Does not mutate s2.
|
|
6
|
-
* API similar to Object.assign(s1, s2)
|
|
7
|
-
*/
|
|
8
|
-
export declare function mergeJsonSchemaObjects<T1 extends AnyObject, T2 extends AnyObject>(s1: JsonSchemaObject<T1>, s2: JsonSchemaObject<T2>): JsonSchemaObject<T1 & T2>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { _uniq } from '../array/array.util.js';
|
|
2
|
-
import { _filterNullishValues } from '../object/object.util.js';
|
|
3
|
-
/**
|
|
4
|
-
* Merges s2 into s1 (mutates s1) and returns s1.
|
|
5
|
-
* Does not mutate s2.
|
|
6
|
-
* API similar to Object.assign(s1, s2)
|
|
7
|
-
*/
|
|
8
|
-
export function mergeJsonSchemaObjects(s1, s2) {
|
|
9
|
-
// Merge `properties`
|
|
10
|
-
Object.entries(s2.properties).forEach(([k, v]) => {
|
|
11
|
-
;
|
|
12
|
-
s1.properties[k] = v;
|
|
13
|
-
});
|
|
14
|
-
// Merge `patternProperties`
|
|
15
|
-
Object.entries(s2.patternProperties || {}).forEach(([k, v]) => {
|
|
16
|
-
;
|
|
17
|
-
s1.patternProperties[k] = v;
|
|
18
|
-
});
|
|
19
|
-
s1.propertyNames = s2.propertyNames || s1.propertyNames;
|
|
20
|
-
s1.minProperties = s2.minProperties ?? s1.minProperties;
|
|
21
|
-
s1.maxProperties = s2.maxProperties ?? s1.maxProperties;
|
|
22
|
-
// Merge `required`
|
|
23
|
-
s1.required.push(...s2.required);
|
|
24
|
-
s1.required = _uniq(s1.required).sort();
|
|
25
|
-
// `additionalProperties` remains the same
|
|
26
|
-
return _filterNullishValues(s1, { mutate: true });
|
|
27
|
-
}
|