remult 0.16.0-exp.9 → 0.16.2-exp.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 +1 -1
- package/esm/remult-fastify.js +2 -1
- package/esm/server/expressBridge.d.ts +1 -1
- package/esm/server/expressBridge.js +38 -14
- package/esm/src/backend-tests/test-http-server.backend-spec.js +4 -6
- package/esm/src/context.d.ts +2 -2
- package/esm/src/data-providers/rest-data-provider.d.ts +4 -1
- package/esm/src/data-providers/rest-data-provider.js +17 -10
- package/esm/src/entity.d.ts +1 -1
- package/esm/src/remult3/RepositoryImplementation.js +1 -1
- package/esm/src/remult3/remult3.d.ts +1 -1
- package/package.json +49 -1
- package/remult-express.js +2 -2
- package/remult-fastify.js +2 -1
- package/server/expressBridge.d.ts +1 -1
- package/server/expressBridge.js +49 -14
- package/src/backend-tests/test-http-server.backend-spec.js +7 -9
- package/src/context.d.ts +2 -2
- package/src/data-providers/rest-data-provider.d.ts +4 -1
- package/src/data-providers/rest-data-provider.js +28 -10
- package/src/entity.d.ts +1 -1
- package/src/remult3/RepositoryImplementation.js +1 -1
- package/src/remult3/remult3.d.ts +1 -1
package/esm/remult-express.js
CHANGED
|
@@ -18,6 +18,6 @@ export function remultExpress(options) {
|
|
|
18
18
|
getRemult: (req) => server.getRemult(req),
|
|
19
19
|
openApiDoc: (options) => server.openApiDoc(options),
|
|
20
20
|
registerRouter: x => server.registerRouter(x),
|
|
21
|
-
|
|
21
|
+
withRemult: (...args) => server.withRemult(...args)
|
|
22
22
|
});
|
|
23
23
|
}
|
package/esm/remult-fastify.js
CHANGED
|
@@ -47,6 +47,7 @@ export function remultFastify(options) {
|
|
|
47
47
|
return Object.assign(pluginFunction, {
|
|
48
48
|
getRemult: x => api.getRemult(x),
|
|
49
49
|
openApiDoc: x => api.openApiDoc(x),
|
|
50
|
-
handle: (req, res) => api.handle(req, res)
|
|
50
|
+
handle: (req, res) => api.handle(req, res),
|
|
51
|
+
withRemult: (req, res, next) => api.withRemult(req, res, next)
|
|
51
52
|
});
|
|
52
53
|
}
|
|
@@ -33,7 +33,7 @@ export interface RemultServer {
|
|
|
33
33
|
}): any;
|
|
34
34
|
registerRouter(r: GenericRouter): void;
|
|
35
35
|
handle(req: GenericRequest, gRes?: GenericResponse): Promise<ServerHandleResponse | undefined>;
|
|
36
|
-
|
|
36
|
+
withRemult(req: GenericRequest, res: GenericResponse, next: VoidFunction): any;
|
|
37
37
|
}
|
|
38
38
|
export declare type GenericRouter = {
|
|
39
39
|
route(path: string): SpecificRoute;
|
|
@@ -4,7 +4,6 @@ import { DataApi, serializeError } from '../src/data-api';
|
|
|
4
4
|
import { allEntities, Remult } from '../src/context';
|
|
5
5
|
import { Entity, Fields, getEntityKey } from '../src/remult3';
|
|
6
6
|
import { IdEntity } from '../src/id-entity';
|
|
7
|
-
import { AsyncLocalStorage } from 'async_hooks';
|
|
8
7
|
import { remult } from '../src/remult-proxy';
|
|
9
8
|
;
|
|
10
9
|
export function createRemultServer(options) {
|
|
@@ -31,6 +30,25 @@ export function createRemultServer(options) {
|
|
|
31
30
|
return dp;
|
|
32
31
|
return new (await import('./JsonEntityFileStorage')).JsonFileDataProvider('./db');
|
|
33
32
|
});
|
|
33
|
+
if (!remultObjectStorage) {
|
|
34
|
+
dataProvider = dataProvider.then(async (dp) => {
|
|
35
|
+
try {
|
|
36
|
+
const asyncHooks = await import('async_hooks');
|
|
37
|
+
remultObjectStorage = new RemultAsyncLocalStorage(new asyncHooks.AsyncLocalStorage());
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
remultObjectStorage = new RemultAsyncLocalStorage(undefined);
|
|
41
|
+
}
|
|
42
|
+
remult.remultFactory = () => {
|
|
43
|
+
const r = remultObjectStorage.getRemult();
|
|
44
|
+
if (r)
|
|
45
|
+
return r;
|
|
46
|
+
else
|
|
47
|
+
throw new Error("remult object was requested outside of a valid context, try running it within initApi or a remult request cycle");
|
|
48
|
+
};
|
|
49
|
+
return dp;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
34
52
|
if (options.initApi) {
|
|
35
53
|
dataProvider = dataProvider.then(async (dp) => {
|
|
36
54
|
var remult = new Remult(dp);
|
|
@@ -60,8 +78,24 @@ export function createRemultServer(options) {
|
|
|
60
78
|
return bridge;
|
|
61
79
|
}
|
|
62
80
|
;
|
|
63
|
-
|
|
64
|
-
|
|
81
|
+
class RemultAsyncLocalStorage {
|
|
82
|
+
constructor(remultObjectStorage) {
|
|
83
|
+
this.remultObjectStorage = remultObjectStorage;
|
|
84
|
+
}
|
|
85
|
+
run(remult, callback) {
|
|
86
|
+
if (this.remultObjectStorage)
|
|
87
|
+
this.remultObjectStorage.run(remult, callback);
|
|
88
|
+
else
|
|
89
|
+
callback();
|
|
90
|
+
}
|
|
91
|
+
getRemult() {
|
|
92
|
+
if (!this.remultObjectStorage) {
|
|
93
|
+
throw "can't use static remult in this environment, `async_hooks` were not found";
|
|
94
|
+
}
|
|
95
|
+
return this.remultObjectStorage.getStore();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
let remultObjectStorage;
|
|
65
99
|
class RemultServerImplementation {
|
|
66
100
|
constructor(queue, options, dataProvider) {
|
|
67
101
|
this.queue = queue;
|
|
@@ -71,18 +105,8 @@ class RemultServerImplementation {
|
|
|
71
105
|
this.hasQueue = false;
|
|
72
106
|
/* internal */
|
|
73
107
|
this.backendMethodsOpenApi = [];
|
|
74
|
-
if (!remultObjectStorageWasSetup) {
|
|
75
|
-
remultObjectStorageWasSetup = true;
|
|
76
|
-
remult.remultFactory = () => {
|
|
77
|
-
const r = remultObjectStorage.getStore();
|
|
78
|
-
if (r)
|
|
79
|
-
return r;
|
|
80
|
-
else
|
|
81
|
-
throw new Error("remult object was requested outside of a valid context, try running it within initApi or a remult request cycle");
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
108
|
}
|
|
85
|
-
|
|
109
|
+
withRemult(req, res, next) {
|
|
86
110
|
this.process(async () => { next(); })(req, res);
|
|
87
111
|
}
|
|
88
112
|
handle(req, gRes) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import axios from 'axios';
|
|
3
3
|
import { remultFresh } from '../../remult-fresh';
|
|
4
|
-
import { Remult } from '../context';
|
|
5
4
|
import { InMemoryDataProvider } from '../data-providers/in-memory-database';
|
|
6
5
|
import { remult } from '../remult-proxy';
|
|
7
6
|
import { Entity, Fields } from '../remult3';
|
|
@@ -12,10 +11,10 @@ let path = remult.apiClient.url + '/tasks';
|
|
|
12
11
|
const environments = [
|
|
13
12
|
// ["next", 3000],
|
|
14
13
|
// ["nest", 3001],
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
14
|
+
// ["koa", 3002],
|
|
15
|
+
// ["fastify", 3003],
|
|
16
|
+
// ["express", 3004],
|
|
17
|
+
// ["generic server", 3005],
|
|
19
18
|
// ["optine", 3006],
|
|
20
19
|
// ["fresh", 8000]
|
|
21
20
|
];
|
|
@@ -160,7 +159,6 @@ Task = __decorate([
|
|
|
160
159
|
], Task);
|
|
161
160
|
export { Task };
|
|
162
161
|
async function create3Tasks() {
|
|
163
|
-
const remult = new Remult(axios);
|
|
164
162
|
remult.apiClient.httpClient = axios;
|
|
165
163
|
const taskRepo = remult.repo(Task);
|
|
166
164
|
for (const task of await taskRepo.find()) {
|
package/esm/src/context.d.ts
CHANGED
|
@@ -94,8 +94,8 @@ export declare function buildRestDataProvider(provider: ExternalHttpProvider | t
|
|
|
94
94
|
export declare function setControllerSettings(target: any, options: ControllerOptions): void;
|
|
95
95
|
export interface UserInfo {
|
|
96
96
|
id: string;
|
|
97
|
-
name
|
|
98
|
-
roles
|
|
97
|
+
name?: string;
|
|
98
|
+
roles?: string[];
|
|
99
99
|
}
|
|
100
100
|
export declare type Allowed = boolean | string | string[] | ((c: Remult) => boolean);
|
|
101
101
|
export declare type AllowedForInstance<T> = boolean | string | string[] | ((c: Remult, entity?: T) => boolean);
|
|
@@ -30,6 +30,9 @@ export declare class RestDataProviderHttpProviderUsingFetch implements RestDataP
|
|
|
30
30
|
put(url: string, data: any): Promise<any>;
|
|
31
31
|
delete(url: string): Promise<any>;
|
|
32
32
|
post(url: string, data: any): Promise<any>;
|
|
33
|
-
myFetch(url: string,
|
|
33
|
+
myFetch(url: string, options?: {
|
|
34
|
+
method?: string;
|
|
35
|
+
body?: string;
|
|
36
|
+
}): Promise<any>;
|
|
34
37
|
}
|
|
35
38
|
export declare function addFilterToUrlAndReturnTrueIfSuccessful(filter: any, url: UrlBuilder): boolean;
|
|
@@ -122,7 +122,7 @@ export class RestDataProviderHttpProviderUsingFetch {
|
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
124
|
delete(url) {
|
|
125
|
-
return this.myFetch(url, { method: 'delete'
|
|
125
|
+
return this.myFetch(url, { method: 'delete' });
|
|
126
126
|
}
|
|
127
127
|
async post(url, data) {
|
|
128
128
|
return await retry(() => this.myFetch(url, {
|
|
@@ -130,15 +130,22 @@ export class RestDataProviderHttpProviderUsingFetch {
|
|
|
130
130
|
body: JSON.stringify(data)
|
|
131
131
|
}));
|
|
132
132
|
}
|
|
133
|
-
myFetch(url,
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
133
|
+
myFetch(url, options) {
|
|
134
|
+
const headers = {
|
|
135
|
+
"Content-type": "application/json"
|
|
136
|
+
};
|
|
137
|
+
if (typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof (window.document.cookie !== 'undefined'))
|
|
138
|
+
for (const cookie of window.document.cookie.split(';')) {
|
|
139
|
+
if (cookie.trim().startsWith('XSRF-TOKEN=')) {
|
|
140
|
+
headers['X-XSRF-TOKEN'] = cookie.split('=')[1];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return (this.fetch || fetch)(url, {
|
|
144
|
+
credentials: 'include',
|
|
145
|
+
method: options?.method,
|
|
146
|
+
body: options?.body,
|
|
147
|
+
headers
|
|
148
|
+
}).then(response => {
|
|
142
149
|
return onSuccess(response);
|
|
143
150
|
}).catch(async (error) => {
|
|
144
151
|
let r = await error;
|
package/esm/src/entity.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export interface EntityOptions<entityType = any> {
|
|
|
42
42
|
*/
|
|
43
43
|
defaultOrderBy?: EntityOrderBy<entityType>;
|
|
44
44
|
/** An event that will be fired before the Entity will be saved to the database.
|
|
45
|
-
* If the `error` property of the entity's ref or any of
|
|
45
|
+
* If the `error` property of the entity's ref or any of its fields will be set, the save will be aborted and an exception will be thrown.
|
|
46
46
|
* this is the place to run logic that we want to run in any case before an entity is saved.
|
|
47
47
|
* @example
|
|
48
48
|
* @Entity<Task>("tasks", {
|
|
@@ -693,7 +693,7 @@ export class rowHelperImplementation extends rowHelperBase {
|
|
|
693
693
|
this.metadata = info;
|
|
694
694
|
if (_isNew) {
|
|
695
695
|
for (const col of info.columnsInfo) {
|
|
696
|
-
if (col.defaultValue) {
|
|
696
|
+
if (col.defaultValue && instance[col.key] === undefined) {
|
|
697
697
|
if (typeof col.defaultValue === "function") {
|
|
698
698
|
instance[col.key] = col.defaultValue(instance);
|
|
699
699
|
}
|
|
@@ -157,7 +157,7 @@ export interface Repository<entityType> {
|
|
|
157
157
|
*/
|
|
158
158
|
insert(item: Partial<OmitEB<entityType>>[]): Promise<entityType[]>;
|
|
159
159
|
insert(item: Partial<OmitEB<entityType>>): Promise<entityType>;
|
|
160
|
-
/** Updates an item, based on
|
|
160
|
+
/** Updates an item, based on its `id`
|
|
161
161
|
* @example
|
|
162
162
|
* taskRepo.update(task.id,{...task,completed:true})
|
|
163
163
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "remult",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.2-exp.1",
|
|
4
4
|
"description": "A CRUD framework for full-stack TypeScript",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -23,50 +23,98 @@
|
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
25
25
|
"require": "./index.js",
|
|
26
|
+
"node": {
|
|
27
|
+
"require": "./index.js",
|
|
28
|
+
"import": "./index.js"
|
|
29
|
+
},
|
|
26
30
|
"import": "./esm/index.js"
|
|
27
31
|
},
|
|
28
32
|
"./remult-express": {
|
|
29
33
|
"require": "./remult-express.js",
|
|
34
|
+
"node": {
|
|
35
|
+
"require": "./remult-express.js",
|
|
36
|
+
"import": "./remult-express.js"
|
|
37
|
+
},
|
|
30
38
|
"import": "./esm/remult-express.js"
|
|
31
39
|
},
|
|
32
40
|
"./server": {
|
|
33
41
|
"require": "./server/index.js",
|
|
42
|
+
"node": {
|
|
43
|
+
"require": "./server/index.js",
|
|
44
|
+
"import": "./server/index.js"
|
|
45
|
+
},
|
|
34
46
|
"import": "./esm/server/index.js"
|
|
35
47
|
},
|
|
36
48
|
"./remult-fastify": {
|
|
37
49
|
"require": "./remult-fastify.js",
|
|
50
|
+
"node": {
|
|
51
|
+
"require": "./remult-fastify.js",
|
|
52
|
+
"import": "./remult-fastify.js"
|
|
53
|
+
},
|
|
38
54
|
"import": "./esm/remult-fastify.js"
|
|
39
55
|
},
|
|
40
56
|
"./remult-fresh": {
|
|
41
57
|
"require": "./remult-fresh.js",
|
|
58
|
+
"node": {
|
|
59
|
+
"require": "./remult-fresh.js",
|
|
60
|
+
"import": "./remult-fresh.js"
|
|
61
|
+
},
|
|
42
62
|
"import": "./esm/remult-fresh.js"
|
|
43
63
|
},
|
|
44
64
|
"./postgres": {
|
|
45
65
|
"require": "./postgres/index.js",
|
|
66
|
+
"node": {
|
|
67
|
+
"require": "./postgres/index.js",
|
|
68
|
+
"import": "./postgres/index.js"
|
|
69
|
+
},
|
|
46
70
|
"import": "./esm/postgres/index.js"
|
|
47
71
|
},
|
|
48
72
|
"./postgres/schema-builder": {
|
|
49
73
|
"require": "./postgres/schema-builder.js",
|
|
74
|
+
"node": {
|
|
75
|
+
"require": "./postgres/schema-builder.js",
|
|
76
|
+
"import": "./postgres/schema-builder.js"
|
|
77
|
+
},
|
|
50
78
|
"import": "./esm/postgres/schema-builder.js"
|
|
51
79
|
},
|
|
52
80
|
"./remult-knex": {
|
|
53
81
|
"require": "./remult-knex/index.js",
|
|
82
|
+
"node": {
|
|
83
|
+
"require": "./remult-knex/index.js",
|
|
84
|
+
"import": "./remult-knex/index.js"
|
|
85
|
+
},
|
|
54
86
|
"import": "./esm/remult-knex/index.js"
|
|
55
87
|
},
|
|
56
88
|
"./remult-mongo": {
|
|
57
89
|
"require": "./remult-mongo.js",
|
|
90
|
+
"node": {
|
|
91
|
+
"require": "./remult-mongo.js",
|
|
92
|
+
"import": "./remult-mongo.js"
|
|
93
|
+
},
|
|
58
94
|
"import": "./esm/remult-mongo.js"
|
|
59
95
|
},
|
|
60
96
|
"./graphql": {
|
|
61
97
|
"require": "./graphql.js",
|
|
98
|
+
"node": {
|
|
99
|
+
"require": "./graphql.js",
|
|
100
|
+
"import": "./graphql.js"
|
|
101
|
+
},
|
|
62
102
|
"import": "./esm/graphql.js"
|
|
63
103
|
},
|
|
64
104
|
"./src/remult3": {
|
|
65
105
|
"require": "./src/remult3/index.js",
|
|
106
|
+
"node": {
|
|
107
|
+
"require": "./src/remult3/index.js",
|
|
108
|
+
"import": "./src/remult3/index.js"
|
|
109
|
+
},
|
|
66
110
|
"import": "./esm/src/remult3/index.js"
|
|
67
111
|
},
|
|
68
112
|
"./src/server-action": {
|
|
69
113
|
"require": "./src/server-action.js",
|
|
114
|
+
"node": {
|
|
115
|
+
"require": "./src/server-action.js",
|
|
116
|
+
"import": "./src/server-action.js"
|
|
117
|
+
},
|
|
70
118
|
"import": "./esm/src/server-action.js"
|
|
71
119
|
}
|
|
72
120
|
}
|
package/remult-express.js
CHANGED
|
@@ -22,12 +22,12 @@ function remultExpress(options) {
|
|
|
22
22
|
getRemult: function (req) { return server.getRemult(req); },
|
|
23
23
|
openApiDoc: function (options) { return server.openApiDoc(options); },
|
|
24
24
|
registerRouter: function (x) { return server.registerRouter(x); },
|
|
25
|
-
|
|
25
|
+
withRemult: function () {
|
|
26
26
|
var args = [];
|
|
27
27
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
28
28
|
args[_i] = arguments[_i];
|
|
29
29
|
}
|
|
30
|
-
return server.
|
|
30
|
+
return server.withRemult.apply(server, tslib_1.__spread(args));
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
}
|
package/remult-fastify.js
CHANGED
|
@@ -55,7 +55,8 @@ function remultFastify(options) {
|
|
|
55
55
|
return Object.assign(pluginFunction, {
|
|
56
56
|
getRemult: function (x) { return api.getRemult(x); },
|
|
57
57
|
openApiDoc: function (x) { return api.openApiDoc(x); },
|
|
58
|
-
handle: function (req, res) { return api.handle(req, res); }
|
|
58
|
+
handle: function (req, res) { return api.handle(req, res); },
|
|
59
|
+
withRemult: function (req, res, next) { return api.withRemult(req, res, next); }
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
62
|
exports.remultFastify = remultFastify;
|
|
@@ -33,7 +33,7 @@ export interface RemultServer {
|
|
|
33
33
|
}): any;
|
|
34
34
|
registerRouter(r: GenericRouter): void;
|
|
35
35
|
handle(req: GenericRequest, gRes?: GenericResponse): Promise<ServerHandleResponse | undefined>;
|
|
36
|
-
|
|
36
|
+
withRemult(req: GenericRequest, res: GenericResponse, next: VoidFunction): any;
|
|
37
37
|
}
|
|
38
38
|
export declare type GenericRouter = {
|
|
39
39
|
route(path: string): SpecificRoute;
|
package/server/expressBridge.js
CHANGED
|
@@ -7,7 +7,6 @@ var data_api_1 = require("../src/data-api");
|
|
|
7
7
|
var context_1 = require("../src/context");
|
|
8
8
|
var remult3_1 = require("../src/remult3");
|
|
9
9
|
var id_entity_1 = require("../src/id-entity");
|
|
10
|
-
var async_hooks_1 = require("async_hooks");
|
|
11
10
|
var remult_proxy_1 = require("../src/remult-proxy");
|
|
12
11
|
;
|
|
13
12
|
function createRemultServer(options) {
|
|
@@ -41,6 +40,35 @@ function createRemultServer(options) {
|
|
|
41
40
|
}
|
|
42
41
|
});
|
|
43
42
|
}); });
|
|
43
|
+
if (!remultObjectStorage) {
|
|
44
|
+
dataProvider = dataProvider.then(function (dp) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
45
|
+
var asyncHooks, _a;
|
|
46
|
+
return tslib_1.__generator(this, function (_b) {
|
|
47
|
+
switch (_b.label) {
|
|
48
|
+
case 0:
|
|
49
|
+
_b.trys.push([0, 2, , 3]);
|
|
50
|
+
return [4 /*yield*/, Promise.resolve().then(function () { return require('async_hooks'); })];
|
|
51
|
+
case 1:
|
|
52
|
+
asyncHooks = _b.sent();
|
|
53
|
+
remultObjectStorage = new RemultAsyncLocalStorage(new asyncHooks.AsyncLocalStorage());
|
|
54
|
+
return [3 /*break*/, 3];
|
|
55
|
+
case 2:
|
|
56
|
+
_a = _b.sent();
|
|
57
|
+
remultObjectStorage = new RemultAsyncLocalStorage(undefined);
|
|
58
|
+
return [3 /*break*/, 3];
|
|
59
|
+
case 3:
|
|
60
|
+
remult_proxy_1.remult.remultFactory = function () {
|
|
61
|
+
var r = remultObjectStorage.getRemult();
|
|
62
|
+
if (r)
|
|
63
|
+
return r;
|
|
64
|
+
else
|
|
65
|
+
throw new Error("remult object was requested outside of a valid context, try running it within initApi or a remult request cycle");
|
|
66
|
+
};
|
|
67
|
+
return [2 /*return*/, dp];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}); });
|
|
71
|
+
}
|
|
44
72
|
if (options.initApi) {
|
|
45
73
|
dataProvider = dataProvider.then(function (dp) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
46
74
|
var remult;
|
|
@@ -87,8 +115,25 @@ function createRemultServer(options) {
|
|
|
87
115
|
}
|
|
88
116
|
exports.createRemultServer = createRemultServer;
|
|
89
117
|
;
|
|
90
|
-
var
|
|
91
|
-
|
|
118
|
+
var RemultAsyncLocalStorage = /** @class */ (function () {
|
|
119
|
+
function RemultAsyncLocalStorage(remultObjectStorage) {
|
|
120
|
+
this.remultObjectStorage = remultObjectStorage;
|
|
121
|
+
}
|
|
122
|
+
RemultAsyncLocalStorage.prototype.run = function (remult, callback) {
|
|
123
|
+
if (this.remultObjectStorage)
|
|
124
|
+
this.remultObjectStorage.run(remult, callback);
|
|
125
|
+
else
|
|
126
|
+
callback();
|
|
127
|
+
};
|
|
128
|
+
RemultAsyncLocalStorage.prototype.getRemult = function () {
|
|
129
|
+
if (!this.remultObjectStorage) {
|
|
130
|
+
throw "can't use static remult in this environment, `async_hooks` were not found";
|
|
131
|
+
}
|
|
132
|
+
return this.remultObjectStorage.getStore();
|
|
133
|
+
};
|
|
134
|
+
return RemultAsyncLocalStorage;
|
|
135
|
+
}());
|
|
136
|
+
var remultObjectStorage;
|
|
92
137
|
var RemultServerImplementation = /** @class */ (function () {
|
|
93
138
|
function RemultServerImplementation(queue, options, dataProvider) {
|
|
94
139
|
this.queue = queue;
|
|
@@ -98,18 +143,8 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
98
143
|
this.hasQueue = false;
|
|
99
144
|
/* internal */
|
|
100
145
|
this.backendMethodsOpenApi = [];
|
|
101
|
-
if (!remultObjectStorageWasSetup) {
|
|
102
|
-
remultObjectStorageWasSetup = true;
|
|
103
|
-
remult_proxy_1.remult.remultFactory = function () {
|
|
104
|
-
var r = remultObjectStorage.getStore();
|
|
105
|
-
if (r)
|
|
106
|
-
return r;
|
|
107
|
-
else
|
|
108
|
-
throw new Error("remult object was requested outside of a valid context, try running it within initApi or a remult request cycle");
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
146
|
}
|
|
112
|
-
RemultServerImplementation.prototype.
|
|
147
|
+
RemultServerImplementation.prototype.withRemult = function (req, res, next) {
|
|
113
148
|
var _this = this;
|
|
114
149
|
this.process(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
115
150
|
next();
|
|
@@ -4,7 +4,6 @@ exports.Task = void 0;
|
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var axios_1 = require("axios");
|
|
6
6
|
var remult_fresh_1 = require("../../remult-fresh");
|
|
7
|
-
var context_1 = require("../context");
|
|
8
7
|
var in_memory_database_1 = require("../data-providers/in-memory-database");
|
|
9
8
|
var remult_proxy_1 = require("../remult-proxy");
|
|
10
9
|
var remult3_1 = require("../remult3");
|
|
@@ -15,10 +14,10 @@ var path = remult_proxy_1.remult.apiClient.url + '/tasks';
|
|
|
15
14
|
var environments = [
|
|
16
15
|
// ["next", 3000],
|
|
17
16
|
// ["nest", 3001],
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
17
|
+
// ["koa", 3002],
|
|
18
|
+
// ["fastify", 3003],
|
|
19
|
+
// ["express", 3004],
|
|
20
|
+
// ["generic server", 3005],
|
|
22
21
|
// ["optine", 3006],
|
|
23
22
|
// ["fresh", 8000]
|
|
24
23
|
];
|
|
@@ -289,14 +288,13 @@ var Task = /** @class */ (function () {
|
|
|
289
288
|
exports.Task = Task;
|
|
290
289
|
function create3Tasks() {
|
|
291
290
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
292
|
-
var
|
|
291
|
+
var taskRepo, _a, _b, task, e_2_1, _c, _d;
|
|
293
292
|
var e_2, _e;
|
|
294
293
|
return tslib_1.__generator(this, function (_f) {
|
|
295
294
|
switch (_f.label) {
|
|
296
295
|
case 0:
|
|
297
|
-
remult =
|
|
298
|
-
|
|
299
|
-
taskRepo = remult.repo(Task);
|
|
296
|
+
remult_proxy_1.remult.apiClient.httpClient = axios_1.default;
|
|
297
|
+
taskRepo = remult_proxy_1.remult.repo(Task);
|
|
300
298
|
_f.label = 1;
|
|
301
299
|
case 1:
|
|
302
300
|
_f.trys.push([1, 7, 8, 9]);
|
package/src/context.d.ts
CHANGED
|
@@ -94,8 +94,8 @@ export declare function buildRestDataProvider(provider: ExternalHttpProvider | t
|
|
|
94
94
|
export declare function setControllerSettings(target: any, options: ControllerOptions): void;
|
|
95
95
|
export interface UserInfo {
|
|
96
96
|
id: string;
|
|
97
|
-
name
|
|
98
|
-
roles
|
|
97
|
+
name?: string;
|
|
98
|
+
roles?: string[];
|
|
99
99
|
}
|
|
100
100
|
export declare type Allowed = boolean | string | string[] | ((c: Remult) => boolean);
|
|
101
101
|
export declare type AllowedForInstance<T> = boolean | string | string[] | ((c: Remult, entity?: T) => boolean);
|
|
@@ -30,6 +30,9 @@ export declare class RestDataProviderHttpProviderUsingFetch implements RestDataP
|
|
|
30
30
|
put(url: string, data: any): Promise<any>;
|
|
31
31
|
delete(url: string): Promise<any>;
|
|
32
32
|
post(url: string, data: any): Promise<any>;
|
|
33
|
-
myFetch(url: string,
|
|
33
|
+
myFetch(url: string, options?: {
|
|
34
|
+
method?: string;
|
|
35
|
+
body?: string;
|
|
36
|
+
}): Promise<any>;
|
|
34
37
|
}
|
|
35
38
|
export declare function addFilterToUrlAndReturnTrueIfSuccessful(filter: any, url: UrlBuilder): boolean;
|
|
@@ -189,7 +189,7 @@ var RestDataProviderHttpProviderUsingFetch = /** @class */ (function () {
|
|
|
189
189
|
});
|
|
190
190
|
};
|
|
191
191
|
RestDataProviderHttpProviderUsingFetch.prototype.delete = function (url) {
|
|
192
|
-
return this.myFetch(url, { method: 'delete'
|
|
192
|
+
return this.myFetch(url, { method: 'delete' });
|
|
193
193
|
};
|
|
194
194
|
RestDataProviderHttpProviderUsingFetch.prototype.post = function (url, data) {
|
|
195
195
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
@@ -205,16 +205,34 @@ var RestDataProviderHttpProviderUsingFetch = /** @class */ (function () {
|
|
|
205
205
|
});
|
|
206
206
|
});
|
|
207
207
|
};
|
|
208
|
-
RestDataProviderHttpProviderUsingFetch.prototype.myFetch = function (url,
|
|
208
|
+
RestDataProviderHttpProviderUsingFetch.prototype.myFetch = function (url, options) {
|
|
209
|
+
var e_4, _a;
|
|
209
210
|
var _this = this;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
211
|
+
var headers = {
|
|
212
|
+
"Content-type": "application/json"
|
|
213
|
+
};
|
|
214
|
+
if (typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof (window.document.cookie !== 'undefined'))
|
|
215
|
+
try {
|
|
216
|
+
for (var _b = tslib_1.__values(window.document.cookie.split(';')), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
217
|
+
var cookie = _c.value;
|
|
218
|
+
if (cookie.trim().startsWith('XSRF-TOKEN=')) {
|
|
219
|
+
headers['X-XSRF-TOKEN'] = cookie.split('=')[1];
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
224
|
+
finally {
|
|
225
|
+
try {
|
|
226
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
227
|
+
}
|
|
228
|
+
finally { if (e_4) throw e_4.error; }
|
|
229
|
+
}
|
|
230
|
+
return (this.fetch || fetch)(url, {
|
|
231
|
+
credentials: 'include',
|
|
232
|
+
method: options === null || options === void 0 ? void 0 : options.method,
|
|
233
|
+
body: options === null || options === void 0 ? void 0 : options.body,
|
|
234
|
+
headers: headers
|
|
235
|
+
}).then(function (response) {
|
|
218
236
|
return onSuccess(response);
|
|
219
237
|
}).catch(function (error) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
220
238
|
var r;
|
package/src/entity.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export interface EntityOptions<entityType = any> {
|
|
|
42
42
|
*/
|
|
43
43
|
defaultOrderBy?: EntityOrderBy<entityType>;
|
|
44
44
|
/** An event that will be fired before the Entity will be saved to the database.
|
|
45
|
-
* If the `error` property of the entity's ref or any of
|
|
45
|
+
* If the `error` property of the entity's ref or any of its fields will be set, the save will be aborted and an exception will be thrown.
|
|
46
46
|
* this is the place to run logic that we want to run in any case before an entity is saved.
|
|
47
47
|
* @example
|
|
48
48
|
* @Entity<Task>("tasks", {
|
|
@@ -1161,7 +1161,7 @@ var rowHelperImplementation = /** @class */ (function (_super) {
|
|
|
1161
1161
|
try {
|
|
1162
1162
|
for (var _b = tslib_1.__values(info.columnsInfo), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1163
1163
|
var col = _c.value;
|
|
1164
|
-
if (col.defaultValue) {
|
|
1164
|
+
if (col.defaultValue && instance[col.key] === undefined) {
|
|
1165
1165
|
if (typeof col.defaultValue === "function") {
|
|
1166
1166
|
instance[col.key] = col.defaultValue(instance);
|
|
1167
1167
|
}
|
package/src/remult3/remult3.d.ts
CHANGED
|
@@ -157,7 +157,7 @@ export interface Repository<entityType> {
|
|
|
157
157
|
*/
|
|
158
158
|
insert(item: Partial<OmitEB<entityType>>[]): Promise<entityType[]>;
|
|
159
159
|
insert(item: Partial<OmitEB<entityType>>): Promise<entityType>;
|
|
160
|
-
/** Updates an item, based on
|
|
160
|
+
/** Updates an item, based on its `id`
|
|
161
161
|
* @example
|
|
162
162
|
* taskRepo.update(task.id,{...task,completed:true})
|
|
163
163
|
*/
|