@sqb/connect 4.15.0 → 4.16.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 (46) hide show
  1. package/esm/client/adapter.js +1 -2
  2. package/esm/client/cursor-stream.js +4 -9
  3. package/esm/client/cursor.js +17 -22
  4. package/esm/client/extensions.js +1 -5
  5. package/esm/client/field-info-map.js +1 -5
  6. package/esm/client/helpers.js +12 -19
  7. package/esm/client/sqb-client.js +27 -32
  8. package/esm/client/sqb-connection.js +36 -41
  9. package/esm/client/types.js +1 -5
  10. package/esm/index.js +32 -40
  11. package/esm/orm/backward.js +12 -19
  12. package/esm/orm/base-entity.js +6 -10
  13. package/esm/orm/commands/command.helper.js +28 -34
  14. package/esm/orm/commands/count.command.js +6 -10
  15. package/esm/orm/commands/create.command.js +14 -18
  16. package/esm/orm/commands/delete.command.js +6 -10
  17. package/esm/orm/commands/find.command.js +30 -34
  18. package/esm/orm/commands/row-converter.js +3 -7
  19. package/esm/orm/commands/update.command.js +14 -18
  20. package/esm/orm/decorators/column.decorator.js +7 -10
  21. package/esm/orm/decorators/embedded.decorator.js +4 -7
  22. package/esm/orm/decorators/entity.decorator.js +53 -56
  23. package/esm/orm/decorators/events.decorator.js +19 -27
  24. package/esm/orm/decorators/foreignkey.decorator.js +4 -7
  25. package/esm/orm/decorators/index.decorator.js +6 -9
  26. package/esm/orm/decorators/link.decorator.js +8 -11
  27. package/esm/orm/decorators/primarykey.decorator.js +8 -11
  28. package/esm/orm/decorators/transform.decorator.js +7 -11
  29. package/esm/orm/model/association-field-metadata.js +4 -8
  30. package/esm/orm/model/association-node.js +2 -6
  31. package/esm/orm/model/association.js +16 -20
  32. package/esm/orm/model/column-field-metadata.js +4 -8
  33. package/esm/orm/model/embedded-field-metadata.js +4 -7
  34. package/esm/orm/model/entity-metadata.js +47 -50
  35. package/esm/orm/model/field-metadata.js +1 -2
  36. package/esm/orm/model/index-metadata.js +1 -2
  37. package/esm/orm/model/link-chain.js +4 -8
  38. package/esm/orm/orm.const.js +3 -6
  39. package/esm/orm/orm.type.js +1 -2
  40. package/esm/orm/repository.class.js +22 -26
  41. package/esm/orm/util/apply-mixins.js +1 -4
  42. package/esm/orm/util/extract-keyvalues.js +6 -9
  43. package/esm/orm/util/orm.helper.js +10 -20
  44. package/esm/orm/util/parse-fields-projection.js +6 -11
  45. package/esm/orm/util/serialize-field.js +10 -13
  46. package/package.json +5 -5
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Entity = Entity;
4
- const entity_metadata_js_1 = require("../model/entity-metadata.js");
5
- const apply_mixins_js_1 = require("../util/apply-mixins.js");
6
- function Entity(options) {
1
+ import { EntityMetadata } from '../model/entity-metadata.js';
2
+ import { applyMixins } from '../util/apply-mixins.js';
3
+ export function Entity(options) {
7
4
  return function (target) {
8
5
  const opts = typeof options === 'object' ? options : {};
9
6
  const tableName = typeof options === 'string' ? options : opts.tableName;
10
- const entity = entity_metadata_js_1.EntityMetadata.define(target);
7
+ const entity = EntityMetadata.define(target);
11
8
  entity.tableName = tableName || target.name;
12
9
  if (opts.schema)
13
10
  entity.schema = opts.schema;
@@ -16,92 +13,92 @@ function Entity(options) {
16
13
  };
17
14
  }
18
15
  (function (Entity) {
19
- Entity.getMetadata = entity_metadata_js_1.EntityMetadata.get;
20
- Entity.getOwnMetadata = entity_metadata_js_1.EntityMetadata.getOwn;
16
+ Entity.getMetadata = EntityMetadata.get;
17
+ Entity.getOwnMetadata = EntityMetadata.getOwn;
21
18
  function getField(ctor, key) {
22
- const model = entity_metadata_js_1.EntityMetadata.get(ctor);
23
- return model && entity_metadata_js_1.EntityMetadata.getField(model, key);
19
+ const model = EntityMetadata.get(ctor);
20
+ return model && EntityMetadata.getField(model, key);
24
21
  }
25
22
  Entity.getField = getField;
26
23
  function getColumnField(ctor, key) {
27
- const model = entity_metadata_js_1.EntityMetadata.get(ctor);
28
- return model && entity_metadata_js_1.EntityMetadata.getColumnField(model, key);
24
+ const model = EntityMetadata.get(ctor);
25
+ return model && EntityMetadata.getColumnField(model, key);
29
26
  }
30
27
  Entity.getColumnField = getColumnField;
31
28
  function getEmbeddedField(ctor, key) {
32
- const model = entity_metadata_js_1.EntityMetadata.get(ctor);
33
- return model && entity_metadata_js_1.EntityMetadata.getEmbeddedField(model, key);
29
+ const model = EntityMetadata.get(ctor);
30
+ return model && EntityMetadata.getEmbeddedField(model, key);
34
31
  }
35
32
  Entity.getEmbeddedField = getEmbeddedField;
36
33
  function getAssociationField(ctor, key) {
37
- const model = entity_metadata_js_1.EntityMetadata.get(ctor);
38
- return model && entity_metadata_js_1.EntityMetadata.getAssociationField(model, key);
34
+ const model = EntityMetadata.get(ctor);
35
+ return model && EntityMetadata.getAssociationField(model, key);
39
36
  }
40
37
  Entity.getAssociationField = getAssociationField;
41
38
  function getColumnFieldByFieldName(ctor, fieldName) {
42
- const model = entity_metadata_js_1.EntityMetadata.get(ctor);
43
- return model && entity_metadata_js_1.EntityMetadata.getColumnFieldByFieldName(model, fieldName);
39
+ const model = EntityMetadata.get(ctor);
40
+ return model && EntityMetadata.getColumnFieldByFieldName(model, fieldName);
44
41
  }
45
42
  Entity.getColumnFieldByFieldName = getColumnFieldByFieldName;
46
43
  function find(ctor, predicate) {
47
- const model = entity_metadata_js_1.EntityMetadata.get(ctor);
48
- return model && entity_metadata_js_1.EntityMetadata.findField(model, predicate);
44
+ const model = EntityMetadata.get(ctor);
45
+ return model && EntityMetadata.findField(model, predicate);
49
46
  }
50
47
  Entity.find = find;
51
48
  function getFieldNames(ctor, filter) {
52
- const model = entity_metadata_js_1.EntityMetadata.get(ctor);
53
- return (model && entity_metadata_js_1.EntityMetadata.getFieldNames(model, filter)) || [];
49
+ const model = EntityMetadata.get(ctor);
50
+ return (model && EntityMetadata.getFieldNames(model, filter)) || [];
54
51
  }
55
52
  Entity.getFieldNames = getFieldNames;
56
53
  function getColumnFieldNames(ctor) {
57
- const model = entity_metadata_js_1.EntityMetadata.get(ctor);
58
- return (model && entity_metadata_js_1.EntityMetadata.getColumnFieldNames(model)) || [];
54
+ const model = EntityMetadata.get(ctor);
55
+ return (model && EntityMetadata.getColumnFieldNames(model)) || [];
59
56
  }
60
57
  Entity.getColumnFieldNames = getColumnFieldNames;
61
58
  function getEmbeddedFieldNames(ctor) {
62
- const model = entity_metadata_js_1.EntityMetadata.get(ctor);
63
- return (model && entity_metadata_js_1.EntityMetadata.getEmbeddedFieldNames(model)) || [];
59
+ const model = EntityMetadata.get(ctor);
60
+ return (model && EntityMetadata.getEmbeddedFieldNames(model)) || [];
64
61
  }
65
62
  Entity.getEmbeddedFieldNames = getEmbeddedFieldNames;
66
63
  function getAssociationFieldNames(ctor) {
67
- const model = entity_metadata_js_1.EntityMetadata.get(ctor);
68
- return (model && entity_metadata_js_1.EntityMetadata.getAssociationFieldNames(model)) || [];
64
+ const model = EntityMetadata.get(ctor);
65
+ return (model && EntityMetadata.getAssociationFieldNames(model)) || [];
69
66
  }
70
67
  Entity.getAssociationFieldNames = getAssociationFieldNames;
71
68
  function getNonAssociationFieldNames(ctor) {
72
- const model = entity_metadata_js_1.EntityMetadata.get(ctor);
73
- return (model && entity_metadata_js_1.EntityMetadata.getNonAssociationFieldNames(model)) || [];
69
+ const model = EntityMetadata.get(ctor);
70
+ return (model && EntityMetadata.getNonAssociationFieldNames(model)) || [];
74
71
  }
75
72
  Entity.getNonAssociationFieldNames = getNonAssociationFieldNames;
76
73
  function getInsertColumnNames(ctor) {
77
- const model = entity_metadata_js_1.EntityMetadata.get(ctor);
78
- return (model && entity_metadata_js_1.EntityMetadata.getInsertColumnNames(model)) || [];
74
+ const model = EntityMetadata.get(ctor);
75
+ return (model && EntityMetadata.getInsertColumnNames(model)) || [];
79
76
  }
80
77
  Entity.getInsertColumnNames = getInsertColumnNames;
81
78
  function getUpdateColumnNames(ctor) {
82
- const model = entity_metadata_js_1.EntityMetadata.get(ctor);
83
- return (model && entity_metadata_js_1.EntityMetadata.getUpdateColumnNames(model)) || [];
79
+ const model = EntityMetadata.get(ctor);
80
+ return (model && EntityMetadata.getUpdateColumnNames(model)) || [];
84
81
  }
85
82
  Entity.getUpdateColumnNames = getUpdateColumnNames;
86
83
  function getPrimaryIndex(ctor) {
87
- const model = entity_metadata_js_1.EntityMetadata.define(ctor);
88
- return entity_metadata_js_1.EntityMetadata.getPrimaryIndex(model);
84
+ const model = EntityMetadata.define(ctor);
85
+ return EntityMetadata.getPrimaryIndex(model);
89
86
  }
90
87
  Entity.getPrimaryIndex = getPrimaryIndex;
91
88
  function getPrimaryIndexColumns(ctor) {
92
- const model = entity_metadata_js_1.EntityMetadata.define(ctor);
93
- return entity_metadata_js_1.EntityMetadata.getPrimaryIndexColumns(model);
89
+ const model = EntityMetadata.define(ctor);
90
+ return EntityMetadata.getPrimaryIndexColumns(model);
94
91
  }
95
92
  Entity.getPrimaryIndexColumns = getPrimaryIndexColumns;
96
93
  function mixin(derivedCtor, ...bases) {
97
94
  for (const base of bases) {
98
95
  if (!base)
99
96
  continue;
100
- (0, apply_mixins_js_1.applyMixins)(derivedCtor, base);
101
- const srcMeta = entity_metadata_js_1.EntityMetadata.get(base);
97
+ applyMixins(derivedCtor, base);
98
+ const srcMeta = EntityMetadata.get(base);
102
99
  if (srcMeta) {
103
- const trgMeta = entity_metadata_js_1.EntityMetadata.define(derivedCtor);
104
- entity_metadata_js_1.EntityMetadata.mixin(trgMeta, srcMeta);
100
+ const trgMeta = EntityMetadata.define(derivedCtor);
101
+ EntityMetadata.mixin(trgMeta, srcMeta);
105
102
  }
106
103
  }
107
104
  return derivedCtor;
@@ -115,11 +112,11 @@ function Entity(options) {
115
112
  };
116
113
  const pickKeys = keys.map(x => x.toLowerCase());
117
114
  const filter = k => pickKeys.includes(k.toLowerCase());
118
- (0, apply_mixins_js_1.applyMixins)(PickEntityClass, classRef, filter);
119
- const srcMeta = entity_metadata_js_1.EntityMetadata.get(classRef);
115
+ applyMixins(PickEntityClass, classRef, filter);
116
+ const srcMeta = EntityMetadata.get(classRef);
120
117
  if (srcMeta) {
121
- const trgMeta = entity_metadata_js_1.EntityMetadata.define(PickEntityClass);
122
- entity_metadata_js_1.EntityMetadata.mixin(trgMeta, srcMeta, filter);
118
+ const trgMeta = EntityMetadata.define(PickEntityClass);
119
+ EntityMetadata.mixin(trgMeta, srcMeta, filter);
123
120
  }
124
121
  return PickEntityClass;
125
122
  }
@@ -132,11 +129,11 @@ function Entity(options) {
132
129
  };
133
130
  const omitKeys = keys.map(x => x.toLowerCase());
134
131
  const filter = k => !omitKeys.includes(k.toLowerCase());
135
- (0, apply_mixins_js_1.applyMixins)(OmitEntityClass, classRef, filter);
136
- const srcMeta = entity_metadata_js_1.EntityMetadata.get(classRef);
132
+ applyMixins(OmitEntityClass, classRef, filter);
133
+ const srcMeta = EntityMetadata.get(classRef);
137
134
  if (srcMeta) {
138
- const trgMeta = entity_metadata_js_1.EntityMetadata.define(OmitEntityClass);
139
- entity_metadata_js_1.EntityMetadata.mixin(trgMeta, srcMeta, filter);
135
+ const trgMeta = EntityMetadata.define(OmitEntityClass);
136
+ EntityMetadata.mixin(trgMeta, srcMeta, filter);
140
137
  }
141
138
  return OmitEntityClass;
142
139
  }
@@ -149,17 +146,17 @@ function Entity(options) {
149
146
  }
150
147
  };
151
148
  for (const base of bases) {
152
- (0, apply_mixins_js_1.applyMixins)(UnionClass, base);
153
- const srcMeta = entity_metadata_js_1.EntityMetadata.get(base);
149
+ applyMixins(UnionClass, base);
150
+ const srcMeta = EntityMetadata.get(base);
154
151
  if (srcMeta) {
155
- const trgMeta = entity_metadata_js_1.EntityMetadata.define(UnionClass);
156
- entity_metadata_js_1.EntityMetadata.mixin(trgMeta, srcMeta);
152
+ const trgMeta = EntityMetadata.define(UnionClass);
153
+ EntityMetadata.mixin(trgMeta, srcMeta);
157
154
  }
158
155
  }
159
156
  return UnionClass;
160
157
  }
161
158
  Entity.Union = Union;
162
- })(Entity || (exports.Entity = Entity = {}));
159
+ })(Entity || (Entity = {}));
163
160
  function applyConstructorProperties(target, sourceClass, constructorArgs, isPropertyInherited) {
164
161
  try {
165
162
  const tempInstance = new sourceClass(...constructorArgs);
@@ -1,63 +1,55 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BeforeInsert = BeforeInsert;
4
- exports.BeforeUpdate = BeforeUpdate;
5
- exports.BeforeDestroy = BeforeDestroy;
6
- exports.AfterInsert = AfterInsert;
7
- exports.AfterUpdate = AfterUpdate;
8
- exports.AfterDestroy = AfterDestroy;
9
- const entity_metadata_js_1 = require("../model/entity-metadata.js");
10
- function BeforeInsert() {
1
+ import { EntityMetadata } from '../model/entity-metadata.js';
2
+ export function BeforeInsert() {
11
3
  return (target, propertyKey) => {
12
4
  if (typeof propertyKey !== 'string')
13
5
  throw new Error('You can define a Column for only string properties');
14
- const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
6
+ const model = EntityMetadata.define(target.constructor);
15
7
  const fn = target.constructor.prototype[propertyKey];
16
- entity_metadata_js_1.EntityMetadata.addEventListener(model, 'before-insert', fn);
8
+ EntityMetadata.addEventListener(model, 'before-insert', fn);
17
9
  };
18
10
  }
19
- function BeforeUpdate() {
11
+ export function BeforeUpdate() {
20
12
  return (target, propertyKey) => {
21
13
  if (typeof propertyKey !== 'string')
22
14
  throw new Error('You can define a Column for only string properties');
23
- const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
15
+ const model = EntityMetadata.define(target.constructor);
24
16
  const fn = target.constructor.prototype[propertyKey];
25
- entity_metadata_js_1.EntityMetadata.addEventListener(model, 'before-update', fn);
17
+ EntityMetadata.addEventListener(model, 'before-update', fn);
26
18
  };
27
19
  }
28
- function BeforeDestroy() {
20
+ export function BeforeDestroy() {
29
21
  return (target, propertyKey) => {
30
22
  if (typeof propertyKey !== 'string')
31
23
  throw new Error('You can define a Column for only string properties');
32
- const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
24
+ const model = EntityMetadata.define(target.constructor);
33
25
  const fn = target.constructor.prototype[propertyKey];
34
- entity_metadata_js_1.EntityMetadata.addEventListener(model, 'before-destroy', fn);
26
+ EntityMetadata.addEventListener(model, 'before-destroy', fn);
35
27
  };
36
28
  }
37
- function AfterInsert() {
29
+ export function AfterInsert() {
38
30
  return (target, propertyKey) => {
39
31
  if (typeof propertyKey !== 'string')
40
32
  throw new Error('You can define a Column for only string properties');
41
- const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
33
+ const model = EntityMetadata.define(target.constructor);
42
34
  const fn = target.constructor.prototype[propertyKey];
43
- entity_metadata_js_1.EntityMetadata.addEventListener(model, 'after-insert', fn);
35
+ EntityMetadata.addEventListener(model, 'after-insert', fn);
44
36
  };
45
37
  }
46
- function AfterUpdate() {
38
+ export function AfterUpdate() {
47
39
  return (target, propertyKey) => {
48
40
  if (typeof propertyKey !== 'string')
49
41
  throw new Error('You can define a Column for only string properties');
50
- const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
42
+ const model = EntityMetadata.define(target.constructor);
51
43
  const fn = target.constructor.prototype[propertyKey];
52
- entity_metadata_js_1.EntityMetadata.addEventListener(model, 'after-update', fn);
44
+ EntityMetadata.addEventListener(model, 'after-update', fn);
53
45
  };
54
46
  }
55
- function AfterDestroy() {
47
+ export function AfterDestroy() {
56
48
  return (target, propertyKey) => {
57
49
  if (typeof propertyKey !== 'string')
58
50
  throw new Error('You can define a Column for only string properties');
59
- const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
51
+ const model = EntityMetadata.define(target.constructor);
60
52
  const fn = target.constructor.prototype[propertyKey];
61
- entity_metadata_js_1.EntityMetadata.addEventListener(model, 'after-destroy', fn);
53
+ EntityMetadata.addEventListener(model, 'after-destroy', fn);
62
54
  };
63
55
  }
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ForeignKey = ForeignKey;
4
- const entity_metadata_js_1 = require("../model/entity-metadata.js");
5
- function ForeignKey(type, targetKey) {
1
+ import { EntityMetadata } from '../model/entity-metadata.js';
2
+ export function ForeignKey(type, targetKey) {
6
3
  return function (target, propertyKey) {
7
4
  if (typeof propertyKey !== 'string')
8
5
  throw new Error('Symbol properties are not accepted');
9
- const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
10
- entity_metadata_js_1.EntityMetadata.addForeignKey(entity, propertyKey, type, targetKey);
6
+ const entity = EntityMetadata.define(target.constructor);
7
+ EntityMetadata.addForeignKey(entity, propertyKey, type, targetKey);
11
8
  };
12
9
  }
@@ -1,20 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Index = Index;
4
- const entity_metadata_js_1 = require("../model/entity-metadata.js");
5
- function Index(arg0, arg1) {
1
+ import { EntityMetadata } from '../model/entity-metadata.js';
2
+ export function Index(arg0, arg1) {
6
3
  return function (target, propertyKey) {
7
4
  if (typeof target === 'function') {
8
5
  if (!(typeof arg0 === 'string' || Array.isArray(arg0)))
9
6
  throw new Error(`You must specify index column(s)`);
10
- const model = entity_metadata_js_1.EntityMetadata.define(target);
11
- return entity_metadata_js_1.EntityMetadata.addIndex(model, { ...arg1, columns: arg0 });
7
+ const model = EntityMetadata.define(target);
8
+ return EntityMetadata.addIndex(model, { ...arg1, columns: arg0 });
12
9
  }
13
10
  if (!target.constructor)
14
11
  throw new Error('Property decorators can be used for class properties only');
15
12
  if (typeof propertyKey !== 'string')
16
13
  throw new Error('Index() decorator can be used for string property keys only');
17
- const model = entity_metadata_js_1.EntityMetadata.define(target.constructor);
18
- entity_metadata_js_1.EntityMetadata.addIndex(model, { ...arg0, columns: [propertyKey] });
14
+ const model = EntityMetadata.define(target.constructor);
15
+ EntityMetadata.addIndex(model, { ...arg0, columns: [propertyKey] });
19
16
  };
20
17
  }
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Link = Link;
4
- const entity_metadata_js_1 = require("../model/entity-metadata.js");
5
- const link_chain_js_1 = require("../model/link-chain.js");
6
- function Link(options) {
1
+ import { EntityMetadata } from '../model/entity-metadata.js';
2
+ import { LinkChain } from '../model/link-chain.js';
3
+ export function Link(options) {
7
4
  let root;
8
5
  let chain;
9
6
  const fn = (target, propertyKey) => {
@@ -14,7 +11,7 @@ function Link(options) {
14
11
  if (reflectType === Array) {
15
12
  throw new TypeError(`Can't get type information while it is an array. Please define entity type`);
16
13
  }
17
- if (!entity_metadata_js_1.EntityMetadata.get(reflectType))
14
+ if (!EntityMetadata.get(reflectType))
18
15
  throw new TypeError(`No entity metadata found for type "${reflectType}"`);
19
16
  fn.toOne(reflectType);
20
17
  }
@@ -24,11 +21,11 @@ function Link(options) {
24
21
  if (reflectType === Array && !root.first.returnsMany()) {
25
22
  throw new TypeError(`Link returns array of instances however property type is not an array`);
26
23
  }
27
- const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
24
+ const entity = EntityMetadata.define(target.constructor);
28
25
  // @ts-ignore
29
26
  // noinspection JSConstantReassignment
30
27
  root.first.source = entity.ctor;
31
- entity_metadata_js_1.EntityMetadata.defineAssociationField(entity, propertyKey, root.first, options);
28
+ EntityMetadata.defineAssociationField(entity, propertyKey, root.first, options);
32
29
  };
33
30
  fn.toOne = (type, args) => {
34
31
  if (chain) {
@@ -62,11 +59,11 @@ function Link(options) {
62
59
  * Crates an Link Chain object
63
60
  */
64
61
  function linkToOne(type, targetKey, sourceKey) {
65
- return new link_chain_js_1.LinkChain(type, targetKey, sourceKey);
62
+ return new LinkChain(type, targetKey, sourceKey);
66
63
  }
67
64
  /**
68
65
  * Crates an Link Chain object
69
66
  */
70
67
  function linkToMany(type, targetKey, sourceKey) {
71
- return new link_chain_js_1.LinkChain(type, targetKey, sourceKey, true);
68
+ return new LinkChain(type, targetKey, sourceKey, true);
72
69
  }
@@ -1,24 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PrimaryKey = PrimaryKey;
4
- const entity_metadata_js_1 = require("../model/entity-metadata.js");
5
- const column_decorator_js_1 = require("./column.decorator.js");
6
- function PrimaryKey(arg0, arg1) {
1
+ import { EntityMetadata } from '../model/entity-metadata.js';
2
+ import { Column } from './column.decorator.js';
3
+ export function PrimaryKey(arg0, arg1) {
7
4
  return function (target, propertyKey) {
8
5
  if (arguments.length === 1) {
9
6
  if (!(typeof arg0 === 'string' || Array.isArray(arg0))) {
10
7
  throw new Error(`You must specify primary index column(s)`);
11
8
  }
12
- const meta = entity_metadata_js_1.EntityMetadata.define(target);
13
- entity_metadata_js_1.EntityMetadata.setPrimaryKeys(meta, arg0, arg1);
9
+ const meta = EntityMetadata.define(target);
10
+ EntityMetadata.setPrimaryKeys(meta, arg0, arg1);
14
11
  return;
15
12
  }
16
13
  if (!target.constructor)
17
14
  throw new Error('Property decorators can be used for class properties only');
18
15
  if (typeof propertyKey !== 'string')
19
16
  throw new Error('Index() decorator can be used for string property keys only');
20
- const meta = entity_metadata_js_1.EntityMetadata.define(target.constructor);
21
- (0, column_decorator_js_1.Column)({ notNull: true })(target, propertyKey);
22
- entity_metadata_js_1.EntityMetadata.setPrimaryKeys(meta, propertyKey, arg0);
17
+ const meta = EntityMetadata.define(target.constructor);
18
+ Column({ notNull: true })(target, propertyKey);
19
+ EntityMetadata.setPrimaryKeys(meta, propertyKey, arg0);
23
20
  };
24
21
  }
@@ -1,21 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Parse = Parse;
4
- exports.Serialize = Serialize;
5
- const entity_metadata_js_1 = require("../model/entity-metadata.js");
6
- function Parse(fn) {
1
+ import { EntityMetadata } from '../model/entity-metadata.js';
2
+ export function Parse(fn) {
7
3
  return (target, propertyKey) => {
8
4
  if (typeof propertyKey !== 'string')
9
5
  throw new Error('You can define a Column for only string properties');
10
- const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
11
- entity_metadata_js_1.EntityMetadata.defineColumnField(entity, propertyKey).parse = fn;
6
+ const entity = EntityMetadata.define(target.constructor);
7
+ EntityMetadata.defineColumnField(entity, propertyKey).parse = fn;
12
8
  };
13
9
  }
14
- function Serialize(fn) {
10
+ export function Serialize(fn) {
15
11
  return (target, propertyKey) => {
16
12
  if (typeof propertyKey !== 'string')
17
13
  throw new Error('You can define a Column for only string properties');
18
- const entity = entity_metadata_js_1.EntityMetadata.define(target.constructor);
19
- entity_metadata_js_1.EntityMetadata.defineColumnField(entity, propertyKey).serialize = fn;
14
+ const entity = EntityMetadata.define(target.constructor);
15
+ EntityMetadata.defineColumnField(entity, propertyKey).serialize = fn;
20
16
  };
21
17
  }
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AssociationFieldMetadata = void 0;
4
- const tslib_1 = require("tslib");
5
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
6
- var AssociationFieldMetadata;
1
+ import _ from 'lodash';
2
+ export var AssociationFieldMetadata;
7
3
  (function (AssociationFieldMetadata) {
8
4
  function create(entity, name, association, options = {}) {
9
5
  const result = {
@@ -18,7 +14,7 @@ var AssociationFieldMetadata;
18
14
  }
19
15
  AssociationFieldMetadata.create = create;
20
16
  function assign(target, options) {
21
- Object.assign(target, lodash_1.default.omit(options, ['entity', 'name', 'kind', 'association']));
17
+ Object.assign(target, _.omit(options, ['entity', 'name', 'kind', 'association']));
22
18
  }
23
19
  AssociationFieldMetadata.assign = assign;
24
- })(AssociationFieldMetadata || (exports.AssociationFieldMetadata = AssociationFieldMetadata = {}));
20
+ })(AssociationFieldMetadata || (AssociationFieldMetadata = {}));
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AssociationNode = void 0;
4
- const association_js_1 = require("./association.js");
5
- class AssociationNode extends association_js_1.Association {
1
+ import { Association } from './association.js';
2
+ export class AssociationNode extends Association {
6
3
  getFirst() {
7
4
  let l = this;
8
5
  while (l.prior)
@@ -22,4 +19,3 @@ class AssociationNode extends association_js_1.Association {
22
19
  return !!(this.next && this.next.returnsMany());
23
20
  }
24
21
  }
25
- exports.AssociationNode = AssociationNode;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Association = void 0;
4
- const putil_varhelpers_1 = require("putil-varhelpers");
5
- const orm_helper_js_1 = require("../util/orm.helper.js");
6
- const entity_metadata_js_1 = require("./entity-metadata.js");
7
- class Association {
1
+ import { camelCase } from 'putil-varhelpers';
2
+ import { resolveEntityMeta } from '../util/orm.helper.js';
3
+ import { EntityMetadata } from './entity-metadata.js';
4
+ export class Association {
8
5
  constructor(name, args) {
9
6
  this.name = name;
10
7
  this.source = args.source;
@@ -14,13 +11,13 @@ class Association {
14
11
  this.many = !!args.many;
15
12
  }
16
13
  async resolveSource() {
17
- this._source = await (0, orm_helper_js_1.resolveEntityMeta)(this.source);
14
+ this._source = await resolveEntityMeta(this.source);
18
15
  if (!this._source)
19
16
  throw new Error(`Can't resolve source entity of association "${this.name}"`);
20
17
  return this._source;
21
18
  }
22
19
  async resolveTarget() {
23
- this._target = await (0, orm_helper_js_1.resolveEntityMeta)(this.target);
20
+ this._target = await resolveEntityMeta(this.target);
24
21
  if (!this._target)
25
22
  throw new Error(`Can't resolve target entity of association "${this.name}"`);
26
23
  return this._target;
@@ -57,7 +54,7 @@ class Association {
57
54
  let targetKey = this.targetKey || '';
58
55
  if (!(sourceKey && targetKey)) {
59
56
  // Try to determine key fields from foreign key from source to target
60
- let foreign = await entity_metadata_js_1.EntityMetadata.getForeignKeyFor(source, target);
57
+ let foreign = await EntityMetadata.getForeignKeyFor(source, target);
61
58
  if (foreign && foreign !== this) {
62
59
  await foreign._resolveKeys();
63
60
  this._sourceKey = foreign._sourceKey;
@@ -67,7 +64,7 @@ class Association {
67
64
  return;
68
65
  }
69
66
  // Try to determine key fields from foreign key from target to source
70
- foreign = await entity_metadata_js_1.EntityMetadata.getForeignKeyFor(target, source);
67
+ foreign = await EntityMetadata.getForeignKeyFor(target, source);
71
68
  if (foreign && foreign !== this) {
72
69
  await foreign._resolveKeys();
73
70
  this._sourceKey = foreign._targetKey;
@@ -78,39 +75,38 @@ class Association {
78
75
  }
79
76
  if (this.many) {
80
77
  if (!sourceKey) {
81
- const primaryIndexColumns = entity_metadata_js_1.EntityMetadata.getPrimaryIndexColumns(source);
78
+ const primaryIndexColumns = EntityMetadata.getPrimaryIndexColumns(source);
82
79
  sourceKey = primaryIndexColumns && primaryIndexColumns.length === 1 ? primaryIndexColumns[0].name : 'id';
83
80
  }
84
81
  if (!targetKey && sourceKey) {
85
82
  // snake-case
86
83
  let s = source.name[0].toLowerCase() + source.name.substring(1) + '_' + sourceKey;
87
- if (!entity_metadata_js_1.EntityMetadata.getColumnField(target, s))
88
- s = (0, putil_varhelpers_1.camelCase)(s);
84
+ if (!EntityMetadata.getColumnField(target, s))
85
+ s = camelCase(s);
89
86
  targetKey = s;
90
87
  }
91
88
  }
92
89
  else {
93
90
  if (!targetKey) {
94
- const primaryIndexColumns = entity_metadata_js_1.EntityMetadata.getPrimaryIndexColumns(target);
91
+ const primaryIndexColumns = EntityMetadata.getPrimaryIndexColumns(target);
95
92
  targetKey = primaryIndexColumns && primaryIndexColumns.length === 1 ? primaryIndexColumns[0].name : 'id';
96
93
  }
97
94
  if (!sourceKey && targetKey) {
98
95
  // snake-case
99
96
  let s = target.name[0].toLowerCase() + target.name.substring(1) + '_' + targetKey;
100
- if (!entity_metadata_js_1.EntityMetadata.getColumnField(source, s))
101
- s = (0, putil_varhelpers_1.camelCase)(s);
97
+ if (!EntityMetadata.getColumnField(source, s))
98
+ s = camelCase(s);
102
99
  sourceKey = s;
103
100
  }
104
101
  }
105
102
  }
106
- this._targetProperty = entity_metadata_js_1.EntityMetadata.getColumnField(target, targetKey);
103
+ this._targetProperty = EntityMetadata.getColumnField(target, targetKey);
107
104
  if (!this._targetProperty)
108
105
  throw new Error(`Can't determine target key of ${this.name}`);
109
- this._sourceProperty = entity_metadata_js_1.EntityMetadata.getColumnField(source, sourceKey);
106
+ this._sourceProperty = EntityMetadata.getColumnField(source, sourceKey);
110
107
  if (!this._sourceProperty)
111
108
  throw new Error(`Can't determine source key of ${this.name}`);
112
109
  this._targetKey = targetKey;
113
110
  this._sourceKey = sourceKey;
114
111
  }
115
112
  }
116
- exports.Association = Association;
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ColumnFieldMetadata = void 0;
4
- const tslib_1 = require("tslib");
5
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
6
- var ColumnFieldMetadata;
1
+ import _ from 'lodash';
2
+ export var ColumnFieldMetadata;
7
3
  (function (ColumnFieldMetadata) {
8
4
  function create(entity, name, options = {}) {
9
5
  const result = {
@@ -18,7 +14,7 @@ var ColumnFieldMetadata;
18
14
  }
19
15
  ColumnFieldMetadata.create = create;
20
16
  function assign(target, options) {
21
- Object.assign(target, lodash_1.default.omit(options, ['entity', 'name', 'kind']));
17
+ Object.assign(target, _.omit(options, ['entity', 'name', 'kind']));
22
18
  }
23
19
  ColumnFieldMetadata.assign = assign;
24
20
  function checkEnumValue(col, v) {
@@ -29,4 +25,4 @@ var ColumnFieldMetadata;
29
25
  throw new Error(`${col.entity.name}.${col.name} value must be one of (${enumKeys})`);
30
26
  }
31
27
  ColumnFieldMetadata.checkEnumValue = checkEnumValue;
32
- })(ColumnFieldMetadata || (exports.ColumnFieldMetadata = ColumnFieldMetadata = {}));
28
+ })(ColumnFieldMetadata || (ColumnFieldMetadata = {}));
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EmbeddedFieldMetadata = void 0;
4
- const orm_helper_js_1 = require("../util/orm.helper.js");
5
- var EmbeddedFieldMetadata;
1
+ import { resolveEntityMeta } from '../util/orm.helper.js';
2
+ export var EmbeddedFieldMetadata;
6
3
  (function (EmbeddedFieldMetadata) {
7
4
  function create(entity, name, type, options) {
8
5
  const result = {
@@ -19,10 +16,10 @@ var EmbeddedFieldMetadata;
19
16
  }
20
17
  EmbeddedFieldMetadata.create = create;
21
18
  async function resolveType(meta) {
22
- const typ = await (0, orm_helper_js_1.resolveEntityMeta)(meta.type);
19
+ const typ = await resolveEntityMeta(meta.type);
23
20
  if (typ)
24
21
  return typ;
25
22
  throw new Error(`Can't resolve type of ${meta.entity.name}.${meta.name}`);
26
23
  }
27
24
  EmbeddedFieldMetadata.resolveType = resolveType;
28
- })(EmbeddedFieldMetadata || (exports.EmbeddedFieldMetadata = EmbeddedFieldMetadata = {}));
25
+ })(EmbeddedFieldMetadata || (EmbeddedFieldMetadata = {}));