Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/app-opine/api/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export const createDocument = ({ params, body, cache }, res) =>
fork(res, 201, cache.createDoc(params.name, body.key, body.value, body.ttl));

// GET /cache/:name/:key
export const getDocument = ({ params, cache }, res) =>
fork(res, 200, cache.getDoc(params.name, params.key));
export const getDocument = ({ params, isLegacyGetEnabled, cache }, res) =>
fork(res, 200, cache.getDoc(params.name, params.key, isLegacyGetEnabled));

// PUT /cache/:name/:key
export const updateDocument = ({ cache, params, body, query }, res) =>
Expand Down
4 changes: 2 additions & 2 deletions packages/app-opine/api/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const createDocument = ({ params, body, data }, res) =>
fork(res, 201, data.createDocument(params.db, body));

// GET /data/:db/:id
export const getDocument = ({ params, data }, res) =>
fork(res, 200, data.getDocument(params.db, params.id));
export const getDocument = ({ params, isLegacyGetEnabled, data }, res) =>
fork(res, 200, data.getDocument(params.db, params.id, isLegacyGetEnabled));

// PUT /data/:db/:id
export const updateDocument = ({ data, params, body }, res) =>
Expand Down
8 changes: 4 additions & 4 deletions packages/app-opine/deps.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export { json, opine, Router } from "https://deno.land/x/opine@2.1.5/mod.ts";
export { json, opine, Router } from "https://deno.land/x/opine@2.3.3/mod.ts";
export { opineCors as cors } from "https://deno.land/x/[email protected]/mod.ts";
export { lookup as getMimeType } from "https://deno.land/x/[email protected]/mod.ts";

export { contentType as getMimeType } from "https://deno.land/[email protected]/media_types/mod.ts";
// TODO: refactor off deprecated: see https://github.com/denoland/deno_std/issues/1778
export { MultipartReader } from "https://deno.land/[email protected]/mime/mod.ts";
export { Buffer } from "https://deno.land/[email protected]/io/buffer.ts";
export { exists } from "https://deno.land/[email protected]/fs/exists.ts";
export { Buffer } from "https://deno.land/[email protected]/io/buffer.ts";

export { default as helmet } from "https://cdn.skypack.dev/[email protected]";
export * as R from "https://cdn.skypack.dev/[email protected]";
Expand Down
2 changes: 1 addition & 1 deletion packages/app-opine/dev_deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export {
assert,
assertEquals,
assertObjectMatch,
} from "https://deno.land/std@0.152.0/testing/asserts.ts";
} from "https://deno.land/std@0.167.0/testing/asserts.ts";
export { superdeno } from "https://deno.land/x/[email protected]/mod.ts";
Binary file added packages/app-opine/hyper63-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 6 additions & 5 deletions packages/app-opine/lib/formData.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { exists, MultipartReader, R } from "../deps.js";
import { MultipartReader, R } from "../deps.js";
import { isMultipartFormData } from "../utils.js";

