type-fns 1.16.0 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * ref:
3
+ * - https://stackoverflow.com/a/67655609/3068233
4
+ * - https://stackoverflow.com/a/73409753/3068233
5
+ */
6
+ type BuildArrayWith<TCheck extends 'len' | 'min', // todo: support 'max' too?
7
+ TLength extends number, TType, TCurrent extends TType[]> = TCurrent['length'] extends TLength ? TCheck extends 'len' ? [...TCurrent] : [...TCurrent, ...TType[]] : BuildArrayWith<TCheck, TLength, TType, [...TCurrent, TType]>;
8
+ /**
9
+ * declares a type of array with a check on its length
10
+ */
11
+ type ArrayWith<TCheck extends 'len' | 'min', // todo: support 'max' too?
12
+ TLength extends number, TType> = BuildArrayWith<TCheck, TLength, TType, []>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=ArrayWith.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArrayWith.js","sourceRoot":"","sources":["../../src/types/ArrayWith.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const test_fns_1 = require("test-fns");
4
+ describe('ArrayWith', () => {
5
+ (0, test_fns_1.given)('desire for array with min length', () => {
6
+ (0, test_fns_1.then)('we can declare the type', () => {
7
+ let products;
8
+ });
9
+ (0, test_fns_1.then)('it allows arrays of exactly the min length to it', () => {
10
+ const products = ['doughnut']; // 🍩
11
+ });
12
+ (0, test_fns_1.then)('it allows arrays with more than the min length to it', () => {
13
+ const products = ['doughnut', 'waffle']; // 🍩, 🧇
14
+ });
15
+ (0, test_fns_1.then)('it blocks arrays with less than the min length to it', () => {
16
+ // @ts-expect-error; Type '[]' is not assignable to type '[string, ...string[]]'. Source has 0 element(s) but target requires 1.ts(2322)
17
+ const products = []; // 🍩, 🧇
18
+ });
19
+ });
20
+ (0, test_fns_1.given)('desire for array with exact length', () => {
21
+ (0, test_fns_1.then)('we can declare the type', () => {
22
+ let products;
23
+ });
24
+ (0, test_fns_1.then)('it allows arrays of exactly the desired length to it', () => {
25
+ const products = ['doughnut']; // 🍩
26
+ });
27
+ (0, test_fns_1.then)('it allows arrays with more than the desired length to it', () => {
28
+ // @ts-expect-error; Type '[string, string]' is not assignable to type '[string]'.Source has 2 element(s) but target allows only 1.
29
+ const products = ['doughnut', 'waffle']; // 🍩, 🧇
30
+ });
31
+ (0, test_fns_1.then)('it blocks arrays with less than the desired length to it', () => {
32
+ // @ts-expect-error; Type '[]' is not assignable to type '[string]'. Source has 0 element(s) but target requires 1.ts(2322)
33
+ const products = [];
34
+ });
35
+ });
36
+ });
37
+ //# sourceMappingURL=ArrayWith.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArrayWith.test.js","sourceRoot":"","sources":["../../src/types/ArrayWith.test.ts"],"names":[],"mappings":";;AAAA,uCAA6C;AAE7C,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,IAAA,gBAAK,EAAC,kCAAkC,EAAE,GAAG,EAAE;QAC7C,IAAA,eAAI,EAAC,yBAAyB,EAAE,GAAG,EAAE;YACnC,IAAI,QAAqC,CAAC;QAC5C,CAAC,CAAC,CAAC;QACH,IAAA,eAAI,EAAC,kDAAkD,EAAE,GAAG,EAAE;YAC5D,MAAM,QAAQ,GAAgC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK;QACnE,CAAC,CAAC,CAAC;QACH,IAAA,eAAI,EAAC,sDAAsD,EAAE,GAAG,EAAE;YAChE,MAAM,QAAQ,GAAgC,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS;QACjF,CAAC,CAAC,CAAC;QACH,IAAA,eAAI,EAAC,sDAAsD,EAAE,GAAG,EAAE;YAChE,wIAAwI;YACxI,MAAM,QAAQ,GAAgC,EAAE,CAAC,CAAC,SAAS;QAC7D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,IAAA,gBAAK,EAAC,oCAAoC,EAAE,GAAG,EAAE;QAC/C,IAAA,eAAI,EAAC,yBAAyB,EAAE,GAAG,EAAE;YACnC,IAAI,QAAqC,CAAC;QAC5C,CAAC,CAAC,CAAC;QACH,IAAA,eAAI,EAAC,sDAAsD,EAAE,GAAG,EAAE;YAChE,MAAM,QAAQ,GAAgC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK;QACnE,CAAC,CAAC,CAAC;QACH,IAAA,eAAI,EAAC,0DAA0D,EAAE,GAAG,EAAE;YACpE,mIAAmI;YACnI,MAAM,QAAQ,GAAgC,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS;QACjF,CAAC,CAAC,CAAC;QACH,IAAA,eAAI,EAAC,0DAA0D,EAAE,GAAG,EAAE;YACpE,2HAA2H;YAC3H,MAAM,QAAQ,GAAgC,EAAE,CAAC;QACnD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -3,5 +3,6 @@ export declare enum Stage {
3
3
  DEVELOPMENT = "dev",
