@zuplo/cli 6.72.2 → 6.72.7

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 (102) 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/posthog-core-stateless.d.ts +35 -2
  32. package/node_modules/@posthog/core/dist/posthog-core-stateless.d.ts.map +1 -1
  33. package/node_modules/@posthog/core/dist/posthog-core-stateless.js +68 -56
  34. package/node_modules/@posthog/core/dist/posthog-core-stateless.mjs +68 -56
  35. package/node_modules/@posthog/core/dist/posthog-core.d.ts +2 -1
  36. package/node_modules/@posthog/core/dist/posthog-core.d.ts.map +1 -1
  37. package/node_modules/@posthog/core/dist/posthog-core.js +1 -0
  38. package/node_modules/@posthog/core/dist/posthog-core.mjs +1 -0
  39. package/node_modules/@posthog/core/dist/types.d.ts +1 -0
  40. package/node_modules/@posthog/core/dist/types.d.ts.map +1 -1
  41. package/node_modules/@posthog/core/dist/types.js +1 -0
  42. package/node_modules/@posthog/core/dist/types.mjs +1 -0
  43. package/node_modules/@posthog/core/package.json +1 -1
  44. package/node_modules/@posthog/core/src/posthog-core-stateless.ts +135 -72
  45. package/node_modules/@posthog/core/src/posthog-core.ts +3 -1
  46. package/node_modules/@posthog/core/src/types.ts +5 -0
  47. package/node_modules/@zuplo/core/package.json +1 -1
  48. package/node_modules/@zuplo/graphql/package.json +1 -1
  49. package/node_modules/@zuplo/openapi-tools/dist/overlay.d.ts.map +1 -1
  50. package/node_modules/@zuplo/openapi-tools/dist/overlay.js +85 -1
  51. package/node_modules/@zuplo/openapi-tools/dist/overlay.js.map +1 -1
  52. package/node_modules/@zuplo/openapi-tools/dist/overlay.spec.js +82 -0
  53. package/node_modules/@zuplo/openapi-tools/dist/overlay.spec.js.map +1 -1
  54. package/node_modules/@zuplo/openapi-tools/package.json +1 -1
  55. package/node_modules/@zuplo/otel/out/esm/chunk-X7TLQJWO.js +26 -0
  56. package/node_modules/@zuplo/otel/out/esm/chunk-X7TLQJWO.js.map +1 -0
  57. package/node_modules/@zuplo/otel/out/esm/index.js +1 -1
  58. package/node_modules/@zuplo/otel/package.json +1 -1
  59. package/node_modules/@zuplo/runtime/out/esm/chunk-423FXHUV.js +399 -0
  60. package/node_modules/@zuplo/runtime/out/esm/chunk-423FXHUV.js.map +1 -0
  61. package/node_modules/@zuplo/runtime/out/esm/chunk-GBIUQ4JJ.js +30 -0
  62. package/node_modules/@zuplo/runtime/out/esm/chunk-GBIUQ4JJ.js.map +1 -0
  63. package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
  64. package/node_modules/@zuplo/runtime/out/esm/index.js.map +1 -1
  65. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +1 -1
  66. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js.map +1 -1
  67. package/node_modules/@zuplo/runtime/out/esm/sdks/aws/index.js +26 -0
  68. package/node_modules/@zuplo/runtime/out/esm/sdks/aws/index.js.map +1 -0
  69. package/node_modules/@zuplo/runtime/out/types/index.d.ts +1576 -288
  70. package/node_modules/@zuplo/runtime/out/types/mcp-gateway/index.d.ts +1374 -156
  71. package/node_modules/@zuplo/runtime/out/types/sdks/aws/index.d.ts +2281 -0
  72. package/node_modules/@zuplo/runtime/package.json +5 -1
  73. package/node_modules/hono/dist/adapter/aws-lambda/handler.js +1 -4
  74. package/node_modules/hono/dist/adapter/lambda-edge/handler.js +12 -2
  75. package/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +1 -4
  76. package/node_modules/hono/dist/cjs/adapter/lambda-edge/handler.js +12 -2
  77. package/node_modules/hono/dist/cjs/client/client.js +10 -1
  78. package/node_modules/hono/dist/cjs/client/utils.js +1 -1
  79. package/node_modules/hono/dist/cjs/middleware/cache/index.js +1 -1
  80. package/node_modules/hono/dist/cjs/middleware/compress/index.js +2 -1
  81. package/node_modules/hono/dist/cjs/middleware/etag/index.js +2 -1
  82. package/node_modules/hono/dist/cjs/middleware/method-override/index.js +5 -3
  83. package/node_modules/hono/dist/cjs/router/trie-router/node.js +9 -0
  84. package/node_modules/hono/dist/client/client.js +10 -1
  85. package/node_modules/hono/dist/client/utils.js +1 -1
  86. package/node_modules/hono/dist/middleware/cache/index.js +1 -1
  87. package/node_modules/hono/dist/middleware/compress/index.js +2 -1
  88. package/node_modules/hono/dist/middleware/etag/index.js +2 -1
  89. package/node_modules/hono/dist/middleware/method-override/index.js +5 -3
  90. package/node_modules/hono/dist/router/trie-router/node.js +9 -0
  91. package/node_modules/hono/dist/types/adapter/lambda-edge/handler.d.ts +1 -1
  92. package/node_modules/hono/dist/types/helper/websocket/index.d.ts +1 -1
  93. package/node_modules/hono/dist/types/middleware/language/language.d.ts +18 -0
  94. package/node_modules/hono/dist/types/utils/types.d.ts +1 -1
  95. package/node_modules/hono/package.json +4 -4
  96. package/package.json +6 -6
  97. package/node_modules/@fastify/reply-from/types/index.test-d.ts +0 -194
  98. package/node_modules/@zuplo/otel/out/esm/chunk-T25G5RDX.js +0 -26
  99. package/node_modules/@zuplo/otel/out/esm/chunk-T25G5RDX.js.map +0 -1
  100. package/node_modules/@zuplo/runtime/out/esm/chunk-IC7XGD5C.js +0 -403
  101. package/node_modules/@zuplo/runtime/out/esm/chunk-IC7XGD5C.js.map +0 -1
  102. /package/node_modules/@zuplo/runtime/out/esm/{chunk-IC7XGD5C.js.LEGAL.txt → chunk-423FXHUV.js.LEGAL.txt} +0 -0
