remult 3.0.4 → 3.0.5
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/async-hooks.d.ts +1 -0
- package/async-hooks.js +5 -0
- package/esm/async-hooks.js +1 -0
- package/esm/server/initAsyncHooks.js +25 -0
- package/esm/src/context.js +5 -4
- package/package.json +6 -1
- package/server/initAsyncHooks.d.ts +25 -0
- package/server/initAsyncHooks.js +25 -0
- package/src/column-interfaces.d.ts +4 -1
- package/src/context.js +5 -5
package/async-hooks.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { initAsyncHooks } from './server/initAsyncHooks.js';
|
package/async-hooks.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initAsyncHooks = void 0;
|
|
4
|
+
var initAsyncHooks_js_1 = require("./server/initAsyncHooks.js");
|
|
5
|
+
Object.defineProperty(exports, "initAsyncHooks", { enumerable: true, get: function () { return initAsyncHooks_js_1.initAsyncHooks; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { initAsyncHooks } from './server/initAsyncHooks.js';
|
|
@@ -2,6 +2,31 @@ import { AsyncLocalStorage } from 'async_hooks';
|
|
|
2
2
|
import { RemultAsyncLocalStorage, } from '../src/context.js';
|
|
3
3
|
import { remultStatic } from '../src/remult-static.js';
|
|
4
4
|
let init = false;
|
|
5
|
+
/**
|
|
6
|
+
* Initializes async context tracking for the server.
|
|
7
|
+
*
|
|
8
|
+
* This should be called before handling any incoming requests or calling `withRemult()`.
|
|
9
|
+
* @example
|
|
10
|
+
* import { remult, repo, withRemult } from 'remult';
|
|
11
|
+
* import { initAsyncHooks } from 'remult/async-hooks';
|
|
12
|
+
*
|
|
13
|
+
* import { Task } from './entities/Task.js';
|
|
14
|
+
*
|
|
15
|
+
* initAsyncHooks();
|
|
16
|
+
*
|
|
17
|
+
* // Thx to the `initAsyncHooks` above,
|
|
18
|
+
* // we have isolated async contexts with multiple `withRemult()`,
|
|
19
|
+
* // without needing to initialize a `remultApi` all the time!
|
|
20
|
+
* withRemult(async () => {
|
|
21
|
+
* remult.user = { id: '42' };
|
|
22
|
+
* repo(Task).find()
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* withRemult(async () => {
|
|
26
|
+
* remult.user = { id: '21' };
|
|
27
|
+
* repo(Task).find()
|
|
28
|
+
* });
|
|
29
|
+
*/
|
|
5
30
|
export function initAsyncHooks() {
|
|
6
31
|
if (init)
|
|
7
32
|
return;
|
package/esm/src/context.js
CHANGED
|
@@ -10,6 +10,7 @@ import { verifyFieldRelationInfo } from './remult3/relationInfoMember.js';
|
|
|
10
10
|
import { remultStatic, resetFactory } from './remult-static.js';
|
|
11
11
|
import { initDataProvider } from '../server/initDataProvider.js';
|
|
12
12
|
import { SubscribableImp } from './remult3/SubscribableImp.js';
|
|
13
|
+
import { getEntitySettings } from './remult3/getEntityRef.js';
|
|
13
14
|
export class RemultAsyncLocalStorage {
|
|
14
15
|
remultObjectStorage;
|
|
15
16
|
static enable() {
|
|
@@ -65,10 +66,10 @@ export class Remult {
|
|
|
65
66
|
* @param dataProvider - an optional alternative data provider to use. Useful for writing to offline storage or an alternative data provider
|
|
66
67
|
*/
|
|
67
68
|
repo = (entity, dataProvider) => {
|
|
68
|
-
|
|
69
|
+
let info = getEntitySettings(entity)(remult);
|
|
69
70
|
if (dataProvider === undefined) {
|
|
70
|
-
if (info?.
|
|
71
|
-
const d = info.
|
|
71
|
+
if (info?.dataProvider) {
|
|
72
|
+
const d = info.dataProvider(this.dataProvider);
|
|
72
73
|
if (d instanceof Promise) {
|
|
73
74
|
dataProvider = new DataProviderPromiseWrapper(d);
|
|
74
75
|
}
|
|
@@ -85,7 +86,7 @@ export class Remult {
|
|
|
85
86
|
this.repCache.set(dataProvider, (dpCache = new Map()));
|
|
86
87
|
let r = dpCache.get(entity);
|
|
87
88
|
if (!r) {
|
|
88
|
-
dpCache.set(entity, (r = new RepositoryImplementation(entity, this, dataProvider,
|
|
89
|
+
dpCache.set(entity, (r = new RepositoryImplementation(entity, this, dataProvider, createOldEntity(entity, this))));
|
|
89
90
|
verifyFieldRelationInfo(r, this, dataProvider);
|
|
90
91
|
}
|
|
91
92
|
return r;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "remult",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.5",
|
|
4
4
|
"description": "A CRUD framework for full-stack TypeScript",
|
|
5
5
|
"homepage": "https://remult.dev",
|
|
6
6
|
"repository": {
|
|
@@ -41,6 +41,11 @@
|
|
|
41
41
|
"import": "./esm/remult-next.js",
|
|
42
42
|
"types": "./remult-next.d.ts"
|
|
43
43
|
},
|
|
44
|
+
"./async-hooks": {
|
|
45
|
+
"require": "./async-hooks.js",
|
|
46
|
+
"import": "./esm/async-hooks.js",
|
|
47
|
+
"types": "./async-hooks.d.ts"
|
|
48
|
+
},
|
|
44
49
|
"./server": {
|
|
45
50
|
"require": "./server/index.js",
|
|
46
51
|
"import": "./esm/server/index.js",
|
|
@@ -1,4 +1,29 @@
|
|
|
1
1
|
import { type RemultAsyncLocalStorageCore } from '../src/context.js';
|
|
2
|
+
/**
|
|
3
|
+
* Initializes async context tracking for the server.
|
|
4
|
+
*
|
|
5
|
+
* This should be called before handling any incoming requests or calling `withRemult()`.
|
|
6
|
+
* @example
|
|
7
|
+
* import { remult, repo, withRemult } from 'remult';
|
|
8
|
+
* import { initAsyncHooks } from 'remult/async-hooks';
|
|
9
|
+
*
|
|
10
|
+
* import { Task } from './entities/Task.js';
|
|
11
|
+
*
|
|
12
|
+
* initAsyncHooks();
|
|
13
|
+
*
|
|
14
|
+
* // Thx to the `initAsyncHooks` above,
|
|
15
|
+
* // we have isolated async contexts with multiple `withRemult()`,
|
|
16
|
+
* // without needing to initialize a `remultApi` all the time!
|
|
17
|
+
* withRemult(async () => {
|
|
18
|
+
* remult.user = { id: '42' };
|
|
19
|
+
* repo(Task).find()
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* withRemult(async () => {
|
|
23
|
+
* remult.user = { id: '21' };
|
|
24
|
+
* repo(Task).find()
|
|
25
|
+
* });
|
|
26
|
+
*/
|
|
2
27
|
export declare function initAsyncHooks(): void;
|
|
3
28
|
export declare class AsyncLocalStorageBridgeToRemultAsyncLocalStorageCoreImpl<T> implements RemultAsyncLocalStorageCore<T> {
|
|
4
29
|
private asyncLocalStorage;
|
package/server/initAsyncHooks.js
CHANGED
|
@@ -7,6 +7,31 @@ var async_hooks_1 = require("async_hooks");
|
|
|
7
7
|
var context_js_1 = require("../src/context.js");
|
|
8
8
|
var remult_static_js_1 = require("../src/remult-static.js");
|
|
9
9
|
var init = false;
|
|
10
|
+
/**
|
|
11
|
+
* Initializes async context tracking for the server.
|
|
12
|
+
*
|
|
13
|
+
* This should be called before handling any incoming requests or calling `withRemult()`.
|
|
14
|
+
* @example
|
|
15
|
+
* import { remult, repo, withRemult } from 'remult';
|
|
16
|
+
* import { initAsyncHooks } from 'remult/async-hooks';
|
|
17
|
+
*
|
|
18
|
+
* import { Task } from './entities/Task.js';
|
|
19
|
+
*
|
|
20
|
+
* initAsyncHooks();
|
|
21
|
+
*
|
|
22
|
+
* // Thx to the `initAsyncHooks` above,
|
|
23
|
+
* // we have isolated async contexts with multiple `withRemult()`,
|
|
24
|
+
* // without needing to initialize a `remultApi` all the time!
|
|
25
|
+
* withRemult(async () => {
|
|
26
|
+
* remult.user = { id: '42' };
|
|
27
|
+
* repo(Task).find()
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* withRemult(async () => {
|
|
31
|
+
* remult.user = { id: '21' };
|
|
32
|
+
* repo(Task).find()
|
|
33
|
+
* });
|
|
34
|
+
*/
|
|
10
35
|
function initAsyncHooks() {
|
|
11
36
|
var _this = this;
|
|
12
37
|
if (init)
|
|
@@ -9,7 +9,10 @@ export interface FieldOptions<entityType = unknown, valueType = unknown> {
|
|
|
9
9
|
caption?: string;
|
|
10
10
|
/** If it can store null in the database */
|
|
11
11
|
allowNull?: boolean;
|
|
12
|
-
/** If a value is required
|
|
12
|
+
/** If a value is required. Short-cut to say `validate: Validators.required`.
|
|
13
|
+
@see option [validate](https://remult.dev/docs/ref_field#validate) below
|
|
14
|
+
@see validator [required](https://remult.dev/docs/ref_validators#required)
|
|
15
|
+
*/
|
|
13
16
|
required?: boolean;
|
|
14
17
|
/**
|
|
15
18
|
* Specifies whether this field should be included in the API. This can be configured
|
package/src/context.js
CHANGED
|
@@ -18,6 +18,7 @@ var relationInfoMember_js_1 = require("./remult3/relationInfoMember.js");
|
|
|
18
18
|
var remult_static_js_1 = require("./remult-static.js");
|
|
19
19
|
var initDataProvider_js_1 = require("../server/initDataProvider.js");
|
|
20
20
|
var SubscribableImp_js_1 = require("./remult3/SubscribableImp.js");
|
|
21
|
+
var getEntityRef_js_1 = require("./remult3/getEntityRef.js");
|
|
21
22
|
var RemultAsyncLocalStorage = /** @class */ (function () {
|
|
22
23
|
function RemultAsyncLocalStorage(remultObjectStorage) {
|
|
23
24
|
this.remultObjectStorage = remultObjectStorage;
|
|
@@ -83,11 +84,10 @@ var Remult = /** @class */ (function () {
|
|
|
83
84
|
* @param dataProvider - an optional alternative data provider to use. Useful for writing to offline storage or an alternative data provider
|
|
84
85
|
*/
|
|
85
86
|
this.repo = function (entity, dataProvider) {
|
|
86
|
-
var
|
|
87
|
-
var info = (0, RepositoryImplementation_js_1.createOldEntity)(entity, _this);
|
|
87
|
+
var info = (0, getEntityRef_js_1.getEntitySettings)(entity)(remult_proxy_js_1.remult);
|
|
88
88
|
if (dataProvider === undefined) {
|
|
89
|
-
if (
|
|
90
|
-
var d = info.
|
|
89
|
+
if (info === null || info === void 0 ? void 0 : info.dataProvider) {
|
|
90
|
+
var d = info.dataProvider(_this.dataProvider);
|
|
91
91
|
if (d instanceof Promise) {
|
|
92
92
|
dataProvider = new data_interfaces_js_1.DataProviderPromiseWrapper(d);
|
|
93
93
|
}
|
|
@@ -104,7 +104,7 @@ var Remult = /** @class */ (function () {
|
|
|
104
104
|
_this.repCache.set(dataProvider, (dpCache = new Map()));
|
|
105
105
|
var r = dpCache.get(entity);
|
|
106
106
|
if (!r) {
|
|
107
|
-
dpCache.set(entity, (r = new RepositoryImplementation_js_1.RepositoryImplementation(entity, _this, dataProvider,
|
|
107
|
+
dpCache.set(entity, (r = new RepositoryImplementation_js_1.RepositoryImplementation(entity, _this, dataProvider, (0, RepositoryImplementation_js_1.createOldEntity)(entity, _this))));
|
|
108
108
|
(0, relationInfoMember_js_1.verifyFieldRelationInfo)(r, _this, dataProvider);
|
|
109
109
|
}
|
|
110
110
|
return r;
|