Skip to content

Commit

Permalink
Rework the frontend code
Browse files Browse the repository at this point in the history
 - Remove unused frontend packages
 - Improve typescript typing
 - Fix some small logic bugs
 - Small improvement to error handling
 - Change some repository links
  • Loading branch information
HeavenVolkoff committed Oct 7, 2024
1 parent 345c3d6 commit b5c14ba
Show file tree
Hide file tree
Showing 30 changed files with 469 additions and 1,366 deletions.
113 changes: 34 additions & 79 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,108 +12,63 @@ on:
workflow_dispatch:

jobs:
test:
name: Test
typescript:
name: TypeScript CI
runs-on: ubuntu-latest
outputs:
filter: ${{ steps.filter.outputs.workflows }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install NodeJS
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '16'
node-version: '20'

- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v4
with:
version: latest

- name: Install system dependencies # Pull this step from `oscartbeaumont/specta`
run: sudo apt-get update && sudo apt install libwebkit2gtk-4.1-dev build-essential curl wget file libssl-dev libayatana-appindicator3-dev librsvg2-dev

- name: Install Rust toolchain
run: rustup toolchain install stable --profile minimal

- name: Rust cache
uses: Swatinem/rust-cache@v2

- name: Install npm dependencies
- name: Install pnpm dependencies
run: pnpm i --frozen-lockfile

# TODO: Enabling this breaks the CI build with SolidJS Typescript errors and I don't get it.
# - name: Build npm packages
# run: pnpm build
- name: Check format with Prettier
run: pnpm prettier --check .

- name: Build Rust crate
run: cargo build --all-features
- name: Typecheck with TypeScript
run: pnpm typecheck

# - name: Generate test bindings for typecheck
# run: cargo test -p example tests::test_rspc_router -- --exact # TODO: Move this into a the first unit test

# - name: Typecheck
# run: pnpm typecheck

# - name: Test Rust crate
# run: cargo test --all --exclude create-rspc-app --all-features

- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
workflows:
- 'packages/**'
build-publish:
name: Publish to NPM
rust:
name: Rust CI
runs-on: ubuntu-latest
needs: test
if: (github.event_name == 'workflow_dispatch' || (needs.test.outputs.filter == 'true' && github.event_name == 'push')) && github.repository == 'spacedriveapp/rspc'
steps:
- uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: pnpm/[email protected]
with:
version: latest

- uses: actions/setup-node@v3
with:
node-version: '16'
cache: 'pnpm'

- name: Setup npmrc
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc

- name: Install dependencies
run: pnpm i --frozen-lockfile
- name: Install system dependencies
run: |-
sudo apt-get -yqq update
sudo apt-get install -yqq libwebkit2gtk-4.1-dev build-essential curl wget file libxdo-dev libssl-dev libayatana-appindicator3-dev librsvg2-dev
- name: Build
run: pnpm build

- name: Configure main version
if: github.ref == 'refs/heads/main'
run: pnpm set-package-versions
env:
RELEASE_COMMIT_SHA: ${{ github.sha }}
- name: Install Rust toolchain
run: rustup toolchain install stable --profile minimal

- name: Publish main to npm
if: github.ref == 'refs/heads/main'
run: pnpm publish -r ${TAG} --no-git-checks --filter "@oscartbeaumont-sd/rspc-*" --access public
env:
TAG: ${{ (github.ref == 'refs/heads/main' && '--tag=main') || '' }}
- name: Build Rust crate
run: cargo build --all-features

# - name: Configure release version
# if: github.ref_type == 'tag'
# run: pnpm set-package-versions
- name: Check Rust format
run: cargo fmt -- --check

# - name: Publish release to npm
# if: github.ref_type == 'tag'
# run: pnpm publish -r ${TAG} --no-git-checks --filter "@oscartbeaumont-sd/rspc-*" --access public
# env:
# TAG: ${{ (contains(github.ref_name, '-beta.') && '--tag=beta') || ''}}
- name: Run Clippy
uses: giraffate/clippy-action@v1
with:
reporter: github-pr-review
tool_name: 'Clippy'
filter_mode: diff_context
github_token: ${{ secrets.GITHUB_TOKEN }}
clippy_flags: --workspace --all-features --locked
fail_on_error: true
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pnpm-lock.yaml
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ description = "A blazing fast and easy to use TRPC server for Rust."
edition = "2021"
license = "MIT"

documentation = "https://docs.rs/rspc/latest/rspc"
repository = "https://github.com/oscartbeaumont/rspc"
repository = "https://github.com/spacedriveapp/rspc"

categories = ["asynchronous", "web-programming"]
include = ["/LICENCE", "/README.md", "/src"]
Expand Down
6 changes: 2 additions & 4 deletions httpz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ description = "Code once, support every Rust webserver!"
edition = "2021"
license = "MIT"

documentation = "https://docs.rs/httpz"
homepage = "https://github.com/oscartbeaumont/httpz"
readme = "README.md"
repository = "https://github.com/oscartbeaumont/httpz"
readme = "README.md"
repository = "https://github.com/spacedriveapp/rspc/tree/main/httpz"

categories = [
"asynchronous",
Expand Down
2 changes: 1 addition & 1 deletion httpz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ httpz is primarily designed to make life easier for library authors. It allows a

Libraries using httpz:

- [rspc](https://github.com/oscartbeaumont/rspc)
- [rspc](https://github.com/spacedriveapp/rspc)
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"name": "@oscartbeaumont-sd/rspc-workspace",
"version": "0.0.0",
"name": "@spacedrive/rspc-workspace",
"version": "1.0.0",
"description": "A blazingly fast and easy to use TRPC-like server for Rust.",
"keywords": [],
"author": "Oscar Beaumont",
"license": "MIT",
"private": true,
"scripts": {
"format": "prettier --write .",
"test": "pnpm -r --parallel --filter=!@oscartbeaumont-sd/rspc-docs --filter=!@oscartbeaumont-sd/rspc-config --filter=!@oscartbeaumont-sd/rspc-examples-* --filter=!rspc-vscode exec pnpm test",
"typecheck": "pnpm -r --filter=!rspc-vscode exec tsc --noEmit",
"client": "pnpm --filter @oscartbeaumont-sd/rspc-client -- ",
"react": "pnpm --filter @oscartbeaumont-sd/rspc-react -- ",
"tauri": "pnpm --filter @oscartbeaumont-sd/rspc-tauri -- "
"test": "echo 'No tests yet.' >&2 && exit 1",
"typecheck": "pnpm -r exec tsc --noEmit",
"client": "pnpm --filter @spacedrive/rspc-client -- ",
"react": "pnpm --filter @spacedrive/rspc-react -- ",
"tauri": "pnpm --filter @spacedrive/rspc-tauri -- "
},
"devDependencies": {
"typescript": "^5.6.2",
"@ianvs/prettier-plugin-sort-imports": "^4.3.1"
},
"packageManager": "pnpm@9.11.0"
"packageManager": "pnpm@9.12.0"
}
4 changes: 2 additions & 2 deletions packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oscartbeaumont-sd/rspc-client",
"version": "0.1.3",
"name": "@spacedrive/rspc-client",
"version": "0.2.0",
"description": "A blazingly fast and easy to use TRPC-like server for Rust.",
"keywords": [],
"author": "Oscar Beaumont",
Expand Down
71 changes: 55 additions & 16 deletions packages/client/src/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,82 @@
// Checkout the unit test 'export_internal_types' to see where this files comes from!

/**
* TODO
* Represents a unique identifier for a request.
*
* @internal
*/
export type RequestId = null | number | string

export type SubscriptionStop = { input: RequestId }
export type SubscriptionStop = { readonly input: RequestId }

export type NewOrOldInput = [RequestId, unknown] | unknown
export type NewOrOldInput = readonly [RequestId, unknown] | unknown

/**
* TODO
* Represents a request object with various methods.
*
* @internal
*/
export type Request = (
| { method: 'query'; params: { path: string; input: unknown } }
| { method: 'mutation'; params: { path: string; input: unknown } }
| { method: 'subscription'; params: { path: string; input: NewOrOldInput } }
export type Request = Readonly<
| {
method: 'query'
params: { path: string; input: unknown }
}
| {
method: 'mutation'
params: { path: string; input: unknown }
}
| {
method: 'subscription'
params: { path: string; input: NewOrOldInput }
}
| { method: 'subscriptionStop'; params: SubscriptionStop | null }
) & { jsonrpc?: string | null; id?: RequestId }
> & { jsonrpc?: string | null; id?: RequestId }

/**
* Represents a Typescript procedure file which is generated by the Rust code.
* This is codegenerated Typescript file is how we can validate the types on the frontend match Rust.
* This code-generated Typescript file is how we can validate the types on the frontend match Rust.
*
* @internal
*/
export type ProcedureDef = { key: string; input: any; result: any }
export type ProcedureDef = Readonly<{
key: string
input: unknown
result: unknown
}>

/**
* TODO
* Represents the inner structure of a request object.
*
* @internal
*/
export type RequestInner =
| { method: 'query'; params: { path: string; input: unknown } }
| { method: 'mutation'; params: { path: string; input: unknown } }
| { method: 'subscription'; params: { path: string; input: NewOrOldInput } }
export type RequestInner = Readonly<
| {
method: 'query'
params: { path: string; input: unknown }
}
| {
method: 'mutation'
params: { path: string; input: unknown }
}
| {
method: 'subscription'
params: { path: string; input: NewOrOldInput }
}
| { method: 'subscriptionStop'; params: SubscriptionStop | null }
>

export type Response = Readonly<{
id: string | number
result:
| {
type: 'event' | 'response'
data: unknown
}
| {
type: 'error'
data: {
message: string
code: number
}
}
}>
Loading

0 comments on commit b5c14ba

Please sign in to comment.