open-index/open-npm huggingface dataset:
npm package: @millihq/etag-cache
Description: Simple in-memory caching solution that supports revalidation via eTag and time-to-live (TTL)
Latest version: 1.1.0

# eTag cache

Simple in-memory caching solution that supports revalidation via eTag and time-to-live (TTL).

## Usage

```ts
import { ETagCache } from '@millihq/etag-cache';

async function revalidateHandler(key: string, eTag?: string) {
  if (eTag === '123') {
    // When the item of the cached item has not changed, you can simply return
    // the eTag and the expiration of the item in the cache gets updated.
    return {
      eTag: '123',
    };
  }

  return {
    item: 'bar',
    eTag: '123',
  };
}

const cache = ETagCache(60 /* TTL in seconds */, revalidateHandler);

const item = await cache.get('foo');
// => bar
```

## Architecture

The cache is designed with a focus on reading performance.
Expired items are only purged from the cache when new items are added to the cache.

```mermaid
sequenceDiagram
Client->>ETag Cache: get('foo')
ETag Cache->>TTL Cache: get('foo')
TTL Cache-->>ETag Cache: { item: 'bar', expired: true/false } | null
alt doesn't exist
  ETag Cache->>Client: Call revalidateHandler(key)
  Client-->>ETag Cache: { item: 'bar', eTag: '123' }
  ETag Cache->>TTL Cache: set('foo', 'bar')
else is expired
 ETag Cache->>Client: Call revalidateHandler(key, eTag)
 Client-->>ETag Cache: { eTag: '123' }
 ETag Cache->>TTL Cache: updateTTL('foo')
end
ETag Cache-->>Client: 'bar'
```

## About

