Skip to content

Commit 2b05812

Browse files
committed
[bot/reopen-database-lock]: Merge remote-tracking branch 'origin/master' into bot/reopen-database-lock
2 parents 8b9d0bd + 77ffdbb commit 2b05812

67 files changed

Lines changed: 1043 additions & 716 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.

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ jobs:
261261
262262
wasm-bindgen --version
263263
264+
- name: Check engine simulation build
265+
run: cargo check -p spacetimedb-engine --no-default-features --features simulation
266+
264267
# Source emsdk environment to make emcc (Emscripten compiler) available in PATH.
265268
- name: Run tests
266269
run: |

Cargo.lock

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

Cargo.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ members = [
1414
"crates/data-structures",
1515
"crates/datastore",
1616
"crates/durability",
17+
"crates/engine",
1718
"crates/execution",
1819
"crates/expr",
1920
"crates/guard",
@@ -133,8 +134,10 @@ spacetimedb-core = { path = "crates/core", version = "=2.6.0" }
133134
spacetimedb-data-structures = { path = "crates/data-structures", version = "=2.6.0" }
134135
spacetimedb-datastore = { path = "crates/datastore", version = "=2.6.0" }
135136
spacetimedb-durability = { path = "crates/durability", version = "=2.6.0" }
137+
spacetimedb-engine = { path = "crates/engine", version = "=2.6.0" }
136138
spacetimedb-execution = { path = "crates/execution", version = "=2.6.0" }
137139
spacetimedb-expr = { path = "crates/expr", version = "=2.6.0" }
140+
spacetimedb-fs-utils = { path = "crates/fs-utils", version = "=2.6.0" }
138141
spacetimedb-guard = { path = "crates/guard", version = "=2.6.0" }
139142
spacetimedb-lib = { path = "crates/lib", default-features = false, version = "=2.6.0" }
140143
spacetimedb-memory-usage = { path = "crates/memory-usage", version = "=2.6.0", default-features = false }
@@ -144,16 +147,15 @@ spacetimedb-pg = { path = "crates/pg", version = "=2.6.0" }
144147
spacetimedb-physical-plan = { path = "crates/physical-plan", version = "=2.6.0" }
145148
spacetimedb-primitives = { path = "crates/primitives", version = "=2.6.0" }
146149
spacetimedb-query = { path = "crates/query", version = "=2.6.0" }
150+
spacetimedb-query-builder = { path = "crates/query-builder", version = "=2.6.0" }
151+
spacetimedb-runtime = { path = "crates/runtime", version = "=2.6.0" }
147152
spacetimedb-sats = { path = "crates/sats", version = "=2.6.0" }
148153
spacetimedb-schema = { path = "crates/schema", version = "=2.6.0" }
154+
spacetimedb-snapshot = { path = "crates/snapshot", version = "=2.6.0" }
149155
spacetimedb-standalone = { path = "crates/standalone", version = "=2.6.0" }
156+
spacetimedb-subscription = { path = "crates/subscription", version = "=2.6.0" }
150157
spacetimedb-sql-parser = { path = "crates/sql-parser", version = "=2.6.0" }
151158
spacetimedb-table = { path = "crates/table", version = "=2.6.0" }
152-
spacetimedb-fs-utils = { path = "crates/fs-utils", version = "=2.6.0" }
153-
spacetimedb-snapshot = { path = "crates/snapshot", version = "=2.6.0" }
154-
spacetimedb-subscription = { path = "crates/subscription", version = "=2.6.0" }
155-
spacetimedb-query-builder = { path = "crates/query-builder", version = "=2.6.0" }
156-
spacetimedb-runtime = { path = "crates/runtime", version = "=2.6.0" }
157159

158160
# Prevent `ahash` from pulling in `getrandom` by disabling default features.
159161
# Modules use `getrandom02` and we need to prevent an incompatible version

crates/bench/benches/subscription.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use criterion::{black_box, criterion_group, criterion_main, Criterion};
22
use spacetimedb::client::consume_each_list::ConsumeEachBuffer;
33
use spacetimedb::db::relational_db::RelationalDB;
4+
use spacetimedb::db::sql::ast::SchemaViewer;
45
use spacetimedb::error::DBError;
56
use spacetimedb::identity::AuthCtx;
6-
use spacetimedb::sql::ast::SchemaViewer;
77
use spacetimedb::subscription::row_list_builder_pool::BsatnRowListBuilderPool;
88
use spacetimedb::subscription::tx::DeltaTx;
99
use spacetimedb::subscription::{collect_table_update, TableUpdateType};

crates/bindings-typescript/src/lib/type_builders.test-d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const rowOptionOptional = {
3535
};
3636
type RowOptionOptional = InferTypeOfRow<typeof rowOptionOptional>;
3737
// eslint-disable-next-line @typescript-eslint/no-unused-vars
38+
const _rowOptionOptionalOmitted: RowOptionOptional = {};
39+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3840
const _rowOptionOptionalNone: RowOptionOptional = {
3941
foo: undefined,
4042
};

crates/bindings-typescript/src/lib/type_builders.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,45 @@ export type Infer<T> = T extends RowObj
3939
/**
4040
* Helper type to extract the type of a row from an object.
4141
*/
42-
export type InferTypeOfRow<T extends RowObj> = {
43-
[K in keyof T & string]: InferTypeOfTypeBuilder<CollapseColumn<T[K]>>;
44-
};
42+
type OptionalRowKeys<T extends RowObj> = {
43+
[K in keyof T & string]-?: CollapseColumn<T[K]> extends OptionBuilder<any>
44+
? K
45+
: never;
46+
}[keyof T & string];
47+
48+
type RequiredRowKeys<T extends RowObj> = Exclude<
49+
keyof T & string,
50+
OptionalRowKeys<T>
51+
>;
52+
53+
export type InferTypeOfRow<T extends RowObj> = Prettify<
54+
{
55+
[K in RequiredRowKeys<T>]: InferTypeOfTypeBuilder<CollapseColumn<T[K]>>;
56+
} & {
57+
[K in OptionalRowKeys<T>]?: InferTypeOfTypeBuilder<CollapseColumn<T[K]>>;
58+
}
59+
>;
60+
61+
type OptionalParamKeys<T extends RowObj> = {
62+
[K in keyof T & string]-?: undefined extends InferTypeOfTypeBuilder<
63+
CollapseColumn<T[K]>
64+
>
65+
? K
66+
: never;
67+
}[keyof T & string];
68+
69+
type RequiredParamKeys<T extends RowObj> = Exclude<
70+
keyof T & string,
71+
OptionalParamKeys<T>
72+
>;
73+
74+
export type InferTypeOfParams<T extends RowObj> = Prettify<
75+
{
76+
[K in RequiredParamKeys<T>]: InferTypeOfTypeBuilder<CollapseColumn<T[K]>>;
77+
} & {
78+
[K in OptionalParamKeys<T>]?: InferTypeOfTypeBuilder<CollapseColumn<T[K]>>;
79+
}
80+
>;
4581

4682
/**
4783
* Helper type to extract the type of a row from an object.

crates/bindings-typescript/src/sdk/db_connection_impl.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ import {
2323
type SubscriptionEventContextInterface,
2424
} from './event_context.ts';
2525
import { EventEmitter } from './event_emitter.ts';
26-
import type { Deserializer, Identity, InferTypeOfRow, Serializer } from '../';
26+
import type {
27+
Deserializer,
28+
Identity,
29+
InferTypeOfParams,
30+
Serializer,
31+
} from '../';
2732
import type {
2833
ProcedureResultMessage,
2934
ReducerResultMessage,
@@ -383,7 +388,9 @@ export class DbConnectionImpl<RemoteModule extends UntypedRemoteModule>
383388
const { serialize: serializeArgs } =
384389
this.#reducerArgsSerializers[reducerName];
385390

386-
(out as any)[key] = (params: InferTypeOfRow<typeof reducer.params>) => {
391+
(out as any)[key] = (
392+
params: InferTypeOfParams<typeof reducer.params>
393+
) => {
387394
const writer = this.#reducerArgsEncoder;
388395
writer.clear();
389396
serializeArgs(writer, params);
@@ -414,7 +421,7 @@ export class DbConnectionImpl<RemoteModule extends UntypedRemoteModule>
414421
this.#procedureSerializers[procedureName];
415422

416423
(out as any)[key] = (
417-
params: InferTypeOfRow<typeof procedure.params>
424+
params: InferTypeOfParams<typeof procedure.params>
418425
): Promise<any> => {
419426
writer.clear();
420427
serializeArgs(writer, params);
@@ -436,7 +443,7 @@ export class DbConnectionImpl<RemoteModule extends UntypedRemoteModule>
436443
event: Event<
437444
ReducerEventInfo<
438445
RemoteModule['reducers'][number]['name'],
439-
InferTypeOfRow<RemoteModule['reducers'][number]['params']>
446+
InferTypeOfParams<RemoteModule['reducers'][number]['params']>
440447
>
441448
>
442449
): EventContextInterface<RemoteModule> {

crates/bindings-typescript/src/sdk/event_context.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { InferTypeOfRow } from '../lib/type_builders.ts';
1+
import type { InferTypeOfParams } from '../lib/type_builders.ts';
22
import type { DbContext } from './db_context';
33
import type { Event } from './event.ts';
44
import type { ReducerEvent } from './reducer_event.ts';
@@ -13,7 +13,7 @@ export interface EventContextInterface<RemoteModule extends UntypedRemoteModule>
1313
event: Event<
1414
ReducerEventInfo<
1515
RemoteModule['reducers'][number]['name'],
16-
InferTypeOfRow<RemoteModule['reducers'][number]['params']>
16+
InferTypeOfParams<RemoteModule['reducers'][number]['params']>
1717
>
1818
>;
1919
}
@@ -25,7 +25,7 @@ export interface ReducerEventContextInterface<
2525
event: ReducerEvent<
2626
ReducerEventInfo<
2727
RemoteModule['reducers'][number]['name'],
28-
InferTypeOfRow<RemoteModule['reducers'][number]['params']>
28+
InferTypeOfParams<RemoteModule['reducers'][number]['params']>
2929
>
3030
>;
3131
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import type { ParamsObj } from '../lib/reducers';
2-
import type { Infer, InferTypeOfRow, TypeBuilder } from '../lib/type_builders';
2+
import type {
3+
Infer,
4+
InferTypeOfParams,
5+
TypeBuilder,
6+
} from '../lib/type_builders';
37
import type { CamelCase } from '../lib/type_util';
48
import { coerceParams, toCamelCase, type CoerceParams } from '../lib/util';
59
import type { UntypedRemoteModule } from './spacetime_module';
@@ -20,7 +24,7 @@ export type ProceduresView<RemoteModule> = IfAny<
2024
? // x: camelCase(name)
2125
{
2226
[K in RemoteModule['procedures'][number] as K['accessorName']]: (
23-
params: InferTypeOfRow<K['params']>
27+
params: InferTypeOfParams<K['params']>
2428
) => Promise<Infer<K['returnType']>>;
2529
}
2630
: never

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import type { ProductType } from '../lib/algebraic_type';
22
import type { ReducerSchema } from '../lib/reducer_schema';
33
import type { ParamsObj } from '../lib/reducers';
4-
import type { CoerceRow } from '../lib/table';
5-
import { RowBuilder, type InferTypeOfRow } from '../lib/type_builders';
4+
import { RowBuilder, type InferTypeOfParams } from '../lib/type_builders';
65
import { toCamelCase } from '../lib/util';
76
import type { SubscriptionEventContextInterface } from './event_context';
87
import type { UntypedRemoteModule } from './spacetime_module';
@@ -26,7 +25,7 @@ export type ReducersView<RemoteModule> = IfAny<
2625
RemoteModule extends UntypedRemoteModule
2726
? {
2827
[K in RemoteModule['reducers'][number] as K['accessorName']]: (
29-
params: InferTypeOfRow<K['params']>
28+
params: InferTypeOfParams<K['params']>
3029
) => Promise<void>;
3130
}
3231
: never
@@ -43,7 +42,7 @@ export type ReducerEventInfo<
4342
export type UntypedReducerDef = {
4443
name: string;
4544
accessorName: string;
46-
params: CoerceRow<ParamsObj>;
45+
params: ParamsObj;
4746
paramsType: ProductType;
4847
};
4948

0 commit comments

Comments
 (0)