pipework 0.281.0 → 0.283.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 (59) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/REFERENCE.md +13 -0
  3. package/dist/core/config/load.d.ts +3 -1
  4. package/dist/core/config/load.d.ts.map +1 -1
  5. package/dist/core/config/load.js +1 -0
  6. package/dist/core/config/load.js.map +1 -1
  7. package/dist/core/config/namespace.d.ts +1 -0
  8. package/dist/core/config/namespace.d.ts.map +1 -1
  9. package/dist/core/config/schema.d.ts +3 -1
  10. package/dist/core/config/schema.d.ts.map +1 -1
  11. package/dist/core/config/schema.js +3 -0
  12. package/dist/core/config/schema.js.map +1 -1
  13. package/dist/core/config/statement-observer.d.ts +58 -0
  14. package/dist/core/config/statement-observer.d.ts.map +1 -1
  15. package/dist/core/surface/types.d.ts +1 -0
  16. package/dist/core/surface/types.d.ts.map +1 -1
  17. package/dist/data/db/instrumentation.d.ts +6 -4
  18. package/dist/data/db/instrumentation.d.ts.map +1 -1
  19. package/dist/data/db/instrumentation.js +12 -14
  20. package/dist/data/db/instrumentation.js.map +1 -1
  21. package/dist/data/db/namespace.d.ts +3 -0
  22. package/dist/data/db/namespace.d.ts.map +1 -1
  23. package/dist/data/db/namespace.js +3 -0
  24. package/dist/data/db/namespace.js.map +1 -1
  25. package/dist/data/db/pool.js +4 -4
  26. package/dist/data/db/pool.js.map +1 -1
  27. package/dist/data/db/query-watch.d.ts +8 -0
  28. package/dist/data/db/query-watch.d.ts.map +1 -1
  29. package/dist/data/db/query-watch.js +70 -2
  30. package/dist/data/db/query-watch.js.map +1 -1
  31. package/dist/data/db/raw-client-warning.js +1 -1
  32. package/dist/data/db/raw-client-warning.js.map +1 -1
  33. package/dist/data/db/rows.d.ts +35 -0
  34. package/dist/data/db/rows.d.ts.map +1 -0
  35. package/dist/data/db/rows.js +91 -0
  36. package/dist/data/db/rows.js.map +1 -0
  37. package/dist/data/query/postgres-js/session.d.ts +1 -1
  38. package/dist/data/query/postgres-js/session.d.ts.map +1 -1
  39. package/dist/data/query/postgres-js/session.js +16 -9
  40. package/dist/data/query/postgres-js/session.js.map +1 -1
  41. package/dist/index.d.ts +2 -1
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js.map +1 -1
  44. package/dist/test/plugin.js +6 -6
  45. package/dist/test/plugin.js.map +1 -1
  46. package/package.json +1 -1
  47. package/src/core/config/load.ts +4 -1
  48. package/src/core/config/schema.ts +4 -1
  49. package/src/core/config/statement-observer.ts +61 -0
  50. package/src/core/surface/types.ts +1 -0
  51. package/src/data/db/instrumentation.ts +15 -14
  52. package/src/data/db/namespace.ts +4 -0
  53. package/src/data/db/pool.ts +4 -4
  54. package/src/data/db/query-watch.ts +72 -3
  55. package/src/data/db/raw-client-warning.ts +1 -1
  56. package/src/data/db/rows.ts +120 -0
  57. package/src/data/query/postgres-js/session.ts +20 -11
  58. package/src/index.ts +2 -1
  59. package/src/test/plugin.ts +6 -6
@@ -16,10 +16,19 @@ import { type Assume, mapResultRow } from '../utils.js';
16
16
  import { propagateObserved, throughErrorBoundary } from './driver-error-boundary.js';
17
17
 
18
18
  /** Wraps one statement's execution; installed by the pool to time it and report it while it runs. */
19
- export type StatementWatch = <T>(query: string, run: () => Promise<T>) => Promise<T>;
19
+ export type StatementWatch = <T>(query: string, run: (seen: (pending: object) => void) => Promise<T>) => Promise<T>;
20
20
 
