@restura/core 1.6.0 → 1.8.0

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 CHANGED
@@ -40,6 +40,10 @@ declare const loggerConfigSchema: z.ZodObject<{
40
40
  }, z.core.$strip>;
41
41
  type LoggerConfigSchema = z.infer<typeof loggerConfigSchema>;
42
42
 
43
+ /**
44
+ * @deprecated This is used for passing around until we finally get to the sending externally
45
+ * // TODO: Remove once backwards compatibility is no longer needed
46
+ */
43
47
  interface RsErrorInternalData<T extends Record<string, unknown> = Record<string, unknown>> {
44
48
  err: ErrorCode;
45
49
  msg: string;
@@ -70,13 +74,13 @@ declare enum HtmlStatusCodes {
70
74
  NETWORK_CONNECT_TIMEOUT = 599
71
75
  }
72
76
  type ErrorCode = 'BAD_REQUEST' | 'UNAUTHORIZED' | 'PAYMENT_REQUIRED' | 'FORBIDDEN' | 'NOT_FOUND' | 'METHOD_NOT_ALLOWED' | 'REQUEST_TIMEOUT' | 'CONFLICT' | 'GONE' | 'PAYLOAD_TOO_LARGE' | 'UNSUPPORTED_MEDIA_TYPE' | 'UPGRADE_REQUIRED' | 'UNPROCESSABLE_ENTITY' | 'TOO_MANY_REQUESTS' | 'SERVER_ERROR' | 'NOT_IMPLEMENTED' | 'BAD_GATEWAY' | 'SERVICE_UNAVAILABLE' | 'GATEWAY_TIMEOUT' | 'NETWORK_CONNECT_TIMEOUT' | 'UNKNOWN_ERROR' | 'RATE_LIMIT_EXCEEDED' | 'INVALID_TOKEN' | 'INCORRECT_EMAIL_OR_PASSWORD' | 'DUPLICATE' | 'CONNECTION_ERROR' | 'SCHEMA_ERROR' | 'DATABASE_ERROR';
73
- declare class RsError<T extends Record<string, unknown> = Record<string, unknown>> {
77
+ declare class RsError<T extends Record<string, unknown> = Record<string, unknown>> extends Error {
74
78
  err: ErrorCode;
75
79
  msg: string;
76
80
  options?: T;
77
81
  status?: number;
78
- stack: string;
79
82
  constructor(errCode: ErrorCode, message?: string, options?: T);
83
+ toJSON(): Record<string, unknown>;
80
84
  static htmlStatus(code: ErrorCode): number;
81
85
  static isRsError(error: unknown): error is RsError;
82
86
  }
@@ -168,7 +172,7 @@ declare const responseDataSchema: z.ZodObject<{
168
172
  OR: "OR";
169
173
  }>>;
170
174
  }, z.core.$strict>>;
171
- properties: z.ZodArray<z.ZodObject<any, z.core.$strict>>;
175
+ properties: z.ZodArray<z.ZodObject</*elided*/ any, z.core.$strict>>;
172
176
  groupBy: z.ZodOptional<z.ZodObject<{
173
177
  columnName: z.ZodString;
174
178
  tableName: z.ZodString;
@@ -311,7 +315,7 @@ declare const standardRouteSchema: z.ZodObject<{
311
315
  OR: "OR";
312
316
  }>>;
313
317
  }, z.core.$strict>>;
314
- properties: z.ZodArray<z.ZodObject<any, z.core.$strict>>;
318
+ properties: z.ZodArray<z.ZodObject</*elided*/ any, z.core.$strict>>;
315
319
  groupBy: z.ZodOptional<z.ZodObject<{
316
320
  columnName: z.ZodString;
317
321
  tableName: z.ZodString;
@@ -736,7 +740,7 @@ declare const resturaSchema: z.ZodObject<{
736
740
  OR: "OR";
737
741
  }>>;
738
742
  }, z.core.$strict>>;
739
- properties: z.ZodArray<z.ZodObject<any, z.core.$strict>>;
743
+ properties: z.ZodArray<z.ZodObject</*elided*/ any, z.core.$strict>>;
740
744
  groupBy: z.ZodOptional<z.ZodObject<{
741
745
  columnName: z.ZodString;
742
746
  tableName: z.ZodString;
@@ -1193,10 +1197,16 @@ declare function questionMarksToOrderedParams(query: string): string;
1193
1197
  /**
1194
1198
  * Creates a query to insert an object into a table.
1195
1199
  * @param table Table name to insert the object into
1196
- * @param obj Data to insert into the table
1197
- * @returns the query to insert the object into the table
1200
+ * @param obj Data to insert into the table
1201
+ * @param options.customSelect Optional custom SELECT clause that wraps the INSERT in a CTE.
1202
+ * When provided, the INSERT is wrapped in `WITH inserted AS (INSERT ... RETURNING *)`,
1203
+ * and your customSelect should reference the `inserted` alias.
1204
+ * Example: `{ customSelect: 'SELECT i.*, u.email FROM inserted i JOIN "user" u ON i."userId" = u.id' }`
1205
+ * @returns The query to insert the object into the table
1198
1206
  */
1199
- declare function insertObjectQuery(table: string, obj: DynamicObject): string;
1207
+ declare function insertObjectQuery(table: string, obj: DynamicObject, options?: {
1208
+ customSelect?: string;
1209
+ }): string;
1200
1210
  /**
1201
1211
  * Creates a query to update an object in a table.
1202
1212
  * @param table Table name to update the object in
@@ -1216,5 +1226,18 @@ declare function isValueNumber(value: unknown): value is number;
1216
1226
  * @returns An escaped query with user input
1217
1227
  */
1218
1228
  declare function SQL(strings: TemplateStringsArray, ...values: unknown[]): string;
1229
+ /**
1230
+ * Converts a JavaScript value to its PostgreSQL literal representation.
1231
+ * Used for debug logging of SQL queries — NOT for building actual queries
1232
+ * (use parameterized queries for that).
1233
+ *
1234
+ * @example
1235
+ * toSqlLiteral('hello') // "'hello'"
1236
+ * toSqlLiteral(42) // "42"
1237
+ * toSqlLiteral(true) // "TRUE"
1238
+ * toSqlLiteral(null) // "NULL"
1239
+ * toSqlLiteral([1, 2]) // "ARRAY[1, 2]"
1240
+ */
1241
+ declare function toSqlLiteral(value: unknown): string;
1219
1242
 
1220
- export { type ActionColumnChangeData, type ActionColumnChangeFilter, type ActionRowDeleteData, type ActionRowDeleteFilter, type ActionRowInsertData, type ActionRowInsertFilter, type ApiMethod, type AsyncExpressApplication, type AuthenticateHandler, type AuthenticatedRequesterDetails, type ConjunctionTypes, type DatabaseActionData, type DynamicObject, type ErrorCode, type EventType, HtmlStatusCodes, type LoggerConfigSchema, type MatchTypes, type MutationType, type OnValidAuthenticationCallback, type PageQuery, PsqlConnection, PsqlEngine, PsqlPool, PsqlTransaction, type QueryMetadata, type RequesterDetails, type ResturaConfigSchema, type ResturaSchema, 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, apiGenerator, escapeColumnName, eventManager, filterPsqlParser, insertObjectQuery, isSchemaValid, isValueNumber, logger, modelGenerator, questionMarksToOrderedParams, restura, resturaGlobalTypesGenerator, resturaSchema, updateObjectQuery };
1243
+ export { type ActionColumnChangeData, type ActionColumnChangeFilter, type ActionRowDeleteData, type ActionRowDeleteFilter, type ActionRowInsertData, type ActionRowInsertFilter, type ApiMethod, type AsyncExpressApplication, type AuthenticateHandler, type AuthenticatedRequesterDetails, type ConjunctionTypes, type DatabaseActionData, type DynamicObject, type ErrorCode, type EventType, HtmlStatusCodes, type LoggerConfigSchema, type MatchTypes, type MutationType, type OnValidAuthenticationCallback, type PageQuery, PsqlConnection, PsqlEngine, PsqlPool, PsqlTransaction, type QueryMetadata, type RequesterDetails, type ResturaConfigSchema, type ResturaSchema, 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, apiGenerator, escapeColumnName, eventManager, filterPsqlParser, insertObjectQuery, isSchemaValid, isValueNumber, logger, modelGenerator, questionMarksToOrderedParams, restura, resturaGlobalTypesGenerator, resturaSchema, toSqlLiteral, updateObjectQuery };