From dd7f9e62a2ea0a535563be9b808154f950a4144f Mon Sep 17 00:00:00 2001 From: Tyler Hall Date: Mon, 20 Dec 2021 21:17:42 +0000 Subject: [PATCH] feat!: remove mapping to id from _id #26 --- adapter.js | 13 +++++-------- adapter_test.js | 8 +------- scripts/ci.sh | 2 +- test/hyper.js | 2 +- utils.js | 9 +-------- 5 files changed, 9 insertions(+), 25 deletions(-) diff --git a/adapter.js b/adapter.js index d9b5e34..253e374 100644 --- a/adapter.js +++ b/adapter.js @@ -1,6 +1,6 @@ // deno-lint-ignore-file no-unused-vars import { crocks, R } from "./deps.js"; -import { formatDocs, queryOptions, xId } from "./utils.js"; +import { formatDocs, queryOptions } from "./utils.js"; const { Async, tryCatch, resultToAsync } = crocks; const { @@ -15,8 +15,6 @@ const { pluck, set, split, - over, - identity, } = R; const cmd = (n) => (db) => Async.fromPromise(db[n].bind(db)); @@ -145,8 +143,8 @@ export function adapter(client) { ) .chain((db) => insertOne(db)({ - _id: id, ...doc, + _id: id, }) .bimap( (e) => ({ ok: false, status: 409, id, msg: e.message }), @@ -174,7 +172,6 @@ export function adapter(client) { ? Async.Resolved(doc) : Async.Rejected({ ok: false, status: 404, msg: "Not Found!" }) ) - .map(over(xId, identity)) .toPromise(); } @@ -232,7 +229,7 @@ export function adapter(client) { ...queryOptions(query), noCursorTimeout: undefined, }).toArray(); - return { ok: true, docs: map(over(xId, identity), docs) }; + return { ok: true, docs }; } catch (e) { console.log(e); return { ok: false, msg: e.message }; @@ -297,7 +294,7 @@ export function adapter(client) { noCursorTimeout: undefined, }).toArray(); - return { ok: true, docs: map(over(xId, identity), docs) }; + return { ok: true, docs }; } catch (e) { console.log("ERROR: ", e.message); return { ok: false, msg: e.message }; @@ -333,7 +330,7 @@ export function adapter(client) { (_) => ({ ok: true, results: map( - (d) => ({ ok: true, id: d.id || d._id, _id: d._id }), + (d) => ({ ok: true, id: d._id }), docs, ), }), diff --git a/adapter_test.js b/adapter_test.js index 8c4731a..54b93ef 100644 --- a/adapter_test.js +++ b/adapter_test.js @@ -54,10 +54,8 @@ test("get document", async () => { }); assertEquals(doc.title, "Groundhog Day"); assertEquals(doc._id, "3-groundhog-day"); - // TODO: remove when blueberry is released - assertEquals(doc.id, doc._id); // cleanup - await a.removeDocument({ db: "hyper~movies", id: "3-groundhog-day" }); + await a.removeDocument({ db: "hyper~movies", _id: "3-groundhog-day" }); }); test("update document", async () => { @@ -121,8 +119,6 @@ test("query documents", async () => { assert(result.ok); assertEquals(result.docs[0]._id, "15-starwars"); - // TODO: remove when blueberry is released - assertEquals(result.docs[0].id, result.docs[0]._id); // cleanup await a.removeDocument({ db: "hyper~movies", id: "10-caddyshack" }); @@ -156,8 +152,6 @@ test("list documents", async () => { assert(result.ok); assertEquals(result.docs.length, 2); assertEquals(result.docs[0]._id, "20-caddyshack"); - // TODO: remove when blueberry is released - assertEquals(result.docs[0].id, result.docs[0]._id); // cleanup await a.removeDocument({ db: "hyper~movies", id: "20-caddyshack" }); diff --git a/scripts/ci.sh b/scripts/ci.sh index 741087a..1694cc5 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -1 +1 @@ -deno test --no-check --allow-net --allow-env --import-map=https://x.nest.land/hyper-test@0.0.4/import_map.json https://x.nest.land/hyper-test@0.0.4/mod.js \ No newline at end of file +deno test --allow-net --allow-env --no-check --import-map=https://x.nest.land/hyper-test@2.0.0/import_map.json https://x.nest.land/hyper-test@2.0.0/mod.js diff --git a/test/hyper.js b/test/hyper.js index 18b3c9a..cf96b20 100644 --- a/test/hyper.js +++ b/test/hyper.js @@ -1,6 +1,6 @@ // Harness deps import { default as appOpine } from "https://x.nest.land/hyper-app-opine@1.2.7/mod.js"; -import { default as core } from "https://x.nest.land/hyper@1.5.2/mod.js"; +import { default as core } from "https://x.nest.land/hyper@2.0.0/mod.js"; import mongo from "../mod.js"; import PORT_NAME from "../port_name.js"; diff --git a/utils.js b/utils.js index b8f4d2b..bb19e9a 100644 --- a/utils.js +++ b/utils.js @@ -1,15 +1,8 @@ import { R } from "./deps.js"; -const { assoc, map, omit, keys, values, lens, prop } = R; - -export const xId = lens(prop("_id"), assoc("id")); +const { assoc, map, omit, keys, values } = R; export const formatDocs = map((d) => { - d = omit(["id"], { - ...d, - _id: d._id || d.id, - }); - if (d._deleted) { return { deleteOne: { filter: { _id: d._id } } }; } else if (d._update) {