Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make some improvements #363

Merged
merged 8 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src/lib/index'
223 changes: 157 additions & 66 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"@types/debug": "^4.1.7",
"@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",
"all-contributors-cli": "^6.14.2",
Expand Down
20 changes: 11 additions & 9 deletions src/adapters/ws/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,17 @@ class WebSocketsAdapter extends Adapter {
return
}
}
}

if (servers.has(pathname)) {
servers.get(pathname).handleUpgrade(request, socket, head, (ws) => {
servers.get(pathname).emit('server:connection:open', ws, request)

ws.on('message', (payload) => {
const msg = this._createMessage(pathname, payload)
this.emit('message', msg, ws)

if (servers.has(pathname)) {
servers.get(pathname).handleUpgrade(request, socket, head, (ws) => {
servers.get(pathname).emit('connect', ws, request)

ws.on('message', (payload) => {
const msg = this._createMessage(pathname, payload)
this.emit('message', msg, ws)
})

this.emit('server:connection:open', { name: this.name(), adapter: this, connection: ws, channel: pathname, request })
})

this.emit('connect', { name: this.name(), adapter: this, connection: ws, channel: pathname })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should get rid of this connect event. As per documentation, connect is only triggered when Glee is a client but in this case it behaves as a server.

Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default async function GleeAppInitializer () {
if (channel.hasPublish()) {
const operationId = channel.publish().json('operationId')
if (operationId) {
const schema = channel.publish().message().payload().json()
const schema = {oneOf: channel.publish().messages().map(message => message.payload().json())} as any;
KhudaDad414 marked this conversation as resolved.
Show resolved Hide resolved
app.use(channelName, validate(schema), (event, next) => {
triggerFunction({
app,
Expand All @@ -78,7 +78,7 @@ export default async function GleeAppInitializer () {
}
}
if (channel.hasSubscribe()) {
const schema = channel.subscribe().message().payload().json()
const schema = {oneOf: channel.subscribe().messages().map(message => message.payload().json())} as any;
KhudaDad414 marked this conversation as resolved.
Show resolved Hide resolved
app.useOutbound(channelName, validate(schema), json2string)
}
})
Expand Down
2 changes: 0 additions & 2 deletions src/lib/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ async function loadConfigsFromFile() {
ASYNCAPI_FILE_PATH = projectConfigs.ASYNCAPI_FILE_PATH ? path.resolve(GLEE_DIR, projectConfigs.ASYNCAPI_FILE_PATH) : ASYNCAPI_FILE_PATH
return projectConfigs
} catch (e) {
if (e.code !== 'ERR_MODULE_NOT_FOUND') {
return console.error(e)
KhudaDad414 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/lifecycleEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export async function run(lifecycleEvent: string, params: GleeFunctionEvent) {
const responses = await Promise.all(handlers.map(info => info.fn(params)))

responses.forEach(res => {
if (res.send) {
if (res?.send) {
res.send.forEach((event: GleeFunctionReturnSend) => {
KhudaDad414 marked this conversation as resolved.
Show resolved Hide resolved
try {
params.glee.send(new GleeMessage({
Expand Down