@sqb/connect 4.11.3 → 4.12.1

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 (68) hide show
  1. package/README.md +9 -24
  2. package/cjs/client/cursor-stream.js +6 -3
  3. package/cjs/client/cursor.js +8 -6
  4. package/cjs/client/field-info-map.js +3 -3
  5. package/cjs/client/sqb-client.js +2 -3
  6. package/cjs/client/sqb-connection.js +14 -13
  7. package/cjs/index.js +1 -0
  8. package/cjs/orm/commands/command.helper.js +8 -9
  9. package/cjs/orm/commands/create.command.js +4 -5
  10. package/cjs/orm/commands/find.command.js +30 -57
  11. package/cjs/orm/commands/row-converter.js +6 -6
  12. package/cjs/orm/commands/update.command.js +3 -4
  13. package/cjs/orm/decorators/column.decorator.js +7 -3
  14. package/cjs/orm/decorators/embedded.decorator.js +1 -1
  15. package/cjs/orm/decorators/entity.decorator.js +2 -2
  16. package/cjs/orm/decorators/link.decorator.js +1 -1
  17. package/cjs/orm/decorators/transform.decorator.js +2 -4
  18. package/cjs/orm/model/association-field-metadata.js +1 -1
  19. package/cjs/orm/model/association.js +2 -4
  20. package/cjs/orm/model/column-field-metadata.js +1 -1
  21. package/cjs/orm/model/embedded-field-metadata.js +1 -1
  22. package/cjs/orm/model/entity-metadata.js +7 -7
  23. package/cjs/orm/model/link-chain.js +2 -2
  24. package/cjs/orm/orm.const.js +2 -1
  25. package/cjs/orm/repository.class.js +29 -15
  26. package/cjs/orm/util/apply-mixins.js +6 -4
  27. package/cjs/orm/util/extract-keyvalues.js +1 -1
  28. package/cjs/orm/util/parse-fields-projection.js +66 -0
  29. package/cjs/orm/util/serialize-field.js +10 -10
  30. package/esm/client/cursor-stream.js +6 -3
  31. package/esm/client/cursor.js +8 -6
  32. package/esm/client/field-info-map.js +3 -3
  33. package/esm/client/helpers.js +1 -1
  34. package/esm/client/sqb-client.js +2 -3
  35. package/esm/client/sqb-connection.js +15 -14
  36. package/esm/index.js +1 -0
  37. package/esm/orm/commands/command.helper.js +9 -10
  38. package/esm/orm/commands/create.command.js +4 -5
  39. package/esm/orm/commands/find.command.js +30 -57
  40. package/esm/orm/commands/row-converter.js +6 -6
  41. package/esm/orm/commands/update.command.js +3 -4
  42. package/esm/orm/decorators/column.decorator.js +6 -2
  43. package/esm/orm/decorators/embedded.decorator.js +1 -1
  44. package/esm/orm/decorators/entity.decorator.js +2 -2
  45. package/esm/orm/decorators/link.decorator.js +1 -1
  46. package/esm/orm/decorators/transform.decorator.js +2 -4
  47. package/esm/orm/model/association-field-metadata.js +1 -1
  48. package/esm/orm/model/association.js +2 -4
  49. package/esm/orm/model/column-field-metadata.js +1 -1
  50. package/esm/orm/model/embedded-field-metadata.js +1 -1
  51. package/esm/orm/model/entity-metadata.js +7 -7
  52. package/esm/orm/model/link-chain.js +2 -2
  53. package/esm/orm/orm.const.js +1 -0
  54. package/esm/orm/repository.class.js +29 -15
  55. package/esm/orm/util/apply-mixins.js +6 -4
  56. package/esm/orm/util/extract-keyvalues.js +1 -1
  57. package/esm/orm/util/parse-fields-projection.js +61 -0
  58. package/esm/orm/util/serialize-field.js +10 -10
  59. package/package.json +10 -6
  60. package/types/index.d.ts +1 -0
  61. package/types/orm/commands/find.command.d.ts +2 -3
  62. package/types/orm/decorators/column.decorator.d.ts +1 -0
  63. package/types/orm/decorators/entity.decorator.d.ts +2 -2
  64. package/types/orm/model/field-metadata.d.ts +1 -1
  65. package/types/orm/orm.const.d.ts +1 -0
  66. package/types/orm/orm.type.d.ts +1 -1
  67. package/types/orm/repository.class.d.ts +11 -8
  68. package/types/orm/util/parse-fields-projection.d.ts +10 -0
