Skip to content

Commit fc3c959

Browse files
authored
fix: upgrade to node 16 and arc 10 and fix type (#289)
1 parent 8c7eb5b commit fc3c959

21 files changed

+3313
-2734
lines changed

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- uses: actions/checkout@v2
1212
- uses: actions/setup-node@v3
1313
with:
14-
node-version: 14
14+
node-version: 16
1515
- run: npm ci
1616
- name: Release
1717
env:

.github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- uses: actions/checkout@v2
1111
- uses: actions/setup-node@v3
1212
with:
13-
node-version: 14
13+
node-version: 16
1414
- run: npm ci
1515
- name: Test
1616
run: npm run test
@@ -21,7 +21,7 @@ jobs:
2121
- uses: actions/checkout@v2
2222
- uses: actions/setup-node@v3
2323
with:
24-
node-version: 14
24+
node-version: 16
2525
- run: npm ci
2626
- name: Lint
2727
run: npm run lint

.node-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16.16.0

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ Subscription
145145
```
146146

147147
```ts
148-
import { tables } from '@architect/functions'
148+
import { tables as arcTables } from '@architect/functions'
149149
150150
const fetchTableNames = async () => {
151-
const tables = await tables()
151+
const tables = await arcTables()
152152
153153
const ensureName = (table) => {
154154
const actualTableName = tables.name(table)
@@ -165,7 +165,7 @@ const fetchTableNames = async () => {
165165
}
166166

167167
const subscriptionServer = makeServer({
168-
dynamodb: tables.db,
168+
dynamodb: tables._db,
169169
schema,
170170
tableNames: fetchTableNames(),
171171
})

lib/index-test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import { assert } from 'chai'
22
import { Handler } from 'aws-lambda'
3-
import { tables } from '@architect/sandbox'
3+
import { start, end } from '@architect/sandbox'
44
import { makeServer } from '.'
55
import { mockServerArgs } from './test/mockServer'
66
import { APIGatewayWebSocketEvent, WebSocketResponse } from './types'
7+
import { join } from 'path'
78

89
describe('makeServer', () => {
910
describe('webSocketHandler', () => {
1011
before(async () => {
11-
await tables.start({ cwd: './mocks/arc-basic-events', quiet: true })
12+
await start({ cwd: join(process.cwd(),'./mocks/arc-basic-events'), quiet: true })
1213
})
1314

1415
after(async () => {
15-
await tables.end()
16+
await end()
1617
})
1718

1819
it('is type compatible with aws-lambda handler', async () => {

lib/messages/subscribe-test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { assert } from 'chai'
3-
import { tables } from '@architect/sandbox'
3+
import { start, end } from '@architect/sandbox'
44
import { subscribe } from './subscribe'
55
import { mockServerContext } from '../test/mockServer'
66
import { connection_init } from './connection_init'
77
import { collect } from 'streaming-iterables'
88
import { subscribe as pubsubSubscribe } from '../pubsub/subscribe'
99
import { makeExecutableSchema } from '@graphql-tools/schema'
10+
import { join } from 'path'
1011

1112
const connectionId = '7rWmyMbMr'
1213
const ConnectionId = connectionId
1314
const connectionInitEvent: any = { requestContext: { connectedAt: 1628905962601, connectionId, domainName: 'localhost:6001', eventType: 'MESSAGE', messageDirection: 'IN', messageId: 'Pn6evkpk2', requestId: 'gN1MPybyL', requestTimeEpoch: 1628905962602, routeKey: '$default', stage: 'testing' }, isBase64Encoded: false, body: '{"type":"connection_init"}' }
1415

1516
describe('messages/subscribe', () => {
1617
beforeEach(async () => {
17-
await tables.start({ cwd: './mocks/arc-basic-events', quiet: true })
18+
await start({ cwd: join(process.cwd(),'./mocks/arc-basic-events'), quiet: true })
1819
})
1920

2021
afterEach(async () => {
21-
await tables.end()
22+
await end()
2223
})
2324

2425
it('executes a query/mutation', async () => {

lib/pubsub/complete-test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { tables } from '@architect/sandbox'
1+
import { start, end } from '@architect/sandbox'
2+
import { join } from 'path'
23
import { mockServerContext } from '../test/mockServer'
34
import { complete } from './complete'
45

56
describe('pubsub:complete', () => {
67
before(async () => {
7-
await tables.start({ cwd: './mocks/arc-basic-events', quiet: true })
8+
await start({ cwd: join(process.cwd(), './mocks/arc-basic-events'), quiet: true })
89
})
910

1011
after(async () => {
11-
await tables.end()
12+
await end()
1213
})
1314

1415
it('takes a topic', async () => {

lib/pubsub/getFilteredSubs-test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import { tables } from '@architect/sandbox'
2+
import { start, end } from '@architect/sandbox'
33
import { assert } from 'chai'
4+
import { join } from 'path'
45
import { mockServerContext } from '../test/mockServer'
56
import { collapseKeys, getFilteredSubs } from './getFilteredSubs'
67

@@ -29,11 +30,11 @@ const makeTopic = () => `topic-${count++}`
2930

3031
describe('getFilteredSubs', () => {
3132
before(async () => {
32-
await tables.start({ cwd: './mocks/arc-basic-events', quiet: true })
33+
await start({ cwd: join(process.cwd(),'./mocks/arc-basic-events'), quiet: true })
3334
})
3435

3536
after(async () => {
36-
await tables.end()
37+
await end()
3738
})
3839

3940
it('can match on no filter', async () => {

lib/test/integration-events-test.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { assert } from 'chai'
3-
import { start as sandBoxStart, end as sandBoxStop } from '@architect/sandbox'
3+
import { start as sandboxStart, end as sandboxEnd } from '@architect/sandbox'
44
import { collect, map } from 'streaming-iterables'
55
import { executeDoubleQuery, executeQuery, executeToComplete, executeToDisconnect } from './execute-helper'
66
import { startGqlWSServer } from './graphql-ws-schema'
7+
import { join } from 'path'
78

89
describe('Events', () => {
910
before(async () => {
10-
await sandBoxStart({ cwd: './mocks/arc-basic-events', quiet: true })
11+
await sandboxStart({ cwd: join(process.cwd(), './mocks/arc-basic-events'), quiet: true })
1112
})
1213

1314
after(async () => {
14-
await new Promise(resolve => setTimeout(resolve, 100)) // pending ddb writes need to finish
15-
await sandBoxStop()
15+
// pending ddb writes need to finish, this is annoying
16+
await new Promise(resolve => setTimeout(resolve, 100))
17+
await sandboxEnd()
1618
})
19+
1720
describe('Basic Events', () => {
1821
it('queries', async () => {
1922
const { url, stop } = await startGqlWSServer()

lib/test/mockServer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const mockServerArgs = async (args: Partial<ServerArgs> = {}): Promise<Se
4747
const tables = await arcTables()
4848

4949
return {
50-
dynamodb: arcTables.db,
50+
dynamodb: tables._db,
5151
schema,
5252
tableNames: {
5353
connections: ensureName(tables, 'Connection'),

lib/test/setup.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { use, assert } from 'chai'
2+
import chaiSubset from 'chai-subset'
3+
4+
process.env.PORT = '6001'
5+
6+
global.assert = assert
7+
8+
use(chaiSubset)

lib/test/setupContains.js

-4
This file was deleted.

lib/test/setupPorts.js

-3
This file was deleted.

lib/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ export type MessageHandler<T> = (arg: { server: ServerClosure, event: APIGateway
195195
Matches the ApiGatewayManagementApi class from aws-sdk but only provides the methods we use
196196
*/
197197
export interface ApiGatewayManagementApiSubset {
198-
postToConnection(input: { ConnectionId: string, Data: string }): { promise: () => Promise<void> }
199-
deleteConnection(input: { ConnectionId: string }): { promise: () => Promise<void> }
198+
postToConnection(input: { ConnectionId: string, Data: string }): { promise: () => Promise<any> }
199+
deleteConnection(input: { ConnectionId: string }): { promise: () => Promise<any> }
200200
}
201201

202202

mocks/arc-basic-events/app.arc

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ basic-events
33

44
@ws
55

6-
@static
7-
folder dist
8-
96
@tables
107
Connection
118
id *String
@@ -14,8 +11,7 @@ Subscription
1411
id *String
1512
ttl TTL
1613

17-
@indexes
18-
14+
@tables-indexes
1915
Subscription
2016
connectionId *String
2117
name ConnectionIndex

mocks/arc-basic-events/lib/graphql.js mocks/arc-basic-events/lib/graphql.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
/* eslint-disable @typescript-eslint/no-var-requires */
2-
require('esbuild-register')
3-
const { makeExecutableSchema } = require('@graphql-tools/schema')
4-
const { tables: arcTables, ws } = require('@architect/functions')
5-
const { makeServer, subscribe } = require('../../../lib')
6-
const { GraphQLError } = require('graphql')
1+
import { makeExecutableSchema } from '@graphql-tools/schema'
2+
import { tables as arcTables, ws } from '@architect/functions'
3+
import { makeServer, subscribe } from '../../../lib'
4+
import { GraphQLError } from 'graphql'
75

86
const typeDefs = `
97
type Query {
@@ -148,7 +146,7 @@ const schema = makeExecutableSchema({
148146
const fetchTableNames = async () => {
149147
const tables = await arcTables()
150148

151-
const ensureName = (table) => {
149+
const ensureName = (table: string) => {
152150
const actualTableName = tables.name(table)
153151
if (!actualTableName) {
154152
throw new Error(`No table found for ${table}`)
@@ -163,7 +161,7 @@ const fetchTableNames = async () => {
163161
}
164162

165163
const subscriptionServer = makeServer({
166-
dynamodb: arcTables.db,
164+
dynamodb: arcTables().then(tables => tables._db),
167165
schema,
168166
tableNames: fetchTableNames(),
169167
apiGatewayManagementApi: ws._api,
@@ -172,4 +170,4 @@ const subscriptionServer = makeServer({
172170
},
173171
})
174172

175-
module.exports = { subscriptionServer }
173+
export { subscriptionServer }
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require('esbuild-register')
12
const { subscriptionServer } = require('../../../lib/graphql')
23

34
exports.handler = subscriptionServer.webSocketHandler
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require('esbuild-register')
12
const { subscriptionServer } = require('../../../lib/graphql')
23

34
exports.handler = subscriptionServer.webSocketHandler
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require('esbuild-register')
12
const { subscriptionServer } = require('../../../lib/graphql')
23

34
exports.handler = subscriptionServer.webSocketHandler

0 commit comments

Comments
 (0)