| 2 | import {Loader} from "./types" |
| 3 | |
| 4 | export class QueryLoader implements Loader { |
| 5 | constructor(private ctx: LoadContext) {} |
| 6 | |
| 7 | when() { |
| 8 | return this.ctx.files.length === 0 && !!this.ctx.query |
| 9 | } |
| 10 | |
| 11 | async run() { |
| 12 | this.ctx.setProgress(Infinity) |
| 13 | const client = await this.ctx.createClient() |
| 14 | await client |
| 15 | .query(this.loadQuery, {signal: this.ctx.signal}) |
| 16 | .then((r) => r.js()) |
| 17 | this.ctx.setProgress(1) |
| 18 | } |
| 19 | |
| 20 | private get loadQuery() { |
| 21 | // This is the load op syntax |
| 22 | // load <pool>[@<branch>] [author <author>] [message <message>] [meta <meta>] |
| 23 | return [ |
| 24 | this.ctx.query, |
| 25 | "| load", |
| 26 | this.ctx.poolId + "@" + this.ctx.branch, |
| 27 | "author " + JSON.stringify(this.ctx.author), |
| 28 | "message " + JSON.stringify(this.ctx.body), |
| 29 | ].join(" ") |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | export function addLoad(query: string, poolId) { |
| 34 | return query + " | load " + poolId |
nothing calls this directly
no outgoing calls
no test coverage detected