@teammy/server 0.2.8 → 0.2.10
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.
- package/dist/main.js +3744 -1673
- package/dist/web/assets/Assistant-C9Zo5FN_.js +1 -0
- package/dist/web/assets/Computers-DNIWiHu4.js +5 -0
- package/dist/web/assets/Computers-XUdWIkZr.css +1 -0
- package/dist/web/assets/{Conversation-CNmGkVy7.css → Conversation-BVNmvuHR.css} +1 -1
- package/dist/web/assets/Conversation-DiVjLVVt.js +1 -0
- package/dist/web/assets/Dashboard-C6M9c0SB.js +1 -0
- package/dist/web/assets/Dashboard-ChX6TZDn.css +1 -0
- package/dist/web/assets/Dropdown-BnYLBw2s.js +55 -0
- package/dist/web/assets/Files-CQcAEYH9.js +1 -0
- package/dist/web/assets/{Help-DwUoT8ZM.js → Help-CDOqVRjJ.js} +158 -37
- package/dist/web/assets/HtmlPreview-BzvYKdju.js +1 -0
- package/dist/web/assets/{Markdown-DorC2YjE.js → Markdown-zJQlHcvy.js} +4 -4
- package/dist/web/assets/MessageComposer-CBI6RiJq.js +1 -0
- package/dist/web/assets/MessageComposer-CJGxkvML.css +1 -0
- package/dist/web/assets/ResourceLibrary-CEFCe7QW.js +6 -0
- package/dist/web/assets/TerminalPane-BrSy-0jI.css +1 -0
- package/dist/web/assets/TerminalPane-GU69G9Ak.js +22 -0
- package/dist/web/assets/WorkspaceTree-BhDZe1go.js +1 -0
- package/dist/web/assets/file-links-V3R--z0b.js +1 -0
- package/dist/web/assets/index-D9m13C7l.js +12 -0
- package/dist/web/assets/index-qX1GRw9I.css +1 -0
- package/dist/web/assets/teammy-logo-dark-GROHRRMa.svg +6 -0
- package/dist/web/assets/teammy-logo-light-B6BoNVcp.svg +6 -0
- package/dist/web/assets/teammy-y-standard-dark-C4LRaRpE.svg +6 -0
- package/dist/web/assets/teammy-y-standard-light-Bl5D78Uj.svg +6 -0
- package/dist/web/downloads/teammy-inbox-skill.zip +0 -0
- package/dist/web/downloads/teammy-skill.zip +0 -0
- package/dist/web/index.html +10 -3
- package/node_modules/@fastify/websocket/.gitattributes +2 -0
- package/node_modules/@fastify/websocket/.github/dependabot.yml +53 -0
- package/node_modules/@fastify/websocket/.github/workflows/ci.yml +33 -0
- package/node_modules/@fastify/websocket/.github/workflows/lock-threads.yml +19 -0
- package/node_modules/@fastify/websocket/.github/workflows/release.yml +24 -0
- package/node_modules/@fastify/websocket/LICENSE +21 -0
- package/node_modules/@fastify/websocket/README.md +393 -0
- package/node_modules/@fastify/websocket/eslint.config.js +6 -0
- package/node_modules/@fastify/websocket/index.js +276 -0
- package/node_modules/@fastify/websocket/package.json +79 -0
- package/node_modules/@fastify/websocket/test/base.test.js +785 -0
- package/node_modules/@fastify/websocket/test/hooks.test.js +414 -0
- package/node_modules/@fastify/websocket/test/inject.test.js +174 -0
- package/node_modules/@fastify/websocket/test/router.test.js +890 -0
- package/node_modules/@fastify/websocket/tsconfig.json +3 -0
- package/node_modules/@fastify/websocket/types/index.d.ts +128 -0
- package/node_modules/@fastify/websocket/types/index.tst.ts +261 -0
- package/node_modules/duplexify/.travis.yml +9 -0
- package/node_modules/duplexify/LICENSE +21 -0
- package/node_modules/duplexify/README.md +97 -0
- package/node_modules/duplexify/example.js +21 -0
- package/node_modules/duplexify/index.js +238 -0
- package/node_modules/duplexify/package.json +39 -0
- package/node_modules/duplexify/test.js +339 -0
- package/node_modules/end-of-stream/LICENSE +21 -0
- package/node_modules/end-of-stream/README.md +54 -0
- package/node_modules/end-of-stream/index.js +96 -0
- package/node_modules/end-of-stream/package.json +37 -0
- package/node_modules/once/LICENSE +15 -0
- package/node_modules/once/README.md +79 -0
- package/node_modules/once/once.js +42 -0
- package/node_modules/once/package.json +33 -0
- package/node_modules/readable-stream/CONTRIBUTING.md +38 -0
- package/node_modules/readable-stream/GOVERNANCE.md +136 -0
- package/node_modules/readable-stream/LICENSE +47 -0
- package/node_modules/readable-stream/README.md +106 -0
- package/node_modules/readable-stream/errors-browser.js +127 -0
- package/node_modules/readable-stream/errors.js +116 -0
- package/node_modules/readable-stream/experimentalWarning.js +17 -0
- package/node_modules/readable-stream/lib/_stream_duplex.js +126 -0
- package/node_modules/readable-stream/lib/_stream_passthrough.js +37 -0
- package/node_modules/readable-stream/lib/_stream_readable.js +1027 -0
- package/node_modules/readable-stream/lib/_stream_transform.js +190 -0
- package/node_modules/readable-stream/lib/_stream_writable.js +641 -0
- package/node_modules/readable-stream/lib/internal/streams/async_iterator.js +180 -0
- package/node_modules/readable-stream/lib/internal/streams/buffer_list.js +183 -0
- package/node_modules/readable-stream/lib/internal/streams/destroy.js +96 -0
- package/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +86 -0
- package/node_modules/readable-stream/lib/internal/streams/from-browser.js +3 -0
- package/node_modules/readable-stream/lib/internal/streams/from.js +52 -0
- package/node_modules/readable-stream/lib/internal/streams/pipeline.js +86 -0
- package/node_modules/readable-stream/lib/internal/streams/state.js +22 -0
- package/node_modules/readable-stream/lib/internal/streams/stream-browser.js +1 -0
- package/node_modules/readable-stream/lib/internal/streams/stream.js +1 -0
- package/node_modules/readable-stream/package.json +68 -0
- package/node_modules/readable-stream/readable-browser.js +9 -0
- package/node_modules/readable-stream/readable.js +16 -0
- package/node_modules/stream-shift/.github/workflows/test.yml +23 -0
- package/node_modules/stream-shift/LICENSE +21 -0
- package/node_modules/stream-shift/README.md +25 -0
- package/node_modules/stream-shift/index.js +21 -0
- package/node_modules/stream-shift/package.json +25 -0
- package/node_modules/stream-shift/test.js +48 -0
- package/node_modules/string_decoder/LICENSE +48 -0
- package/node_modules/string_decoder/README.md +47 -0
- package/node_modules/string_decoder/lib/string_decoder.js +296 -0
- package/node_modules/string_decoder/package.json +34 -0
- package/node_modules/util-deprecate/History.md +16 -0
- package/node_modules/util-deprecate/LICENSE +24 -0
- package/node_modules/util-deprecate/README.md +53 -0
- package/node_modules/util-deprecate/browser.js +67 -0
- package/node_modules/util-deprecate/node.js +6 -0
- package/node_modules/util-deprecate/package.json +27 -0
- package/node_modules/wrappy/LICENSE +15 -0
- package/node_modules/wrappy/README.md +36 -0
- package/node_modules/wrappy/package.json +29 -0
- package/node_modules/wrappy/wrappy.js +33 -0
- package/package.json +15 -2
- package/dist/web/assets/Assistant-CYSa4zNi.js +0 -1
- package/dist/web/assets/Computers-4L48XuFg.js +0 -4
- package/dist/web/assets/Computers-_ugR447I.css +0 -1
- package/dist/web/assets/Conversation-BBWm5w-C.js +0 -1
- package/dist/web/assets/Dashboard-Bdh00JcC.css +0 -1
- package/dist/web/assets/Dashboard-Ck2NsAbX.js +0 -1
- package/dist/web/assets/Files-CjNjoKS3.js +0 -1
- package/dist/web/assets/HtmlPreview-B6aQIaMB.js +0 -1
- package/dist/web/assets/MessageComposer-DQBDG5yF.js +0 -1
- package/dist/web/assets/MessageComposer-DavJdQPa.css +0 -1
- package/dist/web/assets/ResourceLibrary-104NuVRn.js +0 -6
- package/dist/web/assets/WorkspaceTree-B4FMRlCw.js +0 -1
- package/dist/web/assets/file-links-DnngiTbC.js +0 -1
- package/dist/web/assets/index-6PvvMCD7.css +0 -1
- package/dist/web/assets/index-DiR0ePCJ.js +0 -66
- package/dist/web/assets/teammy-calm-DVuoOK0F.png +0 -0
- package/dist/web/assets/teammy-favicon-BiDvlPj2.png +0 -0
- package/dist/web/assets/teammy-mark-CxBtF1-X.png +0 -0
- package/dist/web/assets/teammy-wave-CVTgecuC.png +0 -0
- package/dist/web/assets/teammy-wordmark-ZFwxG0yl.png +0 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import * as fastify from 'fastify'
|
|
2
|
+
import { ContextConfigDefault, FastifyBaseLogger, FastifyInstance, FastifyPluginCallback, FastifyRequest, FastifySchema, FastifyTypeProvider, FastifyTypeProviderDefault, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault, RequestGenericInterface } from 'fastify'
|
|
3
|
+
import { preCloseAsyncHookHandler, preCloseHookHandler } from 'fastify/types/hooks'
|
|
4
|
+
import { FastifyReply } from 'fastify/types/reply'
|
|
5
|
+
import { RouteGenericInterface } from 'fastify/types/route'
|
|
6
|
+
import { IncomingMessage, Server, ServerResponse } from 'node:http'
|
|
7
|
+
import * as WebSocket from 'ws'
|
|
8
|
+
|
|
9
|
+
interface WebsocketRouteOptions<
|
|
10
|
+
RawServer extends RawServerBase = RawServerDefault,
|
|
11
|
+
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
|
12
|
+
RequestGeneric extends RequestGenericInterface = RequestGenericInterface,
|
|
13
|
+
ContextConfig = ContextConfigDefault,
|
|
14
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
15
|
+
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
16
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
17
|
+
> {
|
|
18
|
+
wsHandler?: fastifyWebsocket.WebsocketHandler<RawServer, RawRequest, RequestGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare module 'fastify' {
|
|
22
|
+
interface RouteShorthandOptions<
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
24
|
+
RawServer extends RawServerBase = RawServerDefault
|
|
25
|
+
> {
|
|
26
|
+
websocket?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface InjectWSOption {
|
|
30
|
+
onInit?: (ws: WebSocket.WebSocket) => void
|
|
31
|
+
onOpen?: (ws: WebSocket.WebSocket) => void
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type InjectWSFn<RawRequest> =
|
|
35
|
+
((path?: string, upgradeContext?: Partial<RawRequest>, options?: InjectWSOption) => Promise<WebSocket>)
|
|
36
|
+
|
|
37
|
+
interface FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> {
|
|
38
|
+
websocketServer: WebSocket.Server,
|
|
39
|
+
injectWS: InjectWSFn<RawRequest>
|
|
40
|
+
|
|
41
|
+
// When `websocket: true` is set, `handler` is the websocket handler, so type it as such
|
|
42
|
+
route<
|
|
43
|
+
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
44
|
+
ContextConfig = ContextConfigDefault,
|
|
45
|
+
const SchemaCompiler extends FastifySchema = FastifySchema
|
|
46
|
+
>(
|
|
47
|
+
opts: Omit<RouteOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>, 'handler' | 'websocket'> & {
|
|
48
|
+
websocket: true,
|
|
49
|
+
handler: fastifyWebsocket.WebsocketHandler<RawServer, RawRequest, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
50
|
+
}
|
|
51
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface FastifyRequest {
|
|
55
|
+
ws: boolean
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface RouteShorthandMethod<
|
|
59
|
+
RawServer extends RawServerBase = RawServerDefault,
|
|
60
|
+
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
|
61
|
+
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
|
|
62
|
+
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
63
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
64
|
+
> {
|
|
65
|
+
<RequestGeneric extends RequestGenericInterface = RequestGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, InnerLogger extends Logger = Logger>(
|
|
66
|
+
path: string,
|
|
67
|
+
opts: RouteShorthandOptions<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig, SchemaCompiler, TypeProvider, InnerLogger> & { websocket: true }, // this creates an overload that only applies these different types if the handler is for websockets
|
|
68
|
+
handler?: fastifyWebsocket.WebsocketHandler<RawServer, RawRequest, RequestGeneric, ContextConfig, SchemaCompiler, TypeProvider, InnerLogger>
|
|
69
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, InnerLogger, TypeProvider>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface RouteOptions<
|
|
73
|
+
RawServer extends RawServerBase = RawServerDefault,
|
|
74
|
+
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
76
|
+
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
|
|
77
|
+
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
78
|
+
ContextConfig = ContextConfigDefault,
|
|
79
|
+
SchemaCompiler = fastify.FastifySchema,
|
|
80
|
+
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
81
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
82
|
+
> extends WebsocketRouteOptions<RawServer, RawRequest, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> { }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
type FastifyWebsocket = FastifyPluginCallback<fastifyWebsocket.WebsocketPluginOptions>
|
|
86
|
+
|
|
87
|
+
declare namespace fastifyWebsocket {
|
|
88
|
+
|
|
89
|
+
interface WebSocketServerOptions extends Omit<WebSocket.ServerOptions, 'path'> { }
|
|
90
|
+
export type WebsocketHandler<
|
|
91
|
+
RawServer extends RawServerBase = RawServerDefault,
|
|
92
|
+
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
|
93
|
+
RequestGeneric extends RequestGenericInterface = RequestGenericInterface,
|
|
94
|
+
ContextConfig = ContextConfigDefault,
|
|
95
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
96
|
+
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
97
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
98
|
+
> = (
|
|
99
|
+
this: FastifyInstance<Server, IncomingMessage, ServerResponse>,
|
|
100
|
+
socket: WebSocket.WebSocket,
|
|
101
|
+
request: FastifyRequest<RequestGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger>
|
|
102
|
+
) => void | Promise<any>
|
|
103
|
+
|
|
104
|
+
export interface WebsocketPluginOptions {
|
|
105
|
+
errorHandler?: (this: FastifyInstance, error: Error, socket: WebSocket.WebSocket, request: FastifyRequest, reply: FastifyReply) => void;
|
|
106
|
+
options?: WebSocketServerOptions;
|
|
107
|
+
preClose?: preCloseHookHandler | preCloseAsyncHookHandler;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface RouteOptions<
|
|
111
|
+
RawServer extends RawServerBase = RawServerDefault,
|
|
112
|
+
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
|
113
|
+
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
|
|
114
|
+
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
115
|
+
ContextConfig = ContextConfigDefault,
|
|
116
|
+
SchemaCompiler extends fastify.FastifySchema = fastify.FastifySchema,
|
|
117
|
+
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
118
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
119
|
+
> extends fastify.RouteOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>, WebsocketRouteOptions<RawServer, RawRequest, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> { }
|
|
120
|
+
|
|
121
|
+
export type WebSocket = WebSocket.WebSocket
|
|
122
|
+
|
|
123
|
+
export const fastifyWebsocket: FastifyWebsocket
|
|
124
|
+
export { fastifyWebsocket as default }
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
declare function fastifyWebsocket (...params: Parameters<FastifyWebsocket>): ReturnType<FastifyWebsocket>
|
|
128
|
+
export = fastifyWebsocket
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox'
|
|
2
|
+
import { Type } from 'typebox'
|
|
3
|
+
import fastify, { FastifyBaseLogger, FastifyInstance, FastifyReply, FastifyRequest, FastifySchema, RawRequestDefaultExpression, RawServerDefault, RequestGenericInterface, RouteOptions } from 'fastify'
|
|
4
|
+
import { RouteGenericInterface } from 'fastify/types/route'
|
|
5
|
+
import type { IncomingMessage } from 'node:http'
|
|
6
|
+
import { expect } from 'tstyche'
|
|
7
|
+
import { Server } from 'ws'
|
|
8
|
+
import fastifyWebsocket, { fastifyWebsocket as namedFastifyWebsocket, WebSocket, WebsocketHandler } from '.'
|
|
9
|
+
|
|
10
|
+
const app: FastifyInstance = fastify()
|
|
11
|
+
app.register(fastifyWebsocket)
|
|
12
|
+
app.register(fastifyWebsocket, {})
|
|
13
|
+
app.register(fastifyWebsocket, { options: { maxPayload: 123 } })
|
|
14
|
+
app.register(fastifyWebsocket, {
|
|
15
|
+
errorHandler: function errorHandler (error: Error, socket: WebSocket, request: FastifyRequest, reply: FastifyReply): void {
|
|
16
|
+
expect(this).type.toBe<FastifyInstance>()
|
|
17
|
+
expect(error).type.toBe<Error>()
|
|
18
|
+
expect(socket).type.toBe<WebSocket>()
|
|
19
|
+
expect(request).type.toBe<FastifyRequest>()
|
|
20
|
+
expect(reply).type.toBe<FastifyReply>()
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
app.register(fastifyWebsocket, { options: { perMessageDeflate: true } })
|
|
24
|
+
app.register(fastifyWebsocket, { preClose: function syncPreclose () { } })
|
|
25
|
+
app.register(fastifyWebsocket, { preClose: async function asyncPreclose () { } })
|
|
26
|
+
|
|
27
|
+
app.get('/websockets-via-inferrence', { websocket: true }, async function (socket, request) {
|
|
28
|
+
expect(this).type.toBe<FastifyInstance>()
|
|
29
|
+
expect(socket).type.toBe<WebSocket>()
|
|
30
|
+
expect(app.websocketServer).type.toBe<Server>()
|
|
31
|
+
expect(request).type.toBe<FastifyRequest<RequestGenericInterface>>()
|
|
32
|
+
expect(request.ws).type.toBe<boolean>()
|
|
33
|
+
expect(request.log).type.toBe<FastifyBaseLogger>()
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const handler: WebsocketHandler = async (socket, request) => {
|
|
37
|
+
expect(socket).type.toBe<WebSocket>()
|
|
38
|
+
expect(app.websocketServer).type.toBe<Server>()
|
|
39
|
+
expect(request).type.toBe<FastifyRequest<RequestGenericInterface>>()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
app.get('/websockets-via-annotated-const', { websocket: true }, handler)
|
|
43
|
+
|
|
44
|
+
app.get('/not-specifed', async (request, reply) => {
|
|
45
|
+
expect(request).type.toBe<FastifyRequest>()
|
|
46
|
+
expect(reply).type.toBe<FastifyReply>()
|
|
47
|
+
expect(request.ws).type.toBe<boolean>()
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
app.get('/not-websockets', { websocket: false }, async (request, reply) => {
|
|
51
|
+
expect(request).type.toBe<FastifyRequest>()
|
|
52
|
+
expect(reply).type.toBe<FastifyReply>()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
app.route({
|
|
56
|
+
method: 'GET',
|
|
57
|
+
url: '/route-full-declaration-syntax',
|
|
58
|
+
handler: (request, reply) => {
|
|
59
|
+
expect(request).type.toBe<FastifyRequest>()
|
|
60
|
+
expect(reply).type.toBe<FastifyReply>()
|
|
61
|
+
expect(request.ws).type.toBe<boolean>()
|
|
62
|
+
},
|
|
63
|
+
wsHandler: (socket, request) => {
|
|
64
|
+
expect(socket).type.toBe<WebSocket>()
|
|
65
|
+
expect(request).type.toBe<FastifyRequest<RouteGenericInterface>>()
|
|
66
|
+
expect(request.ws).type.toBe<boolean>()
|
|
67
|
+
},
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
const augmentedRouteOptions: RouteOptions = {
|
|
71
|
+
method: 'GET',
|
|
72
|
+
url: '/route-with-exported-augmented-route-options',
|
|
73
|
+
handler: (request, reply) => {
|
|
74
|
+
expect(request).type.toBe<FastifyRequest>()
|
|
75
|
+
expect(reply).type.toBe<FastifyReply>()
|
|
76
|
+
},
|
|
77
|
+
wsHandler: (socket, request) => {
|
|
78
|
+
expect(socket).type.toBe<WebSocket>()
|
|
79
|
+
expect(request).type.toBe<FastifyRequest<RouteGenericInterface>>()
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
app.route(augmentedRouteOptions)
|
|
83
|
+
|
|
84
|
+
app.get<{
|
|
85
|
+
Params: { foo: string };
|
|
86
|
+
Body: { bar: string };
|
|
87
|
+
Querystring: { search: string };
|
|
88
|
+
Headers: { auth: string };
|
|
89
|
+
}>(
|
|
90
|
+
'/shorthand-explicit-types',
|
|
91
|
+
{
|
|
92
|
+
websocket: true
|
|
93
|
+
},
|
|
94
|
+
async (socket, request) => {
|
|
95
|
+
expect(socket).type.toBe<WebSocket>()
|
|
96
|
+
expect(request.params).type.toBe<{ foo: string }>()
|
|
97
|
+
expect(request.body).type.toBe<{ bar: string }>()
|
|
98
|
+
expect(request.query).type.toBe<{ search: string }>()
|
|
99
|
+
expect(request.headers).type.toBe<
|
|
100
|
+
IncomingMessage['headers'] & { auth: string }
|
|
101
|
+
>()
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
app.route<{
|
|
106
|
+
Params: { foo: string };
|
|
107
|
+
Body: { bar: string };
|
|
108
|
+
Querystring: { search: string };
|
|
109
|
+
Headers: { auth: string };
|
|
110
|
+
}>({
|
|
111
|
+
method: 'GET',
|
|
112
|
+
url: '/longhand-explicit-types',
|
|
113
|
+
handler: (request, _reply) => {
|
|
114
|
+
expect(request.params).type.toBe<{ foo: string }>()
|
|
115
|
+
expect(request.body).type.toBe<{ bar: string }>()
|
|
116
|
+
expect(request.query).type.toBe<{ search: string }>()
|
|
117
|
+
expect(request.headers).type.toBe<
|
|
118
|
+
IncomingMessage['headers'] & { auth: string }
|
|
119
|
+
>()
|
|
120
|
+
},
|
|
121
|
+
wsHandler: (socket, request) => {
|
|
122
|
+
expect(socket).type.toBe<WebSocket>()
|
|
123
|
+
expect(request.params).type.toBe<{ foo: string }>()
|
|
124
|
+
expect(request.body).type.toBe<{ bar: string }>()
|
|
125
|
+
expect(request.query).type.toBe<{ search: string }>()
|
|
126
|
+
expect(request.headers).type.toBe<
|
|
127
|
+
IncomingMessage['headers'] & { auth: string }
|
|
128
|
+
>()
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
app.route({
|
|
133
|
+
method: 'GET',
|
|
134
|
+
url: '/route-full-declaration-syntax-websocket',
|
|
135
|
+
websocket: true,
|
|
136
|
+
handler: async function (socket, request) {
|
|
137
|
+
expect(this).type.toBe<FastifyInstance>()
|
|
138
|
+
expect(socket).type.toBe<WebSocket>()
|
|
139
|
+
expect(request).type.toBe<FastifyRequest<RouteGenericInterface>>()
|
|
140
|
+
expect(request.ws).type.toBe<boolean>()
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
app.route({
|
|
145
|
+
method: 'GET',
|
|
146
|
+
url: '/route-full-declaration-syntax-not-websocket',
|
|
147
|
+
websocket: false,
|
|
148
|
+
handler: (request, reply) => {
|
|
149
|
+
expect(request).type.toBe<FastifyRequest>()
|
|
150
|
+
expect(reply).type.toBe<FastifyReply>()
|
|
151
|
+
}
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
app.route<{
|
|
155
|
+
Params: { foo: string };
|
|
156
|
+
Body: { bar: string };
|
|
157
|
+
Querystring: { search: string };
|
|
158
|
+
Headers: { auth: string };
|
|
159
|
+
}>({
|
|
160
|
+
method: 'GET',
|
|
161
|
+
url: '/longhand-explicit-types-websocket',
|
|
162
|
+
websocket: true,
|
|
163
|
+
handler: (socket, request) => {
|
|
164
|
+
expect(socket).type.toBe<WebSocket>()
|
|
165
|
+
expect(request.params).type.toBe<{ foo: string }>()
|
|
166
|
+
expect(request.body).type.toBe<{ bar: string }>()
|
|
167
|
+
expect(request.query).type.toBe<{ search: string }>()
|
|
168
|
+
expect(request.headers).type.toBe<
|
|
169
|
+
IncomingMessage['headers'] & { auth: string }
|
|
170
|
+
>()
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
const schema = {
|
|
175
|
+
params: Type.Object({ foo: Type.String() }, { required: ['foo'] }),
|
|
176
|
+
querystring: Type.Object({ search: Type.String() }, { required: ['search'] }),
|
|
177
|
+
body: Type.Object({ bar: Type.String() }, { required: ['bar'] }),
|
|
178
|
+
headers: Type.Object({ auth: Type.String() }, { required: ['auth'] })
|
|
179
|
+
} satisfies FastifySchema
|
|
180
|
+
|
|
181
|
+
const server = app.withTypeProvider<TypeBoxTypeProvider>()
|
|
182
|
+
|
|
183
|
+
server.route({
|
|
184
|
+
method: 'GET',
|
|
185
|
+
url: '/longhand-type-inference',
|
|
186
|
+
schema,
|
|
187
|
+
handler: (request, _reply) => {
|
|
188
|
+
expect(request.params).type.toBe<{ foo: string }>()
|
|
189
|
+
expect(request.body).type.toBe<{ bar: string }>()
|
|
190
|
+
expect(request.query).type.toBe<{ search: string }>()
|
|
191
|
+
expect(request.headers).type.toBe<
|
|
192
|
+
IncomingMessage['headers'] & { auth: string }
|
|
193
|
+
>()
|
|
194
|
+
},
|
|
195
|
+
wsHandler: (socket, request) => {
|
|
196
|
+
expect(socket).type.toBe<WebSocket>()
|
|
197
|
+
expect(request.params).type.toBe<{ foo: string }>()
|
|
198
|
+
expect(request.body).type.toBe<{ bar: string }>()
|
|
199
|
+
expect(request.query).type.toBe<{ search: string }>()
|
|
200
|
+
expect(request.headers).type.toBe<
|
|
201
|
+
IncomingMessage['headers'] & { auth: string }
|
|
202
|
+
>()
|
|
203
|
+
}
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
server.get(
|
|
207
|
+
'/websockets-no-type-inference',
|
|
208
|
+
{ websocket: true },
|
|
209
|
+
async function (socket, request) {
|
|
210
|
+
expect(this).type.toBe<FastifyInstance>()
|
|
211
|
+
expect(socket).type.toBe<WebSocket>()
|
|
212
|
+
expect(app.websocketServer).type.toBe<Server>()
|
|
213
|
+
expect(request).type.toBe<
|
|
214
|
+
FastifyRequest<
|
|
215
|
+
RequestGenericInterface,
|
|
216
|
+
RawServerDefault,
|
|
217
|
+
RawRequestDefaultExpression,
|
|
218
|
+
FastifySchema,
|
|
219
|
+
TypeBoxTypeProvider,
|
|
220
|
+
unknown,
|
|
221
|
+
FastifyBaseLogger
|
|
222
|
+
>
|
|
223
|
+
>()
|
|
224
|
+
expect(request.ws).type.toBe<boolean>()
|
|
225
|
+
expect(request.params).type.toBe<unknown>()
|
|
226
|
+
expect(request.body).type.toBe<unknown>()
|
|
227
|
+
expect(request.query).type.toBe<unknown>()
|
|
228
|
+
expect(request.headers).type.toBe<IncomingMessage['headers']>()
|
|
229
|
+
}
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
server.route({
|
|
233
|
+
method: 'GET',
|
|
234
|
+
url: '/longhand-type-inference-websocket',
|
|
235
|
+
schema,
|
|
236
|
+
websocket: true,
|
|
237
|
+
handler: (socket, request) => {
|
|
238
|
+
expect(socket).type.toBe<WebSocket>()
|
|
239
|
+
expect(request.params).type.toBe<{ foo: string }>()
|
|
240
|
+
expect(request.body).type.toBe<{ bar: string }>()
|
|
241
|
+
expect(request.query).type.toBe<{ search: string }>()
|
|
242
|
+
expect(request.headers).type.toBe<
|
|
243
|
+
IncomingMessage['headers'] & { auth: string }
|
|
244
|
+
>()
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
expect(namedFastifyWebsocket).type.toBe(fastifyWebsocket)
|
|
249
|
+
expect(fastifyWebsocket).type.toBe(fastifyWebsocket)
|
|
250
|
+
|
|
251
|
+
app.injectWS('/', {}, {})
|
|
252
|
+
app.injectWS('/', {}, {
|
|
253
|
+
onInit (ws) {
|
|
254
|
+
expect(ws).type.toBe<WebSocket>()
|
|
255
|
+
},
|
|
256
|
+
})
|
|
257
|
+
app.injectWS('/', {}, {
|
|
258
|
+
onOpen (ws) {
|
|
259
|
+
expect(ws).type.toBe<WebSocket>()
|
|
260
|
+
},
|
|
261
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014 Mathias Buus
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# duplexify
|
|
2
|
+
|
|
3
|
+
Turn a writeable and readable stream into a single streams2 duplex stream.
|
|
4
|
+
|
|
5
|
+
Similar to [duplexer2](https://github.com/deoxxa/duplexer2) except it supports both streams2 and streams1 as input
|
|
6
|
+
and it allows you to set the readable and writable part asynchronously using `setReadable(stream)` and `setWritable(stream)`
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
npm install duplexify
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
[](http://travis-ci.org/mafintosh/duplexify)
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
Use `duplexify(writable, readable, streamOptions)` (or `duplexify.obj(writable, readable)` to create an object stream)
|
|
17
|
+
|
|
18
|
+
``` js
|
|
19
|
+
var duplexify = require('duplexify')
|
|
20
|
+
|
|
21
|
+
// turn writableStream and readableStream into a single duplex stream
|
|
22
|
+
var dup = duplexify(writableStream, readableStream)
|
|
23
|
+
|
|
24
|
+
dup.write('hello world') // will write to writableStream
|
|
25
|
+
dup.on('data', function(data) {
|
|
26
|
+
// will read from readableStream
|
|
27
|
+
})
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
You can also set the readable and writable parts asynchronously
|
|
31
|
+
|
|
32
|
+
``` js
|
|
33
|
+
var dup = duplexify()
|
|
34
|
+
|
|
35
|
+
dup.write('hello world') // write will buffer until the writable
|
|
36
|
+
// part has been set
|
|
37
|
+
|
|
38
|
+
// wait a bit ...
|
|
39
|
+
dup.setReadable(readableStream)
|
|
40
|
+
|
|
41
|
+
// maybe wait some more?
|
|
42
|
+
dup.setWritable(writableStream)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
If you call `setReadable` or `setWritable` multiple times it will unregister the previous readable/writable stream.
|
|
46
|
+
To disable the readable or writable part call `setReadable` or `setWritable` with `null`.
|
|
47
|
+
|
|
48
|
+
If the readable or writable streams emits an error or close it will destroy both streams and bubble up the event.
|
|
49
|
+
You can also explicitly destroy the streams by calling `dup.destroy()`. The `destroy` method optionally takes an
|
|
50
|
+
error object as argument, in which case the error is emitted as part of the `error` event.
|
|
51
|
+
|
|
52
|
+
``` js
|
|
53
|
+
dup.on('error', function(err) {
|
|
54
|
+
console.log('readable or writable emitted an error - close will follow')
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
dup.on('close', function() {
|
|
58
|
+
console.log('the duplex stream is destroyed')
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
dup.destroy() // calls destroy on the readable and writable part (if present)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## HTTP request example
|
|
65
|
+
|
|
66
|
+
Turn a node core http request into a duplex stream is as easy as
|
|
67
|
+
|
|
68
|
+
``` js
|
|
69
|
+
var duplexify = require('duplexify')
|
|
70
|
+
var http = require('http')
|
|
71
|
+
|
|
72
|
+
var request = function(opts) {
|
|
73
|
+
var req = http.request(opts)
|
|
74
|
+
var dup = duplexify(req)
|
|
75
|
+
req.on('response', function(res) {
|
|
76
|
+
dup.setReadable(res)
|
|
77
|
+
})
|
|
78
|
+
return dup
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
var req = request({
|
|
82
|
+
method: 'GET',
|
|
83
|
+
host: 'www.google.com',
|
|
84
|
+
port: 80
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
req.end()
|
|
88
|
+
req.pipe(process.stdout)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
MIT
|
|
94
|
+
|
|
95
|
+
## Related
|
|
96
|
+
|
|
97
|
+
`duplexify` is part of the [mississippi stream utility collection](https://github.com/maxogden/mississippi) which includes more useful stream modules similar to this one.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var duplexify = require('duplexify')
|
|
2
|
+
var http = require('http')
|
|
3
|
+
|
|
4
|
+
var request = function(opts) {
|
|
5
|
+
var req = http.request(opts)
|
|
6
|
+
var dup = duplexify()
|
|
7
|
+
dup.setWritable(req)
|
|
8
|
+
req.on('response', function(res) {
|
|
9
|
+
dup.setReadable(res)
|
|
10
|
+
})
|
|
11
|
+
return dup
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
var req = request({
|
|
15
|
+
method: 'GET',
|
|
16
|
+
host: 'www.google.com',
|
|
17
|
+
port: 80
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
req.end()
|
|
21
|
+
req.pipe(process.stdout)
|