Files
dbtype/src/utils.ts
glm-5.1 d0a0de766b feat: fork drizzle-typebox as @alkdev/drizzlebox
- Rebrand package from drizzle-typebox to @alkdev/drizzlebox
- Replace @sinclair/typebox with @alkdev/typebox in all source and test files
- Replace @sinclair/typebox with @alkdev/typebox in rollup externals
- Convert tsconfig.json from monorepo extends to standalone config
- Fix build script monorepo remnant (dist.new -> dist)
- Add missing devDependencies (recast, tsx, typescript, resolve-tspaths)
- Replace monorepo link dependency for drizzle-orm with ^0.38.4
- Add .gitignore, LICENSE (Apache-2.0 with attribution), and README
- Initialize git repo with remote at git.alk.dev:alkdev/drizzlebox
2026-04-25 09:45:14 +00:00

51 lines
1.8 KiB
TypeScript

import type { Kind, Static, TSchema } from '@alkdev/typebox';
import type { Column, SelectedFieldsFlat, Table, View } from 'drizzle-orm';
import type { PgEnum } from 'drizzle-orm/pg-core';
import type { literalSchema } from './column.ts';
export function isColumnType<T extends Column>(column: Column, columnTypes: string[]): column is T {
return columnTypes.includes(column.columnType);
}
export function isWithEnum(column: Column): column is typeof column & { enumValues: [string, ...string[]] } {
return 'enumValues' in column && Array.isArray(column.enumValues) && column.enumValues.length > 0;
}
export const isPgEnum: (entity: any) => entity is PgEnum<[string, ...string[]]> = isWithEnum as any;
type Literal = Static<typeof literalSchema>;
export type Json = Literal | { [key: string]: Json } | Json[];
export interface JsonSchema extends TSchema {
[Kind]: 'Union';
static: Json;
anyOf: Json;
}
export interface BufferSchema extends TSchema {
[Kind]: 'Buffer';
static: Buffer;
type: 'buffer';
}
export type IsNever<T> = [T] extends [never] ? true : false;
export type ArrayHasAtLeastOneValue<TEnum extends [any, ...any[]] | undefined> = TEnum extends [infer TString, ...any[]]
? TString extends `${infer TLiteral}` ? TLiteral extends any ? true
: false
: false
: false;
export type ColumnIsGeneratedAlwaysAs<TColumn extends Column> = TColumn['_']['identity'] extends 'always' ? true
: TColumn['_']['generated'] extends undefined ? false
: TColumn['_']['generated'] extends infer TGenerated extends { type: string }
? TGenerated['type'] extends 'byDefault' ? false
: true
: true;
export type RemoveNever<T> = {
[K in keyof T as T[K] extends never ? never : K]: T[K];
};
export type GetSelection<T extends SelectedFieldsFlat<Column> | Table | View> = T extends Table ? T['_']['columns']
: T extends View ? T['_']['selectedFields']
: T;