Skip to content

Commit

Permalink
chore(client): Drop Node 16 support and add Node 22 support (#1378)
Browse files Browse the repository at this point in the history
Node 16 has been [dead for a
while](https://nodejs.org/en/blog/announcements/nodejs16-eol) and we are
not testing more modern Node LTS versions.

Most prominently, the better-sqlite3 we were using in the client does
not support Node v22 as raised by @robacourt and others
(electric-sql/electric#1301)

I've updated the CI workflows to use Node v22 and the matrices to test
v18 v20 and v22
  • Loading branch information
msfstef authored Jun 18, 2024
1 parent 8cddaaf commit 26b3a87
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 49 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/changesets_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
version: 8
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Create Release Pull Request or Publish
Expand All @@ -33,4 +33,4 @@ jobs:
title: Publish new package versions
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
6 changes: 3 additions & 3 deletions .github/workflows/clients_typescript_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
version: 8
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 22
cache: pnpm
- run: make deps
- run: pnpm run check-styleguide
Expand All @@ -44,7 +44,7 @@ jobs:
version: 8
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 22
cache: pnpm
- run: make deps
- run: pnpm run typecheck
Expand All @@ -53,7 +53,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [16, 18, 20]
node-version: [18, 20, 22]
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/examples_e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 22
cache: npm
cache-dependency-path: |
${{ matrix.example_dir }}/package-lock.json
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 22
cache: yarn
cache-dependency-path: examples/introduction/yarn.lock
- name: Install dependencies
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/generator_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
version: 8
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 22
cache: pnpm
- run: make deps
- run: pnpm run check-styleguide
Expand All @@ -38,7 +38,7 @@ jobs:
version: 8
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 22
cache: pnpm
- run: make deps
- run: pnpm run build
Expand All @@ -47,7 +47,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [16, 18, 20]
node-version: [18, 20, 22]
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/satellite_proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ on:
branches:
- main
paths:
- "protocol/**"
- 'protocol/**'
pull_request:
paths:
- "protocol/**"
- 'protocol/**'
workflow_dispatch:

env:
OTP_VERSION: "27.0"
ELIXIR_VERSION: "1.17.0-otp-27"
OTP_VERSION: '27.0'
ELIXIR_VERSION: '1.17.0-otp-27'

jobs:
verify_proto:
Expand All @@ -29,13 +29,13 @@ jobs:
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
# keep this in sync with the version pinned in .tool-versions
version: "26.1"
version: '26.1'
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 22
cache: pnpm
- uses: erlef/setup-beam@v1
with:
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/toolbar_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
version: 8
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 22
cache: pnpm
- run: make deps
- run: make check_styleguide
Expand All @@ -38,7 +38,7 @@ jobs:
version: 8
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 22
cache: pnpm
- run: make deps
- run: make check_types
Expand All @@ -47,7 +47,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [16, 18, 20]
node-version: [18, 20, 22]
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
Expand Down Expand Up @@ -77,4 +77,3 @@ jobs:
- run: make deps
- run: pnpm config set '//registry.npmjs.org/:_authToken' "${{ secrets.NPM_TOKEN }}"
- run: make publish-canary

4 changes: 2 additions & 2 deletions clients/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"@prisma/client": "4.8.1",
"async-mutex": "^0.4.0",
"base-64": "^1.0.0",
"better-sqlite3": "^8.4.0",
"better-sqlite3": "^11.0.0",
"commander": "^11.1.0",
"cross-fetch": "^3.1.5",
"decompress": "^4.2.1",
Expand Down Expand Up @@ -221,7 +221,7 @@
"@tauri-apps/plugin-sql": "2.0.0-alpha.5",
"@testing-library/react": "^13.4.0",
"@types/base-64": "^1.0.0",
"@types/better-sqlite3": "7.6.3",
"@types/better-sqlite3": "7.6.10",
"@types/decompress": "^4.2.4",
"@types/lodash.flow": "^3.5.7",
"@types/lodash.groupby": "^4.6.7",
Expand Down
4 changes: 2 additions & 2 deletions clients/typescript/src/drivers/better-sqlite3/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class DatabaseAdapter
// This `query` function does not enforce that the query is read-only
async _query({ sql, args }: DbStatement): Promise<Row[]> {
const stmt = this.db.prepare(sql)
return stmt.all(...wrapBindParams(args))
return stmt.all(...wrapBindParams(args)) as Row[]
}

async _runExclusively<T>(
Expand Down Expand Up @@ -161,7 +161,7 @@ class WrappedTx implements Tx {
): void {
try {
const stmt = this.db.prepare(sql)
const rows = stmt.all(...wrapBindParams(args))
const rows = stmt.all(...wrapBindParams(args)) as Row[]
successCallback(this, rows)
} catch (err) {
if (typeof errorCallback !== 'undefined') errorCallback(err)
Expand Down
11 changes: 6 additions & 5 deletions clients/typescript/src/drivers/better-sqlite3/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export interface Database
export type StatementBindParams<T = BindParams> = T extends any[] ? T : [T]

// The relevant subset of the Better-SQLite3 prepared statement.
type BoundStatement<T extends any[]> = Omit<
OriginalStatement<T>,
type BoundStatement<T extends unknown[], Result = unknown> = Omit<
OriginalStatement<T, Result>,
'run' | 'get' | 'all' | 'iterate'
> & {
run: (...params: T) => RunResult
Expand All @@ -31,6 +31,7 @@ type BoundStatement<T extends any[]> = Omit<
iterate: (...params: T) => IterableIterator<Row>
}

export type Statement<T extends BindParams = []> = T extends any[]
? BoundStatement<T>
: BoundStatement<[T]>
export type Statement<
T extends BindParams = [],
Result = unknown
> = T extends any[] ? BoundStatement<T, Result> : BoundStatement<[T], Result>
12 changes: 7 additions & 5 deletions clients/typescript/src/drivers/better-sqlite3/mock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BindParams, DbName, Row, SqlValue } from '../../util/types'
import { Database, Statement, Transaction } from './database'
import type { Statement as OriginalStatement } from 'better-sqlite3'

type MockStatement<T extends BindParams = []> = Pick<
Statement<T>,
Expand All @@ -20,8 +21,8 @@ export class MockDatabase implements Database {
return this
}

prepare<T extends BindParams = []>(_sql: string): Statement<T> {
const mockStatement: MockStatement<T> = {
prepare<T extends unknown[] | {}, R>(_sql: string) {
const mockStatement: MockStatement = {
database: this as any,
readonly: false,
source: _sql,
Expand All @@ -42,13 +43,13 @@ export class MockDatabase implements Database {
}

// Valid only for mocking since we don't expect to need to mock full interface
return mockStatement as Statement<T>
return mockStatement as unknown as OriginalStatement<T, R>
}

transaction<T extends (...args: any[]) => any>(fn: T): Transaction<T> {
const self = this

const baseFn = (...args: Parameters<T>): ReturnType<T> => {
const baseFn = (...args: unknown[]): ReturnType<T> => {
self.inTransaction = true

const retval = fn(...args)
Expand All @@ -58,7 +59,8 @@ export class MockDatabase implements Database {
return retval
}

const txFn = <Transaction<T>>baseFn
const txFn = baseFn as unknown as Transaction<T>
txFn.default = baseFn
txFn.deferred = baseFn
txFn.immediate = baseFn
txFn.exclusive = baseFn
Expand Down
2 changes: 1 addition & 1 deletion components/toolbar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"@vitejs/plugin-react": "^4.2.1",
"better-sqlite3": "^8.4.0",
"better-sqlite3": "^11.0.0",
"electric-sql": "workspace:*",
"eslint": "^8.22.0",
"eslint-plugin-react": "^7.34.1",
Expand Down
2 changes: 1 addition & 1 deletion e2e/satellite_client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"lint": "eslint src --fix"
},
"dependencies": {
"better-sqlite3": "^8.4.0",
"better-sqlite3": "^11.0.0",
"electric-sql": "workspace:*",
"jsonwebtoken": "^9.0.0",
"pg": "^8.11.3",
Expand Down
32 changes: 19 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 26b3a87

Please sign in to comment.