simple-dynamo-ts 1.0.6 → 1.0.7
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/README.md +125 -1
- package/dist/decorators.d.ts +4 -6
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +86 -62
- package/dist/decorators.js.map +1 -1
- package/dist/entity-example2.d.ts +11 -0
- package/dist/entity-example2.d.ts.map +1 -0
- package/dist/entity-example2.js +44 -0
- package/dist/entity-example2.js.map +1 -0
- package/dist/helper-functions.d.ts +14 -0
- package/dist/helper-functions.d.ts.map +1 -0
- package/dist/helper-functions.js +81 -0
- package/dist/helper-functions.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -6
- package/dist/index.js.map +1 -1
- package/dist/simple-dynamodb-repository.d.ts +8 -1
- package/dist/simple-dynamodb-repository.d.ts.map +1 -1
- package/dist/simple-dynamodb-repository.js +63 -15
- package/dist/simple-dynamodb-repository.js.map +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/exceptions.js +0 -36
- package/dist/exceptions.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -164,6 +164,59 @@ Marks a property as the sort key (RANGE key). The field name is optional.
|
|
|
164
164
|
id!: string;
|
|
165
165
|
```
|
|
166
166
|
|
|
167
|
+
### `@CompositePartitionKey(pkName?)`
|
|
168
|
+
|
|
169
|
+
Marks multiple properties as parts of a **single composite partition key**.
|
|
170
|
+
All properties sharing the same `pkName` are combined into one DynamoDB partition key using a `#` separator, in the order the decorators are applied.
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { DynamoTable, CompositePartitionKey } from "simple-dynamo-ts";
|
|
174
|
+
|
|
175
|
+
@DynamoTable("User")
|
|
176
|
+
export class UserEntity {
|
|
177
|
+
@CompositePartitionKey("pk")
|
|
178
|
+
orgId!: string;
|
|
179
|
+
|
|
180
|
+
@CompositePartitionKey("pk")
|
|
181
|
+
id!: string;
|
|
182
|
+
|
|
183
|
+
// In DynamoDB, this will be stored as:
|
|
184
|
+
// pk = `${orgId}#${id}`
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
> **Note**: You cannot mix `@PartitionKey` and `@CompositePartitionKey` in the same entity.
|
|
189
|
+
|
|
190
|
+
### `@CompositeSortKey(skName?)`
|
|
191
|
+
|
|
192
|
+
Marks multiple properties as parts of a **single composite sort key**.
|
|
193
|
+
All properties sharing the same `skName` are combined into one DynamoDB sort key using a `#` separator, in the order the decorators are applied.
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
import { DynamoTable, CompositePartitionKey, CompositeSortKey } from "simple-dynamo-ts";
|
|
197
|
+
|
|
198
|
+
@DynamoTable("User")
|
|
199
|
+
export class UserEntity {
|
|
200
|
+
@CompositePartitionKey("pk")
|
|
201
|
+
orgId!: string;
|
|
202
|
+
|
|
203
|
+
@CompositePartitionKey("pk")
|
|
204
|
+
id!: string;
|
|
205
|
+
|
|
206
|
+
@CompositeSortKey("sk")
|
|
207
|
+
role: string = "USER";
|
|
208
|
+
|
|
209
|
+
@CompositeSortKey("sk")
|
|
210
|
+
email!: string;
|
|
211
|
+
|
|
212
|
+
// In DynamoDB, this will be stored as:
|
|
213
|
+
// pk = `${orgId}#${id}`
|
|
214
|
+
// sk = `${role}#${email}`
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
> **Note**: You cannot mix `@SortKey` and `@CompositeSortKey` in the same entity.
|
|
219
|
+
|
|
167
220
|
### `@IndexPartitionKey(indexName, fieldName?)`
|
|
168
221
|
|
|
169
222
|
Marks a property as a partition key for a DynamoDB Global Secondary Index (GSI).
|
|
@@ -252,6 +305,19 @@ const result = await repository.query({
|
|
|
252
305
|
indexName: "EmailIndex",
|
|
253
306
|
});
|
|
254
307
|
|
|
308
|
+
// With composite keys, you still query by the logical values:
|
|
309
|
+
// Example entity:
|
|
310
|
+
// @CompositePartitionKey("pk") orgId
|
|
311
|
+
// @CompositePartitionKey("pk") id
|
|
312
|
+
// @CompositeSortKey("sk") role
|
|
313
|
+
// @CompositeSortKey("sk") email
|
|
314
|
+
//
|
|
315
|
+
// Repository usage:
|
|
316
|
+
const resultWithComposite = await repository.query({
|
|
317
|
+
pk: "ORG-123#user-456", // composite pk value
|
|
318
|
+
sk: "ADMIN#user@example.com", // composite sk value
|
|
319
|
+
});
|
|
320
|
+
|
|
255
321
|
// Query with limit and sort order
|
|
256
322
|
const result = await repository.query({
|
|
257
323
|
pk: "USER",
|
|
@@ -323,7 +389,7 @@ Thrown when duplicate decorators are applied (e.g., multiple `@PartitionKey` dec
|
|
|
323
389
|
|
|
324
390
|
## Complete Example
|
|
325
391
|
|
|
326
|
-
Here's a complete example demonstrating entity definition and repository usage
|
|
392
|
+
Here's a complete example demonstrating entity definition and repository usage with **simple keys**:
|
|
327
393
|
|
|
328
394
|
```typescript
|
|
329
395
|
// user.entity.ts
|
|
@@ -417,6 +483,64 @@ const allUsers = await usersRepository.findAll();
|
|
|
417
483
|
await usersRepository.delete("user-456");
|
|
418
484
|
```
|
|
419
485
|
|
|
486
|
+
### Complete Example with Composite Keys
|
|
487
|
+
|
|
488
|
+
The same pattern works when using composite partition and sort keys:
|
|
489
|
+
|
|
490
|
+
```typescript
|
|
491
|
+
// user-composite.entity.ts
|
|
492
|
+
import {
|
|
493
|
+
DynamoTable,
|
|
494
|
+
CompositePartitionKey,
|
|
495
|
+
CompositeSortKey,
|
|
496
|
+
} from "simple-dynamo-ts";
|
|
497
|
+
|
|
498
|
+
@DynamoTable("User")
|
|
499
|
+
export class UserCompositeEntity {
|
|
500
|
+
@CompositePartitionKey("pk")
|
|
501
|
+
orgId!: string;
|
|
502
|
+
|
|
503
|
+
@CompositePartitionKey("pk")
|
|
504
|
+
id: string = "generate-id";
|
|
505
|
+
|
|
506
|
+
@CompositeSortKey("sk")
|
|
507
|
+
role: string = "USER";
|
|
508
|
+
|
|
509
|
+
@CompositeSortKey("sk")
|
|
510
|
+
email!: string;
|
|
511
|
+
|
|
512
|
+
password!: string;
|
|
513
|
+
createdAt!: string;
|
|
514
|
+
updatedAt!: string;
|
|
515
|
+
deletedAt?: string;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// users-composite.repository.ts
|
|
519
|
+
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
|
|
520
|
+
import { DynamoDBRepository, QueryOptions } from "simple-dynamo-ts";
|
|
521
|
+
import { UserCompositeEntity } from "./user-composite.entity";
|
|
522
|
+
|
|
523
|
+
export class UsersCompositeRepository extends DynamoDBRepository<UserCompositeEntity> {
|
|
524
|
+
constructor(protected readonly client: DynamoDBDocumentClient) {
|
|
525
|
+
super(client, UserCompositeEntity);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
async findAllByOrg(orgId: string): Promise<UserCompositeEntity[]> {
|
|
529
|
+
const result = await this.query({
|
|
530
|
+
pk: `${orgId}#USER`, // assuming id = "USER"
|
|
531
|
+
});
|
|
532
|
+
return result.items;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
async findByCompositeKeys(orgId: string, id: string, role: string, email: string) {
|
|
536
|
+
return this.getItem(
|
|
537
|
+
`${orgId}#${id}`, // pk = orgId#id
|
|
538
|
+
`${role}#${email}`, // sk = role#email
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
```
|
|
543
|
+
|
|
420
544
|
## Type Definitions
|
|
421
545
|
|
|
422
546
|
### `DynamoKey`
|
package/dist/decorators.d.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import { DynamoEntityTarget } from "./types";
|
|
3
2
|
export declare const DYNAMO_TABLE_NAME_KEY = "dynamo:table:name";
|
|
4
3
|
export declare const DYNAMO_PARTITION_KEY_KEY = "dynamo:partition:key";
|
|
5
4
|
export declare const DYNAMO_SORT_KEY_KEY = "dynamo:sort:key";
|
|
6
5
|
export declare const DYNAMO_INDEX_PARTITION_KEYS_KEY = "dynamo:index:partition:keys";
|
|
7
6
|
export declare const DYNAMO_INDEX_SORT_KEYS_KEY = "dynamo:index:sort:keys";
|
|
7
|
+
export declare const DYNAMO_COMPOSITE_PARTITION_KEY_KEY = "dynamo:composite:partition:key";
|
|
8
|
+
export declare const DYNAMO_COMPOSITE_SORT_KEY_KEY = "dynamo:composite:sort:key";
|
|
8
9
|
export declare function DynamoTable(tableName?: string): ClassDecorator;
|
|
9
10
|
export declare function PartitionKey(fieldName?: string): PropertyDecorator;
|
|
11
|
+
export declare function CompositePartitionKey(pkName?: string): PropertyDecorator;
|
|
10
12
|
export declare function SortKey(fieldName?: string): PropertyDecorator;
|
|
13
|
+
export declare function CompositeSortKey(skName?: string): PropertyDecorator;
|
|
11
14
|
export declare function IndexPartitionKey(indexName: string, fieldName?: string): PropertyDecorator;
|
|
12
15
|
export declare function IndexSortKey(indexName: string, fieldName?: string): PropertyDecorator;
|
|
13
|
-
export declare function getDynamoTableName(target: DynamoEntityTarget): string | undefined;
|
|
14
|
-
export declare function getPartitionKeyName(target: DynamoEntityTarget): string | undefined;
|
|
15
|
-
export declare function getSortKeyName(target: DynamoEntityTarget): string | undefined;
|
|
16
|
-
export declare function getIndexPartitionKeyName(target: DynamoEntityTarget, indexName: string): string | undefined;
|
|
17
|
-
export declare function getIndexSortKeyName(target: DynamoEntityTarget, indexName: string): string | undefined;
|
|
18
16
|
//# sourceMappingURL=decorators.d.ts.map
|
package/dist/decorators.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAU1B,eAAO,MAAM,qBAAqB,sBAAsB,CAAC;AACzD,eAAO,MAAM,wBAAwB,yBAAyB,CAAC;AAC/D,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AACrD,eAAO,MAAM,+BAA+B,gCAAgC,CAAC;AAC7E,eAAO,MAAM,0BAA0B,2BAA2B,CAAC;AACnE,eAAO,MAAM,kCAAkC,mCACb,CAAC;AACnC,eAAO,MAAM,6BAA6B,8BAA8B,CAAC;AAwBzE,wBAAgB,WAAW,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,cAAc,CAc9D;AAqBD,wBAAgB,YAAY,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAyBlE;AAyBD,wBAAgB,qBAAqB,CACnC,MAAM,GAAE,MAAa,GACpB,iBAAiB,CAyDnB;AAuBD,wBAAgB,OAAO,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAyB7D;AAyBD,wBAAgB,gBAAgB,CAAC,MAAM,GAAE,MAAa,GAAG,iBAAiB,CAwDzE;AA2BD,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,GACjB,iBAAiB,CAyBnB;AA2BD,wBAAgB,YAAY,CAC1B,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,GACjB,iBAAiB,CAqBnB"}
|
package/dist/decorators.js
CHANGED
|
@@ -1,76 +1,128 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DYNAMO_INDEX_SORT_KEYS_KEY = exports.DYNAMO_INDEX_PARTITION_KEYS_KEY = exports.DYNAMO_SORT_KEY_KEY = exports.DYNAMO_PARTITION_KEY_KEY = exports.DYNAMO_TABLE_NAME_KEY = void 0;
|
|
3
|
+
exports.DYNAMO_COMPOSITE_SORT_KEY_KEY = exports.DYNAMO_COMPOSITE_PARTITION_KEY_KEY = exports.DYNAMO_INDEX_SORT_KEYS_KEY = exports.DYNAMO_INDEX_PARTITION_KEYS_KEY = exports.DYNAMO_SORT_KEY_KEY = exports.DYNAMO_PARTITION_KEY_KEY = exports.DYNAMO_TABLE_NAME_KEY = void 0;
|
|
4
4
|
exports.DynamoTable = DynamoTable;
|
|
5
5
|
exports.PartitionKey = PartitionKey;
|
|
6
|
+
exports.CompositePartitionKey = CompositePartitionKey;
|
|
6
7
|
exports.SortKey = SortKey;
|
|
8
|
+
exports.CompositeSortKey = CompositeSortKey;
|
|
7
9
|
exports.IndexPartitionKey = IndexPartitionKey;
|
|
8
10
|
exports.IndexSortKey = IndexSortKey;
|
|
9
|
-
exports.getDynamoTableName = getDynamoTableName;
|
|
10
|
-
exports.getPartitionKeyName = getPartitionKeyName;
|
|
11
|
-
exports.getSortKeyName = getSortKeyName;
|
|
12
|
-
exports.getIndexPartitionKeyName = getIndexPartitionKeyName;
|
|
13
|
-
exports.getIndexSortKeyName = getIndexSortKeyName;
|
|
14
11
|
require("reflect-metadata");
|
|
15
12
|
const exceptions_1 = require("./exceptions");
|
|
13
|
+
const helper_functions_1 = require("./helper-functions");
|
|
16
14
|
exports.DYNAMO_TABLE_NAME_KEY = "dynamo:table:name";
|
|
17
15
|
exports.DYNAMO_PARTITION_KEY_KEY = "dynamo:partition:key";
|
|
18
16
|
exports.DYNAMO_SORT_KEY_KEY = "dynamo:sort:key";
|
|
19
17
|
exports.DYNAMO_INDEX_PARTITION_KEYS_KEY = "dynamo:index:partition:keys";
|
|
20
18
|
exports.DYNAMO_INDEX_SORT_KEYS_KEY = "dynamo:index:sort:keys";
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
function getPrototype(target) {
|
|
25
|
-
return getConstructor(target).prototype;
|
|
26
|
-
}
|
|
27
|
-
function validateDuplicateDecorator(target, key, decoratorName, conflict) {
|
|
28
|
-
const existingKey = Reflect.getMetadata(key, target);
|
|
29
|
-
if (existingKey !== undefined) {
|
|
30
|
-
throw new exceptions_1.DuplicateDecoratorError(`Multiple ${decoratorName} decorators found in class "${target.constructor?.name || "Unknown"}". ` +
|
|
31
|
-
`Existing decorator: "${existingKey}", conflicting property: "${String(conflict)}"`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function validateNonEmptyString(value, paramName) {
|
|
35
|
-
if (value.trim() === "") {
|
|
36
|
-
throw new Error(`Invalid ${paramName}: cannot be an empty string.`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
19
|
+
exports.DYNAMO_COMPOSITE_PARTITION_KEY_KEY = "dynamo:composite:partition:key";
|
|
20
|
+
exports.DYNAMO_COMPOSITE_SORT_KEY_KEY = "dynamo:composite:sort:key";
|
|
39
21
|
function DynamoTable(tableName) {
|
|
40
22
|
return function (target) {
|
|
41
23
|
if (tableName) {
|
|
42
|
-
validateNonEmptyString(tableName, "tableName");
|
|
24
|
+
(0, helper_functions_1.validateNonEmptyString)(tableName, "tableName");
|
|
43
25
|
}
|
|
44
26
|
const dynamoTableName = tableName ?? target.name;
|
|
45
|
-
validateDuplicateDecorator(target, exports.DYNAMO_TABLE_NAME_KEY, "@DynamoTable", dynamoTableName);
|
|
27
|
+
(0, helper_functions_1.validateDuplicateDecorator)(target, exports.DYNAMO_TABLE_NAME_KEY, "@DynamoTable", dynamoTableName);
|
|
46
28
|
Reflect.defineMetadata(exports.DYNAMO_TABLE_NAME_KEY, dynamoTableName, target);
|
|
47
29
|
};
|
|
48
30
|
}
|
|
49
31
|
function PartitionKey(fieldName) {
|
|
50
32
|
return function (target, propertyKey) {
|
|
51
33
|
if (fieldName) {
|
|
52
|
-
validateNonEmptyString(fieldName, "fieldName");
|
|
34
|
+
(0, helper_functions_1.validateNonEmptyString)(fieldName, "fieldName");
|
|
53
35
|
}
|
|
54
36
|
const dynamoFieldName = fieldName ?? String(propertyKey);
|
|
55
|
-
|
|
37
|
+
const existingCompositeKeys = (0, helper_functions_1.getCompositePartitionKeyFields)(target);
|
|
38
|
+
if (existingCompositeKeys && existingCompositeKeys.length > 0) {
|
|
39
|
+
throw new exceptions_1.DuplicateDecoratorError(`Cannot use @PartitionKey with @CompositePartitionKey in class "${target.constructor?.name || "Unknown"}". ` +
|
|
40
|
+
`An entity can only have either a single @PartitionKey or multiple @CompositePartitionKey decorators, not both.`);
|
|
41
|
+
}
|
|
42
|
+
(0, helper_functions_1.validateDuplicateDecorator)(target, exports.DYNAMO_PARTITION_KEY_KEY, "@PartitionKey", dynamoFieldName);
|
|
56
43
|
Reflect.defineMetadata(exports.DYNAMO_PARTITION_KEY_KEY, dynamoFieldName, target);
|
|
57
44
|
};
|
|
58
45
|
}
|
|
46
|
+
function CompositePartitionKey(pkName = "pk") {
|
|
47
|
+
return function (target, propertyKey) {
|
|
48
|
+
if (pkName) {
|
|
49
|
+
(0, helper_functions_1.validateNonEmptyString)(pkName, "pkName");
|
|
50
|
+
}
|
|
51
|
+
const fieldName = String(propertyKey);
|
|
52
|
+
const existingPartitionKey = Reflect.getMetadata(exports.DYNAMO_PARTITION_KEY_KEY, target);
|
|
53
|
+
if (existingPartitionKey) {
|
|
54
|
+
throw new exceptions_1.DuplicateDecoratorError(`Cannot use @CompositePartitionKey with @PartitionKey in class "${target.constructor?.name || "Unknown"}". ` +
|
|
55
|
+
`An entity can only have either a single @PartitionKey or multiple @CompositePartitionKey decorators, not both.`);
|
|
56
|
+
}
|
|
57
|
+
const existingCompositeKeys = Reflect.getMetadata(exports.DYNAMO_COMPOSITE_PARTITION_KEY_KEY, target);
|
|
58
|
+
if (!existingCompositeKeys) {
|
|
59
|
+
Reflect.defineMetadata(exports.DYNAMO_COMPOSITE_PARTITION_KEY_KEY, { name: pkName, fields: [fieldName] }, target);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (existingCompositeKeys.name !== pkName) {
|
|
63
|
+
throw new exceptions_1.DuplicateDecoratorError(`Cannot use multiple composite partition key groups in class "${target.constructor?.name || "Unknown"}". ` +
|
|
64
|
+
`Existing composite key group: "${existingCompositeKeys.name}", conflicting group: "${pkName}". ` +
|
|
65
|
+
`All @CompositePartitionKey decorators must use the same pkName.`);
|
|
66
|
+
}
|
|
67
|
+
if (existingCompositeKeys.fields !== undefined) {
|
|
68
|
+
if (existingCompositeKeys.fields.includes(fieldName)) {
|
|
69
|
+
throw new exceptions_1.DuplicateDecoratorError(`Property "${fieldName}" is already part of composite key "${pkName}" in class "${target.constructor?.name || "Unknown"}".`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
existingCompositeKeys.fields.push(fieldName);
|
|
73
|
+
Reflect.defineMetadata(exports.DYNAMO_COMPOSITE_PARTITION_KEY_KEY, existingCompositeKeys, target);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
59
76
|
function SortKey(fieldName) {
|
|
60
77
|
return function (target, propertyKey) {
|
|
61
78
|
if (fieldName) {
|
|
62
|
-
validateNonEmptyString(fieldName, "fieldName");
|
|
79
|
+
(0, helper_functions_1.validateNonEmptyString)(fieldName, "fieldName");
|
|
63
80
|
}
|
|
64
81
|
const dynamoFieldName = fieldName ?? String(propertyKey);
|
|
65
|
-
|
|
82
|
+
const existingCompositeSortKeys = (0, helper_functions_1.getCompositeSortKeyFields)(target);
|
|
83
|
+
if (existingCompositeSortKeys && existingCompositeSortKeys.length > 0) {
|
|
84
|
+
throw new exceptions_1.DuplicateDecoratorError(`Cannot use @SortKey with @CompositeSortKey in class "${target.constructor?.name || "Unknown"}". ` +
|
|
85
|
+
`An entity can only have either a single @SortKey or multiple @CompositeSortKey decorators, not both.`);
|
|
86
|
+
}
|
|
87
|
+
(0, helper_functions_1.validateDuplicateDecorator)(target, exports.DYNAMO_SORT_KEY_KEY, "@SortKey", propertyKey);
|
|
66
88
|
Reflect.defineMetadata(exports.DYNAMO_SORT_KEY_KEY, dynamoFieldName, target);
|
|
67
89
|
};
|
|
68
90
|
}
|
|
91
|
+
function CompositeSortKey(skName = "sk") {
|
|
92
|
+
return function (target, propertyKey) {
|
|
93
|
+
if (skName) {
|
|
94
|
+
(0, helper_functions_1.validateNonEmptyString)(skName, "skName");
|
|
95
|
+
}
|
|
96
|
+
const fieldName = String(propertyKey);
|
|
97
|
+
const existingSortKey = Reflect.getMetadata(exports.DYNAMO_SORT_KEY_KEY, target);
|
|
98
|
+
if (existingSortKey) {
|
|
99
|
+
throw new exceptions_1.DuplicateDecoratorError(`Cannot use @CompositeSortKey with @SortKey in class "${target.constructor?.name || "Unknown"}". ` +
|
|
100
|
+
`An entity can only have either a single @SortKey or multiple @CompositeSortKey decorators, not both.`);
|
|
101
|
+
}
|
|
102
|
+
const existingCompositeKeys = Reflect.getMetadata(exports.DYNAMO_COMPOSITE_SORT_KEY_KEY, target);
|
|
103
|
+
if (!existingCompositeKeys) {
|
|
104
|
+
Reflect.defineMetadata(exports.DYNAMO_COMPOSITE_SORT_KEY_KEY, { name: skName, fields: [fieldName] }, target);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (existingCompositeKeys.name !== skName) {
|
|
108
|
+
throw new exceptions_1.DuplicateDecoratorError(`Cannot use multiple composite sort key groups in class "${target.constructor?.name || "Unknown"}". ` +
|
|
109
|
+
`Existing composite key group: "${existingCompositeKeys.name}", conflicting group: "${skName}". ` +
|
|
110
|
+
`All @CompositeSortKey decorators must use the same skName.`);
|
|
111
|
+
}
|
|
112
|
+
if (existingCompositeKeys.fields !== undefined) {
|
|
113
|
+
if (existingCompositeKeys.fields.includes(fieldName)) {
|
|
114
|
+
throw new exceptions_1.DuplicateDecoratorError(`Property "${fieldName}" is already part of composite sort key "${skName}" in class "${target.constructor?.name || "Unknown"}".`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
existingCompositeKeys.fields.push(fieldName);
|
|
118
|
+
Reflect.defineMetadata(exports.DYNAMO_COMPOSITE_SORT_KEY_KEY, existingCompositeKeys, target);
|
|
119
|
+
};
|
|
120
|
+
}
|
|
69
121
|
function IndexPartitionKey(indexName, fieldName) {
|
|
70
122
|
return function (target, propertyKey) {
|
|
71
|
-
validateNonEmptyString(indexName, "indexName");
|
|
123
|
+
(0, helper_functions_1.validateNonEmptyString)(indexName, "indexName");
|
|
72
124
|
if (fieldName) {
|
|
73
|
-
validateNonEmptyString(fieldName, "fieldName");
|
|
125
|
+
(0, helper_functions_1.validateNonEmptyString)(fieldName, "fieldName");
|
|
74
126
|
}
|
|
75
127
|
const dynamoFieldName = fieldName ?? String(propertyKey);
|
|
76
128
|
const existingKeys = Reflect.getMetadata(exports.DYNAMO_INDEX_PARTITION_KEYS_KEY, target) ?? {};
|
|
@@ -84,9 +136,9 @@ function IndexPartitionKey(indexName, fieldName) {
|
|
|
84
136
|
}
|
|
85
137
|
function IndexSortKey(indexName, fieldName) {
|
|
86
138
|
return function (target, propertyKey) {
|
|
87
|
-
validateNonEmptyString(indexName, "indexName");
|
|
139
|
+
(0, helper_functions_1.validateNonEmptyString)(indexName, "indexName");
|
|
88
140
|
if (fieldName) {
|
|
89
|
-
validateNonEmptyString(fieldName, "fieldName");
|
|
141
|
+
(0, helper_functions_1.validateNonEmptyString)(fieldName, "fieldName");
|
|
90
142
|
}
|
|
91
143
|
const dynamoFieldName = fieldName ?? String(propertyKey);
|
|
92
144
|
const existingKeys = Reflect.getMetadata(exports.DYNAMO_INDEX_SORT_KEYS_KEY, target) ?? {};
|
|
@@ -98,32 +150,4 @@ function IndexSortKey(indexName, fieldName) {
|
|
|
98
150
|
Reflect.defineMetadata(exports.DYNAMO_INDEX_SORT_KEYS_KEY, existingKeys, target);
|
|
99
151
|
};
|
|
100
152
|
}
|
|
101
|
-
function getDynamoTableName(target) {
|
|
102
|
-
const constructor = getConstructor(target);
|
|
103
|
-
return Reflect.getMetadata(exports.DYNAMO_TABLE_NAME_KEY, constructor);
|
|
104
|
-
}
|
|
105
|
-
function getPartitionKeyName(target) {
|
|
106
|
-
const prototype = getPrototype(target);
|
|
107
|
-
return Reflect.getMetadata(exports.DYNAMO_PARTITION_KEY_KEY, prototype);
|
|
108
|
-
}
|
|
109
|
-
function getSortKeyName(target) {
|
|
110
|
-
const prototype = getPrototype(target);
|
|
111
|
-
return Reflect.getMetadata(exports.DYNAMO_SORT_KEY_KEY, prototype);
|
|
112
|
-
}
|
|
113
|
-
function getIndexPartitionKeyName(target, indexName) {
|
|
114
|
-
if (!indexName || indexName.trim() === "") {
|
|
115
|
-
throw new Error("indexName cannot be empty");
|
|
116
|
-
}
|
|
117
|
-
const prototype = getPrototype(target);
|
|
118
|
-
const indexKeys = Reflect.getMetadata(exports.DYNAMO_INDEX_PARTITION_KEYS_KEY, prototype);
|
|
119
|
-
return indexKeys?.[indexName];
|
|
120
|
-
}
|
|
121
|
-
function getIndexSortKeyName(target, indexName) {
|
|
122
|
-
if (!indexName || indexName.trim() === "") {
|
|
123
|
-
throw new Error("indexName cannot be empty");
|
|
124
|
-
}
|
|
125
|
-
const prototype = getPrototype(target);
|
|
126
|
-
const indexKeys = Reflect.getMetadata(exports.DYNAMO_INDEX_SORT_KEYS_KEY, prototype);
|
|
127
|
-
return indexKeys?.[indexName];
|
|
128
|
-
}
|
|
129
153
|
//# sourceMappingURL=decorators.js.map
|
package/dist/decorators.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":";;;AAyCA,kCAcC;AAqBD,oCAyBC;AAyBD,sDA2DC;AAuBD,0BAyBC;AAyBD,4CAwDC;AA2BD,8CA4BC;AA2BD,oCAwBC;AApaD,4BAA0B;AAC1B,6CAAuD;AAEvD,yDAK4B;AAEf,QAAA,qBAAqB,GAAG,mBAAmB,CAAC;AAC5C,QAAA,wBAAwB,GAAG,sBAAsB,CAAC;AAClD,QAAA,mBAAmB,GAAG,iBAAiB,CAAC;AACxC,QAAA,+BAA+B,GAAG,6BAA6B,CAAC;AAChE,QAAA,0BAA0B,G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,IAAI,SAAS,KAAK;gBACtH,uBAAuB,YAAY,CAAC,SAAS,CAAC,6BAA6B,MAAM,CAAC,WAAW,CAAC,GAAG,CACpG,CAAC;QACJ,CAAC;QACD,YAAY,CAAC,SAAS,CAAC,GAAG,eAAe,CAAC;QAC1C,OAAO,CAAC,cAAc,CAAC,kCAA0B,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IAC3E,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-example2.d.ts","sourceRoot":"","sources":["../src/entity-example2.ts"],"names":[],"mappings":"AAMA,qBACa,UAAU;IAErB,KAAK,EAAG,MAAM,CAAC;IAEf,EAAE,EAAE,MAAM,CAAiB;IAE3B,IAAI,EAAE,MAAM,CAAU;IAEtB,KAAK,EAAG,MAAM,CAAC;IACf,QAAQ,EAAG,MAAM,CAAC;IAClB,SAAS,EAAG,MAAM,CAAC;IACnB,SAAS,EAAG,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UserEntity = void 0;
|
|
13
|
+
const decorators_1 = require("./decorators");
|
|
14
|
+
let UserEntity = class UserEntity {
|
|
15
|
+
orgId;
|
|
16
|
+
id = "generate-id";
|
|
17
|
+
role = "USER";
|
|
18
|
+
email;
|
|
19
|
+
password;
|
|
20
|
+
createdAt;
|
|
21
|
+
updatedAt;
|
|
22
|
+
deletedAt;
|
|
23
|
+
};
|
|
24
|
+
exports.UserEntity = UserEntity;
|
|
25
|
+
__decorate([
|
|
26
|
+
(0, decorators_1.CompositePartitionKey)("pk"),
|
|
27
|
+
__metadata("design:type", String)
|
|
28
|
+
], UserEntity.prototype, "orgId", void 0);
|
|
29
|
+
__decorate([
|
|
30
|
+
(0, decorators_1.CompositePartitionKey)("pk"),
|
|
31
|
+
__metadata("design:type", String)
|
|
32
|
+
], UserEntity.prototype, "id", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, decorators_1.CompositeSortKey)("sk"),
|
|
35
|
+
__metadata("design:type", String)
|
|
36
|
+
], UserEntity.prototype, "role", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, decorators_1.CompositeSortKey)("sk"),
|
|
39
|
+
__metadata("design:type", String)
|
|
40
|
+
], UserEntity.prototype, "email", void 0);
|
|
41
|
+
exports.UserEntity = UserEntity = __decorate([
|
|
42
|
+
(0, decorators_1.DynamoTable)("User")
|
|
43
|
+
], UserEntity);
|
|
44
|
+
//# sourceMappingURL=entity-example2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-example2.js","sourceRoot":"","sources":["../src/entity-example2.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAIsB;AAGf,IAAM,UAAU,GAAhB,MAAM,UAAU;IAErB,KAAK,CAAU;IAEf,EAAE,GAAW,aAAa,CAAC;IAE3B,IAAI,GAAW,MAAM,CAAC;IAEtB,KAAK,CAAU;IACf,QAAQ,CAAU;IAClB,SAAS,CAAU;IACnB,SAAS,CAAU;IACnB,SAAS,CAAsB;CAChC,CAAA;AAbY,gCAAU;AAErB;IADC,IAAA,kCAAqB,EAAC,IAAI,CAAC;;yCACb;AAEf;IADC,IAAA,kCAAqB,EAAC,IAAI,CAAC;;sCACD;AAE3B;IADC,IAAA,6BAAgB,EAAC,IAAI,CAAC;;wCACD;AAEtB;IADC,IAAA,6BAAgB,EAAC,IAAI,CAAC;;yCACR;qBARJ,UAAU;IADtB,IAAA,wBAAW,EAAC,MAAM,CAAC;GACP,UAAU,CAatB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { DynamoEntityTarget } from "./types";
|
|
3
|
+
export declare function getConstructor(target: DynamoEntityTarget): NewableFunction;
|
|
4
|
+
export declare function getPrototype(target: DynamoEntityTarget): object;
|
|
5
|
+
export declare function validateDuplicateDecorator(target: object, key: string, decoratorName: string, conflict: string | symbol): void;
|
|
6
|
+
export declare function validateNonEmptyString(value: string, paramName: string): void;
|
|
7
|
+
export declare function getDynamoTableName(target: DynamoEntityTarget): string | undefined;
|
|
8
|
+
export declare function getPartitionKeyName(target: DynamoEntityTarget): string | undefined;
|
|
9
|
+
export declare function getSortKeyName(target: DynamoEntityTarget): string | undefined;
|
|
10
|
+
export declare function getIndexPartitionKeyName(target: DynamoEntityTarget, indexName: string): string | undefined;
|
|
11
|
+
export declare function getIndexSortKeyName(target: DynamoEntityTarget, indexName: string): string | undefined;
|
|
12
|
+
export declare function getCompositePartitionKeyFields(target: DynamoEntityTarget): string[] | undefined;
|
|
13
|
+
export declare function getCompositeSortKeyFields(target: DynamoEntityTarget): string[] | undefined;
|
|
14
|
+
//# sourceMappingURL=helper-functions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper-functions.d.ts","sourceRoot":"","sources":["../src/helper-functions.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAqB,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAchE,wBAAgB,cAAc,CAAC,MAAM,EAAE,kBAAkB,GAAG,eAAe,CAE1E;AAKD,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,CAE/D;AAKD,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,GAAG,MAAM,QAS1B;AAKD,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAI7E;AAeD,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,kBAAkB,GACzB,MAAM,GAAG,SAAS,CAKpB;AAeD,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,kBAAkB,GACzB,MAAM,GAAG,SAAS,CAcpB;AAeD,wBAAgB,cAAc,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,GAAG,SAAS,CAc7E;AAgBD,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,kBAAkB,EAC1B,SAAS,EAAE,MAAM,GAChB,MAAM,GAAG,SAAS,CAUpB;AAgBD,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,kBAAkB,EAC1B,SAAS,EAAE,MAAM,GAChB,MAAM,GAAG,SAAS,CAUpB;AAcD,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,kBAAkB,GACzB,MAAM,EAAE,GAAG,SAAS,CAOtB;AAcD,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,kBAAkB,GACzB,MAAM,EAAE,GAAG,SAAS,CAOtB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getConstructor = getConstructor;
|
|
4
|
+
exports.getPrototype = getPrototype;
|
|
5
|
+
exports.validateDuplicateDecorator = validateDuplicateDecorator;
|
|
6
|
+
exports.validateNonEmptyString = validateNonEmptyString;
|
|
7
|
+
exports.getDynamoTableName = getDynamoTableName;
|
|
8
|
+
exports.getPartitionKeyName = getPartitionKeyName;
|
|
9
|
+
exports.getSortKeyName = getSortKeyName;
|
|
10
|
+
exports.getIndexPartitionKeyName = getIndexPartitionKeyName;
|
|
11
|
+
exports.getIndexSortKeyName = getIndexSortKeyName;
|
|
12
|
+
exports.getCompositePartitionKeyFields = getCompositePartitionKeyFields;
|
|
13
|
+
exports.getCompositeSortKeyFields = getCompositeSortKeyFields;
|
|
14
|
+
require("reflect-metadata");
|
|
15
|
+
const exceptions_1 = require("./exceptions");
|
|
16
|
+
const decorators_1 = require("./decorators");
|
|
17
|
+
function getConstructor(target) {
|
|
18
|
+
return typeof target === "function" ? target : target.constructor;
|
|
19
|
+
}
|
|
20
|
+
function getPrototype(target) {
|
|
21
|
+
return getConstructor(target).prototype;
|
|
22
|
+
}
|
|
23
|
+
function validateDuplicateDecorator(target, key, decoratorName, conflict) {
|
|
24
|
+
const existingKey = Reflect.getMetadata(key, target);
|
|
25
|
+
if (existingKey !== undefined) {
|
|
26
|
+
throw new exceptions_1.DuplicateDecoratorError(`Multiple ${decoratorName} decorators found in class "${target.constructor?.name || "Unknown"}". ` +
|
|
27
|
+
`Existing decorator: "${existingKey}", conflicting property: "${String(conflict)}"`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function validateNonEmptyString(value, paramName) {
|
|
31
|
+
if (value.trim() === "") {
|
|
32
|
+
throw new Error(`Invalid ${paramName}: cannot be an empty string.`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function getDynamoTableName(target) {
|
|
36
|
+
const constructor = getConstructor(target);
|
|
37
|
+
return Reflect.getMetadata(decorators_1.DYNAMO_TABLE_NAME_KEY, constructor);
|
|
38
|
+
}
|
|
39
|
+
function getPartitionKeyName(target) {
|
|
40
|
+
const prototype = getPrototype(target);
|
|
41
|
+
const simplePK = Reflect.getMetadata(decorators_1.DYNAMO_PARTITION_KEY_KEY, prototype);
|
|
42
|
+
if (simplePK)
|
|
43
|
+
return simplePK;
|
|
44
|
+
const compositePK = Reflect.getMetadata(decorators_1.DYNAMO_COMPOSITE_PARTITION_KEY_KEY, prototype);
|
|
45
|
+
return compositePK?.name;
|
|
46
|
+
}
|
|
47
|
+
function getSortKeyName(target) {
|
|
48
|
+
const prototype = getPrototype(target);
|
|
49
|
+
const simpleSK = Reflect.getMetadata(decorators_1.DYNAMO_SORT_KEY_KEY, prototype);
|
|
50
|
+
if (simpleSK)
|
|
51
|
+
return simpleSK;
|
|
52
|
+
const compositeSK = Reflect.getMetadata(decorators_1.DYNAMO_COMPOSITE_SORT_KEY_KEY, prototype);
|
|
53
|
+
return compositeSK?.name;
|
|
54
|
+
}
|
|
55
|
+
function getIndexPartitionKeyName(target, indexName) {
|
|
56
|
+
if (!indexName || indexName.trim() === "") {
|
|
57
|
+
throw new Error("indexName cannot be empty");
|
|
58
|
+
}
|
|
59
|
+
const prototype = getPrototype(target);
|
|
60
|
+
const indexKeys = Reflect.getMetadata(decorators_1.DYNAMO_INDEX_PARTITION_KEYS_KEY, prototype);
|
|
61
|
+
return indexKeys?.[indexName];
|
|
62
|
+
}
|
|
63
|
+
function getIndexSortKeyName(target, indexName) {
|
|
64
|
+
if (!indexName || indexName.trim() === "") {
|
|
65
|
+
throw new Error("indexName cannot be empty");
|
|
66
|
+
}
|
|
67
|
+
const prototype = getPrototype(target);
|
|
68
|
+
const indexKeys = Reflect.getMetadata(decorators_1.DYNAMO_INDEX_SORT_KEYS_KEY, prototype);
|
|
69
|
+
return indexKeys?.[indexName];
|
|
70
|
+
}
|
|
71
|
+
function getCompositePartitionKeyFields(target) {
|
|
72
|
+
const prototype = getPrototype(target);
|
|
73
|
+
const compositeKey = Reflect.getMetadata(decorators_1.DYNAMO_COMPOSITE_PARTITION_KEY_KEY, prototype);
|
|
74
|
+
return compositeKey?.fields;
|
|
75
|
+
}
|
|
76
|
+
function getCompositeSortKeyFields(target) {
|
|
77
|
+
const prototype = getPrototype(target);
|
|
78
|
+
const compositeKey = Reflect.getMetadata(decorators_1.DYNAMO_COMPOSITE_SORT_KEY_KEY, prototype);
|
|
79
|
+
return compositeKey?.fields;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=helper-functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper-functions.js","sourceRoot":"","sources":["../src/helper-functions.ts"],"names":[],"mappings":";;AAgBA,wCAEC;AAKD,oCAEC;AAKD,gEAaC;AAKD,wDAIC;AAeD,gDAOC;AAeD,kDAgBC;AAeD,wCAcC;AAgBD,4DAaC;AAgBD,kDAaC;AAcD,wEASC;AAcD,8DASC;AA9OD,4BAA0B;AAC1B,6CAAuD;AAEvD,6CAQsB;AAKtB,SAAgB,cAAc,CAAC,MAA0B;IACvD,OAAO,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC;AACpE,CAAC;AAKD,SAAgB,YAAY,CAAC,MAA0B;IACrD,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC,SAAmB,CAAC;AACpD,CAAC;AAKD,SAAgB,0BAA0B,CACxC,MAAc,EACd,GAAW,EACX,aAAqB,EACrB,QAAyB;IAEzB,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,CAAuB,CAAC;IAC3E,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,IAAI,oCAAuB,CAC/B,YAAY,aAAa,+BAA+B,MAAM,CAAC,WAAW,EAAE,IAAI,IAAI,SAAS,KAAK;YAChG,wBAAwB,WAAW,6BAA6B,MAAM,CAAC,QAAQ,CAAC,GAAG,CACtF,CAAC;IACJ,CAAC;AACH,CAAC;AAKD,SAAgB,sBAAsB,CAAC,KAAa,EAAE,SAAiB;IACrE,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACxB,MA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WAAW,CACnC,4CAA+B,EAC/B,SAAS,CAC4B,CAAC;IACxC,OAAO,SAAS,EAAE,CAAC,SAAS,CAAC,CAAC;AAChC,CAAC;AAgBD,SAAgB,mBAAmB,CACjC,MAA0B,EAC1B,SAAiB;IAEjB,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;IACD,MAAM,SAAS,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACvC,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CACnC,uCAA0B,EAC1B,SAAS,CAC4B,CAAC;IACxC,OAAO,SAAS,EAAE,CAAC,SAAS,CAAC,CAAC;AAChC,CAAC;AAcD,SAAgB,8BAA8B,CAC5C,MAA0B;IAE1B,MAAM,SAAS,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACvC,MAAM,YAAY,GAAG,OAAO,CAAC,WAAW,CACtC,+CAAkC,EAClC,SAAS,CACuB,CAAC;IACnC,OAAO,YAAY,EAAE,MAAM,CAAC;AAC9B,CAAC;AAcD,SAAgB,yBAAyB,CACvC,MAA0B;IAE1B,MAAM,SAAS,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACvC,MAAM,YAAY,GAAG,OAAO,CAAC,WAAW,CACtC,0CAA6B,EAC7B,SAAS,CACuB,CAAC;IACnC,OAAO,YAAY,EAAE,MAAM,CAAC;AAC9B,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { DynamoDBRepository } from "./simple-dynamodb-repository";
|
|
2
|
-
export { DynamoTable, PartitionKey,
|
|
3
|
-
export
|
|
2
|
+
export { DynamoTable, PartitionKey, CompositePartitionKey, CompositeSortKey, SortKey, IndexPartitionKey, IndexSortKey, } from "./decorators";
|
|
3
|
+
export { getDynamoTableName, getPartitionKeyName, getCompositePartitionKeyFields, getCompositeSortKeyFields, getSortKeyName, getIndexPartitionKeyName, getIndexSortKeyName, } from "./helper-functions";
|
|
4
|
+
export type { QueryOptions, DynamoKey, DynamoKeyMap, CompositeKeyGroup, } from "./types";
|
|
4
5
|
export { ItemNotFoundError, InvalidParametersError, DecoratorMissingError, DuplicateDecoratorError, } from "./exceptions";
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGlE,OAAO,EACL,WAAW,EACX,YAAY,EACZ,OAAO,EACP,iBAAiB,EACjB,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGlE,OAAO,EACL,WAAW,EACX,YAAY,EACZ,qBAAqB,EACrB,gBAAgB,EAChB,OAAO,EACP,iBAAiB,EACjB,YAAY,GACb,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,8BAA8B,EAC9B,yBAAyB,EACzB,cAAc,EACd,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC;AAG5B,YAAY,EACV,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,iBAAiB,GAClB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,cAAc,CAAC"}
|