Skip to content

Commit 3f93250

Browse files
committed
Merge branch 'master' into shub/table-name-to-accessor
2 parents ee62ea2 + 2ffe174 commit 3f93250

864 files changed

Lines changed: 139848 additions & 6521 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: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,25 @@ jobs:
7979
with:
8080
run_install: true
8181

82+
# Install emscripten for C++ module compilation tests.
83+
- name: Install emscripten (Linux)
84+
if: runner.os == 'Linux'
85+
shell: bash
86+
run: |
87+
git clone https://github.com/emscripten-core/emsdk.git ~/emsdk
88+
cd ~/emsdk
89+
./emsdk install 4.0.21
90+
./emsdk activate 4.0.21
91+
92+
- name: Install emscripten (Windows)
93+
if: runner.os == 'Windows'
94+
shell: pwsh
95+
run: |
96+
git clone https://github.com/emscripten-core/emsdk.git $env:USERPROFILE\emsdk
97+
cd $env:USERPROFILE\emsdk
98+
.\emsdk install 4.0.21
99+
.\emsdk activate 4.0.21
100+
82101
- name: Install psql (Windows)
83102
if: runner.os == 'Windows'
84103
run: choco install psql -y --no-progress
@@ -122,11 +141,27 @@ jobs:
122141
- name: Install cargo-nextest
123142
uses: taiki-e/install-action@nextest
124143

125-
- name: Run smoketests
126-
# --test-threads=1 eliminates contention in the C# tests where they fight over bindings
127-
# build artifacts.
128-
# It also seemed to improve performance a fair amount (11m -> 6m)
129-
run: cargo ci smoketests -- --test-threads=1
144+
# --test-threads=1 eliminates contention in the C# tests where they fight over bindings
145+
# build artifacts.
146+
# It also seemed to improve performance a fair amount (11m -> 6m)
147+
- name: Run smoketests (Linux)
148+
if: runner.os == 'Linux'
149+
shell: bash
150+
run: |
151+
if [ -f ~/emsdk/emsdk_env.sh ]; then
152+
source ~/emsdk/emsdk_env.sh
153+
fi
154+
cargo ci smoketests -- --test-threads=1
155+
156+
# Due to Emscripten PATH issues this was separated to make sure OpenSSL still builds correctly
157+
- name: Run smoketests (Windows)
158+
if: runner.os == 'Windows'
159+
shell: pwsh
160+
run: |
161+
if (Test-Path "$env:USERPROFILE\emsdk\emsdk_env.ps1") {
162+
& "$env:USERPROFILE\emsdk\emsdk_env.ps1" | Out-Null
163+
}
164+
cargo ci smoketests -- --test-threads=1
130165
131166
smoketests-python:
132167
needs: [lints]
@@ -806,6 +841,12 @@ jobs:
806841
key: Unity-${{ github.head_ref }}
807842
restore-keys: Unity-
808843

844+
- name: Login to DockerHub
845+
uses: docker/login-action@v2
846+
with:
847+
username: ${{ vars.DOCKERHUB_USERNAME }}
848+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
849+
809850
- name: Run Unity tests
810851
uses: game-ci/unity-test-runner@v4
811852
with:

.github/workflows/package.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
include:
17-
- { name: x86_64 Linux, target: x86_64-unknown-linux-gnu, runner: spacetimedb-new-runner-2 }
17+
# WARNING - do not upgrade this runner to 24.04 or the self hosted runners because it will break downloads for
18+
# anyone who uses a linux distro that doesn't have glibc >= GLIBC_2.38
19+
- { name: x86_64 Linux, target: x86_64-unknown-linux-gnu, runner: ubuntu-22.04 }
1820
- { name: aarch64 Linux, target: aarch64-unknown-linux-gnu, runner: arm-runner }
1921
# Disabled because musl builds weren't working and we didn't want to investigate. See https://github.com/clockworklabs/SpacetimeDB/pull/2964.
2022
# - { name: x86_64 Linux musl, target: x86_64-unknown-linux-musl, runner: bare-metal, container: alpine }

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ new.json
234234
# C++ build data
235235
modules/benchmarks-cpp/build/
236236
modules/module-test-cpp/build/
237+
modules/sdk-test-cpp/build/
238+
modules/sdk-test-connect-disconnect-cpp/build/
239+
modules/sdk-test-procedure-cpp/build/
240+
modules/sdk-test-view-cpp/build/
237241

