remult 0.20.1 → 0.20.3-exp.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/esm/graphql.d.ts +5 -2
- package/esm/graphql.js +39 -22
- package/esm/remult-express.js +2 -1
- package/esm/remult-fastify.js +3 -6
- package/esm/remult-fresh.js +2 -1
- package/esm/remult-next.js +3 -7
- package/esm/remult-sveltekit.js +1 -0
- package/esm/server/expressBridge.d.ts +8 -1
- package/esm/server/expressBridge.js +33 -8
- package/esm/src/buildRestDataProvider.js +1 -1
- package/esm/src/remult3/RepositoryImplementation.js +2 -0
- package/esm/src/server-action.d.ts +5 -0
- package/esm/src/server-action.js +4 -4
- package/graphql.d.ts +5 -2
- package/graphql.js +98 -83
- package/package.json +1 -1
- package/remult-express.js +2 -7
- package/remult-fastify.js +5 -6
- package/remult-fresh.js +2 -1
- package/remult-next.js +4 -6
- package/remult-sveltekit.js +1 -0
- package/server/expressBridge.d.ts +8 -1
- package/server/expressBridge.js +47 -12
- package/src/buildRestDataProvider.js +1 -1
- package/src/remult3/RepositoryImplementation.js +2 -0
- package/src/server-action.d.ts +5 -0
- package/src/server-action.js +4 -4
package/esm/graphql.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function remultGraphql(api:
|
|
1
|
+
import { RemultServerCore } from "./server";
|
|
2
|
+
export declare function remultGraphql(api: RemultServerCore<any>): {
|
|
3
|
+
resolvers: {
|
|
4
|
+
Query: {};
|
|
5
|
+
};
|
|
3
6
|
rootValue: {};
|
|
4
7
|
schema: string;
|
|
5
8
|
};
|
package/esm/graphql.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { Remult } from ".";
|
|
2
|
-
import { allEntities } from "./src/context";
|
|
3
|
-
import { DataApi } from "./src/data-api";
|
|
4
1
|
export function remultGraphql(api) {
|
|
5
|
-
let
|
|
2
|
+
let server = api["get internal server"]();
|
|
3
|
+
const entities = server.getEntities();
|
|
6
4
|
let types = [];
|
|
7
5
|
let filterTypes = '';
|
|
8
6
|
let query = '';
|
|
9
7
|
let root = {};
|
|
8
|
+
let resolversQuery = {};
|
|
9
|
+
let resolvers = { Query: resolversQuery };
|
|
10
10
|
function getType(key) {
|
|
11
11
|
let t = types.find(t => t.key === key);
|
|
12
12
|
if (!t)
|
|
13
13
|
types.push((t = ({ fields: "", key, moreFields: "", resultProcessors: [] })));
|
|
14
14
|
return t;
|
|
15
15
|
}
|
|
16
|
-
for (const
|
|
17
|
-
let meta = r.repo(e).metadata;
|
|
16
|
+
for (const meta of entities) {
|
|
18
17
|
let filterFields = '';
|
|
19
18
|
let key = meta.key;
|
|
20
19
|
const t = getType(key);
|
|
21
|
-
let q = "\n\t" + key + "(options: options, filter:" + key + "Filter): [" + key + "]";
|
|
20
|
+
let q = "\n\t" + key + "(options: options, filter:" + key + "Filter): [" + getTypeName(key) + "]";
|
|
22
21
|
if (key) {
|
|
22
|
+
const filterFieldMap = new Map();
|
|
23
23
|
for (const f of meta.fields) {
|
|
24
24
|
{
|
|
25
25
|
let type = "String";
|
|
@@ -36,11 +36,14 @@ export function remultGraphql(api) {
|
|
|
36
36
|
}
|
|
37
37
|
break;
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
let info = entities.find(i => i.entityType === f.valueType);
|
|
40
|
+
if (info !== undefined) {
|
|
41
|
+
const refKey = info.key;
|
|
42
|
+
t.fields += "\n\t" + f.key + ":" + getTypeName(refKey);
|
|
42
43
|
t.resultProcessors.push(r => {
|
|
43
44
|
const val = r[f.key];
|
|
45
|
+
if (val === null || val === undefined)
|
|
46
|
+
return null;
|
|
44
47
|
r[f.key] = async (args, req, gqlInfo) => {
|
|
45
48
|
const queryResult = await root[refKey]({ ...args.filter, filter: { id: val }, options: { limit: 1 } }, req, gqlInfo);
|
|
46
49
|
if (queryResult.length > 0)
|
|
@@ -59,31 +62,35 @@ export function remultGraphql(api) {
|
|
|
59
62
|
}
|
|
60
63
|
else
|
|
61
64
|
t.fields += "\n\t" + f.key + ":" + type;
|
|
65
|
+
const addFilter = (operator, theType) => {
|
|
66
|
+
if (!theType)
|
|
67
|
+
theType = type;
|
|
68
|
+
filterFields += "\n\t" + f.key + operator + ":" + theType;
|
|
69
|
+
filterFieldMap.set(f.key + operator.replace('_', '.'), f.key + operator);
|
|
70
|
+
};
|
|
62
71
|
for (const operator of ["", "_ne"]) {
|
|
63
|
-
|
|
72
|
+
addFilter(operator);
|
|
64
73
|
}
|
|
65
74
|
if (f.valueType === String || f.valueType === Number)
|
|
66
75
|
for (const operator of ["_gt", "_gte", "_lt", "_lte"]) {
|
|
67
|
-
|
|
76
|
+
addFilter(operator);
|
|
68
77
|
}
|
|
69
78
|
if (f.valueType === String)
|
|
70
79
|
for (const operator of ["_st", "_contains"]) {
|
|
71
|
-
|
|
80
|
+
addFilter(operator);
|
|
72
81
|
}
|
|
73
82
|
if (f.allowNull)
|
|
74
|
-
|
|
75
|
-
|
|
83
|
+
addFilter("_null", "Boolean");
|
|
84
|
+
addFilter("_in", "[" + type + "]");
|
|
76
85
|
}
|
|
77
86
|
}
|
|
78
87
|
filterTypes += "input " + key + "Filter{" + filterFields + "\n\tOR:[" + key + "Filter]\n}\n";
|
|
79
88
|
query += q;
|
|
80
|
-
root[key] = async (
|
|
89
|
+
root[key] = async (arg1, req, a) => {
|
|
90
|
+
const { options, filter } = arg1;
|
|
81
91
|
return new Promise(async (res, error) => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
let remult = await api.getRemult(req);
|
|
85
|
-
let repo = remult.repo(e);
|
|
86
|
-
let dApi = new DataApi(repo, remult);
|
|
92
|
+
server.run(req, async () => {
|
|
93
|
+
let dApi = await server.getDataApi(req, meta);
|
|
87
94
|
let result;
|
|
88
95
|
let err;
|
|
89
96
|
await dApi.getArray({
|
|
@@ -110,6 +117,11 @@ export function remultGraphql(api) {
|
|
|
110
117
|
case "_order":
|
|
111
118
|
return options.order;
|
|
112
119
|
}
|
|
120
|
+
if (filter) {
|
|
121
|
+
let f = filterFieldMap.get(key);
|
|
122
|
+
if (f)
|
|
123
|
+
return filter[f];
|
|
124
|
+
}
|
|
113
125
|
}
|
|
114
126
|
}, filter);
|
|
115
127
|
if (err) {
|
|
@@ -120,6 +132,7 @@ export function remultGraphql(api) {
|
|
|
120
132
|
});
|
|
121
133
|
});
|
|
122
134
|
};
|
|
135
|
+
resolversQuery[key] = (origItem, args, req, gqlInfo) => root[key](args, req, gqlInfo);
|
|
123
136
|
}
|
|
124
137
|
}
|
|
125
138
|
if (query.length > 0) {
|
|
@@ -127,8 +140,9 @@ export function remultGraphql(api) {
|
|
|
127
140
|
}`;
|
|
128
141
|
}
|
|
129
142
|
return {
|
|
143
|
+
resolvers,
|
|
130
144
|
rootValue: root,
|
|
131
|
-
schema: `${types.map(({ key, fields, moreFields }) => "type " + key + "{" + fields + moreFields + "\n}\n").join('')}
|
|
145
|
+
schema: `${types.map(({ key, fields, moreFields }) => "type " + getTypeName(key) + "{" + fields + moreFields + "\n}\n").join('')}
|
|
132
146
|
${query}
|
|
133
147
|
${filterTypes}
|
|
134
148
|
input options{
|
|
@@ -140,3 +154,6 @@ input options{
|
|
|
140
154
|
`
|
|
141
155
|
};
|
|
142
156
|
}
|
|
157
|
+
function getTypeName(key) {
|
|
158
|
+
return key;
|
|
159
|
+
}
|
package/esm/remult-express.js
CHANGED
|
@@ -20,6 +20,7 @@ export function remultExpress(options) {
|
|
|
20
20
|
return Object.assign(app, {
|
|
21
21
|
getRemult: (req) => server.getRemult(req),
|
|
22
22
|
openApiDoc: (options) => server.openApiDoc(options),
|
|
23
|
-
withRemult: (
|
|
23
|
+
withRemult: (req, res, next) => server.withRemult(req, res, next),
|
|
24
|
+
"get internal server": () => server['get internal server']()
|
|
24
25
|
});
|
|
25
26
|
}
|
package/esm/remult-fastify.js
CHANGED
|
@@ -31,7 +31,7 @@ export function remultFastify(options) {
|
|
|
31
31
|
}
|
|
32
32
|
const api = createRemultServer(options, {
|
|
33
33
|
buildGenericRequestInfo: req => req,
|
|
34
|
-
getRequestBody: async (req) => req.body
|
|
34
|
+
getRequestBody: async (req) => req.body,
|
|
35
35
|
});
|
|
36
36
|
const pluginFunction = async (instance, op) => {
|
|
37
37
|
//@ts-ignore
|
|
@@ -61,10 +61,7 @@ export function remultFastify(options) {
|
|
|
61
61
|
return Object.assign(pluginFunction, {
|
|
62
62
|
getRemult: x => api.getRemult(x),
|
|
63
63
|
openApiDoc: x => api.openApiDoc(x),
|
|
64
|
-
withRemult: (req, what) =>
|
|
65
|
-
|
|
66
|
-
what().then(resolve);
|
|
67
|
-
});
|
|
68
|
-
})
|
|
64
|
+
withRemult: (req, what) => api['get internal server']().run(req, what),
|
|
65
|
+
"get internal server": () => api['get internal server']()
|
|
69
66
|
});
|
|
70
67
|
}
|
package/esm/remult-fresh.js
CHANGED
package/esm/remult-next.js
CHANGED
|
@@ -7,6 +7,7 @@ export function remultNext(options) {
|
|
|
7
7
|
return Object.assign((req, res) => result.handle(req, res).then(() => { }), result, {
|
|
8
8
|
getRemult: (req) => result.getRemult(req),
|
|
9
9
|
openApiDoc: (arg) => result.openApiDoc(arg),
|
|
10
|
+
"get internal server": () => result['get internal server']()
|
|
10
11
|
}, {
|
|
11
12
|
getServerSideProps: (getServerPropsFunction) => {
|
|
12
13
|
return (context) => {
|
|
@@ -103,12 +104,7 @@ export function remultNextApp(options) {
|
|
|
103
104
|
POST: handler,
|
|
104
105
|
PUT: handler,
|
|
105
106
|
DELETE: handler,
|
|
106
|
-
withRemult: (what) =>
|
|
107
|
-
|
|
108
|
-
return result.withRemult({}, undefined, () => {
|
|
109
|
-
what().then(resolve);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
}
|
|
107
|
+
withRemult: (what) => result['get internal server']().run(undefined, what),
|
|
108
|
+
"get internal server": () => result['get internal server']()
|
|
113
109
|
};
|
|
114
110
|
}
|
package/esm/remult-sveltekit.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { queuedJobInfoResponse } from '../src/server-action';
|
|
2
2
|
import { DataProvider } from '../src/data-interfaces';
|
|
3
|
+
import { DataApi } from '../src/data-api';
|
|
3
4
|
import { Remult, UserInfo } from '../src/context';
|
|
4
5
|
import { ClassType } from '../classType';
|
|
5
|
-
import { Repository } from '../src/remult3';
|
|
6
|
+
import { EntityMetadata, Repository } from '../src/remult3';
|
|
6
7
|
import { IdEntity } from '../src/id-entity';
|
|
7
8
|
import { LiveQueryStorage, SubscriptionServer } from '../src/live-query/SubscriptionServer';
|
|
8
9
|
export interface RemultServerOptions<RequestType> {
|
|
@@ -70,6 +71,12 @@ export interface RemultServerCore<RequestType> {
|
|
|
70
71
|
title: string;
|
|
71
72
|
version?: string;
|
|
72
73
|
}): any;
|
|
74
|
+
["get internal server"](): remultServerInternalExperimental<RequestType>;
|
|
75
|
+
}
|
|
76
|
+
export interface remultServerInternalExperimental<RequestType> {
|
|
77
|
+
getDataApi(req: RequestType, meta: EntityMetadata<any>): Promise<DataApi>;
|
|
78
|
+
getEntities(): EntityMetadata[];
|
|
79
|
+
run<T>(request: RequestType, what: () => Promise<T>): Promise<T>;
|
|
73
80
|
}
|
|
74
81
|
export declare type GenericRouter = {
|
|
75
82
|
route(path: string): SpecificRoute;
|
|
@@ -30,6 +30,7 @@ export function createRemultServerCore(options, serverCoreOptions) {
|
|
|
30
30
|
if (options.ensureSchema === undefined)
|
|
31
31
|
options.ensureSchema = true;
|
|
32
32
|
RemultAsyncLocalStorage.enable();
|
|
33
|
+
const entitiesMetaData = [];
|
|
33
34
|
dataProvider = dataProvider.then(async (dp) => {
|
|
34
35
|
var remult = new Remult(dp);
|
|
35
36
|
await new Promise((res) => {
|
|
@@ -42,10 +43,10 @@ export function createRemultServerCore(options, serverCoreOptions) {
|
|
|
42
43
|
started = true;
|
|
43
44
|
console.time("Ensure Schema");
|
|
44
45
|
};
|
|
46
|
+
entitiesMetaData.push(...options.entities.map(e => remult.repo(e).metadata));
|
|
45
47
|
if (dp.ensureSchema) {
|
|
46
48
|
startConsoleLog();
|
|
47
|
-
|
|
48
|
-
await dp.ensureSchema(entitiesMetadata);
|
|
49
|
+
await dp.ensureSchema(entitiesMetaData);
|
|
49
50
|
}
|
|
50
51
|
for (const item of [options.liveQueryStorage, options.queueStorage]) {
|
|
51
52
|
if (item?.ensureSchema) {
|
|
@@ -76,7 +77,7 @@ export function createRemultServerCore(options, serverCoreOptions) {
|
|
|
76
77
|
if (options.rootPath === undefined)
|
|
77
78
|
options.rootPath = '/api';
|
|
78
79
|
actionInfo.runningOnServer = true;
|
|
79
|
-
let bridge = new RemultServerImplementation(new inProcessQueueHandler(options.queueStorage), options, dataProvider, serverCoreOptions);
|
|
80
|
+
let bridge = new RemultServerImplementation(new inProcessQueueHandler(options.queueStorage), options, dataProvider, serverCoreOptions, entitiesMetaData);
|
|
80
81
|
return bridge;
|
|
81
82
|
}
|
|
82
83
|
;
|
|
@@ -112,11 +113,12 @@ export class RemultAsyncLocalStorage {
|
|
|
112
113
|
RemultAsyncLocalStorage.instance = new RemultAsyncLocalStorage(undefined);
|
|
113
114
|
/* @internal*/
|
|
114
115
|
export class RemultServerImplementation {
|
|
115
|
-
constructor(queue, options, dataProvider, coreOptions) {
|
|
116
|
+
constructor(queue, options, dataProvider, coreOptions, entitiesMetaData) {
|
|
116
117
|
this.queue = queue;
|
|
117
118
|
this.options = options;
|
|
118
119
|
this.dataProvider = dataProvider;
|
|
119
120
|
this.coreOptions = coreOptions;
|
|
121
|
+
this.entitiesMetaData = entitiesMetaData;
|
|
120
122
|
this.liveQueryStorage = new InMemoryLiveQueryStorage();
|
|
121
123
|
this.runWithSerializedJsonContextData = async (jsonContextData, entityKey, what) => {
|
|
122
124
|
for (const e of this.options.entities) {
|
|
@@ -154,6 +156,30 @@ export class RemultServerImplementation {
|
|
|
154
156
|
if (options.subscriptionServer)
|
|
155
157
|
this.subscriptionServer = options.subscriptionServer;
|
|
156
158
|
}
|
|
159
|
+
async getDataApi(req, meta) {
|
|
160
|
+
const remult = await this.getRemult(req);
|
|
161
|
+
return new DataApi(remult.repo(meta.entityType), remult);
|
|
162
|
+
}
|
|
163
|
+
run(request, what) {
|
|
164
|
+
return new Promise((resolve, error) => {
|
|
165
|
+
return this.withRemult(request, undefined, () => {
|
|
166
|
+
try {
|
|
167
|
+
what().then(resolve).catch(error);
|
|
168
|
+
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
error(err);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
getEntities() {
|
|
176
|
+
//TODO - consider using entitiesMetaData - but it may require making it all awaitable
|
|
177
|
+
var r = new Remult();
|
|
178
|
+
return this.options.entities.map(x => r.repo(x).metadata);
|
|
179
|
+
}
|
|
180
|
+
["get internal server"]() {
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
157
183
|
;
|
|
158
184
|
getRouteImpl() {
|
|
159
185
|
if (!this.routeImpl) {
|
|
@@ -249,6 +275,7 @@ export class RemultServerImplementation {
|
|
|
249
275
|
//@ts-ignore
|
|
250
276
|
.delete(this.process(async (c, req, res, orig) => dataApiFactory(c).delete(res, orig.params.id)));
|
|
251
277
|
}
|
|
278
|
+
//runs with remult but without init request
|
|
252
279
|
async runWithRemult(what) {
|
|
253
280
|
let remult = new Remult();
|
|
254
281
|
remult.liveQueryPublisher = new LiveQueryPublisher(() => remult.subscriptionServer, () => remult.liveQueryStorage, this.runWithSerializedJsonContextData);
|
|
@@ -337,7 +364,6 @@ export class RemultServerImplementation {
|
|
|
337
364
|
});
|
|
338
365
|
}
|
|
339
366
|
openApiDoc(options) {
|
|
340
|
-
let r = new Remult();
|
|
341
367
|
if (!options.version)
|
|
342
368
|
options.version = "1.0.0";
|
|
343
369
|
let spec = {
|
|
@@ -386,9 +412,8 @@ export class RemultServerImplementation {
|
|
|
386
412
|
return item;
|
|
387
413
|
}
|
|
388
414
|
};
|
|
389
|
-
for (const
|
|
390
|
-
let
|
|
391
|
-
let key = getEntityKey(e);
|
|
415
|
+
for (const meta of this.getEntities()) {
|
|
416
|
+
let key = meta.key;
|
|
392
417
|
let parameters = [];
|
|
393
418
|
if (key) {
|
|
394
419
|
let properties = {};
|
|
@@ -49,7 +49,7 @@ export async function retry(what) {
|
|
|
49
49
|
err.message?.startsWith("Error occured while trying to proxy") ||
|
|
50
50
|
err.message?.includes("http proxy error") ||
|
|
51
51
|
err.message?.startsWith("Gateway Timeout") ||
|
|
52
|
-
err.status == 500) && i++ <
|
|
52
|
+
err.status == 500) && i++ < 50) {
|
|
53
53
|
await new Promise((res, req) => {
|
|
54
54
|
setTimeout(() => {
|
|
55
55
|
res({});
|
|
@@ -1484,6 +1484,7 @@ export class Fields {
|
|
|
1484
1484
|
}
|
|
1485
1485
|
static createdAt(...options) {
|
|
1486
1486
|
return Field(() => Date, {
|
|
1487
|
+
allowApiUpdate: false,
|
|
1487
1488
|
saving: (_, ref) => {
|
|
1488
1489
|
if (getEntityRef(_).isNew())
|
|
1489
1490
|
ref.value = new Date();
|
|
@@ -1492,6 +1493,7 @@ export class Fields {
|
|
|
1492
1493
|
}
|
|
1493
1494
|
static updatedAt(...options) {
|
|
1494
1495
|
return Field(() => Date, {
|
|
1496
|
+
allowApiUpdate: false,
|
|
1495
1497
|
saving: (_, ref) => {
|
|
1496
1498
|
ref.value = new Date();
|
|
1497
1499
|
}
|
|
@@ -33,6 +33,11 @@ export declare class myServerAction extends Action<inArgs, result> {
|
|
|
33
33
|
export interface BackendMethodOptions<type> {
|
|
34
34
|
/**Determines when this `BackendMethod` can execute, see: [Allowed](https://remult.dev/docs/allowed.html) */
|
|
35
35
|
allowed: AllowedForInstance<type>;
|
|
36
|
+
/** Used to determine the route for the BackendMethod.
|
|
37
|
+
* @example
|
|
38
|
+
* {allowed:true, apiPrefix:'someFolder/'}
|
|
39
|
+
*/
|
|
40
|
+
apiPrefix?: string;
|
|
36
41
|
/** EXPERIMENTAL: Determines if this method should be queued for later execution */
|
|
37
42
|
queue?: boolean;
|
|
38
43
|
/** EXPERIMENTAL: Determines if the user should be blocked while this `BackendMethod` is running*/
|
package/esm/src/server-action.js
CHANGED
|
@@ -119,7 +119,7 @@ export function BackendMethod(options) {
|
|
|
119
119
|
if (options.paramTypes)
|
|
120
120
|
types = options.paramTypes;
|
|
121
121
|
// if types are undefined - you've forgot to set: "emitDecoratorMetadata":true
|
|
122
|
-
let serverAction = new myServerAction(key, types, options, args => originalMethod.apply(undefined, args));
|
|
122
|
+
let serverAction = new myServerAction((options?.apiPrefix ? (options.apiPrefix + '/') : '') + key, types, options, args => originalMethod.apply(undefined, args));
|
|
123
123
|
serverAction.doWork = async (args, self, url, http) => {
|
|
124
124
|
args = prepareArgsToSend(types, args);
|
|
125
125
|
if (options.blockUser === false) {
|
|
@@ -156,7 +156,7 @@ export function BackendMethod(options) {
|
|
|
156
156
|
if (!controllerOptions.key) {
|
|
157
157
|
controllerOptions.key = c.repo(constructor).metadata.key;
|
|
158
158
|
}
|
|
159
|
-
reg(controllerOptions.key + '/' + key, options ? options.queue : false, options.allowed, async (d, req, res) => {
|
|
159
|
+
reg(controllerOptions.key + '/' + (options?.apiPrefix ? (options.apiPrefix + '/') : '') + key, options ? options.queue : false, options.allowed, async (d, req, res) => {
|
|
160
160
|
d.args = d.args.map(x => isCustomUndefined(x) ? undefined : x);
|
|
161
161
|
let allowed = options.allowed;
|
|
162
162
|
try {
|
|
@@ -243,7 +243,7 @@ export function BackendMethod(options) {
|
|
|
243
243
|
}
|
|
244
244
|
try {
|
|
245
245
|
let r = await (new class extends Action {
|
|
246
|
-
}(classOptions.key + "/" + key, options ? options.queue : false, options.allowed).run({
|
|
246
|
+
}(classOptions.key + "/" + (options?.apiPrefix ? (options.apiPrefix + '/') : '') + key, options ? options.queue : false, options.allowed).run({
|
|
247
247
|
args,
|
|
248
248
|
rowInfo: {
|
|
249
249
|
data: await defs.toApiJson(),
|
|
@@ -264,7 +264,7 @@ export function BackendMethod(options) {
|
|
|
264
264
|
try {
|
|
265
265
|
await defs.__validateEntity();
|
|
266
266
|
let r = await (new class extends Action {
|
|
267
|
-
}(x.classes.get(self.constructor).key + "/" + key, options ? options.queue : false, options.allowed).run({
|
|
267
|
+
}(x.classes.get(self.constructor).key + "/" + (options?.apiPrefix ? (options.apiPrefix + '/') : '') + key, options ? options.queue : false, options.allowed).run({
|
|
268
268
|
args,
|
|
269
269
|
fields: await defs.toApiJson()
|
|
270
270
|
}, baseUrl, http));
|
package/graphql.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function remultGraphql(api:
|
|
1
|
+
import { RemultServerCore } from "./server";
|
|
2
|
+
export declare function remultGraphql(api: RemultServerCore<any>): {
|
|
3
|
+
resolvers: {
|
|
4
|
+
Query: {};
|
|
5
|
+
};
|
|
3
6
|
rootValue: {};
|
|
4
7
|
schema: string;
|
|
5
8
|
};
|
package/graphql.js
CHANGED
|
@@ -2,54 +2,57 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.remultGraphql = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
var _1 = require(".");
|
|
6
|
-
var context_1 = require("./src/context");
|
|
7
|
-
var data_api_1 = require("./src/data-api");
|
|
8
5
|
function remultGraphql(api) {
|
|
9
6
|
var e_1, _a;
|
|
10
7
|
var _this = this;
|
|
11
8
|
var _b;
|
|
12
|
-
var
|
|
9
|
+
var server = api["get internal server"]();
|
|
10
|
+
var entities = server.getEntities();
|
|
13
11
|
var types = [];
|
|
14
12
|
var filterTypes = '';
|
|
15
13
|
var query = '';
|
|
16
14
|
var root = {};
|
|
15
|
+
var resolversQuery = {};
|
|
16
|
+
var resolvers = { Query: resolversQuery };
|
|
17
17
|
function getType(key) {
|
|
18
18
|
var t = types.find(function (t) { return t.key === key; });
|
|
19
19
|
if (!t)
|
|
20
20
|
types.push((t = ({ fields: "", key: key, moreFields: "", resultProcessors: [] })));
|
|
21
21
|
return t;
|
|
22
22
|
}
|
|
23
|
-
var _loop_1 = function (
|
|
23
|
+
var _loop_1 = function (meta) {
|
|
24
24
|
var e_2, _a;
|
|
25
|
-
var meta = r.repo(e).metadata;
|
|
26
25
|
var filterFields = '';
|
|
27
26
|
var key = meta.key;
|
|
28
27
|
var t = getType(key);
|
|
29
|
-
var q = "\n\t" + key + "(options: options, filter:" + key + "Filter): [" + key + "]";
|
|
28
|
+
var q = "\n\t" + key + "(options: options, filter:" + key + "Filter): [" + getTypeName(key) + "]";
|
|
30
29
|
if (key) {
|
|
30
|
+
var filterFieldMap_1 = new Map();
|
|
31
31
|
var _loop_2 = function (f) {
|
|
32
32
|
var e_3, _a, e_4, _b, e_5, _c;
|
|
33
33
|
{
|
|
34
|
-
var
|
|
34
|
+
var type_1 = "String";
|
|
35
35
|
switch (f.valueType) {
|
|
36
36
|
case Boolean:
|
|
37
|
-
|
|
37
|
+
type_1 = "Boolean";
|
|
38
38
|
break;
|
|
39
39
|
case Number:
|
|
40
40
|
{
|
|
41
41
|
if (((_b = f.valueConverter) === null || _b === void 0 ? void 0 : _b.fieldTypeInDb) == 'integer')
|
|
42
|
-
|
|
42
|
+
type_1 = "Int";
|
|
43
43
|
else
|
|
44
|
-
|
|
44
|
+
type_1 = "Float";
|
|
45
45
|
}
|
|
46
46
|
break;
|
|
47
47
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
var info = entities.find(function (i) { return i.entityType === f.valueType; });
|
|
49
|
+
if (info !== undefined) {
|
|
50
|
+
var refKey_1 = info.key;
|
|
51
|
+
t.fields += "\n\t" + f.key + ":" + getTypeName(refKey_1);
|
|
51
52
|
t.resultProcessors.push(function (r) {
|
|
52
53
|
var val = r[f.key];
|
|
54
|
+
if (val === null || val === undefined)
|
|
55
|
+
return null;
|
|
53
56
|
r[f.key] = function (args, req, gqlInfo) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
54
57
|
var queryResult;
|
|
55
58
|
return tslib_1.__generator(this, function (_a) {
|
|
@@ -80,11 +83,17 @@ function remultGraphql(api) {
|
|
|
80
83
|
});
|
|
81
84
|
}
|
|
82
85
|
else
|
|
83
|
-
t.fields += "\n\t" + f.key + ":" +
|
|
86
|
+
t.fields += "\n\t" + f.key + ":" + type_1;
|
|
87
|
+
var addFilter = function (operator, theType) {
|
|
88
|
+
if (!theType)
|
|
89
|
+
theType = type_1;
|
|
90
|
+
filterFields += "\n\t" + f.key + operator + ":" + theType;
|
|
91
|
+
filterFieldMap_1.set(f.key + operator.replace('_', '.'), f.key + operator);
|
|
92
|
+
};
|
|
84
93
|
try {
|
|
85
94
|
for (var _d = (e_3 = void 0, tslib_1.__values(["", "_ne"])), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
86
95
|
var operator = _e.value;
|
|
87
|
-
|
|
96
|
+
addFilter(operator);
|
|
88
97
|
}
|
|
89
98
|
}
|
|
90
99
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
@@ -98,7 +107,7 @@ function remultGraphql(api) {
|
|
|
98
107
|
try {
|
|
99
108
|
for (var _f = (e_4 = void 0, tslib_1.__values(["_gt", "_gte", "_lt", "_lte"])), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
100
109
|
var operator = _g.value;
|
|
101
|
-
|
|
110
|
+
addFilter(operator);
|
|
102
111
|
}
|
|
103
112
|
}
|
|
104
113
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
@@ -112,7 +121,7 @@ function remultGraphql(api) {
|
|
|
112
121
|
try {
|
|
113
122
|
for (var _h = (e_5 = void 0, tslib_1.__values(["_st", "_contains"])), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
114
123
|
var operator = _j.value;
|
|
115
|
-
|
|
124
|
+
addFilter(operator);
|
|
116
125
|
}
|
|
117
126
|
}
|
|
118
127
|
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
@@ -123,8 +132,8 @@ function remultGraphql(api) {
|
|
|
123
132
|
finally { if (e_5) throw e_5.error; }
|
|
124
133
|
}
|
|
125
134
|
if (f.allowNull)
|
|
126
|
-
|
|
127
|
-
|
|
135
|
+
addFilter("_null", "Boolean");
|
|
136
|
+
addFilter("_in", "[" + type_1 + "]");
|
|
128
137
|
}
|
|
129
138
|
};
|
|
130
139
|
try {
|
|
@@ -142,79 +151,81 @@ function remultGraphql(api) {
|
|
|
142
151
|
}
|
|
143
152
|
filterTypes += "input " + key + "Filter{" + filterFields + "\n\tOR:[" + key + "Filter]\n}\n";
|
|
144
153
|
query += q;
|
|
145
|
-
root[key] = function (
|
|
146
|
-
var options
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
154
|
+
root[key] = function (arg1, req, a) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
155
|
+
var options, filter;
|
|
156
|
+
var _this = this;
|
|
157
|
+
return tslib_1.__generator(this, function (_a) {
|
|
158
|
+
options = arg1.options, filter = arg1.filter;
|
|
159
|
+
return [2 /*return*/, new Promise(function (res, error) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
160
|
+
var _this = this;
|
|
161
|
+
return tslib_1.__generator(this, function (_a) {
|
|
162
|
+
server.run(req, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
163
|
+
var dApi, result, err;
|
|
164
|
+
return tslib_1.__generator(this, function (_a) {
|
|
165
|
+
switch (_a.label) {
|
|
166
|
+
case 0: return [4 /*yield*/, server.getDataApi(req, meta)];
|
|
167
|
+
case 1:
|
|
168
|
+
dApi = _a.sent();
|
|
169
|
+
return [4 /*yield*/, dApi.getArray({
|
|
170
|
+
success: function (x) { return result = x.map(function (y) {
|
|
171
|
+
t.resultProcessors.forEach(function (z) { return z(y); });
|
|
172
|
+
return y;
|
|
173
|
+
}); },
|
|
174
|
+
created: undefined,
|
|
175
|
+
deleted: undefined,
|
|
176
|
+
error: function (x) { return err = x; },
|
|
177
|
+
forbidden: function () { return err = 'forbidden'; },
|
|
178
|
+
notFound: function () { return err = 'not found'; },
|
|
179
|
+
progress: undefined
|
|
180
|
+
}, {
|
|
181
|
+
get: function (key) {
|
|
182
|
+
if (options)
|
|
183
|
+
switch (key) {
|
|
184
|
+
case "_limit":
|
|
185
|
+
return options.limit;
|
|
186
|
+
case "_page":
|
|
187
|
+
return options.page;
|
|
188
|
+
case "_sort":
|
|
189
|
+
return options.sort;
|
|
190
|
+
case "_order":
|
|
191
|
+
return options.order;
|
|
192
|
+
}
|
|
193
|
+
if (filter) {
|
|
194
|
+
var f = filterFieldMap_1.get(key);
|
|
195
|
+
if (f)
|
|
196
|
+
return filter[f];
|
|
187
197
|
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
res(result);
|
|
198
|
+
}
|
|
199
|
+
}, filter)];
|
|
200
|
+
case 2:
|
|
201
|
+
_a.sent();
|
|
202
|
+
if (err) {
|
|
203
|
+
error(err);
|
|
196
204
|
return [2 /*return*/];
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
205
|
+
}
|
|
206
|
+
res(result);
|
|
207
|
+
return [2 /*return*/];
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}); });
|
|
211
|
+
return [2 /*return*/];
|
|
212
|
+
});
|
|
213
|
+
}); })];
|
|
204
214
|
});
|
|
205
|
-
};
|
|
215
|
+
}); };
|
|
216
|
+
resolversQuery[key] = function (origItem, args, req, gqlInfo) { return root[key](args, req, gqlInfo); };
|
|
206
217
|
}
|
|
207
218
|
};
|
|
208
219
|
try {
|
|
209
|
-
for (var
|
|
210
|
-
var
|
|
211
|
-
_loop_1(
|
|
220
|
+
for (var entities_1 = tslib_1.__values(entities), entities_1_1 = entities_1.next(); !entities_1_1.done; entities_1_1 = entities_1.next()) {
|
|
221
|
+
var meta = entities_1_1.value;
|
|
222
|
+
_loop_1(meta);
|
|
212
223
|
}
|
|
213
224
|
}
|
|
214
225
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
215
226
|
finally {
|
|
216
227
|
try {
|
|
217
|
-
if (
|
|
228
|
+
if (entities_1_1 && !entities_1_1.done && (_a = entities_1.return)) _a.call(entities_1);
|
|
218
229
|
}
|
|
219
230
|
finally { if (e_1) throw e_1.error; }
|
|
220
231
|
}
|
|
@@ -222,11 +233,15 @@ function remultGraphql(api) {
|
|
|
222
233
|
query = "type Query {" + query + "\n}";
|
|
223
234
|
}
|
|
224
235
|
return {
|
|
236
|
+
resolvers: resolvers,
|
|
225
237
|
rootValue: root,
|
|
226
238
|
schema: types.map(function (_a) {
|
|
227
239
|
var key = _a.key, fields = _a.fields, moreFields = _a.moreFields;
|
|
228
|
-
return "type " + key + "{" + fields + moreFields + "\n}\n";
|
|
240
|
+
return "type " + getTypeName(key) + "{" + fields + moreFields + "\n}\n";
|
|
229
241
|
}).join('') + "\n" + query + "\n" + filterTypes + "\ninput options{\n limit:Int\n page:Int\n sort:String\n order:String\n}\n"
|
|
230
242
|
};
|
|
231
243
|
}
|
|
232
244
|
exports.remultGraphql = remultGraphql;
|
|
245
|
+
function getTypeName(key) {
|
|
246
|
+
return key;
|
|
247
|
+
}
|
package/package.json
CHANGED
package/remult-express.js
CHANGED
|
@@ -27,13 +27,8 @@ function remultExpress(options) {
|
|
|
27
27
|
return Object.assign(app, {
|
|
28
28
|
getRemult: function (req) { return server.getRemult(req); },
|
|
29
29
|
openApiDoc: function (options) { return server.openApiDoc(options); },
|
|
30
|
-
withRemult: function () {
|
|
31
|
-
|
|
32
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
33
|
-
args[_i] = arguments[_i];
|
|
34
|
-
}
|
|
35
|
-
return server.withRemult.apply(server, tslib_1.__spread(args));
|
|
36
|
-
}
|
|
30
|
+
withRemult: function (req, res, next) { return server.withRemult(req, res, next); },
|
|
31
|
+
"get internal server": function () { return server['get internal server'](); }
|
|
37
32
|
});
|
|
38
33
|
}
|
|
39
34
|
exports.remultExpress = remultExpress;
|
package/remult-fastify.js
CHANGED
|
@@ -38,7 +38,7 @@ function remultFastify(options) {
|
|
|
38
38
|
buildGenericRequestInfo: function (req) { return req; },
|
|
39
39
|
getRequestBody: function (req) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
40
40
|
return [2 /*return*/, req.body];
|
|
41
|
-
}); }); }
|
|
41
|
+
}); }); },
|
|
42
42
|
});
|
|
43
43
|
var pluginFunction = function (instance, op) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
44
44
|
var fastifyRouter;
|
|
@@ -71,11 +71,10 @@ function remultFastify(options) {
|
|
|
71
71
|
return Object.assign(pluginFunction, {
|
|
72
72
|
getRemult: function (x) { return api.getRemult(x); },
|
|
73
73
|
openApiDoc: function (x) { return api.openApiDoc(x); },
|
|
74
|
-
withRemult: function (req, what) {
|
|
75
|
-
return api.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}); }
|
|
74
|
+
withRemult: function (req, what) {
|
|
75
|
+
return api['get internal server']().run(req, what);
|
|
76
|
+
},
|
|
77
|
+
"get internal server": function () { return api['get internal server'](); }
|
|
79
78
|
});
|
|
80
79
|
}
|
|
81
80
|
exports.remultFastify = remultFastify;
|
package/remult-fresh.js
CHANGED
package/remult-next.js
CHANGED
|
@@ -14,6 +14,7 @@ function remultNext(options) {
|
|
|
14
14
|
return Object.assign(function (req, res) { return result.handle(req, res).then(function () { }); }, result, {
|
|
15
15
|
getRemult: function (req) { return result.getRemult(req); },
|
|
16
16
|
openApiDoc: function (arg) { return result.openApiDoc(arg); },
|
|
17
|
+
"get internal server": function () { return result['get internal server'](); }
|
|
17
18
|
}, {
|
|
18
19
|
getServerSideProps: function (getServerPropsFunction) {
|
|
19
20
|
return function (context) {
|
|
@@ -160,12 +161,9 @@ function remultNextApp(options) {
|
|
|
160
161
|
PUT: handler,
|
|
161
162
|
DELETE: handler,
|
|
162
163
|
withRemult: function (what) {
|
|
163
|
-
return
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
}
|
|
164
|
+
return result['get internal server']().run(undefined, what);
|
|
165
|
+
},
|
|
166
|
+
"get internal server": function () { return result['get internal server'](); }
|
|
169
167
|
};
|
|
170
168
|
}
|
|
171
169
|
exports.remultNextApp = remultNextApp;
|
package/remult-sveltekit.js
CHANGED
|
@@ -106,6 +106,7 @@ function remultSveltekit(options) {
|
|
|
106
106
|
return Object.assign(handler, {
|
|
107
107
|
getRemult: function (req) { return result.getRemult(req); },
|
|
108
108
|
openApiDoc: function (options) { return result.openApiDoc(options); },
|
|
109
|
+
"get internal server": function () { return result['get internal server'](); }
|
|
109
110
|
});
|
|
110
111
|
}
|
|
111
112
|
exports.remultSveltekit = remultSveltekit;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { queuedJobInfoResponse } from '../src/server-action';
|
|
2
2
|
import { DataProvider } from '../src/data-interfaces';
|
|
3
|
+
import { DataApi } from '../src/data-api';
|
|
3
4
|
import { Remult, UserInfo } from '../src/context';
|
|
4
5
|
import { ClassType } from '../classType';
|
|
5
|
-
import { Repository } from '../src/remult3';
|
|
6
|
+
import { EntityMetadata, Repository } from '../src/remult3';
|
|
6
7
|
import { IdEntity } from '../src/id-entity';
|
|
7
8
|
import { LiveQueryStorage, SubscriptionServer } from '../src/live-query/SubscriptionServer';
|
|
8
9
|
export interface RemultServerOptions<RequestType> {
|
|
@@ -70,6 +71,12 @@ export interface RemultServerCore<RequestType> {
|
|
|
70
71
|
title: string;
|
|
71
72
|
version?: string;
|
|
72
73
|
}): any;
|
|
74
|
+
["get internal server"](): remultServerInternalExperimental<RequestType>;
|
|
75
|
+
}
|
|
76
|
+
export interface remultServerInternalExperimental<RequestType> {
|
|
77
|
+
getDataApi(req: RequestType, meta: EntityMetadata<any>): Promise<DataApi>;
|
|
78
|
+
getEntities(): EntityMetadata[];
|
|
79
|
+
run<T>(request: RequestType, what: () => Promise<T>): Promise<T>;
|
|
73
80
|
}
|
|
74
81
|
export declare type GenericRouter = {
|
|
75
82
|
route(path: string): SpecificRoute;
|
package/server/expressBridge.js
CHANGED
|
@@ -34,6 +34,7 @@ function createRemultServerCore(options, serverCoreOptions) {
|
|
|
34
34
|
if (options.ensureSchema === undefined)
|
|
35
35
|
options.ensureSchema = true;
|
|
36
36
|
RemultAsyncLocalStorage.enable();
|
|
37
|
+
var entitiesMetaData = [];
|
|
37
38
|
dataProvider = dataProvider.then(function (dp) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
38
39
|
var remult;
|
|
39
40
|
var _this = this;
|
|
@@ -43,7 +44,7 @@ function createRemultServerCore(options, serverCoreOptions) {
|
|
|
43
44
|
remult = new context_1.Remult(dp);
|
|
44
45
|
return [4 /*yield*/, new Promise(function (res) {
|
|
45
46
|
RemultAsyncLocalStorage.instance.run(remult, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
46
|
-
var started_1, startConsoleLog,
|
|
47
|
+
var started_1, startConsoleLog, _a, _b, item, e_1_1;
|
|
47
48
|
var e_1, _c;
|
|
48
49
|
return tslib_1.__generator(this, function (_d) {
|
|
49
50
|
switch (_d.label) {
|
|
@@ -56,10 +57,10 @@ function createRemultServerCore(options, serverCoreOptions) {
|
|
|
56
57
|
started_1 = true;
|
|
57
58
|
console.time("Ensure Schema");
|
|
58
59
|
};
|
|
60
|
+
entitiesMetaData.push.apply(entitiesMetaData, tslib_1.__spread(options.entities.map(function (e) { return remult.repo(e).metadata; })));
|
|
59
61
|
if (!dp.ensureSchema) return [3 /*break*/, 2];
|
|
60
62
|
startConsoleLog();
|
|
61
|
-
|
|
62
|
-
return [4 /*yield*/, dp.ensureSchema(entitiesMetadata)];
|
|
63
|
+
return [4 /*yield*/, dp.ensureSchema(entitiesMetaData)];
|
|
63
64
|
case 1:
|
|
64
65
|
_d.sent();
|
|
65
66
|
_d.label = 2;
|
|
@@ -126,7 +127,7 @@ function createRemultServerCore(options, serverCoreOptions) {
|
|
|
126
127
|
if (options.rootPath === undefined)
|
|
127
128
|
options.rootPath = '/api';
|
|
128
129
|
server_action_1.actionInfo.runningOnServer = true;
|
|
129
|
-
var bridge = new RemultServerImplementation(new inProcessQueueHandler(options.queueStorage), options, dataProvider, serverCoreOptions);
|
|
130
|
+
var bridge = new RemultServerImplementation(new inProcessQueueHandler(options.queueStorage), options, dataProvider, serverCoreOptions, entitiesMetaData);
|
|
130
131
|
return bridge;
|
|
131
132
|
}
|
|
132
133
|
exports.createRemultServerCore = createRemultServerCore;
|
|
@@ -165,12 +166,13 @@ var RemultAsyncLocalStorage = /** @class */ (function () {
|
|
|
165
166
|
exports.RemultAsyncLocalStorage = RemultAsyncLocalStorage;
|
|
166
167
|
/* @internal*/
|
|
167
168
|
var RemultServerImplementation = /** @class */ (function () {
|
|
168
|
-
function RemultServerImplementation(queue, options, dataProvider, coreOptions) {
|
|
169
|
+
function RemultServerImplementation(queue, options, dataProvider, coreOptions, entitiesMetaData) {
|
|
169
170
|
var _this = this;
|
|
170
171
|
this.queue = queue;
|
|
171
172
|
this.options = options;
|
|
172
173
|
this.dataProvider = dataProvider;
|
|
173
174
|
this.coreOptions = coreOptions;
|
|
175
|
+
this.entitiesMetaData = entitiesMetaData;
|
|
174
176
|
this.liveQueryStorage = new SubscriptionServer_1.InMemoryLiveQueryStorage();
|
|
175
177
|
this.runWithSerializedJsonContextData = function (jsonContextData, entityKey, what) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
176
178
|
var _loop_1, this_1, _a, _b, e, state_1, e_2_1;
|
|
@@ -266,6 +268,40 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
266
268
|
if (options.subscriptionServer)
|
|
267
269
|
this.subscriptionServer = options.subscriptionServer;
|
|
268
270
|
}
|
|
271
|
+
RemultServerImplementation.prototype.getDataApi = function (req, meta) {
|
|
272
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
273
|
+
var remult;
|
|
274
|
+
return tslib_1.__generator(this, function (_a) {
|
|
275
|
+
switch (_a.label) {
|
|
276
|
+
case 0: return [4 /*yield*/, this.getRemult(req)];
|
|
277
|
+
case 1:
|
|
278
|
+
remult = _a.sent();
|
|
279
|
+
return [2 /*return*/, new data_api_1.DataApi(remult.repo(meta.entityType), remult)];
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
RemultServerImplementation.prototype.run = function (request, what) {
|
|
285
|
+
var _this = this;
|
|
286
|
+
return new Promise(function (resolve, error) {
|
|
287
|
+
return _this.withRemult(request, undefined, function () {
|
|
288
|
+
try {
|
|
289
|
+
what().then(resolve).catch(error);
|
|
290
|
+
}
|
|
291
|
+
catch (err) {
|
|
292
|
+
error(err);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
};
|
|
297
|
+
RemultServerImplementation.prototype.getEntities = function () {
|
|
298
|
+
//TODO - consider using entitiesMetaData - but it may require making it all awaitable
|
|
299
|
+
var r = new context_1.Remult();
|
|
300
|
+
return this.options.entities.map(function (x) { return r.repo(x).metadata; });
|
|
301
|
+
};
|
|
302
|
+
RemultServerImplementation.prototype["get internal server"] = function () {
|
|
303
|
+
return this;
|
|
304
|
+
};
|
|
269
305
|
;
|
|
270
306
|
RemultServerImplementation.prototype.getRouteImpl = function () {
|
|
271
307
|
if (!this.routeImpl) {
|
|
@@ -474,6 +510,7 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
474
510
|
return [2 /*return*/, dataApiFactory(c).delete(res, orig.params.id)];
|
|
475
511
|
}); }); }));
|
|
476
512
|
};
|
|
513
|
+
//runs with remult but without init request
|
|
477
514
|
RemultServerImplementation.prototype.runWithRemult = function (what) {
|
|
478
515
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
479
516
|
var remult, _a;
|
|
@@ -641,7 +678,6 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
641
678
|
};
|
|
642
679
|
RemultServerImplementation.prototype.openApiDoc = function (options) {
|
|
643
680
|
var e_5, _a, e_6, _b;
|
|
644
|
-
var r = new context_1.Remult();
|
|
645
681
|
if (!options.version)
|
|
646
682
|
options.version = "1.0.0";
|
|
647
683
|
var spec = {
|
|
@@ -690,10 +726,9 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
690
726
|
return item;
|
|
691
727
|
}
|
|
692
728
|
};
|
|
693
|
-
var _loop_2 = function (
|
|
729
|
+
var _loop_2 = function (meta) {
|
|
694
730
|
var e_7, _a;
|
|
695
|
-
var
|
|
696
|
-
var key = remult3_1.getEntityKey(e);
|
|
731
|
+
var key = meta.key;
|
|
697
732
|
var parameters = [];
|
|
698
733
|
if (key) {
|
|
699
734
|
var properties = {};
|
|
@@ -869,9 +904,9 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
869
904
|
}
|
|
870
905
|
};
|
|
871
906
|
try {
|
|
872
|
-
for (var _c = tslib_1.__values(this.
|
|
873
|
-
var
|
|
874
|
-
_loop_2(
|
|
907
|
+
for (var _c = tslib_1.__values(this.getEntities()), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
908
|
+
var meta = _d.value;
|
|
909
|
+
_loop_2(meta);
|
|
875
910
|
}
|
|
876
911
|
}
|
|
877
912
|
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
@@ -81,7 +81,7 @@ function retry(what) {
|
|
|
81
81
|
case 4:
|
|
82
82
|
err_1 = _e.sent();
|
|
83
83
|
if (!((((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.startsWith("Error occurred while trying to proxy")) || ((_b = err_1.message) === null || _b === void 0 ? void 0 : _b.startsWith("Error occured while trying to proxy")) || ((_c = err_1.message) === null || _c === void 0 ? void 0 : _c.includes("http proxy error")) || ((_d = err_1.message) === null || _d === void 0 ? void 0 : _d.startsWith("Gateway Timeout")) ||
|
|
84
|
-
err_1.status == 500) && i++ <
|
|
84
|
+
err_1.status == 500) && i++ < 50)) return [3 /*break*/, 6];
|
|
85
85
|
return [4 /*yield*/, new Promise(function (res, req) {
|
|
86
86
|
setTimeout(function () {
|
|
87
87
|
res({});
|
|
@@ -2611,6 +2611,7 @@ var Fields = /** @class */ (function () {
|
|
|
2611
2611
|
options[_i] = arguments[_i];
|
|
2612
2612
|
}
|
|
2613
2613
|
return Field.apply(void 0, tslib_1.__spread([function () { return Date; }, {
|
|
2614
|
+
allowApiUpdate: false,
|
|
2614
2615
|
saving: function (_, ref) {
|
|
2615
2616
|
if (getEntityRef(_).isNew())
|
|
2616
2617
|
ref.value = new Date();
|
|
@@ -2623,6 +2624,7 @@ var Fields = /** @class */ (function () {
|
|
|
2623
2624
|
options[_i] = arguments[_i];
|
|
2624
2625
|
}
|
|
2625
2626
|
return Field.apply(void 0, tslib_1.__spread([function () { return Date; }, {
|
|
2627
|
+
allowApiUpdate: false,
|
|
2626
2628
|
saving: function (_, ref) {
|
|
2627
2629
|
ref.value = new Date();
|
|
2628
2630
|
}
|
package/src/server-action.d.ts
CHANGED
|
@@ -33,6 +33,11 @@ export declare class myServerAction extends Action<inArgs, result> {
|
|
|
33
33
|
export interface BackendMethodOptions<type> {
|
|
34
34
|
/**Determines when this `BackendMethod` can execute, see: [Allowed](https://remult.dev/docs/allowed.html) */
|
|
35
35
|
allowed: AllowedForInstance<type>;
|
|
36
|
+
/** Used to determine the route for the BackendMethod.
|
|
37
|
+
* @example
|
|
38
|
+
* {allowed:true, apiPrefix:'someFolder/'}
|
|
39
|
+
*/
|
|
40
|
+
apiPrefix?: string;
|
|
36
41
|
/** EXPERIMENTAL: Determines if this method should be queued for later execution */
|
|
37
42
|
queue?: boolean;
|
|
38
43
|
/** EXPERIMENTAL: Determines if the user should be blocked while this `BackendMethod` is running*/
|
package/src/server-action.js
CHANGED
|
@@ -196,7 +196,7 @@ function BackendMethod(options) {
|
|
|
196
196
|
if (options.paramTypes)
|
|
197
197
|
types = options.paramTypes;
|
|
198
198
|
// if types are undefined - you've forgot to set: "emitDecoratorMetadata":true
|
|
199
|
-
var serverAction_1 = new myServerAction(key, types, options, function (args) { return originalMethod.apply(undefined, args); });
|
|
199
|
+
var serverAction_1 = new myServerAction(((options === null || options === void 0 ? void 0 : options.apiPrefix) ? (options.apiPrefix + '/') : '') + key, types, options, function (args) { return originalMethod.apply(undefined, args); });
|
|
200
200
|
serverAction_1.doWork = function (args, self, url, http) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
201
201
|
var _this = this;
|
|
202
202
|
return tslib_1.__generator(this, function (_a) {
|
|
@@ -257,7 +257,7 @@ function BackendMethod(options) {
|
|
|
257
257
|
if (!controllerOptions.key) {
|
|
258
258
|
controllerOptions.key = c.repo(constructor).metadata.key;
|
|
259
259
|
}
|
|
260
|
-
reg(controllerOptions.key + '/' + key, options ? options.queue : false, options.allowed, function (d, req, res) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
260
|
+
reg(controllerOptions.key + '/' + ((options === null || options === void 0 ? void 0 : options.apiPrefix) ? (options.apiPrefix + '/') : '') + key, options ? options.queue : false, options.allowed, function (d, req, res) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
261
261
|
var allowed, remult_1, r_1, err_3;
|
|
262
262
|
var _this = this;
|
|
263
263
|
return tslib_1.__generator(this, function (_a) {
|
|
@@ -415,7 +415,7 @@ function BackendMethod(options) {
|
|
|
415
415
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
416
416
|
}
|
|
417
417
|
return class_1;
|
|
418
|
-
}(Action))(classOptions_1.key + "/" + key, options ? options.queue : false, options.allowed)).run;
|
|
418
|
+
}(Action))(classOptions_1.key + "/" + ((options === null || options === void 0 ? void 0 : options.apiPrefix) ? (options.apiPrefix + '/') : '') + key, options ? options.queue : false, options.allowed)).run;
|
|
419
419
|
_e = {
|
|
420
420
|
args: args
|
|
421
421
|
};
|
|
@@ -451,7 +451,7 @@ function BackendMethod(options) {
|
|
|
451
451
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
452
452
|
}
|
|
453
453
|
return class_2;
|
|
454
|
-
}(Action))(x.classes.get(self.constructor).key + "/" + key, options ? options.queue : false, options.allowed)).run;
|
|
454
|
+
}(Action))(x.classes.get(self.constructor).key + "/" + ((options === null || options === void 0 ? void 0 : options.apiPrefix) ? (options.apiPrefix + '/') : '') + key, options ? options.queue : false, options.allowed)).run;
|
|
455
455
|
_g = {
|
|
456
456
|
args: args
|
|
457
457
|
};
|