-
Notifications
You must be signed in to change notification settings - Fork 1k
Add TypeScript submodule support for SpacetimeDB modules #5486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // 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 codegen. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
| #include <string> | ||
| #include <vector> | ||
| #include <optional> | ||
| #include <memory> | ||
| #include "../autogen_base.h" | ||
| #include "spacetimedb/bsatn/bsatn.h" | ||
|
|
||
| namespace SpacetimeDB::Internal { | ||
| struct RawModuleDefV10; | ||
| } // namespace SpacetimeDB::Internal | ||
|
|
||
| namespace SpacetimeDB::Internal { | ||
|
|
||
| SPACETIMEDB_INTERNAL_PRODUCT_TYPE(RawSubmoduleV10) { | ||
| std::string namespace_; | ||
| std::shared_ptr<SpacetimeDB::Internal::RawModuleDefV10> module; | ||
|
|
||
| void bsatn_serialize(::SpacetimeDB::bsatn::Writer& writer) const { | ||
| ::SpacetimeDB::bsatn::serialize(writer, namespace_); | ||
| ::SpacetimeDB::bsatn::serialize(writer, *module); | ||
| } | ||
| SPACETIMEDB_PRODUCT_TYPE_EQUALITY(namespace_, module) | ||
| }; | ||
| } // namespace SpacetimeDB::Internal |
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,7 +113,7 @@ export function toPascalCase(s: string): string { | |
| */ | ||
| export function toCamelCase<T extends string>(s: T): CamelCase<T> { | ||
| const str = s | ||
| .replace(/[-_]+/g, '_') // collapse runs to a single separator (no backtracking issue) | ||
| .replace(/[-_]+/g, '_') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reason for the comment deletion? |
||
| .replace(/_([a-zA-Z0-9])/g, (_, c) => c.toUpperCase()); | ||
| return (str.charAt(0).toLowerCase() + str.slice(1)) as CamelCase<T>; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,11 @@ import type { | |
| } from './message_types.ts'; | ||
| import type { ReducerEvent } from './reducer_event.ts'; | ||
| import { type UntypedRemoteModule } from './spacetime_module.ts'; | ||
| import { makeQueryBuilder } from '../lib/query'; | ||
| import { | ||
| makeFromBuilder, | ||
| makeQueryBuilder, | ||
| type SubscriptionFromBuilder, | ||
| } from '../lib/query'; | ||
| import { | ||
| type TableCache, | ||
| type Operation, | ||
|
|
@@ -57,6 +61,7 @@ import type { | |
| } from './reducers.ts'; | ||
| import type { ClientDbView } from './db_view.ts'; | ||
| import type { RowType, UntypedTableDef } from '../lib/table.ts'; | ||
| import type { UntypedSchemaDef } from '../lib/schema'; | ||
| import type { ProceduresView } from './procedures.ts'; | ||
| import type { Values } from '../lib/type_util.ts'; | ||
| import type { TransactionUpdate } from './client_api/types.ts'; | ||
|
|
@@ -488,6 +493,14 @@ export class DbConnectionImpl<RemoteModule extends UntypedRemoteModule> | |
| return makeQueryBuilder({ tables: this.#remoteModule.tables } as any); | ||
| } | ||
|
|
||
| getFromBuilder< | ||
| SchemaDef extends UntypedSchemaDef, | ||
| >(): SubscriptionFromBuilder<SchemaDef> { | ||
| return makeFromBuilder<SchemaDef>( | ||
| this.#remoteModule.tables as SchemaDef['tables'] | ||
| ); | ||
| } | ||
|
|
||
| registerSubscription( | ||
| handle: SubscriptionHandleImpl<RemoteModule>, | ||
| handleEmitter: EventEmitter< | ||
|
|
@@ -534,8 +547,16 @@ export class DbConnectionImpl<RemoteModule extends UntypedRemoteModule> | |
| const rows: Operation[] = []; | ||
|
|
||
| const deserializeRow = this.#rowDeserializers[tableName]; | ||
| const { primaryKeyColName, primaryKeyColType } = | ||
| this.#rowIdMetadata[tableName]; | ||
| const rowIdInfo = this.#rowIdMetadata[tableName]; | ||
| if (!deserializeRow || !rowIdInfo) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this fallible now for some reason? |
||
| // Likely a client/server schema mismatch (e.g. stale generated bindings). | ||
| stdbLogger( | ||
| 'warn', | ||
| `Received row data for unknown table '${tableName}'; ignoring. Regenerate your module bindings if this table should exist.` | ||
| ); | ||
| return []; | ||
| } | ||
| const { primaryKeyColName, primaryKeyColType } = rowIdInfo; | ||
| let previousOffset = 0; | ||
| while (reader.remaining > 0) { | ||
| const row = deserializeRow(reader); | ||
|
|
@@ -824,6 +845,14 @@ export class DbConnectionImpl<RemoteModule extends UntypedRemoteModule> | |
| // Get table information for the table being updated | ||
| const tableName = tableUpdate.tableName; | ||
| const tableDef = this.#sourceNameToTableDef[tableName]; | ||
| if (!tableDef) { | ||
| // Likely a client/server schema mismatch (e.g. stale generated bindings). | ||
| stdbLogger( | ||
| 'warn', | ||
| `Received update for unknown table '${tableName}'; ignoring. Regenerate your module bindings if this table should exist.` | ||
| ); | ||
| continue; | ||
| } | ||
| const table = this.clientCache.getOrCreateTable(tableDef); | ||
| const newCallbacks = table.applyOperations( | ||
| tableUpdate.operations as Operation< | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unclear why this is called
Subscriptionbecause the query builder isn't specific to subscriptions.