dyno-table 0.2.0-0 → 1.0.0-alpha.1

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.
Files changed (96) hide show
  1. package/README.md +182 -577
  2. package/dist/{table.cjs → index.cjs} +175 -87
  3. package/dist/index.d.cts +2971 -0
  4. package/dist/index.d.ts +2971 -0
  5. package/dist/{table.js → index.js} +127 -86
  6. package/package.json +10 -77
  7. package/dist/builder-types-C_PDZhnP.d.ts +0 -118
  8. package/dist/builder-types-DtwbqMeF.d.cts +0 -118
  9. package/dist/builders/condition-check-builder.cjs +0 -394
  10. package/dist/builders/condition-check-builder.cjs.map +0 -1
  11. package/dist/builders/condition-check-builder.d.cts +0 -157
  12. package/dist/builders/condition-check-builder.d.ts +0 -157
  13. package/dist/builders/condition-check-builder.js +0 -392
  14. package/dist/builders/condition-check-builder.js.map +0 -1
  15. package/dist/builders/delete-builder.cjs +0 -405
  16. package/dist/builders/delete-builder.cjs.map +0 -1
  17. package/dist/builders/delete-builder.d.cts +0 -166
  18. package/dist/builders/delete-builder.d.ts +0 -166
  19. package/dist/builders/delete-builder.js +0 -403
  20. package/dist/builders/delete-builder.js.map +0 -1
  21. package/dist/builders/paginator.cjs +0 -199
  22. package/dist/builders/paginator.cjs.map +0 -1
  23. package/dist/builders/paginator.d.cts +0 -179
  24. package/dist/builders/paginator.d.ts +0 -179
  25. package/dist/builders/paginator.js +0 -197
  26. package/dist/builders/paginator.js.map +0 -1
  27. package/dist/builders/put-builder.cjs +0 -476
  28. package/dist/builders/put-builder.cjs.map +0 -1
  29. package/dist/builders/put-builder.d.cts +0 -274
  30. package/dist/builders/put-builder.d.ts +0 -274
  31. package/dist/builders/put-builder.js +0 -474
  32. package/dist/builders/put-builder.js.map +0 -1
  33. package/dist/builders/query-builder.cjs +0 -674
  34. package/dist/builders/query-builder.cjs.map +0 -1
  35. package/dist/builders/query-builder.d.cts +0 -6
  36. package/dist/builders/query-builder.d.ts +0 -6
  37. package/dist/builders/query-builder.js +0 -672
  38. package/dist/builders/query-builder.js.map +0 -1
  39. package/dist/builders/transaction-builder.cjs +0 -894
  40. package/dist/builders/transaction-builder.cjs.map +0 -1
  41. package/dist/builders/transaction-builder.d.cts +0 -511
  42. package/dist/builders/transaction-builder.d.ts +0 -511
  43. package/dist/builders/transaction-builder.js +0 -892
  44. package/dist/builders/transaction-builder.js.map +0 -1
  45. package/dist/builders/update-builder.cjs +0 -627
  46. package/dist/builders/update-builder.cjs.map +0 -1
  47. package/dist/builders/update-builder.d.cts +0 -365
  48. package/dist/builders/update-builder.d.ts +0 -365
  49. package/dist/builders/update-builder.js +0 -625
  50. package/dist/builders/update-builder.js.map +0 -1
  51. package/dist/conditions--ld9a78i.d.ts +0 -331
  52. package/dist/conditions-ChhQWd6z.d.cts +0 -331
  53. package/dist/conditions.cjs +0 -59
  54. package/dist/conditions.cjs.map +0 -1
  55. package/dist/conditions.d.cts +0 -3
  56. package/dist/conditions.d.ts +0 -3
  57. package/dist/conditions.js +0 -43
  58. package/dist/conditions.js.map +0 -1
  59. package/dist/entity.cjs +0 -228
  60. package/dist/entity.cjs.map +0 -1
  61. package/dist/entity.d.cts +0 -149
  62. package/dist/entity.d.ts +0 -149
  63. package/dist/entity.js +0 -224
  64. package/dist/entity.js.map +0 -1
  65. package/dist/query-builder-Csror9Iu.d.ts +0 -507
  66. package/dist/query-builder-D2FM9rsu.d.cts +0 -507
  67. package/dist/standard-schema.cjs +0 -4
  68. package/dist/standard-schema.cjs.map +0 -1
  69. package/dist/standard-schema.d.cts +0 -57
  70. package/dist/standard-schema.d.ts +0 -57
  71. package/dist/standard-schema.js +0 -3
  72. package/dist/standard-schema.js.map +0 -1
  73. package/dist/table-BEhBPy2G.d.cts +0 -364
  74. package/dist/table-BW3cmUqr.d.ts +0 -364
  75. package/dist/table.cjs.map +0 -1
  76. package/dist/table.d.cts +0 -12
  77. package/dist/table.d.ts +0 -12
  78. package/dist/table.js.map +0 -1
  79. package/dist/types.cjs +0 -4
  80. package/dist/types.cjs.map +0 -1
  81. package/dist/types.d.cts +0 -22
  82. package/dist/types.d.ts +0 -22
  83. package/dist/types.js +0 -3
  84. package/dist/types.js.map +0 -1
  85. package/dist/utils/partition-key-template.cjs +0 -19
  86. package/dist/utils/partition-key-template.cjs.map +0 -1
  87. package/dist/utils/partition-key-template.d.cts +0 -32
  88. package/dist/utils/partition-key-template.d.ts +0 -32
  89. package/dist/utils/partition-key-template.js +0 -17
  90. package/dist/utils/partition-key-template.js.map +0 -1
  91. package/dist/utils/sort-key-template.cjs +0 -19
  92. package/dist/utils/sort-key-template.cjs.map +0 -1
  93. package/dist/utils/sort-key-template.d.cts +0 -35
  94. package/dist/utils/sort-key-template.d.ts +0 -35
  95. package/dist/utils/sort-key-template.js +0 -17
  96. package/dist/utils/sort-key-template.js.map +0 -1
