@stacksjs/database 0.72.23 → 0.72.24
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/dist/framework-schema.d.ts +2032 -0
- package/dist/framework-schema.js +0 -0
- package/dist/index.d.ts +2 -1
- package/dist/utils.d.ts +46 -10
- package/package.json +10 -10
|
File without changes
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export type {
|
|
|
10
10
|
PostgresConfig,
|
|
11
11
|
SqliteConfig,
|
|
12
12
|
} from './driver-config';
|
|
13
|
+
// Core database utilities and default instance
|
|
14
|
+
export type { FrameworkSchema } from './framework-schema';
|
|
13
15
|
export type { SchemaDriftColumn, SchemaDriftReport } from './schema-drift';
|
|
14
16
|
export type { DeclaredFK, FkAuditResult, FkOrphan, FkOrphanReport, LiveFK } from './fk-audit';
|
|
15
17
|
export type { DeclaredUnique, LiveUniqueIndex, UniqueAuditResult } from './unique-audit';
|
|
@@ -74,7 +76,6 @@ export {
|
|
|
74
76
|
mergeWithDefaults,
|
|
75
77
|
validateDriverConfig,
|
|
76
78
|
} from './driver-config';
|
|
77
|
-
// Core database utilities and default instance
|
|
78
79
|
export * from './utils';
|
|
79
80
|
// Types (compatibility layer for Kysely types)
|
|
80
81
|
export * from './types';
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createQueryBuilder, setConfig } from '@stacksjs/query-builder';
|
|
2
|
+
import type { FrameworkSchema } from './framework-schema';
|
|
2
3
|
import type { QueryHooks } from '@stacksjs/query-builder';
|
|
3
4
|
export declare function acquireDbConfigLock(): Promise<() => void>;
|
|
4
5
|
// Function to initialize the config when it's available
|
|
@@ -105,6 +106,25 @@ export declare interface DatabaseQueryLogEvent {
|
|
|
105
106
|
queryDurationMillis: number
|
|
106
107
|
error?: unknown
|
|
107
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* What an insert reports when it was not asked to return rows.
|
|
111
|
+
*
|
|
112
|
+
* Every field optional and every one differently named, because drivers
|
|
113
|
+
* disagree: Postgres answers a count, SQLite a `changes`, MySQL an `insertId`.
|
|
114
|
+
* Typing this as the row - which is what the query builder's own declarations
|
|
115
|
+
* do - is how framework code came to read `insertId` off a value that is not a
|
|
116
|
+
* row and cannot have one.
|
|
117
|
+
*
|
|
118
|
+
* `returning(...)` is the way to get rows out of an insert, and it changes the
|
|
119
|
+
* chain's kind so the types follow.
|
|
120
|
+
*/
|
|
121
|
+
export declare interface InsertReceipt {
|
|
122
|
+
insertId?: number | bigint
|
|
123
|
+
numInsertedOrUpdatedRows?: number | bigint
|
|
124
|
+
numAffectedRows?: number | bigint
|
|
125
|
+
affectedRows?: number
|
|
126
|
+
changes?: number
|
|
127
|
+
}
|
|
108
128
|
export declare interface BaseFluentChain<TRow = Record<string, unknown>, TKind extends ChainKind = 'select'> {
|
|
109
129
|
where(callback: (eb: import('./types').StacksExpressionBuilder) => unknown): FluentChain<TRow, TKind>
|
|
110
130
|
where(...args: unknown[]): FluentChain<TRow, TKind>
|
|
@@ -237,12 +257,20 @@ export type ChainKind = 'select' | 'insert' | 'update' | 'delete' | 'returning';
|
|
|
237
257
|
export type ResultOf<TRow, TKind extends ChainKind> = TKind extends 'select' | 'returning'
|
|
238
258
|
? TRow[]
|
|
239
259
|
: number;
|
|
240
|
-
/**
|
|
241
|
-
|
|
260
|
+
/**
|
|
261
|
+
* What `executeTakeFirst()` resolves to for each verb.
|
|
262
|
+
*
|
|
263
|
+
* The counts are *required*, because the runtime always sets them: an update
|
|
264
|
+
* that changed nothing answers `{ numUpdatedRows: 0 }`. Declaring them optional
|
|
265
|
+
* would make every caller write `?? 0` for a case that cannot happen.
|
|
266
|
+
*/
|
|
267
|
+
export type FirstOf<TRow, TKind extends ChainKind> = TKind extends 'select' | 'returning'
|
|
242
268
|
? TRow | undefined
|
|
243
|
-
: TKind extends '
|
|
244
|
-
?
|
|
245
|
-
:
|
|
269
|
+
: TKind extends 'insert'
|
|
270
|
+
? InsertReceipt | undefined
|
|
271
|
+
: TKind extends 'update'
|
|
272
|
+
? { numUpdatedRows: number }
|
|
273
|
+
: { numDeletedRows: number }
|
|
246
274
|
/** `created_at` -> `CreatedAt`, for the dynamic helper names below. */
|
|
247
275
|
declare type SnakeToPascal<S extends string> = S extends `${infer Head}_${infer Tail}`
|
|
248
276
|
? `${Capitalize<Head>}${SnakeToPascal<Tail>}`
|
|
@@ -320,7 +348,7 @@ declare type GenericPassthroughKeys = | 'transaction'
|
|
|
320
348
|
* well-documented LiteralUnion trick.
|
|
321
349
|
*/
|
|
322
350
|
// eslint-disable-next-line ts/no-empty-object-type
|
|
323
|
-
export type TableName = (keyof DatabaseSchema & string) | (string & {});
|
|
351
|
+
export type TableName = (keyof DatabaseSchema & string) | (keyof FrameworkSchema & string) | (string & {});
|
|
324
352
|
/**
|
|
325
353
|
* The row type of a registered table, or an unknown-valued record.
|
|
326
354
|
*
|
|
@@ -330,10 +358,18 @@ export type TableName = (keyof DatabaseSchema & string) | (string & {});
|
|
|
330
358
|
* the caller narrows, but narrowing it is checked rather than waved through.
|
|
331
359
|
*/
|
|
332
360
|
export type RowOf<T extends TableName> = T extends keyof DatabaseSchema
|
|
333
|
-
? DatabaseSchema[T]
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
361
|
+
? Shape<DatabaseSchema[T]>
|
|
362
|
+
: T extends keyof FrameworkSchema
|
|
363
|
+
? Shape<FrameworkSchema[T]>
|
|
364
|
+
: Record<string, unknown>;
|
|
365
|
+
/**
|
|
366
|
+
* A generated entry, whichever of the two shapes it was written in.
|
|
367
|
+
*
|
|
368
|
+
* The app generator has emitted a flat column record for a while; the
|
|
369
|
+
* `{ columns }` form is what the query builder's own schema type uses. Both are
|
|
370
|
+
* accepted so an app does not have to regenerate to keep compiling.
|
|
371
|
+
*/
|
|
372
|
+
declare type Shape<T> = T extends { columns: infer C } ? C : T;
|
|
337
373
|
// SQLite bootstrap pragmas (stacksjs/stacks#1951) now live in
|
|
338
374
|
// @stacksjs/query-builder — the one chokepoint every framework
|
|
339
375
|
// query-builder instance is created through — so EVERY fresh sqlite
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/database",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.72.
|
|
5
|
+
"version": "0.72.24",
|
|
6
6
|
"description": "The Stacks database integration.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -65,15 +65,15 @@
|
|
|
65
65
|
"dynamodb-tooling": "^0.3.2"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@stacksjs/cli": "0.72.
|
|
69
|
-
"@stacksjs/config": "0.72.
|
|
70
|
-
"@stacksjs/logging": "0.72.
|
|
71
|
-
"@stacksjs/router": "0.72.
|
|
68
|
+
"@stacksjs/cli": "0.72.24",
|
|
69
|
+
"@stacksjs/config": "0.72.24",
|
|
70
|
+
"@stacksjs/logging": "0.72.24",
|
|
71
|
+
"@stacksjs/router": "0.72.24",
|
|
72
72
|
"better-dx": "^0.2.23",
|
|
73
|
-
"@stacksjs/path": "0.72.
|
|
74
|
-
"@stacksjs/query-builder": "0.72.
|
|
75
|
-
"@stacksjs/storage": "0.72.
|
|
76
|
-
"@stacksjs/strings": "0.72.
|
|
77
|
-
"@stacksjs/utils": "0.72.
|
|
73
|
+
"@stacksjs/path": "0.72.24",
|
|
74
|
+
"@stacksjs/query-builder": "0.72.24",
|
|
75
|
+
"@stacksjs/storage": "0.72.24",
|
|
76
|
+
"@stacksjs/strings": "0.72.24",
|
|
77
|
+
"@stacksjs/utils": "0.72.24"
|
|
78
78
|
}
|
|
79
79
|
}
|