Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Add types declaration file (resolve #46) #51

Closed
wants to merge 6 commits into from
Closed
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
33 changes: 33 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Model, Page } from 'objection-2';

declare module 'objection-hashid' {
class HashIdQueryBuilder<M extends Model, R = M[]> {
ArrayQueryBuilderType: HashIdQueryBuilder<M, M[]>;
SingleQueryBuilderType: HashIdQueryBuilder<M, M>;
NumberQueryBuilderType: HashIdQueryBuilder<M, number>;
PageQueryBuilderType: HashIdQueryBuilder<M, Page<M>>;

findByHashId: (hashId: string) => this['SingleQueryBuilderType'] & M['QueryBuilderType']['SingleQueryBuilderType'];
}

interface HashIdInstance<T extends typeof Model> {
QueryBuilderType: HashIdQueryBuilder<this & T['prototype']>;

hashid: string;
hashId: string;
}

interface HashIdStatic<T extends typeof Model> {
QueryBuilder: typeof HashIdQueryBuilder;
hashIdSalt: string;
hashIdMinLength: number | void;
hashIdAlphabet: string | void;
hashIdSeps: string | void;
hashIdField: string | boolean;
hashedFields: Array<string>;

new(): HashIdInstance<T> & T['prototype'];
}

export default function hashid<T extends typeof Model>(model: T): HashIdStatic<T> & Omit<T, 'new'> & T['prototype'];
}