bun-query-builder 0.1.5 → 0.1.6

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 (41) hide show
  1. package/dist/actions/benchmark.d.ts +9 -5
  2. package/dist/actions/cache.d.ts +2 -14
  3. package/dist/actions/console.d.ts +0 -6
  4. package/dist/actions/data.d.ts +3 -13
  5. package/dist/actions/db-info.d.ts +4 -9
  6. package/dist/actions/db-optimize.d.ts +4 -5
  7. package/dist/actions/db-wipe.d.ts +4 -5
  8. package/dist/actions/file.d.ts +2 -1
  9. package/dist/actions/index.d.ts +25 -25
  10. package/dist/actions/inspect.d.ts +3 -9
  11. package/dist/actions/introspect.d.ts +2 -1
  12. package/dist/actions/make-model.d.ts +3 -5
  13. package/dist/actions/migrate-generate.d.ts +4 -5
  14. package/dist/actions/migrate-rollback.d.ts +4 -11
  15. package/dist/actions/migrate-status.d.ts +5 -9
  16. package/dist/actions/migrate.d.ts +13 -21
  17. package/dist/actions/model-show.d.ts +3 -5
  18. package/dist/actions/query-explain-all.d.ts +3 -5
  19. package/dist/actions/relation-diagram.d.ts +5 -5
  20. package/dist/actions/seed.d.ts +7 -17
  21. package/dist/actions/sql.d.ts +2 -1
  22. package/dist/actions/unsafe.d.ts +2 -1
  23. package/dist/actions/validate.d.ts +4 -9
  24. package/dist/actions/wait-ready.d.ts +2 -1
  25. package/dist/client.d.ts +199 -189
  26. package/dist/config.d.ts +2 -1
  27. package/dist/db.d.ts +8 -9
  28. package/dist/drivers/index.d.ts +8 -6
  29. package/dist/drivers/mysql.d.ts +169 -19
  30. package/dist/drivers/postgres.d.ts +155 -19
  31. package/dist/drivers/sqlite.d.ts +157 -19
  32. package/dist/factory.d.ts +3 -6
  33. package/dist/index.d.ts +11 -11
  34. package/dist/index.js +48 -51
  35. package/dist/loader.d.ts +3 -2
  36. package/dist/meta.d.ts +3 -2
  37. package/dist/migrations.d.ts +42 -47
  38. package/dist/schema.d.ts +30 -177
  39. package/dist/seeder.d.ts +12 -17
  40. package/dist/types.d.ts +42 -143
  41. package/package.json +4 -3
