pipework 0.282.0 → 0.284.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/CHANGELOG.md +8 -0
- package/dist/core/config/load.d.ts +11 -1
- package/dist/core/config/load.d.ts.map +1 -1
- package/dist/core/config/load.js +5 -0
- package/dist/core/config/load.js.map +1 -1
- package/dist/core/config/namespace.d.ts +5 -0
- package/dist/core/config/namespace.d.ts.map +1 -1
- package/dist/core/config/schema.d.ts +11 -1
- package/dist/core/config/schema.d.ts.map +1 -1
- package/dist/core/config/schema.js +7 -0
- package/dist/core/config/schema.js.map +1 -1
- package/dist/core/config/statement-observer.d.ts +58 -0
- package/dist/core/config/statement-observer.d.ts.map +1 -1
- package/dist/core/surface/types.d.ts +5 -0
- package/dist/core/surface/types.d.ts.map +1 -1
- package/dist/data/db/instrumentation.d.ts +6 -4
- package/dist/data/db/instrumentation.d.ts.map +1 -1
- package/dist/data/db/instrumentation.js +12 -14
- package/dist/data/db/instrumentation.js.map +1 -1
- package/dist/data/db/namespace.d.ts +1 -1
- package/dist/data/db/namespace.d.ts.map +1 -1
- package/dist/data/db/namespace.js +1 -1
- package/dist/data/db/namespace.js.map +1 -1
- package/dist/data/db/pool.js +5 -5
- package/dist/data/db/pool.js.map +1 -1
- package/dist/data/db/query-size.d.ts +18 -0
- package/dist/data/db/query-size.d.ts.map +1 -0
- package/dist/data/db/query-size.js +68 -0
- package/dist/data/db/query-size.js.map +1 -0
- package/dist/data/db/query-watch.d.ts +24 -0
- package/dist/data/db/query-watch.d.ts.map +1 -1
- package/dist/data/db/query-watch.js +101 -2
- package/dist/data/db/query-watch.js.map +1 -1
- package/dist/data/db/raw-client-warning.js +1 -1
- package/dist/data/db/raw-client-warning.js.map +1 -1
- package/dist/data/query/postgres-js/session.d.ts +1 -1
- package/dist/data/query/postgres-js/session.d.ts.map +1 -1
- package/dist/data/query/postgres-js/session.js +16 -9
- package/dist/data/query/postgres-js/session.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/test/plugin.js +7 -7
- package/dist/test/plugin.js.map +1 -1
- package/package.json +6 -2
- package/src/core/config/load.ts +16 -1
- package/src/core/config/schema.ts +8 -1
- package/src/core/config/statement-observer.ts +61 -0
- package/src/core/surface/types.ts +5 -0
- package/src/data/db/instrumentation.ts +15 -14
- package/src/data/db/namespace.ts +1 -1
- package/src/data/db/pool.ts +5 -5
- package/src/data/db/query-size.ts +63 -0
- package/src/data/db/query-watch.ts +115 -3
- package/src/data/db/raw-client-warning.ts +1 -1
- package/src/data/query/postgres-js/session.ts +20 -11
- package/src/index.ts +1 -1
- package/src/test/plugin.ts +7 -7
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
@@ -21,7 +21,7 @@ export type { TimeoutOptions } from './data/db/timeouts.js'
|
|
|
21
21
|
// sanctioned door to a raw connection; keeps the WRAPPED_PACKAGES postgres ban airtight.
|
|
22
22
|
export { tap } from './data/db/pool.js'
|
|
23
23
|
export type { ManagedConnection, ConnectOptions } from './data/db/pool.js'
|
|
24
|
-
export type { StatementObserver, StatementEvent } from './core/config/statement-observer.js'
|
|
24
|
+
export type { StatementObserver, StatementEvent, StatementSettledObserver, StatementSettledEvent, StatementSettledError } from './core/config/statement-observer.js'
|
|
25
25
|
|
|
26
26
|
export type { DefinedTable, ExternalTable, DomainDefinition, DefinitionMethods, FieldDescriptor, FieldModifiers, FieldMeta, DefineOptions,
|
|
27
27
|
FactoryBuilder, FactoryOptions, TraitDefinition, FieldColumn, ProjectedColumns,
|
package/src/test/plugin.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { runInContext } from '../request/context/store.js'
|
|
|
8
8
|
import type { Flow } from '../request/context/types.js'
|
|
9
9
|
import { randomUUID } from 'node:crypto'
|
|
10
10
|
import { createDebugFn, isObserverOnly } from '../data/db/instrumentation.js'
|
|
11
|
-
import { createStatementWatch } from '../data/db/query-watch.js'
|
|
11
|
+
import { createStatementWatch, largeQueryBudgets } from '../data/db/query-watch.js'
|
|
12
12
|
import { markObservedConnection } from '../data/query/postgres-js/driver-error-boundary.js'
|
|
13
13
|
import type { ResolvedObservability } from '../core/config/load.js'
|
|
14
14
|
import { collapseTransactionsToSavepoints } from './savepoints.js'
|
|
@@ -127,10 +127,10 @@ async function createIsolatedConnection(
|
|
|
127
127
|
observability: ResolvedObservability,
|
|
128
128
|
withSystem: boolean,
|
|
129
129
|
): Promise<PostgresJsDatabase> {
|
|
130
|
-
const
|
|
130
|
+
const watch = createStatementWatch({ database: name, url: testDb.url, slowQueryMs: observability.slowQueryMs, inFlightQueryMs: observability.inFlightQueryMs, onSettled: observability.onStatementSettled, budgets: largeQueryBudgets(observability) })
|
|
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, budgets: largeQueryBudgets(observability) })
|
|
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
|
}
|