oak-domain 2.5.2 → 2.6.2
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/lib/actions/action.d.ts +16 -16
- package/lib/actions/action.js +17 -17
- package/lib/actions/relation.d.ts +5 -5
- package/lib/actions/relation.js +38 -38
- package/lib/base-app-domain/ActionDefDict.d.ts +8 -8
- package/lib/base-app-domain/ActionDefDict.js +9 -9
- package/lib/base-app-domain/EntityDict.d.ts +14 -14
- package/lib/base-app-domain/EntityDict.js +2 -2
- package/lib/base-app-domain/Modi/Action.d.ts +10 -10
- package/lib/base-app-domain/Modi/Action.js +14 -14
- package/lib/base-app-domain/Modi/Schema.d.ts +146 -146
- package/lib/base-app-domain/Modi/Schema.js +2 -2
- package/lib/base-app-domain/Modi/Storage.d.ts +3 -3
- package/lib/base-app-domain/Modi/Storage.js +60 -60
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +189 -189
- package/lib/base-app-domain/ModiEntity/Schema.js +2 -2
- package/lib/base-app-domain/ModiEntity/Storage.d.ts +3 -3
- package/lib/base-app-domain/ModiEntity/Storage.js +27 -27
- package/lib/base-app-domain/Oper/Schema.d.ts +144 -144
- package/lib/base-app-domain/Oper/Schema.js +2 -2
- package/lib/base-app-domain/Oper/Storage.d.ts +3 -3
- package/lib/base-app-domain/Oper/Storage.js +29 -29
- package/lib/base-app-domain/OperEntity/Schema.d.ts +205 -205
- package/lib/base-app-domain/OperEntity/Schema.js +2 -2
- package/lib/base-app-domain/OperEntity/Storage.d.ts +3 -3
- package/lib/base-app-domain/OperEntity/Storage.js +27 -27
- package/lib/base-app-domain/Storage.d.ts +3 -3
- package/lib/base-app-domain/Storage.js +17 -17
- package/lib/base-app-domain/User/Action.d.ts +10 -10
- package/lib/base-app-domain/User/Action.js +12 -12
- package/lib/base-app-domain/User/Schema.d.ts +180 -180
- package/lib/base-app-domain/User/Schema.js +2 -2
- package/lib/base-app-domain/User/Storage.d.ts +3 -3
- package/lib/base-app-domain/User/Storage.js +36 -36
- package/lib/base-app-domain/UserEntityGrant/Schema.d.ts +121 -121
- package/lib/base-app-domain/UserEntityGrant/Schema.js +2 -2
- package/lib/base-app-domain/UserEntityGrant/Storage.d.ts +3 -3
- package/lib/base-app-domain/UserEntityGrant/Storage.js +28 -28
- package/lib/base-app-domain/_SubQuery.d.ts +44 -44
- package/lib/base-app-domain/_SubQuery.js +2 -2
- package/lib/base-app-domain/index.d.ts +3 -3
- package/lib/base-app-domain/index.js +6 -6
- package/lib/checkers/index.d.ts +5 -5
- package/lib/checkers/index.js +16 -16
- package/lib/compiler/env.d.ts +11 -11
- package/lib/compiler/env.js +39 -39
- package/lib/compiler/schemalBuilder.d.ts +2 -2
- package/lib/compiler/schemalBuilder.js +3355 -3355
- package/lib/compiler/uiBuilder.d.ts +1 -1
- package/lib/compiler/uiBuilder.js +3 -3
- package/lib/entities/Modi.d.ts +11 -11
- package/lib/entities/Modi.js +46 -46
- package/lib/entities/ModiEntity.d.ts +8 -8
- package/lib/entities/ModiEntity.js +15 -15
- package/lib/entities/Oper.d.ts +10 -10
- package/lib/entities/Oper.js +17 -17
- package/lib/entities/OperEntity.d.ts +8 -8
- package/lib/entities/OperEntity.js +15 -15
- package/lib/entities/User.d.ts +8 -8
- package/lib/entities/User.js +28 -28
- package/lib/entities/UserEntityGrant.d.ts +7 -7
- package/lib/entities/UserEntityGrant.js +12 -12
- package/lib/store/AsyncRowStore.d.ts +51 -48
- package/lib/store/AsyncRowStore.js +189 -183
- package/lib/store/CascadeStore.d.ts +91 -91
- package/lib/store/CascadeStore.js +1634 -1603
- package/lib/store/SyncRowStore.d.ts +29 -29
- package/lib/store/SyncRowStore.js +48 -48
- package/lib/store/TriggerExecutor.d.ts +32 -32
- package/lib/store/TriggerExecutor.js +532 -532
- package/lib/store/actionDef.d.ts +9 -9
- package/lib/store/actionDef.js +333 -333
- package/lib/store/checker.d.ts +26 -26
- package/lib/store/checker.js +829 -867
- package/lib/store/filter.d.ts +109 -109
- package/lib/store/filter.js +893 -893
- package/lib/store/modi.d.ts +13 -13
- package/lib/store/modi.js +216 -216
- package/lib/store/relation.d.ts +13 -13
- package/lib/store/relation.js +66 -66
- package/lib/store/selection.d.ts +19 -7
- package/lib/store/selection.js +265 -238
- package/lib/triggers/index.d.ts +6 -6
- package/lib/triggers/index.js +11 -11
- package/lib/triggers/modi.d.ts +5 -5
- package/lib/triggers/modi.js +72 -72
- package/lib/types/Action.d.ts +20 -20
- package/lib/types/Action.js +2 -2
- package/lib/types/AppLoader.d.ts +11 -11
- package/lib/types/AppLoader.js +10 -10
- package/lib/types/Aspect.d.ts +13 -12
- package/lib/types/Aspect.js +4 -4
- package/lib/types/Auth.d.ts +69 -69
- package/lib/types/Auth.js +2 -2
- package/lib/types/Connector.d.ts +27 -26
- package/lib/types/Connector.js +9 -9
- package/lib/types/Context.d.ts +7 -7
- package/lib/types/Context.js +3 -3
- package/lib/types/DataType.d.ts +18 -18
- package/lib/types/DataType.js +5 -5
- package/lib/types/Demand.d.ts +77 -77
- package/lib/types/Demand.js +9 -9
- package/lib/types/Endpoint.d.ts +11 -11
- package/lib/types/Endpoint.js +3 -3
- package/lib/types/Entity.d.ts +183 -183
- package/lib/types/Entity.js +14 -14
- package/lib/types/Exception.d.ts +100 -98
- package/lib/types/Exception.js +327 -283
- package/lib/types/Expression.d.ts +163 -163
- package/lib/types/Expression.js +427 -427
- package/lib/types/Geo.d.ts +18 -18
- package/lib/types/Geo.js +2 -2
- package/lib/types/Locale.d.ts +24 -24
- package/lib/types/Locale.js +2 -2
- package/lib/types/Logger.d.ts +5 -5
- package/lib/types/Logger.js +3 -3
- package/lib/types/Polyfill.d.ts +23 -23
- package/lib/types/Polyfill.js +2 -2
- package/lib/types/Port.d.ts +17 -17
- package/lib/types/Port.js +2 -2
- package/lib/types/RowStore.d.ts +12 -12
- package/lib/types/RowStore.js +34 -34
- package/lib/types/Storage.d.ts +56 -56
- package/lib/types/Storage.js +2 -2
- package/lib/types/Timer.d.ts +13 -13
- package/lib/types/Timer.js +2 -2
- package/lib/types/Trigger.d.ts +109 -109
- package/lib/types/Trigger.js +49 -49
- package/lib/types/Txn.d.ts +2 -2
- package/lib/types/Txn.js +3 -3
- package/lib/types/Watcher.d.ts +19 -19
- package/lib/types/Watcher.js +4 -4
- package/lib/types/index.d.ts +21 -21
- package/lib/types/index.js +24 -24
- package/lib/types/schema/DataTypes.d.ts +32 -32
- package/lib/types/schema/DataTypes.js +3 -3
- package/lib/utils/SimpleConnector.d.ts +35 -30
- package/lib/utils/SimpleConnector.js +134 -117
- package/lib/utils/assert.d.ts +5 -5
- package/lib/utils/assert.js +9 -9
- package/lib/utils/concurrent.d.ts +15 -15
- package/lib/utils/concurrent.js +89 -89
- package/lib/utils/cron.d.ts +1 -1
- package/lib/utils/cron.js +18 -18
- package/lib/utils/date.d.ts +1 -1
- package/lib/utils/date.js +18 -18
- package/lib/utils/geo.d.ts +4 -4
- package/lib/utils/geo.js +24 -24
- package/lib/utils/lodash.d.ts +20 -20
- package/lib/utils/lodash.js +55 -55
- package/lib/utils/random/random.d.ts +1 -1
- package/lib/utils/random/random.js +24 -24
- package/lib/utils/random/random.mp.d.ts +1 -1
- package/lib/utils/random/random.mp.js +25 -25
- package/lib/utils/random/random.web.d.ts +1 -1
- package/lib/utils/random/random.web.js +17 -17
- package/lib/utils/string.d.ts +22 -22
- package/lib/utils/string.js +70 -70
- package/lib/utils/url.d.ts +1 -0
- package/lib/utils/url.js +12 -0
- package/lib/utils/uuid.d.ts +12 -12
- package/lib/utils/uuid.js +194 -194
- package/lib/utils/validator.d.ts +23 -23
- package/lib/utils/validator.js +123 -123
- package/package.json +48 -48
- package/src/entities/Modi.ts +68 -68
- package/src/entities/ModiEntity.ts +24 -24
- package/src/entities/Oper.ts +28 -28
- package/src/entities/OperEntity.ts +24 -24
- package/src/entities/User.ts +44 -44
- package/src/entities/UserEntityGrant.ts +24 -24
|
@@ -1,1603 +1,1634 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CascadeStore = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
|
-
var Entity_1 = require("../types/Entity");
|
|
7
|
-
var RowStore_1 = require("../types/RowStore");
|
|
8
|
-
var filter_1 = require("./filter");
|
|
9
|
-
var relation_1 = require("./relation");
|
|
10
|
-
var types_1 = require("../types");
|
|
11
|
-
var lodash_1 = require("../utils/lodash");
|
|
12
|
-
var filter_2 = require("./filter");
|
|
13
|
-
var uuid_1 = require("../utils/uuid");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
_a
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
_b
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
_a
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
_b
|
|
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
|
-
_c)
|
|
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
|
-
_d
|
|
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
|
-
_a
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
_b
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
_c
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
var
|
|
222
|
-
var
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
var
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
_a
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
_a
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
_b
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
var
|
|
263
|
-
var
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
var
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
_a
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
var
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
_a
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
_a
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
var
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
var
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
_a
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
*
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
A
|
|
381
|
-
A UPDATE/B
|
|
382
|
-
A UPDATE/B
|
|
383
|
-
A
|
|
384
|
-
A REMOVE/B
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
A
|
|
389
|
-
A UPDATE/B
|
|
390
|
-
A UPDATE/B
|
|
391
|
-
A
|
|
392
|
-
A REMOVE/B
|
|
393
|
-
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
* @param
|
|
400
|
-
* @param
|
|
401
|
-
* @param
|
|
402
|
-
* @param
|
|
403
|
-
* @param
|
|
404
|
-
* @param
|
|
405
|
-
* @
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
var
|
|
410
|
-
var
|
|
411
|
-
var
|
|
412
|
-
var
|
|
413
|
-
var
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
//
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
var
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
_a
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
var
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
var
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
_b)
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
_c),
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
var
|
|
544
|
-
var
|
|
545
|
-
|
|
546
|
-
var
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
//
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
//
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
Object.assign(dataOtm, (
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
return [
|
|
764
|
-
case
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
return [
|
|
878
|
-
case
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
case
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
case
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
return [
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
var
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
}
|
|
1276
|
-
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
var
|
|
1286
|
-
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
}
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
return [3 /*break*/,
|
|
1412
|
-
case
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
throw
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
if (
|
|
1469
|
-
var
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
CascadeStore.prototype.
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
}
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
var
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
_a
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
}
|
|
1590
|
-
case
|
|
1591
|
-
_b.sent();
|
|
1592
|
-
if (
|
|
1593
|
-
|
|
1594
|
-
}
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CascadeStore = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
|
+
var Entity_1 = require("../types/Entity");
|
|
7
|
+
var RowStore_1 = require("../types/RowStore");
|
|
8
|
+
var filter_1 = require("./filter");
|
|
9
|
+
var relation_1 = require("./relation");
|
|
10
|
+
var types_1 = require("../types");
|
|
11
|
+
var lodash_1 = require("../utils/lodash");
|
|
12
|
+
var filter_2 = require("./filter");
|
|
13
|
+
var uuid_1 = require("../utils/uuid");
|
|
14
|
+
var selection_1 = require("./selection");
|
|
15
|
+
/**这个用来处理级联的select和update,对不同能力的 */
|
|
16
|
+
var CascadeStore = /** @class */ (function (_super) {
|
|
17
|
+
tslib_1.__extends(CascadeStore, _super);
|
|
18
|
+
function CascadeStore(storageSchema) {
|
|
19
|
+
return _super.call(this, storageSchema) || this;
|
|
20
|
+
}
|
|
21
|
+
CascadeStore.prototype.destructCascadeSelect = function (entity, projection2, context, cascadeSelectFn, aggregateFn, option) {
|
|
22
|
+
var _this = this;
|
|
23
|
+
var projection = {};
|
|
24
|
+
var cascadeSelectionFns = [];
|
|
25
|
+
var supportMtoJoin = this.supportManyToOneJoin();
|
|
26
|
+
var toModi = this.getSchema()[entity].toModi;
|
|
27
|
+
var _loop_1 = function (attr) {
|
|
28
|
+
var _a, _b, _c, _d;
|
|
29
|
+
var relation = (0, relation_1.judgeRelation)(this_1.storageSchema, entity, attr);
|
|
30
|
+
if (relation === 1 || relation == 0) {
|
|
31
|
+
Object.assign(projection, (_a = {},
|
|
32
|
+
_a[attr] = projection2[attr],
|
|
33
|
+
_a));
|
|
34
|
+
}
|
|
35
|
+
else if (relation === 2) {
|
|
36
|
+
// 基于entity/entityId的多对一
|
|
37
|
+
Object.assign(projection, {
|
|
38
|
+
entity: 1,
|
|
39
|
+
entityId: 1,
|
|
40
|
+
});
|
|
41
|
+
if (supportMtoJoin) {
|
|
42
|
+
cascadeSelectionFns.push(function (result) {
|
|
43
|
+
if (!toModi) {
|
|
44
|
+
result.forEach(function (ele) {
|
|
45
|
+
if (ele.entity === attr) {
|
|
46
|
+
(0, assert_1.default)(ele.entityId);
|
|
47
|
+
if (!ele[attr]) {
|
|
48
|
+
throw new types_1.OakRowUnexistedException([{
|
|
49
|
+
entity: attr,
|
|
50
|
+
selection: {
|
|
51
|
+
data: projection2[attr],
|
|
52
|
+
filter: {
|
|
53
|
+
id: ele.entityId,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}]);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
var _e = this_1.destructCascadeSelect(attr, projection2[attr], context, cascadeSelectFn, aggregateFn, option), subProjection = _e.projection, subCascadeSelectionFns = _e.cascadeSelectionFns;
|
|
63
|
+
Object.assign(projection, (_b = {},
|
|
64
|
+
_b[attr] = subProjection,
|
|
65
|
+
_b));
|
|
66
|
+
subCascadeSelectionFns.forEach(function (ele) { return cascadeSelectionFns.push(function (result) {
|
|
67
|
+
return ele(result.map(function (ele2) { return ele2[attr]; }).filter(function (ele2) { return !!ele2; }));
|
|
68
|
+
}); });
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
cascadeSelectionFns.push(function (result) {
|
|
72
|
+
var dealWithSubRows = function (subRows) {
|
|
73
|
+
(0, assert_1.default)(subRows.length <= entityIds.length);
|
|
74
|
+
if (subRows.length < entityIds.length && !toModi) {
|
|
75
|
+
throw new types_1.OakRowUnexistedException([{
|
|
76
|
+
entity: attr,
|
|
77
|
+
selection: {
|
|
78
|
+
data: projection2[attr],
|
|
79
|
+
filter: {
|
|
80
|
+
id: {
|
|
81
|
+
$in: entityIds
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
}]);
|
|
86
|
+
}
|
|
87
|
+
result.forEach(function (ele) {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
if (ele.entity === attr) {
|
|
90
|
+
var subRow = subRows.find(function (ele2) { return ele2.id === ele.entityId; });
|
|
91
|
+
if (subRow) {
|
|
92
|
+
Object.assign(ele, (_a = {},
|
|
93
|
+
_a[attr] = subRow,
|
|
94
|
+
_a));
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
Object.assign(ele, (_b = {},
|
|
98
|
+
_b[attr] = null,
|
|
99
|
+
_b));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
var entityIds = (0, lodash_1.uniq)(result.filter(function (ele) { return ele.entity === attr; }).map(function (ele) {
|
|
105
|
+
(0, assert_1.default)(ele.entityId !== null);
|
|
106
|
+
return ele.entityId;
|
|
107
|
+
}));
|
|
108
|
+
if (entityIds.length > 0) {
|
|
109
|
+
var subRows = cascadeSelectFn.call(_this, attr, {
|
|
110
|
+
data: projection2[attr],
|
|
111
|
+
filter: {
|
|
112
|
+
id: {
|
|
113
|
+
$in: entityIds
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
}, context, option);
|
|
117
|
+
if (subRows instanceof Promise) {
|
|
118
|
+
return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
dealWithSubRows(subRows);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else if (typeof relation === 'string') {
|
|
130
|
+
Object.assign(projection, (_c = {},
|
|
131
|
+
_c["".concat(attr, "Id")] = 1,
|
|
132
|
+
_c));
|
|
133
|
+
if (supportMtoJoin) {
|
|
134
|
+
if (!toModi) {
|
|
135
|
+
// 如果不是modi,要保证外键没有空指针
|
|
136
|
+
cascadeSelectionFns.push(function (result) {
|
|
137
|
+
if (!toModi) {
|
|
138
|
+
result.forEach(function (ele) {
|
|
139
|
+
if (ele["".concat(attr, "Id")] && !ele[attr]) {
|
|
140
|
+
throw new types_1.OakRowUnexistedException([{
|
|
141
|
+
entity: relation,
|
|
142
|
+
selection: {
|
|
143
|
+
data: projection2[attr],
|
|
144
|
+
filter: {
|
|
145
|
+
id: ele["".concat(attr, "Id")],
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}]);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
var _f = this_1.destructCascadeSelect(relation, projection2[attr], context, cascadeSelectFn, aggregateFn, option), subProjection = _f.projection, subCascadeSelectionFns = _f.cascadeSelectionFns;
|
|
155
|
+
Object.assign(projection, (_d = {},
|
|
156
|
+
_d[attr] = subProjection,
|
|
157
|
+
_d));
|
|
158
|
+
subCascadeSelectionFns.forEach(function (ele) { return cascadeSelectionFns.push(function (result) {
|
|
159
|
+
return ele(result.map(function (ele2) { return ele2[attr]; }).filter(function (ele2) { return !!ele2; }));
|
|
160
|
+
}); });
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
cascadeSelectionFns.push(function (result) {
|
|
164
|
+
var dealWithSubRows = function (subRows) {
|
|
165
|
+
(0, assert_1.default)(subRows.length <= ids.length);
|
|
166
|
+
if (subRows.length < ids.length && !toModi) {
|
|
167
|
+
throw new types_1.OakRowUnexistedException([{
|
|
168
|
+
entity: relation,
|
|
169
|
+
selection: {
|
|
170
|
+
data: projection2[attr],
|
|
171
|
+
filter: {
|
|
172
|
+
id: {
|
|
173
|
+
$in: ids
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
}
|
|
177
|
+
}]);
|
|
178
|
+
}
|
|
179
|
+
result.forEach(function (ele) {
|
|
180
|
+
var _a, _b, _c;
|
|
181
|
+
if (ele["".concat(attr, "Id")]) {
|
|
182
|
+
var subRow = subRows.find(function (ele2) { return ele2.id === ele["".concat(attr, "Id")]; });
|
|
183
|
+
if (subRow) {
|
|
184
|
+
Object.assign(ele, (_a = {},
|
|
185
|
+
_a[attr] = subRow,
|
|
186
|
+
_a));
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
Object.assign(ele, (_b = {},
|
|
190
|
+
_b[attr] = null,
|
|
191
|
+
_b));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
Object.assign(ele, (_c = {},
|
|
196
|
+
_c[attr] = null,
|
|
197
|
+
_c));
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
var ids = (0, lodash_1.uniq)(result.filter(function (ele) { return !!(ele["".concat(attr, "Id")]); }).map(function (ele) { return ele["".concat(attr, "Id")]; }));
|
|
202
|
+
if (ids.length > 0) {
|
|
203
|
+
var subRows = cascadeSelectFn.call(_this, relation, {
|
|
204
|
+
data: projection2[attr],
|
|
205
|
+
filter: {
|
|
206
|
+
id: {
|
|
207
|
+
$in: ids
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
}, context, option);
|
|
211
|
+
if (subRows instanceof Promise) {
|
|
212
|
+
return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
|
|
213
|
+
}
|
|
214
|
+
dealWithSubRows(subRows);
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
(0, assert_1.default)(relation instanceof Array);
|
|
221
|
+
var _g = projection2[attr], subProjection_1 = _g.data, subFilter_1 = _g.filter, indexFrom_1 = _g.indexFrom, count_1 = _g.count, subSorter_1 = _g.sorter;
|
|
222
|
+
var _h = tslib_1.__read(relation, 2), entity2_1 = _h[0], foreignKey_1 = _h[1];
|
|
223
|
+
var isAggr = attr.endsWith('$$aggr');
|
|
224
|
+
if (foreignKey_1) {
|
|
225
|
+
// 基于属性的一对多
|
|
226
|
+
if (isAggr) {
|
|
227
|
+
// 是聚合运算
|
|
228
|
+
cascadeSelectionFns.push(function (result) {
|
|
229
|
+
var aggrResults = result.map(function (row) {
|
|
230
|
+
var _a, _b;
|
|
231
|
+
var aggrResult = aggregateFn.call(_this, entity2_1, {
|
|
232
|
+
data: subProjection_1,
|
|
233
|
+
filter: (0, filter_1.combineFilters)([(_a = {},
|
|
234
|
+
_a[foreignKey_1] = row.id,
|
|
235
|
+
_a), subFilter_1]),
|
|
236
|
+
sorter: subSorter_1,
|
|
237
|
+
indexFrom: indexFrom_1,
|
|
238
|
+
count: count_1
|
|
239
|
+
}, context, option);
|
|
240
|
+
if (aggrResult instanceof Promise) {
|
|
241
|
+
return aggrResult.then(function (aggrResultResult) {
|
|
242
|
+
var _a;
|
|
243
|
+
return Object.assign(row, (_a = {},
|
|
244
|
+
_a[attr] = aggrResultResult,
|
|
245
|
+
_a));
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
Object.assign(row, (_b = {},
|
|
250
|
+
_b[attr] = aggrResult,
|
|
251
|
+
_b));
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
if (aggrResults.length > 0 && aggrResults[0] instanceof Promise) {
|
|
255
|
+
return Promise.all(aggrResults).then(function () { return undefined; });
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
// 是一对多查询
|
|
261
|
+
cascadeSelectionFns.push(function (result) {
|
|
262
|
+
var _a;
|
|
263
|
+
var ids = result.map(function (ele) { return ele.id; });
|
|
264
|
+
var dealWithSubRows = function (subRows) {
|
|
265
|
+
result.forEach(function (ele) {
|
|
266
|
+
var _a;
|
|
267
|
+
var subRowss = subRows.filter(function (ele2) { return ele2[foreignKey_1] === ele.id; });
|
|
268
|
+
(0, assert_1.default)(subRowss);
|
|
269
|
+
Object.assign(ele, (_a = {},
|
|
270
|
+
_a[attr] = subRowss,
|
|
271
|
+
_a));
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
if (ids.length > 0) {
|
|
275
|
+
var subRows = cascadeSelectFn.call(_this, entity2_1, {
|
|
276
|
+
data: subProjection_1,
|
|
277
|
+
filter: (0, filter_1.combineFilters)([(_a = {},
|
|
278
|
+
_a[foreignKey_1] = {
|
|
279
|
+
$in: ids,
|
|
280
|
+
},
|
|
281
|
+
_a), subFilter_1]),
|
|
282
|
+
sorter: subSorter_1,
|
|
283
|
+
indexFrom: indexFrom_1,
|
|
284
|
+
count: count_1
|
|
285
|
+
}, context, option);
|
|
286
|
+
if (subRows instanceof Promise) {
|
|
287
|
+
return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
|
|
288
|
+
}
|
|
289
|
+
dealWithSubRows(subRows);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
// 基于entity的多对一
|
|
296
|
+
if (isAggr) {
|
|
297
|
+
// 是聚合运算
|
|
298
|
+
cascadeSelectionFns.push(function (result) {
|
|
299
|
+
var aggrResults = result.map(function (row) {
|
|
300
|
+
var _a;
|
|
301
|
+
var aggrResult = aggregateFn.call(_this, entity2_1, {
|
|
302
|
+
data: subProjection_1,
|
|
303
|
+
filter: (0, filter_1.combineFilters)([{
|
|
304
|
+
entity: entity,
|
|
305
|
+
entityId: row.id,
|
|
306
|
+
}, subFilter_1]),
|
|
307
|
+
sorter: subSorter_1,
|
|
308
|
+
indexFrom: indexFrom_1,
|
|
309
|
+
count: count_1
|
|
310
|
+
}, context, option);
|
|
311
|
+
if (aggrResult instanceof Promise) {
|
|
312
|
+
return aggrResult.then(function (aggrResultResult) {
|
|
313
|
+
var _a;
|
|
314
|
+
return Object.assign(row, (_a = {},
|
|
315
|
+
_a[attr] = aggrResultResult,
|
|
316
|
+
_a));
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
Object.assign(row, (_a = {},
|
|
321
|
+
_a[attr] = aggrResult,
|
|
322
|
+
_a));
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
if (aggrResults.length > 0 && aggrResults[0] instanceof Promise) {
|
|
326
|
+
return Promise.all(aggrResults).then(function () { return undefined; });
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
// 是一对多查询
|
|
332
|
+
cascadeSelectionFns.push(function (result) {
|
|
333
|
+
var ids = result.map(function (ele) { return ele.id; });
|
|
334
|
+
var dealWithSubRows = function (subRows) {
|
|
335
|
+
result.forEach(function (ele) {
|
|
336
|
+
var _a;
|
|
337
|
+
var subRowss = subRows.filter(function (ele2) { return ele2.entityId === ele.id; });
|
|
338
|
+
(0, assert_1.default)(subRowss);
|
|
339
|
+
Object.assign(ele, (_a = {},
|
|
340
|
+
_a[attr] = subRowss,
|
|
341
|
+
_a));
|
|
342
|
+
});
|
|
343
|
+
};
|
|
344
|
+
if (ids.length > 0) {
|
|
345
|
+
var subRows = cascadeSelectFn.call(_this, entity2_1, {
|
|
346
|
+
data: subProjection_1,
|
|
347
|
+
filter: (0, filter_1.combineFilters)([{
|
|
348
|
+
entity: entity,
|
|
349
|
+
entityId: {
|
|
350
|
+
$in: ids,
|
|
351
|
+
}
|
|
352
|
+
}, subFilter_1]),
|
|
353
|
+
sorter: subSorter_1,
|
|
354
|
+
indexFrom: indexFrom_1,
|
|
355
|
+
count: count_1
|
|
356
|
+
}, context, option);
|
|
357
|
+
if (subRows instanceof Promise) {
|
|
358
|
+
return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
|
|
359
|
+
}
|
|
360
|
+
dealWithSubRows(subRows);
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
var this_1 = this;
|
|
368
|
+
for (var attr in projection2) {
|
|
369
|
+
_loop_1(attr);
|
|
370
|
+
}
|
|
371
|
+
return {
|
|
372
|
+
projection: projection,
|
|
373
|
+
cascadeSelectionFns: cascadeSelectionFns,
|
|
374
|
+
};
|
|
375
|
+
};
|
|
376
|
+
/**
|
|
377
|
+
* 级联更新
|
|
378
|
+
* A --> B
|
|
379
|
+
多对一:A CREATE/B CREATE,B data的主键赋到A的data上
|
|
380
|
+
A CREATE/B UPDATE,B filter的主键来自A的data
|
|
381
|
+
A UPDATE/B CREATE,B data的主键赋到A的data上
|
|
382
|
+
A UPDATE/B UPDATE,B filter的主键来自A的row
|
|
383
|
+
A UPDATE/B REMOVE,B filter的主键来自A的row
|
|
384
|
+
A REMOVE/B UPDATE,B filter的主键来自A的row
|
|
385
|
+
A REMOVE/B REMOVE,B filter的主键来自A的row
|
|
386
|
+
|
|
387
|
+
一对多:A CREATE/B CREATE,A data上的主键赋到B的data上
|
|
388
|
+
A CREATE/B UPDATE,A data上的主键赋到B的data上
|
|
389
|
+
A UPDATE/B CREATE,A filter上的主键赋到B的data上(一定是带主键的filter)
|
|
390
|
+
A UPDATE/B UPDATE,A filter上的主键赋到B的filter上(一定是带主键的filter)
|
|
391
|
+
A UPDATE/B REMOVE,A filter上的主键赋到B的filter上(一定是带主键的filter)
|
|
392
|
+
A REMOVE/B UPDATE,A filter上的主键赋到B的filter上(且B关于A的外键清空)
|
|
393
|
+
A REMOVE/B REMOVE,A filter上的主键赋到B的filter上
|
|
394
|
+
*
|
|
395
|
+
* 延时更新,
|
|
396
|
+
* A(业务级别的申请对象) ---> B(业务级别需要更新的对象)
|
|
397
|
+
* 两者必须通过entity/entityId关联
|
|
398
|
+
* 此时需要把对B的更新记录成一条新插入的Modi对象,并将A上的entity/entityId指向该对象(新生成的Modi对象的id与此operation的id保持一致)
|
|
399
|
+
* @param entity
|
|
400
|
+
* @param action
|
|
401
|
+
* @param data
|
|
402
|
+
* @param context
|
|
403
|
+
* @param option
|
|
404
|
+
* @param result
|
|
405
|
+
* @param filter
|
|
406
|
+
* @returns
|
|
407
|
+
*/
|
|
408
|
+
CascadeStore.prototype.destructCascadeUpdate = function (entity, action, data, context, option, cascadeUpdate, filter) {
|
|
409
|
+
var _this = this;
|
|
410
|
+
var modiAttr = this.getSchema()[entity].toModi;
|
|
411
|
+
var option2 = Object.assign({}, option);
|
|
412
|
+
var opData = {};
|
|
413
|
+
var beforeFns = [];
|
|
414
|
+
var afterFns = [];
|
|
415
|
+
if (modiAttr && action !== 'remove' && !option.dontCreateModi) {
|
|
416
|
+
// create/update具有modi对象的对象,对其子对象的update行为全部是create modi对象(缓存动作)
|
|
417
|
+
// delete此对象,所有的modi子对象应该通过触发器作废,这个目前先通过系统的trigger来实现
|
|
418
|
+
(0, assert_1.default)(!option2.modiParentId && !option2.modiParentEntity);
|
|
419
|
+
if (action === 'create') {
|
|
420
|
+
option2.modiParentId = data.id;
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
(0, assert_1.default)((filter === null || filter === void 0 ? void 0 : filter.id) && typeof filter.id === 'string');
|
|
424
|
+
option2.modiParentId = filter.id;
|
|
425
|
+
}
|
|
426
|
+
option2.modiParentEntity = entity;
|
|
427
|
+
}
|
|
428
|
+
var _loop_2 = function (attr) {
|
|
429
|
+
var _a, _b, _c, e_1, _d;
|
|
430
|
+
var relation = (0, relation_1.judgeRelation)(this_2.storageSchema, entity, attr);
|
|
431
|
+
if (relation === 1) {
|
|
432
|
+
Object.assign(opData, (_a = {},
|
|
433
|
+
_a[attr] = data[attr],
|
|
434
|
+
_a));
|
|
435
|
+
}
|
|
436
|
+
else if (relation === 2) {
|
|
437
|
+
// 基于entity/entityId的many-to-one
|
|
438
|
+
var operationMto_1 = data[attr];
|
|
439
|
+
var actionMto = operationMto_1.action, dataMto = operationMto_1.data, filterMto = operationMto_1.filter;
|
|
440
|
+
if (actionMto === 'create') {
|
|
441
|
+
Object.assign(opData, {
|
|
442
|
+
entityId: dataMto.id,
|
|
443
|
+
entity: attr,
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
else if (action === 'create') {
|
|
447
|
+
var fkId = data.entityId, entity_1 = data.entity;
|
|
448
|
+
(0, assert_1.default)(typeof fkId === 'string' || entity_1 === attr);
|
|
449
|
+
if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
|
|
450
|
+
// 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
|
|
451
|
+
(0, assert_1.default)(filterMto.id === fkId);
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
// A中data的entityId作为B中filter的主键
|
|
455
|
+
Object.assign(operationMto_1, {
|
|
456
|
+
filter: (0, filter_1.addFilterSegment)({
|
|
457
|
+
id: fkId,
|
|
458
|
+
}),
|
|
459
|
+
filterMto: filterMto,
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
// 剩下三种情况都是B中的filter的id来自A中row的entityId
|
|
465
|
+
(0, assert_1.default)(!data.hasOwnProperty('entityId') && !data.hasOwnProperty('entity'));
|
|
466
|
+
if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
|
|
467
|
+
// 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
|
|
468
|
+
(0, assert_1.default)(typeof filterMto.id === 'string');
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
// A中data的entityId作为B中filter的主键
|
|
472
|
+
Object.assign(operationMto_1, {
|
|
473
|
+
filter: (0, filter_1.addFilterSegment)({
|
|
474
|
+
id: {
|
|
475
|
+
$in: {
|
|
476
|
+
entity: entity,
|
|
477
|
+
data: {
|
|
478
|
+
entityId: 1,
|
|
479
|
+
},
|
|
480
|
+
filter: (0, filter_1.addFilterSegment)({
|
|
481
|
+
entity: attr,
|
|
482
|
+
}, filter),
|
|
483
|
+
}
|
|
484
|
+
},
|
|
485
|
+
}, filterMto),
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
beforeFns.push(function () { return cascadeUpdate.call(_this, attr, operationMto_1, context, option2); });
|
|
490
|
+
}
|
|
491
|
+
else if (typeof relation === 'string') {
|
|
492
|
+
// 基于attr的外键的many-to-one
|
|
493
|
+
var operationMto_2 = data[attr];
|
|
494
|
+
var actionMto = operationMto_2.action, dataMto = operationMto_2.data, filterMto = operationMto_2.filter;
|
|
495
|
+
if (actionMto === 'create') {
|
|
496
|
+
Object.assign(opData, (_b = {},
|
|
497
|
+
_b["".concat(attr, "Id")] = dataMto.id,
|
|
498
|
+
_b));
|
|
499
|
+
}
|
|
500
|
+
else if (action === 'create') {
|
|
501
|
+
var _e = data, _f = "".concat(attr, "Id"), fkId = _e[_f];
|
|
502
|
+
(0, assert_1.default)(typeof fkId === 'string');
|
|
503
|
+
if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
|
|
504
|
+
// 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
|
|
505
|
+
(0, assert_1.default)(filterMto.id === fkId);
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
// A中data的entityId作为B中filter的主键
|
|
509
|
+
Object.assign(operationMto_2, {
|
|
510
|
+
filter: (0, filter_1.addFilterSegment)(filterMto || {}, {
|
|
511
|
+
id: fkId,
|
|
512
|
+
}),
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
(0, assert_1.default)(!data.hasOwnProperty("".concat(attr, "Id")));
|
|
518
|
+
if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
|
|
519
|
+
// 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
|
|
520
|
+
(0, assert_1.default)(typeof filterMto.id === 'string');
|
|
521
|
+
}
|
|
522
|
+
else {
|
|
523
|
+
// A中data的entityId作为B中filter的主键
|
|
524
|
+
Object.assign(operationMto_2, {
|
|
525
|
+
filter: (0, filter_1.addFilterSegment)(filterMto || {}, {
|
|
526
|
+
id: {
|
|
527
|
+
$in: {
|
|
528
|
+
entity: entity,
|
|
529
|
+
data: (_c = {},
|
|
530
|
+
_c["".concat(attr, "Id")] = 1,
|
|
531
|
+
_c),
|
|
532
|
+
filter: filter,
|
|
533
|
+
}
|
|
534
|
+
},
|
|
535
|
+
}),
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
beforeFns.push(function () { return cascadeUpdate.call(_this, relation, operationMto_2, context, option2); });
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
(0, assert_1.default)(relation instanceof Array);
|
|
543
|
+
var _g = tslib_1.__read(relation, 2), entityOtm_1 = _g[0], foreignKey_2 = _g[1];
|
|
544
|
+
var otmOperations = data[attr];
|
|
545
|
+
var dealWithOneToMany = function (otm) {
|
|
546
|
+
var _a, _b, _c, _d, _e, _f;
|
|
547
|
+
var actionOtm = otm.action, dataOtm = otm.data, filterOtm = otm.filter;
|
|
548
|
+
if (!foreignKey_2) {
|
|
549
|
+
// 基于entity/entityId的one-to-many
|
|
550
|
+
if (action === 'create') {
|
|
551
|
+
var id_1 = data.id;
|
|
552
|
+
if (dataOtm instanceof Array) {
|
|
553
|
+
dataOtm.forEach(function (ele) { return Object.assign(ele, {
|
|
554
|
+
entity: entity,
|
|
555
|
+
entityId: id_1,
|
|
556
|
+
}); });
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
559
|
+
Object.assign(dataOtm, {
|
|
560
|
+
entity: entity,
|
|
561
|
+
entityId: id_1,
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
else if (actionOtm === 'create') {
|
|
566
|
+
// 这里先假设A(必是update)的filter上一定有id,否则用户界面上应该设计不出来这样的操作
|
|
567
|
+
// todo 这个假设对watcher等后台行为可能不成立,等遇到create/create一对多的case再完善
|
|
568
|
+
var id_2 = filter.id;
|
|
569
|
+
(0, assert_1.default)(typeof id_2 === 'string');
|
|
570
|
+
if (dataOtm instanceof Array) {
|
|
571
|
+
dataOtm.forEach(function (ele) { return Object.assign(ele, {
|
|
572
|
+
entity: entity,
|
|
573
|
+
entityId: id_2,
|
|
574
|
+
}); });
|
|
575
|
+
}
|
|
576
|
+
else {
|
|
577
|
+
Object.assign(dataOtm, {
|
|
578
|
+
entity: entity,
|
|
579
|
+
entityId: id_2,
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
else {
|
|
584
|
+
// 这里优化一下,如果filter上有id,直接更新成根据entityId来过滤
|
|
585
|
+
// 除了性能原因之外,还因为会制造出user: { id: xxx }这样的查询,general中不允许这样查询的出现
|
|
586
|
+
if (filter) {
|
|
587
|
+
if (filter.id && Object.keys(filter).length === 1) {
|
|
588
|
+
Object.assign(otm, {
|
|
589
|
+
filter: (0, filter_1.addFilterSegment)({
|
|
590
|
+
entity: entity,
|
|
591
|
+
entityId: filter.id,
|
|
592
|
+
}, filterOtm),
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
else {
|
|
596
|
+
Object.assign(otm, {
|
|
597
|
+
filter: (0, filter_1.addFilterSegment)((_a = {},
|
|
598
|
+
_a[entity] = filter,
|
|
599
|
+
_a), filterOtm),
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
if (action === 'remove' && actionOtm === 'update') {
|
|
604
|
+
Object.assign(dataOtm, {
|
|
605
|
+
entity: null,
|
|
606
|
+
entityId: null,
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
else {
|
|
612
|
+
// 基于foreignKey的one-to-many
|
|
613
|
+
if (action === 'create') {
|
|
614
|
+
var id_3 = data.id;
|
|
615
|
+
if (dataOtm instanceof Array) {
|
|
616
|
+
dataOtm.forEach(function (ele) {
|
|
617
|
+
var _a;
|
|
618
|
+
return Object.assign(ele, (_a = {},
|
|
619
|
+
_a[foreignKey_2] = id_3,
|
|
620
|
+
_a));
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
else {
|
|
624
|
+
Object.assign(dataOtm, (_b = {},
|
|
625
|
+
_b[foreignKey_2] = id_3,
|
|
626
|
+
_b));
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
else if (actionOtm === 'create') {
|
|
630
|
+
// 这里先假设A(必是update)的filter上一定有id,否则用户界面上应该设计不出来这样的操作
|
|
631
|
+
// todo 这个假设在后台可能不成立,等遇到了再说
|
|
632
|
+
var id_4 = filter.id;
|
|
633
|
+
(0, assert_1.default)(typeof id_4 === 'string');
|
|
634
|
+
if (dataOtm instanceof Array) {
|
|
635
|
+
dataOtm.forEach(function (ele) {
|
|
636
|
+
var _a;
|
|
637
|
+
return Object.assign(ele, (_a = {},
|
|
638
|
+
_a[foreignKey_2] = id_4,
|
|
639
|
+
_a));
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
else {
|
|
643
|
+
Object.assign(dataOtm, (_c = {},
|
|
644
|
+
_c[foreignKey_2] = id_4,
|
|
645
|
+
_c));
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
// 这里优化一下,如果filter上有id,直接更新成根据entityId来过滤
|
|
650
|
+
// 除了性能原因之外,还因为会制造出user: { id: xxx }这样的查询,general中不允许这样查询的出现
|
|
651
|
+
// 绝大多数情况都是id,但也有可能update可能出现上层filter不是根据id的(userEntityGrant的过期触发的wechatQrCode的过期,见general中的userEntityGrant的trigger)
|
|
652
|
+
if (filter) {
|
|
653
|
+
if (filter.id && Object.keys(filter).length === 1) {
|
|
654
|
+
Object.assign(otm, {
|
|
655
|
+
filter: (0, filter_1.addFilterSegment)((_d = {},
|
|
656
|
+
_d[foreignKey_2] = filter.id,
|
|
657
|
+
_d), filterOtm),
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
else {
|
|
661
|
+
Object.assign(otm, {
|
|
662
|
+
filter: (0, filter_1.addFilterSegment)((_e = {},
|
|
663
|
+
_e[foreignKey_2.slice(0, foreignKey_2.length - 2)] = filter,
|
|
664
|
+
_e), filterOtm),
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
if (action === 'remove' && actionOtm === 'update') {
|
|
669
|
+
Object.assign(dataOtm, (_f = {},
|
|
670
|
+
_f[foreignKey_2] = null,
|
|
671
|
+
_f));
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
// 一对多的依赖应该后建,否则中间会出现空指针,导致checker等出错
|
|
676
|
+
afterFns.push(function () { return cascadeUpdate.call(_this, entityOtm_1, otm, context, option2); });
|
|
677
|
+
};
|
|
678
|
+
if (otmOperations instanceof Array) {
|
|
679
|
+
try {
|
|
680
|
+
for (var otmOperations_1 = (e_1 = void 0, tslib_1.__values(otmOperations)), otmOperations_1_1 = otmOperations_1.next(); !otmOperations_1_1.done; otmOperations_1_1 = otmOperations_1.next()) {
|
|
681
|
+
var oper = otmOperations_1_1.value;
|
|
682
|
+
dealWithOneToMany(oper);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
686
|
+
finally {
|
|
687
|
+
try {
|
|
688
|
+
if (otmOperations_1_1 && !otmOperations_1_1.done && (_d = otmOperations_1.return)) _d.call(otmOperations_1);
|
|
689
|
+
}
|
|
690
|
+
finally { if (e_1) throw e_1.error; }
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
else {
|
|
694
|
+
dealWithOneToMany(otmOperations);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
var this_2 = this;
|
|
699
|
+
for (var attr in data) {
|
|
700
|
+
_loop_2(attr);
|
|
701
|
+
}
|
|
702
|
+
return {
|
|
703
|
+
data: opData,
|
|
704
|
+
beforeFns: beforeFns,
|
|
705
|
+
afterFns: afterFns,
|
|
706
|
+
};
|
|
707
|
+
};
|
|
708
|
+
// 对插入的数据,没有初始值的属性置null
|
|
709
|
+
CascadeStore.prototype.preProcessDataCreated = function (entity, data) {
|
|
710
|
+
var now = Date.now();
|
|
711
|
+
var attributes = this.getSchema()[entity].attributes;
|
|
712
|
+
var processSingle = function (data2) {
|
|
713
|
+
var _a, _b;
|
|
714
|
+
for (var key in attributes) {
|
|
715
|
+
if (data2[key] === undefined) {
|
|
716
|
+
Object.assign(data2, (_a = {},
|
|
717
|
+
_a[key] = null,
|
|
718
|
+
_a));
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
Object.assign(data2, (_b = {},
|
|
722
|
+
_b[Entity_1.CreateAtAttribute] = now,
|
|
723
|
+
_b[Entity_1.UpdateAtAttribute] = now,
|
|
724
|
+
_b[Entity_1.DeleteAtAttribute] = null,
|
|
725
|
+
_b));
|
|
726
|
+
};
|
|
727
|
+
if (data instanceof Array) {
|
|
728
|
+
data.forEach(function (ele) { return processSingle(ele); });
|
|
729
|
+
}
|
|
730
|
+
else {
|
|
731
|
+
processSingle(data);
|
|
732
|
+
}
|
|
733
|
+
};
|
|
734
|
+
// 对更新的数据,去掉所有的undefined属性
|
|
735
|
+
CascadeStore.prototype.preProcessDataUpdated = function (data) {
|
|
736
|
+
var undefinedKeys = Object.keys(data).filter(function (ele) { return data[ele] === undefined; });
|
|
737
|
+
undefinedKeys.forEach(function (ele) { return (0, lodash_1.unset)(data, ele); });
|
|
738
|
+
};
|
|
739
|
+
CascadeStore.prototype.judgeRelation = function (entity, attr) {
|
|
740
|
+
return (0, relation_1.judgeRelation)(this.storageSchema, entity, attr);
|
|
741
|
+
};
|
|
742
|
+
/**
|
|
743
|
+
* 和具体的update过程无关的例程放在这里,包括对later动作的处理、对oper的记录以及对record的收集等
|
|
744
|
+
* @param entity
|
|
745
|
+
* @param operation
|
|
746
|
+
* @param context
|
|
747
|
+
* @param option
|
|
748
|
+
*/
|
|
749
|
+
CascadeStore.prototype.doUpdateSingleRowAsync = function (entity, operation, context, option) {
|
|
750
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
751
|
+
var data, action, operId, filter, now, _a, modiCreate, result_1, createInner, multipleCreate, data_1, data_1_1, d, createSingleOper, e_2_1, operatorId, createOper, _b, ids_1, selection, rows, modiUpsert, upsertModis, _c, originData, originId, _d, createOper, updateAttrCount, result;
|
|
752
|
+
var e_2, _e, _f, _g, _h, _j, _k, _l;
|
|
753
|
+
var _this = this;
|
|
754
|
+
return tslib_1.__generator(this, function (_m) {
|
|
755
|
+
switch (_m.label) {
|
|
756
|
+
case 0:
|
|
757
|
+
data = operation.data, action = operation.action, operId = operation.id, filter = operation.filter;
|
|
758
|
+
now = Date.now();
|
|
759
|
+
_a = action;
|
|
760
|
+
switch (_a) {
|
|
761
|
+
case 'create': return [3 /*break*/, 1];
|
|
762
|
+
}
|
|
763
|
+
return [3 /*break*/, 23];
|
|
764
|
+
case 1:
|
|
765
|
+
this.preProcessDataCreated(entity, data);
|
|
766
|
+
if (!(option.modiParentEntity && !['modi', 'modiEntity', 'oper', 'operEntity'].includes(entity))) return [3 /*break*/, 3];
|
|
767
|
+
// 变成对modi的插入
|
|
768
|
+
(0, assert_1.default)(option.modiParentId);
|
|
769
|
+
modiCreate = {
|
|
770
|
+
id: 'dummy',
|
|
771
|
+
action: 'create',
|
|
772
|
+
data: {
|
|
773
|
+
id: operId,
|
|
774
|
+
targetEntity: entity,
|
|
775
|
+
action: action,
|
|
776
|
+
entity: option.modiParentEntity,
|
|
777
|
+
entityId: option.modiParentId,
|
|
778
|
+
filter: {
|
|
779
|
+
id: {
|
|
780
|
+
$in: [data.id], //这里记录这个filter是为了后面update的时候直接在其上面update,参见本函数后半段关于modiUpsert相关的优化
|
|
781
|
+
},
|
|
782
|
+
},
|
|
783
|
+
data: data,
|
|
784
|
+
iState: 'active',
|
|
785
|
+
},
|
|
786
|
+
};
|
|
787
|
+
return [4 /*yield*/, this.cascadeUpdateAsync('modi', modiCreate, context, option)];
|
|
788
|
+
case 2:
|
|
789
|
+
_m.sent();
|
|
790
|
+
return [2 /*return*/, 1];
|
|
791
|
+
case 3:
|
|
792
|
+
result_1 = 0;
|
|
793
|
+
createInner = function (operation2) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
794
|
+
var _a, e_3;
|
|
795
|
+
return tslib_1.__generator(this, function (_b) {
|
|
796
|
+
switch (_b.label) {
|
|
797
|
+
case 0:
|
|
798
|
+
_b.trys.push([0, 2, , 3]);
|
|
799
|
+
_a = result_1;
|
|
800
|
+
return [4 /*yield*/, this.updateAbjointRowAsync(entity, operation2, context, option)];
|
|
801
|
+
case 1:
|
|
802
|
+
result_1 = _a + _b.sent();
|
|
803
|
+
return [3 /*break*/, 3];
|
|
804
|
+
case 2:
|
|
805
|
+
e_3 = _b.sent();
|
|
806
|
+
/* 这段代码是处理插入时有重复的行,现在看有问题,等实际需求出现再写
|
|
807
|
+
if (e instanceof OakCongruentRowExists) {
|
|
808
|
+
if (option.allowExists) {
|
|
809
|
+
// 如果允许存在,对已存在行进行update,剩下的行继续insert
|
|
810
|
+
const congruentRow = e.getData() as ED[T]['OpSchema'];
|
|
811
|
+
if (data instanceof Array) {
|
|
812
|
+
const rest = data.filter(
|
|
813
|
+
ele => ele.id !== congruentRow.id
|
|
814
|
+
);
|
|
815
|
+
if (rest.length === data.length) {
|
|
816
|
+
throw e;
|
|
817
|
+
}
|
|
818
|
+
const result2 = await this.updateAbjointRow(
|
|
819
|
+
entity,
|
|
820
|
+
Object.assign({}, operation, {
|
|
821
|
+
data: rest,
|
|
822
|
+
}),
|
|
823
|
+
context,
|
|
824
|
+
option
|
|
825
|
+
);
|
|
826
|
+
|
|
827
|
+
const row = data.find(
|
|
828
|
+
ele => ele.id === congruentRow.id
|
|
829
|
+
);
|
|
830
|
+
const updateData = omit(row, ['id', '$$createAt$$']);
|
|
831
|
+
const result3 = await this.updateAbjointRow(
|
|
832
|
+
entity,
|
|
833
|
+
{
|
|
834
|
+
id: await generateNewId(),
|
|
835
|
+
action: 'update',
|
|
836
|
+
data: updateData,
|
|
837
|
+
filter: {
|
|
838
|
+
id: congruentRow.id,
|
|
839
|
+
} as any,
|
|
840
|
+
},
|
|
841
|
+
context,
|
|
842
|
+
option
|
|
843
|
+
);
|
|
844
|
+
|
|
845
|
+
return result2 + result3;
|
|
846
|
+
}
|
|
847
|
+
else {
|
|
848
|
+
if (data.id !== congruentRow.id) {
|
|
849
|
+
throw e;
|
|
850
|
+
}
|
|
851
|
+
const updateData = omit(data, ['id', '$$createAt$$']);
|
|
852
|
+
const result2 = await this.updateAbjointRow(
|
|
853
|
+
entity,
|
|
854
|
+
{
|
|
855
|
+
id: await generateNewId(),
|
|
856
|
+
action: 'update',
|
|
857
|
+
data: updateData,
|
|
858
|
+
filter: {
|
|
859
|
+
id: congruentRow.id,
|
|
860
|
+
} as any,
|
|
861
|
+
},
|
|
862
|
+
context,
|
|
863
|
+
option
|
|
864
|
+
);
|
|
865
|
+
return result2;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
} */
|
|
869
|
+
throw e_3;
|
|
870
|
+
case 3: return [2 /*return*/];
|
|
871
|
+
}
|
|
872
|
+
});
|
|
873
|
+
}); };
|
|
874
|
+
if (!(data instanceof Array)) return [3 /*break*/, 13];
|
|
875
|
+
multipleCreate = this.supportMultipleCreate();
|
|
876
|
+
if (!multipleCreate) return [3 /*break*/, 5];
|
|
877
|
+
return [4 /*yield*/, createInner(operation)];
|
|
878
|
+
case 4:
|
|
879
|
+
_m.sent();
|
|
880
|
+
return [3 /*break*/, 12];
|
|
881
|
+
case 5:
|
|
882
|
+
_m.trys.push([5, 10, 11, 12]);
|
|
883
|
+
data_1 = tslib_1.__values(data), data_1_1 = data_1.next();
|
|
884
|
+
_m.label = 6;
|
|
885
|
+
case 6:
|
|
886
|
+
if (!!data_1_1.done) return [3 /*break*/, 9];
|
|
887
|
+
d = data_1_1.value;
|
|
888
|
+
createSingleOper = {
|
|
889
|
+
id: 'any',
|
|
890
|
+
action: 'create',
|
|
891
|
+
data: d,
|
|
892
|
+
};
|
|
893
|
+
return [4 /*yield*/, createInner(createSingleOper)];
|
|
894
|
+
case 7:
|
|
895
|
+
_m.sent();
|
|
896
|
+
_m.label = 8;
|
|
897
|
+
case 8:
|
|
898
|
+
data_1_1 = data_1.next();
|
|
899
|
+
return [3 /*break*/, 6];
|
|
900
|
+
case 9: return [3 /*break*/, 12];
|
|
901
|
+
case 10:
|
|
902
|
+
e_2_1 = _m.sent();
|
|
903
|
+
e_2 = { error: e_2_1 };
|
|
904
|
+
return [3 /*break*/, 12];
|
|
905
|
+
case 11:
|
|
906
|
+
try {
|
|
907
|
+
if (data_1_1 && !data_1_1.done && (_e = data_1.return)) _e.call(data_1);
|
|
908
|
+
}
|
|
909
|
+
finally { if (e_2) throw e_2.error; }
|
|
910
|
+
return [7 /*endfinally*/];
|
|
911
|
+
case 12: return [3 /*break*/, 15];
|
|
912
|
+
case 13: return [4 /*yield*/, createInner(operation)];
|
|
913
|
+
case 14:
|
|
914
|
+
_m.sent();
|
|
915
|
+
_m.label = 15;
|
|
916
|
+
case 15:
|
|
917
|
+
if (!option.dontCollect) {
|
|
918
|
+
context.opRecords.push({
|
|
919
|
+
a: 'c',
|
|
920
|
+
e: entity,
|
|
921
|
+
d: data,
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
if (!(!option.dontCreateOper && !['oper', 'operEntity', 'modiEntity', 'modi'].includes(entity))) return [3 /*break*/, 22];
|
|
925
|
+
// 按照框架要求生成Oper和OperEntity这两个内置的对象
|
|
926
|
+
(0, assert_1.default)(operId);
|
|
927
|
+
return [4 /*yield*/, context.getCurrentUserId(true)];
|
|
928
|
+
case 16:
|
|
929
|
+
operatorId = _m.sent();
|
|
930
|
+
if (!operatorId) return [3 /*break*/, 22];
|
|
931
|
+
_f = {
|
|
932
|
+
id: 'dummy',
|
|
933
|
+
action: 'create'
|
|
934
|
+
};
|
|
935
|
+
_g = {
|
|
936
|
+
id: operId,
|
|
937
|
+
action: action,
|
|
938
|
+
data: data,
|
|
939
|
+
operatorId: operatorId
|
|
940
|
+
};
|
|
941
|
+
if (!(data instanceof Array)) return [3 /*break*/, 18];
|
|
942
|
+
_h = {
|
|
943
|
+
id: 'dummy',
|
|
944
|
+
action: 'create'
|
|
945
|
+
};
|
|
946
|
+
return [4 /*yield*/, Promise.all(data.map(function (ele) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
947
|
+
var _a;
|
|
948
|
+
return tslib_1.__generator(this, function (_b) {
|
|
949
|
+
switch (_b.label) {
|
|
950
|
+
case 0:
|
|
951
|
+
_a = {};
|
|
952
|
+
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
|
953
|
+
case 1: return [2 /*return*/, (_a.id = _b.sent(),
|
|
954
|
+
_a.entity = entity,
|
|
955
|
+
_a.entityId = ele.id,
|
|
956
|
+
_a)];
|
|
957
|
+
}
|
|
958
|
+
});
|
|
959
|
+
}); }))];
|
|
960
|
+
case 17:
|
|
961
|
+
_b = (_h.data = _m.sent(),
|
|
962
|
+
_h);
|
|
963
|
+
return [3 /*break*/, 20];
|
|
964
|
+
case 18:
|
|
965
|
+
_j = {
|
|
966
|
+
id: 'dummy',
|
|
967
|
+
action: 'create'
|
|
968
|
+
};
|
|
969
|
+
_k = {};
|
|
970
|
+
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
|
971
|
+
case 19:
|
|
972
|
+
_b = [(_j.data = (_k.id = _m.sent(),
|
|
973
|
+
_k.entity = entity,
|
|
974
|
+
_k.entityId = data.id,
|
|
975
|
+
_k),
|
|
976
|
+
_j)];
|
|
977
|
+
_m.label = 20;
|
|
978
|
+
case 20:
|
|
979
|
+
createOper = (_f.data = (_g.operEntity$oper = _b,
|
|
980
|
+
_g),
|
|
981
|
+
_f);
|
|
982
|
+
return [4 /*yield*/, this.cascadeUpdateAsync('oper', createOper, context, {
|
|
983
|
+
dontCollect: true,
|
|
984
|
+
dontCreateOper: true,
|
|
985
|
+
})];
|
|
986
|
+
case 21:
|
|
987
|
+
_m.sent();
|
|
988
|
+
_m.label = 22;
|
|
989
|
+
case 22: return [2 /*return*/, result_1];
|
|
990
|
+
case 23:
|
|
991
|
+
ids_1 = (0, filter_2.getRelevantIds)(filter);
|
|
992
|
+
if (!(ids_1.length === 0)) return [3 /*break*/, 25];
|
|
993
|
+
selection = {
|
|
994
|
+
data: {
|
|
995
|
+
id: 1,
|
|
996
|
+
},
|
|
997
|
+
filter: operation.filter,
|
|
998
|
+
indexFrom: operation.indexFrom,
|
|
999
|
+
count: operation.count,
|
|
1000
|
+
};
|
|
1001
|
+
return [4 /*yield*/, this.selectAbjointRowAsync(entity, selection, context, {
|
|
1002
|
+
dontCollect: true,
|
|
1003
|
+
})];
|
|
1004
|
+
case 24:
|
|
1005
|
+
rows = _m.sent();
|
|
1006
|
+
ids_1.push.apply(ids_1, tslib_1.__spreadArray([], tslib_1.__read((rows.map(function (ele) { return ele.id; }))), false));
|
|
1007
|
+
_m.label = 25;
|
|
1008
|
+
case 25:
|
|
1009
|
+
if (data) {
|
|
1010
|
+
this.preProcessDataUpdated(data);
|
|
1011
|
+
}
|
|
1012
|
+
if (!(option.modiParentEntity && !['modi', 'modiEntity'].includes(entity))) return [3 /*break*/, 31];
|
|
1013
|
+
modiUpsert = void 0;
|
|
1014
|
+
if (!(action !== 'remove')) return [3 /*break*/, 27];
|
|
1015
|
+
return [4 /*yield*/, this.selectAbjointRowAsync('modi', {
|
|
1016
|
+
data: {
|
|
1017
|
+
id: 1,
|
|
1018
|
+
data: 1,
|
|
1019
|
+
},
|
|
1020
|
+
filter: {
|
|
1021
|
+
targetEntity: entity,
|
|
1022
|
+
action: {
|
|
1023
|
+
$in: ['create', 'update'],
|
|
1024
|
+
},
|
|
1025
|
+
entity: option.modiParentEntity,
|
|
1026
|
+
entityId: option.modiParentId,
|
|
1027
|
+
iState: 'active',
|
|
1028
|
+
filter: ids_1.length > 0 ? {
|
|
1029
|
+
id: {
|
|
1030
|
+
$in: ids_1,
|
|
1031
|
+
},
|
|
1032
|
+
} : filter,
|
|
1033
|
+
},
|
|
1034
|
+
sorter: [
|
|
1035
|
+
{
|
|
1036
|
+
$attr: {
|
|
1037
|
+
$$createAt$$: 1,
|
|
1038
|
+
},
|
|
1039
|
+
$direction: 'desc',
|
|
1040
|
+
}
|
|
1041
|
+
],
|
|
1042
|
+
indexFrom: 0,
|
|
1043
|
+
count: 1,
|
|
1044
|
+
}, context, option)];
|
|
1045
|
+
case 26:
|
|
1046
|
+
upsertModis = _m.sent();
|
|
1047
|
+
if (upsertModis.length > 0) {
|
|
1048
|
+
_c = upsertModis[0], originData = _c.data, originId = _c.id;
|
|
1049
|
+
modiUpsert = {
|
|
1050
|
+
id: 'dummy',
|
|
1051
|
+
action: 'update',
|
|
1052
|
+
data: {
|
|
1053
|
+
data: Object.assign({}, originData, data),
|
|
1054
|
+
},
|
|
1055
|
+
filter: {
|
|
1056
|
+
id: originId,
|
|
1057
|
+
}
|
|
1058
|
+
};
|
|
1059
|
+
}
|
|
1060
|
+
_m.label = 27;
|
|
1061
|
+
case 27:
|
|
1062
|
+
if (!!modiUpsert) return [3 /*break*/, 29];
|
|
1063
|
+
modiUpsert = {
|
|
1064
|
+
id: 'dummy',
|
|
1065
|
+
action: 'create',
|
|
1066
|
+
data: {
|
|
1067
|
+
id: operId,
|
|
1068
|
+
targetEntity: entity,
|
|
1069
|
+
entity: option.modiParentEntity,
|
|
1070
|
+
entityId: option.modiParentId,
|
|
1071
|
+
action: action,
|
|
1072
|
+
data: data,
|
|
1073
|
+
iState: 'active',
|
|
1074
|
+
filter: filter,
|
|
1075
|
+
},
|
|
1076
|
+
};
|
|
1077
|
+
if (!(ids_1.length > 0)) return [3 /*break*/, 29];
|
|
1078
|
+
_d = modiUpsert.data;
|
|
1079
|
+
_l = {
|
|
1080
|
+
id: 'dummy',
|
|
1081
|
+
action: 'create'
|
|
1082
|
+
};
|
|
1083
|
+
return [4 /*yield*/, Promise.all(ids_1.map(function (id) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1084
|
+
var _a;
|
|
1085
|
+
return tslib_1.__generator(this, function (_b) {
|
|
1086
|
+
switch (_b.label) {
|
|
1087
|
+
case 0:
|
|
1088
|
+
_a = {};
|
|
1089
|
+
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
|
1090
|
+
case 1: return [2 /*return*/, (_a.id = _b.sent(),
|
|
1091
|
+
_a.entity = entity,
|
|
1092
|
+
_a.entityId = id,
|
|
1093
|
+
_a)];
|
|
1094
|
+
}
|
|
1095
|
+
});
|
|
1096
|
+
}); }))];
|
|
1097
|
+
case 28:
|
|
1098
|
+
_d.modiEntity$modi = (_l.data = _m.sent(),
|
|
1099
|
+
_l);
|
|
1100
|
+
_m.label = 29;
|
|
1101
|
+
case 29: return [4 /*yield*/, this.cascadeUpdateAsync('modi', modiUpsert, context, option)];
|
|
1102
|
+
case 30:
|
|
1103
|
+
_m.sent();
|
|
1104
|
+
return [2 /*return*/, 1];
|
|
1105
|
+
case 31:
|
|
1106
|
+
createOper = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1107
|
+
var createOper_1;
|
|
1108
|
+
var _a, _b, _c;
|
|
1109
|
+
var _this = this;
|
|
1110
|
+
return tslib_1.__generator(this, function (_d) {
|
|
1111
|
+
switch (_d.label) {
|
|
1112
|
+
case 0:
|
|
1113
|
+
if (!(!(option === null || option === void 0 ? void 0 : option.dontCreateOper) && !['oper', 'operEntity', 'modiEntity', 'modi'].includes(entity) && ids_1.length > 0)) return [3 /*break*/, 3];
|
|
1114
|
+
// 按照框架要求生成Oper和OperEntity这两个内置的对象
|
|
1115
|
+
(0, assert_1.default)(operId);
|
|
1116
|
+
_a = {
|
|
1117
|
+
id: 'dummy',
|
|
1118
|
+
action: 'create'
|
|
1119
|
+
};
|
|
1120
|
+
_b = {
|
|
1121
|
+
id: operId,
|
|
1122
|
+
action: action,
|
|
1123
|
+
data: data
|
|
1124
|
+
};
|
|
1125
|
+
_c = {
|
|
1126
|
+
id: 'dummy',
|
|
1127
|
+
action: 'create'
|
|
1128
|
+
};
|
|
1129
|
+
return [4 /*yield*/, Promise.all(ids_1.map(function (ele) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1130
|
+
var _a;
|
|
1131
|
+
return tslib_1.__generator(this, function (_b) {
|
|
1132
|
+
switch (_b.label) {
|
|
1133
|
+
case 0:
|
|
1134
|
+
_a = {};
|
|
1135
|
+
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
|
1136
|
+
case 1: return [2 /*return*/, (_a.id = _b.sent(),
|
|
1137
|
+
_a.entity = entity,
|
|
1138
|
+
_a.entityId = ele,
|
|
1139
|
+
_a)];
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1142
|
+
}); }))];
|
|
1143
|
+
case 1:
|
|
1144
|
+
createOper_1 = (_a.data = (_b.operEntity$oper = (_c.data = _d.sent(),
|
|
1145
|
+
_c),
|
|
1146
|
+
_b),
|
|
1147
|
+
_a);
|
|
1148
|
+
return [4 /*yield*/, this.cascadeUpdateAsync('oper', createOper_1, context, {
|
|
1149
|
+
dontCollect: true,
|
|
1150
|
+
dontCreateOper: true,
|
|
1151
|
+
})];
|
|
1152
|
+
case 2:
|
|
1153
|
+
_d.sent();
|
|
1154
|
+
_d.label = 3;
|
|
1155
|
+
case 3: return [2 /*return*/];
|
|
1156
|
+
}
|
|
1157
|
+
});
|
|
1158
|
+
}); };
|
|
1159
|
+
if (!(action === 'remove')) return [3 /*break*/, 32];
|
|
1160
|
+
if (!option.dontCollect) {
|
|
1161
|
+
context.opRecords.push({
|
|
1162
|
+
a: 'r',
|
|
1163
|
+
e: entity,
|
|
1164
|
+
f: {
|
|
1165
|
+
id: {
|
|
1166
|
+
$in: ids_1,
|
|
1167
|
+
}
|
|
1168
|
+
},
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
return [3 /*break*/, 36];
|
|
1172
|
+
case 32:
|
|
1173
|
+
updateAttrCount = Object.keys(data).length;
|
|
1174
|
+
if (!(updateAttrCount > 0)) return [3 /*break*/, 33];
|
|
1175
|
+
// 优化一下,如果不更新任何属性,则不实际执行
|
|
1176
|
+
Object.assign(data, {
|
|
1177
|
+
$$updateAt$$: now,
|
|
1178
|
+
});
|
|
1179
|
+
if (!option.dontCollect) {
|
|
1180
|
+
context.opRecords.push({
|
|
1181
|
+
a: 'u',
|
|
1182
|
+
e: entity,
|
|
1183
|
+
d: data,
|
|
1184
|
+
f: {
|
|
1185
|
+
id: {
|
|
1186
|
+
$in: ids_1,
|
|
1187
|
+
}
|
|
1188
|
+
},
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
return [3 /*break*/, 36];
|
|
1192
|
+
case 33:
|
|
1193
|
+
if (!(action !== 'update')) return [3 /*break*/, 35];
|
|
1194
|
+
// 如果不是update动作而是用户自定义的动作,这里还是要记录oper
|
|
1195
|
+
return [4 /*yield*/, createOper()];
|
|
1196
|
+
case 34:
|
|
1197
|
+
// 如果不是update动作而是用户自定义的动作,这里还是要记录oper
|
|
1198
|
+
_m.sent();
|
|
1199
|
+
return [2 /*return*/, 0];
|
|
1200
|
+
case 35: return [2 /*return*/, 0];
|
|
1201
|
+
case 36: return [4 /*yield*/, this.updateAbjointRowAsync(entity, operation, context, option)];
|
|
1202
|
+
case 37:
|
|
1203
|
+
result = _m.sent();
|
|
1204
|
+
return [4 /*yield*/, createOper()];
|
|
1205
|
+
case 38:
|
|
1206
|
+
_m.sent();
|
|
1207
|
+
return [2 /*return*/, result];
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
});
|
|
1211
|
+
};
|
|
1212
|
+
CascadeStore.prototype.doUpdateSingleRow = function (entity, operation, context, option) {
|
|
1213
|
+
var e_4, _a;
|
|
1214
|
+
var _this = this;
|
|
1215
|
+
var data = operation.data, action = operation.action, operId = operation.id, filter = operation.filter;
|
|
1216
|
+
var now = Date.now();
|
|
1217
|
+
switch (action) {
|
|
1218
|
+
case 'create': {
|
|
1219
|
+
this.preProcessDataCreated(entity, data);
|
|
1220
|
+
var result_2 = 0;
|
|
1221
|
+
var createInner = function (operation2) {
|
|
1222
|
+
try {
|
|
1223
|
+
result_2 += _this.updateAbjointRow(entity, operation2, context, option);
|
|
1224
|
+
}
|
|
1225
|
+
catch (e) {
|
|
1226
|
+
throw e;
|
|
1227
|
+
}
|
|
1228
|
+
};
|
|
1229
|
+
if (data instanceof Array) {
|
|
1230
|
+
var multipleCreate = this.supportMultipleCreate();
|
|
1231
|
+
if (multipleCreate) {
|
|
1232
|
+
createInner(operation);
|
|
1233
|
+
}
|
|
1234
|
+
else {
|
|
1235
|
+
try {
|
|
1236
|
+
for (var data_2 = tslib_1.__values(data), data_2_1 = data_2.next(); !data_2_1.done; data_2_1 = data_2.next()) {
|
|
1237
|
+
var d = data_2_1.value;
|
|
1238
|
+
var createSingleOper = {
|
|
1239
|
+
id: 'any',
|
|
1240
|
+
action: 'create',
|
|
1241
|
+
data: d,
|
|
1242
|
+
};
|
|
1243
|
+
createInner(createSingleOper);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1247
|
+
finally {
|
|
1248
|
+
try {
|
|
1249
|
+
if (data_2_1 && !data_2_1.done && (_a = data_2.return)) _a.call(data_2);
|
|
1250
|
+
}
|
|
1251
|
+
finally { if (e_4) throw e_4.error; }
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
else {
|
|
1256
|
+
createInner(operation);
|
|
1257
|
+
}
|
|
1258
|
+
return result_2;
|
|
1259
|
+
}
|
|
1260
|
+
default: {
|
|
1261
|
+
if (action === 'remove') {
|
|
1262
|
+
}
|
|
1263
|
+
else {
|
|
1264
|
+
var updateAttrCount = Object.keys(data).length;
|
|
1265
|
+
if (updateAttrCount > 0) {
|
|
1266
|
+
// 优化一下,如果不更新任何属性,则不实际执行
|
|
1267
|
+
Object.assign(data, {
|
|
1268
|
+
$$updateAt$$: now,
|
|
1269
|
+
});
|
|
1270
|
+
this.preProcessDataUpdated(data);
|
|
1271
|
+
}
|
|
1272
|
+
else {
|
|
1273
|
+
return 0;
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
return this.updateAbjointRow(entity, operation, context, option);
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
};
|
|
1280
|
+
CascadeStore.prototype.cascadeUpdate = function (entity, operation, context, option) {
|
|
1281
|
+
var e_5, _a, e_6, _b, e_7, _c;
|
|
1282
|
+
(0, selection_1.reinforceOperation)(this.getSchema(), entity, operation);
|
|
1283
|
+
var action = operation.action, data = operation.data, filter = operation.filter, id = operation.id;
|
|
1284
|
+
var opData;
|
|
1285
|
+
var wholeBeforeFns = [];
|
|
1286
|
+
var wholeAfterFns = [];
|
|
1287
|
+
var result = {};
|
|
1288
|
+
if (['create', 'create-l'].includes(action) && data instanceof Array) {
|
|
1289
|
+
opData = [];
|
|
1290
|
+
try {
|
|
1291
|
+
for (var data_3 = tslib_1.__values(data), data_3_1 = data_3.next(); !data_3_1.done; data_3_1 = data_3.next()) {
|
|
1292
|
+
var d = data_3_1.value;
|
|
1293
|
+
var _d = this.destructCascadeUpdate(entity, action, d, context, option, this.cascadeUpdate), od = _d.data, beforeFns = _d.beforeFns, afterFns = _d.afterFns;
|
|
1294
|
+
opData.push(od);
|
|
1295
|
+
wholeBeforeFns.push.apply(wholeBeforeFns, tslib_1.__spreadArray([], tslib_1.__read(beforeFns), false));
|
|
1296
|
+
wholeAfterFns.push.apply(wholeAfterFns, tslib_1.__spreadArray([], tslib_1.__read(afterFns), false));
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1300
|
+
finally {
|
|
1301
|
+
try {
|
|
1302
|
+
if (data_3_1 && !data_3_1.done && (_a = data_3.return)) _a.call(data_3);
|
|
1303
|
+
}
|
|
1304
|
+
finally { if (e_5) throw e_5.error; }
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
else {
|
|
1308
|
+
var _e = this.destructCascadeUpdate(entity, action, data, context, option, this.cascadeUpdate, filter), od = _e.data, beforeFns = _e.beforeFns, afterFns = _e.afterFns;
|
|
1309
|
+
opData = od;
|
|
1310
|
+
wholeBeforeFns.push.apply(wholeBeforeFns, tslib_1.__spreadArray([], tslib_1.__read(beforeFns), false));
|
|
1311
|
+
wholeAfterFns.push.apply(wholeAfterFns, tslib_1.__spreadArray([], tslib_1.__read(afterFns), false));
|
|
1312
|
+
}
|
|
1313
|
+
var operation2 = Object.assign({}, operation, {
|
|
1314
|
+
data: opData,
|
|
1315
|
+
});
|
|
1316
|
+
try {
|
|
1317
|
+
for (var wholeBeforeFns_1 = tslib_1.__values(wholeBeforeFns), wholeBeforeFns_1_1 = wholeBeforeFns_1.next(); !wholeBeforeFns_1_1.done; wholeBeforeFns_1_1 = wholeBeforeFns_1.next()) {
|
|
1318
|
+
var before_1 = wholeBeforeFns_1_1.value;
|
|
1319
|
+
before_1();
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1323
|
+
finally {
|
|
1324
|
+
try {
|
|
1325
|
+
if (wholeBeforeFns_1_1 && !wholeBeforeFns_1_1.done && (_b = wholeBeforeFns_1.return)) _b.call(wholeBeforeFns_1);
|
|
1326
|
+
}
|
|
1327
|
+
finally { if (e_6) throw e_6.error; }
|
|
1328
|
+
}
|
|
1329
|
+
var count = this.doUpdateSingleRow(entity, operation2, context, option);
|
|
1330
|
+
try {
|
|
1331
|
+
for (var wholeAfterFns_1 = tslib_1.__values(wholeAfterFns), wholeAfterFns_1_1 = wholeAfterFns_1.next(); !wholeAfterFns_1_1.done; wholeAfterFns_1_1 = wholeAfterFns_1.next()) {
|
|
1332
|
+
var after_1 = wholeAfterFns_1_1.value;
|
|
1333
|
+
after_1();
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
1337
|
+
finally {
|
|
1338
|
+
try {
|
|
1339
|
+
if (wholeAfterFns_1_1 && !wholeAfterFns_1_1.done && (_c = wholeAfterFns_1.return)) _c.call(wholeAfterFns_1);
|
|
1340
|
+
}
|
|
1341
|
+
finally { if (e_7) throw e_7.error; }
|
|
1342
|
+
}
|
|
1343
|
+
return result;
|
|
1344
|
+
};
|
|
1345
|
+
/**
|
|
1346
|
+
*
|
|
1347
|
+
* @param entity
|
|
1348
|
+
* @param operation
|
|
1349
|
+
* @param context
|
|
1350
|
+
* @param option
|
|
1351
|
+
*/
|
|
1352
|
+
CascadeStore.prototype.cascadeUpdateAsync = function (entity, operation, context, option) {
|
|
1353
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1354
|
+
var action, data, filter, id, opData, wholeBeforeFns, wholeAfterFns, result, data_4, data_4_1, d, _a, od, beforeFns, afterFns, _b, od, beforeFns, afterFns, operation2, wholeBeforeFns_2, wholeBeforeFns_2_1, before_2, e_8_1, count, wholeAfterFns_2, wholeAfterFns_2_1, after_2, e_9_1;
|
|
1355
|
+
var e_10, _c, e_8, _d, _e, _f, e_9, _g;
|
|
1356
|
+
return tslib_1.__generator(this, function (_h) {
|
|
1357
|
+
switch (_h.label) {
|
|
1358
|
+
case 0:
|
|
1359
|
+
(0, selection_1.reinforceOperation)(this.getSchema(), entity, operation);
|
|
1360
|
+
action = operation.action, data = operation.data, filter = operation.filter, id = operation.id;
|
|
1361
|
+
wholeBeforeFns = [];
|
|
1362
|
+
wholeAfterFns = [];
|
|
1363
|
+
result = {};
|
|
1364
|
+
if (['create', 'create-l'].includes(action) && data instanceof Array) {
|
|
1365
|
+
opData = [];
|
|
1366
|
+
try {
|
|
1367
|
+
for (data_4 = tslib_1.__values(data), data_4_1 = data_4.next(); !data_4_1.done; data_4_1 = data_4.next()) {
|
|
1368
|
+
d = data_4_1.value;
|
|
1369
|
+
_a = this.destructCascadeUpdate(entity, action, d, context, option, this.cascadeUpdateAsync), od = _a.data, beforeFns = _a.beforeFns, afterFns = _a.afterFns;
|
|
1370
|
+
opData.push(od);
|
|
1371
|
+
wholeBeforeFns.push.apply(wholeBeforeFns, tslib_1.__spreadArray([], tslib_1.__read(beforeFns), false));
|
|
1372
|
+
wholeAfterFns.push.apply(wholeAfterFns, tslib_1.__spreadArray([], tslib_1.__read(afterFns), false));
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
1376
|
+
finally {
|
|
1377
|
+
try {
|
|
1378
|
+
if (data_4_1 && !data_4_1.done && (_c = data_4.return)) _c.call(data_4);
|
|
1379
|
+
}
|
|
1380
|
+
finally { if (e_10) throw e_10.error; }
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
else {
|
|
1384
|
+
_b = this.destructCascadeUpdate(entity, action, data, context, option, this.cascadeUpdateAsync, filter), od = _b.data, beforeFns = _b.beforeFns, afterFns = _b.afterFns;
|
|
1385
|
+
opData = od;
|
|
1386
|
+
wholeBeforeFns.push.apply(wholeBeforeFns, tslib_1.__spreadArray([], tslib_1.__read(beforeFns), false));
|
|
1387
|
+
wholeAfterFns.push.apply(wholeAfterFns, tslib_1.__spreadArray([], tslib_1.__read(afterFns), false));
|
|
1388
|
+
}
|
|
1389
|
+
operation2 = Object.assign({}, operation, {
|
|
1390
|
+
data: opData,
|
|
1391
|
+
});
|
|
1392
|
+
_h.label = 1;
|
|
1393
|
+
case 1:
|
|
1394
|
+
_h.trys.push([1, 6, 7, 8]);
|
|
1395
|
+
wholeBeforeFns_2 = tslib_1.__values(wholeBeforeFns), wholeBeforeFns_2_1 = wholeBeforeFns_2.next();
|
|
1396
|
+
_h.label = 2;
|
|
1397
|
+
case 2:
|
|
1398
|
+
if (!!wholeBeforeFns_2_1.done) return [3 /*break*/, 5];
|
|
1399
|
+
before_2 = wholeBeforeFns_2_1.value;
|
|
1400
|
+
return [4 /*yield*/, before_2()];
|
|
1401
|
+
case 3:
|
|
1402
|
+
_h.sent();
|
|
1403
|
+
_h.label = 4;
|
|
1404
|
+
case 4:
|
|
1405
|
+
wholeBeforeFns_2_1 = wholeBeforeFns_2.next();
|
|
1406
|
+
return [3 /*break*/, 2];
|
|
1407
|
+
case 5: return [3 /*break*/, 8];
|
|
1408
|
+
case 6:
|
|
1409
|
+
e_8_1 = _h.sent();
|
|
1410
|
+
e_8 = { error: e_8_1 };
|
|
1411
|
+
return [3 /*break*/, 8];
|
|
1412
|
+
case 7:
|
|
1413
|
+
try {
|
|
1414
|
+
if (wholeBeforeFns_2_1 && !wholeBeforeFns_2_1.done && (_d = wholeBeforeFns_2.return)) _d.call(wholeBeforeFns_2);
|
|
1415
|
+
}
|
|
1416
|
+
finally { if (e_8) throw e_8.error; }
|
|
1417
|
+
return [7 /*endfinally*/];
|
|
1418
|
+
case 8: return [4 /*yield*/, this.doUpdateSingleRowAsync(entity, operation2, context, option)];
|
|
1419
|
+
case 9:
|
|
1420
|
+
count = _h.sent();
|
|
1421
|
+
this.mergeOperationResult(result, (_e = {},
|
|
1422
|
+
_e[entity] = (_f = {},
|
|
1423
|
+
_f[operation2.action] = count,
|
|
1424
|
+
_f),
|
|
1425
|
+
_e));
|
|
1426
|
+
_h.label = 10;
|
|
1427
|
+
case 10:
|
|
1428
|
+
_h.trys.push([10, 15, 16, 17]);
|
|
1429
|
+
wholeAfterFns_2 = tslib_1.__values(wholeAfterFns), wholeAfterFns_2_1 = wholeAfterFns_2.next();
|
|
1430
|
+
_h.label = 11;
|
|
1431
|
+
case 11:
|
|
1432
|
+
if (!!wholeAfterFns_2_1.done) return [3 /*break*/, 14];
|
|
1433
|
+
after_2 = wholeAfterFns_2_1.value;
|
|
1434
|
+
return [4 /*yield*/, after_2()];
|
|
1435
|
+
case 12:
|
|
1436
|
+
_h.sent();
|
|
1437
|
+
_h.label = 13;
|
|
1438
|
+
case 13:
|
|
1439
|
+
wholeAfterFns_2_1 = wholeAfterFns_2.next();
|
|
1440
|
+
return [3 /*break*/, 11];
|
|
1441
|
+
case 14: return [3 /*break*/, 17];
|
|
1442
|
+
case 15:
|
|
1443
|
+
e_9_1 = _h.sent();
|
|
1444
|
+
e_9 = { error: e_9_1 };
|
|
1445
|
+
return [3 /*break*/, 17];
|
|
1446
|
+
case 16:
|
|
1447
|
+
try {
|
|
1448
|
+
if (wholeAfterFns_2_1 && !wholeAfterFns_2_1.done && (_g = wholeAfterFns_2.return)) _g.call(wholeAfterFns_2);
|
|
1449
|
+
}
|
|
1450
|
+
finally { if (e_9) throw e_9.error; }
|
|
1451
|
+
return [7 /*endfinally*/];
|
|
1452
|
+
case 17: return [2 /*return*/, result];
|
|
1453
|
+
}
|
|
1454
|
+
});
|
|
1455
|
+
});
|
|
1456
|
+
};
|
|
1457
|
+
CascadeStore.prototype.cascadeSelect = function (entity, selection, context, option) {
|
|
1458
|
+
(0, selection_1.reinforceSelection)(this.getSchema(), entity, selection);
|
|
1459
|
+
var data = selection.data, filter = selection.filter, indexFrom = selection.indexFrom, count = selection.count, sorter = selection.sorter;
|
|
1460
|
+
var _a = this.destructCascadeSelect(entity, data, context, this.cascadeSelect, this.aggregateSync, option), projection = _a.projection, cascadeSelectionFns = _a.cascadeSelectionFns;
|
|
1461
|
+
var rows = this.selectAbjointRow(entity, {
|
|
1462
|
+
data: projection,
|
|
1463
|
+
filter: filter,
|
|
1464
|
+
indexFrom: indexFrom,
|
|
1465
|
+
count: count,
|
|
1466
|
+
sorter: sorter
|
|
1467
|
+
}, context, option);
|
|
1468
|
+
if (cascadeSelectionFns.length > 0) {
|
|
1469
|
+
var ruException_1 = [];
|
|
1470
|
+
cascadeSelectionFns.forEach(function (ele) {
|
|
1471
|
+
try {
|
|
1472
|
+
ele(rows);
|
|
1473
|
+
}
|
|
1474
|
+
catch (e) {
|
|
1475
|
+
if (e instanceof types_1.OakRowUnexistedException) {
|
|
1476
|
+
var rows_1 = e.getRows();
|
|
1477
|
+
ruException_1.push.apply(ruException_1, tslib_1.__spreadArray([], tslib_1.__read(rows_1), false));
|
|
1478
|
+
}
|
|
1479
|
+
else {
|
|
1480
|
+
throw e;
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
});
|
|
1484
|
+
if (ruException_1.length > 0) {
|
|
1485
|
+
throw new types_1.OakRowUnexistedException(ruException_1);
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
return rows;
|
|
1489
|
+
};
|
|
1490
|
+
/**
|
|
1491
|
+
* 将一次查询的结果集加入result
|
|
1492
|
+
* todo 如果是supportMtoOJoin,这里还要解构(未充分测试)
|
|
1493
|
+
* @param entity
|
|
1494
|
+
* @param rows
|
|
1495
|
+
* @param context
|
|
1496
|
+
*/
|
|
1497
|
+
CascadeStore.prototype.addToResultSelections = function (entity, rows, context) {
|
|
1498
|
+
if (this.supportManyToOneJoin()) {
|
|
1499
|
+
var attrsToPick_1 = [];
|
|
1500
|
+
var _loop_3 = function (attr) {
|
|
1501
|
+
var data = {};
|
|
1502
|
+
var rel = this_3.judgeRelation(entity, attr);
|
|
1503
|
+
if (rel === 2) {
|
|
1504
|
+
this_3.addToResultSelections(attr, rows.map(function (ele) { return ele[attr]; }).filter(function (ele) { return !!ele; }), context);
|
|
1505
|
+
}
|
|
1506
|
+
else if (typeof rel === 'string') {
|
|
1507
|
+
this_3.addToResultSelections(rel, rows.map(function (ele) { return ele[attr]; }).filter(function (ele) { return !!ele; }), context);
|
|
1508
|
+
}
|
|
1509
|
+
else if (rel instanceof Array) {
|
|
1510
|
+
this_3.addToResultSelections(rel[0], rows.map(function (ele) { return ele[attr]; }).reduce(function (prev, current) { return prev.concat(current); }, []), context);
|
|
1511
|
+
}
|
|
1512
|
+
else {
|
|
1513
|
+
attrsToPick_1.push(attr);
|
|
1514
|
+
}
|
|
1515
|
+
};
|
|
1516
|
+
var this_3 = this;
|
|
1517
|
+
for (var attr in rows[0]) {
|
|
1518
|
+
_loop_3(attr);
|
|
1519
|
+
}
|
|
1520
|
+
var originRows = rows.map(function (ele) { return (0, lodash_1.pick)(ele, attrsToPick_1); });
|
|
1521
|
+
this.addSingleRowToResultSelections(entity, originRows, context);
|
|
1522
|
+
}
|
|
1523
|
+
else {
|
|
1524
|
+
this.addSingleRowToResultSelections(entity, rows, context);
|
|
1525
|
+
}
|
|
1526
|
+
};
|
|
1527
|
+
CascadeStore.prototype.addSingleRowToResultSelections = function (entity, rows, context) {
|
|
1528
|
+
var _a;
|
|
1529
|
+
var opRecords = context.opRecords;
|
|
1530
|
+
var lastOperation = opRecords[opRecords.length - 1];
|
|
1531
|
+
if (lastOperation && lastOperation.a === 's') {
|
|
1532
|
+
var entityBranch_1 = lastOperation.d[entity];
|
|
1533
|
+
if (entityBranch_1) {
|
|
1534
|
+
rows.forEach(function (row) {
|
|
1535
|
+
var _a;
|
|
1536
|
+
if (row) {
|
|
1537
|
+
(0, assert_1.default)(row.id);
|
|
1538
|
+
var id = row.id;
|
|
1539
|
+
if (!entityBranch_1[id]) {
|
|
1540
|
+
Object.assign(entityBranch_1, (_a = {},
|
|
1541
|
+
_a[id] = row,
|
|
1542
|
+
_a));
|
|
1543
|
+
}
|
|
1544
|
+
else {
|
|
1545
|
+
Object.assign(entityBranch_1[id], row);
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
});
|
|
1549
|
+
return;
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
else {
|
|
1553
|
+
lastOperation = {
|
|
1554
|
+
a: 's',
|
|
1555
|
+
d: {},
|
|
1556
|
+
};
|
|
1557
|
+
opRecords.push(lastOperation);
|
|
1558
|
+
}
|
|
1559
|
+
var entityBranch = {};
|
|
1560
|
+
rows.forEach(function (row) {
|
|
1561
|
+
var _a;
|
|
1562
|
+
if (row) {
|
|
1563
|
+
var id = row.id;
|
|
1564
|
+
Object.assign(entityBranch, (_a = {},
|
|
1565
|
+
_a[id] = row,
|
|
1566
|
+
_a));
|
|
1567
|
+
}
|
|
1568
|
+
});
|
|
1569
|
+
Object.assign(lastOperation.d, (_a = {},
|
|
1570
|
+
_a[entity] = entityBranch,
|
|
1571
|
+
_a));
|
|
1572
|
+
};
|
|
1573
|
+
CascadeStore.prototype.cascadeSelectAsync = function (entity, selection, context, option) {
|
|
1574
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1575
|
+
var data, filter, indexFrom, count, sorter, _a, projection, cascadeSelectionFns, rows, ruException_2;
|
|
1576
|
+
var _this = this;
|
|
1577
|
+
return tslib_1.__generator(this, function (_b) {
|
|
1578
|
+
switch (_b.label) {
|
|
1579
|
+
case 0:
|
|
1580
|
+
(0, selection_1.reinforceSelection)(this.getSchema(), entity, selection);
|
|
1581
|
+
data = selection.data, filter = selection.filter, indexFrom = selection.indexFrom, count = selection.count, sorter = selection.sorter;
|
|
1582
|
+
_a = this.destructCascadeSelect(entity, data, context, this.cascadeSelectAsync, this.aggregateAsync, option), projection = _a.projection, cascadeSelectionFns = _a.cascadeSelectionFns;
|
|
1583
|
+
return [4 /*yield*/, this.selectAbjointRowAsync(entity, {
|
|
1584
|
+
data: projection,
|
|
1585
|
+
filter: filter,
|
|
1586
|
+
indexFrom: indexFrom,
|
|
1587
|
+
count: count,
|
|
1588
|
+
sorter: sorter
|
|
1589
|
+
}, context, option)];
|
|
1590
|
+
case 1:
|
|
1591
|
+
rows = _b.sent();
|
|
1592
|
+
if (!option.dontCollect) {
|
|
1593
|
+
this.addToResultSelections(entity, rows, context);
|
|
1594
|
+
}
|
|
1595
|
+
if (!(cascadeSelectionFns.length > 0)) return [3 /*break*/, 3];
|
|
1596
|
+
ruException_2 = [];
|
|
1597
|
+
return [4 /*yield*/, Promise.all(cascadeSelectionFns.map(function (ele) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1598
|
+
var e_11, rows_2;
|
|
1599
|
+
return tslib_1.__generator(this, function (_a) {
|
|
1600
|
+
switch (_a.label) {
|
|
1601
|
+
case 0:
|
|
1602
|
+
_a.trys.push([0, 2, , 3]);
|
|
1603
|
+
return [4 /*yield*/, ele(rows)];
|
|
1604
|
+
case 1:
|
|
1605
|
+
_a.sent();
|
|
1606
|
+
return [3 /*break*/, 3];
|
|
1607
|
+
case 2:
|
|
1608
|
+
e_11 = _a.sent();
|
|
1609
|
+
if (e_11 instanceof types_1.OakRowUnexistedException) {
|
|
1610
|
+
rows_2 = e_11.getRows();
|
|
1611
|
+
ruException_2.push.apply(ruException_2, tslib_1.__spreadArray([], tslib_1.__read(rows_2), false));
|
|
1612
|
+
}
|
|
1613
|
+
else {
|
|
1614
|
+
throw e_11;
|
|
1615
|
+
}
|
|
1616
|
+
return [3 /*break*/, 3];
|
|
1617
|
+
case 3: return [2 /*return*/];
|
|
1618
|
+
}
|
|
1619
|
+
});
|
|
1620
|
+
}); }))];
|
|
1621
|
+
case 2:
|
|
1622
|
+
_b.sent();
|
|
1623
|
+
if (ruException_2.length > 0) {
|
|
1624
|
+
throw new types_1.OakRowUnexistedException(ruException_2);
|
|
1625
|
+
}
|
|
1626
|
+
_b.label = 3;
|
|
1627
|
+
case 3: return [2 /*return*/, rows];
|
|
1628
|
+
}
|
|
1629
|
+
});
|
|
1630
|
+
});
|
|
1631
|
+
};
|
|
1632
|
+
return CascadeStore;
|
|
1633
|
+
}(RowStore_1.RowStore));
|
|
1634
|
+
exports.CascadeStore = CascadeStore;
|