@kensio/yulin 0.1.0 → 0.1.2
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.
- package/dist/service/cloudfront/factory/cloudfront-functions.factory.d.ts +3 -4
- package/dist/service/cloudfront/factory/cloudfront-functions.factory.d.ts.map +1 -1
- package/dist/service/cloudfront/factory/cloudfront-functions.factory.js +27 -6
- package/dist/service/cloudfront/factory/cloudfront-functions.factory.js.map +1 -1
- package/dist/service/cloudfront/globals.d.ts +22 -0
- package/dist/service/cloudfront/globals.d.ts.map +1 -0
- package/dist/service/cloudfront/globals.js +7 -0
- package/dist/service/cloudfront/globals.js.map +1 -0
- package/dist/service/cloudfront/index.d.ts +2 -2
- package/dist/service/cloudfront/index.d.ts.map +1 -1
- package/dist/service/cloudfront/index.js +1 -1
- package/dist/service/cloudfront/index.js.map +1 -1
- package/dist/service/cloudfront/typings/cloudfront-functions.namespace.d.ts +39 -0
- package/dist/service/cloudfront/typings/cloudfront-functions.namespace.d.ts.map +1 -0
- package/dist/service/cloudfront/typings/cloudfront-functions.namespace.js +2 -0
- package/dist/service/cloudfront/typings/cloudfront-functions.namespace.js.map +1 -0
- package/package.json +11 -1
- package/.github/workflows/pr.yml +0 -54
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/jsLinters/eslint.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/prettier.xml +0 -7
- package/.idea/vcs.xml +0 -6
- package/.idea/yulin.iml +0 -8
- package/.nvmrc +0 -1
- package/.prettierrc +0 -4
- package/eslint.config.ts +0 -222
- package/pnpm-workspace.yaml +0 -23
- package/scripts/publish.sh +0 -14
- package/src/command/command-handler.ts +0 -3
- package/src/index.ts +0 -0
- package/src/service/cloudfront/factory/cloudfront-functions.factory.iso.test.ts +0 -10
- package/src/service/cloudfront/factory/cloudfront-functions.factory.ts +0 -34
- package/src/service/cloudfront/index.ts +0 -13
- package/src/service/cloudfront/typings/cloudfront-functions.ts +0 -48
- package/src/service/dynamodb/command/create-table/create-table.handler.ts +0 -61
- package/src/service/dynamodb/command/create-table/create-table.iso.test.ts +0 -99
- package/src/service/dynamodb/command/describe-table/describe-table.handler.ts +0 -52
- package/src/service/dynamodb/command/describe-table/describe-table.iso.test.ts +0 -82
- package/src/service/dynamodb/command/list-tables/list-tables.handler.ts +0 -53
- package/src/service/dynamodb/command/list-tables/list-tables.iso.test.ts +0 -119
- package/src/service/dynamodb/command/put-item/put-item.handler.ts +0 -56
- package/src/service/dynamodb/command/put-item/put-item.iso.test.ts +0 -354
- package/src/service/dynamodb/dynamodb.ts +0 -60
- package/src/service/dynamodb/index.ts +0 -0
- package/src/service/dynamodb/item/dynamodb-item-attribute.iso.test.ts +0 -19
- package/src/service/dynamodb/item/dynamodb-item-attribute.ts +0 -116
- package/src/service/dynamodb/item/dynamodb-item.ts +0 -39
- package/src/service/dynamodb/table/dynamodb-key-schema.ts +0 -94
- package/src/service/dynamodb/table/dynamodb-table.iso.test.ts +0 -46
- package/src/service/dynamodb/table/dynamodb-table.ts +0 -75
- package/src/service/organizations/index.ts +0 -0
- package/src/service/organizations/sim-aws-account.ts +0 -36
- package/src/service/s3/index.ts +0 -1
- package/src/util/background/background.iso.test.ts +0 -74
- package/src/util/background/background.ts +0 -62
- package/src/util/brand.type.ts +0 -11
- package/src/util/defined.ts +0 -15
- package/src/util/memo/memo.iso.test.ts +0 -43
- package/src/util/memo/memo.ts +0 -26
- package/src/util/sleep.ts +0 -16
- package/tsconfig.build.json +0 -13
- package/tsconfig.json +0 -39
- package/vitest.config.ts +0 -50
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { CloudFrontRequest } from "../typings/cloudfront-functions.js";
|
|
2
|
-
import { StaticFactory } from "@kensio/part-factory";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Makes instances of the CloudFrontRequest object structure.
|
|
6
|
-
*/
|
|
7
|
-
export const cloudFrontRequestFactory = new StaticFactory<CloudFrontRequest>({
|
|
8
|
-
cookies: {
|
|
9
|
-
sessionId: {
|
|
10
|
-
value: "test-session-id",
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
headers: {
|
|
14
|
-
accept: {
|
|
15
|
-
value: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
|
16
|
-
},
|
|
17
|
-
"accept-language": {
|
|
18
|
-
value: "en-GB,en;q=0.9",
|
|
19
|
-
},
|
|
20
|
-
host: {
|
|
21
|
-
value: "yulin.test",
|
|
22
|
-
},
|
|
23
|
-
"user-agent": {
|
|
24
|
-
value: "Mozilla/5.0",
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
method: "GET",
|
|
28
|
-
querystring: {
|
|
29
|
-
page: {
|
|
30
|
-
value: "1",
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
uri: "/cloudfront/",
|
|
34
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export { cloudFrontRequestFactory } from "./factory/cloudfront-functions.factory.js";
|
|
2
|
-
export type {
|
|
3
|
-
CloudFrontCookies,
|
|
4
|
-
CloudFrontEvent,
|
|
5
|
-
CloudFrontEventContext,
|
|
6
|
-
CloudFrontHeaders,
|
|
7
|
-
CloudFrontMultiValue,
|
|
8
|
-
CloudFrontQueryString,
|
|
9
|
-
CloudFrontRequest,
|
|
10
|
-
CloudFrontResponse,
|
|
11
|
-
CloudFrontValue,
|
|
12
|
-
CloudFrontViewer,
|
|
13
|
-
} from "./typings/cloudfront-functions.js";
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
export interface CloudFrontValue {
|
|
2
|
-
value: string;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export interface CloudFrontMultiValue {
|
|
6
|
-
multiValue: CloudFrontValue[];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type CloudFrontHeaders = Record<string, CloudFrontValue>;
|
|
10
|
-
|
|
11
|
-
export type CloudFrontQueryString = Record<
|
|
12
|
-
string,
|
|
13
|
-
CloudFrontValue | CloudFrontMultiValue
|
|
14
|
-
>;
|
|
15
|
-
|
|
16
|
-
export type CloudFrontCookies = Record<string, CloudFrontValue>;
|
|
17
|
-
|
|
18
|
-
export interface CloudFrontRequest {
|
|
19
|
-
method: string;
|
|
20
|
-
uri: string;
|
|
21
|
-
headers: CloudFrontHeaders;
|
|
22
|
-
querystring: CloudFrontQueryString;
|
|
23
|
-
cookies: CloudFrontCookies;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface CloudFrontResponse {
|
|
27
|
-
statusCode: number;
|
|
28
|
-
statusDescription?: string;
|
|
29
|
-
headers?: CloudFrontHeaders;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface CloudFrontEventContext {
|
|
33
|
-
distributionDomainName?: string;
|
|
34
|
-
endpoint?: string;
|
|
35
|
-
distributionId?: string;
|
|
36
|
-
eventType: "viewer-request" | "viewer-response";
|
|
37
|
-
requestId: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface CloudFrontViewer {
|
|
41
|
-
ip: string;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface CloudFrontEvent {
|
|
45
|
-
context: CloudFrontEventContext;
|
|
46
|
-
viewer: CloudFrontViewer;
|
|
47
|
-
request: CloudFrontRequest;
|
|
48
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { DynamoDbTableName } from "../../table/dynamodb-table.js";
|
|
2
|
-
import { SimDynamoDbTable } from "../../table/dynamodb-table.js";
|
|
3
|
-
import {
|
|
4
|
-
type CreateTableCommand,
|
|
5
|
-
type CreateTableCommandOutput,
|
|
6
|
-
ResourceInUseException,
|
|
7
|
-
} from "@aws-sdk/client-dynamodb";
|
|
8
|
-
import type { BackgroundScheduler } from "../../../../util/background/background.js";
|
|
9
|
-
import type { CommandHandler } from "../../../../command/command-handler.js";
|
|
10
|
-
import { jitter } from "../../../../util/sleep.js";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* DynamoDB CreateTableCommand handler.
|
|
14
|
-
*
|
|
15
|
-
* https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/dynamodb/command/CreateTableCommand/
|
|
16
|
-
*/
|
|
17
|
-
export class CreateTableCommandHandler implements CommandHandler<
|
|
18
|
-
CreateTableCommand,
|
|
19
|
-
CreateTableCommandOutput
|
|
20
|
-
> {
|
|
21
|
-
constructor(
|
|
22
|
-
private readonly tables: Map<DynamoDbTableName, SimDynamoDbTable>,
|
|
23
|
-
private readonly background: BackgroundScheduler,
|
|
24
|
-
) {}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Handle creation of a new DynamoDB Table.
|
|
28
|
-
*/
|
|
29
|
-
async handle(cmd: CreateTableCommand): Promise<CreateTableCommandOutput> {
|
|
30
|
-
if (cmd.input.TableName === undefined) {
|
|
31
|
-
throw new Error("CreateTableCommand.input.TableName is required");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const tableName = cmd.input.TableName as DynamoDbTableName;
|
|
35
|
-
if (this.tables.has(tableName)) {
|
|
36
|
-
throw new ResourceInUseException({
|
|
37
|
-
message: `DynamoDB Table ${tableName} already exists`,
|
|
38
|
-
$metadata: {},
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
await jitter();
|
|
43
|
-
|
|
44
|
-
const table = new SimDynamoDbTable(cmd, this.background);
|
|
45
|
-
this.tables.set(tableName, table);
|
|
46
|
-
|
|
47
|
-
this.background.schedule(() => table.activate());
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
TableDescription: {
|
|
51
|
-
AttributeDefinitions: [],
|
|
52
|
-
TableName: tableName,
|
|
53
|
-
KeySchema: [],
|
|
54
|
-
TableStatus: table.status,
|
|
55
|
-
CreationDateTime: table.creationDateTime,
|
|
56
|
-
GlobalSecondaryIndexes: [],
|
|
57
|
-
},
|
|
58
|
-
$metadata: {},
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { describe, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
CreateTableCommand,
|
|
4
|
-
ListTablesCommand,
|
|
5
|
-
ResourceInUseException,
|
|
6
|
-
} from "@aws-sdk/client-dynamodb";
|
|
7
|
-
import { SimAwsAccount } from "../../../organizations/sim-aws-account.js";
|
|
8
|
-
import {
|
|
9
|
-
assertArrayLength,
|
|
10
|
-
assertIdentical,
|
|
11
|
-
assertInstanceOf,
|
|
12
|
-
assertNonNullable,
|
|
13
|
-
assertStringIncludes,
|
|
14
|
-
assertThrowsErrorAsync,
|
|
15
|
-
} from "@kensio/smartass";
|
|
16
|
-
|
|
17
|
-
describe("DynamoDB CreateTableCommand", () => {
|
|
18
|
-
it("creates new DynamoDB Table", async () => {
|
|
19
|
-
const simAccount = new SimAwsAccount();
|
|
20
|
-
const simDynamoDb = simAccount.getDynamoDb();
|
|
21
|
-
|
|
22
|
-
const createTableOutput = await simDynamoDb.createTable(
|
|
23
|
-
new CreateTableCommand({
|
|
24
|
-
TableName: "FoobarTable",
|
|
25
|
-
KeySchema: [{ AttributeName: "id", KeyType: "HASH" }],
|
|
26
|
-
}),
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
assertNonNullable(createTableOutput.TableDescription);
|
|
30
|
-
assertIdentical(
|
|
31
|
-
createTableOutput.TableDescription.TableName,
|
|
32
|
-
"FoobarTable",
|
|
33
|
-
);
|
|
34
|
-
assertIdentical(createTableOutput.TableDescription.TableStatus, "CREATING");
|
|
35
|
-
|
|
36
|
-
const listTablesOutput = await simDynamoDb.listTables(
|
|
37
|
-
new ListTablesCommand(),
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
assertArrayLength(listTablesOutput.TableNames, 1);
|
|
41
|
-
assertIdentical(listTablesOutput.TableNames[0], "FoobarTable");
|
|
42
|
-
|
|
43
|
-
await simAccount.backgroundTasksComplete();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("throws on undefined Table name", async () => {
|
|
47
|
-
const simAccount = new SimAwsAccount();
|
|
48
|
-
const simDynamoDb = simAccount.getDynamoDb();
|
|
49
|
-
|
|
50
|
-
const error = await assertThrowsErrorAsync(async () =>
|
|
51
|
-
simDynamoDb.createTable(
|
|
52
|
-
new CreateTableCommand({
|
|
53
|
-
TableName: undefined,
|
|
54
|
-
KeySchema: [{ AttributeName: "id", KeyType: "HASH" }],
|
|
55
|
-
}),
|
|
56
|
-
),
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
assertInstanceOf(error, Error);
|
|
60
|
-
assertStringIncludes(
|
|
61
|
-
error.message,
|
|
62
|
-
"CreateTableCommand.input.TableName is required",
|
|
63
|
-
);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("throws on missing key schema", async () => {
|
|
67
|
-
const simAccount = new SimAwsAccount();
|
|
68
|
-
const simDynamoDb = simAccount.getDynamoDb();
|
|
69
|
-
|
|
70
|
-
const error = await assertThrowsErrorAsync(async () =>
|
|
71
|
-
simDynamoDb.createTable(
|
|
72
|
-
new CreateTableCommand({ TableName: "FoobarTable" }),
|
|
73
|
-
),
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
assertInstanceOf(error, Error);
|
|
77
|
-
assertStringIncludes(error.message, "Table KeySchema is not defined");
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("throws on duplicate Table name", async () => {
|
|
81
|
-
const simAccount = new SimAwsAccount();
|
|
82
|
-
const simDynamoDb = simAccount.getDynamoDb();
|
|
83
|
-
|
|
84
|
-
await simDynamoDb.createTable(
|
|
85
|
-
new CreateTableCommand({
|
|
86
|
-
TableName: "FoobarTable",
|
|
87
|
-
KeySchema: [{ AttributeName: "id", KeyType: "HASH" }],
|
|
88
|
-
}),
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
const error = await assertThrowsErrorAsync(async () =>
|
|
92
|
-
simDynamoDb.createTable(
|
|
93
|
-
new CreateTableCommand({ TableName: "FoobarTable" }),
|
|
94
|
-
),
|
|
95
|
-
);
|
|
96
|
-
assertInstanceOf(error, ResourceInUseException);
|
|
97
|
-
assertIdentical(error.$fault, "client");
|
|
98
|
-
});
|
|
99
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ResourceNotFoundException,
|
|
3
|
-
type DescribeTableCommand,
|
|
4
|
-
type DescribeTableOutput,
|
|
5
|
-
} from "@aws-sdk/client-dynamodb";
|
|
6
|
-
import type { CommandHandler } from "../../../../command/command-handler.js";
|
|
7
|
-
import type {
|
|
8
|
-
DynamoDbTableName,
|
|
9
|
-
SimDynamoDbTable,
|
|
10
|
-
} from "../../table/dynamodb-table.js";
|
|
11
|
-
import { jitter } from "../../../../util/sleep.js";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* DynamoDB DescribeTableCommand handler.
|
|
15
|
-
*
|
|
16
|
-
* https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/dynamodb/command/DescribeTableCommand/
|
|
17
|
-
*/
|
|
18
|
-
export class DescribeTableCommandHandler implements CommandHandler<
|
|
19
|
-
DescribeTableCommand,
|
|
20
|
-
DescribeTableOutput
|
|
21
|
-
> {
|
|
22
|
-
constructor(
|
|
23
|
-
private readonly tables: Map<DynamoDbTableName, SimDynamoDbTable>,
|
|
24
|
-
) {}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Simulate describing DynamoDB Table.
|
|
28
|
-
*/
|
|
29
|
-
async handle(cmd: DescribeTableCommand): Promise<DescribeTableOutput> {
|
|
30
|
-
if (cmd.input.TableName === undefined) {
|
|
31
|
-
throw new Error("DescribeTableCommand.input.TableName is required");
|
|
32
|
-
}
|
|
33
|
-
const tableName = cmd.input.TableName as DynamoDbTableName;
|
|
34
|
-
|
|
35
|
-
await jitter();
|
|
36
|
-
|
|
37
|
-
const table = this.tables.get(tableName);
|
|
38
|
-
if (table === undefined) {
|
|
39
|
-
throw new ResourceNotFoundException({
|
|
40
|
-
message: `No DynamoDB Table named ${tableName}`,
|
|
41
|
-
$metadata: {},
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
Table: {
|
|
47
|
-
TableName: table.tableName,
|
|
48
|
-
TableStatus: table.status,
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { describe, it } from "vitest";
|
|
2
|
-
import { SimAwsAccount } from "../../../organizations/sim-aws-account.js";
|
|
3
|
-
import {
|
|
4
|
-
CreateTableCommand,
|
|
5
|
-
DescribeTableCommand,
|
|
6
|
-
ResourceNotFoundException,
|
|
7
|
-
} from "@aws-sdk/client-dynamodb";
|
|
8
|
-
import {
|
|
9
|
-
assertIdentical,
|
|
10
|
-
assertInstanceOf,
|
|
11
|
-
assertNonNullable,
|
|
12
|
-
assertOneOf,
|
|
13
|
-
assertThrowsErrorAsync,
|
|
14
|
-
} from "@kensio/smartass";
|
|
15
|
-
|
|
16
|
-
describe("DynamoDB DescribeTableCommand", () => {
|
|
17
|
-
it("describes DynamoDB Table", async () => {
|
|
18
|
-
const simAccount = new SimAwsAccount();
|
|
19
|
-
const simDynamoDb = simAccount.getDynamoDb();
|
|
20
|
-
|
|
21
|
-
await Promise.all([
|
|
22
|
-
simDynamoDb.createTable(
|
|
23
|
-
new CreateTableCommand({
|
|
24
|
-
TableName: "TableA",
|
|
25
|
-
KeySchema: [{ AttributeName: "id", KeyType: "HASH" }],
|
|
26
|
-
}),
|
|
27
|
-
),
|
|
28
|
-
simDynamoDb.createTable(
|
|
29
|
-
new CreateTableCommand({
|
|
30
|
-
TableName: "TableB",
|
|
31
|
-
KeySchema: [{ AttributeName: "id", KeyType: "HASH" }],
|
|
32
|
-
}),
|
|
33
|
-
),
|
|
34
|
-
simDynamoDb.createTable(
|
|
35
|
-
new CreateTableCommand({
|
|
36
|
-
TableName: "TableC",
|
|
37
|
-
KeySchema: [{ AttributeName: "id", KeyType: "HASH" }],
|
|
38
|
-
}),
|
|
39
|
-
),
|
|
40
|
-
]);
|
|
41
|
-
|
|
42
|
-
const describeTableOutput = await simDynamoDb.describeTable(
|
|
43
|
-
new DescribeTableCommand({ TableName: "TableB" }),
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
assertNonNullable(describeTableOutput.Table?.TableName);
|
|
47
|
-
assertIdentical(describeTableOutput.Table.TableName, "TableB");
|
|
48
|
-
assertNonNullable(describeTableOutput.Table.TableStatus);
|
|
49
|
-
assertOneOf(describeTableOutput.Table.TableStatus, ["CREATING", "ACTIVE"]);
|
|
50
|
-
|
|
51
|
-
await simAccount.backgroundTasksComplete();
|
|
52
|
-
|
|
53
|
-
const describeAgain = await simDynamoDb.describeTable(
|
|
54
|
-
new DescribeTableCommand({ TableName: "TableB" }),
|
|
55
|
-
);
|
|
56
|
-
assertNonNullable(describeAgain.Table?.TableStatus);
|
|
57
|
-
assertIdentical(describeAgain.Table.TableStatus, "ACTIVE");
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("throws on undefined Table name", async () => {
|
|
61
|
-
const simAccount = new SimAwsAccount();
|
|
62
|
-
const simDynamoDb = simAccount.getDynamoDb();
|
|
63
|
-
|
|
64
|
-
await assertThrowsErrorAsync(async () =>
|
|
65
|
-
simDynamoDb.describeTable(
|
|
66
|
-
new DescribeTableCommand({ TableName: undefined }),
|
|
67
|
-
),
|
|
68
|
-
);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("throws on describing non-existent DynamoDB Table", async () => {
|
|
72
|
-
const simAccount = new SimAwsAccount();
|
|
73
|
-
const simDynamoDb = simAccount.getDynamoDb();
|
|
74
|
-
|
|
75
|
-
const error = await assertThrowsErrorAsync(async () =>
|
|
76
|
-
simDynamoDb.describeTable(
|
|
77
|
-
new DescribeTableCommand({ TableName: "NonExistentTable" }),
|
|
78
|
-
),
|
|
79
|
-
);
|
|
80
|
-
assertInstanceOf(error, ResourceNotFoundException);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { CommandHandler } from "../../../../command/command-handler.js";
|
|
2
|
-
import type {
|
|
3
|
-
ListTablesCommand,
|
|
4
|
-
ListTablesOutput,
|
|
5
|
-
} from "@aws-sdk/client-dynamodb";
|
|
6
|
-
import type {
|
|
7
|
-
DynamoDbTableName,
|
|
8
|
-
SimDynamoDbTable,
|
|
9
|
-
} from "../../table/dynamodb-table.js";
|
|
10
|
-
import { jitter } from "../../../../util/sleep.js";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Simulated DynamoDB ListTablesCommand handler.
|
|
14
|
-
*
|
|
15
|
-
* https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/dynamodb/command/ListTablesCommand/
|
|
16
|
-
*/
|
|
17
|
-
export class ListTablesCommandHandler implements CommandHandler<
|
|
18
|
-
ListTablesCommand,
|
|
19
|
-
ListTablesOutput
|
|
20
|
-
> {
|
|
21
|
-
constructor(
|
|
22
|
-
private readonly tables: Map<DynamoDbTableName, SimDynamoDbTable>,
|
|
23
|
-
) {}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Simulate listing DynamoDB Tables.
|
|
27
|
-
*/
|
|
28
|
-
async handle(cmd: ListTablesCommand): Promise<ListTablesOutput> {
|
|
29
|
-
await jitter();
|
|
30
|
-
|
|
31
|
-
const tables = [...this.tables.values()];
|
|
32
|
-
tables.sort((a, b) => a.tableName.localeCompare(b.tableName));
|
|
33
|
-
|
|
34
|
-
const exclusiveStartTableName = cmd.input.ExclusiveStartTableName;
|
|
35
|
-
const limit = cmd.input.Limit ?? 100;
|
|
36
|
-
|
|
37
|
-
const startIndex =
|
|
38
|
-
exclusiveStartTableName === undefined
|
|
39
|
-
? 0
|
|
40
|
-
: Math.max(
|
|
41
|
-
0,
|
|
42
|
-
tables.findIndex((t) => t.tableName === exclusiveStartTableName) +
|
|
43
|
-
1,
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
const page = tables.slice(startIndex, startIndex + limit);
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
TableNames: page.map((table) => table.tableName),
|
|
50
|
-
LastEvaluatedTableName: page.at(-1)?.tableName,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { describe, it } from "vitest";
|
|
2
|
-
import { SimAwsAccount } from "../../../organizations/sim-aws-account.js";
|
|
3
|
-
import {
|
|
4
|
-
CreateTableCommand,
|
|
5
|
-
ListTablesCommand,
|
|
6
|
-
} from "@aws-sdk/client-dynamodb";
|
|
7
|
-
import { assertArrayLength, assertIdentical } from "@kensio/smartass";
|
|
8
|
-
|
|
9
|
-
describe("DynamoDB ListTablesCommand", () => {
|
|
10
|
-
it("List all DynamoDB Tables", async () => {
|
|
11
|
-
const simAccount = new SimAwsAccount();
|
|
12
|
-
const simDynamoDb = simAccount.getDynamoDb();
|
|
13
|
-
|
|
14
|
-
await Promise.all([
|
|
15
|
-
simDynamoDb.createTable(
|
|
16
|
-
new CreateTableCommand({
|
|
17
|
-
TableName: "TableA",
|
|
18
|
-
KeySchema: [{ AttributeName: "id", KeyType: "HASH" }],
|
|
19
|
-
}),
|
|
20
|
-
),
|
|
21
|
-
simDynamoDb.createTable(
|
|
22
|
-
new CreateTableCommand({
|
|
23
|
-
TableName: "TableB",
|
|
24
|
-
KeySchema: [{ AttributeName: "id", KeyType: "HASH" }],
|
|
25
|
-
}),
|
|
26
|
-
),
|
|
27
|
-
simDynamoDb.createTable(
|
|
28
|
-
new CreateTableCommand({
|
|
29
|
-
TableName: "TableC",
|
|
30
|
-
KeySchema: [{ AttributeName: "id", KeyType: "HASH" }],
|
|
31
|
-
}),
|
|
32
|
-
),
|
|
33
|
-
]);
|
|
34
|
-
|
|
35
|
-
const listTablesOutput = await simDynamoDb.listTables(
|
|
36
|
-
new ListTablesCommand(),
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
assertArrayLength(listTablesOutput.TableNames, 3);
|
|
40
|
-
|
|
41
|
-
assertIdentical(listTablesOutput.TableNames[0], "TableA");
|
|
42
|
-
assertIdentical(listTablesOutput.TableNames[1], "TableB");
|
|
43
|
-
assertIdentical(listTablesOutput.TableNames[2], "TableC");
|
|
44
|
-
|
|
45
|
-
assertIdentical(listTablesOutput.LastEvaluatedTableName, "TableC");
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("List DynamoDB Tables with limit", async () => {
|
|
49
|
-
const simAccount = new SimAwsAccount();
|
|
50
|
-
const simDynamoDb = simAccount.getDynamoDb();
|
|
51
|
-
|
|
52
|
-
await Promise.all([
|
|
53
|
-
simDynamoDb.createTable(
|
|
54
|
-
new CreateTableCommand({
|
|
55
|
-
TableName: "TableA",
|
|
56
|
-
KeySchema: [{ AttributeName: "id", KeyType: "HASH" }],
|
|
57
|
-
}),
|
|
58
|
-
),
|
|
59
|
-
simDynamoDb.createTable(
|
|
60
|
-
new CreateTableCommand({
|
|
61
|
-
TableName: "TableB",
|
|
62
|
-
KeySchema: [{ AttributeName: "id", KeyType: "HASH" }],
|
|
63
|
-
}),
|
|
64
|
-
),
|
|
65
|
-
simDynamoDb.createTable(
|
|
66
|
-
new CreateTableCommand({
|
|
67
|
-
TableName: "TableC",
|
|
68
|
-
KeySchema: [{ AttributeName: "id", KeyType: "HASH" }],
|
|
69
|
-
}),
|
|
70
|
-
),
|
|
71
|
-
]);
|
|
72
|
-
|
|
73
|
-
const listTablesOutput = await simDynamoDb.listTables(
|
|
74
|
-
new ListTablesCommand({ Limit: 2 }),
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
assertArrayLength(listTablesOutput.TableNames, 2);
|
|
78
|
-
|
|
79
|
-
assertIdentical(listTablesOutput.TableNames[0], "TableA");
|
|
80
|
-
assertIdentical(listTablesOutput.TableNames[1], "TableB");
|
|
81
|
-
|
|
82
|
-
assertIdentical(listTablesOutput.LastEvaluatedTableName, "TableB");
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("List DynamoDB Tables with exclusive start and limit", async () => {
|
|
86
|
-
const simAccount = new SimAwsAccount();
|
|
87
|
-
const simDynamoDb = simAccount.getDynamoDb();
|
|
88
|
-
|
|
89
|
-
await Promise.all([
|
|
90
|
-
simDynamoDb.createTable(
|
|
91
|
-
new CreateTableCommand({
|
|
92
|
-
TableName: "TableA",
|
|
93
|
-
KeySchema: [{ AttributeName: "id", KeyType: "HASH" }],
|
|
94
|
-
}),
|
|
95
|
-
),
|
|
96
|
-
simDynamoDb.createTable(
|
|
97
|
-
new CreateTableCommand({
|
|
98
|
-
TableName: "TableB",
|
|
99
|
-
KeySchema: [{ AttributeName: "id", KeyType: "HASH" }],
|
|
100
|
-
}),
|
|
101
|
-
),
|
|
102
|
-
simDynamoDb.createTable(
|
|
103
|
-
new CreateTableCommand({
|
|
104
|
-
TableName: "TableC",
|
|
105
|
-
KeySchema: [{ AttributeName: "id", KeyType: "HASH" }],
|
|
106
|
-
}),
|
|
107
|
-
),
|
|
108
|
-
]);
|
|
109
|
-
|
|
110
|
-
const listTablesOutput = await simDynamoDb.listTables(
|
|
111
|
-
new ListTablesCommand({ ExclusiveStartTableName: "TableB", Limit: 2 }),
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
assertArrayLength(listTablesOutput.TableNames, 1);
|
|
115
|
-
|
|
116
|
-
assertIdentical(listTablesOutput.TableNames[0], "TableC");
|
|
117
|
-
assertIdentical(listTablesOutput.LastEvaluatedTableName, "TableC");
|
|
118
|
-
});
|
|
119
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { CommandHandler } from "../../../../command/command-handler.js";
|
|
2
|
-
import {
|
|
3
|
-
type PutItemCommand,
|
|
4
|
-
type PutItemCommandOutput,
|
|
5
|
-
ResourceNotFoundException,
|
|
6
|
-
} from "@aws-sdk/client-dynamodb";
|
|
7
|
-
import type {
|
|
8
|
-
DynamoDbTableName,
|
|
9
|
-
SimDynamoDbTable,
|
|
10
|
-
} from "../../table/dynamodb-table.js";
|
|
11
|
-
import { DynamoDbItem } from "../../item/dynamodb-item.js";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* DynamoDB PutItemCommand handler.
|
|
15
|
-
*
|
|
16
|
-
* https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/dynamodb/command/PutItemCommand/
|
|
17
|
-
*/
|
|
18
|
-
export class PutItemCommandHandler implements CommandHandler<
|
|
19
|
-
PutItemCommand,
|
|
20
|
-
PutItemCommandOutput
|
|
21
|
-
> {
|
|
22
|
-
constructor(
|
|
23
|
-
private readonly tables: Map<DynamoDbTableName, SimDynamoDbTable>,
|
|
24
|
-
) {}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Put an Item into a DynamoDB Table.
|
|
28
|
-
*/
|
|
29
|
-
async handle(cmd: PutItemCommand): Promise<PutItemCommandOutput> {
|
|
30
|
-
const tableName = cmd.input.TableName as DynamoDbTableName | undefined;
|
|
31
|
-
if (tableName === undefined) {
|
|
32
|
-
throw new Error("PutItemCommand.input.TableName is required");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const table = this.tables.get(tableName);
|
|
36
|
-
if (table === undefined) {
|
|
37
|
-
throw new ResourceNotFoundException({
|
|
38
|
-
message: `No DynamoDB Table named ${tableName}`,
|
|
39
|
-
$metadata: {},
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (cmd.input.Item === undefined) {
|
|
44
|
-
throw new Error("PutItemCommand.input.Item is required");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const item = DynamoDbItem.fromAttributeValues(cmd.input.Item);
|
|
48
|
-
|
|
49
|
-
await table.putItem(item);
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
Attributes: item.toAttributeValues(),
|
|
53
|
-
$metadata: {},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
}
|