@cloudbase/js-sdk 3.6.8 → 3.6.9-beta.1

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 (202) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/app/dist/index.esm.js +1 -1
  3. package/app/dist/index.esm.js.map +1 -1
  4. package/app/dist/index.js +1 -1
  5. package/app/dist/index.js.map +1 -1
  6. package/app/dist/index.node.esm.js +1 -1
  7. package/app/dist/index.node.esm.js.map +1 -1
  8. package/app/dist/index.node.js +1 -1
  9. package/app/dist/index.node.js.map +1 -1
  10. package/auth/dist/index.esm.js.map +1 -1
  11. package/auth/dist/index.js.map +1 -1
  12. package/database/dist/index.d.ts +3 -0
  13. package/database/dist/index.esm.js +2 -0
  14. package/database/dist/index.esm.js.map +1 -0
  15. package/database/dist/index.js +2 -0
  16. package/database/dist/index.js.map +1 -0
  17. package/dist/index.cjs.js +1 -1
  18. package/dist/index.cjs.js.map +1 -1
  19. package/dist/index.esm.js +1 -1
  20. package/dist/index.esm.js.map +1 -1
  21. package/dist/index.node.cjs.js +1 -1
  22. package/dist/index.node.cjs.js.map +1 -1
  23. package/dist/index.node.esm.js +1 -1
  24. package/dist/index.node.esm.js.map +1 -1
  25. package/miniprogram_dist/index.js +1 -1
  26. package/oauth/dist/index.esm.js.map +1 -1
  27. package/oauth/dist/index.js.map +1 -1
  28. package/package.json +2 -2
  29. package/types/package.json +1 -1
  30. package/utilities/package.json +2 -2
  31. package/database/dist/commonjs/aggregate.d.ts +0 -29
  32. package/database/dist/commonjs/aggregate.js +0 -156
  33. package/database/dist/commonjs/collection.d.ts +0 -9
  34. package/database/dist/commonjs/collection.js +0 -49
  35. package/database/dist/commonjs/command.d.ts +0 -175
  36. package/database/dist/commonjs/command.js +0 -299
  37. package/database/dist/commonjs/commands/logic.d.ts +0 -24
  38. package/database/dist/commonjs/commands/logic.js +0 -89
  39. package/database/dist/commonjs/commands/query.d.ts +0 -68
  40. package/database/dist/commonjs/commands/query.js +0 -160
  41. package/database/dist/commonjs/commands/update.d.ts +0 -29
  42. package/database/dist/commonjs/commands/update.js +0 -51
  43. package/database/dist/commonjs/config/app.config.d.ts +0 -6
  44. package/database/dist/commonjs/config/app.config.js +0 -7
  45. package/database/dist/commonjs/config/error.config.d.ts +0 -3
  46. package/database/dist/commonjs/config/error.config.js +0 -16
  47. package/database/dist/commonjs/const/code.d.ts +0 -30
  48. package/database/dist/commonjs/const/code.js +0 -33
  49. package/database/dist/commonjs/constant.d.ts +0 -51
  50. package/database/dist/commonjs/constant.js +0 -75
  51. package/database/dist/commonjs/document.d.ts +0 -11
  52. package/database/dist/commonjs/document.js +0 -260
  53. package/database/dist/commonjs/geo/index.d.ts +0 -6
  54. package/database/dist/commonjs/geo/index.js +0 -22
  55. package/database/dist/commonjs/geo/interface.d.ts +0 -24
  56. package/database/dist/commonjs/geo/interface.js +0 -2
  57. package/database/dist/commonjs/geo/lineString.d.ts +0 -19
  58. package/database/dist/commonjs/geo/lineString.js +0 -86
  59. package/database/dist/commonjs/geo/multiLineString.d.ts +0 -18
  60. package/database/dist/commonjs/geo/multiLineString.js +0 -95
  61. package/database/dist/commonjs/geo/multiPoint.d.ts +0 -18
  62. package/database/dist/commonjs/geo/multiPoint.js +0 -79
  63. package/database/dist/commonjs/geo/multiPolygon.d.ts +0 -18
  64. package/database/dist/commonjs/geo/multiPolygon.js +0 -122
  65. package/database/dist/commonjs/geo/point.d.ts +0 -19
  66. package/database/dist/commonjs/geo/point.js +0 -50
  67. package/database/dist/commonjs/geo/polygon.d.ts +0 -19
  68. package/database/dist/commonjs/geo/polygon.js +0 -109
  69. package/database/dist/commonjs/helper/symbol.d.ts +0 -14
  70. package/database/dist/commonjs/helper/symbol.js +0 -31
  71. package/database/dist/commonjs/index.d.ts +0 -40
  72. package/database/dist/commonjs/index.js +0 -61
  73. package/database/dist/commonjs/lib/util.d.ts +0 -1
  74. package/database/dist/commonjs/lib/util.js +0 -26
  75. package/database/dist/commonjs/operator-map.d.ts +0 -4
  76. package/database/dist/commonjs/operator-map.js +0 -24
  77. package/database/dist/commonjs/query.d.ts +0 -22
  78. package/database/dist/commonjs/query.js +0 -252
  79. package/database/dist/commonjs/regexp/index.d.ts +0 -14
  80. package/database/dist/commonjs/regexp/index.js +0 -33
  81. package/database/dist/commonjs/serializer/common.d.ts +0 -11
  82. package/database/dist/commonjs/serializer/common.js +0 -127
  83. package/database/dist/commonjs/serializer/datatype.d.ts +0 -7
  84. package/database/dist/commonjs/serializer/datatype.js +0 -132
  85. package/database/dist/commonjs/serializer/query.d.ts +0 -7
  86. package/database/dist/commonjs/serializer/query.js +0 -232
  87. package/database/dist/commonjs/serializer/update.d.ts +0 -15
  88. package/database/dist/commonjs/serializer/update.js +0 -142
  89. package/database/dist/commonjs/serverDate/index.d.ts +0 -13
  90. package/database/dist/commonjs/serverDate/index.js +0 -30
  91. package/database/dist/commonjs/transaction/collection.d.ts +0 -7
  92. package/database/dist/commonjs/transaction/collection.js +0 -49
  93. package/database/dist/commonjs/transaction/document.d.ts +0 -27
  94. package/database/dist/commonjs/transaction/document.js +0 -205
  95. package/database/dist/commonjs/transaction/index.d.ts +0 -30
  96. package/database/dist/commonjs/transaction/index.js +0 -215
  97. package/database/dist/commonjs/transaction/query.d.ts +0 -43
  98. package/database/dist/commonjs/transaction/query.js +0 -261
  99. package/database/dist/commonjs/typings/index.d.ts +0 -40
  100. package/database/dist/commonjs/typings/index.js +0 -2
  101. package/database/dist/commonjs/typings/realtime.d.ts +0 -219
  102. package/database/dist/commonjs/typings/realtime.js +0 -2
  103. package/database/dist/commonjs/util.d.ts +0 -9
  104. package/database/dist/commonjs/util.js +0 -145
  105. package/database/dist/commonjs/utils/error.d.ts +0 -38
  106. package/database/dist/commonjs/utils/error.js +0 -91
  107. package/database/dist/commonjs/utils/msg.d.ts +0 -0
  108. package/database/dist/commonjs/utils/msg.js +0 -0
  109. package/database/dist/commonjs/utils/symbol.d.ts +0 -8
  110. package/database/dist/commonjs/utils/symbol.js +0 -58
  111. package/database/dist/commonjs/utils/type.d.ts +0 -13
  112. package/database/dist/commonjs/utils/type.js +0 -34
  113. package/database/dist/commonjs/utils/utils.d.ts +0 -4
  114. package/database/dist/commonjs/utils/utils.js +0 -39
  115. package/database/dist/commonjs/validate.d.ts +0 -1
  116. package/database/dist/commonjs/validate.js +0 -60
  117. package/database/dist/esm/aggregate.d.ts +0 -29
  118. package/database/dist/esm/aggregate.js +0 -154
  119. package/database/dist/esm/collection.d.ts +0 -9
  120. package/database/dist/esm/collection.js +0 -46
  121. package/database/dist/esm/command.d.ts +0 -175
  122. package/database/dist/esm/command.js +0 -296
  123. package/database/dist/esm/commands/logic.d.ts +0 -24
  124. package/database/dist/esm/commands/logic.js +0 -84
  125. package/database/dist/esm/commands/query.d.ts +0 -68
  126. package/database/dist/esm/commands/query.js +0 -154
  127. package/database/dist/esm/commands/update.d.ts +0 -29
  128. package/database/dist/esm/commands/update.js +0 -46
  129. package/database/dist/esm/config/app.config.d.ts +0 -6
  130. package/database/dist/esm/config/app.config.js +0 -5
  131. package/database/dist/esm/config/error.config.d.ts +0 -3
  132. package/database/dist/esm/config/error.config.js +0 -13
  133. package/database/dist/esm/const/code.d.ts +0 -30
  134. package/database/dist/esm/const/code.js +0 -30
  135. package/database/dist/esm/constant.d.ts +0 -51
  136. package/database/dist/esm/constant.js +0 -65
  137. package/database/dist/esm/document.d.ts +0 -11
  138. package/database/dist/esm/document.js +0 -257
  139. package/database/dist/esm/geo/index.d.ts +0 -6
  140. package/database/dist/esm/geo/index.js +0 -6
  141. package/database/dist/esm/geo/interface.d.ts +0 -24
  142. package/database/dist/esm/geo/interface.js +0 -1
  143. package/database/dist/esm/geo/lineString.d.ts +0 -19
  144. package/database/dist/esm/geo/lineString.js +0 -83
  145. package/database/dist/esm/geo/multiLineString.d.ts +0 -18
  146. package/database/dist/esm/geo/multiLineString.js +0 -92
  147. package/database/dist/esm/geo/multiPoint.d.ts +0 -18
  148. package/database/dist/esm/geo/multiPoint.js +0 -76
  149. package/database/dist/esm/geo/multiPolygon.d.ts +0 -18
  150. package/database/dist/esm/geo/multiPolygon.js +0 -119
  151. package/database/dist/esm/geo/point.d.ts +0 -19
  152. package/database/dist/esm/geo/point.js +0 -47
  153. package/database/dist/esm/geo/polygon.d.ts +0 -19
  154. package/database/dist/esm/geo/polygon.js +0 -106
  155. package/database/dist/esm/helper/symbol.d.ts +0 -14
  156. package/database/dist/esm/helper/symbol.js +0 -14
  157. package/database/dist/esm/index.d.ts +0 -40
  158. package/database/dist/esm/index.js +0 -55
  159. package/database/dist/esm/lib/util.d.ts +0 -1
  160. package/database/dist/esm/lib/util.js +0 -22
  161. package/database/dist/esm/operator-map.d.ts +0 -4
  162. package/database/dist/esm/operator-map.js +0 -20
  163. package/database/dist/esm/query.d.ts +0 -22
  164. package/database/dist/esm/query.js +0 -249
  165. package/database/dist/esm/regexp/index.d.ts +0 -14
  166. package/database/dist/esm/regexp/index.js +0 -29
  167. package/database/dist/esm/serializer/common.d.ts +0 -11
  168. package/database/dist/esm/serializer/common.js +0 -118
  169. package/database/dist/esm/serializer/datatype.d.ts +0 -7
  170. package/database/dist/esm/serializer/datatype.js +0 -127
  171. package/database/dist/esm/serializer/query.d.ts +0 -7
  172. package/database/dist/esm/serializer/query.js +0 -229
  173. package/database/dist/esm/serializer/update.d.ts +0 -15
  174. package/database/dist/esm/serializer/update.js +0 -139
  175. package/database/dist/esm/serverDate/index.d.ts +0 -13
  176. package/database/dist/esm/serverDate/index.js +0 -26
  177. package/database/dist/esm/transaction/collection.d.ts +0 -7
  178. package/database/dist/esm/transaction/collection.js +0 -46
  179. package/database/dist/esm/transaction/document.d.ts +0 -27
  180. package/database/dist/esm/transaction/document.js +0 -202
  181. package/database/dist/esm/transaction/index.d.ts +0 -30
  182. package/database/dist/esm/transaction/index.js +0 -210
  183. package/database/dist/esm/transaction/query.d.ts +0 -43
  184. package/database/dist/esm/transaction/query.js +0 -258
  185. package/database/dist/esm/typings/index.d.ts +0 -40
  186. package/database/dist/esm/typings/index.js +0 -1
  187. package/database/dist/esm/typings/realtime.d.ts +0 -219
  188. package/database/dist/esm/typings/realtime.js +0 -1
  189. package/database/dist/esm/util.d.ts +0 -9
  190. package/database/dist/esm/util.js +0 -142
  191. package/database/dist/esm/utils/error.d.ts +0 -38
  192. package/database/dist/esm/utils/error.js +0 -84
  193. package/database/dist/esm/utils/msg.d.ts +0 -0
  194. package/database/dist/esm/utils/msg.js +0 -0
  195. package/database/dist/esm/utils/symbol.d.ts +0 -8
  196. package/database/dist/esm/utils/symbol.js +0 -55
  197. package/database/dist/esm/utils/type.d.ts +0 -13
  198. package/database/dist/esm/utils/type.js +0 -20
  199. package/database/dist/esm/utils/utils.d.ts +0 -4
  200. package/database/dist/esm/utils/utils.js +0 -33
  201. package/database/dist/esm/validate.d.ts +0 -1
  202. package/database/dist/esm/validate.js +0 -57
