@volcanicminds/typeorm 0.0.9 → 0.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.
- package/dist/index.d.ts +3 -1
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/query.d.ts +16 -0
- package/dist/lib/query.js +88 -0
- package/dist/lib/query.js.map +1 -0
- package/esm/index.d.ts +3 -1
- package/esm/index.js +7 -2
- package/esm/index.js.map +1 -1
- package/esm/lib/query.d.ts +16 -0
- package/esm/lib/query.js +67 -0
- package/esm/lib/query.js.map +1 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
+
import { DataSource } from 'typeorm';
|
|
2
3
|
import * as userManager from './lib/loader/userManager';
|
|
3
4
|
import { User } from './lib/entities/user.e';
|
|
5
|
+
import { applyQuery, executeCountQuery, executeFindQuery } from './lib/query';
|
|
4
6
|
export { Database } from './types/global';
|
|
5
|
-
export { User, userManager };
|
|
7
|
+
export { User, userManager, DataSource, applyQuery, executeCountQuery, executeFindQuery };
|
package/dist/index.js
CHANGED
|
@@ -32,14 +32,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.userManager = exports.User = void 0;
|
|
35
|
+
exports.executeFindQuery = exports.executeCountQuery = exports.applyQuery = exports.DataSource = exports.userManager = exports.User = void 0;
|
|
36
36
|
require("reflect-metadata");
|
|
37
37
|
const typeorm_1 = require("typeorm");
|
|
38
|
+
Object.defineProperty(exports, "DataSource", { enumerable: true, get: function () { return typeorm_1.DataSource; } });
|
|
38
39
|
const loaderEntities = __importStar(require("./lib/loader/entities"));
|
|
39
40
|
const userManager = __importStar(require("./lib/loader/userManager"));
|
|
40
41
|
exports.userManager = userManager;
|
|
41
42
|
const user_e_1 = require("./lib/entities/user.e");
|
|
42
43
|
Object.defineProperty(exports, "User", { enumerable: true, get: function () { return user_e_1.User; } });
|
|
44
|
+
const query_1 = require("./lib/query");
|
|
45
|
+
Object.defineProperty(exports, "applyQuery", { enumerable: true, get: function () { return query_1.applyQuery; } });
|
|
46
|
+
Object.defineProperty(exports, "executeCountQuery", { enumerable: true, get: function () { return query_1.executeCountQuery; } });
|
|
47
|
+
Object.defineProperty(exports, "executeFindQuery", { enumerable: true, get: function () { return query_1.executeFindQuery; } });
|
|
43
48
|
function start(options) {
|
|
44
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
50
|
return new Promise((resolve, reject) => {
|
|
@@ -89,5 +94,5 @@ function start(options) {
|
|
|
89
94
|
});
|
|
90
95
|
});
|
|
91
96
|
}
|
|
92
|
-
module.exports = { start, User: user_e_1.User, userManager };
|
|
97
|
+
module.exports = { start, User: user_e_1.User, userManager, applyQuery: query_1.applyQuery, executeCountQuery: query_1.executeCountQuery, executeFindQuery: query_1.executeFindQuery };
|
|
93
98
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEZ,4BAAyB;AACzB,qCAAoC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEZ,4BAAyB;AACzB,qCAAoC;AAqER,2FArEnB,oBAAU,OAqEmB;AApEtC,sEAAuD;AACvD,sEAAuD;AAmExC,kCAAW;AAlE1B,kDAA4C;AAkEnC,qFAlEA,aAAI,OAkEA;AAjEb,uCAA6E;AAiErC,2FAjE/B,kBAAU,OAiE+B;AAAE,kGAjE/B,yBAAiB,O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AAQ,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAA;YACrE,OAAO,CAAC,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,gBAAgB,CAAA;YACrE,OAAO,CAAC,OAAO,GAAG,QAAQ,CAAA;YAQ1B,IAAI,oBAAU,CAAC,OAAO,CAAC;iBACpB,UAAU,EAAE;iBACZ,IAAI,CAAC,CAAO,EAAE,EAAE,EAAE;gBAEjB,MAAM,UAAU,GAAG,EAAE,CAAA;gBACrB,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;gBAEzF,MAAM,CAAC,UAAU,GAAG,EAAE,CAAA;gBACtB,MAAM,CAAC,MAAM,GAAG,OAAO,CAAA;gBACvB,MAAM,CAAC,UAAU,GAAG,UAAU,CAAA;gBAC9B,OAAO,OAAO,CAAC,EAAE,CAAC,CAAA;YACpB,CAAC,CAAA,CAAC;iBACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;QACpC,CAAC,CAAC,CAAA;IACJ,CAAC;CAAA;AAID,MAAM,CAAC,OAAO,GAAG,EAAE,KAAK,EAAE,IAAI,EAAJ,aAAI,EAAE,WAAW,EAAE,UAAU,EAAV,kBAAU,EAAE,iBAAiB,EAAjB,yBAAiB,EAAE,gBAAgB,EAAhB,wBAAgB,EAAE,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare function applyQuery(data: any): {
|
|
2
|
+
skip?: number | undefined;
|
|
3
|
+
take?: number | undefined;
|
|
4
|
+
order?: object | undefined;
|
|
5
|
+
where?: object | undefined;
|
|
6
|
+
};
|
|
7
|
+
export declare function executeFindQuery(repo: any, relations?: {}, data?: {}): Promise<{
|
|
8
|
+
records: any;
|
|
9
|
+
headers: {
|
|
10
|
+
'v-total': any;
|
|
11
|
+
'v-count': any;
|
|
12
|
+
'v-pagesize': number | undefined;
|
|
13
|
+
'v-page': number;
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
16
|
+
export declare function executeCountQuery(repo: any, data?: {}): Promise<any>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.executeCountQuery = exports.executeFindQuery = exports.applyQuery = void 0;
|
|
24
|
+
function applyQuery(data) {
|
|
25
|
+
const { page = 0, pageSize = 0, skip: sk = 0, take: tk = 0, sort: s } = data, where = __rest(data, ["page", "pageSize", "skip", "take", "sort"]);
|
|
26
|
+
const take = tk || pageSize || 50;
|
|
27
|
+
const skip = sk || page * pageSize || 0;
|
|
28
|
+
const order = !Array.isArray(s) ? [s] : s;
|
|
29
|
+
const evalOrder = (val = '') => (['desc', 'd', 'false', '1'].includes(val.toLowerCase()) ? 'desc' : 'asc');
|
|
30
|
+
const useOrder = (order = []) => {
|
|
31
|
+
const orderBy = {};
|
|
32
|
+
order
|
|
33
|
+
.filter((o) => !!o)
|
|
34
|
+
.forEach((o) => {
|
|
35
|
+
const p = o.split(':');
|
|
36
|
+
orderBy[p[0]] = evalOrder(p[1]);
|
|
37
|
+
});
|
|
38
|
+
return orderBy;
|
|
39
|
+
};
|
|
40
|
+
const useWhere = (where) => {
|
|
41
|
+
const result = {};
|
|
42
|
+
for (const objectPath in where) {
|
|
43
|
+
const parts = objectPath.split('.');
|
|
44
|
+
let target = result;
|
|
45
|
+
while (parts.length > 1) {
|
|
46
|
+
const part = parts.shift() || '';
|
|
47
|
+
target = target[part] = target[part] || {};
|
|
48
|
+
}
|
|
49
|
+
target[parts[0]] = where[objectPath];
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
};
|
|
53
|
+
const query = {};
|
|
54
|
+
if (skip)
|
|
55
|
+
query.skip = skip;
|
|
56
|
+
if (take)
|
|
57
|
+
query.take = take;
|
|
58
|
+
if (order)
|
|
59
|
+
query.order = useOrder(order);
|
|
60
|
+
if (where)
|
|
61
|
+
query.where = useWhere(where);
|
|
62
|
+
return query;
|
|
63
|
+
}
|
|
64
|
+
exports.applyQuery = applyQuery;
|
|
65
|
+
function executeFindQuery(repo, relations = {}, data = {}) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const extra = applyQuery(data);
|
|
68
|
+
const [records = [], totalCount] = yield repo.findAndCount(Object.assign({ relations: relations }, extra));
|
|
69
|
+
return {
|
|
70
|
+
records,
|
|
71
|
+
headers: {
|
|
72
|
+
'v-total': totalCount,
|
|
73
|
+
'v-count': records.length,
|
|
74
|
+
'v-pagesize': extra.take,
|
|
75
|
+
'v-page': 1
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
exports.executeFindQuery = executeFindQuery;
|
|
81
|
+
function executeCountQuery(repo, data = {}) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const { where = {} } = applyQuery(data);
|
|
84
|
+
return yield repo.count({ where: where });
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
exports.executeCountQuery = executeCountQuery;
|
|
88
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../lib/query.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAgB,UAAU,CAAC,IAAI;IAC7B,MAAM,EAAE,IAAI,GAAG,CAAC,EAAE,QAAQ,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,KAAe,IAAI,EAAd,KAAK,UAAK,IAAI,EAAhF,4CAAyE,CAAO,CAAA;IACtF,MAAM,IAAI,GAAW,EAAE,IAAI,QAAQ,IAAI,EAAE,CAAA;IACzC,MAAM,IAAI,GAAW,EAAE,IAAI,IAAI,GAAG,QAAQ,IAAI,CAAC,CAAA;IAC/C,MAAM,KAAK,GAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAEnD,MAAM,SAAS,GAAG,CAAC,MAAc,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAA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AAG,IAAI,CAAA;IAC3B,IAAI,IAAI;QAAE,KAAK,CAAC,IAAI,GAAG,IAAI,CAAA;IAC3B,IAAI,KAAK;QAAE,KAAK,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IACxC,IAAI,KAAK;QAAE,KAAK,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IACxC,OAAO,KAAK,CAAA;AACd,CAAC;AArDD,gCAqDC;AAED,SAAsB,gBAAgB,CAAC,IAAS,EAAE,SAAS,GAAG,EAAE,EAAE,IAAI,GAAG,EAAE;;QACzE,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;QAE9B,MAAM,CAAC,OAAO,GAAG,EAAE,EAAE,UAAU,CAAC,GAAG,MAAM,IAAI,CAAC,YAAY,iBACxD,SAAS,EAAE,SAAS,IACjB,KAAK,EACR,CAAA;QAEF,OAAO;YACL,OAAO;YACP,OAAO,EAAE;gBACP,SAAS,EAAE,UAAU;gBACrB,SAAS,EAAE,OAAO,CAAC,MAAM;gBACzB,YAAY,EAAE,KAAK,CAAC,IAAI;gBACxB,QAAQ,EAAE,CAAC;aACZ;SACF,CAAA;IACH,CAAC;CAAA;AAjBD,4CAiBC;AAED,SAAsB,iBAAiB,CAAC,IAAS,EAAE,IAAI,GAAG,EAAE;;QAC1D,MAAM,EAAE,KAAK,GAAG,EAAE,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;QACvC,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IAC3C,CAAC;CAAA;AAHD,8CAGC"}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
+
import { DataSource } from 'typeorm';
|
|
2
3
|
import * as userManager from './lib/loader/userManager';
|
|
3
4
|
import { User } from './lib/entities/user.e';
|
|
5
|
+
import { applyQuery, executeCountQuery, executeFindQuery } from './lib/query';
|
|
4
6
|
export { Database } from './types/global';
|
|
5
|
-
export { User, userManager };
|
|
7
|
+
export { User, userManager, DataSource, applyQuery, executeCountQuery, executeFindQuery };
|
package/esm/index.js
CHANGED
|
@@ -23,14 +23,19 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.userManager = exports.User = void 0;
|
|
26
|
+
exports.executeFindQuery = exports.executeCountQuery = exports.applyQuery = exports.DataSource = exports.userManager = exports.User = void 0;
|
|
27
27
|
require("reflect-metadata");
|
|
28
28
|
const typeorm_1 = require("typeorm");
|
|
29
|
+
Object.defineProperty(exports, "DataSource", { enumerable: true, get: function () { return typeorm_1.DataSource; } });
|
|
29
30
|
const loaderEntities = __importStar(require("./lib/loader/entities"));
|
|
30
31
|
const userManager = __importStar(require("./lib/loader/userManager"));
|
|
31
32
|
exports.userManager = userManager;
|
|
32
33
|
const user_e_1 = require("./lib/entities/user.e");
|
|
33
34
|
Object.defineProperty(exports, "User", { enumerable: true, get: function () { return user_e_1.User; } });
|
|
35
|
+
const query_1 = require("./lib/query");
|
|
36
|
+
Object.defineProperty(exports, "applyQuery", { enumerable: true, get: function () { return query_1.applyQuery; } });
|
|
37
|
+
Object.defineProperty(exports, "executeCountQuery", { enumerable: true, get: function () { return query_1.executeCountQuery; } });
|
|
38
|
+
Object.defineProperty(exports, "executeFindQuery", { enumerable: true, get: function () { return query_1.executeFindQuery; } });
|
|
34
39
|
async function start(options) {
|
|
35
40
|
return new Promise((resolve, reject) => {
|
|
36
41
|
if (global.npmDebugServerStarted) {
|
|
@@ -78,5 +83,5 @@ async function start(options) {
|
|
|
78
83
|
.catch((error) => reject(error));
|
|
79
84
|
});
|
|
80
85
|
}
|
|
81
|
-
module.exports = { start, User: user_e_1.User, userManager };
|
|
86
|
+
module.exports = { start, User: user_e_1.User, userManager, applyQuery: query_1.applyQuery, executeCountQuery: query_1.executeCountQuery, executeFindQuery: query_1.executeFindQuery };
|
|
82
87
|
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;AAEZ,4BAAyB;AACzB,qCAAoC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;AAEZ,4BAAyB;AACzB,qCAAoC;AAqER,2FArEnB,oBAAU,OAqEmB;AApEtC,sEAAuD;AACvD,sEAAuD;AAmExC,kCAAW;AAlE1B,kDAA4C;AAkEnC,qFAlEA,aAAI,OAkEA;AAjEb,uCAA6E;AAiErC,2FAjE/B,kBAAU,OAiE+B;AAAE,kGAjE/B,yBAAiB,OAiE+B;AAAE,iGAjE/B,wBAAgB,OAiE+B;AA/DvF,KAAK,UAAU,KAAK,CAAC,OAAO;IAC1B,OAAO,IAAI,OAAO,CAAa,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACjD,IAAI,MAAM,CAAC,qBAAqB,EAAE;YAChC,OAAO,GAAG;gBACR,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,IAAI;gBACV,QAAQ,EAAE,QAAQ;gBAClB,QAAQ,EAAE,QAAQ;gBAClB,QAAQ,EAAE,QAAQ;gBAClB,WAAW,EAAE,IAAI;gBACjB,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,EAAE;aACX,CAAA;SACF;QAED,IAAI,OAAO,IAAI,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,IAAI,CAAC,EAAE;YACvD,MAAM,KAAK,CAAC,0CAA0C,CAAC,CAAA;SACxD;QAED,MAAM,EAAE,Y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,MAAM,GAAG,OAAO,CAAA;YACvB,MAAM,CAAC,UAAU,GAAG,UAAU,CAAA;YAC9B,OAAO,OAAO,CAAC,EAAE,CAAC,CAAA;QACpB,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IACpC,CAAC,CAAC,CAAA;AACJ,CAAC;AAID,MAAM,CAAC,OAAO,GAAG,EAAE,KAAK,EAAE,IAAI,EAAJ,aAAI,EAAE,WAAW,EAAE,UAAU,EAAV,kBAAU,EAAE,iBAAiB,EAAjB,yBAAiB,EAAE,gBAAgB,EAAhB,wBAAgB,EAAE,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare function applyQuery(data: any): {
|
|
2
|
+
skip?: number | undefined;
|
|
3
|
+
take?: number | undefined;
|
|
4
|
+
order?: object | undefined;
|
|
5
|
+
where?: object | undefined;
|
|
6
|
+
};
|
|
7
|
+
export declare function executeFindQuery(repo: any, relations?: {}, data?: {}): Promise<{
|
|
8
|
+
records: any;
|
|
9
|
+
headers: {
|
|
10
|
+
'v-total': any;
|
|
11
|
+
'v-count': any;
|
|
12
|
+
'v-pagesize': number | undefined;
|
|
13
|
+
'v-page': number;
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
16
|
+
export declare function executeCountQuery(repo: any, data?: {}): Promise<any>;
|
package/esm/lib/query.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeCountQuery = exports.executeFindQuery = exports.applyQuery = void 0;
|
|
4
|
+
function applyQuery(data) {
|
|
5
|
+
const { page = 0, pageSize = 0, skip: sk = 0, take: tk = 0, sort: s, ...where } = data;
|
|
6
|
+
const take = tk || pageSize || 50;
|
|
7
|
+
const skip = sk || page * pageSize || 0;
|
|
8
|
+
const order = !Array.isArray(s) ? [s] : s;
|
|
9
|
+
const evalOrder = (val = '') => (['desc', 'd', 'false', '1'].includes(val.toLowerCase()) ? 'desc' : 'asc');
|
|
10
|
+
const useOrder = (order = []) => {
|
|
11
|
+
const orderBy = {};
|
|
12
|
+
order
|
|
13
|
+
.filter((o) => !!o)
|
|
14
|
+
.forEach((o) => {
|
|
15
|
+
const p = o.split(':');
|
|
16
|
+
orderBy[p[0]] = evalOrder(p[1]);
|
|
17
|
+
});
|
|
18
|
+
return orderBy;
|
|
19
|
+
};
|
|
20
|
+
const useWhere = (where) => {
|
|
21
|
+
const result = {};
|
|
22
|
+
for (const objectPath in where) {
|
|
23
|
+
const parts = objectPath.split('.');
|
|
24
|
+
let target = result;
|
|
25
|
+
while (parts.length > 1) {
|
|
26
|
+
const part = parts.shift() || '';
|
|
27
|
+
target = target[part] = target[part] || {};
|
|
28
|
+
}
|
|
29
|
+
target[parts[0]] = where[objectPath];
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
const query = {};
|
|
34
|
+
if (skip)
|
|
35
|
+
query.skip = skip;
|
|
36
|
+
if (take)
|
|
37
|
+
query.take = take;
|
|
38
|
+
if (order)
|
|
39
|
+
query.order = useOrder(order);
|
|
40
|
+
if (where)
|
|
41
|
+
query.where = useWhere(where);
|
|
42
|
+
return query;
|
|
43
|
+
}
|
|
44
|
+
exports.applyQuery = applyQuery;
|
|
45
|
+
async function executeFindQuery(repo, relations = {}, data = {}) {
|
|
46
|
+
const extra = applyQuery(data);
|
|
47
|
+
const [records = [], totalCount] = await repo.findAndCount({
|
|
48
|
+
relations: relations,
|
|
49
|
+
...extra
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
records,
|
|
53
|
+
headers: {
|
|
54
|
+
'v-total': totalCount,
|
|
55
|
+
'v-count': records.length,
|
|
56
|
+
'v-pagesize': extra.take,
|
|
57
|
+
'v-page': 1
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
exports.executeFindQuery = executeFindQuery;
|
|
62
|
+
async function executeCountQuery(repo, data = {}) {
|
|
63
|
+
const { where = {} } = applyQuery(data);
|
|
64
|
+
return await repo.count({ where: where });
|
|
65
|
+
}
|
|
66
|
+
exports.executeCountQuery = executeCountQuery;
|
|
67
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../lib/query.ts"],"names":[],"mappings":";;;AAAA,SAAgB,UAAU,CAAC,IAAI;IAC7B,MAAM,EAAE,IAAI,GAAG,CAAC,EAAE,QAAQ,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,GAAG,IAAI,CAAA;IACtF,MAAM,IAAI,GAAW,EAAE,IAAI,QAAQ,IAAI,EAAE,CAAA;IACzC,MAAM,IAAI,GAAW,EAAE,IAAI,IAAI,GAAG,QAAQ,IAAI,CAAC,CAAA;IAC/C,MAAM,KAAK,GAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAEnD,MAAM,SAAS,GAAG,CAAC,MAAc,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;IAClH,MAAM,QAAQ,GAAG,CAAC,QAAkB,EAAE,EAAE,EAAE;QACxC,MAAM,OAAO,GAAG,EAAE,CAAA;QAClB,KAAK;aACF,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;aAClB,OAAO,CAAC,CAAC,CAAS,EAAE,EAAE;Y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,EAAE,EAAE,IAAI,GAAG,EAAE;IACzE,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;IAE9B,MAAM,CAAC,OAAO,GAAG,EAAE,EAAE,UAAU,CAAC,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC;QACzD,SAAS,EAAE,SAAS;QACpB,GAAG,KAAK;KACT,CAAC,CAAA;IAEF,OAAO;QACL,OAAO;QACP,OAAO,EAAE;YACP,SAAS,EAAE,UAAU;YACrB,SAAS,EAAE,OAAO,CAAC,MAAM;YACzB,YAAY,EAAE,KAAK,CAAC,IAAI;YACxB,QAAQ,EAAE,CAAC;SACZ;KACF,CAAA;AACH,CAAC;AAjBD,4CAiBC;AAEM,KAAK,UAAU,iBAAiB,CAAC,IAAS,EAAE,IAAI,GAAG,EAAE;IAC1D,MAAM,EAAE,KAAK,GAAG,EAAE,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;IACvC,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;AAC3C,CAAC;AAHD,8CAGC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volcanicminds/typeorm",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "TypeORM for the volcanic (minds) backend",
|
|
6
6
|
"keywords": [
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"typeorm": "^0.3.10"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@types/node": "^18.11.
|
|
41
|
+
"@types/node": "^18.11.10",
|
|
42
42
|
"jest": "^29.3.1",
|
|
43
43
|
"npm-upgrade": "^3.1.0",
|
|
44
44
|
"ts-node": "^10.9.1",
|