@digitaldefiance/i18n-lib 1.3.12 → 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.
Files changed (148) hide show
  1. package/README.md +4 -0
  2. package/package.json +12 -27
  3. package/src/active-context.ts +30 -0
  4. package/src/component-definition.ts +11 -0
  5. package/src/component-registration.ts +13 -0
  6. package/src/component-registry.ts +392 -0
  7. package/src/context-error-type.ts +3 -0
  8. package/src/context-error.ts +16 -0
  9. package/src/context-manager.ts +71 -0
  10. package/src/context.ts +90 -0
  11. package/src/core-i18n.ts +609 -0
  12. package/src/core-string-key.ts +49 -0
  13. package/src/create-translation-adapter.ts +47 -0
  14. package/src/currency-code.ts +35 -0
  15. package/{dist/currency-format.d.ts → src/currency-format.ts} +5 -4
  16. package/src/currency.ts +52 -0
  17. package/src/default-config.ts +199 -0
  18. package/src/enum-registry.ts +138 -0
  19. package/src/global-active-context.ts +255 -0
  20. package/src/handleable.ts +79 -0
  21. package/src/i-global-active-context.ts +59 -0
  22. package/src/i-handleable-error-options.ts +6 -0
  23. package/src/i-handleable.ts +5 -0
  24. package/src/i18n-config.ts +29 -0
  25. package/{dist/i18n-context.d.ts → src/i18n-context.ts} +7 -6
  26. package/src/i18n-engine.ts +491 -0
  27. package/{dist/index.d.ts → src/index.ts} +10 -1
  28. package/{dist/language-codes.d.ts → src/language-codes.ts} +23 -11
  29. package/src/language-definition.ts +13 -0
  30. package/src/language-registry.ts +292 -0
  31. package/src/plugin-i18n-engine.ts +520 -0
  32. package/src/plugin-translatable-generic-error.ts +106 -0
  33. package/src/plugin-translatable-handleable-generic.ts +60 -0
  34. package/src/plugin-typed-handleable.ts +77 -0
  35. package/src/registry-config.ts +15 -0
  36. package/src/registry-error-type.ts +12 -0
  37. package/src/registry-error.ts +74 -0
  38. package/src/strict-types.ts +35 -0
  39. package/src/template.ts +63 -0
  40. package/src/timezone.ts +20 -0
  41. package/src/translatable.ts +15 -0
  42. package/src/translation-engine.ts +8 -0
  43. package/src/translation-request.ts +12 -0
  44. package/src/translation-response.ts +8 -0
  45. package/src/typed-error.ts +384 -0
  46. package/src/typed-handleable.ts +70 -0
  47. package/{dist/types.d.ts → src/types.ts} +75 -20
  48. package/src/unified-translator.ts +96 -0
  49. package/src/utils.ts +213 -0
  50. package/src/validation-config.ts +11 -0
  51. package/src/validation-result.ts +12 -0
  52. package/dist/active-context.d.ts +0 -29
  53. package/dist/active-context.js +0 -2
  54. package/dist/component-definition.d.ts +0 -11
  55. package/dist/component-definition.js +0 -2
  56. package/dist/component-registration.d.ts +0 -9
  57. package/dist/component-registration.js +0 -2
  58. package/dist/component-registry.d.ts +0 -68
  59. package/dist/component-registry.js +0 -245
  60. package/dist/context-error-type.d.ts +0 -3
  61. package/dist/context-error-type.js +0 -7
  62. package/dist/context-error.d.ts +0 -6
  63. package/dist/context-error.js +0 -15
  64. package/dist/context-manager.d.ts +0 -33
  65. package/dist/context-manager.js +0 -61
  66. package/dist/context.d.ts +0 -44
  67. package/dist/context.js +0 -69
  68. package/dist/core-i18n.d.ts +0 -62
  69. package/dist/core-i18n.js +0 -477
  70. package/dist/core-string-key.d.ts +0 -42
  71. package/dist/core-string-key.js +0 -50
  72. package/dist/create-translation-adapter.d.ts +0 -20
  73. package/dist/create-translation-adapter.js +0 -36
  74. package/dist/currency-code.d.ts +0 -19
  75. package/dist/currency-code.js +0 -36
  76. package/dist/currency-format.js +0 -2
  77. package/dist/currency.d.ts +0 -11
  78. package/dist/currency.js +0 -48
  79. package/dist/default-config.d.ts +0 -32
  80. package/dist/default-config.js +0 -101
  81. package/dist/enum-registry.d.ts +0 -44
  82. package/dist/enum-registry.js +0 -100
  83. package/dist/global-active-context.d.ts +0 -50
  84. package/dist/global-active-context.js +0 -177
  85. package/dist/handleable.d.ts +0 -13
  86. package/dist/handleable.js +0 -56
  87. package/dist/i-global-active-context.d.ts +0 -22
  88. package/dist/i-global-active-context.js +0 -2
  89. package/dist/i-handleable-error-options.d.ts +0 -6
  90. package/dist/i-handleable-error-options.js +0 -2
  91. package/dist/i-handleable.d.ts +0 -5
  92. package/dist/i-handleable.js +0 -2
  93. package/dist/i18n-config.d.ts +0 -20
  94. package/dist/i18n-config.js +0 -2
  95. package/dist/i18n-context.js +0 -2
  96. package/dist/i18n-engine.d.ts +0 -178
  97. package/dist/i18n-engine.js +0 -338
  98. package/dist/index.js +0 -83
  99. package/dist/language-codes.js +0 -31
  100. package/dist/language-definition.d.ts +0 -13
  101. package/dist/language-definition.js +0 -2
  102. package/dist/language-registry.d.ts +0 -113
  103. package/dist/language-registry.js +0 -216
  104. package/dist/plugin-i18n-engine.d.ts +0 -146
  105. package/dist/plugin-i18n-engine.js +0 -360
  106. package/dist/plugin-translatable-generic-error.d.ts +0 -29
  107. package/dist/plugin-translatable-generic-error.js +0 -66
  108. package/dist/plugin-translatable-handleable-generic.d.ts +0 -28
  109. package/dist/plugin-translatable-handleable-generic.js +0 -40
  110. package/dist/plugin-typed-handleable.d.ts +0 -14
  111. package/dist/plugin-typed-handleable.js +0 -45
  112. package/dist/registry-config.d.ts +0 -14
  113. package/dist/registry-config.js +0 -2
  114. package/dist/registry-error-type.d.ts +0 -12
  115. package/dist/registry-error-type.js +0 -16
  116. package/dist/registry-error.d.ts +0 -18
  117. package/dist/registry-error.js +0 -45
  118. package/dist/strict-types.d.ts +0 -18
  119. package/dist/strict-types.js +0 -17
  120. package/dist/template.d.ts +0 -12
  121. package/dist/template.js +0 -30
  122. package/dist/timezone.d.ts +0 -11
  123. package/dist/timezone.js +0 -22
  124. package/dist/translatable-generic-error.d.ts +0 -29
  125. package/dist/translatable-generic-error.js +0 -66
  126. package/dist/translatable-handleable-generic.d.ts +0 -28
  127. package/dist/translatable-handleable-generic.js +0 -40
  128. package/dist/translatable.d.ts +0 -5
  129. package/dist/translatable.js +0 -11
  130. package/dist/translation-engine.d.ts +0 -8
  131. package/dist/translation-engine.js +0 -2
  132. package/dist/translation-request.d.ts +0 -9
  133. package/dist/translation-request.js +0 -2
  134. package/dist/translation-response.d.ts +0 -8
  135. package/dist/translation-response.js +0 -2
  136. package/dist/typed-error.d.ts +0 -72
  137. package/dist/typed-error.js +0 -251
  138. package/dist/typed-handleable.d.ts +0 -14
  139. package/dist/typed-handleable.js +0 -40
  140. package/dist/types.js +0 -18
  141. package/dist/unified-translator.d.ts +0 -30
  142. package/dist/unified-translator.js +0 -68
  143. package/dist/utils.d.ts +0 -64
  144. package/dist/utils.js +0 -130
  145. package/dist/validation-config.d.ts +0 -11
  146. package/dist/validation-config.js +0 -2
  147. package/dist/validation-result.d.ts +0 -12
  148. package/dist/validation-result.js +0 -2
