@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,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveTableAlarmDefinitions = resolveTableAlarmDefinitions;
|
|
4
|
+
exports.createTableAlarms = createTableAlarms;
|
|
5
|
+
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
6
|
+
const aws_cloudwatch_1 = require("aws-cdk-lib/aws-cloudwatch");
|
|
7
|
+
const aws_dynamodb_1 = require("aws-cdk-lib/aws-dynamodb");
|
|
8
|
+
const cloudwatch_1 = require("@composurecdk/cloudwatch");
|
|
9
|
+
const table_alarm_defaults_js_1 = require("./table-alarm-defaults.js");
|
|
10
|
+
const METRIC_PERIOD = aws_cdk_lib_1.Duration.minutes(1);
|
|
11
|
+
const METRIC_PERIOD_LABEL = `${String(METRIC_PERIOD.toMinutes())} minute`;
|
|
12
|
+
/**
|
|
13
|
+
* Operations the default `systemErrors` alarm sums over. A CloudWatch alarm on
|
|
14
|
+
* a metric-math expression may reference at most 10 individual metrics, and
|
|
15
|
+
* DynamoDB defines 14 operations — so the full-table aggregate cannot be
|
|
16
|
+
* alarmed directly. These ten are the core SDK data-plane operations (single
|
|
17
|
+
* item, query/scan, batch, and transactions); the PartiQL statement operations
|
|
18
|
+
* and the stream `GetRecords` operation are omitted. Override via a custom
|
|
19
|
+
* `addAlarm` if your workload's error profile lives in the excluded set.
|
|
20
|
+
*/
|
|
21
|
+
const SYSTEM_ERROR_OPERATIONS = [
|
|
22
|
+
aws_dynamodb_1.Operation.GET_ITEM,
|
|
23
|
+
aws_dynamodb_1.Operation.BATCH_GET_ITEM,
|
|
24
|
+
aws_dynamodb_1.Operation.QUERY,
|
|
25
|
+
aws_dynamodb_1.Operation.SCAN,
|
|
26
|
+
aws_dynamodb_1.Operation.PUT_ITEM,
|
|
27
|
+
aws_dynamodb_1.Operation.UPDATE_ITEM,
|
|
28
|
+
aws_dynamodb_1.Operation.DELETE_ITEM,
|
|
29
|
+
aws_dynamodb_1.Operation.BATCH_WRITE_ITEM,
|
|
30
|
+
aws_dynamodb_1.Operation.TRANSACT_GET_ITEMS,
|
|
31
|
+
aws_dynamodb_1.Operation.TRANSACT_WRITE_ITEMS,
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
* Builds a table-scoped `AWS/DynamoDB` metric with the `TableName` dimension.
|
|
35
|
+
*/
|
|
36
|
+
function tableMetric(table, metricName) {
|
|
37
|
+
return new aws_cloudwatch_1.Metric({
|
|
38
|
+
namespace: "AWS/DynamoDB",
|
|
39
|
+
metricName,
|
|
40
|
+
dimensionsMap: { TableName: table.tableName },
|
|
41
|
+
statistic: aws_cloudwatch_1.Stats.SUM,
|
|
42
|
+
period: METRIC_PERIOD,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Resolves the recommended alarm configuration into fully-resolved
|
|
47
|
+
* {@link AlarmDefinition}s for a DynamoDB table.
|
|
48
|
+
*/
|
|
49
|
+
function resolveTableAlarmDefinitions(table, config) {
|
|
50
|
+
if (config?.enabled === false)
|
|
51
|
+
return [];
|
|
52
|
+
const definitions = [];
|
|
53
|
+
if (config?.systemErrors !== false) {
|
|
54
|
+
const cfg = (0, cloudwatch_1.resolveAlarmConfig)(config?.systemErrors, table_alarm_defaults_js_1.TABLE_ALARM_DEFAULTS.systemErrors);
|
|
55
|
+
definitions.push({
|
|
56
|
+
key: "systemErrors",
|
|
57
|
+
alarmName: cfg.alarmName,
|
|
58
|
+
// metricSystemErrorsForOperations sums SystemErrors across the given
|
|
59
|
+
// operations into a single MathExpression — the per-operation dimension
|
|
60
|
+
// means there is no single plain Metric for "errors on this table".
|
|
61
|
+
metric: table.metricSystemErrorsForOperations({
|
|
62
|
+
period: METRIC_PERIOD,
|
|
63
|
+
operations: SYSTEM_ERROR_OPERATIONS,
|
|
64
|
+
}),
|
|
65
|
+
threshold: cfg.threshold,
|
|
66
|
+
comparisonOperator: aws_cloudwatch_1.ComparisonOperator.GREATER_THAN_THRESHOLD,
|
|
67
|
+
evaluationPeriods: cfg.evaluationPeriods,
|
|
68
|
+
datapointsToAlarm: cfg.datapointsToAlarm,
|
|
69
|
+
treatMissingData: cfg.treatMissingData,
|
|
70
|
+
description: `DynamoDB table is returning server-side (HTTP 500) errors, summed across the core data-plane operations. ` +
|
|
71
|
+
`Threshold: > ${String(cfg.threshold)} in ${METRIC_PERIOD_LABEL}.`,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (config?.readThrottleEvents !== false) {
|
|
75
|
+
const cfg = (0, cloudwatch_1.resolveAlarmConfig)(config?.readThrottleEvents, table_alarm_defaults_js_1.TABLE_ALARM_DEFAULTS.readThrottleEvents);
|
|
76
|
+
definitions.push({
|
|
77
|
+
key: "readThrottleEvents",
|
|
78
|
+
alarmName: cfg.alarmName,
|
|
79
|
+
metric: tableMetric(table, "ReadThrottleEvents"),
|
|
80
|
+
threshold: cfg.threshold,
|
|
81
|
+
comparisonOperator: aws_cloudwatch_1.ComparisonOperator.GREATER_THAN_THRESHOLD,
|
|
82
|
+
evaluationPeriods: cfg.evaluationPeriods,
|
|
83
|
+
datapointsToAlarm: cfg.datapointsToAlarm,
|
|
84
|
+
treatMissingData: cfg.treatMissingData,
|
|
85
|
+
description: `DynamoDB table read requests are being throttled, indicating a hot partition or ` +
|
|
86
|
+
`insufficient read capacity. Threshold: > ${String(cfg.threshold)} in ${METRIC_PERIOD_LABEL}.`,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (config?.writeThrottleEvents !== false) {
|
|
90
|
+
const cfg = (0, cloudwatch_1.resolveAlarmConfig)(config?.writeThrottleEvents, table_alarm_defaults_js_1.TABLE_ALARM_DEFAULTS.writeThrottleEvents);
|
|
91
|
+
definitions.push({
|
|
92
|
+
key: "writeThrottleEvents",
|
|
93
|
+
alarmName: cfg.alarmName,
|
|
94
|
+
metric: tableMetric(table, "WriteThrottleEvents"),
|
|
95
|
+
threshold: cfg.threshold,
|
|
96
|
+
comparisonOperator: aws_cloudwatch_1.ComparisonOperator.GREATER_THAN_THRESHOLD,
|
|
97
|
+
evaluationPeriods: cfg.evaluationPeriods,
|
|
98
|
+
datapointsToAlarm: cfg.datapointsToAlarm,
|
|
99
|
+
treatMissingData: cfg.treatMissingData,
|
|
100
|
+
description: `DynamoDB table write requests are being throttled, indicating a hot partition or ` +
|
|
101
|
+
`insufficient write capacity. Threshold: > ${String(cfg.threshold)} in ${METRIC_PERIOD_LABEL}.`,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return definitions;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Creates AWS-recommended CloudWatch alarms for a DynamoDB table, merging
|
|
108
|
+
* recommended definitions with any custom alarm builders.
|
|
109
|
+
*
|
|
110
|
+
* @param scope - CDK construct scope for creating alarm constructs.
|
|
111
|
+
* @param id - Base identifier for alarm construct ids.
|
|
112
|
+
* @param table - The DynamoDB table to create alarms for.
|
|
113
|
+
* @param config - User-provided alarm configuration, or `false` to disable all.
|
|
114
|
+
* @param customAlarms - Custom alarm builders added via `addAlarm()`.
|
|
115
|
+
* @returns A record mapping alarm keys to their created Alarm constructs.
|
|
116
|
+
*
|
|
117
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#DynamoDB
|
|
118
|
+
*/
|
|
119
|
+
function createTableAlarms(scope, id, table, config, customAlarms = []) {
|
|
120
|
+
if (config === false)
|
|
121
|
+
return {};
|
|
122
|
+
const enabled = config?.enabled ?? table_alarm_defaults_js_1.TABLE_ALARM_DEFAULTS.enabled;
|
|
123
|
+
if (!enabled)
|
|
124
|
+
return {};
|
|
125
|
+
const recommended = resolveTableAlarmDefinitions(table, config);
|
|
126
|
+
const custom = customAlarms.map((b) => b.resolve(table));
|
|
127
|
+
return (0, cloudwatch_1.createAlarms)(scope, id, [...recommended, ...custom]);
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=table-alarms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-alarms.js","sourceRoot":"","sources":["../../src/table-alarms.ts"],"names":[],"mappings":";;AAyDA,oEAwEC;AAeD,8CAgBC;AAhKD,6CAAuC;AACvC,+DAMoC;AACpC,2DAAkE;AAGlE,yDAAoG;AAEpG,uEAAiE;AAEjE,MAAM,aAAa,GAAG,sBAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC1C,MAAM,mBAAmB,GAAG,GAAG,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC,SAAS,CAAC;AAE1E;;;;;;;;GAQG;AACH,MAAM,uBAAuB,GAAgB;IAC3C,wBAAS,CAAC,QAAQ;IAClB,wBAAS,CAAC,cAAc;IACxB,wBAAS,CAAC,KAAK;IACf,wBAAS,CAAC,IAAI;IACd,wBAAS,CAAC,QAAQ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AAC,gBAAgB;YACtC,WAAW,EACT,mFAAmF;gBACnF,6CAA6C,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,mBAAmB,GAAG;SAClG,CAAC,CAAC;IACL,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,iBAAiB,CAC/B,KAAiB,EACjB,EAAU,EACV,KAAa,EACb,MAA4C,EAC5C,eAAiD,EAAE;IAEnD,IAAI,MAAM,KAAK,KAAK;QAAE,OAAO,EAAE,CAAC;IAEhC,MAAM,OAAO,GAAG,MAAM,EAAE,OAAO,IAAI,8CAAoB,CAAC,OAAO,CAAC;IAChE,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IAExB,MAAM,WAAW,GAAG,4BAA4B,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAChE,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IAEzD,OAAO,IAAA,yBAAY,EAAC,KAAK,EAAE,EAAE,EAAE,CAAC,GAAG,WAAW,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { type Alarm } from "aws-cdk-lib/aws-cloudwatch";
|
|
2
|
+
import { type ITable, Table, type TableProps } 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 table builder.
|
|
10
|
+
*
|
|
11
|
+
* Extends the CDK {@link TableProps} with additional builder-specific options.
|
|
12
|
+
*/
|
|
13
|
+
export interface TableBuilderProps extends TableProps {
|
|
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 ITableBuilder}. Contains the CDK constructs
|
|
31
|
+
* created during {@link Lifecycle.build}, keyed by role.
|
|
32
|
+
*/
|
|
33
|
+
export interface TableBuilderResult {
|
|
34
|
+
/** The classic DynamoDB {@link Table} construct created by the builder. */
|
|
35
|
+
table: Table;
|
|
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 ITableBuilder.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 DynamoDB table.
|
|
51
|
+
*
|
|
52
|
+
* Wraps the classic {@link Table} construct (`AWS::DynamoDB::Table`). For new
|
|
53
|
+
* tables, prefer {@link createTableV2Builder} ({@link TableV2}) — AWS recommends
|
|
54
|
+
* it, and it lets you add cross-region replicas later without replacing the
|
|
55
|
+
* table. Reach for this classic builder when you need an `importSource` (S3 bulk
|
|
56
|
+
* import, V1-only) or parity with existing classic tables. Note the two are
|
|
57
|
+
* different CloudFormation resources and cannot be migrated in place.
|
|
58
|
+
*
|
|
59
|
+
* Each configuration property from the CDK {@link TableProps} is exposed as an
|
|
60
|
+
* overloaded method: call with a value to set it (returns the builder for
|
|
61
|
+
* chaining), or call with no arguments to read the current value.
|
|
62
|
+
*
|
|
63
|
+
* The builder implements {@link Lifecycle}, so it can be used directly as a
|
|
64
|
+
* component in a {@link compose | composed system}. When built, it creates a
|
|
65
|
+
* DynamoDB table with the configured properties — merged with secure,
|
|
66
|
+
* AWS-recommended {@link TABLE_DEFAULTS} — and returns a {@link TableBuilderResult}.
|
|
67
|
+
*
|
|
68
|
+
* The builder also creates AWS-recommended CloudWatch alarms by default. Alarms
|
|
69
|
+
* can be customized or disabled via the `recommendedAlarms` property. Custom
|
|
70
|
+
* alarms can be added via the {@link addAlarm} method.
|
|
71
|
+
*
|
|
72
|
+
* @see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.Table.html
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* import { AttributeType, StreamViewType } from "aws-cdk-lib/aws-dynamodb";
|
|
77
|
+
*
|
|
78
|
+
* const orders = createTableBuilder()
|
|
79
|
+
* .partitionKey({ name: "pk", type: AttributeType.STRING })
|
|
80
|
+
* .sortKey({ name: "sk", type: AttributeType.STRING })
|
|
81
|
+
* .stream(StreamViewType.NEW_AND_OLD_IMAGES);
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export type ITableBuilder = ITaggedBuilder<TableBuilderProps, TableBuilder>;
|
|
85
|
+
declare class TableBuilder implements Lifecycle<TableBuilderResult> {
|
|
86
|
+
#private;
|
|
87
|
+
props: Partial<TableBuilderProps>;
|
|
88
|
+
addAlarm(key: string, configure: (alarm: AlarmDefinitionBuilder<ITable>) => AlarmDefinitionBuilder<ITable>): this;
|
|
89
|
+
/** @internal — see ADR-0005. */
|
|
90
|
+
[COPY_STATE](target: TableBuilder): void;
|
|
91
|
+
build(scope: IConstruct, id: string): TableBuilderResult;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Creates a new {@link ITableBuilder} for configuring an AWS DynamoDB table.
|
|
95
|
+
*
|
|
96
|
+
* This is the entry point for defining a DynamoDB table component. The returned
|
|
97
|
+
* builder exposes every {@link TableBuilderProps} property as a fluent
|
|
98
|
+
* setter/getter and implements {@link Lifecycle} for use with {@link compose}.
|
|
99
|
+
*
|
|
100
|
+
* @returns A fluent builder for an AWS DynamoDB table.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* import { AttributeType } from "aws-cdk-lib/aws-dynamodb";
|
|
105
|
+
*
|
|
106
|
+
* const orders = createTableBuilder().partitionKey({
|
|
107
|
+
* name: "orderId",
|
|
108
|
+
* type: AttributeType.STRING,
|
|
109
|
+
* });
|
|
110
|
+
*
|
|
111
|
+
* // Use standalone:
|
|
112
|
+
* const result = orders.build(stack, "Orders");
|
|
113
|
+
*
|
|
114
|
+
* // Or compose into a system, wiring the stream into a Lambda:
|
|
115
|
+
* const system = compose(
|
|
116
|
+
* { orders, processor: createFunctionBuilder() },
|
|
117
|
+
* { orders: [], processor: ["orders"] },
|
|
118
|
+
* );
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare function createTableBuilder(): ITableBuilder;
|
|
122
|
+
export {};
|
|
123
|
+
//# sourceMappingURL=table-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-builder.d.ts","sourceRoot":"","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CAAC,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAIxC,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,GAAG,kBAAkB;CAWzD;AAgCD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,kBAAkB,IAAI,aAAa,CAElD"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTableBuilder = createTableBuilder;
|
|
4
|
+
const aws_dynamodb_1 = require("aws-cdk-lib/aws-dynamodb");
|
|
5
|
+
const core_1 = require("@composurecdk/core");
|
|
6
|
+
const cloudformation_1 = require("@composurecdk/cloudformation");
|
|
7
|
+
const cloudwatch_1 = require("@composurecdk/cloudwatch");
|
|
8
|
+
const table_alarms_js_1 = require("./table-alarms.js");
|
|
9
|
+
const defaults_js_1 = require("./defaults.js");
|
|
10
|
+
class TableBuilder {
|
|
11
|
+
props = {};
|
|
12
|
+
#customAlarms = [];
|
|
13
|
+
addAlarm(key, configure) {
|
|
14
|
+
this.#customAlarms.push(configure(new cloudwatch_1.AlarmDefinitionBuilder(key)));
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
/** @internal — see ADR-0005. */
|
|
18
|
+
[core_1.COPY_STATE](target) {
|
|
19
|
+
target.#customAlarms.push(...this.#customAlarms);
|
|
20
|
+
}
|
|
21
|
+
build(scope, id) {
|
|
22
|
+
const { recommendedAlarms: alarmConfig, ...tableProps } = this.props;
|
|
23
|
+
const mergedProps = mergeTableDefaults(tableProps);
|
|
24
|
+
const table = new aws_dynamodb_1.Table(scope, id, mergedProps);
|
|
25
|
+
const alarms = (0, table_alarms_js_1.createTableAlarms)(scope, id, table, alarmConfig, this.#customAlarms);
|
|
26
|
+
return { table, tableStreamArn: table.tableStreamArn, alarms };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Merges {@link TABLE_DEFAULTS} under the user's props, then resolves the two
|
|
31
|
+
* cases where a default is mutually exclusive with a sibling the user set
|
|
32
|
+
* (ADR-0009): the `billingMode` default yields to provisioned capacity, and
|
|
33
|
+
* the `encryption` default yields to a customer-managed key.
|
|
34
|
+
*/
|
|
35
|
+
function mergeTableDefaults(props) {
|
|
36
|
+
const merged = { ...defaults_js_1.TABLE_DEFAULTS, ...props };
|
|
37
|
+
// billingMode (default PAY_PER_REQUEST) is mutually exclusive with
|
|
38
|
+
// readCapacity / writeCapacity. If the user set capacity but not the mode,
|
|
39
|
+
// drop the on-demand default so CDK falls back to PROVISIONED. Setting both
|
|
40
|
+
// explicitly is left for CDK to reject.
|
|
41
|
+
const userSetCapacity = props.readCapacity !== undefined || props.writeCapacity !== undefined;
|
|
42
|
+
if (userSetCapacity && props.billingMode === undefined) {
|
|
43
|
+
delete merged.billingMode;
|
|
44
|
+
}
|
|
45
|
+
// encryption (default AWS_MANAGED) is mutually exclusive with a user-supplied
|
|
46
|
+
// encryptionKey, which CDK only accepts under CUSTOMER_MANAGED. Providing a
|
|
47
|
+
// key is an unambiguous request for customer-managed encryption, so infer the
|
|
48
|
+
// mode rather than forcing the user to set both.
|
|
49
|
+
if (props.encryptionKey !== undefined && props.encryption === undefined) {
|
|
50
|
+
merged.encryption = aws_dynamodb_1.TableEncryption.CUSTOMER_MANAGED;
|
|
51
|
+
}
|
|
52
|
+
// 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.
|
|
53
|
+
return merged;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Creates a new {@link ITableBuilder} for configuring an AWS DynamoDB table.
|
|
57
|
+
*
|
|
58
|
+
* This is the entry point for defining a DynamoDB table component. The returned
|
|
59
|
+
* builder exposes every {@link TableBuilderProps} property as a fluent
|
|
60
|
+
* setter/getter and implements {@link Lifecycle} for use with {@link compose}.
|
|
61
|
+
*
|
|
62
|
+
* @returns A fluent builder for an AWS DynamoDB table.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { AttributeType } from "aws-cdk-lib/aws-dynamodb";
|
|
67
|
+
*
|
|
68
|
+
* const orders = createTableBuilder().partitionKey({
|
|
69
|
+
* name: "orderId",
|
|
70
|
+
* type: AttributeType.STRING,
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* // Use standalone:
|
|
74
|
+
* const result = orders.build(stack, "Orders");
|
|
75
|
+
*
|
|
76
|
+
* // Or compose into a system, wiring the stream into a Lambda:
|
|
77
|
+
* const system = compose(
|
|
78
|
+
* { orders, processor: createFunctionBuilder() },
|
|
79
|
+
* { orders: [], processor: ["orders"] },
|
|
80
|
+
* );
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
function createTableBuilder() {
|
|
84
|
+
return (0, cloudformation_1.taggedBuilder)(TableBuilder);
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=table-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-builder.js","sourceRoot":"","sources":["../../src/table-builder.ts"],"names":[],"mappings":";;AAoLA,gDAEC;AArLD,2DAAgG;AAEhG,6CAAgE;AAChE,iEAAkF;AAClF,yDAAkE;AAElE,uDAAsD;AACtD,+CAA+C;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,mCAAsB,CAAS,GAAG,CAAC,CAAC,CAAC,CAAC;QAC5E,OAAO,IAAI,CAAC;IACd,CAAC;IAED,gCAAgC;IAChC,CAAC,iBAAU,CAAC,CA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C1X,OAAO,MAAoB,CAAC;AAC9B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAgB,kBAAkB;IAChC,OAAO,IAAA,8BAAa,EAAkC,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,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ule", { value: true });
|
|
3
|
+
exports.createTableV2Builder = createTableV2Builder;
|
|
4
|
+
const aws_dynamodb_1 = require("aws-cdk-lib/aws-dynamodb");
|
|
5
|
+
const core_1 = require("@composurecdk/core");
|
|
6
|
+
const cloudformation_1 = require("@composurecdk/cloudformation");
|
|
7
|
+
const cloudwatch_1 = require("@composurecdk/cloudwatch");
|
|
8
|
+
const table_alarms_js_1 = require("./table-alarms.js");
|
|
9
|
+
const defaults_js_1 = require("./defaults.js");
|
|
10
|
+
class TableV2Builder {
|
|
11
|
+
props = {};
|
|
12
|
+
#customAlarms = [];
|
|
13
|
+
addAlarm(key, configure) {
|
|
14
|
+
this.#customAlarms.push(configure(new cloudwatch_1.AlarmDefinitionBuilder(key)));
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
/** @internal — see ADR-0005. */
|
|
18
|
+
[core_1.COPY_STATE](target) {
|
|
19
|
+
target.#customAlarms.push(...this.#customAlarms);
|
|
20
|
+
}
|
|
21
|
+
build(scope, id) {
|
|
22
|
+
const { recommendedAlarms: alarmConfig, ...tableProps } = this.props;
|
|
23
|
+
// TableV2's billing and encryption defaults are single helper objects with
|
|
24
|
+
// no flat sibling props, so a same-key spread is sufficient — unlike the
|
|
25
|
+
// classic builder, there are no mutually-exclusive defaults to yield
|
|
26
|
+
// (ADR-0009).
|
|
27
|
+
const mergedProps = { ...defaults_js_1.TABLE_V2_DEFAULTS, ...tableProps };
|
|
28
|
+
const table = new aws_dynamodb_1.TableV2(scope, id, mergedProps);
|
|
29
|
+
const alarms = (0, table_alarms_js_1.createTableAlarms)(scope, id, table, alarmConfig, this.#customAlarms);
|
|
30
|
+
// Unlike the classic Table (whose getter is undefined without a stream),
|
|
31
|
+
// TableV2.tableStreamArn always returns the CFN attribute token even when no
|
|
32
|
+
// stream is configured. Guard on the actual `dynamoStream` prop so the
|
|
33
|
+
// result stays honest — a downstream `ref()` consumer checking
|
|
34
|
+
// `result.tableStreamArn` should only see an ARN when a stream truly exists.
|
|
35
|
+
const tableStreamArn = mergedProps.dynamoStream ? table.tableStreamArn : undefined;
|
|
36
|
+
return { table, tableStreamArn, alarms };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new {@link ITableV2Builder} for configuring an AWS {@link TableV2}.
|
|
41
|
+
*
|
|
42
|
+
* This is the entry point for defining a `TableV2` (`AWS::DynamoDB::GlobalTable`)
|
|
43
|
+
* component — AWS's recommended construct for new tables. The returned builder
|
|
44
|
+
* exposes every {@link TableV2BuilderProps} property as a fluent setter/getter
|
|
45
|
+
* and implements {@link Lifecycle} for use with {@link compose}.
|
|
46
|
+
*
|
|
47
|
+
* @returns A fluent builder for an AWS DynamoDB {@link TableV2}.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { AttributeType } from "aws-cdk-lib/aws-dynamodb";
|
|
52
|
+
*
|
|
53
|
+
* const orders = createTableV2Builder().partitionKey({
|
|
54
|
+
* name: "orderId",
|
|
55
|
+
* type: AttributeType.STRING,
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* // Use standalone:
|
|
59
|
+
* const result = orders.build(stack, "Orders");
|
|
60
|
+
*
|
|
61
|
+
* // Or compose into a system, wiring the stream into a Lambda:
|
|
62
|
+
* const system = compose(
|
|
63
|
+
* { orders, processor: createFunctionBuilder() },
|
|
64
|
+
* { orders: [], processor: ["orders"] },
|
|
65
|
+
* );
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
function createTableV2Builder() {
|
|
69
|
+
return (0, cloudformation_1.taggedBuilder)(TableV2Builder);
|
|
70
|
+
}
|
|
71
|
+
//# 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":";;AAuKA,oDAEC;AAxKD,2DAAmF;AAEnF,6CAAgE;AAChE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BG;AACH,SAAgB,oBAAoB;IAClC,OAAO,IAAA,8BAAa,EAAsC,cAAc,CAAC,CAAC;AAC5E,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type TableProps, type TablePropsV2 } from "aws-cdk-lib/aws-dynamodb";
|
|
2
|
+
/**
|
|
3
|
+
* Secure, AWS-recommended defaults applied to every DynamoDB table built
|
|
4
|
+
* with {@link createTableBuilder}. Each property can be individually
|
|
5
|
+
* overridden via the builder's fluent API.
|
|
6
|
+
*
|
|
7
|
+
* `partitionKey` is intentionally not defaulted — the key schema is the
|
|
8
|
+
* single most workload-specific decision for a table and there is no safe
|
|
9
|
+
* generic value. The builder requires it to be set before {@link Lifecycle.build}.
|
|
10
|
+
*/
|
|
11
|
+
export declare const TABLE_DEFAULTS: Partial<TableProps>;
|
|
12
|
+
/**
|
|
13
|
+
* Secure, AWS-recommended defaults applied to every DynamoDB table built with
|
|
14
|
+
* {@link createTableV2Builder}. These encode the same well-architected intent
|
|
15
|
+
* as {@link TABLE_DEFAULTS} (on-demand billing, AWS-managed-KMS encryption,
|
|
16
|
+
* point-in-time recovery, deletion protection) against the `TableV2`
|
|
17
|
+
* (`AWS::DynamoDB::GlobalTable`) prop shape, where billing and encryption are
|
|
18
|
+
* single helper objects rather than flat props.
|
|
19
|
+
*
|
|
20
|
+
* As with {@link TABLE_DEFAULTS}, `partitionKey` is intentionally not defaulted
|
|
21
|
+
* — the key schema is the single most workload-specific decision for a table
|
|
22
|
+
* and there is no safe generic value.
|
|
23
|
+
*/
|
|
24
|
+
export declare const TABLE_V2_DEFAULTS: Partial<TablePropsV2>;
|
|
25
|
+
//# sourceMappingURL=defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,UAAU,EACf,KAAK,YAAY,EAClB,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,EAAE,OAAO,CAAC,UAAU,CAwD9C,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,EAAE,OAAO,CAAC,YAAY,CA4DnD,CAAC"}
|