remult 0.25.5-exp.3 → 0.25.5-exp.4
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.js +59 -46
- package/esm/src/remult3/RepositoryImplementation.js +8 -3
- package/esm/src/remult3/remult3.js +11 -12
- package/esm/src/sort.js +1 -1
- package/graphql.js +110 -65
- package/package.json +1 -1
- package/src/remult3/RepositoryImplementation.d.ts +7 -2
- package/src/remult3/RepositoryImplementation.js +8 -3
- package/src/remult3/remult3.js +11 -12
- package/src/remult3/repository-internals.d.ts +6 -0
- package/src/sort.js +1 -1
package/esm/graphql.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getRelationFieldInfo } from './internals.js';
|
|
2
2
|
import { Remult, remult } from './index.js';
|
|
3
3
|
import { DataApi } from './src/data-api.js';
|
|
4
|
+
import { getRepositoryInternals } from './src/remult3/repository-internals.js';
|
|
4
5
|
const v2ConnectionAndPagination = false;
|
|
5
6
|
const andImplementation = false;
|
|
6
7
|
let _removeComments = false;
|
|
@@ -151,6 +152,12 @@ export function remultGraphql(options) {
|
|
|
151
152
|
});
|
|
152
153
|
};
|
|
153
154
|
};
|
|
155
|
+
const handleRequestWithDataApiContextBasedOnRepo = (repo, work) => {
|
|
156
|
+
return createResultPromise(async (response, setResult, arg1, req) => {
|
|
157
|
+
const dApi = new DataApi(repo, remult);
|
|
158
|
+
await work(dApi, response, setResult, arg1, repo.metadata);
|
|
159
|
+
});
|
|
160
|
+
};
|
|
154
161
|
const handleRequestWithDataApiContext = (work) => {
|
|
155
162
|
return createResultPromise(async (response, setResult, arg1, req) => {
|
|
156
163
|
const remult = await options.getRemultFromRequest(req);
|
|
@@ -219,7 +226,8 @@ export function remultGraphql(options) {
|
|
|
219
226
|
await dApi.get({
|
|
220
227
|
...response,
|
|
221
228
|
success: (y) => {
|
|
222
|
-
|
|
229
|
+
const orig = { ...y };
|
|
230
|
+
currentType.query.resultProcessors.forEach((z) => z(y, orig));
|
|
223
231
|
setResult(y);
|
|
224
232
|
},
|
|
225
233
|
}, arg1.id);
|
|
@@ -269,29 +277,7 @@ export function remultGraphql(options) {
|
|
|
269
277
|
});
|
|
270
278
|
}
|
|
271
279
|
root[key] = handleRequestWithDataApiContext(async (dApi, response, setResult, arg1, meta) => {
|
|
272
|
-
setResult
|
|
273
|
-
[itemsKey]: createResultPromise(async (response, setResult) => {
|
|
274
|
-
await dApi.getArray({
|
|
275
|
-
...response,
|
|
276
|
-
success: (x) => {
|
|
277
|
-
setResult(x.map((y) => {
|
|
278
|
-
currentType.query.resultProcessors.forEach((z) => z(y));
|
|
279
|
-
return y;
|
|
280
|
-
}));
|
|
281
|
-
},
|
|
282
|
-
}, {
|
|
283
|
-
get: bridgeQueryOptionsToDataApiGet(arg1),
|
|
284
|
-
}, translateWhereToRestBody(meta.fields, arg1));
|
|
285
|
-
}),
|
|
286
|
-
[totalCountKey]: createResultPromise(async (response, setResult) => {
|
|
287
|
-
await dApi.count({
|
|
288
|
-
...response,
|
|
289
|
-
success: (x) => setResult(x.count),
|
|
290
|
-
}, {
|
|
291
|
-
get: bridgeQueryOptionsToDataApiGet(arg1),
|
|
292
|
-
}, translateWhereToRestBody(meta.fields, arg1));
|
|
293
|
-
}),
|
|
294
|
-
});
|
|
280
|
+
connectionImplementation(setResult, itemsKey, createResultPromise, dApi, currentType, arg1, meta, totalCountKey);
|
|
295
281
|
});
|
|
296
282
|
resolversQuery[key] = (origItem, args, req, gqlInfo) => {
|
|
297
283
|
return root[key](args, req, gqlInfo);
|
|
@@ -326,7 +312,8 @@ export function remultGraphql(options) {
|
|
|
326
312
|
await dApi.post({
|
|
327
313
|
...response,
|
|
328
314
|
created: (y) => {
|
|
329
|
-
|
|
315
|
+
const orig = { ...y };
|
|
316
|
+
currentType.query.resultProcessors.forEach((z) => z(y, orig));
|
|
330
317
|
setResult({
|
|
331
318
|
[toCamelCase(getMetaType(meta))]: y,
|
|
332
319
|
});
|
|
@@ -360,7 +347,8 @@ export function remultGraphql(options) {
|
|
|
360
347
|
await dApi.put({
|
|
361
348
|
...response,
|
|
362
349
|
success: (y) => {
|
|
363
|
-
|
|
350
|
+
const orig = { ...y };
|
|
351
|
+
currentType.query.resultProcessors.forEach((z) => z(y, orig));
|
|
364
352
|
setResult({
|
|
365
353
|
[toCamelCase(getMetaType(meta))]: y,
|
|
366
354
|
});
|
|
@@ -435,19 +423,19 @@ export function remultGraphql(options) {
|
|
|
435
423
|
value: `${getMetaType(ref)}${f.allowNull ? '' : '!'}`,
|
|
436
424
|
comment: f.caption,
|
|
437
425
|
});
|
|
438
|
-
currentType.query.resultProcessors.push((r) => {
|
|
439
|
-
const val = r[ri.type == 'reference' ? f.key : f.options.field]; //p1 - fix
|
|
440
|
-
if (val === null || val === undefined)
|
|
441
|
-
return null;
|
|
426
|
+
currentType.query.resultProcessors.push((r, orig) => {
|
|
442
427
|
r[f.key] = async (args, req, gqlInfo) => {
|
|
443
|
-
const
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
428
|
+
const remult = await options.getRemultFromRequest(req);
|
|
429
|
+
const myRepo = remult.repo(meta.entityType);
|
|
430
|
+
const item = myRepo.fromJson(orig);
|
|
431
|
+
let { toRepo, returnNull, returnUndefined } = getRepositoryInternals(myRepo).getFocusedRelationRepo(myRepo.fields.find(f), item);
|
|
432
|
+
if (returnNull || returnUndefined)
|
|
433
|
+
return null;
|
|
434
|
+
const result = await handleRequestWithDataApiContextBasedOnRepo(toRepo, async (dApi, response, setResult, arg1, meta) => {
|
|
435
|
+
return await connectionImplementation(setResult, itemsKey, createResultPromise, dApi, upsertTypes(getMetaType(ref)), arg1, meta, totalCountKey);
|
|
436
|
+
})({ ...args, options: { limit: 1 } }, req);
|
|
437
|
+
const resultItems = await result.items();
|
|
438
|
+
return resultItems[0];
|
|
451
439
|
};
|
|
452
440
|
});
|
|
453
441
|
break;
|
|
@@ -461,15 +449,14 @@ export function remultGraphql(options) {
|
|
|
461
449
|
comment: `List all \`${getMetaType(meta)}\` of \`${refKey}\``,
|
|
462
450
|
});
|
|
463
451
|
currentType.query.resultProcessors.push((r) => {
|
|
464
|
-
const val = r.id;
|
|
465
452
|
r[f.key] = async (args, req, gqlInfo) => {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
}, req
|
|
453
|
+
const remult = await options.getRemultFromRequest(req);
|
|
454
|
+
const myRepo = remult.repo(meta.entityType);
|
|
455
|
+
const item = myRepo.fromJson(r);
|
|
456
|
+
let relRepo = myRepo.relations(item)[f.key];
|
|
457
|
+
return handleRequestWithDataApiContextBasedOnRepo(relRepo, async (dApi, response, setResult, arg1, meta) => {
|
|
458
|
+
return await connectionImplementation(setResult, itemsKey, createResultPromise, dApi, upsertTypes(getMetaType(ref)), arg1, meta, totalCountKey);
|
|
459
|
+
})(args, req);
|
|
473
460
|
};
|
|
474
461
|
});
|
|
475
462
|
}
|
|
@@ -678,6 +665,32 @@ export function remultGraphql(options) {
|
|
|
678
665
|
.join(`\n\n`)}
|
|
679
666
|
`,
|
|
680
667
|
};
|
|
668
|
+
function connectionImplementation(setResult, itemsKey, createResultPromise, dApi, currentType, arg1, meta, totalCountKey) {
|
|
669
|
+
setResult({
|
|
670
|
+
[itemsKey]: createResultPromise(async (response, setResult) => {
|
|
671
|
+
await dApi.getArray({
|
|
672
|
+
...response,
|
|
673
|
+
success: (x) => {
|
|
674
|
+
setResult(x.map((y) => {
|
|
675
|
+
const orig = { ...y };
|
|
676
|
+
currentType.query.resultProcessors.forEach((z) => z(y, orig));
|
|
677
|
+
return y;
|
|
678
|
+
}));
|
|
679
|
+
},
|
|
680
|
+
}, {
|
|
681
|
+
get: bridgeQueryOptionsToDataApiGet(arg1),
|
|
682
|
+
}, translateWhereToRestBody(meta.fields, arg1));
|
|
683
|
+
}),
|
|
684
|
+
[totalCountKey]: createResultPromise(async (response, setResult) => {
|
|
685
|
+
await dApi.count({
|
|
686
|
+
...response,
|
|
687
|
+
success: (x) => setResult(x.count),
|
|
688
|
+
}, {
|
|
689
|
+
get: bridgeQueryOptionsToDataApiGet(arg1),
|
|
690
|
+
}, translateWhereToRestBody(meta.fields, arg1));
|
|
691
|
+
}),
|
|
692
|
+
});
|
|
693
|
+
}
|
|
681
694
|
}
|
|
682
695
|
function getQueryArgsConnection(key) {
|
|
683
696
|
const queryArgsConnection = [
|
|
@@ -82,9 +82,7 @@ export class RepositoryImplementation {
|
|
|
82
82
|
const rel = getRelationFieldInfo(field);
|
|
83
83
|
if (!rel)
|
|
84
84
|
throw Error(key + ' is not a relation');
|
|
85
|
-
|
|
86
|
-
let { findOptions, returnNull, returnUndefined } = this.findOptionsBasedOnRelation(rel, field, undefined, item, repo);
|
|
87
|
-
const toRepo = new RepositoryImplementation(repo.entity, repo.remult, repo.dataProvider, repo._info, findOptions);
|
|
85
|
+
const { toRepo, returnNull, returnUndefined } = this.getFocusedRelationRepo(field, item);
|
|
88
86
|
if (rel.type === 'toMany')
|
|
89
87
|
return toRepo;
|
|
90
88
|
else
|
|
@@ -100,6 +98,13 @@ export class RepositoryImplementation {
|
|
|
100
98
|
},
|
|
101
99
|
});
|
|
102
100
|
}
|
|
101
|
+
getFocusedRelationRepo(field, item) {
|
|
102
|
+
const rel = getRelationFieldInfo(field);
|
|
103
|
+
let repo = rel.toRepo;
|
|
104
|
+
let { findOptions, returnNull, returnUndefined } = this.findOptionsBasedOnRelation(rel, field, undefined, item, repo);
|
|
105
|
+
const toRepo = new RepositoryImplementation(repo.entity, repo.remult, repo.dataProvider, repo._info, findOptions);
|
|
106
|
+
return { toRepo, returnNull, returnUndefined };
|
|
107
|
+
}
|
|
103
108
|
__edp;
|
|
104
109
|
get edp() {
|
|
105
110
|
return this.__edp
|
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
export {};
|
|
2
|
+
//y1 - another toOne scenario - for a one to one relation, where the other table has my id in one of its fields.
|
|
2
3
|
//y1 - number default storage in knex is decimal and it by default has 8,2 - meaning only 999,999 - I think it should be way bigger than that. in firefly we do at least 18 - https://discord.com/channels/975754286384418847/1195162533447876658
|
|
4
|
+
//y1 - talk about the parameter issue with backend methods
|
|
3
5
|
//y1 - tried to upgrade vitest, nuxt tests are failing with loading uuid - sounds familiar?
|
|
4
6
|
//y2 - from the crm-demo(https://crm-demo.up.railway.app/deals), after editing a deal: - _updateEntityBasedOnApi
|
|
5
7
|
//y2 - Backend methods are transactions, it's not intuitive and maybe should be optional / opt in
|
|
6
8
|
//y2 - how to run a transaction as a user
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//p1 - Write some ctrl g
|
|
9
|
+
//p2 - enum column
|
|
10
|
+
//p2 - I think there should be a way to throw a forbidden exception
|
|
10
11
|
//y2 - get backend methods to work when specifying types for date, and entities as poco's
|
|
11
12
|
//y2 - required
|
|
12
13
|
//y2 - reconsider validators
|
|
13
14
|
//y2 - message for invalid value
|
|
14
15
|
//y2 - message for relation that is missing
|
|
15
|
-
//
|
|
16
|
+
//p2 - more column types
|
|
16
17
|
//p2 - processError in remult express
|
|
17
18
|
//p2 - allow find options preprocessor for api calls, to use for authorization
|
|
18
|
-
//
|
|
19
|
+
//p2 - write doc about controlling updates of rows...
|
|
19
20
|
//p1 - need a way to extract the fields from the relation - for generating relation based sql
|
|
20
21
|
//p1 - when doing this, work on graphql relation with fields not just field
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
22
|
+
//p2 - add docs for apply changes
|
|
23
|
+
//p2 - when subscribe is forbidden - the query still runs after the renew process
|
|
24
|
+
//p2 - 'update tasks set where id = $1
|
|
24
25
|
//y2 - consider multi tenancies
|
|
25
26
|
//y2 - allow api read to also support instance and filter. - problem with promise
|
|
26
|
-
//
|
|
27
|
+
//p2 - doc this:
|
|
27
28
|
/**
|
|
28
29
|
* //p2 - doc this
|
|
29
30
|
remult.apiClient.httpClient = (
|
|
@@ -46,12 +47,10 @@ remult.apiClient.url='localhost:3007/api
|
|
|
46
47
|
*/
|
|
47
48
|
//p1 - remult-admin doesn't handle primary key that has compound column
|
|
48
49
|
//p1 - remult-admin didn't show a update for a table with a uniqua that is numeric
|
|
49
|
-
//p1 - crm demo graphql error
|
|
50
|
-
//p1 - fix multiple instances of remult: the defaultRemult and async local hook - and columnsOfType - all can be tests with a vite project loading `remult-admin`
|
|
51
50
|
//p1 -check if checouknt doesn't respect allow read (I think)
|
|
52
51
|
//p1 - allow api update only for new rows
|
|
53
52
|
//p1 - getFields didn't work for kobi in the home component
|
|
54
|
-
//p1 - https://codesandbox.io/p/devbox/demo-sql-expression-wqvj4g
|
|
53
|
+
//p1 - add to docs https://codesandbox.io/p/devbox/demo-sql-expression-wqvj4g
|
|
55
54
|
//p2 - document validators
|
|
56
55
|
//p2 - and validators to reference
|
|
57
56
|
//y2 - discuss a default date formatter
|
package/esm/src/sort.js
CHANGED
|
@@ -63,8 +63,8 @@ export class Sort {
|
|
|
63
63
|
};
|
|
64
64
|
if (field) {
|
|
65
65
|
const rel = getRelationFieldInfo(field);
|
|
66
|
-
const op = field.options; //p1 - fix
|
|
67
66
|
if (rel?.type === 'toOne') {
|
|
67
|
+
const op = rel.options;
|
|
68
68
|
if (typeof op.field === 'string') {
|
|
69
69
|
addSegment(entityDefs.fields.find(op.field));
|
|
70
70
|
}
|
package/graphql.js
CHANGED
|
@@ -5,6 +5,7 @@ var tslib_1 = require("tslib");
|
|
|
5
5
|
var internals_js_1 = require("./internals.js");
|
|
6
6
|
var index_js_1 = require("./index.js");
|
|
7
7
|
var data_api_js_1 = require("./src/data-api.js");
|
|
8
|
+
var repository_internals_js_1 = require("./src/remult3/repository-internals.js");
|
|
8
9
|
var v2ConnectionAndPagination = false;
|
|
9
10
|
var andImplementation = false;
|
|
10
11
|
var _removeComments = false;
|
|
@@ -203,6 +204,21 @@ function remultGraphql(options) {
|
|
|
203
204
|
});
|
|
204
205
|
}); };
|
|
205
206
|
};
|
|
207
|
+
var handleRequestWithDataApiContextBasedOnRepo_1 = function (repo, work) {
|
|
208
|
+
return createResultPromise_1(function (response, setResult, arg1, req) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
209
|
+
var dApi;
|
|
210
|
+
return tslib_1.__generator(this, function (_a) {
|
|
211
|
+
switch (_a.label) {
|
|
212
|
+
case 0:
|
|
213
|
+
dApi = new data_api_js_1.DataApi(repo, index_js_1.remult);
|
|
214
|
+
return [4 /*yield*/, work(dApi, response, setResult, arg1, repo.metadata)];
|
|
215
|
+
case 1:
|
|
216
|
+
_a.sent();
|
|
217
|
+
return [2 /*return*/];
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}); });
|
|
221
|
+
};
|
|
206
222
|
var handleRequestWithDataApiContext_1 = function (work) {
|
|
207
223
|
return createResultPromise_1(function (response, setResult, arg1, req) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
208
224
|
var remult, repo, dApi;
|
|
@@ -276,7 +292,8 @@ function remultGraphql(options) {
|
|
|
276
292
|
return tslib_1.__generator(this, function (_a) {
|
|
277
293
|
switch (_a.label) {
|
|
278
294
|
case 0: return [4 /*yield*/, dApi.get(tslib_1.__assign(tslib_1.__assign({}, response), { success: function (y) {
|
|
279
|
-
|
|
295
|
+
var orig = tslib_1.__assign({}, y);
|
|
296
|
+
currentType.query.resultProcessors.forEach(function (z) { return z(y, orig); });
|
|
280
297
|
setResult(y);
|
|
281
298
|
} }), arg1.id)];
|
|
282
299
|
case 1:
|
|
@@ -330,40 +347,8 @@ function remultGraphql(options) {
|
|
|
330
347
|
});
|
|
331
348
|
}
|
|
332
349
|
root[key] = handleRequestWithDataApiContext_1(function (dApi, response, setResult, arg1, meta) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
return tslib_1.__generator(this, function (_b) {
|
|
336
|
-
setResult((_a = {},
|
|
337
|
-
_a[itemsKey_1] = createResultPromise_1(function (response, setResult) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
338
|
-
return tslib_1.__generator(this, function (_a) {
|
|
339
|
-
switch (_a.label) {
|
|
340
|
-
case 0: return [4 /*yield*/, dApi.getArray(tslib_1.__assign(tslib_1.__assign({}, response), { success: function (x) {
|
|
341
|
-
setResult(x.map(function (y) {
|
|
342
|
-
currentType.query.resultProcessors.forEach(function (z) { return z(y); });
|
|
343
|
-
return y;
|
|
344
|
-
}));
|
|
345
|
-
} }), {
|
|
346
|
-
get: bridgeQueryOptionsToDataApiGet(arg1),
|
|
347
|
-
}, translateWhereToRestBody(meta.fields, arg1))];
|
|
348
|
-
case 1:
|
|
349
|
-
_a.sent();
|
|
350
|
-
return [2 /*return*/];
|
|
351
|
-
}
|
|
352
|
-
});
|
|
353
|
-
}); }),
|
|
354
|
-
_a[totalCountKey_1] = createResultPromise_1(function (response, setResult) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
355
|
-
return tslib_1.__generator(this, function (_a) {
|
|
356
|
-
switch (_a.label) {
|
|
357
|
-
case 0: return [4 /*yield*/, dApi.count(tslib_1.__assign(tslib_1.__assign({}, response), { success: function (x) { return setResult(x.count); } }), {
|
|
358
|
-
get: bridgeQueryOptionsToDataApiGet(arg1),
|
|
359
|
-
}, translateWhereToRestBody(meta.fields, arg1))];
|
|
360
|
-
case 1:
|
|
361
|
-
_a.sent();
|
|
362
|
-
return [2 /*return*/];
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
}); }),
|
|
366
|
-
_a));
|
|
350
|
+
return tslib_1.__generator(this, function (_a) {
|
|
351
|
+
connectionImplementation(setResult, itemsKey_1, createResultPromise_1, dApi, currentType, arg1, meta, totalCountKey_1);
|
|
367
352
|
return [2 /*return*/];
|
|
368
353
|
});
|
|
369
354
|
}); });
|
|
@@ -403,7 +388,8 @@ function remultGraphql(options) {
|
|
|
403
388
|
switch (_a.label) {
|
|
404
389
|
case 0: return [4 /*yield*/, dApi.post(tslib_1.__assign(tslib_1.__assign({}, response), { created: function (y) {
|
|
405
390
|
var _a;
|
|
406
|
-
|
|
391
|
+
var orig = tslib_1.__assign({}, y);
|
|
392
|
+
currentType.query.resultProcessors.forEach(function (z) { return z(y, orig); });
|
|
407
393
|
setResult((_a = {},
|
|
408
394
|
_a[toCamelCase(getMetaType(meta))] = y,
|
|
409
395
|
_a));
|
|
@@ -442,7 +428,8 @@ function remultGraphql(options) {
|
|
|
442
428
|
switch (_a.label) {
|
|
443
429
|
case 0: return [4 /*yield*/, dApi.put(tslib_1.__assign(tslib_1.__assign({}, response), { success: function (y) {
|
|
444
430
|
var _a;
|
|
445
|
-
|
|
431
|
+
var orig = tslib_1.__assign({}, y);
|
|
432
|
+
currentType.query.resultProcessors.forEach(function (z) { return z(y, orig); });
|
|
446
433
|
setResult((_a = {},
|
|
447
434
|
_a[toCamelCase(getMetaType(meta))] = y,
|
|
448
435
|
_a));
|
|
@@ -519,7 +506,7 @@ function remultGraphql(options) {
|
|
|
519
506
|
ref = entities.find(function (i) { return i.entityType === refType_1; });
|
|
520
507
|
}
|
|
521
508
|
notARealField = ri.type === 'toOne' || ri.type === 'toMany';
|
|
522
|
-
var
|
|
509
|
+
var refKey = ref.key;
|
|
523
510
|
switch (ri.type) {
|
|
524
511
|
case 'reference':
|
|
525
512
|
case 'toOne':
|
|
@@ -528,21 +515,34 @@ function remultGraphql(options) {
|
|
|
528
515
|
value: "".concat(getMetaType(ref)).concat(f.allowNull ? '' : '!'),
|
|
529
516
|
comment: f.caption,
|
|
530
517
|
});
|
|
531
|
-
currentType.query.resultProcessors.push(function (r) {
|
|
532
|
-
var val = r[ri.type == 'reference' ? f.key : f.options.field]; //p1 - fix
|
|
533
|
-
if (val === null || val === undefined)
|
|
534
|
-
return null;
|
|
518
|
+
currentType.query.resultProcessors.push(function (r, orig) {
|
|
535
519
|
r[f.key] = function (args, req, gqlInfo) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
536
|
-
var
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
case
|
|
520
|
+
var remult, myRepo, item, _a, toRepo, returnNull, returnUndefined, result, resultItems;
|
|
521
|
+
var _this = this;
|
|
522
|
+
return tslib_1.__generator(this, function (_b) {
|
|
523
|
+
switch (_b.label) {
|
|
524
|
+
case 0: return [4 /*yield*/, options.getRemultFromRequest(req)];
|
|
525
|
+
case 1:
|
|
526
|
+
remult = _b.sent();
|
|
527
|
+
myRepo = remult.repo(meta.entityType);
|
|
528
|
+
item = myRepo.fromJson(orig);
|
|
529
|
+
_a = (0, repository_internals_js_1.getRepositoryInternals)(myRepo).getFocusedRelationRepo(myRepo.fields.find(f), item), toRepo = _a.toRepo, returnNull = _a.returnNull, returnUndefined = _a.returnUndefined;
|
|
530
|
+
if (returnNull || returnUndefined)
|
|
531
|
+
return [2 /*return*/, null];
|
|
532
|
+
return [4 /*yield*/, handleRequestWithDataApiContextBasedOnRepo_1(toRepo, function (dApi, response, setResult, arg1, meta) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
533
|
+
return tslib_1.__generator(this, function (_a) {
|
|
534
|
+
switch (_a.label) {
|
|
535
|
+
case 0: return [4 /*yield*/, connectionImplementation(setResult, itemsKey_1, createResultPromise_1, dApi, upsertTypes(getMetaType(ref)), arg1, meta, totalCountKey_1)];
|
|
536
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
}); })(tslib_1.__assign(tslib_1.__assign({}, args), { options: { limit: 1 } }), req)];
|
|
541
540
|
case 2:
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
541
|
+
result = _b.sent();
|
|
542
|
+
return [4 /*yield*/, result.items()];
|
|
543
|
+
case 3:
|
|
544
|
+
resultItems = _b.sent();
|
|
545
|
+
return [2 /*return*/, resultItems[0]];
|
|
546
546
|
}
|
|
547
547
|
});
|
|
548
548
|
}); };
|
|
@@ -552,22 +552,31 @@ function remultGraphql(options) {
|
|
|
552
552
|
// will do: Category.tasks (actually: Category.tasksOfcategory & tasksOfcategory2)
|
|
553
553
|
currentType.fields.push({
|
|
554
554
|
key: f.key,
|
|
555
|
-
args: getQueryArgsConnection(
|
|
555
|
+
args: getQueryArgsConnection(refKey),
|
|
556
556
|
value: "".concat(getMetaType(ref), "Connection"),
|
|
557
557
|
order: 10,
|
|
558
|
-
comment: "List all `".concat(getMetaType(meta), "` of `").concat(
|
|
558
|
+
comment: "List all `".concat(getMetaType(meta), "` of `").concat(refKey, "`"),
|
|
559
559
|
});
|
|
560
560
|
currentType.query.resultProcessors.push(function (r) {
|
|
561
|
-
var val = r.id;
|
|
562
561
|
r[f.key] = function (args, req, gqlInfo) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
563
|
-
var
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
562
|
+
var remult, myRepo, item, relRepo;
|
|
563
|
+
var _this = this;
|
|
564
|
+
return tslib_1.__generator(this, function (_a) {
|
|
565
|
+
switch (_a.label) {
|
|
566
|
+
case 0: return [4 /*yield*/, options.getRemultFromRequest(req)];
|
|
567
|
+
case 1:
|
|
568
|
+
remult = _a.sent();
|
|
569
|
+
myRepo = remult.repo(meta.entityType);
|
|
570
|
+
item = myRepo.fromJson(r);
|
|
571
|
+
relRepo = myRepo.relations(item)[f.key];
|
|
572
|
+
return [2 /*return*/, handleRequestWithDataApiContextBasedOnRepo_1(relRepo, function (dApi, response, setResult, arg1, meta) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
573
|
+
return tslib_1.__generator(this, function (_a) {
|
|
574
|
+
switch (_a.label) {
|
|
575
|
+
case 0: return [4 /*yield*/, connectionImplementation(setResult, itemsKey_1, createResultPromise_1, dApi, upsertTypes(getMetaType(ref)), arg1, meta, totalCountKey_1)];
|
|
576
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
}); })(args, req)];
|
|
571
580
|
}
|
|
572
581
|
});
|
|
573
582
|
}); };
|
|
@@ -581,7 +590,7 @@ function remultGraphql(options) {
|
|
|
581
590
|
value: "".concat(getMetaType(ref)).concat(f.allowNull ? '' : '!'),
|
|
582
591
|
comment: f.caption,
|
|
583
592
|
});
|
|
584
|
-
var
|
|
593
|
+
var refKey_1 = ref.key;
|
|
585
594
|
currentType.query.resultProcessors.push(function (r) {
|
|
586
595
|
var val = r[f.key];
|
|
587
596
|
if (val === null || val === undefined)
|
|
@@ -590,7 +599,7 @@ function remultGraphql(options) {
|
|
|
590
599
|
var queryResult;
|
|
591
600
|
return tslib_1.__generator(this, function (_a) {
|
|
592
601
|
switch (_a.label) {
|
|
593
|
-
case 0: return [4 /*yield*/, root[
|
|
602
|
+
case 0: return [4 /*yield*/, root[refKey_1](tslib_1.__assign(tslib_1.__assign({}, args.where), { where: { id: { eq: val } }, options: { limit: 1 } }), req, gqlInfo)];
|
|
594
603
|
case 1: return [4 /*yield*/, (_a.sent()).items()];
|
|
595
604
|
case 2:
|
|
596
605
|
queryResult = _a.sent();
|
|
@@ -609,7 +618,7 @@ function remultGraphql(options) {
|
|
|
609
618
|
args: queryArgsConnection,
|
|
610
619
|
value: connectionKey,
|
|
611
620
|
order: 10,
|
|
612
|
-
comment: "List all `".concat(getMetaType(meta), "` of `").concat(
|
|
621
|
+
comment: "List all `".concat(getMetaType(meta), "` of `").concat(refKey_1, "`"),
|
|
613
622
|
});
|
|
614
623
|
refT.query.resultProcessors.push(function (r) {
|
|
615
624
|
var val = r.id;
|
|
@@ -822,6 +831,42 @@ function remultGraphql(options) {
|
|
|
822
831
|
})
|
|
823
832
|
.join("\n\n"), "\n"),
|
|
824
833
|
};
|
|
834
|
+
function connectionImplementation(setResult, itemsKey, createResultPromise, dApi, currentType, arg1, meta, totalCountKey) {
|
|
835
|
+
var _a;
|
|
836
|
+
var _this = this;
|
|
837
|
+
setResult((_a = {},
|
|
838
|
+
_a[itemsKey] = createResultPromise(function (response, setResult) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
839
|
+
return tslib_1.__generator(this, function (_a) {
|
|
840
|
+
switch (_a.label) {
|
|
841
|
+
case 0: return [4 /*yield*/, dApi.getArray(tslib_1.__assign(tslib_1.__assign({}, response), { success: function (x) {
|
|
842
|
+
setResult(x.map(function (y) {
|
|
843
|
+
var orig = tslib_1.__assign({}, y);
|
|
844
|
+
currentType.query.resultProcessors.forEach(function (z) { return z(y, orig); });
|
|
845
|
+
return y;
|
|
846
|
+
}));
|
|
847
|
+
} }), {
|
|
848
|
+
get: bridgeQueryOptionsToDataApiGet(arg1),
|
|
849
|
+
}, translateWhereToRestBody(meta.fields, arg1))];
|
|
850
|
+
case 1:
|
|
851
|
+
_a.sent();
|
|
852
|
+
return [2 /*return*/];
|
|
853
|
+
}
|
|
854
|
+
});
|
|
855
|
+
}); }),
|
|
856
|
+
_a[totalCountKey] = createResultPromise(function (response, setResult) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
857
|
+
return tslib_1.__generator(this, function (_a) {
|
|
858
|
+
switch (_a.label) {
|
|
859
|
+
case 0: return [4 /*yield*/, dApi.count(tslib_1.__assign(tslib_1.__assign({}, response), { success: function (x) { return setResult(x.count); } }), {
|
|
860
|
+
get: bridgeQueryOptionsToDataApiGet(arg1),
|
|
861
|
+
}, translateWhereToRestBody(meta.fields, arg1))];
|
|
862
|
+
case 1:
|
|
863
|
+
_a.sent();
|
|
864
|
+
return [2 /*return*/];
|
|
865
|
+
}
|
|
866
|
+
});
|
|
867
|
+
}); }),
|
|
868
|
+
_a));
|
|
869
|
+
}
|
|
825
870
|
}
|
|
826
871
|
exports.remultGraphql = remultGraphql;
|
|
827
872
|
function getQueryArgsConnection(key) {
|
package/package.json
CHANGED
|
@@ -9,8 +9,8 @@ import type { entityEventListener } from '../__EntityValueProvider.js';
|
|
|
9
9
|
import type { DataProvider, EntityDataProvider, EntityDataProviderFindOptions, ErrorInfo } from '../data-interfaces.js';
|
|
10
10
|
import type { Unsubscribe } from '../live-query/SubscriptionChannel.js';
|
|
11
11
|
import { RelationLoader } from './relation-loader.js';
|
|
12
|
-
import { getInternalKey } from './repository-internals.js';
|
|
13
|
-
export declare class RepositoryImplementation<entityType> implements Repository<entityType> {
|
|
12
|
+
import { type RepositoryInternal, getInternalKey } from './repository-internals.js';
|
|
13
|
+
export declare class RepositoryImplementation<entityType> implements Repository<entityType>, RepositoryInternal<entityType> {
|
|
14
14
|
private entity;
|
|
15
15
|
remult: Remult;
|
|
16
16
|
private dataProvider;
|
|
@@ -19,6 +19,11 @@ export declare class RepositoryImplementation<entityType> implements Repository<
|
|
|
19
19
|
[getInternalKey](): this;
|
|
20
20
|
createAfterFilter(orderBy: EntityOrderBy<entityType>, lastRow: entityType): Promise<EntityFilter<entityType>>;
|
|
21
21
|
relations(item: entityType): RepositoryRelations<entityType>;
|
|
22
|
+
getFocusedRelationRepo(field: FieldMetadata, item: entityType): {
|
|
23
|
+
toRepo: RepositoryImplementation<any>;
|
|
24
|
+
returnNull: boolean;
|
|
25
|
+
returnUndefined: boolean;
|
|
26
|
+
};
|
|
22
27
|
private __edp;
|
|
23
28
|
private get edp();
|
|
24
29
|
constructor(entity: ClassType<entityType>, remult: Remult, dataProvider: DataProvider, _info: EntityFullInfo<entityType>, defaultFindOptions?: FindOptions<entityType>);
|
|
@@ -127,9 +127,7 @@ var RepositoryImplementation = /** @class */ (function () {
|
|
|
127
127
|
var rel = (0, relationInfoMember_js_1.getRelationFieldInfo)(field);
|
|
128
128
|
if (!rel)
|
|
129
129
|
throw Error(key + ' is not a relation');
|
|
130
|
-
var
|
|
131
|
-
var _a = _this.findOptionsBasedOnRelation(rel, field, undefined, item, repo), findOptions = _a.findOptions, returnNull = _a.returnNull, returnUndefined = _a.returnUndefined;
|
|
132
|
-
var toRepo = new RepositoryImplementation(repo.entity, repo.remult, repo.dataProvider, repo._info, findOptions);
|
|
130
|
+
var _a = _this.getFocusedRelationRepo(field, item), toRepo = _a.toRepo, returnNull = _a.returnNull, returnUndefined = _a.returnUndefined;
|
|
133
131
|
if (rel.type === 'toMany')
|
|
134
132
|
return toRepo;
|
|
135
133
|
else
|
|
@@ -145,6 +143,13 @@ var RepositoryImplementation = /** @class */ (function () {
|
|
|
145
143
|
},
|
|
146
144
|
});
|
|
147
145
|
};
|
|
146
|
+
RepositoryImplementation.prototype.getFocusedRelationRepo = function (field, item) {
|
|
147
|
+
var rel = (0, relationInfoMember_js_1.getRelationFieldInfo)(field);
|
|
148
|
+
var repo = rel.toRepo;
|
|
149
|
+
var _a = this.findOptionsBasedOnRelation(rel, field, undefined, item, repo), findOptions = _a.findOptions, returnNull = _a.returnNull, returnUndefined = _a.returnUndefined;
|
|
150
|
+
var toRepo = new RepositoryImplementation(repo.entity, repo.remult, repo.dataProvider, repo._info, findOptions);
|
|
151
|
+
return { toRepo: toRepo, returnNull: returnNull, returnUndefined: returnUndefined };
|
|
152
|
+
};
|
|
148
153
|
Object.defineProperty(RepositoryImplementation.prototype, "edp", {
|
|
149
154
|
get: function () {
|
|
150
155
|
return this.__edp
|
package/src/remult3/remult3.js
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
//y1 - another toOne scenario - for a one to one relation, where the other table has my id in one of its fields.
|
|
3
4
|
//y1 - number default storage in knex is decimal and it by default has 8,2 - meaning only 999,999 - I think it should be way bigger than that. in firefly we do at least 18 - https://discord.com/channels/975754286384418847/1195162533447876658
|
|
5
|
+
//y1 - talk about the parameter issue with backend methods
|
|
4
6
|
//y1 - tried to upgrade vitest, nuxt tests are failing with loading uuid - sounds familiar?
|
|
5
7
|
//y2 - from the crm-demo(https://crm-demo.up.railway.app/deals), after editing a deal: - _updateEntityBasedOnApi
|
|
6
8
|
//y2 - Backend methods are transactions, it's not intuitive and maybe should be optional / opt in
|
|
7
9
|
//y2 - how to run a transaction as a user
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//p1 - Write some ctrl g
|
|
10
|
+
//p2 - enum column
|
|
11
|
+
//p2 - I think there should be a way to throw a forbidden exception
|
|
11
12
|
//y2 - get backend methods to work when specifying types for date, and entities as poco's
|
|
12
13
|
//y2 - required
|
|
13
14
|
//y2 - reconsider validators
|
|
14
15
|
//y2 - message for invalid value
|
|
15
16
|
//y2 - message for relation that is missing
|
|
16
|
-
//
|
|
17
|
+
//p2 - more column types
|
|
17
18
|
//p2 - processError in remult express
|
|
18
19
|
//p2 - allow find options preprocessor for api calls, to use for authorization
|
|
19
|
-
//
|
|
20
|
+
//p2 - write doc about controlling updates of rows...
|
|
20
21
|
//p1 - need a way to extract the fields from the relation - for generating relation based sql
|
|
21
22
|
//p1 - when doing this, work on graphql relation with fields not just field
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
23
|
+
//p2 - add docs for apply changes
|
|
24
|
+
//p2 - when subscribe is forbidden - the query still runs after the renew process
|
|
25
|
+
//p2 - 'update tasks set where id = $1
|
|
25
26
|
//y2 - consider multi tenancies
|
|
26
27
|
//y2 - allow api read to also support instance and filter. - problem with promise
|
|
27
|
-
//
|
|
28
|
+
//p2 - doc this:
|
|
28
29
|
/**
|
|
29
30
|
* //p2 - doc this
|
|
30
31
|
remult.apiClient.httpClient = (
|
|
@@ -47,12 +48,10 @@ remult.apiClient.url='localhost:3007/api
|
|
|
47
48
|
*/
|
|
48
49
|
//p1 - remult-admin doesn't handle primary key that has compound column
|
|
49
50
|
//p1 - remult-admin didn't show a update for a table with a uniqua that is numeric
|
|
50
|
-
//p1 - crm demo graphql error
|
|
51
|
-
//p1 - fix multiple instances of remult: the defaultRemult and async local hook - and columnsOfType - all can be tests with a vite project loading `remult-admin`
|
|
52
51
|
//p1 -check if checouknt doesn't respect allow read (I think)
|
|
53
52
|
//p1 - allow api update only for new rows
|
|
54
53
|
//p1 - getFields didn't work for kobi in the home component
|
|
55
|
-
//p1 - https://codesandbox.io/p/devbox/demo-sql-expression-wqvj4g
|
|
54
|
+
//p1 - add to docs https://codesandbox.io/p/devbox/demo-sql-expression-wqvj4g
|
|
56
55
|
//p2 - document validators
|
|
57
56
|
//p2 - and validators to reference
|
|
58
57
|
//y2 - discuss a default date formatter
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FieldMetadata } from '../column-interfaces.js';
|
|
1
2
|
import type { EntityDataProviderFindOptions } from '../data-interfaces.js';
|
|
2
3
|
import type { Filter } from '../filter/filter-interfaces.js';
|
|
3
4
|
import type { EntityFilter, EntityOrderBy, FindOptions, LoadOptions, Repository } from './remult3.js';
|
|
@@ -9,6 +10,11 @@ export interface RepositoryInternal<entityType> {
|
|
|
9
10
|
getCachedById(id: any, doNotLoadIfNotFound: boolean): entityType;
|
|
10
11
|
getCachedByIdAsync(id: any, doNotLoadIfNotFound: boolean): Promise<entityType>;
|
|
11
12
|
addToCache(item: entityType): any;
|
|
13
|
+
getFocusedRelationRepo(field: FieldMetadata, item: any): {
|
|
14
|
+
toRepo: Repository<any>;
|
|
15
|
+
returnNull: boolean;
|
|
16
|
+
returnUndefined: boolean;
|
|
17
|
+
};
|
|
12
18
|
}
|
|
13
19
|
export declare function getRepositoryInternals<entityType>(repo: Repository<entityType>): RepositoryInternal<entityType>;
|
|
14
20
|
export declare const getInternalKey: unique symbol;
|
package/src/sort.js
CHANGED
|
@@ -92,8 +92,8 @@ var Sort = /** @class */ (function () {
|
|
|
92
92
|
};
|
|
93
93
|
if (field) {
|
|
94
94
|
var rel = (0, relationInfoMember_js_1.getRelationFieldInfo)(field);
|
|
95
|
-
var op = field.options; //p1 - fix
|
|
96
95
|
if ((rel === null || rel === void 0 ? void 0 : rel.type) === 'toOne') {
|
|
96
|
+
var op = rel.options;
|
|
97
97
|
if (typeof op.field === 'string') {
|
|
98
98
|
addSegment(entityDefs.fields.find(op.field));
|
|
99
99
|
}
|