// Order pages at /orders/<short id> instead of /orders/1042, and the id read back to find the row.
//
//   quillo run short_ids.qwe      then open http://localhost:8080/orders

use "short_ids.qwer"

// Your own shuffle of the alphabet, kept with the program: ids made with it read back only with it.
let ALPHABET = "k3G7QAe51FCsPW92uEOyq4Bg6Sp8YzVTmnU0liwDdHXLajZrfxNvobJIRchMKt"

let orders = [{ id: 1042, total: 99 }, { id: 1043, total: 15 }]

route GET /orders = orders | map((o) => { url: `/orders/${short_id_encode([o.id], ALPHABET, 6)?}`, total: o.total })

route GET /orders/:code {
    let ids = short_id_decode(code, ALPHABET, 6)?
    if len(ids) != 1 { reply 404 "No such order" }
    find(orders, (o) => o.id == ids[0]) ?? { error: "gone" }
}

route GET /plain = { id: short_id(1042)?, back: short_id_number(short_id(1042)?)?, pair: short_id_encode([7, 99], "", 0)?, junk: short_id_number("nope!")? }
