@sqb/connect 4.14.0 → 4.15.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/cjs/client/sqb-connection.js +1 -1
- package/cjs/orm/repository.class.js +77 -19
- package/esm/client/adapter.js +2 -1
- package/esm/client/cursor-stream.js +9 -4
- package/esm/client/cursor.js +22 -17
- package/esm/client/extensions.js +5 -1
- package/esm/client/field-info-map.js +5 -1
- package/esm/client/helpers.js +19 -12
- package/esm/client/sqb-client.js +32 -27
- package/esm/client/sqb-connection.js +42 -37
- package/esm/client/types.js +5 -1
- package/esm/index.js +40 -32
- package/esm/orm/backward.js +19 -12
- package/esm/orm/base-entity.js +10 -6
- package/esm/orm/commands/command.helper.js +34 -28
- package/esm/orm/commands/count.command.js +10 -6
- package/esm/orm/commands/create.command.js +18 -14
- package/esm/orm/commands/delete.command.js +10 -6
- package/esm/orm/commands/find.command.js +34 -30
- package/esm/orm/commands/row-converter.js +7 -3
- package/esm/orm/commands/update.command.js +18 -14
- package/esm/orm/decorators/column.decorator.js +10 -7
- package/esm/orm/decorators/embedded.decorator.js +7 -4
- package/esm/orm/decorators/entity.decorator.js +56 -53
- package/esm/orm/decorators/events.decorator.js +27 -19
- package/esm/orm/decorators/foreignkey.decorator.js +7 -4
- package/esm/orm/decorators/index.decorator.js +9 -6
- package/esm/orm/decorators/link.decorator.js +11 -8
- package/esm/orm/decorators/primarykey.decorator.js +11 -8
- package/esm/orm/decorators/transform.decorator.js +11 -7
- package/esm/orm/model/association-field-metadata.js +8 -4
- package/esm/orm/model/association-node.js +6 -2
- package/esm/orm/model/association.js +20 -16
- package/esm/orm/model/column-field-metadata.js +8 -4
- package/esm/orm/model/embedded-field-metadata.js +7 -4
- package/esm/orm/model/entity-metadata.js +50 -47
- package/esm/orm/model/field-metadata.js +2 -1
- package/esm/orm/model/index-metadata.js +2 -1
- package/esm/orm/model/link-chain.js +8 -4
- package/esm/orm/orm.const.js +6 -3
- package/esm/orm/orm.type.js +2 -1
- package/esm/orm/repository.class.js +103 -41
- package/esm/orm/util/apply-mixins.js +4 -1
- package/esm/orm/util/extract-keyvalues.js +9 -6
- package/esm/orm/util/orm.helper.js +20 -10
- package/esm/orm/util/parse-fields-projection.js +11 -6
- package/esm/orm/util/serialize-field.js +13 -10
- package/package.json +30 -24
- package/types/orm/repository.class.d.ts +110 -11
- package/cjs/package.json +0 -3
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UpdateCommand = void 0;
|
|
4
|
+
const builder_1 = require("@sqb/builder");
|
|
5
|
+
const column_field_metadata_js_1 = require("../model/column-field-metadata.js");
|
|
6
|
+
const embedded_field_metadata_js_1 = require("../model/embedded-field-metadata.js");
|
|
7
|
+
const orm_helper_js_1 = require("../util/orm.helper.js");
|
|
8
|
+
const command_helper_js_1 = require("./command.helper.js");
|
|
9
|
+
class UpdateCommand {
|
|
7
10
|
// istanbul ignore next
|
|
8
11
|
constructor() {
|
|
9
12
|
throw new Error('This class is abstract');
|
|
@@ -27,7 +30,7 @@ export class UpdateCommand {
|
|
|
27
30
|
return 0;
|
|
28
31
|
if (args.filter)
|
|
29
32
|
await this._prepareFilter(ctx, args.filter);
|
|
30
|
-
const query = Update(tableName + ' as T', ctx.queryValues).where(...ctx.queryFilter);
|
|
33
|
+
const query = (0, builder_1.Update)(tableName + ' as T', ctx.queryValues).where(...ctx.queryFilter);
|
|
31
34
|
const qr = await args.connection.execute(query, {
|
|
32
35
|
params: args.params ? [...args.params, ctx.queryParams] : ctx.queryParams,
|
|
33
36
|
objectRows: false,
|
|
@@ -37,8 +40,8 @@ export class UpdateCommand {
|
|
|
37
40
|
}
|
|
38
41
|
static async _prepareFilter(ctx, filter) {
|
|
39
42
|
if (filter) {
|
|
40
|
-
const where = And();
|
|
41
|
-
await prepareFilter(ctx.entity, filter, where);
|
|
43
|
+
const where = (0, builder_1.And)();
|
|
44
|
+
await (0, command_helper_js_1.prepareFilter)(ctx.entity, filter, where);
|
|
42
45
|
ctx.queryFilter.push(...where._items);
|
|
43
46
|
}
|
|
44
47
|
}
|
|
@@ -50,7 +53,7 @@ export class UpdateCommand {
|
|
|
50
53
|
v = values[col.name];
|
|
51
54
|
if (v === undefined)
|
|
52
55
|
continue;
|
|
53
|
-
if (isColumnField(col)) {
|
|
56
|
+
if ((0, orm_helper_js_1.isColumnField)(col)) {
|
|
54
57
|
if (col.noUpdate)
|
|
55
58
|
continue;
|
|
56
59
|
if (typeof col.serialize === 'function')
|
|
@@ -59,10 +62,10 @@ export class UpdateCommand {
|
|
|
59
62
|
throw new Error(`${entity.name}.${col.name} is required and can't be null`);
|
|
60
63
|
if (v === undefined)
|
|
61
64
|
continue;
|
|
62
|
-
ColumnFieldMetadata.checkEnumValue(col, v);
|
|
65
|
+
column_field_metadata_js_1.ColumnFieldMetadata.checkEnumValue(col, v);
|
|
63
66
|
const fieldName = prefix + col.fieldName + suffix;
|
|
64
67
|
const k = ('I$_' + fieldName).substring(0, 30);
|
|
65
|
-
ctx.queryValues[fieldName] = Param({
|
|
68
|
+
ctx.queryValues[fieldName] = (0, builder_1.Param)({
|
|
66
69
|
name: k,
|
|
67
70
|
dataType: col.dataType,
|
|
68
71
|
isArray: col.isArray,
|
|
@@ -70,10 +73,11 @@ export class UpdateCommand {
|
|
|
70
73
|
ctx.queryParams[k] = v;
|
|
71
74
|
ctx.colCount++;
|
|
72
75
|
}
|
|
73
|
-
else if (v != null && isEmbeddedField(col)) {
|
|
74
|
-
const type = await EmbeddedFieldMetadata.resolveType(col);
|
|
76
|
+
else if (v != null && (0, orm_helper_js_1.isEmbeddedField)(col)) {
|
|
77
|
+
const type = await embedded_field_metadata_js_1.EmbeddedFieldMetadata.resolveType(col);
|
|
75
78
|
await this._prepareParams(ctx, type, v, col.fieldNamePrefix, col.fieldNameSuffix);
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
81
|
}
|
|
79
82
|
}
|
|
83
|
+
exports.UpdateCommand = UpdateCommand;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Column = Column;
|
|
4
|
+
const entity_metadata_js_1 = require("../model/entity-metadata.js");
|
|
5
|
+
const orm_const_js_1 = require("../orm.const.js");
|
|
6
|
+
function Column(arg0) {
|
|
7
|
+
return Column[orm_const_js_1.DECORATOR_FACTORY](arg0);
|
|
5
8
|
}
|
|
6
|
-
Column[DECORATOR_FACTORY] = function (arg0) {
|
|
9
|
+
Column[orm_const_js_1.DECORATOR_FACTORY] = function (arg0) {
|
|
7
10
|
return (target, propertyKey) => {
|
|
8
11
|
if (typeof propertyKey !== 'string')
|
|
9
12
|
throw new Error('Symbol properties are not accepted');
|
|
10
13
|
const options = (typeof arg0 === 'string' ? { dataType: arg0 } : arg0) || {};
|
|
11
|
-
const entity = EntityMetadata.define(target.constructor);
|
|
14
|
+
const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
12
15
|
if (!options.type) {
|
|
13
16
|
const typ = Reflect.getMetadata('design:type', entity.ctor.prototype, propertyKey);
|
|
14
17
|
if (typ === Array) {
|
|
@@ -18,6 +21,6 @@ Column[DECORATOR_FACTORY] = function (arg0) {
|
|
|
18
21
|
else
|
|
19
22
|
options.type = typ;
|
|
20
23
|
}
|
|
21
|
-
EntityMetadata.defineColumnField(entity, propertyKey, options);
|
|
24
|
+
entity_metadata_js_1.EntityMetadata.defineColumnField(entity, propertyKey, options);
|
|
22
25
|
};
|
|
23
26
|
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Embedded = Embedded;
|
|
4
|
+
const entity_metadata_js_1 = require("../model/entity-metadata.js");
|
|
5
|
+
function Embedded(type, options) {
|
|
3
6
|
return (target, propertyKey) => {
|
|
4
7
|
if (typeof propertyKey !== 'string')
|
|
5
8
|
throw new Error('Symbol properties are not accepted');
|
|
6
9
|
type = type || Reflect.getMetadata('design:type', target, propertyKey);
|
|
7
10
|
if (typeof type !== 'function')
|
|
8
11
|
throw new Error('"type" must be defined');
|
|
9
|
-
const entity = EntityMetadata.define(target.constructor);
|
|
10
|
-
EntityMetadata.defineEmbeddedField(entity, propertyKey, type, options);
|
|
12
|
+
const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
13
|
+
entity_metadata_js_1.EntityMetadata.defineEmbeddedField(entity, propertyKey, type, options);
|
|
11
14
|
};
|
|
12
15
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Entity = Entity;
|
|
4
|
+
const entity_metadata_js_1 = require("../model/entity-metadata.js");
|
|
5
|
+
const apply_mixins_js_1 = require("../util/apply-mixins.js");
|
|
6
|
+
function Entity(options) {
|
|
4
7
|
return function (target) {
|
|
5
8
|
const opts = typeof options === 'object' ? options : {};
|
|
6
9
|
const tableName = typeof options === 'string' ? options : opts.tableName;
|
|
7
|
-
const entity = EntityMetadata.define(target);
|
|
10
|
+
const entity = entity_metadata_js_1.EntityMetadata.define(target);
|
|
8
11
|
entity.tableName = tableName || target.name;
|
|
9
12
|
if (opts.schema)
|
|
10
13
|
entity.schema = opts.schema;
|
|
@@ -13,92 +16,92 @@ export function Entity(options) {
|
|
|
13
16
|
};
|
|
14
17
|
}
|
|
15
18
|
(function (Entity) {
|
|
16
|
-
Entity.getMetadata = EntityMetadata.get;
|
|
17
|
-
Entity.getOwnMetadata = EntityMetadata.getOwn;
|
|
19
|
+
Entity.getMetadata = entity_metadata_js_1.EntityMetadata.get;
|
|
20
|
+
Entity.getOwnMetadata = entity_metadata_js_1.EntityMetadata.getOwn;
|
|
18
21
|
function getField(ctor, key) {
|
|
19
|
-
const model = EntityMetadata.get(ctor);
|
|
20
|
-
return model && EntityMetadata.getField(model, key);
|
|
22
|
+
const model = entity_metadata_js_1.EntityMetadata.get(ctor);
|
|
23
|
+
return model && entity_metadata_js_1.EntityMetadata.getField(model, key);
|
|
21
24
|
}
|
|
22
25
|
Entity.getField = getField;
|
|
23
26
|
function getColumnField(ctor, key) {
|
|
24
|
-
const model = EntityMetadata.get(ctor);
|
|
25
|
-
return model && EntityMetadata.getColumnField(model, key);
|
|
27
|
+
const model = entity_metadata_js_1.EntityMetadata.get(ctor);
|
|
28
|
+
return model && entity_metadata_js_1.EntityMetadata.getColumnField(model, key);
|
|
26
29
|
}
|
|
27
30
|
Entity.getColumnField = getColumnField;
|
|
28
31
|
function getEmbeddedField(ctor, key) {
|
|
29
|
-
const model = EntityMetadata.get(ctor);
|
|
30
|
-
return model && EntityMetadata.getEmbeddedField(model, key);
|
|
32
|
+
const model = entity_metadata_js_1.EntityMetadata.get(ctor);
|
|
33
|
+
return model && entity_metadata_js_1.EntityMetadata.getEmbeddedField(model, key);
|
|
31
34
|
}
|
|
32
35
|
Entity.getEmbeddedField = getEmbeddedField;
|
|
33
36
|
function getAssociationField(ctor, key) {
|
|
34
|
-
const model = EntityMetadata.get(ctor);
|
|
35
|
-
return model && EntityMetadata.getAssociationField(model, key);
|
|
37
|
+
const model = entity_metadata_js_1.EntityMetadata.get(ctor);
|
|
38
|
+
return model && entity_metadata_js_1.EntityMetadata.getAssociationField(model, key);
|
|
36
39
|
}
|
|
37
40
|
Entity.getAssociationField = getAssociationField;
|
|
38
41
|
function getColumnFieldByFieldName(ctor, fieldName) {
|
|
39
|
-
const model = EntityMetadata.get(ctor);
|
|
40
|
-
return model && EntityMetadata.getColumnFieldByFieldName(model, fieldName);
|
|
42
|
+
const model = entity_metadata_js_1.EntityMetadata.get(ctor);
|
|
43
|
+
return model && entity_metadata_js_1.EntityMetadata.getColumnFieldByFieldName(model, fieldName);
|
|
41
44
|
}
|
|
42
45
|
Entity.getColumnFieldByFieldName = getColumnFieldByFieldName;
|
|
43
46
|
function find(ctor, predicate) {
|
|
44
|
-
const model = EntityMetadata.get(ctor);
|
|
45
|
-
return model && EntityMetadata.findField(model, predicate);
|
|
47
|
+
const model = entity_metadata_js_1.EntityMetadata.get(ctor);
|
|
48
|
+
return model && entity_metadata_js_1.EntityMetadata.findField(model, predicate);
|
|
46
49
|
}
|
|
47
50
|
Entity.find = find;
|
|
48
51
|
function getFieldNames(ctor, filter) {
|
|
49
|
-
const model = EntityMetadata.get(ctor);
|
|
50
|
-
return (model && EntityMetadata.getFieldNames(model, filter)) || [];
|
|
52
|
+
const model = entity_metadata_js_1.EntityMetadata.get(ctor);
|
|
53
|
+
return (model && entity_metadata_js_1.EntityMetadata.getFieldNames(model, filter)) || [];
|
|
51
54
|
}
|
|
52
55
|
Entity.getFieldNames = getFieldNames;
|
|
53
56
|
function getColumnFieldNames(ctor) {
|
|
54
|
-
const model = EntityMetadata.get(ctor);
|
|
55
|
-
return (model && EntityMetadata.getColumnFieldNames(model)) || [];
|
|
57
|
+
const model = entity_metadata_js_1.EntityMetadata.get(ctor);
|
|
58
|
+
return (model && entity_metadata_js_1.EntityMetadata.getColumnFieldNames(model)) || [];
|
|
56
59
|
}
|
|
57
60
|
Entity.getColumnFieldNames = getColumnFieldNames;
|
|
58
61
|
function getEmbeddedFieldNames(ctor) {
|
|
59
|
-
const model = EntityMetadata.get(ctor);
|
|
60
|
-
return (model && EntityMetadata.getEmbeddedFieldNames(model)) || [];
|
|
62
|
+
const model = entity_metadata_js_1.EntityMetadata.get(ctor);
|
|
63
|
+
return (model && entity_metadata_js_1.EntityMetadata.getEmbeddedFieldNames(model)) || [];
|
|
61
64
|
}
|
|
62
65
|
Entity.getEmbeddedFieldNames = getEmbeddedFieldNames;
|
|
63
66
|
function getAssociationFieldNames(ctor) {
|
|
64
|
-
const model = EntityMetadata.get(ctor);
|
|
65
|
-
return (model && EntityMetadata.getAssociationFieldNames(model)) || [];
|
|
67
|
+
const model = entity_metadata_js_1.EntityMetadata.get(ctor);
|
|
68
|
+
return (model && entity_metadata_js_1.EntityMetadata.getAssociationFieldNames(model)) || [];
|
|
66
69
|
}
|
|
67
70
|
Entity.getAssociationFieldNames = getAssociationFieldNames;
|
|
68
71
|
function getNonAssociationFieldNames(ctor) {
|
|
69
|
-
const model = EntityMetadata.get(ctor);
|
|
70
|
-
return (model && EntityMetadata.getNonAssociationFieldNames(model)) || [];
|
|
72
|
+
const model = entity_metadata_js_1.EntityMetadata.get(ctor);
|
|
73
|
+
return (model && entity_metadata_js_1.EntityMetadata.getNonAssociationFieldNames(model)) || [];
|
|
71
74
|
}
|
|
72
75
|
Entity.getNonAssociationFieldNames = getNonAssociationFieldNames;
|
|
73
76
|
function getInsertColumnNames(ctor) {
|
|
74
|
-
const model = EntityMetadata.get(ctor);
|
|
75
|
-
return (model && EntityMetadata.getInsertColumnNames(model)) || [];
|
|
77
|
+
const model = entity_metadata_js_1.EntityMetadata.get(ctor);
|
|
78
|
+
return (model && entity_metadata_js_1.EntityMetadata.getInsertColumnNames(model)) || [];
|
|
76
79
|
}
|
|
77
80
|
Entity.getInsertColumnNames = getInsertColumnNames;
|
|
78
81
|
function getUpdateColumnNames(ctor) {
|
|
79
|
-
const model = EntityMetadata.get(ctor);
|
|
80
|
-
return (model && EntityMetadata.getUpdateColumnNames(model)) || [];
|
|
82
|
+
const model = entity_metadata_js_1.EntityMetadata.get(ctor);
|
|
83
|
+
return (model && entity_metadata_js_1.EntityMetadata.getUpdateColumnNames(model)) || [];
|
|
81
84
|
}
|
|
82
85
|
Entity.getUpdateColumnNames = getUpdateColumnNames;
|
|
83
86
|
function getPrimaryIndex(ctor) {
|
|
84
|
-
const model = EntityMetadata.define(ctor);
|
|
85
|
-
return EntityMetadata.getPrimaryIndex(model);
|
|
87
|
+
const model = entity_metadata_js_1.EntityMetadata.define(ctor);
|
|
88
|
+
return entity_metadata_js_1.EntityMetadata.getPrimaryIndex(model);
|
|
86
89
|
}
|
|
87
90
|
Entity.getPrimaryIndex = getPrimaryIndex;
|
|
88
91
|
function getPrimaryIndexColumns(ctor) {
|
|
89
|
-
const model = EntityMetadata.define(ctor);
|
|
90
|
-
return EntityMetadata.getPrimaryIndexColumns(model);
|
|
92
|
+
const model = entity_metadata_js_1.EntityMetadata.define(ctor);
|
|
93
|
+
return entity_metadata_js_1.EntityMetadata.getPrimaryIndexColumns(model);
|
|
91
94
|
}
|
|
92
95
|
Entity.getPrimaryIndexColumns = getPrimaryIndexColumns;
|
|
93
96
|
function mixin(derivedCtor, ...bases) {
|
|
94
97
|
for (const base of bases) {
|
|
95
98
|
if (!base)
|
|
96
99
|
continue;
|
|
97
|
-
applyMixins(derivedCtor, base);
|
|
98
|
-
const srcMeta = EntityMetadata.get(base);
|
|
100
|
+
(0, apply_mixins_js_1.applyMixins)(derivedCtor, base);
|
|
101
|
+
const srcMeta = entity_metadata_js_1.EntityMetadata.get(base);
|
|
99
102
|
if (srcMeta) {
|
|
100
|
-
const trgMeta = EntityMetadata.define(derivedCtor);
|
|
101
|
-
EntityMetadata.mixin(trgMeta, srcMeta);
|
|
103
|
+
const trgMeta = entity_metadata_js_1.EntityMetadata.define(derivedCtor);
|
|
104
|
+
entity_metadata_js_1.EntityMetadata.mixin(trgMeta, srcMeta);
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
107
|
return derivedCtor;
|
|
@@ -112,11 +115,11 @@ export function Entity(options) {
|
|
|
112
115
|
};
|
|
113
116
|
const pickKeys = keys.map(x => x.toLowerCase());
|
|
114
117
|
const filter = k => pickKeys.includes(k.toLowerCase());
|
|
115
|
-
applyMixins(PickEntityClass, classRef, filter);
|
|
116
|
-
const srcMeta = EntityMetadata.get(classRef);
|
|
118
|
+
(0, apply_mixins_js_1.applyMixins)(PickEntityClass, classRef, filter);
|
|
119
|
+
const srcMeta = entity_metadata_js_1.EntityMetadata.get(classRef);
|
|
117
120
|
if (srcMeta) {
|
|
118
|
-
const trgMeta = EntityMetadata.define(PickEntityClass);
|
|
119
|
-
EntityMetadata.mixin(trgMeta, srcMeta, filter);
|
|
121
|
+
const trgMeta = entity_metadata_js_1.EntityMetadata.define(PickEntityClass);
|
|
122
|
+
entity_metadata_js_1.EntityMetadata.mixin(trgMeta, srcMeta, filter);
|
|
120
123
|
}
|
|
121
124
|
return PickEntityClass;
|
|
122
125
|
}
|
|
@@ -129,11 +132,11 @@ export function Entity(options) {
|
|
|
129
132
|
};
|
|
130
133
|
const omitKeys = keys.map(x => x.toLowerCase());
|
|
131
134
|
const filter = k => !omitKeys.includes(k.toLowerCase());
|
|
132
|
-
applyMixins(OmitEntityClass, classRef, filter);
|
|
133
|
-
const srcMeta = EntityMetadata.get(classRef);
|
|
135
|
+
(0, apply_mixins_js_1.applyMixins)(OmitEntityClass, classRef, filter);
|
|
136
|
+
const srcMeta = entity_metadata_js_1.EntityMetadata.get(classRef);
|
|
134
137
|
if (srcMeta) {
|
|
135
|
-
const trgMeta = EntityMetadata.define(OmitEntityClass);
|
|
136
|
-
EntityMetadata.mixin(trgMeta, srcMeta, filter);
|
|
138
|
+
const trgMeta = entity_metadata_js_1.EntityMetadata.define(OmitEntityClass);
|
|
139
|
+
entity_metadata_js_1.EntityMetadata.mixin(trgMeta, srcMeta, filter);
|
|
137
140
|
}
|
|
138
141
|
return OmitEntityClass;
|
|
139
142
|
}
|
|
@@ -146,17 +149,17 @@ export function Entity(options) {
|
|
|
146
149
|
}
|
|
147
150
|
};
|
|
148
151
|
for (const base of bases) {
|
|
149
|
-
applyMixins(UnionClass, base);
|
|
150
|
-
const srcMeta = EntityMetadata.get(base);
|
|
152
|
+
(0, apply_mixins_js_1.applyMixins)(UnionClass, base);
|
|
153
|
+
const srcMeta = entity_metadata_js_1.EntityMetadata.get(base);
|
|
151
154
|
if (srcMeta) {
|
|
152
|
-
const trgMeta = EntityMetadata.define(UnionClass);
|
|
153
|
-
EntityMetadata.mixin(trgMeta, srcMeta);
|
|
155
|
+
const trgMeta = entity_metadata_js_1.EntityMetadata.define(UnionClass);
|
|
156
|
+
entity_metadata_js_1.EntityMetadata.mixin(trgMeta, srcMeta);
|
|
154
157
|
}
|
|
155
158
|
}
|
|
156
159
|
return UnionClass;
|
|
157
160
|
}
|
|
158
161
|
Entity.Union = Union;
|
|
159
|
-
})(Entity || (Entity = {}));
|
|
162
|
+
})(Entity || (exports.Entity = Entity = {}));
|
|
160
163
|
function applyConstructorProperties(target, sourceClass, constructorArgs, isPropertyInherited) {
|
|
161
164
|
try {
|
|
162
165
|
const tempInstance = new sourceClass(...constructorArgs);
|
|
@@ -1,55 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BeforeInsert = BeforeInsert;
|
|
4
|
+
exports.BeforeUpdate = BeforeUpdate;
|
|
5
|
+
exports.BeforeDestroy = BeforeDestroy;
|
|
6
|
+
exports.AfterInsert = AfterInsert;
|
|
7
|
+
exports.AfterUpdate = AfterUpdate;
|
|
8
|
+
exports.AfterDestroy = AfterDestroy;
|
|
9
|
+
const entity_metadata_js_1 = require("../model/entity-metadata.js");
|
|
10
|
+
function BeforeInsert() {
|
|
3
11
|
return (target, propertyKey) => {
|
|
4
12
|
if (typeof propertyKey !== 'string')
|
|
5
13
|
throw new Error('You can define a Column for only string properties');
|
|
6
|
-
const model = EntityMetadata.define(target.constructor);
|
|
14
|
+
const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
7
15
|
const fn = target.constructor.prototype[propertyKey];
|
|
8
|
-
EntityMetadata.addEventListener(model, 'before-insert', fn);
|
|
16
|
+
entity_metadata_js_1.EntityMetadata.addEventListener(model, 'before-insert', fn);
|
|
9
17
|
};
|
|
10
18
|
}
|
|
11
|
-
|
|
19
|
+
function BeforeUpdate() {
|
|
12
20
|
return (target, propertyKey) => {
|
|
13
21
|
if (typeof propertyKey !== 'string')
|
|
14
22
|
throw new Error('You can define a Column for only string properties');
|
|
15
|
-
const model = EntityMetadata.define(target.constructor);
|
|
23
|
+
const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
16
24
|
const fn = target.constructor.prototype[propertyKey];
|
|
17
|
-
EntityMetadata.addEventListener(model, 'before-update', fn);
|
|
25
|
+
entity_metadata_js_1.EntityMetadata.addEventListener(model, 'before-update', fn);
|
|
18
26
|
};
|
|
19
27
|
}
|
|
20
|
-
|
|
28
|
+
function BeforeDestroy() {
|
|
21
29
|
return (target, propertyKey) => {
|
|
22
30
|
if (typeof propertyKey !== 'string')
|
|
23
31
|
throw new Error('You can define a Column for only string properties');
|
|
24
|
-
const model = EntityMetadata.define(target.constructor);
|
|
32
|
+
const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
25
33
|
const fn = target.constructor.prototype[propertyKey];
|
|
26
|
-
EntityMetadata.addEventListener(model, 'before-destroy', fn);
|
|
34
|
+
entity_metadata_js_1.EntityMetadata.addEventListener(model, 'before-destroy', fn);
|
|
27
35
|
};
|
|
28
36
|
}
|
|
29
|
-
|
|
37
|
+
function AfterInsert() {
|
|
30
38
|
return (target, propertyKey) => {
|
|
31
39
|
if (typeof propertyKey !== 'string')
|
|
32
40
|
throw new Error('You can define a Column for only string properties');
|
|
33
|
-
const model = EntityMetadata.define(target.constructor);
|
|
41
|
+
const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
34
42
|
const fn = target.constructor.prototype[propertyKey];
|
|
35
|
-
EntityMetadata.addEventListener(model, 'after-insert', fn);
|
|
43
|
+
entity_metadata_js_1.EntityMetadata.addEventListener(model, 'after-insert', fn);
|
|
36
44
|
};
|
|
37
45
|
}
|
|
38
|
-
|
|
46
|
+
function AfterUpdate() {
|
|
39
47
|
return (target, propertyKey) => {
|
|
40
48
|
if (typeof propertyKey !== 'string')
|
|
41
49
|
throw new Error('You can define a Column for only string properties');
|
|
42
|
-
const model = EntityMetadata.define(target.constructor);
|
|
50
|
+
const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
43
51
|
const fn = target.constructor.prototype[propertyKey];
|
|
44
|
-
EntityMetadata.addEventListener(model, 'after-update', fn);
|
|
52
|
+
entity_metadata_js_1.EntityMetadata.addEventListener(model, 'after-update', fn);
|
|
45
53
|
};
|
|
46
54
|
}
|
|
47
|
-
|
|
55
|
+
function AfterDestroy() {
|
|
48
56
|
return (target, propertyKey) => {
|
|
49
57
|
if (typeof propertyKey !== 'string')
|
|
50
58
|
throw new Error('You can define a Column for only string properties');
|
|
51
|
-
const model = EntityMetadata.define(target.constructor);
|
|
59
|
+
const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
52
60
|
const fn = target.constructor.prototype[propertyKey];
|
|
53
|
-
EntityMetadata.addEventListener(model, 'after-destroy', fn);
|
|
61
|
+
entity_metadata_js_1.EntityMetadata.addEventListener(model, 'after-destroy', fn);
|
|
54
62
|
};
|
|
55
63
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ForeignKey = ForeignKey;
|
|
4
|
+
const entity_metadata_js_1 = require("../model/entity-metadata.js");
|
|
5
|
+
function ForeignKey(type, targetKey) {
|
|
3
6
|
return function (target, propertyKey) {
|
|
4
7
|
if (typeof propertyKey !== 'string')
|
|
5
8
|
throw new Error('Symbol properties are not accepted');
|
|
6
|
-
const entity = EntityMetadata.define(target.constructor);
|
|
7
|
-
EntityMetadata.addForeignKey(entity, propertyKey, type, targetKey);
|
|
9
|
+
const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
10
|
+
entity_metadata_js_1.EntityMetadata.addForeignKey(entity, propertyKey, type, targetKey);
|
|
8
11
|
};
|
|
9
12
|
}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Index = Index;
|
|
4
|
+
const entity_metadata_js_1 = require("../model/entity-metadata.js");
|
|
5
|
+
function Index(arg0, arg1) {
|
|
3
6
|
return function (target, propertyKey) {
|
|
4
7
|
if (typeof target === 'function') {
|
|
5
8
|
if (!(typeof arg0 === 'string' || Array.isArray(arg0)))
|
|
6
9
|
throw new Error(`You must specify index column(s)`);
|
|
7
|
-
const model = EntityMetadata.define(target);
|
|
8
|
-
return EntityMetadata.addIndex(model, { ...arg1, columns: arg0 });
|
|
10
|
+
const model = entity_metadata_js_1.EntityMetadata.define(target);
|
|
11
|
+
return entity_metadata_js_1.EntityMetadata.addIndex(model, { ...arg1, columns: arg0 });
|
|
9
12
|
}
|
|
10
13
|
if (!target.constructor)
|
|
11
14
|
throw new Error('Property decorators can be used for class properties only');
|
|
12
15
|
if (typeof propertyKey !== 'string')
|
|
13
16
|
throw new Error('Index() decorator can be used for string property keys only');
|
|
14
|
-
const model = EntityMetadata.define(target.constructor);
|
|
15
|
-
EntityMetadata.addIndex(model, { ...arg0, columns: [propertyKey] });
|
|
17
|
+
const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
18
|
+
entity_metadata_js_1.EntityMetadata.addIndex(model, { ...arg0, columns: [propertyKey] });
|
|
16
19
|
};
|
|
17
20
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Link = Link;
|
|
4
|
+
const entity_metadata_js_1 = require("../model/entity-metadata.js");
|
|
5
|
+
const link_chain_js_1 = require("../model/link-chain.js");
|
|
6
|
+
function Link(options) {
|
|
4
7
|
let root;
|
|
5
8
|
let chain;
|
|
6
9
|
const fn = (target, propertyKey) => {
|
|
@@ -11,7 +14,7 @@ export function Link(options) {
|
|
|
11
14
|
if (reflectType === Array) {
|
|
12
15
|
throw new TypeError(`Can't get type information while it is an array. Please define entity type`);
|
|
13
16
|
}
|
|
14
|
-
if (!EntityMetadata.get(reflectType))
|
|
17
|
+
if (!entity_metadata_js_1.EntityMetadata.get(reflectType))
|
|
15
18
|
throw new TypeError(`No entity metadata found for type "${reflectType}"`);
|
|
16
19
|
fn.toOne(reflectType);
|
|
17
20
|
}
|
|
@@ -21,11 +24,11 @@ export function Link(options) {
|
|
|
21
24
|
if (reflectType === Array && !root.first.returnsMany()) {
|
|
22
25
|
throw new TypeError(`Link returns array of instances however property type is not an array`);
|
|
23
26
|
}
|
|
24
|
-
const entity = EntityMetadata.define(target.constructor);
|
|
27
|
+
const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
25
28
|
// @ts-ignore
|
|
26
29
|
// noinspection JSConstantReassignment
|
|
27
30
|
root.first.source = entity.ctor;
|
|
28
|
-
EntityMetadata.defineAssociationField(entity, propertyKey, root.first, options);
|
|
31
|
+
entity_metadata_js_1.EntityMetadata.defineAssociationField(entity, propertyKey, root.first, options);
|
|
29
32
|
};
|
|
30
33
|
fn.toOne = (type, args) => {
|
|
31
34
|
if (chain) {
|
|
@@ -59,11 +62,11 @@ export function Link(options) {
|
|
|
59
62
|
* Crates an Link Chain object
|
|
60
63
|
*/
|
|
61
64
|
function linkToOne(type, targetKey, sourceKey) {
|
|
62
|
-
return new LinkChain(type, targetKey, sourceKey);
|
|
65
|
+
return new link_chain_js_1.LinkChain(type, targetKey, sourceKey);
|
|
63
66
|
}
|
|
64
67
|
/**
|
|
65
68
|
* Crates an Link Chain object
|
|
66
69
|
*/
|
|
67
70
|
function linkToMany(type, targetKey, sourceKey) {
|
|
68
|
-
return new LinkChain(type, targetKey, sourceKey, true);
|
|
71
|
+
return new link_chain_js_1.LinkChain(type, targetKey, sourceKey, true);
|
|
69
72
|
}
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PrimaryKey = PrimaryKey;
|
|
4
|
+
const entity_metadata_js_1 = require("../model/entity-metadata.js");
|
|
5
|
+
const column_decorator_js_1 = require("./column.decorator.js");
|
|
6
|
+
function PrimaryKey(arg0, arg1) {
|
|
4
7
|
return function (target, propertyKey) {
|
|
5
8
|
if (arguments.length === 1) {
|
|
6
9
|
if (!(typeof arg0 === 'string' || Array.isArray(arg0))) {
|
|
7
10
|
throw new Error(`You must specify primary index column(s)`);
|
|
8
11
|
}
|
|
9
|
-
const meta = EntityMetadata.define(target);
|
|
10
|
-
EntityMetadata.setPrimaryKeys(meta, arg0, arg1);
|
|
12
|
+
const meta = entity_metadata_js_1.EntityMetadata.define(target);
|
|
13
|
+
entity_metadata_js_1.EntityMetadata.setPrimaryKeys(meta, arg0, arg1);
|
|
11
14
|
return;
|
|
12
15
|
}
|
|
13
16
|
if (!target.constructor)
|
|
14
17
|
throw new Error('Property decorators can be used for class properties only');
|
|
15
18
|
if (typeof propertyKey !== 'string')
|
|
16
19
|
throw new Error('Index() decorator can be used for string property keys only');
|
|
17
|
-
const meta = EntityMetadata.define(target.constructor);
|
|
18
|
-
Column({ notNull: true })(target, propertyKey);
|
|
19
|
-
EntityMetadata.setPrimaryKeys(meta, propertyKey, arg0);
|
|
20
|
+
const meta = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
21
|
+
(0, column_decorator_js_1.Column)({ notNull: true })(target, propertyKey);
|
|
22
|
+
entity_metadata_js_1.EntityMetadata.setPrimaryKeys(meta, propertyKey, arg0);
|
|
20
23
|
};
|
|
21
24
|
}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Parse = Parse;
|
|
4
|
+
exports.Serialize = Serialize;
|
|
5
|
+
const entity_metadata_js_1 = require("../model/entity-metadata.js");
|
|
6
|
+
function Parse(fn) {
|
|
3
7
|
return (target, propertyKey) => {
|
|
4
8
|
if (typeof propertyKey !== 'string')
|
|
5
9
|
throw new Error('You can define a Column for only string properties');
|
|
6
|
-
const entity = EntityMetadata.define(target.constructor);
|
|
7
|
-
EntityMetadata.defineColumnField(entity, propertyKey).parse = fn;
|
|
10
|
+
const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
11
|
+
entity_metadata_js_1.EntityMetadata.defineColumnField(entity, propertyKey).parse = fn;
|
|
8
12
|
};
|
|
9
13
|
}
|
|
10
|
-
|
|
14
|
+
function Serialize(fn) {
|
|
11
15
|
return (target, propertyKey) => {
|
|
12
16
|
if (typeof propertyKey !== 'string')
|
|
13
17
|
throw new Error('You can define a Column for only string properties');
|
|
14
|
-
const entity = EntityMetadata.define(target.constructor);
|
|
15
|
-
EntityMetadata.defineColumnField(entity, propertyKey).serialize = fn;
|
|
18
|
+
const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
19
|
+
entity_metadata_js_1.EntityMetadata.defineColumnField(entity, propertyKey).serialize = fn;
|
|
16
20
|
};
|
|
17
21
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AssociationFieldMetadata = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
6
|
+
var AssociationFieldMetadata;
|
|
3
7
|
(function (AssociationFieldMetadata) {
|
|
4
8
|
function create(entity, name, association, options = {}) {
|
|
5
9
|
const result = {
|
|
@@ -14,7 +18,7 @@ export var AssociationFieldMetadata;
|
|
|
14
18
|
}
|
|
15
19
|
AssociationFieldMetadata.create = create;
|
|
16
20
|
function assign(target, options) {
|
|
17
|
-
Object.assign(target,
|
|
21
|
+
Object.assign(target, lodash_1.default.omit(options, ['entity', 'name', 'kind', 'association']));
|
|
18
22
|
}
|
|
19
23
|
AssociationFieldMetadata.assign = assign;
|
|
20
|
-
})(AssociationFieldMetadata || (AssociationFieldMetadata = {}));
|
|
24
|
+
})(AssociationFieldMetadata || (exports.AssociationFieldMetadata = AssociationFieldMetadata = {}));
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AssociationNode = void 0;
|
|
4
|
+
const association_js_1 = require("./association.js");
|
|
5
|
+
class AssociationNode extends association_js_1.Association {
|
|
3
6
|
getFirst() {
|
|
4
7
|
let l = this;
|
|
5
8
|
while (l.prior)
|
|
@@ -19,3 +22,4 @@ export class AssociationNode extends Association {
|
|
|
19
22
|
return !!(this.next && this.next.returnsMany());
|
|
20
23
|
}
|
|
21
24
|
}
|
|
25
|
+
exports.AssociationNode = AssociationNode;
|