Skip to content
Merged
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.

12 changes: 8 additions & 4 deletions crates/bindings-typescript/src/lib/option.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AlgebraicType } from './algebraic_type';

export type OptionAlgebraicType = {
export type OptionAlgebraicType<T extends AlgebraicType = AlgebraicType> = {
tag: 'Sum';
value: {
variants: [
{ name: 'some'; algebraicType: AlgebraicType },
{ name: 'some'; algebraicType: T },
{
name: 'none';
algebraicType: { tag: 'Product'; value: { elements: [] } };
Expand All @@ -14,9 +14,13 @@ export type OptionAlgebraicType = {
};

export const Option: {
getAlgebraicType(innerType: AlgebraicType): OptionAlgebraicType;
getAlgebraicType<T extends AlgebraicType = AlgebraicType>(
innerType: T
): OptionAlgebraicType<T>;
} = {
getAlgebraicType(innerType: AlgebraicType): OptionAlgebraicType {
getAlgebraicType<T extends AlgebraicType = AlgebraicType>(
innerType: T
): OptionAlgebraicType<T> {
return AlgebraicType.Sum({
variants: [
{ name: 'some', algebraicType: innerType },
Expand Down
46 changes: 36 additions & 10 deletions crates/bindings-typescript/src/server/indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export type Indexes<
[k in keyof I]: Index<TableDef, I[k]>;
};

export type ReadonlyIndexes<
TableDef extends UntypedTableDef,
I extends Record<string, UntypedIndex<keyof TableDef['columns'] & string>>,
> = {
[k in keyof I]: ReadonlyIndex<TableDef, I[k]>;
};

/**
* A type representing a database index, which can be either unique or ranged.
*/
Expand All @@ -56,32 +63,51 @@ export type Index<
? UniqueIndex<TableDef, I>
: RangedIndex<TableDef, I>;

export type ReadonlyIndex<
TableDef extends UntypedTableDef,
I extends UntypedIndex<keyof TableDef['columns'] & string>,
> = I['unique'] extends true
? ReadonlyUniqueIndex<TableDef, I>
: ReadonlyRangedIndex<TableDef, I>;

export interface ReadonlyUniqueIndex<
TableDef extends UntypedTableDef,
I extends UntypedIndex<keyof TableDef['columns'] & string>,
> {
find(col_val: IndexVal<TableDef, I>): RowType<TableDef> | null;
}

/**
* A type representing a unique index on a database table.
* Unique indexes enforce that the indexed columns contain unique values.
*/
export type UniqueIndex<
export interface UniqueIndex<
TableDef extends UntypedTableDef,
I extends UntypedIndex<keyof TableDef['columns'] & string>,
> = {
find(col_val: IndexVal<TableDef, I>): RowType<TableDef> | null;
> extends ReadonlyUniqueIndex<TableDef, I> {
delete(col_val: IndexVal<TableDef, I>): boolean;
update(col_val: RowType<TableDef>): RowType<TableDef>;
};
}

export interface ReadonlyRangedIndex<
TableDef extends UntypedTableDef,
I extends UntypedIndex<keyof TableDef['columns'] & string>,
> {
filter(
range: IndexScanRangeBounds<TableDef, I>
): IterableIterator<RowType<TableDef>>;
}

/**
* A type representing a ranged index on a database table.
* Ranged indexes allow for range queries on the indexed columns.
*/
export type RangedIndex<
export interface RangedIndex<
TableDef extends UntypedTableDef,
I extends UntypedIndex<keyof TableDef['columns'] & string>,
> = {
filter(
range: IndexScanRangeBounds<TableDef, I>
): IterableIterator<RowType<TableDef>>;
> extends ReadonlyRangedIndex<TableDef, I> {
delete(range: IndexScanRangeBounds<TableDef, I>): number;
};
}

/**
* A helper type to extract the value type of an index based on the table definition and index definition.
Expand Down
4 changes: 3 additions & 1 deletion crates/bindings-typescript/src/server/register_hooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { register_hooks } from 'spacetime:sys@1.0';
import { hooks } from './runtime';
import { register_hooks as register_hooks_v1_1 } from 'spacetime:sys@1.1';
import { hooks, hooks_v1_1 } from './runtime';

register_hooks(hooks);
register_hooks_v1_1(hooks_v1_1);
Loading
Loading