@zuplo/cli 6.72.3 → 6.72.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/node_modules/@fastify/reply-from/.github/dependabot.yml +42 -2
  2. package/node_modules/@fastify/reply-from/README.md +3 -3
  3. package/node_modules/@fastify/reply-from/index.js +6 -1
  4. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/.gitattributes +2 -0
  5. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/.github/dependabot.yml +53 -0
  6. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/.github/workflows/ci.yml +33 -0
  7. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/.github/workflows/lock-threads.yml +19 -0
  8. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/LICENSE +21 -0
  9. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/README.md +188 -0
  10. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/eslint.config.js +6 -0
  11. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/index.js +67 -0
  12. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/lib/getPluginName.js +25 -0
  13. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/lib/toCamelCase.js +10 -0
  14. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/package.json +70 -0
  15. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/test/bundlers.test.js +110 -0
  16. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/test/checkVersion.test.js +67 -0
  17. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/test/composite.test.js +14 -0
  18. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/test/esm/esm.mjs +11 -0
  19. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/test/esm/index.test.js +11 -0
  20. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/test/extractPluginName.test.js +49 -0
  21. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/test/mu1tip1e.composite.test.js +15 -0
  22. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/test/test.js +396 -0
  23. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/test/toCamelCase.test.js +24 -0
  24. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/types/example-async.tst.ts +19 -0
  25. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/types/example-callback.tst.ts +19 -0
  26. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/types/index.d.ts +54 -0
  27. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/types/index.tst.ts +249 -0
  28. package/node_modules/@fastify/reply-from/package.json +6 -7
  29. package/node_modules/@fastify/reply-from/test/incomplete-request.test.js +142 -0
  30. package/node_modules/@fastify/reply-from/types/index.tst.ts +123 -0
  31. package/node_modules/@posthog/core/dist/index.d.ts +1 -0
  32. package/node_modules/@posthog/core/dist/index.d.ts.map +1 -1
  33. package/node_modules/@posthog/core/dist/posthog-core-stateless.d.ts +35 -2
  34. package/node_modules/@posthog/core/dist/posthog-core-stateless.d.ts.map +1 -1
  35. package/node_modules/@posthog/core/dist/posthog-core-stateless.js +68 -56
  36. package/node_modules/@posthog/core/dist/posthog-core-stateless.mjs +68 -56
  37. package/node_modules/@posthog/core/dist/posthog-core.d.ts +2 -1
  38. package/node_modules/@posthog/core/dist/posthog-core.d.ts.map +1 -1
  39. package/node_modules/@posthog/core/dist/posthog-core.js +1 -0
  40. package/node_modules/@posthog/core/dist/posthog-core.mjs +1 -0
  41. package/node_modules/@posthog/core/dist/types.d.ts +1 -0
  42. package/node_modules/@posthog/core/dist/types.d.ts.map +1 -1
  43. package/node_modules/@posthog/core/dist/types.js +1 -0
  44. package/node_modules/@posthog/core/dist/types.mjs +1 -0
  45. package/node_modules/@posthog/core/dist/utils/bucketed-rate-limiter.d.ts +17 -0
  46. package/node_modules/@posthog/core/dist/utils/bucketed-rate-limiter.d.ts.map +1 -1
  47. package/node_modules/@posthog/core/dist/utils/bucketed-rate-limiter.js +18 -1
  48. package/node_modules/@posthog/core/dist/utils/bucketed-rate-limiter.mjs +9 -1
  49. package/node_modules/@posthog/core/dist/utils/type-utils.d.ts.map +1 -1
  50. package/node_modules/@posthog/core/package.json +2 -2
  51. package/node_modules/@posthog/core/src/index.ts +3 -0
  52. package/node_modules/@posthog/core/src/posthog-core-stateless.ts +135 -73
  53. package/node_modules/@posthog/core/src/posthog-core.ts +3 -2
  54. package/node_modules/@posthog/core/src/types.ts +5 -0
  55. package/node_modules/@posthog/core/src/utils/bucketed-rate-limiter.spec.ts +38 -1
  56. package/node_modules/@posthog/core/src/utils/bucketed-rate-limiter.ts +29 -0
  57. package/node_modules/@posthog/core/src/utils/type-utils.ts +0 -6
  58. package/node_modules/@posthog/types/LICENSE +2 -2
  59. package/node_modules/@posthog/types/dist/index.d.ts +1 -1
  60. package/node_modules/@posthog/types/dist/index.d.ts.map +1 -1
  61. package/node_modules/@posthog/types/dist/posthog-config.d.ts +32 -11
  62. package/node_modules/@posthog/types/dist/posthog-config.d.ts.map +1 -1
  63. package/node_modules/@posthog/types/package.json +1 -1
  64. package/node_modules/@posthog/types/src/index.ts +1 -0
  65. package/node_modules/@posthog/types/src/posthog-config.ts +34 -11
  66. package/node_modules/@zuplo/core/customer.cli.minified.js +1 -1
  67. package/node_modules/@zuplo/core/index.minified.js +1 -1
  68. package/node_modules/@zuplo/core/package.json +1 -1
  69. package/node_modules/@zuplo/graphql/package.json +1 -1
  70. package/node_modules/@zuplo/openapi-tools/dist/overlay.d.ts.map +1 -1
  71. package/node_modules/@zuplo/openapi-tools/dist/overlay.js +85 -1
  72. package/node_modules/@zuplo/openapi-tools/dist/overlay.js.map +1 -1
  73. package/node_modules/@zuplo/openapi-tools/dist/overlay.spec.js +82 -0
  74. package/node_modules/@zuplo/openapi-tools/dist/overlay.spec.js.map +1 -1
  75. package/node_modules/@zuplo/openapi-tools/package.json +1 -1
  76. package/node_modules/@zuplo/otel/out/esm/chunk-X7TLQJWO.js +26 -0
  77. package/node_modules/@zuplo/otel/out/esm/chunk-X7TLQJWO.js.map +1 -0
  78. package/node_modules/@zuplo/otel/out/esm/index.js +1 -1
  79. package/node_modules/@zuplo/otel/package.json +1 -1
  80. package/node_modules/@zuplo/runtime/out/esm/{chunk-423FXHUV.js → chunk-HKSZ4V6H.js} +124 -124
  81. package/node_modules/@zuplo/runtime/out/esm/chunk-HKSZ4V6H.js.map +1 -0
  82. package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
  83. package/node_modules/@zuplo/runtime/out/esm/index.js.map +1 -1
  84. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +1 -1
  85. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js.map +1 -1
  86. package/node_modules/@zuplo/runtime/out/types/index.d.ts +417 -141
  87. package/node_modules/@zuplo/runtime/out/types/mcp-gateway/index.d.ts +9 -9
  88. package/node_modules/@zuplo/runtime/package.json +1 -1
  89. package/node_modules/hono/dist/adapter/aws-lambda/handler.js +1 -4
  90. package/node_modules/hono/dist/adapter/lambda-edge/handler.js +12 -2
  91. package/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +1 -4
  92. package/node_modules/hono/dist/cjs/adapter/lambda-edge/handler.js +12 -2
  93. package/node_modules/hono/dist/cjs/client/client.js +10 -1
  94. package/node_modules/hono/dist/cjs/client/utils.js +1 -1
  95. package/node_modules/hono/dist/cjs/middleware/cache/index.js +1 -1
  96. package/node_modules/hono/dist/cjs/middleware/compress/index.js +2 -1
  97. package/node_modules/hono/dist/cjs/middleware/etag/index.js +2 -1
  98. package/node_modules/hono/dist/cjs/middleware/method-override/index.js +5 -3
  99. package/node_modules/hono/dist/cjs/router/trie-router/node.js +9 -0
  100. package/node_modules/hono/dist/client/client.js +10 -1
  101. package/node_modules/hono/dist/client/utils.js +1 -1
  102. package/node_modules/hono/dist/middleware/cache/index.js +1 -1
  103. package/node_modules/hono/dist/middleware/compress/index.js +2 -1
  104. package/node_modules/hono/dist/middleware/etag/index.js +2 -1
  105. package/node_modules/hono/dist/middleware/method-override/index.js +5 -3
  106. package/node_modules/hono/dist/router/trie-router/node.js +9 -0
  107. package/node_modules/hono/dist/types/adapter/lambda-edge/handler.d.ts +1 -1
  108. package/node_modules/hono/dist/types/helper/websocket/index.d.ts +1 -1
  109. package/node_modules/hono/dist/types/middleware/language/language.d.ts +18 -0
  110. package/node_modules/hono/dist/types/utils/types.d.ts +1 -1
  111. package/node_modules/hono/package.json +4 -4
  112. package/package.json +6 -6
  113. package/node_modules/@fastify/reply-from/types/index.test-d.ts +0 -194
  114. package/node_modules/@zuplo/otel/out/esm/chunk-T25G5RDX.js +0 -26
  115. package/node_modules/@zuplo/otel/out/esm/chunk-T25G5RDX.js.map +0 -1
  116. package/node_modules/@zuplo/runtime/out/esm/chunk-423FXHUV.js.map +0 -1
  117. /package/node_modules/@zuplo/runtime/out/esm/{chunk-423FXHUV.js.LEGAL.txt → chunk-HKSZ4V6H.js.LEGAL.txt} +0 -0
