@restura/core 0.1.0-alpha.27 → 0.1.0-alpha.29
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 +31 -1
- package/dist/index.d.ts +31 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -2565,6 +2565,15 @@ declare class PsqlTransaction extends PsqlConnection {
|
|
|
2565
2565
|
protected query<R extends QueryResultRow = QueryResultRow, T extends Array<unknown> = unknown[]>(query: string, values?: QueryConfigValues<T>): Promise<QueryResult<R>>;
|
|
2566
2566
|
}
|
|
2567
2567
|
|
|
2568
|
+
/**
|
|
2569
|
+
* This method does a couple of things:
|
|
2570
|
+
* 1. It escapes the column name to prevent SQL injection by removing any double quotes.
|
|
2571
|
+
* 2. It wraps the column name in double quotes to prevent any issues with reserved words or casing.
|
|
2572
|
+
* 3. It replaces any periods in the column name with a period wrapped in double quotes to prevent any issues with schema names.
|
|
2573
|
+
* NOTE: I looked into using pg-format ident() method but that will strip the double quotes when not needed.
|
|
2574
|
+
* @param columnName
|
|
2575
|
+
* @returns
|
|
2576
|
+
*/
|
|
2568
2577
|
declare function escapeColumnName(columnName: string | undefined): string;
|
|
2569
2578
|
/**
|
|
2570
2579
|
* Converts a query with question marks to a query with numbered parameters,
|
|
@@ -2573,9 +2582,30 @@ declare function escapeColumnName(columnName: string | undefined): string;
|
|
|
2573
2582
|
* @returns A string with numbered parameters such as $1, $2 in replacement of question marks
|
|
2574
2583
|
*/
|
|
2575
2584
|
declare function questionMarksToOrderedParams(query: string): string;
|
|
2585
|
+
/**
|
|
2586
|
+
* Creates a query to insert an object into a table.
|
|
2587
|
+
* @param table Table name to insert the object into
|
|
2588
|
+
* @param obj Data to insert into the table
|
|
2589
|
+
* @returns the query to insert the object into the table
|
|
2590
|
+
*/
|
|
2576
2591
|
declare function insertObjectQuery(table: string, obj: DynamicObject): string;
|
|
2592
|
+
/**
|
|
2593
|
+
* Creates a query to update an object in a table.
|
|
2594
|
+
* @param table Table name to update the object in
|
|
2595
|
+
* @param obj Data to update in the table
|
|
2596
|
+
* @param whereStatement Where clause to determine which rows to update
|
|
2597
|
+
* @returns the query to update the object in the table
|
|
2598
|
+
*/
|
|
2577
2599
|
declare function updateObjectQuery(table: string, obj: DynamicObject, whereStatement: string): string;
|
|
2578
2600
|
declare function isValueNumber(value: unknown): value is number;
|
|
2579
|
-
|
|
2601
|
+
/**
|
|
2602
|
+
* This method is used to format a query and escape user input.
|
|
2603
|
+
* Use this with the SQL tag to escape user input. For example:
|
|
2604
|
+
* SQL`UPDATE "USER" SET "firstName" = ${firstName}, "isActive" = ${isActive} WHERE "id" = ${id} RETURNING *`
|
|
2605
|
+
* @param strings template strings array
|
|
2606
|
+
* @param values values to escape
|
|
2607
|
+
* @returns An escaped query with user input
|
|
2608
|
+
*/
|
|
2609
|
+
declare function SQL(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
2580
2610
|
|
|
2581
2611
|
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 MatchTypes, type MutationType, type PageQuery, PsqlConnection, PsqlEngine, PsqlPool, PsqlTransaction, type QueryMetadata, type RequesterDetails, 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, escapeColumnName, eventManager, insertObjectQuery, isValueNumber, logger, questionMarksToOrderedParams, restura, updateObjectQuery };
|
package/dist/index.d.ts
CHANGED
|
@@ -2565,6 +2565,15 @@ declare class PsqlTransaction extends PsqlConnection {
|
|
|
2565
2565
|
protected query<R extends QueryResultRow = QueryResultRow, T extends Array<unknown> = unknown[]>(query: string, values?: QueryConfigValues<T>): Promise<QueryResult<R>>;
|
|
2566
2566
|
}
|
|
2567
2567
|
|
|
2568
|
+
/**
|
|
2569
|
+
* This method does a couple of things:
|
|
2570
|
+
* 1. It escapes the column name to prevent SQL injection by removing any double quotes.
|
|
2571
|
+
* 2. It wraps the column name in double quotes to prevent any issues with reserved words or casing.
|
|
2572
|
+
* 3. It replaces any periods in the column name with a period wrapped in double quotes to prevent any issues with schema names.
|
|
2573
|
+
* NOTE: I looked into using pg-format ident() method but that will strip the double quotes when not needed.
|
|
2574
|
+
* @param columnName
|
|
2575
|
+
* @returns
|
|
2576
|
+
*/
|
|
2568
2577
|
declare function escapeColumnName(columnName: string | undefined): string;
|
|
2569
2578
|
/**
|
|
2570
2579
|
* Converts a query with question marks to a query with numbered parameters,
|
|
@@ -2573,9 +2582,30 @@ declare function escapeColumnName(columnName: string | undefined): string;
|
|
|
2573
2582
|
* @returns A string with numbered parameters such as $1, $2 in replacement of question marks
|
|
2574
2583
|
*/
|
|
2575
2584
|
declare function questionMarksToOrderedParams(query: string): string;
|
|
2585
|
+
/**
|
|
2586
|
+
* Creates a query to insert an object into a table.
|
|
2587
|
+
* @param table Table name to insert the object into
|
|
2588
|
+
* @param obj Data to insert into the table
|
|
2589
|
+
* @returns the query to insert the object into the table
|
|
2590
|
+
*/
|
|
2576
2591
|
declare function insertObjectQuery(table: string, obj: DynamicObject): string;
|
|
2592
|
+
/**
|
|
2593
|
+
* Creates a query to update an object in a table.
|
|
2594
|
+
* @param table Table name to update the object in
|
|
2595
|
+
* @param obj Data to update in the table
|
|
2596
|
+
* @param whereStatement Where clause to determine which rows to update
|
|
2597
|
+
* @returns the query to update the object in the table
|
|
2598
|
+
*/
|
|
2577
2599
|
declare function updateObjectQuery(table: string, obj: DynamicObject, whereStatement: string): string;
|
|
2578
2600
|
declare function isValueNumber(value: unknown): value is number;
|
|
2579
|
-
|
|
2601
|
+
/**
|
|
2602
|
+
* This method is used to format a query and escape user input.
|
|
2603
|
+
* Use this with the SQL tag to escape user input. For example:
|
|
2604
|
+
* SQL`UPDATE "USER" SET "firstName" = ${firstName}, "isActive" = ${isActive} WHERE "id" = ${id} RETURNING *`
|
|
2605
|
+
* @param strings template strings array
|
|
2606
|
+
* @param values values to escape
|
|
2607
|
+
* @returns An escaped query with user input
|
|
2608
|
+
*/
|
|
2609
|
+
declare function SQL(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
2580
2610
|
|
|
2581
2611
|
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 MatchTypes, type MutationType, type PageQuery, PsqlConnection, PsqlEngine, PsqlPool, PsqlTransaction, type QueryMetadata, type RequesterDetails, 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, escapeColumnName, eventManager, insertObjectQuery, isValueNumber, logger, questionMarksToOrderedParams, restura, updateObjectQuery };
|
package/dist/index.js
CHANGED
|
@@ -1612,6 +1612,8 @@ function SQL(strings, ...values) {
|
|
|
1612
1612
|
query += value;
|
|
1613
1613
|
} else if (typeof value === "number") {
|
|
1614
1614
|
query += value;
|
|
1615
|
+
} else if (Array.isArray(value)) {
|
|
1616
|
+
query += import_pg_format.default.literal(JSON.stringify(value)) + "::jsonb";
|
|
1615
1617
|
} else {
|
|
1616
1618
|
query += import_pg_format.default.literal(value);
|
|
1617
1619
|
}
|