@cloudbase/database 0.9.22 → 0.10.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.
Files changed (176) hide show
  1. package/coverage/lcov-report/base.css +224 -0
  2. package/coverage/lcov-report/block-navigation.js +87 -0
  3. package/coverage/lcov-report/favicon.png +0 -0
  4. package/coverage/lcov-report/index.html +101 -0
  5. package/coverage/lcov-report/prettify.css +1 -0
  6. package/coverage/lcov-report/prettify.js +2 -0
  7. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  8. package/coverage/lcov-report/sorter.js +210 -0
  9. package/coverage/lcov.info +0 -0
  10. package/dist/commonjs/aggregate.js +3 -3
  11. package/dist/commonjs/collection.d.ts +1 -1
  12. package/dist/commonjs/collection.js +5 -2
  13. package/dist/commonjs/command.d.ts +5 -5
  14. package/dist/commonjs/command.js +9 -8
  15. package/dist/commonjs/commands/logic.js +3 -2
  16. package/dist/commonjs/commands/query.js +11 -8
  17. package/dist/commonjs/commands/update.js +1 -0
  18. package/dist/commonjs/config/error.config.js +1 -0
  19. package/dist/commonjs/const/code.js +1 -0
  20. package/dist/commonjs/constant.d.ts +7 -7
  21. package/dist/commonjs/constant.js +1 -0
  22. package/dist/commonjs/document.js +11 -10
  23. package/dist/commonjs/geo/index.js +20 -9
  24. package/dist/commonjs/geo/lineString.d.ts +1 -1
  25. package/dist/commonjs/geo/lineString.js +7 -6
  26. package/dist/commonjs/geo/multiLineString.d.ts +1 -1
  27. package/dist/commonjs/geo/multiLineString.js +7 -6
  28. package/dist/commonjs/geo/multiPoint.d.ts +1 -1
  29. package/dist/commonjs/geo/multiPoint.js +7 -6
  30. package/dist/commonjs/geo/multiPolygon.d.ts +1 -1
  31. package/dist/commonjs/geo/multiPolygon.js +7 -6
  32. package/dist/commonjs/geo/point.d.ts +1 -1
  33. package/dist/commonjs/geo/point.js +4 -3
  34. package/dist/commonjs/geo/polygon.d.ts +1 -1
  35. package/dist/commonjs/geo/polygon.js +8 -7
  36. package/dist/commonjs/helper/symbol.js +16 -4
  37. package/dist/commonjs/index.d.ts +9 -2
  38. package/dist/commonjs/index.js +19 -4
  39. package/dist/commonjs/lib/util.js +4 -3
  40. package/dist/commonjs/operator-map.js +1 -0
  41. package/dist/commonjs/query.js +10 -9
  42. package/dist/commonjs/regexp/index.d.ts +1 -1
  43. package/dist/commonjs/regexp/index.js +2 -1
  44. package/dist/commonjs/serializer/common.d.ts +2 -2
  45. package/dist/commonjs/serializer/common.js +23 -17
  46. package/dist/commonjs/serializer/datatype.d.ts +2 -2
  47. package/dist/commonjs/serializer/datatype.js +20 -14
  48. package/dist/commonjs/serializer/query.d.ts +1 -1
  49. package/dist/commonjs/serializer/query.js +24 -23
  50. package/dist/commonjs/serializer/update.d.ts +1 -1
  51. package/dist/commonjs/serializer/update.js +12 -11
  52. package/dist/commonjs/serverDate/index.d.ts +1 -1
  53. package/dist/commonjs/serverDate/index.js +3 -2
  54. package/dist/commonjs/transaction/collection.d.ts +1 -1
  55. package/dist/commonjs/transaction/collection.js +5 -2
  56. package/dist/commonjs/transaction/document.d.ts +1 -1
  57. package/dist/commonjs/transaction/document.js +5 -5
  58. package/dist/commonjs/transaction/index.js +3 -2
  59. package/dist/commonjs/transaction/query.js +1 -0
  60. package/dist/commonjs/typings/index.d.ts +3 -3
  61. package/dist/commonjs/typings/realtime.d.ts +16 -16
  62. package/dist/commonjs/util.js +1 -0
  63. package/dist/commonjs/utils/error.d.ts +2 -1
  64. package/dist/commonjs/utils/error.js +15 -9
  65. package/dist/commonjs/utils/symbol.js +5 -4
  66. package/dist/commonjs/utils/type.d.ts +1 -1
  67. package/dist/commonjs/utils/type.js +23 -11
  68. package/dist/commonjs/utils/utils.js +6 -3
  69. package/dist/commonjs/validate.js +1 -0
  70. package/dist/esm/aggregate.d.ts.map +1 -0
  71. package/dist/esm/aggregate.js +3 -3
  72. package/dist/esm/collection.d.ts +1 -1
  73. package/dist/esm/collection.d.ts.map +1 -0
  74. package/dist/esm/collection.js +4 -2
  75. package/dist/esm/command.d.ts +5 -5
  76. package/dist/esm/command.d.ts.map +1 -0
  77. package/dist/esm/commands/logic.d.ts.map +1 -0
  78. package/dist/esm/commands/query.d.ts.map +1 -0
  79. package/dist/esm/commands/query.js +8 -6
  80. package/dist/esm/commands/update.d.ts.map +1 -0
  81. package/dist/esm/config/app.config.d.ts.map +1 -0
  82. package/dist/esm/config/error.config.d.ts.map +1 -0
  83. package/dist/esm/const/code.d.ts.map +1 -0
  84. package/dist/esm/constant.d.ts +7 -7
  85. package/dist/esm/constant.d.ts.map +1 -0
  86. package/dist/esm/document.d.ts.map +1 -0
  87. package/dist/esm/document.js +2 -2
  88. package/dist/esm/geo/index.d.ts.map +1 -0
  89. package/dist/esm/geo/interface.d.ts.map +1 -0
  90. package/dist/esm/geo/interface.js +1 -0
  91. package/dist/esm/geo/lineString.d.ts +1 -1
  92. package/dist/esm/geo/lineString.d.ts.map +1 -0
  93. package/dist/esm/geo/lineString.js +3 -3
  94. package/dist/esm/geo/multiLineString.d.ts +1 -1
  95. package/dist/esm/geo/multiLineString.d.ts.map +1 -0
  96. package/dist/esm/geo/multiLineString.js +3 -3
  97. package/dist/esm/geo/multiPoint.d.ts +1 -1
  98. package/dist/esm/geo/multiPoint.d.ts.map +1 -0
  99. package/dist/esm/geo/multiPoint.js +3 -3
  100. package/dist/esm/geo/multiPolygon.d.ts +1 -1
  101. package/dist/esm/geo/multiPolygon.d.ts.map +1 -0
  102. package/dist/esm/geo/multiPolygon.js +3 -3
  103. package/dist/esm/geo/point.d.ts +1 -1
  104. package/dist/esm/geo/point.d.ts.map +1 -0
  105. package/dist/esm/geo/point.js +2 -2
  106. package/dist/esm/geo/polygon.d.ts +1 -1
  107. package/dist/esm/geo/polygon.d.ts.map +1 -0
  108. package/dist/esm/geo/polygon.js +4 -4
  109. package/dist/esm/helper/symbol.d.ts.map +1 -0
  110. package/dist/esm/index.d.ts +9 -2
  111. package/dist/esm/index.d.ts.map +1 -0
  112. package/dist/esm/index.js +15 -1
  113. package/dist/esm/lib/util.d.ts.map +1 -0
  114. package/dist/esm/lib/util.js +1 -2
  115. package/dist/esm/operator-map.d.ts.map +1 -0
  116. package/dist/esm/query.d.ts.map +1 -0
  117. package/dist/esm/query.js +4 -4
  118. package/dist/esm/regexp/index.d.ts +1 -1
  119. package/dist/esm/regexp/index.d.ts.map +1 -0
  120. package/dist/esm/regexp/index.js +1 -1
  121. package/dist/esm/serializer/common.d.ts +2 -2
  122. package/dist/esm/serializer/common.d.ts.map +1 -0
  123. package/dist/esm/serializer/common.js +15 -10
  124. package/dist/esm/serializer/datatype.d.ts +2 -2
  125. package/dist/esm/serializer/datatype.d.ts.map +1 -0
  126. package/dist/esm/serializer/datatype.js +12 -7
  127. package/dist/esm/serializer/query.d.ts +1 -1
  128. package/dist/esm/serializer/query.d.ts.map +1 -0
  129. package/dist/esm/serializer/query.js +2 -2
  130. package/dist/esm/serializer/update.d.ts +1 -1
  131. package/dist/esm/serializer/update.d.ts.map +1 -0
  132. package/dist/esm/serverDate/index.d.ts +1 -1
  133. package/dist/esm/serverDate/index.d.ts.map +1 -0
  134. package/dist/esm/serverDate/index.js +2 -2
  135. package/dist/esm/transaction/collection.d.ts +1 -1
  136. package/dist/esm/transaction/collection.d.ts.map +1 -0
  137. package/dist/esm/transaction/collection.js +4 -2
  138. package/dist/esm/transaction/document.d.ts +1 -1
  139. package/dist/esm/transaction/document.d.ts.map +1 -0
  140. package/dist/esm/transaction/document.js +2 -3
  141. package/dist/esm/transaction/index.d.ts.map +1 -0
  142. package/dist/esm/transaction/index.js +2 -2
  143. package/dist/esm/transaction/query.d.ts.map +1 -0
  144. package/dist/esm/typings/index.d.ts +3 -3
  145. package/dist/esm/typings/index.d.ts.map +1 -0
  146. package/dist/esm/typings/index.js +1 -0
  147. package/dist/esm/typings/realtime.d.ts +16 -16
  148. package/dist/esm/typings/realtime.d.ts.map +1 -0
  149. package/dist/esm/typings/realtime.js +1 -0
  150. package/dist/esm/util.d.ts.map +1 -0
  151. package/dist/esm/utils/error.d.ts +2 -1
  152. package/dist/esm/utils/error.d.ts.map +1 -0
  153. package/dist/esm/utils/error.js +7 -5
  154. package/dist/esm/utils/msg.d.ts.map +1 -0
  155. package/dist/esm/utils/symbol.d.ts.map +1 -0
  156. package/dist/esm/utils/symbol.js +4 -4
  157. package/dist/esm/utils/type.d.ts +1 -1
  158. package/dist/esm/utils/type.d.ts.map +1 -0
  159. package/dist/esm/utils/utils.d.ts.map +1 -0
  160. package/dist/esm/utils/utils.js +1 -1
  161. package/dist/esm/validate.d.ts.map +1 -0
  162. package/jest.config.js +14 -0
  163. package/package.json +9 -4
  164. package/src/aggregate.ts +1 -1
  165. package/src/document.ts +1 -1
  166. package/src/index.ts +40 -4
  167. package/src/lib/util.ts +1 -2
  168. package/src/query.ts +4 -4
  169. package/src/transaction/index.ts +1 -1
  170. package/src/utils/utils.ts +1 -1
  171. package/tests/index.test.ts +111 -0
  172. package/tsconfig.esm.json +2 -1
  173. package/tsconfig.json +14 -5
  174. package/tsconfig.test.json +15 -0
  175. package/.trunk/configs/.markdownlint.yaml +0 -10
  176. 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 " + typeof polygons);
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 " + typeof polygon + "[]");
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: true,
117
+ enumerable: false,
117
118
  configurable: true
