@spinajs/orm 2.0.180 → 2.0.181

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.
Files changed (91) hide show
  1. package/lib/cjs/builders.d.ts +643 -643
  2. package/lib/cjs/builders.js +1602 -1602
  3. package/lib/cjs/builders.js.map +1 -1
  4. package/lib/cjs/converters.d.ts +34 -34
  5. package/lib/cjs/converters.js +104 -104
  6. package/lib/cjs/decorators.d.ts +152 -152
  7. package/lib/cjs/decorators.js +449 -449
  8. package/lib/cjs/dehydrators.d.ts +10 -10
  9. package/lib/cjs/dehydrators.js +47 -47
  10. package/lib/cjs/driver.d.ts +82 -82
  11. package/lib/cjs/driver.js +102 -102
  12. package/lib/cjs/driver.js.map +1 -1
  13. package/lib/cjs/enums.d.ts +116 -116
  14. package/lib/cjs/enums.js +126 -126
  15. package/lib/cjs/enums.js.map +1 -1
  16. package/lib/cjs/exceptions.d.ts +6 -6
  17. package/lib/cjs/exceptions.js +10 -10
  18. package/lib/cjs/hydrators.d.ts +19 -19
  19. package/lib/cjs/hydrators.js +132 -132
  20. package/lib/cjs/hydrators.js.map +1 -1
  21. package/lib/cjs/index.d.ts +17 -17
  22. package/lib/cjs/index.js +33 -33
  23. package/lib/cjs/interfaces.d.ts +919 -919
  24. package/lib/cjs/interfaces.js +279 -279
  25. package/lib/cjs/interfaces.js.map +1 -1
  26. package/lib/cjs/middlewares.d.ts +62 -62
  27. package/lib/cjs/middlewares.js +258 -258
  28. package/lib/cjs/model.d.ts +284 -284
  29. package/lib/cjs/model.js +810 -810
  30. package/lib/cjs/orm.d.ts +61 -61
  31. package/lib/cjs/orm.js +333 -333
  32. package/lib/cjs/orm.js.map +1 -1
  33. package/lib/cjs/relation-objects.d.ts +108 -108
  34. package/lib/cjs/relation-objects.js +221 -221
  35. package/lib/cjs/relations.d.ts +61 -61
  36. package/lib/cjs/relations.js +194 -194
  37. package/lib/cjs/relations.js.map +1 -1
  38. package/lib/cjs/statements.d.ts +143 -143
  39. package/lib/cjs/statements.js +309 -309
  40. package/lib/cjs/statements.js.map +1 -1
  41. package/lib/cjs/types.d.ts +32 -32
  42. package/lib/cjs/types.js +2 -2
  43. package/lib/cjs/wrappers.d.ts +5 -5
  44. package/lib/cjs/wrappers.js +12 -12
  45. package/lib/mjs/builders.d.ts +643 -643
  46. package/lib/mjs/builders.js +1594 -1594
  47. package/lib/mjs/builders.js.map +1 -1
  48. package/lib/mjs/converters.d.ts +34 -34
  49. package/lib/mjs/converters.js +96 -96
  50. package/lib/mjs/decorators.d.ts +152 -152
  51. package/lib/mjs/decorators.js +422 -422
  52. package/lib/mjs/dehydrators.d.ts +10 -10
  53. package/lib/mjs/dehydrators.js +41 -41
  54. package/lib/mjs/driver.d.ts +82 -82
  55. package/lib/mjs/driver.js +98 -98
  56. package/lib/mjs/driver.js.map +1 -1
  57. package/lib/mjs/enums.d.ts +116 -116
  58. package/lib/mjs/enums.js +123 -123
  59. package/lib/mjs/enums.js.map +1 -1
  60. package/lib/mjs/exceptions.d.ts +6 -6
  61. package/lib/mjs/exceptions.js +6 -6
  62. package/lib/mjs/hydrators.d.ts +19 -19
  63. package/lib/mjs/hydrators.js +128 -128
  64. package/lib/mjs/hydrators.js.map +1 -1
  65. package/lib/mjs/index.d.ts +17 -17
  66. package/lib/mjs/index.js +17 -17
  67. package/lib/mjs/interfaces.d.ts +919 -919
  68. package/lib/mjs/interfaces.js +267 -267
  69. package/lib/mjs/interfaces.js.map +1 -1
  70. package/lib/mjs/middlewares.d.ts +62 -62
  71. package/lib/mjs/middlewares.js +249 -249
  72. package/lib/mjs/model.d.ts +284 -284
  73. package/lib/mjs/model.js +800 -800
  74. package/lib/mjs/orm.d.ts +61 -61
  75. package/lib/mjs/orm.js +326 -326
  76. package/lib/mjs/orm.js.map +1 -1
  77. package/lib/mjs/relation-objects.d.ts +108 -108
  78. package/lib/mjs/relation-objects.js +211 -211
  79. package/lib/mjs/relations.d.ts +61 -61
  80. package/lib/mjs/relations.js +191 -191
  81. package/lib/mjs/relations.js.map +1 -1
  82. package/lib/mjs/statements.d.ts +143 -143
  83. package/lib/mjs/statements.js +301 -301
  84. package/lib/mjs/statements.js.map +1 -1
  85. package/lib/mjs/types.d.ts +32 -32
  86. package/lib/mjs/types.js +1 -1
  87. package/lib/mjs/wrappers.d.ts +5 -5
  88. package/lib/mjs/wrappers.js +9 -9
  89. package/lib/tsconfig.cjs.tsbuildinfo +1 -1
  90. package/lib/tsconfig.mjs.tsbuildinfo +1 -1
  91. package/package.json +5 -5
