tigerbeetle-node 0.12.16 → 0.12.18
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
CHANGED
|
@@ -7,39 +7,47 @@ The TigerBeetle client for Node.js.
|
|
|
7
7
|
|
|
8
8
|
### Prerequisites
|
|
9
9
|
|
|
10
|
+
Linux >= 5.6 is the only production environment we
|
|
11
|
+
support. But for ease of development we support macOS and
|
|
12
|
+
Windows unless otherwise noted.
|
|
13
|
+
|
|
10
14
|
* NodeJS >= `14`
|
|
11
15
|
|
|
12
|
-
>
|
|
13
|
-
> Windows support is not yet available.
|
|
16
|
+
> Windows support is not yet available for the Node client.
|
|
14
17
|
|
|
15
18
|
## Setup
|
|
16
19
|
|
|
20
|
+
Run:
|
|
21
|
+
|
|
17
22
|
```console
|
|
18
23
|
$ npm install tigerbeetle-node
|
|
19
24
|
```
|
|
20
25
|
|
|
21
|
-
|
|
26
|
+
Now, create `test.js` and copy this into it:
|
|
22
27
|
|
|
23
28
|
```javascript
|
|
24
29
|
const { createClient } = require("tigerbeetle-node");
|
|
25
30
|
console.log("Import ok!");
|
|
26
31
|
```
|
|
27
32
|
|
|
28
|
-
|
|
33
|
+
Finally, build and run:
|
|
29
34
|
|
|
30
35
|
```console
|
|
31
36
|
$ node run test.js
|
|
32
37
|
```
|
|
33
38
|
|
|
39
|
+
Now that all prerequisites and depencies are correctly set
|
|
40
|
+
up, let's dig into using TigerBeetle.
|
|
41
|
+
|
|
34
42
|
If you run into issues, check out the distribution-specific install
|
|
35
43
|
steps that are run in CI to test support:
|
|
36
44
|
|
|
37
|
-
* [Alpine](
|
|
38
|
-
* [Amazon Linux](
|
|
39
|
-
* [Debian](
|
|
40
|
-
* [Fedora](
|
|
41
|
-
* [Ubuntu](
|
|
42
|
-
* [RHEL](
|
|
45
|
+
* [Alpine](https://github.com/tigerbeetledb/tigerbeetle/blob/main/src/clients/node/scripts/scripts/test_install_on_alpine.sh)
|
|
46
|
+
* [Amazon Linux](https://github.com/tigerbeetledb/tigerbeetle/blob/main/src/clients/node/scripts/scripts/test_install_on_amazonlinux.sh)
|
|
47
|
+
* [Debian](https://github.com/tigerbeetledb/tigerbeetle/blob/main/src/clients/node/scripts/scripts/test_install_on_debian.sh)
|
|
48
|
+
* [Fedora](https://github.com/tigerbeetledb/tigerbeetle/blob/main/src/clients/node/scripts/scripts/test_install_on_fedora.sh)
|
|
49
|
+
* [Ubuntu](https://github.com/tigerbeetledb/tigerbeetle/blob/main/src/clients/node/scripts/scripts/test_install_on_ubuntu.sh)
|
|
50
|
+
* [RHEL](https://github.com/tigerbeetledb/tigerbeetle/blob/main/src/clients/node/scripts/scripts/test_install_on_rhelubi.sh)
|
|
43
51
|
|
|
44
52
|
### Sidenote: `BigInt`
|
|
45
53
|
TigerBeetle uses 64-bit integers for many fields while JavaScript's
|
|
@@ -56,6 +64,13 @@ addresses for all replicas in the cluster. The cluster
|
|
|
56
64
|
ID and replica addresses are both chosen by the system that
|
|
57
65
|
starts the TigerBeetle cluster.
|
|
58
66
|
|
|
67
|
+
Clients are thread-safe. But for better
|
|
68
|
+
performance, a single instance should be shared between
|
|
69
|
+
multiple concurrent tasks.
|
|
70
|
+
|
|
71
|
+
Multiple clients are useful when connecting to more than
|
|
72
|
+
one TigerBeetle cluster.
|
|
73
|
+
|
|
59
74
|
In this example the cluster ID is `0` and there are
|
|
60
75
|
three replicas running on ports `3001`, `3002`, and
|
|
61
76
|
`3003`.
|
|
@@ -93,10 +108,6 @@ let account = {
|
|
|
93
108
|
};
|
|
94
109
|
|
|
95
110
|
let accountErrors = await client.createAccounts([account]);
|
|
96
|
-
if (accountErrors.length) {
|
|
97
|
-
// Grab a human-readable message from the response
|
|
98
|
-
console.log(CreateAccountError[accountErrors[0].code]);
|
|
99
|
-
}
|
|
100
111
|
```
|
|
101
112
|
|
|
102
113
|
### Account Flags
|
|
@@ -114,7 +125,7 @@ bitwise-or:
|
|
|
114
125
|
* `AccountFlags.credits_must_not_exceed_credits`
|
|
115
126
|
|
|
116
127
|
|
|
117
|
-
For example, to link
|
|
128
|
+
For example, to link two accounts where the first account
|
|
118
129
|
additionally has the `debits_must_not_exceed_credits` constraint:
|
|
119
130
|
|
|
120
131
|
```javascript
|
|
@@ -137,9 +148,10 @@ See all error conditions in the [create_accounts
|
|
|
137
148
|
reference](https://docs.tigerbeetle.com/reference/operations/create_accounts).
|
|
138
149
|
|
|
139
150
|
```javascript
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
151
|
+
let account2 = { /* ... account values ... */ };
|
|
152
|
+
let account3 = { /* ... account values ... */ };
|
|
153
|
+
let account4 = { /* ... account values ... */ };
|
|
154
|
+
accountErrors = await client.createAccounts([account2, account3, account4]);
|
|
143
155
|
for (const error of accountErrors) {
|
|
144
156
|
switch (error.code) {
|
|
145
157
|
case CreateAccountError.exists:
|
|
@@ -151,11 +163,6 @@ for (const error of accountErrors) {
|
|
|
151
163
|
}
|
|
152
164
|
```
|
|
153
165
|
|
|
154
|
-
The example above shows that the account in index 1 failed
|
|
155
|
-
with error 1. This error here means that `account1` and
|
|
156
|
-
`account3` were created successfully. But `account2` was not
|
|
157
|
-
created.
|
|
158
|
-
|
|
159
166
|
To handle errors you can either 1) exactly match error codes returned
|
|
160
167
|
from `client.createAccounts` with enum values in the
|
|
161
168
|
`CreateAccountError` object, or you can 2) look up the error code in
|
|
@@ -172,8 +179,6 @@ not necessarily the same as the order of IDs in the
|
|
|
172
179
|
request. You can refer to the ID field in the response to
|
|
173
180
|
distinguish accounts.
|
|
174
181
|
|
|
175
|
-
In this example, account `137` exists while account `138` does not.
|
|
176
|
-
|
|
177
182
|
```javascript
|
|
178
183
|
const accounts = await client.lookupAccounts([137n, 138n]);
|
|
179
184
|
console.log(accounts);
|
|
@@ -358,8 +363,6 @@ transfer. So the order of transfers in the response is not necessarily
|
|
|
358
363
|
the same as the order of `id`s in the request. You can refer to the
|
|
359
364
|
`id` field in the response to distinguish transfers.
|
|
360
365
|
|
|
361
|
-
In this example, transfer `1` exists while transfer `2` does not.
|
|
362
|
-
|
|
363
366
|
```javascript
|
|
364
367
|
const transfers = await client.lookupTransfers([1n, 2n]);
|
|
365
368
|
console.log(transfers);
|
|
@@ -445,15 +448,17 @@ const errors = await client.createTransfers(batch);
|
|
|
445
448
|
|
|
446
449
|
### On Linux and macOS
|
|
447
450
|
|
|
451
|
+
In a POSIX shell run:
|
|
452
|
+
|
|
448
453
|
```console
|
|
449
|
-
$ rm -rf tigerbeetle
|
|
450
454
|
$ git clone https://github.com/${GITHUB_REPOSITY:-tigerbeetledb/tigerbeetle}
|
|
451
455
|
$ cd tigerbeetle
|
|
452
|
-
$ git checkout $GIT_SHA
|
|
456
|
+
$ git checkout $GIT_SHA
|
|
453
457
|
$ ./scripts/install_zig.sh
|
|
454
458
|
$ cd src/clients/node
|
|
455
459
|
$ npm install --include dev
|
|
456
460
|
$ npm pack
|
|
461
|
+
$ [ "$TEST" = "true" ] && mvn test || echo "Skipping client unit tests"
|
|
457
462
|
```
|
|
458
463
|
|
|
459
464
|
### On Windows
|
|
Binary file
|
|
Binary file
|