Skip to content

Commit

Permalink
Modernize (#52)
Browse files Browse the repository at this point in the history
* Lint script

* modernize: pnpm & prettier (#51)

* Push

* Push

* Run prettier

* Prettier stuff

* modernize: Remove Husky & pre-commit (#53)

* modernize: tsup (#54)

* Push

* jest

* modernize: jest to vitest (#55)

* modernize: pnpm workspace (#56)

* Monorepo

* Readme

* Move tsconfig

* Fix test

* modernize: CRA -> Vite apps (#57)

* Quickstart

* test app too

* Run pnpm

* Remove eslint files

* Format

* modernize: ES2017 classes (#58)

* modernize: in-house EventEmitter (#64)

* Push

* Undo min change

* modernize: undici for WebSocket in Node (#59)

* Use undici, remove other unneeded dependencies

* pnpm install

* Bundle everything

* Move everything to devDependency

* headers object

* Bump version to 0.11.0

* Push

* Hmm not working still

* Add undici to peerDependencies

* Measure size

* Push

* Fix formatting

* Working on node!!

---------

Co-authored-by: Zeke Foppa <github.com/bfops>
Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>

* modernize: Single output (#68)

* modernize: quickstart, move server into client (#69)

* Push

* Run pnpm install

* modernize: Engines field (#70)

* modernize: Continuous Releases (#71)

* Add pkg.pr.new

* Fix directory

* modernize: Changesets;provenance (#72)

* Push

* Push

* pnpm install

* Any update

* modernize: Split lint and test GH actions (#73)

* Push

* Forgot to rename

* We only care about Lint at commit level

* modernize: pkg.pr.new compact mode (#75)

* modernize: tweak prettier configuration (#74)

* docs: Undici as peerDependency

* modernize: webpackIgnore undici (#77)

* Push

* Webpackignore

* modernize: Conditional browser build (#79)

* Push

* Remove webpackIgnore

* fix: Remove obsolete comment

* modernize: isolatedDeclarations;de-cyclic imports (#81)

* Push

* Fix test

---------

Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
  • Loading branch information
PuruVJ and bfops authored Aug 21, 2024
1 parent 4e1bb07 commit 87ab7c2
Show file tree
Hide file tree
Showing 185 changed files with 8,307 additions and 71,508 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@3.0.2/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
11 changes: 6 additions & 5 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
## Description of Changes
*Describe what has been changed, any new features or bug fixes*

## API
_Describe what has been changed, any new features or bug fixes_

- [ ] This is an API breaking change to the SDK
## API

*If the API is breaking, please state below what will break*
- [ ] This is an API breaking change to the SDK

_If the API is breaking, please state below what will break_

## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*

_List any PRs here that are required for this SDK change to work_
24 changes: 24 additions & 0 deletions .github/workflows/cr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Continuous Releases

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18

- uses: pnpm/action-setup@v4
with:
version: 9.7
run_install: true

- name: Compile
run: pnpm compile

- name: Release
run: cd packages/sdk && pnpm dlx pkg-pr-new publish --compact
38 changes: 38 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Lint

on:
push:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18

- uses: pnpm/action-setup@v4
with:
version: 9.7
run_install: true

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Lint
run: pnpm lint
40 changes: 40 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Publish
on:
push:
branches:
- 'main'

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
publish:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
packages: write
pull-requests: write
issues: read
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 18.x
cache: 'pnpm'

- uses: pnpm/action-setup@v4
with:
version: 9.7
run_install: true

- run: pnpm compile

- name: Create Release Pull Request or Publish
id: changesets
uses: changesets/action@v1
with:
publish: pnpm run ci:release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
31 changes: 19 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,30 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: lts/*
node-version: 18

- name: Cache Yarn dependencies
uses: actions/cache@v2
- uses: pnpm/action-setup@v4
with:
path: .yarn/cache
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
version: 9.7
run_install: true

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Install dependencies
run: yarn install --immutable
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Run tests
run: yarn test
run: pnpm test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
.envrc
dist/
.DS_Store
1 change: 0 additions & 1 deletion .husky/.gitignore

This file was deleted.

4 changes: 0 additions & 4 deletions .husky/pre-commit

This file was deleted.

1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
tests
jest.config.js
.envrc
node_modules
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
pnpm-lock.yaml
dist
target
module_bindings
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"arrowParens": "avoid",
"jsxSingleQuote": false,
"trailingComma": "es5",
"endOfLine": "auto",
"printWidth": 80
}
78 changes: 2 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,3 @@
## SpacetimeDB SDK
`@clockworklabs/spacetimedb-sdk` is a TypeScript SDK for SpacetimeDB.

### Overview

This repository contains the TypeScript SDK for SpacetimeDB. The SDK allows to interact with the database server and is prepared to work with code generated from a SpacetimeDB backend code.

### Installation

The SDK is an NPM package, thus you can use your package manager of choice like NPM or Yarn, for example:

```
npm install --save @clockworklabs/spacetimedb-sdk
```

You can use the package in the browser, using a bundler like webpack of vite, and in terminal applications

### Usage

In order to connect to a database you have to create a new client:

```ts
import { SpacetimeDBClient } from "@clockworklabs/spacetimedb-sdk";

let client = new SpacetimeDBClient("spacetimedb.com/spacetimedb", "<db-name>");
```

If you would like to connect to the client you can call the below method. This also takes optional parameters to override the host or credentials:

```ts
client.connect();
```

If for some reason you need to disconnect the client:

```ts
client.disconnect();
```

This will connect to a database instance without a specified identity. If you want to persist an identity fetched on connection you can register an `onConnect` callback, which will receive a new assigned identity as an argument:

```ts
client.onConnect((identity: string) => {
console.log(identity);
console.log(client.token);
});
```

You may also pass credentials as an optional third argument:

```ts
let credentials = { identity: "<identity>", token: "<token>" };
let client = new SpacetimeDBClient(
"spacetimedb.com/spacetimedb",
"<db-name>",
credentials
);
```

Typically, you will use the SDK with types generated from a backend DB service. For example, given a component named `Player` you can subscribe to player updates by registering the component:

```ts
client.registerComponent(Player, "Player");
```

Then you will be able to register callbacks on insert and delete events, for example:

```ts
Player.onInsert((newPlayer: Player) => {
console.log(newPlayer);
});
```

Given a reducer called `CreatePlayer` you can call it using a call method:

```ts
CreatePlayer.call("Nickname");
```
Source code can be found here on [GitHub](https://github.com/clockworklabs/spacetimedb-typescript-sdk/blob/main/packages/sdk).
27 changes: 27 additions & 0 deletions examples/quickstart/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

server
module_bindings
8 changes: 8 additions & 0 deletions examples/quickstart/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
23 changes: 0 additions & 23 deletions examples/quickstart/client/.gitignore

This file was deleted.

Loading

0 comments on commit 87ab7c2

Please sign in to comment.