@xylex-group/athena 1.0.2 → 1.1.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.
@@ -0,0 +1,84 @@
1
+ import { B as BackendConfig, a as BackendType, A as AthenaConditionValue, b as AthenaConditionArrayValue, c as AthenaConditionOperator, d as AthenaGatewayCallOptions } from './types-IHkO67Tl.cjs';
2
+ export { e as Backend } from './types-IHkO67Tl.cjs';
3
+
4
+ interface SupabaseResult<T> {
5
+ data: T | null;
6
+ error: string | null;
7
+ status: number;
8
+ raw: unknown;
9
+ }
10
+ type MutationSingleResult<Result> = Result extends Array<infer Item> ? Item | null : Result | null;
11
+ interface MutationQuery<Result> extends PromiseLike<SupabaseResult<Result>> {
12
+ select(columns?: string | string[], options?: AthenaGatewayCallOptions): Promise<SupabaseResult<Result>>;
13
+ returning(columns?: string | string[], options?: AthenaGatewayCallOptions): Promise<SupabaseResult<Result>>;
14
+ single(columns?: string | string[], options?: AthenaGatewayCallOptions): Promise<SupabaseResult<MutationSingleResult<Result>>>;
15
+ maybeSingle(columns?: string | string[], options?: AthenaGatewayCallOptions): Promise<SupabaseResult<MutationSingleResult<Result>>>;
16
+ then<TResult1 = SupabaseResult<Result>, TResult2 = never>(onfulfilled?: ((value: SupabaseResult<Result>) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
17
+ catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | undefined | null): Promise<SupabaseResult<Result> | TResult>;
18
+ finally(onfinally?: (() => void) | undefined | null): Promise<SupabaseResult<Result>>;
19
+ }
20
+ /** Shared filter chain - supports eq, limit, etc. in any order relative to select/update */
21
+ interface FilterChain<Self> {
22
+ eq(column: string, value: AthenaConditionValue): Self;
23
+ match(filters: Record<string, AthenaConditionValue>): Self;
24
+ range(from: number, to: number): Self;
25
+ limit(count: number): Self;
26
+ offset(count: number): Self;
27
+ gt(column: string, value: AthenaConditionValue): Self;
28
+ gte(column: string, value: AthenaConditionValue): Self;
29
+ lt(column: string, value: AthenaConditionValue): Self;
30
+ lte(column: string, value: AthenaConditionValue): Self;
31
+ neq(column: string, value: AthenaConditionValue): Self;
32
+ like(column: string, value: AthenaConditionValue): Self;
33
+ ilike(column: string, value: AthenaConditionValue): Self;
34
+ is(column: string, value: AthenaConditionValue): Self;
35
+ in(column: string, values: AthenaConditionArrayValue): Self;
36
+ contains(column: string, values: AthenaConditionArrayValue): Self;
37
+ containedBy(column: string, values: AthenaConditionArrayValue): Self;
38
+ not(columnOrExpression: string, operator?: AthenaConditionOperator, value?: AthenaConditionValue): Self;
39
+ or(expression: string): Self;
40
+ }
41
+ /** Chain returned by select() - supports filters and single/maybeSingle before execution */
42
+ interface SelectChain<Row> extends FilterChain<SelectChain<Row>>, PromiseLike<SupabaseResult<Row[]>> {
43
+ single<T = Row>(columns?: string | string[], options?: AthenaGatewayCallOptions): Promise<SupabaseResult<T | null>>;
44
+ maybeSingle<T = Row>(columns?: string | string[], options?: AthenaGatewayCallOptions): Promise<SupabaseResult<T | null>>;
45
+ }
46
+ /** Chain returned by update() - supports filters before execution, plus select/returning */
47
+ interface UpdateChain<Row> extends FilterChain<UpdateChain<Row>>, MutationQuery<Row[]> {
48
+ }
49
+ interface TableQueryBuilder<Row> extends FilterChain<TableQueryBuilder<Row>> {
50
+ select<T = Row>(columns?: string | string[], options?: AthenaGatewayCallOptions): SelectChain<T>;
51
+ insert(values: Row | Row[], options?: AthenaGatewayCallOptions): MutationQuery<Row | Row[]>;
52
+ upsert(values: Row | Row[], options?: AthenaGatewayCallOptions & {
53
+ updateBody?: Partial<Row>;
54
+ onConflict?: string | string[];
55
+ }): MutationQuery<Row | Row[]>;
56
+ update(values: Partial<Row>, options?: AthenaGatewayCallOptions): UpdateChain<Row>;
57
+ delete(options?: AthenaGatewayCallOptions & {
58
+ resourceId?: string;
59
+ }): MutationQuery<Row | null>;
60
+ single<T = Row>(columns?: string | string[], options?: AthenaGatewayCallOptions): Promise<SupabaseResult<T | null>>;
61
+ maybeSingle<T = Row>(columns?: string | string[], options?: AthenaGatewayCallOptions): Promise<SupabaseResult<T | null>>;
62
+ reset(): TableQueryBuilder<Row>;
63
+ }
64
+ interface SupabaseClient {
65
+ from<Row = unknown>(table: string): TableQueryBuilder<Row>;
66
+ }
67
+ interface AthenaClientBuilder {
68
+ url(url: string): AthenaClientBuilder;
69
+ key(apiKey: string): AthenaClientBuilder;
70
+ backend(backend: BackendConfig | BackendType): AthenaClientBuilder;
71
+ client(clientName: string): AthenaClientBuilder;
72
+ headers(headers: Record<string, string>): AthenaClientBuilder;
73
+ healthTracking(enabled: boolean): AthenaClientBuilder;
74
+ build(): SupabaseClient;
75
+ }
76
+ declare const AthenaClient: {
77
+ builder(): AthenaClientBuilder;
78
+ /** Build client from env: ATHENA_SUPABASE_URL, ATHENA_SUPABASE_KEY (or SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY) */
79
+ fromSupabaseEnv(): SupabaseClient;
80
+ };
81
+ /** Create client (convenience wrapper; use AthenaClient.builder() for full control) */
82
+ declare function createClient(url: string, apiKey: string, options?: Pick<AthenaGatewayCallOptions, 'client' | 'headers' | 'backend'>): SupabaseClient;
83
+
84
+ export { AthenaClient, AthenaGatewayCallOptions, BackendConfig, BackendType, type SupabaseClient, type SupabaseResult, type TableQueryBuilder, createClient };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as AthenaGatewayCallOptions, a as AthenaConditionValue, b as AthenaConditionArrayValue, c as AthenaConditionOperator } from './types-DzCf3v76.js';
2
- export { d as AthenaDeletePayload, e as AthenaFetchPayload, f as AthenaGatewayBaseOptions, g as AthenaGatewayCallLog, h as AthenaGatewayCondition, i as AthenaGatewayEndpointPath, j as AthenaGatewayHookConfig, k as AthenaGatewayHookResult, l as AthenaGatewayMethod, m as AthenaGatewayResponse, n as AthenaGatewayResponseLog, o as AthenaInsertPayload, p as AthenaUpdatePayload } from './types-DzCf3v76.js';
1
+ import { B as BackendConfig, a as BackendType, A as AthenaConditionValue, b as AthenaConditionArrayValue, c as AthenaConditionOperator, d as AthenaGatewayCallOptions } from './types-IHkO67Tl.js';
2
+ export { e as Backend } from './types-IHkO67Tl.js';
3
3
 
