remult 3.0.6-next.0 → 3.0.6-next.1
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/remult-express.js +4 -1
- package/esm/remult-fastify.js +9 -1
- package/esm/remult-fresh.js +5 -1
- package/esm/remult-hapi.js +7 -6
- package/esm/remult-hono.js +16 -14
- package/esm/remult-next.js +14 -8
- package/esm/remult-nuxt.js +7 -4
- package/esm/remult-solid-start.js +9 -6
- package/esm/remult-sveltekit.js +11 -8
- package/esm/server/index.js +4 -1
- package/esm/server/module.js +1 -1
- package/esm/server/remult-api-server.js +14 -2
- package/esm/server/test-api-data-provider.js +4 -1
- package/esm/src/context.js +9 -1
- package/package.json +1 -1
- package/remult-express.js +4 -1
- package/remult-fastify.js +6 -1
- package/remult-fresh.js +5 -1
- package/remult-hapi.js +4 -7
- package/remult-hono.js +16 -14
- package/remult-next.js +14 -8
- package/remult-nuxt.js +7 -4
- package/remult-solid-start.js +9 -6
- package/remult-sveltekit.js +11 -8
- package/server/core.d.ts +1 -1
- package/server/index.js +4 -1
- package/server/module.js +1 -1
- package/server/remult-api-server.d.ts +24 -11
- package/server/remult-api-server.js +23 -11
- package/server/test-api-data-provider.js +4 -1
- package/src/context.d.ts +15 -2
- package/src/context.js +9 -1
package/esm/remult-express.js
CHANGED
|
@@ -13,7 +13,10 @@ export function remultApi(options) {
|
|
|
13
13
|
app.use(express.urlencoded({ extended: true, limit: options.bodySizeLimit }));
|
|
14
14
|
}
|
|
15
15
|
const server = createRemultServer(options, {
|
|
16
|
-
buildGenericRequestInfo: (req) =>
|
|
16
|
+
buildGenericRequestInfo: (req) => ({
|
|
17
|
+
internal: { ...req, on: req.on },
|
|
18
|
+
public: { headers: new Headers(req.headers) },
|
|
19
|
+
}),
|
|
17
20
|
getRequestBody: async (req) => req.body,
|
|
18
21
|
});
|
|
19
22
|
server.registerRouter(app);
|
package/esm/remult-fastify.js
CHANGED
|
@@ -33,7 +33,15 @@ export function remultApi(options) {
|
|
|
33
33
|
return response;
|
|
34
34
|
}
|
|
35
35
|
const api = createRemultServer(options, {
|
|
36
|
-
buildGenericRequestInfo: (req) =>
|
|
36
|
+
buildGenericRequestInfo: (req) => ({
|
|
37
|
+
internal: {
|
|
38
|
+
...req,
|
|
39
|
+
url: req.originalUrl,
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
on: req.on,
|
|
42
|
+
},
|
|
43
|
+
public: { headers: new Headers(req.headers) },
|
|
44
|
+
}),
|
|
37
45
|
getRequestBody: async (req) => req.body,
|
|
38
46
|
});
|
|
39
47
|
const pluginFunction = async (instance, op) => {
|
package/esm/remult-fresh.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { createRemultServerCore } from './server/remult-api-server.js';
|
|
2
2
|
export function remultApi(options, response) {
|
|
3
3
|
const server = createRemultServerCore(options, {
|
|
4
|
-
buildGenericRequestInfo: (r) =>
|
|
4
|
+
buildGenericRequestInfo: (r) => ({
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
internal: { ...r, on: r.on },
|
|
7
|
+
public: { headers: r.headers },
|
|
8
|
+
}),
|
|
5
9
|
getRequestBody: (req) => req.json(),
|
|
6
10
|
});
|
|
7
11
|
return {
|
package/esm/remult-hapi.js
CHANGED
|
@@ -3,13 +3,14 @@ import { PassThrough } from 'stream';
|
|
|
3
3
|
export function remultApi(options) {
|
|
4
4
|
const api = createRemultServer(options, {
|
|
5
5
|
buildGenericRequestInfo: (req) => ({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
internal: {
|
|
7
|
+
...req,
|
|
8
|
+
url: req.url.pathname,
|
|
9
|
+
on: (e, do1) => {
|
|
10
|
+
req.raw.req.on('close', do1);
|
|
11
|
+
},
|
|
12
12
|
},
|
|
13
|
+
public: { headers: new Headers(req.headers) },
|
|
13
14
|
}),
|
|
14
15
|
getRequestBody: async (req) => req.payload,
|
|
15
16
|
});
|
package/esm/remult-hono.js
CHANGED
|
@@ -6,22 +6,24 @@ export function remultApi(options) {
|
|
|
6
6
|
const api = createRemultServer(options, {
|
|
7
7
|
buildGenericRequestInfo: (c) => {
|
|
8
8
|
return {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
internal: {
|
|
10
|
+
method: c.req.method,
|
|
11
|
+
params: c.req.param(),
|
|
12
|
+
query: new Proxy(c.req, {
|
|
13
|
+
get: (target, prop) => {
|
|
14
|
+
const r = c.req.queries(prop);
|
|
15
|
+
if (r?.length == 1)
|
|
16
|
+
return r[0];
|
|
17
|
+
return r;
|
|
18
|
+
},
|
|
19
|
+
}),
|
|
20
|
+
url: c.req.url,
|
|
21
|
+
on: (e, do1) => {
|
|
22
|
+
;
|
|
23
|
+
c['_tempOnClose'](() => do1());
|
|
17
24
|
},
|
|
18
|
-
}),
|
|
19
|
-
url: c.req.url,
|
|
20
|
-
on: (e, do1) => {
|
|
21
|
-
;
|
|
22
|
-
c['_tempOnClose'](() => do1());
|
|
23
|
-
// c.req.on('close', do1)
|
|
24
25
|
},
|
|
26
|
+
public: { headers: new Headers(c.req.header()) },
|
|
25
27
|
};
|
|
26
28
|
},
|
|
27
29
|
getRequestBody: async (c) => {
|
package/esm/remult-next.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { createRemultServer } from './server/index.js';
|
|
2
2
|
export function remultNext(options) {
|
|
3
3
|
let result = createRemultServer(options, {
|
|
4
|
-
buildGenericRequestInfo: (req) =>
|
|
4
|
+
buildGenericRequestInfo: (req) => ({
|
|
5
|
+
internal: { ...req, on: req.on },
|
|
6
|
+
public: { headers: new Headers(req.headers) },
|
|
7
|
+
}),
|
|
5
8
|
getRequestBody: async (req) => req.body,
|
|
6
9
|
});
|
|
7
10
|
return Object.assign((req, res) => result.handle(req, res).then(() => { }), result, {
|
|
@@ -41,14 +44,17 @@ export function remultApi(options) {
|
|
|
41
44
|
let result = createRemultServer(options, {
|
|
42
45
|
getRequestBody: (req) => req.json(),
|
|
43
46
|
buildGenericRequestInfo: (req) => ({
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
internal: {
|
|
48
|
+
url: req?.url,
|
|
49
|
+
method: req?.method,
|
|
50
|
+
on: (e, do1) => {
|
|
51
|
+
if (e === 'close') {
|
|
52
|
+
;
|
|
53
|
+
req['_tempOnClose'] = do1;
|
|
54
|
+
}
|
|
55
|
+
},
|
|
51
56
|
},
|
|
57
|
+
public: { headers: req.headers },
|
|
52
58
|
}),
|
|
53
59
|
});
|
|
54
60
|
const handler = async (req) => {
|
package/esm/remult-nuxt.js
CHANGED
|
@@ -2,15 +2,18 @@ import { readBody, setResponseStatus } from 'h3';
|
|
|
2
2
|
import { createRemultServer } from './server/index.js';
|
|
3
3
|
export function remultApi(options) {
|
|
4
4
|
const result = createRemultServer(options, {
|
|
5
|
-
buildGenericRequestInfo: (event) => {
|
|
6
|
-
|
|
5
|
+
buildGenericRequestInfo: (event) => ({
|
|
6
|
+
internal: {
|
|
7
7
|
method: event.node.req.method,
|
|
8
8
|
url: event.node.req.url,
|
|
9
9
|
on: (a, b) => event.node.req.on('close', () => {
|
|
10
10
|
b();
|
|
11
11
|
}),
|
|
12
|
-
}
|
|
13
|
-
|
|
12
|
+
},
|
|
13
|
+
public: {
|
|
14
|
+
headers: new Headers(event.node.req.headers),
|
|
15
|
+
},
|
|
16
|
+
}),
|
|
14
17
|
getRequestBody: async (event) => await readBody(event),
|
|
15
18
|
});
|
|
16
19
|
const handler = async (event) => {
|
|
@@ -3,13 +3,16 @@ import { createRemultServer } from './server/index.js';
|
|
|
3
3
|
export function remultApi(options) {
|
|
4
4
|
let result = createRemultServer(options, {
|
|
5
5
|
buildGenericRequestInfo: (event) => ({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
internal: {
|
|
7
|
+
url: event.request.url,
|
|
8
|
+
method: event.request.method,
|
|
9
|
+
on: (e, do1) => {
|
|
10
|
+
if (e === 'close') {
|
|
11
|
+
event.locals['_tempOnClose'] = do1;
|
|
12
|
+
}
|
|
13
|
+
},
|
|
12
14
|
},
|
|
15
|
+
public: { headers: new Headers(event.request.headers) },
|
|
13
16
|
}),
|
|
14
17
|
getRequestBody: (event) => event.request.json(),
|
|
15
18
|
});
|
package/esm/remult-sveltekit.js
CHANGED
|
@@ -2,14 +2,17 @@ import { createRemultServer } from './server/index.js';
|
|
|
2
2
|
export function remultApi(options) {
|
|
3
3
|
let result = createRemultServer(options, {
|
|
4
4
|
buildGenericRequestInfo: (event) => ({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
internal: {
|
|
6
|
+
url: event.request.url,
|
|
7
|
+
method: event.request.method,
|
|
8
|
+
on: (e, do1) => {
|
|
9
|
+
if (e === 'close') {
|
|
10
|
+
;
|
|
11
|
+
event.locals['_tempOnClose'] = do1;
|
|
12
|
+
}
|
|
13
|
+
},
|
|
12
14
|
},
|
|
15
|
+
public: { headers: event.request.headers },
|
|
13
16
|
}),
|
|
14
17
|
getRequestBody: (event) => event.request.json(),
|
|
15
18
|
});
|
|
@@ -65,7 +68,7 @@ export function remultApi(options) {
|
|
|
65
68
|
status: responseFromRemultHandler.statusCode,
|
|
66
69
|
headers: {
|
|
67
70
|
'Content-Type': 'application/json',
|
|
68
|
-
}
|
|
71
|
+
},
|
|
69
72
|
});
|
|
70
73
|
return res;
|
|
71
74
|
}
|
package/esm/server/index.js
CHANGED
|
@@ -9,7 +9,10 @@ export { Module } from './module.js';
|
|
|
9
9
|
export function createRemultServer(options, serverCoreOptions) {
|
|
10
10
|
initAsyncHooks();
|
|
11
11
|
return createRemultServerCore(options, serverCoreOptions || {
|
|
12
|
-
buildGenericRequestInfo: (req) =>
|
|
12
|
+
buildGenericRequestInfo: (req) => ({
|
|
13
|
+
internal: cast(req, 'method'),
|
|
14
|
+
public: { headers: new Headers(req.headers) },
|
|
15
|
+
}),
|
|
13
16
|
getRequestBody: async (req) => req.body,
|
|
14
17
|
});
|
|
15
18
|
}
|
package/esm/server/module.js
CHANGED
|
@@ -11,8 +11,8 @@ export class Module {
|
|
|
11
11
|
this.priority = options.priority ?? 0;
|
|
12
12
|
this.entities = options.entities;
|
|
13
13
|
this.controllers = options.controllers;
|
|
14
|
-
this.initRequest = options.initRequest;
|
|
15
14
|
this.initApi = options.initApi;
|
|
15
|
+
this.initRequest = options.initRequest;
|
|
16
16
|
this.modules = options.modules;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -339,7 +339,9 @@ export class RemultServerImplementation {
|
|
|
339
339
|
}
|
|
340
340
|
process(what, doNotReuseInitRequest) {
|
|
341
341
|
return async (req, origRes) => {
|
|
342
|
-
const genReq
|
|
342
|
+
const { internal: genReq, public: genReqPublic, } = req
|
|
343
|
+
? this.coreOptions.buildGenericRequestInfo(req)
|
|
344
|
+
: { internal: {}, public: { headers: new Headers() } };
|
|
343
345
|
if (req) {
|
|
344
346
|
if (!genReq.query) {
|
|
345
347
|
genReq.query = req['_tempQuery'];
|
|
@@ -358,6 +360,16 @@ export class RemultServerImplementation {
|
|
|
358
360
|
if (req) {
|
|
359
361
|
;
|
|
360
362
|
remult.context.request = req;
|
|
363
|
+
remult.context.headers = {
|
|
364
|
+
get: (key) => genReqPublic.headers.get(key) ?? undefined,
|
|
365
|
+
getAll: () => {
|
|
366
|
+
const result = {};
|
|
367
|
+
genReqPublic.headers.forEach((value, key) => {
|
|
368
|
+
result[key] = value;
|
|
369
|
+
});
|
|
370
|
+
return result;
|
|
371
|
+
},
|
|
372
|
+
};
|
|
361
373
|
remultStatic.asyncContext.setInInitRequest(true);
|
|
362
374
|
try {
|
|
363
375
|
let user;
|
|
@@ -1109,7 +1121,7 @@ export class RouteImplementation {
|
|
|
1109
1121
|
});
|
|
1110
1122
|
}
|
|
1111
1123
|
middleware(origReq, res, next) {
|
|
1112
|
-
const req = this.coreOptions.buildGenericRequestInfo(origReq);
|
|
1124
|
+
const { internal: req } = this.coreOptions.buildGenericRequestInfo(origReq);
|
|
1113
1125
|
let theUrl = req.url?.toString() || '';
|
|
1114
1126
|
if (theUrl.startsWith('/'))
|
|
1115
1127
|
//next sends a partial url '/api/tasks' and not the full url
|
|
@@ -11,7 +11,10 @@ export function TestApiDataProvider(options) {
|
|
|
11
11
|
});
|
|
12
12
|
const server = createRemultServerCore({ ...options, dataProvider: dp }, {
|
|
13
13
|
getRequestBody: async (req) => req.body,
|
|
14
|
-
buildGenericRequestInfo: (req) =>
|
|
14
|
+
buildGenericRequestInfo: (req) => ({
|
|
15
|
+
internal: req,
|
|
16
|
+
public: { headers: new Headers() },
|
|
17
|
+
}),
|
|
15
18
|
ignoreAsyncStorage: true,
|
|
16
19
|
});
|
|
17
20
|
const lock = new AsyncLock();
|
package/esm/src/context.js
CHANGED
|
@@ -231,7 +231,15 @@ export class Remult {
|
|
|
231
231
|
}
|
|
232
232
|
/** A helper callback that is called whenever an entity is created. */
|
|
233
233
|
static entityRefInit;
|
|
234
|
-
/**
|
|
234
|
+
/**
|
|
235
|
+
* context that can be used to store custom information that will be disposed as part of the `remult` object.
|
|
236
|
+
*
|
|
237
|
+
* `remult.context` is pre-filled in a framework-agnostic way with:
|
|
238
|
+
* - `headers.get(key: string)` _of request_
|
|
239
|
+
* - `headers.getAll()` _of request_
|
|
240
|
+
*
|
|
241
|
+
* Check out the [extensibility section](/docs/custom-options#enhancing-field-and-entity-definitions-with-custom-options) for more custom options.
|
|
242
|
+
*/
|
|
235
243
|
context = {};
|
|
236
244
|
/** The api client that will be used by `remult` to perform calls to the `api` */
|
|
237
245
|
apiClient = {
|
package/package.json
CHANGED
package/remult-express.js
CHANGED
|
@@ -19,7 +19,10 @@ function remultApi(options) {
|
|
|
19
19
|
app.use(express.urlencoded({ extended: true, limit: options.bodySizeLimit }));
|
|
20
20
|
}
|
|
21
21
|
var server = (0, index_js_1.createRemultServer)(options, {
|
|
22
|
-
buildGenericRequestInfo: function (req) { return
|
|
22
|
+
buildGenericRequestInfo: function (req) { return ({
|
|
23
|
+
internal: tslib_1.__assign(tslib_1.__assign({}, req), { on: req.on }),
|
|
24
|
+
public: { headers: new Headers(req.headers) },
|
|
25
|
+
}); },
|
|
23
26
|
getRequestBody: function (req) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
24
27
|
return [2 /*return*/, req.body];
|
|
25
28
|
}); }); },
|
package/remult-fastify.js
CHANGED
|
@@ -39,7 +39,12 @@ function remultApi(options) {
|
|
|
39
39
|
return response;
|
|
40
40
|
}
|
|
41
41
|
var api = (0, index_js_1.createRemultServer)(options, {
|
|
42
|
-
buildGenericRequestInfo: function (req) { return
|
|
42
|
+
buildGenericRequestInfo: function (req) { return ({
|
|
43
|
+
internal: tslib_1.__assign(tslib_1.__assign({}, req), { url: req.originalUrl,
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
on: req.on }),
|
|
46
|
+
public: { headers: new Headers(req.headers) },
|
|
47
|
+
}); },
|
|
43
48
|
getRequestBody: function (req) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
44
49
|
return [2 /*return*/, req.body];
|
|
45
50
|
}); }); },
|
package/remult-fresh.js
CHANGED
|
@@ -7,7 +7,11 @@ var remult_api_server_js_1 = require("./server/remult-api-server.js");
|
|
|
7
7
|
function remultApi(options, response) {
|
|
8
8
|
var _this = this;
|
|
9
9
|
var server = (0, remult_api_server_js_1.createRemultServerCore)(options, {
|
|
10
|
-
buildGenericRequestInfo: function (r) { return
|
|
10
|
+
buildGenericRequestInfo: function (r) { return ({
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
internal: tslib_1.__assign(tslib_1.__assign({}, r), { on: r.on }),
|
|
13
|
+
public: { headers: r.headers },
|
|
14
|
+
}); },
|
|
11
15
|
getRequestBody: function (req) { return req.json(); },
|
|
12
16
|
});
|
|
13
17
|
return {
|
package/remult-hapi.js
CHANGED
|
@@ -9,13 +9,10 @@ function remultApi(options) {
|
|
|
9
9
|
var _this = this;
|
|
10
10
|
var api = (0, index_js_1.createRemultServer)(options, {
|
|
11
11
|
buildGenericRequestInfo: function (req) { return ({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
on: function (e, do1) {
|
|
17
|
-
req.raw.req.on('close', do1);
|
|
18
|
-
},
|
|
12
|
+
internal: tslib_1.__assign(tslib_1.__assign({}, req), { url: req.url.pathname, on: function (e, do1) {
|
|
13
|
+
req.raw.req.on('close', do1);
|
|
14
|
+
} }),
|
|
15
|
+
public: { headers: new Headers(req.headers) },
|
|
19
16
|
}); },
|
|
20
17
|
getRequestBody: function (req) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
21
18
|
return [2 /*return*/, req.payload];
|
package/remult-hono.js
CHANGED
|
@@ -12,22 +12,24 @@ function remultApi(options) {
|
|
|
12
12
|
var api = (0, index_js_1.createRemultServer)(options, {
|
|
13
13
|
buildGenericRequestInfo: function (c) {
|
|
14
14
|
return {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
internal: {
|
|
16
|
+
method: c.req.method,
|
|
17
|
+
params: c.req.param(),
|
|
18
|
+
query: new Proxy(c.req, {
|
|
19
|
+
get: function (target, prop) {
|
|
20
|
+
var r = c.req.queries(prop);
|
|
21
|
+
if ((r === null || r === void 0 ? void 0 : r.length) == 1)
|
|
22
|
+
return r[0];
|
|
23
|
+
return r;
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
url: c.req.url,
|
|
27
|
+
on: function (e, do1) {
|
|
28
|
+
;
|
|
29
|
+
c['_tempOnClose'](function () { return do1(); });
|
|
23
30
|
},
|
|
24
|
-
}),
|
|
25
|
-
url: c.req.url,
|
|
26
|
-
on: function (e, do1) {
|
|
27
|
-
;
|
|
28
|
-
c['_tempOnClose'](function () { return do1(); });
|
|
29
|
-
// c.req.on('close', do1)
|
|
30
31
|
},
|
|
32
|
+
public: { headers: new Headers(c.req.header()) },
|
|
31
33
|
};
|
|
32
34
|
},
|
|
33
35
|
getRequestBody: function (c) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
package/remult-next.js
CHANGED
|
@@ -8,7 +8,10 @@ var index_js_1 = require("./server/index.js");
|
|
|
8
8
|
function remultNext(options) {
|
|
9
9
|
var _this = this;
|
|
10
10
|
var result = (0, index_js_1.createRemultServer)(options, {
|
|
11
|
-
buildGenericRequestInfo: function (req) { return
|
|
11
|
+
buildGenericRequestInfo: function (req) { return ({
|
|
12
|
+
internal: tslib_1.__assign(tslib_1.__assign({}, req), { on: req.on }),
|
|
13
|
+
public: { headers: new Headers(req.headers) },
|
|
14
|
+
}); },
|
|
12
15
|
getRequestBody: function (req) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
13
16
|
return [2 /*return*/, req.body];
|
|
14
17
|
}); }); },
|
|
@@ -84,14 +87,17 @@ function remultApi(options) {
|
|
|
84
87
|
var result = (0, index_js_1.createRemultServer)(options, {
|
|
85
88
|
getRequestBody: function (req) { return req.json(); },
|
|
86
89
|
buildGenericRequestInfo: function (req) { return ({
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
internal: {
|
|
91
|
+
url: req === null || req === void 0 ? void 0 : req.url,
|
|
92
|
+
method: req === null || req === void 0 ? void 0 : req.method,
|
|
93
|
+
on: function (e, do1) {
|
|
94
|
+
if (e === 'close') {
|
|
95
|
+
;
|
|
96
|
+
req['_tempOnClose'] = do1;
|
|
97
|
+
}
|
|
98
|
+
},
|
|
94
99
|
},
|
|
100
|
+
public: { headers: req.headers },
|
|
95
101
|
}); },
|
|
96
102
|
});
|
|
97
103
|
var handler = function (req) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
package/remult-nuxt.js
CHANGED
|
@@ -8,8 +8,8 @@ var index_js_1 = require("./server/index.js");
|
|
|
8
8
|
function remultApi(options) {
|
|
9
9
|
var _this = this;
|
|
10
10
|
var result = (0, index_js_1.createRemultServer)(options, {
|
|
11
|
-
buildGenericRequestInfo: function (event) {
|
|
12
|
-
|
|
11
|
+
buildGenericRequestInfo: function (event) { return ({
|
|
12
|
+
internal: {
|
|
13
13
|
method: event.node.req.method,
|
|
14
14
|
url: event.node.req.url,
|
|
15
15
|
on: function (a, b) {
|
|
@@ -17,8 +17,11 @@ function remultApi(options) {
|
|
|
17
17
|
b();
|
|
18
18
|
});
|
|
19
19
|
},
|
|
20
|
-
}
|
|
21
|
-
|
|
20
|
+
},
|
|
21
|
+
public: {
|
|
22
|
+
headers: new Headers(event.node.req.headers),
|
|
23
|
+
},
|
|
24
|
+
}); },
|
|
22
25
|
getRequestBody: function (event) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
23
26
|
switch (_a.label) {
|
|
24
27
|
case 0: return [4 /*yield*/, (0, h3_1.readBody)(event)];
|
package/remult-solid-start.js
CHANGED
|
@@ -9,13 +9,16 @@ function remultApi(options) {
|
|
|
9
9
|
var _this = this;
|
|
10
10
|
var result = (0, index_js_1.createRemultServer)(options, {
|
|
11
11
|
buildGenericRequestInfo: function (event) { return ({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
internal: {
|
|
13
|
+
url: event.request.url,
|
|
14
|
+
method: event.request.method,
|
|
15
|
+
on: function (e, do1) {
|
|
16
|
+
if (e === 'close') {
|
|
17
|
+
event.locals['_tempOnClose'] = do1;
|
|
18
|
+
}
|
|
19
|
+
},
|
|
18
20
|
},
|
|
21
|
+
public: { headers: new Headers(event.request.headers) },
|
|
19
22
|
}); },
|
|
20
23
|
getRequestBody: function (event) { return event.request.json(); },
|
|
21
24
|
});
|
package/remult-sveltekit.js
CHANGED
|
@@ -8,14 +8,17 @@ function remultApi(options) {
|
|
|
8
8
|
var _this = this;
|
|
9
9
|
var result = (0, index_js_1.createRemultServer)(options, {
|
|
10
10
|
buildGenericRequestInfo: function (event) { return ({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
internal: {
|
|
12
|
+
url: event.request.url,
|
|
13
|
+
method: event.request.method,
|
|
14
|
+
on: function (e, do1) {
|
|
15
|
+
if (e === 'close') {
|
|
16
|
+
;
|
|
17
|
+
event.locals['_tempOnClose'] = do1;
|
|
18
|
+
}
|
|
19
|
+
},
|
|
18
20
|
},
|
|
21
|
+
public: { headers: event.request.headers },
|
|
19
22
|
}); },
|
|
20
23
|
getRequestBody: function (event) { return event.request.json(); },
|
|
21
24
|
});
|
|
@@ -88,7 +91,7 @@ function remultApi(options) {
|
|
|
88
91
|
status: responseFromRemultHandler.statusCode,
|
|
89
92
|
headers: {
|
|
90
93
|
'Content-Type': 'application/json',
|
|
91
|
-
}
|
|
94
|
+
},
|
|
92
95
|
});
|
|
93
96
|
return [2 /*return*/, res];
|
|
94
97
|
}
|
package/server/core.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { queuedJobInfo, QueueStorage, GenericRequestInfo, GenericRequestHandler, GenericResponse, GenericRouter, createRemultServerCore, RemultServerOptions, SpecificRoute, RemultServer, } from './remult-api-server.js';
|
|
1
|
+
export { type queuedJobInfo, type QueueStorage, type GenericRequestInfo, type GenericRequestHandler, type GenericResponse, type GenericRouter, createRemultServerCore, type RemultServerOptions, type SpecificRoute, type RemultServer, } from './remult-api-server.js';
|
|
2
2
|
export { JsonEntityFileStorage, JsonFileDataProvider, } from './JsonEntityFileStorage.js';
|
|
3
3
|
export { SseSubscriptionServer } from '../SseSubscriptionServer.js';
|
|
4
4
|
export { DataProviderLiveQueryStorage } from '../live-query/data-provider-live-query-storage.js';
|
package/server/index.js
CHANGED
|
@@ -21,7 +21,10 @@ function createRemultServer(options, serverCoreOptions) {
|
|
|
21
21
|
var _this = this;
|
|
22
22
|
(0, initAsyncHooks_js_1.initAsyncHooks)();
|
|
23
23
|
return (0, remult_api_server_js_1.createRemultServerCore)(options, serverCoreOptions || {
|
|
24
|
-
buildGenericRequestInfo: function (req) { return (
|
|
24
|
+
buildGenericRequestInfo: function (req) { return ({
|
|
25
|
+
internal: (0, isOfType_js_1.cast)(req, 'method'),
|
|
26
|
+
public: { headers: new Headers(req.headers) },
|
|
27
|
+
}); },
|
|
25
28
|
getRequestBody: function (req) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
26
29
|
return [2 /*return*/, req.body];
|
|
27
30
|
}); }); },
|
package/server/module.js
CHANGED
|
@@ -9,8 +9,8 @@ var Module = /** @class */ (function () {
|
|
|
9
9
|
this.priority = (_a = options.priority) !== null && _a !== void 0 ? _a : 0;
|
|
10
10
|
this.entities = options.entities;
|
|
11
11
|
this.controllers = options.controllers;
|
|
12
|
-
this.initRequest = options.initRequest;
|
|
13
12
|
this.initApi = options.initApi;
|
|
13
|
+
this.initRequest = options.initRequest;
|
|
14
14
|
this.modules = options.modules;
|
|
15
15
|
}
|
|
16
16
|
return Module;
|
|
@@ -99,16 +99,23 @@ export interface RemultServerOptions<RequestType> {
|
|
|
99
99
|
* @example
|
|
100
100
|
* import { Module } from 'remult/server'
|
|
101
101
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
102
|
+
* // create an analytics module
|
|
103
|
+
* const analytics = () => new Module({
|
|
104
|
+
* key: 'analytics',
|
|
105
|
+
* priority: 11, // Default: 0, Prioritized by ascending order.
|
|
106
|
+
* entities: [AnalyticsEvent],
|
|
107
|
+
* controllers: [AnalyticsController],
|
|
108
|
+
* initApi: () => console.log('analytics module initialized'),
|
|
109
|
+
* initRequest: () => {},
|
|
110
|
+
* modules: [] // You can nest modules
|
|
111
|
+
* })
|
|
112
|
+
*
|
|
113
|
+
* // use the module in the remultApi
|
|
114
|
+
* remultApi({
|
|
115
|
+
* modules: [
|
|
116
|
+
* analytics(),
|
|
117
|
+
* ]
|
|
118
|
+
* })
|
|
112
119
|
*/
|
|
113
120
|
modules?: Module<RequestType>[];
|
|
114
121
|
}
|
|
@@ -145,6 +152,9 @@ export type SpecificRoute<RequestType> = {
|
|
|
145
152
|
post(handler: GenericRequestHandler<RequestType>): SpecificRoute<RequestType>;
|
|
146
153
|
delete(handler: GenericRequestHandler<RequestType>): SpecificRoute<RequestType>;
|
|
147
154
|
};
|
|
155
|
+
export interface GenericRequest {
|
|
156
|
+
headers: Headers;
|
|
157
|
+
}
|
|
148
158
|
export interface GenericRequestInfo {
|
|
149
159
|
url?: string;
|
|
150
160
|
method?: any;
|
|
@@ -199,7 +209,10 @@ export declare class JobsInQueueEntity extends IdEntity {
|
|
|
199
209
|
progress: number;
|
|
200
210
|
}
|
|
201
211
|
export interface ServerCoreOptions<RequestType> {
|
|
202
|
-
buildGenericRequestInfo(req: RequestType):
|
|
212
|
+
buildGenericRequestInfo(req: RequestType): {
|
|
213
|
+
internal: GenericRequestInfo;
|
|
214
|
+
public: GenericRequest;
|
|
215
|
+
};
|
|
203
216
|
getRequestBody(req: RequestType): Promise<any>;
|
|
204
217
|
ignoreAsyncStorage?: boolean;
|
|
205
218
|
}
|
|
@@ -629,12 +629,14 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
629
629
|
RemultServerImplementation.prototype.process = function (what, doNotReuseInitRequest) {
|
|
630
630
|
var _this = this;
|
|
631
631
|
return function (req, origRes) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
632
|
-
var genReq, myReq, myRes, err_2;
|
|
632
|
+
var _a, genReq, genReqPublic, myReq, myRes, err_2;
|
|
633
633
|
var _this = this;
|
|
634
|
-
return tslib_1.__generator(this, function (
|
|
635
|
-
switch (
|
|
634
|
+
return tslib_1.__generator(this, function (_b) {
|
|
635
|
+
switch (_b.label) {
|
|
636
636
|
case 0:
|
|
637
|
-
|
|
637
|
+
_a = req
|
|
638
|
+
? this.coreOptions.buildGenericRequestInfo(req)
|
|
639
|
+
: { internal: {}, public: { headers: new Headers() } }, genReq = _a.internal, genReqPublic = _a.public;
|
|
638
640
|
if (req) {
|
|
639
641
|
if (!genReq.query) {
|
|
640
642
|
genReq.query = req['_tempQuery'];
|
|
@@ -644,13 +646,13 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
644
646
|
}
|
|
645
647
|
myReq = new RequestBridgeToDataApiRequest(genReq);
|
|
646
648
|
myRes = new ResponseBridgeToDataApiResponse(origRes, req, genReq, this.options.error);
|
|
647
|
-
|
|
649
|
+
_b.label = 1;
|
|
648
650
|
case 1:
|
|
649
|
-
|
|
651
|
+
_b.trys.push([1, 6, , 7]);
|
|
650
652
|
if (!(remult_static_js_1.remultStatic.asyncContext.isInInitRequest() &&
|
|
651
653
|
!doNotReuseInitRequest)) return [3 /*break*/, 3];
|
|
652
654
|
return [4 /*yield*/, what(remult_static_js_1.remultStatic.asyncContext.getStore().remult, myReq, myRes, genReq, origRes, req)];
|
|
653
|
-
case 2: return [2 /*return*/,
|
|
655
|
+
case 2: return [2 /*return*/, _b.sent()];
|
|
654
656
|
case 3: return [4 /*yield*/, this.runWithRemult(function (remult) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
655
657
|
var user, i, _initRequest;
|
|
656
658
|
return tslib_1.__generator(this, function (_a) {
|
|
@@ -659,6 +661,16 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
659
661
|
if (!req) return [3 /*break*/, 11];
|
|
660
662
|
;
|
|
661
663
|
remult.context.request = req;
|
|
664
|
+
remult.context.headers = {
|
|
665
|
+
get: function (key) { var _a; return (_a = genReqPublic.headers.get(key)) !== null && _a !== void 0 ? _a : undefined; },
|
|
666
|
+
getAll: function () {
|
|
667
|
+
var result = {};
|
|
668
|
+
genReqPublic.headers.forEach(function (value, key) {
|
|
669
|
+
result[key] = value;
|
|
670
|
+
});
|
|
671
|
+
return result;
|
|
672
|
+
},
|
|
673
|
+
};
|
|
662
674
|
remult_static_js_1.remultStatic.asyncContext.setInInitRequest(true);
|
|
663
675
|
_a.label = 1;
|
|
664
676
|
case 1:
|
|
@@ -712,11 +724,11 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
712
724
|
});
|
|
713
725
|
}); })];
|
|
714
726
|
case 4:
|
|
715
|
-
|
|
716
|
-
|
|
727
|
+
_b.sent();
|
|
728
|
+
_b.label = 5;
|
|
717
729
|
case 5: return [3 /*break*/, 7];
|
|
718
730
|
case 6:
|
|
719
|
-
err_2 =
|
|
731
|
+
err_2 = _b.sent();
|
|
720
732
|
if (origRes)
|
|
721
733
|
myRes.error(err_2, undefined);
|
|
722
734
|
else
|
|
@@ -1581,7 +1593,7 @@ var RouteImplementation = /** @class */ (function () {
|
|
|
1581
1593
|
RouteImplementation.prototype.middleware = function (origReq, res, next) {
|
|
1582
1594
|
var e_8, _a;
|
|
1583
1595
|
var _b;
|
|
1584
|
-
var req = this.coreOptions.buildGenericRequestInfo(origReq);
|
|
1596
|
+
var req = this.coreOptions.buildGenericRequestInfo(origReq).internal;
|
|
1585
1597
|
var theUrl = ((_b = req.url) === null || _b === void 0 ? void 0 : _b.toString()) || '';
|
|
1586
1598
|
if (theUrl.startsWith('/'))
|
|
1587
1599
|
//next sends a partial url '/api/tasks' and not the full url
|
|
@@ -21,7 +21,10 @@ function TestApiDataProvider(options) {
|
|
|
21
21
|
getRequestBody: function (req) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
22
22
|
return [2 /*return*/, req.body];
|
|
23
23
|
}); }); },
|
|
24
|
-
buildGenericRequestInfo: function (req) { return
|
|
24
|
+
buildGenericRequestInfo: function (req) { return ({
|
|
25
|
+
internal: req,
|
|
26
|
+
public: { headers: new Headers() },
|
|
27
|
+
}); },
|
|
25
28
|
ignoreAsyncStorage: true,
|
|
26
29
|
});
|
|
27
30
|
var lock = new AsyncLock();
|
package/src/context.d.ts
CHANGED
|
@@ -90,7 +90,15 @@ export declare class Remult {
|
|
|
90
90
|
clearAllCache(): any;
|
|
91
91
|
/** A helper callback that is called whenever an entity is created. */
|
|
92
92
|
static entityRefInit?: (ref: EntityRef<any>, row: any) => void;
|
|
93
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* context that can be used to store custom information that will be disposed as part of the `remult` object.
|
|
95
|
+
*
|
|
96
|
+
* `remult.context` is pre-filled in a framework-agnostic way with:
|
|
97
|
+
* - `headers.get(key: string)` _of request_
|
|
98
|
+
* - `headers.getAll()` _of request_
|
|
99
|
+
*
|
|
100
|
+
* Check out the [extensibility section](/docs/custom-options#enhancing-field-and-entity-definitions-with-custom-options) for more custom options.
|
|
101
|
+
*/
|
|
94
102
|
readonly context: RemultContext;
|
|
95
103
|
/** The api client that will be used by `remult` to perform calls to the `api` */
|
|
96
104
|
apiClient: ApiClient;
|
|
@@ -102,13 +110,18 @@ export type GetArguments<T> = T extends (...args: infer FirstArgument) => any ?
|
|
|
102
110
|
* To type it correctly, you can extend it with your own properties.
|
|
103
111
|
* @example
|
|
104
112
|
* import type express from 'express'
|
|
113
|
+
*
|
|
105
114
|
* declare module 'remult' {
|
|
106
115
|
* export interface RemultContext {
|
|
107
116
|
* request?: express.Request
|
|
108
117
|
* }
|
|
109
118
|
* }
|
|
110
|
-
|
|
119
|
+
*/
|
|
111
120
|
export interface RemultContext {
|
|
121
|
+
headers?: {
|
|
122
|
+
get: (key: string) => string | undefined;
|
|
123
|
+
getAll: () => Record<string, string>;
|
|
124
|
+
};
|
|
112
125
|
}
|
|
113
126
|
/**
|
|
114
127
|
* Interface for configuring the API client used by Remult to perform HTTP calls to the backend.
|
package/src/context.js
CHANGED
|
@@ -121,7 +121,15 @@ var Remult = /** @class */ (function () {
|
|
|
121
121
|
};
|
|
122
122
|
/* @internal*/
|
|
123
123
|
this.liveQuerySubscriber = new LiveQueryClient_js_1.LiveQueryClient(function () { return _this.apiClient; }, function () { var _a; return (_a = _this.user) === null || _a === void 0 ? void 0 : _a.id; });
|
|
124
|
-
/**
|
|
124
|
+
/**
|
|
125
|
+
* context that can be used to store custom information that will be disposed as part of the `remult` object.
|
|
126
|
+
*
|
|
127
|
+
* `remult.context` is pre-filled in a framework-agnostic way with:
|
|
128
|
+
* - `headers.get(key: string)` _of request_
|
|
129
|
+
* - `headers.getAll()` _of request_
|
|
130
|
+
*
|
|
131
|
+
* Check out the [extensibility section](/docs/custom-options#enhancing-field-and-entity-definitions-with-custom-options) for more custom options.
|
|
132
|
+
*/
|
|
125
133
|
this.context = {};
|
|
126
134
|
/** The api client that will be used by `remult` to perform calls to the `api` */
|
|
127
135
|
this.apiClient = {
|