@restura/core 0.1.0-alpha.16 → 0.1.0-alpha.17

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  import winston from 'winston';
2
2
  import * as express from 'express';
3
3
  import { z } from 'zod';
4
- import { QueryResultRow, QueryConfigValues, QueryResult, PoolConfig, Pool } from 'pg';
4
+ import { QueryResultRow, QueryConfigValues, QueryResult, PoolConfig, Pool, ClientConfig, Client } from 'pg';
5
5
  import { IncomingHttpHeaders } from 'http2';
6
6
 
7
7
  declare const logger: winston.Logger;
@@ -1504,6 +1504,18 @@ declare function updateObjectQuery(table: string, obj: DynamicObject, whereState
1504
1504
  declare function isValueNumber(value: unknown): value is number;
1505
1505
  declare function SQL(strings: any, ...values: any): any;
1506
1506
 
1507
+ declare class PsqlTransaction extends PsqlConnection {
1508
+ clientConfig: ClientConfig;
1509
+ client: Client;
1510
+ private beginTransactionPromise;
1511
+ constructor(clientConfig: ClientConfig);
1512
+ private beginTransaction;
1513
+ rollback(): Promise<QueryResult<QueryResultRow>>;
1514
+ commit(): Promise<QueryResult<QueryResultRow>>;
1515
+ release(): Promise<void>;
1516
+ protected query<R extends QueryResultRow = QueryResultRow, T extends Array<unknown> = unknown[]>(query: string, values?: QueryConfigValues<T>): Promise<QueryResult<R>>;
1517
+ }
1518
+
1507
1519
  type EventType = 'DATABASE_ROW_DELETE' | 'DATABASE_ROW_INSERT' | 'DATABASE_COLUMN_UPDATE' | 'WEBHOOK';
1508
1520
  type MutationType = 'INSERT' | 'UPDATE' | 'DELETE';
1509
1521
  interface SqlMutationData {
@@ -1544,5 +1556,17 @@ type TriggerResult = {
1544
1556
  previousRecord: DynamicObject;
1545
1557
  requesterId: number;
1546
1558
  };
1559
+ declare class EventManager {
1560
+ private actionHandlers;
1561
+ addRowInsertHandler(onInsert: (data: ActionRowInsertData<unknown>) => Promise<void>, filter?: ActionRowInsertFilter): void;
1562
+ addColumnChangeHandler(onUpdate: (data: ActionColumnChangeData) => Promise<void>, filter: ActionColumnChangeFilter): void;
1563
+ addRowDeleteHandler(onDelete: (data: ActionRowDeleteData) => Promise<void>, filter?: ActionRowDeleteFilter): void;
1564
+ fireActionFromDbTrigger(sqlMutationData: SqlMutationData, result: TriggerResult): Promise<void>;
1565
+ private fireInsertActions;
1566
+ private fireDeleteActions;
1567
+ private fireUpdateActions;
1568
+ private hasHandlersForEventType;
1569
+ }
1570
+ declare const eventManager: EventManager;
1547
1571
 
1548
- export { type ActionColumnChangeData, type ActionColumnChangeFilter, type ActionRowDeleteData, type ActionRowDeleteFilter, type ActionRowInsertData, type ActionRowInsertFilter, type ApiMethod, type AsyncExpressApplication, type AuthenticateHandler, type AuthenticationUserDetails, type ConjunctionTypes, type DatabaseActionData, type DynamicObject, type ErrorCode, type EventType, HtmlStatusCodes, type LoginDetails, type MatchTypes, type MutationType, type PageQuery, PsqlPool, type RequesterDetails, type ResponseType, type ResponseTypeMap, RsError, type RsErrorData, type RsErrorInternalData, type RsHeaders, type RsPagedResponseData, type RsRequest, type RsResponse, type RsResponseData, type RsRouteHandler, SQL, type SchemaChangeValue, type SchemaPreview, type SqlMutationData, type StandardOrderTypes, type TriggerResult, type ValidAuthenticationCallback, type ValidatorString, escapeColumnName, insertObjectQuery, isValueNumber, logger, questionMarksToOrderedParams, restura, updateObjectQuery };
1572
+ export { type ActionColumnChangeData, type ActionColumnChangeFilter, type ActionRowDeleteData, type ActionRowDeleteFilter, type ActionRowInsertData, type ActionRowInsertFilter, type ApiMethod, type AsyncExpressApplication, type AuthenticateHandler, type AuthenticationUserDetails, type ConjunctionTypes, type DatabaseActionData, type DynamicObject, type ErrorCode, type EventType, HtmlStatusCodes, type LoginDetails, type MatchTypes, type MutationType, type PageQuery, PsqlConnection, PsqlPool, PsqlTransaction, type RequesterDetails, type ResponseType, type ResponseTypeMap, RsError, type RsErrorData, type RsErrorInternalData, type RsHeaders, type RsPagedResponseData, type RsRequest, type RsResponse, type RsResponseData, type RsRouteHandler, SQL, type SchemaChangeValue, type SchemaPreview, type SqlMutationData, type StandardOrderTypes, type TriggerResult, type ValidAuthenticationCallback, type ValidatorString, escapeColumnName, eventManager, insertObjectQuery, isValueNumber, logger, questionMarksToOrderedParams, restura, updateObjectQuery };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import winston from 'winston';
2
2
  import * as express from 'express';
3
3
  import { z } from 'zod';
4
- import { QueryResultRow, QueryConfigValues, QueryResult, PoolConfig, Pool } from 'pg';
4
+ import { QueryResultRow, QueryConfigValues, QueryResult, PoolConfig, Pool, ClientConfig, Client } from 'pg';
5
5
  import { IncomingHttpHeaders } from 'http2';
6
6
 
7
7
  declare const logger: winston.Logger;
@@ -1504,6 +1504,18 @@ declare function updateObjectQuery(table: string, obj: DynamicObject, whereState
1504
1504
  declare function isValueNumber(value: unknown): value is number;
1505
1505
  declare function SQL(strings: any, ...values: any): any;
1506
1506
 
1507
+ declare class PsqlTransaction extends PsqlConnection {
1508
+ clientConfig: ClientConfig;
1509
+ client: Client;
1510
+ private beginTransactionPromise;
1511
+ constructor(clientConfig: ClientConfig);
1512
+ private beginTransaction;
1513
+ rollback(): Promise<QueryResult<QueryResultRow>>;
1514
+ commit(): Promise<QueryResult<QueryResultRow>>;
1515
+ release(): Promise<void>;
1516
+ protected query<R extends QueryResultRow = QueryResultRow, T extends Array<unknown> = unknown[]>(query: string, values?: QueryConfigValues<T>): Promise<QueryResult<R>>;
1517
+ }
1518
+
1507
1519
  type EventType = 'DATABASE_ROW_DELETE' | 'DATABASE_ROW_INSERT' | 'DATABASE_COLUMN_UPDATE' | 'WEBHOOK';
1508
1520
  type MutationType = 'INSERT' | 'UPDATE' | 'DELETE';
1509
1521
  interface SqlMutationData {
@@ -1544,5 +1556,17 @@ type TriggerResult = {
1544
1556
  previousRecord: DynamicObject;
1545
1557
  requesterId: number;
1546
1558
  };
1559
+ declare class EventManager {
1560
+ private actionHandlers;
1561
+ addRowInsertHandler(onInsert: (data: ActionRowInsertData<unknown>) => Promise<void>, filter?: ActionRowInsertFilter): void;
1562
+ addColumnChangeHandler(onUpdate: (data: ActionColumnChangeData) => Promise<void>, filter: ActionColumnChangeFilter): void;
1563
+ addRowDeleteHandler(onDelete: (data: ActionRowDeleteData) => Promise<void>, filter?: ActionRowDeleteFilter): void;
1564
+ fireActionFromDbTrigger(sqlMutationData: SqlMutationData, result: TriggerResult): Promise<void>;
1565
+ private fireInsertActions;
1566
+ private fireDeleteActions;
1567
+ private fireUpdateActions;
1568
+ private hasHandlersForEventType;
1569
+ }
1570
+ declare const eventManager: EventManager;
1547
1571
 
1548
- export { type ActionColumnChangeData, type ActionColumnChangeFilter, type ActionRowDeleteData, type ActionRowDeleteFilter, type ActionRowInsertData, type ActionRowInsertFilter, type ApiMethod, type AsyncExpressApplication, type AuthenticateHandler, type AuthenticationUserDetails, type ConjunctionTypes, type DatabaseActionData, type DynamicObject, type ErrorCode, type EventType, HtmlStatusCodes, type LoginDetails, type MatchTypes, type MutationType, type PageQuery, PsqlPool, type RequesterDetails, type ResponseType, type ResponseTypeMap, RsError, type RsErrorData, type RsErrorInternalData, type RsHeaders, type RsPagedResponseData, type RsRequest, type RsResponse, type RsResponseData, type RsRouteHandler, SQL, type SchemaChangeValue, type SchemaPreview, type SqlMutationData, type StandardOrderTypes, type TriggerResult, type ValidAuthenticationCallback, type ValidatorString, escapeColumnName, insertObjectQuery, isValueNumber, logger, questionMarksToOrderedParams, restura, updateObjectQuery };
1572
+ export { type ActionColumnChangeData, type ActionColumnChangeFilter, type ActionRowDeleteData, type ActionRowDeleteFilter, type ActionRowInsertData, type ActionRowInsertFilter, type ApiMethod, type AsyncExpressApplication, type AuthenticateHandler, type AuthenticationUserDetails, type ConjunctionTypes, type DatabaseActionData, type DynamicObject, type ErrorCode, type EventType, HtmlStatusCodes, type LoginDetails, type MatchTypes, type MutationType, type PageQuery, PsqlConnection, PsqlPool, PsqlTransaction, type RequesterDetails, type ResponseType, type ResponseTypeMap, RsError, type RsErrorData, type RsErrorInternalData, type RsHeaders, type RsPagedResponseData, type RsRequest, type RsResponse, type RsResponseData, type RsRouteHandler, SQL, type SchemaChangeValue, type SchemaPreview, type SqlMutationData, type StandardOrderTypes, type TriggerResult, type ValidAuthenticationCallback, type ValidatorString, escapeColumnName, eventManager, insertObjectQuery, isValueNumber, logger, questionMarksToOrderedParams, restura, updateObjectQuery };
package/dist/index.js CHANGED
@@ -68,10 +68,13 @@ var __decorateClass = (decorators, target, key, kind) => {
68
68
  var src_exports = {};
69
69
  __export(src_exports, {
70
70
  HtmlStatusCodes: () => HtmlStatusCodes,
71
+ PsqlConnection: () => PsqlConnection,
71
72
  PsqlPool: () => PsqlPool,
73
+ PsqlTransaction: () => PsqlTransaction,
72
74
  RsError: () => RsError,
73
75
  SQL: () => SQL,
74
76
  escapeColumnName: () => escapeColumnName,
77
+ eventManager: () => eventManager_default,
75
78
  insertObjectQuery: () => insertObjectQuery,
76
79
  isValueNumber: () => isValueNumber2,
77
80
  logger: () => logger,
@@ -2699,13 +2702,41 @@ var restura = new ResturaEngine();
2699
2702
  // src/restura/sql/PsqlTransaction.ts
2700
2703
  var import_pg4 = __toESM(require("pg"));
2701
2704
  var { Client: Client2 } = import_pg4.default;
2705
+ var PsqlTransaction = class extends PsqlConnection {
2706
+ constructor(clientConfig) {
2707
+ super();
2708
+ this.clientConfig = clientConfig;
2709
+ this.client = new Client2(clientConfig);
2710
+ this.beginTransactionPromise = this.beginTransaction();
2711
+ }
2712
+ async beginTransaction() {
2713
+ return this.query("BEGIN");
2714
+ }
2715
+ async rollback() {
2716
+ return this.query("ROLLBACK");
2717
+ }
2718
+ async commit() {
2719
+ return this.query("COMMIT");
2720
+ }
2721
+ async release() {
2722
+ return this.client.end();
2723
+ }
2724
+ async query(query, values) {
2725
+ await this.client.connect();
2726
+ await this.beginTransactionPromise;
2727
+ return this.client.query(query, values);
2728
+ }
2729
+ };
2702
2730
  // Annotate the CommonJS export names for ESM import in node:
2703
2731
  0 && (module.exports = {
2704
2732
  HtmlStatusCodes,
2733
+ PsqlConnection,
2705
2734
  PsqlPool,
2735
+ PsqlTransaction,
2706
2736
  RsError,
2707
2737
  SQL,
2708
2738
  escapeColumnName,
2739
+ eventManager,
2709
2740
  insertObjectQuery,
2710
2741
  isValueNumber,
2711
2742
  logger,