@herlinus/coloquent
Version:
Library for retrieving model objects from a JSON-API, with a fluent syntax inspired by Laravel Eloquent.
43 lines • 1.43 kB
JavaScript
import { RetrievalResponse } from "./RetrievalResponse";
export class SingularResponse extends RetrievalResponse {
constructor(query, httpClientResponse, modelType, responseBody) {
super(query, httpClientResponse, modelType, responseBody);
}
getData() {
return this.data;
}
makeModelIndex(data) {
const doc = Array.isArray(data)
?
SingularResponse.coalesceUndefinedIntoNull(data[0])
:
SingularResponse.coalesceUndefinedIntoNull(data);
if (doc) {
this.indexAsModel(doc, this.modelType, this.includeTree);
}
}
indexRequestedResources(data) {
const doc = Array.isArray(data)
?
SingularResponse.coalesceUndefinedIntoNull(data[0])
:
SingularResponse.coalesceUndefinedIntoNull(data);
if (doc) {
this.indexDoc(doc);
}
}
makeDataArray(data) {
const doc = Array.isArray(data)
?
SingularResponse.coalesceUndefinedIntoNull(data[0])
:
SingularResponse.coalesceUndefinedIntoNull(data);
if (doc !== null) {
this.data = this.modelIndex.get(doc.type).get(doc.id);
}
else {
this.data = null;
}
}
}
//# sourceMappingURL=SingularResponse.js.map