import type { AnyOfSchema, AnySchema, AppendKey, BinarySchema, BooleanSchema, ItemSchema, ListSchema, MapSchema, NullSchema, NumberSchema, Paths, PrimitiveSchema, RecordSchema, ResolveAnySchema, ResolveBinarySchema, ResolveBooleanSchema, ResolveNumberSchema, ResolvePrimitiveSchema, ResolveStringSchema, ResolvedBinarySchema, ResolvedNumberSchema, ResolvedStringSchema, Schema, SetSchema, StringSchema, StringToEscape } from '../../../schema/index.js'; import type { Extends, If } from '../../../types/index.js'; export type AnySchemaCondition = AttrCondition, ALL_PATHS, ResolveAnySchema> | AttrCondition<`${ATTR_PATH}${string}`, Exclude, ALL_PATHS>; export type ConditionType = 'S' | 'SS' | 'N' | 'NS' | 'B' | 'BS' | 'BOOL' | 'NULL' | 'L' | 'M'; export type AttrCondition = (SCHEMA extends AnySchema ? AnySchemaCondition : never) | (SCHEMA extends NullSchema ? NullSchemaCondition : never) | (SCHEMA extends BooleanSchema ? BooleanSchemaCondition : never) | (SCHEMA extends NumberSchema ? NumberSchemaCondition : never) | (SCHEMA extends StringSchema ? StringSchemaCondition : never) | (SCHEMA extends BinarySchema ? BinarySchemaCondition : never) | (SCHEMA extends SetSchema ? SetSchemaCondition : never) | (SCHEMA extends ListSchema ? ListSchemaCondition : never) | (SCHEMA extends MapSchema ? MapSchemaCondition : never) | (SCHEMA extends RecordSchema ? RecordSchemaCondition : never) | (SCHEMA extends AnyOfSchema ? AnyOfSchemaCondition : never); export type ExistsCondition = { attr: ATTR_PATH; exists: boolean; }; export type TypeCondition = { attr: ATTR_PATH; type: ConditionType; }; export type EqCondition = { attr: ATTR_PATH; eq: ATTR_VALUE | { attr: ALL_PATHS; } | CUSTOM_VALUE; transform?: boolean; }; type SizeEqCondition = { size: ATTR_PATH; eq: number | { attr: ALL_PATHS; }; }; export type NotEqCondition = { attr: ATTR_PATH; ne: ATTR_VALUE | { attr: ALL_PATHS; } | CUSTOM_VALUE; transform?: boolean; }; type SizeNotEqCondition = { size: ATTR_PATH; ne: number | { attr: ALL_PATHS; }; }; export type InCondition = { attr: ATTR_PATH; in: (ATTR_VALUE | { attr: ALL_PATHS; } | CUSTOM_VALUE)[]; transform?: boolean; }; type SizeInCondition = { size: ATTR_PATH; in: (number | { attr: ALL_PATHS; })[]; }; export type ValueCondition = EqCondition | NotEqCondition | InCondition; type SizeValueCondition = SizeEqCondition | SizeNotEqCondition | SizeInCondition; export type LessThanCondition = { attr: ATTR_PATH; lt: ATTR_VALUE | { attr: ALL_PATHS; } | CUSTOM_VALUE; transform?: boolean; }; type SizeLessThanCondition = { size: ATTR_PATH; lt: number | { attr: ALL_PATHS; }; }; export type LessThanOrEqCondition = { attr: ATTR_PATH; lte: ATTR_VALUE | { attr: ALL_PATHS; } | CUSTOM_VALUE; transform?: boolean; }; type SizeLessThanOrEqCondition = { size: ATTR_PATH; lte: number | { attr: ALL_PATHS; }; }; export type GreaterThanCondition = { attr: ATTR_PATH; gt: ATTR_VALUE | { attr: ALL_PATHS; } | CUSTOM_VALUE; transform?: boolean; }; type SizeGreaterThanCondition = { size: ATTR_PATH; gt: number | { attr: ALL_PATHS; }; }; export type GreaterThanOrEqCondition = { attr: ATTR_PATH; gte: ATTR_VALUE | { attr: ALL_PATHS; } | CUSTOM_VALUE; transform?: boolean; }; type SizeGreaterThanOrEqCondition = { size: ATTR_PATH; gte: number | { attr: ALL_PATHS; }; }; export type BetweenCondition = { attr: ATTR_PATH; between: [ ATTR_VALUE | { attr: ALL_PATHS; } | CUSTOM_VALUE, ATTR_VALUE | { attr: ALL_PATHS; } | CUSTOM_VALUE ]; transform?: boolean; }; type SizeBetweenCondition = { size: ATTR_PATH; between: [number | { attr: ALL_PATHS; }, number | { attr: ALL_PATHS; }]; }; export type RangeCondition = LessThanCondition | LessThanOrEqCondition | GreaterThanCondition | GreaterThanOrEqCondition | BetweenCondition; type SizeRangeCondition = SizeLessThanCondition | SizeLessThanOrEqCondition | SizeGreaterThanCondition | SizeGreaterThanOrEqCondition | SizeBetweenCondition; export type SizeCondition = SizeValueCondition | SizeRangeCondition; export type NullSchemaCondition = ExistsCondition | TypeCondition; export type BooleanSchemaCondition = ExistsCondition | TypeCondition | ValueCondition, ALL_PATHS, CUSTOM_VALUE>; export type NumberSchemaCondition = ExistsCondition | TypeCondition | ValueCondition, ALL_PATHS, CUSTOM_VALUE> | RangeCondition; export type ContainsCondition = { attr: ATTR_PATH; contains: ATTR_VALUE | { attr: ALL_PATHS; } | CUSTOM_VALUE; transform?: boolean; }; export type BeginsWithCondition = { attr: ATTR_PATH; beginsWith: ATTR_VALUE | { attr: ALL_PATHS; } | CUSTOM_VALUE; transform?: boolean; }; export type StringSchemaCondition = ExistsCondition | TypeCondition | ValueCondition, ALL_PATHS, CUSTOM_VALUE> | RangeCondition | BeginsWithCondition | ContainsCondition | SizeCondition; export type BinarySchemaCondition = ExistsCondition | TypeCondition | ValueCondition, ALL_PATHS, CUSTOM_VALUE> | RangeCondition | SizeCondition; export type SetSchemaCondition = ExistsCondition | TypeCondition | ContainsCondition, ALL_PATHS> | SizeCondition; export type ListSchemaCondition = ExistsCondition | TypeCondition | (SCHEMA['elements'] extends PrimitiveSchema ? ContainsCondition, ALL_PATHS> : never) | (ListSchema extends SCHEMA ? never : AttrCondition<`${ATTR_PATH}[${number}]`, SCHEMA['elements'], ALL_PATHS>) | SizeCondition; export type MapSchemaCondition = ExistsCondition | TypeCondition | (MapSchema extends SCHEMA ? never : { [KEY in keyof SCHEMA['attributes'] & string]: AttrCondition, SCHEMA['attributes'][KEY], ALL_PATHS>; }[keyof SCHEMA['attributes'] & string]) | SizeCondition; export type RecordSchemaCondition = ExistsCondition | TypeCondition | (RecordSchema extends SCHEMA ? never : AttrCondition>, SCHEMA['elements'], ALL_PATHS>) | SizeCondition; export type AnyOfSchemaCondition = ExistsCondition | TypeCondition | (AnyOfSchema extends SCHEMA ? never : SCHEMA['elements'][number] extends infer ELEMENT ? ELEMENT extends Schema ? AttrCondition : never : never); export type NonLogicalCondition = ItemSchema extends SCHEMA ? FreeCondition | AnySchemaCondition : FreeCondition | (keyof SCHEMA['attributes'] extends infer ATTR_PATH ? ATTR_PATH extends string ? AttrCondition<`['${ATTR_PATH}']` | If, never, ATTR_PATH>, SCHEMA['attributes'][ATTR_PATH], Paths> : never : never); type DdbAttributeValue = null | boolean | number | string | Uint8Array | Set | Set | Set | DdbAttributeValue[] | { [key: string]: DdbAttributeValue; }; type ScalarAttributeValue = number | string | Uint8Array; type ContainersAttributes = string | Set | Set | Set | DdbAttributeValue[]; /** * @debt v3 "Size conditions can be applied to free conditions as well: Rework { size: 'path', eq: 3 } to { attr: 'path', sizeEq: 3 } (=> { value: 3, sizeEq : 3 })" */ export type FreeCondition = FreeTypeCondition | FreeEqCondition | FreeNotEqCondition | FreeInCondition | FreeLessThanCondition | FreeLessThanOrEqCondition | FreeGreaterThanCondition | FreeGreaterThanOrEqCondition | FreeBetweenCondition | FreeBeginsWithCondition | FreeContainsCondition; type FreeTypeCondition = { value: DdbAttributeValue; type: ConditionType; }; type FreeEqCondition = VALUE extends DdbAttributeValue ? { value: VALUE; eq: VALUE; } : never; type FreeNotEqCondition = VALUE extends DdbAttributeValue ? { value: VALUE; ne: VALUE; } : never; type FreeInCondition = VALUE extends DdbAttributeValue ? { value: VALUE; in: VALUE[]; } : never; type FreeLessThanCondition = VALUE extends ScalarAttributeValue ? { value: VALUE; lt: VALUE; } : never; type FreeLessThanOrEqCondition = VALUE extends ScalarAttributeValue ? { value: VALUE; lte: VALUE; } : never; type FreeGreaterThanCondition = VALUE extends ScalarAttributeValue ? { value: VALUE; gt: VALUE; } : never; type FreeGreaterThanOrEqCondition = VALUE extends ScalarAttributeValue ? { value: VALUE; gte: VALUE; } : never; type FreeBetweenCondition = VALUE extends ScalarAttributeValue ? { value: VALUE; between: [VALUE, VALUE]; } : never; type FreeBeginsWithCondition = { value: string; beginsWith: string; }; type FreeContainsCondition = VALUE extends ContainersAttributes ? { value: VALUE; contains: VALUE extends Set ? ELEMENT : VALUE extends (infer ELEMENT)[] ? ELEMENT : VALUE; } : never; export type LogicalCondition = { and: SchemaCondition[]; } | { or: SchemaCondition[]; } | { not: SchemaCondition; }; export type SchemaCondition = LogicalCondition | NonLogicalCondition; export {};