@clipboard-health/util-ts 0.1.0 → 0.3.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [0.3.0](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.2.0...util-ts-0.3.0) (2023-04-24)
6
+
7
+
8
+ ### Features
9
+
10
+ * use XO ESLint config ([#26](https://github.com/ClipboardHealth/cbh-core/issues/26) ([ae385eb](https://github.com/ClipboardHealth/cbh-core/commit/ae385eb06d02a79f894e2f229731f2cf0aedffbd))
11
+
12
+ ## [0.2.0](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.1.0...util-ts-0.2.0) (2023-04-24)
13
+
14
+
15
+ ### Features
16
+
17
+ * Add `MessageProducer` class ([#24](https://github.com/ClipboardHealth/cbh-core/issues/24)) ([6b9ca48](https://github.com/ClipboardHealth/cbh-core/commit/6b9ca4814a7e4e6e9dd876c3a74dc10f018b023b))
18
+
5
19
  ## 0.1.0 (2023-04-19)
6
20
 
7
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clipboard-health/util-ts",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "main": "./src/index.js",
5
5
  "scripts": {
6
6
  "build": "nx build util-ts",
package/src/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  export * from "./lib/cbh-error";
2
+ export * from "./lib/cbh-response";
2
3
  export * from "./lib/force-cast";
3
4
  export * from "./lib/is-null-or-undefined";
5
+ export * from "./lib/types.d";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/util-ts/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,eAAe,CAAC"}
package/src/index.js CHANGED
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./lib/cbh-error"), exports);
5
+ tslib_1.__exportStar(require("./lib/cbh-response"), exports);
5
6
  tslib_1.__exportStar(require("./lib/force-cast"), exports);
6
7
  tslib_1.__exportStar(require("./lib/is-null-or-undefined"), exports);
8
+ tslib_1.__exportStar(require("./lib/types.d"), exports);
7
9
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/util-ts/src/index.ts"],"names":[],"mappings":";;;AAAA,0DAAgC;AAChC,2DAAiC;AACjC,qEAA2C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/util-ts/src/index.ts"],"names":[],"mappings":";;;AAAA,0DAAgC;AAChC,6DAAmC;AACnC,2DAAiC;AACjC,qEAA2C;AAC3C,wDAA8B"}
@@ -1,3 +1,10 @@
1
+ import type { NonEmptyArray, OneOrNonEmptyArray } from "./types";
2
+ export type CbhIssue = {
3
+ cause?: Error;
4
+ message: string;
5
+ };
1
6
  export declare class CbhError extends Error {
2
- constructor(message: string, cause?: Error);
7
+ readonly issues: NonEmptyArray<CbhIssue>;
8
+ constructor(issues: OneOrNonEmptyArray<CbhIssue>);
3
9
  }
10
+ //# sourceMappingURL=cbh-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cbh-error.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/cbh-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAEjE,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,qBAAa,QAAS,SAAQ,KAAK;IACjC,SAAgB,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;gBAEpC,MAAM,EAAE,kBAAkB,CAAC,QAAQ,CAAC;CASjD"}
@@ -2,13 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CbhError = void 0;
4
4
  class CbhError extends Error {
5
- constructor(message, cause) {
6
- super(message);
7
- // Must be called immediately after `super`.
8
- Object.setPrototypeOf(this, CbhError.prototype);
5
+ issues;
6
+ constructor(issues) {
7
+ const is = toNonEmptyArray(issues);
8
+ const first = is[0];
9
+ super(first?.message, { cause: first?.cause });
10
+ // See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#example
11
+ Object.setPrototypeOf(this, new.target.prototype);
12
+ this.issues = is;
9
13
  this.name = "CbhError";
10
- this.cause = cause;
11
14
  }
12
15
  }
13
16
  exports.CbhError = CbhError;
17
+ function toNonEmptyArray(value) {
18
+ return Array.isArray(value) ? value : [value];
19
+ }
14
20
  //# sourceMappingURL=cbh-error.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cbh-error.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/cbh-error.ts"],"names":[],"mappings":";;;AAAA,MAAa,QAAS,SAAQ,KAAK;IACjC,YAAY,OAAe,EAAE,KAAa;QACxC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,4CAA4C;QAC5C,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;QAEhD,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AATD,4BASC"}
1
+ {"version":3,"file":"cbh-error.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/cbh-error.ts"],"names":[],"mappings":";;;AAOA,MAAa,QAAS,SAAQ,KAAK;IACjB,MAAM,CAA0B;IAEhD,YAAY,MAAoC;QAC9C,MAAM,EAAE,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;QACnC,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QACpB,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAC/C,6FAA6F;QAC7F,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAClD,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAZD,4BAYC;AAED,SAAS,eAAe,CAAI,KAA4B;IACtD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAChD,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { CbhError, type CbhIssue } from "./cbh-error";
2
+ import type { OneOrNonEmptyArray } from "./types";
3
+ export type CbhResponse<T> = {
4
+ success: true;
5
+ data: T;
6
+ } | {
7
+ success: false;
8
+ error: CbhError;
9
+ };
10
+ export declare function toErrorCbhResponse(issues: OneOrNonEmptyArray<CbhIssue>): {
11
+ success: false;
12
+ error: CbhError;
13
+ };
14
+ export declare function toSuccessCbhResponse<T>(data: T): {
15
+ success: true;
16
+ data: T;
17
+ };
18
+ //# sourceMappingURL=cbh-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cbh-response.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/cbh-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,MAAM,MAAM,WAAW,CAAC,CAAC,IACrB;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAC1B;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,QAAQ,CAAA;CAAE,CAAC;AAExC,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG;IACxE,OAAO,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,QAAQ,CAAC;CACjB,CAEA;AAED,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,CAE3E"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toSuccessCbhResponse = exports.toErrorCbhResponse = void 0;
4
+ const cbh_error_1 = require("./cbh-error");
5
+ function toErrorCbhResponse(issues) {
6
+ return { success: false, error: new cbh_error_1.CbhError(issues) };
7
+ }
8
+ exports.toErrorCbhResponse = toErrorCbhResponse;
9
+ function toSuccessCbhResponse(data) {
10
+ return { success: true, data };
11
+ }
12
+ exports.toSuccessCbhResponse = toSuccessCbhResponse;
13
+ //# sourceMappingURL=cbh-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cbh-response.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/cbh-response.ts"],"names":[],"mappings":";;;AAAA,2CAAsD;AAOtD,SAAgB,kBAAkB,CAAC,MAAoC;IAIrE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,oBAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;AACzD,CAAC;AALD,gDAKC;AAED,SAAgB,oBAAoB,CAAI,IAAO;IAC7C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACjC,CAAC;AAFD,oDAEC"}
@@ -1,2 +1,3 @@
1
1
  /** Force cast to the provided type. */
2
2
  export declare function forceCast<T>(val: unknown): T;
3
+ //# sourceMappingURL=force-cast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"force-cast.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/force-cast.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,GAAG,CAAC,CAE5C"}
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.forceCast = void 0;
4
4
  /** Force cast to the provided type. */
5
5
  function forceCast(val) {
6
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
7
6
  return val;
8
7
  }
9
8
  exports.forceCast = forceCast;
@@ -1 +1 @@
1
- {"version":3,"file":"force-cast.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/force-cast.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AACvC,SAAgB,SAAS,CAAI,GAAY;IACvC,yEAAyE;IACzE,OAAO,GAAQ,CAAC;AAClB,CAAC;AAHD,8BAGC"}
1
+ {"version":3,"file":"force-cast.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/force-cast.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AACvC,SAAgB,SAAS,CAAI,GAAY;IACvC,OAAO,GAAQ,CAAC;AAClB,CAAC;AAFD,8BAEC"}
@@ -1 +1,2 @@
1
1
  export declare function isNullOrUndefined(val: unknown): val is null | undefined;
2
+ //# sourceMappingURL=is-null-or-undefined.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-null-or-undefined.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/is-null-or-undefined.ts"],"names":[],"mappings":"AACA,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,IAAI,GAAG,SAAS,CAEvE"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isNullOrUndefined = void 0;
4
+ // eslint-disable-next-line @typescript-eslint/ban-types
4
5
  function isNullOrUndefined(val) {
5
6
  return val === null || val === undefined;
6
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"is-null-or-undefined.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/is-null-or-undefined.ts"],"names":[],"mappings":";;;AAAA,SAAgB,iBAAiB,CAAC,GAAY;IAC5C,OAAO,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,CAAC;AAC3C,CAAC;AAFD,8CAEC"}
1
+ {"version":3,"file":"is-null-or-undefined.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/is-null-or-undefined.ts"],"names":[],"mappings":";;;AAAA,wDAAwD;AACxD,SAAgB,iBAAiB,CAAC,GAAY;IAC5C,OAAO,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,CAAC;AAC3C,CAAC;AAFD,8CAEC"}