uql-orm 0.111.1 → 0.112.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.
Files changed (44) hide show
  1. package/README.md +4 -4
  2. package/dist/browser/uql-browser.min.js +1 -1
  3. package/dist/browser/uql-browser.min.js.map +3 -3
  4. package/dist/bunSql/bunSql.util.d.ts +5 -5
  5. package/dist/bunSql/bunSql.util.js +7 -9
  6. package/dist/bunSql/bunSqlQuerier.js +2 -4
  7. package/dist/bunSql/bunSqlQuerierPool.js +5 -7
  8. package/dist/cockroachdb/crdbQuerierPool.d.ts +2 -5
  9. package/dist/cockroachdb/crdbQuerierPool.js +2 -6
  10. package/dist/entity/decorator/members.d.ts +14 -18
  11. package/dist/entity/decorator/members.js +19 -10
  12. package/dist/entity/metadata/definedFixture/author.d.ts +2 -1
  13. package/dist/entity/metadata/definedFixture/folder.d.ts +126 -0
  14. package/dist/entity/metadata/definedFixture/folder.js +12 -0
  15. package/dist/entity/metadata/definition.js +3 -3
  16. package/dist/mariadb/mariadbQuerierPool.d.ts +7 -1
  17. package/dist/mariadb/mariadbQuerierPool.js +0 -1
  18. package/dist/migrate/codegen/entityCodeGenerator.js +2 -3
  19. package/dist/migrate/migrationLock.js +2 -1
  20. package/dist/mssql/mssqlQuerier.js +2 -1
  21. package/dist/mysql/mysql2QuerierPool.js +2 -1
  22. package/dist/neon/neonQuerierPool.js +2 -2
  23. package/dist/pglite/pgliteDialect.d.ts +1 -3
  24. package/dist/pglite/pgliteDialect.js +1 -3
  25. package/dist/pglite/pgliteQuerier.d.ts +2 -8
  26. package/dist/pglite/pgliteQuerier.js +2 -6
  27. package/dist/postgres/abstractPgQuerierPool.d.ts +5 -9
  28. package/dist/postgres/abstractPgQuerierPool.js +7 -4
  29. package/dist/postgres/pgExecution.d.ts +2 -2
  30. package/dist/postgres/pgQuerier.js +3 -3
  31. package/dist/postgres/pgQuerierPool.d.ts +1 -2
  32. package/dist/postgres/pgQuerierPool.js +1 -5
  33. package/dist/postgres/pgWireTypes.d.ts +1 -2
  34. package/dist/querier/abstractQuerier.js +3 -3
  35. package/dist/querier/abstractSharedHandleQuerierPool.js +2 -1
  36. package/dist/sqlite/hranaQuerier.d.ts +2 -2
  37. package/dist/sqlite/localSqliteQuerierPool.d.ts +1 -1
  38. package/dist/sqlite/sqliteQuerierPool.d.ts +2 -2
  39. package/dist/sqlite/sqliteQuerierPool.js +2 -2
  40. package/dist/type/definedEntity.d.ts +8 -1
  41. package/dist/util/object.util.d.ts +2 -0
  42. package/dist/util/object.util.js +2 -0
  43. package/package.json +7 -7
  44. package/skills/uql-orm/SKILL.md +5 -5
