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
4 changes: 4 additions & 0 deletions notNeededPackages.json
Original file line number Diff line number Diff line change
Expand Up @@ -6455,6 +6455,10 @@
"libraryName": "sendgrid",
"asOfVersion": "4.3.0"
},
"seneca": {
"libraryName": "seneca",
"asOfVersion": "3.31.1"
},
"sentence-case": {
"libraryName": "sentence-case",
"asOfVersion": "1.1.3"
Expand Down
17 changes: 17 additions & 0 deletions types/aws-lambda/aws-lambda-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,20 @@ const mixedUntypedCallbackTypedHandler: CustomHandler = (
context: AWSLambda.Context,
cb: AWSLambda.Callback,
) => {};

// Test streamifyResponse
const streamifyResponseHandler: AWSLambda.StreamifyHandler = (event, responseStream, context) => {
const metadata = {
statusCode: 200,
headers: {
"Content-Type": "application/json",
"CustomHeader": "outerspace",
},
};
responseStream = awslambda.HttpResponseStream.from(responseStream, metadata);
responseStream.setContentType("text/plain");
responseStream.write("Hello, world!");
responseStream.end();
};

awslambda.streamifyResponse(streamifyResponseHandler);
95 changes: 95 additions & 0 deletions types/aws-lambda/handler.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Writable } from "node:stream";
/**
* The interface that AWS Lambda will invoke your handler with.
* There are more specialized types for many cases where AWS services
Expand Down Expand Up @@ -170,3 +171,97 @@ export interface ClientContextEnv {
* Pass `null` or `undefined` for the `error` parameter to use this parameter.
*/
export type Callback<TResult = any> = (error?: Error | string | null, result?: TResult) => void;

/**
* Interface for using response streaming from AWS Lambda.
* To indicate to the runtime that Lambda should stream your function’s responses, you must wrap your function handler with the `awslambda.streamifyResponse()` decorator.
*
* The `streamifyResponse` decorator accepts the following additional parameter, `responseStream`, besides the default node handler parameters, `event`, and `context`.
* The new `responseStream` object provides a stream object that your function can write data to. Data written to this stream is sent immediately to the client. You can optionally set the Content-Type header of the response to pass additional metadata to your client about the contents of the stream.
*
* {@link https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/ AWS blog post}
* {@link https://docs.aws.amazon.com/lambda/latest/dg/config-rs-write-functions.html AWS documentation}
*
* @example <caption>Writing to the response stream</caption>
* import 'aws-lambda';
*
* export const handler = awslambda.streamifyResponse(
* async (event, responseStream, context) => {
* responseStream.setContentType("text/plain");
* responseStream.write("Hello, world!");
* responseStream.end();
* }
* );
*
* @example <caption>Using pipeline</caption>
* import 'aws-lambda';
* import { Readable } from 'stream';
* import { pipeline } from 'stream/promises';
* import zlib from 'zlib';
*
* export const handler = awslambda.streamifyResponse(
* async (event, responseStream, context) => {
* // As an example, convert event to a readable stream.
* const requestStream = Readable.from(Buffer.from(JSON.stringify(event)));
*
* await pipeline(requestStream, zlib.createGzip(), responseStream);
* }
* );
*/
export type StreamifyHandler<TEvent = any, TResult = any> = (
event: TEvent,
responseStream: awslambda.HttpResponseStream,
context: Context,
) => TResult | Promise<TResult>;

declare global {
namespace awslambda {
class HttpResponseStream extends Writable {
static from(
writable: Writable,
metadata: Record<string, unknown>,
): HttpResponseStream;
setContentType: (contentType: string) => void;
}

/**
* Decorator for using response streaming from AWS Lambda.
* To indicate to the runtime that Lambda should stream your function’s responses, you must wrap your function handler with the `awslambda.streamifyResponse()` decorator.
*
* The `streamifyResponse` decorator accepts the following additional parameter, `responseStream`, besides the default node handler parameters, `event`, and `context`.
* The new `responseStream` object provides a stream object that your function can write data to. Data written to this stream is sent immediately to the client. You can optionally set the Content-Type header of the response to pass additional metadata to your client about the contents of the stream.
*
* {@link https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/ AWS blog post}
* {@link https://docs.aws.amazon.com/lambda/latest/dg/config-rs-write-functions.html AWS documentation}
*
* @example <caption>Writing to the response stream</caption>
* import 'aws-lambda';
*
* export const handler = awslambda.streamifyResponse(
* async (event, responseStream, context) => {
* responseStream.setContentType("text/plain");
* responseStream.write("Hello, world!");
* responseStream.end();
* }
* );
*
* @example <caption>Using pipeline</caption>
* import 'aws-lambda';
* import { Readable } from 'stream';
* import { pipeline } from 'stream/promises';
* import zlib from 'zlib';
*
* export const handler = awslambda.streamifyResponse(
* async (event, responseStream, context) => {
* // As an example, convert event to a readable stream.
* const requestStream = Readable.from(Buffer.from(JSON.stringify(event)));
*
* await pipeline(requestStream, zlib.createGzip(), responseStream);
* }
* );
*/
function streamifyResponse<TEvent = any, TResult = void>(
handler: StreamifyHandler<TEvent, TResult>,
): StreamifyHandler<TEvent, TResult>;
}
}
File renamed without changes.
34 changes: 34 additions & 0 deletions types/certstream/certstream-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import CertStreamClient from "certstream";

// $ExpectType typeof CertStreamClient
CertStreamClient;

new CertStreamClient(
(message, context) => {
// $ExpectType any
message;
// $ExpectType any
context;
},
);

new CertStreamClient(
(message, context) => {
// $ExpectType any
message;
// $ExpectType any
context;
},
true,
);

declare let client: CertStreamClient;

// $ExpectType Callback
client.callback;
// $ExpectType any
client.context;
// $ExpectType boolean
client.skipHeartbeats;
// $ExpectType void
client.connect();
16 changes: 16 additions & 0 deletions types/certstream/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
declare namespace CertStreamClient {
type Callback = (message: any, context: any) => void;
}

declare class CertStreamClient {
context: any;
callback: CertStreamClient.Callback;
skipHeartbeats: boolean;

constructor(callback: CertStreamClient.Callback, skipHeartbeats?: boolean);

connect(url?: string): void;
}

export = CertStreamClient;
export as namespace CertStreamClient;
17 changes: 17 additions & 0 deletions types/certstream/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"private": true,
"name": "@types/certstream",
"version": "1.1.9999",
"projects": [
"https://github.com/CaliDog/certstream-js#readme"
],
"devDependencies": {
"@types/certstream": "workspace:."
},
"owners": [
{
"name": "Jimmy Leung",
"githubUsername": "hkleungai"
}
]
}
7 changes: 3 additions & 4 deletions types/seneca/tsconfig.json → types/certstream/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
"compilerOptions": {
"module": "node16",
"lib": [
"es6",
"dom"
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"seneca-tests.ts"
"certstream-tests.ts"
]
}
8 changes: 0 additions & 8 deletions types/seneca/.eslintrc.json

This file was deleted.

Loading