@augment-vir/common 11.0.0 → 11.1.1

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.
@@ -13,6 +13,7 @@ export type DeferredPromiseWrapper<T> = {
13
13
  promise: Promise<T>;
14
14
  resolve: (value: T | PromiseLike<T>) => void;
15
15
  reject: (reason?: any) => void;
16
+ isSettled: () => boolean;
16
17
  };
17
18
  export declare function createDeferredPromiseWrapper<T = void>(): DeferredPromiseWrapper<T>;
18
19
  export type WaitForConditionInputs = {
@@ -58,9 +58,16 @@ exports.wrapPromiseInTimeout = wrapPromiseInTimeout;
58
58
  function createDeferredPromiseWrapper() {
59
59
  let resolve;
60
60
  let reject;
61
+ let settled = false;
61
62
  const promise = new Promise((resolveCallback, rejectCallback) => {
62
- resolve = resolveCallback;
63
- reject = rejectCallback;
63
+ resolve = (value) => {
64
+ settled = true;
65
+ return resolveCallback(value);
66
+ };
67
+ reject = (reason) => {
68
+ settled = true;
69
+ rejectCallback(reason);
70
+ };
64
71
  });
65
72
  // no way to test this edge case
66
73
  // istanbul ignore next
@@ -71,6 +78,9 @@ function createDeferredPromiseWrapper() {
71
78
  promise,
72
79
  resolve,
73
80
  reject,
81
+ isSettled() {
82
+ return settled;
83
+ },
74
84
  };
75
85
  }
76
86
  exports.createDeferredPromiseWrapper = createDeferredPromiseWrapper;
@@ -13,6 +13,7 @@ export type DeferredPromiseWrapper<T> = {
13
13
  promise: Promise<T>;
14
14
  resolve: (value: T | PromiseLike<T>) => void;
15
15
  reject: (reason?: any) => void;
16
+ isSettled: () => boolean;
16
17
  };
17
18
  export declare function createDeferredPromiseWrapper<T = void>(): DeferredPromiseWrapper<T>;
18
19
  export type WaitForConditionInputs = {
@@ -50,9 +50,16 @@ export function wrapPromiseInTimeout(durationMs, originalPromise) {
50
50
  export function createDeferredPromiseWrapper() {
51
51
  let resolve;
52
52
  let reject;
53
+ let settled = false;
53
54
  const promise = new Promise((resolveCallback, rejectCallback) => {
54
- resolve = resolveCallback;
55
- reject = rejectCallback;
55
+ resolve = (value) => {
56
+ settled = true;
57
+ return resolveCallback(value);
58
+ };
59
+ reject = (reason) => {
60
+ settled = true;
61
+ rejectCallback(reason);
62
+ };
56
63
  });
57
64
  // no way to test this edge case
58
65
  // istanbul ignore next
@@ -63,6 +70,9 @@ export function createDeferredPromiseWrapper() {
63
70
  promise,
64
71
  resolve,
65
72
  reject,
73
+ isSettled() {
74
+ return settled;
75
+ },
66
76
  };
67
77
  }
68
78
  export async function waitForCondition({ conditionCallback, timeoutMs = 10000, intervalMs = 100, timeoutMessage = '', }) {
@@ -13,6 +13,7 @@ export type DeferredPromiseWrapper<T> = {
13
13
  promise: Promise<T>;
14
14
  resolve: (value: T | PromiseLike<T>) => void;
15
15
  reject: (reason?: any) => void;
16
+ isSettled: () => boolean;
16
17
  };
17
18
  export declare function createDeferredPromiseWrapper<T = void>(): DeferredPromiseWrapper<T>;
18
19
  export type WaitForConditionInputs = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "11.0.0",
3
+ "version": "11.1.1",
4
4
  "homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
5
5
  "bugs": {
6
6
  "url": "https://github.com/electrovir/augment-vir/issues"
@@ -1,12 +0,0 @@
1
- import { UnionToIntersection } from 'type-fest';
2
- import { ObjectValueType } from '../object';
3
- export type NestedSequentialKeys<ObjectGeneric extends object> = ObjectValueType<{
4
- [Prop in keyof ObjectGeneric]: NonNullable<ObjectGeneric[Prop]> extends object ? [Prop, ...(NestedSequentialKeys<NonNullable<ObjectGeneric[Prop]>> | [])] : [Prop];
5
- }>;
6
- export type NestedKeys<ObjectGeneric extends object> = UnionToIntersection<Extract<ObjectValueType<ObjectGeneric>, object>> extends object ? [
7
- keyof ObjectGeneric,
8
- ...(NestedKeys<UnionToIntersection<Extract<ObjectValueType<ObjectGeneric>, object>>> | [])
9
- ] : [keyof ObjectGeneric];
10
- export type NestedValue<ObjectGeneric extends object, NestedKeysGeneric extends NestedSequentialKeys<ObjectGeneric>> = NestedKeysGeneric extends readonly [infer FirstEntry, ...infer FollowingEntries] ? FirstEntry extends keyof ObjectGeneric ? FollowingEntries extends never[] ? ObjectGeneric[FirstEntry] : ObjectGeneric[FirstEntry] extends object ? FollowingEntries extends NestedSequentialKeys<ObjectGeneric[FirstEntry]> ? NestedValue<ObjectGeneric[FirstEntry], FollowingEntries> : never : never : never : never;
11
- export declare function getValueFromNestedKeys<ObjectGeneric extends object, KeysGeneric extends NestedSequentialKeys<ObjectGeneric>>(inputObject: ObjectGeneric, nestedKeys: KeysGeneric): NestedValue<ObjectGeneric, KeysGeneric> | undefined;
12
- //# sourceMappingURL=nested-keys.d.ts.map
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getValueFromNestedKeys = void 0;
4
- const object_1 = require("./object");
5
- function getValueFromNestedKeys(inputObject, nestedKeys) {
6
- /**
7
- * Lots of as any casts in here because these types are, under the hood, pretty complex. Since
8
- * the inputs and outputs of this function are well typed, these internal as any casts do not
9
- * affect the external API of this function.
10
- */
11
- const keyToAccess = nestedKeys[0];
12
- if (!(0, object_1.typedHasProperty)(inputObject, keyToAccess)) {
13
- return undefined;
14
- }
15
- const currentValue = inputObject[keyToAccess];
16
- if (nestedKeys.length > 1) {
17
- return getValueFromNestedKeys(currentValue, nestedKeys.slice(1));
18
- }
19
- else {
20
- return currentValue;
21
- }
22
- }
23
- exports.getValueFromNestedKeys = getValueFromNestedKeys;
@@ -1,70 +0,0 @@
1
- import { AtLeastOneEntryArray } from './array';
2
- import { NoInfer, RequiredBy, UnPromise } from './type';
3
- export declare function getEnumTypedKeys<T extends object>(input: T): (keyof T)[];
4
- export declare function getEnumTypedValues<T extends object>(input: T): T[keyof T][];
5
- export declare function isEnumValue<T extends object>(input: unknown, checkEnum: T): input is T[keyof T];
6
- export type PartialWithNullable<T extends object> = {
7
- [Prop in keyof T]?: T[Prop] | null | undefined;
8
- };
9
- export declare function isKeyof<ObjectGeneric>(key: PropertyKey, object: ObjectGeneric): key is keyof object;
10
- export declare function filterToEnumValues<T extends object>(inputs: ReadonlyArray<unknown>, checkEnum: T, caseInsensitive?: boolean): T[keyof T][];
11
- export declare function getObjectTypedKeys<ObjectGeneric extends unknown>(input: ObjectGeneric): Array<keyof ObjectGeneric>;
12
- export declare function getObjectTypedValues<ObjectGeneric extends unknown>(input: ObjectGeneric): ObjectGeneric[keyof ObjectGeneric][];
13
- type ExtractValue<KeyGeneric extends PropertyKey, ParentGeneric> = KeyGeneric extends keyof ParentGeneric ? RequiredBy<ParentGeneric, KeyGeneric>[KeyGeneric] : KeyGeneric extends keyof Extract<ParentGeneric, Record<KeyGeneric, any>> ? RequiredBy<Extract<ParentGeneric, Record<KeyGeneric, any>>, KeyGeneric>[KeyGeneric] : never;
14
- type CombinedParentValue<KeyGeneric extends PropertyKey, ParentGeneric> = ExtractValue<KeyGeneric, ParentGeneric> extends never ? unknown : ExtractValue<KeyGeneric, ParentGeneric>;
15
- type CombineTypeWithKey<KeyGeneric extends PropertyKey, ParentGeneric> = ParentGeneric & Record<KeyGeneric, CombinedParentValue<KeyGeneric, ParentGeneric>>;
16
- export declare function typedHasProperty<KeyGeneric extends PropertyKey, ParentGeneric>(inputObject: ParentGeneric, inputKey: KeyGeneric): inputObject is CombineTypeWithKey<KeyGeneric, ParentGeneric>;
17
- export declare function typedHasProperties<KeyGeneric extends PropertyKey, ParentGeneric>(inputObject: ParentGeneric, inputKeys: ReadonlyArray<KeyGeneric>): inputObject is CombineTypeWithKey<KeyGeneric, ParentGeneric>;
18
- export declare function isObject(input: any): input is NonNullable<object>;
19
- export declare function getEntriesSortedByKey(input: object): [string, unknown][];
20
- export declare function areJsonEqual(a: object, b: object): boolean;
21
- export type InnerMappedValues<EntireInputGeneric extends object, MappedValueGeneric> = {
22
- [MappedProp in keyof EntireInputGeneric]: MappedValueGeneric;
23
- };
24
- export type MappedValues<EntireInputGeneric extends object, MappedValueGeneric> = MappedValueGeneric extends PromiseLike<unknown> ? Promise<InnerMappedValues<EntireInputGeneric, UnPromise<MappedValueGeneric>>> : InnerMappedValues<EntireInputGeneric, UnPromise<MappedValueGeneric>>;
25
- /**
26
- * Creates a new object with the same properties as the input object, but with values set to the
27
- * result of mapCallback for each property.
28
- */
29
- export declare function mapObjectValues<EntireInputGeneric extends object, MappedValueGeneric>(inputObject: EntireInputGeneric, mapCallback: (inputKey: keyof EntireInputGeneric, keyValue: EntireInputGeneric[typeof inputKey], fullObject: EntireInputGeneric) => MappedValueGeneric): MappedValues<EntireInputGeneric, MappedValueGeneric>;
30
- export declare function filterObject<ObjectGeneric extends object>(inputObject: ObjectGeneric, callback: (key: keyof ObjectGeneric, value: ObjectValueType<ObjectGeneric>, fullObject: ObjectGeneric) => boolean): Partial<ObjectGeneric>;
31
- /** The input here must be serializable otherwise JSON parsing errors will be thrown */
32
- export declare function copyThroughJson<T>(input: T): T;
33
- export type ObjectValueType<T extends object> = T[keyof T];
34
- /**
35
- * Checks that the first input, testThisOne, matches the object shape of the second input,
36
- * compareToThisOne. Does not compare exact values of properties, only types.
37
- *
38
- * To allow the test input, the first input, to have additional keys that the compare input, the
39
- * second input, does not have, pass in a third argument set to true.
40
- *
41
- * This function REQUIRES a generic to be assigned to it: it cannot infer it from the inputs.
42
- *
43
- * The compare input, the second input, is required to have at least one entry in every array value
44
- * that exists. If more array values are present, they will be considered other possible types for
45
- * entries in that array.
46
- */
47
- export declare function matchesObjectShape<MatchThisGeneric extends object>(testThisOne: unknown, compareToThisOne: NoInfer<ObjectWithAtLeastSingleEntryArrays<MatchThisGeneric>>, allowExtraProps?: boolean, shouldLogWhy?: boolean): testThisOne is MatchThisGeneric;
48
- export type ObjectWithAtLeastSingleEntryArrays<BaseObject extends object> = {
49
- [Prop in keyof BaseObject]: BaseObject[Prop] extends ReadonlyArray<any> ? AtLeastOneEntryArray<BaseObject[Prop]> : BaseObject[Prop] extends object ? ObjectWithAtLeastSingleEntryArrays<BaseObject[Prop]> : BaseObject[Prop];
50
- };
51
- export type NestedBoolean<MatchObject extends object> = Partial<{
52
- [Prop in keyof MatchObject]: MatchObject[Prop] extends object ? NestedBoolean<MatchObject[Prop]> | boolean : boolean;
53
- }>;
54
- /**
55
- * Asserts that the first input, testThisOne, matches the object shape of the second input,
56
- * compareToThisOne. Does not compare exact values of properties, only types.
57
- *
58
- * To allow the test input, the first input, to have additional keys that the compare input, the
59
- * second input, does not have, pass in a third argument set to true.
60
- *
61
- * This function REQUIRES a generic to be assigned to it: it cannot infer it from the inputs.
62
- *
63
- * The compare input, the second input, is required to have at least one entry in every array value
64
- * that exists. If more array values are present, they will be considered other possible types for
65
- * entries in that array.
66
- */
67
- export declare function assertMatchesObjectShape<MatchThisGeneric extends object = never>(testThisOne: unknown, compareToThisOne: NoInfer<ObjectWithAtLeastSingleEntryArrays<MatchThisGeneric>>, allowExtraProps?: boolean, noCheckInnerValueOfTheseKeys?: NestedBoolean<typeof compareToThisOne>): asserts testThisOne is MatchThisGeneric;
68
- export declare function typedObjectFromEntries<KeyType extends PropertyKey, ValueType>(entries: ReadonlyArray<Readonly<[KeyType, ValueType]>>): Record<KeyType, ValueType>;
69
- export {};
70
- //# sourceMappingURL=object.d.ts.map
@@ -1,276 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.typedObjectFromEntries = exports.assertMatchesObjectShape = exports.matchesObjectShape = exports.copyThroughJson = exports.filterObject = exports.mapObjectValues = exports.areJsonEqual = exports.getEntriesSortedByKey = exports.isObject = exports.typedHasProperties = exports.typedHasProperty = exports.getObjectTypedValues = exports.getObjectTypedKeys = exports.filterToEnumValues = exports.isKeyof = exports.isEnumValue = exports.getEnumTypedValues = exports.getEnumTypedKeys = void 0;
4
- const error_1 = require("./error");
5
- const function_1 = require("./function");
6
- function getEnumTypedKeys(input) {
7
- // enum keys are always strings
8
- return getObjectTypedKeys(input).filter((key) => isNaN(Number(key)));
9
- }
10
- exports.getEnumTypedKeys = getEnumTypedKeys;
11
- function getEnumTypedValues(input) {
12
- const keys = getEnumTypedKeys(input);
13
- return keys.map((key) => input[key]);
14
- }
15
- exports.getEnumTypedValues = getEnumTypedValues;
16
- function isEnumValue(input, checkEnum) {
17
- return getEnumTypedValues(checkEnum).includes(input);
18
- }
19
- exports.isEnumValue = isEnumValue;
20
- function isKeyof(key, object) {
21
- return typedHasProperty(object, key);
22
- }
23
- exports.isKeyof = isKeyof;
24
- function filterToEnumValues(inputs, checkEnum, caseInsensitive = false) {
25
- if (caseInsensitive) {
26
- return inputs.reduce((accum, currentInput) => {
27
- const matchedEnumValue = getEnumTypedValues(checkEnum).find((actualEnumValue) => {
28
- return String(actualEnumValue).toUpperCase() === String(currentInput).toUpperCase();
29
- });
30
- if (matchedEnumValue) {
31
- return accum.concat(matchedEnumValue);
32
- }
33
- else {
34
- return accum;
35
- }
36
- }, []);
37
- }
38
- else {
39
- return inputs.filter((input) => isEnumValue(input, checkEnum));
40
- }
41
- }
42
- exports.filterToEnumValues = filterToEnumValues;
43
- function getObjectTypedKeys(input) {
44
- let reflectKeys;
45
- try {
46
- reflectKeys = Reflect.ownKeys(input);
47
- }
48
- catch (error) { }
49
- return (reflectKeys !== null && reflectKeys !== void 0 ? reflectKeys : [
50
- ...Object.keys(input),
51
- ...Object.getOwnPropertySymbols(input),
52
- ]);
53
- }
54
- exports.getObjectTypedKeys = getObjectTypedKeys;
55
- function getObjectTypedValues(input) {
56
- return getObjectTypedKeys(input).map((key) => input[key]);
57
- }
58
- exports.getObjectTypedValues = getObjectTypedValues;
59
- const hasPropertyAttempts = [
60
- (object, key) => {
61
- return key in object;
62
- },
63
- (object, key) => {
64
- /** This handles cases where the input object can't use `in` directly, like string literals */
65
- return key in object.constructor.prototype;
66
- },
67
- ];
68
- function typedHasProperty(inputObject, inputKey) {
69
- if (!inputObject) {
70
- return false;
71
- }
72
- return hasPropertyAttempts.some((attemptCallback) => {
73
- try {
74
- return attemptCallback(inputObject, inputKey);
75
- }
76
- catch (error) {
77
- return false;
78
- }
79
- });
80
- }
81
- exports.typedHasProperty = typedHasProperty;
82
- function typedHasProperties(inputObject, inputKeys) {
83
- return inputObject && inputKeys.every((key) => typedHasProperty(inputObject, key));
84
- }
85
- exports.typedHasProperties = typedHasProperties;
86
- function isObject(input) {
87
- return !!input && typeof input === 'object';
88
- }
89
- exports.isObject = isObject;
90
- function getEntriesSortedByKey(input) {
91
- return Object.entries(input).sort((tupleA, tupleB) => tupleA[0].localeCompare(tupleB[0]));
92
- }
93
- exports.getEntriesSortedByKey = getEntriesSortedByKey;
94
- function areJsonEqual(a, b) {
95
- try {
96
- const sortedAEntries = getEntriesSortedByKey(a);
97
- const sortedBEntries = getEntriesSortedByKey(b);
98
- return JSON.stringify(sortedAEntries) === JSON.stringify(sortedBEntries);
99
- }
100
- catch (error) {
101
- console.error(`Failed to compare objects using JSON.stringify`);
102
- throw error;
103
- }
104
- }
105
- exports.areJsonEqual = areJsonEqual;
106
- /**
107
- * Creates a new object with the same properties as the input object, but with values set to the
108
- * result of mapCallback for each property.
109
- */
110
- function mapObjectValues(inputObject, mapCallback) {
111
- let gotAPromise = false;
112
- const mappedObject = getObjectTypedKeys(inputObject).reduce((accum, currentKey) => {
113
- const mappedValue = mapCallback(currentKey, inputObject[currentKey], inputObject);
114
- if (mappedValue instanceof Promise) {
115
- gotAPromise = true;
116
- }
117
- return {
118
- ...accum,
119
- [currentKey]: mappedValue,
120
- };
121
- }, {});
122
- if (gotAPromise) {
123
- return new Promise(async (resolve, reject) => {
124
- try {
125
- await Promise.all(getObjectTypedKeys(mappedObject).map(async (key) => {
126
- const value = await mappedObject[key];
127
- mappedObject[key] = value;
128
- }));
129
- resolve(mappedObject);
130
- }
131
- catch (error) {
132
- reject(error);
133
- }
134
- });
135
- }
136
- else {
137
- return mappedObject;
138
- }
139
- }
140
- exports.mapObjectValues = mapObjectValues;
141
- function filterObject(inputObject, callback) {
142
- const filteredKeys = getObjectTypedKeys(inputObject).filter((key) => {
143
- const value = inputObject[key];
144
- return callback(key, value, inputObject);
145
- });
146
- return filteredKeys.reduce((accum, key) => {
147
- accum[key] = inputObject[key];
148
- return accum;
149
- }, {});
150
- }
151
- exports.filterObject = filterObject;
152
- /** The input here must be serializable otherwise JSON parsing errors will be thrown */
153
- function copyThroughJson(input) {
154
- try {
155
- return JSON.parse(JSON.stringify(input));
156
- }
157
- catch (error) {
158
- console.error(`Failed to JSON copy for`, input);
159
- throw error;
160
- }
161
- }
162
- exports.copyThroughJson = copyThroughJson;
163
- /**
164
- * Checks that the first input, testThisOne, matches the object shape of the second input,
165
- * compareToThisOne. Does not compare exact values of properties, only types.
166
- *
167
- * To allow the test input, the first input, to have additional keys that the compare input, the
168
- * second input, does not have, pass in a third argument set to true.
169
- *
170
- * This function REQUIRES a generic to be assigned to it: it cannot infer it from the inputs.
171
- *
172
- * The compare input, the second input, is required to have at least one entry in every array value
173
- * that exists. If more array values are present, they will be considered other possible types for
174
- * entries in that array.
175
- */
176
- function matchesObjectShape(testThisOne, compareToThisOne, allowExtraProps = false, shouldLogWhy = false) {
177
- try {
178
- assertMatchesObjectShape(testThisOne, compareToThisOne, allowExtraProps);
179
- return true;
180
- }
181
- catch (error) {
182
- if (shouldLogWhy) {
183
- console.error(error);
184
- }
185
- return false;
186
- }
187
- }
188
- exports.matchesObjectShape = matchesObjectShape;
189
- /**
190
- * Asserts that the first input, testThisOne, matches the object shape of the second input,
191
- * compareToThisOne. Does not compare exact values of properties, only types.
192
- *
193
- * To allow the test input, the first input, to have additional keys that the compare input, the
194
- * second input, does not have, pass in a third argument set to true.
195
- *
196
- * This function REQUIRES a generic to be assigned to it: it cannot infer it from the inputs.
197
- *
198
- * The compare input, the second input, is required to have at least one entry in every array value
199
- * that exists. If more array values are present, they will be considered other possible types for
200
- * entries in that array.
201
- */
202
- function assertMatchesObjectShape(testThisOne, compareToThisOne, allowExtraProps = false, noCheckInnerValueOfTheseKeys = {}) {
203
- const testKeys = getObjectTypedKeys(testThisOne);
204
- const matchKeys = new Set(getObjectTypedKeys(compareToThisOne));
205
- if (!allowExtraProps) {
206
- const extraKeys = testKeys.filter((testKey) => !matchKeys.has(testKey));
207
- if (extraKeys.length) {
208
- throw new Error(`Test object has extra keys: ${extraKeys.join(', ')}`);
209
- }
210
- }
211
- matchKeys.forEach((key) => {
212
- var _a;
213
- if (!typedHasProperty(testThisOne, key)) {
214
- throw new Error(`test object does not have key "${String(key)}" from expected shape.`);
215
- }
216
- function throwKeyError(reason) {
217
- throw new Error(`test object value at key "${String(key)}" did not match expected shape: ${reason}`);
218
- }
219
- const testValue = testThisOne[key];
220
- const shouldMatch = compareToThisOne[key];
221
- if (!noCheckInnerValueOfTheseKeys[key]) {
222
- compareInnerValue(testValue, shouldMatch, throwKeyError, allowExtraProps, (_a = noCheckInnerValueOfTheseKeys[key]) !== null && _a !== void 0 ? _a : {});
223
- }
224
- });
225
- }
226
- exports.assertMatchesObjectShape = assertMatchesObjectShape;
227
- function compareInnerValue(testValue, matchValue, throwKeyError, allowExtraProps, noCheckInnerValueOfTheseKeys) {
228
- var _a;
229
- const testType = typeof testValue;
230
- const shouldMatchType = typeof matchValue;
231
- if (testType !== shouldMatchType) {
232
- throwKeyError(`type "${testType}" did not match expected type "${shouldMatchType}"`);
233
- }
234
- try {
235
- if (typedHasProperty(matchValue, 'constructor')) {
236
- if (!typedHasProperty(testValue, 'constructor') ||
237
- testValue.constructor !== matchValue.constructor) {
238
- throwKeyError(`constructor "${(_a = testValue === null || testValue === void 0 ? void 0 : testValue.constructor) === null || _a === void 0 ? void 0 : _a.name}" did not match expected constructor "${matchValue.constructor}"`);
239
- }
240
- }
241
- }
242
- catch (error) {
243
- // ignore errors from trying to find the constructor
244
- if (error instanceof throwKeyError) {
245
- throw error;
246
- }
247
- }
248
- if (Array.isArray(matchValue)) {
249
- if (!Array.isArray(testValue)) {
250
- throwKeyError(`expected an array`);
251
- }
252
- testValue.forEach((testValueEntry, index) => {
253
- const errors = matchValue
254
- .map((matchValue) => {
255
- try {
256
- compareInnerValue(testValueEntry, matchValue, throwKeyError, allowExtraProps, noCheckInnerValueOfTheseKeys);
257
- return undefined;
258
- }
259
- catch (error) {
260
- return new Error(`entry at index "${index}" did not match expected shape: ${(0, error_1.extractErrorMessage)(error)}`);
261
- }
262
- })
263
- .filter(function_1.isTruthy);
264
- if (errors.length === matchValue.length) {
265
- throw new Error(`entry at index "${index}" did not match any of the possible types from "${matchValue.join(', ')}"`);
266
- }
267
- });
268
- }
269
- else if (isObject(matchValue)) {
270
- assertMatchesObjectShape(testValue, matchValue, allowExtraProps, noCheckInnerValueOfTheseKeys);
271
- }
272
- }
273
- function typedObjectFromEntries(entries) {
274
- return Object.fromEntries(entries);
275
- }
276
- exports.typedObjectFromEntries = typedObjectFromEntries;
@@ -1,8 +0,0 @@
1
- import { UnionToIntersection } from 'type-fest';
2
- import { NestedKeys } from './object/nested-keys';
3
- type InnerPickDeep<OriginalObjectGeneric extends object, DeepKeys extends any[]> = UnionToIntersection<DeepKeys extends [infer CurrentLevelPick, ...infer RemainingKeys] ? {
4
- [CurrentProp in Extract<CurrentLevelPick, keyof OriginalObjectGeneric>]: OriginalObjectGeneric[CurrentProp] extends object ? InnerPickDeep<OriginalObjectGeneric[CurrentProp], RemainingKeys> : OriginalObjectGeneric[CurrentProp];
5
- } : DeepKeys extends [infer CurrentLevelPick] ? CurrentLevelPick extends keyof OriginalObjectGeneric ? Pick<OriginalObjectGeneric, CurrentLevelPick> : never : never>;
6
- export type PickDeep<OriginalObjectGeneric extends object, DeepKeys extends NestedKeys<OriginalObjectGeneric>> = InnerPickDeep<OriginalObjectGeneric, DeepKeys>;
7
- export {};
8
- //# sourceMappingURL=pick-deep.d.ts.map
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,19 +0,0 @@
1
- import { AnyFunction } from './function';
2
- declare function getTypeOf(x: any): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
3
- export type TypeOf = ReturnType<typeof getTypeOf>;
4
- export type TypeOfWithArray = TypeOf | 'array';
5
- export type TypeOfMapping = {
6
- array: any[];
7
- bigint: bigint;
8
- boolean: boolean;
9
- function: AnyFunction;
10
- number: number;
11
- object: Record<PropertyKey, unknown>;
12
- string: string;
13
- symbol: symbol;
14
- undefined: undefined;
15
- };
16
- export declare function typeOfWithArray(input: unknown): TypeOfWithArray;
17
- export declare function isTypeOfWithArray<T extends TypeOfWithArray>(input: unknown, testType: T): input is TypeOfMapping[T];
18
- export {};
19
- //# sourceMappingURL=type-of.d.ts.map
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isTypeOfWithArray = exports.typeOfWithArray = void 0;
4
- // this function is not used at run time, it's only here for types
5
- // istanbul ignore next
6
- function getTypeOf(x) {
7
- return typeof x;
8
- }
9
- function typeOfWithArray(input) {
10
- return Array.isArray(input) ? 'array' : typeof input;
11
- }
12
- exports.typeOfWithArray = typeOfWithArray;
13
- function isTypeOfWithArray(input, testType) {
14
- const inputType = typeOfWithArray(input);
15
- return inputType === testType;
16
- }
17
- exports.isTypeOfWithArray = isTypeOfWithArray;
@@ -1,12 +0,0 @@
1
- import { UnionToIntersection } from 'type-fest';
2
- import { ObjectValueType } from '../object';
3
- export type NestedSequentialKeys<ObjectGeneric extends object> = ObjectValueType<{
4
- [Prop in keyof ObjectGeneric]: NonNullable<ObjectGeneric[Prop]> extends object ? [Prop, ...(NestedSequentialKeys<NonNullable<ObjectGeneric[Prop]>> | [])] : [Prop];
5
- }>;
6
- export type NestedKeys<ObjectGeneric extends object> = UnionToIntersection<Extract<ObjectValueType<ObjectGeneric>, object>> extends object ? [
7
- keyof ObjectGeneric,
8
- ...(NestedKeys<UnionToIntersection<Extract<ObjectValueType<ObjectGeneric>, object>>> | [])
9
- ] : [keyof ObjectGeneric];
10
- export type NestedValue<ObjectGeneric extends object, NestedKeysGeneric extends NestedSequentialKeys<ObjectGeneric>> = NestedKeysGeneric extends readonly [infer FirstEntry, ...infer FollowingEntries] ? FirstEntry extends keyof ObjectGeneric ? FollowingEntries extends never[] ? ObjectGeneric[FirstEntry] : ObjectGeneric[FirstEntry] extends object ? FollowingEntries extends NestedSequentialKeys<ObjectGeneric[FirstEntry]> ? NestedValue<ObjectGeneric[FirstEntry], FollowingEntries> : never : never : never : never;
11
- export declare function getValueFromNestedKeys<ObjectGeneric extends object, KeysGeneric extends NestedSequentialKeys<ObjectGeneric>>(inputObject: ObjectGeneric, nestedKeys: KeysGeneric): NestedValue<ObjectGeneric, KeysGeneric> | undefined;
12
- //# sourceMappingURL=nested-keys.d.ts.map
@@ -1,19 +0,0 @@
1
- import { typedHasProperty } from './object';
2
- export function getValueFromNestedKeys(inputObject, nestedKeys) {
3
- /**
4
- * Lots of as any casts in here because these types are, under the hood, pretty complex. Since
5
- * the inputs and outputs of this function are well typed, these internal as any casts do not
6
- * affect the external API of this function.
7
- */
8
- const keyToAccess = nestedKeys[0];
9
- if (!typedHasProperty(inputObject, keyToAccess)) {
10
- return undefined;
11
- }
12
- const currentValue = inputObject[keyToAccess];
13
- if (nestedKeys.length > 1) {
14
- return getValueFromNestedKeys(currentValue, nestedKeys.slice(1));
15
- }
16
- else {
17
- return currentValue;
18
- }
19
- }
@@ -1,70 +0,0 @@
1
- import { AtLeastOneEntryArray } from './array';
2
- import { NoInfer, RequiredBy, UnPromise } from './type';
3
- export declare function getEnumTypedKeys<T extends object>(input: T): (keyof T)[];
4
- export declare function getEnumTypedValues<T extends object>(input: T): T[keyof T][];
5
- export declare function isEnumValue<T extends object>(input: unknown, checkEnum: T): input is T[keyof T];
6
- export type PartialWithNullable<T extends object> = {
7
- [Prop in keyof T]?: T[Prop] | null | undefined;
8
- };
9
- export declare function isKeyof<ObjectGeneric>(key: PropertyKey, object: ObjectGeneric): key is keyof object;
10
- export declare function filterToEnumValues<T extends object>(inputs: ReadonlyArray<unknown>, checkEnum: T, caseInsensitive?: boolean): T[keyof T][];
11
- export declare function getObjectTypedKeys<ObjectGeneric extends unknown>(input: ObjectGeneric): Array<keyof ObjectGeneric>;
12
- export declare function getObjectTypedValues<ObjectGeneric extends unknown>(input: ObjectGeneric): ObjectGeneric[keyof ObjectGeneric][];
13
- type ExtractValue<KeyGeneric extends PropertyKey, ParentGeneric> = KeyGeneric extends keyof ParentGeneric ? RequiredBy<ParentGeneric, KeyGeneric>[KeyGeneric] : KeyGeneric extends keyof Extract<ParentGeneric, Record<KeyGeneric, any>> ? RequiredBy<Extract<ParentGeneric, Record<KeyGeneric, any>>, KeyGeneric>[KeyGeneric] : never;
14
- type CombinedParentValue<KeyGeneric extends PropertyKey, ParentGeneric> = ExtractValue<KeyGeneric, ParentGeneric> extends never ? unknown : ExtractValue<KeyGeneric, ParentGeneric>;
15
- type CombineTypeWithKey<KeyGeneric extends PropertyKey, ParentGeneric> = ParentGeneric & Record<KeyGeneric, CombinedParentValue<KeyGeneric, ParentGeneric>>;
16
- export declare function typedHasProperty<KeyGeneric extends PropertyKey, ParentGeneric>(inputObject: ParentGeneric, inputKey: KeyGeneric): inputObject is CombineTypeWithKey<KeyGeneric, ParentGeneric>;
17
- export declare function typedHasProperties<KeyGeneric extends PropertyKey, ParentGeneric>(inputObject: ParentGeneric, inputKeys: ReadonlyArray<KeyGeneric>): inputObject is CombineTypeWithKey<KeyGeneric, ParentGeneric>;
18
- export declare function isObject(input: any): input is NonNullable<object>;
19
- export declare function getEntriesSortedByKey(input: object): [string, unknown][];
20
- export declare function areJsonEqual(a: object, b: object): boolean;
21
- export type InnerMappedValues<EntireInputGeneric extends object, MappedValueGeneric> = {
22
- [MappedProp in keyof EntireInputGeneric]: MappedValueGeneric;
23
- };
24
- export type MappedValues<EntireInputGeneric extends object, MappedValueGeneric> = MappedValueGeneric extends PromiseLike<unknown> ? Promise<InnerMappedValues<EntireInputGeneric, UnPromise<MappedValueGeneric>>> : InnerMappedValues<EntireInputGeneric, UnPromise<MappedValueGeneric>>;
25
- /**
26
- * Creates a new object with the same properties as the input object, but with values set to the
27
- * result of mapCallback for each property.
28
- */
29
- export declare function mapObjectValues<EntireInputGeneric extends object, MappedValueGeneric>(inputObject: EntireInputGeneric, mapCallback: (inputKey: keyof EntireInputGeneric, keyValue: EntireInputGeneric[typeof inputKey], fullObject: EntireInputGeneric) => MappedValueGeneric): MappedValues<EntireInputGeneric, MappedValueGeneric>;
30
- export declare function filterObject<ObjectGeneric extends object>(inputObject: ObjectGeneric, callback: (key: keyof ObjectGeneric, value: ObjectValueType<ObjectGeneric>, fullObject: ObjectGeneric) => boolean): Partial<ObjectGeneric>;
31
- /** The input here must be serializable otherwise JSON parsing errors will be thrown */
32
- export declare function copyThroughJson<T>(input: T): T;
33
- export type ObjectValueType<T extends object> = T[keyof T];
34
- /**
35
- * Checks that the first input, testThisOne, matches the object shape of the second input,
36
- * compareToThisOne. Does not compare exact values of properties, only types.
37
- *
38
- * To allow the test input, the first input, to have additional keys that the compare input, the
39
- * second input, does not have, pass in a third argument set to true.
40
- *
41
- * This function REQUIRES a generic to be assigned to it: it cannot infer it from the inputs.
42
- *
43
- * The compare input, the second input, is required to have at least one entry in every array value
44
- * that exists. If more array values are present, they will be considered other possible types for
45
- * entries in that array.
46
- */
47
- export declare function matchesObjectShape<MatchThisGeneric extends object>(testThisOne: unknown, compareToThisOne: NoInfer<ObjectWithAtLeastSingleEntryArrays<MatchThisGeneric>>, allowExtraProps?: boolean, shouldLogWhy?: boolean): testThisOne is MatchThisGeneric;
48
- export type ObjectWithAtLeastSingleEntryArrays<BaseObject extends object> = {
49
- [Prop in keyof BaseObject]: BaseObject[Prop] extends ReadonlyArray<any> ? AtLeastOneEntryArray<BaseObject[Prop]> : BaseObject[Prop] extends object ? ObjectWithAtLeastSingleEntryArrays<BaseObject[Prop]> : BaseObject[Prop];
50
- };
51
- export type NestedBoolean<MatchObject extends object> = Partial<{
52
- [Prop in keyof MatchObject]: MatchObject[Prop] extends object ? NestedBoolean<MatchObject[Prop]> | boolean : boolean;
53
- }>;
54
- /**
55
- * Asserts that the first input, testThisOne, matches the object shape of the second input,
56
- * compareToThisOne. Does not compare exact values of properties, only types.
57
- *
58
- * To allow the test input, the first input, to have additional keys that the compare input, the
59
- * second input, does not have, pass in a third argument set to true.
60
- *
61
- * This function REQUIRES a generic to be assigned to it: it cannot infer it from the inputs.
62
- *
63
- * The compare input, the second input, is required to have at least one entry in every array value
64
- * that exists. If more array values are present, they will be considered other possible types for
65
- * entries in that array.
66
- */
67
- export declare function assertMatchesObjectShape<MatchThisGeneric extends object = never>(testThisOne: unknown, compareToThisOne: NoInfer<ObjectWithAtLeastSingleEntryArrays<MatchThisGeneric>>, allowExtraProps?: boolean, noCheckInnerValueOfTheseKeys?: NestedBoolean<typeof compareToThisOne>): asserts testThisOne is MatchThisGeneric;
68
- export declare function typedObjectFromEntries<KeyType extends PropertyKey, ValueType>(entries: ReadonlyArray<Readonly<[KeyType, ValueType]>>): Record<KeyType, ValueType>;
69
- export {};
70
- //# sourceMappingURL=object.d.ts.map
@@ -1,255 +0,0 @@
1
- import { extractErrorMessage } from './error';
2
- import { isTruthy } from './function';
3
- export function getEnumTypedKeys(input) {
4
- // enum keys are always strings
5
- return getObjectTypedKeys(input).filter((key) => isNaN(Number(key)));
6
- }
7
- export function getEnumTypedValues(input) {
8
- const keys = getEnumTypedKeys(input);
9
- return keys.map((key) => input[key]);
10
- }
11
- export function isEnumValue(input, checkEnum) {
12
- return getEnumTypedValues(checkEnum).includes(input);
13
- }
14
- export function isKeyof(key, object) {
15
- return typedHasProperty(object, key);
16
- }
17
- export function filterToEnumValues(inputs, checkEnum, caseInsensitive = false) {
18
- if (caseInsensitive) {
19
- return inputs.reduce((accum, currentInput) => {
20
- const matchedEnumValue = getEnumTypedValues(checkEnum).find((actualEnumValue) => {
21
- return String(actualEnumValue).toUpperCase() === String(currentInput).toUpperCase();
22
- });
23
- if (matchedEnumValue) {
24
- return accum.concat(matchedEnumValue);
25
- }
26
- else {
27
- return accum;
28
- }
29
- }, []);
30
- }
31
- else {
32
- return inputs.filter((input) => isEnumValue(input, checkEnum));
33
- }
34
- }
35
- export function getObjectTypedKeys(input) {
36
- let reflectKeys;
37
- try {
38
- reflectKeys = Reflect.ownKeys(input);
39
- }
40
- catch (error) { }
41
- return (reflectKeys !== null && reflectKeys !== void 0 ? reflectKeys : [
42
- ...Object.keys(input),
43
- ...Object.getOwnPropertySymbols(input),
44
- ]);
45
- }
46
- export function getObjectTypedValues(input) {
47
- return getObjectTypedKeys(input).map((key) => input[key]);
48
- }
49
- const hasPropertyAttempts = [
50
- (object, key) => {
51
- return key in object;
52
- },
53
- (object, key) => {
54
- /** This handles cases where the input object can't use `in` directly, like string literals */
55
- return key in object.constructor.prototype;
56
- },
57
- ];
58
- export function typedHasProperty(inputObject, inputKey) {
59
- if (!inputObject) {
60
- return false;
61
- }
62
- return hasPropertyAttempts.some((attemptCallback) => {
63
- try {
64
- return attemptCallback(inputObject, inputKey);
65
- }
66
- catch (error) {
67
- return false;
68
- }
69
- });
70
- }
71
- export function typedHasProperties(inputObject, inputKeys) {
72
- return inputObject && inputKeys.every((key) => typedHasProperty(inputObject, key));
73
- }
74
- export function isObject(input) {
75
- return !!input && typeof input === 'object';
76
- }
77
- export function getEntriesSortedByKey(input) {
78
- return Object.entries(input).sort((tupleA, tupleB) => tupleA[0].localeCompare(tupleB[0]));
79
- }
80
- export function areJsonEqual(a, b) {
81
- try {
82
- const sortedAEntries = getEntriesSortedByKey(a);
83
- const sortedBEntries = getEntriesSortedByKey(b);
84
- return JSON.stringify(sortedAEntries) === JSON.stringify(sortedBEntries);
85
- }
86
- catch (error) {
87
- console.error(`Failed to compare objects using JSON.stringify`);
88
- throw error;
89
- }
90
- }
91
- /**
92
- * Creates a new object with the same properties as the input object, but with values set to the
93
- * result of mapCallback for each property.
94
- */
95
- export function mapObjectValues(inputObject, mapCallback) {
96
- let gotAPromise = false;
97
- const mappedObject = getObjectTypedKeys(inputObject).reduce((accum, currentKey) => {
98
- const mappedValue = mapCallback(currentKey, inputObject[currentKey], inputObject);
99
- if (mappedValue instanceof Promise) {
100
- gotAPromise = true;
101
- }
102
- return {
103
- ...accum,
104
- [currentKey]: mappedValue,
105
- };
106
- }, {});
107
- if (gotAPromise) {
108
- return new Promise(async (resolve, reject) => {
109
- try {
110
- await Promise.all(getObjectTypedKeys(mappedObject).map(async (key) => {
111
- const value = await mappedObject[key];
112
- mappedObject[key] = value;
113
- }));
114
- resolve(mappedObject);
115
- }
116
- catch (error) {
117
- reject(error);
118
- }
119
- });
120
- }
121
- else {
122
- return mappedObject;
123
- }
124
- }
125
- export function filterObject(inputObject, callback) {
126
- const filteredKeys = getObjectTypedKeys(inputObject).filter((key) => {
127
- const value = inputObject[key];
128
- return callback(key, value, inputObject);
129
- });
130
- return filteredKeys.reduce((accum, key) => {
131
- accum[key] = inputObject[key];
132
- return accum;
133
- }, {});
134
- }
135
- /** The input here must be serializable otherwise JSON parsing errors will be thrown */
136
- export function copyThroughJson(input) {
137
- try {
138
- return JSON.parse(JSON.stringify(input));
139
- }
140
- catch (error) {
141
- console.error(`Failed to JSON copy for`, input);
142
- throw error;
143
- }
144
- }
145
- /**
146
- * Checks that the first input, testThisOne, matches the object shape of the second input,
147
- * compareToThisOne. Does not compare exact values of properties, only types.
148
- *
149
- * To allow the test input, the first input, to have additional keys that the compare input, the
150
- * second input, does not have, pass in a third argument set to true.
151
- *
152
- * This function REQUIRES a generic to be assigned to it: it cannot infer it from the inputs.
153
- *
154
- * The compare input, the second input, is required to have at least one entry in every array value
155
- * that exists. If more array values are present, they will be considered other possible types for
156
- * entries in that array.
157
- */
158
- export function matchesObjectShape(testThisOne, compareToThisOne, allowExtraProps = false, shouldLogWhy = false) {
159
- try {
160
- assertMatchesObjectShape(testThisOne, compareToThisOne, allowExtraProps);
161
- return true;
162
- }
163
- catch (error) {
164
- if (shouldLogWhy) {
165
- console.error(error);
166
- }
167
- return false;
168
- }
169
- }
170
- /**
171
- * Asserts that the first input, testThisOne, matches the object shape of the second input,
172
- * compareToThisOne. Does not compare exact values of properties, only types.
173
- *
174
- * To allow the test input, the first input, to have additional keys that the compare input, the
175
- * second input, does not have, pass in a third argument set to true.
176
- *
177
- * This function REQUIRES a generic to be assigned to it: it cannot infer it from the inputs.
178
- *
179
- * The compare input, the second input, is required to have at least one entry in every array value
180
- * that exists. If more array values are present, they will be considered other possible types for
181
- * entries in that array.
182
- */
183
- export function assertMatchesObjectShape(testThisOne, compareToThisOne, allowExtraProps = false, noCheckInnerValueOfTheseKeys = {}) {
184
- const testKeys = getObjectTypedKeys(testThisOne);
185
- const matchKeys = new Set(getObjectTypedKeys(compareToThisOne));
186
- if (!allowExtraProps) {
187
- const extraKeys = testKeys.filter((testKey) => !matchKeys.has(testKey));
188
- if (extraKeys.length) {
189
- throw new Error(`Test object has extra keys: ${extraKeys.join(', ')}`);
190
- }
191
- }
192
- matchKeys.forEach((key) => {
193
- var _a;
194
- if (!typedHasProperty(testThisOne, key)) {
195
- throw new Error(`test object does not have key "${String(key)}" from expected shape.`);
196
- }
197
- function throwKeyError(reason) {
198
- throw new Error(`test object value at key "${String(key)}" did not match expected shape: ${reason}`);
199
- }
200
- const testValue = testThisOne[key];
201
- const shouldMatch = compareToThisOne[key];
202
- if (!noCheckInnerValueOfTheseKeys[key]) {
203
- compareInnerValue(testValue, shouldMatch, throwKeyError, allowExtraProps, (_a = noCheckInnerValueOfTheseKeys[key]) !== null && _a !== void 0 ? _a : {});
204
- }
205
- });
206
- }
207
- function compareInnerValue(testValue, matchValue, throwKeyError, allowExtraProps, noCheckInnerValueOfTheseKeys) {
208
- var _a;
209
- const testType = typeof testValue;
210
- const shouldMatchType = typeof matchValue;
211
- if (testType !== shouldMatchType) {
212
- throwKeyError(`type "${testType}" did not match expected type "${shouldMatchType}"`);
213
- }
214
- try {
215
- if (typedHasProperty(matchValue, 'constructor')) {
216
- if (!typedHasProperty(testValue, 'constructor') ||
217
- testValue.constructor !== matchValue.constructor) {
218
- throwKeyError(`constructor "${(_a = testValue === null || testValue === void 0 ? void 0 : testValue.constructor) === null || _a === void 0 ? void 0 : _a.name}" did not match expected constructor "${matchValue.constructor}"`);
219
- }
220
- }
221
- }
222
- catch (error) {
223
- // ignore errors from trying to find the constructor
224
- if (error instanceof throwKeyError) {
225
- throw error;
226
- }
227
- }
228
- if (Array.isArray(matchValue)) {
229
- if (!Array.isArray(testValue)) {
230
- throwKeyError(`expected an array`);
231
- }
232
- testValue.forEach((testValueEntry, index) => {
233
- const errors = matchValue
234
- .map((matchValue) => {
235
- try {
236
- compareInnerValue(testValueEntry, matchValue, throwKeyError, allowExtraProps, noCheckInnerValueOfTheseKeys);
237
- return undefined;
238
- }
239
- catch (error) {
240
- return new Error(`entry at index "${index}" did not match expected shape: ${extractErrorMessage(error)}`);
241
- }
242
- })
243
- .filter(isTruthy);
244
- if (errors.length === matchValue.length) {
245
- throw new Error(`entry at index "${index}" did not match any of the possible types from "${matchValue.join(', ')}"`);
246
- }
247
- });
248
- }
249
- else if (isObject(matchValue)) {
250
- assertMatchesObjectShape(testValue, matchValue, allowExtraProps, noCheckInnerValueOfTheseKeys);
251
- }
252
- }
253
- export function typedObjectFromEntries(entries) {
254
- return Object.fromEntries(entries);
255
- }
@@ -1,8 +0,0 @@
1
- import { UnionToIntersection } from 'type-fest';
2
- import { NestedKeys } from './object/nested-keys';
3
- type InnerPickDeep<OriginalObjectGeneric extends object, DeepKeys extends any[]> = UnionToIntersection<DeepKeys extends [infer CurrentLevelPick, ...infer RemainingKeys] ? {
4
- [CurrentProp in Extract<CurrentLevelPick, keyof OriginalObjectGeneric>]: OriginalObjectGeneric[CurrentProp] extends object ? InnerPickDeep<OriginalObjectGeneric[CurrentProp], RemainingKeys> : OriginalObjectGeneric[CurrentProp];
5
- } : DeepKeys extends [infer CurrentLevelPick] ? CurrentLevelPick extends keyof OriginalObjectGeneric ? Pick<OriginalObjectGeneric, CurrentLevelPick> : never : never>;
6
- export type PickDeep<OriginalObjectGeneric extends object, DeepKeys extends NestedKeys<OriginalObjectGeneric>> = InnerPickDeep<OriginalObjectGeneric, DeepKeys>;
7
- export {};
8
- //# sourceMappingURL=pick-deep.d.ts.map
@@ -1 +0,0 @@
1
- export {};
@@ -1,19 +0,0 @@
1
- import { AnyFunction } from './function';
2
- declare function getTypeOf(x: any): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
3
- export type TypeOf = ReturnType<typeof getTypeOf>;
4
- export type TypeOfWithArray = TypeOf | 'array';
5
- export type TypeOfMapping = {
6
- array: any[];
7
- bigint: bigint;
8
- boolean: boolean;
9
- function: AnyFunction;
10
- number: number;
11
- object: Record<PropertyKey, unknown>;
12
- string: string;
13
- symbol: symbol;
14
- undefined: undefined;
15
- };
16
- export declare function typeOfWithArray(input: unknown): TypeOfWithArray;
17
- export declare function isTypeOfWithArray<T extends TypeOfWithArray>(input: unknown, testType: T): input is TypeOfMapping[T];
18
- export {};
19
- //# sourceMappingURL=type-of.d.ts.map
@@ -1,12 +0,0 @@
1
- // this function is not used at run time, it's only here for types
2
- // istanbul ignore next
3
- function getTypeOf(x) {
4
- return typeof x;
5
- }
6
- export function typeOfWithArray(input) {
7
- return Array.isArray(input) ? 'array' : typeof input;
8
- }
9
- export function isTypeOfWithArray(input, testType) {
10
- const inputType = typeOfWithArray(input);
11
- return inputType === testType;
12
- }
@@ -1,12 +0,0 @@
1
- import { UnionToIntersection } from 'type-fest';
2
- import { ObjectValueType } from '../object';
3
- export type NestedSequentialKeys<ObjectGeneric extends object> = ObjectValueType<{
4
- [Prop in keyof ObjectGeneric]: NonNullable<ObjectGeneric[Prop]> extends object ? [Prop, ...(NestedSequentialKeys<NonNullable<ObjectGeneric[Prop]>> | [])] : [Prop];
5
- }>;
6
- export type NestedKeys<ObjectGeneric extends object> = UnionToIntersection<Extract<ObjectValueType<ObjectGeneric>, object>> extends object ? [
7
- keyof ObjectGeneric,
8
- ...(NestedKeys<UnionToIntersection<Extract<ObjectValueType<ObjectGeneric>, object>>> | [])
9
- ] : [keyof ObjectGeneric];
10
- export type NestedValue<ObjectGeneric extends object, NestedKeysGeneric extends NestedSequentialKeys<ObjectGeneric>> = NestedKeysGeneric extends readonly [infer FirstEntry, ...infer FollowingEntries] ? FirstEntry extends keyof ObjectGeneric ? FollowingEntries extends never[] ? ObjectGeneric[FirstEntry] : ObjectGeneric[FirstEntry] extends object ? FollowingEntries extends NestedSequentialKeys<ObjectGeneric[FirstEntry]> ? NestedValue<ObjectGeneric[FirstEntry], FollowingEntries> : never : never : never : never;
11
- export declare function getValueFromNestedKeys<ObjectGeneric extends object, KeysGeneric extends NestedSequentialKeys<ObjectGeneric>>(inputObject: ObjectGeneric, nestedKeys: KeysGeneric): NestedValue<ObjectGeneric, KeysGeneric> | undefined;
12
- //# sourceMappingURL=nested-keys.d.ts.map
@@ -1,70 +0,0 @@
1
- import { AtLeastOneEntryArray } from './array';
2
- import { NoInfer, RequiredBy, UnPromise } from './type';
3
- export declare function getEnumTypedKeys<T extends object>(input: T): (keyof T)[];
4
- export declare function getEnumTypedValues<T extends object>(input: T): T[keyof T][];
5
- export declare function isEnumValue<T extends object>(input: unknown, checkEnum: T): input is T[keyof T];
6
- export type PartialWithNullable<T extends object> = {
7
- [Prop in keyof T]?: T[Prop] | null | undefined;
8
- };
9
- export declare function isKeyof<ObjectGeneric>(key: PropertyKey, object: ObjectGeneric): key is keyof object;
10
- export declare function filterToEnumValues<T extends object>(inputs: ReadonlyArray<unknown>, checkEnum: T, caseInsensitive?: boolean): T[keyof T][];
11
- export declare function getObjectTypedKeys<ObjectGeneric extends unknown>(input: ObjectGeneric): Array<keyof ObjectGeneric>;
12
- export declare function getObjectTypedValues<ObjectGeneric extends unknown>(input: ObjectGeneric): ObjectGeneric[keyof ObjectGeneric][];
13
- type ExtractValue<KeyGeneric extends PropertyKey, ParentGeneric> = KeyGeneric extends keyof ParentGeneric ? RequiredBy<ParentGeneric, KeyGeneric>[KeyGeneric] : KeyGeneric extends keyof Extract<ParentGeneric, Record<KeyGeneric, any>> ? RequiredBy<Extract<ParentGeneric, Record<KeyGeneric, any>>, KeyGeneric>[KeyGeneric] : never;
14
- type CombinedParentValue<KeyGeneric extends PropertyKey, ParentGeneric> = ExtractValue<KeyGeneric, ParentGeneric> extends never ? unknown : ExtractValue<KeyGeneric, ParentGeneric>;
15
- type CombineTypeWithKey<KeyGeneric extends PropertyKey, ParentGeneric> = ParentGeneric & Record<KeyGeneric, CombinedParentValue<KeyGeneric, ParentGeneric>>;
16
- export declare function typedHasProperty<KeyGeneric extends PropertyKey, ParentGeneric>(inputObject: ParentGeneric, inputKey: KeyGeneric): inputObject is CombineTypeWithKey<KeyGeneric, ParentGeneric>;
17
- export declare function typedHasProperties<KeyGeneric extends PropertyKey, ParentGeneric>(inputObject: ParentGeneric, inputKeys: ReadonlyArray<KeyGeneric>): inputObject is CombineTypeWithKey<KeyGeneric, ParentGeneric>;
18
- export declare function isObject(input: any): input is NonNullable<object>;
19
- export declare function getEntriesSortedByKey(input: object): [string, unknown][];
20
- export declare function areJsonEqual(a: object, b: object): boolean;
21
- export type InnerMappedValues<EntireInputGeneric extends object, MappedValueGeneric> = {
22
- [MappedProp in keyof EntireInputGeneric]: MappedValueGeneric;
23
- };
24
- export type MappedValues<EntireInputGeneric extends object, MappedValueGeneric> = MappedValueGeneric extends PromiseLike<unknown> ? Promise<InnerMappedValues<EntireInputGeneric, UnPromise<MappedValueGeneric>>> : InnerMappedValues<EntireInputGeneric, UnPromise<MappedValueGeneric>>;
25
- /**
26
- * Creates a new object with the same properties as the input object, but with values set to the
27
- * result of mapCallback for each property.
28
- */
29
- export declare function mapObjectValues<EntireInputGeneric extends object, MappedValueGeneric>(inputObject: EntireInputGeneric, mapCallback: (inputKey: keyof EntireInputGeneric, keyValue: EntireInputGeneric[typeof inputKey], fullObject: EntireInputGeneric) => MappedValueGeneric): MappedValues<EntireInputGeneric, MappedValueGeneric>;
30
- export declare function filterObject<ObjectGeneric extends object>(inputObject: ObjectGeneric, callback: (key: keyof ObjectGeneric, value: ObjectValueType<ObjectGeneric>, fullObject: ObjectGeneric) => boolean): Partial<ObjectGeneric>;
31
- /** The input here must be serializable otherwise JSON parsing errors will be thrown */
32
- export declare function copyThroughJson<T>(input: T): T;
33
- export type ObjectValueType<T extends object> = T[keyof T];
34
- /**
35
- * Checks that the first input, testThisOne, matches the object shape of the second input,
36
- * compareToThisOne. Does not compare exact values of properties, only types.
37
- *
38
- * To allow the test input, the first input, to have additional keys that the compare input, the
39
- * second input, does not have, pass in a third argument set to true.
40
- *
41
- * This function REQUIRES a generic to be assigned to it: it cannot infer it from the inputs.
42
- *
43
- * The compare input, the second input, is required to have at least one entry in every array value
44
- * that exists. If more array values are present, they will be considered other possible types for
45
- * entries in that array.
46
- */
47
- export declare function matchesObjectShape<MatchThisGeneric extends object>(testThisOne: unknown, compareToThisOne: NoInfer<ObjectWithAtLeastSingleEntryArrays<MatchThisGeneric>>, allowExtraProps?: boolean, shouldLogWhy?: boolean): testThisOne is MatchThisGeneric;
48
- export type ObjectWithAtLeastSingleEntryArrays<BaseObject extends object> = {
49
- [Prop in keyof BaseObject]: BaseObject[Prop] extends ReadonlyArray<any> ? AtLeastOneEntryArray<BaseObject[Prop]> : BaseObject[Prop] extends object ? ObjectWithAtLeastSingleEntryArrays<BaseObject[Prop]> : BaseObject[Prop];
50
- };
51
- export type NestedBoolean<MatchObject extends object> = Partial<{
52
- [Prop in keyof MatchObject]: MatchObject[Prop] extends object ? NestedBoolean<MatchObject[Prop]> | boolean : boolean;
53
- }>;
54
- /**
55
- * Asserts that the first input, testThisOne, matches the object shape of the second input,
56
- * compareToThisOne. Does not compare exact values of properties, only types.
57
- *
58
- * To allow the test input, the first input, to have additional keys that the compare input, the
59
- * second input, does not have, pass in a third argument set to true.
60
- *
61
- * This function REQUIRES a generic to be assigned to it: it cannot infer it from the inputs.
62
- *
63
- * The compare input, the second input, is required to have at least one entry in every array value
64
- * that exists. If more array values are present, they will be considered other possible types for
65
- * entries in that array.
66
- */
67
- export declare function assertMatchesObjectShape<MatchThisGeneric extends object = never>(testThisOne: unknown, compareToThisOne: NoInfer<ObjectWithAtLeastSingleEntryArrays<MatchThisGeneric>>, allowExtraProps?: boolean, noCheckInnerValueOfTheseKeys?: NestedBoolean<typeof compareToThisOne>): asserts testThisOne is MatchThisGeneric;
68
- export declare function typedObjectFromEntries<KeyType extends PropertyKey, ValueType>(entries: ReadonlyArray<Readonly<[KeyType, ValueType]>>): Record<KeyType, ValueType>;
69
- export {};
70
- //# sourceMappingURL=object.d.ts.map
@@ -1,8 +0,0 @@
1
- import { UnionToIntersection } from 'type-fest';
2
- import { NestedKeys } from './object/nested-keys';
3
- type InnerPickDeep<OriginalObjectGeneric extends object, DeepKeys extends any[]> = UnionToIntersection<DeepKeys extends [infer CurrentLevelPick, ...infer RemainingKeys] ? {
4
- [CurrentProp in Extract<CurrentLevelPick, keyof OriginalObjectGeneric>]: OriginalObjectGeneric[CurrentProp] extends object ? InnerPickDeep<OriginalObjectGeneric[CurrentProp], RemainingKeys> : OriginalObjectGeneric[CurrentProp];
5
- } : DeepKeys extends [infer CurrentLevelPick] ? CurrentLevelPick extends keyof OriginalObjectGeneric ? Pick<OriginalObjectGeneric, CurrentLevelPick> : never : never>;
6
- export type PickDeep<OriginalObjectGeneric extends object, DeepKeys extends NestedKeys<OriginalObjectGeneric>> = InnerPickDeep<OriginalObjectGeneric, DeepKeys>;
7
- export {};
8
- //# sourceMappingURL=pick-deep.d.ts.map
@@ -1,19 +0,0 @@
1
- import { AnyFunction } from './function';
2
- declare function getTypeOf(x: any): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
3
- export type TypeOf = ReturnType<typeof getTypeOf>;
4
- export type TypeOfWithArray = TypeOf | 'array';
5
- export type TypeOfMapping = {
6
- array: any[];
7
- bigint: bigint;
8
- boolean: boolean;
9
- function: AnyFunction;
10
- number: number;
11
- object: Record<PropertyKey, unknown>;
12
- string: string;
13
- symbol: symbol;
14
- undefined: undefined;
15
- };
16
- export declare function typeOfWithArray(input: unknown): TypeOfWithArray;
17
- export declare function isTypeOfWithArray<T extends TypeOfWithArray>(input: unknown, testType: T): input is TypeOfMapping[T];
18
- export {};
19
- //# sourceMappingURL=type-of.d.ts.map