@shuo-li/i18n 1.0.8 → 1.1.0

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.
@@ -39,16 +39,13 @@ interface I18nInitOptions {
39
39
  sse?: SSEConfig;
40
40
  };
41
41
  }
42
- interface I18nValue {
43
- termCode?: string;
44
- langValue?: string;
45
- }
46
42
  interface PullLangBlock {
47
43
  langCode: string;
48
44
  modules: Array<{
49
45
  moduleCode: string;
50
46
  version: number;
51
- i18nValues: I18nValue[];
47
+ /** transform 函数返回的最终资源对象,直接写入 DB 和 i18next */
48
+ resources: Record<string, unknown>;
52
49
  }>;
53
50
  }
54
51
  interface SSEMessage {
@@ -39,16 +39,13 @@ interface I18nInitOptions {
39
39
  sse?: SSEConfig;
40
40
  };
41
41
  }
42
- interface I18nValue {
43
- termCode?: string;
44
- langValue?: string;
45
- }
46
42
  interface PullLangBlock {
47
43
  langCode: string;
48
44
  modules: Array<{
49
45
  moduleCode: string;
50
46
  version: number;
51
- i18nValues: I18nValue[];
47
+ /** transform 函数返回的最终资源对象,直接写入 DB 和 i18next */
48
+ resources: Record<string, unknown>;
52
49
  }>;
53
50
  }
54
51
  interface SSEMessage {
@@ -5,6 +5,52 @@ function emitI18nResourcesUpdated() {
5
5
  window.dispatchEvent(new CustomEvent(I18N_RESOURCES_UPDATED_EVENT));
6
6
  }
7
7
 
8
+ // src/core/utils.ts
9
+ function buildKey(moduleCode, langCode, store) {
10
+ return store.cacheGroupKey ? `${moduleCode}_${langCode}_${store.cacheGroupKey}` : `${moduleCode}_${langCode}`;
11
+ }
12
+ function flatToNested(flat) {
13
+ const result = {};
14
+ for (const [key, value] of Object.entries(flat)) {
15
+ const parts = key.split(".");
16
+ let cur = result;
17
+ for (let i = 0; i < parts.length - 1; i++) {
18
+ const part = parts[i];
19
+ if (typeof cur[part] !== "object" || cur[part] === null) {
20
+ cur[part] = {};
21
+ }
22
+ cur = cur[part];
23
+ }
24
+ cur[parts[parts.length - 1]] = value;
25
+ }
26
+ return result;
27
+ }
28
+ function deepMerge(target, source) {
29
+ const result = { ...target };
30
+ for (const [key, sv] of Object.entries(source)) {
31
+ const tv = result[key];
32
+ if (sv !== null && typeof sv === "object" && !Array.isArray(sv) && tv !== null && typeof tv === "object" && !Array.isArray(tv)) {
33
+ result[key] = deepMerge(tv, sv);
34
+ } else {
35
+ result[key] = sv;
36
+ }
37
+ }
38
+ return result;
39
+ }
40
+ function toDefaultParams(p) {
41
+ const result = {};
42
+ if (p?.storeName) result["storeName"] = p.storeName;
43
+ if (p?.langCode) result["langCode"] = p.langCode;
44
+ if (p?.moduleCode) result["moduleCode"] = p.moduleCode;
45
+ if (p?.version != null) result["version"] = String(p.version);
46
+ return result;
47
+ }
48
+ function toQueryString(params) {
49
+ return new URLSearchParams(
50
+ Object.entries(params).filter(([, v]) => v != null).map(([k, v]) => [k, String(v)])
51
+ ).toString();
52
+ }
53
+
8
54
  // src/core/manager.ts
9
55
  import i18n from "i18next";
10
56
 
@@ -169,61 +215,6 @@ var WorkerManager = class {
169
215
  }
170
216
  };
171
217
 
172
- // src/core/utils.ts
173
- function buildKey(moduleCode, langCode, store) {
174
- return store.cacheGroupKey ? `${moduleCode}_${langCode}_${store.cacheGroupKey}` : `${moduleCode}_${langCode}`;
175
- }
176
- function flatToNested(flat) {
177
- const result = {};
178
- for (const [key, value] of Object.entries(flat)) {
179
- const parts = key.split(".");
180
- let cur = result;
181
- for (let i = 0; i < parts.length - 1; i++) {
182
- const part = parts[i];
183
- if (typeof cur[part] !== "object" || cur[part] === null) {
184
- cur[part] = {};
185
- }
186
- cur = cur[part];
187
- }
188
- cur[parts[parts.length - 1]] = value;
189
- }
190
- return result;
191
- }
192
- function deepMerge(target, source) {
193
- const result = { ...target };
194
- for (const [key, sv] of Object.entries(source)) {
195
- const tv = result[key];
196
- if (sv !== null && typeof sv === "object" && !Array.isArray(sv) && tv !== null && typeof tv === "object" && !Array.isArray(tv)) {
197
- result[key] = deepMerge(tv, sv);
198
- } else {
199
- result[key] = sv;
200
- }
201
- }
202
- return result;
203
- }
204
- function parseI18nValues(values) {
205
- const result = {};
206
- for (const { termCode, langValue } of values) {
207
- if (termCode && langValue !== void 0) {
208
- result[termCode] = langValue ?? "";
209
- }
210
- }
211
- return result;
212
- }
213
- function toDefaultParams(p) {
214
- const result = {};
215
- if (p?.storeName) result["storeName"] = p.storeName;
216
- if (p?.langCode) result["langCode"] = p.langCode;
217
- if (p?.moduleCode) result["moduleCode"] = p.moduleCode;
218
- if (p?.version != null) result["version"] = String(p.version);
219
- return result;
220
- }
221
- function toQueryString(params) {
222
- return new URLSearchParams(
223
- Object.entries(params).filter(([, v]) => v != null).map(([k, v]) => [k, String(v)])
224
- ).toString();
225
- }
226
-
227
218
  // src/core/manager.ts
228
219
  var PRIORITY_MODULES = ["ENUMS", "CUSTOMER"];
229
220
  var currentLang = "zh_CN";
@@ -316,7 +307,7 @@ async function getResource(moduleCode, langCode) {
316
307
  if (result.status === "rejected") continue;
317
308
  const record = result.value;
318
309
  if (!record?.resources) continue;
319
- merged = i === 0 ? deepMerge(merged, record.resources) : deepMerge(merged, flatToNested(record.resources));
310
+ merged = deepMerge(merged, record.resources);
320
311
  }
