@aws-blocks/bb-distributed-table 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cdk.d.ts.map +1 -1
- package/dist/index.cdk.js +5 -0
- package/dist/index.cdk.test.js +24 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
- package/src/index.cdk.test.ts +26 -2
- package/src/index.cdk.ts +5 -0
- package/src/version.ts +1 -1
package/dist/index.cdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cdk.d.ts","sourceRoot":"","sources":["../src/index.cdk.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,EAAoC,MAAM,sBAAsB,CAAC;AAC/E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAInD,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,YAAY,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,cAAc,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEhL,qBAAa,gBAAgB,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,KAAK;IAcA,OAAO,EAAE,GAAG;IAb/D,OAAO,CAAC,KAAK,CAAS;IAEtB;;;;;;OAMG;IACH,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB;gBAI5C,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,EAAS,OAAO,EAAE,GAAG;
|
|
1
|
+
{"version":3,"file":"index.cdk.d.ts","sourceRoot":"","sources":["../src/index.cdk.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,EAAoC,MAAM,sBAAsB,CAAC;AAC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ToLiveAttribute: config.ttl || undefined,
|
|
70
|
+
// Durability follows the stack-wide `defaults` (sandbox → DESTROY +
|
|
71
|
+
// no protection so a teardown is clean; production → RETAIN + protected).
|
|
72
|
+
// A richer per-block override lands with the `protection` option in #282.
|
|
73
|
+
removalPolicy: this.defaults.removalPolicy,
|
|
74
|
+
deletionProtection: this.defaults.deletionProtection,
|
|
70
75
|
});
|
|
71
76
|
this.table.grantReadWriteData(this.handler);
|
|
72
77
|
// Explicit index query permissions
|
package/dist/index.cdk.test.js
CHANGED
|
@@ -13,7 +13,7 @@ import { test } from 'node:test';
|
|
|
13
13
|
import assert from 'node:assert';
|
|
14
14
|
import * as cdk from 'aws-cdk-lib';
|
|
15
15
|
import { Template } from 'aws-cdk-lib/assertions';
|
|
16
|
-
import { Scope, DEFAULT_NODE_RUNTIME } from '@aws-blocks/core/cdk';
|
|
16
|
+
import { Scope, DEFAULT_NODE_RUNTIME, BlocksPresets } from '@aws-blocks/core/cdk';
|
|
17
17
|
import { z } from 'zod';
|
|
18
18
|
import { DistributedTable } from './index.cdk.js';
|
|
19
19
|
const userSchema = z.object({
|
|
@@ -24,6 +24,7 @@ const userSchema = z.object({
|
|
|
24
24
|
class StubBlocksStack extends cdk.Stack {
|
|
25
25
|
handler;
|
|
26
26
|
id;
|
|
27
|
+
defaults = BlocksPresets.production;
|
|
27
28
|
constructor(scope, id) {
|
|
28
29
|
super(scope, id);
|
|
29
30
|
this.id = id;
|
|
@@ -35,9 +36,10 @@ class StubBlocksStack extends cdk.Stack {
|
|
|
35
36
|
});
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
|
-
function setup() {
|
|
39
|
+
function setup(defaults = BlocksPresets.production) {
|
|
39
40
|
const app = new cdk.App();
|
|
40
41
|
const stack = new StubBlocksStack(app, 'TestStack');
|
|
42
|
+
stack.defaults = defaults;
|
|
41
43
|
const parent = new Scope('app');
|
|
42
44
|
return { stack, parent };
|
|
43
45
|
}
|
|
@@ -50,6 +52,26 @@ test('CDK: default DistributedTable provisions a DynamoDB table', () => {
|
|
|
50
52
|
const template = Template.fromStack(stack);
|
|
51
53
|
template.resourceCountIs('AWS::DynamoDB::Table', 1);
|
|
52
54
|
});
|
|
55
|
+
test('CDK: table adopts sandbox defaults (DESTROY, deletion protection off)', () => {
|
|
56
|
+
const { stack, parent } = setup(BlocksPresets.sandbox);
|
|
57
|
+
new DistributedTable(parent, 'users', {
|
|
58
|
+
schema: userSchema,
|
|
59
|
+
key: { partitionKey: 'userId', sortKey: 'createdAt' },
|
|
60
|
+
});
|
|
61
|
+
const template = Template.fromStack(stack);
|
|
62
|
+
template.hasResource('AWS::DynamoDB::Table', { DeletionPolicy: 'Delete' });
|
|
63
|
+
template.hasResourceProperties('AWS::DynamoDB::Table', { DeletionProtectionEnabled: false });
|
|
64
|
+
});
|
|
65
|
+
test('CDK: table adopts production defaults (RETAIN, deletion protection on)', () => {
|
|
66
|
+
const { stack, parent } = setup(BlocksPresets.production);
|
|
67
|
+
new DistributedTable(parent, 'users', {
|
|
68
|
+
schema: userSchema,
|
|
69
|
+
key: { partitionKey: 'userId', sortKey: 'createdAt' },
|
|
70
|
+
});
|
|
71
|
+
const template = Template.fromStack(stack);
|
|
72
|
+
template.hasResource('AWS::DynamoDB::Table', { DeletionPolicy: 'Retain' });
|
|
73
|
+
template.hasResourceProperties('AWS::DynamoDB::Table', { DeletionProtectionEnabled: true });
|
|
74
|
+
});
|
|
53
75
|
test('CDK: DistributedTable.fromExisting does NOT provision a table (regression)', () => {
|
|
54
76
|
const { stack, parent } = setup();
|
|
55
77
|
new DistributedTable(parent, 'users', {
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-blocks/bb-distributed-table",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/aws-devtools-labs/aws-blocks.git",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"test": "node --test --test-concurrency=1 dist/index.test.js dist/parity.test.js dist/index.cdk.test.js"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@aws-blocks/core": "^0.
|
|
43
|
-
"@aws-blocks/bb-logger": "^0.1.
|
|
42
|
+
"@aws-blocks/core": "^0.2.0",
|
|
43
|
+
"@aws-blocks/bb-logger": "^0.1.4",
|
|
44
44
|
"@aws-sdk/client-dynamodb": "^3.0.0",
|
|
45
45
|
"@aws-sdk/lib-dynamodb": "^3.0.0",
|
|
46
46
|
"@standard-schema/spec": "^1.0.0",
|
package/src/index.cdk.test.ts
CHANGED
|
@@ -15,7 +15,7 @@ import assert from 'node:assert';
|
|
|
15
15
|
import * as cdk from 'aws-cdk-lib';
|
|
16
16
|
import type { Construct } from 'constructs';
|
|
17
17
|
import { Template } from 'aws-cdk-lib/assertions';
|
|
18
|
-
import { Scope, DEFAULT_NODE_RUNTIME } from '@aws-blocks/core/cdk';
|
|
18
|
+
import { Scope, DEFAULT_NODE_RUNTIME, BlocksPresets, type BlocksDefaults } from '@aws-blocks/core/cdk';
|
|
19
19
|
import { z } from 'zod';
|
|
20
20
|
import { DistributedTable } from './index.cdk.js';
|
|
21
21
|
|
|
@@ -28,6 +28,7 @@ const userSchema = z.object({
|
|
|
28
28
|
class StubBlocksStack extends cdk.Stack {
|
|
29
29
|
public readonly handler: cdk.aws_lambda.Function;
|
|
30
30
|
public readonly id: string;
|
|
31
|
+
public defaults: BlocksDefaults = BlocksPresets.production;
|
|
31
32
|
constructor(scope: Construct, id: string) {
|
|
32
33
|
super(scope, id);
|
|
33
34
|
this.id = id;
|
|
@@ -40,9 +41,10 @@ class StubBlocksStack extends cdk.Stack {
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
function setup(): { stack: StubBlocksStack; parent: Scope } {
|
|
44
|
+
function setup(defaults: BlocksDefaults = BlocksPresets.production): { stack: StubBlocksStack; parent: Scope } {
|
|
44
45
|
const app = new cdk.App();
|
|
45
46
|
const stack = new StubBlocksStack(app, 'TestStack');
|
|
47
|
+
stack.defaults = defaults;
|
|
46
48
|
const parent = new Scope('app');
|
|
47
49
|
return { stack, parent };
|
|
48
50
|
}
|
|
@@ -57,6 +59,28 @@ test('CDK: default DistributedTable provisions a DynamoDB table', () => {
|
|
|
57
59
|
template.resourceCountIs('AWS::DynamoDB::Table', 1);
|
|
58
60
|
});
|
|
59
61
|
|
|
62
|
+
test('CDK: table adopts sandbox defaults (DESTROY, deletion protection off)', () => {
|
|
63
|
+
const { stack, parent } = setup(BlocksPresets.sandbox);
|
|
64
|
+
new DistributedTable(parent, 'users', {
|
|
65
|
+
schema: userSchema,
|
|
66
|
+
key: { partitionKey: 'userId', sortKey: 'createdAt' },
|
|
67
|
+
});
|
|
68
|
+
const template = Template.fromStack(stack);
|
|
69
|
+
template.hasResource('AWS::DynamoDB::Table', { DeletionPolicy: 'Delete' });
|
|
70
|
+
template.hasResourceProperties('AWS::DynamoDB::Table', { DeletionProtectionEnabled: false });
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('CDK: table adopts production defaults (RETAIN, deletion protection on)', () => {
|
|
74
|
+
const { stack, parent } = setup(BlocksPresets.production);
|
|
75
|
+
new DistributedTable(parent, 'users', {
|
|
76
|
+
schema: userSchema,
|
|
77
|
+
key: { partitionKey: 'userId', sortKey: 'createdAt' },
|
|
78
|
+
});
|
|
79
|
+
const template = Template.fromStack(stack);
|
|
80
|
+
template.hasResource('AWS::DynamoDB::Table', { DeletionPolicy: 'Retain' });
|
|
81
|
+
template.hasResourceProperties('AWS::DynamoDB::Table', { DeletionProtectionEnabled: true });
|
|
82
|
+
});
|
|
83
|
+
|
|
60
84
|
test('CDK: DistributedTable.fromExisting does NOT provision a table (regression)', () => {
|
|
61
85
|
const { stack, parent } = setup();
|
|
62
86
|
new DistributedTable(parent, 'users', {
|
package/src/index.cdk.ts
CHANGED
|
@@ -83,6 +83,11 @@ export class DistributedTable<T = any> extends Scope {
|
|
|
83
83
|
} : undefined,
|
|
84
84
|
billingMode: BillingMode.PAY_PER_REQUEST,
|
|
85
85
|
timeToLiveAttribute: config.ttl || undefined,
|
|
86
|
+
// Durability follows the stack-wide `defaults` (sandbox → DESTROY +
|
|
87
|
+
// no protection so a teardown is clean; production → RETAIN + protected).
|
|
88
|
+
// A richer per-block override lands with the `protection` option in #282.
|
|
89
|
+
removalPolicy: this.defaults.removalPolicy,
|
|
90
|
+
deletionProtection: this.defaults.deletionProtection,
|
|
86
91
|
});
|
|
87
92
|
|
|
88
93
|
this.table.grantReadWriteData(this.handler);
|
package/src/version.ts
CHANGED