remult 0.26.11 → 0.26.12-next.1
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/live-query/data-provider-live-query-storage.js +2 -2
- package/esm/migrations/generate-migrations.js +2 -2
- package/esm/migrations/migrate.js +2 -2
- package/esm/remult-next.js +1 -1
- package/esm/remult-solid-start.js +2 -2
- package/esm/server/JsonEntityFileStorage.js +1 -1
- package/esm/server/initDataProvider.js +7 -2
- package/esm/server/initDataProviderOrJson.js +6 -0
- package/esm/server/remult-api-server.js +64 -44
- package/esm/src/context.js +16 -7
- package/esm/src/data-providers/json-data-provider.js +8 -4
- package/esm/src/remult-static.js +1 -0
- package/esm/src/remult3/remult3.js +11 -6
- package/live-query/data-provider-live-query-storage.js +2 -2
- package/migrations/generate-migrations.js +2 -2
- package/migrations/migrate.js +2 -2
- package/package.json +1 -1
- package/remult-next.d.ts +1 -1
- package/remult-next.js +3 -1
- package/remult-solid-start.d.ts +1 -1
- package/remult-solid-start.js +12 -6
- package/server/JsonEntityFileStorage.js +1 -1
- package/server/initDataProvider.d.ts +1 -1
- package/server/initDataProvider.js +11 -3
- package/server/initDataProviderOrJson.d.ts +2 -0
- package/server/initDataProviderOrJson.js +17 -0
- package/server/remult-api-server.js +132 -85
- package/src/context.d.ts +11 -3
- package/src/context.js +33 -8
- package/src/data-providers/json-data-provider.d.ts +2 -1
- package/src/data-providers/json-data-provider.js +14 -9
- package/src/remult-static.d.ts +2 -0
- package/src/remult-static.js +1 -0
- package/src/remult3/remult3.js +11 -6
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import { initDataProvider } from '../server/initDataProvider.js';
|
|
3
2
|
import { Remult } from '../src/context.js';
|
|
4
3
|
import { EntityBase } from '../src/remult3/RepositoryImplementation.js';
|
|
5
4
|
import { Fields } from '../src/remult3/Fields.js';
|
|
6
5
|
import { Entity } from '../src/remult3/entity.js';
|
|
7
6
|
import { remultStatic } from '../src/remult-static.js';
|
|
7
|
+
import { initDataProviderOrJson } from '../server/initDataProviderOrJson';
|
|
8
8
|
export class DataProviderLiveQueryStorage {
|
|
9
9
|
repo;
|
|
10
10
|
dataProvider;
|
|
11
11
|
constructor(dataProvider) {
|
|
12
|
-
this.dataProvider =
|
|
12
|
+
this.dataProvider = initDataProviderOrJson(dataProvider);
|
|
13
13
|
this.repo = this.dataProvider.then((dp) => new Remult(dp).repo(LiveQueryStorageEntity));
|
|
14
14
|
}
|
|
15
15
|
async ensureSchema() {
|
|
@@ -4,7 +4,7 @@ import { compareMigrationSnapshot, emptySnapshot, } from './compare-migration-sn
|
|
|
4
4
|
import { updateMigrationsFile } from './update-migrations-ts-file.js';
|
|
5
5
|
import { DefaultMigrationBuilder, } from './migration-types.js';
|
|
6
6
|
import { isOfType } from '../src/isOfType.js';
|
|
7
|
-
import {
|
|
7
|
+
import { initDataProviderOrJson } from '../server/initDataProviderOrJson';
|
|
8
8
|
/**
|
|
9
9
|
* Generates migration scripts based on changes in entities.
|
|
10
10
|
*
|
|
@@ -21,7 +21,7 @@ export async function generateMigrations(options) {
|
|
|
21
21
|
const migrationDir = options.migrationsFolder || path.join(process.cwd(), 'src/migrations');
|
|
22
22
|
const snapshotFileName = options.snapshotFile || path.join(migrationDir, 'migrations-snapshot.json');
|
|
23
23
|
const migrationsTSFilename = options.migrationsTSFile || path.join(migrationDir, 'migrations.ts');
|
|
24
|
-
const dataProvider = await
|
|
24
|
+
const dataProvider = await initDataProviderOrJson(options.dataProvider);
|
|
25
25
|
for (const p of [snapshotFileName, migrationsTSFilename]) {
|
|
26
26
|
if (!fs.existsSync(path.dirname(p))) {
|
|
27
27
|
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { Entity, IdEntity, Fields, remult, Remult, } from '../index.js';
|
|
3
|
-
import {
|
|
3
|
+
import { initDataProviderOrJson } from '../server/initDataProviderOrJson';
|
|
4
4
|
import { doTransaction } from '../src/context.js';
|
|
5
5
|
import { cast, isOfType } from '../src/isOfType.js';
|
|
6
6
|
/**
|
|
@@ -17,7 +17,7 @@ import { cast, isOfType } from '../src/isOfType.js';
|
|
|
17
17
|
*/
|
|
18
18
|
export async function migrate(options) {
|
|
19
19
|
let migrationTableName = options.migrationsTable || '__remult_migrations_version';
|
|
20
|
-
const dataProvider = await
|
|
20
|
+
const dataProvider = await initDataProviderOrJson(options.dataProvider);
|
|
21
21
|
const prev = remult.dataProvider;
|
|
22
22
|
remult.dataProvider = dataProvider;
|
|
23
23
|
try {
|
package/esm/remult-next.js
CHANGED
|
@@ -118,6 +118,6 @@ export function remultNextApp(options) {
|
|
|
118
118
|
POST: handler,
|
|
119
119
|
PUT: handler,
|
|
120
120
|
DELETE: handler,
|
|
121
|
-
withRemult: (what) => result.withRemultAsync({}, what),
|
|
121
|
+
withRemult: (what, disableInitUserAndRequest) => result.withRemultAsync(disableInitUserAndRequest ? undefined : {}, what),
|
|
122
122
|
};
|
|
123
123
|
}
|
|
@@ -86,8 +86,8 @@ export function remultSolidStart(options) {
|
|
|
86
86
|
return Object.assign(handler, {
|
|
87
87
|
getRemult: (req) => result.getRemult(req),
|
|
88
88
|
openApiDoc: (options) => result.openApiDoc(options),
|
|
89
|
-
async withRemult(what) {
|
|
90
|
-
return result.withRemultAsync(await getRequestEvent(), what);
|
|
89
|
+
async withRemult(what, disableInitUserAndRequest) {
|
|
90
|
+
return result.withRemultAsync(disableInitUserAndRequest ? undefined : await getRequestEvent(), what);
|
|
91
91
|
},
|
|
92
92
|
GET: serverHandler,
|
|
93
93
|
PUT: serverHandler,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { remultStatic } from '../src/remult-static';
|
|
2
|
+
export function initDataProvider(optionsDataProvider, useStaticDefault, defaultDataProvider) {
|
|
2
3
|
let dataProvider;
|
|
3
4
|
if (typeof optionsDataProvider === 'function') {
|
|
4
5
|
dataProvider = optionsDataProvider();
|
|
@@ -8,7 +9,11 @@ export function initDataProvider(optionsDataProvider) {
|
|
|
8
9
|
dataProvider = dataProvider.then(async (dp) => {
|
|
9
10
|
if (dp)
|
|
10
11
|
return dp;
|
|
11
|
-
|
|
12
|
+
if (useStaticDefault)
|
|
13
|
+
dp = await remultStatic.defaultDataProvider();
|
|
14
|
+
if (dp)
|
|
15
|
+
return dp;
|
|
16
|
+
return defaultDataProvider?.();
|
|
12
17
|
});
|
|
13
18
|
return dataProvider;
|
|
14
19
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { initDataProvider } from './initDataProvider';
|
|
2
|
+
export function initDataProviderOrJson(dataProvider) {
|
|
3
|
+
return initDataProvider(dataProvider, false, async () => {
|
|
4
|
+
return new (await import('./JsonEntityFileStorage.js')).JsonFileDataProvider('./db');
|
|
5
|
+
});
|
|
6
|
+
}
|
|
@@ -10,10 +10,10 @@ 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
12
|
import { serverActionField } from '../src/server-action-info.js';
|
|
13
|
-
import { initDataProvider } from './initDataProvider.js';
|
|
14
13
|
import { remultStatic } from '../src/remult-static.js';
|
|
15
14
|
import remultAdminHtml from './remult-admin.js';
|
|
16
15
|
import { isOfType } from '../src/isOfType.js';
|
|
16
|
+
import { initDataProviderOrJson } from './initDataProviderOrJson';
|
|
17
17
|
export function createRemultServerCore(options, serverCoreOptions) {
|
|
18
18
|
if (!options) {
|
|
19
19
|
options = {};
|
|
@@ -30,7 +30,8 @@ export function createRemultServerCore(options, serverCoreOptions) {
|
|
|
30
30
|
if (!options.queueStorage) {
|
|
31
31
|
options.queueStorage = new InMemoryQueueStorage();
|
|
32
32
|
}
|
|
33
|
-
let dataProvider =
|
|
33
|
+
let dataProvider = initDataProviderOrJson(options.dataProvider);
|
|
34
|
+
remultStatic.defaultDataProvider = () => dataProvider;
|
|
34
35
|
if (options.ensureSchema === undefined)
|
|
35
36
|
options.ensureSchema = true;
|
|
36
37
|
RemultAsyncLocalStorage.enable();
|
|
@@ -104,15 +105,20 @@ export class RemultServerImplementation {
|
|
|
104
105
|
withRemultAsync(request, what) {
|
|
105
106
|
if (!request)
|
|
106
107
|
return this.runWithRemult(what);
|
|
107
|
-
return new Promise((resolve, error) => {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
108
|
+
return new Promise(async (resolve, error) => {
|
|
109
|
+
try {
|
|
110
|
+
return await this.withRemult(request, undefined, async () => {
|
|
111
|
+
try {
|
|
112
|
+
what().then(resolve).catch(error);
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
error(err);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
error(err);
|
|
121
|
+
}
|
|
116
122
|
});
|
|
117
123
|
}
|
|
118
124
|
getEntities() {
|
|
@@ -145,9 +151,9 @@ export class RemultServerImplementation {
|
|
|
145
151
|
throw new Error("Couldn't find entity " + entityKey);
|
|
146
152
|
};
|
|
147
153
|
subscriptionServer;
|
|
148
|
-
withRemult = (req, res, next) => {
|
|
149
|
-
this.process(async () => {
|
|
150
|
-
next();
|
|
154
|
+
withRemult = async (req, res, next) => {
|
|
155
|
+
await this.process(async () => {
|
|
156
|
+
await next();
|
|
151
157
|
})(req, res);
|
|
152
158
|
};
|
|
153
159
|
routeImpl;
|
|
@@ -277,6 +283,8 @@ export class RemultServerImplementation {
|
|
|
277
283
|
x.subscriptionServer = this.subscriptionServer;
|
|
278
284
|
x.liveQueryStorage = this.liveQueryStorage;
|
|
279
285
|
return await what(x);
|
|
286
|
+
}, {
|
|
287
|
+
dataProvider,
|
|
280
288
|
});
|
|
281
289
|
}
|
|
282
290
|
process(what) {
|
|
@@ -291,38 +299,50 @@ export class RemultServerImplementation {
|
|
|
291
299
|
if (!genReq.params)
|
|
292
300
|
genReq.params = req['_tempParams'];
|
|
293
301
|
}
|
|
294
|
-
let myReq = new
|
|
295
|
-
let myRes = new
|
|
302
|
+
let myReq = new RequestBridgeToDataApiRequest(genReq);
|
|
303
|
+
let myRes = new ResponseBridgeToDataApiResponse(origRes, req, this.options.error);
|
|
296
304
|
try {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
305
|
+
if (remultStatic.asyncContext.isInInitRequest())
|
|
306
|
+
return await what(remultStatic.asyncContext.getStore().remult, myReq, myRes, genReq, origRes, req);
|
|
307
|
+
else
|
|
308
|
+
await this.runWithRemult(async (remult) => {
|
|
309
|
+
if (req) {
|
|
310
|
+
remultStatic.asyncContext.setInInitRequest(true);
|
|
311
|
+
try {
|
|
312
|
+
let user;
|
|
313
|
+
if (this.options.getUser)
|
|
314
|
+
user = await this.options.getUser(req);
|
|
315
|
+
else {
|
|
316
|
+
user = req['user'];
|
|
317
|
+
if (!user)
|
|
318
|
+
user = req['auth'];
|
|
319
|
+
}
|
|
320
|
+
if (user)
|
|
321
|
+
remult.user = user;
|
|
322
|
+
if (this.options.initRequest) {
|
|
323
|
+
await this.options.initRequest(req, {
|
|
324
|
+
remult,
|
|
325
|
+
get liveQueryStorage() {
|
|
326
|
+
return remult.liveQueryStorage;
|
|
327
|
+
},
|
|
328
|
+
set liveQueryStorage(value) {
|
|
329
|
+
remult.liveQueryStorage = value;
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
finally {
|
|
335
|
+
remultStatic.asyncContext.setInInitRequest(false);
|
|
336
|
+
}
|
|
319
337
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
});
|
|
338
|
+
await what(remult, myReq, myRes, genReq, origRes, req);
|
|
339
|
+
});
|
|
323
340
|
}
|
|
324
341
|
catch (err) {
|
|
325
|
-
|
|
342
|
+
if (origRes)
|
|
343
|
+
myRes.error(err, undefined);
|
|
344
|
+
else
|
|
345
|
+
throw err;
|
|
326
346
|
}
|
|
327
347
|
};
|
|
328
348
|
}
|
|
@@ -735,7 +755,7 @@ export class RemultServerImplementation {
|
|
|
735
755
|
/* internal */
|
|
736
756
|
backendMethodsOpenApi = [];
|
|
737
757
|
}
|
|
738
|
-
class
|
|
758
|
+
class RequestBridgeToDataApiRequest {
|
|
739
759
|
r;
|
|
740
760
|
get(key) {
|
|
741
761
|
return this.r?.query[key];
|
|
@@ -744,7 +764,7 @@ class ExpressRequestBridgeToDataApiRequest {
|
|
|
744
764
|
this.r = r;
|
|
745
765
|
}
|
|
746
766
|
}
|
|
747
|
-
class
|
|
767
|
+
class ResponseBridgeToDataApiResponse {
|
|
748
768
|
r;
|
|
749
769
|
req;
|
|
750
770
|
handleError;
|
package/esm/src/context.js
CHANGED
|
@@ -7,13 +7,14 @@ import { serverActionField } from './server-action-info.js';
|
|
|
7
7
|
import { buildRestDataProvider, isExternalHttpProvider, } from './buildRestDataProvider.js';
|
|
8
8
|
import { verifyFieldRelationInfo } from './remult3/relationInfoMember.js';
|
|
9
9
|
import { remultStatic, resetFactory } from './remult-static.js';
|
|
10
|
+
import { initDataProvider } from '../server/initDataProvider';
|
|
10
11
|
export class RemultAsyncLocalStorage {
|
|
11
12
|
remultObjectStorage;
|
|
12
13
|
static enable() {
|
|
13
14
|
remultStatic.remultFactory = () => {
|
|
14
|
-
const r = remultStatic.asyncContext.
|
|
15
|
+
const r = remultStatic.asyncContext.getStore();
|
|
15
16
|
if (r)
|
|
16
|
-
return r;
|
|
17
|
+
return r.remult;
|
|
17
18
|
else
|
|
18
19
|
throw new Error('remult object was requested outside of a valid context, try running it within initApi or a remult request cycle');
|
|
19
20
|
};
|
|
@@ -26,12 +27,21 @@ export class RemultAsyncLocalStorage {
|
|
|
26
27
|
}
|
|
27
28
|
async run(remult, callback) {
|
|
28
29
|
if (this.remultObjectStorage) {
|
|
29
|
-
return this.remultObjectStorage.run(remult, () => callback(remult));
|
|
30
|
+
return this.remultObjectStorage.run({ remult }, () => callback(remult));
|
|
30
31
|
}
|
|
31
32
|
else
|
|
32
33
|
return callback(remult);
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
+
isInInitRequest() {
|
|
36
|
+
return this.remultObjectStorage?.getStore()?.inInitRequest;
|
|
37
|
+
}
|
|
38
|
+
setInInitRequest(val) {
|
|
39
|
+
const store = this.remultObjectStorage?.getStore();
|
|
40
|
+
if (!store)
|
|
41
|
+
return;
|
|
42
|
+
store.inInitRequest = val;
|
|
43
|
+
}
|
|
44
|
+
getStore() {
|
|
35
45
|
if (!this.remultObjectStorage) {
|
|
36
46
|
throw new Error("can't use static remult in this environment, `async_hooks` were not initialized");
|
|
37
47
|
}
|
|
@@ -282,9 +292,8 @@ class transactionLiveQueryPublisher {
|
|
|
282
292
|
}
|
|
283
293
|
}
|
|
284
294
|
}
|
|
285
|
-
export function withRemult(callback, options) {
|
|
295
|
+
export async function withRemult(callback, options) {
|
|
286
296
|
const remult = new Remult();
|
|
287
|
-
|
|
288
|
-
remult.dataProvider = options.dataProvider;
|
|
297
|
+
remult.dataProvider = await initDataProvider(options?.dataProvider, true, async () => remult.dataProvider);
|
|
289
298
|
return remultStatic.asyncContext.run(remult, (r) => callback(r));
|
|
290
299
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { ArrayEntityDataProvider } from './array-entity-data-provider.js';
|
|
2
2
|
export class JsonDataProvider {
|
|
3
3
|
storage;
|
|
4
|
-
|
|
4
|
+
formatted;
|
|
5
|
+
constructor(storage, formatted = false) {
|
|
5
6
|
this.storage = storage;
|
|
7
|
+
this.formatted = formatted;
|
|
6
8
|
}
|
|
7
9
|
getEntityDataProvider(entity) {
|
|
8
|
-
return new JsonEntityDataProvider(entity, this.storage);
|
|
10
|
+
return new JsonEntityDataProvider(entity, this.storage, this.formatted);
|
|
9
11
|
}
|
|
10
12
|
async transaction(action) {
|
|
11
13
|
await action(this);
|
|
@@ -14,9 +16,11 @@ export class JsonDataProvider {
|
|
|
14
16
|
class JsonEntityDataProvider {
|
|
15
17
|
entity;
|
|
16
18
|
helper;
|
|
17
|
-
|
|
19
|
+
formatted;
|
|
20
|
+
constructor(entity, helper, formatted) {
|
|
18
21
|
this.entity = entity;
|
|
19
22
|
this.helper = helper;
|
|
23
|
+
this.formatted = formatted;
|
|
20
24
|
}
|
|
21
25
|
async loadEntityData(what) {
|
|
22
26
|
let data = [];
|
|
@@ -25,7 +29,7 @@ class JsonEntityDataProvider {
|
|
|
25
29
|
if (s)
|
|
26
30
|
data = JSON.parse(s);
|
|
27
31
|
let dp = new ArrayEntityDataProvider(this.entity, () => data);
|
|
28
|
-
return what(dp, async () => await this.helper.setItem(dbName, JSON.stringify(data, undefined, 2)));
|
|
32
|
+
return what(dp, async () => await this.helper.setItem(dbName, JSON.stringify(data, undefined, this.formatted ? 2 : undefined)));
|
|
29
33
|
}
|
|
30
34
|
p = Promise.resolve();
|
|
31
35
|
find(options) {
|
package/esm/src/remult-static.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
export const flags = {
|
|
2
2
|
error500RetryCount: 4,
|
|
3
3
|
};
|
|
4
|
-
//y2 - soft-delete-discussion https://discord.com/channels/975754286384418847/1230386433093533698/1230386433093533698
|
|
5
4
|
//y1 - live query with count #436
|
|
5
|
+
//y1 - https://github.com/remult/remult/discussions/438
|
|
6
|
+
//p1 - discuss next auth withRemult paradox
|
|
7
|
+
//p1 - maybe the default withRemult should by default use the data provider set by the remultExpress
|
|
8
|
+
//p1 - withRemult to support the full range of data provider.
|
|
6
9
|
//y1 TODO - In the esm version of our tutorial - the imports are automatically .ts and not .js in react and not in vue
|
|
7
10
|
//y1 TODO - consider id to also support keyof (id:['company','index']) - had problem with | (keyof Partial<entityType>)[] & `entity`
|
|
8
11
|
//y1 TODO - readonly key: keyof MembersOnly<entityType> & string
|
|
9
12
|
//y1 - talk about insert / update / delete with relations
|
|
10
13
|
/*
|
|
11
|
-
|
|
14
|
+
repo(Order).insert({},{
|
|
12
15
|
relations:{
|
|
13
16
|
orderItems:[{},{},{}]
|
|
14
17
|
}
|
|
@@ -16,14 +19,16 @@ export const flags = {
|
|
|
16
19
|
*/
|
|
17
20
|
//y1 - repo batch - for multiple operations:
|
|
18
21
|
/*
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
const result = await repo.batch(x=>({
|
|
23
|
+
data:x.find(),
|
|
24
|
+
count:x.count()
|
|
25
|
+
}))
|
|
23
26
|
*/
|
|
27
|
+
//p1 - consider in json storage, to store the json without spaces
|
|
24
28
|
//p1 - consider upsert (where,set)
|
|
25
29
|
//y1 - wait a second to close stream -see pr
|
|
26
30
|
//p1 - Consider enforcing serial operations on JSON database to prevent data loss
|
|
31
|
+
//y2 - soft-delete-discussion https://discord.com/channels/975754286384418847/1230386433093533698/1230386433093533698
|
|
27
32
|
//p1 - prepare the createEntity discussion
|
|
28
33
|
//p1 - return error on connection error
|
|
29
34
|
//p1 - article on displayValue including it's definition for entities that is used in relations
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LiveQueryStorageEntity = exports.DataProviderLiveQueryStorage = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
var initDataProvider_js_1 = require("../server/initDataProvider.js");
|
|
6
5
|
var context_js_1 = require("../src/context.js");
|
|
7
6
|
var RepositoryImplementation_js_1 = require("../src/remult3/RepositoryImplementation.js");
|
|
8
7
|
var Fields_js_1 = require("../src/remult3/Fields.js");
|
|
9
8
|
var entity_js_1 = require("../src/remult3/entity.js");
|
|
10
9
|
var remult_static_js_1 = require("../src/remult-static.js");
|
|
10
|
+
var initDataProviderOrJson_1 = require("../server/initDataProviderOrJson");
|
|
11
11
|
var DataProviderLiveQueryStorage = /** @class */ (function () {
|
|
12
12
|
function DataProviderLiveQueryStorage(dataProvider) {
|
|
13
|
-
this.dataProvider = (0,
|
|
13
|
+
this.dataProvider = (0, initDataProviderOrJson_1.initDataProviderOrJson)(dataProvider);
|
|
14
14
|
this.repo = this.dataProvider.then(function (dp) {
|
|
15
15
|
return new context_js_1.Remult(dp).repo(LiveQueryStorageEntity);
|
|
16
16
|
});
|
|
@@ -8,7 +8,7 @@ var compare_migration_snapshots_js_1 = require("./compare-migration-snapshots.js
|
|
|
8
8
|
var update_migrations_ts_file_js_1 = require("./update-migrations-ts-file.js");
|
|
9
9
|
var migration_types_js_1 = require("./migration-types.js");
|
|
10
10
|
var isOfType_js_1 = require("../src/isOfType.js");
|
|
11
|
-
var
|
|
11
|
+
var initDataProviderOrJson_1 = require("../server/initDataProviderOrJson");
|
|
12
12
|
/**
|
|
13
13
|
* Generates migration scripts based on changes in entities.
|
|
14
14
|
*
|
|
@@ -31,7 +31,7 @@ function generateMigrations(options) {
|
|
|
31
31
|
migrationDir = options.migrationsFolder || path_1.default.join(process.cwd(), 'src/migrations');
|
|
32
32
|
snapshotFileName = options.snapshotFile || path_1.default.join(migrationDir, 'migrations-snapshot.json');
|
|
33
33
|
migrationsTSFilename = options.migrationsTSFile || path_1.default.join(migrationDir, 'migrations.ts');
|
|
34
|
-
return [4 /*yield*/, (0,
|
|
34
|
+
return [4 /*yield*/, (0, initDataProviderOrJson_1.initDataProviderOrJson)(options.dataProvider)];
|
|
35
35
|
case 1:
|
|
36
36
|
dataProvider = _d.sent();
|
|
37
37
|
try {
|
package/migrations/migrate.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.migrate = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var index_js_1 = require("../index.js");
|
|
6
|
-
var
|
|
6
|
+
var initDataProviderOrJson_1 = require("../server/initDataProviderOrJson");
|
|
7
7
|
var context_js_1 = require("../src/context.js");
|
|
8
8
|
var isOfType_js_1 = require("../src/isOfType.js");
|
|
9
9
|
/**
|
|
@@ -26,7 +26,7 @@ function migrate(options) {
|
|
|
26
26
|
switch (_a.label) {
|
|
27
27
|
case 0:
|
|
28
28
|
migrationTableName = options.migrationsTable || '__remult_migrations_version';
|
|
29
|
-
return [4 /*yield*/, (0,
|
|
29
|
+
return [4 /*yield*/, (0, initDataProviderOrJson_1.initDataProviderOrJson)(options.dataProvider)];
|
|
30
30
|
case 1:
|
|
31
31
|
dataProvider = _a.sent();
|
|
32
32
|
prev = index_js_1.remult.dataProvider;
|
package/package.json
CHANGED
package/remult-next.d.ts
CHANGED
|
@@ -22,5 +22,5 @@ export type RemultNextAppServer = RemultServerCore<Request> & {
|
|
|
22
22
|
PUT: (req: Request) => Promise<Response>;
|
|
23
23
|
POST: (req: Request) => Promise<Response>;
|
|
24
24
|
DELETE: (req: Request) => Promise<Response>;
|
|
25
|
-
withRemult<T>(what: () => Promise<T
|
|
25
|
+
withRemult<T>(what: () => Promise<T>, disableInitUserAndRequest?: boolean): Promise<T>;
|
|
26
26
|
};
|
package/remult-next.js
CHANGED
|
@@ -174,7 +174,9 @@ function remultNextApp(options) {
|
|
|
174
174
|
POST: handler,
|
|
175
175
|
PUT: handler,
|
|
176
176
|
DELETE: handler,
|
|
177
|
-
withRemult: function (what
|
|
177
|
+
withRemult: function (what, disableInitUserAndRequest) {
|
|
178
|
+
return result.withRemultAsync(disableInitUserAndRequest ? undefined : {}, what);
|
|
179
|
+
},
|
|
178
180
|
};
|
|
179
181
|
}
|
|
180
182
|
exports.remultNextApp = remultNextApp;
|
package/remult-solid-start.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { RemultServerCore, RemultServerOptions } from './server/index.js';
|
|
|
3
3
|
export declare function remultSolidStart(options: RemultServerOptions<RequestEvent>): RemultSolidStartServer;
|
|
4
4
|
type RequestHandler = (event: RequestEvent) => Promise<Response>;
|
|
5
5
|
export type RemultSolidStartServer = RemultServerCore<RequestEvent> & {
|
|
6
|
-
withRemult<T>(what: () => Promise<T
|
|
6
|
+
withRemult<T>(what: () => Promise<T>, disableInitUserAndRequest?: boolean): Promise<T>;
|
|
7
7
|
GET: RequestHandler;
|
|
8
8
|
PUT: RequestHandler;
|
|
9
9
|
POST: RequestHandler;
|
package/remult-solid-start.js
CHANGED
|
@@ -112,15 +112,21 @@ function remultSolidStart(options) {
|
|
|
112
112
|
return Object.assign(handler, {
|
|
113
113
|
getRemult: function (req) { return result.getRemult(req); },
|
|
114
114
|
openApiDoc: function (options) { return result.openApiDoc(options); },
|
|
115
|
-
withRemult: function (what) {
|
|
115
|
+
withRemult: function (what, disableInitUserAndRequest) {
|
|
116
116
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
117
|
-
var _a, _b;
|
|
118
|
-
return tslib_1.__generator(this, function (
|
|
119
|
-
switch (
|
|
117
|
+
var _a, _b, _c;
|
|
118
|
+
return tslib_1.__generator(this, function (_d) {
|
|
119
|
+
switch (_d.label) {
|
|
120
120
|
case 0:
|
|
121
121
|
_b = (_a = result).withRemultAsync;
|
|
122
|
-
return [
|
|
123
|
-
|
|
122
|
+
if (!disableInitUserAndRequest) return [3 /*break*/, 1];
|
|
123
|
+
_c = undefined;
|
|
124
|
+
return [3 /*break*/, 3];
|
|
125
|
+
case 1: return [4 /*yield*/, (0, web_1.getRequestEvent)()];
|
|
126
|
+
case 2:
|
|
127
|
+
_c = _d.sent();
|
|
128
|
+
_d.label = 3;
|
|
129
|
+
case 3: return [2 /*return*/, _b.apply(_a, [_c, what])];
|
|
124
130
|
}
|
|
125
131
|
});
|
|
126
132
|
});
|
|
@@ -28,7 +28,7 @@ exports.JsonEntityFileStorage = JsonEntityFileStorage;
|
|
|
28
28
|
var JsonFileDataProvider = /** @class */ (function (_super) {
|
|
29
29
|
tslib_1.__extends(JsonFileDataProvider, _super);
|
|
30
30
|
function JsonFileDataProvider(folderPath) {
|
|
31
|
-
return _super.call(this, new JsonEntityFileStorage(folderPath)) || this;
|
|
31
|
+
return _super.call(this, new JsonEntityFileStorage(folderPath), true) || this;
|
|
32
32
|
}
|
|
33
33
|
return JsonFileDataProvider;
|
|
34
34
|
}(index_js_1.JsonDataProvider));
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { DataProvider } from '../src/data-interfaces.js';
|
|
2
|
-
export declare function initDataProvider(optionsDataProvider
|
|
2
|
+
export declare function initDataProvider(optionsDataProvider: DataProvider | Promise<DataProvider> | (() => Promise<DataProvider | undefined>) | undefined, useStaticDefault: boolean, defaultDataProvider: () => Promise<DataProvider>): Promise<DataProvider>;
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initDataProvider = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
|
|
5
|
+
var remult_static_1 = require("../src/remult-static");
|
|
6
|
+
function initDataProvider(optionsDataProvider, useStaticDefault, defaultDataProvider) {
|
|
6
7
|
var _this = this;
|
|
7
8
|
var dataProvider;
|
|
8
9
|
if (typeof optionsDataProvider === 'function') {
|
|
@@ -16,8 +17,15 @@ function initDataProvider(optionsDataProvider) {
|
|
|
16
17
|
case 0:
|
|
17
18
|
if (dp)
|
|
18
19
|
return [2 /*return*/, dp];
|
|
19
|
-
return [
|
|
20
|
-
|
|
20
|
+
if (!useStaticDefault) return [3 /*break*/, 2];
|
|
21
|
+
return [4 /*yield*/, remult_static_1.remultStatic.defaultDataProvider()];
|
|
22
|
+
case 1:
|
|
23
|
+
dp = _a.sent();
|
|
24
|
+
_a.label = 2;
|
|
25
|
+
case 2:
|
|
26
|
+
if (dp)
|
|
27
|
+
return [2 /*return*/, dp];
|
|
28
|
+
return [2 /*return*/, defaultDataProvider === null || defaultDataProvider === void 0 ? void 0 : defaultDataProvider()];
|
|
21
29
|
}
|
|
22
30
|
});
|
|
23
31
|
}); });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initDataProviderOrJson = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var initDataProvider_1 = require("./initDataProvider");
|
|
6
|
+
function initDataProviderOrJson(dataProvider) {
|
|
7
|
+
var _this = this;
|
|
8
|
+
return (0, initDataProvider_1.initDataProvider)(dataProvider, false, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
9
|
+
return tslib_1.__generator(this, function (_a) {
|
|
10
|
+
switch (_a.label) {
|
|
11
|
+
case 0: return [4 /*yield*/, Promise.resolve().then(function () { return tslib_1.__importStar(require('./JsonEntityFileStorage.js')); })];
|
|
12
|
+
case 1: return [2 /*return*/, new (_a.sent()).JsonFileDataProvider('./db')];
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}); });
|
|
16
|
+
}
|
|
17
|
+
exports.initDataProviderOrJson = initDataProviderOrJson;
|
|
@@ -13,10 +13,10 @@ var entity_js_1 = require("../src/remult3/entity.js");
|
|
|
13
13
|
var getEntityRef_js_1 = require("../src/remult3/getEntityRef.js");
|
|
14
14
|
var server_action_js_1 = require("../src/server-action.js");
|
|
15
15
|
var server_action_info_js_1 = require("../src/server-action-info.js");
|
|
16
|
-
var initDataProvider_js_1 = require("./initDataProvider.js");
|
|
17
16
|
var remult_static_js_1 = require("../src/remult-static.js");
|
|
18
17
|
var remult_admin_js_1 = tslib_1.__importDefault(require("./remult-admin.js"));
|
|
19
18
|
var isOfType_js_1 = require("../src/isOfType.js");
|
|
19
|
+
var initDataProviderOrJson_1 = require("./initDataProviderOrJson");
|
|
20
20
|
function createRemultServerCore(options, serverCoreOptions) {
|
|
21
21
|
if (!options) {
|
|
22
22
|
options = {};
|
|
@@ -33,7 +33,8 @@ function createRemultServerCore(options, serverCoreOptions) {
|
|
|
33
33
|
if (!options.queueStorage) {
|
|
34
34
|
options.queueStorage = new InMemoryQueueStorage();
|
|
35
35
|
}
|
|
36
|
-
var dataProvider = (0,
|
|
36
|
+
var dataProvider = (0, initDataProviderOrJson_1.initDataProviderOrJson)(options.dataProvider);
|
|
37
|
+
remult_static_js_1.remultStatic.defaultDataProvider = function () { return dataProvider; };
|
|
37
38
|
if (options.ensureSchema === undefined)
|
|
38
39
|
options.ensureSchema = true;
|
|
39
40
|
context_js_1.RemultAsyncLocalStorage.enable();
|
|
@@ -142,14 +143,26 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
142
143
|
}
|
|
143
144
|
});
|
|
144
145
|
}); };
|
|
145
|
-
this.withRemult = function (req, res, next) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return [
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
146
|
+
this.withRemult = function (req, res, next) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
147
|
+
var _this = this;
|
|
148
|
+
return tslib_1.__generator(this, function (_a) {
|
|
149
|
+
switch (_a.label) {
|
|
150
|
+
case 0: return [4 /*yield*/, this.process(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
151
|
+
return tslib_1.__generator(this, function (_a) {
|
|
152
|
+
switch (_a.label) {
|
|
153
|
+
case 0: return [4 /*yield*/, next()];
|
|
154
|
+
case 1:
|
|
155
|
+
_a.sent();
|
|
156
|
+
return [2 /*return*/];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}); })(req, res)];
|
|
160
|
+
case 1:
|
|
161
|
+
_a.sent();
|
|
162
|
+
return [2 /*return*/];
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}); };
|
|
153
166
|
this.registeredRouter = false;
|
|
154
167
|
this.hasQueue = false;
|
|
155
168
|
/* internal */
|
|
@@ -240,16 +253,33 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
240
253
|
var _this = this;
|
|
241
254
|
if (!request)
|
|
242
255
|
return this.runWithRemult(what);
|
|
243
|
-
return new Promise(function (resolve, error) {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
256
|
+
return new Promise(function (resolve, error) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
257
|
+
var err_1;
|
|
258
|
+
var _this = this;
|
|
259
|
+
return tslib_1.__generator(this, function (_a) {
|
|
260
|
+
switch (_a.label) {
|
|
261
|
+
case 0:
|
|
262
|
+
_a.trys.push([0, 2, , 3]);
|
|
263
|
+
return [4 /*yield*/, this.withRemult(request, undefined, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
264
|
+
return tslib_1.__generator(this, function (_a) {
|
|
265
|
+
try {
|
|
266
|
+
what().then(resolve).catch(error);
|
|
267
|
+
}
|
|
268
|
+
catch (err) {
|
|
269
|
+
error(err);
|
|
270
|
+
}
|
|
271
|
+
return [2 /*return*/];
|
|
272
|
+
});
|
|
273
|
+
}); })];
|
|
274
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
275
|
+
case 2:
|
|
276
|
+
err_1 = _a.sent();
|
|
277
|
+
error(err_1);
|
|
278
|
+
return [3 /*break*/, 3];
|
|
279
|
+
case 3: return [2 /*return*/];
|
|
250
280
|
}
|
|
251
281
|
});
|
|
252
|
-
});
|
|
282
|
+
}); });
|
|
253
283
|
};
|
|
254
284
|
RemultServerImplementation.prototype.getEntities = function () {
|
|
255
285
|
//TODO V2 - consider using entitiesMetaData - but it may require making it all awaitable
|
|
@@ -524,7 +554,9 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
524
554
|
case 1: return [2 /*return*/, _a.sent()];
|
|
525
555
|
}
|
|
526
556
|
});
|
|
527
|
-
}); }
|
|
557
|
+
}); }, {
|
|
558
|
+
dataProvider: dataProvider,
|
|
559
|
+
})];
|
|
528
560
|
case 3: return [2 /*return*/, _a.sent()];
|
|
529
561
|
}
|
|
530
562
|
});
|
|
@@ -533,7 +565,7 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
533
565
|
RemultServerImplementation.prototype.process = function (what) {
|
|
534
566
|
var _this = this;
|
|
535
567
|
return function (req, origRes) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
536
|
-
var genReq, myReq, myRes,
|
|
568
|
+
var genReq, myReq, myRes, err_2;
|
|
537
569
|
var _this = this;
|
|
538
570
|
return tslib_1.__generator(this, function (_a) {
|
|
539
571
|
switch (_a.label) {
|
|
@@ -548,59 +580,74 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
548
580
|
if (!genReq.params)
|
|
549
581
|
genReq.params = req['_tempParams'];
|
|
550
582
|
}
|
|
551
|
-
myReq = new
|
|
552
|
-
myRes = new
|
|
583
|
+
myReq = new RequestBridgeToDataApiRequest(genReq);
|
|
584
|
+
myRes = new ResponseBridgeToDataApiResponse(origRes, req, this.options.error);
|
|
553
585
|
_a.label = 1;
|
|
554
586
|
case 1:
|
|
555
|
-
_a.trys.push([1,
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
587
|
+
_a.trys.push([1, 6, , 7]);
|
|
588
|
+
if (!remult_static_js_1.remultStatic.asyncContext.isInInitRequest()) return [3 /*break*/, 3];
|
|
589
|
+
return [4 /*yield*/, what(remult_static_js_1.remultStatic.asyncContext.getStore().remult, myReq, myRes, genReq, origRes, req)];
|
|
590
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
591
|
+
case 3: return [4 /*yield*/, this.runWithRemult(function (remult) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
592
|
+
var user;
|
|
593
|
+
return tslib_1.__generator(this, function (_a) {
|
|
594
|
+
switch (_a.label) {
|
|
595
|
+
case 0:
|
|
596
|
+
if (!req) return [3 /*break*/, 8];
|
|
597
|
+
remult_static_js_1.remultStatic.asyncContext.setInInitRequest(true);
|
|
598
|
+
_a.label = 1;
|
|
599
|
+
case 1:
|
|
600
|
+
_a.trys.push([1, , 7, 8]);
|
|
601
|
+
user = void 0;
|
|
602
|
+
if (!this.options.getUser) return [3 /*break*/, 3];
|
|
603
|
+
return [4 /*yield*/, this.options.getUser(req)];
|
|
604
|
+
case 2:
|
|
605
|
+
user = _a.sent();
|
|
606
|
+
return [3 /*break*/, 4];
|
|
607
|
+
case 3:
|
|
608
|
+
user = req['user'];
|
|
609
|
+
if (!user)
|
|
610
|
+
user = req['auth'];
|
|
611
|
+
_a.label = 4;
|
|
612
|
+
case 4:
|
|
613
|
+
if (user)
|
|
614
|
+
remult.user = user;
|
|
615
|
+
if (!this.options.initRequest) return [3 /*break*/, 6];
|
|
616
|
+
return [4 /*yield*/, this.options.initRequest(req, {
|
|
617
|
+
remult: remult,
|
|
618
|
+
get liveQueryStorage() {
|
|
619
|
+
return remult.liveQueryStorage;
|
|
620
|
+
},
|
|
621
|
+
set liveQueryStorage(value) {
|
|
622
|
+
remult.liveQueryStorage = value;
|
|
623
|
+
},
|
|
624
|
+
})];
|
|
625
|
+
case 5:
|
|
626
|
+
_a.sent();
|
|
627
|
+
_a.label = 6;
|
|
628
|
+
case 6: return [3 /*break*/, 8];
|
|
629
|
+
case 7:
|
|
630
|
+
remult_static_js_1.remultStatic.asyncContext.setInInitRequest(false);
|
|
631
|
+
return [7 /*endfinally*/];
|
|
632
|
+
case 8: return [4 /*yield*/, what(remult, myReq, myRes, genReq, origRes, req)];
|
|
633
|
+
case 9:
|
|
634
|
+
_a.sent();
|
|
635
|
+
return [2 /*return*/];
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
}); })];
|
|
639
|
+
case 4:
|
|
597
640
|
_a.sent();
|
|
598
|
-
|
|
599
|
-
case 3
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
641
|
+
_a.label = 5;
|
|
642
|
+
case 5: return [3 /*break*/, 7];
|
|
643
|
+
case 6:
|
|
644
|
+
err_2 = _a.sent();
|
|
645
|
+
if (origRes)
|
|
646
|
+
myRes.error(err_2, undefined);
|
|
647
|
+
else
|
|
648
|
+
throw err_2;
|
|
649
|
+
return [3 /*break*/, 7];
|
|
650
|
+
case 7: return [2 /*return*/];
|
|
604
651
|
}
|
|
605
652
|
});
|
|
606
653
|
}); };
|
|
@@ -1058,42 +1105,42 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
1058
1105
|
return RemultServerImplementation;
|
|
1059
1106
|
}());
|
|
1060
1107
|
exports.RemultServerImplementation = RemultServerImplementation;
|
|
1061
|
-
var
|
|
1062
|
-
function
|
|
1108
|
+
var RequestBridgeToDataApiRequest = /** @class */ (function () {
|
|
1109
|
+
function RequestBridgeToDataApiRequest(r) {
|
|
1063
1110
|
this.r = r;
|
|
1064
1111
|
}
|
|
1065
|
-
|
|
1112
|
+
RequestBridgeToDataApiRequest.prototype.get = function (key) {
|
|
1066
1113
|
var _a;
|
|
1067
1114
|
return (_a = this.r) === null || _a === void 0 ? void 0 : _a.query[key];
|
|
1068
1115
|
};
|
|
1069
|
-
return
|
|
1116
|
+
return RequestBridgeToDataApiRequest;
|
|
1070
1117
|
}());
|
|
1071
|
-
var
|
|
1072
|
-
function
|
|
1118
|
+
var ResponseBridgeToDataApiResponse = /** @class */ (function () {
|
|
1119
|
+
function ResponseBridgeToDataApiResponse(r, req, handleError) {
|
|
1073
1120
|
this.r = r;
|
|
1074
1121
|
this.req = req;
|
|
1075
1122
|
this.handleError = handleError;
|
|
1076
1123
|
}
|
|
1077
|
-
|
|
1124
|
+
ResponseBridgeToDataApiResponse.prototype.forbidden = function () {
|
|
1078
1125
|
this.error({ message: 'Forbidden' }, undefined, 403);
|
|
1079
1126
|
};
|
|
1080
|
-
|
|
1127
|
+
ResponseBridgeToDataApiResponse.prototype.setStatus = function (status) {
|
|
1081
1128
|
return this.r.status(status);
|
|
1082
1129
|
};
|
|
1083
|
-
|
|
1084
|
-
|
|
1130
|
+
ResponseBridgeToDataApiResponse.prototype.progress = function (progress) { };
|
|
1131
|
+
ResponseBridgeToDataApiResponse.prototype.success = function (data) {
|
|
1085
1132
|
this.r.json(data);
|
|
1086
1133
|
};
|
|
1087
|
-
|
|
1134
|
+
ResponseBridgeToDataApiResponse.prototype.created = function (data) {
|
|
1088
1135
|
this.setStatus(201).json(data);
|
|
1089
1136
|
};
|
|
1090
|
-
|
|
1137
|
+
ResponseBridgeToDataApiResponse.prototype.deleted = function () {
|
|
1091
1138
|
this.setStatus(204).end();
|
|
1092
1139
|
};
|
|
1093
|
-
|
|
1140
|
+
ResponseBridgeToDataApiResponse.prototype.notFound = function () {
|
|
1094
1141
|
this.error({ message: 'NotFound' }, undefined, 404);
|
|
1095
1142
|
};
|
|
1096
|
-
|
|
1143
|
+
ResponseBridgeToDataApiResponse.prototype.error = function (exception, entity, httpStatusCode) {
|
|
1097
1144
|
var _a;
|
|
1098
1145
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1099
1146
|
var data, responseSent, sendError;
|
|
@@ -1151,7 +1198,7 @@ var ExpressResponseBridgeToDataApiResponse = /** @class */ (function () {
|
|
|
1151
1198
|
});
|
|
1152
1199
|
});
|
|
1153
1200
|
};
|
|
1154
|
-
return
|
|
1201
|
+
return ResponseBridgeToDataApiResponse;
|
|
1155
1202
|
}());
|
|
1156
1203
|
var inProcessQueueHandler = /** @class */ (function () {
|
|
1157
1204
|
function inProcessQueueHandler(storage) {
|
package/src/context.d.ts
CHANGED
|
@@ -8,9 +8,17 @@ export declare class RemultAsyncLocalStorage {
|
|
|
8
8
|
private readonly remultObjectStorage;
|
|
9
9
|
static enable(): void;
|
|
10
10
|
static disable(): void;
|
|
11
|
-
constructor(remultObjectStorage: RemultAsyncLocalStorageCore<
|
|
11
|
+
constructor(remultObjectStorage: RemultAsyncLocalStorageCore<{
|
|
12
|
+
remult: Remult;
|
|
13
|
+
inInitRequest?: boolean;
|
|
14
|
+
}>);
|
|
12
15
|
run<T>(remult: Remult, callback: (remult: Remult) => Promise<T>): Promise<T>;
|
|
13
|
-
|
|
16
|
+
isInInitRequest(): boolean;
|
|
17
|
+
setInInitRequest(val: boolean): void;
|
|
18
|
+
getStore(): {
|
|
19
|
+
remult: Remult;
|
|
20
|
+
inInitRequest?: boolean;
|
|
21
|
+
};
|
|
14
22
|
}
|
|
15
23
|
export type RemultAsyncLocalStorageCore<T> = {
|
|
16
24
|
run<R>(store: T, callback: () => Promise<R>): Promise<R>;
|
|
@@ -195,5 +203,5 @@ export interface itemChange {
|
|
|
195
203
|
}
|
|
196
204
|
export declare function doTransaction(remult: Remult, what: (dp: DataProvider) => Promise<void>): Promise<void>;
|
|
197
205
|
export declare function withRemult<T>(callback: (remult: any) => Promise<T>, options?: {
|
|
198
|
-
dataProvider?: DataProvider;
|
|
206
|
+
dataProvider?: DataProvider | Promise<DataProvider> | (() => Promise<DataProvider | undefined>);
|
|
199
207
|
}): Promise<T>;
|
package/src/context.js
CHANGED
|
@@ -11,15 +11,16 @@ var server_action_info_js_1 = require("./server-action-info.js");
|
|
|
11
11
|
var buildRestDataProvider_js_1 = require("./buildRestDataProvider.js");
|
|
12
12
|
var relationInfoMember_js_1 = require("./remult3/relationInfoMember.js");
|
|
13
13
|
var remult_static_js_1 = require("./remult-static.js");
|
|
14
|
+
var initDataProvider_1 = require("../server/initDataProvider");
|
|
14
15
|
var RemultAsyncLocalStorage = /** @class */ (function () {
|
|
15
16
|
function RemultAsyncLocalStorage(remultObjectStorage) {
|
|
16
17
|
this.remultObjectStorage = remultObjectStorage;
|
|
17
18
|
}
|
|
18
19
|
RemultAsyncLocalStorage.enable = function () {
|
|
19
20
|
remult_static_js_1.remultStatic.remultFactory = function () {
|
|
20
|
-
var r = remult_static_js_1.remultStatic.asyncContext.
|
|
21
|
+
var r = remult_static_js_1.remultStatic.asyncContext.getStore();
|
|
21
22
|
if (r)
|
|
22
|
-
return r;
|
|
23
|
+
return r.remult;
|
|
23
24
|
else
|
|
24
25
|
throw new Error('remult object was requested outside of a valid context, try running it within initApi or a remult request cycle');
|
|
25
26
|
};
|
|
@@ -31,7 +32,7 @@ var RemultAsyncLocalStorage = /** @class */ (function () {
|
|
|
31
32
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
32
33
|
return tslib_1.__generator(this, function (_a) {
|
|
33
34
|
if (this.remultObjectStorage) {
|
|
34
|
-
return [2 /*return*/, this.remultObjectStorage.run(remult, function () { return callback(remult); })];
|
|
35
|
+
return [2 /*return*/, this.remultObjectStorage.run({ remult: remult }, function () { return callback(remult); })];
|
|
35
36
|
}
|
|
36
37
|
else
|
|
37
38
|
return [2 /*return*/, callback(remult)];
|
|
@@ -39,7 +40,18 @@ var RemultAsyncLocalStorage = /** @class */ (function () {
|
|
|
39
40
|
});
|
|
40
41
|
});
|
|
41
42
|
};
|
|
42
|
-
RemultAsyncLocalStorage.prototype.
|
|
43
|
+
RemultAsyncLocalStorage.prototype.isInInitRequest = function () {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
return (_b = (_a = this.remultObjectStorage) === null || _a === void 0 ? void 0 : _a.getStore()) === null || _b === void 0 ? void 0 : _b.inInitRequest;
|
|
46
|
+
};
|
|
47
|
+
RemultAsyncLocalStorage.prototype.setInInitRequest = function (val) {
|
|
48
|
+
var _a;
|
|
49
|
+
var store = (_a = this.remultObjectStorage) === null || _a === void 0 ? void 0 : _a.getStore();
|
|
50
|
+
if (!store)
|
|
51
|
+
return;
|
|
52
|
+
store.inInitRequest = val;
|
|
53
|
+
};
|
|
54
|
+
RemultAsyncLocalStorage.prototype.getStore = function () {
|
|
43
55
|
if (!this.remultObjectStorage) {
|
|
44
56
|
throw new Error("can't use static remult in this environment, `async_hooks` were not initialized");
|
|
45
57
|
}
|
|
@@ -455,9 +467,22 @@ var transactionLiveQueryPublisher = /** @class */ (function () {
|
|
|
455
467
|
return transactionLiveQueryPublisher;
|
|
456
468
|
}());
|
|
457
469
|
function withRemult(callback, options) {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
470
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
471
|
+
var remult, _a;
|
|
472
|
+
var _this = this;
|
|
473
|
+
return tslib_1.__generator(this, function (_b) {
|
|
474
|
+
switch (_b.label) {
|
|
475
|
+
case 0:
|
|
476
|
+
remult = new Remult();
|
|
477
|
+
_a = remult;
|
|
478
|
+
return [4 /*yield*/, (0, initDataProvider_1.initDataProvider)(options === null || options === void 0 ? void 0 : options.dataProvider, true, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
479
|
+
return [2 /*return*/, remult.dataProvider];
|
|
480
|
+
}); }); })];
|
|
481
|
+
case 1:
|
|
482
|
+
_a.dataProvider = _b.sent();
|
|
483
|
+
return [2 /*return*/, remult_static_js_1.remultStatic.asyncContext.run(remult, function (r) { return callback(r); })];
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
});
|
|
462
487
|
}
|
|
463
488
|
exports.withRemult = withRemult;
|
|
@@ -6,7 +6,8 @@ export interface JsonEntityStorage {
|
|
|
6
6
|
}
|
|
7
7
|
export declare class JsonDataProvider implements DataProvider {
|
|
8
8
|
private storage;
|
|
9
|
-
|
|
9
|
+
private formatted;
|
|
10
|
+
constructor(storage: JsonEntityStorage, formatted?: boolean);
|
|
10
11
|
getEntityDataProvider(entity: EntityMetadata): EntityDataProvider;
|
|
11
12
|
transaction(action: (dataProvider: DataProvider) => Promise<void>): Promise<void>;
|
|
12
13
|
}
|
|
@@ -4,11 +4,13 @@ exports.JsonDataProvider = void 0;
|
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var array_entity_data_provider_js_1 = require("./array-entity-data-provider.js");
|
|
6
6
|
var JsonDataProvider = /** @class */ (function () {
|
|
7
|
-
function JsonDataProvider(storage) {
|
|
7
|
+
function JsonDataProvider(storage, formatted) {
|
|
8
|
+
if (formatted === void 0) { formatted = false; }
|
|
8
9
|
this.storage = storage;
|
|
10
|
+
this.formatted = formatted;
|
|
9
11
|
}
|
|
10
12
|
JsonDataProvider.prototype.getEntityDataProvider = function (entity) {
|
|
11
|
-
return new JsonEntityDataProvider(entity, this.storage);
|
|
13
|
+
return new JsonEntityDataProvider(entity, this.storage, this.formatted);
|
|
12
14
|
};
|
|
13
15
|
JsonDataProvider.prototype.transaction = function (action) {
|
|
14
16
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
@@ -26,9 +28,10 @@ var JsonDataProvider = /** @class */ (function () {
|
|
|
26
28
|
}());
|
|
27
29
|
exports.JsonDataProvider = JsonDataProvider;
|
|
28
30
|
var JsonEntityDataProvider = /** @class */ (function () {
|
|
29
|
-
function JsonEntityDataProvider(entity, helper) {
|
|
31
|
+
function JsonEntityDataProvider(entity, helper, formatted) {
|
|
30
32
|
this.entity = entity;
|
|
31
33
|
this.helper = helper;
|
|
34
|
+
this.formatted = formatted;
|
|
32
35
|
this.p = Promise.resolve();
|
|
33
36
|
}
|
|
34
37
|
JsonEntityDataProvider.prototype.loadEntityData = function (what) {
|
|
@@ -48,12 +51,14 @@ var JsonEntityDataProvider = /** @class */ (function () {
|
|
|
48
51
|
if (s)
|
|
49
52
|
data = JSON.parse(s);
|
|
50
53
|
dp = new array_entity_data_provider_js_1.ArrayEntityDataProvider(this.entity, function () { return data; });
|
|
51
|
-
return [2 /*return*/, what(dp, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
return [2 /*return*/, what(dp, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
55
|
+
return tslib_1.__generator(this, function (_a) {
|
|
56
|
+
switch (_a.label) {
|
|
57
|
+
case 0: return [4 /*yield*/, this.helper.setItem(dbName, JSON.stringify(data, undefined, this.formatted ? 2 : undefined))];
|
|
58
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}); })];
|
|
57
62
|
}
|
|
58
63
|
});
|
|
59
64
|
});
|
package/src/remult-static.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ClassType } from '../classType.js';
|
|
2
2
|
import type { ClassHelper, Remult, RemultAsyncLocalStorage } from './context.js';
|
|
3
|
+
import { DataProvider } from './data-interfaces';
|
|
3
4
|
import type { columnInfo } from './remult3/columnInfo.js';
|
|
4
5
|
export declare const remultStatic: {
|
|
5
6
|
defaultRemultFactory: () => Remult;
|
|
@@ -19,6 +20,7 @@ export declare const remultStatic: {
|
|
|
19
20
|
};
|
|
20
21
|
};
|
|
21
22
|
captionTransformer: any;
|
|
23
|
+
defaultDataProvider: () => Promise<DataProvider>;
|
|
22
24
|
};
|
|
23
25
|
export declare function defaultFactory(): Remult;
|
|
24
26
|
export declare function resetFactory(): void;
|
package/src/remult-static.js
CHANGED
package/src/remult3/remult3.js
CHANGED
|
@@ -4,14 +4,17 @@ exports.flags = void 0;
|
|
|
4
4
|
exports.flags = {
|
|
5
5
|
error500RetryCount: 4,
|
|
6
6
|
};
|
|
7
|
-
//y2 - soft-delete-discussion https://discord.com/channels/975754286384418847/1230386433093533698/1230386433093533698
|
|
8
7
|
//y1 - live query with count #436
|
|
8
|
+
//y1 - https://github.com/remult/remult/discussions/438
|
|
9
|
+
//p1 - discuss next auth withRemult paradox
|
|
10
|
+
//p1 - maybe the default withRemult should by default use the data provider set by the remultExpress
|
|
11
|
+
//p1 - withRemult to support the full range of data provider.
|
|
9
12
|
//y1 TODO - In the esm version of our tutorial - the imports are automatically .ts and not .js in react and not in vue
|
|
10
13
|
//y1 TODO - consider id to also support keyof (id:['company','index']) - had problem with | (keyof Partial<entityType>)[] & `entity`
|
|
11
14
|
//y1 TODO - readonly key: keyof MembersOnly<entityType> & string
|
|
12
15
|
//y1 - talk about insert / update / delete with relations
|
|
13
16
|
/*
|
|
14
|
-
|
|
17
|
+
repo(Order).insert({},{
|
|
15
18
|
relations:{
|
|
16
19
|
orderItems:[{},{},{}]
|
|
17
20
|
}
|
|
@@ -19,14 +22,16 @@ exports.flags = {
|
|
|
19
22
|
*/
|
|
20
23
|
//y1 - repo batch - for multiple operations:
|
|
21
24
|
/*
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
const result = await repo.batch(x=>({
|
|
26
|
+
data:x.find(),
|
|
27
|
+
count:x.count()
|
|
28
|
+
}))
|
|
26
29
|
*/
|
|
30
|
+
//p1 - consider in json storage, to store the json without spaces
|
|
27
31
|
//p1 - consider upsert (where,set)
|
|
28
32
|
//y1 - wait a second to close stream -see pr
|
|
29
33
|
//p1 - Consider enforcing serial operations on JSON database to prevent data loss
|
|
34
|
+
//y2 - soft-delete-discussion https://discord.com/channels/975754286384418847/1230386433093533698/1230386433093533698
|
|
30
35
|
//p1 - prepare the createEntity discussion
|
|
31
36
|
//p1 - return error on connection error
|
|
32
37
|
//p1 - article on displayValue including it's definition for entities that is used in relations
|