remult 0.20.0-exp.9 → 0.20.0
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/graphql.d.ts +2 -2
- package/esm/graphql.js +1 -0
- package/esm/postgres/postgres-data-provider.d.ts +5 -0
- package/esm/postgres/postgres-data-provider.js +4 -0
- package/esm/remult-express.d.ts +5 -2
- package/esm/remult-express.js +2 -2
- package/esm/remult-fastify.d.ts +5 -2
- package/esm/remult-fastify.js +7 -3
- package/esm/remult-fresh.d.ts +2 -7
- package/esm/remult-fresh.js +2 -12
- package/esm/remult-next.d.ts +16 -2
- package/esm/remult-next.js +92 -7
- package/esm/remult-sveltekit.d.ts +3 -2
- package/esm/remult-sveltekit.js +3 -15
- package/esm/server/core.d.ts +1 -1
- package/esm/server/expressBridge.d.ts +11 -9
- package/esm/server/expressBridge.js +27 -23
- package/esm/server/index.d.ts +1 -1
- package/esm/server/index.js +1 -1
- package/esm/src/buildRestDataProvider.js +4 -2
- package/esm/src/data-api.d.ts +3 -3
- package/esm/src/data-api.js +6 -6
- package/esm/src/data-providers/sql-database.js +1 -0
- package/graphql.d.ts +2 -2
- package/graphql.js +1 -0
- package/package.json +1 -1
- package/postgres/postgres-data-provider.d.ts +5 -0
- package/postgres/postgres-data-provider.js +11 -2
- package/remult-express.d.ts +5 -2
- package/remult-express.js +5 -2
- package/remult-fastify.d.ts +5 -2
- package/remult-fastify.js +9 -3
- package/remult-fresh.d.ts +2 -7
- package/remult-fresh.js +7 -24
- package/remult-next.d.ts +16 -2
- package/remult-next.js +134 -38
- package/remult-sveltekit.d.ts +3 -2
- package/remult-sveltekit.js +7 -32
- package/server/core.d.ts +1 -1
- package/server/expressBridge.d.ts +11 -9
- package/server/expressBridge.js +111 -70
- package/server/index.d.ts +1 -1
- package/server/index.js +5 -1
- package/src/buildRestDataProvider.js +15 -11
- package/src/data-api.d.ts +3 -3
- package/src/data-api.js +6 -6
- package/src/data-providers/sql-database.js +1 -0
package/esm/graphql.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function remultGraphql(api:
|
|
1
|
+
import { RemultExpressServer } from "./remult-express";
|
|
2
|
+
export declare function remultGraphql(api: RemultExpressServer): {
|
|
3
3
|
rootValue: {};
|
|
4
4
|
schema: string;
|
|
5
5
|
};
|
package/esm/graphql.js
CHANGED
|
@@ -79,6 +79,7 @@ export function remultGraphql(api) {
|
|
|
79
79
|
query += q;
|
|
80
80
|
root[key] = async ({ options, filter }, req, a) => {
|
|
81
81
|
return new Promise(async (res, error) => {
|
|
82
|
+
//TODO - consider this with remult usage
|
|
82
83
|
api.withRemult(req, undefined, async () => {
|
|
83
84
|
let remult = await api.getRemult(req);
|
|
84
85
|
let repo = remult.repo(e);
|
|
@@ -28,4 +28,9 @@ export declare function createPostgresConnection(options?: {
|
|
|
28
28
|
sslInDev?: boolean;
|
|
29
29
|
configuration?: "heroku" | PoolConfig;
|
|
30
30
|
}): Promise<SqlDatabase>;
|
|
31
|
+
export declare function createPostgresDataProvider(options?: {
|
|
32
|
+
connectionString?: string;
|
|
33
|
+
sslInDev?: boolean;
|
|
34
|
+
configuration?: "heroku" | PoolConfig;
|
|
35
|
+
}): Promise<SqlDatabase>;
|
|
31
36
|
export declare function preparePostgresQueueStorage(sql: SqlDatabase): Promise<import("../server/expressBridge").EntityQueueStorage>;
|
|
@@ -37,6 +37,7 @@ export class PostgresDataProvider {
|
|
|
37
37
|
entityIsUsedForTheFirstTime: this.entityIsUsedForTheFirstTime,
|
|
38
38
|
transaction: () => { throw "nested transactions not allowed"; },
|
|
39
39
|
getLimitSqlSyntax: this.getLimitSqlSyntax,
|
|
40
|
+
supportsJsonColumnType: this.supportsJsonColumnType,
|
|
40
41
|
//@ts-ignore
|
|
41
42
|
pool: client
|
|
42
43
|
});
|
|
@@ -74,6 +75,9 @@ class PostgresBridgeToSQLQueryResult {
|
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
export async function createPostgresConnection(options) {
|
|
78
|
+
return createPostgresDataProvider(options);
|
|
79
|
+
}
|
|
80
|
+
export async function createPostgresDataProvider(options) {
|
|
77
81
|
if (!options)
|
|
78
82
|
options = {};
|
|
79
83
|
let config = {};
|
package/esm/remult-express.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import * as express from 'express';
|
|
2
|
-
import {
|
|
2
|
+
import { RemultServerCore, RemultServerOptions } from './server/expressBridge';
|
|
3
3
|
export declare function remultExpress(options?: RemultServerOptions<express.Request> & {
|
|
4
4
|
bodyParser?: boolean;
|
|
5
5
|
bodySizeLimit?: string;
|
|
6
|
-
}):
|
|
6
|
+
}): RemultExpressServer;
|
|
7
|
+
export declare type RemultExpressServer = express.RequestHandler & RemultServerCore<express.Request> & {
|
|
8
|
+
withRemult: (req: express.Request, res: express.Response, next: VoidFunction) => void;
|
|
9
|
+
};
|
package/esm/remult-express.js
CHANGED
|
@@ -13,13 +13,13 @@ export function remultExpress(options) {
|
|
|
13
13
|
app.use(express.urlencoded({ extended: true, limit: options.bodySizeLimit }));
|
|
14
14
|
}
|
|
15
15
|
const server = createRemultServer(options, {
|
|
16
|
-
|
|
16
|
+
buildGenericRequestInfo: req => req,
|
|
17
|
+
getRequestBody: async (req) => req.body
|
|
17
18
|
});
|
|
18
19
|
server.registerRouter(app);
|
|
19
20
|
return Object.assign(app, {
|
|
20
21
|
getRemult: (req) => server.getRemult(req),
|
|
21
22
|
openApiDoc: (options) => server.openApiDoc(options),
|
|
22
|
-
registerRouter: x => server.registerRouter(x),
|
|
23
23
|
withRemult: (...args) => server.withRemult(...args)
|
|
24
24
|
});
|
|
25
25
|
}
|
package/esm/remult-fastify.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import type { FastifyPluginCallback, FastifyRequest } from 'fastify';
|
|
2
|
-
import {
|
|
3
|
-
export declare function remultFastify(options: RemultServerOptions<FastifyRequest>):
|
|
2
|
+
import { RemultServerOptions, RemultServerCore } from './server/expressBridge';
|
|
3
|
+
export declare function remultFastify(options: RemultServerOptions<FastifyRequest>): RemultFastifyServer;
|
|
4
|
+
export declare type RemultFastifyServer = FastifyPluginCallback & RemultServerCore<FastifyRequest> & {
|
|
5
|
+
withRemult<T>(req: FastifyRequest, what: () => Promise<T>): Promise<T>;
|
|
6
|
+
};
|
package/esm/remult-fastify.js
CHANGED
|
@@ -30,7 +30,8 @@ export function remultFastify(options) {
|
|
|
30
30
|
return response;
|
|
31
31
|
}
|
|
32
32
|
const api = createRemultServer(options, {
|
|
33
|
-
|
|
33
|
+
buildGenericRequestInfo: req => req,
|
|
34
|
+
getRequestBody: async (req) => req.body
|
|
34
35
|
});
|
|
35
36
|
const pluginFunction = async (instance, op) => {
|
|
36
37
|
//@ts-ignore
|
|
@@ -60,7 +61,10 @@ export function remultFastify(options) {
|
|
|
60
61
|
return Object.assign(pluginFunction, {
|
|
61
62
|
getRemult: x => api.getRemult(x),
|
|
62
63
|
openApiDoc: x => api.openApiDoc(x),
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
withRemult: (req, what) => new Promise((resolve) => {
|
|
65
|
+
return api.withRemult(req, undefined, () => {
|
|
66
|
+
what().then(resolve);
|
|
67
|
+
});
|
|
68
|
+
})
|
|
65
69
|
});
|
|
66
70
|
}
|
package/esm/remult-fresh.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import { RemultServerOptions } from "./server/expressBridge";
|
|
2
|
-
import { Remult } from "./src/context";
|
|
1
|
+
import { RemultServerOptions, RemultServerCore } from "./server/expressBridge";
|
|
3
2
|
export declare function remultFresh(options: RemultServerOptions<FreshRequest>, response: FreshResponse): RemultFresh;
|
|
4
|
-
export interface RemultFresh {
|
|
5
|
-
getRemult(req: FreshRequest): Promise<Remult>;
|
|
6
|
-
openApiDoc(options: {
|
|
7
|
-
title: string;
|
|
8
|
-
}): any;
|
|
3
|
+
export interface RemultFresh extends RemultServerCore<FreshRequest> {
|
|
9
4
|
handle(req: FreshRequest, ctx: FreshContext): Promise<any>;
|
|
10
5
|
}
|
|
11
6
|
export interface FreshRequest {
|
package/esm/remult-fresh.js
CHANGED
|
@@ -1,23 +1,13 @@
|
|
|
1
1
|
import { createRemultServerCore } from "./server/expressBridge";
|
|
2
2
|
export function remultFresh(options, response) {
|
|
3
3
|
const server = createRemultServerCore(options, {
|
|
4
|
-
|
|
4
|
+
buildGenericRequestInfo: r => r,
|
|
5
|
+
getRequestBody: req => req.json()
|
|
5
6
|
});
|
|
6
7
|
return {
|
|
7
8
|
getRemult: r => server.getRemult(r),
|
|
8
9
|
openApiDoc: x => server.openApiDoc(x),
|
|
9
10
|
handle: async (req, ctx) => {
|
|
10
|
-
const theReq = {
|
|
11
|
-
method: req.method,
|
|
12
|
-
url: req.url,
|
|
13
|
-
body: undefined
|
|
14
|
-
};
|
|
15
|
-
switch (req.method.toLocaleLowerCase()) {
|
|
16
|
-
case "put":
|
|
17
|
-
case "post":
|
|
18
|
-
theReq.body = await req.json();
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
11
|
let init = {};
|
|
22
12
|
const res = await server.handle(req);
|
|
23
13
|
if (res) {
|
package/esm/remult-next.d.ts
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { GetServerSideProps, NextApiRequest, PreviewData, NextApiHandler } from "next";
|
|
3
3
|
import type { ParsedUrlQuery } from "querystring";
|
|
4
|
-
import {
|
|
5
|
-
export declare function remultNext(options?: RemultServerOptions<NextApiRequest>):
|
|
4
|
+
import { RemultServerCore, RemultServerOptions } from "./server";
|
|
5
|
+
export declare function remultNext(options?: RemultServerOptions<NextApiRequest>): RemultNextServer;
|
|
6
|
+
export declare type RemultNextServer = RemultServerCore<NextApiRequest> & NextApiHandler & {
|
|
6
7
|
getServerSideProps<P extends {
|
|
7
8
|
[key: string]: any;
|
|
8
9
|
} = {
|
|
9
10
|
[key: string]: any;
|
|
10
11
|
}, Q extends ParsedUrlQuery = ParsedUrlQuery, D extends PreviewData = PreviewData>(getServerPropsFunction: GetServerSideProps<P, Q, D>): GetServerSideProps<P, Q, D>;
|
|
12
|
+
/** Creates a `next.js` handler with remult defined in the correct context
|
|
13
|
+
* @see
|
|
14
|
+
* https://remult.dev/tutorials/react-next/appendix-1-get-server-side-props.html#using-remult-in-a-next-js-api-handler
|
|
15
|
+
*/
|
|
16
|
+
handle<T>(handler: NextApiHandler<T>): NextApiHandler<T>;
|
|
17
|
+
};
|
|
18
|
+
export declare function remultNextApp(options?: RemultServerOptions<Request>): RemultNextAppServer;
|
|
19
|
+
export declare type RemultNextAppServer = RemultServerCore<Request> & {
|
|
20
|
+
GET: (req: Request) => Promise<Response>;
|
|
21
|
+
PUT: (req: Request) => Promise<Response>;
|
|
22
|
+
POST: (req: Request) => Promise<Response>;
|
|
23
|
+
DELETE: (req: Request) => Promise<Response>;
|
|
24
|
+
withRemult<T>(what: () => Promise<T>): Promise<T>;
|
|
11
25
|
};
|
package/esm/remult-next.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { createRemultServer } from "./server";
|
|
2
2
|
export function remultNext(options) {
|
|
3
3
|
let result = createRemultServer(options, {
|
|
4
|
-
|
|
4
|
+
buildGenericRequestInfo: req => req,
|
|
5
|
+
getRequestBody: async (req) => req.body
|
|
5
6
|
});
|
|
6
|
-
return Object.assign((req, res) => result.handle(req, res), result, {
|
|
7
|
-
getRemult: (
|
|
8
|
-
|
|
9
|
-
openApiDoc: (...args) => result.openApiDoc(...args),
|
|
10
|
-
registerRouter: (...args) => result.registerRouter(...args),
|
|
11
|
-
withRemult: (...args) => result.withRemult(...args),
|
|
7
|
+
return Object.assign((req, res) => result.handle(req, res).then(() => { }), result, {
|
|
8
|
+
getRemult: (req) => result.getRemult(req),
|
|
9
|
+
openApiDoc: (arg) => result.openApiDoc(arg),
|
|
12
10
|
}, {
|
|
13
11
|
getServerSideProps: (getServerPropsFunction) => {
|
|
14
12
|
return (context) => {
|
|
@@ -24,6 +22,93 @@ export function remultNext(options) {
|
|
|
24
22
|
});
|
|
25
23
|
});
|
|
26
24
|
};
|
|
25
|
+
},
|
|
26
|
+
handle: (handler) => {
|
|
27
|
+
return async (req, res) => {
|
|
28
|
+
await new Promise(async (resolve) => {
|
|
29
|
+
result.withRemult(req, res, async () => {
|
|
30
|
+
await handler(req, res);
|
|
31
|
+
resolve();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
};
|
|
27
35
|
}
|
|
28
36
|
});
|
|
29
37
|
}
|
|
38
|
+
const encoder = new TextEncoder();
|
|
39
|
+
export function remultNextApp(options) {
|
|
40
|
+
let result = createRemultServer(options, {
|
|
41
|
+
getRequestBody: req => req.json(),
|
|
42
|
+
buildGenericRequestInfo: (req) => ({
|
|
43
|
+
url: req.url,
|
|
44
|
+
method: req.method,
|
|
45
|
+
on: (e, do1) => {
|
|
46
|
+
if (e === "close") {
|
|
47
|
+
req["_tempOnClose"] = do1;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
});
|
|
52
|
+
const handler = async (req) => {
|
|
53
|
+
{
|
|
54
|
+
let sseResponse = undefined;
|
|
55
|
+
req["_tempOnClose"] = () => { };
|
|
56
|
+
const response = {
|
|
57
|
+
end: () => { },
|
|
58
|
+
json: () => { },
|
|
59
|
+
status: () => {
|
|
60
|
+
return response;
|
|
61
|
+
},
|
|
62
|
+
write: () => { },
|
|
63
|
+
writeHead: (status, headers) => {
|
|
64
|
+
if (status === 200 && headers) {
|
|
65
|
+
const contentType = headers["Content-Type"];
|
|
66
|
+
if (contentType === "text/event-stream") {
|
|
67
|
+
const messages = [];
|
|
68
|
+
response.write = (x) => messages.push(x);
|
|
69
|
+
const stream = new ReadableStream({
|
|
70
|
+
start: (controller) => {
|
|
71
|
+
for (const message of messages) {
|
|
72
|
+
controller.enqueue(encoder.encode(message));
|
|
73
|
+
}
|
|
74
|
+
response.write = (data) => {
|
|
75
|
+
controller.enqueue(encoder.encode(data));
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
cancel: () => {
|
|
79
|
+
response.write = () => { };
|
|
80
|
+
req["_tempOnClose"]();
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
sseResponse = new Response(stream, { headers });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
const responseFromRemultHandler = await result.handle(req, response);
|
|
89
|
+
if (sseResponse !== undefined) {
|
|
90
|
+
return sseResponse;
|
|
91
|
+
}
|
|
92
|
+
if (responseFromRemultHandler) {
|
|
93
|
+
return new Response(JSON.stringify(responseFromRemultHandler.data), {
|
|
94
|
+
status: responseFromRemultHandler.statusCode,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
return {
|
|
100
|
+
getRemult: (req) => result.getRemult(req),
|
|
101
|
+
openApiDoc: (options) => result.openApiDoc(options),
|
|
102
|
+
GET: handler,
|
|
103
|
+
POST: handler,
|
|
104
|
+
PUT: handler,
|
|
105
|
+
DELETE: handler,
|
|
106
|
+
withRemult: (what) => {
|
|
107
|
+
return new Promise((resolve) => {
|
|
108
|
+
return result.withRemult({}, undefined, () => {
|
|
109
|
+
what().then(resolve);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { RequestEvent, Handle } from '@sveltejs/kit';
|
|
2
|
-
import {
|
|
3
|
-
export declare function remultSveltekit(options?: RemultServerOptions<RequestEvent>):
|
|
2
|
+
import { RemultServerOptions, RemultServerCore } from './server';
|
|
3
|
+
export declare function remultSveltekit(options?: RemultServerOptions<RequestEvent>): RemultSveltekitServer;
|
|
4
|
+
export declare type RemultSveltekitServer = RemultServerCore<RequestEvent> & Handle;
|
package/esm/remult-sveltekit.js
CHANGED
|
@@ -1,28 +1,19 @@
|
|
|
1
1
|
import { createRemultServer } from './server';
|
|
2
2
|
export function remultSveltekit(options) {
|
|
3
3
|
let result = createRemultServer(options, {
|
|
4
|
-
|
|
4
|
+
buildGenericRequestInfo: event => ({
|
|
5
5
|
url: event.request.url,
|
|
6
6
|
method: event.request.method,
|
|
7
|
-
body: event.locals["_tempJson"],
|
|
8
7
|
on: (e, do1) => {
|
|
9
8
|
if (e === 'close') {
|
|
10
9
|
event.locals["_tempOnClose"] = do1;
|
|
11
10
|
}
|
|
12
11
|
}
|
|
13
|
-
})
|
|
12
|
+
}),
|
|
13
|
+
getRequestBody: event => event.request.json()
|
|
14
14
|
});
|
|
15
15
|
const handler = async ({ event, resolve }) => {
|
|
16
16
|
if (event.url.pathname.startsWith(options.rootPath)) {
|
|
17
|
-
let json = {};
|
|
18
|
-
try {
|
|
19
|
-
if (event.request.method == 'POST' || event.request.method == 'PUT') {
|
|
20
|
-
json = await event.request.json();
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
console.log(error);
|
|
25
|
-
}
|
|
26
17
|
let sseResponse = undefined;
|
|
27
18
|
event.locals["_tempOnClose"] = () => { };
|
|
28
19
|
const response = {
|
|
@@ -57,7 +48,6 @@ export function remultSveltekit(options) {
|
|
|
57
48
|
}
|
|
58
49
|
}
|
|
59
50
|
};
|
|
60
|
-
event.locals["_tempJson"] = json;
|
|
61
51
|
const responseFromRemultHandler = await result.handle(event, response);
|
|
62
52
|
if (sseResponse !== undefined) {
|
|
63
53
|
return sseResponse;
|
|
@@ -77,7 +67,5 @@ export function remultSveltekit(options) {
|
|
|
77
67
|
return Object.assign(handler, {
|
|
78
68
|
getRemult: (req) => result.getRemult(req),
|
|
79
69
|
openApiDoc: (options) => result.openApiDoc(options),
|
|
80
|
-
registerRouter: x => result.registerRouter(x),
|
|
81
|
-
withRemult: (...args) => result.withRemult(...args)
|
|
82
70
|
});
|
|
83
71
|
}
|
package/esm/server/core.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { queuedJobInfo, QueueStorage,
|
|
1
|
+
export { queuedJobInfo, QueueStorage, GenericRequestInfo, GenericRequestHandler, GenericResponse, GenericRouter, createRemultServerCore, RemultServerOptions, SpecificRoute, RemultServer } from './expressBridge';
|
|
2
2
|
export { JsonEntityFileStorage, JsonFileDataProvider } from './JsonEntityFileStorage';
|
|
3
3
|
export { SseSubscriptionServer } from '../SseSubscriptionServer';
|
|
4
4
|
export { DataProviderLiveQueryStorage } from '../live-query/data-provider-live-query-storage';
|
|
@@ -44,7 +44,7 @@ export interface RemultServerOptions<RequestType> {
|
|
|
44
44
|
/** Used to store the context relevant info for re running a live query */
|
|
45
45
|
contextSerializer?: {
|
|
46
46
|
serialize(remult: Remult): Promise<any>;
|
|
47
|
-
deserialize(json: any,
|
|
47
|
+
deserialize(json: any, options: InitRequestOptions): Promise<void>;
|
|
48
48
|
};
|
|
49
49
|
/** Storage to use for backend methods that use queue */
|
|
50
50
|
queueStorage?: QueueStorage;
|
|
@@ -54,20 +54,22 @@ export interface InitRequestOptions {
|
|
|
54
54
|
readonly remult: Remult;
|
|
55
55
|
}
|
|
56
56
|
export declare function createRemultServerCore<RequestType>(options: RemultServerOptions<RequestType>, serverCoreOptions: ServerCoreOptions<RequestType>): RemultServer<RequestType>;
|
|
57
|
-
export declare type GenericRequestHandler = (req:
|
|
57
|
+
export declare type GenericRequestHandler = (req: GenericRequestInfo, res: GenericResponse, next: VoidFunction) => void;
|
|
58
58
|
export interface ServerHandleResponse {
|
|
59
59
|
data?: any;
|
|
60
60
|
statusCode: number;
|
|
61
61
|
}
|
|
62
|
-
export interface RemultServer<RequestType> {
|
|
62
|
+
export interface RemultServer<RequestType> extends RemultServerCore<RequestType> {
|
|
63
|
+
withRemult(req: RequestType, res: GenericResponse, next: VoidFunction): any;
|
|
64
|
+
registerRouter(r: GenericRouter): void;
|
|
65
|
+
handle(req: RequestType, gRes?: GenericResponse): Promise<ServerHandleResponse | undefined>;
|
|
66
|
+
}
|
|
67
|
+
export interface RemultServerCore<RequestType> {
|
|
63
68
|
getRemult(req: RequestType): Promise<Remult>;
|
|
64
69
|
openApiDoc(options: {
|
|
65
70
|
title: string;
|
|
66
71
|
version?: string;
|
|
67
72
|
}): any;
|
|
68
|
-
registerRouter(r: GenericRouter): void;
|
|
69
|
-
handle(req: RequestType, gRes?: GenericResponse): Promise<ServerHandleResponse | undefined>;
|
|
70
|
-
withRemult(req: RequestType, res: GenericResponse, next: VoidFunction): any;
|
|
71
73
|
}
|
|
72
74
|
export declare type GenericRouter = {
|
|
73
75
|
route(path: string): SpecificRoute;
|
|
@@ -78,10 +80,9 @@ export declare type SpecificRoute = {
|
|
|
78
80
|
post(handler: GenericRequestHandler): SpecificRoute;
|
|
79
81
|
delete(handler: GenericRequestHandler): SpecificRoute;
|
|
80
82
|
};
|
|
81
|
-
export interface
|
|
83
|
+
export interface GenericRequestInfo {
|
|
82
84
|
url?: string;
|
|
83
85
|
method?: any;
|
|
84
|
-
body?: any;
|
|
85
86
|
query?: any;
|
|
86
87
|
params?: any;
|
|
87
88
|
}
|
|
@@ -129,5 +130,6 @@ export declare class JobsInQueueEntity extends IdEntity {
|
|
|
129
130
|
progress: number;
|
|
130
131
|
}
|
|
131
132
|
export interface ServerCoreOptions<RequestType> {
|
|
132
|
-
|
|
133
|
+
buildGenericRequestInfo(req: RequestType): GenericRequestInfo;
|
|
134
|
+
getRequestBody(req: RequestType): Promise<any>;
|
|
133
135
|
}
|
|
@@ -125,7 +125,15 @@ export class RemultServerImplementation {
|
|
|
125
125
|
await this.runWithRemult(async (remult) => {
|
|
126
126
|
remult.user = jsonContextData.user;
|
|
127
127
|
if (this.options.contextSerializer) {
|
|
128
|
-
await this.options.contextSerializer.deserialize(jsonContextData,
|
|
128
|
+
await this.options.contextSerializer.deserialize(jsonContextData.context, {
|
|
129
|
+
remult,
|
|
130
|
+
get liveQueryStorage() {
|
|
131
|
+
return remult.liveQueryStorage;
|
|
132
|
+
},
|
|
133
|
+
set liveQueryStorage(value) {
|
|
134
|
+
remult.liveQueryStorage = value;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
129
137
|
}
|
|
130
138
|
await what(remult.repo(e));
|
|
131
139
|
});
|
|
@@ -134,6 +142,9 @@ export class RemultServerImplementation {
|
|
|
134
142
|
}
|
|
135
143
|
throw new Error("Couldn't find entity " + entityKey);
|
|
136
144
|
};
|
|
145
|
+
this.withRemult = (req, res, next) => {
|
|
146
|
+
this.process(async () => { next(); })(req, res);
|
|
147
|
+
};
|
|
137
148
|
this.registeredRouter = false;
|
|
138
149
|
this.hasQueue = false;
|
|
139
150
|
/* internal */
|
|
@@ -144,9 +155,6 @@ export class RemultServerImplementation {
|
|
|
144
155
|
this.subscriptionServer = options.subscriptionServer;
|
|
145
156
|
}
|
|
146
157
|
;
|
|
147
|
-
withRemult(req, res, next) {
|
|
148
|
-
this.process(async () => { next(); })(req, res);
|
|
149
|
-
}
|
|
150
158
|
getRouteImpl() {
|
|
151
159
|
if (!this.routeImpl) {
|
|
152
160
|
this.routeImpl = new RouteImplementation(this.coreOptions);
|
|
@@ -196,15 +204,15 @@ export class RemultServerImplementation {
|
|
|
196
204
|
r.route(streamPath).get(this.process(async (remult, req, res, origReq, origRes) => {
|
|
197
205
|
remult.subscriptionServer.openHttpServerStream(origReq, origRes);
|
|
198
206
|
}));
|
|
199
|
-
r.route(streamPath + '/subscribe').post(this.process(async (remult, req, res,
|
|
200
|
-
remult.subscriptionServer.subscribeToChannel(origReq
|
|
207
|
+
r.route(streamPath + '/subscribe').post(this.process(async (remult, req, res, reqInfo, origRes, origReq) => {
|
|
208
|
+
const body = remult.subscriptionServer.subscribeToChannel(await this.coreOptions.getRequestBody(origReq), res, remult);
|
|
201
209
|
}));
|
|
202
|
-
r.route(streamPath + '/unsubscribe').post(this.process(async (remult, req, res,
|
|
203
|
-
remult.subscriptionServer.subscribeToChannel(origReq
|
|
210
|
+
r.route(streamPath + '/unsubscribe').post(this.process(async (remult, req, res, reqInfo, origRes, origReq) => {
|
|
211
|
+
remult.subscriptionServer.subscribeToChannel(await this.coreOptions.getRequestBody(origReq), res, remult, true);
|
|
204
212
|
}));
|
|
205
213
|
}
|
|
206
|
-
r.route(this.options.rootPath + '/' + liveQueryKeepAliveRoute).post(this.process(async (remult, req, res,
|
|
207
|
-
res.success(await remult.liveQueryStorage.keepAliveAndReturnUnknownQueryIds(origReq
|
|
214
|
+
r.route(this.options.rootPath + '/' + liveQueryKeepAliveRoute).post(this.process(async (remult, req, res, reqInfo, origRes, origReq) => {
|
|
215
|
+
res.success(await remult.liveQueryStorage.keepAliveAndReturnUnknownQueryIds(await this.coreOptions.getRequestBody(origReq)));
|
|
208
216
|
}));
|
|
209
217
|
}
|
|
210
218
|
this.options.entities.forEach(e => {
|
|
@@ -230,14 +238,14 @@ export class RemultServerImplementation {
|
|
|
230
238
|
if (this.options.logApiEndPoints)
|
|
231
239
|
console.info("[remult] " + myRoute);
|
|
232
240
|
r.route(myRoute)
|
|
233
|
-
.get(this.process((c, req, res, orig) => dataApiFactory(c).httpGet(res, req, () => this.serializeContext(c)))).put(this.process(async (c, req, res, orig) => dataApiFactory(c).put(res, '', orig
|
|
241
|
+
.get(this.process((c, req, res, orig) => dataApiFactory(c).httpGet(res, req, () => this.serializeContext(c)))).put(this.process(async (c, req, res, _, __, orig) => dataApiFactory(c).put(res, '', await this.coreOptions.getRequestBody(orig))))
|
|
234
242
|
.delete(this.process(async (c, req, res, orig) => dataApiFactory(c).delete(res, '')))
|
|
235
|
-
.post(this.process(async (c, req, res, orig) => dataApiFactory(c).httpPost(res, req, orig
|
|
243
|
+
.post(this.process(async (c, req, res, _, __, orig) => dataApiFactory(c).httpPost(res, req, await this.coreOptions.getRequestBody(orig), () => this.serializeContext(c))));
|
|
236
244
|
r.route(myRoute + '/:id')
|
|
237
245
|
//@ts-ignore
|
|
238
246
|
.get(this.process(async (c, req, res, orig) => dataApiFactory(c).get(res, orig.params.id)))
|
|
239
247
|
//@ts-ignore
|
|
240
|
-
.put(this.process(async (c, req, res, orig) => dataApiFactory(c).put(res,
|
|
248
|
+
.put(this.process(async (c, req, res, reqInfo, _, orig) => dataApiFactory(c).put(res, reqInfo.params.id, await this.coreOptions.getRequestBody(orig))))
|
|
241
249
|
//@ts-ignore
|
|
242
250
|
.delete(this.process(async (c, req, res, orig) => dataApiFactory(c).delete(res, orig.params.id)));
|
|
243
251
|
}
|
|
@@ -255,7 +263,7 @@ export class RemultServerImplementation {
|
|
|
255
263
|
}
|
|
256
264
|
process(what) {
|
|
257
265
|
return async (req, origRes) => {
|
|
258
|
-
const genReq = this.coreOptions.
|
|
266
|
+
const genReq = this.coreOptions.buildGenericRequestInfo(req);
|
|
259
267
|
if (!genReq.query) {
|
|
260
268
|
genReq.query = req["_tempQuery"];
|
|
261
269
|
}
|
|
@@ -264,10 +272,6 @@ export class RemultServerImplementation {
|
|
|
264
272
|
let myReq = new ExpressRequestBridgeToDataApiRequest(genReq);
|
|
265
273
|
let myRes = new ExpressResponseBridgeToDataApiResponse(origRes, req);
|
|
266
274
|
await this.runWithRemult(async (remult) => {
|
|
267
|
-
remult.liveQueryPublisher = new LiveQueryPublisher(() => remult.subscriptionServer, () => remult.liveQueryStorage, this.runWithSerializedJsonContextData);
|
|
268
|
-
remult.dataProvider = (await this.dataProvider);
|
|
269
|
-
remult.subscriptionServer = this.subscriptionServer;
|
|
270
|
-
remult.liveQueryStorage = this.liveQueryStorage;
|
|
271
275
|
if (req) {
|
|
272
276
|
let user;
|
|
273
277
|
if (this.options.getUser)
|
|
@@ -291,7 +295,7 @@ export class RemultServerImplementation {
|
|
|
291
295
|
});
|
|
292
296
|
}
|
|
293
297
|
}
|
|
294
|
-
await what(remult, myReq, myRes, genReq, origRes);
|
|
298
|
+
await what(remult, myReq, myRes, genReq, origRes, req);
|
|
295
299
|
});
|
|
296
300
|
};
|
|
297
301
|
}
|
|
@@ -320,15 +324,15 @@ export class RemultServerImplementation {
|
|
|
320
324
|
this.hasQueue = true;
|
|
321
325
|
this.queue.mapQueuedAction(myUrl, what);
|
|
322
326
|
}
|
|
323
|
-
r.route(myUrl).post(this.process(async (remult, req, res, orig) => {
|
|
327
|
+
r.route(myUrl).post(this.process(async (remult, req, res, _, __, orig) => {
|
|
324
328
|
if (queue) {
|
|
325
329
|
let r = {
|
|
326
|
-
queuedJobId: await this.queue.submitJob(myUrl, remult, orig
|
|
330
|
+
queuedJobId: await this.queue.submitJob(myUrl, remult, await this.coreOptions.getRequestBody(orig))
|
|
327
331
|
};
|
|
328
332
|
res.success(r);
|
|
329
333
|
}
|
|
330
334
|
else
|
|
331
|
-
return what(orig
|
|
335
|
+
return what(await this.coreOptions.getRequestBody(orig), remult, res);
|
|
332
336
|
}));
|
|
333
337
|
});
|
|
334
338
|
}
|
|
@@ -857,7 +861,7 @@ class RouteImplementation {
|
|
|
857
861
|
});
|
|
858
862
|
}
|
|
859
863
|
middleware(origReq, res, next) {
|
|
860
|
-
const req = this.coreOptions.
|
|
864
|
+
const req = this.coreOptions.buildGenericRequestInfo(origReq);
|
|
861
865
|
let theUrl = req.url;
|
|
862
866
|
if (theUrl.startsWith('/')) //next sends a partial url '/api/tasks' and not the full url
|
|
863
867
|
theUrl = 'http://stam' + theUrl;
|
package/esm/server/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RemultServer, RemultServerOptions, ServerCoreOptions } from './expressBridge';
|
|
2
|
-
export { queuedJobInfo, QueueStorage,
|
|
2
|
+
export { queuedJobInfo, QueueStorage, GenericRequestInfo, GenericRequestHandler, RemultServerCore, GenericResponse, GenericRouter, RemultServerOptions, SpecificRoute, RemultServer, InitRequestOptions } from './expressBridge';
|
|
3
3
|
export { JsonEntityFileStorage, JsonFileDataProvider } from './JsonEntityFileStorage';
|
|
4
4
|
export { DataProviderLiveQueryStorage } from '../live-query/data-provider-live-query-storage';
|
|
5
5
|
export { SseSubscriptionServer } from '../SseSubscriptionServer';
|
package/esm/server/index.js
CHANGED
|
@@ -5,5 +5,5 @@ export { DataProviderLiveQueryStorage } from '../live-query/data-provider-live-q
|
|
|
5
5
|
export { SseSubscriptionServer } from '../SseSubscriptionServer';
|
|
6
6
|
export function createRemultServer(options, serverCoreOptions) {
|
|
7
7
|
initAsyncHooks();
|
|
8
|
-
return createRemultServerCore(options, serverCoreOptions || {
|
|
8
|
+
return createRemultServerCore(options, serverCoreOptions || { buildGenericRequestInfo: req => req, getRequestBody: async (req) => req.body });
|
|
9
9
|
}
|
|
@@ -39,15 +39,17 @@ export class HttpProviderBridgeToRestDataProviderHttpProvider {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
export async function retry(what) {
|
|
42
|
+
let i = 0;
|
|
42
43
|
while (true) {
|
|
43
44
|
try {
|
|
44
45
|
return await what();
|
|
45
46
|
}
|
|
46
47
|
catch (err) {
|
|
47
|
-
if (err.message?.startsWith("Error occurred while trying to proxy") ||
|
|
48
|
+
if ((err.message?.startsWith("Error occurred while trying to proxy") ||
|
|
48
49
|
err.message?.startsWith("Error occured while trying to proxy") ||
|
|
49
50
|
err.message?.includes("http proxy error") ||
|
|
50
|
-
err.message?.startsWith("Gateway Timeout")
|
|
51
|
+
err.message?.startsWith("Gateway Timeout") ||
|
|
52
|
+
err.status == 500) && i++ < 10) {
|
|
51
53
|
await new Promise((res, req) => {
|
|
52
54
|
setTimeout(() => {
|
|
53
55
|
res({});
|
package/esm/src/data-api.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ export declare class DataApi<T = any> {
|
|
|
5
5
|
private repository;
|
|
6
6
|
private remult;
|
|
7
7
|
constructor(repository: Repository<T>, remult: Remult);
|
|
8
|
-
httpGet(res: DataApiResponse, req: DataApiRequest,
|
|
9
|
-
httpPost(res: DataApiResponse, req: DataApiRequest, body: any,
|
|
8
|
+
httpGet(res: DataApiResponse, req: DataApiRequest, serializeContext: () => Promise<any>): Promise<void>;
|
|
9
|
+
httpPost(res: DataApiResponse, req: DataApiRequest, body: any, serializeContext: () => Promise<any>): Promise<void>;
|
|
10
10
|
static defaultGetLimit: number;
|
|
11
11
|
get(response: DataApiResponse, id: any): Promise<void>;
|
|
12
12
|
count(response: DataApiResponse, request: DataApiRequest, filterBody?: any): Promise<void>;
|
|
@@ -15,7 +15,7 @@ export declare class DataApi<T = any> {
|
|
|
15
15
|
findOptions: FindOptions<T>;
|
|
16
16
|
}>;
|
|
17
17
|
getArray(response: DataApiResponse, request: DataApiRequest, filterBody?: any): Promise<void>;
|
|
18
|
-
liveQuery(response: DataApiResponse, request: DataApiRequest, filterBody: any,
|
|
18
|
+
liveQuery(response: DataApiResponse, request: DataApiRequest, filterBody: any, serializeContext: () => Promise<any>, queryChannel: string): Promise<void>;
|
|
19
19
|
private buildWhere;
|
|
20
20
|
private doOnId;
|
|
21
21
|
put(response: DataApiResponse, id: any, body: any): Promise<void>;
|