@restura/core 2.0.1 → 2.0.3

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
@@ -433,15 +433,17 @@ var ResponseValidator = class _ResponseValidator {
433
433
  );
434
434
  return { validator: "any", isOptionalOrNullable: false };
435
435
  }
436
+ const isOptionalOrNullable = isNullable || column.roles.length > 0 || column.scopes.length > 0 || column.isNullable;
437
+ const columnType = column.type.toLowerCase();
438
+ if (columnType === "json" || columnType === "jsonb") {
439
+ return { validator: "object", isOptionalOrNullable };
440
+ }
436
441
  let validator = SqlUtils.convertDatabaseTypeToTypescript(
437
442
  column.type,
438
443
  column.value
439
444
  );
440
445
  if (!_ResponseValidator.validatorIsValidString(validator)) validator = this.parseValidationEnum(validator);
441
- return {
442
- validator,
443
- isOptionalOrNullable: isNullable || column.roles.length > 0 || column.scopes.length > 0 || column.isNullable
444
- };
446
+ return { validator, isOptionalOrNullable };
445
447
  }
446
448
  parseValidationEnum(validator) {
447
449
  let terms = validator.split("|");
@@ -506,8 +508,9 @@ var ResponseValidator = class _ResponseValidator {
506
508
  static isCustomRoute(route) {
507
509
  return route.type === "CUSTOM_ONE" || route.type === "CUSTOM_ARRAY" || route.type === "CUSTOM_PAGED";
508
510
  }
511
+ static VALIDATOR_STRINGS = ["boolean", "string", "number", "object", "any"];
509
512
  static validatorIsValidString(validator) {
510
- return !validator.includes("|");
513
+ return _ResponseValidator.VALIDATOR_STRINGS.includes(validator);
511
514
  }
512
515
  };
513
516
 
@@ -3952,7 +3955,7 @@ async function introspectDatabase(pool) {
3952
3955
  const order = row.indexdef.toUpperCase().includes(" DESC") ? "DESC" : "ASC";
3953
3956
  const columnMatch = row.indexdef.match(/\((.+?)\)(?:\s+WHERE\s+(.+))?$/i);
3954
3957
  const columns = columnMatch ? columnMatch[1].split(",").map(
3955
- (colExpr) => colExpr.trim().replace(/^"(.*)"$/, "$1").replace(/\s+(ASC|DESC)$/i, "")
3958
+ (colExpr) => colExpr.trim().replace(/\s+(ASC|DESC)$/i, "").replace(/^"(.*)"$/, "$1")
3956
3959
  ) : [];
3957
3960
  const whereClause = columnMatch?.[2] ?? null;
3958
3961
  table.indexes.push({
@@ -4354,6 +4357,7 @@ function normalizeCheckExpression(expr) {
4354
4357
  normalized = normalized.replace(/::\w+(\[\])?/g, "");
4355
4358
  normalized = normalized.replace(/=\s*ANY\s*\(\s*\(\s*ARRAY\s*\[([^\]]*)\]\s*\)\s*\)/gi, "IN ($1)");
4356
4359
  normalized = normalized.replace(/=\s*ANY\s*\(\s*ARRAY\s*\[([^\]]*)\]\s*\)/gi, "IN ($1)");
4360
+ normalized = normalized.replace(/\bIN\s*\(\s*('(?:[^']|'')*')\s*\)/gi, "= $1");
4357
4361
  normalized = normalized.replace(/"(\w+)"/g, "$1");
4358
4362
  normalized = normalized.replace(/\((\w+)\)/g, "$1");
4359
4363
  normalized = normalized.replace(/\s+/g, " ").trim();