Skip to content
This repository was archived by the owner on May 17, 2025. It is now read-only.

Commit d3ad470

Browse files
committed
fix: lint and file structure
1 parent 2ee2af3 commit d3ad470

25 files changed

+155
-190
lines changed

.eslintrc.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,22 @@ module.exports = {
1616
'@typescript-eslint',
1717
],
1818
rules: {
19-
indent: [
20-
'error',
21-
2,
22-
],
23-
'linebreak-style': [
24-
'error',
25-
'unix',
26-
],
27-
quotes: [
28-
'error',
29-
'single',
30-
],
31-
semi: [
32-
'error',
33-
'never',
34-
],
19+
indent: [ 'error', 2 ],
20+
'linebreak-style': [ 'error', 'unix' ],
21+
quotes: [ 'error', 'single' ],
22+
semi: 'off',
23+
'@typescript-eslint/semi': ['error', 'never'],
3524
'quote-props': ['error', 'as-needed'],
3625
'no-param-reassign': 'error',
3726
'comma-dangle': ['error', 'always-multiline'],
3827
'space-infix-ops': ['error'],
3928
'no-multi-spaces': ['error'],
29+
'no-unused-vars': 'off',
30+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
31+
'@typescript-eslint/member-delimiter-style': ['error', {
32+
multiline: { delimiter: 'none' },
33+
singleline: { delimiter: 'comma', requireLast: false },
34+
multilineDetection: 'last-member',
35+
}],
4036
},
4137
}

lib/gateway.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ import {
55
ServerClosure,
66
WebsocketResponse,
77
} from './types'
8-
import {
9-
complete,
10-
connection_init,
11-
subscribe,
12-
disconnect,
13-
ping,
14-
} from './messages'
8+
import { disconnect } from './messages/disconnect'
9+
import { ping } from './messages/ping'
10+
import { complete } from './messages/complete'
11+
import { subscribe } from './messages/subscribe'
12+
import { connection_init } from './messages/connection_init'
1513
import { pong } from './messages/pong'
1614

1715
export const handleGatewayEvent =

lib/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { DataMapper } from '@aws/dynamodb-data-mapper'
22
import { ServerArgs } from './types'
33
import { publish } from './pubsub/publish'
4-
import { createModel, Connection, Subscription } from './model'
4+
import { createModel } from './model/createModel'
5+
import { Subscription } from './model/Subscription'
56
import { handleGatewayEvent } from './gateway'
67
import { handleStateMachineEvent } from './stepFunctionHandler'
8+
import { Connection } from './model/Connection'
79

