@cloudbase/database 0.9.17-beta → 0.9.19
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/README.md +32 -10
- package/dist/commonjs/ObjectId/index.d.ts +11 -0
- package/dist/commonjs/ObjectId/index.js +21 -0
- package/dist/commonjs/aggregate.d.ts +29 -29
- package/dist/commonjs/aggregate.js +156 -146
- package/dist/commonjs/collection.d.ts +9 -9
- package/dist/commonjs/collection.js +46 -46
- package/dist/commonjs/command.d.ts +175 -175
- package/dist/commonjs/command.js +298 -298
- package/dist/commonjs/commands/logic.d.ts +24 -24
- package/dist/commonjs/commands/logic.js +88 -88
- package/dist/commonjs/commands/query.d.ts +68 -68
- package/dist/commonjs/commands/query.js +157 -157
- package/dist/commonjs/commands/update.d.ts +29 -29
- package/dist/commonjs/commands/update.js +50 -50
- package/dist/commonjs/config/app.config.d.ts +6 -6
- package/dist/commonjs/config/app.config.js +7 -7
- package/dist/commonjs/config/error.config.d.ts +3 -3
- package/dist/commonjs/config/error.config.js +15 -15
- package/dist/commonjs/const/code.d.ts +30 -30
- package/dist/commonjs/const/code.js +32 -32
- package/dist/commonjs/constant.d.ts +51 -51
- package/dist/commonjs/constant.js +74 -74
- package/dist/commonjs/document.d.ts +11 -11
- package/dist/commonjs/document.js +252 -263
- package/dist/commonjs/geo/index.d.ts +6 -6
- package/dist/commonjs/geo/index.js +11 -11
- package/dist/commonjs/geo/interface.d.ts +24 -24
- package/dist/commonjs/geo/interface.js +2 -2
- package/dist/commonjs/geo/lineString.d.ts +19 -19
- package/dist/commonjs/geo/lineString.js +85 -85
- package/dist/commonjs/geo/multiLineString.d.ts +18 -18
- package/dist/commonjs/geo/multiLineString.js +94 -94
- package/dist/commonjs/geo/multiPoint.d.ts +18 -18
- package/dist/commonjs/geo/multiPoint.js +78 -78
- package/dist/commonjs/geo/multiPolygon.d.ts +18 -18
- package/dist/commonjs/geo/multiPolygon.js +121 -121
- package/dist/commonjs/geo/point.d.ts +19 -19
- package/dist/commonjs/geo/point.js +49 -49
- package/dist/commonjs/geo/polygon.d.ts +19 -19
- package/dist/commonjs/geo/polygon.js +108 -108
- package/dist/commonjs/helper/symbol.d.ts +14 -14
- package/dist/commonjs/helper/symbol.js +19 -19
- package/dist/commonjs/index.d.ts +33 -32
- package/dist/commonjs/index.js +46 -46
- package/dist/commonjs/lib/util.d.ts +1 -1
- package/dist/commonjs/lib/util.js +25 -25
- package/dist/commonjs/operator-map.d.ts +4 -4
- package/dist/commonjs/operator-map.js +23 -23
- package/dist/commonjs/query.d.ts +22 -22
- package/dist/commonjs/query.js +251 -262
- package/dist/commonjs/realtime/error.d.ts +7 -7
- package/dist/commonjs/realtime/error.js +11 -27
- package/dist/commonjs/realtime/listener.d.ts +14 -14
- package/dist/commonjs/realtime/listener.js +17 -18
- package/dist/commonjs/realtime/message.d.ts +3 -3
- package/dist/commonjs/realtime/message.js +10 -11
- package/dist/commonjs/realtime/snapshot.d.ts +16 -16
- package/dist/commonjs/realtime/snapshot.js +42 -43
- package/dist/commonjs/realtime/virtual-websocket-client.d.ts +63 -63
- package/dist/commonjs/realtime/virtual-websocket-client.js +736 -990
- package/dist/commonjs/realtime/websocket-client.d.ts +78 -78
- package/dist/commonjs/realtime/websocket-client.js +567 -788
- package/dist/commonjs/realtime/ws-event.d.ts +126 -126
- package/dist/commonjs/realtime/ws-event.js +139 -139
- package/dist/commonjs/regexp/index.d.ts +14 -14
- package/dist/commonjs/regexp/index.js +32 -32
- package/dist/commonjs/serializer/common.d.ts +11 -11
- package/dist/commonjs/serializer/common.js +121 -121
- package/dist/commonjs/serializer/datatype.d.ts +7 -7
- package/dist/commonjs/serializer/datatype.js +126 -126
- package/dist/commonjs/serializer/query.d.ts +7 -7
- package/dist/commonjs/serializer/query.js +231 -231
- package/dist/commonjs/serializer/update.d.ts +15 -15
- package/dist/commonjs/serializer/update.js +141 -141
- package/dist/commonjs/serverDate/index.d.ts +13 -13
- package/dist/commonjs/serverDate/index.js +29 -29
- package/dist/commonjs/transaction/collection.d.ts +7 -7
- package/dist/commonjs/transaction/collection.js +46 -46
- package/dist/commonjs/transaction/document.d.ts +27 -27
- package/dist/commonjs/transaction/document.js +205 -205
- package/dist/commonjs/transaction/index.d.ts +30 -30
- package/dist/commonjs/transaction/index.js +214 -214
- package/dist/commonjs/transaction/query.d.ts +5 -5
- package/dist/commonjs/transaction/query.js +10 -10
- package/dist/commonjs/transaction.d.ts +42 -42
- package/dist/commonjs/transaction.js +126 -126
- package/dist/commonjs/typings/index.d.ts +40 -40
- package/dist/commonjs/typings/index.js +2 -2
- package/dist/commonjs/typings/realtime.d.ts +219 -219
- package/dist/commonjs/typings/realtime.js +2 -2
- package/dist/commonjs/util.d.ts +9 -9
- package/dist/commonjs/util.js +144 -144
- package/dist/commonjs/utils/error.d.ts +37 -37
- package/dist/commonjs/utils/error.js +85 -85
- package/dist/commonjs/utils/symbol.d.ts +8 -8
- package/dist/commonjs/utils/symbol.js +57 -57
- package/dist/commonjs/utils/type.d.ts +13 -13
- package/dist/commonjs/utils/type.js +22 -22
- package/dist/commonjs/utils/utils.d.ts +4 -2
- package/dist/commonjs/utils/utils.js +36 -14
- package/dist/commonjs/validate.d.ts +1 -1
- package/dist/commonjs/validate.js +59 -59
- package/dist/esm/ObjectId/index.d.ts +11 -0
- package/dist/esm/ObjectId/index.js +17 -0
- package/dist/esm/aggregate.d.ts +29 -29
- package/dist/esm/aggregate.js +154 -144
- package/dist/esm/collection.d.ts +9 -9
- package/dist/esm/collection.js +44 -44
- package/dist/esm/command.d.ts +175 -175
- package/dist/esm/command.js +296 -296
- package/dist/esm/commands/logic.d.ts +24 -24
- package/dist/esm/commands/logic.js +84 -84
- package/dist/esm/commands/query.d.ts +68 -68
- package/dist/esm/commands/query.js +152 -152
- package/dist/esm/commands/update.d.ts +29 -29
- package/dist/esm/commands/update.js +46 -46
- package/dist/esm/config/app.config.d.ts +6 -6
- package/dist/esm/config/app.config.js +5 -5
- package/dist/esm/config/error.config.d.ts +3 -3
- package/dist/esm/config/error.config.js +13 -13
- package/dist/esm/const/code.d.ts +30 -30
- package/dist/esm/const/code.js +30 -30
- package/dist/esm/constant.d.ts +51 -51
- package/dist/esm/constant.js +65 -65
- package/dist/esm/document.d.ts +11 -11
- package/dist/esm/document.js +250 -261
- package/dist/esm/geo/index.d.ts +6 -6
- package/dist/esm/geo/index.js +6 -6
- package/dist/esm/geo/interface.d.ts +24 -24
- package/dist/esm/geo/lineString.d.ts +19 -19
- package/dist/esm/geo/lineString.js +83 -83
- package/dist/esm/geo/multiLineString.d.ts +18 -18
- package/dist/esm/geo/multiLineString.js +92 -92
- package/dist/esm/geo/multiPoint.d.ts +18 -18
- package/dist/esm/geo/multiPoint.js +76 -76
- package/dist/esm/geo/multiPolygon.d.ts +18 -18
- package/dist/esm/geo/multiPolygon.js +119 -119
- package/dist/esm/geo/point.d.ts +19 -19
- package/dist/esm/geo/point.js +47 -47
- package/dist/esm/geo/polygon.d.ts +19 -19
- package/dist/esm/geo/polygon.js +106 -106
- package/dist/esm/helper/symbol.d.ts +14 -14
- package/dist/esm/helper/symbol.js +14 -14
- package/dist/esm/index.d.ts +33 -32
- package/dist/esm/index.js +41 -41
- package/dist/esm/lib/util.d.ts +1 -1
- package/dist/esm/lib/util.js +23 -23
- package/dist/esm/operator-map.d.ts +4 -4
- package/dist/esm/operator-map.js +20 -20
- package/dist/esm/query.d.ts +22 -22
- package/dist/esm/query.js +249 -260
- package/dist/esm/realtime/error.d.ts +7 -7
- package/dist/esm/realtime/error.js +8 -25
- package/dist/esm/realtime/listener.d.ts +14 -14
- package/dist/esm/realtime/listener.js +14 -16
- package/dist/esm/realtime/message.d.ts +3 -3
- package/dist/esm/realtime/message.js +6 -7
- package/dist/esm/realtime/snapshot.d.ts +16 -16
- package/dist/esm/realtime/snapshot.js +39 -41
- package/dist/esm/realtime/virtual-websocket-client.d.ts +63 -63
- package/dist/esm/realtime/virtual-websocket-client.js +733 -988
- package/dist/esm/realtime/websocket-client.d.ts +78 -78
- package/dist/esm/realtime/websocket-client.js +564 -786
- package/dist/esm/realtime/ws-event.d.ts +126 -126
- package/dist/esm/realtime/ws-event.js +137 -137
- package/dist/esm/regexp/index.d.ts +14 -14
- package/dist/esm/regexp/index.js +29 -29
- package/dist/esm/serializer/common.d.ts +11 -11
- package/dist/esm/serializer/common.js +113 -113
- package/dist/esm/serializer/datatype.d.ts +7 -7
- package/dist/esm/serializer/datatype.js +122 -122
- package/dist/esm/serializer/query.d.ts +7 -7
- package/dist/esm/serializer/query.js +229 -229
- package/dist/esm/serializer/update.d.ts +15 -15
- package/dist/esm/serializer/update.js +139 -139
- package/dist/esm/serverDate/index.d.ts +13 -13
- package/dist/esm/serverDate/index.js +26 -26
- package/dist/esm/transaction/collection.d.ts +7 -7
- package/dist/esm/transaction/collection.js +44 -44
- package/dist/esm/transaction/document.d.ts +27 -27
- package/dist/esm/transaction/document.js +203 -203
- package/dist/esm/transaction/index.d.ts +30 -30
- package/dist/esm/transaction/index.js +210 -210
- package/dist/esm/transaction/query.d.ts +5 -5
- package/dist/esm/transaction/query.js +8 -8
- package/dist/esm/transaction.d.ts +42 -42
- package/dist/esm/transaction.js +121 -121
- package/dist/esm/typings/index.d.ts +40 -40
- package/dist/esm/typings/realtime.d.ts +219 -219
- package/dist/esm/util.d.ts +9 -9
- package/dist/esm/util.js +142 -142
- package/dist/esm/utils/error.d.ts +37 -37
- package/dist/esm/utils/error.js +82 -82
- package/dist/esm/utils/symbol.d.ts +8 -8
- package/dist/esm/utils/symbol.js +55 -55
- package/dist/esm/utils/type.d.ts +13 -13
- package/dist/esm/utils/type.js +20 -20
- package/dist/esm/utils/utils.d.ts +4 -2
- package/dist/esm/utils/utils.js +33 -12
- package/dist/esm/validate.d.ts +1 -1
- package/dist/esm/validate.js +57 -57
- package/package.json +4 -1
- package/src/aggregate.ts +11 -0
- package/src/document.ts +3 -15
- package/src/index.ts +2 -0
- package/src/query.ts +4 -16
- package/src/utils/utils.ts +28 -0
- package/.DS_Store +0 -0
- package/src/.DS_Store +0 -0
- 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/regexp/.DS_Store +0 -0
package/dist/esm/utils/type.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export declare const getType: (x: any) => string;
|
|
2
|
-
export declare const isObject: <T extends object>(x: any) => x is T;
|
|
3
|
-
export declare const isString: (x: any) => x is string;
|
|
4
|
-
export declare const isNumber: (x: any) => x is number;
|
|
5
|
-
export declare const isPromise: <T extends Promise<any> = Promise<any>>(x: any) => x is T;
|
|
6
|
-
declare type AnyFn = (...args: any[]) => any;
|
|
7
|
-
export declare const isFunction: <T extends AnyFn = AnyFn>(x: any) => x is T;
|
|
8
|
-
export declare const isArray: <T extends any[] = any[]>(x: any) => x is T;
|
|
9
|
-
export declare const isDate: (x: any) => x is Date;
|
|
10
|
-
export declare const isRegExp: (x: any) => x is RegExp;
|
|
11
|
-
export declare const isInternalObject: (x: any) => boolean;
|
|
12
|
-
export declare const isPlainObject: (obj: any) => obj is object;
|
|
13
|
-
export {};
|
|
1
|
+
export declare const getType: (x: any) => string;
|
|
2
|
+
export declare const isObject: <T extends object>(x: any) => x is T;
|
|
3
|
+
export declare const isString: (x: any) => x is string;
|
|
4
|
+
export declare const isNumber: (x: any) => x is number;
|
|
5
|
+
export declare const isPromise: <T extends Promise<any> = Promise<any>>(x: any) => x is T;
|
|
6
|
+
declare type AnyFn = (...args: any[]) => any;
|
|
7
|
+
export declare const isFunction: <T extends AnyFn = AnyFn>(x: any) => x is T;
|
|
8
|
+
export declare const isArray: <T extends any[] = any[]>(x: any) => x is T;
|
|
9
|
+
export declare const isDate: (x: any) => x is Date;
|
|
10
|
+
export declare const isRegExp: (x: any) => x is RegExp;
|
|
11
|
+
export declare const isInternalObject: (x: any) => boolean;
|
|
12
|
+
export declare const isPlainObject: (obj: any) => obj is object;
|
|
13
|
+
export {};
|
package/dist/esm/utils/type.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { InternalSymbol } from './symbol';
|
|
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
|
-
if (typeof obj !== 'object' || obj === null)
|
|
14
|
-
return false;
|
|
15
|
-
var proto = obj;
|
|
16
|
-
while (Object.getPrototypeOf(proto) !== null) {
|
|
17
|
-
proto = Object.getPrototypeOf(proto);
|
|
18
|
-
}
|
|
19
|
-
return Object.getPrototypeOf(obj) === proto;
|
|
20
|
-
};
|
|
1
|
+
import { InternalSymbol } from './symbol';
|
|
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
|
+
if (typeof obj !== 'object' || obj === null)
|
|
14
|
+
return false;
|
|
15
|
+
var proto = obj;
|
|
16
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
17
|
+
proto = Object.getPrototypeOf(proto);
|
|
18
|
+
}
|
|
19
|
+
return Object.getPrototypeOf(obj) === proto;
|
|
20
|
+
};
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
1
|
+
import { Db } from '../';
|
|
2
|
+
export declare const sleep: (ms?: number) => Promise<unknown>;
|
|
3
|
+
export declare const autoCount: (domain?: string) => number;
|
|
4
|
+
export declare function getWsInstance(db: Db): any;
|
package/dist/esm/utils/utils.js
CHANGED
|
@@ -1,12 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { Db } from '../';
|
|
2
|
+
export var sleep = function (ms) {
|
|
3
|
+
if (ms === void 0) { ms = 0; }
|
|
4
|
+
return new Promise(function (r) { return setTimeout(r, ms); });
|
|
5
|
+
};
|
|
6
|
+
var counters = {};
|
|
7
|
+
export var autoCount = function (domain) {
|
|
8
|
+
if (domain === void 0) { domain = 'any'; }
|
|
9
|
+
if (!counters[domain]) {
|
|
10
|
+
counters[domain] = 0;
|
|
11
|
+
}
|
|
12
|
+
return counters[domain]++;
|
|
13
|
+
};
|
|
14
|
+
var wsList = {};
|
|
15
|
+
export function getWsInstance(db) {
|
|
16
|
+
if (!Db.wsClientClass) {
|
|
17
|
+
throw new Error('to use realtime you must import realtime module first');
|
|
18
|
+
}
|
|
19
|
+
var env = db.config.env;
|
|
20
|
+
if (!wsList[env]) {
|
|
21
|
+
wsList[env] = new Db.wsClientClass({
|
|
22
|
+
context: {
|
|
23
|
+
appConfig: {
|
|
24
|
+
docSizeLimit: 1000,
|
|
25
|
+
realtimePingInterval: 10000,
|
|
26
|
+
realtimePongWaitTimeout: 5000,
|
|
27
|
+
request: new Db.reqClass(db.config)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return wsList[env];
|
|
33
|
+
}
|
package/dist/esm/validate.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/dist/esm/validate.js
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { ErrorCode, WhereFilterOpList, OrderDirectionList, FieldType } from './constant';
|
|
2
|
-
import { Util } from './util';
|
|
3
|
-
var Validate = (function () {
|
|
4
|
-
function Validate() {
|
|
5
|
-
}
|
|
6
|
-
Validate.isGeopoint = function (point, degree) {
|
|
7
|
-
if (Util.whichType(degree) !== FieldType.Number) {
|
|
8
|
-
throw new Error('Geo Point must be number type');
|
|
9
|
-
}
|
|
10
|
-
var degreeAbs = Math.abs(degree);
|
|
11
|
-
if (point === 'latitude' && degreeAbs > 90) {
|
|
12
|
-
throw new Error('latitude should be a number ranges from -90 to 90');
|
|
13
|
-
}
|
|
14
|
-
else if (point === 'longitude' && degreeAbs > 180) {
|
|
15
|
-
throw new Error('longitude should be a number ranges from -180 to 180');
|
|
16
|
-
}
|
|
17
|
-
return true;
|
|
18
|
-
};
|
|
19
|
-
Validate.isInteger = function (param, num) {
|
|
20
|
-
if (!Number.isInteger(num)) {
|
|
21
|
-
throw new Error(param + ErrorCode.IntergerError);
|
|
22
|
-
}
|
|
23
|
-
return true;
|
|
24
|
-
};
|
|
25
|
-
Validate.isFieldOrder = function (direction) {
|
|
26
|
-
if (OrderDirectionList.indexOf(direction) === -1) {
|
|
27
|
-
throw new Error(ErrorCode.DirectionError);
|
|
28
|
-
}
|
|
29
|
-
return true;
|
|
30
|
-
};
|
|
31
|
-
Validate.isFieldPath = function (path) {
|
|
32
|
-
if (!/^[a-zA-Z0-9-_\.]/.test(path)) {
|
|
33
|
-
throw new Error();
|
|
34
|
-
}
|
|
35
|
-
return true;
|
|
36
|
-
};
|
|
37
|
-
Validate.isOperator = function (op) {
|
|
38
|
-
if (WhereFilterOpList.indexOf(op) === -1) {
|
|
39
|
-
throw new Error(ErrorCode.OpStrError);
|
|
40
|
-
}
|
|
41
|
-
return true;
|
|
42
|
-
};
|
|
43
|
-
Validate.isCollName = function (name) {
|
|
44
|
-
if (!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(name)) {
|
|
45
|
-
throw new Error(ErrorCode.CollNameError);
|
|
46
|
-
}
|
|
47
|
-
return true;
|
|
48
|
-
};
|
|
49
|
-
Validate.isDocID = function (docId) {
|
|
50
|
-
if (!/^([a-fA-F0-9]){24}$/.test(docId)) {
|
|
51
|
-
throw new Error(ErrorCode.DocIDError);
|
|
52
|
-
}
|
|
53
|
-
return true;
|
|
54
|
-
};
|
|
55
|
-
return Validate;
|
|
56
|
-
}());
|
|
57
|
-
export { Validate };
|
|
1
|
+
import { ErrorCode, WhereFilterOpList, OrderDirectionList, FieldType } from './constant';
|
|
2
|
+
import { Util } from './util';
|
|
3
|
+
var Validate = (function () {
|
|
4
|
+
function Validate() {
|
|
5
|
+
}
|
|
6
|
+
Validate.isGeopoint = function (point, degree) {
|
|
7
|
+
if (Util.whichType(degree) !== FieldType.Number) {
|
|
8
|
+
throw new Error('Geo Point must be number type');
|
|
9
|
+
}
|
|
10
|
+
var degreeAbs = Math.abs(degree);
|
|
11
|
+
if (point === 'latitude' && degreeAbs > 90) {
|
|
12
|
+
throw new Error('latitude should be a number ranges from -90 to 90');
|
|
13
|
+
}
|
|
14
|
+
else if (point === 'longitude' && degreeAbs > 180) {
|
|
15
|
+
throw new Error('longitude should be a number ranges from -180 to 180');
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
};
|
|
19
|
+
Validate.isInteger = function (param, num) {
|
|
20
|
+
if (!Number.isInteger(num)) {
|
|
21
|
+
throw new Error(param + ErrorCode.IntergerError);
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
};
|
|
25
|
+
Validate.isFieldOrder = function (direction) {
|
|
26
|
+
if (OrderDirectionList.indexOf(direction) === -1) {
|
|
27
|
+
throw new Error(ErrorCode.DirectionError);
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
};
|
|
31
|
+
Validate.isFieldPath = function (path) {
|
|
32
|
+
if (!/^[a-zA-Z0-9-_\.]/.test(path)) {
|
|
33
|
+
throw new Error();
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
};
|
|
37
|
+
Validate.isOperator = function (op) {
|
|
38
|
+
if (WhereFilterOpList.indexOf(op) === -1) {
|
|
39
|
+
throw new Error(ErrorCode.OpStrError);
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
};
|
|
43
|
+
Validate.isCollName = function (name) {
|
|
44
|
+
if (!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(name)) {
|
|
45
|
+
throw new Error(ErrorCode.CollNameError);
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
};
|
|
49
|
+
Validate.isDocID = function (docId) {
|
|
50
|
+
if (!/^([a-fA-F0-9]){24}$/.test(docId)) {
|
|
51
|
+
throw new Error(ErrorCode.DocIDError);
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
};
|
|
55
|
+
return Validate;
|
|
56
|
+
}());
|
|
57
|
+
export { Validate };
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/database",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.19",
|
|
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\"",
|
package/src/aggregate.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Db } from './index'
|
|
2
2
|
import { EJSON } from 'bson'
|
|
3
3
|
import { QuerySerializer } from './serializer/query'
|
|
4
|
+
import { Point } from './geo'
|
|
4
5
|
export default class Aggregation {
|
|
5
6
|
_db: any
|
|
6
7
|
_request: any
|
|
@@ -70,6 +71,16 @@ export default class Aggregation {
|
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
geoNear(param) {
|
|
74
|
+
if (param.query) {
|
|
75
|
+
param.query = QuerySerializer.encode(param.query)
|
|
76
|
+
}
|
|
77
|
+
if (param.distanceMultiplier && typeof (param.distanceMultiplier) === 'number') {
|
|
78
|
+
param.distanceMultiplier = param.distanceMultiplier
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if(param.near) {
|
|
82
|
+
param.near = new Point(param.near.longitude, param.near.latitude).toJSON()
|
|
83
|
+
}
|
|
73
84
|
return this._pipe('geoNear', param)
|
|
74
85
|
}
|
|
75
86
|
|
package/src/document.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { UpdateSerializer } from './serializer/update'
|
|
|
5
5
|
import { serialize } from './serializer/datatype'
|
|
6
6
|
import { UpdateCommand } from './commands/update'
|
|
7
7
|
import { IWatchOptions, DBRealtimeListener } from './typings/index'
|
|
8
|
-
import { RealtimeWebSocketClient } from './realtime/websocket-client'
|
|
9
8
|
import { QueryType } from './constant'
|
|
9
|
+
import { getWsInstance } from './utils/utils'
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* 文档模块
|
|
@@ -333,20 +333,9 @@ export class DocumentReference {
|
|
|
333
333
|
* 监听单个文档
|
|
334
334
|
*/
|
|
335
335
|
watch = (options: IWatchOptions): DBRealtimeListener => {
|
|
336
|
-
|
|
337
|
-
Db.ws = new RealtimeWebSocketClient({
|
|
338
|
-
context: {
|
|
339
|
-
appConfig: {
|
|
340
|
-
docSizeLimit: 1000,
|
|
341
|
-
realtimePingInterval: 10000,
|
|
342
|
-
realtimePongWaitTimeout: 5000,
|
|
343
|
-
request: this.request
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
})
|
|
347
|
-
}
|
|
336
|
+
const ws = getWsInstance(this._db)
|
|
348
337
|
|
|
349
|
-
return
|
|
338
|
+
return ws.watch({
|
|
350
339
|
...options,
|
|
351
340
|
envId: this._db.config.env,
|
|
352
341
|
collectionName: this._coll,
|
|
@@ -354,6 +343,5 @@ export class DocumentReference {
|
|
|
354
343
|
_id: this.id
|
|
355
344
|
})
|
|
356
345
|
})
|
|
357
|
-
// })
|
|
358
346
|
}
|
|
359
347
|
}
|
package/src/index.ts
CHANGED
package/src/query.ts
CHANGED
|
@@ -10,8 +10,8 @@ import { QuerySerializer } from './serializer/query'
|
|
|
10
10
|
import { UpdateSerializer } from './serializer/update'
|
|
11
11
|
// import { WSClient } from "./websocket/wsclient"
|
|
12
12
|
import { IWatchOptions, DBRealtimeListener } from './typings/index'
|
|
13
|
-
import { RealtimeWebSocketClient } from './realtime/websocket-client'
|
|
14
13
|
import { ErrorCode } from './constant'
|
|
14
|
+
import { getWsInstance } from './utils/utils'
|
|
15
15
|
|
|
16
16
|
interface GetRes {
|
|
17
17
|
data: any[]
|
|
@@ -449,24 +449,13 @@ export class Query {
|
|
|
449
449
|
* 监听query对应的doc变化
|
|
450
450
|
*/
|
|
451
451
|
watch = (options: IWatchOptions): DBRealtimeListener => {
|
|
452
|
-
|
|
453
|
-
Db.ws = new RealtimeWebSocketClient({
|
|
454
|
-
context: {
|
|
455
|
-
appConfig: {
|
|
456
|
-
docSizeLimit: 1000,
|
|
457
|
-
realtimePingInterval: 10000,
|
|
458
|
-
realtimePongWaitTimeout: 5000,
|
|
459
|
-
request: this._request
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
})
|
|
463
|
-
}
|
|
452
|
+
const ws = getWsInstance(this._db)
|
|
464
453
|
|
|
465
|
-
return
|
|
454
|
+
return ws.watch({
|
|
466
455
|
...options,
|
|
467
456
|
envId: this._db.config.env,
|
|
468
457
|
collectionName: this._coll,
|
|
469
|
-
query: JSON.stringify(this._fieldFilters),
|
|
458
|
+
query: JSON.stringify(this._fieldFilters || {}),
|
|
470
459
|
limit: this._queryOptions.limit,
|
|
471
460
|
orderBy: this._fieldOrders
|
|
472
461
|
? this._fieldOrders.reduce<Record<string, string>>((acc, cur) => {
|
|
@@ -475,7 +464,6 @@ export class Query {
|
|
|
475
464
|
}, {})
|
|
476
465
|
: undefined
|
|
477
466
|
})
|
|
478
|
-
// })
|
|
479
467
|
}
|
|
480
468
|
|
|
481
469
|
/*
|
package/src/utils/utils.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Db } from '../';
|
|
2
|
+
|
|
1
3
|
export const sleep = (ms: number = 0) => new Promise(r => setTimeout(r, ms))
|
|
2
4
|
|
|
3
5
|
const counters: Record<string, number> = {}
|
|
@@ -8,3 +10,29 @@ export const autoCount = (domain: string = 'any'): number => {
|
|
|
8
10
|
}
|
|
9
11
|
return counters[domain]++
|
|
10
12
|
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 工厂模式创建 ws 实例
|
|
16
|
+
*/
|
|
17
|
+
const wsList = {}
|
|
18
|
+
export function getWsInstance(db: Db) {
|
|
19
|
+
if(!Db.wsClientClass){
|
|
20
|
+
throw new Error('to use realtime you must import realtime module first')
|
|
21
|
+
}
|
|
22
|
+
const { env } = db.config
|
|
23
|
+
|
|
24
|
+
if (!wsList[env]) {
|
|
25
|
+
wsList[env] = new Db.wsClientClass({
|
|
26
|
+
context: {
|
|
27
|
+
appConfig: {
|
|
28
|
+
docSizeLimit: 1000,
|
|
29
|
+
realtimePingInterval: 10000,
|
|
30
|
+
realtimePongWaitTimeout: 5000,
|
|
31
|
+
request: new Db.reqClass(db.config)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return wsList[env]
|
|
38
|
+
}
|
package/.DS_Store
DELETED
|
Binary file
|
package/src/.DS_Store
DELETED
|
Binary file
|
package/src/realtime/error.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { IResponseMessageErrorMsg } from '../typings/realtime'
|
|
2
|
-
|
|
3
|
-
export class RealtimeErrorMessageError extends Error {
|
|
4
|
-
isRealtimeErrorMessageError = true
|
|
5
|
-
payload: IResponseMessageErrorMsg
|
|
6
|
-
|
|
7
|
-
constructor(serverErrorMsg: IResponseMessageErrorMsg) {
|
|
8
|
-
super(
|
|
9
|
-
`Watch Error ${JSON.stringify(serverErrorMsg.msgData)} (requestid: ${
|
|
10
|
-
serverErrorMsg.requestId
|
|
11
|
-
})`
|
|
12
|
-
)
|
|
13
|
-
this.payload = serverErrorMsg
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const isRealtimeErrorMessageError = (
|
|
18
|
-
e: any
|
|
19
|
-
): e is RealtimeErrorMessageError => e && e.isRealtimeErrorMessageError
|
package/src/realtime/listener.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { VirtualWebSocketClient } from './virtual-websocket-client'
|
|
2
|
-
import {
|
|
3
|
-
IRealtimeListenerConstructorOptions,
|
|
4
|
-
DBRealtimeListener
|
|
5
|
-
} from '../typings/index'
|
|
6
|
-
|
|
7
|
-
// =============== Realtime Listener (Public) ====================
|
|
8
|
-
|
|
9
|
-
interface IRealtimeListenerOptions extends IRealtimeListenerConstructorOptions {
|
|
10
|
-
// init
|
|
11
|
-
close: () => void
|
|
12
|
-
// debug
|
|
13
|
-
debug?: boolean
|
|
14
|
-
virtualClient?: VirtualWebSocketClient
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class RealtimeListener implements DBRealtimeListener {
|
|
18
|
-
close: () => void
|
|
19
|
-
onChange: (res: any) => void
|
|
20
|
-
onError: (error: any) => void
|
|
21
|
-
|
|
22
|
-
constructor(options: IRealtimeListenerOptions) {
|
|
23
|
-
this.close = options.close
|
|
24
|
-
this.onChange = options.onChange
|
|
25
|
-
this.onError = options.onError
|
|
26
|
-
|
|
27
|
-
if (options.debug) {
|
|
28
|
-
Object.defineProperty(this, 'virtualClient', {
|
|
29
|
-
get: () => {
|
|
30
|
-
return options.virtualClient
|
|
31
|
-
}
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
package/src/realtime/message.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IResponseMessage,
|
|
3
|
-
IResponseMessageInitEventMsg
|
|
4
|
-
} from '../typings/realtime'
|
|
5
|
-
|
|
6
|
-
export function genRequestId(prefix: string = '') {
|
|
7
|
-
return `${prefix ? `${prefix}_` : ''}${+new Date()}_${Math.random()}`
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function isInitEventMessage(
|
|
11
|
-
msg: IResponseMessage
|
|
12
|
-
): msg is IResponseMessageInitEventMsg {
|
|
13
|
-
return msg.msgType === 'INIT_EVENT'
|
|
14
|
-
}
|
package/src/realtime/snapshot.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { ISingleDBEvent, SnapshotType, ISnapshot } from '../typings/index'
|
|
2
|
-
|
|
3
|
-
// =============== Realtime Snapshot / Change Event (Public) ====================
|
|
4
|
-
|
|
5
|
-
interface ISnapshotConstructorOptions {
|
|
6
|
-
id: number
|
|
7
|
-
docChanges: ISingleDBEvent[]
|
|
8
|
-
docs: Record<string, any>[]
|
|
9
|
-
type?: SnapshotType
|
|
10
|
-
// EJSON: any
|
|
11
|
-
msgType?: String
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class Snapshot implements ISnapshot {
|
|
15
|
-
id!: number
|
|
16
|
-
docChanges!: ISingleDBEvent[]
|
|
17
|
-
docs!: Record<string, any>[]
|
|
18
|
-
type?: 'init'
|
|
19
|
-
// EJSON: any
|
|
20
|
-
|
|
21
|
-
constructor(options: ISnapshotConstructorOptions) {
|
|
22
|
-
const { id, docChanges, docs, msgType, type } = options
|
|
23
|
-
|
|
24
|
-
let cachedDocChanges: ISingleDBEvent[]
|
|
25
|
-
let cachedDocs: Record<string, any>[]
|
|
26
|
-
|
|
27
|
-
Object.defineProperties(this, {
|
|
28
|
-
id: {
|
|
29
|
-
get: () => id,
|
|
30
|
-
enumerable: true
|
|
31
|
-
},
|
|
32
|
-
docChanges: {
|
|
33
|
-
get: () => {
|
|
34
|
-
if (!cachedDocChanges) {
|
|
35
|
-
cachedDocChanges = JSON.parse(JSON.stringify(docChanges))
|
|
36
|
-
}
|
|
37
|
-
return cachedDocChanges
|
|
38
|
-
},
|
|
39
|
-
enumerable: true
|
|
40
|
-
},
|
|
41
|
-
docs: {
|
|
42
|
-
get: () => {
|
|
43
|
-
if (!cachedDocs) {
|
|
44
|
-
cachedDocs = JSON.parse(JSON.stringify(docs))
|
|
45
|
-
}
|
|
46
|
-
return cachedDocs
|
|
47
|
-
},
|
|
48
|
-
enumerable: true
|
|
49
|
-
},
|
|
50
|
-
msgType: {
|
|
51
|
-
get: () => msgType,
|
|
52
|
-
enumerable: true
|
|
53
|
-
},
|
|
54
|
-
type: {
|
|
55
|
-
get: () => type,
|
|
56
|
-
enumerable: true
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
}
|
|
60
|
-
}
|