@datapos/datapos-shared 0.3.557 → 0.3.559

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