@sqb/connect 4.14.1 → 4.15.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.
Files changed (47) hide show
  1. package/esm/client/adapter.js +2 -1
  2. package/esm/client/cursor-stream.js +9 -4
  3. package/esm/client/cursor.js +22 -17
  4. package/esm/client/extensions.js +5 -1
  5. package/esm/client/field-info-map.js +5 -1
  6. package/esm/client/helpers.js +19 -12
  7. package/esm/client/sqb-client.js +32 -27
  8. package/esm/client/sqb-connection.js +41 -36
  9. package/esm/client/types.js +5 -1
  10. package/esm/index.js +40 -32
  11. package/esm/orm/backward.js +19 -12
  12. package/esm/orm/base-entity.js +10 -6
  13. package/esm/orm/commands/command.helper.js +34 -28
  14. package/esm/orm/commands/count.command.js +10 -6
  15. package/esm/orm/commands/create.command.js +18 -14
  16. package/esm/orm/commands/delete.command.js +10 -6
  17. package/esm/orm/commands/find.command.js +34 -30
  18. package/esm/orm/commands/row-converter.js +7 -3
  19. package/esm/orm/commands/update.command.js +18 -14
  20. package/esm/orm/decorators/column.decorator.js +10 -7
  21. package/esm/orm/decorators/embedded.decorator.js +7 -4
  22. package/esm/orm/decorators/entity.decorator.js +56 -53
  23. package/esm/orm/decorators/events.decorator.js +27 -19
  24. package/esm/orm/decorators/foreignkey.decorator.js +7 -4
  25. package/esm/orm/decorators/index.decorator.js +9 -6
  26. package/esm/orm/decorators/link.decorator.js +11 -8
  27. package/esm/orm/decorators/primarykey.decorator.js +11 -8
  28. package/esm/orm/decorators/transform.decorator.js +11 -7
  29. package/esm/orm/model/association-field-metadata.js +8 -4
  30. package/esm/orm/model/association-node.js +6 -2
  31. package/esm/orm/model/association.js +20 -16
  32. package/esm/orm/model/column-field-metadata.js +8 -4
  33. package/esm/orm/model/embedded-field-metadata.js +7 -4
  34. package/esm/orm/model/entity-metadata.js +50 -47
  35. package/esm/orm/model/field-metadata.js +2 -1
  36. package/esm/orm/model/index-metadata.js +2 -1
  37. package/esm/orm/model/link-chain.js +8 -4
  38. package/esm/orm/orm.const.js +6 -3
  39. package/esm/orm/orm.type.js +2 -1
  40. package/esm/orm/repository.class.js +26 -22
  41. package/esm/orm/util/apply-mixins.js +4 -1
  42. package/esm/orm/util/extract-keyvalues.js +9 -6
  43. package/esm/orm/util/orm.helper.js +20 -10
  44. package/esm/orm/util/parse-fields-projection.js +11 -6
  45. package/esm/orm/util/serialize-field.js +13 -10
  46. package/package.json +28 -22
  47. package/cjs/package.json +0 -3
