@augment-vir/common 6.1.1 → 6.1.3
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.
|
@@ -45,6 +45,9 @@ export declare function matchesObjectShape<MatchThisGeneric extends object>(test
|
|
|
45
45
|
export type ObjectWithAtLeastSingleEntryArrays<BaseObject extends object> = {
|
|
46
46
|
[Prop in keyof BaseObject]: BaseObject[Prop] extends ReadonlyArray<any> ? AtLeastOneEntryArray<BaseObject[Prop]> : BaseObject[Prop] extends object ? ObjectWithAtLeastSingleEntryArrays<BaseObject[Prop]> : BaseObject[Prop];
|
|
47
47
|
};
|
|
48
|
+
type NestedBoolean<MatchObject extends object> = Partial<{
|
|
49
|
+
[Prop in keyof MatchObject]: MatchObject[Prop] extends object ? NestedBoolean<MatchObject[Prop]> | boolean : boolean;
|
|
50
|
+
}>;
|
|
48
51
|
/**
|
|
49
52
|
* Asserts that the first input, testThisOne, matches the object shape of the second input,
|
|
50
53
|
* compareToThisOne. Does not compare exact values of properties, only types.
|
|
@@ -58,7 +61,7 @@ export type ObjectWithAtLeastSingleEntryArrays<BaseObject extends object> = {
|
|
|
58
61
|
* that exists. If more array values are present, they will be considered other possible types for
|
|
59
62
|
* entries in that array.
|
|
60
63
|
*/
|
|
61
|
-
export declare function assertMatchesObjectShape<MatchThisGeneric extends object = never>(testThisOne: unknown, compareToThisOne: NoInfer<ObjectWithAtLeastSingleEntryArrays<MatchThisGeneric>>, allowExtraProps?: boolean): asserts testThisOne is MatchThisGeneric;
|
|
64
|
+
export declare function assertMatchesObjectShape<MatchThisGeneric extends object = never>(testThisOne: unknown, compareToThisOne: NoInfer<ObjectWithAtLeastSingleEntryArrays<MatchThisGeneric>>, allowExtraProps?: boolean, noCheckInnerValueOfTheseKeys?: NestedBoolean<typeof compareToThisOne>): asserts testThisOne is MatchThisGeneric;
|
|
62
65
|
export declare function typedObjectFromEntries<KeyType extends PropertyKey, ValueType>(entries: ReadonlyArray<Readonly<[KeyType, ValueType]>>): Record<KeyType, ValueType>;
|
|
63
66
|
export {};
|
|
64
67
|
//# sourceMappingURL=object.d.ts.map
|
|
@@ -199,7 +199,7 @@ exports.matchesObjectShape = matchesObjectShape;
|
|
|
199
199
|
* that exists. If more array values are present, they will be considered other possible types for
|
|
200
200
|
* entries in that array.
|
|
201
201
|
*/
|
|
202
|
-
function assertMatchesObjectShape(testThisOne, compareToThisOne, allowExtraProps = false) {
|
|
202
|
+
function assertMatchesObjectShape(testThisOne, compareToThisOne, allowExtraProps = false, noCheckInnerValueOfTheseKeys = {}) {
|
|
203
203
|
const testKeys = getObjectTypedKeys(testThisOne);
|
|
204
204
|
const matchKeys = new Set(getObjectTypedKeys(compareToThisOne));
|
|
205
205
|
if (!allowExtraProps) {
|
|
@@ -209,6 +209,7 @@ function assertMatchesObjectShape(testThisOne, compareToThisOne, allowExtraProps
|
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
matchKeys.forEach((key) => {
|
|
212
|
+
var _a;
|
|
212
213
|
if (!typedHasProperty(testThisOne, key)) {
|
|
213
214
|
throw new Error(`test object does not have key "${String(key)}" from expected shape.`);
|
|
214
215
|
}
|
|
@@ -217,11 +218,13 @@ function assertMatchesObjectShape(testThisOne, compareToThisOne, allowExtraProps
|
|
|
217
218
|
}
|
|
218
219
|
const testValue = testThisOne[key];
|
|
219
220
|
const shouldMatch = compareToThisOne[key];
|
|
220
|
-
|
|
221
|
+
if (!noCheckInnerValueOfTheseKeys[key]) {
|
|
222
|
+
compareInnerValue(testValue, shouldMatch, throwKeyError, allowExtraProps, (_a = noCheckInnerValueOfTheseKeys[key]) !== null && _a !== void 0 ? _a : {});
|
|
223
|
+
}
|
|
221
224
|
});
|
|
222
225
|
}
|
|
223
226
|
exports.assertMatchesObjectShape = assertMatchesObjectShape;
|
|
224
|
-
function compareInnerValue(testValue, matchValue, throwKeyError) {
|
|
227
|
+
function compareInnerValue(testValue, matchValue, throwKeyError, allowExtraProps, noCheckInnerValueOfTheseKeys) {
|
|
225
228
|
var _a;
|
|
226
229
|
const testType = typeof testValue;
|
|
227
230
|
const shouldMatchType = typeof matchValue;
|
|
@@ -250,7 +253,7 @@ function compareInnerValue(testValue, matchValue, throwKeyError) {
|
|
|
250
253
|
const errors = matchValue
|
|
251
254
|
.map((matchValue) => {
|
|
252
255
|
try {
|
|
253
|
-
compareInnerValue(testValueEntry, matchValue, throwKeyError);
|
|
256
|
+
compareInnerValue(testValueEntry, matchValue, throwKeyError, allowExtraProps, noCheckInnerValueOfTheseKeys);
|
|
254
257
|
return undefined;
|
|
255
258
|
}
|
|
256
259
|
catch (error) {
|
|
@@ -264,7 +267,7 @@ function compareInnerValue(testValue, matchValue, throwKeyError) {
|
|
|
264
267
|
});
|
|
265
268
|
}
|
|
266
269
|
else if (isObject(matchValue)) {
|
|
267
|
-
assertMatchesObjectShape(testValue, matchValue);
|
|
270
|
+
assertMatchesObjectShape(testValue, matchValue, allowExtraProps, noCheckInnerValueOfTheseKeys);
|
|
268
271
|
}
|
|
269
272
|
}
|
|
270
273
|
function typedObjectFromEntries(entries) {
|
|
@@ -45,6 +45,9 @@ export declare function matchesObjectShape<MatchThisGeneric extends object>(test
|
|
|
45
45
|
export type ObjectWithAtLeastSingleEntryArrays<BaseObject extends object> = {
|
|
46
46
|
[Prop in keyof BaseObject]: BaseObject[Prop] extends ReadonlyArray<any> ? AtLeastOneEntryArray<BaseObject[Prop]> : BaseObject[Prop] extends object ? ObjectWithAtLeastSingleEntryArrays<BaseObject[Prop]> : BaseObject[Prop];
|
|
47
47
|
};
|
|
48
|
+
type NestedBoolean<MatchObject extends object> = Partial<{
|
|
49
|
+
[Prop in keyof MatchObject]: MatchObject[Prop] extends object ? NestedBoolean<MatchObject[Prop]> | boolean : boolean;
|
|
50
|
+
}>;
|
|
48
51
|
/**
|
|
49
52
|
* Asserts that the first input, testThisOne, matches the object shape of the second input,
|
|
50
53
|
* compareToThisOne. Does not compare exact values of properties, only types.
|
|
@@ -58,7 +61,7 @@ export type ObjectWithAtLeastSingleEntryArrays<BaseObject extends object> = {
|
|
|
58
61
|
* that exists. If more array values are present, they will be considered other possible types for
|
|
59
62
|
* entries in that array.
|
|
60
63
|
*/
|
|
61
|
-
export declare function assertMatchesObjectShape<MatchThisGeneric extends object = never>(testThisOne: unknown, compareToThisOne: NoInfer<ObjectWithAtLeastSingleEntryArrays<MatchThisGeneric>>, allowExtraProps?: boolean): asserts testThisOne is MatchThisGeneric;
|
|
64
|
+
export declare function assertMatchesObjectShape<MatchThisGeneric extends object = never>(testThisOne: unknown, compareToThisOne: NoInfer<ObjectWithAtLeastSingleEntryArrays<MatchThisGeneric>>, allowExtraProps?: boolean, noCheckInnerValueOfTheseKeys?: NestedBoolean<typeof compareToThisOne>): asserts testThisOne is MatchThisGeneric;
|
|
62
65
|
export declare function typedObjectFromEntries<KeyType extends PropertyKey, ValueType>(entries: ReadonlyArray<Readonly<[KeyType, ValueType]>>): Record<KeyType, ValueType>;
|
|
63
66
|
export {};
|
|
64
67
|
//# sourceMappingURL=object.d.ts.map
|
|
@@ -180,7 +180,7 @@ export function matchesObjectShape(testThisOne, compareToThisOne, allowExtraProp
|
|
|
180
180
|
* that exists. If more array values are present, they will be considered other possible types for
|
|
181
181
|
* entries in that array.
|
|
182
182
|
*/
|
|
183
|
-
export function assertMatchesObjectShape(testThisOne, compareToThisOne, allowExtraProps = false) {
|
|
183
|
+
export function assertMatchesObjectShape(testThisOne, compareToThisOne, allowExtraProps = false, noCheckInnerValueOfTheseKeys = {}) {
|
|
184
184
|
const testKeys = getObjectTypedKeys(testThisOne);
|
|
185
185
|
const matchKeys = new Set(getObjectTypedKeys(compareToThisOne));
|
|
186
186
|
if (!allowExtraProps) {
|
|
@@ -190,6 +190,7 @@ export function assertMatchesObjectShape(testThisOne, compareToThisOne, allowExt
|
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
matchKeys.forEach((key) => {
|
|
193
|
+
var _a;
|
|
193
194
|
if (!typedHasProperty(testThisOne, key)) {
|
|
194
195
|
throw new Error(`test object does not have key "${String(key)}" from expected shape.`);
|
|
195
196
|
}
|
|
@@ -198,10 +199,12 @@ export function assertMatchesObjectShape(testThisOne, compareToThisOne, allowExt
|
|
|
198
199
|
}
|
|
199
200
|
const testValue = testThisOne[key];
|
|
200
201
|
const shouldMatch = compareToThisOne[key];
|
|
201
|
-
|
|
202
|
+
if (!noCheckInnerValueOfTheseKeys[key]) {
|
|
203
|
+
compareInnerValue(testValue, shouldMatch, throwKeyError, allowExtraProps, (_a = noCheckInnerValueOfTheseKeys[key]) !== null && _a !== void 0 ? _a : {});
|
|
204
|
+
}
|
|
202
205
|
});
|
|
203
206
|
}
|
|
204
|
-
function compareInnerValue(testValue, matchValue, throwKeyError) {
|
|
207
|
+
function compareInnerValue(testValue, matchValue, throwKeyError, allowExtraProps, noCheckInnerValueOfTheseKeys) {
|
|
205
208
|
var _a;
|
|
206
209
|
const testType = typeof testValue;
|
|
207
210
|
const shouldMatchType = typeof matchValue;
|
|
@@ -230,7 +233,7 @@ function compareInnerValue(testValue, matchValue, throwKeyError) {
|
|
|
230
233
|
const errors = matchValue
|
|
231
234
|
.map((matchValue) => {
|
|
232
235
|
try {
|
|
233
|
-
compareInnerValue(testValueEntry, matchValue, throwKeyError);
|
|
236
|
+
compareInnerValue(testValueEntry, matchValue, throwKeyError, allowExtraProps, noCheckInnerValueOfTheseKeys);
|
|
234
237
|
return undefined;
|
|
235
238
|
}
|
|
236
239
|
catch (error) {
|
|
@@ -244,7 +247,7 @@ function compareInnerValue(testValue, matchValue, throwKeyError) {
|
|
|
244
247
|
});
|
|
245
248
|
}
|
|
246
249
|
else if (isObject(matchValue)) {
|
|
247
|
-
assertMatchesObjectShape(testValue, matchValue);
|
|
250
|
+
assertMatchesObjectShape(testValue, matchValue, allowExtraProps, noCheckInnerValueOfTheseKeys);
|
|
248
251
|
}
|
|
249
252
|
}
|
|
250
253
|
export function typedObjectFromEntries(entries) {
|
|
@@ -45,6 +45,9 @@ export declare function matchesObjectShape<MatchThisGeneric extends object>(test
|
|
|
45
45
|
export type ObjectWithAtLeastSingleEntryArrays<BaseObject extends object> = {
|
|
46
46
|
[Prop in keyof BaseObject]: BaseObject[Prop] extends ReadonlyArray<any> ? AtLeastOneEntryArray<BaseObject[Prop]> : BaseObject[Prop] extends object ? ObjectWithAtLeastSingleEntryArrays<BaseObject[Prop]> : BaseObject[Prop];
|
|
47
47
|
};
|
|
48
|
+
type NestedBoolean<MatchObject extends object> = Partial<{
|
|
49
|
+
[Prop in keyof MatchObject]: MatchObject[Prop] extends object ? NestedBoolean<MatchObject[Prop]> | boolean : boolean;
|
|
50
|
+
}>;
|
|
48
51
|
/**
|
|
49
52
|
* Asserts that the first input, testThisOne, matches the object shape of the second input,
|
|
50
53
|
* compareToThisOne. Does not compare exact values of properties, only types.
|
|
@@ -58,7 +61,7 @@ export type ObjectWithAtLeastSingleEntryArrays<BaseObject extends object> = {
|
|
|
58
61
|
* that exists. If more array values are present, they will be considered other possible types for
|
|
59
62
|
* entries in that array.
|
|
60
63
|
*/
|
|
61
|
-
export declare function assertMatchesObjectShape<MatchThisGeneric extends object = never>(testThisOne: unknown, compareToThisOne: NoInfer<ObjectWithAtLeastSingleEntryArrays<MatchThisGeneric>>, allowExtraProps?: boolean): asserts testThisOne is MatchThisGeneric;
|
|
64
|
+
export declare function assertMatchesObjectShape<MatchThisGeneric extends object = never>(testThisOne: unknown, compareToThisOne: NoInfer<ObjectWithAtLeastSingleEntryArrays<MatchThisGeneric>>, allowExtraProps?: boolean, noCheckInnerValueOfTheseKeys?: NestedBoolean<typeof compareToThisOne>): asserts testThisOne is MatchThisGeneric;
|
|
62
65
|
export declare function typedObjectFromEntries<KeyType extends PropertyKey, ValueType>(entries: ReadonlyArray<Readonly<[KeyType, ValueType]>>): Record<KeyType, ValueType>;
|
|
63
66
|
export {};
|
|
64
67
|
//# sourceMappingURL=object.d.ts.map
|