@sqb/connect 4.0.7 → 4.0.10

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/package.json +6 -7
  2. package/dist/client/Adapter.d.ts +0 -57
  3. package/dist/client/Adapter.js +0 -2
  4. package/dist/client/Cursor.d.ts +0 -116
  5. package/dist/client/Cursor.js +0 -250
  6. package/dist/client/CursorStream.d.ts +0 -29
  7. package/dist/client/CursorStream.js +0 -98
  8. package/dist/client/FieldInfoMap.d.ts +0 -10
  9. package/dist/client/FieldInfoMap.js +0 -33
  10. package/dist/client/SqbClient.d.ts +0 -70
  11. package/dist/client/SqbClient.js +0 -165
  12. package/dist/client/SqbConnection.d.ts +0 -74
  13. package/dist/client/SqbConnection.js +0 -272
  14. package/dist/client/extensions.d.ts +0 -4
  15. package/dist/client/extensions.js +0 -14
  16. package/dist/client/helpers.d.ts +0 -9
  17. package/dist/client/helpers.js +0 -133
  18. package/dist/client/types.d.ts +0 -189
  19. package/dist/client/types.js +0 -5
  20. package/dist/index.d.ts +0 -28
  21. package/dist/index.js +0 -37
  22. package/dist/orm/base-entity.class.d.ts +0 -16
  23. package/dist/orm/base-entity.class.js +0 -56
  24. package/dist/orm/commands/command.helper.d.ts +0 -14
  25. package/dist/orm/commands/command.helper.js +0 -140
  26. package/dist/orm/commands/count.command.d.ts +0 -11
  27. package/dist/orm/commands/count.command.js +0 -30
  28. package/dist/orm/commands/create.command.d.ts +0 -20
  29. package/dist/orm/commands/create.command.js +0 -83
  30. package/dist/orm/commands/destroy.command.d.ts +0 -11
  31. package/dist/orm/commands/destroy.command.js +0 -30
  32. package/dist/orm/commands/find.command.d.ts +0 -44
  33. package/dist/orm/commands/find.command.js +0 -308
  34. package/dist/orm/commands/row-converter.d.ts +0 -55
  35. package/dist/orm/commands/row-converter.js +0 -187
  36. package/dist/orm/commands/update.command.d.ts +0 -22
  37. package/dist/orm/commands/update.command.js +0 -82
  38. package/dist/orm/decorators/column.decorator.d.ts +0 -4
  39. package/dist/orm/decorators/column.decorator.js +0 -14
  40. package/dist/orm/decorators/embedded.decorator.d.ts +0 -2
  41. package/dist/orm/decorators/embedded.decorator.js +0 -17
  42. package/dist/orm/decorators/entity.decorator.d.ts +0 -6
  43. package/dist/orm/decorators/entity.decorator.js +0 -23
  44. package/dist/orm/decorators/events.decorator.d.ts +0 -6
  45. package/dist/orm/decorators/events.decorator.js +0 -76
  46. package/dist/orm/decorators/foreignkey.decorator.d.ts +0 -2
  47. package/dist/orm/decorators/foreignkey.decorator.js +0 -13
  48. package/dist/orm/decorators/index.decorator.d.ts +0 -3
  49. package/dist/orm/decorators/index.decorator.js +0 -22
  50. package/dist/orm/decorators/link.decorator.d.ts +0 -23
  51. package/dist/orm/decorators/link.decorator.js +0 -88
  52. package/dist/orm/decorators/primarykey.decorator.d.ts +0 -3
  53. package/dist/orm/decorators/primarykey.decorator.js +0 -23
  54. package/dist/orm/decorators/transform.decorator.d.ts +0 -3
  55. package/dist/orm/decorators/transform.decorator.js +0 -24
  56. package/dist/orm/model/abstract-entityelement.d.ts +0 -8
  57. package/dist/orm/model/abstract-entityelement.js +0 -10
  58. package/dist/orm/model/association-node.d.ts +0 -9
  59. package/dist/orm/model/association-node.js +0 -25
  60. package/dist/orm/model/association.d.ts +0 -28
  61. package/dist/orm/model/association.js +0 -129
  62. package/dist/orm/model/entity-association-element.d.ts +0 -9
  63. package/dist/orm/model/entity-association-element.js +0 -13
  64. package/dist/orm/model/entity-column-element.d.ts +0 -68
  65. package/dist/orm/model/entity-column-element.js +0 -27
  66. package/dist/orm/model/entity-model.d.ts +0 -59
  67. package/dist/orm/model/entity-model.js +0 -295
  68. package/dist/orm/model/entity-object-element.d.ts +0 -12
  69. package/dist/orm/model/entity-object-element.js +0 -24
  70. package/dist/orm/model/index-meta.d.ts +0 -9
  71. package/dist/orm/model/index-meta.js +0 -16
  72. package/dist/orm/model/link-chain.d.ts +0 -15
  73. package/dist/orm/model/link-chain.js +0 -50
  74. package/dist/orm/orm.const.d.ts +0 -2
  75. package/dist/orm/orm.const.js +0 -5
  76. package/dist/orm/orm.type.d.ts +0 -112
  77. package/dist/orm/orm.type.js +0 -2
  78. package/dist/orm/repository.class.d.ts +0 -125
  79. package/dist/orm/repository.class.js +0 -217
  80. package/dist/orm/util/entity-mapping.d.ts +0 -12
  81. package/dist/orm/util/entity-mapping.js +0 -154
  82. package/dist/orm/util/extract-keyvalues.d.ts +0 -2
  83. package/dist/orm/util/extract-keyvalues.js +0 -60
  84. package/dist/orm/util/orm.helper.d.ts +0 -14
  85. package/dist/orm/util/orm.helper.js +0 -39
  86. package/dist/orm/util/serialize-element.d.ts +0 -2
  87. package/dist/orm/util/serialize-element.js +0 -43
  88. package/dist/types.d.ts +0 -2
  89. package/dist/types.js +0 -2