4
4
  TEST = "test"
5
5
  }
6
- export declare const stage: string;
6
+ export declare const isOfStage: import("type-fns").AssessWithAssure<string | number | symbol, Stage>;
7
+ export declare const stage: Stage;
7
8
  export declare const serviceClientStage: Stage;
@@ -1,12 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.serviceClientStage = exports.stage = exports.Stage = void 0;
3
+ exports.serviceClientStage = exports.stage = exports.isOfStage = exports.Stage = void 0;
4
+ const error_fns_1 = require("@ehmpathy/error-fns");
5
+ const type_fns_1 = require("type-fns");
4
6
  var Stage;
5
7
  (function (Stage) {
6
8
  Stage["PRODUCTION"] = "prod";
7
9
  Stage["DEVELOPMENT"] = "dev";
8
10
  Stage["TEST"] = "test";
9
11
  })(Stage || (exports.Stage = Stage = {}));
12
+ exports.isOfStage = (0, type_fns_1.createIsOfEnum)(Stage);
13
+ /**
14
+ * verify that the server is on UTC timezone
15
+ *
16
+ * why?
17
+ * - non UTC timezone usage causes problems and takes a while to track down
18
+ * - by failing fast if the server our code runs in is not in UTC, we avoid these issues
19
+ * =>
20
+ * - create a pit of success
21
+ */
22
+ const TIMEZONE = process.env.TZ;
23
+ if (TIMEZONE !== 'UTC')
24
+ throw new error_fns_1.UnexpectedCodePathError('env.TZ is not set to UTC. this can cause issues. please set the env var', { found: TIMEZONE, desire: 'UTC' });
10
25
  /**
11
26
  * this allows us to infer what the stage should be in environments that do not have STAGE specified
12
27
  * - e.g., when running locally
@@ -32,6 +47,8 @@ const getEnvironment = () => {
32
47
  const stage = (_a = process.env.STAGE) !== null && _a !== void 0 ? _a : inferStageFromNodeEnv(); // figure it out from NODE_ENV if not explicitly defined
33
48
  if (!stage)
34
49
  throw new Error('process.env.STAGE must be defined');
50
+ if (!(0, exports.isOfStage)(stage))
51
+ throw new Error(`invalid stage defined '${stage}'`);
35
52
  return { stage };
36
53
  };
37
54
  // export stage immediately, since it does not change
@@ -1 +1 @@
1
- {"version":3,"file":"environment.js","sourceRoot":"","sources":["../../src/utils/environment.ts"],"names":[],"mappings":";;;AAAA,IAAY,KAIX;AAJD,WAAY,KAAK;IACf,4BAAmB,CAAA;IACnB,4BAAmB,CAAA;IACnB,sBAAa,CAAA;AACf,CAAC,EAJW,KAAK,qBAAL,KAAK,QAIhB;AAED;;;;GAIG;AACH,MAAM,qBAAqB,GAAG,GAAG,EAAE;IACjC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,iCAAiC;IACvE,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IACtE,IAAI,OAAO,KAAK,YAAY;QAAE,OAAO,KAAK,CAAC,UAAU,CAAC;IACtD,IAAI,OAAO,KAAK,aAAa;QAAE,OAAO,KAAK,CAAC,WAAW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,EAAE;IACjC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,iCAAiC;IACvE,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IACtE,IAAI,OAAO,KAAK,YAAY;QAAE,OAAO,KAAK,CAAC,UAAU,CAAC;IACtD,IAAI,OAAO,KAAK,aAAa;QAAE,OAAO,KAAK,CAAC,WAAW,CAAC;IACxD,IAAI,OAAO,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC;IAC1C,MAAM,IAAI,KAAK,CAAC,uBAAuB,OAAO,GAAG,CAAC,CAAC;AACrD,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,cAAc,GAAG,GAAG,EAAE;;IAC1B,MAAM,KAAK,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,KAAK,mCAAI,qBAAqB,EAAE,CAAC,CAAC,wDAAwD;IACpH,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACjE,IAAI,CAAC,IAAA,iBAAS,EAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,KAAK,GAAG,CAAC,CAAC;IAC3E,OAAO,EAAE,KAAK,EAAE,CAAC;AACnB,CAAC,CAAC;AAEF,qDAAqD;AACtC,aAAK,GAAK,cAAc,EAAE,OAAC;AAE1C,8BAA8B;AACjB,QAAA,kBAAkB,GAC7B,aAAK,KAAK,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,8CAA8C"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "type-fns",
3
3
  "author": "ehmpathy",
4
4
  "description": "A set of types, type checks, and type guards for simpler, safer, and easier to read code.",
5
- "version": "1.16.0",
5
+ "version": "1.18.0",
6
6
  "repository": "ehmpathy/type-fns",
7
7
  "homepage": "https://github.com/ehmpathy/type-fns",
8
8
  "keywords": [
@@ -16,6 +16,7 @@
16
16
  "typescript"
17
17
  ],
18
18
  "bugs": "https://github.com/ehmpathy/type-fns/issues",
19
+ "license": "MIT",
19
20
  "main": "dist/index.js",
20
21
  "engines": {
21
22
  "node": ">=8.0.0"
@@ -34,25 +35,31 @@
34
35
  "build": "npm run build:clean && npm run build:compile",
35
36
  "test:commits": "LAST_TAG=$(git describe --tags --abbrev=0 @^ 2> /dev/null || git rev-list --max-parents=0 HEAD) && npx commitlint --from $LAST_TAG --to HEAD --verbose",
36
37
  "test:types": "tsc -p ./tsconfig.build.json --noEmit",
37
- "prepublish": "npm run build",
38
38
  "test:format:prettier": "prettier --parser typescript --check 'src/**/*.ts' --config ./prettier.config.js",