package/dist/types.d.ts CHANGED
@@ -1,127 +1,49 @@
1
- /**
2
- * # `TransactionBackoffConfig`
3
- *
4
- * Controls exponential backoff between transaction retry attempts.
5
- *
6
- * - `baseMs`: Initial delay in milliseconds used for the first retry.
7
- * - `factor`: Multiplicative growth factor applied per attempt (e.g., 2 = doubles).
8
- * - `maxMs`: Maximum delay cap in milliseconds; backoff never exceeds this value.
9
- * - `jitter`: When true, adds a small randomization to the delay to reduce thundering herds.
10
- *
11
- * The delay for attempt n (1-indexed) is roughly: min(maxMs, baseMs * factor^(n-1)),
12
- * optionally adjusted by jitter.
13
- */
14
- export declare interface TransactionBackoffConfig {
1
+ export declare type SupportedDialect = 'postgres' | 'mysql' | 'sqlite'
2
+
3
+ export interface TransactionBackoffConfig {
15
4
  baseMs: number
16
5
  factor: number
17
6
  maxMs: number
18
7
  jitter: boolean
19
8
  }
20
- /**
21
- * # `TransactionDefaultsConfig`
22
- *
23
- * Default settings applied to transactional operations.
24
- *
25
- * - `retries`: Number of times a transaction may be retried on retriable errors
26
- * (e.g., deadlocks, serialization failures).
27
- * - `isolation`: Transaction isolation level.
28
- * - 'read committed': Prevents dirty reads; non-repeatable reads possible.
29
- * - 'repeatable read': Ensures stable snapshot for a transaction; phantom reads may vary by DB.
30
- * - 'serializable': Highest isolation; transactions appear to run one-by-one.
31
- * - `sqlStates`: Additional vendor error codes considered retriable.
32
- * - `backoff`: Backoff configuration applied between retries.
33
- */
34
- export declare interface TransactionDefaultsConfig {
9
+
10
+ export interface TransactionDefaultsConfig {
35
11
  retries: number
36
12
  isolation?: 'read committed' | 'repeatable read' | 'serializable'
37
13
  sqlStates: string[]
38
14
  backoff: TransactionBackoffConfig
39
15
  }
40
- /**
41
- * # `TimestampConfig`
42
- *
43
- * Column naming conventions for timestamp fields used by helpers.
44
- *
45
- * - `createdAt`: Column name for row creation time (e.g., 'created_at').
46
- * - `updatedAt`: Column name for last update time (e.g., 'updated_at').
47
- * - `defaultOrderColumn`: Column used by helpers like `latest()`/`oldest()`.
48
- */
49
- export declare interface TimestampConfig {
16
+
17
+ export interface TimestampConfig {
50
18
  createdAt: string
51
19
  updatedAt: string
52
20
  defaultOrderColumn: string
53
21
  }
54
- /**
55
- * # `PaginationConfig`
56
- *
57
- * Defaults for result pagination helpers.
58
- *
59
- * - `defaultPerPage`: Default LIMIT used by paginate helpers when not specified.
60
- * - `cursorColumn`: Default column used for cursor-based pagination (e.g., 'id').
61
- */
62
- export declare interface PaginationConfig {
22
+
23
+ export interface PaginationConfig {
63
24
  defaultPerPage: number
64
25
  cursorColumn: string
65
26
  }
66
- /**
67
- * # `AliasingConfig`
68
- *
69
- * Controls how selected columns from joined relations are aliased.
70
- *
71
- * - `relationColumnAliasFormat`:
72
- * - 'table_column': Aliases as `${table}_${column}` (e.g., `posts_title`).
73
- * - 'table.dot.column': Aliases with dot notation (e.g., `posts.title`).
74
- * - 'camelCase': Aliases as camelCase from `${table}_${column}` (e.g., `postsTitle`).
75
- */
76
- export declare interface AliasingConfig {
27
+
28
+ export interface AliasingConfig {
77
29
  relationColumnAliasFormat: 'table_column' | 'table.dot.column' | 'camelCase'
78
30
  }
79
- /**
80
- * # `RelationsConfig`
81
- *
82
- * Conventions for inferring foreign key names and singularization.
83
- *
84
- * - `foreignKeyFormat`:
85
- * - 'singularParent_id': Uses `${singular(parent)}_id` (e.g., `user_id`).
86
- * - 'parentId': Uses camelCase `parentId` (e.g., `userId`).
87
- * - `singularizeStrategy`:
88
- * - 'stripTrailingS': Naively remove trailing 's' when singularizing (default behavior when enabled elsewhere).
89
- * - 'none': Do not singularize relation/table names.
90
- */
91
- export declare interface RelationsConfig {
31
+
32
+ export interface RelationsConfig {
92
33
  foreignKeyFormat: 'singularParent_id' | 'parentId'
93
34
  singularizeStrategy?: 'stripTrailingS' | 'none'
94
35
  maxDepth?: number
95
36
  maxEagerLoad?: number
96
37
  detectCycles?: boolean
97
38
  }
98
- /**
99
- * # `SqlConfig`
100
- *
101
- * Dialect-specific SQL toggles.
102
- *
103
- * - `randomFunction`:
104
- * - 'RANDOM()': PostgreSQL/SQLite style function for random ordering.
105
- * - 'RAND()': MySQL style function for random ordering.
106
- * - `sharedLockSyntax`:
107
- * - 'FOR SHARE': PostgreSQL style shared lock.
108
- * - 'LOCK IN SHARE MODE': MySQL style shared lock.
109
- * - `jsonContainsMode`:
110
- * - 'operator': Use native operators when available (e.g., Postgres `@>`).
111
- * - 'function': Use a function-based approach (e.g., `json_contains`) when operators are not available.
112
- */
113
- export declare interface SqlConfig {
39
+
40
+ export interface SqlConfig {
114
41
  randomFunction?: 'RANDOM()' | 'RAND()'
115
42
  sharedLockSyntax?: 'FOR SHARE' | 'LOCK IN SHARE MODE'
116
43
  jsonContainsMode?: 'operator' | 'function'
117
44
  }
118
- /**
119
- * # `QueryHooks`
120
- *
121
- * Optional lifecycle hooks around query execution. These are invoked for any
122
- * statement executed through the builder (select/insert/update/delete/raw).
123
- */
124
- export declare interface QueryHooks {
45
+
46
+ export interface QueryHooks {
125
47
  onQueryStart?: (event: { sql: string, params?: any[], kind?: 'select' | 'insert' | 'update' | 'delete' | 'raw' }) => void
126
48
  onQueryEnd?: (event: { sql: string, params?: any[], durationMs: number, rowCount?: number, kind?: 'select' | 'insert' | 'update' | 'delete' | 'raw' }) => void
127
49
  onQueryError?: (event: { sql: string, params?: any[], error: any, durationMs: number, kind?: 'select' | 'insert' | 'update' | 'delete' | 'raw' }) => void
@@ -133,17 +55,12 @@ export declare interface QueryHooks {
133
55
  beforeDelete?: (event: { table: string, where?: any }) => void | Promise<void>
134
56
  afterDelete?: (event: { table: string, where?: any, result: any }) => void | Promise<void>
135
57
  }
136
- /**
137
- * # `FeatureToggles`
138
- *
139
- * Optional features that may be enabled per instance.
140
- *
141
- * - `distinctOn`: Enables PostgreSQL-like `DISTINCT ON (...)` behavior in builders.
142
- */
143
- export declare interface FeatureToggles {
58
+
59
+ export interface FeatureToggles {
144
60
  distinctOn: boolean
145
61
  }
146
- export declare interface DatabaseConfig {
62
+
63
+ export interface DatabaseConfig {
147
64
  database: string
148
65
  username: string
149
66
  password: string
@@ -151,26 +68,13 @@ export declare interface DatabaseConfig {
151
68
  url?: string
152
69
  port: number
153
70
  }
154
- /**
155
- * # `QueryBuilderConfig`
156
- *
157
- * Global configuration for the query builder.
158
- *
159
- * - `verbose`: Enables extra logging/diagnostics from the builder.
160
- * - `dialect`: Target SQL dialect. See `SupportedDialect` for details.
161
- * - `timestamps`: Timestamp column naming conventions.
162
- * - `pagination`: Defaults for pagination helpers.
163
- * - `aliasing`: How relation columns are aliased in SELECT lists.
164
- * - `relations`: Foreign key naming and singularization conventions.
165
- * - `transactionDefaults`: Default retry/backoff/isolation behavior for transactions.
166
- * - `sql`: Dialect-specific SQL toggles.
167
- * - `features`: Optional feature flags.
168
- * - `debug.captureText`: When true, the builder exposes a `toText()` method to capture SQL text in memory for debugging.
169
- */
170
- export declare interface QueryBuilderConfig {
71
+
72
+ export interface QueryBuilderConfig {
171
73
  verbose: boolean
172
74
  dialect: SupportedDialect
75
+
173
76
  database: DatabaseConfig
77
+
174
78
  timestamps: TimestampConfig
175
79
  pagination: PaginationConfig
176
80
  aliasing: AliasingConfig
@@ -179,56 +83,51 @@ export declare interface QueryBuilderConfig {
179
83
  sql: SqlConfig
180
84
  features: FeatureToggles
181
85
  debug?: {
182
- /** When true, capture query text for debugging via `toText()`. */
183
86
  captureText: boolean
184
87
  }
185
88
  hooks?: QueryHooks
186
89
  softDeletes?: {
187
- /** When true, apply a default `WHERE deleted_at IS NULL` filter. */
188
90
  enabled: boolean
189
- /** Column name used for soft delete flag/timestamp. */
190
91
  column: string
191
- /** When true, default filter is applied unless `.withTrashed()` is called. */
192
92
  defaultFilter: boolean
193
93
  }
194
94
  }
195
- export declare interface CliOption {
95
+
96
+ export interface CliOption {
196
97
  verbose: boolean
197
98
  }
198
- export declare interface SqlOptions {
99
+
100
+ export interface SqlOptions {
199
101
  limit?: number
200
102
  }
201
- export declare interface WaitReadyOptions {
103
+
104
+ export interface WaitReadyOptions {
202
105
  attempts?: number
203
106
  delay?: number
204
107
  }
205
- export declare interface FileOptions {
108
+
109
+ export interface FileOptions {
206
110
  params?: string
207
111
  }
208
- export declare interface IntrospectOptions {
112
+
113
+ export interface IntrospectOptions {
209
114
  verbose?: boolean
210
115
  }
211
- export declare interface MigrateOptions {
116
+
117
+ export interface MigrateOptions {
212
118
  dialect?: SupportedDialect
213
119
  state?: string
214
120
  apply?: boolean
215
121
  full?: boolean
216
122
  }
217
- export declare interface GenerateMigrationResult {
123
+
124
+ export interface GenerateMigrationResult {
218
125
  sql: string
219
126
  sqlStatements: string[]
220
127
  hasChanges: boolean
221
128
  plan: any
222
129
  }
223
- export declare interface UnsafeOptions {
130
+
131
+ export interface UnsafeOptions {
224
132
  params?: string
225
- }
226
- /**
227
- * # `SupportedDialect`
228
- *
229
- * The SQL dialect used to tailor generated SQL and certain features.
230
- * - 'postgres': Uses `RANDOM()`, supports JSON operators (e.g. `@>`), `FOR SHARE`, `FOR UPDATE`, CTEs
231
- * - 'mysql': Uses `RAND()`, shared locks via `LOCK IN SHARE MODE`
232
- * - 'sqlite': Lightweight engine; some features are limited or emulated
233
- */
234
- export type SupportedDialect = 'postgres' | 'mysql' | 'sqlite'
133
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-query-builder",
3
3
  "type": "module",
4
- "version": "0.1.5",
4
+ "version": "0.1.6",
5
5
  "description": "A simple yet performant query builder for TypeScript. Built with Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -62,15 +62,16 @@
62
62
  "lint:fix": "bunx --bun eslint . --fix",
63
63
  "changelog": "bunx logsmith --verbose",
64
64
  "changelog:generate": "bunx logsmith --output CHANGELOG.md",
65
- "release": "bun run changelog:generate && bunx bumpx prompt --recursive",
65
+ "release": "bun --bun run changelog:generate && bunx --bun bumpx prompt --recursive",
66
66
  "dev:docs": "bun --bun vitepress dev docs",
67
67
  "build:docs": "bun --bun vitepress build docs",
68
68
  "preview:docs": "bun --bun vitepress preview docs",
69
69
  "typecheck": "bun --bun tsc"
70
70
  },
71
71
  "dependencies": {
72
+ "@stacksjs/clapp": "^0.2.0",
72
73
  "@stacksjs/ts-validation": "^0.4.7",
73
- "ts-mocker": "^0.1.3"
74
+ "ts-mocker": "^0.1.5"
74
75
  },
75
76
  "devDependencies": {
76
77
  "bunfig": "^0.15.0"