remult 0.14.32 → 0.14.35
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/{readme.md → README.md} +0 -0
- package/esm/remult-express.js +2 -2
- package/esm/remult-fastify.js +2 -2
- package/esm/remult-fresh.d.ts +8 -3
- package/esm/remult-fresh.js +8 -7
- package/esm/server/JsonEntityFileStorage.d.ts +4 -1
- package/esm/server/JsonEntityFileStorage.js +4 -0
- package/esm/server/expressBridge.d.ts +2 -9
- package/esm/server/expressBridge.js +4 -8
- package/esm/server/index.d.ts +2 -2
- package/esm/server/index.js +2 -2
- package/esm/src/backend-tests/test-http-server.backend-spec.js +37 -6
- package/package.json +1 -1
- package/remult-express.js +1 -1
- package/remult-fastify.js +1 -1
- package/remult-fresh.d.ts +8 -3
- package/remult-fresh.js +7 -6
- package/server/JsonEntityFileStorage.d.ts +4 -1
- package/server/JsonEntityFileStorage.js +11 -1
- package/server/expressBridge.d.ts +2 -9
- package/server/expressBridge.js +14 -13
- package/server/index.d.ts +2 -2
- package/server/index.js +4 -3
- package/src/backend-tests/test-http-server.backend-spec.js +47 -6
- package/esm/remult-middleware.d.ts +0 -10
- package/esm/remult-middleware.js +0 -117
- 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 -10
- package/remult-middleware.js +0 -131
- 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
package/esm/remult-middleware.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { buildRemultServer } from './server/expressBridge';
|
|
2
|
-
export function remultMiddleware(options) {
|
|
3
|
-
const m = new middleware();
|
|
4
|
-
const server = buildRemultServer(m, options);
|
|
5
|
-
return Object.assign((req, res, next) => m.handleRequest(req, res, next), {
|
|
6
|
-
getRemult: (req) => server.getRemult(req),
|
|
7
|
-
openApiDoc: (options) => server.openApiDoc(options),
|
|
8
|
-
addArea: x => server.addArea(x),
|
|
9
|
-
handle: (req, res) => m.handle(req, res)
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
class middleware {
|
|
13
|
-
constructor() {
|
|
14
|
-
this.map = new Map();
|
|
15
|
-
}
|
|
16
|
-
route(path) {
|
|
17
|
-
//consider using:
|
|
18
|
-
//* https://raw.githubusercontent.com/cmorten/opine/main/src/utils/pathToRegex.ts
|
|
19
|
-
//* https://github.com/pillarjs/path-to-regexp
|
|
20
|
-
let r = path.toLowerCase();
|
|
21
|
-
let m = new Map();
|
|
22
|
-
this.map.set(r, m);
|
|
23
|
-
const route = {
|
|
24
|
-
get: (h) => {
|
|
25
|
-
m.set("get", h);
|
|
26
|
-
return route;
|
|
27
|
-
},
|
|
28
|
-
put: (h) => {
|
|
29
|
-
m.set("put", h);
|
|
30
|
-
return route;
|
|
31
|
-
},
|
|
32
|
-
post: (h) => {
|
|
33
|
-
m.set("post", h);
|
|
34
|
-
return route;
|
|
35
|
-
},
|
|
36
|
-
delete: (h) => {
|
|
37
|
-
m.set("delete", h);
|
|
38
|
-
return route;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
return route;
|
|
42
|
-
}
|
|
43
|
-
async handle(req, gRes) {
|
|
44
|
-
return new Promise(res => {
|
|
45
|
-
const response = new class {
|
|
46
|
-
json(data) {
|
|
47
|
-
if (gRes !== undefined)
|
|
48
|
-
gRes.json(data);
|
|
49
|
-
res({ statusCode: this.statusCode, data });
|
|
50
|
-
}
|
|
51
|
-
status(statusCode) {
|
|
52
|
-
if (gRes !== undefined)
|
|
53
|
-
gRes.status(statusCode);
|
|
54
|
-
this.statusCode = statusCode;
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
end() {
|
|
58
|
-
if (gRes !== undefined)
|
|
59
|
-
gRes.end();
|
|
60
|
-
res({
|
|
61
|
-
statusCode: this.statusCode
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
this.handleRequest(req, response, () => res(undefined));
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
handleRequest(req, res, next) {
|
|
69
|
-
let theUrl = req.url;
|
|
70
|
-
if (theUrl.startsWith('/')) //next sends a partial url '/api/tasks' and not the full url
|
|
71
|
-
theUrl = 'http://stam' + theUrl;
|
|
72
|
-
const url = new URL(theUrl);
|
|
73
|
-
const path = url.pathname;
|
|
74
|
-
if (!req.query) {
|
|
75
|
-
let query = {};
|
|
76
|
-
url.searchParams.forEach((val, key) => {
|
|
77
|
-
let current = query[key];
|
|
78
|
-
if (!current) {
|
|
79
|
-
query[key] = val;
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
if (Array.isArray(current)) {
|
|
83
|
-
current.push(val);
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
query[key] = [current, val];
|
|
87
|
-
});
|
|
88
|
-
req.query = query;
|
|
89
|
-
}
|
|
90
|
-
let lowerPath = path.toLowerCase();
|
|
91
|
-
let m = this.map.get(lowerPath);
|
|
92
|
-
if (m) {
|
|
93
|
-
let h = m.get(req.method.toLowerCase());
|
|
94
|
-
if (h) {
|
|
95
|
-
h(req, res, next);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
let idPosition = path.lastIndexOf('/');
|
|
100
|
-
if (idPosition >= 0) {
|
|
101
|
-
lowerPath = path.substring(0, idPosition) + '/:id';
|
|
102
|
-
m = this.map.get(lowerPath);
|
|
103
|
-
if (m) {
|
|
104
|
-
let h = m.get(req.method.toLowerCase());
|
|
105
|
-
if (h) {
|
|
106
|
-
if (!req.params)
|
|
107
|
-
req.params = {};
|
|
108
|
-
req.params.id = path.substring(idPosition + 1);
|
|
109
|
-
h(req, res, next);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
next();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
export { buildRemultServer };
|
|
@@ -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
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { GenericRequest, GenericMiddleware, GenericResponse, GenericRouter, buildRemultServer, RemultServerOptions, SpecificRoute, RemultServer } from './server/expressBridge';
|
|
2
|
-
export declare function remultMiddleware(options?: RemultServerOptions): RemultMiddleware;
|
|
3
|
-
export interface RemultMiddleware extends GenericMiddleware, RemultServer {
|
|
4
|
-
handle(req: GenericRequest, gRes?: GenericResponse): Promise<MiddlewareResponse>;
|
|
5
|
-
}
|
|
6
|
-
export interface MiddlewareResponse {
|
|
7
|
-
data?: any;
|
|
8
|
-
statusCode?: number;
|
|
9
|
-
}
|
|
10
|
-
export { GenericRequest, GenericMiddleware as GenericRequestHandler, GenericResponse, GenericRouter, buildRemultServer, RemultServerOptions as RemultMiddlewareOptions, SpecificRoute, RemultServer };
|
package/remult-middleware.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildRemultServer = exports.remultMiddleware = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var expressBridge_1 = require("./server/expressBridge");
|
|
6
|
-
Object.defineProperty(exports, "buildRemultServer", { enumerable: true, get: function () { return expressBridge_1.buildRemultServer; } });
|
|
7
|
-
function remultMiddleware(options) {
|
|
8
|
-
var m = new middleware();
|
|
9
|
-
var server = expressBridge_1.buildRemultServer(m, options);
|
|
10
|
-
return Object.assign(function (req, res, next) { return m.handleRequest(req, res, next); }, {
|
|
11
|
-
getRemult: function (req) { return server.getRemult(req); },
|
|
12
|
-
openApiDoc: function (options) { return server.openApiDoc(options); },
|
|
13
|
-
addArea: function (x) { return server.addArea(x); },
|
|
14
|
-
handle: function (req, res) { return m.handle(req, res); }
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
exports.remultMiddleware = remultMiddleware;
|
|
18
|
-
var middleware = /** @class */ (function () {
|
|
19
|
-
function middleware() {
|
|
20
|
-
this.map = new Map();
|
|
21
|
-
}
|
|
22
|
-
middleware.prototype.route = function (path) {
|
|
23
|
-
//consider using:
|
|
24
|
-
//* https://raw.githubusercontent.com/cmorten/opine/main/src/utils/pathToRegex.ts
|
|
25
|
-
//* https://github.com/pillarjs/path-to-regexp
|
|
26
|
-
var r = path.toLowerCase();
|
|
27
|
-
var m = new Map();
|
|
28
|
-
this.map.set(r, m);
|
|
29
|
-
var route = {
|
|
30
|
-
get: function (h) {
|
|
31
|
-
m.set("get", h);
|
|
32
|
-
return route;
|
|
33
|
-
},
|
|
34
|
-
put: function (h) {
|
|
35
|
-
m.set("put", h);
|
|
36
|
-
return route;
|
|
37
|
-
},
|
|
38
|
-
post: function (h) {
|
|
39
|
-
m.set("post", h);
|
|
40
|
-
return route;
|
|
41
|
-
},
|
|
42
|
-
delete: function (h) {
|
|
43
|
-
m.set("delete", h);
|
|
44
|
-
return route;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
return route;
|
|
48
|
-
};
|
|
49
|
-
middleware.prototype.handle = function (req, gRes) {
|
|
50
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
51
|
-
var _this = this;
|
|
52
|
-
return tslib_1.__generator(this, function (_a) {
|
|
53
|
-
return [2 /*return*/, new Promise(function (res) {
|
|
54
|
-
var response = new /** @class */ (function () {
|
|
55
|
-
function class_1() {
|
|
56
|
-
}
|
|
57
|
-
class_1.prototype.json = function (data) {
|
|
58
|
-
if (gRes !== undefined)
|
|
59
|
-
gRes.json(data);
|
|
60
|
-
res({ statusCode: this.statusCode, data: data });
|
|
61
|
-
};
|
|
62
|
-
class_1.prototype.status = function (statusCode) {
|
|
63
|
-
if (gRes !== undefined)
|
|
64
|
-
gRes.status(statusCode);
|
|
65
|
-
this.statusCode = statusCode;
|
|
66
|
-
return this;
|
|
67
|
-
};
|
|
68
|
-
class_1.prototype.end = function () {
|
|
69
|
-
if (gRes !== undefined)
|
|
70
|
-
gRes.end();
|
|
71
|
-
res({
|
|
72
|
-
statusCode: this.statusCode
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
return class_1;
|
|
76
|
-
}());
|
|
77
|
-
_this.handleRequest(req, response, function () { return res(undefined); });
|
|
78
|
-
})];
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
};
|
|
82
|
-
middleware.prototype.handleRequest = function (req, res, next) {
|
|
83
|
-
var theUrl = req.url;
|
|
84
|
-
if (theUrl.startsWith('/')) //next sends a partial url '/api/tasks' and not the full url
|
|
85
|
-
theUrl = 'http://stam' + theUrl;
|
|
86
|
-
var url = new URL(theUrl);
|
|
87
|
-
var path = url.pathname;
|
|
88
|
-
if (!req.query) {
|
|
89
|
-
var query_1 = {};
|
|
90
|
-
url.searchParams.forEach(function (val, key) {
|
|
91
|
-
var current = query_1[key];
|
|
92
|
-
if (!current) {
|
|
93
|
-
query_1[key] = val;
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if (Array.isArray(current)) {
|
|
97
|
-
current.push(val);
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
query_1[key] = [current, val];
|
|
101
|
-
});
|
|
102
|
-
req.query = query_1;
|
|
103
|
-
}
|
|
104
|
-
var lowerPath = path.toLowerCase();
|
|
105
|
-
var m = this.map.get(lowerPath);
|
|
106
|
-
if (m) {
|
|
107
|
-
var h = m.get(req.method.toLowerCase());
|
|
108
|
-
if (h) {
|
|
109
|
-
h(req, res, next);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
var idPosition = path.lastIndexOf('/');
|
|
114
|
-
if (idPosition >= 0) {
|
|
115
|
-
lowerPath = path.substring(0, idPosition) + '/:id';
|
|
116
|
-
m = this.map.get(lowerPath);
|
|
117
|
-
if (m) {
|
|
118
|
-
var h = m.get(req.method.toLowerCase());
|
|
119
|
-
if (h) {
|
|
120
|
-
if (!req.params)
|
|
121
|
-
req.params = {};
|
|
122
|
-
req.params.id = path.substring(idPosition + 1);
|
|
123
|
-
h(req, res, next);
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
next();
|
|
129
|
-
};
|
|
130
|
-
return middleware;
|
|
131
|
-
}());
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerActionsOnServer = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var server_action_1 = require("../src/server-action");
|
|
6
|
-
function registerActionsOnServer(area, controllers) {
|
|
7
|
-
var e_1, _a, e_2, _b;
|
|
8
|
-
var addAction = function (a) {
|
|
9
|
-
var x = a[server_action_1.serverActionField];
|
|
10
|
-
if (!x) {
|
|
11
|
-
throw 'failed to set server action, did you forget the BackendMethod Decorator?';
|
|
12
|
-
}
|
|
13
|
-
area.addAction(x);
|
|
14
|
-
};
|
|
15
|
-
server_action_1.actionInfo.runningOnServer = true;
|
|
16
|
-
if (controllers && controllers.length > 0) {
|
|
17
|
-
try {
|
|
18
|
-
for (var controllers_1 = tslib_1.__values(controllers), controllers_1_1 = controllers_1.next(); !controllers_1_1.done; controllers_1_1 = controllers_1.next()) {
|
|
19
|
-
var c = controllers_1_1.value;
|
|
20
|
-
var z = c[server_action_1.classBackendMethodsArray];
|
|
21
|
-
if (z)
|
|
22
|
-
try {
|
|
23
|
-
for (var z_1 = (e_2 = void 0, tslib_1.__values(z)), z_1_1 = z_1.next(); !z_1_1.done; z_1_1 = z_1.next()) {
|
|
24
|
-
var a = z_1_1.value;
|
|
25
|
-
addAction(a);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
29
|
-
finally {
|
|
30
|
-
try {
|
|
31
|
-
if (z_1_1 && !z_1_1.done && (_b = z_1.return)) _b.call(z_1);
|
|
32
|
-
}
|
|
33
|
-
finally { if (e_2) throw e_2.error; }
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
38
|
-
finally {
|
|
39
|
-
try {
|
|
40
|
-
if (controllers_1_1 && !controllers_1_1.done && (_a = controllers_1.return)) _a.call(controllers_1);
|
|
41
|
-
}
|
|
42
|
-
finally { if (e_1) throw e_1.error; }
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
else
|
|
46
|
-
server_action_1.actionInfo.allActions.forEach(function (a) {
|
|
47
|
-
addAction(a);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
exports.registerActionsOnServer = registerActionsOnServer;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerEntitiesOnServer = void 0;
|
|
4
|
-
var remult3_1 = require("../src/remult3");
|
|
5
|
-
var context_1 = require("../src/context");
|
|
6
|
-
var data_api_1 = require("../src/data-api");
|
|
7
|
-
function registerEntitiesOnServer(area, entities) {
|
|
8
|
-
if (!entities)
|
|
9
|
-
entities = context_1.allEntities;
|
|
10
|
-
//add Api Entries
|
|
11
|
-
entities.forEach(function (e) {
|
|
12
|
-
var key = remult3_1.getEntityKey(e);
|
|
13
|
-
if (key != undefined)
|
|
14
|
-
area.add(key, function (c) {
|
|
15
|
-
return new data_api_1.DataApi(c.repo(e), c);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
exports.registerEntitiesOnServer = registerEntitiesOnServer;
|
package/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
|
-
}
|