Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize #52

Merged
merged 25 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f3c4400
Lint script
PuruVJ Jul 16, 2024
853708b
modernize: pnpm & prettier (#51)
PuruVJ Jul 16, 2024
0018a47
modernize: Remove Husky & pre-commit (#53)
PuruVJ Jul 16, 2024
779d0da
modernize: tsup (#54)
PuruVJ Jul 16, 2024
3be2a5e
modernize: jest to vitest (#55)
PuruVJ Jul 16, 2024
2418583
modernize: pnpm workspace (#56)
PuruVJ Jul 16, 2024
ee4d46c
modernize: CRA -> Vite apps (#57)
PuruVJ Jul 16, 2024
cc522e0
modernize: ES2017 classes (#58)
PuruVJ Jul 16, 2024
037a108
modernize: in-house EventEmitter (#64)
PuruVJ Aug 7, 2024
c5e15ac
modernize: undici for WebSocket in Node (#59)
PuruVJ Aug 14, 2024
6bf9e64
modernize: Single output (#68)
PuruVJ Aug 14, 2024
4b25b1d
modernize: quickstart, move server into client (#69)
PuruVJ Aug 14, 2024
3f91365
modernize: Engines field (#70)
PuruVJ Aug 14, 2024
681e3a0
Merge branch 'main' into modernize-nexus
PuruVJ Aug 14, 2024
5a76e11
modernize: Continuous Releases (#71)
PuruVJ Aug 14, 2024
76fe5ce
modernize: Changesets;provenance (#72)
PuruVJ Aug 14, 2024
9fb96de
modernize: Split lint and test GH actions (#73)
PuruVJ Aug 14, 2024
f3dcfb4
modernize: pkg.pr.new compact mode (#75)
PuruVJ Aug 14, 2024
3b4ea79
modernize: tweak prettier configuration (#74)
PuruVJ Aug 14, 2024
e847e12
docs: Undici as peerDependency
PuruVJ Aug 14, 2024
2fd71d3
modernize: webpackIgnore undici (#77)
PuruVJ Aug 15, 2024
2840715
modernize: Conditional browser build (#79)
PuruVJ Aug 19, 2024
628711c
fix: Remove obsolete comment
PuruVJ Aug 19, 2024
3ff68ac
modernize: isolatedDeclarations;de-cyclic imports (#81)
PuruVJ Aug 19, 2024
325d3c8
Merge branch 'main' into modernize-nexus
PuruVJ Aug 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/[email protected]/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