-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Segregate rest and streaming directory (#915)
* chore: Segregate rest and streaming directory * chore: Segregate interfaces and adapters * chore: Prettify tests directory * chore: Move implementations to adapters * chore: Use inline type import
- Loading branch information
Showing
258 changed files
with
711 additions
and
717 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { type mastodon } from '../mastodon'; | ||
import { | ||
HttpConfigImpl, | ||
type MastoHttpConfigProps, | ||
WebSocketConfigImpl, | ||
type WebSocketConfigProps, | ||
} from './config'; | ||
import { HttpNativeImpl } from './http'; | ||
import { createLogger, type LogType } from './logger'; | ||
import { createRequestBuilder } from './request-builder'; | ||
import { SerializerNativeImpl } from './serializers'; | ||
import { WebSocketClientNativeImpl, WebSocketConnector } from './ws'; | ||
|
||
type LogConfigProps = { | ||
readonly logLevel?: LogType; | ||
}; | ||
|
||
export const createRestClient = ( | ||
props: MastoHttpConfigProps & LogConfigProps, | ||
): mastodon.rest.Client => { | ||
const serializer = new SerializerNativeImpl(); | ||
const config = new HttpConfigImpl(props, serializer); | ||
const logger = createLogger(props.logLevel); | ||
const http = new HttpNativeImpl(serializer, config, logger); | ||
const builder = createRequestBuilder(http, ['api']) as mastodon.rest.Client; | ||
return builder; | ||
}; | ||
|
||
export const createOAuthClient = ( | ||
props: MastoHttpConfigProps & LogConfigProps, | ||
): mastodon.oauth.Client => { | ||
const serializer = new SerializerNativeImpl(); | ||
const config = new HttpConfigImpl(props, serializer); | ||
const logger = createLogger(props.logLevel); | ||
const http = new HttpNativeImpl(serializer, config, logger); | ||
const builder = createRequestBuilder(http, [ | ||
'oauth', | ||
]) as mastodon.oauth.Client; | ||
return builder; | ||
}; | ||
|
||
export function createStreamingClient( | ||
props: WebSocketConfigProps & LogConfigProps, | ||
): mastodon.streaming.Client { | ||
const serializer = new SerializerNativeImpl(); | ||
const config = new WebSocketConfigImpl(props, serializer); | ||
const logger = createLogger(props.logLevel); | ||
const connector = new WebSocketConnector( | ||
[config.resolvePath('/api/v1/streaming').toString(), config.getProtocols()], | ||
logger, | ||
config, | ||
); | ||
const connections = connector.getConnections(); | ||
|
||
return new WebSocketClientNativeImpl( | ||
connections, | ||
serializer, | ||
connector.close.bind(connector), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export * from './http-config'; | ||
export * from './log-config'; | ||
export * from './web-socket-config'; |
File renamed without changes.
3 changes: 1 addition & 2 deletions
3
src/utils/merge-abort-signals.ts → src/adapters/config/merge-abort-signals.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
3 changes: 1 addition & 2 deletions
3
src/utils/merge-headers-init.ts → src/adapters/config/merge-headers-init.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.