bun-query-builder 0.1.9 → 0.1.11
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 +290 -0
- package/dist/client.d.ts +5 -3
- package/dist/config.d.ts +20 -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 +11 -1
- package/dist/index.js +9799 -826
- package/dist/model.d.ts +27 -0
- package/dist/orm.d.ts +172 -0
- package/dist/types.d.ts +18 -1
- package/package.json +18 -5
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { DynamoDBClient } from './client';
|
|
2
|
+
import { DynamoDBMigrationTracker } from './migration-tracker';
|
|
3
|
+
import type { DynamoDBClientConfig } from './client';
|
|
4
|
+
import type { DynamoDBMigrationPlan, DynamoDBMigrationOperation, DynamoDBMigrationState } from './migrations';
|
|
5
|
+
import type { DynamoDBTableDefinition, DynamoDBGlobalSecondaryIndex } from '../drivers/dynamodb';
|
|
6
|
+
/**
|
|
7
|
+
* Create a migration driver instance
|
|
8
|
+
*/
|
|
9
|
+
export declare function createMigrationDriver(config: MigrationDriverConfig): DynamoDBMigrationDriver;
|
|
10
|
+
/**
|
|
11
|
+
* Migrate models with default configuration
|
|
12
|
+
*/
|
|
13
|
+
export declare function migrateModels(models: any[], config: MigrationDriverConfig): Promise<MigrationResult[]>;
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Types
|
|
16
|
+
// ============================================================================
|
|
17
|
+
export declare interface MigrationDriverConfig extends DynamoDBClientConfig {
|
|
18
|
+
dryRun?: boolean
|
|
19
|
+
verbose?: boolean
|
|
20
|
+
}
|
|
21
|
+
export declare interface MigrationResult {
|
|
22
|
+
tableName: string
|
|
23
|
+
success: boolean
|
|
24
|
+
operations: string[]
|
|
25
|
+
error?: string
|
|
26
|
+
state?: DynamoDBMigrationState
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Executes DynamoDB schema migrations
|
|
30
|
+
*/
|
|
31
|
+
export declare class DynamoDBMigrationDriver {
|
|
32
|
+
private client: DynamoDBClient;
|
|
33
|
+
private tracker: DynamoDBMigrationTracker;
|
|
34
|
+
private config: MigrationDriverConfig;
|
|
35
|
+
constructor(config: MigrationDriverConfig);
|
|
36
|
+
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
|
+
migrateModel(ModelClass: any): Promise<MigrationResult>;
|
|
51
|
+
migrateModels(models: any[]): Promise<MigrationResult[]>;
|
|
52
|
+
getStatus(): Promise<Map<string, DynamoDBMigrationState | null>>;
|
|
53
|
+
private tableInfoToDefinition(tableInfo: any): DynamoDBTableDefinition;
|
|
54
|
+
private log(args: any[]): void;
|
|
55
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DynamoDBClient } from './client';
|
|
2
|
+
import type { DynamoDBMigrationState } from './migrations';
|
|
3
|
+
import type { DynamoDBTableDefinition } from '../drivers/dynamodb';
|
|
4
|
+
/**
|
|
5
|
+
* Tracks and manages DynamoDB migration state
|
|
6
|
+
*/
|
|
7
|
+
export declare class DynamoDBMigrationTracker {
|
|
8
|
+
private client: DynamoDBClient;
|
|
9
|
+
private initialized: boolean;
|
|
10
|
+
constructor(client: DynamoDBClient);
|
|
11
|
+
ensureMigrationsTable(): Promise<void>;
|
|
12
|
+
private waitForTableActive(tableName: string, maxAttempts?: number): Promise<void>;
|
|
13
|
+
getLatestState(tableName: string): Promise<DynamoDBMigrationState | null>;
|
|
14
|
+
getHistory(tableName: string): Promise<DynamoDBMigrationState[]>;
|
|
15
|
+
recordMigration(tableName: string, definition: DynamoDBTableDefinition, version?: number): Promise<DynamoDBMigrationState>;
|
|
16
|
+
listTrackedTables(): Promise<string[]>;
|
|
17
|
+
hasMigrations(tableName: string): Promise<boolean>;
|
|
18
|
+
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
|
+
}
|
|
22
|
+
export { MIGRATIONS_TABLE };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { DynamoDBTableDefinition, DynamoDBGlobalSecondaryIndex, DynamoDBAttributeDefinition } from '../drivers/dynamodb';
|
|
2
|
+
export type {
|
|
3
|
+
DynamoDBTableDefinition,
|
|
4
|
+
DynamoDBGlobalSecondaryIndex,
|
|
5
|
+
DynamoDBAttributeDefinition,
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Generate a hash of a table definition for comparison
|
|
9
|
+
*/
|
|
10
|
+
export declare function hashTableDefinition(definition: DynamoDBTableDefinition): string;
|
|
11
|
+
/**
|
|
12
|
+
* Extract DynamoDB table definition from a Model class
|
|
13
|
+
*/
|
|
14
|
+
export declare function extractTableDefinition(model: any): DynamoDBTableDefinition;
|
|
15
|
+
/**
|
|
16
|
+
* Extract model schema from a Model class
|
|
17
|
+
*/
|
|
18
|
+
export declare function extractModelSchema(ModelClass: any): DynamoDBModelSchema;
|
|
19
|
+
/**
|
|
20
|
+
* Convert model schema to DynamoDB table definition
|
|
21
|
+
*/
|
|
22
|
+
export declare function convertSchemaToDefinition(schema: DynamoDBModelSchema): DynamoDBTableDefinition;
|
|
23
|
+
/**
|
|
24
|
+
* Build a migration plan by comparing current and target table definitions
|
|
25
|
+
*/
|
|
26
|
+
export declare function buildMigrationPlan(current: DynamoDBTableDefinition | null, target: DynamoDBTableDefinition): DynamoDBMigrationPlan;
|
|
27
|
+
/**
|
|
28
|
+
* Check if two table definitions are equivalent
|
|
29
|
+
*/
|
|
30
|
+
export declare function isDefinitionEqual(a: DynamoDBTableDefinition, b: DynamoDBTableDefinition): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Individual migration operation
|
|
33
|
+
*/
|
|
34
|
+
export declare interface DynamoDBMigrationOperation {
|
|
35
|
+
type: DynamoDBMigrationOperationType
|
|
36
|
+
tableName: string
|
|
37
|
+
details: Record<string, any>
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Migration plan containing all operations to execute
|
|
41
|
+
*/
|
|
42
|
+
export declare interface DynamoDBMigrationPlan {
|
|
43
|
+
tableName: string
|
|
44
|
+
operations: DynamoDBMigrationOperation[]
|
|
45
|
+
timestamp: string
|
|
46
|
+
hash: string
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* State of a migrated table stored in the migrations table
|
|
50
|
+
*/
|
|
51
|
+
export declare interface DynamoDBMigrationState {
|
|
52
|
+
tableName: string
|
|
53
|
+
hash: string
|
|
54
|
+
definition: DynamoDBTableDefinition
|
|
55
|
+
appliedAt: string
|
|
56
|
+
version: number
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Model definition for extracting DynamoDB schema
|
|
60
|
+
*/
|
|
61
|
+
export declare interface DynamoDBModelSchema {
|
|
62
|
+
tableName: string
|
|
63
|
+
pkAttribute: string
|
|
64
|
+
skAttribute: string
|
|
65
|
+
pkPrefix: string
|
|
66
|
+
skPrefix: string
|
|
67
|
+
entityTypeAttribute: string
|
|
68
|
+
timestamps: boolean
|
|
69
|
+
ttlAttribute?: string
|
|
70
|
+
gsis?: DynamoDBGSIDefinition[]
|
|
71
|
+
lsis?: DynamoDBLSIDefinition[]
|
|
72
|
+
billingMode?: 'PAY_PER_REQUEST' | 'PROVISIONED'
|
|
73
|
+
provisionedThroughput?: {
|
|
74
|
+
readCapacityUnits: number
|
|
75
|
+
writeCapacityUnits: number
|
|
76
|
+
}
|
|
77
|
+
streamEnabled?: boolean
|
|
78
|
+
streamViewType?: 'KEYS_ONLY' | 'NEW_IMAGE' | 'OLD_IMAGE' | 'NEW_AND_OLD_IMAGES'
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* GSI definition for model schema
|
|
82
|
+
*/
|
|
83
|
+
export declare interface DynamoDBGSIDefinition {
|
|
84
|
+
indexName: string
|
|
85
|
+
pkAttribute: string
|
|
86
|
+
skAttribute?: string
|
|
87
|
+
projection?: 'ALL' | 'KEYS_ONLY' | string[]
|
|
88
|
+
provisionedThroughput?: {
|
|
89
|
+
readCapacityUnits: number
|
|
90
|
+
writeCapacityUnits: number
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* LSI definition for model schema
|
|
95
|
+
*/
|
|
96
|
+
export declare interface DynamoDBLSIDefinition {
|
|
97
|
+
indexName: string
|
|
98
|
+
skAttribute: string
|
|
99
|
+
projection?: 'ALL' | 'KEYS_ONLY' | string[]
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Migration operation types
|
|
103
|
+
*/
|
|
104
|
+
export type DynamoDBMigrationOperationType = | 'CREATE_TABLE'
|
|
105
|
+
| 'DELETE_TABLE'
|
|
106
|
+
| 'ADD_GSI'
|
|
107
|
+
| 'DELETE_GSI'
|
|
108
|
+
| 'UPDATE_GSI_THROUGHPUT'
|
|
109
|
+
| 'UPDATE_TTL'
|
|
110
|
+
| 'UPDATE_BILLING_MODE'
|
|
111
|
+
| 'UPDATE_THROUGHPUT'
|
|
112
|
+
| 'ENABLE_STREAM'
|
|
113
|
+
| 'DISABLE_STREAM'
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { DynamoDBClient, createClient } from './client';
|
|
2
|
+
/**
|
|
3
|
+
* Configure the global DynamoDB connection for all models
|
|
4
|
+
*/
|
|
5
|
+
export declare function configureModels(config: ModelConfig): void;
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Types
|
|
8
|
+
// ============================================================================
|
|
9
|
+
export declare interface ModelConfig {
|
|
10
|
+
region?: string
|
|
11
|
+
endpoint?: string
|
|
12
|
+
credentials?: {
|
|
13
|
+
accessKeyId: string
|
|
14
|
+
secretAccessKey: string
|
|
15
|
+
sessionToken?: string
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export declare interface ModelQueryBuilder<T extends Model> {
|
|
19
|
+
where(attribute: string, value: any): ModelQueryBuilder<T>
|
|
20
|
+
where(attribute: string, operator: string, value: any): ModelQueryBuilder<T>
|
|
21
|
+
whereIn(attribute: string, values: any[]): ModelQueryBuilder<T>
|
|
22
|
+
whereBetween(attribute: string, start: any, end: any): ModelQueryBuilder<T>
|
|
23
|
+
whereBeginsWith(attribute: string, prefix: string): ModelQueryBuilder<T>
|
|
24
|
+
whereExists(attribute: string): ModelQueryBuilder<T>
|
|
25
|
+
whereNotExists(attribute: string): ModelQueryBuilder<T>
|
|
26
|
+
orderBy(direction: 'asc' | 'desc'): ModelQueryBuilder<T>
|
|
27
|
+
limit(count: number): ModelQueryBuilder<T>
|
|
28
|
+
select(...attributes: string[]): ModelQueryBuilder<T>
|
|
29
|
+
index(indexName: string): ModelQueryBuilder<T>
|
|
30
|
+
consistentRead(): ModelQueryBuilder<T>
|
|
31
|
+
startFrom(key: Record<string, any>): ModelQueryBuilder<T>
|
|
32
|
+
get(): Promise<T[]>
|
|
33
|
+
first(): Promise<T | null>
|
|
34
|
+
count(): Promise<number>
|
|
35
|
+
paginate(pageSize: number, lastKey?: Record<string, any>): Promise<{ items: T[], lastKey?: Record<string, any> }>
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Abstract base class for DynamoDB models
|
|
39
|
+
*
|
|
40
|
+
* Extend this class to create type-safe DynamoDB entities with
|
|
41
|
+
* Laravel Eloquent-like CRUD operations.
|
|
42
|
+
*/
|
|
43
|
+
export declare abstract class Model {
|
|
44
|
+
static tableName: string;
|
|
45
|
+
static pkAttribute: string;
|
|
46
|
+
static skAttribute: string;
|
|
47
|
+
static pkPrefix: string;
|
|
48
|
+
static skPrefix: string;
|
|
49
|
+
static entityTypeAttribute: string;
|
|
50
|
+
static keyDelimiter: string;
|
|
51
|
+
static primaryKey: string;
|
|
52
|
+
static timestamps: boolean;
|
|
53
|
+
static createdAtField: string;
|
|
54
|
+
static updatedAtField: string;
|
|
55
|
+
protected _attributes: Record<string, any>;
|
|
56
|
+
protected _original: Record<string, any>;
|
|
57
|
+
protected _exists: boolean;
|
|
58
|
+
constructor(attributes?: Record<string, any>);
|
|
59
|
+
static query<T extends Model>(this: new (...args: any[]) => T): ModelQueryBuilderImpl<T>;
|
|
60
|
+
static find<T extends Model>(this: new (...args: any[]) => T, id: string): Promise<T | null>;
|
|
61
|
+
static findOrFail<T extends Model>(this: new (...args: any[]) => T, id: string): Promise<T>;
|
|
62
|
+
static all<T extends Model>(this: new (...args: any[]) => T): Promise<T[]>;
|
|
63
|
+
static create<T extends Model>(this: new (...args: any[]) => T, attributes: Record<string, any>): Promise<T>;
|
|
64
|
+
static updateOrCreate<T extends Model>(this: new (...args: any[]) => T, attributes: Record<string, any>, values: Record<string, any>): Promise<T>;
|
|
65
|
+
static where<T extends Model>(this: new (...args: any[]) => T, attribute: string, operatorOrValue: any, value?: any): ModelQueryBuilderImpl<T>;
|
|
66
|
+
static wherePk<T extends Model>(this: new (...args: any[]) => T, value: string): ModelQueryBuilderImpl<T>;
|
|
67
|
+
getKey(): string;
|
|
68
|
+
getAttribute(key: string): any;
|
|
69
|
+
setAttribute(key: string, value: any): this;
|
|
70
|
+
getAttributes(): Record<string, any>;
|
|
71
|
+
isDirty(attribute?: string): boolean;
|
|
72
|
+
getDirty(): Record<string, any>;
|
|
73
|
+
save(): Promise<this>;
|
|
74
|
+
update(values: Record<string, any>): Promise<this>;
|
|
75
|
+
delete(): Promise<boolean>;
|
|
76
|
+
refresh(): Promise<this>;
|
|
77
|
+
toObject(): Record<string, any>;
|
|
78
|
+
toJSON(): Record<string, any>;
|
|
79
|
+
}
|
|
80
|
+
// ============================================================================
|
|
81
|
+
// Query Builder Implementation
|
|
82
|
+
// ============================================================================
|
|
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
|
+
constructor(ModelClass: typeof Model);
|
|
95
|
+
wherePk(value: string): this;
|
|
96
|
+
where(attribute: string, operatorOrValue: any, value?: any): this;
|
|
97
|
+
whereIn(attribute: string, values: any[]): this;
|
|
98
|
+
whereBetween(attribute: string, start: any, end: any): this;
|
|
99
|
+
whereBeginsWith(attribute: string, prefix: string): this;
|
|
100
|
+
whereExists(attribute: string): this;
|
|
101
|
+
whereNotExists(attribute: string): this;
|
|
102
|
+
orderBy(direction: 'asc' | 'desc'): this;
|
|
103
|
+
limit(count: number): this;
|
|
104
|
+
select(attributes: string[]): this;
|
|
105
|
+
index(indexName: string): this;
|
|
106
|
+
consistentRead(): this;
|
|
107
|
+
startFrom(key: Record<string, any>): this;
|
|
108
|
+
private buildRequest(): Record<string, any>;
|
|
109
|
+
get(): Promise<T[]>;
|
|
110
|
+
first(): Promise<T | null>;
|
|
111
|
+
count(): Promise<number>;
|
|
112
|
+
paginate(pageSize: number, lastKey?: Record<string, any>): Promise<{ items: T[], lastKey?: Record<string, any> }>;
|
|
113
|
+
}
|
|
114
|
+
export { DynamoDBClient, createClient } from './client';
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { DynamoDBComparisonOperator, DynamoDBCondition, DynamoDBConfig, DynamoDBDriver, DynamoDBPutItemParams, DynamoDBQueryParams, DynamoDBScanParams, DynamoDBUpdateItemParams, SingleTableEntityMapping, } from './drivers/dynamodb';
|
|
2
|
+
/**
|
|
3
|
+
* Create a DynamoDB query builder
|
|
4
|
+
*/
|
|
5
|
+
export declare function createDynamoDBQueryBuilder<T = any>(options: DynamoDBQueryBuilderOptions): DynamoDBQueryBuilder<T>;
|
|
6
|
+
/**
|
|
7
|
+
* Create a DynamoDB item builder
|
|
8
|
+
*/
|
|
9
|
+
export declare function createDynamoDBItemBuilder<T = any>(options: DynamoDBQueryBuilderOptions): DynamoDBItemBuilder<T>;
|
|
10
|
+
/**
|
|
11
|
+
* Create a DynamoDB client with fluent query builder methods
|
|
12
|
+
*/
|
|
13
|
+
export declare function createDynamoDBClient(options: DynamoDBQueryBuilderOptions): DynamoDBClientMethods;
|
|
14
|
+
/**
|
|
15
|
+
* DynamoDB Query Builder Options
|
|
16
|
+
*/
|
|
17
|
+
export declare interface DynamoDBQueryBuilderOptions {
|
|
18
|
+
config: DynamoDBConfig
|
|
19
|
+
client?: any
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Result type for DynamoDB operations
|
|
23
|
+
*/
|
|
24
|
+
export declare interface DynamoDBResult<T = any> {
|
|
25
|
+
items?: T[]
|
|
26
|
+
item?: T
|
|
27
|
+
count?: number
|
|
28
|
+
scannedCount?: number
|
|
29
|
+
lastEvaluatedKey?: Record<string, any>
|
|
30
|
+
consumedCapacity?: any
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* DynamoDB Client Factory
|
|
34
|
+
*
|
|
35
|
+
* Creates a complete DynamoDB client with query builder methods
|
|
36
|
+
*/
|
|
37
|
+
export declare interface DynamoDBClientMethods {
|
|
38
|
+
query: <T = any>() => DynamoDBQueryBuilder<T>
|
|
39
|
+
item: <T = any>() => DynamoDBItemBuilder<T>
|
|
40
|
+
driver: DynamoDBDriver
|
|
41
|
+
registerEntity: (mapping: SingleTableEntityMapping) => void
|
|
42
|
+
buildKey: (entityType: string, values: Record<string, any>) => { pk: string, sk: string }
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* DynamoDB Query Builder
|
|
46
|
+
*
|
|
47
|
+
* Fluent interface for building DynamoDB queries
|
|
48
|
+
*/
|
|
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
|
+
constructor(options: DynamoDBQueryBuilderOptions);
|
|
63
|
+
table(tableName: string): this;
|
|
64
|
+
index(indexName: string): this;
|
|
65
|
+
entity(entityType: string): this;
|
|
66
|
+
whereKey(attribute: string, operator: DynamoDBComparisonOperator, value: any): this;
|
|
67
|
+
wherePartitionKey(attribute: string, value: any): this;
|
|
68
|
+
whereSortKey(attribute: string, value: any): this;
|
|
69
|
+
whereSortKeyBeginsWith(attribute: string, prefix: string): this;
|
|
70
|
+
whereSortKeyBetween(attribute: string, start: any, end: any): this;
|
|
71
|
+
where(attribute: string, operator: DynamoDBComparisonOperator | 'contains' | 'attribute_exists' | 'attribute_not_exists' | 'IN', value?: any): this;
|
|
72
|
+
whereEquals(attribute: string, value: any): this;
|
|
73
|
+
whereLessThan(attribute: string, value: any): this;
|
|
74
|
+
whereLessThanOrEqual(attribute: string, value: any): this;
|
|
75
|
+
whereGreaterThan(attribute: string, value: any): this;
|
|
76
|
+
whereGreaterThanOrEqual(attribute: string, value: any): this;
|
|
77
|
+
whereBetween(attribute: string, start: any, end: any): this;
|
|
78
|
+
whereBeginsWith(attribute: string, prefix: string): this;
|
|
79
|
+
whereContains(attribute: string, value: any): this;
|
|
80
|
+
whereExists(attribute: string): this;
|
|
81
|
+
whereNotExists(attribute: string): this;
|
|
82
|
+
whereIn(attribute: string, values: any[]): this;
|
|
83
|
+
select(attributes: string[]): this;
|
|
84
|
+
limit(count: number): this;
|
|
85
|
+
ascending(): this;
|
|
86
|
+
descending(): this;
|
|
87
|
+
consistentRead(value?: boolean): this;
|
|
88
|
+
startFrom(key: Record<string, any>): this;
|
|
89
|
+
buildQueryParams(): DynamoDBQueryParams;
|
|
90
|
+
buildScanParams(): DynamoDBScanParams;
|
|
91
|
+
toQueryRequest(): Record<string, any>;
|
|
92
|
+
toScanRequest(): Record<string, any>;
|
|
93
|
+
query(): Promise<DynamoDBResult<T>>;
|
|
94
|
+
scan(): Promise<DynamoDBResult<T>>;
|
|
95
|
+
getAll(): Promise<T[]>;
|
|
96
|
+
first(): Promise<T | undefined>;
|
|
97
|
+
count(): Promise<number>;
|
|
98
|
+
reset(): this;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* DynamoDB Item Builder for Put/Update operations
|
|
102
|
+
*/
|
|
103
|
+
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
|
+
constructor(options: DynamoDBQueryBuilderOptions);
|
|
113
|
+
table(tableName: string): this;
|
|
114
|
+
key(key: Record<string, any>): this;
|
|
115
|
+
item(data: Record<string, any>): this;
|
|
116
|
+
set(attribute: string, value: any): this;
|
|
117
|
+
setMany(values: Record<string, any>): this;
|
|
118
|
+
remove(attribute: string): this;
|
|
119
|
+
add(attribute: string, value: any): this;
|
|
120
|
+
deleteFromSet(attribute: string, values: any): this;
|
|
121
|
+
condition(expression: string): this;
|
|
122
|
+
ifNotExists(attribute?: string): this;
|
|
123
|
+
ifExists(attribute?: string): this;
|
|
124
|
+
returnOld(): this;
|
|
125
|
+
returnNew(): this;
|
|
126
|
+
toPutRequest(): Record<string, any>;
|
|
127
|
+
toUpdateRequest(): Record<string, any>;
|
|
128
|
+
toDeleteRequest(): Record<string, any>;
|
|
129
|
+
toGetRequest(): Record<string, any>;
|
|
130
|
+
put(): Promise<T | undefined>;
|
|
131
|
+
update(): Promise<T | undefined>;
|
|
132
|
+
delete(): Promise<T | undefined>;
|
|
133
|
+
get(): Promise<T | undefined>;
|
|
134
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { DynamoDBQueryBuilder } from './dynamodb-client';
|
|
2
|
+
import type { DynamoDBQueryBuilderOptions } from './dynamodb-client';
|
|
3
|
+
import type { DynamoDBTableDefinition, } from './drivers/dynamodb';
|
|
4
|
+
/**
|
|
5
|
+
* Create a single table manager
|
|
6
|
+
*/
|
|
7
|
+
export declare function createSingleTableManager(config: SingleTableConfig): SingleTableManager;
|
|
8
|
+
/**
|
|
9
|
+
* Create a repository for an entity
|
|
10
|
+
*/
|
|
11
|
+
export declare function createRepository<T extends Record<string, any>>(manager: SingleTableManager, entityName: string, options: DynamoDBQueryBuilderOptions): SingleTableRepository<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Common single table design patterns
|
|
14
|
+
*/
|
|
15
|
+
export declare const SingleTablePatterns: {
|
|
16
|
+
/**
|
|
17
|
+
* User with profile pattern
|
|
18
|
+
* PK: USER#<userId>
|
|
19
|
+
* SK: PROFILE for metadata, or related items like ORDER#<orderId>
|
|
20
|
+
*/
|
|
21
|
+
simpleEntity: (entityName: string, idField: string?) => any;
|
|
22
|
+
/**
|
|
23
|
+
* One-to-many relationship pattern
|
|
24
|
+
* Parent: PK=PARENT#<parentId>, SK=METADATA
|
|
25
|
+
* Child: PK=PARENT#<parentId>, SK=CHILD#<childId>
|
|
26
|
+
*/
|
|
27
|
+
oneToMany: ( parentEntity: string, childEntity: string, parentIdField: string?, childIdField: string?, ) => unknown;
|
|
28
|
+
/**
|
|
29
|
+
* Many-to-many relationship pattern using adjacency list
|
|
30
|
+
* Entity: PK=ENTITY#<entityId>, SK=METADATA
|
|
31
|
+
* Relationship: PK=ENTITY#<entityId>, SK=RELATED#<relatedId>
|
|
32
|
+
* Inverse: PK=ENTITY#<relatedId>, SK=RELATED#<entityId> (via GSI)
|
|
33
|
+
*/
|
|
34
|
+
manyToMany: ( entityName: string, relationName: string, idField: string?, relatedIdField: string?, ) => unknown;
|
|
35
|
+
/**
|
|
36
|
+
* Hierarchical data pattern (e.g., org chart, file system)
|
|
37
|
+
* PK: ROOT#<rootId>
|
|
38
|
+
* SK: PATH#<path> (e.g., PATH#/folder1/folder2/file)
|
|
39
|
+
*/
|
|
40
|
+
hierarchical: (entityName: string, rootIdField: string?, pathField: string?) => any
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Entity definition for single table design
|
|
44
|
+
*/
|
|
45
|
+
export declare interface SingleTableEntity {
|
|
46
|
+
name: string
|
|
47
|
+
pkPattern: string
|
|
48
|
+
skPattern: string
|
|
49
|
+
keyFields: string[]
|
|
50
|
+
indexes?: {
|
|
51
|
+
/** GSI name */
|
|
52
|
+
name: string
|
|
53
|
+
/** Pattern for GSI partition key */
|
|
54
|
+
pkPattern: string
|
|
55
|
+
/** Pattern for GSI sort key */
|
|
56
|
+
skPattern?: string
|
|
57
|
+
}[]
|
|
58
|
+
schema?: Record<string, {
|
|
59
|
+
type: 'string' | 'number' | 'boolean' | 'list' | 'map' | 'set'
|
|
60
|
+
required?: boolean
|
|
61
|
+
}>
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Single table design configuration
|
|
65
|
+
*/
|
|
66
|
+
export declare interface SingleTableConfig {
|
|
67
|
+
tableName: string
|
|
68
|
+
pkAttribute?: string
|
|
69
|
+
skAttribute?: string
|
|
70
|
+
typeAttribute?: string
|
|
71
|
+
indexes?: {
|
|
72
|
+
name: string
|
|
73
|
+
pkAttribute: string
|
|
74
|
+
skAttribute?: string
|
|
75
|
+
}[]
|
|
76
|
+
entities: SingleTableEntity[]
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Single Table Design Manager
|
|
80
|
+
*
|
|
81
|
+
* Manages entity mappings and provides utilities for working with
|
|
82
|
+
* single table design patterns.
|
|
83
|
+
*/
|
|
84
|
+
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
|
+
constructor(config: SingleTableConfig);
|
|
91
|
+
getEntity(name: string): SingleTableEntity | undefined;
|
|
92
|
+
registerEntity(entity: SingleTableEntity): void;
|
|
93
|
+
buildKey(entityName: string, data: Record<string, any>): { pk: string, sk: string };
|
|
94
|
+
buildGSIKey(entityName: string, indexName: string, data: Record<string, any>): { pk: string, sk?: string };
|
|
95
|
+
createItem(entityName: string, data: Record<string, any>): Record<string, any>;
|
|
96
|
+
parseEntityType(item: Record<string, any>): string | undefined;
|
|
97
|
+
parseItem<T = any>(item: Record<string, any>): { type: string, data: T } | undefined;
|
|
98
|
+
getEntityPrefix(entityName: string): string;
|
|
99
|
+
generateTableDefinition(): DynamoDBTableDefinition;
|
|
100
|
+
private interpolatePattern(pattern: string, values: Record<string, any>): string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Single Table Entity Repository
|
|
104
|
+
*
|
|
105
|
+
* Provides CRUD operations for a specific entity type in a single table design.
|
|
106
|
+
*/
|
|
107
|
+
export declare class SingleTableRepository<T extends Record<string, any>> {
|
|
108
|
+
private manager: SingleTableManager;
|
|
109
|
+
private entityName: string;
|
|
110
|
+
private options: DynamoDBQueryBuilderOptions;
|
|
111
|
+
constructor(manager: SingleTableManager, entityName: string, options: DynamoDBQueryBuilderOptions);
|
|
112
|
+
create(data: T): Promise<T>;
|
|
113
|
+
get(keyData: Partial<T>): Promise<T | undefined>;
|
|
114
|
+
update(keyData: Partial<T>, updates: Partial<T>): Promise<T | undefined>;
|
|
115
|
+
delete(keyData: Partial<T>): Promise<boolean>;
|
|
116
|
+
query(): SingleTableQueryBuilder<T>;
|
|
117
|
+
findAll(): Promise<T[]>;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Query builder for single table entity queries
|
|
121
|
+
*/
|
|
122
|
+
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
|
+
constructor(manager: SingleTableManager, entityName: string, options: DynamoDBQueryBuilderOptions);
|
|
130
|
+
wherePartitionKey(pkData: Record<string, any>): this;
|
|
131
|
+
whereSortKey(skData: Record<string, any>): this;
|
|
132
|
+
whereSortKeyBeginsWith(prefix: string): this;
|
|
133
|
+
useIndex(indexName: string, pkData: Record<string, any>): this;
|
|
134
|
+
where(attribute: string, operator: any, value?: any): this;
|
|
135
|
+
select(attributes: string[]): this;
|
|
136
|
+
limit(count: number): this;
|
|
137
|
+
descending(): this;
|
|
138
|
+
execute(): Promise<T[]>;
|
|
139
|
+
first(): Promise<T | undefined>;
|
|
140
|
+
}
|