bun-query-builder 0.1.10 → 0.1.12
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/LICENSE.md +21 -0
- package/README.md +489 -0
- package/dist/actions/migrate.d.ts +17 -7
- package/dist/browser.d.ts +288 -0
- package/dist/client.d.ts +15 -5
- package/dist/config.d.ts +19 -1
- package/dist/db.d.ts +20 -1
- package/dist/drivers/dynamodb.d.ts +338 -0
- package/dist/drivers/index.d.ts +27 -1
- package/dist/dynamodb/client.d.ts +178 -0
- package/dist/dynamodb/index.d.ts +156 -0
- package/dist/dynamodb/migration-driver.d.ts +55 -0
- package/dist/dynamodb/migration-tracker.d.ts +22 -0
- package/dist/dynamodb/migrations.d.ts +113 -0
- package/dist/dynamodb/model.d.ts +114 -0
- package/dist/dynamodb-client.d.ts +134 -0
- package/dist/dynamodb-single-table.d.ts +140 -0
- package/dist/dynamodb-tooling-adapter.d.ts +228 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.js +11914 -772
- package/dist/model.d.ts +27 -0
- package/dist/orm.d.ts +244 -0
- package/dist/schema.d.ts +2 -1
- package/dist/types.d.ts +18 -1
- package/package.json +18 -5
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { DynamoDBItemBuilder, DynamoDBQueryBuilder } from './dynamodb-client';
|
|
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';
|
|
6
|
+
/**
|
|
7
|
+
* Resolve key pattern placeholders with actual values
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolveKeyPattern(keyPatterns: KeyPatterns, data: Record<string, any>): Record<string, string>;
|
|
10
|
+
/**
|
|
11
|
+
* Parse models from configuration (stub implementation)
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseStacksModels(_config: any): Promise<{ models: Map<string, ParsedModel> }>;
|
|
14
|
+
/**
|
|
15
|
+
* Convert model instance to DynamoDB item format (stub)
|
|
16
|
+
*/
|
|
17
|
+
export declare function toDynamoDBItem(item: Record<string, any>): Record<string, any>;
|
|
18
|
+
/**
|
|
19
|
+
* Convert DynamoDB item to model instance (stub)
|
|
20
|
+
*/
|
|
21
|
+
export declare function toModelInstance<T>(item: Record<string, any>): T;
|
|
22
|
+
/**
|
|
23
|
+
* Marshall a JavaScript object to DynamoDB attribute values (stub)
|
|
24
|
+
*/
|
|
25
|
+
export declare function marshallObject(obj: Record<string, any>): Record<string, any>;
|
|
26
|
+
/**
|
|
27
|
+
* Unmarshall DynamoDB attribute values to a JavaScript object (stub)
|
|
28
|
+
*/
|
|
29
|
+
export declare function unmarshallItem(item: Record<string, any>): Record<string, any>;
|
|
30
|
+
/**
|
|
31
|
+
* Create a DynamoDB Tooling Adapter instance
|
|
32
|
+
*/
|
|
33
|
+
export declare function createDynamoDBToolingAdapter(config: DynamoDBToolingConfig): DynamoDBToolingAdapter;
|
|
34
|
+
/**
|
|
35
|
+
* Generate access patterns for a parsed model
|
|
36
|
+
* Standalone function for use outside the adapter
|
|
37
|
+
*/
|
|
38
|
+
export declare function generateAccessPatterns(model: ParsedModel): AccessPattern[];
|
|
39
|
+
/**
|
|
40
|
+
* Convert a Stacks model definition to a single-table entity pattern
|
|
41
|
+
* Standalone function for creating entity patterns
|
|
42
|
+
*/
|
|
43
|
+
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
|
+
/**
|
|
58
|
+
* Access pattern definition for DynamoDB single-table design
|
|
59
|
+
*/
|
|
60
|
+
export declare interface AccessPattern {
|
|
61
|
+
name: string
|
|
62
|
+
description: string
|
|
63
|
+
entityType: string
|
|
64
|
+
operation: 'get' | 'query' | 'scan'
|
|
65
|
+
index: string | 'main' | 'scan' | 'GSI1' | 'GSI2' | 'GSI3' | 'GSI4' | 'GSI5'
|
|
66
|
+
keyCondition: string
|
|
67
|
+
examplePk: string
|
|
68
|
+
exampleSk?: string
|
|
69
|
+
efficient: boolean
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Parsed attribute definition
|
|
73
|
+
*/
|
|
74
|
+
export declare interface ParsedAttribute {
|
|
75
|
+
name: string
|
|
76
|
+
fillable: boolean
|
|
77
|
+
required: boolean
|
|
78
|
+
nullable: boolean
|
|
79
|
+
unique: boolean
|
|
80
|
+
hidden: boolean
|
|
81
|
+
defaultValue?: any
|
|
82
|
+
cast?: string
|
|
83
|
+
dynamoDbType: 'S' | 'N' | 'B' | 'BOOL' | 'NULL' | 'M' | 'L' | 'SS' | 'NS' | 'BS'
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Parsed relationship definition
|
|
87
|
+
*/
|
|
88
|
+
export declare interface ParsedRelationship {
|
|
89
|
+
type: 'hasOne' | 'hasMany' | 'belongsTo' | 'belongsToMany'
|
|
90
|
+
relatedModel: string
|
|
91
|
+
foreignKey: string
|
|
92
|
+
localKey: string
|
|
93
|
+
pivotEntity?: string
|
|
94
|
+
requiresGsi: boolean
|
|
95
|
+
gsiIndex?: number
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Key patterns for DynamoDB single-table design
|
|
99
|
+
*/
|
|
100
|
+
export declare interface KeyPatterns {
|
|
101
|
+
pk: string
|
|
102
|
+
sk: string
|
|
103
|
+
gsi1pk?: string
|
|
104
|
+
gsi1sk?: string
|
|
105
|
+
gsi2pk?: string
|
|
106
|
+
gsi2sk?: string
|
|
107
|
+
gsi3pk?: string
|
|
108
|
+
gsi3sk?: string
|
|
109
|
+
gsi4pk?: string
|
|
110
|
+
gsi4sk?: string
|
|
111
|
+
gsi5pk?: string
|
|
112
|
+
gsi5sk?: string
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Parsed model definition
|
|
116
|
+
*/
|
|
117
|
+
export declare interface ParsedModel {
|
|
118
|
+
name: string
|
|
119
|
+
entityType: string
|
|
120
|
+
primaryKey: string
|
|
121
|
+
attributes: ParsedAttribute[]
|
|
122
|
+
relationships: ParsedRelationship[]
|
|
123
|
+
keyPatterns: KeyPatterns
|
|
124
|
+
accessPatterns: AccessPattern[]
|
|
125
|
+
traits: Record<string, any>
|
|
126
|
+
hasTimestamps: boolean
|
|
127
|
+
hasSoftDeletes: boolean
|
|
128
|
+
hasUuid: boolean
|
|
129
|
+
hasTtl: boolean
|
|
130
|
+
hasVersioning: boolean
|
|
131
|
+
original: StacksModel
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Stacks model definition (input format)
|
|
135
|
+
*/
|
|
136
|
+
export declare interface StacksModel {
|
|
137
|
+
name: string
|
|
138
|
+
primaryKey?: string
|
|
139
|
+
attributes?: Record<string, {
|
|
140
|
+
fillable?: boolean
|
|
141
|
+
required?: boolean
|
|
142
|
+
nullable?: boolean
|
|
143
|
+
unique?: boolean
|
|
144
|
+
hidden?: boolean
|
|
145
|
+
default?: any
|
|
146
|
+
cast?: string
|
|
147
|
+
validation?: { rule?: string }
|
|
148
|
+
}>
|
|
149
|
+
traits?: {
|
|
150
|
+
useTimestamps?: boolean
|
|
151
|
+
useSoftDeletes?: boolean
|
|
152
|
+
useUuid?: boolean
|
|
153
|
+
useTtl?: boolean
|
|
154
|
+
useVersioning?: boolean
|
|
155
|
+
}
|
|
156
|
+
hasOne?: string[]
|
|
157
|
+
hasMany?: string[]
|
|
158
|
+
belongsTo?: string[]
|
|
159
|
+
belongsToMany?: string[]
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Configuration for dynamodb-tooling integration
|
|
163
|
+
*/
|
|
164
|
+
export declare interface DynamoDBToolingConfig {
|
|
165
|
+
region: string
|
|
166
|
+
endpoint?: string
|
|
167
|
+
credentials?: {
|
|
168
|
+
accessKeyId: string
|
|
169
|
+
secretAccessKey: string
|
|
170
|
+
sessionToken?: string
|
|
171
|
+
}
|
|
172
|
+
tableName: string
|
|
173
|
+
pkAttribute?: string
|
|
174
|
+
skAttribute?: string
|
|
175
|
+
entityTypeAttribute?: string
|
|
176
|
+
keyDelimiter?: string
|
|
177
|
+
modelsPath?: string
|
|
178
|
+
gsiConfig?: {
|
|
179
|
+
gsi1pk?: string
|
|
180
|
+
gsi1sk?: string
|
|
181
|
+
gsi2pk?: string
|
|
182
|
+
gsi2sk?: string
|
|
183
|
+
gsi3pk?: string
|
|
184
|
+
gsi3sk?: string
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* DynamoDB Tooling Adapter
|
|
189
|
+
*
|
|
190
|
+
* Bridges dynamodb-tooling with bun-query-builder's fluent API.
|
|
191
|
+
* All model parsing and transformation is delegated to dynamodb-tooling.
|
|
192
|
+
*/
|
|
193
|
+
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
|
+
constructor(config: DynamoDBToolingConfig);
|
|
200
|
+
setClient(client: any): this;
|
|
201
|
+
discoverModels(): Promise<ParsedModel[]>;
|
|
202
|
+
registerModel(model: StacksModel): ParsedModel;
|
|
203
|
+
registerParsedModel(parsed: ParsedModel): ParsedModel;
|
|
204
|
+
registerModels(models: StacksModel[]): ParsedModel[];
|
|
205
|
+
getModel(name: string): ParsedModel | undefined;
|
|
206
|
+
getAllModels(): ParsedModel[];
|
|
207
|
+
repository<T extends Record<string, any>>(modelName: string): SingleTableRepository<T>;
|
|
208
|
+
query<T = any>(modelName: string): DynamoDBQueryBuilder<T>;
|
|
209
|
+
item<T = any>(modelName: string): DynamoDBItemBuilder<T>;
|
|
210
|
+
buildKey(modelName: string, data: Record<string, any>): { pk: string, sk: string };
|
|
211
|
+
createItem(modelName: string, data: Record<string, any>): Record<string, any>;
|
|
212
|
+
parseItem<T = any>(item: Record<string, any>): { type: string, data: T } | undefined;
|
|
213
|
+
getDriver(): DynamoDBDriver;
|
|
214
|
+
getSingleTableManager(): SingleTableManager;
|
|
215
|
+
generateTableDefinition(): any;
|
|
216
|
+
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
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
|
+
export type { WhereOperator } from './browser';
|
|
2
|
+
export type { ModelQueryBuilder } from './dynamodb';
|
|
3
|
+
export type { ColumnName } from './client';
|
|
1
4
|
export * from './actions';
|
|
5
|
+
export * from './browser';
|
|
2
6
|
export * from './client';
|
|
7
|
+
export * from './model';
|
|
3
8
|
export * from './config';
|
|
4
9
|
export * from './drivers';
|
|
10
|
+
export * from './dynamodb-client';
|
|
11
|
+
export * from './dynamodb-single-table';
|
|
12
|
+
export * from './dynamodb-tooling-adapter';
|
|
13
|
+
export * from './dynamodb';
|
|
5
14
|
export * from './factory';
|
|
6
15
|
export * from './loader';
|
|
7
16
|
export * from './meta';
|
|
8
17
|
export * from './migrations';
|
|
18
|
+
export * from './orm';
|
|
9
19
|
export * from './schema';
|
|
10
20
|
export * from './seeder';
|
|
11
|
-
export * from './types';
|
|
21
|
+
export * from './types';
|
|
22
|
+
export { type ModelDefinition, defineModel } from './model';
|