tigerbeetle-node 0.12.104 → 0.12.106
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 +171 -37
- package/dist/bin/aarch64-macos/client.node +0 -0
- package/dist/bin/x86_64-macos/client.node +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ title: Node.js
|
|
|
3
3
|
---
|
|
4
4
|
|
|
5
5
|
This file is generated by
|
|
6
|
-
[src/clients/docs_generate.zig](/src/clients/docs_generate.zig).
|
|
6
|
+
[/src/clients/docs_generate.zig](/src/clients/docs_generate.zig).
|
|
7
7
|
# tigerbeetle-node
|
|
8
8
|
|
|
9
9
|
The TigerBeetle client for Node.js.
|
|
@@ -11,18 +11,20 @@ The TigerBeetle client for Node.js.
|
|
|
11
11
|
### Prerequisites
|
|
12
12
|
|
|
13
13
|
Linux >= 5.6 is the only production environment we
|
|
14
|
-
support. But for ease of development we also support macOS.
|
|
14
|
+
support. But for ease of development we also support macOS. Windows is not yet supported.
|
|
15
15
|
* NodeJS >= `14`
|
|
16
16
|
|
|
17
17
|
## Setup
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
First, create a directory for your project and `cd` into the directory.
|
|
20
|
+
|
|
21
|
+
Then, install the TigerBeetle client:
|
|
20
22
|
|
|
21
23
|
```console
|
|
22
24
|
$ npm install tigerbeetle-node
|
|
23
25
|
```
|
|
24
26
|
|
|
25
|
-
Now, create `
|
|
27
|
+
Now, create `main.js` and copy this into it:
|
|
26
28
|
|
|
27
29
|
```javascript
|
|
28
30
|
const { createClient } = require("tigerbeetle-node");
|
|
@@ -32,7 +34,7 @@ console.log("Import ok!");
|
|
|
32
34
|
Finally, build and run:
|
|
33
35
|
|
|
34
36
|
```console
|
|
35
|
-
$ node
|
|
37
|
+
$ node main.js
|
|
36
38
|
```
|
|
37
39
|
|
|
38
40
|
Now that all prerequisites and dependencies are correctly set
|
|
@@ -48,17 +50,15 @@ steps that are run in CI to test support:
|
|
|
48
50
|
* [Ubuntu](https://github.com/tigerbeetledb/tigerbeetle/blob/main/src/clients/node/scripts/test_install_on_ubuntu.sh)
|
|
49
51
|
* [RHEL](https://github.com/tigerbeetledb/tigerbeetle/blob/main/src/clients/node/scripts/test_install_on_rhelubi.sh)
|
|
50
52
|
|
|
51
|
-
##
|
|
53
|
+
## Sample projects
|
|
52
54
|
|
|
53
55
|
This document is primarily a reference guide to
|
|
54
56
|
the client. Below are various sample projects demonstrating
|
|
55
57
|
features of TigerBeetle.
|
|
56
58
|
|
|
57
|
-
* [Basic](/src/clients/node/samples/basic/): Create two accounts and
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
accounts and start a pending transfer between them, then
|
|
61
|
-
post the transfer.
|
|
59
|
+
* [Basic](/src/clients/node/samples/basic/): Create two accounts and transfer an amount between them.
|
|
60
|
+
* [Two-Phase Transfer](/src/clients/node/samples/two-phase/): Create two accounts and start a pending transfer between
|
|
61
|
+
them, then post the transfer.
|
|
62
62
|
### Sidenote: `BigInt`
|
|
63
63
|
TigerBeetle uses 64-bit integers for many fields while JavaScript's
|
|
64
64
|
builtin `Number` maximum value is `2^53-1`. The `n` suffix in JavaScript
|
|
@@ -81,14 +81,14 @@ multiple concurrent tasks.
|
|
|
81
81
|
Multiple clients are useful when connecting to more than
|
|
82
82
|
one TigerBeetle cluster.
|
|
83
83
|
|
|
84
|
-
In this example the cluster ID is `0` and there
|
|
85
|
-
|
|
86
|
-
`
|
|
84
|
+
In this example the cluster ID is `0` and there is one
|
|
85
|
+
replica. The address is read from the `TB_ADDRESS`
|
|
86
|
+
environment variable and defaults to port `3000`.
|
|
87
87
|
|
|
88
88
|
```javascript
|
|
89
89
|
const client = createClient({
|
|
90
90
|
cluster_id: 0,
|
|
91
|
-
replica_addresses: [
|
|
91
|
+
replica_addresses: [process.env.TB_ADDRESS || '3000']
|
|
92
92
|
});
|
|
93
93
|
```
|
|
94
94
|
|
|
@@ -139,8 +139,32 @@ For example, to link two accounts where the first account
|
|
|
139
139
|
additionally has the `debits_must_not_exceed_credits` constraint:
|
|
140
140
|
|
|
141
141
|
```javascript
|
|
142
|
-
let account0 = {
|
|
143
|
-
|
|
142
|
+
let account0 = {
|
|
143
|
+
id: 100n,
|
|
144
|
+
reserved: Buffer.alloc(48, 0),
|
|
145
|
+
user_data: 0n,
|
|
146
|
+
ledger: 1,
|
|
147
|
+
code: 1,
|
|
148
|
+
debits_pending: 0n,
|
|
149
|
+
debits_posted: 0n,
|
|
150
|
+
credits_pending: 0n,
|
|
151
|
+
credits_posted: 0n,
|
|
152
|
+
timestamp: 0n,
|
|
153
|
+
flags: 0,
|
|
154
|
+
};
|
|
155
|
+
let account1 = {
|
|
156
|
+
id: 101n,
|
|
157
|
+
user_data: 0n,
|
|
158
|
+
reserved: Buffer.alloc(48, 0),
|
|
159
|
+
ledger: 1,
|
|
160
|
+
code: 1,
|
|
161
|
+
debits_pending: 0n,
|
|
162
|
+
debits_posted: 0n,
|
|
163
|
+
credits_pending: 0n,
|
|
164
|
+
credits_posted: 0n,
|
|
165
|
+
timestamp: 0n,
|
|
166
|
+
flags: 0,
|
|
167
|
+
};
|
|
144
168
|
account0.flags = AccountFlags.linked | AccountFlags.debits_must_not_exceed_credits;
|
|
145
169
|
accountErrors = await client.createAccounts([account0, account1]);
|
|
146
170
|
```
|
|
@@ -158,9 +182,45 @@ See all error conditions in the [create_accounts
|
|
|
158
182
|
reference](https://docs.tigerbeetle.com/reference/operations/create_accounts).
|
|
159
183
|
|
|
160
184
|
```javascript
|
|
161
|
-
let account2 = {
|
|
162
|
-
|
|
163
|
-
|
|
185
|
+
let account2 = {
|
|
186
|
+
id: 102n,
|
|
187
|
+
reserved: Buffer.alloc(48, 0),
|
|
188
|
+
user_data: 0n,
|
|
189
|
+
ledger: 1,
|
|
190
|
+
code: 1,
|
|
191
|
+
debits_pending: 0n,
|
|
192
|
+
debits_posted: 0n,
|
|
193
|
+
credits_pending: 0n,
|
|
194
|
+
credits_posted: 0n,
|
|
195
|
+
timestamp: 0n,
|
|
196
|
+
flags: 0,
|
|
197
|
+
};
|
|
198
|
+
let account3 = {
|
|
199
|
+
id: 103n,
|
|
200
|
+
user_data: 0n,
|
|
201
|
+
reserved: Buffer.alloc(48, 0),
|
|
202
|
+
ledger: 1,
|
|
203
|
+
code: 1,
|
|
204
|
+
debits_pending: 0n,
|
|
205
|
+
debits_posted: 0n,
|
|
206
|
+
credits_pending: 0n,
|
|
207
|
+
credits_posted: 0n,
|
|
208
|
+
timestamp: 0n,
|
|
209
|
+
flags: 0,
|
|
210
|
+
};
|
|
211
|
+
let account4 = {
|
|
212
|
+
id: 104n,
|
|
213
|
+
user_data: 0n,
|
|
214
|
+
reserved: Buffer.alloc(48, 0),
|
|
215
|
+
ledger: 1,
|
|
216
|
+
code: 1,
|
|
217
|
+
debits_pending: 0n,
|
|
218
|
+
debits_posted: 0n,
|
|
219
|
+
credits_pending: 0n,
|
|
220
|
+
credits_posted: 0n,
|
|
221
|
+
timestamp: 0n,
|
|
222
|
+
flags: 0,
|
|
223
|
+
};
|
|
164
224
|
accountErrors = await client.createAccounts([account2, account3, account4]);
|
|
165
225
|
for (const error of accountErrors) {
|
|
166
226
|
switch (error.result) {
|
|
@@ -220,8 +280,8 @@ reference](https://docs.tigerbeetle.com/reference/transfers).
|
|
|
220
280
|
let transfer = {
|
|
221
281
|
id: 1n,
|
|
222
282
|
pending_id: 0n,
|
|
223
|
-
debit_account_id:
|
|
224
|
-
credit_account_id:
|
|
283
|
+
debit_account_id: 102n,
|
|
284
|
+
credit_account_id: 103n,
|
|
225
285
|
user_data: 0n,
|
|
226
286
|
reserved: 0n,
|
|
227
287
|
timeout: 0n,
|
|
@@ -316,8 +376,34 @@ bitwise-or:
|
|
|
316
376
|
For example, to link `transfer0` and `transfer1`:
|
|
317
377
|
|
|
318
378
|
```javascript
|
|
319
|
-
transfer0 = {
|
|
320
|
-
|
|
379
|
+
let transfer0 = {
|
|
380
|
+
id: 2n,
|
|
381
|
+
pending_id: 0n,
|
|
382
|
+
debit_account_id: 102n,
|
|
383
|
+
credit_account_id: 103n,
|
|
384
|
+
user_data: 0n,
|
|
385
|
+
reserved: 0n,
|
|
386
|
+
timeout: 0n,
|
|
387
|
+
ledger: 1,
|
|
388
|
+
code: 720,
|
|
389
|
+
flags: 0,
|
|
390
|
+
amount: 10n,
|
|
391
|
+
timestamp: 0n,
|
|
392
|
+
};
|
|
393
|
+
let transfer1 = {
|
|
394
|
+
id: 3n,
|
|
395
|
+
pending_id: 0n,
|
|
396
|
+
debit_account_id: 102n,
|
|
397
|
+
credit_account_id: 103n,
|
|
398
|
+
user_data: 0n,
|
|
399
|
+
reserved: 0n,
|
|
400
|
+
timeout: 0n,
|
|
401
|
+
ledger: 1,
|
|
402
|
+
code: 720,
|
|
403
|
+
flags: 0,
|
|
404
|
+
amount: 10n,
|
|
405
|
+
timestamp: 0n,
|
|
406
|
+
};
|
|
321
407
|
transfer0.flags = TransferFlags.linked;
|
|
322
408
|
// Create the transfer
|
|
323
409
|
transferErrors = await client.createTransfers([transfer0, transfer1]);
|
|
@@ -340,13 +426,37 @@ appropriate accounts and apply them to the `debits_posted` and
|
|
|
340
426
|
`credits_posted` balances.
|
|
341
427
|
|
|
342
428
|
```javascript
|
|
343
|
-
|
|
344
|
-
id:
|
|
345
|
-
pending_id:
|
|
429
|
+
let transfer2 = {
|
|
430
|
+
id: 4n,
|
|
431
|
+
pending_id: 0n,
|
|
432
|
+
debit_account_id: 102n,
|
|
433
|
+
credit_account_id: 103n,
|
|
434
|
+
user_data: 0n,
|
|
435
|
+
reserved: 0n,
|
|
436
|
+
timeout: 0n,
|
|
437
|
+
ledger: 1,
|
|
438
|
+
code: 720,
|
|
439
|
+
flags: TransferFlags.pending,
|
|
440
|
+
amount: 10n,
|
|
441
|
+
timestamp: 0n,
|
|
442
|
+
};
|
|
443
|
+
transferErrors = await client.createTransfers([transfer2]);
|
|
444
|
+
|
|
445
|
+
let transfer3 = {
|
|
446
|
+
id: 5n,
|
|
447
|
+
pending_id: 4n,
|
|
448
|
+
debit_account_id: 102n,
|
|
449
|
+
credit_account_id: 103n,
|
|
450
|
+
user_data: 0n,
|
|
451
|
+
reserved: 0n,
|
|
452
|
+
timeout: 0n,
|
|
453
|
+
ledger: 1,
|
|
454
|
+
code: 720,
|
|
346
455
|
flags: TransferFlags.post_pending_transfer,
|
|
456
|
+
amount: 10n,
|
|
347
457
|
timestamp: 0n,
|
|
348
458
|
};
|
|
349
|
-
transferErrors = await client.createTransfers([
|
|
459
|
+
transferErrors = await client.createTransfers([transfer3]);
|
|
350
460
|
```
|
|
351
461
|
|
|
352
462
|
#### Void a Pending Transfer
|
|
@@ -358,13 +468,37 @@ appropriate accounts and **not** apply them to the `debits_posted` and
|
|
|
358
468
|
`credits_posted` balances.
|
|
359
469
|
|
|
360
470
|
```javascript
|
|
361
|
-
|
|
362
|
-
id:
|
|
363
|
-
pending_id:
|
|
471
|
+
let transfer4 = {
|
|
472
|
+
id: 4n,
|
|
473
|
+
pending_id: 0n,
|
|
474
|
+
debit_account_id: 102n,
|
|
475
|
+
credit_account_id: 103n,
|
|
476
|
+
user_data: 0n,
|
|
477
|
+
reserved: 0n,
|
|
478
|
+
timeout: 0n,
|
|
479
|
+
ledger: 1,
|
|
480
|
+
code: 720,
|
|
481
|
+
flags: TransferFlags.pending,
|
|
482
|
+
amount: 10n,
|
|
483
|
+
timestamp: 0n,
|
|
484
|
+
};
|
|
485
|
+
transferErrors = await client.createTransfers([transfer4]);
|
|
486
|
+
|
|
487
|
+
let transfer5 = {
|
|
488
|
+
id: 7n,
|
|
489
|
+
pending_id: 6n,
|
|
490
|
+
debit_account_id: 102n,
|
|
491
|
+
credit_account_id: 103n,
|
|
492
|
+
user_data: 0n,
|
|
493
|
+
reserved: 0n,
|
|
494
|
+
timeout: 0n,
|
|
495
|
+
ledger: 1,
|
|
496
|
+
code: 720,
|
|
364
497
|
flags: TransferFlags.void_pending_transfer,
|
|
498
|
+
amount: 10n,
|
|
365
499
|
timestamp: 0n,
|
|
366
500
|
};
|
|
367
|
-
transferErrors = await client.createTransfers([
|
|
501
|
+
transferErrors = await client.createTransfers([transfer5]);
|
|
368
502
|
```
|
|
369
503
|
|
|
370
504
|
## Transfer Lookup
|
|
@@ -388,8 +522,8 @@ console.log(transfers);
|
|
|
388
522
|
* [{
|
|
389
523
|
* id: 1n,
|
|
390
524
|
* pending_id: 0n,
|
|
391
|
-
* debit_account_id:
|
|
392
|
-
* credit_account_id:
|
|
525
|
+
* debit_account_id: 102n,
|
|
526
|
+
* credit_account_id: 103n,
|
|
393
527
|
* user_data: 0n,
|
|
394
528
|
* reserved: 0n,
|
|
395
529
|
* timeout: 0n,
|
|
@@ -423,7 +557,7 @@ chain will have their error result set to `linked_event_failed`.
|
|
|
423
557
|
```javascript
|
|
424
558
|
const batch = [];
|
|
425
559
|
let linkedFlag = 0;
|
|
426
|
-
linkedFlag |=
|
|
560
|
+
linkedFlag |= TransferFlags.linked;
|
|
427
561
|
|
|
428
562
|
// An individual transfer (successful):
|
|
429
563
|
batch.push({ id: 1n /* , ... */ });
|
|
@@ -469,9 +603,9 @@ const errors = await client.createTransfers(batch);
|
|
|
469
603
|
In a POSIX shell run:
|
|
470
604
|
|
|
471
605
|
```console
|
|
472
|
-
$ git clone https://github.com
|
|
606
|
+
$ git clone https://github.com/tigerbeetledb/tigerbeetle
|
|
473
607
|
$ cd tigerbeetle
|
|
474
|
-
$ git
|
|
608
|
+
$ git submodule update --init --recursive
|
|
475
609
|
$ ./scripts/install_zig.sh
|
|
476
610
|
$ cd src/clients/node
|
|
477
611
|
$ npm install --include dev
|
|
Binary file
|
|
Binary file
|