@@ -2,12 +2,52 @@ version: 2
2
2
  updates:
3
3
  - package-ecosystem: "github-actions"
4
4
  directory: "/"
5
+ commit-message:
6
+ # Prefix all commit messages with "chore: "
7
+ prefix: "chore"
5
8
  schedule:
6
- interval: "monthly"
9
+ interval: "weekly"
10
+ cooldown:
11
+ default-days: 7
12
+ allow:
13
+ - dependency-name: "*"
14
+ update-types:
15
+ - "version-update:semver-major"
7
16
  open-pull-requests-limit: 10
8
17
 
9
18
  - package-ecosystem: "npm"
10
19
  directory: "/"
20
+ commit-message:
21
+ # Prefix all commit messages with "chore: "
22
+ prefix: "chore"
11
23
  schedule:
12
- interval: "monthly"
24
+ interval: "weekly"
25
+ cooldown:
26
+ default-days: 7
27
+ versioning-strategy: "increase-if-necessary"
28
+ allow:
29
+ - dependency-name: "*"
30
+ update-types:
31
+ - "version-update:semver-major"
32
+ ignore:
33
+ # TODO: remove ignore until neostandard support ESLint 10
34
+ - dependency-name: "eslint"
35
+ - dependency-name: "neostandard"
36
+ - dependency-name: "@stylistic/*"
13
37
  open-pull-requests-limit: 10
