-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove row_pk from the client API (#34)
Re: clockworklabs/SpacetimeDB#840 This commit updates the TypeScript SDK to no longer use the `row_pk` field in the client API, as that field no longer exists. As in the other SDKs, we replace our use of the `row_pk` with the serialized representation of the row, as this saves our needing to have objects/dicts/hash-maps keyed on domain types. Unlike the other SDKs, we support either the binary (protobuf) or JSON APIs. When using the binary API, we convert the BSATN row to a string, and use that as the `rowPk`. When using the JSON API, we `JSON.stringify` the row itself, and use that as the `rowPk`. The latter is ugly and not performant, but we don't care because the JSON API is slow anyways. This commit also removes some uses of `any` from the deserialization code, because I wanted the compiler to double-check my work.
- Loading branch information
Showing
5 changed files
with
207 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Notes for maintainers | ||
|
||
The file `client_api.ts` is generated by [ts-proto](https://github.com/stephenh/ts-proto) | ||
from [the SpacetimeDB client-api-messages proto definition](https://github.com/clockworklabs/SpacetimeDB/blob/master/crates/client-api-messages/protobuf/client_api.proto). | ||
This is not automated. | ||
Whenever the `client_api.proto` changes, you'll have to manually re-run `protoc` to re-generate the definitions. | ||
|
||
```sh | ||
cd spacetimedb-typescript-sdk | ||
npm i # get the dev-dependencies | ||
cd ~/path/to/SpacetimeDB/crates/client-api-messages/protobuf | ||
protoc --plugin=/absolute/path/to/spacetimedb-typescript-sdk/node_modules/.bin/protoc-gen-ts_proto \ | ||
--ts_proto_out=/absolute/path/to/spacetimedb-typescript-sdk/src \ | ||
./client_api.proto | ||
``` | ||
|
||
Note that `protoc` cannot understand paths that start with `~`; | ||
you must write the absolute path starting from `/`. | ||
|
||
For reasons that escape me, `protoc-gen-ts` emits an incorrect import for `Long`. | ||
After generating, you may have to manually edit `client_api.ts` by replacing: | ||
|
||
```ts | ||
import Long = require("long"); | ||
``` | ||
|
||
with: | ||
|
||
```ts | ||
import Long from "long"; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
export interface Message { | ||
IdentityToken?: IdentityToken | undefined; | ||
SubscriptionUpdate?: SubscriptionUpdate | undefined; | ||
TransactionUpdate?: TransactionUpdate | undefined; | ||
} | ||
|
||
export interface IdentityToken { | ||
identity: string; | ||
token: string; | ||
address: string; | ||
} | ||
|
||
export interface SubscriptionUpdate { | ||
table_updates: TableUpdate[]; | ||
} | ||
|
||
export interface TableUpdate { | ||
table_id: number; | ||
table_name: string; | ||
table_row_operations: TableRowOperation[]; | ||
} | ||
|
||
export interface TableRowOperation { | ||
op: "insert" | "delete"; | ||
row: any[]; | ||
} | ||
|
||
export interface TransactionUpdate { | ||
event: Event; | ||
subscription_update: SubscriptionUpdate; | ||
} | ||
|
||
export interface Event { | ||
timestamp: number; | ||
status: "committed" | "failed" | "out_of_energy"; | ||
caller_identity: string; | ||
caller_address: string; | ||
function_call: FunctionCall; | ||
energy_quanta_used: number; | ||
message: string; | ||
} | ||
|
||
export interface FunctionCall { | ||
reducer: string; | ||
args: string; | ||
} |
Oops, something went wrong.