@shuo-li/i18n 1.0.2 → 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-CAjfH0vs.d.cts → cacheEvents-5-eLxrSg.d.cts} +3 -3
- package/dist/{cacheEvents-CAjfH0vs.d.ts → cacheEvents-5-eLxrSg.d.ts} +3 -3
- package/dist/{chunk-VKQL65NM.cjs → chunk-MQYSUEEW.cjs} +51 -36
- package/dist/{chunk-BE3XDO7H.js → chunk-USTXU3BM.js} +43 -28
- 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,8 +23,8 @@ interface SSEConfig {
|
|
|
23
23
|
transformMessage?: (raw: unknown) => SSEMessage;
|
|
24
24
|
}
|
|
25
25
|
interface I18nInitOptions {
|
|
26
|
-
|
|
27
|
-
version?: number;
|
|
26
|
+
langCode: string;
|
|
27
|
+
version?: number | string;
|
|
28
28
|
languages?: string[];
|
|
29
29
|
modules?: string[];
|
|
30
30
|
stores: StoreConfig[];
|
|
@@ -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,8 +23,8 @@ interface SSEConfig {
|
|
|
23
23
|
transformMessage?: (raw: unknown) => SSEMessage;
|
|
24
24
|
}
|
|
25
25
|
interface I18nInitOptions {
|
|
26
|
-
|
|
27
|
-
version?: number;
|
|
26
|
+
langCode: string;
|
|
27
|
+
version?: number | string;
|
|
28
28
|
languages?: string[];
|
|
29
29
|
modules?: string[];
|
|
30
30
|
stores: StoreConfig[];
|
|
@@ -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;
|
|
@@ -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(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/core/cacheEvents.ts
|
|
2
2
|
var I18N_RESOURCES_UPDATED_EVENT = "golucky:i18n-resources-updated";
|
|
3
3
|
function emitI18nResourcesUpdated() {
|
|
4
4
|
if (typeof window === "undefined") return;
|
|
@@ -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,40 +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;
|
|
399
|
-
const
|
|
400
|
-
|
|
400
|
+
const baseStoreName = resolvedStores[0].name;
|
|
401
|
+
const current = String(options.version);
|
|
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"]]);
|
|
404
|
+
if (stored === current) return;
|
|
401
405
|
for (const store of options.stores) {
|
|
402
406
|
await storage.clearStore(store.name);
|
|
403
407
|
}
|
|
404
|
-
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
|
+
});
|
|
405
415
|
}
|
|
406
416
|
async function doUnloginPull(storage, options) {
|
|
407
417
|
const { apiContext } = options;
|
|
408
418
|
if (!apiContext.unloginPull) return;
|
|
409
419
|
const baseStore = resolvedStores[0];
|
|
420
|
+
let blocks;
|
|
410
421
|
try {
|
|
411
|
-
|
|
412
|
-
for (const block of blocks) {
|
|
413
|
-
for (const mod of _nullishCoalesce(block.modules, () => ( []))) {
|
|
414
|
-
const key = buildKey(mod.moduleCode, block.langCode, baseStore);
|
|
415
|
-
const existing = await storage.getRecord(baseStore.name, key);
|
|
416
|
-
const parsed = parseI18nValues(_nullishCoalesce(mod.i18nValues, () => ( [])));
|
|
417
|
-
const resources = deepMerge(
|
|
418
|
-
_nullishCoalesce(_optionalChain([existing, 'optionalAccess', _21 => _21.resources]), () => ( {})),
|
|
419
|
-
flatToNested(parsed)
|
|
420
|
-
);
|
|
421
|
-
await storage.putRecord(baseStore.name, {
|
|
422
|
-
key,
|
|
423
|
-
moduleCode: mod.moduleCode,
|
|
424
|
-
langCode: block.langCode,
|
|
425
|
-
version: _nullishCoalesce(mod.version, () => ( 0)),
|
|
426
|
-
resources
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
}
|
|
422
|
+
blocks = await doFetch(apiContext.unloginPull, options);
|
|
430
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
|
+
}
|
|
431
446
|
}
|
|
432
447
|
await injectCurrentLanguageModules(currentLang);
|
|
433
448
|
await _i18next2.default.changeLanguage(currentLang);
|
|
@@ -492,7 +507,7 @@ async function injectFromDB(moduleCode, langCode) {
|
|
|
492
507
|
const store = resolvedStores[i];
|
|
493
508
|
const key = buildKey(moduleCode, langCode, store);
|
|
494
509
|
const record = await storage.getRecord(store.name, key);
|
|
495
|
-
if (!_optionalChain([record, 'optionalAccess',
|
|
510
|
+
if (!_optionalChain([record, 'optionalAccess', _24 => _24.resources])) continue;
|
|
496
511
|
if (i === 0) {
|
|
497
512
|
_i18next2.default.addResourceBundle(langCode, moduleCode, record.resources, true, true);
|
|
498
513
|
} else {
|
|
@@ -514,7 +529,7 @@ function startSSE(options) {
|
|
|
514
529
|
if (!apiContext.sse) return;
|
|
515
530
|
sseClient.start(
|
|
516
531
|
(raw) => {
|
|
517
|
-
const msg = _optionalChain([apiContext, 'access',
|
|
532
|
+
const msg = _optionalChain([apiContext, 'access', _25 => _25.sse, 'optionalAccess', _26 => _26.transformMessage]) ? apiContext.sse.transformMessage(raw) : raw;
|
|
518
533
|
void handleSSEMessage(msg, options);
|
|
519
534
|
},
|
|
520
535
|
{
|
|
@@ -599,16 +614,16 @@ async function pullAndStore(task, fromVersion, options) {
|
|
|
599
614
|
const storeIndex = resolvedStores.indexOf(store);
|
|
600
615
|
const key = buildKey(mod.moduleCode, block.langCode, store);
|
|
601
616
|
const existing = await storage.getRecord(store.name, key);
|
|
602
|
-
if (mod.version <= (_nullishCoalesce(_optionalChain([existing, 'optionalAccess',
|
|
617
|
+
if (mod.version <= (_nullishCoalesce(_optionalChain([existing, 'optionalAccess', _27 => _27.version]), () => ( 0)))) continue;
|
|
603
618
|
let resources;
|
|
604
619
|
const parsed = parseI18nValues(_nullishCoalesce(mod.i18nValues, () => ( [])));
|
|
605
620
|
if (storeIndex === 0) {
|
|
606
621
|
resources = deepMerge(
|
|
607
|
-
_nullishCoalesce(_optionalChain([existing, 'optionalAccess',
|
|
622
|
+
_nullishCoalesce(_optionalChain([existing, 'optionalAccess', _28 => _28.resources]), () => ( {})),
|
|
608
623
|
flatToNested(parsed)
|
|
609
624
|
);
|
|
610
625
|
} else {
|
|
611
|
-
resources = { ..._nullishCoalesce(_optionalChain([existing, 'optionalAccess',
|
|
626
|
+
resources = { ..._nullishCoalesce(_optionalChain([existing, 'optionalAccess', _29 => _29.resources]), () => ( {})), ...parsed };
|
|
612
627
|
}
|
|
613
628
|
const version = Math.max(mod.version, task.targetVersion);
|
|
614
629
|
await storage.putRecord(store.name, {
|
|
@@ -644,7 +659,7 @@ async function doFetch(config, options, internalParams) {
|
|
|
644
659
|
}
|
|
645
660
|
function buildSig(options) {
|
|
646
661
|
const cgKeys = options.stores.map((s) => _nullishCoalesce(s.cacheGroupKey, () => ( ""))).join(",");
|
|
647
|
-
return [options.apiContext.baseURL, options.
|
|
662
|
+
return [options.apiContext.baseURL, options.langCode, cgKeys].join("|");
|
|
648
663
|
}
|
|
649
664
|
function sortedModules() {
|
|
650
665
|
const priority = PRIORITY_MODULES.filter((m) => resolvedModules.includes(m));
|
|
@@ -652,13 +667,13 @@ function sortedModules() {
|
|
|
652
667
|
return [...priority, ...rest];
|
|
653
668
|
}
|
|
654
669
|
function getStaticLocale(moduleCode, langCode) {
|
|
655
|
-
return _nullishCoalesce(_optionalChain([initOptions, 'optionalAccess',
|
|
670
|
+
return _nullishCoalesce(_optionalChain([initOptions, 'optionalAccess', _30 => _30.staticLocales, 'optionalAccess', _31 => _31[langCode], 'optionalAccess', _32 => _32[moduleCode]]), () => ( {}));
|
|
656
671
|
}
|
|
657
672
|
async function getStoredVersion(store, moduleCode, langCode) {
|
|
658
673
|
const storage = managerOptions.storage;
|
|
659
674
|
const key = buildKey(moduleCode, langCode, store);
|
|
660
675
|
const record = await storage.getRecord(store.name, key);
|
|
661
|
-
return _nullishCoalesce(_optionalChain([record, 'optionalAccess',
|
|
676
|
+
return _nullishCoalesce(_optionalChain([record, 'optionalAccess', _33 => _33.version]), () => ( 0));
|
|
662
677
|
}
|
|
663
678
|
|
|
664
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,40 +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;
|
|
399
|
-
const
|
|
400
|
-
|
|
400
|
+
const baseStoreName = resolvedStores[0].name;
|
|
401
|
+
const current = String(options.version);
|
|
402
|
+
const record = await storage.getRecord(baseStoreName, CACHE_VERSION_KEY).catch(() => void 0);
|
|
403
|
+
const stored = record?.resources?.["value"];
|
|
404
|
+
if (stored === current) return;
|
|
401
405
|
for (const store of options.stores) {
|
|
402
406
|
await storage.clearStore(store.name);
|
|
403
407
|
}
|
|
404
|
-
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
|
+
});
|
|
405
415
|
}
|
|
406
416
|
async function doUnloginPull(storage, options) {
|
|
407
417
|
const { apiContext } = options;
|
|
408
418
|
if (!apiContext.unloginPull) return;
|
|
409
419
|
const baseStore = resolvedStores[0];
|
|
420
|
+
let blocks;
|
|
410
421
|
try {
|
|
411
|
-
|
|
412
|
-
for (const block of blocks) {
|
|
413
|
-
for (const mod of block.modules ?? []) {
|
|
414
|
-
const key = buildKey(mod.moduleCode, block.langCode, baseStore);
|
|
415
|
-
const existing = await storage.getRecord(baseStore.name, key);
|
|
416
|
-
const parsed = parseI18nValues(mod.i18nValues ?? []);
|
|
417
|
-
const resources = deepMerge(
|
|
418
|
-
existing?.resources ?? {},
|
|
419
|
-
flatToNested(parsed)
|
|
420
|
-
);
|
|
421
|
-
await storage.putRecord(baseStore.name, {
|
|
422
|
-
key,
|
|
423
|
-
moduleCode: mod.moduleCode,
|
|
424
|
-
langCode: block.langCode,
|
|
425
|
-
version: mod.version ?? 0,
|
|
426
|
-
resources
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
}
|
|
422
|
+
blocks = await doFetch(apiContext.unloginPull, options);
|
|
430
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
|
+
}
|
|
431
446
|
}
|
|
432
447
|
await injectCurrentLanguageModules(currentLang);
|
|
433
448
|
await i18n.changeLanguage(currentLang);
|
|
@@ -644,7 +659,7 @@ async function doFetch(config, options, internalParams) {
|
|
|
644
659
|
}
|
|
645
660
|
function buildSig(options) {
|
|
646
661
|
const cgKeys = options.stores.map((s) => s.cacheGroupKey ?? "").join(",");
|
|
647
|
-
return [options.apiContext.baseURL, options.
|
|
662
|
+
return [options.apiContext.baseURL, options.langCode, cgKeys].join("|");
|
|
648
663
|
}
|
|
649
664
|
function sortedModules() {
|
|
650
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
|
}
|