@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.
- package/dist/commonjs/ObjectId/index.d.ts +1 -1
- package/dist/commonjs/ObjectId/index.js +16 -9
- package/dist/commonjs/aggregate.js +126 -75
- package/dist/commonjs/collection.d.ts +3 -2
- package/dist/commonjs/collection.js +131 -58
- package/dist/commonjs/command.d.ts +5 -5
- package/dist/commonjs/command.js +181 -154
- package/dist/commonjs/commands/logic.js +30 -20
- package/dist/commonjs/commands/query.d.ts +1 -1
- package/dist/commonjs/commands/query.js +85 -65
- package/dist/commonjs/commands/update.js +9 -7
- package/dist/commonjs/config/error.config.js +1 -0
- package/dist/commonjs/const/code.js +1 -0
- package/dist/commonjs/constant.d.ts +7 -7
- package/dist/commonjs/constant.js +13 -11
- package/dist/commonjs/document.d.ts +10 -6
- package/dist/commonjs/document.js +305 -193
- package/dist/commonjs/geo/index.js +20 -9
- package/dist/commonjs/geo/lineString.d.ts +1 -1
- package/dist/commonjs/geo/lineString.js +62 -33
- package/dist/commonjs/geo/multiLineString.d.ts +1 -1
- package/dist/commonjs/geo/multiLineString.js +71 -32
- package/dist/commonjs/geo/multiPoint.d.ts +1 -1
- package/dist/commonjs/geo/multiPoint.js +58 -29
- package/dist/commonjs/geo/multiPolygon.d.ts +1 -1
- package/dist/commonjs/geo/multiPolygon.js +96 -36
- package/dist/commonjs/geo/point.d.ts +1 -1
- package/dist/commonjs/geo/point.js +30 -23
- package/dist/commonjs/geo/polygon.d.ts +1 -1
- package/dist/commonjs/geo/polygon.js +78 -39
- package/dist/commonjs/helper/symbol.js +17 -5
- package/dist/commonjs/index.d.ts +8 -2
- package/dist/commonjs/index.js +73 -20
- package/dist/commonjs/lib/util.d.ts +1 -0
- package/dist/commonjs/lib/util.js +26 -0
- package/dist/commonjs/operator-map.js +7 -6
- package/dist/commonjs/query.d.ts +8 -4
- package/dist/commonjs/query.js +308 -201
- package/dist/commonjs/regexp/index.d.ts +1 -1
- package/dist/commonjs/regexp/index.js +16 -9
- package/dist/commonjs/serializer/common.d.ts +2 -2
- package/dist/commonjs/serializer/common.js +59 -22
- package/dist/commonjs/serializer/datatype.d.ts +2 -2
- package/dist/commonjs/serializer/datatype.js +58 -21
- package/dist/commonjs/serializer/query.d.ts +1 -1
- package/dist/commonjs/serializer/query.js +137 -127
- package/dist/commonjs/serializer/update.d.ts +1 -1
- package/dist/commonjs/serializer/update.js +83 -78
- package/dist/commonjs/serverDate/index.d.ts +1 -1
- package/dist/commonjs/serverDate/index.js +16 -9
- package/dist/commonjs/transaction/collection.d.ts +7 -0
- package/dist/commonjs/transaction/collection.js +49 -0
- package/dist/commonjs/transaction/document.d.ts +27 -0
- package/dist/commonjs/transaction/document.js +205 -0
- package/dist/commonjs/transaction/index.js +196 -86
- package/dist/commonjs/transaction/query.d.ts +43 -0
- package/dist/commonjs/transaction/query.js +261 -0
- package/dist/commonjs/typings/index.d.ts +4 -4
- package/dist/commonjs/typings/realtime.d.ts +16 -16
- package/dist/commonjs/util.js +123 -92
- package/dist/commonjs/utils/error.d.ts +2 -1
- package/dist/commonjs/utils/error.js +74 -38
- package/dist/commonjs/utils/symbol.js +33 -14
- package/dist/commonjs/utils/type.d.ts +1 -1
- package/dist/commonjs/utils/type.js +25 -13
- package/dist/commonjs/utils/utils.d.ts +4 -1
- package/dist/commonjs/utils/utils.js +93 -22
- package/dist/commonjs/validate.js +79 -63
- package/dist/esm/ObjectId/index.d.ts +1 -1
- package/dist/esm/ObjectId/index.js +15 -8
- package/dist/esm/aggregate.js +118 -66
- package/dist/esm/collection.d.ts +3 -2
- package/dist/esm/collection.js +125 -52
- package/dist/esm/command.d.ts +5 -5
- package/dist/esm/command.js +175 -147
- package/dist/esm/commands/logic.js +30 -20
- package/dist/esm/commands/query.d.ts +1 -1
- package/dist/esm/commands/query.js +91 -71
- package/dist/esm/commands/update.js +8 -6
- package/dist/esm/config/error.config.js +1 -1
- package/dist/esm/const/code.js +1 -1
- package/dist/esm/constant.d.ts +7 -7
- package/dist/esm/constant.js +12 -11
- package/dist/esm/document.d.ts +10 -6
- package/dist/esm/document.js +297 -185
- package/dist/esm/geo/interface.js +1 -0
- package/dist/esm/geo/lineString.d.ts +1 -1
- package/dist/esm/geo/lineString.js +57 -28
- package/dist/esm/geo/multiLineString.d.ts +1 -1
- package/dist/esm/geo/multiLineString.js +66 -27
- package/dist/esm/geo/multiPoint.d.ts +1 -1
- package/dist/esm/geo/multiPoint.js +53 -24
- package/dist/esm/geo/multiPolygon.d.ts +1 -1
- package/dist/esm/geo/multiPolygon.js +91 -31
- package/dist/esm/geo/point.d.ts +1 -1
- package/dist/esm/geo/point.js +26 -19
- package/dist/esm/geo/polygon.d.ts +1 -1
- package/dist/esm/geo/polygon.js +73 -34
- package/dist/esm/helper/symbol.js +13 -13
- package/dist/esm/index.d.ts +8 -2
- package/dist/esm/index.js +62 -9
- package/dist/esm/lib/util.d.ts +1 -0
- package/dist/esm/lib/util.js +22 -0
- package/dist/esm/operator-map.js +4 -4
- package/dist/esm/query.d.ts +8 -4
- package/dist/esm/query.js +299 -192
- package/dist/esm/regexp/index.d.ts +1 -1
- package/dist/esm/regexp/index.js +15 -8
- package/dist/esm/serializer/common.d.ts +2 -2
- package/dist/esm/serializer/common.js +49 -13
- package/dist/esm/serializer/datatype.d.ts +2 -2
- package/dist/esm/serializer/datatype.js +44 -8
- package/dist/esm/serializer/query.d.ts +1 -1
- package/dist/esm/serializer/query.js +112 -102
- package/dist/esm/serializer/update.d.ts +1 -1
- package/dist/esm/serializer/update.js +69 -64
- package/dist/esm/serverDate/index.d.ts +1 -1
- package/dist/esm/serverDate/index.js +15 -8
- package/dist/esm/transaction/collection.d.ts +7 -0
- package/dist/esm/transaction/collection.js +46 -0
- package/dist/esm/transaction/document.d.ts +27 -0
- package/dist/esm/transaction/document.js +202 -0
- package/dist/esm/transaction/index.js +191 -81
- package/dist/esm/transaction/query.d.ts +43 -0
- package/dist/esm/transaction/query.js +258 -0
- package/dist/esm/typings/index.d.ts +4 -4
- package/dist/esm/typings/index.js +1 -0
- package/dist/esm/typings/realtime.d.ts +16 -16
- package/dist/esm/typings/realtime.js +1 -0
- package/dist/esm/util.js +121 -90
- package/dist/esm/utils/error.d.ts +2 -1
- package/dist/esm/utils/error.js +70 -35
- package/dist/esm/utils/symbol.js +33 -14
- package/dist/esm/utils/type.d.ts +1 -1
- package/dist/esm/utils/type.js +12 -12
- package/dist/esm/utils/utils.d.ts +4 -1
- package/dist/esm/utils/utils.js +78 -16
- package/dist/esm/validate.js +65 -49
- package/jest.config.js +14 -0
- package/package.json +14 -10
- package/src/aggregate.ts +1 -5
- package/src/collection.ts +15 -2
- package/src/document.ts +45 -34
- package/src/index.ts +51 -4
- package/src/query.ts +33 -29
- package/src/serializer/query.ts +18 -6
- package/src/transaction/index.ts +1 -1
- package/src/typings/index.ts +0 -4
- package/src/utils/utils.ts +46 -0
- package/src/validate.ts +3 -6
- package/tests/gateway-contract.test.ts +180 -0
- package/tests/index.test.ts +283 -0
- package/tests/transaction-query.test.ts +207 -0
- package/tsconfig.esm.json +4 -2
- package/tsconfig.json +16 -6
- package/tsconfig.test.json +15 -0
- package/dist/commonjs/realtime/error.d.ts +0 -7
- package/dist/commonjs/realtime/error.js +0 -11
- package/dist/commonjs/realtime/listener.d.ts +0 -14
- package/dist/commonjs/realtime/listener.js +0 -17
- package/dist/commonjs/realtime/message.d.ts +0 -3
- package/dist/commonjs/realtime/message.js +0 -10
- package/dist/commonjs/realtime/snapshot.d.ts +0 -16
- package/dist/commonjs/realtime/snapshot.js +0 -42
- package/dist/commonjs/realtime/virtual-websocket-client.d.ts +0 -63
- package/dist/commonjs/realtime/virtual-websocket-client.js +0 -736
- package/dist/commonjs/realtime/websocket-client.d.ts +0 -78
- package/dist/commonjs/realtime/websocket-client.js +0 -567
- package/dist/commonjs/realtime/ws-event.d.ts +0 -126
- package/dist/commonjs/realtime/ws-event.js +0 -139
- package/dist/commonjs/transaction.d.ts +0 -42
- package/dist/commonjs/transaction.js +0 -126
- package/dist/esm/realtime/error.d.ts +0 -7
- package/dist/esm/realtime/error.js +0 -8
- package/dist/esm/realtime/listener.d.ts +0 -14
- package/dist/esm/realtime/listener.js +0 -14
- package/dist/esm/realtime/message.d.ts +0 -3
- package/dist/esm/realtime/message.js +0 -6
- package/dist/esm/realtime/snapshot.d.ts +0 -16
- package/dist/esm/realtime/snapshot.js +0 -39
- package/dist/esm/realtime/virtual-websocket-client.d.ts +0 -63
- package/dist/esm/realtime/virtual-websocket-client.js +0 -733
- package/dist/esm/realtime/websocket-client.d.ts +0 -78
- package/dist/esm/realtime/websocket-client.js +0 -564
- package/dist/esm/realtime/ws-event.d.ts +0 -126
- package/dist/esm/realtime/ws-event.js +0 -137
- package/dist/esm/transaction.d.ts +0 -42
- package/dist/esm/transaction.js +0 -121
- package/src/realtime/error.ts +0 -19
- package/src/realtime/listener.ts +0 -35
- package/src/realtime/message.ts +0 -14
- package/src/realtime/snapshot.ts +0 -60
- package/src/realtime/virtual-websocket-client.ts +0 -1195
- package/src/realtime/websocket-client.ts +0 -995
- package/src/realtime/ws-event.ts +0 -163
- package/src/transaction.ts +0 -190
|
@@ -1,204 +1,315 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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;
|
|
27
43
|
}
|
|
28
|
-
|
|
29
|
-
|
|
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.DocumentReference = void 0;
|
|
51
|
+
var index_1 = require("./index");
|
|
52
|
+
var util_1 = require("./util");
|
|
53
|
+
var update_1 = require("./serializer/update");
|
|
54
|
+
var datatype_1 = require("./serializer/datatype");
|
|
55
|
+
var update_2 = require("./commands/update");
|
|
56
|
+
var constant_1 = require("./constant");
|
|
57
|
+
var utils_1 = require("./utils/utils");
|
|
58
|
+
var code_1 = require("./const/code");
|
|
59
|
+
var bson_1 = require("bson");
|
|
60
|
+
var DocumentReference = (function () {
|
|
61
|
+
function DocumentReference(db, coll, apiOptions, docID, transactionId) {
|
|
62
|
+
var _this = this;
|
|
63
|
+
this.watch = function (options) {
|
|
64
|
+
var ws = (0, utils_1.getWsInstance)(_this._db);
|
|
65
|
+
return ws.watch(__assign(__assign({}, options), { envId: _this._db.config.env, collectionName: _this._coll, query: JSON.stringify({
|
|
66
|
+
_id: _this.id
|
|
30
67
|
}) }));
|
|
31
68
|
};
|
|
32
69
|
this._db = db;
|
|
33
70
|
this._coll = coll;
|
|
34
71
|
this.id = docID;
|
|
35
72
|
this._transactionId = transactionId;
|
|
36
|
-
this.request =
|
|
73
|
+
this.request = index_1.Db.createRequest(this._db.config);
|
|
37
74
|
this._apiOptions = apiOptions;
|
|
38
75
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
checkMixed(objs[key]);
|
|
84
|
-
}
|
|
76
|
+
DocumentReference.prototype.create = function (data, callback) {
|
|
77
|
+
return (0, utils_1.withCallback)(this._create(data), callback);
|
|
78
|
+
};
|
|
79
|
+
DocumentReference.prototype._create = function (data) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
81
|
+
var isBatch, params, res;
|
|
82
|
+
return __generator(this, function (_a) {
|
|
83
|
+
switch (_a.label) {
|
|
84
|
+
case 0:
|
|
85
|
+
isBatch = Array.isArray(data);
|
|
86
|
+
if (!isBatch && this.id) {
|
|
87
|
+
data['_id'] = this.id;
|
|
88
|
+
}
|
|
89
|
+
params = {
|
|
90
|
+
collectionName: this._coll,
|
|
91
|
+
data: isBatch
|
|
92
|
+
? data.map(function (item) { return (0, utils_1.stringifyByEJSON)((0, datatype_1.serialize)(item)); })
|
|
93
|
+
: [(0, utils_1.stringifyByEJSON)((0, datatype_1.serialize)(data))],
|
|
94
|
+
transactionId: this._transactionId
|
|
95
|
+
};
|
|
96
|
+
return [4, this.request.send('database.insertDocument', params, (0, utils_1.getReqOpts)(this._apiOptions))];
|
|
97
|
+
case 1:
|
|
98
|
+
res = _a.sent();
|
|
99
|
+
if (res.code) {
|
|
100
|
+
return [2, res];
|
|
101
|
+
}
|
|
102
|
+
if (this._transactionId) {
|
|
103
|
+
return [2, {
|
|
104
|
+
inserted: 1,
|
|
105
|
+
ok: 1,
|
|
106
|
+
id: res.data.insertedIds[0],
|
|
107
|
+
requestId: res.requestId
|
|
108
|
+
}];
|
|
109
|
+
}
|
|
110
|
+
if (isBatch) {
|
|
111
|
+
return [2, {
|
|
112
|
+
ids: (res.data && res.data.insertedIds) || [],
|
|
113
|
+
requestId: res.requestId
|
|
114
|
+
}];
|
|
115
|
+
}
|
|
116
|
+
return [2, {
|
|
117
|
+
id: res.data.insertedIds[0],
|
|
118
|
+
requestId: res.requestId
|
|
119
|
+
}];
|
|
85
120
|
}
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
DocumentReference.prototype.set = function (data, callback) {
|
|
125
|
+
return (0, utils_1.withCallback)(this._set(data), callback);
|
|
126
|
+
};
|
|
127
|
+
DocumentReference.prototype._set = function (data) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
129
|
+
var hasOperator, checkMixed, param, res;
|
|
130
|
+
return __generator(this, function (_a) {
|
|
131
|
+
switch (_a.label) {
|
|
132
|
+
case 0:
|
|
133
|
+
if (!this.id) {
|
|
134
|
+
return [2, (0, utils_1.processReturn)(this._db.config.throwOnCode, __assign(__assign({}, code_1.ERRORS.INVALID_PARAM), { message: 'docId不能为空' }))];
|
|
135
|
+
}
|
|
136
|
+
if (!data || typeof data !== 'object') {
|
|
137
|
+
return [2, (0, utils_1.processReturn)(this._db.config.throwOnCode, __assign(__assign({}, code_1.ERRORS.INVALID_PARAM), { message: '参数必需是非空对象' }))];
|
|
138
|
+
}
|
|
139
|
+
if (data.hasOwnProperty('_id')) {
|
|
140
|
+
return [2, (0, utils_1.processReturn)(this._db.config.throwOnCode, __assign(__assign({}, code_1.ERRORS.INVALID_PARAM), { message: '不能更新_id的值' }))];
|
|
141
|
+
}
|
|
142
|
+
hasOperator = false;
|
|
143
|
+
checkMixed = function (objs) {
|
|
144
|
+
if (typeof objs === 'object') {
|
|
145
|
+
for (var key in objs) {
|
|
146
|
+
if (objs[key] instanceof update_2.UpdateCommand) {
|
|
147
|
+
hasOperator = true;
|
|
148
|
+
}
|
|
149
|
+
else if (typeof objs[key] === 'object') {
|
|
150
|
+
checkMixed(objs[key]);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
checkMixed(data);
|
|
156
|
+
if (hasOperator) {
|
|
157
|
+
return [2, (0, utils_1.processReturn)(this._db.config.throwOnCode, __assign(__assign({}, code_1.ERRORS.DATABASE_REQUEST_FAILED), { message: 'update operator complicit' }))];
|
|
158
|
+
}
|
|
159
|
+
param = {
|
|
160
|
+
collectionName: this._coll,
|
|
161
|
+
queryType: constant_1.QueryType.DOC,
|
|
162
|
+
data: (0, utils_1.stringifyByEJSON)((0, datatype_1.serialize)(data)),
|
|
163
|
+
transactionId: this._transactionId,
|
|
164
|
+
multi: false,
|
|
165
|
+
merge: false,
|
|
166
|
+
upsert: true
|
|
167
|
+
};
|
|
168
|
+
if (this.id) {
|
|
169
|
+
param['query'] = (0, utils_1.stringifyByEJSON)({ _id: this.id });
|
|
170
|
+
}
|
|
171
|
+
return [4, this.request.send('database.modifyDocument', param, (0, utils_1.getReqOpts)(this._apiOptions))];
|
|
172
|
+
case 1:
|
|
173
|
+
res = _a.sent();
|
|
174
|
+
if (res.code) {
|
|
175
|
+
return [2, res];
|
|
176
|
+
}
|
|
177
|
+
if (this._transactionId) {
|
|
178
|
+
return [2, {
|
|
179
|
+
updated: res.data.updated,
|
|
180
|
+
upserted: [{ _id: res.data.upsert_id }],
|
|
181
|
+
requestId: res.requestId
|
|
182
|
+
}];
|
|
183
|
+
}
|
|
184
|
+
return [2, {
|
|
185
|
+
updated: res.data.updated,
|
|
186
|
+
upsertedId: res.data.upsert_id,
|
|
187
|
+
requestId: res.requestId
|
|
188
|
+
}];
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
DocumentReference.prototype.update = function (data, callback) {
|
|
194
|
+
return (0, utils_1.withCallback)(this._update(data), callback);
|
|
195
|
+
};
|
|
196
|
+
DocumentReference.prototype._update = function (data) {
|
|
197
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
198
|
+
var query, param, res;
|
|
199
|
+
return __generator(this, function (_a) {
|
|
200
|
+
switch (_a.label) {
|
|
201
|
+
case 0:
|
|
202
|
+
if (!data || typeof data !== 'object') {
|
|
203
|
+
return [2, (0, utils_1.processReturn)(this._db.config.throwOnCode, __assign(__assign({}, code_1.ERRORS.INVALID_PARAM), { message: '参数必需是非空对象' }))];
|
|
204
|
+
}
|
|
205
|
+
if (data.hasOwnProperty('_id')) {
|
|
206
|
+
return [2, (0, utils_1.processReturn)(this._db.config.throwOnCode, __assign(__assign({}, code_1.ERRORS.INVALID_PARAM), { message: '不能更新_id的值' }))];
|
|
207
|
+
}
|
|
208
|
+
query = (0, utils_1.stringifyByEJSON)({ _id: this.id });
|
|
209
|
+
param = {
|
|
210
|
+
collectionName: this._coll,
|
|
211
|
+
transactionId: this._transactionId,
|
|
212
|
+
data: update_1.UpdateSerializer.encodeEJSON(data, this._apiOptions.raw || false),
|
|
213
|
+
query: query,
|
|
214
|
+
queryType: constant_1.QueryType.DOC,
|
|
215
|
+
multi: false,
|
|
216
|
+
merge: true,
|
|
217
|
+
upsert: false
|
|
218
|
+
};
|
|
219
|
+
return [4, this.request.send('database.modifyDocument', param, (0, utils_1.getReqOpts)(this._apiOptions))];
|
|
220
|
+
case 1:
|
|
221
|
+
res = _a.sent();
|
|
222
|
+
if (res.code) {
|
|
223
|
+
return [2, res];
|
|
224
|
+
}
|
|
225
|
+
return [2, {
|
|
226
|
+
updated: res.data.updated,
|
|
227
|
+
requestId: res.requestId
|
|
228
|
+
}];
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
DocumentReference.prototype.delete = function (callback) {
|
|
234
|
+
return this.remove(callback);
|
|
235
|
+
};
|
|
236
|
+
DocumentReference.prototype.remove = function (callback) {
|
|
237
|
+
return (0, utils_1.withCallback)(this._remove(), callback);
|
|
238
|
+
};
|
|
239
|
+
DocumentReference.prototype._remove = function () {
|
|
240
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
241
|
+
var query, param, res;
|
|
242
|
+
return __generator(this, function (_a) {
|
|
243
|
+
switch (_a.label) {
|
|
244
|
+
case 0:
|
|
245
|
+
query = (0, utils_1.stringifyByEJSON)({ _id: this.id });
|
|
246
|
+
param = {
|
|
247
|
+
collectionName: this._coll,
|
|
248
|
+
transactionId: this._transactionId,
|
|
249
|
+
query: query,
|
|
250
|
+
queryType: constant_1.QueryType.DOC,
|
|
251
|
+
multi: false
|
|
252
|
+
};
|
|
253
|
+
return [4, this.request.send('database.removeDocument', param, (0, utils_1.getReqOpts)(this._apiOptions))];
|
|
254
|
+
case 1:
|
|
255
|
+
res = _a.sent();
|
|
256
|
+
if (res.code) {
|
|
257
|
+
return [2, res];
|
|
258
|
+
}
|
|
259
|
+
return [2, {
|
|
260
|
+
deleted: res.data.deleted,
|
|
261
|
+
requestId: res.requestId
|
|
262
|
+
}];
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
DocumentReference.prototype.get = function (callback) {
|
|
268
|
+
return (0, utils_1.withCallback)(this._get(), callback);
|
|
269
|
+
};
|
|
270
|
+
DocumentReference.prototype._get = function () {
|
|
271
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
272
|
+
var query, projection, param, res, list, documents;
|
|
273
|
+
return __generator(this, function (_a) {
|
|
274
|
+
switch (_a.label) {
|
|
275
|
+
case 0:
|
|
276
|
+
query = (0, utils_1.stringifyByEJSON)({ _id: this.id });
|
|
277
|
+
projection = this._apiOptions.projection;
|
|
278
|
+
param = {
|
|
279
|
+
collectionName: this._coll,
|
|
280
|
+
query: query,
|
|
281
|
+
transactionId: this._transactionId,
|
|
282
|
+
queryType: constant_1.QueryType.DOC,
|
|
283
|
+
multi: false
|
|
284
|
+
};
|
|
285
|
+
if (projection) {
|
|
286
|
+
param.projection = (0, utils_1.stringifyByEJSON)(projection);
|
|
287
|
+
}
|
|
288
|
+
return [4, this.request.send('database.getDocument', param, (0, utils_1.getReqOpts)(this._apiOptions))];
|
|
289
|
+
case 1:
|
|
290
|
+
res = _a.sent();
|
|
291
|
+
if (res.code) {
|
|
292
|
+
return [2, res];
|
|
293
|
+
}
|
|
294
|
+
list = res.data.list.map(function (item) { return bson_1.EJSON.parse(item); });
|
|
295
|
+
documents = util_1.Util.formatResDocumentData(list);
|
|
296
|
+
if (this._transactionId) {
|
|
297
|
+
return [2, {
|
|
298
|
+
data: documents[0] || null,
|
|
299
|
+
requestId: res.requestId
|
|
300
|
+
}];
|
|
301
|
+
}
|
|
302
|
+
return [2, {
|
|
303
|
+
data: documents,
|
|
304
|
+
requestId: res.requestId
|
|
305
|
+
}];
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
};
|
|
310
|
+
DocumentReference.prototype.field = function (projection) {
|
|
311
|
+
var transformProjection = {};
|
|
312
|
+
for (var k in projection) {
|
|
202
313
|
if (typeof projection[k] === 'boolean') {
|
|
203
314
|
transformProjection[k] = projection[k] === true ? 1 : 0;
|
|
204
315
|
}
|
|
@@ -209,9 +320,10 @@ class DocumentReference {
|
|
|
209
320
|
transformProjection[k] = projection[k];
|
|
210
321
|
}
|
|
211
322
|
}
|
|
212
|
-
|
|
323
|
+
var newApiOption = __assign({}, this._apiOptions);
|
|
213
324
|
newApiOption.projection = transformProjection;
|
|
214
325
|
return new DocumentReference(this._db, this._coll, newApiOption, this.id, this._transactionId);
|
|
215
|
-
}
|
|
216
|
-
|
|
326
|
+
};
|
|
327
|
+
return DocumentReference;
|
|
328
|
+
}());
|
|
217
329
|
exports.DocumentReference = DocumentReference;
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
5
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
17
|
+
__exportStar(require("./point"), exports);
|
|
18
|
+
__exportStar(require("./lineString"), exports);
|
|
19
|
+
__exportStar(require("./polygon"), exports);
|
|
20
|
+
__exportStar(require("./multiPoint"), exports);
|
|
21
|
+
__exportStar(require("./multiLineString"), exports);
|
|
22
|
+
__exportStar(require("./multiPolygon"), exports);
|
|
@@ -15,5 +15,5 @@ export declare class LineString {
|
|
|
15
15
|
};
|
|
16
16
|
static validate(lineString: ISerializedLineString): boolean;
|
|
17
17
|
static isClosed(lineString: LineString): boolean;
|
|
18
|
-
|
|
18
|
+
get _internalType(): import("../utils/symbol").InternalSymbol;
|
|
19
19
|
}
|