remult 0.18.1-exp.0 → 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.
@@ -14,6 +14,7 @@ export declare class ServerEventsController implements ServerEventDispatcher {
14
14
  connections: clientConnection[];
15
15
  constructor(canUserConnectToChannel?: (channel: string, remult: Remult) => boolean);
16
16
  sendChannelMessage<T>(channel: string, message: any): void;
17
+ debugMessageFileSaver: (id: any, channel: any, message: any) => void;
17
18
  openHttpServerStream(req: import('express').Request, res: import('express').Response): clientConnection;
18
19
  debug(): void;
19
20
  debugFileSaver: (x: any) => void;
@@ -53,6 +53,7 @@ export class ServerEventsController {
53
53
  constructor(canUserConnectToChannel) {
54
54
  this.canUserConnectToChannel = canUserConnectToChannel;
55
55
  this.connections = [];
56
+ this.debugMessageFileSaver = (id, channel, message) => { };
56
57
  this.debugFileSaver = () => { };
57
58
  if (!this.canUserConnectToChannel) {
58
59
  this.canUserConnectToChannel = () => true;
@@ -83,6 +84,7 @@ export class ServerEventsController {
83
84
  const data = JSON.stringify({ channel, data: message });
84
85
  for (const sc of this.connections) {
85
86
  if (sc.channels[channel]) {
87
+ this.debugMessageFileSaver(sc.connectionId, channel, message);
86
88
  sc.write(data);
87
89
  }
88
90
  }
@@ -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);
@@ -29,12 +29,17 @@ export function findOptionsToJson(options, meta) {
29
29
  };
30
30
  }
31
31
  export function findOptionsFromJson(json, meta) {
32
- return {
33
- limit: json.limit,
34
- page: json.page,
35
- where: Filter.entityFilterFromJson(meta, json.where),
36
- orderBy: json.orderBy
37
- };
32
+ let r = {};
33
+ for (const key of ["limit", "page", "where", "orderBy"]) {
34
+ if (json[key] !== undefined) {
35
+ if (key === "where") {
36
+ r[key] = Filter.entityFilterFromJson(meta, json.where);
37
+ }
38
+ else
39
+ r[key] = json[key];
40
+ }
41
+ }
42
+ return r;
38
43
  }
39
44
  export class RestEntityDataProvider {
40
45
  constructor(url, http, entity) {
@@ -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,9 +71,10 @@ export class LiveQueryPublisher {
70
71
  runPromise(p) {
71
72
  }
72
73
  itemChanged(entityKey, changes) {
73
- const messages = [];
74
+ //TODO - optimize so that the user will get their messages first. Based on user id
74
75
  this.runPromise(this.storage.provideListeners(entityKey, async ({ query, setLastIds }) => {
75
76
  await this.performWithRequest(query.requestJson, entityKey, async (repo) => {
77
+ const messages = [];
76
78
  const currentItems = await repo.find(findOptionsFromJson(query.findOptionsJson, repo.metadata));
77
79
  const currentIds = currentItems.map(x => repo.getEntityRef(x).getId());
78
80
  for (const id of query.lastIds.filter(y => !currentIds.includes(y))) {
@@ -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.0",
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",
@@ -14,6 +14,7 @@ export declare class ServerEventsController implements ServerEventDispatcher {
14
14
  connections: clientConnection[];
15
15
  constructor(canUserConnectToChannel?: (channel: string, remult: Remult) => boolean);
16
16
  sendChannelMessage<T>(channel: string, message: any): void;
17
+ debugMessageFileSaver: (id: any, channel: any, message: any) => void;
17
18
  openHttpServerStream(req: import('express').Request, res: import('express').Response): clientConnection;
18
19
  debug(): void;
19
20
  debugFileSaver: (x: any) => void;
package/remult-express.js CHANGED
@@ -126,6 +126,7 @@ var ServerEventsController = /** @class */ (function () {
126
126
  function ServerEventsController(canUserConnectToChannel) {
127
127
  this.canUserConnectToChannel = canUserConnectToChannel;
128
128
  this.connections = [];
129
+ this.debugMessageFileSaver = function (id, channel, message) { };
129
130
  this.debugFileSaver = function () { };
130
131
  if (!this.canUserConnectToChannel) {
131
132
  this.canUserConnectToChannel = function () { return true; };
@@ -172,6 +173,7 @@ var ServerEventsController = /** @class */ (function () {
172
173
  for (var _b = tslib_1.__values(this.connections), _c = _b.next(); !_c.done; _c = _b.next()) {
173
174
  var sc = _c.value;
174
175
  if (sc.channels[channel]) {
176
+ this.debugMessageFileSaver(sc.connectionId, channel, message);
175
177
  sc.write(data);
176
178
  }
177
179
  }
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);
@@ -42,12 +42,28 @@ function findOptionsToJson(options, meta) {
42
42
  }
43
43
  exports.findOptionsToJson = findOptionsToJson;
44
44
  function findOptionsFromJson(json, meta) {
45
- return {
46
- limit: json.limit,
47
- page: json.page,
48
- where: filter_interfaces_1.Filter.entityFilterFromJson(meta, json.where),
49
- orderBy: json.orderBy
50
- };
45
+ var e_1, _a;
46
+ var r = {};
47
+ try {
48
+ for (var _b = tslib_1.__values(["limit", "page", "where", "orderBy"]), _c = _b.next(); !_c.done; _c = _b.next()) {
49
+ var key = _c.value;
50
+ if (json[key] !== undefined) {
51
+ if (key === "where") {
52
+ r[key] = filter_interfaces_1.Filter.entityFilterFromJson(meta, json.where);
53
+ }
54
+ else
55
+ r[key] = json[key];
56
+ }
57
+ }
58
+ }
59
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
60
+ finally {
61
+ try {
62
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
63
+ }
64
+ finally { if (e_1) throw e_1.error; }
65
+ }
66
+ return r;
51
67
  }
52
68
  exports.findOptionsFromJson = findOptionsFromJson;
53
69
  var RestEntityDataProvider = /** @class */ (function () {
@@ -57,7 +73,7 @@ var RestEntityDataProvider = /** @class */ (function () {
57
73
  this.entity = entity;
58
74
  }
59
75
  RestEntityDataProvider.prototype.translateFromJson = function (row) {
60
- var e_1, _a;
76
+ var e_2, _a;
61
77
  var result = {};
62
78
  try {
63
79
  for (var _b = tslib_1.__values(this.entity.fields), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -65,17 +81,17 @@ var RestEntityDataProvider = /** @class */ (function () {
65
81
  result[col.key] = col.valueConverter.fromJson(row[col.key]);
66
82
  }
67
83
  }
68
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
84
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
69
85
  finally {
70
86
  try {
71
87
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
72
88
  }
73
- finally { if (e_1) throw e_1.error; }
89
+ finally { if (e_2) throw e_2.error; }
74
90
  }
75
91
  return result;
76
92
  };
77
93
  RestEntityDataProvider.prototype.translateToJson = function (row) {
78
- var e_2, _a;
94
+ var e_3, _a;
79
95
  var result = {};
80
96
  try {
81
97
  for (var _b = tslib_1.__values(this.entity.fields), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -83,12 +99,12 @@ var RestEntityDataProvider = /** @class */ (function () {
83
99
  result[col.key] = col.valueConverter.toJson(row[col.key]);
84
100
  }
85
101
  }
86
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
102
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
87
103
  finally {
88
104
  try {
89
105
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
90
106
  }
91
- finally { if (e_2) throw e_2.error; }
107
+ finally { if (e_3) throw e_3.error; }
92
108
  }
93
109
  return result;
94
110
  };
@@ -153,7 +169,7 @@ var RestEntityDataProvider = /** @class */ (function () {
153
169
  return { filterObject: filterObject, url: url };
154
170
  };
155
171
  RestEntityDataProvider.prototype.update = function (id, data) {
156
- var e_3, _a;
172
+ var e_4, _a;
157
173
  var _this = this;
158
174
  var result = {};
159
175
  var keys = Object.keys(data);
@@ -164,12 +180,12 @@ var RestEntityDataProvider = /** @class */ (function () {
164
180
  result[col.key] = col.valueConverter.toJson(data[col.key]);
165
181
  }
166
182
  }
167
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
183
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
168
184
  finally {
169
185
  try {
170
186
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
171
187
  }
172
- finally { if (e_3) throw e_3.error; }
188
+ finally { if (e_4) throw e_4.error; }
173
189
  }
174
190
  return this.http().put(this.url() + '/' + encodeURIComponent(id), result).then(function (y) { return _this.translateFromJson(y); });
175
191
  };
@@ -228,7 +244,7 @@ var RestDataProviderHttpProviderUsingFetch = /** @class */ (function () {
228
244
  });
229
245
  };
230
246
  RestDataProviderHttpProviderUsingFetch.prototype.myFetch = function (url, options) {
231
- var e_4, _a;
247
+ var e_5, _a;
232
248
  var _this = this;
233
249
  var headers = {
234
250
  "Content-type": "application/json"
@@ -242,12 +258,12 @@ var RestDataProviderHttpProviderUsingFetch = /** @class */ (function () {
242
258
  }
243
259
  }
244
260
  }
245
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
261
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
246
262
  finally {
247
263
  try {
248
264
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
249
265
  }
250
- finally { if (e_4) throw e_4.error; }
266
+ finally { if (e_5) throw e_5.error; }
251
267
  }
252
268
  return (this.fetch || fetch)(url, {
253
269
  credentials: 'include',
@@ -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,7 +147,7 @@ var LiveQueryPublisher = /** @class */ (function () {
146
147
  };
147
148
  LiveQueryPublisher.prototype.itemChanged = function (entityKey, changes) {
148
149
  var _this = this;
149
- var messages = [];
150
+ //TODO - optimize so that the user will get their messages first. Based on user id
150
151
  this.runPromise(this.storage.provideListeners(entityKey, function (_a) {
151
152
  var query = _a.query, setLastIds = _a.setLastIds;
152
153
  return tslib_1.__awaiter(_this, void 0, void 0, function () {
@@ -154,11 +155,13 @@ var LiveQueryPublisher = /** @class */ (function () {
154
155
  return tslib_1.__generator(this, function (_b) {
155
156
  switch (_b.label) {
156
157
  case 0: return [4 /*yield*/, this.performWithRequest(query.requestJson, entityKey, function (repo) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
157
- var currentItems, currentIds, _loop_3, _a, _b, id, _loop_4, currentItems_1, currentItems_1_1, item;
158
+ var messages, currentItems, currentIds, _loop_3, _a, _b, id, _loop_4, currentItems_1, currentItems_1_1, item;
158
159
  var e_3, _c, e_4, _d;
159
160
  return tslib_1.__generator(this, function (_e) {
160
161
  switch (_e.label) {
161
- case 0: return [4 /*yield*/, repo.find(rest_data_provider_1.findOptionsFromJson(query.findOptionsJson, repo.metadata))];
162
+ case 0:
163
+ messages = [];
164
+ return [4 /*yield*/, repo.find(rest_data_provider_1.findOptionsFromJson(query.findOptionsJson, repo.metadata))];
162
165
  case 1:
163
166
  currentItems = _e.sent();
164
167
  currentIds = currentItems.map(function (x) { return repo.getEntityRef(x).getId(); });
@@ -217,6 +220,13 @@ var LiveQueryPublisher = /** @class */ (function () {
217
220
  }
218
221
  finally { if (e_4) throw e_4.error; }
219
222
  }
223
+ this.debugFileSaver({
224
+ query: query.id,
225
+ currentIds: currentIds,
226
+ changes: changes,
227
+ lastIds: query.lastIds,
228
+ messages: messages
229
+ });
220
230
  return [4 /*yield*/, setLastIds(currentIds)];
221
231
  case 2:
222
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;