@nhtio/encoder 0.1.0-master-ab456424
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/LICENSE.md +9 -0
- package/README.md +5 -0
- package/exceptions-BHfZbUPp.mjs +168 -0
- package/exceptions-BHfZbUPp.mjs.map +1 -0
- package/exceptions-iBYg29S4.js +2 -0
- package/exceptions-iBYg29S4.js.map +1 -0
- package/exceptions.cjs +2 -0
- package/exceptions.cjs.map +1 -0
- package/exceptions.d.ts +8 -0
- package/exceptions.mjs +11 -0
- package/exceptions.mjs.map +1 -0
- package/index.cjs +207 -0
- package/index.cjs.map +1 -0
- package/index.d.ts +27 -0
- package/index.mjs +54623 -0
- package/index.mjs.map +1 -0
- package/package.json +31 -0
- package/private/exceptions.d.ts +153 -0
- package/private/function_serializer.d.ts +32 -0
- package/private/schemas.d.ts +27 -0
- package/private/stringification.d.ts +12 -0
- package/private/structured_data.d.ts +10 -0
- package/private/type_guards.d.ts +59 -0
- package/private/types.d.ts +16 -0
- package/types.cjs +2 -0
- package/types.cjs.map +1 -0
- package/types.d.ts +9 -0
- package/types.mjs +2 -0
- package/types.mjs.map +1 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 New Horizon Technology LTD (nht.io)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
var k = Object.defineProperty;
|
|
2
|
+
var S = (r, s, t) => s in r ? k(r, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[s] = t;
|
|
3
|
+
var e = (r, s, t) => S(r, typeof s != "symbol" ? s + "" : s, t);
|
|
4
|
+
class o extends Error {
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new BaseException instance.
|
|
7
|
+
*
|
|
8
|
+
* @param message - The error message. If not provided, uses the static message from the constructor.
|
|
9
|
+
* @param options - Additional options including error cause, code, and status.
|
|
10
|
+
*/
|
|
11
|
+
constructor(t, c) {
|
|
12
|
+
super(t, c);
|
|
13
|
+
/**
|
|
14
|
+
* Name of the class that raised the exception.
|
|
15
|
+
*/
|
|
16
|
+
e(this, "name");
|
|
17
|
+
/**
|
|
18
|
+
* A status code for the error. Usually helpful when converting errors
|
|
19
|
+
* to HTTP responses.
|
|
20
|
+
*/
|
|
21
|
+
e(this, "status");
|
|
22
|
+
const d = this.constructor;
|
|
23
|
+
this.name = d.name, this.message = t || d.message || "", this.status = (c == null ? void 0 : c.status) || d.status || 500;
|
|
24
|
+
const g = (c == null ? void 0 : c.code) || d.code;
|
|
25
|
+
g !== void 0 && (this.code = g);
|
|
26
|
+
const $ = d.help;
|
|
27
|
+
$ !== void 0 && (this.help = $), Error.captureStackTrace(this, d);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Returns the constructor name for the Symbol.toStringTag property.
|
|
31
|
+
*
|
|
32
|
+
* @returns The name of the exception class.
|
|
33
|
+
*/
|
|
34
|
+
get [Symbol.toStringTag]() {
|
|
35
|
+
return this.constructor.name;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Returns a string representation of the exception.
|
|
39
|
+
* Includes the error code in brackets if available.
|
|
40
|
+
*
|
|
41
|
+
* @returns A formatted string representation of the exception.
|
|
42
|
+
*/
|
|
43
|
+
toString() {
|
|
44
|
+
return this.code ? `${this.name} [${this.code}]: ${this.message}` : `${this.name}: ${this.message}`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const n = class n extends o {
|
|
48
|
+
/**
|
|
49
|
+
* Creates a new E_UNENCODABLE_VALUE exception.
|
|
50
|
+
*
|
|
51
|
+
* @param value - The value that could not be encoded.
|
|
52
|
+
*/
|
|
53
|
+
constructor(s) {
|
|
54
|
+
const t = `Value of type ${typeof s} (${String(s)}) is not encodable.`;
|
|
55
|
+
super(t, {
|
|
56
|
+
code: n.code,
|
|
57
|
+
status: n.status
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
e(n, "status", 500), e(n, "code", "E_UNENCODABLE_VALUE");
|
|
62
|
+
let f = n;
|
|
63
|
+
const u = class u extends o {
|
|
64
|
+
/**
|
|
65
|
+
* Creates a new E_ENCODING_FAILED exception.
|
|
66
|
+
*
|
|
67
|
+
* @param value - The value that failed to encode.
|
|
68
|
+
* @param cause - The underlying error that caused the encoding to fail.
|
|
69
|
+
*/
|
|
70
|
+
constructor(s, t) {
|
|
71
|
+
const c = `Value of type ${typeof s} (${String(s)}) is not encodable.`;
|
|
72
|
+
super(c, {
|
|
73
|
+
code: u.code,
|
|
74
|
+
status: u.status,
|
|
75
|
+
cause: t
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
e(u, "status", 500), e(u, "code", "E_ENCODING_FAILED");
|
|
80
|
+
let p = u;
|
|
81
|
+
const i = class i extends o {
|
|
82
|
+
/**
|
|
83
|
+
* Creates a new E_CIRCULAR_REFERENCE exception.
|
|
84
|
+
*/
|
|
85
|
+
constructor() {
|
|
86
|
+
super("Circular reference detected.", {
|
|
87
|
+
code: i.code,
|
|
88
|
+
status: i.status
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
e(i, "status", 500), e(i, "code", "E_CIRCULAR_REFERENCE");
|
|
93
|
+
let x = i;
|
|
94
|
+
const h = class h extends o {
|
|
95
|
+
/**
|
|
96
|
+
* Creates a new E_UNDECODABLE_VALUE exception.
|
|
97
|
+
*
|
|
98
|
+
* @param type - The type string that could not be decoded.
|
|
99
|
+
*/
|
|
100
|
+
constructor(s) {
|
|
101
|
+
const t = `Value of type ${s} cannot be decoded.`;
|
|
102
|
+
super(t, {
|
|
103
|
+
code: h.code,
|
|
104
|
+
status: h.status
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
e(h, "status", 500), e(h, "code", "E_UNDECODABLE_VALUE");
|
|
109
|
+
let v = h;
|
|
110
|
+
const l = class l extends o {
|
|
111
|
+
/**
|
|
112
|
+
* Creates a new E_NOT_AN_ENCODED_VALUE exception.
|
|
113
|
+
*
|
|
114
|
+
* @param value - The string value that is not a valid encoded value.
|
|
115
|
+
*/
|
|
116
|
+
constructor(s) {
|
|
117
|
+
const t = `Value "${s}" is not a valid encoded value.`;
|
|
118
|
+
super(t, {
|
|
119
|
+
code: l.code,
|
|
120
|
+
status: l.status
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
e(l, "status", 500), e(l, "code", "E_NOT_AN_ENCODED_VALUE");
|
|
125
|
+
let b = l;
|
|
126
|
+
const m = class m extends o {
|
|
127
|
+
/**
|
|
128
|
+
* Creates a new E_INVALID_VERSION exception.
|
|
129
|
+
*
|
|
130
|
+
* @param version - The invalid version string.
|
|
131
|
+
*/
|
|
132
|
+
constructor(s) {
|
|
133
|
+
const t = `Invalid version "${s}"`;
|
|
134
|
+
super(t, {
|
|
135
|
+
code: m.code,
|
|
136
|
+
status: m.status
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
e(m, "status", 500), e(m, "code", "E_INVALID_VERSION");
|
|
141
|
+
let y = m;
|
|
142
|
+
const a = class a extends o {
|
|
143
|
+
/**
|
|
144
|
+
* Creates a new E_INCOMPATIBLE_VERSION exception.
|
|
145
|
+
*
|
|
146
|
+
* @param version - The incompatible version string from the encoded data.
|
|
147
|
+
*/
|
|
148
|
+
constructor(s) {
|
|
149
|
+
const t = `Encoded data version ${s} is not compatible with the current version 0.1.0-master-ab456424.`;
|
|
150
|
+
super(t, {
|
|
151
|
+
code: a.code,
|
|
152
|
+
status: a.status
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
e(a, "status", 500), e(a, "code", "E_INCOMPATIBLE_VERSION"), e(a, "help", "This error indicates that the encoded value is from a version which is newer than the version of the decoder.");
|
|
157
|
+
let w = a;
|
|
158
|
+
export {
|
|
159
|
+
o as B,
|
|
160
|
+
f as E,
|
|
161
|
+
x as a,
|
|
162
|
+
p as b,
|
|
163
|
+
v as c,
|
|
164
|
+
b as d,
|
|
165
|
+
y as e,
|
|
166
|
+
w as f
|
|
167
|
+
};
|
|
168
|
+
//# sourceMappingURL=exceptions-BHfZbUPp.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions-BHfZbUPp.mjs","sources":["../src/private/exceptions.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\n\n/**\n * Base exception class that extends the native Error class.\n * Provides a foundation for all custom exceptions with additional metadata\n * like error codes, status codes, and help descriptions.\n */\nexport class BaseException extends Error {\n /**\n * Define the error metadata as static properties to avoid\n * setting them repeatedly on the error instance\n */\n declare static help?: string\n declare static code?: string\n declare static status?: number\n declare static message?: string\n\n /**\n * Name of the class that raised the exception.\n */\n name: string\n\n /**\n * Optional help description for the error. You can use it to define additional\n * human readable information for the error.\n */\n declare help?: string\n\n /**\n * A machine readable error code. This will allow the error handling logic\n * to narrow down exceptions based upon the error code.\n */\n declare code?: string\n\n /**\n * A status code for the error. Usually helpful when converting errors\n * to HTTP responses.\n */\n status: number\n\n /**\n * Creates a new BaseException instance.\n *\n * @param message - The error message. If not provided, uses the static message from the constructor.\n * @param options - Additional options including error cause, code, and status.\n */\n constructor(message?: string, options?: ErrorOptions & { code?: string; status?: number }) {\n super(message, options)\n\n const ErrorConstructor = this.constructor as typeof BaseException\n\n this.name = ErrorConstructor.name\n this.message = message || ErrorConstructor.message || ''\n this.status = options?.status || ErrorConstructor.status || 500\n\n const code = options?.code || ErrorConstructor.code\n if (code !== undefined) {\n this.code = code\n }\n\n const help = ErrorConstructor.help\n if (help !== undefined) {\n this.help = help\n }\n\n Error.captureStackTrace(this, ErrorConstructor)\n }\n\n /**\n * Returns the constructor name for the Symbol.toStringTag property.\n *\n * @returns The name of the exception class.\n */\n get [Symbol.toStringTag]() {\n return this.constructor.name\n }\n\n /**\n * Returns a string representation of the exception.\n * Includes the error code in brackets if available.\n *\n * @returns A formatted string representation of the exception.\n */\n toString() {\n if (this.code) {\n return `${this.name} [${this.code}]: ${this.message}`\n }\n return `${this.name}: ${this.message}`\n }\n}\n\n/**\n * Exception thrown when a value cannot be encoded.\n * This indicates that the value type is not supported by the encoder.\n */\nexport class E_UNENCODABLE_VALUE extends BaseException {\n static status = 500\n static code = 'E_UNENCODABLE_VALUE'\n\n /**\n * Creates a new E_UNENCODABLE_VALUE exception.\n *\n * @param value - The value that could not be encoded.\n */\n constructor(value: unknown) {\n const message = `Value of type ${typeof value} (${String(value)}) is not encodable.`\n super(message, {\n code: E_UNENCODABLE_VALUE.code,\n status: E_UNENCODABLE_VALUE.status,\n })\n }\n}\n\n/**\n * Exception thrown when encoding fails due to an underlying error.\n * This wraps the original error as the cause for better error tracing.\n */\nexport class E_ENCODING_FAILED extends BaseException {\n static status = 500\n static code = 'E_ENCODING_FAILED'\n\n /**\n * Creates a new E_ENCODING_FAILED exception.\n *\n * @param value - The value that failed to encode.\n * @param cause - The underlying error that caused the encoding to fail.\n */\n constructor(value: unknown, cause: unknown) {\n const message = `Value of type ${typeof value} (${String(value)}) is not encodable.`\n super(message, {\n code: E_ENCODING_FAILED.code,\n status: E_ENCODING_FAILED.status,\n cause,\n })\n }\n}\n\n/**\n * Exception thrown when a circular reference is detected during encoding.\n * Circular references cannot be encoded and must be avoided.\n */\nexport class E_CIRCULAR_REFERENCE extends BaseException {\n static status = 500\n static code = 'E_CIRCULAR_REFERENCE'\n\n /**\n * Creates a new E_CIRCULAR_REFERENCE exception.\n */\n constructor() {\n const message = `Circular reference detected.`\n super(message, {\n code: E_CIRCULAR_REFERENCE.code,\n status: E_CIRCULAR_REFERENCE.status,\n })\n }\n}\n\n/**\n * Exception thrown when a value with an unknown or unsupported type cannot be decoded.\n */\nexport class E_UNDECODABLE_VALUE extends BaseException {\n static status = 500\n static code = 'E_UNDECODABLE_VALUE'\n\n /**\n * Creates a new E_UNDECODABLE_VALUE exception.\n *\n * @param type - The type string that could not be decoded.\n */\n constructor(type: string) {\n const message = `Value of type ${type} cannot be decoded.`\n super(message, {\n code: E_UNDECODABLE_VALUE.code,\n status: E_UNDECODABLE_VALUE.status,\n })\n }\n}\n\n/**\n * Exception thrown when attempting to decode a value that is not a valid encoded value.\n * This indicates the input string is not in the expected encoded format.\n */\nexport class E_NOT_AN_ENCODED_VALUE extends BaseException {\n static status = 500\n static code = 'E_NOT_AN_ENCODED_VALUE'\n\n /**\n * Creates a new E_NOT_AN_ENCODED_VALUE exception.\n *\n * @param value - The string value that is not a valid encoded value.\n */\n constructor(value: string) {\n const message = `Value \"${value}\" is not a valid encoded value.`\n super(message, {\n code: E_NOT_AN_ENCODED_VALUE.code,\n status: E_NOT_AN_ENCODED_VALUE.status,\n })\n }\n}\n\n/**\n * Exception thrown when an invalid version string is encountered.\n */\nexport class E_INVALID_VERSION extends BaseException {\n static status = 500\n static code = 'E_INVALID_VERSION'\n\n /**\n * Creates a new E_INVALID_VERSION exception.\n *\n * @param version - The invalid version string.\n */\n constructor(version: string) {\n const message = `Invalid version \"${version}\"`\n super(message, {\n code: E_INVALID_VERSION.code,\n status: E_INVALID_VERSION.status,\n })\n }\n}\n\n/**\n * Exception thrown when attempting to decode data encoded with an incompatible version.\n * This typically occurs when the encoded data is from a newer version than the decoder supports.\n */\nexport class E_INCOMPATIBLE_VERSION extends BaseException {\n static status = 500\n static code = 'E_INCOMPATIBLE_VERSION'\n static help =\n 'This error indicates that the encoded value is from a version which is newer than the version of the decoder.'\n\n /**\n * Creates a new E_INCOMPATIBLE_VERSION exception.\n *\n * @param version - The incompatible version string from the encoded data.\n */\n constructor(version: string) {\n const message = `Encoded data version ${version} is not compatible with the current version ${__VERSION__}.`\n super(message, {\n code: E_INCOMPATIBLE_VERSION.code,\n status: E_INCOMPATIBLE_VERSION.status,\n })\n }\n}\n"],"names":["BaseException","message","options","__publicField","ErrorConstructor","code","help","_E_UNENCODABLE_VALUE","value","E_UNENCODABLE_VALUE","_E_ENCODING_FAILED","cause","E_ENCODING_FAILED","_E_CIRCULAR_REFERENCE","E_CIRCULAR_REFERENCE","_E_UNDECODABLE_VALUE","type","E_UNDECODABLE_VALUE","_E_NOT_AN_ENCODED_VALUE","E_NOT_AN_ENCODED_VALUE","_E_INVALID_VERSION","version","E_INVALID_VERSION","_E_INCOMPATIBLE_VERSION","E_INCOMPATIBLE_VERSION"],"mappings":";;;AAOO,MAAMA,UAAsB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuCvC,YAAYC,GAAkBC,GAA6D;AACzF,UAAMD,GAASC,CAAO;AA3BxB;AAAA;AAAA;AAAA,IAAAC,EAAA;AAkBA;AAAA;AAAA;AAAA;AAAA,IAAAA,EAAA;AAWE,UAAMC,IAAmB,KAAK;AAE9B,SAAK,OAAOA,EAAiB,MAC7B,KAAK,UAAUH,KAAWG,EAAiB,WAAW,IACtD,KAAK,UAASF,KAAA,g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ME,IAANF;AAsBA,MAAMG,IAAN,MAAMA,UAA+BvB,EAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWxD,YAAYqB,GAAiB;AAC3B,UAAMpB,IAAU,wBAAwBoB,CAAO;AAC/C,UAAMpB,GAAS;AAAA,MACb,MAAMsB,EAAuB;AAAA,MAC7B,QAAQA,EAAuB;AAAA,IAAA,CAChC;AAAA,EACH;AACF;AAjBEpB,EADWoB,GACJ,UAAS,MAChBpB,EAFWoB,GAEJ,QAAO,2BACdpB,EAHWoB,GAGJ,QACL;AAJG,IAAMC,IAAND;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var S=Object.defineProperty;var k=(r,t,s)=>t in r?S(r,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[t]=s;var e=(r,t,s)=>k(r,typeof t!="symbol"?t+"":t,s);class a extends Error{constructor(s,c){super(s,c);e(this,"name");e(this,"status");const d=this.constructor;this.name=d.name,this.message=s||d.message||"",this.status=(c==null?void 0:c.status)||d.status||500;const y=(c==null?void 0:c.code)||d.code;y!==void 0&&(this.code=y);const w=d.help;w!==void 0&&(this.help=w),Error.captureStackTrace(this,d)}get[Symbol.toStringTag](){return this.constructor.name}toString(){return this.code?`${this.name} [${this.code}]: ${this.message}`:`${this.name}: ${this.message}`}}const n=class n extends a{constructor(t){const s=`Value of type ${typeof t} (${String(t)}) is not encodable.`;super(s,{code:n.code,status:n.status})}};e(n,"status",500),e(n,"code","E_UNENCODABLE_VALUE");let g=n;const u=class u extends a{constructor(t,s){const c=`Value of type ${typeof t} (${String(t)}) is not encodable.`;super(c,{code:u.code,status:u.status,cause:s})}};e(u,"status",500),e(u,"code","E_ENCODING_FAILED");let $=u;const i=class i extends a{constructor(){super("Circular reference detected.",{code:i.code,status:i.status})}};e(i,"status",500),e(i,"code","E_CIRCULAR_REFERENCE");let f=i;const h=class h extends a{constructor(t){const s=`Value of type ${t} cannot be decoded.`;super(s,{code:h.code,status:h.status})}};e(h,"status",500),e(h,"code","E_UNDECODABLE_VALUE");let p=h;const l=class l extends a{constructor(t){const s=`Value "${t}" is not a valid encoded value.`;super(s,{code:l.code,status:l.status})}};e(l,"status",500),e(l,"code","E_NOT_AN_ENCODED_VALUE");let x=l;const m=class m extends a{constructor(t){const s=`Invalid version "${t}"`;super(s,{code:m.code,status:m.status})}};e(m,"status",500),e(m,"code","E_INVALID_VERSION");let v=m;const o=class o extends a{constructor(t){const s=`Encoded data version ${t} is not compatible with the current version 0.1.0-master-ab456424.`;super(s,{code:o.code,status:o.status})}};e(o,"status",500),e(o,"code","E_INCOMPATIBLE_VERSION"),e(o,"help","This error indicates that the encoded value is from a version which is newer than the version of the decoder.");let b=o;exports.BaseException=a;exports.E_CIRCULAR_REFERENCE=f;exports.E_ENCODING_FAILED=$;exports.E_INCOMPATIBLE_VERSION=b;exports.E_INVALID_VERSION=v;exports.E_NOT_AN_ENCODED_VALUE=x;exports.E_UNDECODABLE_VALUE=p;exports.E_UNENCODABLE_VALUE=g;
|
|
2
|
+
//# sourceMappingURL=exceptions-iBYg29S4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions-iBYg29S4.js","sources":["../src/private/exceptions.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\n\n/**\n * Base exception class that extends the native Error class.\n * Provides a foundation for all custom exceptions with additional metadata\n * like error codes, status codes, and help descriptions.\n */\nexport class BaseException extends Error {\n /**\n * Define the error metadata as static properties to avoid\n * setting them repeatedly on the error instance\n */\n declare static help?: string\n declare static code?: string\n declare static status?: number\n declare static message?: string\n\n /**\n * Name of the class that raised the exception.\n */\n name: string\n\n /**\n * Optional help description for the error. You can use it to define additional\n * human readable information for the error.\n */\n declare help?: string\n\n /**\n * A machine readable error code. This will allow the error handling logic\n * to narrow down exceptions based upon the error code.\n */\n declare code?: string\n\n /**\n * A status code for the error. Usually helpful when converting errors\n * to HTTP responses.\n */\n status: number\n\n /**\n * Creates a new BaseException instance.\n *\n * @param message - The error message. If not provided, uses the static message from the constructor.\n * @param options - Additional options including error cause, code, and status.\n */\n constructor(message?: string, options?: ErrorOptions & { code?: string; status?: number }) {\n super(message, options)\n\n const ErrorConstructor = this.constructor as typeof BaseException\n\n this.name = ErrorConstructor.name\n this.message = message || ErrorConstructor.message || ''\n this.status = options?.status || ErrorConstructor.status || 500\n\n const code = options?.code || ErrorConstructor.code\n if (code !== undefined) {\n this.code = code\n }\n\n const help = ErrorConstructor.help\n if (help !== undefined) {\n this.help = help\n }\n\n Error.captureStackTrace(this, ErrorConstructor)\n }\n\n /**\n * Returns the constructor name for the Symbol.toStringTag property.\n *\n * @returns The name of the exception class.\n */\n get [Symbol.toStringTag]() {\n return this.constructor.name\n }\n\n /**\n * Returns a string representation of the exception.\n * Includes the error code in brackets if available.\n *\n * @returns A formatted string representation of the exception.\n */\n toString() {\n if (this.code) {\n return `${this.name} [${this.code}]: ${this.message}`\n }\n return `${this.name}: ${this.message}`\n }\n}\n\n/**\n * Exception thrown when a value cannot be encoded.\n * This indicates that the value type is not supported by the encoder.\n */\nexport class E_UNENCODABLE_VALUE extends BaseException {\n static status = 500\n static code = 'E_UNENCODABLE_VALUE'\n\n /**\n * Creates a new E_UNENCODABLE_VALUE exception.\n *\n * @param value - The value that could not be encoded.\n */\n constructor(value: unknown) {\n const message = `Value of type ${typeof value} (${String(value)}) is not encodable.`\n super(message, {\n code: E_UNENCODABLE_VALUE.code,\n status: E_UNENCODABLE_VALUE.status,\n })\n }\n}\n\n/**\n * Exception thrown when encoding fails due to an underlying error.\n * This wraps the original error as the cause for better error tracing.\n */\nexport class E_ENCODING_FAILED extends BaseException {\n static status = 500\n static code = 'E_ENCODING_FAILED'\n\n /**\n * Creates a new E_ENCODING_FAILED exception.\n *\n * @param value - The value that failed to encode.\n * @param cause - The underlying error that caused the encoding to fail.\n */\n constructor(value: unknown, cause: unknown) {\n const message = `Value of type ${typeof value} (${String(value)}) is not encodable.`\n super(message, {\n code: E_ENCODING_FAILED.code,\n status: E_ENCODING_FAILED.status,\n cause,\n })\n }\n}\n\n/**\n * Exception thrown when a circular reference is detected during encoding.\n * Circular references cannot be encoded and must be avoided.\n */\nexport class E_CIRCULAR_REFERENCE extends BaseException {\n static status = 500\n static code = 'E_CIRCULAR_REFERENCE'\n\n /**\n * Creates a new E_CIRCULAR_REFERENCE exception.\n */\n constructor() {\n const message = `Circular reference detected.`\n super(message, {\n code: E_CIRCULAR_REFERENCE.code,\n status: E_CIRCULAR_REFERENCE.status,\n })\n }\n}\n\n/**\n * Exception thrown when a value with an unknown or unsupported type cannot be decoded.\n */\nexport class E_UNDECODABLE_VALUE extends BaseException {\n static status = 500\n static code = 'E_UNDECODABLE_VALUE'\n\n /**\n * Creates a new E_UNDECODABLE_VALUE exception.\n *\n * @param type - The type string that could not be decoded.\n */\n constructor(type: string) {\n const message = `Value of type ${type} cannot be decoded.`\n super(message, {\n code: E_UNDECODABLE_VALUE.code,\n status: E_UNDECODABLE_VALUE.status,\n })\n }\n}\n\n/**\n * Exception thrown when attempting to decode a value that is not a valid encoded value.\n * This indicates the input string is not in the expected encoded format.\n */\nexport class E_NOT_AN_ENCODED_VALUE extends BaseException {\n static status = 500\n static code = 'E_NOT_AN_ENCODED_VALUE'\n\n /**\n * Creates a new E_NOT_AN_ENCODED_VALUE exception.\n *\n * @param value - The string value that is not a valid encoded value.\n */\n constructor(value: string) {\n const message = `Value \"${value}\" is not a valid encoded value.`\n super(message, {\n code: E_NOT_AN_ENCODED_VALUE.code,\n status: E_NOT_AN_ENCODED_VALUE.status,\n })\n }\n}\n\n/**\n * Exception thrown when an invalid version string is encountered.\n */\nexport class E_INVALID_VERSION extends BaseException {\n static status = 500\n static code = 'E_INVALID_VERSION'\n\n /**\n * Creates a new E_INVALID_VERSION exception.\n *\n * @param version - The invalid version string.\n */\n constructor(version: string) {\n const message = `Invalid version \"${version}\"`\n super(message, {\n code: E_INVALID_VERSION.code,\n status: E_INVALID_VERSION.status,\n })\n }\n}\n\n/**\n * Exception thrown when attempting to decode data encoded with an incompatible version.\n * This typically occurs when the encoded data is from a newer version than the decoder supports.\n */\nexport class E_INCOMPATIBLE_VERSION extends BaseException {\n static status = 500\n static code = 'E_INCOMPATIBLE_VERSION'\n static help =\n 'This error indicates that the encoded value is from a version which is newer than the version of the decoder.'\n\n /**\n * Creates a new E_INCOMPATIBLE_VERSION exception.\n *\n * @param version - The incompatible version string from the encoded data.\n */\n constructor(version: string) {\n const message = `Encoded data version ${version} is not compatible with the current version ${__VERSION__}.`\n super(message, {\n code: E_INCOMPATIBLE_VERSION.code,\n status: E_INCOMPATIBLE_VERSION.status,\n })\n }\n}\n"],"names":["BaseException","message","options","__publicField","ErrorConstructor","code","help","_E_UNENCODABLE_VALUE","value","E_UNENCODABLE_VALUE","_E_ENCODING_FAILED","cause","E_ENCODING_FAILED","_E_CIRCULAR_REFERENCE","E_CIRCULAR_REFERENCE","_E_UNDECODABLE_VALUE","type","E_UNDECODABLE_VALUE","_E_NOT_AN_ENCODED_VALUE","E_NOT_AN_ENCODED_VALUE","_E_INVALID_VERSION","version","E_INVALID_VERSION","_E_INCOMPATIBLE_VERSION","E_INCOMPATIBLE_VERSION"],"mappings":"iLAOO,MAAMA,UAAsB,KAAM,CAuCvC,YAAYC,EAAkBC,EAA6D,CACzF,MAAMD,EAASC,CAAO,EA3BxBC,EAAA,aAkBAA,EAAA,eAWE,MAAMC,EAAmB,KAAK,YAE9B,KAAK,KAAOA,EAAiB,KAC7B,KAAK,QAAUH,GAAWG,EAAiB,SAAW,GACtD,KAAK,QAASF,GAAA,YAAAA,EAAS,SAAUE,EAAiB,QAAU,IAE5D,MAAMC,GAAOH,GAAA,YAAAA,EAAS,OAAQE,EAAiB,KAC3CC,IAAS,SACX,KAAK,KAAOA,GAGd,MAAMC,EAAOF,EAAiB,KAC1BE,IAAS,SACX,KAAK,KAAOA,GAGd,MAAM,kBAAkB,KAAMF,CAAgB,CAChD,CAOA,IAAK,OAAO,WAAW,GAAI,CACzB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AANF,EAsBA,MAAMG,EAAN,MAAMA,UAA+BlB,CAAc,CASxD,YAAYQ,EAAe,CACzB,MAAMP,EAAU,UAAUO,CAAK,kCAC/B,MAAMP,EAAS,CACb,KAAMiB,EAAuB,KAC7B,OAAQA,EAAuB,MAAA,CAChC,CACH,CACF,EAfEf,EADWe,EACJ,SAAS,KAChBf,EAFWe,EAEJ,OAAO,0BAFT,IAAMC,EAAND,EAqBA,MAAME,EAAN,MAAMA,UAA0BpB,CAAc,CASnD,YAAYqB,EAAiB,CAC3B,MAAMpB,EAAU,oBAAoBoB,CAAO,IAC3C,MAAMpB,EAAS,CACb,KAAMmB,EAAkB,KACxB,OAAQA,EAAkB,MAAA,CAC3B,CACH,CACF,EAfEjB,EADWiB,EACJ,SAAS,KAChBjB,EAFWiB,EAEJ,OAAO,qBAFT,IAAME,EAANF,EAsBA,MAAMG,EAAN,MAAMA,UAA+BvB,CAAc,CAWxD,YAAYqB,EAAiB,CAC3B,MAAMpB,EAAU,wBAAwBoB,CAAO,qEAC/C,MAAMpB,EAAS,CACb,KAAMsB,EAAuB,KAC7B,OAAQA,EAAuB,MAAA,CAChC,CACH,CACF,EAjBEpB,EADWoB,EACJ,SAAS,KAChBpB,EAFWoB,EAEJ,OAAO,0BACdpB,EAHWoB,EAGJ,OACL,iHAJG,IAAMC,EAAND"}
|
package/exceptions.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("./exceptions-iBYg29S4.js");exports.E_CIRCULAR_REFERENCE=E.E_CIRCULAR_REFERENCE;exports.E_ENCODING_FAILED=E.E_ENCODING_FAILED;exports.E_INCOMPATIBLE_VERSION=E.E_INCOMPATIBLE_VERSION;exports.E_INVALID_VERSION=E.E_INVALID_VERSION;exports.E_NOT_AN_ENCODED_VALUE=E.E_NOT_AN_ENCODED_VALUE;exports.E_UNDECODABLE_VALUE=E.E_UNDECODABLE_VALUE;exports.E_UNENCODABLE_VALUE=E.E_UNENCODABLE_VALUE;
|
|
2
|
+
//# sourceMappingURL=exceptions.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/exceptions.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exceptions thrown by the encoder/decoder
|
|
3
|
+
* @module @nhtio/encoder/exceptions
|
|
4
|
+
*
|
|
5
|
+
* @primaryExport
|
|
6
|
+
*/
|
|
7
|
+
export type { BaseException } from './private/exceptions';
|
|
8
|
+
export { E_NOT_AN_ENCODED_VALUE, E_INVALID_VERSION, E_INCOMPATIBLE_VERSION, E_ENCODING_FAILED, E_CIRCULAR_REFERENCE, E_UNENCODABLE_VALUE, E_UNDECODABLE_VALUE, } from './private/exceptions';
|
package/exceptions.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { a as N, b as A, f as I, e as L, d as a, c as C, E as D } from "./exceptions-BHfZbUPp.mjs";
|
|
2
|
+
export {
|
|
3
|
+
N as E_CIRCULAR_REFERENCE,
|
|
4
|
+
A as E_ENCODING_FAILED,
|
|
5
|
+
I as E_INCOMPATIBLE_VERSION,
|
|
6
|
+
L as E_INVALID_VERSION,
|
|
7
|
+
a as E_NOT_AN_ENCODED_VALUE,
|
|
8
|
+
C as E_UNDECODABLE_VALUE,
|
|
9
|
+
D as E_UNENCODABLE_VALUE
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=exceptions.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|