remult 3.0.5 → 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 +5 -1
- package/esm/server/module.js +38 -0
- package/esm/server/remult-api-server.js +57 -21
- 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.d.ts +2 -0
- package/server/index.js +7 -2
- package/server/module.d.ts +26 -0
- package/server/module.js +40 -0
- package/server/remult-api-server.d.ts +33 -1
- package/server/remult-api-server.js +88 -43
- 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
|
@@ -5,10 +5,14 @@ export { SseSubscriptionServer } from '../SseSubscriptionServer.js';
|
|
|
5
5
|
export { DataProviderLiveQueryStorage } from '../live-query/data-provider-live-query-storage.js';
|
|
6
6
|
export { JsonEntityFileStorage, JsonFileDataProvider, } from './JsonEntityFileStorage.js';
|
|
7
7
|
export { TestApiDataProvider } from './test-api-data-provider.js';
|
|
8
|
+
export { Module } from './module.js';
|
|
8
9
|
export function createRemultServer(options, serverCoreOptions) {
|
|
9
10
|
initAsyncHooks();
|
|
10
11
|
return createRemultServerCore(options, serverCoreOptions || {
|
|
11
|
-
buildGenericRequestInfo: (req) =>
|
|
12
|
+
buildGenericRequestInfo: (req) => ({
|
|
13
|
+
internal: cast(req, 'method'),
|
|
14
|
+
public: { headers: new Headers(req.headers) },
|
|
15
|
+
}),
|
|
12
16
|
getRequestBody: async (req) => req.body,
|
|
13
17
|
});
|
|
14
18
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export class Module {
|
|
2
|
+
key;
|
|
3
|
+
priority;
|
|
4
|
+
entities;
|
|
5
|
+
controllers;
|
|
6
|
+
initApi;
|
|
7
|
+
initRequest;
|
|
8
|
+
modules;
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.key = options.key;
|
|
11
|
+
this.priority = options.priority ?? 0;
|
|
12
|
+
this.entities = options.entities;
|
|
13
|
+
this.controllers = options.controllers;
|
|
14
|
+
this.initApi = options.initApi;
|
|
15
|
+
this.initRequest = options.initRequest;
|
|
16
|
+
this.modules = options.modules;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Full flat and ordered list by index and concatenaining the modules name
|
|
21
|
+
*/
|
|
22
|
+
export const modulesFlatAndOrdered = (modules) => {
|
|
23
|
+
const flattenModules = (modules, parentName = '') => {
|
|
24
|
+
return modules.reduce((acc, module) => {
|
|
25
|
+
const fullKey = parentName ? `${parentName}-${module.key}` : module.key;
|
|
26
|
+
// Create a new module object without the 'modules' property
|
|
27
|
+
const { modules: _, ...flatModule } = module;
|
|
28
|
+
const newModule = { ...flatModule, key: fullKey };
|
|
29
|
+
const subModules = module.modules
|
|
30
|
+
? flattenModules(module.modules, fullKey)
|
|
31
|
+
: [];
|
|
32
|
+
return [...acc, newModule, ...subModules];
|
|
33
|
+
}, []);
|
|
34
|
+
};
|
|
35
|
+
const flatModules = flattenModules(modules);
|
|
36
|
+
flatModules.sort((a, b) => a.priority - b.priority);
|
|
37
|
+
return flatModules;
|
|
38
|
+
};
|
|
@@ -14,6 +14,7 @@ import { remultStatic } from '../src/remult-static.js';
|
|
|
14
14
|
import remultAdminHtml, { buildEntityInfo } from './remult-admin.js';
|
|
15
15
|
import { isOfType } from '../src/isOfType.js';
|
|
16
16
|
import { initDataProviderOrJson } from './initDataProviderOrJson.js';
|
|
17
|
+
import { modulesFlatAndOrdered } from './module.js';
|
|
17
18
|
export function createRemultServerCore(options, serverCoreOptions) {
|
|
18
19
|
const safeOptions = options ?? {};
|
|
19
20
|
if (!safeOptions.entities)
|
|
@@ -57,6 +58,9 @@ export class RemultServerImplementation {
|
|
|
57
58
|
dataProvider;
|
|
58
59
|
coreOptions;
|
|
59
60
|
liveQueryStorage = new InMemoryLiveQueryStorage();
|
|
61
|
+
modulesSorted = [];
|
|
62
|
+
entities = [];
|
|
63
|
+
controllers = [];
|
|
60
64
|
constructor(queue, options, dataProvider, coreOptions) {
|
|
61
65
|
this.queue = queue;
|
|
62
66
|
this.options = options;
|
|
@@ -67,6 +71,19 @@ export class RemultServerImplementation {
|
|
|
67
71
|
if (options.subscriptionServer)
|
|
68
72
|
this.subscriptionServer = options.subscriptionServer;
|
|
69
73
|
const entitiesMetaData = [];
|
|
74
|
+
const modules = options.modules ?? [];
|
|
75
|
+
modules.push({
|
|
76
|
+
key: 'default',
|
|
77
|
+
priority: 0,
|
|
78
|
+
entities: options.entities ?? [],
|
|
79
|
+
controllers: options.controllers ?? [],
|
|
80
|
+
initApi: options.initApi,
|
|
81
|
+
initRequest: options.initRequest,
|
|
82
|
+
modules: [],
|
|
83
|
+
});
|
|
84
|
+
this.modulesSorted = modulesFlatAndOrdered(modules);
|
|
85
|
+
this.entities = this.modulesSorted.flatMap((m) => m.entities ?? []);
|
|
86
|
+
this.controllers = this.modulesSorted.flatMap((m) => m.controllers ?? []);
|
|
70
87
|
this.dataProvider = dataProvider.then(async (dp) => {
|
|
71
88
|
await this.runWithRemult(async (remult) => {
|
|
72
89
|
remult.dataProvider = dp;
|
|
@@ -78,8 +95,8 @@ export class RemultServerImplementation {
|
|
|
78
95
|
started = true;
|
|
79
96
|
console.time('Schema ensured');
|
|
80
97
|
};
|
|
81
|
-
if (
|
|
82
|
-
entitiesMetaData.push(...
|
|
98
|
+
if (this.entities)
|
|
99
|
+
entitiesMetaData.push(...this.entities.map((e) => remult.repo(e).metadata));
|
|
83
100
|
if (dp.ensureSchema) {
|
|
84
101
|
startConsoleLog();
|
|
85
102
|
await dp.ensureSchema(entitiesMetaData);
|
|
@@ -96,8 +113,12 @@ export class RemultServerImplementation {
|
|
|
96
113
|
if (started)
|
|
97
114
|
console.timeEnd('Schema ensured');
|
|
98
115
|
}
|
|
99
|
-
|
|
100
|
-
|
|
116
|
+
for (let i = 0; i < this.modulesSorted.length; i++) {
|
|
117
|
+
const _initApi = this.modulesSorted[i].initApi;
|
|
118
|
+
if (_initApi) {
|
|
119
|
+
await _initApi(remult);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
101
122
|
}, { skipDataProvider: true });
|
|
102
123
|
return dp;
|
|
103
124
|
});
|
|
@@ -124,10 +145,10 @@ export class RemultServerImplementation {
|
|
|
124
145
|
getEntities() {
|
|
125
146
|
//TODO V2 - consider using entitiesMetaData - but it may require making it all awaitable
|
|
126
147
|
var r = new Remult();
|
|
127
|
-
return this.
|
|
148
|
+
return this.entities.map((x) => r.repo(x).metadata);
|
|
128
149
|
}
|
|
129
150
|
runWithSerializedJsonContextData = async (jsonContextData, entityKey, what) => {
|
|
130
|
-
for (const e of this.
|
|
151
|
+
for (const e of this.entities) {
|
|
131
152
|
let key = getEntityKey(e);
|
|
132
153
|
if (key === entityKey) {
|
|
133
154
|
await this.runWithRemult(async (remult) => {
|
|
@@ -173,7 +194,7 @@ export class RemultServerImplementation {
|
|
|
173
194
|
throw 'Router already registered';
|
|
174
195
|
this.registeredRouter = true;
|
|
175
196
|
{
|
|
176
|
-
for (const c of this.
|
|
197
|
+
for (const c of this.controllers) {
|
|
177
198
|
let z = c[classBackendMethodsArray];
|
|
178
199
|
if (z)
|
|
179
200
|
for (const a of z) {
|
|
@@ -211,7 +232,7 @@ export class RemultServerImplementation {
|
|
|
211
232
|
if (orig?.params?.id === '__entities-metadata') {
|
|
212
233
|
res.success(buildEntityInfo({
|
|
213
234
|
remult,
|
|
214
|
-
entities: this.
|
|
235
|
+
entities: this.entities,
|
|
215
236
|
}));
|
|
216
237
|
}
|
|
217
238
|
else {
|
|
@@ -259,7 +280,7 @@ export class RemultServerImplementation {
|
|
|
259
280
|
res.success(await remult.liveQueryStorage.keepAliveAndReturnUnknownQueryIds(await this.coreOptions.getRequestBody(origReq)));
|
|
260
281
|
}));
|
|
261
282
|
}
|
|
262
|
-
this.
|
|
283
|
+
this.entities.forEach((e) => {
|
|
263
284
|
this.addEntity(e, getEntityKey(e), r);
|
|
264
285
|
});
|
|
265
286
|
}
|
|
@@ -318,7 +339,9 @@ export class RemultServerImplementation {
|
|
|
318
339
|
}
|
|
319
340
|
process(what, doNotReuseInitRequest) {
|
|
320
341
|
return async (req, origRes) => {
|
|
321
|
-
const genReq
|
|
342
|
+
const { internal: genReq, public: genReqPublic, } = req
|
|
343
|
+
? this.coreOptions.buildGenericRequestInfo(req)
|
|
344
|
+
: { internal: {}, public: { headers: new Headers() } };
|
|
322
345
|
if (req) {
|
|
323
346
|
if (!genReq.query) {
|
|
324
347
|
genReq.query = req['_tempQuery'];
|
|
@@ -337,6 +360,16 @@ export class RemultServerImplementation {
|
|
|
337
360
|
if (req) {
|
|
338
361
|
;
|
|
339
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
|
+
};
|
|
340
373
|
remultStatic.asyncContext.setInInitRequest(true);
|
|
341
374
|
try {
|
|
342
375
|
let user;
|
|
@@ -351,16 +384,19 @@ export class RemultServerImplementation {
|
|
|
351
384
|
}
|
|
352
385
|
if (user)
|
|
353
386
|
remult.user = user;
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
387
|
+
for (let i = 0; i < this.modulesSorted.length; i++) {
|
|
388
|
+
const _initRequest = this.modulesSorted[i].initRequest;
|
|
389
|
+
if (_initRequest) {
|
|
390
|
+
await _initRequest(req, {
|
|
391
|
+
remult,
|
|
392
|
+
get liveQueryStorage() {
|
|
393
|
+
return remult.liveQueryStorage;
|
|
394
|
+
},
|
|
395
|
+
set liveQueryStorage(value) {
|
|
396
|
+
remult.liveQueryStorage = value;
|
|
397
|
+
},
|
|
398
|
+
});
|
|
399
|
+
}
|
|
364
400
|
}
|
|
365
401
|
await what(remult, myReq, myRes, genReq, origRes, req);
|
|
366
402
|
}
|
|
@@ -1085,7 +1121,7 @@ export class RouteImplementation {
|
|
|
1085
1121
|
});
|
|
1086
1122
|
}
|
|
1087
1123
|
middleware(origReq, res, next) {
|
|
1088
|
-
const req = this.coreOptions.buildGenericRequestInfo(origReq);
|
|
1124
|
+
const { internal: req } = this.coreOptions.buildGenericRequestInfo(origReq);
|
|
1089
1125
|
let theUrl = req.url?.toString() || '';
|
|
1090
1126
|
if (theUrl.startsWith('/'))
|
|
1091
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 () {
|