Skip to content

Commit

Permalink
Merge pull request #1 from hyper63/feat/optional-creds
Browse files Browse the repository at this point in the history
feat: make credentials optional
  • Loading branch information
TillaTheHun0 authored Aug 4, 2021
2 parents 53b479a + 9de7855 commit 66d8a63
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Test

on:
push:
branches: '*'
branches: '**'
tags-ignore: '*'

jobs:
Expand Down
22 changes: 15 additions & 7 deletions async-fetch.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import { base64Encode, crocks, R } from "./deps.js";

const { Async } = crocks;
const { ifElse } = R;
const { ifElse, assoc, pipe, identity } = R;

// TODO: Tyler. wrap with opionated approach like before with https://github.com/vercel/fetch
const asyncFetch = (fetch) => Async.fromPromise(fetch);

const createHeaders = (username, password) => ({
"Content-Type": "application/json",
authorization: `Basic ${
base64Encode(new TextEncoder().encode(username + ":" + password))
}`,
});
const createHeaders = (username, password) =>
pipe(
assoc("Content-Type", "application/json"),
ifElse(
() => username && password,
assoc(
"authorization",
`Basic ${
base64Encode(new TextEncoder().encode(username + ":" + password))
}`,
),
identity,
),
)({});

const handleResponse = (pred) =>
ifElse(
Expand Down
4 changes: 2 additions & 2 deletions mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { R } from "./deps.js";
import { asyncFetch, createHeaders, handleResponse } from "./async-fetch.js";
import adapter from "./adapter.js";

const { mergeDeepRight, defaultTo, pipe } = R;
const { mergeDeepLeft, defaultTo, pipe } = R;

export default function ElasticsearchAdapter(config) {
return Object.freeze({
id: "elasticsearch",
port: "search",
load: pipe(
defaultTo({}),
mergeDeepRight(config),
mergeDeepLeft(config), // perfer config over what's passed from previous load
),
link: (env) =>
() => {
Expand Down

0 comments on commit 66d8a63

Please sign in to comment.