@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.
@@ -10,7 +10,7 @@ export { JaypieDatadogSecret } from "./JaypieDatadogSecret";
10
10
  export { JaypieDistribution, JaypieDistributionProps, JaypieWafConfig, SecurityHeadersOverrides, } from "./JaypieDistribution";
11
11
  export { JaypieDnsRecord, JaypieDnsRecordProps } from "./JaypieDnsRecord";
12
12
  export { JaypieDynamoDb, JaypieDynamoDbProps } from "./JaypieDynamoDb";
13
- export type { IndexDefinition } from "@jaypie/fabric";
13
+ export type { IndexDefinition } from "./types/IndexDefinition";
14
14
  export { JaypieEnvSecret } from "./JaypieEnvSecret";
15
15
  export { JaypieEventsRule, JaypieEventsRuleProps } from "./JaypieEventsRule";
16
16
  export { JaypieExpressLambda } from "./JaypieExpressLambda";
@@ -0,0 +1,22 @@
1
+ /**
2
+ * GSI index definition for JaypieDynamoDb.
3
+ *
4
+ * Shape mirrors `@jaypie/fabric`'s IndexDefinition so a single object can be
5
+ * shared between CDK provisioning (here) and runtime model code (fabric).
6
+ * The type is owned locally so `@jaypie/constructs` does not take a runtime
7
+ * dependency on the pre-1.0 `@jaypie/fabric` package.
8
+ *
9
+ * - `pk` fields are combined with a separator to form the partition key attribute
10
+ * - `sk` with one field uses that field directly as the GSI sort key
11
+ * - `sk` with multiple fields produces a composite `{indexName}Sk` attribute
12
+ */
13
+ export interface IndexDefinition {
14
+ /** Name of the index (auto-generated from pk fields if not provided) */
15
+ name?: string;
16
+ /** Partition key fields - combined with separator */
17
+ pk: string[];
18
+ /** Sort key fields - combined with separator when composite */
19
+ sk?: string[];
20
+ /** Advisory: index key is only written when all pk/sk fields are present */
21
+ sparse?: boolean;
22
+ }
@@ -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 {
@@ -10,7 +10,7 @@ export { JaypieDatadogSecret } from "./JaypieDatadogSecret";
10
10
  export { JaypieDistribution, JaypieDistributionProps, JaypieWafConfig, SecurityHeadersOverrides, } from "./JaypieDistribution";
11
11
  export { JaypieDnsRecord, JaypieDnsRecordProps } from "./JaypieDnsRecord";
12
12
  export { JaypieDynamoDb, JaypieDynamoDbProps } from "./JaypieDynamoDb";
13
- export type { IndexDefinition } from "@jaypie/fabric";
13
+ export type { IndexDefinition } from "./types/IndexDefinition";
14
14
  export { JaypieEnvSecret } from "./JaypieEnvSecret";
15
15
  export { JaypieEventsRule, JaypieEventsRuleProps } from "./JaypieEventsRule";
16
16
  export { JaypieExpressLambda } from "./JaypieExpressLambda";
package/dist/esm/index.js CHANGED
@@ -26,7 +26,6 @@ import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
26
26
  import * as origins from 'aws-cdk-lib/aws-cloudfront-origins';
27
27
  import * as wafv2 from 'aws-cdk-lib/aws-wafv2';
28
28
  import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
29
- import { getGsiAttributeNames } from '@jaypie/fabric';
30
29
  import * as cr from 'aws-cdk-lib/custom-resources';
31
30
  import { Nextjs } from 'cdk-nextjs-standalone';
32
31
  import * as path from 'path';
@@ -2900,13 +2899,39 @@ class JaypieDnsRecord extends Construct {
2900
2899
  // Helper Functions
2901
2900
  //
2902
2901
  /**
2903
- * Convert IndexDefinition[] from @jaypie/fabric to CDK GlobalSecondaryIndexPropsV2[].
2902
+ * Derive GSI attribute names for an index definition.
2904
2903
  *
2905
- * Uses `getGsiAttributeNames` as the single source of truth so runtime writes
2906
- * and CDK provisioning agree on attribute names. Composite sk indexes
2907
- * (sk.length > 1) get a dedicated STRING `{indexName}Sk` attribute; single-field
2908
- * sk indexes reference the field directly (STRING in the general case, NUMBER
2909
- * for the legacy `sequence` name).
2904
+ * Mirrors `@jaypie/fabric`'s `getGsiAttributeNames` so CDK provisioning and
2905
+ * any runtime write path agree on the attribute names. Kept local to avoid
2906
+ * a runtime dependency on the pre-1.0 `@jaypie/fabric` package.
2907
+ *
2908
+ * - `pk` is always the index name (`index.name` or generated from `index.pk`)
2909
+ * - `sk` is the single sk field name when `sk.length === 1`, or
2910
+ * `{indexName}Sk` when `sk.length > 1` (composite sk attribute)
2911
+ */
2912
+ function getGsiAttributeNames(index) {
2913
+ const name = index.name ?? generateIndexName(index.pk);
2914
+ let sk;
2915
+ if (index.sk && index.sk.length > 1) {
2916
+ sk = `${name}Sk`;
2917
+ }
2918
+ else if (index.sk && index.sk.length === 1) {
2919
+ sk = index.sk[0];
2920
+ }
2921
+ return { pk: name, sk };
2922
+ }
2923
+ function generateIndexName(pk) {
2924
+ const suffix = pk
2925
+ .map((field) => field.charAt(0).toUpperCase() + field.slice(1))
2926
+ .join("");
2927
+ return `index${suffix}`;
2928
+ }
2929
+ /**
2930
+ * Convert IndexDefinition[] to CDK GlobalSecondaryIndexPropsV2[].
2931
+ *
2932
+ * Composite sk indexes (sk.length > 1) get a dedicated STRING `{indexName}Sk`
2933
+ * attribute; single-field sk indexes reference the field directly (STRING in
2934
+ * the general case, NUMBER for the legacy `sequence` name).
2910
2935
  */
2911
2936
  function indexesToGsi(indexes) {
2912
2937
  return indexes.map((index) => {
@@ -2950,11 +2975,13 @@ function indexesToGsi(indexes) {
2950
2975
  * const table = new JaypieDynamoDb(this, "myApp");
2951
2976
  *
2952
2977
  * @example
2953
- * // With fabricIndex() for GSIs
2954
- * import { fabricIndex } from "@jaypie/fabric";
2978
+ * // With inline IndexDefinition for GSIs
2955
2979
  * const table = new JaypieDynamoDb(this, "MyTable", {
2956
2980
  * tableName: "custom-table-name",
2957
- * indexes: [fabricIndex(), fabricIndex("alias"), fabricIndex("xid")],
2981
+ * indexes: [
2982
+ * { name: "indexModel", pk: ["model"], sk: ["scope", "updatedAt"] },
2983
+ * { name: "indexModelAlias", pk: ["model", "alias"], sk: ["scope", "updatedAt"], sparse: true },
2984
+ * ],
2958
2985
  * });
2959
2986
  */
2960
2987
  class JaypieDynamoDb extends Construct {