@lightningkite/ktor-batteries
Version:
67 lines • 4.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LiveWriteModelApi = void 0;
// Package: com.lightningkite.ktordb.live
// Generated by Khrysalis - this file will be overwritten.
const WriteModelApi_1 = require("../WriteModelApi");
const rxjs_plus_1 = require("@lightningkite/rxjs-plus");
const rxjs_1 = require("rxjs");
const operators_1 = require("rxjs/operators");
//! Declares com.lightningkite.ktordb.live.LiveWriteModelApi
class LiveWriteModelApi extends WriteModelApi_1.WriteModelApi {
constructor(url, token, headers, serializer) {
var _a;
super();
this.url = url;
this.serializer = serializer;
this.authHeaders = (_a = (() => {
if (token === null || token === undefined) {
return null;
}
return ((it) => (new Map([...headers, ...new Map([["Authorization", `Bearer ${it}`]])])))(token);
})()) !== null && _a !== void 0 ? _a : headers;
}
post(value) {
return rxjs_plus_1.HttpClient.INSTANCE.call(this.url, rxjs_plus_1.HttpClient.INSTANCE.POST, this.authHeaders, rxjs_plus_1.HttpBody.json(value), undefined).pipe(rxjs_plus_1.unsuccessfulAsError, (0, rxjs_plus_1.fromJSON)(this.serializer));
}
postBulk(values) {
return rxjs_plus_1.HttpClient.INSTANCE.call(`${this.url}/bulk`, rxjs_plus_1.HttpClient.INSTANCE.POST, this.authHeaders, rxjs_plus_1.HttpBody.json(values), undefined).pipe(rxjs_plus_1.unsuccessfulAsError, (0, rxjs_plus_1.fromJSON)([Array, this.serializer]));
}
upsert(value, id) {
return rxjs_plus_1.HttpClient.INSTANCE.call(`${this.url}/${value._id}`, rxjs_plus_1.HttpClient.INSTANCE.POST, this.authHeaders, rxjs_plus_1.HttpBody.json(value), undefined).pipe(rxjs_plus_1.unsuccessfulAsError, (0, rxjs_plus_1.fromJSON)(this.serializer));
}
put(value) {
return rxjs_plus_1.HttpClient.INSTANCE.call(`${this.url}/${value._id}`, rxjs_plus_1.HttpClient.INSTANCE.PUT, this.authHeaders, rxjs_plus_1.HttpBody.json(value), undefined).pipe(rxjs_plus_1.unsuccessfulAsError, (0, rxjs_plus_1.fromJSON)(this.serializer));
}
putBulk(values) {
return rxjs_plus_1.HttpClient.INSTANCE.call(`${this.url}/bulk`, rxjs_plus_1.HttpClient.INSTANCE.PUT, this.authHeaders, rxjs_plus_1.HttpBody.json(values), undefined).pipe(rxjs_plus_1.unsuccessfulAsError, (0, rxjs_plus_1.fromJSON)([Array, this.serializer]));
}
patch(id, modification) {
return rxjs_plus_1.HttpClient.INSTANCE.call(`${this.url}/${id}`, rxjs_plus_1.HttpClient.INSTANCE.PATCH, this.authHeaders, rxjs_plus_1.HttpBody.json(modification), undefined).pipe(rxjs_plus_1.unsuccessfulAsError, (0, rxjs_plus_1.fromJSON)(this.serializer));
}
patchBulk(modification) {
return rxjs_plus_1.HttpClient.INSTANCE.call(`${this.url}/bulk`, rxjs_plus_1.HttpClient.INSTANCE.PATCH, this.authHeaders, rxjs_plus_1.HttpBody.json(modification), undefined)
.pipe((0, operators_1.mergeMap)((it) => ((0, rxjs_1.from)(it.text()))))
.pipe((0, operators_1.map)((it) => (parseInt(it))));
}
_delete(id) {
return rxjs_plus_1.HttpClient.INSTANCE.call(`${this.url}/${id}`, rxjs_plus_1.HttpClient.INSTANCE.DELETE, this.authHeaders, undefined, undefined).pipe(rxjs_plus_1.unsuccessfulAsError, (0, rxjs_1.switchMap)(x => x.text().then(x => undefined)));
}
deleteBulk(condition) {
return rxjs_plus_1.HttpClient.INSTANCE.call(`${this.url}/bulk`, rxjs_plus_1.HttpClient.INSTANCE.DELETE, this.authHeaders, rxjs_plus_1.HttpBody.json(condition), undefined).pipe(rxjs_plus_1.unsuccessfulAsError, (0, rxjs_1.switchMap)(x => x.text().then(x => undefined)));
}
}
exports.LiveWriteModelApi = LiveWriteModelApi;
(function (LiveWriteModelApi) {
//! Declares com.lightningkite.ktordb.live.LiveWriteModelApi.Companion
class Companion {
constructor() {
}
create(Model, root, path, token, headers = new Map([])) {
return new LiveWriteModelApi(`${root}${path}`, token, headers, Model);
}
}
Companion.INSTANCE = new Companion();
LiveWriteModelApi.Companion = Companion;
})(LiveWriteModelApi = exports.LiveWriteModelApi || (exports.LiveWriteModelApi = {}));
//# sourceMappingURL=LiveWriteModelApi.js.map