@cloudbase/database 0.9.22 → 0.10.0-alpha.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/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +101 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov.info +0 -0
- package/dist/commonjs/aggregate.js +3 -3
- package/dist/commonjs/collection.d.ts +1 -1
- package/dist/commonjs/collection.js +5 -2
- package/dist/commonjs/command.d.ts +5 -5
- package/dist/commonjs/command.js +9 -8
- package/dist/commonjs/commands/logic.js +3 -2
- package/dist/commonjs/commands/query.js +11 -8
- package/dist/commonjs/commands/update.js +1 -0
- 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 +1 -0
- package/dist/commonjs/document.js +11 -10
- package/dist/commonjs/geo/index.js +20 -9
- package/dist/commonjs/geo/lineString.d.ts +1 -1
- package/dist/commonjs/geo/lineString.js +7 -6
- package/dist/commonjs/geo/multiLineString.d.ts +1 -1
- package/dist/commonjs/geo/multiLineString.js +7 -6
- package/dist/commonjs/geo/multiPoint.d.ts +1 -1
- package/dist/commonjs/geo/multiPoint.js +7 -6
- package/dist/commonjs/geo/multiPolygon.d.ts +1 -1
- package/dist/commonjs/geo/multiPolygon.js +7 -6
- package/dist/commonjs/geo/point.d.ts +1 -1
- package/dist/commonjs/geo/point.js +4 -3
- package/dist/commonjs/geo/polygon.d.ts +1 -1
- package/dist/commonjs/geo/polygon.js +8 -7
- package/dist/commonjs/helper/symbol.js +16 -4
- package/dist/commonjs/index.d.ts +9 -2
- package/dist/commonjs/index.js +19 -4
- package/dist/commonjs/lib/util.js +4 -3
- package/dist/commonjs/operator-map.js +1 -0
- package/dist/commonjs/query.js +10 -9
- package/dist/commonjs/regexp/index.d.ts +1 -1
- package/dist/commonjs/regexp/index.js +2 -1
- package/dist/commonjs/serializer/common.d.ts +2 -2
- package/dist/commonjs/serializer/common.js +23 -17
- package/dist/commonjs/serializer/datatype.d.ts +2 -2
- package/dist/commonjs/serializer/datatype.js +20 -14
- package/dist/commonjs/serializer/query.d.ts +1 -1
- package/dist/commonjs/serializer/query.js +24 -23
- package/dist/commonjs/serializer/update.d.ts +1 -1
- package/dist/commonjs/serializer/update.js +12 -11
- package/dist/commonjs/serverDate/index.d.ts +1 -1
- package/dist/commonjs/serverDate/index.js +3 -2
- 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 +3 -2
- package/dist/commonjs/transaction/query.js +1 -0
- package/dist/commonjs/typings/index.d.ts +3 -3
- package/dist/commonjs/typings/realtime.d.ts +16 -16
- package/dist/commonjs/util.js +1 -0
- package/dist/commonjs/utils/error.d.ts +2 -1
- package/dist/commonjs/utils/error.js +15 -9
- package/dist/commonjs/utils/symbol.js +5 -4
- package/dist/commonjs/utils/type.d.ts +1 -1
- package/dist/commonjs/utils/type.js +23 -11
- package/dist/commonjs/utils/utils.js +6 -3
- package/dist/commonjs/validate.js +1 -0
- package/dist/esm/aggregate.d.ts.map +1 -0
- package/dist/esm/aggregate.js +3 -3
- package/dist/esm/collection.d.ts +1 -1
- package/dist/esm/collection.d.ts.map +1 -0
- package/dist/esm/collection.js +4 -2
- package/dist/esm/command.d.ts +5 -5
- package/dist/esm/command.d.ts.map +1 -0
- package/dist/esm/commands/logic.d.ts.map +1 -0
- package/dist/esm/commands/query.d.ts.map +1 -0
- package/dist/esm/commands/query.js +8 -6
- package/dist/esm/commands/update.d.ts.map +1 -0
- package/dist/esm/config/app.config.d.ts.map +1 -0
- package/dist/esm/config/error.config.d.ts.map +1 -0
- package/dist/esm/const/code.d.ts.map +1 -0
- package/dist/esm/constant.d.ts +7 -7
- package/dist/esm/constant.d.ts.map +1 -0
- package/dist/esm/document.d.ts.map +1 -0
- package/dist/esm/document.js +2 -2
- package/dist/esm/geo/index.d.ts.map +1 -0
- package/dist/esm/geo/interface.d.ts.map +1 -0
- package/dist/esm/geo/interface.js +1 -0
- package/dist/esm/geo/lineString.d.ts +1 -1
- package/dist/esm/geo/lineString.d.ts.map +1 -0
- package/dist/esm/geo/lineString.js +3 -3
- package/dist/esm/geo/multiLineString.d.ts +1 -1
- package/dist/esm/geo/multiLineString.d.ts.map +1 -0
- package/dist/esm/geo/multiLineString.js +3 -3
- package/dist/esm/geo/multiPoint.d.ts +1 -1
- package/dist/esm/geo/multiPoint.d.ts.map +1 -0
- package/dist/esm/geo/multiPoint.js +3 -3
- package/dist/esm/geo/multiPolygon.d.ts +1 -1
- package/dist/esm/geo/multiPolygon.d.ts.map +1 -0
- package/dist/esm/geo/multiPolygon.js +3 -3
- package/dist/esm/geo/point.d.ts +1 -1
- package/dist/esm/geo/point.d.ts.map +1 -0
- package/dist/esm/geo/point.js +2 -2
- package/dist/esm/geo/polygon.d.ts +1 -1
- package/dist/esm/geo/polygon.d.ts.map +1 -0
- package/dist/esm/geo/polygon.js +4 -4
- package/dist/esm/helper/symbol.d.ts.map +1 -0
- package/dist/esm/index.d.ts +9 -2
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +15 -1
- package/dist/esm/lib/util.d.ts.map +1 -0
- package/dist/esm/lib/util.js +1 -2
- package/dist/esm/operator-map.d.ts.map +1 -0
- package/dist/esm/query.d.ts.map +1 -0
- package/dist/esm/query.js +4 -4
- package/dist/esm/regexp/index.d.ts +1 -1
- package/dist/esm/regexp/index.d.ts.map +1 -0
- package/dist/esm/regexp/index.js +1 -1
- package/dist/esm/serializer/common.d.ts +2 -2
- package/dist/esm/serializer/common.d.ts.map +1 -0
- package/dist/esm/serializer/common.js +15 -10
- package/dist/esm/serializer/datatype.d.ts +2 -2
- package/dist/esm/serializer/datatype.d.ts.map +1 -0
- package/dist/esm/serializer/datatype.js +12 -7
- package/dist/esm/serializer/query.d.ts +1 -1
- package/dist/esm/serializer/query.d.ts.map +1 -0
- package/dist/esm/serializer/query.js +2 -2
- package/dist/esm/serializer/update.d.ts +1 -1
- package/dist/esm/serializer/update.d.ts.map +1 -0
- package/dist/esm/serverDate/index.d.ts +1 -1
- package/dist/esm/serverDate/index.d.ts.map +1 -0
- package/dist/esm/serverDate/index.js +2 -2
- package/dist/esm/transaction/collection.d.ts +1 -1
- package/dist/esm/transaction/collection.d.ts.map +1 -0
- package/dist/esm/transaction/collection.js +4 -2
- package/dist/esm/transaction/document.d.ts +1 -1
- package/dist/esm/transaction/document.d.ts.map +1 -0
- package/dist/esm/transaction/document.js +2 -3
- package/dist/esm/transaction/index.d.ts.map +1 -0
- package/dist/esm/transaction/index.js +2 -2
- package/dist/esm/transaction/query.d.ts.map +1 -0
- package/dist/esm/typings/index.d.ts +3 -3
- package/dist/esm/typings/index.d.ts.map +1 -0
- package/dist/esm/typings/index.js +1 -0
- package/dist/esm/typings/realtime.d.ts +16 -16
- package/dist/esm/typings/realtime.d.ts.map +1 -0
- package/dist/esm/typings/realtime.js +1 -0
- package/dist/esm/util.d.ts.map +1 -0
- package/dist/esm/utils/error.d.ts +2 -1
- package/dist/esm/utils/error.d.ts.map +1 -0
- package/dist/esm/utils/error.js +7 -5
- package/dist/esm/utils/msg.d.ts.map +1 -0
- package/dist/esm/utils/symbol.d.ts.map +1 -0
- package/dist/esm/utils/symbol.js +4 -4
- package/dist/esm/utils/type.d.ts +1 -1
- package/dist/esm/utils/type.d.ts.map +1 -0
- package/dist/esm/utils/utils.d.ts.map +1 -0
- package/dist/esm/utils/utils.js +1 -1
- package/dist/esm/validate.d.ts.map +1 -0
- package/jest.config.js +14 -0
- package/package.json +9 -4
- package/src/aggregate.ts +1 -1
- package/src/document.ts +1 -1
- package/src/index.ts +40 -4
- package/src/lib/util.ts +1 -2
- package/src/query.ts +4 -4
- package/src/transaction/index.ts +1 -1
- package/src/utils/utils.ts +1 -1
- package/tests/index.test.ts +111 -0
- package/tsconfig.esm.json +2 -1
- package/tsconfig.json +14 -5
- package/tsconfig.test.json +15 -0
- package/.trunk/configs/.markdownlint.yaml +0 -10
- package/.trunk/trunk.yaml +0 -26
|
@@ -11,14 +11,15 @@ var __values = (this && this.__values) || function(o) {
|
|
|
11
11
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.MultiPolygon = void 0;
|
|
14
15
|
var symbol_1 = require("../helper/symbol");
|
|
15
16
|
var type_1 = require("../utils/type");
|
|
16
17
|
var polygon_1 = require("./polygon");
|
|
17
18
|
var MultiPolygon = (function () {
|
|
18
19
|
function MultiPolygon(polygons) {
|
|
19
20
|
var e_1, _a;
|
|
20
|
-
if (!type_1.isArray(polygons)) {
|
|
21
|
-
throw new TypeError("\"polygons\" must be of type Polygon[]. Received type "
|
|
21
|
+
if (!(0, type_1.isArray)(polygons)) {
|
|
22
|
+
throw new TypeError("\"polygons\" must be of type Polygon[]. Received type ".concat(typeof polygons));
|
|
22
23
|
}
|
|
23
24
|
if (polygons.length === 0) {
|
|
24
25
|
throw new Error('MultiPolygon must contain 1 polygon at least');
|
|
@@ -27,7 +28,7 @@ var MultiPolygon = (function () {
|
|
|
27
28
|
for (var polygons_1 = __values(polygons), polygons_1_1 = polygons_1.next(); !polygons_1_1.done; polygons_1_1 = polygons_1.next()) {
|
|
28
29
|
var polygon = polygons_1_1.value;
|
|
29
30
|
if (!(polygon instanceof polygon_1.Polygon)) {
|
|
30
|
-
throw new TypeError("\"polygon\" must be of type Polygon[]. Received type "
|
|
31
|
+
throw new TypeError("\"polygon\" must be of type Polygon[]. Received type ".concat(typeof polygon, "[]"));
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
}
|
|
@@ -65,7 +66,7 @@ var MultiPolygon = (function () {
|
|
|
65
66
|
};
|
|
66
67
|
MultiPolygon.validate = function (multiPolygon) {
|
|
67
68
|
var e_2, _a, e_3, _b, e_4, _c;
|
|
68
|
-
if (multiPolygon.type !== 'MultiPolygon' || !type_1.isArray(multiPolygon.coordinates)) {
|
|
69
|
+
if (multiPolygon.type !== 'MultiPolygon' || !(0, type_1.isArray)(multiPolygon.coordinates)) {
|
|
69
70
|
return false;
|
|
70
71
|
}
|
|
71
72
|
try {
|
|
@@ -77,7 +78,7 @@ var MultiPolygon = (function () {
|
|
|
77
78
|
try {
|
|
78
79
|
for (var line_1 = (e_4 = void 0, __values(line)), line_1_1 = line_1.next(); !line_1_1.done; line_1_1 = line_1.next()) {
|
|
79
80
|
var point = line_1_1.value;
|
|
80
|
-
if (!type_1.isNumber(point[0]) || !type_1.isNumber(point[1])) {
|
|
81
|
+
if (!(0, type_1.isNumber)(point[0]) || !(0, type_1.isNumber)(point[1])) {
|
|
81
82
|
return false;
|
|
82
83
|
}
|
|
83
84
|
}
|
|
@@ -113,7 +114,7 @@ var MultiPolygon = (function () {
|
|
|
113
114
|
get: function () {
|
|
114
115
|
return symbol_1.SYMBOL_GEO_POLYGON;
|
|
115
116
|
},
|
|
116
|
-
enumerable:
|
|
117
|
+
enumerable: false,
|
|
117
118
|
configurable: true
|
|
118
119
|
});
|
|
119
120
|
return MultiPolygon;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Point = void 0;
|
|
3
4
|
var validate_1 = require("../validate");
|
|
4
5
|
var symbol_1 = require("../helper/symbol");
|
|
5
6
|
var type_1 = require("../utils/type");
|
|
@@ -29,11 +30,11 @@ var Point = (function () {
|
|
|
29
30
|
};
|
|
30
31
|
};
|
|
31
32
|
Point.prototype.toReadableString = function () {
|
|
32
|
-
return "["
|
|
33
|
+
return "[".concat(this.longitude, ",").concat(this.latitude, "]");
|
|
33
34
|
};
|
|
34
35
|
Point.validate = function (point) {
|
|
35
36
|
return point.type === 'Point' &&
|
|
36
|
-
type_1.isArray(point.coordinates) &&
|
|
37
|
+
(0, type_1.isArray)(point.coordinates) &&
|
|
37
38
|
validate_1.Validate.isGeopoint('longitude', point.coordinates[0]) &&
|
|
38
39
|
validate_1.Validate.isGeopoint('latitude', point.coordinates[1]);
|
|
39
40
|
};
|
|
@@ -41,7 +42,7 @@ var Point = (function () {
|
|
|
41
42
|
get: function () {
|
|
42
43
|
return symbol_1.SYMBOL_GEO_POINT;
|
|
43
44
|
},
|
|
44
|
-
enumerable:
|
|
45
|
+
enumerable: false,
|
|
45
46
|
configurable: true
|
|
46
47
|
});
|
|
47
48
|
return Point;
|
|
@@ -15,5 +15,5 @@ export declare class Polygon {
|
|
|
15
15
|
};
|
|
16
16
|
static validate(polygon: ISerializedPolygon): boolean;
|
|
17
17
|
static isCloseLineString(lineString: any): boolean;
|
|
18
|
-
|
|
18
|
+
get _internalType(): import("../utils/symbol").InternalSymbol;
|
|
19
19
|
}
|
|
@@ -11,23 +11,24 @@ var __values = (this && this.__values) || function(o) {
|
|
|
11
11
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.Polygon = void 0;
|
|
14
15
|
var symbol_1 = require("../helper/symbol");
|
|
15
16
|
var type_1 = require("../utils/type");
|
|
16
17
|
var lineString_1 = require("./lineString");
|
|
17
18
|
var Polygon = (function () {
|
|
18
19
|
function Polygon(lines) {
|
|
19
|
-
if (!type_1.isArray(lines)) {
|
|
20
|
-
throw new TypeError("\"lines\" must be of type LineString[]. Received type "
|
|
20
|
+
if (!(0, type_1.isArray)(lines)) {
|
|
21
|
+
throw new TypeError("\"lines\" must be of type LineString[]. Received type ".concat(typeof lines));
|
|
21
22
|
}
|
|
22
23
|
if (lines.length === 0) {
|
|
23
24
|
throw new Error('Polygon must contain 1 linestring at least');
|
|
24
25
|
}
|
|
25
26
|
lines.forEach(function (line) {
|
|
26
27
|
if (!(line instanceof lineString_1.LineString)) {
|
|
27
|
-
throw new TypeError("\"lines\" must be of type LineString[]. Received type "
|
|
28
|
+
throw new TypeError("\"lines\" must be of type LineString[]. Received type ".concat(typeof line, "[]"));
|
|
28
29
|
}
|
|
29
30
|
if (!lineString_1.LineString.isClosed(line)) {
|
|
30
|
-
throw new Error("LineString "
|
|
31
|
+
throw new Error("LineString ".concat(line.points.map(function (p) { return p.toReadableString(); }), " is not a closed cycle"));
|
|
31
32
|
}
|
|
32
33
|
});
|
|
33
34
|
this.lines = lines;
|
|
@@ -53,7 +54,7 @@ var Polygon = (function () {
|
|
|
53
54
|
};
|
|
54
55
|
Polygon.validate = function (polygon) {
|
|
55
56
|
var e_1, _a, e_2, _b;
|
|
56
|
-
if (polygon.type !== 'Polygon' || !type_1.isArray(polygon.coordinates)) {
|
|
57
|
+
if (polygon.type !== 'Polygon' || !(0, type_1.isArray)(polygon.coordinates)) {
|
|
57
58
|
return false;
|
|
58
59
|
}
|
|
59
60
|
try {
|
|
@@ -65,7 +66,7 @@ var Polygon = (function () {
|
|
|
65
66
|
try {
|
|
66
67
|
for (var line_1 = (e_2 = void 0, __values(line)), line_1_1 = line_1.next(); !line_1_1.done; line_1_1 = line_1.next()) {
|
|
67
68
|
var point = line_1_1.value;
|
|
68
|
-
if (!type_1.isNumber(point[0]) || !type_1.isNumber(point[1])) {
|
|
69
|
+
if (!(0, type_1.isNumber)(point[0]) || !(0, type_1.isNumber)(point[1])) {
|
|
69
70
|
return false;
|
|
70
71
|
}
|
|
71
72
|
}
|
|
@@ -100,7 +101,7 @@ var Polygon = (function () {
|
|
|
100
101
|
get: function () {
|
|
101
102
|
return symbol_1.SYMBOL_GEO_MULTI_POLYGON;
|
|
102
103
|
},
|
|
103
|
-
enumerable:
|
|
104
|
+
enumerable: false,
|
|
104
105
|
configurable: true
|
|
105
106
|
});
|
|
106
107
|
return Polygon;
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
5
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.SYMBOL_REGEXP = exports.SYMBOL_SERVER_DATE = exports.SYMBOL_GEO_MULTI_POLYGON = exports.SYMBOL_GEO_MULTI_LINE_STRING = exports.SYMBOL_GEO_MULTI_POINT = exports.SYMBOL_GEO_POLYGON = exports.SYMBOL_GEO_LINE_STRING = exports.SYMBOL_GEO_POINT = exports.SYMBOL_LOGIC_COMMAND = exports.SYMBOL_QUERY_COMMAND = exports.SYMBOL_UPDATE_COMMAND = exports.SYMBOL_UNSET_FIELD_NAME = void 0;
|
|
6
18
|
var symbol_1 = require("../utils/symbol");
|
|
7
|
-
|
|
19
|
+
__exportStar(require("../utils/symbol"), exports);
|
|
8
20
|
exports.SYMBOL_UNSET_FIELD_NAME = symbol_1.default.for('UNSET_FIELD_NAME');
|
|
9
21
|
exports.SYMBOL_UPDATE_COMMAND = symbol_1.default.for('UPDATE_COMMAND');
|
|
10
22
|
exports.SYMBOL_QUERY_COMMAND = symbol_1.default.for('QUERY_COMMAND');
|
package/dist/commonjs/index.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { Point } from './geo/point';
|
|
2
2
|
import { CollectionReference } from './collection';
|
|
3
3
|
import { Command } from './command';
|
|
4
|
+
export interface IDbConfig {
|
|
5
|
+
env?: string;
|
|
6
|
+
instance?: string;
|
|
7
|
+
database?: string;
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
4
10
|
interface GeoTeyp {
|
|
5
11
|
Point: typeof Point;
|
|
6
12
|
}
|
|
@@ -17,7 +23,7 @@ export declare class Db {
|
|
|
17
23
|
logicCommand: any;
|
|
18
24
|
updateCommand: any;
|
|
19
25
|
queryCommand: any;
|
|
20
|
-
config:
|
|
26
|
+
config: IDbConfig;
|
|
21
27
|
static ws: any;
|
|
22
28
|
static reqClass: any;
|
|
23
29
|
static wsClass: any;
|
|
@@ -27,7 +33,8 @@ export declare class Db {
|
|
|
27
33
|
static dataVersion: string;
|
|
28
34
|
static runtime: string;
|
|
29
35
|
static appSecretInfo: any;
|
|
30
|
-
|
|
36
|
+
static createRequest(config: IDbConfig): any;
|
|
37
|
+
constructor(config?: IDbConfig);
|
|
31
38
|
collection(collName: string): CollectionReference;
|
|
32
39
|
createCollection(collName: string): any;
|
|
33
40
|
}
|
package/dist/commonjs/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Db = exports.DocumentReference = exports.CollectionReference = exports.Query = void 0;
|
|
3
4
|
var Geo = require("./geo/index");
|
|
4
5
|
var collection_1 = require("./collection");
|
|
5
6
|
var command_1 = require("./command");
|
|
@@ -10,11 +11,11 @@ var logic_1 = require("./commands/logic");
|
|
|
10
11
|
var query_1 = require("./commands/query");
|
|
11
12
|
var update_1 = require("./commands/update");
|
|
12
13
|
var query_2 = require("./query");
|
|
13
|
-
exports
|
|
14
|
+
Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return query_2.Query; } });
|
|
14
15
|
var collection_2 = require("./collection");
|
|
15
|
-
exports
|
|
16
|
+
Object.defineProperty(exports, "CollectionReference", { enumerable: true, get: function () { return collection_2.CollectionReference; } });
|
|
16
17
|
var document_1 = require("./document");
|
|
17
|
-
exports
|
|
18
|
+
Object.defineProperty(exports, "DocumentReference", { enumerable: true, get: function () { return document_1.DocumentReference; } });
|
|
18
19
|
var Db = (function () {
|
|
19
20
|
function Db(config) {
|
|
20
21
|
this.config = config;
|
|
@@ -28,6 +29,20 @@ var Db = (function () {
|
|
|
28
29
|
this.updateCommand = update_1.UpdateCommand;
|
|
29
30
|
this.queryCommand = query_1.QueryCommand;
|
|
30
31
|
}
|
|
32
|
+
Db.createRequest = function (config) {
|
|
33
|
+
var request = new Db.reqClass(config);
|
|
34
|
+
var originalSend = request.send;
|
|
35
|
+
request.send = function (action, data) {
|
|
36
|
+
if (config.instance) {
|
|
37
|
+
data.instance = config.instance;
|
|
38
|
+
}
|
|
39
|
+
if (config.database) {
|
|
40
|
+
data.database = config.database;
|
|
41
|
+
}
|
|
42
|
+
return originalSend.call(this, action, data);
|
|
43
|
+
};
|
|
44
|
+
return request;
|
|
45
|
+
};
|
|
31
46
|
Db.prototype.collection = function (collName) {
|
|
32
47
|
if (!collName) {
|
|
33
48
|
throw new Error('Collection name is required');
|
|
@@ -35,7 +50,7 @@ var Db = (function () {
|
|
|
35
50
|
return new collection_1.CollectionReference(this, collName);
|
|
36
51
|
};
|
|
37
52
|
Db.prototype.createCollection = function (collName) {
|
|
38
|
-
var request =
|
|
53
|
+
var request = Db.createRequest(this.config);
|
|
39
54
|
var params = {
|
|
40
55
|
collectionName: collName
|
|
41
56
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createPromiseCallback =
|
|
4
|
-
|
|
3
|
+
exports.createPromiseCallback = void 0;
|
|
4
|
+
var createPromiseCallback = function () {
|
|
5
|
+
var cb = function () { };
|
|
5
6
|
if (!Promise) {
|
|
6
|
-
cb = function () { };
|
|
7
7
|
cb.promise = {};
|
|
8
8
|
var throwPromiseNotDefined = function () {
|
|
9
9
|
throw new Error('Your Node runtime does support ES6 Promises. ' +
|
|
@@ -23,3 +23,4 @@ exports.createPromiseCallback = function () {
|
|
|
23
23
|
cb.promise = promise;
|
|
24
24
|
return cb;
|
|
25
25
|
};
|
|
26
|
+
exports.createPromiseCallback = createPromiseCallback;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.operatorToString = exports.OperatorMap = void 0;
|
|
3
4
|
var query_1 = require("./commands/query");
|
|
4
5
|
var logic_1 = require("./commands/logic");
|
|
5
6
|
var update_1 = require("./commands/update");
|
package/dist/commonjs/query.js
CHANGED
|
@@ -11,6 +11,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.Query = void 0;
|
|
14
15
|
var util_1 = require("./lib/util");
|
|
15
16
|
var constant_1 = require("./constant");
|
|
16
17
|
var index_1 = require("./index");
|
|
@@ -24,7 +25,7 @@ var Query = (function () {
|
|
|
24
25
|
function Query(db, coll, fieldFilters, fieldOrders, queryOptions) {
|
|
25
26
|
var _this = this;
|
|
26
27
|
this.watch = function (options) {
|
|
27
|
-
var ws = utils_1.getWsInstance(_this._db);
|
|
28
|
+
var ws = (0, utils_1.getWsInstance)(_this._db);
|
|
28
29
|
return ws.watch(__assign(__assign({}, options), { envId: _this._db.config.env, collectionName: _this._coll, query: JSON.stringify(_this._fieldFilters || {}), limit: _this._queryOptions.limit, orderBy: _this._fieldOrders
|
|
29
30
|
? _this._fieldOrders.reduce(function (acc, cur) {
|
|
30
31
|
acc[cur.field] = cur.direction;
|
|
@@ -37,10 +38,10 @@ var Query = (function () {
|
|
|
37
38
|
this._fieldFilters = fieldFilters;
|
|
38
39
|
this._fieldOrders = fieldOrders || [];
|
|
39
40
|
this._queryOptions = queryOptions || {};
|
|
40
|
-
this._request =
|
|
41
|
+
this._request = index_1.Db.createRequest(this._db.config);
|
|
41
42
|
}
|
|
42
43
|
Query.prototype.get = function (callback) {
|
|
43
|
-
callback = callback || util_1.createPromiseCallback();
|
|
44
|
+
callback = callback || (0, util_1.createPromiseCallback)();
|
|
44
45
|
var newOder = [];
|
|
45
46
|
if (this._fieldOrders) {
|
|
46
47
|
this._fieldOrders.forEach(function (order) {
|
|
@@ -81,11 +82,11 @@ var Query = (function () {
|
|
|
81
82
|
data: documents,
|
|
82
83
|
requestId: res.requestId
|
|
83
84
|
};
|
|
84
|
-
if (res.total)
|
|
85
|
+
if (res.total !== undefined)
|
|
85
86
|
result.total = res.total;
|
|
86
|
-
if (res.limit)
|
|
87
|
+
if (res.limit !== undefined)
|
|
87
88
|
result.limit = res.limit;
|
|
88
|
-
if (res.offset)
|
|
89
|
+
if (res.offset !== undefined)
|
|
89
90
|
result.offset = res.offset;
|
|
90
91
|
callback(0, result);
|
|
91
92
|
}
|
|
@@ -96,7 +97,7 @@ var Query = (function () {
|
|
|
96
97
|
return callback.promise;
|
|
97
98
|
};
|
|
98
99
|
Query.prototype.count = function (callback) {
|
|
99
|
-
callback = callback || util_1.createPromiseCallback();
|
|
100
|
+
callback = callback || (0, util_1.createPromiseCallback)();
|
|
100
101
|
var param = {
|
|
101
102
|
collectionName: this._coll,
|
|
102
103
|
queryType: constant_1.QueryType.WHERE
|
|
@@ -158,7 +159,7 @@ var Query = (function () {
|
|
|
158
159
|
return new Query(this._db, this._coll, this._fieldFilters, this._fieldOrders, option);
|
|
159
160
|
};
|
|
160
161
|
Query.prototype.update = function (data, callback) {
|
|
161
|
-
callback = callback || util_1.createPromiseCallback();
|
|
162
|
+
callback = callback || (0, util_1.createPromiseCallback)();
|
|
162
163
|
if (!data || typeof data !== 'object') {
|
|
163
164
|
return Promise.resolve({
|
|
164
165
|
code: 'INVALID_PARAM',
|
|
@@ -215,7 +216,7 @@ var Query = (function () {
|
|
|
215
216
|
return new Query(this._db, this._coll, this._fieldFilters, this._fieldOrders, option);
|
|
216
217
|
};
|
|
217
218
|
Query.prototype.remove = function (callback) {
|
|
218
|
-
callback = callback || util_1.createPromiseCallback();
|
|
219
|
+
callback = callback || (0, util_1.createPromiseCallback)();
|
|
219
220
|
if (Object.keys(this._queryOptions).length > 0) {
|
|
220
221
|
console.warn('`offset`, `limit` and `projection` are not supported in remove() operation');
|
|
221
222
|
}
|
|
@@ -9,6 +9,6 @@ export declare class RegExp {
|
|
|
9
9
|
$regex: string;
|
|
10
10
|
$options: string;
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
get _internalType(): import("../utils/symbol").InternalSymbol;
|
|
13
13
|
}
|
|
14
14
|
export declare function RegExpConstructor(param: any): RegExp;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RegExpConstructor = exports.RegExp = void 0;
|
|
3
4
|
var symbol_1 = require("../helper/symbol");
|
|
4
5
|
var RegExp = (function () {
|
|
5
6
|
function RegExp(_a) {
|
|
@@ -20,7 +21,7 @@ var RegExp = (function () {
|
|
|
20
21
|
get: function () {
|
|
21
22
|
return symbol_1.SYMBOL_REGEXP;
|
|
22
23
|
},
|
|
23
|
-
enumerable:
|
|
24
|
+
enumerable: false,
|
|
24
25
|
configurable: true
|
|
25
26
|
});
|
|
26
27
|
return RegExp;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LogicCommand } from '../commands/logic';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export type IQueryCondition = Record<string, any> | LogicCommand;
|
|
3
|
+
export type AnyObject = {
|
|
4
4
|
[x: string]: any;
|
|
5
5
|
};
|
|
6
6
|
export declare function flattenQueryObject(query: Record<string, any>): Record<string, any>;
|
|
@@ -26,11 +26,17 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
26
26
|
}
|
|
27
27
|
return ar;
|
|
28
28
|
};
|
|
29
|
-
var
|
|
30
|
-
for (var
|
|
31
|
-
|
|
29
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
+
if (ar || !(i in from)) {
|
|
32
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
+
ar[i] = from[i];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
32
37
|
};
|
|
33
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.decodeInternalDataType = exports.encodeInternalDataType = exports.isConversionRequired = exports.mergeConditionAfterEncode = exports.flattenObject = exports.flattenQueryObject = void 0;
|
|
34
40
|
var type_1 = require("../utils/type");
|
|
35
41
|
var datatype_1 = require("./datatype");
|
|
36
42
|
function flatten(query, shouldPreserverObject, parents, visited) {
|
|
@@ -41,22 +47,22 @@ function flatten(query, shouldPreserverObject, parents, visited) {
|
|
|
41
47
|
var value = query[key];
|
|
42
48
|
if (!value)
|
|
43
49
|
continue;
|
|
44
|
-
if (type_1.isObject(value) && !shouldPreserverObject(value)) {
|
|
50
|
+
if ((0, type_1.isObject)(value) && !shouldPreserverObject(value)) {
|
|
45
51
|
if (visited.indexOf(value) > -1) {
|
|
46
52
|
throw new Error('Cannot convert circular structure to JSON');
|
|
47
53
|
}
|
|
48
|
-
var newParents =
|
|
54
|
+
var newParents = __spreadArray(__spreadArray([], __read(parents), false), [
|
|
49
55
|
key,
|
|
50
|
-
]);
|
|
51
|
-
var newVisited =
|
|
56
|
+
], false);
|
|
57
|
+
var newVisited = __spreadArray(__spreadArray([], __read(visited), false), [
|
|
52
58
|
value,
|
|
53
|
-
]);
|
|
59
|
+
], false);
|
|
54
60
|
var flattenedChild = flatten(value, shouldPreserverObject, newParents, newVisited);
|
|
55
61
|
cloned[key] = flattenedChild;
|
|
56
62
|
var hasKeyNotCombined = false;
|
|
57
63
|
for (var childKey in flattenedChild) {
|
|
58
64
|
if (!/^\$/.test(childKey)) {
|
|
59
|
-
cloned[key
|
|
65
|
+
cloned["".concat(key, ".").concat(childKey)] = flattenedChild[childKey];
|
|
60
66
|
delete cloned[key][childKey];
|
|
61
67
|
}
|
|
62
68
|
else {
|
|
@@ -84,20 +90,20 @@ function mergeConditionAfterEncode(query, condition, key) {
|
|
|
84
90
|
}
|
|
85
91
|
for (var conditionKey in condition) {
|
|
86
92
|
if (query[conditionKey]) {
|
|
87
|
-
if (type_1.isArray(query[conditionKey])) {
|
|
93
|
+
if ((0, type_1.isArray)(query[conditionKey])) {
|
|
88
94
|
query[conditionKey].push(condition[conditionKey]);
|
|
89
95
|
}
|
|
90
|
-
else if (type_1.isObject(query[conditionKey])) {
|
|
91
|
-
if (type_1.isObject(condition[conditionKey])) {
|
|
96
|
+
else if ((0, type_1.isObject)(query[conditionKey])) {
|
|
97
|
+
if ((0, type_1.isObject)(condition[conditionKey])) {
|
|
92
98
|
Object.assign(query[conditionKey], condition[conditionKey]);
|
|
93
99
|
}
|
|
94
100
|
else {
|
|
95
|
-
console.warn("unmergable condition, query is object but condition is "
|
|
101
|
+
console.warn("unmergable condition, query is object but condition is ".concat((0, type_1.getType)(condition), ", can only overwrite"), condition, key);
|
|
96
102
|
query[conditionKey] = condition[conditionKey];
|
|
97
103
|
}
|
|
98
104
|
}
|
|
99
105
|
else {
|
|
100
|
-
console.warn("to-merge query is of type "
|
|
106
|
+
console.warn("to-merge query is of type ".concat((0, type_1.getType)(query), ", can only overwrite"), query, condition, key);
|
|
101
107
|
query[conditionKey] = condition[conditionKey];
|
|
102
108
|
}
|
|
103
109
|
}
|
|
@@ -108,14 +114,14 @@ function mergeConditionAfterEncode(query, condition, key) {
|
|
|
108
114
|
}
|
|
109
115
|
exports.mergeConditionAfterEncode = mergeConditionAfterEncode;
|
|
110
116
|
function isConversionRequired(val) {
|
|
111
|
-
return type_1.isInternalObject(val) || type_1.isDate(val) || type_1.isRegExp(val);
|
|
117
|
+
return (0, type_1.isInternalObject)(val) || (0, type_1.isDate)(val) || (0, type_1.isRegExp)(val);
|
|
112
118
|
}
|
|
113
119
|
exports.isConversionRequired = isConversionRequired;
|
|
114
120
|
function encodeInternalDataType(val) {
|
|
115
|
-
return datatype_1.serialize(val);
|
|
121
|
+
return (0, datatype_1.serialize)(val);
|
|
116
122
|
}
|
|
117
123
|
exports.encodeInternalDataType = encodeInternalDataType;
|
|
118
124
|
function decodeInternalDataType(object) {
|
|
119
|
-
return datatype_1.deserialize(object);
|
|
125
|
+
return (0, datatype_1.deserialize)(object);
|
|
120
126
|
}
|
|
121
127
|
exports.decodeInternalDataType = decodeInternalDataType;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LogicCommand } from '../commands/logic';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export type IQueryCondition = Record<string, any> | LogicCommand;
|
|
3
|
+
export type AnyObject = {
|
|
4
4
|
[x: string]: any;
|
|
5
5
|
};
|
|
6
6
|
export declare function serialize(val: any): IQueryCondition;
|
|
@@ -26,11 +26,17 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
26
26
|
}
|
|
27
27
|
return ar;
|
|
28
28
|
};
|
|
29
|
-
var
|
|
30
|
-
for (var
|
|
31
|
-
|
|
29
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
+
if (ar || !(i in from)) {
|
|
32
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
+
ar[i] = from[i];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
32
37
|
};
|
|
33
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.deserialize = exports.serialize = void 0;
|
|
34
40
|
var symbol_1 = require("../helper/symbol");
|
|
35
41
|
var type_1 = require("../utils/type");
|
|
36
42
|
var index_1 = require("../geo/index");
|
|
@@ -40,7 +46,7 @@ function serialize(val) {
|
|
|
40
46
|
}
|
|
41
47
|
exports.serialize = serialize;
|
|
42
48
|
function serializeHelper(val, visited) {
|
|
43
|
-
if (type_1.isInternalObject(val)) {
|
|
49
|
+
if ((0, type_1.isInternalObject)(val)) {
|
|
44
50
|
switch (val._internalType) {
|
|
45
51
|
case symbol_1.SYMBOL_GEO_POINT: {
|
|
46
52
|
return val.toJSON();
|
|
@@ -56,36 +62,36 @@ function serializeHelper(val, visited) {
|
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
64
|
}
|
|
59
|
-
else if (type_1.isDate(val)) {
|
|
65
|
+
else if ((0, type_1.isDate)(val)) {
|
|
60
66
|
return {
|
|
61
67
|
$date: +val,
|
|
62
68
|
};
|
|
63
69
|
}
|
|
64
|
-
else if (type_1.isRegExp(val)) {
|
|
70
|
+
else if ((0, type_1.isRegExp)(val)) {
|
|
65
71
|
return {
|
|
66
72
|
$regex: val.source,
|
|
67
73
|
$options: val.flags,
|
|
68
74
|
};
|
|
69
75
|
}
|
|
70
|
-
else if (type_1.isArray(val)) {
|
|
76
|
+
else if ((0, type_1.isArray)(val)) {
|
|
71
77
|
return val.map(function (item) {
|
|
72
78
|
if (visited.indexOf(item) > -1) {
|
|
73
79
|
throw new Error('Cannot convert circular structure to JSON');
|
|
74
80
|
}
|
|
75
|
-
return serializeHelper(item,
|
|
81
|
+
return serializeHelper(item, __spreadArray(__spreadArray([], __read(visited), false), [
|
|
76
82
|
item,
|
|
77
|
-
]));
|
|
83
|
+
], false));
|
|
78
84
|
});
|
|
79
85
|
}
|
|
80
|
-
else if (type_1.isObject(val)) {
|
|
86
|
+
else if ((0, type_1.isObject)(val)) {
|
|
81
87
|
var ret = __assign({}, val);
|
|
82
88
|
for (var key in ret) {
|
|
83
89
|
if (visited.indexOf(ret[key]) > -1) {
|
|
84
90
|
throw new Error('Cannot convert circular structure to JSON');
|
|
85
91
|
}
|
|
86
|
-
ret[key] = serializeHelper(ret[key],
|
|
92
|
+
ret[key] = serializeHelper(ret[key], __spreadArray(__spreadArray([], __read(visited), false), [
|
|
87
93
|
ret[key],
|
|
88
|
-
]));
|
|
94
|
+
], false));
|
|
89
95
|
}
|
|
90
96
|
return ret;
|
|
91
97
|
}
|
|
@@ -98,7 +104,7 @@ function deserialize(object) {
|
|
|
98
104
|
for (var key in ret) {
|
|
99
105
|
switch (key) {
|
|
100
106
|
case '$date': {
|
|
101
|
-
switch (type_1.getType(ret[key])) {
|
|
107
|
+
switch ((0, type_1.getType)(ret[key])) {
|
|
102
108
|
case 'number': {
|
|
103
109
|
return new Date(ret[key]);
|
|
104
110
|
}
|
|
@@ -111,7 +117,7 @@ function deserialize(object) {
|
|
|
111
117
|
case 'type': {
|
|
112
118
|
switch (ret.type) {
|
|
113
119
|
case 'Point': {
|
|
114
|
-
if (type_1.isArray(ret.coordinates) && type_1.isNumber(ret.coordinates[0]) && type_1.isNumber(ret.coordinates[1])) {
|
|
120
|
+
if ((0, type_1.isArray)(ret.coordinates) && (0, type_1.isNumber)(ret.coordinates[0]) && (0, type_1.isNumber)(ret.coordinates[1])) {
|
|
115
121
|
return new index_1.Point(ret.coordinates[0], ret.coordinates[1]);
|
|
116
122
|
}
|
|
117
123
|
break;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { QueryCommand } from '../commands/query';
|
|
2
2
|
import { LogicCommand } from '../commands/logic';
|
|
3
|
-
export
|
|
3
|
+
export type IQueryCondition = Record<string, any> | LogicCommand;
|
|
4
4
|
export declare class QuerySerializer {
|
|
5
5
|
constructor();
|
|
6
6
|
static encode(query: IQueryCondition | QueryCommand | LogicCommand): IQueryCondition;
|