321
312
  return merged;
322
313
  }
@@ -339,7 +330,8 @@ async function _initI18n(options) {
339
330
  resolvedStaticModules = options.staticLocales ? [...new Set(
340
331
  Object.values(options.staticLocales).flatMap((langModules) => Object.keys(langModules))
341
332
  )] : [];
342
- await storage.ensureStores(resolvedStores);
333
+ const schemaVersion = options.version != null ? Math.max(1, Math.trunc(Number(options.version)) || 1) : 1;
334
+ await storage.ensureStores(resolvedStores, schemaVersion);
343
335
  await checkCacheVersion(storage, options);
344
336
  const allKnownModules = sortedModules();
345
337
  for (const lang of resolvedLanguages) {
@@ -397,9 +389,8 @@ async function doUnloginPull(storage, options) {
397
389
  let blocks;
398
390
  try {
399
391
  blocks = await doFetch(apiContext.unloginPull, options);
400
- } catch {
401
- await injectCurrentLanguageModules(currentLang);
402
- await i18n.changeLanguage(currentLang);
392
+ } catch (err) {
393
+ console.error("[i18n] unloginPull \u8BF7\u6C42\u5931\u8D25\uFF0C\u964D\u7EA7\u9759\u6001\u515C\u5E95", err);
403
394
  emitI18nResourcesUpdated();
404
395
  return;
405
396
  }
@@ -407,10 +398,9 @@ async function doUnloginPull(storage, options) {
407
398
  for (const mod of block.modules ?? []) {
408
399
  const key = buildKey(mod.moduleCode, block.langCode, baseStore);
409
400
  const existing = await storage.getRecord(baseStore.name, key);
410
- const parsed = parseI18nValues(mod.i18nValues ?? []);
411
401
  const resources = deepMerge(
412
402
  existing?.resources ?? {},
413
- flatToNested(parsed)
403
+ mod.resources
414
404
  );
415
405
  await storage.putRecord(baseStore.name, {
416
406
  key,
@@ -458,7 +448,13 @@ function runWorker(options, tasks, pull) {
458
448
  },
459
449
  {
460
450
  onRawData: async (task, raw) => {
461
- const blocks = pull.transform ? pull.transform(raw) : raw;
451
+ let blocks;
452
+ try {
453
+ blocks = pull.transform ? pull.transform(raw) : raw;
454
+ } catch (err) {
455
+ console.error("[i18n] pull transform \u5931\u8D25", task, err);
456
+ return;
457
+ }
462
458
  const store = resolvedStores.find((s) => s.name === task.storeName);
463
459
  if (!store) return;
464
460
  const storeIndex = resolvedStores.indexOf(store);
@@ -467,11 +463,7 @@ function runWorker(options, tasks, pull) {
467
463
  const key = buildKey(mod.moduleCode, block.langCode, store);
468
464
  const existing = await storage.getRecord(store.name, key);
469
465
  if (existing && mod.version <= existing.version) continue;
470
- const parsed = parseI18nValues(mod.i18nValues ?? []);
471
- const resources = storeIndex === 0 ? deepMerge(
472
- existing?.resources ?? {},
473
- flatToNested(parsed)
474
- ) : { ...existing?.resources ?? {}, ...parsed };
466
+ const resources = storeIndex === 0 ? deepMerge(existing?.resources ?? {}, mod.resources) : { ...existing?.resources ?? {}, ...mod.resources };
475
467
  await storage.putRecord(store.name, {
476
468
  key,
477
469
  moduleCode: mod.moduleCode,
@@ -617,16 +609,7 @@ async function pullAndStore(task, fromVersion, options) {
617
609
  const key = buildKey(mod.moduleCode, block.langCode, store);
618
610
  const existing = await storage.getRecord(store.name, key);
619
611
  if (mod.version <= (existing?.version ?? 0)) continue;
620
- let resources;
621
- const parsed = parseI18nValues(mod.i18nValues ?? []);
622
- if (storeIndex === 0) {
623
- resources = deepMerge(
624
- existing?.resources ?? {},
625
- flatToNested(parsed)
626
- );
627
- } else {
628
- resources = { ...existing?.resources ?? {}, ...parsed };
629
- }
612
+ const resources = storeIndex === 0 ? deepMerge(existing?.resources ?? {}, mod.resources) : { ...existing?.resources ?? {}, ...mod.resources };
630
613
  const version = Math.max(mod.version, task.targetVersion);
631
614
  await storage.putRecord(store.name, {
632
615
  key,
@@ -682,5 +665,7 @@ async function getStoredVersion(store, moduleCode, langCode) {
682
665
  export {
683
666
  I18N_RESOURCES_UPDATED_EVENT,
684
667
  emitI18nResourcesUpdated,
668
+ flatToNested,
669
+ deepMerge,
685
670
  createI18nManager
686
671
  };
@@ -5,6 +5,52 @@ function emitI18nResourcesUpdated() {
5
5
  window.dispatchEvent(new CustomEvent(I18N_RESOURCES_UPDATED_EVENT));
6
6
  }
7
7
 
8
+ // src/core/utils.ts
9
+ function buildKey(moduleCode, langCode, store) {
10
+ return store.cacheGroupKey ? `${moduleCode}_${langCode}_${store.cacheGroupKey}` : `${moduleCode}_${langCode}`;
11
+ }
12
+ function flatToNested(flat) {
13
+ const result = {};
14
+ for (const [key, value] of Object.entries(flat)) {
15
+ const parts = key.split(".");
16
+ let cur = result;
17
+ for (let i = 0; i < parts.length - 1; i++) {
18
+ const part = parts[i];
19
+ if (typeof cur[part] !== "object" || cur[part] === null) {
20
+ cur[part] = {};
21
+ }
22
+ cur = cur[part];
23
+ }
24
+ cur[parts[parts.length - 1]] = value;
25
+ }
26
+ return result;
27
+ }
28
+ function deepMerge(target, source) {
29
+ const result = { ...target };
30
+ for (const [key, sv] of Object.entries(source)) {
31
+ const tv = result[key];
32
+ if (sv !== null && typeof sv === "object" && !Array.isArray(sv) && tv !== null && typeof tv === "object" && !Array.isArray(tv)) {
33
+ result[key] = deepMerge(tv, sv);
34
+ } else {
35
+ result[key] = sv;
36
+ }
37
+ }
38
+ return result;
39
+ }
40
+ function toDefaultParams(p) {
41
+ const result = {};
42
+ if (_optionalChain([p, 'optionalAccess', _2 => _2.storeName])) result["storeName"] = p.storeName;
43
+ if (_optionalChain([p, 'optionalAccess', _3 => _3.langCode])) result["langCode"] = p.langCode;
44
+ if (_optionalChain([p, 'optionalAccess', _4 => _4.moduleCode])) result["moduleCode"] = p.moduleCode;
45
+ if (_optionalChain([p, 'optionalAccess', _5 => _5.version]) != null) result["version"] = String(p.version);
46
+ return result;
47
+ }
48
+ function toQueryString(params) {
49
+ return new URLSearchParams(
50
+ Object.entries(params).filter(([, v]) => v != null).map(([k, v]) => [k, String(v)])
51
+ ).toString();
52
+ }
53
+
8
54
  // src/core/manager.ts
9
55
  var _i18next = require('i18next'); var _i18next2 = _interopRequireDefault(_i18next);
10
56
 
@@ -33,7 +79,7 @@ var SSEClient = class {
33
79
  clearTimeout(this.reconnectTimer);
34
80
  this.reconnectTimer = null;
35
81
  }
36
- _optionalChain([this, 'access', _2 => _2.abortController, 'optionalAccess', _3 => _3.abort, 'call', _4 => _4()]);
82
+ _optionalChain([this, 'access', _6 => _6.abortController, 'optionalAccess', _7 => _7.abort, 'call', _8 => _8()]);
37
83
  this.abortController = null;
38
84
  }
39
85
  async connect() {
@@ -103,7 +149,7 @@ var SSEClient = class {
103
149
  if (!data) return;
104
150
  try {
105
151
  const parsed = JSON.parse(data);
106
- _optionalChain([this, 'access', _5 => _5.onMessage, 'optionalCall', _6 => _6(parsed)]);
152
+ _optionalChain([this, 'access', _9 => _9.onMessage, 'optionalCall', _10 => _10(parsed)]);
107
153
  } catch (e2) {
108
154
  }
109
155
  }
@@ -143,16 +189,16 @@ var WorkerManager = class {
143
189
  this.pendingCallbacks.add(p);
144
190
  p.finally(() => this.pendingCallbacks.delete(p));
145
191
  } else if (msg.type === "moduleError") {
146
- _optionalChain([callbacks, 'access', _7 => _7.onModuleError, 'optionalCall', _8 => _8(msg)]);
192
+ _optionalChain([callbacks, 'access', _11 => _11.onModuleError, 'optionalCall', _12 => _12(msg)]);
147
193
  } else if (msg.type === "done" || msg.type === "error") {
148
- if (msg.type === "error") _optionalChain([callbacks, 'access', _9 => _9.onError, 'optionalCall', _10 => _10()]);
194
+ if (msg.type === "error") _optionalChain([callbacks, 'access', _13 => _13.onError, 'optionalCall', _14 => _14()]);
149
195
  this.finalize(callbacks);
150
196
  }
151
197
  });
152
198
  worker.postMessage({ type: "start", payload });
153
199
  }
154
200
  terminate() {
155
- _optionalChain([this, 'access', _11 => _11.worker, 'optionalAccess', _12 => _12.terminate, 'call', _13 => _13()]);
201
+ _optionalChain([this, 'access', _15 => _15.worker, 'optionalAccess', _16 => _16.terminate, 'call', _17 => _17()]);
156
202
  this.worker = null;
157
203
  }
158
204
  isRunning() {
@@ -169,61 +215,6 @@ var WorkerManager = class {
169
215
  }
170
216
  };
171
217
 
172
- // src/core/utils.ts
173
- function buildKey(moduleCode, langCode, store) {
174
- return store.cacheGroupKey ? `${moduleCode}_${langCode}_${store.cacheGroupKey}` : `${moduleCode}_${langCode}`;
175
- }
176
- function flatToNested(flat) {
177
- const result = {};
178
- for (const [key, value] of Object.entries(flat)) {
179
- const parts = key.split(".");
180
- let cur = result;
181
- for (let i = 0; i < parts.length - 1; i++) {
182
- const part = parts[i];
183
- if (typeof cur[part] !== "object" || cur[part] === null) {
184
- cur[part] = {};
185
- }
186
- cur = cur[part];
187
- }
188
- cur[parts[parts.length - 1]] = value;
189
- }
190
- return result;
191
- }
192
- function deepMerge(target, source) {
193
- const result = { ...target };
194
- for (const [key, sv] of Object.entries(source)) {
195
- const tv = result[key];
196
- if (sv !== null && typeof sv === "object" && !Array.isArray(sv) && tv !== null && typeof tv === "object" && !Array.isArray(tv)) {
197
- result[key] = deepMerge(tv, sv);
198
- } else {
199
- result[key] = sv;
200
- }
201
- }
202
- return result;
203
- }
204
- function parseI18nValues(values) {
205
- const result = {};
206
- for (const { termCode, langValue } of values) {
207
- if (termCode && langValue !== void 0) {
208
- result[termCode] = _nullishCoalesce(langValue, () => ( ""));
209
- }
210
- }
211
- return result;
212
- }
213
- function toDefaultParams(p) {
214
- const result = {};
215
- if (_optionalChain([p, 'optionalAccess', _14 => _14.storeName])) result["storeName"] = p.storeName;
216
- if (_optionalChain([p, 'optionalAccess', _15 => _15.langCode])) result["langCode"] = p.langCode;
217
- if (_optionalChain([p, 'optionalAccess', _16 => _16.moduleCode])) result["moduleCode"] = p.moduleCode;
218
- if (_optionalChain([p, 'optionalAccess', _17 => _17.version]) != null) result["version"] = String(p.version);
219
- return result;
220
- }
221
- function toQueryString(params) {
222
- return new URLSearchParams(
223
- Object.entries(params).filter(([, v]) => v != null).map(([k, v]) => [k, String(v)])
224
- ).toString();
225
- }
226
-
227
218
  // src/core/manager.ts
228
219
  var PRIORITY_MODULES = ["ENUMS", "CUSTOMER"];
229
220
  var currentLang = "zh_CN";
@@ -316,7 +307,7 @@ async function getResource(moduleCode, langCode) {
316
307
  if (result.status === "rejected") continue;
317
308
  const record = result.value;
318
309
  if (!_optionalChain([record, 'optionalAccess', _18 => _18.resources])) continue;
319
- merged = i === 0 ? deepMerge(merged, record.resources) : deepMerge(merged, flatToNested(record.resources));
310
+ merged = deepMerge(merged, record.resources);
320
311
  }
321
312
  return merged;
322
313
  }
@@ -339,7 +330,8 @@ async function _initI18n(options) {
339
330
  resolvedStaticModules = options.staticLocales ? [...new Set(
340
331
  Object.values(options.staticLocales).flatMap((langModules) => Object.keys(langModules))
341
332
  )] : [];
342
- await storage.ensureStores(resolvedStores);
333
+ const schemaVersion = options.version != null ? Math.max(1, Math.trunc(Number(options.version)) || 1) : 1;
334
+ await storage.ensureStores(resolvedStores, schemaVersion);
343
335
  await checkCacheVersion(storage, options);
344
336
  const allKnownModules = sortedModules();
345
337
  for (const lang of resolvedLanguages) {
@@ -397,9 +389,8 @@ async function doUnloginPull(storage, options) {
397
389
  let blocks;
398
390
  try {
399
391
  blocks = await doFetch(apiContext.unloginPull, options);
400
- } catch (e4) {
401
- await injectCurrentLanguageModules(currentLang);
402
- await _i18next2.default.changeLanguage(currentLang);
392
+ } catch (err) {
393
+ console.error("[i18n] unloginPull \u8BF7\u6C42\u5931\u8D25\uFF0C\u964D\u7EA7\u9759\u6001\u515C\u5E95", err);
403
394
  emitI18nResourcesUpdated();
404
395
  return;
405
396
  }
@@ -407,10 +398,9 @@ async function doUnloginPull(storage, options) {
407
398
  for (const mod of _nullishCoalesce(block.modules, () => ( []))) {
408
399
  const key = buildKey(mod.moduleCode, block.langCode, baseStore);
409
400
  const existing = await storage.getRecord(baseStore.name, key);
410
- const parsed = parseI18nValues(_nullishCoalesce(mod.i18nValues, () => ( [])));
411
401
  const resources = deepMerge(
412
402
  _nullishCoalesce(_optionalChain([existing, 'optionalAccess', _21 => _21.resources]), () => ( {})),
413
- flatToNested(parsed)
403
+ mod.resources
414
404
  );
415
405
  await storage.putRecord(baseStore.name, {
416
406
  key,
@@ -458,7 +448,13 @@ function runWorker(options, tasks, pull) {
458
448
  },
459
449
  {
460
450
  onRawData: async (task, raw) => {
461
- const blocks = pull.transform ? pull.transform(raw) : raw;
451
+ let blocks;
452
+ try {
453
+ blocks = pull.transform ? pull.transform(raw) : raw;
454
+ } catch (err) {
455
+ console.error("[i18n] pull transform \u5931\u8D25", task, err);
456
+ return;
457
+ }
462
458
  const store = resolvedStores.find((s) => s.name === task.storeName);
463
459
  if (!store) return;
464
460
  const storeIndex = resolvedStores.indexOf(store);
@@ -467,11 +463,7 @@ function runWorker(options, tasks, pull) {
467
463
  const key = buildKey(mod.moduleCode, block.langCode, store);
468
464
  const existing = await storage.getRecord(store.name, key);
469
465
  if (existing && mod.version <= existing.version) continue;
470
- const parsed = parseI18nValues(_nullishCoalesce(mod.i18nValues, () => ( [])));
471
- const resources = storeIndex === 0 ? deepMerge(
472
- _nullishCoalesce(_optionalChain([existing, 'optionalAccess', _22 => _22.resources]), () => ( {})),
473
- flatToNested(parsed)
474
- ) : { ..._nullishCoalesce(_optionalChain([existing, 'optionalAccess', _23 => _23.resources]), () => ( {})), ...parsed };
466
+ const resources = storeIndex === 0 ? deepMerge(_nullishCoalesce(_optionalChain([existing, 'optionalAccess', _22 => _22.resources]), () => ( {})), mod.resources) : { ..._nullishCoalesce(_optionalChain([existing, 'optionalAccess', _23 => _23.resources]), () => ( {})), ...mod.resources };
475
467
  await storage.putRecord(store.name, {
476
468
  key,
477
469
  moduleCode: mod.moduleCode,
@@ -581,7 +573,7 @@ async function flushPendingSSESyncs(options) {
581
573
  task.moduleCode,
582
574
  task.langCode
583
575
  );
584
- } catch (e5) {
576
+ } catch (e4) {
585
577
  localVersion = 0;
586
578
  }
587
579
  if (task.targetVersion <= localVersion) continue;
@@ -592,7 +584,7 @@ async function flushPendingSSESyncs(options) {
592
584
  await _i18next2.default.changeLanguage(currentLang);
593
585
  emitI18nResourcesUpdated();
594
586
  }
595
- } catch (e6) {
587
+ } catch (e5) {
596
588
  }
597
589
  }
598
590
  } finally {
@@ -617,16 +609,7 @@ async function pullAndStore(task, fromVersion, options) {
617
609
  const key = buildKey(mod.moduleCode, block.langCode, store);
618
610
  const existing = await storage.getRecord(store.name, key);
619
611
  if (mod.version <= (_nullishCoalesce(_optionalChain([existing, 'optionalAccess', _27 => _27.version]), () => ( 0)))) continue;
620
- let resources;
621
- const parsed = parseI18nValues(_nullishCoalesce(mod.i18nValues, () => ( [])));
622
- if (storeIndex === 0) {
623
- resources = deepMerge(
624
- _nullishCoalesce(_optionalChain([existing, 'optionalAccess', _28 => _28.resources]), () => ( {})),
625
- flatToNested(parsed)
626
- );
627
- } else {
628
- resources = { ..._nullishCoalesce(_optionalChain([existing, 'optionalAccess', _29 => _29.resources]), () => ( {})), ...parsed };
629
- }
612
+ const resources = storeIndex === 0 ? deepMerge(_nullishCoalesce(_optionalChain([existing, 'optionalAccess', _28 => _28.resources]), () => ( {})), mod.resources) : { ..._nullishCoalesce(_optionalChain([existing, 'optionalAccess', _29 => _29.resources]), () => ( {})), ...mod.resources };
630
613
  const version = Math.max(mod.version, task.targetVersion);
631
614
  await storage.putRecord(store.name, {
632
615
  key,
@@ -683,4 +666,6 @@ async function getStoredVersion(store, moduleCode, langCode) {
683
666
 
684
667
 
685
668
 
686
- exports.I18N_RESOURCES_UPDATED_EVENT = I18N_RESOURCES_UPDATED_EVENT; exports.emitI18nResourcesUpdated = emitI18nResourcesUpdated; exports.createI18nManager = createI18nManager;
669
+
670
+
671
+ exports.I18N_RESOURCES_UPDATED_EVENT = I18N_RESOURCES_UPDATED_EVENT; exports.emitI18nResourcesUpdated = emitI18nResourcesUpdated; exports.flatToNested = flatToNested; exports.deepMerge = deepMerge; exports.createI18nManager = createI18nManager;
package/dist/index.cjs CHANGED
@@ -7,7 +7,9 @@ var _chunkAJJKJPNBcjs = require('./chunk-AJJKJPNB.cjs');
7
7
 
8
8
 
9
9
 
10
- var _chunk2EV6FQILcjs = require('./chunk-2EV6FQIL.cjs');
10
+
11
+
12
+ var _chunkT7476FJ4cjs = require('./chunk-T7476FJ4.cjs');
11
13
 
12
14
  // src/index.ts
13
15
  var _i18next = require('i18next'); var _i18next2 = _interopRequireDefault(_i18next);
@@ -20,12 +22,10 @@ function resourceStoreName(name) {
20
22
  }
21
23
  var dbInstance = null;
22
24
  var dbOpenPromise = null;
23
- var dbStoreNames = [];
24
- function openDB(storeNames, version) {
25
+ function openDB(storeNames, idbVersion) {
25
26
  return new Promise((resolve, reject) => {
26
- const req = version !== void 0 ? indexedDB.open(DB_NAME, version) : indexedDB.open(DB_NAME);
27
- req.onupgradeneeded = (event) => {
28
- if (version === void 0) return;
27
+ const request = indexedDB.open(DB_NAME, idbVersion);
28
+ request.onupgradeneeded = (event) => {
29
29
  const db = event.target.result;
30
30
  for (const name of storeNames) {
31
31
  const storeName = resourceStoreName(name);
@@ -36,8 +36,8 @@ function openDB(storeNames, version) {
36
36
  }
37
37
  }
38
38
  };
39
- req.onsuccess = () => {
40
- const db = req.result;
39
+ request.onsuccess = () => {
40
+ const db = request.result;
41
41
  db.onversionchange = () => {
42
42
  db.close();
43
43
  dbInstance = null;
@@ -47,31 +47,15 @@ function openDB(storeNames, version) {
47
47
  dbInstance = null;
48
48
  dbOpenPromise = null;
49
49
  };
50
- const missing = storeNames.filter((n) => !db.objectStoreNames.contains(resourceStoreName(n)));
51
- if (missing.length === 0 || version !== void 0) {
52
- resolve(db);
53
- return;
54
- }
55
- const nextVersion = db.version + 1;
56
- db.close();
57
- openDB(storeNames, nextVersion).then(resolve).catch(reject);
50
+ resolve(db);
58
51
  };
59
- req.onerror = () => reject(req.error);
60
- req.onblocked = () => reject(new Error("[i18n] IndexedDB open blocked"));
52
+ request.onerror = () => reject(request.error);
53
+ request.onblocked = () => reject(new Error("[i18n] IndexedDB open blocked"));
61
54
  });
62
55
  }
63
56
  function getDB() {
64
57
  if (dbInstance) return Promise.resolve(dbInstance);
65
- if (!dbOpenPromise) {
66
- dbOpenPromise = openDB(dbStoreNames).then((db) => {
67
- dbInstance = db;
68
- dbOpenPromise = null;
69
- return db;
70
- }).catch((err) => {
71
- dbOpenPromise = null;
72
- throw err;
73
- });
74
- }
58
+ if (!dbOpenPromise) throw new Error("[i18n] ensureStores must be called before using the DB");
75
59
  return dbOpenPromise;
76
60
  }
77
61
  function idbRequest(req) {
@@ -89,23 +73,26 @@ async function withRetry(fn) {
89
73
  }
90
74
  }
91
75
  var IndexedDBAdapter = class {
92
- async ensureStores(stores) {
76
+ /**
77
+ * schemaVersion 来自外部传入的 options.version。
78
+ * IDB 版本 = schemaVersion * 100 + stores.length,保证:
79
+ * - options.version 变化 → IDB 版本变化 → onupgradeneeded → 触发 checkCacheVersion 的数据清理
80
+ * - store 数量变化(未登录→登录)→ IDB 版本变化 → onupgradeneeded → 新增 store
81
+ */
82
+ async ensureStores(stores, schemaVersion = 1) {
93
83
  const storeNames = stores.map((s) => s.name);
94
- dbStoreNames = storeNames;
84
+ const idbVersion = schemaVersion * 100 + storeNames.length;
95
85
  if (dbInstance) {
96
86
  const allExist = storeNames.every(
97
87
  (n) => dbInstance.objectStoreNames.contains(resourceStoreName(n))
98
88
  );
99
- if (allExist) return;
100
- const nextVersion = dbInstance.version + 1;
89
+ if (allExist && dbInstance.version === idbVersion) return;
101
90
  dbInstance.close();
102
91
  dbInstance = null;
103
92
  dbOpenPromise = null;
104
- dbInstance = await openDB(storeNames, nextVersion);
105
- return;
106
93
  }
107
94
  if (!dbOpenPromise) {
108
- dbOpenPromise = openDB(storeNames).then((db) => {
95
+ dbOpenPromise = openDB(storeNames, idbVersion).then((db) => {
109
96
  dbInstance = db;
110
97
  dbOpenPromise = null;
111
98
  return db;
@@ -195,7 +182,7 @@ if (!_i18next2.default.isInitialized) {
195
182
  }
196
183
  });
197
184
  }
198
- var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } = _chunk2EV6FQILcjs.createI18nManager.call(void 0, {
185
+ var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } = _chunkT7476FJ4cjs.createI18nManager.call(void 0, {
199
186
  storage: new IndexedDBAdapter(),
200
187
  createWorker: () => new (0, _chunkAJJKJPNBcjs.WebWorkerAdapter)(
201
188
  new Worker(new URL("./workers/preload-worker.js", import.meta.url), { type: "module" })
@@ -211,4 +198,6 @@ var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } =
211
198
 
212
199
 
213
200
 
214
- exports.I18N_RESOURCES_UPDATED_EVENT = _chunk2EV6FQILcjs.I18N_RESOURCES_UPDATED_EVENT; exports.closeSSE = closeSSE; exports.emitI18nResourcesUpdated = _chunk2EV6FQILcjs.emitI18nResourcesUpdated; exports.ensureModules = ensureModules; exports.getAllRecordsByModule = getAllRecordsByModule; exports.getResource = getResource; exports.initI18n = initI18n; exports.useDict = _chunkAJJKJPNBcjs.useDict; exports.useTranslation = _chunkAJJKJPNBcjs.useTranslation;
201
+
202
+
203
+ exports.I18N_RESOURCES_UPDATED_EVENT = _chunkT7476FJ4cjs.I18N_RESOURCES_UPDATED_EVENT; exports.closeSSE = closeSSE; exports.deepMerge = _chunkT7476FJ4cjs.deepMerge; exports.emitI18nResourcesUpdated = _chunkT7476FJ4cjs.emitI18nResourcesUpdated; exports.ensureModules = ensureModules; exports.flatToNested = _chunkT7476FJ4cjs.flatToNested; exports.getAllRecordsByModule = getAllRecordsByModule; exports.getResource = getResource; exports.initI18n = initI18n; exports.useDict = _chunkAJJKJPNBcjs.useDict; exports.useTranslation = _chunkAJJKJPNBcjs.useTranslation;
package/dist/index.d.cts CHANGED
@@ -1,12 +1,22 @@
1
- import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from './cacheEvents-CSwgzbob.cjs';
2
- export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, W as WorkerLike, h as emitI18nResourcesUpdated } from './cacheEvents-CSwgzbob.cjs';
1
+ import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from './cacheEvents-DAFvp5or.cjs';
2
+ export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, W as WorkerLike, h as emitI18nResourcesUpdated } from './cacheEvents-DAFvp5or.cjs';
3
3
  export { u as useDict } from './hooks-ClO29Chr.cjs';
4
4
  export { useTranslation } from 'react-i18next';
5
5
 
6
+ /**
7
+ * dot-notation 平铺 key → 嵌套对象
8
+ * "a.b.c" → { a: { b: { c: value } } }
9
+ */
10
+ declare function flatToNested(flat: Record<string, unknown>): Record<string, unknown>;
11
+ /**
12
+ * 深度合并,source 叶节点覆盖 target,数组直接覆盖
13
+ */
14
+ declare function deepMerge(target: Record<string, unknown>, source: Record<string, unknown>): Record<string, unknown>;
15
+
6
16
  declare const initI18n: typeof initI18n$1;
7
17
  declare const closeSSE: typeof closeSSE$1;
8
18
  declare const ensureModules: typeof ensureModules$1;
9
19
  declare const getResource: typeof getResource$1;
10
20
  declare const getAllRecordsByModule: typeof getAllRecordsByModule$1;
11
21
 
12
- export { closeSSE, ensureModules, getAllRecordsByModule, getResource, initI18n };
22
+ export { closeSSE, deepMerge, ensureModules, flatToNested, getAllRecordsByModule, getResource, initI18n };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,22 @@
1
- import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from './cacheEvents-CSwgzbob.js';
2
- export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, W as WorkerLike, h as emitI18nResourcesUpdated } from './cacheEvents-CSwgzbob.js';
1
+ import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from './cacheEvents-DAFvp5or.js';
2
+ export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, W as WorkerLike, h as emitI18nResourcesUpdated } from './cacheEvents-DAFvp5or.js';
3
3
  export { u as useDict } from './hooks-ClO29Chr.js';
4
4
  export { useTranslation } from 'react-i18next';
5
5
 
6
+ /**
7
+ * dot-notation 平铺 key → 嵌套对象
8
+ * "a.b.c" → { a: { b: { c: value } } }
9
+ */
10
+ declare function flatToNested(flat: Record<string, unknown>): Record<string, unknown>;
11
+ /**
12
+ * 深度合并,source 叶节点覆盖 target,数组直接覆盖
13
+ */
14
+ declare function deepMerge(target: Record<string, unknown>, source: Record<string, unknown>): Record<string, unknown>;
15
+
6
16
  declare const initI18n: typeof initI18n$1;
7
17
  declare const closeSSE: typeof closeSSE$1;
8
18
  declare const ensureModules: typeof ensureModules$1;
9
19
  declare const getResource: typeof getResource$1;
10
20
  declare const getAllRecordsByModule: typeof getAllRecordsByModule$1;
11
21
 
12
- export { closeSSE, ensureModules, getAllRecordsByModule, getResource, initI18n };
22
+ export { closeSSE, deepMerge, ensureModules, flatToNested, getAllRecordsByModule, getResource, initI18n };
package/dist/index.js CHANGED
@@ -6,8 +6,10 @@ import {
6
6
  import {
7
7
  I18N_RESOURCES_UPDATED_EVENT,
8
8
  createI18nManager,
9
- emitI18nResourcesUpdated
10
- } from "./chunk-5VHZCG34.js";
9
+ deepMerge,
10
+ emitI18nResourcesUpdated,
11
+ flatToNested
12
+ } from "./chunk-LZQP6OHB.js";
11
13
 
12
14
  // src/index.ts
13
15
  import i18n from "i18next";
@@ -20,12 +22,10 @@ function resourceStoreName(name) {
20
22
  }
21
23
  var dbInstance = null;
22
24
  var dbOpenPromise = null;
23
- var dbStoreNames = [];
24
- function openDB(storeNames, version) {
25
+ function openDB(storeNames, idbVersion) {
25
26
  return new Promise((resolve, reject) => {
26
- const req = version !== void 0 ? indexedDB.open(DB_NAME, version) : indexedDB.open(DB_NAME);
27
- req.onupgradeneeded = (event) => {
28
- if (version === void 0) return;
27
+ const request = indexedDB.open(DB_NAME, idbVersion);
28
+ request.onupgradeneeded = (event) => {
29
29
  const db = event.target.result;
30
30
  for (const name of storeNames) {
31
31
  const storeName = resourceStoreName(name);
@@ -36,8 +36,8 @@ function openDB(storeNames, version) {
36
36
  }
37
37
  }
38
38
  };
39
- req.onsuccess = () => {
40
- const db = req.result;
39
+ request.onsuccess = () => {
40
+ const db = request.result;
41
41
  db.onversionchange = () => {
42
42
  db.close();
43
43
  dbInstance = null;
@@ -47,31 +47,15 @@ function openDB(storeNames, version) {
47
47
  dbInstance = null;
48
48
  dbOpenPromise = null;
49
49
  };
50
- const missing = storeNames.filter((n) => !db.objectStoreNames.contains(resourceStoreName(n)));
51
- if (missing.length === 0 || version !== void 0) {
52
- resolve(db);
53
- return;
54
- }
55
- const nextVersion = db.version + 1;
56
- db.close();
57
- openDB(storeNames, nextVersion).then(resolve).catch(reject);
50
+ resolve(db);
58
51
  };
59
- req.onerror = () => reject(req.error);
60
- req.onblocked = () => reject(new Error("[i18n] IndexedDB open blocked"));
52
+ request.onerror = () => reject(request.error);
53
+ request.onblocked = () => reject(new Error("[i18n] IndexedDB open blocked"));
61
54
  });
62
55
  }
63
56
  function getDB() {
64
57
  if (dbInstance) return Promise.resolve(dbInstance);
65
- if (!dbOpenPromise) {
66
- dbOpenPromise = openDB(dbStoreNames).then((db) => {
67
- dbInstance = db;
68
- dbOpenPromise = null;
69
- return db;
70
- }).catch((err) => {
71
- dbOpenPromise = null;
72
- throw err;
73
- });
74
- }
58
+ if (!dbOpenPromise) throw new Error("[i18n] ensureStores must be called before using the DB");
75
59
  return dbOpenPromise;
76
60
  }
77
61
  function idbRequest(req) {
@@ -89,23 +73,26 @@ async function withRetry(fn) {
89
73
  }
90
74
  }
91
75
  var IndexedDBAdapter = class {
92
- async ensureStores(stores) {
76
+ /**
77
+ * schemaVersion 来自外部传入的 options.version。
78
+ * IDB 版本 = schemaVersion * 100 + stores.length,保证:
79
+ * - options.version 变化 → IDB 版本变化 → onupgradeneeded → 触发 checkCacheVersion 的数据清理
80
+ * - store 数量变化(未登录→登录)→ IDB 版本变化 → onupgradeneeded → 新增 store
81
+ */
82
+ async ensureStores(stores, schemaVersion = 1) {
93
83
  const storeNames = stores.map((s) => s.name);
94
- dbStoreNames = storeNames;
84
+ const idbVersion = schemaVersion * 100 + storeNames.length;
95
85
  if (dbInstance) {
96
86
  const allExist = storeNames.every(
97
87
  (n) => dbInstance.objectStoreNames.contains(resourceStoreName(n))
98
88
  );
99
- if (allExist) return;
100
- const nextVersion = dbInstance.version + 1;
89
+ if (allExist && dbInstance.version === idbVersion) return;
101
90
  dbInstance.close();
102
91
  dbInstance = null;
103
92
  dbOpenPromise = null;
104
- dbInstance = await openDB(storeNames, nextVersion);
105
- return;
106
93
  }
107
94
  if (!dbOpenPromise) {
108
- dbOpenPromise = openDB(storeNames).then((db) => {
95
+ dbOpenPromise = openDB(storeNames, idbVersion).then((db) => {
109
96
  dbInstance = db;
110
97
  dbOpenPromise = null;
111
98
  return db;
@@ -204,8 +191,10 @@ var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } =
204
191
  export {
205
192
  I18N_RESOURCES_UPDATED_EVENT,
206
193
  closeSSE,
194
+ deepMerge,
207
195
  emitI18nResourcesUpdated,
208
196
  ensureModules,
197
+ flatToNested,
209
198
  getAllRecordsByModule,
210
199
  getResource,
211
200
  initI18n,
package/dist/mp/index.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunk2EV6FQILcjs = require('../chunk-2EV6FQIL.cjs');
5
+ var _chunkT7476FJ4cjs = require('../chunk-T7476FJ4.cjs');
6
6
 
7
7
  // src/storage/wx-sqlite.ts
8
8
  var DB_NAME = "i18n_cache";
@@ -39,7 +39,7 @@ function exec(db, sql, args = []) {
39
39
  });
40
40
  }
41
41
  var WxSQLiteAdapter = class {
42
- async ensureStores(stores) {
42
+ async ensureStores(stores, _schemaVersion) {
43
43
  const db = await getDB();
44
44
  for (const store of stores) {
45
45
  const table = resourceTable(store.name);
@@ -181,7 +181,7 @@ function wxFetch(input, init) {
181
181
  }
182
182
 
183
183
  // src/mp/index.ts
184
- var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } = _chunk2EV6FQILcjs.createI18nManager.call(void 0, {
184
+ var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } = _chunkT7476FJ4cjs.createI18nManager.call(void 0, {
185
185
  storage: new WxSQLiteAdapter(),
186
186
  createWorker: () => new WxWorkerAdapter(wx.createWorker("workers/preload-worker-mp.js")),
187
187
  fetchFn: wxFetch
@@ -194,4 +194,4 @@ var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } =
194
194
 
195
195
 
196
196
 
197
- exports.I18N_RESOURCES_UPDATED_EVENT = _chunk2EV6FQILcjs.I18N_RESOURCES_UPDATED_EVENT; exports.closeSSE = closeSSE; exports.emitI18nResourcesUpdated = _chunk2EV6FQILcjs.emitI18nResourcesUpdated; exports.ensureModules = ensureModules; exports.getAllRecordsByModule = getAllRecordsByModule; exports.getResource = getResource; exports.initI18n = initI18n;
197
+ exports.I18N_RESOURCES_UPDATED_EVENT = _chunkT7476FJ4cjs.I18N_RESOURCES_UPDATED_EVENT; exports.closeSSE = closeSSE; exports.emitI18nResourcesUpdated = _chunkT7476FJ4cjs.emitI18nResourcesUpdated; exports.ensureModules = ensureModules; exports.getAllRecordsByModule = getAllRecordsByModule; exports.getResource = getResource; exports.initI18n = initI18n;
@@ -1,5 +1,5 @@
1
- import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-CSwgzbob.cjs';
2
- export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, h as emitI18nResourcesUpdated } from '../cacheEvents-CSwgzbob.cjs';
1
+ import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-DAFvp5or.cjs';
2
+ export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, h as emitI18nResourcesUpdated } from '../cacheEvents-DAFvp5or.cjs';
3
3
 
4
4
  declare const initI18n: typeof initI18n$1;
5
5
  declare const closeSSE: typeof closeSSE$1;
@@ -1,5 +1,5 @@
1
- import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-CSwgzbob.js';
2
- export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, h as emitI18nResourcesUpdated } from '../cacheEvents-CSwgzbob.js';
1
+ import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-DAFvp5or.js';
2
+ export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, h as emitI18nResourcesUpdated } from '../cacheEvents-DAFvp5or.js';
3
3
 
4
4
  declare const initI18n: typeof initI18n$1;
5
5
  declare const closeSSE: typeof closeSSE$1;
package/dist/mp/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  I18N_RESOURCES_UPDATED_EVENT,
3
3
  createI18nManager,
4
4
  emitI18nResourcesUpdated
5
- } from "../chunk-5VHZCG34.js";
5
+ } from "../chunk-LZQP6OHB.js";
6
6
 
7
7
  // src/storage/wx-sqlite.ts
8
8
  var DB_NAME = "i18n_cache";
@@ -39,7 +39,7 @@ function exec(db, sql, args = []) {
39
39
  });
40
40
  }
41
41
  var WxSQLiteAdapter = class {
42
- async ensureStores(stores) {
42
+ async ensureStores(stores, _schemaVersion) {
43
43
  const db = await getDB();
44
44
  for (const store of stores) {
45
45
  const table = resourceTable(store.name);
@@ -7,7 +7,7 @@ var _chunkAJJKJPNBcjs = require('../chunk-AJJKJPNB.cjs');
7
7
 
8
8
 
9
9
 
10
- var _chunk2EV6FQILcjs = require('../chunk-2EV6FQIL.cjs');
10
+ var _chunkT7476FJ4cjs = require('../chunk-T7476FJ4.cjs');
11
11
 
12
12
  // src/native/index.ts
13
13
  var _i18next = require('i18next'); var _i18next2 = _interopRequireDefault(_i18next);
@@ -30,7 +30,7 @@ async function execute(sql, params = []) {
30
30
  return db.executeAsync(sql, params);
31
31
  }
32
32
  var SQLiteAdapter = class {
33
- async ensureStores(stores) {
33
+ async ensureStores(stores, _schemaVersion) {
34
34
  for (const store of stores) {
35
35
  const table = resourceTable(store.name);
36
36
  await execute(`
@@ -121,7 +121,7 @@ if (!_i18next2.default.isInitialized) {
121
121
  }
122
122
  });
123
123
  }
124
- var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } = _chunk2EV6FQILcjs.createI18nManager.call(void 0, {
124
+ var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } = _chunkT7476FJ4cjs.createI18nManager.call(void 0, {
125
125
  storage: new SQLiteAdapter(),
126
126
  // Hermes Worker(RN 0.71+),API 与 Web Worker 一致
127
127
  createWorker: () => new (0, _chunkAJJKJPNBcjs.WebWorkerAdapter)(
@@ -138,4 +138,4 @@ var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } =
138
138
 
139
139
 
140
140
 
141
- exports.I18N_RESOURCES_UPDATED_EVENT = _chunk2EV6FQILcjs.I18N_RESOURCES_UPDATED_EVENT; exports.closeSSE = closeSSE; exports.emitI18nResourcesUpdated = _chunk2EV6FQILcjs.emitI18nResourcesUpdated; exports.ensureModules = ensureModules; exports.getAllRecordsByModule = getAllRecordsByModule; exports.getResource = getResource; exports.initI18n = initI18n; exports.useDict = _chunkAJJKJPNBcjs.useDict; exports.useTranslation = _chunkAJJKJPNBcjs.useTranslation;
141
+ exports.I18N_RESOURCES_UPDATED_EVENT = _chunkT7476FJ4cjs.I18N_RESOURCES_UPDATED_EVENT; exports.closeSSE = closeSSE; exports.emitI18nResourcesUpdated = _chunkT7476FJ4cjs.emitI18nResourcesUpdated; exports.ensureModules = ensureModules; exports.getAllRecordsByModule = getAllRecordsByModule; exports.getResource = getResource; exports.initI18n = initI18n; exports.useDict = _chunkAJJKJPNBcjs.useDict; exports.useTranslation = _chunkAJJKJPNBcjs.useTranslation;
@@ -1,5 +1,5 @@
1
- import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-CSwgzbob.cjs';
2
- export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, h as emitI18nResourcesUpdated } from '../cacheEvents-CSwgzbob.cjs';
1
+ import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-DAFvp5or.cjs';
2
+ export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, h as emitI18nResourcesUpdated } from '../cacheEvents-DAFvp5or.cjs';
3
3
  export { u as useDict } from '../hooks-ClO29Chr.cjs';
4
4
  export { useTranslation } from 'react-i18next';
5
5
 
@@ -1,5 +1,5 @@
1
- import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-CSwgzbob.js';
2
- export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, h as emitI18nResourcesUpdated } from '../cacheEvents-CSwgzbob.js';
1
+ import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-DAFvp5or.js';
2
+ export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, h as emitI18nResourcesUpdated } from '../cacheEvents-DAFvp5or.js';
3
3
  export { u as useDict } from '../hooks-ClO29Chr.js';
4
4
  export { useTranslation } from 'react-i18next';
5
5
 
@@ -7,7 +7,7 @@ import {
7
7
  I18N_RESOURCES_UPDATED_EVENT,
8
8
  createI18nManager,
9
9
  emitI18nResourcesUpdated
10
- } from "../chunk-5VHZCG34.js";
10
+ } from "../chunk-LZQP6OHB.js";
11
11
 
12
12
  // src/native/index.ts
13
13
  import i18n from "i18next";
@@ -30,7 +30,7 @@ async function execute(sql, params = []) {
30
30
  return db.executeAsync(sql, params);
31
31
  }
32
32
  var SQLiteAdapter = class {
33
- async ensureStores(stores) {
33
+ async ensureStores(stores, _schemaVersion) {
34
34
  for (const store of stores) {
35
35
  const table = resourceTable(store.name);
36
36
  await execute(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuo-li/i18n",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "description": "Cross-platform i18n library for Web, React Native and WeChat MiniProgram",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",