This project is maintained by [milliVolt infrastructure](https://milli.is).  
We build custom infrastructure solutions for any cloud provider.

## License

Apache-2.0 - see [LICENSE](https://github.com/milliHQ/pixel/tree/main/LICENSE) for details.
npm package: @millihq/pixel-core
Description: This is the core package of [Pixel for Next.js](https://github.com/milliHQ/pixel). It is a small wrapper that extracts the image-optimization functionality of Next.js and makes it usable without starting the whole Next.js server.
Latest version: 5.1.0

# Pixel for Next.js - Core

This is the core package of [Pixel for Next.js](https://github.com/milliHQ/pixel).
It is a small wrapper that extracts the image-optimization functionality of Next.js and makes it usable without starting the whole Next.js server.

## Installation

Install the package `@millihq/pixel-core` with your favorite package manager.  
You also need to install [`next`](https://www.npmjs.com/package/next) and its peer dependencies [`react`](https://www.npmjs.com/package/react) and [`react-dom`](https://www.npmjs.com/package/react-dom).

By default [squoosh](https://github.com/GoogleChromeLabs/squoosh) is used as image optimization engine (Next.js default).  
If you want to use [sharp](https://github.com/lovell/sharp) instead, you have to install it as an additional dependency.

```sh
npm i @millihq/pixel-core next react react-dom        # squoosh
npm i @millihq/pixel-core next react react-dom sharp  # sharp
```

### `fetch` usage

Under the hood, Next.js needs global `fetch` available to request the image from the original source.
The module polyfills it with `node-fetch` if it is not available.

If you are using a Node.js version `< 18` you should also add it as peer dependency:

```sh
npm i node-fetch
```

## Usage

Pixel can be integrated with the standard Node.js HTTP request and response model.

```ts
import { readFileSync } from 'fs';
import http, { IncomingMessage, ServerResponse } from 'http';
import { parse as parseUrl } from 'url';

import { Pixel } from '@millihq/pixel-core';

const pixel = new Pixel({
  async requestHandler(req, res) {
    // Load images here that are requested from an absolute path, e.g.
    //
    // /my-image.png
    // => http:localhost:3000/_next/image?w=512&q=75&url=%2Fmy-image.png
    res.write(readFileSync('my-image.png'));
    res.end();
  },
  // Customize the behavior of the image optimizer by providing a custom
  // config, see: https://nextjs.org/docs/api-reference/next/image#advanced
  imageConfig: {
    ...
  },
});

async function listener(req: IncomingMessage, res: ServerResponse) {
  const url = parseUrl(req.url!, true);
  const result = await pixel.imageOptimizer(req, res, url);

  if ('error' in result) {
    res.statusCode = result.statusCode;
    res.end(result.error);
    return;
  }

  res.setHeader('Content-Type', result.contentType);
  res.setHeader('Cache-Control', `public, max-age=${result.maxAge}`);
  res.end(result.buffer);
}

const server = http.createServer(listener);
server.listen(3000);
```

## About

This project is maintained by [milliVolt infrastructure](https://milli.is).  
We build custom infrastructure solutions for any cloud provider.

## License

Apache-2.0 - see [LICENSE](https://github.com/milliHQ/pixel/tree/main/LICENSE) for details.
npm package: @millihq/pixel-express
Description: This is the express middleware package of [Pixel for Next.js](https://github.com/milliHQ/pixel). It enables you to use the image optimizer of Next.js in a express app without starting the whole Next.js server. Useful when you want to provide the image opt
Latest version: 5.1.0

# Pixel for Next.js - express middleware

This is the express middleware package of [Pixel for Next.js](https://github.com/milliHQ/pixel).
It enables you to use the image optimizer of Next.js in a express app without starting the whole Next.js server.
Useful when you want to provide the image optimizer of Next.js as standalone API.

## Installation

Install the package `@millihq/pixel-express` with your favorite package manager.  
You also need to install [`next`](https://www.npmjs.com/package/next) and its peer dependencies [`react`](https://www.npmjs.com/package/react) and [`react-dom`](https://www.npmjs.com/package/react-dom).

By default [squoosh](https://github.com/GoogleChromeLabs/squoosh) is used as image optimization engine (Next.js default).  
If you want to use [sharp](https://github.com/lovell/sharp) instead, you have to install it as an additional dependency.

```sh
npm i @millihq/pixel-express next react react-dom        # squoosh
npm i @millihq/pixel-express next react react-dom sharp  # sharp
```

## Usage

```ts
import { readFileSync } from 'fs';

import express from 'express';
import { pixelExpress } from '@millihq/pixel-express-middleware';

const app = express();

app.get(
  '/next/image',
  pixelExpress({
    async requestHandler(req, res) {
      // Load images here that are requested from an absolute path, e.g.
      //
      // /my-image.png
      // => http:localhost:3000/_next/image?w=512&q=75&url=%2Fmy-image.png
      res.write(readFileSync('my-image.png'));
      res.end();
    },
    // Customize the behavior of the image optimizer by providing a custom
    // config, see: https://nextjs.org/docs/api-reference/next/image#advanced
    imageConfig: {
      ...
    }
  })
);

app.listen(3000);
```

## About

This project is maintained by [milliVolt infrastructure](https://milli.is).  
We build custom infrastructure solutions for any cloud provider.

## License

Apache-2.0 - see [LICENSE](https://github.com/milliHQ/pixel/tree/main/LICENSE) for details.
npm package: @millihq/sammy
Description: A Node.js wrapper for [AWS SAM CLI](https://aws.amazon.com/serverless/sam/) for local testing of Lambda functions.
Latest version: 3.0.0

# Sammy

A Node.js wrapper for [AWS SAM CLI](https://aws.amazon.com/serverless/sam/) for local testing of Lambda functions.

## Usage

```sh
npm i -D @millihq/sammy     # npm
yarn add -D @millihq/sammy  # or yarn
```

Assuming you have a Lambda function with the following content:

```js
// handler.js
exports.handler = async function (event, context) {
  return {
    isBase64Encoded: false,
    statusCode: 200,
    body: 'Hello World!',
    headers: {
      'content-type': 'application/json',
    },
  };
};
```

which is packaged into a compressed zip file called `lambda.zip`.

### Run lambda locally with API-Gateway

You can now start the Lambda function locally and access it through an API-Endpoint:

```ts
import * as path from 'path';

import { generateAPISAM, APISAMGenerator } from '@millihq/sammy';

const lambdaSAM = await generateAPISAM({
  lambdas: {
    first: {
      filename: 'lambda.zip',
      handler: 'handler.handler',
      runtime: 'nodejs16.x',
      route: '/test',
      method: 'get',
    },
  },
  cwd: process.cwd(),
});

const response = await lambdaSAM.sendApiGwRequest('/test');
console.log(await response.text());
// => Hello World!
```

## License

Apache-2.0 - see [LICENSE](./LICENSE) for details.
npm package: @millihq/tf-next-image-optimization
Description: Image optimization component of [Terraform Next.js Image Optimization module for AWS](https://github.com/milliHQ/terraform-aws-next-js-image-optimization).
Latest version: 12.1.3

# Terraform Next.js Image Optimization component

Image optimization component of [Terraform Next.js Image Optimization module for AWS](https://github.com/milliHQ/terraform-aws-next-js-image-optimization).

## License

Apache-2.0 - see [LICENSE](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/blob/main/LICENSE) for details.