21
- function watched<T>(watch: StatementWatch | undefined, query: string, run: () => Promise<T>): Promise<T> {
22
- return watch === undefined ? run() : watch(query, run);
21
+ function watched<T>(watch: StatementWatch | undefined, query: string, run: (seen: (pending: object) => void) => Promise<T>): Promise<T> {
22
+ return watch === undefined ? run(noteSeen) : watch(query, run);
23
+ }
24
+
25
+ function noteSeen(): void {}
26
+
27
+ /** Starts the statement and tells the watch which pending query it is, so it can learn the connection it runs on. */
28
+ function startUnsafe(client: Sql, query: string, params: unknown[], seen: (pending: object) => void) {
29
+ const pending = client.unsafe(query, params as any[]);
30
+ seen(pending);
31
+ return pending;
23
32
  }
24
33
 
25
34
  export class PostgresJsPreparedQuery<T extends PreparedQueryConfig> extends PgPreparedQuery<T> {
@@ -58,8 +67,8 @@ export class PostgresJsPreparedQuery<T extends PreparedQueryConfig> extends PgPr
58
67
  const { fields, queryString: query, client, joinsNotNullableMap, customResultMapper, watch } = this;
59
68
  if (!fields && !customResultMapper) {
60
69
  return tracer.startActiveSpan('drizzle.driver.execute', () => {
61
- return throughErrorBoundary(client, () => watched(watch, query, () => this.queryWithCache(query, params, async () => {
62
- return await client.unsafe(query, params as any[]);
70
+ return throughErrorBoundary(client, () => watched(watch, query, (seen) => this.queryWithCache(query, params, async () => {
71
+ return await startUnsafe(client, query, params, seen);
63
72
  })));
64
73
  });
65
74
  }
@@ -69,8 +78,8 @@ export class PostgresJsPreparedQuery<T extends PreparedQueryConfig> extends PgPr
69
78
  'drizzle.query.text': query,
70
79
  'drizzle.query.params': JSON.stringify(params),
71
80
  });
72
- return throughErrorBoundary(client, () => watched(watch, query, () => this.queryWithCache(query, params, async () => {
73
- return await client.unsafe(query, params as any[]).values();
81
+ return throughErrorBoundary(client, () => watched(watch, query, (seen) => this.queryWithCache(query, params, async () => {
82
+ return await startUnsafe(client, query, params, seen).values();
74
83
  })));
75
84
  });
76
85
 
@@ -95,8 +104,8 @@ export class PostgresJsPreparedQuery<T extends PreparedQueryConfig> extends PgPr
95
104
  'drizzle.query.text': this.queryString,
96
105
  'drizzle.query.params': JSON.stringify(params),
97
106
  });
98
- return throughErrorBoundary(this.client, () => watched(this.watch, this.queryString, () => this.queryWithCache(this.queryString, params, async () => {
99
- return this.client.unsafe(this.queryString, params as any[]);
107
+ return throughErrorBoundary(this.client, () => watched(this.watch, this.queryString, (seen) => this.queryWithCache(this.queryString, params, async () => {
108
+ return startUnsafe(this.client, this.queryString, params, seen);
100
109
  })));
101
110
  });
102
111
  });
@@ -165,14 +174,14 @@ export class PostgresJsSession<
165
174
 
166
175
  query(query: string, params: unknown[]): Promise<RowList<Row[]>> {
167
176
  this.logger.logQuery(query, params);
168
- return throughErrorBoundary(this.client, () => watched(this.options.watch, query, () => this.client.unsafe(query, params as any[]).values()));
177
+ return throughErrorBoundary(this.client, () => watched(this.options.watch, query, (seen) => startUnsafe(this.client, query, params, seen).values()));
169
178
  }
170
179
 
171
180
  queryObjects<T extends Row>(
172
181
  query: string,
173
182
  params: unknown[],
174
183
  ): Promise<RowList<T[]>> {
175
- return throughErrorBoundary(this.client, () => watched(this.options.watch, query, () => this.client.unsafe(query, params as any[])));
184
+ return throughErrorBoundary(this.client, () => watched(this.options.watch, query, (seen) => startUnsafe(this.client, query, params, seen) as unknown as Promise<RowList<T[]>>));
176
185
  }
177
186
 
178
187
  override transaction<T>(
package/src/index.ts CHANGED
@@ -9,6 +9,7 @@ export type { DB, SQL, Table, Column, TransactionConfig } from './data/db/namesp
9
9
  export type { WindowSpec, WindowFrame, FrameBound } from './data/db/expressions.js'
10
10
  export type { Aggregate, EmptyableAggregate, AggregateOptions, JsonOf } from './data/db/aggregates.js'
11
11
  export type { ValueColumnDef } from './data/db/values.js'
12
+ export type { RowsColumns, RowsData, RowsSource, RowsColumnValue } from './data/db/rows.js'
12
13
  export type { ArraySource, ElementOf, JsonbElements } from './data/db/array-elements.js'
13
14
  export type { FunctionSpec, FunctionSource, FunctionSourceFields } from './data/db/function-source.js'
14
15
  export type { SerializableOptions } from './data/db/serializable.js'
@@ -20,7 +21,7 @@ export type { TimeoutOptions } from './data/db/timeouts.js'
20
21
  // sanctioned door to a raw connection; keeps the WRAPPED_PACKAGES postgres ban airtight.
21
22
  export { tap } from './data/db/pool.js'
22
23
  export type { ManagedConnection, ConnectOptions } from './data/db/pool.js'
23
- export type { StatementObserver, StatementEvent } from './core/config/statement-observer.js'
24
+ export type { StatementObserver, StatementEvent, StatementSettledObserver, StatementSettledEvent, StatementSettledError } from './core/config/statement-observer.js'
24
25
 
25
26
  export type { DefinedTable, ExternalTable, DomainDefinition, DefinitionMethods, FieldDescriptor, FieldModifiers, FieldMeta, DefineOptions,
26
27
  FactoryBuilder, FactoryOptions, TraitDefinition, FieldColumn, ProjectedColumns,
@@ -127,10 +127,10 @@ async function createIsolatedConnection(
127
127
  observability: ResolvedObservability,
128
128
  withSystem: boolean,
129
129
  ): Promise<PostgresJsDatabase> {
130
- const debug = createDebugFn(observability)
130
+ const watch = createStatementWatch({ database: name, url: testDb.url, slowQueryMs: observability.slowQueryMs, inFlightQueryMs: observability.inFlightQueryMs, onSettled: observability.onStatementSettled })
131
+ const debug = createDebugFn(observability, watch.noteConnection)
131
132
  const client = postgres(testDb.url, { max: 1, onnotice: () => {}, ...(debug ? { debug } : {}) })
132
133
  if (isObserverOnly(observability)) markObservedConnection(client)
133
- const watch = createStatementWatch({ database: name, url: testDb.url, slowQueryMs: observability.slowQueryMs, inFlightQueryMs: observability.inFlightQueryMs })
134
134
  const db = drizzle(client, { statementWatch: watch.watch })
135
135
 
136
136
  await db.execute(sql.raw('BEGIN'))
@@ -177,12 +177,12 @@ export function createSetupConnection(
177
177
  testDb: TestDatabase,
178
178
  observability?: ResolvedObservability,
179
179
  ): { drizzle: PostgresJsDatabase; close: () => Promise<void> } {
180
- const debug = observability ? createDebugFn(observability) : undefined
181
- const client = postgres(testDb.url, { max: 1, onnotice: () => {}, ...(debug ? { debug } : {}) })
182
- if (observability && isObserverOnly(observability)) markObservedConnection(client)
183
180
  const watch = observability
184
- ? createStatementWatch({ database: 'setup', url: testDb.url, slowQueryMs: observability.slowQueryMs, inFlightQueryMs: observability.inFlightQueryMs })
181
+ ? createStatementWatch({ database: 'setup', url: testDb.url, slowQueryMs: observability.slowQueryMs, inFlightQueryMs: observability.inFlightQueryMs, onSettled: observability.onStatementSettled })
185
182
  : undefined
183
+ const debug = observability ? createDebugFn(observability, watch?.noteConnection) : undefined
184
+ const client = postgres(testDb.url, { max: 1, onnotice: () => {}, ...(debug ? { debug } : {}) })
185
+ if (observability && isObserverOnly(observability)) markObservedConnection(client)
186
186
  const db = splitLargeInserts(drizzle(client, watch ? { statementWatch: watch.watch } : {}))
187
187
  return { drizzle: db, close: async () => { await watch?.close(); await client.end() } }
188
188
  }