@sqb/connect 4.20.7 → 4.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{types/client → client}/cursor-stream.d.ts +1 -1
- package/{types/client → client}/cursor.d.ts +4 -4
- package/{types/client → client}/sqb-connection.d.ts +4 -4
- package/{esm/orm → orm}/commands/command.helper.js +2 -3
- package/{types/orm → orm}/commands/count.command.d.ts +2 -2
- package/{types/orm → orm}/commands/create.command.d.ts +1 -1
- package/{esm/orm → orm}/commands/create.command.js +3 -5
- package/{types/orm → orm}/commands/delete.command.d.ts +2 -2
- package/{types/orm → orm}/commands/find.command.d.ts +2 -2
- package/{esm/orm → orm}/commands/find.command.js +3 -4
- package/{types/orm → orm}/commands/row-converter.d.ts +1 -1
- package/{types/orm → orm}/commands/update.command.d.ts +2 -2
- package/{esm/orm → orm}/commands/update.command.js +3 -5
- package/{types/orm → orm}/model/association-field-metadata.d.ts +0 -5
- package/{types/orm → orm}/model/association.d.ts +3 -3
- package/{esm/orm → orm}/model/association.js +1 -1
- package/{types/orm → orm}/model/column-field-metadata.d.ts +2 -8
- package/{types/orm → orm}/model/embedded-field-metadata.d.ts +0 -1
- package/{esm/orm → orm}/model/embedded-field-metadata.js +0 -14
- package/{types/orm → orm}/model/entity-metadata.d.ts +3 -3
- package/{esm/orm → orm}/model/entity-metadata.js +21 -6
- package/orm/model/index-metadata.js +1 -0
- package/orm/orm.type.js +1 -0
- package/{types/orm → orm}/repository.class.d.ts +2 -2
- package/{esm/orm → orm}/repository.class.js +1 -1
- package/{types/orm → orm}/util/orm.helper.d.ts +5 -3
- package/{esm/orm → orm}/util/orm.helper.js +14 -0
- package/package.json +10 -26
- package/cjs/client/adapter.js +0 -2
- package/cjs/client/cursor-stream.js +0 -104
- package/cjs/client/cursor.js +0 -261
- package/cjs/client/extensions.js +0 -41
- package/cjs/client/field-info-map.js +0 -54
- package/cjs/client/helpers.js +0 -140
- package/cjs/client/sqb-client.js +0 -175
- package/cjs/client/sqb-connection.js +0 -293
- package/cjs/client/sqb-error.js +0 -15
- package/cjs/client/types.js +0 -5
- package/cjs/index.js +0 -41
- package/cjs/orm/backward.js +0 -24
- package/cjs/orm/base-entity.js +0 -29
- package/cjs/orm/commands/command.helper.js +0 -170
- package/cjs/orm/commands/count.command.js +0 -30
- package/cjs/orm/commands/create.command.js +0 -92
- package/cjs/orm/commands/delete.command.js +0 -30
- package/cjs/orm/commands/find.command.js +0 -301
- package/cjs/orm/commands/row-converter.js +0 -190
- package/cjs/orm/commands/update.command.js +0 -83
- package/cjs/orm/decorators/column.decorator.js +0 -32
- package/cjs/orm/decorators/embedded.decorator.js +0 -15
- package/cjs/orm/decorators/entity.decorator.js +0 -180
- package/cjs/orm/decorators/events.decorator.js +0 -63
- package/cjs/orm/decorators/foreignkey.decorator.js +0 -12
- package/cjs/orm/decorators/index.decorator.js +0 -20
- package/cjs/orm/decorators/link.decorator.js +0 -72
- package/cjs/orm/decorators/primarykey.decorator.js +0 -24
- package/cjs/orm/decorators/transform.decorator.js +0 -21
- package/cjs/orm/model/association-field-metadata.js +0 -24
- package/cjs/orm/model/association-node.js +0 -28
- package/cjs/orm/model/association.js +0 -141
- package/cjs/orm/model/column-field-metadata.js +0 -32
- package/cjs/orm/model/embedded-field-metadata.js +0 -28
- package/cjs/orm/model/entity-metadata.js +0 -327
- package/cjs/orm/model/field-metadata.js +0 -2
- package/cjs/orm/model/index-metadata.js +0 -2
- package/cjs/orm/model/link-chain.js +0 -47
- package/cjs/orm/orm.const.js +0 -6
- package/cjs/orm/orm.type.js +0 -2
- package/cjs/orm/repository.class.js +0 -293
- package/cjs/orm/util/apply-mixins.js +0 -16
- package/cjs/orm/util/extract-keyvalues.js +0 -63
- package/cjs/orm/util/orm.helper.js +0 -34
- package/cjs/orm/util/parse-fields-projection.js +0 -68
- package/cjs/orm/util/serialize-field.js +0 -49
- package/cjs/package.json +0 -3
- package/esm/orm/model/association-field-metadata.js +0 -20
- package/esm/orm/model/column-field-metadata.js +0 -28
- package/esm/package.json +0 -3
- package/types/index.d.cts +0 -33
- /package/{types/client → client}/adapter.d.ts +0 -0
- /package/{esm/client → client}/adapter.js +0 -0
- /package/{esm/client → client}/cursor-stream.js +0 -0
- /package/{esm/client → client}/cursor.js +0 -0
- /package/{types/client → client}/extensions.d.ts +0 -0
- /package/{esm/client → client}/extensions.js +0 -0
- /package/{types/client → client}/field-info-map.d.ts +0 -0
- /package/{esm/client → client}/field-info-map.js +0 -0
- /package/{types/client → client}/helpers.d.ts +0 -0
- /package/{esm/client → client}/helpers.js +0 -0
- /package/{types/client → client}/sqb-client.d.ts +0 -0
- /package/{esm/client → client}/sqb-client.js +0 -0
- /package/{esm/client → client}/sqb-connection.js +0 -0
- /package/{types/client → client}/sqb-error.d.ts +0 -0
- /package/{esm/client → client}/sqb-error.js +0 -0
- /package/{types/client → client}/types.d.ts +0 -0
- /package/{esm/client → client}/types.js +0 -0
- /package/{types/index.d.ts → index.d.ts} +0 -0
- /package/{esm/index.js → index.js} +0 -0
- /package/{types/orm → orm}/backward.d.ts +0 -0
- /package/{esm/orm → orm}/backward.js +0 -0
- /package/{types/orm → orm}/base-entity.d.ts +0 -0
- /package/{esm/orm → orm}/base-entity.js +0 -0
- /package/{types/orm → orm}/commands/command.helper.d.ts +0 -0
- /package/{esm/orm → orm}/commands/count.command.js +0 -0
- /package/{esm/orm → orm}/commands/delete.command.js +0 -0
- /package/{esm/orm → orm}/commands/row-converter.js +0 -0
- /package/{types/orm → orm}/decorators/column.decorator.d.ts +0 -0
- /package/{esm/orm → orm}/decorators/column.decorator.js +0 -0
- /package/{types/orm → orm}/decorators/embedded.decorator.d.ts +0 -0
- /package/{esm/orm → orm}/decorators/embedded.decorator.js +0 -0
- /package/{types/orm → orm}/decorators/entity.decorator.d.ts +0 -0
- /package/{esm/orm → orm}/decorators/entity.decorator.js +0 -0
- /package/{types/orm → orm}/decorators/events.decorator.d.ts +0 -0
- /package/{esm/orm → orm}/decorators/events.decorator.js +0 -0
- /package/{types/orm → orm}/decorators/foreignkey.decorator.d.ts +0 -0
- /package/{esm/orm → orm}/decorators/foreignkey.decorator.js +0 -0
- /package/{types/orm → orm}/decorators/index.decorator.d.ts +0 -0
- /package/{esm/orm → orm}/decorators/index.decorator.js +0 -0
- /package/{types/orm → orm}/decorators/link.decorator.d.ts +0 -0
- /package/{esm/orm → orm}/decorators/link.decorator.js +0 -0
- /package/{types/orm → orm}/decorators/primarykey.decorator.d.ts +0 -0
- /package/{esm/orm → orm}/decorators/primarykey.decorator.js +0 -0
- /package/{types/orm → orm}/decorators/transform.decorator.d.ts +0 -0
- /package/{esm/orm → orm}/decorators/transform.decorator.js +0 -0
- /package/{esm/orm/model/field-metadata.js → orm/model/association-field-metadata.js} +0 -0
- /package/{types/orm → orm}/model/association-node.d.ts +0 -0
- /package/{esm/orm → orm}/model/association-node.js +0 -0
- /package/{esm/orm/model/index-metadata.js → orm/model/column-field-metadata.js} +0 -0
- /package/{types/orm → orm}/model/field-metadata.d.ts +0 -0
- /package/{esm/orm/orm.type.js → orm/model/field-metadata.js} +0 -0
- /package/{types/orm → orm}/model/index-metadata.d.ts +0 -0
- /package/{types/orm → orm}/model/link-chain.d.ts +0 -0
- /package/{esm/orm → orm}/model/link-chain.js +0 -0
- /package/{types/orm → orm}/orm.const.d.ts +0 -0
- /package/{esm/orm → orm}/orm.const.js +0 -0
- /package/{types/orm → orm}/orm.type.d.ts +0 -0
- /package/{types/orm → orm}/util/apply-mixins.d.ts +0 -0
- /package/{esm/orm → orm}/util/apply-mixins.js +0 -0
- /package/{types/orm → orm}/util/extract-keyvalues.d.ts +0 -0
- /package/{esm/orm → orm}/util/extract-keyvalues.js +0 -0
- /package/{types/orm → orm}/util/parse-fields-projection.d.ts +0 -0
- /package/{esm/orm → orm}/util/parse-fields-projection.js +0 -0
- /package/{types/orm → orm}/util/serialize-field.d.ts +0 -0
- /package/{esm/orm → orm}/util/serialize-field.js +0 -0
|
@@ -1,293 +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 sqb_connection_js_1 = require("../client/sqb-connection.js");
|
|
6
|
-
const count_command_js_1 = require("./commands/count.command.js");
|
|
7
|
-
const create_command_js_1 = require("./commands/create.command.js");
|
|
8
|
-
const delete_command_js_1 = require("./commands/delete.command.js");
|
|
9
|
-
const find_command_js_1 = require("./commands/find.command.js");
|
|
10
|
-
const update_command_js_1 = require("./commands/update.command.js");
|
|
11
|
-
const entity_metadata_js_1 = require("./model/entity-metadata.js");
|
|
12
|
-
const extract_keyvalues_js_1 = require("./util/extract-keyvalues.js");
|
|
13
|
-
/**
|
|
14
|
-
* @class Repository
|
|
15
|
-
* @template T - The data type class type of the record
|
|
16
|
-
*/
|
|
17
|
-
class Repository extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_typed_events_1.AsyncEventEmitter) {
|
|
18
|
-
_executor;
|
|
19
|
-
_entity;
|
|
20
|
-
_schema;
|
|
21
|
-
constructor(entityDef, executor, schema) {
|
|
22
|
-
super();
|
|
23
|
-
this._executor = executor;
|
|
24
|
-
this._entity = entityDef;
|
|
25
|
-
this._schema = schema;
|
|
26
|
-
}
|
|
27
|
-
get entity() {
|
|
28
|
-
return this._entity;
|
|
29
|
-
}
|
|
30
|
-
get type() {
|
|
31
|
-
return this._entity.ctor;
|
|
32
|
-
}
|
|
33
|
-
create(input, options) {
|
|
34
|
-
return this._execute(async (connection) => {
|
|
35
|
-
const keyValue = await this._create(input, {
|
|
36
|
-
...options,
|
|
37
|
-
connection,
|
|
38
|
-
returning: true,
|
|
39
|
-
});
|
|
40
|
-
const result = keyValue && (await this._find(keyValue, { ...options, connection }));
|
|
41
|
-
if (!result)
|
|
42
|
-
throw new Error('Unable to insert new row');
|
|
43
|
-
return result;
|
|
44
|
-
}, options);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Creates a new resource but returns nothing
|
|
48
|
-
*
|
|
49
|
-
* @param {PartialDTO<T>} input - The input data
|
|
50
|
-
* @param {Repository.CreateOptions} [options] - The options object
|
|
51
|
-
* @returns {Promise<any>} A promise that resolves key value(s) of the created record
|
|
52
|
-
* @throws {Error} if an unknown error occurs while creating the resource
|
|
53
|
-
*/
|
|
54
|
-
createOnly(input, options) {
|
|
55
|
-
return this._execute(async (connection) => {
|
|
56
|
-
const r = await this._create(input, {
|
|
57
|
-
...options,
|
|
58
|
-
connection,
|
|
59
|
-
returning: true,
|
|
60
|
-
});
|
|
61
|
-
const primaryIndex = entity_metadata_js_1.EntityMetadata.getPrimaryIndex(this.entity);
|
|
62
|
-
if (!primaryIndex || primaryIndex.columns.length > 1)
|
|
63
|
-
return r;
|
|
64
|
-
return r[primaryIndex.columns[0]];
|
|
65
|
-
}, options);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Returns the count of records based on the provided options
|
|
69
|
-
*
|
|
70
|
-
* @param {Repository.CountOptions} options - The options for the count operation.
|
|
71
|
-
* @return {Promise<number>} - A promise that resolves to the count of records
|
|
72
|
-
*/
|
|
73
|
-
count(options) {
|
|
74
|
-
return this._execute(async (connection) => this._count({ ...options, connection }), options);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Deletes a record from the collection.
|
|
78
|
-
*
|
|
79
|
-
* @param {any} keyValue - The ID of the resource to delete.
|
|
80
|
-
* @param {Repository.DeleteOptions} [options] - Optional delete options.
|
|
81
|
-
* @return {Promise<boolean>} - A Promise that resolves true or false. True when resource deleted.
|
|
82
|
-
*/
|
|
83
|
-
delete(keyValue, options) {
|
|
84
|
-
return this._execute(async (connection) => this._delete(keyValue, { ...options, connection }), options);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Deletes multiple documents from the collection that meet the specified filter criteria.
|
|
88
|
-
*
|
|
89
|
-
* @param {Repository.DeleteManyOptions} options - The options for the delete operation.
|
|
90
|
-
* @return {Promise<number>} - A promise that resolves to the number of resources deleted.
|
|
91
|
-
*/
|
|
92
|
-
deleteMany(options) {
|
|
93
|
-
return this._execute(async (connection) => this._deleteMany({ ...options, connection }), options);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Checks if a record with the given id exists.
|
|
97
|
-
*
|
|
98
|
-
* @param {any} keyValue - The id of the object to check.
|
|
99
|
-
* @param {Repository.ExistsOptions} [options] - The options for the query (optional).
|
|
100
|
-
* @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
|
|
101
|
-
*/
|
|
102
|
-
exists(keyValue, options) {
|
|
103
|
-
return this._execute(async (connection) => this._exists(keyValue, { ...options, connection }), options);
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Checks if a record with the given arguments exists.
|
|
107
|
-
*
|
|
108
|
-
* @param {Repository.ExistsOptions} [options] - The options for the query (optional).
|
|
109
|
-
* @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
|
|
110
|
-
*/
|
|
111
|
-
existsOne(options) {
|
|
112
|
-
return this._execute(async (connection) => this._existsOne({ ...options, connection }), options);
|
|
113
|
-
}
|
|
114
|
-
findById(keyValue, options) {
|
|
115
|
-
return this._execute(async (connection) => this._find(keyValue, { ...options, connection }), options);
|
|
116
|
-
}
|
|
117
|
-
findOne(options) {
|
|
118
|
-
return this._execute(async (connection) => await this._findOne({
|
|
119
|
-
...options,
|
|
120
|
-
connection,
|
|
121
|
-
}), options);
|
|
122
|
-
}
|
|
123
|
-
findMany(options) {
|
|
124
|
-
return this._execute(async (connection) => this._findMany({ ...options, connection }), options);
|
|
125
|
-
}
|
|
126
|
-
update(keyValue, input, options) {
|
|
127
|
-
return this._execute(async (connection) => {
|
|
128
|
-
const opts = { ...options, connection };
|
|
129
|
-
const keyValues = await this._update(keyValue, input, opts);
|
|
130
|
-
if (keyValues)
|
|
131
|
-
return this._find(keyValues, opts);
|
|
132
|
-
}, options);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Updates a record in the collection with the specified ID and returns updated record count
|
|
136
|
-
*
|
|
137
|
-
* @param {any} keyValue - The ID of the document to update.
|
|
138
|
-
* @param {PatchDTO<T>} input - The partial input data to update the document with.
|
|
139
|
-
* @param {Repository.UpdateOptions} options - The options for updating the document.
|
|
140
|
-
* @returns {Promise<number>} - A Promise that resolves true or false. True when resource updated.
|
|
141
|
-
*/
|
|
142
|
-
updateOnly(keyValue, input, options) {
|
|
143
|
-
return this._execute(async (connection) => !!(await this._update(keyValue, input, { ...options, connection })), options);
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Updates multiple records in the collection based on the specified input and options.
|
|
147
|
-
*
|
|
148
|
-
* @param {PatchDTO<T>} input - The partial input to update the documents with.
|
|
149
|
-
* @param {Repository.UpdateManyOptions} options - The options for updating the documents.
|
|
150
|
-
* @return {Promise<number>} - A promise that resolves to the number of documents matched and modified.
|
|
151
|
-
*/
|
|
152
|
-
updateMany(input, options) {
|
|
153
|
-
return this._execute(async (connection) => this._updateMany(input, { ...options, connection }));
|
|
154
|
-
}
|
|
155
|
-
async _execute(fn, opts) {
|
|
156
|
-
let connection = opts?.connection;
|
|
157
|
-
if (!connection && this._executor instanceof sqb_connection_js_1.SqbConnection)
|
|
158
|
-
connection = this._executor;
|
|
159
|
-
if (connection) {
|
|
160
|
-
if (this._schema)
|
|
161
|
-
await connection.setSchema(this._schema);
|
|
162
|
-
return fn(connection);
|
|
163
|
-
}
|
|
164
|
-
return this._executor.acquire(async (conn) => {
|
|
165
|
-
if (this._schema)
|
|
166
|
-
await conn.setSchema(this._schema);
|
|
167
|
-
await this.emitAsyncSerial('acquire', conn);
|
|
168
|
-
return fn(conn);
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
async _create(values, options) {
|
|
172
|
-
if (!values)
|
|
173
|
-
throw new TypeError('You must provide values');
|
|
174
|
-
const keyValues = await create_command_js_1.CreateCommand.execute({
|
|
175
|
-
...options,
|
|
176
|
-
entity: this._entity,
|
|
177
|
-
values,
|
|
178
|
-
});
|
|
179
|
-
if (options.returning && !keyValues)
|
|
180
|
-
throw new Error('Unable to insert new row');
|
|
181
|
-
return keyValues;
|
|
182
|
-
}
|
|
183
|
-
async _exists(keyValue, options) {
|
|
184
|
-
const filter = [(0, extract_keyvalues_js_1.extractKeyValues)(this._entity, keyValue, true)];
|
|
185
|
-
if (options && options.filter) {
|
|
186
|
-
if (Array.isArray(options.filter))
|
|
187
|
-
filter.push(...options.filter);
|
|
188
|
-
else
|
|
189
|
-
filter.push(options.filter);
|
|
190
|
-
}
|
|
191
|
-
return this._existsOne({
|
|
192
|
-
...options,
|
|
193
|
-
filter,
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
async _existsOne(options) {
|
|
197
|
-
const filter = [];
|
|
198
|
-
if (options && options.filter) {
|
|
199
|
-
if (Array.isArray(options.filter))
|
|
200
|
-
filter.push(...options.filter);
|
|
201
|
-
else
|
|
202
|
-
filter.push(options.filter);
|
|
203
|
-
}
|
|
204
|
-
const resp = await find_command_js_1.FindCommand.execute({
|
|
205
|
-
...options,
|
|
206
|
-
filter,
|
|
207
|
-
entity: this._entity,
|
|
208
|
-
});
|
|
209
|
-
return resp.length > 0;
|
|
210
|
-
}
|
|
211
|
-
async _count(options) {
|
|
212
|
-
return count_command_js_1.CountCommand.execute({
|
|
213
|
-
...options,
|
|
214
|
-
entity: this._entity,
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
async _findMany(options) {
|
|
218
|
-
return await find_command_js_1.FindCommand.execute({
|
|
219
|
-
...options,
|
|
220
|
-
entity: this._entity,
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
async _findOne(options) {
|
|
224
|
-
const rows = await this._findMany({
|
|
225
|
-
...options,
|
|
226
|
-
limit: 1,
|
|
227
|
-
});
|
|
228
|
-
return rows && rows[0];
|
|
229
|
-
}
|
|
230
|
-
async _find(keyValue, options) {
|
|
231
|
-
const filter = [(0, extract_keyvalues_js_1.extractKeyValues)(this._entity, keyValue, true)];
|
|
232
|
-
if (options && options.filter) {
|
|
233
|
-
if (Array.isArray(options.filter))
|
|
234
|
-
filter.push(...options.filter);
|
|
235
|
-
else
|
|
236
|
-
filter.push(options.filter);
|
|
237
|
-
}
|
|
238
|
-
return await this._findOne({ ...options, filter, offset: 0 });
|
|
239
|
-
}
|
|
240
|
-
async _delete(keyValue, options) {
|
|
241
|
-
const filter = [(0, extract_keyvalues_js_1.extractKeyValues)(this._entity, keyValue, true)];
|
|
242
|
-
if (options && options.filter) {
|
|
243
|
-
if (Array.isArray(options.filter))
|
|
244
|
-
filter.push(...options.filter);
|
|
245
|
-
else
|
|
246
|
-
filter.push(options.filter);
|
|
247
|
-
}
|
|
248
|
-
return !!(await delete_command_js_1.DeleteCommand.execute({
|
|
249
|
-
...options,
|
|
250
|
-
filter,
|
|
251
|
-
entity: this._entity,
|
|
252
|
-
}));
|
|
253
|
-
}
|
|
254
|
-
async _deleteMany(options) {
|
|
255
|
-
return delete_command_js_1.DeleteCommand.execute({
|
|
256
|
-
...options,
|
|
257
|
-
entity: this._entity,
|
|
258
|
-
filter: options?.filter,
|
|
259
|
-
params: options?.params,
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
async _update(keyValue, values, options) {
|
|
263
|
-
if (!values)
|
|
264
|
-
throw new TypeError('You must provide values');
|
|
265
|
-
const keyValues = (0, extract_keyvalues_js_1.extractKeyValues)(this._entity, keyValue, true);
|
|
266
|
-
const filter = [keyValues];
|
|
267
|
-
if (options.filter) {
|
|
268
|
-
if (Array.isArray(options.filter))
|
|
269
|
-
filter.push(...options.filter);
|
|
270
|
-
else
|
|
271
|
-
filter.push(options.filter);
|
|
272
|
-
}
|
|
273
|
-
const updateValues = { ...values };
|
|
274
|
-
Object.keys(keyValues).forEach(k => delete updateValues[k]);
|
|
275
|
-
const rowsAffected = await update_command_js_1.UpdateCommand.execute({
|
|
276
|
-
...options,
|
|
277
|
-
entity: this._entity,
|
|
278
|
-
values: updateValues,
|
|
279
|
-
filter,
|
|
280
|
-
});
|
|
281
|
-
return rowsAffected ? keyValues : undefined;
|
|
282
|
-
}
|
|
283
|
-
async _updateMany(values, options) {
|
|
284
|
-
if (!values)
|
|
285
|
-
throw new TypeError('You must provide values');
|
|
286
|
-
return await update_command_js_1.UpdateCommand.execute({
|
|
287
|
-
...options,
|
|
288
|
-
entity: this._entity,
|
|
289
|
-
values,
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
exports.Repository = Repository;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.applyMixins = applyMixins;
|
|
4
|
-
function applyMixins(derivedCtor, baseCtor, filter) {
|
|
5
|
-
for (const name of Object.getOwnPropertyNames(baseCtor.prototype)) {
|
|
6
|
-
if (name === 'constructor' ||
|
|
7
|
-
name === '__proto__' ||
|
|
8
|
-
name === 'toJSON' ||
|
|
9
|
-
name === 'toString' ||
|
|
10
|
-
(filter && !filter(name))) {
|
|
11
|
-
continue;
|
|
12
|
-
}
|
|
13
|
-
Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name) ||
|
|
14
|
-
Object.create(null));
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractKeyValues = extractKeyValues;
|
|
4
|
-
const entity_metadata_js_1 = require("../model/entity-metadata.js");
|
|
5
|
-
const orm_helper_js_1 = require("./orm.helper.js");
|
|
6
|
-
function extractKeyValues(entityDef, valueOrInstance, keepOther) {
|
|
7
|
-
const primaryIndex = entity_metadata_js_1.EntityMetadata.getPrimaryIndex(entityDef);
|
|
8
|
-
if (!primaryIndex)
|
|
9
|
-
throw new Error(`No primary fields defined for "${entityDef.name}" entity`);
|
|
10
|
-
const validateCol = k => {
|
|
11
|
-
const col = entity_metadata_js_1.EntityMetadata.getField(entityDef, k);
|
|
12
|
-
if (!col)
|
|
13
|
-
throw new Error(`Unknown column (${k}) defined as primary key in entity "${entityDef.name}"`);
|
|
14
|
-
if (!(0, orm_helper_js_1.isColumnField)(col)) {
|
|
15
|
-
throw new Error(`Column (${k}) defined as primary key in entity "${entityDef.name}" is not a data column`);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
// if entity's primary key has more than one key field
|
|
19
|
-
if (primaryIndex.columns.length > 1) {
|
|
20
|
-
if (typeof valueOrInstance !== 'object') {
|
|
21
|
-
throw new Error(`"${entityDef.name}" entity` +
|
|
22
|
-
` has more than one primary key field and you must provide all values with an key/value pair`);
|
|
23
|
-
}
|
|
24
|
-
const valueKeys = Object.keys(valueOrInstance);
|
|
25
|
-
const valueKeysUpper = valueKeys.map(x => x.toUpperCase());
|
|
26
|
-
const out = {};
|
|
27
|
-
for (const k of primaryIndex.columns) {
|
|
28
|
-
const i = valueKeysUpper.indexOf(k.toUpperCase());
|
|
29
|
-
if (i < 0)
|
|
30
|
-
throw new Error(`Value of key field "${entityDef.name}.${k}" required to perform this operation`);
|
|
31
|
-
validateCol(k);
|
|
32
|
-
out[k] = valueOrInstance[valueKeys[i]];
|
|
33
|
-
}
|
|
34
|
-
if (keepOther) {
|
|
35
|
-
for (let i = 0; i < valueKeys.length; i++) {
|
|
36
|
-
if (primaryIndex.columns.find(x => x.toUpperCase() === valueKeysUpper[i]))
|
|
37
|
-
continue;
|
|
38
|
-
out[valueKeys[i]] = valueOrInstance[valueKeys[i]];
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return out;
|
|
42
|
-
}
|
|
43
|
-
const primaryColumnName = primaryIndex.columns[0];
|
|
44
|
-
validateCol(primaryColumnName);
|
|
45
|
-
if (typeof valueOrInstance === 'object') {
|
|
46
|
-
const valueKeys = Object.keys(valueOrInstance);
|
|
47
|
-
const valueKeysUpper = valueKeys.map(x => x.toUpperCase());
|
|
48
|
-
const k = valueKeysUpper.indexOf(primaryColumnName.toUpperCase());
|
|
49
|
-
if (k < 0) {
|
|
50
|
-
throw new Error(`Value of key field "${entityDef.name}.${primaryColumnName}" required to perform this operation`);
|
|
51
|
-
}
|
|
52
|
-
const out = { [primaryColumnName]: valueOrInstance[valueKeys[k]] };
|
|
53
|
-
if (keepOther) {
|
|
54
|
-
for (let i = 0; i < valueKeys.length; i++) {
|
|
55
|
-
if (primaryIndex.columns.find(x => x.toUpperCase() === valueKeysUpper[i]))
|
|
56
|
-
continue;
|
|
57
|
-
out[valueKeys[i]] = valueOrInstance[valueKeys[i]];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return out;
|
|
61
|
-
}
|
|
62
|
-
return { [primaryColumnName]: valueOrInstance };
|
|
63
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isAssociationField = exports.isEmbeddedField = void 0;
|
|
4
|
-
exports.isClass = isClass;
|
|
5
|
-
exports.isEntityClass = isEntityClass;
|
|
6
|
-
exports.isColumnField = isColumnField;
|
|
7
|
-
exports.resolveEntity = resolveEntity;
|
|
8
|
-
exports.resolveEntityMeta = resolveEntityMeta;
|
|
9
|
-
const orm_const_js_1 = require("../orm.const.js");
|
|
10
|
-
function isClass(fn) {
|
|
11
|
-
return typeof fn === 'function' && /^\s*class/.test(fn.toString());
|
|
12
|
-
}
|
|
13
|
-
function isEntityClass(fn) {
|
|
14
|
-
return isClass(fn) && Reflect.hasMetadata(orm_const_js_1.ENTITY_METADATA_KEY, fn);
|
|
15
|
-
}
|
|
16
|
-
function isColumnField(f) {
|
|
17
|
-
return !!(f && f.name && f.kind === 'column');
|
|
18
|
-
}
|
|
19
|
-
const isEmbeddedField = (f) => !!(f && f.name && f.kind === 'object');
|
|
20
|
-
exports.isEmbeddedField = isEmbeddedField;
|
|
21
|
-
const isAssociationField = (f) => !!(f && f.name && f.kind === 'association');
|
|
22
|
-
exports.isAssociationField = isAssociationField;
|
|
23
|
-
async function resolveEntity(ctorThunk) {
|
|
24
|
-
if (typeof ctorThunk !== 'function')
|
|
25
|
-
return;
|
|
26
|
-
if (!isClass(ctorThunk))
|
|
27
|
-
ctorThunk = await ctorThunk();
|
|
28
|
-
if (isEntityClass(ctorThunk))
|
|
29
|
-
return ctorThunk;
|
|
30
|
-
}
|
|
31
|
-
async function resolveEntityMeta(ctorThunk) {
|
|
32
|
-
const ctor = await resolveEntity(ctorThunk);
|
|
33
|
-
return ctor && Reflect.getMetadata(orm_const_js_1.ENTITY_METADATA_KEY, ctor);
|
|
34
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FieldsProjection = void 0;
|
|
4
|
-
exports.parseFieldsProjection = parseFieldsProjection;
|
|
5
|
-
const fast_tokenizer_1 = require("fast-tokenizer");
|
|
6
|
-
const FIELD_PATTERN = /^([+-])?([a-z_$]\w*)$/i;
|
|
7
|
-
const NO_DOT_BRACKET_PATTERN = /[^.]\(/g;
|
|
8
|
-
class FieldsProjection {
|
|
9
|
-
}
|
|
10
|
-
exports.FieldsProjection = FieldsProjection;
|
|
11
|
-
(function (FieldsProjection) {
|
|
12
|
-
class Item {
|
|
13
|
-
sign;
|
|
14
|
-
projection;
|
|
15
|
-
}
|
|
16
|
-
FieldsProjection.Item = Item;
|
|
17
|
-
})(FieldsProjection || (exports.FieldsProjection = FieldsProjection = {}));
|
|
18
|
-
function parseFieldsProjection(projection, keepCase) {
|
|
19
|
-
const arr = Array.isArray(projection) ? projection : [projection];
|
|
20
|
-
if (!(arr && arr.length))
|
|
21
|
-
return;
|
|
22
|
-
const out = new FieldsProjection();
|
|
23
|
-
for (let s of arr) {
|
|
24
|
-
if (!keepCase)
|
|
25
|
-
s = s.toLowerCase();
|
|
26
|
-
parse(s, out);
|
|
27
|
-
}
|
|
28
|
-
return out;
|
|
29
|
-
}
|
|
30
|
-
function parse(input, target) {
|
|
31
|
-
/** Add dot before brackets which is required to split fields */
|
|
32
|
-
input = input.replace(NO_DOT_BRACKET_PATTERN, s => s.charAt(0) + '.' + s.substring(1));
|
|
33
|
-
const fields = (0, fast_tokenizer_1.splitString)(input, {
|
|
34
|
-
delimiters: '.',
|
|
35
|
-
brackets: true,
|
|
36
|
-
keepBrackets: false,
|
|
37
|
-
});
|
|
38
|
-
for (let i = 0; i < fields.length; i++) {
|
|
39
|
-
const f = fields[i];
|
|
40
|
-
if (f.includes(',')) {
|
|
41
|
-
const subFields = (0, fast_tokenizer_1.splitString)(f, {
|
|
42
|
-
delimiters: ',',
|
|
43
|
-
brackets: true,
|
|
44
|
-
keepBrackets: true,
|
|
45
|
-
});
|
|
46
|
-
for (const n of subFields) {
|
|
47
|
-
parse(n, target);
|
|
48
|
-
}
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
const m = FIELD_PATTERN.exec(f);
|
|
52
|
-
/* istanbul ignore next */
|
|
53
|
-
if (!m)
|
|
54
|
-
throw new TypeError(`Invalid field path (${input})`);
|
|
55
|
-
const fieldName = m[2];
|
|
56
|
-
const treeItem = (target[fieldName] =
|
|
57
|
-
target[fieldName] || new FieldsProjection.Item());
|
|
58
|
-
if (m[1])
|
|
59
|
-
treeItem.sign = m[1];
|
|
60
|
-
if (i === fields.length - 1) {
|
|
61
|
-
delete treeItem.projection;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
target = treeItem.projection =
|
|
65
|
-
treeItem.projection || new FieldsProjection();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.serializeColumn = serializeColumn;
|
|
4
|
-
const builder_1 = require("@sqb/builder");
|
|
5
|
-
const orm_helper_js_1 = require("./orm.helper.js");
|
|
6
|
-
function serializeColumn(col, v) {
|
|
7
|
-
if ((0, orm_helper_js_1.isColumnField)(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
|
-
const padZero = (n) => (n < 9 ? '0' : '') + n;
|
|
20
|
-
function serializeDataValue(dataType, v) {
|
|
21
|
-
if (v == null)
|
|
22
|
-
return;
|
|
23
|
-
if (v instanceof Date &&
|
|
24
|
-
(dataType === builder_1.DataType.DATE || dataType === builder_1.DataType.TIMESTAMP)) {
|
|
25
|
-
return (v.getFullYear() +
|
|
26
|
-
'-' +
|
|
27
|
-
padZero(v.getMonth() + 1) +
|
|
28
|
-
'-' +
|
|
29
|
-
padZero(v.getDate()) +
|
|
30
|
-
(dataType === builder_1.DataType.TIMESTAMP
|
|
31
|
-
? 'T' +
|
|
32
|
-
padZero(v.getHours()) +
|
|
33
|
-
':' +
|
|
34
|
-
padZero(v.getMinutes()) +
|
|
35
|
-
':' +
|
|
36
|
-
padZero(v.getSeconds())
|
|
37
|
-
: ''));
|
|
38
|
-
}
|
|
39
|
-
if (v instanceof Buffer)
|
|
40
|
-
return v.toString('base64');
|
|
41
|
-
if (typeof v === 'number' &&
|
|
42
|
-
(dataType === builder_1.DataType.SMALLINT || dataType === builder_1.DataType.INTEGER))
|
|
43
|
-
return Math.trunc(v);
|
|
44
|
-
if (typeof v === 'bigint')
|
|
45
|
-
return v.toString();
|
|
46
|
-
if (v && typeof v === 'object' && typeof v.toJSON === 'function')
|
|
47
|
-
return v.toJSON();
|
|
48
|
-
return v;
|
|
49
|
-
}
|
package/cjs/package.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
export var AssociationFieldMetadata;
|
|
3
|
-
(function (AssociationFieldMetadata) {
|
|
4
|
-
function create(entity, name, association, options = {}) {
|
|
5
|
-
const result = {
|
|
6
|
-
kind: 'association',
|
|
7
|
-
entity,
|
|
8
|
-
name,
|
|
9
|
-
association,
|
|
10
|
-
};
|
|
11
|
-
if (options)
|
|
12
|
-
AssociationFieldMetadata.assign(result, options);
|
|
13
|
-
return result;
|
|
14
|
-
}
|
|
15
|
-
AssociationFieldMetadata.create = create;
|
|
16
|
-
function assign(target, options) {
|
|
17
|
-
Object.assign(target, _.omit(options, ['entity', 'name', 'kind', 'association']));
|
|
18
|
-
}
|
|
19
|
-
AssociationFieldMetadata.assign = assign;
|
|
20
|
-
})(AssociationFieldMetadata || (AssociationFieldMetadata = {}));
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
export var ColumnFieldMetadata;
|
|
3
|
-
(function (ColumnFieldMetadata) {
|
|
4
|
-
function create(entity, name, options = {}) {
|
|
5
|
-
const result = {
|
|
6
|
-
kind: 'column',
|
|
7
|
-
entity,
|
|
8
|
-
name,
|
|
9
|
-
fieldName: name,
|
|
10
|
-
};
|
|
11
|
-
if (options)
|
|
12
|
-
ColumnFieldMetadata.assign(result, options);
|
|
13
|
-
return result;
|
|
14
|
-
}
|
|
15
|
-
ColumnFieldMetadata.create = create;
|
|
16
|
-
function assign(target, options) {
|
|
17
|
-
Object.assign(target, _.omit(options, ['entity', 'name', 'kind']));
|
|
18
|
-
}
|
|
19
|
-
ColumnFieldMetadata.assign = assign;
|
|
20
|
-
function checkEnumValue(col, v) {
|
|
21
|
-
if (v === undefined || !col.enum || (v == null && !col.notNull))
|
|
22
|
-
return;
|
|
23
|
-
const enumKeys = Array.isArray(col.enum) ? col.enum : Object.keys(col.enum);
|
|
24
|
-
if (!enumKeys.includes(v))
|
|
25
|
-
throw new Error(`${col.entity.name}.${col.name} value must be one of (${enumKeys})`);
|
|
26
|
-
}
|
|
27
|
-
ColumnFieldMetadata.checkEnumValue = checkEnumValue;
|
|
28
|
-
})(ColumnFieldMetadata || (ColumnFieldMetadata = {}));
|
package/esm/package.json
DELETED
package/types/index.d.cts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
export * from './client/adapter.js';
|
|
3
|
-
export * from './client/cursor.js';
|
|
4
|
-
export * from './client/extensions.js';
|
|
5
|
-
export * from './client/sqb-client.js';
|
|
6
|
-
export * from './client/sqb-connection.js';
|
|
7
|
-
export * from './client/sqb-error.js';
|
|
8
|
-
export * from './client/types.js';
|
|
9
|
-
export * from './orm/backward.js';
|
|
10
|
-
export * from './orm/base-entity.js';
|
|
11
|
-
export * from './orm/decorators/column.decorator.js';
|
|
12
|
-
export * from './orm/decorators/embedded.decorator.js';
|
|
13
|
-
export * from './orm/decorators/entity.decorator.js';
|
|
14
|
-
export * from './orm/decorators/events.decorator.js';
|
|
15
|
-
export * from './orm/decorators/foreignkey.decorator.js';
|
|
16
|
-
export * from './orm/decorators/index.decorator.js';
|
|
17
|
-
export * from './orm/decorators/link.decorator.js';
|
|
18
|
-
export * from './orm/decorators/primarykey.decorator.js';
|
|
19
|
-
export * from './orm/decorators/transform.decorator.js';
|
|
20
|
-
export * from './orm/model/association.js';
|
|
21
|
-
export * from './orm/model/association-field-metadata.js';
|
|
22
|
-
export * from './orm/model/association-node.js';
|
|
23
|
-
export * from './orm/model/column-field-metadata.js';
|
|
24
|
-
export * from './orm/model/embedded-field-metadata.js';
|
|
25
|
-
export * from './orm/model/entity-metadata.js';
|
|
26
|
-
export * from './orm/model/field-metadata.js';
|
|
27
|
-
export * from './orm/model/index-metadata.js';
|
|
28
|
-
export * from './orm/model/link-chain.js';
|
|
29
|
-
export * from './orm/orm.const.js';
|
|
30
|
-
export * from './orm/orm.type.js';
|
|
31
|
-
export * from './orm/repository.class.js';
|
|
32
|
-
export { isAssociationField, isColumnField, isEmbeddedField, isEntityClass, } from './orm/util/orm.helper.js';
|
|
33
|
-
export * from './orm/util/parse-fields-projection.js';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|