Versions

  • v114

    12/6/2023
    Open: Version
    Changes from v113 to v114
    +0
    -0
    ⦚ 79 unchanged lines ⦚
    ⦚ 79 unchanged lines ⦚
  • v113

    12/6/2023
    Open: Version
    Changes from v112 to v113
    +1
    -1
    ⦚ 48 unchanged lines ⦚
    // }

    return c.json({ queries, data: db.data[resource] });
    });

    ⦚ 26 unchanged lines ⦚
    ⦚ 48 unchanged lines ⦚
    // }

    return c.json({ queries, q, data: db.data[resource] });
    });

    ⦚ 26 unchanged lines ⦚
  • v112

    12/6/2023
    Open: Version
    Changes from v111 to v112
    +14
    -14
    ⦚ 32 unchanged lines ⦚
    }

    if (queries.q) {
    let q = queries.q[0];
    q = q.toLowerCase();
    let chain = db.data[resource];

    chain.filter((obj) => {
    for (const key in obj) {
    const value = obj[key];
    if (value.includes(q)) {
    return true;
    }
    }
    return false;
    });
    }

    return c.json({ queries, data: db.data[resource] });
    ⦚ 28 unchanged lines ⦚
    ⦚ 32 unchanged lines ⦚
    }

    // if (queries.q) {
    // let q = queries.q[0];
    // q = q.toLowerCase();
    // let chain = db.data[resource];

    // chain.filter((obj) => {
    // for (const key in obj) {
    // const value = obj[key];
    // if (value.includes(q)) {
    // return true;
    // }
    // }
    // return false;
    // });
    // }

    return c.json({ queries, data: db.data[resource] });
    ⦚ 28 unchanged lines ⦚
  • v111

    12/6/2023
    Open: Version
    Changes from v110 to v111
    +3
    -3
    ⦚ 35 unchanged lines ⦚
    let q = queries.q[0];
    q = q.toLowerCase();
    let chain = db.data[resource]
    chain.filter((obj) => {
    for (const key in obj) {
    const value = obj[key];
    if (value.includes(q) {
    return true;
    }
    ⦚ 34 unchanged lines ⦚
    ⦚ 35 unchanged lines ⦚
    let q = queries.q[0];
    q = q.toLowerCase();
    let chain = db.data[resource];

    chain.filter((obj) => {
    for (const key in obj) {
    const value = obj[key];
    if (value.includes(q)) {
    return true;
    }
    ⦚ 34 unchanged lines ⦚
  • v110

    12/6/2023
    Open: Version
    Changes from v109 to v110
    +5
    -9
    ⦚ 33 unchanged lines ⦚

    if (queries.q) {
    const q = queries.q;
    // Full-text search
    if (Array.isArray(q)) {
    q = q[0];
    }

    q = q.toLowerCase();

    chain = chain.filter((obj) => {
    for (const key in obj) {
    const value = obj[key];
    if (db._.deepQuery(value, q)) {
    return true;
    }
    ⦚ 34 unchanged lines ⦚
    ⦚ 33 unchanged lines ⦚

    if (queries.q) {
    let q = queries.q[0];
    q = q.toLowerCase();
    let chain = db.data[resource]
    chain.filter((obj) => {
    for (const key in obj) {
    const value = obj[key];
    if (value.includes(q) {
    return true;
    }
    ⦚ 34 unchanged lines ⦚
  • v109

    12/6/2023
    Open: Version
    Changes from v108 to v109
    +2
    -1
    ⦚ 32 unchanged lines ⦚
    }

    if (q) {
    // Full-text search
    if (Array.isArray(q)) {
    ⦚ 45 unchanged lines ⦚
    ⦚ 32 unchanged lines ⦚
    }

    if (queries.q) {
    const q = queries.q;
    // Full-text search
    if (Array.isArray(q)) {
    ⦚ 45 unchanged lines ⦚
  • v108

    12/6/2023
    Open: Version
    Changes from v107 to v108
    +19
    -0
    ⦚ 32 unchanged lines ⦚
    }

    return c.json({ queries, data: db.data[resource] });
    });

    ⦚ 26 unchanged lines ⦚
    ⦚ 32 unchanged lines ⦚
    }

    if (q) {
    // Full-text search
    if (Array.isArray(q)) {
    q = q[0];
    }

    q = q.toLowerCase();

    chain = chain.filter((obj) => {
    for (const key in obj) {
    const value = obj[key];
    if (db._.deepQuery(value, q)) {
    return true;
    }
    }
    return false;
    });
    }

    return c.json({ queries, data: db.data[resource] });
    });

    ⦚ 26 unchanged lines ⦚
  • v107

    12/6/2023
    Open: Version
    Changes from v106 to v107
    +1
    -1
    ⦚ 32 unchanged lines ⦚
    }

    return c.json({ queries, data: db.data[resource][0] });
    });

    ⦚ 26 unchanged lines ⦚
    ⦚ 32 unchanged lines ⦚
    }

    return c.json({ queries, data: db.data[resource] });
    });

    ⦚ 26 unchanged lines ⦚
  • v106

    12/6/2023
    Open: Version
    +63
    -0

    /** @jsxImportSource https://esm.sh/hono@3.9.2/jsx **/

    import { Homepage } from "https://esm.town/v/nbbaier/dbToAPIFrontend";
    import { checkResource, getResources, type Options, validate } from "https://esm.town/v/nbbaier/dbToApiHelpers";
    import { Hono } from "npm:hono";

    // TODO: implement options
    export async function createServer(db, options?: Options) {
    const app = new Hono();

    // Make sure our db contains "data"
    if (!validate(db)) {
    app.get("/", c => c.text("Wrong data shape"));
    return app;
    }

    // Extract information about the resources in the db
    const resources = getResources(db);

    // Get / => returns home
    app.get("/", c => c.html(<Homepage resources={resources} />));

    // GET /db => returns all db data
    app.get("/db", c => c.json(db.data));

    // GET /:resource => if :resource is valid, returns db.data[resource]
    app.get("/:resource", c => {
    const { resource } = c.req.param();
    const queries = c.req.queries();

    if (!checkResource(resource, resources)) {
    return c.text(`The requested resource (${resource}) is not available`);
    }

    return c.json({ queries, data: db.data[resource][0] });
    });
Updated: February 4, 2024