@sqb/connect 4.2.1 → 4.5.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/README.md +67 -0
- package/{dist/client/Adapter.js → cjs/client/adapter.js} +0 -0
- package/{dist/client/CursorStream.js → cjs/client/cursor-stream.js} +5 -2
- package/{dist/client/Cursor.js → cjs/client/cursor.js} +18 -11
- package/{dist → cjs}/client/extensions.js +0 -0
- package/{dist/client/FieldInfoMap.js → cjs/client/field-info-map.js} +2 -0
- package/{dist → cjs}/client/helpers.js +2 -2
- package/{dist/client/SqbClient.js → cjs/client/sqb-client.js} +16 -10
- package/{dist/client/SqbConnection.js → cjs/client/sqb-connection.js} +17 -14
- package/{dist → cjs}/client/types.js +0 -0
- package/cjs/index.js +42 -0
- package/{dist → cjs}/orm/backward.js +8 -8
- package/{dist → cjs}/orm/base-entity.js +8 -7
- package/{dist → cjs}/orm/commands/command.helper.js +9 -9
- package/{dist → cjs}/orm/commands/count.command.js +2 -2
- package/{dist → cjs}/orm/commands/create.command.js +12 -12
- package/{dist → cjs}/orm/commands/destroy.command.js +2 -2
- package/{dist → cjs}/orm/commands/find.command.js +100 -88
- package/{dist → cjs}/orm/commands/row-converter.js +10 -7
- package/{dist → cjs}/orm/commands/update.command.js +10 -10
- package/{dist → cjs}/orm/decorators/column.decorator.js +3 -3
- package/{dist → cjs}/orm/decorators/embedded.decorator.js +3 -3
- package/cjs/orm/decorators/entity.decorator.js +179 -0
- package/{dist → cjs}/orm/decorators/events.decorator.js +13 -13
- package/{dist → cjs}/orm/decorators/foreignkey.decorator.js +3 -3
- package/{dist → cjs}/orm/decorators/index.decorator.js +5 -5
- package/cjs/orm/decorators/link.decorator.js +70 -0
- package/{dist → cjs}/orm/decorators/primarykey.decorator.js +7 -7
- package/{dist → cjs}/orm/decorators/transform.decorator.js +5 -5
- package/cjs/orm/model/association-field-metadata.js +24 -0
- package/{dist → cjs}/orm/model/association-node.js +5 -2
- package/{dist → cjs}/orm/model/association.js +31 -39
- package/{dist/orm/model/column-element-metadata.js → cjs/orm/model/column-field-metadata.js} +8 -8
- package/{dist/orm/model/embedded-element-metadata.js → cjs/orm/model/embedded-field-metadata.js} +8 -8
- package/{dist → cjs}/orm/model/entity-metadata.js +90 -91
- package/{dist/orm/model/element-metadata.js → cjs/orm/model/field-metadata.js} +0 -0
- package/{dist → cjs}/orm/model/index-metadata.js +0 -0
- package/{dist → cjs}/orm/model/link-chain.js +12 -15
- package/{dist → cjs}/orm/orm.const.js +0 -0
- package/{dist → cjs}/orm/orm.type.js +0 -0
- package/{dist → cjs}/orm/repository.class.js +25 -22
- package/{dist → cjs}/orm/util/apply-mixins.js +0 -0
- package/{dist → cjs}/orm/util/extract-keyvalues.js +5 -5
- package/{dist → cjs}/orm/util/orm.helper.js +10 -10
- package/{dist/orm/util/serialize-element.js → cjs/orm/util/serialize-field.js} +2 -2
- package/cjs/package.json +3 -0
- package/{dist → cjs}/types.js +0 -0
- package/{dist/client/Adapter.d.ts → esm/client/adapter.d.ts} +1 -1
- package/esm/client/adapter.js +1 -0
- package/{dist/client/CursorStream.d.ts → esm/client/cursor-stream.d.ts} +1 -1
- package/esm/client/cursor-stream.js +96 -0
- package/{dist/client/Cursor.d.ts → esm/client/cursor.d.ts} +5 -5
- package/esm/client/cursor.js +252 -0
- package/{dist → esm}/client/extensions.d.ts +1 -1
- package/esm/client/extensions.js +9 -0
- package/{dist/client/FieldInfoMap.d.ts → esm/client/field-info-map.d.ts} +1 -1
- package/esm/client/field-info-map.js +50 -0
- package/{dist → esm}/client/helpers.d.ts +3 -3
- package/esm/client/helpers.js +125 -0
- package/{dist/client/SqbClient.d.ts → esm/client/sqb-client.d.ts} +4 -10
- package/esm/client/sqb-client.js +166 -0
- package/{dist/client/SqbConnection.d.ts → esm/client/sqb-connection.d.ts} +4 -4
- package/esm/client/sqb-connection.js +270 -0
- package/{dist → esm}/client/types.d.ts +5 -13
- package/esm/client/types.js +1 -0
- package/esm/index.d.ts +33 -0
- package/esm/index.js +32 -0
- package/{dist → esm}/orm/backward.d.ts +1 -1
- package/esm/orm/backward.js +17 -0
- package/{dist → esm}/orm/base-entity.d.ts +1 -1
- package/esm/orm/base-entity.js +25 -0
- package/{dist → esm}/orm/commands/command.helper.d.ts +2 -2
- package/esm/orm/commands/command.helper.js +135 -0
- package/{dist → esm}/orm/commands/count.command.d.ts +3 -3
- package/esm/orm/commands/count.command.js +26 -0
- package/{dist → esm}/orm/commands/create.command.d.ts +2 -2
- package/esm/orm/commands/create.command.js +85 -0
- package/{dist → esm}/orm/commands/destroy.command.d.ts +3 -3
- package/esm/orm/commands/destroy.command.js +26 -0
- package/{dist → esm}/orm/commands/find.command.d.ts +9 -9
- package/esm/orm/commands/find.command.js +318 -0
- package/{dist → esm}/orm/commands/row-converter.d.ts +5 -5
- package/esm/orm/commands/row-converter.js +186 -0
- package/{dist → esm}/orm/commands/update.command.d.ts +3 -3
- package/esm/orm/commands/update.command.js +80 -0
- package/esm/orm/decorators/column.decorator.d.ts +4 -0
- package/esm/orm/decorators/column.decorator.js +19 -0
- package/esm/orm/decorators/embedded.decorator.d.ts +3 -0
- package/esm/orm/decorators/embedded.decorator.js +12 -0
- package/{dist → esm}/orm/decorators/entity.decorator.d.ts +17 -17
- package/esm/orm/decorators/entity.decorator.js +175 -0
- package/{dist → esm}/orm/decorators/events.decorator.d.ts +0 -0
- package/esm/orm/decorators/events.decorator.js +55 -0
- package/{dist → esm}/orm/decorators/foreignkey.decorator.d.ts +1 -1
- package/esm/orm/decorators/foreignkey.decorator.js +9 -0
- package/{dist → esm}/orm/decorators/index.decorator.d.ts +1 -1
- package/esm/orm/decorators/index.decorator.js +17 -0
- package/esm/orm/decorators/link.decorator.d.ts +13 -0
- package/esm/orm/decorators/link.decorator.js +66 -0
- package/{dist → esm}/orm/decorators/primarykey.decorator.d.ts +1 -1
- package/esm/orm/decorators/primarykey.decorator.js +20 -0
- package/{dist → esm}/orm/decorators/transform.decorator.d.ts +1 -1
- package/esm/orm/decorators/transform.decorator.js +19 -0
- package/esm/orm/model/association-field-metadata.d.ts +12 -0
- package/esm/orm/model/association-field-metadata.js +20 -0
- package/{dist → esm}/orm/model/association-node.d.ts +1 -1
- package/esm/orm/model/association-node.js +24 -0
- package/{dist → esm}/orm/model/association.d.ts +6 -7
- package/esm/orm/model/association.js +118 -0
- package/{dist/orm/model/column-element-metadata.d.ts → esm/orm/model/column-field-metadata.d.ts} +10 -14
- package/esm/orm/model/column-field-metadata.js +28 -0
- package/esm/orm/model/embedded-field-metadata.d.ts +14 -0
- package/esm/orm/model/embedded-field-metadata.js +25 -0
- package/esm/orm/model/entity-metadata.d.ts +50 -0
- package/esm/orm/model/entity-metadata.js +337 -0
- package/esm/orm/model/field-metadata.d.ts +16 -0
- package/esm/orm/model/field-metadata.js +1 -0
- package/{dist → esm}/orm/model/index-metadata.d.ts +0 -0
- package/esm/orm/model/index-metadata.js +1 -0
- package/esm/orm/model/link-chain.d.ts +13 -0
- package/esm/orm/model/link-chain.js +43 -0
- package/{dist → esm}/orm/orm.const.d.ts +0 -0
- package/esm/orm/orm.const.js +2 -0
- package/{dist → esm}/orm/orm.type.d.ts +3 -4
- package/esm/orm/orm.type.js +1 -0
- package/{dist → esm}/orm/repository.class.d.ts +23 -23
- package/esm/orm/repository.class.js +238 -0
- package/{dist → esm}/orm/util/apply-mixins.d.ts +0 -0
- package/esm/orm/util/apply-mixins.js +9 -0
- package/{dist → esm}/orm/util/extract-keyvalues.d.ts +1 -1
- package/esm/orm/util/extract-keyvalues.js +57 -0
- package/esm/orm/util/orm.helper.d.ts +13 -0
- package/esm/orm/util/orm.helper.js +28 -0
- package/esm/orm/util/serialize-field.d.ts +2 -0
- package/esm/orm/util/serialize-field.js +39 -0
- package/esm/types.d.ts +7 -0
- package/esm/types.js +1 -0
- package/package.json +54 -41
- package/dist/index.d.ts +0 -33
- package/dist/index.js +0 -42
- package/dist/orm/decorators/column.decorator.d.ts +0 -4
- package/dist/orm/decorators/embedded.decorator.d.ts +0 -3
- package/dist/orm/decorators/entity.decorator.js +0 -179
- package/dist/orm/decorators/link.decorator.d.ts +0 -23
- package/dist/orm/decorators/link.decorator.js +0 -88
- package/dist/orm/model/association-element-metadata.d.ts +0 -10
- package/dist/orm/model/association-element-metadata.js +0 -15
- package/dist/orm/model/element-metadata.d.ts +0 -7
- package/dist/orm/model/embedded-element-metadata.d.ts +0 -14
- package/dist/orm/model/entity-metadata.d.ts +0 -50
- package/dist/orm/model/link-chain.d.ts +0 -15
- package/dist/orm/util/orm.helper.d.ts +0 -13
- package/dist/orm/util/serialize-element.d.ts +0 -2
- package/dist/types.d.ts +0 -2
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AfterDestroy = exports.AfterUpdate = exports.AfterInsert = exports.BeforeDestroy = exports.BeforeUpdate = exports.BeforeInsert = void 0;
|
|
4
|
-
const
|
|
4
|
+
const entity_metadata_js_1 = require("../model/entity-metadata.js");
|
|
5
5
|
function BeforeInsert() {
|
|
6
6
|
return (target, propertyKey) => {
|
|
7
7
|
if (typeof propertyKey !== 'string')
|
|
8
8
|
throw new Error('You can define a Column for only string properties');
|
|
9
|
-
const model =
|
|
9
|
+
const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
10
10
|
const fn = target.constructor.prototype[propertyKey];
|
|
11
|
-
|
|
11
|
+
entity_metadata_js_1.EntityMetadata.addEventListener(model, 'before-insert', fn);
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
exports.BeforeInsert = BeforeInsert;
|
|
@@ -16,9 +16,9 @@ function BeforeUpdate() {
|
|
|
16
16
|
return (target, propertyKey) => {
|
|
17
17
|
if (typeof propertyKey !== 'string')
|
|
18
18
|
throw new Error('You can define a Column for only string properties');
|
|
19
|
-
const model =
|
|
19
|
+
const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
20
20
|
const fn = target.constructor.prototype[propertyKey];
|
|
21
|
-
|
|
21
|
+
entity_metadata_js_1.EntityMetadata.addEventListener(model, 'before-update', fn);
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
exports.BeforeUpdate = BeforeUpdate;
|
|
@@ -26,9 +26,9 @@ function BeforeDestroy() {
|
|
|
26
26
|
return (target, propertyKey) => {
|
|
27
27
|
if (typeof propertyKey !== 'string')
|
|
28
28
|
throw new Error('You can define a Column for only string properties');
|
|
29
|
-
const model =
|
|
29
|
+
const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
30
30
|
const fn = target.constructor.prototype[propertyKey];
|
|
31
|
-
|
|
31
|
+
entity_metadata_js_1.EntityMetadata.addEventListener(model, 'before-destroy', fn);
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
exports.BeforeDestroy = BeforeDestroy;
|
|
@@ -36,9 +36,9 @@ function AfterInsert() {
|
|
|
36
36
|
return (target, propertyKey) => {
|
|
37
37
|
if (typeof propertyKey !== 'string')
|
|
38
38
|
throw new Error('You can define a Column for only string properties');
|
|
39
|
-
const model =
|
|
39
|
+
const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
40
40
|
const fn = target.constructor.prototype[propertyKey];
|
|
41
|
-
|
|
41
|
+
entity_metadata_js_1.EntityMetadata.addEventListener(model, 'after-insert', fn);
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
exports.AfterInsert = AfterInsert;
|
|
@@ -46,9 +46,9 @@ function AfterUpdate() {
|
|
|
46
46
|
return (target, propertyKey) => {
|
|
47
47
|
if (typeof propertyKey !== 'string')
|
|
48
48
|
throw new Error('You can define a Column for only string properties');
|
|
49
|
-
const model =
|
|
49
|
+
const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
50
50
|
const fn = target.constructor.prototype[propertyKey];
|
|
51
|
-
|
|
51
|
+
entity_metadata_js_1.EntityMetadata.addEventListener(model, 'after-update', fn);
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
exports.AfterUpdate = AfterUpdate;
|
|
@@ -56,9 +56,9 @@ function AfterDestroy() {
|
|
|
56
56
|
return (target, propertyKey) => {
|
|
57
57
|
if (typeof propertyKey !== 'string')
|
|
58
58
|
throw new Error('You can define a Column for only string properties');
|
|
59
|
-
const model =
|
|
59
|
+
const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
60
60
|
const fn = target.constructor.prototype[propertyKey];
|
|
61
|
-
|
|
61
|
+
entity_metadata_js_1.EntityMetadata.addEventListener(model, 'after-destroy', fn);
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
exports.AfterDestroy = AfterDestroy;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ForeignKey = void 0;
|
|
4
|
-
const
|
|
4
|
+
const entity_metadata_js_1 = require("../model/entity-metadata.js");
|
|
5
5
|
function ForeignKey(type, targetKey) {
|
|
6
6
|
return function (target, propertyKey) {
|
|
7
7
|
if (typeof propertyKey !== 'string')
|
|
8
8
|
throw new Error('Symbol properties are not accepted');
|
|
9
|
-
const entity =
|
|
10
|
-
|
|
9
|
+
const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
10
|
+
entity_metadata_js_1.EntityMetadata.addForeignKey(entity, propertyKey, type, targetKey);
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
exports.ForeignKey = ForeignKey;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Index = void 0;
|
|
4
|
-
const
|
|
4
|
+
const entity_metadata_js_1 = require("../model/entity-metadata.js");
|
|
5
5
|
function Index(arg0, arg1) {
|
|
6
6
|
return function (target, propertyKey) {
|
|
7
7
|
if (typeof target === 'function') {
|
|
8
8
|
if (!(typeof arg0 === 'string' || Array.isArray(arg0)))
|
|
9
9
|
throw new Error(`You must specify index column(s)`);
|
|
10
|
-
const model =
|
|
11
|
-
return
|
|
10
|
+
const model = entity_metadata_js_1.EntityMetadata.define(target);
|
|
11
|
+
return entity_metadata_js_1.EntityMetadata.addIndex(model, { ...arg1, columns: arg0 });
|
|
12
12
|
}
|
|
13
13
|
if (!target.constructor)
|
|
14
14
|
throw new Error('Property decorators can be used for class properties only');
|
|
15
15
|
if (typeof propertyKey !== 'string')
|
|
16
16
|
throw new Error('Index() decorator can be used for string property keys only');
|
|
17
|
-
const model =
|
|
18
|
-
|
|
17
|
+
const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
18
|
+
entity_metadata_js_1.EntityMetadata.addIndex(model, { ...arg0, columns: [propertyKey] });
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
exports.Index = Index;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Link = void 0;
|
|
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
|
+
if (!entity_metadata_js_1.EntityMetadata.get(reflectType))
|
|
17
|
+
throw new TypeError(`No entity metadata found for type "${reflectType}"`);
|
|
18
|
+
fn.toOne(reflectType);
|
|
19
|
+
}
|
|
20
|
+
if (reflectType !== Array && root.first.returnsMany())
|
|
21
|
+
throw new TypeError(`Link returns single instance however property type is an array`);
|
|
22
|
+
if (reflectType === Array && !root.first.returnsMany())
|
|
23
|
+
throw new TypeError(`Link returns array of instances however property type is not an array`);
|
|
24
|
+
const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
// noinspection JSConstantReassignment
|
|
27
|
+
root.first.source = entity.ctor;
|
|
28
|
+
entity_metadata_js_1.EntityMetadata.defineAssociationField(entity, propertyKey, root.first, options);
|
|
29
|
+
};
|
|
30
|
+
fn.toOne = (type, args) => {
|
|
31
|
+
if (chain) {
|
|
32
|
+
chain = chain.linkToOne(type, args?.targetKey, args?.sourceKey);
|
|
33
|
+
if (args?.where)
|
|
34
|
+
chain.where(args.where);
|
|
35
|
+
return fn;
|
|
36
|
+
}
|
|
37
|
+
root = linkToOne(type, args?.targetKey, args?.sourceKey);
|
|
38
|
+
chain = root;
|
|
39
|
+
if (args?.where)
|
|
40
|
+
chain.where(args.where);
|
|
41
|
+
return fn;
|
|
42
|
+
};
|
|
43
|
+
fn.toMany = (type, args) => {
|
|
44
|
+
if (chain) {
|
|
45
|
+
chain = chain.linkToMany(type, args?.targetKey, args?.sourceKey);
|
|
46
|
+
if (args?.where)
|
|
47
|
+
chain.where(args.where);
|
|
48
|
+
return fn;
|
|
49
|
+
}
|
|
50
|
+
root = linkToMany(type, args?.targetKey, args?.sourceKey);
|
|
51
|
+
chain = root;
|
|
52
|
+
if (args?.where)
|
|
53
|
+
chain.where(args.where);
|
|
54
|
+
return fn;
|
|
55
|
+
};
|
|
56
|
+
return fn;
|
|
57
|
+
}
|
|
58
|
+
exports.Link = Link;
|
|
59
|
+
/**
|
|
60
|
+
* Crates an Link Chain object
|
|
61
|
+
*/
|
|
62
|
+
function linkToOne(type, targetKey, sourceKey) {
|
|
63
|
+
return new link_chain_js_1.LinkChain(type, targetKey, sourceKey);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Crates an Link Chain object
|
|
67
|
+
*/
|
|
68
|
+
function linkToMany(type, targetKey, sourceKey) {
|
|
69
|
+
return new link_chain_js_1.LinkChain(type, targetKey, sourceKey, true);
|
|
70
|
+
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PrimaryKey = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const entity_metadata_js_1 = require("../model/entity-metadata.js");
|
|
5
|
+
const column_decorator_js_1 = require("./column.decorator.js");
|
|
6
6
|
function PrimaryKey(arg0, arg1) {
|
|
7
7
|
return function (target, propertyKey) {
|
|
8
8
|
if (arguments.length === 1) {
|
|
9
9
|
if (!(typeof arg0 === 'string' || Array.isArray(arg0)))
|
|
10
10
|
throw new Error(`You must specify primary index column(s)`);
|
|
11
|
-
const meta =
|
|
12
|
-
|
|
11
|
+
const meta = entity_metadata_js_1.EntityMetadata.define(target);
|
|
12
|
+
entity_metadata_js_1.EntityMetadata.setPrimaryKeys(meta, arg0, arg1);
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
if (!target.constructor)
|
|
16
16
|
throw new Error('Property decorators can be used for class properties only');
|
|
17
17
|
if (typeof propertyKey !== 'string')
|
|
18
18
|
throw new Error('Index() decorator can be used for string property keys only');
|
|
19
|
-
const meta =
|
|
20
|
-
(0,
|
|
21
|
-
|
|
19
|
+
const meta = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
20
|
+
(0, column_decorator_js_1.Column)({ notNull: true })(target, propertyKey);
|
|
21
|
+
entity_metadata_js_1.EntityMetadata.setPrimaryKeys(meta, propertyKey, arg0);
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
exports.PrimaryKey = PrimaryKey;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Serialize = exports.Parse = void 0;
|
|
4
|
-
const
|
|
4
|
+
const entity_metadata_js_1 = require("../model/entity-metadata.js");
|
|
5
5
|
function Parse(fn) {
|
|
6
6
|
return (target, propertyKey) => {
|
|
7
7
|
if (typeof propertyKey !== 'string')
|
|
8
8
|
throw new Error('You can define a Column for only string properties');
|
|
9
|
-
const entity =
|
|
10
|
-
|
|
9
|
+
const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
10
|
+
entity_metadata_js_1.EntityMetadata.defineColumnField(entity, propertyKey)
|
|
11
11
|
.parse = fn;
|
|
12
12
|
};
|
|
13
13
|
}
|
|
@@ -16,8 +16,8 @@ function Serialize(fn) {
|
|
|
16
16
|
return (target, propertyKey) => {
|
|
17
17
|
if (typeof propertyKey !== 'string')
|
|
18
18
|
throw new Error('You can define a Column for only string properties');
|
|
19
|
-
const entity =
|
|
20
|
-
|
|
19
|
+
const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
|
|
20
|
+
entity_metadata_js_1.EntityMetadata.defineColumnField(entity, propertyKey)
|
|
21
21
|
.serialize = fn;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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 || (exports.AssociationFieldMetadata = {}));
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AssociationNode = void 0;
|
|
4
|
-
const
|
|
5
|
-
class AssociationNode extends
|
|
4
|
+
const association_js_1 = require("./association.js");
|
|
5
|
+
class AssociationNode extends association_js_1.Association {
|
|
6
|
+
prior;
|
|
7
|
+
next;
|
|
8
|
+
conditions;
|
|
6
9
|
getFirst() {
|
|
7
10
|
let l = this;
|
|
8
11
|
while (l.prior)
|
|
@@ -2,25 +2,38 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Association = void 0;
|
|
4
4
|
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const orm_helper_js_1 = require("../util/orm.helper.js");
|
|
6
|
+
const entity_metadata_js_1 = require("./entity-metadata.js");
|
|
7
7
|
class Association {
|
|
8
|
+
_resolved;
|
|
9
|
+
_source; // cached value
|
|
10
|
+
_target; // cached value
|
|
11
|
+
_sourceKey; // cached value
|
|
12
|
+
_targetKey; // cached value
|
|
13
|
+
_sourceProperty;
|
|
14
|
+
_targetProperty;
|
|
15
|
+
name;
|
|
16
|
+
source;
|
|
17
|
+
target;
|
|
18
|
+
sourceKey;
|
|
19
|
+
targetKey;
|
|
20
|
+
many;
|
|
8
21
|
constructor(name, args) {
|
|
9
22
|
this.name = name;
|
|
10
23
|
this.source = args.source;
|
|
11
24
|
this.target = args.target;
|
|
12
25
|
this.sourceKey = args.sourceKey;
|
|
13
26
|
this.targetKey = args.targetKey;
|
|
14
|
-
this.
|
|
27
|
+
this.many = !!args.many;
|
|
15
28
|
}
|
|
16
29
|
async resolveSource() {
|
|
17
|
-
this._source = await (0,
|
|
30
|
+
this._source = await (0, orm_helper_js_1.resolveEntityMeta)(this.source);
|
|
18
31
|
if (!this._source)
|
|
19
32
|
throw new Error(`Can't resolve source entity of association "${this.name}"`);
|
|
20
33
|
return this._source;
|
|
21
34
|
}
|
|
22
35
|
async resolveTarget() {
|
|
23
|
-
this._target = await (0,
|
|
36
|
+
this._target = await (0, orm_helper_js_1.resolveEntityMeta)(this.target);
|
|
24
37
|
if (!this._target)
|
|
25
38
|
throw new Error(`Can't resolve target entity of association "${this.name}"`);
|
|
26
39
|
return this._target;
|
|
@@ -45,11 +58,8 @@ class Association {
|
|
|
45
58
|
// @ts-ignore
|
|
46
59
|
return this._targetProperty;
|
|
47
60
|
}
|
|
48
|
-
get sourceBelongsToTarget() {
|
|
49
|
-
return this.kind === 'from' || this.kind === 'from-many';
|
|
50
|
-
}
|
|
51
61
|
returnsMany() {
|
|
52
|
-
return this.
|
|
62
|
+
return this.many;
|
|
53
63
|
}
|
|
54
64
|
async _resolveKeys() {
|
|
55
65
|
if (this._resolved)
|
|
@@ -60,7 +70,7 @@ class Association {
|
|
|
60
70
|
let targetKey = this.targetKey;
|
|
61
71
|
if (!(sourceKey && targetKey)) {
|
|
62
72
|
// Try to determine key fields from foreign key from source to target
|
|
63
|
-
let foreign = await
|
|
73
|
+
let foreign = await entity_metadata_js_1.EntityMetadata.getForeignKeyFor(source, target);
|
|
64
74
|
if (foreign && foreign !== this) {
|
|
65
75
|
await foreign._resolveKeys();
|
|
66
76
|
this._sourceKey = foreign._sourceKey;
|
|
@@ -71,7 +81,7 @@ class Association {
|
|
|
71
81
|
}
|
|
72
82
|
else {
|
|
73
83
|
// Try to determine key fields from foreign key from target to source
|
|
74
|
-
foreign = await
|
|
84
|
+
foreign = await entity_metadata_js_1.EntityMetadata.getForeignKeyFor(target, source);
|
|
75
85
|
if (foreign && foreign !== this) {
|
|
76
86
|
await foreign._resolveKeys();
|
|
77
87
|
this._sourceKey = foreign._targetKey;
|
|
@@ -81,46 +91,28 @@ class Association {
|
|
|
81
91
|
return;
|
|
82
92
|
}
|
|
83
93
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
let masterKey;
|
|
87
|
-
let detailKey;
|
|
88
|
-
if (this.sourceBelongsToTarget) {
|
|
89
|
-
master = target;
|
|
90
|
-
detail = source;
|
|
91
|
-
masterKey = targetKey || '';
|
|
92
|
-
detailKey = sourceKey || '';
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
master = source;
|
|
96
|
-
detail = target;
|
|
97
|
-
detailKey = targetKey || '';
|
|
98
|
-
masterKey = sourceKey || '';
|
|
99
|
-
}
|
|
94
|
+
const master = source;
|
|
95
|
+
const detail = target;
|
|
96
|
+
let masterKey = sourceKey || '';
|
|
97
|
+
let detailKey = targetKey || '';
|
|
100
98
|
if (!detailKey) {
|
|
101
|
-
const primaryIndexColumns =
|
|
99
|
+
const primaryIndexColumns = entity_metadata_js_1.EntityMetadata.getPrimaryIndexColumns(detail);
|
|
102
100
|
detailKey = primaryIndexColumns && primaryIndexColumns.length === 1 ?
|
|
103
101
|
primaryIndexColumns[0].name : 'id';
|
|
104
102
|
}
|
|
105
103
|
if (!masterKey) {
|
|
106
104
|
// snake-case
|
|
107
105
|
masterKey = detail.name[0].toLowerCase() + detail.name.substring(1) + '_' + detailKey;
|
|
108
|
-
if (!
|
|
106
|
+
if (!entity_metadata_js_1.EntityMetadata.getColumnField(master, masterKey))
|
|
109
107
|
masterKey = (0, putil_varhelpers_1.camelCase)(masterKey);
|
|
110
108
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
sourceKey = detailKey;
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
targetKey = detailKey;
|
|
117
|
-
sourceKey = masterKey;
|
|
118
|
-
}
|
|
109
|
+
targetKey = detailKey;
|
|
110
|
+
sourceKey = masterKey;
|
|
119
111
|
}
|
|
120
|
-
this._targetProperty =
|
|
112
|
+
this._targetProperty = entity_metadata_js_1.EntityMetadata.getColumnField(target, targetKey);
|
|
121
113
|
if (!this._targetProperty)
|
|
122
114
|
throw new Error(`Can't determine target key of ${this.name}`);
|
|
123
|
-
this._sourceProperty =
|
|
115
|
+
this._sourceProperty = entity_metadata_js_1.EntityMetadata.getColumnField(source, sourceKey);
|
|
124
116
|
if (!this._sourceProperty)
|
|
125
117
|
throw new Error(`Can't determine source key of ${this.name}`);
|
|
126
118
|
this._targetKey = targetKey;
|
package/{dist/orm/model/column-element-metadata.js → cjs/orm/model/column-field-metadata.js}
RENAMED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ColumnFieldMetadata = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
6
|
-
var
|
|
7
|
-
(function (
|
|
6
|
+
var ColumnFieldMetadata;
|
|
7
|
+
(function (ColumnFieldMetadata) {
|
|
8
8
|
function create(entity, name, options = {}) {
|
|
9
9
|
const result = {
|
|
10
10
|
kind: 'column',
|
|
@@ -13,14 +13,14 @@ var ColumnElementMetadata;
|
|
|
13
13
|
fieldName: name
|
|
14
14
|
};
|
|
15
15
|
if (options)
|
|
16
|
-
|
|
16
|
+
ColumnFieldMetadata.assign(result, options);
|
|
17
17
|
return result;
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
ColumnFieldMetadata.create = create;
|
|
20
20
|
function assign(target, options) {
|
|
21
21
|
Object.assign(target, lodash_1.default.omit(options, ['entity', 'name', 'kind']));
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
ColumnFieldMetadata.assign = assign;
|
|
24
24
|
function checkEnumValue(col, v) {
|
|
25
25
|
if (v === undefined || !col.enum || (v == null && !col.notNull))
|
|
26
26
|
return;
|
|
@@ -28,5 +28,5 @@ var ColumnElementMetadata;
|
|
|
28
28
|
if (!enumKeys.includes(v))
|
|
29
29
|
throw new Error(`${col.entity.name}.${col.name} value must be one of (${enumKeys})`);
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
})(
|
|
31
|
+
ColumnFieldMetadata.checkEnumValue = checkEnumValue;
|
|
32
|
+
})(ColumnFieldMetadata = exports.ColumnFieldMetadata || (exports.ColumnFieldMetadata = {}));
|
package/{dist/orm/model/embedded-element-metadata.js → cjs/orm/model/embedded-field-metadata.js}
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
var
|
|
6
|
-
(function (
|
|
3
|
+
exports.EmbeddedFieldMetadata = void 0;
|
|
4
|
+
const orm_helper_js_1 = require("../util/orm.helper.js");
|
|
5
|
+
var EmbeddedFieldMetadata;
|
|
6
|
+
(function (EmbeddedFieldMetadata) {
|
|
7
7
|
function create(entity, name, type, options) {
|
|
8
8
|
const result = {
|
|
9
9
|
kind: 'object',
|
|
@@ -17,12 +17,12 @@ var EmbeddedElementMetadata;
|
|
|
17
17
|
result.fieldNameSuffix = options.fieldNameSuffix;
|
|
18
18
|
return result;
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
EmbeddedFieldMetadata.create = create;
|
|
21
21
|
async function resolveType(meta) {
|
|
22
|
-
const typ = await (0,
|
|
22
|
+
const typ = await (0, orm_helper_js_1.resolveEntityMeta)(meta.type);
|
|
23
23
|
if (typ)
|
|
24
24
|
return typ;
|
|
25
25
|
throw new Error(`Can't resolve type of ${meta.entity.name}.${meta.name}`);
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
})(
|
|
27
|
+
EmbeddedFieldMetadata.resolveType = resolveType;
|
|
28
|
+
})(EmbeddedFieldMetadata = exports.EmbeddedFieldMetadata || (exports.EmbeddedFieldMetadata = {}));
|