@flusys/nestjs-localization 7.0.2 → 8.0.0-beta.1
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/config/index.d.ts +3 -3
- package/controllers/index.d.ts +3 -3
- package/controllers/language.controller.d.ts +4 -4
- package/controllers/translation-key.controller.d.ts +3 -3
- package/controllers/translation.controller.d.ts +4 -4
- package/docs/index.d.ts +1 -1
- package/docs/localization-swagger.config.d.ts +1 -1
- package/dtos/index.d.ts +3 -3
- package/dtos/translation.dto.d.ts +2 -2
- package/entities/index.d.ts +6 -6
- package/entities/language.entity.d.ts +1 -1
- package/entities/translation-key.entity.d.ts +1 -1
- package/entities/translation.entity.d.ts +2 -2
- package/fesm/349.js +1179 -0
- package/fesm/692.js +1205 -0
- package/fesm/config/index.js +101 -3
- package/fesm/controllers/index.js +15 -3
- package/fesm/docs/index.js +126 -1
- package/fesm/dtos/index.js +680 -3
- package/fesm/entities/index.js +405 -8
- package/fesm/index.js +257 -7
- package/fesm/interfaces/index.js +18 -4
- package/fesm/modules/index.js +152 -1
- package/fesm/runtime.js +85 -0
- package/fesm/services/index.js +15 -5
- package/index.d.ts +7 -7
- package/interfaces/index.d.ts +4 -4
- package/interfaces/language.interface.d.ts +1 -1
- package/interfaces/localization-module-options.interface.d.ts +3 -3
- package/interfaces/translation-key.interface.d.ts +1 -1
- package/interfaces/translation.interface.d.ts +3 -3
- package/modules/index.d.ts +1 -1
- package/modules/localization.module.d.ts +2 -2
- package/package.json +25 -34
- package/services/index.d.ts +5 -5
- package/services/language.service.d.ts +6 -6
- package/services/localization-config.service.d.ts +3 -3
- package/services/localization-datasource.provider.d.ts +3 -3
- package/services/translation-key.service.d.ts +6 -6
- package/services/translation.service.d.ts +5 -5
- package/cjs/config/event-actions.js +0 -33
- package/cjs/config/index.js +0 -20
- package/cjs/config/localization.constants.js +0 -11
- package/cjs/config/message-keys.js +0 -41
- package/cjs/controllers/index.js +0 -20
- package/cjs/controllers/language.controller.js +0 -188
- package/cjs/controllers/language.controller.spec.js +0 -154
- package/cjs/controllers/translation-key.controller.js +0 -135
- package/cjs/controllers/translation-key.controller.spec.js +0 -70
- package/cjs/controllers/translation.controller.js +0 -195
- package/cjs/controllers/translation.controller.spec.js +0 -169
- package/cjs/docs/index.js +0 -11
- package/cjs/docs/localization-swagger.config.js +0 -111
- package/cjs/docs/localization-swagger.config.spec.js +0 -30
- package/cjs/dtos/index.js +0 -20
- package/cjs/dtos/language.dto.js +0 -213
- package/cjs/dtos/translation-key.dto.js +0 -215
- package/cjs/dtos/translation.dto.js +0 -269
- package/cjs/entities/index.js +0 -42
- package/cjs/entities/index.spec.js +0 -18
- package/cjs/entities/language.entity.js +0 -126
- package/cjs/entities/translation-key.entity.js +0 -126
- package/cjs/entities/translation.entity.js +0 -120
- package/cjs/index.js +0 -24
- package/cjs/interfaces/index.js +0 -21
- package/cjs/interfaces/language.interface.js +0 -4
- package/cjs/interfaces/localization-module-options.interface.js +0 -4
- package/cjs/interfaces/translation-key.interface.js +0 -4
- package/cjs/interfaces/translation.interface.js +0 -4
- package/cjs/modules/index.js +0 -18
- package/cjs/modules/localization.module.js +0 -116
- package/cjs/modules/localization.module.spec.js +0 -132
- package/cjs/services/index.js +0 -22
- package/cjs/services/language.service.js +0 -181
- package/cjs/services/language.service.spec.js +0 -256
- package/cjs/services/localization-config.service.js +0 -66
- package/cjs/services/localization-config.service.spec.js +0 -80
- package/cjs/services/localization-datasource.provider.js +0 -79
- package/cjs/services/localization-datasource.provider.spec.js +0 -85
- package/cjs/services/translation-key.service.js +0 -179
- package/cjs/services/translation-key.service.spec.js +0 -303
- package/cjs/services/translation.service.js +0 -228
- package/cjs/services/translation.service.spec.js +0 -530
- package/fesm/config/event-actions.js +0 -12
- package/fesm/config/localization.constants.js +0 -1
- package/fesm/config/message-keys.js +0 -20
- package/fesm/controllers/language.controller.js +0 -178
- package/fesm/controllers/language.controller.spec.js +0 -150
- package/fesm/controllers/translation-key.controller.js +0 -125
- package/fesm/controllers/translation-key.controller.spec.js +0 -66
- package/fesm/controllers/translation.controller.js +0 -185
- package/fesm/controllers/translation.controller.spec.js +0 -165
- package/fesm/docs/localization-swagger.config.js +0 -101
- package/fesm/docs/localization-swagger.config.spec.js +0 -26
- package/fesm/dtos/language.dto.js +0 -192
- package/fesm/dtos/translation-key.dto.js +0 -194
- package/fesm/dtos/translation.dto.js +0 -239
- package/fesm/entities/index.spec.js +0 -14
- package/fesm/entities/language.entity.js +0 -116
- package/fesm/entities/translation-key.entity.js +0 -116
- package/fesm/entities/translation.entity.js +0 -110
- package/fesm/interfaces/language.interface.js +0 -1
- package/fesm/interfaces/localization-module-options.interface.js +0 -1
- package/fesm/interfaces/translation-key.interface.js +0 -1
- package/fesm/interfaces/translation.interface.js +0 -1
- package/fesm/modules/localization.module.js +0 -106
- package/fesm/modules/localization.module.spec.js +0 -128
- package/fesm/services/language.service.js +0 -171
- package/fesm/services/language.service.spec.js +0 -252
- package/fesm/services/localization-config.service.js +0 -56
- package/fesm/services/localization-config.service.spec.js +0 -76
- package/fesm/services/localization-datasource.provider.js +0 -69
- package/fesm/services/localization-datasource.provider.spec.js +0 -81
- package/fesm/services/translation-key.service.js +0 -169
- package/fesm/services/translation-key.service.spec.js +0 -299
- package/fesm/services/translation.service.js +0 -218
- package/fesm/services/translation.service.spec.js +0 -526
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
15
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
18
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
-
}
|
|
20
|
-
function _ts_metadata(k, v) {
|
|
21
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
-
}
|
|
23
|
-
import { Identity } from '@flusys/nestjs-shared/entities';
|
|
24
|
-
import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm';
|
|
25
|
-
import { Language } from './language.entity';
|
|
26
|
-
import { TranslationKey } from './translation-key.entity';
|
|
27
|
-
export class Translation extends Identity {
|
|
28
|
-
constructor(...args){
|
|
29
|
-
super(...args), _define_property(this, "languageId", void 0), _define_property(this, "translationKeyId", void 0), _define_property(this, "value", void 0), _define_property(this, "isVerified", void 0), _define_property(this, "isActive", void 0), _define_property(this, "language", void 0), _define_property(this, "translationKey", void 0);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
_ts_decorate([
|
|
33
|
-
Column({
|
|
34
|
-
type: 'uuid',
|
|
35
|
-
name: 'language_id',
|
|
36
|
-
nullable: false
|
|
37
|
-
}),
|
|
38
|
-
_ts_metadata("design:type", String)
|
|
39
|
-
], Translation.prototype, "languageId", void 0);
|
|
40
|
-
_ts_decorate([
|
|
41
|
-
Column({
|
|
42
|
-
type: 'uuid',
|
|
43
|
-
name: 'translation_key_id',
|
|
44
|
-
nullable: false
|
|
45
|
-
}),
|
|
46
|
-
_ts_metadata("design:type", String)
|
|
47
|
-
], Translation.prototype, "translationKeyId", void 0);
|
|
48
|
-
_ts_decorate([
|
|
49
|
-
Column({
|
|
50
|
-
type: 'text',
|
|
51
|
-
nullable: false
|
|
52
|
-
}),
|
|
53
|
-
_ts_metadata("design:type", String)
|
|
54
|
-
], Translation.prototype, "value", void 0);
|
|
55
|
-
_ts_decorate([
|
|
56
|
-
Column({
|
|
57
|
-
type: 'boolean',
|
|
58
|
-
default: false,
|
|
59
|
-
name: 'is_verified'
|
|
60
|
-
}),
|
|
61
|
-
_ts_metadata("design:type", Boolean)
|
|
62
|
-
], Translation.prototype, "isVerified", void 0);
|
|
63
|
-
_ts_decorate([
|
|
64
|
-
Column({
|
|
65
|
-
type: 'boolean',
|
|
66
|
-
default: true,
|
|
67
|
-
name: 'is_active'
|
|
68
|
-
}),
|
|
69
|
-
_ts_metadata("design:type", Boolean)
|
|
70
|
-
], Translation.prototype, "isActive", void 0);
|
|
71
|
-
_ts_decorate([
|
|
72
|
-
ManyToOne(()=>Language, {
|
|
73
|
-
nullable: false,
|
|
74
|
-
onDelete: 'CASCADE'
|
|
75
|
-
}),
|
|
76
|
-
JoinColumn({
|
|
77
|
-
name: 'language_id'
|
|
78
|
-
}),
|
|
79
|
-
_ts_metadata("design:type", typeof Language === "undefined" ? Object : Language)
|
|
80
|
-
], Translation.prototype, "language", void 0);
|
|
81
|
-
_ts_decorate([
|
|
82
|
-
ManyToOne(()=>TranslationKey, {
|
|
83
|
-
nullable: false,
|
|
84
|
-
onDelete: 'CASCADE'
|
|
85
|
-
}),
|
|
86
|
-
JoinColumn({
|
|
87
|
-
name: 'translation_key_id'
|
|
88
|
-
}),
|
|
89
|
-
_ts_metadata("design:type", typeof TranslationKey === "undefined" ? Object : TranslationKey)
|
|
90
|
-
], Translation.prototype, "translationKey", void 0);
|
|
91
|
-
Translation = _ts_decorate([
|
|
92
|
-
Entity({
|
|
93
|
-
name: 'translation'
|
|
94
|
-
}),
|
|
95
|
-
Index([
|
|
96
|
-
'languageId',
|
|
97
|
-
'translationKeyId'
|
|
98
|
-
], {
|
|
99
|
-
unique: true
|
|
100
|
-
}),
|
|
101
|
-
Index([
|
|
102
|
-
'languageId'
|
|
103
|
-
]),
|
|
104
|
-
Index([
|
|
105
|
-
'translationKeyId'
|
|
106
|
-
]),
|
|
107
|
-
Index([
|
|
108
|
-
'isActive'
|
|
109
|
-
])
|
|
110
|
-
], Translation);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
|
-
import { CacheModule, UtilsModule, createModuleEventsProvider } from '@flusys/nestjs-shared/modules';
|
|
8
|
-
import { Module } from '@nestjs/common';
|
|
9
|
-
import { LOCALIZATION_MODULE_OPTIONS } from '../config/localization.constants';
|
|
10
|
-
import { LanguageController, TranslationKeyController, TranslationController } from '../controllers';
|
|
11
|
-
import { LanguageService, LocalizationConfigService, LocalizationDataSourceProvider, TranslationKeyService, TranslationService } from '../services';
|
|
12
|
-
const CONTROLLERS = [
|
|
13
|
-
LanguageController,
|
|
14
|
-
TranslationKeyController,
|
|
15
|
-
TranslationController
|
|
16
|
-
];
|
|
17
|
-
const EXPORTED_SERVICES = [
|
|
18
|
-
LocalizationConfigService,
|
|
19
|
-
LocalizationDataSourceProvider,
|
|
20
|
-
LanguageService,
|
|
21
|
-
TranslationKeyService,
|
|
22
|
-
TranslationService
|
|
23
|
-
];
|
|
24
|
-
export class LocalizationModule {
|
|
25
|
-
static forRoot(options) {
|
|
26
|
-
return {
|
|
27
|
-
module: LocalizationModule,
|
|
28
|
-
global: options.global ?? false,
|
|
29
|
-
imports: [
|
|
30
|
-
CacheModule,
|
|
31
|
-
UtilsModule
|
|
32
|
-
],
|
|
33
|
-
controllers: options.includeController !== false ? CONTROLLERS : [],
|
|
34
|
-
providers: this.buildProviders(options),
|
|
35
|
-
exports: EXPORTED_SERVICES
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
static forRootAsync(options) {
|
|
39
|
-
return {
|
|
40
|
-
module: LocalizationModule,
|
|
41
|
-
global: options.global ?? false,
|
|
42
|
-
imports: [
|
|
43
|
-
...options.imports || [],
|
|
44
|
-
CacheModule,
|
|
45
|
-
UtilsModule
|
|
46
|
-
],
|
|
47
|
-
controllers: options.includeController !== false ? CONTROLLERS : [],
|
|
48
|
-
providers: [
|
|
49
|
-
...this.createAsyncProviders(options),
|
|
50
|
-
...this.buildProviders()
|
|
51
|
-
],
|
|
52
|
-
exports: EXPORTED_SERVICES
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
static buildProviders(options) {
|
|
56
|
-
const providers = [
|
|
57
|
-
...EXPORTED_SERVICES
|
|
58
|
-
];
|
|
59
|
-
if (options) {
|
|
60
|
-
providers.unshift({
|
|
61
|
-
provide: LOCALIZATION_MODULE_OPTIONS,
|
|
62
|
-
useValue: options
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
providers.push(createModuleEventsProvider('localization', LOCALIZATION_MODULE_OPTIONS));
|
|
66
|
-
return providers;
|
|
67
|
-
}
|
|
68
|
-
static createAsyncProviders(options) {
|
|
69
|
-
if (options.useFactory) {
|
|
70
|
-
return [
|
|
71
|
-
{
|
|
72
|
-
provide: LOCALIZATION_MODULE_OPTIONS,
|
|
73
|
-
useFactory: async (...args)=>({
|
|
74
|
-
...options,
|
|
75
|
-
config: await options.useFactory(...args)
|
|
76
|
-
}),
|
|
77
|
-
inject: options.inject || []
|
|
78
|
-
}
|
|
79
|
-
];
|
|
80
|
-
}
|
|
81
|
-
const factoryClass = options.useClass || options.useExisting;
|
|
82
|
-
if (!factoryClass) return [];
|
|
83
|
-
const providers = [
|
|
84
|
-
{
|
|
85
|
-
provide: LOCALIZATION_MODULE_OPTIONS,
|
|
86
|
-
useFactory: async (factory)=>({
|
|
87
|
-
...options,
|
|
88
|
-
config: await factory.createLocalizationOptions()
|
|
89
|
-
}),
|
|
90
|
-
inject: [
|
|
91
|
-
factoryClass
|
|
92
|
-
]
|
|
93
|
-
}
|
|
94
|
-
];
|
|
95
|
-
if (options.useClass) {
|
|
96
|
-
providers.push({
|
|
97
|
-
provide: options.useClass,
|
|
98
|
-
useClass: options.useClass
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
return providers;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
LocalizationModule = _ts_decorate([
|
|
105
|
-
Module({})
|
|
106
|
-
], LocalizationModule);
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
import { LocalizationModule } from './localization.module';
|
|
15
|
-
import { LOCALIZATION_MODULE_OPTIONS } from '../config/localization.constants';
|
|
16
|
-
import { LanguageController, TranslationKeyController, TranslationController } from '../controllers';
|
|
17
|
-
function providerTokens(providers) {
|
|
18
|
-
return providers.map((p)=>typeof p === 'function' ? p : p.provide);
|
|
19
|
-
}
|
|
20
|
-
describe('LocalizationModule', ()=>{
|
|
21
|
-
describe('forRoot', ()=>{
|
|
22
|
-
it('should default to a non-global module with all controllers registered', ()=>{
|
|
23
|
-
const dynamicModule = LocalizationModule.forRoot({});
|
|
24
|
-
expect(dynamicModule.module).toBe(LocalizationModule);
|
|
25
|
-
expect(dynamicModule.global).toBe(false);
|
|
26
|
-
expect(dynamicModule.controllers).toEqual([
|
|
27
|
-
LanguageController,
|
|
28
|
-
TranslationKeyController,
|
|
29
|
-
TranslationController
|
|
30
|
-
]);
|
|
31
|
-
});
|
|
32
|
-
it('should respect global: true', ()=>{
|
|
33
|
-
expect(LocalizationModule.forRoot({
|
|
34
|
-
global: true
|
|
35
|
-
}).global).toBe(true);
|
|
36
|
-
});
|
|
37
|
-
it('should register no controllers when includeController is false', ()=>{
|
|
38
|
-
expect(LocalizationModule.forRoot({
|
|
39
|
-
includeController: false
|
|
40
|
-
}).controllers).toEqual([]);
|
|
41
|
-
});
|
|
42
|
-
it('should register a LOCALIZATION_MODULE_OPTIONS provider carrying the given options', ()=>{
|
|
43
|
-
const options = {
|
|
44
|
-
bootstrapAppConfig: {}
|
|
45
|
-
};
|
|
46
|
-
const dynamicModule = LocalizationModule.forRoot(options);
|
|
47
|
-
const provider = dynamicModule.providers.find((p)=>p.provide === LOCALIZATION_MODULE_OPTIONS);
|
|
48
|
-
expect(provider.useValue).toBe(options);
|
|
49
|
-
});
|
|
50
|
-
it('should always export the same fixed set of services', ()=>{
|
|
51
|
-
expect(LocalizationModule.forRoot({}).exports).toHaveLength(5);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
describe('forRootAsync', ()=>{
|
|
55
|
-
it('should forward external imports alongside CacheModule/UtilsModule', ()=>{
|
|
56
|
-
let FakeImportedModule = class FakeImportedModule {
|
|
57
|
-
};
|
|
58
|
-
const dynamicModule = LocalizationModule.forRootAsync({
|
|
59
|
-
imports: [
|
|
60
|
-
FakeImportedModule
|
|
61
|
-
]
|
|
62
|
-
});
|
|
63
|
-
expect(dynamicModule.imports).toEqual(expect.arrayContaining([
|
|
64
|
-
FakeImportedModule
|
|
65
|
-
]));
|
|
66
|
-
});
|
|
67
|
-
it('useFactory: builds a LOCALIZATION_MODULE_OPTIONS provider merging resolved config', async ()=>{
|
|
68
|
-
const useFactory = jest.fn().mockResolvedValue({
|
|
69
|
-
foo: 'bar'
|
|
70
|
-
});
|
|
71
|
-
const dynamicModule = LocalizationModule.forRootAsync({
|
|
72
|
-
useFactory,
|
|
73
|
-
inject: [
|
|
74
|
-
'SOME_TOKEN'
|
|
75
|
-
]
|
|
76
|
-
});
|
|
77
|
-
const provider = dynamicModule.providers.find((p)=>p.provide === LOCALIZATION_MODULE_OPTIONS);
|
|
78
|
-
expect(provider.inject).toEqual([
|
|
79
|
-
'SOME_TOKEN'
|
|
80
|
-
]);
|
|
81
|
-
const resolved = await provider.useFactory('injected');
|
|
82
|
-
expect(useFactory).toHaveBeenCalledWith('injected');
|
|
83
|
-
expect(resolved.config).toEqual({
|
|
84
|
-
foo: 'bar'
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
it('useClass: registers both the class provider and an options provider calling createLocalizationOptions()', async ()=>{
|
|
88
|
-
let MyOptionsFactory = class MyOptionsFactory {
|
|
89
|
-
constructor(){
|
|
90
|
-
_define_property(this, "createLocalizationOptions", jest.fn().mockResolvedValue({
|
|
91
|
-
foo: 'from-class'
|
|
92
|
-
}));
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
const dynamicModule = LocalizationModule.forRootAsync({
|
|
96
|
-
useClass: MyOptionsFactory
|
|
97
|
-
});
|
|
98
|
-
const classProvider = dynamicModule.providers.find((p)=>p.provide === MyOptionsFactory);
|
|
99
|
-
expect(classProvider.useClass).toBe(MyOptionsFactory);
|
|
100
|
-
const optionsProvider = dynamicModule.providers.find((p)=>p.provide === LOCALIZATION_MODULE_OPTIONS);
|
|
101
|
-
const instance = new MyOptionsFactory();
|
|
102
|
-
const resolved = await optionsProvider.useFactory(instance);
|
|
103
|
-
expect(instance.createLocalizationOptions).toHaveBeenCalled();
|
|
104
|
-
expect(resolved.config).toEqual({
|
|
105
|
-
foo: 'from-class'
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
it('useExisting: registers a single options provider without a duplicate class registration', ()=>{
|
|
109
|
-
let MyOptionsFactory = class MyOptionsFactory {
|
|
110
|
-
constructor(){
|
|
111
|
-
_define_property(this, "createLocalizationOptions", jest.fn());
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
const dynamicModule = LocalizationModule.forRootAsync({
|
|
115
|
-
useExisting: MyOptionsFactory
|
|
116
|
-
});
|
|
117
|
-
expect(dynamicModule.providers.filter((p)=>p.provide === MyOptionsFactory)).toHaveLength(0);
|
|
118
|
-
const optionsProvider = dynamicModule.providers.find((p)=>p.provide === LOCALIZATION_MODULE_OPTIONS);
|
|
119
|
-
expect(optionsProvider.inject).toEqual([
|
|
120
|
-
MyOptionsFactory
|
|
121
|
-
]);
|
|
122
|
-
});
|
|
123
|
-
it('should register no LOCALIZATION_MODULE_OPTIONS provider when neither useFactory, useClass, nor useExisting is given', ()=>{
|
|
124
|
-
const dynamicModule = LocalizationModule.forRootAsync({});
|
|
125
|
-
expect(providerTokens(dynamicModule.providers)).not.toContain(LOCALIZATION_MODULE_OPTIONS);
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
});
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
15
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
18
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
-
}
|
|
20
|
-
function _ts_metadata(k, v) {
|
|
21
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
-
}
|
|
23
|
-
function _ts_param(paramIndex, decorator) {
|
|
24
|
-
return function(target, key) {
|
|
25
|
-
decorator(target, key, paramIndex);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
import { HybridCache, ApiService } from '@flusys/nestjs-shared/classes';
|
|
29
|
-
import { UtilsService } from '@flusys/nestjs-shared/modules';
|
|
30
|
-
import { ForbiddenException, Inject, Injectable, Scope } from '@nestjs/common';
|
|
31
|
-
import { In, IsNull } from 'typeorm';
|
|
32
|
-
import { LANGUAGE_MESSAGES, LOCALIZATION_EVENT_ENTITIES, LOCALIZATION_EVENT_MODULE } from '../config';
|
|
33
|
-
import { Language } from '../entities';
|
|
34
|
-
import { LocalizationDataSourceProvider } from './localization-datasource.provider';
|
|
35
|
-
export class LanguageService extends ApiService {
|
|
36
|
-
async beforeUpdateOperation(dto, _user, _queryRunner) {
|
|
37
|
-
const dtos = Array.isArray(dto) ? dto : [
|
|
38
|
-
dto
|
|
39
|
-
];
|
|
40
|
-
const ids = dtos.map((d)=>d.id);
|
|
41
|
-
await this.ensureDataSourceRepository();
|
|
42
|
-
const existingLanguages = await this.repository.find({
|
|
43
|
-
where: {
|
|
44
|
-
id: In(ids),
|
|
45
|
-
deletedAt: IsNull()
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
for (const d of dtos){
|
|
49
|
-
const existing = existingLanguages.find((e)=>e.id === d.id);
|
|
50
|
-
if (!existing) {
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
const changesIdentity = d.code !== undefined && d.code !== existing.code || d.name !== undefined && d.name !== existing.name || d.nativeName !== undefined && d.nativeName !== (existing.nativeName ?? undefined) || d.direction !== undefined && d.direction !== existing.direction;
|
|
54
|
-
if (existing.isReadonly && changesIdentity) {
|
|
55
|
-
throw new ForbiddenException({
|
|
56
|
-
message: `Cannot modify code/name of readonly language "${existing.name}"`,
|
|
57
|
-
messageKey: LANGUAGE_MESSAGES.READONLY_UPDATE_FORBIDDEN,
|
|
58
|
-
messageVariables: {
|
|
59
|
-
name: existing.name
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
async beforeDeleteOperation(dto, _user, _queryRunner) {
|
|
66
|
-
const ids = Array.isArray(dto.id) ? dto.id : [
|
|
67
|
-
dto.id
|
|
68
|
-
];
|
|
69
|
-
await this.ensureDataSourceRepository();
|
|
70
|
-
const languages = await this.repository.find({
|
|
71
|
-
where: {
|
|
72
|
-
id: In(ids),
|
|
73
|
-
deletedAt: IsNull()
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
const readonlyLanguages = languages.filter((l)=>l.isReadonly);
|
|
77
|
-
if (readonlyLanguages.length > 0) {
|
|
78
|
-
const names = readonlyLanguages.map((l)=>l.name).join(', ');
|
|
79
|
-
throw new ForbiddenException({
|
|
80
|
-
message: `Cannot delete readonly language(s): ${names}`,
|
|
81
|
-
messageKey: LANGUAGE_MESSAGES.READONLY_DELETE_FORBIDDEN,
|
|
82
|
-
messageVariables: {
|
|
83
|
-
names
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
const defaultLanguages = languages.filter((l)=>l.isDefault);
|
|
88
|
-
if (defaultLanguages.length > 0) {
|
|
89
|
-
const names = defaultLanguages.map((l)=>l.name).join(', ');
|
|
90
|
-
throw new ForbiddenException({
|
|
91
|
-
message: `Cannot delete the default language(s): ${names}. Set another language as default first.`,
|
|
92
|
-
messageKey: LANGUAGE_MESSAGES.DEFAULT_DELETE_FORBIDDEN,
|
|
93
|
-
messageVariables: {
|
|
94
|
-
names
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
async getDefaultLanguage() {
|
|
100
|
-
await this.ensureDataSourceRepository();
|
|
101
|
-
return this.repository.findOne({
|
|
102
|
-
where: {
|
|
103
|
-
isDefault: true,
|
|
104
|
-
deletedAt: IsNull()
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
async getActiveLanguages() {
|
|
109
|
-
await this.ensureDataSourceRepository();
|
|
110
|
-
return this.repository.find({
|
|
111
|
-
where: {
|
|
112
|
-
isActive: true,
|
|
113
|
-
deletedAt: IsNull()
|
|
114
|
-
},
|
|
115
|
-
order: {
|
|
116
|
-
serial: 'ASC',
|
|
117
|
-
name: 'ASC'
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
async setAsDefault(id) {
|
|
122
|
-
await this.ensureDataSourceRepository();
|
|
123
|
-
const previousDefaults = await this.repository.find({
|
|
124
|
-
where: {
|
|
125
|
-
isDefault: true
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
await this.repository.update({
|
|
129
|
-
isDefault: true
|
|
130
|
-
}, {
|
|
131
|
-
isDefault: false
|
|
132
|
-
});
|
|
133
|
-
await this.repository.update({
|
|
134
|
-
id
|
|
135
|
-
}, {
|
|
136
|
-
isDefault: true
|
|
137
|
-
});
|
|
138
|
-
const language = await this.repository.findOne({
|
|
139
|
-
where: {
|
|
140
|
-
id
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
await Promise.all([
|
|
144
|
-
this.clearCacheForAll(),
|
|
145
|
-
this.clearCacheForId([
|
|
146
|
-
...previousDefaults,
|
|
147
|
-
{
|
|
148
|
-
id
|
|
149
|
-
}
|
|
150
|
-
])
|
|
151
|
-
]);
|
|
152
|
-
return language;
|
|
153
|
-
}
|
|
154
|
-
constructor(cacheManager, utilsService, dataSourceProvider){
|
|
155
|
-
super(LOCALIZATION_EVENT_ENTITIES.LANGUAGE, cacheManager, utilsService, LanguageService.name, true, LOCALIZATION_EVENT_MODULE, dataSourceProvider, Language), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
LanguageService = _ts_decorate([
|
|
159
|
-
Injectable({
|
|
160
|
-
scope: Scope.REQUEST
|
|
161
|
-
}),
|
|
162
|
-
_ts_param(0, Inject('CACHE_INSTANCE')),
|
|
163
|
-
_ts_param(1, Inject(UtilsService)),
|
|
164
|
-
_ts_param(2, Inject(LocalizationDataSourceProvider)),
|
|
165
|
-
_ts_metadata("design:type", Function),
|
|
166
|
-
_ts_metadata("design:paramtypes", [
|
|
167
|
-
typeof HybridCache === "undefined" ? Object : HybridCache,
|
|
168
|
-
typeof UtilsService === "undefined" ? Object : UtilsService,
|
|
169
|
-
typeof LocalizationDataSourceProvider === "undefined" ? Object : LocalizationDataSourceProvider
|
|
170
|
-
])
|
|
171
|
-
], LanguageService);
|