@restura/core 0.1.0-alpha.14 → 0.1.0-alpha.15
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 +25 -25
- package/dist/index.d.ts +25 -25
- package/dist/index.js +37 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -29
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -216,7 +216,7 @@ import { createHash } from "crypto";
|
|
|
216
216
|
import * as express from "express";
|
|
217
217
|
import fs3 from "fs";
|
|
218
218
|
import path3 from "path";
|
|
219
|
-
import
|
|
219
|
+
import pg4 from "pg";
|
|
220
220
|
import * as prettier3 from "prettier";
|
|
221
221
|
|
|
222
222
|
// src/restura/sql/SqlUtils.ts
|
|
@@ -748,7 +748,7 @@ var joinDataSchema = z3.object({
|
|
|
748
748
|
var requestDataSchema = z3.object({
|
|
749
749
|
name: z3.string(),
|
|
750
750
|
required: z3.boolean(),
|
|
751
|
-
isNullable: z3.boolean().optional()
|
|
751
|
+
isNullable: z3.boolean().optional(),
|
|
752
752
|
validator: z3.array(validatorDataSchema)
|
|
753
753
|
}).strict();
|
|
754
754
|
var responseDataSchema = z3.object({
|
|
@@ -834,6 +834,12 @@ var postgresColumnDateTypesSchema = z3.enum([
|
|
|
834
834
|
"INTERVAL"
|
|
835
835
|
// time span
|
|
836
836
|
]);
|
|
837
|
+
var postgresColumnJsonTypesSchema = z3.enum([
|
|
838
|
+
"JSON",
|
|
839
|
+
// stores JSON data as raw text
|
|
840
|
+
"JSONB"
|
|
841
|
+
// stores JSON data in a binary format, optimized for query performance
|
|
842
|
+
]);
|
|
837
843
|
var mariaDbColumnNumericTypesSchema = z3.enum([
|
|
838
844
|
"BOOLEAN",
|
|
839
845
|
// 1-byte A synonym for "TINYINT(1)". Supported from version 1.2.0 onwards.
|
|
@@ -896,6 +902,7 @@ var columnDataSchema = z3.object({
|
|
|
896
902
|
postgresColumnNumericTypesSchema,
|
|
897
903
|
postgresColumnStringTypesSchema,
|
|
898
904
|
postgresColumnDateTypesSchema,
|
|
905
|
+
postgresColumnJsonTypesSchema,
|
|
899
906
|
mariaDbColumnNumericTypesSchema,
|
|
900
907
|
mariaDbColumnStringTypesSchema,
|
|
901
908
|
mariaDbColumnDateTypesSchema
|
|
@@ -1203,10 +1210,16 @@ function convertTable(table) {
|
|
|
1203
1210
|
|
|
1204
1211
|
// src/restura/sql/PsqlEngine.ts
|
|
1205
1212
|
import { ObjectUtils as ObjectUtils4 } from "@redskytech/core-utils";
|
|
1213
|
+
import getDiff from "@wmfs/pg-diff-sync";
|
|
1214
|
+
import pgInfo from "@wmfs/pg-info";
|
|
1215
|
+
import pg2 from "pg";
|
|
1206
1216
|
|
|
1207
1217
|
// src/restura/sql/PsqlPool.ts
|
|
1208
1218
|
import pg from "pg";
|
|
1209
1219
|
|
|
1220
|
+
// src/restura/sql/PsqlConnection.ts
|
|
1221
|
+
import format3 from "pg-format";
|
|
1222
|
+
|
|
1210
1223
|
// src/restura/sql/PsqlUtils.ts
|
|
1211
1224
|
import format2 from "pg-format";
|
|
1212
1225
|
function escapeColumnName(columnName) {
|
|
@@ -1255,7 +1268,6 @@ function SQL(strings, ...values) {
|
|
|
1255
1268
|
}
|
|
1256
1269
|
|
|
1257
1270
|
// src/restura/sql/PsqlConnection.ts
|
|
1258
|
-
import format3 from "pg-format";
|
|
1259
1271
|
var PsqlConnection = class {
|
|
1260
1272
|
constructor() {
|
|
1261
1273
|
}
|
|
@@ -1534,9 +1546,7 @@ var filterPsqlParser = peg.generate(filterSqlGrammar, {
|
|
|
1534
1546
|
var filterPsqlParser_default = filterPsqlParser;
|
|
1535
1547
|
|
|
1536
1548
|
// src/restura/sql/PsqlEngine.ts
|
|
1537
|
-
|
|
1538
|
-
import pgInfo from "@wmfs/pg-info";
|
|
1539
|
-
var { Client } = "pg";
|
|
1549
|
+
var { Client } = pg2;
|
|
1540
1550
|
var systemUser = {
|
|
1541
1551
|
role: "",
|
|
1542
1552
|
host: "",
|
|
@@ -1584,7 +1594,7 @@ var PsqlEngine = class extends SqlEngine {
|
|
|
1584
1594
|
}
|
|
1585
1595
|
if (column.isNullable) columnSql += " NULL";
|
|
1586
1596
|
else columnSql += " NOT NULL";
|
|
1587
|
-
if (column.default) columnSql += ` DEFAULT
|
|
1597
|
+
if (column.default) columnSql += ` DEFAULT ${column.default}`;
|
|
1588
1598
|
tableColumns.push(columnSql);
|
|
1589
1599
|
}
|
|
1590
1600
|
sql += tableColumns.join(", \n");
|
|
@@ -1671,12 +1681,10 @@ var PsqlEngine = class extends SqlEngine {
|
|
|
1671
1681
|
await originalClient.connect();
|
|
1672
1682
|
await scratchClient.connect();
|
|
1673
1683
|
const info1 = await pgInfo({
|
|
1674
|
-
client: originalClient
|
|
1675
|
-
schema: "public"
|
|
1684
|
+
client: originalClient
|
|
1676
1685
|
});
|
|
1677
1686
|
const info2 = await pgInfo({
|
|
1678
|
-
client: scratchClient
|
|
1679
|
-
schema: "public"
|
|
1687
|
+
client: scratchClient
|
|
1680
1688
|
});
|
|
1681
1689
|
const diff = getDiff(info1, info2);
|
|
1682
1690
|
await originalClient.end();
|
|
@@ -1955,17 +1963,17 @@ var PsqlEngine = class extends SqlEngine {
|
|
|
1955
1963
|
return whereClause;
|
|
1956
1964
|
}
|
|
1957
1965
|
};
|
|
1958
|
-
|
|
1966
|
+
function schemaToPsqlType(column, tableName) {
|
|
1959
1967
|
if (column.hasAutoIncrement) return "BIGSERIAL";
|
|
1960
1968
|
if (column.type === "ENUM") return `"${tableName}_${column.name}_enum"`;
|
|
1961
1969
|
if (column.type === "DATETIME") return "TIMESTAMPTZ";
|
|
1962
1970
|
if (column.type === "MEDIUMINT") return "INT";
|
|
1963
1971
|
return column.type;
|
|
1964
|
-
}
|
|
1972
|
+
}
|
|
1965
1973
|
|
|
1966
1974
|
// src/restura/sql/PsqlTransaction.ts
|
|
1967
|
-
import
|
|
1968
|
-
var { Client: Client2 } =
|
|
1975
|
+
import pg3 from "pg";
|
|
1976
|
+
var { Client: Client2 } = pg3;
|
|
1969
1977
|
var PsqlTransaction = class extends PsqlConnection {
|
|
1970
1978
|
constructor(clientConfig) {
|
|
1971
1979
|
super();
|
|
@@ -1996,21 +2004,21 @@ var PsqlTransaction = class extends PsqlConnection {
|
|
|
1996
2004
|
import cloneDeep from "lodash.clonedeep";
|
|
1997
2005
|
var CompareSchema = class {
|
|
1998
2006
|
async diffSchema(newSchema, latestSchema, psqlEngine) {
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2007
|
+
const endPoints = this.diffEndPoints(newSchema.endpoints[0].routes, latestSchema.endpoints[0].routes);
|
|
2008
|
+
const globalParams = this.diffStringArray(newSchema.globalParams, latestSchema.globalParams);
|
|
2009
|
+
const roles = this.diffStringArray(newSchema.roles, latestSchema.roles);
|
|
2002
2010
|
let commands = "";
|
|
2003
2011
|
if (JSON.stringify(newSchema.database) !== JSON.stringify(latestSchema.database))
|
|
2004
2012
|
commands = await psqlEngine.diffDatabaseToSchema(newSchema);
|
|
2005
|
-
|
|
2013
|
+
const customTypes = newSchema.customTypes !== latestSchema.customTypes;
|
|
2006
2014
|
const schemaPreview = { endPoints, globalParams, roles, commands, customTypes };
|
|
2007
2015
|
return schemaPreview;
|
|
2008
2016
|
}
|
|
2009
2017
|
diffStringArray(newArray, originalArray) {
|
|
2010
|
-
|
|
2011
|
-
|
|
2018
|
+
const stringsDiff = [];
|
|
2019
|
+
const originalClone = new Set(originalArray);
|
|
2012
2020
|
newArray.forEach((item) => {
|
|
2013
|
-
|
|
2021
|
+
const originalIndex = originalClone.has(item);
|
|
2014
2022
|
if (!originalIndex) {
|
|
2015
2023
|
stringsDiff.push({
|
|
2016
2024
|
name: item,
|
|
@@ -2029,11 +2037,11 @@ var CompareSchema = class {
|
|
|
2029
2037
|
return stringsDiff;
|
|
2030
2038
|
}
|
|
2031
2039
|
diffEndPoints(newEndPoints, originalEndpoints) {
|
|
2032
|
-
|
|
2033
|
-
|
|
2040
|
+
const originalClone = cloneDeep(originalEndpoints);
|
|
2041
|
+
const diffObj = [];
|
|
2034
2042
|
newEndPoints.forEach((endPoint) => {
|
|
2035
|
-
|
|
2036
|
-
|
|
2043
|
+
const { path: path4, method } = endPoint;
|
|
2044
|
+
const endPointIndex = originalClone.findIndex((original) => {
|
|
2037
2045
|
return original.path === endPoint.path && original.method === endPoint.method;
|
|
2038
2046
|
});
|
|
2039
2047
|
if (endPointIndex === -1) {
|
|
@@ -2042,7 +2050,7 @@ var CompareSchema = class {
|
|
|
2042
2050
|
changeType: "NEW"
|
|
2043
2051
|
});
|
|
2044
2052
|
} else {
|
|
2045
|
-
|
|
2053
|
+
const original = originalClone.findIndex((original2) => {
|
|
2046
2054
|
return this.compareEndPoints(endPoint, original2);
|
|
2047
2055
|
});
|
|
2048
2056
|
if (original === -1) {
|
|
@@ -2055,7 +2063,7 @@ var CompareSchema = class {
|
|
|
2055
2063
|
}
|
|
2056
2064
|
});
|
|
2057
2065
|
originalClone.forEach((original) => {
|
|
2058
|
-
|
|
2066
|
+
const { path: path4, method } = original;
|
|
2059
2067
|
diffObj.push({
|
|
2060
2068
|
name: `${method} ${path4}`,
|
|
2061
2069
|
changeType: "DELETED"
|
|
@@ -2083,7 +2091,7 @@ var compareSchema = new CompareSchema();
|
|
|
2083
2091
|
var compareSchema_default = compareSchema;
|
|
2084
2092
|
|
|
2085
2093
|
// src/restura/restura.ts
|
|
2086
|
-
var { types } =
|
|
2094
|
+
var { types } = pg4;
|
|
2087
2095
|
var ResturaEngine = class {
|
|
2088
2096
|
constructor() {
|
|
2089
2097
|
this.publicEndpoints = {
|