UNPKG

@thisisagile/easy

Version:

Straightforward library for building domain-driven microservice architectures

1 lines 1.97 kB
{"version":3,"sources":["../src/sql/Clause.ts"],"sourcesContent":["import { isBoolean, isNumber } from '../types/Is';\nimport { convert, Convert } from '../utils/Convert';\nimport { TypeGuard } from '../types/TypeGuard';\nimport { isA } from '../types/IsA';\nimport type { Text } from '../types/Text';\n\nexport const quote = (a: unknown): string => (isNumber(a) || isBoolean(a) || isClause(a) ? a.toString() : `'${a as string}'`);\n\nexport class Clause implements Text {\n constructor(\n readonly first: unknown,\n readonly operator: string,\n readonly second: unknown\n ) {}\n\n and = (other: Clause): Clause => new ParathesizedClause(this, 'AND', other);\n or = (other: Clause): Clause => new ParathesizedClause(this, 'OR', other);\n\n toString(): string {\n return `${this.first} ${this.operator} ${quote(this.second)}`;\n }\n}\n\nexport class ParathesizedClause extends Clause {\n toString(): string {\n return `(${this.first} ${this.operator} ${quote(this.second)})`;\n }\n}\n\nexport const toClause = (first: unknown, operator: string, second: unknown, conv: Convert = convert.default): Clause =>\n new Clause(first, operator, conv.from(second));\n\nexport const isClause: TypeGuard<Clause> = (c?: unknown): c is Clause => isA<Clause>(c, 'and', 'or');\n"],"mappings":";;;;;;;;;;;;AAMO,IAAM,QAAQ,CAAC,MAAwB,SAAS,CAAC,KAAK,UAAU,CAAC,KAAK,SAAS,CAAC,IAAI,EAAE,SAAS,IAAI,IAAI,CAAW;AAElH,IAAM,SAAN,MAA6B;AAAA,EAClC,YACW,OACA,UACA,QACT;AAHS;AACA;AACA;AAAA,EACR;AAAA,EAEH,MAAM,CAAC,UAA0B,IAAI,mBAAmB,MAAM,OAAO,KAAK;AAAA,EAC1E,KAAK,CAAC,UAA0B,IAAI,mBAAmB,MAAM,MAAM,KAAK;AAAA,EAExE,WAAmB;AACjB,WAAO,GAAG,KAAK,KAAK,IAAI,KAAK,QAAQ,IAAI,MAAM,KAAK,MAAM,CAAC;AAAA,EAC7D;AACF;AAEO,IAAM,qBAAN,cAAiC,OAAO;AAAA,EAC7C,WAAmB;AACjB,WAAO,IAAI,KAAK,KAAK,IAAI,KAAK,QAAQ,IAAI,MAAM,KAAK,MAAM,CAAC;AAAA,EAC9D;AACF;AAEO,IAAM,WAAW,CAAC,OAAgB,UAAkB,QAAiB,OAAgB,QAAQ,YAClG,IAAI,OAAO,OAAO,UAAU,KAAK,KAAK,MAAM,CAAC;AAExC,IAAM,WAA8B,CAAC,MAA6B,IAAY,GAAG,OAAO,IAAI;","names":[]}