@qbraid-core/jobs
Version:
Client for the qBraid Quantum Jobs service.
158 lines • 5.83 kB
JavaScript
;
// Copyright (c) 2025, qBraid Development Team
// All rights reserved.
Object.defineProperty(exports, "__esModule", { value: true });
exports.QuantumJobsClientV1 = exports.QuantumJobsClient = void 0;
const base_1 = require("@qbraid-core/base");
const base_2 = require("@qbraid-core/base");
class QuantumJobsClient extends base_1.QbraidClient {
constructor(session) {
super(session);
}
async getJobs(params) {
const queryTags = params?.tags?.reduce((accumulator, tag) => {
// reducer function for tags
accumulator[`tags.${tag.key}`] = tag.value;
return accumulator;
},
// object definition and type
{});
if (params) {
delete params.tags;
}
const finalParams = { ...params, ...queryTags };
const response = await this.session.client.get(`/quantum-jobs`, {
params: finalParams,
});
return response.data;
}
async deleteJob(jobId) {
const response = await this.session.client.delete(`/quantum-jobs/${jobId}`);
return response.data;
}
async deleteMultipleJobs(jobIdArray) {
const commaSeparatedIds = jobIdArray.join(',');
const response = await this.session.client.delete(`/quantum-jobs?ids=${commaSeparatedIds}`, {
data: { jobIdArray },
});
return response.data;
}
async cancelJobs(jobId) {
const response = await this.session.client.put(`/quantum-jobs/cancel/${jobId}`);
return response.data;
}
}
exports.QuantumJobsClient = QuantumJobsClient;
class QuantumJobsClientV1 extends base_2.QbraidClientV1 {
// NOTE: the QbraidSessionV1 object might change as we introduce the
// microservice architecture for the V1 API. For now, we go through
// the new api, so we have the same pattern as devices
constructor(session) {
super(session);
}
/**
* Get jobs from the V1 API.
* @param params - Optional query parameters to filter jobs
* @returns Array of PlatformJob objects
*/
async getJobs(params) {
const response = await this.session.client.get('/jobs', { params });
return response?.data ?? [];
}
/**
* Delete a single job by its QRN.
* @param jobQrn - The job QRN to delete
* @returns Delete response
*/
async deleteJob(jobQrn) {
const response = await this.session.client.delete(`/jobs/${jobQrn}`);
return response?.data ?? { message: 'Unknown error' };
}
/**
* Delete multiple jobs by their QRNs.
* @param jobQrns - Array of job QRNs to delete
* @returns Delete response with lists of deleted and failed jobs
*/
async deleteMultipleJobs(jobQrns) {
const response = await this.session.client.delete('/jobs', {
params: { qrns: JSON.stringify(jobQrns) },
});
return response?.data ?? { message: 'Unknown error' };
}
/**
* Cancel a job by its QRN.
* @param jobQrn - The job QRN to cancel
* @returns Cancel response
*/
async cancelJob(jobQrn) {
const response = await this.session.client.post(`/jobs/${jobQrn}/cancel`);
return response?.data?.data ?? { message: 'Unknown error' };
}
/**
* Get the result of a completed job.
* @param jobQrn - The job QRN to get results for
* @returns Job result with status, cost, timestamps, and result data
*/
async getJobResult(jobQrn) {
const response = await this.session.client.get(`/jobs/${jobQrn}/result`);
return response.data;
}
/**
* Get the program/circuit data for a job.
* @param jobQrn - The job QRN to get program for
* @returns Program data with format and circuit string
*/
async getJobProgram(jobQrn) {
const response = await this.session.client.get(`/jobs/${jobQrn}/program`);
return response.data.data;
}
/**
* Get the status list of all jobs.
* @returns Job status response with counts of jobs in various statuses
*/
async getJobsStatuses() {
const response = await this.session.client.get('/jobs/statuses');
return response.data.data;
}
/**
* Get all job groups.
* @param params - Optional query parameters to filter groups
* @returns List of group jobs
*/
async getGroups(params) {
const response = await this.session.client.get('/jobs/group', { params });
return response?.data ?? { success: false, data: [], meta: { timestamp: '' } };
}
/**
* Get all jobs within a group.
* @param groupQrn - The group QRN to get jobs for
* @returns List of platform jobs in the group
*/
async getGroupJobs(groupQrn) {
const response = await this.session.client.get(`/jobs/group/${encodeURIComponent(groupQrn)}/jobs`);
return response?.data ?? { success: false, data: [], meta: { timestamp: '' } };
}
/**
* Delete a job group.
* @param groupQrn - The group QRN to delete
* @returns Delete response
*/
async deleteGroup(groupQrn) {
const response = await this.session.client.delete(`/jobs/group/${encodeURIComponent(groupQrn)}`);
return response?.data ?? { message: 'Unknown error' };
}
/**
* Cancel a job group.
* @param groupQrn - The group QRN to cancel
* @returns Updated group job
*/
async cancelGroup(groupQrn) {
const response = await this.session.client.post(`/jobs/group/${encodeURIComponent(groupQrn)}/cancel`);
if (!response?.data) {
throw new Error('Failed to cancel group: no response data');
}
return response.data;
}
}
exports.QuantumJobsClientV1 = QuantumJobsClientV1;
//# sourceMappingURL=client.js.map