@hokuto/jam-node
Version:
JAM Node TS, guardians and utils
94 lines (93 loc) • 3.73 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SearchViewBoxApi = exports.SearchFeatureApi = exports.SearchBaseApi = exports.fetchAtlasSvg = exports.fetchMapSvg = exports.fetchAtlasImage = exports.fetchMapImage = exports.fetchUpload = exports.fetchBlob = exports.fetchJSON = void 0;
const jam_core_1 = require("@hokuto/jam-core");
const types_js_1 = require("../types.js");
const api_fetch_js_1 = require("../utils/api-fetch.js");
const params_js_1 = require("./params.js");
function fetchJSON(coreApi, method = types_js_1.ApiMethod.Get) {
return function fetchJSON(args) {
const url = coreApi(args);
const headers = jam_core_1.CoreApi.Options.getRequestOptions(args);
const { values: params } = args;
return (0, api_fetch_js_1.jsonFetch)(url, { headers, method, params });
};
}
exports.fetchJSON = fetchJSON;
function fetchBlob(coreApi, contentType) {
return function fetchBlob(args) {
const url = coreApi(args);
const headers = jam_core_1.CoreApi.Options.getRequestOptions(args);
const { values: params } = args;
return (0, api_fetch_js_1.blobFetch)(url, { headers, params }, contentType);
};
}
exports.fetchBlob = fetchBlob;
function fetchUpload(coreApi, contentType) {
return function fetchBlob(args) {
const url = coreApi(args);
const headers = jam_core_1.CoreApi.Options.getRequestOptions(args);
const { body } = args;
return (0, api_fetch_js_1.uploadFetch)(url, { headers, method: types_js_1.ApiMethod.Post, body }, contentType);
};
}
exports.fetchUpload = fetchUpload;
function fetchMapImage(coreApi) {
return function fetchMapImage(args, body) {
const { url, headers, method, params } = (0, params_js_1.getMapImageParams)(coreApi, args, body);
return (0, api_fetch_js_1.pngFetch)(url, { headers, method, params });
};
}
exports.fetchMapImage = fetchMapImage;
function fetchAtlasImage(coreApi) {
return function fetchMapImage(args, body) {
const { url, headers, method, params } = (0, params_js_1.getAtlasImageParams)(coreApi, args, body);
return (0, api_fetch_js_1.pngFetch)(url, { headers, method, params });
};
}
exports.fetchAtlasImage = fetchAtlasImage;
function fetchMapSvg(coreApi) {
return function fetchMapImage(args, body) {
const { url, headers, method, params } = (0, params_js_1.getMapImageParams)(coreApi, args, body);
return (0, api_fetch_js_1.svgFetch)(url, { headers, method, params });
};
}
exports.fetchMapSvg = fetchMapSvg;
function fetchAtlasSvg(coreApi) {
return function fetchMapImage(args, body) {
const { url, headers, method, params } = (0, params_js_1.getAtlasImageParams)(coreApi, args, body);
return (0, api_fetch_js_1.svgFetch)(url, { headers, method, params });
};
}
exports.fetchAtlasSvg = fetchAtlasSvg;
class SearchBaseApi {
Items;
Count;
constructor(coreApi) {
this.Items = fetchJSON(coreApi.Items);
this.Count = fetchJSON(coreApi.Count);
}
}
exports.SearchBaseApi = SearchBaseApi;
class SearchFeatureApi extends SearchBaseApi {
Feature;
constructor(coreApi) {
super(coreApi);
this.Feature = {
Items: fetchJSON(coreApi.Feature.Items),
Count: fetchJSON(coreApi.Feature.Count),
};
}
}
exports.SearchFeatureApi = SearchFeatureApi;
class SearchViewBoxApi extends SearchFeatureApi {
ViewBox;
constructor(coreApi) {
super(coreApi);
this.ViewBox = {
Items: fetchJSON(coreApi.ViewBox.Items),
Count: fetchJSON(coreApi.ViewBox.Count),
};
}
}
exports.SearchViewBoxApi = SearchViewBoxApi;