@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,55 +1,91 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
2
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
18
|
+
exports.isCancelledError = exports.CancelledError = exports.isTimeoutError = exports.TimeoutError = exports.isGenericError = exports.isSDKError = exports.CloudSDKError = void 0;
|
|
19
|
+
var type_1 = require("./type");
|
|
20
|
+
var error_config_1 = require("../config/error.config");
|
|
21
|
+
var CloudSDKError = (function (_super) {
|
|
22
|
+
__extends(CloudSDKError, _super);
|
|
23
|
+
function CloudSDKError(options) {
|
|
24
|
+
var _this = _super.call(this, options.errMsg) || this;
|
|
25
|
+
_this.errCode = 'UNKNOWN_ERROR';
|
|
26
|
+
Object.defineProperties(_this, {
|
|
10
27
|
message: {
|
|
11
|
-
get() {
|
|
12
|
-
return (
|
|
13
|
-
''
|
|
28
|
+
get: function () {
|
|
29
|
+
return ("errCode: ".concat(this.errCode, " ").concat(error_config_1.ERR_CODE[this.errCode] ||
|
|
30
|
+
'', " | errMsg: ") + this.errMsg);
|
|
14
31
|
},
|
|
15
|
-
set(msg) {
|
|
32
|
+
set: function (msg) {
|
|
16
33
|
this.errMsg = msg;
|
|
17
34
|
}
|
|
18
35
|
}
|
|
19
36
|
});
|
|
20
|
-
|
|
21
|
-
|
|
37
|
+
_this.errCode = options.errCode || 'UNKNOWN_ERROR';
|
|
38
|
+
_this.errMsg = options.errMsg;
|
|
39
|
+
return _this;
|
|
22
40
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
41
|
+
Object.defineProperty(CloudSDKError.prototype, "message", {
|
|
42
|
+
get: function () {
|
|
43
|
+
return "errCode: ".concat(this.errCode, " | errMsg: ") + this.errMsg;
|
|
44
|
+
},
|
|
45
|
+
set: function (msg) {
|
|
46
|
+
this.errMsg = msg;
|
|
47
|
+
},
|
|
48
|
+
enumerable: false,
|
|
49
|
+
configurable: true
|
|
50
|
+
});
|
|
51
|
+
return CloudSDKError;
|
|
52
|
+
}(Error));
|
|
30
53
|
exports.CloudSDKError = CloudSDKError;
|
|
31
54
|
function isSDKError(error) {
|
|
32
|
-
return (error && error instanceof Error && type_1.isString(error.errMsg));
|
|
55
|
+
return (error && error instanceof Error && (0, type_1.isString)(error.errMsg));
|
|
33
56
|
}
|
|
34
57
|
exports.isSDKError = isSDKError;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
58
|
+
var isGenericError = function (e) { return e.generic; };
|
|
59
|
+
exports.isGenericError = isGenericError;
|
|
60
|
+
var TimeoutError = (function (_super) {
|
|
61
|
+
__extends(TimeoutError, _super);
|
|
62
|
+
function TimeoutError(message) {
|
|
63
|
+
var _this = _super.call(this, message) || this;
|
|
64
|
+
_this.type = 'timeout';
|
|
65
|
+
_this.payload = null;
|
|
66
|
+
_this.generic = true;
|
|
67
|
+
return _this;
|
|
42
68
|
}
|
|
43
|
-
|
|
69
|
+
return TimeoutError;
|
|
70
|
+
}(Error));
|
|
44
71
|
exports.TimeoutError = TimeoutError;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
72
|
+
var isTimeoutError = function (e) {
|
|
73
|
+
return e.type === 'timeout';
|
|
74
|
+
};
|
|
75
|
+
exports.isTimeoutError = isTimeoutError;
|
|
76
|
+
var CancelledError = (function (_super) {
|
|
77
|
+
__extends(CancelledError, _super);
|
|
78
|
+
function CancelledError(message) {
|
|
79
|
+
var _this = _super.call(this, message) || this;
|
|
80
|
+
_this.type = 'cancelled';
|
|
81
|
+
_this.payload = null;
|
|
82
|
+
_this.generic = true;
|
|
83
|
+
return _this;
|
|
52
84
|
}
|
|
53
|
-
|
|
85
|
+
return CancelledError;
|
|
86
|
+
}(Error));
|
|
54
87
|
exports.CancelledError = CancelledError;
|
|
55
|
-
|
|
88
|
+
var isCancelledError = function (e) {
|
|
89
|
+
return e.type === 'cancelled';
|
|
90
|
+
};
|
|
91
|
+
exports.isCancelledError = isCancelledError;
|
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
2
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
18
|
+
exports.InternalSymbol = void 0;
|
|
19
|
+
var _symbols = [];
|
|
20
|
+
var __internalMark__ = {};
|
|
21
|
+
var HiddenSymbol = (function () {
|
|
22
|
+
function HiddenSymbol(target) {
|
|
7
23
|
Object.defineProperties(this, {
|
|
8
24
|
target: {
|
|
9
25
|
enumerable: false,
|
|
@@ -13,27 +29,30 @@ class HiddenSymbol {
|
|
|
13
29
|
},
|
|
14
30
|
});
|
|
15
31
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
32
|
+
return HiddenSymbol;
|
|
33
|
+
}());
|
|
34
|
+
var InternalSymbol = (function (_super) {
|
|
35
|
+
__extends(InternalSymbol, _super);
|
|
36
|
+
function InternalSymbol(target, __mark__) {
|
|
19
37
|
if (__mark__ !== __internalMark__) {
|
|
20
38
|
throw new TypeError('InternalSymbol cannot be constructed with new operator');
|
|
21
39
|
}
|
|
22
|
-
|
|
40
|
+
return _super.call(this, target) || this;
|
|
23
41
|
}
|
|
24
|
-
|
|
25
|
-
for (
|
|
42
|
+
InternalSymbol.for = function (target) {
|
|
43
|
+
for (var i = 0, len = _symbols.length; i < len; i++) {
|
|
26
44
|
if (_symbols[i].target === target) {
|
|
27
45
|
return _symbols[i].instance;
|
|
28
46
|
}
|
|
29
47
|
}
|
|
30
|
-
|
|
48
|
+
var symbol = new InternalSymbol(target, __internalMark__);
|
|
31
49
|
_symbols.push({
|
|
32
|
-
target,
|
|
50
|
+
target: target,
|
|
33
51
|
instance: symbol,
|
|
34
52
|
});
|
|
35
53
|
return symbol;
|
|
36
|
-
}
|
|
37
|
-
|
|
54
|
+
};
|
|
55
|
+
return InternalSymbol;
|
|
56
|
+
}(HiddenSymbol));
|
|
38
57
|
exports.InternalSymbol = InternalSymbol;
|
|
39
58
|
exports.default = InternalSymbol;
|
|
@@ -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;
|
|
@@ -1,22 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
exports.
|
|
9
|
-
|
|
10
|
-
exports.
|
|
11
|
-
|
|
12
|
-
exports.
|
|
13
|
-
|
|
14
|
-
exports.
|
|
3
|
+
exports.isPlainObject = exports.isInternalObject = exports.isRegExp = exports.isDate = exports.isArray = exports.isFunction = exports.isPromise = exports.isNumber = exports.isString = exports.isObject = exports.getType = void 0;
|
|
4
|
+
var symbol_1 = require("./symbol");
|
|
5
|
+
var getType = function (x) { return Object.prototype.toString.call(x).slice(8, -1).toLowerCase(); };
|
|
6
|
+
exports.getType = getType;
|
|
7
|
+
var isObject = function (x) { return (0, exports.getType)(x) === 'object'; };
|
|
8
|
+
exports.isObject = isObject;
|
|
9
|
+
var isString = function (x) { return (0, exports.getType)(x) === 'string'; };
|
|
10
|
+
exports.isString = isString;
|
|
11
|
+
var isNumber = function (x) { return (0, exports.getType)(x) === 'number'; };
|
|
12
|
+
exports.isNumber = isNumber;
|
|
13
|
+
var isPromise = function (x) { return (0, exports.getType)(x) === 'promise'; };
|
|
14
|
+
exports.isPromise = isPromise;
|
|
15
|
+
var isFunction = function (x) { return typeof x === 'function'; };
|
|
16
|
+
exports.isFunction = isFunction;
|
|
17
|
+
var isArray = function (x) { return Array.isArray(x); };
|
|
18
|
+
exports.isArray = isArray;
|
|
19
|
+
var isDate = function (x) { return (0, exports.getType)(x) === 'date'; };
|
|
20
|
+
exports.isDate = isDate;
|
|
21
|
+
var isRegExp = function (x) { return (0, exports.getType)(x) === 'regexp'; };
|
|
22
|
+
exports.isRegExp = isRegExp;
|
|
23
|
+
var isInternalObject = function (x) { return x && (x._internalType instanceof symbol_1.InternalSymbol); };
|
|
24
|
+
exports.isInternalObject = isInternalObject;
|
|
25
|
+
var isPlainObject = function (obj) {
|
|
15
26
|
if (typeof obj !== 'object' || obj === null)
|
|
16
27
|
return false;
|
|
17
|
-
|
|
28
|
+
var proto = obj;
|
|
18
29
|
while (Object.getPrototypeOf(proto) !== null) {
|
|
19
30
|
proto = Object.getPrototypeOf(proto);
|
|
20
31
|
}
|
|
21
32
|
return Object.getPrototypeOf(obj) === proto;
|
|
22
33
|
};
|
|
34
|
+
exports.isPlainObject = isPlainObject;
|
|
@@ -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;
|
|
@@ -1,16 +1,79 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
2
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
29
|
+
exports.processReturn = exports.E = exports.TcbError = exports.parseByEJSON = exports.stringifyByEJSON = exports.filterUndefined = exports.getReqOpts = exports.getWsInstance = exports.autoCount = exports.withCallback = exports.sleep = void 0;
|
|
30
|
+
var __1 = require("../");
|
|
31
|
+
var bson_1 = require("bson");
|
|
32
|
+
var type_1 = require("./type");
|
|
33
|
+
var sleep = function (ms) {
|
|
34
|
+
if (ms === void 0) { ms = 0; }
|
|
35
|
+
return new Promise(function (r) { return setTimeout(r, ms); });
|
|
36
|
+
};
|
|
37
|
+
exports.sleep = sleep;
|
|
38
|
+
function withCallback(promise, callback) {
|
|
39
|
+
if (typeof callback === 'function') {
|
|
40
|
+
promise.then(function (res) { return callback(0, res); }, function (err) { return callback(err); });
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
return promise;
|
|
44
|
+
}
|
|
45
|
+
exports.withCallback = withCallback;
|
|
46
|
+
var counters = {};
|
|
47
|
+
var autoCount = function (domain) {
|
|
48
|
+
if (domain === void 0) { domain = 'any'; }
|
|
8
49
|
if (!counters[domain]) {
|
|
9
50
|
counters[domain] = 0;
|
|
10
51
|
}
|
|
11
52
|
return counters[domain]++;
|
|
12
53
|
};
|
|
13
|
-
exports.
|
|
54
|
+
exports.autoCount = autoCount;
|
|
55
|
+
var wsList = {};
|
|
56
|
+
function getWsInstance(db) {
|
|
57
|
+
if (!__1.Db.wsClientClass) {
|
|
58
|
+
throw new Error('to use realtime you must import realtime module first');
|
|
59
|
+
}
|
|
60
|
+
var env = db.config.env;
|
|
61
|
+
if (!wsList[env]) {
|
|
62
|
+
wsList[env] = new __1.Db.wsClientClass({
|
|
63
|
+
context: {
|
|
64
|
+
appConfig: {
|
|
65
|
+
docSizeLimit: 1000,
|
|
66
|
+
realtimePingInterval: 10000,
|
|
67
|
+
realtimePongWaitTimeout: 5000,
|
|
68
|
+
request: __1.Db.createRequest(db.config)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return wsList[env];
|
|
74
|
+
}
|
|
75
|
+
exports.getWsInstance = getWsInstance;
|
|
76
|
+
var getReqOpts = function (apiOptions) {
|
|
14
77
|
if (apiOptions.timeout !== undefined) {
|
|
15
78
|
return {
|
|
16
79
|
timeout: apiOptions.timeout
|
|
@@ -18,42 +81,50 @@ exports.getReqOpts = (apiOptions) => {
|
|
|
18
81
|
}
|
|
19
82
|
return {};
|
|
20
83
|
};
|
|
21
|
-
exports.
|
|
22
|
-
|
|
84
|
+
exports.getReqOpts = getReqOpts;
|
|
85
|
+
var filterUndefined = function (o) {
|
|
86
|
+
if (!(0, type_1.isObject)(o)) {
|
|
23
87
|
return o;
|
|
24
88
|
}
|
|
25
|
-
for (
|
|
89
|
+
for (var key in o) {
|
|
26
90
|
if (o[key] === undefined) {
|
|
27
91
|
delete o[key];
|
|
28
92
|
}
|
|
29
|
-
else if (type_1.isObject(o[key])) {
|
|
30
|
-
o[key] = exports.filterUndefined(o[key]);
|
|
93
|
+
else if ((0, type_1.isObject)(o[key])) {
|
|
94
|
+
o[key] = (0, exports.filterUndefined)(o[key]);
|
|
31
95
|
}
|
|
32
96
|
}
|
|
33
97
|
return o;
|
|
34
98
|
};
|
|
35
|
-
exports.
|
|
36
|
-
|
|
99
|
+
exports.filterUndefined = filterUndefined;
|
|
100
|
+
var stringifyByEJSON = function (params) {
|
|
101
|
+
params = (0, exports.filterUndefined)(params);
|
|
37
102
|
return bson_1.EJSON.stringify(params, { relaxed: false });
|
|
38
103
|
};
|
|
39
|
-
exports.
|
|
104
|
+
exports.stringifyByEJSON = stringifyByEJSON;
|
|
105
|
+
var parseByEJSON = function (params) {
|
|
40
106
|
return bson_1.EJSON.parse(params);
|
|
41
107
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
108
|
+
exports.parseByEJSON = parseByEJSON;
|
|
109
|
+
var TcbError = (function (_super) {
|
|
110
|
+
__extends(TcbError, _super);
|
|
111
|
+
function TcbError(error) {
|
|
112
|
+
var _this = _super.call(this, error.message) || this;
|
|
113
|
+
_this.code = error.code;
|
|
114
|
+
_this.message = error.message;
|
|
115
|
+
return _this;
|
|
47
116
|
}
|
|
48
|
-
|
|
117
|
+
return TcbError;
|
|
118
|
+
}(Error));
|
|
49
119
|
exports.TcbError = TcbError;
|
|
50
|
-
|
|
120
|
+
var E = function (errObj) {
|
|
51
121
|
return new TcbError(errObj);
|
|
52
122
|
};
|
|
123
|
+
exports.E = E;
|
|
53
124
|
function processReturn(throwOnCode, res) {
|
|
54
125
|
if (throwOnCode === false) {
|
|
55
126
|
return res;
|
|
56
127
|
}
|
|
57
|
-
throw exports.E(
|
|
128
|
+
throw (0, exports.E)(__assign({}, res));
|
|
58
129
|
}
|
|
59
130
|
exports.processReturn = processReturn;
|
|
@@ -1,18 +1,32 @@
|
|
|
1
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
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
exports.Validate = void 0;
|
|
15
|
+
var constant_1 = require("./constant");
|
|
16
|
+
var util_1 = require("./util");
|
|
17
|
+
var code_1 = require("./const/code");
|
|
18
|
+
var utils_1 = require("./utils/utils");
|
|
19
|
+
var type_1 = require("./utils/type");
|
|
20
|
+
var symbol_1 = require("./helper/symbol");
|
|
21
|
+
var validOptionsKeys = ['limit', 'offset', 'projection', 'order', 'multiple', 'timeout', 'raw'];
|
|
22
|
+
var Validate = (function () {
|
|
23
|
+
function Validate() {
|
|
24
|
+
}
|
|
25
|
+
Validate.isGeopoint = function (point, degree) {
|
|
12
26
|
if (util_1.Util.whichType(degree) !== constant_1.FieldType.Number) {
|
|
13
27
|
throw new Error('Geo Point must be number type');
|
|
14
28
|
}
|
|
15
|
-
|
|
29
|
+
var degreeAbs = Math.abs(degree);
|
|
16
30
|
if (point === 'latitude' && degreeAbs > 90) {
|
|
17
31
|
throw new Error('latitude should be a number ranges from -90 to 90');
|
|
18
32
|
}
|
|
@@ -20,92 +34,93 @@ class Validate {
|
|
|
20
34
|
throw new Error('longitude should be a number ranges from -180 to 180');
|
|
21
35
|
}
|
|
22
36
|
return true;
|
|
23
|
-
}
|
|
24
|
-
|
|
37
|
+
};
|
|
38
|
+
Validate.isInteger = function (param, num) {
|
|
25
39
|
if (!Number.isInteger(num)) {
|
|
26
40
|
throw new Error(param + constant_1.ErrorCode.IntergerError);
|
|
27
41
|
}
|
|
28
42
|
return true;
|
|
29
|
-
}
|
|
30
|
-
|
|
43
|
+
};
|
|
44
|
+
Validate.mustBeBoolean = function (param, bool) {
|
|
31
45
|
if (typeof bool !== 'boolean') {
|
|
32
46
|
throw new Error(param + constant_1.ErrorCode.BooleanError);
|
|
33
47
|
}
|
|
34
48
|
return true;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (type_1.getType(value) !== 'object') {
|
|
38
|
-
throw utils_1.E(
|
|
39
|
-
}
|
|
40
|
-
for (
|
|
41
|
-
|
|
42
|
-
if (type_1.getType(subValue) === 'number') {
|
|
49
|
+
};
|
|
50
|
+
Validate.isProjection = function (param, value) {
|
|
51
|
+
if ((0, type_1.getType)(value) !== 'object') {
|
|
52
|
+
throw (0, utils_1.E)(__assign(__assign({}, code_1.ERRORS.INVALID_PARAM), { message: "".concat(param, " projection must be an object") }));
|
|
53
|
+
}
|
|
54
|
+
for (var key in value) {
|
|
55
|
+
var subValue = value[key];
|
|
56
|
+
if ((0, type_1.getType)(subValue) === 'number') {
|
|
43
57
|
if (subValue !== 0 && subValue !== 1) {
|
|
44
|
-
throw utils_1.E(
|
|
58
|
+
throw (0, utils_1.E)(__assign(__assign({}, code_1.ERRORS.INVALID_PARAM), { message: "if the value in projection is of number, it must be 0 or 1" }));
|
|
45
59
|
}
|
|
46
60
|
}
|
|
47
|
-
else if (type_1.getType(subValue) === 'object') {
|
|
61
|
+
else if ((0, type_1.getType)(subValue) === 'object') {
|
|
48
62
|
}
|
|
49
63
|
else {
|
|
50
|
-
throw utils_1.E(
|
|
64
|
+
throw (0, utils_1.E)(__assign(__assign({}, code_1.ERRORS.INVALID_PARAM), { message: 'invalid projection' }));
|
|
51
65
|
}
|
|
52
66
|
}
|
|
53
67
|
return true;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (type_1.getType(value) !== 'object') {
|
|
57
|
-
throw utils_1.E(
|
|
68
|
+
};
|
|
69
|
+
Validate.isOrder = function (param, value) {
|
|
70
|
+
if ((0, type_1.getType)(value) !== 'object') {
|
|
71
|
+
throw (0, utils_1.E)(__assign(__assign({}, code_1.ERRORS.INVALID_PARAM), { message: "".concat(param, " order must be an object") }));
|
|
58
72
|
}
|
|
59
|
-
for (
|
|
60
|
-
|
|
73
|
+
for (var key in value) {
|
|
74
|
+
var subValue = value[key];
|
|
61
75
|
if (subValue !== 1 && subValue !== -1) {
|
|
62
|
-
throw utils_1.E(
|
|
76
|
+
throw (0, utils_1.E)(__assign(__assign({}, code_1.ERRORS.INVALID_PARAM), { message: "order value must be 1 or -1" }));
|
|
63
77
|
}
|
|
64
78
|
}
|
|
65
79
|
return true;
|
|
66
|
-
}
|
|
67
|
-
|
|
80
|
+
};
|
|
81
|
+
Validate.isFieldOrder = function (direction) {
|
|
68
82
|
if (constant_1.OrderDirectionList.indexOf(direction) === -1) {
|
|
69
83
|
throw new Error(constant_1.ErrorCode.DirectionError);
|
|
70
84
|
}
|
|
71
85
|
return true;
|
|
72
|
-
}
|
|
73
|
-
|
|
86
|
+
};
|
|
87
|
+
Validate.isFieldPath = function (path) {
|
|
74
88
|
if (!/^[a-zA-Z0-9-_\.]/.test(path)) {
|
|
75
89
|
throw new Error();
|
|
76
90
|
}
|
|
77
91
|
return true;
|
|
78
|
-
}
|
|
79
|
-
|
|
92
|
+
};
|
|
93
|
+
Validate.isOperator = function (op) {
|
|
80
94
|
if (constant_1.WhereFilterOpList.indexOf(op) === -1) {
|
|
81
95
|
throw new Error(constant_1.ErrorCode.OpStrError);
|
|
82
96
|
}
|
|
83
97
|
return true;
|
|
84
|
-
}
|
|
85
|
-
|
|
98
|
+
};
|
|
99
|
+
Validate.isCollName = function (name) {
|
|
86
100
|
if (!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(name)) {
|
|
87
101
|
throw new Error(constant_1.ErrorCode.CollNameError);
|
|
88
102
|
}
|
|
89
103
|
return true;
|
|
90
|
-
}
|
|
91
|
-
|
|
104
|
+
};
|
|
105
|
+
Validate.isDocID = function (docId) {
|
|
92
106
|
if (!/^([a-fA-F0-9]){24}$/.test(docId)) {
|
|
93
107
|
throw new Error(constant_1.ErrorCode.DocIDError);
|
|
94
108
|
}
|
|
95
109
|
return true;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
110
|
+
};
|
|
111
|
+
Validate.isValidOptions = function (options) {
|
|
112
|
+
if (options === void 0) { options = {}; }
|
|
113
|
+
if ((0, type_1.getType)(options) !== 'object') {
|
|
114
|
+
throw (0, utils_1.E)(__assign(__assign({}, code_1.ERRORS.INVALID_PARAM), { message: "options must be an object" }));
|
|
115
|
+
}
|
|
116
|
+
var keys = Object.keys(options);
|
|
117
|
+
for (var index in keys) {
|
|
103
118
|
if (validOptionsKeys.indexOf(keys[index]) < 0) {
|
|
104
|
-
throw utils_1.E(
|
|
119
|
+
throw (0, utils_1.E)(__assign(__assign({}, code_1.ERRORS.INVALID_PARAM), { message: "".concat(keys[index], " is invalid options key") }));
|
|
105
120
|
}
|
|
106
121
|
}
|
|
107
|
-
|
|
108
|
-
|
|
122
|
+
var _a = options, limit = _a.limit, offset = _a.offset, projection = _a.projection, order = _a.order;
|
|
123
|
+
var multiple = options.multiple;
|
|
109
124
|
if (limit !== undefined) {
|
|
110
125
|
Validate.isInteger('limit', limit);
|
|
111
126
|
}
|
|
@@ -125,23 +140,23 @@ class Validate {
|
|
|
125
140
|
Validate.isInteger('timeout', options.timeout);
|
|
126
141
|
}
|
|
127
142
|
return true;
|
|
128
|
-
}
|
|
129
|
-
|
|
143
|
+
};
|
|
144
|
+
Validate.isValidAggregation = function (stage) {
|
|
130
145
|
if (Object.keys(stage).length !== 1) {
|
|
131
|
-
throw utils_1.E(
|
|
146
|
+
throw (0, utils_1.E)(__assign(__assign({}, code_1.ERRORS.INVALID_PARAM), { message: "aggregation stage must have one key" }));
|
|
132
147
|
}
|
|
133
148
|
return true;
|
|
134
|
-
}
|
|
135
|
-
|
|
149
|
+
};
|
|
150
|
+
Validate.isCentersPhere = function (param) {
|
|
136
151
|
if (Array.isArray(param) && param.length === 2) {
|
|
137
|
-
if (type_1.getType(param[0]) === 'object' &&
|
|
152
|
+
if ((0, type_1.getType)(param[0]) === 'object' &&
|
|
138
153
|
param[0]._internalType === symbol_1.SYMBOL_GEO_POINT &&
|
|
139
154
|
typeof param[1] === 'number') {
|
|
140
155
|
return true;
|
|
141
156
|
}
|
|
142
157
|
if (Array.isArray(param[0]) && param[0].length === 2) {
|
|
143
|
-
|
|
144
|
-
|
|
158
|
+
var longitude = param[0][0];
|
|
159
|
+
var latitude = param[0][1];
|
|
145
160
|
Validate.isGeopoint('longitude', longitude);
|
|
146
161
|
Validate.isGeopoint('latitude', latitude);
|
|
147
162
|
if (typeof param[1] === 'number') {
|
|
@@ -149,7 +164,8 @@ class Validate {
|
|
|
149
164
|
}
|
|
150
165
|
}
|
|
151
166
|
}
|
|
152
|
-
throw new Error(
|
|
153
|
-
}
|
|
154
|
-
|
|
167
|
+
throw new Error("".concat(constant_1.ErrorCode.CentersPhereError));
|
|
168
|
+
};
|
|
169
|
+
return Validate;
|
|
170
|
+
}());
|
|
155
171
|
exports.Validate = Validate;
|