@@ -0,0 +1,19 @@
1
+ import { FastifyPluginAsync } from 'fastify'
2
+
3
+ type FastifyExampleAsync = FastifyPluginAsync<fastifyExampleAsync.FastifyExampleAsyncOptions>
4
+
5
+ declare namespace fastifyExampleAsync {
6
+
7
+ export interface FastifyExampleAsyncOptions {
8
+ foo?: 'bar'
9
+ }
10
+
11
+ export interface FastifyExampleAsyncPluginOptions extends FastifyExampleAsyncOptions {
12
+ }
13
+ export const fastifyExampleAsync: FastifyExampleAsync
14
+ export { fastifyExampleAsync as default }
15
+ }
16
+
17
+ declare function fastifyExampleAsync (...params: Parameters<FastifyExampleAsync>): ReturnType<FastifyExampleAsync>
18
+
19
+ export default fastifyExampleAsync
@@ -0,0 +1,19 @@
1
+ import { FastifyPluginCallback } from 'fastify'
2
+
3
+ type FastifyExampleCallback = FastifyPluginCallback<fastifyExampleCallback.FastifyExampleCallbackOptions>
4
+
5
+ declare namespace fastifyExampleCallback {
6
+
7
+ export interface FastifyExampleCallbackOptions {
8
+ foo?: 'bar'
9
+ }
10
+
11
+ export interface FastifyExampleCallbackPluginOptions extends FastifyExampleCallbackOptions {
12
+ }
13
+ export const fastifyExampleCallback: FastifyExampleCallback
14
+ export { fastifyExampleCallback as default }
15
+ }
16
+
17
+ declare function fastifyExampleCallback (...params: Parameters<FastifyExampleCallback>): ReturnType<FastifyExampleCallback>
18
+
19
+ export default fastifyExampleCallback
@@ -0,0 +1,54 @@
1
+ import {
2
+ FastifyPluginCallback,
3
+ FastifyPluginAsync,
4
+ FastifyPluginOptions,
5
+ RawServerBase,
6
+ RawServerDefault,
7
+ FastifyTypeProvider,
8
+ FastifyTypeProviderDefault,
9
+ FastifyBaseLogger,
10
+ } from 'fastify'
11
+
12
+ type FastifyPlugin = typeof fastifyPlugin
13
+
14
+ declare namespace fastifyPlugin {
15
+ export interface PluginMetadata {
16
+ /** Bare-minimum version of Fastify for your plugin, just add the semver range that you need. */
17
+ fastify?: string,
18
+ name?: string,
19
+ /** Decorator dependencies for this plugin */
20
+ decorators?: {
21
+ fastify?: (string | symbol)[],
22
+ reply?: (string | symbol)[],
23
+ request?: (string | symbol)[]
24
+ },
25
+ /** The plugin dependencies */
26
+ dependencies?: string[],
27
+ encapsulate?: boolean
28
+ }
29
+
30
+ export const fastifyPlugin: FastifyPlugin
31
+ export { fastifyPlugin as default }
32
+ }
33
+
34
+ /**
35
+ * This function does three things for you:
36
+ * 1. Add the `skip-override` hidden property
37
+ * 2. Check bare-minimum version of Fastify
38
+ * 3. Pass some custom metadata of the plugin to Fastify
39
+ * @param fn Fastify plugin function
40
+ * @param options Optional plugin options
41
+ */
42
+
43
+ declare function fastifyPlugin<
44
+ Options extends FastifyPluginOptions = Record<never, never>,
45
+ RawServer extends RawServerBase = RawServerDefault,
46
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
47
+ Logger extends FastifyBaseLogger = FastifyBaseLogger,
48
+ Fn extends FastifyPluginCallback<Options, RawServer, TypeProvider, Logger> | FastifyPluginAsync<Options, RawServer, TypeProvider, Logger> = FastifyPluginCallback<Options, RawServer, TypeProvider, Logger>
49
+ > (
50
+ fn: Fn extends unknown ? Fn extends (...args: any) => Promise<any> ? FastifyPluginAsync<Options, RawServer, TypeProvider, Logger> : FastifyPluginCallback<Options, RawServer, TypeProvider, Logger> : Fn,
51
+ options?: fastifyPlugin.PluginMetadata | string
52
+ ): Fn
53
+
54
+ export = fastifyPlugin
@@ -0,0 +1,249 @@
1
+ import { expect } from 'tstyche'
2
+ import fastifyPlugin from '.'
3
+ import fastify, {
4
+ FastifyPluginCallback,
5
+ FastifyPluginAsync,
6
+ FastifyError,
7
+ FastifyInstance,
8
+ FastifyPluginOptions,
9
+ RawServerDefault,
10
+ FastifyTypeProviderDefault,
11
+ FastifyBaseLogger
12
+ } from 'fastify'
13
+ import { Server } from 'node:https'
14
+ import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox'
15
+ import fastifyExampleCallback from './example-callback.tst'
16
+ import fastifyExampleAsync from './example-async.tst'
17
+
18
+ interface Options {
19
+ foo: string;
20
+ }
21
+
22
+ const testSymbol = Symbol('foobar')
23
+
24
+ const pluginCallback: FastifyPluginCallback = (_fastify, _options, _next) => {}
25
+ expect(fastifyPlugin(pluginCallback)).type.toBe<FastifyPluginCallback>()
26
+
27
+ const pluginCallbackWithTypes = (
28
+ _fastify: FastifyInstance,
29
+ _options: FastifyPluginOptions,
30
+ _next: (error?: FastifyError) => void
31
+ ): void => {}
32
+ expect(
33
+ fastifyPlugin(pluginCallbackWithTypes)
34
+ ).type.toBeAssignableTo<FastifyPluginCallback>()
35
+
36
+ expect(
37
+ fastifyPlugin(
38
+ (
39
+ _fastify: FastifyInstance,
40
+ _options: FastifyPluginOptions,
41
+ _next: (error?: FastifyError) => void
42
+ ): void => {}
43
+ )
44
+ ).type.toBeAssignableTo<FastifyPluginCallback>()
45
+
46
+ expect(fastifyPlugin(pluginCallback, '')).type.toBe<FastifyPluginCallback>()
47
+ expect(
48
+ fastifyPlugin(pluginCallback, {
49
+ fastify: '',
50
+ name: '',
51
+ decorators: {
52
+ fastify: ['', testSymbol],
53
+ reply: ['', testSymbol],
54
+ request: ['', testSymbol]
55
+ },
56
+ dependencies: [''],
57
+ encapsulate: true
58
+ })
59
+ ).type.toBe<FastifyPluginCallback>()
60
+
61
+ const pluginCallbackWithOptions: FastifyPluginCallback<Options> = (
62
+ _fastify,
63
+ options,
64
+ _next
65
+ ) => {
66
+ expect(options.foo).type.toBe<string>()
67
+ }
68
+ expect(fastifyPlugin(pluginCallbackWithOptions)).type.toBe<
69
+ FastifyPluginCallback<Options>
70
+ >()
71
+
72
+ const pluginCallbackWithServer: FastifyPluginCallback<Options, Server> = (
73
+ fastify,
74
+ _options,
75
+ _next
76
+ ) => {
77
+ expect(fastify.server).type.toBe<Server>()
78
+ }
79
+ expect(fastifyPlugin(pluginCallbackWithServer)).type.toBe<
80
+ FastifyPluginCallback<Options, Server>
81
+ >()
82
+
83
+ const pluginCallbackWithTypeProvider: FastifyPluginCallback<
84
+ Options,
85
+ Server,
86
+ TypeBoxTypeProvider
87
+ > = (_fastify, _options, _next) => {}
88
+ expect(fastifyPlugin(pluginCallbackWithTypeProvider)).type.toBe<
89
+ FastifyPluginCallback<Options, Server, TypeBoxTypeProvider>
90
+ >();
91
+
92
+ (async () => {
93
+ const pluginAsync: FastifyPluginAsync = async (_fastify, _options) => {}
94
+ expect(fastifyPlugin(pluginAsync)).type.toBe<FastifyPluginAsync>()
95
+
96
+ const pluginAsyncWithTypes = async (
97
+ _fastify: FastifyInstance,
98
+ _options: FastifyPluginOptions
99
+ ): Promise<void> => {}
100
+ expect(fastifyPlugin(pluginAsyncWithTypes)).type.toBe<
101
+ FastifyPluginAsync<
102
+ FastifyPluginOptions,
103
+ RawServerDefault,
104
+ FastifyTypeProviderDefault
105
+ >
106
+ >()
107
+
108
+ expect(
109
+ fastifyPlugin(
110
+ async (
111
+ _fastify: FastifyInstance,
112
+ _options: FastifyPluginOptions
113
+ ): Promise<void> => {}
114
+ )
115
+ ).type.toBe<
116
+ FastifyPluginAsync<
117
+ FastifyPluginOptions,
118
+ RawServerDefault,
119
+ FastifyTypeProviderDefault
120
+ >
121
+ >()
122
+
123
+ expect(fastifyPlugin(pluginAsync, '')).type.toBe<FastifyPluginAsync>()
124
+ expect(
125
+ fastifyPlugin(pluginAsync, {
126
+ fastify: '',
127
+ name: '',
128
+ decorators: {
129
+ fastify: ['', testSymbol],
130
+ reply: ['', testSymbol],
131
+ request: ['', testSymbol]
132
+ },
133
+ dependencies: [''],
134
+ encapsulate: true
135
+ })
136
+ ).type.toBe<FastifyPluginAsync>()
137
+
138
+ const pluginAsyncWithOptions: FastifyPluginAsync<Options> = async (
139
+ _fastify,
140
+ options
141
+ ) => {
142
+ expect(options.foo).type.toBe<string>()
143
+ }
144
+ expect(fastifyPlugin(pluginAsyncWithOptions)).type.toBe<
145
+ FastifyPluginAsync<Options>
146
+ >()
147
+
148
+ const pluginAsyncWithServer: FastifyPluginAsync<Options, Server> = async (
149
+ fastify,
150
+ _options
151
+ ) => {
152
+ expect(fastify.server).type.toBe<Server>()
153
+ }
154
+ expect(fastifyPlugin(pluginAsyncWithServer)).type.toBe<
155
+ FastifyPluginAsync<Options, Server>
156
+ >()
157
+
158
+ const pluginAsyncWithTypeProvider: FastifyPluginAsync<
159
+ Options,
160
+ Server,
161
+ TypeBoxTypeProvider
162
+ > = async (_fastify, _options) => {}
163
+ expect(fastifyPlugin(pluginAsyncWithTypeProvider)).type.toBe<
164
+ FastifyPluginAsync<Options, Server, TypeBoxTypeProvider>
165
+ >()
166
+
167
+ const server = fastify()
168
+ server.register(fastifyPlugin(pluginCallback))
169
+ server.register(fastifyPlugin(pluginCallbackWithTypes), { foo: 'bar' })
170
+ server.register(fastifyPlugin(pluginCallbackWithOptions), { foo: 'bar' })
171
+ server.register(fastifyPlugin(pluginCallbackWithServer), { foo: 'bar' })
172
+ server.register(fastifyPlugin(pluginCallbackWithTypeProvider), {
173
+ foo: 'bar'
174
+ })
175
+ server.register(fastifyPlugin(pluginAsync))
176
+ server.register(fastifyPlugin(pluginAsyncWithTypes), { foo: 'bar' })
177
+ server.register(fastifyPlugin(pluginAsyncWithOptions), { foo: 'bar' })
178
+ server.register(fastifyPlugin(pluginAsyncWithServer), { foo: 'bar' })
179
+ server.register(fastifyPlugin(pluginAsyncWithTypeProvider), { foo: 'bar' })
180
+
181
+ // Handling Callback and Async Inline
182
+ fastifyPlugin(function (fastify, options, next) {
183
+ expect(fastify).type.toBe<FastifyInstance>()
184
+ expect(options).type.toBe<Record<never, never>>()
185
+ expect(next).type.toBe<(err?: Error) => void>()
186
+ })
187
+
188
+ fastifyPlugin<Options>(function (fastify, options, next) {
189
+ expect(fastify).type.toBe<FastifyInstance>()
190
+ expect(options).type.toBe<Options>()
191
+ expect(next).type.toBe<(err?: Error) => void>()
192
+ })
193
+
194
+ fastifyPlugin<Options>(async function (fastify, options) {
195
+ expect(fastify).type.toBe<FastifyInstance>()
196
+ expect(options).type.toBe<Options>()
197
+ })
198
+
199
+ expect(
200
+ fastifyPlugin(async function (
201
+ _fastify: FastifyInstance,
202
+ _options: Options
203
+ ) {})
204
+ ).type.toBeAssignableTo<
205
+ FastifyPluginAsync<
206
+ Options,
207
+ RawServerDefault,
208
+ FastifyTypeProviderDefault,
209
+ FastifyBaseLogger
210
+ >
211
+ >()
212
+
213
+ fastifyPlugin(async function (fastify, options: Options) {
214
+ expect(fastify).type.toBe<FastifyInstance>()
215
+ expect(options).type.toBe<Options>()
216
+ })
217
+
218
+ fastifyPlugin(async function (fastify, options) {
219
+ expect(fastify).type.toBe<FastifyInstance>()
220
+ expect(options).type.toBe<Record<never, never>>()
221
+ })
222
+
223
+ // @ts-expect-error Target signature provides too few arguments
224
+ fastifyPlugin(async function (fastify, options, next) {})
225
+
226
+ expect(
227
+ fastifyPlugin(function (_fastify, _options, _next) {})
228
+ ).type.toBeAssignableTo<FastifyPluginCallback<Options>>()
229
+
230
+ fastifyPlugin(function (fastify, options: Options, next) {
231
+ expect(fastify).type.toBe<FastifyInstance>()
232
+ expect(options).type.toBe<Options>()
233
+ expect(next).type.toBe<(err?: Error) => void>()
234
+ })
235
+
236
+ // @ts-expect-error Target signature provides too few arguments
237
+ fastifyPlugin(function (fastify, options, next) {
238
+ return Promise.resolve()
239
+ })
240
+
241
+ server.register(fastifyExampleCallback, { foo: 'bar' })
242
+ expect(server.register).type.not.toBeCallableWith(fastifyExampleCallback, {
243
+ foo: 'baz'
244
+ })
245
+ server.register(fastifyExampleAsync, { foo: 'bar' })
246
+ expect(server.register).type.not.toBeCallableWith(fastifyExampleAsync, {
247
+ foo: 'baz'
248
+ })
249
+ })()
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastify/reply-from",
3
- "version": "12.6.2",
3
+ "version": "12.6.3",
4
4
  "description": "forward your HTTP request to another server, for fastify",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -10,7 +10,7 @@
