Skip to content

Commit

Permalink
fix typings
Browse files Browse the repository at this point in the history
  • Loading branch information
mindler-olli committed Mar 18, 2024
1 parent 36b1eb3 commit 1b1b0ec
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 56 deletions.
120 changes: 72 additions & 48 deletions src/queryBuilders/expressionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,61 +389,85 @@ export interface ExpressionBuilderInterfaceWithOnlyExpressionOperations<
_getNode(): ExpressionNode;
}

export type ComparatorExprArg<DDB, Table extends keyof DDB, Key> = [
key: Key,
operation: ExpressionConditionComparators,
value: StripKeys<GetFromPath<DDB[Table], Key>>
];

export type AttributeFuncExprArg<Key> = [
key: Key,
func: Extract<FunctionExpression, "attribute_exists" | "attribute_not_exists">
];

export type AttributeBeginsWithExprArg<Key> = [
key: Key,
func: Extract<FunctionExpression, "begins_with">,
substr: string
];

export type AttributeContainsExprArg<DDB, Table extends keyof DDB, Key> = [
key: Key,
expr: Extract<FunctionExpression, "contains">,
value: GetFromPath<DDB[Table], Key> extends unknown[]
? StripKeys<GetFromPath<DDB[Table], Key>>[number]
: never
];

export type AttributeBetweenExprArg<DDB, Table extends keyof DDB, Key> = [
key: Key,
expr: BetweenExpression,
left: StripKeys<GetFromPath<DDB[Table], Key>>,
right: StripKeys<GetFromPath<DDB[Table], Key>>
];

export type NotExprArg<
DDB,
Table extends keyof DDB,
O,
AllowKeysInExpression = true
> = [
not: NotExpression,
builder: (
qb: ExpressionBuilderInterfaceWithOnlyExpressionOperations<
DDB,
Table,
O,
AllowKeysInExpression
>
) => ExpressionBuilderInterfaceWithOnlyExpressionOperations<DDB, Table, O>
];

export type BuilderExprArg<
DDB,
Table extends keyof DDB,
O,
AllowKeysInExpression = true
> = [
builder: (
qb: ExpressionBuilderInterfaceWithOnlyExpressionOperations<
DDB,
Table,
O,
AllowKeysInExpression
>
) => ExpressionBuilderInterfaceWithOnlyExpressionOperations<DDB, Table, O>
];

export type ExprArgs<
DDB,
Table extends keyof DDB,
O,
Key,
AllowKeysInExpression = true
> =
| [
key: Key,
operation: ExpressionConditionComparators,
value: StripKeys<GetFromPath<DDB[Table], Key>>
]
| [
key: Exclude<Key, "NOT">,
func: Extract<
FunctionExpression,
"attribute_exists" | "attribute_not_exists"
>
]
| [key: Key, func: Extract<FunctionExpression, "begins_with">, substr: string]
| [
key: Key,
expr: Extract<FunctionExpression, "contains">,
value: GetFromPath<DDB[Table], Key> extends unknown[]
? StripKeys<GetFromPath<DDB[Table], Key>>[number]
: never
]
| [
key: Key,
expr: BetweenExpression,
left: StripKeys<GetFromPath<DDB[Table], Key>>,
right: StripKeys<GetFromPath<DDB[Table], Key>>
]
| [
not: NotExpression,
builder: (
qb: ExpressionBuilderInterfaceWithOnlyExpressionOperations<
DDB,
Table,
O,
AllowKeysInExpression
>
) => ExpressionBuilderInterfaceWithOnlyExpressionOperations<DDB, Table, O>
]
| [
builder: (
qb: ExpressionBuilderInterfaceWithOnlyExpressionOperations<
DDB,
Table,
O,
AllowKeysInExpression
>
) => ExpressionBuilderInterfaceWithOnlyExpressionOperations<DDB, Table, O>
];

| ComparatorExprArg<DDB, Table, Key>
| AttributeFuncExprArg<Key>
| AttributeBeginsWithExprArg<Key>
| AttributeContainsExprArg<DDB, Table, Key>
| AttributeBetweenExprArg<DDB, Table, Key>
| BuilderExprArg<DDB, Table, O, AllowKeysInExpression>
| NotExprArg<DDB, Table, O, AllowKeysInExpression>;
export class ExpressionBuilder<
DDB,
Table extends keyof DDB,
Expand Down
66 changes: 63 additions & 3 deletions src/queryBuilders/putItemQueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,75 @@ import { QueryCompiler } from "../queryCompiler";
import { ExecuteOutput, ObjectKeyPaths, PickNonKeys } from "../typeHelpers";
import { preventAwait } from "../util/preventAwait";
import { ReturnValuesOptions } from "../nodes/returnValuesNode";
import { ExprArgs, ExpressionBuilder } from "./expressionBuilder";
import {
AttributeBeginsWithExprArg,
AttributeBetweenExprArg,
AttributeContainsExprArg,
AttributeFuncExprArg,
BuilderExprArg,
ComparatorExprArg,
ExprArgs,
ExpressionBuilder,
NotExprArg,
} from "./expressionBuilder";

