@stacksjs/database 0.70.86 → 0.70.88
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 +10 -10
- package/dist/auth-tables.d.ts +0 -60
- package/dist/class-seeder.d.ts +0 -65
- package/dist/custom/audits.d.ts +0 -16
- package/dist/custom/errors.d.ts +0 -1
- package/dist/custom/index.d.ts +0 -3
- package/dist/custom/jobs.d.ts +0 -3
- package/dist/database.d.ts +0 -89
- package/dist/defaults.d.ts +0 -48
- package/dist/driver-config.d.ts +0 -149
- package/dist/drivers/defaults/index.d.ts +0 -2
- package/dist/drivers/defaults/passwords.d.ts +0 -4
- package/dist/drivers/defaults/traits.d.ts +0 -33
- package/dist/drivers/dynamodb.d.ts +0 -200
- package/dist/drivers/helpers.d.ts +0 -35
- package/dist/drivers/index.d.ts +0 -16
- package/dist/drivers/mysql.d.ts +0 -7
- package/dist/drivers/postgres.d.ts +0 -7
- package/dist/drivers/sqlite.d.ts +0 -20
- package/dist/factory.d.ts +0 -41
- package/dist/fk-audit.d.ts +0 -101
- package/dist/index.d.ts +0 -149
- package/dist/index.js +0 -1263
- package/dist/migration-lock.d.ts +0 -23
- package/dist/migrations.d.ts +0 -76
- package/dist/notification-tables.d.ts +0 -20
- package/dist/query-logger.d.ts +0 -26
- package/dist/query-parser.d.ts +0 -4
- package/dist/rbac-tables.d.ts +0 -17
- package/dist/safe-migrations.d.ts +0 -72
- package/dist/seed-scaffold.d.ts +0 -34
- package/dist/seeder.d.ts +0 -116
- package/dist/sql-helpers.d.ts +0 -33
- package/dist/transaction-context.d.ts +0 -52
- package/dist/types.d.ts +0 -151
- package/dist/unique-audit.d.ts +0 -60
- package/dist/utils.d.ts +0 -189
- package/dist/uuid-columns.d.ts +0 -22
- package/dist/validators.d.ts +0 -26
package/dist/unique-audit.d.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Walk every model file (user + framework defaults) and return the
|
|
3
|
-
* full list of declared unique constraints — both single-column
|
|
4
|
-
* `unique: true` attributes and `unique: true` composite indexes.
|
|
5
|
-
*/
|
|
6
|
-
export declare function getDeclaredUniques(): Promise<DeclaredUnique[]>;
|
|
7
|
-
/**
|
|
8
|
-
* Query the live database for every UNIQUE index, returning a
|
|
9
|
-
* normalised `{ table, name, columns }` shape. Dialect-aware: PRAGMA
|
|
10
|
-
* on SQLite, information_schema / pg_index on MySQL / PostgreSQL.
|
|
11
|
-
*
|
|
12
|
-
* The optional `dialect` parameter is the test seam — production code
|
|
13
|
-
* leaves it undefined so it's derived from `DB_CONNECTION`.
|
|
14
|
-
*/
|
|
15
|
-
export declare function getLiveUniqueIndexes(dialect?: Dialect): Promise<LiveUniqueIndex[]>;
|
|
16
|
-
/**
|
|
17
|
-
* Diff declared unique constraints against live UNIQUE indexes. A
|
|
18
|
-
* declared entry is satisfied iff some live unique index on the same
|
|
19
|
-
* table has an equal column SET (sorted, case-insensitive). Declared
|
|
20
|
-
* entries whose table is absent from the live DB go to `skippedTables`
|
|
21
|
-
* (feature-gated commerce/CMS models legitimately have no table yet)
|
|
22
|
-
* rather than `missing`.
|
|
23
|
-
*/
|
|
24
|
-
export declare function auditUniqueIndexes(dialect?: Dialect): Promise<UniqueAuditResult>;
|
|
25
|
-
// stacksjs/stacks#1952 — Unique-index drift audit. Compares each
|
|
26
|
-
// model's declared uniqueness (`unique: true` attributes and
|
|
27
|
-
// `unique: true` composite indexes) against the UNIQUE indexes that
|
|
28
|
-
// actually exist in the live database.
|
|
29
|
-
//
|
|
30
|
-
// This is the `buddy doctor` companion to the migrate-side self-heal
|
|
31
|
-
// (#1952): `buddy migrate` already re-queues missing unique-index
|
|
32
|
-
// migrations, but that only fires when you run migrate, doesn't help
|
|
33
|
-
// apps scaffolded during the stub era (whose own repos carry
|
|
34
|
-
// `SELECT 1;` stub migrations), and hard-fails mid-migrate on
|
|
35
|
-
// pre-existing duplicate rows instead of reporting first. This audit
|
|
36
|
-
// surfaces the drift read-only, before you migrate.
|
|
37
|
-
//
|
|
38
|
-
// Matching is by COLUMN SET, never by index name — the generator
|
|
39
|
-
// emits names like `users_users_email_unique` while migration
|
|
40
|
-
// filenames say `users_email_unique`, so names are not stable.
|
|
41
|
-
export declare interface DeclaredUnique {
|
|
42
|
-
table: string
|
|
43
|
-
columns: string[]
|
|
44
|
-
model: string
|
|
45
|
-
source: 'attribute' | 'index'
|
|
46
|
-
indexName?: string
|
|
47
|
-
}
|
|
48
|
-
export declare interface LiveUniqueIndex {
|
|
49
|
-
table: string
|
|
50
|
-
name: string
|
|
51
|
-
columns: string[]
|
|
52
|
-
}
|
|
53
|
-
export declare interface UniqueAuditResult {
|
|
54
|
-
supported: boolean
|
|
55
|
-
declared: DeclaredUnique[]
|
|
56
|
-
live: LiveUniqueIndex[]
|
|
57
|
-
missing: DeclaredUnique[]
|
|
58
|
-
skippedTables: string[]
|
|
59
|
-
}
|
|
60
|
-
declare type Dialect = 'sqlite' | 'mysql' | 'postgres' | 'other';
|
package/dist/utils.d.ts
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { createQueryBuilder, setConfig } from '@stacksjs/query-builder';
|
|
2
|
-
export declare function acquireDbConfigLock(): Promise<() => void>;
|
|
3
|
-
// Function to initialize the config when it's available
|
|
4
|
-
export declare function initializeDbConfig(config: any): void;
|
|
5
|
-
export declare function ensureDatabaseConfigLoaded(): Promise<void>;
|
|
6
|
-
declare function getDb(): ReturnType<typeof createQueryBuilder>;
|
|
7
|
-
/**
|
|
8
|
-
* Lazy proxy for the query builder - connection is only made when first used.
|
|
9
|
-
* This is the main entry point for database operations.
|
|
10
|
-
*/
|
|
11
|
-
export declare const db: Proxy;
|
|
12
|
-
/**
|
|
13
|
-
* Fluent chain returned by entry-point methods like `selectFrom`/`updateTable`.
|
|
14
|
-
*
|
|
15
|
-
* bun-query-builder marks legacy chain methods (e.g. `selectAll`, `whereILike`,
|
|
16
|
-
* `selectAllRelations`) as optional in its declarations even though they're
|
|
17
|
-
* always present at runtime. Re-typing them here avoids forcing every call
|
|
18
|
-
* site to use `?.()` or `!` on the chain.
|
|
19
|
-
*
|
|
20
|
-
* Returns are typed as `any` deliberately — typing each variant precisely
|
|
21
|
-
* would re-introduce the optional methods, and we already lose strict column
|
|
22
|
-
* typing one step into a chain (the underlying query builder is constructed
|
|
23
|
-
* with no schema). Tests cover the runtime semantics.
|
|
24
|
-
*/
|
|
25
|
-
export declare interface FluentChain {
|
|
26
|
-
where(callback: (eb: import('./types').StacksExpressionBuilder) => unknown): FluentChain
|
|
27
|
-
where(...args: any[]): FluentChain
|
|
28
|
-
whereNull: (...args: any[]) => FluentChain
|
|
29
|
-
whereNotNull: (...args: any[]) => FluentChain
|
|
30
|
-
whereIn: (...args: any[]) => FluentChain
|
|
31
|
-
whereNotIn: (...args: any[]) => FluentChain
|
|
32
|
-
whereLike: (...args: any[]) => FluentChain
|
|
33
|
-
whereNotLike: (...args: any[]) => FluentChain
|
|
34
|
-
whereILike: (...args: any[]) => FluentChain
|
|
35
|
-
whereNotILike: (...args: any[]) => FluentChain
|
|
36
|
-
whereBetween: (...args: any[]) => FluentChain
|
|
37
|
-
whereNotBetween: (...args: any[]) => FluentChain
|
|
38
|
-
whereRaw: (...args: any[]) => FluentChain
|
|
39
|
-
whereColumn: (...args: any[]) => FluentChain
|
|
40
|
-
orWhere: (...args: any[]) => FluentChain
|
|
41
|
-
orWhereNull: (...args: any[]) => FluentChain
|
|
42
|
-
orWhereNotNull: (...args: any[]) => FluentChain
|
|
43
|
-
orWhereIn: (...args: any[]) => FluentChain
|
|
44
|
-
orWhereNotIn: (...args: any[]) => FluentChain
|
|
45
|
-
orWhereLike: (...args: any[]) => FluentChain
|
|
46
|
-
orWhereNotLike: (...args: any[]) => FluentChain
|
|
47
|
-
orWhereILike: (...args: any[]) => FluentChain
|
|
48
|
-
orWhereColumn: (...args: any[]) => FluentChain
|
|
49
|
-
andWhere: (...args: any[]) => FluentChain
|
|
50
|
-
having: (...args: any[]) => FluentChain
|
|
51
|
-
groupBy: (...args: any[]) => FluentChain
|
|
52
|
-
orderBy: (...args: any[]) => FluentChain
|
|
53
|
-
limit: (...args: any[]) => FluentChain
|
|
54
|
-
offset: (...args: any[]) => FluentChain
|
|
55
|
-
select(selection: ((eb: import('./types').StacksExpressionBuilder) => unknown) | ReadonlyArray<string | ((eb: import('./types').StacksExpressionBuilder) => unknown) | unknown>): FluentChain
|
|
56
|
-
select(...args: any[]): FluentChain
|
|
57
|
-
selectAll: () => FluentChain
|
|
58
|
-
selectAllRelations: () => FluentChain
|
|
59
|
-
selectRaw: (...args: any[]) => FluentChain
|
|
60
|
-
distinct: () => FluentChain
|
|
61
|
-
distinctOn: (...args: any[]) => FluentChain
|
|
62
|
-
innerJoin: (...args: any[]) => FluentChain
|
|
63
|
-
leftJoin: (...args: any[]) => FluentChain
|
|
64
|
-
rightJoin: (...args: any[]) => FluentChain
|
|
65
|
-
fullJoin: (...args: any[]) => FluentChain
|
|
66
|
-
crossJoin: (...args: any[]) => FluentChain
|
|
67
|
-
with: (...args: any[]) => FluentChain
|
|
68
|
-
union: (...args: any[]) => FluentChain
|
|
69
|
-
unionAll: (...args: any[]) => FluentChain
|
|
70
|
-
values: (...args: any[]) => FluentChain
|
|
71
|
-
set: (...args: any[]) => FluentChain
|
|
72
|
-
returning: (...args: any[]) => FluentChain
|
|
73
|
-
returningAll: () => FluentChain
|
|
74
|
-
onConflict: (...args: any[]) => FluentChain
|
|
75
|
-
onDuplicateKeyUpdate: (...args: any[]) => FluentChain
|
|
76
|
-
onConflictDoNothing: (...args: any[]) => FluentChain
|
|
77
|
-
onDuplicateKeyIgnore: () => FluentChain
|
|
78
|
-
forUpdate: () => FluentChain
|
|
79
|
-
forShare: () => FluentChain
|
|
80
|
-
toSQL: () => string
|
|
81
|
-
execute: () => Promise<any>
|
|
82
|
-
executeTakeFirst: () => Promise<any>
|
|
83
|
-
executeTakeFirstOrThrow: () => Promise<any>
|
|
84
|
-
pluck: (...args: any[]) => Promise<any>
|
|
85
|
-
count: (...args: any[]) => Promise<number>
|
|
86
|
-
sum: (...args: any[]) => Promise<number>
|
|
87
|
-
avg: (...args: any[]) => Promise<number>
|
|
88
|
-
min: (...args: any[]) => Promise<any>
|
|
89
|
-
max: (...args: any[]) => Promise<any>
|
|
90
|
-
exists: () => Promise<boolean>
|
|
91
|
-
doesntExist: () => Promise<boolean>
|
|
92
|
-
$call: (callback: (query: FluentChain) => FluentChain) => FluentChain
|
|
93
|
-
[key: string]: any
|
|
94
|
-
}
|
|
95
|
-
/*.ts` and
|
|
96
|
-
* emits `database/types.d.ts` containing:
|
|
97
|
-
*
|
|
98
|
-
* ```ts
|
|
99
|
-
* declare module '@stacksjs/database' {
|
|
100
|
-
* interface DatabaseSchema {
|
|
101
|
-
* court_houses: { columns: { id: number; name: string; ... } }
|
|
102
|
-
* judges: { columns: { id: number; name: string; court_id: number; ... } }
|
|
103
|
-
* }
|
|
104
|
-
* }
|
|
105
|
-
* ```
|
|
106
|
-
*
|
|
107
|
-
* Once that file is loaded into the TS project, `db.selectFrom('co|')`
|
|
108
|
-
* autocompletes to known table names. Apps without a generated file
|
|
109
|
-
* still compile — the `(string & {})` branch on `TableName` keeps the
|
|
110
|
-
* type as a literal-union+escape-hatch, so any string is accepted
|
|
111
|
-
* but known keys are surfaced first by the language server.
|
|
112
|
-
*/
|
|
113
|
-
// eslint-disable-next-line ts/no-empty-object-type
|
|
114
|
-
export declare interface DatabaseSchema {}
|
|
115
|
-
declare interface Db extends Pick<Required<RawQueryBuilder>, GenericPassthroughKeys> {
|
|
116
|
-
fn: import('./types').ExpressionFunctions
|
|
117
|
-
selectFrom: (table: TableName) => FluentChain
|
|
118
|
-
insertInto: (table: TableName) => FluentChain
|
|
119
|
-
updateTable: (table: TableName) => FluentChain
|
|
120
|
-
deleteFrom: (table: TableName) => FluentChain
|
|
121
|
-
table: (table: TableName) => FluentChain
|
|
122
|
-
selectFromSub: (sub: any, alias: string) => FluentChain
|
|
123
|
-
select: (table: TableName, ...columns: string[]) => FluentChain
|
|
124
|
-
unsafe: (query: string, params?: any[]) => UnsafeReturn
|
|
125
|
-
}
|
|
126
|
-
// The bun-query-builder types `unsafe()` as returning `Promise<any>`, but at
|
|
127
|
-
// runtime it returns a Bun SQL Statement that has `.execute()`. This interface
|
|
128
|
-
// corrects the return type so callers can chain `.execute()` without type errors.
|
|
129
|
-
declare type UnsafeReturn = Promise<any> & { execute: () => Promise<any> }
|
|
130
|
-
/**
|
|
131
|
-
* Top-level surface of the lazy `db` proxy. Methods that return a chainable
|
|
132
|
-
* builder are typed as `FluentChain` to flatten the optional-method noise
|
|
133
|
-
* inherent in bun-query-builder's declarations. Methods that introduce their
|
|
134
|
-
* own generics (`transaction<T>`, etc.) are kept as their original signatures
|
|
135
|
-
* via the underlying QueryBuilder type so call-site inference still works.
|
|
136
|
-
*/
|
|
137
|
-
declare type RawQueryBuilder = ReturnType<typeof createQueryBuilder>;
|
|
138
|
-
declare type GenericPassthroughKeys = | 'transaction'
|
|
139
|
-
| 'savepoint'
|
|
140
|
-
| 'beginDistributed'
|
|
141
|
-
| 'transactional'
|
|
142
|
-
| 'configure'
|
|
143
|
-
| 'reserve'
|
|
144
|
-
| 'commitDistributed'
|
|
145
|
-
| 'rollbackDistributed'
|
|
146
|
-
| 'setTransactionDefaults'
|
|
147
|
-
| 'close'
|
|
148
|
-
| 'listen'
|
|
149
|
-
| 'unlisten'
|
|
150
|
-
| 'notify'
|
|
151
|
-
| 'copyTo'
|
|
152
|
-
| 'copyFrom'
|
|
153
|
-
| 'ping'
|
|
154
|
-
| 'waitForReady'
|
|
155
|
-
| 'count'
|
|
156
|
-
| 'sum'
|
|
157
|
-
| 'avg'
|
|
158
|
-
| 'min'
|
|
159
|
-
| 'max'
|
|
160
|
-
| 'insertOrIgnore'
|
|
161
|
-
| 'insertGetId'
|
|
162
|
-
| 'updateOrInsert'
|
|
163
|
-
| 'upsert'
|
|
164
|
-
| 'create'
|
|
165
|
-
| 'createMany'
|
|
166
|
-
| 'sql'
|
|
167
|
-
| 'raw'
|
|
168
|
-
| 'simple'
|
|
169
|
-
| 'file';
|
|
170
|
-
/**
|
|
171
|
-
* Accept either a registered table name (from augmented
|
|
172
|
-
* `DatabaseSchema`) for autocomplete, or any other string for apps
|
|
173
|
-
* that haven't generated types yet / tables not in a model file.
|
|
174
|
-
*
|
|
175
|
-
* The `(string & {})` branch prevents TS from collapsing the union
|
|
176
|
-
* back to `string` and losing the autocomplete narrowing — a
|
|
177
|
-
* well-documented LiteralUnion trick.
|
|
178
|
-
*/
|
|
179
|
-
// eslint-disable-next-line ts/no-empty-object-type
|
|
180
|
-
export type TableName = (keyof DatabaseSchema & string) | (string & {});
|
|
181
|
-
// SQLite bootstrap pragmas (stacksjs/stacks#1951) now live in
|
|
182
|
-
// @stacksjs/query-builder — the one chokepoint every framework
|
|
183
|
-
// query-builder instance is created through — so EVERY fresh sqlite
|
|
184
|
-
// connection gets `foreign_keys = ON`, including builders created outside
|
|
185
|
-
// this module (e.g. the ORM auto-CRUD routes). Re-exported here for
|
|
186
|
-
// backwards compatibility with existing imports.
|
|
187
|
-
export { applySqlitePragmas, SQLITE_BOOTSTRAP_PRAGMAS } from '@stacksjs/query-builder';
|
|
188
|
-
// Export setConfig if available
|
|
189
|
-
export { setConfig };
|
package/dist/uuid-columns.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { sqlHelpers } from './sql-helpers';
|
|
2
|
-
/** Pure builder so tests can assert per-dialect DDL without a live DB. */
|
|
3
|
-
export declare function uuidColumnSql(table: string, sql: SqlHelpers): string;
|
|
4
|
-
/**
|
|
5
|
-
* Resolve every table backing a model with `useUuid: true`, across both
|
|
6
|
-
* userland (`app/Models`) and framework-default (`defaults/app/Models`)
|
|
7
|
-
* model directories. Exported so tests (and `doctor`-style diagnostics) can
|
|
8
|
-
* inspect the resolved set without touching a live database.
|
|
9
|
-
*/
|
|
10
|
-
export declare function findUuidTables(): Promise<string[]>;
|
|
11
|
-
/**
|
|
12
|
-
* Guarantee-ALTER `uuid` onto every table whose model declares
|
|
13
|
-
* `useUuid: true`, independently try/catch-swallowed per table so one
|
|
14
|
-
* already-having-the-column (or not-yet-existing) table never skips the
|
|
15
|
-
* rest. Exported so `buddy migrate`/`migrate:fresh` can call it after model
|
|
16
|
-
* migrations run, same pattern as {@link ensureUsersAuthColumns} — see the
|
|
17
|
-
* call sites in buddy/src/commands/migrate.ts.
|
|
18
|
-
*/
|
|
19
|
-
export declare function ensureUuidColumns(sql: SqlHelpers, options?: { verbose?: boolean }): Promise<void>;
|
|
20
|
-
/** Convenience wrapper resolving dialect helpers from `DB_CONNECTION`, for call sites that don't already have a `SqlHelpers` instance. */
|
|
21
|
-
export declare function ensureUuidColumnsForCurrentDriver(options?: { verbose?: boolean }): Promise<void>;
|
|
22
|
-
declare type SqlHelpers = ReturnType<typeof sqlHelpers>;
|
package/dist/validators.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { BigintValidatorType, BinaryValidatorType, BlobValidatorType, BooleanValidatorType, DatetimeValidatorType, DateValidatorType, DecimalValidatorType, EnumValidatorType, FloatValidatorType, IntegerValidatorType, JsonValidatorType, NumberValidatorType, SmallintValidatorType, StringValidatorType, TimestampTzValidatorType, TimestampValidatorType, UnixValidatorType, ValidationType } from '@stacksjs/ts-validation';
|
|
2
|
-
export declare function isStringValidator(v: ValidationType): v is StringValidatorType;
|
|
3
|
-
export declare function isNumberValidator(v: ValidationType): v is NumberValidatorType;
|
|
4
|
-
export declare function enumValidator(v: ValidationType): v is EnumValidatorType;
|
|
5
|
-
export declare function isBooleanValidator(v: ValidationType): v is BooleanValidatorType;
|
|
6
|
-
export declare function isDateValidator(v: ValidationType): v is DateValidatorType;
|
|
7
|
-
export declare function isUnixValidator(v: ValidationType): v is UnixValidatorType;
|
|
8
|
-
export declare function isFloatValidator(v: ValidationType): v is FloatValidatorType;
|
|
9
|
-
export declare function isDatetimeValidator(v: ValidationType): v is DatetimeValidatorType;
|
|
10
|
-
export declare function isTimestampValidator(v: ValidationType): v is TimestampValidatorType;
|
|
11
|
-
export declare function isTimestampTzValidator(v: ValidationType): v is TimestampTzValidatorType;
|
|
12
|
-
export declare function isDecimalValidator(v: ValidationType): v is DecimalValidatorType;
|
|
13
|
-
export declare function isSmallintValidator(v: ValidationType): v is SmallintValidatorType;
|
|
14
|
-
export declare function isIntegerValidator(v: ValidationType): v is IntegerValidatorType;
|
|
15
|
-
export declare function isBigintValidator(v: ValidationType): v is BigintValidatorType;
|
|
16
|
-
export declare function isBinaryValidator(v: ValidationType): v is BinaryValidatorType;
|
|
17
|
-
export declare function isBlobValidator(v: ValidationType): v is BlobValidatorType;
|
|
18
|
-
export declare function isJsonValidator(v: ValidationType): v is JsonValidatorType;
|
|
19
|
-
export declare function checkValidator(validator: ValidationType, driver: string): string;
|
|
20
|
-
export declare function prepareNumberColumnType(validator: NumberValidatorType, driver?: string): string;
|
|
21
|
-
// Add new function for enum column types
|
|
22
|
-
export declare function prepareEnumColumnType(validator: EnumValidatorType, driver?: string): string;
|
|
23
|
-
export declare function prepareTextColumnType(validator: StringValidatorType, driver?: string): string;
|
|
24
|
-
// Add new function for date/time column types
|
|
25
|
-
export declare function prepareDateTimeColumnType(validator: DateValidatorType, driver?: string): string;
|
|
26
|
-
export declare function findCharacterLength(validator: ValidationType): number;
|