remult 0.16.0-exp.8 → 0.16.0-exp.9
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/index.d.ts +1 -1
- package/esm/postgres/postgres-data-provider.js +2 -2
- package/esm/server/expressBridge.js +5 -4
- package/esm/src/backend-tests/test-http-server.backend-spec.js +12 -9
- package/esm/src/context.d.ts +15 -19
- package/esm/src/context.js +44 -84
- package/esm/src/data-interfaces.d.ts +1 -2
- package/esm/src/data-providers/rest-data-provider.d.ts +4 -4
- package/esm/src/data-providers/rest-data-provider.js +20 -17
- package/esm/src/remult-proxy.js +22 -25
- package/esm/src/remult3/RepositoryImplementation.d.ts +1 -0
- package/esm/src/remult3/RepositoryImplementation.js +2 -2
- package/esm/src/server-action.d.ts +9 -7
- package/esm/src/server-action.js +38 -32
- package/esm/src/shared-tests/db-tests-setup.js +1 -1
- package/esm/src/tests/createData.js +1 -1
- package/esm/src/tests/frontend-database-tests-setup.spec.js +3 -3
- package/esm/src/tests/testHelper.spec.js +16 -11
- package/index.d.ts +1 -1
- package/package.json +1 -1
- package/postgres/postgres-data-provider.js +2 -2
- package/server/expressBridge.js +10 -9
- package/src/backend-tests/test-http-server.backend-spec.js +11 -8
- package/src/context.d.ts +15 -19
- package/src/context.js +52 -105
- package/src/data-interfaces.d.ts +1 -2
- package/src/data-providers/rest-data-provider.d.ts +4 -4
- package/src/data-providers/rest-data-provider.js +21 -16
- package/src/remult-proxy.js +24 -39
- package/src/remult3/RepositoryImplementation.d.ts +1 -0
- package/src/remult3/RepositoryImplementation.js +2 -2
- package/src/server-action.d.ts +9 -7
- package/src/server-action.js +130 -119
- package/src/shared-tests/db-tests-setup.js +1 -1
- package/src/tests/createData.js +1 -1
- package/src/tests/frontend-database-tests-setup.spec.js +3 -3
- package/src/tests/testHelper.spec.js +19 -14
package/esm/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export { SqlDatabase, } from './src/data-providers/sql-database';
|
|
|
12
12
|
export { CustomSqlFilterObject, CustomSqlFilterBuilder } from './src/filter/filter-consumer-bridge-to-sql-request';
|
|
13
13
|
export { JsonDataProvider, JsonEntityStorage } from './src/data-providers/json-data-provider';
|
|
14
14
|
export { Controller, BackendMethodOptions, BackendMethod, ProgressListener } from './src/server-action';
|
|
15
|
-
export { Allowed, Allow, Remult, RemultContext, isBackend, AllowedForInstance, EventDispatcher, EventSource,
|
|
15
|
+
export { Allowed, Allow, Remult, RemultContext, ApiClient, isBackend, AllowedForInstance, EventDispatcher, EventSource, ExternalHttpProvider, Unobserve, UserInfo } from './src/context';
|
|
16
16
|
export { IdEntity } from './src/id-entity';
|
|
17
17
|
export { SortSegment, Sort } from './src/sort';
|
|
18
18
|
export { OneToMany, CompoundIdField } from './src/column';
|
|
@@ -81,14 +81,14 @@ export async function createPostgresConnection(options) {
|
|
|
81
81
|
}
|
|
82
82
|
const db = new SqlDatabase(new PostgresDataProvider(new Pool(config)));
|
|
83
83
|
let remult = new Remult();
|
|
84
|
-
remult.
|
|
84
|
+
remult.dataProvider = (db);
|
|
85
85
|
if (options.autoCreateTables === undefined || options.autoCreateTables)
|
|
86
86
|
await verifyStructureOfAllEntities(db, remult);
|
|
87
87
|
return db;
|
|
88
88
|
}
|
|
89
89
|
export async function preparePostgresQueueStorage(sql) {
|
|
90
90
|
let c = new Remult();
|
|
91
|
-
c.
|
|
91
|
+
c.dataProvider = (sql);
|
|
92
92
|
let JobsInQueueEntity = (await import('../server/expressBridge')).JobsInQueueEntity;
|
|
93
93
|
let e = c.repo(JobsInQueueEntity);
|
|
94
94
|
await new PostgresSchemaBuilder(sql).createIfNotExist(e.metadata);
|
|
@@ -54,7 +54,7 @@ export function createRemultServer(options) {
|
|
|
54
54
|
options.controllers = allControllers;
|
|
55
55
|
}
|
|
56
56
|
if (options.rootPath === undefined)
|
|
57
|
-
options.rootPath =
|
|
57
|
+
options.rootPath = '/api';
|
|
58
58
|
actionInfo.runningOnServer = true;
|
|
59
59
|
let bridge = new RemultServerImplementation(new inProcessQueueHandler(options.queueStorage), options, dataProvider);
|
|
60
60
|
return bridge;
|
|
@@ -123,7 +123,8 @@ class RemultServerImplementation {
|
|
|
123
123
|
else
|
|
124
124
|
res.success(job.info);
|
|
125
125
|
});
|
|
126
|
-
}
|
|
126
|
+
},
|
|
127
|
+
doWork: undefined
|
|
127
128
|
}, r);
|
|
128
129
|
}
|
|
129
130
|
this.options.entities.forEach(e => {
|
|
@@ -155,7 +156,7 @@ class RemultServerImplementation {
|
|
|
155
156
|
let myReq = new ExpressRequestBridgeToDataApiRequest(req);
|
|
156
157
|
let myRes = new ExpressResponseBridgeToDataApiResponse(res, req);
|
|
157
158
|
let remult = new Remult();
|
|
158
|
-
remult.
|
|
159
|
+
remult.dataProvider = (await this.dataProvider);
|
|
159
160
|
await new Promise(res => {
|
|
160
161
|
remultObjectStorage.run(remult, async () => {
|
|
161
162
|
if (req) {
|
|
@@ -168,7 +169,7 @@ class RemultServerImplementation {
|
|
|
168
169
|
user = req['auth'];
|
|
169
170
|
}
|
|
170
171
|
if (user)
|
|
171
|
-
remult.
|
|
172
|
+
remult.user = (user);
|
|
172
173
|
}
|
|
173
174
|
if (this.options.initRequest) {
|
|
174
175
|
await this.options.initRequest(remult, req);
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import axios from 'axios';
|
|
3
3
|
import { remultFresh } from '../../remult-fresh';
|
|
4
|
-
import {
|
|
4
|
+
import { Remult } from '../context';
|
|
5
5
|
import { InMemoryDataProvider } from '../data-providers/in-memory-database';
|
|
6
|
+
import { remult } from '../remult-proxy';
|
|
6
7
|
import { Entity, Fields } from '../remult3';
|
|
7
8
|
import { BackendMethod } from '../server-action';
|
|
8
9
|
import { Categories } from '../tests/remult-3-entities';
|
|
9
|
-
|
|
10
|
-
let path =
|
|
10
|
+
remult.apiClient.url = 'http://localhost:3003/api';
|
|
11
|
+
let path = remult.apiClient.url + '/tasks';
|
|
11
12
|
const environments = [
|
|
12
13
|
// ["next", 3000],
|
|
13
14
|
// ["nest", 3001],
|
|
@@ -21,8 +22,8 @@ const environments = [
|
|
|
21
22
|
function test(name, test) {
|
|
22
23
|
for (const [env, port] of environments) {
|
|
23
24
|
const theTest = async () => {
|
|
24
|
-
|
|
25
|
-
path =
|
|
25
|
+
remult.apiClient.url = `http://localhost:${port}/api`;
|
|
26
|
+
path = remult.apiClient.url + '/tasks';
|
|
26
27
|
await test();
|
|
27
28
|
};
|
|
28
29
|
const testName = env + ` ${port}: ${name}`;
|
|
@@ -93,7 +94,7 @@ test("test http 201", async () => {
|
|
|
93
94
|
});
|
|
94
95
|
test("test regular api call", async () => {
|
|
95
96
|
await create3Tasks();
|
|
96
|
-
let result = await axios.get(
|
|
97
|
+
let result = await axios.get(remult.apiClient.url + "/test");
|
|
97
98
|
expect(result.data.result).toBe(3);
|
|
98
99
|
});
|
|
99
100
|
class FreshResponseTest {
|
|
@@ -106,9 +107,11 @@ class FreshResponseTest {
|
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
109
|
it("test fresh", async () => {
|
|
109
|
-
const api = remultFresh({
|
|
110
|
+
const api = remultFresh({
|
|
111
|
+
entities: [Categories],
|
|
110
112
|
dataProvider: new InMemoryDataProvider(),
|
|
111
|
-
rootPath: '/api'
|
|
113
|
+
rootPath: '/api'
|
|
114
|
+
}, FreshResponseTest);
|
|
112
115
|
const r = await api.handle({
|
|
113
116
|
url: '/api/Categories',
|
|
114
117
|
json() {
|
|
@@ -158,7 +161,7 @@ Task = __decorate([
|
|
|
158
161
|
export { Task };
|
|
159
162
|
async function create3Tasks() {
|
|
160
163
|
const remult = new Remult(axios);
|
|
161
|
-
|
|
164
|
+
remult.apiClient.httpClient = axios;
|
|
162
165
|
const taskRepo = remult.repo(Task);
|
|
163
166
|
for (const task of await taskRepo.find()) {
|
|
164
167
|
await taskRepo.delete(task);
|
package/esm/src/context.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { DataProvider, RestDataProviderHttpProvider } from "./data-interfaces";
|
|
2
|
+
import { RestDataProviderHttpProviderUsingFetch } from './data-providers/rest-data-provider';
|
|
2
3
|
import { EntityMetadata, EntityRef, FindOptions, Repository } from "./remult3";
|
|
3
4
|
import { ClassType } from "../classType";
|
|
4
|
-
export interface
|
|
5
|
+
export interface ExternalHttpProvider {
|
|
5
6
|
post(url: string, data: any): Promise<any> | {
|
|
6
7
|
toPromise(): Promise<any>;
|
|
7
8
|
};
|
|
@@ -17,7 +18,7 @@ export interface HttpProvider {
|
|
|
17
18
|
}
|
|
18
19
|
export declare class HttpProviderBridgeToRestDataProviderHttpProvider implements RestDataProviderHttpProvider {
|
|
19
20
|
private http;
|
|
20
|
-
constructor(http:
|
|
21
|
+
constructor(http: ExternalHttpProvider);
|
|
21
22
|
post(url: string, data: any): Promise<any>;
|
|
22
23
|
delete(url: string): Promise<void>;
|
|
23
24
|
put(url: string, data: any): Promise<any>;
|
|
@@ -37,10 +38,7 @@ export declare class Remult {
|
|
|
37
38
|
*
|
|
38
39
|
*/
|
|
39
40
|
repo<T>(entity: ClassType<T>, dataProvider?: DataProvider): Repository<T>;
|
|
40
|
-
|
|
41
|
-
get user(): UserInfo;
|
|
42
|
-
/** Set's the current user info */
|
|
43
|
-
setUser(info: UserInfo | undefined): Promise<void>;
|
|
41
|
+
user?: UserInfo;
|
|
44
42
|
/** Checks if a user was authenticated */
|
|
45
43
|
authenticated(): boolean;
|
|
46
44
|
/** checks if the user has any of the roles specified in the parameters
|
|
@@ -55,35 +53,32 @@ export declare class Remult {
|
|
|
55
53
|
* [Allowed](https://remult.dev/docs/allowed.html)
|
|
56
54
|
*/
|
|
57
55
|
isAllowedForInstance(instance: any, allowed?: AllowedForInstance<any>): boolean;
|
|
58
|
-
/** returns a dispatcher object that fires once a user has changed*/
|
|
59
|
-
get userChange(): EventDispatcher;
|
|
60
|
-
static defaultHttpProvider: RestDataProviderHttpProvider;
|
|
61
|
-
static setDefaultHttpProvider(provider: HttpProvider | typeof fetch): void;
|
|
62
56
|
/** Creates a new instance of the `remult` object.
|
|
63
57
|
*
|
|
64
58
|
* Can receive either an HttpProvider or a DataProvider as a parameter - which will be used to fetch data from.
|
|
65
59
|
*
|
|
66
60
|
* If no provider is specified, `fetch` will be used as an http provider
|
|
67
61
|
*/
|
|
68
|
-
constructor(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
*/
|
|
73
|
-
static apiBaseUrl: string;
|
|
62
|
+
constructor(http: ExternalHttpProvider | typeof fetch | ApiClient);
|
|
63
|
+
constructor(p: DataProvider);
|
|
64
|
+
constructor();
|
|
65
|
+
call<T extends ((...args: any[]) => Promise<Y>), Y>(backendMethod: T, self?: any): T;
|
|
74
66
|
/** The current data provider */
|
|
75
|
-
|
|
76
|
-
/** sets the current data provider */
|
|
77
|
-
setDataProvider(dataProvider: DataProvider): void;
|
|
67
|
+
dataProvider: DataProvider;
|
|
78
68
|
/** A helper callback that can be used to debug and trace all find operations. Useful in debugging scenarios */
|
|
79
69
|
static onFind: (metadata: EntityMetadata, options: FindOptions<any>) => void;
|
|
80
70
|
clearAllCache(): any;
|
|
81
71
|
/** A helper callback that is called whenever an entity is created. */
|
|
82
72
|
static entityRefInit?: (ref: EntityRef<any>, row: any) => void;
|
|
83
73
|
readonly context: RemultContext;
|
|
74
|
+
apiClient: ApiClient;
|
|
84
75
|
}
|
|
85
76
|
export interface RemultContext {
|
|
86
77
|
}
|
|
78
|
+
export interface ApiClient {
|
|
79
|
+
httpClient?: ExternalHttpProvider | typeof fetch;
|
|
80
|
+
url?: string;
|
|
81
|
+
}
|
|
87
82
|
export declare const allEntities: ClassType<any>[];
|
|
88
83
|
export interface ControllerOptions {
|
|
89
84
|
key: string;
|
|
@@ -95,6 +90,7 @@ export declare class ClassHelper {
|
|
|
95
90
|
export declare class MethodHelper {
|
|
96
91
|
classes: Map<any, ControllerOptions>;
|
|
97
92
|
}
|
|
93
|
+
export declare function buildRestDataProvider(provider: ExternalHttpProvider | typeof fetch): RestDataProviderHttpProvider | RestDataProviderHttpProviderUsingFetch;
|
|
98
94
|
export declare function setControllerSettings(target: any, options: ControllerOptions): void;
|
|
99
95
|
export interface UserInfo {
|
|
100
96
|
id: string;
|
package/esm/src/context.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { actionInfo } from './server-action';
|
|
1
|
+
import { actionInfo, serverActionField } from './server-action';
|
|
2
2
|
import { RestDataProvider, RestDataProviderHttpProviderUsingFetch } from './data-providers/rest-data-provider';
|
|
3
3
|
import { RepositoryImplementation } from "./remult3/RepositoryImplementation";
|
|
4
4
|
export class HttpProviderBridgeToRestDataProviderHttpProvider {
|
|
@@ -75,6 +75,8 @@ export async function processHttpException(ex) {
|
|
|
75
75
|
message: error,
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
|
+
if (z.modelState)
|
|
79
|
+
error.modelState = z.modelState;
|
|
78
80
|
let httpStatusCode = z.status;
|
|
79
81
|
if (httpStatusCode === undefined)
|
|
80
82
|
httpStatusCode = z.response?.status;
|
|
@@ -90,27 +92,31 @@ export function isBackend() {
|
|
|
90
92
|
return actionInfo.runningOnServer;
|
|
91
93
|
}
|
|
92
94
|
export class Remult {
|
|
93
|
-
/** Creates a new instance of the `remult` object.
|
|
94
|
-
*
|
|
95
|
-
* Can receive either an HttpProvider or a DataProvider as a parameter - which will be used to fetch data from.
|
|
96
|
-
*
|
|
97
|
-
* If no provider is specified, `fetch` will be used as an http provider
|
|
98
|
-
*/
|
|
99
95
|
constructor(provider) {
|
|
100
|
-
/* @internal */
|
|
101
|
-
this._userChangeEvent = new EventSource();
|
|
102
96
|
/* @internal */
|
|
103
97
|
this.repCache = new Map();
|
|
98
|
+
/** The current data provider */
|
|
99
|
+
this.dataProvider = new RestDataProvider(() => this.apiClient);
|
|
104
100
|
this.context = {};
|
|
101
|
+
this.apiClient = {
|
|
102
|
+
url: '/api'
|
|
103
|
+
};
|
|
105
104
|
if (provider && provider.getEntityDataProvider) {
|
|
106
|
-
this.
|
|
105
|
+
this.dataProvider = provider;
|
|
107
106
|
return;
|
|
108
107
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
if (isExternalHttpProvider(provider)) {
|
|
109
|
+
this.apiClient.httpClient = provider;
|
|
110
|
+
}
|
|
111
|
+
else if (typeof (provider) === "function")
|
|
112
|
+
this.apiClient.httpClient = provider;
|
|
113
|
+
else if (provider) {
|
|
114
|
+
const apiClient = provider;
|
|
115
|
+
if (apiClient.httpClient)
|
|
116
|
+
this.apiClient.httpClient = apiClient.httpClient;
|
|
117
|
+
if (apiClient.url)
|
|
118
|
+
this.apiClient.url = apiClient.url;
|
|
112
119
|
}
|
|
113
|
-
this._dataSource = new RestDataProvider(null, httpDataProvider);
|
|
114
120
|
}
|
|
115
121
|
/**Return's a `Repository` of the specific entity type
|
|
116
122
|
* @example
|
|
@@ -120,7 +126,7 @@ export class Remult {
|
|
|
120
126
|
*/
|
|
121
127
|
repo(entity, dataProvider) {
|
|
122
128
|
if (dataProvider === undefined)
|
|
123
|
-
dataProvider = this.
|
|
129
|
+
dataProvider = this.dataProvider;
|
|
124
130
|
let dpCache = this.repCache.get(dataProvider);
|
|
125
131
|
if (!dpCache)
|
|
126
132
|
this.repCache.set(dataProvider, dpCache = new Map());
|
|
@@ -130,39 +136,10 @@ export class Remult {
|
|
|
130
136
|
}
|
|
131
137
|
return r;
|
|
132
138
|
}
|
|
133
|
-
|
|
134
|
-
get user() {
|
|
135
|
-
if (this._user === undefined) {
|
|
136
|
-
return {
|
|
137
|
-
id: undefined,
|
|
138
|
-
name: '',
|
|
139
|
-
roles: []
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
return this._user;
|
|
143
|
-
}
|
|
144
|
-
/** Set's the current user info */
|
|
145
|
-
async setUser(info) {
|
|
146
|
-
this._user = info;
|
|
147
|
-
if (this._user === null)
|
|
148
|
-
this._user = undefined;
|
|
149
|
-
let auth = info;
|
|
150
|
-
if (auth) {
|
|
151
|
-
if (!this._user.id && auth.sub)
|
|
152
|
-
this._user.id = auth.sub;
|
|
153
|
-
if (!this._user.roles && auth.permissions) {
|
|
154
|
-
this._user.roles = auth.permissions;
|
|
155
|
-
}
|
|
156
|
-
if (!this._user.name)
|
|
157
|
-
this._user.name = auth.username;
|
|
158
|
-
}
|
|
159
|
-
if (this._user && !this._user.roles)
|
|
160
|
-
this._user.roles = [];
|
|
161
|
-
await this._userChangeEvent.fire();
|
|
162
|
-
}
|
|
139
|
+
/* delete me */
|
|
163
140
|
/** Checks if a user was authenticated */
|
|
164
141
|
authenticated() {
|
|
165
|
-
return this.user
|
|
142
|
+
return this.user?.id !== undefined;
|
|
166
143
|
}
|
|
167
144
|
/** checks if the user has any of the roles specified in the parameters
|
|
168
145
|
* @example
|
|
@@ -187,7 +164,7 @@ export class Remult {
|
|
|
187
164
|
if (typeof roles === 'boolean')
|
|
188
165
|
return roles;
|
|
189
166
|
if (typeof roles === 'string')
|
|
190
|
-
if (this.user
|
|
167
|
+
if (this.user?.roles?.indexOf(roles.toString()) >= 0)
|
|
191
168
|
return true;
|
|
192
169
|
return false;
|
|
193
170
|
}
|
|
@@ -210,46 +187,22 @@ export class Remult {
|
|
|
210
187
|
else
|
|
211
188
|
return this.isAllowed(allowed);
|
|
212
189
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
Remult.defaultHttpProvider = r;
|
|
222
|
-
}
|
|
223
|
-
/** sets the current data provider */
|
|
224
|
-
setDataProvider(dataProvider) {
|
|
225
|
-
this._dataSource = dataProvider;
|
|
190
|
+
call(backendMethod, self) {
|
|
191
|
+
const z = (backendMethod[serverActionField]);
|
|
192
|
+
if (!z.doWork)
|
|
193
|
+
throw Error("The method received is not a valid backend method");
|
|
194
|
+
//@ts-ignore
|
|
195
|
+
return (...args) => {
|
|
196
|
+
return z.doWork(args, self, this.apiClient.url, buildRestDataProvider(this.apiClient.httpClient));
|
|
197
|
+
};
|
|
226
198
|
}
|
|
227
199
|
clearAllCache() {
|
|
228
200
|
this.repCache.clear();
|
|
229
201
|
}
|
|
230
202
|
}
|
|
231
|
-
Remult.defaultHttpProvider = new RestDataProviderHttpProviderUsingFetch();
|
|
232
|
-
/** The api Base Url to be used in all remult calls. by default it's set to `/api`.
|
|
233
|
-
*
|
|
234
|
-
* Set this property in case you want to determine a non relative api url
|
|
235
|
-
*/
|
|
236
|
-
Remult.apiBaseUrl = '/api';
|
|
237
203
|
/** A helper callback that can be used to debug and trace all find operations. Useful in debugging scenarios */
|
|
238
204
|
Remult.onFind = (metadata, options) => { };
|
|
239
|
-
|
|
240
|
-
post(url, data) {
|
|
241
|
-
return Remult.defaultHttpProvider.post(url, data);
|
|
242
|
-
}
|
|
243
|
-
delete(url) {
|
|
244
|
-
return Remult.defaultHttpProvider.delete(url);
|
|
245
|
-
}
|
|
246
|
-
put(url, data) {
|
|
247
|
-
return Remult.defaultHttpProvider.put(url, data);
|
|
248
|
-
}
|
|
249
|
-
get(url) {
|
|
250
|
-
return Remult.defaultHttpProvider.get(url);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
205
|
+
;
|
|
253
206
|
export const allEntities = [];
|
|
254
207
|
export const classHelpers = new Map();
|
|
255
208
|
export class ClassHelper {
|
|
@@ -262,12 +215,19 @@ export class MethodHelper {
|
|
|
262
215
|
this.classes = new Map();
|
|
263
216
|
}
|
|
264
217
|
}
|
|
265
|
-
function
|
|
218
|
+
function isExternalHttpProvider(item) {
|
|
219
|
+
let http = item;
|
|
220
|
+
if (http && http.get && http.put && http.post && http.delete)
|
|
221
|
+
return true;
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
export function buildRestDataProvider(provider) {
|
|
225
|
+
if (!provider)
|
|
226
|
+
return new RestDataProviderHttpProviderUsingFetch();
|
|
266
227
|
let httpDataProvider;
|
|
267
228
|
if (!httpDataProvider) {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
httpDataProvider = new HttpProviderBridgeToRestDataProviderHttpProvider(http);
|
|
229
|
+
if (isExternalHttpProvider(provider)) {
|
|
230
|
+
httpDataProvider = new HttpProviderBridgeToRestDataProviderHttpProvider(provider);
|
|
271
231
|
}
|
|
272
232
|
}
|
|
273
233
|
if (!httpDataProvider) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Sort } from './sort';
|
|
2
2
|
import { Filter } from './filter/filter-interfaces';
|
|
3
3
|
import { EntityMetadata, OmitEB } from './remult3';
|
|
4
|
-
import { HttpProvider } from './context';
|
|
5
4
|
export interface DataProvider {
|
|
6
5
|
getEntityDataProvider(entity: EntityMetadata): EntityDataProvider;
|
|
7
6
|
transaction(action: (dataProvider: DataProvider) => Promise<void>): Promise<void>;
|
|
@@ -20,7 +19,7 @@ export interface EntityDataProviderFindOptions {
|
|
|
20
19
|
page?: number;
|
|
21
20
|
orderBy?: Sort;
|
|
22
21
|
}
|
|
23
|
-
export interface RestDataProviderHttpProvider
|
|
22
|
+
export interface RestDataProviderHttpProvider {
|
|
24
23
|
post(url: string, data: any): Promise<any>;
|
|
25
24
|
delete(url: string): Promise<void>;
|
|
26
25
|
put(url: string, data: any): Promise<any>;
|
|
@@ -2,10 +2,10 @@ import { EntityDataProvider, DataProvider, EntityDataProviderFindOptions, RestDa
|
|
|
2
2
|
import { UrlBuilder } from '../../urlBuilder';
|
|
3
3
|
import { Filter } from '../filter/filter-interfaces';
|
|
4
4
|
import { EntityMetadata } from '../remult3';
|
|
5
|
+
import { ApiClient } from '../context';
|
|
5
6
|
export declare class RestDataProvider implements DataProvider {
|
|
6
|
-
private
|
|
7
|
-
|
|
8
|
-
constructor(url: string | null, http: RestDataProviderHttpProvider);
|
|
7
|
+
private apiProvider;
|
|
8
|
+
constructor(apiProvider: () => ApiClient);
|
|
9
9
|
getEntityDataProvider(entity: EntityMetadata): EntityDataProvider;
|
|
10
10
|
transaction(action: (dataProvider: DataProvider) => Promise<void>): Promise<void>;
|
|
11
11
|
supportsCustomFilter: boolean;
|
|
@@ -14,7 +14,7 @@ export declare class RestEntityDataProvider implements EntityDataProvider {
|
|
|
14
14
|
private url;
|
|
15
15
|
private http;
|
|
16
16
|
private entity;
|
|
17
|
-
constructor(url: string, http: RestDataProviderHttpProvider, entity: EntityMetadata);
|
|
17
|
+
constructor(url: () => string, http: () => RestDataProviderHttpProvider, entity: EntityMetadata);
|
|
18
18
|
translateFromJson(row: any): {};
|
|
19
19
|
translateToJson(row: any): {};
|
|
20
20
|
count(where: Filter): Promise<number>;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { UrlBuilder } from '../../urlBuilder';
|
|
2
2
|
import { customUrlToken } from '../filter/filter-interfaces';
|
|
3
|
-
import {
|
|
3
|
+
import { buildRestDataProvider, retry } from '../context';
|
|
4
4
|
export class RestDataProvider {
|
|
5
|
-
constructor(
|
|
6
|
-
this.
|
|
7
|
-
this.http = http;
|
|
5
|
+
constructor(apiProvider) {
|
|
6
|
+
this.apiProvider = apiProvider;
|
|
8
7
|
this.supportsCustomFilter = true;
|
|
9
8
|
}
|
|
10
9
|
getEntityDataProvider(entity) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
url
|
|
14
|
-
|
|
10
|
+
return new RestEntityDataProvider(() => {
|
|
11
|
+
let url = this.apiProvider()?.url;
|
|
12
|
+
if (url === undefined || url === null)
|
|
13
|
+
url = '/api';
|
|
14
|
+
return url + '/' + entity.key;
|
|
15
|
+
}, () => {
|
|
16
|
+
return buildRestDataProvider(this.apiProvider().httpClient);
|
|
17
|
+
}, entity);
|
|
15
18
|
}
|
|
16
19
|
async transaction(action) {
|
|
17
20
|
throw new Error("Method not implemented.");
|
|
@@ -38,7 +41,7 @@ export class RestEntityDataProvider {
|
|
|
38
41
|
return result;
|
|
39
42
|
}
|
|
40
43
|
async count(where) {
|
|
41
|
-
let url = new UrlBuilder(this.url);
|
|
44
|
+
let url = new UrlBuilder(this.url());
|
|
42
45
|
url.add("__action", "count");
|
|
43
46
|
let filterObject;
|
|
44
47
|
if (where) {
|
|
@@ -47,12 +50,12 @@ export class RestEntityDataProvider {
|
|
|
47
50
|
filterObject = undefined;
|
|
48
51
|
}
|
|
49
52
|
if (filterObject)
|
|
50
|
-
return this.http.post(url.url, filterObject).then(r => +(r.count));
|
|
53
|
+
return this.http().post(url.url, filterObject).then(r => +(r.count));
|
|
51
54
|
else
|
|
52
|
-
return this.http.get(url.url).then(r => +(r.count));
|
|
55
|
+
return this.http().get(url.url).then(r => +(r.count));
|
|
53
56
|
}
|
|
54
57
|
find(options) {
|
|
55
|
-
let url = new UrlBuilder(this.url);
|
|
58
|
+
let url = new UrlBuilder(this.url());
|
|
56
59
|
let filterObject;
|
|
57
60
|
if (options) {
|
|
58
61
|
if (options.where) {
|
|
@@ -81,10 +84,10 @@ export class RestEntityDataProvider {
|
|
|
81
84
|
}
|
|
82
85
|
if (filterObject) {
|
|
83
86
|
url.add("__action", "get");
|
|
84
|
-
return this.http.post(url.url, filterObject).then(x => x.map(y => this.translateFromJson(y)));
|
|
87
|
+
return this.http().post(url.url, filterObject).then(x => x.map(y => this.translateFromJson(y)));
|
|
85
88
|
}
|
|
86
89
|
else
|
|
87
|
-
return this.http.get(url.url).then(x => x.map(y => this.translateFromJson(y)));
|
|
90
|
+
return this.http().get(url.url).then(x => x.map(y => this.translateFromJson(y)));
|
|
88
91
|
;
|
|
89
92
|
}
|
|
90
93
|
update(id, data) {
|
|
@@ -94,13 +97,13 @@ export class RestEntityDataProvider {
|
|
|
94
97
|
if (keys.includes(col.key))
|
|
95
98
|
result[col.key] = col.valueConverter.toJson(data[col.key]);
|
|
96
99
|
}
|
|
97
|
-
return this.http.put(this.url + '/' + encodeURIComponent(id), result).then(y => this.translateFromJson(y));
|
|
100
|
+
return this.http().put(this.url() + '/' + encodeURIComponent(id), result).then(y => this.translateFromJson(y));
|
|
98
101
|
}
|
|
99
102
|
delete(id) {
|
|
100
|
-
return this.http.delete(this.url + '/' + encodeURIComponent(id));
|
|
103
|
+
return this.http().delete(this.url() + '/' + encodeURIComponent(id));
|
|
101
104
|
}
|
|
102
105
|
insert(data) {
|
|
103
|
-
return this.http.post(this.url, this.translateToJson(data)).then(y => this.translateFromJson(y));
|
|
106
|
+
return this.http().post(this.url(), this.translateToJson(data)).then(y => this.translateFromJson(y));
|
|
104
107
|
}
|
|
105
108
|
}
|
|
106
109
|
export class RestDataProviderHttpProviderUsingFetch {
|
package/esm/src/remult-proxy.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Remult } from "./context";
|
|
2
|
+
import { RepositoryImplementation } from "./remult3";
|
|
2
3
|
let defaultRemult = new Remult();
|
|
3
4
|
/*@internal*/
|
|
4
5
|
export class RemultProxy {
|
|
@@ -7,45 +8,41 @@ export class RemultProxy {
|
|
|
7
8
|
this.remultFactory = () => defaultRemult;
|
|
8
9
|
this.repo = (...args) => this.remultFactory().repo(...args);
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
return this.
|
|
11
|
+
call(backendMethod, self) {
|
|
12
|
+
return this.remultFactory().call(backendMethod, self);
|
|
12
13
|
}
|
|
13
|
-
get
|
|
14
|
-
return this.
|
|
14
|
+
get context() {
|
|
15
|
+
return this.remultFactory().context;
|
|
15
16
|
}
|
|
17
|
+
get dataProvider() { return this.remultFactory().dataProvider; }
|
|
16
18
|
;
|
|
17
|
-
|
|
18
|
-
;
|
|
19
|
-
get _dataSource() { return this.instance._dataSource; }
|
|
19
|
+
set dataProvider(provider) { this.remultFactory().dataProvider = provider; }
|
|
20
|
+
get repCache() { return this.remultFactory().repCache; }
|
|
20
21
|
;
|
|
21
|
-
get repCache() { return this.instance.repCache; }
|
|
22
|
-
;
|
|
23
|
-
setUser(info) {
|
|
24
|
-
return this.instance.setUser(info);
|
|
25
|
-
}
|
|
26
22
|
authenticated() {
|
|
27
|
-
return this.
|
|
23
|
+
return this.remultFactory().authenticated();
|
|
28
24
|
}
|
|
29
25
|
isAllowed(roles) {
|
|
30
|
-
return this.
|
|
26
|
+
return this.remultFactory().isAllowed(roles);
|
|
31
27
|
}
|
|
32
28
|
isAllowedForInstance(instance, allowed) {
|
|
33
|
-
return this.
|
|
34
|
-
}
|
|
35
|
-
get userChange() {
|
|
36
|
-
return this.instance.userChange;
|
|
37
|
-
}
|
|
38
|
-
setDataProvider(dataProvider) {
|
|
39
|
-
return this.instance.setDataProvider(dataProvider);
|
|
29
|
+
return this.remultFactory().isAllowedForInstance(instance, allowed);
|
|
40
30
|
}
|
|
41
31
|
clearAllCache() {
|
|
42
|
-
return this.
|
|
43
|
-
}
|
|
44
|
-
get instance() {
|
|
45
|
-
return this.remultFactory();
|
|
32
|
+
return this.remultFactory().clearAllCache();
|
|
46
33
|
}
|
|
47
34
|
get user() {
|
|
48
35
|
return this.remultFactory().user;
|
|
49
36
|
}
|
|
37
|
+
set user(info) {
|
|
38
|
+
this.remultFactory().user = info;
|
|
39
|
+
}
|
|
40
|
+
get apiClient() {
|
|
41
|
+
return this.remultFactory().apiClient;
|
|
42
|
+
}
|
|
43
|
+
set apiClient(client) {
|
|
44
|
+
this.remultFactory().apiClient = client;
|
|
45
|
+
}
|
|
50
46
|
}
|
|
51
47
|
export const remult = new RemultProxy();
|
|
48
|
+
RepositoryImplementation.defaultRemult = remult;
|
|
@@ -11,6 +11,7 @@ export declare class RepositoryImplementation<entityType> implements Repository<
|
|
|
11
11
|
private entity;
|
|
12
12
|
private remult;
|
|
13
13
|
private dataProvider;
|
|
14
|
+
static defaultRemult: Remult;
|
|
14
15
|
createAfterFilter(orderBy: EntityOrderBy<entityType>, lastRow: entityType): Promise<EntityFilter<entityType>>;
|
|
15
16
|
private _info;
|
|
16
17
|
private __edp;
|
|
@@ -6,7 +6,7 @@ import { v4 as uuid } from 'uuid';
|
|
|
6
6
|
import { ValueConverters } from "../valueConverters";
|
|
7
7
|
import { filterHelper } from "../filter/filter-interfaces";
|
|
8
8
|
import { assign } from "../../assign";
|
|
9
|
-
import { remult } from "../remult-proxy";
|
|
9
|
+
//import { remult } from "../remult-proxy";
|
|
10
10
|
let classValidatorValidate = undefined;
|
|
11
11
|
// import("class-validator".toString())
|
|
12
12
|
// .then((v) => {
|
|
@@ -913,7 +913,7 @@ export function getFields(container, remult) {
|
|
|
913
913
|
return getControllerRef(container, remult).fields;
|
|
914
914
|
}
|
|
915
915
|
export function getControllerRef(container, remultArg) {
|
|
916
|
-
const remultVar = remultArg ||
|
|
916
|
+
const remultVar = remultArg || RepositoryImplementation.defaultRemult;
|
|
917
917
|
let result = container[controllerColumns];
|
|
918
918
|
if (!result)
|
|
919
919
|
result = container[entityMember];
|