export interface PutItemQueryBuilderInterface<DDB, Table extends keyof DDB, O> {
// conditionExpression
conditionExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: ExprArgs<DDB, Table, O, Key>
...args: ComparatorExprArg<DDB, Table, Key>
): PutItemQueryBuilderInterface<DDB, Table, O>;

conditionExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: AttributeFuncExprArg<Key>
): PutItemQueryBuilderInterface<DDB, Table, O>;

conditionExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: AttributeBeginsWithExprArg<Key>
): PutItemQueryBuilderInterface<DDB, Table, O>;

conditionExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: AttributeContainsExprArg<DDB, Table, Key>
): PutItemQueryBuilderInterface<DDB, Table, O>;

conditionExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: AttributeBetweenExprArg<DDB, Table, Key>
): PutItemQueryBuilderInterface<DDB, Table, O>;

conditionExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: NotExprArg<DDB, Table, Key>
): PutItemQueryBuilderInterface<DDB, Table, O>;

conditionExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: BuilderExprArg<DDB, Table, Key>
): PutItemQueryBuilderInterface<DDB, Table, O>;

// orConditionExpression
orConditionExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: ExprArgs<DDB, Table, O, Key>
...args: ComparatorExprArg<DDB, Table, Key>
): PutItemQueryBuilderInterface<DDB, Table, O>;

orConditionExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: AttributeFuncExprArg<Key>
): PutItemQueryBuilderInterface<DDB, Table, O>;

orConditionExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: AttributeBeginsWithExprArg<Key>
): PutItemQueryBuilderInterface<DDB, Table, O>;

orConditionExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: AttributeContainsExprArg<DDB, Table, Key>
): PutItemQueryBuilderInterface<DDB, Table, O>;

orConditionExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: AttributeBetweenExprArg<DDB, Table, Key>
): PutItemQueryBuilderInterface<DDB, Table, O>;

orConditionExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: NotExprArg<DDB, Table, Key>
): PutItemQueryBuilderInterface<DDB, Table, O>;

orConditionExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: BuilderExprArg<DDB, Table, Key>
): PutItemQueryBuilderInterface<DDB, Table, O>;

returnValues(
Expand Down
60 changes: 55 additions & 5 deletions src/queryBuilders/queryQueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,65 @@ import {
StripKeys,
} from "../typeHelpers";
import { preventAwait } from "../util/preventAwait";
import { ExprArgs, ExpressionBuilder } from "./expressionBuilder";
import { AttributeBeginsWithExprArg, AttributeBetweenExprArg, AttributeContainsExprArg, AttributeFuncExprArg, BuilderExprArg, ComparatorExprArg, ExprArgs, ExpressionBuilder, NotExprArg } from "./expressionBuilder";

export interface QueryQueryBuilderInterface<DDB, Table extends keyof DDB, O> {
filterExpression<Key extends ObjectKeyPaths<PickNonKeys<DDB[Table]>>>(
...args: ExprArgs<DDB, Table, O, Key, false>
// filterExpression
filterExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: ComparatorExprArg<DDB, Table, Key>
): QueryQueryBuilderInterface<DDB, Table, O>;

orFilterExpression<Key extends ObjectKeyPaths<PickNonKeys<DDB[Table]>>>(
...args: ExprArgs<DDB, Table, O, Key, false>
filterExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: AttributeFuncExprArg<Key>
): QueryQueryBuilderInterface<DDB, Table, O>;

filterExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: AttributeBeginsWithExprArg<Key>
): QueryQueryBuilderInterface<DDB, Table, O>;

filterExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: AttributeContainsExprArg<DDB, Table, Key>
): QueryQueryBuilderInterface<DDB, Table, O>;

filterExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: AttributeBetweenExprArg<DDB, Table, Key>
): QueryQueryBuilderInterface<DDB, Table, O>;

filterExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: NotExprArg<DDB, Table, Key>
): QueryQueryBuilderInterface<DDB, Table, O>;

filterExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: BuilderExprArg<DDB, Table, Key>
): QueryQueryBuilderInterface<DDB, Table, O>;

// orFilterExpression
orFilterExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: ComparatorExprArg<DDB, Table, Key>
): QueryQueryBuilderInterface<DDB, Table, O>;

orFilterExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: AttributeFuncExprArg<Key>
): QueryQueryBuilderInterface<DDB, Table, O>;

orFilterExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: AttributeBeginsWithExprArg<Key>
): QueryQueryBuilderInterface<DDB, Table, O>;

orFilterExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: AttributeContainsExprArg<DDB, Table, Key>
): QueryQueryBuilderInterface<DDB, Table, O>;

orFilterExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: AttributeBetweenExprArg<DDB, Table, Key>
): QueryQueryBuilderInterface<DDB, Table, O>;

orFilterExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: NotExprArg<DDB, Table, Key>
): QueryQueryBuilderInterface<DDB, Table, O>;

orFilterExpression<Key extends ObjectKeyPaths<DDB[Table]>>(
...args: BuilderExprArg<DDB, Table, Key>
): QueryQueryBuilderInterface<DDB, Table, O>;

/**
Expand Down

0 comments on commit 1b1b0ec

Please sign in to comment.