@cloudbase/database 1.4.3 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/dist/commonjs/ObjectId/index.d.ts +1 -1
  2. package/dist/commonjs/ObjectId/index.js +16 -9
  3. package/dist/commonjs/aggregate.js +126 -75
  4. package/dist/commonjs/collection.d.ts +3 -2
  5. package/dist/commonjs/collection.js +131 -58
  6. package/dist/commonjs/command.d.ts +5 -5
  7. package/dist/commonjs/command.js +181 -154
  8. package/dist/commonjs/commands/logic.js +30 -20
  9. package/dist/commonjs/commands/query.d.ts +1 -1
  10. package/dist/commonjs/commands/query.js +85 -65
  11. package/dist/commonjs/commands/update.js +9 -7
  12. package/dist/commonjs/config/error.config.js +1 -0
  13. package/dist/commonjs/const/code.js +1 -0
  14. package/dist/commonjs/constant.d.ts +7 -7
  15. package/dist/commonjs/constant.js +13 -11
  16. package/dist/commonjs/document.d.ts +10 -6
  17. package/dist/commonjs/document.js +305 -193
  18. package/dist/commonjs/geo/index.js +20 -9
  19. package/dist/commonjs/geo/lineString.d.ts +1 -1
  20. package/dist/commonjs/geo/lineString.js +62 -33
  21. package/dist/commonjs/geo/multiLineString.d.ts +1 -1
  22. package/dist/commonjs/geo/multiLineString.js +71 -32
  23. package/dist/commonjs/geo/multiPoint.d.ts +1 -1
  24. package/dist/commonjs/geo/multiPoint.js +58 -29
  25. package/dist/commonjs/geo/multiPolygon.d.ts +1 -1
  26. package/dist/commonjs/geo/multiPolygon.js +96 -36
  27. package/dist/commonjs/geo/point.d.ts +1 -1
  28. package/dist/commonjs/geo/point.js +30 -23
  29. package/dist/commonjs/geo/polygon.d.ts +1 -1
  30. package/dist/commonjs/geo/polygon.js +78 -39
  31. package/dist/commonjs/helper/symbol.js +17 -5
  32. package/dist/commonjs/index.d.ts +8 -2
  33. package/dist/commonjs/index.js +73 -20
  34. package/dist/commonjs/lib/util.d.ts +1 -0
  35. package/dist/commonjs/lib/util.js +26 -0
  36. package/dist/commonjs/operator-map.js +7 -6
  37. package/dist/commonjs/query.d.ts +8 -4
  38. package/dist/commonjs/query.js +308 -201
  39. package/dist/commonjs/regexp/index.d.ts +1 -1
  40. package/dist/commonjs/regexp/index.js +16 -9
  41. package/dist/commonjs/serializer/common.d.ts +2 -2
  42. package/dist/commonjs/serializer/common.js +59 -22
  43. package/dist/commonjs/serializer/datatype.d.ts +2 -2
  44. package/dist/commonjs/serializer/datatype.js +58 -21
  45. package/dist/commonjs/serializer/query.d.ts +1 -1
  46. package/dist/commonjs/serializer/query.js +137 -127
  47. package/dist/commonjs/serializer/update.d.ts +1 -1
  48. package/dist/commonjs/serializer/update.js +83 -78
  49. package/dist/commonjs/serverDate/index.d.ts +1 -1
  50. package/dist/commonjs/serverDate/index.js +16 -9
  51. package/dist/commonjs/transaction/collection.d.ts +7 -0
  52. package/dist/commonjs/transaction/collection.js +49 -0
  53. package/dist/commonjs/transaction/document.d.ts +27 -0
  54. package/dist/commonjs/transaction/document.js +205 -0
  55. package/dist/commonjs/transaction/index.js +196 -86
  56. package/dist/commonjs/transaction/query.d.ts +43 -0
  57. package/dist/commonjs/transaction/query.js +261 -0
  58. package/dist/commonjs/typings/index.d.ts +4 -4
  59. package/dist/commonjs/typings/realtime.d.ts +16 -16
  60. package/dist/commonjs/util.js +123 -92
  61. package/dist/commonjs/utils/error.d.ts +2 -1
  62. package/dist/commonjs/utils/error.js +74 -38
  63. package/dist/commonjs/utils/symbol.js +33 -14
  64. package/dist/commonjs/utils/type.d.ts +1 -1
  65. package/dist/commonjs/utils/type.js +25 -13
  66. package/dist/commonjs/utils/utils.d.ts +4 -1
  67. package/dist/commonjs/utils/utils.js +93 -22
  68. package/dist/commonjs/validate.js +79 -63
  69. package/dist/esm/ObjectId/index.d.ts +1 -1
  70. package/dist/esm/ObjectId/index.js +15 -8
  71. package/dist/esm/aggregate.js +118 -66
  72. package/dist/esm/collection.d.ts +3 -2
  73. package/dist/esm/collection.js +125 -52
  74. package/dist/esm/command.d.ts +5 -5
  75. package/dist/esm/command.js +175 -147
  76. package/dist/esm/commands/logic.js +30 -20
  77. package/dist/esm/commands/query.d.ts +1 -1
  78. package/dist/esm/commands/query.js +91 -71
  79. package/dist/esm/commands/update.js +8 -6
  80. package/dist/esm/config/error.config.js +1 -1
  81. package/dist/esm/const/code.js +1 -1
  82. package/dist/esm/constant.d.ts +7 -7
  83. package/dist/esm/constant.js +12 -11
  84. package/dist/esm/document.d.ts +10 -6
  85. package/dist/esm/document.js +297 -185
  86. package/dist/esm/geo/interface.js +1 -0
  87. package/dist/esm/geo/lineString.d.ts +1 -1
  88. package/dist/esm/geo/lineString.js +57 -28
  89. package/dist/esm/geo/multiLineString.d.ts +1 -1
  90. package/dist/esm/geo/multiLineString.js +66 -27
  91. package/dist/esm/geo/multiPoint.d.ts +1 -1
  92. package/dist/esm/geo/multiPoint.js +53 -24
  93. package/dist/esm/geo/multiPolygon.d.ts +1 -1
  94. package/dist/esm/geo/multiPolygon.js +91 -31
  95. package/dist/esm/geo/point.d.ts +1 -1
  96. package/dist/esm/geo/point.js +26 -19
  97. package/dist/esm/geo/polygon.d.ts +1 -1
  98. package/dist/esm/geo/polygon.js +73 -34
  99. package/dist/esm/helper/symbol.js +13 -13
  100. package/dist/esm/index.d.ts +8 -2
  101. package/dist/esm/index.js +62 -9
  102. package/dist/esm/lib/util.d.ts +1 -0
  103. package/dist/esm/lib/util.js +22 -0
  104. package/dist/esm/operator-map.js +4 -4
  105. package/dist/esm/query.d.ts +8 -4
  106. package/dist/esm/query.js +299 -192
  107. package/dist/esm/regexp/index.d.ts +1 -1
  108. package/dist/esm/regexp/index.js +15 -8
  109. package/dist/esm/serializer/common.d.ts +2 -2
  110. package/dist/esm/serializer/common.js +49 -13
  111. package/dist/esm/serializer/datatype.d.ts +2 -2
  112. package/dist/esm/serializer/datatype.js +44 -8
  113. package/dist/esm/serializer/query.d.ts +1 -1
  114. package/dist/esm/serializer/query.js +112 -102
  115. package/dist/esm/serializer/update.d.ts +1 -1
  116. package/dist/esm/serializer/update.js +69 -64
  117. package/dist/esm/serverDate/index.d.ts +1 -1
  118. package/dist/esm/serverDate/index.js +15 -8
  119. package/dist/esm/transaction/collection.d.ts +7 -0
  120. package/dist/esm/transaction/collection.js +46 -0
  121. package/dist/esm/transaction/document.d.ts +27 -0
  122. package/dist/esm/transaction/document.js +202 -0
  123. package/dist/esm/transaction/index.js +191 -81
  124. package/dist/esm/transaction/query.d.ts +43 -0
  125. package/dist/esm/transaction/query.js +258 -0
  126. package/dist/esm/typings/index.d.ts +4 -4
  127. package/dist/esm/typings/index.js +1 -0
  128. package/dist/esm/typings/realtime.d.ts +16 -16
  129. package/dist/esm/typings/realtime.js +1 -0
  130. package/dist/esm/util.js +121 -90
  131. package/dist/esm/utils/error.d.ts +2 -1
  132. package/dist/esm/utils/error.js +70 -35
  133. package/dist/esm/utils/symbol.js +33 -14
  134. package/dist/esm/utils/type.d.ts +1 -1
  135. package/dist/esm/utils/type.js +12 -12
  136. package/dist/esm/utils/utils.d.ts +4 -1
  137. package/dist/esm/utils/utils.js +78 -16
  138. package/dist/esm/validate.js +65 -49
  139. package/jest.config.js +14 -0
  140. package/package.json +14 -10
  141. package/src/aggregate.ts +1 -5
  142. package/src/collection.ts +15 -2
  143. package/src/document.ts +45 -34
  144. package/src/index.ts +51 -4
  145. package/src/query.ts +33 -29
  146. package/src/serializer/query.ts +18 -6
  147. package/src/transaction/index.ts +1 -1
  148. package/src/typings/index.ts +0 -4
  149. package/src/utils/utils.ts +46 -0
  150. package/src/validate.ts +3 -6
  151. package/tests/gateway-contract.test.ts +180 -0
  152. package/tests/index.test.ts +283 -0
  153. package/tests/transaction-query.test.ts +207 -0
  154. package/tsconfig.esm.json +4 -2
  155. package/tsconfig.json +16 -6
  156. package/tsconfig.test.json +15 -0
  157. package/dist/commonjs/realtime/error.d.ts +0 -7
  158. package/dist/commonjs/realtime/error.js +0 -11
  159. package/dist/commonjs/realtime/listener.d.ts +0 -14
  160. package/dist/commonjs/realtime/listener.js +0 -17
  161. package/dist/commonjs/realtime/message.d.ts +0 -3
  162. package/dist/commonjs/realtime/message.js +0 -10
  163. package/dist/commonjs/realtime/snapshot.d.ts +0 -16
  164. package/dist/commonjs/realtime/snapshot.js +0 -42
  165. package/dist/commonjs/realtime/virtual-websocket-client.d.ts +0 -63
  166. package/dist/commonjs/realtime/virtual-websocket-client.js +0 -736
  167. package/dist/commonjs/realtime/websocket-client.d.ts +0 -78
  168. package/dist/commonjs/realtime/websocket-client.js +0 -567
  169. package/dist/commonjs/realtime/ws-event.d.ts +0 -126
  170. package/dist/commonjs/realtime/ws-event.js +0 -139
  171. package/dist/commonjs/transaction.d.ts +0 -42
  172. package/dist/commonjs/transaction.js +0 -126
  173. package/dist/esm/realtime/error.d.ts +0 -7
  174. package/dist/esm/realtime/error.js +0 -8
  175. package/dist/esm/realtime/listener.d.ts +0 -14
  176. package/dist/esm/realtime/listener.js +0 -14
  177. package/dist/esm/realtime/message.d.ts +0 -3
  178. package/dist/esm/realtime/message.js +0 -6
  179. package/dist/esm/realtime/snapshot.d.ts +0 -16
  180. package/dist/esm/realtime/snapshot.js +0 -39
  181. package/dist/esm/realtime/virtual-websocket-client.d.ts +0 -63
  182. package/dist/esm/realtime/virtual-websocket-client.js +0 -733
  183. package/dist/esm/realtime/websocket-client.d.ts +0 -78
  184. package/dist/esm/realtime/websocket-client.js +0 -564
  185. package/dist/esm/realtime/ws-event.d.ts +0 -126
  186. package/dist/esm/realtime/ws-event.js +0 -137
  187. package/dist/esm/transaction.d.ts +0 -42
  188. package/dist/esm/transaction.js +0 -121
  189. package/src/realtime/error.ts +0 -19
  190. package/src/realtime/listener.ts +0 -35
  191. package/src/realtime/message.ts +0 -14
  192. package/src/realtime/snapshot.ts +0 -60
  193. package/src/realtime/virtual-websocket-client.ts +0 -1195
  194. package/src/realtime/websocket-client.ts +0 -995
  195. package/src/realtime/ws-event.ts +0 -163
  196. package/src/transaction.ts +0 -190
