@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,217 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Repository = void 0;
|
|
4
|
-
const strict_typed_events_1 = require("strict-typed-events");
|
|
5
|
-
const SqbConnection_1 = require("../client/SqbConnection");
|
|
6
|
-
const extract_keyvalues_1 = require("./util/extract-keyvalues");
|
|
7
|
-
const count_command_1 = require("./commands/count.command");
|
|
8
|
-
const create_command_1 = require("./commands/create.command");
|
|
9
|
-
const find_command_1 = require("./commands/find.command");
|
|
10
|
-
const destroy_command_1 = require("./commands/destroy.command");
|
|
11
|
-
const update_command_1 = require("./commands/update.command");
|
|
12
|
-
class Repository extends strict_typed_events_1.AsyncEventEmitter {
|
|
13
|
-
constructor(entityDef, executor, schema) {
|
|
14
|
-
super();
|
|
15
|
-
this._executor = executor;
|
|
16
|
-
this._entity = entityDef;
|
|
17
|
-
this._schema = schema;
|
|
18
|
-
}
|
|
19
|
-
get entity() {
|
|
20
|
-
return this._entity;
|
|
21
|
-
}
|
|
22
|
-
get type() {
|
|
23
|
-
return this._entity.ctor;
|
|
24
|
-
}
|
|
25
|
-
create(values, options) {
|
|
26
|
-
return this._execute(async (connection) => {
|
|
27
|
-
return this._create(values, { ...options, connection });
|
|
28
|
-
}, options);
|
|
29
|
-
}
|
|
30
|
-
createOnly(values, options) {
|
|
31
|
-
return this._execute(async (connection) => {
|
|
32
|
-
return this._createOnly(values, { ...options, connection });
|
|
33
|
-
}, options);
|
|
34
|
-
}
|
|
35
|
-
exists(keyValue, options) {
|
|
36
|
-
return this._execute(async (connection) => {
|
|
37
|
-
return this._exists(keyValue, { ...options, connection });
|
|
38
|
-
}, options);
|
|
39
|
-
}
|
|
40
|
-
count(options) {
|
|
41
|
-
return this._execute(async (connection) => {
|
|
42
|
-
return this._count({ ...options, connection });
|
|
43
|
-
}, options);
|
|
44
|
-
}
|
|
45
|
-
findAll(options) {
|
|
46
|
-
return this._execute(async (connection) => {
|
|
47
|
-
return this._findAll({ ...options, connection });
|
|
48
|
-
}, options);
|
|
49
|
-
}
|
|
50
|
-
findOne(options) {
|
|
51
|
-
return this._execute(async (connection) => {
|
|
52
|
-
return this._findOne({ ...options, connection });
|
|
53
|
-
}, options);
|
|
54
|
-
}
|
|
55
|
-
findByPk(keyValue, options) {
|
|
56
|
-
return this._execute(async (connection) => {
|
|
57
|
-
return this._findByPk(keyValue, { ...options, connection });
|
|
58
|
-
}, options);
|
|
59
|
-
}
|
|
60
|
-
destroy(keyValue, options) {
|
|
61
|
-
return this._execute(async (connection) => {
|
|
62
|
-
return this._destroy(keyValue, { ...options, connection });
|
|
63
|
-
}, options);
|
|
64
|
-
}
|
|
65
|
-
destroyAll(options) {
|
|
66
|
-
return this._execute(async (connection) => {
|
|
67
|
-
return this._destroyAll({ ...options, connection });
|
|
68
|
-
}, options);
|
|
69
|
-
}
|
|
70
|
-
update(keyValue, values, options) {
|
|
71
|
-
return this._execute(async (connection) => {
|
|
72
|
-
const opts = { ...options, connection };
|
|
73
|
-
const keyValues = await this._update(keyValue, values, opts);
|
|
74
|
-
if (keyValues)
|
|
75
|
-
return this._findByPk(keyValues, opts);
|
|
76
|
-
}, options);
|
|
77
|
-
}
|
|
78
|
-
updateOnly(keyValue, values, options) {
|
|
79
|
-
return this._execute(async (connection) => {
|
|
80
|
-
return !!(await this._update(keyValue, values, { ...options, connection }));
|
|
81
|
-
}, options);
|
|
82
|
-
}
|
|
83
|
-
updateAll(values, options) {
|
|
84
|
-
return this._execute(async (connection) => {
|
|
85
|
-
return this._updateAll(values, { ...options, connection });
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
async _execute(fn, opts) {
|
|
89
|
-
let connection = opts?.connection;
|
|
90
|
-
if (!connection && this._executor instanceof SqbConnection_1.SqbConnection)
|
|
91
|
-
connection = this._executor;
|
|
92
|
-
if (connection) {
|
|
93
|
-
if (this._schema)
|
|
94
|
-
await connection.setSchema(this._schema);
|
|
95
|
-
return fn(connection);
|
|
96
|
-
}
|
|
97
|
-
return this._executor.acquire(async (conn) => {
|
|
98
|
-
if (this._schema)
|
|
99
|
-
await conn.setSchema(this._schema);
|
|
100
|
-
await this.emitAsync({ event: 'acquire', serial: true }, conn);
|
|
101
|
-
return fn(conn);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
async _create(values, options) {
|
|
105
|
-
const keyValues = await create_command_1.CreateCommand.execute({
|
|
106
|
-
...options,
|
|
107
|
-
entity: this._entity,
|
|
108
|
-
values,
|
|
109
|
-
returning: true
|
|
110
|
-
});
|
|
111
|
-
const result = keyValues && (await this.findByPk(keyValues, options));
|
|
112
|
-
if (!result)
|
|
113
|
-
throw new Error('Unable to insert new row');
|
|
114
|
-
return result;
|
|
115
|
-
}
|
|
116
|
-
async _createOnly(values, options) {
|
|
117
|
-
await create_command_1.CreateCommand.execute({
|
|
118
|
-
...options,
|
|
119
|
-
entity: this._entity,
|
|
120
|
-
values,
|
|
121
|
-
returning: false
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
async _exists(keyValue, options) {
|
|
125
|
-
const filter = [(0, extract_keyvalues_1.extractKeyValues)(this._entity, keyValue, true)];
|
|
126
|
-
if (options && options.filter) {
|
|
127
|
-
if (Array.isArray(options.filter))
|
|
128
|
-
filter.push(...options.filter);
|
|
129
|
-
else
|
|
130
|
-
filter.push(options.filter);
|
|
131
|
-
}
|
|
132
|
-
return !!(await count_command_1.CountCommand.execute({
|
|
133
|
-
...options,
|
|
134
|
-
filter,
|
|
135
|
-
entity: this._entity
|
|
136
|
-
}));
|
|
137
|
-
}
|
|
138
|
-
async _count(options) {
|
|
139
|
-
return count_command_1.CountCommand.execute({
|
|
140
|
-
...options,
|
|
141
|
-
entity: this._entity
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
async _findAll(options) {
|
|
145
|
-
return await find_command_1.FindCommand.execute({
|
|
146
|
-
...options,
|
|
147
|
-
entity: this._entity,
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
async _findOne(options) {
|
|
151
|
-
const rows = await find_command_1.FindCommand.execute({
|
|
152
|
-
...options,
|
|
153
|
-
entity: this._entity,
|
|
154
|
-
limit: 1
|
|
155
|
-
});
|
|
156
|
-
return rows && rows[0];
|
|
157
|
-
}
|
|
158
|
-
async _findByPk(keyValue, options) {
|
|
159
|
-
const filter = [(0, extract_keyvalues_1.extractKeyValues)(this._entity, keyValue, true)];
|
|
160
|
-
if (options && options.filter) {
|
|
161
|
-
if (Array.isArray(options.filter))
|
|
162
|
-
filter.push(...options.filter);
|
|
163
|
-
else
|
|
164
|
-
filter.push(options.filter);
|
|
165
|
-
}
|
|
166
|
-
return await this._findOne({ ...options, filter, offset: 0 });
|
|
167
|
-
}
|
|
168
|
-
async _destroy(keyValue, options) {
|
|
169
|
-
const filter = [(0, extract_keyvalues_1.extractKeyValues)(this._entity, keyValue, true)];
|
|
170
|
-
if (options && options.filter) {
|
|
171
|
-
if (Array.isArray(options.filter))
|
|
172
|
-
filter.push(...options.filter);
|
|
173
|
-
else
|
|
174
|
-
filter.push(options.filter);
|
|
175
|
-
}
|
|
176
|
-
return !!(await destroy_command_1.DestroyCommand.execute({
|
|
177
|
-
...options,
|
|
178
|
-
filter,
|
|
179
|
-
entity: this._entity,
|
|
180
|
-
}));
|
|
181
|
-
}
|
|
182
|
-
async _destroyAll(options) {
|
|
183
|
-
return destroy_command_1.DestroyCommand.execute({
|
|
184
|
-
...options,
|
|
185
|
-
entity: this._entity,
|
|
186
|
-
filter: options?.filter,
|
|
187
|
-
params: options?.params
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
async _update(keyValue, values, options) {
|
|
191
|
-
const keyValues = (0, extract_keyvalues_1.extractKeyValues)(this._entity, keyValue, true);
|
|
192
|
-
const filter = [keyValues];
|
|
193
|
-
if (options.filter) {
|
|
194
|
-
if (Array.isArray(options.filter))
|
|
195
|
-
filter.push(...options.filter);
|
|
196
|
-
else
|
|
197
|
-
filter.push(options.filter);
|
|
198
|
-
}
|
|
199
|
-
const updateValues = { ...values };
|
|
200
|
-
Object.keys(keyValues).forEach(k => delete updateValues[k]);
|
|
201
|
-
const rowsAffected = await update_command_1.UpdateCommand.execute({
|
|
202
|
-
...options,
|
|
203
|
-
entity: this._entity,
|
|
204
|
-
values: updateValues,
|
|
205
|
-
filter
|
|
206
|
-
});
|
|
207
|
-
return rowsAffected ? keyValues : undefined;
|
|
208
|
-
}
|
|
209
|
-
async _updateAll(values, options) {
|
|
210
|
-
return await update_command_1.UpdateCommand.execute({
|
|
211
|
-
...options,
|
|
212
|
-
entity: this._entity,
|
|
213
|
-
values
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
exports.Repository = Repository;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Type } from 'ts-gems';
|
|
2
|
-
export declare function mixinEntities<A, B, C, D, E, F>(derived: Type, classARef: Type<A>, classBRef: Type<B>, classCRef: Type<C>, classDRef: Type<D>, classERef: Type<E>, classFRef: Type<F>): Type<A & B & C & D & E & F>;
|
|
3
|
-
export declare function mixinEntities<A, B, C, D, E>(derived: Type, classARef: Type<A>, classBRef: Type<B>, classCRef: Type<C>, classDRef: Type<D>, classERef: Type<E>): Type<A & B & C & D & E>;
|
|
4
|
-
export declare function mixinEntities<A, B, C, D>(derived: Type, classARef: Type<A>, classBRef: Type<B>, classCRef: Type<C>, classDRef: Type<D>): Type<A & B & C & D>;
|
|
5
|
-
export declare function mixinEntities<A, B, C>(derived: Type, classARef: Type<A>, classBRef: Type<B>, classCRef: Type<C>): Type<A & B & C>;
|
|
6
|
-
export declare function mixinEntities<A, B>(derived: Type, classARef: Type<A>, classBRef: Type<B>): Type<A & B>;
|
|
7
|
-
export declare function mixinEntities<A, B>(derived: Type, classARef: Type<A>, classBRef: Type<B>): Type<A & B>;
|
|
8
|
-
export declare function pickEntityInto<T, K extends keyof T>(derived: Type, classRef: Type<T>, keys: readonly K[]): Type<Pick<T, typeof keys[number]>>;
|
|
9
|
-
export declare function omitEntityInto<T, K extends keyof T>(derived: Type, classRef: Type<T>, keys: readonly K[]): Type<Omit<T, typeof keys[number]>>;
|
|
10
|
-
export declare function UnionEntity<A, B>(classARef: Type<A>, classBRef: Type<B>): Type<A & B>;
|
|
11
|
-
export declare function PickEntity<T, K extends keyof T>(classRef: Type<T>, keys: readonly K[]): Type<Pick<T, typeof keys[number]>>;
|
|
12
|
-
export declare function OmitEntity<T, K extends keyof T>(classRef: Type<T>, keys: readonly K[]): Type<Omit<T, typeof keys[number]>>;
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OmitEntity = exports.PickEntity = exports.UnionEntity = exports.omitEntityInto = exports.pickEntityInto = exports.mixinEntities = void 0;
|
|
4
|
-
const entity_model_1 = require("../model/entity-model");
|
|
5
|
-
const association_1 = require("../model/association");
|
|
6
|
-
const index_meta_1 = require("../model/index-meta");
|
|
7
|
-
function mixinEntities(derived, classARef, classBRef, classCRef, classDRef, classERef, classFRef) {
|
|
8
|
-
const trg = entity_model_1.EntityModel.attachTo(derived);
|
|
9
|
-
for (const classRef of [classARef, classBRef, classCRef, classDRef, classERef, classFRef]) {
|
|
10
|
-
if (!classRef)
|
|
11
|
-
continue;
|
|
12
|
-
const src = entity_model_1.EntityModel.get(classRef);
|
|
13
|
-
if (!src)
|
|
14
|
-
return derived;
|
|
15
|
-
trg.tableName = src.tableName;
|
|
16
|
-
if (!trg.primaryIndex && src.primaryIndex) {
|
|
17
|
-
trg.primaryIndex = new index_meta_1.IndexMeta(trg, src.primaryIndex.columns, src.primaryIndex);
|
|
18
|
-
}
|
|
19
|
-
if (src.foreignKeys) {
|
|
20
|
-
trg.foreignKeys = trg.foreignKeys || [];
|
|
21
|
-
for (const fk of src.foreignKeys) {
|
|
22
|
-
const newFk = new association_1.Association(fk.name, { ...fk, source: derived });
|
|
23
|
-
trg.foreignKeys.push(newFk);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (src.indexes) {
|
|
27
|
-
trg.indexes = trg.indexes || [];
|
|
28
|
-
for (const idx of src.indexes) {
|
|
29
|
-
const newIdx = new index_meta_1.IndexMeta(trg, idx.columns, idx);
|
|
30
|
-
trg.indexes.push(newIdx);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (src.eventListeners) {
|
|
34
|
-
trg.eventListeners = trg.eventListeners || [];
|
|
35
|
-
trg.eventListeners.push(...src.eventListeners);
|
|
36
|
-
}
|
|
37
|
-
src.elements.forEach((p, n) => {
|
|
38
|
-
const o = Object.assign({}, p);
|
|
39
|
-
o.entity = trg;
|
|
40
|
-
Object.setPrototypeOf(o, Object.getPrototypeOf(p));
|
|
41
|
-
trg.elements.set(n, o);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
return derived;
|
|
45
|
-
}
|
|
46
|
-
exports.mixinEntities = mixinEntities;
|
|
47
|
-
function pickEntityInto(derived, classRef, keys) {
|
|
48
|
-
const trg = entity_model_1.EntityModel.attachTo(derived);
|
|
49
|
-
const src = entity_model_1.EntityModel.get(classRef);
|
|
50
|
-
if (!src)
|
|
51
|
-
return derived;
|
|
52
|
-
trg.tableName = src.tableName;
|
|
53
|
-
trg.schema = src.schema;
|
|
54
|
-
trg.comment = src.comment;
|
|
55
|
-
trg.primaryIndex = src.primaryIndex;
|
|
56
|
-
const pickKeys = keys.map(x => x.toLowerCase());
|
|
57
|
-
for (const fk of src.foreignKeys) {
|
|
58
|
-
if (fk.sourceKey && pickKeys.includes(fk.sourceKey.toLowerCase())) {
|
|
59
|
-
const newFk = new association_1.Association(fk.name, { ...fk, source: derived });
|
|
60
|
-
trg.foreignKeys.push(newFk);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
for (const idx of src.indexes) {
|
|
64
|
-
if (!idx.columns.find(x => !pickKeys.includes(x.toLowerCase()))) {
|
|
65
|
-
const newIdx = new index_meta_1.IndexMeta(trg, idx.columns, idx);
|
|
66
|
-
trg.indexes.push(newIdx);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
trg.eventListeners.push(...src.eventListeners);
|
|
70
|
-
src.elements.forEach((p, n) => {
|
|
71
|
-
if (pickKeys.includes(n))
|
|
72
|
-
trg.elements.set(n, p);
|
|
73
|
-
});
|
|
74
|
-
return derived;
|
|
75
|
-
}
|
|
76
|
-
exports.pickEntityInto = pickEntityInto;
|
|
77
|
-
function omitEntityInto(derived, classRef, keys) {
|
|
78
|
-
const trg = entity_model_1.EntityModel.attachTo(derived);
|
|
79
|
-
const src = entity_model_1.EntityModel.get(classRef);
|
|
80
|
-
if (!src)
|
|
81
|
-
return derived;
|
|
82
|
-
trg.tableName = src.tableName;
|
|
83
|
-
trg.schema = src.schema;
|
|
84
|
-
trg.comment = src.comment;
|
|
85
|
-
trg.primaryIndex = src.primaryIndex;
|
|
86
|
-
const omitKeys = keys.map(x => x.toLowerCase());
|
|
87
|
-
for (const fk of src.foreignKeys) {
|
|
88
|
-
if (!(fk.sourceKey && omitKeys.includes(fk.sourceKey.toLowerCase()))) {
|
|
89
|
-
const newFk = new association_1.Association(fk.name, { ...fk, source: derived });
|
|
90
|
-
trg.foreignKeys.push(newFk);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
for (const idx of src.indexes) {
|
|
94
|
-
if (!idx.columns.find(x => omitKeys.includes(x.toLowerCase()))) {
|
|
95
|
-
const newIdx = new index_meta_1.IndexMeta(trg, idx.columns, idx);
|
|
96
|
-
trg.indexes.push(newIdx);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
trg.eventListeners.push(...src.eventListeners);
|
|
100
|
-
src.elements.forEach((p, n) => {
|
|
101
|
-
if (!omitKeys.includes(n.toLowerCase()))
|
|
102
|
-
trg.elements.set(n.toLowerCase(), p);
|
|
103
|
-
});
|
|
104
|
-
trg.elements.forEach((p, n) => {
|
|
105
|
-
if (omitKeys.includes(n.toLowerCase()))
|
|
106
|
-
trg.elements.delete(n.toLowerCase());
|
|
107
|
-
});
|
|
108
|
-
return derived;
|
|
109
|
-
}
|
|
110
|
-
exports.omitEntityInto = omitEntityInto;
|
|
111
|
-
function UnionEntity(classARef, classBRef) {
|
|
112
|
-
class UnionEntityClass {
|
|
113
|
-
constructor(...args) {
|
|
114
|
-
inheritPropertyInitializers(this, classARef, args);
|
|
115
|
-
inheritPropertyInitializers(this, classBRef, args);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return mixinEntities(UnionEntityClass, classARef, classBRef);
|
|
119
|
-
}
|
|
120
|
-
exports.UnionEntity = UnionEntity;
|
|
121
|
-
function PickEntity(classRef, keys) {
|
|
122
|
-
class PickEntityClass {
|
|
123
|
-
constructor(...args) {
|
|
124
|
-
inheritPropertyInitializers(this, classRef, args);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return pickEntityInto(PickEntityClass, classRef, keys);
|
|
128
|
-
}
|
|
129
|
-
exports.PickEntity = PickEntity;
|
|
130
|
-
function OmitEntity(classRef, keys) {
|
|
131
|
-
class OmitEntityClass {
|
|
132
|
-
constructor(...args) {
|
|
133
|
-
inheritPropertyInitializers(this, classRef, args);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return omitEntityInto(OmitEntityClass, classRef, keys);
|
|
137
|
-
}
|
|
138
|
-
exports.OmitEntity = OmitEntity;
|
|
139
|
-
function inheritPropertyInitializers(target, sourceClass, constructorArgs, isPropertyInherited) {
|
|
140
|
-
try {
|
|
141
|
-
const tempInstance = new sourceClass(...constructorArgs);
|
|
142
|
-
const keys = Object.getOwnPropertyNames(tempInstance);
|
|
143
|
-
for (const key of keys) {
|
|
144
|
-
const srcDesc = Object.getOwnPropertyDescriptor(tempInstance, key);
|
|
145
|
-
const trgDesc = Object.getOwnPropertyDescriptor(target, key);
|
|
146
|
-
if (!srcDesc || trgDesc || (isPropertyInherited && !isPropertyInherited(key)))
|
|
147
|
-
continue;
|
|
148
|
-
Object.defineProperty(target, key, srcDesc);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
catch {
|
|
152
|
-
//
|
|
153
|
-
}
|
|
154
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractKeyValues = void 0;
|
|
4
|
-
const orm_helper_1 = require("./orm.helper");
|
|
5
|
-
function extractKeyValues(entityDef, valueOrInstance, keepOther) {
|
|
6
|
-
const primaryIndex = entityDef.primaryIndex;
|
|
7
|
-
if (!primaryIndex)
|
|
8
|
-
throw new Error(`No primary fields defined for "${entityDef.name}" entity`);
|
|
9
|
-
const validateCol = (k) => {
|
|
10
|
-
const col = entityDef.getElement(k);
|
|
11
|
-
if (!col)
|
|
12
|
-
throw new Error(`Unknown column (${k}) defined as primary key in entity "${entityDef.name}"`);
|
|
13
|
-
if (!(0, orm_helper_1.isColumnElement)(col))
|
|
14
|
-
throw new Error(`Column (${k}) defined as primary key in entity "${entityDef.name}" is not a data column`);
|
|
15
|
-
};
|
|
16
|
-
// if entity's primary key has more than one key field
|
|
17
|
-
if (primaryIndex.columns.length > 1) {
|
|
18
|
-
if (typeof valueOrInstance !== 'object')
|
|
19
|
-
throw new Error(`"${entityDef.name}" entity` +
|
|
20
|
-
` has more than one primary key field and you must provide all values with an key/value pair`);
|
|
21
|
-
const valueKeys = Object.keys(valueOrInstance);
|
|
22
|
-
const valueKeysUpper = valueKeys.map(x => x.toUpperCase());
|
|
23
|
-
const out = {};
|
|
24
|
-
for (const k of primaryIndex.columns) {
|
|
25
|
-
const i = valueKeysUpper.indexOf(k.toUpperCase());
|
|
26
|
-
if (i < 0)
|
|
27
|
-
throw new Error(`Value of key field "${entityDef.name}.${k}" required to perform this operation`);
|
|
28
|
-
validateCol(k);
|
|
29
|
-
out[k] = valueOrInstance[valueKeys[i]];
|
|
30
|
-
}
|
|
31
|
-
if (keepOther) {
|
|
32
|
-
for (let i = 0; i < valueKeys.length; i++) {
|
|
33
|
-
if (primaryIndex.columns.find(x => x.toUpperCase() === valueKeysUpper[i]))
|
|
34
|
-
continue;
|
|
35
|
-
out[valueKeys[i]] = valueOrInstance[valueKeys[i]];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return out;
|
|
39
|
-
}
|
|
40
|
-
const primaryColumnName = primaryIndex.columns[0];
|
|
41
|
-
validateCol(primaryColumnName);
|
|
42
|
-
if (typeof valueOrInstance === 'object') {
|
|
43
|
-
const valueKeys = Object.keys(valueOrInstance);
|
|
44
|
-
const valueKeysUpper = valueKeys.map(x => x.toUpperCase());
|
|
45
|
-
const k = valueKeysUpper.indexOf(primaryColumnName.toUpperCase());
|
|
46
|
-
if (k < 0)
|
|
47
|
-
throw new Error(`Value of key field "${entityDef.name}.${primaryColumnName}" required to perform this operation`);
|
|
48
|
-
const out = { [primaryColumnName]: valueOrInstance[valueKeys[k]] };
|
|
49
|
-
if (keepOther) {
|
|
50
|
-
for (let i = 0; i < valueKeys.length; i++) {
|
|
51
|
-
if (primaryIndex.columns.find(x => x.toUpperCase() === valueKeysUpper[i]))
|
|
52
|
-
continue;
|
|
53
|
-
out[valueKeys[i]] = valueOrInstance[valueKeys[i]];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return out;
|
|
57
|
-
}
|
|
58
|
-
return { [primaryColumnName]: valueOrInstance };
|
|
59
|
-
}
|
|
60
|
-
exports.extractKeyValues = extractKeyValues;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { Type } from 'ts-gems';
|
|
3
|
-
import type { TypeThunk } from '../orm.type';
|
|
4
|
-
import type { EntityModel } from '../model/entity-model';
|
|
5
|
-
import type { EntityColumnElement } from '../model/entity-column-element';
|
|
6
|
-
import type { EntityObjectElement } from '../model/entity-object-element';
|
|
7
|
-
import type { EntityAssociationElement } from '../model/entity-association-element';
|
|
8
|
-
export declare function isClass(fn: any): fn is Type;
|
|
9
|
-
export declare function isEntityClass(fn: any): fn is Type;
|
|
10
|
-
export declare function isColumnElement(f: any): f is EntityColumnElement;
|
|
11
|
-
export declare const isObjectElement: (f: any) => f is EntityObjectElement;
|
|
12
|
-
export declare const isAssociationElement: (f: any) => f is EntityAssociationElement;
|
|
13
|
-
export declare function resolveEntity(ctorThunk: TypeThunk): Promise<Type | undefined>;
|
|
14
|
-
export declare function resolveEntityMeta(ctorThunk: TypeThunk): Promise<EntityModel | undefined>;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveEntityMeta = exports.resolveEntity = exports.isAssociationElement = exports.isObjectElement = exports.isColumnElement = exports.isEntityClass = exports.isClass = void 0;
|
|
4
|
-
require("reflect-metadata");
|
|
5
|
-
const orm_const_1 = require("../orm.const");
|
|
6
|
-
function isClass(fn) {
|
|
7
|
-
return typeof fn === 'function' && /^\s*class/.test(fn.toString());
|
|
8
|
-
}
|
|
9
|
-
exports.isClass = isClass;
|
|
10
|
-
function isEntityClass(fn) {
|
|
11
|
-
return !!(isClass(fn) && fn[orm_const_1.ENTITY_DEFINITION_KEY]);
|
|
12
|
-
}
|
|
13
|
-
exports.isEntityClass = isEntityClass;
|
|
14
|
-
function isColumnElement(f) {
|
|
15
|
-
return !!(f && f.entity && f.kind === 'column');
|
|
16
|
-
}
|
|
17
|
-
exports.isColumnElement = isColumnElement;
|
|
18
|
-
const isObjectElement = (f) => {
|
|
19
|
-
return !!(f && f.entity && f.kind === 'object');
|
|
20
|
-
};
|
|
21
|
-
exports.isObjectElement = isObjectElement;
|
|
22
|
-
const isAssociationElement = (f) => {
|
|
23
|
-
return !!(f && f.entity && f.kind === 'association');
|
|
24
|
-
};
|
|
25
|
-
exports.isAssociationElement = isAssociationElement;
|
|
26
|
-
async function resolveEntity(ctorThunk) {
|
|
27
|
-
if (typeof ctorThunk !== 'function')
|
|
28
|
-
return;
|
|
29
|
-
if (!isClass(ctorThunk))
|
|
30
|
-
ctorThunk = await ctorThunk();
|
|
31
|
-
if (isEntityClass(ctorThunk))
|
|
32
|
-
return ctorThunk;
|
|
33
|
-
}
|
|
34
|
-
exports.resolveEntity = resolveEntity;
|
|
35
|
-
async function resolveEntityMeta(ctorThunk) {
|
|
36
|
-
const ctor = await resolveEntity(ctorThunk);
|
|
37
|
-
return ctor && ctor[orm_const_1.ENTITY_DEFINITION_KEY];
|
|
38
|
-
}
|
|
39
|
-
exports.resolveEntityMeta = resolveEntityMeta;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.serializeColumn = void 0;
|
|
4
|
-
const builder_1 = require("@sqb/builder");
|
|
5
|
-
const orm_helper_1 = require("./orm.helper");
|
|
6
|
-
function serializeColumn(col, v) {
|
|
7
|
-
if ((0, orm_helper_1.isColumnElement)(col)) {
|
|
8
|
-
if (col.isArray) {
|
|
9
|
-
if (Array.isArray(v))
|
|
10
|
-
return v.map(x => serializeDataValue(col.dataType || builder_1.DataType.VARCHAR, x));
|
|
11
|
-
return [serializeDataValue(col.dataType || builder_1.DataType.VARCHAR, v)];
|
|
12
|
-
}
|
|
13
|
-
return serializeDataValue(col.dataType || builder_1.DataType.VARCHAR, v);
|
|
14
|
-
}
|
|
15
|
-
if (typeof v === 'object' && typeof v.toJSON === 'function')
|
|
16
|
-
return v.toJSON();
|
|
17
|
-
return v;
|
|
18
|
-
}
|
|
19
|
-
exports.serializeColumn = serializeColumn;
|
|
20
|
-
const padZero = (n) => (n < 9 ? '0' : '') + n;
|
|
21
|
-
function serializeDataValue(dataType, v) {
|
|
22
|
-
if (v == null)
|
|
23
|
-
return;
|
|
24
|
-
if (v instanceof Date &&
|
|
25
|
-
(dataType === builder_1.DataType.DATE || dataType === builder_1.DataType.TIMESTAMP)) {
|
|
26
|
-
return v.getFullYear() + '-' +
|
|
27
|
-
padZero(v.getMonth() + 1) + '-' +
|
|
28
|
-
padZero(v.getDate()) + (dataType === builder_1.DataType.TIMESTAMP ?
|
|
29
|
-
'T' + padZero(v.getHours()) + ':' +
|
|
30
|
-
padZero(v.getMinutes()) + ':' +
|
|
31
|
-
padZero(v.getSeconds()) : '');
|
|
32
|
-
}
|
|
33
|
-
if (v instanceof Buffer)
|
|
34
|
-
return v.toString('base64');
|
|
35
|
-
if (typeof v === 'number' && (dataType === builder_1.DataType.SMALLINT ||
|
|
36
|
-
dataType === builder_1.DataType.INTEGER))
|
|
37
|
-
return Math.trunc(v);
|
|
38
|
-
if (typeof v === 'bigint')
|
|
39
|
-
return v.toString();
|
|
40
|
-
if (v && typeof v === 'object' && typeof v.toJSON === 'function')
|
|
41
|
-
return v.toJSON();
|
|
42
|
-
return v;
|
|
43
|
-
}
|
package/dist/types.d.ts
DELETED
package/dist/types.js
DELETED