@logixjs/i18n 1.0.2-beta.1 → 1.0.2
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/I18n.cjs +13 -127
- package/dist/I18n.cjs.map +1 -1
- package/dist/I18n.d.cts +15 -7
- package/dist/I18n.d.ts +15 -7
- package/dist/I18n.js +1 -3
- package/dist/Token.cjs +42 -36
- package/dist/Token.cjs.map +1 -1
- package/dist/Token.d.cts +6 -7
- package/dist/Token.d.ts +6 -7
- package/dist/Token.js +1 -4
- package/dist/{chunk-4NKGIEWG.js → chunk-DQVWWU7T.js} +14 -20
- package/dist/chunk-DQVWWU7T.js.map +1 -0
- package/dist/chunk-LGNB43KG.js +123 -0
- package/dist/chunk-LGNB43KG.js.map +1 -0
- package/dist/index.cjs +128 -178
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -4
- package/dist/index.d.ts +2 -4
- package/dist/index.js +2 -14
- package/package.json +29 -22
- package/LICENSE +0 -201
- package/dist/I18nModule.cjs +0 -88
- package/dist/I18nModule.cjs.map +0 -1
- package/dist/I18nModule.d.cts +0 -5
- package/dist/I18nModule.d.ts +0 -5
- package/dist/I18nModule.js +0 -9
- package/dist/I18nModule.js.map +0 -1
- package/dist/chunk-4NKGIEWG.js.map +0 -1
- package/dist/chunk-FDPDEDU7.js +0 -1
- package/dist/chunk-FDPDEDU7.js.map +0 -1
- package/dist/chunk-LW6LHDDL.js +0 -1
- package/dist/chunk-LW6LHDDL.js.map +0 -1
- package/dist/chunk-NWWL4MNH.js +0 -116
- package/dist/chunk-NWWL4MNH.js.map +0 -1
- package/dist/chunk-X2U6SCIR.js +0 -45
- package/dist/chunk-X2U6SCIR.js.map +0 -1
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/internal/driver/i18n.ts","../src/internal/token/token.ts","../src/internal/module/i18nModule.ts"],"sourcesContent":["// Public barrel for @logixjs/i18n\n// Recommended usage:\n// import * as I18n from \"@logixjs/i18n\"\n// Then I18n exposes namespaces like I18n / I18nModule / Token.\n\nexport * from './I18n.js'\nexport * from './I18nModule.js'\nexport * from './Token.js'\n","import {\n Duration,\n Effect,\n Fiber,\n Layer,\n ManagedRuntime,\n Option,\n ServiceMap,\n Scope,\n Schema,\n Stream,\n SubscriptionRef,\n} from 'effect'\n\nimport type { I18nMessageToken, I18nTokenOptionsInput } from '../token/token.js'\nimport { token } from '../token/token.js'\n\nexport type { I18nTokenOptionsInput } from '../token/token.js'\n\nexport type I18nDriver = {\n readonly language: string\n readonly isInitialized?: boolean\n readonly t: (key: string, options?: unknown) => string\n readonly changeLanguage: (language: string) => Promise<unknown> | unknown\n readonly on: (event: 'initialized' | 'languageChanged', handler: (...args: any[]) => void) => unknown\n readonly off: (event: 'initialized' | 'languageChanged', handler: (...args: any[]) => void) => unknown\n}\n\nexport type I18nInitState = 'pending' | 'ready' | 'failed'\n\nexport type I18nSnapshot = {\n readonly language: string\n readonly init: I18nInitState\n readonly seq: number\n}\n\nexport const I18nSnapshotSchema = Schema.Struct({\n language: Schema.String,\n init: Schema.Literals(['pending', 'ready', 'failed']),\n seq: Schema.Number,\n})\n\nexport type I18nService = {\n readonly instance: I18nDriver\n readonly snapshot: SubscriptionRef.SubscriptionRef<I18nSnapshot>\n readonly token: (key: string, options?: I18nTokenOptionsInput) => I18nMessageToken\n readonly changeLanguage: (language: string) => Effect.Effect<void, never, never>\n readonly t: (key: string, options?: I18nTokenOptionsInput) => string\n readonly tReady: (\n key: string,\n options?: I18nTokenOptionsInput,\n timeoutMs?: number,\n ) => Effect.Effect<string, never, never>\n}\n\nexport class I18nTag extends ServiceMap.Service<I18nTag, I18nService>()('@logixjs/i18n/I18n') {}\n\nconst asNonEmptyString = (value: unknown): string | undefined =>\n typeof value === 'string' && value.length > 0 ? value : undefined\n\nconst makeI18nService = (driver: I18nDriver): Effect.Effect<I18nService, never, Scope.Scope> =>\n Effect.gen(function* () {\n const init: I18nInitState = driver.isInitialized ? 'ready' : 'pending'\n let currentSnapshot: I18nSnapshot = {\n language: driver.language,\n init,\n seq: 0,\n }\n const snapshotRef = yield* SubscriptionRef.make<I18nSnapshot>(currentSnapshot)\n\n const update = (patch: Partial<Pick<I18nSnapshot, 'language' | 'init'>>): Effect.Effect<void> =>\n SubscriptionRef.update(snapshotRef, (prev) => {\n const next: I18nSnapshot = {\n language: patch.language ?? prev.language,\n init: patch.init ?? prev.init,\n seq: prev.seq + 1,\n }\n currentSnapshot = next\n return next\n })\n\n const pushSnapshot = (patch: Partial<Pick<I18nSnapshot, 'language' | 'init'>>): void => {\n const next: I18nSnapshot = {\n language: patch.language ?? currentSnapshot.language,\n init: patch.init ?? currentSnapshot.init,\n seq: currentSnapshot.seq + 1,\n }\n currentSnapshot = next\n void Effect.runPromise(SubscriptionRef.set(snapshotRef, next).pipe(Effect.catchCause(() => Effect.void)))\n }\n\n const onInitialized = (): void => {\n pushSnapshot({ init: 'ready', language: driver.language })\n }\n\n const onLanguageChanged = (lang: unknown): void => {\n pushSnapshot({\n init: 'ready',\n language: asNonEmptyString(lang) ?? driver.language,\n })\n }\n\n yield* Effect.sync(() => {\n driver.on('initialized', onInitialized)\n driver.on('languageChanged', onLanguageChanged)\n })\n\n const scope = yield* Effect.scope\n yield* Scope.addFinalizer(\n scope,\n Effect.sync(() => {\n driver.off('initialized', onInitialized)\n driver.off('languageChanged', onLanguageChanged)\n }),\n )\n\n const changeLanguage = (language: string): Effect.Effect<void, never, never> =>\n Effect.gen(function* () {\n yield* update({ language, init: 'pending' })\n const exit = yield* Effect.exit(\n Effect.tryPromise({\n try: () => Promise.resolve(driver.changeLanguage(language)),\n catch: () => undefined,\n }),\n )\n if (exit._tag === 'Failure') {\n yield* update({ init: 'failed' })\n } else {\n yield* update({ init: 'ready', language })\n }\n })\n\n const fallback = (key: string, options?: I18nTokenOptionsInput): string =>\n typeof options?.defaultValue === 'string' ? options.defaultValue : key\n\n const t = (key: string, options?: I18nTokenOptionsInput): string => {\n if (currentSnapshot.init !== 'ready') {\n return fallback(key, options)\n }\n try {\n return driver.t(key, options)\n } catch {\n return fallback(key, options)\n }\n }\n\n const tReady = (\n key: string,\n options?: I18nTokenOptionsInput,\n timeoutMs?: number,\n ): Effect.Effect<string, never, never> =>\n Effect.gen(function* () {\n const cap = timeoutMs ?? 5000\n const snap0 = yield* SubscriptionRef.get(snapshotRef)\n if (snap0.init === 'ready') return t(key, options)\n if (snap0.init === 'failed') return fallback(key, options)\n\n const wait = Stream.filter(SubscriptionRef.changes(snapshotRef), (s) => s.init !== 'pending').pipe(\n Stream.runHead,\n Effect.timeoutOption(Duration.millis(cap)),\n Effect.map((maybe) => (Option.isSome(maybe) ? maybe.value : Option.none())),\n )\n\n const fiber = yield* wait.pipe(Effect.forkChild)\n\n const snap1 = yield* SubscriptionRef.get(snapshotRef)\n if (snap1.init !== 'pending') {\n yield* Fiber.interrupt(fiber)\n return snap1.init === 'ready' ? t(key, options) : fallback(key, options)\n }\n\n const outcome = yield* Fiber.join(fiber)\n return Option.match(outcome, {\n onNone: () => fallback(key, options),\n onSome: (snap) => (snap.init === 'ready' ? t(key, options) : fallback(key, options)),\n })\n })\n\n return {\n instance: driver,\n snapshot: snapshotRef,\n token,\n changeLanguage,\n t,\n tReady,\n } as const\n })\n\nexport const I18n = {\n layer: (driver: I18nDriver): Layer.Layer<I18nTag, never, never> => Layer.effect(I18nTag, makeI18nService(driver)),\n} as const\n","export type JsonPrimitive = null | boolean | number | string\n\nexport type I18nTokenOptions = Readonly<Record<string, JsonPrimitive>>\nexport type I18nTokenOptionsInput = Readonly<Record<string, JsonPrimitive | undefined>>\n\nexport type I18nMessageToken = {\n readonly _tag: 'i18n'\n readonly key: string\n readonly options?: I18nTokenOptions\n}\n\nexport type InvalidI18nMessageTokenReason =\n | 'keyTooLong'\n | 'tooManyOptions'\n | 'optionKeyInvalid'\n | 'optionValueInvalid'\n | 'optionValueTooLong'\n | 'numberNotJsonSafe'\n | 'languageFrozen'\n\nexport class InvalidI18nMessageTokenError extends Error {\n readonly name = 'InvalidI18nMessageTokenError'\n\n constructor(\n readonly reason: InvalidI18nMessageTokenReason,\n readonly details: unknown,\n readonly fix: ReadonlyArray<string>,\n ) {\n super(`[InvalidI18nMessageTokenError] reason=${reason}`)\n }\n}\n\nconst TOKEN_BUDGET = {\n keyMaxLen: 96,\n optionKeyMaxCount: 8,\n optionValueStringMaxLen: 96,\n} as const\n\nconst LANGUAGE_FROZEN_KEYS = new Set(['lng', 'lngs'])\nconst DANGEROUS_OPTION_KEYS = new Set(['__proto__', 'prototype', 'constructor'])\n\nconst isJsonPrimitive = (value: unknown): value is JsonPrimitive =>\n value === null || typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string'\n\nconst invalidToken = (reason: InvalidI18nMessageTokenReason, details: unknown, fix: ReadonlyArray<string>): never => {\n throw new InvalidI18nMessageTokenError(reason, details, fix)\n}\n\nexport const canonicalizeTokenOptions = (options: I18nTokenOptionsInput | undefined): I18nTokenOptions | undefined => {\n if (!options) return undefined\n if (typeof options !== 'object' || options === null || Array.isArray(options)) {\n invalidToken('optionValueInvalid', { field: 'options', actual: typeof options }, [\n '请传入 plain object 作为 options(Record<string, JsonPrimitive>)。',\n '不要传入数组/函数/类实例等不可序列化值。',\n ])\n }\n\n const entries = Object.entries(options).filter((p): p is [string, JsonPrimitive] => p[1] !== undefined)\n\n if (entries.length === 0) return undefined\n\n if (entries.length > TOKEN_BUDGET.optionKeyMaxCount) {\n invalidToken(\n 'tooManyOptions',\n {\n field: 'options',\n max: TOKEN_BUDGET.optionKeyMaxCount,\n actual: entries.length,\n },\n [\n `减少 options 键数量(建议 ≤ ${TOKEN_BUDGET.optionKeyMaxCount})。`,\n '把较长的信息挪到 key 或 defaultValue;避免把大对象塞进 token。',\n ],\n )\n }\n\n for (const [k, v] of entries) {\n if (DANGEROUS_OPTION_KEYS.has(k) || k.length === 0) {\n invalidToken('optionKeyInvalid', { field: `options.${k}`, key: k }, [\n '请使用普通字段名作为 options key(避免 __proto__/constructor/prototype 等危险键)。',\n '如需传递复杂结构,请先在展示边界转换为字符串。',\n ])\n }\n\n if (LANGUAGE_FROZEN_KEYS.has(k)) {\n invalidToken('languageFrozen', { field: `options.${k}`, key: k }, [\n '不要在 token options 中传入 lng/lngs 等语言冻结字段。',\n '语言由外部 i18n 实例决定;token 只表达“要翻译什么”。',\n ])\n }\n\n if (!isJsonPrimitive(v)) {\n invalidToken('optionValueInvalid', { field: `options.${k}`, actual: typeof v }, [\n 'options value 只允许 JsonPrimitive(null/boolean/number/string)。',\n '不要传入对象/数组/函数;需要时请在展示边界先格式化成字符串。',\n ])\n }\n\n if (typeof v === 'number' && !Number.isFinite(v)) {\n invalidToken('numberNotJsonSafe', { field: `options.${k}`, value: String(v) }, [\n '不要在 token options 中传入 NaN/Infinity。',\n '请先把该数值转换为可 JSON 化的 number 或 string。',\n ])\n }\n\n if (typeof v === 'string' && v.length > TOKEN_BUDGET.optionValueStringMaxLen) {\n invalidToken(\n 'optionValueTooLong',\n {\n field: `options.${k}`,\n maxLen: TOKEN_BUDGET.optionValueStringMaxLen,\n actualLen: v.length,\n },\n [\n `缩短字符串值长度(建议 ≤ ${TOKEN_BUDGET.optionValueStringMaxLen})。`,\n '把长文本移到 defaultValue 或直接在展示边界生成最终字符串。',\n ],\n )\n }\n }\n\n entries.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))\n\n const out: Record<string, JsonPrimitive> = {}\n for (const [k, v] of entries) {\n out[k] = v\n }\n return out\n}\n\nexport const token = (key: string, options?: I18nTokenOptionsInput): I18nMessageToken => {\n if (key.length > TOKEN_BUDGET.keyMaxLen) {\n invalidToken('keyTooLong', { field: 'key', maxLen: TOKEN_BUDGET.keyMaxLen, actualLen: key.length }, [\n `缩短 key(建议 ≤ ${TOKEN_BUDGET.keyMaxLen})。`,\n '如果 key 过长,建议改为“稳定 key + 变量 options/defaultValue”。',\n ])\n }\n\n const canon = canonicalizeTokenOptions(options)\n return canon\n ? {\n _tag: 'i18n',\n key,\n options: canon,\n }\n : {\n _tag: 'i18n',\n key,\n }\n}\n","import * as Logix from '@logixjs/core'\nimport { Effect, Schema, SubscriptionRef } from 'effect'\n\nimport { I18nSnapshotSchema, I18nTag } from '../driver/i18n.js'\n\nconst I18nModuleDef = Logix.Module.make('@logixjs/i18n/I18nModule', {\n state: Schema.Struct({ snapshot: I18nSnapshotSchema }),\n actions: {\n changeLanguage: Schema.String,\n },\n})\n\nconst I18nModuleLogic = I18nModuleDef.logic(($) => ({\n setup: $.lifecycle.onStart(\n Effect.gen(function* () {\n const i18n = yield* $.root.resolve(I18nTag)\n const snap = yield* SubscriptionRef.get(i18n.snapshot)\n yield* $.state.mutate((draft) => {\n ;(draft as any).snapshot = snap\n })\n }),\n ),\n run: Effect.gen(function* () {\n const i18n = yield* $.root.resolve(I18nTag)\n\n yield* $.on(SubscriptionRef.changes(i18n.snapshot)).runFork((snap) =>\n $.state.mutate((draft) => {\n ;(draft as any).snapshot = snap\n }),\n )\n\n yield* $.onAction('changeLanguage').runFork((action) => i18n.changeLanguage(action.payload))\n }),\n}))\n\nexport const I18nModule: Logix.AnyModule = I18nModuleDef.implement({\n initial: { snapshot: { language: 'unknown', init: 'pending', seq: 0 } },\n logics: [I18nModuleLogic],\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAYO;;;ACQA,IAAM,+BAAN,cAA2C,MAAM;AAAA,EAGtD,YACW,QACA,SACA,KACT;AACA,UAAM,yCAAyC,MAAM,EAAE;AAJ9C;AACA;AACA;AALX,SAAS,OAAO;AAAA,EAQhB;AACF;AAEA,IAAM,eAAe;AAAA,EACnB,WAAW;AAAA,EACX,mBAAmB;AAAA,EACnB,yBAAyB;AAC3B;AAEA,IAAM,uBAAuB,oBAAI,IAAI,CAAC,OAAO,MAAM,CAAC;AAC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BAAO,OAAO,EAAE,UAAU,mBAAmB,CAAC;AAAA,EACrD,SAAS;AAAA,IACP,gBAAgB,sBAAO;AAAA,EACzB;AACF,CAAC;AAED,IAAM,kBAAkB,cAAc,MAAM,CAAC,OAAO;AAAA,EAClD,OAAO,EAAE,UAAU;AAAA,IACjB,sBAAO,IAAI,aAAa;AACtB,YAAM,OAAO,OAAO,EAAE,KAAK,QAAQ,OAAO;AAC1C,YAAM,OAAO,OAAO,+BAAgB,IAAI,KAAK,QAAQ;AACrD,aAAO,EAAE,MAAM,OAAO,CAAC,UAAU;AAC/B;AAAC,QAAC,MAAc,WAAW;AAAA,MAC7B,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAAA,EACA,KAAK,sBAAO,IAAI,aAAa;AAC3B,UAAM,OAAO,OAAO,EAAE,KAAK,QAAQ,OAAO;AAE1C,WAAO,EAAE,GAAG,+BAAgB,QAAQ,KAAK,QAAQ,CAAC,EAAE;AAAA,MAAQ,CAAC,SAC3D,EAAE,MAAM,OAAO,CAAC,UAAU;AACxB;AAAC,QAAC,MAAc,WAAW;AAAA,MAC7B,CAAC;AAAA,IACH;AAEA,WAAO,EAAE,SAAS,gBAAgB,EAAE,QAAQ,CAAC,WAAW,KAAK,eAAe,OAAO,OAAO,CAAC;AAAA,EAC7F,CAAC;AACH,EAAE;AAEK,IAAM,aAA8B,cAAc,UAAU;AAAA,EACjE,SAAS,EAAE,UAAU,EAAE,UAAU,WAAW,MAAM,WAAW,KAAK,EAAE,EAAE;AAAA,EACtE,QAAQ,CAAC,eAAe;AAC1B,CAAC;","names":["import_effect"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/internal/driver/i18n.ts","../src/internal/token/token.ts"],"sourcesContent":["// Public barrel for @logixjs/i18n\n// Recommended usage:\n// import * as I18n from \"@logixjs/i18n\"\n// Then I18n exposes only the service-first root surface and token contract.\n\nexport { I18n, I18nTag } from './internal/driver/i18n.js'\nexport type { I18nMessageToken, I18nTokenParams, I18nTokenParamsInput } from './internal/token/token.js'\nexport { token } from './internal/token/token.js'\n","import {\n Duration,\n Effect,\n Fiber,\n Layer,\n ManagedRuntime,\n Option,\n ServiceMap,\n Scope,\n Schema,\n Stream,\n SubscriptionRef,\n} from 'effect'\n\nimport type { I18nMessageToken, I18nTokenParamsInput } from '../token/token.js'\n\nexport type { I18nTokenParamsInput } from '../token/token.js'\n\n/**\n * Low-level driver contract.\n *\n * Package-level canonical consumption remains service-first:\n * callers should read `services.i18n` or `I18nTag`, rather than coupling to driver lifecycle details directly.\n */\nexport type I18nDriver = {\n readonly language: string\n readonly isInitialized?: boolean\n readonly t: (key: string, input?: unknown) => string\n readonly changeLanguage: (language: string) => Promise<unknown> | unknown\n readonly on: (event: 'initialized' | 'languageChanged', handler: (...args: any[]) => void) => unknown\n readonly off: (event: 'initialized' | 'languageChanged', handler: (...args: any[]) => void) => unknown\n}\n\nexport type I18nInitState = 'pending' | 'ready' | 'failed'\n\nexport type I18nSnapshot = {\n readonly language: string\n readonly init: I18nInitState\n readonly seq: number\n}\n\nexport const I18nSnapshotSchema = Schema.Struct({\n language: Schema.String,\n init: Schema.Literals(['pending', 'ready', 'failed']),\n seq: Schema.Number,\n})\n\nexport type I18nRenderHints = {\n readonly fallback?: string\n}\n\nexport type I18nService = {\n readonly snapshot: SubscriptionRef.SubscriptionRef<I18nSnapshot>\n readonly changeLanguage: (language: string) => Effect.Effect<void, never, never>\n readonly render: (token: I18nMessageToken, hints?: I18nRenderHints) => string\n readonly renderReady: (\n token: I18nMessageToken,\n hints?: I18nRenderHints,\n timeoutMs?: number,\n ) => Effect.Effect<string, never, never>\n}\n\nexport class I18nTag extends ServiceMap.Service<I18nTag, I18nService>()('@logixjs/i18n/I18n') {}\n\nconst asNonEmptyString = (value: unknown): string | undefined =>\n typeof value === 'string' && value.length > 0 ? value : undefined\n\nconst makeI18nService = (driver: I18nDriver): Effect.Effect<I18nService, never, Scope.Scope> =>\n Effect.gen(function* () {\n const init: I18nInitState = driver.isInitialized ? 'ready' : 'pending'\n let currentSnapshot: I18nSnapshot = {\n language: driver.language,\n init,\n seq: 0,\n }\n const snapshotRef = yield* SubscriptionRef.make<I18nSnapshot>(currentSnapshot)\n\n const update = (patch: Partial<Pick<I18nSnapshot, 'language' | 'init'>>): Effect.Effect<void> =>\n SubscriptionRef.update(snapshotRef, (prev) => {\n const next: I18nSnapshot = {\n language: patch.language ?? prev.language,\n init: patch.init ?? prev.init,\n seq: prev.seq + 1,\n }\n currentSnapshot = next\n return next\n })\n\n const pushSnapshot = (patch: Partial<Pick<I18nSnapshot, 'language' | 'init'>>): void => {\n const next: I18nSnapshot = {\n language: patch.language ?? currentSnapshot.language,\n init: patch.init ?? currentSnapshot.init,\n seq: currentSnapshot.seq + 1,\n }\n currentSnapshot = next\n void Effect.runPromise(SubscriptionRef.set(snapshotRef, next).pipe(Effect.catchCause(() => Effect.void)))\n }\n\n const onInitialized = (): void => {\n pushSnapshot({ init: 'ready', language: driver.language })\n }\n\n const onLanguageChanged = (lang: unknown): void => {\n pushSnapshot({\n init: 'ready',\n language: asNonEmptyString(lang) ?? driver.language,\n })\n }\n\n yield* Effect.sync(() => {\n driver.on('initialized', onInitialized)\n driver.on('languageChanged', onLanguageChanged)\n })\n\n const scope = yield* Effect.scope\n yield* Scope.addFinalizer(\n scope,\n Effect.sync(() => {\n driver.off('initialized', onInitialized)\n driver.off('languageChanged', onLanguageChanged)\n }),\n )\n\n /**\n * Canonical runtime-facing lifecycle wiring:\n * - driver events update the shared snapshot\n * - consumers stay on the service contract (`render`, `renderReady`, `snapshot`)\n */\n const changeLanguage = (language: string): Effect.Effect<void, never, never> =>\n Effect.gen(function* () {\n yield* update({ language, init: 'pending' })\n const exit = yield* Effect.exit(\n Effect.tryPromise({\n try: () => Promise.resolve(driver.changeLanguage(language)),\n catch: () => undefined,\n }),\n )\n if (exit._tag === 'Failure') {\n yield* update({ init: 'failed' })\n } else {\n yield* update({ init: 'ready', language })\n }\n })\n\n const fallback = (message: I18nMessageToken, hints?: I18nRenderHints): string => hints?.fallback ?? message.key\n\n const render = (message: I18nMessageToken, hints?: I18nRenderHints): string => {\n if (currentSnapshot.init !== 'ready') {\n return fallback(message, hints)\n }\n try {\n return driver.t(message.key, message.params as I18nTokenParamsInput | undefined)\n } catch {\n return fallback(message, hints)\n }\n }\n\n const renderReady = (\n message: I18nMessageToken,\n hints?: I18nRenderHints,\n timeoutMs?: number,\n ): Effect.Effect<string, never, never> =>\n Effect.gen(function* () {\n const cap = timeoutMs ?? 5000\n const snap0 = yield* SubscriptionRef.get(snapshotRef)\n if (snap0.init === 'ready') return render(message, hints)\n if (snap0.init === 'failed') return fallback(message, hints)\n\n const wait = Stream.filter(SubscriptionRef.changes(snapshotRef), (s) => s.init !== 'pending').pipe(\n Stream.runHead,\n Effect.timeoutOption(Duration.millis(cap)),\n Effect.map((maybe) => (Option.isSome(maybe) ? maybe.value : Option.none())),\n )\n\n const fiber = yield* wait.pipe(Effect.forkChild)\n\n const snap1 = yield* SubscriptionRef.get(snapshotRef)\n if (snap1.init !== 'pending') {\n yield* Fiber.interrupt(fiber)\n return snap1.init === 'ready' ? render(message, hints) : fallback(message, hints)\n }\n\n const outcome = yield* Fiber.join(fiber)\n return Option.match(outcome, {\n onNone: () => fallback(message, hints),\n onSome: (snap) => (snap.init === 'ready' ? render(message, hints) : fallback(message, hints)),\n })\n })\n\n return {\n snapshot: snapshotRef,\n changeLanguage,\n render,\n renderReady,\n } as const\n })\n\nexport const I18n = {\n layer: (driver: I18nDriver): Layer.Layer<I18nTag, never, never> => Layer.effect(I18nTag, makeI18nService(driver)),\n} as const\n","export type JsonPrimitive = null | boolean | number | string\n\nexport type I18nTokenParams = Readonly<Record<string, JsonPrimitive>>\nexport type I18nTokenParamsInput = Readonly<Record<string, JsonPrimitive | undefined>>\n\nexport type I18nMessageToken = {\n readonly _tag: 'i18n'\n readonly key: string\n readonly params?: I18nTokenParams\n}\n\nexport type InvalidI18nMessageTokenReason =\n | 'keyTooLong'\n | 'tooManyParams'\n | 'paramKeyInvalid'\n | 'paramValueInvalid'\n | 'paramValueTooLong'\n | 'numberNotJsonSafe'\n | 'languageFrozen'\n | 'renderFallbackReserved'\n\nexport class InvalidI18nMessageTokenError extends Error {\n readonly name = 'InvalidI18nMessageTokenError'\n\n constructor(\n readonly reason: InvalidI18nMessageTokenReason,\n readonly details: unknown,\n readonly fix: ReadonlyArray<string>,\n ) {\n super(`[InvalidI18nMessageTokenError] reason=${reason}`)\n }\n}\n\nconst TOKEN_BUDGET = {\n keyMaxLen: 96,\n paramKeyMaxCount: 8,\n paramValueStringMaxLen: 96,\n} as const\n\nconst LANGUAGE_FROZEN_KEYS = new Set(['lng', 'lngs'])\nconst DANGEROUS_PARAM_KEYS = new Set(['__proto__', 'prototype', 'constructor'])\nconst LEGACY_RENDER_FALLBACK_KEY = `default${'Value'}`\nconst RESERVED_RENDER_FALLBACK_KEYS = new Set([LEGACY_RENDER_FALLBACK_KEY])\n\nconst isJsonPrimitive = (value: unknown): value is JsonPrimitive =>\n value === null || typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string'\n\nconst invalidToken = (reason: InvalidI18nMessageTokenReason, details: unknown, fix: ReadonlyArray<string>): never => {\n throw new InvalidI18nMessageTokenError(reason, details, fix)\n}\n\nexport const canonicalizeTokenParams = (params: I18nTokenParamsInput | undefined): I18nTokenParams | undefined => {\n if (!params) return undefined\n if (typeof params !== 'object' || params === null || Array.isArray(params)) {\n invalidToken('paramValueInvalid', { field: 'params', actual: typeof params }, [\n '请传入 plain object 作为 params(Record<string, JsonPrimitive>)。',\n '不要传入数组/函数/类实例等不可序列化值。',\n ])\n }\n\n const entries = Object.entries(params).filter((p): p is [string, JsonPrimitive] => p[1] !== undefined)\n\n if (entries.length === 0) return undefined\n\n if (entries.length > TOKEN_BUDGET.paramKeyMaxCount) {\n invalidToken(\n 'tooManyParams',\n {\n field: 'params',\n max: TOKEN_BUDGET.paramKeyMaxCount,\n actual: entries.length,\n },\n [\n `减少 params 键数量(建议 ≤ ${TOKEN_BUDGET.paramKeyMaxCount})。`,\n '避免把大对象或展示兜底文案塞进 semantic token。',\n ],\n )\n }\n\n for (const [k, v] of entries) {\n if (RESERVED_RENDER_FALLBACK_KEYS.has(k)) {\n invalidToken('renderFallbackReserved', { field: `params.${k}`, key: k }, [\n '不要把旧的展示兜底字段放进 semantic token params。',\n '请把兜底文案改放到 render/renderReady 的 hints.fallback。',\n ])\n }\n\n if (DANGEROUS_PARAM_KEYS.has(k) || k.length === 0) {\n invalidToken('paramKeyInvalid', { field: `params.${k}`, key: k }, [\n '请使用普通字段名作为 params key,避免 __proto__/constructor/prototype 等危险键。',\n '如需传递复杂结构,请先在展示边界转换为字符串。',\n ])\n }\n\n if (LANGUAGE_FROZEN_KEYS.has(k)) {\n invalidToken('languageFrozen', { field: `params.${k}`, key: k }, [\n '不要在 token params 中传入 lng/lngs 等语言冻结字段。',\n '语言由外部 i18n 实例决定;token 只表达“要翻译什么”。',\n ])\n }\n\n if (!isJsonPrimitive(v)) {\n invalidToken('paramValueInvalid', { field: `params.${k}`, actual: typeof v }, [\n 'params value 只允许 JsonPrimitive(null/boolean/number/string)。',\n '不要传入对象/数组/函数;需要时请在展示边界先格式化成字符串。',\n ])\n }\n\n if (typeof v === 'number' && !Number.isFinite(v)) {\n invalidToken('numberNotJsonSafe', { field: `params.${k}`, value: String(v) }, [\n '不要在 token params 中传入 NaN/Infinity。',\n '请先把该数值转换为可 JSON 化的 number 或 string。',\n ])\n }\n\n if (typeof v === 'string' && v.length > TOKEN_BUDGET.paramValueStringMaxLen) {\n invalidToken(\n 'paramValueTooLong',\n {\n field: `params.${k}`,\n maxLen: TOKEN_BUDGET.paramValueStringMaxLen,\n actualLen: v.length,\n },\n [\n `缩短字符串值长度(建议 ≤ ${TOKEN_BUDGET.paramValueStringMaxLen})。`,\n '把长文本留在展示边界,不要放进 semantic token。',\n ],\n )\n }\n }\n\n entries.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))\n\n const out: Record<string, JsonPrimitive> = {}\n for (const [k, v] of entries) {\n out[k] = v\n }\n return out\n}\n\nexport const token = (key: string, params?: I18nTokenParamsInput): I18nMessageToken => {\n if (key.length > TOKEN_BUDGET.keyMaxLen) {\n invalidToken('keyTooLong', { field: 'key', maxLen: TOKEN_BUDGET.keyMaxLen, actualLen: key.length }, [\n `缩短 key(建议 ≤ ${TOKEN_BUDGET.keyMaxLen})。`,\n '如果 key 过长,建议改为“稳定 key + 少量 semantic params”。',\n ])\n }\n\n const canon = canonicalizeTokenParams(params)\n return canon\n ? {\n _tag: 'i18n',\n key,\n params: canon,\n }\n : {\n _tag: 'i18n',\n key,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAYO;AA6BA,IAAM,qBAAqB,qBAAO,OAAO;AAAA,EAC9C,UAAU,qBAAO;AAAA,EACjB,MAAM,qBAAO,SAAS,CAAC,WAAW,SAAS,QAAQ,CAAC;AAAA,EACpD,KAAK,qBAAO;AACd,CAAC;AAiBM,IAAM,UAAN,cAAsB,yBAAW,QAA8B,EAAE,oBAAoB,EAAE;AAAC;AAE/F,IAAM,mBAAmB,CAAC,UACxB,OAAO,UAAU,YAAY,MAAM,SAAS,IAAI,QAAQ;AAE1D,IAAM,kBAAkB,CAAC,WACvB,qBAAO,IAAI,aAAa;AACtB,QAAM,OAAsB,OAAO,gBAAgB,UAAU;AAC7D,MAAI,kBAAgC;AAAA,IAClC,UAAU,OAAO;AAAA,IACjB;AAAA,IACA,KAAK;AAAA,EACP;AACA,QAAM,cAAc,OAAO,8BAAgB,KAAmB,eAAe;AAE7E,QAAM,SAAS,CAAC,UACd,8BAAgB,OAAO,aAAa,CAAC,SAAS;AAC5C,UAAM,OAAqB;AAAA,MACzB,UAAU,MAAM,YAAY,KAAK;AAAA,MACjC,MAAM,MAAM,QAAQ,KAAK;AAAA,MACzB,KAAK,KAAK,MAAM;AAAA,IAClB;AACA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,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,QAAI,OAAO,MAAM,YAAY,EAAE,SAAS,aAAa,wBAAwB;AAC3E;AAAA,QACE;AAAA,QACA;AAAA,UACE,OAAO,UAAU,CAAC;AAAA,UAClB,QAAQ,aAAa;AAAA,UACrB,WAAW,EAAE;AAAA,QACf;AAAA,QACA;AAAA,UACE,6EAAiB,aAAa,sBAAsB;AAAA,UACpD;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,UAAQ,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAO,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,CAAE;AAEvD,QAAM,MAAqC,CAAC;AAC5C,aAAW,CAAC,GAAG,CAAC,KAAK,SAAS;AAC5B,QAAI,CAAC,IAAI;AAAA,EACX;AACA,SAAO;AACT;AAEO,IAAM,QAAQ,CAAC,KAAa,WAAoD;AACrF,MAAI,IAAI,SAAS,aAAa,WAAW;AACvC,iBAAa,cAAc,EAAE,OAAO,OAAO,QAAQ,aAAa,WAAW,WAAW,IAAI,OAAO,GAAG;AAAA,MAClG,6CAAe,aAAa,SAAS;AAAA,MACrC;AAAA,IACF,CAAC;AAAA,EACH;AAEA,QAAM,QAAQ,wBAAwB,MAAM;AAC5C,SAAO,QACH;AAAA,IACE,MAAM;AAAA,IACN;AAAA,IACA,QAAQ;AAAA,EACV,IACA;AAAA,IACE,MAAM;AAAA,IACN;AAAA,EACF;AACN;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { I18n,
|
|
2
|
-
export {
|
|
3
|
-
export { I18nMessageToken, I18nTokenOptions, I18nTokenOptionsInput, InvalidI18nMessageTokenError, InvalidI18nMessageTokenReason, JsonPrimitive, canonicalizeTokenOptions, token } from './Token.cjs';
|
|
1
|
+
export { I18n, I18nTag } from './I18n.cjs';
|
|
2
|
+
export { I18nMessageToken, I18nTokenParams, I18nTokenParamsInput, token } from './Token.cjs';
|
|
4
3
|
import 'effect';
|
|
5
|
-
import '@logixjs/core';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { I18n,
|
|
2
|
-
export {
|
|
3
|
-
export { I18nMessageToken, I18nTokenOptions, I18nTokenOptionsInput, InvalidI18nMessageTokenError, InvalidI18nMessageTokenReason, JsonPrimitive, canonicalizeTokenOptions, token } from './Token.js';
|
|
1
|
+
export { I18n, I18nTag } from './I18n.js';
|
|
2
|
+
export { I18nMessageToken, I18nTokenParams, I18nTokenParamsInput, token } from './Token.js';
|
|
4
3
|
import 'effect';
|
|
5
|
-
import '@logixjs/core';
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,13 @@
|
|
|
1
|
-
import "./chunk-FDPDEDU7.js";
|
|
2
|
-
import {
|
|
3
|
-
I18nModule
|
|
4
|
-
} from "./chunk-X2U6SCIR.js";
|
|
5
1
|
import {
|
|
6
2
|
I18n,
|
|
7
|
-
I18nSnapshotSchema,
|
|
8
3
|
I18nTag
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-LW6LHDDL.js";
|
|
4
|
+
} from "./chunk-DQVWWU7T.js";
|
|
11
5
|
import {
|
|
12
|
-
InvalidI18nMessageTokenError,
|
|
13
|
-
canonicalizeTokenOptions,
|
|
14
6
|
token
|
|
15
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-LGNB43KG.js";
|
|
16
8
|
export {
|
|
17
9
|
I18n,
|
|
18
|
-
I18nModule,
|
|
19
|
-
I18nSnapshotSchema,
|
|
20
10
|
I18nTag,
|
|
21
|
-
InvalidI18nMessageTokenError,
|
|
22
|
-
canonicalizeTokenOptions,
|
|
23
11
|
token
|
|
24
12
|
};
|
|
25
13
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logixjs/i18n",
|
|
3
|
-
"version": "1.0.2
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/yoyooyooo/logix",
|
|
@@ -22,29 +22,22 @@
|
|
|
22
22
|
"import": "./dist/index.js",
|
|
23
23
|
"require": "./dist/index.cjs"
|
|
24
24
|
},
|
|
25
|
-
"./*": {
|
|
26
|
-
"types": "./dist/*.d.ts",
|
|
27
|
-
"import": "./dist/*.js",
|
|
28
|
-
"require": "./dist/*.cjs"
|
|
29
|
-
},
|
|
30
25
|
"./internal/*": null
|
|
31
26
|
},
|
|
32
27
|
"publishConfig": {
|
|
33
|
-
"access": "public"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"effect": "4.0.0-beta.28",
|
|
47
|
-
"@logixjs/core": "1.0.2-beta.1"
|
|
28
|
+
"access": "public",
|
|
29
|
+
"exports": {
|
|
30
|
+
"./package.json": "./package.json",
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"import": "./dist/index.js",
|
|
34
|
+
"require": "./dist/index.cjs"
|
|
35
|
+
},
|
|
36
|
+
"./internal/*": null
|
|
37
|
+
},
|
|
38
|
+
"main": "./dist/index.cjs",
|
|
39
|
+
"module": "./dist/index.js",
|
|
40
|
+
"types": "./dist/index.d.ts"
|
|
48
41
|
},
|
|
49
42
|
"scripts": {
|
|
50
43
|
"build": "tsup --format cjs,esm --dts",
|
|
@@ -55,5 +48,19 @@
|
|
|
55
48
|
"test:changed": "vitest run --changed",
|
|
56
49
|
"test:cache": "vitest run --cache",
|
|
57
50
|
"test:watch": "vitest"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@logixjs/core": "1.0.2",
|
|
54
|
+
"effect": "4.0.0-beta.28"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@effect/vitest": "4.0.0-beta.28",
|
|
58
|
+
"tsup": "^8.0.0",
|
|
59
|
+
"typescript": "^5.8.2",
|
|
60
|
+
"vitest": "^4.0.15"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"@logixjs/core": "1.0.2",
|
|
64
|
+
"effect": "4.0.0-beta.28"
|
|
58
65
|
}
|
|
59
|
-
}
|
|
66
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright [yyyy] [name of copyright owner]
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
package/dist/I18nModule.cjs
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/I18nModule.ts
|
|
31
|
-
var I18nModule_exports = {};
|
|
32
|
-
__export(I18nModule_exports, {
|
|
33
|
-
I18nModule: () => I18nModule
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(I18nModule_exports);
|
|
36
|
-
|
|
37
|
-
// src/internal/module/i18nModule.ts
|
|
38
|
-
var Logix = __toESM(require("@logixjs/core"), 1);
|
|
39
|
-
var import_effect2 = require("effect");
|
|
40
|
-
|
|
41
|
-
// src/internal/driver/i18n.ts
|
|
42
|
-
var import_effect = require("effect");
|
|
43
|
-
var I18nSnapshotSchema = import_effect.Schema.Struct({
|
|
44
|
-
language: import_effect.Schema.String,
|
|
45
|
-
init: import_effect.Schema.Literals(["pending", "ready", "failed"]),
|
|
46
|
-
seq: import_effect.Schema.Number
|
|
47
|
-
});
|
|
48
|
-
var I18nTag = class extends import_effect.ServiceMap.Service()("@logixjs/i18n/I18n") {
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
// src/internal/module/i18nModule.ts
|
|
52
|
-
var I18nModuleDef = Logix.Module.make("@logixjs/i18n/I18nModule", {
|
|
53
|
-
state: import_effect2.Schema.Struct({ snapshot: I18nSnapshotSchema }),
|
|
54
|
-
actions: {
|
|
55
|
-
changeLanguage: import_effect2.Schema.String
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
var I18nModuleLogic = I18nModuleDef.logic(($) => ({
|
|
59
|
-
setup: $.lifecycle.onStart(
|
|
60
|
-
import_effect2.Effect.gen(function* () {
|
|
61
|
-
const i18n = yield* $.root.resolve(I18nTag);
|
|
62
|
-
const snap = yield* import_effect2.SubscriptionRef.get(i18n.snapshot);
|
|
63
|
-
yield* $.state.mutate((draft) => {
|
|
64
|
-
;
|
|
65
|
-
draft.snapshot = snap;
|
|
66
|
-
});
|
|
67
|
-
})
|
|
68
|
-
),
|
|
69
|
-
run: import_effect2.Effect.gen(function* () {
|
|
70
|
-
const i18n = yield* $.root.resolve(I18nTag);
|
|
71
|
-
yield* $.on(import_effect2.SubscriptionRef.changes(i18n.snapshot)).runFork(
|
|
72
|
-
(snap) => $.state.mutate((draft) => {
|
|
73
|
-
;
|
|
74
|
-
draft.snapshot = snap;
|
|
75
|
-
})
|
|
76
|
-
);
|
|
77
|
-
yield* $.onAction("changeLanguage").runFork((action) => i18n.changeLanguage(action.payload));
|
|
78
|
-
})
|
|
79
|
-
}));
|
|
80
|
-
var I18nModule = I18nModuleDef.implement({
|
|
81
|
-
initial: { snapshot: { language: "unknown", init: "pending", seq: 0 } },
|
|
82
|
-
logics: [I18nModuleLogic]
|
|
83
|
-
});
|
|
84
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
-
0 && (module.exports = {
|
|
86
|
-
I18nModule
|
|
87
|
-
});
|
|
88
|
-
//# sourceMappingURL=I18nModule.cjs.map
|
package/dist/I18nModule.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/I18nModule.ts","../src/internal/module/i18nModule.ts","../src/internal/driver/i18n.ts"],"sourcesContent":["export { I18nModule } from './internal/module/i18nModule.js'\n","import * as Logix from '@logixjs/core'\nimport { Effect, Schema, SubscriptionRef } from 'effect'\n\nimport { I18nSnapshotSchema, I18nTag } from '../driver/i18n.js'\n\nconst I18nModuleDef = Logix.Module.make('@logixjs/i18n/I18nModule', {\n state: Schema.Struct({ snapshot: I18nSnapshotSchema }),\n actions: {\n changeLanguage: Schema.String,\n },\n})\n\nconst I18nModuleLogic = I18nModuleDef.logic(($) => ({\n setup: $.lifecycle.onStart(\n Effect.gen(function* () {\n const i18n = yield* $.root.resolve(I18nTag)\n const snap = yield* SubscriptionRef.get(i18n.snapshot)\n yield* $.state.mutate((draft) => {\n ;(draft as any).snapshot = snap\n })\n }),\n ),\n run: Effect.gen(function* () {\n const i18n = yield* $.root.resolve(I18nTag)\n\n yield* $.on(SubscriptionRef.changes(i18n.snapshot)).runFork((snap) =>\n $.state.mutate((draft) => {\n ;(draft as any).snapshot = snap\n }),\n )\n\n yield* $.onAction('changeLanguage').runFork((action) => i18n.changeLanguage(action.payload))\n }),\n}))\n\nexport const I18nModule: Logix.AnyModule = I18nModuleDef.implement({\n initial: { snapshot: { language: 'unknown', init: 'pending', seq: 0 } },\n logics: [I18nModuleLogic],\n})\n","import {\n Duration,\n Effect,\n Fiber,\n Layer,\n ManagedRuntime,\n Option,\n ServiceMap,\n Scope,\n Schema,\n Stream,\n SubscriptionRef,\n} from 'effect'\n\nimport type { I18nMessageToken, I18nTokenOptionsInput } from '../token/token.js'\nimport { token } from '../token/token.js'\n\nexport type { I18nTokenOptionsInput } from '../token/token.js'\n\nexport type I18nDriver = {\n readonly language: string\n readonly isInitialized?: boolean\n readonly t: (key: string, options?: unknown) => string\n readonly changeLanguage: (language: string) => Promise<unknown> | unknown\n readonly on: (event: 'initialized' | 'languageChanged', handler: (...args: any[]) => void) => unknown\n readonly off: (event: 'initialized' | 'languageChanged', handler: (...args: any[]) => void) => unknown\n}\n\nexport type I18nInitState = 'pending' | 'ready' | 'failed'\n\nexport type I18nSnapshot = {\n readonly language: string\n readonly init: I18nInitState\n readonly seq: number\n}\n\nexport const I18nSnapshotSchema = Schema.Struct({\n language: Schema.String,\n init: Schema.Literals(['pending', 'ready', 'failed']),\n seq: Schema.Number,\n})\n\nexport type I18nService = {\n readonly instance: I18nDriver\n readonly snapshot: SubscriptionRef.SubscriptionRef<I18nSnapshot>\n readonly token: (key: string, options?: I18nTokenOptionsInput) => I18nMessageToken\n readonly changeLanguage: (language: string) => Effect.Effect<void, never, never>\n readonly t: (key: string, options?: I18nTokenOptionsInput) => string\n readonly tReady: (\n key: string,\n options?: I18nTokenOptionsInput,\n timeoutMs?: number,\n ) => Effect.Effect<string, never, never>\n}\n\nexport class I18nTag extends ServiceMap.Service<I18nTag, I18nService>()('@logixjs/i18n/I18n') {}\n\nconst asNonEmptyString = (value: unknown): string | undefined =>\n typeof value === 'string' && value.length > 0 ? value : undefined\n\nconst makeI18nService = (driver: I18nDriver): Effect.Effect<I18nService, never, Scope.Scope> =>\n Effect.gen(function* () {\n const init: I18nInitState = driver.isInitialized ? 'ready' : 'pending'\n let currentSnapshot: I18nSnapshot = {\n language: driver.language,\n init,\n seq: 0,\n }\n const snapshotRef = yield* SubscriptionRef.make<I18nSnapshot>(currentSnapshot)\n\n const update = (patch: Partial<Pick<I18nSnapshot, 'language' | 'init'>>): Effect.Effect<void> =>\n SubscriptionRef.update(snapshotRef, (prev) => {\n const next: I18nSnapshot = {\n language: patch.language ?? prev.language,\n init: patch.init ?? prev.init,\n seq: prev.seq + 1,\n }\n currentSnapshot = next\n return next\n })\n\n const pushSnapshot = (patch: Partial<Pick<I18nSnapshot, 'language' | 'init'>>): void => {\n const next: I18nSnapshot = {\n language: patch.language ?? currentSnapshot.language,\n init: patch.init ?? currentSnapshot.init,\n seq: currentSnapshot.seq + 1,\n }\n currentSnapshot = next\n void Effect.runPromise(SubscriptionRef.set(snapshotRef, next).pipe(Effect.catchCause(() => Effect.void)))\n }\n\n const onInitialized = (): void => {\n pushSnapshot({ init: 'ready', language: driver.language })\n }\n\n const onLanguageChanged = (lang: unknown): void => {\n pushSnapshot({\n init: 'ready',\n language: asNonEmptyString(lang) ?? driver.language,\n })\n }\n\n yield* Effect.sync(() => {\n driver.on('initialized', onInitialized)\n driver.on('languageChanged', onLanguageChanged)\n })\n\n const scope = yield* Effect.scope\n yield* Scope.addFinalizer(\n scope,\n Effect.sync(() => {\n driver.off('initialized', onInitialized)\n driver.off('languageChanged', onLanguageChanged)\n }),\n )\n\n const changeLanguage = (language: string): Effect.Effect<void, never, never> =>\n Effect.gen(function* () {\n yield* update({ language, init: 'pending' })\n const exit = yield* Effect.exit(\n Effect.tryPromise({\n try: () => Promise.resolve(driver.changeLanguage(language)),\n catch: () => undefined,\n }),\n )\n if (exit._tag === 'Failure') {\n yield* update({ init: 'failed' })\n } else {\n yield* update({ init: 'ready', language })\n }\n })\n\n const fallback = (key: string, options?: I18nTokenOptionsInput): string =>\n typeof options?.defaultValue === 'string' ? options.defaultValue : key\n\n const t = (key: string, options?: I18nTokenOptionsInput): string => {\n if (currentSnapshot.init !== 'ready') {\n return fallback(key, options)\n }\n try {\n return driver.t(key, options)\n } catch {\n return fallback(key, options)\n }\n }\n\n const tReady = (\n key: string,\n options?: I18nTokenOptionsInput,\n timeoutMs?: number,\n ): Effect.Effect<string, never, never> =>\n Effect.gen(function* () {\n const cap = timeoutMs ?? 5000\n const snap0 = yield* SubscriptionRef.get(snapshotRef)\n if (snap0.init === 'ready') return t(key, options)\n if (snap0.init === 'failed') return fallback(key, options)\n\n const wait = Stream.filter(SubscriptionRef.changes(snapshotRef), (s) => s.init !== 'pending').pipe(\n Stream.runHead,\n Effect.timeoutOption(Duration.millis(cap)),\n Effect.map((maybe) => (Option.isSome(maybe) ? maybe.value : Option.none())),\n )\n\n const fiber = yield* wait.pipe(Effect.forkChild)\n\n const snap1 = yield* SubscriptionRef.get(snapshotRef)\n if (snap1.init !== 'pending') {\n yield* Fiber.interrupt(fiber)\n return snap1.init === 'ready' ? t(key, options) : fallback(key, options)\n }\n\n const outcome = yield* Fiber.join(fiber)\n return Option.match(outcome, {\n onNone: () => fallback(key, options),\n onSome: (snap) => (snap.init === 'ready' ? t(key, options) : fallback(key, options)),\n })\n })\n\n return {\n instance: driver,\n snapshot: snapshotRef,\n token,\n changeLanguage,\n t,\n tReady,\n } as const\n })\n\nexport const I18n = {\n layer: (driver: I18nDriver): Layer.Layer<I18nTag, never, never> => Layer.effect(I18nTag, makeI18nService(driver)),\n} as const\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,IAAAA,iBAAgD;;;ACDhD,oBAYO;AAwBA,IAAM,qBAAqB,qBAAO,OAAO;AAAA,EAC9C,UAAU,qBAAO;AAAA,EACjB,MAAM,qBAAO,SAAS,CAAC,WAAW,SAAS,QAAQ,CAAC;AAAA,EACpD,KAAK,qBAAO;AACd,CAAC;AAeM,IAAM,UAAN,cAAsB,yBAAW,QAA8B,EAAE,oBAAoB,EAAE;AAAC;;;ADlD/F,IAAM,gBAAsB,aAAO,KAAK,4BAA4B;AAAA,EAClE,OAAO,sBAAO,OAAO,EAAE,UAAU,mBAAmB,CAAC;AAAA,EACrD,SAAS;AAAA,IACP,gBAAgB,sBAAO;AAAA,EACzB;AACF,CAAC;AAED,IAAM,kBAAkB,cAAc,MAAM,CAAC,OAAO;AAAA,EAClD,OAAO,EAAE,UAAU;AAAA,IACjB,sBAAO,IAAI,aAAa;AACtB,YAAM,OAAO,OAAO,EAAE,KAAK,QAAQ,OAAO;AAC1C,YAAM,OAAO,OAAO,+BAAgB,IAAI,KAAK,QAAQ;AACrD,aAAO,EAAE,MAAM,OAAO,CAAC,UAAU;AAC/B;AAAC,QAAC,MAAc,WAAW;AAAA,MAC7B,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAAA,EACA,KAAK,sBAAO,IAAI,aAAa;AAC3B,UAAM,OAAO,OAAO,EAAE,KAAK,QAAQ,OAAO;AAE1C,WAAO,EAAE,GAAG,+BAAgB,QAAQ,KAAK,QAAQ,CAAC,EAAE;AAAA,MAAQ,CAAC,SAC3D,EAAE,MAAM,OAAO,CAAC,UAAU;AACxB;AAAC,QAAC,MAAc,WAAW;AAAA,MAC7B,CAAC;AAAA,IACH;AAEA,WAAO,EAAE,SAAS,gBAAgB,EAAE,QAAQ,CAAC,WAAW,KAAK,eAAe,OAAO,OAAO,CAAC;AAAA,EAC7F,CAAC;AACH,EAAE;AAEK,IAAM,aAA8B,cAAc,UAAU;AAAA,EACjE,SAAS,EAAE,UAAU,EAAE,UAAU,WAAW,MAAM,WAAW,KAAK,EAAE,EAAE;AAAA,EACtE,QAAQ,CAAC,eAAe;AAC1B,CAAC;","names":["import_effect"]}
|
package/dist/I18nModule.d.cts
DELETED
package/dist/I18nModule.d.ts
DELETED
package/dist/I18nModule.js
DELETED
package/dist/I18nModule.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internal/driver/i18n.ts"],"sourcesContent":["import {\n Duration,\n Effect,\n Fiber,\n Layer,\n ManagedRuntime,\n Option,\n ServiceMap,\n Scope,\n Schema,\n Stream,\n SubscriptionRef,\n} from 'effect'\n\nimport type { I18nMessageToken, I18nTokenOptionsInput } from '../token/token.js'\nimport { token } from '../token/token.js'\n\nexport type { I18nTokenOptionsInput } from '../token/token.js'\n\nexport type I18nDriver = {\n readonly language: string\n readonly isInitialized?: boolean\n readonly t: (key: string, options?: unknown) => string\n readonly changeLanguage: (language: string) => Promise<unknown> | unknown\n readonly on: (event: 'initialized' | 'languageChanged', handler: (...args: any[]) => void) => unknown\n readonly off: (event: 'initialized' | 'languageChanged', handler: (...args: any[]) => void) => unknown\n}\n\nexport type I18nInitState = 'pending' | 'ready' | 'failed'\n\nexport type I18nSnapshot = {\n readonly language: string\n readonly init: I18nInitState\n readonly seq: number\n}\n\nexport const I18nSnapshotSchema = Schema.Struct({\n language: Schema.String,\n init: Schema.Literals(['pending', 'ready', 'failed']),\n seq: Schema.Number,\n})\n\nexport type I18nService = {\n readonly instance: I18nDriver\n readonly snapshot: SubscriptionRef.SubscriptionRef<I18nSnapshot>\n readonly token: (key: string, options?: I18nTokenOptionsInput) => I18nMessageToken\n readonly changeLanguage: (language: string) => Effect.Effect<void, never, never>\n readonly t: (key: string, options?: I18nTokenOptionsInput) => string\n readonly tReady: (\n key: string,\n options?: I18nTokenOptionsInput,\n timeoutMs?: number,\n ) => Effect.Effect<string, never, never>\n}\n\nexport class I18nTag extends ServiceMap.Service<I18nTag, I18nService>()('@logixjs/i18n/I18n') {}\n\nconst asNonEmptyString = (value: unknown): string | undefined =>\n typeof value === 'string' && value.length > 0 ? value : undefined\n\nconst makeI18nService = (driver: I18nDriver): Effect.Effect<I18nService, never, Scope.Scope> =>\n Effect.gen(function* () {\n const init: I18nInitState = driver.isInitialized ? 'ready' : 'pending'\n let currentSnapshot: I18nSnapshot = {\n language: driver.language,\n init,\n seq: 0,\n }\n const snapshotRef = yield* SubscriptionRef.make<I18nSnapshot>(currentSnapshot)\n\n const update = (patch: Partial<Pick<I18nSnapshot, 'language' | 'init'>>): Effect.Effect<void> =>\n SubscriptionRef.update(snapshotRef, (prev) => {\n const next: I18nSnapshot = {\n language: patch.language ?? prev.language,\n init: patch.init ?? prev.init,\n seq: prev.seq + 1,\n }\n currentSnapshot = next\n return next\n })\n\n const pushSnapshot = (patch: Partial<Pick<I18nSnapshot, 'language' | 'init'>>): void => {\n const next: I18nSnapshot = {\n language: patch.language ?? currentSnapshot.language,\n init: patch.init ?? currentSnapshot.init,\n seq: currentSnapshot.seq + 1,\n }\n currentSnapshot = next\n void Effect.runPromise(SubscriptionRef.set(snapshotRef, next).pipe(Effect.catchCause(() => Effect.void)))\n }\n\n const onInitialized = (): void => {\n pushSnapshot({ init: 'ready', language: driver.language })\n }\n\n const onLanguageChanged = (lang: unknown): void => {\n pushSnapshot({\n init: 'ready',\n language: asNonEmptyString(lang) ?? driver.language,\n })\n }\n\n yield* Effect.sync(() => {\n driver.on('initialized', onInitialized)\n driver.on('languageChanged', onLanguageChanged)\n })\n\n const scope = yield* Effect.scope\n yield* Scope.addFinalizer(\n scope,\n Effect.sync(() => {\n driver.off('initialized', onInitialized)\n driver.off('languageChanged', onLanguageChanged)\n }),\n )\n\n const changeLanguage = (language: string): Effect.Effect<void, never, never> =>\n Effect.gen(function* () {\n yield* update({ language, init: 'pending' })\n const exit = yield* Effect.exit(\n Effect.tryPromise({\n try: () => Promise.resolve(driver.changeLanguage(language)),\n catch: () => undefined,\n }),\n )\n if (exit._tag === 'Failure') {\n yield* update({ init: 'failed' })\n } else {\n yield* update({ init: 'ready', language })\n }\n })\n\n const fallback = (key: string, options?: I18nTokenOptionsInput): string =>\n typeof options?.defaultValue === 'string' ? options.defaultValue : key\n\n const t = (key: string, options?: I18nTokenOptionsInput): string => {\n if (currentSnapshot.init !== 'ready') {\n return fallback(key, options)\n }\n try {\n return driver.t(key, options)\n } catch {\n return fallback(key, options)\n }\n }\n\n const tReady = (\n key: string,\n options?: I18nTokenOptionsInput,\n timeoutMs?: number,\n ): Effect.Effect<string, never, never> =>\n Effect.gen(function* () {\n const cap = timeoutMs ?? 5000\n const snap0 = yield* SubscriptionRef.get(snapshotRef)\n if (snap0.init === 'ready') return t(key, options)\n if (snap0.init === 'failed') return fallback(key, options)\n\n const wait = Stream.filter(SubscriptionRef.changes(snapshotRef), (s) => s.init !== 'pending').pipe(\n Stream.runHead,\n Effect.timeoutOption(Duration.millis(cap)),\n Effect.map((maybe) => (Option.isSome(maybe) ? maybe.value : Option.none())),\n )\n\n const fiber = yield* wait.pipe(Effect.forkChild)\n\n const snap1 = yield* SubscriptionRef.get(snapshotRef)\n if (snap1.init !== 'pending') {\n yield* Fiber.interrupt(fiber)\n return snap1.init === 'ready' ? t(key, options) : fallback(key, options)\n }\n\n const outcome = yield* Fiber.join(fiber)\n return Option.match(outcome, {\n onNone: () => fallback(key, options),\n onSome: (snap) => (snap.init === 'ready' ? t(key, options) : fallback(key, options)),\n })\n })\n\n return {\n instance: driver,\n snapshot: snapshotRef,\n token,\n changeLanguage,\n t,\n tReady,\n } as const\n })\n\nexport const I18n = {\n layer: (driver: I18nDriver): Layer.Layer<I18nTag, never, never> => Layer.effect(I18nTag, makeI18nService(driver)),\n} as const\n"],"mappings":";;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAwBA,IAAM,qBAAqB,OAAO,OAAO;AAAA,EAC9C,UAAU,OAAO;AAAA,EACjB,MAAM,OAAO,SAAS,CAAC,WAAW,SAAS,QAAQ,CAAC;AAAA,EACpD,KAAK,OAAO;AACd,CAAC;AAeM,IAAM,UAAN,cAAsB,WAAW,QAA8B,EAAE,oBAAoB,EAAE;AAAC;AAE/F,IAAM,mBAAmB,CAAC,UACxB,OAAO,UAAU,YAAY,MAAM,SAAS,IAAI,QAAQ;AAE1D,IAAM,kBAAkB,CAAC,WACvB,OAAO,IAAI,aAAa;AACtB,QAAM,OAAsB,OAAO,gBAAgB,UAAU;AAC7D,MAAI,kBAAgC;AAAA,IAClC,UAAU,OAAO;AAAA,IACjB;AAAA,IACA,KAAK;AAAA,EACP;AACA,QAAM,cAAc,OAAO,gBAAgB,KAAmB,eAAe;AAE7E,QAAM,SAAS,CAAC,UACd,gBAAgB,OAAO,aAAa,CAAC,SAAS;AAC5C,UAAM,OAAqB;AAAA,MACzB,UAAU,MAAM,YAAY,KAAK;AAAA,MACjC,MAAM,MAAM,QAAQ,KAAK;AAAA,MACzB,KAAK,KAAK,MAAM;AAAA,IAClB;AACA,sBAAkB;AAClB,WAAO;AAAA,EACT,CAAC;AAEH,QAAM,eAAe,CAAC,UAAkE;AACtF,UAAM,OAAqB;AAAA,MACzB,UAAU,MAAM,YAAY,gBAAgB;AAAA,MAC5C,MAAM,MAAM,QAAQ,gBAAgB;AAAA,MACpC,KAAK,gBAAgB,M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ACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF,CAAC;AAEI,IAAM,OAAO;AAAA,EAClB,OAAO,CAAC,WAA2D,MAAM,OAAO,SAAS,gBAAgB,MAAM,CAAC;AAClH;","names":[]}
|
package/dist/chunk-FDPDEDU7.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-FDPDEDU7.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/chunk-LW6LHDDL.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-LW6LHDDL.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|