Skip to content

Commit

Permalink
Merge pull request #301 from hyper63/twilson63/chg-core-descending-pa…
Browse files Browse the repository at this point in the history
…ram-257

add cast to descending param and fixed cache name check (#257)
  • Loading branch information
twilson63 authored Aug 31, 2021
2 parents c4270d3 + e2fc9d5 commit 9a130f9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/core/lib/cache/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ function validName(name) {
// verify that the name does not contains spaces
// verify that the name does not contain slashes
// verify that the name contains URI friendly characters
// cache names should only start with alphanumeric characters
// should return a true or false
return /^[a-z0-9-~_]+$/.test(name);
return /^[a-z0-9]+$/.test(name[0]) && /^[a-z0-9-~_]+$/.test(name);
}

/**
Expand Down
19 changes: 13 additions & 6 deletions packages/core/lib/cache/store_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,20 @@ test("create cache store", () => {
);
});

test("should not create store", () => {
test("should not create store with space in name", () =>
store.create("foo bar").runWith({ svc: mockService, events })
.toPromise()
.then(() => assertEquals(true, false), () => assertEquals(true, true)));

test("should create store with non alpha in name", () =>
store.create("foo_bar").runWith({ svc: mockService, events })
.toPromise()
.then(() => assertEquals(true, true), () => assertEquals(true, false)));

test("should not create store starting with non alphanumeric", () =>
store.create("_foo").runWith({ svc: mockService, events })
.fork(
() => assertEquals(true, true),
() => assertEquals(false, true),
);
});
.toPromise()
.then(() => assertEquals(true, false), () => assertEquals(true, true)));

test("destroy cache store", () => {
function handleError() {
Expand Down
10 changes: 10 additions & 0 deletions packages/core/lib/data/db.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { apply, is, of, triggerEvent } from "../utils/mod.js";
import { R } from "../../deps.js";

const { lensProp, over } = R;

const INVALID_DB_MSG = "database name is not valid";
const INVALID_RESPONSE = "response is not valid";
Expand All @@ -21,8 +24,15 @@ export const query = (db, query) =>
.chain(apply("queryDocuments"))
.chain(triggerEvent("DATA:QUERY"));

// convert query param descending to boolean
const castFieldDescending = over(
lensProp("fields"),
over(lensProp("descending"), Boolean),
);

export const index = (db, name, fields) =>
of({ db, name, fields })
.map(castFieldDescending)
.chain(apply("indexDocuments"))
.chain(triggerEvent("DATA:INDEX"));

Expand Down

0 comments on commit 9a130f9

Please sign in to comment.