Skip to content

Commit cc73953

Browse files
authored
Typescript views (#3584)
# Description of Changes Currently need changes from both #3548 and #3527, and the latter is merged into master but the former isn't rebased on top of it. so we stay silly for the moment I'd like to pull out my first commit into its own PR, but that's not really possible until #3548 rebases onto master. # Expected complexity level and risk 2 - pretty straightforward translation of the wasm/Rust view implementation to typescript. # Testing - [ ] <!-- maybe a test you want to do --> - [ ] <!-- maybe a test you want a reviewer to do, so they can check it off when they're satisfied. -->
1 parent d4dc289 commit cc73953

29 files changed

+1042
-382
lines changed

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

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

crates/bindings-typescript/src/lib/autogen/raw_misc_module_export_v_9_variants.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/lib/autogen/raw_procedure_def_v_9_type.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.

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

Lines changed: 82 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/lib/option.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { AlgebraicType } from './algebraic_type';
22

3-
export type OptionAlgebraicType = {
3+
export type OptionAlgebraicType<T extends AlgebraicType = AlgebraicType> = {
44
tag: 'Sum';
55
value: {
66
variants: [
7-
{ name: 'some'; algebraicType: AlgebraicType },
7+
{ name: 'some'; algebraicType: T },
88
{
99
name: 'none';
1010
algebraicType: { tag: 'Product'; value: { elements: [] } };
@@ -14,9 +14,13 @@ export type OptionAlgebraicType = {
1414
};
1515

1616
export const Option: {
17-
getAlgebraicType(innerType: AlgebraicType): OptionAlgebraicType;
17+
getAlgebraicType<T extends AlgebraicType = AlgebraicType>(
18+
innerType: T
19+
): OptionAlgebraicType<T>;
1820
} = {
19-
getAlgebraicType(innerType: AlgebraicType): OptionAlgebraicType {
21+
getAlgebraicType<T extends AlgebraicType = AlgebraicType>(
22+
innerType: T
23+
): OptionAlgebraicType<T> {
2024
return AlgebraicType.Sum({
2125
variants: [
2226
{ name: 'some', algebraicType: innerType },

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

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ export type Indexes<
4646
[k in keyof I]: Index<TableDef, I[k]>;
4747
};
4848

49+
export type ReadonlyIndexes<
50+
TableDef extends UntypedTableDef,
51+
I extends Record<string, UntypedIndex<keyof TableDef['columns'] & string>>,
52+
> = {
53+
[k in keyof I]: ReadonlyIndex<TableDef, I[k]>;
54+
};
55+
4956
/**
5057
* A type representing a database index, which can be either unique or ranged.
5158
*/
@@ -56,32 +63,51 @@ export type Index<
5663
? UniqueIndex<TableDef, I>
5764
: RangedIndex<TableDef, I>;
5865

66+
export type ReadonlyIndex<
67+
TableDef extends UntypedTableDef,
68+
I extends UntypedIndex<keyof TableDef['columns'] & string>,
69+
> = I['unique'] extends true
70+
? ReadonlyUniqueIndex<TableDef, I>
71+
: ReadonlyRangedIndex<TableDef, I>;
72+
73+
export interface ReadonlyUniqueIndex<
74+
TableDef extends UntypedTableDef,
75+
I extends UntypedIndex<keyof TableDef['columns'] & string>,
76+
> {
77+
find(col_val: IndexVal<TableDef, I>): RowType<TableDef> | null;
78+
}
79+
5980
/**
6081
* A type representing a unique index on a database table.
6182
* Unique indexes enforce that the indexed columns contain unique values.
6283
*/
63-
export type UniqueIndex<
84+
export interface UniqueIndex<
6485
TableDef extends UntypedTableDef,
6586
I extends UntypedIndex<keyof TableDef['columns'] & string>,
66-
> = {
67-
find(col_val: IndexVal<TableDef, I>): RowType<TableDef> | null;
87+
> extends ReadonlyUniqueIndex<TableDef, I> {
6888
delete(col_val: IndexVal<TableDef, I>): boolean;
6989
update(col_val: RowType<TableDef>): RowType<TableDef>;
70-
};
90+
}
91+
92+
export interface ReadonlyRangedIndex<
93+
TableDef extends UntypedTableDef,
94+
I extends UntypedIndex<keyof TableDef['columns'] & string>,
95+
> {
96+
filter(
97+
range: IndexScanRangeBounds<TableDef, I>
98+
): IterableIterator<RowType<TableDef>>;
99+
}
71100

72101
/**
73102
* A type representing a ranged index on a database table.
74103
* Ranged indexes allow for range queries on the indexed columns.
75104
*/
76-
export type RangedIndex<
105+
export interface RangedIndex<
77106
TableDef extends UntypedTableDef,
78107
I extends UntypedIndex<keyof TableDef['columns'] & string>,
79-
> = {
80-
filter(
81-
range: IndexScanRangeBounds<TableDef, I>
82-
): IterableIterator<RowType<TableDef>>;
108+
> extends ReadonlyRangedIndex<TableDef, I> {
83109
delete(range: IndexScanRangeBounds<TableDef, I>): number;
84-
};
110+
}
85111

86112
/**
87113
* A helper type to extract the value type of an index based on the table definition and index definition.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { register_hooks } from 'spacetime:sys@1.0';
2-
import { hooks } from './runtime';
2+
import { register_hooks as register_hooks_v1_1 } from 'spacetime:sys@1.1';
3+
import { hooks, hooks_v1_1 } from './runtime';
34

45
register_hooks(hooks);
6+
register_hooks_v1_1(hooks_v1_1);

0 commit comments

Comments
 (0)