intor-translator 1.4.2 → 1.4.3

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/dist/index.cjs CHANGED
@@ -121,7 +121,7 @@ var loading = rura.rura.createHook(
121
121
  };
122
122
  }
123
123
  const { loadingMessage } = config;
124
- if ("loadingMessage" in config) {
124
+ if (loadingMessage !== void 0) {
125
125
  return { early: true, output: loadingMessage };
126
126
  }
127
127
  },
@@ -140,7 +140,7 @@ var missing = rura.rura.createHook(
140
140
  };
141
141
  }
142
142
  const { missingMessage } = config;
143
- if ("missingMessage" in config) {
143
+ if (missingMessage !== void 0) {
144
144
  return { early: true, output: missingMessage };
145
145
  }
146
146
  return { early: true, output: key };
@@ -176,6 +176,7 @@ var DEFAULT_HOOKS = [
176
176
  format,
177
177
  interpolate
178
178
  ];
179
+ rura.rura.createPipeline(DEFAULT_HOOKS).debugHooks();
179
180
 
180
181
  // src/translators/base-translator/base-translator.ts
181
182
  var BaseTranslator = class {
@@ -250,12 +251,18 @@ function runTranslate(options) {
250
251
  function translate(options) {
251
252
  const { early, ctx, output } = runTranslate(options);
252
253
  if (early === true) return output;
254
+ if (ctx.finalMessage === void 0) {
255
+ throw new Error("Invariant violated: missing hook did not produce output");
256
+ }
253
257
  return ctx.finalMessage;
254
258
  }
255
259
 
256
260
  // src/translators/methods/translate-raw.ts
257
261
  function translateRaw(options) {
258
262
  const { ctx } = runTranslate(options);
263
+ if (ctx.rawValue === void 0) {
264
+ throw new Error("Invariant violated: missing hook did not produce output");
265
+ }
259
266
  return ctx.rawValue;
260
267
  }
261
268
 
package/dist/index.d.cts CHANGED
@@ -1,19 +1,5 @@
1
1
  import { RuraHook } from 'rura';
2
2
 
3
- type MessagePrimitive$1 = string | number | boolean | null;
4
- type MessageArray$1 = readonly MessageValue$1[];
5
- /**
6
- * A recursive message tree object.
7
- *
8
- * Represents the root message structure for a single locale
9
- * (i.e. the value of `LocaleMessages[locale]`).
10
- */
11
- interface MessageObject$1 {
12
- [key: string]: MessageValue$1;
13
- }
14
- /** A message value in the locale message tree. */
15
- type MessageValue$1 = MessagePrimitive$1 | MessageObject$1 | MessageArray$1;
16
-
17
3
  type MessagePrimitive = string | number | boolean | null;
18
4
  type MessageArray = readonly MessageValue[];
19
5
  /**
@@ -168,6 +154,16 @@ type NodeKeys<M, D extends number = DefaultDepth> = [D] extends [never] ? never
168
154
  type LeafKeys<M, D extends number = DefaultDepth> = [D] extends [never] ? never : M extends object ? {
169
155
  [K in keyof M]: M[K] extends MessageLeaf ? `${K & string}` : M[K] extends object ? `${K & string}.${LeafKeys<M[K], Prev[D]>}` : never;
170
156
  }[keyof M] : never;
157
+ /**
158
+ * Resolves the value type at a given dot-separated leaf key
159
+ * within a nested message object.
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * LeafValue<{ a: { b: { c: string } } }, "a.b.c"> // → string
164
+ * ```
165
+ */
166
+ type LeafValue<M, K extends string> = K extends `${infer Seg}.${infer Rest}` ? Seg extends keyof M ? LeafValue<M[Seg], Rest> : never : K extends keyof M ? M[K] : never;
171
167
 
172
168
  /**
173
169
  * Extracts all **node keys** from the messages
@@ -215,6 +211,13 @@ type LocalizedNodeKeys<M = unknown, L extends keyof M | "union" = "union", D ext
215
211
  * ```
216
212
  */
217
213
  type LocalizedLeafKeys<M = unknown, L extends keyof M | "union" = "union", D extends number = DefaultDepth> = M extends LocaleMessages ? L extends "union" ? LeafKeys<M[keyof M], D> : LeafKeys<M[Extract<L, keyof M>], D> : string;
214
+ /**
215
+ * Resolves the value type of a **localized leaf key**
216
+ * from the messages of a specified locale (or union of locales).
217
+ *
218
+ * - Fallback to `MessageValue` if M is not LocaleMessages
219
+ */
220
+ type LocalizedLeafValue<M = unknown, K extends string = string, L extends keyof M | "union" = "union"> = M extends LocaleMessages ? L extends "union" ? LeafValue<M[keyof M], K> : LeafValue<M[Extract<L, keyof M>], K> : MessageValue;
218
221
 
219
222
  /**
220
223
  * Resolves the type at a dot-separated key in a nested object.
@@ -250,6 +253,21 @@ type MessagesAtPreKey<T, PK extends string> = PK extends `${infer Head}.${infer
250
253
  * ```
251
254
  */
252
255
  type ScopedLeafKeys<M, PK extends string, L extends keyof M | "union" = "union", D extends number = DefaultDepth> = M extends LocaleMessages ? LocalizedMessagesUnion<M, L> extends infer Messages ? Messages extends MessageValue ? MessagesAtPreKey<Messages, PK> extends infer Scoped ? Scoped extends MessageObject ? LeafKeys<Scoped, D> : never : never : never : never : string;
256
+ /**
257
+ * Resolves the value type of a scoped leaf key (`K`)
258
+ * under a prefix path (`PK`) from localized messages.
259
+ *
260
+ * @example
261
+ * ```ts
262
+ * const messages = {
263
+ * en: { a: { b: { c: "hello" }, z: [123] } },
264
+ * };
265
+ *
266
+ * ScopedLeafValue<typeof messages, "a", "z">; // number[]
267
+ * ScopedLeafValue<typeof messages, "a.b", "c">; // string
268
+ * ```
269
+ */
270
+ type ScopedLeafValue<M, PK extends string, K extends string, L extends keyof M | "union" = "union"> = M extends LocaleMessages ? LocalizedMessagesUnion<M, L> extends infer Messages ? Messages extends MessageValue ? MessagesAtPreKey<Messages, PK> extends infer Scoped ? Scoped extends MessageObject ? LeafValue<Scoped, K> : never : never : never : never : MessageValue;
253
271
 
254
272
  /**
255
273
  * Configuration options for translation behavior.
@@ -276,13 +294,13 @@ type TranslateHandlers = {
276
294
  formatHandler?: FormatHandler;
277
295
  };
278
296
  /** Function called when translation is still loading. */
279
- type LoadingHandler<Result = unknown> = (ctx: HandlerContext) => Result;
297
+ type LoadingHandler = (ctx: HandlerContext) => MessageValue;
280
298
  /** Function called when no message is found for the given key. */
281
- type MissingHandler<Result = unknown> = (ctx: HandlerContext) => Result;
299
+ type MissingHandler = (ctx: HandlerContext) => MessageValue;
282
300
  /** Function to format a resolved message. */
283
- type FormatHandler<Result = unknown> = (ctx: HandlerContext & {
301
+ type FormatHandler = (ctx: HandlerContext & {
284
302
  rawString: string;
285
- }) => Result;
303
+ }) => MessageValue;
286
304
  /**
287
305
  * Snapshot of the translate pipeline context exposed to handlers.
288
306
  *
@@ -295,10 +313,8 @@ type HandlerContext = Readonly<Omit<TranslateContext, "finalMessage">>;
295
313
 
296
314
  /**
297
315
  * Context object shared across the translate pipeline.
298
- *
299
- * @template Result - Final translated value type.
300
316
  */
301
- interface TranslateContext<Result = unknown> {
317
+ interface TranslateContext {
302
318
  /** Configuration for the translate pipeline. */
303
319
  config: TranslateConfig;
304
320
  /** Current messages for translation */
@@ -318,16 +334,16 @@ interface TranslateContext<Result = unknown> {
318
334
  /** Raw string message before formatting. */
319
335
  rawString?: string;
320
336
  /** Message after formatting (e.g. ICU, custom formatters) */
321
- formattedMessage?: unknown;
337
+ formattedMessage?: MessageValue;
322
338
  /** Final value produced by the pipeline */
323
- finalMessage?: Result;
339
+ finalMessage?: MessageValue;
324
340
  /** Free-form metadata shared between hooks. */
325
341
  meta: Record<string, unknown>;
326
342
  }
327
343
  /**
328
344
  * A single step in the translate pipeline.
329
345
  */
330
- type TranslateHook = RuraHook<TranslateContext>;
346
+ type TranslateHook = RuraHook<TranslateContext, MessageValue>;
331
347
 
332
348
  /**
333
349
  * Options for initializing a translator
@@ -420,22 +436,22 @@ declare class CoreTranslator<M extends LocaleMessages | unknown = unknown, L ext
420
436
  /** Check if a key exists in the specified locale or current locale. */
421
437
  hasKey: <K extends LocalizedLeafKeys<M, L>>(key: K, targetLocale?: Locale<M>) => boolean;
422
438
  /** Get the translated message for a key, with optional replacements. */
423
- t: <Result = string, K extends LocalizedLeafKeys<M, L> = LocalizedLeafKeys<M, L>>(key: K, replacements?: Replacement) => Result;
439
+ t: <K extends LocalizedLeafKeys<M, L> = LocalizedLeafKeys<M, L>>(key: K, replacements?: Replacement) => LocalizedLeafValue<M, K, L>;
424
440
  /** Get the raw message value for a key without formatting or interpolation. */
425
- tRaw: <K extends LocalizedLeafKeys<M, L> = LocalizedLeafKeys<M, L>>(key: K, replacements?: Replacement) => MessageValue | undefined;
441
+ tRaw: <K extends LocalizedLeafKeys<M, L> = LocalizedLeafKeys<M, L>>(key: K, replacements?: Replacement) => LocalizedLeafValue<M, K, L>;
426
442
  }
427
443
 
428
444
  type ScopeTranslatorOptions<M> = CoreTranslatorOptions<M>;
429
- type ScopeTranslatorMethods<M extends LocaleMessages | unknown = unknown, L extends keyof M | "union" = "union", K = LocalizedLeafKeys<M, L>> = {
445
+ type ScopeTranslatorMethods<M extends LocaleMessages | unknown = unknown, L extends keyof M | "union" = "union", PK extends string | undefined = undefined, K extends string = PK extends string ? ScopedLeafKeys<M, PK, L> : LocalizedLeafKeys<M, L>> = {
430
446
  hasKey: (key?: K, targetLocale?: Locale<M>) => boolean;
431
- t: <Result = string>(key?: K, replacements?: Replacement) => Result;
432
- tRaw: (key?: K, replacements?: Replacement) => MessageValue$1 | undefined;
447
+ t: <Key extends K>(key?: Key, replacements?: Replacement) => PK extends string ? ScopedLeafValue<M, PK, Key, L> : LocalizedLeafValue<M, Key, L>;
448
+ tRaw: <Key extends K>(key?: Key, replacements?: Replacement) => PK extends string ? ScopedLeafValue<M, PK, Key, L> : LocalizedLeafValue<M, Key, L>;
433
449
  };
434
450
 
435
451
  declare class ScopeTranslator<M extends LocaleMessages | unknown = unknown, L extends keyof M | "union" = "union"> extends CoreTranslator<M> {
436
452
  constructor(options: ScopeTranslatorOptions<M>);
437
453
  /** Create a scoped translator with a prefix key for resolving nested message paths. */
438
- scoped<PK extends LocalizedNodeKeys<M, L> | undefined = undefined>(preKey?: PK): PK extends string ? ScopeTranslatorMethods<M, L, ScopedLeafKeys<M, PK, L>> : ScopeTranslatorMethods<M, L>;
454
+ scoped<PK extends LocalizedNodeKeys<M, L> | undefined = undefined>(preKey?: PK): PK extends string ? ScopeTranslatorMethods<M, L, PK> : ScopeTranslatorMethods<M, L>;
439
455
  }
440
456
 
441
457
  /** Semantic tag attributes map. */
@@ -504,4 +520,4 @@ interface Renderer<Output> {
504
520
  */
505
521
  declare function renderRichMessage<Output>(message: string, renderer: Renderer<Output>): Output[];
506
522
 
507
- export { type ASTNode, type Attributes, type DefaultDepth, type FallbackLocalesMap, type FormatHandler, type HandlerContext, type LeafKeys, type LoadingHandler, type Locale, type LocaleMessages, type LocalizedLeafKeys, type LocalizedMessagesUnion, type LocalizedNodeKeys, type MessageObject, type MessageValue, type MissingHandler, type NodeKeys, type Renderer, type Replacement, type ScopedLeafKeys, type TranslateConfig, type TranslateContext, type TranslateHandlers, type TranslateHook, ScopeTranslator as Translator, type ScopeTranslatorMethods as TranslatorMethods, type ScopeTranslatorOptions as TranslatorOptions, type TranslatorPlugin, parseRichMessage, renderRichMessage };
523
+ export { type ASTNode, type Attributes, type DefaultDepth, type FallbackLocalesMap, type FormatHandler, type HandlerContext, type LeafKeys, type LeafValue, type LoadingHandler, type Locale, type LocaleMessages, type LocalizedLeafKeys, type LocalizedLeafValue, type LocalizedMessagesUnion, type LocalizedNodeKeys, type MessageObject, type MessageValue, type MissingHandler, type NodeKeys, type Renderer, type Replacement, type ScopedLeafKeys, type ScopedLeafValue, type TranslateConfig, type TranslateContext, type TranslateHandlers, type TranslateHook, ScopeTranslator as Translator, type ScopeTranslatorMethods as TranslatorMethods, type ScopeTranslatorOptions as TranslatorOptions, type TranslatorPlugin, parseRichMessage, renderRichMessage };
package/dist/index.d.ts CHANGED
@@ -1,19 +1,5 @@
1
1
  import { RuraHook } from 'rura';
2
2
 
3
- type MessagePrimitive$1 = string | number | boolean | null;
4
- type MessageArray$1 = readonly MessageValue$1[];
5
- /**
6
- * A recursive message tree object.
7
- *
8
- * Represents the root message structure for a single locale
9
- * (i.e. the value of `LocaleMessages[locale]`).
10
- */
11
- interface MessageObject$1 {
12
- [key: string]: MessageValue$1;
13
- }
14
- /** A message value in the locale message tree. */
15
- type MessageValue$1 = MessagePrimitive$1 | MessageObject$1 | MessageArray$1;
16
-
17
3
  type MessagePrimitive = string | number | boolean | null;
18
4
  type MessageArray = readonly MessageValue[];
19
5
  /**
@@ -168,6 +154,16 @@ type NodeKeys<M, D extends number = DefaultDepth> = [D] extends [never] ? never
168
154
  type LeafKeys<M, D extends number = DefaultDepth> = [D] extends [never] ? never : M extends object ? {
169
155
  [K in keyof M]: M[K] extends MessageLeaf ? `${K & string}` : M[K] extends object ? `${K & string}.${LeafKeys<M[K], Prev[D]>}` : never;
170
156
  }[keyof M] : never;
157
+ /**
158
+ * Resolves the value type at a given dot-separated leaf key
159
+ * within a nested message object.
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * LeafValue<{ a: { b: { c: string } } }, "a.b.c"> // → string
164
+ * ```
165
+ */
166
+ type LeafValue<M, K extends string> = K extends `${infer Seg}.${infer Rest}` ? Seg extends keyof M ? LeafValue<M[Seg], Rest> : never : K extends keyof M ? M[K] : never;
171
167
 
172
168
  /**
173
169
  * Extracts all **node keys** from the messages
@@ -215,6 +211,13 @@ type LocalizedNodeKeys<M = unknown, L extends keyof M | "union" = "union", D ext
215
211
  * ```
216
212
  */
217
213
  type LocalizedLeafKeys<M = unknown, L extends keyof M | "union" = "union", D extends number = DefaultDepth> = M extends LocaleMessages ? L extends "union" ? LeafKeys<M[keyof M], D> : LeafKeys<M[Extract<L, keyof M>], D> : string;
214
+ /**
215
+ * Resolves the value type of a **localized leaf key**
216
+ * from the messages of a specified locale (or union of locales).
217
+ *
218
+ * - Fallback to `MessageValue` if M is not LocaleMessages
219
+ */
220
+ type LocalizedLeafValue<M = unknown, K extends string = string, L extends keyof M | "union" = "union"> = M extends LocaleMessages ? L extends "union" ? LeafValue<M[keyof M], K> : LeafValue<M[Extract<L, keyof M>], K> : MessageValue;
218
221
 
219
222
  /**
220
223
  * Resolves the type at a dot-separated key in a nested object.
@@ -250,6 +253,21 @@ type MessagesAtPreKey<T, PK extends string> = PK extends `${infer Head}.${infer
250
253
  * ```
251
254
  */
252
255
  type ScopedLeafKeys<M, PK extends string, L extends keyof M | "union" = "union", D extends number = DefaultDepth> = M extends LocaleMessages ? LocalizedMessagesUnion<M, L> extends infer Messages ? Messages extends MessageValue ? MessagesAtPreKey<Messages, PK> extends infer Scoped ? Scoped extends MessageObject ? LeafKeys<Scoped, D> : never : never : never : never : string;
256
+ /**
257
+ * Resolves the value type of a scoped leaf key (`K`)
258
+ * under a prefix path (`PK`) from localized messages.
259
+ *
260
+ * @example
261
+ * ```ts
262
+ * const messages = {
263
+ * en: { a: { b: { c: "hello" }, z: [123] } },
264
+ * };
265
+ *
266
+ * ScopedLeafValue<typeof messages, "a", "z">; // number[]
267
+ * ScopedLeafValue<typeof messages, "a.b", "c">; // string
268
+ * ```
269
+ */
270
+ type ScopedLeafValue<M, PK extends string, K extends string, L extends keyof M | "union" = "union"> = M extends LocaleMessages ? LocalizedMessagesUnion<M, L> extends infer Messages ? Messages extends MessageValue ? MessagesAtPreKey<Messages, PK> extends infer Scoped ? Scoped extends MessageObject ? LeafValue<Scoped, K> : never : never : never : never : MessageValue;
253
271
 
254
272
  /**
255
273
  * Configuration options for translation behavior.
@@ -276,13 +294,13 @@ type TranslateHandlers = {
276
294
  formatHandler?: FormatHandler;
277
295
  };
278
296
  /** Function called when translation is still loading. */
279
- type LoadingHandler<Result = unknown> = (ctx: HandlerContext) => Result;
297
+ type LoadingHandler = (ctx: HandlerContext) => MessageValue;
280
298
  /** Function called when no message is found for the given key. */
281
- type MissingHandler<Result = unknown> = (ctx: HandlerContext) => Result;
299
+ type MissingHandler = (ctx: HandlerContext) => MessageValue;
282
300
  /** Function to format a resolved message. */
283
- type FormatHandler<Result = unknown> = (ctx: HandlerContext & {
301
+ type FormatHandler = (ctx: HandlerContext & {
284
302
  rawString: string;
285
- }) => Result;
303
+ }) => MessageValue;
286
304
  /**
287
305
  * Snapshot of the translate pipeline context exposed to handlers.
288
306
  *
@@ -295,10 +313,8 @@ type HandlerContext = Readonly<Omit<TranslateContext, "finalMessage">>;
295
313
 
296
314
  /**
297
315
  * Context object shared across the translate pipeline.
298
- *
299
- * @template Result - Final translated value type.
300
316
  */
301
- interface TranslateContext<Result = unknown> {
317
+ interface TranslateContext {
302
318
  /** Configuration for the translate pipeline. */
303
319
  config: TranslateConfig;
304
320
  /** Current messages for translation */
@@ -318,16 +334,16 @@ interface TranslateContext<Result = unknown> {
318
334
  /** Raw string message before formatting. */
319
335
  rawString?: string;
320
336
  /** Message after formatting (e.g. ICU, custom formatters) */
321
- formattedMessage?: unknown;
337
+ formattedMessage?: MessageValue;
322
338
  /** Final value produced by the pipeline */
323
- finalMessage?: Result;
339
+ finalMessage?: MessageValue;
324
340
  /** Free-form metadata shared between hooks. */
325
341
  meta: Record<string, unknown>;
326
342
  }
327
343
  /**
328
344
  * A single step in the translate pipeline.
329
345
  */
330
- type TranslateHook = RuraHook<TranslateContext>;
346
+ type TranslateHook = RuraHook<TranslateContext, MessageValue>;
331
347
 
332
348
  /**
333
349
  * Options for initializing a translator
@@ -420,22 +436,22 @@ declare class CoreTranslator<M extends LocaleMessages | unknown = unknown, L ext
420
436
  /** Check if a key exists in the specified locale or current locale. */
421
437
  hasKey: <K extends LocalizedLeafKeys<M, L>>(key: K, targetLocale?: Locale<M>) => boolean;
422
438
  /** Get the translated message for a key, with optional replacements. */
423
- t: <Result = string, K extends LocalizedLeafKeys<M, L> = LocalizedLeafKeys<M, L>>(key: K, replacements?: Replacement) => Result;
439
+ t: <K extends LocalizedLeafKeys<M, L> = LocalizedLeafKeys<M, L>>(key: K, replacements?: Replacement) => LocalizedLeafValue<M, K, L>;
424
440
  /** Get the raw message value for a key without formatting or interpolation. */
425
- tRaw: <K extends LocalizedLeafKeys<M, L> = LocalizedLeafKeys<M, L>>(key: K, replacements?: Replacement) => MessageValue | undefined;
441
+ tRaw: <K extends LocalizedLeafKeys<M, L> = LocalizedLeafKeys<M, L>>(key: K, replacements?: Replacement) => LocalizedLeafValue<M, K, L>;
426
442
  }
427
443
 
428
444
  type ScopeTranslatorOptions<M> = CoreTranslatorOptions<M>;
429
- type ScopeTranslatorMethods<M extends LocaleMessages | unknown = unknown, L extends keyof M | "union" = "union", K = LocalizedLeafKeys<M, L>> = {
445
+ type ScopeTranslatorMethods<M extends LocaleMessages | unknown = unknown, L extends keyof M | "union" = "union", PK extends string | undefined = undefined, K extends string = PK extends string ? ScopedLeafKeys<M, PK, L> : LocalizedLeafKeys<M, L>> = {
430
446
  hasKey: (key?: K, targetLocale?: Locale<M>) => boolean;
431
- t: <Result = string>(key?: K, replacements?: Replacement) => Result;
432
- tRaw: (key?: K, replacements?: Replacement) => MessageValue$1 | undefined;
447
+ t: <Key extends K>(key?: Key, replacements?: Replacement) => PK extends string ? ScopedLeafValue<M, PK, Key, L> : LocalizedLeafValue<M, Key, L>;
448
+ tRaw: <Key extends K>(key?: Key, replacements?: Replacement) => PK extends string ? ScopedLeafValue<M, PK, Key, L> : LocalizedLeafValue<M, Key, L>;
433
449
  };
434
450
 
435
451
  declare class ScopeTranslator<M extends LocaleMessages | unknown = unknown, L extends keyof M | "union" = "union"> extends CoreTranslator<M> {
436
452
  constructor(options: ScopeTranslatorOptions<M>);
437
453
  /** Create a scoped translator with a prefix key for resolving nested message paths. */
438
- scoped<PK extends LocalizedNodeKeys<M, L> | undefined = undefined>(preKey?: PK): PK extends string ? ScopeTranslatorMethods<M, L, ScopedLeafKeys<M, PK, L>> : ScopeTranslatorMethods<M, L>;
454
+ scoped<PK extends LocalizedNodeKeys<M, L> | undefined = undefined>(preKey?: PK): PK extends string ? ScopeTranslatorMethods<M, L, PK> : ScopeTranslatorMethods<M, L>;
439
455
  }
440
456
 
441
457
  /** Semantic tag attributes map. */
@@ -504,4 +520,4 @@ interface Renderer<Output> {
504
520
  */
505
521
  declare function renderRichMessage<Output>(message: string, renderer: Renderer<Output>): Output[];
506
522
 
507
- export { type ASTNode, type Attributes, type DefaultDepth, type FallbackLocalesMap, type FormatHandler, type HandlerContext, type LeafKeys, type LoadingHandler, type Locale, type LocaleMessages, type LocalizedLeafKeys, type LocalizedMessagesUnion, type LocalizedNodeKeys, type MessageObject, type MessageValue, type MissingHandler, type NodeKeys, type Renderer, type Replacement, type ScopedLeafKeys, type TranslateConfig, type TranslateContext, type TranslateHandlers, type TranslateHook, ScopeTranslator as Translator, type ScopeTranslatorMethods as TranslatorMethods, type ScopeTranslatorOptions as TranslatorOptions, type TranslatorPlugin, parseRichMessage, renderRichMessage };
523
+ export { type ASTNode, type Attributes, type DefaultDepth, type FallbackLocalesMap, type FormatHandler, type HandlerContext, type LeafKeys, type LeafValue, type LoadingHandler, type Locale, type LocaleMessages, type LocalizedLeafKeys, type LocalizedLeafValue, type LocalizedMessagesUnion, type LocalizedNodeKeys, type MessageObject, type MessageValue, type MissingHandler, type NodeKeys, type Renderer, type Replacement, type ScopedLeafKeys, type ScopedLeafValue, type TranslateConfig, type TranslateContext, type TranslateHandlers, type TranslateHook, ScopeTranslator as Translator, type ScopeTranslatorMethods as TranslatorMethods, type ScopeTranslatorOptions as TranslatorOptions, type TranslatorPlugin, parseRichMessage, renderRichMessage };
package/dist/index.js CHANGED
@@ -119,7 +119,7 @@ var loading = rura.createHook(
119
119
  };
120
120
  }
121
121
  const { loadingMessage } = config;
122
- if ("loadingMessage" in config) {
122
+ if (loadingMessage !== void 0) {
123
123
  return { early: true, output: loadingMessage };
124
124
  }
125
125
  },
@@ -138,7 +138,7 @@ var missing = rura.createHook(
138
138
  };
139
139
  }
140
140
  const { missingMessage } = config;
141
- if ("missingMessage" in config) {
141
+ if (missingMessage !== void 0) {
142
142
  return { early: true, output: missingMessage };
143
143
  }
144
144
  return { early: true, output: key };
@@ -174,6 +174,7 @@ var DEFAULT_HOOKS = [
174
174
  format,
175
175
  interpolate
176
176
  ];
177
+ rura.createPipeline(DEFAULT_HOOKS).debugHooks();
177
178
 
178
179
  // src/translators/base-translator/base-translator.ts
179
180
  var BaseTranslator = class {
@@ -248,12 +249,18 @@ function runTranslate(options) {
248
249
  function translate(options) {
249
250
  const { early, ctx, output } = runTranslate(options);
250
251
  if (early === true) return output;
252
+ if (ctx.finalMessage === void 0) {
253
+ throw new Error("Invariant violated: missing hook did not produce output");
254
+ }
251
255
  return ctx.finalMessage;
252
256
  }
253
257
 
254
258
  // src/translators/methods/translate-raw.ts
255
259
  function translateRaw(options) {
256
260
  const { ctx } = runTranslate(options);
261
+ if (ctx.rawValue === void 0) {
262
+ throw new Error("Invariant violated: missing hook did not produce output");
263
+ }
257
264
  return ctx.rawValue;
258
265
  }
259
266
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intor-translator",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "🤖 A modern, type-safe i18n engine.",
5
5
  "author": {
6
6
  "name": "Yiming Liao",
@@ -62,7 +62,7 @@
62
62
  "examples:html:rich-message": "vite --config examples/html/rich-message/vite.config.ts"
63
63
  },
64
64
  "dependencies": {
65
- "rura": "1.0.7"
65
+ "rura": "^1.0.8"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@types/node": "24.10.1",