const { compose, nth, split } = R;
Expand All @@ -15,12 +15,13 @@ export default async (req, _res, next) => {
let boundary;

const contentType = req.get("content-type");
if (isMultipartFormData(contentType)) {
boundary = getBoundary(contentType);
}
if (isMultipartFormData(contentType)) boundary = getBoundary(contentType);

if (!(await exists(TMP_DIR))) {
try {
await Deno.mkdir(TMP_DIR, { recursive: true });
} catch (err) {
if (!(err instanceof Deno.errors.AlreadyExists)) throw err;
// dir exists, so do nothing
}

const form = await new MultipartReader(req.body, boundary).readForm({
Expand Down
8 changes: 8 additions & 0 deletions packages/app-opine/lib/legacyGet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { isTrue } from "../utils.js";

export default (req, _res, next) => {
if (!req.get("X-HYPER-LEGACY-GET")) return next();

req.isLegacyGetEnabled = isTrue(req.get("X-HYPER-LEGACY-GET"));
next();
};
5 changes: 3 additions & 2 deletions packages/app-opine/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { cors, helmet, json, opine, R } from "./deps.js";

// middleware
import formData from "./lib/formData.js";
import legacyGet from "./lib/legacyGet.js";

import { isMultipartFormData } from "./utils.js";

Expand Down Expand Up @@ -52,7 +53,7 @@ export function hyperRouter(services) {
app.delete("/data/:db", bindCore, data.removeDb);
app.get("/data/:db", bindCore, data.listDocuments);
app.post("/data/:db", json({ limit: "8mb" }), bindCore, data.createDocument);
app.get("/data/:db/:id", bindCore, data.getDocument);
app.get("/data/:db/:id", bindCore, legacyGet, data.getDocument);
app.put(
"/data/:db/:id",
json({ limit: "8mb" }),
Expand All @@ -71,7 +72,7 @@ export function hyperRouter(services) {
app.get("/cache/:name/_query", bindCore, cache.queryStore);
app.post("/cache/:name/_query", bindCore, cache.queryStore);
app.post("/cache/:name", json(), bindCore, cache.createDocument);
app.get("/cache/:name/:key", bindCore, cache.getDocument);
app.get("/cache/:name/:key", bindCore, legacyGet, cache.getDocument);
app.put("/cache/:name/:key", json(), bindCore, cache.updateDocument);
app.delete("/cache/:name/:key", bindCore, cache.deleteDocument);

Expand Down
2 changes: 1 addition & 1 deletion packages/app-opine/scripts/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

deno lint && deno fmt --check && deno test -A --unstable
deno lint && deno fmt --check && deno test -A --no-lock --no-check --unstable
53 changes: 53 additions & 0 deletions packages/app-opine/test/cache_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// TODO: Tyler. Probably better way to do this
import { crocks } from "../deps.js";
import { assert, assertEquals, superdeno } from "../dev_deps.js";

import build from "../mod.js";

Deno.env.set("DENO_ENV", "test");

const app = build({
cache: {
getDoc: (name, key, isLegacyGetEnabled) =>
crocks.Async.Resolved({
ok: true,
doc: { _id: key, name, isLegacyGetEnabled },
}),
},
middleware: [],
});

Deno.test("cache", async (t) => {
await t.step("GET /cache/:name/:id", async (t) => {
await t.step("should pass the correct values", async () => {
const withLegacy = await superdeno(app)
.get("/cache/movies/key")
.set("X-HYPER-LEGACY-GET", true);

assert(withLegacy.body.ok);
assertEquals(withLegacy.body.doc._id, "key");
assertEquals(withLegacy.body.doc.name, "movies");
assert(withLegacy.body.doc.isLegacyGetEnabled);

const withoutLegacy = await superdeno(app)
.get("/cache/movies/key");

assert(withoutLegacy.body.ok);
assertEquals(withoutLegacy.body.doc._id, "key");
assertEquals(withoutLegacy.body.doc.name, "movies");
// Will cause the default in core to be used
assertEquals(withoutLegacy.body.doc.isLegacyGetEnabled, undefined);

const withLegacyDisabled = await superdeno(app)
.get("/cache/movies/key")
.set("X-HYPER-LEGACY-GET", false);

assert(withLegacyDisabled.body.ok);
assertEquals(withLegacyDisabled.body.doc._id, "key");
assertEquals(withLegacyDisabled.body.doc.name, "movies");
assertEquals(withLegacyDisabled.body.doc.isLegacyGetEnabled, false);
});
});

// TODO: add more test coverage here
});
21 changes: 0 additions & 21 deletions packages/app-opine/test/crawler-delete_test.js

This file was deleted.

36 changes: 0 additions & 36 deletions packages/app-opine/test/crawler-get_test.js

This file was deleted.

21 changes: 0 additions & 21 deletions packages/app-opine/test/crawler-start_test.js

This file was deleted.

33 changes: 0 additions & 33 deletions packages/app-opine/test/crawler-upsert_test.js

This file was deleted.

94 changes: 94 additions & 0 deletions packages/app-opine/test/crawler_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// TODO: Tyler. Probably better way to do this
import { crocks } from "../deps.js";
import { assert, assertEquals, superdeno } from "../dev_deps.js";

import build from "../mod.js";

Deno.env.set("DENO_ENV", "test");

const app = build({
crawler: {
remove: (bucket, name) => crocks.Async.Resolved({ ok: true, bucket, name }),
get: (bucket, name) =>
crocks.Async.Resolved({
id: "test-spider",
app: "test",
source: "https://example.com",
depth: 2,
script: "",
target: {
url: "https://jsonplaceholder.typicode.com/posts",
sub: "1234",
aud: "https://example.com",
secret: "secret",
},
notify: "https://example.com",
bucket,
name,
}),
start: (bucket, name) => crocks.Async.Resolved({ ok: true, bucket, name }),
upsert: ({ app, name }) =>
crocks.Async.Resolved({ ok: true, bucket: app, name }),
},
middleware: [],
});

Deno.test("crawler", async (t) => {
await t.step("GET /crawler/:bucket/:name", async (t) => {
await t.step("GET /crawler/test/spider", async () => {
const res = await superdeno(app)
.get("/crawler/test/spider")
.send();

assertEquals(res.body.id, "test-spider");
assertEquals(res.body.bucket, "test");
assertEquals(res.body.name, "spider");
});
});

await t.step("DELETE /crawler/:bucket/:name", async (t) => {
await t.step("should pass the correct values", async () => {
const res = await superdeno(app)
.delete("/crawler/test/spider")
.send();

assert(res.body.ok);
assertEquals(res.body.bucket, "test");
assertEquals(res.body.name, "spider");
});
});

await t.step("POST /crawler/:bucket/:name/_start", async (t) => {
await t.step("should pass the correct values", async () => {
const res = await superdeno(app)
.post("/crawler/test/spider/_start")
.send();

assert(res.body.ok);
assertEquals(res.body.bucket, "test");
assertEquals(res.body.name, "spider");
});
});

await t.step("PUT /crawler/:bucket/:name", async () => {
const res = await superdeno(app)
.put("/crawler/test/spider")
.set("Content-Type", "application/json")
.send({
source: "https://example.com",
depth: 2,
script: "",
target: {
url: "https://jsonplaceholder.typicode.com/posts",
sub: "1234",
aud: "https://example.com",
secret: "secret",
},
notify: "https://example.com",
});

assertEquals(res.body.ok, true);
assertEquals(res.body.bucket, "test");
assertEquals(res.body.name, "spider");
});
});
23 changes: 0 additions & 23 deletions packages/app-opine/test/data-bulk_test.js

This file was deleted.

Loading