remult 0.18.1-exp.32 → 0.18.1-exp.34

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/ably.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type * as Ably from '../../node_modules/ably';
2
+ import type { SubscriptionServer } from './src/live-query/SubscriptionServer';
3
+ import type { SubscriptionClient, SubscriptionClientConnection } from './src/live-query/SubscriptionChannel';
4
+ export declare class AblySubscriptionClient implements SubscriptionClient {
5
+ private ably;
6
+ constructor(ably: Ably.Types.RealtimePromise);
7
+ openConnection(onReconnect: VoidFunction): Promise<SubscriptionClientConnection>;
8
+ }
9
+ export declare class AblySubscriptionServer implements SubscriptionServer {
10
+ private ably;
11
+ constructor(ably: Ably.Types.RestPromise);
12
+ publishMessage<T>(channel: string, message: T): Promise<void>;
13
+ }
package/ably.js ADDED
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AblySubscriptionServer = exports.AblySubscriptionClient = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var AblySubscriptionClient = /** @class */ (function () {
6
+ function AblySubscriptionClient(ably) {
7
+ this.ably = ably;
8
+ }
9
+ AblySubscriptionClient.prototype.openConnection = function (onReconnect) {
10
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
11
+ var _this = this;
12
+ return tslib_1.__generator(this, function (_a) {
13
+ return [2 /*return*/, {
14
+ close: function () {
15
+ // Since we did not open the connection, we do not close it
16
+ },
17
+ subscribe: function (channel, handler) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
18
+ var myHandler;
19
+ var _this = this;
20
+ return tslib_1.__generator(this, function (_a) {
21
+ switch (_a.label) {
22
+ case 0:
23
+ myHandler = function (y) { return handler(y.data); };
24
+ return [4 /*yield*/, this.ably.channels.get(channel).subscribe(function (y) { return myHandler(y); })];
25
+ case 1:
26
+ _a.sent();
27
+ return [2 /*return*/, function () {
28
+ myHandler = function () { };
29
+ _this.ably.channels.get(channel).unsubscribe();
30
+ }];
31
+ }
32
+ });
33
+ }); }
34
+ }];
35
+ });
36
+ });
37
+ };
38
+ return AblySubscriptionClient;
39
+ }());
40
+ exports.AblySubscriptionClient = AblySubscriptionClient;
41
+ var AblySubscriptionServer = /** @class */ (function () {
42
+ function AblySubscriptionServer(ably) {
43
+ this.ably = ably;
44
+ }
45
+ AblySubscriptionServer.prototype.publishMessage = function (channel, message) {
46
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
47
+ return tslib_1.__generator(this, function (_a) {
48
+ switch (_a.label) {
49
+ case 0: return [4 /*yield*/, this.ably.channels.get(channel).publish({ data: message })];
50
+ case 1:
51
+ _a.sent();
52
+ return [2 /*return*/];
53
+ }
54
+ });
55
+ });
56
+ };
57
+ return AblySubscriptionServer;
58
+ }());
59
+ exports.AblySubscriptionServer = AblySubscriptionServer;
package/esm/ably.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type * as Ably from '../../node_modules/ably';
2
+ import type { SubscriptionServer } from './src/live-query/SubscriptionServer';
3
+ import type { SubscriptionClient, SubscriptionClientConnection } from './src/live-query/SubscriptionChannel';
4
+ export declare class AblySubscriptionClient implements SubscriptionClient {
5
+ private ably;
6
+ constructor(ably: Ably.Types.RealtimePromise);
7
+ openConnection(onReconnect: VoidFunction): Promise<SubscriptionClientConnection>;
8
+ }
9
+ export declare class AblySubscriptionServer implements SubscriptionServer {
10
+ private ably;
11
+ constructor(ably: Ably.Types.RestPromise);
12
+ publishMessage<T>(channel: string, message: T): Promise<void>;
13
+ }
package/esm/ably.js ADDED
@@ -0,0 +1,28 @@
1
+ export class AblySubscriptionClient {
2
+ constructor(ably) {
3
+ this.ably = ably;
4
+ }
5
+ async openConnection(onReconnect) {
6
+ return {
7
+ close: () => {
8
+ // Since we did not open the connection, we do not close it
9
+ },
10
+ subscribe: async (channel, handler) => {
11
+ let myHandler = (y) => handler(y.data);
12
+ await this.ably.channels.get(channel).subscribe(y => myHandler(y));
13
+ return () => {
14
+ myHandler = () => { };
15
+ this.ably.channels.get(channel).unsubscribe();
16
+ };
17
+ }
18
+ };
19
+ }
20
+ }
21
+ export class AblySubscriptionServer {
22
+ constructor(ably) {
23
+ this.ably = ably;
24
+ }
25
+ async publishMessage(channel, message) {
26
+ await this.ably.channels.get(channel).publish({ data: message });
27
+ }
28
+ }
package/esm/index.d.ts CHANGED
@@ -26,4 +26,3 @@ export { ValueConverters } from './src/valueConverters';
26
26
  export { remult } from './src/remult-proxy';
