@cloudbase/database 1.4.3-alpha.0 → 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.js +4 -3
- 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 +1 -1
- package/dist/commonjs/transaction/collection.js +5 -2
- package/dist/commonjs/transaction/document.d.ts +1 -1
- package/dist/commonjs/transaction/document.js +5 -5
- package/dist/commonjs/transaction/index.js +196 -86
- package/dist/commonjs/transaction/query.d.ts +39 -1
- package/dist/commonjs/transaction/query.js +252 -1
- 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.js +1 -2
- 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 +1 -1
- package/dist/esm/transaction/collection.js +4 -2
- package/dist/esm/transaction/document.d.ts +1 -1
- package/dist/esm/transaction/document.js +2 -3
- package/dist/esm/transaction/index.js +191 -81
- package/dist/esm/transaction/query.d.ts +39 -1
- package/dist/esm/transaction/query.js +251 -1
- 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
|
@@ -1,8 +1,258 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
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;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import { EJSON } from 'bson';
|
|
49
|
+
import { ErrorCode } from '../constant';
|
|
50
|
+
import { Validate } from '../validate';
|
|
51
|
+
import { QuerySerializer } from '../serializer/query';
|
|
52
|
+
import { UpdateSerializer } from '../serializer/update';
|
|
53
|
+
import { Util } from '../util';
|
|
54
|
+
var GET_DOC = 'database.getInTransaction';
|
|
55
|
+
var UPDATE_DOC = 'database.updateDocInTransaction';
|
|
56
|
+
var DELETE_DOC = 'database.deleteDocInTransaction';
|
|
1
57
|
var Query = (function () {
|
|
2
|
-
function Query(transaction, coll) {
|
|
58
|
+
function Query(transaction, coll, fieldFilters, fieldOrders, queryOptions) {
|
|
3
59
|
this._coll = coll;
|
|
4
60
|
this._transaction = transaction;
|
|
61
|
+
this._fieldFilters = fieldFilters;
|
|
62
|
+
this._fieldOrders = fieldOrders || [];
|
|
63
|
+
this._queryOptions = queryOptions || {};
|
|
64
|
+
this._request = this._transaction.getRequestMethod();
|
|
65
|
+
this._transactionId = this._transaction.getTransactionId();
|
|
5
66
|
}
|
|
67
|
+
Query.prototype.where = function (query) {
|
|
68
|
+
if (Object.prototype.toString.call(query).slice(8, -1) !== 'Object') {
|
|
69
|
+
throw Error(ErrorCode.QueryParamTypeError);
|
|
70
|
+
}
|
|
71
|
+
var keys = Object.keys(query);
|
|
72
|
+
var checkFlag = keys.some(function (item) {
|
|
73
|
+
return query[item] !== undefined;
|
|
74
|
+
});
|
|
75
|
+
if (keys.length && !checkFlag) {
|
|
76
|
+
throw Error(ErrorCode.QueryParamValueError);
|
|
77
|
+
}
|
|
78
|
+
return new Query(this._transaction, this._coll, QuerySerializer.encode(query), this._fieldOrders, this._queryOptions);
|
|
79
|
+
};
|
|
80
|
+
Query.prototype.orderBy = function (fieldPath, directionStr) {
|
|
81
|
+
Validate.isFieldPath(fieldPath);
|
|
82
|
+
Validate.isFieldOrder(directionStr);
|
|
83
|
+
var newOrder = {
|
|
84
|
+
field: fieldPath,
|
|
85
|
+
direction: directionStr
|
|
86
|
+
};
|
|
87
|
+
var combinedOrders = this._fieldOrders.concat(newOrder);
|
|
88
|
+
return new Query(this._transaction, this._coll, this._fieldFilters, combinedOrders, this._queryOptions);
|
|
89
|
+
};
|
|
90
|
+
Query.prototype.limit = function (limit) {
|
|
91
|
+
Validate.isInteger('limit', limit);
|
|
92
|
+
var option = __assign({}, this._queryOptions);
|
|
93
|
+
option.limit = limit;
|
|
94
|
+
return new Query(this._transaction, this._coll, this._fieldFilters, this._fieldOrders, option);
|
|
95
|
+
};
|
|
96
|
+
Query.prototype.skip = function (offset) {
|
|
97
|
+
Validate.isInteger('offset', offset);
|
|
98
|
+
var option = __assign({}, this._queryOptions);
|
|
99
|
+
option.offset = offset;
|
|
100
|
+
return new Query(this._transaction, this._coll, this._fieldFilters, this._fieldOrders, option);
|
|
101
|
+
};
|
|
102
|
+
Query.prototype.field = function (projection) {
|
|
103
|
+
for (var k in projection) {
|
|
104
|
+
if (projection[k]) {
|
|
105
|
+
if (typeof projection[k] !== 'object') {
|
|
106
|
+
projection[k] = 1;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
projection[k] = 0;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
var option = __assign({}, this._queryOptions);
|
|
114
|
+
option.projection = projection;
|
|
115
|
+
return new Query(this._transaction, this._coll, this._fieldFilters, this._fieldOrders, option);
|
|
116
|
+
};
|
|
117
|
+
Query.prototype.get = function () {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
+
var newOrder, param, res, data, documents, result;
|
|
120
|
+
return __generator(this, function (_a) {
|
|
121
|
+
switch (_a.label) {
|
|
122
|
+
case 0:
|
|
123
|
+
newOrder = [];
|
|
124
|
+
if (this._fieldOrders) {
|
|
125
|
+
this._fieldOrders.forEach(function (order) {
|
|
126
|
+
newOrder.push(order);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
param = {
|
|
130
|
+
collectionName: this._coll,
|
|
131
|
+
transactionId: this._transactionId
|
|
132
|
+
};
|
|
133
|
+
if (this._fieldFilters) {
|
|
134
|
+
param.query = this._fieldFilters;
|
|
135
|
+
}
|
|
136
|
+
if (newOrder.length > 0) {
|
|
137
|
+
param.order = newOrder;
|
|
138
|
+
}
|
|
139
|
+
if (this._queryOptions.offset) {
|
|
140
|
+
param.offset = this._queryOptions.offset;
|
|
141
|
+
}
|
|
142
|
+
if (this._queryOptions.limit) {
|
|
143
|
+
param.limit = this._queryOptions.limit < 1000 ? this._queryOptions.limit : 1000;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
param.limit = 100;
|
|
147
|
+
}
|
|
148
|
+
if (this._queryOptions.projection) {
|
|
149
|
+
param.projection = this._queryOptions.projection;
|
|
150
|
+
}
|
|
151
|
+
return [4, this._request.send(GET_DOC, param)];
|
|
152
|
+
case 1:
|
|
153
|
+
res = _a.sent();
|
|
154
|
+
if (res.code)
|
|
155
|
+
throw res;
|
|
156
|
+
data = res.data !== 'null' ? EJSON.parse(res.data) : null;
|
|
157
|
+
documents = data ? (Array.isArray(data) ? Util.formatResDocumentData(data) : [Util.formatField(data)]) : [];
|
|
158
|
+
result = {
|
|
159
|
+
data: documents,
|
|
160
|
+
requestId: res.requestId
|
|
161
|
+
};
|
|
162
|
+
if (res.total !== undefined)
|
|
163
|
+
result.total = res.total;
|
|
164
|
+
if (res.limit !== undefined)
|
|
165
|
+
result.limit = res.limit;
|
|
166
|
+
if (res.offset !== undefined)
|
|
167
|
+
result.offset = res.offset;
|
|
168
|
+
return [2, result];
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
Query.prototype.count = function () {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
175
|
+
var param, res, data, total;
|
|
176
|
+
return __generator(this, function (_a) {
|
|
177
|
+
switch (_a.label) {
|
|
178
|
+
case 0:
|
|
179
|
+
param = {
|
|
180
|
+
collectionName: this._coll,
|
|
181
|
+
transactionId: this._transactionId
|
|
182
|
+
};
|
|
183
|
+
if (this._fieldFilters) {
|
|
184
|
+
param.query = this._fieldFilters;
|
|
185
|
+
}
|
|
186
|
+
return [4, this._request.send(GET_DOC, param)];
|
|
187
|
+
case 1:
|
|
188
|
+
res = _a.sent();
|
|
189
|
+
if (res.code)
|
|
190
|
+
throw res;
|
|
191
|
+
data = res.data !== 'null' ? EJSON.parse(res.data) : null;
|
|
192
|
+
total = Array.isArray(data) ? data.length : (data ? 1 : 0);
|
|
193
|
+
return [2, {
|
|
194
|
+
requestId: res.requestId,
|
|
195
|
+
total: res.total !== undefined ? res.total : total
|
|
196
|
+
}];
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
Query.prototype.update = function (data) {
|
|
202
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
203
|
+
var param, res;
|
|
204
|
+
return __generator(this, function (_a) {
|
|
205
|
+
switch (_a.label) {
|
|
206
|
+
case 0:
|
|
207
|
+
if (!data || typeof data !== 'object') {
|
|
208
|
+
throw new Error('参数必需是非空对象');
|
|
209
|
+
}
|
|
210
|
+
if (data.hasOwnProperty('_id')) {
|
|
211
|
+
throw new Error('不能更新_id的值');
|
|
212
|
+
}
|
|
213
|
+
param = {
|
|
214
|
+
collectionName: this._coll,
|
|
215
|
+
transactionId: this._transactionId,
|
|
216
|
+
query: this._fieldFilters,
|
|
217
|
+
data: EJSON.stringify(UpdateSerializer.encode(data), { relaxed: false })
|
|
218
|
+
};
|
|
219
|
+
return [4, this._request.send(UPDATE_DOC, param)];
|
|
220
|
+
case 1:
|
|
221
|
+
res = _a.sent();
|
|
222
|
+
if (res.code)
|
|
223
|
+
throw res;
|
|
224
|
+
return [2, __assign(__assign({}, res), { updated: EJSON.parse(res.updated) })];
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
Query.prototype.remove = function () {
|
|
230
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
231
|
+
var param, res;
|
|
232
|
+
return __generator(this, function (_a) {
|
|
233
|
+
switch (_a.label) {
|
|
234
|
+
case 0:
|
|
235
|
+
if (Object.keys(this._queryOptions).length > 0) {
|
|
236
|
+
console.warn('`offset`, `limit` and `projection` are not supported in remove() operation');
|
|
237
|
+
}
|
|
238
|
+
if (this._fieldOrders.length > 0) {
|
|
239
|
+
console.warn('`orderBy` is not supported in remove() operation');
|
|
240
|
+
}
|
|
241
|
+
param = {
|
|
242
|
+
collectionName: this._coll,
|
|
243
|
+
transactionId: this._transactionId,
|
|
244
|
+
query: this._fieldFilters
|
|
245
|
+
};
|
|
246
|
+
return [4, this._request.send(DELETE_DOC, param)];
|
|
247
|
+
case 1:
|
|
248
|
+
res = _a.sent();
|
|
249
|
+
if (res.code)
|
|
250
|
+
throw res;
|
|
251
|
+
return [2, __assign(__assign({}, res), { deleted: EJSON.parse(res.deleted) })];
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
};
|
|
6
256
|
return Query;
|
|
7
257
|
}());
|
|
8
258
|
export { 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];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/esm/util.js
CHANGED
|
@@ -1,98 +1,129 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return Util.formatField(document);
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
Util.formatField = document => {
|
|
11
|
-
const keys = Object.keys(document);
|
|
12
|
-
let protoField = {};
|
|
13
|
-
if (Array.isArray(document)) {
|
|
14
|
-
protoField = [];
|
|
1
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
+
if (!m) return o;
|
|
4
|
+
var i = m.call(o), r, ar = [], e;
|
|
5
|
+
try {
|
|
6
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
15
7
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
switch (type) {
|
|
21
|
-
case FieldType.GeoPoint:
|
|
22
|
-
realValue = new Point(item.coordinates[0], item.coordinates[1]);
|
|
23
|
-
break;
|
|
24
|
-
case FieldType.GeoLineString:
|
|
25
|
-
realValue = new LineString(item.coordinates.map(point => new Point(point[0], point[1])));
|
|
26
|
-
break;
|
|
27
|
-
case FieldType.GeoPolygon:
|
|
28
|
-
realValue = new Polygon(item.coordinates.map(line => new LineString(line.map(([lng, lat]) => new Point(lng, lat)))));
|
|
29
|
-
break;
|
|
30
|
-
case FieldType.GeoMultiPoint:
|
|
31
|
-
realValue = new MultiPoint(item.coordinates.map(point => new Point(point[0], point[1])));
|
|
32
|
-
break;
|
|
33
|
-
case FieldType.GeoMultiLineString:
|
|
34
|
-
realValue = new MultiLineString(item.coordinates.map(line => new LineString(line.map(([lng, lat]) => new Point(lng, lat)))));
|
|
35
|
-
break;
|
|
36
|
-
case FieldType.GeoMultiPolygon:
|
|
37
|
-
realValue = new MultiPolygon(item.coordinates.map(polygon => new Polygon(polygon.map(line => new LineString(line.map(([lng, lat]) => new Point(lng, lat)))))));
|
|
38
|
-
break;
|
|
39
|
-
case FieldType.Date:
|
|
40
|
-
realValue = item;
|
|
41
|
-
break;
|
|
42
|
-
case FieldType.Object:
|
|
43
|
-
case FieldType.Array:
|
|
44
|
-
realValue = Util.formatField(item);
|
|
45
|
-
break;
|
|
46
|
-
case FieldType.ServerDate:
|
|
47
|
-
realValue = new Date(item.$date);
|
|
48
|
-
break;
|
|
49
|
-
default:
|
|
50
|
-
realValue = item;
|
|
51
|
-
}
|
|
52
|
-
if (Array.isArray(protoField)) {
|
|
53
|
-
protoField.push(realValue);
|
|
8
|
+
catch (error) { e = { error: error }; }
|
|
9
|
+
finally {
|
|
10
|
+
try {
|
|
11
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
54
12
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
59
|
-
return protoField;
|
|
13
|
+
finally { if (e) throw e.error; }
|
|
14
|
+
}
|
|
15
|
+
return ar;
|
|
60
16
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
17
|
+
import { FieldType } from './constant';
|
|
18
|
+
import { Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon } from './geo/index';
|
|
19
|
+
var Util = (function () {
|
|
20
|
+
function Util() {
|
|
65
21
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
22
|
+
Util.formatResDocumentData = function (documents) {
|
|
23
|
+
return documents.map(function (document) {
|
|
24
|
+
return Util.formatField(document);
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
Util.formatField = function (document) {
|
|
28
|
+
var keys = Object.keys(document);
|
|
29
|
+
var protoField = {};
|
|
30
|
+
if (Array.isArray(document)) {
|
|
31
|
+
protoField = [];
|
|
69
32
|
}
|
|
70
|
-
|
|
71
|
-
|
|
33
|
+
keys.forEach(function (key) {
|
|
34
|
+
var item = document[key];
|
|
35
|
+
var type = Util.whichType(item);
|
|
36
|
+
var realValue;
|
|
37
|
+
switch (type) {
|
|
38
|
+
case FieldType.GeoPoint:
|
|
39
|
+
realValue = new Point(item.coordinates[0], item.coordinates[1]);
|
|
40
|
+
break;
|
|
41
|
+
case FieldType.GeoLineString:
|
|
42
|
+
realValue = new LineString(item.coordinates.map(function (point) { return new Point(point[0], point[1]); }));
|
|
43
|
+
break;
|
|
44
|
+
case FieldType.GeoPolygon:
|
|
45
|
+
realValue = new Polygon(item.coordinates.map(function (line) { return new LineString(line.map(function (_a) {
|
|
46
|
+
var _b = __read(_a, 2), lng = _b[0], lat = _b[1];
|
|
47
|
+
return new Point(lng, lat);
|
|
48
|
+
})); }));
|
|
49
|
+
break;
|
|
50
|
+
case FieldType.GeoMultiPoint:
|
|
51
|
+
realValue = new MultiPoint(item.coordinates.map(function (point) { return new Point(point[0], point[1]); }));
|
|
52
|
+
break;
|
|
53
|
+
case FieldType.GeoMultiLineString:
|
|
54
|
+
realValue = new MultiLineString(item.coordinates.map(function (line) { return new LineString(line.map(function (_a) {
|
|
55
|
+
var _b = __read(_a, 2), lng = _b[0], lat = _b[1];
|
|
56
|
+
return new Point(lng, lat);
|
|
57
|
+
})); }));
|
|
58
|
+
break;
|
|
59
|
+
case FieldType.GeoMultiPolygon:
|
|
60
|
+
realValue = new MultiPolygon(item.coordinates.map(function (polygon) {
|
|
61
|
+
return new Polygon(polygon.map(function (line) { return new LineString(line.map(function (_a) {
|
|
62
|
+
var _b = __read(_a, 2), lng = _b[0], lat = _b[1];
|
|
63
|
+
return new Point(lng, lat);
|
|
64
|
+
})); }));
|
|
65
|
+
}));
|
|
66
|
+
break;
|
|
67
|
+
case FieldType.Date:
|
|
68
|
+
realValue = item;
|
|
69
|
+
break;
|
|
70
|
+
case FieldType.Object:
|
|
71
|
+
case FieldType.Array:
|
|
72
|
+
realValue = Util.formatField(item);
|
|
73
|
+
break;
|
|
74
|
+
case FieldType.ServerDate:
|
|
75
|
+
realValue = new Date(item.$date);
|
|
76
|
+
break;
|
|
77
|
+
default:
|
|
78
|
+
realValue = item;
|
|
79
|
+
}
|
|
80
|
+
if (Array.isArray(protoField)) {
|
|
81
|
+
protoField.push(realValue);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
protoField[key] = realValue;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return protoField;
|
|
88
|
+
};
|
|
89
|
+
Util.whichType = function (obj) {
|
|
90
|
+
var type = Object.prototype.toString.call(obj).slice(8, -1);
|
|
91
|
+
if (type === FieldType.Date) {
|
|
92
|
+
return FieldType.Date;
|
|
72
93
|
}
|
|
73
|
-
|
|
74
|
-
|
|
94
|
+
if (type === FieldType.Object) {
|
|
95
|
+
if (obj.$date) {
|
|
96
|
+
type = FieldType.ServerDate;
|
|
97
|
+
}
|
|
98
|
+
else if (Point.validate(obj)) {
|
|
99
|
+
type = FieldType.GeoPoint;
|
|
100
|
+
}
|
|
101
|
+
else if (LineString.validate(obj)) {
|
|
102
|
+
type = FieldType.GeoLineString;
|
|
103
|
+
}
|
|
104
|
+
else if (Polygon.validate(obj)) {
|
|
105
|
+
type = FieldType.GeoPolygon;
|
|
106
|
+
}
|
|
107
|
+
else if (MultiPoint.validate(obj)) {
|
|
108
|
+
type = FieldType.GeoMultiPoint;
|
|
109
|
+
}
|
|
110
|
+
else if (MultiLineString.validate(obj)) {
|
|
111
|
+
type = FieldType.GeoMultiLineString;
|
|
112
|
+
}
|
|
113
|
+
else if (MultiPolygon.validate(obj)) {
|
|
114
|
+
type = FieldType.GeoMultiPolygon;
|
|
115
|
+
}
|
|
75
116
|
}
|
|
76
|
-
|
|
77
|
-
|
|
117
|
+
return type;
|
|
118
|
+
};
|
|
119
|
+
Util.generateDocId = function () {
|
|
120
|
+
var chars = 'ABCDEFabcdef0123456789';
|
|
121
|
+
var autoId = '';
|
|
122
|
+
for (var i = 0; i < 24; i++) {
|
|
123
|
+
autoId += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
78
124
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
else if (MultiPolygon.validate(obj)) {
|
|
86
|
-
type = FieldType.GeoMultiPolygon;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return type;
|
|
90
|
-
};
|
|
91
|
-
Util.generateDocId = () => {
|
|
92
|
-
let chars = 'ABCDEFabcdef0123456789';
|
|
93
|
-
let autoId = '';
|
|
94
|
-
for (let i = 0; i < 24; i++) {
|
|
95
|
-
autoId += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
96
|
-
}
|
|
97
|
-
return autoId;
|
|
98
|
-
};
|
|
125
|
+
return autoId;
|
|
126
|
+
};
|
|
127
|
+
return Util;
|
|
128
|
+
}());
|
|
129
|
+
export { 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;
|