@sqb/connect 4.1.4 → 4.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/FieldInfoMap.d.ts +2 -0
- package/dist/client/FieldInfoMap.js +22 -3
- package/dist/orm/base-entity.d.ts +1 -1
- package/dist/orm/base-entity.js +2 -2
- package/dist/orm/decorators/column.decorator.js +1 -1
- package/dist/orm/decorators/embedded.decorator.js +1 -1
- package/dist/orm/decorators/entity.decorator.js +7 -7
- package/dist/orm/decorators/events.decorator.js +6 -6
- package/dist/orm/decorators/foreignkey.decorator.js +1 -1
- package/dist/orm/decorators/index.decorator.js +2 -2
- package/dist/orm/decorators/link.decorator.js +1 -1
- package/dist/orm/decorators/primarykey.decorator.js +2 -2
- package/dist/orm/decorators/transform.decorator.js +2 -2
- package/dist/orm/model/entity-metadata.d.ts +1 -1
- package/dist/orm/model/entity-metadata.js +2 -2
- package/package.json +6 -5
|
@@ -2,9 +2,11 @@ import { FieldInfo } from './types';
|
|
|
2
2
|
export declare class FieldInfoMap {
|
|
3
3
|
private _obj;
|
|
4
4
|
private _arr;
|
|
5
|
+
constructor();
|
|
5
6
|
add(field: FieldInfo): void;
|
|
6
7
|
get(k: string | number): FieldInfo;
|
|
7
8
|
entries(): [string, FieldInfo][];
|
|
8
9
|
keys(): string[];
|
|
9
10
|
values(): FieldInfo[];
|
|
11
|
+
toJSON(): Record<string, FieldInfo>;
|
|
10
12
|
}
|
|
@@ -3,17 +3,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FieldInfoMap = void 0;
|
|
4
4
|
class FieldInfoMap {
|
|
5
5
|
constructor() {
|
|
6
|
-
this
|
|
7
|
-
|
|
6
|
+
Object.defineProperty(this, '_obj', {
|
|
7
|
+
enumerable: false,
|
|
8
|
+
configurable: false,
|
|
9
|
+
writable: true,
|
|
10
|
+
value: {}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(this, '_arr', {
|
|
13
|
+
enumerable: false,
|
|
14
|
+
configurable: false,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: []
|
|
17
|
+
});
|
|
8
18
|
}
|
|
9
19
|
add(field) {
|
|
10
20
|
const idx = field.index != null ? field.index : this._arr.length;
|
|
11
21
|
this._arr[idx] = field;
|
|
12
22
|
field.index = idx;
|
|
13
|
-
|
|
23
|
+
const _obj = this._arr.reduce((a, f) => {
|
|
14
24
|
a[f.name.toUpperCase()] = f;
|
|
15
25
|
return a;
|
|
16
26
|
}, {});
|
|
27
|
+
Object.defineProperty(this, '_obj', {
|
|
28
|
+
enumerable: false,
|
|
29
|
+
configurable: false,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: _obj
|
|
32
|
+
});
|
|
17
33
|
}
|
|
18
34
|
get(k) {
|
|
19
35
|
if (typeof k === 'number')
|
|
@@ -29,5 +45,8 @@ class FieldInfoMap {
|
|
|
29
45
|
values() {
|
|
30
46
|
return [...this._arr];
|
|
31
47
|
}
|
|
48
|
+
toJSON() {
|
|
49
|
+
return { ...this._obj };
|
|
50
|
+
}
|
|
32
51
|
}
|
|
33
52
|
exports.FieldInfoMap = FieldInfoMap;
|
package/dist/orm/base-entity.js
CHANGED
|
@@ -14,11 +14,11 @@ class BaseEntity {
|
|
|
14
14
|
}
|
|
15
15
|
async destroy() {
|
|
16
16
|
const repo = this[orm_const_1.REPOSITORY_KEY];
|
|
17
|
-
return repo.destroy(this);
|
|
17
|
+
return !!(repo && repo.destroy(this));
|
|
18
18
|
}
|
|
19
19
|
async exists() {
|
|
20
20
|
const repo = this[orm_const_1.REPOSITORY_KEY];
|
|
21
|
-
return repo.exists(this);
|
|
21
|
+
return !!(repo && repo.exists(this));
|
|
22
22
|
}
|
|
23
23
|
toJSON() {
|
|
24
24
|
// this method is an placeholder an will be overwritten by declareEntity() method
|
|
@@ -7,7 +7,7 @@ function Column(arg0) {
|
|
|
7
7
|
if (typeof propertyKey !== 'string')
|
|
8
8
|
throw new Error('Symbol properties are not accepted');
|
|
9
9
|
const options = (typeof arg0 === 'string' ? { dataType: arg0 } : arg0) || {};
|
|
10
|
-
const entity = entity_metadata_1.EntityMetadata.
|
|
10
|
+
const entity = entity_metadata_1.EntityMetadata.define(target.constructor);
|
|
11
11
|
if (!options.type) {
|
|
12
12
|
const typ = Reflect.getMetadata("design:type", entity.ctor.prototype, propertyKey);
|
|
13
13
|
if (typ === Array) {
|
|
@@ -9,7 +9,7 @@ function Embedded(type, options) {
|
|
|
9
9
|
type = type || Reflect.getMetadata("design:type", target, propertyKey);
|
|
10
10
|
if (typeof type !== 'function')
|
|
11
11
|
throw new Error('"type" must be defined');
|
|
12
|
-
const entity = entity_metadata_1.EntityMetadata.
|
|
12
|
+
const entity = entity_metadata_1.EntityMetadata.define(target.constructor);
|
|
13
13
|
entity_metadata_1.EntityMetadata.defineEmbeddedElement(entity, propertyKey, type, options);
|
|
14
14
|
};
|
|
15
15
|
}
|
|
@@ -7,7 +7,7 @@ function Entity(options) {
|
|
|
7
7
|
return function (target) {
|
|
8
8
|
const opts = typeof options === 'object' ? options : {};
|
|
9
9
|
const tableName = typeof options === 'string' ? options : opts.tableName;
|
|
10
|
-
const entity = entity_metadata_1.EntityMetadata.
|
|
10
|
+
const entity = entity_metadata_1.EntityMetadata.define(target);
|
|
11
11
|
entity.tableName = tableName || target.name;
|
|
12
12
|
if (opts.schema)
|
|
13
13
|
entity.schema = opts.schema;
|
|
@@ -85,12 +85,12 @@ exports.Entity = Entity;
|
|
|
85
85
|
}
|
|
86
86
|
Entity.getUpdateColumnNames = getUpdateColumnNames;
|
|
87
87
|
function getPrimaryIndex(ctor) {
|
|
88
|
-
const model = entity_metadata_1.EntityMetadata.
|
|
88
|
+
const model = entity_metadata_1.EntityMetadata.define(ctor);
|
|
89
89
|
return entity_metadata_1.EntityMetadata.getPrimaryIndex(model);
|
|
90
90
|
}
|
|
91
91
|
Entity.getPrimaryIndex = getPrimaryIndex;
|
|
92
92
|
function getPrimaryIndexColumns(ctor) {
|
|
93
|
-
const model = entity_metadata_1.EntityMetadata.
|
|
93
|
+
const model = entity_metadata_1.EntityMetadata.define(ctor);
|
|
94
94
|
return entity_metadata_1.EntityMetadata.getPrimaryIndexColumns(model);
|
|
95
95
|
}
|
|
96
96
|
Entity.getPrimaryIndexColumns = getPrimaryIndexColumns;
|
|
@@ -101,7 +101,7 @@ exports.Entity = Entity;
|
|
|
101
101
|
(0, apply_mixins_1.applyMixins)(derivedCtor, base);
|
|
102
102
|
const srcMeta = entity_metadata_1.EntityMetadata.get(base);
|
|
103
103
|
if (srcMeta) {
|
|
104
|
-
const trgMeta = entity_metadata_1.EntityMetadata.
|
|
104
|
+
const trgMeta = entity_metadata_1.EntityMetadata.define(derivedCtor);
|
|
105
105
|
entity_metadata_1.EntityMetadata.mixin(trgMeta, srcMeta);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
@@ -119,7 +119,7 @@ exports.Entity = Entity;
|
|
|
119
119
|
(0, apply_mixins_1.applyMixins)(PickEntityClass, classRef, filter);
|
|
120
120
|
const srcMeta = entity_metadata_1.EntityMetadata.get(classRef);
|
|
121
121
|
if (srcMeta) {
|
|
122
|
-
const trgMeta = entity_metadata_1.EntityMetadata.
|
|
122
|
+
const trgMeta = entity_metadata_1.EntityMetadata.define(PickEntityClass);
|
|
123
123
|
entity_metadata_1.EntityMetadata.mixin(trgMeta, srcMeta, filter);
|
|
124
124
|
}
|
|
125
125
|
return PickEntityClass;
|
|
@@ -136,7 +136,7 @@ exports.Entity = Entity;
|
|
|
136
136
|
(0, apply_mixins_1.applyMixins)(OmitEntityClass, classRef, filter);
|
|
137
137
|
const srcMeta = entity_metadata_1.EntityMetadata.get(classRef);
|
|
138
138
|
if (srcMeta) {
|
|
139
|
-
const trgMeta = entity_metadata_1.EntityMetadata.
|
|
139
|
+
const trgMeta = entity_metadata_1.EntityMetadata.define(OmitEntityClass);
|
|
140
140
|
entity_metadata_1.EntityMetadata.mixin(trgMeta, srcMeta, filter);
|
|
141
141
|
}
|
|
142
142
|
return OmitEntityClass;
|
|
@@ -153,7 +153,7 @@ exports.Entity = Entity;
|
|
|
153
153
|
(0, apply_mixins_1.applyMixins)(UnionClass, base);
|
|
154
154
|
const srcMeta = entity_metadata_1.EntityMetadata.get(base);
|
|
155
155
|
if (srcMeta) {
|
|
156
|
-
const trgMeta = entity_metadata_1.EntityMetadata.
|
|
156
|
+
const trgMeta = entity_metadata_1.EntityMetadata.define(UnionClass);
|
|
157
157
|
entity_metadata_1.EntityMetadata.mixin(trgMeta, srcMeta);
|
|
158
158
|
}
|
|
159
159
|
}
|
|
@@ -6,7 +6,7 @@ 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 = entity_metadata_1.EntityMetadata.
|
|
9
|
+
const model = entity_metadata_1.EntityMetadata.define(target.constructor);
|
|
10
10
|
const fn = target.constructor.prototype[propertyKey];
|
|
11
11
|
entity_metadata_1.EntityMetadata.addEventListener(model, 'before-insert', fn);
|
|
12
12
|
};
|
|
@@ -16,7 +16,7 @@ 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 = entity_metadata_1.EntityMetadata.
|
|
19
|
+
const model = entity_metadata_1.EntityMetadata.define(target.constructor);
|
|
20
20
|
const fn = target.constructor.prototype[propertyKey];
|
|
21
21
|
entity_metadata_1.EntityMetadata.addEventListener(model, 'before-update', fn);
|
|
22
22
|
};
|
|
@@ -26,7 +26,7 @@ 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 = entity_metadata_1.EntityMetadata.
|
|
29
|
+
const model = entity_metadata_1.EntityMetadata.define(target.constructor);
|
|
30
30
|
const fn = target.constructor.prototype[propertyKey];
|
|
31
31
|
entity_metadata_1.EntityMetadata.addEventListener(model, 'before-destroy', fn);
|
|
32
32
|
};
|
|
@@ -36,7 +36,7 @@ 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 = entity_metadata_1.EntityMetadata.
|
|
39
|
+
const model = entity_metadata_1.EntityMetadata.define(target.constructor);
|
|
40
40
|
const fn = target.constructor.prototype[propertyKey];
|
|
41
41
|
entity_metadata_1.EntityMetadata.addEventListener(model, 'after-insert', fn);
|
|
42
42
|
};
|
|
@@ -46,7 +46,7 @@ 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 = entity_metadata_1.EntityMetadata.
|
|
49
|
+
const model = entity_metadata_1.EntityMetadata.define(target.constructor);
|
|
50
50
|
const fn = target.constructor.prototype[propertyKey];
|
|
51
51
|
entity_metadata_1.EntityMetadata.addEventListener(model, 'after-update', fn);
|
|
52
52
|
};
|
|
@@ -56,7 +56,7 @@ 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 = entity_metadata_1.EntityMetadata.
|
|
59
|
+
const model = entity_metadata_1.EntityMetadata.define(target.constructor);
|
|
60
60
|
const fn = target.constructor.prototype[propertyKey];
|
|
61
61
|
entity_metadata_1.EntityMetadata.addEventListener(model, 'after-destroy', fn);
|
|
62
62
|
};
|
|
@@ -6,7 +6,7 @@ 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 = entity_metadata_1.EntityMetadata.
|
|
9
|
+
const entity = entity_metadata_1.EntityMetadata.define(target.constructor);
|
|
10
10
|
entity_metadata_1.EntityMetadata.addForeignKey(entity, propertyKey, type, targetKey);
|
|
11
11
|
};
|
|
12
12
|
}
|
|
@@ -7,14 +7,14 @@ function Index(arg0, arg1) {
|
|
|
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 = entity_metadata_1.EntityMetadata.
|
|
10
|
+
const model = entity_metadata_1.EntityMetadata.define(target);
|
|
11
11
|
return entity_metadata_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 = entity_metadata_1.EntityMetadata.
|
|
17
|
+
const model = entity_metadata_1.EntityMetadata.define(target.constructor);
|
|
18
18
|
entity_metadata_1.EntityMetadata.addIndex(model, { ...arg0, columns: [propertyKey] });
|
|
19
19
|
};
|
|
20
20
|
}
|
|
@@ -10,7 +10,7 @@ function Link(chain) {
|
|
|
10
10
|
if (chain.first.returnsMany() &&
|
|
11
11
|
Reflect.getMetadata("design:type", target, propertyKey) !== Array)
|
|
12
12
|
throw new Error(`Returning type of property (${propertyKey}) must be an array`);
|
|
13
|
-
const entity = entity_metadata_1.EntityMetadata.
|
|
13
|
+
const entity = entity_metadata_1.EntityMetadata.define(target.constructor);
|
|
14
14
|
// @ts-ignore
|
|
15
15
|
// noinspection JSConstantReassignment
|
|
16
16
|
chain.first.source = entity.ctor;
|
|
@@ -8,7 +8,7 @@ function PrimaryKey(arg0, arg1) {
|
|
|
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 = entity_metadata_1.EntityMetadata.
|
|
11
|
+
const meta = entity_metadata_1.EntityMetadata.define(target);
|
|
12
12
|
entity_metadata_1.EntityMetadata.setPrimaryKeys(meta, arg0, arg1);
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
@@ -16,7 +16,7 @@ function PrimaryKey(arg0, arg1) {
|
|
|
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 = entity_metadata_1.EntityMetadata.
|
|
19
|
+
const meta = entity_metadata_1.EntityMetadata.define(target.constructor);
|
|
20
20
|
(0, column_decorator_1.Column)({ notNull: true })(target, propertyKey);
|
|
21
21
|
entity_metadata_1.EntityMetadata.setPrimaryKeys(meta, propertyKey, arg0);
|
|
22
22
|
};
|
|
@@ -6,7 +6,7 @@ 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 = entity_metadata_1.EntityMetadata.
|
|
9
|
+
const entity = entity_metadata_1.EntityMetadata.define(target.constructor);
|
|
10
10
|
entity_metadata_1.EntityMetadata.defineColumnElement(entity, propertyKey)
|
|
11
11
|
.parse = fn;
|
|
12
12
|
};
|
|
@@ -16,7 +16,7 @@ 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 = entity_metadata_1.EntityMetadata.
|
|
19
|
+
const entity = entity_metadata_1.EntityMetadata.define(target.constructor);
|
|
20
20
|
entity_metadata_1.EntityMetadata.defineColumnElement(entity, propertyKey)
|
|
21
21
|
.serialize = fn;
|
|
22
22
|
};
|
|
@@ -20,7 +20,7 @@ export interface EntityMetadata {
|
|
|
20
20
|
eventListeners: Record<string, Function[]>;
|
|
21
21
|
}
|
|
22
22
|
export declare namespace EntityMetadata {
|
|
23
|
-
function
|
|
23
|
+
function define(ctor: Ctor): EntityMetadata;
|
|
24
24
|
function get(ctor: Ctor): Maybe<EntityMetadata>;
|
|
25
25
|
function getOwn(ctor: Ctor): Maybe<EntityMetadata>;
|
|
26
26
|
function getElement(entity: EntityMetadata, elementName: string): Maybe<AnyElementMetadata>;
|
|
@@ -11,7 +11,7 @@ const column_element_metadata_1 = require("./column-element-metadata");
|
|
|
11
11
|
const embedded_element_metadata_1 = require("./embedded-element-metadata");
|
|
12
12
|
var EntityMetadata;
|
|
13
13
|
(function (EntityMetadata) {
|
|
14
|
-
function
|
|
14
|
+
function define(ctor) {
|
|
15
15
|
const own = getOwn(ctor);
|
|
16
16
|
if (own)
|
|
17
17
|
return own;
|
|
@@ -48,7 +48,7 @@ var EntityMetadata;
|
|
|
48
48
|
};
|
|
49
49
|
return meta;
|
|
50
50
|
}
|
|
51
|
-
EntityMetadata.
|
|
51
|
+
EntityMetadata.define = define;
|
|
52
52
|
function get(ctor) {
|
|
53
53
|
return Reflect.getMetadata(orm_const_1.ENTITY_METADATA_KEY, ctor);
|
|
54
54
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqb/connect",
|
|
3
3
|
"description": "Multi-dialect database connection framework written with TypeScript",
|
|
4
|
-
"version": "4.1.
|
|
4
|
+
"version": "4.1.5",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Eray Hanoglu <e.hanoglu@panates.com>"
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"license": "Apache-2.0",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/sqbjs/sqb.git"
|
|
12
|
+
"url": "https://github.com/sqbjs/sqb.git",
|
|
13
|
+
"directory": "packages/connect"
|
|
13
14
|
},
|
|
14
15
|
"keywords": [
|
|
15
16
|
"javascript",
|
|
@@ -38,15 +39,15 @@
|
|
|
38
39
|
"putil-taskqueue": "^2.5.4",
|
|
39
40
|
"putil-varhelpers": "^1.6.4",
|
|
40
41
|
"reflect-metadata": "^0.1.13",
|
|
41
|
-
"strict-typed-events": "^2.
|
|
42
|
-
"ts-gems": "^1.
|
|
42
|
+
"strict-typed-events": "^2.2.0",
|
|
43
|
+
"ts-gems": "^2.1.0"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"@types/debug": "^4.1.7",
|
|
46
47
|
"@types/lodash": "^4.14.182"
|
|
47
48
|
},
|
|
48
49
|
"peerDependencies": {
|
|
49
|
-
"@sqb/builder": "^4.1.
|
|
50
|
+
"@sqb/builder": "^4.1.4"
|
|
50
51
|
},
|
|
51
52
|
"main": "dist/index.js",
|
|
52
53
|
"types": "dist/index.d.ts",
|