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