@squiz/dx-common-lib 1.2.1-alpha.99 → 1.2.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.
Files changed (116) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/lib/assertions/assertAssignWithDefaultUndefinedValue.d.ts +1 -0
  3. package/lib/assertions/assertAssignWithDefaultUndefinedValue.js +3 -1
  4. package/lib/assertions/assertAssignWithDefaultUndefinedValue.js.map +1 -1
  5. package/lib/assertions/assertIsBoolean.d.ts +1 -0
  6. package/lib/assertions/assertIsBoolean.js +12 -0
  7. package/lib/assertions/assertIsBoolean.js.map +1 -0
  8. package/lib/assertions/assertIsBoolean.spec.d.ts +1 -0
  9. package/lib/assertions/assertIsBoolean.spec.js +16 -0
  10. package/lib/assertions/assertIsBoolean.spec.js.map +1 -0
  11. package/lib/assertions/assertIsEnumValue.d.ts +1 -0
  12. package/lib/assertions/assertIsEnumValue.js +18 -0
  13. package/lib/assertions/assertIsEnumValue.js.map +1 -0
  14. package/lib/assertions/assertIsEnumValue.spec.d.ts +1 -0
  15. package/lib/assertions/assertIsEnumValue.spec.js +39 -0
  16. package/lib/assertions/assertIsEnumValue.spec.js.map +1 -0
  17. package/lib/assertions/index.d.ts +9 -0
  18. package/lib/assertions/index.js +28 -0
  19. package/lib/assertions/index.js.map +1 -0
  20. package/lib/error/BadRequestError.d.ts +4 -0
  21. package/lib/error/BadRequestError.js +11 -0
  22. package/lib/error/BadRequestError.js.map +1 -0
  23. package/lib/error/ErrorWithHttpStatusCode.d.ts +5 -0
  24. package/lib/error/ErrorWithHttpStatusCode.js +12 -0
  25. package/lib/error/ErrorWithHttpStatusCode.js.map +1 -0
  26. package/lib/error/InternalServerError.d.ts +4 -0
  27. package/lib/error/InternalServerError.js +11 -0
  28. package/lib/error/InternalServerError.js.map +1 -0
  29. package/lib/error/MethodNotImplementedError.d.ts +4 -0
  30. package/lib/error/MethodNotImplementedError.js +11 -0
  31. package/lib/error/MethodNotImplementedError.js.map +1 -0
  32. package/lib/error/ResourceNotFoundError.d.ts +4 -0
  33. package/lib/error/ResourceNotFoundError.js +11 -0
  34. package/lib/error/ResourceNotFoundError.js.map +1 -0
  35. package/lib/error/TimeoutError.d.ts +5 -0
  36. package/lib/error/TimeoutError.js +12 -0
  37. package/lib/error/TimeoutError.js.map +1 -0
  38. package/lib/error/index.d.ts +6 -0
  39. package/lib/error/index.js +23 -0
  40. package/lib/error/index.js.map +1 -0
  41. package/lib/index.d.ts +4 -7
  42. package/lib/index.js +4 -9
  43. package/lib/index.js.map +1 -1
  44. package/lib/util/getNodeEnv.d.ts +1 -0
  45. package/lib/util/getNodeEnv.js +14 -0
  46. package/lib/util/getNodeEnv.js.map +1 -0
  47. package/lib/util/getNodeEnv.spec.d.ts +1 -0
  48. package/lib/util/getNodeEnv.spec.js +22 -0
  49. package/lib/util/getNodeEnv.spec.js.map +1 -0
  50. package/lib/util/getPageInfo.d.ts +9 -0
  51. package/lib/util/getPageInfo.js +18 -0
  52. package/lib/util/getPageInfo.js.map +1 -0
  53. package/lib/util/index.d.ts +7 -0
  54. package/lib/util/index.js +18 -0
  55. package/lib/util/index.js.map +1 -0
  56. package/lib/util/isPathTryingToAccessOutsideOfRoot.d.ts +1 -0
  57. package/lib/util/isPathTryingToAccessOutsideOfRoot.js +14 -0
  58. package/lib/util/isPathTryingToAccessOutsideOfRoot.js.map +1 -0
  59. package/lib/util/isPathTryingToAccessOutsideOfRoot.spec.d.ts +1 -0
  60. package/lib/util/isPathTryingToAccessOutsideOfRoot.spec.js +25 -0
  61. package/lib/util/isPathTryingToAccessOutsideOfRoot.spec.js.map +1 -0
  62. package/lib/util/isReadable.d.ts +1 -0
  63. package/lib/util/isReadable.js +20 -0
  64. package/lib/util/isReadable.js.map +1 -0
  65. package/lib/util/joinAbsoluteUrlPath.d.ts +1 -0
  66. package/lib/util/joinAbsoluteUrlPath.js +26 -0
  67. package/lib/util/joinAbsoluteUrlPath.js.map +1 -0
  68. package/lib/util/joinAbsoluteUrlPath.spec.d.ts +1 -0
  69. package/lib/util/joinAbsoluteUrlPath.spec.js +43 -0
  70. package/lib/util/joinAbsoluteUrlPath.spec.js.map +1 -0
  71. package/lib/util/never.d.ts +1 -0
  72. package/lib/util/never.js +9 -0
  73. package/lib/util/never.js.map +1 -0
  74. package/lib/util/parseEnvVarForVar.d.ts +1 -0
  75. package/lib/util/parseEnvVarForVar.js +15 -0
  76. package/lib/util/parseEnvVarForVar.js.map +1 -0
  77. package/lib/util/parseEnvVarForVar.spec.d.ts +1 -0
  78. package/lib/util/parseEnvVarForVar.spec.js +20 -0
  79. package/lib/util/parseEnvVarForVar.spec.js.map +1 -0
  80. package/lib/zip/zipDirectory.d.ts +1 -0
  81. package/lib/zip/zipDirectory.js +32 -0
  82. package/lib/zip/zipDirectory.js.map +1 -0
  83. package/lib/zip/zipDirectory.spec.d.ts +1 -0
  84. package/lib/zip/zipDirectory.spec.js +25 -0
  85. package/lib/zip/zipDirectory.spec.js.map +1 -0
  86. package/package.json +13 -7
  87. package/src/assertions/assertAssignWithDefaultUndefinedValue.ts +5 -0
  88. package/src/assertions/assertIsBoolean.spec.ts +16 -0
  89. package/src/assertions/assertIsBoolean.ts +5 -0
  90. package/src/assertions/assertIsEnumValue.spec.ts +39 -0
  91. package/src/assertions/assertIsEnumValue.ts +15 -0
  92. package/src/assertions/index.ts +12 -0
  93. package/src/error/BadRequestError.ts +7 -0
  94. package/src/error/ErrorWithHttpStatusCode.ts +5 -0
  95. package/src/error/InternalServerError.ts +7 -0
  96. package/src/error/MethodNotImplementedError.ts +7 -0
  97. package/src/error/ResourceNotFoundError.ts +7 -0
  98. package/src/error/TimeoutError.ts +8 -0
  99. package/src/error/index.ts +6 -0
  100. package/src/index.ts +4 -10
  101. package/src/util/getNodeEnv.spec.ts +25 -0
  102. package/src/util/getNodeEnv.ts +11 -0
  103. package/src/util/getPageInfo.ts +23 -0
  104. package/src/util/index.ts +7 -0
  105. package/src/util/isPathTryingToAccessOutsideOfRoot.spec.ts +25 -0
  106. package/src/util/isPathTryingToAccessOutsideOfRoot.ts +8 -0
  107. package/src/util/isReadable.ts +12 -0
  108. package/src/util/joinAbsoluteUrlPath.spec.ts +62 -0
  109. package/src/util/joinAbsoluteUrlPath.ts +22 -0
  110. package/src/util/never.ts +4 -0
  111. package/src/util/parseEnvVarForVar.spec.ts +22 -0
  112. package/src/util/parseEnvVarForVar.ts +12 -0
  113. package/src/zip/zipDirectory.spec.ts +24 -0
  114. package/src/zip/zipDirectory.ts +31 -0
  115. package/tsconfig.tsbuildinfo +1 -1
  116. package/jest.integration.config.ts +0 -26
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isPathTryingToAccessOutsideOfRoot = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ function isPathTryingToAccessOutsideOfRoot(rootPath, filePath) {
9
+ const resolvedRoot = path_1.default.resolve(rootPath);
10
+ const joinedPath = path_1.default.join(resolvedRoot, filePath);
11
+ return !joinedPath.includes(resolvedRoot);
12
+ }
13
+ exports.isPathTryingToAccessOutsideOfRoot = isPathTryingToAccessOutsideOfRoot;
14
+ //# sourceMappingURL=isPathTryingToAccessOutsideOfRoot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isPathTryingToAccessOutsideOfRoot.js","sourceRoot":"","sources":["../../src/util/isPathTryingToAccessOutsideOfRoot.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAExB,SAAgB,iCAAiC,CAAC,QAAgB,EAAE,QAAgB;IAClF,MAAM,YAAY,GAAG,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE5C,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IACrD,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;AAC5C,CAAC;AALD,8EAKC"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const isPathTryingToAccessOutsideOfRoot_1 = require("./isPathTryingToAccessOutsideOfRoot");
4
+ describe('isPathTryingToAccessOutsideOfRoot', () => {
5
+ it("should return false if filepath doesn't try to access outside of root", () => {
6
+ expect((0, isPathTryingToAccessOutsideOfRoot_1.isPathTryingToAccessOutsideOfRoot)('my-root/', 'hello')).toEqual(false);
7
+ expect((0, isPathTryingToAccessOutsideOfRoot_1.isPathTryingToAccessOutsideOfRoot)('my-root/', './hello')).toEqual(false);
8
+ expect((0, isPathTryingToAccessOutsideOfRoot_1.isPathTryingToAccessOutsideOfRoot)('my-root/', './hello/../')).toEqual(false);
9
+ });
10
+ it('should resolve a relative root path', () => {
11
+ expect((0, isPathTryingToAccessOutsideOfRoot_1.isPathTryingToAccessOutsideOfRoot)('./my-root/', 'hello')).toEqual(false);
12
+ expect((0, isPathTryingToAccessOutsideOfRoot_1.isPathTryingToAccessOutsideOfRoot)('./my-root/', 'hello/../world')).toEqual(false);
13
+ expect((0, isPathTryingToAccessOutsideOfRoot_1.isPathTryingToAccessOutsideOfRoot)('./my-root/', 'hello/world/..')).toEqual(false);
14
+ expect((0, isPathTryingToAccessOutsideOfRoot_1.isPathTryingToAccessOutsideOfRoot)('./my-root/', './')).toEqual(false);
15
+ expect((0, isPathTryingToAccessOutsideOfRoot_1.isPathTryingToAccessOutsideOfRoot)('./my-root/something', './else')).toEqual(false);
16
+ expect((0, isPathTryingToAccessOutsideOfRoot_1.isPathTryingToAccessOutsideOfRoot)('./my-root/something', './else/1/../../')).toEqual(false);
17
+ });
18
+ it('should return true if filepath does access outside of the root', () => {
19
+ expect((0, isPathTryingToAccessOutsideOfRoot_1.isPathTryingToAccessOutsideOfRoot)('./my-root/', '../')).toEqual(true);
20
+ expect((0, isPathTryingToAccessOutsideOfRoot_1.isPathTryingToAccessOutsideOfRoot)('./my-root/', '../../')).toEqual(true);
21
+ expect((0, isPathTryingToAccessOutsideOfRoot_1.isPathTryingToAccessOutsideOfRoot)('./my-root/', 'hello/../world/../../')).toEqual(true);
22
+ expect((0, isPathTryingToAccessOutsideOfRoot_1.isPathTryingToAccessOutsideOfRoot)('./my-root/', 'hello/../../')).toEqual(true);
23
+ });
24
+ });
25
+ //# sourceMappingURL=isPathTryingToAccessOutsideOfRoot.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isPathTryingToAccessOutsideOfRoot.spec.js","sourceRoot":"","sources":["../../src/util/isPathTryingToAccessOutsideOfRoot.spec.ts"],"names":[],"mappings":";;AAAA,2FAAwF;AAExF,QAAQ,CAAC,mCAAmC,EAAE,GAAG,EAAE;IACjD,EAAE,CAAC,uEAAuE,EAAE,GAAG,EAAE;QAC/E,MAAM,CAAC,IAAA,qEAAiC,EAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC9E,MAAM,CAAC,IAAA,qEAAiC,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAChF,MAAM,CAAC,IAAA,qEAAiC,EAAC,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACtF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC7C,MAAM,CAAC,IAAA,qEAAiC,EAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAChF,MAAM,CAAC,IAAA,qEAAiC,EAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACzF,MAAM,CAAC,IAAA,qEAAiC,EAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACzF,MAAM,CAAC,IAAA,qEAAiC,EAAC,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC7E,MAAM,CAAC,IAAA,qEAAiC,EAAC,qBAAqB,EAAE,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC1F,MAAM,CAAC,IAAA,qEAAiC,EAAC,qBAAqB,EAAE,iBAAiB,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACrG,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gEAAgE,EAAE,GAAG,EAAE;QACxE,MAAM,CAAC,IAAA,qEAAiC,EAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC7E,MAAM,CAAC,IAAA,qEAAiC,EAAC,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAChF,MAAM,CAAC,IAAA,qEAAiC,EAAC,YAAY,EAAE,uBAAuB,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/F,MAAM,CAAC,IAAA,qEAAiC,EAAC,YAAY,EAAE,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACxF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function isReadable(basePath: string, file: string): Promise<boolean>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isReadable = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const fs_1 = require("fs");
10
+ async function isReadable(basePath, file) {
11
+ try {
12
+ await fs_extra_1.default.access(path_1.default.join(basePath, file), fs_1.constants.R_OK);
13
+ return true;
14
+ }
15
+ catch {
16
+ return false;
17
+ }
18
+ }
19
+ exports.isReadable = isReadable;
20
+ //# sourceMappingURL=isReadable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isReadable.js","sourceRoot":"","sources":["../../src/util/isReadable.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,wDAA2B;AAC3B,2BAA+B;AAExB,KAAK,UAAU,UAAU,CAAC,QAAgB,EAAE,IAAY;IAC7D,IAAI;QACF,MAAM,kBAAG,CAAC,MAAM,CAAC,cAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,cAAS,CAAC,IAAI,CAAC,CAAC;QAC5D,OAAO,IAAI,CAAC;KACb;IAAC,MAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAPD,gCAOC"}
@@ -0,0 +1 @@
1
+ export declare function joinAbsoluteUrlPath(...args: string[]): string;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.joinAbsoluteUrlPath = void 0;
4
+ function joinAbsoluteUrlPath(...args) {
5
+ const [rootUrl] = args;
6
+ /**
7
+ * This method takes any form of input string and resolves them to make an absolute url
8
+ * Since these paths are web paths and not file paths, we are creating a URL object (https://nodejs.org/api/url.html). http://example.com has just been used as a dummy entry to create a valid url.
9
+ * Note: path.resolves gives you different output based on the OS node is running on. More reading here https://nodejs.org/api/path.html#windows-vs-posix.
10
+ */
11
+ const url = new URL(getSanitisedString(args), 'http://example.com');
12
+ if (urlIsAbsolute(rootUrl)) {
13
+ return url.toString();
14
+ }
15
+ else {
16
+ return url.pathname.replace(/(^\/|\/$)/g, '');
17
+ }
18
+ }
19
+ exports.joinAbsoluteUrlPath = joinAbsoluteUrlPath;
20
+ function getSanitisedString(subdirs) {
21
+ return subdirs.map((dir) => dir.replace(/(^\.\/+)|(^\/+|\/+$)/g, '')).join('/');
22
+ }
23
+ function urlIsAbsolute(url) {
24
+ return url.match(/^http(s?):\/\//);
25
+ }
26
+ //# sourceMappingURL=joinAbsoluteUrlPath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"joinAbsoluteUrlPath.js","sourceRoot":"","sources":["../../src/util/joinAbsoluteUrlPath.ts"],"names":[],"mappings":";;;AAAA,SAAgB,mBAAmB,CAAC,GAAG,IAAc;IACnD,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IACvB;;;;OAIG;IACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,oBAAoB,CAAC,CAAC;IACpE,IAAI,aAAa,CAAC,OAAO,CAAC,EAAE;QAC1B,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;KACvB;SAAM;QACL,OAAO,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;KAC/C;AACH,CAAC;AAbD,kDAaC;AAED,SAAS,kBAAkB,CAAC,OAAiB;IAC3C,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClF,CAAC;AAED,SAAS,aAAa,CAAC,GAAW;IAChC,OAAO,GAAG,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;AACrC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const joinAbsoluteUrlPath_1 = require("./joinAbsoluteUrlPath");
4
+ describe('joinAbsoluteUrlPath', () => {
5
+ it('should return a valid absolute url for protocol based inputs', () => {
6
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('https://example.com', 'aaa', 'bbb')).toEqual('https://example.com/aaa/bbb');
7
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('https://example.com/', '/aaa', 'bbb')).toEqual('https://example.com/aaa/bbb');
8
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('https://example.com/', '/aaa/', '/bbb///')).toEqual('https://example.com/aaa/bbb');
9
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('https://example.com/', './..///', '/bbb///')).toEqual('https://example.com/bbb');
10
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('https://example.com/', './aaa/', '/bbb/')).toEqual('https://example.com/aaa/bbb');
11
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('https://example.com/', '../aaa/', '/bbb')).toEqual('https://example.com/aaa/bbb');
12
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('https://example.com/', 'ccc', '../aaa/', '/bbb')).toEqual('https://example.com/aaa/bbb');
13
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('https://example.com/', 'ccc', '../../aaa/', '/bbb')).toEqual('https://example.com/aaa/bbb');
14
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('https://example.com/', 'ccc', '/../../aaa/', '/bbb')).toEqual('https://example.com/aaa/bbb');
15
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('https://example.com/', 'ddd', 'eee', 'ccc', '/../../aaa/', '/bbb')).toEqual('https://example.com/ddd/aaa/bbb');
16
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('http://localhost:3000', 'aaa', 'bbb')).toEqual('http://localhost:3000/aaa/bbb');
17
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('http://localhost:3000', '/aaa', 'bbb')).toEqual('http://localhost:3000/aaa/bbb');
18
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('http://localhost:3000', '/aaa/', '/bbb///')).toEqual('http://localhost:3000/aaa/bbb');
19
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('http://localhost:3000', './aaa/', '/bbb/')).toEqual('http://localhost:3000/aaa/bbb');
20
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('http://localhost:3000', '../aaa/', '/bbb')).toEqual('http://localhost:3000/aaa/bbb');
21
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('http://localhost:3000', 'ccc', '../aaa/', '/bbb')).toEqual('http://localhost:3000/aaa/bbb');
22
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('http://localhost:3000', 'ccc', '../../aaa/', '/bbb')).toEqual('http://localhost:3000/aaa/bbb');
23
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('http://localhost:3000', 'ccc', '/../../aaa/', '/bbb')).toEqual('http://localhost:3000/aaa/bbb');
24
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('http://localhost:3000/', 'ddd', 'eee', 'ccc', '/../../aaa/', '/bbb')).toEqual('http://localhost:3000/ddd/aaa/bbb');
25
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('http://localhost:3000/', 'localhost', 'eee', 'ccc', '/../../aaa/', '/bbb')).toEqual('http://localhost:3000/localhost/aaa/bbb');
26
+ });
27
+ it('should return a valid resolved path for inputs', () => {
28
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('aaa', 'bbb')).toEqual('aaa/bbb');
29
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('/aaa', 'bbb')).toEqual('aaa/bbb');
30
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('/aaa/', '/bbb///')).toEqual('aaa/bbb');
31
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('./aaa/', '/bbb/')).toEqual('aaa/bbb');
32
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('../aaa/', '/bbb')).toEqual('aaa/bbb');
33
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('ccc', '../aaa/', '/bbb')).toEqual('aaa/bbb');
34
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('ccc', '../../aaa/', '/bbb')).toEqual('aaa/bbb');
35
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('ccc', '/../../aaa/', '/bbb')).toEqual('aaa/bbb');
36
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('ddd', 'eee', 'ccc', '/../../aaa/', '/bbb')).toEqual('ddd/aaa/bbb');
37
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('http', 'ccc', '/aaa/', '/bbb')).toEqual('http/ccc/aaa/bbb');
38
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('https', 'ccc', '/aaa/', '/bbb')).toEqual('https/ccc/aaa/bbb');
39
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('https', '../ccc', '/aaa/', '/bbb')).toEqual('ccc/aaa/bbb');
40
+ expect((0, joinAbsoluteUrlPath_1.joinAbsoluteUrlPath)('https', './ccc', '/aaa/', '/bbb')).toEqual('https/ccc/aaa/bbb');
41
+ });
42
+ });
43
+ //# sourceMappingURL=joinAbsoluteUrlPath.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"joinAbsoluteUrlPath.spec.js","sourceRoot":"","sources":["../../src/util/joinAbsoluteUrlPath.spec.ts"],"names":[],"mappings":";;AAAA,+DAA4D;AAE5D,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,EAAE,CAAC,8DAA8D,EAAE,GAAG,EAAE;QACtE,MAAM,CAAC,IAAA,yCAAmB,EAAC,qBAAqB,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,6BAA6B,CAAC,CAAC;QACxG,MAAM,CAAC,IAAA,yCAAmB,EAAC,sBAAsB,EAAE,MAAM,EAA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AAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;QAC1F,MAAM,CAAC,IAAA,yCAAmB,EAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QACvF,MAAM,CAAC,IAAA,yCAAmB,EAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC9F,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function never(a: never): never;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.never = void 0;
4
+ function never(a) {
5
+ // this should never be executed. This is a compile time check
6
+ throw new Error(`value ${a} is not valid`);
7
+ }
8
+ exports.never = never;
9
+ //# sourceMappingURL=never.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"never.js","sourceRoot":"","sources":["../../src/util/never.ts"],"names":[],"mappings":";;;AAAA,SAAgB,KAAK,CAAC,CAAQ;IAC5B,8DAA8D;IAC9D,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;AAC7C,CAAC;AAHD,sBAGC"}
@@ -0,0 +1 @@
1
+ export declare function parseEnvVarForVar(varName: string, defaultValue?: string | undefined): string;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseEnvVarForVar = void 0;
4
+ function parseEnvVarForVar(varName, defaultValue = undefined) {
5
+ if (process.env[varName] === undefined) {
6
+ if (defaultValue !== undefined) {
7
+ return defaultValue;
8
+ }
9
+ throw new Error(`env variable ${varName} must be set`);
10
+ }
11
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
12
+ return process.env[varName];
13
+ }
14
+ exports.parseEnvVarForVar = parseEnvVarForVar;
15
+ //# sourceMappingURL=parseEnvVarForVar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseEnvVarForVar.js","sourceRoot":"","sources":["../../src/util/parseEnvVarForVar.ts"],"names":[],"mappings":";;;AAAA,SAAgB,iBAAiB,CAAC,OAAe,EAAE,eAAmC,SAAS;IAC7F,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,SAAS,EAAE;QACtC,IAAI,YAAY,KAAK,SAAS,EAAE;YAC9B,OAAO,YAAY,CAAC;SACrB;QAED,MAAM,IAAI,KAAK,CAAC,gBAAgB,OAAO,cAAc,CAAC,CAAC;KACxD;IAED,oEAAoE;IACpE,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,CAAE,CAAC;AAC/B,CAAC;AAXD,8CAWC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const parseEnvVarForVar_1 = require("./parseEnvVarForVar");
4
+ describe('parseEnvVarForVar', () => {
5
+ it('it should read an environment variable from process.env.*', () => {
6
+ process.env.MY_VAR = 'hello';
7
+ expect((0, parseEnvVarForVar_1.parseEnvVarForVar)('MY_VAR')).toEqual('hello');
8
+ });
9
+ it('it should throw an error if the variable is not available', () => {
10
+ expect(() => (0, parseEnvVarForVar_1.parseEnvVarForVar)('DOESNT_EXIST')).toThrowError(new Error('env variable DOESNT_EXIST must be set'));
11
+ });
12
+ it('it should not throw an error if a default value is provided and env var doesnt exist', () => {
13
+ expect((0, parseEnvVarForVar_1.parseEnvVarForVar)('DOESNT_EXIST', 'default')).toEqual('default');
14
+ });
15
+ it('it should return env var if its set and a defualt value is set', () => {
16
+ process.env.MY_VAR = 'hello';
17
+ expect((0, parseEnvVarForVar_1.parseEnvVarForVar)('MY_VAR', 'default')).toEqual('hello');
18
+ });
19
+ });
20
+ //# sourceMappingURL=parseEnvVarForVar.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseEnvVarForVar.spec.js","sourceRoot":"","sources":["../../src/util/parseEnvVarForVar.spec.ts"],"names":[],"mappings":";;AAAA,2DAAwD;AAExD,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,2DAA2D,EAAE,GAAG,EAAE;QACnE,OAAO,CAAC,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC;QAE7B,MAAM,CAAC,IAAA,qCAAiB,EAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2DAA2D,EAAE,GAAG,EAAE;QACnE,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,qCAAiB,EAAC,cAAc,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC,CAAC;IACnH,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sFAAsF,EAAE,GAAG,EAAE;QAC9F,MAAM,CAAC,IAAA,qCAAiB,EAAC,cAAc,EAAE,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC1E,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gEAAgE,EAAE,GAAG,EAAE;QACxE,OAAO,CAAC,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC;QAC7B,MAAM,CAAC,IAAA,qCAAiB,EAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function zipDirectory(sourceDirectory: string, outputDirectory: string): Promise<string>;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.zipDirectory = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const archiver_1 = __importDefault(require("archiver"));
10
+ function zipDirectory(sourceDirectory, outputDirectory) {
11
+ return new Promise((resolve, reject) => {
12
+ const outputZipFile = path_1.default.join(outputDirectory, '/export.zip');
13
+ const output = fs_1.default.createWriteStream(outputZipFile);
14
+ const archive = (0, archiver_1.default)('zip', {
15
+ zlib: { level: 9 }, // Sets the compression level.
16
+ });
17
+ output.on('close', function () {
18
+ resolve(outputZipFile);
19
+ });
20
+ archive.on('warning', function (err) {
21
+ reject(err);
22
+ });
23
+ archive.on('error', function (err) {
24
+ reject(err);
25
+ });
26
+ archive.pipe(output);
27
+ archive.directory(sourceDirectory, false);
28
+ archive.finalize();
29
+ });
30
+ }
31
+ exports.zipDirectory = zipDirectory;
32
+ //# sourceMappingURL=zipDirectory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zipDirectory.js","sourceRoot":"","sources":["../../src/zip/zipDirectory.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,4CAAoB;AAEpB,wDAAgC;AAEhC,SAAgB,YAAY,CAAC,eAAuB,EAAE,eAAuB;IAC3E,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC7C,MAAM,aAAa,GAAG,cAAI,CAAC,IAAI,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;QAChE,MAAM,MAAM,GAAG,YAAE,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;QAEnD,MAAM,OAAO,GAAG,IAAA,kBAAQ,EAAC,KAAK,EAAE;YAC9B,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,8BAA8B;SACnD,CAAC,CAAC;QAEH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE;YACjB,OAAO,CAAC,aAAa,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,UAAU,GAAG;YACjC,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,GAAG;YAC/B,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACrB,OAAO,CAAC,SAAS,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;QAC1C,OAAO,CAAC,QAAQ,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;AACL,CAAC;AAzBD,oCAyBC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const zipDirectory_1 = require("./zipDirectory");
9
+ describe('zipDirectory', () => {
10
+ const inputDir = fs_1.default.mkdtempSync('zip-test');
11
+ const outDir = fs_1.default.mkdtempSync('zip-test-out');
12
+ beforeAll(() => {
13
+ fs_1.default.writeFileSync(path_1.default.join(inputDir, 'f1.txt'), '1');
14
+ fs_1.default.writeFileSync(path_1.default.join(inputDir, 'f2.txt'), '2');
15
+ });
16
+ afterAll(() => {
17
+ fs_1.default.rmSync(inputDir, { force: true, recursive: true });
18
+ fs_1.default.rmSync(outDir, { force: true, recursive: true });
19
+ });
20
+ it('should take an input path and an output path and create a export.zip', async () => {
21
+ await (0, zipDirectory_1.zipDirectory)(inputDir, outDir);
22
+ expect(fs_1.default.existsSync(path_1.default.join(outDir, 'export.zip'))).toEqual(true);
23
+ });
24
+ });
25
+ //# sourceMappingURL=zipDirectory.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zipDirectory.spec.js","sourceRoot":"","sources":["../../src/zip/zipDirectory.spec.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AACxB,4CAAoB;AACpB,iDAA8C;AAE9C,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,MAAM,QAAQ,GAAG,YAAE,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAC5C,MAAM,MAAM,GAAG,YAAE,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IAE9C,SAAS,CAAC,GAAG,EAAE;QACb,YAAE,CAAC,aAAa,CAAC,cAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,GAAG,CAAC,CAAC;QACrD,YAAE,CAAC,aAAa,CAAC,cAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,GAAG,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,GAAG,EAAE;QACZ,YAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACtD,YAAE,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sEAAsE,EAAE,KAAK,IAAI,EAAE;QACpF,MAAM,IAAA,2BAAY,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAErC,MAAM,CAAC,YAAE,CAAC,UAAU,CAAC,cAAI,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,30 +1,36 @@
1
1
  {
2
2
  "name": "@squiz/dx-common-lib",
3
- "version": "1.2.1-alpha.99",
3
+ "version": "1.2.1",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
7
- "start": "node ./lib/index.js",
8
7
  "compile": "npx tsc",
9
8
  "lint": "eslint ./src --ext .ts",
10
9
  "test": "jest -c jest.config.ts",
11
- "test:integration": "jest -c jest.integration.config.ts",
12
10
  "test:update-snapshots": "jest -c jest.config.ts --updateSnapshot",
13
11
  "clean": "rimraf \".tsbuildinfo\" \"./lib\""
14
12
  },
