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
2 changes: 2 additions & 0 deletions .changeset/clean-terms-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
4 changes: 3 additions & 1 deletion packages/eventstream-serde-universal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
"format": "prettier --config ../../prettier.config.js --ignore-path ../../.prettierignore --write \"**/*.{ts,md,json}\"",
"test": "yarn g:vitest run",
"test:watch": "yarn g:vitest watch"
"test:watch": "yarn g:vitest watch",
"test:integration": "yarn g:vitest run -c vitest.config.integ.mts",
"test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.mts"
},
"main": "./dist-cjs/index.js",
"module": "./dist-es/index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { cbor, dateToTag } from "@smithy/core/cbor";
import { HttpResponse } from "@smithy/protocol-http";
import { requireRequestsFrom } from "@smithy/util-test/src";
import { Readable } from "node:stream";
import { describe, expect, test as it } from "vitest";
import { XYZService } from "xyz";

describe("local model integration test for cbor eventstreams", () => {
it("should read and write cbor event streams", async () => {
const client = new XYZService({
endpoint: "https://localhost",
});

const body = cbor.serialize({
id: "alpha",
timestamp: dateToTag(new Date(0)),
});

function toInt32(n: number): number[] {
const uint32 = new Uint8Array(4);
const dv = new DataView(uint32.buffer, 0, 4);
dv.setUint32(0, n);
return [...uint32];
}

requireRequestsFrom(client)
.toMatch({
hostname: /localhost/,
async body(body) {
const outgoing = [];
for await (const chunk of body) {
outgoing.push(chunk);
}
expect(outgoing).toEqual([
new Uint8Array([
0, 0, 0, 101, 0, 0, 0, 75, 213, 254, 191, 76, 11, 58, 101, 118, 101, 110, 116, 45, 116, 121, 112, 101, 7,
0, 5, 97, 108, 112, 104, 97, 13, 58, 109, 101, 115, 115, 97, 103, 101, 45, 116, 121, 112, 101, 7, 0, 5,
101, 118, 101, 110, 116, 13, 58, 99, 111, 110, 116, 101, 110, 116, 45, 116, 121, 112, 101, 7, 0, 16, 97,
112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 47, 99, 98, 111, 114, 161, 98, 105, 100, 101, 97, 108,
112, 104, 97, 32, 93, 69, 236,
]),
new Uint8Array([
0, 0, 0, 91, 0, 0, 0, 74, 188, 232, 137, 61, 11, 58, 101, 118, 101, 110, 116, 45, 116, 121, 112, 101, 7,
0, 4, 98, 101, 116, 97, 13, 58, 109, 101, 115, 115, 97, 103, 101, 45, 116, 121, 112, 101, 7, 0, 5, 101,
118, 101, 110, 116, 13, 58, 99, 111, 110, 116, 101, 110, 116, 45, 116, 121, 112, 101, 7, 0, 16, 97, 112,
112, 108, 105, 99, 97, 116, 105, 111, 110, 47, 99, 98, 111, 114, 160, 195, 209, 62, 47,
]),
new Uint8Array([
0, 0, 0, 91, 0, 0, 0, 74, 188, 232, 137, 61, 11, 58, 101, 118, 101, 110, 116, 45, 116, 121, 112, 101, 7,
0, 4, 98, 101, 116, 97, 13, 58, 109, 101, 115, 115, 97, 103, 101, 45, 116, 121, 112, 101, 7, 0, 5, 101,
118, 101, 110, 116, 13, 58, 99, 111, 110, 116, 101, 110, 116, 45, 116, 121, 112, 101, 7, 0, 16, 97, 112,
112, 108, 105, 99, 97, 116, 105, 111, 110, 47, 99, 98, 111, 114, 160, 195, 209, 62, 47,
]),
new Uint8Array(),
]);
},
})
.respondWith(
new HttpResponse({
statusCode: 200,
headers: {
"smithy-protocol": "rpc-v2-cbor",
},
body: Readable.from({
async *[Symbol.asyncIterator]() {
yield new Uint8Array([
/* message size */ ...toInt32(91 + body.byteLength),
/* header size */ ...toInt32(75),
/* prelude crc */ ...toInt32(1084132878),
/* headers */
/* :event-type */
11,
...[58, 101, 118, 101, 110, 116, 45, 116, 121, 112, 101],
7,
/* alpha */
0,
5,
...[97, 108, 112, 104, 97],
/* :content-type */
13,
...[58, 99, 111, 110, 116, 101, 110, 116, 45, 116, 121, 112, 101],
7,
/* application/cbor */
0,
16,
...[97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 47, 99, 98, 111, 114],
/* :message-type */
13,
...[58, 109, 101, 115, 115, 97, 103, 101, 45, 116, 121, 112, 101],
7,
/* event */
0,
5,
...[101, 118, 101, 110, 116],

/* body */
...body,

/* message crc */
...toInt32(1938836882),
]);
},
}),
})
);

const response = await client.tradeEventStream({
eventStream: {
async *[Symbol.asyncIterator]() {
yield {
alpha: {
id: "alpha",
},
};
yield {
beta: {},
};
yield {
gamma: {},
};
},
},
});

const responses = [] as any[];
for await (const event of response.eventStream ?? []) {
responses.push(event);
}

expect(responses).toEqual([
{
alpha: {
id: "alpha",
timestamp: new Date(0),
},
},
]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
include: ["**/*.integ.spec.ts"],
environment: "node",
},
});
3 changes: 3 additions & 0 deletions private/my-local-model/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"@aws-sdk/types": "latest",
"@smithy/config-resolver": "workspace:^",
"@smithy/core": "workspace:^",
"@smithy/eventstream-serde-browser": "workspace:^",
"@smithy/eventstream-serde-config-resolver": "workspace:^",
"@smithy/eventstream-serde-node": "workspace:^",
"@smithy/fetch-http-handler": "workspace:^",
"@smithy/hash-node": "workspace:^",
"@smithy/invalid-dependency": "workspace:^",
Expand Down
24 changes: 24 additions & 0 deletions private/my-local-model/src/XYZService.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
// smithy-typescript generated code
import { XYZServiceClient, XYZServiceClientConfig } from "./XYZServiceClient";
import { GetNumbersCommand, GetNumbersCommandInput, GetNumbersCommandOutput } from "./commands/GetNumbersCommand";
import {
TradeEventStreamCommand,
TradeEventStreamCommandInput,
TradeEventStreamCommandOutput,
} from "./commands/TradeEventStreamCommand";
import { createAggregatedClient } from "@smithy/smithy-client";
import { HttpHandlerOptions as __HttpHandlerOptions } from "@smithy/types";

const commands = {
GetNumbersCommand,
TradeEventStreamCommand,
};

export interface XYZService {
Expand All @@ -20,6 +26,24 @@ export interface XYZService {
options: __HttpHandlerOptions,
cb: (err: any, data?: GetNumbersCommandOutput) => void
): void;

/**
* @see {@link TradeEventStreamCommand}
*/
tradeEventStream(): Promise<TradeEventStreamCommandOutput>;
tradeEventStream(
args: TradeEventStreamCommandInput,
options?: __HttpHandlerOptions
): Promise<TradeEventStreamCommandOutput>;
tradeEventStream(
args: TradeEventStreamCommandInput,
cb: (err: any, data?: TradeEventStreamCommandOutput) => void
): void;
tradeEventStream(
args: TradeEventStreamCommandInput,
options: __HttpHandlerOptions,
cb: (err: any, data?: TradeEventStreamCommandOutput) => void
): void;
}

/**
Expand Down
25 changes: 20 additions & 5 deletions private/my-local-model/src/XYZServiceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
resolveHttpAuthSchemeConfig,
} from "./auth/httpAuthSchemeProvider";
import { GetNumbersCommandInput, GetNumbersCommandOutput } from "./commands/GetNumbersCommand";
import { TradeEventStreamCommandInput, TradeEventStreamCommandOutput } from "./commands/TradeEventStreamCommand";
import {
ClientInputEndpointParameters,
ClientResolvedEndpointParameters,
Expand All @@ -19,6 +20,11 @@ import {
getHttpAuthSchemeEndpointRuleSetPlugin,
getHttpSigningPlugin,
} from "@smithy/core";
import {
EventStreamSerdeInputConfig,
EventStreamSerdeResolvedConfig,
resolveEventStreamSerdeConfig,
} from "@smithy/eventstream-serde-config-resolver";
import { getContentLengthPlugin } from "@smithy/middleware-content-length";
import {
EndpointInputConfig,
Expand All @@ -42,6 +48,7 @@ import {
ChecksumConstructor as __ChecksumConstructor,
Decoder as __Decoder,
Encoder as __Encoder,
EventStreamSerdeProvider as __EventStreamSerdeProvider,
HashConstructor as __HashConstructor,
HttpHandlerOptions as __HttpHandlerOptions,
Logger as __Logger,
Expand All @@ -55,12 +62,12 @@ export { __Client };
/**
* @public
*/
export type ServiceInputTypes = GetNumbersCommandInput;
export type ServiceInputTypes = GetNumbersCommandInput | TradeEventStreamCommandInput;

/**
* @public
*/
export type ServiceOutputTypes = GetNumbersCommandOutput;
export type ServiceOutputTypes = GetNumbersCommandOutput | TradeEventStreamCommandOutput;

/**
* @public
Expand Down Expand Up @@ -154,6 +161,11 @@ export interface ClientDefaults extends Partial<__SmithyConfiguration<__HttpHand
*/
extensions?: RuntimeExtension[];

/**
* The function that provides necessary utilities for generating and parsing event stream
*/
eventStreamSerdeProvider?: __EventStreamSerdeProvider;

/**
* The {@link @smithy/smithy-client#DefaultsMode} that will be used to determine how certain default configuration options are resolved in the SDK.
*/
Expand All @@ -168,6 +180,7 @@ export type XYZServiceClientConfigType = Partial<__SmithyConfiguration<__HttpHan
RetryInputConfig &
EndpointInputConfig<EndpointParameters> &
EndpointRequiredInputConfig &
EventStreamSerdeInputConfig &
HttpAuthSchemeInputConfig &
ClientInputEndpointParameters;
/**
Expand All @@ -186,6 +199,7 @@ export type XYZServiceClientResolvedConfigType = __SmithyResolvedConfiguration<_
RetryResolvedConfig &
EndpointResolvedConfig<EndpointParameters> &
EndpointRequiredResolvedConfig &
EventStreamSerdeResolvedConfig &
HttpAuthSchemeResolvedConfig &
ClientResolvedEndpointParameters;
/**
Expand Down Expand Up @@ -218,9 +232,10 @@ export class XYZServiceClient extends __Client<
let _config_2 = resolveRetryConfig(_config_1);
let _config_3 = resolveEndpointConfig(_config_2);
let _config_4 = resolveEndpointRequiredConfig(_config_3);
let _config_5 = resolveHttpAuthSchemeConfig(_config_4);
let _config_6 = resolveRuntimeExtensions(_config_5, configuration?.extensions || []);
this.config = _config_6;
let _config_5 = resolveEventStreamSerdeConfig(_config_4);
let _config_6 = resolveHttpAuthSchemeConfig(_config_5);
let _config_7 = resolveRuntimeExtensions(_config_6, configuration?.extensions || []);
this.config = _config_7;
this.middlewareStack.use(getRetryPlugin(this.config));
this.middlewareStack.use(getContentLengthPlugin(this.config));
this.middlewareStack.use(
Expand Down
Loading