@panyam/tsutils
Version:
Some basic TS utils for personal use
55 lines • 2.48 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
const axios = require("axios").default;
export class ResourceApi {
create(params) {
return __awaiter(this, void 0, void 0, function* () {
const url = this.urlForCreate(params);
const response = yield axios.post(url, this.processCreateParams(params));
return this.processCreateResponse(response);
});
}
batchGet(...resIds) {
return __awaiter(this, void 0, void 0, function* () {
const url = this.urlForBatchGet(resIds);
const response = yield axios.get(url);
return this.processBatchGetResponse(response);
});
}
get(resId, params) {
return __awaiter(this, void 0, void 0, function* () {
const url = this.urlForGet(resId, params);
const response = yield axios.get(url);
return this.processGetResponse(response);
});
}
list(params) {
return __awaiter(this, void 0, void 0, function* () {
const url = this.urlForList(params);
const response = yield axios.get(url);
return this.processListResponse(response);
});
}
update(resId, params) {
return __awaiter(this, void 0, void 0, function* () {
const url = this.urlForUpdate(resId, params);
const response = yield axios.put(url, this.processUpdateParams(params));
return this.processUpdateResponse(response);
});
}
delete(resId, params) {
return __awaiter(this, void 0, void 0, function* () {
const url = this.urlForDelete(resId, params);
const response = yield axios({ method: "delete", url: url });
return this.processDeleteResponse(response);
});
}
}
//# sourceMappingURL=promiseapis.js.map