import { QelosSDKOptions } from './types'; import BaseSDK from './base-sdk'; import type { IBlueprint } from '@qelos/global-types'; import QlBlueprintEntities from './blueprints-entities'; // Empty by design — extended via TypeScript declaration merging from // generated `.d.ts` files (`qelos interfaces build`) so `entitiesOf("todo")` // resolves to the typed entity without callers passing a generic. export interface BlueprintEntitiesRegistry {} export default class QlBlueprints extends BaseSDK { private relativePath = '/api/blueprints'; #entities = new Map(); constructor(private options: QelosSDKOptions) { super(options) } getBlueprint(key: string) { return this.callJsonApi(`${this.relativePath}/${key}`) } getList() { return this.callJsonApi(this.relativePath); } entitiesOf(blueprintKey: K): QlBlueprintEntities; entitiesOf(blueprintKey: string): QlBlueprintEntities; entitiesOf(blueprintKey: string): QlBlueprintEntities { if (!this.#entities.has(blueprintKey)) { this.#entities.set(blueprintKey, new QlBlueprintEntities(this.options, blueprintKey)); } return this.#entities.get(blueprintKey); } getChart(blueprintKey: string, chartType: string, query?: Record) { const qs = this.getQueryParams(query); return this.callJsonApi>(`${this.relativePath}/${blueprintKey}/charts/${chartType}${qs}`); } getPieChart(blueprintKey: string, query?: Record) { const qs = this.getQueryParams(query); return this.callJsonApi>(`${this.relativePath}/${blueprintKey}/charts/pie${qs}`); } getCount(blueprintKey: string, query?: Record) { const qs = this.getQueryParams(query); return this.callJsonApi<{ count: number }>(`${this.relativePath}/${blueprintKey}/charts/count${qs}`); } getSum(blueprintKey: string, sumProperty: string, groupByProperty?: string, query?: Record) { const qs = this.getQueryParams({ ...query, sum: sumProperty, ...(groupByProperty && { groupBy: groupByProperty }) }); return this.callJsonApi<{ groups?: Array<{ group: any; sum: number }>; sum: number }>(`${this.relativePath}/${blueprintKey}/charts/sum${qs}`); } }