tigerbeetle-node 0.11.9 → 0.11.11

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.
@@ -1 +1 @@
1
- ed71bbee01e27a1f4638bfc2b0542414c1fc8b503bce5bbcc45ae2b80b1edb26 dist/client.node
1
+ 21c6105d76e0efc68fe5cbe799d363a083a9b44359e16d7dbfbb172e381ea0c3 dist/client.node
package/dist/index.d.ts CHANGED
@@ -25,22 +25,23 @@ export declare enum AccountFlags {
25
25
  export declare enum CreateAccountError {
26
26
  linked_event_failed = 1,
27
27
  linked_event_chain_open = 2,
28
- reserved_flag = 3,
29
- reserved_field = 4,
30
- id_must_not_be_zero = 5,
31
- id_must_not_be_int_max = 6,
32
- ledger_must_not_be_zero = 7,
33
- code_must_not_be_zero = 8,
34
- debits_pending_must_be_zero = 9,
35
- debits_posted_must_be_zero = 10,
36
- credits_pending_must_be_zero = 11,
37
- credits_posted_must_be_zero = 12,
38
- mutually_exclusive_flags = 13,
39
- exists_with_different_flags = 14,
40
- exists_with_different_user_data = 15,
41
- exists_with_different_ledger = 16,
42
- exists_with_different_code = 17,
43
- exists = 18
28
+ timestamp_must_be_zero = 3,
29
+ reserved_flag = 4,
30
+ reserved_field = 5,
31
+ id_must_not_be_zero = 6,
32
+ id_must_not_be_int_max = 7,
33
+ ledger_must_not_be_zero = 8,
34
+ code_must_not_be_zero = 9,
35
+ debits_pending_must_be_zero = 10,
36
+ debits_posted_must_be_zero = 11,
37
+ credits_pending_must_be_zero = 12,
38
+ credits_posted_must_be_zero = 13,
39
+ mutually_exclusive_flags = 14,
40
+ exists_with_different_flags = 15,
41
+ exists_with_different_user_data = 16,
42
+ exists_with_different_ledger = 17,
43
+ exists_with_different_code = 18,
44
+ exists = 19
44
45
  }
45
46
  export declare type CreateAccountsError = {
46
47
  index: number;
@@ -69,57 +70,59 @@ export declare enum TransferFlags {
69
70
  export declare enum CreateTransferError {
70
71
  linked_event_failed = 1,
71
72
  linked_event_chain_open = 2,
72
- reserved_flag = 3,
73
- reserved_field = 4,
74
- id_must_not_be_zero = 5,
75
- id_must_not_be_int_max = 6,
76
- debit_account_id_must_not_be_zero = 7,
77
- debit_account_id_must_not_be_int_max = 8,
78
- credit_account_id_must_not_be_zero = 9,
79
- credit_account_id_must_not_be_int_max = 10,
80
- accounts_must_be_different = 11,
81
- pending_id_must_be_zero = 12,
82
- ledger_must_not_be_zero = 13,
83
- code_must_not_be_zero = 14,
84
- amount_must_not_be_zero = 15,
85
- debit_account_not_found = 16,
86
- credit_account_not_found = 17,
87
- accounts_must_have_the_same_ledger = 18,
88
- transfer_must_have_the_same_ledger_as_accounts = 19,
89
- exists_with_different_flags = 20,
90
- exists_with_different_debit_account_id = 21,
91
- exists_with_different_credit_account_id = 22,
92
- exists_with_different_user_data = 23,
93
- exists_with_different_pending_id = 24,
94
- exists_with_different_timeout = 25,
95
- exists_with_different_code = 26,
96
- exists_with_different_amount = 27,
97
- exists = 28,
98
- overflows_debits_pending = 29,
99
- overflows_credits_pending = 30,
100
- overflows_debits_posted = 31,
101
- overflows_credits_posted = 32,
102
- overflows_debits = 33,
103
- overflows_credits = 34,
104
- exceeds_credits = 35,
105
- exceeds_debits = 36,
106
- cannot_post_and_void_pending_transfer = 37,
107
- pending_transfer_cannot_post_or_void_another = 38,
108
- timeout_reserved_for_pending_transfer = 39,
109
- pending_id_must_not_be_zero = 40,
110
- pending_id_must_not_be_int_max = 41,
111
- pending_id_must_be_different = 42,
112
- pending_transfer_not_found = 43,
113
- pending_transfer_not_pending = 44,
114
- pending_transfer_has_different_debit_account_id = 45,
115
- pending_transfer_has_different_credit_account_id = 46,
116
- pending_transfer_has_different_ledger = 47,
117
- pending_transfer_has_different_code = 48,
118
- exceeds_pending_transfer_amount = 49,
119
- pending_transfer_has_different_amount = 50,
120
- pending_transfer_already_posted = 51,
121
- pending_transfer_already_voided = 52,
122
- pending_transfer_expired = 53
73
+ timestamp_must_be_zero = 3,
74
+ reserved_flag = 4,
75
+ reserved_field = 5,
76
+ id_must_not_be_zero = 6,
77
+ id_must_not_be_int_max = 7,
78
+ debit_account_id_must_not_be_zero = 8,
79
+ debit_account_id_must_not_be_int_max = 9,
80
+ credit_account_id_must_not_be_zero = 10,
81
+ credit_account_id_must_not_be_int_max = 11,
82
+ accounts_must_be_different = 12,
83
+ pending_id_must_be_zero = 13,
84
+ ledger_must_not_be_zero = 14,
85
+ code_must_not_be_zero = 15,
86
+ amount_must_not_be_zero = 16,
87
+ debit_account_not_found = 17,
88
+ credit_account_not_found = 18,
89
+ accounts_must_have_the_same_ledger = 19,
90
+ transfer_must_have_the_same_ledger_as_accounts = 20,
91
+ exists_with_different_flags = 21,
92
+ exists_with_different_debit_account_id = 22,
93
+ exists_with_different_credit_account_id = 23,
94
+ exists_with_different_user_data = 24,
95
+ exists_with_different_pending_id = 25,
96
+ exists_with_different_timeout = 26,
97
+ exists_with_different_code = 27,
98
+ exists_with_different_amount = 28,
99
+ exists = 29,
100
+ overflows_debits_pending = 30,
101
+ overflows_credits_pending = 31,
102
+ overflows_debits_posted = 32,
103
+ overflows_credits_posted = 33,
104
+ overflows_debits = 34,
105
+ overflows_credits = 35,
106
+ overflows_timeout = 36,
107
+ exceeds_credits = 37,
108
+ exceeds_debits = 38,
109
+ cannot_post_and_void_pending_transfer = 39,
110
+ pending_transfer_cannot_post_or_void_another = 40,
111
+ timeout_reserved_for_pending_transfer = 41,
112
+ pending_id_must_not_be_zero = 42,
113
+ pending_id_must_not_be_int_max = 43,
114
+ pending_id_must_be_different = 44,
115
+ pending_transfer_not_found = 45,
116
+ pending_transfer_not_pending = 46,
117
+ pending_transfer_has_different_debit_account_id = 47,
118
+ pending_transfer_has_different_credit_account_id = 48,
119
+ pending_transfer_has_different_ledger = 49,
120
+ pending_transfer_has_different_code = 50,
121
+ exceeds_pending_transfer_amount = 51,
122
+ pending_transfer_has_different_amount = 52,
123
+ pending_transfer_already_posted = 53,
124
+ pending_transfer_already_voided = 54,
125
+ pending_transfer_expired = 55
123
126
  }
124
127
  export declare type CreateTransfersError = {
125
128
  index: number;
package/dist/index.js CHANGED
@@ -12,22 +12,23 @@ var CreateAccountError;
12
12
  (function (CreateAccountError) {
13
13
  CreateAccountError[CreateAccountError["linked_event_failed"] = 1] = "linked_event_failed";
14
14
  CreateAccountError[CreateAccountError["linked_event_chain_open"] = 2] = "linked_event_chain_open";
15
- CreateAccountError[CreateAccountError["reserved_flag"] = 3] = "reserved_flag";
16
- CreateAccountError[CreateAccountError["reserved_field"] = 4] = "reserved_field";
17
- CreateAccountError[CreateAccountError["id_must_not_be_zero"] = 5] = "id_must_not_be_zero";
18
- CreateAccountError[CreateAccountError["id_must_not_be_int_max"] = 6] = "id_must_not_be_int_max";
19
- CreateAccountError[CreateAccountError["ledger_must_not_be_zero"] = 7] = "ledger_must_not_be_zero";
20
- CreateAccountError[CreateAccountError["code_must_not_be_zero"] = 8] = "code_must_not_be_zero";
21
- CreateAccountError[CreateAccountError["debits_pending_must_be_zero"] = 9] = "debits_pending_must_be_zero";
22
- CreateAccountError[CreateAccountError["debits_posted_must_be_zero"] = 10] = "debits_posted_must_be_zero";
23
- CreateAccountError[CreateAccountError["credits_pending_must_be_zero"] = 11] = "credits_pending_must_be_zero";
24
- CreateAccountError[CreateAccountError["credits_posted_must_be_zero"] = 12] = "credits_posted_must_be_zero";
25
- CreateAccountError[CreateAccountError["mutually_exclusive_flags"] = 13] = "mutually_exclusive_flags";
26
- CreateAccountError[CreateAccountError["exists_with_different_flags"] = 14] = "exists_with_different_flags";
27
- CreateAccountError[CreateAccountError["exists_with_different_user_data"] = 15] = "exists_with_different_user_data";
28
- CreateAccountError[CreateAccountError["exists_with_different_ledger"] = 16] = "exists_with_different_ledger";
29
- CreateAccountError[CreateAccountError["exists_with_different_code"] = 17] = "exists_with_different_code";
30
- CreateAccountError[CreateAccountError["exists"] = 18] = "exists";
15
+ CreateAccountError[CreateAccountError["timestamp_must_be_zero"] = 3] = "timestamp_must_be_zero";
16
+ CreateAccountError[CreateAccountError["reserved_flag"] = 4] = "reserved_flag";
17
+ CreateAccountError[CreateAccountError["reserved_field"] = 5] = "reserved_field";
18
+ CreateAccountError[CreateAccountError["id_must_not_be_zero"] = 6] = "id_must_not_be_zero";
19
+ CreateAccountError[CreateAccountError["id_must_not_be_int_max"] = 7] = "id_must_not_be_int_max";
20
+ CreateAccountError[CreateAccountError["ledger_must_not_be_zero"] = 8] = "ledger_must_not_be_zero";
21
+ CreateAccountError[CreateAccountError["code_must_not_be_zero"] = 9] = "code_must_not_be_zero";
22
+ CreateAccountError[CreateAccountError["debits_pending_must_be_zero"] = 10] = "debits_pending_must_be_zero";
23
+ CreateAccountError[CreateAccountError["debits_posted_must_be_zero"] = 11] = "debits_posted_must_be_zero";
24
+ CreateAccountError[CreateAccountError["credits_pending_must_be_zero"] = 12] = "credits_pending_must_be_zero";
25
+ CreateAccountError[CreateAccountError["credits_posted_must_be_zero"] = 13] = "credits_posted_must_be_zero";
26
+ CreateAccountError[CreateAccountError["mutually_exclusive_flags"] = 14] = "mutually_exclusive_flags";
27
+ CreateAccountError[CreateAccountError["exists_with_different_flags"] = 15] = "exists_with_different_flags";
28
+ CreateAccountError[CreateAccountError["exists_with_different_user_data"] = 16] = "exists_with_different_user_data";
29
+ CreateAccountError[CreateAccountError["exists_with_different_ledger"] = 17] = "exists_with_different_ledger";
30
+ CreateAccountError[CreateAccountError["exists_with_different_code"] = 18] = "exists_with_different_code";
31
+ CreateAccountError[CreateAccountError["exists"] = 19] = "exists";
31
32
  })(CreateAccountError = exports.CreateAccountError || (exports.CreateAccountError = {}));
32
33
  var TransferFlags;
33
34
  (function (TransferFlags) {
@@ -40,57 +41,59 @@ var CreateTransferError;
40
41
  (function (CreateTransferError) {
41
42
  CreateTransferError[CreateTransferError["linked_event_failed"] = 1] = "linked_event_failed";
42
43
  CreateTransferError[CreateTransferError["linked_event_chain_open"] = 2] = "linked_event_chain_open";
43
- CreateTransferError[CreateTransferError["reserved_flag"] = 3] = "reserved_flag";
44
- CreateTransferError[CreateTransferError["reserved_field"] = 4] = "reserved_field";
45
- CreateTransferError[CreateTransferError["id_must_not_be_zero"] = 5] = "id_must_not_be_zero";
46
- CreateTransferError[CreateTransferError["id_must_not_be_int_max"] = 6] = "id_must_not_be_int_max";
47
- CreateTransferError[CreateTransferError["debit_account_id_must_not_be_zero"] = 7] = "debit_account_id_must_not_be_zero";
48
- CreateTransferError[CreateTransferError["debit_account_id_must_not_be_int_max"] = 8] = "debit_account_id_must_not_be_int_max";
49
- CreateTransferError[CreateTransferError["credit_account_id_must_not_be_zero"] = 9] = "credit_account_id_must_not_be_zero";
50
- CreateTransferError[CreateTransferError["credit_account_id_must_not_be_int_max"] = 10] = "credit_account_id_must_not_be_int_max";
51
- CreateTransferError[CreateTransferError["accounts_must_be_different"] = 11] = "accounts_must_be_different";
52
- CreateTransferError[CreateTransferError["pending_id_must_be_zero"] = 12] = "pending_id_must_be_zero";
53
- CreateTransferError[CreateTransferError["ledger_must_not_be_zero"] = 13] = "ledger_must_not_be_zero";
54
- CreateTransferError[CreateTransferError["code_must_not_be_zero"] = 14] = "code_must_not_be_zero";
55
- CreateTransferError[CreateTransferError["amount_must_not_be_zero"] = 15] = "amount_must_not_be_zero";
56
- CreateTransferError[CreateTransferError["debit_account_not_found"] = 16] = "debit_account_not_found";
57
- CreateTransferError[CreateTransferError["credit_account_not_found"] = 17] = "credit_account_not_found";
58
- CreateTransferError[CreateTransferError["accounts_must_have_the_same_ledger"] = 18] = "accounts_must_have_the_same_ledger";
59
- CreateTransferError[CreateTransferError["transfer_must_have_the_same_ledger_as_accounts"] = 19] = "transfer_must_have_the_same_ledger_as_accounts";
60
- CreateTransferError[CreateTransferError["exists_with_different_flags"] = 20] = "exists_with_different_flags";
61
- CreateTransferError[CreateTransferError["exists_with_different_debit_account_id"] = 21] = "exists_with_different_debit_account_id";
62
- CreateTransferError[CreateTransferError["exists_with_different_credit_account_id"] = 22] = "exists_with_different_credit_account_id";
63
- CreateTransferError[CreateTransferError["exists_with_different_user_data"] = 23] = "exists_with_different_user_data";
64
- CreateTransferError[CreateTransferError["exists_with_different_pending_id"] = 24] = "exists_with_different_pending_id";
65
- CreateTransferError[CreateTransferError["exists_with_different_timeout"] = 25] = "exists_with_different_timeout";
66
- CreateTransferError[CreateTransferError["exists_with_different_code"] = 26] = "exists_with_different_code";
67
- CreateTransferError[CreateTransferError["exists_with_different_amount"] = 27] = "exists_with_different_amount";
68
- CreateTransferError[CreateTransferError["exists"] = 28] = "exists";
69
- CreateTransferError[CreateTransferError["overflows_debits_pending"] = 29] = "overflows_debits_pending";
70
- CreateTransferError[CreateTransferError["overflows_credits_pending"] = 30] = "overflows_credits_pending";
71
- CreateTransferError[CreateTransferError["overflows_debits_posted"] = 31] = "overflows_debits_posted";
72
- CreateTransferError[CreateTransferError["overflows_credits_posted"] = 32] = "overflows_credits_posted";
73
- CreateTransferError[CreateTransferError["overflows_debits"] = 33] = "overflows_debits";
74
- CreateTransferError[CreateTransferError["overflows_credits"] = 34] = "overflows_credits";
75
- CreateTransferError[CreateTransferError["exceeds_credits"] = 35] = "exceeds_credits";
76
- CreateTransferError[CreateTransferError["exceeds_debits"] = 36] = "exceeds_debits";
77
- CreateTransferError[CreateTransferError["cannot_post_and_void_pending_transfer"] = 37] = "cannot_post_and_void_pending_transfer";
78
- CreateTransferError[CreateTransferError["pending_transfer_cannot_post_or_void_another"] = 38] = "pending_transfer_cannot_post_or_void_another";
79
- CreateTransferError[CreateTransferError["timeout_reserved_for_pending_transfer"] = 39] = "timeout_reserved_for_pending_transfer";
80
- CreateTransferError[CreateTransferError["pending_id_must_not_be_zero"] = 40] = "pending_id_must_not_be_zero";
81
- CreateTransferError[CreateTransferError["pending_id_must_not_be_int_max"] = 41] = "pending_id_must_not_be_int_max";
82
- CreateTransferError[CreateTransferError["pending_id_must_be_different"] = 42] = "pending_id_must_be_different";
83
- CreateTransferError[CreateTransferError["pending_transfer_not_found"] = 43] = "pending_transfer_not_found";
84
- CreateTransferError[CreateTransferError["pending_transfer_not_pending"] = 44] = "pending_transfer_not_pending";
85
- CreateTransferError[CreateTransferError["pending_transfer_has_different_debit_account_id"] = 45] = "pending_transfer_has_different_debit_account_id";
86
- CreateTransferError[CreateTransferError["pending_transfer_has_different_credit_account_id"] = 46] = "pending_transfer_has_different_credit_account_id";
87
- CreateTransferError[CreateTransferError["pending_transfer_has_different_ledger"] = 47] = "pending_transfer_has_different_ledger";
88
- CreateTransferError[CreateTransferError["pending_transfer_has_different_code"] = 48] = "pending_transfer_has_different_code";
89
- CreateTransferError[CreateTransferError["exceeds_pending_transfer_amount"] = 49] = "exceeds_pending_transfer_amount";
90
- CreateTransferError[CreateTransferError["pending_transfer_has_different_amount"] = 50] = "pending_transfer_has_different_amount";
91
- CreateTransferError[CreateTransferError["pending_transfer_already_posted"] = 51] = "pending_transfer_already_posted";
92
- CreateTransferError[CreateTransferError["pending_transfer_already_voided"] = 52] = "pending_transfer_already_voided";
93
- CreateTransferError[CreateTransferError["pending_transfer_expired"] = 53] = "pending_transfer_expired";
44
+ CreateTransferError[CreateTransferError["timestamp_must_be_zero"] = 3] = "timestamp_must_be_zero";
45
+ CreateTransferError[CreateTransferError["reserved_flag"] = 4] = "reserved_flag";
46
+ CreateTransferError[CreateTransferError["reserved_field"] = 5] = "reserved_field";
47
+ CreateTransferError[CreateTransferError["id_must_not_be_zero"] = 6] = "id_must_not_be_zero";
48
+ CreateTransferError[CreateTransferError["id_must_not_be_int_max"] = 7] = "id_must_not_be_int_max";
49
+ CreateTransferError[CreateTransferError["debit_account_id_must_not_be_zero"] = 8] = "debit_account_id_must_not_be_zero";
50
+ CreateTransferError[CreateTransferError["debit_account_id_must_not_be_int_max"] = 9] = "debit_account_id_must_not_be_int_max";
51
+ CreateTransferError[CreateTransferError["credit_account_id_must_not_be_zero"] = 10] = "credit_account_id_must_not_be_zero";
52
+ CreateTransferError[CreateTransferError["credit_account_id_must_not_be_int_max"] = 11] = "credit_account_id_must_not_be_int_max";
53
+ CreateTransferError[CreateTransferError["accounts_must_be_different"] = 12] = "accounts_must_be_different";
54
+ CreateTransferError[CreateTransferError["pending_id_must_be_zero"] = 13] = "pending_id_must_be_zero";
55
+ CreateTransferError[CreateTransferError["ledger_must_not_be_zero"] = 14] = "ledger_must_not_be_zero";
56
+ CreateTransferError[CreateTransferError["code_must_not_be_zero"] = 15] = "code_must_not_be_zero";
57
+ CreateTransferError[CreateTransferError["amount_must_not_be_zero"] = 16] = "amount_must_not_be_zero";
58
+ CreateTransferError[CreateTransferError["debit_account_not_found"] = 17] = "debit_account_not_found";
59
+ CreateTransferError[CreateTransferError["credit_account_not_found"] = 18] = "credit_account_not_found";
60
+ CreateTransferError[CreateTransferError["accounts_must_have_the_same_ledger"] = 19] = "accounts_must_have_the_same_ledger";
61
+ CreateTransferError[CreateTransferError["transfer_must_have_the_same_ledger_as_accounts"] = 20] = "transfer_must_have_the_same_ledger_as_accounts";
62
+ CreateTransferError[CreateTransferError["exists_with_different_flags"] = 21] = "exists_with_different_flags";
63
+ CreateTransferError[CreateTransferError["exists_with_different_debit_account_id"] = 22] = "exists_with_different_debit_account_id";
64
+ CreateTransferError[CreateTransferError["exists_with_different_credit_account_id"] = 23] = "exists_with_different_credit_account_id";
65
+ CreateTransferError[CreateTransferError["exists_with_different_user_data"] = 24] = "exists_with_different_user_data";
66
+ CreateTransferError[CreateTransferError["exists_with_different_pending_id"] = 25] = "exists_with_different_pending_id";
67
+ CreateTransferError[CreateTransferError["exists_with_different_timeout"] = 26] = "exists_with_different_timeout";
68
+ CreateTransferError[CreateTransferError["exists_with_different_code"] = 27] = "exists_with_different_code";
69
+ CreateTransferError[CreateTransferError["exists_with_different_amount"] = 28] = "exists_with_different_amount";
70
+ CreateTransferError[CreateTransferError["exists"] = 29] = "exists";
71
+ CreateTransferError[CreateTransferError["overflows_debits_pending"] = 30] = "overflows_debits_pending";
72
+ CreateTransferError[CreateTransferError["overflows_credits_pending"] = 31] = "overflows_credits_pending";
73
+ CreateTransferError[CreateTransferError["overflows_debits_posted"] = 32] = "overflows_debits_posted";
74
+ CreateTransferError[CreateTransferError["overflows_credits_posted"] = 33] = "overflows_credits_posted";
75
+ CreateTransferError[CreateTransferError["overflows_debits"] = 34] = "overflows_debits";
76
+ CreateTransferError[CreateTransferError["overflows_credits"] = 35] = "overflows_credits";
77
+ CreateTransferError[CreateTransferError["overflows_timeout"] = 36] = "overflows_timeout";
78
+ CreateTransferError[CreateTransferError["exceeds_credits"] = 37] = "exceeds_credits";
79
+ CreateTransferError[CreateTransferError["exceeds_debits"] = 38] = "exceeds_debits";
80
+ CreateTransferError[CreateTransferError["cannot_post_and_void_pending_transfer"] = 39] = "cannot_post_and_void_pending_transfer";
81
+ CreateTransferError[CreateTransferError["pending_transfer_cannot_post_or_void_another"] = 40] = "pending_transfer_cannot_post_or_void_another";
82
+ CreateTransferError[CreateTransferError["timeout_reserved_for_pending_transfer"] = 41] = "timeout_reserved_for_pending_transfer";
83
+ CreateTransferError[CreateTransferError["pending_id_must_not_be_zero"] = 42] = "pending_id_must_not_be_zero";
84
+ CreateTransferError[CreateTransferError["pending_id_must_not_be_int_max"] = 43] = "pending_id_must_not_be_int_max";
85
+ CreateTransferError[CreateTransferError["pending_id_must_be_different"] = 44] = "pending_id_must_be_different";
86
+ CreateTransferError[CreateTransferError["pending_transfer_not_found"] = 45] = "pending_transfer_not_found";
87
+ CreateTransferError[CreateTransferError["pending_transfer_not_pending"] = 46] = "pending_transfer_not_pending";
88
+ CreateTransferError[CreateTransferError["pending_transfer_has_different_debit_account_id"] = 47] = "pending_transfer_has_different_debit_account_id";
89
+ CreateTransferError[CreateTransferError["pending_transfer_has_different_credit_account_id"] = 48] = "pending_transfer_has_different_credit_account_id";
90
+ CreateTransferError[CreateTransferError["pending_transfer_has_different_ledger"] = 49] = "pending_transfer_has_different_ledger";
91
+ CreateTransferError[CreateTransferError["pending_transfer_has_different_code"] = 50] = "pending_transfer_has_different_code";
92
+ CreateTransferError[CreateTransferError["exceeds_pending_transfer_amount"] = 51] = "exceeds_pending_transfer_amount";
93
+ CreateTransferError[CreateTransferError["pending_transfer_has_different_amount"] = 52] = "pending_transfer_has_different_amount";
94
+ CreateTransferError[CreateTransferError["pending_transfer_already_posted"] = 53] = "pending_transfer_already_posted";
95
+ CreateTransferError[CreateTransferError["pending_transfer_already_voided"] = 54] = "pending_transfer_already_voided";
96
+ CreateTransferError[CreateTransferError["pending_transfer_expired"] = 55] = "pending_transfer_expired";
94
97
  })(CreateTransferError = exports.CreateTransferError || (exports.CreateTransferError = {}));
95
98
  var Operation;
96
99
  (function (Operation) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAY,OAAO,CAAC,eAAe,CAAC,CAAA;AAoCjD,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,mDAAiB,CAAA;IACjB,mGAAyC,CAAA;IACzC,mGAAyC,CAAA;AAC3C,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB;AAED,IAAY,kBAwBX;AAxBD,WAAY,kBAAkB;IAE5B,yFAAuB,CAAA;IACvB,iGAAuB,CAAA;IAEvB,6EAAa,CAAA;IACb,+EAAc,CAAA;IAEd,yFAAmB,CAAA;IACnB,+FAAsB,CAAA;IACtB,iGAAuB,CAAA;IACvB,6FAAqB,CAAA;IACrB,yGAA2B,CAAA;IAC3B,wGAA0B,CAAA;IAC1B,4GAA4B,CAAA;IAC5B,0GAA2B,CAAA;IAE3B,oGAAwB,CAAA;IAExB,0GAA2B,CAAA;IAC3B,kHAA+B,CAAA;IAC/B,4GAA4B,CAAA;IAC5B,wGAA0B,CAAA;IAC1B,gEAAM,CAAA;AACR,CAAC,EAxBW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAwB7B;AAsBD,IAAY,aAKX;AALD,WAAY,aAAa;IACvB,qDAAiB,CAAA;IACjB,uDAAkB,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,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAEnB,OAAO,OAAO,CAAA;AAChB,CAAC;AAzID,oCAyIC","sourcesContent":["const binding: Binding = require('./client.node')\ninterface Binding {\n init: (args: BindingInitArgs) => Context\n request: (context: Context, operation: Operation, batch: Event[], result: ResultCallback) => void\n raw_request: (context: Context, operation: Operation, raw_batch: Buffer, result: ResultCallback) => void\n tick: (context: Context) => void,\n deinit: (context: Context) => void,\n tick_ms: number\n}\n\ninterface BindingInitArgs {\n cluster_id: number, // u32\n replica_addresses: Buffer,\n}\n\nexport interface InitArgs {\n cluster_id: number, // u32\n replica_addresses: Array<string | number>,\n}\n\nexport type Context = object\n\nexport type Account = {\n id: bigint // u128\n user_data: bigint // u128\n reserved: Buffer // [48]u8\n ledger: number // u32, ledger of value\n code: number // u16, A chart of accounts code describing the type of account (e.g. clearing, settlement)\n flags: number // u16\n debits_pending: bigint // u64\n debits_posted: bigint // u64\n credits_pending: bigint // u64\n credits_posted: bigint // u64\n timestamp: bigint // u64, Set this to 0n - the actual value will be set by TigerBeetle server\n}\n\nexport enum AccountFlags {\n linked = (1 << 0),\n debits_must_not_exceed_credits = (1 << 1),\n credits_must_not_exceed_debits = (1 << 2)\n}\n\nexport enum CreateAccountError {\n // ok = 0 (No Error)\n linked_event_failed = 1,\n linked_event_chain_open,\n\n reserved_flag,\n reserved_field,\n\n id_must_not_be_zero,\n id_must_not_be_int_max,\n ledger_must_not_be_zero,\n code_must_not_be_zero,\n debits_pending_must_be_zero,\n debits_posted_must_be_zero,\n credits_pending_must_be_zero,\n credits_posted_must_be_zero,\n\n mutually_exclusive_flags,\n\n exists_with_different_flags,\n exists_with_different_user_data,\n exists_with_different_ledger,\n exists_with_different_code,\n exists,\n}\n\nexport type CreateAccountsError = {\n index: number,\n code: CreateAccountError,\n}\n\nexport type Transfer = {\n id: bigint, // u128\n debit_account_id: bigint, // u128\n credit_account_id: bigint, // u128\n user_data: bigint, // u128\n reserved: bigint, // u128\n pending_id: bigint, // u128\n timeout: bigint, // u64, In nanoseconds.\n ledger: number // u32, The ledger of value.\n code: number, // u16, A user-defined accounting code to describe the type of transfer (e.g. settlement).\n flags: number, // u16\n amount: bigint, // u64,\n timestamp: bigint, // u64, Set this to 0n - the timestamp will be set by TigerBeetle.\n}\n\nexport enum TransferFlags {\n linked = (1 << 0),\n pending = (1 << 1),\n post_pending_transfer = (1 << 2),\n void_pending_transfer = (1 << 3)\n}\n\nexport enum CreateTransferError {\n // ok = 0 (No Error)\n linked_event_failed = 1,\n linked_event_chain_open,\n\n reserved_flag,\n reserved_field,\n\n id_must_not_be_zero,\n id_must_not_be_int_max,\n debit_account_id_must_not_be_zero,\n debit_account_id_must_not_be_int_max,\n credit_account_id_must_not_be_zero,\n credit_account_id_must_not_be_int_max,\n accounts_must_be_different,\n\n pending_id_must_be_zero,\n\n ledger_must_not_be_zero,\n code_must_not_be_zero,\n amount_must_not_be_zero,\n\n debit_account_not_found,\n credit_account_not_found,\n\n accounts_must_have_the_same_ledger,\n transfer_must_have_the_same_ledger_as_accounts,\n\n exists_with_different_flags,\n exists_with_different_debit_account_id,\n exists_with_different_credit_account_id,\n exists_with_different_user_data,\n exists_with_different_pending_id,\n exists_with_different_timeout,\n exists_with_different_code,\n exists_with_different_amount,\n exists,\n\n overflows_debits_pending,\n overflows_credits_pending,\n overflows_debits_posted,\n overflows_credits_posted,\n overflows_debits,\n overflows_credits,\n\n exceeds_credits,\n exceeds_debits,\n\n cannot_post_and_void_pending_transfer,\n pending_transfer_cannot_post_or_void_another,\n timeout_reserved_for_pending_transfer,\n\n pending_id_must_not_be_zero,\n pending_id_must_not_be_int_max,\n pending_id_must_be_different,\n\n pending_transfer_not_found,\n pending_transfer_not_pending,\n\n pending_transfer_has_different_debit_account_id,\n pending_transfer_has_different_credit_account_id,\n pending_transfer_has_different_ledger,\n pending_transfer_has_different_code,\n\n exceeds_pending_transfer_amount,\n pending_transfer_has_different_amount,\n\n pending_transfer_already_posted,\n pending_transfer_already_voided,\n\n pending_transfer_expired,\n}\n\nexport type CreateTransfersError = {\n index: number,\n code: CreateTransferError,\n}\n\nexport type AccountID = bigint // u128\nexport type TransferID = bigint // u128\n\nexport type Event = Account | Transfer | AccountID | TransferID\nexport type Result = CreateAccountsError | CreateTransfersError | Account | Transfer\nexport type ResultCallback = (error: undefined | Error, results: Result[]) => void\n\nexport enum Operation {\n CREATE_ACCOUNT = 3,\n CREATE_TRANSFER,\n ACCOUNT_LOOKUP,\n TRANSFER_LOOKUP\n}\n\nexport interface Client {\n createAccounts: (batch: Account[]) => Promise<CreateAccountsError[]>\n createTransfers: (batch: Transfer[]) => Promise<CreateTransfersError[]>\n lookupAccounts: (batch: AccountID[]) => Promise<Account[]>\n lookupTransfers: (batch: TransferID[]) => Promise<Transfer[]>\n request: (operation: Operation, batch: Event[], callback: ResultCallback) => void\n rawRequest: (operation: Operation, rawBatch: Buffer, callback: ResultCallback) => void\n destroy: () => void\n}\n\nlet _args: InitArgs | undefined = undefined\nconst isSameArgs = (args: InitArgs): boolean => {\n if (typeof _args === 'undefined') {\n return false\n }\n\n if (_args.replica_addresses.length !== args.replica_addresses.length) {\n return false\n }\n\n let isSameReplicas = true\n args.replica_addresses.forEach((entry, index) => {\n if (_args?.replica_addresses[index] !== entry) {\n isSameReplicas = false\n }\n })\n\n return args.cluster_id === _args.cluster_id && isSameReplicas\n}\n\nlet _client: Client | undefined = undefined\nlet _interval: NodeJS.Timeout | undefined = undefined\n// Here to wait until `ping` is sent to server so that connection is registered - temporary till client table and sessions are implemented.\nlet _pinged = false\n// TODO: allow creation of clients if the arguments are different. Will require changes in node.zig as well.\nexport function createClient (args: InitArgs): Client {\n const duplicateArgs = isSameArgs(args)\n if (!duplicateArgs && typeof _client !== 'undefined'){\n throw new Error('Client has already been initialized with different arguments.')\n }\n\n if (duplicateArgs && typeof _client !== 'undefined'){\n throw new Error('Client has already been initialized with the same arguments.')\n }\n\n _args = Object.assign({}, { ...args })\n const context = binding.init({\n ...args,\n replica_addresses: Buffer.from(args.replica_addresses.join(','))\n })\n\n const request = (operation: Operation, batch: Event[], callback: ResultCallback) => {\n binding.request(context, operation, batch, callback)\n }\n\n const rawRequest = (operation: Operation, rawBatch: Buffer, callback: ResultCallback) => {\n binding.raw_request(context, operation, rawBatch, callback)\n }\n\n const createAccounts = async (batch: Account[]): Promise<CreateAccountsError[]> => {\n // Here to wait until `ping` is sent to server so that connection is registered - temporary till client table and sessions are implemented.\n if (!_pinged) {\n await new Promise<void>(resolve => {\n setTimeout(() => {\n _pinged = true\n resolve()\n }, 600)\n })\n }\n return new Promise((resolve, reject) => {\n const callback = (error: undefined | Error, results: CreateAccountsError[]) => {\n if (error) {\n reject(error)\n return\n }\n resolve(results)\n }\n\n try {\n binding.request(context, Operation.CREATE_ACCOUNT, batch, callback)\n } catch (error) {\n reject(error)\n }\n })\n }\n\n const createTransfers = async (batch: Transfer[]): Promise<CreateTransfersError[]> => {\n // Here to wait until `ping` is sent to server so that connection is registered - temporary till client table and sessions are implemented.\n if (!_pinged) {\n await new Promise<void>(resolve => {\n setTimeout(() => {\n _pinged = true\n resolve()\n }, 600)\n })\n }\n return new Promise((resolve, reject) => {\n const callback = (error: undefined | Error, results: CreateTransfersError[]) => {\n if (error) {\n reject(error)\n return\n }\n resolve(results)\n }\n\n try {\n binding.request(context, Operation.CREATE_TRANSFER, batch, callback)\n } catch (error) {\n reject(error)\n }\n })\n }\n\n const lookupAccounts = async (batch: AccountID[]): Promise<Account[]> => {\n return new Promise((resolve, reject) => {\n const callback = (error: undefined | Error, results: Account[]) => {\n if (error) {\n reject(error)\n return\n }\n resolve(results)\n }\n\n try {\n binding.request(context, Operation.ACCOUNT_LOOKUP, batch, callback)\n } catch (error) {\n reject(error)\n }\n })\n }\n\n const lookupTransfers = async (batch: TransferID[]): Promise<Transfer[]> => {\n return new Promise((resolve, reject) => {\n const callback = (error: undefined | Error, results: Transfer[]) => {\n if (error) {\n reject(error)\n return\n }\n resolve(results)\n }\n\n try {\n binding.request(context, Operation.TRANSFER_LOOKUP, batch, callback)\n } catch (error) {\n reject(error)\n }\n })\n }\n\n const destroy = (): void => {\n binding.deinit(context)\n if (_interval){\n clearInterval(_interval)\n }\n _client = undefined\n }\n\n _client = {\n createAccounts,\n createTransfers,\n lookupAccounts,\n lookupTransfers,\n request,\n rawRequest,\n destroy\n }\n\n _interval = setInterval(() => {\n binding.tick(context)\n }, binding.tick_ms)\n\n return _client\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAY,OAAO,CAAC,eAAe,CAAC,CAAA;AAoCjD,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,mDAAiB,CAAA;IACjB,mGAAyC,CAAA;IACzC,mGAAyC,CAAA;AAC3C,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB;AAED,IAAY,kBAyBX;AAzBD,WAAY,kBAAkB;IAE5B,yFAAuB,CAAA;IACvB,iGAAuB,CAAA;IACvB,+FAAsB,CAAA;IAEtB,6EAAa,CAAA;IACb,+EAAc,CAAA;IAEd,yFAAmB,CAAA;IACnB,+FAAsB,CAAA;IACtB,iGAAuB,CAAA;IACvB,6FAAqB,CAAA;IACrB,0GAA2B,CAAA;IAC3B,wGAA0B,CAAA;IAC1B,4GAA4B,CAAA;IAC5B,0GAA2B,CAAA;IAE3B,oGAAwB,CAAA;IAExB,0GAA2B,CAAA;IAC3B,kHAA+B,CAAA;IAC/B,4GAA4B,CAAA;IAC5B,wGAA0B,CAAA;IAC1B,gEAAM,CAAA;AACR,CAAC,EAzBW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAyB7B;AAsBD,IAAY,aAKX;AALD,WAAY,aAAa;IACvB,qDAAiB,CAAA;IACjB,uDAAkB,CAAA;IAClB,mFAAgC,CAAA;IAChC,mFAAgC,CAAA;AAClC,CAAC,EALW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAK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AO,CAAA;AAChB,CAAC;AAzID,oCAyIC","sourcesContent":["const binding: Binding = require('./client.node')\ninterface Binding {\n init: (args: BindingInitArgs) => Context\n request: (context: Context, operation: Operation, batch: Event[], result: ResultCallback) => void\n raw_request: (context: Context, operation: Operation, raw_batch: Buffer, result: ResultCallback) => void\n tick: (context: Context) => void,\n deinit: (context: Context) => void,\n tick_ms: number\n}\n\ninterface BindingInitArgs {\n cluster_id: number, // u32\n replica_addresses: Buffer,\n}\n\nexport interface InitArgs {\n cluster_id: number, // u32\n replica_addresses: Array<string | number>,\n}\n\nexport type Context = object\n\nexport type Account = {\n id: bigint // u128\n user_data: bigint // u128\n reserved: Buffer // [48]u8\n ledger: number // u32, ledger of value\n code: number // u16, A chart of accounts code describing the type of account (e.g. clearing, settlement)\n flags: number // u16\n debits_pending: bigint // u64\n debits_posted: bigint // u64\n credits_pending: bigint // u64\n credits_posted: bigint // u64\n timestamp: bigint // u64, Set this to 0n - the actual value will be set by TigerBeetle server\n}\n\nexport enum AccountFlags {\n linked = (1 << 0),\n debits_must_not_exceed_credits = (1 << 1),\n credits_must_not_exceed_debits = (1 << 2)\n}\n\nexport enum CreateAccountError {\n // ok = 0 (No Error)\n linked_event_failed = 1,\n linked_event_chain_open,\n timestamp_must_be_zero,\n\n reserved_flag,\n reserved_field,\n\n id_must_not_be_zero,\n id_must_not_be_int_max,\n ledger_must_not_be_zero,\n code_must_not_be_zero,\n debits_pending_must_be_zero,\n debits_posted_must_be_zero,\n credits_pending_must_be_zero,\n credits_posted_must_be_zero,\n\n mutually_exclusive_flags,\n\n exists_with_different_flags,\n exists_with_different_user_data,\n exists_with_different_ledger,\n exists_with_different_code,\n exists,\n}\n\nexport type CreateAccountsError = {\n index: number,\n code: CreateAccountError,\n}\n\nexport type Transfer = {\n id: bigint, // u128\n debit_account_id: bigint, // u128\n credit_account_id: bigint, // u128\n user_data: bigint, // u128\n reserved: bigint, // u128\n pending_id: bigint, // u128\n timeout: bigint, // u64, In nanoseconds.\n ledger: number // u32, The ledger of value.\n code: number, // u16, A user-defined accounting code to describe the type of transfer (e.g. settlement).\n flags: number, // u16\n amount: bigint, // u64,\n timestamp: bigint, // u64, Set this to 0n - the timestamp will be set by TigerBeetle.\n}\n\nexport enum TransferFlags {\n linked = (1 << 0),\n pending = (1 << 1),\n post_pending_transfer = (1 << 2),\n void_pending_transfer = (1 << 3)\n}\n\nexport enum CreateTransferError {\n // ok = 0 (No Error)\n linked_event_failed = 1,\n linked_event_chain_open,\n timestamp_must_be_zero,\n\n reserved_flag,\n reserved_field,\n\n id_must_not_be_zero,\n id_must_not_be_int_max,\n debit_account_id_must_not_be_zero,\n debit_account_id_must_not_be_int_max,\n credit_account_id_must_not_be_zero,\n credit_account_id_must_not_be_int_max,\n accounts_must_be_different,\n\n pending_id_must_be_zero,\n\n ledger_must_not_be_zero,\n code_must_not_be_zero,\n amount_must_not_be_zero,\n\n debit_account_not_found,\n credit_account_not_found,\n\n accounts_must_have_the_same_ledger,\n transfer_must_have_the_same_ledger_as_accounts,\n\n exists_with_different_flags,\n exists_with_different_debit_account_id,\n exists_with_different_credit_account_id,\n exists_with_different_user_data,\n exists_with_different_pending_id,\n exists_with_different_timeout,\n exists_with_different_code,\n exists_with_different_amount,\n exists,\n\n overflows_debits_pending,\n overflows_credits_pending,\n overflows_debits_posted,\n overflows_credits_posted,\n overflows_debits,\n overflows_credits,\n overflows_timeout,\n\n exceeds_credits,\n exceeds_debits,\n\n cannot_post_and_void_pending_transfer,\n pending_transfer_cannot_post_or_void_another,\n timeout_reserved_for_pending_transfer,\n\n pending_id_must_not_be_zero,\n pending_id_must_not_be_int_max,\n pending_id_must_be_different,\n\n pending_transfer_not_found,\n pending_transfer_not_pending,\n\n pending_transfer_has_different_debit_account_id,\n pending_transfer_has_different_credit_account_id,\n pending_transfer_has_different_ledger,\n pending_transfer_has_different_code,\n\n exceeds_pending_transfer_amount,\n pending_transfer_has_different_amount,\n\n pending_transfer_already_posted,\n pending_transfer_already_voided,\n\n pending_transfer_expired,\n}\n\nexport type CreateTransfersError = {\n index: number,\n code: CreateTransferError,\n}\n\nexport type AccountID = bigint // u128\nexport type TransferID = bigint // u128\n\nexport type Event = Account | Transfer | AccountID | TransferID\nexport type Result = CreateAccountsError | CreateTransfersError | Account | Transfer\nexport type ResultCallback = (error: undefined | Error, results: Result[]) => void\n\nexport enum Operation {\n CREATE_ACCOUNT = 3,\n CREATE_TRANSFER,\n ACCOUNT_LOOKUP,\n TRANSFER_LOOKUP\n}\n\nexport interface Client {\n createAccounts: (batch: Account[]) => Promise<CreateAccountsError[]>\n createTransfers: (batch: Transfer[]) => Promise<CreateTransfersError[]>\n lookupAccounts: (batch: AccountID[]) => Promise<Account[]>\n lookupTransfers: (batch: TransferID[]) => Promise<Transfer[]>\n request: (operation: Operation, batch: Event[], callback: ResultCallback) => void\n rawRequest: (operation: Operation, rawBatch: Buffer, callback: ResultCallback) => void\n destroy: () => void\n}\n\nlet _args: InitArgs | undefined = undefined\nconst isSameArgs = (args: InitArgs): boolean => {\n if (typeof _args === 'undefined') {\n return false\n }\n\n if (_args.replica_addresses.length !== args.replica_addresses.length) {\n return false\n }\n\n let isSameReplicas = true\n args.replica_addresses.forEach((entry, index) => {\n if (_args?.replica_addresses[index] !== entry) {\n isSameReplicas = false\n }\n })\n\n return args.cluster_id === _args.cluster_id && isSameReplicas\n}\n\nlet _client: Client | undefined = undefined\nlet _interval: NodeJS.Timeout | undefined = undefined\n// Here to wait until `ping` is sent to server so that connection is registered - temporary till client table and sessions are implemented.\nlet _pinged = false\n// TODO: allow creation of clients if the arguments are different. Will require changes in node.zig as well.\nexport function createClient (args: InitArgs): Client {\n const duplicateArgs = isSameArgs(args)\n if (!duplicateArgs && typeof _client !== 'undefined'){\n throw new Error('Client has already been initialized with different arguments.')\n }\n\n if (duplicateArgs && typeof _client !== 'undefined'){\n throw new Error('Client has already been initialized with the same arguments.')\n }\n\n _args = Object.assign({}, { ...args })\n const context = binding.init({\n ...args,\n replica_addresses: Buffer.from(args.replica_addresses.join(','))\n })\n\n const request = (operation: Operation, batch: Event[], callback: ResultCallback) => {\n binding.request(context, operation, batch, callback)\n }\n\n const rawRequest = (operation: Operation, rawBatch: Buffer, callback: ResultCallback) => {\n binding.raw_request(context, operation, rawBatch, callback)\n }\n\n const createAccounts = async (batch: Account[]): Promise<CreateAccountsError[]> => {\n // Here to wait until `ping` is sent to server so that connection is registered - temporary till client table and sessions are implemented.\n if (!_pinged) {\n await new Promise<void>(resolve => {\n setTimeout(() => {\n _pinged = true\n resolve()\n }, 600)\n })\n }\n return new Promise((resolve, reject) => {\n const callback = (error: undefined | Error, results: CreateAccountsError[]) => {\n if (error) {\n reject(error)\n return\n }\n resolve(results)\n }\n\n try {\n binding.request(context, Operation.CREATE_ACCOUNT, batch, callback)\n } catch (error) {\n reject(error)\n }\n })\n }\n\n const createTransfers = async (batch: Transfer[]): Promise<CreateTransfersError[]> => {\n // Here to wait until `ping` is sent to server so that connection is registered - temporary till client table and sessions are implemented.\n if (!_pinged) {\n await new Promise<void>(resolve => {\n setTimeout(() => {\n _pinged = true\n resolve()\n }, 600)\n })\n }\n return new Promise((resolve, reject) => {\n const callback = (error: undefined | Error, results: CreateTransfersError[]) => {\n if (error) {\n reject(error)\n return\n }\n resolve(results)\n }\n\n try {\n binding.request(context, Operation.CREATE_TRANSFER, batch, callback)\n } catch (error) {\n reject(error)\n }\n })\n }\n\n const lookupAccounts = async (batch: AccountID[]): Promise<Account[]> => {\n return new Promise((resolve, reject) => {\n const callback = (error: undefined | Error, results: Account[]) => {\n if (error) {\n reject(error)\n return\n }\n resolve(results)\n }\n\n try {\n binding.request(context, Operation.ACCOUNT_LOOKUP, batch, callback)\n } catch (error) {\n reject(error)\n }\n })\n }\n\n const lookupTransfers = async (batch: TransferID[]): Promise<Transfer[]> => {\n return new Promise((resolve, reject) => {\n const callback = (error: undefined | Error, results: Transfer[]) => {\n if (error) {\n reject(error)\n return\n }\n resolve(results)\n }\n\n try {\n binding.request(context, Operation.TRANSFER_LOOKUP, batch, callback)\n } catch (error) {\n reject(error)\n }\n })\n }\n\n const destroy = (): void => {\n binding.deinit(context)\n if (_interval){\n clearInterval(_interval)\n }\n _client = undefined\n }\n\n _client = {\n createAccounts,\n createTransfers,\n lookupAccounts,\n lookupTransfers,\n request,\n rawRequest,\n destroy\n }\n\n _interval = setInterval(() => {\n binding.tick(context)\n }, binding.tick_ms)\n\n return _client\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tigerbeetle-node",
3
- "version": "0.11.9",
3
+ "version": "0.11.11",
4
4
  "description": "TigerBeetle Node.js client",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -5,25 +5,37 @@ set -e
5
5
  # macOS 13 Ventura is not supported on Zig 0.9.x.
6
6
  # Overriding -target is one workaround Andrew suggests.
7
7
  # https://github.com/ziglang/zig/issues/10478#issuecomment-1294313967
8
- # Cut everything after the first `.` in the target query result
9
- # because the rest of it doesn't always seem to be valid when passed
10
- # back in to `-target`.
11
- target="$(./zig/zig targets | grep triple |cut -d '"' -f 4 | cut -d '.' -f 1)"
8
+ target=""
12
9
  if [ "$(./zig/zig targets | grep triple |cut -d '"' -f 4 | cut -d '.' -f 1,2)" = "aarch64-macos.13" ]; then
13
- target="native-macos.11"
10
+ target="-target native-macos.11"
14
11
  fi
15
12
 
16
- echo "Building for $target"
13
+ # Zig picks musl libc on RHEL instead of glibc, incorrectly
14
+ # https://github.com/ziglang/zig/issues/12156
15
+ if [ -f "/etc/redhat-release" ]; then
16
+ if ! grep Fedora /etc/redhat-release; then
17
+ target="-target native-native-gnu"
18
+ fi
19
+ fi
20
+
21
+ if [ "$target" = "" ]; then
22
+ echo "Building default target"
23
+ else
24
+ echo "Building for '$target'"
25
+ fi
17
26
 
18
27
  mkdir -p dist
19
28
 
20
- ./zig/zig build-lib \
29
+ # Need to do string eval-ing because of shellcheck's strict string
30
+ # interpolation rules.
31
+ cmd="./zig/zig build-lib \
21
32
  -mcpu=baseline \
22
33
  -OReleaseSafe \
23
34
  -dynamic \
24
35
  -lc \
25
- -isystem build/node-"$(node --version)"/include/node \
36
+ -isystem build/node-$(node --version)/include/node \
26
37
  -fallow-shlib-undefined \
27
38
  -femit-bin=dist/client.node \
28
- -target "$target" \
29
- src/node.zig
39
+ $target src/node.zig"
40
+
41
+ eval "$cmd"
package/src/index.ts CHANGED
@@ -44,6 +44,7 @@ export enum CreateAccountError {
44
44
  // ok = 0 (No Error)
45
45
  linked_event_failed = 1,
46
46
  linked_event_chain_open,
47
+ timestamp_must_be_zero,
47
48
 
48
49
  reserved_flag,
49
50
  reserved_field,
@@ -97,6 +98,7 @@ export enum CreateTransferError {
97
98
  // ok = 0 (No Error)
98
99
  linked_event_failed = 1,
99
100
  linked_event_chain_open,
101
+ timestamp_must_be_zero,
100
102
 
101
103
  reserved_flag,
102
104
  reserved_field,
@@ -137,6 +139,7 @@ export enum CreateTransferError {
137
139
  overflows_credits_posted,
138
140
  overflows_debits,
139
141
  overflows_credits,
142
+ overflows_timeout,
140
143
 
141
144
  exceeds_credits,
142
145
  exceeds_debits,
@@ -80,6 +80,7 @@ const ConfigCluster = struct {
80
80
  cache_line_size: comptime_int = 64,
81
81
  clients_max: usize,
82
82
  pipeline_prepare_queue_max: usize = 8,
83
+ view_change_headers_max: usize = 8,
83
84
  quorum_replication_max: u8 = 3,
84
85
  journal_slot_count: usize = 1024,
85
86
  message_size_max: usize = 1 * 1024 * 1024,
@@ -180,6 +181,7 @@ pub const configs = struct {
180
181
  .cluster = .{
181
182
  .clients_max = 4 + 3,
182
183
  .pipeline_prepare_queue_max = 4,
184
+ .view_change_headers_max = 4,
183
185
  .journal_slot_count = Config.Cluster.journal_slot_count_min,
184
186
  .message_size_max = Config.Cluster.message_size_max_min(4),
185
187
  .storage_size_max = 4 * 1024 * 1024 * 1024,
@@ -157,6 +157,9 @@ comptime {
157
157
  assert(message_size_max >= @sizeOf(vsr.Header));
158
158
  assert(message_size_max >= sector_size);
159
159
  assert(message_size_max >= Config.Cluster.message_size_max_min(clients_max));
160
+
161
+ // Ensure that DVC/SV messages can fit all necessary headers.
162
+ assert(message_body_size_max >= view_change_headers_max * @sizeOf(vsr.Header));
160
163
  }
161
164
 
162
165
  /// The maximum number of Viewstamped Replication prepare messages that can be inflight at a time.
@@ -184,6 +187,21 @@ comptime {
184
187
  assert(pipeline_request_queue_max >= 0);
185
188
  }
186
189
 
190
+ /// The number of prepare headers to include in the body of a DVC/SV.
191
+ ///
192
+ /// CRITICAL:
193
+ /// We must provide enough headers to cover all uncommitted headers so that the new
194
+ /// primary (if we are in a view change) can decide whether to discard uncommitted headers
195
+ /// that cannot be repaired because they are gaps. See DVCQuorum for more detail.
196
+ pub const view_change_headers_max = config.cluster.view_change_headers_max;
197
+
198
+ comptime {
199
+ assert(view_change_headers_max > 0);
200
+ assert(view_change_headers_max >= pipeline_prepare_queue_max);
201
+ assert(view_change_headers_max <= journal_slot_count);
202
+ assert(view_change_headers_max <= @divFloor(message_body_size_max, @sizeOf(vsr.Header)));
203
+ }
204
+
187
205
  /// The minimum and maximum amount of time in milliseconds to wait before initiating a connection.
188
206
  /// Exponential backoff and jitter are applied within this range.
189
207
  pub const connection_delay_min_ms = config.process.connection_delay_min_ms;
@@ -185,8 +185,6 @@ const Environment = struct {
185
185
  .commit_min_checksum = env.superblock.working.vsr_state.commit_min_checksum + 1,
186
186
  .commit_min = op,
187
187
  .commit_max = op + 1,
188
- .log_view = 0,
189
- .view = 0,
190
188
  });
191
189
  }
192
190
 
@@ -419,16 +419,17 @@ const Environment = struct {
419
419
  env.manifest_log.checkpoint(checkpoint_callback);
420
420
  env.wait(&env.manifest_log);
421
421
 
422
- var vsr_state = env.manifest_log.superblock.working.vsr_state;
423
- vsr_state.commit_min += 1;
424
- vsr_state.commit_min_checksum += 1;
425
- vsr_state.commit_max += 1;
422
+ const vsr_state = &env.manifest_log.superblock.working.vsr_state;
426
423
 
427
424
  env.pending += 1;
428
425
  env.manifest_log.superblock.checkpoint(
429
426
  checkpoint_superblock_callback,
430
427
  &env.superblock_context,
431
- vsr_state,
428
+ .{
429
+ .commit_min_checksum = vsr_state.commit_min_checksum + 1,
430
+ .commit_min = vsr_state.commit_min + 1,
431
+ .commit_max = vsr_state.commit_max + 1,
432
+ },
432
433
  );
433
434
  env.wait(&env.manifest_log);
434
435
 
@@ -202,15 +202,16 @@ const Environment = struct {
202
202
 
203
203
  log.debug("forest checkpointing completed!", .{});
204
204
 
205
- var vsr_state = env.superblock.staging.vsr_state;
206
- vsr_state.commit_min += 1;
207
- vsr_state.commit_min_checkpoint += 1;
205
+ const vsr_state = &env.superblock.staging.vsr_state;
208
206
 
209
207
  env.state = .superblock_checkpointing;
210
208
  env.superblock.checkpoint(
211
209
  superblock_checkpoint_callback,
212
210
  &env.superblock_context,
213
- vsr_state,
211
+ .{
212
+ .commit_min_checkpoint = vsr_state.commit_min_checkpoint + 1,
213
+ .commit_min = vsr_state.commit_min + 1,
214
+ },
214
215
  );
215
216
  }
216
217