remult 0.16.3 → 0.16.4
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/remult-knex/index.js +9 -2
- package/esm/src/backend-tests/backend-database-test-setup.backend-spec.d.ts +1 -0
- package/esm/src/backend-tests/backend-database-test-setup.backend-spec.js +10 -0
- package/esm/src/live-query/EventSourceLiveQuery.d.ts +5 -0
- package/esm/src/live-query/EventSourceLiveQuery.js +48 -0
- package/esm/src/live-query/EventSourceLiveQueryProvider.d.ts +6 -0
- package/esm/src/live-query/EventSourceLiveQueryProvider.js +24 -0
- package/esm/src/live-query/LiveQuery.d.ts +67 -0
- package/esm/src/live-query/LiveQuery.js +222 -0
- package/esm/src/live-query/LiveQueryManager.d.ts +33 -0
- package/esm/src/live-query/LiveQueryManager.js +97 -0
- package/esm/src/shared-tests/db-tests-setup.d.ts +1 -1
- package/esm/src/shared-tests/db-tests-setup.js +1 -0
- package/esm/src/valueConverters.js +2 -0
- package/package.json +1 -1
- package/remult-knex/index.js +16 -8
- package/src/backend-tests/backend-database-test-setup.backend-spec.d.ts +1 -0
- package/src/backend-tests/backend-database-test-setup.backend-spec.js +11 -1
- package/src/live-query/EventSourceLiveQuery.d.ts +5 -0
- package/src/live-query/EventSourceLiveQuery.js +62 -0
- package/src/live-query/EventSourceLiveQueryProvider.d.ts +6 -0
- package/src/live-query/EventSourceLiveQueryProvider.js +32 -0
- package/src/live-query/LiveQuery.d.ts +67 -0
- package/src/live-query/LiveQuery.js +305 -0
- package/src/live-query/LiveQueryManager.d.ts +33 -0
- package/src/live-query/LiveQueryManager.js +196 -0
- package/src/shared-tests/db-tests-setup.d.ts +1 -1
- package/src/shared-tests/db-tests-setup.js +1 -0
- package/src/valueConverters.js +2 -0
- package/esm/postgres/postgresColumnSyntax.d.ts +0 -2
- package/esm/postgres/postgresColumnSyntax.js +0 -30
- package/esm/remult-middleware.d.ts +0 -2
- package/esm/remult-middleware.js +0 -65
- package/esm/server/register-actions-on-server.d.ts +0 -3
- package/esm/server/register-actions-on-server.js +0 -24
- package/esm/server/register-entities-on-server.d.ts +0 -3
- package/esm/server/register-entities-on-server.js +0 -15
- package/esm/valueConverters.d.ts +0 -12
- package/esm/valueConverters.js +0 -169
- package/postgres/postgresColumnSyntax.d.ts +0 -2
- package/postgres/postgresColumnSyntax.js +0 -34
- package/remult-middleware.d.ts +0 -2
- package/remult-middleware.js +0 -70
- package/server/register-actions-on-server.d.ts +0 -3
- package/server/register-actions-on-server.js +0 -50
- package/server/register-entities-on-server.d.ts +0 -3
- package/server/register-entities-on-server.js +0 -19
- package/valueConverters.d.ts +0 -12
- package/valueConverters.js +0 -168
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LiveQueryManager = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var uuid_1 = require("uuid");
|
|
6
|
+
var LiveQueryManager = /** @class */ (function () {
|
|
7
|
+
function LiveQueryManager(dispatcher) {
|
|
8
|
+
this.dispatcher = dispatcher;
|
|
9
|
+
this.clients = [];
|
|
10
|
+
}
|
|
11
|
+
LiveQueryManager.prototype.subscribe = function (repo, clientId, findOptions, remult, ids) {
|
|
12
|
+
var client = this.clients.find(function (c) { return c.clientId === clientId; });
|
|
13
|
+
if (!client) {
|
|
14
|
+
this.clients.push(client = { clientId: clientId, queries: [] });
|
|
15
|
+
}
|
|
16
|
+
var id = uuid_1.v4();
|
|
17
|
+
console.log({ ids: ids });
|
|
18
|
+
client.queries.push({
|
|
19
|
+
id: id,
|
|
20
|
+
findOptions: findOptions,
|
|
21
|
+
repo: repo,
|
|
22
|
+
ids: ids
|
|
23
|
+
});
|
|
24
|
+
return id;
|
|
25
|
+
};
|
|
26
|
+
LiveQueryManager.prototype.sendMessage = function (key, message) {
|
|
27
|
+
var e_1, _a, e_2, _b;
|
|
28
|
+
try {
|
|
29
|
+
for (var _c = tslib_1.__values(this.clients), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
30
|
+
var c = _d.value;
|
|
31
|
+
try {
|
|
32
|
+
for (var _e = (e_2 = void 0, tslib_1.__values(c.queries)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
33
|
+
var q = _f.value;
|
|
34
|
+
if (q.repo.metadata.key === key) {
|
|
35
|
+
this.dispatcher.sendQueryMessage({ clientId: c.clientId, queryId: q.id, message: message });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
40
|
+
finally {
|
|
41
|
+
try {
|
|
42
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
43
|
+
}
|
|
44
|
+
finally { if (e_2) throw e_2.error; }
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
49
|
+
finally {
|
|
50
|
+
try {
|
|
51
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
52
|
+
}
|
|
53
|
+
finally { if (e_1) throw e_1.error; }
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
LiveQueryManager.prototype.hasListeners = function (ref) {
|
|
57
|
+
var e_3, _a, e_4, _b;
|
|
58
|
+
try {
|
|
59
|
+
for (var _c = tslib_1.__values(this.clients), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
60
|
+
var c = _d.value;
|
|
61
|
+
try {
|
|
62
|
+
for (var _e = (e_4 = void 0, tslib_1.__values(c.queries)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
63
|
+
var q = _f.value;
|
|
64
|
+
if (q.repo.metadata.key === ref.metadata.key)
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
69
|
+
finally {
|
|
70
|
+
try {
|
|
71
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
72
|
+
}
|
|
73
|
+
finally { if (e_4) throw e_4.error; }
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
78
|
+
finally {
|
|
79
|
+
try {
|
|
80
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
81
|
+
}
|
|
82
|
+
finally { if (e_3) throw e_3.error; }
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
};
|
|
86
|
+
LiveQueryManager.prototype.runPromise = function (p) {
|
|
87
|
+
};
|
|
88
|
+
//TODO - reconsider usage of zone
|
|
89
|
+
LiveQueryManager.prototype.saved = function (ref) {
|
|
90
|
+
var e_5, _a;
|
|
91
|
+
var _this = this;
|
|
92
|
+
var isNew = ref.isNew();
|
|
93
|
+
var origId = isNew ? ref.getId() : ref.getOriginalId();
|
|
94
|
+
var _loop_1 = function (c) {
|
|
95
|
+
var e_6, _a;
|
|
96
|
+
var _loop_2 = function (q) {
|
|
97
|
+
if (q.repo.metadata.key === ref.metadata.key) {
|
|
98
|
+
this_1.runPromise(q.repo.find(q.findOptions).then(function (currentItems) {
|
|
99
|
+
var e_7, _a, e_8, _b;
|
|
100
|
+
var currentIds = currentItems.map(function (x) { return q.repo.getEntityRef(x).getId(); });
|
|
101
|
+
var sendMessage = function (message) {
|
|
102
|
+
console.log({ message: message.type });
|
|
103
|
+
_this.dispatcher.sendQueryMessage({ clientId: c.clientId, queryId: q.id, message: message });
|
|
104
|
+
};
|
|
105
|
+
console.log({ ids: q.ids, currentIds: currentIds });
|
|
106
|
+
try {
|
|
107
|
+
for (var _c = (e_7 = void 0, tslib_1.__values(q.ids.filter(function (y) { return !currentIds.includes(y); }))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
108
|
+
var id = _d.value;
|
|
109
|
+
if (id != origId || !currentIds.includes(ref.getId()))
|
|
110
|
+
sendMessage({
|
|
111
|
+
type: "remove",
|
|
112
|
+
data: {
|
|
113
|
+
id: id
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
119
|
+
finally {
|
|
120
|
+
try {
|
|
121
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
122
|
+
}
|
|
123
|
+
finally { if (e_7) throw e_7.error; }
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
for (var currentItems_1 = (e_8 = void 0, tslib_1.__values(currentItems)), currentItems_1_1 = currentItems_1.next(); !currentItems_1_1.done; currentItems_1_1 = currentItems_1.next()) {
|
|
127
|
+
var item = currentItems_1_1.value;
|
|
128
|
+
var itemRef = q.repo.getEntityRef(item);
|
|
129
|
+
if (itemRef.getId() == ref.getId() && q.ids.includes(origId)) {
|
|
130
|
+
sendMessage({
|
|
131
|
+
type: "replace",
|
|
132
|
+
data: {
|
|
133
|
+
oldId: origId,
|
|
134
|
+
item: itemRef.toApiJson()
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
else if (!q.ids.includes(itemRef.getId())) {
|
|
139
|
+
sendMessage({
|
|
140
|
+
type: "add",
|
|
141
|
+
data: { item: itemRef.toApiJson() }
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
147
|
+
finally {
|
|
148
|
+
try {
|
|
149
|
+
if (currentItems_1_1 && !currentItems_1_1.done && (_b = currentItems_1.return)) _b.call(currentItems_1);
|
|
150
|
+
}
|
|
151
|
+
finally { if (e_8) throw e_8.error; }
|
|
152
|
+
}
|
|
153
|
+
q.ids = currentIds;
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
try {
|
|
158
|
+
for (var _b = (e_6 = void 0, tslib_1.__values(c.queries)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
159
|
+
var q = _c.value;
|
|
160
|
+
_loop_2(q);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
164
|
+
finally {
|
|
165
|
+
try {
|
|
166
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
167
|
+
}
|
|
168
|
+
finally { if (e_6) throw e_6.error; }
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
var this_1 = this;
|
|
172
|
+
try {
|
|
173
|
+
for (var _b = tslib_1.__values(this.clients), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
174
|
+
var c = _c.value;
|
|
175
|
+
_loop_1(c);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
179
|
+
finally {
|
|
180
|
+
try {
|
|
181
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
182
|
+
}
|
|
183
|
+
finally { if (e_5) throw e_5.error; }
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
LiveQueryManager.prototype.deleted = function (ref) {
|
|
187
|
+
if (!this.hasListeners(ref))
|
|
188
|
+
return;
|
|
189
|
+
this.sendMessage(ref.metadata.key, {
|
|
190
|
+
type: "remove",
|
|
191
|
+
data: { id: ref.getId() }
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
return LiveQueryManager;
|
|
195
|
+
}());
|
|
196
|
+
exports.LiveQueryManager = LiveQueryManager;
|
|
@@ -6,7 +6,7 @@ import { CategoriesForTesting } from "../tests/remult-3-entities";
|
|
|
6
6
|
import { Status } from "../tests/testModel/models";
|
|
7
7
|
export declare function itWithFocus(key: string, what: () => Promise<void>, focus?: boolean): void;
|
|
8
8
|
export declare function testAll(key: string, what: dbTestWhatSignature, focus?: boolean): void;
|
|
9
|
-
export declare function addDatabaseToTest(tester: dbTestMethodSignature):
|
|
9
|
+
export declare function addDatabaseToTest(tester: dbTestMethodSignature): dbTestMethodSignature;
|
|
10
10
|
export declare function testInMemory(key: string, what: dbTestWhatSignature, focus?: boolean): void;
|
|
11
11
|
export declare type dbTestWhatSignature = (db: {
|
|
12
12
|
db: DataProvider;
|
package/src/valueConverters.js
CHANGED
|
@@ -101,6 +101,8 @@ var ValueConverters = /** @class */ (function () {
|
|
|
101
101
|
fromJson: function (value) {
|
|
102
102
|
if (typeof value === "boolean")
|
|
103
103
|
return value;
|
|
104
|
+
if (value === 1)
|
|
105
|
+
return true;
|
|
104
106
|
if (value !== undefined && value !== null) {
|
|
105
107
|
return value.toString().trim().toLowerCase() == 'true';
|
|
106
108
|
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ValueConverters } from '../valueConverters';
|
|
2
|
-
export function postgresColumnSyntax(x, dbName) {
|
|
3
|
-
let result = dbName;
|
|
4
|
-
if (x.valueType == Number) {
|
|
5
|
-
if (!x.valueConverter.fieldTypeInDb)
|
|
6
|
-
result += " numeric" + (x.allowNull ? "" : " default 0 not null");
|
|
7
|
-
else
|
|
8
|
-
result += " " + x.valueConverter.fieldTypeInDb + (x.allowNull ? "" : " default 0 not null");
|
|
9
|
-
}
|
|
10
|
-
else if (x.valueType == Date) {
|
|
11
|
-
if (!x.valueConverter.fieldTypeInDb)
|
|
12
|
-
if (x.valueConverter == ValueConverters.DateOnly)
|
|
13
|
-
result += " date";
|
|
14
|
-
else
|
|
15
|
-
result += " timestamp";
|
|
16
|
-
else
|
|
17
|
-
result += " " + x.valueConverter.fieldTypeInDb;
|
|
18
|
-
}
|
|
19
|
-
else if (x.valueType == Boolean)
|
|
20
|
-
result += " boolean" + (x.allowNull ? "" : " default false not null");
|
|
21
|
-
else if (x.valueConverter.fieldTypeInDb) {
|
|
22
|
-
result += " " + x.valueConverter.fieldTypeInDb;
|
|
23
|
-
if (!x.allowNull && x.valueConverter.fieldTypeInDb == 'integer') {
|
|
24
|
-
result += " default 0 not null";
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
else
|
|
28
|
-
result += " varchar" + (x.allowNull ? "" : " default '' not null");
|
|
29
|
-
return result;
|
|
30
|
-
}
|
package/esm/remult-middleware.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { remultMiddlewareBase } from './server/expressBridge';
|
|
2
|
-
export function remultMiddleware(options) {
|
|
3
|
-
const m = new middleware();
|
|
4
|
-
let app = Object.assign((req, res, next) => m.handleRequest(req, res, next), {
|
|
5
|
-
route: (path) => m.route(path)
|
|
6
|
-
});
|
|
7
|
-
return remultMiddlewareBase(app, options);
|
|
8
|
-
}
|
|
9
|
-
class middleware {
|
|
10
|
-
constructor() {
|
|
11
|
-
this.map = new Map();
|
|
12
|
-
}
|
|
13
|
-
route(path) {
|
|
14
|
-
//consider using:
|
|
15
|
-
//* https://raw.githubusercontent.com/cmorten/opine/main/src/utils/pathToRegex.ts
|
|
16
|
-
//* https://github.com/pillarjs/path-to-regexp
|
|
17
|
-
let r = path.toLowerCase();
|
|
18
|
-
let m = new Map();
|
|
19
|
-
this.map.set(r, m);
|
|
20
|
-
const route = {
|
|
21
|
-
get: (h) => {
|
|
22
|
-
m.set("get", h);
|
|
23
|
-
return route;
|
|
24
|
-
},
|
|
25
|
-
put: (h) => {
|
|
26
|
-
m.set("put", h);
|
|
27
|
-
return route;
|
|
28
|
-
},
|
|
29
|
-
post: (h) => {
|
|
30
|
-
m.set("post", h);
|
|
31
|
-
return route;
|
|
32
|
-
},
|
|
33
|
-
delete: (h) => {
|
|
34
|
-
m.set("delete", h);
|
|
35
|
-
return route;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
return route;
|
|
39
|
-
}
|
|
40
|
-
handleRequest(req, res, next) {
|
|
41
|
-
let lowerPath = req.path.toLowerCase();
|
|
42
|
-
let m = this.map.get(lowerPath);
|
|
43
|
-
if (m) {
|
|
44
|
-
let h = m.get(req.method.toLowerCase());
|
|
45
|
-
if (h) {
|
|
46
|
-
h(req, res, next);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
let idPosition = req.path.lastIndexOf('/');
|
|
51
|
-
if (idPosition >= 0) {
|
|
52
|
-
lowerPath = req.path.substring(0, idPosition) + '/:id';
|
|
53
|
-
m = this.map.get(lowerPath);
|
|
54
|
-
if (m) {
|
|
55
|
-
let h = m.get(req.method.toLowerCase());
|
|
56
|
-
if (h) {
|
|
57
|
-
req.params.id = req.path.substring(idPosition + 1);
|
|
58
|
-
h(req, res, next);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
next();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { serverActionField, actionInfo, classBackendMethodsArray } from '../src/server-action';
|
|
2
|
-
export function registerActionsOnServer(area, controllers) {
|
|
3
|
-
var addAction = (a) => {
|
|
4
|
-
let x = a[serverActionField];
|
|
5
|
-
if (!x) {
|
|
6
|
-
throw 'failed to set server action, did you forget the BackendMethod Decorator?';
|
|
7
|
-
}
|
|
8
|
-
area.addAction(x);
|
|
9
|
-
};
|
|
10
|
-
actionInfo.runningOnServer = true;
|
|
11
|
-
if (controllers && controllers.length > 0) {
|
|
12
|
-
for (const c of controllers) {
|
|
13
|
-
let z = c[classBackendMethodsArray];
|
|
14
|
-
if (z)
|
|
15
|
-
for (const a of z) {
|
|
16
|
-
addAction(a);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
else
|
|
21
|
-
actionInfo.allActions.forEach((a) => {
|
|
22
|
-
addAction(a);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { getEntityKey } from "../src/remult3";
|
|
2
|
-
import { allEntities } from "../src/context";
|
|
3
|
-
import { DataApi } from "../src/data-api";
|
|
4
|
-
export function registerEntitiesOnServer(area, entities) {
|
|
5
|
-
if (!entities)
|
|
6
|
-
entities = allEntities;
|
|
7
|
-
//add Api Entries
|
|
8
|
-
entities.forEach(e => {
|
|
9
|
-
let key = getEntityKey(e);
|
|
10
|
-
if (key != undefined)
|
|
11
|
-
area.add(key, c => {
|
|
12
|
-
return new DataApi(c.repo(e), c);
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
}
|
package/esm/valueConverters.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ValueConverter } from "./src/column-interfaces";
|
|
2
|
-
export declare class ValueConverters {
|
|
3
|
-
static readonly Date: ValueConverter<Date>;
|
|
4
|
-
static readonly DateOnly: ValueConverter<Date>;
|
|
5
|
-
static readonly DateOnlyString: ValueConverter<Date>;
|
|
6
|
-
static readonly Boolean: ValueConverter<Boolean>;
|
|
7
|
-
static readonly Number: ValueConverter<number>;
|
|
8
|
-
static readonly Integer: ValueConverter<number>;
|
|
9
|
-
static readonly Default: ValueConverter<any>;
|
|
10
|
-
static readonly JsonString: ValueConverter<any>;
|
|
11
|
-
static readonly JsonValue: ValueConverter<any>;
|
|
12
|
-
}
|
package/esm/valueConverters.js
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { InputTypes } from "./inputTypes";
|
|
2
|
-
export class ValueConverters {
|
|
3
|
-
}
|
|
4
|
-
ValueConverters.Date = {
|
|
5
|
-
toJson: (val) => {
|
|
6
|
-
if (!val)
|
|
7
|
-
return '';
|
|
8
|
-
if (typeof (val) === "string")
|
|
9
|
-
val = new Date(val);
|
|
10
|
-
if (val instanceof Date) {
|
|
11
|
-
return val.toISOString();
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
console.log("ToJsonError", val);
|
|
15
|
-
throw new Error("Expected date but got val");
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
fromJson: (val) => {
|
|
19
|
-
if (val == undefined)
|
|
20
|
-
return undefined;
|
|
21
|
-
if (val == '')
|
|
22
|
-
return undefined;
|
|
23
|
-
if (val.startsWith('0000-00-00'))
|
|
24
|
-
return undefined;
|
|
25
|
-
return new Date(Date.parse(val));
|
|
26
|
-
},
|
|
27
|
-
toDb: x => x,
|
|
28
|
-
fromDb: x => x,
|
|
29
|
-
fromInput: x => ValueConverters.Date.fromJson(x),
|
|
30
|
-
toInput: x => ValueConverters.Date.toJson(x),
|
|
31
|
-
displayValue: (val) => {
|
|
32
|
-
if (!val)
|
|
33
|
-
return '';
|
|
34
|
-
return val.toLocaleString();
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
ValueConverters.DateOnly = {
|
|
38
|
-
fromInput: x => ValueConverters.DateOnly.fromJson(x),
|
|
39
|
-
toInput: x => ValueConverters.DateOnly.toJson(x),
|
|
40
|
-
toJson: (val) => {
|
|
41
|
-
var d = val;
|
|
42
|
-
if (typeof d === "string" || typeof (d) === "number")
|
|
43
|
-
d = new Date(d);
|
|
44
|
-
if (!d || d == null)
|
|
45
|
-
return null;
|
|
46
|
-
if (d.getHours() == 0)
|
|
47
|
-
return new Date(d.valueOf() - d.getTimezoneOffset() * 60000).toISOString().substring(0, 10);
|
|
48
|
-
else
|
|
49
|
-
return d.toISOString().substring(0, 10);
|
|
50
|
-
},
|
|
51
|
-
fromJson: (value) => {
|
|
52
|
-
if (!value || value == '' || value == '0000-00-00')
|
|
53
|
-
return null;
|
|
54
|
-
let d = new Date(Date.parse(value));
|
|
55
|
-
d.setMinutes(d.getMinutes() + d.getTimezoneOffset());
|
|
56
|
-
return d;
|
|
57
|
-
},
|
|
58
|
-
inputType: InputTypes.date,
|
|
59
|
-
toDb: (val) => {
|
|
60
|
-
if (!val)
|
|
61
|
-
return null;
|
|
62
|
-
return ValueConverters.DateOnly.fromJson(ValueConverters.DateOnly.toJson(val));
|
|
63
|
-
} //when using date storage, the database expects and returns a date local and every where else we reflect on date iso
|
|
64
|
-
,
|
|
65
|
-
fromDb: (val) => {
|
|
66
|
-
var d = val;
|
|
67
|
-
if (!d)
|
|
68
|
-
return null;
|
|
69
|
-
return val;
|
|
70
|
-
},
|
|
71
|
-
fieldTypeInDb: 'date',
|
|
72
|
-
displayValue: (value) => {
|
|
73
|
-
if (!value)
|
|
74
|
-
return '';
|
|
75
|
-
return value.toLocaleDateString(undefined);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
ValueConverters.DateOnlyString = {
|
|
79
|
-
...ValueConverters.DateOnly,
|
|
80
|
-
toDb: (d) => {
|
|
81
|
-
let val = ValueConverters.DateOnly.toJson(d);
|
|
82
|
-
if (!val)
|
|
83
|
-
return undefined;
|
|
84
|
-
return val.replace(/-/g, '');
|
|
85
|
-
},
|
|
86
|
-
fromDb: (val) => {
|
|
87
|
-
if (val === null)
|
|
88
|
-
return null;
|
|
89
|
-
if (!val)
|
|
90
|
-
return undefined;
|
|
91
|
-
return new Date(val.substring(0, 4) + '-' + val.substring(4, 6) + '-' + val.substring(6, 8));
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
ValueConverters.Boolean = {
|
|
95
|
-
toDb: (val) => val,
|
|
96
|
-
inputType: InputTypes.checkbox,
|
|
97
|
-
fromDb: (value) => {
|
|
98
|
-
return ValueConverters.Boolean.fromJson(value);
|
|
99
|
-
},
|
|
100
|
-
fromJson: value => {
|
|
101
|
-
if (typeof value === "boolean")
|
|
102
|
-
return value;
|
|
103
|
-
if (value !== undefined && value !== null) {
|
|
104
|
-
return value.toString().trim().toLowerCase() == 'true';
|
|
105
|
-
}
|
|
106
|
-
return value;
|
|
107
|
-
},
|
|
108
|
-
toJson: x => x,
|
|
109
|
-
fromInput: x => ValueConverters.Boolean.fromJson(x),
|
|
110
|
-
toInput: x => ValueConverters.Boolean.toJson(x)
|
|
111
|
-
};
|
|
112
|
-
ValueConverters.Number = {
|
|
113
|
-
fromDb: value => {
|
|
114
|
-
if (value === null)
|
|
115
|
-
return null;
|
|
116
|
-
if (value !== undefined)
|
|
117
|
-
return +value;
|
|
118
|
-
return undefined;
|
|
119
|
-
},
|
|
120
|
-
toDb: value => value,
|
|
121
|
-
fromJson: value => ValueConverters.Number.fromDb(value),
|
|
122
|
-
toJson: value => ValueConverters.Number.toDb(value),
|
|
123
|
-
fromInput: (x, type) => {
|
|
124
|
-
let r = +x;
|
|
125
|
-
if (!x)
|
|
126
|
-
return undefined;
|
|
127
|
-
return r;
|
|
128
|
-
},
|
|
129
|
-
toInput: (x, type) => {
|
|
130
|
-
return x?.toString();
|
|
131
|
-
},
|
|
132
|
-
inputType: InputTypes.number
|
|
133
|
-
};
|
|
134
|
-
ValueConverters.Integer = {
|
|
135
|
-
...ValueConverters.Number,
|
|
136
|
-
toJson: value => {
|
|
137
|
-
let val = ValueConverters.Number.toDb(value);
|
|
138
|
-
if (!val)
|
|
139
|
-
return val;
|
|
140
|
-
return +(+val).toFixed(0);
|
|
141
|
-
},
|
|
142
|
-
toDb: value => ValueConverters.Integer.toJson(value),
|
|
143
|
-
fieldTypeInDb: 'integer'
|
|
144
|
-
};
|
|
145
|
-
ValueConverters.Default = {
|
|
146
|
-
fromJson: x => x,
|
|
147
|
-
toJson: x => x,
|
|
148
|
-
fromDb: x => ValueConverters.JsonString.fromDb(x),
|
|
149
|
-
toDb: x => ValueConverters.JsonString.toDb(x),
|
|
150
|
-
fromInput: x => ValueConverters.Default.fromJson(x),
|
|
151
|
-
toInput: x => ValueConverters.Default.toJson(x)
|
|
152
|
-
};
|
|
153
|
-
ValueConverters.JsonString = {
|
|
154
|
-
fromJson: x => x,
|
|
155
|
-
toJson: x => x,
|
|
156
|
-
fromDb: x => x == null ? null : x ? JSON.parse(ValueConverters.JsonString.fromJson(x)) : undefined,
|
|
157
|
-
toDb: x => x !== undefined ? x === null ? null : JSON.stringify(ValueConverters.JsonString.toJson(x)) : undefined,
|
|
158
|
-
fromInput: x => ValueConverters.JsonString.fromJson(x),
|
|
159
|
-
toInput: x => ValueConverters.JsonString.toJson(x)
|
|
160
|
-
};
|
|
161
|
-
ValueConverters.JsonValue = {
|
|
162
|
-
fromJson: x => x,
|
|
163
|
-
toJson: x => x,
|
|
164
|
-
fromDb: x => x,
|
|
165
|
-
toDb: x => x,
|
|
166
|
-
fromInput: x => ValueConverters.JsonString.fromJson(x),
|
|
167
|
-
toInput: x => ValueConverters.JsonString.toJson(x),
|
|
168
|
-
fieldTypeInDb: 'json'
|
|
169
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.postgresColumnSyntax = void 0;
|
|
4
|
-
var valueConverters_1 = require("../valueConverters");
|
|
5
|
-
function postgresColumnSyntax(x, dbName) {
|
|
6
|
-
var result = dbName;
|
|
7
|
-
if (x.valueType == Number) {
|
|
8
|
-
if (!x.valueConverter.fieldTypeInDb)
|
|
9
|
-
result += " numeric" + (x.allowNull ? "" : " default 0 not null");
|
|
10
|
-
else
|
|
11
|
-
result += " " + x.valueConverter.fieldTypeInDb + (x.allowNull ? "" : " default 0 not null");
|
|
12
|
-
}
|
|
13
|
-
else if (x.valueType == Date) {
|
|
14
|
-
if (!x.valueConverter.fieldTypeInDb)
|
|
15
|
-
if (x.valueConverter == valueConverters_1.ValueConverters.DateOnly)
|
|
16
|
-
result += " date";
|
|
17
|
-
else
|
|
18
|
-
result += " timestamp";
|
|
19
|
-
else
|
|
20
|
-
result += " " + x.valueConverter.fieldTypeInDb;
|
|
21
|
-
}
|
|
22
|
-
else if (x.valueType == Boolean)
|
|
23
|
-
result += " boolean" + (x.allowNull ? "" : " default false not null");
|
|
24
|
-
else if (x.valueConverter.fieldTypeInDb) {
|
|
25
|
-
result += " " + x.valueConverter.fieldTypeInDb;
|
|
26
|
-
if (!x.allowNull && x.valueConverter.fieldTypeInDb == 'integer') {
|
|
27
|
-
result += " default 0 not null";
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
else
|
|
31
|
-
result += " varchar" + (x.allowNull ? "" : " default '' not null");
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
|
-
exports.postgresColumnSyntax = postgresColumnSyntax;
|
package/remult-middleware.d.ts
DELETED
package/remult-middleware.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.remultMiddleware = void 0;
|
|
4
|
-
var expressBridge_1 = require("./server/expressBridge");
|
|
5
|
-
function remultMiddleware(options) {
|
|
6
|
-
var m = new middleware();
|
|
7
|
-
var app = Object.assign(function (req, res, next) { return m.handleRequest(req, res, next); }, {
|
|
8
|
-
route: function (path) { return m.route(path); }
|
|
9
|
-
});
|
|
10
|
-
return expressBridge_1.remultMiddlewareBase(app, options);
|
|
11
|
-
}
|
|
12
|
-
exports.remultMiddleware = remultMiddleware;
|
|
13
|
-
var middleware = /** @class */ (function () {
|
|
14
|
-
function middleware() {
|
|
15
|
-
this.map = new Map();
|
|
16
|
-
}
|
|
17
|
-
middleware.prototype.route = function (path) {
|
|
18
|
-
//consider using:
|
|
19
|
-
//* https://raw.githubusercontent.com/cmorten/opine/main/src/utils/pathToRegex.ts
|
|
20
|
-
//* https://github.com/pillarjs/path-to-regexp
|
|
21
|
-
var r = path.toLowerCase();
|
|
22
|
-
var m = new Map();
|
|
23
|
-
this.map.set(r, m);
|
|
24
|
-
var route = {
|
|
25
|
-
get: function (h) {
|
|
26
|
-
m.set("get", h);
|
|
27
|
-
return route;
|
|
28
|
-
},
|
|
29
|
-
put: function (h) {
|
|
30
|
-
m.set("put", h);
|
|
31
|
-
return route;
|
|
32
|
-
},
|
|
33
|
-
post: function (h) {
|
|
34
|
-
m.set("post", h);
|
|
35
|
-
return route;
|
|
36
|
-
},
|
|
37
|
-
delete: function (h) {
|
|
38
|
-
m.set("delete", h);
|
|
39
|
-
return route;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
return route;
|
|
43
|
-
};
|
|
44
|
-
middleware.prototype.handleRequest = function (req, res, next) {
|
|
45
|
-
var lowerPath = req.path.toLowerCase();
|
|
46
|
-
var m = this.map.get(lowerPath);
|
|
47
|
-
if (m) {
|
|
48
|
-
var h = m.get(req.method.toLowerCase());
|
|
49
|
-
if (h) {
|
|
50
|
-
h(req, res, next);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
var idPosition = req.path.lastIndexOf('/');
|
|
55
|
-
if (idPosition >= 0) {
|
|
56
|
-
lowerPath = req.path.substring(0, idPosition) + '/:id';
|
|
57
|
-
m = this.map.get(lowerPath);
|
|
58
|
-
if (m) {
|
|
59
|
-
var h = m.get(req.method.toLowerCase());
|
|
60
|
-
if (h) {
|
|
61
|
-
req.params.id = req.path.substring(idPosition + 1);
|
|
62
|
-
h(req, res, next);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
next();
|
|
68
|
-
};
|
|
69
|
-
return middleware;
|
|
70
|
-
}());
|