Skip to content

Commit

Permalink
JavaScript (v3): Scope the libs package. (#5514)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpyle0819 authored Oct 17, 2023
1 parent 272bff2 commit ac3e696
Show file tree
Hide file tree
Showing 131 changed files with 2,884 additions and 1,174 deletions.
2 changes: 1 addition & 1 deletion javascriptv3/example_code/cloudwatch-events/libs/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// snippet-start:[javascript.v3.cloudwatchevents.client]
import { CloudWatchEventsClient } from "@aws-sdk/client-cloudwatch-events";
import { DEFAULT_REGION } from "libs/utils/util-aws-sdk.js";
import { DEFAULT_REGION } from "@aws-sdk-examples/libs/utils/util-aws-sdk.js";

export const client = new CloudWatchEventsClient({ region: DEFAULT_REGION });
// snippet-end:[javascript.v3.cloudwatchevents.client]
4 changes: 2 additions & 2 deletions javascriptv3/example_code/cloudwatch-events/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"author": "Corey Pyle <[email protected]>",
"license": "Apache-2.0",
"dependencies": {
"@aws-sdk-examples/libs": "^1.0.0",
"@aws-sdk/client-cloudwatch-events": "^3.229.0",
"@aws-sdk/client-cloudwatch-logs": "^3.229.0",
"@aws-sdk/client-lambda": "^3.229.0",
"libs": "*"
"@aws-sdk/client-lambda": "^3.229.0"
},
"type": "module",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
CloudWatchEventsClient,
RemoveTargetsCommand,
} from "@aws-sdk/client-cloudwatch-events";
import { DEFAULT_REGION } from "../../libs/utils/util-aws-sdk.js";
import { DEFAULT_REGION } from "@aws-sdk-examples/libs/utils/util-aws-sdk.js";

/**
* Create a log group.
Expand Down
1 change: 1 addition & 0 deletions javascriptv3/example_code/cloudwatch-logs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"license": "Apache-2.0",
"type": "module",
"dependencies": {
"@aws-sdk-examples/libs": "^1.0.0",
"@aws-sdk/client-cloudwatch-logs": "^3.215.0",
"@aws-sdk/client-iam": "^3.216.0",
"@aws-sdk/client-lambda": "^3.216.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { DescribeSubscriptionFiltersCommand } from "@aws-sdk/client-cloudwatch-l
import { LambdaClient, waitUntilFunctionUpdated } from "@aws-sdk/client-lambda";
import { describe, it, beforeAll, afterAll, expect } from "vitest";

import { retry } from "libs/utils/util-timers.js";
import { setEnv } from "libs/utils/util-node.js";
import { retry } from "@aws-sdk-examples/libs/utils/util-timers.js";
import { setEnv } from "@aws-sdk-examples/libs/utils/util-node.js";

import {
addPermissionLogsInvokeFunction,
Expand Down
2 changes: 1 addition & 1 deletion javascriptv3/example_code/cloudwatch/libs/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// snippet-start:[javascript.v3.cloudwatch.client]
import { CloudWatchClient } from "@aws-sdk/client-cloudwatch";
import { DEFAULT_REGION } from "libs/utils/util-aws-sdk.js";
import { DEFAULT_REGION } from "@aws-sdk-examples/libs/utils/util-aws-sdk.js";

export const client = new CloudWatchClient({ region: DEFAULT_REGION });
// snippet-end:[javascript.v3.cloudwatch.client]
4 changes: 2 additions & 2 deletions javascriptv3/example_code/cloudwatch/libs/ec2-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
RunInstancesCommand,
TerminateInstancesCommand,
} from "@aws-sdk/client-ec2";
import { retry } from "libs/utils/util-timers.js";
import { DEFAULT_REGION } from "libs/utils/util-aws-sdk.js";
import { retry } from "@aws-sdk-examples/libs/utils/util-timers.js";
import { DEFAULT_REGION } from "@aws-sdk-examples/libs/utils/util-aws-sdk.js";

const client = new EC2Client({ region: DEFAULT_REGION });

Expand Down
4 changes: 2 additions & 2 deletions javascriptv3/example_code/cloudwatch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"license": "Apache-2.0",
"type": "module",
"dependencies": {
"@aws-sdk-examples/libs": "^1.0.0",
"@aws-sdk/client-cloudwatch": "^3.212.0",
"@aws-sdk/client-ec2": "^3.213.0",
"libs": "*"
"@aws-sdk/client-ec2": "^3.213.0"
},
"scripts": {
"integration-test": "vitest run **/*.integration.test.js"
Expand Down
1 change: 1 addition & 0 deletions javascriptv3/example_code/codebuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"author": "Corey Pyle <[email protected]>",
"license": "Apache-2.0",
"dependencies": {
"@aws-sdk-examples/libs": "^1.0.0",
"@aws-sdk/client-codebuild": "^3.391.0"
},
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
DeleteProjectCommand,
paginateListProjects,
} from "@aws-sdk/client-codebuild";
import { retry } from "../../libs/utils/util-timers.js";
import { retry } from "@aws-sdk-examples/libs/utils/util-timers.js";

