Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update typescript definitions to support node16 mode. #26

Merged
merged 1 commit into from
Oct 26, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
package-lock.json
.nyc_output
.vscode
.idea
41 changes: 26 additions & 15 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface TsqueryOptions {
declare namespace tsquery {
export interface TsqueryOptions {
word?: RegExp; // regex for a word. It must contain named captures: word (required), quote (optional), phrase (optional), negated (optional)
negated?: RegExp; // regex to detect if the expression following an operator is negated, this is useful for example with 'foo!bar', you can parse it as foo&!bar by adding the negation as part of and
quotedWordSep?: RegExp; // regex for word delimiters inside quotes
Expand All @@ -10,9 +11,9 @@ export interface TsqueryOptions {
prefix?: RegExp; // regex for detecting `prefix` operator (placed at the end of a word to match words starting like it)
tailOp?: string; // default operator to use with tail (unparsed suffix of the query, if any)
singleQuoteReplacement?: string; // should not be a reserved word like <()|&!]|:\*
}
}

interface BaseNode<T extends string | undefined> {
interface BaseNode<T extends string | undefined> {
readonly type: T;
readonly negated: boolean | undefined;
readonly left: TsqueryNode | undefined;
Expand All @@ -21,44 +22,54 @@ interface BaseNode<T extends string | undefined> {
readonly prefix: string | undefined;
readonly quoted: boolean | undefined;
toString(): string;
}
}

export interface AndNode extends BaseNode<"&"> {
export interface AndNode extends BaseNode<"&"> {
readonly left: TsqueryNode;
readonly right: TsqueryNode;
readonly value: undefined;
readonly prefix: undefined;
readonly quoted: undefined;
}
export interface OrNode extends BaseNode<"|"> {
}

export interface OrNode extends BaseNode<"|"> {
readonly left: TsqueryNode;
readonly right: TsqueryNode;
readonly value: undefined;
readonly prefix: undefined;
readonly quoted: undefined;
}
}

export interface FollowedByNode extends BaseNode<`<${"-" | number}>`> {
export interface FollowedByNode extends BaseNode<`<${"-" | number}>`> {
readonly left: WordNode;
readonly right: WordNode;
readonly value: undefined;
readonly prefix: undefined;
readonly quoted: undefined;
}
}

export interface WordNode extends BaseNode<undefined> {
export interface WordNode extends BaseNode<undefined> {
readonly value: string;
readonly left: undefined;
readonly right: undefined;
readonly quoted: boolean;
}
}

export type TsqueryNode = AndNode | OrNode | FollowedByNode | WordNode;
export type TsqueryNode = AndNode | OrNode | FollowedByNode | WordNode;

export class Tsquery {
export class Tsquery {
constructor(options?: TsqueryOptions);
parseAndStringify(str: string): string;
parse(str: string): TsqueryNode | undefined;
}
}

declare function tsquery(options?: tsquery.TsqueryOptions): (str: string) => string;

interface tsquery {
(options?: tsquery.TsqueryOptions): (str: string) => string;
Tsquery: tsquery.Tsquery;
Node: tsquery.TsqueryNode;
}

export default function (options?: TsqueryOptions): (str: string) => string;
export = tsquery;
Loading