open-index/open-npm huggingface dataset:
npm package: @fastgpt-sdk/sandbox-adapter
Description: Unified abstraction layer for cloud sandbox providers with adapter pattern and feature polyfilling
Latest version: 0.0.35

# @fastgpt/sandbox

A unified, high-level abstraction layer for cloud sandbox providers. It offers a consistent, vendor-agnostic interface for creating, managing, and interacting with sandboxed environments like OpenSandbox.

> This package is ESM-only (`"type": "module"`) and requires Node.js **>= 20**.

## 安装

```bash
pnpm add @fastgpt/sandbox
```

## Next.js 集成

如果在 Next.js 项目中使用，需要配置以处理 ESM 依赖。在 `next.config.js` 中添加：

```javascript
/** @type {import('next').NextConfig} */
const nextConfig = {
  transpilePackages: ['@fastgpt-sdk/sandbox-adapter'],
  experimental: {
    esmExternals: 'loose',
  },
};

module.exports = nextConfig;
```

详细说明请参考 [Next.js 集成指南](./docs/NEXTJS_INTEGRATION.md)。

## 用途

### 1. 操作沙盒

1. 执行命令：执行命令并返回结果
   1. Create 接口：成功返回，则认为沙盒已创建成功，可以执行命令。
   2. 执行
2. 下载文件。

### 2. 管理沙盒

1. 定期暂停：每 n 分钟不活跃则暂停
2. 定期销毁：每 n 分钟不活跃则销毁


## 添加新适配器
npm package: @fasti18n/client-js
Description: A js module that interacts with the fastI18n service
Author: FastI18n
Latest version: 0.0.5

# client-js

