-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #313 from hyper63/twilson63/feat-hyper-connect-cre…
…ate-312 Twilson63/feat hyper connect create 312
- Loading branch information
Showing
18 changed files
with
921 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: publish connect | ||
|
||
on: | ||
push: | ||
tags: | ||
- "hyper-connect@*" | ||
|
||
jobs: | ||
publish-egg: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: denoland/setup-deno@v1 | ||
with: | ||
deno-version: v1.x | ||
- run: deno install -A -f --unstable --no-check https://x.nest.land/[email protected]/eggs.ts | ||
- run: | | ||
export PATH="/home/runner/.deno/bin:$PATH" | ||
eggs link ${{ secrets.NESTAPIKEY }} | ||
cd packages/connect | ||
eggs publish --yes | ||
publish-npm: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: "16.x" | ||
registry-url: "https://registry.npmjs.org" | ||
- run: cd packages/connect && yarn | ||
- run: cd packages/connect && npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: test connect | ||
on: | ||
push: | ||
branches: | ||
- "**" | ||
paths: | ||
- "packages/connect/**" | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
deno-version: [1.13.x] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Deno ${{ matrix.deno-version }} | ||
uses: denoland/setup-deno@v1 | ||
with: | ||
deno-version: ${{ matrix.deno-version }} | ||
- run: cd packages/connect && ./scripts/test.sh | ||
env: | ||
CI: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
export { default as hyper } from "https://x.nest.land/[email protected]/mod.js"; | ||
export { default as app } from "https://x.nest.land/[email protected].3/mod.js"; | ||
export { default as app } from "https://x.nest.land/[email protected].4/mod.js"; | ||
//export { default as app } from "../../packages/app-opine/mod.js"; | ||
|
||
// adapters | ||
export { default as dndb } from "https://x.nest.land/[email protected]/mod.js"; | ||
export { default as cache } from "https://x.nest.land/hyper-adapter-sqlite@0.0.4/mod.js"; | ||
export { default as cache } from "https://x.nest.land/hyper-adapter-sqlite@1.0.0/mod.js"; | ||
export { default as fs } from "https://x.nest.land/[email protected]/mod.js"; | ||
export { default as minisearch } from "https://x.nest.land/hyper-adapter-minisearch@1.0.12/mod.js"; | ||
export { default as minisearch } from "https://x.nest.land/hyper-adapter-minisearch@1.1.0/mod.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ export default { | |
}, | ||
{ | ||
port: "search", | ||
plugins: [minisearch()], | ||
plugins: [minisearch({ dir: DIR })], | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
<h1 align="center">⚡️ hyper-connect ⚡️</h1> | ||
<p align="center"> | ||
hyper-connect is a client for [hyper](https://docs.hyper.io) - the client leverages the `Request` object from the fetch specification to construct a http request to send to the hyper server. The hyper-connect library handles all of the redundant details of a fetch request, so you can just specify the unique differences of your request. | ||
</p> | ||
<p align="center"> | ||
INSERT BADGES HERE | ||
</p> | ||
|
||
--- | ||
|
||
## Table of Contents | ||
|
||
- [Getting Started](#getting-started) | ||
- [Examples](#examples) | ||
- [Documentation](#documentation) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
- [Support](#support) | ||
|
||
--- | ||
|
||
## Getting Started | ||
|
||
### Deno | ||
|
||
```js | ||
import connect from "https://x.nest.land/hyper-connect@VERSION/mod.js"; | ||
|
||
const HYPER = Deno.env.get("HYPER"); // connect string: cloud://key:[email protected]/:app | ||
|
||
const hyper = connect(HYPER)(); | ||
|
||
const docs = await fetch(await hyper.data.list()).then((r) => r.json()); | ||
const userSession = await fetch(await hyper.cache.get(user)).then((r) => | ||
r.json() | ||
); | ||
const result = await fetch(await hyper.search.query(criteria)).then((r) => | ||
r.json() | ||
); | ||
``` | ||
|
||
With hyper-connect you can access all of the hyper services and get back a | ||
Request object via a promise, then you can add that request object to your fetch | ||
call to invoke your request and receive a response. | ||
|
||
### NodeJS | ||
|
||
`npm install hyper-connect` | ||
|
||
```js | ||
import connect from "hyper-connect"; | ||
import fetch from "node-fetch"; | ||
|
||
const HYPER = process.env.get["HYPER"]; // connect string: cloud://key:[email protected]/:app | ||
|
||
const hyper = connect(HYPER)(); | ||
|
||
const docs = await fetch(await hyper.data.list()).then((r) => r.json()); | ||
const userSession = await fetch(await hyper.cache.get(user)).then((r) => | ||
r.json() | ||
); | ||
const result = await fetch(await hyper.search.query(criteria)).then((r) => | ||
r.json() | ||
); | ||
``` | ||
|
||
--- | ||
|
||
## Examples | ||
|
||
### How to add a document to hyper data? | ||
|
||
```js | ||
const doc = { | ||
id: "1", | ||
type: "movie", | ||
title: "Dune", | ||
year: "2021", | ||
}; | ||
|
||
const req = await hyper.data.add(doc); | ||
const response = await fetch(req); | ||
if (response.ok) { | ||
const result = await response.json(); | ||
console.log(result); | ||
} | ||
``` | ||
|
||
### How to get all the documents of type 'movie'? | ||
|
||
```js | ||
const req = await hyper.data.query({ type: "movie" }); | ||
const response = await fetch(req); | ||
if (response.ok) { | ||
const result = await response.json(); | ||
console.log(result); | ||
} | ||
``` | ||
|
||
### How to add a cache key/value pair to hyper cache? | ||
|
||
```js | ||
const req = await hyper.cache.add("key", { counter: 1 }); | ||
const response = await fetch(req); | ||
if (response.ok) { | ||
const result = await response.json(); | ||
console.log(result); | ||
} | ||
``` | ||
|
||
## Documentation | ||
|
||
hyper is a suite of service apis, with hyper connect you can specify the api you | ||
want to connect with and the action you want to perform. | ||
hyper.[service].[action] - with each service there are a different set of | ||
actions to call. This table breaks down the service and action with description | ||
of the action. | ||
|
||
### data | ||
|
||
| Service | Action | Description | | ||
| ------- | ------ | ------------------------------------------------------------------- | | ||
| data | add | creates a json document in the hyper data store | | ||
| data | list | lists the documents given a start,stop,limit range | | ||
| data | get | retrieves a document by id | | ||
| data | update | updates a given document by id | | ||
| data | remove | removes a document from the store | | ||
| data | query | queries the store for a set of documents based on selector criteria | | ||
| data | index | creates an index for the data store | | ||
| data | bulk | inserts, updates, and removed document via a batch of documents | | ||
|
||
### cache | ||
|
||
| Service | Action | Description | | ||
| ------- | ------ | ------------------------------------------------------------------- | | ||
| cache | add | creates a json document in the hyper cache store with a key | | ||
| cache | get | retrieves a document by key | | ||
| cache | set | sets a given document by key | | ||
| cache | remove | removes a document from the cache | | ||
| cache | query | queries the cache for a set of documents based on a pattern matcher | | ||
|
||
### search | ||
|
||
| Service | Action | Description | | ||
| ------- | ------ | ------------------------------------------------- | | ||
| search | add | indexes a json document in the hyper search index | | ||
| search | get | retrieves a document from index | | ||
| search | remove | removes a document from the index | | ||
| search | search | searches index by text | | ||
|
||
--- | ||
|
||
### Contributing | ||
|
||
--- | ||
|
||
### License | ||
|
||
Apache 2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import data from "./lib/data.js"; | ||
import cache from "./lib/cache.js"; | ||
import search from "./lib/search.js"; | ||
import { buildRequest } from "./utils.js"; | ||
|
||
export default function (connectionString) { | ||
const cs = new URL(connectionString); | ||
const br = buildRequest(cs); | ||
|
||
const $ = (svc, client, action, ...args) => { | ||
return client[action](...args).runWith(br(svc)).toPromise(); | ||
}; | ||
|
||
/** | ||
* @param {string} domain | ||
*/ | ||
return function (_domain = "default") { | ||
return { | ||
data: { | ||
add: (body) => $("data", data, "add", body), | ||
list: (params) => $("data", data, "list", params), | ||
get: (id) => $("data", data, "get", id), | ||
update: (id, body) => $("data", data, "update", id, body), | ||
remove: (id) => $("data", data, "remove", id), | ||
query: (selector, options) => | ||
$("data", data, "query", selector, options), | ||
bulk: (docs) => $("data", data, "bulk", docs), | ||
create: () => $("data", data, "create"), | ||
destroy: (confirm) => $("data", data, "destroy", confirm), | ||
index: (name, fields) => $("data", data, "index", name, fields), | ||
}, | ||
cache: { | ||
create: () => $("cache", cache, "create"), | ||
destroy: (confirm) => $("cache", cache, "destroy", confirm), | ||
add: (key, value, ttl) => $("cache", cache, "add", key, value, ttl), | ||
remove: (key) => $("cache", cache, "remove", key), | ||
get: (key) => $("cache", cache, "get", key), | ||
set: (key, value, ttl) => $("cache", cache, "set", key, value, ttl), | ||
query: (pattern) => $("cache", cache, "query", pattern), | ||
}, | ||
search: { | ||
create: (fields, storeFields) => | ||
$("search", search, "create", fields, storeFields), | ||
destroy: (confirm) => $("search", search, "destroy", confirm), | ||
add: (key, doc) => $("search", search, "add", key, doc), | ||
remove: (key) => $("search", search, "remove", key), | ||
get: (key) => $("search", search, "get", key), | ||
update: (key, doc) => $("search", search, "update", key, doc), | ||
query: (query, options) => $("search", search, "query", query, options), | ||
load: (docs) => $("search", search, "load", docs), | ||
}, | ||
info: { | ||
isCloud: cs.protocol === "cloud:", | ||
}, | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
let crocks, R, signJWT, jwt; | ||
|
||
if (globalThis.Deno) { | ||
crocks = (await import("https://cdn.skypack.dev/crocks")).default; | ||
R = await import("https://cdn.skypack.dev/ramda"); | ||
signJWT = (await import("https://deno.land/x/[email protected]/mod.ts")).create; | ||
} else { | ||
crocks = (await import("crocks")).default; | ||
R = (await import("ramda")).default; | ||
jwt = (await import("jsonwebtoken")); | ||
signJWT = (headers, payload, secret) => | ||
jwt(payload, secret, { algorithm: headers.alg }); | ||
} | ||
|
||
export { crocks, R, signJWT }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"$schema": "https://x.nest.land/[email protected]/src/schema.json", | ||
"name": "hyper-connect", | ||
"entry": "./mod.js", | ||
"description": "hyper client to connect to hyper services", | ||
"homepage": "https://github.com/hyper63/hyper", | ||
"repo": "https://github.com/hyper63/hyper", | ||
"version": "0.0.1", | ||
"unstable": false, | ||
"unlisted": false, | ||
"files": [ | ||
"./connect.js", | ||
"./deps.js", | ||
"./egg.json", | ||
"./mod.js", | ||
"./README.md", | ||
"./utils.js", | ||
"./lib/*.js" | ||
], | ||
"ignore": [ | ||
"./package.json", | ||
"./scripts/*", | ||
"./.git*" | ||
], | ||
"checkFormat": false, | ||
"checkTests": false, | ||
"checkInstallation": false, | ||
"check": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Request } from "node-fetch"; | ||
import connect from "./connect"; | ||
|
||
globalThis.Request = Request; | ||
|
||
export default connect; |
Oops, something went wrong.