remult 0.20.3-exp.1 → 0.20.3-exp.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/postgres/schema-builder.js +7 -3
- package/esm/remult-svletekit.d.ts +3 -0
- package/esm/remult-svletekit.js +83 -0
- package/esm/server/expressBridge.js +1 -10
- package/package.json +1 -1
- package/postgres/getEntityTypescriptPostgres.d.ts +1 -0
- package/postgres/getEntityTypescriptPostgres.js +125 -0
- package/postgres/schema-builder.js +6 -3
- package/server/expressBridge.js +1 -10
|
@@ -128,15 +128,19 @@ export class PostgresSchemaBuilder {
|
|
|
128
128
|
let e = await dbNamesOf(entity);
|
|
129
129
|
let cols = (await cmd.execute(`select column_name
|
|
130
130
|
FROM information_schema.columns
|
|
131
|
-
WHERE table_name=${cmd.addParameterAndReturnSqlToken((e.$entityName).toLocaleLowerCase())} ` + this.additionalWhere)).rows.map(x => x.column_name);
|
|
131
|
+
WHERE table_name=${cmd.addParameterAndReturnSqlToken((e.$entityName).toLocaleLowerCase())} ` + this.additionalWhere)).rows.map(x => x.column_name.toLocaleLowerCase());
|
|
132
132
|
for (const col of entity.fields) {
|
|
133
|
-
if (!isDbReadonly(col, e))
|
|
134
|
-
|
|
133
|
+
if (!isDbReadonly(col, e)) {
|
|
134
|
+
let colName = e.$dbNameOf(col).toLocaleLowerCase();
|
|
135
|
+
if (colName.startsWith('"') && colName.endsWith('"'))
|
|
136
|
+
colName = colName.substring(1, colName.length - 1);
|
|
137
|
+
if (!cols.includes(colName)) {
|
|
135
138
|
let sql = `alter table ${e.$entityName} add column ${postgresColumnSyntax(col, e.$dbNameOf(col))}`;
|
|
136
139
|
if (PostgresSchemaBuilder.logToConsole)
|
|
137
140
|
console.info(sql);
|
|
138
141
|
await this.pool.execute(sql);
|
|
139
142
|
}
|
|
143
|
+
}
|
|
140
144
|
}
|
|
141
145
|
}
|
|
142
146
|
catch (err) {
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createRemultServer } from './server';
|
|
2
|
+
export function remultSveltekit(options) {
|
|
3
|
+
let result = createRemultServer(options, {
|
|
4
|
+
buildGenericRequest: event => ({
|
|
5
|
+
url: event.request.url,
|
|
6
|
+
method: event.request.method,
|
|
7
|
+
body: event.locals["_tempJson"],
|
|
8
|
+
on: (e, do1) => {
|
|
9
|
+
if (e === 'close') {
|
|
10
|
+
event.locals["_tempOnClose"] = do1;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
});
|
|
15
|
+
const handler = async ({ event, resolve }) => {
|
|
16
|
+
if (event.url.pathname.startsWith(options.rootPath)) {
|
|
17
|
+
let json = {};
|
|
18
|
+
try {
|
|
19
|
+
if (event.request.method == 'POST' || event.request.method == 'PUT') {
|
|
20
|
+
json = await event.request.json();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
console.log(error);
|
|
25
|
+
}
|
|
26
|
+
let sseResponse = undefined;
|
|
27
|
+
event.locals["_tempOnClose"] = () => { };
|
|
28
|
+
const response = {
|
|
29
|
+
end: () => { },
|
|
30
|
+
json: () => { },
|
|
31
|
+
status: () => {
|
|
32
|
+
return response;
|
|
33
|
+
},
|
|
34
|
+
write: () => { },
|
|
35
|
+
writeHead: (status, headers) => {
|
|
36
|
+
if (status === 200 && headers) {
|
|
37
|
+
const contentType = headers['Content-Type'];
|
|
38
|
+
if (contentType === 'text/event-stream') {
|
|
39
|
+
const messages = [];
|
|
40
|
+
response.write = (x) => messages.push(x);
|
|
41
|
+
const stream = new ReadableStream({
|
|
42
|
+
start: (controller) => {
|
|
43
|
+
for (const message of messages) {
|
|
44
|
+
controller.enqueue(message);
|
|
45
|
+
}
|
|
46
|
+
response.write = (data) => {
|
|
47
|
+
controller.enqueue(data);
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
cancel: () => {
|
|
51
|
+
response.write = () => { };
|
|
52
|
+
event.locals["_tempOnClose"]();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
sseResponse = new Response(stream, { headers });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
event.locals["_tempJson"] = json;
|
|
61
|
+
const responseFromRemultHandler = await result.handle(event, response);
|
|
62
|
+
if (sseResponse !== undefined) {
|
|
63
|
+
return sseResponse;
|
|
64
|
+
}
|
|
65
|
+
if (responseFromRemultHandler) {
|
|
66
|
+
return new Response(JSON.stringify(responseFromRemultHandler.data), {
|
|
67
|
+
status: responseFromRemultHandler.statusCode
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return new Promise((res) => {
|
|
72
|
+
result.withRemult(event, undefined, async () => {
|
|
73
|
+
res(await resolve(event));
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
return Object.assign(handler, {
|
|
78
|
+
getRemult: (req) => result.getRemult(req),
|
|
79
|
+
openApiDoc: (options) => result.openApiDoc(options),
|
|
80
|
+
registerRouter: x => result.registerRouter(x),
|
|
81
|
+
withRemult: (...args) => result.withRemult(...args)
|
|
82
|
+
});
|
|
83
|
+
}
|
|
@@ -437,15 +437,7 @@ export class RemultServerImplementation {
|
|
|
437
437
|
parameters.push({
|
|
438
438
|
"name": f.key,
|
|
439
439
|
"in": "query",
|
|
440
|
-
"description": "filter equal to " + f.key,
|
|
441
|
-
"required": false,
|
|
442
|
-
"style": "simple",
|
|
443
|
-
type
|
|
444
|
-
});
|
|
445
|
-
parameters.push({
|
|
446
|
-
"name": f.key + "_ne",
|
|
447
|
-
"in": "query",
|
|
448
|
-
"description": "filter not equal to " + f.key,
|
|
440
|
+
"description": "filter equal to " + f.key + ". See [more filtering options](https://remult.dev/docs/rest-api.html#filter)",
|
|
449
441
|
"required": false,
|
|
450
442
|
"style": "simple",
|
|
451
443
|
type
|
|
@@ -456,7 +448,6 @@ export class RemultServerImplementation {
|
|
|
456
448
|
type: "object",
|
|
457
449
|
properties
|
|
458
450
|
};
|
|
459
|
-
//TODO - handle allow api read also on the get level
|
|
460
451
|
if (JSON.stringify(properties) !== JSON.stringify(mutationProperties)) {
|
|
461
452
|
mutationKey += 'Mutation';
|
|
462
453
|
spec.components.schemas[mutationKey] = {
|
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getEntityTypescriptPostgres(table: string, schema?: string): Promise<string>;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEntityTypescriptPostgres = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var remult_1 = require("remult");
|
|
6
|
+
function getEntityTypescriptPostgres(table, schema) {
|
|
7
|
+
if (schema === void 0) { schema = 'public'; }
|
|
8
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
9
|
+
var command, cols, props, first, _a, _b, _c, column_name, column_default, data_type, datetime_precision, character_maximum_length, decorator, decoratorArgs, type, defaultVal, e_1_1, r;
|
|
10
|
+
var e_1, _d;
|
|
11
|
+
return tslib_1.__generator(this, function (_e) {
|
|
12
|
+
switch (_e.label) {
|
|
13
|
+
case 0:
|
|
14
|
+
command = remult_1.SqlDatabase.getDb(remult_1.remult).createCommand();
|
|
15
|
+
cols = '';
|
|
16
|
+
props = [];
|
|
17
|
+
props.push('allowApiCrud: true');
|
|
18
|
+
if (table.toLocaleLowerCase() != table) {
|
|
19
|
+
// props.push("dbName: '\"" + table + "\"'");
|
|
20
|
+
}
|
|
21
|
+
first = undefined;
|
|
22
|
+
_e.label = 1;
|
|
23
|
+
case 1:
|
|
24
|
+
_e.trys.push([1, 6, 7, 8]);
|
|
25
|
+
return [4 /*yield*/, command.execute("select * from INFORMATION_SCHEMA.COLUMNS where table_schema=" + command.addParameterAndReturnSqlToken(schema) + " and table_name=" + command.addParameterAndReturnSqlToken(table) + "\n \n order by ordinal_position")];
|
|
26
|
+
case 2:
|
|
27
|
+
_a = tslib_1.__values.apply(void 0, [(_e.sent()).rows]), _b = _a.next();
|
|
28
|
+
_e.label = 3;
|
|
29
|
+
case 3:
|
|
30
|
+
if (!!_b.done) return [3 /*break*/, 5];
|
|
31
|
+
_c = _b.value, column_name = _c.column_name, column_default = _c.column_default, data_type = _c.data_type, datetime_precision = _c.datetime_precision, character_maximum_length = _c.character_maximum_length;
|
|
32
|
+
decorator = '@Fields.string';
|
|
33
|
+
decoratorArgs = '';
|
|
34
|
+
type = '';
|
|
35
|
+
defaultVal = "''";
|
|
36
|
+
switch (data_type) {
|
|
37
|
+
case 'decimal':
|
|
38
|
+
case 'real':
|
|
39
|
+
case 'int':
|
|
40
|
+
case 'smallint':
|
|
41
|
+
case 'tinyint':
|
|
42
|
+
case 'bigint':
|
|
43
|
+
case 'float':
|
|
44
|
+
case 'numeric':
|
|
45
|
+
case 'NUMBER':
|
|
46
|
+
case 'money':
|
|
47
|
+
if (datetime_precision === 0)
|
|
48
|
+
decorator = '@Fields.integer';
|
|
49
|
+
else
|
|
50
|
+
decorator = '@Fields.number';
|
|
51
|
+
defaultVal = '0';
|
|
52
|
+
break;
|
|
53
|
+
case 'nchar':
|
|
54
|
+
case 'nvarchar':
|
|
55
|
+
case 'ntext':
|
|
56
|
+
case 'NVARCHAR2':
|
|
57
|
+
case 'text':
|
|
58
|
+
case 'varchar':
|
|
59
|
+
case 'VARCHAR2':
|
|
60
|
+
break;
|
|
61
|
+
case 'char':
|
|
62
|
+
case 'CHAR':
|
|
63
|
+
console.log({
|
|
64
|
+
character_maximum_length: character_maximum_length,
|
|
65
|
+
column_default: column_default,
|
|
66
|
+
data_type: data_type,
|
|
67
|
+
column_name: column_name
|
|
68
|
+
});
|
|
69
|
+
if (character_maximum_length == 8 && column_default == "('00000000')") {
|
|
70
|
+
decorator = '@Fields.dateOnly';
|
|
71
|
+
type = 'Date';
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
case 'DATE':
|
|
75
|
+
case 'datetime':
|
|
76
|
+
case 'datetime2':
|
|
77
|
+
case 'timestamp without time zone':
|
|
78
|
+
decorator = '@Fields.date';
|
|
79
|
+
type = 'Date';
|
|
80
|
+
break;
|
|
81
|
+
case 'bit':
|
|
82
|
+
decorator = '@Fields.boolean';
|
|
83
|
+
break;
|
|
84
|
+
default:
|
|
85
|
+
console.log(data_type);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
if (column_name.toLocaleLowerCase() != column_name ||
|
|
89
|
+
column_name == 'order')
|
|
90
|
+
decoratorArgs = "{ dbName: '\"" + column_name + "\"' }";
|
|
91
|
+
if (!first)
|
|
92
|
+
first = column_name;
|
|
93
|
+
cols += '\n\n ' + decorator + ("(" + decoratorArgs + ")\n ") + column_name;
|
|
94
|
+
if (!defaultVal) {
|
|
95
|
+
cols += '!';
|
|
96
|
+
cols += ': ';
|
|
97
|
+
cols += type;
|
|
98
|
+
}
|
|
99
|
+
if (defaultVal)
|
|
100
|
+
cols += ' = ' + defaultVal;
|
|
101
|
+
_e.label = 4;
|
|
102
|
+
case 4:
|
|
103
|
+
_b = _a.next();
|
|
104
|
+
return [3 /*break*/, 3];
|
|
105
|
+
case 5: return [3 /*break*/, 8];
|
|
106
|
+
case 6:
|
|
107
|
+
e_1_1 = _e.sent();
|
|
108
|
+
e_1 = { error: e_1_1 };
|
|
109
|
+
return [3 /*break*/, 8];
|
|
110
|
+
case 7:
|
|
111
|
+
try {
|
|
112
|
+
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
113
|
+
}
|
|
114
|
+
finally { if (e_1) throw e_1.error; }
|
|
115
|
+
return [7 /*endfinally*/];
|
|
116
|
+
case 8:
|
|
117
|
+
r = "import { Entity, Fields, EntityBase } from \"remult\";\n@Entity<" + table + ">(\"" + table + "\", { \n " + props.join(',\n ') + " \n})\nexport class " + table + " extends EntityBase {" +
|
|
118
|
+
cols +
|
|
119
|
+
'\n}'.replace(' ', '');
|
|
120
|
+
return [2 /*return*/, r];
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
exports.getEntityTypescriptPostgres = getEntityTypescriptPostgres;
|
|
@@ -257,7 +257,7 @@ var PostgresSchemaBuilder = /** @class */ (function () {
|
|
|
257
257
|
};
|
|
258
258
|
PostgresSchemaBuilder.prototype.verifyAllColumns = function (entity) {
|
|
259
259
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
260
|
-
var cmd, e, cols, _a, _b, col, sql, e_4_1, err_3;
|
|
260
|
+
var cmd, e, cols, _a, _b, col, colName, sql, e_4_1, err_3;
|
|
261
261
|
var e_4, _c;
|
|
262
262
|
return tslib_1.__generator(this, function (_d) {
|
|
263
263
|
switch (_d.label) {
|
|
@@ -269,7 +269,7 @@ var PostgresSchemaBuilder = /** @class */ (function () {
|
|
|
269
269
|
e = _d.sent();
|
|
270
270
|
return [4 /*yield*/, cmd.execute("select column_name \n FROM information_schema.columns \n WHERE table_name=" + cmd.addParameterAndReturnSqlToken((e.$entityName).toLocaleLowerCase()) + " " + this.additionalWhere)];
|
|
271
271
|
case 2:
|
|
272
|
-
cols = (_d.sent()).rows.map(function (x) { return x.column_name; });
|
|
272
|
+
cols = (_d.sent()).rows.map(function (x) { return x.column_name.toLocaleLowerCase(); });
|
|
273
273
|
_d.label = 3;
|
|
274
274
|
case 3:
|
|
275
275
|
_d.trys.push([3, 8, 9, 10]);
|
|
@@ -279,7 +279,10 @@ var PostgresSchemaBuilder = /** @class */ (function () {
|
|
|
279
279
|
if (!!_b.done) return [3 /*break*/, 7];
|
|
280
280
|
col = _b.value;
|
|
281
281
|
if (!!filter_consumer_bridge_to_sql_request_1.isDbReadonly(col, e)) return [3 /*break*/, 6];
|
|
282
|
-
|
|
282
|
+
colName = e.$dbNameOf(col).toLocaleLowerCase();
|
|
283
|
+
if (colName.startsWith('"') && colName.endsWith('"'))
|
|
284
|
+
colName = colName.substring(1, colName.length - 1);
|
|
285
|
+
if (!!cols.includes(colName)) return [3 /*break*/, 6];
|
|
283
286
|
sql = "alter table " + e.$entityName + " add column " + postgresColumnSyntax(col, e.$dbNameOf(col));
|
|
284
287
|
if (PostgresSchemaBuilder.logToConsole)
|
|
285
288
|
console.info(sql);
|
package/server/expressBridge.js
CHANGED
|
@@ -754,15 +754,7 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
754
754
|
parameters.push({
|
|
755
755
|
"name": f.key,
|
|
756
756
|
"in": "query",
|
|
757
|
-
"description": "filter equal to " + f.key,
|
|
758
|
-
"required": false,
|
|
759
|
-
"style": "simple",
|
|
760
|
-
type: type
|
|
761
|
-
});
|
|
762
|
-
parameters.push({
|
|
763
|
-
"name": f.key + "_ne",
|
|
764
|
-
"in": "query",
|
|
765
|
-
"description": "filter not equal to " + f.key,
|
|
757
|
+
"description": "filter equal to " + f.key + ". See [more filtering options](https://remult.dev/docs/rest-api.html#filter)",
|
|
766
758
|
"required": false,
|
|
767
759
|
"style": "simple",
|
|
768
760
|
type: type
|
|
@@ -781,7 +773,6 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
781
773
|
type: "object",
|
|
782
774
|
properties: properties
|
|
783
775
|
};
|
|
784
|
-
//TODO - handle allow api read also on the get level
|
|
785
776
|
if (JSON.stringify(properties) !== JSON.stringify(mutationProperties)) {
|
|
786
777
|
mutationKey += 'Mutation';
|
|
787
778
|
spec.components.schemas[mutationKey] = {
|