@@ -0,0 +1,384 @@
1
+ // Legacy imports (for backward compatibility)
2
+ import { DefaultStringKey, Language, StringKey } from './default-config';
3
+ import { I18nEngine } from './i18n-engine';
4
+
5
+ // New plugin architecture imports
6
+ // CoreLanguageCode is deprecated - using string for flexibility
7
+ import { CoreStringKey } from './core-string-key';
8
+ import { PluginI18nEngine } from './plugin-i18n-engine';
9
+ import { TranslationEngine } from './translation-engine';
10
+
11
+ export type { TranslationEngine };
12
+
13
+ /**
14
+ * Type constraint to ensure reasonMap has entries for all enum values
15
+ */
16
+ export type CompleteReasonMap<
17
+ TEnum extends Record<string, string | number>,
18
+ TStringKey extends string,
19
+ > = Record<TEnum[keyof TEnum], TStringKey>;
20
+
21
+ /**
22
+ * Base typed error class with common patterns
23
+ */
24
+ export abstract class BaseTypedError<
25
+ TEnum extends Record<string, string>,
26
+ > extends Error {
27
+ constructor(
28
+ public readonly type: TEnum[keyof TEnum],
29
+ message: string,
30
+ public readonly metadata?: Record<string, any>,
31
+ ) {
32
+ super(message);
33
+ this.name = this.constructor.name;
34
+ }
35
+
36
+ /**
37
+ * Create a simple typed error without engine dependency
38
+ */
39
+ static createSimple<
40
+ TEnum extends Record<string, string>,
41
+ TError extends BaseTypedError<TEnum>,
42
+ >(
43
+ this: new (
44
+ type: TEnum[keyof TEnum],
45
+ message: string,
46
+ metadata?: Record<string, any>,
47
+ ) => TError,
48
+ type: TEnum[keyof TEnum],
49
+ message: string,
50
+ metadata?: Record<string, any>,
51
+ ): TError {
52
+ return new this(type, message, metadata);
53
+ }
54
+
55
+ /**
56
+ * Create a typed error with translation support
57
+ */
58
+ static createTranslated<
59
+ TEnum extends Record<string, string>,
60
+ TStringKey extends string,
61
+ TError extends BaseTypedError<TEnum>,
62
+ >(
63
+ this: new (
64
+ type: TEnum[keyof TEnum],
65
+ message: string,
66
+ metadata?: Record<string, any>,
67
+ ) => TError,
68
+ engine: TranslationEngine,
69
+ type: TEnum[keyof TEnum],
70
+ reasonMap: CompleteReasonMap<TEnum, TStringKey>,
71
+ variables?: Record<string, string | number>,
72
+ language?: string,
73
+ metadata?: Record<string, any>,
74
+ ): TError {
75
+ const key = reasonMap[type];
76
+ let message: string;
77
+
78
+ if (key && engine) {
79
+ // Try to translate the error message using the engine
80
+ message = engine.safeTranslate(key, variables, language);
81
+ } else {
82
+ // Fallback to a basic English message
83
+ message = `Error: ${type}${
84
+ metadata ? ` - ${JSON.stringify(metadata)}` : ''
85
+ }`;
86
+ }
87
+
88
+ return new this(type, message, metadata);
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Legacy TypedError that ensures complete enum coverage (for backward compatibility)
94
+ */
95
+ export abstract class TypedError<
96
+ TEnum extends Record<string, string>,
97
+ TStringKey extends string = StringKey,
98
+ > extends Error {
99
+ constructor(
100
+ engine: I18nEngine<TStringKey, Language, Record<string, any>>,
101
+ public readonly type: TEnum[keyof TEnum],
102
+ public readonly reasonMap: CompleteReasonMap<TEnum, TStringKey>,
103
+ public readonly language?: Language,
104
+ public readonly otherVars?: Record<string, string | number>,
105
+ ) {
106
+ const key = reasonMap[type];
107
+ if (!key)
108
+ throw new Error(
109
+ engine.translate(
110
+ DefaultStringKey.Error_MissingTranslationKeyTemplate as any,
111
+ { type },
112
+ language,
113
+ ),
114
+ );
115
+ super(engine.translate(key, otherVars, language));
116
+ this.name = this.constructor.name;
117
+ }
118
+ }
119
+
120
+ /**
121
+ * Plugin-based TypedError that works with the new component registration system
122
+ */
123
+ export abstract class PluginTypedError<
124
+ TEnum extends Record<string, string>,
125
+ TStringKey extends string,
126
+ TLanguages extends string = string,
127
+ > extends Error {
128
+ constructor(
129
+ engine: PluginI18nEngine<TLanguages>,
130
+ public readonly componentId: string,
131
+ public readonly type: TEnum[keyof TEnum],
132
+ public readonly reasonMap: CompleteReasonMap<TEnum, TStringKey>,
133
+ public readonly language?: TLanguages,
134
+ public readonly otherVars?: Record<string, string | number>,
135
+ ) {
136
+ const key = reasonMap[type];
137
+
138
+ // If key is not found in the reason map, use core error message
139
+ if (!key) {
140
+ const errorMsg = engine.safeTranslate(
141
+ 'core',
142
+ CoreStringKey.Error_StringKeyNotFoundTemplate,
143
+ {
144
+ stringKey: String(type),
145
+ componentId: componentId,
146
+ },
147
+ language,
148
+ );
149
+ throw new Error(errorMsg);
150
+ }
151
+
152
+ // Translate the error message using the component and string key
153
+ const translatedMessage = engine.safeTranslate(
154
+ componentId,
155
+ key,
156
+ otherVars,
157
+ language,
158
+ );
159
+ super(translatedMessage);
160
+ this.name = this.constructor.name;
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Core system TypedError using the core component strings
166
+ */
167
+ export abstract class CoreTypedError<
168
+ TEnum extends Record<string, string>,
169
+ > extends Error {
170
+ constructor(
171
+ engine: PluginI18nEngine<string>,
172
+ public readonly type: TEnum[keyof TEnum],
173
+ public readonly reasonMap: CompleteReasonMap<TEnum, CoreStringKey>,
174
+ public readonly language?: string,
175
+ public readonly otherVars?: Record<string, string | number>,
176
+ ) {
177
+ const key = reasonMap[type];
178
+
179
+ // If key is not found in the reason map, use a fallback error
180
+ if (!key) {
181
+ const errorMsg = engine.safeTranslate(
182
+ 'core',
183
+ CoreStringKey.Error_StringKeyNotFoundTemplate,
184
+ {
185
+ stringKey: String(type),
186
+ componentId: 'core',
187
+ },
188
+ language,
189
+ );
190
+ throw new Error(errorMsg);
191
+ }
192
+
193
+ // Translate the error message using the core component
194
+ const translatedMessage = engine.safeTranslate(
195
+ 'core',
196
+ key,
197
+ otherVars,
198
+ language,
199
+ );
200
+ super(translatedMessage);
201
+ this.name = this.constructor.name;
202
+ }
203
+ }
204
+
205
+ /**
206
+ * Helper function to create a plugin-based TypedError with automatic engine detection
207
+ */
208
+ export function createPluginTypedError<
209
+ TEnum extends Record<string, string>,
210
+ TStringKey extends string,
211
+ TLanguages extends string = string,
212
+ >(
213
+ componentId: string,
214
+ type: TEnum[keyof TEnum],
215
+ reasonMap: CompleteReasonMap<TEnum, TStringKey>,
216
+ otherVars?: Record<string, string | number>,
217
+ language?: TLanguages,
218
+ instanceKey?: string,
219
+ ): Error {
220
+ const engine = PluginI18nEngine.getInstance<TLanguages>(instanceKey);
221
+
222
+ return new (class extends PluginTypedError<TEnum, TStringKey, TLanguages> {
223
+ constructor() {
224
+ super(engine, componentId, type, reasonMap, language, otherVars);
225
+ }
226
+ })();
227
+ }
228
+
229
+ /**
230
+ * Helper function to create a core system TypedError with automatic engine detection
231
+ */
232
+ export function createCoreTypedError<TEnum extends Record<string, string>>(
233
+ type: TEnum[keyof TEnum],
234
+ reasonMap: CompleteReasonMap<TEnum, CoreStringKey>,
235
+ otherVars?: Record<string, string | number>,
236
+ language?: string,
237
+ instanceKey?: string,
238
+ ): Error {
239
+ const engine = PluginI18nEngine.getInstance<string>(instanceKey);
240
+
241
+ return new (class extends CoreTypedError<TEnum> {
242
+ constructor() {
243
+ super(engine, type, reasonMap, language, otherVars);
244
+ }
245
+ })();
246
+ }
247
+
248
+ /**
249
+ * Create a simple error with translation support (generalized pattern from RegistryError)
250
+ */
251
+ export function createTranslatedError<
252
+ TEnum extends Record<string, string>,
253
+ TStringKey extends string,
254
+ >(
255
+ engine: TranslationEngine,
256
+ componentId: string,
257
+ type: TEnum[keyof TEnum],
258
+ reasonMap: Record<TEnum[keyof TEnum], TStringKey>,
259
+ variables?: Record<string, string | number>,
260
+ language?: string,
261
+ metadata?: Record<string, any>,
262
+ errorName?: string,
263
+ ): Error {
264
+ const key = reasonMap[type];
265
+ let message: string;
266
+
267
+ if (key && engine) {
268
+ try {
269
+ // Try to translate the error message using the engine
270
+ message = engine.safeTranslate(key, variables, language);
271
+ } catch (translationError) {
272
+ // Fallback if translation fails
273
+ message = `Error: ${type}${
274
+ metadata ? ` - ${JSON.stringify(metadata)}` : ''
275
+ }`;
276
+ }
277
+ } else {
278
+ // Fallback to a basic English message
279
+ message = `Error: ${type}${
280
+ metadata ? ` - ${JSON.stringify(metadata)}` : ''
281
+ }`;
282
+ }
283
+
284
+ const error = new Error(message);
285
+ error.name = errorName || 'TranslatedError';
286
+ (error as any).type = type;
287
+ (error as any).metadata = metadata;
288
+
289
+ return error;
290
+ }
291
+
292
+ /**
293
+ * Example usage of the new plugin-based TypedError system
294
+ */
295
+
296
+ // Example 1: Core system error using CoreStringKey
297
+ /*
298
+ enum DatabaseErrorType {
299
+ ConnectionFailed = 'connectionFailed',
300
+ QueryTimeout = 'queryTimeout',
301
+ AccessDenied = 'accessDenied'
302
+ }
303
+
304
+ const coreErrorReasonMap: CompleteReasonMap<typeof DatabaseErrorType, CoreStringKey> = {
305
+ [DatabaseErrorType.ConnectionFailed]: CoreStringKey.Error_NetworkError,
306
+ [DatabaseErrorType.QueryTimeout]: CoreStringKey.Error_InternalServer,
307
+ [DatabaseErrorType.AccessDenied]: CoreStringKey.Error_AccessDenied
308
+ };
309
+
310
+ class DatabaseError extends CoreTypedError<typeof DatabaseErrorType> {
311
+ constructor(
312
+ engine: PluginI18nEngine<CoreLanguageCode>,
313
+ type: DatabaseErrorType,
314
+ otherVars?: Record<string, string | number>,
315
+ language?: CoreLanguage
316
+ ) {
317
+ super(engine, type, coreErrorReasonMap, language, otherVars);
318
+ }
319
+ }
320
+
321
+ // Usage:
322
+ // const engine = PluginI18nEngine.getInstance<string>();
323
+ // throw new DatabaseError(engine, DatabaseErrorType.ConnectionFailed);
324
+ */
325
+
326
+ // Example 2: Custom component error with custom strings
327
+ /*
328
+ enum UserErrorType {
329
+ UserNotFound = 'userNotFound',
330
+ InvalidCredentials = 'invalidCredentials',
331
+ AccountLocked = 'accountLocked'
332
+ }
333
+
334
+ enum UserErrorStringKey {
335
+ UserNotFoundMessage = 'userNotFoundMessage',
336
+ InvalidCredentialsMessage = 'invalidCredentialsMessage',
337
+ AccountLockedMessage = 'accountLockedMessage'
338
+ }
339
+
340
+ const userErrorReasonMap: CompleteReasonMap<typeof UserErrorType, UserErrorStringKey> = {
341
+ [UserErrorType.UserNotFound]: UserErrorStringKey.UserNotFoundMessage,
342
+ [UserErrorType.InvalidCredentials]: UserErrorStringKey.InvalidCredentialsMessage,
343
+ [UserErrorType.AccountLocked]: UserErrorStringKey.AccountLockedMessage
344
+ };
345
+
346
+ class UserError extends PluginTypedError<typeof UserErrorType, UserErrorStringKey, string> {
347
+ constructor(
348
+ engine: PluginI18nEngine<string>,
349
+ type: UserErrorType,
350
+ otherVars?: Record<string, string | number>,
351
+ language?: string
352
+ ) {
353
+ super(engine, 'user-system', type, userErrorReasonMap, language, otherVars);
354
+ }
355
+ }
356
+
357
+ // Usage:
358
+ // const engine = PluginI18nEngine.getInstance<string>();
359
+ // throw new UserError(engine, UserErrorType.UserNotFound, { username: 'john_doe' });
360
+ */
361
+
362
+ // Example 3: Using helper functions for simpler error creation
363
+ /*
364
+ // Define your error types and mappings
365
+ enum ApiErrorType {
366
+ Timeout = 'timeout',
367
+ NotFound = 'notFound'
368
+ }
369
+
370
+ const apiErrorMap: CompleteReasonMap<typeof ApiErrorType, CoreStringKey> = {
371
+ [ApiErrorType.Timeout]: CoreStringKey.Error_NetworkError,
372
+ [ApiErrorType.NotFound]: CoreStringKey.Error_NotFound
373
+ };
374
+
375
+ // Create errors using helper functions
376
+ function throwApiError(type: ApiErrorType, vars?: Record<string, string | number>) {
377
+ throw createCoreTypedError(type, apiErrorMap, vars);
378
+ }
379
+
380
+ // Usage:
381
+ // throwApiError(ApiErrorType.NotFound, { resource: 'user' });
382
+ */
383
+
384
+ // Export the type for external use (already exported above)
@@ -0,0 +1,70 @@
1
+ import { CoreLanguageCode } from './core-i18n';
2
+ import { CoreStringKey } from './core-string-key';
3
+ import { HandleableError } from './handleable';
4
+ import { IHandleable } from './i-handleable';
5
+ import { HandleableErrorOptions } from './i-handleable-error-options';
6
+ import { PluginI18nEngine } from './plugin-i18n-engine';
7
+ import { CompleteReasonMap, TranslationEngine } from './typed-error';
8
+
9
+ export class TypedHandleableError<
10
+ TEnum extends Record<string, string>,
11
+ TStringKey extends string,
12
+ TLanguage extends CoreLanguageCode = CoreLanguageCode,
13
+ >
14
+ extends HandleableError
15
+ implements IHandleable
16
+ {
17
+ public readonly type: TEnum[keyof TEnum];
18
+ public readonly reasonMap: CompleteReasonMap<TEnum, TStringKey>;
19
+ public readonly engine: TranslationEngine<TStringKey>;
20
+ public readonly language?: TLanguage;
21
+ public readonly otherVars?: Record<string, string | number>;
22
+
23
+ constructor(
24
+ type: TEnum[keyof TEnum],
25
+ reasonMap: CompleteReasonMap<TEnum, TStringKey>,
26
+ engine: TranslationEngine<TStringKey>,
27
+ language?: TLanguage,
28
+ otherVars?: Record<string, string | number>,
29
+ options?: HandleableErrorOptions,
30
+ ) {
31
+ const key = reasonMap[type];
32
+ if (!key) {
33
+ const coreEngine = PluginI18nEngine.getInstance<TLanguage>();
34
+ throw new Error(
35
+ coreEngine.translate(
36
+ 'core',
37
+ CoreStringKey.Error_MissingTranslationKeyTemplate,
38
+ {
39
+ stringKey: key as string,
40
+ },
41
+ ),
42
+ );
43
+ }
44
+
45
+ let message: string = String(type);
46
+ try {
47
+ const keyString = key as TStringKey;
48
+ const translated = engine.translate(keyString, otherVars, language);
49
+ message = String(translated || type);
50
+ } catch (error) {
51
+ message = String(type);
52
+ }
53
+
54
+ super(new Error(message), options);
55
+
56
+ this.type = type;
57
+ this.reasonMap = reasonMap;
58
+ this.language = language;
59
+ this.otherVars = otherVars;
60
+ this.engine = engine;
61
+ }
62
+
63
+ public override toJSON(): Record<string, unknown> {
64
+ const baseJson = super.toJSON();
65
+ return {
66
+ ...baseJson,
67
+ type: this.type,
68
+ };
69
+ }
70
+ }
@@ -1,91 +1,146 @@
1
1
  import { ComponentDefinition } from './component-definition';
2
2
  import { ComponentRegistration } from './component-registration';
3
3
  import { LanguageDefinition } from './language-definition';
4
+
4
5
  /**
5
6
  * Standard language context spaces
6
7
  */
7
8
  export type LanguageContextSpace = 'admin' | 'user';
9
+
8
10
  /**
9
11
  * Default currency code
10
12
  */
11
- export declare const DefaultCurrencyCode: string;
13
+ export const DefaultCurrencyCode: string = 'USD';
14
+
12
15
  /**
13
16
  * Default timezone
14
17
  */
15
- export declare const DefaultTimezone: string;
18
+ export const DefaultTimezone: string = 'UTC';
19
+
16
20
  /**
17
21
  * Currency position type
18
22
  */
19
23
  export type CurrencyPosition = 'prefix' | 'postfix' | 'infix';
24
+
20
25
  /**
21
26
  * Collection of localized strings for a specific language
22
27
  */
23
- export type StringsCollection<TStringKey extends string> = Partial<Record<TStringKey, string>>;
28
+ export type StringsCollection<TStringKey extends string> = Partial<
29
+ Record<TStringKey, string>
30
+ >;
31
+
24
32
  /**
25
33
  * Mapping of languages to their respective string collections
26
34
  */
27
- export type MasterStringsCollection<TStringKey extends string, TLanguage extends string> = Partial<Record<TLanguage, StringsCollection<TStringKey>>>;
35
+ export type MasterStringsCollection<
36
+ TStringKey extends string,
37
+ TLanguage extends string,
38
+ > = Partial<Record<TLanguage, StringsCollection<TStringKey>>>;
39
+
28
40
  /**
29
41
  * Mapping of language codes to their respective languages
30
42
  */
31
- export type LanguageCodeCollection<TLanguage extends string> = Partial<Record<TLanguage, string>>;
43
+ export type LanguageCodeCollection<TLanguage extends string> = Partial<
44
+ Record<TLanguage, string>
45
+ >;
46
+
32
47
  /**
33
48
  * Mapping of enumeration values to their translations in multiple languages
34
49
  */
35
- export type EnumTranslationMap<TEnum extends string | number, TLanguage extends string> = Partial<Record<TLanguage, Partial<Record<TEnum, string>>>>;
50
+ export type EnumTranslationMap<
51
+ TEnum extends string | number,
52
+ TLanguage extends string,
53
+ > = Partial<Record<TLanguage, Partial<Record<TEnum, string>>>>;
54
+
36
55
  /**
37
56
  * String collection for a specific language and component
38
57
  */
39
58
  export type ComponentStrings<TStringKeys extends string> = {
40
- [K in TStringKeys]: string;
59
+ [K in TStringKeys]: string;
41
60
  };
61
+
42
62
  /**
43
63
  * Partial string collection (used during registration before validation)
44
64
  */
45
65
  export type PartialComponentStrings<TStringKeys extends string> = {
46
- [K in TStringKeys]?: string;
66
+ [K in TStringKeys]?: string;
47
67
  };
68
+
48
69
  /**
49
70
  * Language strings for a component across all registered languages
50
71
  */
51
- export type ComponentLanguageStrings<TStringKeys extends string, TLanguages extends string> = {
52
- [L in TLanguages]: ComponentStrings<TStringKeys>;
72
+ export type ComponentLanguageStrings<
73
+ TStringKeys extends string,
74
+ TLanguages extends string,
75
+ > = {
76
+ [L in TLanguages]: ComponentStrings<TStringKeys>;
53
77
  };
78
+
54
79
  /**
55
80
  * Partial language strings (used during registration before validation)
56
81
  */
57
- export type PartialComponentLanguageStrings<TStringKeys extends string, TLanguages extends string> = {
58
- [L in TLanguages]?: PartialComponentStrings<TStringKeys>;
82
+ export type PartialComponentLanguageStrings<
83
+ TStringKeys extends string,
84
+ TLanguages extends string,
85
+ > = {
86
+ [L in TLanguages]?: PartialComponentStrings<TStringKeys>;
59
87
  };
88
+
60
89
  /**
61
90
  * Generic translation type for any enumeration
62
91
  */
63
92
  export type EnumTranslation<T extends string | number> = {
64
- [K in T]: string;
93
+ [K in T]: string;
65
94
  };
95
+
66
96
  /**
67
97
  * Generic language translation type for any enumeration
68
98
  */
69
- export type EnumLanguageTranslation<T extends string | number, TLanguage extends string = string> = Partial<{
70
- [L in TLanguage]: EnumTranslation<T>;
99
+ export type EnumLanguageTranslation<
100
+ T extends string | number,
101
+ TLanguage extends string = string,
102
+ > = Partial<{
103
+ [L in TLanguage]: EnumTranslation<T>;
71
104
  }>;
105
+
72
106
  /**
73
107
  * Type utility to extract string keys from a component definition
74
108
  */
75
- export type ExtractStringKeys<T> = T extends ComponentDefinition<infer K> ? K : never;
109
+ export type ExtractStringKeys<T> = T extends ComponentDefinition<infer K>
110
+ ? K
111
+ : never;
112
+
76
113
  /**
77
114
  * Type utility to extract languages from registry
78
115
  */
79
- export type ExtractLanguages<T> = T extends LanguageDefinition ? T['id'] : never;
116
+ export type ExtractLanguages<T> = T extends LanguageDefinition
117
+ ? T['id']
118
+ : never;
119
+
80
120
  /**
81
121
  * Type utility to create a strongly typed component registration
82
122
  */
83
- export type CreateComponentRegistration<TComponent extends ComponentDefinition<any>, TLanguages extends string> = ComponentRegistration<ExtractStringKeys<TComponent>, TLanguages>;
123
+ export type CreateComponentRegistration<
124
+ TComponent extends ComponentDefinition<any>,
125
+ TLanguages extends string,
126
+ > = ComponentRegistration<ExtractStringKeys<TComponent>, TLanguages>;
127
+
84
128
  /**
85
129
  * Utility type to ensure all string keys are provided for all languages
86
130
  */
87
- export type CompleteComponentStrings<TStringKeys extends string, TLanguages extends string> = ComponentLanguageStrings<TStringKeys, TLanguages>;
131
+ export type CompleteComponentStrings<
132
+ TStringKeys extends string,
133
+ TLanguages extends string,
134
+ > = ComponentLanguageStrings<TStringKeys, TLanguages>;
135
+
88
136
  /**
89
137
  * Helper function to create typed translations for an enumeration
90
138
  */
91
- export declare function createTranslations<T extends string | number, TLanguage extends string>(translations: EnumLanguageTranslation<T, TLanguage>): EnumLanguageTranslation<T, TLanguage>;
139
+ export function createTranslations<
140
+ T extends string | number,
141
+ TLanguage extends string,
142
+ >(
143
+ translations: EnumLanguageTranslation<T, TLanguage>,
144
+ ): EnumLanguageTranslation<T, TLanguage> {
145
+ return translations;
146
+ }