@lafken/dynamo 0.10.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/LICENCE +21 -0
- package/README.md +503 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +19 -0
- package/lib/main/index.d.ts +1 -0
- package/lib/main/index.js +17 -0
- package/lib/main/table/index.d.ts +2 -0
- package/lib/main/table/index.js +18 -0
- package/lib/main/table/table.d.ts +107 -0
- package/lib/main/table/table.js +141 -0
- package/lib/main/table/table.types.d.ts +368 -0
- package/lib/main/table/table.types.js +15 -0
- package/lib/resolver/index.d.ts +1 -0
- package/lib/resolver/index.js +17 -0
- package/lib/resolver/resolver.d.ts +12 -0
- package/lib/resolver/resolver.js +48 -0
- package/lib/resolver/resolver.types.d.ts +13 -0
- package/lib/resolver/resolver.types.js +2 -0
- package/lib/resolver/table/external/external.d.ts +14 -0
- package/lib/resolver/table/external/external.js +15 -0
- package/lib/resolver/table/internal/internal.d.ts +19 -0
- package/lib/resolver/table/internal/internal.js +224 -0
- package/lib/resolver/table/table.types.d.ts +4 -0
- package/lib/resolver/table/table.types.js +2 -0
- package/lib/service/client/client.d.ts +3 -0
- package/lib/service/client/client.js +10 -0
- package/lib/service/index.d.ts +3 -0
- package/lib/service/index.js +19 -0
- package/lib/service/query-builder/base/base.d.ts +19 -0
- package/lib/service/query-builder/base/base.js +151 -0
- package/lib/service/query-builder/base/base.types.d.ts +37 -0
- package/lib/service/query-builder/base/base.types.js +2 -0
- package/lib/service/query-builder/base/base.utils.d.ts +22 -0
- package/lib/service/query-builder/base/base.utils.js +89 -0
- package/lib/service/query-builder/batch-write/batch-write.d.ts +15 -0
- package/lib/service/query-builder/batch-write/batch-write.js +51 -0
- package/lib/service/query-builder/batch-write/batch-write.types.d.ts +9 -0
- package/lib/service/query-builder/batch-write/batch-write.types.js +2 -0
- package/lib/service/query-builder/bulk-create/bulk-create.d.ts +6 -0
- package/lib/service/query-builder/bulk-create/bulk-create.js +26 -0
- package/lib/service/query-builder/bulk-create/bulk-create.types.d.ts +4 -0
- package/lib/service/query-builder/bulk-create/bulk-create.types.js +2 -0
- package/lib/service/query-builder/bulk-delete/bulk-delete.d.ts +6 -0
- package/lib/service/query-builder/bulk-delete/bulk-delete.js +27 -0
- package/lib/service/query-builder/bulk-delete/bulk-delete.types.d.ts +7 -0
- package/lib/service/query-builder/bulk-delete/bulk-delete.types.js +2 -0
- package/lib/service/query-builder/create/create.d.ts +6 -0
- package/lib/service/query-builder/create/create.js +22 -0
- package/lib/service/query-builder/create/create.types.d.ts +6 -0
- package/lib/service/query-builder/create/create.types.js +2 -0
- package/lib/service/query-builder/delete/delete.d.ts +13 -0
- package/lib/service/query-builder/delete/delete.js +33 -0
- package/lib/service/query-builder/delete/delete.types.d.ts +7 -0
- package/lib/service/query-builder/delete/delete.types.js +2 -0
- package/lib/service/query-builder/dynamo-index/dynamo-index.d.ts +15 -0
- package/lib/service/query-builder/dynamo-index/dynamo-index.js +90 -0
- package/lib/service/query-builder/dynamo-index/dynamo-index.types.d.ts +5 -0
- package/lib/service/query-builder/dynamo-index/dynamo-index.types.js +2 -0
- package/lib/service/query-builder/find/find.d.ts +13 -0
- package/lib/service/query-builder/find/find.js +63 -0
- package/lib/service/query-builder/find/find.types.d.ts +8 -0
- package/lib/service/query-builder/find/find.types.js +2 -0
- package/lib/service/query-builder/find-all/find-all.d.ts +10 -0
- package/lib/service/query-builder/find-all/find-all.js +19 -0
- package/lib/service/query-builder/find-one/find-one.d.ts +9 -0
- package/lib/service/query-builder/find-one/find-one.js +20 -0
- package/lib/service/query-builder/index.d.ts +1 -0
- package/lib/service/query-builder/index.js +17 -0
- package/lib/service/query-builder/query-builder.types.d.ts +243 -0
- package/lib/service/query-builder/query-builder.types.js +3 -0
- package/lib/service/query-builder/scan/scan.d.ts +15 -0
- package/lib/service/query-builder/scan/scan.js +57 -0
- package/lib/service/query-builder/scan/scan.types.d.ts +6 -0
- package/lib/service/query-builder/scan/scan.types.js +2 -0
- package/lib/service/query-builder/update/update.d.ts +15 -0
- package/lib/service/query-builder/update/update.js +101 -0
- package/lib/service/query-builder/update/update.types.d.ts +6 -0
- package/lib/service/query-builder/update/update.types.js +2 -0
- package/lib/service/query-builder/update/update.utils.d.ts +11 -0
- package/lib/service/query-builder/update/update.utils.js +22 -0
- package/lib/service/query-builder/upsert/upsert.d.ts +14 -0
- package/lib/service/query-builder/upsert/upsert.js +40 -0
- package/lib/service/query-builder/upsert/upsert.types.d.ts +7 -0
- package/lib/service/query-builder/upsert/upsert.types.js +2 -0
- package/lib/service/repository/index.d.ts +3 -0
- package/lib/service/repository/index.js +19 -0
- package/lib/service/repository/repository.d.ts +3 -0
- package/lib/service/repository/repository.js +89 -0
- package/lib/service/repository/repository.types.d.ts +23 -0
- package/lib/service/repository/repository.types.js +2 -0
- package/lib/service/repository/repository.utils.d.ts +9 -0
- package/lib/service/repository/repository.utils.js +17 -0
- package/lib/service/transaction/index.d.ts +2 -0
- package/lib/service/transaction/index.js +18 -0
- package/lib/service/transaction/transaction.d.ts +4 -0
- package/lib/service/transaction/transaction.js +38 -0
- package/lib/service/transaction/transaction.types.d.ts +5 -0
- package/lib/service/transaction/transaction.types.js +2 -0
- package/package.json +99 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SortKey = exports.PartitionKey = exports.Field = exports.Table = void 0;
|
|
4
|
+
const common_1 = require("@lafken/common");
|
|
5
|
+
const table_types_1 = require("./table.types");
|
|
6
|
+
/**
|
|
7
|
+
* Class decorator that registers a class as a DynamoDB table resource.
|
|
8
|
+
*
|
|
9
|
+
* The decorated class represents a DynamoDB table and its schema.
|
|
10
|
+
* Use `@PartitionKey`, `@SortKey`, and `@Field` on the class
|
|
11
|
+
* properties to define the table structure. Options such as billing
|
|
12
|
+
* mode, indexes, streams, TTL, and replicas can be set through the
|
|
13
|
+
* decorator props.
|
|
14
|
+
*
|
|
15
|
+
* @typeParam T - The class being decorated.
|
|
16
|
+
* @param props - Optional table configuration. If omitted, the class
|
|
17
|
+
* name is used as the table name with pay-per-request billing.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* @Table({ stream: { enabled: true, type: 'NEW_AND_OLD_IMAGES' } })
|
|
22
|
+
* export class UserTable {
|
|
23
|
+
* @PartitionKey(String)
|
|
24
|
+
* id: PrimaryPartition<string>;
|
|
25
|
+
*
|
|
26
|
+
* @SortKey(Number)
|
|
27
|
+
* createdAt: PrimaryPartition<string>;
|
|
28
|
+
*
|
|
29
|
+
* @Field()
|
|
30
|
+
* email: string;
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
const Table = (props = {}) => (constructor) => {
|
|
35
|
+
const { name = constructor.name, indexes = [], ...dynamoProps } = props;
|
|
36
|
+
Reflect.defineMetadata(table_types_1.TableMetadataKeys.table, {
|
|
37
|
+
...dynamoProps,
|
|
38
|
+
name,
|
|
39
|
+
indexes,
|
|
40
|
+
}, constructor);
|
|
41
|
+
};
|
|
42
|
+
exports.Table = Table;
|
|
43
|
+
/**
|
|
44
|
+
* Property decorator that registers a class field as a DynamoDB
|
|
45
|
+
* table attribute.
|
|
46
|
+
*
|
|
47
|
+
* The attribute type is inferred from the property's TypeScript type
|
|
48
|
+
* by default, but can be overridden via the `type` option. Use this
|
|
49
|
+
* decorator for regular attributes that are neither the partition key
|
|
50
|
+
* nor the sort key.
|
|
51
|
+
*
|
|
52
|
+
* @param props - Optional field configuration.
|
|
53
|
+
* @param props.type - Explicit type override (`String`, `Number`, `Boolean`,
|
|
54
|
+
* a class, or an array wrapper).
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* @Table()
|
|
59
|
+
* export class OrderTable {
|
|
60
|
+
* @PartitionKey(String)
|
|
61
|
+
* id: string;
|
|
62
|
+
*
|
|
63
|
+
* @Field()
|
|
64
|
+
* status: string;
|
|
65
|
+
*
|
|
66
|
+
* @Field({ type: Number })
|
|
67
|
+
* total: number;
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
const Field = (props = {}) => (constructor, name) => {
|
|
72
|
+
const { type: fieldType } = props;
|
|
73
|
+
const fields = Reflect.getMetadata(table_types_1.TableMetadataKeys.fields, constructor) || {};
|
|
74
|
+
const type = fieldType
|
|
75
|
+
? (0, common_1.getPrimitiveType)(fieldType) || 'Object'
|
|
76
|
+
: Reflect.getMetadata('design:type', constructor, name).name;
|
|
77
|
+
Reflect.defineMetadata(table_types_1.TableMetadataKeys.fields, {
|
|
78
|
+
...fields,
|
|
79
|
+
[name]: {
|
|
80
|
+
name,
|
|
81
|
+
type,
|
|
82
|
+
},
|
|
83
|
+
}, constructor);
|
|
84
|
+
};
|
|
85
|
+
exports.Field = Field;
|
|
86
|
+
/**
|
|
87
|
+
* Property decorator that marks a field as the DynamoDB table
|
|
88
|
+
* **partition key** (hash key).
|
|
89
|
+
*
|
|
90
|
+
* Every DynamoDB table requires exactly one partition key. The
|
|
91
|
+
* accepted types are `String` or `Number`.
|
|
92
|
+
*
|
|
93
|
+
* Internally registers the field as a regular `@Field` as well,
|
|
94
|
+
* so there is no need to apply both decorators.
|
|
95
|
+
*
|
|
96
|
+
* @param type - The key type (`String` or `Number`).
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* @Table()
|
|
101
|
+
* export class UserTable {
|
|
102
|
+
* @PartitionKey(String)
|
|
103
|
+
* id: string;
|
|
104
|
+
* }
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
const PartitionKey = (type) => (constructor, name) => {
|
|
108
|
+
(0, exports.Field)({ type })(constructor, name);
|
|
109
|
+
Reflect.defineMetadata(table_types_1.TableMetadataKeys.partition_key, name, constructor);
|
|
110
|
+
};
|
|
111
|
+
exports.PartitionKey = PartitionKey;
|
|
112
|
+
/**
|
|
113
|
+
* Property decorator that marks a field as the DynamoDB table
|
|
114
|
+
* **sort key** (range key).
|
|
115
|
+
*
|
|
116
|
+
* A sort key is optional but, when present, works together with
|
|
117
|
+
* the partition key to form a composite primary key. The accepted
|
|
118
|
+
* types are `String` or `Number`.
|
|
119
|
+
*
|
|
120
|
+
* Internally registers the field as a regular `@Field` as well,
|
|
121
|
+
* so there is no need to apply both decorators.
|
|
122
|
+
*
|
|
123
|
+
* @param type - The key type (`String` or `Number`).
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* @Table()
|
|
128
|
+
* export class EventTable {
|
|
129
|
+
* @PartitionKey(String)
|
|
130
|
+
* userId: string;
|
|
131
|
+
*
|
|
132
|
+
* @SortKey(Number)
|
|
133
|
+
* timestamp: number;
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
const SortKey = (type) => (constructor, name) => {
|
|
138
|
+
(0, exports.Field)({ type })(constructor, name);
|
|
139
|
+
Reflect.defineMetadata(table_types_1.TableMetadataKeys.sort_key, name, constructor);
|
|
140
|
+
};
|
|
141
|
+
exports.SortKey = SortKey;
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import type { DeepPartial, DynamoTableNames, FieldTypes, OnlyNumber, OnlyNumberString, ResourceOutputType } from '@lafken/common';
|
|
3
|
+
/**
|
|
4
|
+
* Internal metadata keys used to store DynamoDB table configuration
|
|
5
|
+
* via `Reflect.defineMetadata`.
|
|
6
|
+
*/
|
|
7
|
+
export declare enum TableMetadataKeys {
|
|
8
|
+
table = "dynamo:table",
|
|
9
|
+
partition_key = "dynamo:partition_key",
|
|
10
|
+
sort_key = "dynamo:sort_key",
|
|
11
|
+
fields = "dynamo:fields"
|
|
12
|
+
}
|
|
13
|
+
export type TableOutputAttributes = 'arn' | 'id' | 'streamArn' | 'streamLabel';
|
|
14
|
+
/**
|
|
15
|
+
* Base configuration shared by all DynamoDB secondary indexes.
|
|
16
|
+
*
|
|
17
|
+
* @typeParam T - The table class whose properties define the available attributes.
|
|
18
|
+
*/
|
|
19
|
+
interface IndexBase<T extends Function> {
|
|
20
|
+
/** Logical name of the index. */
|
|
21
|
+
name: string;
|
|
22
|
+
/**
|
|
23
|
+
* Attributes projected into the index.
|
|
24
|
+
*
|
|
25
|
+
* Pass an array of property names to project only specific attributes,
|
|
26
|
+
* or `'ALL'` to include every attribute from the base table.
|
|
27
|
+
*/
|
|
28
|
+
projection?: (keyof T['prototype'])[] | 'ALL';
|
|
29
|
+
}
|
|
30
|
+
type AttributeFilter<T> = {
|
|
31
|
+
[key in keyof T]?: (T[key] | {
|
|
32
|
+
'anything-but': T[key][];
|
|
33
|
+
} | {
|
|
34
|
+
exists: boolean;
|
|
35
|
+
} | {
|
|
36
|
+
prefix: T[key];
|
|
37
|
+
} | '')[] | null;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Configuration for a DynamoDB **Local Secondary Index** (LSI).
|
|
41
|
+
*
|
|
42
|
+
* A local index shares the same partition key as the base table but
|
|
43
|
+
* uses a different sort key, enabling alternative query patterns
|
|
44
|
+
* within the same partition.
|
|
45
|
+
*
|
|
46
|
+
* @typeParam T - The table class whose properties define the available attributes.
|
|
47
|
+
*/
|
|
48
|
+
export interface LocalIndex<T extends Function> extends IndexBase<T> {
|
|
49
|
+
/** Must be `'local'` to indicate a Local Secondary Index. */
|
|
50
|
+
type: 'local';
|
|
51
|
+
/** The table property used as the sort key for this index. */
|
|
52
|
+
sortKey: keyof OnlyNumberString<T['prototype']>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Configuration for a DynamoDB **Global Secondary Index** (GSI).
|
|
56
|
+
*
|
|
57
|
+
* A global index has its own partition key (and optional sort key),
|
|
58
|
+
* allowing queries across the entire table with a completely different
|
|
59
|
+
* key schema.
|
|
60
|
+
*
|
|
61
|
+
* @typeParam T - The table class whose properties define the available attributes.
|
|
62
|
+
*/
|
|
63
|
+
export interface GlobalIndex<T extends Function> extends IndexBase<T> {
|
|
64
|
+
/** Set to `'global'` (or omit) to indicate a Global Secondary Index. */
|
|
65
|
+
type?: 'global';
|
|
66
|
+
/**
|
|
67
|
+
* The table property (or composite of properties) used as the
|
|
68
|
+
* partition key for this index.
|
|
69
|
+
*/
|
|
70
|
+
partitionKey: keyof OnlyNumberString<T['prototype']> | (keyof OnlyNumberString<T['prototype']>)[];
|
|
71
|
+
/**
|
|
72
|
+
* Optional table property (or composite of properties) used as the
|
|
73
|
+
* sort key for this index.
|
|
74
|
+
*/
|
|
75
|
+
sortKey?: keyof OnlyNumberString<T['prototype']> | (keyof OnlyNumberString<T['prototype']>)[];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A Global Secondary Index with explicit read/write capacity units.
|
|
79
|
+
* Used when the table billing mode is `'provisioned'`.
|
|
80
|
+
*/
|
|
81
|
+
export type GlobalIndexWithReadWriteCapacity<T extends Function> = GlobalIndex<T> & ReadWriteCapacity;
|
|
82
|
+
/**
|
|
83
|
+
* Provisioned throughput settings for a DynamoDB table or index.
|
|
84
|
+
*/
|
|
85
|
+
export interface ReadWriteCapacity {
|
|
86
|
+
/** Maximum number of strongly consistent reads per second. */
|
|
87
|
+
readCapacity: number;
|
|
88
|
+
/** Maximum number of writes per second. */
|
|
89
|
+
writeCapacity: number;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Union of all secondary index types allowed when the table uses
|
|
93
|
+
* pay-per-request billing.
|
|
94
|
+
*/
|
|
95
|
+
export type DynamoIndex<T extends Function> = LocalIndex<T> | GlobalIndex<T>;
|
|
96
|
+
/**
|
|
97
|
+
* Supported DynamoDB Stream view types.
|
|
98
|
+
*
|
|
99
|
+
* Determines which item data is written to the stream record when a
|
|
100
|
+
* table item is modified.
|
|
101
|
+
*/
|
|
102
|
+
export type StreamTypes = 'NEW_IMAGE' | 'OLD_IMAGE' | 'NEW_AND_OLD_IMAGES' | 'KEYS_ONLY';
|
|
103
|
+
/**
|
|
104
|
+
* Configuration for a DynamoDB Global Table replica in another AWS region.
|
|
105
|
+
*/
|
|
106
|
+
export interface Replica {
|
|
107
|
+
/** AWS region where the replica will be created (e.g. `'us-east-2'`). */
|
|
108
|
+
regionName: string;
|
|
109
|
+
/**
|
|
110
|
+
* Read consistency mode for the replica.
|
|
111
|
+
*
|
|
112
|
+
* - `'STRONG'` — Strongly consistent reads.
|
|
113
|
+
* - `'EVENTUAL'` — Eventually consistent reads (default DynamoDB behaviour).
|
|
114
|
+
*/
|
|
115
|
+
consistenceMode?: 'STRONG' | 'EVENTUAL';
|
|
116
|
+
/** When `true`, the replica cannot be deleted accidentally. */
|
|
117
|
+
deletionProtectionEnabled?: boolean;
|
|
118
|
+
/** When `true`, tags from the primary table are propagated to the replica. */
|
|
119
|
+
propagateTags?: boolean;
|
|
120
|
+
}
|
|
121
|
+
export interface FilterCriteria<T> {
|
|
122
|
+
/**
|
|
123
|
+
* Event types to include in the stream.
|
|
124
|
+
*
|
|
125
|
+
* Specify one or more of the following:
|
|
126
|
+
* - `'INSERT'` – Record when a new item is added.
|
|
127
|
+
* - `'MODIFY'` – Record when an existing item is modified.
|
|
128
|
+
* - `'REMOVE'` – Record when an item is deleted.
|
|
129
|
+
*/
|
|
130
|
+
eventName?: ('INSERT' | 'MODIFY' | 'REMOVE')[];
|
|
131
|
+
/**
|
|
132
|
+
* Filter by specific partition keys.
|
|
133
|
+
*
|
|
134
|
+
* Only records with the specified partition key values will be included.
|
|
135
|
+
*/
|
|
136
|
+
keys?: AttributeFilter<TablePartition<T>>;
|
|
137
|
+
/**
|
|
138
|
+
* Filter based on the new image of the item.
|
|
139
|
+
*
|
|
140
|
+
* Allows applying conditions to the attributes of the new item image
|
|
141
|
+
* after an INSERT or MODIFY event.
|
|
142
|
+
*/
|
|
143
|
+
newImage?: AttributeFilter<DeepPartial<T>>;
|
|
144
|
+
/**
|
|
145
|
+
* Filter based on the old image of the item.
|
|
146
|
+
*
|
|
147
|
+
* Allows applying conditions to the attributes of the old item image
|
|
148
|
+
* before a MODIFY or REMOVE event.
|
|
149
|
+
*/
|
|
150
|
+
oldImage?: AttributeFilter<DeepPartial<T>>;
|
|
151
|
+
}
|
|
152
|
+
export interface DynamoStream<T> {
|
|
153
|
+
/**
|
|
154
|
+
* Enable DynamoDB Stream.
|
|
155
|
+
*
|
|
156
|
+
* Specifies whether the DynamoDB Stream is active for the table.
|
|
157
|
+
* When enabled, changes to items in the table (insert, modify, remove)
|
|
158
|
+
* will be captured and can be consumed by EventBridge or Lambda functions.
|
|
159
|
+
*/
|
|
160
|
+
enabled?: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Stream type.
|
|
163
|
+
*
|
|
164
|
+
* Specifies which information is captured in the DynamoDB Stream
|
|
165
|
+
* when items in the table are modified.
|
|
166
|
+
*
|
|
167
|
+
* Available options:
|
|
168
|
+
* - `'NEW_IMAGE'` – Only the new item image is recorded.
|
|
169
|
+
* - `'OLD_IMAGE'` – Only the old item image is recorded.
|
|
170
|
+
* - `'NEW_AND_OLD_IMAGES'` – Both new and old images are recorded.
|
|
171
|
+
* - `'KEYS_ONLY'` – Only the key attributes are recorded.
|
|
172
|
+
*
|
|
173
|
+
* @default "NEW_AND_OLD_IMAGES"
|
|
174
|
+
*/
|
|
175
|
+
type?: StreamTypes;
|
|
176
|
+
/**
|
|
177
|
+
* Batch size for stream events.
|
|
178
|
+
*
|
|
179
|
+
* Specifies the maximum number of records that will be sent
|
|
180
|
+
* in a single batch to the event consumer.
|
|
181
|
+
* Adjusting this value can help control memory usage and processing throughput.
|
|
182
|
+
*/
|
|
183
|
+
batchSize?: number;
|
|
184
|
+
/**
|
|
185
|
+
* Maximum batching window in seconds.
|
|
186
|
+
*
|
|
187
|
+
* Specifies the maximum amount of time to gather records before
|
|
188
|
+
* sending a batch to the event consumer.
|
|
189
|
+
* This allows for combining multiple changes into a single batch,
|
|
190
|
+
* potentially reducing the number of invocations.
|
|
191
|
+
*
|
|
192
|
+
* @default 1
|
|
193
|
+
*/
|
|
194
|
+
maximumBatchingWindowInSeconds?: number;
|
|
195
|
+
/**
|
|
196
|
+
* Stream filters.
|
|
197
|
+
*
|
|
198
|
+
* Specifies filter criteria to selectively process only certain records
|
|
199
|
+
* from the DynamoDB Stream. This allows you to ignore events that do
|
|
200
|
+
* not match the defined conditions, reducing unnecessary processing.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* {
|
|
204
|
+
* filters: {
|
|
205
|
+
* eventName: ['INSERT'],
|
|
206
|
+
* keys: {
|
|
207
|
+
* PK: ['foo']
|
|
208
|
+
* },
|
|
209
|
+
* newImage: {
|
|
210
|
+
* bar: [1, 2, 3]
|
|
211
|
+
* }
|
|
212
|
+
* }
|
|
213
|
+
* }
|
|
214
|
+
*/
|
|
215
|
+
filters?: FilterCriteria<T>;
|
|
216
|
+
}
|
|
217
|
+
export interface TableBase<T extends Function> {
|
|
218
|
+
isExternal?: never;
|
|
219
|
+
/**
|
|
220
|
+
* Table name.
|
|
221
|
+
*
|
|
222
|
+
* Defines the logical name of the DynamoDB table.
|
|
223
|
+
* If not specified, the name of the decorated class will be used.
|
|
224
|
+
*/
|
|
225
|
+
name?: DynamoTableNames;
|
|
226
|
+
/**
|
|
227
|
+
* Enable X-Ray tracing.
|
|
228
|
+
*
|
|
229
|
+
* When enabled, AWS X-Ray tracing is activated for all operations
|
|
230
|
+
* on this DynamoDB table. This allows you to trace and analyze
|
|
231
|
+
* requests, helping with debugging and performance monitoring.
|
|
232
|
+
*/
|
|
233
|
+
tracing?: boolean;
|
|
234
|
+
/**
|
|
235
|
+
* Enable DynamoDB Streams via EventBridge.
|
|
236
|
+
*
|
|
237
|
+
* When enabled, the table will send stream events for item changes
|
|
238
|
+
* (insert, modify, remove) through EventBridge. This allows other
|
|
239
|
+
* services to react to changes in the table in near real-time.
|
|
240
|
+
*
|
|
241
|
+
* - `detailType` is always set to `'db:stream'`.
|
|
242
|
+
* - `source` is set to `dynamodb.<table_name>`, where `<table_name>` is
|
|
243
|
+
* the name of the decorated class.
|
|
244
|
+
*
|
|
245
|
+
* @example {
|
|
246
|
+
* stream: {
|
|
247
|
+
* enabled: true,
|
|
248
|
+
* type: ['NEW_AND_OLD_IMAGES'],
|
|
249
|
+
* batchSize: 10,
|
|
250
|
+
* maximumBatchingWindowInSeconds: 10,
|
|
251
|
+
* filters: {
|
|
252
|
+
* eventName: ['INSERT'],
|
|
253
|
+
* keys: {
|
|
254
|
+
* PK: ['foo']
|
|
255
|
+
* },
|
|
256
|
+
* newImage: {
|
|
257
|
+
* bar: [1, 2, 3]
|
|
258
|
+
* }
|
|
259
|
+
* }
|
|
260
|
+
* }
|
|
261
|
+
* }
|
|
262
|
+
*/
|
|
263
|
+
stream?: DynamoStream<T['prototype']>;
|
|
264
|
+
/**
|
|
265
|
+
* Defines the name of the attribute used as the TTL (Time to Live) field in DynamoDB.
|
|
266
|
+
*
|
|
267
|
+
* When specified, this attribute determines when an item will automatically expire and be deleted
|
|
268
|
+
* by DynamoDB. The value of this field should be a Unix timestamp (in seconds) representing
|
|
269
|
+
* the expiration time.
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* {
|
|
273
|
+
* // Items with an 'expiresAt' attribute set to a future Unix timestamp will be removed after that time.
|
|
274
|
+
* ttl: 'expiresAt'
|
|
275
|
+
* }
|
|
276
|
+
*/
|
|
277
|
+
ttl?: keyof OnlyNumber<T['prototype']>;
|
|
278
|
+
/**
|
|
279
|
+
* Define the dyanamo table replication mode across another regions
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* {
|
|
283
|
+
* replica: [{
|
|
284
|
+
* regionName: 'us-east-2',
|
|
285
|
+
* consistenceMode: 'EVENTUAL'
|
|
286
|
+
* }]
|
|
287
|
+
* }
|
|
288
|
+
*/
|
|
289
|
+
replica?: Replica[];
|
|
290
|
+
/**
|
|
291
|
+
* Defines which DynamoDB table attributes should be exported.
|
|
292
|
+
*
|
|
293
|
+
* Supported attributes are based on Terraform `aws_dynamodb_table`
|
|
294
|
+
* exported attributes and currently include:
|
|
295
|
+
* - `arn`: ARN of the table.
|
|
296
|
+
* - `id`: Name of the table.
|
|
297
|
+
* - `streamArn`: ARN of the table stream. Only available when stream is enabled.
|
|
298
|
+
* - `streamLabel`: ISO 8601 timestamp for the table stream. Only available when stream is enabled.
|
|
299
|
+
*
|
|
300
|
+
* Each selected attribute can be exported through SSM Parameter Store (`type: 'ssm'`)
|
|
301
|
+
* or Terraform outputs (`type: 'output'`).
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* {
|
|
305
|
+
* outputs: [
|
|
306
|
+
* { type: 'ssm', name: '/my-table/arn', value: 'arn' },
|
|
307
|
+
* { type: 'output', name: 'table_stream_arn', value: 'streamArn' }
|
|
308
|
+
* ]
|
|
309
|
+
* }
|
|
310
|
+
*/
|
|
311
|
+
outputs?: ResourceOutputType<TableOutputAttributes>;
|
|
312
|
+
}
|
|
313
|
+
export interface TableProvisioned<T extends Function> extends TableBase<T>, ReadWriteCapacity {
|
|
314
|
+
billingMode: 'provisioned';
|
|
315
|
+
/**
|
|
316
|
+
* Table indexes.
|
|
317
|
+
*
|
|
318
|
+
* Defines the secondary indexes to apply on the DynamoDB table.
|
|
319
|
+
* These indexes can be used to optimize query patterns or support
|
|
320
|
+
* additional access patterns.
|
|
321
|
+
*/
|
|
322
|
+
indexes?: (LocalIndex<T> | GlobalIndexWithReadWriteCapacity<T>)[];
|
|
323
|
+
}
|
|
324
|
+
export interface TablePayPerRequest<T extends Function> extends TableBase<T> {
|
|
325
|
+
billingMode?: 'pay_per_request';
|
|
326
|
+
/**
|
|
327
|
+
* Table indexes.
|
|
328
|
+
*
|
|
329
|
+
* Defines the secondary indexes to apply on the DynamoDB table.
|
|
330
|
+
* These indexes can be used to optimize query patterns or support
|
|
331
|
+
* additional access patterns.
|
|
332
|
+
*/
|
|
333
|
+
indexes?: DynamoIndex<T>[];
|
|
334
|
+
}
|
|
335
|
+
export type InternalTableProps<T extends Function> = TableProvisioned<T> | TablePayPerRequest<T>;
|
|
336
|
+
export interface ExternalTableProps<T extends Function> extends Omit<InternalTableProps<T>, 'outputs' | 'replica' | 'stream' | 'isExternal'> {
|
|
337
|
+
/**
|
|
338
|
+
* Marks the DynamoDB table as an external resource.
|
|
339
|
+
*
|
|
340
|
+
* When set to `true`, the table is not created by the framework.
|
|
341
|
+
* Instead, it references an existing DynamoDB table using the provided `name`.
|
|
342
|
+
*/
|
|
343
|
+
isExternal: true;
|
|
344
|
+
}
|
|
345
|
+
export type DynamoTableProps<T extends Function> = InternalTableProps<T> | ExternalTableProps<T>;
|
|
346
|
+
export interface InternalTableMetadata extends Omit<InternalTableProps<any>, 'name'> {
|
|
347
|
+
name: string;
|
|
348
|
+
}
|
|
349
|
+
export interface ExternalTableMetadata extends Omit<ExternalTableProps<any>, 'name'> {
|
|
350
|
+
name: string;
|
|
351
|
+
}
|
|
352
|
+
export type TableMetadata = InternalTableMetadata | ExternalTableMetadata;
|
|
353
|
+
export interface FieldProps {
|
|
354
|
+
type?: StringConstructor | NumberConstructor | BooleanConstructor | [Function] | Function;
|
|
355
|
+
}
|
|
356
|
+
export interface FieldMetadata {
|
|
357
|
+
name: string;
|
|
358
|
+
type: FieldTypes;
|
|
359
|
+
}
|
|
360
|
+
export type FieldsMetadata = Record<string, FieldMetadata>;
|
|
361
|
+
type Partition = {
|
|
362
|
+
__special: unknown;
|
|
363
|
+
};
|
|
364
|
+
export type PrimaryPartition<T = never> = T | (T & Partition);
|
|
365
|
+
export type TablePartition<T> = {
|
|
366
|
+
[K in keyof T as [Extract<T[K], Partition>] extends [never] ? never : K]: T[K];
|
|
367
|
+
};
|
|
368
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TableMetadataKeys = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
/**
|
|
6
|
+
* Internal metadata keys used to store DynamoDB table configuration
|
|
7
|
+
* via `Reflect.defineMetadata`.
|
|
8
|
+
*/
|
|
9
|
+
var TableMetadataKeys;
|
|
10
|
+
(function (TableMetadataKeys) {
|
|
11
|
+
TableMetadataKeys["table"] = "dynamo:table";
|
|
12
|
+
TableMetadataKeys["partition_key"] = "dynamo:partition_key";
|
|
13
|
+
TableMetadataKeys["sort_key"] = "dynamo:sort_key";
|
|
14
|
+
TableMetadataKeys["fields"] = "dynamo:fields";
|
|
15
|
+
})(TableMetadataKeys || (exports.TableMetadataKeys = TableMetadataKeys = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './resolver';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./resolver"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ClassResource } from '@lafken/common';
|
|
2
|
+
import type { AppModule, AppStack, ResolverType } from '@lafken/resolver';
|
|
3
|
+
import type { ClassResourceExtends } from './resolver.types';
|
|
4
|
+
export declare class DynamoResolver implements ResolverType {
|
|
5
|
+
private tables;
|
|
6
|
+
type: string;
|
|
7
|
+
private extensibleTables;
|
|
8
|
+
constructor(tables: (ClassResource | ClassResourceExtends)[]);
|
|
9
|
+
beforeCreate(scope: AppModule): void;
|
|
10
|
+
create(): void;
|
|
11
|
+
afterCreate(scope: AppStack): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DynamoResolver = void 0;
|
|
4
|
+
const main_1 = require("../main");
|
|
5
|
+
const external_1 = require("./table/external/external");
|
|
6
|
+
const internal_1 = require("./table/internal/internal");
|
|
7
|
+
class DynamoResolver {
|
|
8
|
+
tables;
|
|
9
|
+
type = 'DYNAMODB';
|
|
10
|
+
extensibleTables = [];
|
|
11
|
+
constructor(tables) {
|
|
12
|
+
this.tables = tables;
|
|
13
|
+
}
|
|
14
|
+
beforeCreate(scope) {
|
|
15
|
+
for (const table of this.tables) {
|
|
16
|
+
const isExtensibleResource = 'table' in table;
|
|
17
|
+
const tableResource = isExtensibleResource ? table.table : table;
|
|
18
|
+
const tableProps = Reflect.getMetadata(main_1.TableMetadataKeys.table, tableResource);
|
|
19
|
+
let dynamoTable;
|
|
20
|
+
if (tableProps.isExternal !== undefined) {
|
|
21
|
+
dynamoTable = new external_1.ExternalTable(scope, tableProps);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
dynamoTable = new internal_1.InternalTable(scope, {
|
|
25
|
+
classResource: tableResource,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (isExtensibleResource) {
|
|
29
|
+
this.extensibleTables.push({
|
|
30
|
+
table: dynamoTable,
|
|
31
|
+
extends: table.extends,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
create() {
|
|
37
|
+
throw new Error('It is not possible to parse this service');
|
|
38
|
+
}
|
|
39
|
+
afterCreate(scope) {
|
|
40
|
+
for (const extendTable of this.extensibleTables) {
|
|
41
|
+
extendTable.extends({
|
|
42
|
+
scope,
|
|
43
|
+
table: extendTable.table,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.DynamoResolver = DynamoResolver;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DataAwsDynamodbTable } from '@cdktn/provider-aws/lib/data-aws-dynamodb-table';
|
|
2
|
+
import type { DynamodbTable } from '@cdktn/provider-aws/lib/dynamodb-table';
|
|
3
|
+
import type { ClassResource } from '@lafken/common';
|
|
4
|
+
import type { AppStack } from '@lafken/resolver';
|
|
5
|
+
interface ExtendProps {
|
|
6
|
+
scope: AppStack;
|
|
7
|
+
table: DynamodbTable | DataAwsDynamodbTable;
|
|
8
|
+
}
|
|
9
|
+
export interface ClassResourceExtends {
|
|
10
|
+
table: ClassResource;
|
|
11
|
+
extends: (props: ExtendProps) => void;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DataAwsDynamodbTable } from '@cdktn/provider-aws/lib/data-aws-dynamodb-table';
|
|
2
|
+
import type { Construct } from 'constructs';
|
|
3
|
+
import type { ExternalTableMetadata } from '../../../main';
|
|
4
|
+
declare const ExternalTable_base: (new (...args: any[]) => {
|
|
5
|
+
isGlobal(module: import("@lafken/common").ModuleGlobalReferenceNames | (string & {}), id: string): void;
|
|
6
|
+
isDependent(resolveDependency: () => void): void;
|
|
7
|
+
readonly node: import("constructs").Node;
|
|
8
|
+
with(...mixins: import("constructs").IMixin[]): import("constructs").IConstruct;
|
|
9
|
+
toString(): string;
|
|
10
|
+
}) & typeof DataAwsDynamodbTable;
|
|
11
|
+
export declare class ExternalTable extends ExternalTable_base {
|
|
12
|
+
constructor(scope: Construct, props: ExternalTableMetadata);
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExternalTable = void 0;
|
|
4
|
+
const data_aws_dynamodb_table_1 = require("@cdktn/provider-aws/lib/data-aws-dynamodb-table");
|
|
5
|
+
const resolver_1 = require("@lafken/resolver");
|
|
6
|
+
class ExternalTable extends resolver_1.lafkenResource.make(data_aws_dynamodb_table_1.DataAwsDynamodbTable) {
|
|
7
|
+
constructor(scope, props) {
|
|
8
|
+
const { name } = props;
|
|
9
|
+
super(scope, `${name}-table`, {
|
|
10
|
+
name,
|
|
11
|
+
});
|
|
12
|
+
this.isGlobal('dynamo', name);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.ExternalTable = ExternalTable;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DynamodbTable } from '@cdktn/provider-aws/lib/dynamodb-table';
|
|
2
|
+
import type { Construct } from 'constructs';
|
|
3
|
+
import type { InternalTableProps } from '../table.types';
|
|
4
|
+
declare const InternalTable_base: (new (...args: any[]) => {
|
|
5
|
+
isGlobal(module: import("@lafken/common").ModuleGlobalReferenceNames | (string & {}), id: string): void;
|
|
6
|
+
isDependent(resolveDependency: () => void): void;
|
|
7
|
+
readonly node: import("constructs").Node;
|
|
8
|
+
with(...mixins: import("constructs").IMixin[]): import("constructs").IConstruct;
|
|
9
|
+
toString(): string;
|
|
10
|
+
}) & typeof DynamodbTable;
|
|
11
|
+
export declare class InternalTable extends InternalTable_base {
|
|
12
|
+
constructor(scope: Construct, props: InternalTableProps);
|
|
13
|
+
private static getAttributes;
|
|
14
|
+
private static getBillingModeProps;
|
|
15
|
+
private static getIndexes;
|
|
16
|
+
private createFilterCriteria;
|
|
17
|
+
private getKeyFilterCriteria;
|
|
18
|
+
}
|
|
19
|
+
export {};
|