bun-query-builder 0.1.21 → 0.1.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/browser.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { BrowserConfig } from './types';
2
- import type { Faker } from 'ts-mocker';
2
+ import type { Faker } from '@stacksjs/ts-faker';
3
3
  // Export types for external use
4
4
  export type { BrowserModelInstance, BrowserModelQueryBuilder };
5
5
  /**
@@ -56,29 +56,40 @@ export declare function createBrowserDb<Tables extends Record<string, any>>(): {
56
56
  export declare function createBrowserModel<const TDef extends BrowserModelDefinition>(definition: TDef): void;
57
57
  /**
58
58
  * Auth helpers for browser
59
- * @defaultValue `{ async login: () => unknown, async register: () => unknown }`
59
+ * @defaultValue
60
+ * ```ts
61
+ * {
62
+ * login: (credentials?: { email: string, password: string }): Promise<BrowserAuthResponse> {
63
+ * const response) => Promise<unknown>,
64
+ * register: (data?: { name: string, email: string, password: string }): Promise<BrowserAuthResponse> {
65
+ * const response) => Promise<unknown>,
66
+ * logout: () => unknown,
67
+ * user: () => unknown,
68
+ * check: () => unknown
69
+ * }
70
+ * ```
60
71
  */
61
72
  export declare const browserAuth: {
62
73
  /**
63
74
  * Login and store token
64
75
  */
65
- async login: (credentials: { email: string, password: string }) => Promise<BrowserAuthResponse>;
76
+ login: (credentials: { email: string, password: string }) => Promise<BrowserAuthResponse>;
66
77
  /**
67
78
  * Register a new user
68
79
  */
69
- async register: (data: { name: string, email: string, password: string }) => Promise<BrowserAuthResponse>;
80
+ register: (data: { name: string, email: string, password: string }) => Promise<BrowserAuthResponse>;
70
81
  /**
71
82
  * Logout and clear token
72
83
  */
73
- async logout: () => Promise<void>;
84
+ logout: () => Promise<void>;
74
85
  /**
75
86
  * Get current authenticated user
76
87
  */
77
- async user: unknown;
88
+ user: () => Promise<Record<string, unknown> | null>;
78
89
  /**
79
90
  * Check if user is authenticated
80
91
  */
81
- async check: () => Promise<boolean>;
92
+ check: () => Promise<boolean>;
82
93
  /**
83
94
  * Get the current token
84
95
  */
package/dist/client.d.ts CHANGED
@@ -32,9 +32,9 @@ export declare interface WhereRaw {
32
32
  export declare interface BaseSelectQueryBuilder<DB extends DatabaseSchema<any>, TTable extends keyof DB & string, TSelected, TJoined extends string = TTable,> {
33
33
  distinct: () => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
34
34
  distinctOn: (...columns: (keyof DB[TTable]['columns'] & string | string)[]) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
35
- selectRaw: (fragment: any) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
35
+ selectRaw: (fragment: SqlFragment) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
36
36
  where: (expr: WhereExpression<DB[TTable]['columns']> | string, op?: WhereOperator, value?: any) => SelectQueryBuilder<DB, TTable, TSelected>
37
- whereRaw: (fragment: any) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
37
+ whereRaw: (fragment: SqlFragment) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
38
38
  whereColumn: (left: string, op: WhereOperator, right: string) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
39
39
  orWhereColumn: (left: string, op: WhereOperator, right: string) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
40
40
  whereIn: (column: keyof DB[TTable]['columns'] & string, values: any[] | { toSQL: () => any }) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
@@ -100,13 +100,13 @@ export declare interface BaseSelectQueryBuilder<DB extends DatabaseSchema<any>,
100
100
  crossJoin: <T2 extends keyof DB & string>(table: T2) => SelectQueryBuilder<DB, TTable, TSelected, TJoined | T2>
101
101
  crossJoinSub: (sub: { toSQL: () => any }, alias: string) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
102
102
  groupBy: (...columns: (keyof DB[TTable]['columns'] & string | string)[]) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
103
- groupByRaw: (fragment: any) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
103
+ groupByRaw: (fragment: SqlFragment) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
104
104
  having: (expr: WhereExpression<any>) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
105
- havingRaw: (fragment: any) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
105
+ havingRaw: (fragment: SqlFragment) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
106
106
  addSelect: (...columns: (keyof DB[TTable]['columns'] & string | string)[]) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
107
107
  select?: (columns: (keyof DB[TTable]['columns'] & string | string)[]) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
108
108
  selectAll?: () => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
109
- orderByRaw: (fragment: any) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
109
+ orderByRaw: (fragment: SqlFragment) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
110
110
  union: (other: { toSQL: () => any }) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
111
111
  unionAll: (other: { toSQL: () => any }) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
112
112
  forPage: (page: number, perPage: number) => SelectQueryBuilder<DB, TTable, TSelected, TJoined>
@@ -356,6 +356,28 @@ export declare interface TransactionOptions {
356
356
  declare type Primitive = string | number | boolean | bigint | Date | null | undefined;
357
357
  declare type ValueOrRef = Primitive;
358
358
  export type WhereOperator = '=' | '!=' | '<' | '>' | '<=' | '>=' | 'like' | 'in' | 'not in' | 'is' | 'is not';
359
+ /**
360
+ * Brand for SQL fragments produced by Bun's `sql\`...\`` tagged-template
361
+ * (or any equivalent helper). Typed as `object` so the *Raw methods
362
+ * (`whereRaw`, `selectRaw`, `groupByRaw`, `havingRaw`, `orderByRaw`)
363
+ * refuse to compile when passed a bare string — concatenated user
364
+ * input (`whereRaw(\`status = '${req.body.s}'\`)`) was the canonical
365
+ * SQL-injection vector flagged by the audit as Q-3.
366
+ *
367
+ * Callers who legitimately need raw SQL use `sql\`...\`` which
368
+ * separates the SQL fragment from parameter values:
369
+ *
370
+ * ```ts
371
+ * import { sql } from 'bun'
372
+ * db.selectFrom('users').whereRaw(sql\`lower(name) = lower(${input})\`)
373
+ * ```
374
+ *
375
+ * The runtime guard in each *Raw method also rejects bare strings as
376
+ * a defense-in-depth backstop for `as any` casts.
377
+ *
378
+ * See stacksjs/stacks#1858 Q-3.
379
+ */
380
+ export type SqlFragment = object;
359
381
  export type WhereExpression<TableColumns> = | Partial<{ [K in keyof TableColumns & string]: ValueOrRef | ValueOrRef[] }>
360
382
  | [key: keyof TableColumns & string, op: WhereOperator, value: ValueOrRef | ValueOrRef[]]
361
383
  | WhereRaw;
package/dist/config.d.ts CHANGED
@@ -11,11 +11,6 @@ export declare function getPlaceholder(index: number): string;
11
11
  */
12
12
  export declare function getPlaceholders(count: number, startIndex?: number): string;
13
13
  export declare function getConfig(): Promise<QueryBuilderConfig>;
14
- /**
15
- * Programmatically set/override the query builder configuration.
16
- * This is useful when you want to configure bun-query-builder from
17
- * your application code rather than using a config file.
18
- */
19
14
  export declare function setConfig(userConfig: Partial<QueryBuilderConfig>): void;
20
15
  export declare const defaultConfig: QueryBuilderConfig;
21
16
  // For backwards compatibility — synchronous access with default fallback.
@@ -15,5 +15,17 @@ export declare interface DialectDriver {
15
15
  recordMigrationQuery: () => string
16
16
  }
17
17
  export declare class MySQLDriver implements DialectDriver {
18
-
18
+ createEnumType(_enumTypeName: string, _values: string[]): string;
19
+ createTable(table: TablePlan): string;
20
+ createIndex(tableName: string, index: IndexPlan): string;
21
+ addForeignKey(tableName: string, columnName: string, refTable: string, refColumn: string, onDelete?: string, onUpdate?: string): string;
22
+ addColumn(tableName: string, column: ColumnPlan): string;
23
+ modifyColumn(tableName: string, column: ColumnPlan): string;
24
+ dropTable(tableName: string): string;
25
+ dropColumn(tableName: string, columnName: string): string;
26
+ dropIndex(tableName: string, indexName: string): string;
27
+ dropEnumType(_enumTypeName: string): string;
28
+ createMigrationsTable(): string;
29
+ getExecutedMigrationsQuery(): string;
30
+ recordMigrationQuery(): string;
19
31
  }
@@ -15,5 +15,17 @@ export declare interface DialectDriver {
15
15
  recordMigrationQuery: () => string
16
16
  }
17
17
  export declare class PostgresDriver implements DialectDriver {
18
-
18
+ createEnumType(enumTypeName: string, values: string[]): string;
19
+ createTable(table: TablePlan): string;
20
+ createIndex(tableName: string, index: IndexPlan): string;
21
+ addForeignKey(tableName: string, columnName: string, refTable: string, refColumn: string, onDelete?: string, onUpdate?: string): string;
22
+ addColumn(tableName: string, column: ColumnPlan): string;
23
+ modifyColumn(tableName: string, column: ColumnPlan): string;
24
+ dropTable(tableName: string): string;
25
+ dropColumn(tableName: string, columnName: string): string;
26
+ dropIndex(tableName: string, indexName: string): string;
27
+ dropEnumType(enumTypeName: string): string;
28
+ createMigrationsTable(): string;
29
+ getExecutedMigrationsQuery(): string;
30
+ recordMigrationQuery(): string;
19
31
  }
@@ -15,5 +15,17 @@ export declare interface DialectDriver {
15
15
  recordMigrationQuery: () => string
16
16
  }
17
17
  export declare class SQLiteDriver implements DialectDriver {
18
-
18
+ createEnumType(_enumTypeName: string, _values: string[]): string;
19
+ createTable(table: TablePlan): string;
20
+ createIndex(tableName: string, index: IndexPlan): string;
21
+ addForeignKey(_tableName: string, _columnName: string, _refTable: string, _refColumn: string, _onDelete?: string, _onUpdate?: string): string;
22
+ addColumn(tableName: string, column: ColumnPlan): string;
23
+ modifyColumn(tableName: string, column: ColumnPlan): string;
24
+ dropTable(tableName: string): string;
25
+ dropColumn(tableName: string, columnName: string): string;
26
+ dropIndex(tableName: string, indexName: string): string;
27
+ dropEnumType(_enumTypeName: string): string;
28
+ createMigrationsTable(): string;
29
+ getExecutedMigrationsQuery(): string;
30
+ recordMigrationQuery(): string;
19
31
  }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // Resolve ambiguous re-exports by explicitly choosing which module's version to use
2
2
  export type { WhereOperator } from './browser';
3
- export type { ModelQueryBuilder } from './dynamodb';
3
+ export type { ModelQueryBuilder } from './dynamodb/index';
4
4
  export type { ColumnName } from './client';
5
5
  // Re-export the type-inference version of InferRelationNames (supports wrapped models)
6
6
  // to resolve the ambiguity with orm.ts's InferRelationNames (which takes raw definitions)
@@ -22,16 +22,16 @@ export type {
22
22
  ModelCreateDataLoose,
23
23
  RelationCardinality,
24
24
  } from './type-inference';
25
- export * from './actions';
25
+ export * from './actions/index';
26
26
  export * from './browser';
27
27
  export * from './client';
28
28
  export * from './model';
29
29
  export * from './config';
30
- export * from './drivers';
30
+ export * from './drivers/index';
31
31
  export * from './dynamodb-client';
32
32
  export * from './dynamodb-single-table';
33
33
  export * from './dynamodb-tooling-adapter';
34
- export * from './dynamodb';
34
+ export * from './dynamodb/index';
35
35
  export * from './factory';
36
36
  export * from './loader';
37
37
  export * from './meta';
@@ -44,4 +44,4 @@ export * from './type-inference';
44
44
  export * from './types';
45
45
  export { type ModelDefinition, defineModel } from './model';
46
46
  // Explicit re-exports for model registry functions
47
- export { getModel, getAllModels, getModelRegistry, hasModel, clearModelRegistry } from './model';
47
+ export { getModel, getAllModels, getModelRegistry, hasModel, clearModelRegistry, registerModel } from './model';
package/dist/model.d.ts CHANGED
@@ -53,6 +53,18 @@ export declare function hasModel(name: string): boolean;
53
53
  * Clear all registered models. Primarily useful for testing.
54
54
  */
55
55
  export declare function clearModelRegistry(): void;
56
+ /**
57
+ * Register an already-created model instance in the global registry.
58
+ *
59
+ * Framework integrations can build richer model facades themselves and
60
+ * still expose those models to query-builder features that discover
61
+ * models through the shared registry.
62
+ *
63
+ * @param name - The model name (e.g., 'User', 'Trail')
64
+ * @param model - The runtime model instance to register
65
+ * @returns The same model instance for convenient passthrough usage
66
+ */
67
+ export declare function registerModel<TModel>(name: string, model: TModel): TModel;
56
68
  /**
57
69
  * Define an isomorphic model that works in both server and browser.
58
70
  *
package/dist/orm.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Database, type SQLQueryBindings } from 'bun:sqlite';
2
- import type { Faker } from 'ts-mocker';
2
+ import type { Faker } from '@stacksjs/ts-faker';
3
3
  export type {
4
4
  ModelInstance,
5
5
  ModelQueryBuilder,
package/dist/schema.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Faker } from 'ts-mocker';
1
+ import type { Faker } from '@stacksjs/ts-faker';
2
2
  /**
3
3
  * # `defineModel(model)`
4
4
  *