@restura/core 0.1.0-alpha.25 → 0.1.0-alpha.26
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 +14 -8
- package/dist/index.d.ts +14 -8
- package/dist/index.js +17 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -126,14 +126,14 @@ interface ActionRowInsertData<T = DynamicObject> extends DatabaseActionData {
|
|
|
126
126
|
insertId: number;
|
|
127
127
|
insertObject: T;
|
|
128
128
|
}
|
|
129
|
-
interface ActionRowDeleteData extends DatabaseActionData {
|
|
130
|
-
deletedRow:
|
|
129
|
+
interface ActionRowDeleteData<T = DynamicObject> extends DatabaseActionData {
|
|
130
|
+
deletedRow: T;
|
|
131
131
|
}
|
|
132
|
-
interface ActionColumnChangeData extends DatabaseActionData {
|
|
132
|
+
interface ActionColumnChangeData<T = DynamicObject> extends DatabaseActionData {
|
|
133
133
|
tableName: string;
|
|
134
134
|
rowId: number;
|
|
135
|
-
newData:
|
|
136
|
-
oldData:
|
|
135
|
+
newData: T;
|
|
136
|
+
oldData: T;
|
|
137
137
|
}
|
|
138
138
|
interface ActionRowInsertFilter {
|
|
139
139
|
tableName: string;
|
|
@@ -158,9 +158,9 @@ type QueryMetadata = RequesterDetails & {
|
|
|
158
158
|
};
|
|
159
159
|
declare class EventManager {
|
|
160
160
|
private actionHandlers;
|
|
161
|
-
addRowInsertHandler(onInsert: (data: ActionRowInsertData<
|
|
162
|
-
addColumnChangeHandler(onUpdate: (data: ActionColumnChangeData) => Promise<void>, filter: ActionColumnChangeFilter): void;
|
|
163
|
-
addRowDeleteHandler(onDelete: (data: ActionRowDeleteData) => Promise<void>, filter?: ActionRowDeleteFilter): void;
|
|
161
|
+
addRowInsertHandler<T extends DynamicObject>(onInsert: (data: ActionRowInsertData<T>, queryMetadata: QueryMetadata) => Promise<void>, filter?: ActionRowInsertFilter): void;
|
|
162
|
+
addColumnChangeHandler<T extends DynamicObject>(onUpdate: (data: ActionColumnChangeData<T>, queryMetadata: QueryMetadata) => Promise<void>, filter: ActionColumnChangeFilter): void;
|
|
163
|
+
addRowDeleteHandler<T extends DynamicObject>(onDelete: (data: ActionRowDeleteData<T>, queryMetadata: QueryMetadata) => Promise<void>, filter?: ActionRowDeleteFilter): void;
|
|
164
164
|
fireActionFromDbTrigger(sqlMutationData: SqlMutationData, result: TriggerResult): Promise<void>;
|
|
165
165
|
private fireInsertActions;
|
|
166
166
|
private fireDeleteActions;
|
|
@@ -2564,6 +2564,12 @@ declare class PsqlTransaction extends PsqlConnection {
|
|
|
2564
2564
|
}
|
|
2565
2565
|
|
|
2566
2566
|
declare function escapeColumnName(columnName: string | undefined): string;
|
|
2567
|
+
/**
|
|
2568
|
+
* Converts a query with question marks to a query with numbered parameters,
|
|
2569
|
+
* however it ignores question marks inside single or double quotes.
|
|
2570
|
+
* @param query PostgreSQL query with question marks
|
|
2571
|
+
* @returns A string with numbered parameters such as $1, $2 in replacement of question marks
|
|
2572
|
+
*/
|
|
2567
2573
|
declare function questionMarksToOrderedParams(query: string): string;
|
|
2568
2574
|
declare function insertObjectQuery(table: string, obj: DynamicObject): string;
|
|
2569
2575
|
declare function updateObjectQuery(table: string, obj: DynamicObject, whereStatement: string): string;
|
package/dist/index.d.ts
CHANGED
|
@@ -126,14 +126,14 @@ interface ActionRowInsertData<T = DynamicObject> extends DatabaseActionData {
|
|
|
126
126
|
insertId: number;
|
|
127
127
|
insertObject: T;
|
|
128
128
|
}
|
|
129
|
-
interface ActionRowDeleteData extends DatabaseActionData {
|
|
130
|
-
deletedRow:
|
|
129
|
+
interface ActionRowDeleteData<T = DynamicObject> extends DatabaseActionData {
|
|
130
|
+
deletedRow: T;
|
|
131
131
|
}
|
|
132
|
-
interface ActionColumnChangeData extends DatabaseActionData {
|
|
132
|
+
interface ActionColumnChangeData<T = DynamicObject> extends DatabaseActionData {
|
|
133
133
|
tableName: string;
|
|
134
134
|
rowId: number;
|
|
135
|
-
newData:
|
|
136
|
-
oldData:
|
|
135
|
+
newData: T;
|
|
136
|
+
oldData: T;
|
|
137
137
|
}
|
|
138
138
|
interface ActionRowInsertFilter {
|
|
139
139
|
tableName: string;
|
|
@@ -158,9 +158,9 @@ type QueryMetadata = RequesterDetails & {
|
|
|
158
158
|
};
|
|
159
159
|
declare class EventManager {
|
|
160
160
|
private actionHandlers;
|
|
161
|
-
addRowInsertHandler(onInsert: (data: ActionRowInsertData<
|
|
162
|
-
addColumnChangeHandler(onUpdate: (data: ActionColumnChangeData) => Promise<void>, filter: ActionColumnChangeFilter): void;
|
|
163
|
-
addRowDeleteHandler(onDelete: (data: ActionRowDeleteData) => Promise<void>, filter?: ActionRowDeleteFilter): void;
|
|
161
|
+
addRowInsertHandler<T extends DynamicObject>(onInsert: (data: ActionRowInsertData<T>, queryMetadata: QueryMetadata) => Promise<void>, filter?: ActionRowInsertFilter): void;
|
|
162
|
+
addColumnChangeHandler<T extends DynamicObject>(onUpdate: (data: ActionColumnChangeData<T>, queryMetadata: QueryMetadata) => Promise<void>, filter: ActionColumnChangeFilter): void;
|
|
163
|
+
addRowDeleteHandler<T extends DynamicObject>(onDelete: (data: ActionRowDeleteData<T>, queryMetadata: QueryMetadata) => Promise<void>, filter?: ActionRowDeleteFilter): void;
|
|
164
164
|
fireActionFromDbTrigger(sqlMutationData: SqlMutationData, result: TriggerResult): Promise<void>;
|
|
165
165
|
private fireInsertActions;
|
|
166
166
|
private fireDeleteActions;
|
|
@@ -2564,6 +2564,12 @@ declare class PsqlTransaction extends PsqlConnection {
|
|
|
2564
2564
|
}
|
|
2565
2565
|
|
|
2566
2566
|
declare function escapeColumnName(columnName: string | undefined): string;
|
|
2567
|
+
/**
|
|
2568
|
+
* Converts a query with question marks to a query with numbered parameters,
|
|
2569
|
+
* however it ignores question marks inside single or double quotes.
|
|
2570
|
+
* @param query PostgreSQL query with question marks
|
|
2571
|
+
* @returns A string with numbered parameters such as $1, $2 in replacement of question marks
|
|
2572
|
+
*/
|
|
2567
2573
|
declare function questionMarksToOrderedParams(query: string): string;
|
|
2568
2574
|
declare function insertObjectQuery(table: string, obj: DynamicObject): string;
|
|
2569
2575
|
declare function updateObjectQuery(table: string, obj: DynamicObject, whereStatement: string): string;
|
package/dist/index.js
CHANGED
|
@@ -972,7 +972,7 @@ function resturaGlobalTypesGenerator() {
|
|
|
972
972
|
return `/** Auto generated file. DO NOT MODIFY **/
|
|
973
973
|
/** This file contains types that may be used in the CustomTypes of Restura **/
|
|
974
974
|
/** For example export interface MyPagedQuery extends Restura.PageQuery { } **/
|
|
975
|
-
|
|
975
|
+
|
|
976
976
|
declare namespace Restura {
|
|
977
977
|
export type StandardOrderTypes = 'ASC' | 'DESC' | 'RAND' | 'NONE';
|
|
978
978
|
export interface PageQuery {
|
|
@@ -1554,7 +1554,22 @@ function escapeColumnName(columnName) {
|
|
|
1554
1554
|
}
|
|
1555
1555
|
function questionMarksToOrderedParams(query) {
|
|
1556
1556
|
let count = 1;
|
|
1557
|
-
|
|
1557
|
+
let inSingleQuote = false;
|
|
1558
|
+
let inDoubleQuote = false;
|
|
1559
|
+
return query.replace(/('|"|\?)/g, (char) => {
|
|
1560
|
+
if (char === "'") {
|
|
1561
|
+
inSingleQuote = !inSingleQuote && !inDoubleQuote;
|
|
1562
|
+
return char;
|
|
1563
|
+
}
|
|
1564
|
+
if (char === '"') {
|
|
1565
|
+
inDoubleQuote = !inDoubleQuote && !inSingleQuote;
|
|
1566
|
+
return char;
|
|
1567
|
+
}
|
|
1568
|
+
if (char === "?" && !inSingleQuote && !inDoubleQuote) {
|
|
1569
|
+
return `$${count++}`;
|
|
1570
|
+
}
|
|
1571
|
+
return char;
|
|
1572
|
+
});
|
|
1558
1573
|
}
|
|
1559
1574
|
function insertObjectQuery(table, obj) {
|
|
1560
1575
|
const keys = Object.keys(obj);
|