@sqb/connect 4.0.13 → 4.1.0
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/dist/client/Adapter.d.ts +1 -1
- package/dist/client/Cursor.d.ts +2 -2
- package/dist/client/Cursor.js +3 -3
- package/dist/client/CursorStream.js +1 -1
- package/dist/client/SqbClient.d.ts +2 -2
- package/dist/client/SqbClient.js +5 -5
- package/dist/client/SqbConnection.d.ts +3 -3
- package/dist/client/SqbConnection.js +7 -7
- package/dist/client/helpers.d.ts +2 -2
- package/dist/client/types.d.ts +4 -4
- package/dist/index.d.ts +19 -15
- package/dist/index.js +20 -16
- package/dist/orm/base-entity.d.ts +8 -0
- package/dist/orm/base-entity.js +28 -0
- package/dist/orm/commands/command.helper.d.ts +4 -4
- package/dist/orm/commands/command.helper.js +5 -3
- package/dist/orm/commands/count.command.d.ts +3 -3
- package/dist/orm/commands/create.command.d.ts +4 -4
- package/dist/orm/commands/create.command.js +13 -7
- package/dist/orm/commands/destroy.command.d.ts +3 -3
- package/dist/orm/commands/find.command.d.ts +9 -9
- package/dist/orm/commands/find.command.js +13 -11
- package/dist/orm/commands/row-converter.d.ts +4 -4
- package/dist/orm/commands/update.command.d.ts +5 -5
- package/dist/orm/commands/update.command.js +7 -5
- package/dist/orm/decorators/column.decorator.d.ts +2 -2
- package/dist/orm/decorators/column.decorator.js +13 -4
- package/dist/orm/decorators/embedded.decorator.d.ts +3 -2
- package/dist/orm/decorators/embedded.decorator.js +6 -7
- package/dist/orm/decorators/entity.decorator.d.ts +31 -4
- package/dist/orm/decorators/entity.decorator.js +142 -5
- package/dist/orm/decorators/events.decorator.js +13 -25
- package/dist/orm/decorators/foreignkey.decorator.js +3 -3
- package/dist/orm/decorators/index.decorator.d.ts +3 -3
- package/dist/orm/decorators/index.decorator.js +5 -6
- package/dist/orm/decorators/link.decorator.d.ts +1 -1
- package/dist/orm/decorators/link.decorator.js +3 -3
- package/dist/orm/decorators/primarykey.decorator.d.ts +3 -3
- package/dist/orm/decorators/primarykey.decorator.js +7 -6
- package/dist/orm/decorators/transform.decorator.js +5 -5
- package/dist/orm/model/association-element-metadata.d.ts +10 -0
- package/dist/orm/model/association-element-metadata.js +15 -0
- package/dist/orm/model/association.d.ts +6 -6
- package/dist/orm/model/association.js +9 -8
- package/dist/orm/model/{entity-column-element.d.ts → column-element-metadata.d.ts} +21 -10
- package/dist/orm/model/column-element-metadata.js +32 -0
- package/dist/orm/model/element-metadata.d.ts +7 -0
- package/dist/orm/model/element-metadata.js +2 -0
- package/dist/orm/model/embedded-element-metadata.d.ts +14 -0
- package/dist/orm/model/embedded-element-metadata.js +28 -0
- package/dist/orm/model/entity-metadata.d.ts +49 -0
- package/dist/orm/model/entity-metadata.js +329 -0
- package/dist/orm/model/index-metadata.d.ts +18 -0
- package/dist/orm/model/index-metadata.js +2 -0
- package/dist/orm/orm.const.d.ts +1 -1
- package/dist/orm/orm.const.js +3 -3
- package/dist/orm/orm.type.d.ts +1 -92
- package/dist/orm/repository.class.d.ts +5 -4
- package/dist/orm/repository.class.js +27 -5
- package/dist/orm/util/apply-mixins.d.ts +1 -0
- package/dist/orm/util/apply-mixins.js +12 -0
- package/dist/orm/util/extract-keyvalues.d.ts +2 -2
- package/dist/orm/util/extract-keyvalues.js +3 -2
- package/dist/orm/util/orm.helper.d.ts +8 -9
- package/dist/orm/util/orm.helper.js +8 -9
- package/dist/orm/util/serialize-element.d.ts +2 -2
- package/package.json +10 -10
- package/dist/orm/base-entity.class.d.ts +0 -16
- package/dist/orm/base-entity.class.js +0 -56
- package/dist/orm/model/abstract-entityelement.d.ts +0 -8
- package/dist/orm/model/abstract-entityelement.js +0 -10
- package/dist/orm/model/entity-association-element.d.ts +0 -9
- package/dist/orm/model/entity-association-element.js +0 -13
- package/dist/orm/model/entity-column-element.js +0 -27
- package/dist/orm/model/entity-model.d.ts +0 -59
- package/dist/orm/model/entity-model.js +0 -295
- package/dist/orm/model/entity-object-element.d.ts +0 -12
- package/dist/orm/model/entity-object-element.js +0 -24
- package/dist/orm/model/index-meta.d.ts +0 -9
- package/dist/orm/model/index-meta.js +0 -16
- package/dist/orm/util/entity-mapping.d.ts +0 -12
- package/dist/orm/util/entity-mapping.js +0 -154
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EntityModel = void 0;
|
|
4
|
-
const builder_1 = require("@sqb/builder");
|
|
5
|
-
const orm_const_1 = require("../orm.const");
|
|
6
|
-
const index_meta_1 = require("./index-meta");
|
|
7
|
-
const association_1 = require("./association");
|
|
8
|
-
const entity_column_element_1 = require("./entity-column-element");
|
|
9
|
-
const entity_object_element_1 = require("./entity-object-element");
|
|
10
|
-
const entity_association_element_1 = require("./entity-association-element");
|
|
11
|
-
const serialize_element_1 = require("../util/serialize-element");
|
|
12
|
-
const orm_helper_1 = require("../util/orm.helper");
|
|
13
|
-
class EntityModel {
|
|
14
|
-
constructor(ctor) {
|
|
15
|
-
this.ctor = ctor;
|
|
16
|
-
this.elements = new Map();
|
|
17
|
-
this.indexes = [];
|
|
18
|
-
this.foreignKeys = [];
|
|
19
|
-
this.eventListeners = [];
|
|
20
|
-
this.name = ctor.name;
|
|
21
|
-
}
|
|
22
|
-
get elementKeys() {
|
|
23
|
-
if (!(this._elementKeys && this.hasOwnProperty('_elementKeys')))
|
|
24
|
-
this._elementKeys = Array.from(this.elements.keys());
|
|
25
|
-
return this._elementKeys;
|
|
26
|
-
}
|
|
27
|
-
getElement(name) {
|
|
28
|
-
if (!name)
|
|
29
|
-
return;
|
|
30
|
-
return this.elements.get(name.toLowerCase());
|
|
31
|
-
}
|
|
32
|
-
getColumnElement(name) {
|
|
33
|
-
if (!name)
|
|
34
|
-
return;
|
|
35
|
-
const prop = this.elements.get(name.toLowerCase());
|
|
36
|
-
return (0, orm_helper_1.isColumnElement)(prop) ? prop : undefined;
|
|
37
|
-
}
|
|
38
|
-
getColumnElementByFieldName(fieldName) {
|
|
39
|
-
if (!fieldName)
|
|
40
|
-
return;
|
|
41
|
-
fieldName = fieldName.toLowerCase();
|
|
42
|
-
for (const prop of this.elements.values()) {
|
|
43
|
-
if ((0, orm_helper_1.isColumnElement)(prop) && prop.fieldName.toLowerCase() === fieldName)
|
|
44
|
-
return prop;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
getObjectElement(name) {
|
|
48
|
-
if (!name)
|
|
49
|
-
return;
|
|
50
|
-
const col = this.elements.get(name.toLowerCase());
|
|
51
|
-
return (0, orm_helper_1.isObjectElement)(col) ? col : undefined;
|
|
52
|
-
}
|
|
53
|
-
getAssociationElement(name) {
|
|
54
|
-
if (!name)
|
|
55
|
-
return;
|
|
56
|
-
const col = this.elements.get(name.toLowerCase());
|
|
57
|
-
return (0, orm_helper_1.isAssociationElement)(col) ? col : undefined;
|
|
58
|
-
}
|
|
59
|
-
defineColumnElement(propertyKey, options) {
|
|
60
|
-
let prop = this.getElement(propertyKey);
|
|
61
|
-
if (!prop || !(0, orm_helper_1.isColumnElement)(prop)) {
|
|
62
|
-
prop = new entity_column_element_1.EntityColumnElement(this, propertyKey, options);
|
|
63
|
-
if (!prop.type) {
|
|
64
|
-
const typ = Reflect.getMetadata("design:type", this.ctor.prototype, propertyKey);
|
|
65
|
-
if (typ === Array) {
|
|
66
|
-
prop.type = String;
|
|
67
|
-
prop.isArray = true;
|
|
68
|
-
}
|
|
69
|
-
else
|
|
70
|
-
prop.type = typ;
|
|
71
|
-
}
|
|
72
|
-
if (!prop.dataType) {
|
|
73
|
-
if (prop.type === Boolean)
|
|
74
|
-
prop.dataType = builder_1.DataType.BOOL;
|
|
75
|
-
else if (prop.type === String)
|
|
76
|
-
prop.dataType = builder_1.DataType.VARCHAR;
|
|
77
|
-
else if (prop.type === Number)
|
|
78
|
-
prop.dataType = builder_1.DataType.NUMBER;
|
|
79
|
-
else if (prop.type === Date)
|
|
80
|
-
prop.dataType = builder_1.DataType.TIMESTAMP;
|
|
81
|
-
else if (prop.type === Array) {
|
|
82
|
-
prop.dataType = builder_1.DataType.VARCHAR;
|
|
83
|
-
prop.isArray = true;
|
|
84
|
-
}
|
|
85
|
-
else if (prop.type === Buffer)
|
|
86
|
-
prop.dataType = builder_1.DataType.BINARY;
|
|
87
|
-
}
|
|
88
|
-
if (options?.isArray)
|
|
89
|
-
prop.isArray = true;
|
|
90
|
-
if (!this.elements.has(propertyKey.toLowerCase()))
|
|
91
|
-
this.elementKeys.push(propertyKey);
|
|
92
|
-
this.elements.set(propertyKey.toLowerCase(), prop);
|
|
93
|
-
}
|
|
94
|
-
else if (options)
|
|
95
|
-
prop.assign(options);
|
|
96
|
-
return prop;
|
|
97
|
-
}
|
|
98
|
-
defineAssociationElement(propertyKey, association) {
|
|
99
|
-
const prop = new entity_association_element_1.EntityAssociationElement(this, propertyKey, association);
|
|
100
|
-
let l = association;
|
|
101
|
-
let i = 1;
|
|
102
|
-
while (l) {
|
|
103
|
-
l.name = this.name + '.' + propertyKey + '#' + (i++);
|
|
104
|
-
l = l.next;
|
|
105
|
-
}
|
|
106
|
-
if (!this.elements.has(propertyKey.toLowerCase()))
|
|
107
|
-
this.elementKeys.push(propertyKey);
|
|
108
|
-
this.elements.set(propertyKey.toLowerCase(), prop);
|
|
109
|
-
return prop;
|
|
110
|
-
}
|
|
111
|
-
defineObjectElement(propertyKey, type) {
|
|
112
|
-
type = type || Reflect.getMetadata("design:type", this.ctor.prototype, propertyKey);
|
|
113
|
-
if (typeof type !== 'function')
|
|
114
|
-
throw new Error('"type" must be defined');
|
|
115
|
-
let prop = this.getElement(propertyKey);
|
|
116
|
-
if (!prop || !(0, orm_helper_1.isObjectElement)(prop)) {
|
|
117
|
-
prop = new entity_object_element_1.EntityObjectElement(this, propertyKey, type);
|
|
118
|
-
if (!this.elements.has(propertyKey.toLowerCase()))
|
|
119
|
-
this.elementKeys.push(propertyKey);
|
|
120
|
-
this.elements.set(propertyKey.toLowerCase(), prop);
|
|
121
|
-
}
|
|
122
|
-
return prop;
|
|
123
|
-
}
|
|
124
|
-
setPrimaryIndex(column, options) {
|
|
125
|
-
this.primaryIndex = new index_meta_1.IndexMeta(this, column, options);
|
|
126
|
-
this.primaryIndex.unique = true;
|
|
127
|
-
}
|
|
128
|
-
addIndex(column, options) {
|
|
129
|
-
this.indexes.push(new index_meta_1.IndexMeta(this, column, options));
|
|
130
|
-
}
|
|
131
|
-
addForeignKey(propertyKey, target, targetKey) {
|
|
132
|
-
const fk = new association_1.Association(this.name + '.' + propertyKey, {
|
|
133
|
-
source: this.ctor,
|
|
134
|
-
sourceKey: propertyKey,
|
|
135
|
-
target,
|
|
136
|
-
targetKey
|
|
137
|
-
});
|
|
138
|
-
this.foreignKeys.push(fk);
|
|
139
|
-
}
|
|
140
|
-
before(event, fn) {
|
|
141
|
-
this.eventListeners.push({ event: 'before-' + event, fn });
|
|
142
|
-
}
|
|
143
|
-
after(event, fn) {
|
|
144
|
-
this.eventListeners.push({ event: 'after-' + event, fn });
|
|
145
|
-
}
|
|
146
|
-
getPrimaryIndexColumns() {
|
|
147
|
-
const out = [];
|
|
148
|
-
if (this.primaryIndex) {
|
|
149
|
-
for (const k of this.primaryIndex.columns) {
|
|
150
|
-
const col = this.getColumnElement(k);
|
|
151
|
-
if (!col)
|
|
152
|
-
throw new Error(`Data column "${k}" in primary index of ${this.name} does not exists`);
|
|
153
|
-
out.push(col);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return out;
|
|
157
|
-
}
|
|
158
|
-
getElementNames(fn) {
|
|
159
|
-
const out = [];
|
|
160
|
-
for (const k of this.elementKeys) {
|
|
161
|
-
const el = this.getElement(k);
|
|
162
|
-
if (el && (!fn || fn(el)))
|
|
163
|
-
out.push(k);
|
|
164
|
-
}
|
|
165
|
-
return out;
|
|
166
|
-
}
|
|
167
|
-
getColumnNames() {
|
|
168
|
-
return this.getElementNames(orm_helper_1.isColumnElement);
|
|
169
|
-
}
|
|
170
|
-
getObjectElementNames() {
|
|
171
|
-
return this.getElementNames(orm_helper_1.isObjectElement);
|
|
172
|
-
}
|
|
173
|
-
getAssociationElementNames() {
|
|
174
|
-
return this.getElementNames(orm_helper_1.isAssociationElement);
|
|
175
|
-
}
|
|
176
|
-
getNonAssociationElementNames() {
|
|
177
|
-
return this.getElementNames(x => !(0, orm_helper_1.isAssociationElement)(x));
|
|
178
|
-
}
|
|
179
|
-
getInsertColumnNames() {
|
|
180
|
-
const out = [];
|
|
181
|
-
for (const k of this.elementKeys) {
|
|
182
|
-
const col = this.getElement(k);
|
|
183
|
-
if ((0, orm_helper_1.isColumnElement)(col) && !col.noInsert)
|
|
184
|
-
out.push(k);
|
|
185
|
-
}
|
|
186
|
-
return out;
|
|
187
|
-
}
|
|
188
|
-
getUpdateColumnNames() {
|
|
189
|
-
const out = [];
|
|
190
|
-
for (const k of this.elementKeys) {
|
|
191
|
-
const col = this.getElement(k);
|
|
192
|
-
if ((0, orm_helper_1.isColumnElement)(col) && !col.noUpdate)
|
|
193
|
-
out.push(k);
|
|
194
|
-
}
|
|
195
|
-
return out;
|
|
196
|
-
}
|
|
197
|
-
async getForeignKeyFor(t) {
|
|
198
|
-
for (const f of this.foreignKeys) {
|
|
199
|
-
if (await f.resolveTarget() === t)
|
|
200
|
-
return f;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
static get(ctor) {
|
|
204
|
-
return ctor[orm_const_1.ENTITY_DEFINITION_KEY];
|
|
205
|
-
}
|
|
206
|
-
static hasOwn(ctor) {
|
|
207
|
-
return ctor.hasOwnProperty(orm_const_1.ENTITY_DEFINITION_KEY);
|
|
208
|
-
}
|
|
209
|
-
static attachTo(ctor) {
|
|
210
|
-
const own = this.hasOwn(ctor) ? this.get(ctor) : undefined;
|
|
211
|
-
if (own)
|
|
212
|
-
return own;
|
|
213
|
-
const current = this.get(ctor);
|
|
214
|
-
const entity = new EntityModel(ctor);
|
|
215
|
-
Object.defineProperty(ctor, orm_const_1.ENTITY_DEFINITION_KEY, {
|
|
216
|
-
value: entity,
|
|
217
|
-
enumerable: false
|
|
218
|
-
});
|
|
219
|
-
// Merge base entity columns into this one
|
|
220
|
-
if (current) {
|
|
221
|
-
entity.tableName = current.tableName;
|
|
222
|
-
for (const k of current.elementKeys) {
|
|
223
|
-
const col = current.elements.get(k.toLowerCase());
|
|
224
|
-
if (col) {
|
|
225
|
-
entity.elementKeys.push(k);
|
|
226
|
-
entity.elements.set(k.toLowerCase(), col);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
for (const fk of current.foreignKeys) {
|
|
230
|
-
const newFk = new association_1.Association(fk.name, { ...fk, source: ctor });
|
|
231
|
-
entity.foreignKeys.push(newFk);
|
|
232
|
-
}
|
|
233
|
-
for (const idx of current.indexes) {
|
|
234
|
-
const newIdx = new index_meta_1.IndexMeta(entity, idx.columns, idx);
|
|
235
|
-
entity.indexes.push(newIdx);
|
|
236
|
-
}
|
|
237
|
-
entity.eventListeners.push(...current.eventListeners);
|
|
238
|
-
if (current.primaryIndex)
|
|
239
|
-
entity.setPrimaryIndex([...current.primaryIndex.columns]);
|
|
240
|
-
}
|
|
241
|
-
ctor.prototype.toJSON = function () {
|
|
242
|
-
const obj = {};
|
|
243
|
-
const elementKeys = entity.elementKeys;
|
|
244
|
-
const l = elementKeys.length;
|
|
245
|
-
let key;
|
|
246
|
-
let v;
|
|
247
|
-
for (let i = 0; i < l; i++) {
|
|
248
|
-
key = elementKeys[i];
|
|
249
|
-
v = this[key];
|
|
250
|
-
if (v === undefined)
|
|
251
|
-
continue;
|
|
252
|
-
const col = entity.getElement(key);
|
|
253
|
-
if (col)
|
|
254
|
-
obj[key] = (0, serialize_element_1.serializeColumn)(col, v);
|
|
255
|
-
}
|
|
256
|
-
return obj;
|
|
257
|
-
};
|
|
258
|
-
return entity;
|
|
259
|
-
}
|
|
260
|
-
static getElementNames(ctor) {
|
|
261
|
-
const meta = this.get(ctor);
|
|
262
|
-
return meta && [...meta.elementKeys];
|
|
263
|
-
}
|
|
264
|
-
static getColumnNames(ctor) {
|
|
265
|
-
const meta = this.get(ctor);
|
|
266
|
-
if (meta)
|
|
267
|
-
return meta.getColumnNames();
|
|
268
|
-
}
|
|
269
|
-
static getAssociationElementNames(ctor) {
|
|
270
|
-
const meta = this.get(ctor);
|
|
271
|
-
if (meta)
|
|
272
|
-
return meta.getAssociationElementNames();
|
|
273
|
-
}
|
|
274
|
-
static getNonAssociationElementNames(ctor) {
|
|
275
|
-
const meta = this.get(ctor);
|
|
276
|
-
if (meta)
|
|
277
|
-
return meta.getNonAssociationElementNames();
|
|
278
|
-
}
|
|
279
|
-
static getObjectElementNames(ctor) {
|
|
280
|
-
const meta = this.get(ctor);
|
|
281
|
-
if (meta)
|
|
282
|
-
return meta.getObjectElementNames();
|
|
283
|
-
}
|
|
284
|
-
static getInsertColumnNames(ctor) {
|
|
285
|
-
const meta = this.get(ctor);
|
|
286
|
-
if (meta)
|
|
287
|
-
return meta.getInsertColumnNames();
|
|
288
|
-
}
|
|
289
|
-
static getUpdateColumnNames(ctor) {
|
|
290
|
-
const meta = this.get(ctor);
|
|
291
|
-
if (meta)
|
|
292
|
-
return meta.getUpdateColumnNames();
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
exports.EntityModel = EntityModel;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ElementKind, TypeThunk, DataPropertyOptions } from '../orm.type';
|
|
2
|
-
import { AbstractEntityelement } from './abstract-entityelement';
|
|
3
|
-
import { EntityModel } from './entity-model';
|
|
4
|
-
export declare class EntityObjectElement extends AbstractEntityelement {
|
|
5
|
-
kind: ElementKind;
|
|
6
|
-
type: TypeThunk;
|
|
7
|
-
fieldNamePrefix?: string;
|
|
8
|
-
fieldNameSuffix?: string;
|
|
9
|
-
constructor(entity: EntityModel, name: string, type: TypeThunk);
|
|
10
|
-
resolveType(): Promise<EntityModel>;
|
|
11
|
-
assign(options: DataPropertyOptions): void;
|
|
12
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EntityObjectElement = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
6
|
-
const abstract_entityelement_1 = require("./abstract-entityelement");
|
|
7
|
-
const orm_helper_1 = require("../util/orm.helper");
|
|
8
|
-
class EntityObjectElement extends abstract_entityelement_1.AbstractEntityelement {
|
|
9
|
-
constructor(entity, name, type) {
|
|
10
|
-
super(entity, name);
|
|
11
|
-
this.kind = 'object';
|
|
12
|
-
this.type = type;
|
|
13
|
-
}
|
|
14
|
-
async resolveType() {
|
|
15
|
-
const typ = await (0, orm_helper_1.resolveEntityMeta)(this.type);
|
|
16
|
-
if (typ)
|
|
17
|
-
return typ;
|
|
18
|
-
throw new Error(`Can't resolve type of ${this.entity.name}.${this.name}`);
|
|
19
|
-
}
|
|
20
|
-
assign(options) {
|
|
21
|
-
Object.assign(this, lodash_1.default.omit(options, ['entity', 'name', 'kind']));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.EntityObjectElement = EntityObjectElement;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { EntityModel } from './entity-model';
|
|
2
|
-
import { IndexOptions } from '../orm.type';
|
|
3
|
-
export declare class IndexMeta {
|
|
4
|
-
entity: EntityModel;
|
|
5
|
-
columns: string[];
|
|
6
|
-
name?: string;
|
|
7
|
-
unique?: boolean;
|
|
8
|
-
constructor(entity: EntityModel, column: string | string[], options?: IndexOptions);
|
|
9
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IndexMeta = void 0;
|
|
4
|
-
class IndexMeta {
|
|
5
|
-
constructor(entity, column, options) {
|
|
6
|
-
this.entity = entity;
|
|
7
|
-
this.columns = Array.isArray(column) ? column : [column];
|
|
8
|
-
if (options) {
|
|
9
|
-
if (options.name)
|
|
10
|
-
this.name = options.name;
|
|
11
|
-
if (options.unique)
|
|
12
|
-
this.unique = options.unique;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.IndexMeta = IndexMeta;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Type } from 'ts-gems';
|
|
2
|
-
export declare function mixinEntities<A, B, C, D, E, F>(derived: Type, classARef: Type<A>, classBRef: Type<B>, classCRef: Type<C>, classDRef: Type<D>, classERef: Type<E>, classFRef: Type<F>): Type<A & B & C & D & E & F>;
|
|
3
|
-
export declare function mixinEntities<A, B, C, D, E>(derived: Type, classARef: Type<A>, classBRef: Type<B>, classCRef: Type<C>, classDRef: Type<D>, classERef: Type<E>): Type<A & B & C & D & E>;
|
|
4
|
-
export declare function mixinEntities<A, B, C, D>(derived: Type, classARef: Type<A>, classBRef: Type<B>, classCRef: Type<C>, classDRef: Type<D>): Type<A & B & C & D>;
|
|
5
|
-
export declare function mixinEntities<A, B, C>(derived: Type, classARef: Type<A>, classBRef: Type<B>, classCRef: Type<C>): Type<A & B & C>;
|
|
6
|
-
export declare function mixinEntities<A, B>(derived: Type, classARef: Type<A>, classBRef: Type<B>): Type<A & B>;
|
|
7
|
-
export declare function mixinEntities<A, B>(derived: Type, classARef: Type<A>, classBRef: Type<B>): Type<A & B>;
|
|
8
|
-
export declare function pickEntityInto<T, K extends keyof T>(derived: Type, classRef: Type<T>, keys: readonly K[]): Type<Pick<T, typeof keys[number]>>;
|
|
9
|
-
export declare function omitEntityInto<T, K extends keyof T>(derived: Type, classRef: Type<T>, keys: readonly K[]): Type<Omit<T, typeof keys[number]>>;
|
|
10
|
-
export declare function UnionEntity<A, B>(classARef: Type<A>, classBRef: Type<B>): Type<A & B>;
|
|
11
|
-
export declare function PickEntity<T, K extends keyof T>(classRef: Type<T>, keys: readonly K[]): Type<Pick<T, typeof keys[number]>>;
|
|
12
|
-
export declare function OmitEntity<T, K extends keyof T>(classRef: Type<T>, keys: readonly K[]): Type<Omit<T, typeof keys[number]>>;
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OmitEntity = exports.PickEntity = exports.UnionEntity = exports.omitEntityInto = exports.pickEntityInto = exports.mixinEntities = void 0;
|
|
4
|
-
const entity_model_1 = require("../model/entity-model");
|
|
5
|
-
const association_1 = require("../model/association");
|
|
6
|
-
const index_meta_1 = require("../model/index-meta");
|
|
7
|
-
function mixinEntities(derived, classARef, classBRef, classCRef, classDRef, classERef, classFRef) {
|
|
8
|
-
const trg = entity_model_1.EntityModel.attachTo(derived);
|
|
9
|
-
for (const classRef of [classARef, classBRef, classCRef, classDRef, classERef, classFRef]) {
|
|
10
|
-
if (!classRef)
|
|
11
|
-
continue;
|
|
12
|
-
const src = entity_model_1.EntityModel.get(classRef);
|
|
13
|
-
if (!src)
|
|
14
|
-
return derived;
|
|
15
|
-
trg.tableName = src.tableName;
|
|
16
|
-
if (!trg.primaryIndex && src.primaryIndex) {
|
|
17
|
-
trg.primaryIndex = new index_meta_1.IndexMeta(trg, src.primaryIndex.columns, src.primaryIndex);
|
|
18
|
-
}
|
|
19
|
-
if (src.foreignKeys) {
|
|
20
|
-
trg.foreignKeys = trg.foreignKeys || [];
|
|
21
|
-
for (const fk of src.foreignKeys) {
|
|
22
|
-
const newFk = new association_1.Association(fk.name, { ...fk, source: derived });
|
|
23
|
-
trg.foreignKeys.push(newFk);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (src.indexes) {
|
|
27
|
-
trg.indexes = trg.indexes || [];
|
|
28
|
-
for (const idx of src.indexes) {
|
|
29
|
-
const newIdx = new index_meta_1.IndexMeta(trg, idx.columns, idx);
|
|
30
|
-
trg.indexes.push(newIdx);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (src.eventListeners) {
|
|
34
|
-
trg.eventListeners = trg.eventListeners || [];
|
|
35
|
-
trg.eventListeners.push(...src.eventListeners);
|
|
36
|
-
}
|
|
37
|
-
src.elements.forEach((p, n) => {
|
|
38
|
-
const o = Object.assign({}, p);
|
|
39
|
-
o.entity = trg;
|
|
40
|
-
Object.setPrototypeOf(o, Object.getPrototypeOf(p));
|
|
41
|
-
trg.elements.set(n, o);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
return derived;
|
|
45
|
-
}
|
|
46
|
-
exports.mixinEntities = mixinEntities;
|
|
47
|
-
function pickEntityInto(derived, classRef, keys) {
|
|
48
|
-
const trg = entity_model_1.EntityModel.attachTo(derived);
|
|
49
|
-
const src = entity_model_1.EntityModel.get(classRef);
|
|
50
|
-
if (!src)
|
|
51
|
-
return derived;
|
|
52
|
-
trg.tableName = src.tableName;
|
|
53
|
-
trg.schema = src.schema;
|
|
54
|
-
trg.comment = src.comment;
|
|
55
|
-
trg.primaryIndex = src.primaryIndex;
|
|
56
|
-
const pickKeys = keys.map(x => x.toLowerCase());
|
|
57
|
-
for (const fk of src.foreignKeys) {
|
|
58
|
-
if (fk.sourceKey && pickKeys.includes(fk.sourceKey.toLowerCase())) {
|
|
59
|
-
const newFk = new association_1.Association(fk.name, { ...fk, source: derived });
|
|
60
|
-
trg.foreignKeys.push(newFk);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
for (const idx of src.indexes) {
|
|
64
|
-
if (!idx.columns.find(x => !pickKeys.includes(x.toLowerCase()))) {
|
|
65
|
-
const newIdx = new index_meta_1.IndexMeta(trg, idx.columns, idx);
|
|
66
|
-
trg.indexes.push(newIdx);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
trg.eventListeners.push(...src.eventListeners);
|
|
70
|
-
src.elements.forEach((p, n) => {
|
|
71
|
-
if (pickKeys.includes(n))
|
|
72
|
-
trg.elements.set(n, p);
|
|
73
|
-
});
|
|
74
|
-
return derived;
|
|
75
|
-
}
|
|
76
|
-
exports.pickEntityInto = pickEntityInto;
|
|
77
|
-
function omitEntityInto(derived, classRef, keys) {
|
|
78
|
-
const trg = entity_model_1.EntityModel.attachTo(derived);
|
|
79
|
-
const src = entity_model_1.EntityModel.get(classRef);
|
|
80
|
-
if (!src)
|
|
81
|
-
return derived;
|
|
82
|
-
trg.tableName = src.tableName;
|
|
83
|
-
trg.schema = src.schema;
|
|
84
|
-
trg.comment = src.comment;
|
|
85
|
-
trg.primaryIndex = src.primaryIndex;
|
|
86
|
-
const omitKeys = keys.map(x => x.toLowerCase());
|
|
87
|
-
for (const fk of src.foreignKeys) {
|
|
88
|
-
if (!(fk.sourceKey && omitKeys.includes(fk.sourceKey.toLowerCase()))) {
|
|
89
|
-
const newFk = new association_1.Association(fk.name, { ...fk, source: derived });
|
|
90
|
-
trg.foreignKeys.push(newFk);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
for (const idx of src.indexes) {
|
|
94
|
-
if (!idx.columns.find(x => omitKeys.includes(x.toLowerCase()))) {
|
|
95
|
-
const newIdx = new index_meta_1.IndexMeta(trg, idx.columns, idx);
|
|
96
|
-
trg.indexes.push(newIdx);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
trg.eventListeners.push(...src.eventListeners);
|
|
100
|
-
src.elements.forEach((p, n) => {
|
|
101
|
-
if (!omitKeys.includes(n.toLowerCase()))
|
|
102
|
-
trg.elements.set(n.toLowerCase(), p);
|
|
103
|
-
});
|
|
104
|
-
trg.elements.forEach((p, n) => {
|
|
105
|
-
if (omitKeys.includes(n.toLowerCase()))
|
|
106
|
-
trg.elements.delete(n.toLowerCase());
|
|
107
|
-
});
|
|
108
|
-
return derived;
|
|
109
|
-
}
|
|
110
|
-
exports.omitEntityInto = omitEntityInto;
|
|
111
|
-
function UnionEntity(classARef, classBRef) {
|
|
112
|
-
class UnionEntityClass {
|
|
113
|
-
constructor(...args) {
|
|
114
|
-
inheritPropertyInitializers(this, classARef, args);
|
|
115
|
-
inheritPropertyInitializers(this, classBRef, args);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return mixinEntities(UnionEntityClass, classARef, classBRef);
|
|
119
|
-
}
|
|
120
|
-
exports.UnionEntity = UnionEntity;
|
|
121
|
-
function PickEntity(classRef, keys) {
|
|
122
|
-
class PickEntityClass {
|
|
123
|
-
constructor(...args) {
|
|
124
|
-
inheritPropertyInitializers(this, classRef, args);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return pickEntityInto(PickEntityClass, classRef, keys);
|
|
128
|
-
}
|
|
129
|
-
exports.PickEntity = PickEntity;
|
|
130
|
-
function OmitEntity(classRef, keys) {
|
|
131
|
-
class OmitEntityClass {
|
|
132
|
-
constructor(...args) {
|
|
133
|
-
inheritPropertyInitializers(this, classRef, args);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return omitEntityInto(OmitEntityClass, classRef, keys);
|
|
137
|
-
}
|
|
138
|
-
exports.OmitEntity = OmitEntity;
|
|
139
|
-
function inheritPropertyInitializers(target, sourceClass, constructorArgs, isPropertyInherited) {
|
|
140
|
-
try {
|
|
141
|
-
const tempInstance = new sourceClass(...constructorArgs);
|
|
142
|
-
const keys = Object.getOwnPropertyNames(tempInstance);
|
|
143
|
-
for (const key of keys) {
|
|
144
|
-
const srcDesc = Object.getOwnPropertyDescriptor(tempInstance, key);
|
|
145
|
-
const trgDesc = Object.getOwnPropertyDescriptor(target, key);
|
|
146
|
-
if (!srcDesc || trgDesc || (isPropertyInherited && !isPropertyInherited(key)))
|
|
147
|
-
continue;
|
|
148
|
-
Object.defineProperty(target, key, srcDesc);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
catch {
|
|
152
|
-
//
|
|
153
|
-
}
|
|
154
|
-
}
|