@cloudbase/database 1.4.3 → 1.5.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/dist/commonjs/ObjectId/index.d.ts +1 -1
- package/dist/commonjs/ObjectId/index.js +16 -9
- package/dist/commonjs/aggregate.js +126 -75
- package/dist/commonjs/collection.d.ts +3 -2
- package/dist/commonjs/collection.js +131 -58
- package/dist/commonjs/command.d.ts +5 -5
- package/dist/commonjs/command.js +181 -154
- package/dist/commonjs/commands/logic.js +30 -20
- package/dist/commonjs/commands/query.d.ts +1 -1
- package/dist/commonjs/commands/query.js +85 -65
- package/dist/commonjs/commands/update.js +9 -7
- package/dist/commonjs/config/error.config.js +1 -0
- package/dist/commonjs/const/code.js +1 -0
- package/dist/commonjs/constant.d.ts +7 -7
- package/dist/commonjs/constant.js +13 -11
- package/dist/commonjs/document.d.ts +10 -6
- package/dist/commonjs/document.js +305 -193
- package/dist/commonjs/geo/index.js +20 -9
- package/dist/commonjs/geo/lineString.d.ts +1 -1
- package/dist/commonjs/geo/lineString.js +62 -33
- package/dist/commonjs/geo/multiLineString.d.ts +1 -1
- package/dist/commonjs/geo/multiLineString.js +71 -32
- package/dist/commonjs/geo/multiPoint.d.ts +1 -1
- package/dist/commonjs/geo/multiPoint.js +58 -29
- package/dist/commonjs/geo/multiPolygon.d.ts +1 -1
- package/dist/commonjs/geo/multiPolygon.js +96 -36
- package/dist/commonjs/geo/point.d.ts +1 -1
- package/dist/commonjs/geo/point.js +30 -23
- package/dist/commonjs/geo/polygon.d.ts +1 -1
- package/dist/commonjs/geo/polygon.js +78 -39
- package/dist/commonjs/helper/symbol.js +17 -5
- package/dist/commonjs/index.d.ts +8 -2
- package/dist/commonjs/index.js +73 -20
- package/dist/commonjs/lib/util.d.ts +1 -0
- package/dist/commonjs/lib/util.js +26 -0
- package/dist/commonjs/operator-map.js +7 -6
- package/dist/commonjs/query.d.ts +8 -4
- package/dist/commonjs/query.js +308 -201
- package/dist/commonjs/regexp/index.d.ts +1 -1
- package/dist/commonjs/regexp/index.js +16 -9
- package/dist/commonjs/serializer/common.d.ts +2 -2
- package/dist/commonjs/serializer/common.js +59 -22
- package/dist/commonjs/serializer/datatype.d.ts +2 -2
- package/dist/commonjs/serializer/datatype.js +58 -21
- package/dist/commonjs/serializer/query.d.ts +1 -1
- package/dist/commonjs/serializer/query.js +137 -127
- package/dist/commonjs/serializer/update.d.ts +1 -1
- package/dist/commonjs/serializer/update.js +83 -78
- package/dist/commonjs/serverDate/index.d.ts +1 -1
- package/dist/commonjs/serverDate/index.js +16 -9
- package/dist/commonjs/transaction/collection.d.ts +7 -0
- package/dist/commonjs/transaction/collection.js +49 -0
- package/dist/commonjs/transaction/document.d.ts +27 -0
- package/dist/commonjs/transaction/document.js +205 -0
- package/dist/commonjs/transaction/index.js +196 -86
- package/dist/commonjs/transaction/query.d.ts +43 -0
- package/dist/commonjs/transaction/query.js +261 -0
- package/dist/commonjs/typings/index.d.ts +4 -4
- package/dist/commonjs/typings/realtime.d.ts +16 -16
- package/dist/commonjs/util.js +123 -92
- package/dist/commonjs/utils/error.d.ts +2 -1
- package/dist/commonjs/utils/error.js +74 -38
- package/dist/commonjs/utils/symbol.js +33 -14
- package/dist/commonjs/utils/type.d.ts +1 -1
- package/dist/commonjs/utils/type.js +25 -13
- package/dist/commonjs/utils/utils.d.ts +4 -1
- package/dist/commonjs/utils/utils.js +93 -22
- package/dist/commonjs/validate.js +79 -63
- package/dist/esm/ObjectId/index.d.ts +1 -1
- package/dist/esm/ObjectId/index.js +15 -8
- package/dist/esm/aggregate.js +118 -66
- package/dist/esm/collection.d.ts +3 -2
- package/dist/esm/collection.js +125 -52
- package/dist/esm/command.d.ts +5 -5
- package/dist/esm/command.js +175 -147
- package/dist/esm/commands/logic.js +30 -20
- package/dist/esm/commands/query.d.ts +1 -1
- package/dist/esm/commands/query.js +91 -71
- package/dist/esm/commands/update.js +8 -6
- package/dist/esm/config/error.config.js +1 -1
- package/dist/esm/const/code.js +1 -1
- package/dist/esm/constant.d.ts +7 -7
- package/dist/esm/constant.js +12 -11
- package/dist/esm/document.d.ts +10 -6
- package/dist/esm/document.js +297 -185
- package/dist/esm/geo/interface.js +1 -0
- package/dist/esm/geo/lineString.d.ts +1 -1
- package/dist/esm/geo/lineString.js +57 -28
- package/dist/esm/geo/multiLineString.d.ts +1 -1
- package/dist/esm/geo/multiLineString.js +66 -27
- package/dist/esm/geo/multiPoint.d.ts +1 -1
- package/dist/esm/geo/multiPoint.js +53 -24
- package/dist/esm/geo/multiPolygon.d.ts +1 -1
- package/dist/esm/geo/multiPolygon.js +91 -31
- package/dist/esm/geo/point.d.ts +1 -1
- package/dist/esm/geo/point.js +26 -19
- package/dist/esm/geo/polygon.d.ts +1 -1
- package/dist/esm/geo/polygon.js +73 -34
- package/dist/esm/helper/symbol.js +13 -13
- package/dist/esm/index.d.ts +8 -2
- package/dist/esm/index.js +62 -9
- package/dist/esm/lib/util.d.ts +1 -0
- package/dist/esm/lib/util.js +22 -0
- package/dist/esm/operator-map.js +4 -4
- package/dist/esm/query.d.ts +8 -4
- package/dist/esm/query.js +299 -192
- package/dist/esm/regexp/index.d.ts +1 -1
- package/dist/esm/regexp/index.js +15 -8
- package/dist/esm/serializer/common.d.ts +2 -2
- package/dist/esm/serializer/common.js +49 -13
- package/dist/esm/serializer/datatype.d.ts +2 -2
- package/dist/esm/serializer/datatype.js +44 -8
- package/dist/esm/serializer/query.d.ts +1 -1
- package/dist/esm/serializer/query.js +112 -102
- package/dist/esm/serializer/update.d.ts +1 -1
- package/dist/esm/serializer/update.js +69 -64
- package/dist/esm/serverDate/index.d.ts +1 -1
- package/dist/esm/serverDate/index.js +15 -8
- package/dist/esm/transaction/collection.d.ts +7 -0
- package/dist/esm/transaction/collection.js +46 -0
- package/dist/esm/transaction/document.d.ts +27 -0
- package/dist/esm/transaction/document.js +202 -0
- package/dist/esm/transaction/index.js +191 -81
- package/dist/esm/transaction/query.d.ts +43 -0
- package/dist/esm/transaction/query.js +258 -0
- package/dist/esm/typings/index.d.ts +4 -4
- package/dist/esm/typings/index.js +1 -0
- package/dist/esm/typings/realtime.d.ts +16 -16
- package/dist/esm/typings/realtime.js +1 -0
- package/dist/esm/util.js +121 -90
- package/dist/esm/utils/error.d.ts +2 -1
- package/dist/esm/utils/error.js +70 -35
- package/dist/esm/utils/symbol.js +33 -14
- package/dist/esm/utils/type.d.ts +1 -1
- package/dist/esm/utils/type.js +12 -12
- package/dist/esm/utils/utils.d.ts +4 -1
- package/dist/esm/utils/utils.js +78 -16
- package/dist/esm/validate.js +65 -49
- package/jest.config.js +14 -0
- package/package.json +14 -10
- package/src/aggregate.ts +1 -5
- package/src/collection.ts +15 -2
- package/src/document.ts +45 -34
- package/src/index.ts +51 -4
- package/src/query.ts +33 -29
- package/src/serializer/query.ts +18 -6
- package/src/transaction/index.ts +1 -1
- package/src/typings/index.ts +0 -4
- package/src/utils/utils.ts +46 -0
- package/src/validate.ts +3 -6
- package/tests/gateway-contract.test.ts +180 -0
- package/tests/index.test.ts +283 -0
- package/tests/transaction-query.test.ts +207 -0
- package/tsconfig.esm.json +4 -2
- package/tsconfig.json +16 -6
- package/tsconfig.test.json +15 -0
- package/dist/commonjs/realtime/error.d.ts +0 -7
- package/dist/commonjs/realtime/error.js +0 -11
- package/dist/commonjs/realtime/listener.d.ts +0 -14
- package/dist/commonjs/realtime/listener.js +0 -17
- package/dist/commonjs/realtime/message.d.ts +0 -3
- package/dist/commonjs/realtime/message.js +0 -10
- package/dist/commonjs/realtime/snapshot.d.ts +0 -16
- package/dist/commonjs/realtime/snapshot.js +0 -42
- package/dist/commonjs/realtime/virtual-websocket-client.d.ts +0 -63
- package/dist/commonjs/realtime/virtual-websocket-client.js +0 -736
- package/dist/commonjs/realtime/websocket-client.d.ts +0 -78
- package/dist/commonjs/realtime/websocket-client.js +0 -567
- package/dist/commonjs/realtime/ws-event.d.ts +0 -126
- package/dist/commonjs/realtime/ws-event.js +0 -139
- package/dist/commonjs/transaction.d.ts +0 -42
- package/dist/commonjs/transaction.js +0 -126
- package/dist/esm/realtime/error.d.ts +0 -7
- package/dist/esm/realtime/error.js +0 -8
- package/dist/esm/realtime/listener.d.ts +0 -14
- package/dist/esm/realtime/listener.js +0 -14
- package/dist/esm/realtime/message.d.ts +0 -3
- package/dist/esm/realtime/message.js +0 -6
- package/dist/esm/realtime/snapshot.d.ts +0 -16
- package/dist/esm/realtime/snapshot.js +0 -39
- package/dist/esm/realtime/virtual-websocket-client.d.ts +0 -63
- package/dist/esm/realtime/virtual-websocket-client.js +0 -733
- package/dist/esm/realtime/websocket-client.d.ts +0 -78
- package/dist/esm/realtime/websocket-client.js +0 -564
- package/dist/esm/realtime/ws-event.d.ts +0 -126
- package/dist/esm/realtime/ws-event.js +0 -137
- package/dist/esm/transaction.d.ts +0 -42
- package/dist/esm/transaction.js +0 -121
- package/src/realtime/error.ts +0 -19
- package/src/realtime/listener.ts +0 -35
- package/src/realtime/message.ts +0 -14
- package/src/realtime/snapshot.ts +0 -60
- package/src/realtime/virtual-websocket-client.ts +0 -1195
- package/src/realtime/websocket-client.ts +0 -995
- package/src/realtime/ws-event.ts +0 -163
- package/src/transaction.ts +0 -190
package/dist/commonjs/query.js
CHANGED
|
@@ -1,34 +1,71 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
28
43
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.Query = void 0;
|
|
51
|
+
var constant_1 = require("./constant");
|
|
52
|
+
var index_1 = require("./index");
|
|
53
|
+
var validate_1 = require("./validate");
|
|
54
|
+
var util_1 = require("./util");
|
|
55
|
+
var query_1 = require("./serializer/query");
|
|
56
|
+
var update_1 = require("./serializer/update");
|
|
57
|
+
var constant_2 = require("./constant");
|
|
58
|
+
var utils_1 = require("./utils/utils");
|
|
59
|
+
var code_1 = require("./const/code");
|
|
60
|
+
var bson_1 = require("bson");
|
|
61
|
+
var Query = (function () {
|
|
62
|
+
function Query(db, coll, fieldFilters, apiOptions, transactionId) {
|
|
63
|
+
var _this = this;
|
|
64
|
+
this.watch = function (options) {
|
|
65
|
+
var ws = (0, utils_1.getWsInstance)(_this._db);
|
|
66
|
+
var _a = _this._apiOptions, limit = _a.limit, order = _a.order;
|
|
67
|
+
return ws.watch(__assign(__assign({}, options), { envId: _this._db.config.env, collectionName: _this._coll, query: JSON.stringify(_this._fieldFilters), limit: limit, orderBy: order
|
|
68
|
+
? order.reduce(function (acc, cur) {
|
|
32
69
|
acc[cur.field] = cur.direction;
|
|
33
70
|
return acc;
|
|
34
71
|
}, {})
|
|
@@ -38,146 +75,189 @@ class Query {
|
|
|
38
75
|
this._coll = coll;
|
|
39
76
|
this._fieldFilters = fieldFilters;
|
|
40
77
|
this._apiOptions = apiOptions || {};
|
|
41
|
-
this._request =
|
|
78
|
+
this._request = index_1.Db.createRequest(this._db.config);
|
|
42
79
|
this._transactionId = transactionId;
|
|
43
80
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
81
|
+
Query.prototype.get = function (callback) {
|
|
82
|
+
return (0, utils_1.withCallback)(this._get(), callback);
|
|
83
|
+
};
|
|
84
|
+
Query.prototype._get = function () {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
86
|
+
var order, param, offset, limit, projection, res, list, documents, result;
|
|
87
|
+
return __generator(this, function (_a) {
|
|
88
|
+
switch (_a.label) {
|
|
89
|
+
case 0:
|
|
90
|
+
order = this._apiOptions.order;
|
|
91
|
+
param = {
|
|
92
|
+
collectionName: this._coll,
|
|
93
|
+
queryType: constant_1.QueryType.WHERE,
|
|
94
|
+
transactionId: this._transactionId
|
|
95
|
+
};
|
|
96
|
+
if (this._fieldFilters) {
|
|
97
|
+
param.query = this._fieldFilters;
|
|
98
|
+
}
|
|
99
|
+
if (order) {
|
|
100
|
+
param.order = (0, utils_1.stringifyByEJSON)(order);
|
|
101
|
+
}
|
|
102
|
+
offset = this._apiOptions.offset;
|
|
103
|
+
if (offset) {
|
|
104
|
+
param.offset = offset;
|
|
105
|
+
}
|
|
106
|
+
limit = this._apiOptions.limit;
|
|
107
|
+
if (limit) {
|
|
108
|
+
param.limit = limit < 1000 ? limit : 1000;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
param.limit = 100;
|
|
112
|
+
}
|
|
113
|
+
projection = this._apiOptions.projection;
|
|
114
|
+
if (projection) {
|
|
115
|
+
param.projection = (0, utils_1.stringifyByEJSON)(projection);
|
|
116
|
+
}
|
|
117
|
+
return [4, this._request.send('database.getDocument', param, (0, utils_1.getReqOpts)(this._apiOptions))];
|
|
118
|
+
case 1:
|
|
119
|
+
res = _a.sent();
|
|
120
|
+
if (res.code) {
|
|
121
|
+
return [2, res];
|
|
122
|
+
}
|
|
123
|
+
list = res.data.list.map(function (item) { return bson_1.EJSON.parse(item); });
|
|
124
|
+
documents = util_1.Util.formatResDocumentData(list);
|
|
125
|
+
result = {
|
|
126
|
+
data: documents,
|
|
127
|
+
requestId: res.requestId
|
|
128
|
+
};
|
|
129
|
+
if (res.total)
|
|
130
|
+
result.total = res.total;
|
|
131
|
+
if (res.limit)
|
|
132
|
+
result.limit = res.limit;
|
|
133
|
+
if (res.offset)
|
|
134
|
+
result.offset = res.offset;
|
|
135
|
+
return [2, result];
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
Query.prototype.count = function (callback) {
|
|
141
|
+
return (0, utils_1.withCallback)(this._count(), callback);
|
|
142
|
+
};
|
|
143
|
+
Query.prototype._count = function () {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
145
|
+
var param, res;
|
|
146
|
+
return __generator(this, function (_a) {
|
|
147
|
+
switch (_a.label) {
|
|
148
|
+
case 0:
|
|
149
|
+
param = {
|
|
150
|
+
collectionName: this._coll,
|
|
151
|
+
queryType: constant_1.QueryType.WHERE
|
|
152
|
+
};
|
|
153
|
+
if (this._fieldFilters) {
|
|
154
|
+
param.query = this._fieldFilters;
|
|
155
|
+
}
|
|
156
|
+
return [4, this._request.send('database.calculateDocument', param, (0, utils_1.getReqOpts)(this._apiOptions))];
|
|
157
|
+
case 1:
|
|
158
|
+
res = _a.sent();
|
|
159
|
+
if (res.code) {
|
|
160
|
+
return [2, res];
|
|
161
|
+
}
|
|
162
|
+
return [2, {
|
|
163
|
+
requestId: res.requestId,
|
|
164
|
+
total: res.data.total
|
|
165
|
+
}];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
Query.prototype.where = function (query) {
|
|
108
171
|
if (Object.prototype.toString.call(query).slice(8, -1) !== 'Object') {
|
|
109
172
|
throw Error(constant_2.ErrorCode.QueryParamTypeError);
|
|
110
173
|
}
|
|
111
|
-
|
|
112
|
-
|
|
174
|
+
var keys = Object.keys(query);
|
|
175
|
+
var checkFlag = keys.some(function (item) {
|
|
113
176
|
return query[item] !== undefined;
|
|
114
177
|
});
|
|
115
178
|
if (keys.length && !checkFlag) {
|
|
116
179
|
throw Error(constant_2.ErrorCode.QueryParamValueError);
|
|
117
180
|
}
|
|
118
181
|
return new Query(this._db, this._coll, query_1.QuerySerializer.encodeEJSON(query, this._apiOptions.raw || false), this._apiOptions, this._transactionId);
|
|
119
|
-
}
|
|
120
|
-
options(apiOptions) {
|
|
182
|
+
};
|
|
183
|
+
Query.prototype.options = function (apiOptions) {
|
|
121
184
|
validate_1.Validate.isValidOptions(apiOptions);
|
|
122
185
|
return new Query(this._db, this._coll, this._fieldFilters, apiOptions, this._transactionId);
|
|
123
|
-
}
|
|
124
|
-
orderBy(fieldPath, directionStr) {
|
|
186
|
+
};
|
|
187
|
+
Query.prototype.orderBy = function (fieldPath, directionStr) {
|
|
188
|
+
var _a;
|
|
125
189
|
validate_1.Validate.isFieldPath(fieldPath);
|
|
126
190
|
validate_1.Validate.isFieldOrder(directionStr);
|
|
127
|
-
|
|
128
|
-
[fieldPath]
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
191
|
+
var newOrder = (_a = {},
|
|
192
|
+
_a[fieldPath] = directionStr === 'desc' ? -1 : 1,
|
|
193
|
+
_a);
|
|
194
|
+
var order = this._apiOptions.order || {};
|
|
195
|
+
var newApiOption = Object.assign({}, this._apiOptions, {
|
|
132
196
|
order: Object.assign({}, order, newOrder)
|
|
133
197
|
});
|
|
134
198
|
return new Query(this._db, this._coll, this._fieldFilters, newApiOption, this._transactionId);
|
|
135
|
-
}
|
|
136
|
-
limit(limit) {
|
|
199
|
+
};
|
|
200
|
+
Query.prototype.limit = function (limit) {
|
|
137
201
|
validate_1.Validate.isInteger('limit', limit);
|
|
138
|
-
|
|
202
|
+
var newApiOption = __assign({}, this._apiOptions);
|
|
139
203
|
newApiOption.limit = limit;
|
|
140
204
|
return new Query(this._db, this._coll, this._fieldFilters, newApiOption, this._transactionId);
|
|
141
|
-
}
|
|
142
|
-
skip(offset) {
|
|
205
|
+
};
|
|
206
|
+
Query.prototype.skip = function (offset) {
|
|
143
207
|
validate_1.Validate.isInteger('offset', offset);
|
|
144
|
-
|
|
208
|
+
var newApiOption = __assign({}, this._apiOptions);
|
|
145
209
|
newApiOption.offset = offset;
|
|
146
210
|
return new Query(this._db, this._coll, this._fieldFilters, newApiOption, this._transactionId);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
211
|
+
};
|
|
212
|
+
Query.prototype.update = function (data, callback) {
|
|
213
|
+
return (0, utils_1.withCallback)(this._update(data), callback);
|
|
214
|
+
};
|
|
215
|
+
Query.prototype._update = function (data) {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
217
|
+
var multiple, multi, param, res;
|
|
218
|
+
return __generator(this, function (_a) {
|
|
219
|
+
switch (_a.label) {
|
|
220
|
+
case 0:
|
|
221
|
+
if (!data || typeof data !== 'object') {
|
|
222
|
+
return [2, (0, utils_1.processReturn)(this._db.config.throwOnCode, __assign(__assign({}, code_1.ERRORS.INVALID_PARAM), { message: '参数必需是非空对象' }))];
|
|
223
|
+
}
|
|
224
|
+
if (data.hasOwnProperty('_id')) {
|
|
225
|
+
return [2, (0, utils_1.processReturn)(this._db.config.throwOnCode, __assign(__assign({}, code_1.ERRORS.INVALID_PARAM), { message: '不能更新_id的值' }))];
|
|
226
|
+
}
|
|
227
|
+
multiple = this._apiOptions.multiple;
|
|
228
|
+
multi = multiple === undefined ? true : multiple;
|
|
229
|
+
param = {
|
|
230
|
+
collectionName: this._coll,
|
|
231
|
+
queryType: constant_1.QueryType.WHERE,
|
|
232
|
+
multi: multi,
|
|
233
|
+
merge: true,
|
|
234
|
+
upsert: false,
|
|
235
|
+
data: update_1.UpdateSerializer.encodeEJSON(data, this._apiOptions.raw || false)
|
|
236
|
+
};
|
|
237
|
+
if (this._transactionId) {
|
|
238
|
+
param.transactionId = this._transactionId;
|
|
239
|
+
}
|
|
240
|
+
if (this._fieldFilters) {
|
|
241
|
+
param.query = this._fieldFilters;
|
|
242
|
+
}
|
|
243
|
+
return [4, this._request.send('database.modifyDocument', param, (0, utils_1.getReqOpts)(this._apiOptions))];
|
|
244
|
+
case 1:
|
|
245
|
+
res = _a.sent();
|
|
246
|
+
if (res.code) {
|
|
247
|
+
return [2, res];
|
|
248
|
+
}
|
|
249
|
+
return [2, {
|
|
250
|
+
requestId: res.requestId,
|
|
251
|
+
updated: res.data.updated,
|
|
252
|
+
upsertId: res.data.upsert_id
|
|
253
|
+
}];
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
Query.prototype.field = function (projection) {
|
|
259
|
+
var transformProjection = {};
|
|
260
|
+
for (var k in projection) {
|
|
181
261
|
if (typeof projection[k] === 'boolean') {
|
|
182
262
|
transformProjection[k] = projection[k] === true ? 1 : 0;
|
|
183
263
|
}
|
|
@@ -188,62 +268,89 @@ class Query {
|
|
|
188
268
|
transformProjection[k] = projection[k];
|
|
189
269
|
}
|
|
190
270
|
}
|
|
191
|
-
|
|
271
|
+
var newApiOption = __assign({}, this._apiOptions);
|
|
192
272
|
newApiOption.projection = transformProjection;
|
|
193
273
|
return new Query(this._db, this._coll, this._fieldFilters, newApiOption, this._transactionId);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
order
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
274
|
+
};
|
|
275
|
+
Query.prototype.remove = function (callback) {
|
|
276
|
+
return (0, utils_1.withCallback)(this._remove(), callback);
|
|
277
|
+
};
|
|
278
|
+
Query.prototype._remove = function () {
|
|
279
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
280
|
+
var _a, offset, limit, projection, order, multiple, multi, param, res;
|
|
281
|
+
return __generator(this, function (_b) {
|
|
282
|
+
switch (_b.label) {
|
|
283
|
+
case 0:
|
|
284
|
+
_a = this._apiOptions, offset = _a.offset, limit = _a.limit, projection = _a.projection, order = _a.order;
|
|
285
|
+
if (offset !== undefined ||
|
|
286
|
+
limit !== undefined ||
|
|
287
|
+
projection !== undefined ||
|
|
288
|
+
order !== undefined) {
|
|
289
|
+
console.warn('`offset`, `limit`, `projection`, `orderBy` are not supported in remove() operation');
|
|
290
|
+
}
|
|
291
|
+
multiple = this._apiOptions.multiple;
|
|
292
|
+
multi = multiple === undefined ? true : multiple;
|
|
293
|
+
param = {
|
|
294
|
+
collectionName: this._coll,
|
|
295
|
+
query: this._fieldFilters,
|
|
296
|
+
queryType: constant_1.QueryType.WHERE,
|
|
297
|
+
multi: multi
|
|
298
|
+
};
|
|
299
|
+
if (this._transactionId) {
|
|
300
|
+
param.transactionId = this._transactionId;
|
|
301
|
+
}
|
|
302
|
+
return [4, this._request.send('database.removeDocument', param, (0, utils_1.getReqOpts)(this._apiOptions))];
|
|
303
|
+
case 1:
|
|
304
|
+
res = _b.sent();
|
|
305
|
+
if (res.code) {
|
|
306
|
+
return [2, res];
|
|
307
|
+
}
|
|
308
|
+
return [2, {
|
|
309
|
+
requestId: res.requestId,
|
|
310
|
+
deleted: res.data.deleted
|
|
311
|
+
}];
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
Query.prototype.updateAndReturn = function (data) {
|
|
317
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
318
|
+
var param, res;
|
|
319
|
+
return __generator(this, function (_a) {
|
|
320
|
+
switch (_a.label) {
|
|
321
|
+
case 0:
|
|
322
|
+
if (!data || typeof data !== 'object') {
|
|
323
|
+
return [2, (0, utils_1.processReturn)(this._db.config.throwOnCode, __assign(__assign({}, code_1.ERRORS.INVALID_PARAM), { message: '参数必需是非空对象' }))];
|
|
324
|
+
}
|
|
325
|
+
if (data.hasOwnProperty('_id')) {
|
|
326
|
+
return [2, (0, utils_1.processReturn)(this._db.config.throwOnCode, __assign(__assign({}, code_1.ERRORS.INVALID_PARAM), { message: '不能更新_id的值' }))];
|
|
327
|
+
}
|
|
328
|
+
param = {
|
|
329
|
+
collectionName: this._coll,
|
|
330
|
+
queryType: constant_1.QueryType.WHERE,
|
|
331
|
+
data: update_1.UpdateSerializer.encodeEJSON(data, false)
|
|
332
|
+
};
|
|
333
|
+
if (this._transactionId) {
|
|
334
|
+
param.transactionId = this._transactionId;
|
|
335
|
+
}
|
|
336
|
+
if (this._fieldFilters) {
|
|
337
|
+
param.query = this._fieldFilters;
|
|
338
|
+
}
|
|
339
|
+
return [4, this._request.send('database.modifyAndReturnDoc', param, (0, utils_1.getReqOpts)(this._apiOptions))];
|
|
340
|
+
case 1:
|
|
341
|
+
res = _a.sent();
|
|
342
|
+
if (res.code) {
|
|
343
|
+
return [2, res];
|
|
344
|
+
}
|
|
345
|
+
return [2, {
|
|
346
|
+
requestId: res.requestId,
|
|
347
|
+
updated: res.data.updated,
|
|
348
|
+
doc: res.data.doc && bson_1.EJSON.parse(res.data.doc)
|
|
349
|
+
}];
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
};
|
|
354
|
+
return Query;
|
|
355
|
+
}());
|
|
249
356
|
exports.Query = Query;
|
|
@@ -13,6 +13,6 @@ export declare class RegExp {
|
|
|
13
13
|
options: string;
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
|
-
|
|
16
|
+
get _internalType(): import("../utils/symbol").InternalSymbol;
|
|
17
17
|
}
|
|
18
18
|
export declare function RegExpConstructor(param: any): RegExp;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
exports.RegExpConstructor = exports.RegExp = void 0;
|
|
4
|
+
var symbol_1 = require("../helper/symbol");
|
|
5
|
+
var RegExp = (function () {
|
|
6
|
+
function RegExp(_a) {
|
|
7
|
+
var regexp = _a.regexp, options = _a.options;
|
|
6
8
|
if (!regexp) {
|
|
7
9
|
throw new TypeError('regexp must be a string');
|
|
8
10
|
}
|
|
@@ -11,18 +13,23 @@ class RegExp {
|
|
|
11
13
|
options: options || ''
|
|
12
14
|
};
|
|
13
15
|
}
|
|
14
|
-
parse() {
|
|
16
|
+
RegExp.prototype.parse = function () {
|
|
15
17
|
return {
|
|
16
18
|
$regularExpression: {
|
|
17
19
|
pattern: this.$regularExpression.pattern,
|
|
18
20
|
options: this.$regularExpression.options
|
|
19
21
|
}
|
|
20
22
|
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(RegExp.prototype, "_internalType", {
|
|
25
|
+
get: function () {
|
|
26
|
+
return symbol_1.SYMBOL_REGEXP;
|
|
27
|
+
},
|
|
28
|
+
enumerable: false,
|
|
29
|
+
configurable: true
|
|
30
|
+
});
|
|
31
|
+
return RegExp;
|
|
32
|
+
}());
|
|
26
33
|
exports.RegExp = RegExp;
|
|
27
34
|
function RegExpConstructor(param) {
|
|
28
35
|
return new RegExp(param);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LogicCommand } from '../commands/logic';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export type IQueryCondition = Record<string, any> | LogicCommand;
|
|
3
|
+
export type AnyObject = {
|
|
4
4
|
[x: string]: any;
|
|
5
5
|
};
|
|
6
6
|
export declare function flattenQueryObject(query: Record<string, any>): Record<string, any>;
|