@@ -1,11 +1,47 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __read = (this && this.__read) || function (o, n) {
13
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
14
+ if (!m) return o;
15
+ var i = m.call(o), r, ar = [], e;
16
+ try {
17
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
18
+ }
19
+ catch (error) { e = { error: error }; }
20
+ finally {
21
+ try {
22
+ if (r && !r.done && (m = i["return"])) m.call(i);
23
+ }
24
+ finally { if (e) throw e.error; }
25
+ }
26
+ return ar;
27
+ };
28
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
29
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
30
+ if (ar || !(i in from)) {
31
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
32
+ ar[i] = from[i];
33
+ }
34
+ }
35
+ return to.concat(ar || Array.prototype.slice.call(from));
36
+ };
1
37
  import { getType, isObject, isArray, isDate, isRegExp, isInternalObject } from '../utils/type';
2
38
  import { serialize as serializeInternalDataType, deserialize as deserializeInternalDataType } from './datatype';
3
39
  function flatten(query, shouldPreserverObject, parents, visited) {
4
- const cloned = Object.assign({}, query);
5
- for (const key in query) {
40
+ var cloned = __assign({}, query);
41
+ for (var key in query) {
6
42
  if (/^\$/.test(key))
7
43
  continue;
8
- const value = query[key];
44
+ var value = query[key];
9
45
  if (value === undefined) {
10
46
  delete cloned[key];
11
47
  continue;
@@ -16,14 +52,14 @@ function flatten(query, shouldPreserverObject, parents, visited) {
16
52
  if (visited.indexOf(value) > -1) {
17
53
  throw new Error('Cannot convert circular structure to JSON');
18
54
  }
19
- const newParents = [...parents, key];
20
- const newVisited = [...visited, value];
21
- const flattenedChild = flatten(value, shouldPreserverObject, newParents, newVisited);
55
+ var newParents = __spreadArray(__spreadArray([], __read(parents), false), [key], false);
56
+ var newVisited = __spreadArray(__spreadArray([], __read(visited), false), [value], false);
57
+ var flattenedChild = flatten(value, shouldPreserverObject, newParents, newVisited);
22
58
  cloned[key] = flattenedChild;
23
- let hasKeyNotCombined = false;
24
- for (const childKey in flattenedChild) {
59
+ var hasKeyNotCombined = false;
60
+ for (var childKey in flattenedChild) {
25
61
  if (!/^\$/.test(childKey)) {
26
- cloned[`${key}.${childKey}`] = flattenedChild[childKey];
62
+ cloned["".concat(key, ".").concat(childKey)] = flattenedChild[childKey];
27
63
  delete cloned[key][childKey];
28
64
  }
29
65
  else {
@@ -41,13 +77,13 @@ export function flattenQueryObject(query) {
41
77
  return flatten(query, isConversionRequired, [], [query]);
42
78
  }
43
79
  export function flattenObject(object) {
44
- return flatten(object, (_) => false, [], [object]);
80
+ return flatten(object, function (_) { return false; }, [], [object]);
45
81
  }
46
82
  export function mergeConditionAfterEncode(query, condition, key) {
47
83
  if (!condition[key]) {
48
84
  delete query[key];
49
85
  }
50
- for (const conditionKey in condition) {
86
+ for (var conditionKey in condition) {
51
87
  if (query[conditionKey]) {
52
88
  if (isArray(query[conditionKey])) {
53
89
  query[conditionKey].push(condition[conditionKey]);
@@ -57,12 +93,12 @@ export function mergeConditionAfterEncode(query, condition, key) {
57
93
  Object.assign(query[conditionKey], condition[conditionKey]);
58
94
  }
59
95
  else {
60
- console.warn(`unmergable condition, query is object but condition is ${getType(condition)}, can only overwrite`, condition, key);
96
+ console.warn("unmergable condition, query is object but condition is ".concat(getType(condition), ", can only overwrite"), condition, key);
61
97
  query[conditionKey] = condition[conditionKey];
62
98
  }
63
99
  }
64
100
  else {
65
- console.warn(`to-merge query is of type ${getType(query)}, can only overwrite`, query, condition, key);
101
+ console.warn("to-merge query is of type ".concat(getType(query), ", can only overwrite"), query, condition, key);
66
102
  query[conditionKey] = condition[conditionKey];
67
103
  }
68
104
  }
@@ -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;
@@ -1,3 +1,39 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __read = (this && this.__read) || function (o, n) {
13
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
14
+ if (!m) return o;
15
+ var i = m.call(o), r, ar = [], e;
16
+ try {
17
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
18
+ }
19
+ catch (error) { e = { error: error }; }
20
+ finally {
21
+ try {
22
+ if (r && !r.done && (m = i["return"])) m.call(i);
23
+ }
24
+ finally { if (e) throw e.error; }
25
+ }
26
+ return ar;
27
+ };
28
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
29
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
30
+ if (ar || !(i in from)) {
31
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
32
+ ar[i] = from[i];
33
+ }
34
+ }
35
+ return to.concat(ar || Array.prototype.slice.call(from));
36
+ };
1
37
  import { SYMBOL_GEO_POINT, SYMBOL_SERVER_DATE, SYMBOL_OBJECTID, SYMBOL_REGEXP } from '../helper/symbol';
2
38
  import { getType, isObject, isArray, isDate, isNumber, isInternalObject, isRegExp } from '../utils/type';
3
39
  import { Point } from '../geo/index';
@@ -37,22 +73,22 @@ function serializeHelper(val, visited) {
37
73
  };
38
74
  }
39
75
  else if (isArray(val)) {
40
- return val.map(item => {
76
+ return val.map(function (item) {
41
77
  if (visited.indexOf(item) > -1) {
42
78
  throw new Error('Cannot convert circular structure to JSON');
43
79
  }
44
- return serializeHelper(item, [...visited, item]);
80
+ return serializeHelper(item, __spreadArray(__spreadArray([], __read(visited), false), [item], false));
45
81
  });
46
82
  }
47
83
  else if (isObject(val)) {
48
- const rawRet = Object.assign({}, val);
49
- const finalRet = {};
50
- for (const key in rawRet) {
84
+ var rawRet = __assign({}, val);
85
+ var finalRet = {};
86
+ for (var key in rawRet) {
51
87
  if (visited.indexOf(rawRet[key]) > -1) {
52
88
  throw new Error('Cannot convert circular structure to JSON');
53
89
  }
54
90
  if (rawRet[key] !== undefined) {
55
- finalRet[key] = serializeHelper(rawRet[key], [...visited, rawRet[key]]);
91
+ finalRet[key] = serializeHelper(rawRet[key], __spreadArray(__spreadArray([], __read(visited), false), [rawRet[key]], false));
56
92
  }
57
93
  }
58
94
  return finalRet;
@@ -62,8 +98,8 @@ function serializeHelper(val, visited) {
62
98
  }
63
99
  }
64
100
  export function deserialize(object) {
65
- const ret = Object.assign({}, object);
66
- for (const key in ret) {
101
+ var ret = __assign({}, object);
102
+ for (var key in ret) {
67
103
  switch (key) {
68
104
  case '$date': {
69
105
  switch (getType(ret[key])) {
@@ -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;
@@ -6,19 +6,25 @@ import { operatorToString } from '../operator-map';
6
6
  import { flattenQueryObject, isConversionRequired, encodeInternalDataType } from './common';
7
7
  import { stringifyByEJSON } from '../utils/utils';
8
8
  import { Validate } from '../validate';
9
- export class QuerySerializer {
10
- constructor() { }
11
- static encode(query) {
12
- const encoder = new QueryEncoder();
13
- return encoder.encodeQuery(query);
9
+ var QuerySerializer = (function () {
10
+ function QuerySerializer() {
14
11
  }
15
- static encodeEJSON(query, raw) {
16
- const encoder = new QueryEncoder();
12
+ QuerySerializer.encode = function (query) {
13
+ var encoder = new QueryEncoder();
14
+ return encoder.encodeQuery(query);
15
+ };
16
+ QuerySerializer.encodeEJSON = function (query, raw) {
17
+ var encoder = new QueryEncoder();
17
18
  return stringifyByEJSON(raw ? query : encoder.encodeQuery(query));
19
+ };
20
+ return QuerySerializer;
21
+ }());
22
+ export { QuerySerializer };
23
+ var QueryEncoder = (function () {
24
+ function QueryEncoder() {
18
25
  }
19
- }
20
- class QueryEncoder {
21
- encodeQuery(query, key) {
26
+ QueryEncoder.prototype.encodeQuery = function (query, key) {
27
+ var _a, _b, _c;
22
28
  if (isConversionRequired(query)) {
23
29
  if (isLogicCommand(query)) {
24
30
  return this.encodeLogicCommand(query);
@@ -27,13 +33,13 @@ class QueryEncoder {
27
33
  return this.encodeQueryCommand(query);
28
34
  }
29
35
  else if (isRegExp(query)) {
30
- return { [key]: this.encodeRegExp(query) };
36
+ return _a = {}, _a[key] = this.encodeRegExp(query), _a;
31
37
  }
32
38
  else if (isDate(query)) {
33
- return { [key]: query };
39
+ return _b = {}, _b[key] = encodeInternalDataType(query), _b;
34
40
  }
35
41
  else {
36
- return { [key]: this.encodeQueryObject(query) };
42
+ return _c = {}, _c[key] = this.encodeQueryObject(query), _c;
37
43
  }
38
44
  }
39
45
  else {
@@ -44,75 +50,78 @@ class QueryEncoder {
44
50
  return query;
45
51
  }
46
52
  }
47
- }
48
- encodeRegExp(query) {
53
+ };
54
+ QueryEncoder.prototype.encodeRegExp = function (query) {
49
55
  return {
50
56
  $regularExpression: {
51
57
  pattern: query.source,
52
58
  options: query.flags
53
59
  }
54
60
  };
55
- }
56
- encodeLogicCommand(query) {
61
+ };
62
+ QueryEncoder.prototype.encodeLogicCommand = function (query) {
63
+ var _a, _b, _c, _d, _e, _f, _g;
64
+ var _this = this;
57
65
  switch (query.operator) {
58
66
  case LOGIC_COMMANDS_LITERAL.NOR:
59
67
  case LOGIC_COMMANDS_LITERAL.AND:
60
68
  case LOGIC_COMMANDS_LITERAL.OR: {
61
- const $op = operatorToString(query.operator);
62
- const subqueries = query.operands.map((oprand) => this.encodeQuery(oprand, query.fieldName));
63
- return {
64
- [$op]: subqueries
65
- };
69
+ var $op = operatorToString(query.operator);
70
+ var subqueries = query.operands.map(function (oprand) { return _this.encodeQuery(oprand, query.fieldName); });
71
+ return _a = {},
72
+ _a[$op] = subqueries,
73
+ _a;
66
74
  }
67
75
  case LOGIC_COMMANDS_LITERAL.NOT: {
68
- const $op = operatorToString(query.operator);
69
- const operatorExpression = query.operands[0];
76
+ var $op = operatorToString(query.operator);
77
+ var operatorExpression = query.operands[0];
70
78
  if (isRegExp(operatorExpression)) {
71
- return {
72
- [query.fieldName]: {
73
- [$op]: this.encodeRegExp(operatorExpression)
74
- }
75
- };
79
+ return _b = {},
80
+ _b[query.fieldName] = (_c = {},
81
+ _c[$op] = this.encodeRegExp(operatorExpression),
82
+ _c),
83
+ _b;
76
84
  }
77
85
  else {
78
- const subqueries = this.encodeQuery(operatorExpression)[query.fieldName];
79
- return {
80
- [query.fieldName]: {
81
- [$op]: subqueries
82
- }
83
- };
86
+ var subqueries = this.encodeQuery(operatorExpression)[query.fieldName];
87
+ return _d = {},
88
+ _d[query.fieldName] = (_e = {},
89
+ _e[$op] = subqueries,
90
+ _e),
91
+ _d;
84
92
  }
85
93
  }
86
94
  default: {
87
- const $op = operatorToString(query.operator);
95
+ var $op = operatorToString(query.operator);
88
96
  if (query.operands.length === 1) {
89
- const subquery = this.encodeQuery(query.operands[0]);
90
- return {
91
- [$op]: subquery
92
- };
97
+ var subquery = this.encodeQuery(query.operands[0]);
98
+ return _f = {},
99
+ _f[$op] = subquery,
100
+ _f;
93
101
  }
94
102
  else {
95
- const subqueries = query.operands.map(this.encodeQuery.bind(this));
96
- return {
97
- [$op]: subqueries
98
- };
103
+ var subqueries = query.operands.map(this.encodeQuery.bind(this));
104
+ return _g = {},
105
+ _g[$op] = subqueries,
106
+ _g;
99
107
  }
100
108
  }
101
109
  }
102
- }
103
- encodeQueryCommand(query) {
110
+ };
111
+ QueryEncoder.prototype.encodeQueryCommand = function (query) {
104
112
  if (isComparisonCommand(query)) {
105
113
  return this.encodeComparisonCommand(query);
106
114
  }
107
115
  else {
108
116
  return this.encodeComparisonCommand(query);
109
117
  }
110
- }
111
- encodeComparisonCommand(query) {
118
+ };
119
+ QueryEncoder.prototype.encodeComparisonCommand = function (query) {
120
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
112
121
  if (query.fieldName === SYMBOL_UNSET_FIELD_NAME) {
113
122
  throw new Error('Cannot encode a comparison command with unset field name');
114
123
  }
115
- const $op = operatorToString(query.operator);
124
+ var $op = operatorToString(query.operator);
116
125
  switch (query.operator) {
117
126
  case QUERY_COMMANDS_LITERAL.EQ:
118
127
  case QUERY_COMMANDS_LITERAL.NEQ:
@@ -124,94 +133,94 @@ class QueryEncoder {
124
133
  case QUERY_COMMANDS_LITERAL.EXISTS:
125
134
  case QUERY_COMMANDS_LITERAL.SIZE:
126
135
  case QUERY_COMMANDS_LITERAL.MOD: {
127
- return {
128
- [query.fieldName]: {
129
- [$op]: encodeInternalDataType(query.operands[0])
130
- }
131
- };
136
+ return _a = {},
137
+ _a[query.fieldName] = (_b = {},
138
+ _b[$op] = encodeInternalDataType(query.operands[0]),
139
+ _b),
140
+ _a;
132
141
  }
133
142
  case QUERY_COMMANDS_LITERAL.IN:
134
143
  case QUERY_COMMANDS_LITERAL.NIN:
135
144
  case QUERY_COMMANDS_LITERAL.ALL: {
136
- return {
137
- [query.fieldName]: {
138
- [$op]: encodeInternalDataType(query.operands)
139
- }
140
- };
145
+ return _c = {},
146
+ _c[query.fieldName] = (_d = {},
147
+ _d[$op] = encodeInternalDataType(query.operands),
148
+ _d),
149
+ _c;
141
150
  }
142
151
  case QUERY_COMMANDS_LITERAL.GEO_NEAR: {
143
- const options = query.operands[0];
144
- return {
145
- [query.fieldName]: {
152
+ var options = query.operands[0];
153
+ return _e = {},
154
+ _e[query.fieldName] = {
146
155
  $nearSphere: {
147
156
  $geometry: options.geometry.toJSON(),
148
157
  $maxDistance: options.maxDistance,
149
158
  $minDistance: options.minDistance
150
159
  }
151
- }
152
- };
160
+ },
161
+ _e;
153
162
  }
154
163
  case QUERY_COMMANDS_LITERAL.GEO_WITHIN: {
155
- const options = query.operands[0];
164
+ var options = query.operands[0];
156
165
  if (options.centerSphere) {
157
166
  Validate.isCentersPhere(options.centerSphere);
158
- const centerSphere = options.centerSphere;
167
+ var centerSphere = options.centerSphere;
159
168
  if (centerSphere[0]._internalType === SYMBOL_GEO_POINT) {
160
- return {
161
- [query.fieldName]: {
169
+ return _f = {},
170
+ _f[query.fieldName] = {
162
171
  $geoWithin: {
163
172
  $centerSphere: [centerSphere[0].toJSON().coordinates, centerSphere[1]]
164
173
  }
165
- }
166
- };
174
+ },
175
+ _f;
167
176
  }
168
- return {
169
- [query.fieldName]: {
177
+ return _g = {},
178
+ _g[query.fieldName] = {
170
179
  $geoWithin: {
171
180
  $centerSphere: options.centerSphere
172
181
  }
173
- }
174
- };
182
+ },
183
+ _g;
175
184
  }
176
- return {
177
- [query.fieldName]: {
185
+ return _h = {},
186
+ _h[query.fieldName] = {
178
187
  $geoWithin: {
179
188
  $geometry: options.geometry.toJSON()
180
189
  }
181
- }
182
- };
190
+ },
191
+ _h;
183
192
  }
184
193
  case QUERY_COMMANDS_LITERAL.GEO_INTERSECTS: {
185
- const options = query.operands[0];
186
- return {
187
- [query.fieldName]: {
194
+ var options = query.operands[0];
195
+ return _j = {},
196
+ _j[query.fieldName] = {
188
197
  $geoIntersects: {
189
198
  $geometry: options.geometry.toJSON()
190
199
  }
191
- }
192
- };
200
+ },
201
+ _j;
193
202
  }
194
203
  default: {
195
- return {
196
- [query.fieldName]: {
197
- [$op]: encodeInternalDataType(query.operands[0])
198
- }
199
- };
204
+ return _k = {},
205
+ _k[query.fieldName] = (_l = {},
206
+ _l[$op] = encodeInternalDataType(query.operands[0]),
207
+ _l),
208
+ _k;
200
209
  }
201
210
  }
202
- }
203
- encodeQueryObject(query) {
204
- const flattened = flattenQueryObject(query);
205
- for (const key in flattened) {
206
- const val = flattened[key];
211
+ };
212
+ QueryEncoder.prototype.encodeQueryObject = function (query) {
213
+ var flattened = flattenQueryObject(query);
214
+ for (var key in flattened) {
215
+ var val = flattened[key];
207
216
  if (isLogicCommand(val)) {
208
217
  flattened[key] = val._setFieldName(key);
209
- const condition = this.encodeLogicCommand(flattened[key]);
218
+ var condition = this.encodeLogicCommand(flattened[key]);
210
219
  this.mergeConditionAfterEncode(flattened, condition, key);
211
220
  }
212
221
  else if (isComparisonCommand(val)) {
213
222
  flattened[key] = val._setFieldName(key);
214
- const condition = this.encodeComparisonCommand(flattened[key]);
223
+ var condition = this.encodeComparisonCommand(flattened[key]);
215
224
  this.mergeConditionAfterEncode(flattened, condition, key);
216
225
  }
217
226
  else if (isConversionRequired(val)) {
@@ -219,12 +228,12 @@ class QueryEncoder {
219
228
  }
220
229
  }
221
230
  return flattened;
222
- }
223
- mergeConditionAfterEncode(query, condition, key) {
231
+ };
232
+ QueryEncoder.prototype.mergeConditionAfterEncode = function (query, condition, key) {
224
233
  if (!condition[key]) {
225
234
  delete query[key];
226
235
  }
227
- for (const conditionKey in condition) {
236
+ for (var conditionKey in condition) {
228
237
  if (query[conditionKey]) {
229
238
  if (isArray(query[conditionKey])) {
230
239
  query[conditionKey] = query[conditionKey].concat(condition[conditionKey]);
@@ -234,12 +243,12 @@ class QueryEncoder {
234
243
  Object.assign(query, condition);
235
244
  }
236
245
  else {
237
- console.warn(`unmergable condition, query is object but condition is ${getType(condition)}, can only overwrite`, condition, key);
246
+ console.warn("unmergable condition, query is object but condition is ".concat(getType(condition), ", can only overwrite"), condition, key);
238
247
  query[conditionKey] = condition[conditionKey];
239
248
  }
240
249
  }
241
250
  else {
242
- console.warn(`to-merge query is of type ${getType(query)}, can only overwrite`, query, condition, key);
251
+ console.warn("to-merge query is of type ".concat(getType(query), ", can only overwrite"), query, condition, key);
243
252
  query[conditionKey] = condition[conditionKey];
244
253
  }
245
254
  }
@@ -247,5 +256,6 @@ class QueryEncoder {
247
256
  query[conditionKey] = condition[conditionKey];
248
257
  }
249
258
  }
250
- }
251
- }
259
+ };
260
+ return QueryEncoder;
261
+ }());
@@ -1,6 +1,6 @@
1
1
  import { UpdateCommand } from '../commands/update';
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 interface IUpdateCondition {
5
5
  [key: string]: any;
6
6
  }