10
10
  "lint:fix": "eslint --fix",
11
11
  "test": "npm run test:unit && npm run test:typescript",
12
12
  "test:unit": "c8 node --test --test-timeout=30000",
13
- "test:typescript": "tsd"
13
+ "test:typescript": "tstyche"
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
@@ -59,10 +59,9 @@
59
59
  ],
60
60
  "devDependencies": {
61
61
  "@fastify/formbody": "^8.0.0",
62
- "@fastify/multipart": "^9.0.0",
62
+ "@fastify/multipart": "^10.0.0",
63
63
  "@sinonjs/fake-timers": "^15.0.0",
64
- "@types/node": "^25.0.3",
65
- "@types/tap": "^18.0.0",
64
+ "@types/node": "^26.0.0",
66
65
  "c8": "^11.0.0",
67
66
  "eslint": "^9.17.0",
68
67
  "fastify": "^5.0.0",
@@ -73,14 +72,14 @@
73
72
  "proxy": "^4.0.0",
74
73
  "proxyquire": "^2.1.3",
75
74
  "split2": "^4.2.0",
76
- "tsd": "^0.33.0"
75
+ "tstyche": "^7.0.0"
77
76
  },
78
77
  "dependencies": {
79
78
  "@fastify/error": "^4.0.0",
80
79
  "end-of-stream": "^1.4.4",
81
80
  "fast-content-type-parse": "^3.0.0",
82
81
  "fast-querystring": "^1.1.2",
83
- "fastify-plugin": "^5.0.1",
82
+ "fastify-plugin": "^6.0.0",
84
83
  "toad-cache": "^3.7.0",
85
84
  "undici": "^7.0.0"
86
85
  },
