UNPKG

@hokuto/jam-node

Version:

JAM Node TS, guardians and utils

81 lines (80 loc) 2.89 kB
import { CoreApi, } from "@hokuto/jam-core"; import { ApiMethod } from "../types.js"; import { blobFetch, jsonFetch, pngFetch, svgFetch, uploadFetch, } from "../utils/api-fetch.js"; import { getAtlasImageParams, getMapImageParams } from "./params.js"; export function fetchJSON(coreApi, method = ApiMethod.Get) { return function fetchJSON(args) { const url = coreApi(args); const headers = CoreApi.Options.getRequestOptions(args); const { values: params } = args; return jsonFetch(url, { headers, method, params }); }; } export function fetchBlob(coreApi, contentType) { return function fetchBlob(args) { const url = coreApi(args); const headers = CoreApi.Options.getRequestOptions(args); const { values: params } = args; return blobFetch(url, { headers, params }, contentType); }; } export function fetchUpload(coreApi, contentType) { return function fetchBlob(args) { const url = coreApi(args); const headers = CoreApi.Options.getRequestOptions(args); const { body } = args; return uploadFetch(url, { headers, method: ApiMethod.Post, body }, contentType); }; } export function fetchMapImage(coreApi) { return function fetchMapImage(args, body) { const { url, headers, method, params } = getMapImageParams(coreApi, args, body); return pngFetch(url, { headers, method, params }); }; } export function fetchAtlasImage(coreApi) { return function fetchMapImage(args, body) { const { url, headers, method, params } = getAtlasImageParams(coreApi, args, body); return pngFetch(url, { headers, method, params }); }; } export function fetchMapSvg(coreApi) { return function fetchMapImage(args, body) { const { url, headers, method, params } = getMapImageParams(coreApi, args, body); return svgFetch(url, { headers, method, params }); }; } export function fetchAtlasSvg(coreApi) { return function fetchMapImage(args, body) { const { url, headers, method, params } = getAtlasImageParams(coreApi, args, body); return svgFetch(url, { headers, method, params }); }; } export class SearchBaseApi { Items; Count; constructor(coreApi) { this.Items = fetchJSON(coreApi.Items); this.Count = fetchJSON(coreApi.Count); } } export class SearchFeatureApi extends SearchBaseApi { Feature; constructor(coreApi) { super(coreApi); this.Feature = { Items: fetchJSON(coreApi.Feature.Items), Count: fetchJSON(coreApi.Feature.Count), }; } } export class SearchViewBoxApi extends SearchFeatureApi { ViewBox; constructor(coreApi) { super(coreApi); this.ViewBox = { Items: fetchJSON(coreApi.ViewBox.Items), Count: fetchJSON(coreApi.ViewBox.Count), }; } }