remult 0.20.3 → 0.20.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/postgres/schema-builder.js +7 -3
- package/esm/server/expressBridge.js +1 -10
- package/esm/src/remult3/RepositoryImplementation.js +2 -2
- 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
- package/src/remult3/RepositoryImplementation.js +2 -2
|
@@ -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) {
|
|
@@ -412,15 +412,7 @@ export class RemultServerImplementation {
|
|
|
412
412
|
parameters.push({
|
|
413
413
|
"name": f.key,
|
|
414
414
|
"in": "query",
|
|
415
|
-
"description": "filter equal to " + f.key,
|
|
416
|
-
"required": false,
|
|
417
|
-
"style": "simple",
|
|
418
|
-
type
|
|
419
|
-
});
|
|
420
|
-
parameters.push({
|
|
421
|
-
"name": f.key + "_ne",
|
|
422
|
-
"in": "query",
|
|
423
|
-
"description": "filter not equal to " + f.key,
|
|
415
|
+
"description": "filter equal to " + f.key + ". See [more filtering options](https://remult.dev/docs/rest-api.html#filter)",
|
|
424
416
|
"required": false,
|
|
425
417
|
"style": "simple",
|
|
426
418
|
type
|
|
@@ -431,7 +423,6 @@ export class RemultServerImplementation {
|
|
|
431
423
|
type: "object",
|
|
432
424
|
properties
|
|
433
425
|
};
|
|
434
|
-
//TODO - handle allow api read also on the get level
|
|
435
426
|
if (JSON.stringify(properties) !== JSON.stringify(mutationProperties)) {
|
|
436
427
|
mutationKey += 'Mutation';
|
|
437
428
|
spec.components.schemas[mutationKey] = {
|
|
@@ -277,7 +277,7 @@ export class RepositoryImplementation {
|
|
|
277
277
|
result[col.key] = col.valueConverter.fromJson(row[col.key]);
|
|
278
278
|
}
|
|
279
279
|
return result;
|
|
280
|
-
}));
|
|
280
|
+
}), load);
|
|
281
281
|
}
|
|
282
282
|
async loadManyToOneForManyRows(rawRows, load) {
|
|
283
283
|
let loadFields = undefined;
|
|
@@ -1398,7 +1398,7 @@ class EntityFullInfo {
|
|
|
1398
1398
|
return !item ? this.remult.isAllowedForInstance(undefined, this.options.allowApiUpdate) : this.remult.repo(this.entityType).getEntityRef(item).apiUpdateAllowed;
|
|
1399
1399
|
}
|
|
1400
1400
|
get apiReadAllowed() {
|
|
1401
|
-
if (this.options.
|
|
1401
|
+
if (this.options.allowApiRead === undefined)
|
|
1402
1402
|
return true; //TODO2 - consider that this default may be confusing, since it's different from all others.
|
|
1403
1403
|
return this.remult.isAllowed(this.options.allowApiRead);
|
|
1404
1404
|
}
|
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
|
@@ -719,15 +719,7 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
719
719
|
parameters.push({
|
|
720
720
|
"name": f.key,
|
|
721
721
|
"in": "query",
|
|
722
|
-
"description": "filter equal to " + f.key,
|
|
723
|
-
"required": false,
|
|
724
|
-
"style": "simple",
|
|
725
|
-
type: type
|
|
726
|
-
});
|
|
727
|
-
parameters.push({
|
|
728
|
-
"name": f.key + "_ne",
|
|
729
|
-
"in": "query",
|
|
730
|
-
"description": "filter not equal to " + f.key,
|
|
722
|
+
"description": "filter equal to " + f.key + ". See [more filtering options](https://remult.dev/docs/rest-api.html#filter)",
|
|
731
723
|
"required": false,
|
|
732
724
|
"style": "simple",
|
|
733
725
|
type: type
|
|
@@ -746,7 +738,6 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
746
738
|
type: "object",
|
|
747
739
|
properties: properties
|
|
748
740
|
};
|
|
749
|
-
//TODO - handle allow api read also on the get level
|
|
750
741
|
if (JSON.stringify(properties) !== JSON.stringify(mutationProperties)) {
|
|
751
742
|
mutationKey += 'Mutation';
|
|
752
743
|
spec.components.schemas[mutationKey] = {
|
|
@@ -481,7 +481,7 @@ var RepositoryImplementation = /** @class */ (function () {
|
|
|
481
481
|
finally { if (e_7) throw e_7.error; }
|
|
482
482
|
}
|
|
483
483
|
return result;
|
|
484
|
-
}))];
|
|
484
|
+
}), load)];
|
|
485
485
|
});
|
|
486
486
|
});
|
|
487
487
|
};
|
|
@@ -2481,7 +2481,7 @@ var EntityFullInfo = /** @class */ (function () {
|
|
|
2481
2481
|
};
|
|
2482
2482
|
Object.defineProperty(EntityFullInfo.prototype, "apiReadAllowed", {
|
|
2483
2483
|
get: function () {
|
|
2484
|
-
if (this.options.
|
|
2484
|
+
if (this.options.allowApiRead === undefined)
|
|
2485
2485
|
return true; //TODO2 - consider that this default may be confusing, since it's different from all others.
|
|
2486
2486
|
return this.remult.isAllowed(this.options.allowApiRead);
|
|
2487
2487
|
},
|