Skip to content

Commit 88490fa

Browse files
authored
Merge pull request #28 from hyper63/tillathehun0/adapters-do-not-map-26
feat!: remove mapping to id from _id #26
2 parents 6e025f9 + dd7f9e6 commit 88490fa

File tree

5 files changed

+9
-25
lines changed

5 files changed

+9
-25
lines changed

adapter.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// deno-lint-ignore-file no-unused-vars
22
import { crocks, R } from "./deps.js";
3-
import { formatDocs, queryOptions, xId } from "./utils.js";
3+
import { formatDocs, queryOptions } from "./utils.js";
44

55
const { Async, tryCatch, resultToAsync } = crocks;
66
const {
@@ -15,8 +15,6 @@ const {
1515
pluck,
1616
set,
1717
split,
18-
over,
19-
identity,
2018
} = R;
2119
const cmd = (n) => (db) => Async.fromPromise(db[n].bind(db));
2220

@@ -145,8 +143,8 @@ export function adapter(client) {
145143
)
146144
.chain((db) =>
147145
insertOne(db)({
148-
_id: id,
149146
...doc,
147+
_id: id,
150148
})
151149
.bimap(
152150
(e) => ({ ok: false, status: 409, id, msg: e.message }),
@@ -174,7 +172,6 @@ export function adapter(client) {
174172
? Async.Resolved(doc)
175173
: Async.Rejected({ ok: false, status: 404, msg: "Not Found!" })
176174
)
177-
.map(over(xId, identity))
178175
.toPromise();
179176
}
180177

@@ -232,7 +229,7 @@ export function adapter(client) {
232229
...queryOptions(query),
233230
noCursorTimeout: undefined,
234231
}).toArray();
235-
return { ok: true, docs: map(over(xId, identity), docs) };
232+
return { ok: true, docs };
236233
} catch (e) {
237234
console.log(e);
238235
return { ok: false, msg: e.message };
@@ -297,7 +294,7 @@ export function adapter(client) {
297294
noCursorTimeout: undefined,
298295
}).toArray();
299296

300-
return { ok: true, docs: map(over(xId, identity), docs) };
297+
return { ok: true, docs };
301298
} catch (e) {
302299
console.log("ERROR: ", e.message);
303300
return { ok: false, msg: e.message };
@@ -333,7 +330,7 @@ export function adapter(client) {
333330
(_) => ({
334331
ok: true,
335332
results: map(
336-
(d) => ({ ok: true, id: d.id || d._id, _id: d._id }),
333+
(d) => ({ ok: true, id: d._id }),
337334
docs,
338335
),
339336
}),

adapter_test.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,8 @@ test("get document", async () => {
5454
});
5555
assertEquals(doc.title, "Groundhog Day");
5656
assertEquals(doc._id, "3-groundhog-day");
57-
// TODO: remove when blueberry is released
58-
assertEquals(doc.id, doc._id);
5957
// cleanup
60-
await a.removeDocument({ db: "hyper~movies", id: "3-groundhog-day" });
58+
await a.removeDocument({ db: "hyper~movies", _id: "3-groundhog-day" });
6159
});
6260

6361
test("update document", async () => {
@@ -121,8 +119,6 @@ test("query documents", async () => {
121119

122120
assert(result.ok);
123121
assertEquals(result.docs[0]._id, "15-starwars");
124-
// TODO: remove when blueberry is released
125-
assertEquals(result.docs[0].id, result.docs[0]._id);
126122

127123
// cleanup
128124
await a.removeDocument({ db: "hyper~movies", id: "10-caddyshack" });
@@ -156,8 +152,6 @@ test("list documents", async () => {
156152
assert(result.ok);
157153
assertEquals(result.docs.length, 2);
158154
assertEquals(result.docs[0]._id, "20-caddyshack");
159-
// TODO: remove when blueberry is released
160-
assertEquals(result.docs[0].id, result.docs[0]._id);
161155

162156
// cleanup
163157
await a.removeDocument({ db: "hyper~movies", id: "20-caddyshack" });

scripts/ci.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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
1+
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

test/hyper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Harness deps
22
import { default as appOpine } from "https://x.nest.land/hyper-app-opine@1.2.7/mod.js";
3-
import { default as core } from "https://x.nest.land/hyper@1.5.2/mod.js";
3+
import { default as core } from "https://x.nest.land/hyper@2.0.0/mod.js";
44

55
import mongo from "../mod.js";
66
import PORT_NAME from "../port_name.js";

utils.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
import { R } from "./deps.js";
22

3-
const { assoc, map, omit, keys, values, lens, prop } = R;
4-
5-
export const xId = lens(prop("_id"), assoc("id"));
3+
const { assoc, map, omit, keys, values } = R;
64

75
export const formatDocs = map((d) => {
8-
d = omit(["id"], {
9-
...d,
10-
_id: d._id || d.id,
11-
});
12-
136
if (d._deleted) {
147
return { deleteOne: { filter: { _id: d._id } } };
158
} else if (d._update) {

0 commit comments

Comments
 (0)