@@ -1,222 +1,222 @@
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.OneToManyRelationList = exports.ManyToManyRelationList = exports.SingleRelation = exports.Relation = void 0;
7
- /* eslint-disable prettier/prettier */
8
- const interfaces_js_1 = require("./interfaces.js");
9
- const di_1 = require("@spinajs/di");
10
- const builders_js_1 = require("./builders.js");
11
- const model_js_1 = require("./model.js");
12
- const orm_js_1 = require("./orm.js");
13
- const lodash_1 = __importDefault(require("lodash"));
14
- /**
15
- * Iterable list of populated relation entities
16
- *
17
- * It allows to add / remove objects to relation
18
- */
19
- class Relation extends Array {
20
- constructor(owner, Model, Relation, objects) {
21
- super();
22
- this.owner = owner;
23
- this.Model = Model;
24
- this.Relation = Relation;
25
- this.Populated = false;
26
- if (objects) {
27
- this.push(...objects);
28
- }
29
- this.TargetModelDescriptor = (0, model_js_1.extractModelDescriptor)(Model);
30
- this.Orm = di_1.DI.get(orm_js_1.Orm);
31
- if (this.TargetModelDescriptor) {
32
- this.Driver = this.Orm.Connections.get(this.TargetModelDescriptor.Connection);
33
- }
34
- this.IsModelAForwardRef = !(0, di_1.isConstructor)(this.Model);
35
- }
36
- /**
37
- * Delete all objects from relation
38
- */
39
- async clear() {
40
- await this.remove(this);
41
- }
42
- empty() {
43
- this.length = 0;
44
- }
45
- /**
46
- * Populates this relation ( loads all data related to owner of this relation)
47
- */
48
- async populate(callback) {
49
- const query = this.Relation.TargetModel.where(this.Relation.ForeignKey, this.owner.PrimaryKeyValue);
50
- if (callback) {
51
- callback.apply(query);
52
- }
53
- const result = await query;
54
- if (result) {
55
- this.length = 0;
56
- this.push(...result);
57
- }
58
- this.Populated = true;
59
- }
60
- }
61
- exports.Relation = Relation;
62
- class SingleRelation {
63
- constructor(_owner, model, Relation, object) {
64
- this._owner = _owner;
65
- this.model = model;
66
- this.Relation = Relation;
67
- this.Populated = false;
68
- this.TargetModelDescriptor = (0, model_js_1.extractModelDescriptor)(model);
69
- this.Orm = di_1.DI.get(orm_js_1.Orm);
70
- this.Value = object;
71
- }
72
- async set(obj) {
73
- this.Value = obj;
74
- await this._owner.update();
75
- }
76
- attach(obj) {
77
- this.Value = obj;
78
- }
79
- detach() {
80
- this.Value = null;
81
- }
82
- async remove() {
83
- this.Value = null;
84
- await this.Value.destroy();
85
- await this._owner.update();
86
- }
87
- async populate(callback) {
88
- /**
89
- * Do little cheat - we construct query that loads initial model with given relation.
90
- * Then we only assign relation property.
91
- *
92
- * TODO: create only relation query without loading its owner.
93
- */
94
- const query = (0, model_js_1.createQuery)(this.Relation.TargetModel, (builders_js_1.SelectQueryBuilder)).query;
95
- const desc = (0, model_js_1.extractModelDescriptor)(this.Relation.TargetModel);
96
- query.where({ [desc.PrimaryKey]: this._owner[this.Relation.ForeignKey] });
97
- if (callback) {
98
- callback.apply(query);
99
- }
100
- const result = await query.firstOrFail();
101
- if (result) {
102
- this.Value = result;
103
- }
104
- this.Populated = true;
105
- }
106
- }
107
- exports.SingleRelation = SingleRelation;
108
- class ManyToManyRelationList extends Relation {
109
- intersection(_obj, _callback) {
110
- throw new Error('Method not implemented.');
111
- }
112
- union(_obj, _mode) {
113
- throw new Error('Method not implemented.');
114
- }
115
- diff(_obj, _callback) {
116
- throw new Error('Method not implemented.');
117
- }
118
- set(_obj, _callback) {
119
- throw new Error('Method not implemented.');
120
- }
121
- async remove(obj) {
122
- const self = this;
123
- const data = (Array.isArray(obj) ? obj : [obj]).map((d) => d.PrimaryKeyValue);
124
- const jmodelDescriptor = (0, model_js_1.extractModelDescriptor)(this.Relation.JunctionModel);
125
- const query = this.Driver.del()
126
- .from(jmodelDescriptor.TableName)
127
- .where(function () {
128
- this.whereIn(self.Relation.JunctionModelTargetModelFKey_Name, data);
129
- this.andWhere(self.Relation.JunctionModelSourceModelFKey_Name, self.owner.PrimaryKeyValue);
130
- });
131
- if (this.Driver.Options.Database) {
132
- query.database(this.Driver.Options.Database);
133
- }
134
- await query;
135
- lodash_1.default.remove(this, (o) => data.indexOf(o.PrimaryKeyValue) !== -1);
136
- }
137
- async add(obj, mode) {
138
- const data = Array.isArray(obj) ? obj : [obj];
139
- const relEntities = data.map((d) => {
140
- const relEntity = new this.Relation.JunctionModel();
141
- relEntity[this.Relation.JunctionModelSourceModelFKey_Name] = this.owner.PrimaryKeyValue;
142
- relEntity[this.Relation.JunctionModelTargetModelFKey_Name] = d.PrimaryKeyValue;
143
- return relEntity;
144
- });
145
- for (const m of relEntities) {
146
- await m.insert(mode);
147
- }
148
- this.push(...data);
149
- }
150
- }
151
- exports.ManyToManyRelationList = ManyToManyRelationList;
152
- class OneToManyRelationList extends Relation {
153
- async deleteRelationData(data) {
154
- if (data.length === 0) {
155
- return;
156
- }
157
- const self = this;
158
- const query = this.Driver.del()
159
- .from(this.TargetModelDescriptor.TableName)
160
- .andWhere(function () {
161
- this.whereNotIn(self.Relation.PrimaryKey, data.filter((x) => x.PrimaryKeyValue).map((x) => x.PrimaryKeyValue));
162
- this.where(self.Relation.ForeignKey, self.owner.PrimaryKeyValue);
163
- });
164
- if (this.Driver.Options.Database) {
165
- query.database(this.Driver.Options.Database);
166
- }
167
- await query;
168
- this.empty();
169
- }
170
- async diff(dataset, callback) {
171
- // calculate difference between this data in relation and dataset ( objects from this relation)
172
- const result = callback ? lodash_1.default.differenceWith(dataset, [...this], callback) : lodash_1.default.differenceBy(dataset, [...this], this.TargetModelDescriptor.PrimaryKey);
173
- // calculate difference between dataset and data in this relation ( objects from dataset )
174
- const result2 = callback ? lodash_1.default.differenceWith([...this], dataset, callback) : lodash_1.default.differenceBy([...this], dataset, this.TargetModelDescriptor.PrimaryKey);
175
- // combine difference from two sets
176
- const finalDiff = [...result, ...result2];
177
- await this.deleteRelationData(finalDiff);
178
- await this.add(finalDiff, interfaces_js_1.InsertBehaviour.InsertOrUpdate);
179
- }
180
- async set(obj) {
181
- await this.deleteRelationData(obj);
182
- await this.add(obj, interfaces_js_1.InsertBehaviour.InsertOrUpdate);
183
- }
184
- async intersection(obj, callback) {
185
- const result = callback ? lodash_1.default.intersectionWith(obj, [...this], callback) : lodash_1.default.intersectionBy(obj, [...this], this.TargetModelDescriptor.PrimaryKey);
186
- await this.deleteRelationData(result);
187
- await this.add(result, interfaces_js_1.InsertBehaviour.InsertOrUpdate);
188
- }
189
- async union(obj, mode) {
190
- await this.add(obj, mode ?? interfaces_js_1.InsertBehaviour.InsertOrIgnore);
191
- }
192
- async remove(obj) {
193
- const data = (Array.isArray(obj) ? obj : [obj]).map((d) => d.PrimaryKeyValue);
194
- const query = this.Driver.del().whereIn(this.Relation.ForeignKey, data).setTable(this.TargetModelDescriptor.TableName);
195
- if (this.Driver.Options.Database) {
196
- query.database(this.Driver.Options.Database);
197
- }
198
- await query;
199
- lodash_1.default.remove(this, (o) => data.indexOf(o.PrimaryKeyValue) !== -1);
200
- }
201
- async add(obj, mode) {
202
- const data = Array.isArray(obj) ? obj : [obj];
203
- const tInsert = data.map((x) => {
204
- if (x instanceof model_js_1.ModelBase) {
205
- return x;
206
- }
207
- if (this.IsModelAForwardRef) {
208
- new (this.Model())(x);
209
- }
210
- return new this.Model(x);
211
- });
212
- data.forEach((d) => {
213
- d[this.Relation.ForeignKey] = this.owner.PrimaryKeyValue;
214
- });
215
- for (const m of tInsert) {
216
- await m.insertOrUpdate(mode);
217
- }
218
- this.push(...tInsert);
219
- }
220
- }
221
- exports.OneToManyRelationList = OneToManyRelationList;
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.OneToManyRelationList = exports.ManyToManyRelationList = exports.SingleRelation = exports.Relation = void 0;
7
+ /* eslint-disable prettier/prettier */
8
+ const interfaces_js_1 = require("./interfaces.js");
9
+ const di_1 = require("@spinajs/di");
10
+ const builders_js_1 = require("./builders.js");
11
+ const model_js_1 = require("./model.js");
12
+ const orm_js_1 = require("./orm.js");
13
+ const lodash_1 = __importDefault(require("lodash"));
14
+ /**
15
+ * Iterable list of populated relation entities
16
+ *
17
+ * It allows to add / remove objects to relation
18
+ */
19
+ class Relation extends Array {
20
+ constructor(owner, Model, Relation, objects) {
21
+ super();
22
+ this.owner = owner;
23
+ this.Model = Model;
24
+ this.Relation = Relation;
25
+ this.Populated = false;
26
+ if (objects) {
27
+ this.push(...objects);
28
+ }
29
+ this.TargetModelDescriptor = (0, model_js_1.extractModelDescriptor)(Model);
30
+ this.Orm = di_1.DI.get(orm_js_1.Orm);
31
+ if (this.TargetModelDescriptor) {
32
+ this.Driver = this.Orm.Connections.get(this.TargetModelDescriptor.Connection);
33
+ }
34
+ this.IsModelAForwardRef = !(0, di_1.isConstructor)(this.Model);
35
+ }
36
+ /**
37
+ * Delete all objects from relation
38
+ */
39
+ async clear() {
40
+ await this.remove(this);
41
+ }
42
+ empty() {
43
+ this.length = 0;
44
+ }
45
+ /**
46
+ * Populates this relation ( loads all data related to owner of this relation)
47
+ */
48
+ async populate(callback) {
49
+ const query = this.Relation.TargetModel.where(this.Relation.ForeignKey, this.owner.PrimaryKeyValue);
50
+ if (callback) {
51
+ callback.apply(query);
52
+ }
53
+ const result = await query;
54
+ if (result) {
55
+ this.length = 0;
56
+ this.push(...result);
57
+ }
58
+ this.Populated = true;
59
+ }
60
+ }
61
+ exports.Relation = Relation;
62
+ class SingleRelation {
63
+ constructor(_owner, model, Relation, object) {
64
+ this._owner = _owner;
65
+ this.model = model;
66
+ this.Relation = Relation;
67
+ this.Populated = false;
68
+ this.TargetModelDescriptor = (0, model_js_1.extractModelDescriptor)(model);
69
+ this.Orm = di_1.DI.get(orm_js_1.Orm);
70
+ this.Value = object;
71
+ }
72
+ async set(obj) {
73
+ this.Value = obj;
74
+ await this._owner.update();
75
+ }
76
+ attach(obj) {
77
+ this.Value = obj;
78
+ }
79
+ detach() {
80
+ this.Value = null;
81
+ }
82
+ async remove() {
83
+ this.Value = null;
84
+ await this.Value.destroy();
85
+ await this._owner.update();
86
+ }
87
+ async populate(callback) {
88
+ /**
89
+ * Do little cheat - we construct query that loads initial model with given relation.
90
+ * Then we only assign relation property.
91
+ *
92
+ * TODO: create only relation query without loading its owner.
93
+ */
94
+ const query = (0, model_js_1.createQuery)(this.Relation.TargetModel, (builders_js_1.SelectQueryBuilder)).query;
95
+ const desc = (0, model_js_1.extractModelDescriptor)(this.Relation.TargetModel);
96
+ query.where({ [desc.PrimaryKey]: this._owner[this.Relation.ForeignKey] });
97
+ if (callback) {
98
+ callback.apply(query);
99
+ }
100
+ const result = await query.firstOrFail();
101
+ if (result) {
102
+ this.Value = result;
103
+ }
104
+ this.Populated = true;
105
+ }
106
+ }
107
+ exports.SingleRelation = SingleRelation;
108
+ class ManyToManyRelationList extends Relation {
109
+ intersection(_obj, _callback) {
110
+ throw new Error('Method not implemented.');
111
+ }
112
+ union(_obj, _mode) {
113
+ throw new Error('Method not implemented.');
114
+ }
115
+ diff(_obj, _callback) {
116
+ throw new Error('Method not implemented.');
117
+ }
118
+ set(_obj, _callback) {
119
+ throw new Error('Method not implemented.');
120
+ }
121
+ async remove(obj) {
122
+ const self = this;
123
+ const data = (Array.isArray(obj) ? obj : [obj]).map((d) => d.PrimaryKeyValue);
124
+ const jmodelDescriptor = (0, model_js_1.extractModelDescriptor)(this.Relation.JunctionModel);
125
+ const query = this.Driver.del()
126
+ .from(jmodelDescriptor.TableName)
127
+ .where(function () {
128
+ this.whereIn(self.Relation.JunctionModelTargetModelFKey_Name, data);
129
+ this.andWhere(self.Relation.JunctionModelSourceModelFKey_Name, self.owner.PrimaryKeyValue);
130
+ });
131
+ if (this.Driver.Options.Database) {
132
+ query.database(this.Driver.Options.Database);
133
+ }
134
+ await query;
135
+ lodash_1.default.remove(this, (o) => data.indexOf(o.PrimaryKeyValue) !== -1);
136
+ }
137
+ async add(obj, mode) {
138
+ const data = Array.isArray(obj) ? obj : [obj];
139
+ const relEntities = data.map((d) => {
140
+ const relEntity = new this.Relation.JunctionModel();
141
+ relEntity[this.Relation.JunctionModelSourceModelFKey_Name] = this.owner.PrimaryKeyValue;
142
+ relEntity[this.Relation.JunctionModelTargetModelFKey_Name] = d.PrimaryKeyValue;
143
+ return relEntity;
144
+ });
145
+ for (const m of relEntities) {
146
+ await m.insert(mode);
147
+ }
148
+ this.push(...data);
149
+ }
150
+ }
151
+ exports.ManyToManyRelationList = ManyToManyRelationList;
152
+ class OneToManyRelationList extends Relation {
153
+ async deleteRelationData(data) {
154
+ if (data.length === 0) {
155
+ return;
156
+ }
157
+ const self = this;
158
+ const query = this.Driver.del()
159
+ .from(this.TargetModelDescriptor.TableName)
160
+ .andWhere(function () {
161
+ this.whereNotIn(self.Relation.PrimaryKey, data.filter((x) => x.PrimaryKeyValue).map((x) => x.PrimaryKeyValue));
162
+ this.where(self.Relation.ForeignKey, self.owner.PrimaryKeyValue);
163
+ });
164
+ if (this.Driver.Options.Database) {
165
+ query.database(this.Driver.Options.Database);
166
+ }
167
+ await query;
168
+ this.empty();
169
+ }
170
+ async diff(dataset, callback) {
171
+ // calculate difference between this data in relation and dataset ( objects from this relation)
172
+ const result = callback ? lodash_1.default.differenceWith(dataset, [...this], callback) : lodash_1.default.differenceBy(dataset, [...this], this.TargetModelDescriptor.PrimaryKey);
173
+ // calculate difference between dataset and data in this relation ( objects from dataset )
174
+ const result2 = callback ? lodash_1.default.differenceWith([...this], dataset, callback) : lodash_1.default.differenceBy([...this], dataset, this.TargetModelDescriptor.PrimaryKey);
175
+ // combine difference from two sets
176
+ const finalDiff = [...result, ...result2];
177
+ await this.deleteRelationData(finalDiff);
178
+ await this.add(finalDiff, interfaces_js_1.InsertBehaviour.InsertOrUpdate);
179
+ }
180
+ async set(obj) {
181
+ await this.deleteRelationData(obj);
182
+ await this.add(obj, interfaces_js_1.InsertBehaviour.InsertOrUpdate);
183
+ }
184
+ async intersection(obj, callback) {
185
+ const result = callback ? lodash_1.default.intersectionWith(obj, [...this], callback) : lodash_1.default.intersectionBy(obj, [...this], this.TargetModelDescriptor.PrimaryKey);
186
+ await this.deleteRelationData(result);
187
+ await this.add(result, interfaces_js_1.InsertBehaviour.InsertOrUpdate);
188
+ }
189
+ async union(obj, mode) {
190
+ await this.add(obj, mode ?? interfaces_js_1.InsertBehaviour.InsertOrIgnore);
191
+ }
192
+ async remove(obj) {
193
+ const data = (Array.isArray(obj) ? obj : [obj]).map((d) => d.PrimaryKeyValue);
194
+ const query = this.Driver.del().whereIn(this.Relation.ForeignKey, data).setTable(this.TargetModelDescriptor.TableName);
195
+ if (this.Driver.Options.Database) {
196
+ query.database(this.Driver.Options.Database);
197
+ }
198
+ await query;
199
+ lodash_1.default.remove(this, (o) => data.indexOf(o.PrimaryKeyValue) !== -1);
200
+ }
201
+ async add(obj, mode) {
202
+ const data = Array.isArray(obj) ? obj : [obj];
203
+ const tInsert = data.map((x) => {
204
+ if (x instanceof model_js_1.ModelBase) {
205
+ return x;
206
+ }
207
+ if (this.IsModelAForwardRef) {
208
+ new (this.Model())(x);
209
+ }
210
+ return new this.Model(x);
211
+ });
212
+ data.forEach((d) => {
213
+ d[this.Relation.ForeignKey] = this.owner.PrimaryKeyValue;
214
+ });
215
+ for (const m of tInsert) {
216
+ await m.insertOrUpdate(mode);
217
+ }
218
+ this.push(...tInsert);
219
+ }
220
+ }
221
+ exports.OneToManyRelationList = OneToManyRelationList;
222
222
  //# sourceMappingURL=relation-objects.js.map
