Skip to content

Commit a78b056

Browse files
Reorganize types generated for typescript clients (#4258)
NOTE: Cherry-picking #4127 from the `2.0-breaking-changes` branch. ## Original PR Description This changes generated types in ts client bindings. We currently generate a few different types of types: reducer args, procedure args, rows, and user defined types. To avoid potential conflicts between these types (for example, if a user defined a type called `FooRow`, and also had a tabled named `foo`, we would end up with two types named `FooRow`), this puts each set of types in a different file and namespace. We also stopped exporting the `xxxRow` types, because there is always another type generated for those. We now have a `types` directory, which has an `index.ts` with user defined types, along with `reducers.ts` and `procedures.ts` for the types generated for reducer/procedure parameters. ``` import type * as Types from './module_bindings/types'; var currentMessages: Types.Message[] = []; ``` or ``` import { type Message } from './module_bindings/types'; var currentMessages: Message[] = []; ``` This has a couple other changes: - For procedure and reducer types, this adds a suffix of `Args`, since we may want types for the return values in the future. - For all of the types, instead of exposing the schema object, we are now giving the typescript type (e.g. `export type Message = __Infer<typeof MessageRow>;`). I couldn't think of a reason for users to want the schema object, so this should save users from needing to do all of the `Infer` boilerplate. This is a breaking change for v2. 2. This only changes typescript, and it should generally make thing easier to use. --------- Co-authored-by: Jeffrey Dallatezza <jeffreydallatezza@gmail.com>
1 parent aca374a commit a78b056

62 files changed

Lines changed: 1007 additions & 371 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/bindings-typescript/src/sdk/client_api/index.ts

Lines changed: 9 additions & 77 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-typescript/src/sdk/client_api/procedures.ts

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-typescript/src/sdk/client_api/reducers.ts

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-typescript/src/sdk/client_api/rows.ts

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-typescript/src/sdk/client_api/types.ts

Lines changed: 77 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
2+
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
3+
4+
/* eslint-disable */
5+
/* tslint:disable */
6+
import { type Infer as __Infer } from '../../../lib/type_builders';
7+
8+
// Import all non-reducer types
9+
import BsatnRowList from '../bsatn_row_list_type';
10+
import CallProcedure from '../call_procedure_type';
11+
import CallReducer from '../call_reducer_type';
12+
import ClientMessage from '../client_message_type';
13+
import CompressableQueryUpdate from '../compressable_query_update_type';
14+
import DatabaseUpdate from '../database_update_type';
15+
import EnergyQuanta from '../energy_quanta_type';
16+
import IdentityToken from '../identity_token_type';
17+
import InitialSubscription from '../initial_subscription_type';
18+
import OneOffQuery from '../one_off_query_type';
19+
import OneOffQueryResponse from '../one_off_query_response_type';
20+
import OneOffTable from '../one_off_table_type';
21+
import ProcedureResult from '../procedure_result_type';
22+
import ProcedureStatus from '../procedure_status_type';
23+
import QueryId from '../query_id_type';
24+
import QueryUpdate from '../query_update_type';
25+
import ReducerCallInfo from '../reducer_call_info_type';
26+
import RowSizeHint from '../row_size_hint_type';
27+
import ServerMessage from '../server_message_type';
28+
import Subscribe from '../subscribe_type';
29+
import SubscribeApplied from '../subscribe_applied_type';
30+
import SubscribeMulti from '../subscribe_multi_type';
31+
import SubscribeMultiApplied from '../subscribe_multi_applied_type';
32+
import SubscribeRows from '../subscribe_rows_type';
33+
import SubscribeSingle from '../subscribe_single_type';
34+
import SubscriptionError from '../subscription_error_type';
35+
import TableUpdate from '../table_update_type';
36+
import TransactionUpdate from '../transaction_update_type';
37+
import TransactionUpdateLight from '../transaction_update_light_type';
38+
import Unsubscribe from '../unsubscribe_type';
39+
import UnsubscribeApplied from '../unsubscribe_applied_type';
40+
import UnsubscribeMulti from '../unsubscribe_multi_type';
41+
import UnsubscribeMultiApplied from '../unsubscribe_multi_applied_type';
42+
import UpdateStatus from '../update_status_type';
43+
44+
export type BsatnRowList = __Infer<typeof BsatnRowList>;
45+
export type CallProcedure = __Infer<typeof CallProcedure>;
46+
export type CallReducer = __Infer<typeof CallReducer>;
47+
export type ClientMessage = __Infer<typeof ClientMessage>;
48+
export type CompressableQueryUpdate = __Infer<typeof CompressableQueryUpdate>;
49+
export type DatabaseUpdate = __Infer<typeof DatabaseUpdate>;
50+
export type EnergyQuanta = __Infer<typeof EnergyQuanta>;
51+
export type IdentityToken = __Infer<typeof IdentityToken>;
52+
export type InitialSubscription = __Infer<typeof InitialSubscription>;
53+
export type OneOffQuery = __Infer<typeof OneOffQuery>;
54+
export type OneOffQueryResponse = __Infer<typeof OneOffQueryResponse>;
55+
export type OneOffTable = __Infer<typeof OneOffTable>;
56+
export type ProcedureResult = __Infer<typeof ProcedureResult>;
57+
export type ProcedureStatus = __Infer<typeof ProcedureStatus>;
58+
export type QueryId = __Infer<typeof QueryId>;
59+
export type QueryUpdate = __Infer<typeof QueryUpdate>;
60+
export type ReducerCallInfo = __Infer<typeof ReducerCallInfo>;
61+
export type RowSizeHint = __Infer<typeof RowSizeHint>;
62+
export type ServerMessage = __Infer<typeof ServerMessage>;
63+
export type Subscribe = __Infer<typeof Subscribe>;
64+
export type SubscribeApplied = __Infer<typeof SubscribeApplied>;
65+
export type SubscribeMulti = __Infer<typeof SubscribeMulti>;
66+
export type SubscribeMultiApplied = __Infer<typeof SubscribeMultiApplied>;
67+
export type SubscribeRows = __Infer<typeof SubscribeRows>;
68+
export type SubscribeSingle = __Infer<typeof SubscribeSingle>;
69+
export type SubscriptionError = __Infer<typeof SubscriptionError>;
70+
export type TableUpdate = __Infer<typeof TableUpdate>;
71+
export type TransactionUpdate = __Infer<typeof TransactionUpdate>;
72+
export type TransactionUpdateLight = __Infer<typeof TransactionUpdateLight>;
73+
export type Unsubscribe = __Infer<typeof Unsubscribe>;
74+
export type UnsubscribeApplied = __Infer<typeof UnsubscribeApplied>;
75+
export type UnsubscribeMulti = __Infer<typeof UnsubscribeMulti>;
76+
export type UnsubscribeMultiApplied = __Infer<typeof UnsubscribeMultiApplied>;
77+
export type UpdateStatus = __Infer<typeof UpdateStatus>;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
2+
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
3+
4+
/* eslint-disable */
5+
/* tslint:disable */
6+
import { type Infer as __Infer } from '../../../lib/type_builders';
7+
8+
// Import all procedure arg schemas
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
2+
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
3+
4+
/* eslint-disable */
5+
/* tslint:disable */
6+
import { type Infer as __Infer } from '../../../lib/type_builders';
7+
8+
// Import all reducer arg schemas

crates/bindings-typescript/test-app/src/module_bindings/index.ts

Lines changed: 7 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-typescript/test-app/src/module_bindings/procedures.ts

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)