Skip to content

Commit

Permalink
Extracted adapters to separate packages and removed them from GleeQuore
Browse files Browse the repository at this point in the history
  • Loading branch information
fmvilas committed Oct 28, 2024
1 parent 2d691fa commit 2421410
Show file tree
Hide file tree
Showing 53 changed files with 1,324 additions and 473 deletions.
1 change: 0 additions & 1 deletion packages/gleequore/index.d.ts

This file was deleted.

22 changes: 8 additions & 14 deletions packages/gleequore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
"name": "@asyncapi/gleequore",
"version": "0.0.0",
"description": "The Quore of Glee",
"exports": "./dist/moduleIndex.js",
"main": "./dist/index.js",
"type": "module",
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"types": "./index.d.ts",
"files": [
"dist",
"./src/index.d.ts"
],
"types": "./src/index.d.ts",
"scripts": {
"build": "tsc",
"bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION",
Expand All @@ -32,31 +36,21 @@
},
"license": "Apache-2.0",
"dependencies": {
"@asyncapi/glee-shared-utils": "workspace:*",
"@asyncapi/parser": "^3.1.0",
"ajv": "^6.12.6",
"async": "^3.2.0",
"better-ajv-errors": "^0.7.0",
"debug": "^4.3.1",
"got": "^12.5.3",
"kafkajs": "^2.2.3",
"mqtt": "^4.3.7",
"path-to-regexp": "^6.2.0",
"redis": "^4.0.2",
"socket.io": "^4.1.2",
"typescript": "^4.5.4",
"uri-templates": "^0.2.0",
"uuid": "^8.3.2",
"ws": "^7.4.6"
"uuid": "^8.3.2"
},
"devDependencies": {
"@jest/globals": "29.7.0",
"@tsconfig/node14": "^1.0.1",
"@types/async": "^3.2.11",
"@types/debug": "^4.1.7",
"@types/jest": "^29.5.14",
"@types/socket.io": "^3.0.2",
"@types/uri-templates": "^0.1.31",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^5.9.0",
"@typescript-eslint/parser": "^5.9.0",
"eslint": "^8.6.0",
Expand Down
127 changes: 15 additions & 112 deletions packages/gleequore/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,17 @@ import GleeQuoreConnection from './lib/connection.js'
import GleeQuore from './index.ts'
import type GleeQuoreMessage from './lib/message.js'

type WebSocketServerType = 'native' | 'socket.io'
type HttpServerType = 'native'
type QueryParam = { [key: string]: string } | { [key: string]: string[] }

export type AuthFunction<T> = ({
serverName,
parsedAsyncAPI,
}: {
serverName: string
parsedAsyncAPI: AsyncAPIDocument
}) => Promise<T>
export { default as GleeQuoreAdapter } from './lib/adapter.js'
export { default as GleeQuoreMessage } from './lib/message.js'
export { default as GleeQuoreConnection } from './lib/connection.js'
export { default as GleeQuoreClusterAdapter } from './lib/cluster.js'
export { default as GleeQuoreError } from './errors.js'

export interface AuthFunctionInfo {
clientAuth?: GleeQuoreAuthFunction
serverAuth?: GleeQuoreAuthFunction
}

export interface MqttAuthConfig {
cert?: string
username?: string
password?: string
clientId?: string
}

export interface WsAuthConfig {
token?: string
username?: string
password?: string
}

export interface HttpAuthConfig {
token?: string
username?: string
password?: string
}

export type AuthProps = {
getToken: () => string
getUserPass: () => {
Expand All @@ -53,77 +28,12 @@ export type AuthProps = {
getAPIKeys: () => string
}

export type WsHttpAuth = WsAuthConfig | HttpAuthConfig

export interface KafkaAuthConfig {
key?: string
cert?: string
clientId?: string
rejectUnauthorized?: boolean
username?: string
password?: string
}

export type GleeQuoreClusterAdapterConfig = {
adapter?: string | typeof GleeQuoreClusterAdapter
name?: string
url: string
}

export type WebsocketServerAdapterConfig = {
httpServer?: any
adapter?: WebSocketServerType | typeof GleeQuoreAdapter
port?: number
}

export type WebsocketAdapterConfig = {
server?: WebsocketServerAdapterConfig
}

export type HttpAdapterConfig = {
server: {
httpServer?: any
port?: number
}
client?: {
auth?: HttpAuthConfig | AuthFunction<HttpAuthConfig>
query?: QueryParam
body?: any
}
}
export type MqttAdapterConfig = {
auth?: MqttAuthConfig | AuthFunction<MqttAuthConfig>
}

export type KafkaAdapterConfig = {
auth?: KafkaAuthConfig | AuthFunction<KafkaAuthConfig>
}

export enum Log {
CHANNEL_ONLY = 'channel-only',
NONE = 'none'
}

export type LogsConfig = {
incoming: Log
outgoing: Log
}

export interface GleeQuoreConfig {
includeServers?: string[],
cluster?: GleeQuoreClusterAdapterConfig,
http?: HttpAdapterConfig,
kafka?: KafkaAdapterConfig,
ws?: WebsocketAdapterConfig,
mqtt?: MqttAdapterConfig,
}

export type GleeQuoreFunctionReturn = {
send?: GleeQuoreFunctionReturnSend[]
reply?: GleeQuoreFunctionReturnReply[]
broadcast?: GleeQuoreFunctionReturnBroadcast[]
}

export type GleeQuoreFunctionEvent = {
request: GleeQuoreMessage
app: GleeQuore
Expand All @@ -145,17 +55,6 @@ export type GleeQuoreAuthFunctionEvent = {
doc: any
}

export type GleeQuoreFunctionReturnSend = {
payload?: any
query?: QueryParam
headers?: { [key: string]: string }
channel?: string
server?: string
}

export type GleeQuoreFunctionReturnReply = Omit<GleeQuoreFunctionReturnSend, "channel" | "server">
export type GleeQuoreFunctionReturnBroadcast = GleeQuoreFunctionReturnSend

export type GleeQuoreFunction = (
event: GleeQuoreFunctionEvent
) => Promise<any>
Expand All @@ -168,11 +67,12 @@ export type GleeQuoreAuthFunction = (
event: GleeQuoreAuthFunctionEvent
) => Promise<GleeQuoreAuthFunctionEvent> | void

type Headers = { [key: string]: string }
export interface Authenticatable {
headers: Headers,
query: QueryParam
url: URL
export interface GleeQuoreAdapterOptions {
glee: GleeQuore;
serverName: string;
server: ServerInterface;
parsedAsyncAPI: AsyncAPIDocument;
config?: object
}

export type AdapterRecord = {
Expand All @@ -181,9 +81,12 @@ export type AdapterRecord = {
serverName: string
server: ServerInterface
asyncapi: AsyncAPIDocumentInterface
config?: object
}

export type ClusterAdapterRecord = {
Adapter: typeof GleeQuoreClusterAdapter
instance?: GleeQuoreClusterAdapter
instance?: GleeQuoreClusterAdapter,
clusterName?: string,
clusterURL?: string
}
Loading

0 comments on commit 2421410

Please sign in to comment.