@@ -0,0 +1,142 @@
1
+ 'use strict'
2
+
3
+ const { once } = require('node:events')
4
+ const http = require('node:http')
5
+ const net = require('node:net')
6
+ const t = require('node:test')
7
+ const Fastify = require('fastify')
8
+ const From = require('..')
9
+
10
+ for (const [name, options] of [
11
+ ['undici', {}],
12
+ ['node:http', { undici: false }]
13
+ ]) {
14
+ t.test(`closes the downstream connection when ${name} responds before the request is complete`, async (t) => {
15
+ const target = http.createServer((_req, res) => {
16
+ res.end('early')
17
+ })
18
+ const instance = Fastify()
19
+
20
+ t.after(async () => {
21
+ instance.server.closeAllConnections()
22
+ target.closeAllConnections()
23
+ await instance.close()
24
+ if (target.listening) await new Promise(resolve => target.close(resolve))
25
+ })
26
+
27
+ await new Promise(resolve => target.listen({ port: 0 }, resolve))
28
+
29
+ instance.register(From, options)
30
+ instance.addContentTypeParser('application/octet-stream', function (_request, payload, done) {
31
+ done(null, payload)
32
+ })
33
+ instance.post('/', (_request, reply) => {
34
+ reply.from(`http://localhost:${target.address().port}`)
35
+ })
36
+ await instance.listen({ port: 0 })
37
+
38
+ const socket = net.connect(instance.server.address().port, '127.0.0.1')
39
+ t.after(() => socket.destroy())
40
+ await once(socket, 'connect')
41
+
42
+ const responsePromise = new Promise((resolve, reject) => {
43
+ let response = ''
44
+ const timeout = setTimeout(() => {
45
+ reject(new Error('downstream connection was not closed'))
46
+ }, 5000)
47
+
48
+ socket.on('data', chunk => {
49
+ response += chunk.toString('latin1')
50
+ })
51
+ socket.once('error', err => {
52
+ clearTimeout(timeout)
53
+ reject(err)
54
+ })
55
+ socket.once('close', () => {
56
+ clearTimeout(timeout)
57
+ resolve(response)
58
+ })
59
+ })
60
+
61
+ socket.write([
62
+ 'POST / HTTP/1.1',
63
+ 'Host: localhost',
64
+ 'Content-Type: application/octet-stream',
65
+ 'Content-Length: 1048576',
66
+ 'Connection: keep-alive',
67
+ '',
68
+ 'a'
69
+ ].join('\r\n'))
70
+
71
+ const response = await responsePromise
72
+ t.assert.match(response, /^HTTP\/1\.1 200 OK\r\n/)
73
+ t.assert.match(response, /\r\nconnection: close\r\n/i)
74
+ t.assert.match(response, /\r\n\r\nearly$/)
75
+ })
76
+
77
+ t.test(`keeps the downstream connection reusable after ${name} consumes the request`, async (t) => {
78
+ const target = http.createServer((req, res) => {
79
+ req.resume()
80
+ req.on('end', () => res.end('complete'))
81
+ })
82
+ const agent = new http.Agent({ keepAlive: true, maxSockets: 1 })
83
+ const instance = Fastify()
84
+
85
+ t.after(async () => {
86
+ agent.destroy()
87
+ instance.server.closeAllConnections()
88
+ target.closeAllConnections()
89
+ await instance.close()
90
+ if (target.listening) await new Promise(resolve => target.close(resolve))
91
+ })
92
+
93
+ await new Promise(resolve => target.listen({ port: 0 }, resolve))
94
+
95
+ instance.register(From, options)
96
+ instance.addContentTypeParser('application/octet-stream', function (_request, payload, done) {
97
+ done(null, payload)
98
+ })
99
+ instance.post('/', (_request, reply) => {
100
+ reply.from(`http://localhost:${target.address().port}`)
101
+ })
102
+ await instance.listen({ port: 0 })
103
+
104
+ const first = await makeRequest(instance.server.address().port, agent, 'first')
105
+ t.assert.notStrictEqual(first.headers.connection, 'close')
106
+
107
+ const second = await makeRequest(instance.server.address().port, agent, 'second')
108
+ t.assert.strictEqual(second.reusedSocket, true)
109
+ t.assert.strictEqual(second.body, 'complete')
110
+ })
111
+ }
112
+
113
+ function makeRequest (port, agent, body) {
114
+ return new Promise((resolve, reject) => {
115
+ const req = http.request({
116
+ agent,
117
+ method: 'POST',
118
+ hostname: '127.0.0.1',
119
+ port,
120
+ path: '/',
121
+ headers: {
122
+ 'content-length': Buffer.byteLength(body),
123
+ 'content-type': 'application/octet-stream'
124
+ }
125
+ }, res => {
126
+ let responseBody = ''
127
+ res.setEncoding('utf8')
128
+ res.on('data', chunk => {
129
+ responseBody += chunk
130
+ })
131
+ res.on('end', () => {
132
+ resolve({
133
+ body: responseBody,
134
+ headers: res.headers,
135
+ reusedSocket: req.reusedSocket
136
+ })
137
+ })
138
+ })
139
+ req.on('error', reject)
140
+ req.end(body)
141
+ })
142
+ }
@@ -0,0 +1,123 @@
1
+ import { expect } from 'tstyche'
2
+ import fastify, {
3
+ type FastifyReply,
4
+ type FastifyRequest,
5
+ type RawServerBase,
6
+ type RequestGenericInterface,
7
+ type RouteGenericInterface
8
+ } from 'fastify'
9
+ import * as http from 'node:http'
10
+ import { type IncomingHttpHeaders } from 'node:http2'
11
+ import * as https from 'node:https'
12
+ import { Agent, Client, Dispatcher, Pool } from 'undici'
13
+ import replyFrom, {
14
+ type FastifyReplyFromOptions,
15
+ type RawServerResponse
16
+ } from '.'
17
+
18
+ const fullOptions: FastifyReplyFromOptions = {
19
+ base: 'http://example2.com',
20
+ http: {
21
+ agentOptions: {
22
+ keepAliveMsecs: 60 * 1000,
23
+ maxFreeSockets: 2048,
24
+ maxSockets: 2048
25
+ },
26
+ requestOptions: { timeout: 1000 },
27
+ agents: {
28
+ 'http:': new http.Agent({}),
29
+ 'https:': new https.Agent({})
30
+ }
31
+ },
32
+ http2: {
33
+ sessionTimeout: 1000,
34
+ requestTimeout: 1000,
35
+ sessionOptions: { rejectUnauthorized: true },
36
+ requestOptions: { endStream: true }
37
+ },
38
+ cacheURLs: 100,
39
+ disableCache: false,
40
+ undici: {
41
+ connections: 100,
42
+ pipelining: 10,
43
+ proxy: 'http://example2.com:8080'
44
+ },
45
+ contentTypesToEncode: ['application/x-www-form-urlencoded'],
46
+ retryMethods: ['GET', 'HEAD', 'OPTIONS', 'TRACE'],
47
+ maxRetriesOn503: 10,
48
+ disableRequestLogging: false,
49
+ globalAgent: false,
50
+ destroyAgent: true
51
+ }
52
+
53
+ const app = fastify()
54
+
55
+ app.register(replyFrom)
56
+ app.register(replyFrom, {})
57
+ app.register(replyFrom, { http2: true })
58
+ app.register(replyFrom, fullOptions)
59
+ app.register(replyFrom, { undici: { proxy: new URL('http://example2.com:8080') } })
60
+ app.register(replyFrom, { undici: { proxy: { uri: 'http://example2.com:8080' } } })
61
+
62
+ app.register(replyFrom, { base: 'http://example.com', undici: new Agent() })
63
+ app.register(replyFrom, { base: 'http://example.com', undici: new Pool('http://example.com') })
64
+ app.register(replyFrom, { base: 'http://example.com', undici: new Client('http://example.com') })
65
+ app.register(replyFrom, { base: 'http://example.com', undici: new Dispatcher() })
66
+
67
+ app.get('/v1', (_request, reply) => {
68
+ expect(reply.from()).type.toBe<FastifyReply>()
69
+ })
70
+
71
+ app.get('/v3', (_request, reply) => {
72
+ reply.from('/v3', {
73
+ timeout: 1000,
74
+ body: { hello: 'world' },
75
+ rewriteRequestHeaders (req, headers) {
76
+ expect(req).type.toBe<FastifyRequest<RequestGenericInterface, RawServerBase>>()
77
+ return headers
78
+ },
79
+ getUpstream (req, base) {
80
+ expect(req).type.toBe<FastifyRequest<RequestGenericInterface, RawServerBase>>()
81
+ return base
82
+ },
83
+ onResponse (request, reply, res) {
84
+ expect(request).type.toBe<FastifyRequest<RequestGenericInterface, RawServerBase>>()
85
+ expect(reply).type.toBe<FastifyReply<RouteGenericInterface, RawServerBase>>()
86
+ expect(res).type.toBe<RawServerResponse<RawServerBase>>()
87
+ expect(res.statusCode).type.toBe<number>()
88
+ }
89
+ })
90
+ })
91
+
92
+ app.get('/http2', (_request, reply) => {
93
+ reply.from('/', {
94
+ method: 'POST',
95
+ retryDelay: ({ req, res, err, attempt, getDefaultDelay }) => {
96
+ const defaultDelay = getDefaultDelay(req, res, err, attempt)
97
+ expect(defaultDelay).type.toBe<number | null>()
98
+
99
+ if (res && res.statusCode === 500 && req.method === 'GET') {
100
+ return 300
101
+ }
102
+ return null
103
+ },
104
+ rewriteHeaders (headers) {
105
+ return headers
106
+ },
107
+ rewriteRequestHeaders (_req, headers: IncomingHttpHeaders) {
108
+ return headers
109
+ },
110
+ onError (reply: FastifyReply<RouteGenericInterface, RawServerBase>, error) {
111
+ return reply.send(error.error)
112
+ },
113
+ queryString (search, reqUrl, request) {
114
+ expect(search).type.toBe<string | undefined>()
115
+ expect(reqUrl).type.toBe<string>()
116
+ expect(request).type.toBe<FastifyRequest<RequestGenericInterface, RawServerBase>>()
117
+ return ''
118
+ },
119
+ })
120
+ })
121
+
122
+ expect<FastifyReplyFromOptions>().type.toBeAssignableFrom(fullOptions)
123
+ expect<FastifyReplyFromOptions>().type.toBeAssignableFrom({ http2: true })