@spinajs/intl-orm 1.2.108

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/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # `intl-orm`
2
+
3
+ > TODO: description
4
+
5
+ ## Usage
6
+
7
+ ```
8
+ const intlOrm = require('intl-orm');
9
+
10
+ // TODO: DEMONSTRATE API
11
+ ```
12
+ ## TODO
13
+ * Translate many to many relations
14
+ * Translate belongsTo relations
15
+ * Clear translations
16
+ * OnDelete delete translations
17
+ * Check if exists translation
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const path_1 = require("path");
4
+ function dir(path) {
5
+ return (0, path_1.resolve)((0, path_1.normalize)((0, path_1.join)(__dirname, path)));
6
+ }
7
+ module.exports = {
8
+ system: {
9
+ dirs: {
10
+ migrations: [dir('./../migrations')],
11
+ models: [dir('./../models')],
12
+ },
13
+ },
14
+ };
15
+ //# sourceMappingURL=intl-orm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intl-orm.js","sourceRoot":"","sources":["../../src/config/intl-orm.ts"],"names":[],"mappings":";;AAAA,+BAAgD;AAEhD,SAAS,GAAG,CAAC,IAAY;IACvB,OAAO,IAAA,cAAO,EAAC,IAAA,gBAAS,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,CAAC,OAAO,GAAG;IACf,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,UAAU,EAAE,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;YACpC,MAAM,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;SAC7B;KACF;CACF,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ import { IBuilderMiddleware, IModelDescrtiptor, ModelBase, Orm, OrmRelation, SelectQueryBuilder } from '@spinajs/orm';
2
+ declare module '@spinajs/orm' {
3
+ interface ISelectBuilderExtensions<T = any> {
4
+ translate(lang: string): this;
5
+ }
6
+ interface IColumnDescriptor {
7
+ Translate: boolean;
8
+ }
9
+ }
10
+ export declare class IntlModelBase extends ModelBase {
11
+ Language: string;
12
+ /**
13
+ * Reloads entity with proper translation
14
+ *
15
+ * @param lang - language to load
16
+ */
17
+ translate(lang: string): Promise<void>;
18
+ update(): Promise<void>;
19
+ }
20
+ export declare function Translate(): any;
21
+ export declare class IntlModelRelation extends OrmRelation {
22
+ protected _lang: string;
23
+ protected _mDescriptor: IModelDescrtiptor;
24
+ constructor(_lang: string, _orm: Orm, _query: SelectQueryBuilder<any>, _mDescriptor: IModelDescrtiptor, _parentRelation?: OrmRelation);
25
+ execute(): void;
26
+ translate(_lang: string): void;
27
+ }
28
+ export declare class IntlModelMiddleware implements IBuilderMiddleware {
29
+ protected _lang: string;
30
+ protected _relationQuery: SelectQueryBuilder;
31
+ protected _description: IModelDescrtiptor;
32
+ constructor(_lang: string, _relationQuery: SelectQueryBuilder, _description: IModelDescrtiptor);
33
+ afterQuery(data: any[]): any[];
34
+ modelCreation(_: any): ModelBase;
35
+ afterHydration(data: ModelBase[]): Promise<any[]>;
36
+ }
package/lib/index.js ADDED
@@ -0,0 +1,171 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.IntlModelMiddleware = exports.IntlModelRelation = exports.Translate = exports.IntlModelBase = void 0;
16
+ const di_1 = require("@spinajs/di");
17
+ const orm_1 = require("@spinajs/orm");
18
+ const lodash_1 = __importDefault(require("lodash"));
19
+ const IntlResource_1 = require("./models/IntlResource");
20
+ class IntlModelBase extends orm_1.ModelBase {
21
+ /**
22
+ * Reloads entity with proper translation
23
+ *
24
+ * @param lang - language to load
25
+ */
26
+ async translate(lang) {
27
+ const translations = await IntlResource_1.IntlResource.where({
28
+ ResourceId: this.PrimaryKeyValue,
29
+ Resource: this.constructor.name,
30
+ Lang: lang,
31
+ });
32
+ translations.forEach((rd) => {
33
+ this[rd.Column] = rd.Value;
34
+ });
35
+ this.Language = lang;
36
+ }
37
+ async update() {
38
+ if (!this.Language) {
39
+ await super.update();
40
+ }
41
+ else {
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 = [this.PrimaryKeyName, ...tColumns.map((c) => c.Name)];
50
+ const dToUpdate = this.dehydrate(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_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.IntlModelBase = IntlModelBase;
71
+ function Translate() {
72
+ return (0, orm_1.extractDecoratorDescriptor)((model, _target, propertyKey) => {
73
+ const columnDesc = model.Columns.find((c) => c.Name === propertyKey);
74
+ if (!columnDesc) {
75
+ // we dont want to fill all props, they will be loaded from db and mergeg with this
76
+ model.Columns.push({ Name: propertyKey, Translate: true });
77
+ }
78
+ else {
79
+ columnDesc.Translate = true;
80
+ }
81
+ }, true);
82
+ }
83
+ exports.Translate = Translate;
84
+ let IntlModelRelation = class IntlModelRelation extends orm_1.OrmRelation {
85
+ constructor(_lang, _orm, _query, _mDescriptor, _parentRelation) {
86
+ super(_orm, _query, {
87
+ TargetModel: IntlResource_1.IntlResource,
88
+ Name: 'Translations',
89
+ Type: orm_1.RelationType.Many,
90
+ SourceModel: null,
91
+ ForeignKey: '',
92
+ PrimaryKey: '',
93
+ Recursive: false,
94
+ }, _parentRelation);
95
+ this._lang = _lang;
96
+ this._mDescriptor = _mDescriptor;
97
+ this._relationQuery.from('intl_resources', this.Alias);
98
+ }
99
+ execute() {
100
+ this._query.middleware(new IntlModelMiddleware(this._lang, this._relationQuery, this._mDescriptor));
101
+ }
102
+ translate(_lang) {
103
+ // empty, cannot translate translation relation!
104
+ }
105
+ };
106
+ IntlModelRelation = __decorate([
107
+ (0, di_1.NewInstance)(),
108
+ __metadata("design:paramtypes", [String, orm_1.Orm, orm_1.SelectQueryBuilder, Object, orm_1.OrmRelation])
109
+ ], IntlModelRelation);
110
+ exports.IntlModelRelation = IntlModelRelation;
111
+ class IntlModelMiddleware {
112
+ constructor(_lang, _relationQuery, _description) {
113
+ this._lang = _lang;
114
+ this._relationQuery = _relationQuery;
115
+ this._description = _description;
116
+ }
117
+ afterQuery(data) {
118
+ return data;
119
+ }
120
+ modelCreation(_) {
121
+ return null;
122
+ }
123
+ async afterHydration(data) {
124
+ const self = this;
125
+ const pks = data.map((d) => {
126
+ return d[this._description.PrimaryKey];
127
+ });
128
+ const hydrateMiddleware = {
129
+ afterQuery(data) {
130
+ return data;
131
+ },
132
+ modelCreation() {
133
+ return null;
134
+ },
135
+ async afterHydration(relationData) {
136
+ data.forEach((d) => {
137
+ const relData = relationData.filter((rd) => {
138
+ return rd['ResourceId'] === d[self._description.PrimaryKey];
139
+ });
140
+ relData.forEach((rd) => {
141
+ d[rd.Column] = rd.Value;
142
+ });
143
+ d.Language = this._lang;
144
+ });
145
+ },
146
+ };
147
+ if (pks.length !== 0) {
148
+ this._relationQuery.whereIn('ResourceId', pks);
149
+ this._relationQuery.where('Resource', this._description.Name);
150
+ this._relationQuery.where('Lang', this._lang);
151
+ this._relationQuery.middleware(hydrateMiddleware);
152
+ return await this._relationQuery;
153
+ }
154
+ return [];
155
+ }
156
+ }
157
+ exports.IntlModelMiddleware = IntlModelMiddleware;
158
+ orm_1.SelectQueryBuilder.prototype['translate'] = function (lang) {
159
+ const descriptor = (0, orm_1.extractModelDescriptor)(this._model);
160
+ const relInstance = this._container.resolve(IntlModelRelation, [lang, this._container.get(orm_1.Orm), this, descriptor, this._owner]);
161
+ relInstance.execute();
162
+ // translate all other relations automatically
163
+ this._relations.forEach((r) => {
164
+ r.executeOnQuery(function () {
165
+ this.translate(lang);
166
+ });
167
+ });
168
+ this._relations.push(relInstance);
169
+ return this;
170
+ };
171
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oCAA0C;AAC1C,sCAAyM;AACzM,oDAAuB;AACvB,wDAAqD;AAYrD,MAAa,aAAc,SAAQ,eAAS;IAG1C;;;;OAIG;IACI,KAAK,CAAC,SAAS,CAAC,IAAY;QACjC,MAAM,YAAY,GAAG,MAAM,2BAAY,CAAC,KAAK,CAAC;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AAC;CACF;AA/CD,kDA+CC;AAEA,wBAAkB,CAAC,SAAiB,CAAC,WAAW,CAAC,GAAG,UAAoC,IAAY;IACnG,MAAM,UAAU,GAAG,IAAA,4BAAsB,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvD,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAG,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAChI,WAAW,CAAC,OAAO,EAAE,CAAC;IAEtB,8CAA8C;IAC9C,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QAC5B,CAAC,CAAC,cAAc,CAAC;YACf,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAClC,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ module.exports = intlOrm;
4
+
5
+ function intlOrm() {
6
+ // TODO
7
+ }
@@ -0,0 +1,5 @@
1
+ import { OrmMigration, OrmDriver } from '@spinajs/orm';
2
+ export declare class IntOrm_2022_06_28_01_13_00 extends OrmMigration {
3
+ up(connection: OrmDriver): Promise<void>;
4
+ down(_connection: OrmDriver): Promise<void>;
5
+ }
@@ -0,0 +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.IntOrm_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 IntOrm_2022_06_28_01_13_00 = class IntOrm_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
+ IntOrm_2022_06_28_01_13_00 = __decorate([
35
+ (0, orm_1.Migration)('default')
36
+ ], IntOrm_2022_06_28_01_13_00);
37
+ exports.IntOrm_2022_06_28_01_13_00 = IntOrm_2022_06_28_01_13_00;
38
+ //# sourceMappingURL=IntOrm_2022_06_28_01_13_00.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntOrm_2022_06_28_01_13_00.js","sourceRoot":"","sources":["../../src/migrations/IntOrm_2022_06_28_01_13_00.ts"],"names":[],"mappings":";;;;;;;;;AAAA,sDAAsD;AACtD,sCAAkE;AAGlE,IAAa,0BAA0B,GAAvC,MAAa,0BAA2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CAAC,uBAAuB,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,0BAA0B;IADtC,IAAA,eAAS,EAAC,SAAS,CAAC;GACR,0BAA0B,CAwBtC;AAxBY,gEAA0B"}
@@ -0,0 +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 IntlResource extends ModelBase {
8
+ ResourceId: number;
9
+ Resource: string;
10
+ Column: string;
11
+ Lang: string;
12
+ Value: string;
13
+ }
@@ -0,0 +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 = __decorate([
19
+ (0, orm_1.Connection)('default'),
20
+ (0, orm_1.Model)('intl_resources')
21
+ ], IntlResource);
22
+ exports.IntlResource = IntlResource;
23
+ //# sourceMappingURL=IntlResource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlResource.js","sourceRoot":"","sources":["../../src/models/IntlResource.ts"],"names":[],"mappings":";;;;;;;;;AAAA,sCAA4D;AAE5D;;;;GAIG;AAGH,IAAa,YAAY,GAAzB,MAAa,YAAa,SAAQ,eAAS;CAU1C,CAAA;AAVY,YAAY;IAFxB,IAAA,gBAAU,EAAC,SAAS,CAAC;IACrB,IAAA,WAAK,EAAC,gBAAgB,CAAC;GACX,YAAY,CAUxB;AAVY,oCAAY"}
@@ -0,0 +1,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
+ }
@@ -0,0 +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
+ __decorate([
22
+ (0, orm_1.Primary)(),
23
+ __metadata("design:type", Number)
24
+ ], IntlTranslation.prototype, "Id", void 0);
25
+ IntlTranslation = __decorate([
26
+ (0, orm_1.Connection)('default'),
27
+ (0, orm_1.Model)('intl_translations')
28
+ ], IntlTranslation);
29
+ exports.IntlTranslation = IntlTranslation;
30
+ //# sourceMappingURL=IntlTranslation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlTranslation.js","sourceRoot":"","sources":["../../src/models/IntlTranslation.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sCAAqE;AAErE;;;;GAIG;AAGH,IAAa,eAAe,GAA5B,MAAa,eAAgB,SAAQ,eAAS;CAS7C,CAAA;AAPC;IADC,IAAA,aAAO,GAAE;;2CACQ;AAFP,eAAe;IAF3B,IAAA,gBAAU,EAAC,SAAS,CAAC;IACrB,IAAA,WAAK,EAAC,mBAAmB,CAAC;GACd,eAAe,CAS3B;AATY,0CAAe"}
File without changes
@@ -0,0 +1,32 @@
1
+ // import { NewInstance } from '@spinajs/di';
2
+ // import { BelongsToRecursiveRelation, BelongsToRelation, ManyToManyRelation, OneToManyRelation } from '@spinajs/orm';
3
+ // declare module '@spinajs/orm' {
4
+ // export interface IOrmRelation {
5
+ // translate(lang: string): void;
6
+ // }
7
+ // }
8
+ // @NewInstance()
9
+ // export class IntlBelongsToRelation extends BelongsToRelation {
10
+ // public translate(lang: string): void {
11
+ // this._relationQuery.translate(lang);
12
+ // }
13
+ // }
14
+ // @NewInstance()
15
+ // export class IntlBelongsToRecursiveRelation extends BelongsToRecursiveRelation {
16
+ // public translate(lang: string): void {
17
+ // this._relationQuery.translate(lang);
18
+ // }
19
+ // }
20
+ // @NewInstance()
21
+ // export class IntlOneToManyRelation extends OneToManyRelation {
22
+ // public translate(lang: string): void {
23
+ // this._relationQuery.translate(lang);
24
+ // }
25
+ // }
26
+ // @NewInstance()
27
+ // export class IntlManyToManyRelation extends ManyToManyRelation {
28
+ // public translate(lang: string): void {
29
+ // this._relationQuery.translate(lang);
30
+ // }
31
+ // }
32
+ //# sourceMappingURL=relations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relations.js","sourceRoot":"","sources":["../src/relations.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,uHAAuH;AAEvH,kCAAkC;AAClC,oCAAoC;AACpC,qCAAqC;AACrC,MAAM;AACN,IAAI;AAEJ,iBAAiB;AACjB,iEAAiE;AACjE,2CAA2C;AAC3C,2CAA2C;AAC3C,MAAM;AACN,IAAI;AAEJ,iBAAiB;AACjB,mFAAmF;AACnF,2CAA2C;AAC3C,2CAA2C;AAC3C,MAAM;AACN,IAAI;AAEJ,iBAAiB;AACjB,iEAAiE;AACjE,2CAA2C;AAC3C,2CAA2C;AAC3C,MAAM;AACN,IAAI;AAEJ,iBAAiB;AACjB,mEAAmE;AACnE,2CAA2C;AAC3C,2CAA2C;AAC3C,MAAM;AACN,IAAI"}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@spinajs/intl-orm",
3
+ "version": "1.2.108",
4
+ "description": "Internationalization support for ORM module",
5
+ "main": "lib/index.js",
6
+ "private": false,
7
+ "scripts": {
8
+ "build": "npm run clean && npm run compile",
9
+ "compile": "tsc -p tsconfig.build.json",
10
+ "clean": "",
11
+ "test": "ts-mocha -p tsconfig.json test/**/*.test.ts",
12
+ "coverage": "nyc npm run test",
13
+ "build-docs": "rimraf docs && typedoc --options typedoc.json src/",
14
+ "prepare": "npm run build",
15
+ "format": "prettier --write \"src/**/*.ts\"",
16
+ "lint": "eslint -c .eslintrc.js --ext .ts src --fix",
17
+ "prepublishOnly": "npm test && npm run lint",
18
+ "preversion": "npm run lint",
19
+ "version": "npm run format && git add -A src",
20
+ "postversion": "git push && git push --tags"
21
+ },
22
+ "files": [
23
+ "lib/**/*"
24
+ ],
25
+ "types": "lib",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/spinajs/main.git"
29
+ },
30
+ "keywords": [
31
+ "spinajs",
32
+ "int orm"
33
+ ],
34
+ "author": "SpinaJS <spinajs@coderush.pl> (https://github.com/spinajs/main)",
35
+ "license": "MIT",
36
+ "bugs": {
37
+ "url": "https://github.com/spinajs/main/issues"
38
+ },
39
+ "homepage": "https://github.com/spinajs/main#readme",
40
+ "dependencies": {
41
+ "@spinajs/configuration": "^1.2.81",
42
+ "@spinajs/di": "^1.2.81",
43
+ "@spinajs/exceptions": "^1.2.81",
44
+ "@spinajs/intl": "^1.2.103",
45
+ "@spinajs/log": "^1.2.103",
46
+ "@spinajs/orm": "^1.2.108",
47
+ "@spinajs/reflection": "^1.2.103",
48
+ "luxon": "^2.4.0",
49
+ "typescript-mix": "^3.1.3"
50
+ },
51
+ "devDependencies": {
52
+ "@spinajs/orm-sqlite": "^1.2.108"
53
+ },
54
+ "gitHead": "81e996198a9d4dac8970f71181b0f5eaf6070918"
55
+ }