@@ -1,11 +1,14 @@
1
- import { DataType } from '@sqb/builder';
2
- import { ENTITY_METADATA_KEY } from '../orm.const.js';
3
- import { isAssociationField, isColumnField, isEmbeddedField } from '../util/orm.helper.js';
4
- import { Association } from './association.js';
5
- import { AssociationFieldMetadata } from './association-field-metadata.js';
6
- import { ColumnFieldMetadata } from './column-field-metadata.js';
7
- import { EmbeddedFieldMetadata } from './embedded-field-metadata.js';
8
- export var EntityMetadata;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EntityMetadata = void 0;
4
+ const builder_1 = require("@sqb/builder");
5
+ const orm_const_js_1 = require("../orm.const.js");
6
+ const orm_helper_js_1 = require("../util/orm.helper.js");
7
+ const association_js_1 = require("./association.js");
8
+ const association_field_metadata_js_1 = require("./association-field-metadata.js");
9
+ const column_field_metadata_js_1 = require("./column-field-metadata.js");
10
+ const embedded_field_metadata_js_1 = require("./embedded-field-metadata.js");
11
+ var EntityMetadata;
9
12
  (function (EntityMetadata) {
10
13
  function define(ctor) {
11
14
  const own = getOwn(ctor);
@@ -20,7 +23,7 @@ export var EntityMetadata;
20
23
  foreignKeys: [],
21
24
  eventListeners: {},
22
25
  };
23
- Reflect.defineMetadata(ENTITY_METADATA_KEY, meta, ctor);
26
+ Reflect.defineMetadata(orm_const_js_1.ENTITY_METADATA_KEY, meta, ctor);
24
27
  // Merge base entity columns into this one
25
28
  if (baseMeta) {
26
29
  EntityMetadata.mixin(meta, baseMeta);
@@ -29,11 +32,11 @@ export var EntityMetadata;
29
32
  }
30
33
  EntityMetadata.define = define;
31
34
  function get(ctor) {
32
- return Reflect.getMetadata(ENTITY_METADATA_KEY, ctor);
35
+ return Reflect.getMetadata(orm_const_js_1.ENTITY_METADATA_KEY, ctor);
33
36
  }
34
37
  EntityMetadata.get = get;
35
38
  function getOwn(ctor) {
36
- return Reflect.getOwnMetadata(ENTITY_METADATA_KEY, ctor);
39
+ return Reflect.getOwnMetadata(orm_const_js_1.ENTITY_METADATA_KEY, ctor);
37
40
  }
38
41
  EntityMetadata.getOwn = getOwn;
39
42
  function getField(entity, fieldName) {
@@ -42,21 +45,21 @@ export var EntityMetadata;
42
45
  EntityMetadata.getField = getField;
43
46
  function getColumnField(entity, fieldName) {
44
47
  const el = getField(entity, fieldName);
45
- if (el && !isColumnField(el))
48
+ if (el && !(0, orm_helper_js_1.isColumnField)(el))
46
49
  throw new Error(`"${el.name}" requested as "column" but it is "${el.kind}"`);
47
50
  return el;
48
51
  }
49
52
  EntityMetadata.getColumnField = getColumnField;
50
53
  function getEmbeddedField(entity, fieldName) {
51
54
  const el = getField(entity, fieldName);
52
- if (el && !isEmbeddedField(el))
55
+ if (el && !(0, orm_helper_js_1.isEmbeddedField)(el))
53
56
  throw new Error(`"${el.name}" requested as "embedded" but it is "${el.kind}"`);
54
57
  return el;
55
58
  }
56
59
  EntityMetadata.getEmbeddedField = getEmbeddedField;
57
60
  function getAssociationField(entity, fieldName) {
58
61
  const el = getField(entity, fieldName);
59
- if (el && !isAssociationField(el)) {
62
+ if (el && !(0, orm_helper_js_1.isAssociationField)(el)) {
60
63
  throw new Error(`"${el.name}" requested as "association" but it is "${el.kind}"`);
61
64
  }
62
65
  return el;
@@ -71,7 +74,7 @@ export var EntityMetadata;
71
74
  return;
72
75
  fieldName = fieldName.toLowerCase();
73
76
  for (const prop of Object.values(entity.fields)) {
74
- if (isColumnField(prop) && prop.fieldName.toLowerCase() === fieldName)
77
+ if ((0, orm_helper_js_1.isColumnField)(prop) && prop.fieldName.toLowerCase() === fieldName)
75
78
  return prop;
76
79
  }
77
80
  }
@@ -98,27 +101,27 @@ export var EntityMetadata;
98
101
  }
99
102
  EntityMetadata.getFieldNames = getFieldNames;
100
103
  function getColumnFieldNames(entity) {
101
- return getFieldNames(entity, isColumnField);
104
+ return getFieldNames(entity, orm_helper_js_1.isColumnField);
102
105
  }
103
106
  EntityMetadata.getColumnFieldNames = getColumnFieldNames;
104
107
  function getEmbeddedFieldNames(entity) {
105
- return getFieldNames(entity, isEmbeddedField);
108
+ return getFieldNames(entity, orm_helper_js_1.isEmbeddedField);
106
109
  }
107
110
  EntityMetadata.getEmbeddedFieldNames = getEmbeddedFieldNames;
108
111
  function getAssociationFieldNames(entity) {
109
- return getFieldNames(entity, isAssociationField);
112
+ return getFieldNames(entity, orm_helper_js_1.isAssociationField);
110
113
  }
111
114
  EntityMetadata.getAssociationFieldNames = getAssociationFieldNames;
112
115
  function getNonAssociationFieldNames(entity) {
113
- return getFieldNames(entity, x => !isAssociationField(x));
116
+ return getFieldNames(entity, x => !(0, orm_helper_js_1.isAssociationField)(x));
114
117
  }
115
118
  EntityMetadata.getNonAssociationFieldNames = getNonAssociationFieldNames;
116
119
  function getInsertColumnNames(entity) {
117
- return getFieldNames(entity, x => isColumnField(x) && !x.noInsert);
120
+ return getFieldNames(entity, x => (0, orm_helper_js_1.isColumnField)(x) && !x.noInsert);
118
121
  }
119
122
  EntityMetadata.getInsertColumnNames = getInsertColumnNames;
120
123
  function getUpdateColumnNames(entity) {
121
- return getFieldNames(entity, x => isColumnField(x) && !x.noUpdate);
124
+ return getFieldNames(entity, x => (0, orm_helper_js_1.isColumnField)(x) && !x.noUpdate);
122
125
  }
123
126
  EntityMetadata.getUpdateColumnNames = getUpdateColumnNames;
124
127
  function getPrimaryIndex(entity) {
@@ -161,7 +164,7 @@ export var EntityMetadata;
161
164
  EntityMetadata.addIndex = addIndex;
162
165
  function addForeignKey(entity, propertyKey, target, targetKey) {
163
166
  entity.foreignKeys = entity.foreignKeys || [];
164
- const fk = new Association(entity.name + '.' + propertyKey, {
167
+ const fk = new association_js_1.Association(entity.name + '.' + propertyKey, {
165
168
  source: entity.ctor,
166
169
  sourceKey: propertyKey,
167
170
  target,
@@ -181,30 +184,30 @@ export var EntityMetadata;
181
184
  function defineColumnField(entity, name, options = {}) {
182
185
  delete entity._fieldNames;
183
186
  let prop = EntityMetadata.getField(entity, name);
184
- if (isColumnField(prop))
187
+ if ((0, orm_helper_js_1.isColumnField)(prop))
185
188
  options = { ...prop, ...options };
186
189
  if (!options.type) {
187
190
  switch (options.dataType) {
188
- case DataType.BOOL:
191
+ case builder_1.DataType.BOOL:
189
192
  options.type = Boolean;
190
193
  break;
191
- case DataType.VARCHAR:
192
- case DataType.CHAR:
193
- case DataType.TEXT:
194
+ case builder_1.DataType.VARCHAR:
195
+ case builder_1.DataType.CHAR:
196
+ case builder_1.DataType.TEXT:
194
197
  options.type = String;
195
198
  break;
196
- case DataType.NUMBER:
197
- case DataType.DOUBLE:
198
- case DataType.FLOAT:
199
- case DataType.INTEGER:
200
- case DataType.SMALLINT:
199
+ case builder_1.DataType.NUMBER:
200
+ case builder_1.DataType.DOUBLE:
201
+ case builder_1.DataType.FLOAT:
202
+ case builder_1.DataType.INTEGER:
203
+ case builder_1.DataType.SMALLINT:
201
204
  options.type = Number;
202
205
  break;
203
- case DataType.TIMESTAMP:
204
- case DataType.TIMESTAMPTZ:
206
+ case builder_1.DataType.TIMESTAMP:
207
+ case builder_1.DataType.TIMESTAMPTZ:
205
208
  options.type = Date;
206
209
  break;
207
- case DataType.BINARY:
210
+ case builder_1.DataType.BINARY:
208
211
  options.type = Buffer;
209
212
  break;
210
213
  default:
@@ -214,26 +217,26 @@ export var EntityMetadata;
214
217
  if (!options.dataType) {
215
218
  switch (options.type) {
216
219
  case Boolean:
217
- options.dataType = DataType.BOOL;
220
+ options.dataType = builder_1.DataType.BOOL;
218
221
  break;
219
222
  case Number:
220
- options.dataType = DataType.NUMBER;
223
+ options.dataType = builder_1.DataType.NUMBER;
221
224
  break;
222
225
  case Date:
223
- options.dataType = DataType.TIMESTAMP;
226
+ options.dataType = builder_1.DataType.TIMESTAMP;
224
227
  break;
225
228
  case Array:
226
- options.dataType = DataType.VARCHAR;
229
+ options.dataType = builder_1.DataType.VARCHAR;
227
230
  options.isArray = true;
228
231
  break;
229
232
  case Buffer:
230
- options.dataType = DataType.BINARY;
233
+ options.dataType = builder_1.DataType.BINARY;
231
234
  break;
232
235
  default:
233
- options.dataType = DataType.VARCHAR;
236
+ options.dataType = builder_1.DataType.VARCHAR;
234
237
  }
235
238
  }
236
- prop = ColumnFieldMetadata.create(entity, name, options);
239
+ prop = column_field_metadata_js_1.ColumnFieldMetadata.create(entity, name, options);
237
240
  entity.fields[name.toLowerCase()] = prop;
238
241
  return prop;
239
242
  }
@@ -241,16 +244,16 @@ export var EntityMetadata;
241
244
  function defineEmbeddedField(entity, name, type, options) {
242
245
  delete entity._fieldNames;
243
246
  let prop = EntityMetadata.getField(entity, name);
244
- if (isEmbeddedField(prop))
247
+ if ((0, orm_helper_js_1.isEmbeddedField)(prop))
245
248
  options = { ...prop, ...options };
246
- prop = EmbeddedFieldMetadata.create(entity, name, type, options);
249
+ prop = embedded_field_metadata_js_1.EmbeddedFieldMetadata.create(entity, name, type, options);
247
250
  entity.fields[name.toLowerCase()] = prop;
248
251
  return prop;
249
252
  }
250
253
  EntityMetadata.defineEmbeddedField = defineEmbeddedField;
251
254
  function defineAssociationField(entity, propertyKey, association, options) {
252
255
  delete entity._fieldNames;
253
- const prop = AssociationFieldMetadata.create(entity, propertyKey, association, options);
256
+ const prop = association_field_metadata_js_1.AssociationFieldMetadata.create(entity, propertyKey, association, options);
254
257
  let l = association;
255
258
  let i = 1;
256
259
  while (l) {
@@ -295,7 +298,7 @@ export var EntityMetadata;
295
298
  derived.foreignKeys = derived.foreignKeys || [];
296
299
  for (const fk of base.foreignKeys) {
297
300
  if (!fk.sourceKey || hasField(fk.sourceKey)) {
298
- const newFk = new Association(fk.name, { ...fk, source: derived.ctor });
301
+ const newFk = new association_js_1.Association(fk.name, { ...fk, source: derived.ctor });
299
302
  derived.foreignKeys.push(newFk);
300
303
  }
301
304
  }
@@ -318,4 +321,4 @@ export var EntityMetadata;
318
321
  }
319
322
  }
320
323
  EntityMetadata.mixin = mixin;
321
- })(EntityMetadata || (EntityMetadata = {}));
324
+ })(EntityMetadata || (exports.EntityMetadata = EntityMetadata = {}));
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,8 +1,11 @@
1
- import { AssociationNode } from './association-node.js';
2
- export class LinkChain {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LinkChain = void 0;
4
+ const association_node_js_1 = require("./association-node.js");
5
+ class LinkChain {
3
6
  constructor(target, targetKey, sourceKey, many) {
4
7
  this.target = target;
5
- this.first = this.current = new AssociationNode('', {
8
+ this.first = this.current = new association_node_js_1.AssociationNode('', {
6
9
  many,
7
10
  target,
8
11
  source: null,
@@ -25,7 +28,7 @@ export class LinkChain {
25
28
  return this._newNode(target, targetColumn, parentColumn, true);
26
29
  }
27
30
  _newNode(target, targetKey, parentKey, many = false) {
28
- const child = new AssociationNode(this.current.name, {
31
+ const child = new association_node_js_1.AssociationNode(this.current.name, {
29
32
  many,
30
33
  source: this.current.target,
31
34
  target,
@@ -38,3 +41,4 @@ export class LinkChain {
38
41
  return this;
39
42
  }
40
43
  }
44
+ exports.LinkChain = LinkChain;
@@ -1,3 +1,6 @@
1
- export const ENTITY_METADATA_KEY = Symbol.for('SQB_ENTITY_METADATA');
2
- export const REPOSITORY_KEY = Symbol.for('SQB_REPOSITORY');
3
- export const DECORATOR_FACTORY = Symbol.for('decorator.factory');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DECORATOR_FACTORY = exports.REPOSITORY_KEY = exports.ENTITY_METADATA_KEY = void 0;
4
+ exports.ENTITY_METADATA_KEY = Symbol.for('SQB_ENTITY_METADATA');
5
+ exports.REPOSITORY_KEY = Symbol.for('SQB_REPOSITORY');
6
+ exports.DECORATOR_FACTORY = Symbol.for('decorator.factory');
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,16 +1,19 @@
1
- import { AsyncEventEmitter, TypedEventEmitterClass } from 'strict-typed-events';
2
- import { SqbConnection } from '../client/sqb-connection.js';
3
- import { CountCommand } from './commands/count.command.js';
4
- import { CreateCommand } from './commands/create.command.js';
5
- import { DeleteCommand } from './commands/delete.command.js';
6
- import { FindCommand } from './commands/find.command.js';
7
- import { UpdateCommand } from './commands/update.command.js';
8
- import { extractKeyValues } from './util/extract-keyvalues.js';
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 extract_keyvalues_js_1 = require("./util/extract-keyvalues.js");
9
12
  /**
10
13
  * @class Repository
11
14
  * @template T - The data type class type of the record
12
15
  */
13
- export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
16
+ class Repository extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict_typed_events_1.AsyncEventEmitter) {
14
17
  constructor(entityDef, executor, schema) {
15
18
  super();
16
19
  this._executor = executor;
@@ -134,7 +137,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
134
137
  }
135
138
  async _execute(fn, opts) {
136
139
  let connection = opts?.connection;
137
- if (!connection && this._executor instanceof SqbConnection)
140
+ if (!connection && this._executor instanceof sqb_connection_js_1.SqbConnection)
138
141
  connection = this._executor;
139
142
  if (connection) {
140
143
  if (this._schema)
@@ -151,7 +154,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
151
154
  async _create(values, options) {
152
155
  if (!values)
153
156
  throw new TypeError('You must provide values');
154
- const keyValues = await CreateCommand.execute({
157
+ const keyValues = await create_command_js_1.CreateCommand.execute({
155
158
  ...options,
156
159
  entity: this._entity,
157
160
  values,
@@ -161,7 +164,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
161
164
  return keyValues;
162
165
  }
163
166
  async _exists(keyValue, options) {
164
- const filter = [extractKeyValues(this._entity, keyValue, true)];
167
+ const filter = [(0, extract_keyvalues_js_1.extractKeyValues)(this._entity, keyValue, true)];
165
168
  if (options && options.filter) {
166
169
  if (Array.isArray(options.filter))
167
170
  filter.push(...options.filter);
@@ -181,7 +184,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
181
184
  else
182
185
  filter.push(options.filter);
183
186
  }
184
- const resp = await FindCommand.execute({
187
+ const resp = await find_command_js_1.FindCommand.execute({
185
188
  ...options,
186
189
  filter,
187
190
  entity: this._entity,
@@ -189,13 +192,13 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
189
192
  return resp.length > 0;
190
193
  }
191
194
  async _count(options) {
192
- return CountCommand.execute({
195
+ return count_command_js_1.CountCommand.execute({
193
196
  ...options,
194
197
  entity: this._entity,
195
198
  });
196
199
  }
197
200
  async _findMany(options) {
198
- return await FindCommand.execute({
201
+ return await find_command_js_1.FindCommand.execute({
199
202
  ...options,
200
203
  entity: this._entity,
201
204
  });
@@ -208,7 +211,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
208
211
  return rows && rows[0];
209
212
  }
210
213
  async _find(keyValue, options) {
211
- const filter = [extractKeyValues(this._entity, keyValue, true)];
214
+ const filter = [(0, extract_keyvalues_js_1.extractKeyValues)(this._entity, keyValue, true)];
212
215
  if (options && options.filter) {
213
216
  if (Array.isArray(options.filter))
214
217
  filter.push(...options.filter);
@@ -218,21 +221,21 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
218
221
  return await this._findOne({ ...options, filter, offset: 0 });
219
222
  }
220
223
  async _delete(keyValue, options) {
221
- const filter = [extractKeyValues(this._entity, keyValue, true)];
224
+ const filter = [(0, extract_keyvalues_js_1.extractKeyValues)(this._entity, keyValue, true)];
222
225
  if (options && options.filter) {
223
226
  if (Array.isArray(options.filter))
224
227
  filter.push(...options.filter);
225
228
  else
226
229
  filter.push(options.filter);
227
230
  }
228
- return !!(await DeleteCommand.execute({
231
+ return !!(await delete_command_js_1.DeleteCommand.execute({
229
232
  ...options,
230
233
  filter,
231
234
  entity: this._entity,
232
235
  }));
233
236
  }
234
237
  async _deleteMany(options) {
235
- return DeleteCommand.execute({
238
+ return delete_command_js_1.DeleteCommand.execute({
236
239
  ...options,
237
240
  entity: this._entity,
238
241
  filter: options?.filter,
@@ -242,7 +245,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
242
245
  async _update(keyValue, values, options) {
243
246
  if (!values)
244
247
  throw new TypeError('You must provide values');
245
- const keyValues = extractKeyValues(this._entity, keyValue, true);
248
+ const keyValues = (0, extract_keyvalues_js_1.extractKeyValues)(this._entity, keyValue, true);
246
249
  const filter = [keyValues];
247
250
  if (options.filter) {
248
251
  if (Array.isArray(options.filter))
@@ -252,7 +255,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
252
255
  }
253
256
  const updateValues = { ...values };
254
257
  Object.keys(keyValues).forEach(k => delete updateValues[k]);
255
- const rowsAffected = await UpdateCommand.execute({
258
+ const rowsAffected = await update_command_js_1.UpdateCommand.execute({
256
259
  ...options,
257
260
  entity: this._entity,
258
261
  values: updateValues,
@@ -263,10 +266,11 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
263
266
  async _updateMany(values, options) {
264
267
  if (!values)
265
268
  throw new TypeError('You must provide values');
266
- return await UpdateCommand.execute({
269
+ return await update_command_js_1.UpdateCommand.execute({
267
270
  ...options,
268
271
  entity: this._entity,
269
272
  values,
270
273
  });
271
274
  }
272
275
  }
276
+ exports.Repository = Repository;
@@ -1,4 +1,7 @@
1
- export function applyMixins(derivedCtor, baseCtor, filter) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyMixins = applyMixins;
4
+ function applyMixins(derivedCtor, baseCtor, filter) {
2
5
  for (const name of Object.getOwnPropertyNames(baseCtor.prototype)) {
3
6
  if (name === 'constructor' ||
4
7
  name === '__proto__' ||
@@ -1,14 +1,17 @@
1
- import { EntityMetadata } from '../model/entity-metadata.js';
2
- import { isColumnField } from './orm.helper.js';
3
- export function extractKeyValues(entityDef, valueOrInstance, keepOther) {
4
- const primaryIndex = EntityMetadata.getPrimaryIndex(entityDef);
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);
5
8
  if (!primaryIndex)
6
9
  throw new Error(`No primary fields defined for "${entityDef.name}" entity`);
7
10
  const validateCol = k => {
8
- const col = EntityMetadata.getField(entityDef, k);
11
+ const col = entity_metadata_js_1.EntityMetadata.getField(entityDef, k);
9
12
  if (!col)
10
13
  throw new Error(`Unknown column (${k}) defined as primary key in entity "${entityDef.name}"`);
11
- if (!isColumnField(col)) {
14
+ if (!(0, orm_helper_js_1.isColumnField)(col)) {
12
15
  throw new Error(`Column (${k}) defined as primary key in entity "${entityDef.name}" is not a data column`);
13
16
  }
14
17
  };
@@ -1,16 +1,26 @@
1
- import { ENTITY_METADATA_KEY } from '../orm.const.js';
2
- export function isClass(fn) {
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) {
3
11
  return typeof fn === 'function' && /^\s*class/.test(fn.toString());
4
12
  }
5
- export function isEntityClass(fn) {
6
- return isClass(fn) && Reflect.hasMetadata(ENTITY_METADATA_KEY, fn);
13
+ function isEntityClass(fn) {
14
+ return isClass(fn) && Reflect.hasMetadata(orm_const_js_1.ENTITY_METADATA_KEY, fn);
7
15
  }
8
- export function isColumnField(f) {
16
+ function isColumnField(f) {
9
17
  return !!(f && f.name && f.kind === 'column');
10
18
  }
11
- export const isEmbeddedField = (f) => !!(f && f.name && f.kind === 'object');
12
- export const isAssociationField = (f) => !!(f && f.name && f.kind === 'association');
13
- export async function resolveEntity(ctorThunk) {
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) {
14
24
  if (typeof ctorThunk !== 'function')
15
25
  return;
16
26
  if (!isClass(ctorThunk))
@@ -18,7 +28,7 @@ export async function resolveEntity(ctorThunk) {
18
28
  if (isEntityClass(ctorThunk))
19
29
  return ctorThunk;
20
30
  }
21
- export async function resolveEntityMeta(ctorThunk) {
31
+ async function resolveEntityMeta(ctorThunk) {
22
32
  const ctor = await resolveEntity(ctorThunk);
23
- return ctor && Reflect.getMetadata(ENTITY_METADATA_KEY, ctor);
33
+ return ctor && Reflect.getMetadata(orm_const_js_1.ENTITY_METADATA_KEY, ctor);
24
34
  }
@@ -1,14 +1,19 @@
1
- import { splitString } from 'fast-tokenizer';
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");
2
6
  const FIELD_PATTERN = /^([+-])?([a-z_$]\w*)$/i;
3
7
  const NO_DOT_BRACKET_PATTERN = /[^.]\(/g;
4
- export class FieldsProjection {
8
+ class FieldsProjection {
5
9
  }
10
+ exports.FieldsProjection = FieldsProjection;
6
11
  (function (FieldsProjection) {
7
12
  class Item {
8
13
  }
9
14
  FieldsProjection.Item = Item;
10
- })(FieldsProjection || (FieldsProjection = {}));
11
- export function parseFieldsProjection(projection, keepCase) {
15
+ })(FieldsProjection || (exports.FieldsProjection = FieldsProjection = {}));
16
+ function parseFieldsProjection(projection, keepCase) {
12
17
  const arr = Array.isArray(projection) ? projection : [projection];
13
18
  if (!(arr && arr.length))
14
19
  return;
@@ -23,7 +28,7 @@ export function parseFieldsProjection(projection, keepCase) {
23
28
  function parse(input, target) {
24
29
  /** Add dot before brackets which is required to split fields */
25
30
  input = input.replace(NO_DOT_BRACKET_PATTERN, s => s.charAt(0) + '.' + s.substring(1));
26
- const fields = splitString(input, {
31
+ const fields = (0, fast_tokenizer_1.splitString)(input, {
27
32
  delimiters: '.',
28
33
  brackets: true,
29
34
  keepBrackets: false,
@@ -31,7 +36,7 @@ function parse(input, target) {
31
36
  for (let i = 0; i < fields.length; i++) {
32
37
  const f = fields[i];
33
38
  if (f.includes(',')) {
34
- const subFields = splitString(f, {
39
+ const subFields = (0, fast_tokenizer_1.splitString)(f, {
35
40
  delimiters: ',',
36
41
  brackets: true,
37
42
  keepBrackets: true,
@@ -1,13 +1,16 @@
1
- import { DataType } from '@sqb/builder';
2
- import { isColumnField } from './orm.helper.js';
3
- export function serializeColumn(col, v) {
4
- if (isColumnField(col)) {
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)) {
5
8
  if (col.isArray) {
6
9
  if (Array.isArray(v))
7
- return v.map(x => serializeDataValue(col.dataType || DataType.VARCHAR, x));
8
- return [serializeDataValue(col.dataType || DataType.VARCHAR, v)];
10
+ return v.map(x => serializeDataValue(col.dataType || builder_1.DataType.VARCHAR, x));
11
+ return [serializeDataValue(col.dataType || builder_1.DataType.VARCHAR, v)];
9
12
  }
10
- return serializeDataValue(col.dataType || DataType.VARCHAR, v);
13
+ return serializeDataValue(col.dataType || builder_1.DataType.VARCHAR, v);
11
14
  }
12
15
  if (typeof v === 'object' && typeof v.toJSON === 'function')
13
16
  return v.toJSON();
@@ -17,19 +20,19 @@ const padZero = (n) => (n < 9 ? '0' : '') + n;
17
20
  function serializeDataValue(dataType, v) {
18
21
  if (v == null)
19
22
  return;
20
- if (v instanceof Date && (dataType === DataType.DATE || dataType === DataType.TIMESTAMP)) {
23
+ if (v instanceof Date && (dataType === builder_1.DataType.DATE || dataType === builder_1.DataType.TIMESTAMP)) {
21
24
  return (v.getFullYear() +
22
25
  '-' +
23
26
  padZero(v.getMonth() + 1) +
24
27
  '-' +
25
28
  padZero(v.getDate()) +
26
- (dataType === DataType.TIMESTAMP
29
+ (dataType === builder_1.DataType.TIMESTAMP
27
30
  ? 'T' + padZero(v.getHours()) + ':' + padZero(v.getMinutes()) + ':' + padZero(v.getSeconds())
28
31
  : ''));
29
32
  }
30
33
  if (v instanceof Buffer)
31
34
  return v.toString('base64');
32
- if (typeof v === 'number' && (dataType === DataType.SMALLINT || dataType === DataType.INTEGER))
35
+ if (typeof v === 'number' && (dataType === builder_1.DataType.SMALLINT || dataType === builder_1.DataType.INTEGER))
33
36
  return Math.trunc(v);
34
37
  if (typeof v === 'bigint')
35
38
  return v.toString();