@composurecdk/dynamodb 0.8.4
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 +186 -0
- package/dist/commonjs/defaults.d.ts +25 -0
- package/dist/commonjs/defaults.d.ts.map +1 -0
- package/dist/commonjs/defaults.js +138 -0
- package/dist/commonjs/defaults.js.map +1 -0
- package/dist/commonjs/index.d.ts +6 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +13 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/table-alarm-config.d.ts +58 -0
- package/dist/commonjs/table-alarm-config.d.ts.map +1 -0
- package/dist/commonjs/table-alarm-config.js +3 -0
- package/dist/commonjs/table-alarm-config.js.map +1 -0
- package/dist/commonjs/table-alarm-defaults.d.ts +21 -0
- package/dist/commonjs/table-alarm-defaults.d.ts.map +1 -0
- package/dist/commonjs/table-alarm-defaults.js +51 -0
- package/dist/commonjs/table-alarm-defaults.js.map +1 -0
- package/dist/commonjs/table-alarms.d.ts +26 -0
- package/dist/commonjs/table-alarms.d.ts.map +1 -0
- package/dist/commonjs/table-alarms.js +129 -0
- package/dist/commonjs/table-alarms.js.map +1 -0
- package/dist/commonjs/table-builder.d.ts +123 -0
- package/dist/commonjs/table-builder.d.ts.map +1 -0
- package/dist/commonjs/table-builder.js +86 -0
- package/dist/commonjs/table-builder.js.map +1 -0
- package/dist/commonjs/table-v2-builder.d.ts +129 -0
- package/dist/commonjs/table-v2-builder.d.ts.map +1 -0
- package/dist/commonjs/table-v2-builder.js +71 -0
- package/dist/commonjs/table-v2-builder.js.map +1 -0
- package/dist/esm/defaults.d.ts +25 -0
- package/dist/esm/defaults.d.ts.map +1 -0
- package/dist/esm/defaults.js +135 -0
- package/dist/esm/defaults.js.map +1 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/table-alarm-config.d.ts +58 -0
- package/dist/esm/table-alarm-config.d.ts.map +1 -0
- package/dist/esm/table-alarm-config.js +2 -0
- package/dist/esm/table-alarm-config.js.map +1 -0
- package/dist/esm/table-alarm-defaults.d.ts +21 -0
- package/dist/esm/table-alarm-defaults.d.ts.map +1 -0
- package/dist/esm/table-alarm-defaults.js +48 -0
- package/dist/esm/table-alarm-defaults.js.map +1 -0
- package/dist/esm/table-alarms.d.ts +26 -0
- package/dist/esm/table-alarms.d.ts.map +1 -0
- package/dist/esm/table-alarms.js +125 -0
- package/dist/esm/table-alarms.js.map +1 -0
- package/dist/esm/table-builder.d.ts +123 -0
- package/dist/esm/table-builder.d.ts.map +1 -0
- package/dist/esm/table-builder.js +83 -0
- package/dist/esm/table-builder.js.map +1 -0
- package/dist/esm/table-v2-builder.d.ts +129 -0
- package/dist/esm/table-v2-builder.d.ts.map +1 -0
- package/dist/esm/table-v2-builder.js +68 -0
- package/dist/esm/table-v2-builder.js.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Table, TableEncryption } from "aws-cdk-lib/aws-dynamodb";
|
|
2
|
+
import { COPY_STATE } from "@composurecdk/core";
|
|
3
|
+
import { taggedBuilder } from "@composurecdk/cloudformation";
|
|
4
|
+
import { AlarmDefinitionBuilder } from "@composurecdk/cloudwatch";
|
|
5
|
+
import { createTableAlarms } from "./table-alarms.js";
|
|
6
|
+
import { TABLE_DEFAULTS } from "./defaults.js";
|
|
7
|
+
class TableBuilder {
|
|
8
|
+
props = {};
|
|
9
|
+
#customAlarms = [];
|
|
10
|
+
addAlarm(key, configure) {
|
|
11
|
+
this.#customAlarms.push(configure(new AlarmDefinitionBuilder(key)));
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
/** @internal — see ADR-0005. */
|
|
15
|
+
[COPY_STATE](target) {
|
|
16
|
+
target.#customAlarms.push(...this.#customAlarms);
|
|
17
|
+
}
|
|
18
|
+
build(scope, id) {
|
|
19
|
+
const { recommendedAlarms: alarmConfig, ...tableProps } = this.props;
|
|
20
|
+
const mergedProps = mergeTableDefaults(tableProps);
|
|
21
|
+
const table = new Table(scope, id, mergedProps);
|
|
22
|
+
const alarms = createTableAlarms(scope, id, table, alarmConfig, this.#customAlarms);
|
|
23
|
+
return { table, tableStreamArn: table.tableStreamArn, alarms };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Merges {@link TABLE_DEFAULTS} under the user's props, then resolves the two
|
|
28
|
+
* cases where a default is mutually exclusive with a sibling the user set
|
|
29
|
+
* (ADR-0009): the `billingMode` default yields to provisioned capacity, and
|
|
30
|
+
* the `encryption` default yields to a customer-managed key.
|
|
31
|
+
*/
|
|
32
|
+
function mergeTableDefaults(props) {
|
|
33
|
+
const merged = { ...TABLE_DEFAULTS, ...props };
|
|
34
|
+
// billingMode (default PAY_PER_REQUEST) is mutually exclusive with
|
|
35
|
+
// readCapacity / writeCapacity. If the user set capacity but not the mode,
|
|
36
|
+
// drop the on-demand default so CDK falls back to PROVISIONED. Setting both
|
|
37
|
+
// explicitly is left for CDK to reject.
|
|
38
|
+
const userSetCapacity = props.readCapacity !== undefined || props.writeCapacity !== undefined;
|
|
39
|
+
if (userSetCapacity && props.billingMode === undefined) {
|
|
40
|
+
delete merged.billingMode;
|
|
41
|
+
}
|
|
42
|
+
// encryption (default AWS_MANAGED) is mutually exclusive with a user-supplied
|
|
43
|
+
// encryptionKey, which CDK only accepts under CUSTOMER_MANAGED. Providing a
|
|
44
|
+
// key is an unambiguous request for customer-managed encryption, so infer the
|
|
45
|
+
// mode rather than forcing the user to set both.
|
|
46
|
+
if (props.encryptionKey !== undefined && props.encryption === undefined) {
|
|
47
|
+
merged.encryption = TableEncryption.CUSTOMER_MANAGED;
|
|
48
|
+
}
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- `as TableProps` is load-bearing on the supported aws-cdk-lib floor, where `partitionKey` is required and the spread of Partials is not assignable without it; current devDeps make `partitionKey` optional (multi-attribute `partitionKeys` was added), so it only looks redundant against the latest CDK.
|
|
50
|
+
return merged;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Creates a new {@link ITableBuilder} for configuring an AWS DynamoDB table.
|
|
54
|
+
*
|
|
55
|
+
* This is the entry point for defining a DynamoDB table component. The returned
|
|
56
|
+
* builder exposes every {@link TableBuilderProps} property as a fluent
|
|
57
|
+
* setter/getter and implements {@link Lifecycle} for use with {@link compose}.
|
|
58
|
+
*
|
|
59
|
+
* @returns A fluent builder for an AWS DynamoDB table.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { AttributeType } from "aws-cdk-lib/aws-dynamodb";
|
|
64
|
+
*
|
|
65
|
+
* const orders = createTableBuilder().partitionKey({
|
|
66
|
+
* name: "orderId",
|
|
67
|
+
* type: AttributeType.STRING,
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* // Use standalone:
|
|
71
|
+
* const result = orders.build(stack, "Orders");
|
|
72
|
+
*
|
|
73
|
+
* // Or compose into a system, wiring the stream into a Lambda:
|
|
74
|
+
* const system = compose(
|
|
75
|
+
* { orders, processor: createFunctionBuilder() },
|
|
76
|
+
* { orders: [], processor: ["orders"] },
|
|
77
|
+
* );
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export function createTableBuilder() {
|
|
81
|
+
return taggedBuilder(TableBuilder);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=table-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-builder.js","sourceRoot":"","sources":["../../src/table-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,EAAE,eAAe,EAAmB,MAAM,0BAA0B,CAAC;AAEhG,OAAO,EAAE,UAAU,EAAkB,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAuB,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAoF/C,MAAM,YAAY;IAChB,KAAK,GAA+B,EAAE,CAAC;IAC9B,aAAa,GAAqC,EAAE,CAAC;IAE9D,QAAQ,CACN,GAAW,EACX,SAAoF;QAEpF,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,sBAAsB,CAAS,GAAG,CAAC,CAAC,CAAC,CAAC;QAC5E,OAAO,IAAI,CAAC;IACd,CAAC;IAED,gCAAgC;IAChC,CAAC,UAAU,CAAC,CAAC,MAAoB;QAC/B,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,KAAiB,EAAE,EAAU;QACjC,MAAM,EAAE,iBAAiB,EAAE,WAAW,EAAE,GAAG,UAAU,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAErE,MAAM,WAAW,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;QAEnD,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC;QAEhD,MAAM,MAAM,GAAG,iBAAiB,CAAC,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAEpF,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;IACjE,CAAC;CACF;AAED;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,KAA0B;IACpD,MAAM,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,KAAK,EAAE,CAAC;IAE/C,mEAAmE;IACnE,2EAA2E;IAC3E,4EAA4E;IAC5E,wCAAwC;IACxC,MAAM,eAAe,GAAG,KAAK,CAAC,YAAY,KAAK,SAAS,IAAI,KAAK,CAAC,aAAa,KAAK,SAAS,CAAC;IAC9F,IAAI,eAAe,IAAI,KAAK,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QACvD,OAAO,MAAM,CAAC,WAAW,CAAC;IAC5B,CAAC;IAED,8EAA8E;IAC9E,4EAA4E;IAC5E,8EAA8E;IAC9E,iDAAiD;IACjD,IAAI,KAAK,CAAC,aAAa,KAAK,SAAS,IAAI,KAAK,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACxE,MAAM,CAAC,UAAU,GAAG,eAAe,CAAC,gBAAgB,CAAC;IACvD,CAAC;IAED,0XAA0X;IAC1X,OAAO,MAAoB,CAAC;AAC9B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,aAAa,CAAkC,YAAY,CAAC,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { type Alarm } from "aws-cdk-lib/aws-cloudwatch";
|
|
2
|
+
import { type ITable, TableV2, type TablePropsV2 } from "aws-cdk-lib/aws-dynamodb";
|
|
3
|
+
import { type IConstruct } from "constructs";
|
|
4
|
+
import { COPY_STATE, type Lifecycle } from "@composurecdk/core";
|
|
5
|
+
import { type ITaggedBuilder } from "@composurecdk/cloudformation";
|
|
6
|
+
import { AlarmDefinitionBuilder } from "@composurecdk/cloudwatch";
|
|
7
|
+
import type { TableAlarmConfig } from "./table-alarm-config.js";
|
|
8
|
+
/**
|
|
9
|
+
* Configuration properties for the DynamoDB {@link TableV2} builder.
|
|
10
|
+
*
|
|
11
|
+
* Extends the CDK {@link TablePropsV2} with additional builder-specific options.
|
|
12
|
+
*/
|
|
13
|
+
export interface TableV2BuilderProps extends TablePropsV2 {
|
|
14
|
+
/**
|
|
15
|
+
* Configuration for AWS-recommended CloudWatch alarms.
|
|
16
|
+
*
|
|
17
|
+
* By default, the builder creates recommended alarms with sensible
|
|
18
|
+
* thresholds for server-side errors and read/write throttling. Individual
|
|
19
|
+
* alarms can be customized or disabled. Set to `false` to disable all alarms.
|
|
20
|
+
*
|
|
21
|
+
* No alarm actions are configured by default since notification methods are
|
|
22
|
+
* user-specific. Access alarms from the build result or use an `afterBuild`
|
|
23
|
+
* hook to apply actions.
|
|
24
|
+
*
|
|
25
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#DynamoDB
|
|
26
|
+
*/
|
|
27
|
+
recommendedAlarms?: TableAlarmConfig | false;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The build output of an {@link ITableV2Builder}. Contains the CDK constructs
|
|
31
|
+
* created during {@link Lifecycle.build}, keyed by role.
|
|
32
|
+
*/
|
|
33
|
+
export interface TableV2BuilderResult {
|
|
34
|
+
/** The DynamoDB {@link TableV2} construct created by the builder. */
|
|
35
|
+
table: TableV2;
|
|
36
|
+
/**
|
|
37
|
+
* The table's DynamoDB Streams ARN, or `undefined` when no stream is
|
|
38
|
+
* configured. Surfaced directly so a downstream consumer (e.g. a Lambda
|
|
39
|
+
* `DynamoEventSource`) can be wired via `ref()`.
|
|
40
|
+
*/
|
|
41
|
+
tableStreamArn?: string;
|
|
42
|
+
/**
|
|
43
|
+
* CloudWatch alarms created for the table, keyed by alarm name — both the
|
|
44
|
+
* AWS-recommended alarms and any added via {@link ITableV2Builder.addAlarm}.
|
|
45
|
+
* No alarm actions are configured.
|
|
46
|
+
*/
|
|
47
|
+
alarms: Record<string, Alarm>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A fluent builder for configuring and creating an AWS {@link TableV2} — the
|
|
51
|
+
* `AWS::DynamoDB::GlobalTable` resource, AWS's recommended construct for new
|
|
52
|
+
* tables.
|
|
53
|
+
*
|
|
54
|
+
* A single-region `TableV2` bills the same as a classic {@link Table} but
|
|
55
|
+
* future-proofs the one irreversible part of the choice: you can add
|
|
56
|
+
* cross-region replicas later without replacing the table. `ITableV2 extends
|
|
57
|
+
* ITable`, so a built table works everywhere an `ITable` is expected (grants,
|
|
58
|
+
* `DynamoEventSource`) — composition wiring is unaffected.
|
|
59
|
+
*
|
|
60
|
+
* Each configuration property from the CDK {@link TablePropsV2} is exposed as an
|
|
61
|
+
* overloaded method: call with a value to set it (returns the builder for
|
|
62
|
+
* chaining), or call with no arguments to read the current value. Note the V2
|
|
63
|
+
* prop shape differs from the classic one — e.g. billing is a single
|
|
64
|
+
* `.billing(Billing.onDemand())` helper, encryption is
|
|
65
|
+
* `.encryption(TableEncryptionV2.awsManagedKey())`, and the stream is
|
|
66
|
+
* `.dynamoStream(StreamViewType…)`.
|
|
67
|
+
*
|
|
68
|
+
* The builder implements {@link Lifecycle}, so it can be used directly as a
|
|
69
|
+
* component in a {@link compose | composed system}. When built, it creates a
|
|
70
|
+
* table with the configured properties — merged with secure, AWS-recommended
|
|
71
|
+
* {@link TABLE_V2_DEFAULTS} — and returns a {@link TableV2BuilderResult}.
|
|
72
|
+
*
|
|
73
|
+
* The builder also creates AWS-recommended CloudWatch alarms by default. Alarms
|
|
74
|
+
* can be customized or disabled via the `recommendedAlarms` property. Custom
|
|
75
|
+
* alarms can be added via the {@link addAlarm} method.
|
|
76
|
+
*
|
|
77
|
+
* @see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.TableV2.html
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* import { AttributeType, StreamViewType } from "aws-cdk-lib/aws-dynamodb";
|
|
82
|
+
*
|
|
83
|
+
* const orders = createTableV2Builder()
|
|
84
|
+
* .partitionKey({ name: "pk", type: AttributeType.STRING })
|
|
85
|
+
* .sortKey({ name: "sk", type: AttributeType.STRING })
|
|
86
|
+
* .dynamoStream(StreamViewType.NEW_AND_OLD_IMAGES);
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export type ITableV2Builder = ITaggedBuilder<TableV2BuilderProps, TableV2Builder>;
|
|
90
|
+
declare class TableV2Builder implements Lifecycle<TableV2BuilderResult> {
|
|
91
|
+
#private;
|
|
92
|
+
props: Partial<TableV2BuilderProps>;
|
|
93
|
+
addAlarm(key: string, configure: (alarm: AlarmDefinitionBuilder<ITable>) => AlarmDefinitionBuilder<ITable>): this;
|
|
94
|
+
/** @internal — see ADR-0005. */
|
|
95
|
+
[COPY_STATE](target: TableV2Builder): void;
|
|
96
|
+
build(scope: IConstruct, id: string): TableV2BuilderResult;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Creates a new {@link ITableV2Builder} for configuring an AWS {@link TableV2}.
|
|
100
|
+
*
|
|
101
|
+
* This is the entry point for defining a `TableV2` (`AWS::DynamoDB::GlobalTable`)
|
|
102
|
+
* component — AWS's recommended construct for new tables. The returned builder
|
|
103
|
+
* exposes every {@link TableV2BuilderProps} property as a fluent setter/getter
|
|
104
|
+
* and implements {@link Lifecycle} for use with {@link compose}.
|
|
105
|
+
*
|
|
106
|
+
* @returns A fluent builder for an AWS DynamoDB {@link TableV2}.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* import { AttributeType } from "aws-cdk-lib/aws-dynamodb";
|
|
111
|
+
*
|
|
112
|
+
* const orders = createTableV2Builder().partitionKey({
|
|
113
|
+
* name: "orderId",
|
|
114
|
+
* type: AttributeType.STRING,
|
|
115
|
+
* });
|
|
116
|
+
*
|
|
117
|
+
* // Use standalone:
|
|
118
|
+
* const result = orders.build(stack, "Orders");
|
|
119
|
+
*
|
|
120
|
+
* // Or compose into a system, wiring the stream into a Lambda:
|
|
121
|
+
* const system = compose(
|
|
122
|
+
* { orders, processor: createFunctionBuilder() },
|
|
123
|
+
* { orders: [], processor: ["orders"] },
|
|
124
|
+
* );
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare function createTableV2Builder(): ITableV2Builder;
|
|
128
|
+
export {};
|
|
129
|
+
//# sourceMappingURL=table-v2-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-v2-builder.d.ts","sourceRoot":"","sources":["../../src/table-v2-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,KAAK,MAAM,EAAE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,KAAK,cAAc,EAAiB,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAIhE;;;;GAIG;AACH,MAAM,WAAW,mBAAoB,SAAQ,YAAY;IACvD;;;;;;;;;;;;OAYG;IACH,iBAAiB,CAAC,EAAE,gBAAgB,GAAG,KAAK,CAAC;CAC9C;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,qEAAqE;IACrE,KAAK,EAAE,OAAO,CAAC;IAEf;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,MAAM,eAAe,GAAG,cAAc,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAC;AAElF,cAAM,cAAe,YAAW,SAAS,CAAC,oBAAoB,CAAC;;IAC7D,KAAK,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAM;IAGzC,QAAQ,CACN,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,CAAC,KAAK,EAAE,sBAAsB,CAAC,MAAM,CAAC,KAAK,sBAAsB,CAAC,MAAM,CAAC,GACnF,IAAI;IAKP,gCAAgC;IAChC,CAAC,UAAU,CAAC,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI;IAI1C,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,GAAG,oBAAoB;CAsB3D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,oBAAoB,IAAI,eAAe,CAEtD"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { TableV2 } from "aws-cdk-lib/aws-dynamodb";
|
|
2
|
+
import { COPY_STATE } from "@composurecdk/core";
|
|
3
|
+
import { taggedBuilder } from "@composurecdk/cloudformation";
|
|
4
|
+
import { AlarmDefinitionBuilder } from "@composurecdk/cloudwatch";
|
|
5
|
+
import { createTableAlarms } from "./table-alarms.js";
|
|
6
|
+
import { TABLE_V2_DEFAULTS } from "./defaults.js";
|
|
7
|
+
class TableV2Builder {
|
|
8
|
+
props = {};
|
|
9
|
+
#customAlarms = [];
|
|
10
|
+
addAlarm(key, configure) {
|
|
11
|
+
this.#customAlarms.push(configure(new AlarmDefinitionBuilder(key)));
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
/** @internal — see ADR-0005. */
|
|
15
|
+
[COPY_STATE](target) {
|
|
16
|
+
target.#customAlarms.push(...this.#customAlarms);
|
|
17
|
+
}
|
|
18
|
+
build(scope, id) {
|
|
19
|
+
const { recommendedAlarms: alarmConfig, ...tableProps } = this.props;
|
|
20
|
+
// TableV2's billing and encryption defaults are single helper objects with
|
|
21
|
+
// no flat sibling props, so a same-key spread is sufficient — unlike the
|
|
22
|
+
// classic builder, there are no mutually-exclusive defaults to yield
|
|
23
|
+
// (ADR-0009).
|
|
24
|
+
const mergedProps = { ...TABLE_V2_DEFAULTS, ...tableProps };
|
|
25
|
+
const table = new TableV2(scope, id, mergedProps);
|
|
26
|
+
const alarms = createTableAlarms(scope, id, table, alarmConfig, this.#customAlarms);
|
|
27
|
+
// Unlike the classic Table (whose getter is undefined without a stream),
|
|
28
|
+
// TableV2.tableStreamArn always returns the CFN attribute token even when no
|
|
29
|
+
// stream is configured. Guard on the actual `dynamoStream` prop so the
|
|
30
|
+
// result stays honest — a downstream `ref()` consumer checking
|
|
31
|
+
// `result.tableStreamArn` should only see an ARN when a stream truly exists.
|
|
32
|
+
const tableStreamArn = mergedProps.dynamoStream ? table.tableStreamArn : undefined;
|
|
33
|
+
return { table, tableStreamArn, alarms };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new {@link ITableV2Builder} for configuring an AWS {@link TableV2}.
|
|
38
|
+
*
|
|
39
|
+
* This is the entry point for defining a `TableV2` (`AWS::DynamoDB::GlobalTable`)
|
|
40
|
+
* component — AWS's recommended construct for new tables. The returned builder
|
|
41
|
+
* exposes every {@link TableV2BuilderProps} property as a fluent setter/getter
|
|
42
|
+
* and implements {@link Lifecycle} for use with {@link compose}.
|
|
43
|
+
*
|
|
44
|
+
* @returns A fluent builder for an AWS DynamoDB {@link TableV2}.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { AttributeType } from "aws-cdk-lib/aws-dynamodb";
|
|
49
|
+
*
|
|
50
|
+
* const orders = createTableV2Builder().partitionKey({
|
|
51
|
+
* name: "orderId",
|
|
52
|
+
* type: AttributeType.STRING,
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
55
|
+
* // Use standalone:
|
|
56
|
+
* const result = orders.build(stack, "Orders");
|
|
57
|
+
*
|
|
58
|
+
* // Or compose into a system, wiring the stream into a Lambda:
|
|
59
|
+
* const system = compose(
|
|
60
|
+
* { orders, processor: createFunctionBuilder() },
|
|
61
|
+
* { orders: [], processor: ["orders"] },
|
|
62
|
+
* );
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export function createTableV2Builder() {
|
|
66
|
+
return taggedBuilder(TableV2Builder);
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=table-v2-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-v2-builder.js","sourceRoot":"","sources":["../../src/table-v2-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,OAAO,EAAqB,MAAM,0BAA0B,CAAC;AAEnF,OAAO,EAAE,UAAU,EAAkB,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAuB,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAyFlD,MAAM,cAAc;IAClB,KAAK,GAAiC,EAAE,CAAC;IAChC,aAAa,GAAqC,EAAE,CAAC;IAE9D,QAAQ,CACN,GAAW,EACX,SAAoF;QAEpF,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,sBAAsB,CAAS,GAAG,CAAC,CAAC,CAAC,CAAC;QAC5E,OAAO,IAAI,CAAC;IACd,CAAC;IAED,gCAAgC;IAChC,CAAC,UAAU,CAAC,CAAC,MAAsB;QACjC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,KAAiB,EAAE,EAAU;QACjC,MAAM,EAAE,iBAAiB,EAAE,WAAW,EAAE,GAAG,UAAU,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAErE,2EAA2E;QAC3E,yEAAyE;QACzE,qEAAqE;QACrE,cAAc;QACd,MAAM,WAAW,GAAG,EAAE,GAAG,iBAAiB,EAAE,GAAG,UAAU,EAAkB,CAAC;QAE5E,MAAM,KAAK,GAAG,IAAI,OAAO,CAAC,KAAK,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC;QAElD,MAAM,MAAM,GAAG,iBAAiB,CAAC,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAEpF,yEAAyE;QACzE,6EAA6E;QAC7E,uEAAuE;QACvE,+DAA+D;QAC/D,6EAA6E;QAC7E,MAAM,cAAc,GAAG,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC;QAEnF,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,CAAC;IAC3C,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO,aAAa,CAAsC,cAAc,CAAC,CAAC;AAC5E,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@composurecdk/dynamodb",
|
|
3
|
+
"version": "0.8.4",
|
|
4
|
+
"description": "Composable DynamoDB table builder with well-architected defaults",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/laazyj/composureCDK",
|
|
8
|
+
"directory": "packages/dynamodb"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"clean": "rm -rf dist .tshy .tshy-build",
|
|
17
|
+
"build": "tshy",
|
|
18
|
+
"typecheck": "tsc --noEmit",
|
|
19
|
+
"check:exports": "attw --pack . --profile node16 && publint",
|
|
20
|
+
"test": "vitest run",
|
|
21
|
+
"test:watch": "vitest"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"aws",
|
|
25
|
+
"cdk",
|
|
26
|
+
"aws-cdk",
|
|
27
|
+
"infrastructure-as-code",
|
|
28
|
+
"iac",
|
|
29
|
+
"composurecdk",
|
|
30
|
+
"dynamodb",
|
|
31
|
+
"database",
|
|
32
|
+
"nosql",
|
|
33
|
+
"serverless"
|
|
34
|
+
],
|
|
35
|
+
"author": "Jason Duffett (https://github.com/laazyj)",
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"type": "module",
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=20"
|
|
43
|
+
},
|
|
44
|
+
"tshy": {
|
|
45
|
+
"exports": {
|
|
46
|
+
"./package.json": "./package.json",
|
|
47
|
+
".": "./src/index.ts"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@composurecdk/cloudformation": "^0.8.0",
|
|
52
|
+
"@composurecdk/cloudwatch": "^0.8.0",
|
|
53
|
+
"@composurecdk/core": "^0.8.0",
|
|
54
|
+
"aws-cdk-lib": "^2.178.0",
|
|
55
|
+
"constructs": "^10.0.0"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@types/node": "^25.9.3",
|
|
59
|
+
"aws-cdk-lib": "^2.258.1",
|
|
60
|
+
"constructs": "^10.6.0",
|
|
61
|
+
"typescript": "^6.0.3",
|
|
62
|
+
"vitest": "^4.1.8"
|
|
63
|
+
},
|
|
64
|
+
"exports": {
|
|
65
|
+
"./package.json": "./package.json",
|
|
66
|
+
".": {
|
|
67
|
+
"import": {
|
|
68
|
+
"types": "./dist/esm/index.d.ts",
|
|
69
|
+
"default": "./dist/esm/index.js"
|
|
70
|
+
},
|
|
71
|
+
"require": {
|
|
72
|
+
"types": "./dist/commonjs/index.d.ts",
|
|
73
|
+
"default": "./dist/commonjs/index.js"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"main": "./dist/commonjs/index.js",
|
|
78
|
+
"types": "./dist/commonjs/index.d.ts",
|
|
79
|
+
"module": "./dist/esm/index.js"
|
|
80
|
+
}
|