@restura/core 2.1.1 → 2.1.2

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.ts CHANGED
@@ -3,7 +3,7 @@ import { z } from 'zod';
3
3
  import * as express from 'express';
4
4
  import { IncomingHttpHeaders } from 'http2';
5
5
  import { QueryResultRow, QueryConfigValues, QueryResult, PoolConfig, Pool, ClientConfig, Client } from 'pg';
6
- import peg from 'pegjs';
6
+ import * as pegjs from 'pegjs';
7
7
 
8
8
  type LogLevel = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
9
9
  interface ResturaLogger {
@@ -1155,7 +1155,7 @@ declare class ResturaEngine {
1155
1155
  }
1156
1156
  declare const restura: ResturaEngine;
1157
1157
 
1158
- declare const filterPsqlParser: peg.Parser;
1158
+ declare const filterPsqlParser: pegjs.Parser;
1159
1159
 
1160
1160
  declare abstract class SqlEngine {
1161
1161
  runQueryForRoute(req: RsRequest<unknown>, routeData: StandardRouteData, schema: ResturaSchema): Promise<DynamicObject | any[] | boolean>;
@@ -1358,6 +1358,7 @@ interface TriggerSqlOptions {
1358
1358
  delivery?: 'direct' | 'outbox';
1359
1359
  channel?: string;
1360
1360
  tableColumns?: string[];
1361
+ columnTypes?: Record<string, string>;
1361
1362
  }
1362
1363
  interface SchemaGenerationOptions {
1363
1364
  eventDelivery?: 'direct' | 'outbox';
package/dist/index.js CHANGED
@@ -2437,8 +2437,9 @@ function buildTriggerFunctionSql(tableName, operation, notify, options) {
2437
2437
  let updateGuard = "";
2438
2438
  if (operation === "update") {
2439
2439
  updateScope = ` OF ${columns.map((column) => `"${column}"`).join(", ")}`;
2440
+ const columnComparison = (column) => options?.columnTypes?.[column] === "JSON" ? `OLD."${column}"::jsonb IS DISTINCT FROM NEW."${column}"::jsonb` : `OLD."${column}" IS DISTINCT FROM NEW."${column}"`;
2440
2441
  updateGuard = `
2441
- WHEN (${columns.map((column) => `OLD."${column}" IS DISTINCT FROM NEW."${column}"`).join(" OR ")})`;
2442
+ WHEN (${columns.map(columnComparison).join(" OR ")})`;
2442
2443
  }
2443
2444
  return `
2444
2445
  CREATE OR REPLACE FUNCTION ${functionName}()
@@ -2479,7 +2480,8 @@ function generateNotifyTriggersSql(schema, options) {
2479
2480
  const triggerOptions = {
2480
2481
  delivery: options?.eventDelivery,
2481
2482
  channel: options?.outboxChannel,
2482
- tableColumns: table.columns.map((column) => column.name)
2483
+ tableColumns: table.columns.map((column) => column.name),
2484
+ columnTypes: Object.fromEntries(table.columns.map((column) => [column.name, column.type]))
2483
2485
  };
2484
2486
  statements.push(createInsertTriggerSql(table.name, table.notify, triggerOptions));
2485
2487
  statements.push(createUpdateTriggerSql(table.name, table.notify, triggerOptions));
@@ -2810,7 +2812,26 @@ var EventOutboxConsumer = class {
2810
2812
  };
2811
2813
 
2812
2814
  // src/restura/sql/filterPsqlParser.ts
2815
+ import format2 from "pg-format";
2816
+
2817
+ // src/restura/sql/compilePegParser.ts
2813
2818
  import peg from "pegjs";
2819
+ function compilePegParser(grammar, dependencies, modules) {
2820
+ const parserSource = peg.generate(grammar, {
2821
+ output: "source",
2822
+ format: "commonjs",
2823
+ dependencies
2824
+ });
2825
+ const moduleShim = { exports: {} };
2826
+ const requireShim = (moduleId) => {
2827
+ if (moduleId in modules) return modules[moduleId];
2828
+ throw new Error(`compilePegParser: no module provided for dependency '${moduleId}'`);
2829
+ };
2830
+ new Function("module", "exports", "require", parserSource)(moduleShim, moduleShim.exports, requireShim);
2831
+ return moduleShim.exports;
2832
+ }
2833
+
2834
+ // src/restura/sql/filterPsqlParser.ts
2814
2835
  var initializers = `
2815
2836
  // Quotes a SQL identifier (column/table name) with double quotes, escaping any embedded quotes
2816
2837
  function quoteSqlIdentity(value) {
@@ -3146,10 +3167,7 @@ ValueWithPipesChar
3146
3167
  / c:":" !":" { return c; }
3147
3168
  `;
3148
3169
  var fullGrammar = entryGrammar + oldGrammar + newGrammar;
3149
- var filterPsqlParser = peg.generate(fullGrammar, {
3150
- format: "commonjs",
3151
- dependencies: { format: "pg-format" }
3152
- });
3170
+ var filterPsqlParser = compilePegParser(fullGrammar, { format: "pg-format" }, { "pg-format": format2 });
3153
3171
  var filterPsqlParser_default = filterPsqlParser;
3154
3172
 
3155
3173
  // src/restura/sql/PsqlEngine.ts