open-index/open-npm huggingface dataset:
npm package: @openmicrostep/tests
Description: This is a very simple javascript testing tool that brings microstep declarative test definition and execution to Javascript.
Author: OpenMicroStep
Latest version: 0.1.6

# MSTests for Javascript

This is a very simple javascript testing tool that brings microstep declarative test definition and execution to Javascript.

Install: `npm install @openmicrostep/tests`

Each test module declare a name and either a test function or a list of test modules.
Named function can be directly used as test module.

If a test function takes one parameter, it's considered asynchronous and the first argument will be a _Flux_ as defined in _@openmicrostep/async_ npm module.

Exemple:

```js
module.exports = {
    name: "mytestsuite",
    tests: [
        { name: "my test", test: function() {
            // run mytest
        },
        { name: "my test subs", tests: [ ... ] },
        function direct_named_test() {
            // run direct_named_test
        },
        function direct_async_test(flux) {
            flux.continue();
        }
    ]
}
```
npm package: @openmiddleware/chain
Description: Universal, type-safe middleware framework for any JavaScript runtime
Author: Ersin Koc
Latest version: 1.0.0

# @openmiddleware/chain

Core middleware framework for OpenMiddleware. Universal, type-safe, and zero-dependency.

## Installation

```bash
npm install @openmiddleware/chain
```

## Usage

```typescript
import { createChain, logger, cors, auth } from '@openmiddleware/chain';

const chain = createChain()
  .use(logger({ level: 'info' }))
  .use(cors({ origin: '*' }))
  .use(auth({ jwt: { secret: 'my-secret' } }));

// Execute with a Fetch API Request
const result = await chain.execute(request);

if (result.done) {
  return result.response;
}

// Access state
console.log(result.state.user);
```

## Built-in Middlewares

- `request-id` - Adds unique request ID
- `logger` - Structured logging
- `cors` - Cross-origin resource sharing
- `helmet` - Security headers
- `timeout` - Request timeout
- `error-handler` - Error handling
- `rate-limit` - Rate limiting
- `cache` - Response caching
- `compress` - Response compression
- `body-parser` - Body parsing
- `auth` - JWT, API key, Basic auth
- `validator` - Request validation with built-in schema builder

## Documentation