38
+ groups:
39
+ # Production dependencies with breaking changes
40
+ dependencies:
41
+ dependency-type: "production"
42
+ # ESLint related dependencies
43
+ dev-dependencies-eslint:
44
+ patterns:
45
+ - "eslint"
46
+ - "neostandard"
47
+ - "@stylistic/*"
48
+ # TypeScript related dependencies
49
+ dev-dependencies-typescript:
50
+ patterns:
51
+ - "@types/*"
52
+ - "tstyche"
53
+ - "typescript"
@@ -70,7 +70,7 @@ Set the base URL for all the forwarded requests.
70
70
  *String or String[]*:
71
71
 
72
72
  * **Single string** → a normal `undici.Pool` / `http.request` client is used.
73
- * **Array with ≥ 2 elements** → **[`undici.BalancedPool`](https://undici.nodejs.org/#/docs/api/BalancedPool)** is automatically selected and requests are load-balanced round-robin across the given origins.
73
+ * **Array with ≥ 2 elements** → **[`undici.BalancedPool`](https://undici.nodejs.org/api/BalancedPool)** is automatically selected and requests are load-balanced round-robin across the given origins.
74
74
 
75
75
  When you provide an array, only the *origin* (`protocol://host:port`) part of each URL is considered; any path component is ignored.
76
76
 
@@ -354,7 +354,7 @@ const customRetryLogic = ({req, res, err, getDefaultRetry}: RetryDetails) => {
354
354
  ### `reply.from(source, [opts])`
355
355
 
356
356
  The plugin decorates the
357
- [`Reply`](https://fastify.dev/docs/latest/Reference/Reply)
357
+ [`Reply`](https://fastify.dev/docs/latest/Reference/Reply/)
358
358
  instance with a `from` method, which will reply to the original request
359
359
  __from the desired source__. The options allows overrides of any part of
360
360
  the request or response being sent or received to/from the source.
@@ -512,7 +512,7 @@ This library has:
512
512
  - The default value for `requestTimeout` is 10 seconds (`10000`), a value of 0 disables the timeout.
513
513
  - The default value for `sessionTimeout` is 60 seconds (`60000`), a value of 0 disables the timeout.
514
514
 
515
- When a timeout happens, [`504 Gateway Timeout`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/504)
515
+ When a timeout happens, [`504 Gateway Timeout`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/504)
516
516
  will be returned to the client.
517
517
 
518
518
  ## Compatibility with @fastify/multipart
@@ -146,7 +146,7 @@ const fastifyReplyFrom = fp(function from (fastify, opts, next) {
146
146
  }
147
147
  }
148
148
 
149
- // according to https://tools.ietf.org/html/rfc2616#section-4.3
149
+ // according to https://datatracker.ietf.org/doc/html/rfc2616#section-4.3
150
150
  // fastify ignore message body when it's a GET or HEAD request
151
151
  // when proxy this request, we should reset the content-length to make it a valid http request
152
152
  // discussion: https://github.com/fastify/fastify/issues/953
@@ -218,6 +218,11 @@ const fastifyReplyFrom = fp(function from (fastify, opts, next) {
218
218
  )
219
219
  } else {
220
220
  copyHeaders(rewriteHeaders(res.headers, this.request), this)
221
+ // An HTTP/1 connection cannot be reused until its request body has
222
+ // been consumed. Close it if the upstream responds before that point.
223
+ if (!req.complete) {
224
+ this.header('connection', 'close')
225
+ }
221
226
  }
222
227
  try {
223
228
  this.code(res.statusCode)
@@ -0,0 +1,2 @@
1
+ # Set default behavior to automatically convert line endings
2
+ * text=auto eol=lf
@@ -0,0 +1,53 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "github-actions"
4
+ directory: "/"
5
+ commit-message:
6
+ # Prefix all commit messages with "chore: "
7
+ prefix: "chore"
8
+ schedule:
9
+ interval: "weekly"
10
+ cooldown:
11
+ default-days: 7
12
+ allow:
13
+ - dependency-name: "*"
14
+ update-types:
15
+ - "version-update:semver-major"
16
+ open-pull-requests-limit: 10
17
+
18
+ - package-ecosystem: "npm"
19
+ directory: "/"
20
+ commit-message:
21
+ # Prefix all commit messages with "chore: "
22
+ prefix: "chore"
23
+ schedule:
24
+ interval: "weekly"
25
+ cooldown:
26
+ default-days: 7
27
+ versioning-strategy: "increase-if-necessary"
28
+ allow:
29
+ - dependency-name: "*"
30
+ update-types:
31
+ - "version-update:semver-major"
32
+ ignore:
33
+ # TODO: remove ignore until neostandard support ESLint 10
34
+ - dependency-name: "eslint"
35
+ - dependency-name: "neostandard"
36
+ - dependency-name: "@stylistic/*"
37
+ open-pull-requests-limit: 10
38
+ groups:
39
+ # Production dependencies with breaking changes
40
+ dependencies:
41
+ dependency-type: "production"
42
+ # ESLint related dependencies
43
+ dev-dependencies-eslint:
44
+ patterns:
45
+ - "eslint"
46
+ - "neostandard"
47
+ - "@stylistic/*"
48
+ # TypeScript related dependencies
49
+ dev-dependencies-typescript:
50
+ patterns:
51
+ - "@types/*"
52
+ - "tstyche"
53
+ - "typescript"
@@ -0,0 +1,33 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - next
8
+ - 'v*'
9
+ paths-ignore:
10
+ - 'docs/**'
11
+ - '*.md'
12
+ pull_request:
13
+ paths-ignore:
14
+ - 'docs/**'
15
+ - '*.md'
16
+
17
+ # This allows a subsequently queued workflow run to interrupt previous runs
18
+ concurrency:
19
+ group: "${{ github.workflow }}-${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
20
+ cancel-in-progress: true
21
+
22
+ permissions:
23
+ contents: read
24
+
25
+ jobs:
26
+ test:
27
+ permissions:
28
+ contents: write
29
+ pull-requests: write
30
+ uses: fastify/workflows/.github/workflows/plugins-ci.yml@v6
31
+ with:
32
+ license-check: true
33
+ lint: true
@@ -0,0 +1,19 @@
1
+ name: Lock Threads
2
+
3
+ on:
4
+ schedule:
5
+ - cron: '0 0 1 * *'
6
+ workflow_dispatch:
7
+
8
+ concurrency:
9
+ group: lock
10
+
11
+ permissions:
12
+ contents: read
13
+
14
+ jobs:
15
+ lock-threads:
16
+ permissions:
17
+ issues: write
18
+ pull-requests: write
19
+ uses: fastify/workflows/.github/workflows/lock-threads.yml@v6
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017-present The Fastify team <https://github.com/fastify/fastify#team>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,188 @@
1
+ # fastify-plugin
2
+
3
+ [![CI](https://github.com/fastify/fastify-plugin/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/fastify-plugin/actions/workflows/ci.yml)
4
+ [![NPM version](https://img.shields.io/npm/v/fastify-plugin.svg?style=flat)](https://www.npmjs.com/package/fastify-plugin)
5
+ [![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)
6
+
7
+ `fastify-plugin` is a plugin helper for [Fastify](https://github.com/fastify/fastify).
8
+
9
+ When you build plugins for Fastify and you want them to be accessible in the same context where you require them, you have two ways:
10
+ 1. Use the `skip-override` hidden property
11
+ 2. Use this module
12
+
13
+ __Note: the v4.x series of this module covers Fastify v4__
14
+ __Note: the v2.x & v3.x series of this module covers Fastify v3. For Fastify v2 support, refer to the v1.x series.__
15
+
16
+ ## Install
17
+
18
+ ```sh
19
+ npm i fastify-plugin
20
+ ```
21
+
22
+ ## Usage
23
+ `fastify-plugin` can do three things for you:
24
+ - Add the `skip-override` hidden property
25
+ - Check the bare-minimum version of Fastify
26
+ - Pass some custom metadata of the plugin to Fastify
27
+
28
+ Example using a callback:
29
+ ```js
30
+ const fp = require('fastify-plugin')
31
+
32
+ module.exports = fp(function (fastify, opts, done) {
33
+ // your plugin code
34
+ done()
35
+ })
36
+ ```
37
+
38
+ Example using an [async](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) function:
39
+ ```js
40
+ const fp = require('fastify-plugin')
41
+
42
+ // A callback function param is not required for async functions
43
+ module.exports = fp(async function (fastify, opts) {
44
+ // Wait for an async function to fulfill promise before proceeding
45
+ await exampleAsyncFunction()
46
+ })
47
+ ```
48
+
49
+ ## Metadata
50
+ In addition, if you use this module when creating new plugins, you can declare the dependencies, the name, and the expected Fastify version that your plugin needs.
51
+
52
+ #### Fastify version
53
+ If you need to set a bare-minimum version of Fastify for your plugin, just add the [semver](https://semver.org/) range that you need:
54
+ ```js
55
+ const fp = require('fastify-plugin')
56
+
57
+ module.exports = fp(function (fastify, opts, done) {
58
+ // your plugin code
59
+ done()
60
+ }, { fastify: '5.x' })
61
+ ```
62
+
63
+ If you need to check the Fastify version only, you can pass just the version string.
64
+
65
+ You can check [here](https://github.com/npm/node-semver#ranges) how to define a `semver` range.
66
+
67
+ #### Name
68
+ Fastify uses this option to validate the dependency graph, allowing it to ensure that no name collisions occur and making it possible to perform [dependency checks](https://github.com/fastify/fastify-plugin#dependencies).
69
+
70
+ ```js
71
+ const fp = require('fastify-plugin')
72
+
73
+ function plugin (fastify, opts, done) {
74
+ // your plugin code
75
+ done()
76
+ }
77
+
78
+ module.exports = fp(plugin, {
79
+ fastify: '5.x',
80
+ name: 'your-plugin-name'
81
+ })
82
+ ```
83
+
84
+ #### Dependencies
85
+ You can also check if the `plugins` and `decorators` that your plugin intend to use are present in the dependency graph.
86
+ > *Note:* This is the point where registering `name` of the plugins become important, because you can reference `plugin` dependencies by their [name](https://github.com/fastify/fastify-plugin#name).
87
+ ```js
88
+ const fp = require('fastify-plugin')
89
+
90
+ function plugin (fastify, opts, done) {
91
+ // your plugin code
92
+ done()
93
+ }
94
+
95
+ module.exports = fp(plugin, {
96
+ fastify: '5.x',
97
+ decorators: {
98
+ fastify: ['plugin1', 'plugin2'],
99
+ reply: ['compress']
100
+ },
101
+ dependencies: ['plugin1-name', 'plugin2-name']
102
+ })
103
+ ```
104
+
105
+ #### Encapsulate
106
+
107
+ By default, `fastify-plugin` breaks the [encapsulation](https://github.com/fastify/fastify/blob/HEAD/docs/Reference/Encapsulation.md) but you can optionally keep the plugin encapsulated.
108
+ This allows you to set the plugin's name and validate its dependencies without making the plugin accessible.
109
+ ```js
110
+ const fp = require('fastify-plugin')
111
+
112
+ function plugin (fastify, opts, done) {
113
+ // the decorator is not accessible outside this plugin
114
+ fastify.decorate('util', function() {})
115
+ done()
116
+ }
117
+
118
+ module.exports = fp(plugin, {
119
+ name: 'my-encapsulated-plugin',
120
+ fastify: '5.x',
121
+ decorators: {
122
+ fastify: ['plugin1', 'plugin2'],
123
+ reply: ['compress']
124
+ },
125
+ dependencies: ['plugin1-name', 'plugin2-name'],
126
+ encapsulate: true
127
+ })
128
+ ```
129
+
130
+ #### Bundlers and Typescript
131
+ `fastify-plugin` adds a `.default` and `[name]` property to the passed in function.
132
+ The type definition would have to be updated to leverage this.
133
+
134
+ ## Known Issue: TypeScript Contextual Inference
135
+
136
+ [Documentation Reference](https://www.typescriptlang.org/docs/handbook/functions.html#inferring-the-types)
137
+
138
+ It is common for developers to inline their plugin with fastify-plugin such as:
139
+
140
+ ```js
141
+ fp((fastify, opts, done) => { done() })
142
+ fp(async (fastify, opts) => { return })
143
+ ```
144
+
145
+ TypeScript can sometimes infer the types of the arguments for these functions. Plugins in Fastify are recommended to be typed using either `FastifyPluginCallback` or `FastifyPluginAsync`. These two definitions only differ in two ways:
146
+
147
+ 1. The third argument `done` (the callback part)
148
+ 2. The return type `FastifyPluginCallback` or `FastifyPluginAsync`
149
+
150
+ At this time, TypeScript inference is not smart enough to differentiate by definition argument length alone.
151
+
152
+ Thus, if you are a TypeScript developer please use on the following patterns instead:
153
+
154
+ ```ts
155
+ // Callback
156
+
157
+ // Assign type directly
158
+ const pluginCallback: FastifyPluginCallback = (fastify, options, done) => { }
159
+ fp(pluginCallback)
160
+
161
+ // or define your own function declaration that satisfies the existing definitions
162
+ const pluginCallbackWithTypes = (fastify: FastifyInstance, options: FastifyPluginOptions, done: (error?: FastifyError) => void): void => { }
163
+ fp(pluginCallbackWithTypes)
164
+ // or inline
165
+ fp((fastify: FastifyInstance, options: FastifyPluginOptions, done: (error?: FastifyError) => void): void => { })
166
+
167
+ // Async
168
+
169
+ // Assign type directly
170
+ const pluginAsync: FastifyPluginAsync = async (fastify, options) => { }
171
+ fp(pluginAsync)
172
+
173
+ // or define your own function declaration that satisfies the existing definitions
174
+ const pluginAsyncWithTypes = async (fastify: FastifyInstance, options: FastifyPluginOptions): Promise<void> => { }
175
+ fp(pluginAsyncWithTypes)
176
+ // or inline
177
+ fp(async (fastify: FastifyInstance, options: FastifyPluginOptions): Promise<void> => { })
178
+ ```
179
+
180
+ ## Acknowledgments
181
+
182
+ This project is kindly sponsored by:
183
+ - [nearForm](https://nearform.com)
184
+ - [LetzDoIt](https://www.letzdoitapp.com/)
185
+
186
+ ## License
187
+
188
+ Licensed under [MIT](./LICENSE).
@@ -0,0 +1,6 @@
1
+ 'use strict'
2
+
3
+ module.exports = require('neostandard')({
4
+ ignores: require('neostandard').resolveIgnoresFromGitignore(),
5
+ ts: true
6
+ })
@@ -0,0 +1,67 @@
1
+ 'use strict'
2
+
3
+ const getPluginName = require('./lib/getPluginName')
4
+ const toCamelCase = require('./lib/toCamelCase')
5
+
6
+ let count = 0
7
+
8
+ function plugin (fn, options = {}) {
9
+ let autoName = false
10
+
11
+ if (fn.default !== undefined) {
12
+ // Support for 'export default' behaviour in transpiled ECMAScript module
13
+ fn = fn.default
14
+ }
15
+
16
+ if (typeof fn !== 'function') {
17
+ throw new TypeError(
18
+ `fastify-plugin expects a function, instead got a '${typeof fn}'`
19
+ )
20
+ }
21
+
22
+ if (typeof options === 'string') {
23
+ options = {
24
+ fastify: options
25
+ }
26
+ }
27
+
28
+ if (
29
+ typeof options !== 'object' ||
30
+ Array.isArray(options) ||
31
+ options === null
32
+ ) {
33
+ throw new TypeError('The options object should be an object')
34
+ }
35
+
36
+ if (options.fastify !== undefined && typeof options.fastify !== 'string') {
37
+ throw new TypeError(`fastify-plugin expects a version string, instead got '${typeof options.fastify}'`)
38
+ }
39
+
40
+ if (!options.name) {
41
+ autoName = true
42
+ options.name = getPluginName(fn) + '-auto-' + count++
43
+ }
44
+
45
+ fn[Symbol.for('skip-override')] = options.encapsulate !== true
46
+ fn[Symbol.for('fastify.display-name')] = options.name
47
+ fn[Symbol.for('plugin-meta')] = options
48
+
49
+ // Faux modules support
50
+ if (!fn.default) {
51
+ fn.default = fn
52
+ }
53
+
54
+ // TypeScript support for named imports
55
+ // See https://github.com/fastify/fastify/issues/2404 for more details
56
+ // The type definitions would have to be update to match this.
57
+ const camelCase = toCamelCase(options.name)
58
+ if (!autoName && !fn[camelCase]) {
59
+ fn[camelCase] = fn
60
+ }
61
+
62
+ return fn
63
+ }
64
+
65
+ module.exports = plugin
66
+ module.exports.default = plugin
67
+ module.exports.fastifyPlugin = plugin
@@ -0,0 +1,25 @@
1
+ 'use strict'
2
+
3
+ const fpStackTracePattern = /at\s(?:.*\.)?plugin\s.*\n\s*(.*)/
4
+ const fileNamePattern = /(\w*(\.\w*)*)\..*/
5
+
6
+ module.exports = function getPluginName (fn) {
7
+ if (fn.name.length > 0) return fn.name
8
+
9
+ const stackTraceLimit = Error.stackTraceLimit
10
+ Error.stackTraceLimit = 10
11
+ try {
12
+ throw new Error('anonymous function')
13
+ } catch (e) {
14
+ Error.stackTraceLimit = stackTraceLimit
15
+ return extractPluginName(e.stack)
16
+ }
17
+ }
18
+
19
+ function extractPluginName (stack) {
20
+ const m = stack.match(fpStackTracePattern)
21
+
22
+ // get last section of path and match for filename
23
+ return m ? m[1].split(/[/\\]/).slice(-1)[0].match(fileNamePattern)[1] : 'anonymous'
24
+ }
25
+ module.exports.extractPluginName = extractPluginName
@@ -0,0 +1,10 @@
1
+ 'use strict'
2
+
3
+ module.exports = function toCamelCase (name) {
4
+ if (name[0] === '@') {
5
+ name = name.slice(1).replace('/', '-')
6
+ }
7
+ return name.replace(/-(.)/g, function (match, g1) {
8
+ return g1.toUpperCase()
9
+ })
10
+ }
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "fastify-plugin",
3
+ "version": "6.0.0",
4
+ "description": "Plugin helper for Fastify",
5
+ "main": "index.js",
6
+ "type": "commonjs",
7
+ "types": "types/index.d.ts",
8
+ "scripts": {
9
+ "lint": "eslint",
10
+ "lint:fix": "eslint --fix",
11
+ "test": "npm run test:unit && npm run test:typescript",
12
+ "test:unit": "c8 --100 node --test",
13
+ "test:coverage": "c8 node --test && c8 report --reporter=html",
14
+ "test:typescript": "tstyche"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/fastify/fastify-plugin.git"
19
+ },
20
+ "keywords": [
21
+ "plugin",
22
+ "helper",
23
+ "fastify"
24
+ ],
25
+ "author": "Tomas Della Vedova - @delvedor (http://delved.org)",
26
+ "contributors": [
27
+ {
28
+ "name": "Matteo Collina",
29
+ "email": "hello@matteocollina.com"
30
+ },
31
+ {
32
+ "name": "Manuel Spigolon",
33
+ "email": "behemoth89@gmail.com"
34
+ },
35
+ {
36
+ "name": "Aras Abbasi",
37
+ "email": "aras.abbasi@gmail.com"
38
+ },
39
+ {
40
+ "name": "Frazer Smith",
41
+ "email": "frazer.dev@icloud.com",
42
+ "url": "https://github.com/fdawgs"
43
+ }
44
+ ],
45
+ "license": "MIT",
46
+ "bugs": {
47
+ "url": "https://github.com/fastify/fastify-plugin/issues"
48
+ },
49
+ "homepage": "https://github.com/fastify/fastify-plugin#readme",
50
+ "funding": [
51
+ {
52
+ "type": "github",
53
+ "url": "https://github.com/sponsors/fastify"
54
+ },
55
+ {
56
+ "type": "opencollective",
57
+ "url": "https://opencollective.com/fastify"
58
+ }
59
+ ],
60
+ "devDependencies": {
61
+ "@fastify/type-provider-typebox": "^6.0.0",
62
+ "@types/node": "^25.0.3",
63
+ "c8": "^11.0.0",
64
+ "eslint": "^9.17.0",
65
+ "fastify": "^5.0.0",
66
+ "neostandard": "^0.13.0",
67
+ "proxyquire": "^2.1.3",
68
+ "tstyche": "^7.0.0"
69
+ }
70
+ }