UNPKG

@hf-chimera/store

Version:

Cross-end reactivity API

1 lines 4.51 kB
{"version":3,"file":"qb-D6vPK6P0.cjs","names":["ChimeraOrderNulls","chimeraCreateOrderBy","chimeraCreateConjunction","chimeraCreateOperator","chimeraCreateNot"],"sources":["../packages/qb/index.ts"],"sourcesContent":["import type {\n\tAnyChimeraStore,\n\tChimeraConjunctionDescriptor,\n\tChimeraConjunctionOperationDescriptor,\n\tChimeraConjunctionType,\n\tChimeraFilterDescriptor,\n\tChimeraOrderDescriptor,\n\tChimeraPropertyGetter,\n\tChimeraStoreEntities,\n\tChimeraStoreOperatorMap,\n} from \"../../src\";\nimport {\n\tChimeraOrderNulls,\n\tchimeraCreateConjunction,\n\tchimeraCreateNot,\n\tchimeraCreateOperator,\n\tchimeraCreateOrderBy,\n} from \"../../src\";\nimport type { KeysOfType } from \"../../src/shared/types\";\n\nexport type QueryBuilderCreator<\n\tStore extends AnyChimeraStore,\n\tEntity extends ChimeraStoreEntities<Store>,\n\tOperatorsMap extends ChimeraStoreOperatorMap<Store> = ChimeraStoreOperatorMap<Store>,\n> = (q: ChimeraQueryBuilder<Store, Entity, OperatorsMap>) => any;\n\nexport class ChimeraQueryBuilder<\n\tStore extends AnyChimeraStore,\n\tEntity extends ChimeraStoreEntities<Store>,\n\tOperatorsMap extends ChimeraStoreOperatorMap<Store> = ChimeraStoreOperatorMap<Store>,\n> {\n\tprivate orderRules: ChimeraOrderDescriptor<Entity>[] = [];\n\n\torderBy(\n\t\tkey: ChimeraPropertyGetter<Entity> | (keyof Entity & string),\n\t\tdesc = false,\n\t\tnulls: ChimeraOrderNulls = ChimeraOrderNulls.Last,\n\t): this {\n\t\tthis.orderRules.push(chimeraCreateOrderBy<Entity>(key, desc, nulls));\n\t\treturn this;\n\t}\n\n\tprivate filters: ChimeraConjunctionOperationDescriptor<OperatorsMap, Entity>[] = [];\n\tprivate rootConjunction: Exclude<ChimeraConjunctionType, \"not\"> = \"and\";\n\n\tprivate conjunction(type: Exclude<ChimeraConjunctionType, \"not\">) {\n\t\tthis.rootConjunction = type;\n\t}\n\n\tprivate buildFilter(): ChimeraConjunctionDescriptor<OperatorsMap, Entity> | null {\n\t\treturn this.filters.length\n\t\t\t? chimeraCreateConjunction<Entity, OperatorsMap>(this.rootConjunction, this.filters)\n\t\t\t: null;\n\t}\n\n\twhere<Op extends keyof OperatorsMap & string>(\n\t\tvalue:\n\t\t\t| ChimeraPropertyGetter<Entity, Parameters<OperatorsMap[Op]>[0]>\n\t\t\t| (KeysOfType<Entity, Parameters<OperatorsMap[Op]>[0]> & string),\n\t\top: Op,\n\t\ttest: Parameters<OperatorsMap[Op]>[1],\n\t): this {\n\t\tthis.filters.push(chimeraCreateOperator<Entity, OperatorsMap, Op>(op, value, test));\n\t\treturn this;\n\t}\n\n\tgroup(conjunction: ChimeraConjunctionType, builder: QueryBuilderCreator<Store, Entity, OperatorsMap>): this {\n\t\tconst isNot = conjunction === \"not\";\n\t\tconst nestedBuilder = new ChimeraQueryBuilder<Store, Entity, OperatorsMap>();\n\n\t\t!isNot && nestedBuilder.conjunction(conjunction);\n\n\t\tbuilder(nestedBuilder);\n\n\t\tconst nestedQuery = nestedBuilder.buildFilter();\n\t\tnestedQuery && this.filters.push(isNot ? chimeraCreateNot<Entity, OperatorsMap>(nestedQuery) : nestedQuery);\n\n\t\treturn this;\n\t}\n\n\twhereNot<Op extends keyof OperatorsMap & string>(\n\t\tvalue:\n\t\t\t| ChimeraPropertyGetter<Entity, Parameters<OperatorsMap[Op]>[0]>\n\t\t\t| (KeysOfType<Entity, Parameters<OperatorsMap[Op]>[0]> & string),\n\t\top: Op,\n\t\ttest: Parameters<OperatorsMap[Op]>[1],\n\t): this {\n\t\tthis.filters.push(\n\t\t\tchimeraCreateNot<Entity, OperatorsMap>(chimeraCreateOperator<Entity, OperatorsMap, Op>(op, value, test)),\n\t\t);\n\t\treturn this;\n\t}\n\n\tbuild(): {\n\t\tfilter: ChimeraFilterDescriptor<OperatorsMap, Entity> | null;\n\t\torder: ChimeraOrderDescriptor<Entity>[] | null;\n\t} {\n\t\treturn {\n\t\t\tfilter: this.buildFilter(),\n\t\t\torder: this.orderRules.length ? this.orderRules : null,\n\t\t};\n\t}\n}\n"],"mappings":";;;AA0BA,IAAa,sBAAb,MAAa,oBAIX;CACD,AAAQ,aAA+C,EAAE;CAEzD,QACC,KACA,OAAO,OACP,QAA2BA,8BAAkB,MACtC;AACP,OAAK,WAAW,KAAKC,iCAA6B,KAAK,MAAM,MAAM,CAAC;AACpE,SAAO;;CAGR,AAAQ,UAAyE,EAAE;CACnF,AAAQ,kBAA0D;CAElE,AAAQ,YAAY,MAA8C;AACjE,OAAK,kBAAkB;;CAGxB,AAAQ,cAAyE;AAChF,SAAO,KAAK,QAAQ,SACjBC,qCAA+C,KAAK,iBAAiB,KAAK,QAAQ,GAClF;;CAGJ,MACC,OAGA,IACA,MACO;AACP,OAAK,QAAQ,KAAKC,kCAAgD,IAAI,OAAO,KAAK,CAAC;AACnF,SAAO;;CAGR,MAAM,aAAqC,SAAiE;EAC3G,MAAM,QAAQ,gBAAgB;EAC9B,MAAM,gBAAgB,IAAI,qBAAkD;AAE5E,GAAC,SAAS,cAAc,YAAY,YAAY;AAEhD,UAAQ,cAAc;EAEtB,MAAM,cAAc,cAAc,aAAa;AAC/C,iBAAe,KAAK,QAAQ,KAAK,QAAQC,6BAAuC,YAAY,GAAG,YAAY;AAE3G,SAAO;;CAGR,SACC,OAGA,IACA,MACO;AACP,OAAK,QAAQ,KACZA,6BAAuCD,kCAAgD,IAAI,OAAO,KAAK,CAAC,CACxG;AACD,SAAO;;CAGR,QAGE;AACD,SAAO;GACN,QAAQ,KAAK,aAAa;GAC1B,OAAO,KAAK,WAAW,SAAS,KAAK,aAAa;GAClD"}