dyno-table 2.5.2 → 2.6.1
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/builders/batch-builder.d.ts +249 -0
- package/dist/builders/builder-types.d.ts +123 -0
- package/dist/builders/condition-check-builder.d.ts +149 -0
- package/dist/builders/delete-builder.d.ts +208 -0
- package/dist/builders/entity-aware-builders.d.ts +127 -0
- package/dist/builders/filter-builder.d.ts +294 -0
- package/dist/builders/get-builder.d.ts +191 -0
- package/dist/builders/index.d.ts +14 -0
- package/dist/builders/paginator.d.ts +151 -0
- package/dist/builders/put-builder.d.ts +317 -0
- package/dist/builders/query-builder.d.ts +218 -0
- package/dist/builders/result-iterator.d.ts +55 -0
- package/dist/builders/scan-builder.d.ts +109 -0
- package/dist/builders/transaction-builder.d.ts +462 -0
- package/dist/builders/types.d.ts +25 -0
- package/dist/builders/update-builder.d.ts +372 -0
- package/dist/builders.cjs +3648 -43
- package/dist/builders.d.ts +1 -4
- package/dist/builders.js +3648 -3
- package/dist/conditions.cjs +60 -67
- package/dist/conditions.d.ts +705 -3
- package/dist/conditions.js +46 -1
- package/dist/entity/ddb-indexing.d.ts +45 -0
- package/dist/entity/entity.d.ts +188 -0
- package/dist/entity/index-utils.d.ts +24 -0
- package/dist/entity.cjs +1126 -15
- package/dist/entity.d.ts +1 -261
- package/dist/entity.js +1127 -3
- package/dist/errors.d.ts +212 -0
- package/dist/expression.d.ts +9 -0
- package/dist/index-definition.d.ts +10 -0
- package/dist/index.cjs +5388 -270
- package/dist/index.d.ts +16 -273
- package/dist/index.js +5332 -6
- package/dist/operation-types.d.ts +8 -0
- package/dist/standard-schema.d.ts +2 -4
- package/dist/table.cjs +4311 -7
- package/dist/table.d.ts +13 -8
- package/dist/table.js +4315 -4
- package/dist/types.d.ts +6 -9
- package/dist/utils/chunk-array.d.ts +9 -0
- package/dist/utils/debug-expression.d.ts +32 -0
- package/dist/utils/debug-transaction.d.ts +17 -0
- package/dist/utils/error-factory.d.ts +162 -0
- package/dist/utils/error-utils.d.ts +170 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/partition-key-template.d.ts +30 -0
- package/dist/utils/sort-key-template.d.ts +33 -0
- package/dist/utils.cjs +28 -10
- package/dist/utils.d.ts +1 -66
- package/dist/utils.js +29 -1
- package/package.json +53 -66
- package/dist/builders.d.cts +0 -4
- package/dist/chunk-2WIBY7PZ.js +0 -46
- package/dist/chunk-3DR6VOFW.cjs +0 -3349
- package/dist/chunk-42LH2UEM.js +0 -577
- package/dist/chunk-7UJJ7JXM.cjs +0 -63
- package/dist/chunk-ELULXDSB.cjs +0 -564
- package/dist/chunk-FF7FYGDH.js +0 -543
- package/dist/chunk-G5ERTQFX.cjs +0 -843
- package/dist/chunk-NYJGW3XH.js +0 -3334
- package/dist/chunk-PB7BBCZO.cjs +0 -32
- package/dist/chunk-QVRMYGC4.js +0 -29
- package/dist/chunk-RNX2DAHA.js +0 -818
- package/dist/chunk-ZUBCW3LA.cjs +0 -579
- package/dist/conditions-BSAcZswY.d.ts +0 -731
- package/dist/conditions-C8bM__Pn.d.cts +0 -731
- package/dist/conditions.d.cts +0 -3
- package/dist/entity.d.cts +0 -261
- package/dist/index-Bc-ra0im.d.ts +0 -3042
- package/dist/index-CPCmWsEv.d.cts +0 -3042
- package/dist/index.d.cts +0 -273
- package/dist/standard-schema.d.cts +0 -57
- package/dist/table.d.cts +0 -165
- package/dist/types.d.cts +0 -29
- package/dist/utils.d.cts +0 -66
package/dist/conditions.js
CHANGED
|
@@ -1 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
// src/conditions.ts
|
|
2
|
+
var createComparisonCondition = (type) => (attr, value) => ({
|
|
3
|
+
type,
|
|
4
|
+
attr,
|
|
5
|
+
value
|
|
6
|
+
});
|
|
7
|
+
var eq = createComparisonCondition("eq");
|
|
8
|
+
var ne = createComparisonCondition("ne");
|
|
9
|
+
var lt = createComparisonCondition("lt");
|
|
10
|
+
var lte = createComparisonCondition("lte");
|
|
11
|
+
var gt = createComparisonCondition("gt");
|
|
12
|
+
var gte = createComparisonCondition("gte");
|
|
13
|
+
var between = (attr, lower, upper) => ({
|
|
14
|
+
type: "between",
|
|
15
|
+
attr,
|
|
16
|
+
value: [lower, upper]
|
|
17
|
+
});
|
|
18
|
+
var inArray = (attr, values) => ({
|
|
19
|
+
type: "in",
|
|
20
|
+
attr,
|
|
21
|
+
value: values
|
|
22
|
+
});
|
|
23
|
+
var beginsWith = createComparisonCondition("beginsWith");
|
|
24
|
+
var contains = createComparisonCondition("contains");
|
|
25
|
+
var attributeExists = (attr) => ({
|
|
26
|
+
type: "attributeExists",
|
|
27
|
+
attr
|
|
28
|
+
});
|
|
29
|
+
var attributeNotExists = (attr) => ({
|
|
30
|
+
type: "attributeNotExists",
|
|
31
|
+
attr
|
|
32
|
+
});
|
|
33
|
+
var and = (...conditions) => ({
|
|
34
|
+
type: "and",
|
|
35
|
+
conditions
|
|
36
|
+
});
|
|
37
|
+
var or = (...conditions) => ({
|
|
38
|
+
type: "or",
|
|
39
|
+
conditions
|
|
40
|
+
});
|
|
41
|
+
var not = (condition) => ({
|
|
42
|
+
type: "not",
|
|
43
|
+
condition
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export { and, attributeExists, attributeNotExists, beginsWith, between, contains, createComparisonCondition, eq, gt, gte, inArray, lt, lte, ne, not, or };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Table } from "../table";
|
|
2
|
+
import type { DynamoItem } from "../types";
|
|
3
|
+
import type { IndexDefinition } from "./entity";
|
|
4
|
+
/**
|
|
5
|
+
* Helper class for building indexes for DynamoDB operations
|
|
6
|
+
*/
|
|
7
|
+
export declare class IndexBuilder<T extends DynamoItem> {
|
|
8
|
+
private readonly table;
|
|
9
|
+
private readonly indexes;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new IndexBuilder instance
|
|
12
|
+
*
|
|
13
|
+
* @param table - The DynamoDB table instance
|
|
14
|
+
* @param indexes - The index definitions
|
|
15
|
+
*/
|
|
16
|
+
constructor(table: Table, indexes?: Record<string, IndexDefinition<T>>);
|
|
17
|
+
/**
|
|
18
|
+
* Build index attributes for item creation
|
|
19
|
+
*
|
|
20
|
+
* @param item - The item to generate indexes for
|
|
21
|
+
* @param options - Options for building indexes
|
|
22
|
+
* @returns Record of GSI attribute names to their values
|
|
23
|
+
*/
|
|
24
|
+
buildForCreate(item: T, options?: {
|
|
25
|
+
excludeReadOnly?: boolean;
|
|
26
|
+
}): Record<string, string>;
|
|
27
|
+
/**
|
|
28
|
+
* Build index attributes for item updates
|
|
29
|
+
*
|
|
30
|
+
* @param currentData - The current data before update
|
|
31
|
+
* @param updates - The update data
|
|
32
|
+
* @param options - Options for building indexes
|
|
33
|
+
* @returns Record of GSI attribute names to their updated values
|
|
34
|
+
*/
|
|
35
|
+
buildForUpdate(currentData: T, updates: Partial<T>, options?: {
|
|
36
|
+
forceRebuildIndexes?: string[];
|
|
37
|
+
}): Record<string, string>;
|
|
38
|
+
/**
|
|
39
|
+
* Check if a key has undefined values
|
|
40
|
+
*
|
|
41
|
+
* @param key - The index key to check
|
|
42
|
+
* @returns True if the key contains undefined values, false otherwise
|
|
43
|
+
*/
|
|
44
|
+
private hasUndefinedValues;
|
|
45
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import type { DeleteBuilder, GetBuilder, Path, PathType, PutBuilder, QueryBuilder, ScanBuilder, TransactionBuilder, UpdateBuilder, UpdateCommandParams } from "../builders";
|
|
2
|
+
import { type Condition, type ConditionOperator, type PrimaryKey, type PrimaryKeyWithoutExpression } from "../conditions";
|
|
3
|
+
import type { StandardSchemaV1 } from "../standard-schema";
|
|
4
|
+
import type { Table } from "../table";
|
|
5
|
+
import type { DynamoItem, Index, TableConfig } from "../types";
|
|
6
|
+
export type QueryFunction<_T extends DynamoItem, I, R> = (input: I) => R;
|
|
7
|
+
export type QueryFunctionWithSchema<T extends DynamoItem, I, R> = QueryFunction<T, I, R> & {
|
|
8
|
+
schema?: StandardSchemaV1<I>;
|
|
9
|
+
};
|
|
10
|
+
export type QueryRecord<T extends DynamoItem> = {
|
|
11
|
+
[K: string]: QueryFunctionWithSchema<T, any, any>;
|
|
12
|
+
};
|
|
13
|
+
export type MappedQueries<T extends DynamoItem, Q extends QueryRecord<T>> = {
|
|
14
|
+
[K in keyof Q]: Q[K] extends QueryFunctionWithSchema<T, infer I, infer R> ? (input: I) => R : never;
|
|
15
|
+
};
|
|
16
|
+
export type QueryEntity<T extends DynamoItem> = {
|
|
17
|
+
scan: () => ScanBuilder<T>;
|
|
18
|
+
get: (key: PrimaryKeyWithoutExpression) => EntityGetBuilder<T>;
|
|
19
|
+
query: (keyCondition: PrimaryKey) => QueryBuilder<T, TableConfig>;
|
|
20
|
+
};
|
|
21
|
+
type SetElementType<T> = T extends Set<infer U> ? U : T extends Array<infer U> ? U : never;
|
|
22
|
+
type PathSetElementType<T, K extends Path<T>> = SetElementType<PathType<T, K>>;
|
|
23
|
+
export type EntityPutBuilder<T extends DynamoItem> = PutBuilder<T> & {
|
|
24
|
+
readonly entityName: string;
|
|
25
|
+
};
|
|
26
|
+
export type EntityGetBuilder<T extends DynamoItem> = GetBuilder<T> & {
|
|
27
|
+
readonly entityName: string;
|
|
28
|
+
};
|
|
29
|
+
export type EntityDeleteBuilder = DeleteBuilder & {
|
|
30
|
+
readonly entityName: string;
|
|
31
|
+
};
|
|
32
|
+
export type EntityUpdateBuilder<T extends DynamoItem> = {
|
|
33
|
+
readonly entityName: string;
|
|
34
|
+
set(values: Partial<T>): EntityUpdateBuilder<T>;
|
|
35
|
+
set<K extends Path<T>>(path: K, value: PathType<T, K>): EntityUpdateBuilder<T>;
|
|
36
|
+
remove<K extends Path<T>>(path: K): EntityUpdateBuilder<T>;
|
|
37
|
+
add<K extends Path<T>>(path: K, value: PathType<T, K>): EntityUpdateBuilder<T>;
|
|
38
|
+
deleteElementsFromSet<K extends Path<T>>(path: K, value: PathSetElementType<T, K>[] | Set<PathSetElementType<T, K>>): EntityUpdateBuilder<T>;
|
|
39
|
+
condition(condition: Condition | ((op: ConditionOperator<T>) => Condition)): EntityUpdateBuilder<T>;
|
|
40
|
+
returnValues(returnValues: "ALL_NEW" | "UPDATED_NEW" | "ALL_OLD" | "UPDATED_OLD" | "NONE"): EntityUpdateBuilder<T>;
|
|
41
|
+
toDynamoCommand(): UpdateCommandParams;
|
|
42
|
+
withTransaction(transaction: TransactionBuilder): void;
|
|
43
|
+
debug(): ReturnType<UpdateBuilder<T>["debug"]>;
|
|
44
|
+
execute(): Promise<{
|
|
45
|
+
item?: T;
|
|
46
|
+
}>;
|
|
47
|
+
forceIndexRebuild(indexes: string | string[]): EntityUpdateBuilder<T>;
|
|
48
|
+
getForceRebuildIndexes(): string[];
|
|
49
|
+
};
|
|
50
|
+
interface Settings {
|
|
51
|
+
/**
|
|
52
|
+
* Defaults to "entityType"
|
|
53
|
+
*/
|
|
54
|
+
entityTypeAttributeName?: string;
|
|
55
|
+
timestamps?: {
|
|
56
|
+
createdAt?: {
|
|
57
|
+
/**
|
|
58
|
+
* ISO vs Unix trade-offs
|
|
59
|
+
*
|
|
60
|
+
* Both options support between, greater than and less than comparisons.
|
|
61
|
+
*
|
|
62
|
+
* ISO:
|
|
63
|
+
* - Human readable, but requires more storage space
|
|
64
|
+
* - Does not work with DynamoDBs TTL feature.
|
|
65
|
+
*
|
|
66
|
+
* UNIX:
|
|
67
|
+
* - Less readable, but requires less storage space.
|
|
68
|
+
* - Works with DynamoDBs TTL feature.
|
|
69
|
+
*/
|
|
70
|
+
format: "ISO" | "UNIX";
|
|
71
|
+
/**
|
|
72
|
+
* Defaults to "createdAt"
|
|
73
|
+
*/
|
|
74
|
+
attributeName?: string;
|
|
75
|
+
};
|
|
76
|
+
updatedAt?: {
|
|
77
|
+
/**
|
|
78
|
+
* ISO vs Unix trade-offs
|
|
79
|
+
*
|
|
80
|
+
* Both options support between, greater than and less than comparisons.
|
|
81
|
+
*
|
|
82
|
+
* ISO:
|
|
83
|
+
* - Human readable, but requires more storage space
|
|
84
|
+
* - Does not work with DynamoDBs TTL feature.
|
|
85
|
+
*
|
|
86
|
+
* UNIX:
|
|
87
|
+
* - Less readable, but requires less storage space.
|
|
88
|
+
* - Works with DynamoDBs TTL feature.
|
|
89
|
+
*/
|
|
90
|
+
format: "ISO" | "UNIX";
|
|
91
|
+
/**
|
|
92
|
+
* Defaults to "updatedAt"
|
|
93
|
+
*/
|
|
94
|
+
attributeName?: string;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export interface EntityConfig<T extends DynamoItem, TInput extends DynamoItem = T, I extends DynamoItem = T, Q extends QueryRecord<T> = QueryRecord<T>> {
|
|
99
|
+
name: string;
|
|
100
|
+
schema: StandardSchemaV1<TInput, T>;
|
|
101
|
+
primaryKey: IndexDefinition<I>;
|
|
102
|
+
indexes?: Record<string, IndexDefinition<T>>;
|
|
103
|
+
queries: Q;
|
|
104
|
+
settings?: Settings;
|
|
105
|
+
}
|
|
106
|
+
export interface EntityRepository<
|
|
107
|
+
/**
|
|
108
|
+
* The Entity Type (output type)
|
|
109
|
+
*/
|
|
110
|
+
T extends DynamoItem,
|
|
111
|
+
/**
|
|
112
|
+
* The Input Type (for create operations)
|
|
113
|
+
*/
|
|
114
|
+
TInput extends DynamoItem = T,
|
|
115
|
+
/**
|
|
116
|
+
* The Primary Index (Partition index) Type
|
|
117
|
+
*/
|
|
118
|
+
I extends DynamoItem = T,
|
|
119
|
+
/**
|
|
120
|
+
* The Queries object
|
|
121
|
+
*/
|
|
122
|
+
Q extends QueryRecord<T> = QueryRecord<T>> {
|
|
123
|
+
create: (data: TInput) => EntityPutBuilder<T>;
|
|
124
|
+
upsert: (data: TInput & I) => EntityPutBuilder<T>;
|
|
125
|
+
get: (key: I) => EntityGetBuilder<T>;
|
|
126
|
+
update: (key: I, data: Partial<T>) => EntityUpdateBuilder<T>;
|
|
127
|
+
delete: (key: I) => EntityDeleteBuilder;
|
|
128
|
+
query: MappedQueries<T, Q>;
|
|
129
|
+
scan: () => ScanBuilder<T>;
|
|
130
|
+
}
|
|
131
|
+
export interface EntityDefinition<T extends DynamoItem, TInput extends DynamoItem = T, I extends DynamoItem = T, Q extends QueryRecord<T> = QueryRecord<T>> {
|
|
132
|
+
name: string;
|
|
133
|
+
createRepository: (table: Table) => EntityRepository<T, TInput, I, Q>;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Creates an entity definition with type-safe operations
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* interface User {
|
|
141
|
+
* id: string;
|
|
142
|
+
* name: string;
|
|
143
|
+
* }
|
|
144
|
+
*
|
|
145
|
+
* const UserEntity = defineEntity<User>({
|
|
146
|
+
* name: "User",
|
|
147
|
+
* schema: userSchema,
|
|
148
|
+
* primaryKey: primaryKey,
|
|
149
|
+
* });
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
export declare function defineEntity<T extends DynamoItem, TInput extends DynamoItem = T, I extends DynamoItem = T, Q extends QueryRecord<T> = QueryRecord<T>>(config: EntityConfig<T, TInput, I, Q>): EntityDefinition<T, TInput, I, Q>;
|
|
153
|
+
export declare function createQueries<T extends DynamoItem>(): {
|
|
154
|
+
input: <I>(schema: StandardSchemaV1<I>) => {
|
|
155
|
+
query: <R extends ScanBuilder<T> | QueryBuilder<T, TableConfig> | GetBuilder<T>>(handler: (params: {
|
|
156
|
+
input: I;
|
|
157
|
+
entity: QueryEntity<T>;
|
|
158
|
+
}) => R) => QueryFunctionWithSchema<T, I, R>;
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Defines a DynamoDB index configuration
|
|
163
|
+
*/
|
|
164
|
+
export interface IndexDefinition<T extends DynamoItem> extends Index<T> {
|
|
165
|
+
/** The name of the index */
|
|
166
|
+
name: string;
|
|
167
|
+
/** Whether the index is read-only */
|
|
168
|
+
isReadOnly: boolean;
|
|
169
|
+
/** Function to generate the index key from an item */
|
|
170
|
+
generateKey: (item: T) => {
|
|
171
|
+
pk: string;
|
|
172
|
+
sk?: string;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
export declare function createIndex(): {
|
|
176
|
+
input: <T extends DynamoItem>(schema: StandardSchemaV1<T>) => {
|
|
177
|
+
partitionKey: <P extends (item: T) => string>(pkFn: P) => {
|
|
178
|
+
sortKey: <S extends (item: T) => string>(skFn: S) => IndexDefinition<T> & {
|
|
179
|
+
readOnly: (value?: boolean) => IndexDefinition<T>;
|
|
180
|
+
};
|
|
181
|
+
withoutSortKey: () => IndexDefinition<T> & {
|
|
182
|
+
readOnly: (value?: boolean) => IndexDefinition<T>;
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
readOnly: (value?: boolean) => /*elided*/ any;
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Table } from "../table";
|
|
2
|
+
import type { DynamoItem } from "../types";
|
|
3
|
+
import type { IndexDefinition } from "./entity";
|
|
4
|
+
/**
|
|
5
|
+
* Builds secondary indexes for an item based on the configured indexes
|
|
6
|
+
*
|
|
7
|
+
* @param dataForKeyGeneration - The validated data to generate keys from
|
|
8
|
+
* @param table - The DynamoDB table instance containing GSI configurations
|
|
9
|
+
* @param indexes - The index definitions
|
|
10
|
+
* @param excludeReadOnly - Whether to exclude read-only indexes
|
|
11
|
+
* @returns Record of GSI attribute names to their values
|
|
12
|
+
*/
|
|
13
|
+
export declare function buildIndexes<T extends DynamoItem>(dataForKeyGeneration: T, table: Table, indexes: Record<string, IndexDefinition<T>> | undefined, excludeReadOnly?: boolean): Record<string, string>;
|
|
14
|
+
/**
|
|
15
|
+
* Builds index updates for an item based on the configured indexes
|
|
16
|
+
*
|
|
17
|
+
* @param currentData - The current data before update
|
|
18
|
+
* @param updates - The update data
|
|
19
|
+
* @param table - The DynamoDB table instance containing GSI configurations
|
|
20
|
+
* @param indexes - The index definitions
|
|
21
|
+
* @param forceRebuildIndexes - Array of index names to force rebuild even if readonly
|
|
22
|
+
* @returns Record of GSI attribute names to their updated values
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildIndexUpdates<T extends DynamoItem>(currentData: T, updates: Partial<T>, table: Table, indexes: Record<string, IndexDefinition<T>> | undefined, forceRebuildIndexes?: string[]): Record<string, string>;
|