@datapos/datapos-shared 0.3.558 → 0.3.561

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.
@@ -1,126 +1,127 @@
1
- class c extends Error {
1
+ class a extends Error {
2
2
  locator;
3
- /** Logical source of the error. */
4
- constructor(s, o, e) {
5
- super(s, e), this.name = new.target.name, this.locator = o;
3
+ // Logical source of the error
4
+ constructor(o, s, r) {
5
+ super(o, r), this.name = "DPUError", this.locator = s;
6
6
  }
7
7
  }
8
- class i extends c {
8
+ class l extends a {
9
+ body;
10
+ // Sanitized snapshot of the response body
11
+ constructor(o, s, r, t) {
12
+ super(o, s, t), this.name = "APIError", this.body = E(r ?? void 0);
13
+ }
9
14
  }
10
- class g extends i {
15
+ class u extends a {
16
+ constructor(o, s, r) {
17
+ super(o, s, r), this.name = "EngineError";
18
+ }
11
19
  }
12
- class u extends i {
13
- constructor(s, o, e) {
14
- super(s, o, e), this.name = "EngineError";
20
+ class f extends a {
21
+ constructor(o, s, r) {
22
+ super(o, s, r), this.name = "ConnectorError";
15
23
  }
16
24
  }
17
- class l extends i {
25
+ class i extends a {
18
26
  body;
19
- /** Sanitized HTTP response body. */
20
- constructor(s, o, e, t) {
21
- super(s, o, t), this.name = new.target.name, this.body = d(e ?? void 0);
27
+ // Sanitized snapshot of the response body
28
+ constructor(o, s, r, t) {
29
+ super(o, s, t), this.name = "FetchError", this.body = E(r ?? void 0);
22
30
  }
23
31
  }
24
- async function k(r, s, o) {
25
- const e = ` - ${r.statusText}`, t = `${s} Response status '${r.status}${r.statusText ? e : ""}' received.`;
26
- let a;
32
+ async function b(e, o, s) {
33
+ const r = ` - ${e.statusText}`, t = `${o} Response status '${e.status}${e.statusText ? r : ""}' received.`;
34
+ let c;
27
35
  try {
28
- a = await r.text();
29
- } catch (f) {
30
- a = `<body unavailable: ${n(f).message}>`;
36
+ c = await e.text();
37
+ } catch (d) {
38
+ c = `<body unavailable: ${n(d).message}>`;
31
39
  }
32
- return new l(t, o, a);
40
+ return new i(t, s, c);
33
41
  }
34
- function y(r) {
35
- return r.map((s) => s.message).join(" ");
42
+ function y(e) {
43
+ return e.map((o) => o.message).join(" ");
36
44
  }
37
- function b(r) {
45
+ function k(e) {
38
46
  try {
39
- r();
47
+ e();
40
48
  } catch {
41
49
  }
42
50
  }
43
- function n(r) {
44
- if (r instanceof Error) return r;
45
- if (typeof r == "string") return new Error(r);
46
- if (typeof r == "number" || typeof r == "boolean" || typeof r == "bigint") return new Error(String(r));
47
- if (typeof r == "symbol") return new Error(r.description ?? "Unknown error");
48
- if (typeof r == "object")
51
+ function n(e) {
52
+ if (e instanceof Error) return e;
53
+ if (typeof e == "string") return new Error(e);
54
+ if (typeof e == "number" || typeof e == "boolean" || typeof e == "bigint") return new Error(String(e));
55
+ if (typeof e == "symbol") return new Error(e.description ?? "Unknown error");
56
+ if (typeof e == "object")
49
57
  try {
50
- return new Error(JSON.stringify(r));
58
+ return new Error(JSON.stringify(e));
51
59
  } catch {
52
60
  return new Error("Unknown error");
53
61
  }
54
62
  return new Error("Unknown error");
55
63
  }
56
- function w(r) {
57
- const s = /* @__PURE__ */ new Set(), o = [];
58
- let e = n(r);
59
- for (; e != null && !s.has(e); ) {
60
- s.add(e), console.log("CAUSE STACK", e.stack);
64
+ function h(e) {
65
+ const o = /* @__PURE__ */ new Set(), s = [];
66
+ let r = n(e);
67
+ for (; r != null && !o.has(r); ) {
68
+ o.add(r);
61
69
  let t;
62
- e instanceof l ? (t = { body: e.body, locator: e.locator, message: e.message, name: "FetchError", stack: e.stack }, e = e.cause == null ? null : n(e.cause)) : e instanceof u ? (t = { body: void 0, locator: e.locator, message: e.message, name: "EngineError", stack: e.stack }, e = e.cause == null ? null : n(e.cause)) : e instanceof c ? (t = { body: void 0, locator: e.locator, message: e.message, name: "DataPosError", stack: e.stack }, e = e.cause == null ? null : n(e.cause)) : e instanceof Error ? (t = { body: void 0, locator: "", message: e.message, name: e.name, stack: e.stack }, e = e.cause == null ? null : n(e.cause)) : (t = { body: void 0, locator: "", message: E(e), name: "Error", stack: void 0 }, e = null), /(?:\.{3}|[.!?])$/.test(t.message) || (t.message += "."), o.push(t);
70
+ r instanceof l ? (t = { body: r.body, locator: r.locator, message: r.message, name: "APIError", stack: r.stack }, r = r.cause == null ? null : n(r.cause)) : r instanceof f ? (t = { body: void 0, locator: r.locator, message: r.message, name: "ConnectorError", stack: r.stack }, r = r.cause == null ? null : n(r.cause)) : r instanceof u ? (t = { body: void 0, locator: r.locator, message: r.message, name: "EngineError", stack: r.stack }, r = r.cause == null ? null : n(r.cause)) : r instanceof i ? (t = { body: r.body, locator: r.locator, message: r.message, name: "FetchError", stack: r.stack }, r = r.cause == null ? null : n(r.cause)) : r instanceof a ? (t = { body: void 0, locator: r.locator, message: r.message, name: "DPUError", stack: r.stack }, r = r.cause == null ? null : n(r.cause)) : r instanceof Error ? (t = { body: void 0, locator: "", message: r.message, name: r.name, stack: r.stack }, r = r.cause == null ? null : n(r.cause)) : (t = { body: void 0, locator: "", message: m(r), name: "Error", stack: void 0 }, r = null), /(?:\.{3}|[.!?])$/.test(t.message) || (t.message += "."), s.push(t);
63
71
  }
64
- return o;
72
+ return s;
65
73
  }
66
- function h(r) {
67
- if (r.length === 0) return;
68
- let s;
69
- for (const o of r.toReversed()) {
70
- let e;
71
- if (o.body !== void 0)
72
- console.log("FetchError"), e = new l(o.message, o.locator, o.body, { cause: s });
73
- else if (o.locator === "")
74
- console.log("Generic"), e = new Error(o.message, { cause: s }), e.name = o.name;
75
- else
76
- switch (o.name) {
77
- case "APIError":
78
- console.log("APIError"), e = new g(o.message, o.locator, { cause: s });
79
- break;
80
- case "EngineError":
81
- e = new u(o.message, o.locator, { cause: s }), console.log("EngineError", e);
82
- break;
83
- // case 'ApplicationError':
84
- // error = new ApplicationError(serialised.message, serialised.locator, { rebuiltError });
85
- // break;
86
- // case 'OperationalError':
87
- // error = new OperationalError(serialised.message, serialised.locator, { rebuiltError });
88
- // break;
89
- // case 'WindowHandledRuntimeError':
90
- // error = new WindowHandledRuntimeError(serialised.message, serialised.locator, { rebuiltError });
91
- // break;
92
- // case 'WindowHandledPromiseRejectionError':
93
- // error = new WindowHandledPromiseRejectionError(serialised.message, serialised.locator, { rebuiltError });
94
- // break;
95
- default:
96
- console.log("Fallback"), e = new c(o.message, o.locator, { cause: s });
97
- break;
98
- }
99
- console.log(1111, e.stack, o.stack), o.stack !== void 0 && (e.stack = o.stack), console.log(2222, e.stack, o.stack), s = e;
74
+ function w(e) {
75
+ if (e.length === 0) return;
76
+ let o;
77
+ for (const s of e.toReversed()) {
78
+ let r;
79
+ switch (s.name) {
80
+ case "APIError":
81
+ r = new l(s.message, s.locator, s.body, { cause: o });
82
+ break;
83
+ case "ConnectorError":
84
+ r = new f(s.message, s.locator, { cause: o });
85
+ break;
86
+ case "EngineError":
87
+ r = new u(s.message, s.locator, { cause: o });
88
+ break;
89
+ case "FetchError":
90
+ r = new i(s.message, s.locator, s.body, { cause: o });
91
+ break;
92
+ case "DPUError":
93
+ r = new a(s.message, s.locator, { cause: o });
94
+ break;
95
+ default:
96
+ r = new Error(s.message, { cause: o }), r.name = s.name;
97
+ break;
98
+ }
99
+ s.stack !== void 0 && (r.stack = s.stack), o = r;
100
100
  }
101
- return s;
101
+ return o;
102
102
  }
103
- function E(r) {
104
- let s;
103
+ function m(e) {
104
+ let o;
105
105
  try {
106
- s = JSON.stringify(r);
106
+ o = JSON.stringify(e);
107
107
  } catch {
108
- typeof r == "symbol" ? s = r.description ?? "Unknown error" : typeof r == "bigint" ? s = r.toString() : s = "Unknown error";
108
+ typeof e == "symbol" ? o = e.description ?? "Unknown error" : typeof e == "bigint" ? o = e.toString() : o = "Unknown error";
109
109
  }
110
- return s === "" && (s = "Unknown error"), s;
110
+ return o === "" && (o = "Unknown error"), o;
111
111
  }
112
- function d(r) {
113
- if (!(r == null || r === ""))
114
- return r.length > 2048 ? `${r.slice(0, 2048)}... [truncated]` : r;
112
+ function E(e) {
113
+ if (!(e == null || e === ""))
114
+ return e.length > 2048 ? `${e.slice(0, 2048)}... [truncated]` : e;
115
115
  }
116
116
  export {
117
- g as APIError,
117
+ l as APIError,
118
+ f as ConnectorError,
118
119
  u as EngineError,
119
- l as FetchError,
120
- k as buildFetchError,
120
+ i as FetchError,
121
+ b as buildFetchError,
121
122
  y as concatenateSerialisedErrorMessages,
122
- b as ignoreErrors,
123
+ k as ignoreErrors,
123
124
  n as normalizeToError,
124
- w as serialiseError,
125
- h as unserialiseError
125
+ h as serialiseError,
126
+ w as unserialiseError
126
127
  };
@@ -1,72 +1,54 @@
1
- /**
2
- * Error constants, type declarations, classes, runtime utilities and local helpers.
3
- */
4
- /** Serializable representation of an error and its cause chain.
5
- * Used for logging, reporting, and transport across process or network boundaries.
6
- */
7
- interface SerialisedError {
8
- /** HTTP response body (Fetch errors only). */ body: string | undefined;
9
- /** Logical source of the error. */ locator: string;
10
- /** Human-readable error message. */ message: string;
11
- /** Error class or type name. */ name: string;
12
- /** Stack trace, if available. */ stack: string | undefined;
1
+ export interface SerialisedError {
2
+ body: string | undefined;
3
+ locator: string;
4
+ message: string;
5
+ name: string;
6
+ stack: string | undefined;
13
7
  }
14
- /** Base class for all Data Positioning errors.
15
- * All errors include a `locator` identifying the logical source of the error (module, feature, or operation).
16
- */
17
- declare class DataPosError extends Error {
18
- readonly locator: string; /** Logical source of the error. */
8
+ declare class DPUError extends Error {
9
+ readonly locator: string;
19
10
  constructor(message: string, locator: string, options?: ErrorOptions);
20
11
  }
21
- /** Represents application-level failures.
22
- * Used for errors originating from application logic, not external systems.
23
- */
24
- declare class ApplicationError extends DataPosError {
12
+ export declare class APIError extends DPUError {
13
+ readonly body: string | undefined;
14
+ constructor(message: string, locator: string, body: string | undefined, options?: ErrorOptions);
25
15
  }
26
- /** Represents API-related failures.
27
- * Typically thrown when backend requests fail or return invalid responses.
28
- */
29
- declare class APIError extends ApplicationError {
16
+ export declare class EngineError extends DPUError {
17
+ constructor(message: string, locator: string, options?: ErrorOptions);
30
18
  }
31
- /** Represents engine or core processing failures. */
32
- declare class EngineError extends ApplicationError {
19
+ export declare class ConnectorError extends DPUError {
33
20
  constructor(message: string, locator: string, options?: ErrorOptions);
34
21
  }
35
- /** Represents failures during HTTP requests.
36
- * Includes a sanitized snapshot of the response body for diagnostic purposes.
37
- */
38
- declare class FetchError extends ApplicationError {
39
- readonly body: string | undefined; /** Sanitized HTTP response body. */
40
- constructor(message: string, locator: string, body?: string | null, options?: ErrorOptions);
22
+ export declare class FetchError extends DPUError {
23
+ readonly body: string | undefined;
24
+ constructor(message: string, locator: string, body: string | undefined, options?: ErrorOptions);
41
25
  }
42
26
  /** Builds a {@link FetchError} from an HTTP response.
43
27
  * The response body is eagerly read so it can be included in error logs even after the response stream is closed.
44
28
  */
45
- declare function buildFetchError(response: {
29
+ export declare function buildFetchError(response: {
46
30
  status: number;
47
31
  statusText: string;
48
32
  text: () => Promise<string>;
49
33
  }, message: string, locator: string): Promise<FetchError>;
50
34
  /** Concatenates serialized error messages into a single string. */
51
- declare function concatenateSerialisedErrorMessages(serialisedErrors: SerialisedError[]): string;
35
+ export declare function concatenateSerialisedErrorMessages(serialisedErrors: SerialisedError[]): string;
52
36
  /** Ignore best-effort cleanup errors to keep teardown noise-free. */
53
- declare function ignoreErrors(action: () => void): void;
37
+ export declare function ignoreErrors(action: () => void): void;
54
38
  /** Normalizes an unknown thrown value into an {@link Error}.
55
39
  * This function should be used at error boundaries to guarantee consistent error handling.
56
40
  */
57
- declare function normalizeToError(value: unknown): Error;
41
+ export declare function normalizeToError(value: unknown): Error;
58
42
  /** Serializes an error and its cause chain into a flat structure.
59
43
  * - Errors are ordered from outermost to root cause.
60
44
  * - Cycles in the cause chain are safely ignored.
61
45
  * - Messages are normalized to end with punctuation.
62
46
  */
63
- declare function serialiseError(error?: unknown): SerialisedError[];
47
+ export declare function serialiseError(error?: unknown): SerialisedError[];
64
48
  /** Unserialises an array of {@link SerialisedError} objects back into an error with a cause chain.
65
49
  * - Reconstructs the appropriate error class based on serialized properties.
66
50
  * - Chains errors from outermost to root cause using the `cause` option.
67
51
  * - Returns `undefined` if the input array is empty.
68
52
  */
69
- declare function unserialiseError(serialisedErrors: SerialisedError[]): Error | undefined;
70
- export type { SerialisedError };
71
- export { APIError, EngineError, FetchError };
72
- export { buildFetchError, concatenateSerialisedErrorMessages, ignoreErrors, normalizeToError, serialiseError, unserialiseError };
53
+ export declare function unserialiseError(serialisedErrors: SerialisedError[]): Error | undefined;
54
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datapos/datapos-shared",
3
- "version": "0.3.558",
3
+ "version": "0.3.561",
4
4
  "description": "A library containing common constants, types and utilities used across all Data Positioning projects.",
5
5
  "license": "MIT",
6
6
  "author": "Jonathan Terrell <terrell.jm@gmail.com>",