hyper-nano 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +229 -0
  2. package/bin/index.js +71 -0
  3. package/package.json +19 -0
package/README.md ADDED
@@ -0,0 +1,229 @@
1
+ <h1 align="center">⚡️ hyper {nano} ⚡️</h1>
2
+ <p align="center">
3
+ hyper nano version is a standalone developer instance of hyper, this version gives you
4
+ the ability to run hyper locally with no config setup.
5
+ </p>
6
+
7
+ ---
8
+
9
+ ## Table of Contents
10
+
11
+ - [Motivation](#motivation)
12
+ - [Documentation](#documentation)
13
+ - [Contributing](#contributing)
14
+
15
+ ---
16
+
17
+ ## Motivation
18
+
19
+ A core tenant of the hyper service framework is that an application should not
20
+ need to care about the underlying service implementation. By building an
21
+ application to consume an api, your appliation, and ergo your business logic, is
22
+ kept separate and decoupled from the services that power it.
23
+
24
+ > Learn more about
25
+ > [Clean Architecture](https://blog.hyper.io/the-perfect-application-architecture/)
26
+
27
+ This allows for _swapping out_ the service api implementations, without having
28
+ to change business logic. `hyper-nano` is an embodiment of this approach.
29
+
30
+ `hyper nano` is an instance of hyper running an `http` based api, and a set of
31
+ `in-memory` [`adapters`](https://docs.hyper.io/oss/building-your-own-adapter)
32
+ for all of the hyper service offerings:
33
+
34
+ - data (powered by [PouchDB](https://github.com/hyper63/hyper-adapter-pouchdb))
35
+ - cache (powered by [Sqlite](https://github.com/hyper63/hyper-adapter-sqlite))
36
+ - storage (powered by your local
37
+ [file system](https://github.com/hyper63/hyper-adapter-fs))
38
+ - search (powered by
39
+ [Sqlite and Minisearch](https://github.com/hyper63/hyper-adapter-minisearch))
40
+ - queue (powered by
41
+ [DnDB and an in-memory queue](https://github.com/hyper63/hyper-adapter-queue))
42
+
43
+ This allows running a hyper instance locally, great for development, or for
44
+ sandboxed short-lived environments ie. GitHub Workspaces or GitPod.
45
+
46
+ > At hyper, we exclusively use short-lived ephermeral environments for all
47
+ > development. We dog food hyper to build hyper.
48
+
49
+ Then when you deploy, your application consumes your _actual_ hyper application
50
+ in [hyper cloud](https://docs.hyper.io), with no code changes required; (hyper
51
+ cloud is just hyper instances running a different `http` based api set of
52
+ `adapters`)
53
+
54
+ ## Documentation
55
+
56
+ [consuming hyper documentation](https://docs.hyper.io)
57
+
58
+ To use `hyper nano`, you can download a compiled binary and run it
59
+
60
+ ```sh
61
+ curl https://hyperland.s3.amazonaws.com/hyper -o nano
62
+ chmod +x nano
63
+ ./nano
64
+ ```
65
+
66
+ There are binaries built for each major platform:
67
+
68
+ - [Linux](https://hyperland.s3.amazonaws.com/hyper)
69
+ - [Darwin (Mac)](https://hyperland.s3.amazonaws.com/hyper-x86_64-apple-darwin)
70
+ - [Darwin ARM (Mac M1)](https://hyperland.s3.amazonaws.com/hyper-aarch64-apple-darwin)
71
+ - [Windows](https://hyperland.s3.amazonaws.com/hyper-x86_64-pc-windows-msvc.exe)
72
+
73
+ Alternatively, if you use `Deno` you may run `hyper nano` directly from the
74
+ source:
75
+
76
+ ```sh
77
+ deno run --allow-env --allow-read --allow-write=__hyper__ --allow-net --unstable --no-check=remote https://raw.githubusercontent.com/hyper63/hyper/main/images/nano/mod.js
78
+ ```
79
+
80
+ If you'd like to programmatically start `hyper nano`, you can import `main.js`
81
+ and run `main`:
82
+
83
+ ```js
84
+ import { main } from "https://raw.githubusercontent.com/hyper63/hyper/main/images/nano/main.js";
85
+
86
+ await main();
87
+ ```
88
+
89
+ and then run:
90
+
91
+ ```sh
92
+ deno run --allow-env --allow-read --allow-write=__hyper__ --allow-net --unstable --no-check=remote foo.js
93
+ ```
94
+
95
+ All of these examples above will start a `hyper nano` instance, listening on
96
+ port `6363`. You can then consume your hyper instance
97
+ [`hyper-connect`](https://github.com/hyper63/hyper/tree/main/packages/connect)
98
+ (recommended) or using `HTTP`.
99
+
100
+ To consume using
101
+ [`hyper-connect`](https://github.com/hyper63/hyper/tree/main/packages/connect)
102
+ pass `http://localhost:[port]/[domain]` to `hyper-connect` as your
103
+ [`connection string`](https://docs.hyper.io/app-keys#nq-connection-string)
104
+
105
+ Consume with
106
+ [`hyper-connect`](https://github.com/hyper63/hyper/tree/main/packages/connect):
107
+
108
+ ```js
109
+ import { connect } from "hyper-connect";
110
+
111
+ const hyper = connect("http://localhost:6363/test");
112
+
113
+ await hyper.data.list();
114
+ ```
115
+
116
+ Or consume via HTTP
117
+
118
+ ```sh
119
+ curl http://localhost:6363/data/test
120
+ ```
121
+
122
+ ## URL Structure Disclaimer
123
+
124
+ > If you use
125
+ > [`hyper-connect`](https://github.com/hyper63/hyper/tree/main/packages/connect)
126
+ > to consume hyper, you may disregard this section.
127
+
128
+ `hyper nano` is built on the open source version of hyper, and has a different
129
+ URL structure than `hyper cloud`. This is because `hyper cloud` allows for
130
+ groupings of services made explicit by the url.
131
+
132
+ For example, assuming the domain `foo` that has a `data` and `cache` service,
133
+ `hyper nano` urls are structured as `/data/foo` and `/cache/foo`, whereas
134
+ `hyper cloud` urls are structured as `/foo/data/default` and
135
+ `/foo/cache/default`.
136
+
137
+ If you're consuming `hyper` using straight HTTP, you will need to take this
138
+ difference in url structure into account. If you use `hyper-connect`, no changes
139
+ are required since `hyper-connect` supports both `hyper oss` and `hyper cloud`
140
+ url structures and knows which structure to use based on the provided connection
141
+ string.
142
+
143
+ ### Bootstrapping services
144
+
145
+ > **This feature is experimental and will need the `--experimental` flag to be
146
+ > enabled**
147
+
148
+ `hyper nano` can be supplied arguments to create services on startup:
149
+
150
+ - `--data`: create a hyper data service on startup
151
+ - `--cache`: create a hyper cache service on startup
152
+ - `--storage`: createa a hyper storage service on startup
153
+
154
+ Other command line arguments can be provided:
155
+
156
+ - `--purge`: destroy the existing services. You may also pass in which service
157
+ types to purge. ie
158
+ `./nano --experimental --data --cache --storage --purge=data,cache` will
159
+ delete `data` and `cache`, but not `storage`
160
+ - `--domain`: the name of the domain your services will be created under. This
161
+ defaults to `test`
162
+
163
+ Examples:
164
+
165
+ ```sh
166
+ # Listen on 6363
167
+ ./nano
168
+
169
+ # Purge the existing data service, then create a new one in test domain
170
+ ./nano --experimental --data --purge
171
+
172
+ # Purge the cache service, then create data and cache services in test domain
173
+ ./nano --experimental --data --cache --purge=cache
174
+
175
+ # Purge data, cache, and storage, then create data, cache, and storage services in test domain
176
+ ./nano --experimental --data --cache --storage --purge
177
+ ```
178
+
179
+ or programmatically:
180
+
181
+ ```js
182
+ import { main } from "https://raw.githubusercontent.com/hyper63/hyper/main/images/nano/main.js";
183
+
184
+ /**
185
+ * - Listen on 6363
186
+ * - Purge data service in test domain
187
+ * - Create data, cache, and storage services in the test domain
188
+ */
189
+ await main({
190
+ domain: "test",
191
+ experimental: true,
192
+ services: {
193
+ data: true,
194
+ cache: true,
195
+ storage: true,
196
+ },
197
+ purge: {
198
+ data: true,
199
+ },
200
+ });
201
+ ```
202
+
203
+ ## Contributing
204
+
205
+ ### cache
206
+
207
+ ```
208
+ ./scripts/cache.sh
209
+ ```
210
+
211
+ ### test
212
+
213
+ ```
214
+ ./scripts/test.sh
215
+ ```
216
+
217
+ ### compile
218
+
219
+ ```
220
+ ./scripts/compile.sh
221
+ ```
222
+
223
+ ### actions
224
+
225
+ Github actions deploy hyper to https://hyperland.s3.amazonaws.com/hyper
226
+
227
+ ## LICENSE
228
+
229
+ Apache 2.0
package/bin/index.js ADDED
@@ -0,0 +1,71 @@
1
+ #! /usr/bin/env node
2
+
3
+ const { existsSync } = require("fs");
4
+ const { exec, execSync } = require("child_process");
5
+ const { platform, arch } = require("os");
6
+ const { dirname, join } = require("path");
7
+
8
+ const chalk = require("chalk");
9
+ const ora = require("ora");
10
+
11
+ const destDir = join(dirname(__filename));
12
+ const binaryDest = join(destDir, "hyper-nano");
13
+
14
+ function getBinary() {
15
+ const binaries = {
16
+ linux: "hyper-x86_64-unknown-linux-gnu",
17
+ win32: "hyper-x86_64-pc-windows-msvc.exe",
18
+ darwinx86_64: "hyper-x86_64-apple-darwin",
19
+ darwinarm64: "hyper-aarch64-apple-darwin",
20
+ };
21
+
22
+ const os = platform();
23
+ let binary = undefined;
24
+
25
+ if (os === "linux" || os === "win32") {
26
+ binary = binaries[os];
27
+ } else if (os === "darwin") {
28
+ // darwin, so if arm64, use aarch64 binary, otherwise use darwin x86-64 binary
29
+ const architecture = arch() === "arm64" ? "arm64" : "x86_64";
30
+ binary = binaries[`${os}${architecture}`];
31
+ }
32
+
33
+ return binary;
34
+ }
35
+
36
+ async function main() {
37
+ if (!existsSync(binaryDest)) {
38
+ const binary = getBinary();
39
+ if (binary) {
40
+ const spinner = ora("Downloading hyper {nano}").start();
41
+ await new Promise((resolve, reject) => {
42
+ // TODO: make cross platform
43
+ exec(
44
+ `curl https://hyperland.s3.amazonaws.com/${binary} -o ${binaryDest} && chmod +x ${binaryDest}`,
45
+ { cwd: destDir, stdio: "ignore", stderr: "inherit" },
46
+ ).on("close", (code) => code ? reject(code) : resolve(code));
47
+ });
48
+ spinner.stop();
49
+ } else {
50
+ console.log(
51
+ chalk.yellow(
52
+ `Platform ${platform()} not supported by hyper nano. Skipping hyper nano binary install...`,
53
+ ),
54
+ );
55
+ }
56
+ }
57
+
58
+ if (existsSync(binaryDest)) {
59
+ const args = process.argv.slice(2, process.argv.length);
60
+
61
+ execSync(
62
+ `./hyper-nano ${args.join(" ")}`,
63
+ {
64
+ stdio: "inherit",
65
+ cwd: destDir,
66
+ },
67
+ );
68
+ }
69
+ }
70
+
71
+ main();
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "hyper-nano",
3
+ "version": "1.2.0",
4
+ "license": "Apache-2.0",
5
+ "description": "In-Memory hyper http server using in-memory adapters",
6
+ "homepage": "https://github.com/hyper63/hyper/tree/main/images/nano",
7
+ "repo": "https://github.com/hyper63/hyper",
8
+ "sideEffects": false,
9
+ "bin": {
10
+ "hyper-nano": "bin/index.js"
11
+ },
12
+ "files": [
13
+ "bin"
14
+ ],
15
+ "dependencies": {
16
+ "chalk": "^4",
17
+ "ora": "^5"
18
+ }
19
+ }