@@ -1,24 +0,0 @@
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;
@@ -1,8 +0,0 @@
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
- }
@@ -1,10 +0,0 @@
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;
@@ -1,9 +0,0 @@
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
- }
@@ -1,25 +0,0 @@
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;
@@ -1,28 +0,0 @@
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
- }
@@ -1,129 +0,0 @@
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_1 = require("../util/orm.helper");
6
- class Association {
7
- constructor(name, args) {
8
- this.name = name;
9
- this.source = args.source;
10
- this.target = args.target;
11
- this.sourceKey = args.sourceKey;
12
- this.targetKey = args.targetKey;
13
- this.kind = args.kind;
14
- }
15
- async resolveSource() {
16
- this._source = await (0, orm_helper_1.resolveEntityMeta)(this.source);
17
- if (!this._source)
18
- throw new Error(`Can't resolve source entity of association "${this.name}"`);
19
- return this._source;
20
- }
21
- async resolveTarget() {
22
- this._target = await (0, orm_helper_1.resolveEntityMeta)(this.target);
23
- if (!this._target)
24
- throw new Error(`Can't resolve target entity of association "${this.name}"`);
25
- return this._target;
26
- }
27
- async resolveSourceKey() {
28
- await this._resolveKeys();
29
- // @ts-ignore
30
- return this._sourceKey;
31
- }
32
- async resolveSourceProperty() {
33
- await this._resolveKeys();
34
- // @ts-ignore
35
- return this._sourceProperty;
36
- }
37
- async resolveTargetKey() {
38
- await this._resolveKeys();
39
- // @ts-ignore
40
- return this._targetKey;
41
- }
42
- async resolveTargetProperty() {
43
- await this._resolveKeys();
44
- // @ts-ignore
45
- return this._targetProperty;
46
- }
47
- get sourceBelongsToTarget() {
48
- return this.kind === 'from' || this.kind === 'from-many';
49
- }
50
- returnsMany() {
51
- return this.kind === 'to-many' || this.kind === 'from-many';
52
- }
53
- async _resolveKeys() {
54
- if (this._resolved)
55
- return;
56
- const source = await this.resolveSource();
57
- const target = await this.resolveTarget();
58
- let sourceKey = this.sourceKey;
59
- let targetKey = this.targetKey;
60
- if (!(sourceKey && targetKey)) {
61
- // Try to determine key fields from foreign key from source to target
62
- let foreign = await source.getForeignKeyFor(target);
63
- if (foreign && foreign !== this) {
64
- await foreign._resolveKeys();
65
- this._sourceKey = foreign._sourceKey;
66
- this._sourceProperty = foreign._sourceProperty;
67
- this._targetKey = foreign._targetKey;
68
- this._targetProperty = foreign._targetProperty;
69
- return;
70
- }
71
- else {
72
- // Try to determine key fields from foreign key from target to source
73
- foreign = await target.getForeignKeyFor(source);
74
- if (foreign && foreign !== this) {
75
- await foreign._resolveKeys();
76
- this._sourceKey = foreign._targetKey;
77
- this._sourceProperty = foreign._targetProperty;
78
- this._targetKey = foreign._sourceKey;
79
- this._targetProperty = foreign._sourceProperty;
80
- return;
81
- }
82
- }
83
- let master;
84
- let detail;
85
- let masterKey;
86
- let detailKey;
87
- if (this.sourceBelongsToTarget) {
88
- master = target;
89
- detail = source;
90
- masterKey = targetKey || '';
91
- detailKey = sourceKey || '';
92
- }
93
- else {
94
- master = source;
95
- detail = target;
96
- detailKey = targetKey || '';
97
- masterKey = sourceKey || '';
98
- }
99
- if (!detailKey) {
100
- const primaryIndex = detail.primaryIndex;
101
- detailKey = primaryIndex && primaryIndex.columns.length === 1 ?
102
- primaryIndex.columns[0] : 'id';
103
- }
104
- if (!masterKey) {
105
- // snake-case
106
- masterKey = detail.name[0].toLowerCase() + detail.name.substring(1) + '_' + detailKey;
107
- if (!master.getColumnElement(masterKey))
108
- masterKey = (0, putil_varhelpers_1.camelCase)(masterKey);
109
- }
110
- if (this.sourceBelongsToTarget) {
111
- targetKey = masterKey;
112
- sourceKey = detailKey;
113
- }
114
- else {
115
- targetKey = detailKey;
116
- sourceKey = masterKey;
117
- }
118
- }
119
- this._targetProperty = target.getColumnElement(targetKey);
120
- if (!this._targetProperty)
121
- throw new Error(`Can't determine target key of ${this.name}`);
122
- this._sourceProperty = source.getColumnElement(sourceKey);
123
- if (!this._sourceProperty)
124
- throw new Error(`Can't determine source key of ${this.name}`);
125
- this._targetKey = targetKey;
126
- this._sourceKey = sourceKey;
127
- }
128
- }
129
- exports.Association = Association;
@@ -1,9 +0,0 @@
1
- import type { EntityModel } from './entity-model';
2
- import { ElementKind } from '../orm.type';
3
- import { AbstractEntityelement } from './abstract-entityelement';
4
- import type { AssociationNode } from './association-node';
5
- export declare class EntityAssociationElement extends AbstractEntityelement {
6
- readonly association: AssociationNode;
7
- readonly kind: ElementKind;
8
- constructor(entity: EntityModel, name: string, association: AssociationNode);
9
- }
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EntityAssociationElement = void 0;
4
- const abstract_entityelement_1 = require("./abstract-entityelement");
5
- class EntityAssociationElement extends abstract_entityelement_1.AbstractEntityelement {
6
- constructor(entity, name, association) {
7
- super(entity, name);
8
- this.association = association;
9
- this.kind = 'association';
10
- this.association.name = this.entity.name + '.' + name;
11
- }
12
- }
13
- exports.EntityAssociationElement = EntityAssociationElement;
@@ -1,68 +0,0 @@
1
- import 'reflect-metadata';
2
- import { DataType } from '@sqb/builder';
3
- import type { EntityModel } from './entity-model';
4
- import { ElementKind, ColumnAutoGenerationStrategy, ColumnTransformFunction, DataPropertyOptions, EnumValue, FieldValue, DefaultValueGetter } from '../orm.type';
5
- import { AbstractEntityelement } from './abstract-entityelement';
6
- export declare class EntityColumnElement extends AbstractEntityelement {
7
- readonly kind: ElementKind;
8
- fieldName: string;
9
- dataType?: DataType;
10
- type?: Function;
11
- /**
12
- * Field comment
13
- */
14
- comment?: string;
15
- /**
16
- * Column's default value
17
- */
18
- default?: FieldValue | DefaultValueGetter;
19
- /**
20
- * Indicates if column data is an array
21
- */
22
- isArray?: boolean;
23
- /**
24
- * Indicates enum values
25
- */
26
- enum?: EnumValue;
27
- /**
28
- * Character or byte length of column
29
- */
30
- length?: number;
31
- /**
32
- * The precision for a decimal field
33
- */
34
- precision?: number;
35
- /**
36
- * The scale for a decimal field
37
- */
38
- scale?: number;
39
- /**
40
- * Fields's collation.
41
- */
42
- collation?: string;
43
- /**
44
- * Indicates auto generation strategy
45
- */
46
- autoGenerated?: ColumnAutoGenerationStrategy;
47
- /**
48
- * Indicates if column value can be null
49
- */
50
- notNull?: boolean;
51
- /**
52
- * Indicates whether or not to hide this column by default when making queries.
53
- */
54
- hidden?: boolean;
55
- /**
56
- * Indicates if column value is used in update queries
57
- */
58
- noUpdate?: boolean;
59
- /**
60
- * Indicates if column value is used in insert queries
61
- */
62
- noInsert?: boolean;
63
- parse?: ColumnTransformFunction;
64
- serialize?: ColumnTransformFunction;
65
- constructor(entity: EntityModel, name: string, options?: DataPropertyOptions);
66
- assign(options: DataPropertyOptions): void;
67
- checkEnumValue(v: FieldValue): void;
68
- }
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EntityColumnElement = void 0;
4
- const tslib_1 = require("tslib");
5
- require("reflect-metadata");
6
- const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
7
- const abstract_entityelement_1 = require("./abstract-entityelement");
8
- class EntityColumnElement extends abstract_entityelement_1.AbstractEntityelement {
9
- constructor(entity, name, options = {}) {
10
- super(entity, name);
11
- this.kind = 'column';
12
- this.fieldName = name;
13
- if (options)
14
- this.assign(options);
15
- }
16
- assign(options) {
17
- Object.assign(this, lodash_1.default.omit(options, ['entity', 'name', 'kind']));
18
- }
19
- checkEnumValue(v) {
20
- if (v === undefined || !this.enum || (v == null && !this.notNull))
21
- return;
22
- const enumKeys = Array.isArray(this.enum) ? this.enum : Object.keys(this.enum);
23
- if (!enumKeys.includes(v))
24
- throw new Error(`${this.entity.name}.${this.name} value must be one of (${enumKeys})`);
25
- }
26
- }
27
- exports.EntityColumnElement = EntityColumnElement;
@@ -1,59 +0,0 @@
1
- import { Type, Maybe } from 'ts-gems';
2
- import { IndexOptions, TypeThunk, DataPropertyOptions } from '../orm.type';
3
- import { IndexMeta } from './index-meta';
4
- import { Association } from './association';
5
- import { EntityColumnElement } from './entity-column-element';
6
- import { EntityObjectElement } from './entity-object-element';
7
- import { EntityAssociationElement } from './entity-association-element';
8
- import { AssociationNode } from './association-node';
9
- export declare type EntityElement = EntityColumnElement | EntityObjectElement | EntityAssociationElement;
10
- export declare class EntityModel {
11
- readonly ctor: Type;
12
- private _elementKeys?;
13
- readonly name: string;
14
- tableName?: string;
15
- schema?: string;
16
- comment?: string;
17
- primaryIndex?: IndexMeta;
18
- elements: Map<string, EntityElement>;
19
- indexes: IndexMeta[];
20
- foreignKeys: Association[];
21
- eventListeners: {
22
- event: string;
23
- fn: Function;
24
- }[];
25
- constructor(ctor: Type);
26
- get elementKeys(): string[];
27
- getElement(name: string): Maybe<EntityElement>;
28
- getColumnElement(name: string): Maybe<EntityColumnElement>;
29
- getColumnElementByFieldName(fieldName: string): Maybe<EntityColumnElement>;
30
- getObjectElement(name: string): Maybe<EntityObjectElement>;
31
- getAssociationElement(name: string): Maybe<EntityAssociationElement>;
32
- defineColumnElement(propertyKey: string, options?: DataPropertyOptions): EntityColumnElement;
33
- defineAssociationElement(propertyKey: string, association: AssociationNode): EntityAssociationElement;
34
- defineObjectElement(propertyKey: string, type?: TypeThunk): EntityObjectElement;
35
- setPrimaryIndex(column: string | string[], options?: IndexOptions): void;
36
- addIndex(column: string | string[], options?: IndexOptions): void;
37
- addForeignKey(propertyKey: string, target: TypeThunk, targetKey?: string): void;
38
- before(event: 'insert' | 'update' | 'destroy', fn: Type): void;
39
- after(event: 'insert' | 'update' | 'destroy', fn: Type): void;
40
- getPrimaryIndexColumns(): EntityColumnElement[];
41
- getElementNames(fn: (el: EntityElement) => boolean): string[];
42
- getColumnNames(): string[];
43
- getObjectElementNames(): string[];
44
- getAssociationElementNames(): string[];
45
- getNonAssociationElementNames(): string[];
46
- getInsertColumnNames(): string[];
47
- getUpdateColumnNames(): string[];
48
- getForeignKeyFor(t: EntityModel): Promise<Maybe<Association>>;
49
- static get(ctor: Function): Maybe<EntityModel>;
50
- static hasOwn(ctor: Function): boolean;
51
- static attachTo(ctor: Function): EntityModel;
52
- static getElementNames<T extends Function, K extends keyof T>(ctor: T): K[] | undefined;
53
- static getColumnNames<T extends Function, K extends keyof T>(ctor: T): K[] | undefined;
54
- static getAssociationElementNames<T extends Function, K extends keyof T>(ctor: T): K[] | undefined;
55
- static getNonAssociationElementNames<T extends Function, K extends keyof T>(ctor: T): K[] | undefined;
56
- static getObjectElementNames<T extends Function, K extends keyof T>(ctor: T): K[] | undefined;
57
- static getInsertColumnNames<T extends Function, K extends keyof T>(ctor: T): K[] | undefined;
58
- static getUpdateColumnNames<T extends Function, K extends keyof T>(ctor: T): K[] | undefined;
59
- }