@digitaldefiance/i18n-lib 1.3.6 → 1.3.7
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/README.md +5 -0
- package/dist/handleable.d.ts +13 -0
- package/dist/handleable.js +56 -0
- package/dist/i-handleable-error-options.d.ts +6 -0
- package/dist/i-handleable-error-options.js +2 -0
- package/dist/i-handleable.d.ts +5 -0
- package/dist/i-handleable.js +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/translatable-handleable-generic.d.ts +28 -0
- package/dist/translatable-handleable-generic.js +40 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2274,6 +2274,11 @@ For issues, questions, or contributions:
|
|
|
2274
2274
|
|
|
2275
2275
|
## ChangeLog
|
|
2276
2276
|
|
|
2277
|
+
### Version 1.3.7
|
|
2278
|
+
|
|
2279
|
+
- Add handleable at i18n level
|
|
2280
|
+
- Add TranslatableGenericHandleable at i18n level
|
|
2281
|
+
|
|
2277
2282
|
### Version 1.3.6
|
|
2278
2283
|
|
|
2279
2284
|
- Simplify LanguageContextSpace and generics related to it
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { HandleableErrorOptions } from './i-handleable-error-options';
|
|
2
|
+
import { IHandleable } from './i-handleable';
|
|
3
|
+
export declare class HandleableError extends Error implements IHandleable {
|
|
4
|
+
readonly cause?: Error;
|
|
5
|
+
readonly statusCode: number;
|
|
6
|
+
readonly sourceData?: unknown;
|
|
7
|
+
private _handled;
|
|
8
|
+
constructor(source: Error, options?: HandleableErrorOptions);
|
|
9
|
+
get handled(): boolean;
|
|
10
|
+
set handled(value: boolean);
|
|
11
|
+
private serializeValue;
|
|
12
|
+
toJSON(): Record<string, unknown>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HandleableError = void 0;
|
|
4
|
+
class HandleableError extends Error {
|
|
5
|
+
constructor(source, options) {
|
|
6
|
+
super(source.message);
|
|
7
|
+
this.name = this.constructor.name;
|
|
8
|
+
this.cause = options?.cause ?? source;
|
|
9
|
+
this.statusCode = options?.statusCode ?? 500;
|
|
10
|
+
this._handled = options?.handled ?? false;
|
|
11
|
+
this.sourceData = options?.sourceData;
|
|
12
|
+
// Capture stack trace - prioritize source stack, then capture new one
|
|
13
|
+
if (source.stack) {
|
|
14
|
+
this.stack = source.stack;
|
|
15
|
+
}
|
|
16
|
+
else if (Error.captureStackTrace) {
|
|
17
|
+
Error.captureStackTrace(this, this.constructor);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
this.stack = new Error().stack;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
get handled() {
|
|
24
|
+
return this._handled;
|
|
25
|
+
}
|
|
26
|
+
set handled(value) {
|
|
27
|
+
this._handled = value;
|
|
28
|
+
}
|
|
29
|
+
serializeValue(value) {
|
|
30
|
+
if (value && typeof value === 'object' && 'toJSON' in value && typeof value.toJSON === 'function') {
|
|
31
|
+
return value.toJSON();
|
|
32
|
+
}
|
|
33
|
+
if (value instanceof Error) {
|
|
34
|
+
return value.message;
|
|
35
|
+
}
|
|
36
|
+
if (Array.isArray(value)) {
|
|
37
|
+
return value.map(item => this.serializeValue(item));
|
|
38
|
+
}
|
|
39
|
+
if (value && typeof value === 'object') {
|
|
40
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, this.serializeValue(v)]));
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
toJSON() {
|
|
45
|
+
return {
|
|
46
|
+
name: this.name,
|
|
47
|
+
message: this.message,
|
|
48
|
+
statusCode: this.statusCode,
|
|
49
|
+
handled: this.handled,
|
|
50
|
+
stack: this.stack,
|
|
51
|
+
cause: this.serializeValue(this.cause),
|
|
52
|
+
...(this.sourceData ? { sourceData: this.serializeValue(this.sourceData) } : {}),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.HandleableError = HandleableError;
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,9 @@ export * from './currency-format';
|
|
|
12
12
|
export * from './default-config';
|
|
13
13
|
export * from './enum-registry';
|
|
14
14
|
export * from './global-active-context';
|
|
15
|
+
export * from './handleable';
|
|
16
|
+
export * from './i-handleable';
|
|
17
|
+
export * from './i-handleable-error-options';
|
|
15
18
|
export * from './i-global-active-context';
|
|
16
19
|
export * from './i18n-context';
|
|
17
20
|
export * from './i18n-engine';
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,9 @@ __exportStar(require("./currency-format"), exports);
|
|
|
31
31
|
__exportStar(require("./default-config"), exports);
|
|
32
32
|
__exportStar(require("./enum-registry"), exports);
|
|
33
33
|
__exportStar(require("./global-active-context"), exports);
|
|
34
|
+
__exportStar(require("./handleable"), exports);
|
|
35
|
+
__exportStar(require("./i-handleable"), exports);
|
|
36
|
+
__exportStar(require("./i-handleable-error-options"), exports);
|
|
34
37
|
__exportStar(require("./i-global-active-context"), exports);
|
|
35
38
|
__exportStar(require("./i18n-context"), exports);
|
|
36
39
|
__exportStar(require("./i18n-engine"), exports);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { IHandleable } from './i-handleable';
|
|
2
|
+
import { TranslatableGenericError } from './translatable-generic-error';
|
|
3
|
+
/**
|
|
4
|
+
* Generic translatable error that works with any plugin engine and component
|
|
5
|
+
*/
|
|
6
|
+
export declare class TranslatableHandleableGenericError<TStringKey extends string = string, TLanguage extends string = string> extends TranslatableGenericError<TStringKey, TLanguage> implements IHandleable {
|
|
7
|
+
private _handled;
|
|
8
|
+
readonly cause?: Error;
|
|
9
|
+
readonly statusCode: number;
|
|
10
|
+
readonly sourceData?: unknown;
|
|
11
|
+
/**
|
|
12
|
+
* Create a translatable error
|
|
13
|
+
* @param componentId - The component ID to translate from
|
|
14
|
+
* @param stringKey - The translation key
|
|
15
|
+
* @param variables - Variables for interpolation
|
|
16
|
+
* @param language - Optional language override
|
|
17
|
+
* @param metadata - Additional error metadata
|
|
18
|
+
* @param instanceKey - Optional engine instance key
|
|
19
|
+
*/
|
|
20
|
+
constructor(componentId: string, stringKey: TStringKey, variables?: Record<string, string | number>, language?: TLanguage, metadata?: Record<string, any>, instanceKey?: string, handleableOptions?: {
|
|
21
|
+
statusCode?: number;
|
|
22
|
+
cause?: Error;
|
|
23
|
+
sourceData?: unknown;
|
|
24
|
+
});
|
|
25
|
+
get handled(): boolean;
|
|
26
|
+
set handled(value: boolean);
|
|
27
|
+
toJSON(): Record<string, unknown>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TranslatableHandleableGenericError = void 0;
|
|
4
|
+
const translatable_generic_error_1 = require("./translatable-generic-error");
|
|
5
|
+
/**
|
|
6
|
+
* Generic translatable error that works with any plugin engine and component
|
|
7
|
+
*/
|
|
8
|
+
class TranslatableHandleableGenericError extends translatable_generic_error_1.TranslatableGenericError {
|
|
9
|
+
/**
|
|
10
|
+
* Create a translatable error
|
|
11
|
+
* @param componentId - The component ID to translate from
|
|
12
|
+
* @param stringKey - The translation key
|
|
13
|
+
* @param variables - Variables for interpolation
|
|
14
|
+
* @param language - Optional language override
|
|
15
|
+
* @param metadata - Additional error metadata
|
|
16
|
+
* @param instanceKey - Optional engine instance key
|
|
17
|
+
*/
|
|
18
|
+
constructor(componentId, stringKey, variables, language, metadata, instanceKey, handleableOptions) {
|
|
19
|
+
super(componentId, stringKey, variables, language, metadata, instanceKey);
|
|
20
|
+
this._handled = false;
|
|
21
|
+
this.statusCode = handleableOptions?.statusCode ?? 500;
|
|
22
|
+
this.cause = handleableOptions?.cause;
|
|
23
|
+
this.sourceData = handleableOptions?.sourceData;
|
|
24
|
+
}
|
|
25
|
+
get handled() {
|
|
26
|
+
return this._handled;
|
|
27
|
+
}
|
|
28
|
+
set handled(value) {
|
|
29
|
+
this._handled = value;
|
|
30
|
+
}
|
|
31
|
+
toJSON() {
|
|
32
|
+
return {
|
|
33
|
+
statusCode: this.statusCode,
|
|
34
|
+
message: this.message,
|
|
35
|
+
cause: this.cause,
|
|
36
|
+
sourceData: this.sourceData,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.TranslatableHandleableGenericError = TranslatableHandleableGenericError;
|