27
27
  export { SubscriptionServer, LiveQueryStorage, StoredQuery, InMemoryLiveQueryStorage } from "./src/live-query/SubscriptionServer";
28
28
  export { SubscriptionListener, SubscriptionClientConnection, SubscriptionClient, SubscriptionChannel, LiveQueryChange, Unsubscribe } from './src/live-query/SubscriptionChannel';
29
- export { DataProviderLiveQueryStorage } from './live-query/data-provider-live-query-storage';
package/esm/index.js CHANGED
@@ -24,4 +24,3 @@ export { remult } from './src/remult-proxy';
24
24
  //export { getId } from './src/remult3/getId';
25
25
  export { InMemoryLiveQueryStorage } from "./src/live-query/SubscriptionServer";
26
26
  export { SubscriptionChannel } from './src/live-query/SubscriptionChannel';
27
- export { DataProviderLiveQueryStorage } from './live-query/data-provider-live-query-storage';
@@ -1,21 +1,21 @@
1
1
  import { Remult } from "../src/context";
2
2
  import { CanEnsureSchema, DataProvider } from "../src/data-interfaces";
3
3
  import { LiveQueryStorage, StoredQuery } from "../src/live-query/SubscriptionServer";
4
- import { Repository } from "../src/remult3";
4
+ import { EntityBase, Repository } from "../src/remult3";
5
5
  export declare class DataProviderLiveQueryStorage implements LiveQueryStorage, CanEnsureSchema {
6
6
  repo: Promise<Repository<LiveQueryStorageEntity>>;
7
7
  dataProvider: Promise<DataProvider>;
8
8
  constructor(dataProvider: DataProvider | Promise<DataProvider> | (() => Promise<DataProvider | undefined>));
9
9
  ensureSchema(remult: Remult): Promise<void>;
10
- add({ id, entityKey, data }: StoredQuery): void;
11
- remove(queryId: string): void;
10
+ add({ id, entityKey, data }: StoredQuery): Promise<void>;
11
+ remove(queryId: string): Promise<void>;
12
12
  forEach(entityKey: string, callback: (args: {
13
13
  query: StoredQuery;
14
14
  setData(data: any): Promise<void>;
15
15
  }) => Promise<void>): Promise<void>;
16
16
  keepAliveAndReturnUnknownQueryIds(queryIds: string[]): Promise<string[]>;
17
17
  }
