bun-query-builder 0.1.12 → 0.1.15

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 (63) hide show
  1. package/README.md +45 -468
  2. package/dist/__tests__/type-narrowing-compile.d.ts +1 -0
  3. package/dist/__tests__/type-narrowing.test.d.ts +1 -0
  4. package/dist/actions/benchmark.d.ts +1 -1
  5. package/dist/actions/cache.d.ts +1 -1
  6. package/dist/actions/console.d.ts +1 -1
  7. package/dist/actions/data.d.ts +2 -1
  8. package/dist/actions/db-info.d.ts +1 -1
  9. package/dist/actions/db-optimize.d.ts +1 -1
  10. package/dist/actions/db-wipe.d.ts +1 -1
  11. package/dist/actions/explain.d.ts +1 -1
  12. package/dist/actions/file.d.ts +1 -1
  13. package/dist/actions/index.d.ts +1 -1
  14. package/dist/actions/inspect.d.ts +1 -1
  15. package/dist/actions/introspect.d.ts +1 -1
  16. package/dist/actions/make-model.d.ts +1 -1
  17. package/dist/actions/migrate-generate.d.ts +1 -1
  18. package/dist/actions/migrate-rollback.d.ts +1 -1
  19. package/dist/actions/migrate-status.d.ts +1 -1
  20. package/dist/actions/migrate.d.ts +1 -1
  21. package/dist/actions/model-show.d.ts +1 -1
  22. package/dist/actions/ping.d.ts +1 -1
  23. package/dist/actions/query-explain-all.d.ts +1 -1
  24. package/dist/actions/relation-diagram.d.ts +1 -1
  25. package/dist/actions/seed.d.ts +1 -1
  26. package/dist/actions/sql.d.ts +1 -1
  27. package/dist/actions/unsafe.d.ts +1 -1
  28. package/dist/actions/validate.d.ts +1 -1
  29. package/dist/actions/wait-ready.d.ts +1 -1
  30. package/dist/bin/cli.js +25785 -0
  31. package/dist/browser.d.ts +118 -44
  32. package/dist/client.d.ts +22 -56
  33. package/dist/config.d.ts +16 -3
  34. package/dist/db.d.ts +5 -4
  35. package/dist/drivers/dynamodb.d.ts +3 -13
  36. package/dist/drivers/index.d.ts +2 -1
  37. package/dist/drivers/mysql.d.ts +3 -9
  38. package/dist/drivers/postgres.d.ts +3 -9
  39. package/dist/drivers/sqlite.d.ts +3 -9
  40. package/dist/dynamodb/client.d.ts +1 -5
  41. package/dist/dynamodb/index.d.ts +7 -28
  42. package/dist/dynamodb/migration-driver.d.ts +2 -23
  43. package/dist/dynamodb/migration-tracker.d.ts +4 -6
  44. package/dist/dynamodb/migrations.d.ts +4 -1
  45. package/dist/dynamodb/model.d.ts +5 -13
  46. package/dist/dynamodb-client.d.ts +3 -23
  47. package/dist/dynamodb-single-table.d.ts +22 -26
  48. package/dist/dynamodb-tooling-adapter.d.ts +2 -33
  49. package/dist/factory.d.ts +3 -3
  50. package/dist/index.d.ts +24 -1
  51. package/dist/loader.d.ts +1 -1
  52. package/dist/meta.d.ts +1 -1
  53. package/dist/migrations.d.ts +4 -4
  54. package/dist/model.d.ts +61 -3
  55. package/dist/orm.d.ts +130 -82
  56. package/dist/schema.d.ts +32 -25
  57. package/dist/seeder.d.ts +3 -1
  58. package/dist/src/browser.js +824 -0
  59. package/dist/src/dynamodb/index.js +2301 -0
  60. package/dist/{index.js → src/index.js} +21466 -20710
  61. package/dist/type-inference.d.ts +326 -0
  62. package/dist/types.d.ts +1 -5
  63. package/package.json +3 -7
