@shuo-li/i18n 1.0.3 → 1.0.4
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/{cacheEvents-CDBRPnHU.d.cts → cacheEvents-5-eLxrSg.d.cts} +2 -2
- package/dist/{cacheEvents-CDBRPnHU.d.ts → cacheEvents-5-eLxrSg.d.ts} +2 -2
- package/dist/{chunk-K5VX3COH.cjs → chunk-MQYSUEEW.cjs} +48 -34
- package/dist/{chunk-IWP4252C.js → chunk-USTXU3BM.js} +41 -27
- package/dist/index.cjs +7 -45
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -42
- package/dist/mp/index.cjs +9 -43
- package/dist/mp/index.d.cts +2 -2
- package/dist/mp/index.d.ts +2 -2
- package/dist/mp/index.js +7 -41
- package/dist/native/index.cjs +10 -44
- package/dist/native/index.d.cts +2 -2
- package/dist/native/index.d.ts +2 -2
- package/dist/native/index.js +7 -41
- package/package.json +1 -1
|
@@ -23,7 +23,7 @@ interface SSEConfig {
|
|
|
23
23
|
transformMessage?: (raw: unknown) => SSEMessage;
|
|
24
24
|
}
|
|
25
25
|
interface I18nInitOptions {
|
|
26
|
-
|
|
26
|
+
langCode: string;
|
|
27
27
|
version?: number | string;
|
|
28
28
|
languages?: string[];
|
|
29
29
|
modules?: string[];
|
|
@@ -32,7 +32,7 @@ interface I18nInitOptions {
|
|
|
32
32
|
apiContext: {
|
|
33
33
|
baseURL: string;
|
|
34
34
|
getHeaders: () => Record<string, string>;
|
|
35
|
-
isLoggedIn:
|
|
35
|
+
isLoggedIn: boolean;
|
|
36
36
|
unloginPull?: UnloginPullConfig;
|
|
37
37
|
pull?: PullConfig;
|
|
38
38
|
sseSync?: SSESyncConfig;
|
|
@@ -23,7 +23,7 @@ interface SSEConfig {
|
|
|
23
23
|
transformMessage?: (raw: unknown) => SSEMessage;
|
|
24
24
|
}
|
|
25
25
|
interface I18nInitOptions {
|
|
26
|
-
|
|
26
|
+
langCode: string;
|
|
27
27
|
version?: number | string;
|
|
28
28
|
languages?: string[];
|
|
29
29
|
modules?: string[];
|
|
@@ -32,7 +32,7 @@ interface I18nInitOptions {
|
|
|
32
32
|
apiContext: {
|
|
33
33
|
baseURL: string;
|
|
34
34
|
getHeaders: () => Record<string, string>;
|
|
35
|
-
isLoggedIn:
|
|
35
|
+
isLoggedIn: boolean;
|
|
36
36
|
unloginPull?: UnloginPullConfig;
|
|
37
37
|
pull?: PullConfig;
|
|
38
38
|
sseSync?: SSESyncConfig;
|
|
@@ -301,7 +301,7 @@ async function initI18n(options) {
|
|
|
301
301
|
currentSig = sig;
|
|
302
302
|
initOptions = options;
|
|
303
303
|
const p = _initI18n(options).then(() => {
|
|
304
|
-
if (!options.apiContext.isLoggedIn
|
|
304
|
+
if (!options.apiContext.isLoggedIn) {
|
|
305
305
|
currentPromise = null;
|
|
306
306
|
}
|
|
307
307
|
}).catch((err) => {
|
|
@@ -362,11 +362,11 @@ async function getAllRecordsByModule(moduleCode) {
|
|
|
362
362
|
async function _initI18n(options) {
|
|
363
363
|
const { storage } = managerOptions;
|
|
364
364
|
const { apiContext } = options;
|
|
365
|
-
currentLang = options.
|
|
365
|
+
currentLang = options.langCode;
|
|
366
366
|
resolvedStores = options.stores;
|
|
367
|
-
resolvedLanguages = _nullishCoalesce(options.languages, () => ( [options.
|
|
367
|
+
resolvedLanguages = _nullishCoalesce(options.languages, () => ( [options.langCode]));
|
|
368
368
|
resolvedModules = _nullishCoalesce(options.modules, () => ( []));
|
|
369
|
-
await storage.
|
|
369
|
+
await storage.ensureStores(resolvedStores);
|
|
370
370
|
await checkCacheVersion(storage, options);
|
|
371
371
|
for (const lang of resolvedLanguages) {
|
|
372
372
|
for (const m of resolvedModules) {
|
|
@@ -375,7 +375,7 @@ async function _initI18n(options) {
|
|
|
375
375
|
}
|
|
376
376
|
await injectCurrentLanguageModules(currentLang);
|
|
377
377
|
await _i18next2.default.changeLanguage(currentLang);
|
|
378
|
-
if (!apiContext.isLoggedIn
|
|
378
|
+
if (!apiContext.isLoggedIn) {
|
|
379
379
|
if (!unloginPullStarted && apiContext.unloginPull) {
|
|
380
380
|
unloginPullStarted = true;
|
|
381
381
|
await doUnloginPull(storage, options);
|
|
@@ -394,41 +394,55 @@ async function _initI18n(options) {
|
|
|
394
394
|
startSSE(options);
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
|
+
var CACHE_VERSION_KEY = "__meta__:cache_version";
|
|
397
398
|
async function checkCacheVersion(storage, options) {
|
|
398
399
|
if (options.version == null) return;
|
|
400
|
+
const baseStoreName = resolvedStores[0].name;
|
|
399
401
|
const current = String(options.version);
|
|
400
|
-
const
|
|
402
|
+
const record = await storage.getRecord(baseStoreName, CACHE_VERSION_KEY).catch(() => void 0);
|
|
403
|
+
const stored = _optionalChain([record, 'optionalAccess', _21 => _21.resources, 'optionalAccess', _22 => _22["value"]]);
|
|
401
404
|
if (stored === current) return;
|
|
402
405
|
for (const store of options.stores) {
|
|
403
406
|
await storage.clearStore(store.name);
|
|
404
407
|
}
|
|
405
|
-
await storage.
|
|
408
|
+
await storage.putRecord(baseStoreName, {
|
|
409
|
+
key: CACHE_VERSION_KEY,
|
|
410
|
+
moduleCode: "__meta__",
|
|
411
|
+
langCode: "__meta__",
|
|
412
|
+
version: 0,
|
|
413
|
+
resources: { value: current }
|
|
414
|
+
});
|
|
406
415
|
}
|
|
407
416
|
async function doUnloginPull(storage, options) {
|
|
408
417
|
const { apiContext } = options;
|
|
409
418
|
if (!apiContext.unloginPull) return;
|
|
410
419
|
const baseStore = resolvedStores[0];
|
|
420
|
+
let blocks;
|
|
411
421
|
try {
|
|
412
|
-
|
|
413
|
-
for (const block of blocks) {
|
|
414
|
-
for (const mod of _nullishCoalesce(block.modules, () => ( []))) {
|
|
415
|
-
const key = buildKey(mod.moduleCode, block.langCode, baseStore);
|
|
416
|
-
const existing = await storage.getRecord(baseStore.name, key);
|
|
417
|
-
const parsed = parseI18nValues(_nullishCoalesce(mod.i18nValues, () => ( [])));
|
|
418
|
-
const resources = deepMerge(
|
|
419
|
-
_nullishCoalesce(_optionalChain([existing, 'optionalAccess', _21 => _21.resources]), () => ( {})),
|
|
420
|
-
flatToNested(parsed)
|
|
421
|
-
);
|
|
422
|
-
await storage.putRecord(baseStore.name, {
|
|
423
|
-
key,
|
|
424
|
-
moduleCode: mod.moduleCode,
|
|
425
|
-
langCode: block.langCode,
|
|
426
|
-
version: _nullishCoalesce(mod.version, () => ( 0)),
|
|
427
|
-
resources
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
}
|
|
422
|
+
blocks = await doFetch(apiContext.unloginPull, options);
|
|
431
423
|
} catch (e4) {
|
|
424
|
+
await injectCurrentLanguageModules(currentLang);
|
|
425
|
+
await _i18next2.default.changeLanguage(currentLang);
|
|
426
|
+
emitI18nResourcesUpdated();
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
for (const block of blocks) {
|
|
430
|
+
for (const mod of _nullishCoalesce(block.modules, () => ( []))) {
|
|
431
|
+
const key = buildKey(mod.moduleCode, block.langCode, baseStore);
|
|
432
|
+
const existing = await storage.getRecord(baseStore.name, key);
|
|
433
|
+
const parsed = parseI18nValues(_nullishCoalesce(mod.i18nValues, () => ( [])));
|
|
434
|
+
const resources = deepMerge(
|
|
435
|
+
_nullishCoalesce(_optionalChain([existing, 'optionalAccess', _23 => _23.resources]), () => ( {})),
|
|
436
|
+
flatToNested(parsed)
|
|
437
|
+
);
|
|
438
|
+
await storage.putRecord(baseStore.name, {
|
|
439
|
+
key,
|
|
440
|
+
moduleCode: mod.moduleCode,
|
|
441
|
+
langCode: block.langCode,
|
|
442
|
+
version: _nullishCoalesce(mod.version, () => ( 0)),
|
|
443
|
+
resources
|
|
444
|
+
});
|
|
445
|
+
}
|
|
432
446
|
}
|
|
433
447
|
await injectCurrentLanguageModules(currentLang);
|
|
434
448
|
await _i18next2.default.changeLanguage(currentLang);
|
|
@@ -493,7 +507,7 @@ async function injectFromDB(moduleCode, langCode) {
|
|
|
493
507
|
const store = resolvedStores[i];
|
|
494
508
|
const key = buildKey(moduleCode, langCode, store);
|
|
495
509
|
const record = await storage.getRecord(store.name, key);
|
|
496
|
-
if (!_optionalChain([record, 'optionalAccess',
|
|
510
|
+
if (!_optionalChain([record, 'optionalAccess', _24 => _24.resources])) continue;
|
|
497
511
|
if (i === 0) {
|
|
498
512
|
_i18next2.default.addResourceBundle(langCode, moduleCode, record.resources, true, true);
|
|
499
513
|
} else {
|
|
@@ -515,7 +529,7 @@ function startSSE(options) {
|
|
|
515
529
|
if (!apiContext.sse) return;
|
|
516
530
|
sseClient.start(
|
|
517
531
|
(raw) => {
|
|
518
|
-
const msg = _optionalChain([apiContext, 'access',
|
|
532
|
+
const msg = _optionalChain([apiContext, 'access', _25 => _25.sse, 'optionalAccess', _26 => _26.transformMessage]) ? apiContext.sse.transformMessage(raw) : raw;
|
|
519
533
|
void handleSSEMessage(msg, options);
|
|
520
534
|
},
|
|
521
535
|
{
|
|
@@ -600,16 +614,16 @@ async function pullAndStore(task, fromVersion, options) {
|
|
|
600
614
|
const storeIndex = resolvedStores.indexOf(store);
|
|
601
615
|
const key = buildKey(mod.moduleCode, block.langCode, store);
|
|
602
616
|
const existing = await storage.getRecord(store.name, key);
|
|
603
|
-
if (mod.version <= (_nullishCoalesce(_optionalChain([existing, 'optionalAccess',
|
|
617
|
+
if (mod.version <= (_nullishCoalesce(_optionalChain([existing, 'optionalAccess', _27 => _27.version]), () => ( 0)))) continue;
|
|
604
618
|
let resources;
|
|
605
619
|
const parsed = parseI18nValues(_nullishCoalesce(mod.i18nValues, () => ( [])));
|
|
606
620
|
if (storeIndex === 0) {
|
|
607
621
|
resources = deepMerge(
|
|
608
|
-
_nullishCoalesce(_optionalChain([existing, 'optionalAccess',
|
|
622
|
+
_nullishCoalesce(_optionalChain([existing, 'optionalAccess', _28 => _28.resources]), () => ( {})),
|
|
609
623
|
flatToNested(parsed)
|
|
610
624
|
);
|
|
611
625
|
} else {
|
|
612
|
-
resources = { ..._nullishCoalesce(_optionalChain([existing, 'optionalAccess',
|
|
626
|
+
resources = { ..._nullishCoalesce(_optionalChain([existing, 'optionalAccess', _29 => _29.resources]), () => ( {})), ...parsed };
|
|
613
627
|
}
|
|
614
628
|
const version = Math.max(mod.version, task.targetVersion);
|
|
615
629
|
await storage.putRecord(store.name, {
|
|
@@ -645,7 +659,7 @@ async function doFetch(config, options, internalParams) {
|
|
|
645
659
|
}
|
|
646
660
|
function buildSig(options) {
|
|
647
661
|
const cgKeys = options.stores.map((s) => _nullishCoalesce(s.cacheGroupKey, () => ( ""))).join(",");
|
|
648
|
-
return [options.apiContext.baseURL, options.
|
|
662
|
+
return [options.apiContext.baseURL, options.langCode, cgKeys].join("|");
|
|
649
663
|
}
|
|
650
664
|
function sortedModules() {
|
|
651
665
|
const priority = PRIORITY_MODULES.filter((m) => resolvedModules.includes(m));
|
|
@@ -653,13 +667,13 @@ function sortedModules() {
|
|
|
653
667
|
return [...priority, ...rest];
|
|
654
668
|
}
|
|
655
669
|
function getStaticLocale(moduleCode, langCode) {
|
|
656
|
-
return _nullishCoalesce(_optionalChain([initOptions, 'optionalAccess',
|
|
670
|
+
return _nullishCoalesce(_optionalChain([initOptions, 'optionalAccess', _30 => _30.staticLocales, 'optionalAccess', _31 => _31[langCode], 'optionalAccess', _32 => _32[moduleCode]]), () => ( {}));
|
|
657
671
|
}
|
|
658
672
|
async function getStoredVersion(store, moduleCode, langCode) {
|
|
659
673
|
const storage = managerOptions.storage;
|
|
660
674
|
const key = buildKey(moduleCode, langCode, store);
|
|
661
675
|
const record = await storage.getRecord(store.name, key);
|
|
662
|
-
return _nullishCoalesce(_optionalChain([record, 'optionalAccess',
|
|
676
|
+
return _nullishCoalesce(_optionalChain([record, 'optionalAccess', _33 => _33.version]), () => ( 0));
|
|
663
677
|
}
|
|
664
678
|
|
|
665
679
|
|
|
@@ -301,7 +301,7 @@ async function initI18n(options) {
|
|
|
301
301
|
currentSig = sig;
|
|
302
302
|
initOptions = options;
|
|
303
303
|
const p = _initI18n(options).then(() => {
|
|
304
|
-
if (!options.apiContext.isLoggedIn
|
|
304
|
+
if (!options.apiContext.isLoggedIn) {
|
|
305
305
|
currentPromise = null;
|
|
306
306
|
}
|
|
307
307
|
}).catch((err) => {
|
|
@@ -362,11 +362,11 @@ async function getAllRecordsByModule(moduleCode) {
|
|
|
362
362
|
async function _initI18n(options) {
|
|
363
363
|
const { storage } = managerOptions;
|
|
364
364
|
const { apiContext } = options;
|
|
365
|
-
currentLang = options.
|
|
365
|
+
currentLang = options.langCode;
|
|
366
366
|
resolvedStores = options.stores;
|
|
367
|
-
resolvedLanguages = options.languages ?? [options.
|
|
367
|
+
resolvedLanguages = options.languages ?? [options.langCode];
|
|
368
368
|
resolvedModules = options.modules ?? [];
|
|
369
|
-
await storage.
|
|
369
|
+
await storage.ensureStores(resolvedStores);
|
|
370
370
|
await checkCacheVersion(storage, options);
|
|
371
371
|
for (const lang of resolvedLanguages) {
|
|
372
372
|
for (const m of resolvedModules) {
|
|
@@ -375,7 +375,7 @@ async function _initI18n(options) {
|
|
|
375
375
|
}
|
|
376
376
|
await injectCurrentLanguageModules(currentLang);
|
|
377
377
|
await i18n.changeLanguage(currentLang);
|
|
378
|
-
if (!apiContext.isLoggedIn
|
|
378
|
+
if (!apiContext.isLoggedIn) {
|
|
379
379
|
if (!unloginPullStarted && apiContext.unloginPull) {
|
|
380
380
|
unloginPullStarted = true;
|
|
381
381
|
await doUnloginPull(storage, options);
|
|
@@ -394,41 +394,55 @@ async function _initI18n(options) {
|
|
|
394
394
|
startSSE(options);
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
|
+
var CACHE_VERSION_KEY = "__meta__:cache_version";
|
|
397
398
|
async function checkCacheVersion(storage, options) {
|
|
398
399
|
if (options.version == null) return;
|
|
400
|
+
const baseStoreName = resolvedStores[0].name;
|
|
399
401
|
const current = String(options.version);
|
|
400
|
-
const
|
|
402
|
+
const record = await storage.getRecord(baseStoreName, CACHE_VERSION_KEY).catch(() => void 0);
|
|
403
|
+
const stored = record?.resources?.["value"];
|
|
401
404
|
if (stored === current) return;
|
|
402
405
|
for (const store of options.stores) {
|
|
403
406
|
await storage.clearStore(store.name);
|
|
404
407
|
}
|
|
405
|
-
await storage.
|
|
408
|
+
await storage.putRecord(baseStoreName, {
|
|
409
|
+
key: CACHE_VERSION_KEY,
|
|
410
|
+
moduleCode: "__meta__",
|
|
411
|
+
langCode: "__meta__",
|
|
412
|
+
version: 0,
|
|
413
|
+
resources: { value: current }
|
|
414
|
+
});
|
|
406
415
|
}
|
|
407
416
|
async function doUnloginPull(storage, options) {
|
|
408
417
|
const { apiContext } = options;
|
|
409
418
|
if (!apiContext.unloginPull) return;
|
|
410
419
|
const baseStore = resolvedStores[0];
|
|
420
|
+
let blocks;
|
|
411
421
|
try {
|
|
412
|
-
|
|
413
|
-
for (const block of blocks) {
|
|
414
|
-
for (const mod of block.modules ?? []) {
|
|
415
|
-
const key = buildKey(mod.moduleCode, block.langCode, baseStore);
|
|
416
|
-
const existing = await storage.getRecord(baseStore.name, key);
|
|
417
|
-
const parsed = parseI18nValues(mod.i18nValues ?? []);
|
|
418
|
-
const resources = deepMerge(
|
|
419
|
-
existing?.resources ?? {},
|
|
420
|
-
flatToNested(parsed)
|
|
421
|
-
);
|
|
422
|
-
await storage.putRecord(baseStore.name, {
|
|
423
|
-
key,
|
|
424
|
-
moduleCode: mod.moduleCode,
|
|
425
|
-
langCode: block.langCode,
|
|
426
|
-
version: mod.version ?? 0,
|
|
427
|
-
resources
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
}
|
|
422
|
+
blocks = await doFetch(apiContext.unloginPull, options);
|
|
431
423
|
} catch {
|
|
424
|
+
await injectCurrentLanguageModules(currentLang);
|
|
425
|
+
await i18n.changeLanguage(currentLang);
|
|
426
|
+
emitI18nResourcesUpdated();
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
for (const block of blocks) {
|
|
430
|
+
for (const mod of block.modules ?? []) {
|
|
431
|
+
const key = buildKey(mod.moduleCode, block.langCode, baseStore);
|
|
432
|
+
const existing = await storage.getRecord(baseStore.name, key);
|
|
433
|
+
const parsed = parseI18nValues(mod.i18nValues ?? []);
|
|
434
|
+
const resources = deepMerge(
|
|
435
|
+
existing?.resources ?? {},
|
|
436
|
+
flatToNested(parsed)
|
|
437
|
+
);
|
|
438
|
+
await storage.putRecord(baseStore.name, {
|
|
439
|
+
key,
|
|
440
|
+
moduleCode: mod.moduleCode,
|
|
441
|
+
langCode: block.langCode,
|
|
442
|
+
version: mod.version ?? 0,
|
|
443
|
+
resources
|
|
444
|
+
});
|
|
445
|
+
}
|
|
432
446
|
}
|
|
433
447
|
await injectCurrentLanguageModules(currentLang);
|
|
434
448
|
await i18n.changeLanguage(currentLang);
|
|
@@ -645,7 +659,7 @@ async function doFetch(config, options, internalParams) {
|
|
|
645
659
|
}
|
|
646
660
|
function buildSig(options) {
|
|
647
661
|
const cgKeys = options.stores.map((s) => s.cacheGroupKey ?? "").join(",");
|
|
648
|
-
return [options.apiContext.baseURL, options.
|
|
662
|
+
return [options.apiContext.baseURL, options.langCode, cgKeys].join("|");
|
|
649
663
|
}
|
|
650
664
|
function sortedModules() {
|
|
651
665
|
const priority = PRIORITY_MODULES.filter((m) => resolvedModules.includes(m));
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
@@ -7,7 +7,7 @@ var _chunkAJJKJPNBcjs = require('./chunk-AJJKJPNB.cjs');
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkMQYSUEEWcjs = require('./chunk-MQYSUEEW.cjs');
|
|
11
11
|
|
|
12
12
|
// src/index.ts
|
|
13
13
|
var _i18next = require('i18next'); var _i18next2 = _interopRequireDefault(_i18next);
|
|
@@ -16,7 +16,6 @@ var _reacti18next = require('react-i18next');
|
|
|
16
16
|
// src/storage/indexeddb.ts
|
|
17
17
|
var DB_NAME = "i18n_cache";
|
|
18
18
|
var SCHEMA_VERSION = 2;
|
|
19
|
-
var META_STORE = "i18n_meta";
|
|
20
19
|
function resourceStoreName(name) {
|
|
21
20
|
return `i18n_resources_${name}`;
|
|
22
21
|
}
|
|
@@ -36,9 +35,6 @@ function openDB(storeNames) {
|
|
|
36
35
|
s.createIndex("by_language", "langCode");
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
|
-
if (!db.objectStoreNames.contains(META_STORE)) {
|
|
40
|
-
db.createObjectStore(META_STORE, { keyPath: "key" });
|
|
41
|
-
}
|
|
42
38
|
};
|
|
43
39
|
request.onsuccess = () => {
|
|
44
40
|
const db = request.result;
|
|
@@ -86,26 +82,9 @@ async function withRetry(fn) {
|
|
|
86
82
|
}
|
|
87
83
|
}
|
|
88
84
|
var IndexedDBAdapter = class {
|
|
89
|
-
async
|
|
85
|
+
async ensureStores(stores) {
|
|
90
86
|
dbStoreNames = stores.map((s) => s.name);
|
|
91
|
-
|
|
92
|
-
const stored = await this.getMeta("schema_version");
|
|
93
|
-
const storedVersion = Number(_nullishCoalesce(stored, () => ( 0)));
|
|
94
|
-
if (storedVersion === 0) {
|
|
95
|
-
await this.setMeta("schema_version", String(SCHEMA_VERSION));
|
|
96
|
-
} else if (storedVersion < SCHEMA_VERSION) {
|
|
97
|
-
db.close();
|
|
98
|
-
dbInstance = null;
|
|
99
|
-
await new Promise((resolve, reject) => {
|
|
100
|
-
const req = indexedDB.deleteDatabase(DB_NAME);
|
|
101
|
-
req.onsuccess = () => resolve();
|
|
102
|
-
req.onerror = () => reject(req.error);
|
|
103
|
-
});
|
|
104
|
-
dbInstance = await openDB(dbStoreNames);
|
|
105
|
-
await this.setMeta("schema_version", String(SCHEMA_VERSION));
|
|
106
|
-
} else if (storedVersion > SCHEMA_VERSION) {
|
|
107
|
-
throw new Error(`[i18n] DB schema version ${storedVersion} > current ${SCHEMA_VERSION}`);
|
|
108
|
-
}
|
|
87
|
+
await getDB(dbStoreNames);
|
|
109
88
|
}
|
|
110
89
|
async getRecord(storeName, key) {
|
|
111
90
|
return withRetry(async () => {
|
|
@@ -138,23 +117,6 @@ var IndexedDBAdapter = class {
|
|
|
138
117
|
await idbRequest(tx.objectStore(resourceStoreName(storeName)).clear());
|
|
139
118
|
});
|
|
140
119
|
}
|
|
141
|
-
async getMeta(key) {
|
|
142
|
-
return withRetry(async () => {
|
|
143
|
-
const db = await getDB();
|
|
144
|
-
const tx = db.transaction(META_STORE, "readonly");
|
|
145
|
-
const result = await idbRequest(
|
|
146
|
-
tx.objectStore(META_STORE).get(key)
|
|
147
|
-
);
|
|
148
|
-
return _nullishCoalesce(_optionalChain([result, 'optionalAccess', _ => _.value]), () => ( null));
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
async setMeta(key, value) {
|
|
152
|
-
await withRetry(async () => {
|
|
153
|
-
const db = await getDB();
|
|
154
|
-
const tx = db.transaction(META_STORE, "readwrite");
|
|
155
|
-
await idbRequest(tx.objectStore(META_STORE).put({ key, value }));
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
120
|
async hasLoginResources(stores) {
|
|
159
121
|
return withRetry(async () => {
|
|
160
122
|
const db = await getDB();
|
|
@@ -171,7 +133,7 @@ var IndexedDBAdapter = class {
|
|
|
171
133
|
return;
|
|
172
134
|
}
|
|
173
135
|
const record = cursor.value;
|
|
174
|
-
if (!record.key.startsWith("UNLOGIN_")) {
|
|
136
|
+
if (!record.key.startsWith("UNLOGIN_") && !record.key.startsWith("__meta__:")) {
|
|
175
137
|
resolve(true);
|
|
176
138
|
return;
|
|
177
139
|
}
|
|
@@ -203,7 +165,7 @@ if (!_i18next2.default.isInitialized) {
|
|
|
203
165
|
}
|
|
204
166
|
});
|
|
205
167
|
}
|
|
206
|
-
var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } =
|
|
168
|
+
var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } = _chunkMQYSUEEWcjs.createI18nManager.call(void 0, {
|
|
207
169
|
storage: new IndexedDBAdapter(),
|
|
208
170
|
workerWritesDB: true,
|
|
209
171
|
createWorker: () => new (0, _chunkAJJKJPNBcjs.WebWorkerAdapter)(
|
|
@@ -220,4 +182,4 @@ var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } =
|
|
|
220
182
|
|
|
221
183
|
|
|
222
184
|
|
|
223
|
-
exports.I18N_RESOURCES_UPDATED_EVENT =
|
|
185
|
+
exports.I18N_RESOURCES_UPDATED_EVENT = _chunkMQYSUEEWcjs.I18N_RESOURCES_UPDATED_EVENT; exports.closeSSE = closeSSE; exports.emitI18nResourcesUpdated = _chunkMQYSUEEWcjs.emitI18nResourcesUpdated; exports.ensureModules = ensureModules; exports.getAllRecordsByModule = getAllRecordsByModule; exports.getResource = getResource; exports.initI18n = initI18n; exports.useDict = _chunkAJJKJPNBcjs.useDict; exports.useTranslation = _chunkAJJKJPNBcjs.useTranslation;
|
package/dist/index.d.cts
CHANGED
|
@@ -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-
|
|
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-
|
|
1
|
+
import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from './cacheEvents-5-eLxrSg.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-5-eLxrSg.cjs';
|
|
3
3
|
export { u as useDict } from './hooks-ClO29Chr.cjs';
|
|
4
4
|
export { useTranslation } from 'react-i18next';
|
|
5
5
|
|
package/dist/index.d.ts
CHANGED
|
@@ -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-
|
|
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-
|
|
1
|
+
import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from './cacheEvents-5-eLxrSg.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-5-eLxrSg.js';
|
|
3
3
|
export { u as useDict } from './hooks-ClO29Chr.js';
|
|
4
4
|
export { useTranslation } from 'react-i18next';
|
|
5
5
|
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
I18N_RESOURCES_UPDATED_EVENT,
|
|
8
8
|
createI18nManager,
|
|
9
9
|
emitI18nResourcesUpdated
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-USTXU3BM.js";
|
|
11
11
|
|
|
12
12
|
// src/index.ts
|
|
13
13
|
import i18n from "i18next";
|
|
@@ -16,7 +16,6 @@ import { initReactI18next } from "react-i18next";
|
|
|
16
16
|
// src/storage/indexeddb.ts
|
|
17
17
|
var DB_NAME = "i18n_cache";
|
|
18
18
|
var SCHEMA_VERSION = 2;
|
|
19
|
-
var META_STORE = "i18n_meta";
|
|
20
19
|
function resourceStoreName(name) {
|
|
21
20
|
return `i18n_resources_${name}`;
|
|
22
21
|
}
|
|
@@ -36,9 +35,6 @@ function openDB(storeNames) {
|
|
|
36
35
|
s.createIndex("by_language", "langCode");
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
|
-
if (!db.objectStoreNames.contains(META_STORE)) {
|
|
40
|
-
db.createObjectStore(META_STORE, { keyPath: "key" });
|
|
41
|
-
}
|
|
42
38
|
};
|
|
43
39
|
request.onsuccess = () => {
|
|
44
40
|
const db = request.result;
|
|
@@ -86,26 +82,9 @@ async function withRetry(fn) {
|
|
|
86
82
|
}
|
|
87
83
|
}
|
|
88
84
|
var IndexedDBAdapter = class {
|
|
89
|
-
async
|
|
85
|
+
async ensureStores(stores) {
|
|
90
86
|
dbStoreNames = stores.map((s) => s.name);
|
|
91
|
-
|
|
92
|
-
const stored = await this.getMeta("schema_version");
|
|
93
|
-
const storedVersion = Number(stored ?? 0);
|
|
94
|
-
if (storedVersion === 0) {
|
|
95
|
-
await this.setMeta("schema_version", String(SCHEMA_VERSION));
|
|
96
|
-
} else if (storedVersion < SCHEMA_VERSION) {
|
|
97
|
-
db.close();
|
|
98
|
-
dbInstance = null;
|
|
99
|
-
await new Promise((resolve, reject) => {
|
|
100
|
-
const req = indexedDB.deleteDatabase(DB_NAME);
|
|
101
|
-
req.onsuccess = () => resolve();
|
|
102
|
-
req.onerror = () => reject(req.error);
|
|
103
|
-
});
|
|
104
|
-
dbInstance = await openDB(dbStoreNames);
|
|
105
|
-
await this.setMeta("schema_version", String(SCHEMA_VERSION));
|
|
106
|
-
} else if (storedVersion > SCHEMA_VERSION) {
|
|
107
|
-
throw new Error(`[i18n] DB schema version ${storedVersion} > current ${SCHEMA_VERSION}`);
|
|
108
|
-
}
|
|
87
|
+
await getDB(dbStoreNames);
|
|
109
88
|
}
|
|
110
89
|
async getRecord(storeName, key) {
|
|
111
90
|
return withRetry(async () => {
|
|
@@ -138,23 +117,6 @@ var IndexedDBAdapter = class {
|
|
|
138
117
|
await idbRequest(tx.objectStore(resourceStoreName(storeName)).clear());
|
|
139
118
|
});
|
|
140
119
|
}
|
|
141
|
-
async getMeta(key) {
|
|
142
|
-
return withRetry(async () => {
|
|
143
|
-
const db = await getDB();
|
|
144
|
-
const tx = db.transaction(META_STORE, "readonly");
|
|
145
|
-
const result = await idbRequest(
|
|
146
|
-
tx.objectStore(META_STORE).get(key)
|
|
147
|
-
);
|
|
148
|
-
return result?.value ?? null;
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
async setMeta(key, value) {
|
|
152
|
-
await withRetry(async () => {
|
|
153
|
-
const db = await getDB();
|
|
154
|
-
const tx = db.transaction(META_STORE, "readwrite");
|
|
155
|
-
await idbRequest(tx.objectStore(META_STORE).put({ key, value }));
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
120
|
async hasLoginResources(stores) {
|
|
159
121
|
return withRetry(async () => {
|
|
160
122
|
const db = await getDB();
|
|
@@ -171,7 +133,7 @@ var IndexedDBAdapter = class {
|
|
|
171
133
|
return;
|
|
172
134
|
}
|
|
173
135
|
const record = cursor.value;
|
|
174
|
-
if (!record.key.startsWith("UNLOGIN_")) {
|
|
136
|
+
if (!record.key.startsWith("UNLOGIN_") && !record.key.startsWith("__meta__:")) {
|
|
175
137
|
resolve(true);
|
|
176
138
|
return;
|
|
177
139
|
}
|
package/dist/mp/index.cjs
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkMQYSUEEWcjs = require('../chunk-MQYSUEEW.cjs');
|
|
6
6
|
|
|
7
7
|
// src/storage/wx-sqlite.ts
|
|
8
8
|
var DB_NAME = "i18n_cache";
|
|
9
|
-
var SCHEMA_VERSION = 2;
|
|
10
9
|
function resourceTable(name) {
|
|
11
10
|
return `i18n_resources_${name}`;
|
|
12
11
|
}
|
|
@@ -40,40 +39,17 @@ function exec(db, sql, args = []) {
|
|
|
40
39
|
});
|
|
41
40
|
}
|
|
42
41
|
var WxSQLiteAdapter = class {
|
|
43
|
-
async
|
|
44
|
-
const db = await getDB();
|
|
45
|
-
await exec(db, `
|
|
46
|
-
CREATE TABLE IF NOT EXISTS i18n_meta (
|
|
47
|
-
key TEXT PRIMARY KEY,
|
|
48
|
-
value TEXT NOT NULL
|
|
49
|
-
)
|
|
50
|
-
`);
|
|
51
|
-
const stored = await this.getMeta("schema_version");
|
|
52
|
-
const storedVersion = Number(_nullishCoalesce(stored, () => ( 0)));
|
|
53
|
-
if (storedVersion === 0) {
|
|
54
|
-
await this.createTables(stores);
|
|
55
|
-
await this.setMeta("schema_version", String(SCHEMA_VERSION));
|
|
56
|
-
} else if (storedVersion < SCHEMA_VERSION) {
|
|
57
|
-
for (const store of stores) {
|
|
58
|
-
await exec(db, `DROP TABLE IF EXISTS ${resourceTable(store.name)}`);
|
|
59
|
-
}
|
|
60
|
-
await this.createTables(stores);
|
|
61
|
-
await this.setMeta("schema_version", String(SCHEMA_VERSION));
|
|
62
|
-
} else if (storedVersion > SCHEMA_VERSION) {
|
|
63
|
-
throw new Error(`[i18n] wx.openDatabase schema version ${storedVersion} > current ${SCHEMA_VERSION}`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
async createTables(stores) {
|
|
42
|
+
async ensureStores(stores) {
|
|
67
43
|
const db = await getDB();
|
|
68
44
|
for (const store of stores) {
|
|
69
45
|
const table = resourceTable(store.name);
|
|
70
46
|
await exec(db, `
|
|
71
47
|
CREATE TABLE IF NOT EXISTS ${table} (
|
|
72
|
-
key
|
|
48
|
+
key TEXT PRIMARY KEY,
|
|
73
49
|
module_code TEXT NOT NULL,
|
|
74
|
-
lang_code
|
|
75
|
-
version
|
|
76
|
-
resources
|
|
50
|
+
lang_code TEXT NOT NULL,
|
|
51
|
+
version INTEGER NOT NULL DEFAULT 0,
|
|
52
|
+
resources TEXT NOT NULL
|
|
77
53
|
)
|
|
78
54
|
`);
|
|
79
55
|
await exec(
|
|
@@ -129,23 +105,13 @@ var WxSQLiteAdapter = class {
|
|
|
129
105
|
const db = await getDB();
|
|
130
106
|
await exec(db, `DELETE FROM ${resourceTable(storeName)}`);
|
|
131
107
|
}
|
|
132
|
-
async getMeta(key) {
|
|
133
|
-
const db = await getDB();
|
|
134
|
-
const result = await exec(db, "SELECT value FROM i18n_meta WHERE key = ?", [key]);
|
|
135
|
-
if (result.rows.length === 0) return null;
|
|
136
|
-
return result.rows.item(0).value;
|
|
137
|
-
}
|
|
138
|
-
async setMeta(key, value) {
|
|
139
|
-
const db = await getDB();
|
|
140
|
-
await exec(db, "INSERT OR REPLACE INTO i18n_meta (key, value) VALUES (?, ?)", [key, value]);
|
|
141
|
-
}
|
|
142
108
|
async hasLoginResources(stores) {
|
|
143
109
|
const db = await getDB();
|
|
144
110
|
for (const store of stores) {
|
|
145
111
|
const result = await exec(
|
|
146
112
|
db,
|
|
147
113
|
`SELECT key FROM ${resourceTable(store.name)}
|
|
148
|
-
WHERE key NOT LIKE 'UNLOGIN_%' LIMIT 1`
|
|
114
|
+
WHERE key NOT LIKE 'UNLOGIN_%' AND key NOT LIKE '__meta__:%' LIMIT 1`
|
|
149
115
|
);
|
|
150
116
|
if (result.rows.length > 0) return true;
|
|
151
117
|
}
|
|
@@ -215,7 +181,7 @@ function wxFetch(input, init) {
|
|
|
215
181
|
}
|
|
216
182
|
|
|
217
183
|
// src/mp/index.ts
|
|
218
|
-
var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } =
|
|
184
|
+
var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } = _chunkMQYSUEEWcjs.createI18nManager.call(void 0, {
|
|
219
185
|
storage: new WxSQLiteAdapter(),
|
|
220
186
|
createWorker: () => new WxWorkerAdapter(wx.createWorker("workers/preload-worker-mp.js")),
|
|
221
187
|
fetchFn: wxFetch
|
|
@@ -228,4 +194,4 @@ var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } =
|
|
|
228
194
|
|
|
229
195
|
|
|
230
196
|
|
|
231
|
-
exports.I18N_RESOURCES_UPDATED_EVENT =
|
|
197
|
+
exports.I18N_RESOURCES_UPDATED_EVENT = _chunkMQYSUEEWcjs.I18N_RESOURCES_UPDATED_EVENT; exports.closeSSE = closeSSE; exports.emitI18nResourcesUpdated = _chunkMQYSUEEWcjs.emitI18nResourcesUpdated; exports.ensureModules = ensureModules; exports.getAllRecordsByModule = getAllRecordsByModule; exports.getResource = getResource; exports.initI18n = initI18n;
|
package/dist/mp/index.d.cts
CHANGED
|
@@ -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-
|
|
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-
|
|
1
|
+
import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-5-eLxrSg.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-5-eLxrSg.cjs';
|
|
3
3
|
|
|
4
4
|
declare const initI18n: typeof initI18n$1;
|
|
5
5
|
declare const closeSSE: typeof closeSSE$1;
|
package/dist/mp/index.d.ts
CHANGED
|
@@ -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-
|
|
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-
|
|
1
|
+
import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-5-eLxrSg.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-5-eLxrSg.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,11 +2,10 @@ import {
|
|
|
2
2
|
I18N_RESOURCES_UPDATED_EVENT,
|
|
3
3
|
createI18nManager,
|
|
4
4
|
emitI18nResourcesUpdated
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-USTXU3BM.js";
|
|
6
6
|
|
|
7
7
|
// src/storage/wx-sqlite.ts
|
|
8
8
|
var DB_NAME = "i18n_cache";
|
|
9
|
-
var SCHEMA_VERSION = 2;
|
|
10
9
|
function resourceTable(name) {
|
|
11
10
|
return `i18n_resources_${name}`;
|
|
12
11
|
}
|
|
@@ -40,40 +39,17 @@ function exec(db, sql, args = []) {
|
|
|
40
39
|
});
|
|
41
40
|
}
|
|
42
41
|
var WxSQLiteAdapter = class {
|
|
43
|
-
async
|
|
44
|
-
const db = await getDB();
|
|
45
|
-
await exec(db, `
|
|
46
|
-
CREATE TABLE IF NOT EXISTS i18n_meta (
|
|
47
|
-
key TEXT PRIMARY KEY,
|
|
48
|
-
value TEXT NOT NULL
|
|
49
|
-
)
|
|
50
|
-
`);
|
|
51
|
-
const stored = await this.getMeta("schema_version");
|
|
52
|
-
const storedVersion = Number(stored ?? 0);
|
|
53
|
-
if (storedVersion === 0) {
|
|
54
|
-
await this.createTables(stores);
|
|
55
|
-
await this.setMeta("schema_version", String(SCHEMA_VERSION));
|
|
56
|
-
} else if (storedVersion < SCHEMA_VERSION) {
|
|
57
|
-
for (const store of stores) {
|
|
58
|
-
await exec(db, `DROP TABLE IF EXISTS ${resourceTable(store.name)}`);
|
|
59
|
-
}
|
|
60
|
-
await this.createTables(stores);
|
|
61
|
-
await this.setMeta("schema_version", String(SCHEMA_VERSION));
|
|
62
|
-
} else if (storedVersion > SCHEMA_VERSION) {
|
|
63
|
-
throw new Error(`[i18n] wx.openDatabase schema version ${storedVersion} > current ${SCHEMA_VERSION}`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
async createTables(stores) {
|
|
42
|
+
async ensureStores(stores) {
|
|
67
43
|
const db = await getDB();
|
|
68
44
|
for (const store of stores) {
|
|
69
45
|
const table = resourceTable(store.name);
|
|
70
46
|
await exec(db, `
|
|
71
47
|
CREATE TABLE IF NOT EXISTS ${table} (
|
|
72
|
-
key
|
|
48
|
+
key TEXT PRIMARY KEY,
|
|
73
49
|
module_code TEXT NOT NULL,
|
|
74
|
-
lang_code
|
|
75
|
-
version
|
|
76
|
-
resources
|
|
50
|
+
lang_code TEXT NOT NULL,
|
|
51
|
+
version INTEGER NOT NULL DEFAULT 0,
|
|
52
|
+
resources TEXT NOT NULL
|
|
77
53
|
)
|
|
78
54
|
`);
|
|
79
55
|
await exec(
|
|
@@ -129,23 +105,13 @@ var WxSQLiteAdapter = class {
|
|
|
129
105
|
const db = await getDB();
|
|
130
106
|
await exec(db, `DELETE FROM ${resourceTable(storeName)}`);
|
|
131
107
|
}
|
|
132
|
-
async getMeta(key) {
|
|
133
|
-
const db = await getDB();
|
|
134
|
-
const result = await exec(db, "SELECT value FROM i18n_meta WHERE key = ?", [key]);
|
|
135
|
-
if (result.rows.length === 0) return null;
|
|
136
|
-
return result.rows.item(0).value;
|
|
137
|
-
}
|
|
138
|
-
async setMeta(key, value) {
|
|
139
|
-
const db = await getDB();
|
|
140
|
-
await exec(db, "INSERT OR REPLACE INTO i18n_meta (key, value) VALUES (?, ?)", [key, value]);
|
|
141
|
-
}
|
|
142
108
|
async hasLoginResources(stores) {
|
|
143
109
|
const db = await getDB();
|
|
144
110
|
for (const store of stores) {
|
|
145
111
|
const result = await exec(
|
|
146
112
|
db,
|
|
147
113
|
`SELECT key FROM ${resourceTable(store.name)}
|
|
148
|
-
WHERE key NOT LIKE 'UNLOGIN_%' LIMIT 1`
|
|
114
|
+
WHERE key NOT LIKE 'UNLOGIN_%' AND key NOT LIKE '__meta__:%' LIMIT 1`
|
|
149
115
|
);
|
|
150
116
|
if (result.rows.length > 0) return true;
|
|
151
117
|
}
|
package/dist/native/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
@@ -7,7 +7,7 @@ var _chunkAJJKJPNBcjs = require('../chunk-AJJKJPNB.cjs');
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkMQYSUEEWcjs = require('../chunk-MQYSUEEW.cjs');
|
|
11
11
|
|
|
12
12
|
// src/native/index.ts
|
|
13
13
|
var _i18next = require('i18next'); var _i18next2 = _interopRequireDefault(_i18next);
|
|
@@ -15,7 +15,6 @@ var _reacti18next = require('react-i18next');
|
|
|
15
15
|
|
|
16
16
|
// src/storage/sqlite.ts
|
|
17
17
|
var DB_NAME = "i18n_cache";
|
|
18
|
-
var SCHEMA_VERSION = 2;
|
|
19
18
|
function resourceTable(name) {
|
|
20
19
|
return `i18n_resources_${name}`;
|
|
21
20
|
}
|
|
@@ -31,38 +30,16 @@ async function execute(sql, params = []) {
|
|
|
31
30
|
return db.executeAsync(sql, params);
|
|
32
31
|
}
|
|
33
32
|
var SQLiteAdapter = class {
|
|
34
|
-
async
|
|
35
|
-
await execute(`
|
|
36
|
-
CREATE TABLE IF NOT EXISTS i18n_meta (
|
|
37
|
-
key TEXT PRIMARY KEY,
|
|
38
|
-
value TEXT NOT NULL
|
|
39
|
-
)
|
|
40
|
-
`);
|
|
41
|
-
const stored = await this.getMeta("schema_version");
|
|
42
|
-
const storedVersion = Number(_nullishCoalesce(stored, () => ( 0)));
|
|
43
|
-
if (storedVersion === 0) {
|
|
44
|
-
await this.createTables(stores);
|
|
45
|
-
await this.setMeta("schema_version", String(SCHEMA_VERSION));
|
|
46
|
-
} else if (storedVersion < SCHEMA_VERSION) {
|
|
47
|
-
for (const store of stores) {
|
|
48
|
-
await execute(`DROP TABLE IF EXISTS ${resourceTable(store.name)}`);
|
|
49
|
-
}
|
|
50
|
-
await this.createTables(stores);
|
|
51
|
-
await this.setMeta("schema_version", String(SCHEMA_VERSION));
|
|
52
|
-
} else if (storedVersion > SCHEMA_VERSION) {
|
|
53
|
-
throw new Error(`[i18n] SQLite schema version ${storedVersion} > current ${SCHEMA_VERSION}`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
async createTables(stores) {
|
|
33
|
+
async ensureStores(stores) {
|
|
57
34
|
for (const store of stores) {
|
|
58
35
|
const table = resourceTable(store.name);
|
|
59
36
|
await execute(`
|
|
60
37
|
CREATE TABLE IF NOT EXISTS ${table} (
|
|
61
|
-
key
|
|
38
|
+
key TEXT PRIMARY KEY,
|
|
62
39
|
module_code TEXT NOT NULL,
|
|
63
|
-
lang_code
|
|
64
|
-
version
|
|
65
|
-
resources
|
|
40
|
+
lang_code TEXT NOT NULL,
|
|
41
|
+
version INTEGER NOT NULL DEFAULT 0,
|
|
42
|
+
resources TEXT NOT NULL
|
|
66
43
|
)
|
|
67
44
|
`);
|
|
68
45
|
await execute(
|
|
@@ -105,22 +82,11 @@ var SQLiteAdapter = class {
|
|
|
105
82
|
async clearStore(storeName) {
|
|
106
83
|
await execute(`DELETE FROM ${resourceTable(storeName)}`);
|
|
107
84
|
}
|
|
108
|
-
async getMeta(key) {
|
|
109
|
-
const { rows } = await execute("SELECT value FROM i18n_meta WHERE key = ?", [key]);
|
|
110
|
-
if (!rows.length) return null;
|
|
111
|
-
return rows[0].value;
|
|
112
|
-
}
|
|
113
|
-
async setMeta(key, value) {
|
|
114
|
-
await execute(
|
|
115
|
-
"INSERT OR REPLACE INTO i18n_meta (key, value) VALUES (?, ?)",
|
|
116
|
-
[key, value]
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
85
|
async hasLoginResources(stores) {
|
|
120
86
|
for (const store of stores) {
|
|
121
87
|
const { rows } = await execute(
|
|
122
88
|
`SELECT key FROM ${resourceTable(store.name)}
|
|
123
|
-
WHERE key NOT LIKE 'UNLOGIN_%' LIMIT 1`
|
|
89
|
+
WHERE key NOT LIKE 'UNLOGIN_%' AND key NOT LIKE '__meta__:%' LIMIT 1`
|
|
124
90
|
);
|
|
125
91
|
if (rows.length > 0) return true;
|
|
126
92
|
}
|
|
@@ -155,7 +121,7 @@ if (!_i18next2.default.isInitialized) {
|
|
|
155
121
|
}
|
|
156
122
|
});
|
|
157
123
|
}
|
|
158
|
-
var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } =
|
|
124
|
+
var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } = _chunkMQYSUEEWcjs.createI18nManager.call(void 0, {
|
|
159
125
|
storage: new SQLiteAdapter(),
|
|
160
126
|
// Hermes Worker(RN 0.71+),API 与 Web Worker 一致
|
|
161
127
|
createWorker: () => new (0, _chunkAJJKJPNBcjs.WebWorkerAdapter)(
|
|
@@ -172,4 +138,4 @@ var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } =
|
|
|
172
138
|
|
|
173
139
|
|
|
174
140
|
|
|
175
|
-
exports.I18N_RESOURCES_UPDATED_EVENT =
|
|
141
|
+
exports.I18N_RESOURCES_UPDATED_EVENT = _chunkMQYSUEEWcjs.I18N_RESOURCES_UPDATED_EVENT; exports.closeSSE = closeSSE; exports.emitI18nResourcesUpdated = _chunkMQYSUEEWcjs.emitI18nResourcesUpdated; exports.ensureModules = ensureModules; exports.getAllRecordsByModule = getAllRecordsByModule; exports.getResource = getResource; exports.initI18n = initI18n; exports.useDict = _chunkAJJKJPNBcjs.useDict; exports.useTranslation = _chunkAJJKJPNBcjs.useTranslation;
|
package/dist/native/index.d.cts
CHANGED
|
@@ -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-
|
|
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-
|
|
1
|
+
import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-5-eLxrSg.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-5-eLxrSg.cjs';
|
|
3
3
|
export { u as useDict } from '../hooks-ClO29Chr.cjs';
|
|
4
4
|
export { useTranslation } from 'react-i18next';
|
|
5
5
|
|
package/dist/native/index.d.ts
CHANGED
|
@@ -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-
|
|
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-
|
|
1
|
+
import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-5-eLxrSg.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-5-eLxrSg.js';
|
|
3
3
|
export { u as useDict } from '../hooks-ClO29Chr.js';
|
|
4
4
|
export { useTranslation } from 'react-i18next';
|
|
5
5
|
|
package/dist/native/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
I18N_RESOURCES_UPDATED_EVENT,
|
|
8
8
|
createI18nManager,
|
|
9
9
|
emitI18nResourcesUpdated
|
|
10
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-USTXU3BM.js";
|
|
11
11
|
|
|
12
12
|
// src/native/index.ts
|
|
13
13
|
import i18n from "i18next";
|
|
@@ -15,7 +15,6 @@ import { initReactI18next } from "react-i18next";
|
|
|
15
15
|
|
|
16
16
|
// src/storage/sqlite.ts
|
|
17
17
|
var DB_NAME = "i18n_cache";
|
|
18
|
-
var SCHEMA_VERSION = 2;
|
|
19
18
|
function resourceTable(name) {
|
|
20
19
|
return `i18n_resources_${name}`;
|
|
21
20
|
}
|
|
@@ -31,38 +30,16 @@ async function execute(sql, params = []) {
|
|
|
31
30
|
return db.executeAsync(sql, params);
|
|
32
31
|
}
|
|
33
32
|
var SQLiteAdapter = class {
|
|
34
|
-
async
|
|
35
|
-
await execute(`
|
|
36
|
-
CREATE TABLE IF NOT EXISTS i18n_meta (
|
|
37
|
-
key TEXT PRIMARY KEY,
|
|
38
|
-
value TEXT NOT NULL
|
|
39
|
-
)
|
|
40
|
-
`);
|
|
41
|
-
const stored = await this.getMeta("schema_version");
|
|
42
|
-
const storedVersion = Number(stored ?? 0);
|
|
43
|
-
if (storedVersion === 0) {
|
|
44
|
-
await this.createTables(stores);
|
|
45
|
-
await this.setMeta("schema_version", String(SCHEMA_VERSION));
|
|
46
|
-
} else if (storedVersion < SCHEMA_VERSION) {
|
|
47
|
-
for (const store of stores) {
|
|
48
|
-
await execute(`DROP TABLE IF EXISTS ${resourceTable(store.name)}`);
|
|
49
|
-
}
|
|
50
|
-
await this.createTables(stores);
|
|
51
|
-
await this.setMeta("schema_version", String(SCHEMA_VERSION));
|
|
52
|
-
} else if (storedVersion > SCHEMA_VERSION) {
|
|
53
|
-
throw new Error(`[i18n] SQLite schema version ${storedVersion} > current ${SCHEMA_VERSION}`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
async createTables(stores) {
|
|
33
|
+
async ensureStores(stores) {
|
|
57
34
|
for (const store of stores) {
|
|
58
35
|
const table = resourceTable(store.name);
|
|
59
36
|
await execute(`
|
|
60
37
|
CREATE TABLE IF NOT EXISTS ${table} (
|
|
61
|
-
key
|
|
38
|
+
key TEXT PRIMARY KEY,
|
|
62
39
|
module_code TEXT NOT NULL,
|
|
63
|
-
lang_code
|
|
64
|
-
version
|
|
65
|
-
resources
|
|
40
|
+
lang_code TEXT NOT NULL,
|
|
41
|
+
version INTEGER NOT NULL DEFAULT 0,
|
|
42
|
+
resources TEXT NOT NULL
|
|
66
43
|
)
|
|
67
44
|
`);
|
|
68
45
|
await execute(
|
|
@@ -105,22 +82,11 @@ var SQLiteAdapter = class {
|
|
|
105
82
|
async clearStore(storeName) {
|
|
106
83
|
await execute(`DELETE FROM ${resourceTable(storeName)}`);
|
|
107
84
|
}
|
|
108
|
-
async getMeta(key) {
|
|
109
|
-
const { rows } = await execute("SELECT value FROM i18n_meta WHERE key = ?", [key]);
|
|
110
|
-
if (!rows.length) return null;
|
|
111
|
-
return rows[0].value;
|
|
112
|
-
}
|
|
113
|
-
async setMeta(key, value) {
|
|
114
|
-
await execute(
|
|
115
|
-
"INSERT OR REPLACE INTO i18n_meta (key, value) VALUES (?, ?)",
|
|
116
|
-
[key, value]
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
85
|
async hasLoginResources(stores) {
|
|
120
86
|
for (const store of stores) {
|
|
121
87
|
const { rows } = await execute(
|
|
122
88
|
`SELECT key FROM ${resourceTable(store.name)}
|
|
123
|
-
WHERE key NOT LIKE 'UNLOGIN_%' LIMIT 1`
|
|
89
|
+
WHERE key NOT LIKE 'UNLOGIN_%' AND key NOT LIKE '__meta__:%' LIMIT 1`
|
|
124
90
|
);
|
|
125
91
|
if (rows.length > 0) return true;
|
|
126
92
|
}
|