@spinajs/intl-orm 2.0.180 → 2.0.182
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/lib/cjs/decorators.d.ts +1 -1
- package/lib/cjs/decorators.js +18 -18
- package/lib/cjs/index.d.ts +61 -61
- package/lib/cjs/index.js +215 -215
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/migrations/IntlOrm_2022_06_28_01_13_00.d.ts +5 -5
- package/lib/cjs/migrations/IntlOrm_2022_06_28_01_13_00.js +37 -37
- package/lib/cjs/migrations/IntlOrm_2022_06_28_01_13_00.js.map +1 -1
- package/lib/cjs/model.d.ts +12 -12
- package/lib/cjs/model.js +70 -70
- package/lib/cjs/models/IntlResource.d.ts +13 -13
- package/lib/cjs/models/IntlResource.js +22 -22
- package/lib/cjs/models/IntlResource.js.map +1 -1
- package/lib/cjs/models/IntlTranslation.d.ts +12 -12
- package/lib/cjs/models/IntlTranslation.js +29 -29
- package/lib/cjs/models/IntlTranslation.js.map +1 -1
- package/lib/mjs/decorators.d.ts +1 -1
- package/lib/mjs/decorators.js +14 -14
- package/lib/mjs/index.d.ts +61 -61
- package/lib/mjs/index.js +194 -194
- package/lib/mjs/index.js.map +1 -1
- package/lib/mjs/migrations/IntlOrm_2022_06_28_01_13_00.d.ts +5 -5
- package/lib/mjs/migrations/IntlOrm_2022_06_28_01_13_00.js +34 -34
- package/lib/mjs/migrations/IntlOrm_2022_06_28_01_13_00.js.map +1 -1
- package/lib/mjs/model.d.ts +12 -12
- package/lib/mjs/model.js +63 -63
- package/lib/mjs/models/IntlResource.d.ts +13 -13
- package/lib/mjs/models/IntlResource.js +19 -19
- package/lib/mjs/models/IntlResource.js.map +1 -1
- package/lib/mjs/models/IntlTranslation.d.ts +12 -12
- package/lib/mjs/models/IntlTranslation.js +26 -26
- package/lib/mjs/models/IntlTranslation.js.map +1 -1
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +9 -9
package/lib/mjs/model.js
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import { DI } from '@spinajs/di';
|
|
2
|
-
import { InsertBehaviour, ModelBase } from '@spinajs/orm';
|
|
3
|
-
import _ from 'lodash';
|
|
4
|
-
import { IntlResource } from './models/IntlResource.js';
|
|
5
|
-
import { Configuration } from '@spinajs/configuration-common';
|
|
6
|
-
import { guessLanguage } from '@spinajs/intl';
|
|
7
|
-
export class Translatable extends ModelBase {
|
|
8
|
-
/**
|
|
9
|
-
* Reloads entity with proper translation
|
|
10
|
-
*
|
|
11
|
-
* @param lang - language to load
|
|
12
|
-
*/
|
|
13
|
-
async translate(lang) {
|
|
14
|
-
const selectedLang = guessLanguage(lang);
|
|
15
|
-
const translations = await IntlResource.where({
|
|
16
|
-
ResourceId: this.PrimaryKeyValue,
|
|
17
|
-
Resource: this.constructor.name,
|
|
18
|
-
Lang: selectedLang,
|
|
19
|
-
});
|
|
20
|
-
translations.forEach((rd) => {
|
|
21
|
-
this[rd.Column] = rd.Value;
|
|
22
|
-
});
|
|
23
|
-
this.Language = selectedLang;
|
|
24
|
-
}
|
|
25
|
-
setLanguage(lang) {
|
|
26
|
-
this.Language = lang;
|
|
27
|
-
}
|
|
28
|
-
async update() {
|
|
29
|
-
const selectedLang = guessLanguage(this.Language);
|
|
30
|
-
const defaultLanguage = DI.get(Configuration).get('intl.defaultLocale');
|
|
31
|
-
if (!selectedLang || defaultLanguage === selectedLang) {
|
|
32
|
-
await super.update();
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
this.Language = selectedLang;
|
|
36
|
-
// TODO: temporaty use uniqyBy, pls FIX model descriptor proper handling in ORM module
|
|
37
|
-
const tColumns = _.uniqBy(this.ModelDescriptor.Columns.filter((c) => c.Translate), 'Name');
|
|
38
|
-
const { query } = this.createUpdateQuery();
|
|
39
|
-
if (this.ModelDescriptor.Timestamps.UpdatedAt) {
|
|
40
|
-
this[this.ModelDescriptor.Timestamps.UpdatedAt] = new Date();
|
|
41
|
-
}
|
|
42
|
-
// update only non translated
|
|
43
|
-
const cToDehydrate = [...tColumns.map((c) => c.Name)];
|
|
44
|
-
const dToUpdate = _.omit(this.toSql(), cToDehydrate);
|
|
45
|
-
if (Object.keys(dToUpdate).length !== 0) {
|
|
46
|
-
await query.update(dToUpdate).where(this.PrimaryKeyName, this.PrimaryKeyValue);
|
|
47
|
-
}
|
|
48
|
-
const translations = tColumns.map((c) => {
|
|
49
|
-
return new IntlResource({
|
|
50
|
-
ResourceId: this.PrimaryKeyValue,
|
|
51
|
-
Resource: this.constructor.name,
|
|
52
|
-
Column: c.Name,
|
|
53
|
-
Lang: this.Language,
|
|
54
|
-
Value: this[c.Name],
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
// update or insert translations to database
|
|
58
|
-
for (const t of translations) {
|
|
59
|
-
await t.insert(InsertBehaviour.InsertOrUpdate);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
1
|
+
import { DI } from '@spinajs/di';
|
|
2
|
+
import { InsertBehaviour, ModelBase } from '@spinajs/orm';
|
|
3
|
+
import _ from 'lodash';
|
|
4
|
+
import { IntlResource } from './models/IntlResource.js';
|
|
5
|
+
import { Configuration } from '@spinajs/configuration-common';
|
|
6
|
+
import { guessLanguage } from '@spinajs/intl';
|
|
7
|
+
export class Translatable extends ModelBase {
|
|
8
|
+
/**
|
|
9
|
+
* Reloads entity with proper translation
|
|
10
|
+
*
|
|
11
|
+
* @param lang - language to load
|
|
12
|
+
*/
|
|
13
|
+
async translate(lang) {
|
|
14
|
+
const selectedLang = guessLanguage(lang);
|
|
15
|
+
const translations = await IntlResource.where({
|
|
16
|
+
ResourceId: this.PrimaryKeyValue,
|
|
17
|
+
Resource: this.constructor.name,
|
|
18
|
+
Lang: selectedLang,
|
|
19
|
+
});
|
|
20
|
+
translations.forEach((rd) => {
|
|
21
|
+
this[rd.Column] = rd.Value;
|
|
22
|
+
});
|
|
23
|
+
this.Language = selectedLang;
|
|
24
|
+
}
|
|
25
|
+
setLanguage(lang) {
|
|
26
|
+
this.Language = lang;
|
|
27
|
+
}
|
|
28
|
+
async update() {
|
|
29
|
+
const selectedLang = guessLanguage(this.Language);
|
|
30
|
+
const defaultLanguage = DI.get(Configuration).get('intl.defaultLocale');
|
|
31
|
+
if (!selectedLang || defaultLanguage === selectedLang) {
|
|
32
|
+
await super.update();
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
this.Language = selectedLang;
|
|
36
|
+
// TODO: temporaty use uniqyBy, pls FIX model descriptor proper handling in ORM module
|
|
37
|
+
const tColumns = _.uniqBy(this.ModelDescriptor.Columns.filter((c) => c.Translate), 'Name');
|
|
38
|
+
const { query } = this.createUpdateQuery();
|
|
39
|
+
if (this.ModelDescriptor.Timestamps.UpdatedAt) {
|
|
40
|
+
this[this.ModelDescriptor.Timestamps.UpdatedAt] = new Date();
|
|
41
|
+
}
|
|
42
|
+
// update only non translated
|
|
43
|
+
const cToDehydrate = [...tColumns.map((c) => c.Name)];
|
|
44
|
+
const dToUpdate = _.omit(this.toSql(), cToDehydrate);
|
|
45
|
+
if (Object.keys(dToUpdate).length !== 0) {
|
|
46
|
+
await query.update(dToUpdate).where(this.PrimaryKeyName, this.PrimaryKeyValue);
|
|
47
|
+
}
|
|
48
|
+
const translations = tColumns.map((c) => {
|
|
49
|
+
return new IntlResource({
|
|
50
|
+
ResourceId: this.PrimaryKeyValue,
|
|
51
|
+
Resource: this.constructor.name,
|
|
52
|
+
Column: c.Name,
|
|
53
|
+
Lang: this.Language,
|
|
54
|
+
Value: this[c.Name],
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
// update or insert translations to database
|
|
58
|
+
for (const t of translations) {
|
|
59
|
+
await t.insert(InsertBehaviour.InsertOrUpdate);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
64
|
//# sourceMappingURL=model.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { ModelBase } from '@spinajs/orm';
|
|
2
|
-
/**
|
|
3
|
-
* Base modele for users used by ACL
|
|
4
|
-
*
|
|
5
|
-
* To add / extend fields simply extend this model and register as default user model in ACL service
|
|
6
|
-
*/
|
|
7
|
-
export declare class IntlResource extends ModelBase {
|
|
8
|
-
ResourceId: number;
|
|
9
|
-
Resource: string;
|
|
10
|
-
Column: string;
|
|
11
|
-
Lang: string;
|
|
12
|
-
Value: string;
|
|
13
|
-
}
|
|
1
|
+
import { ModelBase } from '@spinajs/orm';
|
|
2
|
+
/**
|
|
3
|
+
* Base modele for users used by ACL
|
|
4
|
+
*
|
|
5
|
+
* To add / extend fields simply extend this model and register as default user model in ACL service
|
|
6
|
+
*/
|
|
7
|
+
export declare class IntlResource extends ModelBase {
|
|
8
|
+
ResourceId: number;
|
|
9
|
+
Resource: string;
|
|
10
|
+
Column: string;
|
|
11
|
+
Lang: string;
|
|
12
|
+
Value: string;
|
|
13
|
+
}
|
|
14
14
|
//# sourceMappingURL=IntlResource.d.ts.map
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (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 { ModelBase, Connection, Model } from '@spinajs/orm';
|
|
8
|
-
/**
|
|
9
|
-
* Base modele for users used by ACL
|
|
10
|
-
*
|
|
11
|
-
* To add / extend fields simply extend this model and register as default user model in ACL service
|
|
12
|
-
*/
|
|
13
|
-
let IntlResource = class IntlResource extends ModelBase {
|
|
14
|
-
};
|
|
15
|
-
IntlResource = __decorate([
|
|
16
|
-
Connection('default'),
|
|
17
|
-
Model('intl_resources')
|
|
18
|
-
], IntlResource);
|
|
19
|
-
export { IntlResource };
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (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 { ModelBase, Connection, Model } from '@spinajs/orm';
|
|
8
|
+
/**
|
|
9
|
+
* Base modele for users used by ACL
|
|
10
|
+
*
|
|
11
|
+
* To add / extend fields simply extend this model and register as default user model in ACL service
|
|
12
|
+
*/
|
|
13
|
+
let IntlResource = class IntlResource extends ModelBase {
|
|
14
|
+
};
|
|
15
|
+
IntlResource = __decorate([
|
|
16
|
+
Connection('default'),
|
|
17
|
+
Model('intl_resources')
|
|
18
|
+
], IntlResource);
|
|
19
|
+
export { IntlResource };
|
|
20
20
|
//# sourceMappingURL=IntlResource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlResource.js","sourceRoot":"","sources":["../../../src/models/IntlResource.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE5D;;;;GAIG;AAGI,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,SAAS;CAU1C,CAAA;AAVY,YAAY;IAFxB,UAAU,CAAC,SAAS,CAAC;IACrB,KAAK,CAAC,gBAAgB,CAAC;GACX,YAAY,CAUxB
|
|
1
|
+
{"version":3,"file":"IntlResource.js","sourceRoot":"","sources":["../../../src/models/IntlResource.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE5D;;;;GAIG;AAGI,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,SAAS;CAU1C,CAAA;AAVY,YAAY;IAFxB,UAAU,CAAC,SAAS,CAAC;IACrB,KAAK,CAAC,gBAAgB,CAAC;GACX,YAAY,CAUxB"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { ModelBase } from '@spinajs/orm';
|
|
2
|
-
/**
|
|
3
|
-
* Base modele for users used by ACL
|
|
4
|
-
*
|
|
5
|
-
* To add / extend fields simply extend this model and register as default user model in ACL service
|
|
6
|
-
*/
|
|
7
|
-
export declare class IntlTranslation extends ModelBase {
|
|
8
|
-
Id: number;
|
|
9
|
-
Key: string;
|
|
10
|
-
Value: string;
|
|
11
|
-
Lang: string;
|
|
12
|
-
}
|
|
1
|
+
import { ModelBase } from '@spinajs/orm';
|
|
2
|
+
/**
|
|
3
|
+
* Base modele for users used by ACL
|
|
4
|
+
*
|
|
5
|
+
* To add / extend fields simply extend this model and register as default user model in ACL service
|
|
6
|
+
*/
|
|
7
|
+
export declare class IntlTranslation extends ModelBase {
|
|
8
|
+
Id: number;
|
|
9
|
+
Key: string;
|
|
10
|
+
Value: string;
|
|
11
|
+
Lang: string;
|
|
12
|
+
}
|
|
13
13
|
//# sourceMappingURL=IntlTranslation.d.ts.map
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (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
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { ModelBase, Connection, Model, Primary } from '@spinajs/orm';
|
|
11
|
-
/**
|
|
12
|
-
* Base modele for users used by ACL
|
|
13
|
-
*
|
|
14
|
-
* To add / extend fields simply extend this model and register as default user model in ACL service
|
|
15
|
-
*/
|
|
16
|
-
let IntlTranslation = class IntlTranslation extends ModelBase {
|
|
17
|
-
};
|
|
18
|
-
__decorate([
|
|
19
|
-
Primary(),
|
|
20
|
-
__metadata("design:type", Number)
|
|
21
|
-
], IntlTranslation.prototype, "Id", void 0);
|
|
22
|
-
IntlTranslation = __decorate([
|
|
23
|
-
Connection('default'),
|
|
24
|
-
Model('intl_translations')
|
|
25
|
-
], IntlTranslation);
|
|
26
|
-
export { IntlTranslation };
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (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
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { ModelBase, Connection, Model, Primary } from '@spinajs/orm';
|
|
11
|
+
/**
|
|
12
|
+
* Base modele for users used by ACL
|
|
13
|
+
*
|
|
14
|
+
* To add / extend fields simply extend this model and register as default user model in ACL service
|
|
15
|
+
*/
|
|
16
|
+
let IntlTranslation = class IntlTranslation extends ModelBase {
|
|
17
|
+
};
|
|
18
|
+
__decorate([
|
|
19
|
+
Primary(),
|
|
20
|
+
__metadata("design:type", Number)
|
|
21
|
+
], IntlTranslation.prototype, "Id", void 0);
|
|
22
|
+
IntlTranslation = __decorate([
|
|
23
|
+
Connection('default'),
|
|
24
|
+
Model('intl_translations')
|
|
25
|
+
], IntlTranslation);
|
|
26
|
+
export { IntlTranslation };
|
|
27
27
|
//# sourceMappingURL=IntlTranslation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlTranslation.js","sourceRoot":"","sources":["../../../src/models/IntlTranslation.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAErE;;;;GAIG;AAGI,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,SAAS;CAS7C,CAAA;
|
|
1
|
+
{"version":3,"file":"IntlTranslation.js","sourceRoot":"","sources":["../../../src/models/IntlTranslation.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAErE;;;;GAIG;AAGI,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,SAAS;CAS7C,CAAA;AAPQ;IADN,OAAO,EAAE;;2CACQ;AAFP,eAAe;IAF3B,UAAU,CAAC,SAAS,CAAC;IACrB,KAAK,CAAC,mBAAmB,CAAC;GACd,eAAe,CAS3B"}
|