@@ -1,4 +1,4 @@
1
- import { And, Eq, Exists, Field, InnerJoin, isCompOperator, isLogicalOperator, LeftOuterJoin, Raw, Select } from '@sqb/builder';
1
+ import { And, Eq, Exists, Field, InnerJoin, isCompOperator, isLogicalOperator, LeftOuterJoin, Raw, Select, } from '@sqb/builder';
2
2
  import { EmbeddedFieldMetadata } from '../model/embedded-field-metadata.js';
3
3
  import { EntityMetadata } from '../model/entity-metadata.js';
4
4
  import { isAssociationField, isColumnField, isEmbeddedField } from '../util/orm.helper.js';
@@ -22,8 +22,9 @@ export async function joinAssociation(joinInfos, association, parentAlias, inner
22
22
  const keyCol = await node.resolveSourceProperty();
23
23
  const targetCol = await node.resolveTargetProperty();
24
24
  const joinAlias = 'J' + (joinInfos.length + 1);
25
- const join = innerJoin ? InnerJoin(targetEntity.tableName + ' as ' + joinAlias) :
26
- LeftOuterJoin(targetEntity.tableName + ' as ' + joinAlias);
25
+ const join = innerJoin
26
+ ? InnerJoin(targetEntity.tableName + ' as ' + joinAlias)
27
+ : LeftOuterJoin(targetEntity.tableName + ' as ' + joinAlias);
27
28
  join.on(Eq(Field(joinAlias + '.' + targetCol.fieldName, targetCol.dataType, targetCol.isArray), Field(parentAlias + '.' + keyCol.fieldName, keyCol.dataType, keyCol.isArray)));
28
29
  if (node.conditions)
29
30
  await prepareFilter(targetEntity, node.conditions, join._conditions, joinAlias);
@@ -32,7 +33,7 @@ export async function joinAssociation(joinInfos, association, parentAlias, inner
32
33
  sourceEntity,
33
34
  targetEntity,
34
35
  joinAlias,
35
- join
36
+ join,
36
37
  };
37
38
  joinInfos.push(joinInfo);
38
39
  }
@@ -46,7 +47,7 @@ export async function joinAssociation(joinInfos, association, parentAlias, inner
46
47
  }
