remult 0.20.3-exp.0 → 0.20.3
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 +2 -5
- package/esm/graphql.js +26 -37
- package/esm/remult-express.js +1 -2
- package/esm/remult-fastify.js +6 -3
- package/esm/remult-fresh.js +1 -2
- package/esm/remult-next.js +7 -3
- package/esm/remult-sveltekit.js +0 -1
- package/esm/server/expressBridge.d.ts +1 -8
- package/esm/server/expressBridge.js +47 -55
- package/graphql.d.ts +2 -5
- package/graphql.js +37 -48
- package/package.json +1 -1
- package/remult-express.js +7 -2
- package/remult-fastify.js +6 -5
- package/remult-fresh.js +1 -2
- package/remult-next.js +6 -4
- package/remult-sveltekit.js +0 -1
- package/server/expressBridge.d.ts +1 -8
- package/server/expressBridge.js +52 -69
package/esm/graphql.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function remultGraphql(api:
|
|
3
|
-
resolvers: {
|
|
4
|
-
Query: {};
|
|
5
|
-
};
|
|
1
|
+
import { RemultExpressServer } from "./remult-express";
|
|
2
|
+
export declare function remultGraphql(api: RemultExpressServer): {
|
|
6
3
|
rootValue: {};
|
|
7
4
|
schema: string;
|
|
8
5
|
};
|
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";
|
|
1
4
|
export function remultGraphql(api) {
|
|
2
|
-
let
|
|
3
|
-
const entities = server.getEntities();
|
|
5
|
+
let r = new Remult();
|
|
4
6
|
let types = [];
|
|
5
7
|
let filterTypes = '';
|
|
6
8
|
let query = '';
|
|
7
9
|
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
|
|
16
|
+
for (const e of allEntities) {
|
|
17
|
+
let meta = r.repo(e).metadata;
|
|
17
18
|
let filterFields = '';
|
|
18
19
|
let key = meta.key;
|
|
19
20
|
const t = getType(key);
|
|
20
|
-
let q = "\n\t" + key + "(options: options, filter:" + key + "Filter): [" +
|
|
21
|
+
let q = "\n\t" + key + "(options: options, filter:" + key + "Filter): [" + key + "]";
|
|
21
22
|
if (key) {
|
|
22
|
-
const filterFieldMap = new Map();
|
|
23
23
|
for (const f of meta.fields) {
|
|
24
24
|
{
|
|
25
25
|
let type = "String";
|
|
@@ -36,14 +36,11 @@ export function remultGraphql(api) {
|
|
|
36
36
|
}
|
|
37
37
|
break;
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
t.fields += "\n\t" + f.key + ":" + getTypeName(refKey);
|
|
39
|
+
if (allEntities.includes(f.valueType)) {
|
|
40
|
+
const refKey = r.repo(f.valueType).metadata.key;
|
|
41
|
+
t.fields += "\n\t" + f.key + ":" + refKey;
|
|
43
42
|
t.resultProcessors.push(r => {
|
|
44
43
|
const val = r[f.key];
|
|
45
|
-
if (val === null || val === undefined)
|
|
46
|
-
return null;
|
|
47
44
|
r[f.key] = async (args, req, gqlInfo) => {
|
|
48
45
|
const queryResult = await root[refKey]({ ...args.filter, filter: { id: val }, options: { limit: 1 } }, req, gqlInfo);
|
|
49
46
|
if (queryResult.length > 0)
|
|
@@ -62,26 +59,20 @@ export function remultGraphql(api) {
|
|
|
62
59
|
}
|
|
63
60
|
else
|
|
64
61
|
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
|
-
};
|
|
71
62
|
for (const operator of ["", "_ne"]) {
|
|
72
|
-
|
|
63
|
+
filterFields += "\n\t" + f.key + operator + ":" + type;
|
|
73
64
|
}
|
|
74
65
|
if (f.valueType === String || f.valueType === Number)
|
|
75
66
|
for (const operator of ["_gt", "_gte", "_lt", "_lte"]) {
|
|
76
|
-
|
|
67
|
+
filterFields += "\n\t" + f.key + operator + ":" + type;
|
|
77
68
|
}
|
|
78
69
|
if (f.valueType === String)
|
|
79
70
|
for (const operator of ["_st", "_contains"]) {
|
|
80
|
-
|
|
71
|
+
filterFields += "\n\t" + f.key + operator + ":" + type;
|
|
81
72
|
}
|
|
82
73
|
if (f.allowNull)
|
|
83
|
-
|
|
84
|
-
|
|
74
|
+
filterFields += "\n\t" + f.key + "_null:Boolean";
|
|
75
|
+
filterFields += "\n\t" + f.key + "_in:[" + type + "]";
|
|
85
76
|
}
|
|
86
77
|
}
|
|
87
78
|
filterTypes += "input " + key + "Filter{" + filterFields + "\n\tOR:[" + key + "Filter]\n}\n";
|
|
@@ -89,8 +80,11 @@ export function remultGraphql(api) {
|
|
|
89
80
|
root[key] = async (arg1, req, a) => {
|
|
90
81
|
const { options, filter } = arg1;
|
|
91
82
|
return new Promise(async (res, error) => {
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
//TODO - consider this with remult usage when working with other servers
|
|
84
|
+
api.withRemult(req, undefined, async () => {
|
|
85
|
+
let remult = await api.getRemult(req);
|
|
86
|
+
let repo = remult.repo(e);
|
|
87
|
+
let dApi = new DataApi(repo, remult);
|
|
94
88
|
let result;
|
|
95
89
|
let err;
|
|
96
90
|
await dApi.getArray({
|
|
@@ -117,11 +111,6 @@ export function remultGraphql(api) {
|
|
|
117
111
|
case "_order":
|
|
118
112
|
return options.order;
|
|
119
113
|
}
|
|
120
|
-
if (filter) {
|
|
121
|
-
let f = filterFieldMap.get(key);
|
|
122
|
-
if (f)
|
|
123
|
-
return filter[f];
|
|
124
|
-
}
|
|
125
114
|
}
|
|
126
115
|
}, filter);
|
|
127
116
|
if (err) {
|
|
@@ -132,7 +121,6 @@ export function remultGraphql(api) {
|
|
|
132
121
|
});
|
|
133
122
|
});
|
|
134
123
|
};
|
|
135
|
-
resolversQuery[key] = (origItem, args, req, gqlInfo) => root[key](args, req, gqlInfo);
|
|
136
124
|
}
|
|
137
125
|
}
|
|
138
126
|
if (query.length > 0) {
|
|
@@ -140,9 +128,8 @@ export function remultGraphql(api) {
|
|
|
140
128
|
}`;
|
|
141
129
|
}
|
|
142
130
|
return {
|
|
143
|
-
resolvers,
|
|
144
131
|
rootValue: root,
|
|
145
|
-
schema: `${types.map(({ key, fields, moreFields }) => "type " +
|
|
132
|
+
schema: `${types.map(({ key, fields, moreFields }) => "type " + key + "{" + fields + moreFields + "\n}\n").join('')}
|
|
146
133
|
${query}
|
|
147
134
|
${filterTypes}
|
|
148
135
|
input options{
|
|
@@ -154,6 +141,8 @@ input options{
|
|
|
154
141
|
`
|
|
155
142
|
};
|
|
156
143
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
144
|
+
//TODO - filter doesn't work since we changed id_eq to be id.eq in rest, but graphql doesn't allow it.
|
|
145
|
+
//TODO - the list of entities, is based on allEntities - that's wrong - it should be based on the api entities - or a separate array.
|
|
146
|
+
//TODO - it's currently only planned for express server - it uses it's 'withRemult' that doesn't exist in all other servers.
|
|
147
|
+
//TODO - it doesn't support mutations
|
|
148
|
+
//TODO - it doesn't support backend methods
|
package/esm/remult-express.js
CHANGED
|
@@ -20,7 +20,6 @@ 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: (
|
|
24
|
-
"get internal server": () => server['get internal server']()
|
|
23
|
+
withRemult: (...args) => server.withRemult(...args)
|
|
25
24
|
});
|
|
26
25
|
}
|
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,7 +61,10 @@ 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
|
-
|
|
64
|
+
withRemult: (req, what) => new Promise((resolve) => {
|
|
65
|
+
return api.withRemult(req, undefined, () => {
|
|
66
|
+
what().then(resolve);
|
|
67
|
+
});
|
|
68
|
+
})
|
|
66
69
|
});
|
|
67
70
|
}
|
package/esm/remult-fresh.js
CHANGED
package/esm/remult-next.js
CHANGED
|
@@ -7,7 +7,6 @@ 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']()
|
|
11
10
|
}, {
|
|
12
11
|
getServerSideProps: (getServerPropsFunction) => {
|
|
13
12
|
return (context) => {
|
|
@@ -104,7 +103,12 @@ export function remultNextApp(options) {
|
|
|
104
103
|
POST: handler,
|
|
105
104
|
PUT: handler,
|
|
106
105
|
DELETE: handler,
|
|
107
|
-
withRemult: (what) =>
|
|
108
|
-
|
|
106
|
+
withRemult: (what) => {
|
|
107
|
+
return new Promise((resolve) => {
|
|
108
|
+
return result.withRemult({}, undefined, () => {
|
|
109
|
+
what().then(resolve);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
109
113
|
};
|
|
110
114
|
}
|
package/esm/remult-sveltekit.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { queuedJobInfoResponse } from '../src/server-action';
|
|
2
2
|
import { DataProvider } from '../src/data-interfaces';
|
|
3
|
-
import { DataApi } from '../src/data-api';
|
|
4
3
|
import { Remult, UserInfo } from '../src/context';
|
|
5
4
|
import { ClassType } from '../classType';
|
|
6
|
-
import {
|
|
5
|
+
import { Repository } from '../src/remult3';
|
|
7
6
|
import { IdEntity } from '../src/id-entity';
|
|
8
7
|
import { LiveQueryStorage, SubscriptionServer } from '../src/live-query/SubscriptionServer';
|
|
9
8
|
export interface RemultServerOptions<RequestType> {
|
|
@@ -71,12 +70,6 @@ export interface RemultServerCore<RequestType> {
|
|
|
71
70
|
title: string;
|
|
72
71
|
version?: string;
|
|
73
72
|
}): 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>;
|
|
80
73
|
}
|
|
81
74
|
export declare type GenericRouter = {
|
|
82
75
|
route(path: string): SpecificRoute;
|
|
@@ -30,7 +30,6 @@ export function createRemultServerCore(options, serverCoreOptions) {
|
|
|
30
30
|
if (options.ensureSchema === undefined)
|
|
31
31
|
options.ensureSchema = true;
|
|
32
32
|
RemultAsyncLocalStorage.enable();
|
|
33
|
-
const entitiesMetaData = [];
|
|
34
33
|
dataProvider = dataProvider.then(async (dp) => {
|
|
35
34
|
var remult = new Remult(dp);
|
|
36
35
|
await new Promise((res) => {
|
|
@@ -43,10 +42,10 @@ export function createRemultServerCore(options, serverCoreOptions) {
|
|
|
43
42
|
started = true;
|
|
44
43
|
console.time("Ensure Schema");
|
|
45
44
|
};
|
|
46
|
-
entitiesMetaData.push(...options.entities.map(e => remult.repo(e).metadata));
|
|
47
45
|
if (dp.ensureSchema) {
|
|
48
46
|
startConsoleLog();
|
|
49
|
-
|
|
47
|
+
const entitiesMetadata = options.entities.map(e => remult.repo(e).metadata);
|
|
48
|
+
await dp.ensureSchema(entitiesMetadata);
|
|
50
49
|
}
|
|
51
50
|
for (const item of [options.liveQueryStorage, options.queueStorage]) {
|
|
52
51
|
if (item?.ensureSchema) {
|
|
@@ -77,7 +76,7 @@ export function createRemultServerCore(options, serverCoreOptions) {
|
|
|
77
76
|
if (options.rootPath === undefined)
|
|
78
77
|
options.rootPath = '/api';
|
|
79
78
|
actionInfo.runningOnServer = true;
|
|
80
|
-
let bridge = new RemultServerImplementation(new inProcessQueueHandler(options.queueStorage), options, dataProvider, serverCoreOptions
|
|
79
|
+
let bridge = new RemultServerImplementation(new inProcessQueueHandler(options.queueStorage), options, dataProvider, serverCoreOptions);
|
|
81
80
|
return bridge;
|
|
82
81
|
}
|
|
83
82
|
;
|
|
@@ -113,12 +112,11 @@ export class RemultAsyncLocalStorage {
|
|
|
113
112
|
RemultAsyncLocalStorage.instance = new RemultAsyncLocalStorage(undefined);
|
|
114
113
|
/* @internal*/
|
|
115
114
|
export class RemultServerImplementation {
|
|
116
|
-
constructor(queue, options, dataProvider, coreOptions
|
|
115
|
+
constructor(queue, options, dataProvider, coreOptions) {
|
|
117
116
|
this.queue = queue;
|
|
118
117
|
this.options = options;
|
|
119
118
|
this.dataProvider = dataProvider;
|
|
120
119
|
this.coreOptions = coreOptions;
|
|
121
|
-
this.entitiesMetaData = entitiesMetaData;
|
|
122
120
|
this.liveQueryStorage = new InMemoryLiveQueryStorage();
|
|
123
121
|
this.runWithSerializedJsonContextData = async (jsonContextData, entityKey, what) => {
|
|
124
122
|
for (const e of this.options.entities) {
|
|
@@ -156,30 +154,6 @@ export class RemultServerImplementation {
|
|
|
156
154
|
if (options.subscriptionServer)
|
|
157
155
|
this.subscriptionServer = options.subscriptionServer;
|
|
158
156
|
}
|
|
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
|
-
}
|
|
183
157
|
;
|
|
184
158
|
getRouteImpl() {
|
|
185
159
|
if (!this.routeImpl) {
|
|
@@ -275,7 +249,6 @@ export class RemultServerImplementation {
|
|
|
275
249
|
//@ts-ignore
|
|
276
250
|
.delete(this.process(async (c, req, res, orig) => dataApiFactory(c).delete(res, orig.params.id)));
|
|
277
251
|
}
|
|
278
|
-
//runs with remult but without init request
|
|
279
252
|
async runWithRemult(what) {
|
|
280
253
|
let remult = new Remult();
|
|
281
254
|
remult.liveQueryPublisher = new LiveQueryPublisher(() => remult.subscriptionServer, () => remult.liveQueryStorage, this.runWithSerializedJsonContextData);
|
|
@@ -364,6 +337,7 @@ export class RemultServerImplementation {
|
|
|
364
337
|
});
|
|
365
338
|
}
|
|
366
339
|
openApiDoc(options) {
|
|
340
|
+
let r = new Remult();
|
|
367
341
|
if (!options.version)
|
|
368
342
|
options.version = "1.0.0";
|
|
369
343
|
let spec = {
|
|
@@ -412,41 +386,59 @@ export class RemultServerImplementation {
|
|
|
412
386
|
return item;
|
|
413
387
|
}
|
|
414
388
|
};
|
|
415
|
-
for (const
|
|
416
|
-
let
|
|
389
|
+
for (const e of this.options.entities) {
|
|
390
|
+
let meta = r.repo(e).metadata;
|
|
391
|
+
let key = getEntityKey(e);
|
|
417
392
|
let parameters = [];
|
|
418
393
|
if (key) {
|
|
394
|
+
let mutationKey = key;
|
|
419
395
|
let properties = {};
|
|
396
|
+
let mutationProperties = {};
|
|
420
397
|
for (const f of meta.fields) {
|
|
421
398
|
let type = f.valueType == String ? "string" :
|
|
422
399
|
f.valueType == Boolean ? "boolean" :
|
|
423
400
|
f.valueType == Date ? "string" :
|
|
424
401
|
f.valueType == Number ? "number" :
|
|
425
402
|
"object";
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
403
|
+
if (f.options.includeInApi !== false) {
|
|
404
|
+
properties[f.key] = {
|
|
405
|
+
type
|
|
406
|
+
};
|
|
407
|
+
if (f.options.allowApiUpdate !== false) {
|
|
408
|
+
mutationProperties[f.key] = {
|
|
409
|
+
type
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
parameters.push({
|
|
413
|
+
"name": f.key,
|
|
414
|
+
"in": "query",
|
|
415
|
+
"description": "filter equal to " + f.key,
|
|
416
|
+
"required": false,
|
|
417
|
+
"style": "simple",
|
|
418
|
+
type
|
|
419
|
+
});
|
|
420
|
+
parameters.push({
|
|
421
|
+
"name": f.key + "_ne",
|
|
422
|
+
"in": "query",
|
|
423
|
+
"description": "filter not equal to " + f.key,
|
|
424
|
+
"required": false,
|
|
425
|
+
"style": "simple",
|
|
426
|
+
type
|
|
427
|
+
});
|
|
428
|
+
}
|
|
445
429
|
}
|
|
446
430
|
spec.components.schemas[key] = {
|
|
447
431
|
type: "object",
|
|
448
432
|
properties
|
|
449
433
|
};
|
|
434
|
+
//TODO - handle allow api read also on the get level
|
|
435
|
+
if (JSON.stringify(properties) !== JSON.stringify(mutationProperties)) {
|
|
436
|
+
mutationKey += 'Mutation';
|
|
437
|
+
spec.components.schemas[mutationKey] = {
|
|
438
|
+
type: "object",
|
|
439
|
+
properties: mutationProperties
|
|
440
|
+
};
|
|
441
|
+
}
|
|
450
442
|
let definition = {
|
|
451
443
|
"$ref": "#/components/schemas/" + key
|
|
452
444
|
};
|
|
@@ -456,8 +448,8 @@ export class RemultServerImplementation {
|
|
|
456
448
|
condition = meta.options.allowApiCrud;
|
|
457
449
|
return secureBase(condition, def, item);
|
|
458
450
|
};
|
|
459
|
-
let apiPath = spec.paths['/
|
|
460
|
-
let apiPathWithId = spec.paths['/
|
|
451
|
+
let apiPath = spec.paths[this.options.rootPath + '/' + key] = {};
|
|
452
|
+
let apiPathWithId = spec.paths[this.options.rootPath + '/' + key + "/{id}"] = {};
|
|
461
453
|
//https://github.com/2fd/open-api.d.ts
|
|
462
454
|
apiPath.get = secure(meta.options.allowApiRead, true, {
|
|
463
455
|
description: "return an array of " + key + ". supports filter operators. For more info on filtering [see this article](https://remult.dev/docs/rest-api.html#filter)",
|
|
@@ -516,7 +508,7 @@ export class RemultServerImplementation {
|
|
|
516
508
|
"content": {
|
|
517
509
|
"application/json": {
|
|
518
510
|
"schema": {
|
|
519
|
-
"$ref": "#/components/schemas/" +
|
|
511
|
+
"$ref": "#/components/schemas/" + mutationKey
|
|
520
512
|
}
|
|
521
513
|
}
|
|
522
514
|
}
|
package/graphql.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function remultGraphql(api:
|
|
3
|
-
resolvers: {
|
|
4
|
-
Query: {};
|
|
5
|
-
};
|
|
1
|
+
import { RemultExpressServer } from "./remult-express";
|
|
2
|
+
export declare function remultGraphql(api: RemultExpressServer): {
|
|
6
3
|
rootValue: {};
|
|
7
4
|
schema: string;
|
|
8
5
|
};
|
package/graphql.js
CHANGED
|
@@ -2,57 +2,54 @@
|
|
|
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");
|
|
5
8
|
function remultGraphql(api) {
|
|
6
9
|
var e_1, _a;
|
|
7
10
|
var _this = this;
|
|
8
11
|
var _b;
|
|
9
|
-
var
|
|
10
|
-
var entities = server.getEntities();
|
|
12
|
+
var r = new _1.Remult();
|
|
11
13
|
var types = [];
|
|
12
14
|
var filterTypes = '';
|
|
13
15
|
var query = '';
|
|
14
16
|
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 (e) {
|
|
24
24
|
var e_2, _a;
|
|
25
|
+
var meta = r.repo(e).metadata;
|
|
25
26
|
var filterFields = '';
|
|
26
27
|
var key = meta.key;
|
|
27
28
|
var t = getType(key);
|
|
28
|
-
var q = "\n\t" + key + "(options: options, filter:" + key + "Filter): [" +
|
|
29
|
+
var q = "\n\t" + key + "(options: options, filter:" + key + "Filter): [" + key + "]";
|
|
29
30
|
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 = "String";
|
|
35
35
|
switch (f.valueType) {
|
|
36
36
|
case Boolean:
|
|
37
|
-
|
|
37
|
+
type = "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 = "Int";
|
|
43
43
|
else
|
|
44
|
-
|
|
44
|
+
type = "Float";
|
|
45
45
|
}
|
|
46
46
|
break;
|
|
47
47
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
t.fields += "\n\t" + f.key + ":" + getTypeName(refKey_1);
|
|
48
|
+
if (context_1.allEntities.includes(f.valueType)) {
|
|
49
|
+
var refKey_1 = r.repo(f.valueType).metadata.key;
|
|
50
|
+
t.fields += "\n\t" + f.key + ":" + refKey_1;
|
|
52
51
|
t.resultProcessors.push(function (r) {
|
|
53
52
|
var val = r[f.key];
|
|
54
|
-
if (val === null || val === undefined)
|
|
55
|
-
return null;
|
|
56
53
|
r[f.key] = function (args, req, gqlInfo) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
57
54
|
var queryResult;
|
|
58
55
|
return tslib_1.__generator(this, function (_a) {
|
|
@@ -83,17 +80,11 @@ function remultGraphql(api) {
|
|
|
83
80
|
});
|
|
84
81
|
}
|
|
85
82
|
else
|
|
86
|
-
t.fields += "\n\t" + f.key + ":" +
|
|
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
|
-
};
|
|
83
|
+
t.fields += "\n\t" + f.key + ":" + type;
|
|
93
84
|
try {
|
|
94
85
|
for (var _d = (e_3 = void 0, tslib_1.__values(["", "_ne"])), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
95
86
|
var operator = _e.value;
|
|
96
|
-
|
|
87
|
+
filterFields += "\n\t" + f.key + operator + ":" + type;
|
|
97
88
|
}
|
|
98
89
|
}
|
|
99
90
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
@@ -107,7 +98,7 @@ function remultGraphql(api) {
|
|
|
107
98
|
try {
|
|
108
99
|
for (var _f = (e_4 = void 0, tslib_1.__values(["_gt", "_gte", "_lt", "_lte"])), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
109
100
|
var operator = _g.value;
|
|
110
|
-
|
|
101
|
+
filterFields += "\n\t" + f.key + operator + ":" + type;
|
|
111
102
|
}
|
|
112
103
|
}
|
|
113
104
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
@@ -121,7 +112,7 @@ function remultGraphql(api) {
|
|
|
121
112
|
try {
|
|
122
113
|
for (var _h = (e_5 = void 0, tslib_1.__values(["_st", "_contains"])), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
123
114
|
var operator = _j.value;
|
|
124
|
-
|
|
115
|
+
filterFields += "\n\t" + f.key + operator + ":" + type;
|
|
125
116
|
}
|
|
126
117
|
}
|
|
127
118
|
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
@@ -132,8 +123,8 @@ function remultGraphql(api) {
|
|
|
132
123
|
finally { if (e_5) throw e_5.error; }
|
|
133
124
|
}
|
|
134
125
|
if (f.allowNull)
|
|
135
|
-
|
|
136
|
-
|
|
126
|
+
filterFields += "\n\t" + f.key + "_null:Boolean";
|
|
127
|
+
filterFields += "\n\t" + f.key + "_in:[" + type + "]";
|
|
137
128
|
}
|
|
138
129
|
};
|
|
139
130
|
try {
|
|
@@ -159,13 +150,16 @@ function remultGraphql(api) {
|
|
|
159
150
|
return [2 /*return*/, new Promise(function (res, error) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
160
151
|
var _this = this;
|
|
161
152
|
return tslib_1.__generator(this, function (_a) {
|
|
162
|
-
|
|
163
|
-
|
|
153
|
+
//TODO - consider this with remult usage when working with other servers
|
|
154
|
+
api.withRemult(req, undefined, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
155
|
+
var remult, repo, dApi, result, err;
|
|
164
156
|
return tslib_1.__generator(this, function (_a) {
|
|
165
157
|
switch (_a.label) {
|
|
166
|
-
case 0: return [4 /*yield*/,
|
|
158
|
+
case 0: return [4 /*yield*/, api.getRemult(req)];
|
|
167
159
|
case 1:
|
|
168
|
-
|
|
160
|
+
remult = _a.sent();
|
|
161
|
+
repo = remult.repo(e);
|
|
162
|
+
dApi = new data_api_1.DataApi(repo, remult);
|
|
169
163
|
return [4 /*yield*/, dApi.getArray({
|
|
170
164
|
success: function (x) { return result = x.map(function (y) {
|
|
171
165
|
t.resultProcessors.forEach(function (z) { return z(y); });
|
|
@@ -190,11 +184,6 @@ function remultGraphql(api) {
|
|
|
190
184
|
case "_order":
|
|
191
185
|
return options.order;
|
|
192
186
|
}
|
|
193
|
-
if (filter) {
|
|
194
|
-
var f = filterFieldMap_1.get(key);
|
|
195
|
-
if (f)
|
|
196
|
-
return filter[f];
|
|
197
|
-
}
|
|
198
187
|
}
|
|
199
188
|
}, filter)];
|
|
200
189
|
case 2:
|
|
@@ -213,19 +202,18 @@ function remultGraphql(api) {
|
|
|
213
202
|
}); })];
|
|
214
203
|
});
|
|
215
204
|
}); };
|
|
216
|
-
resolversQuery[key] = function (origItem, args, req, gqlInfo) { return root[key](args, req, gqlInfo); };
|
|
217
205
|
}
|
|
218
206
|
};
|
|
219
207
|
try {
|
|
220
|
-
for (var
|
|
221
|
-
var
|
|
222
|
-
_loop_1(
|
|
208
|
+
for (var allEntities_1 = tslib_1.__values(context_1.allEntities), allEntities_1_1 = allEntities_1.next(); !allEntities_1_1.done; allEntities_1_1 = allEntities_1.next()) {
|
|
209
|
+
var e = allEntities_1_1.value;
|
|
210
|
+
_loop_1(e);
|
|
223
211
|
}
|
|
224
212
|
}
|
|
225
213
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
226
214
|
finally {
|
|
227
215
|
try {
|
|
228
|
-
if (
|
|
216
|
+
if (allEntities_1_1 && !allEntities_1_1.done && (_a = allEntities_1.return)) _a.call(allEntities_1);
|
|
229
217
|
}
|
|
230
218
|
finally { if (e_1) throw e_1.error; }
|
|
231
219
|
}
|
|
@@ -233,15 +221,16 @@ function remultGraphql(api) {
|
|
|
233
221
|
query = "type Query {" + query + "\n}";
|
|
234
222
|
}
|
|
235
223
|
return {
|
|
236
|
-
resolvers: resolvers,
|
|
237
224
|
rootValue: root,
|
|
238
225
|
schema: types.map(function (_a) {
|
|
239
226
|
var key = _a.key, fields = _a.fields, moreFields = _a.moreFields;
|
|
240
|
-
return "type " +
|
|
227
|
+
return "type " + key + "{" + fields + moreFields + "\n}\n";
|
|
241
228
|
}).join('') + "\n" + query + "\n" + filterTypes + "\ninput options{\n limit:Int\n page:Int\n sort:String\n order:String\n}\n"
|
|
242
229
|
};
|
|
243
230
|
}
|
|
244
231
|
exports.remultGraphql = remultGraphql;
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
232
|
+
//TODO - filter doesn't work since we changed id_eq to be id.eq in rest, but graphql doesn't allow it.
|
|
233
|
+
//TODO - the list of entities, is based on allEntities - that's wrong - it should be based on the api entities - or a separate array.
|
|
234
|
+
//TODO - it's currently only planned for express server - it uses it's 'withRemult' that doesn't exist in all other servers.
|
|
235
|
+
//TODO - it doesn't support mutations
|
|
236
|
+
//TODO - it doesn't support backend methods
|
package/package.json
CHANGED
package/remult-express.js
CHANGED
|
@@ -27,8 +27,13 @@ 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
|
-
|
|
30
|
+
withRemult: function () {
|
|
31
|
+
var args = [];
|
|
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
|
+
}
|
|
32
37
|
});
|
|
33
38
|
}
|
|
34
39
|
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,10 +71,11 @@ 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
|
-
|
|
74
|
+
withRemult: function (req, what) { return new Promise(function (resolve) {
|
|
75
|
+
return api.withRemult(req, undefined, function () {
|
|
76
|
+
what().then(resolve);
|
|
77
|
+
});
|
|
78
|
+
}); }
|
|
78
79
|
});
|
|
79
80
|
}
|
|
80
81
|
exports.remultFastify = remultFastify;
|
package/remult-fresh.js
CHANGED
package/remult-next.js
CHANGED
|
@@ -14,7 +14,6 @@ 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'](); }
|
|
18
17
|
}, {
|
|
19
18
|
getServerSideProps: function (getServerPropsFunction) {
|
|
20
19
|
return function (context) {
|
|
@@ -161,9 +160,12 @@ function remultNextApp(options) {
|
|
|
161
160
|
PUT: handler,
|
|
162
161
|
DELETE: handler,
|
|
163
162
|
withRemult: function (what) {
|
|
164
|
-
return
|
|
165
|
-
|
|
166
|
-
|
|
163
|
+
return new Promise(function (resolve) {
|
|
164
|
+
return result.withRemult({}, undefined, function () {
|
|
165
|
+
what().then(resolve);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}
|
|
167
169
|
};
|
|
168
170
|
}
|
|
169
171
|
exports.remultNextApp = remultNextApp;
|
package/remult-sveltekit.js
CHANGED
|
@@ -106,7 +106,6 @@ 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'](); }
|
|
110
109
|
});
|
|
111
110
|
}
|
|
112
111
|
exports.remultSveltekit = remultSveltekit;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { queuedJobInfoResponse } from '../src/server-action';
|
|
2
2
|
import { DataProvider } from '../src/data-interfaces';
|
|
3
|
-
import { DataApi } from '../src/data-api';
|
|
4
3
|
import { Remult, UserInfo } from '../src/context';
|
|
5
4
|
import { ClassType } from '../classType';
|
|
6
|
-
import {
|
|
5
|
+
import { Repository } from '../src/remult3';
|
|
7
6
|
import { IdEntity } from '../src/id-entity';
|
|
8
7
|
import { LiveQueryStorage, SubscriptionServer } from '../src/live-query/SubscriptionServer';
|
|
9
8
|
export interface RemultServerOptions<RequestType> {
|
|
@@ -71,12 +70,6 @@ export interface RemultServerCore<RequestType> {
|
|
|
71
70
|
title: string;
|
|
72
71
|
version?: string;
|
|
73
72
|
}): 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>;
|
|
80
73
|
}
|
|
81
74
|
export declare type GenericRouter = {
|
|
82
75
|
route(path: string): SpecificRoute;
|
package/server/expressBridge.js
CHANGED
|
@@ -34,7 +34,6 @@ function createRemultServerCore(options, serverCoreOptions) {
|
|
|
34
34
|
if (options.ensureSchema === undefined)
|
|
35
35
|
options.ensureSchema = true;
|
|
36
36
|
RemultAsyncLocalStorage.enable();
|
|
37
|
-
var entitiesMetaData = [];
|
|
38
37
|
dataProvider = dataProvider.then(function (dp) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
39
38
|
var remult;
|
|
40
39
|
var _this = this;
|
|
@@ -44,7 +43,7 @@ function createRemultServerCore(options, serverCoreOptions) {
|
|
|
44
43
|
remult = new context_1.Remult(dp);
|
|
45
44
|
return [4 /*yield*/, new Promise(function (res) {
|
|
46
45
|
RemultAsyncLocalStorage.instance.run(remult, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
47
|
-
var started_1, startConsoleLog, _a, _b, item, e_1_1;
|
|
46
|
+
var started_1, startConsoleLog, entitiesMetadata, _a, _b, item, e_1_1;
|
|
48
47
|
var e_1, _c;
|
|
49
48
|
return tslib_1.__generator(this, function (_d) {
|
|
50
49
|
switch (_d.label) {
|
|
@@ -57,10 +56,10 @@ function createRemultServerCore(options, serverCoreOptions) {
|
|
|
57
56
|
started_1 = true;
|
|
58
57
|
console.time("Ensure Schema");
|
|
59
58
|
};
|
|
60
|
-
entitiesMetaData.push.apply(entitiesMetaData, tslib_1.__spread(options.entities.map(function (e) { return remult.repo(e).metadata; })));
|
|
61
59
|
if (!dp.ensureSchema) return [3 /*break*/, 2];
|
|
62
60
|
startConsoleLog();
|
|
63
|
-
|
|
61
|
+
entitiesMetadata = options.entities.map(function (e) { return remult.repo(e).metadata; });
|
|
62
|
+
return [4 /*yield*/, dp.ensureSchema(entitiesMetadata)];
|
|
64
63
|
case 1:
|
|
65
64
|
_d.sent();
|
|
66
65
|
_d.label = 2;
|
|
@@ -127,7 +126,7 @@ function createRemultServerCore(options, serverCoreOptions) {
|
|
|
127
126
|
if (options.rootPath === undefined)
|
|
128
127
|
options.rootPath = '/api';
|
|
129
128
|
server_action_1.actionInfo.runningOnServer = true;
|
|
130
|
-
var bridge = new RemultServerImplementation(new inProcessQueueHandler(options.queueStorage), options, dataProvider, serverCoreOptions
|
|
129
|
+
var bridge = new RemultServerImplementation(new inProcessQueueHandler(options.queueStorage), options, dataProvider, serverCoreOptions);
|
|
131
130
|
return bridge;
|
|
132
131
|
}
|
|
133
132
|
exports.createRemultServerCore = createRemultServerCore;
|
|
@@ -166,13 +165,12 @@ var RemultAsyncLocalStorage = /** @class */ (function () {
|
|
|
166
165
|
exports.RemultAsyncLocalStorage = RemultAsyncLocalStorage;
|
|
167
166
|
/* @internal*/
|
|
168
167
|
var RemultServerImplementation = /** @class */ (function () {
|
|
169
|
-
function RemultServerImplementation(queue, options, dataProvider, coreOptions
|
|
168
|
+
function RemultServerImplementation(queue, options, dataProvider, coreOptions) {
|
|
170
169
|
var _this = this;
|
|
171
170
|
this.queue = queue;
|
|
172
171
|
this.options = options;
|
|
173
172
|
this.dataProvider = dataProvider;
|
|
174
173
|
this.coreOptions = coreOptions;
|
|
175
|
-
this.entitiesMetaData = entitiesMetaData;
|
|
176
174
|
this.liveQueryStorage = new SubscriptionServer_1.InMemoryLiveQueryStorage();
|
|
177
175
|
this.runWithSerializedJsonContextData = function (jsonContextData, entityKey, what) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
178
176
|
var _loop_1, this_1, _a, _b, e, state_1, e_2_1;
|
|
@@ -268,40 +266,6 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
268
266
|
if (options.subscriptionServer)
|
|
269
267
|
this.subscriptionServer = options.subscriptionServer;
|
|
270
268
|
}
|
|
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
|
-
};
|
|
305
269
|
;
|
|
306
270
|
RemultServerImplementation.prototype.getRouteImpl = function () {
|
|
307
271
|
if (!this.routeImpl) {
|
|
@@ -510,7 +474,6 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
510
474
|
return [2 /*return*/, dataApiFactory(c).delete(res, orig.params.id)];
|
|
511
475
|
}); }); }));
|
|
512
476
|
};
|
|
513
|
-
//runs with remult but without init request
|
|
514
477
|
RemultServerImplementation.prototype.runWithRemult = function (what) {
|
|
515
478
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
516
479
|
var remult, _a;
|
|
@@ -678,6 +641,7 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
678
641
|
};
|
|
679
642
|
RemultServerImplementation.prototype.openApiDoc = function (options) {
|
|
680
643
|
var e_5, _a, e_6, _b;
|
|
644
|
+
var r = new context_1.Remult();
|
|
681
645
|
if (!options.version)
|
|
682
646
|
options.version = "1.0.0";
|
|
683
647
|
var spec = {
|
|
@@ -726,12 +690,15 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
726
690
|
return item;
|
|
727
691
|
}
|
|
728
692
|
};
|
|
729
|
-
var _loop_2 = function (
|
|
693
|
+
var _loop_2 = function (e) {
|
|
730
694
|
var e_7, _a;
|
|
731
|
-
var
|
|
695
|
+
var meta = r.repo(e).metadata;
|
|
696
|
+
var key = remult3_1.getEntityKey(e);
|
|
732
697
|
var parameters = [];
|
|
733
698
|
if (key) {
|
|
699
|
+
var mutationKey = key;
|
|
734
700
|
var properties = {};
|
|
701
|
+
var mutationProperties = {};
|
|
735
702
|
try {
|
|
736
703
|
for (var _b = (e_7 = void 0, tslib_1.__values(meta.fields)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
737
704
|
var f = _c.value;
|
|
@@ -740,25 +707,32 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
740
707
|
f.valueType == Date ? "string" :
|
|
741
708
|
f.valueType == Number ? "number" :
|
|
742
709
|
"object";
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
710
|
+
if (f.options.includeInApi !== false) {
|
|
711
|
+
properties[f.key] = {
|
|
712
|
+
type: type
|
|
713
|
+
};
|
|
714
|
+
if (f.options.allowApiUpdate !== false) {
|
|
715
|
+
mutationProperties[f.key] = {
|
|
716
|
+
type: type
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
parameters.push({
|
|
720
|
+
"name": f.key,
|
|
721
|
+
"in": "query",
|
|
722
|
+
"description": "filter equal to " + f.key,
|
|
723
|
+
"required": false,
|
|
724
|
+
"style": "simple",
|
|
725
|
+
type: type
|
|
726
|
+
});
|
|
727
|
+
parameters.push({
|
|
728
|
+
"name": f.key + "_ne",
|
|
729
|
+
"in": "query",
|
|
730
|
+
"description": "filter not equal to " + f.key,
|
|
731
|
+
"required": false,
|
|
732
|
+
"style": "simple",
|
|
733
|
+
type: type
|
|
734
|
+
});
|
|
735
|
+
}
|
|
762
736
|
}
|
|
763
737
|
}
|
|
764
738
|
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
@@ -772,6 +746,14 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
772
746
|
type: "object",
|
|
773
747
|
properties: properties
|
|
774
748
|
};
|
|
749
|
+
//TODO - handle allow api read also on the get level
|
|
750
|
+
if (JSON.stringify(properties) !== JSON.stringify(mutationProperties)) {
|
|
751
|
+
mutationKey += 'Mutation';
|
|
752
|
+
spec.components.schemas[mutationKey] = {
|
|
753
|
+
type: "object",
|
|
754
|
+
properties: mutationProperties
|
|
755
|
+
};
|
|
756
|
+
}
|
|
775
757
|
var definition = {
|
|
776
758
|
"$ref": "#/components/schemas/" + key
|
|
777
759
|
};
|
|
@@ -781,8 +763,8 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
781
763
|
condition = meta.options.allowApiCrud;
|
|
782
764
|
return secureBase(condition, def, item);
|
|
783
765
|
};
|
|
784
|
-
var apiPath = spec.paths['/
|
|
785
|
-
var apiPathWithId = spec.paths['/
|
|
766
|
+
var apiPath = spec.paths[this_2.options.rootPath + '/' + key] = {};
|
|
767
|
+
var apiPathWithId = spec.paths[this_2.options.rootPath + '/' + key + "/{id}"] = {};
|
|
786
768
|
//https://github.com/2fd/open-api.d.ts
|
|
787
769
|
apiPath.get = secure(meta.options.allowApiRead, true, {
|
|
788
770
|
description: "return an array of " + key + ". supports filter operators. For more info on filtering [see this article](https://remult.dev/docs/rest-api.html#filter)",
|
|
@@ -841,7 +823,7 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
841
823
|
"content": {
|
|
842
824
|
"application/json": {
|
|
843
825
|
"schema": {
|
|
844
|
-
"$ref": "#/components/schemas/" +
|
|
826
|
+
"$ref": "#/components/schemas/" + mutationKey
|
|
845
827
|
}
|
|
846
828
|
}
|
|
847
829
|
}
|
|
@@ -903,10 +885,11 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
903
885
|
});
|
|
904
886
|
}
|
|
905
887
|
};
|
|
888
|
+
var this_2 = this;
|
|
906
889
|
try {
|
|
907
|
-
for (var _c = tslib_1.__values(this.
|
|
908
|
-
var
|
|
909
|
-
_loop_2(
|
|
890
|
+
for (var _c = tslib_1.__values(this.options.entities), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
891
|
+
var e = _d.value;
|
|
892
|
+
_loop_2(e);
|
|
910
893
|
}
|
|
911
894
|
}
|
|
912
895
|
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|