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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) 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 +1 -1
  11. package/auth/dist/index.esm.js.map +1 -1
  12. package/auth/dist/index.js +1 -1
  13. package/auth/dist/index.js.map +1 -1
  14. package/database/dist/index.d.ts +3 -0
  15. package/database/dist/index.esm.js +2 -0
  16. package/database/dist/index.esm.js.map +1 -0
  17. package/database/dist/index.js +2 -0
  18. package/database/dist/index.js.map +1 -0
  19. package/dist/index.cjs.js +1 -1
  20. package/dist/index.cjs.js.map +1 -1
  21. package/dist/index.esm.js +1 -1
  22. package/dist/index.esm.js.map +1 -1
  23. package/dist/index.node.cjs.js +1 -1
  24. package/dist/index.node.cjs.js.map +1 -1
  25. package/dist/index.node.esm.js +1 -1
  26. package/dist/index.node.esm.js.map +1 -1
  27. package/miniprogram_dist/auth/index.js +1 -1
  28. package/miniprogram_dist/index.js +1 -1
  29. package/miniprogram_dist/oauth/index.js +1 -1
  30. package/oauth/dist/index.esm.js +1 -1
  31. package/oauth/dist/index.esm.js.map +1 -1
  32. package/oauth/dist/index.js +1 -1
  33. package/oauth/dist/index.js.map +1 -1
  34. package/package.json +2 -2
  35. package/types/package.json +1 -1
  36. package/utilities/package.json +2 -2
  37. package/database/dist/commonjs/aggregate.d.ts +0 -29
  38. package/database/dist/commonjs/aggregate.js +0 -156
  39. package/database/dist/commonjs/collection.d.ts +0 -9
  40. package/database/dist/commonjs/collection.js +0 -49
  41. package/database/dist/commonjs/command.d.ts +0 -175
  42. package/database/dist/commonjs/command.js +0 -299
  43. package/database/dist/commonjs/commands/logic.d.ts +0 -24
  44. package/database/dist/commonjs/commands/logic.js +0 -89
  45. package/database/dist/commonjs/commands/query.d.ts +0 -68
  46. package/database/dist/commonjs/commands/query.js +0 -160
  47. package/database/dist/commonjs/commands/update.d.ts +0 -29
  48. package/database/dist/commonjs/commands/update.js +0 -51
  49. package/database/dist/commonjs/config/app.config.d.ts +0 -6
  50. package/database/dist/commonjs/config/app.config.js +0 -7
  51. package/database/dist/commonjs/config/error.config.d.ts +0 -3
  52. package/database/dist/commonjs/config/error.config.js +0 -16
  53. package/database/dist/commonjs/const/code.d.ts +0 -30
  54. package/database/dist/commonjs/const/code.js +0 -33
  55. package/database/dist/commonjs/constant.d.ts +0 -51
  56. package/database/dist/commonjs/constant.js +0 -75
  57. package/database/dist/commonjs/document.d.ts +0 -11
  58. package/database/dist/commonjs/document.js +0 -260
  59. package/database/dist/commonjs/geo/index.d.ts +0 -6
  60. package/database/dist/commonjs/geo/index.js +0 -22
  61. package/database/dist/commonjs/geo/interface.d.ts +0 -24
  62. package/database/dist/commonjs/geo/interface.js +0 -2
  63. package/database/dist/commonjs/geo/lineString.d.ts +0 -19
  64. package/database/dist/commonjs/geo/lineString.js +0 -86
  65. package/database/dist/commonjs/geo/multiLineString.d.ts +0 -18
  66. package/database/dist/commonjs/geo/multiLineString.js +0 -95
  67. package/database/dist/commonjs/geo/multiPoint.d.ts +0 -18
  68. package/database/dist/commonjs/geo/multiPoint.js +0 -79
  69. package/database/dist/commonjs/geo/multiPolygon.d.ts +0 -18
  70. package/database/dist/commonjs/geo/multiPolygon.js +0 -122
  71. package/database/dist/commonjs/geo/point.d.ts +0 -19
  72. package/database/dist/commonjs/geo/point.js +0 -50
  73. package/database/dist/commonjs/geo/polygon.d.ts +0 -19
  74. package/database/dist/commonjs/geo/polygon.js +0 -109
  75. package/database/dist/commonjs/helper/symbol.d.ts +0 -14
  76. package/database/dist/commonjs/helper/symbol.js +0 -31
  77. package/database/dist/commonjs/index.d.ts +0 -40
  78. package/database/dist/commonjs/index.js +0 -61
  79. package/database/dist/commonjs/lib/util.d.ts +0 -1
  80. package/database/dist/commonjs/lib/util.js +0 -26
  81. package/database/dist/commonjs/operator-map.d.ts +0 -4
  82. package/database/dist/commonjs/operator-map.js +0 -24
  83. package/database/dist/commonjs/query.d.ts +0 -22
  84. package/database/dist/commonjs/query.js +0 -252
  85. package/database/dist/commonjs/regexp/index.d.ts +0 -14
  86. package/database/dist/commonjs/regexp/index.js +0 -33
  87. package/database/dist/commonjs/serializer/common.d.ts +0 -11
  88. package/database/dist/commonjs/serializer/common.js +0 -127
  89. package/database/dist/commonjs/serializer/datatype.d.ts +0 -7
  90. package/database/dist/commonjs/serializer/datatype.js +0 -132
  91. package/database/dist/commonjs/serializer/query.d.ts +0 -7
  92. package/database/dist/commonjs/serializer/query.js +0 -232
  93. package/database/dist/commonjs/serializer/update.d.ts +0 -15
  94. package/database/dist/commonjs/serializer/update.js +0 -142
  95. package/database/dist/commonjs/serverDate/index.d.ts +0 -13
  96. package/database/dist/commonjs/serverDate/index.js +0 -30
  97. package/database/dist/commonjs/transaction/collection.d.ts +0 -7
  98. package/database/dist/commonjs/transaction/collection.js +0 -49
  99. package/database/dist/commonjs/transaction/document.d.ts +0 -27
  100. package/database/dist/commonjs/transaction/document.js +0 -205
  101. package/database/dist/commonjs/transaction/index.d.ts +0 -30
  102. package/database/dist/commonjs/transaction/index.js +0 -215
  103. package/database/dist/commonjs/transaction/query.d.ts +0 -43
  104. package/database/dist/commonjs/transaction/query.js +0 -261
  105. package/database/dist/commonjs/typings/index.d.ts +0 -40
  106. package/database/dist/commonjs/typings/index.js +0 -2
  107. package/database/dist/commonjs/typings/realtime.d.ts +0 -219
  108. package/database/dist/commonjs/typings/realtime.js +0 -2
  109. package/database/dist/commonjs/util.d.ts +0 -9
  110. package/database/dist/commonjs/util.js +0 -145
  111. package/database/dist/commonjs/utils/error.d.ts +0 -38
  112. package/database/dist/commonjs/utils/error.js +0 -91
  113. package/database/dist/commonjs/utils/msg.d.ts +0 -0
  114. package/database/dist/commonjs/utils/msg.js +0 -0
  115. package/database/dist/commonjs/utils/symbol.d.ts +0 -8
  116. package/database/dist/commonjs/utils/symbol.js +0 -58
  117. package/database/dist/commonjs/utils/type.d.ts +0 -13
  118. package/database/dist/commonjs/utils/type.js +0 -34
  119. package/database/dist/commonjs/utils/utils.d.ts +0 -4
  120. package/database/dist/commonjs/utils/utils.js +0 -39
  121. package/database/dist/commonjs/validate.d.ts +0 -1
  122. package/database/dist/commonjs/validate.js +0 -60
  123. package/database/dist/esm/aggregate.d.ts +0 -29
  124. package/database/dist/esm/aggregate.js +0 -154
  125. package/database/dist/esm/collection.d.ts +0 -9
  126. package/database/dist/esm/collection.js +0 -46
  127. package/database/dist/esm/command.d.ts +0 -175
  128. package/database/dist/esm/command.js +0 -296
  129. package/database/dist/esm/commands/logic.d.ts +0 -24
  130. package/database/dist/esm/commands/logic.js +0 -84
  131. package/database/dist/esm/commands/query.d.ts +0 -68
  132. package/database/dist/esm/commands/query.js +0 -154
  133. package/database/dist/esm/commands/update.d.ts +0 -29
  134. package/database/dist/esm/commands/update.js +0 -46
  135. package/database/dist/esm/config/app.config.d.ts +0 -6
  136. package/database/dist/esm/config/app.config.js +0 -5
  137. package/database/dist/esm/config/error.config.d.ts +0 -3
  138. package/database/dist/esm/config/error.config.js +0 -13
  139. package/database/dist/esm/const/code.d.ts +0 -30
  140. package/database/dist/esm/const/code.js +0 -30
  141. package/database/dist/esm/constant.d.ts +0 -51
  142. package/database/dist/esm/constant.js +0 -65
  143. package/database/dist/esm/document.d.ts +0 -11
  144. package/database/dist/esm/document.js +0 -257
  145. package/database/dist/esm/geo/index.d.ts +0 -6
  146. package/database/dist/esm/geo/index.js +0 -6
  147. package/database/dist/esm/geo/interface.d.ts +0 -24
  148. package/database/dist/esm/geo/interface.js +0 -1
  149. package/database/dist/esm/geo/lineString.d.ts +0 -19
  150. package/database/dist/esm/geo/lineString.js +0 -83
  151. package/database/dist/esm/geo/multiLineString.d.ts +0 -18
  152. package/database/dist/esm/geo/multiLineString.js +0 -92
  153. package/database/dist/esm/geo/multiPoint.d.ts +0 -18
  154. package/database/dist/esm/geo/multiPoint.js +0 -76
  155. package/database/dist/esm/geo/multiPolygon.d.ts +0 -18
  156. package/database/dist/esm/geo/multiPolygon.js +0 -119
  157. package/database/dist/esm/geo/point.d.ts +0 -19
  158. package/database/dist/esm/geo/point.js +0 -47
  159. package/database/dist/esm/geo/polygon.d.ts +0 -19
  160. package/database/dist/esm/geo/polygon.js +0 -106
  161. package/database/dist/esm/helper/symbol.d.ts +0 -14
  162. package/database/dist/esm/helper/symbol.js +0 -14
  163. package/database/dist/esm/index.d.ts +0 -40
  164. package/database/dist/esm/index.js +0 -55
  165. package/database/dist/esm/lib/util.d.ts +0 -1
  166. package/database/dist/esm/lib/util.js +0 -22
  167. package/database/dist/esm/operator-map.d.ts +0 -4
  168. package/database/dist/esm/operator-map.js +0 -20
  169. package/database/dist/esm/query.d.ts +0 -22
  170. package/database/dist/esm/query.js +0 -249
  171. package/database/dist/esm/regexp/index.d.ts +0 -14
  172. package/database/dist/esm/regexp/index.js +0 -29
  173. package/database/dist/esm/serializer/common.d.ts +0 -11
  174. package/database/dist/esm/serializer/common.js +0 -118
  175. package/database/dist/esm/serializer/datatype.d.ts +0 -7
  176. package/database/dist/esm/serializer/datatype.js +0 -127
  177. package/database/dist/esm/serializer/query.d.ts +0 -7
  178. package/database/dist/esm/serializer/query.js +0 -229
  179. package/database/dist/esm/serializer/update.d.ts +0 -15
  180. package/database/dist/esm/serializer/update.js +0 -139
  181. package/database/dist/esm/serverDate/index.d.ts +0 -13
  182. package/database/dist/esm/serverDate/index.js +0 -26
  183. package/database/dist/esm/transaction/collection.d.ts +0 -7
  184. package/database/dist/esm/transaction/collection.js +0 -46
  185. package/database/dist/esm/transaction/document.d.ts +0 -27
  186. package/database/dist/esm/transaction/document.js +0 -202
  187. package/database/dist/esm/transaction/index.d.ts +0 -30
  188. package/database/dist/esm/transaction/index.js +0 -210
  189. package/database/dist/esm/transaction/query.d.ts +0 -43
  190. package/database/dist/esm/transaction/query.js +0 -258
  191. package/database/dist/esm/typings/index.d.ts +0 -40
  192. package/database/dist/esm/typings/index.js +0 -1
  193. package/database/dist/esm/typings/realtime.d.ts +0 -219
  194. package/database/dist/esm/typings/realtime.js +0 -1
  195. package/database/dist/esm/util.d.ts +0 -9
  196. package/database/dist/esm/util.js +0 -142
  197. package/database/dist/esm/utils/error.d.ts +0 -38
  198. package/database/dist/esm/utils/error.js +0 -84
  199. package/database/dist/esm/utils/msg.d.ts +0 -0
  200. package/database/dist/esm/utils/msg.js +0 -0
  201. package/database/dist/esm/utils/symbol.d.ts +0 -8
  202. package/database/dist/esm/utils/symbol.js +0 -55
  203. package/database/dist/esm/utils/type.d.ts +0 -13
  204. package/database/dist/esm/utils/type.js +0 -20
  205. package/database/dist/esm/utils/utils.d.ts +0 -4
  206. package/database/dist/esm/utils/utils.js +0 -33
  207. package/database/dist/esm/validate.d.ts +0 -1
  208. package/database/dist/esm/validate.js +0 -57
