Removed @clockworklabs/typescript-sdk in favor of spacetimedb (#3262)

# Description of Changes

This PR removes the `@clockworklabs/typescript-sdk` from the repository
and retains only `spacetimedb` in the `crates/bindings-typescript`
directory. Some files are migrated to `spacetimedb`. I have also updated
the appropriate READMEs.

In addition I have symlinked the old `sdks/typescript` directory to
point to `crates/bindings-typescript`.

# API and ABI breaking changes

This is not technically a breaking change of any kind, although it does
orphan and deprecate the
[@clockworklabs/spacetimedb-sdk](https://www.npmjs.com/package/@clockworklabs/spacetimedb-sdk)
npm package. This package will no longer work with SpacetimeDB.

Users should now install and use the `spacetimedb` package.

# Expected complexity level and risk

2, it's a straightforward change but affects many files.

# Testing

- [ ] I ran `pnpm test` in the `spacetimedb` package
- [ ] I ran the quickstart app

---------

Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
This commit is contained in:
Tyler Cloutier
2025-09-22 20:25:24 -04:00
committed by GitHub
parent b44d4bae4c
commit 58d299ea42
86 changed files with 411 additions and 1552 deletions
-1
View File
@@ -362,7 +362,6 @@ jobs:
- name: Get pnpm store directory
shell: bash
working-directory: sdks/typescript
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
+8 -16
View File
@@ -26,7 +26,7 @@ jobs:
- name: Get pnpm store directory
shell: bash
working-directory: sdks/typescript
working-directory: crates/bindings-typescript
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
@@ -38,22 +38,14 @@ jobs:
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Build module library
- name: Build module library and SDK
working-directory: crates/bindings-typescript
run: pnpm build
- name: Run module library tests
- name: Run module library and SDK tests
working-directory: crates/bindings-typescript
run: pnpm test
- name: Build SDK
working-directory: sdks/typescript
run: pnpm build
- name: Run SDK tests
working-directory: sdks/typescript
run: pnpm test
# - name: Extract SpacetimeDB branch name from file
# id: extract-branch
# run: |
@@ -104,12 +96,12 @@ jobs:
- name: Generate client bindings
working-directory: modules/quickstart-chat
run: |
spacetime generate --lang typescript --out-dir ../../sdks/typescript/examples/quickstart-chat/src/module_bindings
cd ../../sdks/typescript
pnpm lint --write
spacetime generate --lang typescript --out-dir ../../crates/bindings-typescript/examples/quickstart-chat/src/module_bindings
cd ../../crates/bindings-typescript
pnpm format
- name: Check for changes
working-directory: sdks/typescript
working-directory: crates/bindings-typescript
run: |
# This was copied from SpacetimeDB/tools/check-diff.sh.
# It's required because `spacetime generate` creates lines with the SpacetimeDB commit
@@ -137,7 +129,7 @@ jobs:
# spacetime logs quickstart-chat
- name: Check that quickstart-chat builds
working-directory: sdks/typescript/examples/quickstart-chat
working-directory: crates/bindings-typescript/examples/quickstart-chat
run: pnpm build
# - name: Run quickstart-chat tests
@@ -0,0 +1,4 @@
src/sdk/client_api/*.ts linguist-generated=true
src/lib/autogen/*.ts linguist-generated=true
test-app/src/module_bindings/*.ts linguist-generated=true
examples/quickstart/client/src/module_bindings/*.ts linguist-generated=true
+13
View File
@@ -0,0 +1,13 @@
# Notes for maintainers
The directory `src/sdk/client_api` is generated from [the SpacetimeDB client-api-messages](https://github.com/clockworklabs/SpacetimeDB/tree/master/crates/client-api-messages).
The directory `src/lib/autogen` is generated from the SpacetimeDB `ModuleDef` definition using the `regen-typescript-moduledef` Rust program.
In order to regenerate both of these bindings, run `pnpm generate`.
Whenever the `client-api-messages` crate or the `ModuleDef` changes, you'll have to manually re-generate the definitions.
## Releases and publishing
In order to release and publish a new version of the package, update the version and run `npm publish`.
+118
View File
@@ -0,0 +1,118 @@
## SpacetimeDB Module Library and SDK
### Overview
This repository contains both the SpacetimeDB module library and the TypeScript SDK for SpacetimeDB. The SDK allows you to interact with the database server from a client and applies type information from your SpacetimeDB server module.
### Installation
The SDK is an NPM package, thus you can use your package manager of choice like NPM or Yarn, for example:
```
npm add spacetimedb
```
You can use the package in the browser, using a bundler like vite/parcel/rsbuild, in server-side applications like NodeJS, Deno, Bun, NextJS, Remix, and in Cloudflare Workers.
> NOTE: For usage in NodeJS 18-21, you need to install the `undici` package as a peer dependency: `npm add spacetimedb undici`. Node 22 and later are supported out of the box.
### Usage
In order to connect to a database you have to generate module bindings for your database.
```ts
import { DbConnection } from './module_bindings';
const connection = DbConnection.builder()
.withUri('ws://localhost:3000')
.withModuleName('MODULE_NAME')
.onDisconnect(() => {
console.log('disconnected');
})
.onConnectError(() => {
console.log('client_error');
})
.onConnect((connection, identity, _token) => {
console.log(
'Connected to SpacetimeDB with identity:',
identity.toHexString()
);
connection.subscriptionBuilder().subscribe('SELECT * FROM player');
})
.withToken('TOKEN')
.build();
```
If you need to disconnect the client:
```ts
connection.disconnect();
```
Typically, you will use the SDK with types generated from SpacetimeDB module. For example, given a table named `Player` you can subscribe to player updates like this:
```ts
connection.db.player.onInsert((ctx, player) => {
console.log(player);
});
```
Given a reducer called `CreatePlayer` you can call it using a call method:
```ts
connection.reducers.createPlayer();
```
#### React Usage
This module also include React hooks to subscribe to tables under the `spacetimedb/react` subpath. In order to use SpacetimeDB React hooks in your project, first add a `SpacetimeDBProvider` at the top of your component hierarchy:
```tsx
const connectionBuilder = DbConnection.builder()
.withUri('ws://localhost:3000')
.withModuleName('MODULE_NAME')
.withLightMode(true)
.onDisconnect(() => {
console.log('disconnected');
})
.onConnectError(() => {
console.log('client_error');
})
.onConnect((conn, identity, _token) => {
console.log(
'Connected to SpacetimeDB with identity:',
identity.toHexString()
);
conn.subscriptionBuilder().subscribe('SELECT * FROM player');
})
.withToken('TOKEN');
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<SpacetimeDBProvider connectionBuilder={connectionBuilder}>
<App />
</SpacetimeDBProvider>
</React.StrictMode>
);
```
One you add a `SpacetimeDBProvider` to your hierarchy, you can use SpacetimeDB React hooks in your render function:
```tsx
function App() {
const conn = useSpacetimeDB<DbConnection>();
const { rows: messages } = useTable<DbConnection, Message>('message');
...
}
```
### Developer notes
To run the tests, do:
```sh
pnpm build && pnpm test
```
@@ -1,5 +1,5 @@
{
"name": "client",
"name": "@clockworklabs/quickstart-chat",
"private": true,
"version": "0.0.1",
"type": "module",
@@ -16,7 +16,7 @@
"spacetime:publish": "spacetime publish chat --project-path server --server testnet"
},
"dependencies": {
"@clockworklabs/spacetimedb-sdk": "workspace:*",
"spacetimedb": "workspace:*",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

@@ -2,7 +2,7 @@ import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, it, expect } from 'vitest';
import App from './App';
import { SpacetimeDBProvider } from '@clockworklabs/spacetimedb-sdk/react';
import { SpacetimeDBProvider } from 'spacetimedb/react';
import { DbConnection } from './module_bindings';
describe('App Integration Test', () => {
@@ -1,13 +1,8 @@
import React, { useState } from 'react';
import './App.css';
import { DbConnection, Message, User } from './module_bindings';
import {
useSpacetimeDB,
useTable,
where,
eq,
} from '@clockworklabs/spacetimedb-sdk/react';
import { Identity, Timestamp } from '@clockworklabs/spacetimedb-sdk';
import { useSpacetimeDB, useTable, where, eq } from 'spacetimedb/react';
import { Identity, Timestamp } from 'spacetimedb';
export type PrettyMessage = {
senderName: string;

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

@@ -2,8 +2,8 @@ import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import './index.css';
import App from './App.tsx';
import { Identity } from '@clockworklabs/spacetimedb-sdk';
import { SpacetimeDBProvider } from '@clockworklabs/spacetimedb-sdk/react';
import { Identity } from 'spacetimedb';
import { SpacetimeDBProvider } from 'spacetimedb/react';
import { DbConnection, ErrorContext } from './module_bindings/index.ts';
const onConnect = (conn: DbConnection, identity: Identity, token: string) => {
@@ -25,7 +25,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from '@clockworklabs/spacetimedb-sdk';
} from 'spacetimedb';
export type IdentityConnected = {};
/**
@@ -25,7 +25,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from '@clockworklabs/spacetimedb-sdk';
} from 'spacetimedb';
export type IdentityDisconnected = {};
/**
@@ -27,7 +27,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from '@clockworklabs/spacetimedb-sdk';
} from 'spacetimedb';
// Import and reexport all reducer arg types
import { IdentityConnected } from './identity_connected_reducer.ts';
@@ -25,7 +25,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from '@clockworklabs/spacetimedb-sdk';
} from 'spacetimedb';
import { Message } from './message_type';
import {
type EventContext,
@@ -25,7 +25,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from '@clockworklabs/spacetimedb-sdk';
} from 'spacetimedb';
export type Message = {
sender: __Identity;
@@ -25,7 +25,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from '@clockworklabs/spacetimedb-sdk';
} from 'spacetimedb';
export type SendMessage = {
text: string;
@@ -25,7 +25,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from '@clockworklabs/spacetimedb-sdk';
} from 'spacetimedb';
export type SetName = {
name: string;
@@ -25,7 +25,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from '@clockworklabs/spacetimedb-sdk';
} from 'spacetimedb';
import { User } from './user_type';
import {
type EventContext,
@@ -25,7 +25,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from '@clockworklabs/spacetimedb-sdk';
} from 'spacetimedb';
export type User = {
identity: __Identity;
+15 -11
View File
@@ -1,6 +1,6 @@
{
"name": "spacetimedb",
"version": "0.0.1",
"version": "1.4.0",
"description": "API and ABI bindings for the SpacetimeDB TypeScript module library",
"homepage": "https://github.com/clockworklabs/SpacetimeDB#readme",
"bugs": {
@@ -21,7 +21,9 @@
"type": "module",
"sideEffects": false,
"scripts": {
"build": "tsup",
"build:js": "tsup",
"build:types": "tsc -p tsconfig.build.json",
"build": "pnpm -s build:js && pnpm -s build:types",
"format": "prettier . --write --ignore-path ../../.prettierignore",
"lint": "eslint . && prettier . --check --ignore-path ../../.prettierignore",
"test": "vitest run",
@@ -29,39 +31,41 @@
"brotli-size": "brotli-size dist/index.js",
"size": "pnpm -s build && size-limit",
"generate:moduledef": "cargo run -p spacetimedb-codegen --example regen-typescript-moduledef && prettier --write src/lib/autogen",
"generate:client-api": "cargo build -p spacetimedb-standalone && cargo run -p spacetimedb-client-api-messages --example get_ws_schema > ws_schema.json && cargo run -p spacetimedb-cli generate --lang typescript --out-dir src/sdk/client_api --module-def ws_schema.json && rm ws_schema.json && find src/sdk/client_api -type f -exec perl -pi -e 's#\\@clockworklabs/spacetimedb-sdk#../../index#g' {} + && prettier --write src/sdk/client_api",
"generate:client-api": "cargo build -p spacetimedb-standalone && cargo run -p spacetimedb-client-api-messages --example get_ws_schema > ws_schema.json && cargo run -p spacetimedb-cli generate --lang typescript --out-dir src/sdk/client_api --module-def ws_schema.json && rm ws_schema.json && find src/sdk/client_api -type f -exec perl -pi -e 's#spacetimedb#../../index#g' {} + && prettier --write src/sdk/client_api",
"generate:test-app": "pnpm --filter @clockworklabs/test-app generate",
"generate": "pnpm generate:moduledef && pnpm generate:client-api && pnpm generate:test-app"
"generate": "pnpm generate:moduledef && pnpm generate:client-api && pnpm generate:test-app",
"prepublishOnly": "pnpm run build && pnpm run test && pnpm run size"
},
"source": "src/index.ts",
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"types": "src/index.ts",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./src/index.ts",
"source": "./src/index.ts",
"development": "./src/index.ts",
"types": "./dist/index.d.ts",
"browser": "./dist/index.browser.mjs",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"default": "./dist/index.mjs"
},
"./sdk": {
"types": "./src/sdk/index.ts",
"development": "./src/index.ts",
"types": "./dist/index.d.ts",
"browser": "./dist/sdk/index.browser.mjs",
"import": "./dist/sdk/index.mjs",
"require": "./dist/sdk/index.cjs",
"default": "./dist/sdk/index.mjs"
},
"./react": {
"types": "./src/react/index.ts",
"development": "./src/react/index.ts",
"types": "./dist/react/index.d.ts",
"import": "./dist/react/index.mjs",
"require": "./dist/react/index.cjs",
"default": "./dist/react/index.mjs"
},
"./server": {
"types": "./src/server/index.ts",
"development": "./src/server/index.ts",
"types": "./dist/server/index.d.ts",
"import": "./dist/server/index.mjs",
"require": "./dist/server/index.cjs",
"default": "./dist/server/index.mjs"
@@ -1,4 +1,7 @@
import { DbConnectionBuilder, type DbConnectionImpl } from '../index';
import {
DbConnectionBuilder,
type DbConnectionImpl,
} from '../sdk/db_connection_impl';
import * as React from 'react';
import { SpacetimeDBContext } from './useSpacetimeDB';
@@ -1,5 +1,5 @@
import { createContext, useContext, type Context } from 'react';
import type { DbConnectionImpl } from '../index';
import type { DbConnectionImpl } from '../sdk/db_connection_impl';
export const SpacetimeDBContext: Context<DbConnectionImpl | undefined> =
createContext<DbConnectionImpl | undefined>(undefined);
@@ -6,7 +6,7 @@ import {
useSyncExternalStore,
} from 'react';
import { useSpacetimeDB } from './useSpacetimeDB';
import { DbConnectionImpl, TableCache } from '../sdk';
import { DbConnectionImpl, TableCache } from '../sdk/db_connection_impl';
export interface UseQueryCallbacks<RowType> {
onInsert?: (row: RowType) => void;
+1 -1
View File
@@ -1,7 +1,7 @@
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
// This was generated using spacetimedb cli version 1.4.0 (commit 9e4684ee0f7b78689c60efbdcb7a9e23e34eea15).
// This was generated using ../../index cli version 1.4.0 (commit 9e4684ee0f7b78689c60efbdcb7a9e23e34eea15).
/* eslint-disable */
/* tslint:disable */
@@ -1,6 +1,6 @@
import { DbConnectionImpl, type ConnectionEvent } from './db_connection_impl';
import { EventEmitter } from './event_emitter';
import type { Identity } from 'spacetimedb';
import type { Identity } from '../';
import type RemoteModule from './spacetime_module';
import { ensureMinimumVersionOrThrow } from './version';
import { WebsocketDecompressAdapter } from './websocket_decompress_adapter';
@@ -1,12 +1,12 @@
import { ConnectionId } from 'spacetimedb';
import { ConnectionId } from '../';
import {
AlgebraicType,
type AlgebraicTypeVariants,
type ComparablePrimitive,
} from 'spacetimedb';
import { parseValue } from 'spacetimedb';
import { BinaryReader } from 'spacetimedb';
import { BinaryWriter } from 'spacetimedb';
} from '../';
import { parseValue } from '../';
import { BinaryReader } from '../';
import { BinaryWriter } from '../';
import { BsatnRowList } from './client_api/bsatn_row_list_type.ts';
import { ClientMessage } from './client_api/client_message_type.ts';
import { DatabaseUpdate } from './client_api/database_update_type.ts';
@@ -25,7 +25,7 @@ import {
} from './event_context.ts';
import { EventEmitter } from './event_emitter.ts';
import { decompress } from './decompress.ts';
import type { Identity } from 'spacetimedb';
import type { Identity } from '../';
import type {
IdentityTokenMessage,
Message,
@@ -1,8 +1,8 @@
import { ConnectionId } from 'spacetimedb';
import { ConnectionId } from '../';
import type { UpdateStatus } from './client_api/index.ts';
import { Identity } from 'spacetimedb';
import { Identity } from '../';
import type { TableUpdate } from './table_cache.ts';
import { Timestamp } from 'spacetimedb';
import { Timestamp } from '../';
export type InitialSubscriptionMessage<RowType extends Record<string, any>> = {
tag: 'InitialSubscription';
@@ -1,7 +1,7 @@
import { ConnectionId } from 'spacetimedb';
import { Timestamp } from 'spacetimedb';
import { ConnectionId } from '../';
import { Timestamp } from '../';
import type { UpdateStatus } from './client_api/index.ts';
import { Identity } from 'spacetimedb';
import { Identity } from '../';
export type ReducerInfoType = { name: string; args?: any } | never;
@@ -1,4 +1,4 @@
import type { AlgebraicType } from 'spacetimedb';
import type { AlgebraicType } from '../';
import type { DbConnectionImpl } from './db_connection_impl';
export interface TableRuntimeTypeInfo {
@@ -2,7 +2,7 @@ import { EventEmitter } from './event_emitter.ts';
import type { TableRuntimeTypeInfo } from './spacetime_module.ts';
import { stdbLogger } from './logger.ts';
import type { ComparablePrimitive } from 'spacetimedb';
import type { ComparablePrimitive } from '../';
import type { EventContextInterface } from './index.ts';
export type Operation<
@@ -1,13 +1,5 @@
import { decompress } from './decompress';
// Add type declarations for ImportMeta.env
interface ImportMetaEnv {
readonly BROWSER?: string;
}
interface ImportMeta {
readonly env: ImportMetaEnv;
}
import { resolveWS } from './ws';
export class WebsocketDecompressAdapter {
onclose?: (...ev: any[]) => void;
@@ -91,27 +83,7 @@ export class WebsocketDecompressAdapter {
}): Promise<WebsocketDecompressAdapter> {
const headers = new Headers();
let WS: typeof WebSocket;
if ((import.meta as unknown as ImportMeta).env?.BROWSER === 'false') {
if ('WebSocket' in globalThis) {
WS = WebSocket;
} else {
try {
const { WebSocket: UndiciWS } = await import('undici');
WS = UndiciWS as unknown as typeof WebSocket;
} catch (err) {
console.warn(
'[spacetimedb-sdk] No global WebSocket found. ' +
'On Node 1821, please install `undici` (npm install undici) ' +
'to enable WebSocket support.'
);
throw err;
}
}
} else {
WS = WebSocket;
}
const WS = await resolveWS();
// We swap our original token to a shorter-lived token
// to avoid sending the original via query params.
@@ -1,4 +1,4 @@
import { AlgebraicType, BinaryWriter } from 'spacetimedb';
import { AlgebraicType, BinaryWriter } from '../';
import { ServerMessage } from './client_api/index.ts';
class WebsocketTestAdapter {
+24
View File
@@ -0,0 +1,24 @@
export async function resolveWS(): Promise<typeof WebSocket> {
// Browser or Node >= 22 (or any env that exposes global WebSocket)
if (typeof (globalThis as any).WebSocket !== 'undefined') {
return (globalThis as any).WebSocket as typeof WebSocket;
}
// Node without a global WebSocket: lazily load undici's polyfill.
// Use an unstatable dynamic import so bundlers don't prebundle it.
const dynamicImport = new Function('m', 'return import(m)') as (
m: string
) => Promise<any>;
try {
const { WebSocket: UndiciWS } = await dynamicImport('undici');
return UndiciWS as unknown as typeof WebSocket;
} catch (err) {
console.warn(
'[spacetimedb-sdk] No global WebSocket found. ' +
'On Node 1821, please install `undici` (npm install undici) ' +
'to enable WebSocket support.'
);
throw err;
}
}
@@ -12,7 +12,7 @@
"format": "prettier . --write --ignore-path ../../../.prettierignore",
"lint": "eslint . && prettier . --check --ignore-path ../../../.prettierignore",
"preview": "vite preview",
"generate": "cargo build -p spacetimedb-standalone && cargo run -p spacetimedb-cli generate --lang typescript --out-dir src/module_bindings --project-path server && prettier --write src/module_bindings && find src/module_bindings -type f -exec perl -pi -e 's#\\@clockworklabs/spacetimedb-sdk#../../../src/index#g' {} + && prettier --write src/module_bindings",
"generate": "cargo build -p spacetimedb-standalone && cargo run -p spacetimedb-cli generate --lang typescript --out-dir src/module_bindings --project-path server && prettier --write src/module_bindings && find src/module_bindings -type f -exec perl -pi -e 's#spacetimedb#../../../src/index#g' {} + && prettier --write src/module_bindings",
"spacetime:generate": "spacetime generate --lang typescript --out-dir src/module_bindings --project-path server",
"spacetime:start": "spacetime start server",
"spacetime:publish:local": "spacetime publish game --project-path server --server local",
@@ -1,7 +1,7 @@
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
// This was generated using spacetimedb cli version 1.4.0 (commit 9e4684ee0f7b78689c60efbdcb7a9e23e34eea15).
// This was generated using ../../../src/index cli version 1.4.0 (commit 9e4684ee0f7b78689c60efbdcb7a9e23e34eea15).
/* eslint-disable */
/* tslint:disable */
+22 -1
View File
@@ -1,5 +1,11 @@
import { describe, it, expect } from 'vitest';
import { AlgebraicType, t } from '../src/index';
import {
AlgebraicType,
ConnectionId,
Identity,
t,
type IdentityTokenMessage,
} from '../src/index';
describe('TypeBuilder', () => {
it('builds the correct algebraic type for a point', () => {
@@ -131,3 +137,18 @@ describe('TypeBuilder', () => {
expect(col.columnMetadata.isScheduleAt).toBe(true);
});
});
describe('Identity', () => {
it('imports something from the spacetimedb sdk', () => {
const _msg: IdentityTokenMessage = {
tag: 'IdentityToken',
identity: Identity.fromString(
'0xc200000000000000000000000000000000000000000000000000000000000000'
),
token: 'some-token',
connectionId: ConnectionId.fromString(
'0x00000000000000000000000000000000'
),
};
});
});
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": false,
"declaration": true,
"emitDeclarationOnly": true,
"declarationMap": true,
"outDir": "dist",
"rootDir": "src"
},
"include": ["src/**/*"]
}
+4 -26
View File
@@ -3,8 +3,8 @@ import { defineConfig, type Options } from 'tsup';
function commonEsbuildTweaks() {
return (options: any) => {
// Prefer "exports"."source" when deps provide it; harmless otherwise.
options.conditions = ['source', 'import', 'default'];
// Prefer "exports"."development" when deps provide it; harmless otherwise.
options.conditions = ['development', 'import', 'default'];
options.mainFields = ['browser', 'module', 'main'];
};
}
@@ -20,17 +20,12 @@ export default defineConfig([
format: ['esm', 'cjs'],
target: 'es2022',
outDir: 'dist',
dts: false, // types come from ./src in package.json
dts: false,
sourcemap: true,
clean: true,
platform: 'neutral',
treeshake: 'smallest',
external: ['undici'],
// env variable used at build time to determine platform-specific code
// see: websocket_decompress_adapter.ts
env: {
BROWSER: 'false',
},
outExtension,
esbuildOptions: commonEsbuildTweaks(),
},
@@ -47,9 +42,6 @@ export default defineConfig([
platform: 'browser',
treeshake: 'smallest',
external: ['undici'],
env: {
BROWSER: 'true',
},
outExtension,
esbuildOptions: commonEsbuildTweaks(),
},
@@ -96,9 +88,6 @@ export default defineConfig([
platform: 'neutral',
treeshake: 'smallest',
external: ['undici'],
env: {
BROWSER: 'false',
},
outExtension,
esbuildOptions: commonEsbuildTweaks(),
},
@@ -115,9 +104,6 @@ export default defineConfig([
platform: 'browser',
treeshake: 'smallest',
external: ['undici'],
env: {
BROWSER: 'true',
},
outExtension,
esbuildOptions: commonEsbuildTweaks(),
},
@@ -134,9 +120,6 @@ export default defineConfig([
platform: 'neutral', // flip to 'node' if you actually rely on Node builtins
treeshake: 'smallest',
external: ['undici'],
env: {
BROWSER: 'false',
},
outExtension,
esbuildOptions: commonEsbuildTweaks(),
},
@@ -158,9 +141,6 @@ export default defineConfig([
platform: 'browser',
treeshake: 'smallest',
external: ['undici'],
env: {
BROWSER: 'true',
},
outExtension,
esbuildOptions: commonEsbuildTweaks(),
},
@@ -175,6 +155,7 @@ export default defineConfig([
sourcemap: true,
minify: 'terser',
platform: 'browser',
external: ['undici'],
treeshake: 'smallest',
outExtension: ({ format }) => ({ js: format === 'cjs' ? '.cjs' : '.mjs' }),
esbuildOptions: commonEsbuildTweaks(),
@@ -192,9 +173,6 @@ export default defineConfig([
platform: 'browser',
treeshake: 'smallest',
external: ['undici'],
env: {
BROWSER: 'true',
},
outExtension: ({ format }) => ({ js: format === 'cjs' ? '.cjs' : '.mjs' }),
esbuildOptions: commonEsbuildTweaks(),
},
@@ -39,7 +39,7 @@ fn main() -> anyhow::Result<()> {
if filename == "index.ts" {
return Ok(());
}
let code = regex_replace!(&code, r"@clockworklabs/spacetimedb-sdk", "../../index");
let code = regex_replace!(&code, r#"from "spacetimedb";"#, r#"from "../../index";"#);
// Elide types which are related to client-side only things
let code = regex_replace!(&code, r"type CallReducerFlags as __CallReducerFlags,", r"");
+1 -1
View File
@@ -705,7 +705,7 @@ fn print_spacetimedb_imports(out: &mut Indenter) {
writeln!(out, "{ty},");
}
out.dedent(1);
writeln!(out, "}} from \"@clockworklabs/spacetimedb-sdk\";");
writeln!(out, "}} from \"spacetimedb\";");
}
fn print_file_header(output: &mut Indenter, include_version: bool) {
@@ -30,7 +30,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type AddPlayer = {
name: string,
@@ -92,7 +92,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type AddPrivate = {
name: string,
@@ -154,7 +154,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type Add = {
name: string,
@@ -218,7 +218,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type AssertCallerIdentityIsModuleIdentity = {};
/**
@@ -277,7 +277,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type Baz = {
field: string,
@@ -340,7 +340,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type ClientConnected = {};
/**
@@ -399,7 +399,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type DeletePlayer = {
id: bigint,
@@ -461,7 +461,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type DeletePlayersByName = {
name: string,
@@ -523,7 +523,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
import { Baz } from "./baz_type";
// Mark import as potentially unused
declare type __keep_Baz = Baz;
@@ -599,7 +599,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
import { Baz as BazType } from "./baz_type";
// Mark import as potentially unused
declare type __keep_BazType = BazType;
@@ -638,7 +638,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
import { HasSpecialStuff } from "./has_special_stuff_type";
import { type EventContext, type Reducer, RemoteReducers, RemoteTables } from ".";
declare type __keep = [EventContext, Reducer, RemoteReducers, RemoteTables];
@@ -713,7 +713,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type HasSpecialStuff = {
identity: __Identity,
@@ -780,7 +780,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
// Import and reexport all reducer arg types
import { Add } from "./add_reducer.ts";
@@ -1433,7 +1433,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type ListOverAge = {
age: number,
@@ -1495,7 +1495,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type LogModuleIdentity = {};
/**
@@ -1554,7 +1554,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
import { Player } from "./player_type";
import { type EventContext, type Reducer, RemoteReducers, RemoteTables } from ".";
declare type __keep = [EventContext, Reducer, RemoteReducers, RemoteTables];
@@ -1703,7 +1703,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
import * as NamespaceTestCVariants from './namespace_test_c_variants'
// The tagged union or sum type for the algebraic type `NamespaceTestC`.
@@ -1772,7 +1772,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type Foo = { tag: "Foo" };
export type Bar = { tag: "Bar" };
@@ -1806,7 +1806,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
import * as NamespaceTestFVariants from './namespace_test_f_variants'
// The tagged union or sum type for the algebraic type `NamespaceTestF`.
@@ -1878,7 +1878,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type Foo = { tag: "Foo" };
export type Bar = { tag: "Bar" };
@@ -1913,7 +1913,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
import { Person } from "./person_type";
import { type EventContext, type Reducer, RemoteReducers, RemoteTables } from ".";
declare type __keep = [EventContext, Reducer, RemoteReducers, RemoteTables];
@@ -2018,7 +2018,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type Person = {
id: number,
@@ -2085,7 +2085,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
import { PkMultiIdentity } from "./pk_multi_identity_type";
import { type EventContext, type Reducer, RemoteReducers, RemoteTables } from ".";
declare type __keep = [EventContext, Reducer, RemoteReducers, RemoteTables];
@@ -2212,7 +2212,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type PkMultiIdentity = {
id: number,
@@ -2277,7 +2277,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
import { Player } from "./player_type";
import { type EventContext, type Reducer, RemoteReducers, RemoteTables } from ".";
declare type __keep = [EventContext, Reducer, RemoteReducers, RemoteTables];
@@ -2426,7 +2426,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type Player = {
identity: __Identity,
@@ -2493,7 +2493,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type Point = {
x: bigint,
@@ -2558,7 +2558,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
import { Point } from "./point_type";
import { type EventContext, type Reducer, RemoteReducers, RemoteTables } from ".";
declare type __keep = [EventContext, Reducer, RemoteReducers, RemoteTables];
@@ -2633,7 +2633,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
import { PrivateTable } from "./private_table_type";
import { type EventContext, type Reducer, RemoteReducers, RemoteTables } from ".";
declare type __keep = [EventContext, Reducer, RemoteReducers, RemoteTables];
@@ -2708,7 +2708,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type PrivateTable = {
name: string,
@@ -2771,7 +2771,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type QueryPrivate = {};
/**
@@ -2830,7 +2830,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
import { RepeatingTestArg } from "./repeating_test_arg_type";
import { type EventContext, type Reducer, RemoteReducers, RemoteTables } from ".";
declare type __keep = [EventContext, Reducer, RemoteReducers, RemoteTables];
@@ -2935,7 +2935,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type RepeatingTestArg = {
scheduledId: bigint,
@@ -3002,7 +3002,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
import { RepeatingTestArg } from "./repeating_test_arg_type";
// Mark import as potentially unused
@@ -3068,7 +3068,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type SayHello = {};
/**
@@ -3127,7 +3127,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
import { TestA } from "./test_a_type";
import { type EventContext, type Reducer, RemoteReducers, RemoteTables } from ".";
declare type __keep = [EventContext, Reducer, RemoteReducers, RemoteTables];
@@ -3202,7 +3202,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type TestA = {
x: number,
@@ -3269,7 +3269,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type TestB = {
foo: string,
@@ -3332,7 +3332,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type TestBtreeIndexArgs = {};
/**
@@ -3391,7 +3391,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
import { TestD } from "./test_d_type";
import { NamespaceTestC } from "./namespace_test_c_type";
// Mark import as potentially unused
@@ -3470,7 +3470,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
import { NamespaceTestC } from "./namespace_test_c_type";
// Mark import as potentially unused
declare type __keep_NamespaceTestC = NamespaceTestC;
@@ -3537,7 +3537,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
import { TestE } from "./test_e_type";
import { type EventContext, type Reducer, RemoteReducers, RemoteTables } from ".";
declare type __keep = [EventContext, Reducer, RemoteReducers, RemoteTables];
@@ -3642,7 +3642,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
export type TestE = {
id: bigint,
@@ -3707,7 +3707,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
import { TestFoobar } from "./test_foobar_type";
import { Foobar } from "./foobar_type";
// Mark import as potentially unused
@@ -3786,7 +3786,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
import { Foobar } from "./foobar_type";
// Mark import as potentially unused
declare type __keep_Foobar = Foobar;
@@ -3853,7 +3853,7 @@ import {
type EventContextInterface as __EventContextInterface,
type ReducerEventContextInterface as __ReducerEventContextInterface,
type SubscriptionEventContextInterface as __SubscriptionEventContextInterface,
} from "@clockworklabs/spacetimedb-sdk";
} from "spacetimedb";
import { TestA } from "./test_a_type";
// Mark import as potentially unused
+4 -2
View File
@@ -34,9 +34,11 @@ Then add the SpacetimeDB SDK to your dependencies:
```bash
cd client
npm install @clockworklabs/spacetimedb-sdk
npm install spacetimedb
```
> WARNING! The `@clockworklabs/spacetimedb-sdk` package has been deprecated in favor of the `spacetimedb` package as of SpacetimeDB version 1.4.0. If you are using the old SDK package, you will need to switch to `spacetimedb`. You will also need a SpacetimeDB CLI version of 1.4.0+ to generate bindings for the new `spacetimedb` package.
You should have this folder layout starting from the root of your project:
```bash
@@ -81,7 +83,7 @@ You may also need to import some definitions from the SDK library:
```typescript
import {
Identity, ConnectionId, Event, ReducerEvent
} from '@clockworklabs/spacetimedb-sdk';
} from 'spacetimedb';
```
## Type `DbConnection`
+7 -5
View File
@@ -28,11 +28,13 @@ pnpm install
We also need to install the `spacetime-client-sdk` package:
```bash
pnpm install @clockworklabs/spacetimedb-sdk
pnpm install spacetimedb
```
> If you are using another package manager like `yarn` or `npm`, the same steps should work with the appropriate commands for those tools.
> WARNING! The `@clockworklabs/spacetimedb-sdk` package has been deprecated in favor of the `spacetimedb` package as of SpacetimeDB version 1.4.0. If you are using the old SDK package, you will need to switch to `spacetimedb`. You will also need a SpacetimeDB CLI version of 1.4.0+ to generate bindings for the new `spacetimedb` package.
You can now `pnpm run dev` to see the Vite template app running at `http://localhost:5173`.
## Basic layout
@@ -54,8 +56,8 @@ import {
useTable,
where,
eq,
} from '@clockworklabs/spacetimedb-sdk/react';
import { Identity, Timestamp } from '@clockworklabs/spacetimedb-sdk';
} from 'spacetimedb/react';
import { Identity, Timestamp } from 'spacetimedb';
import './App.css';
export type PrettyMessage = {
@@ -484,8 +486,8 @@ import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import './index.css';
import App from './App.tsx';
import { Identity } from '@clockworklabs/spacetimedb-sdk';
import { SpacetimeDBProvider } from '@clockworklabs/spacetimedb-sdk/react';
import { Identity } from 'spacetimedb';
import { SpacetimeDBProvider } from 'spacetimedb/react';
import { DbConnection, ErrorContext } from './module_bindings/index.ts';
```
+7 -4
View File
@@ -2278,10 +2278,13 @@ Install the SDK package into your project:
```bash
# Using npm
npm install @clockworklabs/spacetimedb-sdk
npm install spacetimedb
# Or using pnpm
pnpm add spacetimedb
# Or using yarn
yarn add @clockworklabs/spacetimedb-sdk
yarn add spacetimedb
```
#### 2. Generate Module Bindings
@@ -2299,7 +2302,7 @@ Import the necessary generated types and SDK components:
```typescript
// Import SDK core types
import { Identity, Status } from "@clockworklabs/spacetimedb-sdk";
import { Identity, Status } from "spacetimedb";
// Import generated connection class, event contexts, and table types
import { DbConnection, EventContext, ReducerEventContext, Message, User } from "./module_bindings";
// Reducer functions are accessed via conn.reducers
@@ -2311,7 +2314,7 @@ Use the generated `DbConnection` class and its builder pattern to establish a co
```typescript
import { DbConnection, EventContext, ReducerEventContext, Message, User } from './module_bindings';
import { Identity, Status } from '@clockworklabs/spacetimedb-sdk';
import { Identity, Status } from 'spacetimedb';
const HOST = "ws://localhost:3000";
const DB_NAME = "quickstart-chat";
+1 -2
View File
@@ -38,9 +38,8 @@ export default tseslint.config(
'./tsconfig.json',
'./crates/bindings-typescript/tsconfig.json',
'./crates/bindings-typescript/test-app/tsconfig.json',
'./crates/bindings-typescript/examples/quickstart-chat/tsconfig.json',
'./docs/tsconfig.json',
'./sdks/typescript/tsconfig.json',
'./sdks/typescript/examples/quickstart-chat/tsconfig.json',
],
projectService: true,
tsconfigRootDir: __dirname,
+5 -5
View File
@@ -4,11 +4,11 @@
"engines": { "node": ">=18.0.0", "pnpm": ">=9.0.0" },
"type": "module",
"scripts": {
"format": "pnpm --filter ./crates/bindings-typescript run format && pnpm --filter ./docs run format && pnpm --filter ./sdks/typescript run format",
"lint": "pnpm --filter ./crates/bindings-typescript run lint && pnpm --filter ./docs run lint && pnpm --filter ./sdks/typescript run lint",
"build": "pnpm --filter ./crates/bindings-typescript run build && pnpm --filter ./docs run build && pnpm --filter ./sdks/typescript run build",
"test": "pnpm --filter ./crates/bindings-typescript run test && pnpm --filter ./docs run test && pnpm --filter ./sdks/typescript run test",
"generate": "pnpm --filter ./crates/bindings-typescript run generate && pnpm --filter ./docs run generate && pnpm --filter ./sdks/typescript run generate",
"format": "pnpm --filter ./crates/bindings-typescript run format && pnpm --filter ./docs run format && pnpm --filter ./crates/bindings-typescript/examples/quickstart-chat run format && pnpm --filter ./crates/bindings-typescript/test-app run format",
"lint": "pnpm --filter ./crates/bindings-typescript run lint && pnpm --filter ./docs run lint && pnpm --filter ./crates/bindings-typescript/examples/quickstart-chat run lint && pnpm --filter ./crates/bindings-typescript/test-app run lint",
"build": "pnpm --filter ./crates/bindings-typescript run build && pnpm --filter ./docs run build && pnpm --filter ./crates/bindings-typescript/examples/quickstart-chat run build && pnpm --filter ./crates/bindings-typescript/test-app run build",
"test": "pnpm --filter ./crates/bindings-typescript run test && pnpm --filter ./docs run test && && pnpm --filter ./crates/bindings-typescript/examples/quickstart-chat run test && pnpm --filter ./crates/bindings-typescript/test-app run test",
"generate": "pnpm --filter ./crates/bindings-typescript run generate && pnpm --filter ./docs run generate && pnpm --filter ./crates/bindings-typescript/examples/quickstart-chat run generate && pnpm --filter ./crates/bindings-typescript/test-app run generate",
"clean": "pnpm -r exec rimraf dist .tsbuildinfo coverage"
},
"devDependencies": {
+73 -707
View File
File diff suppressed because it is too large Load Diff
+1 -2
View File
@@ -1,6 +1,5 @@
packages:
- 'crates/bindings-typescript'
- 'crates/bindings-typescript/test-app'
- 'sdks/typescript'
- 'sdks/typescript/examples/quickstart-chat'
- 'crates/bindings-typescript/examples/quickstart-chat'
- 'docs'
+1
View File
@@ -0,0 +1 @@
../crates/bindings-typescript
-8
View File
@@ -1,8 +0,0 @@
# 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)
-14
View File
@@ -1,14 +0,0 @@
{
"$schema": "https://unpkg.com/@changesets/config@3.0.2/schema.json",
"changelog": [
"@changesets/changelog-github",
{ "repo": "clockworklabs/SpacetimeDB" }
],
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
-2
View File
@@ -1,2 +0,0 @@
src/client_api/*.ts linguist-generated=true
examples/quickstart/client/src/module_bindings/*.ts linguist-generated=true
-24
View File
@@ -1,24 +0,0 @@
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: Build
run: pnpm build
- name: Release
run: cd packages/sdk && pnpm dlx pkg-pr-new publish --compact --pnpm
-40
View File
@@ -1,40 +0,0 @@
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: pnpm/action-setup@v4
with:
version: 9.7
run_install: true
- uses: actions/setup-node@v4
with:
node-version: 18.x
cache: 'pnpm'
- run: pnpm build
- 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 }}
@@ -1,60 +0,0 @@
name: Repo migration notice
on:
issues:
types: [opened]
pull_request:
types: [opened]
jobs:
comment:
runs-on: ubuntu-latest
steps:
- name: Add comment
uses: actions/github-script@v7
env:
migrated_repo: https://github.com/ClockworkLabs/SpacetimeDB
migrated_path: sdks/typescript
default_branch: main
with:
script: |
const isPR = context.eventName === 'pull_request';
const number = isPR ? context.payload.pull_request.number : context.payload.issue.number;
let message;
if (isPR) {
message = `
Thank you for submitting this!
We are in the process of migrating this repository (see [DEVELOP.md](../blob/${process.env.default_branch}/DEVELOP.md)).
To make sure we see your PR, please open it in the [SpacetimeDB](${process.env.migrated_repo}) repo, under [${process.env.migrated_path}](${process.env.migrated_repo}/tree/master/${process.env.migrated_path}).
Apologies for the inconvenience, and thank you again!
`;
} else {
message = `
Thank you for submitting this!
We are in the process of migrating this repository (see [DEVELOP.md](../blob/${process.env.default_branch}/DEVELOP.md)).
To make sure we actually see your issue, please open it here: [SpacetimeDB/issues/new](${process.env.migrated_repo}/issues/new).
Apologies for the inconvenience, and thank you again!
`;
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: number,
body: message
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: number,
state: 'closed'
});
-7
View File
@@ -1,7 +0,0 @@
{
"workbench.colorCustomizations": {
"[Material Theme Darker]": {},
"minimap.background": "#00000000",
"scrollbar.shadow": "#00000000"
}
}
-90
View File
@@ -1,90 +0,0 @@
# Changelog
## 1.2.0
### Patch Changes
- [#176](https://github.com/clockworklabs/spacetimedb-typescript-sdk/pull/176) [`941cf4e`](https://github.com/clockworklabs/spacetimedb-typescript-sdk/commit/941cf4eba6b7df934d74696b373b89cc62764673) Thanks [@BastianGanze](https://github.com/BastianGanze)! - Make ws connection fail when token is invalid
## 1.0.0-rc1.0
### Major Changes
- [#116](https://github.com/clockworklabs/spacetimedb-typescript-sdk/pull/116) [`9032269`](https://github.com/clockworklabs/spacetimedb-typescript-sdk/commit/9032269004d4dae587c39ccd85da0a32fb9a0114) Thanks [@PuruVJ](https://github.com/PuruVJ)! - Enter RC
- [#117](https://github.com/clockworklabs/spacetimedb-typescript-sdk/pull/117) [`5d7304b`](https://github.com/clockworklabs/spacetimedb-typescript-sdk/commit/5d7304bd3e05dd7a032cfb7069aab97b881f0179) Thanks [@PuruVJ](https://github.com/PuruVJ)! - feat: Switch to GZIP compression by default
### Minor Changes
- [#110](https://github.com/clockworklabs/spacetimedb-typescript-sdk/pull/110) [`a501f5c`](https://github.com/clockworklabs/spacetimedb-typescript-sdk/commit/a501f5ccf9a0a926eb4f345ddeb01ffcb872d67e) Thanks [@Centril](https://github.com/Centril)! - Support light tx updates via builder.with*light_mode(*) and the call flag NoSuccessNotify
- [#119](https://github.com/clockworklabs/spacetimedb-typescript-sdk/pull/119) [`6547882`](https://github.com/clockworklabs/spacetimedb-typescript-sdk/commit/6547882bb28ed9a1ca436335745e9997328026ff) Thanks [@kazimuth](https://github.com/kazimuth)! - Update Identity and Address to use bigints rather than byte arrays (see https://github.com/clockworklabs/SpacetimeDB/pull/1616)
### Patch Changes
- [#109](https://github.com/clockworklabs/spacetimedb-typescript-sdk/pull/109) [`cf7b7d8`](https://github.com/clockworklabs/spacetimedb-typescript-sdk/commit/cf7b7d89a1547fb3863f6641f5b2eb40a27c05d8) Thanks [@PuruVJ](https://github.com/PuruVJ)! - fix: websocket message handling, Buffer, onConnect
## 0.12.1
### Patch Changes
- [#107](https://github.com/clockworklabs/spacetimedb-typescript-sdk/pull/107) [`2f6c82c`](https://github.com/clockworklabs/spacetimedb-typescript-sdk/commit/2f6c82c724b9f9407c7bedee13252ca8ffab8f7d) Thanks [@PuruVJ](https://github.com/PuruVJ)! - fix: websocket message handling, Buffer, onConnect
- [#108](https://github.com/clockworklabs/spacetimedb-typescript-sdk/pull/108) [`b9db9b6`](https://github.com/clockworklabs/spacetimedb-typescript-sdk/commit/b9db9b6e46d8c98b29327d97c12c07b7a2fc96bf) Thanks [@PuruVJ](https://github.com/PuruVJ)! - docs: Public facing docs for 0.12
- [#105](https://github.com/clockworklabs/spacetimedb-typescript-sdk/pull/105) [`79c278b`](https://github.com/clockworklabs/spacetimedb-typescript-sdk/commit/79c278be71b2dfd82106ada983fd81d395b1d912) Thanks [@PuruVJ](https://github.com/PuruVJ)! - fix: temporary token path invocation
## 0.12.0
### Minor Changes
- [#92](https://github.com/clockworklabs/spacetimedb-typescript-sdk/pull/92) [`ab1f463`](https://github.com/clockworklabs/spacetimedb-typescript-sdk/commit/ab1f463d7da6e530a6cd47e2433141bfd16addd1) Thanks [@PuruVJ](https://github.com/PuruVJ)! - breaking: Flatten AlgebraicType & Simplify some codegen
- [#102](https://github.com/clockworklabs/spacetimedb-typescript-sdk/pull/102) [`b8c944c`](https://github.com/clockworklabs/spacetimedb-typescript-sdk/commit/b8c944cd23d3b53c72131803a775127bf0a95213) Thanks [@cloutiertyler](https://github.com/cloutiertyler)! - internal: Remove global instance, allow multiple connections
### Patch Changes
- [#91](https://github.com/clockworklabs/spacetimedb-typescript-sdk/pull/91) [`5adb557`](https://github.com/clockworklabs/spacetimedb-typescript-sdk/commit/5adb55776c81d0760cf0268df0fa5dee600f0ef8) Thanks [@PuruVJ](https://github.com/PuruVJ)! - types: Allow autocomplete in .on and .off types
- [#96](https://github.com/clockworklabs/spacetimedb-typescript-sdk/pull/96) [`17227c0`](https://github.com/clockworklabs/spacetimedb-typescript-sdk/commit/17227c0f65def3a9d5e767756ccf46777210041a) Thanks [@PuruVJ](https://github.com/PuruVJ)! - (fix) Synchronous WS Processing
## [0.8.0](https://github.com/clockworklabs/spacetimedb-typescript-sdk/compare/0.7.2...0.8.0) (2023-12-11)
### Bug Fixes
- Properly use BigInt for any numbers bigger than 32 bits
- Fix generating primary key names to be camel case
### Features
- Added ability to start multiple SpacetimeDB clients. New clients will have a separate ClientDB
- Changed the return type of functions returning table records - now they are arras instead of iterators
- Reducer callbacks have args passed in separately, which makes it easier to know what types they are
For example a reducer taking a single string argument will have a callback signature like `(reducerEvent: ReducerEvent, name: string)`
instead of `(reducerEvent: ReducerEvent, args: any[])`
- We now require explicitly registering any tables or reducers with `SpacetimeDBClient.registerReducers()` and `SpacetimeDBClient.registerTables()`.
This also allows to register child classes, which in turn allows to use customized table classes. We will add more info
on how to do it in the future. This makes it also harder to run into weird issues. If you only import a reducer, but not use
it to set any callbacks, Node.js will filter out the import. If you then subscribe to a table SpacetimeDBClient will be unable
to find the reducer. To ensure this is not happening people were adding a `console.log` statement listing and used classes to
stop Node.js from filtering out any imports, like `console.log(SayHelloReducer)`. Now with the reducer call it's more explicit
- In this release we have also moved some methods from generated types into the SDK, which should result in a smaller footprint from
generated classes
- Generated sum types are now easier to use. For sum types without any values you can use their type name as value, for example given an
enum in Rust:
```rust
enum UserRole {
Admin,
Moderator,
User,
Other(String)
}
```
you can now use types itself as values. For example given a reducer for setting a role you could now do the following in TypeScript:
```typescript
SetRoleReducer.call(UserRole.Admin);
SetRoleReducer.call(UserRole.Other('another role'));
```
-47
View File
@@ -1,47 +0,0 @@
# Migration note
We are in the process of moving from the `spacetimedb-typescript-sdk` repo to the `sdks/typescript` subdirectory of [SpacetimeDB](https://github.com/clockworklabs/SpacetimeDB). **Any new changes should be made there**. The `spacetimedb-typescript-sdk` repo will only be updated on release. Apologies in advance for any sharp edges while the migration is in progress.
# Notes for maintainers
The directory `packages/sdk/src/client_api` is generated from [the SpacetimeDB client-api-messages](https://github.com/clockworklabs/SpacetimeDB/tree/master/crates/client-api-messages).
This is not automated.
Whenever the `client-api-messages` crate changes, you'll have to manually re-generate the definitions.
See that crate's DEVELOP.md for how to do this.
The generated files must be manually modified to fix their imports from the rest of the SDK.
Within each generated file:
- Change the import from `"@clockworklabs/spacetimedb-sdk"` to `"../index"`.
On a mac, you can do that by running this in the directory: `find . -type f -exec sed -i '' 's/"@clockworklabs\/spacetimedb-sdk"/"..\/index"/g' {} \;`.
## Releases and publishing
Every Pull Request with a public-facing change (Bug fix, perf, feature etc) must be accompanied by a changeset. Any person working on a patch or feature needs to run `pnpm -w changeset` command, which will prompt them to select packages changed. Choose `@clockworklabs/spacetimedb-sdk`
![image](https://github.com/user-attachments/assets/3a69ff1f-c92b-459a-8dcc-d8fea53f77b4)
Next it will ask whether you'd like to add a Major tag to it. Hit enter to go to minor tag. If its a minor change(In our case, minor is major until v1 comes out, as in every minor can have breaking changes). If its a patch change(Or minor for prerelease time), then again hit enter
After selecting the correct tag, it will ask you for a message
![image](https://github.com/user-attachments/assets/d05a338b-965d-4669-8155-542d0225b257)
![image](https://github.com/user-attachments/assets/7abc830e-4590-42e7-bce8-86155d86c672)
![image](https://github.com/user-attachments/assets/8f3b16bd-b01d-4117-8d02-3887f1d308dd)
Once that is done, hit enter. It will generate a `.md` file which you can then push to github. This all has to be done in the PR with the feature/fix in it.
We can merge it instantly to do a release, or we can merge PRs with their own Changesets. E.g. Any new feature or patch we work on for 1.0 now, should have a Changeset in it. All of these will accumulate in the "Version Packages" PR. Once all these are satisfactorily done, we merge this PR, which will
- Release the package on npm
- Release on Github tags
- Update CHANGELOG.md
**NOTE: It is very important that no one manually runs `npm publish`. We have provenance enabled on this package, means each version will be signed by github and traceable to the very commit associated to it**
Publishing manually will breach the provenance contract, and alert security servcies like Snyk into investigating the package or issuing a warning. npm install of our package will also warn them of potential compromise to the package
![image](https://github.com/user-attachments/assets/b56282b7-9055-48a0-8a49-3df9d75d481f)
![image](https://github.com/user-attachments/assets/99d023cf-31cc-48a0-93ed-a88c326425c5)
-1
View File
@@ -1 +0,0 @@
../../../../licenses/apache2.txt
-73
View File
@@ -1,73 +0,0 @@
## SpacetimeDB SDK
### 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 vite/parcel/rsbuild, in server-side applications like NodeJS, Deno, Bun and in Cloudflare Workers.
> NOTE: For usage in NodeJS 18-21, you need to install the `undici` package as a peer dependency: `npm install @clockworklabs/spacetimedb-sdk undici`. Node 22 and later are supported out of the box.
### Usage
In order to connect to a database you have to generate module bindings for your database.
```ts
import { DbConnection } from './module_bindings';
const connection = DbConnection.builder()
.withUri('ws://localhost:3000')
.withModuleName('MODULE_NAME')
.onDisconnect(() => {
console.log('disconnected');
})
.onConnectError(() => {
console.log('client_error');
})
.onConnect((connection, identity, _token) => {
console.log(
'Connected to SpacetimeDB with identity:',
identity.toHexString()
);
connection.subscriptionBuilder().subscribe('SELECT * FROM player');
})
.withToken('TOKEN')
.build();
```
If for some reason you need to disconnect the client:
```ts
connection.disconnect();
```
Typically, you will use the SDK with types generated from a backend DB service. For example, given a table named `Player` you can subscribe to player updates like this:
```ts
connection.db.player.onInsert((ctx, player) => {
console.log(player);
});
```
Given a reducer called `CreatePlayer` you can call it using a call method:
```ts
connection.reducers.createPlayer();
```
### Developer notes
To run the tests, do:
```sh
pnpm build && pnpm test
```
@@ -1 +0,0 @@
/// <reference types="vite/client" />
-93
View File
@@ -1,93 +0,0 @@
{
"name": "@clockworklabs/spacetimedb-sdk",
"version": "1.3.1",
"description": "SDK for SpacetimeDB",
"author": {
"name": "Clockwork Labs",
"email": "no-reply@clockworklabs.io"
},
"keywords": [
"spacetime",
"spacetimedb",
"database",
"react",
"state",
"realtime",
"websocket",
"serverless"
],
"types": "./src/index.ts",
"main": "./dist/index.js",
"module": "./dist/index.js",
"browser": "./dist/browser/index.js",
"type": "module",
"files": [
"dist"
],
"exports": {
".": {
"types": "./src/index.ts",
"browser": "./dist/browser/index.js",
"import": "./dist/index.js",
"default": "./dist/index.js"
},
"./react": {
"types": "./src/react/index.ts",
"browser": "./dist/browser/react/index.js",
"import": "./dist/react/index.js",
"default": "./dist/react/index.js"
},
"./package.json": "./package.json"
},
"sideEffects": false,
"scripts": {
"changeset": "changeset",
"ci:release": "changeset publish",
"ci:version": "changeset version",
"format": "prettier . --write --ignore-path ../../.prettierignore",
"build": "tsup",
"lint": "eslint . && prettier . --check --ignore-path ../../.prettierignore",
"test": "pnpm build && vitest run",
"generate": "cargo build -p spacetimedb-standalone && cargo run -p spacetimedb-client-api-messages --example get_ws_schema > ws_schema.json && cargo run -p spacetimedb-cli generate --lang typescript --out-dir src/client_api --module-def ws_schema.json && rm ws_schema.json && find src/client_api -type f -exec perl -pi -e 's#\\@clockworklabs/spacetimedb-sdk#../index#g' {} + && prettier --write src/client_api",
"size": "brotli-size dist/min/index.js"
},
"repository": {
"type": "git",
"url": "https://github.com/clockworklabs/spacetimedb-typescript-sdk"
},
"publishConfig": {
"provenance": true
},
"engines": {
"node": ">=18.0.0",
"pnpm": ">=9.0.0"
},
"peerDependencies": {
"react": "^18.0.0 || ^19.0.0-0 || ^19.0.0",
"undici": "^6.19.2"
},
"peerDependenciesMeta": {
"react": {
"optional": true
},
"undici": {
"optional": true
}
},
"devDependencies": {
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.7",
"brotli-size-cli": "^1.0.0",
"terser": "^5.31.2",
"tsx": "^4.17.0",
"typescript": "^5.5.3",
"@types/react": "^19.1.13",
"prettier": "^3.3.3",
"tsup": "^8.1.0",
"vite": "^7.1.5",
"vitest": "^3.2.4"
},
"dependencies": {
"spacetimedb": "workspace:^"
}
}
-11
View File
@@ -1,11 +0,0 @@
export * from 'spacetimedb/sdk';
export type * from 'spacetimedb/sdk';
export {
AlgebraicType,
ConnectionId,
Identity,
TimeDuration,
Timestamp,
deepEqual,
type AlgebraicTypeVariants,
} from 'spacetimedb';
-2
View File
@@ -1,2 +0,0 @@
export * from 'spacetimedb/react';
export type * from 'spacetimedb/react';
-18
View File
@@ -1,18 +0,0 @@
import { describe, it } from 'vitest';
import type { IdentityTokenMessage } from 'spacetimedb/sdk';
import { ConnectionId, Identity } from 'spacetimedb';
describe('spacetimedb', () => {
it('imports something from the spacetimedb sdk', () => {
const _msg: IdentityTokenMessage = {
tag: 'IdentityToken',
identity: Identity.fromString(
'0xc200000000000000000000000000000000000000000000000000000000000000'
),
token: 'some-token',
connectionId: ConnectionId.fromString(
'0x00000000000000000000000000000000'
),
};
});
});
-28
View File
@@ -1,28 +0,0 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"declaration": true,
"emitDeclarationOnly": false,
"noEmit": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"verbatimModuleSyntax": true,
"allowImportingTsExtensions": true,
"strict": true,
"noImplicitAny": false,
"moduleResolution": "Bundler",
"allowSyntheticDefaultImports": true,
"isolatedDeclarations": true,
"isolatedModules": true,
"jsx": "react-jsx",
"baseUrl": ".",
"paths": {
"spacetimedb": ["../../crates/bindings-typescript/src/index.ts"]
}
},
"include": ["src/**/*", "tests/**/*", "tsup.config.ts", "vitest.config.ts"],
"exclude": ["node_modules", "**/__tests__/*", "dist/**/*"]
}
-104
View File
@@ -1,104 +0,0 @@
import { defineConfig, type Options } from 'tsup';
function commonEsbuildTweaks() {
return (options: any) => {
// Prefer "exports"."source" when deps provide it; harmless otherwise.
options.conditions = ['source', 'import', 'default'];
options.mainFields = ['browser', 'module', 'main'];
};
}
export default defineConfig([
// ESM wrapper -> dist/index.js
{
entry: { index: 'src/index.ts' },
format: ['esm'],
target: 'es2022',
outDir: 'dist',
dts: false, // types come from ./src in package.json
sourcemap: true,
clean: true,
platform: 'neutral',
noExternal: ['spacetimedb'],
treeshake: 'smallest',
external: ['undici'],
esbuildOptions: commonEsbuildTweaks(),
},
// Browser-flavored wrapper -> dist/browser/index.js
{
entry: { index: 'src/index.ts' },
format: ['esm'],
target: 'es2022',
outDir: 'dist/browser',
dts: false,
sourcemap: true,
clean: true,
platform: 'browser',
noExternal: ['spacetimedb'],
treeshake: 'smallest',
external: ['undici'],
esbuildOptions: commonEsbuildTweaks(),
},
// The below minified builds are not referenced in package.json and are
// just included in the build for measuring the size impact of minification.
// It is expected that consumers of the library will run their own
// minification as part of their app bundling process.
// Minified browser build -> dist/min/index.js
{
entry: { index: 'src/index.ts' },
format: ['esm'],
target: 'es2022',
outDir: 'dist/min',
dts: false,
sourcemap: true,
minify: 'terser',
platform: 'browser',
noExternal: ['spacetimedb'],
treeshake: 'smallest',
external: ['undici'],
esbuildOptions: commonEsbuildTweaks(),
},
// React subpath (SSR-friendly) -> dist/react/index.js
{
entry: { index: 'src/react/index.ts' },
format: ['esm'],
target: 'es2022',
outDir: 'dist/react',
dts: false, // wrapper doesn't own .d.ts; package.json points to src
sourcemap: true,
clean: true,
platform: 'neutral',
noExternal: ['spacetimedb'],
treeshake: 'smallest',
esbuildOptions: commonEsbuildTweaks(),
},
// React subpath (browser) -> dist/browser/react/index.js
{
entry: { index: 'src/react/index.ts' },
format: ['esm'],
target: 'es2022',
outDir: 'dist/browser/react',
dts: false,
sourcemap: true,
clean: true,
platform: 'browser',
noExternal: ['spacetimedb'],
treeshake: 'smallest',
esbuildOptions: commonEsbuildTweaks(),
},
]) satisfies
| Options
| Options[]
| ((
overrideOptions: Options
) => Options | Options[] | Promise<Options | Options[]>) as
| Options
| Options[]
| ((
overrideOptions: Options
) => Options | Options[] | Promise<Options | Options[]>);
-24
View File
@@ -1,24 +0,0 @@
import type { UserConfig } from 'vite';
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
environment: 'node',
include: ['tests/**/*.test.ts'],
deps: {
external: ['spacetimedb'],
},
},
resolve: {
// Prefer source in dev *if your SDK exposes "source" in exports*.
// Otherwise omit "source".
conditions: ['source', 'development', 'node', 'import', 'default'],
mainFields: ['module', 'main', 'browser'],
preserveSymlinks: false,
extensions: ['.ts', '.tsx', '.mjs', '.js', '.json'],
},
optimizeDeps: {
esbuildOptions: { conditions: ['source', 'import', 'module', 'default'] },
exclude: ['spacetimedb'],
},
}) satisfies UserConfig as UserConfig;
+1 -2
View File
@@ -3,8 +3,7 @@
"references": [
{ "path": "crates/bindings-typescript" },
{ "path": "crates/bindings-typescript/test-app" },
{ "path": "crates/bindings-typescript/examples/quickstart-chat" },
{ "path": "docs" },
{ "path": "sdks/typescript" },
{ "path": "sdks/typescript/examples/quickstart-chat" },
]
}