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: 1 addition & 1 deletion benches/__shared__/client-server.fetch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ClientServer } from './client-server'
import { toFetchBody, toFetchHeaders, toFetchResponse, toStandardLazyRequest, toStandardLazyResponse } from '@standardserver/fetch'
import { toFetchBody, toFetchHeaders, toFetchResponse, toStandardLazyRequest, toStandardLazyResponse } from '@standard-server/fetch'

export function createFetchClientServer(): ClientServer {
const clientServer: ClientServer = {
Expand Down
4 changes: 2 additions & 2 deletions benches/__shared__/client-server.node.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { AddressInfo } from 'node:net'
import type { ClientServer } from './client-server'
import * as http from 'node:http'
import { toFetchBody, toFetchHeaders, toStandardLazyResponse } from '@standardserver/fetch'
import { sendStandardResponse, toStandardLazyRequest } from '@standardserver/node'
import { toFetchBody, toFetchHeaders, toStandardLazyResponse } from '@standard-server/fetch'
import { sendStandardResponse, toStandardLazyRequest } from '@standard-server/node'

export function createNodeClientServer(): ClientServer {
const clientServer: ClientServer = {
Expand Down
2 changes: 1 addition & 1 deletion benches/__shared__/client-server.peer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ClientServer } from './client-server'
import { ClientPeer, decodePeerMessage, encodePeerMessage, isClientPeerSendMessage, isServerPeerSendMessage, ServerPeer } from '@standardserver/peer'
import { ClientPeer, decodePeerMessage, encodePeerMessage, isClientPeerSendMessage, isServerPeerSendMessage, ServerPeer } from '@standard-server/peer'

export function createPeerClientServer(): ClientServer {
let clientPeer: ClientPeer
Expand Down
4 changes: 2 additions & 2 deletions benches/__shared__/client-server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { StandardLazyRequest, StandardLazyResponse, StandardRequest, StandardResponse } from '@standardserver/core'
import { isAsyncIteratorObject } from '@standardserver/shared'
import type { StandardLazyRequest, StandardLazyResponse, StandardRequest, StandardResponse } from '@standard-server/core'
import { isAsyncIteratorObject } from '@standard-server/shared'

export interface ClientServer {
handler: (request: StandardLazyRequest) => Promise<StandardResponse>
Expand Down
2 changes: 1 addition & 1 deletion benches/__shared__/payloads.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stringifyJSON } from '@standardserver/shared'
import { stringifyJSON } from '@standard-server/shared'

const SIZE_1KB = 1024
const SIZE_10KB = 10 * SIZE_1KB
Expand Down
2 changes: 1 addition & 1 deletion benches/event-stream.bench.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { decodeEventStreamMessage, encodeEventStreamMessage, EventStreamDecoder } from '@standardserver/core'
import { decodeEventStreamMessage, encodeEventStreamMessage, EventStreamDecoder } from '@standard-server/core'
import { bench, describe } from 'vitest'

const SIZE_1KB = 1024
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@standardserver/repo",
"name": "@standard-server/repo",
"type": "module",
"version": "0.8.3",
"private": true,
Expand Down Expand Up @@ -27,12 +27,12 @@
"@codspeed/vitest-plugin": "^5.7.1",
"@hono/node-server": "^2.0.12",
"@remix-run/node-fetch-server": "^0.14.0",
"@standardserver/core": "workspace:*",
"@standardserver/fastify": "workspace:*",
"@standardserver/fetch": "workspace:*",
"@standardserver/node": "workspace:*",
"@standardserver/peer": "workspace:*",
"@standardserver/shared": "workspace:*",
"@standard-server/core": "workspace:*",
"@standard-server/fastify": "workspace:*",
"@standard-server/fetch": "workspace:*",
"@standard-server/node": "workspace:*",
"@standard-server/peer": "workspace:*",
"@standard-server/shared": "workspace:*",
"@types/express": "^5.0.6",
"@types/node": "^26.4.1",
"@types/ws": "^8.18.1",
Expand Down
50 changes: 25 additions & 25 deletions packages/aws-lambda/README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
# @standardserver/aws-lambda
# @standard-server/aws-lambda

<div align="center">
<a href="https://codecov.io/gh/middleapi/standardserver">
<img alt="codecov" src="https://codecov.io/gh/middleapi/standardserver/branch/main/graph/badge.svg">
<a href="https://codecov.io/gh/middleapi/standard-server">
<img alt="codecov" src="https://codecov.io/gh/middleapi/standard-server/branch/main/graph/badge.svg">
</a>
<a href="https://www.npmjs.com/package/@standardserver/aws-lambda">
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40standardserver%2Faws-lambda?logo=npm" />
<a href="https://www.npmjs.com/package/@standard-server/aws-lambda">
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40standard-server%2Faws-lambda?logo=npm" />
</a>
<a href="https://app.codspeed.io/middleapi/standardserver?utm_source=badge">
<a href="https://app.codspeed.io/middleapi/standard-server?utm_source=badge">
<img src="https://img.shields.io/endpoint?url=https://codspeed.io/badge.json" alt="CodSpeed" />
</a>
<a href="https://github.com/middleapi/standardserver/blob/main/LICENSE">
<img alt="MIT License" src="https://img.shields.io/github/license/middleapi/standardserver?logo=open-source-initiative" />
<a href="https://github.com/middleapi/standard-server/blob/main/LICENSE">
<img alt="MIT License" src="https://img.shields.io/github/license/middleapi/standard-server?logo=open-source-initiative" />
</a>
<a href="https://discord.gg/TXEbwRBvQn">
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
</a>
<a href="https://deepwiki.com/middleapi/standardserver">
<a href="https://deepwiki.com/middleapi/standard-server">
<img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki">
</a>
</div>

`@standardserver/aws-lambda` adapts AWS Lambda events and response streams to the transport-agnostic request and response model defined by Standard Server.
`@standard-server/aws-lambda` adapts AWS Lambda events and response streams to the transport-agnostic request and response model defined by Standard Server.

Standard Server provides a unified interface for client-server communication across HTTP and message-based transports. It lets you write handlers against the same request, response, body, and streaming primitives whether the underlying transport is the Fetch API, Node.js HTTP, HTTP/2, or a peer-style message channel.

Standard Server ships as a small ecosystem of packages:

| Package | Description |
| ------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
| [`@standardserver/core`](https://github.com/middleapi/standardserver/blob/main/packages/core/README.md) | The shared contract: types, body parsing rules, validators, and SSE helpers |
| [`@standardserver/fetch`](https://github.com/middleapi/standardserver/blob/main/packages/fetch/README.md) | Fetch API adapter for browsers, workers, and other Fetch-based runtimes |
| [`@standardserver/node`](https://github.com/middleapi/standardserver/blob/main/packages/node/README.md) | Node.js HTTP and HTTP/2 adapter |
| [`@standardserver/fastify`](https://github.com/middleapi/standardserver/blob/main/packages/fastify/README.md) | Fastify adapter built on the Node.js adapter |
| [`@standardserver/aws-lambda`](https://github.com/middleapi/standardserver/blob/main/packages/aws-lambda/README.md) | AWS Lambda adapter with response streaming |
| [`@standardserver/peer`](https://github.com/middleapi/standardserver/blob/main/packages/peer/README.md) | Message-based adapter for WebSocket, MessagePort, and custom transports |
| [`@standardserver/shared`](https://github.com/middleapi/standardserver/blob/main/packages/shared/README.md) | Internal utilities shared across the ecosystem |
| Package | Description |
| --------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
| [`@standard-server/core`](https://github.com/middleapi/standard-server/blob/main/packages/core/README.md) | The shared contract: types, body parsing rules, validators, and SSE helpers |
| [`@standard-server/fetch`](https://github.com/middleapi/standard-server/blob/main/packages/fetch/README.md) | Fetch API adapter for browsers, workers, and other Fetch-based runtimes |
| [`@standard-server/node`](https://github.com/middleapi/standard-server/blob/main/packages/node/README.md) | Node.js HTTP and HTTP/2 adapter |
| [`@standard-server/fastify`](https://github.com/middleapi/standard-server/blob/main/packages/fastify/README.md) | Fastify adapter built on the Node.js adapter |
| [`@standard-server/aws-lambda`](https://github.com/middleapi/standard-server/blob/main/packages/aws-lambda/README.md) | AWS Lambda adapter with response streaming |
| [`@standard-server/peer`](https://github.com/middleapi/standard-server/blob/main/packages/peer/README.md) | Message-based adapter for WebSocket, MessagePort, and custom transports |
| [`@standard-server/shared`](https://github.com/middleapi/standard-server/blob/main/packages/shared/README.md) | Internal utilities shared across the ecosystem |

This package is the AWS Lambda adapter for that model. It converts an API Gateway proxy event — payload format version 1.0 or 2.0, the latter also used by Lambda Function URLs — into a `StandardLazyRequest`, and writes a `StandardResponse` back through the stream provided by `awslambda.streamifyResponse`, so streaming bodies such as server-sent events flow to the client as they are produced instead of being buffered.

Expand All @@ -56,9 +56,9 @@ The package exposes these helpers:
Use `toStandardLazyRequest()` to convert the incoming event into a `StandardLazyRequest`, then `sendStandardResponse()` to write the resulting `StandardResponse` back through the response stream. The handler must be wrapped with `awslambda.streamifyResponse`, and the function must run on the AWS Lambda Node.js runtime with response streaming enabled.

```ts
import type { AwsLambdaGlobal } from '@standardserver/aws-lambda'
import type { StandardLazyRequest, StandardResponse } from '@standardserver/core'
import { sendStandardResponse, toStandardLazyRequest } from '@standardserver/aws-lambda'
import type { AwsLambdaGlobal } from '@standard-server/aws-lambda'
import type { StandardLazyRequest, StandardResponse } from '@standard-server/core'
import { sendStandardResponse, toStandardLazyRequest } from '@standard-server/aws-lambda'

// injected by the AWS Lambda Node.js runtime when response streaming is enabled
declare const awslambda: AwsLambdaGlobal
Expand Down Expand Up @@ -93,7 +93,7 @@ export const handler = awslambda.streamifyResponse(async (event, responseStream,

## Resolving Body

The event carries the request body as a fully buffered, optionally base64-encoded string. `resolveBody(hint?)` decodes it and then follows the shared Standard Server resolution rules: an explicit `hint` wins, then the [`standard-server` header](https://github.com/middleapi/standardserver/blob/main/packages/core/README.md#the-standard-server-header), then inference from the content headers. See [how body parsing works](https://github.com/middleapi/standardserver/blob/main/packages/core/README.md#how-body-parsing-works) in the core README for the full algorithm.
The event carries the request body as a fully buffered, optionally base64-encoded string. `resolveBody(hint?)` decodes it and then follows the shared Standard Server resolution rules: an explicit `hint` wins, then the [`standard-server` header](https://github.com/middleapi/standard-server/blob/main/packages/core/README.md#the-standard-server-header), then inference from the content headers. See [how body parsing works](https://github.com/middleapi/standard-server/blob/main/packages/core/README.md#how-body-parsing-works) in the core README for the full algorithm.

> [!TIP]
> For efficient communication, set the `standard-server` header to explicitly hint the body type, especially for file or binary streaming. For example, if you upload a file with a common `content-type` such as `application/json` but omit the `standard-server` header, the server may interpret it as JSON and parse it unexpectedly.
Expand All @@ -108,7 +108,7 @@ The event carries the request body as a fully buffered, optionally base64-encode

## Learn more

For the project overview and the shared contract, see the [core documentation](https://github.com/middleapi/standardserver/blob/main/packages/core/README.md). For the Node.js primitives this adapter is built on, see the [Node.js adapter documentation](https://github.com/middleapi/standardserver/blob/main/packages/node/README.md).
For the project overview and the shared contract, see the [core documentation](https://github.com/middleapi/standard-server/blob/main/packages/core/README.md). For the Node.js primitives this adapter is built on, see the [Node.js adapter documentation](https://github.com/middleapi/standard-server/blob/main/packages/node/README.md).

## Sponsors

Expand Down Expand Up @@ -196,4 +196,4 @@ With thanks to [36 past sponsors](https://htmlpreview.github.io/?https://github.

## License

Distributed under the MIT License. See [LICENCE](https://github.com/middleapi/standardserver/blob/main/LICENCE) for more information.
Distributed under the MIT License. See [LICENCE](https://github.com/middleapi/standard-server/blob/main/LICENCE) for more information.
15 changes: 7 additions & 8 deletions packages/aws-lambda/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@standardserver/aws-lambda",
"name": "@standard-server/aws-lambda",
"type": "module",
"version": "0.8.3",
"description": "AWS Lambda adapter for Standard Server: transport-agnostic requests and responses with Lambda response streaming support",
Expand All @@ -8,14 +8,13 @@
"https://github.com/sponsors/dinwwwh",
"https://opencollective.com/middleapi"
],
"homepage": "https://standardserver.dev",
"repository": {
"type": "git",
"url": "git+https://github.com/middleapi/standardserver.git",
"url": "git+https://github.com/middleapi/standard-server.git",
"directory": "packages/aws-lambda"
},
"keywords": [
"standardserver",
"standard-server",
"aws",
"lambda",
"aws-lambda",
Expand Down Expand Up @@ -51,10 +50,10 @@
"type:check": "tsc -b"
},
"dependencies": {
"@standardserver/core": "workspace:*",
"@standardserver/fetch": "workspace:*",
"@standardserver/node": "workspace:*",
"@standardserver/shared": "workspace:*"
"@standard-server/core": "workspace:*",
"@standard-server/fetch": "workspace:*",
"@standard-server/node": "workspace:*",
"@standard-server/shared": "workspace:*"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.162",
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-lambda/src/body.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AsyncIteratorClass } from '@standardserver/shared'
import type { AsyncIteratorClass } from '@standard-server/shared'
import type { APIGatewayProxyEvent } from './types'
import { Buffer } from 'node:buffer'
import { toStandardBody } from './body'
Expand Down
8 changes: 4 additions & 4 deletions packages/aws-lambda/src/body.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { StandardBody, StandardBodyHint } from '@standardserver/core'
import type { StandardBody, StandardBodyHint } from '@standard-server/core'
import type { AnyAPIGatewayProxyEvent } from './types'
import { Buffer } from 'node:buffer'
import { flattenStandardHeader, getFilenameFromContentDisposition, resolveStandardBodyHint } from '@standardserver/core'
import { toAsyncIteratorObject } from '@standardserver/fetch'
import { parseEmptyableJSON } from '@standardserver/shared'
import { flattenStandardHeader, getFilenameFromContentDisposition, resolveStandardBodyHint } from '@standard-server/core'
import { toAsyncIteratorObject } from '@standard-server/fetch'
import { parseEmptyableJSON } from '@standard-server/shared'
import { getEventHeader } from './headers'

export interface ToStandardBodyOptions {
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-lambda/src/headers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { StandardHeaders } from '@standardserver/core'
import type { StandardHeaders } from '@standard-server/core'
import type { AnyAPIGatewayProxyEvent } from './types'
import { toArray } from '@standardserver/shared'
import { toArray } from '@standard-server/shared'

/**
* Convert API Gateway proxy event headers to standard headers.
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-lambda/src/request.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { APIGatewayProxyEvent, APIGatewayProxyEventV2, HttpResponseStream } from './types'
import Stream from 'node:stream'
import * as StandardServerNode from '@standardserver/node'
import * as StandardServerNode from '@standard-server/node'
import * as Body from './body'
import * as Headers from './headers'
import { toStandardLazyRequest } from './request'
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-lambda/src/request.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { StandardLazyRequest } from '@standardserver/core'
import type { StandardLazyRequest } from '@standard-server/core'
import type { AnyAPIGatewayProxyEvent, HttpResponseStream } from './types'
import { toAbortSignal } from '@standardserver/node'
import { toAbortSignal } from '@standard-server/node'
import { toStandardBody } from './body'
import { toStandardHeaders } from './headers'
import { toStandardUrl } from './url'
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-lambda/src/response.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { StandardResponse } from '@standardserver/core'
import type { StandardResponse } from '@standard-server/core'
import type { HttpResponseStream } from './types'
import { Buffer } from 'node:buffer'
import Stream from 'node:stream'
import * as StandardServerNode from '@standardserver/node'
import * as StandardServerNode from '@standard-server/node'
import { sendStandardResponse } from './response'

const toNodeHttpBodySpy = vi.spyOn(StandardServerNode, 'toNodeHttpBody')
Expand Down
6 changes: 3 additions & 3 deletions packages/aws-lambda/src/response.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { StandardResponse } from '@standardserver/core'
import type { ToNodeHttpBodyOptions } from '@standardserver/node'
import type { StandardResponse } from '@standard-server/core'
import type { ToNodeHttpBodyOptions } from '@standard-server/node'
import type { AwsLambdaGlobal, HttpResponseStream } from './types'
import { canWriteToNodeResponse, getNodeResponseError, toNodeHttpBody } from '@standardserver/node'
import { canWriteToNodeResponse, getNodeResponseError, toNodeHttpBody } from '@standard-server/node'
import { toLambdaHeaders } from './headers'

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-lambda/src/url.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { StandardUrl } from '@standardserver/core'
import type { StandardUrl } from '@standard-server/core'
import type { AnyAPIGatewayProxyEvent } from './types'

/**
Expand Down
Loading
Loading