inferred-types 0.22.0 → 0.22.5
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/index.d.ts +69 -47
- package/dist/index.js +40 -16
- package/dist/index.mjs +39 -15
- package/package.json +18 -14
- package/src/Mutation/index.ts +6 -29
- package/src/index.ts +6 -29
- package/src/shared/index.ts +6 -29
- package/src/types/Keys.ts +10 -6
- package/src/types/alphabetic/CamelCase.ts +1 -1
- package/src/types/alphabetic/alpha-characters.ts +33 -9
- package/src/types/alphabetic/index.ts +6 -29
- package/src/types/dictionary/DictChangeValue.ts +26 -0
- package/src/types/dictionary/MutableProps.ts +19 -0
- package/src/types/dictionary/index.ts +7 -29
- package/src/types/dictionary/props.ts +1 -1
- package/src/types/fluent/index.ts +6 -29
- package/src/types/functions/index.ts +6 -29
- package/src/types/index.ts +6 -29
- package/src/types/kv/index.ts +6 -29
- package/src/types/lists/index.ts +6 -29
- package/src/types/string-literals/index.ts +6 -29
- package/src/types/tuples/index.ts +6 -29
- package/src/types/type-conversion/index.ts +6 -29
- package/src/utility/api/index.ts +6 -29
- package/src/utility/dictionary/defineProperties.ts +35 -0
- package/src/utility/dictionary/index.ts +7 -29
- package/src/utility/dictionary/kv/index.ts +6 -29
- package/src/utility/errors/ReadOnlyViolation.ts +3 -0
- package/src/utility/errors/index.ts +12 -0
- package/src/utility/index.ts +7 -29
- package/src/utility/lists/index.ts +6 -29
- package/src/utility/literals/index.ts +6 -29
- package/src/utility/map-reduce/index.ts +6 -29
- package/src/utility/modelling/index.ts +6 -29
- package/src/utility/runtime/conditions/index.ts +6 -30
- package/src/utility/runtime/ifTypeOf.ts +4 -3
- package/src/utility/runtime/index.ts +6 -29
- package/src/utility/state/index.ts +6 -29
- package/tests/data/index.ts +6 -29
- package/tests/dictionary/DictChangeValue.test.ts +30 -0
- package/tests/dictionary/DictReturnValues.test.ts +5 -1
- package/tests/dictionary/MutableProps.test.ts +30 -0
- package/src/utility/runtime/conditions/isLiteral.ts +0 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Alpha as Alpha$1 } from 'common-types';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* **MutationIdentity**
|
|
5
3
|
*
|
|
@@ -433,9 +431,6 @@ declare type IsFunction<T> = T extends FunctionType ? true : false;
|
|
|
433
431
|
*/
|
|
434
432
|
declare function isFunction<T extends unknown>(input: T): IsFunction<T>;
|
|
435
433
|
|
|
436
|
-
declare type IsLiteral<L extends string | number, T extends any> = T extends L ? true : false;
|
|
437
|
-
declare function isLiteral<L extends Readonly<string>>(...allowed: L[]): <T extends unknown>(i: T) => IsLiteral<L, T>;
|
|
438
|
-
|
|
439
434
|
declare function isNull<T>(i: T): T extends null ? true : false;
|
|
440
435
|
|
|
441
436
|
declare function isNumber<T>(i: T): T extends number ? true : false;
|
|
@@ -562,6 +557,20 @@ O extends (...args: any[]) => any = (...args: any[]) => any> = SimplifyObject<{
|
|
|
562
557
|
*/
|
|
563
558
|
declare type Get<T, K> = K extends `${infer FK}.${infer L}` ? FK extends keyof T ? Get<T[FK], L> : never : K extends keyof T ? T[K] : never;
|
|
564
559
|
|
|
560
|
+
/**
|
|
561
|
+
* Given a dictionary of type `<T>`, this utility function will
|
|
562
|
+
* make the `<M>` generic property _mutable_ and all other _read-only_.
|
|
563
|
+
*
|
|
564
|
+
* ```ts
|
|
565
|
+
* // { foo: string, bar?: Readonly<number> }
|
|
566
|
+
* type Example = MutableProps<{
|
|
567
|
+
* foo: Readonly<string>,
|
|
568
|
+
* bar?: number
|
|
569
|
+
* }, "foo">;
|
|
570
|
+
* ```
|
|
571
|
+
*/
|
|
572
|
+
declare type MutableProps<T extends {}, M extends keyof T & string> = ExpandRecursively<Mutable<Pick<T, M>> & Readonly<Pick<T, Keys<T, M>>>>;
|
|
573
|
+
|
|
565
574
|
/**
|
|
566
575
|
* Given a dictionary of type `<T>`, this utility function will
|
|
567
576
|
* make the `<R>` generic property _required_ (use a union to make
|
|
@@ -574,6 +583,43 @@ declare type Get<T, K> = K extends `${infer FK}.${infer L}` ? FK extends keyof T
|
|
|
574
583
|
*/
|
|
575
584
|
declare type RequireProps<T extends {}, R extends keyof T> = ExpandRecursively<Required<Pick<T, R>> & T>;
|
|
576
585
|
|
|
586
|
+
declare type LowerAlpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
|
|
587
|
+
/** Uppercase alphabetic character */
|
|
588
|
+
declare type UpperAlpha = Uppercase<LowerAlpha>;
|
|
589
|
+
/**
|
|
590
|
+
* Alphabetical characters (upper and lower)
|
|
591
|
+
*/
|
|
592
|
+
declare type Alpha = UpperAlpha | LowerAlpha;
|
|
593
|
+
declare type Whitespace = " " | "\n" | "\t";
|
|
594
|
+
declare type Punctuation = "." | "," | ";" | "!" | "?";
|
|
595
|
+
/**
|
|
596
|
+
* Characters which typically are used to separate words (but not including a space)
|
|
597
|
+
*/
|
|
598
|
+
declare type StringDelimiter = "_" | "-" | "/" | "\\";
|
|
599
|
+
declare type OpeningBracket = "(" | "[" | "{";
|
|
600
|
+
declare type ClosingBracket = ")" | "]" | "}";
|
|
601
|
+
/**
|
|
602
|
+
* Opening and closing parenthesis
|
|
603
|
+
*/
|
|
604
|
+
declare type Parenthesis = "(" | ")";
|
|
605
|
+
/**
|
|
606
|
+
* Opening and closing brackets
|
|
607
|
+
*/
|
|
608
|
+
declare type Bracket = OpeningBracket | ClosingBracket;
|
|
609
|
+
/**
|
|
610
|
+
* Numeric string characters
|
|
611
|
+
*/
|
|
612
|
+
declare type NumericString = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
613
|
+
/**
|
|
614
|
+
* Any alphabetic or numeric string character
|
|
615
|
+
*/
|
|
616
|
+
declare type AlphaNumeric = Alpha | NumericString;
|
|
617
|
+
declare type SpecialCharacters = "@" | "~" | "^" | "#" | "&" | "*";
|
|
618
|
+
/**
|
|
619
|
+
* Non-alphabetic characters including whitespace, string numerals, and
|
|
620
|
+
*/
|
|
621
|
+
declare type NonAlpha = Whitespace | Punctuation | NumericString | Bracket | SpecialCharacters;
|
|
622
|
+
|
|
577
623
|
/**
|
|
578
624
|
* Extracts the _required_ keys in the object's type
|
|
579
625
|
*/
|
|
@@ -607,7 +653,7 @@ declare type KeysWithValue<W extends any, T extends object> = {
|
|
|
607
653
|
* A `PrivateKey` must start with a `_` character and then follow with
|
|
608
654
|
* an alphabetic character
|
|
609
655
|
*/
|
|
610
|
-
declare type PrivateKey = `_${Alpha
|
|
656
|
+
declare type PrivateKey = `_${Alpha}${string}`;
|
|
611
657
|
/**
|
|
612
658
|
* Keys on an object which have a `_` character as first part of the
|
|
613
659
|
* name are considered private and this utility will create a union
|
|
@@ -905,43 +951,6 @@ declare type StringLength<S extends string, R extends number[] = []> = S extends
|
|
|
905
951
|
*/
|
|
906
952
|
declare type Trim<S extends string> = string extends S ? string : S extends `${Whitespace}${infer Right}` ? Trim<Right> : S extends `${infer Left}${Whitespace}` ? Trim<Left> : S;
|
|
907
953
|
|
|
908
|
-
declare type LowerAlpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
|
|
909
|
-
/** Uppercase alphabetic character */
|
|
910
|
-
declare type UpperAlpha = Uppercase<LowerAlpha>;
|
|
911
|
-
/**
|
|
912
|
-
* Alphabetical characters (upper and lower)
|
|
913
|
-
*/
|
|
914
|
-
declare type Alpha = UpperAlpha | LowerAlpha;
|
|
915
|
-
declare type Whitespace = " " | "\n" | "\t";
|
|
916
|
-
declare type Punctuation = "." | "," | ";" | "!" | "?";
|
|
917
|
-
/**
|
|
918
|
-
* Characters which typically are used to separate words (but not including a space)
|
|
919
|
-
*/
|
|
920
|
-
declare type StringDelimiter = "_" | "-" | "/" | "\\";
|
|
921
|
-
declare type OpenningBracket = "(" | "[" | "{";
|
|
922
|
-
declare type ClosingBracket = ")" | "]" | "}";
|
|
923
|
-
/**
|
|
924
|
-
* Openning and closing parenthesis
|
|
925
|
-
*/
|
|
926
|
-
declare type Parenthesis = "(" | ")";
|
|
927
|
-
/**
|
|
928
|
-
* Openning and closing brackets
|
|
929
|
-
*/
|
|
930
|
-
declare type Bracket = OpenningBracket | ClosingBracket;
|
|
931
|
-
/**
|
|
932
|
-
* Numeric string characters
|
|
933
|
-
*/
|
|
934
|
-
declare type NumericString = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
935
|
-
/**
|
|
936
|
-
* Any alphabetic or numeric string character
|
|
937
|
-
*/
|
|
938
|
-
declare type AlphaNumeric = Alpha | NumericString;
|
|
939
|
-
declare type SpecialCharacters = "@" | "~" | "^" | "#" | "&" | "*";
|
|
940
|
-
/**
|
|
941
|
-
* Non-alphabetic characters including whitespace, string numerals, and
|
|
942
|
-
*/
|
|
943
|
-
declare type NonAlpha = Whitespace | Punctuation | NumericString | Bracket | SpecialCharacters;
|
|
944
|
-
|
|
945
954
|
/**
|
|
946
955
|
* An email address
|
|
947
956
|
*/
|
|
@@ -972,7 +981,7 @@ declare type DashDelim<T extends string> = T extends `${infer Begin}${" "}${infe
|
|
|
972
981
|
*/
|
|
973
982
|
declare type PascalCase<S extends string> = string extends S ? string : Trim<DashDelim<LowerAllCaps<S>>> extends `${infer Begin}${Delimiter}${infer Rest}` ? PascalCase<`${Capitalize<Begin>}${Capitalize<Rest>}`> : Capitalize<Trim<LowerAllCaps<S>>>;
|
|
974
983
|
|
|
975
|
-
declare type CamelCase<S extends string> = Uncapitalize<PascalCase<S>>;
|
|
984
|
+
declare type CamelCase<S extends string> = string extends S ? string : Uncapitalize<PascalCase<S>>;
|
|
976
985
|
|
|
977
986
|
/**
|
|
978
987
|
* Capitalize all words in a string
|
|
@@ -1331,6 +1340,19 @@ declare const api: <N extends Narrowable, TPrivate extends Readonly<Record<any,
|
|
|
1331
1340
|
*/
|
|
1332
1341
|
declare function arrayToKeyLookup<T extends readonly string[]>(...keys: T): Record<T[number], true>;
|
|
1333
1342
|
|
|
1343
|
+
interface DefinePropertiesApi<T extends {}> {
|
|
1344
|
+
/**
|
|
1345
|
+
* Makes a property on the object **readonly** on the Javascript runtime
|
|
1346
|
+
*/
|
|
1347
|
+
ro<K extends keyof T>(prop: K, errorMsg?: (p: K, v: any) => string): Omit<T, K> & Record<K, Readonly<T[K]>>;
|
|
1348
|
+
/**
|
|
1349
|
+
* Makes a property on the object **read/writeable** on the Javascript runtime;
|
|
1350
|
+
* this is the default so only use this where it is needed.
|
|
1351
|
+
*/
|
|
1352
|
+
rw<K extends keyof T>(prop: K): Omit<T, K> & Record<K, Readonly<T[K]>>;
|
|
1353
|
+
}
|
|
1354
|
+
declare function defineProperties<T extends {}>(obj: T): DefinePropertiesApi<T>;
|
|
1355
|
+
|
|
1334
1356
|
/**
|
|
1335
1357
|
* Takes a dictionary of type `I` and converts it to a dictionary of type `O` where
|
|
1336
1358
|
* they _keys_ used in both dictionaries are the same.
|
|
@@ -1383,10 +1405,10 @@ declare function strArrayToDict<T extends readonly string[]>(...strings: T): Exp
|
|
|
1383
1405
|
* const arr = dictToKv({ id: 123, foo: "bar" });
|
|
1384
1406
|
* ```
|
|
1385
1407
|
*/
|
|
1386
|
-
declare function dictToKv<N extends Narrowable, T extends Record<string, N>, U extends boolean>(obj: T, _makeTuple?: U): U extends true ? UnionToTuple<(Mutable<T> extends infer T_1 ? { [K in keyof T_1]: {
|
|
1408
|
+
declare function dictToKv<N extends Narrowable, T extends Record<string, N>, U extends boolean>(obj: T, _makeTuple?: U): U extends true ? UnionToTuple<(Mutable<T> extends infer T_1 extends object ? { [K in keyof T_1]: {
|
|
1387
1409
|
key: K;
|
|
1388
1410
|
value: Mutable<T>[K];
|
|
1389
|
-
}; } : never)[keyof T], LastInUnion<(Mutable<T> extends infer T_1 ? { [K in keyof T_1]: {
|
|
1411
|
+
}; } : never)[keyof T], LastInUnion<(Mutable<T> extends infer T_1 extends object ? { [K in keyof T_1]: {
|
|
1390
1412
|
key: K;
|
|
1391
1413
|
value: Mutable<T>[K];
|
|
1392
1414
|
}; } : never)[keyof T]>> : KvFrom<Mutable<T>>;
|
|
@@ -1653,4 +1675,4 @@ interface IFluentConfigurator<C> {
|
|
|
1653
1675
|
*/
|
|
1654
1676
|
declare function FluentConfigurator<I>(initial?: I): IFluentConfigurator<{}>;
|
|
1655
1677
|
|
|
1656
|
-
export { AllCaps, Alpha, AlphaNumeric, Api, ApiFunction, ApiValue, AppendToDictionary, AppendToObject, ArrConcat, Array$1 as Array, ArrayConverter, AssertExtends, Bracket, Break, CamelCase, CapitalizeWords, ClosingBracket, Condition, Configurator, Constructor, DashToSnake, DashUppercase, Dasherize, DictArray, DictArrayFilterCallback, DictArrayKv, DictFromKv, DictKvTuple, DictPartialApplication, DictPrependWithFn, DictReturnValues, DynamicRule, DynamicRuleSet, Email, EnumValues, ExpandRecursively, ExpectExtends, ExplicitFunction, ExtendsClause, ExtendsNarrowlyClause, Filter, FinalReturn, First, FirstKey, FirstKeyValue, FirstOfEach, FluentConfigurator, FluentFunction, FromDictArray, FunctionType, GeneralDictionary, Get, HasUppercase, IConfigurator, IFluentConfigurator, If, IfExtends, IfExtendsThen, Include, Includes, IsArray, IsBoolean, IsCapitalized, IsFalse, IsFunction,
|
|
1678
|
+
export { AllCaps, Alpha, AlphaNumeric, Api, ApiFunction, ApiValue, AppendToDictionary, AppendToObject, ArrConcat, Array$1 as Array, ArrayConverter, AssertExtends, Bracket, Break, CamelCase, CapitalizeWords, ClosingBracket, Condition, Configurator, Constructor, DashToSnake, DashUppercase, Dasherize, DefinePropertiesApi, DictArray, DictArrayFilterCallback, DictArrayKv, DictFromKv, DictKvTuple, DictPartialApplication, DictPrependWithFn, DictReturnValues, DynamicRule, DynamicRuleSet, Email, EnumValues, ExpandRecursively, ExpectExtends, ExplicitFunction, ExtendsClause, ExtendsNarrowlyClause, Filter, FinalReturn, First, FirstKey, FirstKeyValue, FirstOfEach, FluentConfigurator, FluentFunction, FromDictArray, FunctionType, GeneralDictionary, Get, HasUppercase, IConfigurator, IFluentConfigurator, If, IfExtends, IfExtendsThen, Include, Includes, IsArray, IsBoolean, IsCapitalized, IsFalse, IsFunction, IsObject, IsString, IsTrue, KebabCase, KeyValue, KeyedRecord, Keys, KeysWithValue, KvFrom, KvTuple, LastInUnion, LeftWhitespace, Length, LowerAllCaps, LowerAlpha, MaybeFalse, MaybeTrue, Model, Mutable, MutableProps, MutationFunction, MutationIdentity, Narrowable, NonAlpha, NonNumericKeys, NonStringKeys, Not, Numeric, NumericKeys, NumericString, ObjectType, Opaque, OpeningBracket, OptionalKeys, OptionalProps, Parenthesis, PascalCase, Pluralize, PrivateKey, PrivateKeys, PublicKeys, Punctuation, PureFluentApi, Replace, RequireProps, RequiredKeys, RequiredProps, Retain, RightWhitespace, RuleDefinition, RuntimeProp, RuntimeType, SameKeys, SecondOfEach, SimplifyObject, SnakeCase, SpecialCharacters, StringDelimiter, StringKeys, StringLength, ToFluent, Transformer, Trim, TrimLeft, TrimRight, TupleToUnion, Type, TypeApi, TypeCondition, TypeDefinition, TypeGuard, TypeOptions, UnionToIntersection, UnionToTuple, UniqueDictionary, UniqueForProp, UpperAlpha, ValueTuple, ValueTypeFunc, ValueTypes, Where, WhereNot, Whitespace, WithNumericKeys, WithStringKeys, WithValue, ZipCode, and, api, arrayToKeyLookup, arrayToObject, condition, createFnWithProps, createMutationFunction, defineProperties, defineType, dictToKv, dictionaryTransform, entries, equals, filterDictArray, fnWithProps, greater, groupBy, idLiteral, idTypeGuard, identity, ifTypeOf, isArray, isBoolean, isFalse, isFunction, isNull, isNumber, isObject, isString, isSymbol, isTrue, isType, isUndefined, keys, kindLiteral, kv, kvToDict, less, literal, mapValues, nameLiteral, or, randomString, readonlyFnWithProps, ruleSet, strArrayToDict, type, typeApi, uuid, valueTypes, withValue };
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@ __export(src_exports, {
|
|
|
32
32
|
condition: () => condition,
|
|
33
33
|
createFnWithProps: () => createFnWithProps,
|
|
34
34
|
createMutationFunction: () => createMutationFunction,
|
|
35
|
+
defineProperties: () => defineProperties,
|
|
35
36
|
defineType: () => defineType,
|
|
36
37
|
dictToKv: () => dictToKv,
|
|
37
38
|
dictionaryTransform: () => dictionaryTransform,
|
|
@@ -49,7 +50,6 @@ __export(src_exports, {
|
|
|
49
50
|
isBoolean: () => isBoolean,
|
|
50
51
|
isFalse: () => isFalse,
|
|
51
52
|
isFunction: () => isFunction,
|
|
52
|
-
isLiteral: () => isLiteral,
|
|
53
53
|
isNull: () => isNull,
|
|
54
54
|
isNumber: () => isNumber,
|
|
55
55
|
isObject: () => isObject,
|
|
@@ -174,6 +174,26 @@ function arrayToKeyLookup(...keys2) {
|
|
|
174
174
|
return obj;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
// src/utility/dictionary/defineProperties.ts
|
|
178
|
+
function defineProperties(obj) {
|
|
179
|
+
return {
|
|
180
|
+
ro(prop, errorMsg) {
|
|
181
|
+
Object.defineProperty(obj, prop, {
|
|
182
|
+
writable: false,
|
|
183
|
+
set(v) {
|
|
184
|
+
const message = errorMsg ? errorMsg(prop, v) : `The ${String(
|
|
185
|
+
prop
|
|
186
|
+
)} is readonly but an attempt was made to change it's value to "${JSON.stringify(
|
|
187
|
+
v
|
|
188
|
+
)}"!`;
|
|
189
|
+
throw new Error(message);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
return obj;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
177
197
|
// src/utility/dictionary/dictionaryTransform.ts
|
|
178
198
|
function dictionaryTransform(input, transform) {
|
|
179
199
|
return keys(input).reduce((acc, i) => {
|
|
@@ -196,7 +216,9 @@ function entries(obj) {
|
|
|
196
216
|
|
|
197
217
|
// src/utility/dictionary/mapValues.ts
|
|
198
218
|
function mapValues(obj, valueMapper) {
|
|
199
|
-
return Object.fromEntries(
|
|
219
|
+
return Object.fromEntries(
|
|
220
|
+
[...entries(obj)].map(([k, v]) => [k, valueMapper(v)])
|
|
221
|
+
);
|
|
200
222
|
}
|
|
201
223
|
|
|
202
224
|
// src/utility/dictionary/strArrayToDict.ts
|
|
@@ -259,7 +281,9 @@ function FluentConfigurator(initial = {}) {
|
|
|
259
281
|
};
|
|
260
282
|
};
|
|
261
283
|
if (initial && typeof initial !== "object") {
|
|
262
|
-
throw new Error(
|
|
284
|
+
throw new Error(
|
|
285
|
+
"The FluentConfigurator was passed a non-object based value as the initial value. This is not allowed."
|
|
286
|
+
);
|
|
263
287
|
}
|
|
264
288
|
return initial ? api2(initial) : api2({});
|
|
265
289
|
}
|
|
@@ -413,8 +437,11 @@ function runtimeExtendsCheck(val, base, narrow = false) {
|
|
|
413
437
|
case "object":
|
|
414
438
|
if (val === null && base === null) {
|
|
415
439
|
return true;
|
|
440
|
+
} else {
|
|
441
|
+
return keys(base).every(
|
|
442
|
+
(i) => runtimeExtendsCheck(val[i], base[i], narrow)
|
|
443
|
+
);
|
|
416
444
|
}
|
|
417
|
-
return keys(base).every((i) => runtimeExtendsCheck(val[i], base[i], narrow));
|
|
418
445
|
}
|
|
419
446
|
}
|
|
420
447
|
var ifTypeOf = (val) => ({
|
|
@@ -464,13 +491,6 @@ function isFunction(input) {
|
|
|
464
491
|
return typeof input === "function";
|
|
465
492
|
}
|
|
466
493
|
|
|
467
|
-
// src/utility/runtime/conditions/isLiteral.ts
|
|
468
|
-
function isLiteral(...allowed) {
|
|
469
|
-
return (i) => {
|
|
470
|
-
return !allowed.every((v) => i !== v);
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
|
|
474
494
|
// src/utility/runtime/conditions/isNull.ts
|
|
475
495
|
function isNull(i) {
|
|
476
496
|
return i === null;
|
|
@@ -581,7 +601,9 @@ function isType(t) {
|
|
|
581
601
|
function type(fn) {
|
|
582
602
|
const result = fn(typeApi());
|
|
583
603
|
if (!isType(result)) {
|
|
584
|
-
throw new Error(
|
|
604
|
+
throw new Error(
|
|
605
|
+
`When using type(), the callback passed in returned an invalid type! Value returned was: ${result}`
|
|
606
|
+
);
|
|
585
607
|
}
|
|
586
608
|
return result;
|
|
587
609
|
}
|
|
@@ -590,9 +612,11 @@ function type(fn) {
|
|
|
590
612
|
function withValue(td) {
|
|
591
613
|
return (obj) => {
|
|
592
614
|
const t = type(td);
|
|
593
|
-
return Object.fromEntries(
|
|
594
|
-
|
|
595
|
-
|
|
615
|
+
return Object.fromEntries(
|
|
616
|
+
[...entries(obj)].filter(([_key, value]) => {
|
|
617
|
+
return t.typeGuard(value);
|
|
618
|
+
})
|
|
619
|
+
);
|
|
596
620
|
};
|
|
597
621
|
}
|
|
598
622
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -609,6 +633,7 @@ function withValue(td) {
|
|
|
609
633
|
condition,
|
|
610
634
|
createFnWithProps,
|
|
611
635
|
createMutationFunction,
|
|
636
|
+
defineProperties,
|
|
612
637
|
defineType,
|
|
613
638
|
dictToKv,
|
|
614
639
|
dictionaryTransform,
|
|
@@ -626,7 +651,6 @@ function withValue(td) {
|
|
|
626
651
|
isBoolean,
|
|
627
652
|
isFalse,
|
|
628
653
|
isFunction,
|
|
629
|
-
isLiteral,
|
|
630
654
|
isNull,
|
|
631
655
|
isNumber,
|
|
632
656
|
isObject,
|
package/dist/index.mjs
CHANGED
|
@@ -93,6 +93,26 @@ function arrayToKeyLookup(...keys2) {
|
|
|
93
93
|
return obj;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
// src/utility/dictionary/defineProperties.ts
|
|
97
|
+
function defineProperties(obj) {
|
|
98
|
+
return {
|
|
99
|
+
ro(prop, errorMsg) {
|
|
100
|
+
Object.defineProperty(obj, prop, {
|
|
101
|
+
writable: false,
|
|
102
|
+
set(v) {
|
|
103
|
+
const message = errorMsg ? errorMsg(prop, v) : `The ${String(
|
|
104
|
+
prop
|
|
105
|
+
)} is readonly but an attempt was made to change it's value to "${JSON.stringify(
|
|
106
|
+
v
|
|
107
|
+
)}"!`;
|
|
108
|
+
throw new Error(message);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
return obj;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
96
116
|
// src/utility/dictionary/dictionaryTransform.ts
|
|
97
117
|
function dictionaryTransform(input, transform) {
|
|
98
118
|
return keys(input).reduce((acc, i) => {
|
|
@@ -115,7 +135,9 @@ function entries(obj) {
|
|
|
115
135
|
|
|
116
136
|
// src/utility/dictionary/mapValues.ts
|
|
117
137
|
function mapValues(obj, valueMapper) {
|
|
118
|
-
return Object.fromEntries(
|
|
138
|
+
return Object.fromEntries(
|
|
139
|
+
[...entries(obj)].map(([k, v]) => [k, valueMapper(v)])
|
|
140
|
+
);
|
|
119
141
|
}
|
|
120
142
|
|
|
121
143
|
// src/utility/dictionary/strArrayToDict.ts
|
|
@@ -178,7 +200,9 @@ function FluentConfigurator(initial = {}) {
|
|
|
178
200
|
};
|
|
179
201
|
};
|
|
180
202
|
if (initial && typeof initial !== "object") {
|
|
181
|
-
throw new Error(
|
|
203
|
+
throw new Error(
|
|
204
|
+
"The FluentConfigurator was passed a non-object based value as the initial value. This is not allowed."
|
|
205
|
+
);
|
|
182
206
|
}
|
|
183
207
|
return initial ? api2(initial) : api2({});
|
|
184
208
|
}
|
|
@@ -332,8 +356,11 @@ function runtimeExtendsCheck(val, base, narrow = false) {
|
|
|
332
356
|
case "object":
|
|
333
357
|
if (val === null && base === null) {
|
|
334
358
|
return true;
|
|
359
|
+
} else {
|
|
360
|
+
return keys(base).every(
|
|
361
|
+
(i) => runtimeExtendsCheck(val[i], base[i], narrow)
|
|
362
|
+
);
|
|
335
363
|
}
|
|
336
|
-
return keys(base).every((i) => runtimeExtendsCheck(val[i], base[i], narrow));
|
|
337
364
|
}
|
|
338
365
|
}
|
|
339
366
|
var ifTypeOf = (val) => ({
|
|
@@ -383,13 +410,6 @@ function isFunction(input) {
|
|
|
383
410
|
return typeof input === "function";
|
|
384
411
|
}
|
|
385
412
|
|
|
386
|
-
// src/utility/runtime/conditions/isLiteral.ts
|
|
387
|
-
function isLiteral(...allowed) {
|
|
388
|
-
return (i) => {
|
|
389
|
-
return !allowed.every((v) => i !== v);
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
|
|
393
413
|
// src/utility/runtime/conditions/isNull.ts
|
|
394
414
|
function isNull(i) {
|
|
395
415
|
return i === null;
|
|
@@ -500,7 +520,9 @@ function isType(t) {
|
|
|
500
520
|
function type(fn) {
|
|
501
521
|
const result = fn(typeApi());
|
|
502
522
|
if (!isType(result)) {
|
|
503
|
-
throw new Error(
|
|
523
|
+
throw new Error(
|
|
524
|
+
`When using type(), the callback passed in returned an invalid type! Value returned was: ${result}`
|
|
525
|
+
);
|
|
504
526
|
}
|
|
505
527
|
return result;
|
|
506
528
|
}
|
|
@@ -509,9 +531,11 @@ function type(fn) {
|
|
|
509
531
|
function withValue(td) {
|
|
510
532
|
return (obj) => {
|
|
511
533
|
const t = type(td);
|
|
512
|
-
return Object.fromEntries(
|
|
513
|
-
|
|
514
|
-
|
|
534
|
+
return Object.fromEntries(
|
|
535
|
+
[...entries(obj)].filter(([_key, value]) => {
|
|
536
|
+
return t.typeGuard(value);
|
|
537
|
+
})
|
|
538
|
+
);
|
|
515
539
|
};
|
|
516
540
|
}
|
|
517
541
|
export {
|
|
@@ -527,6 +551,7 @@ export {
|
|
|
527
551
|
condition,
|
|
528
552
|
createFnWithProps,
|
|
529
553
|
createMutationFunction,
|
|
554
|
+
defineProperties,
|
|
530
555
|
defineType,
|
|
531
556
|
dictToKv,
|
|
532
557
|
dictionaryTransform,
|
|
@@ -544,7 +569,6 @@ export {
|
|
|
544
569
|
isBoolean,
|
|
545
570
|
isFalse,
|
|
546
571
|
isFunction,
|
|
547
|
-
isLiteral,
|
|
548
572
|
isNull,
|
|
549
573
|
isNumber,
|
|
550
574
|
isObject,
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inferred-types",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.5",
|
|
4
4
|
"description": "Functions which provide useful type inference on TS projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ken Snyder<ken@ken.net>",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"module": "dist/index.mjs",
|
|
9
9
|
"typings": "dist/index.d.ts",
|
|
10
|
+
"repository": {
|
|
11
|
+
"url": "https://github.com/inocan-group/inferred-types"
|
|
12
|
+
},
|
|
10
13
|
"sideEffects": false,
|
|
11
14
|
"scripts": {
|
|
12
15
|
"about": "tokei src",
|
|
@@ -29,29 +32,30 @@
|
|
|
29
32
|
},
|
|
30
33
|
"devDependencies": {
|
|
31
34
|
"@type-challenges/utils": "~0.1.1",
|
|
32
|
-
"@types/node": "
|
|
33
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
34
|
-
"@typescript-eslint/parser": "^5.
|
|
35
|
+
"@types/node": "16",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^5.40.1",
|
|
37
|
+
"@typescript-eslint/parser": "^5.40.1",
|
|
35
38
|
"bumpp": "^8.2.1",
|
|
36
|
-
"common-types": "^1.
|
|
39
|
+
"common-types": "^1.31.1",
|
|
37
40
|
"cross-env": "^7.0.3",
|
|
38
|
-
"dd": "^0.
|
|
39
|
-
"dotenv": "^16.0.
|
|
40
|
-
"eslint": "^8.
|
|
41
|
+
"dd": "^0.24.0",
|
|
42
|
+
"dotenv": "^16.0.3",
|
|
43
|
+
"eslint": "^8.25.0",
|
|
41
44
|
"eslint-config-prettier": "^8.5.0",
|
|
42
45
|
"eslint-plugin-import": "^2.26.0",
|
|
43
46
|
"eslint-plugin-prettier": "^4.2.1",
|
|
44
|
-
"eslint-plugin-promise": "^6.
|
|
47
|
+
"eslint-plugin-promise": "^6.1.0",
|
|
45
48
|
"npm-run-all": "~4.1.5",
|
|
46
49
|
"prettier": "~2.7.1",
|
|
47
50
|
"rimraf": "^3.0.2",
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
51
|
+
"sharp": "^0.31.1",
|
|
52
|
+
"tsup": "^6.3.0",
|
|
53
|
+
"typescript": "^4.8.4",
|
|
54
|
+
"vite": "^3.1.8",
|
|
55
|
+
"vitest": "^0.24.3"
|
|
52
56
|
},
|
|
53
57
|
"dependencies": {
|
|
54
|
-
"
|
|
58
|
+
"brilliant-errors": "^0.6.0"
|
|
55
59
|
},
|
|
56
60
|
"pnpm": {
|
|
57
61
|
"overrides": {
|
package/src/Mutation/index.ts
CHANGED
|
@@ -1,37 +1,14 @@
|
|
|
1
1
|
// #autoindex
|
|
2
2
|
|
|
3
|
-
// #region
|
|
4
|
-
// index last changed at:
|
|
5
|
-
// hash-code:
|
|
3
|
+
// #region auto-indexed files
|
|
4
|
+
// index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
|
|
5
|
+
// hash-code: bd3a442e
|
|
6
6
|
|
|
7
7
|
// file exports
|
|
8
8
|
export * from "./MutationFunction";
|
|
9
9
|
export * from "./MutationIdentity";
|
|
10
10
|
|
|
11
|
-
// #endregion
|
|
11
|
+
// #endregion auto-indexed files
|
|
12
12
|
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
// By default it assumes that exports are named exports but this can be changed by
|
|
17
|
-
// adding a modifier to the '// #autoindex' syntax:
|
|
18
|
-
//
|
|
19
|
-
// - autoindex:named same as default, exports "named symbols"
|
|
20
|
-
// - autoindex:default assumes each file is exporting a default export and
|
|
21
|
-
// converts the default export to the name of the file
|
|
22
|
-
// - autoindex:offset assumes files export "named symbols" but that each
|
|
23
|
-
// file's symbols should be offset by the file's name
|
|
24
|
-
//
|
|
25
|
-
// You may also exclude certain files or directories by adding it to the
|
|
26
|
-
// autoindex command. As an example:
|
|
27
|
-
//
|
|
28
|
-
// - autoindex:named, exclude: foo,bar,baz
|
|
29
|
-
//
|
|
30
|
-
// Inversely, if you state a file to be an "orphan" then autoindex files
|
|
31
|
-
// below this file will not reference this autoindex file:
|
|
32
|
-
//
|
|
33
|
-
// - autoindex:named, orphan
|
|
34
|
-
//
|
|
35
|
-
// All content outside the "// #region" section in this file will be
|
|
36
|
-
// preserved in situations where you need to do something paricularly awesome.
|
|
37
|
-
// Keep on being awesome.
|
|
13
|
+
// see https://github.com/inocan-group/do-devops/docs/autoindex.md
|
|
14
|
+
// for more info
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// #autoindex
|
|
2
2
|
|
|
3
|
-
// #region
|
|
4
|
-
// index last changed at:
|
|
5
|
-
// hash-code:
|
|
3
|
+
// #region auto-indexed files
|
|
4
|
+
// index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
|
|
5
|
+
// hash-code: 5ddbbf55
|
|
6
6
|
|
|
7
7
|
// directory exports
|
|
8
8
|
export * from "./Mutation/index";
|
|
@@ -10,30 +10,7 @@ export * from "./shared/index";
|
|
|
10
10
|
export * from "./types/index";
|
|
11
11
|
export * from "./utility/index";
|
|
12
12
|
|
|
13
|
-
// #endregion
|
|
13
|
+
// #endregion auto-indexed files
|
|
14
14
|
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
// By default it assumes that exports are named exports but this can be changed by
|
|
19
|
-
// adding a modifier to the '// #autoindex' syntax:
|
|
20
|
-
//
|
|
21
|
-
// - autoindex:named same as default, exports "named symbols"
|
|
22
|
-
// - autoindex:default assumes each file is exporting a default export and
|
|
23
|
-
// converts the default export to the name of the file
|
|
24
|
-
// - autoindex:offset assumes files export "named symbols" but that each
|
|
25
|
-
// file's symbols should be offset by the file's name
|
|
26
|
-
//
|
|
27
|
-
// You may also exclude certain files or directories by adding it to the
|
|
28
|
-
// autoindex command. As an example:
|
|
29
|
-
//
|
|
30
|
-
// - autoindex:named, exclude: foo,bar,baz
|
|
31
|
-
//
|
|
32
|
-
// Inversely, if you state a file to be an "orphan" then autoindex files
|
|
33
|
-
// below this file will not reference this autoindex file:
|
|
34
|
-
//
|
|
35
|
-
// - autoindex:named, orphan
|
|
36
|
-
//
|
|
37
|
-
// All content outside the "// #region" section in this file will be
|
|
38
|
-
// preserved in situations where you need to do something paricularly awesome.
|
|
39
|
-
// Keep on being awesome.
|
|
15
|
+
// see https://github.com/inocan-group/do-devops/docs/autoindex.md
|
|
16
|
+
// for more info
|
package/src/shared/index.ts
CHANGED
|
@@ -1,38 +1,15 @@
|
|
|
1
1
|
// #autoindex: orphan
|
|
2
2
|
|
|
3
|
-
// #region
|
|
4
|
-
// index last changed at:
|
|
5
|
-
// hash-code:
|
|
3
|
+
// #region auto-indexed files
|
|
4
|
+
// index last changed at: 8th Aug, 2022, 09:51 AM ( GMT-7 )
|
|
5
|
+
// hash-code: 3305143b
|
|
6
6
|
|
|
7
7
|
// file exports
|
|
8
8
|
export * from "./randomString";
|
|
9
9
|
export * from "./uuid";
|
|
10
10
|
export * from "./valueTypes";
|
|
11
11
|
|
|
12
|
-
// #endregion
|
|
12
|
+
// #endregion auto-indexed files
|
|
13
13
|
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
// By default it assumes that exports are named exports but this can be changed by
|
|
18
|
-
// adding a modifier to the '// #autoindex' syntax:
|
|
19
|
-
//
|
|
20
|
-
// - autoindex:named same as default, exports "named symbols"
|
|
21
|
-
// - autoindex:default assumes each file is exporting a default export and
|
|
22
|
-
// converts the default export to the name of the file
|
|
23
|
-
// - autoindex:offset assumes files export "named symbols" but that each
|
|
24
|
-
// file's symbols should be offset by the file's name
|
|
25
|
-
//
|
|
26
|
-
// You may also exclude certain files or directories by adding it to the
|
|
27
|
-
// autoindex command. As an example:
|
|
28
|
-
//
|
|
29
|
-
// - autoindex:named, exclude: foo,bar,baz
|
|
30
|
-
//
|
|
31
|
-
// Inversely, if you state a file to be an "orphan" then autoindex files
|
|
32
|
-
// below this file will not reference this autoindex file:
|
|
33
|
-
//
|
|
34
|
-
// - autoindex:named, orphan
|
|
35
|
-
//
|
|
36
|
-
// All content outside the "// #region" section in this file will be
|
|
37
|
-
// preserved in situations where you need to do something paricularly awesome.
|
|
38
|
-
// Keep on being awesome.
|
|
14
|
+
// see https://github.com/inocan-group/do-devops/docs/autoindex.md
|
|
15
|
+
// for more info
|
package/src/types/Keys.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
2
|
* A Utility class that provides the same functionality as the built-in
|
|
3
3
|
* `keyof` TS operator but can also:
|
|
4
|
-
*
|
|
4
|
+
*
|
|
5
5
|
* - receive an array of strings and convert that into a union type.
|
|
6
6
|
* - you can exclude literal string from the returned result
|
|
7
|
-
*
|
|
7
|
+
*
|
|
8
8
|
* ```ts
|
|
9
9
|
* const t1 = { foo: 1, bar: 2 };
|
|
10
10
|
* // "foo" | "bar"
|
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
export type Keys<
|
|
18
18
|
T extends Record<string, any> | readonly string[],
|
|
19
19
|
W extends string | undefined = undefined
|
|
20
|
-
|
|
21
|
-
? W extends string
|
|
22
|
-
|
|
20
|
+
> = T extends readonly string[]
|
|
21
|
+
? W extends string
|
|
22
|
+
? Exclude<T[number], W>
|
|
23
|
+
: T[number]
|
|
24
|
+
: W extends string
|
|
25
|
+
? Exclude<keyof T & string, W>
|
|
26
|
+
: keyof T & string;
|