presidium-db-client-server 0.0.0 → 0.1.1
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/ArrayEventEmitter.js +4 -0
- package/AsyncIterator.js +4 -0
- package/BinaryEntriesStream.js +4 -0
- package/BinaryStream.js +4 -0
- package/DatabaseHandler.js +4 -0
- package/DatabaseServer.js +16 -1
- package/DiskHashTableClient.js +4 -0
- package/DiskSortedHashTableClient.js +4 -0
- package/README.md +55 -0
- package/TextEntriesStream.js +4 -0
- package/TextStream.js +4 -0
- package/buffersToEntry.js +4 -0
- package/handleServerResponse.js +4 -3
- package/package.json +8 -2
package/ArrayEventEmitter.js
CHANGED
package/AsyncIterator.js
CHANGED
package/BinaryEntriesStream.js
CHANGED
package/BinaryStream.js
CHANGED
package/DatabaseHandler.js
CHANGED
package/DatabaseServer.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presidium DB Client and Server may be freely distributed under the CFOSS license.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
require("rubico/global")
|
|
1
6
|
const HTTP = require("presidium/HTTP")
|
|
2
7
|
const DiskHashTable = require("presidium/DiskHashTable")
|
|
3
8
|
const DatabaseHandler = require("./DatabaseHandler")
|
|
@@ -61,7 +66,17 @@ class DatabaseServer {
|
|
|
61
66
|
hts: this.hts,
|
|
62
67
|
})
|
|
63
68
|
|
|
64
|
-
|
|
69
|
+
const handler = tryCatch(
|
|
70
|
+
databaseHandler,
|
|
71
|
+
function errorHandler(error, request, response) {
|
|
72
|
+
response.writeHead(error.code ?? 500, {
|
|
73
|
+
"Content-Type": "text/plain",
|
|
74
|
+
})
|
|
75
|
+
response.end(error.message)
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
this.server = HTTP.Server(handler)
|
|
65
80
|
}
|
|
66
81
|
|
|
67
82
|
/**
|
package/DiskHashTableClient.js
CHANGED
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Presidium DB Client and Server
|
|
2
|
+

|
|
3
|
+
|
|
4
|
+
Source code: [GitHub](https://github.com/richytong/presidium-websocket) |
|
|
5
|
+
License: [CFOSS](https://cloutsworld.com/en-us/legal/license/cfoss)
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
[](https://codecov.io/gh/richytong/presidium-db-client-server)
|
|
9
|
+
[](https://www.npmjs.com/package/presidium-db-client-server)
|
|
10
|
+
|
|
11
|
+
Presidium DB Client and Server.
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
const DatabaseServer = require("presidium-db-client-server/DatabaseServer")
|
|
15
|
+
const DiskHashTableClient = require("presidium-db-client-server/DiskHashTableClient")
|
|
16
|
+
|
|
17
|
+
const server = new DatabaseServer({
|
|
18
|
+
databasePath: `${__dirname}/database`,
|
|
19
|
+
})
|
|
20
|
+
await server.init()
|
|
21
|
+
|
|
22
|
+
server.listen(5000, () => {
|
|
23
|
+
console.log("Database server listening on port 5000")
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
const sessionHt = new DiskHashTableClient({
|
|
27
|
+
serverUrl: "http://localhost:7357",
|
|
28
|
+
tableName: "Session",
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const accessToken = "token"
|
|
32
|
+
const session = { accessToken }
|
|
33
|
+
|
|
34
|
+
await sessionHt.set(accessToken, JSON.stringify(session))
|
|
35
|
+
|
|
36
|
+
const sessionJson = await sessionHt.get(accessToken)
|
|
37
|
+
|
|
38
|
+
await sessionHt.delete(accessToken)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Docs
|
|
42
|
+
Coming soon.
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
with [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm):
|
|
47
|
+
```bash
|
|
48
|
+
npm i presidium-db-client-server
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
Presidium DB Client and Server is distributed under the [CFOSS License](https://cloutsworld.com/en-us/legal/license/cfoss).
|
|
53
|
+
|
|
54
|
+
## Support
|
|
55
|
+
* minimum Node.js version: 16
|
package/TextEntriesStream.js
CHANGED
package/TextStream.js
CHANGED
package/buffersToEntry.js
CHANGED
package/handleServerResponse.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presidium DB Client and Server may be freely distributed under the CFOSS license.
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
const Readable = require("presidium/Readable")
|
|
2
6
|
const TextStream = require("./TextStream")
|
|
3
7
|
const BinaryStream = require("./BinaryStream")
|
|
@@ -52,9 +56,6 @@ async function handleServerResponse(response, options = {}) {
|
|
|
52
56
|
const stream = new BinaryEntriesStream(response, entryLength, delimiter, encoding)
|
|
53
57
|
return AsyncIterator.fromEvents(stream, "entry")
|
|
54
58
|
}
|
|
55
|
-
if (response.headers["content-type"] == "application/json") {
|
|
56
|
-
return Readable.JSON(response)
|
|
57
|
-
}
|
|
58
59
|
if (response.headers["content-type"] == "application/octet-stream") {
|
|
59
60
|
return Readable.Buffer(response)
|
|
60
61
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "presidium-db-client-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Presidium DB client and server library",
|
|
5
5
|
"author": "Richard Tong",
|
|
6
6
|
"license": "CFOSS",
|
|
@@ -37,5 +37,11 @@
|
|
|
37
37
|
"scripts": {
|
|
38
38
|
"test": "node test.js"
|
|
39
39
|
},
|
|
40
|
-
"dependencies": {
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"presidium": "^4.5.0",
|
|
42
|
+
"rubico": "^2.20.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"codecov": "^3.8.2"
|
|
46
|
+
}
|
|
41
47
|
}
|