wirejs-deploy-amplify-basic 0.0.66-table-resource → 0.0.68-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.
|
@@ -7,14 +7,15 @@ import { Bucket, BlockPublicAccess } from 'aws-cdk-lib/aws-s3';
|
|
|
7
7
|
import { Table, AttributeType, BillingMode } from 'aws-cdk-lib/aws-dynamodb';
|
|
8
8
|
import { api } from './functions/api/resource';
|
|
9
9
|
import { auth } from './auth/resource';
|
|
10
|
+
import { KeyFieldDefinition } from 'wirejs-resources';
|
|
11
|
+
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
import generated from './generated-resources';
|
|
10
14
|
|
|
11
15
|
const APP_ID = process.env.AWS_APP_ID ?? process.env.PWD?.replace(/[^a-zA-Z0-9-_]/g, '_');
|
|
12
16
|
const BRANCH_ID = process.env.AWS_BRANCH ?? process.env.USER ?? 'anonymous';
|
|
13
17
|
const TABLE_NAME_PREFIX = `${APP_ID}-${BRANCH_ID}-`;
|
|
14
18
|
|
|
15
|
-
// @ts-ignore
|
|
16
|
-
import generated from './generated-resources';
|
|
17
|
-
|
|
18
19
|
/**
|
|
19
20
|
* Amplify resources
|
|
20
21
|
*/
|
|
@@ -59,25 +60,30 @@ function isDistributedTable(resource: any): resource is {
|
|
|
59
60
|
type: 'DistributedTable';
|
|
60
61
|
options: {
|
|
61
62
|
absoluteId: string;
|
|
62
|
-
partitionKey:
|
|
63
|
-
sortKey:
|
|
63
|
+
partitionKey: KeyFieldDefinition<any, any, any>;
|
|
64
|
+
sortKey: KeyFieldDefinition<any, any, any> | undefined;
|
|
64
65
|
}
|
|
65
66
|
} {
|
|
66
67
|
return resource.type === 'DistributedTable';
|
|
67
68
|
}
|
|
68
69
|
|
|
70
|
+
const PKFieldTypes = {
|
|
71
|
+
'string': AttributeType.STRING,
|
|
72
|
+
'number': AttributeType.NUMBER,
|
|
73
|
+
}
|
|
74
|
+
|
|
69
75
|
// TODO: Need to get AttributeType from customer definition.
|
|
70
76
|
for (const resource of generated) {
|
|
71
77
|
if (isDistributedTable(resource)) {
|
|
72
78
|
const sanitizedId = resource.options.absoluteId.replace(/[^a-zA-Z0-9-_]/g, '_');
|
|
73
79
|
const table = new Table(backend.stack, sanitizedId, {
|
|
74
80
|
partitionKey: {
|
|
75
|
-
name: resource.options.partitionKey,
|
|
76
|
-
type:
|
|
81
|
+
name: resource.options.partitionKey.field,
|
|
82
|
+
type: PKFieldTypes[resource.options.partitionKey.type],
|
|
77
83
|
},
|
|
78
84
|
sortKey: resource.options.sortKey ? {
|
|
79
|
-
name: resource.options.sortKey
|
|
80
|
-
type:
|
|
85
|
+
name: resource.options.sortKey.field,
|
|
86
|
+
type: PKFieldTypes[resource.options.sortKey.type],
|
|
81
87
|
} : undefined,
|
|
82
88
|
removalPolicy: RemovalPolicy.RETAIN,
|
|
83
89
|
tableName: `${TABLE_NAME_PREFIX}${sanitizedId}`,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
2
|
-
import { Filter, Parser, RecordKey, Resource } from 'wirejs-resources';
|
|
2
|
+
import { AnyKeyFieldOption, Filter, Parser, RecordKey, Resource } from 'wirejs-resources';
|
|
3
3
|
export declare function PassThruParser<T>(record: Record<string, any>): T;
|
|
4
4
|
/**
|
|
5
5
|
* A table of records that favors very high *overall* scalability at the expense of
|
|
@@ -12,7 +12,7 @@ export declare function PassThruParser<T>(record: Record<string, any>): T;
|
|
|
12
12
|
*
|
|
13
13
|
* High cardinality, non-sequential partition keys allow for the best overall scaling.
|
|
14
14
|
*/
|
|
15
|
-
export declare class DistributedTable<const P extends Parser<any>, const T extends ReturnType<P>, const PK extends
|
|
15
|
+
export declare class DistributedTable<const P extends Parser<any>, const T extends ReturnType<P>, const PK extends AnyKeyFieldOption<T>, const SK extends AnyKeyFieldOption<T> | undefined> extends Resource {
|
|
16
16
|
#private;
|
|
17
17
|
parse: P;
|
|
18
18
|
partitionKey: PK;
|
|
@@ -26,6 +26,8 @@ export declare class DistributedTable<const P extends Parser<any>, const T exten
|
|
|
26
26
|
sort?: SK;
|
|
27
27
|
};
|
|
28
28
|
});
|
|
29
|
+
get partitionKeyName(): PK['field'];
|
|
30
|
+
get sortKeyName(): 'field' extends (keyof SK) ? SK['field'] : undefined;
|
|
29
31
|
save(item: T): Promise<void>;
|
|
30
32
|
saveMany(items: T[]): Promise<void>;
|
|
31
33
|
delete(item: RecordKey<T, PK, SK>): Promise<void>;
|
|
@@ -34,7 +36,7 @@ export declare class DistributedTable<const P extends Parser<any>, const T exten
|
|
|
34
36
|
scan(options?: {
|
|
35
37
|
filter?: Filter<T>;
|
|
36
38
|
}): AsyncGenerator<T>;
|
|
37
|
-
query(partition: Pick<T, PK>, options?: {
|
|
39
|
+
query(partition: Pick<T, PK['field']>, options?: {
|
|
38
40
|
filter?: Filter<T>;
|
|
39
41
|
}): AsyncGenerator<T>;
|
|
40
42
|
}
|
|
@@ -111,14 +111,18 @@ export class DistributedTable extends Resource {
|
|
|
111
111
|
sortKey: this.sort,
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
|
+
get partitionKeyName() {
|
|
115
|
+
return this.partitionKey.field;
|
|
116
|
+
}
|
|
117
|
+
get sortKeyName() {
|
|
118
|
+
return this.sort?.field;
|
|
119
|
+
}
|
|
114
120
|
#getDDBKey(key) {
|
|
115
121
|
const ddbKey = {
|
|
116
|
-
[this.
|
|
122
|
+
[this.partitionKeyName]: key[this.partitionKeyName]
|
|
117
123
|
};
|
|
118
|
-
if (this.
|
|
119
|
-
|
|
120
|
-
ddbKey[sk] = key[sk];
|
|
121
|
-
}
|
|
124
|
+
if (typeof this.sortKeyName === 'string') {
|
|
125
|
+
ddbKey[this.sortKeyName] = key[this.sortKeyName];
|
|
122
126
|
}
|
|
123
127
|
return ddbKey;
|
|
124
128
|
}
|
|
@@ -191,9 +195,9 @@ export class DistributedTable extends Resource {
|
|
|
191
195
|
const expressionAttributeValues = options.filter ? buildExpressionAttributeValues(options.filter) : undefined;
|
|
192
196
|
const result = await this.ddbClient.send(new QueryCommand({
|
|
193
197
|
TableName: this.table,
|
|
194
|
-
KeyConditionExpression: `${this.
|
|
198
|
+
KeyConditionExpression: `${this.partitionKeyName} = :partitionKey`,
|
|
195
199
|
ExpressionAttributeValues: {
|
|
196
|
-
':partitionKey': ddbKey[this.
|
|
200
|
+
':partitionKey': ddbKey[this.partitionKeyName],
|
|
197
201
|
...expressionAttributeValues
|
|
198
202
|
},
|
|
199
203
|
FilterExpression: filterExpression,
|
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.68-table-resource",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"recursive-copy": "^2.0.14",
|
|
33
33
|
"rimraf": "^6.0.1",
|
|
34
34
|
"wirejs-dom": "^1.0.38",
|
|
35
|
-
"wirejs-resources": "^0.1.
|
|
35
|
+
"wirejs-resources": "^0.1.36-table-resource"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@aws-amplify/backend": "^1.14.0",
|