@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
|
@@ -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;
|
package/dist/esm/utils/error.js
CHANGED
|
@@ -1,49 +1,84 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
1
16
|
import { isString } from './type';
|
|
2
17
|
import { ERR_CODE } from '../config/error.config';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
this.
|
|
7
|
-
|
|
18
|
+
var CloudSDKError = (function (_super) {
|
|
19
|
+
__extends(CloudSDKError, _super);
|
|
20
|
+
function CloudSDKError(options) {
|
|
21
|
+
var _this = _super.call(this, options.errMsg) || this;
|
|
22
|
+
_this.errCode = 'UNKNOWN_ERROR';
|
|
23
|
+
Object.defineProperties(_this, {
|
|
8
24
|
message: {
|
|
9
|
-
get() {
|
|
10
|
-
return (
|
|
11
|
-
''
|
|
25
|
+
get: function () {
|
|
26
|
+
return ("errCode: ".concat(this.errCode, " ").concat(ERR_CODE[this.errCode] ||
|
|
27
|
+
'', " | errMsg: ") + this.errMsg);
|
|
12
28
|
},
|
|
13
|
-
set(msg) {
|
|
29
|
+
set: function (msg) {
|
|
14
30
|
this.errMsg = msg;
|
|
15
31
|
}
|
|
16
32
|
}
|
|
17
33
|
});
|
|
18
|
-
|
|
19
|
-
|
|
34
|
+
_this.errCode = options.errCode || 'UNKNOWN_ERROR';
|
|
35
|
+
_this.errMsg = options.errMsg;
|
|
36
|
+
return _this;
|
|
20
37
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
38
|
+
Object.defineProperty(CloudSDKError.prototype, "message", {
|
|
39
|
+
get: function () {
|
|
40
|
+
return "errCode: ".concat(this.errCode, " | errMsg: ") + this.errMsg;
|
|
41
|
+
},
|
|
42
|
+
set: function (msg) {
|
|
43
|
+
this.errMsg = msg;
|
|
44
|
+
},
|
|
45
|
+
enumerable: false,
|
|
46
|
+
configurable: true
|
|
47
|
+
});
|
|
48
|
+
return CloudSDKError;
|
|
49
|
+
}(Error));
|
|
50
|
+
export { CloudSDKError };
|
|
28
51
|
export function isSDKError(error) {
|
|
29
52
|
return (error && error instanceof Error && isString(error.errMsg));
|
|
30
53
|
}
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
54
|
+
export var isGenericError = function (e) { return e.generic; };
|
|
55
|
+
var TimeoutError = (function (_super) {
|
|
56
|
+
__extends(TimeoutError, _super);
|
|
57
|
+
function TimeoutError(message) {
|
|
58
|
+
var _this = _super.call(this, message) || this;
|
|
59
|
+
_this.type = 'timeout';
|
|
60
|
+
_this.payload = null;
|
|
61
|
+
_this.generic = true;
|
|
62
|
+
return _this;
|
|
38
63
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
export
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
64
|
+
return TimeoutError;
|
|
65
|
+
}(Error));
|
|
66
|
+
export { TimeoutError };
|
|
67
|
+
export var isTimeoutError = function (e) {
|
|
68
|
+
return e.type === 'timeout';
|
|
69
|
+
};
|
|
70
|
+
var CancelledError = (function (_super) {
|
|
71
|
+
__extends(CancelledError, _super);
|
|
72
|
+
function CancelledError(message) {
|
|
73
|
+
var _this = _super.call(this, message) || this;
|
|
74
|
+
_this.type = 'cancelled';
|
|
75
|
+
_this.payload = null;
|
|
76
|
+
_this.generic = true;
|
|
77
|
+
return _this;
|
|
47
78
|
}
|
|
48
|
-
|
|
49
|
-
|
|
79
|
+
return CancelledError;
|
|
80
|
+
}(Error));
|
|
81
|
+
export { CancelledError };
|
|
82
|
+
export var isCancelledError = function (e) {
|
|
83
|
+
return e.type === 'cancelled';
|
|
84
|
+
};
|
package/dist/esm/utils/symbol.js
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
var _symbols = [];
|
|
17
|
+
var __internalMark__ = {};
|
|
18
|
+
var HiddenSymbol = (function () {
|
|
19
|
+
function HiddenSymbol(target) {
|
|
5
20
|
Object.defineProperties(this, {
|
|
6
21
|
target: {
|
|
7
22
|
enumerable: false,
|
|
@@ -11,26 +26,30 @@ class HiddenSymbol {
|
|
|
11
26
|
},
|
|
12
27
|
});
|
|
13
28
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
29
|
+
return HiddenSymbol;
|
|
30
|
+
}());
|
|
31
|
+
var InternalSymbol = (function (_super) {
|
|
32
|
+
__extends(InternalSymbol, _super);
|
|
33
|
+
function InternalSymbol(target, __mark__) {
|
|
17
34
|
if (__mark__ !== __internalMark__) {
|
|
18
35
|
throw new TypeError('InternalSymbol cannot be constructed with new operator');
|
|
19
36
|
}
|
|
20
|
-
|
|
37
|
+
return _super.call(this, target) || this;
|
|
21
38
|
}
|
|
22
|
-
|
|
23
|
-
for (
|
|
39
|
+
InternalSymbol.for = function (target) {
|
|
40
|
+
for (var i = 0, len = _symbols.length; i < len; i++) {
|
|
24
41
|
if (_symbols[i].target === target) {
|
|
25
42
|
return _symbols[i].instance;
|
|
26
43
|
}
|
|
27
44
|
}
|
|
28
|
-
|
|
45
|
+
var symbol = new InternalSymbol(target, __internalMark__);
|
|
29
46
|
_symbols.push({
|
|
30
|
-
target,
|
|
47
|
+
target: target,
|
|
31
48
|
instance: symbol,
|
|
32
49
|
});
|
|
33
50
|
return symbol;
|
|
34
|
-
}
|
|
35
|
-
|
|
51
|
+
};
|
|
52
|
+
return InternalSymbol;
|
|
53
|
+
}(HiddenSymbol));
|
|
54
|
+
export { InternalSymbol };
|
|
36
55
|
export default InternalSymbol;
|
package/dist/esm/utils/type.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare const isObject: <T extends object>(x: any) => x is T;
|
|
|
3
3
|
export declare const isString: (x: any) => x is string;
|
|
4
4
|
export declare const isNumber: (x: any) => x is number;
|
|
5
5
|
export declare const isPromise: <T extends Promise<any> = Promise<any>>(x: any) => x is T;
|
|
6
|
-
|
|
6
|
+
type AnyFn = (...args: any[]) => any;
|
|
7
7
|
export declare const isFunction: <T extends AnyFn = AnyFn>(x: any) => x is T;
|
|
8
8
|
export declare const isArray: <T extends any[] = any[]>(x: any) => x is T;
|
|
9
9
|
export declare const isDate: (x: any) => x is Date;
|
package/dist/esm/utils/type.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { InternalSymbol } from './symbol';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
2
|
+
export var getType = function (x) { return Object.prototype.toString.call(x).slice(8, -1).toLowerCase(); };
|
|
3
|
+
export var isObject = function (x) { return getType(x) === 'object'; };
|
|
4
|
+
export var isString = function (x) { return getType(x) === 'string'; };
|
|
5
|
+
export var isNumber = function (x) { return getType(x) === 'number'; };
|
|
6
|
+
export var isPromise = function (x) { return getType(x) === 'promise'; };
|
|
7
|
+
export var isFunction = function (x) { return typeof x === 'function'; };
|
|
8
|
+
export var isArray = function (x) { return Array.isArray(x); };
|
|
9
|
+
export var isDate = function (x) { return getType(x) === 'date'; };
|
|
10
|
+
export var isRegExp = function (x) { return getType(x) === 'regexp'; };
|
|
11
|
+
export var isInternalObject = function (x) { return x && (x._internalType instanceof InternalSymbol); };
|
|
12
|
+
export var isPlainObject = function (obj) {
|
|
13
13
|
if (typeof obj !== 'object' || obj === null)
|
|
14
14
|
return false;
|
|
15
|
-
|
|
15
|
+
var proto = obj;
|
|
16
16
|
while (Object.getPrototypeOf(proto) !== null) {
|
|
17
17
|
proto = Object.getPrototypeOf(proto);
|
|
18
18
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { Db } from '../';
|
|
1
2
|
import { QueryOption, UpdateOption } from '../query';
|
|
2
3
|
export declare const sleep: (ms?: number) => Promise<unknown>;
|
|
4
|
+
export declare function withCallback<T>(promise: Promise<T>, callback?: any): Promise<T> | undefined;
|
|
3
5
|
export declare const autoCount: (domain?: string) => number;
|
|
6
|
+
export declare function getWsInstance(db: Db): any;
|
|
4
7
|
export declare const getReqOpts: (apiOptions: QueryOption | UpdateOption) => any;
|
|
5
8
|
export declare const filterUndefined: (o: any) => any;
|
|
6
|
-
export declare const stringifyByEJSON: (params: any) =>
|
|
9
|
+
export declare const stringifyByEJSON: (params: any) => string;
|
|
7
10
|
export declare const parseByEJSON: (params: any) => any;
|
|
8
11
|
export declare class TcbError extends Error {
|
|
9
12
|
readonly code: string;
|