@augment-vir/common 27.0.0 → 28.0.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/cjs/augments/json.js +1 -11
- package/dist/cjs/augments/object/merge-property-arrays.js +15 -0
- package/dist/cjs/index.js +1 -1
- package/dist/esm/augments/json.js +1 -11
- package/dist/esm/augments/object/merge-property-arrays.js +11 -0
- package/dist/esm/index.js +1 -1
- package/dist/types/augments/json.d.ts +1 -2
- package/dist/types/augments/object/merge-property-arrays.d.ts +1 -0
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cjs/augments/object/matches-object-shape.js +0 -116
- package/dist/esm/augments/object/matches-object-shape.js +0 -111
- package/dist/types/augments/object/matches-object-shape.d.ts +0 -36
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stringifyJson = exports.parseJson = void 0;
|
|
4
|
-
const run_time_assertions_1 = require("run-time-assertions");
|
|
5
|
-
const matches_object_shape_1 = require("./object/matches-object-shape");
|
|
6
4
|
const wrap_in_try_1 = require("./wrap-in-try");
|
|
7
|
-
function parseJson({ jsonString, errorHandler,
|
|
5
|
+
function parseJson({ jsonString, errorHandler, }) {
|
|
8
6
|
try {
|
|
9
7
|
const parsedJson = JSON.parse(jsonString);
|
|
10
|
-
if (shapeMatcher != undefined) {
|
|
11
|
-
if ((0, run_time_assertions_1.isRunTimeType)(shapeMatcher, 'object')) {
|
|
12
|
-
(0, matches_object_shape_1.assertMatchesObjectShape)(parsedJson, shapeMatcher);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
(0, run_time_assertions_1.assertRunTimeType)(parsedJson, (0, run_time_assertions_1.getRunTimeType)(shapeMatcher), 'parsedJson');
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
8
|
return parsedJson;
|
|
19
9
|
}
|
|
20
10
|
catch (error) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mergePropertyArrays = void 0;
|
|
4
|
+
const get_or_set_1 = require("./get-or-set");
|
|
5
|
+
function mergePropertyArrays(...inputs) {
|
|
6
|
+
const combined = {};
|
|
7
|
+
inputs.forEach((input) => {
|
|
8
|
+
Object.entries(input).forEach(([key, newArray,]) => {
|
|
9
|
+
const currentArray = (0, get_or_set_1.getOrSet)(combined, key, () => []);
|
|
10
|
+
currentArray.push(...newArray);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
return combined;
|
|
14
|
+
}
|
|
15
|
+
exports.mergePropertyArrays = mergePropertyArrays;
|
package/dist/cjs/index.js
CHANGED
|
@@ -35,8 +35,8 @@ __exportStar(require("./augments/object/get-or-set"), exports);
|
|
|
35
35
|
__exportStar(require("./augments/object/has-key"), exports);
|
|
36
36
|
__exportStar(require("./augments/object/jsonify"), exports);
|
|
37
37
|
__exportStar(require("./augments/object/map-object"), exports);
|
|
38
|
-
__exportStar(require("./augments/object/matches-object-shape"), exports);
|
|
39
38
|
__exportStar(require("./augments/object/merge-deep"), exports);
|
|
39
|
+
__exportStar(require("./augments/object/merge-property-arrays"), exports);
|
|
40
40
|
__exportStar(require("./augments/object/nested-keys"), exports);
|
|
41
41
|
__exportStar(require("./augments/object/object"), exports);
|
|
42
42
|
__exportStar(require("./augments/object/object-entries"), exports);
|
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import { assertRunTimeType, getRunTimeType, isRunTimeType } from 'run-time-assertions';
|
|
2
|
-
import { assertMatchesObjectShape } from './object/matches-object-shape';
|
|
3
1
|
import { wrapInTry } from './wrap-in-try';
|
|
4
|
-
export function parseJson({ jsonString, errorHandler,
|
|
2
|
+
export function parseJson({ jsonString, errorHandler, }) {
|
|
5
3
|
try {
|
|
6
4
|
const parsedJson = JSON.parse(jsonString);
|
|
7
|
-
if (shapeMatcher != undefined) {
|
|
8
|
-
if (isRunTimeType(shapeMatcher, 'object')) {
|
|
9
|
-
assertMatchesObjectShape(parsedJson, shapeMatcher);
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
assertRunTimeType(parsedJson, getRunTimeType(shapeMatcher), 'parsedJson');
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
5
|
return parsedJson;
|
|
16
6
|
}
|
|
17
7
|
catch (error) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getOrSet } from './get-or-set';
|
|
2
|
+
export function mergePropertyArrays(...inputs) {
|
|
3
|
+
const combined = {};
|
|
4
|
+
inputs.forEach((input) => {
|
|
5
|
+
Object.entries(input).forEach(([key, newArray,]) => {
|
|
6
|
+
const currentArray = getOrSet(combined, key, () => []);
|
|
7
|
+
currentArray.push(...newArray);
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
return combined;
|
|
11
|
+
}
|
package/dist/esm/index.js
CHANGED
|
@@ -19,8 +19,8 @@ export * from './augments/object/get-or-set';
|
|
|
19
19
|
export * from './augments/object/has-key';
|
|
20
20
|
export * from './augments/object/jsonify';
|
|
21
21
|
export * from './augments/object/map-object';
|
|
22
|
-
export * from './augments/object/matches-object-shape';
|
|
23
22
|
export * from './augments/object/merge-deep';
|
|
23
|
+
export * from './augments/object/merge-property-arrays';
|
|
24
24
|
export * from './augments/object/nested-keys';
|
|
25
25
|
export * from './augments/object/object';
|
|
26
26
|
export * from './augments/object/object-entries';
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { JsonCompatibleValue } from './json-compatible';
|
|
2
2
|
import { WrapInTryOptions } from './wrap-in-try';
|
|
3
|
-
export declare function parseJson<ParsedJsonGeneric>({ jsonString, errorHandler,
|
|
3
|
+
export declare function parseJson<ParsedJsonGeneric>({ jsonString, errorHandler, }: {
|
|
4
4
|
jsonString: string;
|
|
5
5
|
errorHandler?: (error: unknown) => never | ParsedJsonGeneric;
|
|
6
|
-
shapeMatcher?: ParsedJsonGeneric;
|
|
7
6
|
}): ParsedJsonGeneric;
|
|
8
7
|
export declare function stringifyJson(jsonValue: JsonCompatibleValue, { whitespace, ...tryOptions }?: {
|
|
9
8
|
whitespace?: number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function mergePropertyArrays<T extends Record<PropertyKey, unknown[]>>(...inputs: ReadonlyArray<Readonly<T>>): T;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -19,8 +19,8 @@ export * from './augments/object/get-or-set';
|
|
|
19
19
|
export * from './augments/object/has-key';
|
|
20
20
|
export * from './augments/object/jsonify';
|
|
21
21
|
export * from './augments/object/map-object';
|
|
22
|
-
export * from './augments/object/matches-object-shape';
|
|
23
22
|
export * from './augments/object/merge-deep';
|
|
23
|
+
export * from './augments/object/merge-property-arrays';
|
|
24
24
|
export * from './augments/object/nested-keys';
|
|
25
25
|
export * from './augments/object/object';
|
|
26
26
|
export * from './augments/object/object-entries';
|
package/package.json
CHANGED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertMatchesObjectShape = exports.matchesObjectShape = void 0;
|
|
4
|
-
const boolean_1 = require("../boolean");
|
|
5
|
-
const error_1 = require("../error");
|
|
6
|
-
const object_1 = require("./object");
|
|
7
|
-
const object_entries_1 = require("./object-entries");
|
|
8
|
-
const typed_has_property_1 = require("./typed-has-property");
|
|
9
|
-
/**
|
|
10
|
-
* Checks that the first input, testThisOne, matches the object shape of the second input,
|
|
11
|
-
* compareToThisOne. Does not compare exact values of properties, only types.
|
|
12
|
-
*
|
|
13
|
-
* To allow the test input, the first input, to have additional keys that the compare input, the
|
|
14
|
-
* second input, does not have, pass in a third argument set to true.
|
|
15
|
-
*
|
|
16
|
-
* This function REQUIRES a generic to be assigned to it: it cannot infer it from the inputs.
|
|
17
|
-
*
|
|
18
|
-
* The compare input, the second input, is required to have at least one entry in every array value
|
|
19
|
-
* that exists. If more array values are present, they will be considered other possible types for
|
|
20
|
-
* entries in that array.
|
|
21
|
-
*/
|
|
22
|
-
function matchesObjectShape(testThisOne, compareToThisOne, allowExtraProps = false, shouldLogWhy = false) {
|
|
23
|
-
try {
|
|
24
|
-
assertMatchesObjectShape(testThisOne, compareToThisOne, allowExtraProps);
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
if (shouldLogWhy) {
|
|
29
|
-
console.error(error);
|
|
30
|
-
}
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.matchesObjectShape = matchesObjectShape;
|
|
35
|
-
/**
|
|
36
|
-
* Asserts that the first input, testThisOne, matches the object shape of the second input,
|
|
37
|
-
* compareToThisOne. Does not compare exact values of properties, only types.
|
|
38
|
-
*
|
|
39
|
-
* To allow the test input, the first input, to have additional keys that the compare input, the
|
|
40
|
-
* second input, does not have, pass in a third argument set to true.
|
|
41
|
-
*
|
|
42
|
-
* This function REQUIRES a generic to be assigned to it: it cannot infer it from the inputs.
|
|
43
|
-
*
|
|
44
|
-
* The compare input, the second input, is required to have at least one entry in every array value
|
|
45
|
-
* that exists. If more array values are present, they will be considered other possible types for
|
|
46
|
-
* entries in that array.
|
|
47
|
-
*/
|
|
48
|
-
function assertMatchesObjectShape(testThisOne, compareToThisOne, allowExtraProps = false, noCheckInnerValueOfTheseKeys = {}) {
|
|
49
|
-
const testKeys = (0, object_entries_1.getObjectTypedKeys)(testThisOne);
|
|
50
|
-
const matchKeys = new Set((0, object_entries_1.getObjectTypedKeys)(compareToThisOne));
|
|
51
|
-
if (!allowExtraProps) {
|
|
52
|
-
const extraKeys = testKeys.filter((testKey) => !matchKeys.has(testKey));
|
|
53
|
-
if (extraKeys.length) {
|
|
54
|
-
throw new Error(`Test object has extra keys: ${extraKeys.join(', ')}`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
matchKeys.forEach((key) => {
|
|
58
|
-
if (!(0, typed_has_property_1.typedHasProperty)(testThisOne, key)) {
|
|
59
|
-
throw new Error(`test object does not have key "${String(key)}" from expected shape.`);
|
|
60
|
-
}
|
|
61
|
-
function throwKeyError(reason) {
|
|
62
|
-
throw new Error(`test object value at key "${String(key)}" did not match expected shape: ${reason}`);
|
|
63
|
-
}
|
|
64
|
-
const testValue = testThisOne[key];
|
|
65
|
-
const shouldMatch = compareToThisOne[key];
|
|
66
|
-
if (!noCheckInnerValueOfTheseKeys[key]) {
|
|
67
|
-
compareInnerValue(testValue, shouldMatch, throwKeyError, allowExtraProps, noCheckInnerValueOfTheseKeys[key] ?? {});
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
exports.assertMatchesObjectShape = assertMatchesObjectShape;
|
|
72
|
-
function compareInnerValue(testValue, matchValue, throwKeyError, allowExtraProps, noCheckInnerValueOfTheseKeys) {
|
|
73
|
-
const testType = typeof testValue;
|
|
74
|
-
const shouldMatchType = typeof matchValue;
|
|
75
|
-
if (testType !== shouldMatchType) {
|
|
76
|
-
throwKeyError(`type "${testType}" did not match expected type "${shouldMatchType}"`);
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
if ((0, typed_has_property_1.typedHasProperty)(matchValue, 'constructor')) {
|
|
80
|
-
if (!(0, typed_has_property_1.typedHasProperty)(testValue, 'constructor') ||
|
|
81
|
-
testValue.constructor !== matchValue.constructor) {
|
|
82
|
-
throwKeyError(`constructor "${testValue?.constructor?.name}" did not match expected constructor "${matchValue.constructor}"`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
// ignore errors from trying to find the constructor
|
|
88
|
-
if (error instanceof throwKeyError) {
|
|
89
|
-
throw error;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (Array.isArray(matchValue)) {
|
|
93
|
-
if (!Array.isArray(testValue)) {
|
|
94
|
-
throwKeyError(`expected an array`);
|
|
95
|
-
}
|
|
96
|
-
testValue.forEach((testValueEntry, index) => {
|
|
97
|
-
const errors = matchValue
|
|
98
|
-
.map((matchValue) => {
|
|
99
|
-
try {
|
|
100
|
-
compareInnerValue(testValueEntry, matchValue, throwKeyError, allowExtraProps, noCheckInnerValueOfTheseKeys);
|
|
101
|
-
return undefined;
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
return new Error(`entry at index "${index}" did not match expected shape: ${(0, error_1.extractErrorMessage)(error)}`);
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
.filter(boolean_1.isTruthy);
|
|
108
|
-
if (errors.length === matchValue.length) {
|
|
109
|
-
throw new Error(`entry at index "${index}" did not match any of the possible types from "${matchValue.join(', ')}"`);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
else if ((0, object_1.isObject)(matchValue)) {
|
|
114
|
-
assertMatchesObjectShape(testValue, matchValue, allowExtraProps, noCheckInnerValueOfTheseKeys);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { isTruthy } from '../boolean';
|
|
2
|
-
import { extractErrorMessage } from '../error';
|
|
3
|
-
import { isObject } from './object';
|
|
4
|
-
import { getObjectTypedKeys } from './object-entries';
|
|
5
|
-
import { typedHasProperty } from './typed-has-property';
|
|
6
|
-
/**
|
|
7
|
-
* Checks that the first input, testThisOne, matches the object shape of the second input,
|
|
8
|
-
* compareToThisOne. Does not compare exact values of properties, only types.
|
|
9
|
-
*
|
|
10
|
-
* To allow the test input, the first input, to have additional keys that the compare input, the
|
|
11
|
-
* second input, does not have, pass in a third argument set to true.
|
|
12
|
-
*
|
|
13
|
-
* This function REQUIRES a generic to be assigned to it: it cannot infer it from the inputs.
|
|
14
|
-
*
|
|
15
|
-
* The compare input, the second input, is required to have at least one entry in every array value
|
|
16
|
-
* that exists. If more array values are present, they will be considered other possible types for
|
|
17
|
-
* entries in that array.
|
|
18
|
-
*/
|
|
19
|
-
export function matchesObjectShape(testThisOne, compareToThisOne, allowExtraProps = false, shouldLogWhy = false) {
|
|
20
|
-
try {
|
|
21
|
-
assertMatchesObjectShape(testThisOne, compareToThisOne, allowExtraProps);
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
if (shouldLogWhy) {
|
|
26
|
-
console.error(error);
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Asserts that the first input, testThisOne, matches the object shape of the second input,
|
|
33
|
-
* compareToThisOne. Does not compare exact values of properties, only types.
|
|
34
|
-
*
|
|
35
|
-
* To allow the test input, the first input, to have additional keys that the compare input, the
|
|
36
|
-
* second input, does not have, pass in a third argument set to true.
|
|
37
|
-
*
|
|
38
|
-
* This function REQUIRES a generic to be assigned to it: it cannot infer it from the inputs.
|
|
39
|
-
*
|
|
40
|
-
* The compare input, the second input, is required to have at least one entry in every array value
|
|
41
|
-
* that exists. If more array values are present, they will be considered other possible types for
|
|
42
|
-
* entries in that array.
|
|
43
|
-
*/
|
|
44
|
-
export function assertMatchesObjectShape(testThisOne, compareToThisOne, allowExtraProps = false, noCheckInnerValueOfTheseKeys = {}) {
|
|
45
|
-
const testKeys = getObjectTypedKeys(testThisOne);
|
|
46
|
-
const matchKeys = new Set(getObjectTypedKeys(compareToThisOne));
|
|
47
|
-
if (!allowExtraProps) {
|
|
48
|
-
const extraKeys = testKeys.filter((testKey) => !matchKeys.has(testKey));
|
|
49
|
-
if (extraKeys.length) {
|
|
50
|
-
throw new Error(`Test object has extra keys: ${extraKeys.join(', ')}`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
matchKeys.forEach((key) => {
|
|
54
|
-
if (!typedHasProperty(testThisOne, key)) {
|
|
55
|
-
throw new Error(`test object does not have key "${String(key)}" from expected shape.`);
|
|
56
|
-
}
|
|
57
|
-
function throwKeyError(reason) {
|
|
58
|
-
throw new Error(`test object value at key "${String(key)}" did not match expected shape: ${reason}`);
|
|
59
|
-
}
|
|
60
|
-
const testValue = testThisOne[key];
|
|
61
|
-
const shouldMatch = compareToThisOne[key];
|
|
62
|
-
if (!noCheckInnerValueOfTheseKeys[key]) {
|
|
63
|
-
compareInnerValue(testValue, shouldMatch, throwKeyError, allowExtraProps, noCheckInnerValueOfTheseKeys[key] ?? {});
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
function compareInnerValue(testValue, matchValue, throwKeyError, allowExtraProps, noCheckInnerValueOfTheseKeys) {
|
|
68
|
-
const testType = typeof testValue;
|
|
69
|
-
const shouldMatchType = typeof matchValue;
|
|
70
|
-
if (testType !== shouldMatchType) {
|
|
71
|
-
throwKeyError(`type "${testType}" did not match expected type "${shouldMatchType}"`);
|
|
72
|
-
}
|
|
73
|
-
try {
|
|
74
|
-
if (typedHasProperty(matchValue, 'constructor')) {
|
|
75
|
-
if (!typedHasProperty(testValue, 'constructor') ||
|
|
76
|
-
testValue.constructor !== matchValue.constructor) {
|
|
77
|
-
throwKeyError(`constructor "${testValue?.constructor?.name}" did not match expected constructor "${matchValue.constructor}"`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
// ignore errors from trying to find the constructor
|
|
83
|
-
if (error instanceof throwKeyError) {
|
|
84
|
-
throw error;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (Array.isArray(matchValue)) {
|
|
88
|
-
if (!Array.isArray(testValue)) {
|
|
89
|
-
throwKeyError(`expected an array`);
|
|
90
|
-
}
|
|
91
|
-
testValue.forEach((testValueEntry, index) => {
|
|
92
|
-
const errors = matchValue
|
|
93
|
-
.map((matchValue) => {
|
|
94
|
-
try {
|
|
95
|
-
compareInnerValue(testValueEntry, matchValue, throwKeyError, allowExtraProps, noCheckInnerValueOfTheseKeys);
|
|
96
|
-
return undefined;
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
return new Error(`entry at index "${index}" did not match expected shape: ${extractErrorMessage(error)}`);
|
|
100
|
-
}
|
|
101
|
-
})
|
|
102
|
-
.filter(isTruthy);
|
|
103
|
-
if (errors.length === matchValue.length) {
|
|
104
|
-
throw new Error(`entry at index "${index}" did not match any of the possible types from "${matchValue.join(', ')}"`);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
else if (isObject(matchValue)) {
|
|
109
|
-
assertMatchesObjectShape(testValue, matchValue, allowExtraProps, noCheckInnerValueOfTheseKeys);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { AtLeastOneEntryArray } from '../array/array';
|
|
2
|
-
import { NoInfer } from '../type';
|
|
3
|
-
/**
|
|
4
|
-
* Checks that the first input, testThisOne, matches the object shape of the second input,
|
|
5
|
-
* compareToThisOne. Does not compare exact values of properties, only types.
|
|
6
|
-
*
|
|
7
|
-
* To allow the test input, the first input, to have additional keys that the compare input, the
|
|
8
|
-
* second input, does not have, pass in a third argument set to true.
|
|
9
|
-
*
|
|
10
|
-
* This function REQUIRES a generic to be assigned to it: it cannot infer it from the inputs.
|
|
11
|
-
*
|
|
12
|
-
* The compare input, the second input, is required to have at least one entry in every array value
|
|
13
|
-
* that exists. If more array values are present, they will be considered other possible types for
|
|
14
|
-
* entries in that array.
|
|
15
|
-
*/
|
|
16
|
-
export declare function matchesObjectShape<MatchThisGeneric extends object>(testThisOne: unknown, compareToThisOne: NoInfer<ObjectWithAtLeastSingleEntryArrays<MatchThisGeneric>>, allowExtraProps?: boolean, shouldLogWhy?: boolean): testThisOne is MatchThisGeneric;
|
|
17
|
-
export type ObjectWithAtLeastSingleEntryArrays<BaseObject extends object> = {
|
|
18
|
-
[Prop in keyof BaseObject]: BaseObject[Prop] extends ReadonlyArray<any> ? AtLeastOneEntryArray<BaseObject[Prop]> : BaseObject[Prop] extends object ? ObjectWithAtLeastSingleEntryArrays<BaseObject[Prop]> : BaseObject[Prop];
|
|
19
|
-
};
|
|
20
|
-
export type NestedBoolean<MatchObject extends object> = Partial<{
|
|
21
|
-
[Prop in keyof MatchObject]: MatchObject[Prop] extends object ? NestedBoolean<MatchObject[Prop]> | boolean : boolean;
|
|
22
|
-
}>;
|
|
23
|
-
/**
|
|
24
|
-
* Asserts that the first input, testThisOne, matches the object shape of the second input,
|
|
25
|
-
* compareToThisOne. Does not compare exact values of properties, only types.
|
|
26
|
-
*
|
|
27
|
-
* To allow the test input, the first input, to have additional keys that the compare input, the
|
|
28
|
-
* second input, does not have, pass in a third argument set to true.
|
|
29
|
-
*
|
|
30
|
-
* This function REQUIRES a generic to be assigned to it: it cannot infer it from the inputs.
|
|
31
|
-
*
|
|
32
|
-
* The compare input, the second input, is required to have at least one entry in every array value
|
|
33
|
-
* that exists. If more array values are present, they will be considered other possible types for
|
|
34
|
-
* entries in that array.
|
|
35
|
-
*/
|
|
36
|
-
export declare function assertMatchesObjectShape<MatchThisGeneric extends object = never>(testThisOne: unknown, compareToThisOne: NoInfer<ObjectWithAtLeastSingleEntryArrays<MatchThisGeneric>>, allowExtraProps?: boolean, noCheckInnerValueOfTheseKeys?: NestedBoolean<typeof compareToThisOne>): asserts testThisOne is MatchThisGeneric;
|