Skip to content

Commit 413c8cb

Browse files
cloutiertylerbfops
andauthored
Unifies TypeScript packages and command names (#3195)
# Description of Changes This PR: - standardizes the prettier config across all TypeScript projects - adds a root level package.json - standardizes all `pnpm` commands to be the same - updates documentation accordingly - adds some additional typescript testing for serialization and deserialization **IMPORTANT!** Once this PR merges we will need to change the `compile-and-test` required check to `build-and-test` # API and ABI breaking changes No breaking changes. # Expected complexity level and risk 2 - It in principle doesn't change any code, but could affect deploy processes. # Testing - [x] Just the automated testing that we had previously - [x] I added additional automated tests --------- Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
1 parent 5901fb5 commit 413c8cb

30 files changed

Lines changed: 1195 additions & 464 deletions

.github/workflows/ci.yml

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -254,19 +254,41 @@ jobs:
254254
GIT_REF="${{ github.ref }}"
255255
fi
256256
echo "GIT_REF=${GIT_REF}" >>"$GITHUB_ENV"
257+
257258
- name: Checkout sources
258259
uses: actions/checkout@v4
259260
with:
260261
ref: ${{ env.GIT_REF }}
262+
263+
- name: Set up Node.js
264+
uses: actions/setup-node@v4
265+
with:
266+
node-version: 18
267+
268+
- uses: pnpm/action-setup@v4
269+
with:
270+
run_install: true
271+
272+
- name: Get pnpm store directory
273+
shell: bash
274+
working-directory: sdks/typescript
275+
run: |
276+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
277+
278+
- uses: actions/cache@v4
279+
name: Setup pnpm cache
280+
with:
281+
path: ${{ env.STORE_PATH }}
282+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
283+
restore-keys: |
284+
${{ runner.os }}-pnpm-store-
285+
261286
- uses: dsherret/rust-toolchain-file@v1
287+
262288
- name: Check for docs change
263289
run: |
264290
cargo run --features markdown-docs -p spacetimedb-cli > docs/docs/cli-reference.md
265-
cd docs
266-
# This is needed because our website doesn't render markdown quite properly.
267-
# See the README in docs for more details.
268-
sed -i'' -E 's!^(##) `(.*)`$!\1 \2!' docs/cli-reference.md
269-
sed -i'' -E 's!^(######) \*\*(.*)\*\*$!\1 <b>\2</b>!' docs/cli-reference.md
291+
pnpm format
270292
git status
271293
if git diff --exit-code HEAD; then
272294
echo "No docs changes detected"
@@ -275,29 +297,3 @@ jobs:
275297
exit 1
276298
fi
277299
278-
license_check:
279-
name: Check licenses
280-
permissions: read-all
281-
runs-on: ubuntu-latest
282-
steps:
283-
- name: Find Git ref
284-
env:
285-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
286-
shell: bash
287-
run: |
288-
PR_NUMBER="${{ github.event.inputs.pr_number || null }}"
289-
if test -n "${PR_NUMBER}"; then
290-
GIT_REF="$( gh pr view --repo clockworklabs/SpacetimeDB $PR_NUMBER --json headRefName --jq .headRefName )"
291-
else
292-
GIT_REF="${{ github.ref }}"
293-
fi
294-
echo "GIT_REF=${GIT_REF}" >>"$GITHUB_ENV"
295-
- name: Checkout sources
296-
uses: actions/checkout@v4
297-
with:
298-
ref: ${{ env.GIT_REF }}
299-
- uses: dsherret/rust-toolchain-file@v1
300-
- name: Check for invalid licenses
301-
run: |
302-
cd tools/license-check
303-
cargo run

.github/workflows/docs-validate-nav-build.yml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,35 @@ jobs:
1818
- name: Set up Node.js
1919
uses: actions/setup-node@v3
2020
with:
21-
node-version: '16'
21+
node-version: '18'
22+
23+
- uses: pnpm/action-setup@v4
24+
with:
25+
run_install: true
26+
27+
- name: Get pnpm store directory
28+
working-directory: sdks/typescript
29+
shell: bash
30+
run: |
31+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
32+
33+
- uses: actions/cache@v4
34+
name: Setup pnpm cache
35+
with:
36+
path: ${{ env.STORE_PATH }}
37+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
38+
restore-keys: |
39+
${{ runner.os }}-pnpm-store-
2240
2341
- name: Install dependencies
2442
working-directory: docs
2543
run: |
26-
npm install
44+
pnpm install
45+
46+
- name: Lint
47+
working-directory: docs
48+
run: |
49+
pnpm lint
2750
2851
- name: Backup existing nav.js
2952
working-directory: docs
@@ -33,12 +56,12 @@ jobs:
3356
- name: Build nav.ts
3457
working-directory: docs
3558
run: |
36-
npm run build
59+
pnpm build
3760
3861
- name: Compare generated nav.js with original nav.js
3962
working-directory: docs
4063
run: |
41-
diff -q docs/nav.js docs/nav.js.original || (echo "Generated nav.js differs from committed version. Run 'npm run build' and commit the updated file." && exit 1)
64+
diff -q docs/nav.js docs/nav.js.original || (echo "Generated nav.js differs from committed version. Run 'pnpm build' and commit the updated file." && exit 1)
4265
4366
# We do this after checking that nav.js matches nav.ts, to avoid confusing error messages if an author updates one but not the other.
4467
# If the .ts and .js are in sync, it doesn't matter which one we check against here.

.github/workflows/typescript-lint.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ jobs:
2222

2323
- uses: pnpm/action-setup@v4
2424
with:
25-
version: 9.7
2625
run_install: true
2726

2827
- name: Get pnpm store directory

.github/workflows/typescript-test.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
merge_group:
99

1010
jobs:
11-
compile-and-test:
11+
build-and-test:
1212
runs-on: ubuntu-latest
1313

1414
steps:
@@ -22,7 +22,6 @@ jobs:
2222

2323
- uses: pnpm/action-setup@v4
2424
with:
25-
version: 9.7
2625
run_install: true
2726

2827
- name: Get pnpm store directory
@@ -39,9 +38,9 @@ jobs:
3938
restore-keys: |
4039
${{ runner.os }}-pnpm-store-
4140
42-
- name: Compile
41+
- name: Build
4342
working-directory: sdks/typescript
44-
run: pnpm compile
43+
run: pnpm build
4544

4645
- name: Run sdk tests
4746
working-directory: sdks/typescript/packages/sdk

crates/bindings-typescript/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"type": "module",
3636
"scripts": {
3737
"build": "tsc",
38-
"compile": "pnpm run build",
3938
"format": "prettier --write .",
4039
"lint": "eslint . && prettier . --check",
4140
"test": "vitest run",

crates/bindings-typescript/src/connection_id.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,17 @@ import { hexStringToU128, u128ToHexString, u128ToUint8Array } from './utils';
44
* A unique identifier for a client connected to a database.
55
*/
66
export class ConnectionId {
7-
data: bigint;
8-
9-
get __connection_id__(): bigint {
10-
return this.data;
11-
}
7+
__connection_id__: bigint;
128

139
/**
1410
* Creates a new `ConnectionId`.
1511
*/
1612
constructor(data: bigint) {
17-
this.data = data;
13+
this.__connection_id__ = data;
1814
}
1915

2016
isZero(): boolean {
21-
return this.data === BigInt(0);
17+
return this.__connection_id__ === BigInt(0);
2218
}
2319

2420
static nullIfZero(addr: ConnectionId): ConnectionId | null {
@@ -44,21 +40,21 @@ export class ConnectionId {
4440
* Compare two connection IDs for equality.
4541
*/
4642
isEqual(other: ConnectionId): boolean {
47-
return this.data == other.data;
43+
return this.__connection_id__ == other.__connection_id__;
4844
}
4945

5046
/**
5147
* Print the connection ID as a hexadecimal string.
5248
*/
5349
toHexString(): string {
54-
return u128ToHexString(this.data);
50+
return u128ToHexString(this.__connection_id__);
5551
}
5652

5753
/**
5854
* Convert the connection ID to a Uint8Array.
5955
*/
6056
toUint8Array(): Uint8Array {
61-
return u128ToUint8Array(this.data);
57+
return u128ToUint8Array(this.__connection_id__);
6258
}
6359

6460
/**

crates/bindings-typescript/src/identity.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import { hexStringToU256, u256ToHexString, u256ToUint8Array } from './utils';
44
* A unique identifier for a user connected to a database.
55
*/
66
export class Identity {
7-
data: bigint;
8-
9-
get __identity__(): bigint {
10-
return this.data;
11-
}
7+
__identity__: bigint;
128

139
/**
1410
* Creates a new `Identity`.
@@ -18,7 +14,7 @@ export class Identity {
1814
constructor(data: string | bigint) {
1915
// we get a JSON with __identity__ when getting a token with a JSON API
2016
// and an bigint when using BSATN
21-
this.data = typeof data === 'string' ? hexStringToU256(data) : data;
17+
this.__identity__ = typeof data === 'string' ? hexStringToU256(data) : data;
2218
}
2319

2420
/**
@@ -32,14 +28,14 @@ export class Identity {
3228
* Print the identity as a hexadecimal string.
3329
*/
3430
toHexString(): string {
35-
return u256ToHexString(this.data);
31+
return u256ToHexString(this.__identity__);
3632
}
3733

3834
/**
3935
* Convert the address to a Uint8Array.
4036
*/
4137
toUint8Array(): Uint8Array {
42-
return u256ToUint8Array(this.data);
38+
return u256ToUint8Array(this.__identity__);
4339
}
4440

4541
/**

docs/.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/*.md
2+
**/*.html

docs/.prettierrc

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

0 commit comments

Comments
 (0)