@@ -1,62 +1,62 @@
1
- import { IRelationDescriptor, IModelDescriptor, ForwardRefFunction, ISelectQueryBuilder } from './interfaces.js';
2
- import { Constructor, Container } from '@spinajs/di';
3
- import { ModelBase } from './model.js';
4
- import { Orm } from './orm.js';
5
- import { OrmDriver } from './driver.js';
6
- export interface IOrmRelation {
7
- /**
8
- * Executes relation, should be called only once.
9
- *
10
- * @param callback - optional callback to perform actions on relations eg. populate more, filter relational data etc.
11
- */
12
- execute(callback?: (this: ISelectQueryBuilder, relation: OrmRelation) => void): void;
13
- /**
14
- * Execute actions on relation query, does not initialize relation. Use it only AFTER execute was called.
15
- *
16
- * @param callback - execute callback to perform actions on relations eg. populate more, filter relational data etc.
17
- */
18
- executeOnQuery(callback: (this: ISelectQueryBuilder, relation: OrmRelation) => void): void;
19
- /**
20
- * Relation name
21
- */
22
- Name: string;
23
- }
24
- export declare abstract class OrmRelation implements IOrmRelation {
25
- protected _container: Container;
26
- protected _query: ISelectQueryBuilder;
27
- protected _description: IRelationDescriptor;
28
- parentRelation?: OrmRelation;
29
- protected _targetModel: Constructor<ModelBase> | ForwardRefFunction;
30
- protected _targetModelDescriptor: IModelDescriptor;
31
- protected _relationQuery: ISelectQueryBuilder;
32
- protected _separator: string;
33
- protected _driver: OrmDriver;
34
- Name: string;
35
- get Alias(): string;
36
- constructor(_container: Container, _query: ISelectQueryBuilder, _description: IRelationDescriptor, parentRelation?: OrmRelation);
37
- abstract execute(callback?: (this: ISelectQueryBuilder, relation: OrmRelation) => void): void;
38
- executeOnQuery(callback: (this: ISelectQueryBuilder<any>, relation: OrmRelation) => void): void;
39
- }
40
- export declare class BelongsToRelation extends OrmRelation {
41
- constructor(_container: Container, _query: ISelectQueryBuilder<any>, _description: IRelationDescriptor, _parentRelation?: OrmRelation);
42
- execute(callback: (this: ISelectQueryBuilder, relation: OrmRelation) => void): void;
43
- }
44
- export declare class BelongsToRecursiveRelation extends OrmRelation {
45
- constructor(_container: Container, _query: ISelectQueryBuilder<any>, _description: IRelationDescriptor, _parentRelation?: OrmRelation);
46
- execute(callback: (this: ISelectQueryBuilder, relation: OrmRelation) => void): void;
47
- }
48
- export declare class OneToManyRelation extends OrmRelation {
49
- constructor(_container: Container, _query: ISelectQueryBuilder<any>, _description: IRelationDescriptor, _parentRelation?: OrmRelation);
50
- execute(callback?: (this: ISelectQueryBuilder<any>, relation: OrmRelation) => void): void;
51
- }
52
- export declare class ManyToManyRelation extends OrmRelation {
53
- protected _orm: Orm;
54
- protected _joinModel: Constructor<ModelBase>;
55
- protected _joinModelDescriptor: IModelDescriptor;
56
- protected _joinQuery: ISelectQueryBuilder;
57
- get TableJoinQuery(): ISelectQueryBuilder<unknown>;
58
- get RelationQuery(): ISelectQueryBuilder<unknown>;
59
- constructor(_container: Container, _orm: Orm, _query: ISelectQueryBuilder<any>, _description: IRelationDescriptor, _parentRelation?: OrmRelation);
60
- execute(callback?: (this: ISelectQueryBuilder<any>, relation: OrmRelation) => void): void;
61
- }
1
+ import { IRelationDescriptor, IModelDescriptor, ForwardRefFunction, ISelectQueryBuilder } from './interfaces.js';
2
+ import { Constructor, Container } from '@spinajs/di';
3
+ import { ModelBase } from './model.js';
4
+ import { Orm } from './orm.js';
5
+ import { OrmDriver } from './driver.js';
6
+ export interface IOrmRelation {
7
+ /**
8
+ * Executes relation, should be called only once.
9
+ *
10
+ * @param callback - optional callback to perform actions on relations eg. populate more, filter relational data etc.
11
+ */
12
+ execute(callback?: (this: ISelectQueryBuilder, relation: OrmRelation) => void): void;
13
+ /**
14
+ * Execute actions on relation query, does not initialize relation. Use it only AFTER execute was called.
15
+ *
16
+ * @param callback - execute callback to perform actions on relations eg. populate more, filter relational data etc.
17
+ */
18
+ executeOnQuery(callback: (this: ISelectQueryBuilder, relation: OrmRelation) => void): void;
19
+ /**
20
+ * Relation name
21
+ */
22
+ Name: string;
23
+ }
24
+ export declare abstract class OrmRelation implements IOrmRelation {
25
+ protected _container: Container;
26
+ protected _query: ISelectQueryBuilder;
27
+ protected _description: IRelationDescriptor;
28
+ parentRelation?: OrmRelation;
29
+ protected _targetModel: Constructor<ModelBase> | ForwardRefFunction;
30
+ protected _targetModelDescriptor: IModelDescriptor;
31
+ protected _relationQuery: ISelectQueryBuilder;
32
+ protected _separator: string;
33
+ protected _driver: OrmDriver;
34
+ Name: string;
35
+ get Alias(): string;
36
+ constructor(_container: Container, _query: ISelectQueryBuilder, _description: IRelationDescriptor, parentRelation?: OrmRelation);
37
+ abstract execute(callback?: (this: ISelectQueryBuilder, relation: OrmRelation) => void): void;
38
+ executeOnQuery(callback: (this: ISelectQueryBuilder<any>, relation: OrmRelation) => void): void;
39
+ }
40
+ export declare class BelongsToRelation extends OrmRelation {
41
+ constructor(_container: Container, _query: ISelectQueryBuilder<any>, _description: IRelationDescriptor, _parentRelation?: OrmRelation);
42
+ execute(callback: (this: ISelectQueryBuilder, relation: OrmRelation) => void): void;
43
+ }
44
+ export declare class BelongsToRecursiveRelation extends OrmRelation {
45
+ constructor(_container: Container, _query: ISelectQueryBuilder<any>, _description: IRelationDescriptor, _parentRelation?: OrmRelation);
46
+ execute(callback: (this: ISelectQueryBuilder, relation: OrmRelation) => void): void;
47
+ }
48
+ export declare class OneToManyRelation extends OrmRelation {
49
+ constructor(_container: Container, _query: ISelectQueryBuilder<any>, _description: IRelationDescriptor, _parentRelation?: OrmRelation);
50
+ execute(callback?: (this: ISelectQueryBuilder<any>, relation: OrmRelation) => void): void;
51
+ }
52
+ export declare class ManyToManyRelation extends OrmRelation {
53
+ protected _orm: Orm;
54
+ protected _joinModel: Constructor<ModelBase>;
55
+ protected _joinModelDescriptor: IModelDescriptor;
56
+ protected _joinQuery: ISelectQueryBuilder;
57
+ get TableJoinQuery(): ISelectQueryBuilder<unknown>;
58
+ get RelationQuery(): ISelectQueryBuilder<unknown>;
59
+ constructor(_container: Container, _orm: Orm, _query: ISelectQueryBuilder<any>, _description: IRelationDescriptor, _parentRelation?: OrmRelation);
60
+ execute(callback?: (this: ISelectQueryBuilder<any>, relation: OrmRelation) => void): void;
61
+ }
62
62
  //# sourceMappingURL=relations.d.ts.map