@sqb/connect 4.11.3 → 4.12.1
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/README.md +9 -24
- package/cjs/client/cursor-stream.js +6 -3
- package/cjs/client/cursor.js +8 -6
- package/cjs/client/field-info-map.js +3 -3
- package/cjs/client/sqb-client.js +2 -3
- package/cjs/client/sqb-connection.js +14 -13
- package/cjs/index.js +1 -0
- package/cjs/orm/commands/command.helper.js +8 -9
- package/cjs/orm/commands/create.command.js +4 -5
- package/cjs/orm/commands/find.command.js +30 -57
- package/cjs/orm/commands/row-converter.js +6 -6
- package/cjs/orm/commands/update.command.js +3 -4
- package/cjs/orm/decorators/column.decorator.js +7 -3
- package/cjs/orm/decorators/embedded.decorator.js +1 -1
- package/cjs/orm/decorators/entity.decorator.js +2 -2
- package/cjs/orm/decorators/link.decorator.js +1 -1
- package/cjs/orm/decorators/transform.decorator.js +2 -4
- package/cjs/orm/model/association-field-metadata.js +1 -1
- package/cjs/orm/model/association.js +2 -4
- package/cjs/orm/model/column-field-metadata.js +1 -1
- package/cjs/orm/model/embedded-field-metadata.js +1 -1
- package/cjs/orm/model/entity-metadata.js +7 -7
- package/cjs/orm/model/link-chain.js +2 -2
- package/cjs/orm/orm.const.js +2 -1
- package/cjs/orm/repository.class.js +29 -15
- package/cjs/orm/util/apply-mixins.js +6 -4
- package/cjs/orm/util/extract-keyvalues.js +1 -1
- package/cjs/orm/util/parse-fields-projection.js +66 -0
- package/cjs/orm/util/serialize-field.js +10 -10
- package/esm/client/cursor-stream.js +6 -3
- package/esm/client/cursor.js +8 -6
- package/esm/client/field-info-map.js +3 -3
- package/esm/client/helpers.js +1 -1
- package/esm/client/sqb-client.js +2 -3
- package/esm/client/sqb-connection.js +15 -14
- package/esm/index.js +1 -0
- package/esm/orm/commands/command.helper.js +9 -10
- package/esm/orm/commands/create.command.js +4 -5
- package/esm/orm/commands/find.command.js +30 -57
- package/esm/orm/commands/row-converter.js +6 -6
- package/esm/orm/commands/update.command.js +3 -4
- package/esm/orm/decorators/column.decorator.js +6 -2
- package/esm/orm/decorators/embedded.decorator.js +1 -1
- package/esm/orm/decorators/entity.decorator.js +2 -2
- package/esm/orm/decorators/link.decorator.js +1 -1
- package/esm/orm/decorators/transform.decorator.js +2 -4
- package/esm/orm/model/association-field-metadata.js +1 -1
- package/esm/orm/model/association.js +2 -4
- package/esm/orm/model/column-field-metadata.js +1 -1
- package/esm/orm/model/embedded-field-metadata.js +1 -1
- package/esm/orm/model/entity-metadata.js +7 -7
- package/esm/orm/model/link-chain.js +2 -2
- package/esm/orm/orm.const.js +1 -0
- package/esm/orm/repository.class.js +29 -15
- package/esm/orm/util/apply-mixins.js +6 -4
- package/esm/orm/util/extract-keyvalues.js +1 -1
- package/esm/orm/util/parse-fields-projection.js +61 -0
- package/esm/orm/util/serialize-field.js +10 -10
- package/package.json +10 -6
- package/types/index.d.ts +1 -0
- package/types/orm/commands/find.command.d.ts +2 -3
- package/types/orm/decorators/column.decorator.d.ts +1 -0
- package/types/orm/decorators/entity.decorator.d.ts +2 -2
- package/types/orm/model/field-metadata.d.ts +1 -1
- package/types/orm/orm.const.d.ts +1 -0
- package/types/orm/orm.type.d.ts +1 -1
- package/types/orm/repository.class.d.ts +11 -8
- package/types/orm/util/parse-fields-projection.d.ts +10 -0
|
@@ -22,8 +22,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
22
22
|
create(values, options) {
|
|
23
23
|
return this._execute(async (connection) => {
|
|
24
24
|
const keyValue = await this._create(values, { ...options, connection, returning: true });
|
|
25
|
-
const result = keyValue &&
|
|
26
|
-
await this._find(keyValue, { ...options, connection });
|
|
25
|
+
const result = keyValue && (await this._find(keyValue, { ...options, connection }));
|
|
27
26
|
if (!result)
|
|
28
27
|
throw new Error('Unable to insert new row');
|
|
29
28
|
return result;
|
|
@@ -39,15 +38,16 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
39
38
|
return this._exists(keyValue, { ...options, connection });
|
|
40
39
|
}, options);
|
|
41
40
|
}
|
|
41
|
+
existsOne(options) {
|
|
42
|
+
return this._execute(async (connection) => {
|
|
43
|
+
return this._existsOne({ ...options, connection });
|
|
44
|
+
}, options);
|
|
45
|
+
}
|
|
42
46
|
count(options) {
|
|
43
47
|
return this._execute(async (connection) => {
|
|
44
48
|
return this._count({ ...options, connection });
|
|
45
49
|
}, options);
|
|
46
50
|
}
|
|
47
|
-
/** @deprecated - Use findById instead */
|
|
48
|
-
find(keyValue, options) {
|
|
49
|
-
return this.findById(keyValue, options);
|
|
50
|
-
}
|
|
51
51
|
findById(keyValue, options) {
|
|
52
52
|
return this._execute(async (connection) => {
|
|
53
53
|
return this._find(keyValue, { ...options, connection });
|
|
@@ -116,7 +116,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
116
116
|
const keyValues = await CreateCommand.execute({
|
|
117
117
|
...options,
|
|
118
118
|
entity: this._entity,
|
|
119
|
-
values
|
|
119
|
+
values,
|
|
120
120
|
});
|
|
121
121
|
if (options.returning && !keyValues)
|
|
122
122
|
throw new Error('Unable to insert new row');
|
|
@@ -130,16 +130,30 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
130
130
|
else
|
|
131
131
|
filter.push(options.filter);
|
|
132
132
|
}
|
|
133
|
-
return
|
|
133
|
+
return this._existsOne({
|
|
134
134
|
...options,
|
|
135
135
|
filter,
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async _existsOne(options) {
|
|
139
|
+
const filter = [];
|
|
140
|
+
if (options && options.filter) {
|
|
141
|
+
if (Array.isArray(options.filter))
|
|
142
|
+
filter.push(...options.filter);
|
|
143
|
+
else
|
|
144
|
+
filter.push(options.filter);
|
|
145
|
+
}
|
|
146
|
+
const resp = await FindCommand.execute({
|
|
147
|
+
...options,
|
|
148
|
+
filter,
|
|
149
|
+
entity: this._entity,
|
|
150
|
+
});
|
|
151
|
+
return resp.length > 0;
|
|
138
152
|
}
|
|
139
153
|
async _count(options) {
|
|
140
154
|
return CountCommand.execute({
|
|
141
155
|
...options,
|
|
142
|
-
entity: this._entity
|
|
156
|
+
entity: this._entity,
|
|
143
157
|
});
|
|
144
158
|
}
|
|
145
159
|
async _findMany(options) {
|
|
@@ -151,7 +165,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
151
165
|
async _findOne(options) {
|
|
152
166
|
const rows = await this._findMany({
|
|
153
167
|
...options,
|
|
154
|
-
limit: 1
|
|
168
|
+
limit: 1,
|
|
155
169
|
});
|
|
156
170
|
return rows && rows[0];
|
|
157
171
|
}
|
|
@@ -184,7 +198,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
184
198
|
...options,
|
|
185
199
|
entity: this._entity,
|
|
186
200
|
filter: options?.filter,
|
|
187
|
-
params: options?.params
|
|
201
|
+
params: options?.params,
|
|
188
202
|
});
|
|
189
203
|
}
|
|
190
204
|
async _update(keyValue, values, options) {
|
|
@@ -204,7 +218,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
204
218
|
...options,
|
|
205
219
|
entity: this._entity,
|
|
206
220
|
values: updateValues,
|
|
207
|
-
filter
|
|
221
|
+
filter,
|
|
208
222
|
});
|
|
209
223
|
return rowsAffected ? keyValues : undefined;
|
|
210
224
|
}
|
|
@@ -214,7 +228,7 @@ export class Repository extends TypedEventEmitterClass(AsyncEventEmitter) {
|
|
|
214
228
|
return await UpdateCommand.execute({
|
|
215
229
|
...options,
|
|
216
230
|
entity: this._entity,
|
|
217
|
-
values
|
|
231
|
+
values,
|
|
218
232
|
});
|
|
219
233
|
}
|
|
220
234
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export function applyMixins(derivedCtor, baseCtor, filter) {
|
|
2
2
|
for (const name of Object.getOwnPropertyNames(baseCtor.prototype)) {
|
|
3
|
-
if (
|
|
4
|
-
|
|
3
|
+
if (name === 'constructor' ||
|
|
4
|
+
name === '__proto__' ||
|
|
5
|
+
name === 'toJSON' ||
|
|
6
|
+
name === 'toString' ||
|
|
7
|
+
(filter && !filter(name)))
|
|
5
8
|
continue;
|
|
6
|
-
Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name) ||
|
|
7
|
-
Object.create(null));
|
|
9
|
+
Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name) || Object.create(null));
|
|
8
10
|
}
|
|
9
11
|
}
|
|
@@ -4,7 +4,7 @@ export function extractKeyValues(entityDef, valueOrInstance, keepOther) {
|
|
|
4
4
|
const primaryIndex = EntityMetadata.getPrimaryIndex(entityDef);
|
|
5
5
|
if (!primaryIndex)
|
|
6
6
|
throw new Error(`No primary fields defined for "${entityDef.name}" entity`);
|
|
7
|
-
const validateCol =
|
|
7
|
+
const validateCol = k => {
|
|
8
8
|
const col = EntityMetadata.getField(entityDef, k);
|
|
9
9
|
if (!col)
|
|
10
10
|
throw new Error(`Unknown column (${k}) defined as primary key in entity "${entityDef.name}"`);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { splitString } from 'fast-tokenizer';
|
|
2
|
+
const FIELD_PATTERN = /^([+-])?([a-z_$]\w*)$/i;
|
|
3
|
+
const NO_DOT_BRACKET_PATTERN = /[^.]\(/g;
|
|
4
|
+
export class FieldsProjection {
|
|
5
|
+
}
|
|
6
|
+
(function (FieldsProjection) {
|
|
7
|
+
class Item {
|
|
8
|
+
}
|
|
9
|
+
FieldsProjection.Item = Item;
|
|
10
|
+
})(FieldsProjection || (FieldsProjection = {}));
|
|
11
|
+
export function parseFieldsProjection(projection, keepCase) {
|
|
12
|
+
const arr = Array.isArray(projection) ? projection : [projection];
|
|
13
|
+
if (!(arr && arr.length))
|
|
14
|
+
return;
|
|
15
|
+
const out = new FieldsProjection();
|
|
16
|
+
for (let s of arr) {
|
|
17
|
+
if (!keepCase)
|
|
18
|
+
s = s.toLowerCase();
|
|
19
|
+
parse(s, out);
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
function parse(input, target) {
|
|
24
|
+
/** Add dot before brackets which is required to split fields */
|
|
25
|
+
input = input.replace(NO_DOT_BRACKET_PATTERN, s => {
|
|
26
|
+
return s.charAt(0) + '.' + s.substring(1);
|
|
27
|
+
});
|
|
28
|
+
const fields = splitString(input, {
|
|
29
|
+
delimiters: '.',
|
|
30
|
+
brackets: true,
|
|
31
|
+
keepBrackets: false,
|
|
32
|
+
});
|
|
33
|
+
for (let i = 0; i < fields.length; i++) {
|
|
34
|
+
const f = fields[i];
|
|
35
|
+
if (f.includes(',')) {
|
|
36
|
+
const subFields = splitString(f, {
|
|
37
|
+
delimiters: ',',
|
|
38
|
+
brackets: true,
|
|
39
|
+
keepBrackets: true,
|
|
40
|
+
});
|
|
41
|
+
for (const n of subFields) {
|
|
42
|
+
parse(n, target);
|
|
43
|
+
}
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const m = FIELD_PATTERN.exec(f);
|
|
47
|
+
/* istanbul ignore next */
|
|
48
|
+
if (!m)
|
|
49
|
+
throw new TypeError(`Invalid field path (${input})`);
|
|
50
|
+
const fieldName = m[2];
|
|
51
|
+
const treeItem = (target[fieldName] = target[fieldName] || new FieldsProjection.Item());
|
|
52
|
+
if (m[1])
|
|
53
|
+
treeItem.sign = m[1];
|
|
54
|
+
if (i === fields.length - 1) {
|
|
55
|
+
delete treeItem.projection;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
target = treeItem.projection = treeItem.projection || new FieldsProjection();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -17,19 +17,19 @@ const padZero = (n) => (n < 9 ? '0' : '') + n;
|
|
|
17
17
|
function serializeDataValue(dataType, v) {
|
|
18
18
|
if (v == null)
|
|
19
19
|
return;
|
|
20
|
-
if (v instanceof Date &&
|
|
21
|
-
(
|
|
22
|
-
|
|
23
|
-
padZero(v.getMonth() + 1) +
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
padZero(v.
|
|
20
|
+
if (v instanceof Date && (dataType === DataType.DATE || dataType === DataType.TIMESTAMP)) {
|
|
21
|
+
return (v.getFullYear() +
|
|
22
|
+
'-' +
|
|
23
|
+
padZero(v.getMonth() + 1) +
|
|
24
|
+
'-' +
|
|
25
|
+
padZero(v.getDate()) +
|
|
26
|
+
(dataType === DataType.TIMESTAMP
|
|
27
|
+
? 'T' + padZero(v.getHours()) + ':' + padZero(v.getMinutes()) + ':' + padZero(v.getSeconds())
|
|
28
|
+
: ''));
|
|
28
29
|
}
|
|
29
30
|
if (v instanceof Buffer)
|
|
30
31
|
return v.toString('base64');
|
|
31
|
-
if (typeof v === 'number' && (dataType === DataType.SMALLINT ||
|
|
32
|
-
dataType === DataType.INTEGER))
|
|
32
|
+
if (typeof v === 'number' && (dataType === DataType.SMALLINT || dataType === DataType.INTEGER))
|
|
33
33
|
return Math.trunc(v);
|
|
34
34
|
if (typeof v === 'bigint')
|
|
35
35
|
return v.toString();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqb/connect",
|
|
3
3
|
"description": "Multi-dialect database connection framework written with TypeScript",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.12.1",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Eray Hanoglu <e.hanoglu@panates.com>",
|
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
"build:esm": "tsc -b tsconfig-build-esm.json",
|
|
26
26
|
"postbuild": "cp README.md package.json ../../LICENSE ../../build/connect && cp ../../package.cjs.json ../../build/connect/cjs/package.json",
|
|
27
27
|
"lint": "eslint . --max-warnings=0",
|
|
28
|
+
"lint:fix": "eslint . --max-warnings=0 --fix",
|
|
29
|
+
"format": "prettier . --write --log-level=warn",
|
|
28
30
|
"test": "jest",
|
|
29
31
|
"cover": "jest --collect-coverage",
|
|
30
32
|
"clean": "npm run clean:src | npm run clean:dist | npm run clean:cover",
|
|
@@ -33,7 +35,8 @@
|
|
|
33
35
|
"clean:cover": "rimraf ../../coverage/connect"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"debug": "^4.3.
|
|
38
|
+
"debug": "^4.3.5",
|
|
39
|
+
"fast-tokenizer": "^1.3.0",
|
|
37
40
|
"lightning-pool": "^4.2.2",
|
|
38
41
|
"lodash": "^4.17.21",
|
|
39
42
|
"power-tasks": "^1.7.3",
|
|
@@ -42,15 +45,16 @@
|
|
|
42
45
|
"putil-promisify": "^1.10.1",
|
|
43
46
|
"putil-varhelpers": "^1.6.5",
|
|
44
47
|
"strict-typed-events": "^2.3.3",
|
|
45
|
-
"ts-gems": "^3.
|
|
48
|
+
"ts-gems": "^3.4.0"
|
|
46
49
|
},
|
|
47
50
|
"devDependencies": {
|
|
48
51
|
"@types/debug": "^4.1.12",
|
|
49
|
-
"@types/lodash": "^4.17.
|
|
52
|
+
"@types/lodash": "^4.17.5",
|
|
53
|
+
"postgresql-client": "^2.11.2"
|
|
50
54
|
},
|
|
51
55
|
"peerDependencies": {
|
|
52
|
-
"@sqb/builder": "^4.
|
|
53
|
-
"reflect-metadata": "^0.
|
|
56
|
+
"@sqb/builder": "^4.12.1",
|
|
57
|
+
"reflect-metadata": "^0.2.2"
|
|
54
58
|
},
|
|
55
59
|
"engines": {
|
|
56
60
|
"node": ">=16.0",
|
package/types/index.d.ts
CHANGED
|
@@ -28,4 +28,5 @@ export * from './orm/decorators/link.decorator.js';
|
|
|
28
28
|
export * from './orm/decorators/primarykey.decorator.js';
|
|
29
29
|
export * from './orm/decorators/transform.decorator.js';
|
|
30
30
|
export { isColumnField, isEmbeddedField, isAssociationField, isEntityClass } from './orm/util/orm.helper.js';
|
|
31
|
+
export * from './orm/util/parse-fields-projection.js';
|
|
31
32
|
export * from './orm/backward.js';
|
|
@@ -2,6 +2,7 @@ import { SqbConnection } from '../../client/sqb-connection.js';
|
|
|
2
2
|
import { AssociationNode } from '../model/association-node.js';
|
|
3
3
|
import { EntityMetadata } from '../model/entity-metadata.js';
|
|
4
4
|
import { Repository } from '../repository.class.js';
|
|
5
|
+
import { FieldsProjection } from '../util/parse-fields-projection.js';
|
|
5
6
|
import { RowConverter } from './row-converter.js';
|
|
6
7
|
export type FindCommandArgs = {
|
|
7
8
|
entity: EntityMetadata;
|
|
@@ -29,9 +30,7 @@ export declare class FindCommand {
|
|
|
29
30
|
tableAlias?: string;
|
|
30
31
|
converter?: RowConverter;
|
|
31
32
|
entity?: EntityMetadata;
|
|
32
|
-
|
|
33
|
-
omit?: string[];
|
|
34
|
-
include?: string[];
|
|
33
|
+
projection?: FieldsProjection | string | string[];
|
|
35
34
|
sort?: string[];
|
|
36
35
|
prefix?: string;
|
|
37
36
|
suffix?: string;
|
|
@@ -2,3 +2,4 @@ import { DataType } from '@sqb/builder';
|
|
|
2
2
|
import { ColumnFieldOptions } from '../model/column-field-metadata.js';
|
|
3
3
|
export declare function Column(type?: DataType): PropertyDecorator;
|
|
4
4
|
export declare function Column(options?: ColumnFieldOptions): PropertyDecorator;
|
|
5
|
+
export declare namespace Column { }
|
|
@@ -28,8 +28,8 @@ export declare namespace Entity {
|
|
|
28
28
|
function mixin<A, B, C, D>(derivedCtor: Type<A>, baseB: Type<B>, baseC: Type<C>, baseD: Type<D>): Type<A & B & C & D>;
|
|
29
29
|
function mixin<A, B, C, D, E>(derivedCtor: Type<A>, baseB: Type<B>, baseC: Type<C>, baseD: Type<D>, baseE: Type<E>): Type<A & B & C & D & E>;
|
|
30
30
|
function mixin<A, B, C, D, E, F>(derivedCtor: Type<A>, baseB: Type<B>, baseC: Type<C>, baseD: Type<D>, baseE: Type<E>, baseF: Type<F>): Type<A & B & C & D & E & F>;
|
|
31
|
-
function Pick<T, K extends keyof T>(classRef: Type<T>, keys: readonly K[]): Type<Pick<T, typeof keys[number]>>;
|
|
32
|
-
function Omit<T, K extends keyof T>(classRef: Type<T>, keys: readonly K[]): Type<Omit<T, typeof keys[number]>>;
|
|
31
|
+
function Pick<T, K extends keyof T>(classRef: Type<T>, keys: readonly K[]): Type<Pick<T, (typeof keys)[number]>>;
|
|
32
|
+
function Omit<T, K extends keyof T>(classRef: Type<T>, keys: readonly K[]): Type<Omit<T, (typeof keys)[number]>>;
|
|
33
33
|
function Union<A, B>(baseA: Type<A>, baseB: Type<B>): Type<A & B>;
|
|
34
34
|
function Union<A, B, C>(baseA: Type<A>, baseB: Type<B>, baseC: Type<C>): Type<A & B & C>;
|
|
35
35
|
function Union<A, B, C, D>(baseA: Type<A>, baseB: Type<B>, baseC: Type<C>, baseD: Type<D>): Type<A & B & C & D>;
|
|
@@ -10,7 +10,7 @@ export interface FieldMetadata {
|
|
|
10
10
|
hidden?: boolean;
|
|
11
11
|
/**
|
|
12
12
|
* Indicates whether or not to include this field by default when making queries.
|
|
13
|
-
* If this set to "true" the field must be requested using "
|
|
13
|
+
* If this set to "true" the field must be requested using "projection" option.
|
|
14
14
|
*/
|
|
15
15
|
exclusive?: boolean;
|
|
16
16
|
}
|
package/types/orm/orm.const.d.ts
CHANGED
package/types/orm/orm.type.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type ColumnAutoGenerationStrategy = 'increment' | 'uuid' | 'rowid' | 'tim
|
|
|
8
8
|
export type ColumnTransformFunction = (value: any, name: string) => any;
|
|
9
9
|
export type TypeResolver<T> = () => Type<T> | Promise<Type<T>>;
|
|
10
10
|
export type TypeThunk<T = any> = Type<T> | TypeResolver<T>;
|
|
11
|
-
export type EnumValue =
|
|
11
|
+
export type EnumValue = FieldValue[] | Object;
|
|
12
12
|
export type FieldValue = string | number | boolean | Date | null;
|
|
13
13
|
export type DefaultValueGetter = (obj?: any) => FieldValue | undefined;
|
|
14
14
|
export interface AssociationSettings {
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { PartialDTO, PatchDTO, StrictOmit, Type } from 'ts-gems';
|
|
2
|
+
import { LogicalOperator } from '@sqb/builder';
|
|
2
3
|
import { FieldInfoMap } from '../client/field-info-map.js';
|
|
3
4
|
import { SqbClient } from '../client/sqb-client.js';
|
|
4
5
|
import { SqbConnection } from '../client/sqb-connection.js';
|
|
5
6
|
import { QueryRequest, TransactionFunction } from '../client/types.js';
|
|
6
7
|
import { EntityMetadata } from './model/entity-metadata.js';
|
|
7
8
|
interface Projection {
|
|
8
|
-
|
|
9
|
-
omit?: string[];
|
|
10
|
-
include?: string[];
|
|
9
|
+
projection?: string | string[];
|
|
11
10
|
}
|
|
12
11
|
interface Filtering {
|
|
13
|
-
filter?:
|
|
12
|
+
filter?: LogicalOperator | LogicalOperator[] | object | object[];
|
|
14
13
|
params?: any;
|
|
15
14
|
}
|
|
16
15
|
export declare namespace Repository {
|
|
@@ -30,7 +29,7 @@ export declare namespace Repository {
|
|
|
30
29
|
}
|
|
31
30
|
interface FindOptions extends CommandOptions, Projection, Filtering {
|
|
32
31
|
}
|
|
33
|
-
interface FindOneOptions extends
|
|
32
|
+
interface FindOneOptions extends FindOptions {
|
|
34
33
|
sort?: string[];
|
|
35
34
|
offset?: number;
|
|
36
35
|
}
|
|
@@ -43,6 +42,8 @@ export declare namespace Repository {
|
|
|
43
42
|
}
|
|
44
43
|
interface UpdateOptions extends CommandOptions, Projection, Filtering {
|
|
45
44
|
}
|
|
45
|
+
interface UpdateOnlyOptions extends CommandOptions, Filtering {
|
|
46
|
+
}
|
|
46
47
|
interface UpdateManyOptions extends CommandOptions, Filtering {
|
|
47
48
|
}
|
|
48
49
|
}
|
|
@@ -62,16 +63,15 @@ export declare class Repository<T> extends Repository_base {
|
|
|
62
63
|
create(values: PartialDTO<T>, options?: Repository.CreateOptions): Promise<PartialDTO<T>>;
|
|
63
64
|
createOnly(values: PartialDTO<T>, options?: StrictOmit<Repository.CreateOptions, keyof Projection>): Promise<void>;
|
|
64
65
|
exists(keyValue: any | Record<string, any>, options?: Repository.ExistsOptions): Promise<boolean>;
|
|
66
|
+
existsOne(options?: Repository.ExistsOptions): Promise<boolean>;
|
|
65
67
|
count(options?: Repository.CountOptions): Promise<number>;
|
|
66
|
-
/** @deprecated - Use findById instead */
|
|
67
|
-
find(keyValue: any | Record<string, any>, options?: Repository.FindOptions): Promise<PartialDTO<T> | undefined>;
|
|
68
68
|
findById(keyValue: any | Record<string, any>, options?: Repository.FindOptions): Promise<PartialDTO<T> | undefined>;
|
|
69
69
|
findOne(options?: Repository.FindOneOptions): Promise<PartialDTO<T> | undefined>;
|
|
70
70
|
findMany(options?: Repository.FindManyOptions): Promise<PartialDTO<T>[]>;
|
|
71
71
|
delete(keyValue: any | Record<string, any>, options?: Repository.DeleteOptions): Promise<boolean>;
|
|
72
72
|
deleteMany(options?: Repository.DeleteManyOptions): Promise<number>;
|
|
73
73
|
update(keyValue: any | Record<string, any>, values: PatchDTO<T>, options?: Repository.UpdateOptions): Promise<PartialDTO<T> | undefined>;
|
|
74
|
-
updateOnly(keyValue: any | Record<string, any>, values: PatchDTO<T>, options?:
|
|
74
|
+
updateOnly(keyValue: any | Record<string, any>, values: PatchDTO<T>, options?: Repository.UpdateOnlyOptions): Promise<boolean>;
|
|
75
75
|
updateMany(values: PartialDTO<T>, options?: Repository.UpdateManyOptions): Promise<number>;
|
|
76
76
|
protected _execute(fn: TransactionFunction, opts?: Repository.CommandOptions): Promise<any>;
|
|
77
77
|
protected _create(values: PartialDTO<T>, options: Repository.CreateOptions & {
|
|
@@ -81,6 +81,9 @@ export declare class Repository<T> extends Repository_base {
|
|
|
81
81
|
protected _exists(keyValue: any | Record<string, any>, options: Repository.ExistsOptions & {
|
|
82
82
|
connection: SqbConnection;
|
|
83
83
|
}): Promise<boolean>;
|
|
84
|
+
protected _existsOne(options: Repository.ExistsOptions & {
|
|
85
|
+
connection: SqbConnection;
|
|
86
|
+
}): Promise<boolean>;
|
|
84
87
|
protected _count(options: Repository.CountOptions & {
|
|
85
88
|
connection: SqbConnection;
|
|
86
89
|
}): Promise<number>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class FieldsProjection {
|
|
2
|
+
[key: string]: FieldsProjection.Item;
|
|
3
|
+
}
|
|
4
|
+
export declare namespace FieldsProjection {
|
|
5
|
+
class Item {
|
|
6
|
+
sign?: string;
|
|
7
|
+
projection?: FieldsProjection;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare function parseFieldsProjection(projection: string | string[], keepCase?: boolean): FieldsProjection | undefined;
|