15
13
  "author": "",
16
14
  "license": "ISC",
15
+ "dependencies": {
16
+ "@squiz/dx-logger-lib": "^1.2.1",
17
+ "archiver": "5.3.1",
18
+ "fs-extra": "10.1.0"
19
+ },
17
20
  "devDependencies": {
18
- "@types/jest": "28.1.6",
21
+ "@types/archiver": "5.3.1",
22
+ "@types/express": "4.17.13",
23
+ "@types/fs-extra": "9.0.13",
24
+ "@types/jest": "28.1.8",
19
25
  "@types/node": "17.0.27",
20
- "dotenv": "16.0.1",
26
+ "dotenv": "16.0.2",
21
27
  "eslint": "8.22.0",
22
28
  "jest": "28.1.3",
23
29
  "rimraf": "3.0.2",
24
- "ts-jest": "28.0.7",
30
+ "ts-jest": "28.0.8",
25
31
  "ts-loader": "9.3.1",
26
32
  "ts-node": "10.9.1",
27
33
  "typescript": "4.7.4"
28
34
  },
29
- "gitHead": "36030fd058a84822e5c51f7a9f139fc07ab5fdd9"
35
+ "gitHead": "362dbbb8f3e4cd5e4aa255596fd61d84a579bc73"
30
36
  }
