remult 0.17.0-exp.4 → 0.17.0-exp.6
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/esm/src/context.d.ts +1 -0
- package/esm/src/context.js +56 -0
- package/esm/src/data-api.js +8 -1
- package/esm/src/live-query/LiveQueryPublisher.js +2 -2
- package/esm/src/live-query/LiveQuerySubscriber.d.ts +1 -0
- package/esm/src/live-query/LiveQuerySubscriber.js +11 -7
- package/esm/src/server-action.js +1 -57
- package/package.json +1 -1
- package/src/context.d.ts +1 -0
- package/src/context.js +105 -1
- package/src/data-api.js +47 -11
- package/src/live-query/LiveQueryPublisher.js +2 -2
- package/src/live-query/LiveQuerySubscriber.d.ts +1 -0
- package/src/live-query/LiveQuerySubscriber.js +11 -7
- package/src/server-action.js +14 -117
package/esm/src/context.d.ts
CHANGED
package/esm/src/context.js
CHANGED
|
@@ -286,3 +286,59 @@ export class EventSource {
|
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
|
+
export async function doTransaction(remult, what) {
|
|
290
|
+
return await remult.dataProvider.transaction(async (ds) => {
|
|
291
|
+
remult.dataProvider = (ds);
|
|
292
|
+
const trans = new transactionLiveQueryPublisher(remult.liveQueryPublisher);
|
|
293
|
+
remult.liveQueryPublisher = trans;
|
|
294
|
+
await what();
|
|
295
|
+
trans.flush();
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
class transactionLiveQueryPublisher {
|
|
299
|
+
constructor(orig) {
|
|
300
|
+
this.orig = orig;
|
|
301
|
+
this.transactionItems = new Map();
|
|
302
|
+
}
|
|
303
|
+
stopLiveQuery(id) {
|
|
304
|
+
this.orig.stopLiveQuery(id);
|
|
305
|
+
}
|
|
306
|
+
itemChanged(entityKey, changes) {
|
|
307
|
+
let items = this.transactionItems.get(entityKey);
|
|
308
|
+
if (!items) {
|
|
309
|
+
this.transactionItems.set(entityKey, items = []);
|
|
310
|
+
}
|
|
311
|
+
for (const c of changes) {
|
|
312
|
+
if (c.oldId !== undefined) {
|
|
313
|
+
const item = items.find(y => y.id === c.oldId);
|
|
314
|
+
if (item !== undefined) {
|
|
315
|
+
if (c.deleted)
|
|
316
|
+
item.deleted = true;
|
|
317
|
+
if (c.id != item.id)
|
|
318
|
+
item.id = c.id;
|
|
319
|
+
}
|
|
320
|
+
else
|
|
321
|
+
items.push(c);
|
|
322
|
+
}
|
|
323
|
+
else
|
|
324
|
+
items.push(c);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
flush() {
|
|
328
|
+
for (const key of this.transactionItems.keys()) {
|
|
329
|
+
this.orig.itemChanged(key, this.transactionItems.get(key));
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
sendChannelMessage(channel, message) {
|
|
333
|
+
this.orig.sendChannelMessage(channel, message);
|
|
334
|
+
}
|
|
335
|
+
defineLiveQueryChannel(repo, options, remult, ids) {
|
|
336
|
+
return this.orig.defineLiveQueryChannel(repo, options, remult, ids);
|
|
337
|
+
}
|
|
338
|
+
get dispatcher() {
|
|
339
|
+
return this.orig.dispatcher;
|
|
340
|
+
}
|
|
341
|
+
set dispatcher(value) {
|
|
342
|
+
this.orig.dispatcher = value;
|
|
343
|
+
}
|
|
344
|
+
}
|
package/esm/src/data-api.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { customUrlToken, buildFilterFromRequestParameters } from './filter/filter-interfaces';
|
|
2
|
+
import { doTransaction } from './context';
|
|
2
3
|
import { Filter } from './filter/filter-interfaces';
|
|
3
4
|
import { ForbiddenError } from './server-action';
|
|
4
5
|
export class DataApi {
|
|
@@ -189,7 +190,13 @@ export class DataApi {
|
|
|
189
190
|
return this.repository.getEntityRef(newr).toApiJson();
|
|
190
191
|
};
|
|
191
192
|
if (Array.isArray(body)) {
|
|
192
|
-
|
|
193
|
+
const result = [];
|
|
194
|
+
await doTransaction(this.remult, async () => {
|
|
195
|
+
for (const item of body) {
|
|
196
|
+
result.push(await insert(item));
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
response.created(result);
|
|
193
200
|
}
|
|
194
201
|
else
|
|
195
202
|
response.created(await insert(body));
|
|
@@ -24,7 +24,7 @@ export class LiveQueryPublisher {
|
|
|
24
24
|
}
|
|
25
25
|
itemChanged(entityKey, changes) {
|
|
26
26
|
for (const q of this.queries) {
|
|
27
|
-
//
|
|
27
|
+
// possible optimization delete only messages that don't require running the query again
|
|
28
28
|
if (q.repo.metadata.key === entityKey) {
|
|
29
29
|
const messages = [];
|
|
30
30
|
this.runPromise(q.repo.find(q.findOptions).then(currentItems => {
|
|
@@ -34,7 +34,7 @@ export class LiveQueryPublisher {
|
|
|
34
34
|
};
|
|
35
35
|
for (const id of q.ids.filter(y => !currentIds.includes(y))) {
|
|
36
36
|
let c = changes.find(c => c.oldId == id);
|
|
37
|
-
if (id != c.oldId || !currentIds.includes(c.id))
|
|
37
|
+
if (c === undefined || id != c.oldId || !currentIds.includes(c.id))
|
|
38
38
|
sendMessage({
|
|
39
39
|
type: "remove",
|
|
40
40
|
data: {
|
|
@@ -17,6 +17,7 @@ export declare class LiveQueryClient {
|
|
|
17
17
|
runPromise(p: Promise<any>): Promise<any>;
|
|
18
18
|
close(): void;
|
|
19
19
|
subscribeChannel<T>(key: string, onResult: (item: T) => void): () => void;
|
|
20
|
+
timeoutToCloseWhenNotClosed: number;
|
|
20
21
|
private closeIfNoListeners;
|
|
21
22
|
subscribe<entityType>(repo: Repository<entityType>, options: FindOptions<entityType>, onResult: (reducer: (prevState: entityType[]) => entityType[]) => void): () => void;
|
|
22
23
|
client: Promise<PubSubClient>;
|
|
@@ -90,6 +90,7 @@ export class LiveQueryClient {
|
|
|
90
90
|
this.wrapMessageHandling = handleMessage => handleMessage();
|
|
91
91
|
this.queries = new Map();
|
|
92
92
|
this.channels = new Map();
|
|
93
|
+
this.timeoutToCloseWhenNotClosed = 1000;
|
|
93
94
|
}
|
|
94
95
|
runPromise(p) {
|
|
95
96
|
return p;
|
|
@@ -121,13 +122,16 @@ export class LiveQueryClient {
|
|
|
121
122
|
};
|
|
122
123
|
}
|
|
123
124
|
closeIfNoListeners() {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (this.
|
|
127
|
-
this.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
125
|
+
this.runPromise(new Promise((res) => {
|
|
126
|
+
setTimeout(() => {
|
|
127
|
+
if (this.client)
|
|
128
|
+
if (this.queries.size === 0 && this.channels.size === 0) {
|
|
129
|
+
this.runPromise(this.client.then(x => x.disconnect()));
|
|
130
|
+
this.client = undefined;
|
|
131
|
+
}
|
|
132
|
+
res({});
|
|
133
|
+
}, this.timeoutToCloseWhenNotClosed);
|
|
134
|
+
}));
|
|
131
135
|
}
|
|
132
136
|
//TODO - consider the time that may pass from the get request to the subscribe to the channel, in some cases this could mean, a call to server to get token and a call to the external provider - it may be some time
|
|
133
137
|
subscribe(repo, options, onResult) {
|
package/esm/src/server-action.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import { Remult, allEntities, classHelpers, ClassHelper, setControllerSettings, buildRestDataProvider } from './context';
|
|
2
|
+
import { Remult, allEntities, classHelpers, ClassHelper, setControllerSettings, buildRestDataProvider, doTransaction } from './context';
|
|
3
3
|
import { SqlDatabase } from './data-providers/sql-database';
|
|
4
4
|
import { getEntityRef, decorateColumnSettings, getEntitySettings, getControllerRef } from './remult3';
|
|
5
5
|
import { remult } from './remult-proxy';
|
|
@@ -66,62 +66,6 @@ export class ForbiddenError extends Error {
|
|
|
66
66
|
this.isForbiddenError = true;
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
async function doTransaction(remult, what) {
|
|
70
|
-
return await remult.dataProvider.transaction(async (ds) => {
|
|
71
|
-
remult.dataProvider = (ds);
|
|
72
|
-
const trans = new transactionLiveQueryPublisher(remult.liveQueryPublisher);
|
|
73
|
-
remult.liveQueryPublisher = trans;
|
|
74
|
-
await what();
|
|
75
|
-
trans.flush();
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
class transactionLiveQueryPublisher {
|
|
79
|
-
constructor(orig) {
|
|
80
|
-
this.orig = orig;
|
|
81
|
-
this.transactionItems = new Map();
|
|
82
|
-
}
|
|
83
|
-
stopLiveQuery(id) {
|
|
84
|
-
this.orig.stopLiveQuery(id);
|
|
85
|
-
}
|
|
86
|
-
itemChanged(entityKey, changes) {
|
|
87
|
-
let items = this.transactionItems.get(entityKey);
|
|
88
|
-
if (!items) {
|
|
89
|
-
this.transactionItems.set(entityKey, items = []);
|
|
90
|
-
}
|
|
91
|
-
for (const c of changes) {
|
|
92
|
-
if (c.oldId !== undefined) {
|
|
93
|
-
const item = items.find(y => y.id === c.oldId);
|
|
94
|
-
if (item !== undefined) {
|
|
95
|
-
if (c.deleted)
|
|
96
|
-
item.deleted = true;
|
|
97
|
-
if (c.id != item.id)
|
|
98
|
-
item.id = c.id;
|
|
99
|
-
}
|
|
100
|
-
else
|
|
101
|
-
items.push(c);
|
|
102
|
-
}
|
|
103
|
-
else
|
|
104
|
-
items.push(c);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
flush() {
|
|
108
|
-
for (const key of this.transactionItems.keys()) {
|
|
109
|
-
this.orig.itemChanged(key, this.transactionItems.get(key));
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
sendChannelMessage(channel, message) {
|
|
113
|
-
this.orig.sendChannelMessage(channel, message);
|
|
114
|
-
}
|
|
115
|
-
defineLiveQueryChannel(repo, options, remult, ids) {
|
|
116
|
-
return this.orig.defineLiveQueryChannel(repo, options, remult, ids);
|
|
117
|
-
}
|
|
118
|
-
get dispatcher() {
|
|
119
|
-
return this.orig.dispatcher;
|
|
120
|
-
}
|
|
121
|
-
set dispatcher(value) {
|
|
122
|
-
this.orig.dispatcher = value;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
69
|
export class myServerAction extends Action {
|
|
126
70
|
constructor(name, types, options, originalMethod) {
|
|
127
71
|
super(name, options.queue, options.allowed);
|
package/package.json
CHANGED
package/src/context.d.ts
CHANGED
package/src/context.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EventSource = exports.queryConfig = exports.Allow = exports.setControllerSettings = exports.buildRestDataProvider = exports.ClassHelper = exports.classHelpers = exports.allEntities = exports.Remult = exports.isBackend = exports.processHttpException = exports.toPromise = exports.retry = exports.HttpProviderBridgeToRestDataProviderHttpProvider = void 0;
|
|
3
|
+
exports.doTransaction = exports.EventSource = exports.queryConfig = exports.Allow = exports.setControllerSettings = exports.buildRestDataProvider = exports.ClassHelper = exports.classHelpers = exports.allEntities = exports.Remult = exports.isBackend = exports.processHttpException = exports.toPromise = exports.retry = exports.HttpProviderBridgeToRestDataProviderHttpProvider = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var server_action_1 = require("./server-action");
|
|
6
6
|
var rest_data_provider_1 = require("./data-providers/rest-data-provider");
|
|
@@ -418,3 +418,107 @@ var EventSource = /** @class */ (function () {
|
|
|
418
418
|
return EventSource;
|
|
419
419
|
}());
|
|
420
420
|
exports.EventSource = EventSource;
|
|
421
|
+
function doTransaction(remult, what) {
|
|
422
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
423
|
+
var _this = this;
|
|
424
|
+
return tslib_1.__generator(this, function (_a) {
|
|
425
|
+
switch (_a.label) {
|
|
426
|
+
case 0: return [4 /*yield*/, remult.dataProvider.transaction(function (ds) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
427
|
+
var trans;
|
|
428
|
+
return tslib_1.__generator(this, function (_a) {
|
|
429
|
+
switch (_a.label) {
|
|
430
|
+
case 0:
|
|
431
|
+
remult.dataProvider = (ds);
|
|
432
|
+
trans = new transactionLiveQueryPublisher(remult.liveQueryPublisher);
|
|
433
|
+
remult.liveQueryPublisher = trans;
|
|
434
|
+
return [4 /*yield*/, what()];
|
|
435
|
+
case 1:
|
|
436
|
+
_a.sent();
|
|
437
|
+
trans.flush();
|
|
438
|
+
return [2 /*return*/];
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
}); })];
|
|
442
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
exports.doTransaction = doTransaction;
|
|
448
|
+
var transactionLiveQueryPublisher = /** @class */ (function () {
|
|
449
|
+
function transactionLiveQueryPublisher(orig) {
|
|
450
|
+
this.orig = orig;
|
|
451
|
+
this.transactionItems = new Map();
|
|
452
|
+
}
|
|
453
|
+
transactionLiveQueryPublisher.prototype.stopLiveQuery = function (id) {
|
|
454
|
+
this.orig.stopLiveQuery(id);
|
|
455
|
+
};
|
|
456
|
+
transactionLiveQueryPublisher.prototype.itemChanged = function (entityKey, changes) {
|
|
457
|
+
var e_4, _a;
|
|
458
|
+
var items = this.transactionItems.get(entityKey);
|
|
459
|
+
if (!items) {
|
|
460
|
+
this.transactionItems.set(entityKey, items = []);
|
|
461
|
+
}
|
|
462
|
+
var _loop_1 = function (c) {
|
|
463
|
+
if (c.oldId !== undefined) {
|
|
464
|
+
var item = items.find(function (y) { return y.id === c.oldId; });
|
|
465
|
+
if (item !== undefined) {
|
|
466
|
+
if (c.deleted)
|
|
467
|
+
item.deleted = true;
|
|
468
|
+
if (c.id != item.id)
|
|
469
|
+
item.id = c.id;
|
|
470
|
+
}
|
|
471
|
+
else
|
|
472
|
+
items.push(c);
|
|
473
|
+
}
|
|
474
|
+
else
|
|
475
|
+
items.push(c);
|
|
476
|
+
};
|
|
477
|
+
try {
|
|
478
|
+
for (var changes_1 = tslib_1.__values(changes), changes_1_1 = changes_1.next(); !changes_1_1.done; changes_1_1 = changes_1.next()) {
|
|
479
|
+
var c = changes_1_1.value;
|
|
480
|
+
_loop_1(c);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
484
|
+
finally {
|
|
485
|
+
try {
|
|
486
|
+
if (changes_1_1 && !changes_1_1.done && (_a = changes_1.return)) _a.call(changes_1);
|
|
487
|
+
}
|
|
488
|
+
finally { if (e_4) throw e_4.error; }
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
transactionLiveQueryPublisher.prototype.flush = function () {
|
|
492
|
+
var e_5, _a;
|
|
493
|
+
try {
|
|
494
|
+
for (var _b = tslib_1.__values(this.transactionItems.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
495
|
+
var key = _c.value;
|
|
496
|
+
this.orig.itemChanged(key, this.transactionItems.get(key));
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
500
|
+
finally {
|
|
501
|
+
try {
|
|
502
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
503
|
+
}
|
|
504
|
+
finally { if (e_5) throw e_5.error; }
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
transactionLiveQueryPublisher.prototype.sendChannelMessage = function (channel, message) {
|
|
508
|
+
this.orig.sendChannelMessage(channel, message);
|
|
509
|
+
};
|
|
510
|
+
transactionLiveQueryPublisher.prototype.defineLiveQueryChannel = function (repo, options, remult, ids) {
|
|
511
|
+
return this.orig.defineLiveQueryChannel(repo, options, remult, ids);
|
|
512
|
+
};
|
|
513
|
+
Object.defineProperty(transactionLiveQueryPublisher.prototype, "dispatcher", {
|
|
514
|
+
get: function () {
|
|
515
|
+
return this.orig.dispatcher;
|
|
516
|
+
},
|
|
517
|
+
set: function (value) {
|
|
518
|
+
this.orig.dispatcher = value;
|
|
519
|
+
},
|
|
520
|
+
enumerable: false,
|
|
521
|
+
configurable: true
|
|
522
|
+
});
|
|
523
|
+
return transactionLiveQueryPublisher;
|
|
524
|
+
}());
|
package/src/data-api.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.serializeError = exports.determineSort = exports.DataApi = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var filter_interfaces_1 = require("./filter/filter-interfaces");
|
|
6
|
+
var context_1 = require("./context");
|
|
6
7
|
var filter_interfaces_2 = require("./filter/filter-interfaces");
|
|
7
8
|
var server_action_1 = require("./server-action");
|
|
8
9
|
var DataApi = /** @class */ (function () {
|
|
@@ -320,12 +321,12 @@ var DataApi = /** @class */ (function () {
|
|
|
320
321
|
};
|
|
321
322
|
DataApi.prototype.post = function (response, body) {
|
|
322
323
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
323
|
-
var insert_1, _a, _b,
|
|
324
|
+
var insert_1, result_1, _a, _b, err_4;
|
|
324
325
|
var _this = this;
|
|
325
|
-
return tslib_1.__generator(this, function (
|
|
326
|
-
switch (
|
|
326
|
+
return tslib_1.__generator(this, function (_c) {
|
|
327
|
+
switch (_c.label) {
|
|
327
328
|
case 0:
|
|
328
|
-
|
|
329
|
+
_c.trys.push([0, 5, , 6]);
|
|
329
330
|
insert_1 = function (what) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
330
331
|
var newr;
|
|
331
332
|
return tslib_1.__generator(this, function (_a) {
|
|
@@ -346,20 +347,55 @@ var DataApi = /** @class */ (function () {
|
|
|
346
347
|
});
|
|
347
348
|
}); };
|
|
348
349
|
if (!Array.isArray(body)) return [3 /*break*/, 2];
|
|
349
|
-
|
|
350
|
-
return [4 /*yield*/,
|
|
350
|
+
result_1 = [];
|
|
351
|
+
return [4 /*yield*/, context_1.doTransaction(this.remult, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
352
|
+
var body_1, body_1_1, item, _a, _b, e_1_1;
|
|
353
|
+
var e_1, _c;
|
|
354
|
+
return tslib_1.__generator(this, function (_d) {
|
|
355
|
+
switch (_d.label) {
|
|
356
|
+
case 0:
|
|
357
|
+
_d.trys.push([0, 5, 6, 7]);
|
|
358
|
+
body_1 = tslib_1.__values(body), body_1_1 = body_1.next();
|
|
359
|
+
_d.label = 1;
|
|
360
|
+
case 1:
|
|
361
|
+
if (!!body_1_1.done) return [3 /*break*/, 4];
|
|
362
|
+
item = body_1_1.value;
|
|
363
|
+
_b = (_a = result_1).push;
|
|
364
|
+
return [4 /*yield*/, insert_1(item)];
|
|
365
|
+
case 2:
|
|
366
|
+
_b.apply(_a, [_d.sent()]);
|
|
367
|
+
_d.label = 3;
|
|
368
|
+
case 3:
|
|
369
|
+
body_1_1 = body_1.next();
|
|
370
|
+
return [3 /*break*/, 1];
|
|
371
|
+
case 4: return [3 /*break*/, 7];
|
|
372
|
+
case 5:
|
|
373
|
+
e_1_1 = _d.sent();
|
|
374
|
+
e_1 = { error: e_1_1 };
|
|
375
|
+
return [3 /*break*/, 7];
|
|
376
|
+
case 6:
|
|
377
|
+
try {
|
|
378
|
+
if (body_1_1 && !body_1_1.done && (_c = body_1.return)) _c.call(body_1);
|
|
379
|
+
}
|
|
380
|
+
finally { if (e_1) throw e_1.error; }
|
|
381
|
+
return [7 /*endfinally*/];
|
|
382
|
+
case 7: return [2 /*return*/];
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
}); })];
|
|
351
386
|
case 1:
|
|
352
|
-
|
|
387
|
+
_c.sent();
|
|
388
|
+
response.created(result_1);
|
|
353
389
|
return [3 /*break*/, 4];
|
|
354
390
|
case 2:
|
|
355
|
-
|
|
391
|
+
_b = (_a = response).created;
|
|
356
392
|
return [4 /*yield*/, insert_1(body)];
|
|
357
393
|
case 3:
|
|
358
|
-
|
|
359
|
-
|
|
394
|
+
_b.apply(_a, [_c.sent()]);
|
|
395
|
+
_c.label = 4;
|
|
360
396
|
case 4: return [3 /*break*/, 6];
|
|
361
397
|
case 5:
|
|
362
|
-
err_4 =
|
|
398
|
+
err_4 = _c.sent();
|
|
363
399
|
if (err_4.isForbiddenError)
|
|
364
400
|
response.forbidden();
|
|
365
401
|
else
|
|
@@ -31,7 +31,7 @@ var LiveQueryPublisher = /** @class */ (function () {
|
|
|
31
31
|
var e_1, _a;
|
|
32
32
|
var _this = this;
|
|
33
33
|
var _loop_1 = function (q) {
|
|
34
|
-
//
|
|
34
|
+
// possible optimization delete only messages that don't require running the query again
|
|
35
35
|
if (q.repo.metadata.key === entityKey) {
|
|
36
36
|
var messages_1 = [];
|
|
37
37
|
this_1.runPromise(q.repo.find(q.findOptions).then(function (currentItems) {
|
|
@@ -42,7 +42,7 @@ var LiveQueryPublisher = /** @class */ (function () {
|
|
|
42
42
|
};
|
|
43
43
|
var _loop_2 = function (id) {
|
|
44
44
|
var c = changes.find(function (c) { return c.oldId == id; });
|
|
45
|
-
if (id != c.oldId || !currentIds.includes(c.id))
|
|
45
|
+
if (c === undefined || id != c.oldId || !currentIds.includes(c.id))
|
|
46
46
|
sendMessage({
|
|
47
47
|
type: "remove",
|
|
48
48
|
data: {
|
|
@@ -17,6 +17,7 @@ export declare class LiveQueryClient {
|
|
|
17
17
|
runPromise(p: Promise<any>): Promise<any>;
|
|
18
18
|
close(): void;
|
|
19
19
|
subscribeChannel<T>(key: string, onResult: (item: T) => void): () => void;
|
|
20
|
+
timeoutToCloseWhenNotClosed: number;
|
|
20
21
|
private closeIfNoListeners;
|
|
21
22
|
subscribe<entityType>(repo: Repository<entityType>, options: FindOptions<entityType>, onResult: (reducer: (prevState: entityType[]) => entityType[]) => void): () => void;
|
|
22
23
|
client: Promise<PubSubClient>;
|
|
@@ -187,6 +187,7 @@ var LiveQueryClient = /** @class */ (function () {
|
|
|
187
187
|
this.wrapMessageHandling = function (handleMessage) { return handleMessage(); };
|
|
188
188
|
this.queries = new Map();
|
|
189
189
|
this.channels = new Map();
|
|
190
|
+
this.timeoutToCloseWhenNotClosed = 1000;
|
|
190
191
|
}
|
|
191
192
|
LiveQueryClient.prototype.runPromise = function (p) {
|
|
192
193
|
return p;
|
|
@@ -222,13 +223,16 @@ var LiveQueryClient = /** @class */ (function () {
|
|
|
222
223
|
};
|
|
223
224
|
LiveQueryClient.prototype.closeIfNoListeners = function () {
|
|
224
225
|
var _this = this;
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
if (_this.
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
226
|
+
this.runPromise(new Promise(function (res) {
|
|
227
|
+
setTimeout(function () {
|
|
228
|
+
if (_this.client)
|
|
229
|
+
if (_this.queries.size === 0 && _this.channels.size === 0) {
|
|
230
|
+
_this.runPromise(_this.client.then(function (x) { return x.disconnect(); }));
|
|
231
|
+
_this.client = undefined;
|
|
232
|
+
}
|
|
233
|
+
res({});
|
|
234
|
+
}, _this.timeoutToCloseWhenNotClosed);
|
|
235
|
+
}));
|
|
232
236
|
};
|
|
233
237
|
//TODO - consider the time that may pass from the get request to the subscribe to the channel, in some cases this could mean, a call to server to get token and a call to the external provider - it may be some time
|
|
234
238
|
LiveQueryClient.prototype.subscribe = function (repo, options, onResult) {
|
package/src/server-action.js
CHANGED
|
@@ -111,109 +111,6 @@ var ForbiddenError = /** @class */ (function (_super) {
|
|
|
111
111
|
return ForbiddenError;
|
|
112
112
|
}(Error));
|
|
113
113
|
exports.ForbiddenError = ForbiddenError;
|
|
114
|
-
function doTransaction(remult, what) {
|
|
115
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
116
|
-
var _this = this;
|
|
117
|
-
return tslib_1.__generator(this, function (_a) {
|
|
118
|
-
switch (_a.label) {
|
|
119
|
-
case 0: return [4 /*yield*/, remult.dataProvider.transaction(function (ds) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
120
|
-
var trans;
|
|
121
|
-
return tslib_1.__generator(this, function (_a) {
|
|
122
|
-
switch (_a.label) {
|
|
123
|
-
case 0:
|
|
124
|
-
remult.dataProvider = (ds);
|
|
125
|
-
trans = new transactionLiveQueryPublisher(remult.liveQueryPublisher);
|
|
126
|
-
remult.liveQueryPublisher = trans;
|
|
127
|
-
return [4 /*yield*/, what()];
|
|
128
|
-
case 1:
|
|
129
|
-
_a.sent();
|
|
130
|
-
trans.flush();
|
|
131
|
-
return [2 /*return*/];
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
}); })];
|
|
135
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
var transactionLiveQueryPublisher = /** @class */ (function () {
|
|
141
|
-
function transactionLiveQueryPublisher(orig) {
|
|
142
|
-
this.orig = orig;
|
|
143
|
-
this.transactionItems = new Map();
|
|
144
|
-
}
|
|
145
|
-
transactionLiveQueryPublisher.prototype.stopLiveQuery = function (id) {
|
|
146
|
-
this.orig.stopLiveQuery(id);
|
|
147
|
-
};
|
|
148
|
-
transactionLiveQueryPublisher.prototype.itemChanged = function (entityKey, changes) {
|
|
149
|
-
var e_1, _a;
|
|
150
|
-
var items = this.transactionItems.get(entityKey);
|
|
151
|
-
if (!items) {
|
|
152
|
-
this.transactionItems.set(entityKey, items = []);
|
|
153
|
-
}
|
|
154
|
-
var _loop_1 = function (c) {
|
|
155
|
-
if (c.oldId !== undefined) {
|
|
156
|
-
var item = items.find(function (y) { return y.id === c.oldId; });
|
|
157
|
-
if (item !== undefined) {
|
|
158
|
-
if (c.deleted)
|
|
159
|
-
item.deleted = true;
|
|
160
|
-
if (c.id != item.id)
|
|
161
|
-
item.id = c.id;
|
|
162
|
-
}
|
|
163
|
-
else
|
|
164
|
-
items.push(c);
|
|
165
|
-
}
|
|
166
|
-
else
|
|
167
|
-
items.push(c);
|
|
168
|
-
};
|
|
169
|
-
try {
|
|
170
|
-
for (var changes_1 = tslib_1.__values(changes), changes_1_1 = changes_1.next(); !changes_1_1.done; changes_1_1 = changes_1.next()) {
|
|
171
|
-
var c = changes_1_1.value;
|
|
172
|
-
_loop_1(c);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
176
|
-
finally {
|
|
177
|
-
try {
|
|
178
|
-
if (changes_1_1 && !changes_1_1.done && (_a = changes_1.return)) _a.call(changes_1);
|
|
179
|
-
}
|
|
180
|
-
finally { if (e_1) throw e_1.error; }
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
transactionLiveQueryPublisher.prototype.flush = function () {
|
|
184
|
-
var e_2, _a;
|
|
185
|
-
try {
|
|
186
|
-
for (var _b = tslib_1.__values(this.transactionItems.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
187
|
-
var key = _c.value;
|
|
188
|
-
this.orig.itemChanged(key, this.transactionItems.get(key));
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
192
|
-
finally {
|
|
193
|
-
try {
|
|
194
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
195
|
-
}
|
|
196
|
-
finally { if (e_2) throw e_2.error; }
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
transactionLiveQueryPublisher.prototype.sendChannelMessage = function (channel, message) {
|
|
200
|
-
this.orig.sendChannelMessage(channel, message);
|
|
201
|
-
};
|
|
202
|
-
transactionLiveQueryPublisher.prototype.defineLiveQueryChannel = function (repo, options, remult, ids) {
|
|
203
|
-
return this.orig.defineLiveQueryChannel(repo, options, remult, ids);
|
|
204
|
-
};
|
|
205
|
-
Object.defineProperty(transactionLiveQueryPublisher.prototype, "dispatcher", {
|
|
206
|
-
get: function () {
|
|
207
|
-
return this.orig.dispatcher;
|
|
208
|
-
},
|
|
209
|
-
set: function (value) {
|
|
210
|
-
this.orig.dispatcher = value;
|
|
211
|
-
},
|
|
212
|
-
enumerable: false,
|
|
213
|
-
configurable: true
|
|
214
|
-
});
|
|
215
|
-
return transactionLiveQueryPublisher;
|
|
216
|
-
}());
|
|
217
114
|
var myServerAction = /** @class */ (function (_super) {
|
|
218
115
|
tslib_1.__extends(myServerAction, _super);
|
|
219
116
|
function myServerAction(name, types, options, originalMethod) {
|
|
@@ -232,7 +129,7 @@ var myServerAction = /** @class */ (function (_super) {
|
|
|
232
129
|
case 0:
|
|
233
130
|
result = { data: {} };
|
|
234
131
|
ds = remult.dataProvider;
|
|
235
|
-
return [4 /*yield*/, doTransaction(remult, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
132
|
+
return [4 /*yield*/, context_1.doTransaction(remult, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
236
133
|
var _a, _b, err_2;
|
|
237
134
|
return tslib_1.__generator(this, function (_c) {
|
|
238
135
|
switch (_c.label) {
|
|
@@ -351,10 +248,10 @@ function BackendMethod(options) {
|
|
|
351
248
|
var originalMethod = descriptor.value;
|
|
352
249
|
var serverAction = {
|
|
353
250
|
__register: function (reg) {
|
|
354
|
-
var
|
|
251
|
+
var e_1, _a;
|
|
355
252
|
var _this = this;
|
|
356
253
|
var c = new context_1.Remult();
|
|
357
|
-
var
|
|
254
|
+
var _loop_1 = function (constructor) {
|
|
358
255
|
var controllerOptions = x.classes.get(constructor);
|
|
359
256
|
if (!controllerOptions.key) {
|
|
360
257
|
controllerOptions.key = c.repo(constructor).metadata.key;
|
|
@@ -371,7 +268,7 @@ function BackendMethod(options) {
|
|
|
371
268
|
case 1:
|
|
372
269
|
_a.trys.push([1, 3, , 4]);
|
|
373
270
|
remult_1 = req;
|
|
374
|
-
return [4 /*yield*/, doTransaction(remult_1, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
271
|
+
return [4 /*yield*/, context_1.doTransaction(remult_1, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
375
272
|
var _a, repo, y, rowHelper, rows, defs, err_4, y, controllerRef, err_5;
|
|
376
273
|
var _b, _c, _d;
|
|
377
274
|
return tslib_1.__generator(this, function (_e) {
|
|
@@ -480,20 +377,20 @@ function BackendMethod(options) {
|
|
|
480
377
|
try {
|
|
481
378
|
for (var _b = tslib_1.__values(x.classes.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
482
379
|
var constructor = _c.value;
|
|
483
|
-
|
|
380
|
+
_loop_1(constructor);
|
|
484
381
|
}
|
|
485
382
|
}
|
|
486
|
-
catch (
|
|
383
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
487
384
|
finally {
|
|
488
385
|
try {
|
|
489
386
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
490
387
|
}
|
|
491
|
-
finally { if (
|
|
388
|
+
finally { if (e_1) throw e_1.error; }
|
|
492
389
|
}
|
|
493
390
|
},
|
|
494
391
|
doWork: function (args, self, baseUrl, http) {
|
|
495
392
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
496
|
-
var defs, classOptions_1, r, _a, _b, err_6, defs, r, _c, _d,
|
|
393
|
+
var defs, classOptions_1, r, _a, _b, err_6, defs, r, _c, _d, e_2;
|
|
497
394
|
var _e, _f, _g;
|
|
498
395
|
return tslib_1.__generator(this, function (_h) {
|
|
499
396
|
switch (_h.label) {
|
|
@@ -567,8 +464,8 @@ function BackendMethod(options) {
|
|
|
567
464
|
_h.sent();
|
|
568
465
|
return [2 /*return*/, r.result];
|
|
569
466
|
case 14:
|
|
570
|
-
|
|
571
|
-
throw defs.catchSaveErrors(
|
|
467
|
+
e_2 = _h.sent();
|
|
468
|
+
throw defs.catchSaveErrors(e_2);
|
|
572
469
|
case 15: return [2 /*return*/];
|
|
573
470
|
}
|
|
574
471
|
});
|
|
@@ -621,12 +518,12 @@ var ProgressListener = /** @class */ (function () {
|
|
|
621
518
|
}());
|
|
622
519
|
exports.ProgressListener = ProgressListener;
|
|
623
520
|
function prepareArgsToSend(types, args) {
|
|
624
|
-
var
|
|
521
|
+
var e_3, _a;
|
|
625
522
|
if (types) {
|
|
626
523
|
for (var index = 0; index < types.length; index++) {
|
|
627
524
|
var paramType = types[index];
|
|
628
525
|
try {
|
|
629
|
-
for (var _b = (
|
|
526
|
+
for (var _b = (e_3 = void 0, tslib_1.__values([context_1.Remult, sql_database_1.SqlDatabase])), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
630
527
|
var type = _c.value;
|
|
631
528
|
if (args[index] instanceof type)
|
|
632
529
|
args[index] = undefined;
|
|
@@ -635,12 +532,12 @@ function prepareArgsToSend(types, args) {
|
|
|
635
532
|
}
|
|
636
533
|
}
|
|
637
534
|
}
|
|
638
|
-
catch (
|
|
535
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
639
536
|
finally {
|
|
640
537
|
try {
|
|
641
538
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
642
539
|
}
|
|
643
|
-
finally { if (
|
|
540
|
+
finally { if (e_3) throw e_3.error; }
|
|
644
541
|
}
|
|
645
542
|
if (args[index] != undefined) {
|
|
646
543
|
var x = { valueType: paramType };
|