@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
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
43
|
+
}
|
|
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 bson_1 = require("bson");
|
|
52
|
+
var constant_1 = require("../constant");
|
|
53
|
+
var validate_1 = require("../validate");
|
|
54
|
+
var query_1 = require("../serializer/query");
|
|
55
|
+
var update_1 = require("../serializer/update");
|
|
56
|
+
var util_1 = require("../util");
|
|
57
|
+
var GET_DOC = 'database.getInTransaction';
|
|
58
|
+
var UPDATE_DOC = 'database.updateDocInTransaction';
|
|
59
|
+
var DELETE_DOC = 'database.deleteDocInTransaction';
|
|
60
|
+
var Query = (function () {
|
|
61
|
+
function Query(transaction, coll, fieldFilters, fieldOrders, queryOptions) {
|
|
62
|
+
this._coll = coll;
|
|
63
|
+
this._transaction = transaction;
|
|
64
|
+
this._fieldFilters = fieldFilters;
|
|
65
|
+
this._fieldOrders = fieldOrders || [];
|
|
66
|
+
this._queryOptions = queryOptions || {};
|
|
67
|
+
this._request = this._transaction.getRequestMethod();
|
|
68
|
+
this._transactionId = this._transaction.getTransactionId();
|
|
69
|
+
}
|
|
70
|
+
Query.prototype.where = function (query) {
|
|
71
|
+
if (Object.prototype.toString.call(query).slice(8, -1) !== 'Object') {
|
|
72
|
+
throw Error(constant_1.ErrorCode.QueryParamTypeError);
|
|
73
|
+
}
|
|
74
|
+
var keys = Object.keys(query);
|
|
75
|
+
var checkFlag = keys.some(function (item) {
|
|
76
|
+
return query[item] !== undefined;
|
|
77
|
+
});
|
|
78
|
+
if (keys.length && !checkFlag) {
|
|
79
|
+
throw Error(constant_1.ErrorCode.QueryParamValueError);
|
|
80
|
+
}
|
|
81
|
+
return new Query(this._transaction, this._coll, query_1.QuerySerializer.encode(query), this._fieldOrders, this._queryOptions);
|
|
82
|
+
};
|
|
83
|
+
Query.prototype.orderBy = function (fieldPath, directionStr) {
|
|
84
|
+
validate_1.Validate.isFieldPath(fieldPath);
|
|
85
|
+
validate_1.Validate.isFieldOrder(directionStr);
|
|
86
|
+
var newOrder = {
|
|
87
|
+
field: fieldPath,
|
|
88
|
+
direction: directionStr
|
|
89
|
+
};
|
|
90
|
+
var combinedOrders = this._fieldOrders.concat(newOrder);
|
|
91
|
+
return new Query(this._transaction, this._coll, this._fieldFilters, combinedOrders, this._queryOptions);
|
|
92
|
+
};
|
|
93
|
+
Query.prototype.limit = function (limit) {
|
|
94
|
+
validate_1.Validate.isInteger('limit', limit);
|
|
95
|
+
var option = __assign({}, this._queryOptions);
|
|
96
|
+
option.limit = limit;
|
|
97
|
+
return new Query(this._transaction, this._coll, this._fieldFilters, this._fieldOrders, option);
|
|
98
|
+
};
|
|
99
|
+
Query.prototype.skip = function (offset) {
|
|
100
|
+
validate_1.Validate.isInteger('offset', offset);
|
|
101
|
+
var option = __assign({}, this._queryOptions);
|
|
102
|
+
option.offset = offset;
|
|
103
|
+
return new Query(this._transaction, this._coll, this._fieldFilters, this._fieldOrders, option);
|
|
104
|
+
};
|
|
105
|
+
Query.prototype.field = function (projection) {
|
|
106
|
+
for (var k in projection) {
|
|
107
|
+
if (projection[k]) {
|
|
108
|
+
if (typeof projection[k] !== 'object') {
|
|
109
|
+
projection[k] = 1;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
projection[k] = 0;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
var option = __assign({}, this._queryOptions);
|
|
117
|
+
option.projection = projection;
|
|
118
|
+
return new Query(this._transaction, this._coll, this._fieldFilters, this._fieldOrders, option);
|
|
119
|
+
};
|
|
120
|
+
Query.prototype.get = function () {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
122
|
+
var newOrder, param, res, data, documents, result;
|
|
123
|
+
return __generator(this, function (_a) {
|
|
124
|
+
switch (_a.label) {
|
|
125
|
+
case 0:
|
|
126
|
+
newOrder = [];
|
|
127
|
+
if (this._fieldOrders) {
|
|
128
|
+
this._fieldOrders.forEach(function (order) {
|
|
129
|
+
newOrder.push(order);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
param = {
|
|
133
|
+
collectionName: this._coll,
|
|
134
|
+
transactionId: this._transactionId
|
|
135
|
+
};
|
|
136
|
+
if (this._fieldFilters) {
|
|
137
|
+
param.query = this._fieldFilters;
|
|
138
|
+
}
|
|
139
|
+
if (newOrder.length > 0) {
|
|
140
|
+
param.order = newOrder;
|
|
141
|
+
}
|
|
142
|
+
if (this._queryOptions.offset) {
|
|
143
|
+
param.offset = this._queryOptions.offset;
|
|
144
|
+
}
|
|
145
|
+
if (this._queryOptions.limit) {
|
|
146
|
+
param.limit = this._queryOptions.limit < 1000 ? this._queryOptions.limit : 1000;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
param.limit = 100;
|
|
150
|
+
}
|
|
151
|
+
if (this._queryOptions.projection) {
|
|
152
|
+
param.projection = this._queryOptions.projection;
|
|
153
|
+
}
|
|
154
|
+
return [4, this._request.send(GET_DOC, param)];
|
|
155
|
+
case 1:
|
|
156
|
+
res = _a.sent();
|
|
157
|
+
if (res.code)
|
|
158
|
+
throw res;
|
|
159
|
+
data = res.data !== 'null' ? bson_1.EJSON.parse(res.data) : null;
|
|
160
|
+
documents = data ? (Array.isArray(data) ? util_1.Util.formatResDocumentData(data) : [util_1.Util.formatField(data)]) : [];
|
|
161
|
+
result = {
|
|
162
|
+
data: documents,
|
|
163
|
+
requestId: res.requestId
|
|
164
|
+
};
|
|
165
|
+
if (res.total !== undefined)
|
|
166
|
+
result.total = res.total;
|
|
167
|
+
if (res.limit !== undefined)
|
|
168
|
+
result.limit = res.limit;
|
|
169
|
+
if (res.offset !== undefined)
|
|
170
|
+
result.offset = res.offset;
|
|
171
|
+
return [2, result];
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
Query.prototype.count = function () {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
178
|
+
var param, res, data, total;
|
|
179
|
+
return __generator(this, function (_a) {
|
|
180
|
+
switch (_a.label) {
|
|
181
|
+
case 0:
|
|
182
|
+
param = {
|
|
183
|
+
collectionName: this._coll,
|
|
184
|
+
transactionId: this._transactionId
|
|
185
|
+
};
|
|
186
|
+
if (this._fieldFilters) {
|
|
187
|
+
param.query = this._fieldFilters;
|
|
188
|
+
}
|
|
189
|
+
return [4, this._request.send(GET_DOC, param)];
|
|
190
|
+
case 1:
|
|
191
|
+
res = _a.sent();
|
|
192
|
+
if (res.code)
|
|
193
|
+
throw res;
|
|
194
|
+
data = res.data !== 'null' ? bson_1.EJSON.parse(res.data) : null;
|
|
195
|
+
total = Array.isArray(data) ? data.length : (data ? 1 : 0);
|
|
196
|
+
return [2, {
|
|
197
|
+
requestId: res.requestId,
|
|
198
|
+
total: res.total !== undefined ? res.total : total
|
|
199
|
+
}];
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
Query.prototype.update = function (data) {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
206
|
+
var param, res;
|
|
207
|
+
return __generator(this, function (_a) {
|
|
208
|
+
switch (_a.label) {
|
|
209
|
+
case 0:
|
|
210
|
+
if (!data || typeof data !== 'object') {
|
|
211
|
+
throw new Error('参数必需是非空对象');
|
|
212
|
+
}
|
|
213
|
+
if (data.hasOwnProperty('_id')) {
|
|
214
|
+
throw new Error('不能更新_id的值');
|
|
215
|
+
}
|
|
216
|
+
param = {
|
|
217
|
+
collectionName: this._coll,
|
|
218
|
+
transactionId: this._transactionId,
|
|
219
|
+
query: this._fieldFilters,
|
|
220
|
+
data: bson_1.EJSON.stringify(update_1.UpdateSerializer.encode(data), { relaxed: false })
|
|
221
|
+
};
|
|
222
|
+
return [4, this._request.send(UPDATE_DOC, param)];
|
|
223
|
+
case 1:
|
|
224
|
+
res = _a.sent();
|
|
225
|
+
if (res.code)
|
|
226
|
+
throw res;
|
|
227
|
+
return [2, __assign(__assign({}, res), { updated: bson_1.EJSON.parse(res.updated) })];
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
Query.prototype.remove = function () {
|
|
233
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
234
|
+
var param, res;
|
|
235
|
+
return __generator(this, function (_a) {
|
|
236
|
+
switch (_a.label) {
|
|
237
|
+
case 0:
|
|
238
|
+
if (Object.keys(this._queryOptions).length > 0) {
|
|
239
|
+
console.warn('`offset`, `limit` and `projection` are not supported in remove() operation');
|
|
240
|
+
}
|
|
241
|
+
if (this._fieldOrders.length > 0) {
|
|
242
|
+
console.warn('`orderBy` is not supported in remove() operation');
|
|
243
|
+
}
|
|
244
|
+
param = {
|
|
245
|
+
collectionName: this._coll,
|
|
246
|
+
transactionId: this._transactionId,
|
|
247
|
+
query: this._fieldFilters
|
|
248
|
+
};
|
|
249
|
+
return [4, this._request.send(DELETE_DOC, param)];
|
|
250
|
+
case 1:
|
|
251
|
+
res = _a.sent();
|
|
252
|
+
if (res.code)
|
|
253
|
+
throw res;
|
|
254
|
+
return [2, __assign(__assign({}, res), { deleted: bson_1.EJSON.parse(res.deleted) })];
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
return Query;
|
|
260
|
+
}());
|
|
261
|
+
exports.Query = Query;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Point } from '../geo/index';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export type DataType = 'init' | 'update' | 'add' | 'remove' | 'replace' | 'limit';
|
|
3
|
+
export type QueueType = 'init' | 'enqueue' | 'dequeue' | 'update';
|
|
4
4
|
export interface IDatabaseServiceContext extends IServiceContext {
|
|
5
5
|
appConfig: IAppConfig;
|
|
6
6
|
ws?: any;
|
|
@@ -30,7 +30,7 @@ export interface ISingleDBEvent {
|
|
|
30
30
|
updatedFields?: any;
|
|
31
31
|
removedFields?: any;
|
|
32
32
|
}
|
|
33
|
-
export
|
|
33
|
+
export type SnapshotType = 'init';
|
|
34
34
|
export interface DBRealtimeListener {
|
|
35
35
|
close: () => void;
|
|
36
36
|
}
|
|
@@ -42,4 +42,4 @@ export interface IServiceContext {
|
|
|
42
42
|
export interface IReqOpts {
|
|
43
43
|
timeout: number;
|
|
44
44
|
}
|
|
45
|
-
export
|
|
45
|
+
export type CenterSphere = [Point, number] | [[number, number], number];
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { DataType, QueueType } from './index';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export type IRequestMsgType = 'LOGIN' | 'INIT_WATCH' | 'REBUILD_WATCH' | 'CHECK_LAST' | 'CLOSE_WATCH' | 'PING';
|
|
3
|
+
export type IResponseMsgType = 'LOGIN_RES' | 'INIT_EVENT' | 'NEXT_EVENT' | 'CHECK_EVENT' | 'PONG' | 'ERROR';
|
|
4
4
|
export interface IRequestMessageBase<W extends boolean = true> {
|
|
5
5
|
watchId: W extends true ? string : undefined;
|
|
6
6
|
requestId: string;
|
|
7
7
|
msgType: IRequestMsgType;
|
|
8
8
|
msgData: IRequestMessageMsgData;
|
|
9
9
|
}
|
|
10
|
-
export
|
|
11
|
-
export
|
|
10
|
+
export type IRequestMessageMsgData = IRequestMessageInitWatchData | IRequestMessageLoginData | IRequestMessageRebuildWatchData | IRequestMessageCheckLastData | IRequestMessageCloseWatchData | IRequestMessagePingData;
|
|
11
|
+
export type IRequestMessage = IRequestMessageInitWatchMsg | IRequestMessageLoginMsg | IRequestMessageRebuildWatchMsg | IRequestMessageCheckLastMsg | IRequestMessageCloseWatchMsg | IRequestMessagePingMsg;
|
|
12
12
|
export interface IRequestMessageLoginData {
|
|
13
13
|
envId: string;
|
|
14
14
|
accessToken: string;
|
|
@@ -55,12 +55,12 @@ export interface IRequestMessageCheckLastMsg extends IRequestMessageBase {
|
|
|
55
55
|
msgType: 'CHECK_LAST';
|
|
56
56
|
msgData: IRequestMessageCheckLastData;
|
|
57
57
|
}
|
|
58
|
-
export
|
|
58
|
+
export type IRequestMessageCloseWatchData = null;
|
|
59
59
|
export interface IRequestMessageCloseWatchMsg extends IRequestMessageBase {
|
|
60
60
|
msgType: 'CLOSE_WATCH';
|
|
61
61
|
msgData: IRequestMessageCloseWatchData;
|
|
62
62
|
}
|
|
63
|
-
export
|
|
63
|
+
export type IRequestMessagePingData = null;
|
|
64
64
|
export interface IRequestMessagePingMsg extends IRequestMessageBase<false> {
|
|
65
65
|
msgType: 'PING';
|
|
66
66
|
msgData: IRequestMessagePingData;
|
|
@@ -71,9 +71,9 @@ export interface IResponseMessageBase<W extends boolean = true> {
|
|
|
71
71
|
msgType: IResponseMsgType;
|
|
72
72
|
msgData: IResponseMessageMsgData;
|
|
73
73
|
}
|
|
74
|
-
export
|
|
75
|
-
export
|
|
76
|
-
export
|
|
74
|
+
export type IResponseMessageMsgData = IResponseMessageLoginResData | IResponseMessageInitEventData | IResponseMessageNextEventData | IResponseMessageCheckEventData | IResponseMessagePongData | IResponseMessageErrorData;
|
|
75
|
+
export type IResponseMessage = IResponseMessageLoginResMsg | IResponseMessageInitEventMsg | IResponseMessageNextEventMsg | IResponseMessageCheckEventMsg | IResponseMessagePongMsg | IResponseMessageErrorMsg;
|
|
76
|
+
export type IResponseMessageLoginResData = {
|
|
77
77
|
envId: string;
|
|
78
78
|
} & Partial<IResponseMessageErrorData>;
|
|
79
79
|
export interface IResponseMessageLoginResMsg extends IResponseMessageBase<false> {
|
|
@@ -106,12 +106,12 @@ export interface IResponseMessageCheckEventMsg extends IResponseMessageBase {
|
|
|
106
106
|
msgType: 'CHECK_EVENT';
|
|
107
107
|
msgData: IResponseMessageCheckEventData;
|
|
108
108
|
}
|
|
109
|
-
export
|
|
109
|
+
export type IResponseMessagePongData = null;
|
|
110
110
|
export interface IResponseMessagePongMsg extends IResponseMessageBase {
|
|
111
111
|
msgType: 'PONG';
|
|
112
112
|
msgData: IResponseMessagePongData;
|
|
113
113
|
}
|
|
114
|
-
export
|
|
114
|
+
export type IResponseMessageErrorData = {
|
|
115
115
|
message: string;
|
|
116
116
|
} & ({
|
|
117
117
|
code: 'SYS_ERR';
|
|
@@ -134,7 +134,7 @@ export interface IResponseMessageErrorMsg extends IResponseMessageBase {
|
|
|
134
134
|
msgType: 'ERROR';
|
|
135
135
|
msgData: IResponseMessageErrorData;
|
|
136
136
|
}
|
|
137
|
-
export
|
|
137
|
+
export type IDBEvent = IDBInitEvent | IDBNextEvent;
|
|
138
138
|
export interface IDBEventBase {
|
|
139
139
|
ID: number;
|
|
140
140
|
DataType: DataType;
|
|
@@ -148,10 +148,10 @@ export interface IDBInitEvent extends IDBEventBase {
|
|
|
148
148
|
UpdatedFields?: any;
|
|
149
149
|
removedFields?: any;
|
|
150
150
|
}
|
|
151
|
-
export
|
|
152
|
-
export
|
|
153
|
-
export
|
|
154
|
-
export
|
|
151
|
+
export type IDBNextEvent = IDBNextEventDataUpdate | IDBNextEventDataReplace | IDBNextEventDataAdd | IDBNextEventDataRemove | IDBNextEventDataLimit;
|
|
152
|
+
export type IDBNextEventDataUpdate = IDBNextEventDataUpdateQueueUpdate | IDBNextEventDataUpdateQueueEnqueue | IDBNextEventDataUpdateQueueDequeue;
|
|
153
|
+
export type IDBNextEventDataReplace = IDBNextEventDataReplaceQueueUpdate | IDBNextEventDataReplaceQueueEnqueue | IDBNextEventDataReplaceQueueDequeue;
|
|
154
|
+
export type IDBNextEventDataLimit = IDBNextEventDataLimitQueueEnqueue | IDBNextEventDataLimitQueueDequeue;
|
|
155
155
|
export interface IDBNextEventDataUpdateQueueUpdate extends IDBEventBase {
|
|
156
156
|
DataType: 'update';
|
|
157
157
|
QueueType: 'update';
|
package/dist/commonjs/util.js
CHANGED
|
@@ -1,101 +1,132 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Util.formatResDocumentData = (documents) => {
|
|
9
|
-
return documents.map(document => {
|
|
10
|
-
return Util.formatField(document);
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
Util.formatField = document => {
|
|
14
|
-
const keys = Object.keys(document);
|
|
15
|
-
let protoField = {};
|
|
16
|
-
if (Array.isArray(document)) {
|
|
17
|
-
protoField = [];
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
18
8
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
switch (type) {
|
|
24
|
-
case constant_1.FieldType.GeoPoint:
|
|
25
|
-
realValue = new index_1.Point(item.coordinates[0], item.coordinates[1]);
|
|
26
|
-
break;
|
|
27
|
-
case constant_1.FieldType.GeoLineString:
|
|
28
|
-
realValue = new index_1.LineString(item.coordinates.map(point => new index_1.Point(point[0], point[1])));
|
|
29
|
-
break;
|
|
30
|
-
case constant_1.FieldType.GeoPolygon:
|
|
31
|
-
realValue = new index_1.Polygon(item.coordinates.map(line => new index_1.LineString(line.map(([lng, lat]) => new index_1.Point(lng, lat)))));
|
|
32
|
-
break;
|
|
33
|
-
case constant_1.FieldType.GeoMultiPoint:
|
|
34
|
-
realValue = new index_1.MultiPoint(item.coordinates.map(point => new index_1.Point(point[0], point[1])));
|
|
35
|
-
break;
|
|
36
|
-
case constant_1.FieldType.GeoMultiLineString:
|
|
37
|
-
realValue = new index_1.MultiLineString(item.coordinates.map(line => new index_1.LineString(line.map(([lng, lat]) => new index_1.Point(lng, lat)))));
|
|
38
|
-
break;
|
|
39
|
-
case constant_1.FieldType.GeoMultiPolygon:
|
|
40
|
-
realValue = new index_1.MultiPolygon(item.coordinates.map(polygon => new index_1.Polygon(polygon.map(line => new index_1.LineString(line.map(([lng, lat]) => new index_1.Point(lng, lat)))))));
|
|
41
|
-
break;
|
|
42
|
-
case constant_1.FieldType.Date:
|
|
43
|
-
realValue = item;
|
|
44
|
-
break;
|
|
45
|
-
case constant_1.FieldType.Object:
|
|
46
|
-
case constant_1.FieldType.Array:
|
|
47
|
-
realValue = Util.formatField(item);
|
|
48
|
-
break;
|
|
49
|
-
case constant_1.FieldType.ServerDate:
|
|
50
|
-
realValue = new Date(item.$date);
|
|
51
|
-
break;
|
|
52
|
-
default:
|
|
53
|
-
realValue = item;
|
|
54
|
-
}
|
|
55
|
-
if (Array.isArray(protoField)) {
|
|
56
|
-
protoField.push(realValue);
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
57
13
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
return protoField;
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
63
17
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.Util = void 0;
|
|
20
|
+
var constant_1 = require("./constant");
|
|
21
|
+
var index_1 = require("./geo/index");
|
|
22
|
+
var Util = (function () {
|
|
23
|
+
function Util() {
|
|
68
24
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
25
|
+
Util.formatResDocumentData = function (documents) {
|
|
26
|
+
return documents.map(function (document) {
|
|
27
|
+
return Util.formatField(document);
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
Util.formatField = function (document) {
|
|
31
|
+
var keys = Object.keys(document);
|
|
32
|
+
var protoField = {};
|
|
33
|
+
if (Array.isArray(document)) {
|
|
34
|
+
protoField = [];
|
|
75
35
|
}
|
|
76
|
-
|
|
77
|
-
|
|
36
|
+
keys.forEach(function (key) {
|
|
37
|
+
var item = document[key];
|
|
38
|
+
var type = Util.whichType(item);
|
|
39
|
+
var realValue;
|
|
40
|
+
switch (type) {
|
|
41
|
+
case constant_1.FieldType.GeoPoint:
|
|
42
|
+
realValue = new index_1.Point(item.coordinates[0], item.coordinates[1]);
|
|
43
|
+
break;
|
|
44
|
+
case constant_1.FieldType.GeoLineString:
|
|
45
|
+
realValue = new index_1.LineString(item.coordinates.map(function (point) { return new index_1.Point(point[0], point[1]); }));
|
|
46
|
+
break;
|
|
47
|
+
case constant_1.FieldType.GeoPolygon:
|
|
48
|
+
realValue = new index_1.Polygon(item.coordinates.map(function (line) { return new index_1.LineString(line.map(function (_a) {
|
|
49
|
+
var _b = __read(_a, 2), lng = _b[0], lat = _b[1];
|
|
50
|
+
return new index_1.Point(lng, lat);
|
|
51
|
+
})); }));
|
|
52
|
+
break;
|
|
53
|
+
case constant_1.FieldType.GeoMultiPoint:
|
|
54
|
+
realValue = new index_1.MultiPoint(item.coordinates.map(function (point) { return new index_1.Point(point[0], point[1]); }));
|
|
55
|
+
break;
|
|
56
|
+
case constant_1.FieldType.GeoMultiLineString:
|
|
57
|
+
realValue = new index_1.MultiLineString(item.coordinates.map(function (line) { return new index_1.LineString(line.map(function (_a) {
|
|
58
|
+
var _b = __read(_a, 2), lng = _b[0], lat = _b[1];
|
|
59
|
+
return new index_1.Point(lng, lat);
|
|
60
|
+
})); }));
|
|
61
|
+
break;
|
|
62
|
+
case constant_1.FieldType.GeoMultiPolygon:
|
|
63
|
+
realValue = new index_1.MultiPolygon(item.coordinates.map(function (polygon) {
|
|
64
|
+
return new index_1.Polygon(polygon.map(function (line) { return new index_1.LineString(line.map(function (_a) {
|
|
65
|
+
var _b = __read(_a, 2), lng = _b[0], lat = _b[1];
|
|
66
|
+
return new index_1.Point(lng, lat);
|
|
67
|
+
})); }));
|
|
68
|
+
}));
|
|
69
|
+
break;
|
|
70
|
+
case constant_1.FieldType.Date:
|
|
71
|
+
realValue = item;
|
|
72
|
+
break;
|
|
73
|
+
case constant_1.FieldType.Object:
|
|
74
|
+
case constant_1.FieldType.Array:
|
|
75
|
+
realValue = Util.formatField(item);
|
|
76
|
+
break;
|
|
77
|
+
case constant_1.FieldType.ServerDate:
|
|
78
|
+
realValue = new Date(item.$date);
|
|
79
|
+
break;
|
|
80
|
+
default:
|
|
81
|
+
realValue = item;
|
|
82
|
+
}
|
|
83
|
+
if (Array.isArray(protoField)) {
|
|
84
|
+
protoField.push(realValue);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
protoField[key] = realValue;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
return protoField;
|
|
91
|
+
};
|
|
92
|
+
Util.whichType = function (obj) {
|
|
93
|
+
var type = Object.prototype.toString.call(obj).slice(8, -1);
|
|
94
|
+
if (type === constant_1.FieldType.Date) {
|
|
95
|
+
return constant_1.FieldType.Date;
|
|
78
96
|
}
|
|
79
|
-
|
|
80
|
-
|
|
97
|
+
if (type === constant_1.FieldType.Object) {
|
|
98
|
+
if (obj.$date) {
|
|
99
|
+
type = constant_1.FieldType.ServerDate;
|
|
100
|
+
}
|
|
101
|
+
else if (index_1.Point.validate(obj)) {
|
|
102
|
+
type = constant_1.FieldType.GeoPoint;
|
|
103
|
+
}
|
|
104
|
+
else if (index_1.LineString.validate(obj)) {
|
|
105
|
+
type = constant_1.FieldType.GeoLineString;
|
|
106
|
+
}
|
|
107
|
+
else if (index_1.Polygon.validate(obj)) {
|
|
108
|
+
type = constant_1.FieldType.GeoPolygon;
|
|
109
|
+
}
|
|
110
|
+
else if (index_1.MultiPoint.validate(obj)) {
|
|
111
|
+
type = constant_1.FieldType.GeoMultiPoint;
|
|
112
|
+
}
|
|
113
|
+
else if (index_1.MultiLineString.validate(obj)) {
|
|
114
|
+
type = constant_1.FieldType.GeoMultiLineString;
|
|
115
|
+
}
|
|
116
|
+
else if (index_1.MultiPolygon.validate(obj)) {
|
|
117
|
+
type = constant_1.FieldType.GeoMultiPolygon;
|
|
118
|
+
}
|
|
81
119
|
}
|
|
82
|
-
|
|
83
|
-
|
|
120
|
+
return type;
|
|
121
|
+
};
|
|
122
|
+
Util.generateDocId = function () {
|
|
123
|
+
var chars = 'ABCDEFabcdef0123456789';
|
|
124
|
+
var autoId = '';
|
|
125
|
+
for (var i = 0; i < 24; i++) {
|
|
126
|
+
autoId += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
84
127
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return type;
|
|
93
|
-
};
|
|
94
|
-
Util.generateDocId = () => {
|
|
95
|
-
let chars = 'ABCDEFabcdef0123456789';
|
|
96
|
-
let autoId = '';
|
|
97
|
-
for (let i = 0; i < 24; i++) {
|
|
98
|
-
autoId += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
99
|
-
}
|
|
100
|
-
return autoId;
|
|
101
|
-
};
|
|
128
|
+
return autoId;
|
|
129
|
+
};
|
|
130
|
+
return Util;
|
|
131
|
+
}());
|
|
132
|
+
exports.Util = Util;
|
|
@@ -7,7 +7,8 @@ export declare class CloudSDKError extends Error {
|
|
|
7
7
|
errMsg: string;
|
|
8
8
|
requestID?: string;
|
|
9
9
|
constructor(options: IErrorConstructorOptions);
|
|
10
|
-
message: string;
|
|
10
|
+
get message(): string;
|
|
11
|
+
set message(msg: string);
|
|
11
12
|
}
|
|
12
13
|
interface IErrorConstructorOptions {
|
|
13
14
|
errCode?: string;
|