@oasislabs/parcel
Advanced tools
Comparing version
@@ -9,2 +9,9 @@ import type { Opaque } from 'type-fest'; | ||
/** | ||
* Filters for specifying the subset of jobs to be listed/fetched. | ||
*/ | ||
export declare type ListJobsFilter = { | ||
/** Selects jobs that were submitted by this identity. */ | ||
submitter?: IdentityId; | ||
}; | ||
/** | ||
* Input document for a compute job. | ||
@@ -107,6 +114,12 @@ */ | ||
/** | ||
* Most recently observed status of the pod. This data may not be up to | ||
* date. The data type is a mostly subset of [Kubernetes' | ||
* PodStatus](https://www.k8sref.io/docs/workloads/pod-v1/#podstatus). | ||
* Most recently observed status of the pod. May be missing if the job is no | ||
* longer tracked by the system; this will typically happen for older jobs. | ||
* This data may not be up to date. The data type is a mostly subset of | ||
* [Kubernetes' PodStatus](https://www.k8sref.io/docs/workloads/pod-v1/#podstatus). | ||
*/ | ||
status?: JobStatus; | ||
}>; | ||
export declare type PODJobStatusReport = Readonly<PODModel & { | ||
id: JobId; | ||
/** Most recently observed status of the pod. */ | ||
status: JobStatus; | ||
@@ -122,5 +135,14 @@ }>; | ||
readonly spec: JobSpec; | ||
readonly status: JobStatus; | ||
readonly status?: JobStatus; | ||
constructor(client: HttpClient, pod: PODJob); | ||
} | ||
/** | ||
* An existing, already-submitted job. The job might also be already completed. | ||
*/ | ||
export declare class JobStatusReport { | ||
#private; | ||
readonly id: JobId; | ||
readonly status: JobStatus; | ||
constructor(client: HttpClient, pod: PODJobStatusReport); | ||
} | ||
export declare namespace ComputeImpl { | ||
@@ -130,3 +152,4 @@ function submitJob(client: HttpClient, spec: JobSpec): Promise<Job>; | ||
function getJob(client: HttpClient, jobId: JobId): Promise<Job>; | ||
function getJobStatus(client: HttpClient, jobId: JobId): Promise<JobStatusReport>; | ||
function terminateJob(client: HttpClient, jobId: JobId): Promise<void>; | ||
} |
@@ -8,3 +8,3 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { | ||
}; | ||
var _client; | ||
var _client, _client_1; | ||
import { makePage } from './model.js'; | ||
@@ -32,5 +32,18 @@ export var JobPhase; | ||
_client = new WeakMap(); | ||
/** | ||
* An existing, already-submitted job. The job might also be already completed. | ||
*/ | ||
export class JobStatusReport { | ||
constructor(client, pod) { | ||
_client_1.set(this, void 0); | ||
__classPrivateFieldSet(this, _client_1, client); | ||
this.id = pod.id; | ||
this.status = pod.status; | ||
} | ||
} | ||
_client_1 = new WeakMap(); | ||
const COMPUTE_EP = 'compute'; | ||
const JOBS_EP = `${COMPUTE_EP}/jobs`; | ||
const endpointForId = (id) => `${JOBS_EP}/${id}`; | ||
const statusEndpointForId = (id) => `${JOBS_EP}/${id}/status`; | ||
export var ComputeImpl; | ||
@@ -53,2 +66,7 @@ (function (ComputeImpl) { | ||
ComputeImpl.getJob = getJob; | ||
async function getJobStatus(client, jobId) { | ||
const pod = await client.get(statusEndpointForId(jobId)); | ||
return new JobStatusReport(client, pod); | ||
} | ||
ComputeImpl.getJobStatus = getJobStatus; | ||
async function terminateJob(client, jobId) { | ||
@@ -55,0 +73,0 @@ return client.delete(endpointForId(jobId)); |
@@ -31,3 +31,3 @@ import type { Primitive } from 'type-fest'; | ||
type AccessTime = { | ||
access_time: number; | ||
accessTime: RelationalOp<string>; | ||
}; | ||
@@ -34,0 +34,0 @@ type WorkerId = { |
@@ -13,3 +13,3 @@ import type { Opaque } from 'type-fest'; | ||
condition?: Condition; | ||
capabilities?: string; | ||
capabilities: string; | ||
delegating?: ResourceId; | ||
@@ -16,0 +16,0 @@ }>; |
@@ -49,3 +49,3 @@ var _a, _b, _c; | ||
if (isApiErrorResponse(res)) { | ||
throw new ApiError(req, opts, res, (await res.json()).error); | ||
throw new ApiError(req, opts, res, `Error from ${req.url}: ${(await res.json()).error}`); | ||
} | ||
@@ -52,0 +52,0 @@ const expectedStatus = (_a = req.expectedStatus) !== null && _a !== void 0 ? _a : EXPECTED_RESPONSE_CODES.get(req.method); |
import type { Merge, Opaque, SetOptional } from 'type-fest'; | ||
import type { AppId } from './app.js'; | ||
import { Grant } from './grant.js'; | ||
import type { HttpClient } from './http.js'; | ||
@@ -20,3 +21,3 @@ import type { Model, Page, PageParams, PODModel, ResourceId, Writable } from './model.js'; | ||
delete(): Promise<void>; | ||
grantPermission(id: PermissionId): Promise<void>; | ||
grantPermission(id: PermissionId): Promise<GrantedPermission>; | ||
/** Fetches permissions to which this identity has agreed. */ | ||
@@ -34,3 +35,4 @@ listGrantedPermissions(filter?: ListGrantedPermissionsFilter & PageParams): Promise<Page<Permission>>; | ||
function delete_(client: HttpClient, id: IdentityId): Promise<void>; | ||
function grantPermission(client: HttpClient, identityId: IdentityId, permissionId: PermissionId): Promise<void>; | ||
/** Grants permission to an app. */ | ||
function grantPermission(client: HttpClient, identityId: IdentityId, permissionId: PermissionId): Promise<GrantedPermission>; | ||
function listGrantedPermissions(client: HttpClient, identityId: IdentityId, filter?: ListGrantedPermissionsFilter & PageParams): Promise<Page<Permission>>; | ||
@@ -52,1 +54,6 @@ function getGrantedPermission(client: HttpClient, identityId: IdentityId, permissionId: PermissionId): Promise<Permission>; | ||
}>; | ||
/** The outcome of granting a permission to an app. */ | ||
export declare type GrantedPermission = { | ||
/** The actual grants created as a result of accepting the permission. */ | ||
grants: Grant[]; | ||
}; |
@@ -15,3 +15,3 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { | ||
var _client; | ||
import { setExpectedStatus } from './http.js'; | ||
import { Grant } from './grant.js'; | ||
import { Permission } from './permission.js'; | ||
@@ -80,8 +80,8 @@ const IDENTITIES_EP = 'identities'; | ||
IdentityImpl.delete_ = delete_; | ||
/** Grants permission to an app. */ | ||
async function grantPermission(client, identityId, permissionId) { | ||
await client.post(endpointForPermission(identityId, permissionId), undefined, { | ||
hooks: { | ||
beforeRequest: [setExpectedStatus(204)], | ||
}, | ||
}); | ||
const { grants } = await client.create(endpointForPermission(identityId, permissionId), {}); | ||
return { | ||
grants: grants.map((g) => new Grant(client, g)), | ||
}; | ||
} | ||
@@ -88,0 +88,0 @@ IdentityImpl.grantPermission = grantPermission; |
import type { App, AppCreateParams, AppId, AppUpdateParams, ListAppsFilter } from './app.js'; | ||
import type { Client, ClientCreateParams, ClientId, ClientUpdateParams, ListClientsFilter } from './client.js'; | ||
import type { Job, JobId, JobSpec, JobStatus } from './compute.js'; | ||
import { InputDocumentSpec, JobPhase, OutputDocument, OutputDocumentSpec } from './compute.js'; | ||
import type { Job, JobId, JobSpec, JobStatus, JobStatusReport } from './compute.js'; | ||
import { InputDocumentSpec, JobPhase, ListJobsFilter, OutputDocument, OutputDocumentSpec } from './compute.js'; | ||
import type { AccessEvent, Document, DocumentId, DocumentUpdateParams, DocumentUploadParams, ListAccessLogFilter, ListDocumentsFilter, Storable, Upload } from './document.js'; | ||
import type { Capabilities, Grant, GrantCreateParams, GrantId } from './grant.js'; | ||
import { ListGrantsFilter } from './grant.js'; | ||
import type { Grant, GrantCreateParams, GrantId } from './grant.js'; | ||
import { Capabilities, ListGrantsFilter } from './grant.js'; | ||
import type { Config as ClientConfig, Download } from './http.js'; | ||
import { ApiError } from './http.js'; | ||
import type { Identity, IdentityCreateParams, IdentityId, IdentityUpdateParams } from './identity.js'; | ||
import type { GrantedPermission, Identity, IdentityCreateParams, IdentityId, IdentityUpdateParams } from './identity.js'; | ||
import type { Page, PageParams } from './model.js'; | ||
@@ -15,3 +15,3 @@ import type { Permission, PermissionCreateParams, PermissionId } from './permission.js'; | ||
import { PARCEL_RUNTIME_AUD } from './token.js'; | ||
export { AccessEvent, ApiError, App, AppCreateParams, AppId, AppUpdateParams, Capabilities, Client, ClientCreateParams, ClientCredentials, ClientId, Document, DocumentId, DocumentUpdateParams, DocumentUploadParams, Download, Grant, GrantCreateParams, GrantId, Identity, IdentityCreateParams, IdentityId, IdentityUpdateParams, InputDocumentSpec, Job, JobId, JobPhase, JobSpec, JobStatus, OutputDocument, OutputDocumentSpec, PARCEL_RUNTIME_AUD, Page, PageParams, Permission, PermissionCreateParams, PermissionId, PrivateJWK, PublicJWK, RefreshingTokenProviderParams, RenewingTokenProviderParams, Scope, SelfIssuedTokenProviderParams, Storable, TokenSource, }; | ||
export { AccessEvent, ApiError, App, AppCreateParams, AppId, AppUpdateParams, Capabilities, Client, ClientCreateParams, ClientCredentials, ClientId, Document, DocumentId, DocumentUpdateParams, DocumentUploadParams, Download, Grant, GrantCreateParams, GrantId, GrantedPermission, Identity, IdentityCreateParams, IdentityId, IdentityUpdateParams, InputDocumentSpec, Job, JobId, JobPhase, JobSpec, JobStatus, JobStatusReport, OutputDocument, OutputDocumentSpec, PARCEL_RUNTIME_AUD, Page, PageParams, Permission, PermissionCreateParams, PermissionId, PrivateJWK, PublicJWK, RefreshingTokenProviderParams, RenewingTokenProviderParams, Scope, SelfIssuedTokenProviderParams, Storable, TokenSource, }; | ||
export default class Parcel { | ||
@@ -55,7 +55,7 @@ private currentIdentity?; | ||
/** | ||
* Lists all known jobs owned by the current user. The dispatcher keeps track of jobs for at most 24h after they complete. | ||
* Lists all known jobs visible to the current user. | ||
* @param filter Controls pagination. | ||
* @result Job Lists known jobs. Includes recently completed jobs. | ||
*/ | ||
listJobs(filter?: PageParams): Promise<Page<Job>>; | ||
listJobs(filter?: ListJobsFilter & PageParams): Promise<Page<Job>>; | ||
/** | ||
@@ -66,2 +66,7 @@ * Returns the full description of a known job, including its status. | ||
/** | ||
* Returns the status of the job. This method is faster than `getJob()` and throws if the | ||
* job status is unknown. This makes it well suited for status polling. | ||
*/ | ||
getJobStatus(jobId: JobId): Promise<JobStatusReport>; | ||
/** | ||
* Schedules the job for eventual termination/deletion. The job will be terminated at some point in the future on a best-effort basis. | ||
@@ -68,0 +73,0 @@ * It is not an error to request to terminate an already-terminated or non-existing job. |
@@ -5,3 +5,3 @@ import { AppImpl } from './app.js'; | ||
import { DocumentImpl } from './document.js'; | ||
import { GrantImpl } from './grant.js'; | ||
import { Capabilities, GrantImpl } from './grant.js'; | ||
import { ApiError, HttpClient } from './http.js'; | ||
@@ -11,3 +11,3 @@ import { IdentityImpl } from './identity.js'; | ||
import { TokenProvider, PARCEL_RUNTIME_AUD } from './token.js'; | ||
export { ApiError, JobPhase, PARCEL_RUNTIME_AUD, }; | ||
export { ApiError, Capabilities, JobPhase, PARCEL_RUNTIME_AUD, }; | ||
export default class Parcel { | ||
@@ -114,3 +114,3 @@ constructor(tokenSource, config) { | ||
/** | ||
* Lists all known jobs owned by the current user. The dispatcher keeps track of jobs for at most 24h after they complete. | ||
* Lists all known jobs visible to the current user. | ||
* @param filter Controls pagination. | ||
@@ -129,2 +129,9 @@ * @result Job Lists known jobs. Includes recently completed jobs. | ||
/** | ||
* Returns the status of the job. This method is faster than `getJob()` and throws if the | ||
* job status is unknown. This makes it well suited for status polling. | ||
*/ | ||
async getJobStatus(jobId) { | ||
return ComputeImpl.getJobStatus(this.client, jobId); | ||
} | ||
/** | ||
* Schedules the job for eventual termination/deletion. The job will be terminated at some point in the future on a best-effort basis. | ||
@@ -131,0 +138,0 @@ * It is not an error to request to terminate an already-terminated or non-existing job. |
{ | ||
"name": "@oasislabs/parcel", | ||
"version": "1.0.0-beta.3", | ||
"version": "1.0.0-beta.4", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "author": "Oasis Labs <feedback@oasislabs.com>", |
@@ -12,2 +12,10 @@ import type { Opaque } from 'type-fest'; | ||
/** | ||
* Filters for specifying the subset of jobs to be listed/fetched. | ||
*/ | ||
export type ListJobsFilter = { | ||
/** Selects jobs that were submitted by this identity. */ | ||
submitter?: IdentityId; | ||
}; | ||
/** | ||
* Input document for a compute job. | ||
@@ -126,6 +134,15 @@ */ | ||
/** | ||
* Most recently observed status of the pod. This data may not be up to | ||
* date. The data type is a mostly subset of [Kubernetes' | ||
* PodStatus](https://www.k8sref.io/docs/workloads/pod-v1/#podstatus). | ||
* Most recently observed status of the pod. May be missing if the job is no | ||
* longer tracked by the system; this will typically happen for older jobs. | ||
* This data may not be up to date. The data type is a mostly subset of | ||
* [Kubernetes' PodStatus](https://www.k8sref.io/docs/workloads/pod-v1/#podstatus). | ||
*/ | ||
status?: JobStatus; | ||
} | ||
>; | ||
export type PODJobStatusReport = Readonly< | ||
PODModel & { | ||
id: JobId; | ||
/** Most recently observed status of the pod. */ | ||
status: JobStatus; | ||
@@ -142,3 +159,3 @@ } | ||
public readonly spec: JobSpec; | ||
public readonly status: JobStatus; | ||
public readonly status?: JobStatus; | ||
@@ -156,5 +173,22 @@ #client: HttpClient; | ||
/** | ||
* An existing, already-submitted job. The job might also be already completed. | ||
*/ | ||
export class JobStatusReport { | ||
public readonly id: JobId; | ||
public readonly status: JobStatus; | ||
#client: HttpClient; | ||
public constructor(client: HttpClient, pod: PODJobStatusReport) { | ||
this.#client = client; | ||
this.id = pod.id; | ||
this.status = pod.status; | ||
} | ||
} | ||
const COMPUTE_EP = 'compute'; | ||
const JOBS_EP = `${COMPUTE_EP}/jobs`; | ||
const endpointForId = (id: JobId) => `${JOBS_EP}/${id}`; | ||
const statusEndpointForId = (id: JobId) => `${JOBS_EP}/${id}/status`; | ||
@@ -177,2 +211,7 @@ export namespace ComputeImpl { | ||
export async function getJobStatus(client: HttpClient, jobId: JobId): Promise<JobStatusReport> { | ||
const pod = await client.get<PODJobStatusReport>(statusEndpointForId(jobId)); | ||
return new JobStatusReport(client, pod); | ||
} | ||
export async function terminateJob(client: HttpClient, jobId: JobId): Promise<void> { | ||
@@ -179,0 +218,0 @@ return client.delete(endpointForId(jobId)); |
@@ -40,3 +40,3 @@ import type { Primitive } from 'type-fest'; | ||
export type AccessTime = { | ||
access_time: number; // TODO: This should be a Date, but Date is not currently serializable as a JsonObject. | ||
accessTime: RelationalOp<string>; // TODO: This should be a Date, but Date is not currently serializable as a JsonObject. | ||
}; | ||
@@ -43,0 +43,0 @@ // Environment-based selectors. |
@@ -18,3 +18,3 @@ import type { Opaque } from 'type-fest'; | ||
condition?: Condition; | ||
capabilities?: string; | ||
capabilities: string; | ||
delegating?: ResourceId; | ||
@@ -21,0 +21,0 @@ } |
@@ -70,3 +70,8 @@ import type { WriteStream } from 'fs'; | ||
if (isApiErrorResponse(res)) { | ||
throw new ApiError(req, opts, res, (await res.json()).error); | ||
throw new ApiError( | ||
req, | ||
opts, | ||
res, | ||
`Error from ${req.url}: ${(await res.json()).error}`, | ||
); | ||
} | ||
@@ -73,0 +78,0 @@ |
import type { Merge, Opaque, SetOptional } from 'type-fest'; | ||
import type { AppId } from './app.js'; | ||
import type { PODGrant } from './grant.js'; | ||
import { Grant } from './grant.js'; | ||
import type { HttpClient } from './http.js'; | ||
import { setExpectedStatus } from './http.js'; | ||
import type { Model, Page, PageParams, PODModel, ResourceId, Writable } from './model.js'; | ||
@@ -49,3 +50,3 @@ import { Permission } from './permission.js'; | ||
public async grantPermission(id: PermissionId): Promise<void> { | ||
public async grantPermission(id: PermissionId): Promise<GrantedPermission> { | ||
return IdentityImpl.grantPermission(this.#client, this.id, id); | ||
@@ -103,2 +104,3 @@ } | ||
/** Grants permission to an app. */ | ||
export async function grantPermission( | ||
@@ -108,8 +110,10 @@ client: HttpClient, | ||
permissionId: PermissionId, | ||
): Promise<void> { | ||
await client.post(endpointForPermission(identityId, permissionId), undefined, { | ||
hooks: { | ||
beforeRequest: [setExpectedStatus(204)], | ||
}, | ||
}); | ||
): Promise<GrantedPermission> { | ||
const { grants } = await client.create<PODGrantedPermission>( | ||
endpointForPermission(identityId, permissionId), | ||
{}, | ||
); | ||
return { | ||
grants: grants.map((g) => new Grant(client, g)), | ||
}; | ||
} | ||
@@ -171,1 +175,11 @@ | ||
}>; | ||
type PODGrantedPermission = { | ||
grants: PODGrant[]; | ||
}; | ||
/** The outcome of granting a permission to an app. */ | ||
export type GrantedPermission = { | ||
/** The actual grants created as a result of accepting the permission. */ | ||
grants: Grant[]; | ||
}; |
@@ -10,3 +10,3 @@ import type { App, AppCreateParams, AppId, AppUpdateParams, ListAppsFilter } from './app.js'; | ||
} from './client.js'; | ||
import type { Job, JobId, JobSpec, JobStatus } from './compute.js'; | ||
import type { Job, JobId, JobSpec, JobStatus, JobStatusReport } from './compute.js'; | ||
import { | ||
@@ -16,2 +16,3 @@ ComputeImpl, | ||
JobPhase, | ||
ListJobsFilter, | ||
OutputDocument, | ||
@@ -33,7 +34,8 @@ OutputDocumentSpec, | ||
import { DocumentImpl } from './document.js'; | ||
import type { Capabilities, Grant, GrantCreateParams, GrantId } from './grant.js'; | ||
import { GrantImpl, ListGrantsFilter } from './grant.js'; | ||
import type { Grant, GrantCreateParams, GrantId } from './grant.js'; | ||
import { Capabilities, GrantImpl, ListGrantsFilter } from './grant.js'; | ||
import type { Config as ClientConfig, Download } from './http.js'; | ||
import { ApiError, HttpClient } from './http.js'; | ||
import type { | ||
GrantedPermission, | ||
Identity, | ||
@@ -80,2 +82,3 @@ IdentityCreateParams, | ||
GrantId, | ||
GrantedPermission, | ||
Identity, | ||
@@ -91,2 +94,3 @@ IdentityCreateParams, | ||
JobStatus, | ||
JobStatusReport, | ||
OutputDocument, | ||
@@ -254,7 +258,7 @@ OutputDocumentSpec, | ||
/** | ||
* Lists all known jobs owned by the current user. The dispatcher keeps track of jobs for at most 24h after they complete. | ||
* Lists all known jobs visible to the current user. | ||
* @param filter Controls pagination. | ||
* @result Job Lists known jobs. Includes recently completed jobs. | ||
*/ | ||
public async listJobs(filter: PageParams = {}): Promise<Page<Job>> { | ||
public async listJobs(filter: ListJobsFilter & PageParams = {}): Promise<Page<Job>> { | ||
return ComputeImpl.listJobs(this.client, filter); | ||
@@ -271,2 +275,10 @@ } | ||
/** | ||
* Returns the status of the job. This method is faster than `getJob()` and throws if the | ||
* job status is unknown. This makes it well suited for status polling. | ||
*/ | ||
public async getJobStatus(jobId: JobId): Promise<JobStatusReport> { | ||
return ComputeImpl.getJobStatus(this.client, jobId); | ||
} | ||
/** | ||
* Schedules the job for eventual termination/deletion. The job will be terminated at some point in the future on a best-effort basis. | ||
@@ -273,0 +285,0 @@ * It is not an error to request to terminate an already-terminated or non-existing job. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
217581
2.39%4445
2.8%