remult 3.0.6 → 3.0.7-next.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/README.md +2 -2
- package/async-hooks.d.ts +26 -1
- package/async-hooks.js +31 -2
- package/esm/async-hooks.js +31 -1
- package/esm/remult-express.js +13 -4
- package/esm/server/get-remult-admin-html.js +1 -1
- package/esm/server/initAsyncHooks.js +0 -25
- package/esm/src/remult-static.js +1 -0
- package/esm/src/remult3/Fields.js +49 -30
- package/esm/src/remult3/IdEntity.js +1 -1
- package/esm/src/remult3/entity.js +1 -1
- package/package.json +5 -3
- package/remult-express.js +13 -4
- package/server/get-remult-admin-html.js +1 -1
- package/server/initAsyncHooks.d.ts +0 -25
- package/server/initAsyncHooks.js +0 -25
- package/server/remult-api-server.d.ts +1 -1
- package/src/column-interfaces.d.ts +4 -3
- package/src/remult-static.d.ts +1 -0
- package/src/remult-static.js +1 -0
- package/src/remult3/Fields.d.ts +34 -4
- package/src/remult3/Fields.js +50 -40
- package/src/remult3/IdEntity.js +1 -1
- package/src/remult3/RepositoryImplementation.d.ts +1 -1
- package/src/remult3/entity.d.ts +1 -1
- package/src/remult3/entity.js +1 -1
package/README.md
CHANGED
|
@@ -76,7 +76,7 @@ import { Entity, Fields } from 'remult'
|
|
|
76
76
|
allowApiCrud: true,
|
|
77
77
|
})
|
|
78
78
|
export class Product {
|
|
79
|
-
@Fields.
|
|
79
|
+
@Fields.id()
|
|
80
80
|
id = ''
|
|
81
81
|
|
|
82
82
|
@Fields.string()
|
|
@@ -166,7 +166,7 @@ import { Entity, Fields, Validators } from 'remult'
|
|
|
166
166
|
allowApiCrud: true,
|
|
167
167
|
})
|
|
168
168
|
export class Product {
|
|
169
|
-
@Fields.
|
|
169
|
+
@Fields.id()
|
|
170
170
|
id = ''
|
|
171
171
|
|
|
172
172
|
@Fields.string({
|
package/async-hooks.d.ts
CHANGED
|
@@ -1 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Initializes and enables async context tracking for the server.
|
|
3
|
+
*
|
|
4
|
+
* This should be called before handling any incoming requests or calling `withRemult()`.
|
|
5
|
+
* @example
|
|
6
|
+
* import { remult, repo, withRemult } from 'remult';
|
|
7
|
+
* import { initAsyncHooks } from 'remult/async-hooks';
|
|
8
|
+
*
|
|
9
|
+
* import { Task } from './entities/Task.js';
|
|
10
|
+
*
|
|
11
|
+
* initAsyncHooks();
|
|
12
|
+
*
|
|
13
|
+
* // Thx to the `initAsyncHooks` above,
|
|
14
|
+
* // we have isolated async contexts with multiple `withRemult()`,
|
|
15
|
+
* // without needing to initialize a `remultApi` all the time!
|
|
16
|
+
* withRemult(async () => {
|
|
17
|
+
* remult.user = { id: '42' };
|
|
18
|
+
* repo(Task).find()
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* withRemult(async () => {
|
|
22
|
+
* remult.user = { id: '21' };
|
|
23
|
+
* repo(Task).find()
|
|
24
|
+
* });
|
|
25
|
+
*/
|
|
26
|
+
export declare function initAsyncHooks(): void;
|
package/async-hooks.js
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.initAsyncHooks =
|
|
3
|
+
exports.initAsyncHooks = initAsyncHooks;
|
|
4
|
+
var context_js_1 = require("./src/context.js");
|
|
4
5
|
var initAsyncHooks_js_1 = require("./server/initAsyncHooks.js");
|
|
5
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Initializes and enables async context tracking for the server.
|
|
8
|
+
*
|
|
9
|
+
* This should be called before handling any incoming requests or calling `withRemult()`.
|
|
10
|
+
* @example
|
|
11
|
+
* import { remult, repo, withRemult } from 'remult';
|
|
12
|
+
* import { initAsyncHooks } from 'remult/async-hooks';
|
|
13
|
+
*
|
|
14
|
+
* import { Task } from './entities/Task.js';
|
|
15
|
+
*
|
|
16
|
+
* initAsyncHooks();
|
|
17
|
+
*
|
|
18
|
+
* // Thx to the `initAsyncHooks` above,
|
|
19
|
+
* // we have isolated async contexts with multiple `withRemult()`,
|
|
20
|
+
* // without needing to initialize a `remultApi` all the time!
|
|
21
|
+
* withRemult(async () => {
|
|
22
|
+
* remult.user = { id: '42' };
|
|
23
|
+
* repo(Task).find()
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* withRemult(async () => {
|
|
27
|
+
* remult.user = { id: '21' };
|
|
28
|
+
* repo(Task).find()
|
|
29
|
+
* });
|
|
30
|
+
*/
|
|
31
|
+
function initAsyncHooks() {
|
|
32
|
+
(0, initAsyncHooks_js_1.initAsyncHooks)();
|
|
33
|
+
context_js_1.RemultAsyncLocalStorage.enable();
|
|
34
|
+
}
|
package/esm/async-hooks.js
CHANGED
|
@@ -1 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
import { RemultAsyncLocalStorage } from './src/context.js';
|
|
2
|
+
import { initAsyncHooks as _initAsyncHooks } from './server/initAsyncHooks.js';
|
|
3
|
+
/**
|
|
4
|
+
* Initializes and enables async context tracking for the server.
|
|
5
|
+
*
|
|
6
|
+
* This should be called before handling any incoming requests or calling `withRemult()`.
|
|
7
|
+
* @example
|
|
8
|
+
* import { remult, repo, withRemult } from 'remult';
|
|
9
|
+
* import { initAsyncHooks } from 'remult/async-hooks';
|
|
10
|
+
*
|
|
11
|
+
* import { Task } from './entities/Task.js';
|
|
12
|
+
*
|
|
13
|
+
* initAsyncHooks();
|
|
14
|
+
*
|
|
15
|
+
* // Thx to the `initAsyncHooks` above,
|
|
16
|
+
* // we have isolated async contexts with multiple `withRemult()`,
|
|
17
|
+
* // without needing to initialize a `remultApi` all the time!
|
|
18
|
+
* withRemult(async () => {
|
|
19
|
+
* remult.user = { id: '42' };
|
|
20
|
+
* repo(Task).find()
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* withRemult(async () => {
|
|
24
|
+
* remult.user = { id: '21' };
|
|
25
|
+
* repo(Task).find()
|
|
26
|
+
* });
|
|
27
|
+
*/
|
|
28
|
+
export function initAsyncHooks() {
|
|
29
|
+
_initAsyncHooks();
|
|
30
|
+
RemultAsyncLocalStorage.enable();
|
|
31
|
+
}
|
package/esm/remult-express.js
CHANGED
|
@@ -8,15 +8,24 @@ export function remultApi(options) {
|
|
|
8
8
|
if (options.bodySizeLimit === undefined) {
|
|
9
9
|
options.bodySizeLimit = '10mb';
|
|
10
10
|
}
|
|
11
|
+
const expressVersion = typeof app.del === 'function' ? 4 : 5;
|
|
11
12
|
if (options?.bodyParser !== false) {
|
|
12
13
|
app.use(express.json({ limit: options.bodySizeLimit }));
|
|
13
14
|
app.use(express.urlencoded({ extended: true, limit: options.bodySizeLimit }));
|
|
14
15
|
}
|
|
15
16
|
const server = createRemultServer(options, {
|
|
16
|
-
buildGenericRequestInfo: (req) =>
|
|
17
|
-
internal
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
buildGenericRequestInfo: (req) => {
|
|
18
|
+
const internal = { ...req, on: req.on };
|
|
19
|
+
if (expressVersion === 5) {
|
|
20
|
+
if (!internal.query) {
|
|
21
|
+
internal.query = req.query;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
internal,
|
|
26
|
+
public: { headers: new Headers(req.headers) },
|
|
27
|
+
};
|
|
28
|
+
},
|
|
20
29
|
getRequestBody: async (req) => req.body,
|
|
21
30
|
});
|
|
22
31
|
server.registerRouter(app);
|