810
export const createInstance = (opts: ServerArgs) => {
911
const closure = {
@@ -29,8 +31,9 @@ export const createInstance = (opts: ServerArgs) => {
2931
}
3032
}
3133

32-
export { prepareResolvers } from './utils'
34+
export { prepareResolvers } from './utils/graphql'
3335
export * from './pubsub/subscribe'
3436

3537
export * from './types'
36-
export { Subscription, Connection } from './model'
38+
export { Subscription } from './model/Subscription'
39+
export { Connection } from './model/Connection'

lib/messages/complete.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import { parse } from 'graphql'
22
import { CompleteMessage } from 'graphql-ws'
33
import { buildExecutionContext } from 'graphql/execution/execute'
4-
import {
5-
constructContext,
6-
deleteConnection,
7-
getResolverAndArgs,
8-
promisify,
9-
} from '../utils'
4+
import { deleteConnection } from '../utils/aws'
5+
import { constructContext, getResolverAndArgs } from '../utils/graphql'
106
import { MessageHandler } from './types'
117

128
/** Handler function for 'complete' message. */
139
export const complete: MessageHandler<CompleteMessage> =
1410
(c) =>
1511
async ({ event, message }) => {
1612
try {
17-
await promisify(() => c.onComplete?.({ event, message }))
13+
await c.onComplete?.({ event, message })
1814

1915
const topicSubscriptions = await c.mapper.query(c.model.Subscription, {
2016
id: `${event.requestContext.connectionId!}|${message.id}`,
@@ -57,7 +53,7 @@ export const complete: MessageHandler<CompleteMessage> =
5753

5854
await Promise.all(deletions)
5955
} catch (err) {
60-
await promisify(() => c.onError?.(err, { event, message }))
56+
await c.onError?.(err, { event, message })
6157
await deleteConnection(c)(event.requestContext)
6258
}
6359
}

lib/messages/connection_init.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { StepFunctions } from 'aws-sdk'
22
import { ConnectionInitMessage, MessageType } from 'graphql-ws'
3-
import { assign } from '../model'
43
import { StateFunctionInput } from '../types'
5-
import { sendMessage, deleteConnection, promisify } from '../utils'
4+
import { deleteConnection, sendMessage } from '../utils/aws'
65
import { MessageHandler } from './types'
76

87
/** Handler function for 'connection_init' message. */
@@ -11,7 +10,7 @@ export const connection_init: MessageHandler<ConnectionInitMessage> =
1110
async ({ event, message }) => {
1211
try {
1312
const res = c.onConnectionInit
14-
? await promisify(() => c.onConnectionInit!({ event, message }))
13+
? await c.onConnectionInit({ event, message })
1514
: message.payload
1615

1716
if (c.pingpong) {
@@ -32,7 +31,7 @@ export const connection_init: MessageHandler<ConnectionInitMessage> =
3231
}
3332

3433
// Write to persistence
35-
const connection = assign(new c.model.Connection(), {
34+
const connection = Object.assign(new c.model.Connection(), {
3635
id: event.requestContext.connectionId!,
3736
requestContext: event.requestContext,
3837
payload: res,
@@ -43,7 +42,7 @@ export const connection_init: MessageHandler<ConnectionInitMessage> =
4342
message: { type: MessageType.ConnectionAck },
4443
})
4544
} catch (err) {
46-
await promisify(() => c.onError?.(err, { event, message }))
45+
await c.onError?.(err, { event, message })
4746
await deleteConnection(c)(event.requestContext)
4847
}
4948
}

lib/messages/disconnect.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import { parse } from 'graphql'
22
import { equals } from '@aws/dynamodb-expressions'
33
import { buildExecutionContext } from 'graphql/execution/execute'
4-
import { constructContext, getResolverAndArgs, promisify } from '../utils'
54
import { MessageHandler } from './types'
6-
import { assign } from '../model'
5+
import { constructContext, getResolverAndArgs } from '../utils/graphql'
76

87
/** Handler function for 'disconnect' message. */
98
export const disconnect: MessageHandler<null> =
109
(c) =>
1110
async ({ event }) => {
1211
try {
13-
await promisify(() => c.onDisconnect?.({ event }))
12+
await c.onDisconnect?.({ event })
1413

1514
const entities = await c.mapper.query(
1615
c.model.Subscription,
@@ -63,12 +62,12 @@ export const disconnect: MessageHandler<null> =
6362
...deletions,
6463
// Delete connection
6564
c.mapper.delete(
66-
assign(new c.model.Connection(), {
65+
Object.assign(new c.model.Connection(), {
6766
id: event.requestContext.connectionId!,
6867
}),
6968
),
7069
])
7170
} catch (err) {
72-
await promisify(() => c.onError?.(err, { event }))
71+
await c.onError?.(err, { event })
7372
}
7473
}

lib/messages/index.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

lib/messages/ping.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { PingMessage, MessageType } from 'graphql-ws'
2-
import { sendMessage, deleteConnection, promisify } from '../utils'
2+
import { deleteConnection, sendMessage } from '../utils/aws'
33
import { MessageHandler } from './types'
44

55
/** Handler function for 'ping' message. */
66
export const ping: MessageHandler<PingMessage> =
77
(c) =>
88
async ({ event, message }) => {
99
try {
10-
await promisify(() => c.onPing?.({ event, message }))
10+
await c.onPing?.({ event, message })
1111
return sendMessage(c)({
1212
...event.requestContext,
1313
message: { type: MessageType.Pong },
1414
})
1515
} catch (err) {
16-
await promisify(() => c.onError?.(err, { event, message }))
16+
await c.onError?.(err, { event, message })
1717
await deleteConnection(c)(event.requestContext)
1818
}
1919
}

lib/messages/pong.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
import { MessageType, PongMessage } from 'graphql-ws'
2-
import { assign } from '../model'
3-
import { sendMessage, deleteConnection, promisify } from '../utils'
1+
import { PongMessage } from 'graphql-ws'
2+
import { deleteConnection } from '../utils/aws'
43
import { MessageHandler } from './types'
54

65
/** Handler function for 'pong' message. */
76
export const pong: MessageHandler<PongMessage> =
87
(c) =>
98
async ({ event, message }) => {
109
try {
11-
await promisify(() => c.onPong?.({ event, message }))
10+
await c.onPong?.({ event, message })
1211
await c.mapper.update(
13-
assign(new c.model.Connection(), {
12+
Object.assign(new c.model.Connection(), {
1413
id: event.requestContext.connectionId!,
1514
hasPonged: true,
1615
}),
@@ -19,7 +18,7 @@ export const pong: MessageHandler<PongMessage> =
1918
},
2019
)
2120
} catch (err) {
22-
await promisify(() => c.onError?.(err, { event, message }))
21+
await c.onError?.(err, { event, message })
2322
await deleteConnection(c)(event.requestContext)
2423
}
2524
}

lib/messages/subscribe.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@ import {
66
execute,
77
} from 'graphql/execution/execute'
88
import { MessageHandler } from './types'
9-
import {
10-
constructContext,
11-
deleteConnection,
12-
getResolverAndArgs,
13-
promisify,
14-
sendMessage,
15-
} from '../utils'
16-
import { assign } from '../model'
179
import { ServerClosure, SubscribeHandler } from '../types'
10+
import { constructContext, getResolverAndArgs } from '../utils/graphql'
11+
import { deleteConnection, sendMessage } from '../utils/aws'
1812

1913
/** Handler function for 'subscribe' message. */
2014
export const subscribe: MessageHandler<SubscribeMessage> =
@@ -23,11 +17,11 @@ export const subscribe: MessageHandler<SubscribeMessage> =
2317
try {
2418
const [connection] = await Promise.all([
2519
await c.mapper.get(
26-
assign(new c.model.Connection(), {
20+
Object.assign(new c.model.Connection(), {
2721
id: event.requestContext.connectionId!,
2822
}),
2923
),
30-
await promisify(() => c.onSubscribe?.({ event, message })),
24+
await c.onSubscribe?.({ event, message }),
3125
])
3226
const connectionParams = connection.payload || {}
3327

@@ -112,7 +106,7 @@ export const subscribe: MessageHandler<SubscribeMessage> =
112106
).definitions // Access subscribe instance
113107
await Promise.all(
114108
topicDefinitions.map(async ({ topic, filter }) => {
115-
const subscription = assign(new c.model.Subscription(), {
109+
const subscription = Object.assign(new c.model.Subscription(), {
116110
id: `${event.requestContext.connectionId}|${message.id}`,
117111
topic,
118112
filter: filter || {},
@@ -130,7 +124,7 @@ export const subscribe: MessageHandler<SubscribeMessage> =
130124
}),
131125
)
132126
} catch (err) {
133-
await promisify(() => c.onError?.(err, { event, message }))
127+
await c.onError?.(err, { event, message })
134128
await deleteConnection(c)(event.requestContext)
135129
}
136130
}

0 commit comments

Comments
 (0)