generated from johngeorgewright/ts-module
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add and and or statment constructs
- Loading branch information
1 parent
be2aee2
commit f3981fb
Showing
4 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Statement } from './condition' | ||
import { GTStatement } from './gt' | ||
import { Comparable } from './is' | ||
import { LTStatement } from './lt' | ||
import { NotStatement } from './not' | ||
import { OrStatement } from './or' | ||
|
||
type AndStatementValueItem<T extends Comparable> = | ||
| NotStatement<T> | ||
| GTStatement | ||
| LTStatement | ||
| OrStatement<T> | ||
|
||
type AndStatementValue<T extends Comparable> = AndStatementValueItem<T>[] | ||
|
||
export class AndStatement<T extends Comparable> extends Statement< | ||
AndStatementValue<T> | ||
> { | ||
override statement(prop: string): string { | ||
return `(${this.value | ||
.map((value) => `${value.statement(prop)}`) | ||
.join(' AND ')})` | ||
} | ||
} | ||
|
||
export function And<T extends Comparable>(values: AndStatementValue<T>) { | ||
return new AndStatement(values) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
export * from './and' | ||
export * from './gt' | ||
export * from './in' | ||
export * from './is' | ||
export * from './like' | ||
export * from './lt' | ||
export * from './not' | ||
export * from './null' | ||
export * from './or' | ||
export * from './pql' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { AndStatement } from './and' | ||
import { Statement } from './condition' | ||
import { GTStatement } from './gt' | ||
import { Comparable, Is, IsStatement } from './is' | ||
import { LTStatement } from './lt' | ||
import { NotStatement } from './not' | ||
|
||
type OrStatementValueItem<T extends Comparable> = | ||
| IsStatement<T> | ||
| NotStatement<T> | ||
| GTStatement | ||
| LTStatement | ||
| AndStatement<T> | ||
|
||
type OrStatementValue<T extends Comparable> = OrStatementValueItem<T>[] | ||
|
||
type OrValue<T extends Comparable> = (OrStatementValueItem<T> | T)[] | ||
|
||
export class OrStatement<T extends Comparable> extends Statement< | ||
OrStatementValue<T> | ||
> { | ||
constructor(values: OrValue<T>) { | ||
super( | ||
values.map((value) => (value instanceof Statement ? value : Is(value))), | ||
) | ||
} | ||
|
||
override statement(prop: string): string { | ||
return `(${this.value.map((value) => value.statement(prop)).join(' OR ')})` | ||
} | ||
} | ||
|
||
export function Or<T extends Comparable>(values: OrValue<T>) { | ||
return new OrStatement(values) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters