Skip to content

Commit fefceb9

Browse files
committed
fix(ts-sdk): replace URL by whatwg-url to support React Native
1 parent f2440d7 commit fefceb9

File tree

7 files changed

+51
-184
lines changed

7 files changed

+51
-184
lines changed

sdks/typescript/packages/sdk/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@
4343
},
4444
"devDependencies": {
4545
"@clockworklabs/test-app": "file:../test-app",
46+
"@types/whatwg-url": "^13.0.0",
4647
"tsup": "^8.1.0",
4748
"undici": "^6.19.2"
4849
},
4950
"dependencies": {
50-
"base64-js": "^1.5.1"
51+
"base64-js": "^1.5.1",
52+
"whatwg-url": "^14.2.0"
5153
}
5254
}

sdks/typescript/packages/sdk/src/db_connection_builder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Identity } from './identity';
44
import type RemoteModule from './spacetime_module';
55
import { ensureMinimumVersionOrThrow } from './version';
66
import { WebsocketDecompressAdapter } from './websocket_decompress_adapter';
7+
import { URL } from 'whatwg-url';
78

89
/**
910
* The database client connection to a SpacetimeDB server.
@@ -44,7 +45,7 @@ export class DbConnectionBuilder<
4445
*
4546
**/
4647
withUri(uri: string | URL): this {
47-
this.#uri = new URL(uri);
48+
this.#uri = new URL(uri.toString());
4849
return this;
4950
}
5051

sdks/typescript/packages/sdk/src/db_connection_impl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import {
6262
import { stdbLogger } from './logger.ts';
6363
import { type ReducerRuntimeTypeInfo } from './spacetime_module.ts';
6464
import { fromByteArray } from 'base64-js';
65+
import { URL } from 'whatwg-url';
6566

6667
export {
6768
AlgebraicType,

sdks/typescript/packages/sdk/src/websocket_decompress_adapter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { decompress } from './decompress';
2+
import { URL } from 'whatwg-url';
23

34
export class WebsocketDecompressAdapter {
45
onclose?: (...ev: any[]) => void;
@@ -98,7 +99,10 @@ export class WebsocketDecompressAdapter {
9899
const tokenUrl = new URL('v1/identity/websocket-token', url);
99100
tokenUrl.protocol = url.protocol === 'wss:' ? 'https:' : 'http:';
100101

101-
const response = await fetch(tokenUrl, { method: 'POST', headers });
102+
const response = await fetch(tokenUrl.toString(), {
103+
method: 'POST',
104+
headers,
105+
});
102106
if (response.ok) {
103107
const { token } = await response.json();
104108
temporaryAuthToken = token;

sdks/typescript/packages/test-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"dependencies": {
2020
"react": "^18.3.1",
2121
"react-dom": "^18.3.1",
22-
"@clockworklabs/spacetimedb-sdk": "workspace:*"
22+
"@clockworklabs/spacetimedb-sdk": "file:../sdk"
2323
},
2424
"devDependencies": {
2525
"@types/react": "^18.3.3",

sdks/typescript/packages/test-app/server/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

8+
[workspace]
9+
810
[lib]
911
crate-type = ["cdylib"]
1012

0 commit comments

Comments
 (0)