@@ -1,249 +0,0 @@
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
- import { createPromiseCallback } from './lib/util';
13
- import { QueryType } from './constant';
14
- import { Db } from './index';
15
- import { Validate } from './validate';
16
- import { Util } from './util';
17
- import { QuerySerializer } from './serializer/query';
18
- import { UpdateSerializer } from './serializer/update';
19
- import { ErrorCode } from './constant';
20
- import { getWsInstance } from './utils/utils';
21
- var Query = (function () {
22
- function Query(db, coll, fieldFilters, fieldOrders, queryOptions) {
23
- var _this = this;
24
- this.watch = function (options) {
25
- var ws = getWsInstance(_this._db);
26
- 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
27
- ? _this._fieldOrders.reduce(function (acc, cur) {
28
- acc[cur.field] = cur.direction;
29
- return acc;
30
- }, {})
31
- : undefined }));
32
- };
33
- this._db = db;
34
- this._coll = coll;
35
- this._fieldFilters = fieldFilters;
36
- this._fieldOrders = fieldOrders || [];
37
- this._queryOptions = queryOptions || {};
38
- this._request = Db.createRequest(this._db.config);
39
- }
40
- Query.prototype.get = function (callback) {
41
- callback = callback || createPromiseCallback();
42
- var newOder = [];
43
- if (this._fieldOrders) {
44
- this._fieldOrders.forEach(function (order) {
45
- newOder.push(order);
46
- });
47
- }
48
- var param = {
49
- collectionName: this._coll,
50
- queryType: QueryType.WHERE
51
- };
52
- if (this._fieldFilters) {
53
- param.query = this._fieldFilters;
54
- }
55
- if (newOder.length > 0) {
56
- param.order = newOder;
57
- }
58
- if (this._queryOptions.offset) {
59
- param.offset = this._queryOptions.offset;
60
- }
61
- if (this._queryOptions.limit) {
62
- param.limit = this._queryOptions.limit < 1000 ? this._queryOptions.limit : 1000;
63
- }
64
- else {
65
- param.limit = 100;
66
- }
67
- if (this._queryOptions.projection) {
68
- param.projection = this._queryOptions.projection;
69
- }
70
- this._request
71
- .send('database.queryDocument', param)
72
- .then(function (res) {
73
- if (res.code) {
74
- callback(0, res);
75
- }
76
- else {
77
- var documents = Util.formatResDocumentData(res.data.list);
78
- var result = {
79
- data: documents,
80
- requestId: res.requestId
81
- };
82
- if (res.total !== undefined)
83
- result.total = res.total;
84
- if (res.limit !== undefined)
85
- result.limit = res.limit;
86
- if (res.offset !== undefined)
87
- result.offset = res.offset;
88
- callback(0, result);
89
- }
90
- })
91
- .catch(function (err) {
92
- callback(err);
93
- });
94
- return callback.promise;
95
- };
96
- Query.prototype.count = function (callback) {
97
- callback = callback || createPromiseCallback();
98
- var param = {
99
- collectionName: this._coll,
100
- queryType: QueryType.WHERE
101
- };
102
- if (this._fieldFilters) {
103
- param.query = this._fieldFilters;
104
- }
105
- this._request
106
- .send('database.countDocument', param)
107
- .then(function (res) {
108
- if (res.code) {
109
- callback(0, res);
110
- }
111
- else {
112
- callback(0, {
113
- requestId: res.requestId,
114
- total: res.data.total
115
- });
116
- }
117
- })
118
- .catch(function (e) {
119
- callback(e);
120
- });
121
- return callback.promise;
122
- };
123
- Query.prototype.where = function (query) {
124
- if (Object.prototype.toString.call(query).slice(8, -1) !== 'Object') {
125
- throw Error(ErrorCode.QueryParamTypeError);
126
- }
127
- var keys = Object.keys(query);
128
- var checkFlag = keys.some(function (item) {
129
- return query[item] !== undefined;
130
- });
131
- if (keys.length && !checkFlag) {
132
- throw Error(ErrorCode.QueryParamValueError);
133
- }
134
- return new Query(this._db, this._coll, QuerySerializer.encode(query), this._fieldOrders, this._queryOptions);
135
- };
136
- Query.prototype.orderBy = function (fieldPath, directionStr) {
137
- Validate.isFieldPath(fieldPath);
138
- Validate.isFieldOrder(directionStr);
139
- var newOrder = {
140
- field: fieldPath,
141
- direction: directionStr
142
- };
143
- var combinedOrders = this._fieldOrders.concat(newOrder);
144
- return new Query(this._db, this._coll, this._fieldFilters, combinedOrders, this._queryOptions);
145
- };
146
- Query.prototype.limit = function (limit) {
147
- Validate.isInteger('limit', limit);
148
- var option = __assign({}, this._queryOptions);
149
- option.limit = limit;
150
- return new Query(this._db, this._coll, this._fieldFilters, this._fieldOrders, option);
151
- };
152
- Query.prototype.skip = function (offset) {
153
- Validate.isInteger('offset', offset);
154
- var option = __assign({}, this._queryOptions);
155
- option.offset = offset;
156
- return new Query(this._db, this._coll, this._fieldFilters, this._fieldOrders, option);
157
- };
158
- Query.prototype.update = function (data, callback) {
159
- callback = callback || createPromiseCallback();
160
- if (!data || typeof data !== 'object') {
161
- return Promise.resolve({
162
- code: 'INVALID_PARAM',
163
- message: '参数必需是非空对象'
164
- });
165
- }
166
- if (data.hasOwnProperty('_id')) {
167
- return Promise.resolve({
168
- code: 'INVALID_PARAM',
169
- message: '不能更新_id的值'
170
- });
171
- }
172
- var param = {
173
- collectionName: this._coll,
174
- query: this._fieldFilters,
175
- queryType: QueryType.WHERE,
176
- multi: true,
177
- merge: true,
178
- upsert: false,
179
- data: UpdateSerializer.encode(data)
180
- };
181
- this._request
182
- .send('database.updateDocument', param)
183
- .then(function (res) {
184
- if (res.code) {
185
- callback(0, res);
186
- }
187
- else {
188
- callback(0, {
189
- requestId: res.requestId,
190
- updated: res.data.updated,
191
- upsertId: res.data.upsert_id
192
- });
193
- }
194
- })
195
- .catch(function (e) {
196
- callback(e);
197
- });
198
- return callback.promise;
199
- };
200
- Query.prototype.field = function (projection) {
201
- for (var k in projection) {
202
- if (projection[k]) {
203
- if (typeof projection[k] !== 'object') {
204
- projection[k] = 1;
205
- }
206
- }
207
- else {
208
- projection[k] = 0;
209
- }
210
- }
211
- var option = __assign({}, this._queryOptions);
212
- option.projection = projection;
213
- return new Query(this._db, this._coll, this._fieldFilters, this._fieldOrders, option);
214
- };
215
- Query.prototype.remove = function (callback) {
216
- callback = callback || createPromiseCallback();
217
- if (Object.keys(this._queryOptions).length > 0) {
218
- console.warn('`offset`, `limit` and `projection` are not supported in remove() operation');
219
- }
220
- if (this._fieldOrders.length > 0) {
221
- console.warn('`orderBy` is not supported in remove() operation');
222
- }
223
- var param = {
224
- collectionName: this._coll,
225
- query: QuerySerializer.encode(this._fieldFilters),
226
- queryType: QueryType.WHERE,
227
- multi: true
228
- };
229
- this._request
230
- .send('database.deleteDocument', param)
231
- .then(function (res) {
232
- if (res.code) {
233
- callback(0, res);
234
- }
235
- else {
236
- callback(0, {
237
- requestId: res.requestId,
238
- deleted: res.data.deleted
239
- });
240
- }
241
- })
242
- .catch(function (e) {
243
- callback(e);
244
- });
245
- return callback.promise;
246
- };
247
- return Query;
248
- }());
249
- export { Query };
@@ -1,14 +0,0 @@
1
- export declare class RegExp {
2
- $regex: string;
3
- $options: string;
4
- constructor({ regexp, options }: {
5
- regexp: any;
6
- options: any;
7
- });
8
- parse(): {
9
- $regex: string;
10
- $options: string;
11
- };
12
- get _internalType(): import("../utils/symbol").InternalSymbol;
13
- }
14
- export declare function RegExpConstructor(param: any): RegExp;
@@ -1,29 +0,0 @@
1
- import { SYMBOL_REGEXP } from '../helper/symbol';
2
- var RegExp = (function () {
3
- function RegExp(_a) {
4
- var regexp = _a.regexp, options = _a.options;
5
- if (!regexp) {
6
- throw new TypeError('regexp must be a string');
7
- }
8
- this.$regex = regexp;
9
- this.$options = options;
10
- }
11
- RegExp.prototype.parse = function () {
12
- return {
13
- $regex: this.$regex,
14
- $options: this.$options
15
- };
16
- };
17
- Object.defineProperty(RegExp.prototype, "_internalType", {
18
- get: function () {
19
- return SYMBOL_REGEXP;
20
- },
21
- enumerable: false,
22
- configurable: true
23
- });
24
- return RegExp;
25
- }());
26
- export { RegExp };
27
- export function RegExpConstructor(param) {
28
- return new RegExp(param);
29
- }
@@ -1,11 +0,0 @@
1
- import { LogicCommand } from '../commands/logic';
2
- export type IQueryCondition = Record<string, any> | LogicCommand;
3
- export type AnyObject = {
4
- [x: string]: any;
5
- };
6
- export declare function flattenQueryObject(query: Record<string, any>): Record<string, any>;
7
- export declare function flattenObject(object: AnyObject): AnyObject;
8
- export declare function mergeConditionAfterEncode(query: Record<string, any>, condition: Record<string, any>, key: string): void;
9
- export declare function isConversionRequired(val: any): boolean;
10
- export declare function encodeInternalDataType(val: any): IQueryCondition;
11
- export declare function decodeInternalDataType(object: AnyObject): any;
@@ -1,118 +0,0 @@
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
- };
37
- import { getType, isObject, isArray, isDate, isRegExp, isInternalObject } from '../utils/type';
38
- import { serialize as serializeInternalDataType, deserialize as deserializeInternalDataType } from './datatype';
39
- function flatten(query, shouldPreserverObject, parents, visited) {
40
- var cloned = __assign({}, query);
41
- for (var key in query) {
42
- if (/^\$/.test(key))
43
- continue;
44
- var value = query[key];
45
- if (!value)
46
- continue;
47
- if (isObject(value) && !shouldPreserverObject(value)) {
48
- if (visited.indexOf(value) > -1) {
49
- throw new Error('Cannot convert circular structure to JSON');
50
- }
51
- var newParents = __spreadArray(__spreadArray([], __read(parents), false), [
52
- key,
53
- ], false);
54
- var newVisited = __spreadArray(__spreadArray([], __read(visited), false), [
55
- value,
56
- ], false);
57
- var flattenedChild = flatten(value, shouldPreserverObject, newParents, newVisited);
58
- cloned[key] = flattenedChild;
59
- var hasKeyNotCombined = false;
60
- for (var childKey in flattenedChild) {
61
- if (!/^\$/.test(childKey)) {
62
- cloned["".concat(key, ".").concat(childKey)] = flattenedChild[childKey];
63
- delete cloned[key][childKey];
64
- }
65
- else {
66
- hasKeyNotCombined = true;
67
- }
68
- }
69
- if (!hasKeyNotCombined) {
70
- delete cloned[key];
71
- }
72
- }
73
- }
74
- return cloned;
75
- }
76
- export function flattenQueryObject(query) {
77
- return flatten(query, isConversionRequired, [], [query]);
78
- }
79
- export function flattenObject(object) {
80
- return flatten(object, function (_) { return false; }, [], [object]);
81
- }
82
- export function mergeConditionAfterEncode(query, condition, key) {
83
- if (!condition[key]) {
84
- delete query[key];
85
- }
86
- for (var conditionKey in condition) {
87
- if (query[conditionKey]) {
88
- if (isArray(query[conditionKey])) {
89
- query[conditionKey].push(condition[conditionKey]);
90
- }
91
- else if (isObject(query[conditionKey])) {
92
- if (isObject(condition[conditionKey])) {
93
- Object.assign(query[conditionKey], condition[conditionKey]);
94
- }
95
- else {
96
- console.warn("unmergable condition, query is object but condition is ".concat(getType(condition), ", can only overwrite"), condition, key);
97
- query[conditionKey] = condition[conditionKey];
98
- }
99
- }
100
- else {
101
- console.warn("to-merge query is of type ".concat(getType(query), ", can only overwrite"), query, condition, key);
102
- query[conditionKey] = condition[conditionKey];
103
- }
104
- }
105
- else {
106
- query[conditionKey] = condition[conditionKey];
107
- }
108
- }
109
- }
110
- export function isConversionRequired(val) {
111
- return isInternalObject(val) || isDate(val) || isRegExp(val);
112
- }
113
- export function encodeInternalDataType(val) {
114
- return serializeInternalDataType(val);
115
- }
116
- export function decodeInternalDataType(object) {
117
- return deserializeInternalDataType(object);
118
- }
@@ -1,7 +0,0 @@
1
- import { LogicCommand } from '../commands/logic';
2
- export type IQueryCondition = Record<string, any> | LogicCommand;
3
- export type AnyObject = {
4
- [x: string]: any;
5
- };
6
- export declare function serialize(val: any): IQueryCondition;
7
- export declare function deserialize(object: AnyObject): any;
@@ -1,127 +0,0 @@
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
- };
37
- import { SYMBOL_GEO_POINT, SYMBOL_SERVER_DATE, SYMBOL_REGEXP } from '../helper/symbol';
38
- import { getType, isObject, isArray, isDate, isNumber, isInternalObject, isRegExp } from '../utils/type';
39
- import { Point } from '../geo/index';
40
- import { ServerDate } from '../serverDate/index';
41
- export function serialize(val) {
42
- return serializeHelper(val, [val]);
43
- }
44
- function serializeHelper(val, visited) {
45
- if (isInternalObject(val)) {
46
- switch (val._internalType) {
47
- case SYMBOL_GEO_POINT: {
48
- return val.toJSON();
49
- }
50
- case SYMBOL_SERVER_DATE: {
51
- return val.parse();
52
- }
53
- case SYMBOL_REGEXP: {
54
- return val.parse();
55
- }
56
- default: {
57
- return val.toJSON ? val.toJSON() : val;
58
- }
59
- }
60
- }
61
- else if (isDate(val)) {
62
- return {
63
- $date: +val,
64
- };
65
- }
66
- else if (isRegExp(val)) {
67
- return {
68
- $regex: val.source,
69
- $options: val.flags,
70
- };
71
- }
72
- else if (isArray(val)) {
73
- return val.map(function (item) {
74
- if (visited.indexOf(item) > -1) {
75
- throw new Error('Cannot convert circular structure to JSON');
76
- }
77
- return serializeHelper(item, __spreadArray(__spreadArray([], __read(visited), false), [
78
- item,
79
- ], false));
80
- });
81
- }
82
- else if (isObject(val)) {
83
- var ret = __assign({}, val);
84
- for (var key in ret) {
85
- if (visited.indexOf(ret[key]) > -1) {
86
- throw new Error('Cannot convert circular structure to JSON');
87
- }
88
- ret[key] = serializeHelper(ret[key], __spreadArray(__spreadArray([], __read(visited), false), [
89
- ret[key],
90
- ], false));
91
- }
92
- return ret;
93
- }
94
- else {
95
- return val;
96
- }
97
- }
98
- export function deserialize(object) {
99
- var ret = __assign({}, object);
100
- for (var key in ret) {
101
- switch (key) {
102
- case '$date': {
103
- switch (getType(ret[key])) {
104
- case 'number': {
105
- return new Date(ret[key]);
106
- }
107
- case 'object': {
108
- return new ServerDate(ret[key]);
109
- }
110
- }
111
- break;
112
- }
113
- case 'type': {
114
- switch (ret.type) {
115
- case 'Point': {
116
- if (isArray(ret.coordinates) && isNumber(ret.coordinates[0]) && isNumber(ret.coordinates[1])) {
117
- return new Point(ret.coordinates[0], ret.coordinates[1]);
118
- }
119
- break;
120
- }
121
- }
122
- break;
123
- }
124
- }
125
- }
126
- return object;
127
- }
@@ -1,7 +0,0 @@
1
- import { QueryCommand } from '../commands/query';
2
- import { LogicCommand } from '../commands/logic';
3
- export type IQueryCondition = Record<string, any> | LogicCommand;
4
- export declare class QuerySerializer {
5
- constructor();
6
- static encode(query: IQueryCondition | QueryCommand | LogicCommand): IQueryCondition;
7
- }