238242
# Symlinked output from `nix build`
239243
result

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ rayon-core = "1.11.0"
255255
regex = "1"
256256
reqwest = { version = "0.12", features = ["stream", "json"] }
257257
rolldown = { git = "https://github.com/rolldown/rolldown.git", tag = "v1.0.0-beta.42" }
258+
rolldown_common = { git = "https://github.com/rolldown/rolldown.git", tag = "v1.0.0-beta.42" }
258259
rolldown_utils = { git = "https://github.com/rolldown/rolldown.git", tag = "v1.0.0-beta.42" }
259260
ron = "0.8"
260261
rusqlite = { version = "0.29.0", features = ["bundled", "column_decltype"] }

crates/bindings-typescript/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { DbConnection } from './module_bindings';
2525

2626
const connection = DbConnection.builder()
2727
.withUri('ws://localhost:3000')
28-
.withModuleName('MODULE_NAME')
28+
.withDatabaseName('MODULE_NAME')
2929
.onDisconnect(() => {
3030
console.log('disconnected');
3131
})
@@ -71,7 +71,7 @@ This module also include React hooks to subscribe to tables under the `spacetime
7171
```tsx
7272
const connectionBuilder = DbConnection.builder()
7373
.withUri('ws://localhost:3000')
74-
.withModuleName('MODULE_NAME')
74+
.withDatabaseName('MODULE_NAME')
7575
.withLightMode(true)
7676
.onDisconnect(() => {
7777
console.log('disconnected');

crates/bindings-typescript/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
"author": "Clockwork Labs",
2121
"type": "module",
2222
"sideEffects": [
23-
"./src/server/polyfills.ts",
24-
"./src/server/register_hooks.ts"
23+
"./src/server/polyfills.ts"
2524
],
2625
"scripts": {
2726
"build:js": "tsup",

crates/bindings-typescript/src/lib/autogen/function_visibility_type.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type IndexOpts<AllowedCol extends string> = {
1212
name?: string;
1313
} & (
1414
| { algorithm: 'btree'; columns: readonly AllowedCol[] }
15+
| { algorithm: 'hash'; columns: readonly AllowedCol[] }
1516
| { algorithm: 'direct'; column: AllowedCol }
1617
);
1718

@@ -21,7 +22,7 @@ export type IndexOpts<AllowedCol extends string> = {
2122
export type UntypedIndex<AllowedCol extends string> = {
2223
name: string;
2324
unique?: boolean;
24-
algorithm: 'btree' | 'direct';
25+
algorithm: 'btree' | 'direct' | 'hash';
2526
columns: readonly AllowedCol[];
2627
};
2728

@@ -47,14 +48,17 @@ export type Indexes<
4748
};
4849

4950
/**
50-
* A type representing a database index, which can be either unique or ranged.
51+
* A type representing a database index,
52+
* which can either be unique or filter for a single value or range of values.
5153
*/
5254
export type Index<
5355
TableDef extends UntypedTableDef,
5456
I extends UntypedIndex<keyof TableDef['columns'] & string>,
5557
> = I['unique'] extends true
5658
? UniqueIndex<TableDef, I>
57-
: RangedIndex<TableDef, I>;
59+
: I['algorithm'] extends 'hash'
60+
? PointIndex<TableDef, I>
61+
: RangedIndex<TableDef, I>;
5862

5963
/**
6064
* A type representing a collection of read-only indexes defined on a table.
@@ -67,15 +71,18 @@ export type ReadonlyIndexes<
6771
};
6872

6973
/**
70-
* A type representing a read-only database index, which can be either unique or ranged.
74+
* A type representing a read-only database index,
75+
* which can be either unique, pointed, or ranged.
7176
* This type only exposes read-only operations.
7277
*/
7378
export type ReadonlyIndex<
7479
TableDef extends UntypedTableDef,
7580
I extends UntypedIndex<keyof TableDef['columns'] & string>,
7681
> = I['unique'] extends true
7782
? ReadonlyUniqueIndex<TableDef, I>
78-
: ReadonlyRangedIndex<TableDef, I>;
83+
: I['algorithm'] extends 'hash'
84+
? ReadonlyPointIndex<TableDef, I>
85+
: ReadonlyRangedIndex<TableDef, I>;
7986

8087
/**
8188
* A type representing a read-only unique index on a database table.
@@ -99,6 +106,29 @@ export interface UniqueIndex<
99106
update(colVal: Prettify<RowType<TableDef>>): Prettify<RowType<TableDef>>;
100107
}
101108

109+
/**
110+
* A type representing a read-only point index on a database table.
111+
*/
112+
export interface ReadonlyPointIndex<
113+
TableDef extends UntypedTableDef,
114+
I extends UntypedIndex<keyof TableDef['columns'] & string>,
115+
> {
116+
filter(
117+
point: IndexVal<TableDef, I>
118+
): IteratorObject<Prettify<RowType<TableDef>>, undefined>;
119+
}
120+
121+
/**
122+
* A type representing a point index on a database table.
123+
* Point indexes allow for exact match queries on the indexed columns.
124+
*/
125+
export interface PointIndex<
126+
TableDef extends UntypedTableDef,
127+
I extends UntypedIndex<keyof TableDef['columns'] & string>,
128+
> extends ReadonlyPointIndex<TableDef, I> {
129+
delete(point: IndexVal<TableDef, I>): number;
130+
}
131+
102132
/**
103133
* A type representing a read-only ranged index on a database table.
104134
*/
@@ -190,7 +220,7 @@ export type ColumnIndex<
190220
name: Name;
191221
unique: ColumnIsUnique<M>;
192222
columns: readonly [Name];
193-
algorithm: 'btree' | 'direct';
223+
algorithm: 'btree' | 'direct' | 'hash';
194224
} & (M extends {
195225
indexType: infer I extends NonNullable<IndexTypes>;
196226
}

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

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,20 @@ type ColList = ColId[];
4141
/**
4242
* Check if any column in the row has invalid metadata.
4343
*/
44-
type HasInvalidColumn<Row extends RowObj> = {
45-
[K in keyof Row]: Row[K] extends ColumnBuilder<any, any, infer M>
46-
? ValidateColumnMetadata<M> extends InvalidColumnMetadata<any>
47-
? true
48-
: false
49-
: false;
50-
}[keyof Row] extends false
51-
? false
52-
: true;
44+
type HasInvalidColumn<Row extends RowObj> =
45+
// this checks if Row exactly equals RowObj - if it does, we can't
46+
// do type-system-level checking, so just let it pass
47+
(<G>() => G extends Row ? 1 : 2) extends <G>() => G extends RowObj ? 1 : 2
48+
? false
49+
: {
50+
[K in keyof Row]: Row[K] extends ColumnBuilder<any, any, infer M>
51+
? ValidateColumnMetadata<M> extends InvalidColumnMetadata<any>
52+
? true
53+
: false
54+
: false;
55+
}[keyof Row] extends false
56+
? false
57+
: true;
5358

5459
/**
5560
* Extract the names of columns that have invalid metadata.
@@ -336,6 +341,9 @@ export function table<Row extends RowObj, const Opts extends TableOpts<Row>>(
336341
case 'btree':
337342
algorithm = RawIndexAlgorithm.BTree([id]);
338343
break;
344+
case 'hash':
345+
algorithm = RawIndexAlgorithm.Hash([id]);
346+
break;
339347
case 'direct':
340348
algorithm = RawIndexAlgorithm.Direct(id);
341349
break;
@@ -393,6 +401,12 @@ export function table<Row extends RowObj, const Opts extends TableOpts<Row>>(
393401
value: indexOpts.columns.map(c => colIds.get(c)!),
394402
};
395403
break;
404+
case 'hash':
405+
algorithm = {
406+
tag: 'Hash',
407+
value: indexOpts.columns.map(c => colIds.get(c)!),
408+
};
409+
break;
396410
case 'direct':
397411
algorithm = { tag: 'Direct', value: colIds.get(indexOpts.column)! };
398412
break;

0 commit comments

Comments
 (0)