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