[![codecov](https://codecov.io/gh/fasti18n/client-js/graph/badge.svg?token=KPGFHMZ7SW)](https://codecov.io/gh/fasti18n/client-js)


A js module that interacts with the fastI18n service
npm package: @fastia/ui
Description: Tailwind CSS UI components for React.
Author: ronuss
Latest version: 0.1.31

# Fastia
Fastia is a lightweight library of React components styled with Tailwind CSS, designed to speed up your web development projects.

> Fastia **requires** Tailwind CSS to be **installed** in your project, as it's uses Tailwind's classes.

## Installation

To get started with Fastia, you can easily install it using npm or yarn:

```bash
npm install @fastia/ui
# or
yarn add @fastia/ui
```

## Usage

### `<FastiaButton>`

#### Props

- `color` (string, required): Sets the color of the button. Available options are:
  - "yellow"
  - "red"
  - "green"
  - "gray"
  - "blue"

#### Example

```jsx
import React from "react";
import { FastiaButton } from "@fastia/ui";

function MyComponent() {
  return (
    <div>
      <FastiaButton color="blue">Click me</FastiaButton>
    </div>
  );
}
```

## License

Fastia is released under the MIT License.
npm package: @fastify-decorators/typedi
Description: fastify-decorators plugin to work with Sequelize
Author: Andrey Chalkin
Latest version: 4.0.0-next.5

<h1 style="text-align: center">@fastify-decorators/typedi</h1>

[![npm version](https://badge.fury.io/js/@fastify-decorators%2Ftypedi.svg)](https://badge.fury.io/js/@fastify-decorators%2Ftypedi)
[![npm](https://img.shields.io/npm/dm/@fastify-decorators/typedi.svg?colorB=brightgreen)](https://www.npmjs.com/package/@fastify-decorators/typedi)
[![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)

## Dependency injection

Dependency injection (DI) is widely used mechanism to autowire controller/service dependency.
In fastify-decorators DI only available for controllers.

This plugin provides support for integration with [TypeDI](https://npmjs.com/package/typedi)

### Getting started

1. Install `@fastify-decorators/typedi` and `typedi`
2. Use TypeDI container in the app

   ```typescript
   import { useContainer } from '@fastify-decorators/typedi';
   import { fastify } from 'fastify';
   import { bootstrap } from 'fastify-decorators';
   import { Container } from 'typedi';

   useContainer(Container);

   export const app = fastify();

   app.register(bootstrap, {
     directory: import.meta.url,
   });
   ```

3. Write services, annotate them with `@Service` and inject into controllers using `@Inject` from TypeDI

### Examples

- [Example 1](https://github.com/L2jLiga/fastify-decorators/tree/v4/examples/typedi)
npm package: @fastify-plus/openapi
Description: modern fastify (@openapi)
Author: zhongyuanjia
Latest version: 0.2.1-alpha.0

### OpenApi Specification

this package define the api schema and export common decorators

### Define Api

```typescript
// optional tag, default is class name
@ApiTag('User')
@Controller('users')
class UserController {
  @Post({ description: 'create a new user' })
  @ApiOkResponse({ type: Number, description: 'return created user id' })
  async createUser(
    @ApiRequestBody({ description: 'user schema' }) userSchema: UserSchema,
  ): Promise<number> {
    return 1;
  }

  @Get()
  @ApiOkResponse({ type: UserSchema })
  async getUser(@ApiRequestQuery() id: number) {
    return new UserSchema();
  }
}

@ApiSchema({ description: 'user' })
class UserSchema {
  @ApiSchema({
    description: 'user id',
    required: false,
  })
  id?: number;

  @ApiSchema()
  username: string;

  @ApiSchema()
  password: string;
}
```
npm package: @fastify-resty/core
Description: Fastify Resty API Framework core functionality
Author: Demidovich Daniil
Latest version: 0.3.0

# @fastify-resty/core

The core functionality of `fastify-resty` framework.

## Install

Using npm:

```sh
npm install @fastify-resty/core
```

or using yarn:

```sh
yarn add @fastify-resty/core
```
npm package: @fastify-resty/typeorm
Description: Fastify Resty TypeORM connector
Author: Demidovich Daniil
Latest version: 0.3.0

# @fastify-resty/typeorm

The `TypeORM` connector for `fastify-resty` framework.

## Install

Using npm:

```sh
npm install @fastify-resty/typeorm
```

or using yarn:

```sh
yarn add @fastify-resty/typeorm
```
npm package: @fastify-userland/typeorm-query-runner
Description: Fastify typeorm QueryRunner
Author: Black-Hole
Latest version: 1.0.0

# @fastify-userland/typeorm-query-runner

![CI](https://github.com/fastify-userland/typeorm-query-runner/workflows/CI/badge.svg)
[![NPM version](https://img.shields.io/npm/v/@fastify-userland/typeorm-query-runner.svg?style=flat)](https://www.npmjs.com/package/@fastify-userland/typeorm-query-runner)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
[![NPM size](https://img.shields.io/bundlephobia/min/@fastify-userland/typeorm-query-runner)](https://www.npmjs.com/package/@fastify-userland/typeorm-query-runner)
[![Coverage Status](https://coveralls.io/repos/github/fastify-userland/typeorm-query-runner/badge.svg?branch=main)](https://coveralls.io/github/fastify-userland/typeorm-query-runner?branch=main)

A plugin for Fastify that adds support for `typrorm QueryRunner and Transaction`.

Supports Fastify versions 4.x.

> Support TypeScript

## Install

```shell
# npm
npm i @fastify-userland/typeorm-query-runner

# pnpm
pnpm add @fastify-userland/typeorm-query-runner

# yarn
yarn add @fastify-userland/typeorm-query-runner
```

## Usage

```JavaScript
const fastify = require('fastify')()

fastify.register(require('@fastify-userland/typeorm-query-runner'), {
  dataSource: dataSource,
  transaction: true,
  match: request => request.routerPath.startsWith('/v2'),
  respIsError: (respStr) => respStr === '{"status":false}'
})

fastify.get('/', async (req, reply) => {
  console.log(req.queryRunner)
  console.log(req.queryRunner.manager)

  await req.queryRunner.manager.insert();
  
  reply.send({ hello: 'world' })
})

fastify.listen(3000)
```

### Options

* `dataSource`(Required): TypeORM dataSource

* `transaction`(Optional): Whether to bind the life cycle of a thing to a request. - **default: `false`**
  - Receiving requests: opening transaction
  - Return response: close transaction
  - Requesting an error: rolling back transaction

* `match`(Optional): Only matching requests will enable the plugin. - **default: `() => true`**
  - Receiving requests: opening transaction
  - Return response: close transaction
  - Requesting an error: rolling back transaction
```javascript
match: request => {
  return request.routerPath.startsWith('/v2')
}
```

* `respIsError`(Optional): When the response matches the condition, it is considered an error - **default: `() => false`**
```javascript
respIsError: (respStr) => {
  return respStr === '{"status":false}'
}
```

## License

Licensed under [MIT](./LICENSE).
npm package: @fastify/accept-negotiator
Description: a negotiator for the accept-headers
Author: Aras Abbasi
Latest version: 2.0.1

# @fastify/accept-negotiator


[![CI](https://github.com/fastify/accept-negotiator/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/accept-negotiator/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/accept-negotiator.svg?style=flat)](https://www.npmjs.com/package/@fastify/accept-negotiator)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

A negotiator for accept-* headers.

### Install
```
npm i @fastify/accept-negotiator
```

### Usage

The module exports a function that you can use for negotiating an accept-* header such as [`accept-encoding`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding). It takes 2 parameters:

```
negotiate(header, supportedValues)
```

- `header` (`string`, required) - The accept-header, e.g. accept-encoding
- `supportedValues` (`string[]`, required) - The values, which are supported

```js
const negotiate = require('@fastify/accept-negotiator').negotiate
const encoding = negotiate('gzip, deflate, br', ['br'])
console.log(encoding) // 'br*
```

The module also exports a class that you can use for negotiating an accept-* header, and use caching for better performance.


```
Negotiate(supportedValues)
```

- `supportedValues` (`string[]`, required) - The values, which are supported
- `cache` (`{ set: Function; get: Function; has: Function }`, optional) - A Cache-Store, e.g. ES6-Map or mnemonist LRUCache

```js
const Negotiator = require('@fastify/accept-negotiator').Negotiator
const encodingNegotiator = new Negotiator({ supportedValues: ['br'], cache: new Map() })

const encoding = encodingNegotiator.negotiate('gzip, deflate, br')
console.log(encoding) // 'br*
```

## License

Licensed under [MIT](./LICENSE).
npm package: @fastify/accepts
Description: Add accept parser to fastify
Author: allevo
Latest version: 5.0.4

# @fastify/accepts

[![CI](https://github.com/fastify/fastify-accepts/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/fastify-accepts/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/accepts.svg?style=flat)](https://www.npmjs.com/package/@fastify/accepts)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

Add an accepts parser to Fastify.

## Install

`npm i @fastify/accepts`

### Compatibility

| Plugin version | Fastify version |
| ---------------|-----------------|
| `>=5.x`        | `^5.x`          |
| `^4.x`         | `^4.x`          |
| `>=2.x <4.x`   | `^3.x`          |
| `^1.x`         | `^2.x`          |
| `^1.x`         | `^1.x`          |


Please note that if a Fastify version is out of support, then so are the corresponding versions of this plugin
in the table above.
See [Fastify's LTS policy](https://github.com/fastify/fastify/blob/main/docs/Reference/LTS.md) for more details.

## Usage

```js
const fastify = require('fastify')
const Boom = require('@hapi/boom')

fastify.register(require('@fastify/accepts'))

fastify.post('/', function (req, reply) {
  const accept = req.accepts() // Accepts object
  switch(accept.type(['json', 'html'])) {
    case 'json':
      reply.type('application/json').send({hello: 'world'})
      break
    case 'html':
      reply.type('text/html').send('<b>hello, world!</b>')
      break
    default:
      reply.send(Boom.notAcceptable('unacceptable'))
      break
  }
})
```

See [accepts package](https://www.npmjs.com/package/accepts) for all available APIs.

This plugin adds to `Request` object all `Accepts` object methods.

```js
fastify.post('/', function (req, reply) {
  req.charset(['utf-8'])
  req.charsets()
  req.encoding(['gzip', 'compress'])
  req.encodings()
  req.language(['es', 'en'])
  req.languages()
  req.type(['image/png', 'image/tiff'])
  req.types()
})
```

### Options

- `decorateReply` If `true`, the `Reply` object will be decorated with the `requestAccepts`, `requestTypes`, `requestCharsets`, `requestEncodings`, and `requestLanguages` methods, which will return the corresponding values from the `Request` object. Default: `false`.

## License

Licensed under [MIT](./LICENSE).
npm package: @fastify/accepts-serializer
Description: Serializer according to the accept header
Author: allevo
Latest version: 6.0.3

# @fastify/accepts-serializer

[![CI](https://github.com/fastify/fastify-accepts-serializer/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/fastify-accepts-serializer/actions/workflows/ci.yml)
[![npm version](https://img.shields.io/npm/v/@fastify/accepts-serializer)](https://www.npmjs.com/package/@fastify/accepts-serializer)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

Serialize according to the `Accept` header.


## Install
```sh
npm i @fastify/accepts-serializer
```

### Compatibility

| Plugin version | Fastify version |
| ---------------|-----------------|
| `>=6.x`        | `^5.x`          |
| `^5.x`         | `^4.x`          |
| `>=3.x <5.x`   | `^3.x`          |
| `^2.x`         | `^2.x`          |
| `^1.x`         | `^1.x`          |


Please note that if a Fastify version is out of support, then so are the corresponding versions of this plugin
in the table above.
See [Fastify's LTS policy](https://github.com/fastify/fastify/blob/main/docs/Reference/LTS.md) for more details.

## Usage
```js

const protobuf = require('protobufjs')
const YAML = require('yamljs')
const msgpack = require('msgpack5')()

const root = protobuf.loadSync('test/awesome.proto')
const AwesomeMessage = root.lookupType('awesomepackage.AwesomeMessage')

const fastify = require('fastify')()

// Global serializers
fastify.register(require('@fastify/accepts-serializer'), {
  serializers: [
    {
      regex: /^application\/yaml$/,
      serializer: body => YAML.stringify(body)
    },
    {
      regex: /^application\/x-msgpack$/,
      serializer: body => msgpack.encode(body)
    }
  ],
  default: 'application/yaml' // MIME type used if Accept header does not match anything
})

// Per-router serializers
const config = {
  serializers: [
    {
      regex: /^application\/x-protobuf$/,
      serializer: body => AwesomeMessage.encode(AwesomeMessage.create(body)).finish()
    }
  ]
}

fastify.get('/request', { config }, function (req, reply) {
  reply.send({pippo: 'pluto'})
})
```

## Behavior

For each route, a SerializerManager is defined, which has both per-route and global serializer definitions.

The MIME type `application/json` is always handled by `fastify` if no serializer is registered for that MIME type.

If no `default` key is specified in configuration, all requests with an unknown `Accept` header will be replied to with a 406 response (a boom error is used).

## License

Licensed under [MIT](./LICENSE).
npm package: @fastify/flash
Description: Flash message plugin for fastify.
Latest version: 6.0.3

# @fastify/flash

[![CI](https://github.com/fastify/fastify-flash/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fastify-flash/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/flash.svg?style=flat)](https://www.npmjs.com/package/@fastify/flash)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)

The flash is a special area of the session used for storing messages. Messages are written to the flash and cleared after being displayed to the user. The flash is typically used in combination with redirects, ensuring that the message is available to the next page that is to be rendered.

This plugin is inspired by [connect-flash](https://github.com/jaredhanson/connect-flash).

## Install
`npm i @fastify/flash`

## Usage
Flash messages are stored in the session. First, we need to register the session plugin: [@fastify/secure-session](https://www.npmjs.com/package/@fastify/secure-session).

``` javascript
const fastify = require('fastify')()
const fastifySession = require('@fastify/secure-session')
const fastifyFlash = require('@fastify/flash')

fastify.register(fastifySession, {
  // adapt this to point to the directory where secret-key is located
  key: fs.readFileSync(path.join(__dirname, 'secret-key')),
  cookie: {
    // options from setCookie, see https://github.com/fastify/fastify-cookie
  }
})
fastify.register(fastifyFlash)

fastify.get('/test', (req, reply) => {
  req.flash('warning', ['username required', 'password required'])

  const warning = reply.flash('warning')
  reply.send({ warning }) // {"warning":["username required","password required"]}
})
```

### Note on session plugin
`@fastify/secure-session` can be replaced by any session plugin as long as it:

1. registers via the onRequest hook
2. supports req.session as the session store


## API
### Set flash messages
Signature
``` typescript
req.flash(type: string, ...message: string[] | [string[]]): number
```
It can be called in three different ways:
- `req.flash('info', 'Welcome back')`
- `req.flash('warning', ['username required', 'password required'])`
- `req.flash('info', 'Hello %s', 'Jared') // will use util.format to format the string`

`req.flash` returns the number of messages stored with the provided type.

### Get flash messages
signature
``` typescript
reply.flash(type?: string): { [k: string]: undefined | string[] } | string[]
```
It can be called in two different ways:
- `reply.flash() // returns all messages as object { [k: string]: undefined | string[] }`
- `reply.flash('info') // returns an array of messages that are stored with the provided type`

## License

Licensed under [MIT](./LICENSE).
npm package: @fastify/forwarded
Description: Parse HTTP X-Forwarded-For header
Author: Douglas Christopher Wilson
Latest version: 3.0.1

# @fastify/forwarded

[![CI](https://github.com/fastify/forwarded/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/forwarded/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/forwarded.svg?style=flat)](https://www.npmjs.com/package/@fastify/forwarded)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

Parse HTTP X-Forwarded-For header.

Updated version of the great https://github.com/jshttp/forwarded.
Implements https://github.com/jshttp/forwarded/pull/9.

## Installation

```sh
$ npm i @fastify/forwarded
```

## API

```js
const forwarded = require('@fastify/forwarded')
```

### forwarded(req)

```js
const addresses = forwarded(req)
```

Parse the `X-Forwarded-For` header from the request. Returns an array
of the addresses, including the socket address for the `req`, in reverse
order (i.e. index `0` is the socket address and the last index is the
furthest address, typically the end-user).

## Testing

```sh
$ npm test
```

## License

[MIT](LICENSE)
npm package: @fastify/htmx
Description: The official @fastify/vite renderer for HTMX
Latest version: 0.4.1

<br>

**`@fastify/htmx`** is the official [**`@fastify/vite`**](https://github.com/fastify/fastify-vite) renderer for HTMX.

See the [documentation suite](https://github.com/fastify/fastify-vite) to learn more.
npm package: @fastify/one-line-logger
Description: A simple formatter for fastify's logs
Author: Matteo Collina
Latest version: 2.1.0

<a id="@fastify/one-line-logger"></a>
# @fastify/one-line-logger


[![CI](https://github.com/fastify/one-line-logger/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/one-line-logger/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/one-line-logger.svg?style=flat)](https://www.npmjs.com/package/@fastify/one-line-logger)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

`@fastify/one-line-logger` helps you format fastify's log into a nice one-line message:

```
YYYY-MM-dd HH:mm:ss.SSSTZ - <level> - <method> <route path> - <message>
```

A standard incoming request log line like:

```
{"level": 30,"time": 1660151282194,"pid": 1557,"hostname": "foo","reqId": "req-1","req": {"method": "GET","url": "/path","hostname": "localhost:8080","remoteAddress": "127.0.0.1"},"msg": "incoming request"}
```

Will format to:

```
2022-08-11 01:08:02.194+0100 - info - GET / - incoming request
```

<a id="install"></a>
## Install

```
npm i @fastify/one-line-logger
```

<a id="getting-started"></a>
## Getting started

```js
const server = fastify({
  logger: {
    transport: {
      target: "@fastify/one-line-logger",
    },
  },
});
```

## Colors

Colors are enabled by default when supported. To manually disable the colors you need to set the `transport.colorize` option to `false`. For more options check the `colorette` [docs](https://github.com/jorgebucaran/colorette?tab=readme-ov-file#environment).

```js
const server = fastify({
  logger: {
    transport: {
      target: "@fastify/one-line-logger",
      colorize: false,
    },
  },
});
```


## Custom levels

Custom levels could be used by passing it into logger opts

```js
const server = fastify({
  logger: {
    transport: {
      target: "@fastify/one-line-logger",
    },
    customLevels: {
      foo: 35,
      bar: 45,
    },
  },
});

server.get("/", (request, reply) => {
  request.log.info("time to foobar");
  request.log.foo("FOO!");
  request.log.bar("BAR!");
  reply.send({ foobar: true });
});
```

## Custom level colors

Custom level colors can be used by passing it into logger opts. They can also overwrite the default level's colors. Check all the supported colors [here](https://github.com/jorgebucaran/colorette?tab=readme-ov-file#supported-colors).

```js
const server = fastify({
  logger: {
    transport: {
      target: "@fastify/one-line-logger",
      colors: {
        35: "bgYellow",
        45: "magenta",
        60: "bgRedBright" // overwriting the `fatal` log color
      }
    },
    customLevels: {
      foo: 35,
      bar: 45,
    },
  },
});

server.get("/", (request, reply) => {
  request.log.fatal("An error occured");
  request.log.foo("FOO!");
  request.log.bar("BAR!");
  reply.send({ foobar: true });
});
```

<a id="license"></a>
## License

Licensed under [MIT](./LICENSE).
npm package: @fastify/react
Description: The official @fastify/vite renderer for React
Latest version: 1.1.7

<br>

**`@fastify/react`** is the official [**`@fastify/vite`**](https://github.com/fastify/fastify-vite) renderer for React.

See the [documentation suite](https://fastify.github.io/fastify-vite/react/) to learn more.
npm package: @fastify/restartable
Description: Restart Fastify without losing a request
Author: Matteo Collina
Latest version: 3.0.2

# @fastify/restartable

[![NPM version](https://img.shields.io/npm/v/@fastify/restartable.svg?style=flat)](https://www.npmjs.com/package/@fastify/restartable)
[![CI](https://github.com/fastify/restartable/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/restartable/actions/workflows/ci.yml)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

Restart Fastify without losing a request.

This module is useful if you want to compose the
fastify routes dynamically or you need some remote
config. In case of a change, you can restart Fastify.

## Install

```bash
npm i @fastify/restartable
```

## Usage

```js
import { restartable } from '@fastify/restartable'

async function createApp (fastify, opts) {
  const app = fastify(opts)

  app.get('/restart', async () => {
    await app.restart()
    return { status: 'ok' }
  })

  app.addHook('onClose', async () => {
    if(!app.closingRestartable) {
      console.log('closing the app because of restart')
    }
    else{
      console.log('closing the app because server is stopping')
    }
  })

  return app
}

const app = await restartable(createApp, { logger: true })
const host = await app.listen({ port: 3000 })

console.log('server listening on', host)

// call restart() if you want to restart
process.on('SIGUSR1', () => {
  console.log('Restarting the server')
  app.restart()
})

process.once('SIGINT', () => {
  console.log('Stopping the server')
  app.close()
})

```

## Hooks

- `preRestart` - called before creating a new app instance and closing an
existing one. The hook is called with the current app instance as an argument.
Use it to close any resources that you don't want to be shared between the
app instances.

- `onRestart` - called after the new app instance is created and the old one
is closed. The hook is called with the new app instance as an argument.

**Example**:

```js
  async function createApplication (fastify, opts) {
    console.log('creating new app instance')
    return fastify(opts)
  }
  const app = await restartable(createApplication)

  app.addPreRestartHook(async (app) => {
    console.log('preRestart hook called')
  })

  app.addOnRestartHook(async (app) => {
    console.log('onRestart hook called')
  })

  await app.restart()
```

**Output**:

```bash
preRestart hook called
creating new app instance
onRestart hook called
```

## License

Licensed under [MIT](./LICENSE).
npm package: @fastify/routes
Description: A plugin for Fastify that provides a map of routes
Author: Cemre Mengu
Latest version: 6.0.2

# @fastify/routes

[![CI](https://github.com/fastify/fastify-routes/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fastify-routes/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/routes.svg?style=flat)](https://www.npmjs.com/package/@fastify/routes)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

This plugin decorates a Fastify instance with `routes`, which is a [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) of registered routes. Note that you have to await the registration of this plugin before registering any routes so that @fastify/routes can collect them.

## Data Structure

The `fastify.routes` Map has a key for each path any route has been registered, which points to an array of routes registered on that path. There can be more than one route for a given path if there are multiple routes added with different methods or different constraints.

```js
  {
    '/hello': [
      {
        method: 'GET',
        url: '/hello',
        schema: { ... },
        handler: Function,
        prefix: String,
        logLevel: String,
        bodyLimit: Number,
        constraints: undefined,
      },
      {
        method: 'POST',
        url: '/hello',
        schema: { ... },
        handler: Function,
        prefix: String,
        logLevel: String,
        bodyLimit: Number,
        constraints: { ... },
      }
    ]
  }
```

## Example

```js
const fastify = require("fastify")();

(async () => {
  await fastify.register(require("@fastify/routes"));
  fastify.get("/hello", {}, (request, reply) => {
    reply.send({ hello: "world" });
  });

  fastify.listen({ port: 3000 }, (err, address) => {
    if (err) {
      console.error(err);
      return;
    }
    console.log(fastify.routes);
    /* will output a Map with entries:
    {
      '/hello': [
        {
          method: 'GET',
          url: '/hello',
          schema: Object,
          handler: <Function>,
          prefix: <String>,
          logLevel: <String>,
          bodyLimit: <Number>
        }
      ]
    }
    */
  });
})();
```

## License

MIT License
npm package: @fastify/routes-stats
Description: provide stats for routes using perf_hooks, for fastify
Author: Matteo Collina
Latest version: 4.0.2

# @fastify/routes-stats

[![CI](https://github.com/fastify/fastify-routes-stats/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fastify-routes-stats/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/routes-stats.svg?style=flat)](https://www.npmjs.com/package/@fastify/routes-stats)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

Provide stats for routes using `require('node:perf_hooks')`, for **Fastify**.

## Install

```sh
npm i @fastify/routes-stats
```

## Example

```js
'use strict'

const Fastify = require('fastify')
const fastify = Fastify()

fastify.register(require('@fastify/routes-stats'), {
  printInterval: 4000, // milliseconds
  decoratorName: "performanceMarked", // decorator is set to true if a performance.mark was called for the request
})

fastify.get('/', function (request, reply) {
  reply.send({ hello: 'world' })
})

fastify.get(
  '/:param/dynamic-route-example',
  { config: { statsId: 'group-stats-together' } },
  function (request, reply) {
    reply.send({ hello: 'world' })
  }
)

fastify.get('/__stats__', async function () {
  // stats is added to the fastify instance
  return this.stats()
})

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

```sh
$ curl -s localhost:3000/__stats__ | jsonlint
{
  "GET": {
    "/": {
      "mean": 0.2406786,
      "mode": 0.755647,
      "median": 0.121999,
      "max": 0.755647,
      "min": 0.050214,
      "sd": 0.2905856386253457
    }
  },
  "POST": {
    "/": {
      "mean": 0.11260519999999999,
      "mode": 0.292262,
      "median": 0.055179,
      "max": 0.292262,
      "min": 0.044159,
      "sd": 0.10438752062722824
    }
  }
}
```

It will also log a stat object every 30 seconds (by default).

## License

MIT
npm package: @fastify/schedule
Description: Fastify plugin for scheduling periodic jobs
Latest version: 6.0.0

# @fastify/schedule

[![CI](https://github.com/fastify/fastify-schedule/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/fastify-schedule/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/schedule.svg?style=flat)](https://www.npmjs.com/package/@fastify/schedule)
[![NPM downloads](https://img.shields.io/npm/dm/@fastify/schedule.svg?style=flat)](https://www.npmjs.com/package/@fastify/schedule)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

Fastify plugin for scheduling periodic jobs. Provides an instance of [toad-scheduler](https://github.com/kibertoad/toad-scheduler) on fastify instance.
Jobs are stopped automatically when the fastify instance is stopped.

## Getting started

First install the package:

```bash
npm i @fastify/schedule toad-scheduler
```

Next, set up the plugin:

```js
const fastify = require('fastify')();
const { fastifySchedule } = require('@fastify/schedule');
const { SimpleIntervalJob, AsyncTask } = require('toad-scheduler');

const task = new AsyncTask(
    'simple task',
    () => { return db.pollForSomeData().then((result) => { /* continue the promise chain */ }) },
    (err) => { /* handle errors here */ }
)
const job = new SimpleIntervalJob({ seconds: 20, }, task)

fastify.register(fastifySchedulePlugin);

// `fastify.scheduler` becomes available after initialization.
// Therefore, you need to call `ready` method.
fastify.ready().then(() => {
    fastify.scheduler.addSimpleIntervalJob(job)
})
```

For more detailed instructions, see the [documentation](https://github.com/kibertoad/toad-scheduler) of `toad-scheduler`.
npm package: @fastify/soap-client
Description: SOAP client integration
Author: Tommaso Allevi - @allevo
Latest version: 2.2.0
Deprecated: This module is deprecated, use the soap module directly

# @fastify/soap-client

![CI](https://github.com/fastify/fastify-soap-client/workflows/CI/badge.svg)
[![NPM version](https://img.shields.io/npm/v/@fastify/soap-client)](https://www.npmjs.com/package/@fastify/soap-client)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)

This plugin decorates your fastify instance with a SOAP client using [`soap` library](https://www.npmjs.com/package/soap)

## Install

```
npm i @fastify/soap-client
```

## Usage

```js
const fastifySoapClient = require('@fastify/soap-client')

fastify.register(fastifySoapClient, {
  url: 'http://www.dneonline.com/calculator.asmx?WSDL',
  // options: { soap library options }
})

const addSchema = {
  body: {
    type: 'array',
    items: [
      { type: 'number' },
      { type: 'number' }
    ]
  }
}
fastify.post('/add', addSchema, function (req, reply) {
  this.soapClient.Add({ intA: req.body[0], intB: req.body[1] }, function (err, result) {
    if (err) {
      reply.send(err)
      return
    }
    reply.send(result.AddResult)
  })
})
```

## Reference

- *url:* (required) the url where the wsdl is located. See [soap library reference](https://www.npmjs.com/package/soap#soapcreateclienturl-options-callback---create-a-new-soap-client-from-a-wsdl-url-also-supports-a-local-filesystem-path)
- *options:* the soap library options. See [soap library](https://www.npmjs.com/package/soap#options)

## License
Licensed under MIT
npm package: @fastify/url-data
Description: A Fastify plugin to provide access to URI components
Author: James Sumners
Latest version: 6.0.3

# @fastify/url-data

[![CI](https://github.com/fastify/fastify-url-data/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fastify-url-data/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/url-data.svg?style=flat)](https://www.npmjs.com/package/@fastify/url-data)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

A plugin for [Fastify](https://fastify.dev/) that adds support for getting raw
URL information from the request.

## Install
```
npm i @fastify/url-data
```

### Compatibility
| Plugin version | Fastify version |
| ---------------|-----------------|
| `^6.x`         | `^5.x`          |
| `^5.x`         | `^4.x`          |
| `^3.x`         | `^3.x`          |
| `^2.x`         | `^2.x`          |
| `^2.x`         | `^1.x`          |


Please note that if a Fastify version is out of support, then so are the corresponding versions of this plugin
in the table above.
See [Fastify's LTS policy](https://github.com/fastify/fastify/blob/main/docs/Reference/LTS.md) for more details.

## Example

```js
const fastify = require('fastify')()

fastify.register(require('@fastify/url-data'))

fastify.get('/foo', (req, reply) => {
  const urlData = req.urlData()
  req.log.info(urlData.path) // '/foo'
  req.log.info(urlData.query) // 'a=b&c=d'
  req.log.info(urlData.host) // '127.0.0.1'
  req.log.info(urlData.port) // 8080

  // if you just need single data:
  req.log.info(req.urlData('path')) // '/foo'

  reply.send({hello: 'world'})
})

// GET: 'http://127.0.0.1:8080/foo?a=b&c=d
```

## License

Licensed under [MIT](./LICENSE).
npm package: @fastify/vite
Description: Official Fastify plugin for Vite integration.
Latest version: 9.0.0
Deprecated: false

<br>

<img src="https://github.com/fastify/fastify-vite/assets/12291/7f711a83-91df-41d5-abf9-ae4f38ed24d3" style="width: 250px">

# **`@fastify/vite`**

This [Fastify](https://fastify.dev) plugin allows you to run Vite's development server as middleware, **expose** your [Vite](https://vitejs.dev) application to your Fastify application, with configuration hooks to **ease router integration** and **other customizations**, and also automatically serve Vite builds, inferred from a Vite configuration file.

See the [full documentation suite](https://fastify.github.io/fastify-vite/) to learn more.
npm package: @fastify/zipkin
Description: Fastify plugin for Zipkin distributed tracing system.
Author: Tomas Della Vedova - @delvedor
Latest version: 4.0.2

# @fastify/zipkin

[![CI](https://github.com/fastify/fastify-zipkin/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fastify-zipkin/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/zipkin.svg?style=flat)](https://www.npmjs.com/package/@fastify/zipkin)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

Fastify plugin for [Zipkin](https://zipkin.io/) distributed tracing system.

## Install
```
npm i @fastify/zipkin
```

### Compatibility
| Plugin version | Fastify version |
| ---------------|-----------------|
| `^4.x`         | `^5.x`          |
| `^3.x`         | `^4.x`          |
| `^3.x`         | `^3.x`          |


Please note that if a Fastify version is out of support, then so are the corresponding versions of this plugin
in the table above.
See [Fastify's LTS policy](https://github.com/fastify/fastify/blob/main/docs/Reference/LTS.md) for more details.


## Usage
Require the plugin and register it within Fastify, then pass the following options: `{ serviceName, httpReporterUrl [, servicePort , tracer, recorder ] }`

```js
const fastify = require('fastify')()

fastify.register(require('@fastify/zipkin'), {
  serviceName: 'my-service-name',
  servicePort: 3000,
  httpReporterUrl: 'http://localhost:9411/api/v2/spans'
})

fastify.get('/', (req, reply) => {
  reply.send({ hello: 'world' })
})

fastify.listen({ port: 3000 }, err => {
  if (err) throw err
  console.log('Server listenting on localhost:', fastify.server.address().port)
})
```

## License

Licensed under [MIT](./LICENSE).