@jaypie/constructs 1.2.42 → 1.2.43
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/cjs/JaypieDynamoDb.d.ts +11 -16
- package/dist/cjs/index.cjs +26 -31
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/JaypieDynamoDb.d.ts +11 -16
- package/dist/esm/index.js +27 -32
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -6,25 +6,23 @@ export interface JaypieDynamoDbProps extends Omit<dynamodb.TablePropsV2, "global
|
|
|
6
6
|
/**
|
|
7
7
|
* Configure GSIs for the table using @jaypie/fabric IndexDefinition format.
|
|
8
8
|
* - `undefined`: No GSIs (default)
|
|
9
|
-
* - Array of IndexDefinition: Use the specified indexes
|
|
9
|
+
* - Array of IndexDefinition: Use the specified indexes (prefer fabricIndex())
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* // No GSIs (default)
|
|
13
13
|
* new JaypieDynamoDb(this, "myTable");
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
|
-
* // With
|
|
16
|
+
* // With fabricIndex-shaped indexes
|
|
17
|
+
* import { fabricIndex } from "@jaypie/fabric";
|
|
17
18
|
* new JaypieDynamoDb(this, "myTable", {
|
|
18
|
-
* indexes: [
|
|
19
|
-
* { pk: ["scope", "model"], sk: ["sequence"] },
|
|
20
|
-
* { pk: ["scope", "model", "type"], sk: ["sequence"], sparse: true },
|
|
21
|
-
* ],
|
|
19
|
+
* indexes: [fabricIndex(), fabricIndex("alias"), fabricIndex("xid")],
|
|
22
20
|
* });
|
|
23
21
|
*/
|
|
24
22
|
indexes?: IndexDefinition[];
|
|
25
23
|
/**
|
|
26
24
|
* Partition key attribute definition.
|
|
27
|
-
* @default { name: "
|
|
25
|
+
* @default { name: "id", type: AttributeType.STRING }
|
|
28
26
|
*/
|
|
29
27
|
partitionKey?: dynamodb.Attribute;
|
|
30
28
|
/**
|
|
@@ -40,8 +38,8 @@ export interface JaypieDynamoDbProps extends Omit<dynamodb.TablePropsV2, "global
|
|
|
40
38
|
*/
|
|
41
39
|
service?: string;
|
|
42
40
|
/**
|
|
43
|
-
* Sort key attribute definition.
|
|
44
|
-
*
|
|
41
|
+
* Sort key attribute definition. Defaults to `undefined` (no sort key) —
|
|
42
|
+
* the Jaypie single-table pattern uses `id` as a unique partition key.
|
|
45
43
|
*/
|
|
46
44
|
sortKey?: dynamodb.Attribute;
|
|
47
45
|
/**
|
|
@@ -53,8 +51,7 @@ export interface JaypieDynamoDbProps extends Omit<dynamodb.TablePropsV2, "global
|
|
|
53
51
|
* DynamoDB table with Jaypie single-table design patterns.
|
|
54
52
|
*
|
|
55
53
|
* Creates a table with:
|
|
56
|
-
* - Partition key: `
|
|
57
|
-
* - Sort key: `id` (String)
|
|
54
|
+
* - Partition key: `id` (String), no sort key
|
|
58
55
|
* - Billing: PAY_PER_REQUEST (on-demand)
|
|
59
56
|
* - Removal policy: RETAIN in production, DESTROY otherwise
|
|
60
57
|
* - No GSIs by default (use `indexes` prop to add them)
|
|
@@ -65,13 +62,11 @@ export interface JaypieDynamoDbProps extends Omit<dynamodb.TablePropsV2, "global
|
|
|
65
62
|
* const table = new JaypieDynamoDb(this, "myApp");
|
|
66
63
|
*
|
|
67
64
|
* @example
|
|
68
|
-
* // With
|
|
65
|
+
* // With fabricIndex() for GSIs
|
|
66
|
+
* import { fabricIndex } from "@jaypie/fabric";
|
|
69
67
|
* const table = new JaypieDynamoDb(this, "MyTable", {
|
|
70
68
|
* tableName: "custom-table-name",
|
|
71
|
-
* indexes: [
|
|
72
|
-
* { pk: ["scope", "model"] },
|
|
73
|
-
* { pk: ["scope", "model", "type"], sparse: true },
|
|
74
|
-
* ],
|
|
69
|
+
* indexes: [fabricIndex(), fabricIndex("alias"), fabricIndex("xid")],
|
|
75
70
|
* });
|
|
76
71
|
*/
|
|
77
72
|
export declare class JaypieDynamoDb extends Construct implements dynamodb.ITableV2 {
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -2931,41 +2931,39 @@ class JaypieDnsRecord extends constructs.Construct {
|
|
|
2931
2931
|
}
|
|
2932
2932
|
}
|
|
2933
2933
|
|
|
2934
|
-
//
|
|
2935
|
-
//
|
|
2936
|
-
// Constants
|
|
2937
|
-
//
|
|
2938
|
-
/** Composite key separator used in GSI partition keys */
|
|
2939
|
-
const SEPARATOR = "#";
|
|
2940
2934
|
//
|
|
2941
2935
|
//
|
|
2942
2936
|
// Helper Functions
|
|
2943
2937
|
//
|
|
2944
2938
|
/**
|
|
2945
|
-
* Convert IndexDefinition[] from @jaypie/fabric to CDK GlobalSecondaryIndexPropsV2[]
|
|
2939
|
+
* Convert IndexDefinition[] from @jaypie/fabric to CDK GlobalSecondaryIndexPropsV2[].
|
|
2946
2940
|
*
|
|
2947
|
-
*
|
|
2948
|
-
*
|
|
2941
|
+
* Uses `getGsiAttributeNames` as the single source of truth so runtime writes
|
|
2942
|
+
* and CDK provisioning agree on attribute names. Composite sk indexes
|
|
2943
|
+
* (sk.length > 1) get a dedicated STRING `{indexName}Sk` attribute; single-field
|
|
2944
|
+
* sk indexes reference the field directly (STRING in the general case, NUMBER
|
|
2945
|
+
* for the legacy `sequence` name).
|
|
2949
2946
|
*/
|
|
2950
2947
|
function indexesToGsi(indexes) {
|
|
2951
2948
|
return indexes.map((index) => {
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2949
|
+
const { pk, sk } = fabric.getGsiAttributeNames(index);
|
|
2950
|
+
let sortKey;
|
|
2951
|
+
if (sk) {
|
|
2952
|
+
if (sk === "sequence") {
|
|
2953
|
+
sortKey = { name: "sequence", type: dynamodb__namespace.AttributeType.NUMBER };
|
|
2954
|
+
}
|
|
2955
|
+
else {
|
|
2956
|
+
sortKey = { name: sk, type: dynamodb__namespace.AttributeType.STRING };
|
|
2957
|
+
}
|
|
2958
|
+
}
|
|
2956
2959
|
return {
|
|
2957
|
-
indexName,
|
|
2960
|
+
indexName: pk,
|
|
2958
2961
|
partitionKey: {
|
|
2959
|
-
name:
|
|
2962
|
+
name: pk,
|
|
2960
2963
|
type: dynamodb__namespace.AttributeType.STRING,
|
|
2961
2964
|
},
|
|
2962
2965
|
projectionType: dynamodb__namespace.ProjectionType.ALL,
|
|
2963
|
-
sortKey
|
|
2964
|
-
? { name: "sequence", type: dynamodb__namespace.AttributeType.NUMBER }
|
|
2965
|
-
: {
|
|
2966
|
-
name: skFields.join(SEPARATOR),
|
|
2967
|
-
type: dynamodb__namespace.AttributeType.STRING,
|
|
2968
|
-
},
|
|
2966
|
+
...(sortKey && { sortKey }),
|
|
2969
2967
|
};
|
|
2970
2968
|
});
|
|
2971
2969
|
}
|
|
@@ -2977,8 +2975,7 @@ function indexesToGsi(indexes) {
|
|
|
2977
2975
|
* DynamoDB table with Jaypie single-table design patterns.
|
|
2978
2976
|
*
|
|
2979
2977
|
* Creates a table with:
|
|
2980
|
-
* - Partition key: `
|
|
2981
|
-
* - Sort key: `id` (String)
|
|
2978
|
+
* - Partition key: `id` (String), no sort key
|
|
2982
2979
|
* - Billing: PAY_PER_REQUEST (on-demand)
|
|
2983
2980
|
* - Removal policy: RETAIN in production, DESTROY otherwise
|
|
2984
2981
|
* - No GSIs by default (use `indexes` prop to add them)
|
|
@@ -2989,13 +2986,11 @@ function indexesToGsi(indexes) {
|
|
|
2989
2986
|
* const table = new JaypieDynamoDb(this, "myApp");
|
|
2990
2987
|
*
|
|
2991
2988
|
* @example
|
|
2992
|
-
* // With
|
|
2989
|
+
* // With fabricIndex() for GSIs
|
|
2990
|
+
* import { fabricIndex } from "@jaypie/fabric";
|
|
2993
2991
|
* const table = new JaypieDynamoDb(this, "MyTable", {
|
|
2994
2992
|
* tableName: "custom-table-name",
|
|
2995
|
-
* indexes: [
|
|
2996
|
-
* { pk: ["scope", "model"] },
|
|
2997
|
-
* { pk: ["scope", "model", "type"], sparse: true },
|
|
2998
|
-
* ],
|
|
2993
|
+
* indexes: [fabricIndex(), fabricIndex("alias"), fabricIndex("xid")],
|
|
2999
2994
|
* });
|
|
3000
2995
|
*/
|
|
3001
2996
|
class JaypieDynamoDb extends constructs.Construct {
|
|
@@ -3007,11 +3002,11 @@ class JaypieDynamoDb extends constructs.Construct {
|
|
|
3007
3002
|
const constructId = isShorthand ? `JaypieDynamoDb-${id}` : id;
|
|
3008
3003
|
super(scope, constructId);
|
|
3009
3004
|
const { billing = dynamodb__namespace.Billing.onDemand(), indexes, partitionKey = {
|
|
3010
|
-
name: "
|
|
3005
|
+
name: "id",
|
|
3011
3006
|
type: dynamodb__namespace.AttributeType.STRING,
|
|
3012
3007
|
}, project, removalPolicy = isProductionEnv()
|
|
3013
3008
|
? cdk.RemovalPolicy.RETAIN
|
|
3014
|
-
: cdk.RemovalPolicy.DESTROY, roleTag = CDK$2.ROLE.STORAGE, service, sortKey
|
|
3009
|
+
: cdk.RemovalPolicy.DESTROY, roleTag = CDK$2.ROLE.STORAGE, service, sortKey, vendorTag, ...restProps } = props;
|
|
3015
3010
|
// Convert IndexDefinition[] to CDK GSI props
|
|
3016
3011
|
const globalSecondaryIndexes = indexes ? indexesToGsi(indexes) : undefined;
|
|
3017
3012
|
this._table = new dynamodb__namespace.TableV2(this, "Table", {
|
|
@@ -3019,7 +3014,7 @@ class JaypieDynamoDb extends constructs.Construct {
|
|
|
3019
3014
|
globalSecondaryIndexes,
|
|
3020
3015
|
partitionKey,
|
|
3021
3016
|
removalPolicy,
|
|
3022
|
-
sortKey,
|
|
3017
|
+
...(sortKey && { sortKey }),
|
|
3023
3018
|
...restProps,
|
|
3024
3019
|
});
|
|
3025
3020
|
// Apply tags
|