18
- declare class LiveQueryStorageEntity {
18
+ declare class LiveQueryStorageEntity extends EntityBase {
19
19
  id: string;
20
20
  entityKey: string;
21
21
  data: any;
@@ -1,7 +1,7 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
2
  import { initDataProvider } from "../server/initDataProvider";
3
3
  import { Remult } from "../src/context";
4
- import { Entity, Fields } from "../src/remult3";
4
+ import { Entity, EntityBase, Fields } from "../src/remult3";
5
5
  export class DataProviderLiveQueryStorage {
6
6
  constructor(dataProvider) {
7
7
  this.dataProvider = initDataProvider(dataProvider);
@@ -10,14 +10,15 @@ export class DataProviderLiveQueryStorage {
10
10
  async ensureSchema(remult) {
11
11
  await (await this.dataProvider).ensureSchema([(await this.repo).metadata], "Live query storage");
12
12
  }
13
- add({ id, entityKey, data }) {
14
- this.repo.then(async (repo) => {
13
+ async add({ id, entityKey, data }) {
14
+ await this.repo.then(async (repo) => {
15
+ //TODO - talk to yoni about how this fails with non entity ref - since repo save here makes a wrong decision, since an item returns
15
16
  const q = await repo.findId(id, { createIfNotFound: true });
16
- await repo.save({ ...q, entityKey, data });
17
+ await q.assign({ entityKey, data }).save();
17
18
  });
18
19
  }
19
- remove(queryId) {
20
- this.repo.then(repo => repo.delete(queryId)).catch(() => { });
20
+ async remove(queryId) {
21
+ await this.repo.then(repo => repo.delete(queryId)).catch(() => { });
21
22
  }
22
23
  async forEach(entityKey, callback) {
23
24
  const repo = await this.repo;
@@ -47,8 +48,9 @@ export class DataProviderLiveQueryStorage {
47
48
  return queryIds;
48
49
  }
49
50
  }
50
- let LiveQueryStorageEntity = class LiveQueryStorageEntity {
51
+ let LiveQueryStorageEntity = class LiveQueryStorageEntity extends EntityBase {
51
52
  constructor() {
53
+ super(...arguments);
52
54
  this.id = '';
53
55
  this.entityKey = '';
54
56
  this.lastUsedIso = new Date().toISOString();
@@ -1,3 +1,4 @@
1
1
  export { queuedJobInfo, QueueStorage, GenericRequest, GenericRequestHandler, GenericResponse, GenericRouter, createRemultServerCore, RemultServerOptions, SpecificRoute, RemultServer } from './expressBridge';
2
2
  export { JsonEntityFileStorage, JsonFileDataProvider } from './JsonEntityFileStorage';
3
3
  export { SseSubscriptionServer } from '../SseSubscriptionServer';
4
+ export { DataProviderLiveQueryStorage } from '../live-query/data-provider-live-query-storage';
@@ -1,3 +1,4 @@
1
1
  export { createRemultServerCore } from './expressBridge';
2
2
  export { JsonEntityFileStorage, JsonFileDataProvider } from './JsonEntityFileStorage';
3
3
  export { SseSubscriptionServer } from '../SseSubscriptionServer';
4
+ export { DataProviderLiveQueryStorage } from '../live-query/data-provider-live-query-storage';
@@ -20,7 +20,7 @@ export class DataApi {
20
20
  }
21
21
  return this.getArray(res, req, undefined);
22
22
  }
23
- httpPost(res, req, body, serializeRequest) {
23
+ async httpPost(res, req, body, serializeRequest) {
24
24
  const action = req?.get("__action");
25
25
  if (action?.startsWith(liveQueryAction))
26
26
  return this.liveQuery(res, req, undefined, serializeRequest, getLiveQueryChannel(action.substring(liveQueryAction.length), this.remult.user?.id));
@@ -30,7 +30,7 @@ export class DataApi {
30
30
  case "count":
31
31
  return this.count(res, req, body);
32
32
  case "endLiveQuery":
33
- this.remult.liveQueryStorage.remove(getLiveQueryChannel(body.id, this.remult.user?.id));
33
+ await this.remult.liveQueryStorage.remove(getLiveQueryChannel(body.id, this.remult.user?.id));
34
34
  res.success("ok");
35
35
  return;
36
36
  default:
@@ -133,7 +133,7 @@ export class DataApi {
133
133
  findOptionsJson: findOptionsToJson(r.findOptions, this.repository.metadata),
134
134
  lastIds: r.r.map(y => getId(this.repository.metadata, y))
135
135
  };
136
- this.remult.liveQueryStorage.add({
136
+ await this.remult.liveQueryStorage.add({
137
137
  entityKey: this.repository.metadata.key,
138
138
  id: queryChannel,
139
139
  data
@@ -2,8 +2,8 @@ export interface SubscriptionServer {
2
2
  publishMessage<T>(channel: string, message: T): Promise<void>;
3
3
  }
4
4
  export interface LiveQueryStorage {
5
- add(query: StoredQuery): void;
6
- remove(queryId: string): void;
5
+ add(query: StoredQuery): Promise<void>;
6
+ remove(queryId: string): Promise<void>;
7
7
  forEach(entityKey: string, callback: (args: {
8
8
  query: StoredQuery;
9
9
  setData(data: any): Promise<void>;
@@ -18,9 +18,9 @@ export declare class InMemoryLiveQueryStorage implements LiveQueryStorage {
18
18
  lastUsed: string;
19
19
  })[];
20
20
  constructor();
21
- add(query: StoredQuery): void;
21
+ add(query: StoredQuery): Promise<void>;
22
22
  removeCountForTesting: number;
23
- remove(id: any): void;
23
+ remove(id: any): Promise<void>;
24
24
  forEach(entityKey: string, handle: (args: {
25
25
  query: StoredQuery;
26
26
  setData(data: any): Promise<void>;
@@ -82,11 +82,11 @@ export class InMemoryLiveQueryStorage {
82
82
  this.debug();
83
83
  return result;
84
84
  }
85
- add(query) {
85
+ async add(query) {
86
86
  this.queries.push({ ...query, lastUsed: new Date().toISOString() });
87
87
  this.debug();
88
88
  }
89
- remove(id) {
89
+ async remove(id) {
90
90
  this.queries = this.queries.filter(q => q.id !== id);
91
91
  this.removeCountForTesting++;
92
92
  this.debug();
@@ -19,6 +19,8 @@ import { Validators } from "../validators";
19
19
  import { Status } from "../tests/testModel/models";
20
20
  import { IdEntity } from "../id-entity";
21
21
  import { describeClass } from "../remult3/DecoratorReplacer";
22
+ import { DataProviderLiveQueryStorage } from "../../live-query/data-provider-live-query-storage";
23
+ import { v4 as uuid } from 'uuid';
22
24
  testAll("what", async ({ remult, createEntity }) => {
23
25
  await (await createEntity(stam)).create({ id: 1, title: 'noam' }).save();
24
26
  expect(await remult.repo(stam).count()).toBe(1);
@@ -767,3 +769,14 @@ testAll("test date", async ({ createEntity }) => {
767
769
  let item = await r.findFirst();
768
770
  expect(item.d.getFullYear()).toBe(1976);
769
771
  }, false);
772
+ testAll("test live query storage", async ({ db, remult }) => {
773
+ var x = new DataProviderLiveQueryStorage(db);
774
+ if (db.ensureSchema)
775
+ await x.ensureSchema(remult);
776
+ const id = uuid();
777
+ await x.add({ id, entityKey: 'x', data: "noam" });
778
+ await x.forEach("x", async (args) => {
779
+ expect(args.query.data).toBe("noam");
780
+ });
781
+ expect((await x.keepAliveAndReturnUnknownQueryIds([id]))).toEqual([]);
782
+ });
package/index.d.ts CHANGED
@@ -26,4 +26,3 @@ export { ValueConverters } from './src/valueConverters';
26
26
  export { remult } from './src/remult-proxy';
27
27
  export { SubscriptionServer, LiveQueryStorage, StoredQuery, InMemoryLiveQueryStorage } from "./src/live-query/SubscriptionServer";
28
28
  export { SubscriptionListener, SubscriptionClientConnection, SubscriptionClient, SubscriptionChannel, LiveQueryChange, Unsubscribe } from './src/live-query/SubscriptionChannel';
29
- export { DataProviderLiveQueryStorage } from './live-query/data-provider-live-query-storage';
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DataProviderLiveQueryStorage = exports.SubscriptionChannel = exports.InMemoryLiveQueryStorage = exports.remult = exports.ValueConverters = exports.Validators = exports.UrlBuilder = exports.Filter = exports.CompoundIdField = exports.OneToMany = exports.Sort = exports.IdEntity = exports.EventSource = exports.isBackend = exports.Remult = exports.Allow = exports.ProgressListener = exports.BackendMethod = exports.Controller = exports.JsonDataProvider = exports.dbNamesOf = exports.CustomSqlFilterBuilder = exports.SqlDatabase = exports.WebSqlDataProvider = exports.ArrayEntityDataProvider = exports.InMemoryDataProvider = exports.RestDataProvider = exports.describeClass = exports.CaptionTransformer = exports.ValueListInfo = exports.getValueList = exports.ValueListFieldType = exports.getEntityRef = exports.getFields = exports.FieldType = exports.ControllerBase = exports.EntityBase = exports.Entity = exports.Fields = exports.Field = void 0;
3
+ exports.SubscriptionChannel = exports.InMemoryLiveQueryStorage = exports.remult = exports.ValueConverters = exports.Validators = exports.UrlBuilder = exports.Filter = exports.CompoundIdField = exports.OneToMany = exports.Sort = exports.IdEntity = exports.EventSource = exports.isBackend = exports.Remult = exports.Allow = exports.ProgressListener = exports.BackendMethod = exports.Controller = exports.JsonDataProvider = exports.dbNamesOf = exports.CustomSqlFilterBuilder = exports.SqlDatabase = exports.WebSqlDataProvider = exports.ArrayEntityDataProvider = exports.InMemoryDataProvider = exports.RestDataProvider = exports.describeClass = exports.CaptionTransformer = exports.ValueListInfo = exports.getValueList = exports.ValueListFieldType = exports.getEntityRef = exports.getFields = exports.FieldType = exports.ControllerBase = exports.EntityBase = exports.Entity = exports.Fields = exports.Field = void 0;
4
4
  /*
5
5
  * Public API Surface of remult
6
6
  */
@@ -66,5 +66,3 @@ var SubscriptionServer_1 = require("./src/live-query/SubscriptionServer");
66
66
  Object.defineProperty(exports, "InMemoryLiveQueryStorage", { enumerable: true, get: function () { return SubscriptionServer_1.InMemoryLiveQueryStorage; } });
67
67
  var SubscriptionChannel_1 = require("./src/live-query/SubscriptionChannel");
68
68
  Object.defineProperty(exports, "SubscriptionChannel", { enumerable: true, get: function () { return SubscriptionChannel_1.SubscriptionChannel; } });
69
- var data_provider_live_query_storage_1 = require("./live-query/data-provider-live-query-storage");
70
- Object.defineProperty(exports, "DataProviderLiveQueryStorage", { enumerable: true, get: function () { return data_provider_live_query_storage_1.DataProviderLiveQueryStorage; } });
@@ -1,21 +1,21 @@
1
1
  import { Remult } from "../src/context";
2
2
  import { CanEnsureSchema, DataProvider } from "../src/data-interfaces";
3
3
  import { LiveQueryStorage, StoredQuery } from "../src/live-query/SubscriptionServer";
4
- import { Repository } from "../src/remult3";
4
+ import { EntityBase, Repository } from "../src/remult3";
5
5
  export declare class DataProviderLiveQueryStorage implements LiveQueryStorage, CanEnsureSchema {
6
6
  repo: Promise<Repository<LiveQueryStorageEntity>>;
7
7
  dataProvider: Promise<DataProvider>;
8
8
  constructor(dataProvider: DataProvider | Promise<DataProvider> | (() => Promise<DataProvider | undefined>));
9
9
  ensureSchema(remult: Remult): Promise<void>;
10
- add({ id, entityKey, data }: StoredQuery): void;
11
- remove(queryId: string): void;
10
+ add({ id, entityKey, data }: StoredQuery): Promise<void>;
11
+ remove(queryId: string): Promise<void>;
12
12
  forEach(entityKey: string, callback: (args: {
13
13
  query: StoredQuery;
14
14
  setData(data: any): Promise<void>;
15
15
  }) => Promise<void>): Promise<void>;
16
16
  keepAliveAndReturnUnknownQueryIds(queryIds: string[]): Promise<string[]>;
17
17
  }
18
- declare class LiveQueryStorageEntity {
18
+ declare class LiveQueryStorageEntity extends EntityBase {
19
19
  id: string;
20
20
  entityKey: string;
21
21
  data: any;
@@ -30,25 +30,43 @@ var DataProviderLiveQueryStorage = /** @class */ (function () {
30
30
  });
31
31
  };
32
32
  DataProviderLiveQueryStorage.prototype.add = function (_a) {
33
- var _this = this;
34
33
  var id = _a.id, entityKey = _a.entityKey, data = _a.data;
35
- this.repo.then(function (repo) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
36
- var q;
34
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
35
+ var _this = this;
36
+ return tslib_1.__generator(this, function (_b) {
37
+ switch (_b.label) {
38
+ case 0: return [4 /*yield*/, this.repo.then(function (repo) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
39
+ var q;
40
+ return tslib_1.__generator(this, function (_a) {
41
+ switch (_a.label) {
42
+ case 0: return [4 /*yield*/, repo.findId(id, { createIfNotFound: true })];
43
+ case 1:
44
+ q = _a.sent();
45
+ return [4 /*yield*/, q.assign({ entityKey: entityKey, data: data }).save()];
46
+ case 2:
47
+ _a.sent();
48
+ return [2 /*return*/];
49
+ }
50
+ });
51
+ }); })];
52
+ case 1:
53
+ _b.sent();
54
+ return [2 /*return*/];
55
+ }
56
+ });
57
+ });
58
+ };
59
+ DataProviderLiveQueryStorage.prototype.remove = function (queryId) {
60
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
37
61
  return tslib_1.__generator(this, function (_a) {
38
62
  switch (_a.label) {
39
- case 0: return [4 /*yield*/, repo.findId(id, { createIfNotFound: true })];
63
+ case 0: return [4 /*yield*/, this.repo.then(function (repo) { return repo.delete(queryId); }).catch(function () { })];
40
64
  case 1:
41
- q = _a.sent();
42
- return [4 /*yield*/, repo.save(tslib_1.__assign(tslib_1.__assign({}, q), { entityKey: entityKey, data: data }))];
43
- case 2:
44
65
  _a.sent();
45
66
  return [2 /*return*/];
46
67
  }
47
68
  });
48
- }); });
49
- };
50
- DataProviderLiveQueryStorage.prototype.remove = function (queryId) {
51
- this.repo.then(function (repo) { return repo.delete(queryId); }).catch(function () { });
69
+ });
52
70
  };
53
71
  DataProviderLiveQueryStorage.prototype.forEach = function (entityKey, callback) {
54
72
  return tslib_1.__awaiter(this, void 0, void 0, function () {
@@ -184,11 +202,14 @@ var DataProviderLiveQueryStorage = /** @class */ (function () {
184
202
  return DataProviderLiveQueryStorage;
185
203
  }());
186
204
  exports.DataProviderLiveQueryStorage = DataProviderLiveQueryStorage;
187
- var LiveQueryStorageEntity = /** @class */ (function () {
205
+ var LiveQueryStorageEntity = /** @class */ (function (_super) {
206
+ tslib_1.__extends(LiveQueryStorageEntity, _super);
188
207
  function LiveQueryStorageEntity() {
189
- this.id = '';
190
- this.entityKey = '';
191
- this.lastUsedIso = new Date().toISOString();
208
+ var _this = _super !== null && _super.apply(this, arguments) || this;
209
+ _this.id = '';
210
+ _this.entityKey = '';
211
+ _this.lastUsedIso = new Date().toISOString();
212
+ return _this;
192
213
  }
193
214
  tslib_1.__decorate([
194
215
  remult3_1.Fields.string(),
@@ -212,4 +233,4 @@ var LiveQueryStorageEntity = /** @class */ (function () {
212
233
  })
213
234
  ], LiveQueryStorageEntity);
214
235
  return LiveQueryStorageEntity;
215
- }());
236
+ }(remult3_1.EntityBase));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.18.1-exp.32",
3
+ "version": "0.18.1-exp.34",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -111,12 +111,12 @@
111
111
  "import": "./esm/remult-mongo.js"
112
112
  },
113
113
  "./ably": {
114
- "require": "./live-query/ably.js",
114
+ "require": "./ably.js",
115
115
  "node": {
116
- "require": "./live-query/ably.js",
117
- "import": "./live-query/ably.js"
116
+ "require": "./ably.js",
117
+ "import": "./ably.js"
118
118
  },
119
- "import": "./esm/live-query/ably.js"
119
+ "import": "./esm/ably.js"
120
120
  },
121
121
  "./graphql": {
122
122
  "require": "./graphql.js",
package/server/core.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { queuedJobInfo, QueueStorage, GenericRequest, GenericRequestHandler, GenericResponse, GenericRouter, createRemultServerCore, RemultServerOptions, SpecificRoute, RemultServer } from './expressBridge';
2
2
  export { JsonEntityFileStorage, JsonFileDataProvider } from './JsonEntityFileStorage';
3
3
  export { SseSubscriptionServer } from '../SseSubscriptionServer';
4
+ export { DataProviderLiveQueryStorage } from '../live-query/data-provider-live-query-storage';
package/server/core.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SseSubscriptionServer = exports.JsonFileDataProvider = exports.JsonEntityFileStorage = exports.createRemultServerCore = void 0;
3
+ exports.DataProviderLiveQueryStorage = exports.SseSubscriptionServer = exports.JsonFileDataProvider = exports.JsonEntityFileStorage = exports.createRemultServerCore = void 0;
4
4
  var expressBridge_1 = require("./expressBridge");
5
5
  Object.defineProperty(exports, "createRemultServerCore", { enumerable: true, get: function () { return expressBridge_1.createRemultServerCore; } });
6
6
  var JsonEntityFileStorage_1 = require("./JsonEntityFileStorage");
@@ -8,3 +8,5 @@ Object.defineProperty(exports, "JsonEntityFileStorage", { enumerable: true, get:
8
8
  Object.defineProperty(exports, "JsonFileDataProvider", { enumerable: true, get: function () { return JsonEntityFileStorage_1.JsonFileDataProvider; } });
9
9
  var SseSubscriptionServer_1 = require("../SseSubscriptionServer");
10
10
  Object.defineProperty(exports, "SseSubscriptionServer", { enumerable: true, get: function () { return SseSubscriptionServer_1.SseSubscriptionServer; } });
11
+ var data_provider_live_query_storage_1 = require("../live-query/data-provider-live-query-storage");
12
+ Object.defineProperty(exports, "DataProviderLiveQueryStorage", { enumerable: true, get: function () { return data_provider_live_query_storage_1.DataProviderLiveQueryStorage; } });
package/src/data-api.js CHANGED
@@ -27,21 +27,32 @@ var DataApi = /** @class */ (function () {
27
27
  };
28
28
  DataApi.prototype.httpPost = function (res, req, body, serializeRequest) {
29
29
  var _a, _b;
30
- var action = req === null || req === void 0 ? void 0 : req.get("__action");
31
- if (action === null || action === void 0 ? void 0 : action.startsWith(rest_data_provider_1.liveQueryAction))
32
- return this.liveQuery(res, req, undefined, serializeRequest, getLiveQueryChannel(action.substring(rest_data_provider_1.liveQueryAction.length), (_a = this.remult.user) === null || _a === void 0 ? void 0 : _a.id));
33
- switch (action) {
34
- case "get":
35
- return this.getArray(res, req, body);
36
- case "count":
37
- return this.count(res, req, body);
38
- case "endLiveQuery":
39
- this.remult.liveQueryStorage.remove(getLiveQueryChannel(body.id, (_b = this.remult.user) === null || _b === void 0 ? void 0 : _b.id));
40
- res.success("ok");
41
- return;
42
- default:
43
- return this.post(res, body);
44
- }
30
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
31
+ var action, _c;
32
+ return tslib_1.__generator(this, function (_d) {
33
+ switch (_d.label) {
34
+ case 0:
35
+ action = req === null || req === void 0 ? void 0 : req.get("__action");
36
+ if (action === null || action === void 0 ? void 0 : action.startsWith(rest_data_provider_1.liveQueryAction))
37
+ return [2 /*return*/, this.liveQuery(res, req, undefined, serializeRequest, getLiveQueryChannel(action.substring(rest_data_provider_1.liveQueryAction.length), (_a = this.remult.user) === null || _a === void 0 ? void 0 : _a.id))];
38
+ _c = action;
39
+ switch (_c) {
40
+ case "get": return [3 /*break*/, 1];
41
+ case "count": return [3 /*break*/, 2];
42
+ case "endLiveQuery": return [3 /*break*/, 3];
43
+ }
44
+ return [3 /*break*/, 5];
45
+ case 1: return [2 /*return*/, this.getArray(res, req, body)];
46
+ case 2: return [2 /*return*/, this.count(res, req, body)];
47
+ case 3: return [4 /*yield*/, this.remult.liveQueryStorage.remove(getLiveQueryChannel(body.id, (_b = this.remult.user) === null || _b === void 0 ? void 0 : _b.id))];
48
+ case 4:
49
+ _d.sent();
50
+ res.success("ok");
51
+ return [2 /*return*/];
52
+ case 5: return [2 /*return*/, this.post(res, body)];
53
+ }
54
+ });
55
+ });
45
56
  };
46
57
  DataApi.prototype.get = function (response, id) {
47
58
  return tslib_1.__awaiter(this, void 0, void 0, function () {
@@ -210,7 +221,7 @@ var DataApi = /** @class */ (function () {
210
221
  }
211
222
  _a.label = 1;
212
223
  case 1:
213
- _a.trys.push([1, 3, , 4]);
224
+ _a.trys.push([1, 4, , 5]);
214
225
  return [4 /*yield*/, this.getArrayImpl(response, request, filterBody)];
215
226
  case 2:
216
227
  r = _a.sent();
@@ -219,21 +230,23 @@ var DataApi = /** @class */ (function () {
219
230
  findOptionsJson: rest_data_provider_1.findOptionsToJson(r.findOptions, this.repository.metadata),
220
231
  lastIds: r.r.map(function (y) { return getId_1.getId(_this.repository.metadata, y); })
221
232
  };
222
- this.remult.liveQueryStorage.add({
223
- entityKey: this.repository.metadata.key,
224
- id: queryChannel,
225
- data: data
226
- });
227
- response.success(r.r);
228
- return [3 /*break*/, 4];
233
+ return [4 /*yield*/, this.remult.liveQueryStorage.add({
234
+ entityKey: this.repository.metadata.key,
235
+ id: queryChannel,
236
+ data: data
237
+ })];
229
238
  case 3:
239
+ _a.sent();
240
+ response.success(r.r);
241
+ return [3 /*break*/, 5];
242
+ case 4:
230
243
  err_3 = _a.sent();
231
244
  if (err_3.isForbiddenError)
232
245
  response.forbidden();
233
246
  else
234
247
  response.error(err_3);
235
- return [3 /*break*/, 4];
236
- case 4: return [2 /*return*/];
248
+ return [3 /*break*/, 5];
249
+ case 5: return [2 /*return*/];
237
250
  }
238
251
  });
239
252
  });
@@ -2,8 +2,8 @@ export interface SubscriptionServer {
2
2
  publishMessage<T>(channel: string, message: T): Promise<void>;
3
3
  }
4
4
  export interface LiveQueryStorage {
5
- add(query: StoredQuery): void;
6
- remove(queryId: string): void;
5
+ add(query: StoredQuery): Promise<void>;
6
+ remove(queryId: string): Promise<void>;
7
7
  forEach(entityKey: string, callback: (args: {
8
8
  query: StoredQuery;
9
9
  setData(data: any): Promise<void>;
@@ -18,9 +18,9 @@ export declare class InMemoryLiveQueryStorage implements LiveQueryStorage {
18
18
  lastUsed: string;
19
19
  })[];
20
20
  constructor();
21
- add(query: StoredQuery): void;
21
+ add(query: StoredQuery): Promise<void>;
22
22
  removeCountForTesting: number;
23
- remove(id: any): void;
23
+ remove(id: any): Promise<void>;
24
24
  forEach(entityKey: string, handle: (args: {
25
25
  query: StoredQuery;
26
26
  setData(data: any): Promise<void>;
@@ -172,13 +172,23 @@ var InMemoryLiveQueryStorage = /** @class */ (function () {
172
172
  });
173
173
  };
174
174
  InMemoryLiveQueryStorage.prototype.add = function (query) {
175
- this.queries.push(tslib_1.__assign(tslib_1.__assign({}, query), { lastUsed: new Date().toISOString() }));
176
- this.debug();
175
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
176
+ return tslib_1.__generator(this, function (_a) {
177
+ this.queries.push(tslib_1.__assign(tslib_1.__assign({}, query), { lastUsed: new Date().toISOString() }));
178
+ this.debug();
179
+ return [2 /*return*/];
180
+ });
181
+ });
177
182
  };
178
183
  InMemoryLiveQueryStorage.prototype.remove = function (id) {
179
- this.queries = this.queries.filter(function (q) { return q.id !== id; });
180
- this.removeCountForTesting++;
181
- this.debug();
184
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
185
+ return tslib_1.__generator(this, function (_a) {
186
+ this.queries = this.queries.filter(function (q) { return q.id !== id; });
187
+ this.removeCountForTesting++;
188
+ this.debug();
189
+ return [2 /*return*/];
190
+ });
191
+ });
182
192
  };
183
193
  InMemoryLiveQueryStorage.prototype.forEach = function (entityKey, handle) {
184
194
  return tslib_1.__awaiter(this, void 0, void 0, function () {
@@ -22,6 +22,8 @@ var validators_1 = require("../validators");
22
22
  var models_1 = require("../tests/testModel/models");
23
23
  var id_entity_1 = require("../id-entity");
24
24
  var DecoratorReplacer_1 = require("../remult3/DecoratorReplacer");
25
+ var data_provider_live_query_storage_1 = require("../../live-query/data-provider-live-query-storage");
26
+ var uuid_1 = require("uuid");
25
27
  db_tests_setup_1.testAll("what", function (_a) {
26
28
  var remult = _a.remult, createEntity = _a.createEntity;
27
29
  return tslib_1.__awaiter(void 0, void 0, void 0, function () {
@@ -1720,3 +1722,38 @@ db_tests_setup_1.testAll("test date", function (_a) {
1720
1722
  });
1721
1723
  });
1722
1724
  }, false);
1725
+ db_tests_setup_1.testAll("test live query storage", function (_a) {
1726
+ var db = _a.db, remult = _a.remult;
1727
+ return tslib_1.__awaiter(void 0, void 0, void 0, function () {
1728
+ var x, id, _b;
1729
+ return tslib_1.__generator(this, function (_c) {
1730
+ switch (_c.label) {
1731
+ case 0:
1732
+ x = new data_provider_live_query_storage_1.DataProviderLiveQueryStorage(db);
1733
+ if (!db.ensureSchema) return [3 /*break*/, 2];
1734
+ return [4 /*yield*/, x.ensureSchema(remult)];
1735
+ case 1:
1736
+ _c.sent();
1737
+ _c.label = 2;
1738
+ case 2:
1739
+ id = uuid_1.v4();
1740
+ return [4 /*yield*/, x.add({ id: id, entityKey: 'x', data: "noam" })];
1741
+ case 3:
1742
+ _c.sent();
1743
+ return [4 /*yield*/, x.forEach("x", function (args) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
1744
+ return tslib_1.__generator(this, function (_a) {
1745
+ expect(args.query.data).toBe("noam");
1746
+ return [2 /*return*/];
1747
+ });
1748
+ }); })];
1749
+ case 4:
1750
+ _c.sent();
1751
+ _b = expect;
1752
+ return [4 /*yield*/, x.keepAliveAndReturnUnknownQueryIds([id])];
1753
+ case 5:
1754
+ _b.apply(void 0, [(_c.sent())]).toEqual([]);
1755
+ return [2 /*return*/];
1756
+ }
1757
+ });
1758
+ });
1759
+ });