tigerbeetle-node 0.11.11 → 0.11.13

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 (64) hide show
  1. package/README.md +212 -196
  2. package/dist/.client.node.sha256 +1 -1
  3. package/package.json +6 -8
  4. package/scripts/build_lib.sh +22 -2
  5. package/src/node.zig +1 -0
  6. package/src/tigerbeetle/scripts/benchmark.bat +9 -5
  7. package/src/tigerbeetle/scripts/benchmark.sh +1 -4
  8. package/src/tigerbeetle/scripts/fail_on_diff.sh +9 -0
  9. package/src/tigerbeetle/scripts/fuzz_loop_hash_log.sh +12 -0
  10. package/src/tigerbeetle/scripts/scripts/benchmark.bat +55 -0
  11. package/src/tigerbeetle/scripts/scripts/benchmark.sh +66 -0
  12. package/src/tigerbeetle/scripts/scripts/confirm_image.sh +44 -0
  13. package/src/tigerbeetle/scripts/scripts/fail_on_diff.sh +9 -0
  14. package/src/tigerbeetle/scripts/scripts/fuzz_loop.sh +15 -0
  15. package/src/tigerbeetle/scripts/scripts/fuzz_loop_hash_log.sh +12 -0
  16. package/src/tigerbeetle/scripts/scripts/fuzz_unique_errors.sh +7 -0
  17. package/src/tigerbeetle/scripts/scripts/install.bat +7 -0
  18. package/src/tigerbeetle/scripts/scripts/install.sh +21 -0
  19. package/src/tigerbeetle/scripts/scripts/install_zig.bat +113 -0
  20. package/src/tigerbeetle/scripts/scripts/install_zig.sh +90 -0
  21. package/src/tigerbeetle/scripts/scripts/lint.zig +199 -0
  22. package/src/tigerbeetle/scripts/scripts/pre-commit.sh +9 -0
  23. package/src/tigerbeetle/scripts/scripts/shellcheck.sh +5 -0
  24. package/src/tigerbeetle/scripts/scripts/tests_on_alpine.sh +10 -0
  25. package/src/tigerbeetle/scripts/scripts/tests_on_ubuntu.sh +14 -0
  26. package/src/tigerbeetle/scripts/scripts/upgrade_ubuntu_kernel.sh +48 -0
  27. package/src/tigerbeetle/scripts/scripts/validate_docs.sh +23 -0
  28. package/src/tigerbeetle/scripts/scripts/vr_state_enumerate +46 -0
  29. package/src/tigerbeetle/src/benchmark.zig +253 -231
  30. package/src/tigerbeetle/src/config.zig +2 -3
  31. package/src/tigerbeetle/src/constants.zig +2 -10
  32. package/src/tigerbeetle/src/io/linux.zig +15 -6
  33. package/src/tigerbeetle/src/lsm/forest.zig +1 -0
  34. package/src/tigerbeetle/src/lsm/forest_fuzz.zig +63 -14
  35. package/src/tigerbeetle/src/lsm/groove.zig +134 -70
  36. package/src/tigerbeetle/src/lsm/level_iterator.zig +2 -2
  37. package/src/tigerbeetle/src/lsm/manifest_level.zig +1 -0
  38. package/src/tigerbeetle/src/lsm/posted_groove.zig +7 -4
  39. package/src/tigerbeetle/src/lsm/segmented_array.zig +1 -0
  40. package/src/tigerbeetle/src/lsm/table.zig +29 -51
  41. package/src/tigerbeetle/src/lsm/table_immutable.zig +6 -17
  42. package/src/tigerbeetle/src/lsm/table_iterator.zig +2 -2
  43. package/src/tigerbeetle/src/lsm/table_mutable.zig +9 -26
  44. package/src/tigerbeetle/src/lsm/test.zig +1 -0
  45. package/src/tigerbeetle/src/lsm/tree.zig +2 -26
  46. package/src/tigerbeetle/src/lsm/tree_fuzz.zig +7 -2
  47. package/src/tigerbeetle/src/message_bus.zig +2 -1
  48. package/src/tigerbeetle/src/simulator.zig +14 -3
  49. package/src/tigerbeetle/src/state_machine/auditor.zig +1 -0
  50. package/src/tigerbeetle/src/state_machine.zig +402 -184
  51. package/src/tigerbeetle/src/stdx.zig +32 -0
  52. package/src/tigerbeetle/src/testing/cluster/network.zig +6 -7
  53. package/src/tigerbeetle/src/testing/cluster.zig +6 -5
  54. package/src/tigerbeetle/src/testing/packet_simulator.zig +19 -10
  55. package/src/tigerbeetle/src/testing/state_machine.zig +1 -0
  56. package/src/tigerbeetle/src/unit_tests.zig +20 -22
  57. package/src/tigerbeetle/src/vsr/README.md +209 -0
  58. package/src/tigerbeetle/src/vsr/client.zig +4 -4
  59. package/src/tigerbeetle/src/vsr/clock.zig +2 -0
  60. package/src/tigerbeetle/src/vsr/journal.zig +2 -0
  61. package/src/tigerbeetle/src/vsr/replica.zig +646 -578
  62. package/src/tigerbeetle/src/vsr/superblock.zig +14 -17
  63. package/src/tigerbeetle/src/vsr/superblock_fuzz.zig +5 -5
  64. package/src/tigerbeetle/src/vsr.zig +370 -37