@@ -0,0 +1,126 @@
1
+ export declare const Folder: import("../../../index.js").RelatedEntity<object & {
2
+ id: number;
3
+ name: string;
4
+ size: number;
5
+ } & {
6
+ parentId?: number | null | undefined;
7
+ } & import("../../../index.js").Brands<{
8
+ readonly id: import("../../../index.js").NumericColumn<{
9
+ readonly type: NumberConstructor;
10
+ } & {
11
+ readonly isId: true;
12
+ readonly autoIncrement: true;
13
+ }, number>;
14
+ readonly name: import("../../../index.js").StringColumn<{
15
+ readonly type: StringConstructor;
16
+ }, string>;
17
+ readonly size: import("../../../index.js").NumericColumn<{
18
+ readonly type: NumberConstructor;
19
+ }, number>;
20
+ readonly parentId: import("../../../index.js").NumericColumn<{
21
+ readonly type: NumberConstructor;
22
+ } & {
23
+ readonly nullable: true;
24
+ }, number>;
25
+ }, object> & import("../../../index.js").RelationRow<{
26
+ readonly parent: () => import("../../../index.js").DefinedRelation<object & {
27
+ id: number;
28
+ name: string;
29
+ size: number;
30
+ } & {
31
+ parentId?: number | null | undefined;
32
+ } & import("../../../index.js").Brands<{
33
+ readonly id: import("../../../index.js").NumericColumn<{
34
+ readonly type: NumberConstructor;
35
+ } & {
36
+ readonly isId: true;
37
+ readonly autoIncrement: true;
38
+ }, number>;
39
+ readonly name: import("../../../index.js").StringColumn<{
40
+ readonly type: StringConstructor;
41
+ }, string>;
42
+ readonly size: import("../../../index.js").NumericColumn<{
43
+ readonly type: NumberConstructor;
44
+ }, number>;
45
+ readonly parentId: import("../../../index.js").NumericColumn<{
46
+ readonly type: NumberConstructor;
47
+ } & {
48
+ readonly nullable: true;
49
+ }, number>;
50
+ }, object> & import("../../../index.js").RelationRow</*elided*/ any> & import("../../../index.js").AggregateRow<{
51
+ readonly childCount: () => import("../../../index.js").RelationAggregate<number>;
52
+ readonly childSize: () => import("../../../index.js").RelationAggregate<number>;
53
+ }>, "m1", object & {
54
+ id: number;
55
+ name: string;
56
+ size: number;
57
+ } & {
58
+ parentId?: number | null | undefined;
59
+ } & import("../../../index.js").Brands<{
60
+ readonly id: import("../../../index.js").NumericColumn<{
61
+ readonly type: NumberConstructor;
62
+ } & {
63
+ readonly isId: true;
64
+ readonly autoIncrement: true;
65
+ }, number>;
66
+ readonly name: import("../../../index.js").StringColumn<{
67
+ readonly type: StringConstructor;
68
+ }, string>;
69
+ readonly size: import("../../../index.js").NumericColumn<{
70
+ readonly type: NumberConstructor;
71
+ }, number>;
72
+ readonly parentId: import("../../../index.js").NumericColumn<{
73
+ readonly type: NumberConstructor;
74
+ } & {
75
+ readonly nullable: true;
76
+ }, number>;
77
+ }, object> & import("../../../index.js").RelationRow</*elided*/ any> & import("../../../index.js").AggregateRow<{
78
+ readonly childCount: () => import("../../../index.js").RelationAggregate<number>;
79
+ readonly childSize: () => import("../../../index.js").RelationAggregate<number>;
80
+ }>>;
81
+ readonly children: () => import("../../../index.js").DefinedRelation<object & {
82
+ id: number;
83
+ name: string;
84
+ size: number;
85
+ } & {
86
+ parentId?: number | null | undefined;
87
+ } & import("../../../index.js").Brands<{
88
+ readonly id: import("../../../index.js").NumericColumn<{
89
+ readonly type: NumberConstructor;
90
+ } & {
91
+ readonly isId: true;
92
+ readonly autoIncrement: true;
93
+ }, number>;
94
+ readonly name: import("../../../index.js").StringColumn<{
95
+ readonly type: StringConstructor;
96
+ }, string>;
97
+ readonly size: import("../../../index.js").NumericColumn<{
98
+ readonly type: NumberConstructor;
99
+ }, number>;
100
+ readonly parentId: import("../../../index.js").NumericColumn<{
101
+ readonly type: NumberConstructor;
102
+ } & {
103
+ readonly nullable: true;
104
+ }, number>;
105
+ }, object> & import("../../../index.js").RelationRow</*elided*/ any> & import("../../../index.js").AggregateRow<{
106
+ readonly childCount: () => import("../../../index.js").RelationAggregate<number>;
107
+ readonly childSize: () => import("../../../index.js").RelationAggregate<number>;
108
+ }>, "1m", {
109
+ id: number;
110
+ name: string;
111
+ size: number;
112
+ } & {
113
+ parentId?: number | null | undefined;
114
+ }>;
115
+ }> & import("../../../index.js").AggregateRow<{
116
+ readonly childCount: () => import("../../../index.js").RelationAggregate<number>;
117
+ readonly childSize: () => import("../../../index.js").RelationAggregate<number>;
118
+ }>, number, {
119
+ id: number;
120
+ name: string;
121
+ size: number;
122
+ } & {
123
+ parentId?: number | null | undefined;
124
+ }, false>;
125
+ export interface Folder extends InstanceType<typeof Folder> {
126
+ }
@@ -0,0 +1,12 @@
1
+ import { f } from '../../column.js';
2
+ import { defineEntity } from '../definition.js';
3
+ export const Folder = defineEntity({
4
+ name: 'Folder',
5
+ fields: { id: f.number().autoIncrement(), name: f.string(), size: f.number(), parentId: f.number().nullable() },
6
+ }).relations((rel) => ({
7
+ parent: () => rel.manyToOne(Folder, { references: (folder) => folder.parentId }),
8
+ children: () => rel.oneToMany(Folder, { mappedBy: (folder) => folder.parent }),
9
+ }), (folder) => ({
10
+ childCount: () => folder.children.count(),
11
+ childSize: () => folder.children.sum((child) => child.size),
12
+ }));
@@ -69,8 +69,8 @@ export function keyOf(pick) {
69
69
  const KEY_MAP = new Proxy({}, { get: (_, key) => key });
70
70
  function addRelation(meta, key, registration) {
71
71
  const { entity } = meta;
72
- if (!registration.entity) {
73
- throw new UqlUsageError(`'${entity.name}.${key}' needs an 'entity' getter, e.g. '@ManyToOne({ entity: () => Company })'.`);
72
+ if (typeof registration.entity !== 'function') {
73
+ throw new UqlUsageError(`'${entity.name}.${key}' needs its target first, e.g. '@ManyToOne(() => Company)'.`);
74
74
  }
75
75
  if (registration.through && registration.references) {
76
76
  throw new UqlUsageError(`'${entity.name}.${key}' joins through a junction, whose column referencing each side is the join; ` +
@@ -246,7 +246,7 @@ function fieldsOf(name, values) {
246
246
  if (field instanceof RelationAggregate) {
247
247
  return [key, aggregateField(field)];
248
248
  }
249
- // The types refuse anything else; an untyped caller still reaches here.
249
+ // The types refuse anything else, but for an aggregate thunk, whose constraint cannot read what it returns.
250
250
  if (!isColumn(field)) {
251
251
  throw new UqlUsageError(`'${name}.${key}' is neither a column nor an aggregate: declare it as one`);
252
252
  }
@@ -1,8 +1,14 @@
1
- import { createPool, type Pool } from 'mariadb';
1
+ import { createPool, type Pool, type SqlError } from 'mariadb';
2
2
  import { AbstractSqlQuerierPool } from '../querier/index.js';
3
3
  import type { ExtraOptions } from '../type/index.js';
4
4
  import { MariaDialect } from './mariaDialect.js';
5
5
  import { MariadbQuerier } from './mariadbQuerier.js';
6
+ declare module 'mariadb' {
7
+ /** The pool is an `EventEmitter` firing 'error' on a connection it cannot open or clean up, which its types leave out. */
8
+ interface Pool {
9
+ on(ev: 'error', callback: (err: SqlError) => void): Pool;
10
+ }
11
+ }
6
12
  type PoolConfig = Exclude<Parameters<typeof createPool>[0], string>;
7
13
  export declare class MariadbQuerierPool extends AbstractSqlQuerierPool<MariadbQuerier, MariaDialect> {
8
14
  readonly pool: Pool;
@@ -13,7 +13,6 @@ export class MariadbQuerierPool extends AbstractSqlQuerierPool {
13
13
  // reads as its UTC text, which hydration decodes, since the connector would take it for local time
14
14
  // whatever `timezone` says; that only sets the session's zone, UTC, so `NOW()` agrees.
15
15
  this.pool = createPool({ timezone: 'Z', dateStrings: true, ...opts });
16
- // `mariadb` fires 'error' at runtime without declaring it, hence the cast; this makes it visible.
17
16
  attachPoolErrorHandler(this.pool, 'MariaDB pool connection encountered an error', extra?.logger);
18
17
  }
19
18
  async getQuerier() {
@@ -169,14 +169,13 @@ export class EntityCodeGenerator {
169
169
  const relatedClassName = this.options.classNameTransformer(rel.to.table.name);
170
170
  const references = this.referencesSource(rel, relatedClassName);
171
171
  const options = [
172
- `entity: () => ${relatedClassName}`,
173
172
  ...(references ? [`references: ${references}`] : []),
174
173
  ...(rel.onDelete && rel.onDelete !== DEFAULT_FOREIGN_KEY_ACTION ? [`onDelete: '${rel.onDelete}'`] : []),
175
174
  ...(rel.onUpdate && rel.onUpdate !== DEFAULT_FOREIGN_KEY_ACTION ? [`onUpdate: '${rel.onUpdate}'`] : []),
176
175
  ];
177
176
  return [
178
177
  ...this.syncDoc(`Relation to ${rel.to.table.name} via ${rel.from.columns.map((c) => c.name).join(', ')}`),
179
- ` @${rel.type}({ ${options.join(', ')} })`,
178
+ ` @${rel.type}(() => ${relatedClassName}${options.length ? `, { ${options.join(', ')} }` : ''})`,
180
179
  ` ${this.owningPropertyName(rel)}?: ${relatedClassName};`,
181
180
  ].join('\n');
182
181
  }
@@ -225,7 +224,7 @@ export class EntityCodeGenerator {
225
224
  const many = inverseType === 'OneToMany' || inverseType === 'ManyToMany';
226
225
  return [
227
226
  ...this.syncDoc(`Inverse relation from ${rel.from.table.name}`),
228
- ` @${inverseType}({ entity: () => ${relatedClassName}, mappedBy: (${param}) => ${inverse} })`,
227
+ ` @${inverseType}(() => ${relatedClassName}, { mappedBy: (${param}) => ${inverse} })`,
229
228
  ` ${this.inversePropertyName(rel)}?: ${relatedClassName}${many ? '[]' : ''};`,
230
229
  ].join('\n');
231
230
  }
@@ -1,3 +1,4 @@
1
+ import { noop } from '../util/object.util.js';
1
2
  import { sql } from '../util/sql.js';
2
3
  import { fnv1a } from '../util/string.util.js';
3
4
  import { UqlUsageError } from '../util/uqlError.js';
@@ -49,7 +50,7 @@ export async function holdingLock(lock, { name, timeout }, work) {
49
50
  await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
50
51
  }
51
52
  const result = await work().catch(async (error) => {
52
- await lock.release().catch(() => { });
53
+ await lock.release().catch(noop);
53
54
  throw error;
54
55
  });
55
56
  await lock.release();
@@ -1,5 +1,6 @@
1
1
  import mssql from 'mssql';
2
2
  import { AbstractPoolQuerier } from '../querier/abstractPoolQuerier.js';
3
+ import { noop } from '../util/object.util.js';
3
4
  import { decodeWireTypes } from './mssqlWireTypes.js';
4
5
  /**
5
6
  * A connection is a `ConnectionPool` handle here rather than a checked-out socket: `mssql` owns its
@@ -48,7 +49,7 @@ export class MsSqlQuerier extends AbstractPoolQuerier {
48
49
  }
49
50
  finally {
50
51
  // The cancel reports itself as an error on the stream, and the loop that would hear it is gone.
51
- rows.on('error', () => { });
52
+ rows.on('error', noop);
52
53
  request.cancel();
53
54
  await completed;
54
55
  }
@@ -2,6 +2,7 @@ import { promisify } from 'node:util';
2
2
  import { createPool } from 'mysql2/promise';
3
3
  import { dialectOptionsFrom } from '../dialect/abstractDialect.js';
4
4
  import { AbstractSqlQuerierPool } from '../querier/index.js';
5
+ import { noop } from '../util/object.util.js';
5
6
  import { MySql2Querier } from './mysql2Querier.js';
6
7
  import { MySqlDialect } from './mysqlDialect.js';
7
8
  export class MySql2QuerierPool extends AbstractSqlQuerierPool {
@@ -14,7 +15,7 @@ export class MySql2QuerierPool extends AbstractSqlQuerierPool {
14
15
  this.pool = createPool({ supportBigNumbers: true, timezone: 'Z', ...opts });
15
16
  // The session in UTC too, so `NOW()` agrees with a bound date: queued as each connection opens, ahead of
16
17
  // any statement on it. One that fails has lost its connection, which the next statement reports.
17
- this.pool.pool.on('connection', (connection) => connection.query("SET time_zone = '+00:00'", () => { }));
18
+ this.pool.pool.on('connection', (connection) => connection.query("SET time_zone = '+00:00'", noop));
18
19
  }
19
20
  async getQuerier() {
20
21
  const { pool } = this.pool;
@@ -4,16 +4,16 @@ import { pgExecution } from '../postgres/pgExecution.js';
4
4
  import { PgQuerier } from '../postgres/pgQuerier.js';
5
5
  import { wireTypes } from '../postgres/pgWireTypes.js';
6
6
  import { AbstractSqlQuerierPool } from '../querier/index.js';
7
+ import { noop } from '../util/object.util.js';
7
8
  import { NeonDialect } from './neonDialect.js';
8
9
  import { NeonQuerier } from './neonQuerier.js';
9
- const ignoreError = () => { };
10
10
  /**
11
11
  * A WebSocket session of one querier's own, ended where a pooled client would be handed back. A socket error while
12
12
  * it closes is heard and dropped, as `pg-pool` hears one on a client it holds, rather than reaching no listener.
13
13
  */
14
14
  class NeonSession extends Client {
15
15
  release() {
16
- this.on('error', ignoreError);
16
+ this.on('error', noop);
17
17
  return this.end();
18
18
  }
19
19
  }
@@ -1,9 +1,7 @@
1
1
  import { PostgresDialect } from '../postgres/postgresDialect.js';
2
2
  import type { SqlDialectFeatures } from '../type/index.js';
3
- /** Postgres as PGlite runs it, which binds fewer values per statement than a server. */
3
+ /** Postgres as PGlite runs it, one session shared by every querier. */
4
4
  export declare class PgliteDialect extends PostgresDialect {
5
5
  /** Every querier shares the one session, which an advisory lock it already holds never makes wait. */
6
6
  readonly features: SqlDialectFeatures;
7
- /** Past 32767 PGlite answers no rows, and wrong ones from then on, where a server takes 65535. */
8
- readonly maxBindValues: number;
9
7
  }
@@ -1,8 +1,6 @@
1
1
  import { POSTGRES_FEATURES, PostgresDialect } from '../postgres/postgresDialect.js';
2
- /** Postgres as PGlite runs it, which binds fewer values per statement than a server. */
2
+ /** Postgres as PGlite runs it, one session shared by every querier. */
3
3
  export class PgliteDialect extends PostgresDialect {
4
4
  /** Every querier shares the one session, which an advisory lock it already holds never makes wait. */
5
5
  features = { ...POSTGRES_FEATURES, namedLocks: false };
6
- /** Past 32767 PGlite answers no rows, and wrong ones from then on, where a server takes 65535. */
7
- maxBindValues = 32767;
8
6
  }
@@ -1,13 +1,11 @@
1
+ import { type PgResult } from '../postgres/pgExecution.js';
1
2
  import { AbstractSqlQuerier } from '../querier/index.js';
2
3
  import type { ExtraOptions } from '../type/index.js';
3
4
  import type { SqlExecution } from '../util/sql.util.js';
4
5
  import type { PgliteDialect } from './pgliteDialect.js';
5
6
  /** The two methods uql uses of `@electric-sql/pglite`, stated so its published types do not depend on a pre-1.0 package. */
6
7
  export type PgliteDatabase = {
7
- query<T>(query: string, params?: unknown[]): Promise<{
8
- rows: T[];
9
- affectedRows?: number;
10
- }>;
8
+ query(query: string, params?: unknown[]): Promise<PgResult>;
11
9
  close(): Promise<void>;
12
10
  };
13
11
  /**
@@ -21,9 +19,5 @@ export declare class PgliteQuerier extends AbstractSqlQuerier {
21
19
  constructor(db: PgliteDatabase, dialect: PgliteDialect, extra?: ExtraOptions);
22
20
  /** Every querier of the pool is this one handle's session, so they share its transaction. */
23
21
  protected get connection(): object;
24
- /**
25
- * `affectedRows`, not `rowCount`: PGlite derives the former from the command tag of a write only, where the
26
- * latter also counts a `SELECT`'s rows and is absent altogether from a DDL tag.
27
- */
28
22
  protected execute(sql: string, values?: unknown[]): Promise<SqlExecution>;
29
23
  }
@@ -1,3 +1,4 @@
1
+ import { pgExecution } from '../postgres/pgExecution.js';
1
2
  import { AbstractSqlQuerier } from '../querier/index.js';
2
3
  /**
3
4
  * Querier for PGlite, Postgres compiled to WASM and run in this process.
@@ -15,12 +16,7 @@ export class PgliteQuerier extends AbstractSqlQuerier {
15
16
  get connection() {
16
17
  return this.db;
17
18
  }
18
- /**
19
- * `affectedRows`, not `rowCount`: PGlite derives the former from the command tag of a write only, where the
20
- * latter also counts a `SELECT`'s rows and is absent altogether from a DDL tag.
21
- */
22
19
  async execute(sql, values) {
23
- const { rows, affectedRows } = await this.db.query(sql, values);
24
- return { rows, changes: affectedRows };
20
+ return pgExecution(await this.db.query(sql, values));
25
21
  }
26
22
  }
@@ -1,16 +1,12 @@
1
+ import { Pool, type PoolConfig } from 'pg';
1
2
  import type { AbstractSqlDialect } from '../dialect/index.js';
2
3
  import { AbstractSqlQuerierPool } from '../querier/index.js';
3
4
  import type { ExtraOptions } from '../type/index.js';
4
- import { type PgAnyClient, PgQuerier } from './pgQuerier.js';
5
- export interface PgAnyPool {
6
- connect: () => Promise<PgAnyClient>;
7
- end: () => Promise<void>;
8
- on(event: 'error', listener: (err: Error) => void): unknown;
9
- }
10
- /** A Postgres-wire pool of {@link PgQuerier}s, attaching the error handler that keeps a dropped connection from crashing the process. */
5
+ import { PgQuerier } from './pgQuerier.js';
6
+ /** A `pg` pool of {@link PgQuerier}s, whose error handler keeps a dropped connection from crashing the process. */
11
7
  export declare abstract class AbstractPgQuerierPool<D extends AbstractSqlDialect> extends AbstractSqlQuerierPool<PgQuerier, D> {
12
- readonly pool: PgAnyPool;
13
- constructor(dialect: D, pool: PgAnyPool, extra?: ExtraOptions);
8
+ readonly pool: Pool;
9
+ constructor(dialect: D, opts: PoolConfig, extra?: ExtraOptions);
14
10
  getQuerier(): Promise<PgQuerier>;
15
11
  end(): Promise<void>;
16
12
  }
@@ -1,13 +1,16 @@
1
+ import { Pool, types } from 'pg';
1
2
  import { AbstractSqlQuerierPool } from '../querier/index.js';
2
3
  import { attachPoolErrorHandler } from '../util/index.js';
3
4
  import { PgQuerier } from './pgQuerier.js';
4
- /** A Postgres-wire pool of {@link PgQuerier}s, attaching the error handler that keeps a dropped connection from crashing the process. */
5
+ import { wireTypes } from './pgWireTypes.js';
6
+ /** A `pg` pool of {@link PgQuerier}s, whose error handler keeps a dropped connection from crashing the process. */
5
7
  export class AbstractPgQuerierPool extends AbstractSqlQuerierPool {
6
8
  pool;
7
- constructor(dialect, pool, extra) {
9
+ constructor(dialect, opts, extra) {
8
10
  super(dialect, extra);
9
- this.pool = pool;
10
- attachPoolErrorHandler(pool, 'Idle Postgres pool client encountered an error', extra?.logger);
11
+ // keepAlive cuts down, but cannot stop, a NAT or firewall silently dropping an idle remote connection.
12
+ this.pool = new Pool({ keepAlive: true, types: wireTypes(types), ...opts });
13
+ attachPoolErrorHandler(this.pool, 'Idle Postgres pool client encountered an error', extra?.logger);
11
14
  }
12
15
  async getQuerier() {
13
16
  return new PgQuerier(() => this.pool.connect(), this.dialect, this.extra);
@@ -1,8 +1,8 @@
1
1
  import type { RawRow } from '../type/index.js';
2
2
  import type { SqlExecution } from '../util/sql.util.js';
3
- /** A node-postgres result as the querier reads it: its rows, and the rows it changed. */
3
+ /** A Postgres-wire result as the querier reads it: its rows, and its command tag's count. */
4
4
  export type PgResult = {
5
5
  readonly rows: RawRow[];
6
- readonly rowCount: number | null;
6
+ readonly rowCount?: number | null;
7
7
  };
8
8
  export declare function pgExecution({ rows, rowCount }: PgResult): SqlExecution;
@@ -1,6 +1,6 @@
1
1
  import { AbstractPoolQuerier } from '../querier/abstractPoolQuerier.js';
2
+ import { noop } from '../util/object.util.js';
2
3
  import { pgExecution } from './pgExecution.js';
3
- const ignoreError = () => { };
4
4
  /**
5
5
  * Querier for every client with node-postgres' API: `pg` itself, for Postgres and CockroachDB, and
6
6
  * Neon's serverless driver; the dialect is whichever the pool built.
@@ -11,7 +11,7 @@ export class PgQuerier extends AbstractPoolQuerier {
11
11
  * the process: the querier hears it while it holds the client, and what it hands the client back to after it.
12
12
  */
13
13
  acquired(conn) {
14
- conn.on('error', ignoreError);
14
+ conn.on('error', noop);
15
15
  return conn;
16
16
  }
17
17
  async execute(sql, values) {
@@ -22,7 +22,7 @@ export class PgQuerier extends AbstractPoolQuerier {
22
22
  yield* this.getConn().query(new QueryStream(query, values));
23
23
  }
24
24
  async releaseConn(conn, discard) {
25
- conn.removeListener('error', ignoreError);
25
+ conn.removeListener('error', noop);
26
26
  await conn.release(discard);
27
27
  }
28
28
  }
@@ -1,8 +1,7 @@
1
- import { Pool, type PoolConfig } from 'pg';
1
+ import type { PoolConfig } from 'pg';
2
2
  import type { ExtraOptions } from '../type/index.js';
3
3
  import { AbstractPgQuerierPool } from './abstractPgQuerierPool.js';
4
4
  import { PostgresDialect } from './postgresDialect.js';
5
5
  export declare class PgQuerierPool extends AbstractPgQuerierPool<PostgresDialect> {
6
- readonly pool: Pool;
7
6
  constructor(opts: PoolConfig, extra?: ExtraOptions);
8
7
  }
@@ -1,12 +1,8 @@
1
- import { Pool, types } from 'pg';
2
1
  import { dialectOptionsFrom } from '../dialect/abstractDialect.js';
3
2
  import { AbstractPgQuerierPool } from './abstractPgQuerierPool.js';
4
- import { wireTypes } from './pgWireTypes.js';
5
3
  import { PostgresDialect } from './postgresDialect.js';
6
4
  export class PgQuerierPool extends AbstractPgQuerierPool {
7
5
  constructor(opts, extra) {
8
- // keepAlive reduces (but can't eliminate) idle connections being silently
9
- // dropped by NATs/firewalls on long-lived remote connections.
10
- super(new PostgresDialect(dialectOptionsFrom(extra)), new Pool({ keepAlive: true, types: wireTypes(types), ...opts }), extra);
6
+ super(new PostgresDialect(dialectOptionsFrom(extra)), opts, extra);
11
7
  }
12
8
  }
@@ -2,8 +2,7 @@ import type { CustomTypesConfig } from 'pg';
2
2
  /**
3
3
  * The registry every pg-family driver exposes as `types`: `pg`'s own, and `@neondatabase/serverless`'s
4
4
  * reimplementation of it. Taken as a parameter rather than imported, because `uql-orm/neon` must not
5
- * pull `pg` into an edge bundle that has no such peer installed - the same reason
6
- * `abstractPgQuerierPool.ts` keeps its `pg` imports type-only.
5
+ * pull `pg` into an edge bundle that has no such peer installed.
7
6
  */
8
7
  type PgTypes = {
9
8
  getTypeParser(oid: number, format?: 'text' | 'binary'): Decode;
@@ -2,7 +2,7 @@ import { getMeta, idOf, namesEvery, namesKey, relationOf } from '../entity/index
2
2
  import { SAVEPOINT_PREFIX } from '../dialect/aliases.js';
3
3
  import { namesRows } from '../dialect/operators.js';
4
4
  import { parseQueryLock } from '../type/index.js';
5
- import { childrenExcept, childrenOf, chunk, clone, entityName, fillOnFields, filterFieldKeys, getKeys, deletionOf, hasKeys, getRelationRequestSummary, guardWrite, idOnlyQuery, keyJoins, keySet, isPagedQuery, isScalarId, LoggerWrapper, normalizeScalarFieldSelection, parentJoins, pointAt, queryLoggerFor, parseRelationAtKey, rowKey, runHooks, securityConditions, someKey, targetJoins, foundRowAssigned, whereAnd, whereIds, whereKeysIn, whereWith, withDeleted, cascadingRelations, isClass, defaultReadKeys, holdsForeignKey, } from '../util/index.js';
5
+ import { childrenExcept, childrenOf, chunk, clone, entityName, fillOnFields, filterFieldKeys, getKeys, deletionOf, hasKeys, getRelationRequestSummary, guardWrite, idOnlyQuery, keyJoins, keySet, isPagedQuery, isScalarId, LoggerWrapper, normalizeScalarFieldSelection, parentJoins, pointAt, queryLoggerFor, parseRelationAtKey, rowKey, runHooks, securityConditions, someKey, targetJoins, foundRowAssigned, whereAnd, whereIds, whereKeysIn, whereWith, withDeleted, cascadingRelations, isClass, defaultReadKeys, holdsForeignKey, noop, } from '../util/index.js';
6
6
  import { UqlOptimisticLockError, UqlUsageError } from '../util/uqlError.js';
7
7
  import { keysetRead } from './keyset.js';
8
8
  import { enrichError } from './queryError.js';
@@ -992,7 +992,7 @@ export class AbstractQuerier {
992
992
  nested(parent, callback) {
993
993
  const scope = newScope(this, this.#slot, parent);
994
994
  const run = parent.nested.then(() => inTransaction(scope, () => this.savepointed(scope, parent, callback)));
995
- parent.nested = run.catch(() => undefined);
995
+ parent.nested = run.catch(noop);
996
996
  return run;
997
997
  }
998
998
  /** `callback` between a savepoint and its release, rolled back to it on failure, its `onCommit` callbacks kept only where it succeeds. */
@@ -1199,7 +1199,7 @@ export class AbstractQuerier {
1199
1199
  }
1200
1200
  enqueue(task) {
1201
1201
  const res = this.taskQueue.then(task);
1202
- this.taskQueue = res.catch(() => { });
1202
+ this.taskQueue = res.catch(noop);
1203
1203
  return res;
1204
1204
  }
1205
1205
  /** Runs `task`, logs `query` with its duration, and tags a failure with it: a method, since a decorator would lose the generics. */
@@ -1,3 +1,4 @@
1
+ import { noop } from '../util/object.util.js';
1
2
  import { AbstractSqlQuerierPool } from './abstractSqlQuerierPool.js';
2
3
  /**
3
4
  * A pool over one handle kept for its lifetime: a local SQLite file, the embedded Turso engine, PGlite, or a
@@ -25,7 +26,7 @@ export class AbstractSharedHandleQuerierPool extends AbstractSqlQuerierPool {
25
26
  this.opening = undefined;
26
27
  // An open still in flight is awaited rather than abandoned: closing is what releases its file or port.
27
28
  // One that failed leaves nothing to close, and `getQuerier` already reported it to its own caller.
28
- const db = await opening?.catch(() => undefined);
29
+ const db = await opening?.catch(noop);
29
30
  await db?.close();
30
31
  }
31
32
  }
@@ -1,11 +1,11 @@
1
1
  import { AbstractSqlQuerier, type BoundStatement } from '../querier/index.js';
2
- import type { ExtraOptions, TransactionOptions } from '../type/index.js';
2
+ import type { ExtraOptions, RawRow, TransactionOptions } from '../type/index.js';
3
3
  import type { SqlExecution } from '../util/sql.util.js';
4
4
  import { type SqliteBindValue } from './bindValues.js';
5
5
  import type { SqliteDialect } from './sqliteDialect.js';
6
6
  export type HranaInValue = SqliteBindValue | ArrayBuffer | Date;
7
7
  export type HranaResultSet = {
8
- rows: unknown[];
8
+ rows: RawRow[];
9
9
  rowsAffected: number;
10
10
  };
11
11
  export type HranaStatement = {
@@ -18,7 +18,7 @@ export type LocalSqlitePoolOptions = {
18
18
  export type LocalSqliteDatabase = {
19
19
  prepare(sql: string): SqlitePreparedStatement;
20
20
  loadExtension(path: string): void;
21
- /** Defines a SQL function, which `bun:sqlite` cannot. */
21
+ /** Defines a SQL function, which `bun:sqlite` has only in its newer releases. */
22
22
  function?(name: string, options: {
23
23
  deterministic: boolean;
24
24
  }, fn: (...args: SqlValue[]) => SqlValue): unknown;
@@ -13,8 +13,8 @@ export declare class SqliteQuerierPool extends AbstractLocalSqliteQuerierPool<Lo
13
13
  readonly opts?: SqlitePoolOptions | undefined;
14
14
  constructor(filename?: string | Buffer, opts?: SqlitePoolOptions | undefined, extra?: ExtraOptions);
15
15
  /**
16
- * `bun:sqlite` rejects option keys it does not know, so `extensions` is stripped out, and opens only a
17
- * path, so a serialized database - which better-sqlite3 takes as its filename - is deserialized there instead.
16
+ * `extensions` is uql's, so it never reaches the driver. `bun:sqlite` opens only a path, so a serialized
17
+ * database, which better-sqlite3 takes as its filename, is deserialized there instead.
18
18
  */
19
19
  protected createDb(): Promise<LocalSqliteDatabase>;
20
20
  }
@@ -14,8 +14,8 @@ export class SqliteQuerierPool extends AbstractLocalSqliteQuerierPool {
14
14
  this.opts = opts;
15
15
  }
16
16
  /**
17
- * `bun:sqlite` rejects option keys it does not know, so `extensions` is stripped out, and opens only a
18
- * path, so a serialized database - which better-sqlite3 takes as its filename - is deserialized there instead.
17
+ * `extensions` is uql's, so it never reaches the driver. `bun:sqlite` opens only a path, so a serialized
18
+ * database, which better-sqlite3 takes as its filename, is deserialized there instead.
19
19
  */
20
20
  async createDb() {
21
21
  const { extensions, ...driverOpts } = this.opts ?? {};
@@ -76,6 +76,13 @@ export type AggregateFields = {
76
76
  readonly computed: QuerySql;
77
77
  }>;
78
78
  };
79
+ /**
80
+ * What `relations` constrains its aggregates to: a thunk returning `void`, which TypeScript checks without reading what it
81
+ * returns. Reading it would read a tree's own to-many while its type is inferred (TS7022); first read refuses a wrong value.
82
+ */
83
+ type AggregateThunks = {
84
+ readonly [key: string]: () => void;
85
+ };
79
86
  /** The aggregate fields a `relations` callback declares, as a row reads them, never written. */
80
87
  export type AggregateRow<A> = {
81
88
  readonly [K in keyof A]-?: A[K] extends () => infer F ? FieldValue<F> : never;
@@ -160,7 +167,7 @@ type DefinedSections<Row, Key, Columns, B, Abstract> = {
160
167
  * The relations, each read lazily so entities pointing at each other declare in either order, and the values
161
168
  * read over the to-many ones, its base's too: `(author) => ({ postCount: () => author.posts.count() })`.
162
169
  */
163
- relations<const R, const A extends AggregateFields = {}>(relations: (rel: RelationBuilder<Columns>) => R, aggregates?: (refs: RefMap<Columns> & AggregateRefs<R> & ToManyRefs<B, Exclude<ToManyRelationKey<B>, keyof R>>) => A): RelatedEntity<Row & RelationRow<R> & AggregateRow<A>, Key, Columns, Abstract>;
170
+ relations<const R, const A extends AggregateThunks = {}>(relations: (rel: RelationBuilder<Columns>) => R, aggregates?: (refs: RefMap<Columns> & AggregateRefs<R> & ToManyRefs<B, Exclude<ToManyRelationKey<B>, keyof R>>) => A): RelatedEntity<Row & RelationRow<R> & AggregateRow<A>, Key, Columns, Abstract>;
164
171
  };
165
172
  /** A defined entity's class once its relations are in: its filters may follow, and read through them. */
166
173
  export type RelatedEntity<Row, Key, Columns, Abstract = false> = DefinedClass<Row, Key, Columns, Abstract> & {
@@ -1,4 +1,6 @@
1
1
  import type { EntityMeta, JsonScalar } from '../type/index.js';
2
+ /** Does nothing: a listener or `catch` that only has to be there. `undefined` rather than `void`, so `.catch(noop)` keeps `T | undefined`. */
3
+ export declare const noop: () => undefined;
2
4
  /** Whether `value` is a {@link JsonScalar}, which `$addToSet` and an `=` on a JSON path compare by equality. */
3
5
  export declare function isJsonScalar(value: unknown): value is JsonScalar;
4
6
  /** Orders two strings by code unit, or two numbers by value, the order every engine sorts text by, so names and JSON keys agree across them. */
@@ -1,3 +1,5 @@
1
+ /** Does nothing: a listener or `catch` that only has to be there. `undefined` rather than `void`, so `.catch(noop)` keeps `T | undefined`. */
2
+ export const noop = () => undefined;
1
3
  /** Whether `value` is a {@link JsonScalar}, which `$addToSet` and an `=` on a JSON path compare by equality. */
2
4
  export function isJsonScalar(value) {
3
5
  return typeof value === 'string' || typeof value === 'boolean' || Number.isFinite(value);