@@ -3,7 +3,7 @@ export declare interface DialectDriver {
3
3
  createEnumType: (enumTypeName: string, values: string[]) => string
4
4
  createTable: (table: TablePlan) => string
5
5
  createIndex: (tableName: string, index: IndexPlan) => string
6
- addForeignKey: (tableName: string, columnName: string, refTable: string, refColumn: string) => string
6
+ addForeignKey: (tableName: string, columnName: string, refTable: string, refColumn: string, onDelete?: string, onUpdate?: string) => string
7
7
  addColumn: (tableName: string, column: ColumnPlan) => string
8
8
  modifyColumn: (tableName: string, column: ColumnPlan) => string
9
9
  dropTable: (tableName: string) => string
@@ -15,15 +15,10 @@ export declare interface DialectDriver {
15
15
  recordMigrationQuery: () => string
16
16
  }
17
17
  export declare class SQLiteDriver implements DialectDriver {
18
- private quoteIdentifier(id: string): string;
19
- private getColumnType(column: ColumnPlan): string;
20
- private getPrimaryKeyType(column: ColumnPlan): string;
21
- private getAutoIncrementClause(column: ColumnPlan): string;
22
- private getDefaultValue(column: ColumnPlan): string;
23
18
  createEnumType(_enumTypeName: string, _values: string[]): string;
24
19
  createTable(table: TablePlan): string;
25
20
  createIndex(tableName: string, index: IndexPlan): string;
26
- addForeignKey(tableName: string, columnName: string, refTable: string, refColumn: string): string;
21
+ addForeignKey(tableName: string, columnName: string, refTable: string, refColumn: string, onDelete?: string, onUpdate?: string): string;
27
22
  addColumn(tableName: string, column: ColumnPlan): string;
28
23
  modifyColumn(tableName: string, column: ColumnPlan): string;
29
24
  dropTable(tableName: string): string;
@@ -33,5 +28,4 @@ export declare class SQLiteDriver implements DialectDriver {
33
28
  createMigrationsTable(): string;
34
29
  getExecutedMigrationsQuery(): string;
35
30
  recordMigrationQuery(): string;
36
- private renderColumn(column: ColumnPlan): string;
37
- }
31
+ }
@@ -154,11 +154,7 @@ export declare interface DynamoDBDeleteItemOutput {
154
154
  * Uses AWS Signature V4 and native fetch for zero-dependency DynamoDB access.
155
155
  */
156
156
  export declare class DynamoDBClient {
157
- private config: DynamoDBClientConfig;
158
- private endpoint: string;
159
- private credentials: DynamoDBCredentials;
160
157
  constructor(config: DynamoDBClientConfig);
161
- private execute(operation: string, input: any): Promise<any>;
162
158
  query(input: DynamoDBQueryInput): Promise<DynamoDBQueryOutput>;
163
159
  scan(input: DynamoDBScanInput): Promise<DynamoDBQueryOutput>;
164
160
  getItem(input: DynamoDBGetItemInput): Promise<DynamoDBGetItemOutput>;
@@ -175,4 +171,4 @@ export declare class DynamoDBClient {
175
171
  updateTable(input: any): Promise<any>;
176
172
  updateTimeToLive(input: any): Promise<any>;
177
173
  describeTimeToLive(tableName: string): Promise<any>;
178
- }
174
+ }
@@ -1,4 +1,5 @@
1
- import type { DynamoDBConfig, DynamoDBDriver, SingleTableEntityMapping, } from '../drivers/dynamodb';
1
+ import type { DynamoDBConfig, DynamoDBDriver, SingleTableEntityMapping } from '../drivers/dynamodb';
2
+ // Re-export types from driver
2
3
  export type {
3
4
  DynamoDBConfig,
4
5
  DynamoDBDriver,
@@ -82,28 +83,12 @@ export declare interface DynamoDBQueryResult<T = any> {
82
83
  * Entity-centric query builder for DynamoDB
83
84
  */
84
85
  export declare class EntityQueryBuilder<T = any> {
85
- private driver: DynamoDBDriver;
86
- private client: any;
87
- private tableName: string;
88
- private pkAttribute: string;
89
- private skAttribute: string;
90
- private entityTypeAttr: string;
91
- private delimiter: string;
92
- private _entityType?: string;
93
- private _pkValue?: string;
94
- private _skCondition?: { type: 'eq' | 'begins_with' | 'between' | 'lt' | 'lte' | 'gt' | 'gte', value: string, value2?: string };
95
- private _indexName?: string;
96
- private _projectionAttrs: string[];
97
- private _filterConditions: Array<{ attribute: string, operator: string, value?: any, values?: any[] }>;
98
- private _limitValue?: number;
99
- private _scanForward: boolean;
100
- private _consistentRead: boolean;
101
- private _startKey?: Record<string, any>;
102
86
  constructor(driver: DynamoDBDriver, client: any, tableName: string, config: { pkAttribute: string, skAttribute: string, entityTypeAttribute: string, keyDelimiter: string });
103
87
  entity(entityType: string): this;
104
88
  pk(value: string): this;
89
+ get sk(): SortKeyBuilder;
105
90
  index(indexName: string): this;
106
- project(attributes: string[]): this;
91
+ project(...attributes: string[]): this;
107
92
  filter(attribute: string, operator: string, value?: any): this;
108
93
  where(attribute: string, value: any): this;
109
94
  whereIn(attribute: string, values: any[]): this;
@@ -122,14 +107,6 @@ export declare class EntityQueryBuilder<T = any> {
122
107
  * DynamoDB client with entity-centric API
123
108
  */
124
109
  declare class DynamoClient {
125
- private driver?: DynamoDBDriver;
126
- private client?: any;
127
- private tableName: string;
128
- private pkAttribute: string;
129
- private skAttribute: string;
130
- private entityTypeAttr: string;
131
- private delimiter: string;
132
- private entityMappings: Map<string, SingleTableEntityMapping>;
133
110
  connection(config: DynamoConnectionConfig): this;
134
111
  setClient(client: any): this;
135
112
  registerEntity(mapping: SingleTableEntityMapping): this;
@@ -138,8 +115,10 @@ declare class DynamoClient {
138
115
  transactWrite(operations: TransactWriteOperation[]): Promise<void>;
139
116
  getDriver(): DynamoDBDriver | undefined;
140
117
  }
118
+ // Re-export Model and client
141
119
  export { Model, configureModels } from './model';
142
120
  export { DynamoDBClient, createClient } from './client';
121
+ // Re-export migrations
143
122
  export {
144
123
  DynamoDBMigrationDriver,
145
124
  createMigrationDriver,
@@ -153,4 +132,4 @@ export {
153
132
  hashTableDefinition,
154
133
  isDefinitionEqual,
155
134
  } from './migrations';
156
- export { DynamoDBMigrationTracker, MIGRATIONS_TABLE } from './migration-tracker';
135
+ export { DynamoDBMigrationTracker, MIGRATIONS_TABLE } from './migration-tracker';
@@ -1,8 +1,5 @@
1
- import { DynamoDBClient } from './client';
2
- import { DynamoDBMigrationTracker } from './migration-tracker';
3
1
  import type { DynamoDBClientConfig } from './client';
4
- import type { DynamoDBMigrationPlan, DynamoDBMigrationOperation, DynamoDBMigrationState } from './migrations';
5
- import type { DynamoDBTableDefinition, DynamoDBGlobalSecondaryIndex } from '../drivers/dynamodb';
2
+ import type { DynamoDBMigrationPlan, DynamoDBMigrationState } from './migrations';
6
3
  /**
7
4
  * Create a migration driver instance
8
5
  */
@@ -29,27 +26,9 @@ export declare interface MigrationResult {
29
26
  * Executes DynamoDB schema migrations
30
27
  */
31
28
  export declare class DynamoDBMigrationDriver {
32
- private client: DynamoDBClient;
33
- private tracker: DynamoDBMigrationTracker;
34
- private config: MigrationDriverConfig;
35
29
  constructor(config: MigrationDriverConfig);
36
30
  execute(plan: DynamoDBMigrationPlan): Promise<MigrationResult>;
37
- private executeOperation(op: DynamoDBMigrationOperation): Promise<void>;
38
- private createTable(definition: DynamoDBTableDefinition): Promise<void>;
39
- private deleteTable(tableName: string): Promise<void>;
40
- private addGSI(tableName: string, gsi: DynamoDBGlobalSecondaryIndex): Promise<void>;
41
- private deleteGSI(tableName: string, indexName: string): Promise<void>;
42
- private updateTTL(tableName: string, ttlAttribute: string | null, enabled: boolean): Promise<void>;
43
- private updateBillingMode(tableName: string, billingMode: 'PAY_PER_REQUEST' | 'PROVISIONED', provisionedThroughput?: { readCapacityUnits: number; writeCapacityUnits: number }): Promise<void>;
44
- private enableStream(tableName: string, viewType: string): Promise<void>;
45
- private disableStream(tableName: string): Promise<void>;
46
- private executeUpdateTable(input: any): Promise<void>;
47
- private executeUpdateTimeToLive(input: any): Promise<void>;
48
- private waitForTableActive(tableName: string, maxAttempts?: number): Promise<void>;
49
- private waitForGSIActive(tableName: string, indexName: string, maxAttempts?: number): Promise<void>;
50
31
  migrateModel(ModelClass: any): Promise<MigrationResult>;
51
32
  migrateModels(models: any[]): Promise<MigrationResult[]>;
52
33
  getStatus(): Promise<Map<string, DynamoDBMigrationState | null>>;
53
- private tableInfoToDefinition(tableInfo: any): DynamoDBTableDefinition;
54
- private log(args: any[]): void;
55
- }
34
+ }
@@ -5,18 +5,16 @@ import type { DynamoDBTableDefinition } from '../drivers/dynamodb';
5
5
  * Tracks and manages DynamoDB migration state
6
6
  */
7
7
  export declare class DynamoDBMigrationTracker {
8
- private client: DynamoDBClient;
9
- private initialized: boolean;
10
8
  constructor(client: DynamoDBClient);
11
9
  ensureMigrationsTable(): Promise<void>;
12
- private waitForTableActive(tableName: string, maxAttempts?: number): Promise<void>;
13
10
  getLatestState(tableName: string): Promise<DynamoDBMigrationState | null>;
14
11
  getHistory(tableName: string): Promise<DynamoDBMigrationState[]>;
15
12
  recordMigration(tableName: string, definition: DynamoDBTableDefinition, version?: number): Promise<DynamoDBMigrationState>;
16
13
  listTrackedTables(): Promise<string[]>;
17
14
  hasMigrations(tableName: string): Promise<boolean>;
18
15
  deleteMigrationHistory(tableName: string): Promise<void>;
19
- private marshallState(state: DynamoDBMigrationState, pk: string, sk: string): Record<string, any>;
20
- private unmarshallState(item: Record<string, any>): DynamoDBMigrationState;
21
16
  }
22
- export { MIGRATIONS_TABLE };
17
+ // ============================================================================
18
+ // Exports
19
+ // ============================================================================
20
+ export { MIGRATIONS_TABLE };
@@ -1,4 +1,7 @@
1
1
  import type { DynamoDBTableDefinition, DynamoDBGlobalSecondaryIndex, DynamoDBAttributeDefinition } from '../drivers/dynamodb';
2
+ // ============================================================================
3
+ // Exports
4
+ // ============================================================================
2
5
  export type {
3
6
  DynamoDBTableDefinition,
4
7
  DynamoDBGlobalSecondaryIndex,
@@ -110,4 +113,4 @@ export type DynamoDBMigrationOperationType = | 'CREATE_TABLE'
110
113
  | 'UPDATE_BILLING_MODE'
111
114
  | 'UPDATE_THROUGHPUT'
112
115
  | 'ENABLE_STREAM'
113
- | 'DISABLE_STREAM'
116
+ | 'DISABLE_STREAM';
@@ -81,16 +81,6 @@ export declare abstract class Model {
81
81
  // Query Builder Implementation
82
82
  // ============================================================================
83
83
  declare class ModelQueryBuilderImpl<T extends Model> implements ModelQueryBuilder<T> {
84
- private ModelClass: typeof Model;
85
- private _pkValue?: string;
86
- private _skCondition?: { type: string, value: any, value2?: any };
87
- private _indexName?: string;
88
- private _filterConditions: Array<{ attribute: string, operator: string, value?: any, values?: any[] }>;
89
- private _projectionAttrs: string[];
90
- private _limitValue?: number;
91
- private _scanForward: boolean;
92
- private _consistentReadValue: boolean;
93
- private _startKey?: Record<string, any>;
94
84
  constructor(ModelClass: typeof Model);
95
85
  wherePk(value: string): this;
96
86
  where(attribute: string, operatorOrValue: any, value?: any): this;
@@ -101,14 +91,16 @@ declare class ModelQueryBuilderImpl<T extends Model> implements ModelQueryBuilde
101
91
  whereNotExists(attribute: string): this;
102
92
  orderBy(direction: 'asc' | 'desc'): this;
103
93
  limit(count: number): this;
104
- select(attributes: string[]): this;
94
+ select(...attributes: string[]): this;
105
95
  index(indexName: string): this;
106
96
  consistentRead(): this;
107
97
  startFrom(key: Record<string, any>): this;
108
- private buildRequest(): Record<string, any>;
109
98
  get(): Promise<T[]>;
110
99
  first(): Promise<T | null>;
111
100
  count(): Promise<number>;
112
101
  paginate(pageSize: number, lastKey?: Record<string, any>): Promise<{ items: T[], lastKey?: Record<string, any> }>;
113
102
  }
114
- export { DynamoDBClient, createClient } from './client';
103
+ // ============================================================================
104
+ // Re-exports for convenience
105
+ // ============================================================================
106
+ export { DynamoDBClient, createClient } from './client';
@@ -1,4 +1,4 @@
1
- import type { DynamoDBComparisonOperator, DynamoDBCondition, DynamoDBConfig, DynamoDBDriver, DynamoDBPutItemParams, DynamoDBQueryParams, DynamoDBScanParams, DynamoDBUpdateItemParams, SingleTableEntityMapping, } from './drivers/dynamodb';
1
+ import type { DynamoDBComparisonOperator, DynamoDBConfig, DynamoDBDriver, DynamoDBQueryParams, DynamoDBScanParams, SingleTableEntityMapping } from './drivers/dynamodb';
2
2
  /**
3
3
  * Create a DynamoDB query builder
4
4
  */
@@ -47,18 +47,6 @@ export declare interface DynamoDBClientMethods {
47
47
  * Fluent interface for building DynamoDB queries
48
48
  */
49
49
  export declare class DynamoDBQueryBuilder<T = any> {
50
- private driver: DynamoDBDriver;
51
- private client: any;
52
- private tableName: string;
53
- private indexName?: string;
54
- private entityType?: string;
55
- private keyConditions: DynamoDBCondition[];
56
- private filterConditions: DynamoDBCondition[];
57
- private projectionAttrs: string[];
58
- private limitValue?: number;
59
- private scanForward: boolean;
60
- private consistentReadValue: boolean;
61
- private startKey?: Record<string, any>;
62
50
  constructor(options: DynamoDBQueryBuilderOptions);
63
51
  table(tableName: string): this;
64
52
  index(indexName: string): this;
@@ -80,7 +68,7 @@ export declare class DynamoDBQueryBuilder<T = any> {
80
68
  whereExists(attribute: string): this;
81
69
  whereNotExists(attribute: string): this;
82
70
  whereIn(attribute: string, values: any[]): this;
83
- select(attributes: string[]): this;
71
+ select(...attributes: string[]): this;
84
72
  limit(count: number): this;
85
73
  ascending(): this;
86
74
  descending(): this;
@@ -101,14 +89,6 @@ export declare class DynamoDBQueryBuilder<T = any> {
101
89
  * DynamoDB Item Builder for Put/Update operations
102
90
  */
103
91
  export declare class DynamoDBItemBuilder<T = any> {
104
- private driver: DynamoDBDriver;
105
- private client: any;
106
- private tableName: string;
107
- private itemData: Record<string, any>;
108
- private keyData: Record<string, any>;
109
- private updateExpressions: DynamoDBUpdateItemParams['updateExpressions'];
110
- private conditionExpr?: string;
111
- private returnValuesOption: DynamoDBPutItemParams['returnValues'];
112
92
  constructor(options: DynamoDBQueryBuilderOptions);
113
93
  table(tableName: string): this;
114
94
  key(key: Record<string, any>): this;
@@ -131,4 +111,4 @@ export declare class DynamoDBItemBuilder<T = any> {
131
111
  update(): Promise<T | undefined>;
132
112
  delete(): Promise<T | undefined>;
133
113
  get(): Promise<T | undefined>;
134
- }
114
+ }
@@ -1,6 +1,5 @@
1
- import { DynamoDBQueryBuilder } from './dynamodb-client';
2
1
  import type { DynamoDBQueryBuilderOptions } from './dynamodb-client';
3
- import type { DynamoDBTableDefinition, } from './drivers/dynamodb';
2
+ import type { DynamoDBTableDefinition } from './drivers/dynamodb';
4
3
  /**
5
4
  * Create a single table manager
6
5
  */
@@ -11,6 +10,21 @@ export declare function createSingleTableManager(config: SingleTableConfig): Sin
11
10
  export declare function createRepository<T extends Record<string, any>>(manager: SingleTableManager, entityName: string, options: DynamoDBQueryBuilderOptions): SingleTableRepository<T>;
12
11
  /**
13
12
  * Common single table design patterns
13
+ * @defaultValue
14
+ * ```ts
15
+ * {
16
+ * simpleEntity: (entityName: string, idField?: string) => unknown,
17
+ * oneToMany: (parentEntity: string,
18
+ * childEntity: string,
19
+ * parentIdField?: string,
20
+ * childIdField?: string,) => unknown,
21
+ * manyToMany: (entityName: string,
22
+ * relationName: string,
23
+ * idField?: string,
24
+ * relatedIdField?: string,) => unknown,
25
+ * hierarchical: (entityName: string, rootIdField?: string, pathField?: string) => unknown
26
+ * }
27
+ * ```
14
28
  */
15
29
  export declare const SingleTablePatterns: {
16
30
  /**
@@ -18,26 +32,26 @@ export declare const SingleTablePatterns: {
18
32
  * PK: USER#<userId>
19
33
  * SK: PROFILE for metadata, or related items like ORDER#<orderId>
20
34
  */
21
- simpleEntity: (entityName: string, idField: string?) => any;
35
+ simpleEntity: (entityName: string, idField?: string) => unknown;
22
36
  /**
23
37
  * One-to-many relationship pattern
24
38
  * Parent: PK=PARENT#<parentId>, SK=METADATA
25
39
  * Child: PK=PARENT#<parentId>, SK=CHILD#<childId>
26
40
  */
27
- oneToMany: ( parentEntity: string, childEntity: string, parentIdField: string?, childIdField: string?, ) => unknown;
41
+ oneToMany: (parentEntity: string, childEntity: string, parentIdField?: string, childIdField?: string,) => unknown;
28
42
  /**
29
43
  * Many-to-many relationship pattern using adjacency list
30
44
  * Entity: PK=ENTITY#<entityId>, SK=METADATA
31
45
  * Relationship: PK=ENTITY#<entityId>, SK=RELATED#<relatedId>
32
46
  * Inverse: PK=ENTITY#<relatedId>, SK=RELATED#<entityId> (via GSI)
33
47
  */
34
- manyToMany: ( entityName: string, relationName: string, idField: string?, relatedIdField: string?, ) => unknown;
48
+ manyToMany: (entityName: string, relationName: string, idField?: string, relatedIdField?: string,) => unknown;
35
49
  /**
36
50
  * Hierarchical data pattern (e.g., org chart, file system)
37
51
  * PK: ROOT#<rootId>
38
52
  * SK: PATH#<path> (e.g., PATH#/folder1/folder2/file)
39
53
  */
40
- hierarchical: (entityName: string, rootIdField: string?, pathField: string?) => any
54
+ hierarchical: (entityName: string, rootIdField?: string, pathField?: string) => unknown
41
55
  };
42
56
  /**
43
57
  * Entity definition for single table design
@@ -48,11 +62,8 @@ export declare interface SingleTableEntity {
48
62
  skPattern: string
49
63
  keyFields: string[]
50
64
  indexes?: {
51
- /** GSI name */
52
65
  name: string
53
- /** Pattern for GSI partition key */
54
66
  pkPattern: string
55
- /** Pattern for GSI sort key */
56
67
  skPattern?: string
57
68
  }[]
58
69
  schema?: Record<string, {
@@ -82,11 +93,6 @@ export declare interface SingleTableConfig {
82
93
  * single table design patterns.
83
94
  */
84
95
  export declare class SingleTableManager {
85
- private config: SingleTableConfig;
86
- private entities: Map<string, SingleTableEntity>;
87
- private pkAttribute: string;
88
- private skAttribute: string;
89
- private typeAttribute: string;
90
96
  constructor(config: SingleTableConfig);
91
97
  getEntity(name: string): SingleTableEntity | undefined;
92
98
  registerEntity(entity: SingleTableEntity): void;
@@ -97,7 +103,6 @@ export declare class SingleTableManager {
97
103
  parseItem<T = any>(item: Record<string, any>): { type: string, data: T } | undefined;
98
104
  getEntityPrefix(entityName: string): string;
99
105
  generateTableDefinition(): DynamoDBTableDefinition;
100
- private interpolatePattern(pattern: string, values: Record<string, any>): string;
101
106
  }
102
107
  /**
103
108
  * Single Table Entity Repository
@@ -105,9 +110,6 @@ export declare class SingleTableManager {
105
110
  * Provides CRUD operations for a specific entity type in a single table design.
106
111
  */
107
112
  export declare class SingleTableRepository<T extends Record<string, any>> {
108
- private manager: SingleTableManager;
109
- private entityName: string;
110
- private options: DynamoDBQueryBuilderOptions;
111
113
  constructor(manager: SingleTableManager, entityName: string, options: DynamoDBQueryBuilderOptions);
112
114
  create(data: T): Promise<T>;
113
115
  get(keyData: Partial<T>): Promise<T | undefined>;
@@ -120,21 +122,15 @@ export declare class SingleTableRepository<T extends Record<string, any>> {
120
122
  * Query builder for single table entity queries
121
123
  */
122
124
  export declare class SingleTableQueryBuilder<T> {
123
- private manager: SingleTableManager;
124
- private entityName: string;
125
- private options: DynamoDBQueryBuilderOptions;
126
- private builder: DynamoDBQueryBuilder<Record<string, any>>;
127
- private pkValue?: string;
128
- private skConditions: { operator: string, value: any, values?: any[] }[];
129
125
  constructor(manager: SingleTableManager, entityName: string, options: DynamoDBQueryBuilderOptions);
130
126
  wherePartitionKey(pkData: Record<string, any>): this;
131
127
  whereSortKey(skData: Record<string, any>): this;
132
128
  whereSortKeyBeginsWith(prefix: string): this;
133
129
  useIndex(indexName: string, pkData: Record<string, any>): this;
134
130
  where(attribute: string, operator: any, value?: any): this;
135
- select(attributes: string[]): this;
131
+ select(...attributes: string[]): this;
136
132
  limit(count: number): this;
137
133
  descending(): this;
138
134
  execute(): Promise<T[]>;
139
135
  first(): Promise<T | undefined>;
140
- }
136
+ }
@@ -1,8 +1,6 @@
1
1
  import { DynamoDBItemBuilder, DynamoDBQueryBuilder } from './dynamodb-client';
2
2
  import { SingleTableManager, SingleTableRepository } from './dynamodb-single-table';
3
- import type { DynamoDBDriver, SingleTableEntityMapping } from './drivers/dynamodb';
4
- import type { DynamoDBQueryBuilderOptions } from './dynamodb-client';
5
- import type { SingleTableConfig, SingleTableEntity } from './dynamodb-single-table';
3
+ import type { DynamoDBDriver } from './drivers/dynamodb';
6
4
  /**
7
5
  * Resolve key pattern placeholders with actual values
8
6
  */
@@ -41,19 +39,6 @@ export declare function generateAccessPatterns(model: ParsedModel): AccessPatter
41
39
  * Standalone function for creating entity patterns
42
40
  */
43
41
  export declare function stacksModelToEntity(model: { name: string; primaryKey?: string }, delimiter?: string): { name: string; pkPattern: string; skPattern: string };
44
- /**
45
- * DynamoDB Tooling Adapter
46
- *
47
- * This module provides integration between bun-query-builder's DynamoDB driver
48
- * and the dynamodb-tooling ORM. It bridges the gap between:
49
- *
50
- * 1. Stacks model definitions (from dynamodb-tooling)
51
- * 2. Single table design patterns (from dynamodb-tooling)
52
- * 3. bun-query-builder's DynamoDB query builder
53
- *
54
- * IMPORTANT: This adapter EXTENDS dynamodb-tooling rather than duplicating it.
55
- * All model parsing, key generation, and entity transformation is delegated to dynamodb-tooling.
56
- */
57
42
  /**
58
43
  * Access pattern definition for DynamoDB single-table design
59
44
  */
@@ -191,11 +176,6 @@ export declare interface DynamoDBToolingConfig {
191
176
  * All model parsing and transformation is delegated to dynamodb-tooling.
192
177
  */
193
178
  export declare class DynamoDBToolingAdapter {
194
- private config: DynamoDBToolingConfig;
195
- private driver: DynamoDBDriver;
196
- private singleTableManager: SingleTableManager;
197
- private models: Map<string, ParsedModel>;
198
- private queryBuilderOptions: DynamoDBQueryBuilderOptions;
199
179
  constructor(config: DynamoDBToolingConfig);
200
180
  setClient(client: any): this;
201
181
  discoverModels(): Promise<ParsedModel[]>;
@@ -214,15 +194,4 @@ export declare class DynamoDBToolingAdapter {
214
194
  getSingleTableManager(): SingleTableManager;
215
195
  generateTableDefinition(): any;
216
196
  generateAccessPatterns(modelName: string): AccessPattern[];
217
- private parseWithTooling(model: StacksModel): ParsedModel;
218
- private parseAttributes(model: StacksModel): ParsedModel['attributes'];
219
- private inferDynamoDBType(def: any): 'S' | 'N' | 'B' | 'BOOL' | 'NULL' | 'M' | 'L' | 'SS' | 'NS' | 'BS';
220
- private parseRelationships(model: StacksModel, primaryKey: string): ParsedModel['relationships'];
221
- private deriveGSIKeyPatterns(entityType: string, primaryKey: string, delimiter: string, relationships: ParsedModel['relationships']): Record<string, string>;
222
- private deriveAccessPatterns(modelName: string, entityType: string, primaryKey: string, relationships: ParsedModel['relationships']): AccessPattern[];
223
- private toSingleTableEntity(model: ParsedModel): SingleTableEntity;
224
- private extractKeyFields(pattern: string): string[];
225
- private extractGSIPatterns(keyPatterns: ParsedModel['keyPatterns']): SingleTableEntity['indexes'];
226
- private toEntityMapping(model: ParsedModel): SingleTableEntityMapping;
227
- private buildGSIConfig(): SingleTableConfig['indexes'];
228
- }
197
+ }
package/dist/factory.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { DatabaseSchema, ModelRecord } from './schema';
2
2
  export declare function buildDatabaseSchema<MRecord extends ModelRecord>(models: MRecord): BuildDatabaseSchema<MRecord>;
3
- export type BuildDatabaseSchema<MRecord extends ModelRecord> = DatabaseSchema<MRecord>
4
- export type TablesFromSchema<DB> = keyof DB & string
3
+ export type BuildDatabaseSchema<MRecord extends ModelRecord> = DatabaseSchema<MRecord>;
4
+ export type TablesFromSchema<DB> = keyof DB & string;
5
5
  export type ColumnsOf<DB, TTable extends keyof DB & string> = DB[TTable] extends { columns: infer C }
6
6
  ? C
7
- : never
7
+ : never;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,26 @@
1
+ // Resolve ambiguous re-exports by explicitly choosing which module's version to use
1
2
  export type { WhereOperator } from './browser';
2
3
  export type { ModelQueryBuilder } from './dynamodb';
3
4
  export type { ColumnName } from './client';
5
+ // Re-export the type-inference version of InferRelationNames (supports wrapped models)
6
+ // to resolve the ambiguity with orm.ts's InferRelationNames (which takes raw definitions)
7
+ export type { InferRelationNames } from './type-inference';
8
+ // Explicit re-exports for type inference utilities
9
+ export type {
10
+ InferAttributes,
11
+ InferFillableAttributes,
12
+ InferPrimaryKey,
13
+ InferTableName,
14
+ InferNumericColumns,
15
+ InferColumnNames,
16
+ InferHiddenKeys,
17
+ InferGuardedKeys,
18
+ ModelRow,
19
+ ModelRowLoose,
20
+ ModelCreateData,
21
+ ModelCreateDataLoose,
22
+ RelationCardinality,
23
+ } from './type-inference';
4
24
  export * from './actions';
5
25
  export * from './browser';
6
26
  export * from './client';
@@ -18,5 +38,8 @@ export * from './migrations';
18
38
  export * from './orm';
19
39
  export * from './schema';
20
40
  export * from './seeder';
41
+ export * from './type-inference';
21
42
  export * from './types';
22
- export { type ModelDefinition, defineModel } from './model';
43
+ export { type ModelDefinition, defineModel } from './model';
44
+ // Explicit re-exports for model registry functions
45
+ export { getModel, getAllModels, getModelRegistry, hasModel, clearModelRegistry } from './model';
package/dist/loader.d.ts CHANGED
@@ -3,4 +3,4 @@ export declare function loadModels(options: LoadModelsOptions): Promise<ModelRec
3
3
  export declare interface LoadModelsOptions {
4
4
  cwd?: string
5
5
  modelsDir: string
6
- }
6
+ }
package/dist/meta.d.ts CHANGED
@@ -18,4 +18,4 @@ export declare interface SchemaMeta {
18
18
  morphedByMany?: Record<string, string>
19
19
  }>
20
20
  scopes?: Record<string, Record<string, (qb: any, value?: any) => any>>
21
- }
21
+ }
@@ -1,4 +1,4 @@
1
- import type { ModelRecord } from './schema';
1
+ import type { ModelRecord, OnForeignKeyAction } from './schema';
2
2
  import type { SupportedDialect } from './types';
3
3
  export declare function buildMigrationPlan(models: ModelRecord, options: InferenceOptions): MigrationPlan;
4
4
  export declare function generateSql(plan: MigrationPlan): string[];
@@ -35,7 +35,7 @@ export declare interface ColumnPlan {
35
35
  isNullable: boolean
36
36
  hasDefault: boolean
37
37
  defaultValue?: PrimitiveDefault
38
- references?: { table: string, column: string }
38
+ references?: { table: string, column: string, onDelete?: OnForeignKeyAction, onUpdate?: OnForeignKeyAction }
39
39
  enumValues?: string[]
40
40
  }
41
41
  export declare interface IndexPlan {
@@ -55,7 +55,7 @@ export declare interface MigrationPlan {
55
55
  export declare interface InferenceOptions {
56
56
  dialect: SupportedDialect
57
57
  }
58
- export type PrimitiveDefault = string | number | boolean | bigint | Date
58
+ export type PrimitiveDefault = string | number | boolean | bigint | Date;
59
59
  export type NormalizedColumnType = | 'string'
60
60
  | 'text'
61
61
  | 'boolean'
@@ -67,4 +67,4 @@ export type NormalizedColumnType = | 'string'
67
67
  | 'date'
68
68
  | 'datetime'
69
69
  | 'json'
70
- | 'enum'
70
+ | 'enum';
package/dist/model.d.ts CHANGED
@@ -1,10 +1,68 @@
1
+ import { createBrowserModel, type BrowserModelDefinition } from './browser';
2
+ // Re-export the browser model types for convenience
1
3
  export type { BrowserModelDefinition as ModelDefinition };
4
+ /**
5
+ * Look up a registered model by name.
6
+ *
7
+ * @param name - The model name (e.g., 'User', 'Trail')
8
+ * @returns The model instance, or undefined if not registered
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const User = getModel('User')
13
+ * if (User) {
14
+ * const users = await User.all()
15
+ * }
16
+ * ```
17
+ */
18
+ export declare function getModel(name: string): ReturnType<typeof createBrowserModel> | undefined;
19
+ /**
20
+ * Get all registered models as an array.
21
+ *
22
+ * @returns Array of all registered model instances
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const models = getAllModels()
27
+ * for (const model of models) {
28
+ * console.log(model.getTable())
29
+ * }
30
+ * ```
31
+ */
32
+ export declare function getAllModels(): ReturnType<typeof createBrowserModel>[];
33
+ /**
34
+ * Get all registered models as a name-to-model map.
35
+ *
36
+ * @returns Record mapping model names to model instances
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const models = getModelRegistry()
41
+ * // { User: UserModel, Trail: TrailModel, ... }
42
+ * ```
43
+ */
44
+ export declare function getModelRegistry(): Record<string, ReturnType<typeof createBrowserModel>>;
45
+ /**
46
+ * Check if a model with the given name is registered.
47
+ *
48
+ * @param name - The model name to check
49
+ * @returns true if the model is registered
50
+ */
51
+ export declare function hasModel(name: string): boolean;
52
+ /**
53
+ * Clear all registered models. Primarily useful for testing.
54
+ */
55
+ export declare function clearModelRegistry(): void;
2
56
  /**
3
57
  * Define an isomorphic model that works in both server and browser.
4
58
  *
5
59
  * In the browser, this creates a model that uses fetch() to call your API.
6
- * On the server, this returns the definition for ORM generation AND provides
7
- * query methods that work directly with the database.
60
+ * On the server, this uses the dynamic ORM (createModel) to provide fully
61
+ * typed query methods that work directly with the database — no code
62
+ * generation needed.
63
+ *
64
+ * The model is automatically registered in the global model registry,
65
+ * making it available via `getModel(name)` and `getAllModels()`.
8
66
  *
9
67
  * @param definition - The model definition
10
68
  * @returns An isomorphic model with query methods
@@ -24,4 +82,4 @@ export declare function defineModel<const TDef extends BrowserModelDefinition>(d
24
82
  * registerBrowserModels({ Trail, Activity })
25
83
  * ```
26
84
  */
27
- export declare function registerBrowserModels(models: Record<string, unknown>): void;
85
+ export declare function registerBrowserModels(models: Record<string, unknown>): void;