@restura/core 1.0.4 → 1.0.5
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 +4 -2
- package/dist/index.js +31 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -934,8 +934,10 @@ declare abstract class PsqlConnection {
|
|
|
934
934
|
readonly instanceId: UUID;
|
|
935
935
|
protected constructor(instanceId?: UUID);
|
|
936
936
|
protected abstract query<R extends QueryResultRow = QueryResultRow, T extends Array<unknown> = unknown[]>(query: string, values?: QueryConfigValues<T>): Promise<QueryResult<R>>;
|
|
937
|
-
queryOne<T>(query: string, options:
|
|
938
|
-
|
|
937
|
+
queryOne<T>(query: string, options: unknown[], requesterDetails: RequesterDetails): Promise<T>;
|
|
938
|
+
queryOneSchema<T>(query: string, params: unknown[], requesterDetails: RequesterDetails, zodSchema: z.ZodSchema<T>): Promise<T>;
|
|
939
|
+
runQuery<T>(query: string, options: unknown[], requesterDetails: RequesterDetails): Promise<T[]>;
|
|
940
|
+
runQuerySchema<T>(query: string, params: unknown[], requesterDetails: RequesterDetails, zodSchema: z.ZodSchema<T>): Promise<T[]>;
|
|
939
941
|
private logQueryDuration;
|
|
940
942
|
private logSqlStatement;
|
|
941
943
|
}
|
package/dist/index.js
CHANGED
|
@@ -1617,6 +1617,7 @@ import pg from "pg";
|
|
|
1617
1617
|
import crypto from "crypto";
|
|
1618
1618
|
import format3 from "pg-format";
|
|
1619
1619
|
import { format as sqlFormat } from "sql-formatter";
|
|
1620
|
+
import { z as z6 } from "zod/v4";
|
|
1620
1621
|
|
|
1621
1622
|
// src/restura/sql/PsqlUtils.ts
|
|
1622
1623
|
import format2 from "pg-format";
|
|
@@ -1691,7 +1692,6 @@ var PsqlConnection = class {
|
|
|
1691
1692
|
constructor(instanceId) {
|
|
1692
1693
|
this.instanceId = instanceId || crypto.randomUUID();
|
|
1693
1694
|
}
|
|
1694
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1695
1695
|
async queryOne(query, options, requesterDetails) {
|
|
1696
1696
|
const formattedQuery = questionMarksToOrderedParams(query);
|
|
1697
1697
|
const meta = { connectionInstanceId: this.instanceId, ...requesterDetails };
|
|
@@ -1713,7 +1713,21 @@ var PsqlConnection = class {
|
|
|
1713
1713
|
throw new RsError("DATABASE_ERROR", `${error.message}`);
|
|
1714
1714
|
}
|
|
1715
1715
|
}
|
|
1716
|
-
|
|
1716
|
+
async queryOneSchema(query, params, requesterDetails, zodSchema) {
|
|
1717
|
+
const result = await this.queryOne(query, params, requesterDetails);
|
|
1718
|
+
try {
|
|
1719
|
+
return zodSchema.parse(result);
|
|
1720
|
+
} catch (error) {
|
|
1721
|
+
if (error instanceof z6.ZodError) {
|
|
1722
|
+
logger.error("Invalid data returned from database:");
|
|
1723
|
+
logger.silly("\n" + JSON.stringify(result, null, 2));
|
|
1724
|
+
logger.error("\n" + z6.prettifyError(error));
|
|
1725
|
+
} else {
|
|
1726
|
+
logger.error(error);
|
|
1727
|
+
}
|
|
1728
|
+
throw new RsError("DATABASE_ERROR", `Invalid data returned from database`);
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1717
1731
|
async runQuery(query, options, requesterDetails) {
|
|
1718
1732
|
const formattedQuery = questionMarksToOrderedParams(query);
|
|
1719
1733
|
const meta = { connectionInstanceId: this.instanceId, ...requesterDetails };
|
|
@@ -1732,6 +1746,21 @@ var PsqlConnection = class {
|
|
|
1732
1746
|
throw new RsError("DATABASE_ERROR", `${error.message}`);
|
|
1733
1747
|
}
|
|
1734
1748
|
}
|
|
1749
|
+
async runQuerySchema(query, params, requesterDetails, zodSchema) {
|
|
1750
|
+
const result = await this.runQuery(query, params, requesterDetails);
|
|
1751
|
+
try {
|
|
1752
|
+
return z6.array(zodSchema).parse(result);
|
|
1753
|
+
} catch (error) {
|
|
1754
|
+
if (error instanceof z6.ZodError) {
|
|
1755
|
+
logger.error("Invalid data returned from database:");
|
|
1756
|
+
logger.silly("\n" + JSON.stringify(result, null, 2));
|
|
1757
|
+
logger.error("\n" + z6.prettifyError(error));
|
|
1758
|
+
} else {
|
|
1759
|
+
logger.error(error);
|
|
1760
|
+
}
|
|
1761
|
+
throw new RsError("DATABASE_ERROR", `Invalid data returned from database`);
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1735
1764
|
logQueryDuration(startTime) {
|
|
1736
1765
|
if (logger.level === "silly") {
|
|
1737
1766
|
const [seconds, nanoseconds] = process.hrtime(startTime);
|