remult 0.22.2 → 0.22.3
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 +27 -27
- package/esm/postgres/schema-builder.js +4 -4
- package/esm/remult-knex/index.js +2 -2
- package/esm/src/backend-tests/backend-database-test-setup.backend-spec.js +10 -0
- package/esm/src/id-entity.d.ts +4 -0
- package/esm/src/id-entity.js +8 -0
- package/esm/src/remult3/RepositoryImplementation.js +7 -5
- package/esm/src/shared-tests/db-tests.db-tests.js +35 -0
- package/package.json +1 -1
- package/postgres/postgresColumnSyntax.d.ts +2 -0
- package/postgres/postgresColumnSyntax.js +34 -0
- package/remult-knex/index.js +2 -2
- package/remult-middleware.d.ts +2 -0
- package/remult-middleware.js +70 -0
- package/server/register-actions-on-server.d.ts +3 -0
- package/server/register-actions-on-server.js +50 -0
- package/server/register-entities-on-server.d.ts +3 -0
- package/server/register-entities-on-server.js +19 -0
- package/src/backend-tests/backend-database-test-setup.backend-spec.js +10 -0
- package/{esm/core/src → src}/backend-tests/my-test.backend-spec.d.ts +1 -1
- package/src/backend-tests/my-test.backend-spec.js +217 -0
- package/src/backend-tests/test-http-server.backend-spec.d.ts +6 -0
- package/src/backend-tests/test-http-server.backend-spec.js +342 -0
- package/src/id-entity.d.ts +4 -0
- package/src/id-entity.js +17 -0
- package/src/remult3/RepositoryImplementation.js +15 -13
- package/src/shared-tests/db-tests.db-tests.js +64 -0
- package/{esm/core/src/valueConverters.d.ts → valueConverters.d.ts} +12 -13
- package/valueConverters.js +168 -0
- package/esm/angular/interfaces/index.d.ts +0 -1
- package/esm/angular/interfaces/index.js +0 -1
- package/esm/angular/interfaces/src/column-collection.d.ts +0 -70
- package/esm/angular/interfaces/src/column-collection.js +0 -341
- package/esm/angular/interfaces/src/data-area-settings.d.ts +0 -15
- package/esm/angular/interfaces/src/data-area-settings.js +0 -35
- package/esm/angular/interfaces/src/data-control-interfaces.d.ts +0 -36
- package/esm/angular/interfaces/src/data-control-interfaces.js +0 -57
- package/esm/angular/interfaces/src/dataList.d.ts +0 -13
- package/esm/angular/interfaces/src/dataList.js +0 -42
- package/esm/angular/interfaces/src/filter-helper.d.ts +0 -13
- package/esm/angular/interfaces/src/filter-helper.js +0 -59
- package/esm/angular/interfaces/src/grid-settings.d.ts +0 -145
- package/esm/angular/interfaces/src/grid-settings.js +0 -387
- package/esm/angular/interfaces/src/public_api.d.ts +0 -4
- package/esm/angular/interfaces/src/public_api.js +0 -4
- package/esm/angular/src/angular/RemultAngularPluginsService.d.ts +0 -4
- package/esm/angular/src/angular/RemultAngularPluginsService.js +0 -3
- package/esm/angular/src/angular/data-control/data-control2.component.d.ts +0 -49
- package/esm/angular/src/angular/data-control/data-control2.component.js +0 -138
- package/esm/core/SseSubscriptionServer.d.ts +0 -33
- package/esm/core/SseSubscriptionServer.js +0 -107
- package/esm/core/assign.d.ts +0 -1
- package/esm/core/assign.js +0 -5
- package/esm/core/classType.d.ts +0 -3
- package/esm/core/classType.js +0 -1
- package/esm/core/index.d.ts +0 -27
- package/esm/core/index.js +0 -25
- package/esm/core/inputTypes.d.ts +0 -9
- package/esm/core/inputTypes.js +0 -9
- package/esm/core/live-query/data-provider-live-query-storage.d.ts +0 -22
- package/esm/core/live-query/data-provider-live-query-storage.js +0 -71
- package/esm/core/postgres/index.d.ts +0 -2
- package/esm/core/postgres/index.js +0 -2
- package/esm/core/postgres/postgres-data-provider.d.ts +0 -36
- package/esm/core/postgres/postgres-data-provider.js +0 -120
- package/esm/core/postgres/schema-builder.d.ts +0 -17
- package/esm/core/postgres/schema-builder.js +0 -153
- package/esm/core/remult-fresh.d.ts +0 -17
- package/esm/core/remult-fresh.js +0 -29
- package/esm/core/remult-knex/index.d.ts +0 -30
- package/esm/core/remult-knex/index.js +0 -446
- package/esm/core/remult-mongo.d.ts +0 -24
- package/esm/core/remult-mongo.js +0 -254
- package/esm/core/server/JsonEntityFileStorage.d.ts +0 -10
- package/esm/core/server/JsonEntityFileStorage.js +0 -25
- package/esm/core/server/core.d.ts +0 -4
- package/esm/core/server/core.js +0 -4
- package/esm/core/server/expressBridge.d.ts +0 -182
- package/esm/core/server/expressBridge.js +0 -938
- package/esm/core/server/index.d.ts +0 -6
- package/esm/core/server/index.js +0 -9
- package/esm/core/server/initAsyncHooks.d.ts +0 -1
- package/esm/core/server/initAsyncHooks.js +0 -9
- package/esm/core/server/initDataProvider.d.ts +0 -2
- package/esm/core/server/initDataProvider.js +0 -14
- package/esm/core/src/__EntityValueProvider.d.ts +0 -11
- package/esm/core/src/__EntityValueProvider.js +0 -1
- package/esm/core/src/__RowsOfDataForTesting.d.ts +0 -3
- package/esm/core/src/__RowsOfDataForTesting.js +0 -1
- package/esm/core/src/backend-tests/backend-database-test-setup.backend-spec.d.ts +0 -6
- package/esm/core/src/backend-tests/backend-database-test-setup.backend-spec.js +0 -147
- package/esm/core/src/backend-tests/my-test.backend-spec.js +0 -197
- package/esm/core/src/backend-tests/test-http-server.backend-spec.d.ts +0 -1
- package/esm/core/src/backend-tests/test-http-server.backend-spec.js +0 -167
- package/esm/core/src/buildRestDataProvider.d.ts +0 -31
- package/esm/core/src/buildRestDataProvider.js +0 -113
- package/esm/core/src/column-interfaces.d.ts +0 -154
- package/esm/core/src/column-interfaces.js +0 -7
- package/esm/core/src/column.d.ts +0 -58
- package/esm/core/src/column.js +0 -174
- package/esm/core/src/context.d.ts +0 -134
- package/esm/core/src/context.js +0 -286
- package/esm/core/src/data-api.d.ts +0 -39
- package/esm/core/src/data-api.js +0 -279
- package/esm/core/src/data-interfaces.d.ts +0 -41
- package/esm/core/src/data-interfaces.js +0 -12
- package/esm/core/src/data-providers/array-entity-data-provider.d.ts +0 -22
- package/esm/core/src/data-providers/array-entity-data-provider.js +0 -252
- package/esm/core/src/data-providers/in-memory-database.d.ts +0 -9
- package/esm/core/src/data-providers/in-memory-database.js +0 -14
- package/esm/core/src/data-providers/json-data-provider.d.ts +0 -12
- package/esm/core/src/data-providers/json-data-provider.js +0 -55
- package/esm/core/src/data-providers/rest-data-provider.d.ts +0 -49
- package/esm/core/src/data-providers/rest-data-provider.js +0 -256
- package/esm/core/src/data-providers/sql-database.d.ts +0 -33
- package/esm/core/src/data-providers/sql-database.js +0 -384
- package/esm/core/src/data-providers/web-sql-data-provider.d.ts +0 -24
- package/esm/core/src/data-providers/web-sql-data-provider.js +0 -143
- package/esm/core/src/entity.d.ts +0 -91
- package/esm/core/src/entity.js +0 -1
- package/esm/core/src/filter/filter-consumer-bridge-to-sql-request.d.ts +0 -50
- package/esm/core/src/filter/filter-consumer-bridge-to-sql-request.js +0 -150
- package/esm/core/src/filter/filter-consumer-bridge-to-url-builder.d.ts +0 -1
- package/esm/core/src/filter/filter-consumer-bridge-to-url-builder.js +0 -1
- package/esm/core/src/filter/filter-interfaces.d.ts +0 -85
- package/esm/core/src/filter/filter-interfaces.js +0 -477
- package/esm/core/src/live-query/LiveQueryClient.d.ts +0 -20
- package/esm/core/src/live-query/LiveQueryClient.js +0 -188
- package/esm/core/src/live-query/SseSubscriptionClient.d.ts +0 -5
- package/esm/core/src/live-query/SseSubscriptionClient.js +0 -86
- package/esm/core/src/live-query/SubscriptionChannel.d.ts +0 -72
- package/esm/core/src/live-query/SubscriptionChannel.js +0 -123
- package/esm/core/src/live-query/SubscriptionServer.d.ts +0 -53
- package/esm/core/src/live-query/SubscriptionServer.js +0 -111
- package/esm/core/src/live-query/live-query-tests.spec.d.ts +0 -6
- package/esm/core/src/live-query/live-query-tests.spec.js +0 -952
- package/esm/core/src/remult-proxy.d.ts +0 -35
- package/esm/core/src/remult-proxy.js +0 -113
- package/esm/core/src/remult3/DecoratorReplacer.d.ts +0 -10
- package/esm/core/src/remult3/DecoratorReplacer.js +0 -20
- package/esm/core/src/remult3/RepositoryImplementation.d.ts +0 -355
- package/esm/core/src/remult3/RepositoryImplementation.js +0 -2109
- package/esm/core/src/remult3/index.d.ts +0 -2
- package/esm/core/src/remult3/index.js +0 -2
- package/esm/core/src/remult3/remult3.d.ts +0 -395
- package/esm/core/src/remult3/remult3.js +0 -2
- package/esm/core/src/server-action.d.ts +0 -81
- package/esm/core/src/server-action.js +0 -394
- package/esm/core/src/shared-tests/db-tests-setup.d.ts +0 -32
- package/esm/core/src/shared-tests/db-tests-setup.js +0 -78
- package/esm/core/src/shared-tests/db-tests.db-tests.d.ts +0 -25
- package/esm/core/src/shared-tests/db-tests.db-tests.js +0 -810
- package/esm/core/src/shared-tests/deleteAll.d.ts +0 -2
- package/esm/core/src/shared-tests/deleteAll.js +0 -4
- package/esm/core/src/shared-tests/entityWithValidations.d.ts +0 -14
- package/esm/core/src/shared-tests/entityWithValidations.js +0 -43
- package/esm/core/src/shared-tests/index.d.ts +0 -4
- package/esm/core/src/shared-tests/index.js +0 -4
- package/esm/core/src/shared-tests/test-custom-id-column.spec.d.ts +0 -1
- package/esm/core/src/shared-tests/test-custom-id-column.spec.js +0 -67
- package/esm/core/src/shared-tests/test-special-value.spec.d.ts +0 -10
- package/esm/core/src/shared-tests/test-special-value.spec.js +0 -73
- package/esm/core/src/shared-tests/test-update-with-null.spec.d.ts +0 -1
- package/esm/core/src/shared-tests/test-update-with-null.spec.js +0 -31
- package/esm/core/src/sort.d.ts +0 -16
- package/esm/core/src/sort.js +0 -103
- package/esm/core/src/sql-command.d.ts +0 -19
- package/esm/core/src/sql-command.js +0 -1
- package/esm/core/src/test.d.ts +0 -3
- package/esm/core/src/test.js +0 -12
- package/esm/core/src/tests/Done.d.ts +0 -5
- package/esm/core/src/tests/Done.js +0 -9
- package/esm/core/src/tests/RowProvider.spec.d.ts +0 -16
- package/esm/core/src/tests/RowProvider.spec.js +0 -631
- package/esm/core/src/tests/TestDataApiResponse.d.ts +0 -10
- package/esm/core/src/tests/TestDataApiResponse.js +0 -22
- package/esm/core/src/tests/basicRowFunctionality.spec.d.ts +0 -8
- package/esm/core/src/tests/basicRowFunctionality.spec.js +0 -2103
- package/esm/core/src/tests/c.d.ts +0 -8
- package/esm/core/src/tests/c.js +0 -13
- package/esm/core/src/tests/createData.d.ts +0 -7
- package/esm/core/src/tests/createData.js +0 -22
- package/esm/core/src/tests/d.d.ts +0 -6
- package/esm/core/src/tests/d.js +0 -11
- package/esm/core/src/tests/dWithPrefilter.d.ts +0 -7
- package/esm/core/src/tests/dWithPrefilter.js +0 -18
- package/esm/core/src/tests/entityForCustomFilter.d.ts +0 -16
- package/esm/core/src/tests/entityForCustomFilter.js +0 -33
- package/esm/core/src/tests/entityWithValidationsOnColumn.d.ts +0 -5
- package/esm/core/src/tests/entityWithValidationsOnColumn.js +0 -13
- package/esm/core/src/tests/frontend-database-tests-setup.spec.d.ts +0 -4
- package/esm/core/src/tests/frontend-database-tests-setup.spec.js +0 -37
- package/esm/core/src/tests/h.d.ts +0 -6
- package/esm/core/src/tests/h.js +0 -24
- package/esm/core/src/tests/remult-3-basic-tests.spec.d.ts +0 -1
- package/esm/core/src/tests/remult-3-basic-tests.spec.js +0 -236
- package/esm/core/src/tests/remult-3-entities.d.ts +0 -23
- package/esm/core/src/tests/remult-3-entities.js +0 -39
- package/esm/core/src/tests/tasks.d.ts +0 -6
- package/esm/core/src/tests/tasks.js +0 -10
- package/esm/core/src/tests/test-context-as-storage.spec.d.ts +0 -0
- package/esm/core/src/tests/test-context-as-storage.spec.js +0 -1
- package/esm/core/src/tests/test-data-api/predefined-filter.spec.d.ts +0 -1
- package/esm/core/src/tests/test-data-api/predefined-filter.spec.js +0 -389
- package/esm/core/src/tests/test-data-api/test-put-with-validation.spec.d.ts +0 -5
- package/esm/core/src/tests/test-data-api/test-put-with-validation.spec.js +0 -152
- package/esm/core/src/tests/test-decorator-precedence.spec.d.ts +0 -1
- package/esm/core/src/tests/test-decorator-precedence.spec.js +0 -38
- package/esm/core/src/tests/test-default-value.spec.d.ts +0 -1
- package/esm/core/src/tests/test-default-value.spec.js +0 -33
- package/esm/core/src/tests/test-entity-inheritance.spec.d.ts +0 -14
- package/esm/core/src/tests/test-entity-inheritance.spec.js +0 -82
- package/esm/core/src/tests/test-exceptions.spec.d.ts +0 -1
- package/esm/core/src/tests/test-exceptions.spec.js +0 -375
- package/esm/core/src/tests/test-json.spec.d.ts +0 -1
- package/esm/core/src/tests/test-json.spec.js +0 -115
- package/esm/core/src/tests/test-many-to-one-relation-in-entity.spec.d.ts +0 -9
- package/esm/core/src/tests/test-many-to-one-relation-in-entity.spec.js +0 -809
- package/esm/core/src/tests/test-non-active-record.spec.d.ts +0 -1
- package/esm/core/src/tests/test-non-active-record.spec.js +0 -66
- package/esm/core/src/tests/test-object-column.spec.d.ts +0 -1
- package/esm/core/src/tests/test-object-column.spec.js +0 -189
- package/esm/core/src/tests/test-paged-foreach.spec.d.ts +0 -1
- package/esm/core/src/tests/test-paged-foreach.spec.js +0 -328
- package/esm/core/src/tests/test-remult-angular.spec.d.ts +0 -1
- package/esm/core/src/tests/test-remult-angular.spec.js +0 -23
- package/esm/core/src/tests/test-server-controller.spec.d.ts +0 -7
- package/esm/core/src/tests/test-server-controller.spec.js +0 -489
- package/esm/core/src/tests/test-server-expressions.spec.d.ts +0 -1
- package/esm/core/src/tests/test-server-expressions.spec.js +0 -178
- package/esm/core/src/tests/test-server-method-on-entity.spec.d.ts +0 -1
- package/esm/core/src/tests/test-server-method-on-entity.spec.js +0 -306
- package/esm/core/src/tests/test-sql-expression.spec.d.ts +0 -5
- package/esm/core/src/tests/test-sql-expression.spec.js +0 -205
- package/esm/core/src/tests/test-sql.spec.d.ts +0 -1
- package/esm/core/src/tests/test-sql.spec.js +0 -170
- package/esm/core/src/tests/test-subscribe.spec.d.ts +0 -1
- package/esm/core/src/tests/test-subscribe.spec.js +0 -135
- package/esm/core/src/tests/test-type-recovery.spec.d.ts +0 -1
- package/esm/core/src/tests/test-type-recovery.spec.js +0 -49
- package/esm/core/src/tests/test-where-api.spec.d.ts +0 -1
- package/esm/core/src/tests/test-where-api.spec.js +0 -434
- package/esm/core/src/tests/testHelper.spec.d.ts +0 -36
- package/esm/core/src/tests/testHelper.spec.js +0 -226
- package/esm/core/src/tests/testModel/models.d.ts +0 -16
- package/esm/core/src/tests/testModel/models.js +0 -25
- package/esm/core/src/validators.d.ts +0 -14
- package/esm/core/src/validators.js +0 -33
- package/esm/core/src/valueConverters.js +0 -197
- package/esm/core/urlBuilder.d.ts +0 -6
- package/esm/core/urlBuilder.js +0 -20
- package/esm/test-servers/shared/Task.d.ts +0 -9
- package/esm/test-servers/shared/Task.js +0 -32
- package/esm/test.d.ts +0 -5
- package/esm/test.js +0 -6
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { v4 as uuid } from 'uuid';
|
|
2
|
-
import { ConnectionNotFoundError } from './src/live-query/SseSubscriptionClient';
|
|
3
|
-
export class SseSubscriptionServer {
|
|
4
|
-
canUserConnectToChannel;
|
|
5
|
-
//@internal
|
|
6
|
-
subscribeToChannel({ channel, clientId }, res, remult, remove = false) {
|
|
7
|
-
for (const c of this.connections) {
|
|
8
|
-
if (c.connectionId === clientId) {
|
|
9
|
-
if (this.canUserConnectToChannel(channel, remult)) {
|
|
10
|
-
if (remove)
|
|
11
|
-
delete c.channels[channel];
|
|
12
|
-
else
|
|
13
|
-
c.channels[channel] = true;
|
|
14
|
-
res.success({ status: "ok" });
|
|
15
|
-
this.debug();
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
res.forbidden();
|
|
20
|
-
this.debug();
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
res.success(ConnectionNotFoundError);
|
|
26
|
-
}
|
|
27
|
-
//@internal
|
|
28
|
-
connections = [];
|
|
29
|
-
constructor(canUserConnectToChannel) {
|
|
30
|
-
this.canUserConnectToChannel = canUserConnectToChannel;
|
|
31
|
-
if (!this.canUserConnectToChannel) {
|
|
32
|
-
this.canUserConnectToChannel = () => true;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
async publishMessage(channel, message) {
|
|
36
|
-
const data = JSON.stringify({ channel, data: message });
|
|
37
|
-
for (const sc of this.connections) {
|
|
38
|
-
if (sc.channels[channel]) {
|
|
39
|
-
this.debugMessageFileSaver(sc.connectionId, channel, message);
|
|
40
|
-
sc.write(data);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
//@internal
|
|
45
|
-
debugMessageFileSaver = (id, channel, message) => { };
|
|
46
|
-
//@internal
|
|
47
|
-
openHttpServerStream(req, res) {
|
|
48
|
-
res.writeHead(200, {
|
|
49
|
-
'Content-Type': 'text/event-stream',
|
|
50
|
-
'Cache-Control': 'no-cache',
|
|
51
|
-
'Connection': 'keep-alive'
|
|
52
|
-
});
|
|
53
|
-
const cc = new clientConnection(res);
|
|
54
|
-
//const lastEventId = req.headers['last-event-id'];
|
|
55
|
-
this.connections.push(cc);
|
|
56
|
-
this.debug();
|
|
57
|
-
//@ts-ignore
|
|
58
|
-
req.on("close", () => {
|
|
59
|
-
cc.close();
|
|
60
|
-
this.connections = this.connections.filter(s => s !== cc);
|
|
61
|
-
this.debug();
|
|
62
|
-
});
|
|
63
|
-
return cc;
|
|
64
|
-
}
|
|
65
|
-
//@internal
|
|
66
|
-
debug() {
|
|
67
|
-
this.debugFileSaver(this.connections.map(x => ({
|
|
68
|
-
id: x.connectionId,
|
|
69
|
-
channels: x.channels
|
|
70
|
-
})));
|
|
71
|
-
}
|
|
72
|
-
//@internal
|
|
73
|
-
debugFileSaver = () => { };
|
|
74
|
-
}
|
|
75
|
-
export class clientConnection {
|
|
76
|
-
response;
|
|
77
|
-
channels = {};
|
|
78
|
-
timeOutRef;
|
|
79
|
-
close() {
|
|
80
|
-
if (this.timeOutRef)
|
|
81
|
-
clearTimeout(this.timeOutRef);
|
|
82
|
-
this.closed = true;
|
|
83
|
-
}
|
|
84
|
-
closed = false;
|
|
85
|
-
write(eventData, eventType = "message") {
|
|
86
|
-
let event = "event:" + eventType;
|
|
87
|
-
// if (id != undefined)
|
|
88
|
-
// event += "\nid:" + id;
|
|
89
|
-
this.response.write(event + "\ndata:" + eventData + "\n\n");
|
|
90
|
-
if (this.response.flush)
|
|
91
|
-
this.response.flush();
|
|
92
|
-
}
|
|
93
|
-
connectionId = uuid();
|
|
94
|
-
constructor(response) {
|
|
95
|
-
this.response = response;
|
|
96
|
-
this.write(this.connectionId, "connectionId");
|
|
97
|
-
this.sendLiveMessage();
|
|
98
|
-
}
|
|
99
|
-
sendLiveMessage() {
|
|
100
|
-
if (this.closed)
|
|
101
|
-
return;
|
|
102
|
-
this.write("", "keep-alive");
|
|
103
|
-
this.timeOutRef = setTimeout(() => {
|
|
104
|
-
this.sendLiveMessage();
|
|
105
|
-
}, 45000);
|
|
106
|
-
}
|
|
107
|
-
}
|
package/esm/core/assign.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function assign<T>(item: T, valuesToSet: Partial<T>): T;
|
package/esm/core/assign.js
DELETED
package/esm/core/classType.d.ts
DELETED
package/esm/core/classType.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/esm/core/index.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export { Field, Fields, FieldsMetadata, Entity, IdEntity, EntityBase, ControllerBase, FieldRef, IdFieldRef, FieldsRef, EntityMetadata, EntityOrderBy, EntityFilter, FindOptions, QueryResult, QueryOptions, Repository, FieldType, FindFirstOptions, ComparisonValueFilter, ValueFilter, IdFilter, ContainsStringValueFilter, getFields, EntityRef, getEntityRef, SortSegments, ValueListFieldType, getValueList, ValueListFieldOptions, ValueListInfo, OmitEB, Paginator, CaptionTransformer, LiveQuery, LiveQueryChangeInfo } from './src/remult3';
|
|
2
|
-
export { StringFieldOptions } from './src/remult3/RepositoryImplementation';
|
|
3
|
-
export { describeClass } from './src/remult3/DecoratorReplacer';
|
|
4
|
-
export { EntityOptions } from './src/entity';
|
|
5
|
-
export { DataProvider, EntityDataProvider, EntityDataProviderFindOptions, ErrorInfo, RestDataProviderHttpProvider } from './src/data-interfaces';
|
|
6
|
-
export { SqlCommand, SqlImplementation, SqlResult } from './src/sql-command';
|
|
7
|
-
export { FieldMetadata, FieldOptions, FieldValidator, ValueConverter, ValueListItem, // reconsider, maybe it should go to remult angular as the abstraction ?
|
|
8
|
-
ValueOrExpression } from './src/column-interfaces';
|
|
9
|
-
export { RestDataProvider } from './src/data-providers/rest-data-provider';
|
|
10
|
-
export { InMemoryDataProvider } from './src/data-providers/in-memory-database';
|
|
11
|
-
export { ArrayEntityDataProvider } from './src/data-providers/array-entity-data-provider';
|
|
12
|
-
export { WebSqlDataProvider } from './src/data-providers/web-sql-data-provider';
|
|
13
|
-
export { SqlDatabase, } from './src/data-providers/sql-database';
|
|
14
|
-
export { CustomSqlFilterObject, CustomSqlFilterBuilder, dbNamesOf } from './src/filter/filter-consumer-bridge-to-sql-request';
|
|
15
|
-
export { JsonDataProvider, JsonEntityStorage } from './src/data-providers/json-data-provider';
|
|
16
|
-
export { Controller, BackendMethodOptions, BackendMethod, ProgressListener } from './src/server-action';
|
|
17
|
-
export { Allowed, Allow, Remult, RemultContext, ApiClient, isBackend, AllowedForInstance, EventDispatcher, EventSource, UserInfo } from './src/context';
|
|
18
|
-
export { ExternalHttpProvider } from './src/buildRestDataProvider';
|
|
19
|
-
export { SortSegment, Sort } from './src/sort';
|
|
20
|
-
export { OneToMany, CompoundIdField } from './src/column';
|
|
21
|
-
export { Filter } from './src/filter/filter-interfaces';
|
|
22
|
-
export { UrlBuilder } from './urlBuilder';
|
|
23
|
-
export { Validators } from './src/validators';
|
|
24
|
-
export { ValueConverters } from './src/valueConverters';
|
|
25
|
-
export { remult } from './src/remult-proxy';
|
|
26
|
-
export { SubscriptionServer, LiveQueryStorage, StoredQuery, InMemoryLiveQueryStorage } from "./src/live-query/SubscriptionServer";
|
|
27
|
-
export { SubscriptionListener, SubscriptionClientConnection, SubscriptionClient, SubscriptionChannel, LiveQueryChange, Unsubscribe } from './src/live-query/SubscriptionChannel';
|
package/esm/core/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Public API Surface of remult
|
|
3
|
-
*/
|
|
4
|
-
export { Field, Fields, Entity, IdEntity, EntityBase, ControllerBase, FieldType, getFields, getEntityRef, ValueListFieldType, getValueList, ValueListInfo, CaptionTransformer } from './src/remult3';
|
|
5
|
-
export { describeClass } from './src/remult3/DecoratorReplacer';
|
|
6
|
-
export { RestDataProvider } from './src/data-providers/rest-data-provider'; //V
|
|
7
|
-
export { InMemoryDataProvider } from './src/data-providers/in-memory-database'; //V
|
|
8
|
-
export { ArrayEntityDataProvider } from './src/data-providers/array-entity-data-provider'; //V
|
|
9
|
-
export { WebSqlDataProvider } from './src/data-providers/web-sql-data-provider'; //V
|
|
10
|
-
export { SqlDatabase, } from './src/data-providers/sql-database'; //V
|
|
11
|
-
export { CustomSqlFilterBuilder, dbNamesOf } from './src/filter/filter-consumer-bridge-to-sql-request';
|
|
12
|
-
export { JsonDataProvider } from './src/data-providers/json-data-provider'; //V
|
|
13
|
-
//export * from './src/data-api'; //reconsider if to make internal
|
|
14
|
-
export { Controller, BackendMethod, ProgressListener } from './src/server-action';
|
|
15
|
-
export { Allow, Remult, isBackend, EventSource } from './src/context';
|
|
16
|
-
export { Sort } from './src/sort';
|
|
17
|
-
export { OneToMany, CompoundIdField } from './src/column';
|
|
18
|
-
export { Filter } from './src/filter/filter-interfaces';
|
|
19
|
-
export { UrlBuilder } from './urlBuilder';
|
|
20
|
-
export { Validators } from './src/validators';
|
|
21
|
-
export { ValueConverters } from './src/valueConverters';
|
|
22
|
-
export { remult } from './src/remult-proxy';
|
|
23
|
-
//export { getId } from './src/remult3/getId';
|
|
24
|
-
export { InMemoryLiveQueryStorage } from "./src/live-query/SubscriptionServer";
|
|
25
|
-
export { SubscriptionChannel } from './src/live-query/SubscriptionChannel';
|
package/esm/core/inputTypes.d.ts
DELETED
package/esm/core/inputTypes.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Storage, DataProvider } from "../src/data-interfaces";
|
|
2
|
-
import { LiveQueryStorage, StoredQuery } from "../src/live-query/SubscriptionServer";
|
|
3
|
-
import { EntityBase, Repository } from "../src/remult3";
|
|
4
|
-
export declare class DataProviderLiveQueryStorage implements LiveQueryStorage, Storage {
|
|
5
|
-
repo: Promise<Repository<LiveQueryStorageEntity>>;
|
|
6
|
-
dataProvider: Promise<DataProvider>;
|
|
7
|
-
constructor(dataProvider: DataProvider | Promise<DataProvider> | (() => Promise<DataProvider | undefined>));
|
|
8
|
-
ensureSchema(): Promise<void>;
|
|
9
|
-
add({ id, entityKey, data }: StoredQuery): Promise<void>;
|
|
10
|
-
remove(queryId: string): Promise<void>;
|
|
11
|
-
forEach(entityKey: string, callback: (args: {
|
|
12
|
-
query: StoredQuery;
|
|
13
|
-
setData(data: any): Promise<void>;
|
|
14
|
-
}) => Promise<void>): Promise<void>;
|
|
15
|
-
keepAliveAndReturnUnknownQueryIds(queryIds: string[]): Promise<string[]>;
|
|
16
|
-
}
|
|
17
|
-
export declare class LiveQueryStorageEntity extends EntityBase {
|
|
18
|
-
id: string;
|
|
19
|
-
entityKey: string;
|
|
20
|
-
data: any;
|
|
21
|
-
lastUsedIso: string;
|
|
22
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { initDataProvider } from "../server/initDataProvider";
|
|
2
|
-
import { allEntities, Remult } from "../src/context";
|
|
3
|
-
import { Entity, EntityBase, Fields } from "../src/remult3";
|
|
4
|
-
export class DataProviderLiveQueryStorage {
|
|
5
|
-
repo;
|
|
6
|
-
dataProvider;
|
|
7
|
-
constructor(dataProvider) {
|
|
8
|
-
this.dataProvider = initDataProvider(dataProvider);
|
|
9
|
-
this.repo = this.dataProvider.then(dp => new Remult(dp).repo(LiveQueryStorageEntity));
|
|
10
|
-
}
|
|
11
|
-
async ensureSchema() {
|
|
12
|
-
const dp = await this.dataProvider;
|
|
13
|
-
if (dp.ensureSchema)
|
|
14
|
-
await dp.ensureSchema([(await this.repo).metadata]);
|
|
15
|
-
}
|
|
16
|
-
async add({ id, entityKey, data }) {
|
|
17
|
-
await this.repo.then(async (repo) => {
|
|
18
|
-
const q = await repo.findId(id, { createIfNotFound: true });
|
|
19
|
-
await q.assign({ entityKey, data }).save();
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
async remove(queryId) {
|
|
23
|
-
await this.repo.then(async (repo) => {
|
|
24
|
-
const r = await repo.findId(queryId);
|
|
25
|
-
if (r)
|
|
26
|
-
await repo.delete(r);
|
|
27
|
-
}).catch(() => { });
|
|
28
|
-
}
|
|
29
|
-
async forEach(entityKey, callback) {
|
|
30
|
-
const repo = await this.repo;
|
|
31
|
-
let d = new Date();
|
|
32
|
-
d.setMinutes(d.getMinutes() - 5);
|
|
33
|
-
const iso = d.toISOString();
|
|
34
|
-
for (const query of await repo.find({ where: { entityKey } })) {
|
|
35
|
-
if (query.lastUsedIso < iso)
|
|
36
|
-
await repo.delete(query);
|
|
37
|
-
else {
|
|
38
|
-
await callback({
|
|
39
|
-
query, setData: async (data) => {
|
|
40
|
-
query.data = data;
|
|
41
|
-
await repo.save(query);
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
async keepAliveAndReturnUnknownQueryIds(queryIds) {
|
|
48
|
-
const repo = await this.repo;
|
|
49
|
-
for (const query of await repo.find({ where: { id: queryIds } })) {
|
|
50
|
-
query.lastUsedIso = new Date().toISOString();
|
|
51
|
-
await repo.save(query);
|
|
52
|
-
queryIds = queryIds.filter(x => x !== query.id);
|
|
53
|
-
}
|
|
54
|
-
return queryIds;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
@Entity(undefined, {
|
|
58
|
-
dbName: 'remult_live_query_storage'
|
|
59
|
-
})
|
|
60
|
-
/*@internal */
|
|
61
|
-
export class LiveQueryStorageEntity extends EntityBase {
|
|
62
|
-
@Fields.string()
|
|
63
|
-
id = '';
|
|
64
|
-
@Fields.string()
|
|
65
|
-
entityKey = '';
|
|
66
|
-
@Fields.object()
|
|
67
|
-
data;
|
|
68
|
-
@Fields.string()
|
|
69
|
-
lastUsedIso = new Date().toISOString();
|
|
70
|
-
}
|
|
71
|
-
allEntities.splice(allEntities.indexOf(LiveQueryStorageEntity), 1);
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { ClientBase, PoolConfig, QueryResult } from 'pg';
|
|
2
|
-
import { Remult } from '../src/context';
|
|
3
|
-
import { EntityMetadata } from '../src/remult3';
|
|
4
|
-
import { SqlCommand, SqlImplementation } from '../src/sql-command';
|
|
5
|
-
import { SqlDatabase } from '../src/data-providers/sql-database';
|
|
6
|
-
export interface PostgresPool extends PostgresCommandSource {
|
|
7
|
-
connect(): Promise<PostgresClient>;
|
|
8
|
-
}
|
|
9
|
-
export interface PostgresClient extends PostgresCommandSource {
|
|
10
|
-
release(): void;
|
|
11
|
-
}
|
|
12
|
-
export declare class PostgresDataProvider implements SqlImplementation {
|
|
13
|
-
private pool;
|
|
14
|
-
supportsJsonColumnType: boolean;
|
|
15
|
-
static getDb(remult?: Remult): ClientBase;
|
|
16
|
-
entityIsUsedForTheFirstTime(entity: EntityMetadata): Promise<void>;
|
|
17
|
-
getLimitSqlSyntax(limit: number, offset: number): string;
|
|
18
|
-
createCommand(): SqlCommand;
|
|
19
|
-
constructor(pool: PostgresPool);
|
|
20
|
-
ensureSchema(entities: EntityMetadata<any>[]): Promise<void>;
|
|
21
|
-
transaction(action: (dataProvider: SqlImplementation) => Promise<void>): Promise<void>;
|
|
22
|
-
}
|
|
23
|
-
export interface PostgresCommandSource {
|
|
24
|
-
query(queryText: string, values?: any[]): Promise<QueryResult>;
|
|
25
|
-
}
|
|
26
|
-
export declare function createPostgresConnection(options?: {
|
|
27
|
-
connectionString?: string;
|
|
28
|
-
sslInDev?: boolean;
|
|
29
|
-
configuration?: "heroku" | PoolConfig;
|
|
30
|
-
}): Promise<SqlDatabase>;
|
|
31
|
-
export declare function createPostgresDataProvider(options?: {
|
|
32
|
-
connectionString?: string;
|
|
33
|
-
sslInDev?: boolean;
|
|
34
|
-
configuration?: "heroku" | PoolConfig;
|
|
35
|
-
}): Promise<SqlDatabase>;
|
|
36
|
-
export declare function preparePostgresQueueStorage(sql: SqlDatabase): Promise<import("../server/expressBridge").EntityQueueStorage>;
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { Pool } from 'pg';
|
|
2
|
-
import { Remult } from '../src/context';
|
|
3
|
-
import { PostgresSchemaBuilder } from './schema-builder';
|
|
4
|
-
import { SqlDatabase } from '../src/data-providers/sql-database';
|
|
5
|
-
export class PostgresDataProvider {
|
|
6
|
-
pool;
|
|
7
|
-
supportsJsonColumnType = true;
|
|
8
|
-
static getDb(remult) {
|
|
9
|
-
const sql = SqlDatabase.getDb(remult);
|
|
10
|
-
const me = sql._getSourceSql();
|
|
11
|
-
if (!me.pool) {
|
|
12
|
-
throw "the data provider is not a PostgresDataProvider";
|
|
13
|
-
}
|
|
14
|
-
return me.pool;
|
|
15
|
-
}
|
|
16
|
-
async entityIsUsedForTheFirstTime(entity) {
|
|
17
|
-
}
|
|
18
|
-
getLimitSqlSyntax(limit, offset) {
|
|
19
|
-
return ' limit ' + limit + ' offset ' + offset;
|
|
20
|
-
}
|
|
21
|
-
createCommand() {
|
|
22
|
-
return new PostgresBridgeToSQLCommand(this.pool);
|
|
23
|
-
}
|
|
24
|
-
constructor(pool) {
|
|
25
|
-
this.pool = pool;
|
|
26
|
-
}
|
|
27
|
-
async ensureSchema(entities) {
|
|
28
|
-
var db = new SqlDatabase(this);
|
|
29
|
-
var sb = new PostgresSchemaBuilder(db);
|
|
30
|
-
await sb.ensureSchema(entities);
|
|
31
|
-
}
|
|
32
|
-
async transaction(action) {
|
|
33
|
-
let client = await this.pool.connect();
|
|
34
|
-
try {
|
|
35
|
-
await client.query('BEGIN');
|
|
36
|
-
await action({
|
|
37
|
-
createCommand: () => new PostgresBridgeToSQLCommand(client),
|
|
38
|
-
entityIsUsedForTheFirstTime: this.entityIsUsedForTheFirstTime,
|
|
39
|
-
transaction: () => { throw "nested transactions not allowed"; },
|
|
40
|
-
getLimitSqlSyntax: this.getLimitSqlSyntax,
|
|
41
|
-
supportsJsonColumnType: this.supportsJsonColumnType,
|
|
42
|
-
//@ts-ignore
|
|
43
|
-
pool: client
|
|
44
|
-
});
|
|
45
|
-
await client.query('COMMIT');
|
|
46
|
-
}
|
|
47
|
-
catch (err) {
|
|
48
|
-
await client.query('ROLLBACK');
|
|
49
|
-
throw err;
|
|
50
|
-
}
|
|
51
|
-
finally {
|
|
52
|
-
await client.release();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
class PostgresBridgeToSQLCommand {
|
|
57
|
-
source;
|
|
58
|
-
constructor(source) {
|
|
59
|
-
this.source = source;
|
|
60
|
-
}
|
|
61
|
-
values = [];
|
|
62
|
-
addParameterAndReturnSqlToken(val) {
|
|
63
|
-
if (Array.isArray(val))
|
|
64
|
-
val = JSON.stringify(val);
|
|
65
|
-
this.values.push(val);
|
|
66
|
-
return '$' + this.values.length;
|
|
67
|
-
}
|
|
68
|
-
execute(sql) {
|
|
69
|
-
return this.source.query(sql, this.values).then(r => new PostgresBridgeToSQLQueryResult(r));
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
class PostgresBridgeToSQLQueryResult {
|
|
73
|
-
r;
|
|
74
|
-
getColumnKeyInResultForIndexInSelect(index) {
|
|
75
|
-
return this.r.fields[index].name;
|
|
76
|
-
}
|
|
77
|
-
constructor(r) {
|
|
78
|
-
this.r = r;
|
|
79
|
-
this.rows = r.rows;
|
|
80
|
-
}
|
|
81
|
-
rows;
|
|
82
|
-
}
|
|
83
|
-
export async function createPostgresConnection(options) {
|
|
84
|
-
return createPostgresDataProvider(options);
|
|
85
|
-
}
|
|
86
|
-
export async function createPostgresDataProvider(options) {
|
|
87
|
-
if (!options)
|
|
88
|
-
options = {};
|
|
89
|
-
let config = {};
|
|
90
|
-
if (options.configuration)
|
|
91
|
-
if (options.configuration == "heroku") {
|
|
92
|
-
config = {
|
|
93
|
-
connectionString: process.env.DATABASE_URL,
|
|
94
|
-
ssl: process.env.NODE_ENV !== "production" && !options.sslInDev ? false : {
|
|
95
|
-
rejectUnauthorized: false
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
else
|
|
100
|
-
config = options.configuration;
|
|
101
|
-
else {
|
|
102
|
-
if (!options.connectionString)
|
|
103
|
-
options.connectionString = process.env.DATABASE_URL;
|
|
104
|
-
}
|
|
105
|
-
if (!config.connectionString && options.connectionString) {
|
|
106
|
-
config.connectionString = options.connectionString;
|
|
107
|
-
}
|
|
108
|
-
const db = new SqlDatabase(new PostgresDataProvider(new Pool(config)));
|
|
109
|
-
let remult = new Remult();
|
|
110
|
-
remult.dataProvider = (db);
|
|
111
|
-
return db;
|
|
112
|
-
}
|
|
113
|
-
export async function preparePostgresQueueStorage(sql) {
|
|
114
|
-
let c = new Remult();
|
|
115
|
-
c.dataProvider = (sql);
|
|
116
|
-
let JobsInQueueEntity = (await import('../server/expressBridge')).JobsInQueueEntity;
|
|
117
|
-
let e = c.repo(JobsInQueueEntity);
|
|
118
|
-
await sql.ensureSchema([e.metadata]);
|
|
119
|
-
return new (await import('../server/expressBridge')).EntityQueueStorage(c.repo(JobsInQueueEntity));
|
|
120
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { FieldMetadata } from '../src/column-interfaces';
|
|
2
|
-
import { Remult } from '../src/context';
|
|
3
|
-
import { SqlDatabase } from '../src/data-providers/sql-database';
|
|
4
|
-
import { EntityMetadata } from '../src/remult3';
|
|
5
|
-
export declare function postgresColumnSyntax(x: FieldMetadata, dbName: string): string;
|
|
6
|
-
export declare function verifyStructureOfAllEntities(db: SqlDatabase, remult: Remult): Promise<void>;
|
|
7
|
-
export declare class PostgresSchemaBuilder {
|
|
8
|
-
private pool;
|
|
9
|
-
static logToConsole: boolean;
|
|
10
|
-
verifyStructureOfAllEntities(remult?: Remult): Promise<void>;
|
|
11
|
-
ensureSchema(entities: EntityMetadata<any>[]): Promise<void>;
|
|
12
|
-
createIfNotExist(entity: EntityMetadata): Promise<void>;
|
|
13
|
-
addColumnIfNotExist<T extends EntityMetadata>(entity: T, c: ((e: T) => FieldMetadata)): Promise<void>;
|
|
14
|
-
verifyAllColumns<T extends EntityMetadata>(entity: T): Promise<void>;
|
|
15
|
-
additionalWhere: string;
|
|
16
|
-
constructor(pool: SqlDatabase, schema?: string);
|
|
17
|
-
}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { allEntities } from '../src/context';
|
|
2
|
-
import { dbNamesOf, isDbReadonly } from '../src/filter/filter-consumer-bridge-to-sql-request';
|
|
3
|
-
import { remult as defaultRemult } from '../src/remult-proxy';
|
|
4
|
-
import { isAutoIncrement } from '../src/remult3';
|
|
5
|
-
import { ValueConverters } from '../src/valueConverters';
|
|
6
|
-
export function postgresColumnSyntax(x, dbName) {
|
|
7
|
-
let result = dbName;
|
|
8
|
-
if (x.valueType == Number) {
|
|
9
|
-
if (!x.valueConverter.fieldTypeInDb)
|
|
10
|
-
result += " numeric" + (x.allowNull ? "" : " default 0 not null");
|
|
11
|
-
else
|
|
12
|
-
result += " " + x.valueConverter.fieldTypeInDb + (x.allowNull ? "" : " default 0 not null");
|
|
13
|
-
}
|
|
14
|
-
else if (x.valueType == Date) {
|
|
15
|
-
if (!x.valueConverter.fieldTypeInDb)
|
|
16
|
-
if (x.valueConverter == ValueConverters.DateOnly)
|
|
17
|
-
result += " date";
|
|
18
|
-
else
|
|
19
|
-
result += " timestamp";
|
|
20
|
-
else
|
|
21
|
-
result += " " + x.valueConverter.fieldTypeInDb;
|
|
22
|
-
}
|
|
23
|
-
else if (x.valueType == Boolean)
|
|
24
|
-
result += " boolean" + (x.allowNull ? "" : " default false not null");
|
|
25
|
-
else if (x.valueConverter.fieldTypeInDb) {
|
|
26
|
-
result += " " + x.valueConverter.fieldTypeInDb;
|
|
27
|
-
if (!x.allowNull && x.valueConverter.fieldTypeInDb == 'integer') {
|
|
28
|
-
result += " default 0 not null";
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
else
|
|
32
|
-
result += " varchar" + (x.allowNull ? "" : " default '' not null");
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
export async function verifyStructureOfAllEntities(db, remult) {
|
|
36
|
-
return await new PostgresSchemaBuilder(db).verifyStructureOfAllEntities(remult);
|
|
37
|
-
}
|
|
38
|
-
export class PostgresSchemaBuilder {
|
|
39
|
-
pool;
|
|
40
|
-
//@internal
|
|
41
|
-
static logToConsole = true;
|
|
42
|
-
async verifyStructureOfAllEntities(remult) {
|
|
43
|
-
if (!remult) {
|
|
44
|
-
remult = defaultRemult;
|
|
45
|
-
}
|
|
46
|
-
const completed = new Set();
|
|
47
|
-
const entities = [];
|
|
48
|
-
for (const entityClass of [...allEntities].reverse()) {
|
|
49
|
-
let entity = remult.repo(entityClass).metadata;
|
|
50
|
-
let e = await dbNamesOf(entity);
|
|
51
|
-
if (completed.has(e.$entityName))
|
|
52
|
-
continue;
|
|
53
|
-
completed.add(e.$entityName);
|
|
54
|
-
entities.push(entity);
|
|
55
|
-
}
|
|
56
|
-
await this.ensureSchema(entities);
|
|
57
|
-
}
|
|
58
|
-
async ensureSchema(entities) {
|
|
59
|
-
for (const entity of entities) {
|
|
60
|
-
let e = await dbNamesOf(entity);
|
|
61
|
-
try {
|
|
62
|
-
if (!entity.options.sqlExpression) {
|
|
63
|
-
if (e.$entityName.toLowerCase().indexOf('from ') < 0) {
|
|
64
|
-
await this.createIfNotExist(entity);
|
|
65
|
-
await this.verifyAllColumns(entity);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
catch (err) {
|
|
70
|
-
console.error("failed verify structure of " + e.$entityName + " ", err);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
async createIfNotExist(entity) {
|
|
75
|
-
var c = this.pool.createCommand();
|
|
76
|
-
let e = await dbNamesOf(entity);
|
|
77
|
-
await c.execute("select 1 from information_Schema.tables where table_name=" + c.addParameterAndReturnSqlToken((e.$entityName).toLowerCase()) + this.additionalWhere).then(async (r) => {
|
|
78
|
-
if (r.rows.length == 0) {
|
|
79
|
-
let result = '';
|
|
80
|
-
for (const x of entity.fields) {
|
|
81
|
-
if (!isDbReadonly(x, e) || isAutoIncrement(x)) {
|
|
82
|
-
if (result.length != 0)
|
|
83
|
-
result += ',';
|
|
84
|
-
result += '\r\n ';
|
|
85
|
-
if (isAutoIncrement(x))
|
|
86
|
-
result += e.$dbNameOf(x) + ' serial';
|
|
87
|
-
else {
|
|
88
|
-
result += postgresColumnSyntax(x, e.$dbNameOf(x));
|
|
89
|
-
}
|
|
90
|
-
if (x == entity.idMetadata.field)
|
|
91
|
-
result += ' primary key';
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
let sql = 'create table ' + e.$entityName + ' (' + result + '\r\n)';
|
|
95
|
-
if (PostgresSchemaBuilder.logToConsole)
|
|
96
|
-
console.info(sql);
|
|
97
|
-
await this.pool.execute(sql);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
async addColumnIfNotExist(entity, c) {
|
|
102
|
-
let e = await dbNamesOf(entity);
|
|
103
|
-
if (isDbReadonly(c(entity), e))
|
|
104
|
-
return;
|
|
105
|
-
try {
|
|
106
|
-
let cmd = this.pool.createCommand();
|
|
107
|
-
const colName = e.$dbNameOf(c(entity));
|
|
108
|
-
if ((await cmd.execute(`select 1
|
|
109
|
-
FROM information_schema.columns
|
|
110
|
-
WHERE table_name=${cmd.addParameterAndReturnSqlToken((e.$entityName).toLocaleLowerCase())} and column_name=${cmd.addParameterAndReturnSqlToken((colName).toLocaleLowerCase())}` + this.additionalWhere)).rows.length == 0) {
|
|
111
|
-
let sql = `alter table ${e.$entityName} add column ${postgresColumnSyntax(c(entity), colName)}`;
|
|
112
|
-
if (PostgresSchemaBuilder.logToConsole)
|
|
113
|
-
console.info(sql);
|
|
114
|
-
await this.pool.execute(sql);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
catch (err) {
|
|
118
|
-
console.error(err);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
async verifyAllColumns(entity) {
|
|
122
|
-
try {
|
|
123
|
-
let cmd = this.pool.createCommand();
|
|
124
|
-
let e = await dbNamesOf(entity);
|
|
125
|
-
let cols = (await cmd.execute(`select column_name
|
|
126
|
-
FROM information_schema.columns
|
|
127
|
-
WHERE table_name=${cmd.addParameterAndReturnSqlToken((e.$entityName).toLocaleLowerCase())} ` + this.additionalWhere)).rows.map(x => x.column_name.toLocaleLowerCase());
|
|
128
|
-
for (const col of entity.fields) {
|
|
129
|
-
if (!isDbReadonly(col, e)) {
|
|
130
|
-
let colName = e.$dbNameOf(col).toLocaleLowerCase();
|
|
131
|
-
if (colName.startsWith('"') && colName.endsWith('"'))
|
|
132
|
-
colName = colName.substring(1, colName.length - 1);
|
|
133
|
-
if (!cols.includes(colName)) {
|
|
134
|
-
let sql = `alter table ${e.$entityName} add column ${postgresColumnSyntax(col, e.$dbNameOf(col))}`;
|
|
135
|
-
if (PostgresSchemaBuilder.logToConsole)
|
|
136
|
-
console.info(sql);
|
|
137
|
-
await this.pool.execute(sql);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
catch (err) {
|
|
143
|
-
console.error(err);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
additionalWhere = '';
|
|
147
|
-
constructor(pool, schema) {
|
|
148
|
-
this.pool = pool;
|
|
149
|
-
if (schema) {
|
|
150
|
-
this.additionalWhere = ' and table_schema=\'' + schema + '\'';
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { RemultServerOptions, RemultServerCore } from "./server/expressBridge";
|
|
2
|
-
export declare function remultFresh(options: RemultServerOptions<FreshRequest>, response: FreshResponse): RemultFresh;
|
|
3
|
-
export interface RemultFresh extends RemultServerCore<FreshRequest> {
|
|
4
|
-
handle(req: FreshRequest, ctx: FreshContext): Promise<any>;
|
|
5
|
-
}
|
|
6
|
-
export interface FreshRequest {
|
|
7
|
-
url: string;
|
|
8
|
-
method: string;
|
|
9
|
-
json: () => Promise<any>;
|
|
10
|
-
}
|
|
11
|
-
export interface FreshContext {
|
|
12
|
-
next: () => Promise<any>;
|
|
13
|
-
}
|
|
14
|
-
export interface FreshResponse {
|
|
15
|
-
new (body?: any | undefined, init?: ResponseInit): any;
|
|
16
|
-
json(data: unknown, init?: ResponseInit): any;
|
|
17
|
-
}
|