@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
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
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;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.IntlOrm_2022_06_28_01_13_00 = void 0;
|
|
10
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
11
|
-
const orm_1 = require("@spinajs/orm");
|
|
12
|
-
let IntlOrm_2022_06_28_01_13_00 = class IntlOrm_2022_06_28_01_13_00 extends orm_1.OrmMigration {
|
|
13
|
-
async up(connection) {
|
|
14
|
-
await connection.schema().createTable('intl_resources', (table) => {
|
|
15
|
-
table.int('ResourceId').notNull();
|
|
16
|
-
table.string('Resource', 32).notNull();
|
|
17
|
-
table.string('Column', 16).notNull();
|
|
18
|
-
table.string('Lang', 6).notNull();
|
|
19
|
-
table.text('Value');
|
|
20
|
-
});
|
|
21
|
-
await connection.schema().createTable('intl_translations', (table) => {
|
|
22
|
-
table.int('Id').primaryKey().autoIncrement();
|
|
23
|
-
table.string('Key', 32).notNull();
|
|
24
|
-
table.text('Value');
|
|
25
|
-
table.string('Lang', 6).notNull();
|
|
26
|
-
});
|
|
27
|
-
await connection.index().unique().table('intl_resources').name('intl_resources_idx').columns(['ResourceId', 'Resource', 'Column', 'Lang']);
|
|
28
|
-
await connection.index().unique().table('intl_translations').name('intl_translations_idx').columns(['Key', 'Lang']);
|
|
29
|
-
}
|
|
30
|
-
// tslint:disable-next-line: no-empty
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
32
|
-
async down(_connection) { }
|
|
33
|
-
};
|
|
34
|
-
IntlOrm_2022_06_28_01_13_00 =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.IntlOrm_2022_06_28_01_13_00 = void 0;
|
|
10
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
11
|
+
const orm_1 = require("@spinajs/orm");
|
|
12
|
+
let IntlOrm_2022_06_28_01_13_00 = class IntlOrm_2022_06_28_01_13_00 extends orm_1.OrmMigration {
|
|
13
|
+
async up(connection) {
|
|
14
|
+
await connection.schema().createTable('intl_resources', (table) => {
|
|
15
|
+
table.int('ResourceId').notNull();
|
|
16
|
+
table.string('Resource', 32).notNull();
|
|
17
|
+
table.string('Column', 16).notNull();
|
|
18
|
+
table.string('Lang', 6).notNull();
|
|
19
|
+
table.text('Value');
|
|
20
|
+
});
|
|
21
|
+
await connection.schema().createTable('intl_translations', (table) => {
|
|
22
|
+
table.int('Id').primaryKey().autoIncrement();
|
|
23
|
+
table.string('Key', 32).notNull();
|
|
24
|
+
table.text('Value');
|
|
25
|
+
table.string('Lang', 6).notNull();
|
|
26
|
+
});
|
|
27
|
+
await connection.index().unique().table('intl_resources').name('intl_resources_idx').columns(['ResourceId', 'Resource', 'Column', 'Lang']);
|
|
28
|
+
await connection.index().unique().table('intl_translations').name('intl_translations_idx').columns(['Key', 'Lang']);
|
|
29
|
+
}
|
|
30
|
+
// tslint:disable-next-line: no-empty
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
32
|
+
async down(_connection) { }
|
|
33
|
+
};
|
|
34
|
+
exports.IntlOrm_2022_06_28_01_13_00 = IntlOrm_2022_06_28_01_13_00;
|
|
35
|
+
exports.IntlOrm_2022_06_28_01_13_00 = IntlOrm_2022_06_28_01_13_00 = __decorate([
|
|
36
|
+
(0, orm_1.Migration)('default')
|
|
37
|
+
], IntlOrm_2022_06_28_01_13_00);
|
|
38
38
|
//# sourceMappingURL=IntlOrm_2022_06_28_01_13_00.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlOrm_2022_06_28_01_13_00.js","sourceRoot":"","sources":["../../../src/migrations/IntlOrm_2022_06_28_01_13_00.ts"],"names":[],"mappings":";;;;;;;;;AAAA,sDAAsD;AACtD,sCAAkE;AAG3D,IAAM,2BAA2B,GAAjC,MAAM,2BAA4B,SAAQ,kBAAY;IACpD,KAAK,CAAC,EAAE,CAAC,UAAqB;QACnC,MAAM,UAAU,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC,gBAAgB,EAAE,CAAC,KAAK,EAAE,EAAE;YAChE,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC;YAClC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;YACvC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;YACrC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;YAClC,KAAK,CAAC,IAA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CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IACtH,CAAC;IAED,qCAAqC;IACrC,gEAAgE;IACzD,KAAK,CAAC,IAAI,CAAC,WAAsB,IAAkB,CAAC;CAC5D,CAAA;AAxBY,kEAA2B;sCAA3B,2BAA2B;IADvC,IAAA,eAAS,EAAC,SAAS,CAAC;GACR,2BAA2B,CAwBvC"}
|
package/lib/cjs/model.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { ModelBase } from '@spinajs/orm';
|
|
2
|
-
export declare class Translatable extends ModelBase {
|
|
3
|
-
protected Language: string;
|
|
4
|
-
/**
|
|
5
|
-
* Reloads entity with proper translation
|
|
6
|
-
*
|
|
7
|
-
* @param lang - language to load
|
|
8
|
-
*/
|
|
9
|
-
translate(lang?: string): Promise<void>;
|
|
10
|
-
setLanguage(lang: string): void;
|
|
11
|
-
update(): Promise<void>;
|
|
12
|
-
}
|
|
1
|
+
import { ModelBase } from '@spinajs/orm';
|
|
2
|
+
export declare class Translatable extends ModelBase {
|
|
3
|
+
protected Language: string;
|
|
4
|
+
/**
|
|
5
|
+
* Reloads entity with proper translation
|
|
6
|
+
*
|
|
7
|
+
* @param lang - language to load
|
|
8
|
+
*/
|
|
9
|
+
translate(lang?: string): Promise<void>;
|
|
10
|
+
setLanguage(lang: string): void;
|
|
11
|
+
update(): Promise<void>;
|
|
12
|
+
}
|
|
13
13
|
//# sourceMappingURL=model.d.ts.map
|
package/lib/cjs/model.js
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Translatable = void 0;
|
|
7
|
-
const di_1 = require("@spinajs/di");
|
|
8
|
-
const orm_1 = require("@spinajs/orm");
|
|
9
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
10
|
-
const IntlResource_js_1 = require("./models/IntlResource.js");
|
|
11
|
-
const configuration_common_1 = require("@spinajs/configuration-common");
|
|
12
|
-
const intl_1 = require("@spinajs/intl");
|
|
13
|
-
class Translatable extends orm_1.ModelBase {
|
|
14
|
-
/**
|
|
15
|
-
* Reloads entity with proper translation
|
|
16
|
-
*
|
|
17
|
-
* @param lang - language to load
|
|
18
|
-
*/
|
|
19
|
-
async translate(lang) {
|
|
20
|
-
const selectedLang = (0, intl_1.guessLanguage)(lang);
|
|
21
|
-
const translations = await IntlResource_js_1.IntlResource.where({
|
|
22
|
-
ResourceId: this.PrimaryKeyValue,
|
|
23
|
-
Resource: this.constructor.name,
|
|
24
|
-
Lang: selectedLang,
|
|
25
|
-
});
|
|
26
|
-
translations.forEach((rd) => {
|
|
27
|
-
this[rd.Column] = rd.Value;
|
|
28
|
-
});
|
|
29
|
-
this.Language = selectedLang;
|
|
30
|
-
}
|
|
31
|
-
setLanguage(lang) {
|
|
32
|
-
this.Language = lang;
|
|
33
|
-
}
|
|
34
|
-
async update() {
|
|
35
|
-
const selectedLang = (0, intl_1.guessLanguage)(this.Language);
|
|
36
|
-
const defaultLanguage = di_1.DI.get(configuration_common_1.Configuration).get('intl.defaultLocale');
|
|
37
|
-
if (!selectedLang || defaultLanguage === selectedLang) {
|
|
38
|
-
await super.update();
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
this.Language = selectedLang;
|
|
42
|
-
// TODO: temporaty use uniqyBy, pls FIX model descriptor proper handling in ORM module
|
|
43
|
-
const tColumns = lodash_1.default.uniqBy(this.ModelDescriptor.Columns.filter((c) => c.Translate), 'Name');
|
|
44
|
-
const { query } = this.createUpdateQuery();
|
|
45
|
-
if (this.ModelDescriptor.Timestamps.UpdatedAt) {
|
|
46
|
-
this[this.ModelDescriptor.Timestamps.UpdatedAt] = new Date();
|
|
47
|
-
}
|
|
48
|
-
// update only non translated
|
|
49
|
-
const cToDehydrate = [...tColumns.map((c) => c.Name)];
|
|
50
|
-
const dToUpdate = lodash_1.default.omit(this.toSql(), cToDehydrate);
|
|
51
|
-
if (Object.keys(dToUpdate).length !== 0) {
|
|
52
|
-
await query.update(dToUpdate).where(this.PrimaryKeyName, this.PrimaryKeyValue);
|
|
53
|
-
}
|
|
54
|
-
const translations = tColumns.map((c) => {
|
|
55
|
-
return new IntlResource_js_1.IntlResource({
|
|
56
|
-
ResourceId: this.PrimaryKeyValue,
|
|
57
|
-
Resource: this.constructor.name,
|
|
58
|
-
Column: c.Name,
|
|
59
|
-
Lang: this.Language,
|
|
60
|
-
Value: this[c.Name],
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
// update or insert translations to database
|
|
64
|
-
for (const t of translations) {
|
|
65
|
-
await t.insert(orm_1.InsertBehaviour.InsertOrUpdate);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.Translatable = Translatable;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Translatable = void 0;
|
|
7
|
+
const di_1 = require("@spinajs/di");
|
|
8
|
+
const orm_1 = require("@spinajs/orm");
|
|
9
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
10
|
+
const IntlResource_js_1 = require("./models/IntlResource.js");
|
|
11
|
+
const configuration_common_1 = require("@spinajs/configuration-common");
|
|
12
|
+
const intl_1 = require("@spinajs/intl");
|
|
13
|
+
class Translatable extends orm_1.ModelBase {
|
|
14
|
+
/**
|
|
15
|
+
* Reloads entity with proper translation
|
|
16
|
+
*
|
|
17
|
+
* @param lang - language to load
|
|
18
|
+
*/
|
|
19
|
+
async translate(lang) {
|
|
20
|
+
const selectedLang = (0, intl_1.guessLanguage)(lang);
|
|
21
|
+
const translations = await IntlResource_js_1.IntlResource.where({
|
|
22
|
+
ResourceId: this.PrimaryKeyValue,
|
|
23
|
+
Resource: this.constructor.name,
|
|
24
|
+
Lang: selectedLang,
|
|
25
|
+
});
|
|
26
|
+
translations.forEach((rd) => {
|
|
27
|
+
this[rd.Column] = rd.Value;
|
|
28
|
+
});
|
|
29
|
+
this.Language = selectedLang;
|
|
30
|
+
}
|
|
31
|
+
setLanguage(lang) {
|
|
32
|
+
this.Language = lang;
|
|
33
|
+
}
|
|
34
|
+
async update() {
|
|
35
|
+
const selectedLang = (0, intl_1.guessLanguage)(this.Language);
|
|
36
|
+
const defaultLanguage = di_1.DI.get(configuration_common_1.Configuration).get('intl.defaultLocale');
|
|
37
|
+
if (!selectedLang || defaultLanguage === selectedLang) {
|
|
38
|
+
await super.update();
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
this.Language = selectedLang;
|
|
42
|
+
// TODO: temporaty use uniqyBy, pls FIX model descriptor proper handling in ORM module
|
|
43
|
+
const tColumns = lodash_1.default.uniqBy(this.ModelDescriptor.Columns.filter((c) => c.Translate), 'Name');
|
|
44
|
+
const { query } = this.createUpdateQuery();
|
|
45
|
+
if (this.ModelDescriptor.Timestamps.UpdatedAt) {
|
|
46
|
+
this[this.ModelDescriptor.Timestamps.UpdatedAt] = new Date();
|
|
47
|
+
}
|
|
48
|
+
// update only non translated
|
|
49
|
+
const cToDehydrate = [...tColumns.map((c) => c.Name)];
|
|
50
|
+
const dToUpdate = lodash_1.default.omit(this.toSql(), cToDehydrate);
|
|
51
|
+
if (Object.keys(dToUpdate).length !== 0) {
|
|
52
|
+
await query.update(dToUpdate).where(this.PrimaryKeyName, this.PrimaryKeyValue);
|
|
53
|
+
}
|
|
54
|
+
const translations = tColumns.map((c) => {
|
|
55
|
+
return new IntlResource_js_1.IntlResource({
|
|
56
|
+
ResourceId: this.PrimaryKeyValue,
|
|
57
|
+
Resource: this.constructor.name,
|
|
58
|
+
Column: c.Name,
|
|
59
|
+
Lang: this.Language,
|
|
60
|
+
Value: this[c.Name],
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
// update or insert translations to database
|
|
64
|
+
for (const t of translations) {
|
|
65
|
+
await t.insert(orm_1.InsertBehaviour.InsertOrUpdate);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.Translatable = Translatable;
|
|
71
71
|
//# 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,23 +1,23 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
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;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.IntlResource = void 0;
|
|
10
|
-
const orm_1 = require("@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 IntlResource = class IntlResource extends orm_1.ModelBase {
|
|
17
|
-
};
|
|
18
|
-
IntlResource =
|
|
19
|
-
|
|
20
|
-
(0, orm_1.
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.IntlResource = void 0;
|
|
10
|
+
const orm_1 = require("@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 IntlResource = class IntlResource extends orm_1.ModelBase {
|
|
17
|
+
};
|
|
18
|
+
exports.IntlResource = IntlResource;
|
|
19
|
+
exports.IntlResource = IntlResource = __decorate([
|
|
20
|
+
(0, orm_1.Connection)('default'),
|
|
21
|
+
(0, orm_1.Model)('intl_resources')
|
|
22
|
+
], IntlResource);
|
|
23
23
|
//# sourceMappingURL=IntlResource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlResource.js","sourceRoot":"","sources":["../../../src/models/IntlResource.ts"],"names":[],"mappings":";;;;;;;;;AAAA,sCAA4D;AAE5D;;;;GAIG;AAGI,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,eAAS;CAU1C,CAAA;AAVY,YAAY;IAFxB,IAAA,gBAAU,EAAC,SAAS,CAAC;IACrB,IAAA,WAAK,EAAC,gBAAgB,CAAC;GACX,YAAY,CAUxB
|
|
1
|
+
{"version":3,"file":"IntlResource.js","sourceRoot":"","sources":["../../../src/models/IntlResource.ts"],"names":[],"mappings":";;;;;;;;;AAAA,sCAA4D;AAE5D;;;;GAIG;AAGI,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,eAAS;CAU1C,CAAA;AAVY,oCAAY;uBAAZ,YAAY;IAFxB,IAAA,gBAAU,EAAC,SAAS,CAAC;IACrB,IAAA,WAAK,EAAC,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,30 +1,30 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
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;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.IntlTranslation = void 0;
|
|
13
|
-
const orm_1 = require("@spinajs/orm");
|
|
14
|
-
/**
|
|
15
|
-
* Base modele for users used by ACL
|
|
16
|
-
*
|
|
17
|
-
* To add / extend fields simply extend this model and register as default user model in ACL service
|
|
18
|
-
*/
|
|
19
|
-
let IntlTranslation = class IntlTranslation extends orm_1.ModelBase {
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
IntlTranslation
|
|
26
|
-
|
|
27
|
-
(0, orm_1.
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.IntlTranslation = void 0;
|
|
13
|
+
const orm_1 = require("@spinajs/orm");
|
|
14
|
+
/**
|
|
15
|
+
* Base modele for users used by ACL
|
|
16
|
+
*
|
|
17
|
+
* To add / extend fields simply extend this model and register as default user model in ACL service
|
|
18
|
+
*/
|
|
19
|
+
let IntlTranslation = class IntlTranslation extends orm_1.ModelBase {
|
|
20
|
+
};
|
|
21
|
+
exports.IntlTranslation = IntlTranslation;
|
|
22
|
+
__decorate([
|
|
23
|
+
(0, orm_1.Primary)(),
|
|
24
|
+
__metadata("design:type", Number)
|
|
25
|
+
], IntlTranslation.prototype, "Id", void 0);
|
|
26
|
+
exports.IntlTranslation = IntlTranslation = __decorate([
|
|
27
|
+
(0, orm_1.Connection)('default'),
|
|
28
|
+
(0, orm_1.Model)('intl_translations')
|
|
29
|
+
], IntlTranslation);
|
|
30
30
|
//# sourceMappingURL=IntlTranslation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlTranslation.js","sourceRoot":"","sources":["../../../src/models/IntlTranslation.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sCAAqE;AAErE;;;;GAIG;AAGI,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,eAAS;CAS7C,CAAA;
|
|
1
|
+
{"version":3,"file":"IntlTranslation.js","sourceRoot":"","sources":["../../../src/models/IntlTranslation.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sCAAqE;AAErE;;;;GAIG;AAGI,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,eAAS;CAS7C,CAAA;AATY,0CAAe;AAEnB;IADN,IAAA,aAAO,GAAE;;2CACQ;0BAFP,eAAe;IAF3B,IAAA,gBAAU,EAAC,SAAS,CAAC;IACrB,IAAA,WAAK,EAAC,mBAAmB,CAAC;GACd,eAAe,CAS3B"}
|
package/lib/mjs/decorators.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function Translate(): any;
|
|
1
|
+
export declare function Translate(): any;
|
|
2
2
|
//# sourceMappingURL=decorators.d.ts.map
|
package/lib/mjs/decorators.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { extractDecoratorDescriptor } from '@spinajs/orm';
|
|
2
|
-
export function Translate() {
|
|
3
|
-
return extractDecoratorDescriptor((model, _target, propertyKey) => {
|
|
4
|
-
const columnDesc = model.Columns.find((c) => c.Name === propertyKey);
|
|
5
|
-
if (!columnDesc) {
|
|
6
|
-
// we dont want to fill all props, they will be loaded from db and mergeg with this
|
|
7
|
-
model.Columns.push({ Name: propertyKey, Translate: true });
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
columnDesc.Translate = true;
|
|
11
|
-
}
|
|
12
|
-
model.Translatable = true;
|
|
13
|
-
}, true);
|
|
14
|
-
}
|
|
1
|
+
import { extractDecoratorDescriptor } from '@spinajs/orm';
|
|
2
|
+
export function Translate() {
|
|
3
|
+
return extractDecoratorDescriptor((model, _target, propertyKey) => {
|
|
4
|
+
const columnDesc = model.Columns.find((c) => c.Name === propertyKey);
|
|
5
|
+
if (!columnDesc) {
|
|
6
|
+
// we dont want to fill all props, they will be loaded from db and mergeg with this
|
|
7
|
+
model.Columns.push({ Name: propertyKey, Translate: true });
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
columnDesc.Translate = true;
|
|
11
|
+
}
|
|
12
|
+
model.Translatable = true;
|
|
13
|
+
}, true);
|
|
14
|
+
}
|
|
15
15
|
//# sourceMappingURL=decorators.js.map
|
package/lib/mjs/index.d.ts
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import { Container } from '@spinajs/di';
|
|
2
|
-
import { IModelDescriptor, ModelBase, OrmRelation, SelectQueryBuilder, QueryBuilder, QueryMiddleware, IBuilderMiddleware, IOrmRelation, ISelectQueryBuilder } from '@spinajs/orm';
|
|
3
|
-
import { TranslationSource } from '@spinajs/intl';
|
|
4
|
-
export * from './decorators.js';
|
|
5
|
-
export * from './migrations/IntlOrm_2022_06_28_01_13_00.js';
|
|
6
|
-
export * from './models/IntlResource.js';
|
|
7
|
-
export * from './models/IntlTranslation.js';
|
|
8
|
-
export * from './model.js';
|
|
9
|
-
declare module '@spinajs/orm' {
|
|
10
|
-
interface ISelectQueryBuilder<T> {
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* Translates model to given language.
|
|
14
|
-
* Working only with queries thata are model related ( created by model orm functions )
|
|
15
|
-
* TODO: in future it should work with raw queries, by passing relation information for translation
|
|
16
|
-
* TODO: fallback for translation from normal sources ( like config files )
|
|
17
|
-
*
|
|
18
|
-
* @param lang translate to language
|
|
19
|
-
*/
|
|
20
|
-
translate(lang: string): SelectQueryBuilder<T>;
|
|
21
|
-
translated: boolean;
|
|
22
|
-
AllowTranslate: boolean;
|
|
23
|
-
}
|
|
24
|
-
interface IColumnDescriptor {
|
|
25
|
-
Translate: boolean;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export declare class IntlModelRelation extends OrmRelation {
|
|
29
|
-
protected _lang: string;
|
|
30
|
-
protected _mDescriptor: IModelDescriptor;
|
|
31
|
-
constructor(_container: Container, _lang: string, _query: ISelectQueryBuilder, _mDescriptor: IModelDescriptor, _parentRelation?: OrmRelation);
|
|
32
|
-
execute(): void;
|
|
33
|
-
translate(_lang: string): void;
|
|
34
|
-
}
|
|
35
|
-
export declare class IntlModelMiddleware implements IBuilderMiddleware {
|
|
36
|
-
protected _lang: string;
|
|
37
|
-
protected _relationQuery: ISelectQueryBuilder;
|
|
38
|
-
protected _description: IModelDescriptor;
|
|
39
|
-
protected _owner: IOrmRelation;
|
|
40
|
-
constructor(_lang: string, _relationQuery: ISelectQueryBuilder, _description: IModelDescriptor, _owner: IOrmRelation);
|
|
41
|
-
afterQueryCreation(_query: QueryBuilder<any>): void;
|
|
42
|
-
afterQuery(data: any[]): any[];
|
|
43
|
-
modelCreation(_: any): ModelBase;
|
|
44
|
-
afterHydration(data: ModelBase[]): Promise<any[]>;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Middleware for automatic query translations
|
|
48
|
-
* for modes. If query is standalone ( not created by model related function )
|
|
49
|
-
* skips translation completely.
|
|
50
|
-
* When AsyncStorage is set & language property is present
|
|
51
|
-
*
|
|
52
|
-
*/
|
|
53
|
-
export declare class IntlQueryMiddleware extends QueryMiddleware {
|
|
54
|
-
beforeQueryExecution(builder: QueryBuilder<any>): void;
|
|
55
|
-
afterQueryCreation(_builder: QueryBuilder): void;
|
|
56
|
-
}
|
|
57
|
-
export declare class DbTranslationSource extends TranslationSource {
|
|
58
|
-
load(): Promise<{
|
|
59
|
-
[x: string]: any;
|
|
60
|
-
}>;
|
|
61
|
-
}
|
|
1
|
+
import { Container } from '@spinajs/di';
|
|
2
|
+
import { IModelDescriptor, ModelBase, OrmRelation, SelectQueryBuilder, QueryBuilder, QueryMiddleware, IBuilderMiddleware, IOrmRelation, ISelectQueryBuilder } from '@spinajs/orm';
|
|
3
|
+
import { TranslationSource } from '@spinajs/intl';
|
|
4
|
+
export * from './decorators.js';
|
|
5
|
+
export * from './migrations/IntlOrm_2022_06_28_01_13_00.js';
|
|
6
|
+
export * from './models/IntlResource.js';
|
|
7
|
+
export * from './models/IntlTranslation.js';
|
|
8
|
+
export * from './model.js';
|
|
9
|
+
declare module '@spinajs/orm' {
|
|
10
|
+
interface ISelectQueryBuilder<T> {
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* Translates model to given language.
|
|
14
|
+
* Working only with queries thata are model related ( created by model orm functions )
|
|
15
|
+
* TODO: in future it should work with raw queries, by passing relation information for translation
|
|
16
|
+
* TODO: fallback for translation from normal sources ( like config files )
|
|
17
|
+
*
|
|
18
|
+
* @param lang translate to language
|
|
19
|
+
*/
|
|
20
|
+
translate(lang: string): SelectQueryBuilder<T>;
|
|
21
|
+
translated: boolean;
|
|
22
|
+
AllowTranslate: boolean;
|
|
23
|
+
}
|
|
24
|
+
interface IColumnDescriptor {
|
|
25
|
+
Translate: boolean;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export declare class IntlModelRelation extends OrmRelation {
|
|
29
|
+
protected _lang: string;
|
|
30
|
+
protected _mDescriptor: IModelDescriptor;
|
|
31
|
+
constructor(_container: Container, _lang: string, _query: ISelectQueryBuilder, _mDescriptor: IModelDescriptor, _parentRelation?: OrmRelation);
|
|
32
|
+
execute(): void;
|
|
33
|
+
translate(_lang: string): void;
|
|
34
|
+
}
|
|
35
|
+
export declare class IntlModelMiddleware implements IBuilderMiddleware {
|
|
36
|
+
protected _lang: string;
|
|
37
|
+
protected _relationQuery: ISelectQueryBuilder;
|
|
38
|
+
protected _description: IModelDescriptor;
|
|
39
|
+
protected _owner: IOrmRelation;
|
|
40
|
+
constructor(_lang: string, _relationQuery: ISelectQueryBuilder, _description: IModelDescriptor, _owner: IOrmRelation);
|
|
41
|
+
afterQueryCreation(_query: QueryBuilder<any>): void;
|
|
42
|
+
afterQuery(data: any[]): any[];
|
|
43
|
+
modelCreation(_: any): ModelBase;
|
|
44
|
+
afterHydration(data: ModelBase[]): Promise<any[]>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Middleware for automatic query translations
|
|
48
|
+
* for modes. If query is standalone ( not created by model related function )
|
|
49
|
+
* skips translation completely.
|
|
50
|
+
* When AsyncStorage is set & language property is present
|
|
51
|
+
*
|
|
52
|
+
*/
|
|
53
|
+
export declare class IntlQueryMiddleware extends QueryMiddleware {
|
|
54
|
+
beforeQueryExecution(builder: QueryBuilder<any>): void;
|
|
55
|
+
afterQueryCreation(_builder: QueryBuilder): void;
|
|
56
|
+
}
|
|
57
|
+
export declare class DbTranslationSource extends TranslationSource {
|
|
58
|
+
load(): Promise<{
|
|
59
|
+
[x: string]: any;
|
|
60
|
+
}>;
|
|
61
|
+
}
|
|
62
62
|
//# sourceMappingURL=index.d.ts.map
|