@sqb/connect 4.0.7 → 4.0.10
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/package.json +6 -7
- package/dist/client/Adapter.d.ts +0 -57
- package/dist/client/Adapter.js +0 -2
- package/dist/client/Cursor.d.ts +0 -116
- package/dist/client/Cursor.js +0 -250
- package/dist/client/CursorStream.d.ts +0 -29
- package/dist/client/CursorStream.js +0 -98
- package/dist/client/FieldInfoMap.d.ts +0 -10
- package/dist/client/FieldInfoMap.js +0 -33
- package/dist/client/SqbClient.d.ts +0 -70
- package/dist/client/SqbClient.js +0 -165
- package/dist/client/SqbConnection.d.ts +0 -74
- package/dist/client/SqbConnection.js +0 -272
- package/dist/client/extensions.d.ts +0 -4
- package/dist/client/extensions.js +0 -14
- package/dist/client/helpers.d.ts +0 -9
- package/dist/client/helpers.js +0 -133
- package/dist/client/types.d.ts +0 -189
- package/dist/client/types.js +0 -5
- package/dist/index.d.ts +0 -28
- package/dist/index.js +0 -37
- package/dist/orm/base-entity.class.d.ts +0 -16
- package/dist/orm/base-entity.class.js +0 -56
- package/dist/orm/commands/command.helper.d.ts +0 -14
- package/dist/orm/commands/command.helper.js +0 -140
- package/dist/orm/commands/count.command.d.ts +0 -11
- package/dist/orm/commands/count.command.js +0 -30
- package/dist/orm/commands/create.command.d.ts +0 -20
- package/dist/orm/commands/create.command.js +0 -83
- package/dist/orm/commands/destroy.command.d.ts +0 -11
- package/dist/orm/commands/destroy.command.js +0 -30
- package/dist/orm/commands/find.command.d.ts +0 -44
- package/dist/orm/commands/find.command.js +0 -308
- package/dist/orm/commands/row-converter.d.ts +0 -55
- package/dist/orm/commands/row-converter.js +0 -187
- package/dist/orm/commands/update.command.d.ts +0 -22
- package/dist/orm/commands/update.command.js +0 -82
- package/dist/orm/decorators/column.decorator.d.ts +0 -4
- package/dist/orm/decorators/column.decorator.js +0 -14
- package/dist/orm/decorators/embedded.decorator.d.ts +0 -2
- package/dist/orm/decorators/embedded.decorator.js +0 -17
- package/dist/orm/decorators/entity.decorator.d.ts +0 -6
- package/dist/orm/decorators/entity.decorator.js +0 -23
- package/dist/orm/decorators/events.decorator.d.ts +0 -6
- package/dist/orm/decorators/events.decorator.js +0 -76
- package/dist/orm/decorators/foreignkey.decorator.d.ts +0 -2
- package/dist/orm/decorators/foreignkey.decorator.js +0 -13
- package/dist/orm/decorators/index.decorator.d.ts +0 -3
- package/dist/orm/decorators/index.decorator.js +0 -22
- package/dist/orm/decorators/link.decorator.d.ts +0 -23
- package/dist/orm/decorators/link.decorator.js +0 -88
- package/dist/orm/decorators/primarykey.decorator.d.ts +0 -3
- package/dist/orm/decorators/primarykey.decorator.js +0 -23
- package/dist/orm/decorators/transform.decorator.d.ts +0 -3
- package/dist/orm/decorators/transform.decorator.js +0 -24
- package/dist/orm/model/abstract-entityelement.d.ts +0 -8
- package/dist/orm/model/abstract-entityelement.js +0 -10
- package/dist/orm/model/association-node.d.ts +0 -9
- package/dist/orm/model/association-node.js +0 -25
- package/dist/orm/model/association.d.ts +0 -28
- package/dist/orm/model/association.js +0 -129
- 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.d.ts +0 -68
- 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/model/link-chain.d.ts +0 -15
- package/dist/orm/model/link-chain.js +0 -50
- package/dist/orm/orm.const.d.ts +0 -2
- package/dist/orm/orm.const.js +0 -5
- package/dist/orm/orm.type.d.ts +0 -112
- package/dist/orm/orm.type.js +0 -2
- package/dist/orm/repository.class.d.ts +0 -125
- package/dist/orm/repository.class.js +0 -217
- package/dist/orm/util/entity-mapping.d.ts +0 -12
- package/dist/orm/util/entity-mapping.js +0 -154
- package/dist/orm/util/extract-keyvalues.d.ts +0 -2
- package/dist/orm/util/extract-keyvalues.js +0 -60
- package/dist/orm/util/orm.helper.d.ts +0 -14
- package/dist/orm/util/orm.helper.js +0 -39
- package/dist/orm/util/serialize-element.d.ts +0 -2
- package/dist/orm/util/serialize-element.js +0 -43
- package/dist/types.d.ts +0 -2
- package/dist/types.js +0 -2
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RowConverter = void 0;
|
|
4
|
-
const builder_1 = require("@sqb/builder");
|
|
5
|
-
const isValueProperty = (prop) => {
|
|
6
|
-
return prop.fieldAlias && !prop.converter;
|
|
7
|
-
};
|
|
8
|
-
const isObjectProperty = (prop) => {
|
|
9
|
-
return prop.converter && !prop.findCommand;
|
|
10
|
-
};
|
|
11
|
-
const isNestedProperty = (prop) => {
|
|
12
|
-
return prop.converter && prop.findCommand;
|
|
13
|
-
};
|
|
14
|
-
class RowConverter {
|
|
15
|
-
constructor(resultType, parent) {
|
|
16
|
-
this.resultType = resultType;
|
|
17
|
-
this.parent = parent;
|
|
18
|
-
this._properties = {};
|
|
19
|
-
}
|
|
20
|
-
addValueProperty(args) {
|
|
21
|
-
this._propertyKeys = undefined;
|
|
22
|
-
const item = {
|
|
23
|
-
fieldAlias: args.fieldAlias,
|
|
24
|
-
dataType: args.dataType,
|
|
25
|
-
parse: args.parse
|
|
26
|
-
};
|
|
27
|
-
this._properties[args.name] = item;
|
|
28
|
-
return item;
|
|
29
|
-
}
|
|
30
|
-
addObjectProperty(args) {
|
|
31
|
-
this._checkCircularDep(args.type);
|
|
32
|
-
this._propertyKeys = undefined;
|
|
33
|
-
const converter = new RowConverter(args.type, this);
|
|
34
|
-
const item = {
|
|
35
|
-
converter,
|
|
36
|
-
type: args.type
|
|
37
|
-
};
|
|
38
|
-
this._properties[args.name] = item;
|
|
39
|
-
return item;
|
|
40
|
-
}
|
|
41
|
-
addNestedProperty(args) {
|
|
42
|
-
this._checkCircularDep(args.type);
|
|
43
|
-
const converter = new RowConverter(args.type, this);
|
|
44
|
-
const item = {
|
|
45
|
-
converter,
|
|
46
|
-
type: args.type,
|
|
47
|
-
parentField: args.parentField,
|
|
48
|
-
keyField: args.keyField,
|
|
49
|
-
findCommand: args.findCommand,
|
|
50
|
-
sort: args.sort,
|
|
51
|
-
paramValues: []
|
|
52
|
-
};
|
|
53
|
-
this._properties[args.name] = item;
|
|
54
|
-
return item;
|
|
55
|
-
}
|
|
56
|
-
get keys() {
|
|
57
|
-
if (!this._propertyKeys)
|
|
58
|
-
this._propertyKeys = Object.keys(this._properties);
|
|
59
|
-
return this._propertyKeys;
|
|
60
|
-
}
|
|
61
|
-
async transform(connection, fields, rows, onTransform) {
|
|
62
|
-
const rowLen = rows.length;
|
|
63
|
-
const result = [];
|
|
64
|
-
for (let rowIdx = 0; rowIdx < rowLen; rowIdx++) {
|
|
65
|
-
const row = rows[rowIdx];
|
|
66
|
-
const o = (await this._rowToObject(connection, fields, row)) || {};
|
|
67
|
-
if (onTransform)
|
|
68
|
-
onTransform(fields, row, o);
|
|
69
|
-
result.push(o);
|
|
70
|
-
}
|
|
71
|
-
if (!this.keys)
|
|
72
|
-
return result;
|
|
73
|
-
await this._iterateForNested(this, connection, fields, rows, result);
|
|
74
|
-
// Return only non empty objects
|
|
75
|
-
return result.filter(x => !!x);
|
|
76
|
-
}
|
|
77
|
-
_rowToObject(executor, fields, row) {
|
|
78
|
-
// Cache keys for better performance
|
|
79
|
-
const elementKeys = this.keys;
|
|
80
|
-
const elementLen = elementKeys.length;
|
|
81
|
-
let result;
|
|
82
|
-
for (let elIdx = 0; elIdx < elementLen; elIdx++) {
|
|
83
|
-
const elKey = elementKeys[elIdx];
|
|
84
|
-
const prop = this._properties[elKey];
|
|
85
|
-
if (isValueProperty(prop)) {
|
|
86
|
-
const field = fields.get(prop.fieldAlias);
|
|
87
|
-
if (field) {
|
|
88
|
-
let v = row[field.index];
|
|
89
|
-
if (typeof prop.parse === 'function')
|
|
90
|
-
v = prop.parse(v, elKey);
|
|
91
|
-
if (v != null) {
|
|
92
|
-
result = result || {};
|
|
93
|
-
if (prop.dataType === builder_1.DataType.JSON && typeof v === 'string')
|
|
94
|
-
v = JSON.parse(v);
|
|
95
|
-
result[elKey] = v;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
else if (isNestedProperty(prop)) {
|
|
100
|
-
// One2Many Eager element
|
|
101
|
-
// Keep a list of key field/value pairs to fetch rows for eager relation
|
|
102
|
-
const _params = prop.paramValues;
|
|
103
|
-
const f = fields.get(prop.parentField);
|
|
104
|
-
const v = f && row[f.index];
|
|
105
|
-
if (v != null && !_params.includes(v))
|
|
106
|
-
_params.push(v);
|
|
107
|
-
}
|
|
108
|
-
else if (isObjectProperty(prop)) {
|
|
109
|
-
const v = prop.converter._rowToObject(executor, fields, row);
|
|
110
|
-
if (v != null) {
|
|
111
|
-
result = result || {};
|
|
112
|
-
result[elKey] = v;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
if (result)
|
|
117
|
-
Object.setPrototypeOf(result, this.resultType.prototype);
|
|
118
|
-
return result;
|
|
119
|
-
}
|
|
120
|
-
async _iterateForNested(node, connection, fields, rows, result) {
|
|
121
|
-
// Fetch one-2-many related rows and merge with result rows
|
|
122
|
-
const keys = node.keys;
|
|
123
|
-
const propertyLen = keys.length;
|
|
124
|
-
const promises = [];
|
|
125
|
-
for (let propIdx = 0; propIdx < propertyLen; propIdx++) {
|
|
126
|
-
const propKey = keys[propIdx];
|
|
127
|
-
const prop = node._properties[propKey];
|
|
128
|
-
if (isNestedProperty(prop)) {
|
|
129
|
-
if (!(prop.paramValues && prop.paramValues.length))
|
|
130
|
-
continue;
|
|
131
|
-
const resultType = this.resultType;
|
|
132
|
-
const promise = async function (p) {
|
|
133
|
-
const findCommand = p.findCommand;
|
|
134
|
-
let fld;
|
|
135
|
-
const map = new Map();
|
|
136
|
-
const r = await findCommand.execute({
|
|
137
|
-
connection,
|
|
138
|
-
limit: findCommand.maxEagerFetch + 1,
|
|
139
|
-
params: { [p.parentField]: p.paramValues },
|
|
140
|
-
onTransformRow: (_fields, row, obj) => {
|
|
141
|
-
fld = fld || _fields.get('' + p.keyField);
|
|
142
|
-
const keyValue = fld && row[fld.index];
|
|
143
|
-
if (keyValue != null) {
|
|
144
|
-
let arr = map.get(keyValue);
|
|
145
|
-
if (!arr) {
|
|
146
|
-
arr = [];
|
|
147
|
-
map.set(keyValue, arr);
|
|
148
|
-
}
|
|
149
|
-
arr.push(obj);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
if (r.length > findCommand.maxEagerFetch)
|
|
154
|
-
throw new Error(`Number of returning rows for "${propKey}" exceeds maxEagerFetch limit`);
|
|
155
|
-
for (let i = 0; i < result.length; i++) {
|
|
156
|
-
const row = rows[i];
|
|
157
|
-
let obj = result[i];
|
|
158
|
-
if (!obj) {
|
|
159
|
-
obj = {};
|
|
160
|
-
Object.setPrototypeOf(result, resultType.prototype);
|
|
161
|
-
}
|
|
162
|
-
const f = fields.get('' + p.parentField);
|
|
163
|
-
const keyValue = f && row[f.index];
|
|
164
|
-
if (keyValue != null) {
|
|
165
|
-
const arr = map.get(keyValue);
|
|
166
|
-
if (arr) {
|
|
167
|
-
obj[propKey] = arr;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}(prop);
|
|
172
|
-
promises.push(promise);
|
|
173
|
-
}
|
|
174
|
-
else if (isObjectProperty(prop)) {
|
|
175
|
-
promises.push(this._iterateForNested(prop.converter, connection, fields, rows, result));
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
await Promise.all(promises);
|
|
179
|
-
}
|
|
180
|
-
_checkCircularDep(t) {
|
|
181
|
-
if (this.resultType === t)
|
|
182
|
-
throw new Error('Circular elements requested');
|
|
183
|
-
if (this.parent)
|
|
184
|
-
this.parent._checkCircularDep(t);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
exports.RowConverter = RowConverter;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { EntityModel } from '../model/entity-model';
|
|
2
|
-
import { Repository } from '../repository.class';
|
|
3
|
-
import { SqbConnection } from '../../client/SqbConnection';
|
|
4
|
-
export declare type UpdateCommandArgs = {
|
|
5
|
-
entity: EntityModel;
|
|
6
|
-
connection: SqbConnection;
|
|
7
|
-
values: any;
|
|
8
|
-
} & Repository.UpdateAllOptions;
|
|
9
|
-
declare type UpdateCommandContext = {
|
|
10
|
-
entity: EntityModel;
|
|
11
|
-
queryParams: any;
|
|
12
|
-
queryValues: any;
|
|
13
|
-
queryFilter: any[];
|
|
14
|
-
colCount: number;
|
|
15
|
-
};
|
|
16
|
-
export declare class UpdateCommand {
|
|
17
|
-
protected constructor();
|
|
18
|
-
static execute(args: UpdateCommandArgs): Promise<number>;
|
|
19
|
-
protected static _prepareFilter(ctx: UpdateCommandContext, filter: any): Promise<void>;
|
|
20
|
-
protected static _prepareParams(ctx: UpdateCommandContext, entity: EntityModel, values: any, prefix?: string, suffix?: string): Promise<void>;
|
|
21
|
-
}
|
|
22
|
-
export {};
|
|
@@ -1,82 +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 command_helper_1 = require("./command.helper");
|
|
6
|
-
const orm_helper_1 = require("../util/orm.helper");
|
|
7
|
-
class UpdateCommand {
|
|
8
|
-
// istanbul ignore next
|
|
9
|
-
constructor() {
|
|
10
|
-
throw new Error('This class is abstract');
|
|
11
|
-
}
|
|
12
|
-
static async execute(args) {
|
|
13
|
-
const { entity } = args;
|
|
14
|
-
const tableName = entity.tableName;
|
|
15
|
-
if (!tableName)
|
|
16
|
-
throw new Error(`${entity.ctor.name} is not decorated with @Entity decorator`);
|
|
17
|
-
// Create a context
|
|
18
|
-
const ctx = {
|
|
19
|
-
entity,
|
|
20
|
-
queryParams: {},
|
|
21
|
-
queryValues: {},
|
|
22
|
-
queryFilter: [],
|
|
23
|
-
colCount: 0,
|
|
24
|
-
};
|
|
25
|
-
// Prepare
|
|
26
|
-
await this._prepareParams(ctx, entity, args.values);
|
|
27
|
-
if (!ctx.colCount)
|
|
28
|
-
return 0;
|
|
29
|
-
if (args.filter)
|
|
30
|
-
await this._prepareFilter(ctx, args.filter);
|
|
31
|
-
const query = (0, builder_1.Update)(tableName + ' as T', ctx.queryValues)
|
|
32
|
-
.where(...ctx.queryFilter);
|
|
33
|
-
const qr = await args.connection.execute(query, {
|
|
34
|
-
params: args.params ? [...args.params, ctx.queryParams] : ctx.queryParams,
|
|
35
|
-
objectRows: false,
|
|
36
|
-
cursor: false
|
|
37
|
-
});
|
|
38
|
-
return qr.rowsAffected || 0;
|
|
39
|
-
}
|
|
40
|
-
static async _prepareFilter(ctx, filter) {
|
|
41
|
-
if (filter) {
|
|
42
|
-
const where = (0, builder_1.And)();
|
|
43
|
-
await (0, command_helper_1.prepareFilter)(ctx.entity, filter, where);
|
|
44
|
-
ctx.queryFilter.push(...where._items);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
static async _prepareParams(ctx, entity, values, prefix, suffix) {
|
|
48
|
-
let v;
|
|
49
|
-
prefix = prefix || '';
|
|
50
|
-
suffix = suffix || '';
|
|
51
|
-
for (const col of entity.elements.values()) {
|
|
52
|
-
v = values[col.name];
|
|
53
|
-
if (v === undefined)
|
|
54
|
-
continue;
|
|
55
|
-
if ((0, orm_helper_1.isColumnElement)(col)) {
|
|
56
|
-
if (col.noUpdate)
|
|
57
|
-
continue;
|
|
58
|
-
if (typeof col.serialize === 'function')
|
|
59
|
-
v = col.serialize(v, col.name);
|
|
60
|
-
if (v === null && col.notNull)
|
|
61
|
-
throw new Error(`${entity.name}.${col.name} is required and can't be null`);
|
|
62
|
-
if (v === undefined)
|
|
63
|
-
continue;
|
|
64
|
-
col.checkEnumValue(v);
|
|
65
|
-
const fieldName = prefix + col.fieldName + suffix;
|
|
66
|
-
const k = '$input_' + fieldName;
|
|
67
|
-
ctx.queryValues[fieldName] = (0, builder_1.Param)({
|
|
68
|
-
name: k,
|
|
69
|
-
dataType: col.dataType,
|
|
70
|
-
isArray: col.isArray
|
|
71
|
-
});
|
|
72
|
-
ctx.queryParams[k] = v;
|
|
73
|
-
ctx.colCount++;
|
|
74
|
-
}
|
|
75
|
-
else if (v != null && (0, orm_helper_1.isObjectElement)(col)) {
|
|
76
|
-
const type = await col.resolveType();
|
|
77
|
-
await this._prepareParams(ctx, type, v, col.fieldNamePrefix, col.fieldNameSuffix);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
exports.UpdateCommand = UpdateCommand;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Column = void 0;
|
|
4
|
-
const entity_model_1 = require("../model/entity-model");
|
|
5
|
-
function Column(arg0) {
|
|
6
|
-
return (target, propertyKey) => {
|
|
7
|
-
if (typeof propertyKey !== 'string')
|
|
8
|
-
throw new Error('Symbol properties are not accepted');
|
|
9
|
-
const options = typeof arg0 === 'string' ? { dataType: arg0 } : arg0;
|
|
10
|
-
entity_model_1.EntityModel.attachTo(target.constructor)
|
|
11
|
-
.defineColumnElement(propertyKey, options);
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
exports.Column = Column;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Embedded = void 0;
|
|
4
|
-
const entity_model_1 = require("../model/entity-model");
|
|
5
|
-
function Embedded(type, options) {
|
|
6
|
-
return (target, propertyKey) => {
|
|
7
|
-
if (typeof propertyKey !== 'string')
|
|
8
|
-
throw new Error('Symbol properties are not accepted');
|
|
9
|
-
const el = entity_model_1.EntityModel.attachTo(target.constructor)
|
|
10
|
-
.defineObjectElement(propertyKey, type);
|
|
11
|
-
if (options?.fieldNamePrefix)
|
|
12
|
-
el.fieldNamePrefix = options.fieldNamePrefix;
|
|
13
|
-
if (options?.fieldNameSuffix)
|
|
14
|
-
el.fieldNameSuffix = options.fieldNameSuffix;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
exports.Embedded = Embedded;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { EntityModel } from '../model/entity-model';
|
|
2
|
-
import { EntityConfig } from '../orm.type';
|
|
3
|
-
export declare function Entity(options?: EntityConfig | string): ClassDecorator;
|
|
4
|
-
export declare namespace Entity {
|
|
5
|
-
function getMetadata(ctor: Function): EntityModel | undefined;
|
|
6
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Entity = void 0;
|
|
4
|
-
const entity_model_1 = require("../model/entity-model");
|
|
5
|
-
function Entity(options) {
|
|
6
|
-
return function (target) {
|
|
7
|
-
const opts = typeof options === 'object' ? options : {};
|
|
8
|
-
const tableName = typeof options === 'string' ? options : opts.tableName;
|
|
9
|
-
const entity = entity_model_1.EntityModel.attachTo(target);
|
|
10
|
-
entity.tableName = tableName || target.name;
|
|
11
|
-
if (opts.schema)
|
|
12
|
-
entity.schema = opts.schema;
|
|
13
|
-
if (opts.comment)
|
|
14
|
-
entity.comment = opts.comment;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
exports.Entity = Entity;
|
|
18
|
-
(function (Entity) {
|
|
19
|
-
function getMetadata(ctor) {
|
|
20
|
-
return entity_model_1.EntityModel.get(ctor);
|
|
21
|
-
}
|
|
22
|
-
Entity.getMetadata = getMetadata;
|
|
23
|
-
})(Entity = exports.Entity || (exports.Entity = {}));
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare function BeforeInsert(): PropertyDecorator;
|
|
2
|
-
export declare function BeforeUpdate(): PropertyDecorator;
|
|
3
|
-
export declare function BeforeDestroy(): PropertyDecorator;
|
|
4
|
-
export declare function AfterInsert(): PropertyDecorator;
|
|
5
|
-
export declare function AfterUpdate(): PropertyDecorator;
|
|
6
|
-
export declare function AfterDestroy(): PropertyDecorator;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AfterDestroy = exports.AfterUpdate = exports.AfterInsert = exports.BeforeDestroy = exports.BeforeUpdate = exports.BeforeInsert = void 0;
|
|
4
|
-
const entity_model_1 = require("../model/entity-model");
|
|
5
|
-
function BeforeInsert() {
|
|
6
|
-
return (target, propertyKey) => {
|
|
7
|
-
if (typeof propertyKey !== 'string')
|
|
8
|
-
throw new Error('You can define a Column for only string properties');
|
|
9
|
-
const entity = entity_model_1.EntityModel.attachTo(target.constructor);
|
|
10
|
-
const fn = target.constructor.prototype[propertyKey];
|
|
11
|
-
if (typeof fn !== 'function')
|
|
12
|
-
throw new Error('Property must be a function');
|
|
13
|
-
entity.before('insert', fn);
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
exports.BeforeInsert = BeforeInsert;
|
|
17
|
-
function BeforeUpdate() {
|
|
18
|
-
return (target, propertyKey) => {
|
|
19
|
-
if (typeof propertyKey !== 'string')
|
|
20
|
-
throw new Error('You can define a Column for only string properties');
|
|
21
|
-
const entity = entity_model_1.EntityModel.attachTo(target.constructor);
|
|
22
|
-
const fn = target.constructor.prototype[propertyKey];
|
|
23
|
-
if (typeof fn !== 'function')
|
|
24
|
-
throw new Error('Property must be a function');
|
|
25
|
-
entity.before('update', fn);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
exports.BeforeUpdate = BeforeUpdate;
|
|
29
|
-
function BeforeDestroy() {
|
|
30
|
-
return (target, propertyKey) => {
|
|
31
|
-
if (typeof propertyKey !== 'string')
|
|
32
|
-
throw new Error('You can define a Column for only string properties');
|
|
33
|
-
const entity = entity_model_1.EntityModel.attachTo(target.constructor);
|
|
34
|
-
const fn = target.constructor.prototype[propertyKey];
|
|
35
|
-
if (typeof fn !== 'function')
|
|
36
|
-
throw new Error('Property must be a function');
|
|
37
|
-
entity.before('destroy', fn);
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
exports.BeforeDestroy = BeforeDestroy;
|
|
41
|
-
function AfterInsert() {
|
|
42
|
-
return (target, propertyKey) => {
|
|
43
|
-
if (typeof propertyKey !== 'string')
|
|
44
|
-
throw new Error('You can define a Column for only string properties');
|
|
45
|
-
const entity = entity_model_1.EntityModel.attachTo(target.constructor);
|
|
46
|
-
const fn = target.constructor.prototype[propertyKey];
|
|
47
|
-
if (typeof fn !== 'function')
|
|
48
|
-
throw new Error('Property must be a function');
|
|
49
|
-
entity.after('insert', fn);
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
exports.AfterInsert = AfterInsert;
|
|
53
|
-
function AfterUpdate() {
|
|
54
|
-
return (target, propertyKey) => {
|
|
55
|
-
if (typeof propertyKey !== 'string')
|
|
56
|
-
throw new Error('You can define a Column for only string properties');
|
|
57
|
-
const entity = entity_model_1.EntityModel.attachTo(target.constructor);
|
|
58
|
-
const fn = target.constructor.prototype[propertyKey];
|
|
59
|
-
if (typeof fn !== 'function')
|
|
60
|
-
throw new Error('Property must be a function');
|
|
61
|
-
entity.after('update', fn);
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
exports.AfterUpdate = AfterUpdate;
|
|
65
|
-
function AfterDestroy() {
|
|
66
|
-
return (target, propertyKey) => {
|
|
67
|
-
if (typeof propertyKey !== 'string')
|
|
68
|
-
throw new Error('You can define a Column for only string properties');
|
|
69
|
-
const entity = entity_model_1.EntityModel.attachTo(target.constructor);
|
|
70
|
-
const fn = target.constructor.prototype[propertyKey];
|
|
71
|
-
if (typeof fn !== 'function')
|
|
72
|
-
throw new Error('Property must be a function');
|
|
73
|
-
entity.after('destroy', fn);
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
exports.AfterDestroy = AfterDestroy;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ForeignKey = void 0;
|
|
4
|
-
const entity_model_1 = require("../model/entity-model");
|
|
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
|
-
entity_model_1.EntityModel.attachTo(target.constructor)
|
|
10
|
-
.addForeignKey(propertyKey, type, targetKey);
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
exports.ForeignKey = ForeignKey;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Index = void 0;
|
|
4
|
-
const entity_model_1 = require("../model/entity-model");
|
|
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 entity = entity_model_1.EntityModel.attachTo(target);
|
|
11
|
-
entity.addIndex(arg0, arg1);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
if (!target.constructor)
|
|
15
|
-
throw new Error('Property decorators can be used for class properties only');
|
|
16
|
-
if (typeof propertyKey !== 'string')
|
|
17
|
-
throw new Error('Index() decorator can be used for string property keys only');
|
|
18
|
-
const entity = entity_model_1.EntityModel.attachTo(target.constructor);
|
|
19
|
-
entity.addIndex(propertyKey, arg0);
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
exports.Index = Index;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { TypeThunk } from '../orm.type';
|
|
2
|
-
import { LinkChain } from '../model/link-chain';
|
|
3
|
-
export declare function Link(chain: LinkChain<any>): PropertyDecorator;
|
|
4
|
-
export declare function LinkToOne(type?: TypeThunk, targetKey?: string, sourceKey?: string): PropertyDecorator;
|
|
5
|
-
export declare function LinkToMany(type: TypeThunk, targetKey?: string, sourceKey?: string): PropertyDecorator;
|
|
6
|
-
export declare function LinkFromOne(type?: TypeThunk, targetKey?: string, sourceKey?: string): PropertyDecorator;
|
|
7
|
-
export declare function LinkFromMany(type?: TypeThunk, targetKey?: string, sourceKey?: string): PropertyDecorator;
|
|
8
|
-
/**
|
|
9
|
-
* Crates an Link Chain object
|
|
10
|
-
*/
|
|
11
|
-
export declare function linkToOne<T>(type: TypeThunk<T>, targetKey?: keyof T, sourceKey?: string): LinkChain<T>;
|
|
12
|
-
/**
|
|
13
|
-
* Crates an Link Chain object
|
|
14
|
-
*/
|
|
15
|
-
export declare function linkToMany<T>(type: TypeThunk<T>, targetKey?: keyof T, sourceKey?: string): LinkChain<T>;
|
|
16
|
-
/**
|
|
17
|
-
* Crates an Link Chain object
|
|
18
|
-
*/
|
|
19
|
-
export declare function linkFromOne<T>(type: TypeThunk<T>, targetKey?: keyof T, sourceKey?: string): LinkChain<T>;
|
|
20
|
-
/**
|
|
21
|
-
* Crates an Link Chain object
|
|
22
|
-
*/
|
|
23
|
-
export declare function linkFromMany<T>(type: TypeThunk<T>, targetKey?: keyof T, sourceKey?: string): LinkChain<T>;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.linkFromMany = exports.linkFromOne = exports.linkToMany = exports.linkToOne = exports.LinkFromMany = exports.LinkFromOne = exports.LinkToMany = exports.LinkToOne = exports.Link = void 0;
|
|
4
|
-
const entity_model_1 = require("../model/entity-model");
|
|
5
|
-
const link_chain_1 = require("../model/link-chain");
|
|
6
|
-
function Link(chain) {
|
|
7
|
-
return (target, propertyKey) => {
|
|
8
|
-
if (typeof propertyKey !== 'string')
|
|
9
|
-
throw new Error('You can define a column for only string properties');
|
|
10
|
-
if (chain.first.returnsMany() &&
|
|
11
|
-
Reflect.getMetadata("design:type", target, propertyKey) !== Array)
|
|
12
|
-
throw new Error(`Returning type of property (${propertyKey}) must be an array`);
|
|
13
|
-
const entity = entity_model_1.EntityModel.attachTo(target.constructor);
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
// noinspection JSConstantReassignment
|
|
16
|
-
chain.first.source = entity.ctor;
|
|
17
|
-
entity.defineAssociationElement(propertyKey, chain.first);
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
exports.Link = Link;
|
|
21
|
-
function LinkToOne(type, targetKey, sourceKey) {
|
|
22
|
-
return (target, propertyKey) => {
|
|
23
|
-
type = type || Reflect.getMetadata("design:type", target, propertyKey);
|
|
24
|
-
if (!type || type === Array)
|
|
25
|
-
throw new Error('You must provide "type"');
|
|
26
|
-
const chain = linkToOne(type, targetKey, sourceKey);
|
|
27
|
-
Link(chain)(target, propertyKey);
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
exports.LinkToOne = LinkToOne;
|
|
31
|
-
function LinkToMany(type, targetKey, sourceKey) {
|
|
32
|
-
return (target, propertyKey) => {
|
|
33
|
-
type = type || Reflect.getMetadata("design:type", target, propertyKey);
|
|
34
|
-
if (!type || type === Array)
|
|
35
|
-
throw new Error('You must provide "type"');
|
|
36
|
-
const chain = linkToMany(type, targetKey, sourceKey);
|
|
37
|
-
Link(chain)(target, propertyKey);
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
exports.LinkToMany = LinkToMany;
|
|
41
|
-
function LinkFromOne(type, targetKey, sourceKey) {
|
|
42
|
-
return (target, propertyKey) => {
|
|
43
|
-
type = type || Reflect.getMetadata("design:type", target, propertyKey);
|
|
44
|
-
if (!type || type === Array)
|
|
45
|
-
throw new Error('You must provide "type"');
|
|
46
|
-
const chain = linkFromOne(type, targetKey, sourceKey);
|
|
47
|
-
Link(chain)(target, propertyKey);
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
exports.LinkFromOne = LinkFromOne;
|
|
51
|
-
function LinkFromMany(type, targetKey, sourceKey) {
|
|
52
|
-
return (target, propertyKey) => {
|
|
53
|
-
type = type || Reflect.getMetadata("design:type", target, propertyKey);
|
|
54
|
-
if (!type || type === Array)
|
|
55
|
-
throw new Error('You must provide "type"');
|
|
56
|
-
const chain = linkFromMany(type, targetKey, sourceKey);
|
|
57
|
-
Link(chain)(target, propertyKey);
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
exports.LinkFromMany = LinkFromMany;
|
|
61
|
-
/**
|
|
62
|
-
* Crates an Link Chain object
|
|
63
|
-
*/
|
|
64
|
-
function linkToOne(type, targetKey, sourceKey) {
|
|
65
|
-
return new link_chain_1.LinkChain(type, 'to', targetKey, sourceKey);
|
|
66
|
-
}
|
|
67
|
-
exports.linkToOne = linkToOne;
|
|
68
|
-
/**
|
|
69
|
-
* Crates an Link Chain object
|
|
70
|
-
*/
|
|
71
|
-
function linkToMany(type, targetKey, sourceKey) {
|
|
72
|
-
return new link_chain_1.LinkChain(type, 'to-many', targetKey, sourceKey);
|
|
73
|
-
}
|
|
74
|
-
exports.linkToMany = linkToMany;
|
|
75
|
-
/**
|
|
76
|
-
* Crates an Link Chain object
|
|
77
|
-
*/
|
|
78
|
-
function linkFromOne(type, targetKey, sourceKey) {
|
|
79
|
-
return new link_chain_1.LinkChain(type, 'from', targetKey, sourceKey);
|
|
80
|
-
}
|
|
81
|
-
exports.linkFromOne = linkFromOne;
|
|
82
|
-
/**
|
|
83
|
-
* Crates an Link Chain object
|
|
84
|
-
*/
|
|
85
|
-
function linkFromMany(type, targetKey, sourceKey) {
|
|
86
|
-
return new link_chain_1.LinkChain(type, 'from-many', targetKey, sourceKey);
|
|
87
|
-
}
|
|
88
|
-
exports.linkFromMany = linkFromMany;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PrimaryKey = void 0;
|
|
4
|
-
const entity_model_1 = require("../model/entity-model");
|
|
5
|
-
function PrimaryKey(arg0, arg1) {
|
|
6
|
-
return function (target, propertyKey) {
|
|
7
|
-
if (arguments.length === 1) {
|
|
8
|
-
if (!(typeof arg0 === 'string' || Array.isArray(arg0)))
|
|
9
|
-
throw new Error(`You must specify primary index column(s)`);
|
|
10
|
-
const entity = entity_model_1.EntityModel.attachTo(target);
|
|
11
|
-
entity.setPrimaryIndex(arg0, arg1);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
if (!target.constructor)
|
|
15
|
-
throw new Error('Property decorators can be used for class properties only');
|
|
16
|
-
if (typeof propertyKey !== 'string')
|
|
17
|
-
throw new Error('Index() decorator can be used for string property keys only');
|
|
18
|
-
const entity = entity_model_1.EntityModel.attachTo(target.constructor);
|
|
19
|
-
entity.defineColumnElement(propertyKey, { notNull: true });
|
|
20
|
-
entity.setPrimaryIndex(propertyKey, arg0);
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
exports.PrimaryKey = PrimaryKey;
|