remult 0.18.1-exp.1 → 0.18.1-exp.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.
@@ -226,12 +226,9 @@ class transactionLiveQueryPublisher {
226
226
  }
227
227
  }
228
228
  flush() {
229
- //TODO - figure out and resolve
230
- setTimeout(() => {
231
- for (const key of this.transactionItems.keys()) {
232
- this.orig.itemChanged(key, this.transactionItems.get(key));
233
- }
234
- }, 100);
229
+ for (const key of this.transactionItems.keys()) {
230
+ this.orig.itemChanged(key, this.transactionItems.get(key));
231
+ }
235
232
  }
236
233
  sendChannelMessage(channel, message) {
237
234
  this.orig.sendChannelMessage(channel, message);
@@ -72,7 +72,8 @@ export class LiveQueryClient {
72
72
  q.subscribeCode = () => {
73
73
  if (q.unsubscribe) {
74
74
  q.unsubscribe();
75
- q.unsubscribe = undefined;
75
+ //TODO - consider race scenario where unsubscribe is called before subscribe
76
+ q.unsubscribe = () => { };
76
77
  }
77
78
  const thenResult = (r) => {
78
79
  this.client.then(c => {
@@ -25,12 +25,13 @@ export declare class LiveQueryStorageInMemoryImplementation implements LiveQuery
25
25
  export declare class LiveQueryPublisher implements LiveQueryPublisherInterface {
26
26
  dispatcher: ServerEventDispatcher;
27
27
  storage: LiveQueryStorage;
28
- private performWithRequest;
28
+ performWithRequest: (serializedRequest: any, entityKey: string, what: (repo: Repository<any>) => Promise<void>) => Promise<void>;
29
29
  constructor(dispatcher: ServerEventDispatcher, storage: LiveQueryStorage, performWithRequest: (serializedRequest: any, entityKey: string, what: (repo: Repository<any>) => Promise<void>) => Promise<void>);
30
30
  stopLiveQuery(id: any): void;
31
31
  sendChannelMessage<messageType>(channel: string, message: messageType): void;
32
32
  defineLiveQueryChannel(serializeRequest: () => any, entityKey: string, findOptions: FindOptions<any>, ids: any[], userId: string, repo: Repository<any>): string;
33
33
  runPromise(p: Promise<any>): void;
34
+ debugFileSaver: (x: any) => void;
34
35
  itemChanged(entityKey: string, changes: itemChange[]): void;
35
36
  }
36
37
  export interface ServerEventDispatcher {
@@ -49,6 +49,7 @@ export class LiveQueryPublisher {
49
49
  this.dispatcher = dispatcher;
50
50
  this.storage = storage;
51
51
  this.performWithRequest = performWithRequest;
52
+ this.debugFileSaver = (x) => { };
52
53
  }
53
54
  stopLiveQuery(id) {
54
55
  this.storage.remove(id);
@@ -70,6 +71,7 @@ export class LiveQueryPublisher {
70
71
  runPromise(p) {
71
72
  }
72
73
  itemChanged(entityKey, changes) {
74
+ //TODO - optimize so that the user will get their messages first. Based on user id
73
75
  this.runPromise(this.storage.provideListeners(entityKey, async ({ query, setLastIds }) => {
74
76
  await this.performWithRequest(query.requestJson, entityKey, async (repo) => {
75
77
  const messages = [];
@@ -104,6 +106,13 @@ export class LiveQueryPublisher {
104
106
  });
105
107
  }
106
108
  }
109
+ this.debugFileSaver({
110
+ query: query.id,
111
+ currentIds,
112
+ changes,
113
+ lastIds: query.lastIds,
114
+ messages
115
+ });
107
116
  await setLastIds(currentIds);
108
117
  this.dispatcher.sendChannelMessage(query.id, messages);
109
118
  });
@@ -83,6 +83,7 @@ export class MessageChannel {
83
83
  }
84
84
  }
85
85
  export const liveQueryKeepAliveRoute = '/_liveQueryKeepAlive';
86
+ //TODO Yoni - keep in remult?
86
87
  export class AMessageChannel {
87
88
  constructor(channelKey) {
88
89
  this.channelKey = channelKey;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.18.1-exp.1",
3
+ "version": "0.18.1-exp.2",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/src/context.js CHANGED
@@ -347,24 +347,20 @@ var transactionLiveQueryPublisher = /** @class */ (function () {
347
347
  }
348
348
  };
349
349
  transactionLiveQueryPublisher.prototype.flush = function () {
350
- var _this = this;
351
- //TODO - figure out and resolve
352
- setTimeout(function () {
353
- var e_5, _a;
354
- try {
355
- for (var _b = tslib_1.__values(_this.transactionItems.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
356
- var key = _c.value;
357
- _this.orig.itemChanged(key, _this.transactionItems.get(key));
358
- }
350
+ var e_5, _a;
351
+ try {
352
+ for (var _b = tslib_1.__values(this.transactionItems.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
353
+ var key = _c.value;
354
+ this.orig.itemChanged(key, this.transactionItems.get(key));
359
355
  }
360
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
361
- finally {
362
- try {
363
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
364
- }
365
- finally { if (e_5) throw e_5.error; }
356
+ }
357
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
358
+ finally {
359
+ try {
360
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
366
361
  }
367
- }, 100);
362
+ finally { if (e_5) throw e_5.error; }
363
+ }
368
364
  };
369
365
  transactionLiveQueryPublisher.prototype.sendChannelMessage = function (channel, message) {
370
366
  this.orig.sendChannelMessage(channel, message);
@@ -79,7 +79,8 @@ var LiveQueryClient = /** @class */ (function () {
79
79
  q.subscribeCode = function () {
80
80
  if (q.unsubscribe) {
81
81
  q.unsubscribe();
82
- q.unsubscribe = undefined;
82
+ //TODO - consider race scenario where unsubscribe is called before subscribe
83
+ q.unsubscribe = function () { };
83
84
  }
84
85
  var thenResult = function (r) {
85
86
  _this.client.then(function (c) {
@@ -25,12 +25,13 @@ export declare class LiveQueryStorageInMemoryImplementation implements LiveQuery
25
25
  export declare class LiveQueryPublisher implements LiveQueryPublisherInterface {
26
26
  dispatcher: ServerEventDispatcher;
27
27
  storage: LiveQueryStorage;
28
- private performWithRequest;
28
+ performWithRequest: (serializedRequest: any, entityKey: string, what: (repo: Repository<any>) => Promise<void>) => Promise<void>;
29
29
  constructor(dispatcher: ServerEventDispatcher, storage: LiveQueryStorage, performWithRequest: (serializedRequest: any, entityKey: string, what: (repo: Repository<any>) => Promise<void>) => Promise<void>);
30
30
  stopLiveQuery(id: any): void;
31
31
  sendChannelMessage<messageType>(channel: string, message: messageType): void;
32
32
  defineLiveQueryChannel(serializeRequest: () => any, entityKey: string, findOptions: FindOptions<any>, ids: any[], userId: string, repo: Repository<any>): string;
33
33
  runPromise(p: Promise<any>): void;
34
+ debugFileSaver: (x: any) => void;
34
35
  itemChanged(entityKey: string, changes: itemChange[]): void;
35
36
  }
36
37
  export interface ServerEventDispatcher {
@@ -124,6 +124,7 @@ var LiveQueryPublisher = /** @class */ (function () {
124
124
  this.dispatcher = dispatcher;
125
125
  this.storage = storage;
126
126
  this.performWithRequest = performWithRequest;
127
+ this.debugFileSaver = function (x) { };
127
128
  }
128
129
  LiveQueryPublisher.prototype.stopLiveQuery = function (id) {
129
130
  this.storage.remove(id);
@@ -146,6 +147,7 @@ var LiveQueryPublisher = /** @class */ (function () {
146
147
  };
147
148
  LiveQueryPublisher.prototype.itemChanged = function (entityKey, changes) {
148
149
  var _this = this;
150
+ //TODO - optimize so that the user will get their messages first. Based on user id
149
151
  this.runPromise(this.storage.provideListeners(entityKey, function (_a) {
150
152
  var query = _a.query, setLastIds = _a.setLastIds;
151
153
  return tslib_1.__awaiter(_this, void 0, void 0, function () {
@@ -218,6 +220,13 @@ var LiveQueryPublisher = /** @class */ (function () {
218
220
  }
219
221
  finally { if (e_4) throw e_4.error; }
220
222
  }
223
+ this.debugFileSaver({
224
+ query: query.id,
225
+ currentIds: currentIds,
226
+ changes: changes,
227
+ lastIds: query.lastIds,
228
+ messages: messages
229
+ });
221
230
  return [4 /*yield*/, setLastIds(currentIds)];
222
231
  case 2:
223
232
  _e.sent();
@@ -183,6 +183,7 @@ var MessageChannel = /** @class */ (function () {
183
183
  }());
184
184
  exports.MessageChannel = MessageChannel;
185
185
  exports.liveQueryKeepAliveRoute = '/_liveQueryKeepAlive';
186
+ //TODO Yoni - keep in remult?
186
187
  var AMessageChannel = /** @class */ (function () {
187
188
  function AMessageChannel(channelKey) {
188
189
  this.channelKey = channelKey;