wirejs-deploy-amplify-basic 0.0.61-table-resource → 0.0.63-table-resource
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,11 +1,13 @@
|
|
|
1
1
|
import { env } from 'process';
|
|
2
|
-
import { DynamoDBClient,
|
|
2
|
+
import { DynamoDBClient, DeleteItemCommand, GetItemCommand, ScanCommand, QueryCommand, } from '@aws-sdk/client-dynamodb';
|
|
3
|
+
import { PutCommand, } from '@aws-sdk/lib-dynamodb';
|
|
3
4
|
import { Resource, } from 'wirejs-resources';
|
|
4
5
|
import { addResource } from '../resource-collector.js';
|
|
5
6
|
function isFieldComparison(filter) {
|
|
6
7
|
return !['and', 'or', 'not'].some(key => key in filter);
|
|
7
8
|
}
|
|
8
9
|
function buildFilterExpression(filter) {
|
|
10
|
+
console.log('Building filter expression for filter:', filter);
|
|
9
11
|
if (filter.and) {
|
|
10
12
|
return `(${filter.and.map(buildFilterExpression).join(' AND ')})`;
|
|
11
13
|
}
|
|
@@ -39,6 +41,7 @@ function buildFilterExpression(filter) {
|
|
|
39
41
|
throw new Error(`Unsupported filter condition: ${JSON.stringify(condition)}`);
|
|
40
42
|
}
|
|
41
43
|
function buildExpressionAttributeValues(filter) {
|
|
44
|
+
console.log('Building expression attribute values for filter:', filter);
|
|
42
45
|
const values = {};
|
|
43
46
|
if (filter.and || filter.or || filter.not) {
|
|
44
47
|
const subFilters = filter.and ?? filter.or ?? [filter.not];
|
|
@@ -49,7 +52,7 @@ function buildExpressionAttributeValues(filter) {
|
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
54
|
else if (isFieldComparison(filter)) {
|
|
52
|
-
const field = Object.keys(filter)
|
|
55
|
+
const [field] = Object.keys(filter);
|
|
53
56
|
const condition = filter[field];
|
|
54
57
|
if ('eq' in condition)
|
|
55
58
|
values[`:${field}`] = { S: condition.eq };
|
|
@@ -125,7 +128,8 @@ export class DistributedTable extends Resource {
|
|
|
125
128
|
...key,
|
|
126
129
|
...item,
|
|
127
130
|
};
|
|
128
|
-
|
|
131
|
+
console.log('Saving item to DynamoDB:', itemToSave);
|
|
132
|
+
await this.ddbClient.send(new PutCommand({
|
|
129
133
|
TableName: this.table,
|
|
130
134
|
Item: itemToSave,
|
|
131
135
|
}));
|
|
@@ -136,6 +140,7 @@ export class DistributedTable extends Resource {
|
|
|
136
140
|
}
|
|
137
141
|
async delete(item) {
|
|
138
142
|
const key = this.#getDDBKey(item);
|
|
143
|
+
console.log('Deleting item from DynamoDB:', key);
|
|
139
144
|
await this.ddbClient.send(new DeleteItemCommand({
|
|
140
145
|
TableName: this.table,
|
|
141
146
|
Key: key,
|
|
@@ -147,6 +152,7 @@ export class DistributedTable extends Resource {
|
|
|
147
152
|
}
|
|
148
153
|
async get(key) {
|
|
149
154
|
const ddbKey = this.#getDDBKey(key);
|
|
155
|
+
console.log('Getting item from DynamoDB:', ddbKey);
|
|
150
156
|
const result = await this.ddbClient.send(new GetItemCommand({
|
|
151
157
|
TableName: this.table,
|
|
152
158
|
Key: ddbKey,
|
|
@@ -156,6 +162,7 @@ export class DistributedTable extends Resource {
|
|
|
156
162
|
return this.parse(result.Item);
|
|
157
163
|
}
|
|
158
164
|
async *scan(options = {}) {
|
|
165
|
+
console.log('Scanning DynamoDB table:', this.table, options);
|
|
159
166
|
let lastEvaluatedKey = undefined;
|
|
160
167
|
do {
|
|
161
168
|
const filterExpression = options.filter ? buildFilterExpression(options.filter) : undefined;
|
|
@@ -176,6 +183,7 @@ export class DistributedTable extends Resource {
|
|
|
176
183
|
} while (lastEvaluatedKey);
|
|
177
184
|
}
|
|
178
185
|
async *query(partition, options = {}) {
|
|
186
|
+
console.log('Querying DynamoDB table:', this.table, partition, options);
|
|
179
187
|
let lastEvaluatedKey = undefined;
|
|
180
188
|
do {
|
|
181
189
|
const ddbKey = this.#getDDBKey(partition);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wirejs-deploy-amplify-basic",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.63-table-resource",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -25,13 +25,14 @@
|
|
|
25
25
|
"@aws-sdk/client-cognito-identity-provider": "^3.741.0",
|
|
26
26
|
"@aws-sdk/client-dynamodb": "^3.774.0",
|
|
27
27
|
"@aws-sdk/client-s3": "^3.738.0",
|
|
28
|
+
"@aws-sdk/lib-dynamodb": "^3.778.0",
|
|
28
29
|
"copy": "^0.3.2",
|
|
29
30
|
"esbuild": "^0.24.2",
|
|
30
31
|
"jsdom": "^25.0.0",
|
|
31
32
|
"recursive-copy": "^2.0.14",
|
|
32
33
|
"rimraf": "^6.0.1",
|
|
33
34
|
"wirejs-dom": "^1.0.38",
|
|
34
|
-
"wirejs-resources": "^0.1.
|
|
35
|
+
"wirejs-resources": "^0.1.31-table-resource"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@aws-amplify/backend": "^1.14.0",
|