@@ -1,205 +0,0 @@
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.DocumentReference = void 0;
51
- var bson_1 = require("bson");
52
- var code_1 = require("../const/code");
53
- var update_1 = require("../serializer/update");
54
- var datatype_1 = require("../serializer/datatype");
55
- var util_1 = require("../util");
56
- var GET_DOC = 'database.getInTransaction';
57
- var UPDATE_DOC = 'database.updateDocInTransaction';
58
- var DELETE_DOC = 'database.deleteDocInTransaction';
59
- var INSERT_DOC = 'database.insertDocInTransaction';
60
- var DocumentReference = (function () {
61
- function DocumentReference(transaction, coll, docID) {
62
- this._coll = coll;
63
- this.id = docID;
64
- this._transaction = transaction;
65
- this._request = this._transaction.getRequestMethod();
66
- this._transactionId = this._transaction.getTransactionId();
67
- }
68
- DocumentReference.prototype.create = function (data) {
69
- return __awaiter(this, void 0, void 0, function () {
70
- var params, res, inserted, ok;
71
- return __generator(this, function (_a) {
72
- switch (_a.label) {
73
- case 0:
74
- params = {
75
- collectionName: this._coll,
76
- transactionId: this._transactionId,
77
- data: bson_1.EJSON.stringify((0, datatype_1.serialize)(data), { relaxed: false })
78
- };
79
- if (this.id) {
80
- params['_id'] = this.id;
81
- }
82
- return [4, this._request.send(INSERT_DOC, params)];
83
- case 1:
84
- res = _a.sent();
85
- if (res.code) {
86
- throw res;
87
- }
88
- inserted = bson_1.EJSON.parse(res.inserted);
89
- ok = bson_1.EJSON.parse(res.ok);
90
- if (ok == 1 && inserted == 1) {
91
- return [2, __assign(__assign({}, res), { ok: ok, inserted: inserted })];
92
- }
93
- else {
94
- throw new Error(code_1.ERRORS.INSERT_DOC_FAIL.message);
95
- }
96
- return [2];
97
- }
98
- });
99
- });
100
- };
101
- DocumentReference.prototype.get = function () {
102
- return __awaiter(this, void 0, void 0, function () {
103
- var param, res;
104
- return __generator(this, function (_a) {
105
- switch (_a.label) {
106
- case 0:
107
- param = {
108
- collectionName: this._coll,
109
- transactionId: this._transactionId,
110
- query: {
111
- _id: { $eq: this.id }
112
- }
113
- };
114
- return [4, this._request.send(GET_DOC, param)];
115
- case 1:
116
- res = _a.sent();
117
- if (res.code)
118
- throw res;
119
- return [2, {
120
- data: res.data !== 'null' ? util_1.Util.formatField(bson_1.EJSON.parse(res.data)) : bson_1.EJSON.parse(res.data),
121
- requestId: res.requestId
122
- }];
123
- }
124
- });
125
- });
126
- };
127
- DocumentReference.prototype.set = function (data) {
128
- return __awaiter(this, void 0, void 0, function () {
129
- var param, res;
130
- return __generator(this, function (_a) {
131
- switch (_a.label) {
132
- case 0:
133
- param = {
134
- collectionName: this._coll,
135
- transactionId: this._transactionId,
136
- query: {
137
- _id: { $eq: this.id }
138
- },
139
- data: bson_1.EJSON.stringify((0, datatype_1.serialize)(data), { relaxed: false }),
140
- upsert: true
141
- };
142
- return [4, this._request.send(UPDATE_DOC, param)];
143
- case 1:
144
- res = _a.sent();
145
- if (res.code)
146
- throw res;
147
- return [2, __assign(__assign({}, res), { updated: bson_1.EJSON.parse(res.updated), upserted: res.upserted
148
- ? JSON.parse(res.upserted)
149
- : null })];
150
- }
151
- });
152
- });
153
- };
154
- DocumentReference.prototype.update = function (data) {
155
- return __awaiter(this, void 0, void 0, function () {
156
- var param, res;
157
- return __generator(this, function (_a) {
158
- switch (_a.label) {
159
- case 0:
160
- param = {
161
- collectionName: this._coll,
162
- transactionId: this._transactionId,
163
- query: {
164
- _id: { $eq: this.id }
165
- },
166
- data: bson_1.EJSON.stringify(update_1.UpdateSerializer.encode(data), {
167
- relaxed: false
168
- })
169
- };
170
- return [4, this._request.send(UPDATE_DOC, param)];
171
- case 1:
172
- res = _a.sent();
173
- if (res.code)
174
- throw res;
175
- return [2, __assign(__assign({}, res), { updated: bson_1.EJSON.parse(res.updated) })];
176
- }
177
- });
178
- });
179
- };
180
- DocumentReference.prototype.delete = function () {
181
- return __awaiter(this, void 0, void 0, function () {
182
- var param, res;
183
- return __generator(this, function (_a) {
184
- switch (_a.label) {
185
- case 0:
186
- param = {
187
- collectionName: this._coll,
188
- transactionId: this._transactionId,
189
- query: {
190
- _id: { $eq: this.id }
191
- }
192
- };
193
- return [4, this._request.send(DELETE_DOC, param)];
194
- case 1:
195
- res = _a.sent();
196
- if (res.code)
197
- throw res;
198
- return [2, __assign(__assign({}, res), { deleted: bson_1.EJSON.parse(res.deleted) })];
199
- }
200
- });
201
- });
202
- };
203
- return DocumentReference;
204
- }());
205
- exports.DocumentReference = DocumentReference;
@@ -1,30 +0,0 @@
1
- import { Db } from '../index';
2
- import { CollectionReference } from './collection';
3
- interface TransactionAPI {
4
- send(interfaceName: string, param?: any): any;
5
- }
6
- export declare class Transaction {
7
- private _id;
8
- private _db;
9
- private _request;
10
- aborted: boolean;
11
- abortReason: any;
12
- commited: boolean;
13
- inited: boolean;
14
- constructor(db: Db);
15
- init(): Promise<void>;
16
- collection(collName: string): CollectionReference;
17
- getTransactionId(): string;
18
- getRequestMethod(): TransactionAPI;
19
- commit(): Promise<CommitResult>;
20
- rollback(customRollbackRes: any): Promise<RollbackResult>;
21
- }
22
- export declare function startTransaction(): Promise<Transaction>;
23
- export declare function runTransaction(callback: (transaction: Transaction) => void | Promise<any>, times?: number): Promise<any>;
24
- interface CommitResult {
25
- requestId: string;
26
- }
27
- interface RollbackResult {
28
- requestId: string;
29
- }
30
- export {};
@@ -1,215 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- 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;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.runTransaction = exports.startTransaction = exports.Transaction = void 0;
40
- var index_1 = require("../index");
41
- var collection_1 = require("./collection");
42
- var code_1 = require("../const/code");
43
- var START = 'database.startTransaction';
44
- var COMMIT = 'database.commitTransaction';
45
- var ABORT = 'database.abortTransaction';
46
- var Transaction = (function () {
47
- function Transaction(db) {
48
- this._db = db;
49
- this._request = index_1.Db.createRequest(this._db.config);
50
- this.aborted = false;
51
- this.commited = false;
52
- this.inited = false;
53
- }
54
- Transaction.prototype.init = function () {
55
- return __awaiter(this, void 0, void 0, function () {
56
- var res;
57
- return __generator(this, function (_a) {
58
- switch (_a.label) {
59
- case 0: return [4, this._request.send(START)];
60
- case 1:
61
- res = _a.sent();
62
- if (res.code) {
63
- throw res;
64
- }
65
- this.inited = true;
66
- this._id = res.transactionId;
67
- return [2];
68
- }
69
- });
70
- });
71
- };
72
- Transaction.prototype.collection = function (collName) {
73
- if (!collName) {
74
- throw new Error('Collection name is required');
75
- }
76
- return new collection_1.CollectionReference(this, collName);
77
- };
78
- Transaction.prototype.getTransactionId = function () {
79
- return this._id;
80
- };
81
- Transaction.prototype.getRequestMethod = function () {
82
- return this._request;
83
- };
84
- Transaction.prototype.commit = function () {
85
- return __awaiter(this, void 0, void 0, function () {
86
- var param, res;
87
- return __generator(this, function (_a) {
88
- switch (_a.label) {
89
- case 0:
90
- param = {
91
- transactionId: this._id
92
- };
93
- return [4, this._request.send(COMMIT, param)];
94
- case 1:
95
- res = _a.sent();
96
- if (res.code)
97
- throw res;
98
- this.commited = true;
99
- return [2, res];
100
- }
101
- });
102
- });
103
- };
104
- Transaction.prototype.rollback = function (customRollbackRes) {
105
- return __awaiter(this, void 0, void 0, function () {
106
- var param, res;
107
- return __generator(this, function (_a) {
108
- switch (_a.label) {
109
- case 0:
110
- param = {
111
- transactionId: this._id
112
- };
113
- return [4, this._request.send(ABORT, param)];
114
- case 1:
115
- res = _a.sent();
116
- if (res.code)
117
- throw res;
118
- this.aborted = true;
119
- this.abortReason = customRollbackRes;
120
- return [2, res];
121
- }
122
- });
123
- });
124
- };
125
- return Transaction;
126
- }());
127
- exports.Transaction = Transaction;
128
- function startTransaction() {
129
- return __awaiter(this, void 0, void 0, function () {
130
- var transaction;
131
- return __generator(this, function (_a) {
132
- switch (_a.label) {
133
- case 0:
134
- transaction = new Transaction(this);
135
- return [4, transaction.init()];
136
- case 1:
137
- _a.sent();
138
- return [2, transaction];
139
- }
140
- });
141
- });
142
- }
143
- exports.startTransaction = startTransaction;
144
- function runTransaction(callback, times) {
145
- if (times === void 0) { times = 3; }
146
- return __awaiter(this, void 0, void 0, function () {
147
- var transaction, callbackRes, error_1, throwWithRollback;
148
- var _this = this;
149
- return __generator(this, function (_a) {
150
- switch (_a.label) {
151
- case 0:
152
- _a.trys.push([0, 4, , 10]);
153
- transaction = new Transaction(this);
154
- return [4, transaction.init()];
155
- case 1:
156
- _a.sent();
157
- return [4, callback(transaction)];
158
- case 2:
159
- callbackRes = _a.sent();
160
- if (transaction.aborted === true) {
161
- throw transaction.abortReason;
162
- }
163
- return [4, transaction.commit()];
164
- case 3:
165
- _a.sent();
166
- return [2, callbackRes];
167
- case 4:
168
- error_1 = _a.sent();
169
- if (transaction.inited === false) {
170
- throw error_1;
171
- }
172
- throwWithRollback = function (error) { return __awaiter(_this, void 0, void 0, function () {
173
- var err_1;
174
- return __generator(this, function (_a) {
175
- switch (_a.label) {
176
- case 0:
177
- if (!(!transaction.aborted && !transaction.commited)) return [3, 5];
178
- _a.label = 1;
179
- case 1:
180
- _a.trys.push([1, 3, , 4]);
181
- return [4, transaction.rollback()];
182
- case 2:
183
- _a.sent();
184
- return [3, 4];
185
- case 3:
186
- err_1 = _a.sent();
187
- return [3, 4];
188
- case 4: throw error;
189
- case 5:
190
- if (transaction.aborted === true) {
191
- throw transaction.abortReason;
192
- }
193
- throw error;
194
- }
195
- });
196
- }); };
197
- if (!(times <= 0)) return [3, 6];
198
- return [4, throwWithRollback(error_1)];
199
- case 5:
200
- _a.sent();
201
- _a.label = 6;
202
- case 6:
203
- if (!(error_1 && error_1.code === code_1.ERRORS.DATABASE_TRANSACTION_CONFLICT.code)) return [3, 8];
204
- return [4, runTransaction.bind(this)(callback, --times)];
205
- case 7: return [2, _a.sent()];
206
- case 8: return [4, throwWithRollback(error_1)];
207
- case 9:
208
- _a.sent();
209
- return [3, 10];
210
- case 10: return [2];
211
- }
212
- });
213
- });
214
- }
215
- exports.runTransaction = runTransaction;
@@ -1,43 +0,0 @@
1
- import { Transaction } from './index';
2
- import { OrderByDirection } from '../constant';
3
- interface QueryOrder {
4
- field?: string;
5
- direction?: 'asc' | 'desc';
6
- }
7
- interface QueryOption {
8
- limit?: number;
9
- offset?: number;
10
- projection?: Object;
11
- }
12
- interface GetResult {
13
- data: any[];
14
- requestId: string;
15
- total?: number;
16
- limit?: number;
17
- offset?: number;
18
- }
19
- interface UpdateResult {
20
- requestId: string;
21
- updated: number;
22
- }
23
- interface DeleteResult {
24
- requestId: string;
25
- deleted: number | string;
26
- }
27
- export declare class Query {
28
- protected _transaction: Transaction;
29
- constructor(transaction: Transaction, coll: string, fieldFilters?: Object, fieldOrders?: QueryOrder[], queryOptions?: QueryOption);
30
- where(query: object): Query;
31
- orderBy(fieldPath: string, directionStr: OrderByDirection): Query;
32
- limit(limit: number): Query;
33
- skip(offset: number): Query;
34
- field(projection: any): Query;
35
- get(): Promise<GetResult>;
36
- count(): Promise<{
37
- requestId: string;
38
- total: number;
39
- }>;
40
- update(data: Object): Promise<UpdateResult>;
41
- remove(): Promise<DeleteResult>;
42
- }
43
- export {};