Skip to content
Open
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
1 change: 1 addition & 0 deletions crates/bindings-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"lint": "eslint . && prettier . --check --ignore-path ../../.prettierignore",
"test": "vitest run",
"test:typecheck": "vitest typecheck --run",
"test:typecheck:dts": "tsc -p tsconfig.typecheck.dts.json --noEmit",
"coverage": "vitest run --coverage",
"brotli-size": "brotli-size dist/index.js",
"size": "pnpm -s build && size-limit",
Expand Down
2 changes: 2 additions & 0 deletions crates/bindings-typescript/src/lib/type_builders.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const rowOptionOptional = {
};
type RowOptionOptional = InferTypeOfRow<typeof rowOptionOptional>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _rowOptionOptionalOmitted: RowOptionOptional = {};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _rowOptionOptionalNone: RowOptionOptional = {
foo: undefined,
};
Expand Down
21 changes: 18 additions & 3 deletions crates/bindings-typescript/src/lib/type_builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,24 @@ export type Infer<T> = T extends RowObj
/**
* Helper type to extract the type of a row from an object.
*/
export type InferTypeOfRow<T extends RowObj> = {
[K in keyof T & string]: InferTypeOfTypeBuilder<CollapseColumn<T[K]>>;
};
type OptionalRowKeys<T extends RowObj> = {
[K in keyof T & string]-?: CollapseColumn<T[K]> extends OptionBuilder<any>
? K
: never;
}[keyof T & string];

type RequiredRowKeys<T extends RowObj> = Exclude<
keyof T & string,
OptionalRowKeys<T>
>;

export type InferTypeOfRow<T extends RowObj> = Prettify<
{
[K in RequiredRowKeys<T>]: InferTypeOfTypeBuilder<CollapseColumn<T[K]>>;
} & {
[K in OptionalRowKeys<T>]?: InferTypeOfTypeBuilder<CollapseColumn<T[K]>>;
}
>;

/**
* Helper type to extract the type of a row from an object.
Expand Down
3 changes: 2 additions & 1 deletion crates/bindings-typescript/src/sdk/table_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ export class TableCacheImpl<
const columns = idx.columns;

// Extract the tuple key for this btree index (column order preserved)
const getKey = (row: Row): readonly unknown[] => columns.map(c => row[c]);
const getKey = (row: Row): readonly unknown[] =>
columns.map(c => (row as Record<string, unknown>)[c]);

// The server’s ranged scan fixes all prefix cols to equality and applies
// the bound only to the *last* term. We mirror that.
Expand Down
7 changes: 5 additions & 2 deletions crates/bindings-typescript/src/server/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,11 @@ type ViewInfo<F> = {
returnTypeBaseSize: number;
};

export type Views = ViewInfo<ViewFn<any, any, any>>[];
export type AnonViews = ViewInfo<AnonymousViewFn<any, any, any>>[];
type AnyViewFn = (ctx: ViewCtx<any>, params: any) => any;
type AnyAnonymousViewFn = (ctx: AnonymousViewCtx<any>, params: any) => any;

export type Views = ViewInfo<AnyViewFn>[];
export type AnonViews = ViewInfo<AnyAnonymousViewFn>[];

// A helper to get the product type out of a type builder.
// This is only non-never if the type builder is an array.
Expand Down
8 changes: 8 additions & 0 deletions crates/bindings-typescript/tsconfig.typecheck.dts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"jsx": "react-jsx"
},
"include": ["src/**/*.test-d.ts", "src/server/sys.d.ts"],
"exclude": ["node_modules", "dist/**/*", "src/svelte/**/*", "src/vue/**/*"]
}
Loading