39
39
  "test:format": "npm run test:format:prettier",
40
40
  "test:lint:deps": "npx depcheck -c ./depcheckrc.yml",
41
41
  "test:lint:eslint": "eslint -c ./.eslintrc.js src/**/*.ts",
42
42
  "test:lint": "npm run test:lint:eslint && npm run test:lint:deps",
43
- "test:unit": "jest -c ./jest.unit.config.ts --forceExit --verbose --passWithNoTests",
44
- "test:integration": "jest -c ./jest.integration.config.ts --forceExit --verbose --passWithNoTests",
43
+ "test:unit": "jest -c ./jest.unit.config.ts --forceExit --verbose --passWithNoTests $([ -z $THOROUGH ] && echo '--changedSince=main')",
44
+ "test:integration": "jest -c ./jest.integration.config.ts --forceExit --verbose --passWithNoTests $([ -z $THOROUGH ] && echo '--changedSince=main')",
45
45
  "test:acceptance:locally": "npm run build && LOCALLY=true jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests",
46
46
  "test": "npm run test:commits && npm run test:types && npm run test:format && npm run test:lint && npm run test:unit && npm run test:integration && npm run test:acceptance:locally",
47
47
  "test:acceptance": "npm run build && jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests",
48
48
  "prepush": "npm run test && npm run build",
49
+ "prepublish": "npm run build",
49
50
  "preversion": "npm run prepush",