package/README.md CHANGED
@@ -1,12 +1,34 @@
1
+ This file is generated by
2
+ [src/clients/docs_generate.zig](/src/clients/docs_generate.zig).
3
+
1
4
  # tigerbeetle-node
2
- [TigerBeetle](https://github.com/tigerbeetledb/tigerbeetle) client for Node.js.
3
5
 
4
- ## Installation
6
+ The TigerBeetle client for Node.js.
7
+
8
+ ### Prerequisites
9
+
10
+ * NodeJS >= `14`
11
+
12
+ > Your operating system should be Linux (kernel >= v5.6) or macOS.
13
+ > Windows support is not yet available.
14
+
15
+ ## Setup
16
+
17
+ ```console
18
+ $ npm install tigerbeetle-node
19
+ ```
5
20
 
6
- Install the `tigerbeetle-node` module to your current working directory:
21
+ Create `test.js` and copy this into it:
7
22
 
8
- ```shell
9
- npm install tigerbeetle-node
23
+ ```javascript
24
+ const { createClient } = require("tigerbeetle-node");
25
+ console.log("Import ok!");
26
+ ```
27
+
28
+ And run:
29
+
30
+ ```console
31
+ $ node run test.js
10
32
  ```
11
33
 
12
34
  If you run into issues, check out the distribution-specific install
@@ -19,79 +41,68 @@ steps that are run in CI to test support:
19
41
  * [Ubuntu](./scripts/test_install_on_ubuntu.sh)
20
42
  * [RHEL](./scripts/test_install_on_rhelubi.sh)
21
43
 
22
- ### Prerequisites
23
-
24
- * NodeJS >= `14.0.0`. _(If the correct version is not installed, an installation error will occur)_
25
-
26
- > Your operating system should be Linux (kernel >= v5.6) or macOS.
27
- > Windows support is not yet available.
44
+ ### Sidenote: `BigInt`
45
+ TigerBeetle uses 64-bit integers for many fields while JavaScript's
46
+ builtin `Number` maximum value is `2^53-1`. The `n` suffix in JavaScript
47
+ means the value is a `BigInt`. This is useful for literal numbers. If
48
+ you already have a `Number` variable though, you can call the `BigInt`
49
+ constructor to get a `BigInt` from it. For example, `1n` is the same as
50
+ `BigInt(1)`.
28
51
 
29
- ## Usage
52
+ ## Creating a Client
30
53
 
31
- A client needs to be configured with a `cluster_id` and `replica_addresses`.
32
- This instantiates the client where memory is allocated to internally buffer events to be sent.
33
- For the moment, only one client can be instantiated globally per process.
34
- Future releases will allow multiple client instantiations.
54
+ A client is created with a cluster ID and replica
55
+ addresses for all replicas in the cluster. The cluster
56
+ ID and replica addresses are both chosen by the system that
57
+ starts the TigerBeetle cluster.
35
58
 
36
- ```js
37
- const {
38
- createClient,
39
- CreateAccountError,
40
- CreateTransferError,
41
- AccountFlags,
42
- TransferFlags,
43
- } = require('tigerbeetle-node');
59
+ In this example the cluster ID is `0` and there are
60
+ three replicas running on ports `3001`, `3002`, and
61
+ `3003`.
44
62
 
63
+ ```javascript
45
64
  const client = createClient({
46
65
  cluster_id: 0,
47
66
  replica_addresses: ['3001', '3002', '3003']
48
67
  });
49
68
  ```
50
69
 
51
- One of the ways TigerBeetle achieves its performance is through
52
- batching. This is reflected in the below function interfaces where
53
- each one takes in an array of items.
70
+ The following are valid addresses:
71
+ * `3000` (interpreted as `127.0.0.1:3000`)
72
+ * `127.0.0.1:3000` (interpreted as `127.0.0.1:3000`)
73
+ * `127.0.0.1` (interpreted as `127.0.0.1:3001`, `3001` is the default port)
54
74
 
55
- ### Sidenote: `BigInt`
56
-
57
- TigerBeetle uses 64-bit integers for many fields while JavaScript's
58
- builtin `Number` maximum value is 2^53-1. The `n` suffix in JavaScript
59
- means the value is a BigInt. This is useful for literal numbers. If
60
- you already have a `Number` variable though, you can call the `BigInt`
61
- constructor to get a `BigInt` from it. For example, `1n` is the same
62
- as `BigInt(1)`.
63
-
64
- ## Creating Accounts: `client.createAccounts`
75
+ ## Creating Accounts
65
76
 
66
77
  See details for account fields in the [Accounts
67
78
  reference](https://docs.tigerbeetle.com/reference/accounts).
68
79
 
69
- ```js
70
- const account = {
71
- id: 137n, // u128
72
- user_data: 0n, // u128, opaque third-party identifier to link this account to an external entity:
73
- reserved: Buffer.alloc(48, 0), // [48]u8
74
- ledger: 1, // u32, ledger value
75
- code: 718, // u16, a chart of accounts code describing the type of account (e.g. clearing, settlement)
76
- flags: 0, // u16
77
- debits_pending: 0n, // u64
78
- debits_posted: 0n, // u64
79
- credits_pending: 0n, // u64
80
- credits_posted: 0n, // u64
81
- timestamp: 0n, // u64, Reserved: This will be set by the server.
80
+ ```javascript
81
+ let account = {
82
+ id: 137n,
83
+ user_data: 0n,
84
+ reserved: Buffer.alloc(48, 0),
85
+ ledger: 1,
86
+ code: 718,
87
+ flags: 0,
88
+ debits_pending: 0n,
89
+ debits_posted: 0n,
90
+ credits_pending: 0n,
91
+ credits_posted: 0n,
92
+ timestamp: 0n,
82
93
  };
83
94
 
84
- const errors = await client.createAccounts([account]);
85
- if (errors.length) {
95
+ let accountErrors = await client.createAccounts([account]);
96
+ if (accountErrors.length) {
86
97
  // Grab a human-readable message from the response
87
- console.log(CreateAccountError[errors[0].code]);
98
+ console.log(CreateAccountError[accountErrors[0].code]);
88
99
  }
89
100
  ```
90
101
 
91
102
  ### Account Flags
92
103
 
93
- The account `flags` value is a bitfield. See details for these flags in
94
- the [Accounts
104
+ The account flags value is a bitfield. See details for
105
+ these flags in the [Accounts
95
106
  reference](https://docs.tigerbeetle.com/reference/accounts#flags).
96
107
 
97
108
  To toggle behavior for an account, combine enum values stored in the
@@ -102,30 +113,34 @@ bitwise-or:
102
113
  * `AccountFlags.debits_must_not_exceed_credits`
103
114
  * `AccountFlags.credits_must_not_exceed_credits`
104
115
 
116
+
105
117
  For example, to link `account0` and `account1`, where `account0`
106
118
  additionally has the `debits_must_not_exceed_credits` constraint:
107
119
 
108
- ```js
109
- const account0 = { ... account values ... };
110
- const account1 = { ... account values ... };
120
+ ```javascript
121
+ let account0 = { /* ... account values ... */ };
122
+ let account1 = { /* ... account values ... */ };
111
123
  account0.flags = AccountFlags.linked | AccountFlags.debits_must_not_exceed_credits;
112
- // Create the account
113
- const errors = client.createAccounts([account0, account1]);
124
+ accountErrors = await client.createAccounts([account0, account1]);
114
125
  ```
115
126
 
116
127
  ### Response and Errors
117
128
 
118
- The response is an empty array if all accounts were created
119
- successfully. If the response is non-empty, each object in the
120
- response array contains error information for an account that
121
- failed. The error object contains an error code and the index of the
122
- account in the request batch.
129
+ The response is an empty array if all accounts were
130
+ created successfully. If the response is non-empty, each
131
+ object in the response array contains error information
132
+ for an account that failed. The error object contains an
133
+ error code and the index of the account in the request
134
+ batch.
135
+
136
+ See all error conditions in the [create_accounts
137
+ reference](https://docs.tigerbeetle.com/reference/operations/create_accounts).
123
138
 
124
- ```js
125
- const errors = await client.createAccounts([account1, account2, account3]);
139
+ ```javascript
140
+ accountErrors = await client.createAccounts([account1, account2, account3]);
126
141
 
127
- // errors = [{ index: 1, code: 1 }];
128
- for (const error of errors) {
142
+ // accountErrors = [{ index: 1, code: 1 }];
143
+ for (const error of accountErrors) {
129
144
  switch (error.code) {
130
145
  case CreateAccountError.exists:
131
146
  console.error(`Batch account at ${error.index} already exists.`);
@@ -136,29 +151,33 @@ for (const error of errors) {
136
151
  }
137
152
  ```
138
153
 
139
- The example above shows that the account in index 1 failed with
140
- error 1. This error here means that `account1` and `account3` were
141
- created successfully. But `account2` was not created.
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.
142
158
 
143
159
  To handle errors you can either 1) exactly match error codes returned
144
160
  from `client.createAccounts` with enum values in the
145
161
  `CreateAccountError` object, or you can 2) look up the error code in
146
162
  the `CreateAccountError` object for a human-readable string.
147
163
 
148
- ## Account Lookup: `client.lookupAccounts`
164
+ ## Account Lookup
149
165
 
150
- Account lookup is batched, like account creation. Pass in all `id`s to
151
- fetch, and matched accounts are returned.
166
+ Account lookup is batched, like account creation. Pass
167
+ in all IDs to fetch. The account for each matched ID is returned.
152
168
 
153
- If no account matches an `id`, no object is returned for that
154
- account. So the order of accounts in the response is not necessarily
155
- the same as the order of `id`s in the request. You can refer to the
156
- `id` field in the response to distinguish accounts.
169
+ If no account matches an ID, no object is returned for
170
+ that account. So the order of accounts in the response is
171
+ not necessarily the same as the order of IDs in the
172
+ request. You can refer to the ID field in the response to
173
+ distinguish accounts.
174
+
175
+ In this example, transfer `137` exists while transfer `138` does not.
157
176
 
158
- ```js
159
- // account 137n exists, 138n does not
177
+ ```javascript
160
178
  const accounts = await client.lookupAccounts([137n, 138n]);
161
- /* console.log(accounts);
179
+ console.log(accounts);
180
+ /*
162
181
  * [{
163
182
  * id: 137n,
164
183
  * user_data: 0n,
@@ -175,41 +194,29 @@ const accounts = await client.lookupAccounts([137n, 138n]);
175
194
  */
176
195
  ```
177
196
 
178
- ## Creating Transfers: `client.createTransfers`
197
+ ## Create Transfers
179
198
 
180
199
  This creates a journal entry between two accounts.
181
200
 
182
201
  See details for transfer fields in the [Transfers
183
202
  reference](https://docs.tigerbeetle.com/reference/transfers).
184
203
 
185
- ```js
186
- const transfer = {
187
- id: 1n, // u128
188
- pending_id: 0n, // u128
189
- // Double-entry accounting:
190
- debit_account_id: 1n, // u128
191
- credit_account_id: 2n, // u128
192
- // Opaque third-party identifier to link this transfer to an external entity:
193
- user_data: 0n, // u128
194
- reserved: 0n, // u128
195
- // Timeout applicable for a pending/2-phase transfer:
196
- timeout: 0n, // u64, in nano-seconds.
197
- // Collection of accounts usually grouped by the currency:
198
- // You can't transfer money between accounts with different ledgers:
199
- ledger: 1, // u32, ledger for transfer (e.g. currency).
200
- // Chart of accounts code describing the reason for the transfer:
201
- code: 720, // u16, (e.g. deposit, settlement)
202
- flags: 0, // u16
203
- amount: 10n, // u64
204
- timestamp: 0n, //u64, Reserved: This will be set by the server.
204
+ ```javascript
205
+ let transfer = {
206
+ id: 1n,
207
+ pending_id: 0n,
208
+ debit_account_id: 1n,
209
+ credit_account_id: 2n,
210
+ user_data: 0n,
211
+ reserved: 0n,
212
+ timeout: 0n,
213
+ ledger: 1,
214
+ code: 720,
215
+ flags: 0,
216
+ amount: 10n,
217
+ timestamp: 0n,
205
218
  };
206
- const errors = await client.createTransfers([transfer]);
207
- for (const error of errors) {
208
- switch (error.code) {
209
- default:
210
- console.error(`Batch transfer at ${error.index} failed to create: ${CreateAccountError[error.code]}.`);
211
- }
212
- }
219
+ let transferErrors = await client.createTransfers([transfer]);
213
220
  ```
214
221
 
215
222
  ### Response and Errors
@@ -220,11 +227,11 @@ response array contains error information for an transfer that
220
227
  failed. The error object contains an error code and the index of the
221
228
  transfer in the request batch.
222
229
 
223
- ```js
224
- const errors = await client.createTransfers([transfer1, transfer2, transfer3]);
230
+ See all error conditions in the [create_transfers
231
+ reference](https://docs.tigerbeetle.com/reference/operations/create_transfers).
225
232
 
226
- // errors = [{ index: 1, code: 1 }];
227
- for (const error of errors) {
233
+ ```javascript
234
+ for (const error of transferErrors) {
228
235
  switch (error.code) {
229
236
  case CreateTransferError.exists:
230
237
  console.error(`Batch transfer at ${error.index} already exists.`);
@@ -235,41 +242,40 @@ for (const error of errors) {
235
242
  }
236
243
  ```
237
244
 
238
- The example above shows that the transfer in index 1 failed with
239
- error 1. This error here means that `transfer1` and `transfer3` were
240
- created successfully. But `transfer2` was not created.
241
-
242
245
  To handle errors you can either 1) exactly match error codes returned
243
246
  from `client.createTransfers` with enum values in the
244
247
  `CreateTransferError` object, or you can 2) look up the error code in
245
248
  the `CreateTransferError` object for a human-readable string.
246
249
 
247
- ### Batching
250
+ ## Batching
248
251
 
249
- TigerBeetle performance is maximized when you batch inserts. The
250
- client does not do this automatically for you. So, for example, you
251
- can insert 1 million transfers one at a time like so:
252
+ TigerBeetle performance is maximized when you batch
253
+ API requests. The client does not do this automatically for
254
+ you. So, for example, you *can* insert 1 million transfers
255
+ one at a time like so:
252
256
 
253
- ```js
254
- for (let i = 0; i < 1_000_000; i++) {
255
- const errors = client.createTransfers(transfers[i]);
257
+ ```javascript
258
+ for (let i = 0; i < transfers.len; i++) {
259
+ const transferErrors = await client.createTransfers(transfers[i]);
256
260
  // error handling omitted
257
261
  }
258
262
  ```
259
263
 
260
- But the insert rate will be a fraction of potential. Instead, always
261
- batch what you can. The maximum batch size is set in the TigerBeetle
262
- server. The default is 8191.
264
+ But the insert rate will be a *fraction* of
265
+ potential. Instead, **always batch what you can**.
263
266
 
264
- ```js
267
+ The maximum batch size is set in the TigerBeetle server. The default
268
+ is 8191.
269
+
270
+ ```javascript
265
271
  const BATCH_SIZE = 8191;
266
- for (let i = 0; i < 1_000_000; i += BATCH_SIZE) {
267
- const errors = client.createTransfers(transfers.slice(i, Math.min(transfers.length, BATCH_SIZE)));
272
+ for (let i = 0; i < transfers.length; i += BATCH_SIZE) {
273
+ const transferErrors = await client.createTransfers(transfers.slice(i, Math.min(transfers.length, BATCH_SIZE)));
268
274
  // error handling omitted
269
275
  }
270
276
  ```
271
277
 
272
- ### Transfer Flags
278
+ ## Transfer Flags
273
279
 
274
280
  The transfer `flags` value is a bitfield. See details for these flags in
275
281
  the [Transfers
@@ -286,15 +292,15 @@ bitwise-or:
286
292
 
287
293
  For example, to link `transfer0` and `transfer1`:
288
294
 
289
- ```js
290
- const transfer0 = { ... transfer values ... };
291
- const transfer1 = { ... transfer values ... };
295
+ ```javascript
296
+ transfer0 = { /* ... transfer values ... */ };
297
+ transfer1 = { /* ... transfer values ... */ };
292
298
  transfer0.flags = TransferFlags.linked;
293
299
  // Create the transfer
294
- const errors = client.createTransfers([transfer0, transfer1]);
300
+ transferErrors = await client.createTransfers([transfer0, transfer1]);
295
301
  ```
296
302
 
297
- #### Two-Phase Transfers
303
+ ### Two-Phase Transfers
298
304
 
299
305
  Two-phase transfers are supported natively by toggling the appropriate
300
306
  flag. TigerBeetle will then adjust the `credits_pending` and
@@ -302,25 +308,43 @@ flag. TigerBeetle will then adjust the `credits_pending` and
302
308
  post pending transfer then needs to be sent to post or void the
303
309
  transfer.
304
310
 
305
- ##### Post a Pending Transfer
311
+ #### Post a Pending Transfer
306
312
 
307
- With `transfer.flags == TransferFlags.post_pending_transfer`,
313
+ With `flags` set to `post_pending_transfer`,
308
314
  TigerBeetle will post the transfer. TigerBeetle will atomically roll
309
315
  back the changes to `debits_pending` and `credits_pending` of the
310
316
  appropriate accounts and apply them to the `debits_posted` and
311
317
  `credits_posted` balances.
312
318
 
313
- ```js
314
- const post = {
315
- id: 2n, // u128, must correspond to the transfer id
316
- pending_id: 1n, // u128, id of the pending transfer
317
- flags: TransferFlags.post_pending_transfer, // to void, use [void_pending_transfer]
318
- timestamp: 0n, // u64, Reserved: This will be set by the server.
319
- }
320
- const errors = await client.createTransfers([post])
319
+ ```javascript
320
+ transfer = {
321
+ id: 2n,
322
+ pending_id: 1n,
323
+ flags: TransferFlags.post_pending_transfer,
324
+ timestamp: 0n,
325
+ };
326
+ transferErrors = await client.createTransfers([transfer]);
321
327
  ```
322
328
 
323
- ## Transfer Lookup: `client.lookupTransfers`
329
+ #### Void a Pending Transfer
330
+
331
+ In contrast, with `flags` set to `void_pending_transfer`,
332
+ TigerBeetle will void the transfer. TigerBeetle will roll
333
+ back the changes to `debits_pending` and `credits_pending` of the
334
+ appropriate accounts and **not** apply them to the `debits_posted` and
335
+ `credits_posted` balances.
336
+
337
+ ```javascript
338
+ transfer = {
339
+ id: 2n,
340
+ pending_id: 1n,
341
+ flags: TransferFlags.void_pending_transfer,
342
+ timestamp: 0n,
343
+ };
344
+ transferErrors = await client.createTransfers([transfer]);
345
+ ```
346
+
347
+ ## Transfer Lookup
324
348
 
325
349
  NOTE: While transfer lookup exists, it is not a flexible query API. We
326
350
  are developing query APIs and there will be new methods for querying
@@ -334,10 +358,12 @@ transfer. So the order of transfers in the response is not necessarily
334
358
  the same as the order of `id`s in the request. You can refer to the
335
359
  `id` field in the response to distinguish transfers.
336
360
 
337
- ```js
338
- // transfer 1n exists, 2n does not
361
+ In this example, transfer `1` exists while transfer `2` does not.
362
+
363
+ ```javascript
339
364
  const transfers = await client.lookupTransfers([1n, 2n]);
340
- /* console.log(transfers);
365
+ console.log(transfers);
366
+ /*
341
367
  * [{
342
368
  * id: 1n,
343
369
  * pending_id: 0n,
@@ -357,8 +383,8 @@ const transfers = await client.lookupTransfers([1n, 2n]);
357
383
 
358
384
  ## Linked Events
359
385
 
360
- When the `linked` flag is specified for the `createAccount` or
361
- `createTransfer` event, it links an event with the next event in the
386
+ When the `linked` flag is specified for an account when creating accounts or
387
+ a transfer when creating transfers, it links that event with the next event in the
362
388
  batch, to create a chain of events, of arbitrary length, which all
363
389
  succeed or fail together. The tail of a chain is denoted by the first
364
390
  event without this flag. The last event in a batch may therefore never
@@ -373,35 +399,36 @@ to subsequent events after the chain. The event that was the first to
373
399
  break the chain will have a unique error result. Other events in the
374
400
  chain will have their error result set to `linked_event_failed`.
375
401
 
376
- ```js
377
- let batch = []
378
- let linkedFlag = 0
379
- linkedFlag |= CreateTransferFlags.linked
402
+ ```javascript
403
+ const batch = [];
404
+ let linkedFlag = 0;
405
+ linkedFlag |= CreateTransferFlags.linked;
380
406
 
381
407
  // An individual transfer (successful):
382
- batch.push({ id: 1n, ... })
408
+ batch.push({ id: 1n /* , ... */ });
383
409
 
384
410
  // A chain of 4 transfers (the last transfer in the chain closes the chain with linked=false):
385
- batch.push({ id: 2n, ..., flags: linkedFlag }) // Commit/rollback.
386
- batch.push({ id: 3n, ..., flags: linkedFlag }) // Commit/rollback.
387
- batch.push({ id: 2n, ..., flags: linkedFlag }) // Fail with exists
388
- batch.push({ id: 4n, ..., flags: 0 }) // Fail without committing.
411
+ batch.push({ id: 2n, /* ..., */ flags: linkedFlag }); // Commit/rollback.
412
+ batch.push({ id: 3n, /* ..., */ flags: linkedFlag }); // Commit/rollback.
413
+ batch.push({ id: 2n, /* ..., */ flags: linkedFlag }); // Fail with exists
414
+ batch.push({ id: 4n, /* ..., */ flags: 0 }); // Fail without committing.
389
415
 
390
416
  // An individual transfer (successful):
391
417
  // This should not see any effect from the failed chain above.
392
- batch.push({ id: 2n, ..., flags: 0 })
418
+ batch.push({ id: 2n, /* ..., */ flags: 0 });
393
419
 
394
420
  // A chain of 2 transfers (the first transfer fails the chain):
395
- batch.push({ id: 2n, ..., flags: linkedFlag })
396
- batch.push({ id: 3n, ..., flags: 0 })
421
+ batch.push({ id: 2n, /* ..., */ flags: linkedFlag });
422
+ batch.push({ id: 3n, /* ..., */ flags: 0 });
397
423
 
398
424
  // A chain of 2 transfers (successful):
399
- batch.push({ id: 3n, ..., flags: linkedFlag })
400
- batch.push({ id: 4n, ..., flags: 0 })
425
+ batch.push({ id: 3n, /* ..., */ flags: linkedFlag });
426
+ batch.push({ id: 4n, /* ..., */ flags: 0 });
401
427
 
402
- const errors = await client.createTransfers(batch)
428
+ const errors = await client.createTransfers(batch);
403
429
 
404
430
  /**
431
+ * console.log(errors);
405
432
  * [
406
433
  * { index: 1, error: 1 }, // linked_event_failed
407
434
  * { index: 2, error: 1 }, // linked_event_failed
@@ -414,38 +441,27 @@ const errors = await client.createTransfers(batch)
414
441
  */
415
442
  ```
416
443
 
417
- ### Development
444
+ ## Development Setup
418
445
 
419
- To get up and running when cloning the repo:
446
+ ### On Linux and macOS
420
447
 
421
- ```shell
422
- git clone --recurse-submodules https://github.com/tigerbeetledb/tigerbeetle-node.git
423
- cd tigerbeetle-node/
424
- npm install --include dev # This will automatically install and build everything you need.
448
+ ```console
449
+ $ git clone https://github.com/tigerbeetledb/tigerbeetle
450
+ $ cd tigerbeetle
451
+ $ ./scripts/install_zig.sh
452
+ $ cd src/clients/node
453
+ $ npm install --include dev
454
+ $ npm pack
425
455
  ```
426
456
 
427
- #### Rebuild
428
-
429
- To rebuild the TypeScript distribution, and to rebuild the native Node library, again after changes:
457
+ ### On Windows
430
458
 
431
- ```shell
432
- npm run build
459
+ ```console
460
+ $ git clone https://github.com/tigerbeetledb/tigerbeetle
461
+ $ cd tigerbeetle
462
+ $ ./scripts/install_zig.bat
463
+ $ npm install --include dev # NOTE! This does not work at the moment (on Windows).
464
+ $ cd src/clients/node
465
+ $ npm pack
433
466
  ```
434
467
 
435
- *If you ever run `npm run clean` then you will need to `npm install --include dev` to reinstall
436
- TypeScript within `node_modules`, as TypeScript is required by `npm run prepack` when publishing.*
437
-
438
- #### Benchmark
439
-
440
- ```shell
441
- npm run benchmark
442
- ```
443
-
444
- #### Test
445
-
446
- ```shell
447
- ./tigerbeetle format --cluster=0 --replica=0 ./cluster_0_replica_0_test.tigerbeetle
448
- ./tigerbeetle start --addresses=3001 ./cluster_0_replica_0_test.tigerbeetle > tigerbeetle_test.log 2>&1
449
- npm run test
450
- ```
451
- For more information, type; `./tigerbeetle -h`
@@ -1 +1 @@
1
- 21c6105d76e0efc68fe5cbe799d363a083a9b44359e16d7dbfbb172e381ea0c3 dist/client.node
1
+ dc919aef39f18dc4a76aea2029dd29963d9b7139459558b2d6691c68a80d622c dist/client.node
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "tigerbeetle-node",
3
- "version": "0.11.11",
3
+ "version": "0.11.13",
4
4
  "description": "TigerBeetle Node.js client",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/tigerbeetledb/tigerbeetle-node.git"
9
+ "url": "git+https://github.com/tigerbeetledb/tigerbeetle.git",
10
+ "directory": "src/clients/node"
10
11
  },
11
12
  "preferUnplugged": true,
12
13
  "files": [
@@ -24,9 +25,7 @@
24
25
  "src/index.ts",
25
26
  "src/node.zig",
26
27
  "src/test.ts",
27
- "src/tigerbeetle/src/*.zig",
28
- "src/tigerbeetle/src/{c,io,lsm,testing,vsr,state_machine}",
29
- "src/tigerbeetle/scripts",
28
+ "src/tigerbeetle",
30
29
  "src/translate.zig",
31
30
  "tsconfig.json"
32
31
  ],
@@ -36,13 +35,12 @@
36
35
  "scripts": {
37
36
  "benchmark": "./scripts/benchmark.sh",
38
37
  "test": "node dist/test",
39
- "postinstall": "npm run install_zig && npm run download_node_headers && npm run build_lib",
40
- "install_zig": "sh ./src/tigerbeetle/scripts/install_zig.sh",
38
+ "postinstall": "npm run download_node_headers && npm run build_lib",
41
39
  "download_node_headers": "sh ./scripts/download_node_headers.sh",
42
40
  "build": "npm run build_tsc && npm run build_lib",
43
41
  "build_tsc": "./node_modules/typescript/bin/tsc",
44
42
  "build_lib": "sh ./scripts/build_lib.sh",
45
- "prepack": "npm run build_tsc",
43
+ "prepack": "npm run build",
46
44
  "clean": "rm -rf build dist node_modules src/zig-cache zig"
47
45
  },
48
46
  "author": "TigerBeetle, Inc",