@rockster/core 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/translations/controllers/translation.controller.d.ts +3 -1
- package/translations/controllers/translation.controller.js +17 -3
- package/translations/controllers/translation.controller.js.map +1 -1
- package/translations/services/translations.service.d.ts +1 -0
- package/translations/services/translations.service.js +33 -12
- package/translations/services/translations.service.js.map +1 -1
- package/translations/services/translator.service.d.ts +1 -0
- package/translations/services/translator.service.js +6 -0
- package/translations/services/translator.service.js.map +1 -1
package/package.json
CHANGED
|
@@ -5,9 +5,11 @@ import { GetValuesRequest } from '../models/get-values.request';
|
|
|
5
5
|
import { GetValuesResponse } from '../models/get-values.response';
|
|
6
6
|
import { TranslationsService } from '../services/translations.service';
|
|
7
7
|
import { ITranslationValues } from '../interfaces/translation-values';
|
|
8
|
+
import { TranslatorService } from '../services/translator.service';
|
|
8
9
|
export declare class TranslationController {
|
|
9
10
|
protected readonly translationsService: TranslationsService;
|
|
10
|
-
|
|
11
|
+
protected readonly translatorService: TranslatorService;
|
|
12
|
+
constructor(translationsService: TranslationsService, translatorService: TranslatorService);
|
|
11
13
|
postConfig(content: IPostContent<TranslationConfig>): Promise<TranslationConfig>;
|
|
12
14
|
postValues(content: IPostContent<ITranslationValues>): Promise<ITranslationValues>;
|
|
13
15
|
queryConfig(content: IQueryContent<TranslationConfig>): Promise<import("../../query/interfaces").Query<TranslationConfig>>;
|
|
@@ -28,15 +28,28 @@ const post_action_decorator_1 = require("../../command/decorators/post-action.de
|
|
|
28
28
|
const post_content_decorator_1 = require("../../command/decorators/post-content.decorator");
|
|
29
29
|
const action_content_decorator_1 = require("../../controllers/decorators/actions/action-content.decorator");
|
|
30
30
|
const action_decorator_1 = require("../../controllers/decorators/actions/action.decorator");
|
|
31
|
+
const translator_service_1 = require("../services/translator.service");
|
|
31
32
|
let TranslationController = class TranslationController {
|
|
32
|
-
constructor(translationsService) {
|
|
33
|
+
constructor(translationsService, translatorService) {
|
|
33
34
|
this.translationsService = translationsService;
|
|
35
|
+
this.translatorService = translatorService;
|
|
34
36
|
}
|
|
35
37
|
async postConfig(content) {
|
|
36
38
|
return (0, execute_post_1.executePost)(content);
|
|
37
39
|
}
|
|
38
40
|
async postValues(content) {
|
|
39
|
-
|
|
41
|
+
const result = await (0, execute_post_1.executePost)(content);
|
|
42
|
+
const configId = result?.translationConfigId
|
|
43
|
+
?? content.data?.translationConfigId;
|
|
44
|
+
if (configId) {
|
|
45
|
+
const referenceId = await this
|
|
46
|
+
.translationsService
|
|
47
|
+
.getReferenceIdForConfig(configId);
|
|
48
|
+
if (referenceId) {
|
|
49
|
+
await this.translatorService.invalidateReference(referenceId);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
40
53
|
}
|
|
41
54
|
async queryConfig(content) {
|
|
42
55
|
return (0, execute_query_1.executeQuery)({ content: content });
|
|
@@ -98,6 +111,7 @@ __decorate([
|
|
|
98
111
|
], TranslationController.prototype, "getValues", null);
|
|
99
112
|
exports.TranslationController = TranslationController = __decorate([
|
|
100
113
|
(0, controller_decorator_1.Controller)(),
|
|
101
|
-
__metadata("design:paramtypes", [translations_service_1.TranslationsService
|
|
114
|
+
__metadata("design:paramtypes", [translations_service_1.TranslationsService,
|
|
115
|
+
translator_service_1.TranslatorService])
|
|
102
116
|
], TranslationController);
|
|
103
117
|
//# sourceMappingURL=translation.controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translation.controller.js","sourceRoot":"./","sources":["translations/controllers/translation.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,qFAA0E;AAC1E,uEAAmE;AACnE,kFAA6E;AAE7E,uDAAsD;AACtD,kFAA6E;AAC7E,uEAAmE;AACnE,qEAAgE;AAChE,uEAAkE;AAClE,2EAAuE;AAEvE,qFAA0E;AAC1E,4FAA+E;AAC/E,0FAA4E;AAC5E,4FAA8E;AAC9E,4GAA8F;AAC9F,4FAA+E;
|
|
1
|
+
{"version":3,"file":"translation.controller.js","sourceRoot":"./","sources":["translations/controllers/translation.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,qFAA0E;AAC1E,uEAAmE;AACnE,kFAA6E;AAE7E,uDAAsD;AACtD,kFAA6E;AAC7E,uEAAmE;AACnE,qEAAgE;AAChE,uEAAkE;AAClE,2EAAuE;AAEvE,qFAA0E;AAC1E,4FAA+E;AAC/E,0FAA4E;AAC5E,4FAA8E;AAC9E,4GAA8F;AAC9F,4FAA+E;AAC/E,uEAAmE;AAG5D,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAE/B,YACsB,mBAAwC,EACxC,iBAAoC;QADpC,wBAAmB,GAAnB,mBAAmB,CAAqB;QACxC,sBAAiB,GAAjB,iBAAiB,CAAmB;IACvD,CAAC;IAKE,AAAN,KAAK,CAAC,UAAU,CACE,OAAwC;QAEvD,OAAO,IAAA,0BAAW,EAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IAKK,AAAN,KAAK,CAAC,UAAU,CACE,OAAyC;QAExD,MAAM,MAAM,GAAG,MAAM,IAAA,0BAAW,EAAC,OAAO,CAAC,CAAC;QAC1C,MAAM,QAAQ,GAAI,MAA4B,EAAE,mBAAmB;eAC7D,OAAO,CAAC,IAAI,EAAE,mBAAmB,CAAC;QACxC,IAAI,QAAQ,EAAE,CAAC;YACZ,MAAM,WAAW,GAAG,MAAM,IAAI;iBAC1B,mBAAmB;iBACnB,uBAAuB,CAAC,QAAQ,CAAC,CAAC;YACtC,IAAI,WAAW,EAAE,CAAC;gBACf,MAAM,IAAI,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;YACjE,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC;IACjB,CAAC;IAGK,AAAN,KAAK,CAAC,WAAW,CACE,OAAyC;QAEzD,OAAO,IAAA,4BAAY,EAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;IAC7C,CAAC;IAGK,AAAN,KAAK,CAAC,WAAW,CACE,OAAyC;QAEzD,OAAO,IAAA,4BAAY,EAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;IAC7C,CAAC;IAMK,AAAN,KAAK,CAAC,SAAS,CACK,OAAyB;QAE1C,MAAM,MAAM,GAAG,MAAM,IAAI;aACrB,mBAAmB;aACnB,SAAS,CACP,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,MAAM,CAChB,CAAC;QAEL,OAAO;YACJ,MAAM,EAAE,MAAM;SACK,CAAC;IAC1B,CAAC;CACH,CAAA;AApEY,sDAAqB;AAUzB;IAHL,IAAA,kCAAU,EAAC;QACT,IAAI,EAAE,GAAG,EAAE,CAAC,6CAAiB;KAC/B,CAAC;IAEE,WAAA,IAAA,oCAAW,GAAE,CAAA;;;;uDAGhB;AAKK;IAHL,IAAA,kCAAU,EAAC;QACT,IAAI,EAAE,GAAG,EAAE,CAAC,6CAAiB;KAC/B,CAAC;IAEE,WAAA,IAAA,oCAAW,GAAE,CAAA;;;;uDAchB;AAGK;IADL,IAAA,iDAAsB,GAAE;IAErB,WAAA,IAAA,yBAAY,GAAE,CAAA;;;;wDAGjB;AAGK;IADL,IAAA,iDAAsB,GAAE;IAErB,WAAA,IAAA,yBAAY,GAAE,CAAA;;;;wDAGjB;AAMK;IAJL,IAAA,yBAAM,EAAC;QACL,QAAQ,EAAE,GAAG,EAAE,CAAC,uCAAiB;QACjC,MAAM,EAAE,IAAI;KACd,CAAC;IAEE,WAAA,IAAA,wCAAa,GAAE,CAAA;;qCAAU,qCAAgB;;sDAY5C;gCAnES,qBAAqB;IADjC,IAAA,iCAAU,GAAE;qCAIiC,0CAAmB;QACrB,sCAAiB;GAJhD,qBAAqB,CAoEjC"}
|
|
@@ -18,29 +18,50 @@ const typeorm_1 = require("typeorm");
|
|
|
18
18
|
const cache_1 = require("../../cache");
|
|
19
19
|
let TranslationsService = class TranslationsService {
|
|
20
20
|
async getValues(referenceId, locale) {
|
|
21
|
+
const config = await this
|
|
22
|
+
.repository
|
|
23
|
+
.manager
|
|
24
|
+
.getRepository(translation_config_entity_1.TranslationConfig)
|
|
25
|
+
.findOne({
|
|
26
|
+
where: { referenceId },
|
|
27
|
+
select: ['id', 'default']
|
|
28
|
+
});
|
|
29
|
+
if (!config) {
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
21
32
|
const values = await this
|
|
22
33
|
.repository
|
|
23
34
|
.createQueryBuilder('translationValues')
|
|
24
|
-
.
|
|
25
|
-
.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
.where('translationValues.translation_config_id = :configId', {
|
|
36
|
+
configId: config.id
|
|
37
|
+
})
|
|
38
|
+
.andWhere('(translationValues.locale = :locale OR translationValues.locale = :defaultLocale)', {
|
|
39
|
+
locale,
|
|
40
|
+
defaultLocale: config.default
|
|
41
|
+
})
|
|
30
42
|
.getMany();
|
|
31
43
|
const _default = values
|
|
32
|
-
.find((value) =>
|
|
33
|
-
|
|
34
|
-
}) || { values: {} };
|
|
44
|
+
.find((value) => value.locale === config.default)
|
|
45
|
+
|| { values: {} };
|
|
35
46
|
const _requested = values
|
|
36
|
-
.find((value) =>
|
|
37
|
-
|
|
38
|
-
}) || { values: {} };
|
|
47
|
+
.find((value) => value.locale === locale)
|
|
48
|
+
|| { values: {} };
|
|
39
49
|
return {
|
|
40
50
|
..._default.values,
|
|
41
51
|
..._requested.values
|
|
42
52
|
};
|
|
43
53
|
}
|
|
54
|
+
async getReferenceIdForConfig(translationConfigId) {
|
|
55
|
+
const config = await this
|
|
56
|
+
.repository
|
|
57
|
+
.manager
|
|
58
|
+
.getRepository(translation_config_entity_1.TranslationConfig)
|
|
59
|
+
.findOne({
|
|
60
|
+
where: { id: translationConfigId },
|
|
61
|
+
select: ['referenceId']
|
|
62
|
+
});
|
|
63
|
+
return config?.referenceId ?? null;
|
|
64
|
+
}
|
|
44
65
|
};
|
|
45
66
|
exports.TranslationsService = TranslationsService;
|
|
46
67
|
__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translations.service.js","sourceRoot":"./","sources":["translations/services/translations.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6DAAsD;AAEtD,qFAA0E;AAC1E,qFAA0E;AAC1E,6CAAkD;AAClD,
|
|
1
|
+
{"version":3,"file":"translations.service.js","sourceRoot":"./","sources":["translations/services/translations.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6DAAsD;AAEtD,qFAA0E;AAC1E,qFAA0E;AAC1E,6CAAkD;AAClD,qCAAqC;AACrC,uCAGqB;AAGd,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAS7B,KAAK,CAAC,SAAS,CACZ,WAAmB,EACnB,MAAc;QAEd,MAAM,MAAM,GAAG,MAAM,IAAI;aACrB,UAAU;aACV,OAAO;aACP,aAAa,CAAC,6CAAiB,CAAC;aAChC,OAAO,CAAC;YACN,KAAK,EAAE,EAAE,WAAW,EAAE;YACtB,MAAM,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC;SAC3B,CAAC,CAAC;QAEN,IAAI,CAAC,MAAM,EAAE,CAAC;YACX,OAAO,EAAE,CAAC;QACb,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI;aACrB,UAAU;aACV,kBAAkB,CAAC,mBAAmB,CAAC;aACvC,KAAK,CAAC,qDAAqD,EAAE;YAC3D,QAAQ,EAAE,MAAM,CAAC,EAAE;SACrB,CAAC;aACD,QAAQ,CACN,mFAAmF,EACnF;YACG,MAAM;YACN,aAAa,EAAE,MAAM,CAAC,OAAO;SAC/B,CACH;aACA,OAAO,EAAE,CAAC;QAEd,MAAM,QAAQ,GAAG,MAAM;aACnB,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,OAAO,CAAC;eAC9C,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;QACrB,MAAM,UAAU,GAAG,MAAM;aACrB,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC;eACtC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;QACrB,OAAO;YACJ,GAAG,QAAQ,CAAC,MAAM;YAClB,GAAG,UAAU,CAAC,MAAM;SACtB,CAAC;IACL,CAAC;IAED,KAAK,CAAC,uBAAuB,CAC1B,mBAA2B;QAE3B,MAAM,MAAM,GAAG,MAAM,IAAI;aACrB,UAAU;aACV,OAAO;aACP,aAAa,CAAC,6CAAiB,CAAC;aAChC,OAAO,CAAC;YACN,KAAK,EAAE,EAAE,EAAE,EAAE,mBAAmB,EAAE;YAClC,MAAM,EAAE,CAAC,aAAa,CAAC;SACzB,CAAC,CAAC;QACN,OAAO,MAAM,EAAE,WAAW,IAAI,IAAI,CAAC;IACtC,CAAC;CACH,CAAA;AAlEY,kDAAmB;AAGnB;IADT,IAAA,2BAAgB,EAAC,GAAG,EAAE,CAAC,6CAAiB,CAAC;8BACpB,oBAAU;uDAAoB;AAG1C;IADT,IAAA,mBAAW,GAAE;;kDACiB;8BANrB,mBAAmB;IAD/B,IAAA,2BAAU,GAAE;GACA,mBAAmB,CAkE/B"}
|
|
@@ -7,5 +7,6 @@ export declare class TranslatorService {
|
|
|
7
7
|
protected cache: CacheClient;
|
|
8
8
|
constructor(translationsService: TranslationsService);
|
|
9
9
|
useValues(referenceId: string, locale: Locale): Promise<TranslatorHandle>;
|
|
10
|
+
invalidateReference(referenceId: string): Promise<void>;
|
|
10
11
|
protected getHandle(values: Dictionary<string>): TranslatorHandle;
|
|
11
12
|
}
|
|
@@ -33,6 +33,12 @@ let TranslatorService = class TranslatorService {
|
|
|
33
33
|
await this.cache.expire(key, env_1.env.cacheTTL);
|
|
34
34
|
return this.getHandle(values);
|
|
35
35
|
}
|
|
36
|
+
async invalidateReference(referenceId) {
|
|
37
|
+
const keys = await this.cache.keys(`translations:${referenceId}:*`);
|
|
38
|
+
for (const key of keys) {
|
|
39
|
+
await this.cache.del(key);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
36
42
|
getHandle(values) {
|
|
37
43
|
return (key, replaces = {}) => {
|
|
38
44
|
let value = values[key] || key;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translator.service.js","sourceRoot":"./","sources":["translations/services/translator.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6DAAsD;AACtD,iEAA6D;AAC7D,uCAGqB;AAOrB,gCAA6B;AAGtB,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAK3B,YACa,mBAAwC;QAAxC,wBAAmB,GAAnB,mBAAmB,CAAqB;IAClD,CAAC;IAEJ,KAAK,CAAC,SAAS,CACZ,WAAmB,EACnB,MAAc;QAGd,MAAM,GAAG,GAAG,gBAAgB,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QACvE,MAAM,MAAM,GAAG,MAAM,IAAI;aACrB,KAAK;aACL,GAAG,CAAC,GAAG,CAAC,CAAC;QAEb,IAAI,MAAM,EAAE,CAAC;YACV,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QAC7C,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI;aACrB,mBAAmB;aACnB,SAAS,CACP,WAAW,EACX,MAAM,CACR,CAAC;QAGL,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;QAClD,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,SAAG,CAAC,QAAQ,CAAC,CAAC;QAE3C,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAES,SAAS,CAAC,MAA0B;QAC3C,OAAO,CAAC,GAAW,EAAE,WAA+B,EAAE,EAAE,EAAE;YACvD,IAAI,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;YAC/B,MAAM;iBACF,mBAAmB,CAAC,QAAQ,CAAC;iBAC7B,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;gBAClB,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5D,CAAC,CAAC,CAAC;YACN,OAAO,KAAK,CAAC;QAChB,CAAC,CAAA;IACJ,CAAC;CACH,CAAA;
|
|
1
|
+
{"version":3,"file":"translator.service.js","sourceRoot":"./","sources":["translations/services/translator.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6DAAsD;AACtD,iEAA6D;AAC7D,uCAGqB;AAOrB,gCAA6B;AAGtB,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAK3B,YACa,mBAAwC;QAAxC,wBAAmB,GAAnB,mBAAmB,CAAqB;IAClD,CAAC;IAEJ,KAAK,CAAC,SAAS,CACZ,WAAmB,EACnB,MAAc;QAGd,MAAM,GAAG,GAAG,gBAAgB,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QACvE,MAAM,MAAM,GAAG,MAAM,IAAI;aACrB,KAAK;aACL,GAAG,CAAC,GAAG,CAAC,CAAC;QAEb,IAAI,MAAM,EAAE,CAAC;YACV,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QAC7C,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI;aACrB,mBAAmB;aACnB,SAAS,CACP,WAAW,EACX,MAAM,CACR,CAAC;QAGL,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;QAClD,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,SAAG,CAAC,QAAQ,CAAC,CAAC;QAE3C,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,WAAmB;QAC1C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,WAAW,IAAI,CAAC,CAAC;QACpE,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACtB,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC7B,CAAC;IACJ,CAAC;IAES,SAAS,CAAC,MAA0B;QAC3C,OAAO,CAAC,GAAW,EAAE,WAA+B,EAAE,EAAE,EAAE;YACvD,IAAI,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;YAC/B,MAAM;iBACF,mBAAmB,CAAC,QAAQ,CAAC;iBAC7B,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;gBAClB,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5D,CAAC,CAAC,CAAC;YACN,OAAO,KAAK,CAAC;QAChB,CAAC,CAAA;IACJ,CAAC;CACH,CAAA;AAvDY,8CAAiB;AAGjB;IADT,IAAA,mBAAW,GAAE;;gDACe;4BAHnB,iBAAiB;IAD7B,IAAA,2BAAU,GAAE;qCAOwB,0CAAmB;GAN3C,iBAAiB,CAuD7B"}
|