@restura/core 0.1.0-alpha.26 → 0.1.0-alpha.27
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/dist/index.d.mts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +39 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -269,7 +269,6 @@ import cookieParser from "cookie-parser";
|
|
|
269
269
|
import * as express from "express";
|
|
270
270
|
import fs4 from "fs";
|
|
271
271
|
import path4 from "path";
|
|
272
|
-
import pg3 from "pg";
|
|
273
272
|
import * as prettier3 from "prettier";
|
|
274
273
|
|
|
275
274
|
// src/restura/RsError.ts
|
|
@@ -428,10 +427,10 @@ var compareSchema = new CompareSchema();
|
|
|
428
427
|
var compareSchema_default = compareSchema;
|
|
429
428
|
|
|
430
429
|
// src/restura/customApiFactory.ts
|
|
431
|
-
import { fileUtils } from "@restura/internal";
|
|
432
430
|
import Bluebird2 from "bluebird";
|
|
433
431
|
import fs from "fs";
|
|
434
432
|
import path from "path";
|
|
433
|
+
import { FileUtils } from "@restura/internal";
|
|
435
434
|
var CustomApiFactory = class {
|
|
436
435
|
constructor() {
|
|
437
436
|
this.customApis = {};
|
|
@@ -440,7 +439,7 @@ var CustomApiFactory = class {
|
|
|
440
439
|
const apiVersions = ["v1"];
|
|
441
440
|
for (const apiVersion of apiVersions) {
|
|
442
441
|
const apiVersionFolderPath = path.join(baseFolderPath, apiVersion);
|
|
443
|
-
const directoryExists = await
|
|
442
|
+
const directoryExists = await FileUtils.existDir(apiVersionFolderPath);
|
|
444
443
|
if (!directoryExists) continue;
|
|
445
444
|
await this.addDirectory(apiVersionFolderPath, apiVersion);
|
|
446
445
|
}
|
|
@@ -1283,7 +1282,7 @@ import { ObjectUtils as ObjectUtils2 } from "@redskytech/core-utils";
|
|
|
1283
1282
|
import jsonschema from "jsonschema";
|
|
1284
1283
|
import { z as z4 } from "zod";
|
|
1285
1284
|
|
|
1286
|
-
// src/restura/utils/
|
|
1285
|
+
// src/restura/utils/utils.ts
|
|
1287
1286
|
function addQuotesToStrings(variable) {
|
|
1288
1287
|
if (typeof variable === "string") {
|
|
1289
1288
|
return `'${variable}'`;
|
|
@@ -1294,6 +1293,17 @@ function addQuotesToStrings(variable) {
|
|
|
1294
1293
|
return variable;
|
|
1295
1294
|
}
|
|
1296
1295
|
}
|
|
1296
|
+
function sortObjectKeysAlphabetically(obj) {
|
|
1297
|
+
if (Array.isArray(obj)) {
|
|
1298
|
+
return obj.map(sortObjectKeysAlphabetically);
|
|
1299
|
+
} else if (obj !== null && typeof obj === "object") {
|
|
1300
|
+
return Object.keys(obj).sort().reduce((sorted, key) => {
|
|
1301
|
+
sorted[key] = sortObjectKeysAlphabetically(obj[key]);
|
|
1302
|
+
return sorted;
|
|
1303
|
+
}, {});
|
|
1304
|
+
}
|
|
1305
|
+
return obj;
|
|
1306
|
+
}
|
|
1297
1307
|
|
|
1298
1308
|
// src/restura/validators/requestValidator.ts
|
|
1299
1309
|
function requestValidator(req, routeData, validationSchema) {
|
|
@@ -1853,7 +1863,7 @@ var filterPsqlParser = peg.generate(filterSqlGrammar, {
|
|
|
1853
1863
|
var filterPsqlParser_default = filterPsqlParser;
|
|
1854
1864
|
|
|
1855
1865
|
// src/restura/sql/PsqlEngine.ts
|
|
1856
|
-
var { Client } = pg2;
|
|
1866
|
+
var { Client, types } = pg2;
|
|
1857
1867
|
var systemUser = {
|
|
1858
1868
|
role: "",
|
|
1859
1869
|
host: "",
|
|
@@ -1864,6 +1874,7 @@ var PsqlEngine = class extends SqlEngine {
|
|
|
1864
1874
|
constructor(psqlConnectionPool, shouldListenForDbTriggers = false) {
|
|
1865
1875
|
super();
|
|
1866
1876
|
this.psqlConnectionPool = psqlConnectionPool;
|
|
1877
|
+
this.setupPgReturnTypes();
|
|
1867
1878
|
if (shouldListenForDbTriggers) {
|
|
1868
1879
|
this.setupTriggerListeners = this.listenForDbTriggers();
|
|
1869
1880
|
}
|
|
@@ -1873,6 +1884,16 @@ var PsqlEngine = class extends SqlEngine {
|
|
|
1873
1884
|
await this.triggerClient.end();
|
|
1874
1885
|
}
|
|
1875
1886
|
}
|
|
1887
|
+
setupPgReturnTypes() {
|
|
1888
|
+
const TIMESTAMPTZ_OID = 1184;
|
|
1889
|
+
types.setTypeParser(TIMESTAMPTZ_OID, (val) => {
|
|
1890
|
+
return val === null ? null : new Date(val).toISOString();
|
|
1891
|
+
});
|
|
1892
|
+
const BIGINT_OID = 20;
|
|
1893
|
+
types.setTypeParser(BIGINT_OID, (val) => {
|
|
1894
|
+
return val === null ? null : Number(val);
|
|
1895
|
+
});
|
|
1896
|
+
}
|
|
1876
1897
|
async listenForDbTriggers() {
|
|
1877
1898
|
this.triggerClient = new Client({
|
|
1878
1899
|
user: this.psqlConnectionPool.poolConfig.user,
|
|
@@ -1926,7 +1947,7 @@ var PsqlEngine = class extends SqlEngine {
|
|
|
1926
1947
|
const tableColumns = [];
|
|
1927
1948
|
for (const column of table.columns) {
|
|
1928
1949
|
let columnSql = "";
|
|
1929
|
-
columnSql += ` "${column.name}" ${schemaToPsqlType(column)}`;
|
|
1950
|
+
columnSql += ` "${column.name}" ${this.schemaToPsqlType(column)}`;
|
|
1930
1951
|
let value = column.value;
|
|
1931
1952
|
if (column.type === "JSON") value = "";
|
|
1932
1953
|
if (column.type === "JSONB") value = "";
|
|
@@ -2395,10 +2416,14 @@ CREATE TRIGGER "${tableName}_insert"
|
|
|
2395
2416
|
EXECUTE FUNCTION notify_${tableName}_insert();
|
|
2396
2417
|
`;
|
|
2397
2418
|
}
|
|
2419
|
+
schemaToPsqlType(column) {
|
|
2420
|
+
if (column.hasAutoIncrement) return "BIGSERIAL";
|
|
2421
|
+
if (column.type === "ENUM") return `TEXT`;
|
|
2422
|
+
if (column.type === "DATETIME") return "TIMESTAMPTZ";
|
|
2423
|
+
if (column.type === "MEDIUMINT") return "INT";
|
|
2424
|
+
return column.type;
|
|
2425
|
+
}
|
|
2398
2426
|
};
|
|
2399
|
-
__decorateClass([
|
|
2400
|
-
boundMethod
|
|
2401
|
-
], PsqlEngine.prototype, "handleTrigger", 1);
|
|
2402
2427
|
__decorateClass([
|
|
2403
2428
|
boundMethod
|
|
2404
2429
|
], PsqlEngine.prototype, "createUpdateTrigger", 1);
|
|
@@ -2408,26 +2433,19 @@ __decorateClass([
|
|
|
2408
2433
|
__decorateClass([
|
|
2409
2434
|
boundMethod
|
|
2410
2435
|
], PsqlEngine.prototype, "createInsertTriggers", 1);
|
|
2411
|
-
function schemaToPsqlType(column) {
|
|
2412
|
-
if (column.hasAutoIncrement) return "BIGSERIAL";
|
|
2413
|
-
if (column.type === "ENUM") return `TEXT`;
|
|
2414
|
-
if (column.type === "DATETIME") return "TIMESTAMPTZ";
|
|
2415
|
-
if (column.type === "MEDIUMINT") return "INT";
|
|
2416
|
-
return column.type;
|
|
2417
|
-
}
|
|
2418
2436
|
|
|
2419
2437
|
// src/restura/utils/TempCache.ts
|
|
2420
2438
|
import fs3 from "fs";
|
|
2421
2439
|
import path3 from "path";
|
|
2422
2440
|
import { DateUtils } from "@redskytech/core-utils";
|
|
2441
|
+
import { FileUtils as FileUtils2 } from "@restura/internal";
|
|
2423
2442
|
import Bluebird3 from "bluebird";
|
|
2424
2443
|
import * as os2 from "os";
|
|
2425
|
-
import { fileUtils as fileUtils2 } from "@restura/internal";
|
|
2426
2444
|
var TempCache = class {
|
|
2427
2445
|
constructor(location) {
|
|
2428
2446
|
this.maxDurationDays = 7;
|
|
2429
2447
|
this.location = location || os2.tmpdir();
|
|
2430
|
-
|
|
2448
|
+
FileUtils2.ensureDir(this.location).catch((e) => {
|
|
2431
2449
|
throw e;
|
|
2432
2450
|
});
|
|
2433
2451
|
}
|
|
@@ -2449,7 +2467,6 @@ var TempCache = class {
|
|
|
2449
2467
|
};
|
|
2450
2468
|
|
|
2451
2469
|
// src/restura/restura.ts
|
|
2452
|
-
var { types } = pg3;
|
|
2453
2470
|
var ResturaEngine = class {
|
|
2454
2471
|
constructor() {
|
|
2455
2472
|
this.publicEndpoints = {
|
|
@@ -2472,7 +2489,6 @@ var ResturaEngine = class {
|
|
|
2472
2489
|
new TempCache(this.resturaConfig.fileTempCachePath);
|
|
2473
2490
|
this.psqlConnectionPool = psqlConnectionPool;
|
|
2474
2491
|
this.psqlEngine = new PsqlEngine(this.psqlConnectionPool, true);
|
|
2475
|
-
setupPgReturnTypes();
|
|
2476
2492
|
await customApiFactory_default.loadApiFiles(this.resturaConfig.customApiFolderPath);
|
|
2477
2493
|
this.authenticationHandler = authenticationHandler;
|
|
2478
2494
|
app.use(compression());
|
|
@@ -2623,7 +2639,7 @@ var ResturaEngine = class {
|
|
|
2623
2639
|
}
|
|
2624
2640
|
async updateSchema(req, res) {
|
|
2625
2641
|
try {
|
|
2626
|
-
this.schema = req.data;
|
|
2642
|
+
this.schema = sortObjectKeysAlphabetically(req.data);
|
|
2627
2643
|
await this.storeFileSystemSchema();
|
|
2628
2644
|
await this.reloadEndpoints();
|
|
2629
2645
|
await this.updateTypes();
|
|
@@ -2785,22 +2801,11 @@ __decorateClass([
|
|
|
2785
2801
|
__decorateClass([
|
|
2786
2802
|
boundMethod
|
|
2787
2803
|
], ResturaEngine.prototype, "runCustomRouteLogic", 1);
|
|
2788
|
-
function setupPgReturnTypes() {
|
|
2789
|
-
const TIMESTAMPTZ_OID = 1184;
|
|
2790
|
-
types.setTypeParser(TIMESTAMPTZ_OID, (val) => {
|
|
2791
|
-
return val === null ? null : new Date(val).toISOString();
|
|
2792
|
-
});
|
|
2793
|
-
const BIGINT_OID = 20;
|
|
2794
|
-
types.setTypeParser(BIGINT_OID, (val) => {
|
|
2795
|
-
return val === null ? null : Number(val);
|
|
2796
|
-
});
|
|
2797
|
-
}
|
|
2798
|
-
setupPgReturnTypes();
|
|
2799
2804
|
var restura = new ResturaEngine();
|
|
2800
2805
|
|
|
2801
2806
|
// src/restura/sql/PsqlTransaction.ts
|
|
2802
|
-
import
|
|
2803
|
-
var { Client: Client2 } =
|
|
2807
|
+
import pg3 from "pg";
|
|
2808
|
+
var { Client: Client2 } = pg3;
|
|
2804
2809
|
var PsqlTransaction = class extends PsqlConnection {
|
|
2805
2810
|
constructor(clientConfig) {
|
|
2806
2811
|
super();
|