describe(
"create-project",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"integration-test": "vitest run **/*.integration.test.js"
},
"dependencies": {
"@aws-sdk-examples/libs": "^1.0.0",
"@aws-sdk/client-cognito-identity-provider": "^3.423.0",
"@aws-sdk/client-ses": "^3.423.0",
"@types/qrcode-terminal": "^0.12.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { getFirstEntry } from "libs/utils/util-csv.js";
import { log } from "libs/utils/util-log.js";
import { getFirstEntry } from "@aws-sdk-examples/libs/utils/util-csv.js";
import { log } from "@aws-sdk-examples/libs/utils/util-log.js";
import { adminGetUser } from "../../../actions/admin-get-user.js";
import { FILE_USER_POOLS } from "./constants.js";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
*/
/** snippet-start:[javascript.v3.cognito-idp.scenarios.basic.AdminInitiateAuthHandler] **/
import qrcode from "qrcode-terminal";
import { log } from "libs/utils/util-log.js";
import { log } from "@aws-sdk-examples/libs/utils/util-log.js";
import { adminInitiateAuth } from "../../../actions/admin-initiate-auth.js";
import { associateSoftwareToken } from "../../../actions/associate-software-token.js";
import { FILE_USER_POOLS } from "./constants.js";
import { getFirstEntry } from "libs/utils/util-csv.js";
import { getFirstEntry } from "@aws-sdk-examples/libs/utils/util-csv.js";

const handleMfaSetup = async (session, username) => {
const { SecretCode, Session } = await associateSoftwareToken(session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/

/** snippet-start:[javascript.v3.cognito-idp.scenarios.basic.AdminRespondToAuthChallengeHandler] **/
import { log } from "libs/utils/util-log.js";
import { log } from "@aws-sdk-examples/libs/utils/util-log.js";
import { adminRespondToAuthChallenge } from "../../../actions/admin-respond-to-auth-challenge.js";
import { getFirstEntry } from "libs/utils/util-csv.js";
import { getFirstEntry } from "@aws-sdk-examples/libs/utils/util-csv.js";
import { FILE_USER_POOLS } from "./constants.js";

const verifyUsername = (username) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { deleteFiles } from "libs/utils/util-fs.js";
import { log } from "libs/utils/util-log.js";
import { deleteFiles } from "@aws-sdk-examples/libs/utils/util-fs.js";
import { log } from "@aws-sdk-examples/libs/utils/util-log.js";
import { deleteUserPool } from "../../../actions/delete-user-pool.js";
import { FILE_USER_POOLS } from "./constants.js";
import { getFirstValuesFromEntries } from "libs/utils/util-csv.js";
import { getFirstValuesFromEntries } from "@aws-sdk-examples/libs/utils/util-csv.js";

/**
* @param {string[]} userPoolIds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*/

/** snippet-start:[javascript.v3.cognito-idp.scenarios.basic.ConfirmSignUpHandler] **/
import { log } from "libs/utils/util-log.js";
import { log } from "@aws-sdk-examples/libs/utils/util-log.js";
import { confirmSignUp } from "../../../actions/confirm-sign-up.js";
import { FILE_USER_POOLS } from "./constants.js";
import { getSecondValuesFromEntries } from "libs/utils/util-csv.js";
import { getSecondValuesFromEntries } from "@aws-sdk-examples/libs/utils/util-csv.js";

const validateClient = (clientId) => {
if (!clientId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { log } from "libs/utils/util-log.js";
import { getTmp, setTmp } from "libs/utils/util-fs.js";
import { log } from "@aws-sdk-examples/libs/utils/util-log.js";
import { getTmp, setTmp } from "@aws-sdk-examples/libs/utils/util-fs.js";
import { createUserPool } from "../../../actions/create-user-pool.js";
import { FILE_USER_POOLS, NAME_CLIENT } from "./constants.js";
import { setUserPoolMfaConfig } from "../../../actions/set-user-pool-mfa-config.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { getFirstEntry } from "libs/utils/util-csv.js";
import { log } from "libs/utils/util-log.js";
import { getFirstEntry } from "@aws-sdk-examples/libs/utils/util-csv.js";
import { log } from "@aws-sdk-examples/libs/utils/util-log.js";
import { listUsers } from "../../../actions/list-users.js";
import { FILE_USER_POOLS } from "./constants.js";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { getFirstEntry } from "libs/utils/util-csv.js";
import { log } from "libs/utils/util-log.js";
import { getFirstEntry } from "@aws-sdk-examples/libs/utils/util-csv.js";
import { log } from "@aws-sdk-examples/libs/utils/util-log.js";
import { resendConfirmationCode } from "../../../actions/resend-confirmation-code.js";
import { FILE_USER_POOLS } from "./constants.js";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*/

/** snippet-start:[javascript.v3.cognito-idp.scenarios.basic.SignUpHandler] **/
import { log } from "libs/utils/util-log.js";
import { log } from "@aws-sdk-examples/libs/utils/util-log.js";
import { signUp } from "../../../actions/sign-up.js";
import { FILE_USER_POOLS } from "./constants.js";
import { getSecondValuesFromEntries } from "libs/utils/util-csv.js";
import { getSecondValuesFromEntries } from "@aws-sdk-examples/libs/utils/util-csv.js";

const validateClient = (clientId) => {
if (!clientId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/** snippet-start:[javascript.v3.cognito-idp.scenarios.basic.VerifySoftwareTokenHandler] **/
import { log } from "libs/utils/util-log.js";
import { log } from "@aws-sdk-examples/libs/utils/util-log.js";
import { verifySoftwareToken } from "../../../actions/verify-software-token.js";

const validateTotp = (totp) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import { createInterface } from "readline";
import { stdin as input, stdout as output } from "process";

import { readCommands } from "libs/cmd-runner.js";
import { log } from "libs/utils/util-log.js";
import { startsWith } from "libs/utils/util-array.js";
import { readCommands } from "@aws-sdk-examples/libs/cmd-runner.js";
import { log } from "@aws-sdk-examples/libs/utils/util-log.js";
import { startsWith } from "@aws-sdk-examples/libs/utils/util-array.js";

import { createUserPoolHandler } from "./command-handlers/create-user-pool-handler.js";
import { cleanUpHandler } from "./command-handlers/clean-up-handler.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { describe, it, expect, afterAll } from "vitest";
import { createUserPool } from "../actions/create-user-pool.js";
import { getUniqueName } from "../../libs/utils/util-string.js";
import { getUniqueName } from "@aws-sdk-examples/libs/utils/util-string.js";
import { deleteUserPool } from "../actions/delete-user-pool.js";
import { createUserPoolClient } from "../actions/create-user-pool-client.js";
import { listUsers } from "../actions/list-users.js";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
"type": "module",
"main": "build/index.js",
"scripts": {
"test": "node --experimental-vm-modules $(yarn bin jest)",
"test": "vitest run **/*.unit.test.ts",
"start": "node ./watch.js"
},
"author": "[email protected]",
"license": "Apache-2.0",
"devDependencies": {
"@types/express": "^4.17.14",
"@types/mimetext": "^2.0.0",
"jest": "^29.2.1",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"typescript": "^4.8.4"
"typescript": "^4.8.4",
"vitest": "^0.34.6"
},
"dependencies": {
"@aws-sdk/client-rds-data": "^3.190.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { RDSDataClient } from "@aws-sdk/client-rds-data";
import { SESClient } from "@aws-sdk/client-ses";
import { createClientForDefaultRegion } from "../../../libs/utils/util-aws-sdk.js";

const rdsDataClient: RDSDataClient =
createClientForDefaultRegion(RDSDataClient);
const sesClient: SESClient = createClientForDefaultRegion(SESClient);
const rdsDataClient: RDSDataClient = new RDSDataClient({});
const sesClient: SESClient = new SESClient({});

export { rdsDataClient, sesClient };
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from "@jest/globals";
import { describe, it, expect } from "vitest";
import { buildStatementCommand } from "../src/statement-commands/command-helper.js";

describe("command-helper", () => {
Expand All @@ -7,7 +7,7 @@ describe("command-helper", () => {
const sql = "select * from some_table";
const command = buildStatementCommand(sql);
expect(command.constructor.name).toBe("ExecuteStatementCommand");
expect(command.input.sql).toBe(sql)
expect(command.input.sql).toBe(sql);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, jest, expect } from "@jest/globals";
import { Request, Response } from "express";
import { describe, it, vi, expect } from "vitest";
import { NextFunction, Request, Response } from "express";
import QueryString from "qs";
import { getItemsHandler } from "../src/handlers/get-items-handler.js";

Expand All @@ -8,17 +8,19 @@ describe("getItemsHandler", () => {
"should create a request handler that sends a response " +
"with the result of the call to the SDK client",
async () => {
const sendable = { send: async <R>() => ({ records: [] } as R) };
// eslint-disable-next-line
const sendable = { send: async <R>() => ({ records: [] }) as R };
// eslint-disable-next-line
const handler = getItemsHandler.withClient({ rdsDataClient: sendable });
const send: unknown = jest.fn();
const send: unknown = vi.fn();

await handler(
{ query: { archived: "false" } as QueryString.ParsedQs } as Request,
{ send } as Response,
jest.fn()
vi.fn() as unknown as NextFunction,
);

expect(send).toHaveBeenCalledWith([]);
}
},
);
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect } from "@jest/globals";
import { Item } from "src/types/item.js";
import { describe, it, expect } from "vitest";
import type { Item } from "src/types/item.js";
import { parseItem } from "../src/handlers/parse-item.js";

describe("parseItem", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it } from "@jest/globals";
import { describe, expect, it } from "vitest";
import {
csvToHtmlTable,
makeCsv,
Expand Down Expand Up @@ -31,7 +31,7 @@ describe("postItemsReportHandler", () => {
expect(result).toBe(
"id,description,guide,status,name,archived" +
`\n${records[0][0].stringValue},${records[0][1].stringValue},${records[0][2].stringValue},${records[0][3].stringValue},${records[0][4].stringValue},${records[0][5].longValue}` +
`\n${records[1][0].stringValue},${records[1][1].stringValue},${records[1][2].stringValue},${records[1][3].stringValue},${records[1][4].stringValue},${records[1][5].longValue}`
`\n${records[1][0].stringValue},${records[1][1].stringValue},${records[1][2].stringValue},${records[1][3].stringValue},${records[1][4].stringValue},${records[1][5].longValue}`,
);
});
});
Expand All @@ -41,7 +41,7 @@ describe("postItemsReportHandler", () => {
const csv = makeCsv(records);
const html = csvToHtmlTable(csv);
expect(html).toBe(
`<table>
`<table>
<tr>
<th>id</th>
<th>description</th>
Expand All @@ -67,7 +67,7 @@ describe("postItemsReportHandler", () => {
<td>1</td>
</tr>
</table>
`
`,
);
});
});
Expand Down
Loading

0 comments on commit ac3e696

Please sign in to comment.