UNPKG

blogger-feeds

Version:
76 lines (75 loc) 1.94 kB
import "./core-6805d14a.js"; import { m as p, M as h, P as y } from "./helpers-3b1a3663.js"; const b = async function* (e) { var s, o; let { opt: n, keep: i } = e, r, t; do t = t ? await l({ from: r, keep: i, opt: n }) : await l(e), r = (t == null ? void 0 : t.type) === "data" && ((s = t == null ? void 0 : t.meta) == null ? void 0 : s.next), yield t; while (r && !((o = n == null ? void 0 : n.signal) != null && o.aborted)); e = i = t = r = n = null; }, m = { keepalive: !0, headers: { "accept-encoding": "br gzip", accept: "application/json", connection: "keep-alive" } }, l = async (e) => { let n, i, r, t; try { if (i = p((e == null ? void 0 : e.from) ?? {}, (e == null ? void 0 : e.make) ?? {}), !i) throw new Error("invalid conf.blogger"); if (t = new Request(i, e.opt ?? m), r = await fetch(t), !r.ok) throw new Error("response error"); n = await r.clone().json(), n = u(n, e), e = i = r = t = null; } catch (s) { n = { type: "error", conf: e, err: s, req: t, res: r }; } return n; }, d = ["blog", "blogId", "postId", "next"], a = function* ({ raw: e, meta: n, schema: i, choice: r }) { for (Array.isArray(e) || (e = [e]); e.length; ) { const t = {}, s = e.shift(); for (const [o, c] of i) (r.has("*") || r.has(o)) && (t[o] = c(s, n ?? (n = t)) || null); yield t; } }, u = (e, n) => { var s; const i = new Set( Array.isArray(n.keep) ? n.keep.concat(d) : ["*"] ), r = a({ raw: (e == null ? void 0 : e.feed) || (e == null ? void 0 : e.entry), schema: h, choice: i }).next().value, t = [ ...a({ raw: ((s = e == null ? void 0 : e.feed) == null ? void 0 : s.entry) || (e == null ? void 0 : e.entry), schema: y, choice: i, meta: r }) ]; return { type: "data", meta: r, data: t }; }; export { b as client };