remult 0.23.5 → 0.24.0-exp.2
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/SseSubscriptionServer.d.ts +3 -3
- package/SseSubscriptionServer.js +2 -2
- package/ably.d.ts +3 -3
- package/esm/SseSubscriptionServer.js +1 -1
- package/esm/graphql.js +3 -3
- package/esm/index.js +24 -24
- package/esm/internals.js +5 -5
- package/esm/live-query/data-provider-live-query-storage.js +5 -5
- package/esm/package.json +3 -0
- package/esm/postgres/index.d.ts +2 -2
- package/esm/postgres/index.js +2 -2
- package/esm/postgres/postgres-data-provider.d.ts +17 -6
- package/esm/postgres/postgres-data-provider.js +51 -10
- package/esm/postgres/schema-builder.js +10 -10
- package/esm/remult-express.js +2 -2
- package/esm/remult-fastify.js +2 -2
- package/esm/remult-fresh.js +1 -1
- package/esm/remult-hapi.js +2 -3
- package/esm/remult-knex/index.js +20 -11
- package/esm/remult-mongo.js +6 -6
- package/esm/remult-next.js +2 -2
- package/esm/remult-nuxt.js +49 -0
- package/esm/remult-sveltekit.js +2 -2
- package/esm/server/JsonEntityFileStorage.js +1 -1
- package/esm/server/core.js +4 -4
- package/esm/server/expressBridge.js +23 -23
- package/esm/server/index.js +5 -5
- package/esm/server/initAsyncHooks.js +1 -1
- package/esm/server/initDataProvider.js +1 -1
- package/esm/src/buildRestDataProvider.js +1 -1
- package/esm/src/column-interfaces.d.ts +2 -1
- package/esm/src/column.js +2 -2
- package/esm/src/context.js +26 -20
- package/esm/src/data-api.d.ts +0 -1
- package/esm/src/data-api.js +5 -5
- package/esm/src/data-interfaces.js +1 -1
- package/esm/src/data-providers/array-entity-data-provider.js +3 -3
- package/esm/src/data-providers/in-memory-database.js +1 -1
- package/esm/src/data-providers/json-data-provider.js +2 -2
- package/esm/src/data-providers/rest-data-provider.js +6 -6
- package/esm/src/data-providers/sql-database.d.ts +3 -2
- package/esm/src/data-providers/sql-database.js +22 -15
- package/esm/src/data-providers/web-sql-data-provider.js +3 -3
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.d.ts +4 -2
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +44 -6
- package/esm/src/filter/filter-interfaces.d.ts +1 -1
- package/esm/src/filter/filter-interfaces.js +3 -3
- package/esm/src/live-query/LiveQueryClient.js +5 -5
- package/esm/src/live-query/SseSubscriptionClient.js +10 -7
- package/esm/src/live-query/SubscriptionChannel.js +3 -3
- package/esm/src/live-query/SubscriptionServer.js +1 -1
- package/esm/src/remult-proxy.js +1 -1
- package/esm/src/remult3/Fields.js +8 -4
- package/esm/src/remult3/IdEntity.js +2 -2
- package/esm/src/remult3/RepositoryImplementation.d.ts +2 -4
- package/esm/src/remult3/RepositoryImplementation.js +78 -92
- package/esm/src/remult3/__updateEntityBasedOnWhere.js +1 -1
- package/esm/src/remult3/entity.js +2 -2
- package/esm/src/remult3/relation-loader.js +3 -3
- package/esm/src/remult3/remult3.d.ts +2 -1
- package/esm/src/remult3/remult3.js +23 -20
- package/esm/src/resultCompoundIdFilter.js +1 -1
- package/esm/src/server-action.js +8 -8
- package/esm/src/sort.js +2 -2
- package/esm/src/sql-command.d.ts +1 -0
- package/esm/src/validators.js +1 -1
- package/esm/src/valueConverters.js +1 -1
- package/graphql.d.ts +2 -2
- package/graphql.js +7 -7
- package/index.d.ts +32 -32
- package/index.js +65 -64
- package/internals.d.ts +7 -7
- package/internals.js +12 -12
- package/live-query/data-provider-live-query-storage.d.ts +4 -4
- package/live-query/data-provider-live-query-storage.js +14 -14
- package/package.json +53 -88
- package/postgres/index.d.ts +2 -2
- package/postgres/index.js +9 -3
- package/postgres/postgres-data-provider.d.ts +23 -11
- package/postgres/postgres-data-provider.js +92 -20
- package/postgres/schema-builder.d.ts +4 -4
- package/postgres/schema-builder.js +17 -17
- package/remult-express.d.ts +2 -2
- package/remult-express.js +3 -3
- package/remult-fastify.d.ts +2 -2
- package/remult-fastify.js +3 -3
- package/remult-fresh.d.ts +1 -1
- package/remult-fresh.js +2 -2
- package/remult-hapi.d.ts +2 -2
- package/remult-hapi.js +3 -4
- package/remult-knex/index.d.ts +5 -5
- package/remult-knex/index.js +53 -41
- package/remult-mongo.d.ts +2 -2
- package/remult-mongo.js +16 -16
- package/remult-next.d.ts +1 -1
- package/remult-next.js +4 -4
- package/remult-nuxt.d.ts +6 -0
- package/remult-nuxt.js +74 -0
- package/remult-sveltekit.d.ts +2 -2
- package/remult-sveltekit.js +3 -3
- package/server/JsonEntityFileStorage.d.ts +2 -2
- package/server/JsonEntityFileStorage.js +2 -2
- package/server/core.d.ts +4 -4
- package/server/core.js +9 -9
- package/server/expressBridge.d.ts +9 -9
- package/server/expressBridge.js +70 -77
- package/server/index.d.ts +5 -5
- package/server/index.js +11 -11
- package/server/initAsyncHooks.js +2 -2
- package/server/initDataProvider.d.ts +1 -1
- package/server/initDataProvider.js +1 -1
- package/src/CompoundIdField.d.ts +3 -3
- package/src/buildRestDataProvider.d.ts +1 -1
- package/src/buildRestDataProvider.js +3 -3
- package/src/column-interfaces.d.ts +14 -7
- package/src/column.d.ts +1 -1
- package/src/column.js +6 -6
- package/src/context.d.ts +11 -10
- package/src/context.js +52 -32
- package/src/data-api.d.ts +3 -3
- package/src/data-api.js +18 -18
- package/src/data-interfaces.d.ts +3 -3
- package/src/data-interfaces.js +2 -2
- package/src/data-providers/array-entity-data-provider.js +9 -9
- package/src/data-providers/in-memory-database.d.ts +3 -3
- package/src/data-providers/in-memory-database.js +2 -2
- package/src/data-providers/json-data-provider.d.ts +2 -2
- package/src/data-providers/json-data-provider.js +3 -3
- package/src/data-providers/rest-data-provider.d.ts +5 -5
- package/src/data-providers/rest-data-provider.js +19 -19
- package/src/data-providers/sql-database.d.ts +8 -7
- package/src/data-providers/sql-database.js +56 -41
- package/src/data-providers/web-sql-data-provider.d.ts +4 -4
- package/src/data-providers/web-sql-data-provider.js +10 -10
- package/src/entity.d.ts +3 -3
- package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +8 -6
- package/src/filter/filter-consumer-bridge-to-sql-request.js +70 -9
- package/src/filter/filter-interfaces.d.ts +3 -3
- package/src/filter/filter-interfaces.js +9 -9
- package/src/live-query/LiveQueryClient.js +9 -9
- package/src/live-query/SseSubscriptionClient.d.ts +2 -1
- package/src/live-query/SseSubscriptionClient.js +15 -12
- package/src/live-query/SubscriptionChannel.d.ts +1 -1
- package/src/live-query/SubscriptionChannel.js +8 -8
- package/src/live-query/SubscriptionServer.js +2 -2
- package/src/remult-proxy.d.ts +1 -1
- package/src/remult-proxy.js +3 -3
- package/src/remult3/Fields.d.ts +6 -6
- package/src/remult3/Fields.js +17 -13
- package/src/remult3/IdEntity.d.ts +1 -1
- package/src/remult3/IdEntity.js +4 -4
- package/src/remult3/RepositoryImplementation.d.ts +48 -18
- package/src/remult3/RepositoryImplementation.js +172 -191
- package/src/remult3/__updateEntityBasedOnWhere.d.ts +1 -1
- package/src/remult3/__updateEntityBasedOnWhere.js +2 -2
- package/src/remult3/columnInfo.d.ts +2 -2
- package/src/remult3/entity.d.ts +3 -3
- package/src/remult3/entity.js +7 -7
- package/src/remult3/getEntityRef.d.ts +3 -3
- package/src/remult3/relation-loader-types.d.ts +2 -2
- package/src/remult3/relation-loader.d.ts +2 -2
- package/src/remult3/relation-loader.js +6 -6
- package/src/remult3/relationInfoMember.d.ts +2 -2
- package/src/remult3/remult3.d.ts +22 -9
- package/src/remult3/remult3.js +23 -20
- package/src/remult3/repository-internals.d.ts +3 -3
- package/src/resultCompoundIdFilter.d.ts +2 -2
- package/src/resultCompoundIdFilter.js +2 -2
- package/src/server-action.d.ts +4 -4
- package/src/server-action.js +40 -40
- package/src/sort.d.ts +2 -2
- package/src/sort.js +5 -5
- package/src/sql-command.d.ts +2 -1
- package/src/validators.d.ts +1 -1
- package/src/validators.js +2 -2
- package/src/valueConverters.d.ts +1 -1
- package/src/valueConverters.js +4 -4
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import { SseSubscriptionServer } from '../SseSubscriptionServer';
|
|
3
|
-
import { Remult, RemultAsyncLocalStorage, allEntities } from '../src/context';
|
|
4
|
-
import { DataApi, serializeError } from '../src/data-api';
|
|
5
|
-
import { liveQueryKeepAliveRoute, streamUrl, } from '../src/live-query/SubscriptionChannel';
|
|
6
|
-
import { InMemoryLiveQueryStorage, LiveQueryPublisher, } from '../src/live-query/SubscriptionServer';
|
|
7
|
-
import { IdEntity } from '../src/remult3/IdEntity';
|
|
8
|
-
import { Fields } from '../src/remult3/Fields';
|
|
9
|
-
import { Entity } from '../src/remult3/entity';
|
|
10
|
-
import { getEntityKey } from '../src/remult3/getEntityRef';
|
|
11
|
-
import { Action, classBackendMethodsArray } from '../src/server-action';
|
|
12
|
-
import { actionInfo, serverActionField } from '../src/server-action-info';
|
|
13
|
-
import { initDataProvider } from './initDataProvider';
|
|
2
|
+
import { SseSubscriptionServer } from '../SseSubscriptionServer.js';
|
|
3
|
+
import { Remult, RemultAsyncLocalStorage, allEntities, withRemult, } from '../src/context.js';
|
|
4
|
+
import { DataApi, serializeError } from '../src/data-api.js';
|
|
5
|
+
import { liveQueryKeepAliveRoute, streamUrl, } from '../src/live-query/SubscriptionChannel.js';
|
|
6
|
+
import { InMemoryLiveQueryStorage, LiveQueryPublisher, } from '../src/live-query/SubscriptionServer.js';
|
|
7
|
+
import { IdEntity } from '../src/remult3/IdEntity.js';
|
|
8
|
+
import { Fields } from '../src/remult3/Fields.js';
|
|
9
|
+
import { Entity } from '../src/remult3/entity.js';
|
|
10
|
+
import { getEntityKey } from '../src/remult3/getEntityRef.js';
|
|
11
|
+
import { Action, classBackendMethodsArray } from '../src/server-action.js';
|
|
12
|
+
import { actionInfo, serverActionField } from '../src/server-action-info.js';
|
|
13
|
+
import { initDataProvider } from './initDataProvider.js';
|
|
14
14
|
export function createRemultServerCore(options, serverCoreOptions) {
|
|
15
15
|
if (!options) {
|
|
16
16
|
options = {};
|
|
@@ -98,7 +98,9 @@ export class RemultServerImplementation {
|
|
|
98
98
|
return dp;
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
|
-
|
|
101
|
+
withRemultAsync(request, what) {
|
|
102
|
+
if (!request)
|
|
103
|
+
return this.runWithRemult(what);
|
|
102
104
|
return new Promise((resolve, error) => {
|
|
103
105
|
return this.withRemult(request, undefined, () => {
|
|
104
106
|
try {
|
|
@@ -246,16 +248,14 @@ export class RemultServerImplementation {
|
|
|
246
248
|
}
|
|
247
249
|
//runs with remult but without init request
|
|
248
250
|
async runWithRemult(what, options) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
res(await what(remult));
|
|
258
|
-
});
|
|
251
|
+
return await withRemult(async (remult) => {
|
|
252
|
+
var x = remult;
|
|
253
|
+
x.liveQueryPublisher = new LiveQueryPublisher(() => remult.subscriptionServer, () => remult.liveQueryStorage, this.runWithSerializedJsonContextData);
|
|
254
|
+
if (!options?.skipDataProvider)
|
|
255
|
+
x.dataProvider = await this.dataProvider;
|
|
256
|
+
x.subscriptionServer = this.subscriptionServer;
|
|
257
|
+
x.liveQueryStorage = this.liveQueryStorage;
|
|
258
|
+
return await what(x);
|
|
259
259
|
});
|
|
260
260
|
}
|
|
261
261
|
process(what) {
|
package/esm/server/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { createRemultServerCore } from './expressBridge';
|
|
2
|
-
import { initAsyncHooks } from './initAsyncHooks';
|
|
3
|
-
export { SseSubscriptionServer } from '../SseSubscriptionServer';
|
|
4
|
-
export { DataProviderLiveQueryStorage } from '../live-query/data-provider-live-query-storage';
|
|
5
|
-
export { JsonEntityFileStorage, JsonFileDataProvider, } from './JsonEntityFileStorage';
|
|
1
|
+
import { createRemultServerCore } from './expressBridge.js';
|
|
2
|
+
import { initAsyncHooks } from './initAsyncHooks.js';
|
|
3
|
+
export { SseSubscriptionServer } from '../SseSubscriptionServer.js';
|
|
4
|
+
export { DataProviderLiveQueryStorage } from '../live-query/data-provider-live-query-storage.js';
|
|
5
|
+
export { JsonEntityFileStorage, JsonFileDataProvider, } from './JsonEntityFileStorage.js';
|
|
6
6
|
export function createRemultServer(options, serverCoreOptions) {
|
|
7
7
|
initAsyncHooks();
|
|
8
8
|
return createRemultServerCore(options, serverCoreOptions || {
|
|
@@ -8,7 +8,7 @@ export function initDataProvider(optionsDataProvider) {
|
|
|
8
8
|
dataProvider = dataProvider.then(async (dp) => {
|
|
9
9
|
if (dp)
|
|
10
10
|
return dp;
|
|
11
|
-
return new (await import('./JsonEntityFileStorage')).JsonFileDataProvider('./db');
|
|
11
|
+
return new (await import('./JsonEntityFileStorage.js')).JsonFileDataProvider('./db');
|
|
12
12
|
});
|
|
13
13
|
return dataProvider;
|
|
14
14
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RestDataProviderHttpProviderUsingFetch } from './data-providers/rest-data-provider';
|
|
1
|
+
import { RestDataProviderHttpProviderUsingFetch } from './data-providers/rest-data-provider.js';
|
|
2
2
|
export function buildRestDataProvider(provider) {
|
|
3
3
|
if (!provider)
|
|
4
4
|
return new RestDataProviderHttpProviderUsingFetch();
|
|
@@ -120,7 +120,8 @@ export interface FieldMetadata<valueType = any, entityType = any> {
|
|
|
120
120
|
* Task == taskRepo.metadata.fields.title.target //will return true
|
|
121
121
|
*/
|
|
122
122
|
readonly target: ClassType<valueType>;
|
|
123
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* @deprecated Returns the dbName - based on it's `dbName` option and it's `sqlExpression` option */
|
|
124
125
|
getDbName(): Promise<string>;
|
|
125
126
|
/** Indicates if this field is based on a server express */
|
|
126
127
|
readonly isServerExpression: boolean;
|
package/esm/src/column.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getEntityRef } from './remult3/getEntityRef';
|
|
2
|
-
import { getRepositoryInternals } from './remult3/repository-internals';
|
|
1
|
+
import { getEntityRef } from './remult3/getEntityRef.js';
|
|
2
|
+
import { getRepositoryInternals } from './remult3/repository-internals.js';
|
|
3
3
|
export function makeTitle(name) {
|
|
4
4
|
// insert a space before all caps
|
|
5
5
|
return (name
|
package/esm/src/context.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { RestDataProvider } from './data-providers/rest-data-provider';
|
|
2
|
-
import { LiveQueryClient } from './live-query/LiveQueryClient';
|
|
3
|
-
import { SseSubscriptionClient } from './live-query/SseSubscriptionClient';
|
|
4
|
-
import { RemultProxy, remult } from './remult-proxy';
|
|
5
|
-
import { RepositoryImplementation, createOldEntity, } from './remult3/RepositoryImplementation';
|
|
6
|
-
import { actionInfo, serverActionField } from './server-action-info';
|
|
7
|
-
import { buildRestDataProvider, isExternalHttpProvider, } from './buildRestDataProvider';
|
|
1
|
+
import { RestDataProvider } from './data-providers/rest-data-provider.js';
|
|
2
|
+
import { LiveQueryClient } from './live-query/LiveQueryClient.js';
|
|
3
|
+
import { SseSubscriptionClient } from './live-query/SseSubscriptionClient.js';
|
|
4
|
+
import { RemultProxy, remult } from './remult-proxy.js';
|
|
5
|
+
import { RepositoryImplementation, createOldEntity, } from './remult3/RepositoryImplementation.js';
|
|
6
|
+
import { actionInfo, serverActionField } from './server-action-info.js';
|
|
7
|
+
import { buildRestDataProvider, isExternalHttpProvider, } from './buildRestDataProvider.js';
|
|
8
8
|
export class RemultAsyncLocalStorage {
|
|
9
9
|
remultObjectStorage;
|
|
10
10
|
static enable() {
|
|
@@ -26,9 +26,9 @@ export class RemultAsyncLocalStorage {
|
|
|
26
26
|
}
|
|
27
27
|
run(remult, callback) {
|
|
28
28
|
if (this.remultObjectStorage)
|
|
29
|
-
this.remultObjectStorage.run(remult, callback);
|
|
29
|
+
this.remultObjectStorage.run(remult, () => callback(remult));
|
|
30
30
|
else
|
|
31
|
-
callback();
|
|
31
|
+
callback(remult);
|
|
32
32
|
}
|
|
33
33
|
getRemult() {
|
|
34
34
|
if (!this.remultObjectStorage) {
|
|
@@ -140,7 +140,6 @@ export class Remult {
|
|
|
140
140
|
this.apiClient.wrapMessageHandling = apiClient.wrapMessageHandling;
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
-
/* @internal*/
|
|
144
143
|
liveQueryStorage;
|
|
145
144
|
subscriptionServer;
|
|
146
145
|
/* @internal*/
|
|
@@ -178,16 +177,6 @@ export class Remult {
|
|
|
178
177
|
url: '/api',
|
|
179
178
|
subscriptionClient: new SseSubscriptionClient(),
|
|
180
179
|
};
|
|
181
|
-
static run(callback, options) {
|
|
182
|
-
const remult = new Remult();
|
|
183
|
-
if (options.dataProvider)
|
|
184
|
-
remult.dataProvider = options.dataProvider;
|
|
185
|
-
let r;
|
|
186
|
-
RemultAsyncLocalStorage.instance.run(remult, () => {
|
|
187
|
-
r = callback();
|
|
188
|
-
});
|
|
189
|
-
return r;
|
|
190
|
-
}
|
|
191
180
|
}
|
|
192
181
|
RemultProxy.defaultRemultFactory = () => new Remult();
|
|
193
182
|
export const allEntities = [];
|
|
@@ -286,3 +275,20 @@ class transactionLiveQueryPublisher {
|
|
|
286
275
|
}
|
|
287
276
|
}
|
|
288
277
|
}
|
|
278
|
+
export function withRemult(callback, options) {
|
|
279
|
+
const remult = new Remult();
|
|
280
|
+
if (options?.dataProvider)
|
|
281
|
+
remult.dataProvider = options.dataProvider;
|
|
282
|
+
let r;
|
|
283
|
+
RemultAsyncLocalStorage.instance.run(remult, () => {
|
|
284
|
+
r = new Promise(async (res, rej) => {
|
|
285
|
+
try {
|
|
286
|
+
res(await callback(remult));
|
|
287
|
+
}
|
|
288
|
+
catch (err) {
|
|
289
|
+
rej(err);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
return r;
|
|
294
|
+
}
|
package/esm/src/data-api.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ export declare class DataApi<T = any> {
|
|
|
14
14
|
r: any[];
|
|
15
15
|
findOptions: FindOptions<T>;
|
|
16
16
|
}>;
|
|
17
|
-
private includeNone;
|
|
18
17
|
getArray(response: DataApiResponse, request: DataApiRequest, filterBody?: any): Promise<void>;
|
|
19
18
|
liveQuery(response: DataApiResponse, request: DataApiRequest, filterBody: any, serializeContext: () => Promise<any>, queryChannel: string): Promise<void>;
|
|
20
19
|
private buildWhere;
|
package/esm/src/data-api.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { getRelationInfo } from '../internals';
|
|
2
|
-
import { doTransaction } from './context';
|
|
3
|
-
import { findOptionsToJson, liveQueryAction, } from './data-providers/rest-data-provider';
|
|
4
|
-
import { Filter, buildFilterFromRequestParameters, customUrlToken, } from './filter/filter-interfaces';
|
|
5
|
-
import { ForbiddenError } from './server-action';
|
|
1
|
+
import { getRelationInfo } from '../internals.js';
|
|
2
|
+
import { doTransaction } from './context.js';
|
|
3
|
+
import { findOptionsToJson, liveQueryAction, } from './data-providers/rest-data-provider.js';
|
|
4
|
+
import { Filter, buildFilterFromRequestParameters, customUrlToken, } from './filter/filter-interfaces.js';
|
|
5
|
+
import { ForbiddenError } from './server-action.js';
|
|
6
6
|
export class DataApi {
|
|
7
7
|
repository;
|
|
8
8
|
remult;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CompoundIdField } from '../CompoundIdField';
|
|
2
|
-
import { dbNamesOf, isDbReadonly, } from '../filter/filter-consumer-bridge-to-sql-request';
|
|
3
|
-
import { Filter, customDatabaseFilterToken } from '../filter/filter-interfaces';
|
|
1
|
+
import { CompoundIdField } from '../CompoundIdField.js';
|
|
2
|
+
import { dbNamesOf, isDbReadonly, } from '../filter/filter-consumer-bridge-to-sql-request.js';
|
|
3
|
+
import { Filter, customDatabaseFilterToken, } from '../filter/filter-interfaces.js';
|
|
4
4
|
//@internal
|
|
5
5
|
export class ArrayEntityDataProvider {
|
|
6
6
|
entity;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ArrayEntityDataProvider } from './array-entity-data-provider';
|
|
1
|
+
import { ArrayEntityDataProvider } from './array-entity-data-provider.js';
|
|
2
2
|
export class JsonDataProvider {
|
|
3
3
|
storage;
|
|
4
4
|
constructor(storage) {
|
|
@@ -20,7 +20,7 @@ class JsonEntityDataProvider {
|
|
|
20
20
|
}
|
|
21
21
|
async loadEntityData(what) {
|
|
22
22
|
let data = [];
|
|
23
|
-
let dbName = await this.entity.
|
|
23
|
+
let dbName = await this.entity.options.dbName;
|
|
24
24
|
let s = this.helper.getItem(dbName);
|
|
25
25
|
if (s)
|
|
26
26
|
data = JSON.parse(s);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { UrlBuilder } from '../../urlBuilder';
|
|
2
|
-
import { buildRestDataProvider, retry } from '../buildRestDataProvider';
|
|
3
|
-
import { Remult } from '../context';
|
|
4
|
-
import { customUrlToken, Filter } from '../filter/filter-interfaces';
|
|
5
|
-
import { actionInfo } from '../server-action-info';
|
|
6
|
-
import { getRelationInfo } from '../remult3/relationInfoMember';
|
|
1
|
+
import { UrlBuilder } from '../../urlBuilder.js';
|
|
2
|
+
import { buildRestDataProvider, retry } from '../buildRestDataProvider.js';
|
|
3
|
+
import { Remult } from '../context.js';
|
|
4
|
+
import { customUrlToken, Filter } from '../filter/filter-interfaces.js';
|
|
5
|
+
import { actionInfo } from '../server-action-info.js';
|
|
6
|
+
import { getRelationInfo } from '../remult3/relationInfoMember.js';
|
|
7
7
|
export class RestDataProvider {
|
|
8
8
|
apiProvider;
|
|
9
9
|
constructor(apiProvider) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DataProvider, EntityDataProvider } from '../data-interfaces';
|
|
2
2
|
import type { SqlCommand, SqlCommandWithParameters, SqlImplementation, SqlResult } from '../sql-command';
|
|
3
3
|
import type { Remult } from '../context';
|
|
4
|
-
import type { CustomSqlFilterBuilderFunction } from '../filter/filter-consumer-bridge-to-sql-request';
|
|
4
|
+
import type { CustomSqlFilterBuilderFunction, EntityDbNamesBase } from '../filter/filter-consumer-bridge-to-sql-request';
|
|
5
5
|
import type { EntityFilter, EntityMetadata } from '../remult3/remult3';
|
|
6
6
|
import type { RepositoryOverloads } from '../remult3/RepositoryImplementation';
|
|
7
7
|
export declare class SqlDatabase implements DataProvider {
|
|
@@ -9,11 +9,12 @@ export declare class SqlDatabase implements DataProvider {
|
|
|
9
9
|
static getDb(remult?: Remult): SqlDatabase;
|
|
10
10
|
createCommand(): SqlCommand;
|
|
11
11
|
execute(sql: string): Promise<SqlResult>;
|
|
12
|
+
wrapIdentifier: (name: string) => string;
|
|
12
13
|
ensureSchema(entities: EntityMetadata<any>[]): Promise<void>;
|
|
13
14
|
getEntityDataProvider(entity: EntityMetadata): EntityDataProvider;
|
|
14
15
|
transaction(action: (dataProvider: DataProvider) => Promise<void>): Promise<void>;
|
|
15
16
|
static rawFilter(build: CustomSqlFilterBuilderFunction): EntityFilter<any>;
|
|
16
|
-
static filterToRaw<entityType>(repo: RepositoryOverloads<entityType>, condition: EntityFilter<entityType>, sqlCommand?: SqlCommandWithParameters): Promise<string>;
|
|
17
|
+
static filterToRaw<entityType>(repo: RepositoryOverloads<entityType>, condition: EntityFilter<entityType>, sqlCommand?: SqlCommandWithParameters, dbNames?: EntityDbNamesBase): Promise<string>;
|
|
17
18
|
/**
|
|
18
19
|
* `false` _(default)_ - No logging
|
|
19
20
|
*
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { CompoundIdField } from '../CompoundIdField';
|
|
2
|
-
import { FilterConsumerBridgeToSqlRequest, dbNamesOf, isDbReadonly, } from '../filter/filter-consumer-bridge-to-sql-request';
|
|
3
|
-
import { Filter, customDatabaseFilterToken } from '../filter/filter-interfaces';
|
|
4
|
-
import { remult as defaultRemult } from '../remult-proxy';
|
|
5
|
-
import { getRepository } from '../remult3/RepositoryImplementation';
|
|
6
|
-
import { Sort } from '../sort';
|
|
7
|
-
import { ValueConverters } from '../valueConverters';
|
|
8
|
-
import { getRepositoryInternals } from '../remult3/repository-internals';
|
|
1
|
+
import { CompoundIdField } from '../CompoundIdField.js';
|
|
2
|
+
import { FilterConsumerBridgeToSqlRequest, dbNamesOf, isDbReadonly, } from '../filter/filter-consumer-bridge-to-sql-request.js';
|
|
3
|
+
import { Filter, customDatabaseFilterToken, } from '../filter/filter-interfaces.js';
|
|
4
|
+
import { remult as defaultRemult } from '../remult-proxy.js';
|
|
5
|
+
import { getRepository } from '../remult3/RepositoryImplementation.js';
|
|
6
|
+
import { Sort } from '../sort.js';
|
|
7
|
+
import { ValueConverters } from '../valueConverters.js';
|
|
8
|
+
import { getRepositoryInternals } from '../remult3/repository-internals.js';
|
|
9
9
|
// @dynamic
|
|
10
10
|
export class SqlDatabase {
|
|
11
11
|
sql;
|
|
@@ -21,6 +21,7 @@ export class SqlDatabase {
|
|
|
21
21
|
async execute(sql) {
|
|
22
22
|
return await this.createCommand().execute(sql);
|
|
23
23
|
}
|
|
24
|
+
wrapIdentifier = (x) => x;
|
|
24
25
|
/* @internal*/
|
|
25
26
|
_getSourceSql() {
|
|
26
27
|
return this.sql;
|
|
@@ -69,6 +70,7 @@ export class SqlDatabase {
|
|
|
69
70
|
entityIsUsedForTheFirstTime: (y) => x.entityIsUsedForTheFirstTime(y),
|
|
70
71
|
transaction: (z) => x.transaction(z),
|
|
71
72
|
supportsJsonColumnType: this.sql.supportsJsonColumnType,
|
|
73
|
+
wrapIdentifier: this.wrapIdentifier,
|
|
72
74
|
}));
|
|
73
75
|
}
|
|
74
76
|
finally {
|
|
@@ -83,12 +85,12 @@ export class SqlDatabase {
|
|
|
83
85
|
},
|
|
84
86
|
};
|
|
85
87
|
}
|
|
86
|
-
static async filterToRaw(repo, condition, sqlCommand) {
|
|
88
|
+
static async filterToRaw(repo, condition, sqlCommand, dbNames) {
|
|
87
89
|
if (!sqlCommand) {
|
|
88
90
|
sqlCommand = new myDummySQLCommand();
|
|
89
91
|
}
|
|
90
92
|
const r = getRepository(repo);
|
|
91
|
-
var b = new FilterConsumerBridgeToSqlRequest(sqlCommand, await dbNamesOf(r.metadata));
|
|
93
|
+
var b = new FilterConsumerBridgeToSqlRequest(sqlCommand, dbNames || (await dbNamesOf(r.metadata)));
|
|
92
94
|
b._addWhere = false;
|
|
93
95
|
await (await getRepositoryInternals(r).translateWhereToFilter(condition)).__applyToConsumer(b);
|
|
94
96
|
return await b.resolveWhere();
|
|
@@ -109,6 +111,8 @@ export class SqlDatabase {
|
|
|
109
111
|
static durationThreshold = 0;
|
|
110
112
|
constructor(sql) {
|
|
111
113
|
this.sql = sql;
|
|
114
|
+
if (sql.wrapIdentifier)
|
|
115
|
+
this.wrapIdentifier = (x) => sql.wrapIdentifier(x);
|
|
112
116
|
}
|
|
113
117
|
createdEntities = [];
|
|
114
118
|
}
|
|
@@ -159,14 +163,17 @@ class LogSQLCommand {
|
|
|
159
163
|
this.logToConsole(duration, sql, this.args);
|
|
160
164
|
}
|
|
161
165
|
else {
|
|
162
|
-
console.info(
|
|
166
|
+
console.info(sql + '\n', { arguments: this.args, duration });
|
|
163
167
|
}
|
|
164
168
|
}
|
|
165
169
|
}
|
|
166
170
|
return r;
|
|
167
171
|
}
|
|
168
172
|
catch (err) {
|
|
169
|
-
console.error(
|
|
173
|
+
console.error((err.message || 'Sql Error') + ':\n', sql, {
|
|
174
|
+
arguments: this.args,
|
|
175
|
+
error: err,
|
|
176
|
+
});
|
|
170
177
|
throw err;
|
|
171
178
|
}
|
|
172
179
|
}
|
|
@@ -184,7 +191,7 @@ class ActualSQLServerDataProvider {
|
|
|
184
191
|
this.strategy = strategy;
|
|
185
192
|
}
|
|
186
193
|
async init() {
|
|
187
|
-
let dbNameProvider = await dbNamesOf(this.entity);
|
|
194
|
+
let dbNameProvider = await dbNamesOf(this.entity, (x) => this.sql.wrapIdentifier(x));
|
|
188
195
|
await this.iAmUsed(dbNameProvider);
|
|
189
196
|
return dbNameProvider;
|
|
190
197
|
}
|
|
@@ -386,9 +393,9 @@ async function bulkInsert(array, db) {
|
|
|
386
393
|
// do whatever
|
|
387
394
|
const c = db.createCommand();
|
|
388
395
|
let sql = 'insert into ' +
|
|
389
|
-
(await items[0]._.metadata.
|
|
396
|
+
(await items[0]._.metadata.options.dbName) +
|
|
390
397
|
' (' +
|
|
391
|
-
(await Promise.all(items[0]._.metadata.fields.toArray().map((f) => f.
|
|
398
|
+
(await Promise.all(items[0]._.metadata.fields.toArray().map((f) => f.options.dbName))).join(',') +
|
|
392
399
|
') values ';
|
|
393
400
|
sql += items
|
|
394
401
|
.map((row) => '(' +
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { dbNamesOf, isDbReadonly, } from '../filter/filter-consumer-bridge-to-sql-request';
|
|
2
|
-
import { isAutoIncrement } from '../remult3/RepositoryImplementation';
|
|
3
|
-
import { SqlDatabase } from './sql-database';
|
|
1
|
+
import { dbNamesOf, isDbReadonly, } from '../filter/filter-consumer-bridge-to-sql-request.js';
|
|
2
|
+
import { isAutoIncrement } from '../remult3/RepositoryImplementation.js';
|
|
3
|
+
import { SqlDatabase } from './sql-database.js';
|
|
4
4
|
//SqlDatabase.LogToConsole = true;
|
|
5
5
|
export class WebSqlDataProvider {
|
|
6
6
|
databaseName;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FieldMetadata } from '../column-interfaces';
|
|
2
2
|
import type { EntityMetadataOverloads, RepositoryOverloads } from '../remult3/RepositoryImplementation';
|
|
3
|
-
import type { EntityFilter, MembersOnly } from '../remult3/remult3';
|
|
3
|
+
import type { EntityFilter, EntityMetadata, MembersOnly } from '../remult3/remult3';
|
|
4
4
|
import type { SqlCommandWithParameters } from '../sql-command';
|
|
5
5
|
import type { Filter, FilterConsumer } from './filter-interfaces';
|
|
6
6
|
export declare class FilterConsumerBridgeToSqlRequest implements FilterConsumer {
|
|
@@ -48,4 +48,6 @@ export declare type EntityDbNamesBase = {
|
|
|
48
48
|
export declare type EntityDbNames<entityType> = {
|
|
49
49
|
[Properties in keyof Required<MembersOnly<entityType>>]: string;
|
|
50
50
|
} & EntityDbNamesBase;
|
|
51
|
-
export declare function dbNamesOf<entityType>(repo: EntityMetadataOverloads<entityType
|
|
51
|
+
export declare function dbNamesOf<entityType>(repo: EntityMetadataOverloads<entityType>, wrapIdentifier?: (name: string) => string): Promise<EntityDbNames<entityType>>;
|
|
52
|
+
export declare function entityDbName(metadata: EntityMetadata, wrapIdentifier?: (name: string) => string): Promise<string>;
|
|
53
|
+
export declare function fieldDbName(f: FieldMetadata, meta: EntityMetadata, wrapIdentifier?: (name: string) => string): Promise<string>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { SqlDatabase } from '../data-providers/sql-database';
|
|
2
|
-
import { getEntityMetadata } from '../remult3/RepositoryImplementation';
|
|
1
|
+
import { SqlDatabase } from '../data-providers/sql-database.js';
|
|
2
|
+
import { getEntityMetadata } from '../remult3/RepositoryImplementation.js';
|
|
3
|
+
import { getRelationInfo } from '../remult3/relationInfoMember.js';
|
|
3
4
|
export class FilterConsumerBridgeToSqlRequest {
|
|
4
5
|
r;
|
|
5
6
|
nameProvider;
|
|
@@ -151,12 +152,13 @@ export class CustomSqlFilterBuilder {
|
|
|
151
152
|
export function isDbReadonly(field, dbNames) {
|
|
152
153
|
return (field.dbReadOnly ||
|
|
153
154
|
field.isServerExpression ||
|
|
154
|
-
|
|
155
|
+
(field.options.sqlExpression &&
|
|
156
|
+
field.options.dbName != dbNames.$dbNameOf(field)));
|
|
155
157
|
}
|
|
156
|
-
export async function dbNamesOf(repo) {
|
|
158
|
+
export async function dbNamesOf(repo, wrapIdentifier = (x) => x) {
|
|
157
159
|
var meta = getEntityMetadata(repo);
|
|
158
160
|
const result = {
|
|
159
|
-
$entityName: await meta
|
|
161
|
+
$entityName: await entityDbName(meta, wrapIdentifier),
|
|
160
162
|
toString: () => result.$entityName,
|
|
161
163
|
$dbNameOf: (field) => {
|
|
162
164
|
var key;
|
|
@@ -168,7 +170,43 @@ export async function dbNamesOf(repo) {
|
|
|
168
170
|
},
|
|
169
171
|
};
|
|
170
172
|
for (const field of meta.fields) {
|
|
171
|
-
result[field.key] = await field
|
|
173
|
+
result[field.key] = await fieldDbName(field, meta, wrapIdentifier);
|
|
172
174
|
}
|
|
173
175
|
return result;
|
|
174
176
|
}
|
|
177
|
+
export async function entityDbName(metadata, wrapIdentifier = (x) => x) {
|
|
178
|
+
if (metadata.options.sqlExpression) {
|
|
179
|
+
if (typeof metadata.options.sqlExpression === 'string')
|
|
180
|
+
return metadata.options.sqlExpression;
|
|
181
|
+
else if (typeof metadata.options.sqlExpression === 'function') {
|
|
182
|
+
return await metadata.options.sqlExpression(metadata);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return wrapIdentifier(metadata.options.dbName);
|
|
186
|
+
}
|
|
187
|
+
export async function fieldDbName(f, meta, wrapIdentifier = (x) => x) {
|
|
188
|
+
try {
|
|
189
|
+
if (f.options.sqlExpression) {
|
|
190
|
+
let result;
|
|
191
|
+
if (typeof f.options.sqlExpression === 'function') {
|
|
192
|
+
result = await f.options.sqlExpression(meta);
|
|
193
|
+
}
|
|
194
|
+
else
|
|
195
|
+
result = f.options.sqlExpression;
|
|
196
|
+
if (!result)
|
|
197
|
+
return f.options.dbName;
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
const rel = getRelationInfo(f.options);
|
|
201
|
+
let field = rel?.type === 'toOne' &&
|
|
202
|
+
f.options.field;
|
|
203
|
+
if (field) {
|
|
204
|
+
let fInfo = meta.fields.find(field);
|
|
205
|
+
if (fInfo)
|
|
206
|
+
return fieldDbName(fInfo, meta, wrapIdentifier);
|
|
207
|
+
}
|
|
208
|
+
return wrapIdentifier(f.options.dbName);
|
|
209
|
+
}
|
|
210
|
+
finally {
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Remult } from '../context';
|
|
2
|
-
import { getEntityRef, getEntitySettings } from '../remult3/getEntityRef';
|
|
3
|
-
import { getRelationInfo } from '../remult3/relationInfoMember';
|
|
1
|
+
import { Remult } from '../context.js';
|
|
2
|
+
import { getEntityRef, getEntitySettings } from '../remult3/getEntityRef.js';
|
|
3
|
+
import { getRelationInfo } from '../remult3/relationInfoMember.js';
|
|
4
4
|
export class Filter {
|
|
5
5
|
apply;
|
|
6
6
|
constructor(apply) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { buildRestDataProvider } from '../buildRestDataProvider';
|
|
2
|
-
import { RestDataProvider } from '../data-providers/rest-data-provider';
|
|
3
|
-
import { getRepositoryInternals } from '../remult3/repository-internals';
|
|
4
|
-
import { liveQueryKeepAliveRoute, LiveQuerySubscriber, } from './SubscriptionChannel';
|
|
1
|
+
import { buildRestDataProvider } from '../buildRestDataProvider.js';
|
|
2
|
+
import { RestDataProvider } from '../data-providers/rest-data-provider.js';
|
|
3
|
+
import { getRepositoryInternals } from '../remult3/repository-internals.js';
|
|
4
|
+
import { liveQueryKeepAliveRoute, LiveQuerySubscriber, } from './SubscriptionChannel.js';
|
|
5
5
|
/* @internal*/
|
|
6
6
|
export class LiveQueryClient {
|
|
7
7
|
apiProvider;
|
|
@@ -165,7 +165,7 @@ export class LiveQueryClient {
|
|
|
165
165
|
}
|
|
166
166
|
if (ids.length > 0) {
|
|
167
167
|
let p = this.apiProvider();
|
|
168
|
-
let { actionInfo } = await import('../server-action-info');
|
|
168
|
+
let { actionInfo } = await import('../server-action-info.js');
|
|
169
169
|
const invalidIds = await this.runPromise(await 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()) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { buildRestDataProvider } from '../buildRestDataProvider';
|
|
2
|
-
import { remult } from '../remult-proxy';
|
|
3
|
-
import { actionInfo } from '../server-action-info';
|
|
4
|
-
import { streamUrl } from './SubscriptionChannel';
|
|
1
|
+
import { buildRestDataProvider } from '../buildRestDataProvider.js';
|
|
2
|
+
import { remult } from '../remult-proxy.js';
|
|
3
|
+
import { actionInfo } from '../server-action-info.js';
|
|
4
|
+
import { streamUrl } from './SubscriptionChannel.js';
|
|
5
5
|
export class SseSubscriptionClient {
|
|
6
6
|
openConnection(onReconnect) {
|
|
7
7
|
let connectionId;
|
|
@@ -37,9 +37,7 @@ export class SseSubscriptionClient {
|
|
|
37
37
|
function createConnection() {
|
|
38
38
|
if (source)
|
|
39
39
|
source.close();
|
|
40
|
-
source =
|
|
41
|
-
withCredentials: true,
|
|
42
|
-
});
|
|
40
|
+
source = SseSubscriptionClient.createEventSource(remult.apiClient.url + '/' + streamUrl);
|
|
43
41
|
source.onmessage = (e) => {
|
|
44
42
|
let message = JSON.parse(e.data);
|
|
45
43
|
const listeners = channels.get(message.channel);
|
|
@@ -82,5 +80,10 @@ export class SseSubscriptionClient {
|
|
|
82
80
|
}
|
|
83
81
|
}
|
|
84
82
|
}
|
|
83
|
+
static createEventSource(url) {
|
|
84
|
+
return new EventSource(url, {
|
|
85
|
+
withCredentials: true,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
85
88
|
}
|
|
86
89
|
export const ConnectionNotFoundError = 'client connection not found';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { v4 as uuid } from 'uuid';
|
|
2
|
-
import { Sort } from '../sort';
|
|
3
|
-
import { remult as defaultRemult } from '../remult-proxy';
|
|
4
|
-
import { getRepositoryInternals } from '../remult3/repository-internals';
|
|
2
|
+
import { Sort } from '../sort.js';
|
|
3
|
+
import { remult as defaultRemult } from '../remult-proxy.js';
|
|
4
|
+
import { getRepositoryInternals } from '../remult3/repository-internals.js';
|
|
5
5
|
export const streamUrl = 'stream';
|
|
6
6
|
//@internal
|
|
7
7
|
export class LiveQuerySubscriber {
|
package/esm/src/remult-proxy.js
CHANGED