hyper-nano 1.3.1 → 2.0.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 +59 -69
  2. package/bin/index.js +35 -33
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -16,40 +16,35 @@
16
16
 
17
17
  ## Motivation
18
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.
19
+ A core tenant of the hyper service framework is that an application should not need to care about
20
+ the underlying service implementation. By building an application to consume an api, your
21
+ appliation, and ergo your business logic, is kept separate and decoupled from the services that
22
+ power it.
23
23
 
24
- > Learn more about
25
- > [Clean Architecture](https://blog.hyper.io/the-perfect-application-architecture/)
24
+ > Learn more about [Clean Architecture](https://blog.hyper.io/the-perfect-application-architecture/)
26
25
 
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.
26
+ This allows for _swapping out_ the service api implementations, without having to change business
27
+ logic. `hyper-nano` is an embodiment of this approach.
29
28
 
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:
29
+ `hyper nano` is an instance of hyper running an `http` based api, and a set of `in-memory`
30
+ [`adapters`](https://docs.hyper.io/oss/building-your-own-adapter) for all of the hyper service
31
+ offerings:
33
32
 
34
33
  - data (powered by [PouchDB](https://github.com/hyper63/hyper-adapter-pouchdb))
35
34
  - 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))
35
+ - storage (powered by your local [file system](https://github.com/hyper63/hyper-adapter-fs))
36
+ - search (powered by [Sqlite and Minisearch](https://github.com/hyper63/hyper-adapter-minisearch))
37
+ - queue (powered by [DnDB and an in-memory queue](https://github.com/hyper63/hyper-adapter-queue))
42
38
 
43
- This allows running a hyper instance locally, great for development, or for
44
- sandboxed short-lived environments ie. GitHub Workspaces or GitPod.
39
+ This allows running a hyper instance locally, great for development, or for sandboxed short-lived
40
+ environments ie. GitHub Workspaces or GitPod.
45
41
 
46
- > At hyper, we exclusively use short-lived ephermeral environments for all
47
- > development. We dog food hyper to build hyper.
42
+ > At hyper, we exclusively use short-lived ephermeral environments for all development. We dog food
43
+ > hyper to build hyper.
48
44
 
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`)
45
+ Then when you deploy, your application consumes your _actual_ hyper application in
46
+ [hyper cloud](https://docs.hyper.io), with no code changes required; (hyper cloud is just hyper
47
+ instances running a different `http` based api set of `adapters`)
53
48
 
54
49
  ## Documentation
55
50
 
@@ -80,20 +75,18 @@ npx hyper-nano --domain=foobar --experimental --data --cache ...
80
75
 
81
76
  ### Deno Usage
82
77
 
83
- Alternatively, if you use `Deno` you may run `hyper nano` directly from the
84
- source:
78
+ Alternatively, if you use `Deno` you may run `hyper nano` directly from the source:
85
79
 
86
80
  ```sh
87
81
  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
88
82
  ```
89
83
 
90
- If you'd like to programmatically start `hyper nano`, you can import `main.js`
91
- and run `main`:
84
+ If you'd like to programmatically start `hyper nano`, you can import `main.js` and run `main`:
92
85
 
93
86
  ```js
94
- import { main } from "https://raw.githubusercontent.com/hyper63/hyper/main/images/nano/main.js";
87
+ import { main } from 'https://raw.githubusercontent.com/hyper63/hyper/main/images/nano/main.js'
95
88
 
96
- await main();
89
+ await main()
97
90
  ```
98
91
 
99
92
  and then run:
@@ -102,25 +95,23 @@ and then run:
102
95
  deno run --allow-env --allow-read --allow-write=__hyper__ --allow-net --unstable --no-check=remote foo.js
103
96
  ```
104
97
 
105
- All of these examples above will start a `hyper nano` instance, listening on
106
- port `6363`. You can then consume your hyper instance
107
- [`hyper-connect`](https://github.com/hyper63/hyper/tree/main/packages/connect)
108
- (recommended) or using `HTTP`.
98
+ All of these examples above will start a `hyper nano` instance, listening on port `6363`. You can
99
+ then consume your hyper instance
100
+ [`hyper-connect`](https://github.com/hyper63/hyper/tree/main/packages/connect) (recommended) or
101
+ using `HTTP`.
109
102
 
110
- To consume using
111
- [`hyper-connect`](https://github.com/hyper63/hyper/tree/main/packages/connect)
112
- pass `http://localhost:[port]/[domain]` to `hyper-connect` as your
103
+ To consume using [`hyper-connect`](https://github.com/hyper63/hyper/tree/main/packages/connect) pass
104
+ `http://localhost:[port]/[domain]` to `hyper-connect` as your
113
105
  [`connection string`](https://docs.hyper.io/app-keys#nq-connection-string)
114
106
 
115
- Consume with
116
- [`hyper-connect`](https://github.com/hyper63/hyper/tree/main/packages/connect):
107
+ Consume with [`hyper-connect`](https://github.com/hyper63/hyper/tree/main/packages/connect):
117
108
 
118
109
  ```js
119
- import { connect } from "hyper-connect";
110
+ import { connect } from 'hyper-connect'
120
111
 
121
- const hyper = connect("http://localhost:6363/test");
112
+ const hyper = connect('http://localhost:6363/test')
122
113
 
123
- await hyper.data.list();
114
+ await hyper.data.list()
124
115
  ```
125
116
 
126
117
  Or consume via HTTP
@@ -129,31 +120,32 @@ Or consume via HTTP
129
120
  curl http://localhost:6363/data/test
130
121
  ```
131
122
 
123
+ > Starting with Node 17, Node has changed how it resolves `localhost`, when using global `fetch` and
124
+ > `fetch` from libraries like `undici`. This may cause requests to `localhost` not to resolve
125
+ > correctly and fail. To get around this, you can use `127.0.0.1` or `0.0.0.0`, in lieu of
126
+ > `localhost`. For more info, See [this issue](https://github.com/nodejs/node/pull/39987)
127
+
132
128
  ## URL Structure Disclaimer
133
129
 
134
- > If you use
135
- > [`hyper-connect`](https://github.com/hyper63/hyper/tree/main/packages/connect)
136
- > to consume hyper, you may disregard this section.
130
+ > If you use [`hyper-connect`](https://github.com/hyper63/hyper/tree/main/packages/connect) to
131
+ > consume hyper, you may disregard this section.
137
132
 
138
- `hyper nano` is built on the open source version of hyper, and has a different
139
- URL structure than `hyper cloud`. This is because `hyper cloud` allows for
140
- groupings of services made explicit by the url.
133
+ `hyper nano` is built on the open source version of hyper, and has a different URL structure than
134
+ `hyper cloud`. This is because `hyper cloud` allows for groupings of services made explicit by the
135
+ url.
141
136
 
142
- For example, assuming the domain `foo` that has a `data` and `cache` service,
143
- `hyper nano` urls are structured as `/data/foo` and `/cache/foo`, whereas
144
- `hyper cloud` urls are structured as `/foo/data/default` and
145
- `/foo/cache/default`.
137
+ For example, assuming the domain `foo` that has a `data` and `cache` service, `hyper nano` urls are
138
+ structured as `/data/foo` and `/cache/foo`, whereas `hyper cloud` urls are structured as
139
+ `/foo/data/default` and `/foo/cache/default`.
146
140
 
147
- If you're consuming `hyper` using straight HTTP, you will need to take this
148
- difference in url structure into account. If you use `hyper-connect`, no changes
149
- are required since `hyper-connect` supports both `hyper oss` and `hyper cloud`
150
- url structures and knows which structure to use based on the provided connection
151
- string.
141
+ If you're consuming `hyper` using straight HTTP, you will need to take this difference in url
142
+ structure into account. If you use `hyper-connect`, no changes are required since `hyper-connect`
143
+ supports both `hyper oss` and `hyper cloud` url structures and knows which structure to use based on
144
+ the provided connection string.
152
145
 
153
146
  ### Bootstrapping services
154
147
 
155
- > **This feature is experimental and will need the `--experimental` flag to be
156
- > enabled**
148
+ > **This feature is experimental and will need the `--experimental` flag to be enabled**
157
149
 
158
150
  `hyper nano` can be supplied arguments to create services on startup:
159
151
 
@@ -163,12 +155,10 @@ string.
163
155
 
164
156
  Other command line arguments can be provided:
165
157
 
166
- - `--purge`: destroy the existing services. You may also pass in which service
167
- types to purge. ie
168
- `./nano --experimental --data --cache --storage --purge=data,cache` will
169
- delete `data` and `cache`, but not `storage`
170
- - `--domain`: the name of the domain your services will be created under. This
171
- defaults to `test`
158
+ - `--purge`: destroy the existing services. You may also pass in which service types to purge. ie
159
+ `./nano --experimental --data --cache --storage --purge=data,cache` will delete `data` and
160
+ `cache`, but not `storage`
161
+ - `--domain`: the name of the domain your services will be created under. This defaults to `test`
172
162
 
173
163
  Examples:
174
164
 
@@ -189,7 +179,7 @@ Examples:
189
179
  or programmatically:
190
180
 
191
181
  ```js
192
- import { main } from "https://raw.githubusercontent.com/hyper63/hyper/main/images/nano/main.js";
182
+ import { main } from 'https://raw.githubusercontent.com/hyper63/hyper/main/images/nano/main.js'
193
183
 
194
184
  /**
195
185
  * - Listen on 6363
@@ -197,7 +187,7 @@ import { main } from "https://raw.githubusercontent.com/hyper63/hyper/main/image
197
187
  * - Create data, cache, and storage services in the test domain
198
188
  */
199
189
  await main({
200
- domain: "test",
190
+ domain: 'test',
201
191
  experimental: true,
202
192
  services: {
203
193
  data: true,
@@ -207,7 +197,7 @@ await main({
207
197
  purge: {
208
198
  data: true,
209
199
  },
210
- });
200
+ })
211
201
  ```
212
202
 
213
203
  ## Contributing
package/bin/index.js CHANGED
@@ -1,71 +1,73 @@
1
1
  #! /usr/bin/env node
2
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");
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
7
 
8
- const chalk = require("chalk");
9
- const ora = require("ora");
8
+ const chalk = require('chalk')
9
+ const ora = require('ora')
10
10
 
11
- const destDir = join(dirname(__filename));
12
- const binaryDest = join(destDir, "hyper-nano");
11
+ const { version } = require('../package.json')
12
+
13
+ const destDir = join(dirname('.'))
14
+ const binaryDest = join(destDir, 'hyper-nano')
13
15
 
14
16
  function getBinary() {
15
17
  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
- };
18
+ linux: `hyper-x86_64-unknown-linux-gnu-${version}`,
19
+ win32: `hyper-x86_64-pc-windows-msvc-${version}.exe`,
20
+ darwinx86_64: `hyper-x86_64-apple-darwin-${version}`,
21
+ darwinarm64: `hyper-aarch64-apple-darwin-${version}`,
22
+ }
21
23
 
22
- const os = platform();
23
- let binary = undefined;
24
+ const os = platform()
25
+ let binary = undefined
24
26
 
25
- if (os === "linux" || os === "win32") {
26
- binary = binaries[os];
27
- } else if (os === "darwin") {
27
+ if (os === 'linux' || os === 'win32') {
28
+ binary = binaries[os]
29
+ } else if (os === 'darwin') {
28
30
  // 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
+ const architecture = arch() === 'arm64' ? 'arm64' : 'x86_64'
32
+ binary = binaries[`${os}${architecture}`]
31
33
  }
32
34
 
33
- return binary;
35
+ return binary
34
36
  }
35
37
 
36
38
  async function main() {
37
39
  if (!existsSync(binaryDest)) {
38
- const binary = getBinary();
40
+ const binary = getBinary()
39
41
  if (binary) {
40
- const spinner = ora("Downloading hyper {nano}").start();
42
+ const spinner = ora('Downloading hyper {nano}').start()
41
43
  await new Promise((resolve, reject) => {
42
44
  // TODO: make cross platform
43
45
  exec(
44
46
  `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();
47
+ { cwd: destDir, stdio: 'ignore', stderr: 'inherit' },
48
+ ).on('close', (code) => code ? reject(code) : resolve(code))
49
+ })
50
+ spinner.stop()
49
51
  } else {
50
52
  console.log(
51
53
  chalk.yellow(
52
54
  `Platform ${platform()} not supported by hyper nano. Skipping hyper nano binary install...`,
53
55
  ),
54
- );
56
+ )
55
57
  }
56
58
  }
57
59
 
58
60
  if (existsSync(binaryDest)) {
59
- const args = process.argv.slice(2, process.argv.length);
61
+ const args = process.argv.slice(2, process.argv.length)
60
62
 
61
63
  execSync(
62
- `./hyper-nano ${args.join(" ")}`,
64
+ `./hyper-nano ${args.join(' ')}`,
63
65
  {
64
- stdio: "inherit",
66
+ stdio: 'inherit',
65
67
  cwd: destDir,
66
68
  },
67
- );
69
+ )
68
70
  }
69
71
  }
70
72
 
71
- main();
73
+ main()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyper-nano",
3
- "version": "1.3.1",
3
+ "version": "2.0.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "In-Memory hyper http server using in-memory adapters",
6
6
  "homepage": "https://github.com/hyper63/hyper/tree/main/images/nano",