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
2 changes: 1 addition & 1 deletion crates/bindings-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"format": "prettier . --write --ignore-path ../../.prettierignore",
"lint": "eslint . && prettier . --check --ignore-path ../../.prettierignore",
"test": "vitest run",
"test:typecheck": "vitest typecheck --run",
"test:typecheck": "tsc -p tsconfig.typecheck.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 @@ -36,12 +36,27 @@ export type Infer<T> = T extends RowObj
? InferTypeOfTypeBuilder<T>
: never;

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>
>;

/**
* 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]>>;
};
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
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
10 changes: 3 additions & 7 deletions crates/bindings-typescript/tsconfig.typecheck.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
"jsx": "react-jsx"
},
"include": [
"tests/**/*",
"src/lib/**/*",
"src/sdk/**/*",
"src/react/**/*",
"test-app/**/*"
"src/**/*.test-d.ts",
"src/server/sys.d.ts"
],
"exclude": [
"node_modules",
"dist/**/*",
"src/svelte/**/*",
"src/vue/**/*",
"src/server/**/*"
"src/vue/**/*"
]
}
2 changes: 1 addition & 1 deletion crates/bindings-typescript/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineConfig({
globals: true,
environment: 'node',
typecheck: {
include: ['tests/**/*.test.ts'],
include: ['src/**/*.test-d.ts'],
tsconfig: './tsconfig.typecheck.json',
},
},
Expand Down