@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.js CHANGED
@@ -260,7 +260,7 @@ var import_crypto = require("crypto");
260
260
  var express = __toESM(require("express"));
261
261
  var import_fs3 = __toESM(require("fs"));
262
262
  var import_path3 = __toESM(require("path"));
263
- var import_pg3 = __toESM(require("pg"));
263
+ var import_pg4 = __toESM(require("pg"));
264
264
  var prettier3 = __toESM(require("prettier"));
265
265
 
266
266
  // src/restura/sql/SqlUtils.ts
@@ -792,7 +792,7 @@ var joinDataSchema = import_zod3.z.object({
792
792
  var requestDataSchema = import_zod3.z.object({
793
793
  name: import_zod3.z.string(),
794
794
  required: import_zod3.z.boolean(),
795
- isNullable: import_zod3.z.boolean().optional().default(false),
795
+ isNullable: import_zod3.z.boolean().optional(),
796
796
  validator: import_zod3.z.array(validatorDataSchema)
797
797
  }).strict();
798
798
  var responseDataSchema = import_zod3.z.object({
@@ -878,6 +878,12 @@ var postgresColumnDateTypesSchema = import_zod3.z.enum([
878
878
  "INTERVAL"
879
879
  // time span
880
880
  ]);
881
+ var postgresColumnJsonTypesSchema = import_zod3.z.enum([
882
+ "JSON",
883
+ // stores JSON data as raw text
884
+ "JSONB"
885
+ // stores JSON data in a binary format, optimized for query performance
886
+ ]);
881
887
  var mariaDbColumnNumericTypesSchema = import_zod3.z.enum([
882
888
  "BOOLEAN",
883
889
  // 1-byte A synonym for "TINYINT(1)". Supported from version 1.2.0 onwards.
@@ -940,6 +946,7 @@ var columnDataSchema = import_zod3.z.object({
940
946
  postgresColumnNumericTypesSchema,
941
947
  postgresColumnStringTypesSchema,
942
948
  postgresColumnDateTypesSchema,
949
+ postgresColumnJsonTypesSchema,
943
950
  mariaDbColumnNumericTypesSchema,
944
951
  mariaDbColumnStringTypesSchema,
945
952
  mariaDbColumnDateTypesSchema
@@ -1247,10 +1254,16 @@ function convertTable(table) {
1247
1254
 
1248
1255
  // src/restura/sql/PsqlEngine.ts
1249
1256
  var import_core_utils5 = require("@redskytech/core-utils");
1257
+ var import_pg_diff_sync = __toESM(require("@wmfs/pg-diff-sync"));
1258
+ var import_pg_info = __toESM(require("@wmfs/pg-info"));
1259
+ var import_pg2 = __toESM(require("pg"));
1250
1260
 
1251
1261
  // src/restura/sql/PsqlPool.ts
1252
1262
  var import_pg = __toESM(require("pg"));
1253
1263
 
1264
+ // src/restura/sql/PsqlConnection.ts
1265
+ var import_pg_format2 = __toESM(require("pg-format"));
1266
+
1254
1267
  // src/restura/sql/PsqlUtils.ts
1255
1268
  var import_pg_format = __toESM(require("pg-format"));
1256
1269
  function escapeColumnName(columnName) {
@@ -1299,7 +1312,6 @@ function SQL(strings, ...values) {
1299
1312
  }
1300
1313
 
1301
1314
  // src/restura/sql/PsqlConnection.ts
1302
- var import_pg_format2 = __toESM(require("pg-format"));
1303
1315
  var PsqlConnection = class {
1304
1316
  constructor() {
1305
1317
  }
@@ -1578,9 +1590,7 @@ var filterPsqlParser = import_pegjs.default.generate(filterSqlGrammar, {
1578
1590
  var filterPsqlParser_default = filterPsqlParser;
1579
1591
 
1580
1592
  // src/restura/sql/PsqlEngine.ts
1581
- var import_pg_diff_sync = __toESM(require("@wmfs/pg-diff-sync"));
1582
- var import_pg_info = __toESM(require("@wmfs/pg-info"));
1583
- var { Client } = "pg";
1593
+ var { Client } = import_pg2.default;
1584
1594
  var systemUser = {
1585
1595
  role: "",
1586
1596
  host: "",
@@ -1628,7 +1638,7 @@ var PsqlEngine = class extends SqlEngine {
1628
1638
  }
1629
1639
  if (column.isNullable) columnSql += " NULL";
1630
1640
  else columnSql += " NOT NULL";
1631
- if (column.default) columnSql += ` DEFAULT '${column.default}'`;
1641
+ if (column.default) columnSql += ` DEFAULT ${column.default}`;
1632
1642
  tableColumns.push(columnSql);
1633
1643
  }
1634
1644
  sql += tableColumns.join(", \n");
@@ -1715,12 +1725,10 @@ var PsqlEngine = class extends SqlEngine {
1715
1725
  await originalClient.connect();
1716
1726
  await scratchClient.connect();
1717
1727
  const info1 = await (0, import_pg_info.default)({
1718
- client: originalClient,
1719
- schema: "public"
1728
+ client: originalClient
1720
1729
  });
1721
1730
  const info2 = await (0, import_pg_info.default)({
1722
- client: scratchClient,
1723
- schema: "public"
1731
+ client: scratchClient
1724
1732
  });
1725
1733
  const diff = (0, import_pg_diff_sync.default)(info1, info2);
1726
1734
  await originalClient.end();
@@ -1999,17 +2007,17 @@ var PsqlEngine = class extends SqlEngine {
1999
2007
  return whereClause;
2000
2008
  }
2001
2009
  };
2002
- var schemaToPsqlType = (column, tableName) => {
2010
+ function schemaToPsqlType(column, tableName) {
2003
2011
  if (column.hasAutoIncrement) return "BIGSERIAL";
2004
2012
  if (column.type === "ENUM") return `"${tableName}_${column.name}_enum"`;
2005
2013
  if (column.type === "DATETIME") return "TIMESTAMPTZ";
2006
2014
  if (column.type === "MEDIUMINT") return "INT";
2007
2015
  return column.type;
2008
- };
2016
+ }
2009
2017
 
2010
2018
  // src/restura/sql/PsqlTransaction.ts
2011
- var import_pg2 = __toESM(require("pg"));
2012
- var { Client: Client2 } = import_pg2.default;
2019
+ var import_pg3 = __toESM(require("pg"));
2020
+ var { Client: Client2 } = import_pg3.default;
2013
2021
  var PsqlTransaction = class extends PsqlConnection {
2014
2022
  constructor(clientConfig) {
2015
2023
  super();
@@ -2040,21 +2048,21 @@ var PsqlTransaction = class extends PsqlConnection {
2040
2048
  var import_lodash = __toESM(require("lodash.clonedeep"));
2041
2049
  var CompareSchema = class {
2042
2050
  async diffSchema(newSchema, latestSchema, psqlEngine) {
2043
- let endPoints = this.diffEndPoints(newSchema.endpoints[0].routes, latestSchema.endpoints[0].routes);
2044
- let globalParams = this.diffStringArray(newSchema.globalParams, latestSchema.globalParams);
2045
- let roles = this.diffStringArray(newSchema.roles, latestSchema.roles);
2051
+ const endPoints = this.diffEndPoints(newSchema.endpoints[0].routes, latestSchema.endpoints[0].routes);
2052
+ const globalParams = this.diffStringArray(newSchema.globalParams, latestSchema.globalParams);
2053
+ const roles = this.diffStringArray(newSchema.roles, latestSchema.roles);
2046
2054
  let commands = "";
2047
2055
  if (JSON.stringify(newSchema.database) !== JSON.stringify(latestSchema.database))
2048
2056
  commands = await psqlEngine.diffDatabaseToSchema(newSchema);
2049
- let customTypes = newSchema.customTypes !== latestSchema.customTypes;
2057
+ const customTypes = newSchema.customTypes !== latestSchema.customTypes;
2050
2058
  const schemaPreview = { endPoints, globalParams, roles, commands, customTypes };
2051
2059
  return schemaPreview;
2052
2060
  }
2053
2061
  diffStringArray(newArray, originalArray) {
2054
- let stringsDiff = [];
2055
- let originalClone = new Set(originalArray);
2062
+ const stringsDiff = [];
2063
+ const originalClone = new Set(originalArray);
2056
2064
  newArray.forEach((item) => {
2057
- let originalIndex = originalClone.has(item);
2065
+ const originalIndex = originalClone.has(item);
2058
2066
  if (!originalIndex) {
2059
2067
  stringsDiff.push({
2060
2068
  name: item,
@@ -2073,11 +2081,11 @@ var CompareSchema = class {
2073
2081
  return stringsDiff;
2074
2082
  }
2075
2083
  diffEndPoints(newEndPoints, originalEndpoints) {
2076
- let originalClone = (0, import_lodash.default)(originalEndpoints);
2077
- let diffObj = [];
2084
+ const originalClone = (0, import_lodash.default)(originalEndpoints);
2085
+ const diffObj = [];
2078
2086
  newEndPoints.forEach((endPoint) => {
2079
- let { path: path4, method } = endPoint;
2080
- let endPointIndex = originalClone.findIndex((original) => {
2087
+ const { path: path4, method } = endPoint;
2088
+ const endPointIndex = originalClone.findIndex((original) => {
2081
2089
  return original.path === endPoint.path && original.method === endPoint.method;
2082
2090
  });
2083
2091
  if (endPointIndex === -1) {
@@ -2086,7 +2094,7 @@ var CompareSchema = class {
2086
2094
  changeType: "NEW"
2087
2095
  });
2088
2096
  } else {
2089
- let original = originalClone.findIndex((original2) => {
2097
+ const original = originalClone.findIndex((original2) => {
2090
2098
  return this.compareEndPoints(endPoint, original2);
2091
2099
  });
2092
2100
  if (original === -1) {
@@ -2099,7 +2107,7 @@ var CompareSchema = class {
2099
2107
  }
2100
2108
  });
2101
2109
  originalClone.forEach((original) => {
2102
- let { path: path4, method } = original;
2110
+ const { path: path4, method } = original;
2103
2111
  diffObj.push({
2104
2112
  name: `${method} ${path4}`,
2105
2113
  changeType: "DELETED"
@@ -2127,7 +2135,7 @@ var compareSchema = new CompareSchema();
2127
2135
  var compareSchema_default = compareSchema;
2128
2136
 
2129
2137
  // src/restura/restura.ts
2130
- var { types } = import_pg3.default;
2138
+ var { types } = import_pg4.default;
2131
2139
  var ResturaEngine = class {
2132
2140
  constructor() {
2133
2141
  this.publicEndpoints = {