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