Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions crates/bindings-typescript/tests/client_query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('ClientQuery.toSql', () => {
it('renders semijoin queries without additional filters', () => {
const sql = toSql(
tables.player
.rightSemijoin(tables.unindexed_player, (player, other) =>
.rightSemijoin(tables.unindexedPlayer, (player, other) =>
other.id.eq(player.id)
)
.build()
Expand All @@ -104,7 +104,7 @@ describe('ClientQuery.toSql', () => {
const sql = toSql(
tables.player
.where(row => row.id.eq(42))
.rightSemijoin(tables.unindexed_player, (player, other) =>
.rightSemijoin(tables.unindexedPlayer, (player, other) =>
other.id.eq(player.id)
)
.build()
Expand All @@ -119,7 +119,7 @@ describe('ClientQuery.toSql', () => {
const sql = toSql(
tables.player
.where(row => row.name.eq("O'Brian"))
.rightSemijoin(tables.unindexed_player, (player, other) =>
.rightSemijoin(tables.unindexedPlayer, (player, other) =>
other.id.eq(player.id)
)
.build()
Expand All @@ -134,7 +134,7 @@ describe('ClientQuery.toSql', () => {
const sql = toSql(
tables.player
.where(row => and(row.name.eq('Alice'), row.id.eq(30)))
.rightSemijoin(tables.unindexed_player, (player, other) =>
.rightSemijoin(tables.unindexedPlayer, (player, other) =>
other.id.eq(player.id)
)
.build()
Expand Down Expand Up @@ -196,7 +196,7 @@ describe('ClientQuery.toSql', () => {
it('basic semijoin', () => {
const sql = toSql(
tables.player
.rightSemijoin(tables.unindexed_player, (player, other) =>
.rightSemijoin(tables.unindexedPlayer, (player, other) =>
other.id.eq(player.id)
)
.build()
Expand All @@ -209,7 +209,7 @@ describe('ClientQuery.toSql', () => {
it('basic left semijoin', () => {
const sql = toSql(
tables.player
.leftSemijoin(tables.unindexed_player, (player, other) =>
.leftSemijoin(tables.unindexedPlayer, (player, other) =>
other.id.eq(player.id)
)
.build()
Expand Down Expand Up @@ -252,7 +252,7 @@ describe('ClientQuery.toSql', () => {
const sql = toSql(
tables.player
.where(row => row.id.eq(42))
.rightSemijoin(tables.unindexed_player, (player, other) =>
.rightSemijoin(tables.unindexedPlayer, (player, other) =>
other.id.eq(player.id)
)
.where(row => row.name.eq('Gadget'))
Expand Down Expand Up @@ -286,15 +286,15 @@ describe('useTable type compatibility', () => {

it('rightSemijoin result is assignable to useTable query param', () => {
assertType<UseTableQuery>(
tables.player.rightSemijoin(tables.unindexed_player, (p, o) =>
tables.player.rightSemijoin(tables.unindexedPlayer, (p, o) =>
o.id.eq(p.id)
)
);
});

it('leftSemijoin result is assignable to useTable query param', () => {
assertType<UseTableQuery>(
tables.player.leftSemijoin(tables.unindexed_player, (p, o) =>
tables.player.leftSemijoin(tables.unindexedPlayer, (p, o) =>
o.id.eq(p.id)
)
);
Expand All @@ -303,7 +303,7 @@ describe('useTable type compatibility', () => {
it('semijoin with .where() is assignable to useTable query param', () => {
assertType<UseTableQuery>(
tables.player
.rightSemijoin(tables.unindexed_player, (p, o) => o.id.eq(p.id))
.rightSemijoin(tables.unindexedPlayer, (p, o) => o.id.eq(p.id))
.where(r => r.name.eq('test'))
);
});
Expand All @@ -320,7 +320,7 @@ describe('useTable type compatibility', () => {

it('semijoin result exposes toSql() returning string', () => {
const sql: string = tables.player
.rightSemijoin(tables.unindexed_player, (p, o) => o.id.eq(p.id))
.rightSemijoin(tables.unindexedPlayer, (p, o) => o.id.eq(p.id))
.toSql();
expect(typeof sql).toBe('string');
});
Expand Down
10 changes: 5 additions & 5 deletions crates/bindings-typescript/tests/db_connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -847,11 +847,11 @@ describe('DbConnection', () => {

// `onUpdate` is only available when the generated view row binding carries
// primary-key metadata.
client.db.my_user_procedural.onInsert((_ctx, row) => {
client.db.myUserProcedural.onInsert((_ctx, row) => {
expect(row).toEqual(initialRow);
initialInsertPromise.resolve();
});
client.db.my_user_procedural.onUpdate((_ctx, oldRow, newRow) => {
client.db.myUserProcedural.onUpdate((_ctx, oldRow, newRow) => {
updates.push({
oldRow,
newRow,
Expand All @@ -876,7 +876,7 @@ describe('DbConnection', () => {

await initialInsertPromise.promise;
expect(client.db.player.count()).toEqual(1n);
expect(client.db.my_user_procedural.count()).toEqual(1n);
expect(client.db.myUserProcedural.count()).toEqual(1n);

// A delete and insert with the same primary key in one transaction should
// be coalesced by the client cache into `onUpdate`, not separate delete and
Expand Down Expand Up @@ -909,8 +909,8 @@ describe('DbConnection', () => {
},
]);
expect(client.db.player.count()).toEqual(1n);
expect(client.db.my_user_procedural.count()).toEqual(1n);
expect([...client.db.my_user_procedural.iter()][0]).toEqual(updatedRow);
expect(client.db.myUserProcedural.count()).toEqual(1n);
expect([...client.db.myUserProcedural.iter()][0]).toEqual(updatedRow);
});

test('Filtering works', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { and } from ${JSON.stringify(imports.query)};
import { tables } from ${JSON.stringify(imports.moduleBindings)};

tables.player
.leftSemijoin(tables.unindexed_player, (l, r) => ${semijoinPredicateExpr})
.leftSemijoin(tables.unindexedPlayer, (l, r) => ${semijoinPredicateExpr})
.build();
`;

Expand Down
4 changes: 2 additions & 2 deletions crates/bindings-typescript/tests/table_cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ function runTest(

describe('TableCache', () => {
describe('Unindexed player table', () => {
const newTable = () => new TableCacheImpl(tables.unindexed_player.tableDef);
const newTable = () => new TableCacheImpl(tables.unindexedPlayer.tableDef);
const mkOperation = (
type: 'insert' | 'delete',
row: Infer<typeof UnindexedPlayer>
) => {
const rowId = AlgebraicType.intoMapKey(
{ tag: 'Product', value: tables.unindexed_player.rowType },
{ tag: 'Product', value: tables.unindexedPlayer.rowType },
row
);
return {
Expand Down
6 changes: 4 additions & 2 deletions crates/codegen/src/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ impl Lang for TypeScript {
out.indent(1);
for table in iter_tables(module, options.visibility) {
let type_ref = table.product_type_ref;
let table_accessor = table.accessor_name.deref().to_case(Case::Camel);
let table_name_pascalcase = table.accessor_name.deref().to_case(Case::Pascal);
writeln!(out, "{}: __table({{", table.accessor_name);
writeln!(out, "{table_accessor}: __table({{");
out.indent(1);
write_table_opts(
module,
Expand All @@ -215,8 +216,9 @@ impl Lang for TypeScript {
}
for view in iter_views(module) {
let type_ref = view.product_type_ref;
let view_accessor = view.accessor_name.deref().to_case(Case::Camel);
let view_name_pascalcase = view.accessor_name.deref().to_case(Case::Pascal);
writeln!(out, "{}: __table({{", view.accessor_name);
writeln!(out, "{view_accessor}: __table({{");
out.indent(1);
write_table_opts(module, out, type_ref, &view.name, iter::empty(), iter::empty(), false);
out.dedent(1);
Expand Down
15 changes: 15 additions & 0 deletions crates/codegen/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,18 @@ declare_tests! {
test_codegen_typescript => TypeScript,
test_codegen_rust => Rust,
}

#[test]
fn test_typescript_table_handles_are_camel_case() {
let module = compiled_module();
let index = generate(module, &TypeScript, &CodegenOptions::default())
.into_iter()
.find(|file| file.filename == "index.ts")
.expect("typescript codegen should emit index.ts")
.code;

assert!(index.contains("loggedOutPlayer: __table({"));
assert!(!index.contains("logged_out_player: __table({"));
assert!(index.contains("myPlayer: __table({"));
assert!(!index.contains("my_player: __table({"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ import TestFRow from "./test_f_table";

/** The schema information for all tables in this module. This is defined the same was as the tables would have been defined in the server. */
const tablesSchema = __schema({
logged_out_player: __table({
loggedOutPlayer: __table({
name: 'logged_out_player',
indexes: [
{ accessor: 'identity', name: 'logged_out_player_identity_idx_btree', algorithm: 'btree', columns: [
Expand Down Expand Up @@ -239,21 +239,21 @@ const tablesSchema = __schema({
{ name: 'player_player_id_key', constraint: 'unique', columns: ['playerId'] },
],
}, PlayerRow),
test_d: __table({
testD: __table({
name: 'test_d',
indexes: [
],
constraints: [
],
}, TestDRow),
test_f: __table({
testF: __table({
name: 'test_f',
indexes: [
],
constraints: [
],
}, TestFRow),
my_player: __table({
myPlayer: __table({
name: 'my_player',
indexes: [
],
Expand Down
2 changes: 1 addition & 1 deletion demo/Blackholio/client-ts/src/game/GameManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class GameManager {
connection.db.player.onDelete((_ctx, player) => {
this.players.delete(player.playerId);
});
connection.db.consume_entity_event.onInsert((_ctx, event) =>
connection.db.consumeEntityEvent.onInsert((_ctx, event) =>
this.consumeEntityEventOnInsert(event)
);
}
Expand Down
2 changes: 1 addition & 1 deletion demo/Blackholio/client-ts/src/module_bindings/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion templates/hangman-react-ts/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function App() {
const { identity, isActive: connected } = useSpacetimeDB();
const [rounds] = useTable(tables.currentRound);
const [players] = useTable(tables.player);
const [boards] = useTable(tables.my_progress);
const [boards] = useTable(tables.myProgress);
const [results] = useTable(tables.roundResult);
const setName = useReducer(reducers.setName);
const guessLetter = useReducer(reducers.guessLetter);
Expand Down
2 changes: 1 addition & 1 deletion templates/hangman-react-ts/src/module_bindings/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions templates/money-exchange-react-ts/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ function NameForm({

function App() {
const { identity, isActive: connected } = useSpacetimeDB();
const [accounts] = useTable(tables.my_account);
const [accounts] = useTable(tables.myAccount);
const [directory] = useTable(tables.directory);
const [changes] = useTable(tables.my_account_changes);
const [changes] = useTable(tables.myAccountChanges);
const setName = useReducer(reducers.setName);
const sendTransfer = useReducer(reducers.transfer);
const [editingName, setEditingName] = useState(false);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading