@shuo-li/i18n 1.0.3 → 1.0.5
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-CSwgzbob.d.cts} +6 -15
- package/dist/{cacheEvents-CDBRPnHU.d.ts → cacheEvents-CSwgzbob.d.ts} +6 -15
- package/dist/{chunk-K5VX3COH.cjs → chunk-JPKSBSEO.cjs} +136 -129
- package/dist/{chunk-IWP4252C.js → chunk-X6D2MZ7M.js} +124 -117
- package/dist/index.cjs +7 -46
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -43
- 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/dist/workers/preload-worker-rn.cjs +12 -55
- package/dist/workers/preload-worker-rn.js +12 -55
- package/dist/workers/preload-worker.cjs +4 -128
- package/dist/workers/preload-worker.js +3 -127
- 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;
|
|
@@ -88,19 +88,10 @@ interface WorkerTask {
|
|
|
88
88
|
/** 经 buildParams 映射后的实际请求参数;未提供时 Worker 使用内部字段名 */
|
|
89
89
|
params?: Record<string, unknown>;
|
|
90
90
|
}
|
|
91
|
-
interface
|
|
92
|
-
type: '
|
|
93
|
-
storeName: string;
|
|
94
|
-
langCode: string;
|
|
95
|
-
moduleCode: string;
|
|
96
|
-
version: number;
|
|
97
|
-
}
|
|
98
|
-
interface WorkerDataReadyMessage {
|
|
99
|
-
type: 'dataReady';
|
|
100
|
-
storeName: string;
|
|
101
|
-
storeIndex: number;
|
|
102
|
-
record: ResourceRecord;
|
|
91
|
+
interface WorkerRawDataMessage {
|
|
92
|
+
type: 'rawData';
|
|
103
93
|
task: WorkerTask;
|
|
94
|
+
raw: unknown;
|
|
104
95
|
}
|
|
105
96
|
interface WorkerModuleErrorMessage {
|
|
106
97
|
type: 'moduleError';
|
|
@@ -115,7 +106,7 @@ interface WorkerErrorMessage {
|
|
|
115
106
|
type: 'error';
|
|
116
107
|
message?: string;
|
|
117
108
|
}
|
|
118
|
-
type WorkerOutMessage =
|
|
109
|
+
type WorkerOutMessage = WorkerRawDataMessage | WorkerModuleErrorMessage | WorkerDoneMessage | WorkerErrorMessage;
|
|
119
110
|
interface WorkerLike {
|
|
120
111
|
postMessage(data: unknown): void;
|
|
121
112
|
onMessage(handler: (data: WorkerOutMessage) => void): void;
|
|
@@ -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;
|
|
@@ -88,19 +88,10 @@ interface WorkerTask {
|
|
|
88
88
|
/** 经 buildParams 映射后的实际请求参数;未提供时 Worker 使用内部字段名 */
|
|
89
89
|
params?: Record<string, unknown>;
|
|
90
90
|
}
|
|
91
|
-
interface
|
|
92
|
-
type: '
|
|
93
|
-
storeName: string;
|
|
94
|
-
langCode: string;
|
|
95
|
-
moduleCode: string;
|
|
96
|
-
version: number;
|
|
97
|
-
}
|
|
98
|
-
interface WorkerDataReadyMessage {
|
|
99
|
-
type: 'dataReady';
|
|
100
|
-
storeName: string;
|
|
101
|
-
storeIndex: number;
|
|
102
|
-
record: ResourceRecord;
|
|
91
|
+
interface WorkerRawDataMessage {
|
|
92
|
+
type: 'rawData';
|
|
103
93
|
task: WorkerTask;
|
|
94
|
+
raw: unknown;
|
|
104
95
|
}
|
|
105
96
|
interface WorkerModuleErrorMessage {
|
|
106
97
|
type: 'moduleError';
|
|
@@ -115,7 +106,7 @@ interface WorkerErrorMessage {
|
|
|
115
106
|
type: 'error';
|
|
116
107
|
message?: string;
|
|
117
108
|
}
|
|
118
|
-
type WorkerOutMessage =
|
|
109
|
+
type WorkerOutMessage = WorkerRawDataMessage | WorkerModuleErrorMessage | WorkerDoneMessage | WorkerErrorMessage;
|
|
119
110
|
interface WorkerLike {
|
|
120
111
|
postMessage(data: unknown): void;
|
|
121
112
|
onMessage(handler: (data: WorkerOutMessage) => void): void;
|
|
@@ -119,6 +119,56 @@ var SSEClient = class {
|
|
|
119
119
|
}
|
|
120
120
|
};
|
|
121
121
|
|
|
122
|
+
// src/core/worker-manager.ts
|
|
123
|
+
var WorkerManager = class {
|
|
124
|
+
constructor() {
|
|
125
|
+
this.worker = null;
|
|
126
|
+
this.pendingCallbacks = /* @__PURE__ */ new Set();
|
|
127
|
+
this.finalized = false;
|
|
128
|
+
}
|
|
129
|
+
start(createWorker, payload, callbacks) {
|
|
130
|
+
this.terminate();
|
|
131
|
+
this.finalized = false;
|
|
132
|
+
this.pendingCallbacks = /* @__PURE__ */ new Set();
|
|
133
|
+
if (payload.tasks.length === 0) {
|
|
134
|
+
callbacks.onDone();
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const worker = createWorker();
|
|
138
|
+
this.worker = worker;
|
|
139
|
+
worker.onMessage((msg) => {
|
|
140
|
+
if (msg.type === "rawData") {
|
|
141
|
+
const p = callbacks.onRawData(msg.task, msg.raw).catch(() => {
|
|
142
|
+
});
|
|
143
|
+
this.pendingCallbacks.add(p);
|
|
144
|
+
p.finally(() => this.pendingCallbacks.delete(p));
|
|
145
|
+
} else if (msg.type === "moduleError") {
|
|
146
|
+
_optionalChain([callbacks, 'access', _7 => _7.onModuleError, 'optionalCall', _8 => _8(msg)]);
|
|
147
|
+
} else if (msg.type === "done" || msg.type === "error") {
|
|
148
|
+
if (msg.type === "error") _optionalChain([callbacks, 'access', _9 => _9.onError, 'optionalCall', _10 => _10()]);
|
|
149
|
+
this.finalize(callbacks);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
worker.postMessage({ type: "start", payload });
|
|
153
|
+
}
|
|
154
|
+
terminate() {
|
|
155
|
+
_optionalChain([this, 'access', _11 => _11.worker, 'optionalAccess', _12 => _12.terminate, 'call', _13 => _13()]);
|
|
156
|
+
this.worker = null;
|
|
157
|
+
}
|
|
158
|
+
isRunning() {
|
|
159
|
+
return this.worker !== null;
|
|
160
|
+
}
|
|
161
|
+
finalize(callbacks) {
|
|
162
|
+
if (this.finalized) return;
|
|
163
|
+
this.finalized = true;
|
|
164
|
+
const pending = [...this.pendingCallbacks];
|
|
165
|
+
Promise.allSettled(pending).then(() => {
|
|
166
|
+
this.terminate();
|
|
167
|
+
callbacks.onDone();
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
122
172
|
// src/core/utils.ts
|
|
123
173
|
function buildKey(moduleCode, langCode, store) {
|
|
124
174
|
return store.cacheGroupKey ? `${moduleCode}_${langCode}_${store.cacheGroupKey}` : `${moduleCode}_${langCode}`;
|
|
@@ -162,10 +212,10 @@ function parseI18nValues(values) {
|
|
|
162
212
|
}
|
|
163
213
|
function toDefaultParams(p) {
|
|
164
214
|
const result = {};
|
|
165
|
-
if (_optionalChain([p, 'optionalAccess',
|
|
166
|
-
if (_optionalChain([p, 'optionalAccess',
|
|
167
|
-
if (_optionalChain([p, 'optionalAccess',
|
|
168
|
-
if (_optionalChain([p, 'optionalAccess',
|
|
215
|
+
if (_optionalChain([p, 'optionalAccess', _14 => _14.storeName])) result["storeName"] = p.storeName;
|
|
216
|
+
if (_optionalChain([p, 'optionalAccess', _15 => _15.langCode])) result["langCode"] = p.langCode;
|
|
217
|
+
if (_optionalChain([p, 'optionalAccess', _16 => _16.moduleCode])) result["moduleCode"] = p.moduleCode;
|
|
218
|
+
if (_optionalChain([p, 'optionalAccess', _17 => _17.version]) != null) result["version"] = String(p.version);
|
|
169
219
|
return result;
|
|
170
220
|
}
|
|
171
221
|
function toQueryString(params) {
|
|
@@ -174,89 +224,7 @@ function toQueryString(params) {
|
|
|
174
224
|
).toString();
|
|
175
225
|
}
|
|
176
226
|
|
|
177
|
-
// src/core/worker-manager.ts
|
|
178
|
-
var WorkerManager = class {
|
|
179
|
-
constructor() {
|
|
180
|
-
this.worker = null;
|
|
181
|
-
this.pendingCallbacks = /* @__PURE__ */ new Set();
|
|
182
|
-
this.finalized = false;
|
|
183
|
-
}
|
|
184
|
-
start(createWorker, payload, callbacks, storage) {
|
|
185
|
-
this.terminate();
|
|
186
|
-
this.finalized = false;
|
|
187
|
-
this.pendingCallbacks = /* @__PURE__ */ new Set();
|
|
188
|
-
if (payload.tasks.length === 0) {
|
|
189
|
-
callbacks.onDone();
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
const worker = createWorker();
|
|
193
|
-
this.worker = worker;
|
|
194
|
-
worker.onMessage((msg) => {
|
|
195
|
-
if (msg.type === "moduleLoaded") {
|
|
196
|
-
const m = msg;
|
|
197
|
-
const p = callbacks.onModuleLoaded({
|
|
198
|
-
storeName: m.storeName,
|
|
199
|
-
langCode: m.langCode,
|
|
200
|
-
moduleCode: m.moduleCode,
|
|
201
|
-
version: m.version
|
|
202
|
-
});
|
|
203
|
-
this.pendingCallbacks.add(p);
|
|
204
|
-
p.finally(() => this.pendingCallbacks.delete(p));
|
|
205
|
-
} else if (msg.type === "dataReady") {
|
|
206
|
-
if (!storage) return;
|
|
207
|
-
const p = (async () => {
|
|
208
|
-
const existing = await storage.getRecord(msg.storeName, msg.record.key);
|
|
209
|
-
if (existing && msg.record.version <= existing.version) return;
|
|
210
|
-
let resources;
|
|
211
|
-
if (msg.storeIndex === 0) {
|
|
212
|
-
resources = deepMerge(
|
|
213
|
-
_nullishCoalesce(_optionalChain([existing, 'optionalAccess', _11 => _11.resources]), () => ( {})),
|
|
214
|
-
msg.record.resources
|
|
215
|
-
);
|
|
216
|
-
} else {
|
|
217
|
-
resources = { ..._nullishCoalesce(_optionalChain([existing, 'optionalAccess', _12 => _12.resources]), () => ( {})), ...msg.record.resources };
|
|
218
|
-
}
|
|
219
|
-
const mergedRecord = { ...msg.record, resources };
|
|
220
|
-
await storage.putRecord(msg.storeName, mergedRecord);
|
|
221
|
-
await callbacks.onModuleLoaded({
|
|
222
|
-
storeName: msg.task.storeName,
|
|
223
|
-
langCode: mergedRecord.langCode,
|
|
224
|
-
moduleCode: mergedRecord.moduleCode,
|
|
225
|
-
version: mergedRecord.version
|
|
226
|
-
});
|
|
227
|
-
})().catch(() => {
|
|
228
|
-
});
|
|
229
|
-
this.pendingCallbacks.add(p);
|
|
230
|
-
p.finally(() => this.pendingCallbacks.delete(p));
|
|
231
|
-
} else if (msg.type === "moduleError") {
|
|
232
|
-
_optionalChain([callbacks, 'access', _13 => _13.onModuleError, 'optionalCall', _14 => _14(msg)]);
|
|
233
|
-
} else if (msg.type === "done" || msg.type === "error") {
|
|
234
|
-
if (msg.type === "error") _optionalChain([callbacks, 'access', _15 => _15.onError, 'optionalCall', _16 => _16()]);
|
|
235
|
-
this.finalize(callbacks);
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
worker.postMessage({ type: "start", payload });
|
|
239
|
-
}
|
|
240
|
-
terminate() {
|
|
241
|
-
_optionalChain([this, 'access', _17 => _17.worker, 'optionalAccess', _18 => _18.terminate, 'call', _19 => _19()]);
|
|
242
|
-
this.worker = null;
|
|
243
|
-
}
|
|
244
|
-
isRunning() {
|
|
245
|
-
return this.worker !== null;
|
|
246
|
-
}
|
|
247
|
-
finalize(callbacks) {
|
|
248
|
-
if (this.finalized) return;
|
|
249
|
-
this.finalized = true;
|
|
250
|
-
const pending = [...this.pendingCallbacks];
|
|
251
|
-
Promise.allSettled(pending).then(() => {
|
|
252
|
-
this.terminate();
|
|
253
|
-
callbacks.onDone();
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
|
|
258
227
|
// src/core/manager.ts
|
|
259
|
-
var DB_NAME = "i18n_cache";
|
|
260
228
|
var PRIORITY_MODULES = ["ENUMS", "CUSTOMER"];
|
|
261
229
|
var currentLang = "zh_CN";
|
|
262
230
|
var currentSig = null;
|
|
@@ -301,7 +269,7 @@ async function initI18n(options) {
|
|
|
301
269
|
currentSig = sig;
|
|
302
270
|
initOptions = options;
|
|
303
271
|
const p = _initI18n(options).then(() => {
|
|
304
|
-
if (!options.apiContext.isLoggedIn
|
|
272
|
+
if (!options.apiContext.isLoggedIn) {
|
|
305
273
|
currentPromise = null;
|
|
306
274
|
}
|
|
307
275
|
}).catch((err) => {
|
|
@@ -345,7 +313,7 @@ async function getResource(moduleCode, langCode) {
|
|
|
345
313
|
const result = results[i];
|
|
346
314
|
if (result.status === "rejected") continue;
|
|
347
315
|
const record = result.value;
|
|
348
|
-
if (!_optionalChain([record, 'optionalAccess',
|
|
316
|
+
if (!_optionalChain([record, 'optionalAccess', _18 => _18.resources])) continue;
|
|
349
317
|
merged = i === 0 ? deepMerge(merged, record.resources) : deepMerge(merged, flatToNested(record.resources));
|
|
350
318
|
}
|
|
351
319
|
return merged;
|
|
@@ -362,11 +330,11 @@ async function getAllRecordsByModule(moduleCode) {
|
|
|
362
330
|
async function _initI18n(options) {
|
|
363
331
|
const { storage } = managerOptions;
|
|
364
332
|
const { apiContext } = options;
|
|
365
|
-
currentLang = options.
|
|
333
|
+
currentLang = options.langCode;
|
|
366
334
|
resolvedStores = options.stores;
|
|
367
|
-
resolvedLanguages = _nullishCoalesce(options.languages, () => ( [options.
|
|
335
|
+
resolvedLanguages = _nullishCoalesce(options.languages, () => ( [options.langCode]));
|
|
368
336
|
resolvedModules = _nullishCoalesce(options.modules, () => ( []));
|
|
369
|
-
await storage.
|
|
337
|
+
await storage.ensureStores(resolvedStores);
|
|
370
338
|
await checkCacheVersion(storage, options);
|
|
371
339
|
for (const lang of resolvedLanguages) {
|
|
372
340
|
for (const m of resolvedModules) {
|
|
@@ -375,7 +343,7 @@ async function _initI18n(options) {
|
|
|
375
343
|
}
|
|
376
344
|
await injectCurrentLanguageModules(currentLang);
|
|
377
345
|
await _i18next2.default.changeLanguage(currentLang);
|
|
378
|
-
if (!apiContext.isLoggedIn
|
|
346
|
+
if (!apiContext.isLoggedIn) {
|
|
379
347
|
if (!unloginPullStarted && apiContext.unloginPull) {
|
|
380
348
|
unloginPullStarted = true;
|
|
381
349
|
await doUnloginPull(storage, options);
|
|
@@ -394,41 +362,55 @@ async function _initI18n(options) {
|
|
|
394
362
|
startSSE(options);
|
|
395
363
|
}
|
|
396
364
|
}
|
|
365
|
+
var CACHE_VERSION_KEY = "__meta__:cache_version";
|
|
397
366
|
async function checkCacheVersion(storage, options) {
|
|
398
367
|
if (options.version == null) return;
|
|
368
|
+
const baseStoreName = resolvedStores[0].name;
|
|
399
369
|
const current = String(options.version);
|
|
400
|
-
const
|
|
370
|
+
const record = await storage.getRecord(baseStoreName, CACHE_VERSION_KEY).catch(() => void 0);
|
|
371
|
+
const stored = _optionalChain([record, 'optionalAccess', _19 => _19.resources, 'optionalAccess', _20 => _20["value"]]);
|
|
401
372
|
if (stored === current) return;
|
|
402
373
|
for (const store of options.stores) {
|
|
403
374
|
await storage.clearStore(store.name);
|
|
404
375
|
}
|
|
405
|
-
await storage.
|
|
376
|
+
await storage.putRecord(baseStoreName, {
|
|
377
|
+
key: CACHE_VERSION_KEY,
|
|
378
|
+
moduleCode: "__meta__",
|
|
379
|
+
langCode: "__meta__",
|
|
380
|
+
version: 0,
|
|
381
|
+
resources: { value: current }
|
|
382
|
+
});
|
|
406
383
|
}
|
|
407
384
|
async function doUnloginPull(storage, options) {
|
|
408
385
|
const { apiContext } = options;
|
|
409
386
|
if (!apiContext.unloginPull) return;
|
|
410
387
|
const baseStore = resolvedStores[0];
|
|
388
|
+
let blocks;
|
|
411
389
|
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
|
-
}
|
|
390
|
+
blocks = await doFetch(apiContext.unloginPull, options);
|
|
431
391
|
} catch (e4) {
|
|
392
|
+
await injectCurrentLanguageModules(currentLang);
|
|
393
|
+
await _i18next2.default.changeLanguage(currentLang);
|
|
394
|
+
emitI18nResourcesUpdated();
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
for (const block of blocks) {
|
|
398
|
+
for (const mod of _nullishCoalesce(block.modules, () => ( []))) {
|
|
399
|
+
const key = buildKey(mod.moduleCode, block.langCode, baseStore);
|
|
400
|
+
const existing = await storage.getRecord(baseStore.name, key);
|
|
401
|
+
const parsed = parseI18nValues(_nullishCoalesce(mod.i18nValues, () => ( [])));
|
|
402
|
+
const resources = deepMerge(
|
|
403
|
+
_nullishCoalesce(_optionalChain([existing, 'optionalAccess', _21 => _21.resources]), () => ( {})),
|
|
404
|
+
flatToNested(parsed)
|
|
405
|
+
);
|
|
406
|
+
await storage.putRecord(baseStore.name, {
|
|
407
|
+
key,
|
|
408
|
+
moduleCode: mod.moduleCode,
|
|
409
|
+
langCode: block.langCode,
|
|
410
|
+
version: _nullishCoalesce(mod.version, () => ( 0)),
|
|
411
|
+
resources
|
|
412
|
+
});
|
|
413
|
+
}
|
|
432
414
|
}
|
|
433
415
|
await injectCurrentLanguageModules(currentLang);
|
|
434
416
|
await _i18next2.default.changeLanguage(currentLang);
|
|
@@ -455,7 +437,7 @@ async function startWorkerFull(options) {
|
|
|
455
437
|
function runWorker(options, tasks, pull) {
|
|
456
438
|
return new Promise((resolve, reject) => {
|
|
457
439
|
const { apiContext } = options;
|
|
458
|
-
const
|
|
440
|
+
const storage = managerOptions.storage;
|
|
459
441
|
workerManager.start(
|
|
460
442
|
managerOptions.createWorker,
|
|
461
443
|
{
|
|
@@ -463,20 +445,45 @@ function runWorker(options, tasks, pull) {
|
|
|
463
445
|
headers: apiContext.getHeaders(),
|
|
464
446
|
pullPath: pull.path,
|
|
465
447
|
pullMethod: _nullishCoalesce(pull.method, () => ( "GET")),
|
|
466
|
-
|
|
467
|
-
tasks,
|
|
468
|
-
dbName: DB_NAME
|
|
448
|
+
tasks
|
|
469
449
|
},
|
|
470
450
|
{
|
|
471
|
-
|
|
472
|
-
|
|
451
|
+
onRawData: async (task, raw) => {
|
|
452
|
+
const blocks = pull.transform ? pull.transform(raw) : raw;
|
|
453
|
+
const store = resolvedStores.find((s) => s.name === task.storeName);
|
|
454
|
+
if (!store) return;
|
|
455
|
+
const storeIndex = resolvedStores.indexOf(store);
|
|
456
|
+
for (const block of blocks) {
|
|
457
|
+
for (const mod of _nullishCoalesce(block.modules, () => ( []))) {
|
|
458
|
+
const key = buildKey(mod.moduleCode, block.langCode, store);
|
|
459
|
+
const existing = await storage.getRecord(store.name, key);
|
|
460
|
+
if (existing && mod.version <= existing.version) continue;
|
|
461
|
+
const parsed = parseI18nValues(_nullishCoalesce(mod.i18nValues, () => ( [])));
|
|
462
|
+
const resources = storeIndex === 0 ? deepMerge(
|
|
463
|
+
_nullishCoalesce(_optionalChain([existing, 'optionalAccess', _22 => _22.resources]), () => ( {})),
|
|
464
|
+
flatToNested(parsed)
|
|
465
|
+
) : { ..._nullishCoalesce(_optionalChain([existing, 'optionalAccess', _23 => _23.resources]), () => ( {})), ...parsed };
|
|
466
|
+
await storage.putRecord(store.name, {
|
|
467
|
+
key,
|
|
468
|
+
moduleCode: mod.moduleCode,
|
|
469
|
+
langCode: block.langCode,
|
|
470
|
+
version: mod.version,
|
|
471
|
+
resources
|
|
472
|
+
});
|
|
473
|
+
await onModuleLoaded({
|
|
474
|
+
storeName: task.storeName,
|
|
475
|
+
langCode: block.langCode,
|
|
476
|
+
moduleCode: mod.moduleCode,
|
|
477
|
+
version: mod.version
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
}
|
|
473
481
|
},
|
|
474
482
|
onModuleError: (_data) => {
|
|
475
483
|
},
|
|
476
484
|
onDone: resolve,
|
|
477
485
|
onError: () => reject(new Error("[i18n] Worker fatal error"))
|
|
478
|
-
}
|
|
479
|
-
workerWritesDB ? void 0 : managerOptions.storage
|
|
486
|
+
}
|
|
480
487
|
);
|
|
481
488
|
});
|
|
482
489
|
}
|
|
@@ -493,7 +500,7 @@ async function injectFromDB(moduleCode, langCode) {
|
|
|
493
500
|
const store = resolvedStores[i];
|
|
494
501
|
const key = buildKey(moduleCode, langCode, store);
|
|
495
502
|
const record = await storage.getRecord(store.name, key);
|
|
496
|
-
if (!_optionalChain([record, 'optionalAccess',
|
|
503
|
+
if (!_optionalChain([record, 'optionalAccess', _24 => _24.resources])) continue;
|
|
497
504
|
if (i === 0) {
|
|
498
505
|
_i18next2.default.addResourceBundle(langCode, moduleCode, record.resources, true, true);
|
|
499
506
|
} else {
|
|
@@ -515,7 +522,7 @@ function startSSE(options) {
|
|
|
515
522
|
if (!apiContext.sse) return;
|
|
516
523
|
sseClient.start(
|
|
517
524
|
(raw) => {
|
|
518
|
-
const msg = _optionalChain([apiContext, 'access',
|
|
525
|
+
const msg = _optionalChain([apiContext, 'access', _25 => _25.sse, 'optionalAccess', _26 => _26.transformMessage]) ? apiContext.sse.transformMessage(raw) : raw;
|
|
519
526
|
void handleSSEMessage(msg, options);
|
|
520
527
|
},
|
|
521
528
|
{
|
|
@@ -600,16 +607,16 @@ async function pullAndStore(task, fromVersion, options) {
|
|
|
600
607
|
const storeIndex = resolvedStores.indexOf(store);
|
|
601
608
|
const key = buildKey(mod.moduleCode, block.langCode, store);
|
|
602
609
|
const existing = await storage.getRecord(store.name, key);
|
|
603
|
-
if (mod.version <= (_nullishCoalesce(_optionalChain([existing, 'optionalAccess',
|
|
610
|
+
if (mod.version <= (_nullishCoalesce(_optionalChain([existing, 'optionalAccess', _27 => _27.version]), () => ( 0)))) continue;
|
|
604
611
|
let resources;
|
|
605
612
|
const parsed = parseI18nValues(_nullishCoalesce(mod.i18nValues, () => ( [])));
|
|
606
613
|
if (storeIndex === 0) {
|
|
607
614
|
resources = deepMerge(
|
|
608
|
-
_nullishCoalesce(_optionalChain([existing, 'optionalAccess',
|
|
615
|
+
_nullishCoalesce(_optionalChain([existing, 'optionalAccess', _28 => _28.resources]), () => ( {})),
|
|
609
616
|
flatToNested(parsed)
|
|
610
617
|
);
|
|
611
618
|
} else {
|
|
612
|
-
resources = { ..._nullishCoalesce(_optionalChain([existing, 'optionalAccess',
|
|
619
|
+
resources = { ..._nullishCoalesce(_optionalChain([existing, 'optionalAccess', _29 => _29.resources]), () => ( {})), ...parsed };
|
|
613
620
|
}
|
|
614
621
|
const version = Math.max(mod.version, task.targetVersion);
|
|
615
622
|
await storage.putRecord(store.name, {
|
|
@@ -645,7 +652,7 @@ async function doFetch(config, options, internalParams) {
|
|
|
645
652
|
}
|
|
646
653
|
function buildSig(options) {
|
|
647
654
|
const cgKeys = options.stores.map((s) => _nullishCoalesce(s.cacheGroupKey, () => ( ""))).join(",");
|
|
648
|
-
return [options.apiContext.baseURL, options.
|
|
655
|
+
return [options.apiContext.baseURL, options.langCode, cgKeys].join("|");
|
|
649
656
|
}
|
|
650
657
|
function sortedModules() {
|
|
651
658
|
const priority = PRIORITY_MODULES.filter((m) => resolvedModules.includes(m));
|
|
@@ -653,13 +660,13 @@ function sortedModules() {
|
|
|
653
660
|
return [...priority, ...rest];
|
|
654
661
|
}
|
|
655
662
|
function getStaticLocale(moduleCode, langCode) {
|
|
656
|
-
return _nullishCoalesce(_optionalChain([initOptions, 'optionalAccess',
|
|
663
|
+
return _nullishCoalesce(_optionalChain([initOptions, 'optionalAccess', _30 => _30.staticLocales, 'optionalAccess', _31 => _31[langCode], 'optionalAccess', _32 => _32[moduleCode]]), () => ( {}));
|
|
657
664
|
}
|
|
658
665
|
async function getStoredVersion(store, moduleCode, langCode) {
|
|
659
666
|
const storage = managerOptions.storage;
|
|
660
667
|
const key = buildKey(moduleCode, langCode, store);
|
|
661
668
|
const record = await storage.getRecord(store.name, key);
|
|
662
|
-
return _nullishCoalesce(_optionalChain([record, 'optionalAccess',
|
|
669
|
+
return _nullishCoalesce(_optionalChain([record, 'optionalAccess', _33 => _33.version]), () => ( 0));
|
|
663
670
|
}
|
|
664
671
|
|
|
665
672
|
|