@xylex-group/athena 1.2.1 → 1.4.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.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as BackendConfig, a as BackendType, A as AthenaConditionValue, b as AthenaConditionArrayValue, c as AthenaConditionOperator, d as AthenaGatewayCallOptions, e as AthenaGatewayErrorDetails, f as AthenaRpcCallOptions } from './errors-DHmpYG46.cjs';
2
- export { g as AthenaGatewayError, h as AthenaGatewayErrorCode, i as AthenaRpcFilter, j as AthenaRpcFilterOperator, k as AthenaRpcOrder, l as AthenaRpcPayload, m as Backend, n as isAthenaGatewayError } from './errors-DHmpYG46.cjs';
1
+ import { B as BackendConfig, a as BackendType, A as AthenaConditionValue, b as AthenaConditionArrayValue, c as AthenaConditionOperator, d as AthenaGatewayCallOptions, e as AthenaGatewayErrorDetails, f as AthenaRpcCallOptions } from './errors-CB-eJQ7x.cjs';
2
+ export { g as AthenaGatewayError, h as AthenaGatewayErrorCode, i as AthenaRpcFilter, j as AthenaRpcFilterOperator, k as AthenaRpcOrder, l as AthenaRpcPayload, m as Backend, n as isAthenaGatewayError } from './errors-CB-eJQ7x.cjs';
3
3
 
4
4
  interface AthenaResult<T> {
5
5
  data: T | null;
@@ -19,6 +19,9 @@ interface MutationQuery<Result> extends PromiseLike<AthenaResult<Result>> {
19
19
  catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | undefined | null): Promise<AthenaResult<Result> | TResult>;
20
20
  finally(onfinally?: (() => void) | undefined | null): Promise<AthenaResult<Result>>;
21
21
  }
22
+ interface OrderOptions {
23
+ ascending?: boolean;
24
+ }
22
25
  /** Shared filter chain - supports eq, limit, etc. in any order relative to select/update */
