@sqb/connect 4.0.15 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/Adapter.d.ts +1 -1
- package/dist/client/Cursor.d.ts +2 -2
- package/dist/client/Cursor.js +3 -3
- package/dist/client/CursorStream.js +1 -1
- package/dist/client/SqbClient.d.ts +2 -2
- package/dist/client/SqbClient.js +5 -5
- package/dist/client/SqbConnection.d.ts +3 -3
- package/dist/client/SqbConnection.js +7 -7
- package/dist/client/helpers.d.ts +2 -2
- package/dist/client/types.d.ts +4 -4
- package/dist/index.d.ts +20 -15
- package/dist/index.js +21 -16
- package/dist/orm/backward.d.ts +8 -0
- package/dist/orm/backward.js +19 -0
- package/dist/orm/base-entity.d.ts +8 -0
- package/dist/orm/base-entity.js +28 -0
- package/dist/orm/commands/command.helper.d.ts +4 -4
- package/dist/orm/commands/command.helper.js +5 -3
- package/dist/orm/commands/count.command.d.ts +3 -3
- package/dist/orm/commands/create.command.d.ts +4 -4
- package/dist/orm/commands/create.command.js +13 -7
- package/dist/orm/commands/destroy.command.d.ts +3 -3
- package/dist/orm/commands/find.command.d.ts +9 -9
- package/dist/orm/commands/find.command.js +13 -11
- package/dist/orm/commands/row-converter.d.ts +4 -4
- package/dist/orm/commands/update.command.d.ts +5 -5
- package/dist/orm/commands/update.command.js +7 -5
- package/dist/orm/decorators/column.decorator.d.ts +2 -2
- package/dist/orm/decorators/column.decorator.js +13 -4
- package/dist/orm/decorators/embedded.decorator.d.ts +3 -2
- package/dist/orm/decorators/embedded.decorator.js +6 -7
- package/dist/orm/decorators/entity.decorator.d.ts +31 -4
- package/dist/orm/decorators/entity.decorator.js +147 -5
- package/dist/orm/decorators/events.decorator.js +13 -25
- package/dist/orm/decorators/foreignkey.decorator.js +3 -3
- package/dist/orm/decorators/index.decorator.d.ts +3 -3
- package/dist/orm/decorators/index.decorator.js +5 -6
- package/dist/orm/decorators/link.decorator.d.ts +1 -1
- package/dist/orm/decorators/link.decorator.js +3 -3
- package/dist/orm/decorators/primarykey.decorator.d.ts +3 -3
- package/dist/orm/decorators/primarykey.decorator.js +7 -6
- package/dist/orm/decorators/transform.decorator.js +5 -5
- package/dist/orm/model/association-element-metadata.d.ts +10 -0
- package/dist/orm/model/association-element-metadata.js +15 -0
- package/dist/orm/model/association.d.ts +6 -6
- package/dist/orm/model/association.js +9 -8
- package/dist/orm/model/{entity-column-element.d.ts → column-element-metadata.d.ts} +21 -10
- package/dist/orm/model/column-element-metadata.js +32 -0
- package/dist/orm/model/element-metadata.d.ts +7 -0
- package/dist/orm/model/element-metadata.js +2 -0
- package/dist/orm/model/embedded-element-metadata.d.ts +14 -0
- package/dist/orm/model/embedded-element-metadata.js +28 -0
- package/dist/orm/model/entity-metadata.d.ts +50 -0
- package/dist/orm/model/entity-metadata.js +341 -0
- package/dist/orm/model/index-metadata.d.ts +18 -0
- package/dist/orm/model/index-metadata.js +2 -0
- package/dist/orm/orm.const.d.ts +1 -1
- package/dist/orm/orm.const.js +3 -3
- package/dist/orm/orm.type.d.ts +1 -92
- package/dist/orm/repository.class.d.ts +5 -4
- package/dist/orm/repository.class.js +27 -5
- package/dist/orm/util/apply-mixins.d.ts +1 -0
- package/dist/orm/util/apply-mixins.js +12 -0
- package/dist/orm/util/extract-keyvalues.d.ts +2 -2
- package/dist/orm/util/extract-keyvalues.js +3 -2
- package/dist/orm/util/orm.helper.d.ts +8 -9
- package/dist/orm/util/orm.helper.js +8 -9
- package/dist/orm/util/serialize-element.d.ts +2 -2
- package/package.json +4 -4
- package/dist/orm/base-entity.class.d.ts +0 -16
- package/dist/orm/base-entity.class.js +0 -56
- package/dist/orm/model/abstract-entityelement.d.ts +0 -8
- package/dist/orm/model/abstract-entityelement.js +0 -10
- package/dist/orm/model/entity-association-element.d.ts +0 -9
- package/dist/orm/model/entity-association-element.js +0 -13
- package/dist/orm/model/entity-column-element.js +0 -27
- package/dist/orm/model/entity-model.d.ts +0 -59
- package/dist/orm/model/entity-model.js +0 -295
- package/dist/orm/model/entity-object-element.d.ts +0 -12
- package/dist/orm/model/entity-object-element.js +0 -24
- package/dist/orm/model/index-meta.d.ts +0 -9
- package/dist/orm/model/index-meta.js +0 -16
- package/dist/orm/util/entity-mapping.d.ts +0 -12
- package/dist/orm/util/entity-mapping.js +0 -154
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { EntityModel } from '../model/entity-model';
|
|
2
|
-
import { Repository } from '../repository.class';
|
|
3
1
|
import { SqbConnection } from '../../client/SqbConnection';
|
|
2
|
+
import { EntityMetadata } from '../model/entity-metadata';
|
|
3
|
+
import { Repository } from '../repository.class';
|
|
4
4
|
export declare type UpdateCommandArgs = {
|
|
5
|
-
entity:
|
|
5
|
+
entity: EntityMetadata;
|
|
6
6
|
connection: SqbConnection;
|
|
7
7
|
values: any;
|
|
8
8
|
} & Repository.UpdateAllOptions;
|
|
9
9
|
declare type UpdateCommandContext = {
|
|
10
|
-
entity:
|
|
10
|
+
entity: EntityMetadata;
|
|
11
11
|
queryParams: any;
|
|
12
12
|
queryValues: any;
|
|
13
13
|
queryFilter: any[];
|
|
@@ -17,6 +17,6 @@ export declare class UpdateCommand {
|
|
|
17
17
|
protected constructor();
|
|
18
18
|
static execute(args: UpdateCommandArgs): Promise<number>;
|
|
19
19
|
protected static _prepareFilter(ctx: UpdateCommandContext, filter: any): Promise<void>;
|
|
20
|
-
protected static _prepareParams(ctx: UpdateCommandContext, entity:
|
|
20
|
+
protected static _prepareParams(ctx: UpdateCommandContext, entity: EntityMetadata, values: any, prefix?: string, suffix?: string): Promise<void>;
|
|
21
21
|
}
|
|
22
22
|
export {};
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UpdateCommand = void 0;
|
|
4
4
|
const builder_1 = require("@sqb/builder");
|
|
5
|
-
const
|
|
5
|
+
const column_element_metadata_1 = require("../model/column-element-metadata");
|
|
6
|
+
const embedded_element_metadata_1 = require("../model/embedded-element-metadata");
|
|
6
7
|
const orm_helper_1 = require("../util/orm.helper");
|
|
8
|
+
const command_helper_1 = require("./command.helper");
|
|
7
9
|
class UpdateCommand {
|
|
8
10
|
// istanbul ignore next
|
|
9
11
|
constructor() {
|
|
@@ -48,7 +50,7 @@ class UpdateCommand {
|
|
|
48
50
|
let v;
|
|
49
51
|
prefix = prefix || '';
|
|
50
52
|
suffix = suffix || '';
|
|
51
|
-
for (const col of entity.elements
|
|
53
|
+
for (const col of Object.values(entity.elements)) {
|
|
52
54
|
v = values[col.name];
|
|
53
55
|
if (v === undefined)
|
|
54
56
|
continue;
|
|
@@ -61,7 +63,7 @@ class UpdateCommand {
|
|
|
61
63
|
throw new Error(`${entity.name}.${col.name} is required and can't be null`);
|
|
62
64
|
if (v === undefined)
|
|
63
65
|
continue;
|
|
64
|
-
|
|
66
|
+
column_element_metadata_1.ColumnElementMetadata.checkEnumValue(col, v);
|
|
65
67
|
const fieldName = prefix + col.fieldName + suffix;
|
|
66
68
|
const k = '$input_' + fieldName;
|
|
67
69
|
ctx.queryValues[fieldName] = (0, builder_1.Param)({
|
|
@@ -72,8 +74,8 @@ class UpdateCommand {
|
|
|
72
74
|
ctx.queryParams[k] = v;
|
|
73
75
|
ctx.colCount++;
|
|
74
76
|
}
|
|
75
|
-
else if (v != null && (0, orm_helper_1.
|
|
76
|
-
const type = await
|
|
77
|
+
else if (v != null && (0, orm_helper_1.isEmbeddedElement)(col)) {
|
|
78
|
+
const type = await embedded_element_metadata_1.EmbeddedElementMetadata.resolveType(col);
|
|
77
79
|
await this._prepareParams(ctx, type, v, col.fieldNamePrefix, col.fieldNameSuffix);
|
|
78
80
|
}
|
|
79
81
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { DataType } from '@sqb/builder';
|
|
2
|
-
import {
|
|
2
|
+
import { ColumnElementOptions } from '../model/column-element-metadata';
|
|
3
3
|
export declare function Column(type?: DataType): PropertyDecorator;
|
|
4
|
-
export declare function Column(options?:
|
|
4
|
+
export declare function Column(options?: ColumnElementOptions): PropertyDecorator;
|
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Column = void 0;
|
|
4
|
-
const
|
|
4
|
+
const entity_metadata_1 = require("../model/entity-metadata");
|
|
5
5
|
function Column(arg0) {
|
|
6
6
|
return (target, propertyKey) => {
|
|
7
7
|
if (typeof propertyKey !== 'string')
|
|
8
8
|
throw new Error('Symbol properties are not accepted');
|
|
9
|
-
const options = typeof arg0 === 'string' ? { dataType: arg0 } : arg0;
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const options = (typeof arg0 === 'string' ? { dataType: arg0 } : arg0) || {};
|
|
10
|
+
const entity = entity_metadata_1.EntityMetadata.inject(target.constructor);
|
|
11
|
+
if (!options.type) {
|
|
12
|
+
const typ = Reflect.getMetadata("design:type", entity.ctor.prototype, propertyKey);
|
|
13
|
+
if (typ === Array) {
|
|
14
|
+
options.type = String;
|
|
15
|
+
options.isArray = true;
|
|
16
|
+
}
|
|
17
|
+
else
|
|
18
|
+
options.type = typ;
|
|
19
|
+
}
|
|
20
|
+
entity_metadata_1.EntityMetadata.defineColumnElement(entity, propertyKey, options);
|
|
12
21
|
};
|
|
13
22
|
}
|
|
14
23
|
exports.Column = Column;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { EmbeddedElementOptions } from '../model/embedded-element-metadata';
|
|
2
|
+
import { TypeThunk } from '../orm.type';
|
|
3
|
+
export declare function Embedded(type?: TypeThunk, options?: EmbeddedElementOptions): PropertyDecorator;
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Embedded = void 0;
|
|
4
|
-
const
|
|
4
|
+
const entity_metadata_1 = require("../model/entity-metadata");
|
|
5
5
|
function Embedded(type, options) {
|
|
6
6
|
return (target, propertyKey) => {
|
|
7
7
|
if (typeof propertyKey !== 'string')
|
|
8
8
|
throw new Error('Symbol properties are not accepted');
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
el.fieldNameSuffix = options.fieldNameSuffix;
|
|
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_1.EntityMetadata.inject(target.constructor);
|
|
13
|
+
entity_metadata_1.EntityMetadata.defineEmbeddedElement(entity, propertyKey, type, options);
|
|
15
14
|
};
|
|
16
15
|
}
|
|
17
16
|
exports.Embedded = Embedded;
|
|
@@ -1,6 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { Maybe, Type } from 'ts-gems';
|
|
2
|
+
import { AssociationElementMetadata } from '../model/association-element-metadata';
|
|
3
|
+
import { ColumnElementMetadata } from '../model/column-element-metadata';
|
|
4
|
+
import { EmbeddedElementMetadata } from '../model/embedded-element-metadata';
|
|
5
|
+
import { AnyElementMetadata, EntityMetadata, EntityOptions } from '../model/entity-metadata';
|
|
6
|
+
import { IndexMetadata } from '../model/index-metadata';
|
|
7
|
+
export declare function Entity(options?: EntityOptions | string): ClassDecorator;
|
|
4
8
|
export declare namespace Entity {
|
|
5
|
-
|
|
9
|
+
const getMetadata: typeof EntityMetadata.get;
|
|
10
|
+
const getOwnMetadata: typeof EntityMetadata.getOwn;
|
|
11
|
+
function getElement<T>(ctor: Type<T>, key: keyof T | string): Maybe<AnyElementMetadata>;
|
|
12
|
+
function getColumnElement<T>(ctor: Type<T>, key: keyof T | string): Maybe<ColumnElementMetadata>;
|
|
13
|
+
function getEmbeddedElement<T>(ctor: Type<T>, key: keyof T | string): Maybe<EmbeddedElementMetadata>;
|
|
14
|
+
function getAssociationElement<T>(ctor: Type<T>, key: keyof T | string): Maybe<AssociationElementMetadata>;
|
|
15
|
+
function getColumnElementByFieldName(ctor: Type, fieldName: string): Maybe<ColumnElementMetadata>;
|
|
16
|
+
function find(ctor: Type, predicate: (el: AnyElementMetadata) => boolean): Maybe<AnyElementMetadata>;
|
|
17
|
+
function getElementNames(ctor: Type, filter?: (el: AnyElementMetadata) => boolean): string[];
|
|
18
|
+
function getColumnNames(ctor: Type): string[];
|
|
19
|
+
function getEmbeddedElementNames(ctor: Type): string[];
|
|
20
|
+
function getAssociationElementNames(ctor: Type): string[];
|
|
21
|
+
function getNonAssociationElementNames(ctor: Type): string[];
|
|
22
|
+
function getInsertColumnNames(ctor: Type): string[];
|
|
23
|
+
function getUpdateColumnNames(ctor: Type): string[];
|
|
24
|
+
function getPrimaryIndex(ctor: Type): Maybe<IndexMetadata>;
|
|
25
|
+
function getPrimaryIndexColumns(ctor: Type): ColumnElementMetadata[];
|
|
26
|
+
function Pick<T, K extends keyof T>(classRef: Type<T>, keys: readonly K[]): Type<Pick<T, typeof keys[number]>>;
|
|
27
|
+
function Omit<T, K extends keyof T>(classRef: Type<T>, keys: readonly K[]): Type<Omit<T, typeof keys[number]>>;
|
|
28
|
+
function Union<A, B>(baseA: Type<A>, baseB: Type<B>): Type<A & B>;
|
|
29
|
+
function Union<A, B, C>(baseA: Type<A>, baseB: Type<B>, baseC: Type<C>): Type<A & B & C>;
|
|
30
|
+
function Union<A, B, C, D>(baseA: Type<A>, baseB: Type<B>, baseC: Type<C>, baseD: Type<D>): Type<A & B & C & D>;
|
|
31
|
+
function Union<A, B, C, D, E>(baseA: Type<A>, baseB: Type<B>, baseC: Type<C>, baseD: Type<D>, baseE: Type<E>): Type<A & B & C & D & E>;
|
|
32
|
+
function Union<A, B, C, D, E, F>(baseA: Type<A>, baseB: Type<B>, baseC: Type<C>, baseD: Type<D>, baseE: Type<E>, baseF: Type<F>): Type<A & B & C & D & E & F>;
|
|
6
33
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Entity = void 0;
|
|
4
|
-
const
|
|
4
|
+
const entity_metadata_1 = require("../model/entity-metadata");
|
|
5
|
+
const apply_mixins_1 = require("../util/apply-mixins");
|
|
5
6
|
function Entity(options) {
|
|
6
7
|
return function (target) {
|
|
7
8
|
const opts = typeof options === 'object' ? options : {};
|
|
8
9
|
const tableName = typeof options === 'string' ? options : opts.tableName;
|
|
9
|
-
const entity =
|
|
10
|
+
const entity = entity_metadata_1.EntityMetadata.inject(target);
|
|
10
11
|
entity.tableName = tableName || target.name;
|
|
11
12
|
if (opts.schema)
|
|
12
13
|
entity.schema = opts.schema;
|
|
@@ -16,8 +17,149 @@ function Entity(options) {
|
|
|
16
17
|
}
|
|
17
18
|
exports.Entity = Entity;
|
|
18
19
|
(function (Entity) {
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
Entity.getMetadata = entity_metadata_1.EntityMetadata.get;
|
|
21
|
+
Entity.getOwnMetadata = entity_metadata_1.EntityMetadata.getOwn;
|
|
22
|
+
function getElement(ctor, key) {
|
|
23
|
+
const model = entity_metadata_1.EntityMetadata.get(ctor);
|
|
24
|
+
return model && entity_metadata_1.EntityMetadata.getElement(model, key);
|
|
21
25
|
}
|
|
22
|
-
Entity.
|
|
26
|
+
Entity.getElement = getElement;
|
|
27
|
+
function getColumnElement(ctor, key) {
|
|
28
|
+
const model = entity_metadata_1.EntityMetadata.get(ctor);
|
|
29
|
+
return model && entity_metadata_1.EntityMetadata.getColumnElement(model, key);
|
|
30
|
+
}
|
|
31
|
+
Entity.getColumnElement = getColumnElement;
|
|
32
|
+
function getEmbeddedElement(ctor, key) {
|
|
33
|
+
const model = entity_metadata_1.EntityMetadata.get(ctor);
|
|
34
|
+
return model && entity_metadata_1.EntityMetadata.getEmbeddedElement(model, key);
|
|
35
|
+
}
|
|
36
|
+
Entity.getEmbeddedElement = getEmbeddedElement;
|
|
37
|
+
function getAssociationElement(ctor, key) {
|
|
38
|
+
const model = entity_metadata_1.EntityMetadata.get(ctor);
|
|
39
|
+
return model && entity_metadata_1.EntityMetadata.getAssociationElement(model, key);
|
|
40
|
+
}
|
|
41
|
+
Entity.getAssociationElement = getAssociationElement;
|
|
42
|
+
function getColumnElementByFieldName(ctor, fieldName) {
|
|
43
|
+
const model = entity_metadata_1.EntityMetadata.get(ctor);
|
|
44
|
+
return model && entity_metadata_1.EntityMetadata.getColumnElementByFieldName(model, fieldName);
|
|
45
|
+
}
|
|
46
|
+
Entity.getColumnElementByFieldName = getColumnElementByFieldName;
|
|
47
|
+
function find(ctor, predicate) {
|
|
48
|
+
const model = entity_metadata_1.EntityMetadata.get(ctor);
|
|
49
|
+
return model && entity_metadata_1.EntityMetadata.findElement(model, predicate);
|
|
50
|
+
}
|
|
51
|
+
Entity.find = find;
|
|
52
|
+
function getElementNames(ctor, filter) {
|
|
53
|
+
const model = entity_metadata_1.EntityMetadata.get(ctor);
|
|
54
|
+
return (model && entity_metadata_1.EntityMetadata.getElementNames(model, filter)) || [];
|
|
55
|
+
}
|
|
56
|
+
Entity.getElementNames = getElementNames;
|
|
57
|
+
function getColumnNames(ctor) {
|
|
58
|
+
const model = entity_metadata_1.EntityMetadata.get(ctor);
|
|
59
|
+
return (model && entity_metadata_1.EntityMetadata.getColumnNames(model)) || [];
|
|
60
|
+
}
|
|
61
|
+
Entity.getColumnNames = getColumnNames;
|
|
62
|
+
function getEmbeddedElementNames(ctor) {
|
|
63
|
+
const model = entity_metadata_1.EntityMetadata.get(ctor);
|
|
64
|
+
return (model && entity_metadata_1.EntityMetadata.getEmbeddedElementNames(model)) || [];
|
|
65
|
+
}
|
|
66
|
+
Entity.getEmbeddedElementNames = getEmbeddedElementNames;
|
|
67
|
+
function getAssociationElementNames(ctor) {
|
|
68
|
+
const model = entity_metadata_1.EntityMetadata.get(ctor);
|
|
69
|
+
return (model && entity_metadata_1.EntityMetadata.getAssociationElementNames(model)) || [];
|
|
70
|
+
}
|
|
71
|
+
Entity.getAssociationElementNames = getAssociationElementNames;
|
|
72
|
+
function getNonAssociationElementNames(ctor) {
|
|
73
|
+
const model = entity_metadata_1.EntityMetadata.get(ctor);
|
|
74
|
+
return (model && entity_metadata_1.EntityMetadata.getNonAssociationElementNames(model)) || [];
|
|
75
|
+
}
|
|
76
|
+
Entity.getNonAssociationElementNames = getNonAssociationElementNames;
|
|
77
|
+
function getInsertColumnNames(ctor) {
|
|
78
|
+
const model = entity_metadata_1.EntityMetadata.get(ctor);
|
|
79
|
+
return (model && entity_metadata_1.EntityMetadata.getInsertColumnNames(model)) || [];
|
|
80
|
+
}
|
|
81
|
+
Entity.getInsertColumnNames = getInsertColumnNames;
|
|
82
|
+
function getUpdateColumnNames(ctor) {
|
|
83
|
+
const model = entity_metadata_1.EntityMetadata.get(ctor);
|
|
84
|
+
return (model && entity_metadata_1.EntityMetadata.getUpdateColumnNames(model)) || [];
|
|
85
|
+
}
|
|
86
|
+
Entity.getUpdateColumnNames = getUpdateColumnNames;
|
|
87
|
+
function getPrimaryIndex(ctor) {
|
|
88
|
+
const model = entity_metadata_1.EntityMetadata.inject(ctor);
|
|
89
|
+
return entity_metadata_1.EntityMetadata.getPrimaryIndex(model);
|
|
90
|
+
}
|
|
91
|
+
Entity.getPrimaryIndex = getPrimaryIndex;
|
|
92
|
+
function getPrimaryIndexColumns(ctor) {
|
|
93
|
+
const model = entity_metadata_1.EntityMetadata.inject(ctor);
|
|
94
|
+
return entity_metadata_1.EntityMetadata.getPrimaryIndexColumns(model);
|
|
95
|
+
}
|
|
96
|
+
Entity.getPrimaryIndexColumns = getPrimaryIndexColumns;
|
|
97
|
+
function Pick(classRef, keys) {
|
|
98
|
+
const PickEntityClass = class {
|
|
99
|
+
constructor(...args) {
|
|
100
|
+
applyConstructorProperties(this, classRef, args);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
const pickKeys = keys.map(x => x.toLowerCase());
|
|
104
|
+
const filter = (k) => pickKeys.includes(k.toLowerCase());
|
|
105
|
+
(0, apply_mixins_1.applyMixins)(PickEntityClass, classRef, filter);
|
|
106
|
+
const srcMeta = entity_metadata_1.EntityMetadata.get(classRef);
|
|
107
|
+
if (srcMeta) {
|
|
108
|
+
const trgMeta = entity_metadata_1.EntityMetadata.inject(PickEntityClass);
|
|
109
|
+
entity_metadata_1.EntityMetadata.mixin(trgMeta, srcMeta, filter);
|
|
110
|
+
}
|
|
111
|
+
return PickEntityClass;
|
|
112
|
+
}
|
|
113
|
+
Entity.Pick = Pick;
|
|
114
|
+
function Omit(classRef, keys) {
|
|
115
|
+
const OmitEntityClass = class {
|
|
116
|
+
constructor(...args) {
|
|
117
|
+
applyConstructorProperties(this, classRef, args);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const omitKeys = keys.map(x => x.toLowerCase());
|
|
121
|
+
const filter = (k) => !omitKeys.includes(k.toLowerCase());
|
|
122
|
+
(0, apply_mixins_1.applyMixins)(OmitEntityClass, classRef, filter);
|
|
123
|
+
const srcMeta = entity_metadata_1.EntityMetadata.get(classRef);
|
|
124
|
+
if (srcMeta) {
|
|
125
|
+
const trgMeta = entity_metadata_1.EntityMetadata.inject(OmitEntityClass);
|
|
126
|
+
entity_metadata_1.EntityMetadata.mixin(trgMeta, srcMeta, filter);
|
|
127
|
+
}
|
|
128
|
+
return OmitEntityClass;
|
|
129
|
+
}
|
|
130
|
+
Entity.Omit = Omit;
|
|
131
|
+
function Union(...bases) {
|
|
132
|
+
const UnionClass = class {
|
|
133
|
+
constructor(...args) {
|
|
134
|
+
for (const c of bases)
|
|
135
|
+
applyConstructorProperties(this, c, args);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
for (const base of bases) {
|
|
139
|
+
(0, apply_mixins_1.applyMixins)(UnionClass, base);
|
|
140
|
+
const srcMeta = entity_metadata_1.EntityMetadata.get(base);
|
|
141
|
+
if (srcMeta) {
|
|
142
|
+
const trgMeta = entity_metadata_1.EntityMetadata.inject(UnionClass);
|
|
143
|
+
entity_metadata_1.EntityMetadata.mixin(trgMeta, srcMeta);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return UnionClass;
|
|
147
|
+
}
|
|
148
|
+
Entity.Union = Union;
|
|
23
149
|
})(Entity = exports.Entity || (exports.Entity = {}));
|
|
150
|
+
function applyConstructorProperties(target, sourceClass, constructorArgs, isPropertyInherited) {
|
|
151
|
+
try {
|
|
152
|
+
const tempInstance = new sourceClass(...constructorArgs);
|
|
153
|
+
const keys = Object.getOwnPropertyNames(tempInstance);
|
|
154
|
+
for (const key of keys) {
|
|
155
|
+
const srcDesc = Object.getOwnPropertyDescriptor(tempInstance, key);
|
|
156
|
+
const trgDesc = Object.getOwnPropertyDescriptor(target, key);
|
|
157
|
+
if (!srcDesc || trgDesc || (isPropertyInherited && !isPropertyInherited(key)))
|
|
158
|
+
continue;
|
|
159
|
+
Object.defineProperty(target, key, srcDesc);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
//
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -1,16 +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_1 = require("../model/entity-metadata");
|
|
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
|
|
9
|
+
const model = entity_metadata_1.EntityMetadata.inject(target.constructor);
|
|
10
10
|
const fn = target.constructor.prototype[propertyKey];
|
|
11
|
-
|
|
12
|
-
throw new Error('Property must be a function');
|
|
13
|
-
entity.before('insert', fn);
|
|
11
|
+
entity_metadata_1.EntityMetadata.addEventListener(model, 'before-insert', fn);
|
|
14
12
|
};
|
|
15
13
|
}
|
|
16
14
|
exports.BeforeInsert = BeforeInsert;
|
|
@@ -18,11 +16,9 @@ function BeforeUpdate() {
|
|
|
18
16
|
return (target, propertyKey) => {
|
|
19
17
|
if (typeof propertyKey !== 'string')
|
|
20
18
|
throw new Error('You can define a Column for only string properties');
|
|
21
|
-
const
|
|
19
|
+
const model = entity_metadata_1.EntityMetadata.inject(target.constructor);
|
|
22
20
|
const fn = target.constructor.prototype[propertyKey];
|
|
23
|
-
|
|
24
|
-
throw new Error('Property must be a function');
|
|
25
|
-
entity.before('update', fn);
|
|
21
|
+
entity_metadata_1.EntityMetadata.addEventListener(model, 'before-update', fn);
|
|
26
22
|
};
|
|
27
23
|
}
|
|
28
24
|
exports.BeforeUpdate = BeforeUpdate;
|
|
@@ -30,11 +26,9 @@ function BeforeDestroy() {
|
|
|
30
26
|
return (target, propertyKey) => {
|
|
31
27
|
if (typeof propertyKey !== 'string')
|
|
32
28
|
throw new Error('You can define a Column for only string properties');
|
|
33
|
-
const
|
|
29
|
+
const model = entity_metadata_1.EntityMetadata.inject(target.constructor);
|
|
34
30
|
const fn = target.constructor.prototype[propertyKey];
|
|
35
|
-
|
|
36
|
-
throw new Error('Property must be a function');
|
|
37
|
-
entity.before('destroy', fn);
|
|
31
|
+
entity_metadata_1.EntityMetadata.addEventListener(model, 'before-destroy', fn);
|
|
38
32
|
};
|
|
39
33
|
}
|
|
40
34
|
exports.BeforeDestroy = BeforeDestroy;
|
|
@@ -42,11 +36,9 @@ function AfterInsert() {
|
|
|
42
36
|
return (target, propertyKey) => {
|
|
43
37
|
if (typeof propertyKey !== 'string')
|
|
44
38
|
throw new Error('You can define a Column for only string properties');
|
|
45
|
-
const
|
|
39
|
+
const model = entity_metadata_1.EntityMetadata.inject(target.constructor);
|
|
46
40
|
const fn = target.constructor.prototype[propertyKey];
|
|
47
|
-
|
|
48
|
-
throw new Error('Property must be a function');
|
|
49
|
-
entity.after('insert', fn);
|
|
41
|
+
entity_metadata_1.EntityMetadata.addEventListener(model, 'after-insert', fn);
|
|
50
42
|
};
|
|
51
43
|
}
|
|
52
44
|
exports.AfterInsert = AfterInsert;
|
|
@@ -54,11 +46,9 @@ function AfterUpdate() {
|
|
|
54
46
|
return (target, propertyKey) => {
|
|
55
47
|
if (typeof propertyKey !== 'string')
|
|
56
48
|
throw new Error('You can define a Column for only string properties');
|
|
57
|
-
const
|
|
49
|
+
const model = entity_metadata_1.EntityMetadata.inject(target.constructor);
|
|
58
50
|
const fn = target.constructor.prototype[propertyKey];
|
|
59
|
-
|
|
60
|
-
throw new Error('Property must be a function');
|
|
61
|
-
entity.after('update', fn);
|
|
51
|
+
entity_metadata_1.EntityMetadata.addEventListener(model, 'after-update', fn);
|
|
62
52
|
};
|
|
63
53
|
}
|
|
64
54
|
exports.AfterUpdate = AfterUpdate;
|
|
@@ -66,11 +56,9 @@ function AfterDestroy() {
|
|
|
66
56
|
return (target, propertyKey) => {
|
|
67
57
|
if (typeof propertyKey !== 'string')
|
|
68
58
|
throw new Error('You can define a Column for only string properties');
|
|
69
|
-
const
|
|
59
|
+
const model = entity_metadata_1.EntityMetadata.inject(target.constructor);
|
|
70
60
|
const fn = target.constructor.prototype[propertyKey];
|
|
71
|
-
|
|
72
|
-
throw new Error('Property must be a function');
|
|
73
|
-
entity.after('destroy', fn);
|
|
61
|
+
entity_metadata_1.EntityMetadata.addEventListener(model, 'after-destroy', fn);
|
|
74
62
|
};
|
|
75
63
|
}
|
|
76
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_1 = require("../model/entity-metadata");
|
|
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
|
-
|
|
10
|
-
|
|
9
|
+
const entity = entity_metadata_1.EntityMetadata.inject(target.constructor);
|
|
10
|
+
entity_metadata_1.EntityMetadata.addForeignKey(entity, propertyKey, type, targetKey);
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
exports.ForeignKey = ForeignKey;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function Index(fields: string | string[], options?:
|
|
3
|
-
export declare function Index(options?:
|
|
1
|
+
import { IndexMetadata } from '../model/index-metadata';
|
|
2
|
+
export declare function Index(fields: string | string[], options?: Omit<IndexMetadata, 'columns'>): ClassDecorator;
|
|
3
|
+
export declare function Index(options?: Omit<IndexMetadata, 'columns'>): PropertyDecorator;
|
|
@@ -1,22 +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_1 = require("../model/entity-metadata");
|
|
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
|
|
11
|
-
|
|
12
|
-
return;
|
|
10
|
+
const model = entity_metadata_1.EntityMetadata.inject(target);
|
|
11
|
+
return entity_metadata_1.EntityMetadata.addIndex(model, { ...arg1, columns: arg0 });
|
|
13
12
|
}
|
|
14
13
|
if (!target.constructor)
|
|
15
14
|
throw new Error('Property decorators can be used for class properties only');
|
|
16
15
|
if (typeof propertyKey !== 'string')
|
|
17
16
|
throw new Error('Index() decorator can be used for string property keys only');
|
|
18
|
-
const
|
|
19
|
-
|
|
17
|
+
const model = entity_metadata_1.EntityMetadata.inject(target.constructor);
|
|
18
|
+
entity_metadata_1.EntityMetadata.addIndex(model, { ...arg0, columns: [propertyKey] });
|
|
20
19
|
};
|
|
21
20
|
}
|
|
22
21
|
exports.Index = Index;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TypeThunk } from '../orm.type';
|
|
2
1
|
import { LinkChain } from '../model/link-chain';
|
|
2
|
+
import { TypeThunk } from '../orm.type';
|
|
3
3
|
export declare function Link(chain: LinkChain<any>): PropertyDecorator;
|
|
4
4
|
export declare function LinkToOne(type?: TypeThunk, targetKey?: string, sourceKey?: string): PropertyDecorator;
|
|
5
5
|
export declare function LinkToMany(type: TypeThunk, targetKey?: string, sourceKey?: string): PropertyDecorator;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.linkFromMany = exports.linkFromOne = exports.linkToMany = exports.linkToOne = exports.LinkFromMany = exports.LinkFromOne = exports.LinkToMany = exports.LinkToOne = exports.Link = void 0;
|
|
4
|
-
const
|
|
4
|
+
const entity_metadata_1 = require("../model/entity-metadata");
|
|
5
5
|
const link_chain_1 = require("../model/link-chain");
|
|
6
6
|
function Link(chain) {
|
|
7
7
|
return (target, propertyKey) => {
|
|
@@ -10,11 +10,11 @@ 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 =
|
|
13
|
+
const entity = entity_metadata_1.EntityMetadata.inject(target.constructor);
|
|
14
14
|
// @ts-ignore
|
|
15
15
|
// noinspection JSConstantReassignment
|
|
16
16
|
chain.first.source = entity.ctor;
|
|
17
|
-
|
|
17
|
+
entity_metadata_1.EntityMetadata.defineAssociationElement(entity, propertyKey, chain.first);
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
exports.Link = Link;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function PrimaryKey(fields: string | string[], options?:
|
|
3
|
-
export declare function PrimaryKey(options?:
|
|
1
|
+
import { IndexMetadata } from '../model/index-metadata';
|
|
2
|
+
export declare function PrimaryKey(fields: string | string[], options?: Omit<IndexMetadata, 'columns' | 'unique' | 'primary'>): ClassDecorator;
|
|
3
|
+
export declare function PrimaryKey(options?: Omit<IndexMetadata, 'columns' | 'unique' | 'primary'>): PropertyDecorator;
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PrimaryKey = void 0;
|
|
4
|
-
const
|
|
4
|
+
const entity_metadata_1 = require("../model/entity-metadata");
|
|
5
|
+
const column_decorator_1 = require("./column.decorator");
|
|
5
6
|
function PrimaryKey(arg0, arg1) {
|
|
6
7
|
return function (target, propertyKey) {
|
|
7
8
|
if (arguments.length === 1) {
|
|
8
9
|
if (!(typeof arg0 === 'string' || Array.isArray(arg0)))
|
|
9
10
|
throw new Error(`You must specify primary index column(s)`);
|
|
10
|
-
const
|
|
11
|
-
|
|
11
|
+
const meta = entity_metadata_1.EntityMetadata.inject(target);
|
|
12
|
+
entity_metadata_1.EntityMetadata.setPrimaryKeys(meta, arg0, arg1);
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
14
15
|
if (!target.constructor)
|
|
15
16
|
throw new Error('Property decorators can be used for class properties only');
|
|
16
17
|
if (typeof propertyKey !== 'string')
|
|
17
18
|
throw new Error('Index() decorator can be used for string property keys only');
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const meta = entity_metadata_1.EntityMetadata.inject(target.constructor);
|
|
20
|
+
(0, column_decorator_1.Column)({ notNull: true })(target, propertyKey);
|
|
21
|
+
entity_metadata_1.EntityMetadata.setPrimaryKeys(meta, propertyKey, arg0);
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
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_1 = require("../model/entity-metadata");
|
|
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
|
-
|
|
10
|
-
|
|
9
|
+
const entity = entity_metadata_1.EntityMetadata.inject(target.constructor);
|
|
10
|
+
entity_metadata_1.EntityMetadata.defineColumnElement(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
|
-
|
|
20
|
-
|
|
19
|
+
const entity = entity_metadata_1.EntityMetadata.inject(target.constructor);
|
|
20
|
+
entity_metadata_1.EntityMetadata.defineColumnElement(entity, propertyKey)
|
|
21
21
|
.serialize = fn;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AssociationNode } from './association-node';
|
|
2
|
+
import { ElementMetadata } from './element-metadata';
|
|
3
|
+
import type { EntityMetadata } from './entity-metadata';
|
|
4
|
+
export interface AssociationElementMetadata extends ElementMetadata {
|
|
5
|
+
readonly kind: 'association';
|
|
6
|
+
readonly association: AssociationNode;
|
|
7
|
+
}
|
|
8
|
+
export declare namespace AssociationElementMetadata {
|
|
9
|
+
function create(entity: EntityMetadata, name: string, association: AssociationNode): AssociationElementMetadata;
|
|
10
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AssociationElementMetadata = void 0;
|
|
4
|
+
var AssociationElementMetadata;
|
|
5
|
+
(function (AssociationElementMetadata) {
|
|
6
|
+
function create(entity, name, association) {
|
|
7
|
+
return {
|
|
8
|
+
kind: 'association',
|
|
9
|
+
entity,
|
|
10
|
+
name,
|
|
11
|
+
association
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
AssociationElementMetadata.create = create;
|
|
15
|
+
})(AssociationElementMetadata = exports.AssociationElementMetadata || (exports.AssociationElementMetadata = {}));
|