@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
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;
|
package/dist/esm/utils/utils.js
CHANGED
|
@@ -1,14 +1,72 @@
|
|
|
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 __assign = (this && this.__assign) || function () {
|
|
17
|
+
__assign = Object.assign || function(t) {
|
|
18
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
+
s = arguments[i];
|
|
20
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
+
t[p] = s[p];
|
|
22
|
+
}
|
|
23
|
+
return t;
|
|
24
|
+
};
|
|
25
|
+
return __assign.apply(this, arguments);
|
|
26
|
+
};
|
|
27
|
+
import { Db } from '../';
|
|
1
28
|
import { EJSON } from 'bson';
|
|
2
29
|
import { isObject } from './type';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
30
|
+
export var sleep = function (ms) {
|
|
31
|
+
if (ms === void 0) { ms = 0; }
|
|
32
|
+
return new Promise(function (r) { return setTimeout(r, ms); });
|
|
33
|
+
};
|
|
34
|
+
export function withCallback(promise, callback) {
|
|
35
|
+
if (typeof callback === 'function') {
|
|
36
|
+
promise.then(function (res) { return callback(0, res); }, function (err) { return callback(err); });
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
return promise;
|
|
40
|
+
}
|
|
41
|
+
var counters = {};
|
|
42
|
+
export var autoCount = function (domain) {
|
|
43
|
+
if (domain === void 0) { domain = 'any'; }
|
|
6
44
|
if (!counters[domain]) {
|
|
7
45
|
counters[domain] = 0;
|
|
8
46
|
}
|
|
9
47
|
return counters[domain]++;
|
|
10
48
|
};
|
|
11
|
-
|
|
49
|
+
var wsList = {};
|
|
50
|
+
export function getWsInstance(db) {
|
|
51
|
+
if (!Db.wsClientClass) {
|
|
52
|
+
throw new Error('to use realtime you must import realtime module first');
|
|
53
|
+
}
|
|
54
|
+
var env = db.config.env;
|
|
55
|
+
if (!wsList[env]) {
|
|
56
|
+
wsList[env] = new Db.wsClientClass({
|
|
57
|
+
context: {
|
|
58
|
+
appConfig: {
|
|
59
|
+
docSizeLimit: 1000,
|
|
60
|
+
realtimePingInterval: 10000,
|
|
61
|
+
realtimePongWaitTimeout: 5000,
|
|
62
|
+
request: Db.createRequest(db.config)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return wsList[env];
|
|
68
|
+
}
|
|
69
|
+
export var getReqOpts = function (apiOptions) {
|
|
12
70
|
if (apiOptions.timeout !== undefined) {
|
|
13
71
|
return {
|
|
14
72
|
timeout: apiOptions.timeout
|
|
@@ -16,11 +74,11 @@ export const getReqOpts = (apiOptions) => {
|
|
|
16
74
|
}
|
|
17
75
|
return {};
|
|
18
76
|
};
|
|
19
|
-
export
|
|
77
|
+
export var filterUndefined = function (o) {
|
|
20
78
|
if (!isObject(o)) {
|
|
21
79
|
return o;
|
|
22
80
|
}
|
|
23
|
-
for (
|
|
81
|
+
for (var key in o) {
|
|
24
82
|
if (o[key] === undefined) {
|
|
25
83
|
delete o[key];
|
|
26
84
|
}
|
|
@@ -30,26 +88,30 @@ export const filterUndefined = o => {
|
|
|
30
88
|
}
|
|
31
89
|
return o;
|
|
32
90
|
};
|
|
33
|
-
export
|
|
91
|
+
export var stringifyByEJSON = function (params) {
|
|
34
92
|
params = filterUndefined(params);
|
|
35
93
|
return EJSON.stringify(params, { relaxed: false });
|
|
36
94
|
};
|
|
37
|
-
export
|
|
95
|
+
export var parseByEJSON = function (params) {
|
|
38
96
|
return EJSON.parse(params);
|
|
39
97
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
98
|
+
var TcbError = (function (_super) {
|
|
99
|
+
__extends(TcbError, _super);
|
|
100
|
+
function TcbError(error) {
|
|
101
|
+
var _this = _super.call(this, error.message) || this;
|
|
102
|
+
_this.code = error.code;
|
|
103
|
+
_this.message = error.message;
|
|
104
|
+
return _this;
|
|
45
105
|
}
|
|
46
|
-
|
|
47
|
-
|
|
106
|
+
return TcbError;
|
|
107
|
+
}(Error));
|
|
108
|
+
export { TcbError };
|
|
109
|
+
export var E = function (errObj) {
|
|
48
110
|
return new TcbError(errObj);
|
|
49
111
|
};
|
|
50
112
|
export function processReturn(throwOnCode, res) {
|
|
51
113
|
if (throwOnCode === false) {
|
|
52
114
|
return res;
|
|
53
115
|
}
|
|
54
|
-
throw E(
|
|
116
|
+
throw E(__assign({}, res));
|
|
55
117
|
}
|
package/dist/esm/validate.js
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
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
|
+
};
|
|
1
12
|
import { ErrorCode, WhereFilterOpList, OrderDirectionList, FieldType } from './constant';
|
|
2
13
|
import { Util } from './util';
|
|
3
14
|
import { ERRORS } from './const/code';
|
|
4
15
|
import { E } from './utils/utils';
|
|
5
16
|
import { getType } from './utils/type';
|
|
6
17
|
import { SYMBOL_GEO_POINT } from './helper/symbol';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
18
|
+
var validOptionsKeys = ['limit', 'offset', 'projection', 'order', 'multiple', 'timeout', 'raw'];
|
|
19
|
+
var Validate = (function () {
|
|
20
|
+
function Validate() {
|
|
21
|
+
}
|
|
22
|
+
Validate.isGeopoint = function (point, degree) {
|
|
10
23
|
if (Util.whichType(degree) !== FieldType.Number) {
|
|
11
24
|
throw new Error('Geo Point must be number type');
|
|
12
25
|
}
|
|
13
|
-
|
|
26
|
+
var degreeAbs = Math.abs(degree);
|
|
14
27
|
if (point === 'latitude' && degreeAbs > 90) {
|
|
15
28
|
throw new Error('latitude should be a number ranges from -90 to 90');
|
|
16
29
|
}
|
|
@@ -18,92 +31,93 @@ export class Validate {
|
|
|
18
31
|
throw new Error('longitude should be a number ranges from -180 to 180');
|
|
19
32
|
}
|
|
20
33
|
return true;
|
|
21
|
-
}
|
|
22
|
-
|
|
34
|
+
};
|
|
35
|
+
Validate.isInteger = function (param, num) {
|
|
23
36
|
if (!Number.isInteger(num)) {
|
|
24
37
|
throw new Error(param + ErrorCode.IntergerError);
|
|
25
38
|
}
|
|
26
39
|
return true;
|
|
27
|
-
}
|
|
28
|
-
|
|
40
|
+
};
|
|
41
|
+
Validate.mustBeBoolean = function (param, bool) {
|
|
29
42
|
if (typeof bool !== 'boolean') {
|
|
30
43
|
throw new Error(param + ErrorCode.BooleanError);
|
|
31
44
|
}
|
|
32
45
|
return true;
|
|
33
|
-
}
|
|
34
|
-
|
|
46
|
+
};
|
|
47
|
+
Validate.isProjection = function (param, value) {
|
|
35
48
|
if (getType(value) !== 'object') {
|
|
36
|
-
throw E(
|
|
49
|
+
throw E(__assign(__assign({}, ERRORS.INVALID_PARAM), { message: "".concat(param, " projection must be an object") }));
|
|
37
50
|
}
|
|
38
|
-
for (
|
|
39
|
-
|
|
51
|
+
for (var key in value) {
|
|
52
|
+
var subValue = value[key];
|
|
40
53
|
if (getType(subValue) === 'number') {
|
|
41
54
|
if (subValue !== 0 && subValue !== 1) {
|
|
42
|
-
throw E(
|
|
55
|
+
throw E(__assign(__assign({}, ERRORS.INVALID_PARAM), { message: "if the value in projection is of number, it must be 0 or 1" }));
|
|
43
56
|
}
|
|
44
57
|
}
|
|
45
58
|
else if (getType(subValue) === 'object') {
|
|
46
59
|
}
|
|
47
60
|
else {
|
|
48
|
-
throw E(
|
|
61
|
+
throw E(__assign(__assign({}, ERRORS.INVALID_PARAM), { message: 'invalid projection' }));
|
|
49
62
|
}
|
|
50
63
|
}
|
|
51
64
|
return true;
|
|
52
|
-
}
|
|
53
|
-
|
|
65
|
+
};
|
|
66
|
+
Validate.isOrder = function (param, value) {
|
|
54
67
|
if (getType(value) !== 'object') {
|
|
55
|
-
throw E(
|
|
68
|
+
throw E(__assign(__assign({}, ERRORS.INVALID_PARAM), { message: "".concat(param, " order must be an object") }));
|
|
56
69
|
}
|
|
57
|
-
for (
|
|
58
|
-
|
|
70
|
+
for (var key in value) {
|
|
71
|
+
var subValue = value[key];
|
|
59
72
|
if (subValue !== 1 && subValue !== -1) {
|
|
60
|
-
throw E(
|
|
73
|
+
throw E(__assign(__assign({}, ERRORS.INVALID_PARAM), { message: "order value must be 1 or -1" }));
|
|
61
74
|
}
|
|
62
75
|
}
|
|
63
76
|
return true;
|
|
64
|
-
}
|
|
65
|
-
|
|
77
|
+
};
|
|
78
|
+
Validate.isFieldOrder = function (direction) {
|
|
66
79
|
if (OrderDirectionList.indexOf(direction) === -1) {
|
|
67
80
|
throw new Error(ErrorCode.DirectionError);
|
|
68
81
|
}
|
|
69
82
|
return true;
|
|
70
|
-
}
|
|
71
|
-
|
|
83
|
+
};
|
|
84
|
+
Validate.isFieldPath = function (path) {
|
|
72
85
|
if (!/^[a-zA-Z0-9-_\.]/.test(path)) {
|
|
73
86
|
throw new Error();
|
|
74
87
|
}
|
|
75
88
|
return true;
|
|
76
|
-
}
|
|
77
|
-
|
|
89
|
+
};
|
|
90
|
+
Validate.isOperator = function (op) {
|
|
78
91
|
if (WhereFilterOpList.indexOf(op) === -1) {
|
|
79
92
|
throw new Error(ErrorCode.OpStrError);
|
|
80
93
|
}
|
|
81
94
|
return true;
|
|
82
|
-
}
|
|
83
|
-
|
|
95
|
+
};
|
|
96
|
+
Validate.isCollName = function (name) {
|
|
84
97
|
if (!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(name)) {
|
|
85
98
|
throw new Error(ErrorCode.CollNameError);
|
|
86
99
|
}
|
|
87
100
|
return true;
|
|
88
|
-
}
|
|
89
|
-
|
|
101
|
+
};
|
|
102
|
+
Validate.isDocID = function (docId) {
|
|
90
103
|
if (!/^([a-fA-F0-9]){24}$/.test(docId)) {
|
|
91
104
|
throw new Error(ErrorCode.DocIDError);
|
|
92
105
|
}
|
|
93
106
|
return true;
|
|
94
|
-
}
|
|
95
|
-
|
|
107
|
+
};
|
|
108
|
+
Validate.isValidOptions = function (options) {
|
|
109
|
+
if (options === void 0) { options = {}; }
|
|
96
110
|
if (getType(options) !== 'object') {
|
|
97
|
-
throw E(
|
|
111
|
+
throw E(__assign(__assign({}, ERRORS.INVALID_PARAM), { message: "options must be an object" }));
|
|
98
112
|
}
|
|
99
|
-
|
|
100
|
-
for (
|
|
113
|
+
var keys = Object.keys(options);
|
|
114
|
+
for (var index in keys) {
|
|
101
115
|
if (validOptionsKeys.indexOf(keys[index]) < 0) {
|
|
102
|
-
throw E(
|
|
116
|
+
throw E(__assign(__assign({}, ERRORS.INVALID_PARAM), { message: "".concat(keys[index], " is invalid options key") }));
|
|
103
117
|
}
|
|
104
118
|
}
|
|
105
|
-
|
|
106
|
-
|
|
119
|
+
var _a = options, limit = _a.limit, offset = _a.offset, projection = _a.projection, order = _a.order;
|
|
120
|
+
var multiple = options.multiple;
|
|
107
121
|
if (limit !== undefined) {
|
|
108
122
|
Validate.isInteger('limit', limit);
|
|
109
123
|
}
|
|
@@ -123,14 +137,14 @@ export class Validate {
|
|
|
123
137
|
Validate.isInteger('timeout', options.timeout);
|
|
124
138
|
}
|
|
125
139
|
return true;
|
|
126
|
-
}
|
|
127
|
-
|
|
140
|
+
};
|
|
141
|
+
Validate.isValidAggregation = function (stage) {
|
|
128
142
|
if (Object.keys(stage).length !== 1) {
|
|
129
|
-
throw E(
|
|
143
|
+
throw E(__assign(__assign({}, ERRORS.INVALID_PARAM), { message: "aggregation stage must have one key" }));
|
|
130
144
|
}
|
|
131
145
|
return true;
|
|
132
|
-
}
|
|
133
|
-
|
|
146
|
+
};
|
|
147
|
+
Validate.isCentersPhere = function (param) {
|
|
134
148
|
if (Array.isArray(param) && param.length === 2) {
|
|
135
149
|
if (getType(param[0]) === 'object' &&
|
|
136
150
|
param[0]._internalType === SYMBOL_GEO_POINT &&
|
|
@@ -138,8 +152,8 @@ export class Validate {
|
|
|
138
152
|
return true;
|
|
139
153
|
}
|
|
140
154
|
if (Array.isArray(param[0]) && param[0].length === 2) {
|
|
141
|
-
|
|
142
|
-
|
|
155
|
+
var longitude = param[0][0];
|
|
156
|
+
var latitude = param[0][1];
|
|
143
157
|
Validate.isGeopoint('longitude', longitude);
|
|
144
158
|
Validate.isGeopoint('latitude', latitude);
|
|
145
159
|
if (typeof param[1] === 'number') {
|
|
@@ -147,6 +161,8 @@ export class Validate {
|
|
|
147
161
|
}
|
|
148
162
|
}
|
|
149
163
|
}
|
|
150
|
-
throw new Error(
|
|
151
|
-
}
|
|
152
|
-
|
|
164
|
+
throw new Error("".concat(ErrorCode.CentersPhereError));
|
|
165
|
+
};
|
|
166
|
+
return Validate;
|
|
167
|
+
}());
|
|
168
|
+
export { Validate };
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
preset: 'ts-jest',
|
|
3
|
+
testEnvironment: 'node',
|
|
4
|
+
testMatch: ['**/tests/**/*.ts'],
|
|
5
|
+
moduleFileExtensions: ['ts', 'js'],
|
|
6
|
+
transform: {
|
|
7
|
+
'^.+\\.ts$': ['ts-jest', {
|
|
8
|
+
tsconfig: 'tsconfig.test.json'
|
|
9
|
+
}]
|
|
10
|
+
},
|
|
11
|
+
transformIgnorePatterns: [
|
|
12
|
+
'/node_modules/(?!@types)/'
|
|
13
|
+
]
|
|
14
|
+
};
|
package/package.json
CHANGED
|
@@ -1,32 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/database",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "database for (node.)js sdk ",
|
|
5
5
|
"main": "dist/commonjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"tag": "next"
|
|
9
|
+
},
|
|
7
10
|
"scripts": {
|
|
8
11
|
"eslint": "eslint \"./**/*.ts\"",
|
|
9
12
|
"eslint-fix": "eslint --fix \"./**/*.ts\"",
|
|
10
|
-
"test": "
|
|
13
|
+
"test": "jest",
|
|
11
14
|
"build": "tsc -p tsconfig.json && tsc -p tsconfig.esm.json",
|
|
12
15
|
"prepublishOnly": "npm run build"
|
|
13
16
|
},
|
|
14
17
|
"author": "",
|
|
15
18
|
"license": "ISC",
|
|
16
19
|
"devDependencies": {
|
|
20
|
+
"@types/jest": "26.0.24",
|
|
21
|
+
"@types/node": "14.14.31",
|
|
17
22
|
"eslint": "^5.15.3",
|
|
18
23
|
"eslint-config-prettier": "^4.1.0",
|
|
19
24
|
"eslint-plugin-prettier": "^3.0.1",
|
|
20
25
|
"eslint-plugin-typescript": "^0.14.0",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
26
|
+
"jest": "26.6.3",
|
|
27
|
+
"ts-jest": "26.5.6",
|
|
28
|
+
"typescript": "^4.1.0",
|
|
29
|
+
"typescript-eslint-parser": "^22.0.0"
|
|
24
30
|
},
|
|
25
31
|
"sideEffects": false,
|
|
26
32
|
"dependencies": {
|
|
27
|
-
"bson": "^
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"lodash.unset": "4.5.2"
|
|
31
|
-
}
|
|
33
|
+
"bson": "^6.10.4"
|
|
34
|
+
},
|
|
35
|
+
"packageManager": "yarn@1.22.22"
|
|
32
36
|
}
|