remult 0.16.0-exp.7 → 0.16.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/index.d.ts +1 -1
- package/esm/postgres/postgres-data-provider.js +2 -2
- package/esm/postgres/postgresColumnSyntax.d.ts +2 -0
- package/esm/postgres/postgresColumnSyntax.js +30 -0
- package/esm/remult-express.js +2 -1
- package/esm/remult-fastify.js +2 -1
- package/esm/remult-middleware.d.ts +2 -0
- package/esm/remult-middleware.js +65 -0
- package/esm/server/expressBridge.d.ts +1 -0
- package/esm/server/expressBridge.js +45 -17
- package/esm/server/register-actions-on-server.d.ts +3 -0
- package/esm/server/register-actions-on-server.js +24 -0
- package/esm/server/register-entities-on-server.d.ts +3 -0
- package/esm/server/register-entities-on-server.js +15 -0
- package/esm/src/backend-tests/test-http-server.backend-spec.js +15 -14
- package/esm/src/context.d.ts +17 -21
- 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 +8 -5
- package/esm/src/data-providers/rest-data-provider.js +37 -27
- package/esm/src/remult-proxy.js +22 -25
- package/esm/src/remult3/RepositoryImplementation.d.ts +1 -0
- package/esm/src/remult3/RepositoryImplementation.js +3 -3
- 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/esm/valueConverters.d.ts +12 -0
- package/esm/valueConverters.js +169 -0
- package/index.d.ts +1 -1
- package/package.json +1 -1
- package/postgres/postgres-data-provider.js +2 -2
- package/postgres/postgresColumnSyntax.d.ts +2 -0
- package/postgres/postgresColumnSyntax.js +34 -0
- package/remult-express.js +9 -1
- package/remult-fastify.js +2 -1
- package/remult-middleware.d.ts +2 -0
- package/remult-middleware.js +70 -0
- package/server/expressBridge.d.ts +1 -0
- package/server/expressBridge.js +65 -22
- package/server/register-actions-on-server.d.ts +3 -0
- package/server/register-actions-on-server.js +50 -0
- package/server/register-entities-on-server.d.ts +3 -0
- package/server/register-entities-on-server.js +19 -0
- package/src/backend-tests/test-http-server.backend-spec.js +17 -16
- package/src/context.d.ts +17 -21
- package/src/context.js +52 -105
- package/src/data-interfaces.d.ts +1 -2
- package/src/data-providers/rest-data-provider.d.ts +8 -5
- package/src/data-providers/rest-data-provider.js +49 -26
- package/src/remult-proxy.js +24 -39
- package/src/remult3/RepositoryImplementation.d.ts +1 -0
- package/src/remult3/RepositoryImplementation.js +3 -3
- 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/valueConverters.d.ts +12 -0
- package/valueConverters.js +168 -0
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);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ValueConverters } from '../valueConverters';
|
|
2
|
+
export function postgresColumnSyntax(x, dbName) {
|
|
3
|
+
let result = dbName;
|
|
4
|
+
if (x.valueType == Number) {
|
|
5
|
+
if (!x.valueConverter.fieldTypeInDb)
|
|
6
|
+
result += " numeric" + (x.allowNull ? "" : " default 0 not null");
|
|
7
|
+
else
|
|
8
|
+
result += " " + x.valueConverter.fieldTypeInDb + (x.allowNull ? "" : " default 0 not null");
|
|
9
|
+
}
|
|
10
|
+
else if (x.valueType == Date) {
|
|
11
|
+
if (!x.valueConverter.fieldTypeInDb)
|
|
12
|
+
if (x.valueConverter == ValueConverters.DateOnly)
|
|
13
|
+
result += " date";
|
|
14
|
+
else
|
|
15
|
+
result += " timestamp";
|
|
16
|
+
else
|
|
17
|
+
result += " " + x.valueConverter.fieldTypeInDb;
|
|
18
|
+
}
|
|
19
|
+
else if (x.valueType == Boolean)
|
|
20
|
+
result += " boolean" + (x.allowNull ? "" : " default false not null");
|
|
21
|
+
else if (x.valueConverter.fieldTypeInDb) {
|
|
22
|
+
result += " " + x.valueConverter.fieldTypeInDb;
|
|
23
|
+
if (!x.allowNull && x.valueConverter.fieldTypeInDb == 'integer') {
|
|
24
|
+
result += " default 0 not null";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else
|
|
28
|
+
result += " varchar" + (x.allowNull ? "" : " default '' not null");
|
|
29
|
+
return result;
|
|
30
|
+
}
|
package/esm/remult-express.js
CHANGED
|
@@ -17,6 +17,7 @@ export function remultExpress(options) {
|
|
|
17
17
|
return Object.assign(app, {
|
|
18
18
|
getRemult: (req) => server.getRemult(req),
|
|
19
19
|
openApiDoc: (options) => server.openApiDoc(options),
|
|
20
|
-
registerRouter: x => server.registerRouter(x)
|
|
20
|
+
registerRouter: x => server.registerRouter(x),
|
|
21
|
+
withRemult: (...args) => server.withRemult(...args)
|
|
21
22
|
});
|
|
22
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
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { remultMiddlewareBase } from './server/expressBridge';
|
|
2
|
+
export function remultMiddleware(options) {
|
|
3
|
+
const m = new middleware();
|
|
4
|
+
let app = Object.assign((req, res, next) => m.handleRequest(req, res, next), {
|
|
5
|
+
route: (path) => m.route(path)
|
|
6
|
+
});
|
|
7
|
+
return remultMiddlewareBase(app, options);
|
|
8
|
+
}
|
|
9
|
+
class middleware {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.map = new Map();
|
|
12
|
+
}
|
|
13
|
+
route(path) {
|
|
14
|
+
//consider using:
|
|
15
|
+
//* https://raw.githubusercontent.com/cmorten/opine/main/src/utils/pathToRegex.ts
|
|
16
|
+
//* https://github.com/pillarjs/path-to-regexp
|
|
17
|
+
let r = path.toLowerCase();
|
|
18
|
+
let m = new Map();
|
|
19
|
+
this.map.set(r, m);
|
|
20
|
+
const route = {
|
|
21
|
+
get: (h) => {
|
|
22
|
+
m.set("get", h);
|
|
23
|
+
return route;
|
|
24
|
+
},
|
|
25
|
+
put: (h) => {
|
|
26
|
+
m.set("put", h);
|
|
27
|
+
return route;
|
|
28
|
+
},
|
|
29
|
+
post: (h) => {
|
|
30
|
+
m.set("post", h);
|
|
31
|
+
return route;
|
|
32
|
+
},
|
|
33
|
+
delete: (h) => {
|
|
34
|
+
m.set("delete", h);
|
|
35
|
+
return route;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
return route;
|
|
39
|
+
}
|
|
40
|
+
handleRequest(req, res, next) {
|
|
41
|
+
let lowerPath = req.path.toLowerCase();
|
|
42
|
+
let m = this.map.get(lowerPath);
|
|
43
|
+
if (m) {
|
|
44
|
+
let h = m.get(req.method.toLowerCase());
|
|
45
|
+
if (h) {
|
|
46
|
+
h(req, res, next);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
let idPosition = req.path.lastIndexOf('/');
|
|
51
|
+
if (idPosition >= 0) {
|
|
52
|
+
lowerPath = req.path.substring(0, idPosition) + '/:id';
|
|
53
|
+
m = this.map.get(lowerPath);
|
|
54
|
+
if (m) {
|
|
55
|
+
let h = m.get(req.method.toLowerCase());
|
|
56
|
+
if (h) {
|
|
57
|
+
req.params.id = req.path.substring(idPosition + 1);
|
|
58
|
+
h(req, res, next);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
next();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -33,6 +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
|
+
withRemult(req: GenericRequest, res: GenericResponse, next: VoidFunction): any;
|
|
36
37
|
}
|
|
37
38
|
export declare type GenericRouter = {
|
|
38
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);
|
|
@@ -54,14 +72,30 @@ export function createRemultServer(options) {
|
|
|
54
72
|
options.controllers = allControllers;
|
|
55
73
|
}
|
|
56
74
|
if (options.rootPath === undefined)
|
|
57
|
-
options.rootPath =
|
|
75
|
+
options.rootPath = '/api';
|
|
58
76
|
actionInfo.runningOnServer = true;
|
|
59
77
|
let bridge = new RemultServerImplementation(new inProcessQueueHandler(options.queueStorage), options, dataProvider);
|
|
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,16 +105,9 @@ class RemultServerImplementation {
|
|
|
71
105
|
this.hasQueue = false;
|
|
72
106
|
/* internal */
|
|
73
107
|
this.backendMethodsOpenApi = [];
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
}
|
|
108
|
+
}
|
|
109
|
+
withRemult(req, res, next) {
|
|
110
|
+
this.process(async () => { next(); })(req, res);
|
|
84
111
|
}
|
|
85
112
|
handle(req, gRes) {
|
|
86
113
|
if (!this.routeImpl) {
|
|
@@ -120,7 +147,8 @@ class RemultServerImplementation {
|
|
|
120
147
|
else
|
|
121
148
|
res.success(job.info);
|
|
122
149
|
});
|
|
123
|
-
}
|
|
150
|
+
},
|
|
151
|
+
doWork: undefined
|
|
124
152
|
}, r);
|
|
125
153
|
}
|
|
126
154
|
this.options.entities.forEach(e => {
|
|
@@ -152,7 +180,7 @@ class RemultServerImplementation {
|
|
|
152
180
|
let myReq = new ExpressRequestBridgeToDataApiRequest(req);
|
|
153
181
|
let myRes = new ExpressResponseBridgeToDataApiResponse(res, req);
|
|
154
182
|
let remult = new Remult();
|
|
155
|
-
remult.
|
|
183
|
+
remult.dataProvider = (await this.dataProvider);
|
|
156
184
|
await new Promise(res => {
|
|
157
185
|
remultObjectStorage.run(remult, async () => {
|
|
158
186
|
if (req) {
|
|
@@ -165,7 +193,7 @@ class RemultServerImplementation {
|
|
|
165
193
|
user = req['auth'];
|
|
166
194
|
}
|
|
167
195
|
if (user)
|
|
168
|
-
remult.
|
|
196
|
+
remult.user = (user);
|
|
169
197
|
}
|
|
170
198
|
if (this.options.initRequest) {
|
|
171
199
|
await this.options.initRequest(remult, req);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { serverActionField, actionInfo, classBackendMethodsArray } from '../src/server-action';
|
|
2
|
+
export function registerActionsOnServer(area, controllers) {
|
|
3
|
+
var addAction = (a) => {
|
|
4
|
+
let x = a[serverActionField];
|
|
5
|
+
if (!x) {
|
|
6
|
+
throw 'failed to set server action, did you forget the BackendMethod Decorator?';
|
|
7
|
+
}
|
|
8
|
+
area.addAction(x);
|
|
9
|
+
};
|
|
10
|
+
actionInfo.runningOnServer = true;
|
|
11
|
+
if (controllers && controllers.length > 0) {
|
|
12
|
+
for (const c of controllers) {
|
|
13
|
+
let z = c[classBackendMethodsArray];
|
|
14
|
+
if (z)
|
|
15
|
+
for (const a of z) {
|
|
16
|
+
addAction(a);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else
|
|
21
|
+
actionInfo.allActions.forEach((a) => {
|
|
22
|
+
addAction(a);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getEntityKey } from "../src/remult3";
|
|
2
|
+
import { allEntities } from "../src/context";
|
|
3
|
+
import { DataApi } from "../src/data-api";
|
|
4
|
+
export function registerEntitiesOnServer(area, entities) {
|
|
5
|
+
if (!entities)
|
|
6
|
+
entities = allEntities;
|
|
7
|
+
//add Api Entries
|
|
8
|
+
entities.forEach(e => {
|
|
9
|
+
let key = getEntityKey(e);
|
|
10
|
+
if (key != undefined)
|
|
11
|
+
area.add(key, c => {
|
|
12
|
+
return new DataApi(c.repo(e), c);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import axios from 'axios';
|
|
3
3
|
import { remultFresh } from '../../remult-fresh';
|
|
4
|
-
import { HttpProviderBridgeToRestDataProviderHttpProvider, Remult } from '../context';
|
|
5
4
|
import { InMemoryDataProvider } from '../data-providers/in-memory-database';
|
|
5
|
+
import { remult } from '../remult-proxy';
|
|
6
6
|
import { Entity, Fields } from '../remult3';
|
|
7
7
|
import { BackendMethod } from '../server-action';
|
|
8
8
|
import { Categories } from '../tests/remult-3-entities';
|
|
9
|
-
|
|
10
|
-
let path =
|
|
9
|
+
remult.apiClient.url = 'http://localhost:3003/api';
|
|
10
|
+
let path = remult.apiClient.url + '/tasks';
|
|
11
11
|
const environments = [
|
|
12
12
|
// ["next", 3000],
|
|
13
13
|
// ["nest", 3001],
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
14
|
+
// ["koa", 3002],
|
|
15
|
+
// ["fastify", 3003],
|
|
16
|
+
// ["express", 3004],
|
|
17
|
+
// ["generic server", 3005],
|
|
18
18
|
// ["optine", 3006],
|
|
19
19
|
// ["fresh", 8000]
|
|
20
20
|
];
|
|
21
21
|
function test(name, test) {
|
|
22
22
|
for (const [env, port] of environments) {
|
|
23
23
|
const theTest = async () => {
|
|
24
|
-
|
|
25
|
-
path =
|
|
24
|
+
remult.apiClient.url = `http://localhost:${port}/api`;
|
|
25
|
+
path = remult.apiClient.url + '/tasks';
|
|
26
26
|
await test();
|
|
27
27
|
};
|
|
28
28
|
const testName = env + ` ${port}: ${name}`;
|
|
@@ -93,7 +93,7 @@ test("test http 201", async () => {
|
|
|
93
93
|
});
|
|
94
94
|
test("test regular api call", async () => {
|
|
95
95
|
await create3Tasks();
|
|
96
|
-
let result = await axios.get(
|
|
96
|
+
let result = await axios.get(remult.apiClient.url + "/test");
|
|
97
97
|
expect(result.data.result).toBe(3);
|
|
98
98
|
});
|
|
99
99
|
class FreshResponseTest {
|
|
@@ -106,9 +106,11 @@ class FreshResponseTest {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
it("test fresh", async () => {
|
|
109
|
-
const api = remultFresh({
|
|
109
|
+
const api = remultFresh({
|
|
110
|
+
entities: [Categories],
|
|
110
111
|
dataProvider: new InMemoryDataProvider(),
|
|
111
|
-
rootPath: '/api'
|
|
112
|
+
rootPath: '/api'
|
|
113
|
+
}, FreshResponseTest);
|
|
112
114
|
const r = await api.handle({
|
|
113
115
|
url: '/api/Categories',
|
|
114
116
|
json() {
|
|
@@ -157,8 +159,7 @@ Task = __decorate([
|
|
|
157
159
|
], Task);
|
|
158
160
|
export { Task };
|
|
159
161
|
async function create3Tasks() {
|
|
160
|
-
|
|
161
|
-
Remult.defaultHttpProvider = new HttpProviderBridgeToRestDataProviderHttpProvider(axios);
|
|
162
|
+
remult.apiClient.httpClient = axios;
|
|
162
163
|
const taskRepo = remult.repo(Task);
|
|
163
164
|
for (const task of await taskRepo.find()) {
|
|
164
165
|
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,11 +90,12 @@ 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;
|
|
101
|
-
name
|
|
102
|
-
roles
|
|
97
|
+
name?: string;
|
|
98
|
+
roles?: string[];
|
|
103
99
|
}
|
|
104
100
|
export declare type Allowed = boolean | string | string[] | ((c: Remult) => boolean);
|
|
105
101
|
export declare type AllowedForInstance<T> = boolean | string | string[] | ((c: Remult, entity?: T) => boolean);
|