@sqb/connect 4.20.7 → 4.21.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.
- package/{types/client → client}/cursor-stream.d.ts +1 -1
- package/{types/client → client}/cursor.d.ts +4 -4
- package/{types/client → client}/sqb-connection.d.ts +4 -4
- package/{esm/orm → orm}/commands/command.helper.js +2 -3
- package/{types/orm → orm}/commands/count.command.d.ts +2 -2
- package/{types/orm → orm}/commands/create.command.d.ts +1 -1
- package/{esm/orm → orm}/commands/create.command.js +3 -5
- package/{types/orm → orm}/commands/delete.command.d.ts +2 -2
- package/{types/orm → orm}/commands/find.command.d.ts +2 -2
- package/{esm/orm → orm}/commands/find.command.js +3 -4
- package/{types/orm → orm}/commands/row-converter.d.ts +1 -1
- package/{types/orm → orm}/commands/update.command.d.ts +2 -2
- package/{esm/orm → orm}/commands/update.command.js +3 -5
- package/{types/orm → orm}/model/association-field-metadata.d.ts +0 -5
- package/{types/orm → orm}/model/association.d.ts +3 -3
- package/{esm/orm → orm}/model/association.js +1 -1
- package/{types/orm → orm}/model/column-field-metadata.d.ts +2 -8
- package/{types/orm → orm}/model/embedded-field-metadata.d.ts +0 -1
- package/{esm/orm → orm}/model/embedded-field-metadata.js +0 -14
- package/{types/orm → orm}/model/entity-metadata.d.ts +3 -3
- package/{esm/orm → orm}/model/entity-metadata.js +21 -6
- package/orm/model/index-metadata.js +1 -0
- package/orm/orm.type.js +1 -0
- package/{types/orm → orm}/repository.class.d.ts +2 -2
- package/{esm/orm → orm}/repository.class.js +1 -1
- package/{types/orm → orm}/util/orm.helper.d.ts +5 -3
- package/{esm/orm → orm}/util/orm.helper.js +14 -0
- package/package.json +10 -26
- package/cjs/client/adapter.js +0 -2
- package/cjs/client/cursor-stream.js +0 -104
- package/cjs/client/cursor.js +0 -261
- package/cjs/client/extensions.js +0 -41
- package/cjs/client/field-info-map.js +0 -54
- package/cjs/client/helpers.js +0 -140
- package/cjs/client/sqb-client.js +0 -175
- package/cjs/client/sqb-connection.js +0 -293
- package/cjs/client/sqb-error.js +0 -15
- package/cjs/client/types.js +0 -5
- package/cjs/index.js +0 -41
- package/cjs/orm/backward.js +0 -24
- package/cjs/orm/base-entity.js +0 -29
- package/cjs/orm/commands/command.helper.js +0 -170
- package/cjs/orm/commands/count.command.js +0 -30
- package/cjs/orm/commands/create.command.js +0 -92
- package/cjs/orm/commands/delete.command.js +0 -30
- package/cjs/orm/commands/find.command.js +0 -301
- package/cjs/orm/commands/row-converter.js +0 -190
- package/cjs/orm/commands/update.command.js +0 -83
- package/cjs/orm/decorators/column.decorator.js +0 -32
- package/cjs/orm/decorators/embedded.decorator.js +0 -15
- package/cjs/orm/decorators/entity.decorator.js +0 -180
- package/cjs/orm/decorators/events.decorator.js +0 -63
- package/cjs/orm/decorators/foreignkey.decorator.js +0 -12
- package/cjs/orm/decorators/index.decorator.js +0 -20
- package/cjs/orm/decorators/link.decorator.js +0 -72
- package/cjs/orm/decorators/primarykey.decorator.js +0 -24
- package/cjs/orm/decorators/transform.decorator.js +0 -21
- package/cjs/orm/model/association-field-metadata.js +0 -24
- package/cjs/orm/model/association-node.js +0 -28
- package/cjs/orm/model/association.js +0 -141
- package/cjs/orm/model/column-field-metadata.js +0 -32
- package/cjs/orm/model/embedded-field-metadata.js +0 -28
- package/cjs/orm/model/entity-metadata.js +0 -327
- package/cjs/orm/model/field-metadata.js +0 -2
- package/cjs/orm/model/index-metadata.js +0 -2
- package/cjs/orm/model/link-chain.js +0 -47
- package/cjs/orm/orm.const.js +0 -6
- package/cjs/orm/orm.type.js +0 -2
- package/cjs/orm/repository.class.js +0 -293
- package/cjs/orm/util/apply-mixins.js +0 -16
- package/cjs/orm/util/extract-keyvalues.js +0 -63
- package/cjs/orm/util/orm.helper.js +0 -34
- package/cjs/orm/util/parse-fields-projection.js +0 -68
- package/cjs/orm/util/serialize-field.js +0 -49
- package/cjs/package.json +0 -3
- package/esm/orm/model/association-field-metadata.js +0 -20
- package/esm/orm/model/column-field-metadata.js +0 -28
- package/esm/package.json +0 -3
- package/types/index.d.cts +0 -33
- /package/{types/client → client}/adapter.d.ts +0 -0
- /package/{esm/client → client}/adapter.js +0 -0
- /package/{esm/client → client}/cursor-stream.js +0 -0
- /package/{esm/client → client}/cursor.js +0 -0
- /package/{types/client → client}/extensions.d.ts +0 -0
- /package/{esm/client → client}/extensions.js +0 -0
- /package/{types/client → client}/field-info-map.d.ts +0 -0
- /package/{esm/client → client}/field-info-map.js +0 -0
- /package/{types/client → client}/helpers.d.ts +0 -0
- /package/{esm/client → client}/helpers.js +0 -0
- /package/{types/client → client}/sqb-client.d.ts +0 -0
- /package/{esm/client → client}/sqb-client.js +0 -0
- /package/{esm/client → client}/sqb-connection.js +0 -0
- /package/{types/client → client}/sqb-error.d.ts +0 -0
- /package/{esm/client → client}/sqb-error.js +0 -0
- /package/{types/client → client}/types.d.ts +0 -0
- /package/{esm/client → client}/types.js +0 -0
- /package/{types/index.d.ts → index.d.ts} +0 -0
- /package/{esm/index.js → index.js} +0 -0
- /package/{types/orm → orm}/backward.d.ts +0 -0
- /package/{esm/orm → orm}/backward.js +0 -0
- /package/{types/orm → orm}/base-entity.d.ts +0 -0
- /package/{esm/orm → orm}/base-entity.js +0 -0
- /package/{types/orm → orm}/commands/command.helper.d.ts +0 -0
- /package/{esm/orm → orm}/commands/count.command.js +0 -0
- /package/{esm/orm → orm}/commands/delete.command.js +0 -0
- /package/{esm/orm → orm}/commands/row-converter.js +0 -0
- /package/{types/orm → orm}/decorators/column.decorator.d.ts +0 -0
- /package/{esm/orm → orm}/decorators/column.decorator.js +0 -0
- /package/{types/orm → orm}/decorators/embedded.decorator.d.ts +0 -0
- /package/{esm/orm → orm}/decorators/embedded.decorator.js +0 -0
- /package/{types/orm → orm}/decorators/entity.decorator.d.ts +0 -0
- /package/{esm/orm → orm}/decorators/entity.decorator.js +0 -0
- /package/{types/orm → orm}/decorators/events.decorator.d.ts +0 -0
- /package/{esm/orm → orm}/decorators/events.decorator.js +0 -0
- /package/{types/orm → orm}/decorators/foreignkey.decorator.d.ts +0 -0
- /package/{esm/orm → orm}/decorators/foreignkey.decorator.js +0 -0
- /package/{types/orm → orm}/decorators/index.decorator.d.ts +0 -0
- /package/{esm/orm → orm}/decorators/index.decorator.js +0 -0
- /package/{types/orm → orm}/decorators/link.decorator.d.ts +0 -0
- /package/{esm/orm → orm}/decorators/link.decorator.js +0 -0
- /package/{types/orm → orm}/decorators/primarykey.decorator.d.ts +0 -0
- /package/{esm/orm → orm}/decorators/primarykey.decorator.js +0 -0
- /package/{types/orm → orm}/decorators/transform.decorator.d.ts +0 -0
- /package/{esm/orm → orm}/decorators/transform.decorator.js +0 -0
- /package/{esm/orm/model/field-metadata.js → orm/model/association-field-metadata.js} +0 -0
- /package/{types/orm → orm}/model/association-node.d.ts +0 -0
- /package/{esm/orm → orm}/model/association-node.js +0 -0
- /package/{esm/orm/model/index-metadata.js → orm/model/column-field-metadata.js} +0 -0
- /package/{types/orm → orm}/model/field-metadata.d.ts +0 -0
- /package/{esm/orm/orm.type.js → orm/model/field-metadata.js} +0 -0
- /package/{types/orm → orm}/model/index-metadata.d.ts +0 -0
- /package/{types/orm → orm}/model/link-chain.d.ts +0 -0
- /package/{esm/orm → orm}/model/link-chain.js +0 -0
- /package/{types/orm → orm}/orm.const.d.ts +0 -0
- /package/{esm/orm → orm}/orm.const.js +0 -0
- /package/{types/orm → orm}/orm.type.d.ts +0 -0
- /package/{types/orm → orm}/util/apply-mixins.d.ts +0 -0
- /package/{esm/orm → orm}/util/apply-mixins.js +0 -0
- /package/{types/orm → orm}/util/extract-keyvalues.d.ts +0 -0
- /package/{esm/orm → orm}/util/extract-keyvalues.js +0 -0
- /package/{types/orm → orm}/util/parse-fields-projection.d.ts +0 -0
- /package/{esm/orm → orm}/util/parse-fields-projection.js +0 -0
- /package/{types/orm → orm}/util/serialize-field.d.ts +0 -0
- /package/{esm/orm → orm}/util/serialize-field.js +0 -0
|
@@ -1,141 +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_js_1 = require("../util/orm.helper.js");
|
|
6
|
-
const entity_metadata_js_1 = require("./entity-metadata.js");
|
|
7
|
-
class Association {
|
|
8
|
-
_resolved;
|
|
9
|
-
_source; // cached value
|
|
10
|
-
_target; // cached value
|
|
11
|
-
_sourceKey; // cached value
|
|
12
|
-
_targetKey; // cached value
|
|
13
|
-
_sourceProperty;
|
|
14
|
-
_targetProperty;
|
|
15
|
-
name;
|
|
16
|
-
source;
|
|
17
|
-
target;
|
|
18
|
-
sourceKey;
|
|
19
|
-
targetKey;
|
|
20
|
-
many;
|
|
21
|
-
constructor(name, args) {
|
|
22
|
-
this.name = name;
|
|
23
|
-
this.source = args.source;
|
|
24
|
-
this.target = args.target;
|
|
25
|
-
this.sourceKey = args.sourceKey;
|
|
26
|
-
this.targetKey = args.targetKey;
|
|
27
|
-
this.many = !!args.many;
|
|
28
|
-
}
|
|
29
|
-
async resolveSource() {
|
|
30
|
-
this._source = await (0, orm_helper_js_1.resolveEntityMeta)(this.source);
|
|
31
|
-
if (!this._source)
|
|
32
|
-
throw new Error(`Can't resolve source entity of association "${this.name}"`);
|
|
33
|
-
return this._source;
|
|
34
|
-
}
|
|
35
|
-
async resolveTarget() {
|
|
36
|
-
this._target = await (0, orm_helper_js_1.resolveEntityMeta)(this.target);
|
|
37
|
-
if (!this._target)
|
|
38
|
-
throw new Error(`Can't resolve target entity of association "${this.name}"`);
|
|
39
|
-
return this._target;
|
|
40
|
-
}
|
|
41
|
-
async resolveSourceKey() {
|
|
42
|
-
await this._resolveKeys();
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
return this._sourceKey;
|
|
45
|
-
}
|
|
46
|
-
async resolveSourceProperty() {
|
|
47
|
-
await this._resolveKeys();
|
|
48
|
-
// @ts-ignore
|
|
49
|
-
return this._sourceProperty;
|
|
50
|
-
}
|
|
51
|
-
async resolveTargetKey() {
|
|
52
|
-
await this._resolveKeys();
|
|
53
|
-
// @ts-ignore
|
|
54
|
-
return this._targetKey;
|
|
55
|
-
}
|
|
56
|
-
async resolveTargetProperty() {
|
|
57
|
-
await this._resolveKeys();
|
|
58
|
-
// @ts-ignore
|
|
59
|
-
return this._targetProperty;
|
|
60
|
-
}
|
|
61
|
-
returnsMany() {
|
|
62
|
-
return this.many;
|
|
63
|
-
}
|
|
64
|
-
async _resolveKeys() {
|
|
65
|
-
if (this._resolved)
|
|
66
|
-
return;
|
|
67
|
-
const source = await this.resolveSource();
|
|
68
|
-
const target = await this.resolveTarget();
|
|
69
|
-
let sourceKey = this.sourceKey || '';
|
|
70
|
-
let targetKey = this.targetKey || '';
|
|
71
|
-
if (!(sourceKey && targetKey)) {
|
|
72
|
-
// Try to determine key fields from foreign key from source to target
|
|
73
|
-
let foreign = await entity_metadata_js_1.EntityMetadata.getForeignKeyFor(source, target);
|
|
74
|
-
if (foreign && foreign !== this) {
|
|
75
|
-
await foreign._resolveKeys();
|
|
76
|
-
this._sourceKey = foreign._sourceKey;
|
|
77
|
-
this._sourceProperty = foreign._sourceProperty;
|
|
78
|
-
this._targetKey = foreign._targetKey;
|
|
79
|
-
this._targetProperty = foreign._targetProperty;
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
// Try to determine key fields from foreign key from target to source
|
|
83
|
-
foreign = await entity_metadata_js_1.EntityMetadata.getForeignKeyFor(target, source);
|
|
84
|
-
if (foreign && foreign !== this) {
|
|
85
|
-
await foreign._resolveKeys();
|
|
86
|
-
this._sourceKey = foreign._targetKey;
|
|
87
|
-
this._sourceProperty = foreign._targetProperty;
|
|
88
|
-
this._targetKey = foreign._sourceKey;
|
|
89
|
-
this._targetProperty = foreign._sourceProperty;
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
if (this.many) {
|
|
93
|
-
if (!sourceKey) {
|
|
94
|
-
const primaryIndexColumns = entity_metadata_js_1.EntityMetadata.getPrimaryIndexColumns(source);
|
|
95
|
-
sourceKey =
|
|
96
|
-
primaryIndexColumns && primaryIndexColumns.length === 1
|
|
97
|
-
? primaryIndexColumns[0].name
|
|
98
|
-
: 'id';
|
|
99
|
-
}
|
|
100
|
-
if (!targetKey && sourceKey) {
|
|
101
|
-
// snake-case
|
|
102
|
-
let s = source.name[0].toLowerCase() +
|
|
103
|
-
source.name.substring(1) +
|
|
104
|
-
'_' +
|
|
105
|
-
sourceKey;
|
|
106
|
-
if (!entity_metadata_js_1.EntityMetadata.getColumnField(target, s))
|
|
107
|
-
s = (0, putil_varhelpers_1.camelCase)(s);
|
|
108
|
-
targetKey = s;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
if (!targetKey) {
|
|
113
|
-
const primaryIndexColumns = entity_metadata_js_1.EntityMetadata.getPrimaryIndexColumns(target);
|
|
114
|
-
targetKey =
|
|
115
|
-
primaryIndexColumns && primaryIndexColumns.length === 1
|
|
116
|
-
? primaryIndexColumns[0].name
|
|
117
|
-
: 'id';
|
|
118
|
-
}
|
|
119
|
-
if (!sourceKey && targetKey) {
|
|
120
|
-
// snake-case
|
|
121
|
-
let s = target.name[0].toLowerCase() +
|
|
122
|
-
target.name.substring(1) +
|
|
123
|
-
'_' +
|
|
124
|
-
targetKey;
|
|
125
|
-
if (!entity_metadata_js_1.EntityMetadata.getColumnField(source, s))
|
|
126
|
-
s = (0, putil_varhelpers_1.camelCase)(s);
|
|
127
|
-
sourceKey = s;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
this._targetProperty = entity_metadata_js_1.EntityMetadata.getColumnField(target, targetKey);
|
|
132
|
-
if (!this._targetProperty)
|
|
133
|
-
throw new Error(`Can't determine target key of ${this.name}`);
|
|
134
|
-
this._sourceProperty = entity_metadata_js_1.EntityMetadata.getColumnField(source, sourceKey);
|
|
135
|
-
if (!this._sourceProperty)
|
|
136
|
-
throw new Error(`Can't determine source key of ${this.name}`);
|
|
137
|
-
this._targetKey = targetKey;
|
|
138
|
-
this._sourceKey = sourceKey;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
exports.Association = Association;
|
|
@@ -1,32 +0,0 @@
|
|
|
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;
|
|
7
|
-
(function (ColumnFieldMetadata) {
|
|
8
|
-
function create(entity, name, options = {}) {
|
|
9
|
-
const result = {
|
|
10
|
-
kind: 'column',
|
|
11
|
-
entity,
|
|
12
|
-
name,
|
|
13
|
-
fieldName: name,
|
|
14
|
-
};
|
|
15
|
-
if (options)
|
|
16
|
-
ColumnFieldMetadata.assign(result, options);
|
|
17
|
-
return result;
|
|
18
|
-
}
|
|
19
|
-
ColumnFieldMetadata.create = create;
|
|
20
|
-
function assign(target, options) {
|
|
21
|
-
Object.assign(target, lodash_1.default.omit(options, ['entity', 'name', 'kind']));
|
|
22
|
-
}
|
|
23
|
-
ColumnFieldMetadata.assign = assign;
|
|
24
|
-
function checkEnumValue(col, v) {
|
|
25
|
-
if (v === undefined || !col.enum || (v == null && !col.notNull))
|
|
26
|
-
return;
|
|
27
|
-
const enumKeys = Array.isArray(col.enum) ? col.enum : Object.keys(col.enum);
|
|
28
|
-
if (!enumKeys.includes(v))
|
|
29
|
-
throw new Error(`${col.entity.name}.${col.name} value must be one of (${enumKeys})`);
|
|
30
|
-
}
|
|
31
|
-
ColumnFieldMetadata.checkEnumValue = checkEnumValue;
|
|
32
|
-
})(ColumnFieldMetadata || (exports.ColumnFieldMetadata = ColumnFieldMetadata = {}));
|
|
@@ -1,28 +0,0 @@
|
|
|
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;
|
|
6
|
-
(function (EmbeddedFieldMetadata) {
|
|
7
|
-
function create(entity, name, type, options) {
|
|
8
|
-
const result = {
|
|
9
|
-
kind: 'object',
|
|
10
|
-
entity,
|
|
11
|
-
name,
|
|
12
|
-
type,
|
|
13
|
-
};
|
|
14
|
-
if (options?.fieldNamePrefix)
|
|
15
|
-
result.fieldNamePrefix = options.fieldNamePrefix;
|
|
16
|
-
if (options?.fieldNameSuffix)
|
|
17
|
-
result.fieldNameSuffix = options.fieldNameSuffix;
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
EmbeddedFieldMetadata.create = create;
|
|
21
|
-
async function resolveType(meta) {
|
|
22
|
-
const typ = await (0, orm_helper_js_1.resolveEntityMeta)(meta.type);
|
|
23
|
-
if (typ)
|
|
24
|
-
return typ;
|
|
25
|
-
throw new Error(`Can't resolve type of ${meta.entity.name}.${meta.name}`);
|
|
26
|
-
}
|
|
27
|
-
EmbeddedFieldMetadata.resolveType = resolveType;
|
|
28
|
-
})(EmbeddedFieldMetadata || (exports.EmbeddedFieldMetadata = EmbeddedFieldMetadata = {}));
|
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EntityMetadata = void 0;
|
|
4
|
-
const builder_1 = require("@sqb/builder");
|
|
5
|
-
const orm_const_js_1 = require("../orm.const.js");
|
|
6
|
-
const orm_helper_js_1 = require("../util/orm.helper.js");
|
|
7
|
-
const association_js_1 = require("./association.js");
|
|
8
|
-
const association_field_metadata_js_1 = require("./association-field-metadata.js");
|
|
9
|
-
const column_field_metadata_js_1 = require("./column-field-metadata.js");
|
|
10
|
-
const embedded_field_metadata_js_1 = require("./embedded-field-metadata.js");
|
|
11
|
-
var EntityMetadata;
|
|
12
|
-
(function (EntityMetadata) {
|
|
13
|
-
function define(ctor) {
|
|
14
|
-
const own = getOwn(ctor);
|
|
15
|
-
if (own)
|
|
16
|
-
return own;
|
|
17
|
-
const baseMeta = get(ctor);
|
|
18
|
-
const meta = {
|
|
19
|
-
ctor: ctor,
|
|
20
|
-
name: ctor.name,
|
|
21
|
-
fields: {},
|
|
22
|
-
indexes: [],
|
|
23
|
-
foreignKeys: [],
|
|
24
|
-
eventListeners: {},
|
|
25
|
-
};
|
|
26
|
-
Reflect.defineMetadata(orm_const_js_1.ENTITY_METADATA_KEY, meta, ctor);
|
|
27
|
-
// Merge base entity columns into this one
|
|
28
|
-
if (baseMeta) {
|
|
29
|
-
EntityMetadata.mixin(meta, baseMeta);
|
|
30
|
-
}
|
|
31
|
-
return meta;
|
|
32
|
-
}
|
|
33
|
-
EntityMetadata.define = define;
|
|
34
|
-
function get(ctor) {
|
|
35
|
-
return Reflect.getMetadata(orm_const_js_1.ENTITY_METADATA_KEY, ctor);
|
|
36
|
-
}
|
|
37
|
-
EntityMetadata.get = get;
|
|
38
|
-
function getOwn(ctor) {
|
|
39
|
-
return Reflect.getOwnMetadata(orm_const_js_1.ENTITY_METADATA_KEY, ctor);
|
|
40
|
-
}
|
|
41
|
-
EntityMetadata.getOwn = getOwn;
|
|
42
|
-
function getField(entity, fieldName) {
|
|
43
|
-
return fieldName ? entity.fields[fieldName.toLowerCase()] : undefined;
|
|
44
|
-
}
|
|
45
|
-
EntityMetadata.getField = getField;
|
|
46
|
-
function getColumnField(entity, fieldName) {
|
|
47
|
-
const el = getField(entity, fieldName);
|
|
48
|
-
if (el && !(0, orm_helper_js_1.isColumnField)(el))
|
|
49
|
-
throw new Error(`"${el.name}" requested as "column" but it is "${el.kind}"`);
|
|
50
|
-
return el;
|
|
51
|
-
}
|
|
52
|
-
EntityMetadata.getColumnField = getColumnField;
|
|
53
|
-
function getEmbeddedField(entity, fieldName) {
|
|
54
|
-
const el = getField(entity, fieldName);
|
|
55
|
-
if (el && !(0, orm_helper_js_1.isEmbeddedField)(el))
|
|
56
|
-
throw new Error(`"${el.name}" requested as "embedded" but it is "${el.kind}"`);
|
|
57
|
-
return el;
|
|
58
|
-
}
|
|
59
|
-
EntityMetadata.getEmbeddedField = getEmbeddedField;
|
|
60
|
-
function getAssociationField(entity, fieldName) {
|
|
61
|
-
const el = getField(entity, fieldName);
|
|
62
|
-
if (el && !(0, orm_helper_js_1.isAssociationField)(el)) {
|
|
63
|
-
throw new Error(`"${el.name}" requested as "association" but it is "${el.kind}"`);
|
|
64
|
-
}
|
|
65
|
-
return el;
|
|
66
|
-
}
|
|
67
|
-
EntityMetadata.getAssociationField = getAssociationField;
|
|
68
|
-
function findField(entity, predicate) {
|
|
69
|
-
return Object.values(entity.fields).find(predicate);
|
|
70
|
-
}
|
|
71
|
-
EntityMetadata.findField = findField;
|
|
72
|
-
function getColumnFieldByFieldName(entity, fieldName) {
|
|
73
|
-
if (!fieldName)
|
|
74
|
-
return;
|
|
75
|
-
fieldName = fieldName.toLowerCase();
|
|
76
|
-
for (const prop of Object.values(entity.fields)) {
|
|
77
|
-
if ((0, orm_helper_js_1.isColumnField)(prop) && prop.fieldName.toLowerCase() === fieldName)
|
|
78
|
-
return prop;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
EntityMetadata.getColumnFieldByFieldName = getColumnFieldByFieldName;
|
|
82
|
-
function getFieldNames(entity, filter) {
|
|
83
|
-
if (filter) {
|
|
84
|
-
const out = [];
|
|
85
|
-
for (const el of Object.values(entity.fields)) {
|
|
86
|
-
if (el && (!filter || filter(el)))
|
|
87
|
-
out.push(el.name);
|
|
88
|
-
}
|
|
89
|
-
return out;
|
|
90
|
-
}
|
|
91
|
-
// Create a cached name array
|
|
92
|
-
if (!Object.prototype.hasOwnProperty.call(entity, '_fieldNames')) {
|
|
93
|
-
Object.defineProperty(entity, '_fieldNames', {
|
|
94
|
-
enumerable: false,
|
|
95
|
-
configurable: true,
|
|
96
|
-
writable: true,
|
|
97
|
-
value: Object.values(entity.fields).map(m => m.name),
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
return entity._fieldNames;
|
|
101
|
-
}
|
|
102
|
-
EntityMetadata.getFieldNames = getFieldNames;
|
|
103
|
-
function getColumnFieldNames(entity) {
|
|
104
|
-
return getFieldNames(entity, orm_helper_js_1.isColumnField);
|
|
105
|
-
}
|
|
106
|
-
EntityMetadata.getColumnFieldNames = getColumnFieldNames;
|
|
107
|
-
function getEmbeddedFieldNames(entity) {
|
|
108
|
-
return getFieldNames(entity, orm_helper_js_1.isEmbeddedField);
|
|
109
|
-
}
|
|
110
|
-
EntityMetadata.getEmbeddedFieldNames = getEmbeddedFieldNames;
|
|
111
|
-
function getAssociationFieldNames(entity) {
|
|
112
|
-
return getFieldNames(entity, orm_helper_js_1.isAssociationField);
|
|
113
|
-
}
|
|
114
|
-
EntityMetadata.getAssociationFieldNames = getAssociationFieldNames;
|
|
115
|
-
function getNonAssociationFieldNames(entity) {
|
|
116
|
-
return getFieldNames(entity, x => !(0, orm_helper_js_1.isAssociationField)(x));
|
|
117
|
-
}
|
|
118
|
-
EntityMetadata.getNonAssociationFieldNames = getNonAssociationFieldNames;
|
|
119
|
-
function getInsertColumnNames(entity) {
|
|
120
|
-
return getFieldNames(entity, x => (0, orm_helper_js_1.isColumnField)(x) && !x.noInsert);
|
|
121
|
-
}
|
|
122
|
-
EntityMetadata.getInsertColumnNames = getInsertColumnNames;
|
|
123
|
-
function getUpdateColumnNames(entity) {
|
|
124
|
-
return getFieldNames(entity, x => (0, orm_helper_js_1.isColumnField)(x) && !x.noUpdate);
|
|
125
|
-
}
|
|
126
|
-
EntityMetadata.getUpdateColumnNames = getUpdateColumnNames;
|
|
127
|
-
function getPrimaryIndex(entity) {
|
|
128
|
-
return entity.indexes && entity.indexes.find(idx => idx.primary);
|
|
129
|
-
}
|
|
130
|
-
EntityMetadata.getPrimaryIndex = getPrimaryIndex;
|
|
131
|
-
function getPrimaryIndexColumns(entity) {
|
|
132
|
-
const idx = getPrimaryIndex(entity);
|
|
133
|
-
const out = [];
|
|
134
|
-
if (idx) {
|
|
135
|
-
for (const k of idx.columns) {
|
|
136
|
-
const col = getColumnField(entity, k);
|
|
137
|
-
if (!col)
|
|
138
|
-
throw new Error(`Data column "${k}" in primary index of ${entity.name} does not exists`);
|
|
139
|
-
out.push(col);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return out;
|
|
143
|
-
}
|
|
144
|
-
EntityMetadata.getPrimaryIndexColumns = getPrimaryIndexColumns;
|
|
145
|
-
async function getForeignKeyFor(src, trg) {
|
|
146
|
-
if (!src.foreignKeys)
|
|
147
|
-
return;
|
|
148
|
-
for (const f of src.foreignKeys) {
|
|
149
|
-
if ((await f.resolveTarget()) === trg)
|
|
150
|
-
return f;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
EntityMetadata.getForeignKeyFor = getForeignKeyFor;
|
|
154
|
-
function addIndex(entity, index) {
|
|
155
|
-
entity.indexes = entity.indexes || [];
|
|
156
|
-
index = {
|
|
157
|
-
...index,
|
|
158
|
-
columns: Array.isArray(index.columns) ? index.columns : [index.columns],
|
|
159
|
-
};
|
|
160
|
-
if (index.primary)
|
|
161
|
-
entity.indexes.forEach(idx => delete idx.primary);
|
|
162
|
-
entity.indexes.push(index);
|
|
163
|
-
}
|
|
164
|
-
EntityMetadata.addIndex = addIndex;
|
|
165
|
-
function addForeignKey(entity, propertyKey, target, targetKey) {
|
|
166
|
-
entity.foreignKeys = entity.foreignKeys || [];
|
|
167
|
-
const fk = new association_js_1.Association(entity.name + '.' + propertyKey, {
|
|
168
|
-
source: entity.ctor,
|
|
169
|
-
sourceKey: propertyKey,
|
|
170
|
-
target,
|
|
171
|
-
targetKey,
|
|
172
|
-
});
|
|
173
|
-
entity.foreignKeys.push(fk);
|
|
174
|
-
}
|
|
175
|
-
EntityMetadata.addForeignKey = addForeignKey;
|
|
176
|
-
function addEventListener(entity, event, fn) {
|
|
177
|
-
if (typeof fn !== 'function')
|
|
178
|
-
throw new Error('Property must be a function');
|
|
179
|
-
entity.eventListeners = entity.eventListeners || {};
|
|
180
|
-
entity.eventListeners[event] = entity.eventListeners[event] || [];
|
|
181
|
-
entity.eventListeners[event].push(fn);
|
|
182
|
-
}
|
|
183
|
-
EntityMetadata.addEventListener = addEventListener;
|
|
184
|
-
function defineColumnField(entity, name, options = {}) {
|
|
185
|
-
delete entity._fieldNames;
|
|
186
|
-
let prop = EntityMetadata.getField(entity, name);
|
|
187
|
-
if ((0, orm_helper_js_1.isColumnField)(prop))
|
|
188
|
-
options = { ...prop, ...options };
|
|
189
|
-
if (!options.type) {
|
|
190
|
-
switch (options.dataType) {
|
|
191
|
-
case builder_1.DataType.BOOL:
|
|
192
|
-
options.type = Boolean;
|
|
193
|
-
break;
|
|
194
|
-
case builder_1.DataType.VARCHAR:
|
|
195
|
-
case builder_1.DataType.CHAR:
|
|
196
|
-
case builder_1.DataType.TEXT:
|
|
197
|
-
options.type = String;
|
|
198
|
-
break;
|
|
199
|
-
case builder_1.DataType.NUMBER:
|
|
200
|
-
case builder_1.DataType.DOUBLE:
|
|
201
|
-
case builder_1.DataType.FLOAT:
|
|
202
|
-
case builder_1.DataType.INTEGER:
|
|
203
|
-
case builder_1.DataType.SMALLINT:
|
|
204
|
-
options.type = Number;
|
|
205
|
-
break;
|
|
206
|
-
case builder_1.DataType.TIMESTAMP:
|
|
207
|
-
case builder_1.DataType.TIMESTAMPTZ:
|
|
208
|
-
options.type = Date;
|
|
209
|
-
break;
|
|
210
|
-
case builder_1.DataType.BINARY:
|
|
211
|
-
options.type = Buffer;
|
|
212
|
-
break;
|
|
213
|
-
default:
|
|
214
|
-
options.type = String;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
if (!options.dataType) {
|
|
218
|
-
switch (options.type) {
|
|
219
|
-
case Boolean:
|
|
220
|
-
options.dataType = builder_1.DataType.BOOL;
|
|
221
|
-
break;
|
|
222
|
-
case Number:
|
|
223
|
-
options.dataType = builder_1.DataType.NUMBER;
|
|
224
|
-
break;
|
|
225
|
-
case Date:
|
|
226
|
-
options.dataType = builder_1.DataType.TIMESTAMP;
|
|
227
|
-
break;
|
|
228
|
-
case Array:
|
|
229
|
-
options.dataType = builder_1.DataType.VARCHAR;
|
|
230
|
-
options.isArray = true;
|
|
231
|
-
break;
|
|
232
|
-
case Buffer:
|
|
233
|
-
options.dataType = builder_1.DataType.BINARY;
|
|
234
|
-
break;
|
|
235
|
-
default:
|
|
236
|
-
options.dataType = builder_1.DataType.VARCHAR;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
prop = column_field_metadata_js_1.ColumnFieldMetadata.create(entity, name, options);
|
|
240
|
-
entity.fields[name.toLowerCase()] = prop;
|
|
241
|
-
return prop;
|
|
242
|
-
}
|
|
243
|
-
EntityMetadata.defineColumnField = defineColumnField;
|
|
244
|
-
function defineEmbeddedField(entity, name, type, options) {
|
|
245
|
-
delete entity._fieldNames;
|
|
246
|
-
let prop = EntityMetadata.getField(entity, name);
|
|
247
|
-
if ((0, orm_helper_js_1.isEmbeddedField)(prop))
|
|
248
|
-
options = { ...prop, ...options };
|
|
249
|
-
prop = embedded_field_metadata_js_1.EmbeddedFieldMetadata.create(entity, name, type, options);
|
|
250
|
-
entity.fields[name.toLowerCase()] = prop;
|
|
251
|
-
return prop;
|
|
252
|
-
}
|
|
253
|
-
EntityMetadata.defineEmbeddedField = defineEmbeddedField;
|
|
254
|
-
function defineAssociationField(entity, propertyKey, association, options) {
|
|
255
|
-
delete entity._fieldNames;
|
|
256
|
-
const prop = association_field_metadata_js_1.AssociationFieldMetadata.create(entity, propertyKey, association, options);
|
|
257
|
-
let l = association;
|
|
258
|
-
let i = 1;
|
|
259
|
-
while (l) {
|
|
260
|
-
l.name = entity.name + '.' + propertyKey + '#' + i++;
|
|
261
|
-
l = l.next;
|
|
262
|
-
}
|
|
263
|
-
entity.fields[propertyKey.toLowerCase()] = prop;
|
|
264
|
-
return prop;
|
|
265
|
-
}
|
|
266
|
-
EntityMetadata.defineAssociationField = defineAssociationField;
|
|
267
|
-
function setPrimaryKeys(entity, column, options) {
|
|
268
|
-
addIndex(entity, {
|
|
269
|
-
...options,
|
|
270
|
-
columns: Array.isArray(column) ? column : [column],
|
|
271
|
-
unique: true,
|
|
272
|
-
primary: true,
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
EntityMetadata.setPrimaryKeys = setPrimaryKeys;
|
|
276
|
-
function mixin(derived, base, filter) {
|
|
277
|
-
const hasField = (k) => !filter || filter(k);
|
|
278
|
-
delete derived._fieldNames;
|
|
279
|
-
if (!derived.tableName) {
|
|
280
|
-
derived.tableName = base.tableName;
|
|
281
|
-
derived.schema = base.schema;
|
|
282
|
-
derived.comment = base.comment;
|
|
283
|
-
}
|
|
284
|
-
// Copy indexes
|
|
285
|
-
if (base.indexes && base.indexes.length) {
|
|
286
|
-
const hasPrimaryIndex = !!getPrimaryIndex(derived);
|
|
287
|
-
for (const idx of base.indexes) {
|
|
288
|
-
if (!idx.columns.find(x => !hasField(x))) {
|
|
289
|
-
if (hasPrimaryIndex)
|
|
290
|
-
addIndex(derived, { ...idx, primary: undefined });
|
|
291
|
-
else
|
|
292
|
-
addIndex(derived, idx);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
// Copy foreign indexes
|
|
297
|
-
if (base.foreignKeys && base.foreignKeys.length) {
|
|
298
|
-
derived.foreignKeys = derived.foreignKeys || [];
|
|
299
|
-
for (const fk of base.foreignKeys) {
|
|
300
|
-
if (!fk.sourceKey || hasField(fk.sourceKey)) {
|
|
301
|
-
const newFk = new association_js_1.Association(fk.name, {
|
|
302
|
-
...fk,
|
|
303
|
-
source: derived.ctor,
|
|
304
|
-
});
|
|
305
|
-
derived.foreignKeys.push(newFk);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
// Copy event listeners
|
|
310
|
-
if (base.eventListeners) {
|
|
311
|
-
for (const [event, arr] of Object.entries(base.eventListeners)) {
|
|
312
|
-
arr.forEach(fn => EntityMetadata.addEventListener(derived, event, fn));
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
// Copy fields
|
|
316
|
-
derived.fields = derived.fields || {};
|
|
317
|
-
for (const [n, p] of Object.entries(base.fields)) {
|
|
318
|
-
if (!hasField(n))
|
|
319
|
-
continue;
|
|
320
|
-
const o = Object.assign({}, p);
|
|
321
|
-
o.entity = derived;
|
|
322
|
-
Object.setPrototypeOf(o, Object.getPrototypeOf(p));
|
|
323
|
-
derived.fields[n] = o;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
EntityMetadata.mixin = mixin;
|
|
327
|
-
})(EntityMetadata || (exports.EntityMetadata = EntityMetadata = {}));
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LinkChain = void 0;
|
|
4
|
-
const association_node_js_1 = require("./association-node.js");
|
|
5
|
-
class LinkChain {
|
|
6
|
-
target;
|
|
7
|
-
first;
|
|
8
|
-
current;
|
|
9
|
-
constructor(target, targetKey, sourceKey, many) {
|
|
10
|
-
this.target = target;
|
|
11
|
-
this.first = this.current = new association_node_js_1.AssociationNode('', {
|
|
12
|
-
many,
|
|
13
|
-
target,
|
|
14
|
-
source: null,
|
|
15
|
-
sourceKey,
|
|
16
|
-
targetKey: targetKey,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
where(conditions) {
|
|
20
|
-
this.current.conditions = this.current.conditions || [];
|
|
21
|
-
if (Array.isArray(conditions))
|
|
22
|
-
this.current.conditions.push(...conditions);
|
|
23
|
-
else
|
|
24
|
-
this.current.conditions.push(conditions);
|
|
25
|
-
return this;
|
|
26
|
-
}
|
|
27
|
-
linkToOne(target, targetColumn, parentColumn) {
|
|
28
|
-
return this._newNode(target, targetColumn, parentColumn);
|
|
29
|
-
}
|
|
30
|
-
linkToMany(target, targetColumn, parentColumn) {
|
|
31
|
-
return this._newNode(target, targetColumn, parentColumn, true);
|
|
32
|
-
}
|
|
33
|
-
_newNode(target, targetKey, parentKey, many = false) {
|
|
34
|
-
const child = new association_node_js_1.AssociationNode(this.current.name, {
|
|
35
|
-
many,
|
|
36
|
-
source: this.current.target,
|
|
37
|
-
target,
|
|
38
|
-
sourceKey: parentKey,
|
|
39
|
-
targetKey: targetKey,
|
|
40
|
-
});
|
|
41
|
-
child.prior = this.current;
|
|
42
|
-
this.current.next = child;
|
|
43
|
-
this.current = child;
|
|
44
|
-
return this;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.LinkChain = LinkChain;
|
package/cjs/orm/orm.const.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DECORATOR_FACTORY = exports.REPOSITORY_KEY = exports.ENTITY_METADATA_KEY = void 0;
|
|
4
|
-
exports.ENTITY_METADATA_KEY = Symbol.for('SQB_ENTITY_METADATA');
|
|
5
|
-
exports.REPOSITORY_KEY = Symbol.for('SQB_REPOSITORY');
|
|
6
|
-
exports.DECORATOR_FACTORY = Symbol.for('decorator.factory');
|
package/cjs/orm/orm.type.js
DELETED