@jaypie/constructs 1.2.43 → 1.2.44

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.
@@ -1,22 +1,24 @@
1
1
  import { Construct } from "constructs";
2
2
  import { RemovalPolicy } from "aws-cdk-lib";
3
3
  import * as dynamodb from "aws-cdk-lib/aws-dynamodb";
4
- import { type IndexDefinition } from "@jaypie/fabric";
4
+ import type { IndexDefinition } from "./types/IndexDefinition";
5
5
  export interface JaypieDynamoDbProps extends Omit<dynamodb.TablePropsV2, "globalSecondaryIndexes" | "partitionKey" | "sortKey"> {
6
6
  /**
7
- * Configure GSIs for the table using @jaypie/fabric IndexDefinition format.
7
+ * Configure GSIs for the table using the IndexDefinition format.
8
8
  * - `undefined`: No GSIs (default)
9
- * - Array of IndexDefinition: Use the specified indexes (prefer fabricIndex())
9
+ * - Array of IndexDefinition: Use the specified indexes
10
10
  *
11
11
  * @example
12
12
  * // No GSIs (default)
13
13
  * new JaypieDynamoDb(this, "myTable");
14
14
  *
15
15
  * @example
16
- * // With fabricIndex-shaped indexes
17
- * import { fabricIndex } from "@jaypie/fabric";
16
+ * // Inline indexes
18
17
  * new JaypieDynamoDb(this, "myTable", {
19
- * indexes: [fabricIndex(), fabricIndex("alias"), fabricIndex("xid")],
18
+ * indexes: [
19
+ * { name: "indexModel", pk: ["model"], sk: ["scope", "updatedAt"] },
20
+ * { name: "indexModelAlias", pk: ["model", "alias"], sk: ["scope", "updatedAt"], sparse: true },
21
+ * ],
20
22
  * });
21
23
  */
22
24
  indexes?: IndexDefinition[];
@@ -62,11 +64,13 @@ export interface JaypieDynamoDbProps extends Omit<dynamodb.TablePropsV2, "global
62
64
  * const table = new JaypieDynamoDb(this, "myApp");
63
65
  *
64
66
  * @example
65
- * // With fabricIndex() for GSIs
66
- * import { fabricIndex } from "@jaypie/fabric";
67
+ * // With inline IndexDefinition for GSIs
67
68
  * const table = new JaypieDynamoDb(this, "MyTable", {
68
69
  * tableName: "custom-table-name",
69
- * indexes: [fabricIndex(), fabricIndex("alias"), fabricIndex("xid")],
70
+ * indexes: [
71
+ * { name: "indexModel", pk: ["model"], sk: ["scope", "updatedAt"] },
72
+ * { name: "indexModelAlias", pk: ["model", "alias"], sk: ["scope", "updatedAt"], sparse: true },
73
+ * ],
70
74
  * });
71
75
  */
72
76
  export declare class JaypieDynamoDb extends Construct implements dynamodb.ITableV2 {
@@ -23,7 +23,6 @@ var cloudfront = require('aws-cdk-lib/aws-cloudfront');
23
23
  var origins = require('aws-cdk-lib/aws-cloudfront-origins');
24
24
  var wafv2 = require('aws-cdk-lib/aws-wafv2');
25
25
  var dynamodb = require('aws-cdk-lib/aws-dynamodb');
26
- var fabric = require('@jaypie/fabric');
27
26
  var cr = require('aws-cdk-lib/custom-resources');
28
27
  var cdkNextjsStandalone = require('cdk-nextjs-standalone');
29
28
  var path = require('path');
@@ -2936,17 +2935,43 @@ class JaypieDnsRecord extends constructs.Construct {
2936
2935
  // Helper Functions
2937
2936
  //
2938
2937
  /**
2939
- * Convert IndexDefinition[] from @jaypie/fabric to CDK GlobalSecondaryIndexPropsV2[].
2938
+ * Derive GSI attribute names for an index definition.
2940
2939
  *
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).
2940
+ * Mirrors `@jaypie/fabric`'s `getGsiAttributeNames` so CDK provisioning and
2941
+ * any runtime write path agree on the attribute names. Kept local to avoid
2942
+ * a runtime dependency on the pre-1.0 `@jaypie/fabric` package.
2943
+ *
2944
+ * - `pk` is always the index name (`index.name` or generated from `index.pk`)
2945
+ * - `sk` is the single sk field name when `sk.length === 1`, or
2946
+ * `{indexName}Sk` when `sk.length > 1` (composite sk attribute)
2947
+ */
2948
+ function getGsiAttributeNames(index) {
2949
+ const name = index.name ?? generateIndexName(index.pk);
2950
+ let sk;
2951
+ if (index.sk && index.sk.length > 1) {
2952
+ sk = `${name}Sk`;
2953
+ }
2954
+ else if (index.sk && index.sk.length === 1) {
2955
+ sk = index.sk[0];
2956
+ }
2957
+ return { pk: name, sk };
2958
+ }
2959
+ function generateIndexName(pk) {
2960
+ const suffix = pk
2961
+ .map((field) => field.charAt(0).toUpperCase() + field.slice(1))
2962
+ .join("");
2963
+ return `index${suffix}`;
2964
+ }
2965
+ /**
2966
+ * Convert IndexDefinition[] to CDK GlobalSecondaryIndexPropsV2[].
2967
+ *
2968
+ * Composite sk indexes (sk.length > 1) get a dedicated STRING `{indexName}Sk`
2969
+ * attribute; single-field sk indexes reference the field directly (STRING in
2970
+ * the general case, NUMBER for the legacy `sequence` name).
2946
2971
  */
2947
2972
  function indexesToGsi(indexes) {
2948
2973
  return indexes.map((index) => {
2949
- const { pk, sk } = fabric.getGsiAttributeNames(index);
2974
+ const { pk, sk } = getGsiAttributeNames(index);
2950
2975
  let sortKey;
2951
2976
  if (sk) {
2952
2977
  if (sk === "sequence") {
@@ -2986,11 +3011,13 @@ function indexesToGsi(indexes) {
2986
3011
  * const table = new JaypieDynamoDb(this, "myApp");
2987
3012
  *
2988
3013
  * @example
2989
- * // With fabricIndex() for GSIs
2990
- * import { fabricIndex } from "@jaypie/fabric";
3014
+ * // With inline IndexDefinition for GSIs
2991
3015
  * const table = new JaypieDynamoDb(this, "MyTable", {
2992
3016
  * tableName: "custom-table-name",
2993
- * indexes: [fabricIndex(), fabricIndex("alias"), fabricIndex("xid")],
3017
+ * indexes: [
3018
+ * { name: "indexModel", pk: ["model"], sk: ["scope", "updatedAt"] },
3019
+ * { name: "indexModelAlias", pk: ["model", "alias"], sk: ["scope", "updatedAt"], sparse: true },
3020
+ * ],
2994
3021
  * });
2995
3022
  */
2996
3023
  class JaypieDynamoDb extends constructs.Construct {