@sqb/connect 4.0.9 → 4.0.13

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 (89) hide show
  1. package/dist/client/Adapter.d.ts +57 -0
  2. package/dist/client/Adapter.js +2 -0
  3. package/dist/client/Cursor.d.ts +116 -0
  4. package/dist/client/Cursor.js +250 -0
  5. package/dist/client/CursorStream.d.ts +29 -0
  6. package/dist/client/CursorStream.js +98 -0
  7. package/dist/client/FieldInfoMap.d.ts +10 -0
  8. package/dist/client/FieldInfoMap.js +33 -0
  9. package/dist/client/SqbClient.d.ts +70 -0
  10. package/dist/client/SqbClient.js +165 -0
  11. package/dist/client/SqbConnection.d.ts +74 -0
  12. package/dist/client/SqbConnection.js +272 -0
  13. package/dist/client/extensions.d.ts +4 -0
  14. package/dist/client/extensions.js +14 -0
  15. package/dist/client/helpers.d.ts +9 -0
  16. package/dist/client/helpers.js +133 -0
  17. package/dist/client/types.d.ts +189 -0
  18. package/dist/client/types.js +5 -0
  19. package/dist/index.d.ts +28 -0
  20. package/dist/index.js +37 -0
  21. package/dist/orm/base-entity.class.d.ts +16 -0
  22. package/dist/orm/base-entity.class.js +56 -0
  23. package/dist/orm/commands/command.helper.d.ts +14 -0
  24. package/dist/orm/commands/command.helper.js +140 -0
  25. package/dist/orm/commands/count.command.d.ts +11 -0
  26. package/dist/orm/commands/count.command.js +30 -0
  27. package/dist/orm/commands/create.command.d.ts +20 -0
  28. package/dist/orm/commands/create.command.js +83 -0
  29. package/dist/orm/commands/destroy.command.d.ts +11 -0
  30. package/dist/orm/commands/destroy.command.js +30 -0
  31. package/dist/orm/commands/find.command.d.ts +44 -0
  32. package/dist/orm/commands/find.command.js +308 -0
  33. package/dist/orm/commands/row-converter.d.ts +55 -0
  34. package/dist/orm/commands/row-converter.js +187 -0
  35. package/dist/orm/commands/update.command.d.ts +22 -0
  36. package/dist/orm/commands/update.command.js +82 -0
  37. package/dist/orm/decorators/column.decorator.d.ts +4 -0
  38. package/dist/orm/decorators/column.decorator.js +14 -0
  39. package/dist/orm/decorators/embedded.decorator.d.ts +2 -0
  40. package/dist/orm/decorators/embedded.decorator.js +17 -0
  41. package/dist/orm/decorators/entity.decorator.d.ts +6 -0
  42. package/dist/orm/decorators/entity.decorator.js +23 -0
  43. package/dist/orm/decorators/events.decorator.d.ts +6 -0
  44. package/dist/orm/decorators/events.decorator.js +76 -0
  45. package/dist/orm/decorators/foreignkey.decorator.d.ts +2 -0
  46. package/dist/orm/decorators/foreignkey.decorator.js +13 -0
  47. package/dist/orm/decorators/index.decorator.d.ts +3 -0
  48. package/dist/orm/decorators/index.decorator.js +22 -0
  49. package/dist/orm/decorators/link.decorator.d.ts +23 -0
  50. package/dist/orm/decorators/link.decorator.js +88 -0
  51. package/dist/orm/decorators/primarykey.decorator.d.ts +3 -0
  52. package/dist/orm/decorators/primarykey.decorator.js +23 -0
  53. package/dist/orm/decorators/transform.decorator.d.ts +3 -0
  54. package/dist/orm/decorators/transform.decorator.js +24 -0
  55. package/dist/orm/model/abstract-entityelement.d.ts +8 -0
  56. package/dist/orm/model/abstract-entityelement.js +10 -0
  57. package/dist/orm/model/association-node.d.ts +9 -0
  58. package/dist/orm/model/association-node.js +25 -0
  59. package/dist/orm/model/association.d.ts +28 -0
  60. package/dist/orm/model/association.js +129 -0
  61. package/dist/orm/model/entity-association-element.d.ts +9 -0
  62. package/dist/orm/model/entity-association-element.js +13 -0
  63. package/dist/orm/model/entity-column-element.d.ts +68 -0
  64. package/dist/orm/model/entity-column-element.js +27 -0
  65. package/dist/orm/model/entity-model.d.ts +59 -0
  66. package/dist/orm/model/entity-model.js +295 -0
  67. package/dist/orm/model/entity-object-element.d.ts +12 -0
  68. package/dist/orm/model/entity-object-element.js +24 -0
  69. package/dist/orm/model/index-meta.d.ts +9 -0
  70. package/dist/orm/model/index-meta.js +16 -0
  71. package/dist/orm/model/link-chain.d.ts +15 -0
  72. package/dist/orm/model/link-chain.js +50 -0
  73. package/dist/orm/orm.const.d.ts +2 -0
  74. package/dist/orm/orm.const.js +5 -0
  75. package/dist/orm/orm.type.d.ts +112 -0
  76. package/dist/orm/orm.type.js +2 -0
  77. package/dist/orm/repository.class.d.ts +125 -0
  78. package/dist/orm/repository.class.js +217 -0
  79. package/dist/orm/util/entity-mapping.d.ts +12 -0
  80. package/dist/orm/util/entity-mapping.js +154 -0
  81. package/dist/orm/util/extract-keyvalues.d.ts +2 -0
  82. package/dist/orm/util/extract-keyvalues.js +60 -0
  83. package/dist/orm/util/orm.helper.d.ts +14 -0
  84. package/dist/orm/util/orm.helper.js +39 -0
  85. package/dist/orm/util/serialize-element.d.ts +2 -0
  86. package/dist/orm/util/serialize-element.js +43 -0
  87. package/dist/types.d.ts +2 -0
  88. package/dist/types.js +2 -0
  89. package/package.json +3 -3
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UpdateCommand = void 0;
4
+ const builder_1 = require("@sqb/builder");
5
+ const command_helper_1 = require("./command.helper");
6
+ const orm_helper_1 = require("../util/orm.helper");
7
+ class UpdateCommand {
8
+ // istanbul ignore next
9
+ constructor() {
10
+ throw new Error('This class is abstract');
11
+ }
12
+ static async execute(args) {
13
+ const { entity } = args;
14
+ const tableName = entity.tableName;
15
+ if (!tableName)
16
+ throw new Error(`${entity.ctor.name} is not decorated with @Entity decorator`);
17
+ // Create a context
18
+ const ctx = {
19
+ entity,
20
+ queryParams: {},
21
+ queryValues: {},
22
+ queryFilter: [],
23
+ colCount: 0,
24
+ };
25
+ // Prepare
26
+ await this._prepareParams(ctx, entity, args.values);
27
+ if (!ctx.colCount)
28
+ return 0;
29
+ if (args.filter)
30
+ await this._prepareFilter(ctx, args.filter);
31
+ const query = (0, builder_1.Update)(tableName + ' as T', ctx.queryValues)
32
+ .where(...ctx.queryFilter);
33
+ const qr = await args.connection.execute(query, {
34
+ params: args.params ? [...args.params, ctx.queryParams] : ctx.queryParams,
35
+ objectRows: false,
36
+ cursor: false
37
+ });
38
+ return qr.rowsAffected || 0;
39
+ }
40
+ static async _prepareFilter(ctx, filter) {
41
+ if (filter) {
42
+ const where = (0, builder_1.And)();
43
+ await (0, command_helper_1.prepareFilter)(ctx.entity, filter, where);
44
+ ctx.queryFilter.push(...where._items);
45
+ }
46
+ }
47
+ static async _prepareParams(ctx, entity, values, prefix, suffix) {
48
+ let v;
49
+ prefix = prefix || '';
50
+ suffix = suffix || '';
51
+ for (const col of entity.elements.values()) {
52
+ v = values[col.name];
53
+ if (v === undefined)
54
+ continue;
55
+ if ((0, orm_helper_1.isColumnElement)(col)) {
56
+ if (col.noUpdate)
57
+ continue;
58
+ if (typeof col.serialize === 'function')
59
+ v = col.serialize(v, col.name);
60
+ if (v === null && col.notNull)
61
+ throw new Error(`${entity.name}.${col.name} is required and can't be null`);
62
+ if (v === undefined)
63
+ continue;
64
+ col.checkEnumValue(v);
65
+ const fieldName = prefix + col.fieldName + suffix;
66
+ const k = '$input_' + fieldName;
67
+ ctx.queryValues[fieldName] = (0, builder_1.Param)({
68
+ name: k,
69
+ dataType: col.dataType,
70
+ isArray: col.isArray
71
+ });
72
+ ctx.queryParams[k] = v;
73
+ ctx.colCount++;
74
+ }
75
+ else if (v != null && (0, orm_helper_1.isObjectElement)(col)) {
76
+ const type = await col.resolveType();
77
+ await this._prepareParams(ctx, type, v, col.fieldNamePrefix, col.fieldNameSuffix);
78
+ }
79
+ }
80
+ }
81
+ }
82
+ exports.UpdateCommand = UpdateCommand;
@@ -0,0 +1,4 @@
1
+ import { DataType } from '@sqb/builder';
2
+ import { DataPropertyOptions } from '../orm.type';
3
+ export declare function Column(type?: DataType): PropertyDecorator;
4
+ export declare function Column(options?: DataPropertyOptions): PropertyDecorator;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Column = void 0;
4
+ const entity_model_1 = require("../model/entity-model");
5
+ function Column(arg0) {
6
+ return (target, propertyKey) => {
7
+ if (typeof propertyKey !== 'string')
8
+ throw new Error('Symbol properties are not accepted');
9
+ const options = typeof arg0 === 'string' ? { dataType: arg0 } : arg0;
10
+ entity_model_1.EntityModel.attachTo(target.constructor)
11
+ .defineColumnElement(propertyKey, options);
12
+ };
13
+ }
14
+ exports.Column = Column;
@@ -0,0 +1,2 @@
1
+ import { EmbeddedTypeOptions, TypeThunk } from '../orm.type';
2
+ export declare function Embedded(type?: TypeThunk, options?: EmbeddedTypeOptions): PropertyDecorator;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Embedded = void 0;
4
+ const entity_model_1 = require("../model/entity-model");
5
+ function Embedded(type, options) {
6
+ return (target, propertyKey) => {
7
+ if (typeof propertyKey !== 'string')
8
+ throw new Error('Symbol properties are not accepted');
9
+ const el = entity_model_1.EntityModel.attachTo(target.constructor)
10
+ .defineObjectElement(propertyKey, type);
11
+ if (options?.fieldNamePrefix)
12
+ el.fieldNamePrefix = options.fieldNamePrefix;
13
+ if (options?.fieldNameSuffix)
14
+ el.fieldNameSuffix = options.fieldNameSuffix;
15
+ };
16
+ }
17
+ exports.Embedded = Embedded;
@@ -0,0 +1,6 @@
1
+ import { EntityModel } from '../model/entity-model';
2
+ import { EntityConfig } from '../orm.type';
3
+ export declare function Entity(options?: EntityConfig | string): ClassDecorator;
4
+ export declare namespace Entity {
5
+ function getMetadata(ctor: Function): EntityModel | undefined;
6
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Entity = void 0;
4
+ const entity_model_1 = require("../model/entity-model");
5
+ function Entity(options) {
6
+ return function (target) {
7
+ const opts = typeof options === 'object' ? options : {};
8
+ const tableName = typeof options === 'string' ? options : opts.tableName;
9
+ const entity = entity_model_1.EntityModel.attachTo(target);
10
+ entity.tableName = tableName || target.name;
11
+ if (opts.schema)
12
+ entity.schema = opts.schema;
13
+ if (opts.comment)
14
+ entity.comment = opts.comment;
15
+ };
16
+ }
17
+ exports.Entity = Entity;
18
+ (function (Entity) {
19
+ function getMetadata(ctor) {
20
+ return entity_model_1.EntityModel.get(ctor);
21
+ }
22
+ Entity.getMetadata = getMetadata;
23
+ })(Entity = exports.Entity || (exports.Entity = {}));
@@ -0,0 +1,6 @@
1
+ export declare function BeforeInsert(): PropertyDecorator;
2
+ export declare function BeforeUpdate(): PropertyDecorator;
3
+ export declare function BeforeDestroy(): PropertyDecorator;
4
+ export declare function AfterInsert(): PropertyDecorator;
5
+ export declare function AfterUpdate(): PropertyDecorator;
6
+ export declare function AfterDestroy(): PropertyDecorator;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AfterDestroy = exports.AfterUpdate = exports.AfterInsert = exports.BeforeDestroy = exports.BeforeUpdate = exports.BeforeInsert = void 0;
4
+ const entity_model_1 = require("../model/entity-model");
5
+ function BeforeInsert() {
6
+ return (target, propertyKey) => {
7
+ if (typeof propertyKey !== 'string')
8
+ throw new Error('You can define a Column for only string properties');
9
+ const entity = entity_model_1.EntityModel.attachTo(target.constructor);
10
+ const fn = target.constructor.prototype[propertyKey];
11
+ if (typeof fn !== 'function')
12
+ throw new Error('Property must be a function');
13
+ entity.before('insert', fn);
14
+ };
15
+ }
16
+ exports.BeforeInsert = BeforeInsert;
17
+ function BeforeUpdate() {
18
+ return (target, propertyKey) => {
19
+ if (typeof propertyKey !== 'string')
20
+ throw new Error('You can define a Column for only string properties');
21
+ const entity = entity_model_1.EntityModel.attachTo(target.constructor);
22
+ const fn = target.constructor.prototype[propertyKey];
23
+ if (typeof fn !== 'function')
24
+ throw new Error('Property must be a function');
25
+ entity.before('update', fn);
26
+ };
27
+ }
28
+ exports.BeforeUpdate = BeforeUpdate;
29
+ function BeforeDestroy() {
30
+ return (target, propertyKey) => {
31
+ if (typeof propertyKey !== 'string')
32
+ throw new Error('You can define a Column for only string properties');
33
+ const entity = entity_model_1.EntityModel.attachTo(target.constructor);
34
+ const fn = target.constructor.prototype[propertyKey];
35
+ if (typeof fn !== 'function')
36
+ throw new Error('Property must be a function');
37
+ entity.before('destroy', fn);
38
+ };
39
+ }
40
+ exports.BeforeDestroy = BeforeDestroy;
41
+ function AfterInsert() {
42
+ return (target, propertyKey) => {
43
+ if (typeof propertyKey !== 'string')
44
+ throw new Error('You can define a Column for only string properties');
45
+ const entity = entity_model_1.EntityModel.attachTo(target.constructor);
46
+ const fn = target.constructor.prototype[propertyKey];
47
+ if (typeof fn !== 'function')
48
+ throw new Error('Property must be a function');
49
+ entity.after('insert', fn);
50
+ };
51
+ }
52
+ exports.AfterInsert = AfterInsert;
53
+ function AfterUpdate() {
54
+ return (target, propertyKey) => {
55
+ if (typeof propertyKey !== 'string')
56
+ throw new Error('You can define a Column for only string properties');
57
+ const entity = entity_model_1.EntityModel.attachTo(target.constructor);
58
+ const fn = target.constructor.prototype[propertyKey];
59
+ if (typeof fn !== 'function')
60
+ throw new Error('Property must be a function');
61
+ entity.after('update', fn);
62
+ };
63
+ }
64
+ exports.AfterUpdate = AfterUpdate;
65
+ function AfterDestroy() {
66
+ return (target, propertyKey) => {
67
+ if (typeof propertyKey !== 'string')
68
+ throw new Error('You can define a Column for only string properties');
69
+ const entity = entity_model_1.EntityModel.attachTo(target.constructor);
70
+ const fn = target.constructor.prototype[propertyKey];
71
+ if (typeof fn !== 'function')
72
+ throw new Error('Property must be a function');
73
+ entity.after('destroy', fn);
74
+ };
75
+ }
76
+ exports.AfterDestroy = AfterDestroy;
@@ -0,0 +1,2 @@
1
+ import { TypeThunk } from '../orm.type';
2
+ export declare function ForeignKey(type: TypeThunk, targetKey?: string): PropertyDecorator;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ForeignKey = void 0;
4
+ const entity_model_1 = require("../model/entity-model");
5
+ function ForeignKey(type, targetKey) {
6
+ return function (target, propertyKey) {
7
+ if (typeof propertyKey !== 'string')
8
+ throw new Error('Symbol properties are not accepted');
9
+ entity_model_1.EntityModel.attachTo(target.constructor)
10
+ .addForeignKey(propertyKey, type, targetKey);
11
+ };
12
+ }
13
+ exports.ForeignKey = ForeignKey;
@@ -0,0 +1,3 @@
1
+ import { IndexOptions } from '../orm.type';
2
+ export declare function Index(fields: string | string[], options?: IndexOptions): ClassDecorator;
3
+ export declare function Index(options?: IndexOptions): PropertyDecorator;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Index = void 0;
4
+ const entity_model_1 = require("../model/entity-model");
5
+ function Index(arg0, arg1) {
6
+ return function (target, propertyKey) {
7
+ if (typeof target === 'function') {
8
+ if (!(typeof arg0 === 'string' || Array.isArray(arg0)))
9
+ throw new Error(`You must specify index column(s)`);
10
+ const entity = entity_model_1.EntityModel.attachTo(target);
11
+ entity.addIndex(arg0, arg1);
12
+ return;
13
+ }
14
+ if (!target.constructor)
15
+ throw new Error('Property decorators can be used for class properties only');
16
+ if (typeof propertyKey !== 'string')
17
+ throw new Error('Index() decorator can be used for string property keys only');
18
+ const entity = entity_model_1.EntityModel.attachTo(target.constructor);
19
+ entity.addIndex(propertyKey, arg0);
20
+ };
21
+ }
22
+ exports.Index = Index;
@@ -0,0 +1,23 @@
1
+ import { TypeThunk } from '../orm.type';
2
+ import { LinkChain } from '../model/link-chain';
3
+ export declare function Link(chain: LinkChain<any>): PropertyDecorator;
4
+ export declare function LinkToOne(type?: TypeThunk, targetKey?: string, sourceKey?: string): PropertyDecorator;
5
+ export declare function LinkToMany(type: TypeThunk, targetKey?: string, sourceKey?: string): PropertyDecorator;
6
+ export declare function LinkFromOne(type?: TypeThunk, targetKey?: string, sourceKey?: string): PropertyDecorator;
7
+ export declare function LinkFromMany(type?: TypeThunk, targetKey?: string, sourceKey?: string): PropertyDecorator;
8
+ /**
9
+ * Crates an Link Chain object
10
+ */
11
+ export declare function linkToOne<T>(type: TypeThunk<T>, targetKey?: keyof T, sourceKey?: string): LinkChain<T>;
12
+ /**
13
+ * Crates an Link Chain object
14
+ */
15
+ export declare function linkToMany<T>(type: TypeThunk<T>, targetKey?: keyof T, sourceKey?: string): LinkChain<T>;
16
+ /**
17
+ * Crates an Link Chain object
18
+ */
19
+ export declare function linkFromOne<T>(type: TypeThunk<T>, targetKey?: keyof T, sourceKey?: string): LinkChain<T>;
20
+ /**
21
+ * Crates an Link Chain object
22
+ */
23
+ export declare function linkFromMany<T>(type: TypeThunk<T>, targetKey?: keyof T, sourceKey?: string): LinkChain<T>;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.linkFromMany = exports.linkFromOne = exports.linkToMany = exports.linkToOne = exports.LinkFromMany = exports.LinkFromOne = exports.LinkToMany = exports.LinkToOne = exports.Link = void 0;
4
+ const entity_model_1 = require("../model/entity-model");
5
+ const link_chain_1 = require("../model/link-chain");
6
+ function Link(chain) {
7
+ return (target, propertyKey) => {
8
+ if (typeof propertyKey !== 'string')
9
+ throw new Error('You can define a column for only string properties');
10
+ if (chain.first.returnsMany() &&
11
+ Reflect.getMetadata("design:type", target, propertyKey) !== Array)
12
+ throw new Error(`Returning type of property (${propertyKey}) must be an array`);
13
+ const entity = entity_model_1.EntityModel.attachTo(target.constructor);
14
+ // @ts-ignore
15
+ // noinspection JSConstantReassignment
16
+ chain.first.source = entity.ctor;
17
+ entity.defineAssociationElement(propertyKey, chain.first);
18
+ };
19
+ }
20
+ exports.Link = Link;
21
+ function LinkToOne(type, targetKey, sourceKey) {
22
+ return (target, propertyKey) => {
23
+ type = type || Reflect.getMetadata("design:type", target, propertyKey);
24
+ if (!type || type === Array)
25
+ throw new Error('You must provide "type"');
26
+ const chain = linkToOne(type, targetKey, sourceKey);
27
+ Link(chain)(target, propertyKey);
28
+ };
29
+ }
30
+ exports.LinkToOne = LinkToOne;
31
+ function LinkToMany(type, targetKey, sourceKey) {
32
+ return (target, propertyKey) => {
33
+ type = type || Reflect.getMetadata("design:type", target, propertyKey);
34
+ if (!type || type === Array)
35
+ throw new Error('You must provide "type"');
36
+ const chain = linkToMany(type, targetKey, sourceKey);
37
+ Link(chain)(target, propertyKey);
38
+ };
39
+ }
40
+ exports.LinkToMany = LinkToMany;
41
+ function LinkFromOne(type, targetKey, sourceKey) {
42
+ return (target, propertyKey) => {
43
+ type = type || Reflect.getMetadata("design:type", target, propertyKey);
44
+ if (!type || type === Array)
45
+ throw new Error('You must provide "type"');
46
+ const chain = linkFromOne(type, targetKey, sourceKey);
47
+ Link(chain)(target, propertyKey);
48
+ };
49
+ }
50
+ exports.LinkFromOne = LinkFromOne;
51
+ function LinkFromMany(type, targetKey, sourceKey) {
52
+ return (target, propertyKey) => {
53
+ type = type || Reflect.getMetadata("design:type", target, propertyKey);
54
+ if (!type || type === Array)
55
+ throw new Error('You must provide "type"');
56
+ const chain = linkFromMany(type, targetKey, sourceKey);
57
+ Link(chain)(target, propertyKey);
58
+ };
59
+ }
60
+ exports.LinkFromMany = LinkFromMany;
61
+ /**
62
+ * Crates an Link Chain object
63
+ */
64
+ function linkToOne(type, targetKey, sourceKey) {
65
+ return new link_chain_1.LinkChain(type, 'to', targetKey, sourceKey);
66
+ }
67
+ exports.linkToOne = linkToOne;
68
+ /**
69
+ * Crates an Link Chain object
70
+ */
71
+ function linkToMany(type, targetKey, sourceKey) {
72
+ return new link_chain_1.LinkChain(type, 'to-many', targetKey, sourceKey);
73
+ }
74
+ exports.linkToMany = linkToMany;
75
+ /**
76
+ * Crates an Link Chain object
77
+ */
78
+ function linkFromOne(type, targetKey, sourceKey) {
79
+ return new link_chain_1.LinkChain(type, 'from', targetKey, sourceKey);
80
+ }
81
+ exports.linkFromOne = linkFromOne;
82
+ /**
83
+ * Crates an Link Chain object
84
+ */
85
+ function linkFromMany(type, targetKey, sourceKey) {
86
+ return new link_chain_1.LinkChain(type, 'from-many', targetKey, sourceKey);
87
+ }
88
+ exports.linkFromMany = linkFromMany;
@@ -0,0 +1,3 @@
1
+ import { IndexOptions } from '../orm.type';
2
+ export declare function PrimaryKey(fields: string | string[], options?: IndexOptions): ClassDecorator;
3
+ export declare function PrimaryKey(options?: IndexOptions): PropertyDecorator;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PrimaryKey = void 0;
4
+ const entity_model_1 = require("../model/entity-model");
5
+ function PrimaryKey(arg0, arg1) {
6
+ return function (target, propertyKey) {
7
+ if (arguments.length === 1) {
8
+ if (!(typeof arg0 === 'string' || Array.isArray(arg0)))
9
+ throw new Error(`You must specify primary index column(s)`);
10
+ const entity = entity_model_1.EntityModel.attachTo(target);
11
+ entity.setPrimaryIndex(arg0, arg1);
12
+ return;
13
+ }
14
+ if (!target.constructor)
15
+ throw new Error('Property decorators can be used for class properties only');
16
+ if (typeof propertyKey !== 'string')
17
+ throw new Error('Index() decorator can be used for string property keys only');
18
+ const entity = entity_model_1.EntityModel.attachTo(target.constructor);
19
+ entity.defineColumnElement(propertyKey, { notNull: true });
20
+ entity.setPrimaryIndex(propertyKey, arg0);
21
+ };
22
+ }
23
+ exports.PrimaryKey = PrimaryKey;
@@ -0,0 +1,3 @@
1
+ import { ColumnTransformFunction } from '../orm.type';
2
+ export declare function Parse(fn: ColumnTransformFunction): PropertyDecorator;
3
+ export declare function Serialize(fn: ColumnTransformFunction): PropertyDecorator;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Serialize = exports.Parse = void 0;
4
+ const entity_model_1 = require("../model/entity-model");
5
+ function Parse(fn) {
6
+ return (target, propertyKey) => {
7
+ if (typeof propertyKey !== 'string')
8
+ throw new Error('You can define a Column for only string properties');
9
+ entity_model_1.EntityModel.attachTo(target.constructor)
10
+ .defineColumnElement(propertyKey)
11
+ .parse = fn;
12
+ };
13
+ }
14
+ exports.Parse = Parse;
15
+ function Serialize(fn) {
16
+ return (target, propertyKey) => {
17
+ if (typeof propertyKey !== 'string')
18
+ throw new Error('You can define a Column for only string properties');
19
+ entity_model_1.EntityModel.attachTo(target.constructor)
20
+ .defineColumnElement(propertyKey)
21
+ .serialize = fn;
22
+ };
23
+ }
24
+ exports.Serialize = Serialize;
@@ -0,0 +1,8 @@
1
+ import type { EntityModel } from './entity-model';
2
+ import { ElementKind } from '../orm.type';
3
+ export declare abstract class AbstractEntityelement {
4
+ readonly entity: EntityModel;
5
+ readonly name: string;
6
+ abstract kind: ElementKind;
7
+ protected constructor(entity: EntityModel, name: string);
8
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbstractEntityelement = void 0;
4
+ class AbstractEntityelement {
5
+ constructor(entity, name) {
6
+ this.entity = entity;
7
+ this.name = name;
8
+ }
9
+ }
10
+ exports.AbstractEntityelement = AbstractEntityelement;
@@ -0,0 +1,9 @@
1
+ import { Association } from './association';
2
+ export declare class AssociationNode extends Association {
3
+ prior?: AssociationNode;
4
+ next?: AssociationNode;
5
+ conditions?: any[];
6
+ getFirst(): AssociationNode;
7
+ getLast(): AssociationNode;
8
+ returnsMany(): boolean;
9
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AssociationNode = void 0;
4
+ const association_1 = require("./association");
5
+ class AssociationNode extends association_1.Association {
6
+ getFirst() {
7
+ let l = this;
8
+ while (l.prior)
9
+ l = l.prior;
10
+ return l;
11
+ }
12
+ getLast() {
13
+ let l = this;
14
+ while (l.next)
15
+ l = l.next;
16
+ return l;
17
+ }
18
+ returnsMany() {
19
+ const n = super.returnsMany();
20
+ if (n)
21
+ return n;
22
+ return !!(this.next && this.next.returnsMany());
23
+ }
24
+ }
25
+ exports.AssociationNode = AssociationNode;
@@ -0,0 +1,28 @@
1
+ import { AssociationKind, AssociationSettings, TypeThunk } from '../orm.type';
2
+ import { EntityModel } from './entity-model';
3
+ import { EntityColumnElement } from './entity-column-element';
4
+ export declare class Association {
5
+ private _resolved?;
6
+ private _source?;
7
+ private _target?;
8
+ private _sourceKey?;
9
+ private _targetKey?;
10
+ private _sourceProperty?;
11
+ private _targetProperty?;
12
+ name: string;
13
+ readonly source: TypeThunk;
14
+ readonly target: TypeThunk;
15
+ readonly sourceKey?: string;
16
+ readonly targetKey?: string;
17
+ readonly kind?: AssociationKind;
18
+ constructor(name: string, args: AssociationSettings);
19
+ resolveSource(): Promise<EntityModel>;
20
+ resolveTarget(): Promise<EntityModel>;
21
+ resolveSourceKey(): Promise<string>;
22
+ resolveSourceProperty(): Promise<EntityColumnElement>;
23
+ resolveTargetKey(): Promise<string>;
24
+ resolveTargetProperty(): Promise<EntityColumnElement>;
25
+ get sourceBelongsToTarget(): boolean;
26
+ returnsMany(): boolean;
27
+ protected _resolveKeys(): Promise<void>;
28
+ }