@digitaldefiance/i18n-lib 1.3.11 → 1.3.13
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 +8 -0
- package/package.json +12 -27
- package/src/active-context.ts +30 -0
- package/src/component-definition.ts +11 -0
- package/src/component-registration.ts +13 -0
- package/src/component-registry.ts +392 -0
- package/src/context-error-type.ts +3 -0
- package/src/context-error.ts +16 -0
- package/src/context-manager.ts +71 -0
- package/src/context.ts +90 -0
- package/src/core-i18n.ts +609 -0
- package/src/core-string-key.ts +49 -0
- package/src/create-translation-adapter.ts +47 -0
- package/src/currency-code.ts +35 -0
- package/{dist/currency-format.d.ts → src/currency-format.ts} +5 -4
- package/src/currency.ts +52 -0
- package/src/default-config.ts +199 -0
- package/src/enum-registry.ts +138 -0
- package/src/global-active-context.ts +255 -0
- package/src/handleable.ts +79 -0
- package/src/i-global-active-context.ts +59 -0
- package/src/i-handleable-error-options.ts +6 -0
- package/src/i-handleable.ts +5 -0
- package/src/i18n-config.ts +29 -0
- package/{dist/i18n-context.d.ts → src/i18n-context.ts} +7 -6
- package/src/i18n-engine.ts +491 -0
- package/{dist/index.d.ts → src/index.ts} +10 -1
- package/{dist/language-codes.d.ts → src/language-codes.ts} +23 -11
- package/src/language-definition.ts +13 -0
- package/src/language-registry.ts +292 -0
- package/src/plugin-i18n-engine.ts +520 -0
- package/src/plugin-translatable-generic-error.ts +106 -0
- package/src/plugin-translatable-handleable-generic.ts +60 -0
- package/src/plugin-typed-handleable.ts +77 -0
- package/src/registry-config.ts +15 -0
- package/src/registry-error-type.ts +12 -0
- package/src/registry-error.ts +74 -0
- package/src/strict-types.ts +35 -0
- package/src/template.ts +63 -0
- package/src/timezone.ts +20 -0
- package/src/translatable.ts +15 -0
- package/src/translation-engine.ts +8 -0
- package/src/translation-request.ts +12 -0
- package/src/translation-response.ts +8 -0
- package/src/typed-error.ts +384 -0
- package/src/typed-handleable.ts +70 -0
- package/{dist/types.d.ts → src/types.ts} +75 -20
- package/src/unified-translator.ts +96 -0
- package/src/utils.ts +213 -0
- package/src/validation-config.ts +11 -0
- package/src/validation-result.ts +12 -0
- package/dist/active-context.d.ts +0 -29
- package/dist/active-context.js +0 -2
- package/dist/component-definition.d.ts +0 -11
- package/dist/component-definition.js +0 -2
- package/dist/component-registration.d.ts +0 -9
- package/dist/component-registration.js +0 -2
- package/dist/component-registry.d.ts +0 -68
- package/dist/component-registry.js +0 -245
- package/dist/context-error-type.d.ts +0 -3
- package/dist/context-error-type.js +0 -7
- package/dist/context-error.d.ts +0 -6
- package/dist/context-error.js +0 -15
- package/dist/context-manager.d.ts +0 -33
- package/dist/context-manager.js +0 -61
- package/dist/context.d.ts +0 -44
- package/dist/context.js +0 -69
- package/dist/core-i18n.d.ts +0 -62
- package/dist/core-i18n.js +0 -477
- package/dist/core-string-key.d.ts +0 -42
- package/dist/core-string-key.js +0 -50
- package/dist/create-translation-adapter.d.ts +0 -20
- package/dist/create-translation-adapter.js +0 -36
- package/dist/currency-code.d.ts +0 -19
- package/dist/currency-code.js +0 -36
- package/dist/currency-format.js +0 -2
- package/dist/currency.d.ts +0 -11
- package/dist/currency.js +0 -48
- package/dist/default-config.d.ts +0 -32
- package/dist/default-config.js +0 -101
- package/dist/enum-registry.d.ts +0 -44
- package/dist/enum-registry.js +0 -100
- package/dist/global-active-context.d.ts +0 -50
- package/dist/global-active-context.js +0 -177
- package/dist/handleable.d.ts +0 -13
- package/dist/handleable.js +0 -56
- package/dist/i-global-active-context.d.ts +0 -22
- package/dist/i-global-active-context.js +0 -2
- package/dist/i-handleable-error-options.d.ts +0 -6
- package/dist/i-handleable-error-options.js +0 -2
- package/dist/i-handleable.d.ts +0 -5
- package/dist/i-handleable.js +0 -2
- package/dist/i18n-config.d.ts +0 -20
- package/dist/i18n-config.js +0 -2
- package/dist/i18n-context.js +0 -2
- package/dist/i18n-engine.d.ts +0 -178
- package/dist/i18n-engine.js +0 -338
- package/dist/index.js +0 -83
- package/dist/language-codes.js +0 -31
- package/dist/language-definition.d.ts +0 -13
- package/dist/language-definition.js +0 -2
- package/dist/language-registry.d.ts +0 -113
- package/dist/language-registry.js +0 -216
- package/dist/plugin-i18n-engine.d.ts +0 -146
- package/dist/plugin-i18n-engine.js +0 -360
- package/dist/plugin-translatable-generic-error.d.ts +0 -29
- package/dist/plugin-translatable-generic-error.js +0 -66
- package/dist/plugin-translatable-handleable-generic.d.ts +0 -28
- package/dist/plugin-translatable-handleable-generic.js +0 -40
- package/dist/plugin-typed-handleable.d.ts +0 -14
- package/dist/plugin-typed-handleable.js +0 -45
- package/dist/registry-config.d.ts +0 -14
- package/dist/registry-config.js +0 -2
- package/dist/registry-error-type.d.ts +0 -12
- package/dist/registry-error-type.js +0 -16
- package/dist/registry-error.d.ts +0 -18
- package/dist/registry-error.js +0 -45
- package/dist/strict-types.d.ts +0 -18
- package/dist/strict-types.js +0 -17
- package/dist/template.d.ts +0 -12
- package/dist/template.js +0 -30
- package/dist/timezone.d.ts +0 -11
- package/dist/timezone.js +0 -22
- package/dist/translatable-generic-error.d.ts +0 -29
- package/dist/translatable-generic-error.js +0 -66
- package/dist/translatable-handleable-generic.d.ts +0 -28
- package/dist/translatable-handleable-generic.js +0 -40
- package/dist/translatable.d.ts +0 -5
- package/dist/translatable.js +0 -11
- package/dist/translation-engine.d.ts +0 -8
- package/dist/translation-engine.js +0 -2
- package/dist/translation-request.d.ts +0 -9
- package/dist/translation-request.js +0 -2
- package/dist/translation-response.d.ts +0 -8
- package/dist/translation-response.js +0 -2
- package/dist/typed-error.d.ts +0 -72
- package/dist/typed-error.js +0 -251
- package/dist/typed-handleable.d.ts +0 -14
- package/dist/typed-handleable.js +0 -40
- package/dist/types.js +0 -18
- package/dist/unified-translator.d.ts +0 -30
- package/dist/unified-translator.js +0 -68
- package/dist/utils.d.ts +0 -64
- package/dist/utils.js +0 -130
- package/dist/validation-config.d.ts +0 -11
- package/dist/validation-config.js +0 -2
- package/dist/validation-result.d.ts +0 -12
- package/dist/validation-result.js +0 -2
package/dist/registry-error.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RegistryError = void 0;
|
|
4
|
-
// CoreLanguageCode is deprecated - using string
|
|
5
|
-
const core_string_key_1 = require("./core-string-key");
|
|
6
|
-
const registry_error_type_1 = require("./registry-error-type");
|
|
7
|
-
const typed_error_1 = require("./typed-error");
|
|
8
|
-
/**
|
|
9
|
-
* Reason map for registry errors
|
|
10
|
-
*/
|
|
11
|
-
const REGISTRY_ERROR_REASON_MAP = {
|
|
12
|
-
[registry_error_type_1.RegistryErrorType.ComponentNotFound]: core_string_key_1.CoreStringKey.Error_ComponentNotFoundTemplate,
|
|
13
|
-
[registry_error_type_1.RegistryErrorType.DuplicateComponent]: core_string_key_1.CoreStringKey.Error_DuplicateComponentTemplate,
|
|
14
|
-
[registry_error_type_1.RegistryErrorType.DuplicateLanguage]: core_string_key_1.CoreStringKey.Error_DuplicateLanguageTemplate,
|
|
15
|
-
[registry_error_type_1.RegistryErrorType.IncompleteRegistration]: core_string_key_1.CoreStringKey.Error_IncompleteRegistrationTemplate,
|
|
16
|
-
[registry_error_type_1.RegistryErrorType.LanguageNotFound]: core_string_key_1.CoreStringKey.Error_LanguageNotFoundTemplate,
|
|
17
|
-
[registry_error_type_1.RegistryErrorType.StringKeyNotFound]: core_string_key_1.CoreStringKey.Error_StringKeyNotFoundTemplate,
|
|
18
|
-
[registry_error_type_1.RegistryErrorType.ValidationFailed]: core_string_key_1.CoreStringKey.Error_ValidationFailedTemplate,
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Registry error class that can work with plugin engines
|
|
22
|
-
*/
|
|
23
|
-
class RegistryError extends Error {
|
|
24
|
-
constructor(type, message, metadata) {
|
|
25
|
-
super(message);
|
|
26
|
-
this.type = type;
|
|
27
|
-
this.metadata = metadata;
|
|
28
|
-
this.name = 'RegistryError';
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Create a registry error with translation support
|
|
32
|
-
*/
|
|
33
|
-
static createWithEngine(engine, type, variables, language, metadata) {
|
|
34
|
-
const error = (0, typed_error_1.createTranslatedError)(engine, 'core', type, REGISTRY_ERROR_REASON_MAP, variables, language, metadata, 'RegistryError');
|
|
35
|
-
// Convert to RegistryError instance
|
|
36
|
-
return new RegistryError(type, error.message, metadata);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Create a simple RegistryError without engine dependency
|
|
40
|
-
*/
|
|
41
|
-
static createSimple(type, message, metadata) {
|
|
42
|
-
return new RegistryError(type, message, metadata);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.RegistryError = RegistryError;
|
package/dist/strict-types.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enforces that for each language L, all string keys K are present.
|
|
3
|
-
*/
|
|
4
|
-
export type CompleteLanguageStrings<TStringKey extends string> = {
|
|
5
|
-
[K in TStringKey]: string;
|
|
6
|
-
};
|
|
7
|
-
export type CompleteComponentLanguageStrings<TStringKey extends string, TLanguages extends string> = {
|
|
8
|
-
[L in TLanguages]: CompleteLanguageStrings<TStringKey>;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Helper to assert at compile-time that an object is a complete component language map.
|
|
12
|
-
* Returns the object unchanged at runtime.
|
|
13
|
-
*/
|
|
14
|
-
export declare function createCompleteComponentStrings<TStringKey extends string, TLanguages extends string>(obj: CompleteComponentLanguageStrings<TStringKey, TLanguages>): CompleteComponentLanguageStrings<TStringKey, TLanguages>;
|
|
15
|
-
/**
|
|
16
|
-
* Utility to extract missing keys at compile time (identity, purely for readability)
|
|
17
|
-
*/
|
|
18
|
-
export declare function defineLanguageStrings<TStringKey extends string>(strings: CompleteLanguageStrings<TStringKey>): CompleteLanguageStrings<TStringKey>;
|
package/dist/strict-types.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createCompleteComponentStrings = createCompleteComponentStrings;
|
|
4
|
-
exports.defineLanguageStrings = defineLanguageStrings;
|
|
5
|
-
/**
|
|
6
|
-
* Helper to assert at compile-time that an object is a complete component language map.
|
|
7
|
-
* Returns the object unchanged at runtime.
|
|
8
|
-
*/
|
|
9
|
-
function createCompleteComponentStrings(obj) {
|
|
10
|
-
return obj;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Utility to extract missing keys at compile time (identity, purely for readability)
|
|
14
|
-
*/
|
|
15
|
-
function defineLanguageStrings(strings) {
|
|
16
|
-
return strings;
|
|
17
|
-
}
|
package/dist/template.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Template processing utilities for i18n
|
|
3
|
-
*/
|
|
4
|
-
export type EnumKeys<T> = keyof T;
|
|
5
|
-
/**
|
|
6
|
-
* Recursive type to validate that all enum keys in the template string exist in the provided enum type
|
|
7
|
-
*/
|
|
8
|
-
export type IsValidEnumTemplate<T extends string, TEnum> = T extends `${string}{{${string}.${infer Key}}}${infer Rest}` ? Key extends EnumKeys<TEnum> ? IsValidEnumTemplate<Rest, TEnum> : false : true;
|
|
9
|
-
/**
|
|
10
|
-
* Template function that processes {{EnumName.EnumKey}} patterns
|
|
11
|
-
*/
|
|
12
|
-
export declare function createTemplateProcessor<TEnum extends Record<string, string>, TLanguage extends string>(enumObj: TEnum, translateFn: (key: TEnum[keyof TEnum], vars?: Record<string, string | number>, language?: TLanguage) => string, enumName: string): <T extends string>(str: IsValidEnumTemplate<T, TEnum> extends true ? T : never, language?: TLanguage, ...otherVars: Record<string, string | number>[]) => string;
|
package/dist/template.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTemplateProcessor = createTemplateProcessor;
|
|
4
|
-
/**
|
|
5
|
-
* Template function that processes {{EnumName.EnumKey}} patterns
|
|
6
|
-
*/
|
|
7
|
-
function createTemplateProcessor(enumObj, translateFn, enumName) {
|
|
8
|
-
return function t(str, language, ...otherVars) {
|
|
9
|
-
let varIndex = 0;
|
|
10
|
-
const pattern = new RegExp(`\\{\\{${enumName}\\.(\\w+)\\}\\}`, 'g');
|
|
11
|
-
// First replace enum patterns
|
|
12
|
-
let result = str.replace(pattern, (match, enumKey) => {
|
|
13
|
-
const enumValue = enumObj[enumKey];
|
|
14
|
-
if (!enumValue) {
|
|
15
|
-
return match; // Return original if enum key not found
|
|
16
|
-
}
|
|
17
|
-
const needsVars = enumValue
|
|
18
|
-
.toLowerCase()
|
|
19
|
-
.endsWith('template');
|
|
20
|
-
const vars = needsVars ? otherVars[varIndex++] ?? {} : {};
|
|
21
|
-
return translateFn(enumValue, vars, language);
|
|
22
|
-
});
|
|
23
|
-
// Then replace any remaining variables from all otherVars
|
|
24
|
-
const allVars = otherVars.reduce((acc, vars) => ({ ...acc, ...vars }), {});
|
|
25
|
-
result = result.replace(/\{(\w+)\}/g, (match, varName) => {
|
|
26
|
-
return allVars[varName] !== undefined ? String(allVars[varName]) : match;
|
|
27
|
-
});
|
|
28
|
-
return result;
|
|
29
|
-
};
|
|
30
|
-
}
|
package/dist/timezone.d.ts
DELETED
package/dist/timezone.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Timezone = void 0;
|
|
4
|
-
const utils_1 = require("./utils");
|
|
5
|
-
/**
|
|
6
|
-
* Class representing a validated timezone.
|
|
7
|
-
*/
|
|
8
|
-
class Timezone {
|
|
9
|
-
constructor(timezone) {
|
|
10
|
-
if (!(0, utils_1.isValidTimezone)(timezone)) {
|
|
11
|
-
throw new Error(`Invalid timezone: ${timezone}`);
|
|
12
|
-
}
|
|
13
|
-
this._timezone = timezone;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Gets the timezone value.
|
|
17
|
-
*/
|
|
18
|
-
get value() {
|
|
19
|
-
return this._timezone;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.Timezone = Timezone;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { PluginI18nEngine } from './plugin-i18n-engine';
|
|
2
|
-
/**
|
|
3
|
-
* Generic translatable error that works with any plugin engine and component
|
|
4
|
-
*/
|
|
5
|
-
export declare class TranslatableGenericError<TStringKey extends string = string, TLanguage extends string = string> extends Error {
|
|
6
|
-
readonly stringKey: TStringKey;
|
|
7
|
-
readonly componentId: string;
|
|
8
|
-
readonly language?: TLanguage;
|
|
9
|
-
readonly variables?: Record<string, string | number>;
|
|
10
|
-
readonly metadata?: Record<string, any>;
|
|
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);
|
|
21
|
-
/**
|
|
22
|
-
* Create error with explicit engine instance
|
|
23
|
-
*/
|
|
24
|
-
static withEngine<TStringKey extends string, TLanguage extends string>(engine: PluginI18nEngine<TLanguage>, componentId: string, stringKey: TStringKey, variables?: Record<string, string | number>, language?: TLanguage, metadata?: Record<string, any>): TranslatableGenericError<TStringKey, TLanguage>;
|
|
25
|
-
/**
|
|
26
|
-
* Retranslate the error message in a different language
|
|
27
|
-
*/
|
|
28
|
-
retranslate(language: TLanguage, instanceKey?: string): string;
|
|
29
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TranslatableGenericError = void 0;
|
|
4
|
-
const plugin_i18n_engine_1 = require("./plugin-i18n-engine");
|
|
5
|
-
/**
|
|
6
|
-
* Generic translatable error that works with any plugin engine and component
|
|
7
|
-
*/
|
|
8
|
-
class TranslatableGenericError extends Error {
|
|
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) {
|
|
19
|
-
let translatedMessage;
|
|
20
|
-
try {
|
|
21
|
-
const engine = plugin_i18n_engine_1.PluginI18nEngine.getInstance(instanceKey);
|
|
22
|
-
translatedMessage = engine.safeTranslate(componentId, stringKey, variables, language);
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
// If engine not found or translation fails, use fallback format
|
|
26
|
-
translatedMessage = `[${componentId}.${stringKey}]`;
|
|
27
|
-
}
|
|
28
|
-
super(translatedMessage);
|
|
29
|
-
this.name = 'TranslatableGenericError';
|
|
30
|
-
this.stringKey = stringKey;
|
|
31
|
-
this.componentId = componentId;
|
|
32
|
-
this.language = language;
|
|
33
|
-
this.variables = variables;
|
|
34
|
-
this.metadata = metadata;
|
|
35
|
-
// Ensure proper prototype chain for instanceof checks across transpiled targets
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Create error with explicit engine instance
|
|
39
|
-
*/
|
|
40
|
-
static withEngine(engine, componentId, stringKey, variables, language, metadata) {
|
|
41
|
-
const translatedMessage = engine.safeTranslate(componentId, stringKey, variables, language);
|
|
42
|
-
const error = Object.create(TranslatableGenericError.prototype);
|
|
43
|
-
Error.call(error, translatedMessage);
|
|
44
|
-
error.name = 'TranslatableGenericError';
|
|
45
|
-
error.stringKey = stringKey;
|
|
46
|
-
error.componentId = componentId;
|
|
47
|
-
error.language = language;
|
|
48
|
-
error.variables = variables;
|
|
49
|
-
error.metadata = metadata;
|
|
50
|
-
error.message = translatedMessage;
|
|
51
|
-
return error;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Retranslate the error message in a different language
|
|
55
|
-
*/
|
|
56
|
-
retranslate(language, instanceKey) {
|
|
57
|
-
try {
|
|
58
|
-
const engine = plugin_i18n_engine_1.PluginI18nEngine.getInstance(instanceKey);
|
|
59
|
-
return engine.safeTranslate(this.componentId, this.stringKey, this.variables, language);
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
return `[${this.componentId}.${this.stringKey}]`;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
exports.TranslatableGenericError = TranslatableGenericError;
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
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;
|
package/dist/translatable.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { I18nEngine } from './i18n-engine';
|
|
2
|
-
import { Language } from './default-config';
|
|
3
|
-
export declare class TranslatableError<TStringKey extends string> extends Error {
|
|
4
|
-
constructor(engine: I18nEngine<TStringKey, Language, any, any>, string: TStringKey, otherVars?: Record<string, string | number>, language?: Language);
|
|
5
|
-
}
|
package/dist/translatable.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TranslatableError = void 0;
|
|
4
|
-
class TranslatableError extends Error {
|
|
5
|
-
constructor(engine, string, otherVars, language) {
|
|
6
|
-
super(engine.translate(string, otherVars, language));
|
|
7
|
-
this.name = 'TranslatableError';
|
|
8
|
-
Object.setPrototypeOf(this, TranslatableError.prototype);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.TranslatableError = TranslatableError;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Minimal interface for translation engines
|
|
3
|
-
* Allows flexibility in what can be used as a translation engine
|
|
4
|
-
*/
|
|
5
|
-
export interface TranslationEngine<TStringKey extends string = string> {
|
|
6
|
-
translate: (key: TStringKey, vars?: Record<string, string | number>, lang?: any) => string;
|
|
7
|
-
safeTranslate: (key: TStringKey, vars?: Record<string, string | number>, lang?: any) => string;
|
|
8
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Translation request interface
|
|
3
|
-
*/
|
|
4
|
-
export interface TranslationRequest<TStringKeys extends string, TLanguages extends string> {
|
|
5
|
-
readonly componentId: string;
|
|
6
|
-
readonly stringKey: TStringKeys;
|
|
7
|
-
readonly language?: TLanguages;
|
|
8
|
-
readonly variables?: Record<string, string | number>;
|
|
9
|
-
}
|
package/dist/typed-error.d.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { Language, StringKey } from './default-config';
|
|
2
|
-
import { I18nEngine } from './i18n-engine';
|
|
3
|
-
import { CoreStringKey } from './core-string-key';
|
|
4
|
-
import { PluginI18nEngine } from './plugin-i18n-engine';
|
|
5
|
-
import { TranslationEngine } from './translation-engine';
|
|
6
|
-
export { TranslationEngine };
|
|
7
|
-
/**
|
|
8
|
-
* Type constraint to ensure reasonMap has entries for all enum values
|
|
9
|
-
*/
|
|
10
|
-
export type CompleteReasonMap<TEnum extends Record<string, string | number>, TStringKey extends string> = Record<TEnum[keyof TEnum], TStringKey>;
|
|
11
|
-
/**
|
|
12
|
-
* Base typed error class with common patterns
|
|
13
|
-
*/
|
|
14
|
-
export declare abstract class BaseTypedError<TEnum extends Record<string, string>, TStringKey extends string> extends Error {
|
|
15
|
-
readonly type: TEnum[keyof TEnum];
|
|
16
|
-
readonly metadata?: Record<string, any> | undefined;
|
|
17
|
-
constructor(type: TEnum[keyof TEnum], message: string, metadata?: Record<string, any> | undefined);
|
|
18
|
-
/**
|
|
19
|
-
* Create a simple typed error without engine dependency
|
|
20
|
-
*/
|
|
21
|
-
static createSimple<TEnum extends Record<string, string>, TStringKey extends string, TError extends BaseTypedError<TEnum, TStringKey>>(this: new (type: TEnum[keyof TEnum], message: string, metadata?: Record<string, any>) => TError, type: TEnum[keyof TEnum], message: string, metadata?: Record<string, any>): TError;
|
|
22
|
-
/**
|
|
23
|
-
* Create a typed error with translation support
|
|
24
|
-
*/
|
|
25
|
-
static createTranslated<TEnum extends Record<string, string>, TStringKey extends string, TError extends BaseTypedError<TEnum, TStringKey>>(this: new (type: TEnum[keyof TEnum], message: string, metadata?: Record<string, any>) => TError, engine: TranslationEngine, componentId: string, type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, TStringKey>, variables?: Record<string, string | number>, language?: string, metadata?: Record<string, any>): TError;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Legacy TypedError that ensures complete enum coverage (for backward compatibility)
|
|
29
|
-
*/
|
|
30
|
-
export declare abstract class TypedError<TEnum extends Record<string, string>, TStringKey extends string = StringKey> extends Error {
|
|
31
|
-
readonly type: TEnum[keyof TEnum];
|
|
32
|
-
readonly reasonMap: CompleteReasonMap<TEnum, TStringKey>;
|
|
33
|
-
readonly language?: Language | undefined;
|
|
34
|
-
readonly otherVars?: Record<string, string | number> | undefined;
|
|
35
|
-
constructor(engine: I18nEngine<TStringKey, Language, Record<string, any>>, type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, TStringKey>, language?: Language | undefined, otherVars?: Record<string, string | number> | undefined);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Plugin-based TypedError that works with the new component registration system
|
|
39
|
-
*/
|
|
40
|
-
export declare abstract class PluginTypedError<TEnum extends Record<string, string>, TStringKey extends string, TLanguages extends string = string> extends Error {
|
|
41
|
-
readonly componentId: string;
|
|
42
|
-
readonly type: TEnum[keyof TEnum];
|
|
43
|
-
readonly reasonMap: CompleteReasonMap<TEnum, TStringKey>;
|
|
44
|
-
readonly language?: TLanguages | undefined;
|
|
45
|
-
readonly otherVars?: Record<string, string | number> | undefined;
|
|
46
|
-
constructor(engine: PluginI18nEngine<TLanguages>, componentId: string, type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, TStringKey>, language?: TLanguages | undefined, otherVars?: Record<string, string | number> | undefined);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Core system TypedError using the core component strings
|
|
50
|
-
*/
|
|
51
|
-
export declare abstract class CoreTypedError<TEnum extends Record<string, string>> extends Error {
|
|
52
|
-
readonly type: TEnum[keyof TEnum];
|
|
53
|
-
readonly reasonMap: CompleteReasonMap<TEnum, CoreStringKey>;
|
|
54
|
-
readonly language?: string | undefined;
|
|
55
|
-
readonly otherVars?: Record<string, string | number> | undefined;
|
|
56
|
-
constructor(engine: PluginI18nEngine<string>, type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, CoreStringKey>, language?: string | undefined, otherVars?: Record<string, string | number> | undefined);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Helper function to create a plugin-based TypedError with automatic engine detection
|
|
60
|
-
*/
|
|
61
|
-
export declare function createPluginTypedError<TEnum extends Record<string, string>, TStringKey extends string, TLanguages extends string = string>(componentId: string, type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, TStringKey>, otherVars?: Record<string, string | number>, language?: TLanguages, instanceKey?: string): Error;
|
|
62
|
-
/**
|
|
63
|
-
* Helper function to create a core system TypedError with automatic engine detection
|
|
64
|
-
*/
|
|
65
|
-
export declare function createCoreTypedError<TEnum extends Record<string, string>>(type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, CoreStringKey>, otherVars?: Record<string, string | number>, language?: string, instanceKey?: string): Error;
|
|
66
|
-
/**
|
|
67
|
-
* Create a simple error with translation support (generalized pattern from RegistryError)
|
|
68
|
-
*/
|
|
69
|
-
export declare function createTranslatedError<TEnum extends Record<string, string>, TStringKey extends string>(engine: TranslationEngine, componentId: string, type: TEnum[keyof TEnum], reasonMap: Record<TEnum[keyof TEnum], TStringKey>, variables?: Record<string, string | number>, language?: string, metadata?: Record<string, any>, errorName?: string): Error;
|
|
70
|
-
/**
|
|
71
|
-
* Example usage of the new plugin-based TypedError system
|
|
72
|
-
*/
|