remult 0.25.5-exp.1 → 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 +66 -51
- 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 -12
- 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 +116 -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 -12
- 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);
|
|
@@ -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
|
});
|
|
@@ -397,8 +385,7 @@ export function remultGraphql(options) {
|
|
|
397
385
|
}
|
|
398
386
|
const whereTypeFields = [];
|
|
399
387
|
for (const f of meta.fields) {
|
|
400
|
-
const ri =
|
|
401
|
-
// let's not consider toMany relations for now
|
|
388
|
+
const ri = getRelationFieldInfo(f);
|
|
402
389
|
if (f.options.includeInApi === false)
|
|
403
390
|
continue;
|
|
404
391
|
let type = 'String';
|
|
@@ -423,9 +410,12 @@ export function remultGraphql(options) {
|
|
|
423
410
|
let notARealField = false;
|
|
424
411
|
if (ri) {
|
|
425
412
|
{
|
|
426
|
-
const refType = ri.
|
|
413
|
+
const refType = ri.toEntity;
|
|
427
414
|
ref = entities.find((i) => i.entityType === refType);
|
|
428
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
|
+
}
|
|
429
419
|
notARealField = ri.type === 'toOne' || ri.type === 'toMany';
|
|
430
420
|
const refKey = ref.key;
|
|
431
421
|
switch (ri.type) {
|
|
@@ -436,19 +426,19 @@ export function remultGraphql(options) {
|
|
|
436
426
|
value: `${getMetaType(ref)}${f.allowNull ? '' : '!'}`,
|
|
437
427
|
comment: f.caption,
|
|
438
428
|
});
|
|
439
|
-
currentType.query.resultProcessors.push((r) => {
|
|
440
|
-
const val = r[ri.type == 'reference' ? f.key : f.options.field]; //p1 - fix
|
|
441
|
-
if (val === null || val === undefined)
|
|
442
|
-
return null;
|
|
429
|
+
currentType.query.resultProcessors.push((r, orig) => {
|
|
443
430
|
r[f.key] = async (args, req, gqlInfo) => {
|
|
444
|
-
const
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
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];
|
|
452
442
|
};
|
|
453
443
|
});
|
|
454
444
|
break;
|
|
@@ -461,16 +451,15 @@ export function remultGraphql(options) {
|
|
|
461
451
|
order: 10,
|
|
462
452
|
comment: `List all \`${getMetaType(meta)}\` of \`${refKey}\``,
|
|
463
453
|
});
|
|
464
|
-
currentType.query.resultProcessors.push((r) => {
|
|
465
|
-
const val = r.id;
|
|
454
|
+
currentType.query.resultProcessors.push((r, y) => {
|
|
466
455
|
r[f.key] = async (args, req, gqlInfo) => {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}, 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);
|
|
474
463
|
};
|
|
475
464
|
});
|
|
476
465
|
}
|
|
@@ -679,6 +668,32 @@ export function remultGraphql(options) {
|
|
|
679
668
|
.join(`\n\n`)}
|
|
680
669
|
`,
|
|
681
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
|
+
}
|
|
682
697
|
}
|
|
683
698
|
function getQueryArgsConnection(key) {
|
|
684
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,
|
package/esm/src/remult-proxy.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
+
import { defaultFactory } from './remult-static.js';
|
|
1
2
|
import { getInternalKey } from './remult3/repository-internals.js';
|
|
2
|
-
let defaultRemult;
|
|
3
|
-
function defaultFactory() {
|
|
4
|
-
if (!defaultRemult) {
|
|
5
|
-
defaultRemult = RemultProxy.defaultRemultFactory();
|
|
6
|
-
}
|
|
7
|
-
return defaultRemult;
|
|
8
|
-
}
|
|
9
3
|
/*@internal*/
|
|
10
4
|
export class RemultProxy {
|
|
11
|
-
static defaultRemultFactory;
|
|
12
5
|
/* @internal*/
|
|
13
6
|
get liveQuerySubscriber() {
|
|
14
7
|
return this.remultFactory().liveQuerySubscriber;
|
|
@@ -82,6 +75,7 @@ export class RemultProxy {
|
|
|
82
75
|
get fields() {
|
|
83
76
|
return self.remultFactory().repo(...args).metadata.fields;
|
|
84
77
|
},
|
|
78
|
+
//@ts-ignore
|
|
85
79
|
[getInternalKey]() {
|
|
86
80
|
return self
|
|
87
81
|
.remultFactory()
|