47
48
  export async function prepareFilter(entityDef, filter, trgOp, tableAlias = 'T') {
48
49
  let srcOp;
49
- if (isLogicalOperator(filter))
50
+ if (isLogicalOperator(filter) && filter._operatorType === trgOp._operatorType)
50
51
  srcOp = filter;
51
52
  else {
52
53
  srcOp = And();
@@ -101,8 +102,7 @@ export async function prepareFilter(entityDef, filter, trgOp, tableAlias = 'T')
101
102
  if (!subSelect) {
102
103
  const keyCol = await col.association.resolveSourceProperty();
103
104
  const targetCol = await col.association.resolveTargetProperty();
104
- subSelect = Select(Raw('1'))
105
- .from(_curEntity.tableName + ' K');
105
+ subSelect = Select(Raw('1')).from(_curEntity.tableName + ' K');
106
106
  subSelect.where(Eq(Field('K.' + targetCol.fieldName, targetCol.dataType, targetCol.isArray), Field(tableAlias + '.' + keyCol.fieldName, keyCol.dataType, keyCol.isArray)));
107
107
  trgOp.add(Exists(subSelect));
108
108
  trgOp = subSelect._where;
@@ -118,9 +118,8 @@ export async function prepareFilter(entityDef, filter, trgOp, tableAlias = 'T')
118
118
  const targetEntity = await node.resolveTarget();
119
119
  const sourceColumn = await node.resolveSourceProperty();
120
120
  const targetColumn = await node.resolveTargetProperty();
121
- const joinAlias = 'J' + (((subSelect?._joins?.length) || 0) + 1);
122
- subSelect.join(InnerJoin(targetEntity.tableName + ' ' + joinAlias)
123
- .on(Eq(Field(joinAlias + '.' + targetColumn.fieldName, targetColumn.dataType, targetColumn.isArray), Field(_curAlias + '.' + sourceColumn.fieldName, sourceColumn.dataType, sourceColumn.isArray))));
121
+ const joinAlias = 'J' + ((subSelect?._joins?.length || 0) + 1);
122
+ subSelect.join(InnerJoin(targetEntity.tableName + ' ' + joinAlias).on(Eq(Field(joinAlias + '.' + targetColumn.fieldName, targetColumn.dataType, targetColumn.isArray), Field(_curAlias + '.' + sourceColumn.fieldName, sourceColumn.dataType, sourceColumn.isArray))));
124
123
  _curEntity = targetEntity;
125
124
  _curAlias = joinAlias;
126
125
  node = node.next;
@@ -18,7 +18,7 @@ export class CreateCommand {
18
18
  entity,
19
19
  queryParams: {},
20
20
  queryValues: {},
21
- colCount: 0
21
+ colCount: 0,
22
22
  };
23
23
  // Prepare
24
24
  await this._prepareParams(ctx, entity, args.values);
@@ -33,7 +33,7 @@ export class CreateCommand {
33
33
  const qr = await args.connection.execute(query, {
34
34
  params: ctx.queryParams,
35
35
  objectRows: false,
36
- cursor: false
36
+ cursor: false,
37
37
  });
38
38
  if (args.returning && qr.fields && qr.rows?.length) {
39
39
  const keyValues = {};
@@ -55,8 +55,7 @@ export class CreateCommand {
55
55
  if (col.noInsert)
56
56
  continue;
57
57
  if (v == null && col.default !== undefined) {
58
- v = typeof col.default === 'function' ?
59
- col.default(values) : col.default;
58
+ v = typeof col.default === 'function' ? col.default(values) : col.default;
60
59
  }
61
60
  if (typeof col.serialize === 'function')
62
61
  v = col.serialize(v, col.name);
@@ -71,7 +70,7 @@ export class CreateCommand {
71
70
  ctx.queryValues[fieldName] = Param({
72
71
  name: k,
73
72
  dataType: col.dataType,
74
- isArray: col.isArray
73
+ isArray: col.isArray,
75
74
  });
76
75
  ctx.queryParams[k] = v;
77
76
  ctx.colCount++;
@@ -1,9 +1,9 @@
1
1
  import { And, In, Param, Select } from '@sqb/builder';
2
- import { Entity } from '../decorators/entity.decorator.js';
3
2
  import { AssociationNode } from '../model/association-node.js';
4
3
  import { EmbeddedFieldMetadata } from '../model/embedded-field-metadata.js';
5
4
  import { EntityMetadata } from '../model/entity-metadata.js';
6
5
  import { isAssociationField, isColumnField, isEmbeddedField } from '../util/orm.helper.js';
6
+ import { parseFieldsProjection } from '../util/parse-fields-projection.js';
7
7
  import { joinAssociationGetLast, prepareFilter } from './command.helper.js';
8
8
  import { RowConverter } from './row-converter.js';
9
9
  const SORT_ORDER_PATTERN = /^([-+])?(.*)$/;
@@ -53,10 +53,8 @@ export class FindCommand {
53
53
  maxEagerFetch: args.maxEagerFetch,
54
54
  });
55
55
  await command.addFields({
56
- pick: args.pick,
57
- include: args.include,
58
- omit: args.omit,
59
- sort: args.sort
56
+ projection: args.projection,
57
+ sort: args.sort,
60
58
  });
61
59
  if (args.filter)
62
60
  await command.filter(args.filter);
@@ -68,27 +66,11 @@ export class FindCommand {
68
66
  const tableAlias = opts.tableAlias || this.resultAlias;
69
67
  const entity = opts.entity || this._getEntityFromAlias(tableAlias);
70
68
  const converter = opts.converter || this.converter;
71
- const _pick = opts.pick ?
72
- opts.pick.map(x => x.toLowerCase()) : undefined;
73
- const _omit = opts.omit ?
74
- opts.omit.map(x => x.toLowerCase()) : undefined;
75
- const _include = opts.include ?
76
- opts.include.map(x => x.toLowerCase()) : undefined;
77
- let requestedFields;
78
- if (_pick)
79
- requestedFields = [..._pick];
80
- else {
81
- requestedFields = Entity.getFieldNames(entity.ctor).reduce((a, x) => {
82
- const f = Entity.getField(entity.ctor, x);
83
- if (f && !f.exclusive)
84
- a.push(x.toLowerCase());
85
- return a;
86
- }, []);
87
- }
88
- if (_include)
89
- requestedFields.push(..._include);
90
- const sortFields = opts.sort && opts.sort.length ?
91
- opts.sort.map(x => x.toLowerCase()) : undefined;
69
+ const projection = typeof opts.projection === 'string' || Array.isArray(opts.projection)
70
+ ? parseFieldsProjection(opts.projection)
71
+ : opts.projection;
72
+ const defaultFields = !projection || !Object.values(projection).find(p => !p.sign);
73
+ const sortFields = opts.sort && opts.sort.length ? opts.sort.map(x => x.toLowerCase()) : undefined;
92
74
  const prefix = opts.prefix || '';
93
75
  const suffix = opts.suffix || '';
94
76
  for (const key of Object.keys(entity.fields)) {
@@ -96,12 +78,16 @@ export class FindCommand {
96
78
  if (!col || col.hidden)
97
79
  continue;
98
80
  const colNameLower = col.name.toLowerCase();
99
- // Ignore field if in excluded list
100
- if (_omit && _omit.includes(colNameLower))
101
- continue;
102
- // Check if field request list
103
- if (!requestedFields.find((x) => x === colNameLower || x.startsWith(colNameLower + '.')))
81
+ const p = projection?.[colNameLower];
82
+ if (
83
+ /** Ignore if field is omitted */
84
+ p?.sign === '-' ||
85
+ /** Ignore if default fields and field is not in projection */
86
+ (!defaultFields && !p) ||
87
+ /** Ignore if default fields enabled and fields is exclusive */
88
+ (defaultFields && col.exclusive && !p)) {
104
89
  continue;
90
+ }
105
91
  // Add field to select list if field is a column
106
92
  if (isColumnField(col)) {
107
93
  const fieldAlias = this._selectColumn(tableAlias, col, prefix, suffix);
@@ -110,7 +96,7 @@ export class FindCommand {
110
96
  name: col.name,
111
97
  fieldAlias,
112
98
  dataType: col.dataType,
113
- parse: col.parse
99
+ parse: col.parse,
114
100
  });
115
101
  continue;
116
102
  }
@@ -118,7 +104,7 @@ export class FindCommand {
118
104
  const typ = await EmbeddedFieldMetadata.resolveType(col);
119
105
  const subConverter = converter.addObjectProperty({
120
106
  name: col.name,
121
- type: typ.ctor
107
+ type: typ.ctor,
122
108
  }).converter;
123
109
  await this.addFields({
124
110
  tableAlias,
@@ -126,10 +112,7 @@ export class FindCommand {
126
112
  entity: typ,
127
113
  prefix: col.fieldNamePrefix,
128
114
  suffix: col.fieldNameSuffix,
129
- pick: _pick?.includes(colNameLower) ? undefined :
130
- extractSubFields(colNameLower, _pick),
131
- include: extractSubFields(colNameLower, _include),
132
- omit: extractSubFields(colNameLower, _omit),
115
+ projection: p?.projection,
133
116
  sort: extractSubFields(colNameLower, sortFields),
134
117
  });
135
118
  continue;
@@ -140,17 +123,14 @@ export class FindCommand {
140
123
  const joinInfo = await joinAssociationGetLast(this._joins, col.association, tableAlias);
141
124
  const subConverter = converter.addObjectProperty({
142
125
  name: col.name,
143
- type: joinInfo.targetEntity.ctor
126
+ type: joinInfo.targetEntity.ctor,
144
127
  }).converter;
145
128
  // Add join fields to select columns list
146
129
  await this.addFields({
147
130
  tableAlias: joinInfo.joinAlias,
148
131
  converter: subConverter,
149
132
  entity: joinInfo.targetEntity,
150
- pick: _pick?.includes(colNameLower) ? undefined :
151
- extractSubFields(colNameLower, _pick),
152
- include: extractSubFields(colNameLower, _include),
153
- omit: extractSubFields(colNameLower, _omit),
133
+ projection: p?.projection,
154
134
  sort: extractSubFields(colNameLower, sortFields),
155
135
  });
156
136
  continue;
@@ -164,16 +144,13 @@ export class FindCommand {
164
144
  const parentField = this._selectColumn(tableAlias, sourceCol);
165
145
  const findCommand = await FindCommand.create(col.association, {
166
146
  maxSubQueries: this.maxSubQueries - 1,
167
- maxEagerFetch: this.maxEagerFetch
147
+ maxEagerFetch: this.maxEagerFetch,
168
148
  });
169
149
  findCommand.converter.parent = this.converter;
170
150
  await findCommand.filter(In(targetCol.name, Param(parentField)));
171
151
  const sort = sortFields && extractSubFields(colNameLower, sortFields);
172
152
  await findCommand.addFields({
173
- pick: _pick?.includes(colNameLower) ? undefined :
174
- extractSubFields(colNameLower, _pick),
175
- include: extractSubFields(colNameLower, _include),
176
- omit: extractSubFields(colNameLower, _omit),
153
+ projection: p?.projection,
177
154
  sort,
178
155
  });
179
156
  if (sort)
@@ -186,20 +163,18 @@ export class FindCommand {
186
163
  findCommand,
187
164
  parentField,
188
165
  keyField,
189
- sort: extractSubFields(colNameLower, sortFields)
166
+ sort: extractSubFields(colNameLower, sortFields),
190
167
  });
191
168
  }
192
169
  }
193
170
  }
194
171
  }
195
172
  _selectColumn(tableAlias, el, prefix, suffix) {
196
- const fieldName = (prefix || '').toLowerCase() +
197
- el.fieldName.toUpperCase() +
198
- (suffix || '').toLowerCase();
173
+ const fieldName = (prefix || '').toLowerCase() + el.fieldName.toUpperCase() + (suffix || '').toLowerCase();
199
174
  const fieldAlias = (tableAlias + '_' + fieldName).substring(0, 30);
200
175
  this._selectColumns[fieldAlias] = {
201
176
  field: el,
202
- statement: tableAlias + '.' + fieldName + ' as ' + fieldAlias
177
+ statement: tableAlias + '.' + fieldName + ' as ' + fieldAlias,
203
178
  };
204
179
  return fieldAlias;
205
180
  }
@@ -256,12 +231,10 @@ export class FindCommand {
256
231
  }
257
232
  async execute(args) {
258
233
  // Generate select query
259
- const columnSqls = Object.keys(this._selectColumns)
260
- .map(x => this._selectColumns[x].statement);
234
+ const columnSqls = Object.keys(this._selectColumns).map(x => this._selectColumns[x].statement);
261
235
  if (!columnSqls.length)
262
236
  columnSqls.push('1');
263
- const query = Select(...columnSqls)
264
- .from(this.mainEntity.tableName + ' as ' + this.mainAlias);
237
+ const query = Select(...columnSqls).from(this.mainEntity.tableName + ' as ' + this.mainAlias);
265
238
  if (args.distinct)
266
239
  query.distinct();
267
240
  query.where(...this._filter._items);
@@ -280,7 +253,7 @@ export class FindCommand {
280
253
  params: args?.params,
281
254
  fetchRows: args?.limit,
282
255
  objectRows: false,
283
- cursor: false
256
+ cursor: false,
284
257
  });
285
258
  // Create objects
286
259
  if (resp.rows && resp.fields) {
@@ -19,7 +19,7 @@ export class RowConverter {
19
19
  const item = {
20
20
  fieldAlias: args.fieldAlias,
21
21
  dataType: args.dataType,
22
- parse: args.parse
22
+ parse: args.parse,
23
23
  };
24
24
  this._properties[args.name] = item;
25
25
  return item;
@@ -30,7 +30,7 @@ export class RowConverter {
30
30
  const converter = new RowConverter(args.type, this);
31
31
  const item = {
32
32
  converter,
33
- type: args.type
33
+ type: args.type,
34
34
  };
35
35
  this._properties[args.name] = item;
36
36
  return item;
@@ -45,7 +45,7 @@ export class RowConverter {
45
45
  keyField: args.keyField,
46
46
  findCommand: args.findCommand,
47
47
  sort: args.sort,
48
- paramValues: []
48
+ paramValues: [],
49
49
  };
50
50
  this._properties[args.name] = item;
51
51
  return item;
@@ -126,7 +126,7 @@ export class RowConverter {
126
126
  if (!(prop.paramValues && prop.paramValues.length))
127
127
  continue;
128
128
  const resultType = this.resultType;
129
- const promise = async function (p) {
129
+ const promise = (async function (p) {
130
130
  const findCommand = p.findCommand;
131
131
  let fld;
132
132
  const map = new Map();
@@ -148,7 +148,7 @@ export class RowConverter {
148
148
  arr.push(obj);
149
149
  });
150
150
  }
151
- }
151
+ },
152
152
  });
153
153
  if (r.length > findCommand.maxEagerFetch)
154
154
  throw new Error(`Number of returning rows for "${propKey}" exceeds maxEagerFetch limit`);
@@ -168,7 +168,7 @@ export class RowConverter {
168
168
  }
169
169
  }
170
170
  }
171
- }(prop);
171
+ })(prop);
172
172
  promises.push(promise);
173
173
  }
174
174
  else if (isObjectProperty(prop)) {
@@ -27,12 +27,11 @@ export class UpdateCommand {
27
27
  return 0;
28
28
  if (args.filter)
29
29
  await this._prepareFilter(ctx, args.filter);
30
- const query = Update(tableName + ' as T', ctx.queryValues)
31
- .where(...ctx.queryFilter);
30
+ const query = Update(tableName + ' as T', ctx.queryValues).where(...ctx.queryFilter);
32
31
  const qr = await args.connection.execute(query, {
33
32
  params: args.params ? [...args.params, ctx.queryParams] : ctx.queryParams,
34
33
  objectRows: false,
35
- cursor: false
34
+ cursor: false,
36
35
  });
37
36
  return qr.rowsAffected || 0;
38
37
  }
@@ -66,7 +65,7 @@ export class UpdateCommand {
66
65
  ctx.queryValues[fieldName] = Param({
67
66
  name: k,
68
67
  dataType: col.dataType,
69
- isArray: col.isArray
68
+ isArray: col.isArray,
70
69
  });
71
70
  ctx.queryParams[k] = v;
72
71
  ctx.colCount++;
@@ -1,12 +1,16 @@
1
1
  import { EntityMetadata } from '../model/entity-metadata.js';
2
+ import { DECORATOR_FACTORY } from '../orm.const.js';
2
3
  export function Column(arg0) {
4
+ return Column[DECORATOR_FACTORY](arg0);
5
+ }
6
+ Column[DECORATOR_FACTORY] = function (arg0) {
3
7
  return (target, propertyKey) => {
4
8
  if (typeof propertyKey !== 'string')
5
9
  throw new Error('Symbol properties are not accepted');
6
10
  const options = (typeof arg0 === 'string' ? { dataType: arg0 } : arg0) || {};
7
11
  const entity = EntityMetadata.define(target.constructor);
8
12
  if (!options.type) {
9
- const typ = Reflect.getMetadata("design:type", entity.ctor.prototype, propertyKey);
13
+ const typ = Reflect.getMetadata('design:type', entity.ctor.prototype, propertyKey);
10
14
  if (typ === Array) {
11
15
  options.type = String;
12
16
  options.isArray = true;
@@ -16,4 +20,4 @@ export function Column(arg0) {
16
20
  }
17
21
  EntityMetadata.defineColumnField(entity, propertyKey, options);
18
22
  };
19
- }
23
+ };
@@ -3,7 +3,7 @@ export function Embedded(type, options) {
3
3
  return (target, propertyKey) => {
4
4
  if (typeof propertyKey !== 'string')
5
5
  throw new Error('Symbol properties are not accepted');
6
- type = type || Reflect.getMetadata("design:type", target, propertyKey);
6
+ type = type || Reflect.getMetadata('design:type', target, propertyKey);
7
7
  if (typeof type !== 'function')
8
8
  throw new Error('"type" must be defined');
9
9
  const entity = EntityMetadata.define(target.constructor);
@@ -111,7 +111,7 @@ export function Entity(options) {
111
111
  }
112
112
  };
113
113
  const pickKeys = keys.map(x => x.toLowerCase());
114
- const filter = (k) => pickKeys.includes(k.toLowerCase());
114
+ const filter = k => pickKeys.includes(k.toLowerCase());
115
115
  applyMixins(PickEntityClass, classRef, filter);
116
116
  const srcMeta = EntityMetadata.get(classRef);
117
117
  if (srcMeta) {
@@ -128,7 +128,7 @@ export function Entity(options) {
128
128
  }
129
129
  };
130
130
  const omitKeys = keys.map(x => x.toLowerCase());
131
- const filter = (k) => !omitKeys.includes(k.toLowerCase());
131
+ const filter = k => !omitKeys.includes(k.toLowerCase());
132
132
  applyMixins(OmitEntityClass, classRef, filter);
133
133
  const srcMeta = EntityMetadata.get(classRef);
134
134
  if (srcMeta) {
@@ -6,7 +6,7 @@ export function Link(options) {
6
6
  const fn = (target, propertyKey) => {
7
7
  if (typeof propertyKey !== 'string')
8
8
  throw new TypeError('Symbol properties are not allowed');
9
- const reflectType = Reflect.getMetadata("design:type", target, propertyKey);
9
+ const reflectType = Reflect.getMetadata('design:type', target, propertyKey);
10
10
  if (!root) {
11
11
  if (reflectType === Array)
12
12
  throw new TypeError(`Can't get type information while it is an array. Please define entity type`);
@@ -4,8 +4,7 @@ export function Parse(fn) {
4
4
  if (typeof propertyKey !== 'string')
5
5
  throw new Error('You can define a Column for only string properties');
6
6
  const entity = EntityMetadata.define(target.constructor);
7
- EntityMetadata.defineColumnField(entity, propertyKey)
8
- .parse = fn;
7
+ EntityMetadata.defineColumnField(entity, propertyKey).parse = fn;
9
8
  };
10
9
  }
11
10
  export function Serialize(fn) {
@@ -13,7 +12,6 @@ export function Serialize(fn) {
13
12
  if (typeof propertyKey !== 'string')
14
13
  throw new Error('You can define a Column for only string properties');
15
14
  const entity = EntityMetadata.define(target.constructor);
16
- EntityMetadata.defineColumnField(entity, propertyKey)
17
- .serialize = fn;
15
+ EntityMetadata.defineColumnField(entity, propertyKey).serialize = fn;
18
16
  };
19
17
  }
@@ -6,7 +6,7 @@ export var AssociationFieldMetadata;
6
6
  kind: 'association',
7
7
  entity,
8
8
  name,
9
- association
9
+ association,
10
10
  };
11
11
  if (options)
12
12
  AssociationFieldMetadata.assign(result, options);
@@ -78,8 +78,7 @@ export class Association {
78
78
  if (this.many) {
79
79
  if (!sourceKey) {
80
80
  const primaryIndexColumns = EntityMetadata.getPrimaryIndexColumns(source);
81
- sourceKey = primaryIndexColumns && primaryIndexColumns.length === 1 ?
82
- primaryIndexColumns[0].name : 'id';
81
+ sourceKey = primaryIndexColumns && primaryIndexColumns.length === 1 ? primaryIndexColumns[0].name : 'id';
83
82
  }
84
83
  if (!targetKey && sourceKey) {
85
84
  // snake-case
@@ -92,8 +91,7 @@ export class Association {
92
91
  else {
93
92
  if (!targetKey) {
94
93
  const primaryIndexColumns = EntityMetadata.getPrimaryIndexColumns(target);
95
- targetKey = primaryIndexColumns && primaryIndexColumns.length === 1 ?
96
- primaryIndexColumns[0].name : 'id';
94
+ targetKey = primaryIndexColumns && primaryIndexColumns.length === 1 ? primaryIndexColumns[0].name : 'id';
97
95
  }
98
96
  if (!sourceKey && targetKey) {
99
97
  // snake-case
@@ -6,7 +6,7 @@ export var ColumnFieldMetadata;
6
6
  kind: 'column',
7
7
  entity,
8
8
  name,
9
- fieldName: name
9
+ fieldName: name,
10
10
  };
11
11
  if (options)
12
12
  ColumnFieldMetadata.assign(result, options);
@@ -6,7 +6,7 @@ export var EmbeddedFieldMetadata;
6
6
  kind: 'object',
7
7
  entity,
8
8
  name,
9
- type
9
+ type,
10
10
  };
11
11
  if (options?.fieldNamePrefix)
12
12
  result.fieldNamePrefix = options.fieldNamePrefix;
@@ -18,7 +18,7 @@ export var EntityMetadata;
18
18
  fields: {},
19
19
  indexes: [],
20
20
  foreignKeys: [],
21
- eventListeners: {}
21
+ eventListeners: {},
22
22
  };
23
23
  Reflect.defineMetadata(ENTITY_METADATA_KEY, meta, ctor);
24
24
  // Merge base entity columns into this one
@@ -90,7 +90,7 @@ export var EntityMetadata;
90
90
  enumerable: false,
91
91
  configurable: true,
92
92
  writable: true,
93
- value: Object.values(entity.fields).map(m => m.name)
93
+ value: Object.values(entity.fields).map(m => m.name),
94
94
  });
95
95
  return entity._fieldNames;
96
96
  }
@@ -141,7 +141,7 @@ export var EntityMetadata;
141
141
  if (!src.foreignKeys)
142
142
  return;
143
143
  for (const f of src.foreignKeys) {
144
- if (await f.resolveTarget() === trg)
144
+ if ((await f.resolveTarget()) === trg)
145
145
  return f;
146
146
  }
147
147
  }
@@ -150,7 +150,7 @@ export var EntityMetadata;
150
150
  entity.indexes = entity.indexes || [];
151
151
  index = {
152
152
  ...index,
153
- columns: Array.isArray(index.columns) ? index.columns : [index.columns]
153
+ columns: Array.isArray(index.columns) ? index.columns : [index.columns],
154
154
  };
155
155
  if (index.primary)
156
156
  entity.indexes.forEach(idx => delete idx.primary);
@@ -163,7 +163,7 @@ export var EntityMetadata;
163
163
  source: entity.ctor,
164
164
  sourceKey: propertyKey,
165
165
  target,
166
- targetKey
166
+ targetKey,
167
167
  });
168
168
  entity.foreignKeys.push(fk);
169
169
  }
@@ -252,7 +252,7 @@ export var EntityMetadata;
252
252
  let l = association;
253
253
  let i = 1;
254
254
  while (l) {
255
- l.name = entity.name + '.' + propertyKey + '#' + (i++);
255
+ l.name = entity.name + '.' + propertyKey + '#' + i++;
256
256
  l = l.next;
257
257
  }
258
258
  entity.fields[propertyKey.toLowerCase()] = prop;
@@ -264,7 +264,7 @@ export var EntityMetadata;
264
264
  ...options,
265
265
  columns: Array.isArray(column) ? column : [column],
266
266
  unique: true,
267
- primary: true
267
+ primary: true,
268
268
  });
269
269
  }
270
270
  EntityMetadata.setPrimaryKeys = setPrimaryKeys;
@@ -7,7 +7,7 @@ export class LinkChain {
7
7
  target,
8
8
  source: null,
9
9
  sourceKey,
10
- targetKey: targetKey
10
+ targetKey: targetKey,
11
11
  });
12
12
  }
13
13
  where(conditions) {
@@ -30,7 +30,7 @@ export class LinkChain {
30
30
  source: this.current.target,
31
31
  target,
32
32
  sourceKey: parentKey,
33
- targetKey: targetKey
33
+ targetKey: targetKey,
34
34
  });
35
35
  child.prior = this.current;
36
36
  this.current.next = child;
@@ -1,2 +1,3 @@
1
1
  export const ENTITY_METADATA_KEY = Symbol.for('SQB_ENTITY_METADATA');
2
2
  export const REPOSITORY_KEY = Symbol.for('SQB_REPOSITORY');
3
+ export const DECORATOR_FACTORY = Symbol.for('decorator.factory');