@clipboard-health/util-ts 0.1.0 → 0.2.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,13 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [0.2.0](https://github.com/ClipboardHealth/cbh-core/compare/util-ts-0.1.0...util-ts-0.2.0) (2023-04-24)
6
+
7
+
8
+ ### Features
9
+
10
+ * Add `MessageProducer` class ([#24](https://github.com/ClipboardHealth/cbh-core/issues/24)) ([6b9ca48](https://github.com/ClipboardHealth/cbh-core/commit/6b9ca4814a7e4e6e9dd876c3a74dc10f018b023b))
11
+
5
12
  ## 0.1.0 (2023-04-19)
6
13
 
7
14
 
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.2.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, 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,QAAQ,EAAE,MAAM,aAAa,CAAC;AACjD,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,2CAAiD;AAOjD,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,CAG5C"}
@@ -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":"AAAA,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,IAAI,GAAG,SAAS,CAEvE"}