23
26
  interface FilterChain<Self> {
24
27
  eq(column: string, value: AthenaConditionValue): Self;
@@ -26,6 +29,10 @@ interface FilterChain<Self> {
26
29
  range(from: number, to: number): Self;
27
30
  limit(count: number): Self;
28
31
  offset(count: number): Self;
32
+ currentPage(value: number): Self;
33
+ pageSize(value: number): Self;
34
+ totalPages(value: number): Self;
35
+ order(column: string, options?: OrderOptions): Self;
29
36
  gt(column: string, value: AthenaConditionValue): Self;
30
37
  gte(column: string, value: AthenaConditionValue): Self;
31
38
  lt(column: string, value: AthenaConditionValue): Self;
@@ -123,4 +130,118 @@ declare class AthenaClient {
123
130
  /** Create client (convenience wrapper; use AthenaClient.builder() for full control) */
124
131
  declare function createClient(url: string, apiKey: string, options?: Pick<AthenaGatewayCallOptions, 'client' | 'headers' | 'backend'>): AthenaSdkClient;
125
132
 
126
- export { AthenaClient, AthenaGatewayCallOptions, AthenaGatewayErrorDetails, type AthenaResult, AthenaRpcCallOptions, type AthenaSdkClient, BackendConfig, BackendType, type RpcOrderOptions, type RpcQueryBuilder, type TableQueryBuilder, createClient };
133
+ type AthenaErrorKind = 'unique_violation' | 'not_found' | 'validation' | 'auth' | 'rate_limit' | 'transient' | 'unknown';
134
+ interface AthenaOperationContext {
135
+ table?: string;
136
+ operation?: string;
137
+ identity?: string | Record<string, unknown>;
138
+ }
139
+ interface NormalizedAthenaError {
140
+ kind: AthenaErrorKind;
141
+ status?: number;
142
+ constraint?: string;
143
+ table?: string;
144
+ operation?: string;
145
+ message: string;
146
+ raw: unknown;
147
+ }
148
+ interface UnwrapOptions {
149
+ allowNull?: boolean;
150
+ context?: AthenaOperationContext;
151
+ }
152
+ interface UnwrapOneOptions extends UnwrapOptions {
153
+ requireExactlyOne?: boolean;
154
+ }
155
+ interface IntCoercionOptions {
156
+ strictBigInt?: boolean;
157
+ min?: number;
158
+ max?: number;
159
+ }
160
+ type RetryBackoffStrategy = 'linear' | 'exponential' | ((attempt: number, error: unknown) => number);
161
+ interface RetryConfig {
162
+ retries: number;
163
+ baseDelayMs?: number;
164
+ maxDelayMs?: number;
165
+ backoff?: RetryBackoffStrategy;
166
+ jitter?: boolean | number;
167
+ shouldRetry?: (error: unknown, attempt: number) => boolean | Promise<boolean>;
168
+ }
169
+ interface RequireAffectedOptions {
170
+ min?: number;
171
+ }
172
+ /**
173
+ * Returns `true` when a result is successful (`2xx` status and no `error`).
174
+ */
175
+ declare function isOk<T>(result: AthenaResult<T>): boolean;
176
+ /**
177
+ * Normalizes any Athena failure shape into a stable, typed error envelope.
178
+ *
179
+ * Accepts `AthenaResult`, `AthenaGatewayError`, native `Error`, or unknown values.
180
+ * Optional `context` can override inferred table/operation metadata for clearer diagnostics.
181
+ */
182
+ declare function normalizeAthenaError(resultOrError: unknown, context?: AthenaOperationContext): NormalizedAthenaError;
183
+ /**
184
+ * Unwraps a successful result into a row array.
185
+ *
186
+ * - Throws on failed results.
187
+ * - Converts `null` data to an empty array.
188
+ * - Wraps scalar data in a single-element array.
189
+ */
190
+ declare function unwrapRows<T>(result: AthenaResult<T[] | T | null>, options?: UnwrapOptions): T[];
191
+ /**
192
+ * Unwraps successful result data from `AthenaResult<T | null>`.
193
+ *
194
+ * By default, `null` data throws. Pass `{ allowNull: true }` to permit nullable payloads.
195
+ */
196
+ declare function unwrap<T>(result: AthenaResult<T | null>, options: UnwrapOptions & {
197
+ allowNull: true;
198
+ }): T | null;
199
+ declare function unwrap<T>(result: AthenaResult<T | null>, options?: UnwrapOptions): T;
200
+ /**
201
+ * Unwraps the first row from a successful result that may contain arrays/scalars/null.
202
+ *
203
+ * - Throws on failed results.
204
+ * - Throws when no row exists unless `allowNull: true` is provided.
205
+ * - Optionally enforces exact cardinality via `requireExactlyOne`.
206
+ */
207
+ declare function unwrapOne<T>(result: AthenaResult<T[] | T | null>, options: UnwrapOneOptions & {
208
+ allowNull: true;
209
+ }): T | null;
210
+ declare function unwrapOne<T>(result: AthenaResult<T[] | T | null>, options?: UnwrapOneOptions): T;
211
+ /**
212
+ * Asserts that an Athena result is successful.
213
+ *
214
+ * Returns the original result for fluent composition and throws `AthenaGatewayError` on failure.
215
+ */
216
+ declare function requireSuccess<T>(result: AthenaResult<T>, context?: AthenaOperationContext): AthenaResult<T>;
217
+ /**
218
+ * Enforces mutation postconditions based on `result.count`.
219
+ *
220
+ * - Validates success first.
221
+ * - Requires a non-null count in the response.
222
+ * - Validates `count >= min` (default: `1`).
223
+ *
224
+ * Useful for guaranteeing that critical writes actually affected rows.
225
+ */
226
+ declare function requireAffected<T>(result: AthenaResult<T>, options?: RequireAffectedOptions, context?: AthenaOperationContext): number;
227
+ /**
228
+ * Safely coerces `unknown` values into finite integers.
229
+ *
230
+ * Returns `null` when coercion fails or bounds/strict bigint checks are violated.
231
+ */
232
+ declare function coerceInt(value: unknown, options?: IntCoercionOptions): number | null;
233
+ /**
234
+ * Strict integer assertion wrapper around `coerceInt`.
235
+ *
236
+ * Throws a `TypeError` with the provided label when coercion fails.
237
+ */
238
+ declare function assertInt(value: unknown, label?: string, options?: IntCoercionOptions): number;
239
+ /**
240
+ * Retries an async operation with configurable backoff and retry policy.
241
+ *
242
+ * `retries` represents additional attempts after the first failure.
243
+ * By default, transient and rate-limit errors are retried.
244
+ */
245
+ declare function withRetry<T>(config: RetryConfig, fn: () => Promise<T>): Promise<T>;
246
+
247
+ export { AthenaClient, type AthenaErrorKind, AthenaGatewayCallOptions, AthenaGatewayErrorDetails, type AthenaOperationContext, type AthenaResult, AthenaRpcCallOptions, type AthenaSdkClient, BackendConfig, BackendType, type IntCoercionOptions, type NormalizedAthenaError, type RequireAffectedOptions, type RetryBackoffStrategy, type RetryConfig, type RpcOrderOptions, type RpcQueryBuilder, type TableQueryBuilder, type UnwrapOneOptions, type UnwrapOptions, assertInt, coerceInt, createClient, isOk, normalizeAthenaError, requireAffected, requireSuccess, unwrap, unwrapOne, unwrapRows, withRetry };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as BackendConfig, a as BackendType, A as AthenaConditionValue, b as AthenaConditionArrayValue, c as AthenaConditionOperator, d as AthenaGatewayCallOptions, e as AthenaGatewayErrorDetails, f as AthenaRpcCallOptions } from './errors-DHmpYG46.js';
2
- export { g as AthenaGatewayError, h as AthenaGatewayErrorCode, i as AthenaRpcFilter, j as AthenaRpcFilterOperator, k as AthenaRpcOrder, l as AthenaRpcPayload, m as Backend, n as isAthenaGatewayError } from './errors-DHmpYG46.js';
1
+ import { B as BackendConfig, a as BackendType, A as AthenaConditionValue, b as AthenaConditionArrayValue, c as AthenaConditionOperator, d as AthenaGatewayCallOptions, e as AthenaGatewayErrorDetails, f as AthenaRpcCallOptions } from './errors-CB-eJQ7x.js';
2
+ export { g as AthenaGatewayError, h as AthenaGatewayErrorCode, i as AthenaRpcFilter, j as AthenaRpcFilterOperator, k as AthenaRpcOrder, l as AthenaRpcPayload, m as Backend, n as isAthenaGatewayError } from './errors-CB-eJQ7x.js';
3
3
 
4
4
  interface AthenaResult<T> {
5
5
  data: T | null;
@@ -19,6 +19,9 @@ interface MutationQuery<Result> extends PromiseLike<AthenaResult<Result>> {
19
19
  catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | undefined | null): Promise<AthenaResult<Result> | TResult>;
20
20
  finally(onfinally?: (() => void) | undefined | null): Promise<AthenaResult<Result>>;
21
21
  }
22
+ interface OrderOptions {
23
+ ascending?: boolean;
24
+ }
22
25
  /** Shared filter chain - supports eq, limit, etc. in any order relative to select/update */
23
26
  interface FilterChain<Self> {
24
27
  eq(column: string, value: AthenaConditionValue): Self;
@@ -26,6 +29,10 @@ interface FilterChain<Self> {
26
29
  range(from: number, to: number): Self;
27
30
  limit(count: number): Self;
28
31
  offset(count: number): Self;
32
+ currentPage(value: number): Self;
33
+ pageSize(value: number): Self;
34
+ totalPages(value: number): Self;
35
+ order(column: string, options?: OrderOptions): Self;
29
36
  gt(column: string, value: AthenaConditionValue): Self;
30
37
  gte(column: string, value: AthenaConditionValue): Self;
31
38
  lt(column: string, value: AthenaConditionValue): Self;
@@ -123,4 +130,118 @@ declare class AthenaClient {
123
130
  /** Create client (convenience wrapper; use AthenaClient.builder() for full control) */
124
131
  declare function createClient(url: string, apiKey: string, options?: Pick<AthenaGatewayCallOptions, 'client' | 'headers' | 'backend'>): AthenaSdkClient;
125
132
 
126
- export { AthenaClient, AthenaGatewayCallOptions, AthenaGatewayErrorDetails, type AthenaResult, AthenaRpcCallOptions, type AthenaSdkClient, BackendConfig, BackendType, type RpcOrderOptions, type RpcQueryBuilder, type TableQueryBuilder, createClient };
133
+ type AthenaErrorKind = 'unique_violation' | 'not_found' | 'validation' | 'auth' | 'rate_limit' | 'transient' | 'unknown';
134
+ interface AthenaOperationContext {
135
+ table?: string;
136
+ operation?: string;
137
+ identity?: string | Record<string, unknown>;
138
+ }
139
+ interface NormalizedAthenaError {
140
+ kind: AthenaErrorKind;
141
+ status?: number;
142
+ constraint?: string;
143
+ table?: string;
144
+ operation?: string;
145
+ message: string;
146
+ raw: unknown;
147
+ }
148
+ interface UnwrapOptions {
149
+ allowNull?: boolean;
150
+ context?: AthenaOperationContext;
151
+ }
152
+ interface UnwrapOneOptions extends UnwrapOptions {
153
+ requireExactlyOne?: boolean;
154
+ }
155
+ interface IntCoercionOptions {
156
+ strictBigInt?: boolean;
157
+ min?: number;
158
+ max?: number;
159
+ }
160
+ type RetryBackoffStrategy = 'linear' | 'exponential' | ((attempt: number, error: unknown) => number);
161
+ interface RetryConfig {
162
+ retries: number;
163
+ baseDelayMs?: number;
164
+ maxDelayMs?: number;
165
+ backoff?: RetryBackoffStrategy;
166
+ jitter?: boolean | number;
167
+ shouldRetry?: (error: unknown, attempt: number) => boolean | Promise<boolean>;
168
+ }
169
+ interface RequireAffectedOptions {
170
+ min?: number;
171
+ }
172
+ /**
173
+ * Returns `true` when a result is successful (`2xx` status and no `error`).
174
+ */
175
+ declare function isOk<T>(result: AthenaResult<T>): boolean;
176
+ /**
177
+ * Normalizes any Athena failure shape into a stable, typed error envelope.
178
+ *
179
+ * Accepts `AthenaResult`, `AthenaGatewayError`, native `Error`, or unknown values.
180
+ * Optional `context` can override inferred table/operation metadata for clearer diagnostics.
181
+ */
182
+ declare function normalizeAthenaError(resultOrError: unknown, context?: AthenaOperationContext): NormalizedAthenaError;
183
+ /**
184
+ * Unwraps a successful result into a row array.
185
+ *
186
+ * - Throws on failed results.
187
+ * - Converts `null` data to an empty array.
188
+ * - Wraps scalar data in a single-element array.
189
+ */
190
+ declare function unwrapRows<T>(result: AthenaResult<T[] | T | null>, options?: UnwrapOptions): T[];
191
+ /**
192
+ * Unwraps successful result data from `AthenaResult<T | null>`.
193
+ *
194
+ * By default, `null` data throws. Pass `{ allowNull: true }` to permit nullable payloads.
195
+ */
196
+ declare function unwrap<T>(result: AthenaResult<T | null>, options: UnwrapOptions & {
197
+ allowNull: true;
198
+ }): T | null;
199
+ declare function unwrap<T>(result: AthenaResult<T | null>, options?: UnwrapOptions): T;
200
+ /**
201
+ * Unwraps the first row from a successful result that may contain arrays/scalars/null.
202
+ *
203
+ * - Throws on failed results.
204
+ * - Throws when no row exists unless `allowNull: true` is provided.
205
+ * - Optionally enforces exact cardinality via `requireExactlyOne`.
206
+ */
207
+ declare function unwrapOne<T>(result: AthenaResult<T[] | T | null>, options: UnwrapOneOptions & {
208
+ allowNull: true;
209
+ }): T | null;
210
+ declare function unwrapOne<T>(result: AthenaResult<T[] | T | null>, options?: UnwrapOneOptions): T;
211
+ /**
212
+ * Asserts that an Athena result is successful.
213
+ *
214
+ * Returns the original result for fluent composition and throws `AthenaGatewayError` on failure.
215
+ */
216
+ declare function requireSuccess<T>(result: AthenaResult<T>, context?: AthenaOperationContext): AthenaResult<T>;
217
+ /**
218
+ * Enforces mutation postconditions based on `result.count`.
219
+ *
220
+ * - Validates success first.
221
+ * - Requires a non-null count in the response.
222
+ * - Validates `count >= min` (default: `1`).
223
+ *
224
+ * Useful for guaranteeing that critical writes actually affected rows.
225
+ */
226
+ declare function requireAffected<T>(result: AthenaResult<T>, options?: RequireAffectedOptions, context?: AthenaOperationContext): number;
227
+ /**
228
+ * Safely coerces `unknown` values into finite integers.
229
+ *
230
+ * Returns `null` when coercion fails or bounds/strict bigint checks are violated.
231
+ */
232
+ declare function coerceInt(value: unknown, options?: IntCoercionOptions): number | null;
233
+ /**
234
+ * Strict integer assertion wrapper around `coerceInt`.
235
+ *
236
+ * Throws a `TypeError` with the provided label when coercion fails.
237
+ */
238
+ declare function assertInt(value: unknown, label?: string, options?: IntCoercionOptions): number;
239
+ /**
240
+ * Retries an async operation with configurable backoff and retry policy.
241
+ *
242
+ * `retries` represents additional attempts after the first failure.
243
+ * By default, transient and rate-limit errors are retried.
244
+ */
245
+ declare function withRetry<T>(config: RetryConfig, fn: () => Promise<T>): Promise<T>;
246
+
247
+ export { AthenaClient, type AthenaErrorKind, AthenaGatewayCallOptions, AthenaGatewayErrorDetails, type AthenaOperationContext, type AthenaResult, AthenaRpcCallOptions, type AthenaSdkClient, BackendConfig, BackendType, type IntCoercionOptions, type NormalizedAthenaError, type RequireAffectedOptions, type RetryBackoffStrategy, type RetryConfig, type RpcOrderOptions, type RpcQueryBuilder, type TableQueryBuilder, type UnwrapOneOptions, type UnwrapOptions, assertInt, coerceInt, createClient, isOk, normalizeAthenaError, requireAffected, requireSuccess, unwrap, unwrapOne, unwrapRows, withRetry };