118
119
  });
119
120
  return MultiPolygon;
@@ -15,5 +15,5 @@ export declare class Point {
15
15
  };
16
16
  toReadableString(): string;
17
17
  static validate(point: ISerializedPoint): boolean;
18
- readonly _internalType: import("../utils/symbol").InternalSymbol;
18
+ get _internalType(): import("../utils/symbol").InternalSymbol;
19
19
  }
@@ -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 "[" + this.longitude + "," + this.latitude + "]";
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: true,
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
- readonly _internalType: import("../utils/symbol").InternalSymbol;
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 " + typeof lines);
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 " + typeof line + "[]");
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 " + line.points.map(function (p) { return p.toReadableString(); }) + " is not a closed cycle");
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: true,
104
+ enumerable: false,
104
105
  configurable: true
105
106
  });
106
107
  return Polygon;
@@ -1,10 +1,22 @@
1
1
  "use strict";
2
- function __export(m) {
3
- for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
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
- __export(require("../utils/symbol"));
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');
@@ -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: any;
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
- constructor(config?: any);
36
+ static createRequest(config: IDbConfig): any;
37
+ constructor(config?: IDbConfig);
31
38
  collection(collName: string): CollectionReference;
32
39
  createCollection(collName: string): any;
33
40
  }
@@ -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.Query = query_2.Query;
14
+ Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return query_2.Query; } });
14
15
  var collection_2 = require("./collection");
