import { EnumShape, ShapeVisitor, TypeShape, UnionShape, Value } from '@punchcard/shape'; import { ArrayShape, MapShape, SetShape } from '@punchcard/shape/lib/collection'; import { AnyShape, BinaryShape, BoolShape, NothingShape, NumberShape, StringShape, TimestampShape } from '@punchcard/shape/lib/primitive'; import { Shape } from '@punchcard/shape/lib/shape'; import { AttributeValue } from './attribute'; import { Writer } from './writer'; export declare namespace DSL { type Tag = typeof Tag; const Tag: unique symbol; type Of = T extends BinaryShape ? DSL.Binary : T extends BoolShape ? DSL.Bool : T extends AnyShape ? DSL.Any : T extends NumberShape ? DSL.Number : T extends StringShape ? DSL.String : T extends TimestampShape ? DSL.Timestamp : T extends UnionShape ? U extends 1 ? { [i in Extract]: Of; }[1] : NothingShape extends Extract], NothingShape> ? U['length'] extends 1 ? DSL.Object : U['length'] extends 2 ? Exclude<{ [i in Extract]: Of; }[Extract], DSL.Object> : DSL.Union : DSL.Union : T extends EnumShape ? Enum : T extends TypeShape ? DSL.Struct : T extends MapShape ? DSL.Map : T extends SetShape ? DSL.Set : T extends ArrayShape ? DSL.List : T extends { [Tag]: infer Q; } ? Q : DSL.Object; type Root> = Struct['fields']; function of>(shape: T): Root; function _of(shape: T, expr: ExpressionNode): Of; const DslVisitor: ShapeVisitor>; } export declare namespace DSL { const isNode: (a: any) => a is Node; type Expression = ExpressionNode | Value.Of; const NodeType: unique symbol; const SubNodeType: unique symbol; const DataType: unique symbol; const InstanceExpression: unique symbol; const Synthesize: unique symbol; abstract class Node { readonly [NodeType]: T; constructor(nodeType: T); abstract [Synthesize](writer: Writer): void; } function isStatementNode(a: any): a is StatementNode; abstract class StatementNode extends Node<'statement'> { abstract [SubNodeType]: string; constructor(); } abstract class ExpressionNode extends Node<'expression'> { readonly [DataType]: S; abstract readonly [SubNodeType]: string; constructor(shape: S); } class Id extends ExpressionNode { readonly value: string; readonly [SubNodeType] = "identifier"; constructor(value: string); [Synthesize](writer: Writer): void; } function isLiteral(a: any): a is Literal; class Literal extends ExpressionNode { readonly value: Value.Of>; readonly [SubNodeType] = "literal"; constructor(type: T, value: Value.Of>); [Synthesize](writer: Writer): void; } class RootProperty extends ExpressionNode { readonly name: string; [SubNodeType]: string; constructor(type: T, name: string); [Synthesize](writer: Writer): void; } class FunctionCall extends ExpressionNode { readonly name: string; readonly returnType: T; readonly parameters: ExpressionNode[]; [SubNodeType]: string; constructor(name: string, returnType: T, parameters: ExpressionNode[]); [Synthesize](writer: Writer): void; } class Object extends ExpressionNode { readonly [SubNodeType] = "object"; readonly [InstanceExpression]: ExpressionNode; constructor(type: T, instanceExpression: ExpressionNode); [Synthesize](writer: Writer): void; equals(other: Expression): Bool; get size(): Number; set(value: Expression | Computation): Action; exists(): Bool; notExists(): Bool; } namespace Object { function beginsWith(lhs: Expression, rhs: Expression): Bool; class Assign extends StatementNode { private readonly instance; private readonly value; [SubNodeType]: string; constructor(instance: Object, value: Node); [Synthesize](writer: Writer): void; } abstract class Comparison extends ExpressionNode { readonly left: ExpressionNode; readonly right: ExpressionNode; protected abstract operator: string; constructor(left: ExpressionNode, right: ExpressionNode); [Synthesize](writer: Writer): void; } class Equals extends Object.Comparison { protected readonly operator: '='; readonly [SubNodeType] = "equals"; } } function size(path: Object): Size; class Size extends FunctionCall { constructor(path: Object); } class Bool extends Object { constructor(expression: ExpressionNode, boolShape?: BoolShape); and(...conditions: Expression[]): Bool; or(...conditions: Expression[]): Bool; not(): Bool; } namespace Bool { abstract class Operands extends ExpressionNode { readonly operands: ExpressionNode[]; abstract readonly operator: string; constructor(operands: ExpressionNode[]); [Synthesize](writer: Writer): void; } class And extends Operands { readonly operator = "AND"; [SubNodeType]: 'and'; } class Or extends Operands { readonly operator = "OR"; [SubNodeType]: 'or'; } class Not extends ExpressionNode { readonly operand: ExpressionNode; [SubNodeType]: 'not'; constructor(operand: ExpressionNode); [Synthesize](writer: Writer): void; } } function or(...operands: ExpressionNode[]): Bool; function and(...operands: ExpressionNode[]): Bool; function not(operand: ExpressionNode): Bool; class Ord extends Object { greaterThan(other: Expression): Bool; greaterThanOrEqual(other: Expression): Bool; lessThan(other: Expression): Bool; lessThanOrEqual(other: Expression): Bool; between(lowerBound: Expression, upperBound: Expression): Bool; } namespace Ord { class Gt extends Object.Comparison { protected readonly operator: '>'; readonly [SubNodeType] = "greaterThan"; } class Gte extends Object.Comparison { protected readonly operator: '>='; readonly [SubNodeType] = "greaterThanOrEqual"; } class Lt extends Object.Comparison { protected readonly operator: '<'; readonly [SubNodeType] = "lessThan"; } class Lte extends Object.Comparison { protected readonly operator: '<='; readonly [SubNodeType] = "lessThanOrEqual"; } class Between extends ExpressionNode { readonly lhs: ExpressionNode; readonly lowerBound: ExpressionNode; readonly upperBound: ExpressionNode; readonly [SubNodeType] = "between"; constructor(lhs: ExpressionNode, lowerBound: ExpressionNode, upperBound: ExpressionNode); [Synthesize](writer: Writer): void; } } function isComputation(a: any): a is Computation; /** * Computations are not Expressions, although they do represent a value. * * This is because they are not usable within Query or Filter expressions. * * E.g. this is impossible: * ``` * table.putIf(.., item => item.plus(1).equals(2)) * ``` */ abstract class Computation extends StatementNode { readonly lhs: ExpressionNode; readonly rhs: ExpressionNode; readonly [SubNodeType] = "computation"; abstract readonly operator: string; constructor(lhs: ExpressionNode, rhs: ExpressionNode); [Synthesize](writer: Writer): void; } class ComputationExpression extends ExpressionNode { readonly computation: Computation; [SubNodeType]: string; constructor(shape: T, computation: Computation); [Synthesize](writer: Writer): void; } enum ActionType { SET = "SET" } class Action { readonly actionType: ActionType; readonly statement: StatementNode; constructor(actionType: ActionType, statement: StatementNode); } /** * Represents a number in a DynamoDB Filter, Query or Update expression. */ class Number extends Ord { constructor(expression: ExpressionNode, shape?: NumberShape); decrement(value?: Expression): Action; increment(value?: Expression): Action; minus(value: Expression): Number.Minus; plus(value: Expression): Number.Plus; } namespace Number { class Plus extends Computation { operator: '+'; } class Minus extends Computation { operator: '-'; } } class Binary extends Object { } class StringLike extends Ord { beginsWith(value: Expression): Bool; get length(): Number; } class String extends StringLike { constructor(expression: ExpressionNode, shape?: StringShape); } namespace String { class BeginsWith extends FunctionCall { readonly [SubNodeType] = "string-begins-with"; constructor(lhs: ExpressionNode, rhs: ExpressionNode); } function beginsWith(lhs: Expression, rhs: Expression): Bool; } class Timestamp extends Object { constructor(expression: ExpressionNode, shape?: TimestampShape); } class Enum extends StringLike { } class List extends Object> { constructor(type: ArrayShape, expression: ExpressionNode>); [index: number]: Of; get length(): Number; get(index: Expression): Of; push(item: Expression): Action; concat(list: Expression>): Action; } namespace List { class Item extends ExpressionNode { readonly list: List; readonly index: ExpressionNode; readonly [SubNodeType] = "list-item"; constructor(list: List, index: ExpressionNode); [Synthesize](writer: Writer): void; } class Append extends FunctionCall> { readonly list: List; readonly values: List; [SubNodeType]: 'list-append'; constructor(list: List, values: List); } } class Set extends Object> { contains(value: Expression): Bool; } namespace Set { class Contains extends FunctionCall { constructor(set: Set, value: ExpressionNode); } } class Map extends Object> { get(key: Expression): Of; put(key: Expression, value: Expression): Action; } namespace Map { class GetValue extends ExpressionNode { readonly map: Map; readonly key: ExpressionNode; readonly [SubNodeType] = "map-value"; constructor(map: Map, key: ExpressionNode); [Synthesize](writer: Writer): void; } } class Struct> extends Object { readonly fields: { [fieldName in keyof T['Members']]: Of; }; constructor(type: T, expression: ExpressionNode); } namespace Struct { class Field extends ExpressionNode { readonly struct: Struct; readonly name: string; readonly [SubNodeType] = "struct-field"; constructor(struct: Struct, type: T, name: string); [Synthesize](writer: Writer): void; } } class Any extends Object { as(shape: S): DSL.Of; equals(args: never): never; set(args: never): never; } class Union> extends Object { as]>(shape: S): DSL.Of; } } //# sourceMappingURL=dsl.d.ts.map