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

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,20 @@ 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
+ private connectPromise;
1512
+ constructor(clientConfig: ClientConfig);
1513
+ close(): Promise<void>;
1514
+ private beginTransaction;
1515
+ rollback(): Promise<QueryResult<QueryResultRow>>;
1516
+ commit(): Promise<QueryResult<QueryResultRow>>;
1517
+ release(): Promise<void>;
1518
+ protected query<R extends QueryResultRow = QueryResultRow, T extends Array<unknown> = unknown[]>(query: string, values?: QueryConfigValues<T>): Promise<QueryResult<R>>;
1519
+ }
1520
+
1507
1521
  type EventType = 'DATABASE_ROW_DELETE' | 'DATABASE_ROW_INSERT' | 'DATABASE_COLUMN_UPDATE' | 'WEBHOOK';
1508
1522
  type MutationType = 'INSERT' | 'UPDATE' | 'DELETE';
1509
1523
  interface SqlMutationData {
@@ -1544,5 +1558,17 @@ type TriggerResult = {
1544
1558
  previousRecord: DynamicObject;
1545
1559
  requesterId: number;
1546
1560
  };
1561
+ declare class EventManager {
1562
+ private actionHandlers;
1563
+ addRowInsertHandler(onInsert: (data: ActionRowInsertData<unknown>) => Promise<void>, filter?: ActionRowInsertFilter): void;
1564
+ addColumnChangeHandler(onUpdate: (data: ActionColumnChangeData) => Promise<void>, filter: ActionColumnChangeFilter): void;
1565
+ addRowDeleteHandler(onDelete: (data: ActionRowDeleteData) => Promise<void>, filter?: ActionRowDeleteFilter): void;
1566
+ fireActionFromDbTrigger(sqlMutationData: SqlMutationData, result: TriggerResult): Promise<void>;
1567
+ private fireInsertActions;
1568
+ private fireDeleteActions;
1569
+ private fireUpdateActions;
1570
+ private hasHandlersForEventType;
1571
+ }
1572
+ declare const eventManager: EventManager;
1547
1573
 
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 };
1574
+ 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,20 @@ 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
+ private connectPromise;
1512
+ constructor(clientConfig: ClientConfig);
1513
+ close(): Promise<void>;
1514
+ private beginTransaction;
1515
+ rollback(): Promise<QueryResult<QueryResultRow>>;
1516
+ commit(): Promise<QueryResult<QueryResultRow>>;
1517
+ release(): Promise<void>;
1518
+ protected query<R extends QueryResultRow = QueryResultRow, T extends Array<unknown> = unknown[]>(query: string, values?: QueryConfigValues<T>): Promise<QueryResult<R>>;
1519
+ }
1520
+
1507
1521
  type EventType = 'DATABASE_ROW_DELETE' | 'DATABASE_ROW_INSERT' | 'DATABASE_COLUMN_UPDATE' | 'WEBHOOK';
1508
1522
  type MutationType = 'INSERT' | 'UPDATE' | 'DELETE';
1509
1523
  interface SqlMutationData {
@@ -1544,5 +1558,17 @@ type TriggerResult = {
1544
1558
  previousRecord: DynamicObject;
1545
1559
  requesterId: number;
1546
1560
  };
1561
+ declare class EventManager {
1562
+ private actionHandlers;
1563
+ addRowInsertHandler(onInsert: (data: ActionRowInsertData<unknown>) => Promise<void>, filter?: ActionRowInsertFilter): void;
1564
+ addColumnChangeHandler(onUpdate: (data: ActionColumnChangeData) => Promise<void>, filter: ActionColumnChangeFilter): void;
1565
+ addRowDeleteHandler(onDelete: (data: ActionRowDeleteData) => Promise<void>, filter?: ActionRowDeleteFilter): void;
1566
+ fireActionFromDbTrigger(sqlMutationData: SqlMutationData, result: TriggerResult): Promise<void>;
1567
+ private fireInsertActions;
1568
+ private fireDeleteActions;
1569
+ private fireUpdateActions;
1570
+ private hasHandlersForEventType;
1571
+ }
1572
+ declare const eventManager: EventManager;
1547
1573
 
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 };
1574
+ 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,48 @@ 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.connectPromise = this.client.connect();
2711
+ this.beginTransactionPromise = this.beginTransaction();
2712
+ }
2713
+ async close() {
2714
+ if (this.client) {
2715
+ await this.client.end();
2716
+ }
2717
+ }
2718
+ async beginTransaction() {
2719
+ await this.connectPromise;
2720
+ return this.client.query("BEGIN");
2721
+ }
2722
+ async rollback() {
2723
+ return this.query("ROLLBACK");
2724
+ }
2725
+ async commit() {
2726
+ return this.query("COMMIT");
2727
+ }
2728
+ async release() {
2729
+ return this.client.end();
2730
+ }
2731
+ async query(query, values) {
2732
+ await this.connectPromise;
2733
+ await this.beginTransactionPromise;
2734
+ return this.client.query(query, values);
2735
+ }
2736
+ };
2702
2737
  // Annotate the CommonJS export names for ESM import in node:
2703
2738
  0 && (module.exports = {
2704
2739
  HtmlStatusCodes,
2740
+ PsqlConnection,
2705
2741
  PsqlPool,
2742
+ PsqlTransaction,
2706
2743
  RsError,
2707
2744
  SQL,
2708
2745
  escapeColumnName,
2746
+ eventManager,
2709
2747
  insertObjectQuery,
2710
2748
  isValueNumber,
2711
2749
  logger,