@centia-io/sdk 0.2.15 → 0.2.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -1
- package/dist/centia-io-sdk.cjs +153 -15
- package/dist/centia-io-sdk.d.cts +204 -7
- package/dist/centia-io-sdk.d.cts.map +1 -1
- package/dist/centia-io-sdk.d.ts +204 -7
- package/dist/centia-io-sdk.d.ts.map +1 -1
- package/dist/centia-io-sdk.js +153 -16
- package/dist/centia-io-sdk.js.map +1 -1
- package/dist/centia-io-sdk.umd.js +153 -15
- package/package.json +1 -1
|
@@ -3463,12 +3463,6 @@
|
|
|
3463
3463
|
relationPath(schema, relation, rest = "") {
|
|
3464
3464
|
return `api/v4/schemas/${encodeURIComponent(schema)}/relations/${encodeURIComponent(relation)}/snapshots${rest}`;
|
|
3465
3465
|
}
|
|
3466
|
-
/**
|
|
3467
|
-
* Queue a Parquet snapshot of a table or view. Returns 202 with the job id.
|
|
3468
|
-
* Throws `CentiaApiError`: 403 (super-user only), 404 (relation not found),
|
|
3469
|
-
* 409 (a snapshot of the relation is already pending or running),
|
|
3470
|
-
* 501 (snapshot storage not configured).
|
|
3471
|
-
*/
|
|
3472
3466
|
async postSnapshot(body) {
|
|
3473
3467
|
return this.client.request({
|
|
3474
3468
|
path: "api/v4/snapshots",
|
|
@@ -3477,10 +3471,11 @@
|
|
|
3477
3471
|
expectedStatus: 202
|
|
3478
3472
|
});
|
|
3479
3473
|
}
|
|
3480
|
-
/** Get a snapshot job by id. Super-user only. */
|
|
3481
3474
|
async getSnapshot(id) {
|
|
3482
|
-
|
|
3483
|
-
|
|
3475
|
+
var _this2 = this;
|
|
3476
|
+
const keys = Array.isArray(id) ? id : [id];
|
|
3477
|
+
return _this2.client.request({
|
|
3478
|
+
path: `api/v4/snapshots/${keys.map((k) => encodeURIComponent(k)).join(",")}`,
|
|
3484
3479
|
method: "GET"
|
|
3485
3480
|
});
|
|
3486
3481
|
}
|
|
@@ -3555,24 +3550,46 @@
|
|
|
3555
3550
|
return _this8.rawGet(_this8.relationPath(schema, relation, `/${encodeURIComponent(date)}/data`), "HEAD");
|
|
3556
3551
|
}
|
|
3557
3552
|
/**
|
|
3553
|
+
* Absolute URL of one output format of the snapshot, without fetching it —
|
|
3554
|
+
* for DuckDB/GDAL or a plain fetch.
|
|
3555
|
+
*/
|
|
3556
|
+
getRelationSnapshotDataFormatUrl(schema, relation, date, format) {
|
|
3557
|
+
return `${this.client.baseUrl}/${this.relationPath(schema, relation, `/${encodeURIComponent(date)}/data/${encodeURIComponent(format)}`)}`;
|
|
3558
|
+
}
|
|
3559
|
+
/**
|
|
3560
|
+
* Fetch one output format of the snapshot (Content-Type is the format's
|
|
3561
|
+
* media type). Same redirect/range semantics as getRelationSnapshotData.
|
|
3562
|
+
* Throws `CentiaApiError`: 400 (unknown format id), 404 (no snapshot for
|
|
3563
|
+
* that date, or the format was skipped/not requested), 403, 416, 502.
|
|
3564
|
+
*/
|
|
3565
|
+
async getRelationSnapshotDataFormat(schema, relation, date, format, options) {
|
|
3566
|
+
var _this9 = this;
|
|
3567
|
+
return _this9.rawGet(_this9.relationPath(schema, relation, `/${encodeURIComponent(date)}/data/${encodeURIComponent(format)}`), "GET", options);
|
|
3568
|
+
}
|
|
3569
|
+
/** HEAD request for one output format of the snapshot. */
|
|
3570
|
+
async headRelationSnapshotDataFormat(schema, relation, date, format) {
|
|
3571
|
+
var _this10 = this;
|
|
3572
|
+
return _this10.rawGet(_this10.relationPath(schema, relation, `/${encodeURIComponent(date)}/data/${encodeURIComponent(format)}`), "HEAD");
|
|
3573
|
+
}
|
|
3574
|
+
/**
|
|
3558
3575
|
* Fetch one file of the snapshot by catalog name (`data-<id>.parquet`,
|
|
3559
3576
|
* `metadata-<id>.json`). Same redirect/range semantics as
|
|
3560
3577
|
* getRelationSnapshotData.
|
|
3561
3578
|
*/
|
|
3562
3579
|
async getRelationSnapshotFile(schema, relation, date, file, options) {
|
|
3563
|
-
var
|
|
3564
|
-
return
|
|
3580
|
+
var _this11 = this;
|
|
3581
|
+
return _this11.rawGet(_this11.relationPath(schema, relation, `/${encodeURIComponent(date)}/files/${encodeURIComponent(file)}`), "GET", options);
|
|
3565
3582
|
}
|
|
3566
3583
|
/** HEAD request for one file of the snapshot. */
|
|
3567
3584
|
async headRelationSnapshotFile(schema, relation, date, file) {
|
|
3568
|
-
var
|
|
3569
|
-
return
|
|
3585
|
+
var _this12 = this;
|
|
3586
|
+
return _this12.rawGet(_this12.relationPath(schema, relation, `/${encodeURIComponent(date)}/files/${encodeURIComponent(file)}`), "HEAD");
|
|
3570
3587
|
}
|
|
3571
3588
|
async rawGet(path, method, options) {
|
|
3572
|
-
var
|
|
3589
|
+
var _this13 = this;
|
|
3573
3590
|
const headers = {};
|
|
3574
3591
|
if (options === null || options === void 0 ? void 0 : options.range) headers["Range"] = `bytes=${options.range[0]}-${options.range[1]}`;
|
|
3575
|
-
return
|
|
3592
|
+
return _this13.client.requestRaw({
|
|
3576
3593
|
path,
|
|
3577
3594
|
method,
|
|
3578
3595
|
headers: Object.keys(headers).length > 0 ? headers : void 0,
|
|
@@ -3581,6 +3598,126 @@
|
|
|
3581
3598
|
}
|
|
3582
3599
|
};
|
|
3583
3600
|
|
|
3601
|
+
//#endregion
|
|
3602
|
+
//#region src/scheduler/Scheduler.ts
|
|
3603
|
+
function idsPath(id) {
|
|
3604
|
+
return (Array.isArray(id) ? id : [id]).map((k) => encodeURIComponent(String(k))).join(",");
|
|
3605
|
+
}
|
|
3606
|
+
/**
|
|
3607
|
+
* Client for the scheduler API (`/api/v4/scheduler`). Super-user only.
|
|
3608
|
+
*
|
|
3609
|
+
* Jobs describe recurring data imports (cron-scheduled); runs are their
|
|
3610
|
+
* executions. Starting a run is asynchronous — poll `getSchedulerRuns`
|
|
3611
|
+
* (the `_links.runs` of the 202) until the run finishes.
|
|
3612
|
+
*
|
|
3613
|
+
* ```ts
|
|
3614
|
+
* const scheduler = new Scheduler(createCentiaClient({ baseUrl, auth }));
|
|
3615
|
+
* const { ids } = await scheduler.postSchedulerJob({ name, schema, url, schedule: '0 3 * * *' });
|
|
3616
|
+
* await scheduler.postSchedulerRun({ job: ids[0] });
|
|
3617
|
+
* ```
|
|
3618
|
+
*/
|
|
3619
|
+
var Scheduler = class {
|
|
3620
|
+
constructor(client) {
|
|
3621
|
+
this.client = client;
|
|
3622
|
+
}
|
|
3623
|
+
/** List all scheduler jobs. */
|
|
3624
|
+
async getSchedulerJobs() {
|
|
3625
|
+
return this.client.request({
|
|
3626
|
+
path: "api/v4/scheduler/jobs",
|
|
3627
|
+
method: "GET"
|
|
3628
|
+
});
|
|
3629
|
+
}
|
|
3630
|
+
async getSchedulerJob(id) {
|
|
3631
|
+
return this.client.request({
|
|
3632
|
+
path: `api/v4/scheduler/jobs/${idsPath(id)}`,
|
|
3633
|
+
method: "GET"
|
|
3634
|
+
});
|
|
3635
|
+
}
|
|
3636
|
+
/**
|
|
3637
|
+
* Create one or more jobs (201; all-or-nothing for arrays). Returns the
|
|
3638
|
+
* Location header and the new ids parsed from it, in request order.
|
|
3639
|
+
*/
|
|
3640
|
+
async postSchedulerJob(body) {
|
|
3641
|
+
var _this3 = this;
|
|
3642
|
+
var _res$getHeader, _location$split$pop;
|
|
3643
|
+
const location = (_res$getHeader = (await _this3.client.requestFull({
|
|
3644
|
+
path: "api/v4/scheduler/jobs",
|
|
3645
|
+
method: "POST",
|
|
3646
|
+
body,
|
|
3647
|
+
expectedStatus: 201
|
|
3648
|
+
})).getHeader("Location")) !== null && _res$getHeader !== void 0 ? _res$getHeader : "";
|
|
3649
|
+
return {
|
|
3650
|
+
location,
|
|
3651
|
+
ids: ((_location$split$pop = location.split("/").pop()) !== null && _location$split$pop !== void 0 ? _location$split$pop : "").split(",").map((s) => Number(s)).filter((n) => Number.isFinite(n))
|
|
3652
|
+
};
|
|
3653
|
+
}
|
|
3654
|
+
/** Partially update a job (303 + Location). */
|
|
3655
|
+
async patchSchedulerJob(id, body) {
|
|
3656
|
+
var _this4 = this;
|
|
3657
|
+
var _res$getHeader2;
|
|
3658
|
+
return { location: (_res$getHeader2 = (await _this4.client.requestFull({
|
|
3659
|
+
path: `api/v4/scheduler/jobs/${idsPath(id)}`,
|
|
3660
|
+
method: "PATCH",
|
|
3661
|
+
body,
|
|
3662
|
+
expectedStatus: 303
|
|
3663
|
+
})).getHeader("Location")) !== null && _res$getHeader2 !== void 0 ? _res$getHeader2 : "" };
|
|
3664
|
+
}
|
|
3665
|
+
/**
|
|
3666
|
+
* Delete one or more jobs (204). Nothing is deleted if any id fails:
|
|
3667
|
+
* throws 404 (unknown id) or 409 (a run is in progress).
|
|
3668
|
+
*/
|
|
3669
|
+
async deleteSchedulerJob(id) {
|
|
3670
|
+
await this.client.request({
|
|
3671
|
+
path: `api/v4/scheduler/jobs/${idsPath(id)}`,
|
|
3672
|
+
method: "DELETE",
|
|
3673
|
+
expectedStatus: 204
|
|
3674
|
+
});
|
|
3675
|
+
}
|
|
3676
|
+
/** List runs (running plus the newest 50 finished), optionally filtered by job and status. */
|
|
3677
|
+
async getSchedulerRuns(options) {
|
|
3678
|
+
var _this6 = this;
|
|
3679
|
+
const query = {};
|
|
3680
|
+
if ((options === null || options === void 0 ? void 0 : options.job) !== void 0) query.job = String(options.job);
|
|
3681
|
+
if ((options === null || options === void 0 ? void 0 : options.status) !== void 0) query.status = options.status;
|
|
3682
|
+
return _this6.client.request({
|
|
3683
|
+
path: "api/v4/scheduler/runs",
|
|
3684
|
+
method: "GET",
|
|
3685
|
+
query: Object.keys(query).length > 0 ? query : void 0
|
|
3686
|
+
});
|
|
3687
|
+
}
|
|
3688
|
+
/** Get one run by uuid. */
|
|
3689
|
+
async getSchedulerRun(uuid) {
|
|
3690
|
+
return this.client.request({
|
|
3691
|
+
path: `api/v4/scheduler/runs/${encodeURIComponent(uuid)}`,
|
|
3692
|
+
method: "GET"
|
|
3693
|
+
});
|
|
3694
|
+
}
|
|
3695
|
+
/**
|
|
3696
|
+
* Start a run of a job (202). Throws 404 (unknown job) or 409 (a run of
|
|
3697
|
+
* the job is already running).
|
|
3698
|
+
*/
|
|
3699
|
+
async postSchedulerRun(body) {
|
|
3700
|
+
return this.client.request({
|
|
3701
|
+
path: "api/v4/scheduler/runs",
|
|
3702
|
+
method: "POST",
|
|
3703
|
+
body,
|
|
3704
|
+
expectedStatus: 202
|
|
3705
|
+
});
|
|
3706
|
+
}
|
|
3707
|
+
/**
|
|
3708
|
+
* Stop a running run: sends SIGINT, which the server escalates to SIGKILL
|
|
3709
|
+
* after 30 s — the request itself can take up to ~30 s, so do not use a
|
|
3710
|
+
* short timeout. Throws 404 (no running run with that uuid) or 409 (the
|
|
3711
|
+
* run is on another host).
|
|
3712
|
+
*/
|
|
3713
|
+
async deleteSchedulerRun(uuid) {
|
|
3714
|
+
return this.client.request({
|
|
3715
|
+
path: `api/v4/scheduler/runs/${encodeURIComponent(uuid)}`,
|
|
3716
|
+
method: "DELETE"
|
|
3717
|
+
});
|
|
3718
|
+
}
|
|
3719
|
+
};
|
|
3720
|
+
|
|
3584
3721
|
//#endregion
|
|
3585
3722
|
//#region src/auth/errors.ts
|
|
3586
3723
|
/**
|
|
@@ -3718,6 +3855,7 @@ exports.Ogc = Ogc;
|
|
|
3718
3855
|
exports.Ows = Ows;
|
|
3719
3856
|
exports.PasswordFlow = PasswordFlow;
|
|
3720
3857
|
exports.Rpc = Rpc;
|
|
3858
|
+
exports.Scheduler = Scheduler;
|
|
3721
3859
|
exports.SessionExpiredError = SessionExpiredError;
|
|
3722
3860
|
exports.SignUp = SignUp;
|
|
3723
3861
|
exports.Snapshots = Snapshots;
|