remult 0.25.5-exp.0 → 0.25.5-exp.10
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 +69 -52
- package/esm/internals.js +3 -2
- package/esm/live-query/data-provider-live-query-storage.js +3 -2
- package/esm/postgres/schema-builder.js +2 -2
- package/esm/remult-knex/index.js +24 -7
- package/esm/server/expressBridge.js +7 -6
- package/esm/server/initAsyncHooks.js +2 -1
- package/esm/src/context.js +13 -11
- package/esm/src/data-api.js +2 -2
- package/esm/src/data-providers/rest-data-provider.js +7 -8
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +2 -2
- package/esm/src/filter/filter-interfaces.js +4 -6
- package/esm/src/live-query/LiveQueryClient.js +2 -2
- package/esm/src/live-query/SseSubscriptionClient.js +3 -3
- package/esm/src/remult-proxy.js +2 -8
- package/esm/src/remult-static.js +36 -0
- package/esm/src/remult3/Fields.js +8 -22
- package/esm/src/remult3/RepositoryImplementation.js +62 -145
- package/esm/src/remult3/entity.js +3 -2
- package/esm/src/remult3/relation-loader.js +2 -2
- package/esm/src/remult3/relationInfoMember.js +113 -1
- package/esm/src/remult3/remult3.js +30 -15
- package/esm/src/remult3/repository-internals.js +1 -1
- package/esm/src/server-action-info.js +0 -11
- package/esm/src/server-action.js +24 -20
- package/esm/src/sort.js +3 -3
- package/graphql.js +118 -69
- package/internals.d.ts +10 -3
- package/internals.js +4 -3
- package/live-query/data-provider-live-query-storage.js +2 -1
- package/package.json +1 -1
- package/postgres/schema-builder.js +2 -2
- package/remult-knex/index.js +75 -51
- package/server/expressBridge.js +5 -4
- package/server/initAsyncHooks.js +2 -1
- package/src/context.d.ts +0 -3
- package/src/context.js +12 -10
- package/src/data-api.js +2 -2
- package/src/data-providers/rest-data-provider.d.ts +1 -1
- package/src/data-providers/rest-data-provider.js +6 -7
- package/src/filter/filter-consumer-bridge-to-sql-request.js +1 -1
- package/src/filter/filter-interfaces.d.ts +1 -1
- package/src/filter/filter-interfaces.js +3 -5
- package/src/live-query/LiveQueryClient.js +8 -10
- package/src/live-query/SseSubscriptionClient.js +3 -3
- package/src/remult-proxy.js +4 -9
- package/src/remult-static.d.ts +22 -0
- package/src/remult-static.js +40 -0
- package/src/remult3/Fields.js +7 -20
- package/src/remult3/RepositoryImplementation.d.ts +7 -4
- package/src/remult3/RepositoryImplementation.js +210 -306
- package/src/remult3/entity.js +2 -1
- package/src/remult3/relation-loader.js +1 -1
- package/src/remult3/relationInfoMember.d.ts +29 -3
- package/src/remult3/relationInfoMember.js +145 -3
- package/src/remult3/remult3.d.ts +2 -6
- package/src/remult3/remult3.js +30 -15
- package/src/remult3/repository-internals.d.ts +7 -1
- package/src/remult3/repository-internals.js +1 -1
- package/src/server-action-info.d.ts +0 -9
- package/src/server-action-info.js +1 -12
- package/src/server-action.d.ts +2 -2
- package/src/server-action.js +22 -18
- package/src/sort.js +3 -3
package/esm/graphql.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
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);
|
|
@@ -206,7 +213,9 @@ export function remultGraphql(options) {
|
|
|
206
213
|
});
|
|
207
214
|
};
|
|
208
215
|
const queryArgsConnection = getQueryArgsConnection(key);
|
|
209
|
-
|
|
216
|
+
let getSingleEntityKey = toCamelCase(getMetaType(meta));
|
|
217
|
+
if (getSingleEntityKey === toCamelCase(key))
|
|
218
|
+
getSingleEntityKey = 'single' + key;
|
|
210
219
|
root_query.fields.push({
|
|
211
220
|
key: getSingleEntityKey,
|
|
212
221
|
args: [argId],
|
|
@@ -217,7 +226,8 @@ export function remultGraphql(options) {
|
|
|
217
226
|
await dApi.get({
|
|
218
227
|
...response,
|
|
219
228
|
success: (y) => {
|
|
220
|
-
|
|
229
|
+
const orig = { ...y };
|
|
230
|
+
currentType.query.resultProcessors.forEach((z) => z(y, orig));
|
|
221
231
|
setResult(y);
|
|
222
232
|
},
|
|
223
233
|
}, arg1.id);
|
|
@@ -267,29 +277,7 @@ export function remultGraphql(options) {
|
|
|
267
277
|
});
|
|
268
278
|
}
|
|
269
279
|
root[key] = handleRequestWithDataApiContext(async (dApi, response, setResult, arg1, meta) => {
|
|
270
|
-
setResult
|
|
271
|
-
[itemsKey]: createResultPromise(async (response, setResult) => {
|
|
272
|
-
await dApi.getArray({
|
|
273
|
-
...response,
|
|
274
|
-
success: (x) => {
|
|
275
|
-
setResult(x.map((y) => {
|
|
276
|
-
currentType.query.resultProcessors.forEach((z) => z(y));
|
|
277
|
-
return y;
|
|
278
|
-
}));
|
|
279
|
-
},
|
|
280
|
-
}, {
|
|
281
|
-
get: bridgeQueryOptionsToDataApiGet(arg1),
|
|
282
|
-
}, translateWhereToRestBody(meta.fields, arg1));
|
|
283
|
-
}),
|
|
284
|
-
[totalCountKey]: createResultPromise(async (response, setResult) => {
|
|
285
|
-
await dApi.count({
|
|
286
|
-
...response,
|
|
287
|
-
success: (x) => setResult(x.count),
|
|
288
|
-
}, {
|
|
289
|
-
get: bridgeQueryOptionsToDataApiGet(arg1),
|
|
290
|
-
}, translateWhereToRestBody(meta.fields, arg1));
|
|
291
|
-
}),
|
|
292
|
-
});
|
|
280
|
+
connectionImplementation(setResult, itemsKey, createResultPromise, dApi, currentType, arg1, meta, totalCountKey);
|
|
293
281
|
});
|
|
294
282
|
resolversQuery[key] = (origItem, args, req, gqlInfo) => {
|
|
295
283
|
return root[key](args, req, gqlInfo);
|
|
@@ -324,7 +312,8 @@ export function remultGraphql(options) {
|
|
|
324
312
|
await dApi.post({
|
|
325
313
|
...response,
|
|
326
314
|
created: (y) => {
|
|
327
|
-
|
|
315
|
+
const orig = { ...y };
|
|
316
|
+
currentType.query.resultProcessors.forEach((z) => z(y, orig));
|
|
328
317
|
setResult({
|
|
329
318
|
[toCamelCase(getMetaType(meta))]: y,
|
|
330
319
|
});
|
|
@@ -358,7 +347,8 @@ export function remultGraphql(options) {
|
|
|
358
347
|
await dApi.put({
|
|
359
348
|
...response,
|
|
360
349
|
success: (y) => {
|
|
361
|
-
|
|
350
|
+
const orig = { ...y };
|
|
351
|
+
currentType.query.resultProcessors.forEach((z) => z(y, orig));
|
|
362
352
|
setResult({
|
|
363
353
|
[toCamelCase(getMetaType(meta))]: y,
|
|
364
354
|
});
|
|
@@ -395,8 +385,7 @@ export function remultGraphql(options) {
|
|
|
395
385
|
}
|
|
396
386
|
const whereTypeFields = [];
|
|
397
387
|
for (const f of meta.fields) {
|
|
398
|
-
const ri =
|
|
399
|
-
// let's not consider toMany relations for now
|
|
388
|
+
const ri = getRelationFieldInfo(f);
|
|
400
389
|
if (f.options.includeInApi === false)
|
|
401
390
|
continue;
|
|
402
391
|
let type = 'String';
|
|
@@ -421,9 +410,12 @@ export function remultGraphql(options) {
|
|
|
421
410
|
let notARealField = false;
|
|
422
411
|
if (ri) {
|
|
423
412
|
{
|
|
424
|
-
const refType = ri.
|
|
413
|
+
const refType = ri.toEntity;
|
|
425
414
|
ref = entities.find((i) => i.entityType === refType);
|
|
426
415
|
}
|
|
416
|
+
if (!ref) {
|
|
417
|
+
throw new Error(`Entity "${ri.toEntity.name}" that is used by the relation "${f.key}" in "${meta.entityType.name}" was not found in the 'entities' array.`);
|
|
418
|
+
}
|
|
427
419
|
notARealField = ri.type === 'toOne' || ri.type === 'toMany';
|
|
428
420
|
const refKey = ref.key;
|
|
429
421
|
switch (ri.type) {
|
|
@@ -434,19 +426,19 @@ export function remultGraphql(options) {
|
|
|
434
426
|
value: `${getMetaType(ref)}${f.allowNull ? '' : '!'}`,
|
|
435
427
|
comment: f.caption,
|
|
436
428
|
});
|
|
437
|
-
currentType.query.resultProcessors.push((r) => {
|
|
438
|
-
const val = r[ri.type == 'reference' ? f.key : f.options.field]; //p1 - fix
|
|
439
|
-
if (val === null || val === undefined)
|
|
440
|
-
return null;
|
|
429
|
+
currentType.query.resultProcessors.push((r, orig) => {
|
|
441
430
|
r[f.key] = async (args, req, gqlInfo) => {
|
|
442
|
-
const
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
431
|
+
const remult = await options.getRemultFromRequest(req);
|
|
432
|
+
const myRepo = remult.repo(meta.entityType);
|
|
433
|
+
const item = myRepo.fromJson(orig);
|
|
434
|
+
let { toRepo, returnNull, returnUndefined } = getRepositoryInternals(myRepo).getFocusedRelationRepo(myRepo.fields.find(f), item);
|
|
435
|
+
if (returnNull || returnUndefined)
|
|
436
|
+
return null;
|
|
437
|
+
const result = await handleRequestWithDataApiContextBasedOnRepo(toRepo, async (dApi, response, setResult, arg1, meta) => {
|
|
438
|
+
return await connectionImplementation(setResult, itemsKey, createResultPromise, dApi, upsertTypes(getMetaType(ref)), arg1, meta, totalCountKey);
|
|
439
|
+
})({ ...args, options: { limit: 1 } }, req);
|
|
440
|
+
const resultItems = await result.items();
|
|
441
|
+
return resultItems[0];
|
|
450
442
|
};
|
|
451
443
|
});
|
|
452
444
|
break;
|
|
@@ -459,16 +451,15 @@ export function remultGraphql(options) {
|
|
|
459
451
|
order: 10,
|
|
460
452
|
comment: `List all \`${getMetaType(meta)}\` of \`${refKey}\``,
|
|
461
453
|
});
|
|
462
|
-
currentType.query.resultProcessors.push((r) => {
|
|
463
|
-
const val = r.id;
|
|
454
|
+
currentType.query.resultProcessors.push((r, y) => {
|
|
464
455
|
r[f.key] = async (args, req, gqlInfo) => {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
}, req
|
|
456
|
+
const remult = await options.getRemultFromRequest(req);
|
|
457
|
+
const myRepo = remult.repo(meta.entityType);
|
|
458
|
+
const item = myRepo.fromJson(y);
|
|
459
|
+
let relRepo = myRepo.relations(item)[f.key];
|
|
460
|
+
return handleRequestWithDataApiContextBasedOnRepo(relRepo, async (dApi, response, setResult, arg1, meta) => {
|
|
461
|
+
return await connectionImplementation(setResult, itemsKey, createResultPromise, dApi, upsertTypes(getMetaType(ref)), arg1, meta, totalCountKey);
|
|
462
|
+
})(args, req);
|
|
472
463
|
};
|
|
473
464
|
});
|
|
474
465
|
}
|
|
@@ -677,6 +668,32 @@ export function remultGraphql(options) {
|
|
|
677
668
|
.join(`\n\n`)}
|
|
678
669
|
`,
|
|
679
670
|
};
|
|
671
|
+
function connectionImplementation(setResult, itemsKey, createResultPromise, dApi, currentType, arg1, meta, totalCountKey) {
|
|
672
|
+
setResult({
|
|
673
|
+
[itemsKey]: createResultPromise(async (response, setResult) => {
|
|
674
|
+
await dApi.getArray({
|
|
675
|
+
...response,
|
|
676
|
+
success: (x) => {
|
|
677
|
+
setResult(x.map((y) => {
|
|
678
|
+
const orig = { ...y };
|
|
679
|
+
currentType.query.resultProcessors.forEach((z) => z(y, orig));
|
|
680
|
+
return y;
|
|
681
|
+
}));
|
|
682
|
+
},
|
|
683
|
+
}, {
|
|
684
|
+
get: bridgeQueryOptionsToDataApiGet(arg1),
|
|
685
|
+
}, translateWhereToRestBody(meta.fields, arg1));
|
|
686
|
+
}),
|
|
687
|
+
[totalCountKey]: createResultPromise(async (response, setResult) => {
|
|
688
|
+
await dApi.count({
|
|
689
|
+
...response,
|
|
690
|
+
success: (x) => setResult(x.count),
|
|
691
|
+
}, {
|
|
692
|
+
get: bridgeQueryOptionsToDataApiGet(arg1),
|
|
693
|
+
}, translateWhereToRestBody(meta.fields, arg1));
|
|
694
|
+
}),
|
|
695
|
+
});
|
|
696
|
+
}
|
|
680
697
|
}
|
|
681
698
|
function getQueryArgsConnection(key) {
|
|
682
699
|
const queryArgsConnection = [
|
package/esm/internals.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { remultStatic } from './src/remult-static.js';
|
|
2
|
+
export { getRelationInfo, getRelationFieldInfo, } from './src/remult3/relationInfoMember.js';
|
|
2
3
|
export { decorateColumnSettings, controllerRefImpl, getControllerRef, } from './src/remult3/RepositoryImplementation.js';
|
|
3
4
|
export { getEntitySettings } from './src/remult3/getEntityRef.js';
|
|
4
5
|
export { __updateEntityBasedOnWhere } from './src/filter/filter-interfaces.js';
|
|
5
|
-
export
|
|
6
|
+
export const actionInfo = remultStatic.actionInfo;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { initDataProvider } from '../server/initDataProvider.js';
|
|
3
|
-
import {
|
|
3
|
+
import { Remult } from '../src/context.js';
|
|
4
4
|
import { EntityBase } from '../src/remult3/RepositoryImplementation.js';
|
|
5
5
|
import { Fields } from '../src/remult3/Fields.js';
|
|
6
6
|
import { Entity } from '../src/remult3/entity.js';
|
|
7
|
+
import { remultStatic } from '../src/remult-static.js';
|
|
7
8
|
export class DataProviderLiveQueryStorage {
|
|
8
9
|
repo;
|
|
9
10
|
dataProvider;
|
|
@@ -89,4 +90,4 @@ LiveQueryStorageEntity = __decorate([
|
|
|
89
90
|
/*@internal */
|
|
90
91
|
], LiveQueryStorageEntity);
|
|
91
92
|
export { LiveQueryStorageEntity };
|
|
92
|
-
allEntities.splice(allEntities.indexOf(LiveQueryStorageEntity), 1);
|
|
93
|
+
remultStatic.allEntities.splice(remultStatic.allEntities.indexOf(LiveQueryStorageEntity), 1);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { allEntities } from '../src/context.js';
|
|
2
1
|
import { dbNamesOf, shouldNotCreateField, } from '../src/filter/filter-consumer-bridge-to-sql-request.js';
|
|
3
2
|
import { remult as defaultRemult } from '../src/remult-proxy.js';
|
|
3
|
+
import { remultStatic } from '../src/remult-static.js';
|
|
4
4
|
import { isAutoIncrement } from '../src/remult3/RepositoryImplementation.js';
|
|
5
5
|
import { ValueConverters } from '../src/valueConverters.js';
|
|
6
6
|
export function postgresColumnSyntax(x, dbName) {
|
|
@@ -95,7 +95,7 @@ export class PostgresSchemaBuilder {
|
|
|
95
95
|
}
|
|
96
96
|
const completed = new Set();
|
|
97
97
|
const entities = [];
|
|
98
|
-
for (const entityClass of [...allEntities].reverse()) {
|
|
98
|
+
for (const entityClass of [...remultStatic.allEntities].reverse()) {
|
|
99
99
|
let entity = remult.repo(entityClass).metadata;
|
|
100
100
|
let e = await dbNamesOf(entity, this.pool.wrapIdentifier);
|
|
101
101
|
if (completed.has(e.$entityName))
|
package/esm/remult-knex/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { allEntities } from '../src/context.js';
|
|
2
1
|
import { dbNamesOf, isDbReadonly, shouldNotCreateField, } from '../src/filter/filter-consumer-bridge-to-sql-request.js';
|
|
3
2
|
import { customDatabaseFilterToken, Filter, } from '../src/filter/filter-interfaces.js';
|
|
4
3
|
import { CompoundIdField } from '../src/CompoundIdField.js';
|
|
@@ -8,6 +7,7 @@ import { Sort } from '../src/sort.js';
|
|
|
8
7
|
import { ValueConverters } from '../src/valueConverters.js';
|
|
9
8
|
import { resultCompoundIdFilter as resultCompoundIdFilter } from '../src/resultCompoundIdFilter.js';
|
|
10
9
|
import { getRepositoryInternals } from '../src/remult3/repository-internals.js';
|
|
10
|
+
import { remultStatic } from '../src/remult-static.js';
|
|
11
11
|
export class KnexDataProvider {
|
|
12
12
|
knex;
|
|
13
13
|
constructor(knex) {
|
|
@@ -20,7 +20,7 @@ export class KnexDataProvider {
|
|
|
20
20
|
return r.knex;
|
|
21
21
|
}
|
|
22
22
|
getEntityDataProvider(entity) {
|
|
23
|
-
if (!
|
|
23
|
+
if (!supportsJsonLoadingAndSaving(this.knex))
|
|
24
24
|
for (const f of entity.fields.toArray()) {
|
|
25
25
|
if (f.valueConverter.fieldTypeInDb === 'json') {
|
|
26
26
|
//@ts-ignore
|
|
@@ -31,6 +31,17 @@ export class KnexDataProvider {
|
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
+
else if (this.knex.client.config.client === 'mysql2') {
|
|
35
|
+
for (const f of entity.fields.toArray()) {
|
|
36
|
+
if (f.valueConverter.fieldTypeInDb === 'json') {
|
|
37
|
+
//@ts-ignore
|
|
38
|
+
f.valueConverter = {
|
|
39
|
+
...f.valueConverter,
|
|
40
|
+
toDb: ValueConverters.JsonString.toDb,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
34
45
|
return new KnexEntityDataProvider(entity, this.knex);
|
|
35
46
|
}
|
|
36
47
|
async transaction(action) {
|
|
@@ -331,7 +342,7 @@ export class KnexSchemaBuilder {
|
|
|
331
342
|
async verifyStructureOfAllEntities(remult) {
|
|
332
343
|
if (!remult)
|
|
333
344
|
remult = remultContext;
|
|
334
|
-
const entities = allEntities.map((x) => remult.repo(x).metadata);
|
|
345
|
+
const entities = remultStatic.allEntities.map((x) => remult.repo(x).metadata);
|
|
335
346
|
await this.ensureSchema(entities);
|
|
336
347
|
}
|
|
337
348
|
async ensureSchema(entities) {
|
|
@@ -367,7 +378,7 @@ export class KnexSchemaBuilder {
|
|
|
367
378
|
if (isAutoIncrement(x))
|
|
368
379
|
b.increments(cols.get(x).name);
|
|
369
380
|
else {
|
|
370
|
-
buildColumn(x, cols.get(x).name, b,
|
|
381
|
+
buildColumn(x, cols.get(x).name, b, supportsJsonDataStorage(this.knex));
|
|
371
382
|
if (x == entity.idMetadata.field)
|
|
372
383
|
b.primary([cols.get(x).name]);
|
|
373
384
|
}
|
|
@@ -384,7 +395,7 @@ export class KnexSchemaBuilder {
|
|
|
384
395
|
let colName = e.$dbNameOf(col);
|
|
385
396
|
if (!(await this.knex.schema.hasColumn(e.$entityName, colName))) {
|
|
386
397
|
await logSql(this.knex.schema.alterTable(e.$entityName, (b) => {
|
|
387
|
-
buildColumn(col, colName, b,
|
|
398
|
+
buildColumn(col, colName, b, supportsJsonDataStorage(this.knex));
|
|
388
399
|
}));
|
|
389
400
|
}
|
|
390
401
|
}
|
|
@@ -406,11 +417,17 @@ export class KnexSchemaBuilder {
|
|
|
406
417
|
this.knex = knex;
|
|
407
418
|
}
|
|
408
419
|
}
|
|
409
|
-
function
|
|
420
|
+
function supportsJsonDataStorage(knex) {
|
|
421
|
+
const client = knex.client.config.client;
|
|
422
|
+
if (client?.includes('sqlite3') || client?.includes('mssql'))
|
|
423
|
+
return false;
|
|
424
|
+
return true;
|
|
425
|
+
}
|
|
426
|
+
function supportsJsonLoadingAndSaving(knex) {
|
|
410
427
|
const client = knex.client.config.client;
|
|
411
428
|
if (client?.includes('sqlite3') ||
|
|
412
429
|
client?.includes('mssql') ||
|
|
413
|
-
client
|
|
430
|
+
client == 'mysql')
|
|
414
431
|
return false;
|
|
415
432
|
return true;
|
|
416
433
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { SseSubscriptionServer } from '../SseSubscriptionServer.js';
|
|
3
|
-
import { Remult, RemultAsyncLocalStorage,
|
|
3
|
+
import { Remult, RemultAsyncLocalStorage, withRemult } from '../src/context.js';
|
|
4
4
|
import { DataApi, serializeError } from '../src/data-api.js';
|
|
5
5
|
import { liveQueryKeepAliveRoute, streamUrl, } from '../src/live-query/SubscriptionChannel.js';
|
|
6
6
|
import { InMemoryLiveQueryStorage, LiveQueryPublisher, } from '../src/live-query/SubscriptionServer.js';
|
|
@@ -9,8 +9,9 @@ import { Fields } from '../src/remult3/Fields.js';
|
|
|
9
9
|
import { Entity } from '../src/remult3/entity.js';
|
|
10
10
|
import { getEntityKey } from '../src/remult3/getEntityRef.js';
|
|
11
11
|
import { Action, classBackendMethodsArray } from '../src/server-action.js';
|
|
12
|
-
import {
|
|
12
|
+
import { serverActionField } from '../src/server-action-info.js';
|
|
13
13
|
import { initDataProvider } from './initDataProvider.js';
|
|
14
|
+
import { remultStatic } from '../src/remult-static.js';
|
|
14
15
|
export function createRemultServerCore(options, serverCoreOptions) {
|
|
15
16
|
if (!options) {
|
|
16
17
|
options = {};
|
|
@@ -20,7 +21,7 @@ export function createRemultServerCore(options, serverCoreOptions) {
|
|
|
20
21
|
}
|
|
21
22
|
if (options.logApiEndPoints === undefined)
|
|
22
23
|
options.logApiEndPoints = true;
|
|
23
|
-
actionInfo.runningOnServer = true;
|
|
24
|
+
remultStatic.actionInfo.runningOnServer = true;
|
|
24
25
|
if (options.defaultGetLimit) {
|
|
25
26
|
DataApi.defaultGetLimit = options.defaultGetLimit;
|
|
26
27
|
}
|
|
@@ -34,7 +35,7 @@ export function createRemultServerCore(options, serverCoreOptions) {
|
|
|
34
35
|
{
|
|
35
36
|
let allControllers = [];
|
|
36
37
|
if (!options.entities)
|
|
37
|
-
options.entities = [...allEntities];
|
|
38
|
+
options.entities = [...remultStatic.allEntities];
|
|
38
39
|
if (options.entities)
|
|
39
40
|
allControllers.push(...options.entities);
|
|
40
41
|
if (options.controllers)
|
|
@@ -43,7 +44,7 @@ export function createRemultServerCore(options, serverCoreOptions) {
|
|
|
43
44
|
}
|
|
44
45
|
if (options.rootPath === undefined)
|
|
45
46
|
options.rootPath = '/api';
|
|
46
|
-
actionInfo.runningOnServer = true;
|
|
47
|
+
remultStatic.actionInfo.runningOnServer = true;
|
|
47
48
|
let bridge = new RemultServerImplementation(new inProcessQueueHandler(options.queueStorage), options, dataProvider, serverCoreOptions);
|
|
48
49
|
return bridge;
|
|
49
50
|
}
|
|
@@ -987,4 +988,4 @@ JobsInQueueEntity = __decorate([
|
|
|
987
988
|
})
|
|
988
989
|
], JobsInQueueEntity);
|
|
989
990
|
export { JobsInQueueEntity };
|
|
990
|
-
allEntities.splice(allEntities.indexOf(JobsInQueueEntity), 1);
|
|
991
|
+
remultStatic.allEntities.splice(remultStatic.allEntities.indexOf(JobsInQueueEntity), 1);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
2
|
import { RemultAsyncLocalStorage } from '../src/context.js';
|
|
3
|
+
import { remultStatic } from '../src/remult-static.js';
|
|
3
4
|
let init = false;
|
|
4
5
|
export function initAsyncHooks() {
|
|
5
6
|
if (init)
|
|
6
7
|
return;
|
|
7
8
|
init = true;
|
|
8
|
-
|
|
9
|
+
remultStatic.asyncContext = new RemultAsyncLocalStorage(new AsyncLocalStorage());
|
|
9
10
|
}
|
package/esm/src/context.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { RestDataProvider } from './data-providers/rest-data-provider.js';
|
|
2
2
|
import { LiveQueryClient } from './live-query/LiveQueryClient.js';
|
|
3
3
|
import { SseSubscriptionClient } from './live-query/SseSubscriptionClient.js';
|
|
4
|
-
import {
|
|
4
|
+
import { remult } from './remult-proxy.js';
|
|
5
5
|
import { RepositoryImplementation, createOldEntity, } from './remult3/RepositoryImplementation.js';
|
|
6
|
-
import {
|
|
6
|
+
import { serverActionField } from './server-action-info.js';
|
|
7
7
|
import { buildRestDataProvider, isExternalHttpProvider, } from './buildRestDataProvider.js';
|
|
8
|
+
import { verifyFieldRelationInfo } from './remult3/relationInfoMember.js';
|
|
9
|
+
import { remultStatic } from './remult-static.js';
|
|
8
10
|
export class RemultAsyncLocalStorage {
|
|
9
11
|
remultObjectStorage;
|
|
10
12
|
static enable() {
|
|
11
13
|
;
|
|
12
14
|
remult.remultFactory = () => {
|
|
13
|
-
const r =
|
|
15
|
+
const r = remultStatic.asyncContext.getRemult();
|
|
14
16
|
if (r)
|
|
15
17
|
return r;
|
|
16
18
|
else
|
|
@@ -36,10 +38,11 @@ export class RemultAsyncLocalStorage {
|
|
|
36
38
|
}
|
|
37
39
|
return this.remultObjectStorage.getStore();
|
|
38
40
|
}
|
|
39
|
-
static instance = new RemultAsyncLocalStorage(undefined);
|
|
40
41
|
}
|
|
42
|
+
if (!remultStatic.asyncContext)
|
|
43
|
+
remultStatic.asyncContext = new RemultAsyncLocalStorage(undefined);
|
|
41
44
|
export function isBackend() {
|
|
42
|
-
return actionInfo.runningOnServer || !remult.dataProvider.isProxy;
|
|
45
|
+
return remultStatic.actionInfo.runningOnServer || !remult.dataProvider.isProxy;
|
|
43
46
|
}
|
|
44
47
|
export class Remult {
|
|
45
48
|
/**Return's a `Repository` of the specific entity type
|
|
@@ -58,6 +61,7 @@ export class Remult {
|
|
|
58
61
|
let r = dpCache.get(entity);
|
|
59
62
|
if (!r) {
|
|
60
63
|
dpCache.set(entity, (r = new RepositoryImplementation(entity, this, dataProvider, createOldEntity(entity, this))));
|
|
64
|
+
verifyFieldRelationInfo(r, this, dataProvider);
|
|
61
65
|
}
|
|
62
66
|
return r;
|
|
63
67
|
}
|
|
@@ -178,18 +182,16 @@ export class Remult {
|
|
|
178
182
|
subscriptionClient: new SseSubscriptionClient(),
|
|
179
183
|
};
|
|
180
184
|
}
|
|
181
|
-
|
|
182
|
-
export const allEntities = [];
|
|
183
|
-
export const classHelpers = new Map();
|
|
185
|
+
remultStatic.defaultRemultFactory = () => new Remult();
|
|
184
186
|
export class ClassHelper {
|
|
185
187
|
classes = new Map();
|
|
186
188
|
}
|
|
187
189
|
export function setControllerSettings(target, options) {
|
|
188
190
|
let r = target;
|
|
189
191
|
while (true) {
|
|
190
|
-
let helper = classHelpers.get(r);
|
|
192
|
+
let helper = remultStatic.classHelpers.get(r);
|
|
191
193
|
if (!helper)
|
|
192
|
-
classHelpers.set(r, (helper = new ClassHelper()));
|
|
194
|
+
remultStatic.classHelpers.set(r, (helper = new ClassHelper()));
|
|
193
195
|
helper.classes.set(target, options);
|
|
194
196
|
let p = Object.getPrototypeOf(r.prototype);
|
|
195
197
|
if (p == null)
|
|
@@ -280,7 +282,7 @@ export function withRemult(callback, options) {
|
|
|
280
282
|
if (options?.dataProvider)
|
|
281
283
|
remult.dataProvider = options.dataProvider;
|
|
282
284
|
let r;
|
|
283
|
-
|
|
285
|
+
remultStatic.asyncContext.run(remult, () => {
|
|
284
286
|
r = new Promise(async (res, rej) => {
|
|
285
287
|
try {
|
|
286
288
|
res(await callback(remult));
|
package/esm/src/data-api.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { getRelationInfo } from '../internals.js';
|
|
2
1
|
import { doTransaction } from './context.js';
|
|
3
2
|
import { findOptionsToJson, liveQueryAction, } from './data-providers/rest-data-provider.js';
|
|
4
3
|
import { Filter, buildFilterFromRequestParameters, customUrlToken, } from './filter/filter-interfaces.js';
|
|
4
|
+
import { getRelationFieldInfo } from './remult3/relationInfoMember.js';
|
|
5
5
|
import { ForbiddenError } from './server-action.js';
|
|
6
6
|
export class DataApi {
|
|
7
7
|
repository;
|
|
@@ -118,7 +118,7 @@ export class DataApi {
|
|
|
118
118
|
includeNone() {
|
|
119
119
|
let include = {};
|
|
120
120
|
for (const field of this.repository.metadata.fields) {
|
|
121
|
-
if (
|
|
121
|
+
if (getRelationFieldInfo(field)) {
|
|
122
122
|
include[field.key] = false;
|
|
123
123
|
}
|
|
124
124
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { UrlBuilder } from '../../urlBuilder.js';
|
|
2
2
|
import { buildRestDataProvider, retry } from '../buildRestDataProvider.js';
|
|
3
|
-
import { Remult } from '../context.js';
|
|
4
3
|
import { customUrlToken, Filter } from '../filter/filter-interfaces.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { getRelationFieldInfo } from '../remult3/relationInfoMember.js';
|
|
5
|
+
import { remultStatic } from '../remult-static.js';
|
|
7
6
|
export class RestDataProvider {
|
|
8
7
|
apiProvider;
|
|
9
8
|
constructor(apiProvider) {
|
|
@@ -32,9 +31,9 @@ export function findOptionsToJson(options, meta) {
|
|
|
32
31
|
if (Object.prototype.hasOwnProperty.call(options.include, key)) {
|
|
33
32
|
let element = options.include[key];
|
|
34
33
|
if (typeof element === 'object') {
|
|
35
|
-
const rel =
|
|
34
|
+
const rel = getRelationFieldInfo(meta.fields.find(key));
|
|
36
35
|
if (rel) {
|
|
37
|
-
element = findOptionsToJson(element,
|
|
36
|
+
element = findOptionsToJson(element, rel.toRepo.metadata);
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
newInclude[key] = element;
|
|
@@ -74,9 +73,9 @@ export function findOptionsFromJson(json, meta) {
|
|
|
74
73
|
if (Object.prototype.hasOwnProperty.call(newInclude, key)) {
|
|
75
74
|
let element = newInclude[key];
|
|
76
75
|
if (typeof element === 'object') {
|
|
77
|
-
const rel =
|
|
76
|
+
const rel = getRelationFieldInfo(meta.fields.find(key));
|
|
78
77
|
if (rel) {
|
|
79
|
-
element = findOptionsFromJson(element,
|
|
78
|
+
element = findOptionsFromJson(element, rel.toRepo.metadata);
|
|
80
79
|
}
|
|
81
80
|
}
|
|
82
81
|
newInclude[key] = element;
|
|
@@ -179,7 +178,7 @@ export class RestEntityDataProvider {
|
|
|
179
178
|
return {
|
|
180
179
|
result,
|
|
181
180
|
unsubscribe: async () => {
|
|
182
|
-
return actionInfo.runActionWithoutBlockingUI(() => this.http().post(this.url() + '?__action=endLiveQuery', {
|
|
181
|
+
return remultStatic.actionInfo.runActionWithoutBlockingUI(() => this.http().post(this.url() + '?__action=endLiveQuery', {
|
|
183
182
|
id: queryId,
|
|
184
183
|
}));
|
|
185
184
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SqlDatabase } from '../data-providers/sql-database.js';
|
|
2
2
|
import { getEntityMetadata } from '../remult3/RepositoryImplementation.js';
|
|
3
|
-
import {
|
|
3
|
+
import { getRelationFieldInfo } from '../remult3/relationInfoMember.js';
|
|
4
4
|
export class FilterConsumerBridgeToSqlRequest {
|
|
5
5
|
r;
|
|
6
6
|
nameProvider;
|
|
@@ -200,7 +200,7 @@ export async function fieldDbName(f, meta, wrapIdentifier = (x) => x) {
|
|
|
200
200
|
return f.dbName;
|
|
201
201
|
return result;
|
|
202
202
|
}
|
|
203
|
-
const rel =
|
|
203
|
+
const rel = getRelationFieldInfo(f);
|
|
204
204
|
let field = rel?.type === 'toOne' &&
|
|
205
205
|
f.options.field;
|
|
206
206
|
if (field) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Remult } from '../context.js';
|
|
2
1
|
import { getEntityRef, getEntitySettings } from '../remult3/getEntityRef.js';
|
|
3
|
-
import {
|
|
2
|
+
import { getRelationFieldInfo } from '../remult3/relationInfoMember.js';
|
|
4
3
|
export class Filter {
|
|
5
4
|
apply;
|
|
6
5
|
constructor(apply) {
|
|
@@ -49,7 +48,7 @@ export class Filter {
|
|
|
49
48
|
}
|
|
50
49
|
else {
|
|
51
50
|
const field = entity.fields[key];
|
|
52
|
-
const rel =
|
|
51
|
+
const rel = getRelationFieldInfo(field);
|
|
53
52
|
const op = field.options;
|
|
54
53
|
let fh = rel?.type === 'toOne'
|
|
55
54
|
? op.fields
|
|
@@ -167,10 +166,9 @@ class filterHelper {
|
|
|
167
166
|
if (ei) {
|
|
168
167
|
if (!val) {
|
|
169
168
|
if (val === null && !this.metadata.allowNull) {
|
|
170
|
-
const rel =
|
|
169
|
+
const rel = getRelationFieldInfo(this.metadata);
|
|
171
170
|
if (rel?.type === 'reference')
|
|
172
|
-
if (
|
|
173
|
-
.valueType === Number)
|
|
171
|
+
if (rel.toRepo.metadata.idMetadata.field.options.valueType === Number)
|
|
174
172
|
return 0;
|
|
175
173
|
else
|
|
176
174
|
return '';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { buildRestDataProvider } from '../buildRestDataProvider.js';
|
|
2
2
|
import { RestDataProvider } from '../data-providers/rest-data-provider.js';
|
|
3
|
+
import { remultStatic } from '../remult-static.js';
|
|
3
4
|
import { getRepositoryInternals } from '../remult3/repository-internals.js';
|
|
4
5
|
import { liveQueryKeepAliveRoute, LiveQuerySubscriber, } from './SubscriptionChannel.js';
|
|
5
6
|
/* @internal*/
|
|
@@ -165,8 +166,7 @@ export class LiveQueryClient {
|
|
|
165
166
|
}
|
|
166
167
|
if (ids.length > 0) {
|
|
167
168
|
let p = this.apiProvider();
|
|
168
|
-
|
|
169
|
-
const invalidIds = await this.runPromise(await actionInfo.runActionWithoutBlockingUI(() => buildRestDataProvider(p.httpClient).post(p.url + '/' + liveQueryKeepAliveRoute, ids)));
|
|
169
|
+
const invalidIds = await this.runPromise(await remultStatic.actionInfo.runActionWithoutBlockingUI(() => buildRestDataProvider(p.httpClient).post(p.url + '/' + liveQueryKeepAliveRoute, ids)));
|
|
170
170
|
for (const id of invalidIds) {
|
|
171
171
|
for (const q of this.queries.values()) {
|
|
172
172
|
if (q.queryChannel === id)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { buildRestDataProvider } from '../buildRestDataProvider.js';
|
|
2
2
|
import { remult } from '../remult-proxy.js';
|
|
3
|
-
import {
|
|
3
|
+
import { remultStatic } from '../remult-static.js';
|
|
4
4
|
import { streamUrl } from './SubscriptionChannel.js';
|
|
5
5
|
export class SseSubscriptionClient {
|
|
6
6
|
openConnection(onReconnect) {
|
|
@@ -23,7 +23,7 @@ export class SseSubscriptionClient {
|
|
|
23
23
|
return () => {
|
|
24
24
|
listeners.splice(listeners.indexOf(handler, 1));
|
|
25
25
|
if (listeners.length == 0) {
|
|
26
|
-
actionInfo.runActionWithoutBlockingUI(() => provider.post(remult.apiClient.url + '/' + streamUrl + '/unsubscribe', {
|
|
26
|
+
remultStatic.actionInfo.runActionWithoutBlockingUI(() => provider.post(remult.apiClient.url + '/' + streamUrl + '/unsubscribe', {
|
|
27
27
|
channel: channel,
|
|
28
28
|
clientId: connectionId,
|
|
29
29
|
}));
|
|
@@ -69,7 +69,7 @@ export class SseSubscriptionClient {
|
|
|
69
69
|
});
|
|
70
70
|
return createConnectionPromise();
|
|
71
71
|
async function subscribeToChannel(channel) {
|
|
72
|
-
const result = await actionInfo.runActionWithoutBlockingUI(() => {
|
|
72
|
+
const result = await remultStatic.actionInfo.runActionWithoutBlockingUI(() => {
|
|
73
73
|
return provider.post(remult.apiClient.url + '/' + streamUrl + '/subscribe', {
|
|
74
74
|
channel: channel,
|
|
75
75
|
clientId: connectionId,
|