15
- exports.CollectionReference = collection_2.CollectionReference;
16
+ Object.defineProperty(exports, "CollectionReference", { enumerable: true, get: function () { return collection_2.CollectionReference; } });
16
17
  var document_1 = require("./document");
17
- exports.DocumentReference = document_1.DocumentReference;
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 = new Db.reqClass(this.config);
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 = function () {
4
- var cb;
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");
@@ -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 = new index_1.Db.reqClass(this._db.config);
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
- readonly _internalType: import("../utils/symbol").InternalSymbol;
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: true,
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 declare type IQueryCondition = Record<string, any> | LogicCommand;
3
- export declare type AnyObject = {
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 __spread = (this && this.__spread) || function () {
30
- for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
31
- return ar;
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 = __spread(parents, [
54
+ var newParents = __spreadArray(__spreadArray([], __read(parents), false), [
49
55
  key,
50
- ]);
51
- var newVisited = __spread(visited, [
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 + "." + childKey] = flattenedChild[childKey];
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 " + type_1.getType(condition) + ", can only overwrite", condition, key);
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 " + type_1.getType(query) + ", can only overwrite", query, condition, key);
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 declare type IQueryCondition = Record<string, any> | LogicCommand;
3
- export declare type AnyObject = {
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 __spread = (this && this.__spread) || function () {
30
- for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
31
- return ar;
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, __spread(visited, [
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], __spread(visited, [
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 declare type IQueryCondition = Record<string, any> | LogicCommand;
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;