@umituz/web-database 1.2.0 → 1.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/web-database",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Database layer for the fleet — the single vendor-coupled module (Neon serverless HTTP driver today): sql(url) raw executor, createDb(url, schema) drizzle factory, Db type alias, query utilities (batchQueries, findFirst, findMany, exists, countRows), and db lifecycle tooling (reset / snapshot / seed)",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/src/index.ts CHANGED
@@ -16,6 +16,7 @@ export {
16
16
  findMany,
17
17
  } from './query';
18
18
  export type {
19
+ AnyDb,
19
20
  AnyPgTable,
20
21
  BatchCapableDb,
21
22
  FindManyOptions,
package/src/query.ts CHANGED
@@ -5,11 +5,15 @@ import type { Db } from './driver';
5
5
 
6
6
  export type AnyPgTable = PgTable<TableConfig>;
7
7
 
8
- export type BatchCapableDb = {
9
- batch?: <T extends readonly unknown[]>(queries: readonly [...T]) => Promise<{ [K in keyof T]: Awaited<T[K]> }>;
10
- select: Db['select'];
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ export type AnyDb = Db<any> | {
10
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
+ select: Db<any>['select'];
12
+ batch?: unknown;
11
13
  };
12
14
 
15
+ export type BatchCapableDb = AnyDb;
16
+
13
17
  type TableColumns<T extends AnyPgTable> = T['_']['columns'];
14
18
 
15
19
  type WhereInput<T extends AnyPgTable> =
@@ -46,12 +50,13 @@ export async function batchQueries<T extends readonly PromiseLike<unknown>[]>(
46
50
  queries: readonly [...T]
47
51
  ): Promise<{ [K in keyof T]: Awaited<T[K]> }>;
48
52
  export async function batchQueries(
49
- db: BatchCapableDb,
53
+ db: AnyDb,
50
54
  queries: Record<string, PromiseLike<unknown>> | readonly PromiseLike<unknown>[]
51
55
  ): Promise<unknown> {
56
+ const hasBatch = typeof (db as { batch?: unknown }).batch === 'function';
52
57
  if (Array.isArray(queries)) {
53
- if (typeof db.batch === 'function') {
54
- return db.batch(queries as never);
58
+ if (hasBatch) {
59
+ return (db as unknown as { batch: (items: readonly unknown[]) => Promise<unknown[]> }).batch(queries);
55
60
  }
56
61
  return Promise.all(queries);
57
62
  }
@@ -61,8 +66,8 @@ export async function batchQueries(
61
66
  const promiseList = keys.map((key) => queryMap[key]);
62
67
 
63
68
  let results: unknown[];
64
- if (typeof db.batch === 'function') {
65
- results = (await db.batch(promiseList as never)) as unknown[];
69
+ if (hasBatch) {
70
+ results = (await (db as unknown as { batch: (items: readonly unknown[]) => Promise<unknown[]> }).batch(promiseList)) as unknown[];
66
71
  } else {
67
72
  results = await Promise.all(promiseList);
68
73
  }