tigerbeetle-node 0.12.42 → 0.12.44
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/dist/benchmark.js +1 -1
- package/dist/benchmark.js.map +1 -1
- package/dist/bin/aarch64-linux-gnu/client.node +0 -0
- package/dist/bin/aarch64-linux-musl/client.node +0 -0
- package/dist/bin/aarch64-macos/client.node +0 -0
- package/dist/bin/x86_64-linux-gnu/client.node +0 -0
- package/dist/bin/x86_64-linux-musl/client.node +0 -0
- package/dist/bin/x86_64-macos/client.node +0 -0
- package/dist/bindings.d.ts +136 -0
- package/dist/bindings.js +109 -0
- package/dist/bindings.js.map +1 -0
- package/dist/index.d.ts +2 -131
- package/dist/index.js +17 -106
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/benchmark.ts +1 -1
- package/src/bindings.ts +601 -0
- package/src/index.ts +13 -167
- package/src/node.zig +0 -5
package/dist/index.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
2
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createClient =
|
|
13
|
+
exports.createClient = void 0;
|
|
14
|
+
__exportStar(require("./bindings"), exports);
|
|
15
|
+
const bindings_1 = require("./bindings");
|
|
4
16
|
function getBinding() {
|
|
5
17
|
const { arch, platform } = process;
|
|
6
18
|
const archMap = {
|
|
@@ -34,107 +46,6 @@ function getBinding() {
|
|
|
34
46
|
return require(filename);
|
|
35
47
|
}
|
|
36
48
|
const binding = getBinding();
|
|
37
|
-
var AccountFlags;
|
|
38
|
-
(function (AccountFlags) {
|
|
39
|
-
AccountFlags[AccountFlags["linked"] = 1] = "linked";
|
|
40
|
-
AccountFlags[AccountFlags["debits_must_not_exceed_credits"] = 2] = "debits_must_not_exceed_credits";
|
|
41
|
-
AccountFlags[AccountFlags["credits_must_not_exceed_debits"] = 4] = "credits_must_not_exceed_debits";
|
|
42
|
-
})(AccountFlags = exports.AccountFlags || (exports.AccountFlags = {}));
|
|
43
|
-
var CreateAccountError;
|
|
44
|
-
(function (CreateAccountError) {
|
|
45
|
-
CreateAccountError[CreateAccountError["linked_event_failed"] = 1] = "linked_event_failed";
|
|
46
|
-
CreateAccountError[CreateAccountError["linked_event_chain_open"] = 2] = "linked_event_chain_open";
|
|
47
|
-
CreateAccountError[CreateAccountError["timestamp_must_be_zero"] = 3] = "timestamp_must_be_zero";
|
|
48
|
-
CreateAccountError[CreateAccountError["reserved_flag"] = 4] = "reserved_flag";
|
|
49
|
-
CreateAccountError[CreateAccountError["reserved_field"] = 5] = "reserved_field";
|
|
50
|
-
CreateAccountError[CreateAccountError["id_must_not_be_zero"] = 6] = "id_must_not_be_zero";
|
|
51
|
-
CreateAccountError[CreateAccountError["id_must_not_be_int_max"] = 7] = "id_must_not_be_int_max";
|
|
52
|
-
CreateAccountError[CreateAccountError["flags_are_mutually_exclusive"] = 8] = "flags_are_mutually_exclusive";
|
|
53
|
-
CreateAccountError[CreateAccountError["ledger_must_not_be_zero"] = 9] = "ledger_must_not_be_zero";
|
|
54
|
-
CreateAccountError[CreateAccountError["code_must_not_be_zero"] = 10] = "code_must_not_be_zero";
|
|
55
|
-
CreateAccountError[CreateAccountError["debits_pending_must_be_zero"] = 11] = "debits_pending_must_be_zero";
|
|
56
|
-
CreateAccountError[CreateAccountError["debits_posted_must_be_zero"] = 12] = "debits_posted_must_be_zero";
|
|
57
|
-
CreateAccountError[CreateAccountError["credits_pending_must_be_zero"] = 13] = "credits_pending_must_be_zero";
|
|
58
|
-
CreateAccountError[CreateAccountError["credits_posted_must_be_zero"] = 14] = "credits_posted_must_be_zero";
|
|
59
|
-
CreateAccountError[CreateAccountError["exists_with_different_flags"] = 15] = "exists_with_different_flags";
|
|
60
|
-
CreateAccountError[CreateAccountError["exists_with_different_user_data"] = 16] = "exists_with_different_user_data";
|
|
61
|
-
CreateAccountError[CreateAccountError["exists_with_different_ledger"] = 17] = "exists_with_different_ledger";
|
|
62
|
-
CreateAccountError[CreateAccountError["exists_with_different_code"] = 18] = "exists_with_different_code";
|
|
63
|
-
CreateAccountError[CreateAccountError["exists"] = 19] = "exists";
|
|
64
|
-
})(CreateAccountError = exports.CreateAccountError || (exports.CreateAccountError = {}));
|
|
65
|
-
var TransferFlags;
|
|
66
|
-
(function (TransferFlags) {
|
|
67
|
-
TransferFlags[TransferFlags["linked"] = 1] = "linked";
|
|
68
|
-
TransferFlags[TransferFlags["pending"] = 2] = "pending";
|
|
69
|
-
TransferFlags[TransferFlags["post_pending_transfer"] = 4] = "post_pending_transfer";
|
|
70
|
-
TransferFlags[TransferFlags["void_pending_transfer"] = 8] = "void_pending_transfer";
|
|
71
|
-
TransferFlags[TransferFlags["balancing_debit"] = 16] = "balancing_debit";
|
|
72
|
-
TransferFlags[TransferFlags["balancing_credit"] = 32] = "balancing_credit";
|
|
73
|
-
})(TransferFlags = exports.TransferFlags || (exports.TransferFlags = {}));
|
|
74
|
-
var CreateTransferError;
|
|
75
|
-
(function (CreateTransferError) {
|
|
76
|
-
CreateTransferError[CreateTransferError["linked_event_failed"] = 1] = "linked_event_failed";
|
|
77
|
-
CreateTransferError[CreateTransferError["linked_event_chain_open"] = 2] = "linked_event_chain_open";
|
|
78
|
-
CreateTransferError[CreateTransferError["timestamp_must_be_zero"] = 3] = "timestamp_must_be_zero";
|
|
79
|
-
CreateTransferError[CreateTransferError["reserved_flag"] = 4] = "reserved_flag";
|
|
80
|
-
CreateTransferError[CreateTransferError["reserved_field"] = 5] = "reserved_field";
|
|
81
|
-
CreateTransferError[CreateTransferError["id_must_not_be_zero"] = 6] = "id_must_not_be_zero";
|
|
82
|
-
CreateTransferError[CreateTransferError["id_must_not_be_int_max"] = 7] = "id_must_not_be_int_max";
|
|
83
|
-
CreateTransferError[CreateTransferError["flags_are_mutually_exclusive"] = 8] = "flags_are_mutually_exclusive";
|
|
84
|
-
CreateTransferError[CreateTransferError["debit_account_id_must_not_be_zero"] = 9] = "debit_account_id_must_not_be_zero";
|
|
85
|
-
CreateTransferError[CreateTransferError["debit_account_id_must_not_be_int_max"] = 10] = "debit_account_id_must_not_be_int_max";
|
|
86
|
-
CreateTransferError[CreateTransferError["credit_account_id_must_not_be_zero"] = 11] = "credit_account_id_must_not_be_zero";
|
|
87
|
-
CreateTransferError[CreateTransferError["credit_account_id_must_not_be_int_max"] = 12] = "credit_account_id_must_not_be_int_max";
|
|
88
|
-
CreateTransferError[CreateTransferError["accounts_must_be_different"] = 13] = "accounts_must_be_different";
|
|
89
|
-
CreateTransferError[CreateTransferError["pending_id_must_be_zero"] = 14] = "pending_id_must_be_zero";
|
|
90
|
-
CreateTransferError[CreateTransferError["pending_id_must_not_be_zero"] = 15] = "pending_id_must_not_be_zero";
|
|
91
|
-
CreateTransferError[CreateTransferError["pending_id_must_not_be_int_max"] = 16] = "pending_id_must_not_be_int_max";
|
|
92
|
-
CreateTransferError[CreateTransferError["pending_id_must_be_different"] = 17] = "pending_id_must_be_different";
|
|
93
|
-
CreateTransferError[CreateTransferError["timeout_reserved_for_pending_transfer"] = 18] = "timeout_reserved_for_pending_transfer";
|
|
94
|
-
CreateTransferError[CreateTransferError["ledger_must_not_be_zero"] = 19] = "ledger_must_not_be_zero";
|
|
95
|
-
CreateTransferError[CreateTransferError["code_must_not_be_zero"] = 20] = "code_must_not_be_zero";
|
|
96
|
-
CreateTransferError[CreateTransferError["amount_must_not_be_zero"] = 21] = "amount_must_not_be_zero";
|
|
97
|
-
CreateTransferError[CreateTransferError["debit_account_not_found"] = 22] = "debit_account_not_found";
|
|
98
|
-
CreateTransferError[CreateTransferError["credit_account_not_found"] = 23] = "credit_account_not_found";
|
|
99
|
-
CreateTransferError[CreateTransferError["accounts_must_have_the_same_ledger"] = 24] = "accounts_must_have_the_same_ledger";
|
|
100
|
-
CreateTransferError[CreateTransferError["transfer_must_have_the_same_ledger_as_accounts"] = 25] = "transfer_must_have_the_same_ledger_as_accounts";
|
|
101
|
-
CreateTransferError[CreateTransferError["pending_transfer_not_found"] = 26] = "pending_transfer_not_found";
|
|
102
|
-
CreateTransferError[CreateTransferError["pending_transfer_not_pending"] = 27] = "pending_transfer_not_pending";
|
|
103
|
-
CreateTransferError[CreateTransferError["pending_transfer_has_different_debit_account_id"] = 28] = "pending_transfer_has_different_debit_account_id";
|
|
104
|
-
CreateTransferError[CreateTransferError["pending_transfer_has_different_credit_account_id"] = 29] = "pending_transfer_has_different_credit_account_id";
|
|
105
|
-
CreateTransferError[CreateTransferError["pending_transfer_has_different_ledger"] = 30] = "pending_transfer_has_different_ledger";
|
|
106
|
-
CreateTransferError[CreateTransferError["pending_transfer_has_different_code"] = 31] = "pending_transfer_has_different_code";
|
|
107
|
-
CreateTransferError[CreateTransferError["exceeds_pending_transfer_amount"] = 32] = "exceeds_pending_transfer_amount";
|
|
108
|
-
CreateTransferError[CreateTransferError["pending_transfer_has_different_amount"] = 33] = "pending_transfer_has_different_amount";
|
|
109
|
-
CreateTransferError[CreateTransferError["pending_transfer_already_posted"] = 34] = "pending_transfer_already_posted";
|
|
110
|
-
CreateTransferError[CreateTransferError["pending_transfer_already_voided"] = 35] = "pending_transfer_already_voided";
|
|
111
|
-
CreateTransferError[CreateTransferError["pending_transfer_expired"] = 36] = "pending_transfer_expired";
|
|
112
|
-
CreateTransferError[CreateTransferError["exists_with_different_flags"] = 37] = "exists_with_different_flags";
|
|
113
|
-
CreateTransferError[CreateTransferError["exists_with_different_debit_account_id"] = 38] = "exists_with_different_debit_account_id";
|
|
114
|
-
CreateTransferError[CreateTransferError["exists_with_different_credit_account_id"] = 39] = "exists_with_different_credit_account_id";
|
|
115
|
-
CreateTransferError[CreateTransferError["exists_with_different_pending_id"] = 40] = "exists_with_different_pending_id";
|
|
116
|
-
CreateTransferError[CreateTransferError["exists_with_different_user_data"] = 41] = "exists_with_different_user_data";
|
|
117
|
-
CreateTransferError[CreateTransferError["exists_with_different_timeout"] = 42] = "exists_with_different_timeout";
|
|
118
|
-
CreateTransferError[CreateTransferError["exists_with_different_code"] = 43] = "exists_with_different_code";
|
|
119
|
-
CreateTransferError[CreateTransferError["exists_with_different_amount"] = 44] = "exists_with_different_amount";
|
|
120
|
-
CreateTransferError[CreateTransferError["exists"] = 45] = "exists";
|
|
121
|
-
CreateTransferError[CreateTransferError["overflows_debits_pending"] = 46] = "overflows_debits_pending";
|
|
122
|
-
CreateTransferError[CreateTransferError["overflows_credits_pending"] = 47] = "overflows_credits_pending";
|
|
123
|
-
CreateTransferError[CreateTransferError["overflows_debits_posted"] = 48] = "overflows_debits_posted";
|
|
124
|
-
CreateTransferError[CreateTransferError["overflows_credits_posted"] = 49] = "overflows_credits_posted";
|
|
125
|
-
CreateTransferError[CreateTransferError["overflows_debits"] = 50] = "overflows_debits";
|
|
126
|
-
CreateTransferError[CreateTransferError["overflows_credits"] = 51] = "overflows_credits";
|
|
127
|
-
CreateTransferError[CreateTransferError["overflows_timeout"] = 52] = "overflows_timeout";
|
|
128
|
-
CreateTransferError[CreateTransferError["exceeds_credits"] = 53] = "exceeds_credits";
|
|
129
|
-
CreateTransferError[CreateTransferError["exceeds_debits"] = 54] = "exceeds_debits";
|
|
130
|
-
})(CreateTransferError = exports.CreateTransferError || (exports.CreateTransferError = {}));
|
|
131
|
-
var Operation;
|
|
132
|
-
(function (Operation) {
|
|
133
|
-
Operation[Operation["CREATE_ACCOUNT"] = 3] = "CREATE_ACCOUNT";
|
|
134
|
-
Operation[Operation["CREATE_TRANSFER"] = 4] = "CREATE_TRANSFER";
|
|
135
|
-
Operation[Operation["ACCOUNT_LOOKUP"] = 5] = "ACCOUNT_LOOKUP";
|
|
136
|
-
Operation[Operation["TRANSFER_LOOKUP"] = 6] = "TRANSFER_LOOKUP";
|
|
137
|
-
})(Operation = exports.Operation || (exports.Operation = {}));
|
|
138
49
|
let _args = undefined;
|
|
139
50
|
const isSameArgs = (args) => {
|
|
140
51
|
if (typeof _args === 'undefined') {
|
|
@@ -191,7 +102,7 @@ function createClient(args) {
|
|
|
191
102
|
resolve(results);
|
|
192
103
|
};
|
|
193
104
|
try {
|
|
194
|
-
binding.request(context, Operation.
|
|
105
|
+
binding.request(context, bindings_1.Operation.create_accounts, batch, callback);
|
|
195
106
|
}
|
|
196
107
|
catch (error) {
|
|
197
108
|
reject(error);
|
|
@@ -216,7 +127,7 @@ function createClient(args) {
|
|
|
216
127
|
resolve(results);
|
|
217
128
|
};
|
|
218
129
|
try {
|
|
219
|
-
binding.request(context, Operation.
|
|
130
|
+
binding.request(context, bindings_1.Operation.create_transfers, batch, callback);
|
|
220
131
|
}
|
|
221
132
|
catch (error) {
|
|
222
133
|
reject(error);
|
|
@@ -233,7 +144,7 @@ function createClient(args) {
|
|
|
233
144
|
resolve(results);
|
|
234
145
|
};
|
|
235
146
|
try {
|
|
236
|
-
binding.request(context, Operation.
|
|
147
|
+
binding.request(context, bindings_1.Operation.lookup_accounts, batch, callback);
|
|
237
148
|
}
|
|
238
149
|
catch (error) {
|
|
239
150
|
reject(error);
|
|
@@ -250,7 +161,7 @@ function createClient(args) {
|
|
|
250
161
|
resolve(results);
|
|
251
162
|
};
|
|
252
163
|
try {
|
|
253
|
-
binding.request(context, Operation.
|
|
164
|
+
binding.request(context, bindings_1.Operation.lookup_transfers, batch, callback);
|
|
254
165
|
}
|
|
255
166
|
catch (error) {
|
|
256
167
|
reject(error);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@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AI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,QAAQ,GAAG,CAAC,KAAwB,EAAE,OAAmB,EAAE,EAAE;gBACjE,IAAI,KAAK,EAAE;oBACT,MAAM,CAAC,KAAK,CAAC,CAAA;oBACb,OAAM;iBACP;gBACD,OAAO,CAAC,OAAO,CAAC,CAAA;YAClB,CAAC,CAAA;YAED,IAAI;gBACF,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,eAAe,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAA;aACrE;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,CAAC,KAAK,CAAC,CAAA;aACd;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;IAED,MAAM,OAAO,GAAG,GAAS,EAAE;QACzB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QACvB,IAAI,SAAS,EAAC;YACZ,aAAa,CAAC,SAAS,CAAC,CAAA;SACzB;QACD,OAAO,GAAG,SAAS,CAAA;IACrB,CAAC,CAAA;IAED,OAAO,GAAG;QACR,cAAc;QACd,eAAe;QACf,cAAc;QACd,eAAe;QACf,OAAO;QACP,UAAU;QACV,OAAO;KACR,CAAA;IAED,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE;QAC3B,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACvB,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAEnB,OAAO,OAAO,CAAA;AAChB,CAAC;AAzID,oCAyIC","sourcesContent":["function getBinding (): Binding {\n const { arch, platform } = process\n\n const archMap = {\n \"arm64\": \"aarch64\",\n \"x64\": \"x86_64\"\n }\n\n const platformMap = {\n \"linux\": \"linux\",\n \"darwin\": \"macos\"\n }\n\n if (! (arch in archMap)) {\n throw new Error(`Unsupported arch: ${arch}`)\n }\n\n if (! (platform in platformMap)) {\n throw new Error(`Unsupported platform: ${platform}`)\n }\n\n let extra = ''\n\n /**\n * We need to detect during runtime which libc we're running on to load the correct NAPI.\n * binary.\n *\n * Rationale: The /proc/self/map_files/ subdirectory contains entries corresponding to\n * memory-mapped files loaded by Node.\n * https://man7.org/linux/man-pages/man5/proc.5.html: We detect a musl-based distro by\n * checking if any library contains the name \"musl\".\n *\n * Prior art: https://github.com/xerial/sqlite-jdbc/issues/623\n */\n\n const fs = require('fs')\n const path = require('path')\n\n if (platform === 'linux') {\n extra = '-gnu'\n\n for (const file of fs.readdirSync(\"/proc/self/map_files/\")) {\n const realPath = fs.readlinkSync(path.join(\"/proc/self/map_files/\", file))\n if (realPath.includes('musl')) {\n extra = '-musl'\n break\n }\n }\n }\n\n const filename = `./bin/${archMap[arch]}-${platformMap[platform]}${extra}/client.node`\n return require(filename)\n}\n\nconst binding = getBinding()\n\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\n flags_are_mutually_exclusive,\n\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 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 balancing_debit = (1 << 4),\n balancing_credit = (1 << 5),\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\n flags_are_mutually_exclusive,\n\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 pending_id_must_not_be_zero,\n pending_id_must_not_be_int_max,\n pending_id_must_be_different,\n timeout_reserved_for_pending_transfer,\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 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 exists_with_different_flags,\n exists_with_different_debit_account_id,\n exists_with_different_credit_account_id,\n exists_with_different_pending_id,\n exists_with_different_user_data,\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\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,6CAA0B;AAC1B,yCAMmB;AAEnB,SAAS,UAAU;IACjB,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAA;IAElC,MAAM,OAAO,GAAG;QACd,OAAO,EAAE,SAAS;QAClB,KAAK,EAAE,QAAQ;KAChB,CAAA;IAED,MAAM,WAAW,GAAG;QAClB,OAAO,EAAE,OAAO;QAChB,QAAQ,EAAE,OAAO;KAClB,CAAA;IAED,IAAI,CAAE,CAAC,IAAI,IAAI,OAAO,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,EAAE,CAAC,CAAA;KAC7C;IAED,IAAI,CAAE,CAAC,QAAQ,IAAI,WAA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AAE,oBAAS,CAAC,gBAAgB,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAA;aACtE;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,CAAC,KAAK,CAAC,CAAA;aACd;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;IAED,MAAM,OAAO,GAAG,GAAS,EAAE;QACzB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QACvB,IAAI,SAAS,EAAC;YACZ,aAAa,CAAC,SAAS,CAAC,CAAA;SACzB;QACD,OAAO,GAAG,SAAS,CAAA;IACrB,CAAC,CAAA;IAED,OAAO,GAAG;QACR,cAAc;QACd,eAAe;QACf,cAAc;QACd,eAAe;QACf,OAAO;QACP,UAAU;QACV,OAAO;KACR,CAAA;IAED,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE;QAC3B,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACvB,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAEnB,OAAO,OAAO,CAAA;AAChB,CAAC;AAzID,oCAyIC","sourcesContent":["export * from './bindings'\nimport {\n Account,\n Transfer,\n CreateAccountsError,\n CreateTransfersError,\n Operation,\n} from './bindings'\n\nfunction getBinding (): Binding {\n const { arch, platform } = process\n\n const archMap = {\n \"arm64\": \"aarch64\",\n \"x64\": \"x86_64\"\n }\n\n const platformMap = {\n \"linux\": \"linux\",\n \"darwin\": \"macos\"\n }\n\n if (! (arch in archMap)) {\n throw new Error(`Unsupported arch: ${arch}`)\n }\n\n if (! (platform in platformMap)) {\n throw new Error(`Unsupported platform: ${platform}`)\n }\n\n let extra = ''\n\n /**\n * We need to detect during runtime which libc we're running on to load the correct NAPI.\n * binary.\n *\n * Rationale: The /proc/self/map_files/ subdirectory contains entries corresponding to\n * memory-mapped files loaded by Node.\n * https://man7.org/linux/man-pages/man5/proc.5.html: We detect a musl-based distro by\n * checking if any library contains the name \"musl\".\n *\n * Prior art: https://github.com/xerial/sqlite-jdbc/issues/623\n */\n\n const fs = require('fs')\n const path = require('path')\n\n if (platform === 'linux') {\n extra = '-gnu'\n\n for (const file of fs.readdirSync(\"/proc/self/map_files/\")) {\n const realPath = fs.readlinkSync(path.join(\"/proc/self/map_files/\", file))\n if (realPath.includes('musl')) {\n extra = '-musl'\n break\n }\n }\n }\n\n const filename = `./bin/${archMap[arch]}-${platformMap[platform]}${extra}/client.node`\n return require(filename)\n}\n\nconst binding = getBinding()\n\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 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 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_accounts, 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_transfers, 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.lookup_accounts, 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.lookup_transfers, 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
package/src/benchmark.ts
CHANGED
|
@@ -63,7 +63,7 @@ const rawCreateTransfers = async (batch: Buffer): Promise<CreateTransfersError[]
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
try {
|
|
66
|
-
client.rawRequest(Operation.
|
|
66
|
+
client.rawRequest(Operation.create_transfers, batch, callback)
|
|
67
67
|
} catch (error) {
|
|
68
68
|
reject(error)
|
|
69
69
|
}
|