-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve select options typing + validation to handle more edge cases
- Loading branch information
Thomas Aribart
committed
Nov 1, 2023
1 parent
6d47096
commit e368009
Showing
4 changed files
with
124 additions
and
11 deletions.
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 |
---|---|---|
@@ -1,18 +1,38 @@ | ||
import type { CapacityOption } from 'v1/commands/constants/options/capacity' | ||
import type { Condition } from 'v1/commands/types/condition' | ||
import type { AnyAttributePath, Condition } from 'v1/commands/types' | ||
import type { EntityV2 } from 'v1/entity' | ||
|
||
import type { SelectOption } from './constants' | ||
import type { | ||
SelectOption, | ||
AllProjectedAttributesSelectOption, | ||
SpecificAttributesSelectOption | ||
} from './constants' | ||
|
||
export type ScanOptions<ENTITIES extends EntityV2 = EntityV2> = { | ||
capacity?: CapacityOption | ||
consistent?: boolean | ||
exclusiveStartKey?: Record<string, unknown> | ||
indexName?: string | ||
limit?: number | ||
select?: SelectOption | ||
filters?: EntityV2 extends ENTITIES | ||
? Record<string, Condition> | ||
: { [ENTITY in ENTITIES as ENTITY['name']]: Condition<ENTITY> } | ||
} & ( | ||
| { segment?: never; totalSegments?: never } | ||
// Either both segment & totalSegments are set, either none | ||
} & ({ segment?: never; totalSegments?: never } | { segment: number; totalSegments: number }) | ||
| { segment: number; totalSegments: number } | ||
) & | ||
( | ||
| { select?: Exclude<SelectOption, AllProjectedAttributesSelectOption>; indexName?: string } | ||
// "ALL_PROJECTED_ATTRIBUTES" is only available if indexName is present | ||
| { select?: SelectOption; indexName: string } | ||
) & | ||
( | ||
| { attributes?: undefined; select?: SelectOption } | ||
// "SPECIFIC_ATTRIBUTES" is the only valid option if projectionExpression is present | ||
| { | ||
attributes: EntityV2 extends ENTITIES | ||
? Record<string, Condition> | ||
: { [ENTITY in ENTITIES as ENTITY['name']]: AnyAttributePath<ENTITY>[] } | ||
select?: SpecificAttributesSelectOption | ||
} | ||
) |
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
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
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