Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,207 changes: 1,058 additions & 149 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@
"@aws-sdk/client-s3": "<3.731.0",
"@aws-sdk/client-s3-control": "^3.830.0",
"@aws-sdk/client-sagemaker": "<3.696.0",
"@aws-sdk/client-schemas": "~3.693.0",
"@aws-sdk/client-sfn": "<3.731.0",
"@aws-sdk/client-ssm": "<3.731.0",
"@aws-sdk/client-sso": "<3.731.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as nls from 'vscode-nls'
const localize = nls.loadMessageBundle()
import { Schemas } from 'aws-sdk'
import { PutCodeBindingResponse } from '@aws-sdk/client-schemas'
import fs = require('fs')
import path = require('path')
import * as vscode from 'vscode'
Expand Down Expand Up @@ -180,10 +180,8 @@ export class SchemaCodeDownloader {
export class CodeGenerator {
public constructor(public client: SchemaClient) {}

public async generate(
codeDownloadRequest: SchemaCodeDownloadRequestDetails
): Promise<Schemas.PutCodeBindingResponse> {
let response: Schemas.PutCodeBindingResponse
public async generate(codeDownloadRequest: SchemaCodeDownloadRequestDetails): Promise<PutCodeBindingResponse> {
let response: PutCodeBindingResponse
try {
response = await this.client.putCodeBinding(
codeDownloadRequest.language,
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/eventSchemas/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import * as nls from 'vscode-nls'
const localize = nls.loadMessageBundle()

import { Schemas } from 'aws-sdk'
import { RegistrySummary, SchemaSummary, SearchSchemaSummary } from '@aws-sdk/client-schemas'
import * as vscode from 'vscode'
import { SchemaClient } from '../shared/clients/schemaClient'

export async function* listRegistryItems(client: SchemaClient): AsyncIterableIterator<Schemas.RegistrySummary> {
export async function* listRegistryItems(client: SchemaClient): AsyncIterableIterator<RegistrySummary> {
const status = vscode.window.setStatusBarMessage(
localize('AWS.message.statusBar.loading.registries', 'Loading Registry Items...')
)
Expand All @@ -25,7 +25,7 @@ export async function* listRegistryItems(client: SchemaClient): AsyncIterableIte
export async function* listSchemaItems(
client: SchemaClient,
registryName: string
): AsyncIterableIterator<Schemas.SchemaSummary> {
): AsyncIterableIterator<SchemaSummary> {
const status = vscode.window.setStatusBarMessage(
localize('AWS.message.statusBar.loading.schemaItems', 'Loading Schema Items...')
)
Expand All @@ -41,7 +41,7 @@ export async function* searchSchemas(
client: SchemaClient,
keyword: string,
registryName: string
): AsyncIterableIterator<Schemas.SearchSchemaSummary> {
): AsyncIterableIterator<SearchSchemaSummary> {
const status = vscode.window.setStatusBarMessage(
localize('AWS.message.statusBar.searching.schemas', 'Searching Schemas...')
)
Expand Down
110 changes: 68 additions & 42 deletions packages/core/src/shared/clients/schemaClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,33 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { Schemas } from 'aws-sdk'
import {
DescribeCodeBindingCommand,
DescribeCodeBindingResponse,
DescribeSchemaCommand,
DescribeSchemaResponse,
GetCodeBindingSourceCommand,
GetCodeBindingSourceResponse,
ListRegistriesCommand,
ListRegistriesRequest,
ListRegistriesResponse,
ListSchemasCommand,
ListSchemasRequest,
ListSchemasResponse,
ListSchemaVersionsCommand,
ListSchemaVersionsRequest,
ListSchemaVersionsResponse,
PutCodeBindingCommand,
PutCodeBindingResponse,
RegistrySummary,
SchemasClient,
SchemaSummary,
SchemaVersionSummary,
SearchSchemasCommand,
SearchSchemasRequest,
SearchSchemasResponse,
SearchSchemaSummary,
} from '@aws-sdk/client-schemas'
import globals from '../extensionGlobals'

import { ClassToInterfaceType } from '../utilities/tsUtils'
Expand All @@ -12,13 +38,13 @@ export type SchemaClient = ClassToInterfaceType<DefaultSchemaClient>
export class DefaultSchemaClient {
public constructor(public readonly regionCode: string) {}

public async *listRegistries(): AsyncIterableIterator<Schemas.RegistrySummary> {
const client = await this.createSdkClient()
public async *listRegistries(): AsyncIterableIterator<RegistrySummary> {
const client = this.createSdkClient()

const request: Schemas.ListRegistriesRequest = {}
const request: ListRegistriesRequest = {}

do {
const response: Schemas.ListRegistriesResponse = await client.listRegistries(request).promise()
const response: ListRegistriesResponse = await client.send(new ListRegistriesCommand(request))

if (response.Registries) {
yield* response.Registries
Expand All @@ -28,15 +54,15 @@ export class DefaultSchemaClient {
} while (request.NextToken)
}

public async *listSchemas(registryName: string): AsyncIterableIterator<Schemas.SchemaSummary> {
const client = await this.createSdkClient()
public async *listSchemas(registryName: string): AsyncIterableIterator<SchemaSummary> {
const client = this.createSdkClient()

const request: Schemas.ListSchemasRequest = {
const request: ListSchemasRequest = {
RegistryName: registryName,
}

do {
const response: Schemas.ListSchemasResponse = await client.listSchemas(request).promise()
const response: ListSchemasResponse = await client.send(new ListSchemasCommand(request))

if (response.Schemas) {
yield* response.Schemas
Expand All @@ -50,31 +76,31 @@ export class DefaultSchemaClient {
registryName: string,
schemaName: string,
schemaVersion?: string
): Promise<Schemas.DescribeSchemaResponse> {
const client = await this.createSdkClient()
): Promise<DescribeSchemaResponse> {
const client = this.createSdkClient()

return await client
.describeSchema({
return await client.send(
new DescribeSchemaCommand({
RegistryName: registryName,
SchemaName: schemaName,
SchemaVersion: schemaVersion,
})
.promise()
)
}

public async *listSchemaVersions(
registryName: string,
schemaName: string
): AsyncIterableIterator<Schemas.SchemaVersionSummary> {
const client = await this.createSdkClient()
): AsyncIterableIterator<SchemaVersionSummary> {
const client = this.createSdkClient()

const request: Schemas.ListSchemaVersionsRequest = {
const request: ListSchemaVersionsRequest = {
RegistryName: registryName,
SchemaName: schemaName,
}

do {
const response: Schemas.ListSchemaVersionsResponse = await client.listSchemaVersions(request).promise()
const response: ListSchemaVersionsResponse = await client.send(new ListSchemaVersionsCommand(request))

if (response.SchemaVersions) {
yield* response.SchemaVersions
Expand All @@ -84,19 +110,16 @@ export class DefaultSchemaClient {
} while (request.NextToken)
}

public async *searchSchemas(
keywords: string,
registryName: string
): AsyncIterableIterator<Schemas.SearchSchemaSummary> {
const client = await this.createSdkClient()
public async *searchSchemas(keywords: string, registryName: string): AsyncIterableIterator<SearchSchemaSummary> {
const client = this.createSdkClient()

const request: Schemas.SearchSchemasRequest = {
const request: SearchSchemasRequest = {
Keywords: keywords,
RegistryName: registryName,
}

do {
const response: Schemas.SearchSchemasResponse = await client.searchSchemas(request).promise()
const response: SearchSchemasResponse = await client.send(new SearchSchemasCommand(request))

if (response.Schemas) {
yield* response.Schemas
Expand All @@ -111,55 +134,58 @@ export class DefaultSchemaClient {
registryName: string,
schemaName: string,
schemaVersion: string
): Promise<Schemas.GetCodeBindingSourceResponse> {
const client = await this.createSdkClient()
): Promise<GetCodeBindingSourceResponse> {
const client = this.createSdkClient()

return await client
.getCodeBindingSource({
return await client.send(
new GetCodeBindingSourceCommand({
Language: language,
RegistryName: registryName,
SchemaName: schemaName,
SchemaVersion: schemaVersion,
})
.promise()
)
}

public async putCodeBinding(
language: string,
registryName: string,
schemaName: string,
schemaVersion: string
): Promise<Schemas.PutCodeBindingResponse> {
const client = await this.createSdkClient()
): Promise<PutCodeBindingResponse> {
const client = this.createSdkClient()

return await client
.putCodeBinding({
return await client.send(
new PutCodeBindingCommand({
Language: language,
RegistryName: registryName,
SchemaName: schemaName,
SchemaVersion: schemaVersion,
})
.promise()
)
}
public async describeCodeBinding(
language: string,
registryName: string,
schemaName: string,
schemaVersion: string
): Promise<Schemas.DescribeCodeBindingResponse> {
const client = await this.createSdkClient()
): Promise<DescribeCodeBindingResponse> {
const client = this.createSdkClient()

return await client
.describeCodeBinding({
return await client.send(
new DescribeCodeBindingCommand({
Language: language,
RegistryName: registryName,
SchemaName: schemaName,
SchemaVersion: schemaVersion,
})
.promise()
)
}

private async createSdkClient(): Promise<Schemas> {
return await globals.sdkClientBuilder.createAwsService(Schemas, undefined, this.regionCode)
private createSdkClient(): SchemasClient {
return globals.sdkClientBuilderV3.createAwsService({
serviceClient: SchemasClient,
clientOptions: { region: this.regionCode },
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import assert from 'assert'
import * as path from 'path'
import * as vscode from 'vscode'

import { Schemas } from 'aws-sdk'
import {
DescribeCodeBindingResponse,
GetCodeBindingSourceResponse,
PutCodeBindingResponse,
} from '@aws-sdk/client-schemas'
import * as sinon from 'sinon'

import {
Expand Down Expand Up @@ -61,8 +65,8 @@ describe('CodeDownloader', function () {

describe('codeDownloader', async function () {
it('should return an error if the response body is not Buffer', async function () {
const response: Schemas.GetCodeBindingSourceResponse = {
Body: 'Invalied body',
const response: GetCodeBindingSourceResponse = {
Body: 'Invalied body' as any,
}
sandbox.stub(schemaClient, 'getCodeBindingSource').returns(Promise.resolve(response))

Expand All @@ -75,8 +79,8 @@ describe('CodeDownloader', function () {

it('should return arrayBuffer for valid Body type', async function () {
const myBuffer = Buffer.from('TEST STRING')
const response: Schemas.GetCodeBindingSourceResponse = {
Body: myBuffer,
const response: GetCodeBindingSourceResponse = {
Body: myBuffer as any,
}

sandbox.stub(schemaClient, 'getCodeBindingSource').returns(Promise.resolve(response))
Expand Down Expand Up @@ -148,7 +152,7 @@ describe('CodeGenerator', function () {

describe('codeGenerator', async function () {
it('should return the current status of code generation', async function () {
const response: Schemas.PutCodeBindingResponse = {
const response: PutCodeBindingResponse = {
Status: CodeGenerationStatus.CREATE_IN_PROGRESS,
}
sandbox.stub(schemaClient, 'putCodeBinding').returns(Promise.resolve(response))
Expand All @@ -164,7 +168,7 @@ describe('CodeGenerator', function () {
// If code bindings were not generated, but putCodeBinding was already called, ConflictException occurs
// Return CREATE_IN_PROGRESS and keep polling in this case
it('should return valid code generation status if it gets ConflictException', async function () {
const response: Schemas.PutCodeBindingResponse = {
const response: PutCodeBindingResponse = {
Status: CodeGenerationStatus.CREATE_IN_PROGRESS,
}

Expand Down Expand Up @@ -224,10 +228,10 @@ describe('CodeGeneratorStatusPoller', function () {

describe('getCurrentStatus', async function () {
it('should return the current status of code generation', async function () {
const firstStatus: Schemas.DescribeCodeBindingResponse = {
const firstStatus: DescribeCodeBindingResponse = {
Status: CodeGenerationStatus.CREATE_IN_PROGRESS,
}
const secondStatus: Schemas.DescribeCodeBindingResponse = {
const secondStatus: DescribeCodeBindingResponse = {
Status: CodeGenerationStatus.CREATE_COMPLETE,
}

Expand All @@ -245,7 +249,7 @@ describe('CodeGeneratorStatusPoller', function () {

describe('codeGeneratorStatusPoller', async function () {
it('fails if code generation status is invalid without retry', async function () {
const schemaResponse: Schemas.DescribeCodeBindingResponse = {
const schemaResponse: DescribeCodeBindingResponse = {
Status: CodeGenerationStatus.CREATE_FAILED,
}

Expand All @@ -266,7 +270,7 @@ describe('CodeGeneratorStatusPoller', function () {
})

it('times out after max attempts if status is still in progress', async function () {
const schemaResponse: Schemas.DescribeCodeBindingResponse = {
const schemaResponse: DescribeCodeBindingResponse = {
Status: CodeGenerationStatus.CREATE_IN_PROGRESS,
}

Expand All @@ -290,7 +294,7 @@ describe('CodeGeneratorStatusPoller', function () {
})

it('succeeds when code is previously generated without retry', async function () {
const schemaResponse: Schemas.DescribeCodeBindingResponse = {
const schemaResponse: DescribeCodeBindingResponse = {
Status: CodeGenerationStatus.CREATE_COMPLETE,
}

Expand Down Expand Up @@ -402,7 +406,7 @@ describe('SchemaCodeDownload', function () {
it('should generate code if download fails with ResourceNotFound and place it into requested directory', async function () {
sandbox.stub(poller, 'pollForCompletion').returns(Promise.resolve('CREATE_COMPLETE'))
const codeDownloaderStub = sandbox.stub(downloader, 'download')
const codeGeneratorResponse: Schemas.PutCodeBindingResponse = {
const codeGeneratorResponse: PutCodeBindingResponse = {
Status: 'CREATE_IN_PROGRESS',
}
sandbox.stub(generator, 'generate').returns(Promise.resolve(codeGeneratorResponse))
Expand Down
Loading
Loading