remult 3.3.17-next.0 → 3.3.17
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/SseSubscriptionServer.d.ts +2 -3
- package/SseSubscriptionServer.js +0 -40
- package/esm/SseSubscriptionServer.js +0 -13
- package/esm/server/remult-api-server.js +14 -15
- package/esm/src/remult3/RepositoryImplementation.js +4 -2
- package/internals.d.ts +0 -2
- package/package.json +1 -1
- package/server/remult-api-server.d.ts +0 -17
- package/server/remult-api-server.js +39 -19
- package/src/remult3/RepositoryImplementation.js +4 -2
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { GenericResponse } from './server/index.js';
|
|
2
|
-
import type { SubscriptionServerRouteApi, SubscriptionServerWithRoutes } from './server/remult-api-server.js';
|
|
3
2
|
import type { Remult } from './src/context.js';
|
|
4
|
-
|
|
3
|
+
import type { SubscriptionServer } from './src/live-query/SubscriptionServer.js';
|
|
4
|
+
export declare class SseSubscriptionServer implements SubscriptionServer {
|
|
5
5
|
private canUserConnectToChannel?;
|
|
6
|
-
initApiServer(api: SubscriptionServerRouteApi): void;
|
|
7
6
|
constructor(canUserConnectToChannel?: ((channel: string, remult: Remult) => boolean) | undefined);
|
|
8
7
|
publishMessage<T>(channel: string, message: any): Promise<void>;
|
|
9
8
|
}
|
package/SseSubscriptionServer.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.clientConnection = exports.SseSubscriptionServer = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var SseSubscriptionClient_js_1 = require("./src/live-query/SseSubscriptionClient.js");
|
|
6
|
-
var SubscriptionChannel_js_1 = require("./src/live-query/SubscriptionChannel.js");
|
|
7
6
|
var SseSubscriptionServer = /** @class */ (function () {
|
|
8
7
|
function SseSubscriptionServer(canUserConnectToChannel) {
|
|
9
8
|
this.canUserConnectToChannel = canUserConnectToChannel;
|
|
@@ -17,45 +16,6 @@ var SseSubscriptionServer = /** @class */ (function () {
|
|
|
17
16
|
this.canUserConnectToChannel = function () { return true; };
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
|
-
SseSubscriptionServer.prototype.initApiServer = function (api) {
|
|
21
|
-
var _this = this;
|
|
22
|
-
var streamPath = '/' + SubscriptionChannel_js_1.streamUrl;
|
|
23
|
-
api.addRoute(streamPath, 'get', function (_a) { return tslib_1.__awaiter(_this, [_a], void 0, function (_b) {
|
|
24
|
-
var req = _b.req, origRes = _b.origRes;
|
|
25
|
-
return tslib_1.__generator(this, function (_c) {
|
|
26
|
-
this.openHttpServerStream(req, origRes);
|
|
27
|
-
return [2 /*return*/];
|
|
28
|
-
});
|
|
29
|
-
}); });
|
|
30
|
-
api.addRoute(streamPath + '/subscribe', 'post', function (_a) { return tslib_1.__awaiter(_this, [_a], void 0, function (_b) {
|
|
31
|
-
var _c;
|
|
32
|
-
var remult = _b.remult, res = _b.res, getBody = _b.getBody;
|
|
33
|
-
return tslib_1.__generator(this, function (_d) {
|
|
34
|
-
switch (_d.label) {
|
|
35
|
-
case 0:
|
|
36
|
-
_c = this.subscribeToChannel;
|
|
37
|
-
return [4 /*yield*/, getBody()];
|
|
38
|
-
case 1:
|
|
39
|
-
_c.apply(this, [_d.sent(), res, remult]);
|
|
40
|
-
return [2 /*return*/];
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}); });
|
|
44
|
-
api.addRoute(streamPath + '/unsubscribe', 'post', function (_a) { return tslib_1.__awaiter(_this, [_a], void 0, function (_b) {
|
|
45
|
-
var _c;
|
|
46
|
-
var remult = _b.remult, res = _b.res, getBody = _b.getBody;
|
|
47
|
-
return tslib_1.__generator(this, function (_d) {
|
|
48
|
-
switch (_d.label) {
|
|
49
|
-
case 0:
|
|
50
|
-
_c = this.subscribeToChannel;
|
|
51
|
-
return [4 /*yield*/, getBody()];
|
|
52
|
-
case 1:
|
|
53
|
-
_c.apply(this, [_d.sent(), res, remult, true]);
|
|
54
|
-
return [2 /*return*/];
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}); });
|
|
58
|
-
};
|
|
59
19
|
//@internal
|
|
60
20
|
SseSubscriptionServer.prototype.subscribeToChannel = function (_a, res, remult, remove) {
|
|
61
21
|
var e_1, _b;
|
|
@@ -1,19 +1,6 @@
|
|
|
1
1
|
import { ConnectionNotFoundError } from './src/live-query/SseSubscriptionClient.js';
|
|
2
|
-
import { streamUrl } from './src/live-query/SubscriptionChannel.js';
|
|
3
2
|
export class SseSubscriptionServer {
|
|
4
3
|
canUserConnectToChannel;
|
|
5
|
-
initApiServer(api) {
|
|
6
|
-
const streamPath = '/' + streamUrl;
|
|
7
|
-
api.addRoute(streamPath, 'get', async ({ req, origRes }) => {
|
|
8
|
-
this.openHttpServerStream(req, origRes);
|
|
9
|
-
});
|
|
10
|
-
api.addRoute(streamPath + '/subscribe', 'post', async ({ remult, res, getBody }) => {
|
|
11
|
-
this.subscribeToChannel(await getBody(), res, remult);
|
|
12
|
-
});
|
|
13
|
-
api.addRoute(streamPath + '/unsubscribe', 'post', async ({ remult, res, getBody }) => {
|
|
14
|
-
this.subscribeToChannel(await getBody(), res, remult, true);
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
4
|
//@internal
|
|
18
5
|
subscribeToChannel({ channel, clientId }, res, remult, remove = false) {
|
|
19
6
|
for (const c of this.connections) {
|
|
@@ -2,7 +2,7 @@ import { __decorate, __metadata } from "tslib";
|
|
|
2
2
|
import { SseSubscriptionServer } from '../SseSubscriptionServer.js';
|
|
3
3
|
import { Remult, RemultAsyncLocalStorage, withRemult } from '../src/context.js';
|
|
4
4
|
import { DataApi, serializeError } from '../src/data-api.js';
|
|
5
|
-
import { liveQueryKeepAliveRoute } from '../src/live-query/SubscriptionChannel.js';
|
|
5
|
+
import { liveQueryKeepAliveRoute, streamUrl, } from '../src/live-query/SubscriptionChannel.js';
|
|
6
6
|
import { InMemoryLiveQueryStorage, LiveQueryPublisher, } from '../src/live-query/SubscriptionServer.js';
|
|
7
7
|
import { IdEntity } from '../src/remult3/IdEntity.js';
|
|
8
8
|
import { Fields } from '../src/remult3/Fields.js';
|
|
@@ -266,20 +266,19 @@ export class RemultServerImplementation {
|
|
|
266
266
|
r.route(this.options.rootPath + '/admin').get(admin());
|
|
267
267
|
}
|
|
268
268
|
r.route(this.options.rootPath + '/me').get(this.process(async (remult, req, res) => res.success(remult.user ?? null)));
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
});
|
|
269
|
+
if (this.options.subscriptionServer instanceof SseSubscriptionServer) {
|
|
270
|
+
const streamPath = this.options.rootPath + '/' + streamUrl;
|
|
271
|
+
r.route(streamPath).get(this.process(async (remult, req, res, origReq, origRes) => {
|
|
272
|
+
;
|
|
273
|
+
remult.subscriptionServer.openHttpServerStream(origReq, origRes);
|
|
274
|
+
}));
|
|
275
|
+
r.route(streamPath + '/subscribe').post(this.process(async (remult, _2, res, _, _1, origReq) => {
|
|
276
|
+
const body = remult.subscriptionServer.subscribeToChannel(await this.coreOptions.getRequestBody(origReq), res, remult);
|
|
277
|
+
}));
|
|
278
|
+
r.route(streamPath + '/unsubscribe').post(this.process(async (remult, req, res, reqInfo, origRes, origReq) => {
|
|
279
|
+
;
|
|
280
|
+
remult.subscriptionServer.subscribeToChannel(await this.coreOptions.getRequestBody(origReq), res, remult, true);
|
|
281
|
+
}));
|
|
283
282
|
}
|
|
284
283
|
r.route(this.options.rootPath + '/' + liveQueryKeepAliveRoute).post(this.process(async (remult, req, res, reqInfo, origRes, origReq) => {
|
|
285
284
|
res.success(await remult.liveQueryStorage.keepAliveAndReturnUnknownQueryIds(await this.coreOptions.getRequestBody(origReq)));
|
|
@@ -1698,8 +1698,10 @@ export class rowHelperImplementation extends rowHelperBase {
|
|
|
1698
1698
|
}
|
|
1699
1699
|
}
|
|
1700
1700
|
else if (!getRelationFieldInfo(col))
|
|
1701
|
-
if (data[col.key] === undefined)
|
|
1702
|
-
|
|
1701
|
+
if (data[col.key] === undefined) {
|
|
1702
|
+
if (!Reflect.deleteProperty(this.instance, col.key))
|
|
1703
|
+
this.instance[col.key] = undefined;
|
|
1704
|
+
}
|
|
1703
1705
|
else
|
|
1704
1706
|
this.instance[col.key] = data[col.key];
|
|
1705
1707
|
}
|
package/internals.d.ts
CHANGED
|
@@ -14,8 +14,6 @@ export declare const actionInfo: {
|
|
|
14
14
|
};
|
|
15
15
|
export { isOfType } from './src/isOfType.js';
|
|
16
16
|
export type { ClassType } from './classType.js';
|
|
17
|
-
export type { SubscriptionServerWithRoutes, SubscriptionServerRouteApi, SubscriptionServerRouteHandlerArgs, } from './server/remult-api-server.js';
|
|
18
|
-
export type { DataApiResponse } from './src/data-api.js';
|
|
19
17
|
export { flags } from './src/remult3/remult3.js';
|
|
20
18
|
export { DataProviderPromiseWrapper } from './src/data-interfaces.js';
|
|
21
19
|
export { pagedQueryResult } from './src/remult3/pagedQueryResult.js';
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ClassType } from '../classType.js';
|
|
2
2
|
import type { Allowed, UserInfo } from '../src/context.js';
|
|
3
3
|
import { Remult } from '../src/context.js';
|
|
4
|
-
import type { DataApiResponse } from '../src/data-api.js';
|
|
5
4
|
import type { DataProvider } from '../src/data-interfaces.js';
|
|
6
5
|
import type { LiveQueryStorage, SubscriptionServer } from '../src/live-query/SubscriptionServer.js';
|
|
7
6
|
import { IdEntity } from '../src/remult3/IdEntity.js';
|
|
@@ -168,22 +167,6 @@ export interface GenericResponse {
|
|
|
168
167
|
status(statusCode: number): GenericResponse;
|
|
169
168
|
end(): void;
|
|
170
169
|
}
|
|
171
|
-
/** A `SubscriptionServer` that also needs to serve http routes (for example SSE),
|
|
172
|
-
* can implement this interface to register them on the api server */
|
|
173
|
-
export interface SubscriptionServerWithRoutes extends SubscriptionServer {
|
|
174
|
-
initApiServer(api: SubscriptionServerRouteApi): void;
|
|
175
|
-
}
|
|
176
|
-
export interface SubscriptionServerRouteApi {
|
|
177
|
-
rootPath: string;
|
|
178
|
-
addRoute(relativePath: string, method: 'get' | 'post', handler: (args: SubscriptionServerRouteHandlerArgs) => Promise<void>): void;
|
|
179
|
-
}
|
|
180
|
-
export interface SubscriptionServerRouteHandlerArgs {
|
|
181
|
-
remult: Remult;
|
|
182
|
-
res: DataApiResponse;
|
|
183
|
-
req: GenericRequestInfo;
|
|
184
|
-
origRes: GenericResponse;
|
|
185
|
-
getBody(): Promise<any>;
|
|
186
|
-
}
|
|
187
170
|
export interface queuedJobInfo {
|
|
188
171
|
info: queuedJobInfoResponse;
|
|
189
172
|
userId: string;
|
|
@@ -441,25 +441,45 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
441
441
|
r.route(this.options.rootPath + '/me').get(this.process(function (remult, req, res) { return tslib_1.__awaiter(_this, void 0, void 0, function () { var _a; return tslib_1.__generator(this, function (_b) {
|
|
442
442
|
return [2 /*return*/, res.success((_a = remult.user) !== null && _a !== void 0 ? _a : null)];
|
|
443
443
|
}); }); }));
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
444
|
+
if (this.options.subscriptionServer instanceof SseSubscriptionServer_js_1.SseSubscriptionServer) {
|
|
445
|
+
var streamPath = this.options.rootPath + '/' + SubscriptionChannel_js_1.streamUrl;
|
|
446
|
+
r.route(streamPath).get(this.process(function (remult, req, res, origReq, origRes) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
447
|
+
return tslib_1.__generator(this, function (_a) {
|
|
448
|
+
;
|
|
449
|
+
remult.subscriptionServer.openHttpServerStream(origReq, origRes);
|
|
450
|
+
return [2 /*return*/];
|
|
451
|
+
});
|
|
452
|
+
}); }));
|
|
453
|
+
r.route(streamPath + '/subscribe').post(this.process(function (remult, _2, res, _, _1, origReq) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
454
|
+
var body, _a, _b;
|
|
455
|
+
return tslib_1.__generator(this, function (_c) {
|
|
456
|
+
switch (_c.label) {
|
|
457
|
+
case 0:
|
|
458
|
+
_b = (_a = remult.subscriptionServer).subscribeToChannel;
|
|
459
|
+
return [4 /*yield*/, this.coreOptions.getRequestBody(origReq)];
|
|
460
|
+
case 1:
|
|
461
|
+
body = _b.apply(_a, [_c.sent(), res,
|
|
462
|
+
remult]);
|
|
463
|
+
return [2 /*return*/];
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
}); }));
|
|
467
|
+
r.route(streamPath + '/unsubscribe').post(this.process(function (remult, req, res, reqInfo, origRes, origReq) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
468
|
+
var _a, _b;
|
|
469
|
+
return tslib_1.__generator(this, function (_c) {
|
|
470
|
+
switch (_c.label) {
|
|
471
|
+
case 0:
|
|
472
|
+
;
|
|
473
|
+
_b = (_a = remult.subscriptionServer).subscribeToChannel;
|
|
474
|
+
return [4 /*yield*/, this.coreOptions.getRequestBody(origReq)];
|
|
475
|
+
case 1:
|
|
476
|
+
_b.apply(_a, [_c.sent(), res,
|
|
477
|
+
remult,
|
|
478
|
+
true]);
|
|
479
|
+
return [2 /*return*/];
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
}); }));
|
|
463
483
|
}
|
|
464
484
|
r.route(this.options.rootPath + '/' + SubscriptionChannel_js_1.liveQueryKeepAliveRoute).post(this.process(function (remult, req, res, reqInfo, origRes, origReq) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
465
485
|
var _a, _b, _c, _d;
|
|
@@ -2856,8 +2856,10 @@ var rowHelperImplementation = /** @class */ (function (_super) {
|
|
|
2856
2856
|
case 6: return [3 /*break*/, 8];
|
|
2857
2857
|
case 7:
|
|
2858
2858
|
if (!(0, relationInfoMember_js_1.getRelationFieldInfo)(col))
|
|
2859
|
-
if (data[col.key] === undefined)
|
|
2860
|
-
|
|
2859
|
+
if (data[col.key] === undefined) {
|
|
2860
|
+
if (!Reflect.deleteProperty(this.instance, col.key))
|
|
2861
|
+
this.instance[col.key] = undefined;
|
|
2862
|
+
}
|
|
2861
2863
|
else
|
|
2862
2864
|
this.instance[col.key] = data[col.key];
|
|
2863
2865
|
_d.label = 8;
|