4
4
  interface SupabaseResult<T> {
5
5
  data: T | null;
@@ -17,35 +17,46 @@ interface MutationQuery<Result> extends PromiseLike<SupabaseResult<Result>> {
17
17
  catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | undefined | null): Promise<SupabaseResult<Result> | TResult>;
18
18
  finally(onfinally?: (() => void) | undefined | null): Promise<SupabaseResult<Result>>;
19
19
  }
20
- interface TableQueryBuilder<Row> {
21
- select<T = Row>(columns?: string | string[], options?: AthenaGatewayCallOptions): Promise<SupabaseResult<T>>;
20
+ /** Shared filter chain - supports eq, limit, etc. in any order relative to select/update */
21
+ interface FilterChain<Self> {
22
+ eq(column: string, value: AthenaConditionValue): Self;
23
+ match(filters: Record<string, AthenaConditionValue>): Self;
24
+ range(from: number, to: number): Self;
25
+ limit(count: number): Self;
26
+ offset(count: number): Self;
27
+ gt(column: string, value: AthenaConditionValue): Self;
28
+ gte(column: string, value: AthenaConditionValue): Self;
29
+ lt(column: string, value: AthenaConditionValue): Self;
30
+ lte(column: string, value: AthenaConditionValue): Self;
31
+ neq(column: string, value: AthenaConditionValue): Self;
32
+ like(column: string, value: AthenaConditionValue): Self;
33
+ ilike(column: string, value: AthenaConditionValue): Self;
34
+ is(column: string, value: AthenaConditionValue): Self;
35
+ in(column: string, values: AthenaConditionArrayValue): Self;
36
+ contains(column: string, values: AthenaConditionArrayValue): Self;
37
+ containedBy(column: string, values: AthenaConditionArrayValue): Self;
38
+ not(columnOrExpression: string, operator?: AthenaConditionOperator, value?: AthenaConditionValue): Self;
39
+ or(expression: string): Self;
40
+ }
41
+ /** Chain returned by select() - supports filters and single/maybeSingle before execution */
42
+ interface SelectChain<Row> extends FilterChain<SelectChain<Row>>, PromiseLike<SupabaseResult<Row[]>> {
43
+ single<T = Row>(columns?: string | string[], options?: AthenaGatewayCallOptions): Promise<SupabaseResult<T | null>>;
44
+ maybeSingle<T = Row>(columns?: string | string[], options?: AthenaGatewayCallOptions): Promise<SupabaseResult<T | null>>;
45
+ }
46
+ /** Chain returned by update() - supports filters before execution, plus select/returning */
47
+ interface UpdateChain<Row> extends FilterChain<UpdateChain<Row>>, MutationQuery<Row[]> {
48
+ }
49
+ interface TableQueryBuilder<Row> extends FilterChain<TableQueryBuilder<Row>> {
50
+ select<T = Row>(columns?: string | string[], options?: AthenaGatewayCallOptions): SelectChain<T>;
22
51
  insert(values: Row | Row[], options?: AthenaGatewayCallOptions): MutationQuery<Row | Row[]>;
23
52
  upsert(values: Row | Row[], options?: AthenaGatewayCallOptions & {
24
53
  updateBody?: Partial<Row>;
25
54
  onConflict?: string | string[];
26
55
  }): MutationQuery<Row | Row[]>;
27
- update(values: Partial<Row>, options?: AthenaGatewayCallOptions): MutationQuery<Row[]>;
56
+ update(values: Partial<Row>, options?: AthenaGatewayCallOptions): UpdateChain<Row>;
28
57
  delete(options?: AthenaGatewayCallOptions & {
29
58
  resourceId?: string;
30
59
  }): MutationQuery<Row | null>;
31
- eq(column: string, value: AthenaConditionValue): TableQueryBuilder<Row>;
32
- match(filters: Record<string, AthenaConditionValue>): TableQueryBuilder<Row>;
33
- range(from: number, to: number): TableQueryBuilder<Row>;
34
- limit(count: number): TableQueryBuilder<Row>;
35
- offset(count: number): TableQueryBuilder<Row>;
36
- gt(column: string, value: AthenaConditionValue): TableQueryBuilder<Row>;
37
- gte(column: string, value: AthenaConditionValue): TableQueryBuilder<Row>;
38
- lt(column: string, value: AthenaConditionValue): TableQueryBuilder<Row>;
39
- lte(column: string, value: AthenaConditionValue): TableQueryBuilder<Row>;
40
- neq(column: string, value: AthenaConditionValue): TableQueryBuilder<Row>;
41
- like(column: string, value: AthenaConditionValue): TableQueryBuilder<Row>;
42
- ilike(column: string, value: AthenaConditionValue): TableQueryBuilder<Row>;
43
- is(column: string, value: AthenaConditionValue): TableQueryBuilder<Row>;
44
- in(column: string, values: AthenaConditionArrayValue): TableQueryBuilder<Row>;
45
- contains(column: string, values: AthenaConditionArrayValue): TableQueryBuilder<Row>;
46
- containedBy(column: string, values: AthenaConditionArrayValue): TableQueryBuilder<Row>;
47
- not(columnOrExpression: string, operator?: AthenaConditionOperator, value?: AthenaConditionValue): TableQueryBuilder<Row>;
48
- or(expression: string): TableQueryBuilder<Row>;
49
60
  single<T = Row>(columns?: string | string[], options?: AthenaGatewayCallOptions): Promise<SupabaseResult<T | null>>;
50
61
  maybeSingle<T = Row>(columns?: string | string[], options?: AthenaGatewayCallOptions): Promise<SupabaseResult<T | null>>;
51
62
  reset(): TableQueryBuilder<Row>;
@@ -53,6 +64,21 @@ interface TableQueryBuilder<Row> {
53
64
  interface SupabaseClient {
54
65
  from<Row = unknown>(table: string): TableQueryBuilder<Row>;
55
66
  }
56
- declare function createClient(url: string, apiKey: string, options?: AthenaGatewayCallOptions): SupabaseClient;
67
+ interface AthenaClientBuilder {
68
+ url(url: string): AthenaClientBuilder;
69
+ key(apiKey: string): AthenaClientBuilder;
70
+ backend(backend: BackendConfig | BackendType): AthenaClientBuilder;
71
+ client(clientName: string): AthenaClientBuilder;
72
+ headers(headers: Record<string, string>): AthenaClientBuilder;
73
+ healthTracking(enabled: boolean): AthenaClientBuilder;
74
+ build(): SupabaseClient;
75
+ }
76
+ declare const AthenaClient: {
77
+ builder(): AthenaClientBuilder;
78
+ /** Build client from env: ATHENA_SUPABASE_URL, ATHENA_SUPABASE_KEY (or SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY) */
79
+ fromSupabaseEnv(): SupabaseClient;
80
+ };
81
+ /** Create client (convenience wrapper; use AthenaClient.builder() for full control) */
82
+ declare function createClient(url: string, apiKey: string, options?: Pick<AthenaGatewayCallOptions, 'client' | 'headers' | 'backend'>): SupabaseClient;
57
83
 
58
- export { AthenaGatewayCallOptions, type SupabaseClient, type SupabaseResult, type TableQueryBuilder, createClient };
84
+ export { AthenaClient, AthenaGatewayCallOptions, BackendConfig, BackendType, type SupabaseClient, type SupabaseResult, type TableQueryBuilder, createClient };
package/dist/index.js CHANGED
@@ -1,5 +1,3 @@
1
- 'use strict';
2
-
3
1
  // src/gateway/client.ts
4
2
  var DEFAULT_BASE_URL = "https://athena-db.com";
5
3
  var DEFAULT_CLIENT = "railway_direct";
@@ -15,31 +13,32 @@ function normalizeHeaderValue(value) {
15
13
  return value ? value : void 0;
16
14
  }
17
15
  function buildHeaders(config, options) {
18
- const mergedStripNulls = options?.stripNulls ?? config.stripNulls ?? true;
19
- const finalClient = options?.client ?? config.client ?? DEFAULT_CLIENT;
20
- const finalApiKey = options?.apiKey ?? config.apiKey;
21
- const finalSupabaseUrl = options?.supabaseUrl ?? config.supabaseUrl;
22
- const finalSupabaseKey = options?.supabaseKey ?? config.supabaseKey;
23
- const finalPublishEvent = options?.publishEvent ?? config.publishEvent;
16
+ const mergedStripNulls = options?.stripNulls ?? true;
24
17
  const extraHeaders = {
25
18
  ...config.headers ?? {},
26
19
  ...options?.headers ?? {}
27
20
  };
21
+ const headerClient = extraHeaders["x-athena-client"] ?? extraHeaders["X-Athena-Client"];
22
+ const finalClient = options?.client ?? config.client ?? (typeof headerClient === "string" ? headerClient : void 0) ?? DEFAULT_CLIENT;
23
+ const finalApiKey = options?.apiKey ?? config.apiKey;
24
+ const finalPublishEvent = options?.publishEvent ?? config.publishEvent;
28
25
  const headers = {
29
26
  "Content-Type": "application/json"
30
27
  };
31
28
  if (options?.userId ?? config.userId) {
32
29
  headers["X-User-Id"] = options?.userId ?? config.userId ?? "";
33
30
  }
34
- if (options?.companyId ?? config.companyId) {
35
- headers["X-Company-Id"] = options?.companyId ?? config.companyId ?? "";
36
- }
37
31
  if (options?.organizationId ?? config.organizationId) {
38
32
  headers["X-Organization-Id"] = options?.organizationId ?? config.organizationId ?? "";
39
33
  }
40
34
  if (finalClient) {
41
35
  headers["X-Athena-Client"] = finalClient;
42
36
  }
37
+ const finalBackend = options?.backend ?? config.backend;
38
+ if (finalBackend) {
39
+ const type = typeof finalBackend === "string" ? finalBackend : finalBackend.type;
40
+ if (type) headers["X-Backend-Type"] = type;
41
+ }
43
42
  if (typeof mergedStripNulls === "boolean") {
44
43
  headers["X-Strip-Nulls"] = mergedStripNulls ? "true" : "false";
45
44
  }
@@ -50,13 +49,9 @@ function buildHeaders(config, options) {
50
49
  headers["apikey"] = finalApiKey;
51
50
  headers["x-api-key"] = headers["x-api-key"] ?? finalApiKey;
52
51
  }
53
- if (finalSupabaseUrl) {
54
- headers["x-supabase-url"] = finalSupabaseUrl;
55
- }
56
- if (finalSupabaseKey) {
57
- headers["x-supabase-key"] = finalSupabaseKey;
58
- }
52
+ const athenaClientKeys = ["x-athena-client", "X-Athena-Client"];
59
53
  Object.entries(extraHeaders).forEach(([key, value]) => {
54
+ if (athenaClientKeys.includes(key)) return;
60
55
  const normalized = normalizeHeaderValue(value);
61
56
  if (normalized) {
62
57
  headers[key] = normalized;
@@ -196,115 +191,155 @@ function stringifyFilterValue(value) {
196
191
  }
197
192
  return String(value);
198
193
  }
199
- function createTableBuilder(tableName, client) {
200
- const state = {
201
- conditions: []
202
- };
203
- const addCondition = (operator, column, value) => {
204
- const condition = { operator };
205
- if (column) condition.column = column;
206
- if (value !== void 0) condition.value = value;
207
- state.conditions.push(condition);
208
- };
209
- const builder = {
210
- reset() {
211
- state.conditions = [];
212
- state.limit = void 0;
213
- state.offset = void 0;
214
- return builder;
194
+ function createFilterMethods(state, addCondition, self) {
195
+ return {
196
+ eq(column, value) {
197
+ addCondition("eq", column, value);
198
+ return self;
199
+ },
200
+ match(filters) {
201
+ Object.entries(filters).forEach(([column, value]) => addCondition("eq", column, value));
202
+ return self;
215
203
  },
216
204
  range(from, to) {
217
205
  state.offset = from;
218
206
  state.limit = to - from + 1;
219
- return builder;
207
+ return self;
220
208
  },
221
209
  limit(count) {
222
210
  state.limit = count;
223
- return builder;
211
+ return self;
224
212
  },
225
213
  offset(count) {
226
214
  state.offset = count;
227
- return builder;
228
- },
229
- match(filters) {
230
- Object.entries(filters).forEach(([column, value]) => {
231
- addCondition("eq", column, value);
232
- });
233
- return builder;
234
- },
235
- eq(column, value) {
236
- addCondition("eq", column, value);
237
- return builder;
215
+ return self;
238
216
  },
239
217
  gt(column, value) {
240
218
  addCondition("gt", column, value);
241
- return builder;
219
+ return self;
242
220
  },
243
221
  gte(column, value) {
244
222
  addCondition("gte", column, value);
245
- return builder;
223
+ return self;
246
224
  },
247
225
  lt(column, value) {
248
226
  addCondition("lt", column, value);
249
- return builder;
227
+ return self;
250
228
  },
251
229
  lte(column, value) {
252
230
  addCondition("lte", column, value);
253
- return builder;
231
+ return self;
254
232
  },
255
233
  neq(column, value) {
256
234
  addCondition("neq", column, value);
257
- return builder;
235
+ return self;
258
236
  },
259
237
  like(column, value) {
260
238
  addCondition("like", column, value);
261
- return builder;
239
+ return self;
262
240
  },
263
241
  ilike(column, value) {
264
242
  addCondition("ilike", column, value);
265
- return builder;
243
+ return self;
266
244
  },
267
245
  is(column, value) {
268
246
  addCondition("is", column, value);
269
- return builder;
247
+ return self;
270
248
  },
271
249
  in(column, values) {
272
250
  addCondition("in", column, values);
273
- return builder;
251
+ return self;
274
252
  },
275
253
  contains(column, values) {
276
254
  addCondition("contains", column, values);
277
- return builder;
255
+ return self;
278
256
  },
279
257
  containedBy(column, values) {
280
258
  addCondition("containedBy", column, values);
281
- return builder;
259
+ return self;
282
260
  },
283
261
  not(columnOrExpression, operator, value) {
284
- if (operator && value !== void 0) {
262
+ if (operator != null && value !== void 0) {
285
263
  addCondition("not", void 0, `${columnOrExpression}.${operator}.${stringifyFilterValue(value)}`);
286
264
  } else {
287
265
  addCondition("not", void 0, columnOrExpression);
288
266
  }
289
- return builder;
267
+ return self;
290
268
  },
291
269
  or(expression) {
292
270
  addCondition("or", void 0, expression);
271
+ return self;
272
+ }
273
+ };
274
+ }
275
+ function createTableBuilder(tableName, client) {
276
+ const state = {
277
+ conditions: []
278
+ };
279
+ const addCondition = (operator, column, value) => {
280
+ const condition = { operator };
281
+ if (column) {
282
+ condition.column = column;
283
+ if (operator === "eq") {
284
+ condition.eq_column = column;
285
+ }
286
+ }
287
+ if (value !== void 0) {
288
+ condition.value = value;
289
+ if (operator === "eq") {
290
+ condition.eq_value = value;
291
+ }
292
+ }
293
+ state.conditions.push(condition);
294
+ };
295
+ const builder = {};
296
+ const filterMethods = createFilterMethods(state, addCondition, builder);
297
+ const runSelect = async (columns = DEFAULT_COLUMNS, options) => {
298
+ const payload = {
299
+ table_name: tableName,
300
+ columns,
301
+ conditions: state.conditions.length ? [...state.conditions] : void 0,
302
+ limit: state.limit,
303
+ offset: state.offset,
304
+ strip_nulls: options?.stripNulls ?? true,
305
+ count: options?.count,
306
+ head: options?.head
307
+ };
308
+ const response = await client.fetchGateway(payload, options);
309
+ return formatResult(response);
310
+ };
311
+ const createSelectChain = (columns, options) => {
312
+ const chain = {};
313
+ const filterMethods2 = createFilterMethods(state, addCondition, chain);
314
+ Object.assign(chain, filterMethods2, {
315
+ async single(cols, opts) {
316
+ const r = await runSelect(cols ?? columns, opts ?? options);
317
+ return toSingleResult(r);
318
+ },
319
+ maybeSingle(cols, opts) {
320
+ return chain.single(cols, opts);
321
+ },
322
+ then(onfulfilled, onrejected) {
323
+ return runSelect(columns, options).then(onfulfilled, onrejected);
324
+ },
325
+ catch(onrejected) {
326
+ return runSelect(columns, options).catch(onrejected);
327
+ },
328
+ finally(onfinally) {
329
+ return runSelect(columns, options).finally(onfinally);
330
+ }
331
+ });
332
+ return chain;
333
+ };
334
+ Object.assign(builder, filterMethods, {
335
+ reset() {
336
+ state.conditions = [];
337
+ state.limit = void 0;
338
+ state.offset = void 0;
293
339
  return builder;
294
340
  },
295
- async select(columns = DEFAULT_COLUMNS, options) {
296
- const payload = {
297
- table_name: tableName,
298
- columns,
299
- conditions: state.conditions.length ? [...state.conditions] : void 0,
300
- limit: state.limit,
301
- offset: state.offset,
302
- strip_nulls: options?.stripNulls ?? true,
303
- count: options?.count,
304
- head: options?.head
305
- };
306
- const response = await client.fetchGateway(payload, options);
307
- return formatResult(response);
341
+ select(columns = DEFAULT_COLUMNS, options) {
342
+ return createSelectChain(columns, options);
308
343
  },
309
344
  insert(values, options) {
310
345
  const executeInsert = async (columns, selectOptions) => {
@@ -345,8 +380,8 @@ function createTableBuilder(tableName, client) {
345
380
  return createMutationQuery(executeUpsert);
346
381
  },
347
382
  update(values, options) {
348
- const filters = state.conditions.length ? [...state.conditions] : void 0;
349
383
  const executeUpdate = async (columns, selectOptions) => {
384
+ const filters = state.conditions.length ? [...state.conditions] : void 0;
350
385
  const mergedOptions = mergeOptions(options, selectOptions);
351
386
  const payload = {
352
387
  table_name: tableName,
@@ -358,7 +393,11 @@ function createTableBuilder(tableName, client) {
358
393
  const response = await client.updateGateway(payload, mergedOptions);
359
394
  return formatResult(response);
360
395
  };
361
- return createMutationQuery(executeUpdate);
396
+ const mutation = createMutationQuery(executeUpdate);
397
+ const updateChain = {};
398
+ const filterMethods2 = createFilterMethods(state, addCondition, updateChain);
399
+ Object.assign(updateChain, filterMethods2, mutation);
400
+ return updateChain;
362
401
  },
363
402
  delete(options) {
364
403
  const filters = state.conditions.length ? [...state.conditions] : void 0;
@@ -386,23 +425,101 @@ function createTableBuilder(tableName, client) {
386
425
  async maybeSingle(columns, options) {
387
426
  return builder.single(columns, options);
388
427
  }
389
- };
428
+ });
390
429
  return builder;
391
430
  }
392
- function createClient(url, apiKey, options) {
393
- const { baseUrl: optBaseUrl, apiKey: optApiKey, ...restOptions } = options ?? {};
394
- const client = createAthenaGatewayClient({
395
- baseUrl: optBaseUrl ?? url,
396
- apiKey: optApiKey ?? apiKey,
397
- ...restOptions
431
+ function createClientFromConfig(config) {
432
+ const gateway = createAthenaGatewayClient({
433
+ baseUrl: config.baseUrl,
434
+ apiKey: config.apiKey,
435
+ client: config.client,
436
+ backend: config.backend,
437
+ headers: config.headers
398
438
  });
399
439
  return {
400
440
  from(table) {
401
- return createTableBuilder(table, client);
441
+ return createTableBuilder(table, gateway);
402
442
  }
403
443
  };
404
444
  }
445
+ var DEFAULT_BACKEND = { type: "athena" };
446
+ function toBackendConfig(b) {
447
+ if (!b) return DEFAULT_BACKEND;
448
+ return typeof b === "string" ? { type: b } : b;
449
+ }
450
+ var AthenaClient = {
451
+ builder() {
452
+ let url;
453
+ let key;
454
+ let backend = DEFAULT_BACKEND;
455
+ let clientName;
456
+ let headers;
457
+ const builder = {
458
+ url(u) {
459
+ url = u;
460
+ return builder;
461
+ },
462
+ key(k) {
463
+ key = k;
464
+ return builder;
465
+ },
466
+ backend(b) {
467
+ backend = toBackendConfig(b);
468
+ return builder;
469
+ },
470
+ client(c) {
471
+ clientName = c;
472
+ return builder;
473
+ },
474
+ headers(h) {
475
+ headers = h;
476
+ return builder;
477
+ },
478
+ healthTracking(enabled) {
479
+ return builder;
480
+ },
481
+ build() {
482
+ if (!url || !key) {
483
+ throw new Error("AthenaClient requires url and key; call .url() and .key() before .build()");
484
+ }
485
+ return createClientFromConfig({
486
+ baseUrl: url,
487
+ apiKey: key,
488
+ client: clientName,
489
+ backend,
490
+ headers});
491
+ }
492
+ };
493
+ return builder;
494
+ },
495
+ /** Build client from env: ATHENA_SUPABASE_URL, ATHENA_SUPABASE_KEY (or SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY) */
496
+ fromSupabaseEnv() {
497
+ const url = process.env.ATHENA_SUPABASE_URL ?? process.env.SUPABASE_URL;
498
+ const key = process.env.ATHENA_SUPABASE_KEY ?? process.env.SUPABASE_SERVICE_ROLE_KEY;
499
+ if (!url || !key) {
500
+ throw new Error(
501
+ "ATHENA_SUPABASE_URL and ATHENA_SUPABASE_KEY (or SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY) are required"
502
+ );
503
+ }
504
+ return AthenaClient.builder().backend({ type: "supabase" }).url(url).key(key).build();
505
+ }
506
+ };
507
+ function createClient(url, apiKey, options) {
508
+ const b = AthenaClient.builder().url(url).key(apiKey).backend(toBackendConfig(options?.backend));
509
+ if (options?.client) b.client(options.client);
510
+ if (options?.headers && Object.keys(options.headers).length > 0) b.headers(options.headers);
511
+ return b.build();
512
+ }
513
+
514
+ // src/gateway/types.ts
515
+ var Backend = {
516
+ Athena: { type: "athena" },
517
+ Supabase: { type: "supabase" },
518
+ Postgrest: { type: "postgrest" },
519
+ PostgreSQL: { type: "postgresql" },
520
+ ScyllaDB: { type: "scylladb" }
521
+ };
405
522
 
406
- exports.createClient = createClient;
523
+ export { AthenaClient, Backend, createClient };
407
524
  //# sourceMappingURL=index.js.map
408
525
  //# sourceMappingURL=index.js.map