hyper-nano 1.3.0 → 1.4.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.
- package/README.md +59 -69
- package/bin/index.js +33 -33
- 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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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
|
-
|
|
32
|
-
|
|
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
|
-
|
|
38
|
-
-
|
|
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
|
-
|
|
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
|
-
>
|
|
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
|
-
|
|
51
|
-
|
|
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
|
|
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
|
-
|
|
107
|
-
[`hyper-connect`](https://github.com/hyper63/hyper/tree/main/packages/connect)
|
|
108
|
-
|
|
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`
|
|
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
|
|
110
|
+
import { connect } from 'hyper-connect'
|
|
120
111
|
|
|
121
|
-
const hyper = connect(
|
|
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
|
-
>
|
|
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
|
-
|
|
140
|
-
|
|
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
|
-
|
|
144
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
|
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:
|
|
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,71 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const { existsSync } = require(
|
|
4
|
-
const { exec, execSync } = require(
|
|
5
|
-
const { platform, arch } = require(
|
|
6
|
-
const { dirname, join } = require(
|
|
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(
|
|
9
|
-
const ora = require(
|
|
8
|
+
const chalk = require('chalk')
|
|
9
|
+
const ora = require('ora')
|
|
10
10
|
|
|
11
|
-
const destDir = join(dirname(__filename))
|
|
12
|
-
const binaryDest = join(destDir,
|
|
11
|
+
const destDir = join(dirname(__filename))
|
|
12
|
+
const binaryDest = join(destDir, 'hyper-nano')
|
|
13
13
|
|
|
14
14
|
function getBinary() {
|
|
15
15
|
const binaries = {
|
|
16
|
-
linux:
|
|
17
|
-
win32:
|
|
18
|
-
darwinx86_64:
|
|
19
|
-
darwinarm64:
|
|
20
|
-
}
|
|
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
21
|
|
|
22
|
-
const os = platform()
|
|
23
|
-
let binary = undefined
|
|
22
|
+
const os = platform()
|
|
23
|
+
let binary = undefined
|
|
24
24
|
|
|
25
|
-
if (os ===
|
|
26
|
-
binary = binaries[os]
|
|
27
|
-
} else if (os ===
|
|
25
|
+
if (os === 'linux' || os === 'win32') {
|
|
26
|
+
binary = binaries[os]
|
|
27
|
+
} else if (os === 'darwin') {
|
|
28
28
|
// darwin, so if arm64, use aarch64 binary, otherwise use darwin x86-64 binary
|
|
29
|
-
const architecture = arch() ===
|
|
30
|
-
binary = binaries[`${os}${architecture}`]
|
|
29
|
+
const architecture = arch() === 'arm64' ? 'arm64' : 'x86_64'
|
|
30
|
+
binary = binaries[`${os}${architecture}`]
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
return binary
|
|
33
|
+
return binary
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
async function main() {
|
|
37
37
|
if (!existsSync(binaryDest)) {
|
|
38
|
-
const binary = getBinary()
|
|
38
|
+
const binary = getBinary()
|
|
39
39
|
if (binary) {
|
|
40
|
-
const spinner = ora(
|
|
40
|
+
const spinner = ora('Downloading hyper {nano}').start()
|
|
41
41
|
await new Promise((resolve, reject) => {
|
|
42
42
|
// TODO: make cross platform
|
|
43
43
|
exec(
|
|
44
44
|
`curl https://hyperland.s3.amazonaws.com/${binary} -o ${binaryDest} && chmod +x ${binaryDest}`,
|
|
45
|
-
{ cwd: destDir, stdio:
|
|
46
|
-
).on(
|
|
47
|
-
})
|
|
48
|
-
spinner.stop()
|
|
45
|
+
{ cwd: destDir, stdio: 'ignore', stderr: 'inherit' },
|
|
46
|
+
).on('close', (code) => code ? reject(code) : resolve(code))
|
|
47
|
+
})
|
|
48
|
+
spinner.stop()
|
|
49
49
|
} else {
|
|
50
50
|
console.log(
|
|
51
51
|
chalk.yellow(
|
|
52
52
|
`Platform ${platform()} not supported by hyper nano. Skipping hyper nano binary install...`,
|
|
53
53
|
),
|
|
54
|
-
)
|
|
54
|
+
)
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
if (existsSync(binaryDest)) {
|
|
59
|
-
const args = process.argv.slice(2, process.argv.length)
|
|
59
|
+
const args = process.argv.slice(2, process.argv.length)
|
|
60
60
|
|
|
61
61
|
execSync(
|
|
62
|
-
`./hyper-nano ${args.join(
|
|
62
|
+
`./hyper-nano ${args.join(' ')}`,
|
|
63
63
|
{
|
|
64
|
-
stdio:
|
|
64
|
+
stdio: 'inherit',
|
|
65
65
|
cwd: destDir,
|
|
66
66
|
},
|
|
67
|
-
)
|
|
67
|
+
)
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
main()
|
|
71
|
+
main()
|
package/package.json
CHANGED