See [openmiddleware.dev](https://openmiddleware.dev) for full documentation.

## License

MIT
npm package: @openmiddleware/express
Description: Express.js adapter for OpenMiddleware
Author: Ersin Koc
Latest version: 1.0.0

# @openmiddleware/express

Express.js adapter for OpenMiddleware.

## Installation

```bash
npm install @openmiddleware/chain @openmiddleware/express
```

## Usage

```typescript
import express from 'express';
import { createChain, logger, cors, auth } from '@openmiddleware/chain';
import { toExpress } from '@openmiddleware/express';

const app = express();

const chain = createChain()
  .use(logger({ level: 'info' }))
  .use(cors({ origin: '*' }))
  .use(auth({ jwt: { secret: 'my-secret' } }));

// Apply to all routes
app.use(toExpress(chain));

// Or specific routes
app.use('/api/*', toExpress(chain));

app.get('/api/users', (req, res) => {
  // Access state via res.locals.state
  const user = res.locals.state?.user;
  res.json({ users: [] });
});

app.listen(3000);
```

## API

### toExpress(chain)

Converts an OpenMiddleware chain to Express middleware.

- **chain** - OpenMiddleware chain instance
- **returns** - Express middleware function

State is accessible via `res.locals.state`.

## License

MIT
npm package: @openmiddleware/fastify
Description: Fastify adapter for OpenMiddleware
Author: Ersin Koc
Latest version: 1.0.0

# @openmiddleware/fastify

Fastify adapter for OpenMiddleware.

## Installation

```bash
npm install @openmiddleware/chain @openmiddleware/fastify
```

## Usage

```typescript
import Fastify from 'fastify';
import { createChain, logger, cors, auth } from '@openmiddleware/chain';
import { toFastify, fastifyPreHandler } from '@openmiddleware/fastify';

const fastify = Fastify();

const chain = createChain()
  .use(logger({ level: 'info' }))
  .use(cors({ origin: '*' }));

// Register as plugin
fastify.register(toFastify(chain));

// Or use as preHandler for specific routes
const authChain = createChain()
  .use(auth({ jwt: { secret: 'my-secret' } }));

fastify.get('/api/users', {
  preHandler: fastifyPreHandler(authChain),
}, async (request, reply) => {
  const user = request.middlewareState?.user;
  return { users: [] };
});

fastify.listen({ port: 3000 });
```

## API

### toFastify(chain)

Converts an OpenMiddleware chain to a Fastify plugin.

- **chain** - OpenMiddleware chain instance
- **returns** - Fastify plugin

### fastifyPreHandler(chain)

Creates a preHandler hook from an OpenMiddleware chain.

- **chain** - OpenMiddleware chain instance
- **returns** - Fastify preHandler function

State is accessible via `request.middlewareState`.

## License

MIT
npm package: @openmiddleware/hono
Description: Hono adapter for OpenMiddleware
Author: Ersin Koc
Latest version: 1.0.0

# @openmiddleware/hono

Hono adapter for OpenMiddleware.

## Installation

```bash
npm install @openmiddleware/chain @openmiddleware/hono
```

## Usage

```typescript
import { Hono } from 'hono';
import { createChain, logger, cors, auth } from '@openmiddleware/chain';
import { toHono, honoHandler } from '@openmiddleware/hono';

const app = new Hono();

const chain = createChain()
  .use(logger({ level: 'info' }))
  .use(cors({ origin: '*' }));

// Apply to all routes
app.use('*', toHono(chain));

// Or use honoHandler for route-specific middleware with handler
app.get('/api/users', honoHandler(
  createChain().use(auth({ jwt: { secret: 'my-secret' } })),
  (c) => {
    const user = c.get('state')?.user;
    return c.json({ users: [] });
  }
));

export default app;
```

## API

### toHono(chain)

Converts an OpenMiddleware chain to Hono middleware.

- **chain** - OpenMiddleware chain instance
- **returns** - Hono middleware function

### honoHandler(chain, handler)

Combines middleware chain with a handler.

- **chain** - OpenMiddleware chain instance
- **handler** - Hono handler function
- **returns** - Combined Hono handler

State is accessible via `c.get('state')`.

## License

MIT
npm package: @openmiddleware/koa
Description: Koa adapter for OpenMiddleware
Author: Ersin Koc
Latest version: 1.0.0

# @openmiddleware/koa

Koa adapter for OpenMiddleware.

## Installation

```bash
npm install @openmiddleware/chain @openmiddleware/koa
```

## Usage

```typescript
import Koa from 'koa';
import Router from '@koa/router';
import { createChain, logger, cors, auth } from '@openmiddleware/chain';
import { toKoa } from '@openmiddleware/koa';

const app = new Koa();
const router = new Router();

const chain = createChain()
  .use(logger({ level: 'info' }))
  .use(cors({ origin: '*' }))
  .use(auth({ jwt: { secret: 'my-secret' } }));

// Apply globally
app.use(toKoa(chain));

router.get('/api/users', (ctx) => {
  // Access state via ctx.state
  const user = ctx.state.user;
  ctx.body = { users: [] };
});

app.use(router.routes());
app.listen(3000);
```

## API

### toKoa(chain)

Converts an OpenMiddleware chain to Koa middleware.

- **chain** - OpenMiddleware chain instance
- **returns** - Koa middleware function

State is merged into `ctx.state`.

## License

MIT
npm package: @openmiddleware/testing
Description: Test utilities for OpenMiddleware
Author: Ersin Koc
Latest version: 1.0.0

# @openmiddleware/testing

Testing utilities for OpenMiddleware.

## Installation

```bash
npm install -D @openmiddleware/testing
```

## Usage

```typescript
import { testMiddleware, mockRequest, matchers } from '@openmiddleware/testing';
import { cors, logger } from '@openmiddleware/chain';
import { expect, describe, it } from 'vitest';

// Extend Vitest with custom matchers
expect.extend(matchers);

describe('cors middleware', () => {
  it('should add CORS headers', async () => {
    const result = await testMiddleware(cors({ origin: '*' }), {
      url: 'https://api.example.com/users',
      headers: { Origin: 'https://example.com' },
    });

    expect(result.response).toHaveHeader('Access-Control-Allow-Origin', '*');
    expect(result.response).toBeSuccessful();
  });

  it('should handle preflight requests', async () => {
    const result = await testMiddleware(cors({ origin: '*' }), {
      method: 'OPTIONS',
      url: 'https://api.example.com/users',
      headers: {
        Origin: 'https://example.com',
        'Access-Control-Request-Method': 'POST',
      },
    });

    expect(result.done).toBe(true);
    expect(result.response).toHaveStatus(204);
  });
});
```

## API

### testMiddleware(middleware, options)

Tests a single middleware.

- **middleware** - Middleware to test
- **options** - Request options (url, method, headers, body)
- **returns** - Test result with response and state

### testChain(chain, options)

Tests a middleware chain.

- **chain** - Chain to test
- **options** - Request options
- **returns** - Test result

### Mock Request Helpers

```typescript
import { mockRequest, mockGet, mockPost, mockPut, mockPatch, mockDelete, mockOptions } from '@openmiddleware/testing';

const req = mockGet('https://api.example.com/users');
const req = mockPost('https://api.example.com/users', { name: 'John' });
```

## Custom Matchers

- `toHaveStatus(status)` - Check response status
- `toHaveHeader(name, value?)` - Check response header
- `toHaveBody(body)` - Check response body
- `toBeRedirect(location?)` - Check if redirect
- `toBeSuccessful()` - Check if 2xx status
- `toBeClientError()` - Check if 4xx status
- `toBeServerError()` - Check if 5xx status
- `toBeJson()` - Check if JSON response

## License

MIT