@cloudbase/js-sdk 2.28.8 → 2.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +147 -0
- package/ai/dist/index.esm.js +2 -3
- package/ai/dist/index.esm.js.map +1 -0
- package/ai/dist/index.js +2 -21
- package/ai/dist/index.js.map +1 -0
- package/apis/dist/index.esm.js +2 -3
- package/apis/dist/index.esm.js.map +1 -0
- package/apis/dist/index.js +2 -21
- package/apis/dist/index.js.map +1 -0
- package/app/dist/index.esm.js +2 -11
- package/app/dist/index.esm.js.map +1 -0
- package/app/dist/index.js +2 -18
- package/app/dist/index.js.map +1 -0
- package/auth/dist/index.d.ts +2 -2
- package/auth/dist/index.esm.js +3 -8
- package/auth/dist/index.esm.js.LICENSE.txt +12 -0
- package/auth/dist/index.esm.js.map +1 -0
- package/auth/dist/index.js +3 -13
- package/auth/dist/index.js.LICENSE.txt +12 -0
- package/auth/dist/index.js.map +1 -0
- package/cloudrun/dist/index.esm.js +2 -3
- package/cloudrun/dist/index.esm.js.map +1 -0
- package/cloudrun/dist/index.js +2 -21
- package/cloudrun/dist/index.js.map +1 -0
- package/container/dist/index.d.ts +2 -2
- package/container/dist/index.esm.js +2 -8
- package/container/dist/index.esm.js.map +1 -0
- package/container/dist/index.js +2 -13
- package/container/dist/index.js.map +1 -0
- package/database/dist/commonjs/aggregate.d.ts +29 -0
- package/database/dist/commonjs/aggregate.js +156 -0
- package/database/dist/commonjs/collection.d.ts +9 -0
- package/database/dist/commonjs/collection.js +49 -0
- package/database/dist/commonjs/command.d.ts +175 -0
- package/database/dist/commonjs/command.js +299 -0
- package/database/dist/commonjs/commands/logic.d.ts +24 -0
- package/database/dist/commonjs/commands/logic.js +89 -0
- package/database/dist/commonjs/commands/query.d.ts +68 -0
- package/database/dist/commonjs/commands/query.js +160 -0
- package/database/dist/commonjs/commands/update.d.ts +29 -0
- package/database/dist/commonjs/commands/update.js +51 -0
- package/database/dist/commonjs/config/app.config.d.ts +6 -0
- package/database/dist/commonjs/config/app.config.js +7 -0
- package/database/dist/commonjs/config/error.config.d.ts +3 -0
- package/database/dist/commonjs/config/error.config.js +16 -0
- package/database/dist/commonjs/const/code.d.ts +30 -0
- package/database/dist/commonjs/const/code.js +33 -0
- package/database/dist/commonjs/constant.d.ts +51 -0
- package/database/dist/commonjs/constant.js +75 -0
- package/database/dist/commonjs/document.d.ts +11 -0
- package/database/dist/commonjs/document.js +260 -0
- package/database/dist/commonjs/geo/index.d.ts +6 -0
- package/database/dist/commonjs/geo/index.js +22 -0
- package/database/dist/commonjs/geo/interface.d.ts +24 -0
- package/database/dist/commonjs/geo/interface.js +2 -0
- package/database/dist/commonjs/geo/lineString.d.ts +19 -0
- package/database/dist/commonjs/geo/lineString.js +86 -0
- package/database/dist/commonjs/geo/multiLineString.d.ts +18 -0
- package/database/dist/commonjs/geo/multiLineString.js +95 -0
- package/database/dist/commonjs/geo/multiPoint.d.ts +18 -0
- package/database/dist/commonjs/geo/multiPoint.js +79 -0
- package/database/dist/commonjs/geo/multiPolygon.d.ts +18 -0
- package/database/dist/commonjs/geo/multiPolygon.js +122 -0
- package/database/dist/commonjs/geo/point.d.ts +19 -0
- package/database/dist/commonjs/geo/point.js +50 -0
- package/database/dist/commonjs/geo/polygon.d.ts +19 -0
- package/database/dist/commonjs/geo/polygon.js +109 -0
- package/database/dist/commonjs/helper/symbol.d.ts +14 -0
- package/database/dist/commonjs/helper/symbol.js +31 -0
- package/database/dist/commonjs/index.d.ts +40 -0
- package/database/dist/commonjs/index.js +61 -0
- package/database/dist/commonjs/lib/util.d.ts +1 -0
- package/database/dist/commonjs/lib/util.js +26 -0
- package/database/dist/commonjs/operator-map.d.ts +4 -0
- package/database/dist/commonjs/operator-map.js +24 -0
- package/database/dist/commonjs/query.d.ts +22 -0
- package/database/dist/commonjs/query.js +252 -0
- package/database/dist/commonjs/regexp/index.d.ts +14 -0
- package/database/dist/commonjs/regexp/index.js +33 -0
- package/database/dist/commonjs/serializer/common.d.ts +11 -0
- package/database/dist/commonjs/serializer/common.js +127 -0
- package/database/dist/commonjs/serializer/datatype.d.ts +7 -0
- package/database/dist/commonjs/serializer/datatype.js +132 -0
- package/database/dist/commonjs/serializer/query.d.ts +7 -0
- package/database/dist/commonjs/serializer/query.js +232 -0
- package/database/dist/commonjs/serializer/update.d.ts +15 -0
- package/database/dist/commonjs/serializer/update.js +142 -0
- package/database/dist/commonjs/serverDate/index.d.ts +13 -0
- package/database/dist/commonjs/serverDate/index.js +30 -0
- package/database/dist/commonjs/transaction/collection.d.ts +7 -0
- package/database/dist/commonjs/transaction/collection.js +49 -0
- package/database/dist/commonjs/transaction/document.d.ts +27 -0
- package/database/dist/commonjs/transaction/document.js +205 -0
- package/database/dist/commonjs/transaction/index.d.ts +30 -0
- package/database/dist/commonjs/transaction/index.js +215 -0
- package/database/dist/commonjs/transaction/query.d.ts +43 -0
- package/database/dist/commonjs/transaction/query.js +261 -0
- package/database/dist/commonjs/typings/index.d.ts +40 -0
- package/database/dist/commonjs/typings/index.js +2 -0
- package/database/dist/commonjs/typings/realtime.d.ts +219 -0
- package/database/dist/commonjs/typings/realtime.js +2 -0
- package/database/dist/commonjs/util.d.ts +9 -0
- package/database/dist/commonjs/util.js +145 -0
- package/database/dist/commonjs/utils/error.d.ts +38 -0
- package/database/dist/commonjs/utils/error.js +91 -0
- package/database/dist/commonjs/utils/msg.d.ts +0 -0
- package/database/dist/commonjs/utils/msg.js +0 -0
- package/database/dist/commonjs/utils/symbol.d.ts +8 -0
- package/database/dist/commonjs/utils/symbol.js +58 -0
- package/database/dist/commonjs/utils/type.d.ts +13 -0
- package/database/dist/commonjs/utils/type.js +34 -0
- package/database/dist/commonjs/utils/utils.d.ts +4 -0
- package/database/dist/commonjs/utils/utils.js +39 -0
- package/database/dist/commonjs/validate.d.ts +1 -0
- package/database/dist/commonjs/validate.js +60 -0
- package/database/dist/esm/aggregate.d.ts +29 -0
- package/database/dist/esm/aggregate.js +154 -0
- package/database/dist/esm/collection.d.ts +9 -0
- package/database/dist/esm/collection.js +46 -0
- package/database/dist/esm/command.d.ts +175 -0
- package/database/dist/esm/command.js +296 -0
- package/database/dist/esm/commands/logic.d.ts +24 -0
- package/database/dist/esm/commands/logic.js +84 -0
- package/database/dist/esm/commands/query.d.ts +68 -0
- package/database/dist/esm/commands/query.js +154 -0
- package/database/dist/esm/commands/update.d.ts +29 -0
- package/database/dist/esm/commands/update.js +46 -0
- package/database/dist/esm/config/app.config.d.ts +6 -0
- package/database/dist/esm/config/app.config.js +5 -0
- package/database/dist/esm/config/error.config.d.ts +3 -0
- package/database/dist/esm/config/error.config.js +13 -0
- package/database/dist/esm/const/code.d.ts +30 -0
- package/database/dist/esm/const/code.js +30 -0
- package/database/dist/esm/constant.d.ts +51 -0
- package/database/dist/esm/constant.js +65 -0
- package/database/dist/esm/document.d.ts +11 -0
- package/database/dist/esm/document.js +257 -0
- package/database/dist/esm/geo/index.d.ts +6 -0
- package/database/dist/esm/geo/index.js +6 -0
- package/database/dist/esm/geo/interface.d.ts +24 -0
- package/database/dist/esm/geo/interface.js +1 -0
- package/database/dist/esm/geo/lineString.d.ts +19 -0
- package/database/dist/esm/geo/lineString.js +83 -0
- package/database/dist/esm/geo/multiLineString.d.ts +18 -0
- package/database/dist/esm/geo/multiLineString.js +92 -0
- package/database/dist/esm/geo/multiPoint.d.ts +18 -0
- package/database/dist/esm/geo/multiPoint.js +76 -0
- package/database/dist/esm/geo/multiPolygon.d.ts +18 -0
- package/database/dist/esm/geo/multiPolygon.js +119 -0
- package/database/dist/esm/geo/point.d.ts +19 -0
- package/database/dist/esm/geo/point.js +47 -0
- package/database/dist/esm/geo/polygon.d.ts +19 -0
- package/database/dist/esm/geo/polygon.js +106 -0
- package/database/dist/esm/helper/symbol.d.ts +14 -0
- package/database/dist/esm/helper/symbol.js +14 -0
- package/database/dist/esm/index.d.ts +40 -0
- package/database/dist/esm/index.js +55 -0
- package/database/dist/esm/lib/util.d.ts +1 -0
- package/database/dist/esm/lib/util.js +22 -0
- package/database/dist/esm/operator-map.d.ts +4 -0
- package/database/dist/esm/operator-map.js +20 -0
- package/database/dist/esm/query.d.ts +22 -0
- package/database/dist/esm/query.js +249 -0
- package/database/dist/esm/regexp/index.d.ts +14 -0
- package/database/dist/esm/regexp/index.js +29 -0
- package/database/dist/esm/serializer/common.d.ts +11 -0
- package/database/dist/esm/serializer/common.js +118 -0
- package/database/dist/esm/serializer/datatype.d.ts +7 -0
- package/database/dist/esm/serializer/datatype.js +127 -0
- package/database/dist/esm/serializer/query.d.ts +7 -0
- package/database/dist/esm/serializer/query.js +229 -0
- package/database/dist/esm/serializer/update.d.ts +15 -0
- package/database/dist/esm/serializer/update.js +139 -0
- package/database/dist/esm/serverDate/index.d.ts +13 -0
- package/database/dist/esm/serverDate/index.js +26 -0
- package/database/dist/esm/transaction/collection.d.ts +7 -0
- package/database/dist/esm/transaction/collection.js +46 -0
- package/database/dist/esm/transaction/document.d.ts +27 -0
- package/database/dist/esm/transaction/document.js +202 -0
- package/database/dist/esm/transaction/index.d.ts +30 -0
- package/database/dist/esm/transaction/index.js +210 -0
- package/database/dist/esm/transaction/query.d.ts +43 -0
- package/database/dist/esm/transaction/query.js +258 -0
- package/database/dist/esm/typings/index.d.ts +40 -0
- package/database/dist/esm/typings/index.js +1 -0
- package/database/dist/esm/typings/realtime.d.ts +219 -0
- package/database/dist/esm/typings/realtime.js +1 -0
- package/database/dist/esm/util.d.ts +9 -0
- package/database/dist/esm/util.js +142 -0
- package/database/dist/esm/utils/error.d.ts +38 -0
- package/database/dist/esm/utils/error.js +84 -0
- package/database/dist/esm/utils/msg.d.ts +0 -0
- package/database/dist/esm/utils/msg.js +0 -0
- package/database/dist/esm/utils/symbol.d.ts +8 -0
- package/database/dist/esm/utils/symbol.js +55 -0
- package/database/dist/esm/utils/type.d.ts +13 -0
- package/database/dist/esm/utils/type.js +20 -0
- package/database/dist/esm/utils/utils.d.ts +4 -0
- package/database/dist/esm/utils/utils.js +33 -0
- package/database/dist/esm/validate.d.ts +1 -0
- package/database/dist/esm/validate.js +57 -0
- package/database/package.json +34 -4
- package/dist/index.cjs.js +3 -40
- package/dist/index.cjs.js.LICENSE.txt +12 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.esm.js +3 -35
- package/dist/index.esm.js.LICENSE.txt +12 -0
- package/dist/index.esm.js.map +1 -0
- package/functions/dist/index.d.ts +2 -2
- package/functions/dist/index.esm.js +2 -8
- package/functions/dist/index.esm.js.map +1 -0
- package/functions/dist/index.js +2 -13
- package/functions/dist/index.js.map +1 -0
- package/index.d.ts +654 -45
- package/miniprogram_dist/ai.js +1 -1
- package/miniprogram_dist/apis.js +1 -1
- package/miniprogram_dist/app.js +1 -1
- package/miniprogram_dist/auth.js +1 -1
- package/miniprogram_dist/cloudrun.js +1 -1
- package/miniprogram_dist/container.js +1 -1
- package/miniprogram_dist/database.js +1 -1
- package/miniprogram_dist/functions.js +1 -1
- package/miniprogram_dist/index.js +1 -1
- package/miniprogram_dist/model.js +1 -1
- package/miniprogram_dist/mysql.js +1 -1
- package/miniprogram_dist/oauth.js +2 -1
- package/miniprogram_dist/realtime.js +1 -1
- package/miniprogram_dist/storage.js +1 -1
- package/model/dist/index.esm.js +2 -3
- package/model/dist/index.esm.js.map +1 -0
- package/model/dist/index.js +2 -21
- package/model/dist/index.js.map +1 -0
- package/mysql/dist/index.esm.js +2 -3
- package/mysql/dist/index.esm.js.map +1 -0
- package/mysql/dist/index.js +2 -21
- package/mysql/dist/index.js.map +1 -0
- package/oauth/dist/index.esm.js +3 -3
- package/oauth/dist/index.esm.js.LICENSE.txt +12 -0
- package/oauth/dist/index.esm.js.map +1 -0
- package/oauth/dist/index.js +3 -21
- package/oauth/dist/index.js.LICENSE.txt +12 -0
- package/oauth/dist/index.js.map +1 -0
- package/package.json +113 -20
- package/realtime/dist/index.d.ts +2 -2
- package/realtime/dist/index.esm.js +2 -8
- package/realtime/dist/index.esm.js.map +1 -0
- package/realtime/dist/index.js +2 -13
- package/realtime/dist/index.js.map +1 -0
- package/storage/dist/index.d.ts +2 -2
- package/storage/dist/index.esm.js +2 -4
- package/storage/dist/index.esm.js.map +1 -0
- package/storage/dist/index.js +2 -9
- package/storage/dist/index.js.map +1 -0
- package/types/analytics.d.ts +51 -0
- package/types/auth.d.ts +99 -0
- package/types/cache.d.ts +26 -0
- package/types/cloudrun.d.ts +9 -0
- package/types/component.d.ts +17 -0
- package/types/container.d.ts +93 -0
- package/types/database.d.ts +31 -0
- package/types/events.d.ts +13 -0
- package/types/functions.d.ts +40 -0
- package/types/index.d.ts +211 -0
- package/types/package.json +43 -0
- package/types/realtime.d.ts +350 -0
- package/types/request.d.ts +30 -0
- package/types/storage.d.ts +126 -0
- package/utilities/dist/cjs/adapters/index.d.ts +45 -0
- package/utilities/dist/cjs/adapters/index.js +68 -0
- package/utilities/dist/cjs/adapters/platforms/web.d.ts +20 -0
- package/utilities/dist/cjs/adapters/platforms/web.js +286 -0
- package/utilities/dist/cjs/constants/common.d.ts +6 -0
- package/utilities/dist/cjs/constants/common.js +24 -0
- package/utilities/dist/cjs/constants/errors.d.ts +8 -0
- package/utilities/dist/cjs/constants/errors.js +12 -0
- package/utilities/dist/cjs/constants/index.d.ts +3 -0
- package/utilities/dist/cjs/constants/index.js +21 -0
- package/utilities/dist/cjs/helpers/decorators.d.ts +11 -0
- package/utilities/dist/cjs/helpers/decorators.js +238 -0
- package/utilities/dist/cjs/helpers/index.d.ts +1 -0
- package/utilities/dist/cjs/helpers/index.js +18 -0
- package/utilities/dist/cjs/index.d.ts +13 -0
- package/utilities/dist/cjs/index.js +51 -0
- package/utilities/dist/cjs/libs/abortController.d.ts +9 -0
- package/utilities/dist/cjs/libs/abortController.js +25 -0
- package/utilities/dist/cjs/libs/cache.d.ts +17 -0
- package/utilities/dist/cjs/libs/cache.js +261 -0
- package/utilities/dist/cjs/libs/events.d.ts +27 -0
- package/utilities/dist/cjs/libs/events.js +108 -0
- package/utilities/dist/cjs/libs/langEvent.d.ts +3 -0
- package/utilities/dist/cjs/libs/langEvent.js +7 -0
- package/utilities/dist/cjs/libs/util.d.ts +49 -0
- package/utilities/dist/cjs/libs/util.js +282 -0
- package/utilities/dist/esm/adapters/index.d.ts +45 -0
- package/utilities/dist/esm/adapters/index.js +40 -0
- package/utilities/dist/esm/adapters/platforms/web.d.ts +20 -0
- package/utilities/dist/esm/adapters/platforms/web.js +282 -0
- package/utilities/dist/esm/constants/common.d.ts +6 -0
- package/utilities/dist/esm/constants/common.js +17 -0
- package/utilities/dist/esm/constants/errors.d.ts +8 -0
- package/utilities/dist/esm/constants/errors.js +9 -0
- package/utilities/dist/esm/constants/index.d.ts +3 -0
- package/utilities/dist/esm/constants/index.js +4 -0
- package/utilities/dist/esm/helpers/decorators.d.ts +11 -0
- package/utilities/dist/esm/helpers/decorators.js +234 -0
- package/utilities/dist/esm/helpers/index.d.ts +1 -0
- package/utilities/dist/esm/helpers/index.js +2 -0
- package/utilities/dist/esm/index.d.ts +13 -0
- package/utilities/dist/esm/index.js +14 -0
- package/utilities/dist/esm/libs/abortController.d.ts +9 -0
- package/utilities/dist/esm/libs/abortController.js +23 -0
- package/utilities/dist/esm/libs/cache.d.ts +17 -0
- package/utilities/dist/esm/libs/cache.js +258 -0
- package/utilities/dist/esm/libs/events.d.ts +27 -0
- package/utilities/dist/esm/libs/events.js +102 -0
- package/utilities/dist/esm/libs/langEvent.d.ts +3 -0
- package/utilities/dist/esm/libs/langEvent.js +4 -0
- package/utilities/dist/esm/libs/util.d.ts +49 -0
- package/utilities/dist/esm/libs/util.js +254 -0
- package/utilities/dist/miniprogram/index.js +1 -0
- package/utilities/package.json +26 -0
- package/analytics/dist/index.d.ts +0 -2
- package/analytics/dist/index.esm.js +0 -4
- package/analytics/dist/index.js +0 -9
- package/analytics/package.json +0 -6
- package/database/dist/index.d.ts +0 -3
- package/database/dist/index.esm.js +0 -503
- package/database/dist/index.js +0 -509
- package/miniprogram_dist/analytics.js +0 -1
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.Query = void 0;
|
|
51
|
+
var bson_1 = require("bson");
|
|
52
|
+
var constant_1 = require("../constant");
|
|
53
|
+
var validate_1 = require("../validate");
|
|
54
|
+
var query_1 = require("../serializer/query");
|
|
55
|
+
var update_1 = require("../serializer/update");
|
|
56
|
+
var util_1 = require("../util");
|
|
57
|
+
var GET_DOC = 'database.getInTransaction';
|
|
58
|
+
var UPDATE_DOC = 'database.updateDocInTransaction';
|
|
59
|
+
var DELETE_DOC = 'database.deleteDocInTransaction';
|
|
60
|
+
var Query = (function () {
|
|
61
|
+
function Query(transaction, coll, fieldFilters, fieldOrders, queryOptions) {
|
|
62
|
+
this._coll = coll;
|
|
63
|
+
this._transaction = transaction;
|
|
64
|
+
this._fieldFilters = fieldFilters;
|
|
65
|
+
this._fieldOrders = fieldOrders || [];
|
|
66
|
+
this._queryOptions = queryOptions || {};
|
|
67
|
+
this._request = this._transaction.getRequestMethod();
|
|
68
|
+
this._transactionId = this._transaction.getTransactionId();
|
|
69
|
+
}
|
|
70
|
+
Query.prototype.where = function (query) {
|
|
71
|
+
if (Object.prototype.toString.call(query).slice(8, -1) !== 'Object') {
|
|
72
|
+
throw Error(constant_1.ErrorCode.QueryParamTypeError);
|
|
73
|
+
}
|
|
74
|
+
var keys = Object.keys(query);
|
|
75
|
+
var checkFlag = keys.some(function (item) {
|
|
76
|
+
return query[item] !== undefined;
|
|
77
|
+
});
|
|
78
|
+
if (keys.length && !checkFlag) {
|
|
79
|
+
throw Error(constant_1.ErrorCode.QueryParamValueError);
|
|
80
|
+
}
|
|
81
|
+
return new Query(this._transaction, this._coll, query_1.QuerySerializer.encode(query), this._fieldOrders, this._queryOptions);
|
|
82
|
+
};
|
|
83
|
+
Query.prototype.orderBy = function (fieldPath, directionStr) {
|
|
84
|
+
validate_1.Validate.isFieldPath(fieldPath);
|
|
85
|
+
validate_1.Validate.isFieldOrder(directionStr);
|
|
86
|
+
var newOrder = {
|
|
87
|
+
field: fieldPath,
|
|
88
|
+
direction: directionStr
|
|
89
|
+
};
|
|
90
|
+
var combinedOrders = this._fieldOrders.concat(newOrder);
|
|
91
|
+
return new Query(this._transaction, this._coll, this._fieldFilters, combinedOrders, this._queryOptions);
|
|
92
|
+
};
|
|
93
|
+
Query.prototype.limit = function (limit) {
|
|
94
|
+
validate_1.Validate.isInteger('limit', limit);
|
|
95
|
+
var option = __assign({}, this._queryOptions);
|
|
96
|
+
option.limit = limit;
|
|
97
|
+
return new Query(this._transaction, this._coll, this._fieldFilters, this._fieldOrders, option);
|
|
98
|
+
};
|
|
99
|
+
Query.prototype.skip = function (offset) {
|
|
100
|
+
validate_1.Validate.isInteger('offset', offset);
|
|
101
|
+
var option = __assign({}, this._queryOptions);
|
|
102
|
+
option.offset = offset;
|
|
103
|
+
return new Query(this._transaction, this._coll, this._fieldFilters, this._fieldOrders, option);
|
|
104
|
+
};
|
|
105
|
+
Query.prototype.field = function (projection) {
|
|
106
|
+
for (var k in projection) {
|
|
107
|
+
if (projection[k]) {
|
|
108
|
+
if (typeof projection[k] !== 'object') {
|
|
109
|
+
projection[k] = 1;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
projection[k] = 0;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
var option = __assign({}, this._queryOptions);
|
|
117
|
+
option.projection = projection;
|
|
118
|
+
return new Query(this._transaction, this._coll, this._fieldFilters, this._fieldOrders, option);
|
|
119
|
+
};
|
|
120
|
+
Query.prototype.get = function () {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
122
|
+
var newOrder, param, res, data, documents, result;
|
|
123
|
+
return __generator(this, function (_a) {
|
|
124
|
+
switch (_a.label) {
|
|
125
|
+
case 0:
|
|
126
|
+
newOrder = [];
|
|
127
|
+
if (this._fieldOrders) {
|
|
128
|
+
this._fieldOrders.forEach(function (order) {
|
|
129
|
+
newOrder.push(order);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
param = {
|
|
133
|
+
collectionName: this._coll,
|
|
134
|
+
transactionId: this._transactionId
|
|
135
|
+
};
|
|
136
|
+
if (this._fieldFilters) {
|
|
137
|
+
param.query = this._fieldFilters;
|
|
138
|
+
}
|
|
139
|
+
if (newOrder.length > 0) {
|
|
140
|
+
param.order = newOrder;
|
|
141
|
+
}
|
|
142
|
+
if (this._queryOptions.offset) {
|
|
143
|
+
param.offset = this._queryOptions.offset;
|
|
144
|
+
}
|
|
145
|
+
if (this._queryOptions.limit) {
|
|
146
|
+
param.limit = this._queryOptions.limit < 1000 ? this._queryOptions.limit : 1000;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
param.limit = 100;
|
|
150
|
+
}
|
|
151
|
+
if (this._queryOptions.projection) {
|
|
152
|
+
param.projection = this._queryOptions.projection;
|
|
153
|
+
}
|
|
154
|
+
return [4, this._request.send(GET_DOC, param)];
|
|
155
|
+
case 1:
|
|
156
|
+
res = _a.sent();
|
|
157
|
+
if (res.code)
|
|
158
|
+
throw res;
|
|
159
|
+
data = res.data !== 'null' ? bson_1.EJSON.parse(res.data) : null;
|
|
160
|
+
documents = data ? (Array.isArray(data) ? util_1.Util.formatResDocumentData(data) : [util_1.Util.formatField(data)]) : [];
|
|
161
|
+
result = {
|
|
162
|
+
data: documents,
|
|
163
|
+
requestId: res.requestId
|
|
164
|
+
};
|
|
165
|
+
if (res.total !== undefined)
|
|
166
|
+
result.total = res.total;
|
|
167
|
+
if (res.limit !== undefined)
|
|
168
|
+
result.limit = res.limit;
|
|
169
|
+
if (res.offset !== undefined)
|
|
170
|
+
result.offset = res.offset;
|
|
171
|
+
return [2, result];
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
Query.prototype.count = function () {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
178
|
+
var param, res, data, total;
|
|
179
|
+
return __generator(this, function (_a) {
|
|
180
|
+
switch (_a.label) {
|
|
181
|
+
case 0:
|
|
182
|
+
param = {
|
|
183
|
+
collectionName: this._coll,
|
|
184
|
+
transactionId: this._transactionId
|
|
185
|
+
};
|
|
186
|
+
if (this._fieldFilters) {
|
|
187
|
+
param.query = this._fieldFilters;
|
|
188
|
+
}
|
|
189
|
+
return [4, this._request.send(GET_DOC, param)];
|
|
190
|
+
case 1:
|
|
191
|
+
res = _a.sent();
|
|
192
|
+
if (res.code)
|
|
193
|
+
throw res;
|
|
194
|
+
data = res.data !== 'null' ? bson_1.EJSON.parse(res.data) : null;
|
|
195
|
+
total = Array.isArray(data) ? data.length : (data ? 1 : 0);
|
|
196
|
+
return [2, {
|
|
197
|
+
requestId: res.requestId,
|
|
198
|
+
total: res.total !== undefined ? res.total : total
|
|
199
|
+
}];
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
Query.prototype.update = function (data) {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
206
|
+
var param, res;
|
|
207
|
+
return __generator(this, function (_a) {
|
|
208
|
+
switch (_a.label) {
|
|
209
|
+
case 0:
|
|
210
|
+
if (!data || typeof data !== 'object') {
|
|
211
|
+
throw new Error('参数必需是非空对象');
|
|
212
|
+
}
|
|
213
|
+
if (data.hasOwnProperty('_id')) {
|
|
214
|
+
throw new Error('不能更新_id的值');
|
|
215
|
+
}
|
|
216
|
+
param = {
|
|
217
|
+
collectionName: this._coll,
|
|
218
|
+
transactionId: this._transactionId,
|
|
219
|
+
query: this._fieldFilters,
|
|
220
|
+
data: bson_1.EJSON.stringify(update_1.UpdateSerializer.encode(data), { relaxed: false })
|
|
221
|
+
};
|
|
222
|
+
return [4, this._request.send(UPDATE_DOC, param)];
|
|
223
|
+
case 1:
|
|
224
|
+
res = _a.sent();
|
|
225
|
+
if (res.code)
|
|
226
|
+
throw res;
|
|
227
|
+
return [2, __assign(__assign({}, res), { updated: bson_1.EJSON.parse(res.updated) })];
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
Query.prototype.remove = function () {
|
|
233
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
234
|
+
var param, res;
|
|
235
|
+
return __generator(this, function (_a) {
|
|
236
|
+
switch (_a.label) {
|
|
237
|
+
case 0:
|
|
238
|
+
if (Object.keys(this._queryOptions).length > 0) {
|
|
239
|
+
console.warn('`offset`, `limit` and `projection` are not supported in remove() operation');
|
|
240
|
+
}
|
|
241
|
+
if (this._fieldOrders.length > 0) {
|
|
242
|
+
console.warn('`orderBy` is not supported in remove() operation');
|
|
243
|
+
}
|
|
244
|
+
param = {
|
|
245
|
+
collectionName: this._coll,
|
|
246
|
+
transactionId: this._transactionId,
|
|
247
|
+
query: this._fieldFilters
|
|
248
|
+
};
|
|
249
|
+
return [4, this._request.send(DELETE_DOC, param)];
|
|
250
|
+
case 1:
|
|
251
|
+
res = _a.sent();
|
|
252
|
+
if (res.code)
|
|
253
|
+
throw res;
|
|
254
|
+
return [2, __assign(__assign({}, res), { deleted: bson_1.EJSON.parse(res.deleted) })];
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
return Query;
|
|
260
|
+
}());
|
|
261
|
+
exports.Query = Query;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type DataType = 'init' | 'update' | 'add' | 'remove' | 'replace' | 'limit';
|
|
2
|
+
export type QueueType = 'init' | 'enqueue' | 'dequeue' | 'update';
|
|
3
|
+
export interface IDatabaseServiceContext extends IServiceContext {
|
|
4
|
+
appConfig: IAppConfig;
|
|
5
|
+
ws?: any;
|
|
6
|
+
}
|
|
7
|
+
export interface IAppConfig {
|
|
8
|
+
docSizeLimit: number;
|
|
9
|
+
realtimePingInterval: number;
|
|
10
|
+
realtimePongWaitTimeout: number;
|
|
11
|
+
request: any;
|
|
12
|
+
}
|
|
13
|
+
export interface IWatchOptions {
|
|
14
|
+
onChange: (snapshot: ISnapshot) => void;
|
|
15
|
+
onError: (error: any) => void;
|
|
16
|
+
}
|
|
17
|
+
export interface ISnapshot {
|
|
18
|
+
id: number;
|
|
19
|
+
docChanges: ISingleDBEvent[];
|
|
20
|
+
docs: Record<string, any>;
|
|
21
|
+
type?: SnapshotType;
|
|
22
|
+
}
|
|
23
|
+
export interface ISingleDBEvent {
|
|
24
|
+
id: number;
|
|
25
|
+
dataType: DataType;
|
|
26
|
+
queueType: QueueType;
|
|
27
|
+
docId: string;
|
|
28
|
+
doc: Record<string, any>;
|
|
29
|
+
updatedFields?: any;
|
|
30
|
+
removedFields?: any;
|
|
31
|
+
}
|
|
32
|
+
export type SnapshotType = 'init';
|
|
33
|
+
export interface DBRealtimeListener {
|
|
34
|
+
close: () => void;
|
|
35
|
+
}
|
|
36
|
+
export interface IRealtimeListenerConstructorOptions extends IWatchOptions {
|
|
37
|
+
}
|
|
38
|
+
export interface IServiceContext {
|
|
39
|
+
env?: string;
|
|
40
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { DataType, QueueType } from './index';
|
|
2
|
+
export type IRequestMsgType = 'LOGIN' | 'INIT_WATCH' | 'REBUILD_WATCH' | 'CHECK_LAST' | 'CLOSE_WATCH' | 'PING';
|
|
3
|
+
export type IResponseMsgType = 'LOGIN_RES' | 'INIT_EVENT' | 'NEXT_EVENT' | 'CHECK_EVENT' | 'PONG' | 'ERROR';
|
|
4
|
+
export interface IRequestMessageBase<W extends boolean = true> {
|
|
5
|
+
watchId: W extends true ? string : undefined;
|
|
6
|
+
requestId: string;
|
|
7
|
+
msgType: IRequestMsgType;
|
|
8
|
+
msgData: IRequestMessageMsgData;
|
|
9
|
+
}
|
|
10
|
+
export type IRequestMessageMsgData = IRequestMessageInitWatchData | IRequestMessageLoginData | IRequestMessageRebuildWatchData | IRequestMessageCheckLastData | IRequestMessageCloseWatchData | IRequestMessagePingData;
|
|
11
|
+
export type IRequestMessage = IRequestMessageInitWatchMsg | IRequestMessageLoginMsg | IRequestMessageRebuildWatchMsg | IRequestMessageCheckLastMsg | IRequestMessageCloseWatchMsg | IRequestMessagePingMsg;
|
|
12
|
+
export interface IRequestMessageLoginData {
|
|
13
|
+
envId: string;
|
|
14
|
+
accessToken: string;
|
|
15
|
+
referrer: 'web';
|
|
16
|
+
sdkVersion: string;
|
|
17
|
+
dataVersion: string;
|
|
18
|
+
}
|
|
19
|
+
export interface IRequestExtraMessageLoginData {
|
|
20
|
+
runtime: string;
|
|
21
|
+
signStr: string;
|
|
22
|
+
secretVersion: string;
|
|
23
|
+
}
|
|
24
|
+
export interface IRequestMessageLoginMsg extends IRequestMessageBase<false> {
|
|
25
|
+
msgType: 'LOGIN';
|
|
26
|
+
msgData: IRequestMessageLoginData;
|
|
27
|
+
exMsgData?: IRequestExtraMessageLoginData;
|
|
28
|
+
}
|
|
29
|
+
export interface IRequestMessageInitWatchData {
|
|
30
|
+
envId: string;
|
|
31
|
+
collName: string;
|
|
32
|
+
query: string;
|
|
33
|
+
limit?: number;
|
|
34
|
+
orderBy?: Record<string, string>;
|
|
35
|
+
}
|
|
36
|
+
export interface IRequestMessageInitWatchMsg extends IRequestMessageBase {
|
|
37
|
+
msgType: 'INIT_WATCH';
|
|
38
|
+
msgData: IRequestMessageInitWatchData;
|
|
39
|
+
}
|
|
40
|
+
export interface IRequestMessageRebuildWatchData {
|
|
41
|
+
envId: string;
|
|
42
|
+
collName: string;
|
|
43
|
+
queryID: string;
|
|
44
|
+
eventID: number;
|
|
45
|
+
}
|
|
46
|
+
export interface IRequestMessageRebuildWatchMsg extends IRequestMessageBase {
|
|
47
|
+
msgType: 'REBUILD_WATCH';
|
|
48
|
+
msgData: IRequestMessageRebuildWatchData;
|
|
49
|
+
}
|
|
50
|
+
export interface IRequestMessageCheckLastData {
|
|
51
|
+
queryID: string;
|
|
52
|
+
eventID: number;
|
|
53
|
+
}
|
|
54
|
+
export interface IRequestMessageCheckLastMsg extends IRequestMessageBase {
|
|
55
|
+
msgType: 'CHECK_LAST';
|
|
56
|
+
msgData: IRequestMessageCheckLastData;
|
|
57
|
+
}
|
|
58
|
+
export type IRequestMessageCloseWatchData = null;
|
|
59
|
+
export interface IRequestMessageCloseWatchMsg extends IRequestMessageBase {
|
|
60
|
+
msgType: 'CLOSE_WATCH';
|
|
61
|
+
msgData: IRequestMessageCloseWatchData;
|
|
62
|
+
}
|
|
63
|
+
export type IRequestMessagePingData = null;
|
|
64
|
+
export interface IRequestMessagePingMsg extends IRequestMessageBase<false> {
|
|
65
|
+
msgType: 'PING';
|
|
66
|
+
msgData: IRequestMessagePingData;
|
|
67
|
+
}
|
|
68
|
+
export interface IResponseMessageBase<W extends boolean = true> {
|
|
69
|
+
watchId: W extends true ? string : undefined;
|
|
70
|
+
requestId: string;
|
|
71
|
+
msgType: IResponseMsgType;
|
|
72
|
+
msgData: IResponseMessageMsgData;
|
|
73
|
+
}
|
|
74
|
+
export type IResponseMessageMsgData = IResponseMessageLoginResData | IResponseMessageInitEventData | IResponseMessageNextEventData | IResponseMessageCheckEventData | IResponseMessagePongData | IResponseMessageErrorData;
|
|
75
|
+
export type IResponseMessage = IResponseMessageLoginResMsg | IResponseMessageInitEventMsg | IResponseMessageNextEventMsg | IResponseMessageCheckEventMsg | IResponseMessagePongMsg | IResponseMessageErrorMsg;
|
|
76
|
+
export type IResponseMessageLoginResData = {
|
|
77
|
+
envId: string;
|
|
78
|
+
} & Partial<IResponseMessageErrorData>;
|
|
79
|
+
export interface IResponseMessageLoginResMsg extends IResponseMessageBase<false> {
|
|
80
|
+
msgType: 'LOGIN_RES';
|
|
81
|
+
msgData: IResponseMessageLoginResData;
|
|
82
|
+
}
|
|
83
|
+
export interface IResponseMessageInitEventData {
|
|
84
|
+
queryID: string;
|
|
85
|
+
currEvent: number;
|
|
86
|
+
events: IDBEvent[];
|
|
87
|
+
}
|
|
88
|
+
export interface IResponseMessageInitEventMsg extends IResponseMessageBase {
|
|
89
|
+
msgType: 'INIT_EVENT';
|
|
90
|
+
msgData: IResponseMessageInitEventData;
|
|
91
|
+
}
|
|
92
|
+
export interface IResponseMessageNextEventData {
|
|
93
|
+
queryID: string;
|
|
94
|
+
currEvent: number;
|
|
95
|
+
events: IDBEvent[];
|
|
96
|
+
}
|
|
97
|
+
export interface IResponseMessageNextEventMsg extends IResponseMessageBase {
|
|
98
|
+
msgType: 'NEXT_EVENT';
|
|
99
|
+
msgData: IResponseMessageNextEventData;
|
|
100
|
+
}
|
|
101
|
+
export interface IResponseMessageCheckEventData {
|
|
102
|
+
queryID: string;
|
|
103
|
+
currEvent: number;
|
|
104
|
+
}
|
|
105
|
+
export interface IResponseMessageCheckEventMsg extends IResponseMessageBase {
|
|
106
|
+
msgType: 'CHECK_EVENT';
|
|
107
|
+
msgData: IResponseMessageCheckEventData;
|
|
108
|
+
}
|
|
109
|
+
export type IResponseMessagePongData = null;
|
|
110
|
+
export interface IResponseMessagePongMsg extends IResponseMessageBase {
|
|
111
|
+
msgType: 'PONG';
|
|
112
|
+
msgData: IResponseMessagePongData;
|
|
113
|
+
}
|
|
114
|
+
export type IResponseMessageErrorData = {
|
|
115
|
+
message: string;
|
|
116
|
+
} & ({
|
|
117
|
+
code: 'SYS_ERR';
|
|
118
|
+
} | {
|
|
119
|
+
code: 'CHECK_LOGIN_FAILED';
|
|
120
|
+
} | {
|
|
121
|
+
code: 'SIGN_INVALID_ERROR';
|
|
122
|
+
} | {
|
|
123
|
+
code: 'SIGN_EXPIRED_ERROR';
|
|
124
|
+
} | {
|
|
125
|
+
code: 'INVALIID_ENV';
|
|
126
|
+
} | {
|
|
127
|
+
code: 'SIGN_PARAM_INVALID';
|
|
128
|
+
} | {
|
|
129
|
+
code: 'COLLECTION_PERMISSION_DENIED';
|
|
130
|
+
} | {
|
|
131
|
+
code: 'QUERYID_INVALID_ERROR';
|
|
132
|
+
});
|
|
133
|
+
export interface IResponseMessageErrorMsg extends IResponseMessageBase {
|
|
134
|
+
msgType: 'ERROR';
|
|
135
|
+
msgData: IResponseMessageErrorData;
|
|
136
|
+
}
|
|
137
|
+
export type IDBEvent = IDBInitEvent | IDBNextEvent;
|
|
138
|
+
export interface IDBEventBase {
|
|
139
|
+
ID: number;
|
|
140
|
+
DataType: DataType;
|
|
141
|
+
QueueType: QueueType;
|
|
142
|
+
DocID: string;
|
|
143
|
+
Doc: string;
|
|
144
|
+
}
|
|
145
|
+
export interface IDBInitEvent extends IDBEventBase {
|
|
146
|
+
DataType: 'init';
|
|
147
|
+
QueueType: 'init';
|
|
148
|
+
UpdatedFields?: any;
|
|
149
|
+
removedFields?: any;
|
|
150
|
+
}
|
|
151
|
+
export type IDBNextEvent = IDBNextEventDataUpdate | IDBNextEventDataReplace | IDBNextEventDataAdd | IDBNextEventDataRemove | IDBNextEventDataLimit;
|
|
152
|
+
export type IDBNextEventDataUpdate = IDBNextEventDataUpdateQueueUpdate | IDBNextEventDataUpdateQueueEnqueue | IDBNextEventDataUpdateQueueDequeue;
|
|
153
|
+
export type IDBNextEventDataReplace = IDBNextEventDataReplaceQueueUpdate | IDBNextEventDataReplaceQueueEnqueue | IDBNextEventDataReplaceQueueDequeue;
|
|
154
|
+
export type IDBNextEventDataLimit = IDBNextEventDataLimitQueueEnqueue | IDBNextEventDataLimitQueueDequeue;
|
|
155
|
+
export interface IDBNextEventDataUpdateQueueUpdate extends IDBEventBase {
|
|
156
|
+
DataType: 'update';
|
|
157
|
+
QueueType: 'update';
|
|
158
|
+
Doc: '';
|
|
159
|
+
UpdatedFields: string;
|
|
160
|
+
RemovedFields: string;
|
|
161
|
+
}
|
|
162
|
+
export interface IDBNextEventDataUpdateQueueEnqueue extends IDBEventBase {
|
|
163
|
+
DataType: 'update';
|
|
164
|
+
QueueType: 'enqueue';
|
|
165
|
+
Doc: string;
|
|
166
|
+
UpdatedFields: string;
|
|
167
|
+
RemovedFields: string;
|
|
168
|
+
}
|
|
169
|
+
export interface IDBNextEventDataUpdateQueueDequeue extends IDBEventBase {
|
|
170
|
+
DataType: 'update';
|
|
171
|
+
QueueType: 'dequeue';
|
|
172
|
+
Doc: '';
|
|
173
|
+
UpdatedFields: string;
|
|
174
|
+
RemovedFields: string;
|
|
175
|
+
}
|
|
176
|
+
export interface IDBNextEventDataReplaceQueueUpdate extends IDBEventBase {
|
|
177
|
+
DataType: 'replace';
|
|
178
|
+
QueueType: 'update';
|
|
179
|
+
Doc: string;
|
|
180
|
+
UpdatedFields: '';
|
|
181
|
+
RemovedFields: '';
|
|
182
|
+
}
|
|
183
|
+
export interface IDBNextEventDataReplaceQueueEnqueue extends IDBEventBase {
|
|
184
|
+
DataType: 'replace';
|
|
185
|
+
QueueType: 'enqueue';
|
|
186
|
+
Doc: string;
|
|
187
|
+
UpdatedFields: '';
|
|
188
|
+
RemovedFields: '';
|
|
189
|
+
}
|
|
190
|
+
export interface IDBNextEventDataReplaceQueueDequeue extends IDBEventBase {
|
|
191
|
+
DataType: 'replace';
|
|
192
|
+
QueueType: 'dequeue';
|
|
193
|
+
Doc: string;
|
|
194
|
+
UpdatedFields: '';
|
|
195
|
+
RemovedFields: '';
|
|
196
|
+
}
|
|
197
|
+
export interface IDBNextEventDataAdd extends IDBEventBase {
|
|
198
|
+
DataType: 'add';
|
|
199
|
+
QueueType: 'enqueue';
|
|
200
|
+
}
|
|
201
|
+
export interface IDBNextEventDataRemove extends IDBEventBase {
|
|
202
|
+
DataType: 'remove';
|
|
203
|
+
QueueType: 'dequeue';
|
|
204
|
+
Doc: '';
|
|
205
|
+
}
|
|
206
|
+
export interface IDBNextEventDataLimitQueueEnqueue extends IDBEventBase {
|
|
207
|
+
DataType: 'limit';
|
|
208
|
+
QueueType: 'enqueue';
|
|
209
|
+
Doc: string;
|
|
210
|
+
UpdatedFields: '';
|
|
211
|
+
RemovedFields: '';
|
|
212
|
+
}
|
|
213
|
+
export interface IDBNextEventDataLimitQueueDequeue extends IDBEventBase {
|
|
214
|
+
DataType: 'limit';
|
|
215
|
+
QueueType: 'dequeue';
|
|
216
|
+
Doc: '';
|
|
217
|
+
UpdatedFields: '';
|
|
218
|
+
RemovedFields: '';
|
|
219
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.Util = void 0;
|
|
20
|
+
var constant_1 = require("./constant");
|
|
21
|
+
var index_1 = require("./geo/index");
|
|
22
|
+
var index_2 = require("./serverDate/index");
|
|
23
|
+
var Util = (function () {
|
|
24
|
+
function Util() {
|
|
25
|
+
}
|
|
26
|
+
Util.formatResDocumentData = function (documents) {
|
|
27
|
+
return documents.map(function (document) {
|
|
28
|
+
return Util.formatField(document);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
Util.formatField = function (document) {
|
|
32
|
+
var keys = Object.keys(document);
|
|
33
|
+
var protoField = {};
|
|
34
|
+
if (Array.isArray(document)) {
|
|
35
|
+
protoField = [];
|
|
36
|
+
}
|
|
37
|
+
keys.forEach(function (key) {
|
|
38
|
+
var item = document[key];
|
|
39
|
+
var type = Util.whichType(item);
|
|
40
|
+
var realValue;
|
|
41
|
+
switch (type) {
|
|
42
|
+
case constant_1.FieldType.GeoPoint:
|
|
43
|
+
realValue = new index_1.Point(item.coordinates[0], item.coordinates[1]);
|
|
44
|
+
break;
|
|
45
|
+
case constant_1.FieldType.GeoLineString:
|
|
46
|
+
realValue = new index_1.LineString(item.coordinates.map(function (point) { return new index_1.Point(point[0], point[1]); }));
|
|
47
|
+
break;
|
|
48
|
+
case constant_1.FieldType.GeoPolygon:
|
|
49
|
+
realValue = new index_1.Polygon(item.coordinates.map(function (line) { return new index_1.LineString(line.map(function (_a) {
|
|
50
|
+
var _b = __read(_a, 2), lng = _b[0], lat = _b[1];
|
|
51
|
+
return new index_1.Point(lng, lat);
|
|
52
|
+
})); }));
|
|
53
|
+
break;
|
|
54
|
+
case constant_1.FieldType.GeoMultiPoint:
|
|
55
|
+
realValue = new index_1.MultiPoint(item.coordinates.map(function (point) { return new index_1.Point(point[0], point[1]); }));
|
|
56
|
+
break;
|
|
57
|
+
case constant_1.FieldType.GeoMultiLineString:
|
|
58
|
+
realValue = new index_1.MultiLineString(item.coordinates.map(function (line) { return new index_1.LineString(line.map(function (_a) {
|
|
59
|
+
var _b = __read(_a, 2), lng = _b[0], lat = _b[1];
|
|
60
|
+
return new index_1.Point(lng, lat);
|
|
61
|
+
})); }));
|
|
62
|
+
break;
|
|
63
|
+
case constant_1.FieldType.GeoMultiPolygon:
|
|
64
|
+
realValue = new index_1.MultiPolygon(item.coordinates.map(function (polygon) {
|
|
65
|
+
return new index_1.Polygon(polygon.map(function (line) { return new index_1.LineString(line.map(function (_a) {
|
|
66
|
+
var _b = __read(_a, 2), lng = _b[0], lat = _b[1];
|
|
67
|
+
return new index_1.Point(lng, lat);
|
|
68
|
+
})); }));
|
|
69
|
+
}));
|
|
70
|
+
break;
|
|
71
|
+
case constant_1.FieldType.Timestamp:
|
|
72
|
+
realValue = new Date(item.$timestamp * 1000);
|
|
73
|
+
break;
|
|
74
|
+
case constant_1.FieldType.Object:
|
|
75
|
+
case constant_1.FieldType.Array:
|
|
76
|
+
realValue = Util.formatField(item);
|
|
77
|
+
break;
|
|
78
|
+
case constant_1.FieldType.ServerDate:
|
|
79
|
+
realValue = new Date(item.$date);
|
|
80
|
+
break;
|
|
81
|
+
default:
|
|
82
|
+
realValue = item;
|
|
83
|
+
}
|
|
84
|
+
if (Array.isArray(protoField)) {
|
|
85
|
+
protoField.push(realValue);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
protoField[key] = realValue;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return protoField;
|
|
92
|
+
};
|
|
93
|
+
Util.whichType = function (obj) {
|
|
94
|
+
var type = Object.prototype.toString.call(obj).slice(8, -1);
|
|
95
|
+
if (type === constant_1.FieldType.Timestamp) {
|
|
96
|
+
return constant_1.FieldType.BsonDate;
|
|
97
|
+
}
|
|
98
|
+
if (type === constant_1.FieldType.Object) {
|
|
99
|
+
if (obj instanceof index_1.Point) {
|
|
100
|
+
return constant_1.FieldType.GeoPoint;
|
|
101
|
+
}
|
|
102
|
+
else if (obj instanceof Date) {
|
|
103
|
+
return constant_1.FieldType.Timestamp;
|
|
104
|
+
}
|
|
105
|
+
else if (obj instanceof index_2.ServerDate) {
|
|
106
|
+
return constant_1.FieldType.ServerDate;
|
|
107
|
+
}
|
|
108
|
+
if (obj.$timestamp) {
|
|
109
|
+
type = constant_1.FieldType.Timestamp;
|
|
110
|
+
}
|
|
111
|
+
else if (obj.$date) {
|
|
112
|
+
type = constant_1.FieldType.ServerDate;
|
|
113
|
+
}
|
|
114
|
+
else if (index_1.Point.validate(obj)) {
|
|
115
|
+
type = constant_1.FieldType.GeoPoint;
|
|
116
|
+
}
|
|
117
|
+
else if (index_1.LineString.validate(obj)) {
|
|
118
|
+
type = constant_1.FieldType.GeoLineString;
|
|
119
|
+
}
|
|
120
|
+
else if (index_1.Polygon.validate(obj)) {
|
|
121
|
+
type = constant_1.FieldType.GeoPolygon;
|
|
122
|
+
}
|
|
123
|
+
else if (index_1.MultiPoint.validate(obj)) {
|
|
124
|
+
type = constant_1.FieldType.GeoMultiPoint;
|
|
125
|
+
}
|
|
126
|
+
else if (index_1.MultiLineString.validate(obj)) {
|
|
127
|
+
type = constant_1.FieldType.GeoMultiLineString;
|
|
128
|
+
}
|
|
129
|
+
else if (index_1.MultiPolygon.validate(obj)) {
|
|
130
|
+
type = constant_1.FieldType.GeoMultiPolygon;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return type;
|
|
134
|
+
};
|
|
135
|
+
Util.generateDocId = function () {
|
|
136
|
+
var chars = 'ABCDEFabcdef0123456789';
|
|
137
|
+
var autoId = '';
|
|
138
|
+
for (var i = 0; i < 24; i++) {
|
|
139
|
+
autoId += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
140
|
+
}
|
|
141
|
+
return autoId;
|
|
142
|
+
};
|
|
143
|
+
return Util;
|
|
144
|
+
}());
|
|
145
|
+
exports.Util = Util;
|