@@ -15,3 +15,8 @@ export function assertAssignWithDefaultUndefinedValue<T>(
15
15
 
16
16
  return assertAssign(value, assertionFunc, errorMessage);
17
17
  }
18
+
19
+ export const isSomeEnum =
20
+ <TEnum>(enumType: TEnum) =>
21
+ (token: unknown): token is TEnum[keyof TEnum] =>
22
+ Object.values(enumType).includes(token as TEnum[keyof TEnum]);
@@ -0,0 +1,16 @@
1
+ import { assertIsBoolean } from './assertIsBoolean';
2
+
3
+ describe('assertIsBoolean', () => {
4
+ it('should throw an assertion error if input is undefined', () => {
5
+ expect(() => assertIsBoolean(undefined)).toThrowErrorMatchingInlineSnapshot(`"Expected undefined to be a boolean"`);
6
+ });
7
+
8
+ it('should throw an assertion error if input is null', () => {
9
+ expect(() => assertIsBoolean(null)).toThrowErrorMatchingInlineSnapshot(`"Expected null to be a boolean"`);
10
+ });
11
+
12
+ it('should return "void" or undefined if valid', () => {
13
+ expect(assertIsBoolean(true)).toBeUndefined();
14
+ expect(() => assertIsBoolean(false)).not.toThrowError();
15
+ });
16
+ });
@@ -0,0 +1,5 @@
1
+ import assert from 'assert/strict';
2
+
3
+ export function assertIsBoolean(value: unknown): asserts value is boolean {
4
+ assert.ok(typeof value === 'boolean', `Expected ${value} to be a boolean`);
5
+ }
@@ -0,0 +1,39 @@
1
+ import { AssertionError } from 'assert';
2
+ import { assertIsEnumValue } from './assertIsEnumValue';
3
+
4
+ describe('assertIsEnumValue', () => {
5
+ enum StringEnum {
6
+ A = 'a',
7
+ B = 'b',
8
+ C = 'c',
9
+ }
10
+
11
+ enum NumEnum {
12
+ A,
13
+ B,
14
+ C,
15
+ }
16
+
17
+ it('should not show an error if input value is in enum object', () => {
18
+ expect(assertIsEnumValue('a', StringEnum)).toBeUndefined();
19
+ const val = StringEnum.B;
20
+ expect(assertIsEnumValue(val, StringEnum)).toBeUndefined();
21
+ });
22
+
23
+ it('should not show an error if input value is in enum object (with no default values)', () => {
24
+ expect(assertIsEnumValue(2, NumEnum)).toBeUndefined();
25
+ const val = NumEnum.C;
26
+ expect(assertIsEnumValue(val, NumEnum)).toBeUndefined();
27
+ });
28
+
29
+ it("should throw an AssertionError is value isn't in enum", () => {
30
+ expect(() => assertIsEnumValue('zz', StringEnum)).toThrowError(AssertionError);
31
+ expect(() => assertIsEnumValue('zz', StringEnum)).toThrowErrorMatchingInlineSnapshot(`
32
+ "'zz' in [
33
+ 'a',
34
+ 'b',
35
+ 'c'
36
+ ]"
37
+ `);
38
+ });
39
+ });
@@ -0,0 +1,15 @@
1
+ import { AssertionError } from 'assert';
2
+
3
+ export function assertIsEnumValue<T extends object>(val: unknown, obj: T): asserts val is T[keyof T] {
4
+ if (isValueIsEnumValue(val, obj) === false) {
5
+ throw new AssertionError({
6
+ actual: val,
7
+ expected: Object.values(obj),
8
+ operator: 'in',
9
+ });
10
+ }
11
+ }
12
+
13
+ function isValueIsEnumValue<TEnum extends object>(val: unknown, enumType: TEnum): val is TEnum[keyof TEnum] {
14
+ return Object.values(enumType).includes(val as TEnum[keyof TEnum]);
15
+ }
@@ -0,0 +1,12 @@
1
+ // Common Assertions
2
+ export * from './assertIsString';
3
+ export * from './assertIsDefined';
4
+ export * from './assertIsMapOfStringString';
5
+ export * from './assertIsObject';
6
+ export * from './assertIsNotAnEmptyString';
7
+ export * from './assertIsEnumValue';
8
+ export * from './assertIsBoolean';
9
+
10
+ // Assert assign
11
+ export * from './assertAssignWithDefaultUndefinedValue';
12
+ export * from './assertAssign';
@@ -0,0 +1,7 @@
1
+ import { ErrorWithHttpStatusCode } from './ErrorWithHttpStatusCode';
2
+
3
+ export class BadRequestError extends ErrorWithHttpStatusCode {
4
+ constructor(message: string) {
5
+ super(400, message);
6
+ }
7
+ }
@@ -0,0 +1,5 @@
1
+ export class ErrorWithHttpStatusCode extends Error {
2
+ constructor(public statusCode: number, public message: string) {
3
+ super(message);
4
+ }
5
+ }
@@ -0,0 +1,7 @@
1
+ import { ErrorWithHttpStatusCode } from './ErrorWithHttpStatusCode';
2
+
3
+ export class InternalServerError extends ErrorWithHttpStatusCode {
4
+ constructor(message: string) {
5
+ super(500, message);
6
+ }
7
+ }
@@ -0,0 +1,7 @@
1
+ import { InternalServerError } from './InternalServerError';
2
+
3
+ export class MethodNotImplementedError extends InternalServerError {
4
+ constructor(message?: string) {
5
+ super(message ?? 'method is not implemented');
6
+ }
7
+ }
@@ -0,0 +1,7 @@
1
+ import { ErrorWithHttpStatusCode } from './ErrorWithHttpStatusCode';
2
+
3
+ export class ResourceNotFoundError extends ErrorWithHttpStatusCode {
4
+ constructor(message: string) {
5
+ super(404, message);
6
+ }
7
+ }
@@ -0,0 +1,8 @@
1
+ import { ErrorWithHttpStatusCode } from './ErrorWithHttpStatusCode';
2
+
3
+ export class TimeoutError extends ErrorWithHttpStatusCode {
4
+ name = 'TimeoutError';
5
+ constructor(message: string = 'request failed to evaluate within the timeout period') {
6
+ super(500, message);
7
+ }
8
+ }
@@ -0,0 +1,6 @@
1
+ export * from './BadRequestError';
2
+ export * from './ErrorWithHttpStatusCode';
3
+ export * from './InternalServerError';
4
+ export * from './ResourceNotFoundError';
5
+ export * from './TimeoutError';
6
+ export * from './MethodNotImplementedError';
package/src/index.ts CHANGED
@@ -1,10 +1,4 @@
1
- // Common Assertions
2
- export * from './assertions/assertIsString';
3
- export * from './assertions/assertIsDefined';
4
- export * from './assertions/assertIsMapOfStringString';
5
- export * from './assertions/assertIsObject';
6
- export * from './assertions/assertIsNotAnEmptyString';
7
-
8
- // Assert assign
9
- export * from './assertions/assertAssignWithDefaultUndefinedValue';
10
- export * from './assertions/assertAssign';
1
+ export * from './assertions/';
2
+ export * from './error';
3
+ export * from './util';
4
+ export * from './zip/zipDirectory';
@@ -0,0 +1,25 @@
1
+ import { getNodeEnv } from './getNodeEnv';
2
+
3
+ describe('getNodeEnv', () => {
4
+ it('should return production if NODE_ENV equals production', () => {
5
+ process.env.NODE_ENV = 'production';
6
+ expect(getNodeEnv()).toEqual('production');
7
+ });
8
+
9
+ it('should return development if NODE_ENV equals development', () => {
10
+ process.env.NODE_ENV = 'development';
11
+ expect(getNodeEnv()).toEqual('development');
12
+ });
13
+
14
+ it('should return development if NODE_ENV is not set', () => {
15
+ delete process.env.NODE_ENV;
16
+ expect(getNodeEnv()).toEqual('development');
17
+ });
18
+
19
+ it('should throw if NODE_ENV set to non valid environment', () => {
20
+ process.env.NODE_ENV = 'invalid';
21
+ expect(() => getNodeEnv()).toThrowError(
22
+ new Error('NODE_ENV env var can only be values "production" or "development"'),
23
+ );
24
+ });
25
+ });
@@ -0,0 +1,11 @@
1
+ export function getNodeEnv(): 'production' | 'development' {
2
+ if (process.env.NODE_ENV == 'production') {
3
+ return 'production';
4
+ }
5
+
6
+ if (process.env.NODE_ENV == 'development' || process.env.NODE_ENV === undefined) {
7
+ return 'development';
8
+ }
9
+
10
+ throw new Error('NODE_ENV env var can only be values "production" or "development"');
11
+ }
@@ -0,0 +1,23 @@
1
+ export type PageInfoResult = {
2
+ current: number;
3
+ next: number | null;
4
+ previous: number | null;
5
+ totalPages: number;
6
+ totalItems: number;
7
+ pageSize: number;
8
+ };
9
+
10
+ export function getPageInfo(current: number, pageSize: number, totalItems: number): PageInfoResult {
11
+ const totalPages = Math.ceil(totalItems / pageSize);
12
+ const next = current + 1 > totalPages ? null : current + 1;
13
+ const previous = current <= 1 ? null : current - 1;
14
+
15
+ return {
16
+ current,
17
+ next,
18
+ previous,
19
+ totalPages,
20
+ totalItems,
21
+ pageSize,
22
+ };
23
+ }