@@ -1,157 +0,0 @@
1
- import { P as PrimaryKeyWithoutExpression, C as Condition, b as ConditionOperator } from '../conditions-ChhQWd6z.cjs';
2
- import { TransactionBuilder } from './transaction-builder.cjs';
3
- import { DynamoItem } from '../types.cjs';
4
- import '@aws-sdk/lib-dynamodb';
5
- import '../builder-types-DtwbqMeF.cjs';
6
-
7
- /**
8
- * Builder for creating DynamoDB condition check operations.
9
- * Use this builder when you need to:
10
- * - Verify item state without modifying it
11
- * - Ensure preconditions in transactions
12
- * - Implement optimistic locking patterns
13
- * - Validate business rules
14
- *
15
- * @example
16
- * ```typescript
17
- * // Check if dinosaur is ready for feeding
18
- * const check = new ConditionCheckBuilder('dinosaurs', { id: 'TREX-001' })
19
- * .condition(op =>
20
- * op.and([
21
- * op.eq('status', 'HUNTING'),
22
- * op.gt('stats.hunger', 80),
23
- * op.lt('stats.health', 100)
24
- * ])
25
- * )
26
- * .toDynamoCommand();
27
- *
28
- * // Check habitat security status
29
- * const securityCheck = new ConditionCheckBuilder('habitats', { id: 'PADDOCK-A' })
30
- * .condition(op =>
31
- * op.and([
32
- * op.eq('securityStatus', 'ACTIVE'),
33
- * op.attributeExists('lastInspection'),
34
- * op.lt('threatLevel', 5)
35
- * ])
36
- * )
37
- * .toDynamoCommand();
38
- * ```
39
- */
40
- declare class ConditionCheckBuilder {
41
- private readonly key;
42
- private readonly tableName;
43
- private conditionExpression?;
44
- constructor(tableName: string, key: PrimaryKeyWithoutExpression);
45
- /**
46
- * Adds a condition that must be satisfied for the check to succeed.
47
- * Use this method when you need to:
48
- * - Validate complex item states
49
- * - Check multiple attributes together
50
- * - Ensure safety conditions are met
51
- *
52
- * @example
53
- * ```typescript
54
- * // Check dinosaur health and behavior
55
- * builder.condition(op =>
56
- * op.and([
57
- * op.gt('stats.health', 50),
58
- * op.not(op.eq('status', 'SEDATED')),
59
- * op.lt('aggressionLevel', 8)
60
- * ])
61
- * );
62
- *
63
- * // Verify habitat conditions
64
- * builder.condition(op =>
65
- * op.and([
66
- * op.eq('powerStatus', 'ONLINE'),
67
- * op.between('temperature', 20, 30),
68
- * op.attributeExists('lastMaintenance')
69
- * ])
70
- * );
71
- *
72
- * // Check breeding conditions
73
- * builder.condition(op =>
74
- * op.and([
75
- * op.eq('species', 'VELOCIRAPTOR'),
76
- * op.gte('age', 3),
77
- * op.eq('geneticPurity', 100)
78
- * ])
79
- * );
80
- * ```
81
- *
82
- * @param condition - Either a Condition DynamoItem or a callback function that builds the condition
83
- * @returns The builder instance for method chaining
84
- */
85
- condition<T extends DynamoItem>(condition: Condition | ((op: ConditionOperator<T>) => Condition)): this;
86
- /**
87
- * Generates the DynamoDB command parameters for direct execution.
88
- * Use this method when you want to:
89
- * - Execute the condition check as a standalone operation
90
- * - Get the raw DynamoDB command for custom execution
91
- * - Inspect the generated command parameters
92
- *
93
- * @example
94
- * ```ts
95
- * const command = new ConditionCheckBuilder('myTable', { id: '123' })
96
- * .condition(op => op.attributeExists('status'))
97
- * .toDynamoCommand();
98
- * // Use command with DynamoDB client
99
- * ```
100
- *
101
- * @throws {Error} If no condition has been set
102
- * @returns The DynamoDB command parameters
103
- */
104
- private toDynamoCommand;
105
- /**
106
- * Adds this condition check operation to a transaction.
107
- * Use this method when you need to:
108
- * - Verify habitat safety before transfers
109
- * - Ensure proper feeding conditions
110
- * - Validate security protocols
111
- *
112
- * @example
113
- * ```ts
114
- * const transaction = new TransactionBuilder();
115
- * new ConditionCheckBuilder('habitats', { id: 'PADDOCK-B' })
116
- * .condition(op => op.and([
117
- * op.eq('securityStatus', 'ACTIVE'),
118
- * op.lt('currentOccupants', 3),
119
- * op.eq('habitatType', 'CARNIVORE')
120
- * ]))
121
- * .withTransaction(transaction);
122
- * // Add dinosaur transfer operations
123
- * ```
124
- *
125
- * @param transaction - The transaction builder to add this operation to
126
- * @throws {Error} If no condition has been set
127
- * @returns The builder instance for method chaining
128
- */
129
- withTransaction(transaction: TransactionBuilder): this;
130
- /**
131
- * Gets a human-readable representation of the condition check command
132
- * with all expression placeholders replaced by their actual values.
133
- * Use this method when you need to:
134
- * - Debug complex condition expressions
135
- * - Verify condition parameters
136
- * - Log safety checks
137
- * - Troubleshoot condition failures
138
- *
139
- * @example
140
- * ```ts
141
- * const debugInfo = new ConditionCheckBuilder('dinosaurs', { id: 'TREX-001' })
142
- * .condition(op => op.and([
143
- * op.between('stats.health', 50, 100),
144
- * op.not(op.eq('status', 'SEDATED')),
145
- * op.attributeExists('lastFeedingTime')
146
- * op.eq('version', 1)
147
- * ]))
148
- * .debug();
149
- * console.log(debugInfo);
150
- * ```
151
- *
152
- * @returns A readable representation of the condition check command with resolved expressions
153
- */
154
- debug(): DynamoItem;
155
- }
156
-
157
- export { ConditionCheckBuilder };
@@ -1,157 +0,0 @@
1
- import { P as PrimaryKeyWithoutExpression, C as Condition, b as ConditionOperator } from '../conditions--ld9a78i.js';
2
- import { TransactionBuilder } from './transaction-builder.js';
3
- import { DynamoItem } from '../types.js';
4
- import '@aws-sdk/lib-dynamodb';
5
- import '../builder-types-C_PDZhnP.js';
6
-
7
- /**
8
- * Builder for creating DynamoDB condition check operations.
9
- * Use this builder when you need to:
10
- * - Verify item state without modifying it
11
- * - Ensure preconditions in transactions
12
- * - Implement optimistic locking patterns
13
- * - Validate business rules
14
- *
15
- * @example
16
- * ```typescript
17
- * // Check if dinosaur is ready for feeding
18
- * const check = new ConditionCheckBuilder('dinosaurs', { id: 'TREX-001' })
19
- * .condition(op =>
20
- * op.and([
21
- * op.eq('status', 'HUNTING'),
22
- * op.gt('stats.hunger', 80),
23
- * op.lt('stats.health', 100)
24
- * ])
25
- * )
26
- * .toDynamoCommand();
27
- *
28
- * // Check habitat security status
29
- * const securityCheck = new ConditionCheckBuilder('habitats', { id: 'PADDOCK-A' })
30
- * .condition(op =>
31
- * op.and([
32
- * op.eq('securityStatus', 'ACTIVE'),
33
- * op.attributeExists('lastInspection'),
34
- * op.lt('threatLevel', 5)
35
- * ])
36
- * )
37
- * .toDynamoCommand();
38
- * ```
39
- */
40
- declare class ConditionCheckBuilder {
41
- private readonly key;
42
- private readonly tableName;
43
- private conditionExpression?;
44
- constructor(tableName: string, key: PrimaryKeyWithoutExpression);
45
- /**
46
- * Adds a condition that must be satisfied for the check to succeed.
47
- * Use this method when you need to:
48
- * - Validate complex item states
49
- * - Check multiple attributes together
50
- * - Ensure safety conditions are met
51
- *
52
- * @example
53
- * ```typescript
54
- * // Check dinosaur health and behavior
55
- * builder.condition(op =>
56
- * op.and([
57
- * op.gt('stats.health', 50),
58
- * op.not(op.eq('status', 'SEDATED')),
59
- * op.lt('aggressionLevel', 8)
60
- * ])
61
- * );
62
- *
63
- * // Verify habitat conditions
64
- * builder.condition(op =>
65
- * op.and([
66
- * op.eq('powerStatus', 'ONLINE'),
67
- * op.between('temperature', 20, 30),
68
- * op.attributeExists('lastMaintenance')
69
- * ])
70
- * );
71
- *
72
- * // Check breeding conditions
73
- * builder.condition(op =>
74
- * op.and([
75
- * op.eq('species', 'VELOCIRAPTOR'),
76
- * op.gte('age', 3),
77
- * op.eq('geneticPurity', 100)
78
- * ])
79
- * );
80
- * ```
81
- *
82
- * @param condition - Either a Condition DynamoItem or a callback function that builds the condition
83
- * @returns The builder instance for method chaining
84
- */
85
- condition<T extends DynamoItem>(condition: Condition | ((op: ConditionOperator<T>) => Condition)): this;
86
- /**
87
- * Generates the DynamoDB command parameters for direct execution.
88
- * Use this method when you want to:
89
- * - Execute the condition check as a standalone operation
90
- * - Get the raw DynamoDB command for custom execution
91
- * - Inspect the generated command parameters
92
- *
93
- * @example
94
- * ```ts
95
- * const command = new ConditionCheckBuilder('myTable', { id: '123' })
96
- * .condition(op => op.attributeExists('status'))
97
- * .toDynamoCommand();
98
- * // Use command with DynamoDB client
99
- * ```
100
- *
101
- * @throws {Error} If no condition has been set
102
- * @returns The DynamoDB command parameters
103
- */
104
- private toDynamoCommand;
105
- /**
106
- * Adds this condition check operation to a transaction.
107
- * Use this method when you need to:
108
- * - Verify habitat safety before transfers
109
- * - Ensure proper feeding conditions
110
- * - Validate security protocols
111
- *
112
- * @example
113
- * ```ts
114
- * const transaction = new TransactionBuilder();
115
- * new ConditionCheckBuilder('habitats', { id: 'PADDOCK-B' })
116
- * .condition(op => op.and([
117
- * op.eq('securityStatus', 'ACTIVE'),
118
- * op.lt('currentOccupants', 3),
119
- * op.eq('habitatType', 'CARNIVORE')
120
- * ]))
121
- * .withTransaction(transaction);
122
- * // Add dinosaur transfer operations
123
- * ```
124
- *
125
- * @param transaction - The transaction builder to add this operation to
126
- * @throws {Error} If no condition has been set
127
- * @returns The builder instance for method chaining
128
- */
129
- withTransaction(transaction: TransactionBuilder): this;
130
- /**
131
- * Gets a human-readable representation of the condition check command
132
- * with all expression placeholders replaced by their actual values.
133
- * Use this method when you need to:
134
- * - Debug complex condition expressions
135
- * - Verify condition parameters
136
- * - Log safety checks
137
- * - Troubleshoot condition failures
138
- *
139
- * @example
140
- * ```ts
141
- * const debugInfo = new ConditionCheckBuilder('dinosaurs', { id: 'TREX-001' })
142
- * .condition(op => op.and([
143
- * op.between('stats.health', 50, 100),
144
- * op.not(op.eq('status', 'SEDATED')),
145
- * op.attributeExists('lastFeedingTime')
146
- * op.eq('version', 1)
147
- * ]))
148
- * .debug();
149
- * console.log(debugInfo);
150
- * ```
151
- *
152
- * @returns A readable representation of the condition check command with resolved expressions
153
- */
154
- debug(): DynamoItem;
155
- }
156
-
157
- export { ConditionCheckBuilder };
@@ -1,392 +0,0 @@
1
- // src/conditions.ts
2
- var createComparisonCondition = (type) => (attr, value) => ({
3
- type,
4
- attr,
5
- value
6
- });
7
- var eq = createComparisonCondition("eq");
8
- var ne = createComparisonCondition("ne");
9
- var lt = createComparisonCondition("lt");
10
- var lte = createComparisonCondition("lte");
11
- var gt = createComparisonCondition("gt");
12
- var gte = createComparisonCondition("gte");
13
- var between = (attr, lower, upper) => ({
14
- type: "between",
15
- attr,
16
- value: [lower, upper]
17
- });
18
- var beginsWith = createComparisonCondition("beginsWith");
19
- var contains = createComparisonCondition("contains");
20
- var attributeExists = (attr) => ({
21
- type: "attributeExists",
22
- attr
23
- });
24
- var attributeNotExists = (attr) => ({
25
- type: "attributeNotExists",
26
- attr
27
- });
28
- var and = (...conditions) => ({
29
- type: "and",
30
- conditions
31
- });
32
- var or = (...conditions) => ({
33
- type: "or",
34
- conditions
35
- });
36
- var not = (condition) => ({
37
- type: "not",
38
- condition
39
- });
40
-
41
- // src/expression.ts
42
- var generateAttributeName = (params, attr) => {
43
- for (const [existingName, existingAttr] of Object.entries(params.expressionAttributeNames)) {
44
- if (existingAttr === attr) {
45
- return existingName;
46
- }
47
- }
48
- const attrName = `#${Object.keys(params.expressionAttributeNames).length}`;
49
- params.expressionAttributeNames[attrName] = attr;
50
- return attrName;
51
- };
52
- var generateValueName = (params, value) => {
53
- const valueName = `:${params.valueCounter.count++}`;
54
- params.expressionAttributeValues[valueName] = value;
55
- return valueName;
56
- };
57
- var validateCondition = (condition, requiresAttr = true, requiresValue = true) => {
58
- if (requiresAttr && !condition.attr) {
59
- throw new Error(`Attribute is required for ${condition.type} condition`);
60
- }
61
- if (requiresValue && condition.value === void 0) {
62
- throw new Error(`Value is required for ${condition.type} condition`);
63
- }
64
- };
65
- var buildComparisonExpression = (condition, operator, params) => {
66
- validateCondition(condition);
67
- if (!condition.attr) {
68
- throw new Error(`Attribute is required for ${condition.type} condition`);
69
- }
70
- const attrName = generateAttributeName(params, condition.attr);
71
- const valueName = generateValueName(params, condition.value);
72
- return `${attrName} ${operator} ${valueName}`;
73
- };
74
- var buildBetweenExpression = (condition, params) => {
75
- validateCondition(condition);
76
- if (!condition.attr) {
77
- throw new Error(`Attribute is required for ${condition.type} condition`);
78
- }
79
- if (!Array.isArray(condition.value) || condition.value.length !== 2) {
80
- throw new Error("Between condition requires an array of two values");
81
- }
82
- const attrName = generateAttributeName(params, condition.attr);
83
- const lowerName = generateValueName(params, condition.value[0]);
84
- const upperName = generateValueName(params, condition.value[1]);
85
- return `${attrName} BETWEEN ${lowerName} AND ${upperName}`;
86
- };
87
- var buildFunctionExpression = (functionName, condition, params) => {
88
- validateCondition(condition);
89
- if (!condition.attr) {
90
- throw new Error(`Attribute is required for ${condition.type} condition`);
91
- }
92
- const attrName = generateAttributeName(params, condition.attr);
93
- const valueName = generateValueName(params, condition.value);
94
- return `${functionName}(${attrName}, ${valueName})`;
95
- };
96
- var buildAttributeFunction = (functionName, condition, params) => {
97
- validateCondition(condition, true, false);
98
- if (!condition.attr) {
99
- throw new Error(`Attribute is required for ${condition.type} condition`);
100
- }
101
- const attrName = generateAttributeName(params, condition.attr);
102
- return `${functionName}(${attrName})`;
103
- };
104
- var buildLogicalExpression = (operator, conditions, params) => {
105
- if (!conditions || conditions.length === 0) {
106
- throw new Error(`At least one condition is required for ${operator} expression`);
107
- }
108
- const expressions = conditions.map((c) => buildExpression(c, params));
109
- return `(${expressions.join(` ${operator} `)})`;
110
- };
111
- var buildExpression = (condition, params) => {
112
- if (!condition) return "";
113
- try {
114
- const expressionBuilders = {
115
- eq: () => buildComparisonExpression(condition, "=", params),
116
- ne: () => buildComparisonExpression(condition, "<>", params),
117
- lt: () => buildComparisonExpression(condition, "<", params),
118
- lte: () => buildComparisonExpression(condition, "<=", params),
119
- gt: () => buildComparisonExpression(condition, ">", params),
120
- gte: () => buildComparisonExpression(condition, ">=", params),
121
- between: () => buildBetweenExpression(condition, params),
122
- beginsWith: () => buildFunctionExpression("begins_with", condition, params),
123
- contains: () => buildFunctionExpression("contains", condition, params),
124
- attributeExists: () => buildAttributeFunction("attribute_exists", condition, params),
125
- attributeNotExists: () => buildAttributeFunction("attribute_not_exists", condition, params),
126
- and: () => {
127
- if (!condition.conditions) {
128
- throw new Error("Conditions array is required for AND operator");
129
- }
130
- return buildLogicalExpression("AND", condition.conditions, params);
131
- },
132
- or: () => {
133
- if (!condition.conditions) {
134
- throw new Error("Conditions array is required for OR operator");
135
- }
136
- return buildLogicalExpression("OR", condition.conditions, params);
137
- },
138
- not: () => {
139
- if (!condition.condition) {
140
- throw new Error("Condition is required for NOT operator");
141
- }
142
- return `NOT (${buildExpression(condition.condition, params)})`;
143
- }
144
- };
145
- const builder = expressionBuilders[condition.type];
146
- if (!builder) {
147
- throw new Error(`Unknown condition type: ${condition.type}`);
148
- }
149
- return builder();
150
- } catch (error) {
151
- if (error instanceof Error) {
152
- console.error(`Error building expression for condition type ${condition.type}:`, error.message);
153
- } else {
154
- console.error(`Error building expression for condition type ${condition.type}:`, error);
155
- }
156
- throw error;
157
- }
158
- };
159
- var prepareExpressionParams = (condition) => {
160
- if (!condition) return {};
161
- const params = {
162
- expressionAttributeNames: {},
163
- expressionAttributeValues: {},
164
- valueCounter: { count: 0 }
165
- };
166
- const expression = buildExpression(condition, params);
167
- return {
168
- expression,
169
- names: Object.keys(params.expressionAttributeNames).length > 0 ? params.expressionAttributeNames : void 0,
170
- values: Object.keys(params.expressionAttributeValues).length > 0 ? params.expressionAttributeValues : void 0
171
- };
172
- };
173
-
174
- // src/utils/debug-expression.ts
175
- function debugCommand(command) {
176
- const result = {};
177
- function replaceAliases(expressionString) {
178
- if (!expressionString) {
179
- return expressionString;
180
- }
181
- let replacedString = expressionString;
182
- for (const alias in command.expressionAttributeNames) {
183
- const attributeName = command.expressionAttributeNames[alias];
184
- const regex = new RegExp(alias, "g");
185
- replacedString = replacedString.replace(regex, attributeName);
186
- }
187
- for (const alias in command.expressionAttributeValues) {
188
- let attributeValue = command.expressionAttributeValues[alias];
189
- if (attributeValue instanceof Set) {
190
- const array = Array.from(attributeValue);
191
- attributeValue = `Set(${array.length}){${array.map((v) => JSON.stringify(v)).join(", ")}}`;
192
- } else {
193
- attributeValue = JSON.stringify(attributeValue);
194
- }
195
- const regex = new RegExp(alias, "g");
196
- replacedString = replacedString.replace(regex, attributeValue);
197
- }
198
- return replacedString;
199
- }
200
- if (command.updateExpression) {
201
- result.updateExpression = replaceAliases(command.updateExpression);
202
- }
203
- if (command.conditionExpression) {
204
- result.conditionExpression = replaceAliases(command.conditionExpression);
205
- }
206
- if (command.filterExpression) {
207
- result.filterExpression = replaceAliases(command.filterExpression);
208
- }
209
- if (command.keyConditionExpression) {
210
- result.keyConditionExpression = replaceAliases(command.keyConditionExpression);
211
- }
212
- if (command.projectionExpression) {
213
- result.projectionExpression = replaceAliases(command.projectionExpression);
214
- }
215
- return {
216
- raw: command,
217
- readable: result
218
- };
219
- }
220
-
221
- // src/builders/condition-check-builder.ts
222
- var ConditionCheckBuilder = class {
223
- key;
224
- tableName;
225
- conditionExpression;
226
- constructor(tableName, key) {
227
- this.tableName = tableName;
228
- this.key = key;
229
- }
230
- /**
231
- * Adds a condition that must be satisfied for the check to succeed.
232
- * Use this method when you need to:
233
- * - Validate complex item states
234
- * - Check multiple attributes together
235
- * - Ensure safety conditions are met
236
- *
237
- * @example
238
- * ```typescript
239
- * // Check dinosaur health and behavior
240
- * builder.condition(op =>
241
- * op.and([
242
- * op.gt('stats.health', 50),
243
- * op.not(op.eq('status', 'SEDATED')),
244
- * op.lt('aggressionLevel', 8)
245
- * ])
246
- * );
247
- *
248
- * // Verify habitat conditions
249
- * builder.condition(op =>
250
- * op.and([
251
- * op.eq('powerStatus', 'ONLINE'),
252
- * op.between('temperature', 20, 30),
253
- * op.attributeExists('lastMaintenance')
254
- * ])
255
- * );
256
- *
257
- * // Check breeding conditions
258
- * builder.condition(op =>
259
- * op.and([
260
- * op.eq('species', 'VELOCIRAPTOR'),
261
- * op.gte('age', 3),
262
- * op.eq('geneticPurity', 100)
263
- * ])
264
- * );
265
- * ```
266
- *
267
- * @param condition - Either a Condition DynamoItem or a callback function that builds the condition
268
- * @returns The builder instance for method chaining
269
- */
270
- condition(condition) {
271
- if (typeof condition === "function") {
272
- const conditionOperator = {
273
- eq,
274
- ne,
275
- lt,
276
- lte,
277
- gt,
278
- gte,
279
- between,
280
- beginsWith,
281
- contains,
282
- attributeExists,
283
- attributeNotExists,
284
- and,
285
- or,
286
- not
287
- };
288
- this.conditionExpression = condition(conditionOperator);
289
- } else {
290
- this.conditionExpression = condition;
291
- }
292
- return this;
293
- }
294
- /**
295
- * Generates the DynamoDB command parameters for direct execution.
296
- * Use this method when you want to:
297
- * - Execute the condition check as a standalone operation
298
- * - Get the raw DynamoDB command for custom execution
299
- * - Inspect the generated command parameters
300
- *
301
- * @example
302
- * ```ts
303
- * const command = new ConditionCheckBuilder('myTable', { id: '123' })
304
- * .condition(op => op.attributeExists('status'))
305
- * .toDynamoCommand();
306
- * // Use command with DynamoDB client
307
- * ```
308
- *
309
- * @throws {Error} If no condition has been set
310
- * @returns The DynamoDB command parameters
311
- */
312
- toDynamoCommand() {
313
- if (!this.conditionExpression) {
314
- throw new Error("Condition is required for condition check operations");
315
- }
316
- const { expression, names, values } = prepareExpressionParams(this.conditionExpression);
317
- if (!expression) {
318
- throw new Error("Failed to generate condition expression");
319
- }
320
- return {
321
- tableName: this.tableName,
322
- key: this.key,
323
- conditionExpression: expression,
324
- expressionAttributeNames: names,
325
- expressionAttributeValues: values
326
- };
327
- }
328
- /**
329
- * Adds this condition check operation to a transaction.
330
- * Use this method when you need to:
331
- * - Verify habitat safety before transfers
332
- * - Ensure proper feeding conditions
333
- * - Validate security protocols
334
- *
335
- * @example
336
- * ```ts
337
- * const transaction = new TransactionBuilder();
338
- * new ConditionCheckBuilder('habitats', { id: 'PADDOCK-B' })
339
- * .condition(op => op.and([
340
- * op.eq('securityStatus', 'ACTIVE'),
341
- * op.lt('currentOccupants', 3),
342
- * op.eq('habitatType', 'CARNIVORE')
343
- * ]))
344
- * .withTransaction(transaction);
345
- * // Add dinosaur transfer operations
346
- * ```
347
- *
348
- * @param transaction - The transaction builder to add this operation to
349
- * @throws {Error} If no condition has been set
350
- * @returns The builder instance for method chaining
351
- */
352
- withTransaction(transaction) {
353
- if (!this.conditionExpression) {
354
- throw new Error("Condition is required for condition check operations");
355
- }
356
- const command = this.toDynamoCommand();
357
- transaction.conditionCheckWithCommand(command);
358
- return this;
359
- }
360
- /**
361
- * Gets a human-readable representation of the condition check command
362
- * with all expression placeholders replaced by their actual values.
363
- * Use this method when you need to:
364
- * - Debug complex condition expressions
365
- * - Verify condition parameters
366
- * - Log safety checks
367
- * - Troubleshoot condition failures
368
- *
369
- * @example
370
- * ```ts
371
- * const debugInfo = new ConditionCheckBuilder('dinosaurs', { id: 'TREX-001' })
372
- * .condition(op => op.and([
373
- * op.between('stats.health', 50, 100),
374
- * op.not(op.eq('status', 'SEDATED')),
375
- * op.attributeExists('lastFeedingTime')
376
- * op.eq('version', 1)
377
- * ]))
378
- * .debug();
379
- * console.log(debugInfo);
380
- * ```
381
- *
382
- * @returns A readable representation of the condition check command with resolved expressions
383
- */
384
- debug() {
385
- const command = this.toDynamoCommand();
386
- return debugCommand(command);
387
- }
388
- };
389
-
390
- export { ConditionCheckBuilder };
391
- //# sourceMappingURL=condition-check-builder.js.map
392
- //# sourceMappingURL=condition-check-builder.js.map