50
- "postversion": "git push origin HEAD --tags --no-verify"
51
+ "postversion": "git push origin HEAD --tags --no-verify",
52
+ "postinstall": "[ -d .git ] && npx husky install || exit 0"
53
+ },
54
+ "dependencies": {
55
+ "@ehmpathy/error-fns": "1.0.2",
56
+ "type-fns": "1.16.0",
57
+ "uuid": "9.0.0"
51
58
  },
52
59
  "devDependencies": {
53
- "@commitlint/cli": "13.1.0",
60
+ "@commitlint/cli": "19.3.0",
54
61
  "@commitlint/config-conventional": "13.1.0",
55
- "@trivago/prettier-plugin-sort-imports": "2.0.4",
62
+ "@trivago/prettier-plugin-sort-imports": "4.3.0",
56
63
  "@tsconfig/node-lts-strictest": "18.12.1",
57
64
  "@types/jest": "29.2.4",
58
65
  "@types/uuid": "9.0.0",
@@ -60,19 +67,19 @@
60
67
  "@typescript-eslint/parser": "7.8.0",
61
68
  "core-js": "3.26.1",
62
69
  "cz-conventional-changelog": "3.3.0",
63
- "declapract": "0.11.2",
64
- "declapract-typescript-ehmpathy": "0.23.7",
70
+ "declapract": "0.11.5",
71
+ "declapract-typescript-ehmpathy": "0.33.6",
65
72
  "depcheck": "1.4.3",
66
73
  "eslint": "8.56.0",
67
74
  "eslint-config-airbnb-typescript": "18.0.0",
68
75
  "eslint-config-prettier": "8.5.0",
69
76
  "eslint-plugin-import": "2.26.0",
70
77
  "eslint-plugin-prettier": "4.2.1",
71
- "husky": "7.0.2",
78
+ "husky": "8.0.3",
72
79
  "jest": "29.3.1",
73
80
  "prettier": "2.8.1",
74
81
  "test-fns": "1.3.0",
75
- "ts-jest": "29.0.3",
82
+ "ts-jest": "29.1.3",
76
83
  "ts-node": "10.9.2",
77
84
  "typescript": "5.4.5",
78
85
  "uuid": "^3.3.3"
@@ -81,8 +88,5 @@
81
88
  "commitizen": {
82
89
  "path": "./node_modules/cz-conventional-changelog"
83
90
  }
84
- },
85
- "dependencies": {
86
- "@ehmpathy/error-fns": "1.0.2"
87
91
  }
88
92
  }
@@ -1,9 +0,0 @@
1
- /**
2
- * UnexpectedCodePath errors are used to indicate that we've reached a code path that should never have been reached
3
- *
4
- * Purpose of having a dedicated class for this type of error is to allow us to easily add metadata about what was going on when we reached this code path
5
- * - e.g., the variables in memory at the time
6
- */
7
- export declare class UnexpectedCodePathError extends Error {
8
- constructor(message: string, metadata?: Record<string, any>);
9
- }
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnexpectedCodePathError = void 0;
4
- /**
5
- * UnexpectedCodePath errors are used to indicate that we've reached a code path that should never have been reached
6
- *
7
- * Purpose of having a dedicated class for this type of error is to allow us to easily add metadata about what was going on when we reached this code path
8
- * - e.g., the variables in memory at the time
9
- */
10
- class UnexpectedCodePathError extends Error {
11
- constructor(message, metadata) {
12
- const fullMessage = `UnexpectedCodePath: ${message}${metadata ? `\n\n${JSON.stringify(metadata)}` : ''}}`;
13
- super(fullMessage);
14
- }
15
- }
16
- exports.UnexpectedCodePathError = UnexpectedCodePathError;
17
- //# sourceMappingURL=UnexpectedCodePathError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UnexpectedCodePathError.js","sourceRoot":"","sources":["../../../src/utils/errors/UnexpectedCodePathError.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,MAAa,uBAAwB,SAAQ,KAAK;IAChD,YAAY,OAAe,EAAE,QAA8B;QACzD,MAAM,WAAW,GAAG,uBAAuB,OAAO,GAChD,QAAQ,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EACjD,GAAG,CAAC;QACJ,KAAK,CAAC,WAAW,CAAC,CAAC;IACrB,CAAC;CACF;AAPD,0DAOC"}