tigerbeetle-node 0.4.2 → 0.5.2

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 (58) hide show
  1. package/README.md +19 -5
  2. package/dist/benchmark.js.map +1 -1
  3. package/dist/index.d.ts +18 -16
  4. package/dist/index.js +35 -13
  5. package/dist/index.js.map +1 -1
  6. package/dist/test.js +12 -0
  7. package/dist/test.js.map +1 -1
  8. package/package.json +2 -2
  9. package/scripts/postinstall.sh +2 -2
  10. package/src/benchmark.ts +2 -2
  11. package/src/index.ts +29 -4
  12. package/src/node.zig +120 -17
  13. package/src/test.ts +14 -0
  14. package/src/tigerbeetle/scripts/install.sh +1 -1
  15. package/src/tigerbeetle/scripts/install_zig.bat +109 -0
  16. package/src/tigerbeetle/scripts/install_zig.sh +4 -2
  17. package/src/tigerbeetle/scripts/lint.zig +8 -2
  18. package/src/tigerbeetle/scripts/vopr.bat +48 -0
  19. package/src/tigerbeetle/src/benchmark.zig +10 -8
  20. package/src/tigerbeetle/src/cli.zig +6 -4
  21. package/src/tigerbeetle/src/config.zig +2 -2
  22. package/src/tigerbeetle/src/demo.zig +119 -89
  23. package/src/tigerbeetle/src/demo_01_create_accounts.zig +5 -3
  24. package/src/tigerbeetle/src/demo_02_lookup_accounts.zig +2 -3
  25. package/src/tigerbeetle/src/demo_03_create_transfers.zig +5 -3
  26. package/src/tigerbeetle/src/demo_04_create_transfers_two_phase_commit.zig +5 -3
  27. package/src/tigerbeetle/src/demo_05_accept_transfers.zig +5 -3
  28. package/src/tigerbeetle/src/demo_06_reject_transfers.zig +5 -3
  29. package/src/tigerbeetle/src/demo_07_lookup_transfers.zig +7 -0
  30. package/src/tigerbeetle/src/io/benchmark.zig +238 -0
  31. package/src/tigerbeetle/src/{io_darwin.zig → io/darwin.zig} +89 -124
  32. package/src/tigerbeetle/src/io/linux.zig +933 -0
  33. package/src/tigerbeetle/src/io/test.zig +621 -0
  34. package/src/tigerbeetle/src/io.zig +7 -1328
  35. package/src/tigerbeetle/src/main.zig +18 -10
  36. package/src/tigerbeetle/src/message_bus.zig +43 -60
  37. package/src/tigerbeetle/src/message_pool.zig +3 -2
  38. package/src/tigerbeetle/src/ring_buffer.zig +135 -68
  39. package/src/tigerbeetle/src/simulator.zig +41 -37
  40. package/src/tigerbeetle/src/state_machine.zig +851 -26
  41. package/src/tigerbeetle/src/storage.zig +49 -46
  42. package/src/tigerbeetle/src/test/cluster.zig +2 -2
  43. package/src/tigerbeetle/src/test/message_bus.zig +6 -6
  44. package/src/tigerbeetle/src/test/network.zig +3 -3
  45. package/src/tigerbeetle/src/test/packet_simulator.zig +32 -29
  46. package/src/tigerbeetle/src/test/state_checker.zig +2 -2
  47. package/src/tigerbeetle/src/test/state_machine.zig +4 -0
  48. package/src/tigerbeetle/src/test/storage.zig +39 -19
  49. package/src/tigerbeetle/src/test/time.zig +2 -2
  50. package/src/tigerbeetle/src/tigerbeetle.zig +6 -129
  51. package/src/tigerbeetle/src/time.zig +6 -5
  52. package/src/tigerbeetle/src/vsr/client.zig +11 -11
  53. package/src/tigerbeetle/src/vsr/clock.zig +26 -43
  54. package/src/tigerbeetle/src/vsr/journal.zig +7 -6
  55. package/src/tigerbeetle/src/vsr/marzullo.zig +6 -3
  56. package/src/tigerbeetle/src/vsr/replica.zig +51 -48
  57. package/src/tigerbeetle/src/vsr.zig +24 -20
  58. package/src/translate.zig +55 -55
package/README.md CHANGED
@@ -1,15 +1,25 @@
1
1
  # tigerbeetle-node
2
- [TigerBeetle](https://github.com/coilhq/tigerbeetle) client for NodeJS
2
+ [TigerBeetle](https://github.com/coilhq/tigerbeetle) client for Node.js.
3
3
 
4
4
  ## Installation
5
- **Prerequisites:** The current version of the client reuses components from TigerBeetle. As such it targets Linux kernel v5.6 or newer. Node >= 14.0.0 is also required.
5
+ The following steps will install the `tigerbeetle-node` module to your current working directory.
6
6
 
7
- Later portable versions of TigerBeetle may supplement `io_uring` with `kqueue` for macOS and FreeBSD support, or `IOCP` for Windows support.
7
+ ### Prerequisites
8
+
9
+ * NodeJS >= `14.0.0`. _(If the correct version is not installed, an installation error will occur)_
10
+
11
+ > Your operating system should be Linux (kernel >= v5.6) or macOS. Windows support is not yet available but is in the works.
12
+
13
+ > Ensure you are not currently in the project (tigerbeetle-node) directory, but the `parent` directory instead;
14
+
15
+ ### YARN Package Manager
8
16
 
9
17
  ```sh
10
18
  yarn add tigerbeetle-node
11
19
  ```
12
20
  or
21
+
22
+ ### NPM Package Manager
13
23
  ```sh
14
24
  npm install tigerbeetle-node
15
25
  ```
@@ -24,7 +34,10 @@ yarn
24
34
  ```
25
35
 
26
36
  ## Usage
27
- A client needs to be configured with a `cluster_id` and `replica_addresses`. This instantiates the client where memory is allocated to internally buffer events to be sent. For the moment, only one client can be instantiated globally per process. Future releases will allow multiple client instantiations.
37
+ A client needs to be configured with a `cluster_id` and `replica_addresses`.
38
+ This instantiates the client where memory is allocated to internally buffer events to be sent.
39
+ For the moment, only one client can be instantiated globally per process.
40
+ Future releases will allow multiple client instantiations.
28
41
  ```js
29
42
  import { createClient } from 'tigerbeetle-node'
30
43
 
@@ -34,7 +47,8 @@ const client = createClient({
34
47
  })
35
48
  ```
36
49
 
37
- One of the ways TigerBeetle achieves its performance is through batching. This is reflected in the below function interfaces where each one takes in an array of events.
50
+ One of the ways TigerBeetle achieves its performance is through batching.
51
+ This is reflected in the below function interfaces where each one takes in an array of events.
38
52
 
39
53
  ### Account Creation
40
54
 
@@ -1 +1 @@
1
- {"version":3,"file":"benchmark.js","sourceRoot":"","sources":["../src/benchmark.ts"],"names":[],"mappings":";;;;;AAAA,oDAA2B;AAC3B,wBASU;AAEV,MAAM,aAAa,GAAG,OAAO,CAAA;AAC7B,MAAM,sBAAsB,GAAG,KAAK,CAAA;AACpC,MAAM,mBAAmB,GAAG,KAAK,CAAA;AACjC,MAAM,cAAc,GAAG,KAAK,CAAA;AAC5B,MAAM,2BAA2B,GAAG,mBAAmB,CAAC,CAAC,CAAC,MAA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AAY,CAAC,CAAC,CAAC,EAAE,yBAAyB,MAAM,EAAE,CAAC,CAAA;IACxF,OAAO,CAAC,GAAG,CAAC,4DAA4D,SAAS,CAAC,yBAAyB,IAAI,CAAC,CAAA;IAChH,OAAO,CAAC,GAAG,CAAC,4DAA4D,SAAS,CAAC,yBAAyB,IAAI,CAAC,CAAA;IAChH,gBAAM,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAA;IAC7B,gBAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,eAAe,KAAK,MAAM,CAAC,aAAa,CAAC,CAAC,CAAA;IAC7D,gBAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,gBAAgB,KAAK,MAAM,CAAC,aAAa,CAAC,CAAC,CAAA;IAE9D,IAAI,MAAM,GAAG,kBAAkB,GAAG,CAAC,GAAG,GAAG,SAAS,CAAC,GAAC,GAAG,EAAE;QACvD,OAAO,CAAC,IAAI,CAAC,+DAA+D,kBAAkB,EAAE,CAAC,CAAA;KAClG;AACH,CAAC,CAAA;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IACnB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;AACpB,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE;IACpB,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;AACxB,CAAC,CAAC,CAAA","sourcesContent":["import assert from 'assert'\nimport {\n Commit,\n Account,\n createClient,\n Transfer,\n TransferFlags,\n CreateTransfersError,\n CommitTransfersError,\n Operation\n} from '.'\n\nconst MAX_TRANSFERS = 1000000\nconst MAX_REQUEST_BATCH_SIZE = 10000\nconst IS_TWO_PHASE_COMMIT = false\nconst IS_RAW_REQUEST = false\nconst PREVIOUS_RAW_REQUEST_RESULT = IS_TWO_PHASE_COMMIT ? 300000 : 620000\nconst PREVIOUS_RESULT = IS_TWO_PHASE_COMMIT ? 150000 : 310000\nconst PREVIOUS_BENCHMARK = IS_RAW_REQUEST ? PREVIOUS_RAW_REQUEST_RESULT : PREVIOUS_RESULT\nconst TOLERANCE = 10 // percent that the benchmark is allowed to deviate from the previous benchmark\n\nconst client = createClient({\n cluster_id: 1,\n replica_addresses: ['3001']\n})\n\nconst TRANSFER_SIZE = 128\nconst COMMIT_SIZE = 64\nconst Zeroed48Bytes = Buffer.alloc(48, 0)\nconst Zeroed32Bytes = Buffer.alloc(32, 0)\nconst accountA: Account = {\n id: 137n,\n user_data: 0n,\n reserved: Zeroed48Bytes,\n code: 0,\n flags: 0,\n unit: 1,\n debits_accepted: 0n,\n debits_reserved: 0n,\n credits_accepted: 0n,\n credits_reserved: 0n,\n timestamp: 0n,\n}\n\nconst accountB: Account = {\n id: 138n,\n user_data: 0n,\n reserved: Zeroed48Bytes,\n code: 0,\n flags: 0,\n unit: 1,\n debits_accepted: 0n,\n debits_reserved: 0n,\n credits_accepted: 0n,\n credits_reserved: 0n,\n timestamp: 0n,\n}\n\n// helper function to promisify the raw_request\nconst rawCreateTransfers = async (batch: Buffer): Promise<CreateTransfersError[]> => {\n return new Promise((resolve, reject) => {\n const callback = (error: undefined | Error, results: CreateTransfersError[]) => {\n if (error) {\n reject(error)\n }\n resolve(results)\n }\n\n try {\n client.rawRequest(Operation.CREATE_TRANSFER, batch, callback)\n } catch (error) {\n reject(error)\n }\n })\n}\n\n// helper function to promisify the raw_request\nconst rawCommitTransfers = async (batch: Buffer): Promise<CommitTransfersError[]> => {\n return new Promise((resolve, reject) => {\n const callback = (error: undefined | Error, results: CommitTransfersError[]) => {\n if (error) {\n reject(error)\n }\n resolve(results)\n }\n\n try {\n client.rawRequest(Operation.COMMIT_TRANSFER, batch, callback)\n } catch (error) {\n reject(error)\n }\n })\n}\n\n/**\n * This encoding function is only for this benchmark script.\n * \n * ID_OFFSET = 0\n * DEBIT_ACCOUNT_ID_OFFSET = 0 + 16 = 16\n * CREDIT_ACCOUNT_ID_OFFSET = 16 + 16 = 32\n * USER_DATA_OFFSET = 32 + 16 = 48\n * RESERVED_OFFSET = 48 + 16 = 64\n * TIMEOUT_OFFSET = 64 + 32 = 96\n * CODE_OFFSET = 96 + 8 = 104\n * FLAGS_OFFSET = 104 + 4 = 108\n * AMOUNT_OFFSET = 108 + 4 = 112\n * TIMESTAMP_OFFSET = 112 + 8 = 120\n */ \nconst encodeTransfer = (transfer: Transfer, offset: number, output: Buffer): void => {\n assert(offset + TRANSFER_SIZE <= output.length)\n\n output.writeBigUInt64LE(transfer.id, offset)\n output.writeBigUInt64LE(transfer.debit_account_id, offset + 16)\n output.writeBigUInt64LE(transfer.credit_account_id, offset + 32)\n output.writeBigUInt64LE(transfer.timeout, offset + 96)\n output.writeUInt32LE(transfer.code, offset + 104)\n output.writeUInt32LE(transfer.flags, offset + 108)\n output.writeBigUInt64LE(transfer.amount, offset + 112)\n output.writeBigUInt64LE(transfer.timestamp, offset + 120)\n}\n\n// This encoding function is only for this benchmark script.\nconst encodeCommit = (commit: Commit, offset: number, output: Buffer): void => {\n assert(offset + COMMIT_SIZE <= output.length)\n\n output.writeBigUInt64LE(commit.id, offset)\n}\n\nconst runBenchmarkRawReqeust = async () => {\n assert(\n MAX_TRANSFERS % MAX_REQUEST_BATCH_SIZE === 0,\n \"The raw request benchmark requires MAX_TRANSFERS to be a multiple of MAX_REQUEST_BATCH_SIZE\"\n )\n console.log(`pre-allocating ${MAX_TRANSFERS} transfers and commits...`)\n const transfers: Buffer[] = []\n const commits: Buffer[] = []\n\n let count = 0\n while (count < MAX_TRANSFERS) {\n const transferBatch = Buffer.alloc(MAX_REQUEST_BATCH_SIZE * TRANSFER_SIZE, 0)\n const commitBatch = Buffer.alloc(MAX_REQUEST_BATCH_SIZE * COMMIT_SIZE, 0)\n for (let i = 0; i < MAX_REQUEST_BATCH_SIZE; i++) {\n if (count === MAX_TRANSFERS) break\n\n count += 1\n encodeTransfer(\n {\n id: BigInt(count),\n debit_account_id: accountA.id,\n credit_account_id: accountB.id,\n code: 0,\n reserved: Zeroed32Bytes,\n user_data: 0n,\n flags: IS_TWO_PHASE_COMMIT ? TransferFlags.two_phase_commit : 0,\n amount: 1n,\n timeout: IS_TWO_PHASE_COMMIT ? BigInt(2e9) : 0n,\n timestamp: 0n,\n },\n i * TRANSFER_SIZE,\n transferBatch\n )\n \n if (IS_TWO_PHASE_COMMIT) {\n encodeCommit(\n {\n id: BigInt(count),\n reserved: Buffer.alloc(32, 0),\n code: 0,\n flags: 0,\n timestamp: 0n,\n },\n i * COMMIT_SIZE,\n commitBatch \n )\n }\n }\n\n transfers.push(transferBatch)\n if (IS_TWO_PHASE_COMMIT) commits.push(commitBatch)\n }\n assert(count === MAX_TRANSFERS)\n\n console.log(`starting benchmark. MAX_TRANSFERS=${MAX_TRANSFERS} REQUEST_BATCH_SIZE=${MAX_REQUEST_BATCH_SIZE} NUMBER_OF_BATCHES=${transfers.length}`)\n let maxCreateTransfersLatency = 0\n let maxCommitTransfersLatency = 0\n const start = Date.now()\n\n for(let i = 0; i < transfers.length; i++) {\n const ms1 = Date.now()\n\n const transferResults = await rawCreateTransfers(transfers[i])\n assert(transferResults.length === 0)\n\n const ms2 = Date.now()\n const createTransferLatency = ms2 - ms1\n if (createTransferLatency > maxCreateTransfersLatency) {\n maxCreateTransfersLatency = createTransferLatency\n }\n\n if (IS_TWO_PHASE_COMMIT) {\n const commitResults = await rawCommitTransfers(commits[i])\n assert(commitResults.length === 0)\n\n const ms3 = Date.now()\n const commitTransferLatency = ms3 - ms2\n if (commitTransferLatency > maxCommitTransfersLatency) {\n maxCommitTransfersLatency = commitTransferLatency\n }\n }\n }\n\n const ms = Date.now() - start\n\n return {\n ms,\n maxCommitTransfersLatency,\n maxCreateTransfersLatency\n }\n}\n\nconst runBenchmark = async () => {\n console.log(`pre-allocating ${MAX_TRANSFERS} transfers and commits...`)\n const transfers: Transfer[][] = []\n const commits: Commit[][] = []\n\n let count = 0\n while (count < MAX_TRANSFERS) {\n const transferBatch: Transfer[] = []\n const commitBatch: Commit[] = []\n for (let i = 0; i < MAX_REQUEST_BATCH_SIZE; i++) {\n if (count === MAX_TRANSFERS) break\n\n count += 1\n transferBatch.push({\n id: BigInt(count),\n debit_account_id: accountA.id,\n credit_account_id: accountB.id,\n code: 0,\n reserved: Zeroed32Bytes,\n user_data: 0n,\n flags: IS_TWO_PHASE_COMMIT ? TransferFlags.two_phase_commit : 0,\n amount: 1n,\n timeout: IS_TWO_PHASE_COMMIT ? BigInt(2e9) : 0n,\n timestamp: 0n,\n })\n \n if (IS_TWO_PHASE_COMMIT) {\n commitBatch.push({\n id: BigInt(count),\n reserved: Buffer.alloc(32, 0),\n code: 0,\n flags: 0,\n timestamp: 0n,\n })\n }\n }\n\n transfers.push(transferBatch)\n if (IS_TWO_PHASE_COMMIT) commits.push(commitBatch)\n }\n assert(count === MAX_TRANSFERS)\n\n console.log(`starting benchmark. MAX_TRANSFERS=${MAX_TRANSFERS} REQUEST_BATCH_SIZE=${MAX_REQUEST_BATCH_SIZE} NUMBER_OF_BATCHES=${transfers.length}`)\n let maxCreateTransfersLatency = 0\n let maxCommitTransfersLatency = 0\n const start = Date.now()\n\n for(let i = 0; i < transfers.length; i++) {\n const ms1 = Date.now()\n\n const transferResults = await client.createTransfers(transfers[i])\n assert(transferResults.length === 0)\n\n const ms2 = Date.now()\n const createTransferLatency = ms2 - ms1\n if (createTransferLatency > maxCreateTransfersLatency) {\n maxCreateTransfersLatency = createTransferLatency\n }\n\n if (IS_TWO_PHASE_COMMIT) {\n const commitResults = await client.commitTransfers(commits[i])\n assert(commitResults.length === 0)\n\n const ms3 = Date.now()\n const commitTransferLatency = ms3 - ms2\n if (commitTransferLatency > maxCommitTransfersLatency) {\n maxCommitTransfersLatency = commitTransferLatency\n }\n }\n }\n\n const ms = Date.now() - start\n\n return {\n ms,\n maxCommitTransfersLatency,\n maxCreateTransfersLatency\n }\n}\n\nconst main = async () => { \n console.log(\"creating the accounts...\")\n await client.createAccounts([accountA, accountB])\n const accountResults = await client.lookupAccounts([accountA.id, accountB.id])\n assert(accountResults.length === 2)\n assert(accountResults[0].debits_accepted === 0n)\n assert(accountResults[1].debits_accepted === 0n)\n\n const benchmark = IS_RAW_REQUEST ? await runBenchmarkRawReqeust() : await runBenchmark() \n \n const accounts = await client.lookupAccounts([accountA.id, accountB.id])\n const result = Math.floor((1000 * MAX_TRANSFERS)/benchmark.ms)\n console.log(\"=============================\")\n console.log(`${IS_TWO_PHASE_COMMIT ? 'two-phase ' : ''}transfers per second: ${result}`)\n console.log(`create transfers max p100 latency per 10 000 transfers = ${benchmark.maxCreateTransfersLatency}ms`)\n console.log(`commit transfers max p100 latency per 10 000 transfers = ${benchmark.maxCommitTransfersLatency}ms`)\n assert(accounts.length === 2)\n assert(accounts[0].debits_accepted === BigInt(MAX_TRANSFERS))\n assert(accounts[1].credits_accepted === BigInt(MAX_TRANSFERS))\n\n if (result < PREVIOUS_BENCHMARK * (100 - TOLERANCE)/100) {\n console.warn(`There has been a performance regression. Previous benchmark=${PREVIOUS_BENCHMARK}`)\n }\n}\n\nmain().catch(error => { \n console.log(error)\n}).finally(async () => {\n await client.destroy()\n})\n"]}
1
+ {"version":3,"file":"benchmark.js","sourceRoot":"","sources":["../src/benchmark.ts"],"names":[],"mappings":";;;;;AAAA,oDAA2B;AAC3B,wBASU;AAEV,MAAM,aAAa,GAAG,OAAO,CAAA;AAC7B,MAAM,sBAAsB,GAAG,KAAK,CAAA;AACpC,MAAM,mBAAmB,GAAG,KAAK,CAAA;AACjC,MAAM,cAAc,GAAG,KAAK,CAAA;AAC5B,MAAM,2BAA2B,GAAG,mBAAmB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAA;AACzE,MAAM,eAAe,GAAG,mBAAmB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAA;AAC7D,MAAM,kBAAkB,GAAG,cAAc,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAC,CAAC,eAAe,CAAA;AACzF,MAAM,SAAS,GAAG,EAAE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Q,CAAC,MAAM,KAAK,CAAC,CAAC,CAAA;IAC7B,gBAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,eAAe,KAAK,MAAM,CAAC,aAAa,CAAC,CAAC,CAAA;IAC7D,gBAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,gBAAgB,KAAK,MAAM,CAAC,aAAa,CAAC,CAAC,CAAA;IAE9D,IAAI,MAAM,GAAG,kBAAkB,GAAG,CAAC,GAAG,GAAG,SAAS,CAAC,GAAC,GAAG,EAAE;QACvD,OAAO,CAAC,IAAI,CAAC,+DAA+D,kBAAkB,EAAE,CAAC,CAAA;KAClG;AACH,CAAC,CAAA;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IACnB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;AACpB,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE;IACpB,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;AACxB,CAAC,CAAC,CAAA","sourcesContent":["import assert from 'assert'\nimport {\n Commit,\n Account,\n createClient,\n Transfer,\n TransferFlags,\n CreateTransfersError,\n CommitTransfersError,\n Operation\n} from '.'\n\nconst MAX_TRANSFERS = 1000000\nconst MAX_REQUEST_BATCH_SIZE = 10000\nconst IS_TWO_PHASE_COMMIT = false\nconst IS_RAW_REQUEST = false\nconst PREVIOUS_RAW_REQUEST_RESULT = IS_TWO_PHASE_COMMIT ? 300000 : 620000\nconst PREVIOUS_RESULT = IS_TWO_PHASE_COMMIT ? 150000 : 310000\nconst PREVIOUS_BENCHMARK = IS_RAW_REQUEST ? PREVIOUS_RAW_REQUEST_RESULT : PREVIOUS_RESULT\nconst TOLERANCE = 10 // percent that the benchmark is allowed to deviate from the previous benchmark\n\nconst client = createClient({\n cluster_id: 1,\n replica_addresses: ['3001']\n})\n\nconst TRANSFER_SIZE = 128\nconst COMMIT_SIZE = 64\nconst Zeroed48Bytes = Buffer.alloc(48, 0)\nconst Zeroed32Bytes = Buffer.alloc(32, 0)\nconst accountA: Account = {\n id: 137n,\n user_data: 0n,\n reserved: Zeroed48Bytes,\n code: 0,\n flags: 0,\n unit: 1,\n debits_accepted: 0n,\n debits_reserved: 0n,\n credits_accepted: 0n,\n credits_reserved: 0n,\n timestamp: 0n,\n}\n\nconst accountB: Account = {\n id: 138n,\n user_data: 0n,\n reserved: Zeroed48Bytes,\n code: 0,\n flags: 0,\n unit: 1,\n debits_accepted: 0n,\n debits_reserved: 0n,\n credits_accepted: 0n,\n credits_reserved: 0n,\n timestamp: 0n,\n}\n\n// helper function to promisify the raw_request\nconst rawCreateTransfers = async (batch: Buffer): Promise<CreateTransfersError[]> => {\n return new Promise((resolve, reject) => {\n const callback = (error: undefined | Error, results: CreateTransfersError[]) => {\n if (error) {\n reject(error)\n }\n resolve(results)\n }\n\n try {\n client.rawRequest(Operation.CREATE_TRANSFER, batch, callback)\n } catch (error) {\n reject(error)\n }\n })\n}\n\n// helper function to promisify the raw_request\nconst rawCommitTransfers = async (batch: Buffer): Promise<CommitTransfersError[]> => {\n return new Promise((resolve, reject) => {\n const callback = (error: undefined | Error, results: CommitTransfersError[]) => {\n if (error) {\n reject(error)\n }\n resolve(results)\n }\n\n try {\n client.rawRequest(Operation.COMMIT_TRANSFER, batch, callback)\n } catch (error) {\n reject(error)\n }\n })\n}\n\n/**\n * This encoding function is only for this benchmark script.\n * \n * ID_OFFSET = 0\n * DEBIT_ACCOUNT_ID_OFFSET = 0 + 16 = 16\n * CREDIT_ACCOUNT_ID_OFFSET = 16 + 16 = 32\n * USER_DATA_OFFSET = 32 + 16 = 48\n * RESERVED_OFFSET = 48 + 16 = 64\n * TIMEOUT_OFFSET = 64 + 32 = 96\n * CODE_OFFSET = 96 + 8 = 104\n * FLAGS_OFFSET = 104 + 4 = 108\n * AMOUNT_OFFSET = 108 + 4 = 112\n * TIMESTAMP_OFFSET = 112 + 8 = 120\n */ \nconst encodeTransfer = (transfer: Transfer, offset: number, output: Buffer): void => {\n assert(offset + TRANSFER_SIZE <= output.length)\n\n output.writeBigUInt64LE(transfer.id, offset)\n output.writeBigUInt64LE(transfer.debit_account_id, offset + 16)\n output.writeBigUInt64LE(transfer.credit_account_id, offset + 32)\n output.writeBigUInt64LE(transfer.timeout, offset + 96)\n output.writeUInt32LE(transfer.code, offset + 104)\n output.writeUInt32LE(transfer.flags, offset + 108)\n output.writeBigUInt64LE(transfer.amount, offset + 112)\n output.writeBigUInt64LE(transfer.timestamp, offset + 120)\n}\n\n// This encoding function is only for this benchmark script.\nconst encodeCommit = (commit: Commit, offset: number, output: Buffer): void => {\n assert(offset + COMMIT_SIZE <= output.length)\n\n output.writeBigUInt64LE(commit.id, offset)\n}\n\nconst runBenchmarkRawReqeust = async () => {\n assert(\n MAX_TRANSFERS % MAX_REQUEST_BATCH_SIZE === 0,\n \"The raw request benchmark requires MAX_TRANSFERS to be a multiple of MAX_REQUEST_BATCH_SIZE\"\n )\n console.log(`pre-allocating ${MAX_TRANSFERS} transfers and commits...`)\n const transfers: Buffer[] = []\n const commits: Buffer[] = []\n\n let count = 0\n while (count < MAX_TRANSFERS) {\n const transferBatch = Buffer.alloc(MAX_REQUEST_BATCH_SIZE * TRANSFER_SIZE, 0)\n const commitBatch = Buffer.alloc(MAX_REQUEST_BATCH_SIZE * COMMIT_SIZE, 0)\n for (let i = 0; i < MAX_REQUEST_BATCH_SIZE; i++) {\n if (count === MAX_TRANSFERS) break\n\n count += 1\n encodeTransfer(\n {\n id: BigInt(count),\n debit_account_id: accountA.id,\n credit_account_id: accountB.id,\n code: 0,\n reserved: Zeroed32Bytes,\n user_data: 0n,\n flags: IS_TWO_PHASE_COMMIT ? TransferFlags.two_phase_commit : 0,\n amount: 1n,\n timeout: IS_TWO_PHASE_COMMIT ? BigInt(2e9) : 0n,\n timestamp: 0n,\n },\n i * TRANSFER_SIZE,\n transferBatch\n )\n \n if (IS_TWO_PHASE_COMMIT) {\n encodeCommit(\n {\n id: BigInt(count),\n reserved: Buffer.alloc(32, 0),\n code: 0,\n flags: 0,\n timestamp: 0n,\n },\n i * COMMIT_SIZE,\n commitBatch \n )\n }\n }\n\n transfers.push(transferBatch)\n if (IS_TWO_PHASE_COMMIT) commits.push(commitBatch)\n }\n assert(count === MAX_TRANSFERS)\n\n console.log(`starting benchmark. MAX_TRANSFERS=${MAX_TRANSFERS} REQUEST_BATCH_SIZE=${MAX_REQUEST_BATCH_SIZE} NUMBER_OF_BATCHES=${transfers.length}`)\n let maxCreateTransfersLatency = 0\n let maxCommitTransfersLatency = 0\n const start = Date.now()\n\n for (let i = 0; i < transfers.length; i++) {\n const ms1 = Date.now()\n\n const transferResults = await rawCreateTransfers(transfers[i])\n assert(transferResults.length === 0)\n\n const ms2 = Date.now()\n const createTransferLatency = ms2 - ms1\n if (createTransferLatency > maxCreateTransfersLatency) {\n maxCreateTransfersLatency = createTransferLatency\n }\n\n if (IS_TWO_PHASE_COMMIT) {\n const commitResults = await rawCommitTransfers(commits[i])\n assert(commitResults.length === 0)\n\n const ms3 = Date.now()\n const commitTransferLatency = ms3 - ms2\n if (commitTransferLatency > maxCommitTransfersLatency) {\n maxCommitTransfersLatency = commitTransferLatency\n }\n }\n }\n\n const ms = Date.now() - start\n\n return {\n ms,\n maxCommitTransfersLatency,\n maxCreateTransfersLatency\n }\n}\n\nconst runBenchmark = async () => {\n console.log(`pre-allocating ${MAX_TRANSFERS} transfers and commits...`)\n const transfers: Transfer[][] = []\n const commits: Commit[][] = []\n\n let count = 0\n while (count < MAX_TRANSFERS) {\n const transferBatch: Transfer[] = []\n const commitBatch: Commit[] = []\n for (let i = 0; i < MAX_REQUEST_BATCH_SIZE; i++) {\n if (count === MAX_TRANSFERS) break\n\n count += 1\n transferBatch.push({\n id: BigInt(count),\n debit_account_id: accountA.id,\n credit_account_id: accountB.id,\n code: 0,\n reserved: Zeroed32Bytes,\n user_data: 0n,\n flags: IS_TWO_PHASE_COMMIT ? TransferFlags.two_phase_commit : 0,\n amount: 1n,\n timeout: IS_TWO_PHASE_COMMIT ? BigInt(2e9) : 0n,\n timestamp: 0n,\n })\n \n if (IS_TWO_PHASE_COMMIT) {\n commitBatch.push({\n id: BigInt(count),\n reserved: Buffer.alloc(32, 0),\n code: 0,\n flags: 0,\n timestamp: 0n,\n })\n }\n }\n\n transfers.push(transferBatch)\n if (IS_TWO_PHASE_COMMIT) commits.push(commitBatch)\n }\n assert(count === MAX_TRANSFERS)\n\n console.log(`starting benchmark. MAX_TRANSFERS=${MAX_TRANSFERS} REQUEST_BATCH_SIZE=${MAX_REQUEST_BATCH_SIZE} NUMBER_OF_BATCHES=${transfers.length}`)\n let maxCreateTransfersLatency = 0\n let maxCommitTransfersLatency = 0\n const start = Date.now()\n\n for (let i = 0; i < transfers.length; i++) {\n const ms1 = Date.now()\n\n const transferResults = await client.createTransfers(transfers[i])\n assert(transferResults.length === 0)\n\n const ms2 = Date.now()\n const createTransferLatency = ms2 - ms1\n if (createTransferLatency > maxCreateTransfersLatency) {\n maxCreateTransfersLatency = createTransferLatency\n }\n\n if (IS_TWO_PHASE_COMMIT) {\n const commitResults = await client.commitTransfers(commits[i])\n assert(commitResults.length === 0)\n\n const ms3 = Date.now()\n const commitTransferLatency = ms3 - ms2\n if (commitTransferLatency > maxCommitTransfersLatency) {\n maxCommitTransfersLatency = commitTransferLatency\n }\n }\n }\n\n const ms = Date.now() - start\n\n return {\n ms,\n maxCommitTransfersLatency,\n maxCreateTransfersLatency\n }\n}\n\nconst main = async () => { \n console.log(\"creating the accounts...\")\n await client.createAccounts([accountA, accountB])\n const accountResults = await client.lookupAccounts([accountA.id, accountB.id])\n assert(accountResults.length === 2)\n assert(accountResults[0].debits_accepted === 0n)\n assert(accountResults[1].debits_accepted === 0n)\n\n const benchmark = IS_RAW_REQUEST ? await runBenchmarkRawReqeust() : await runBenchmark() \n \n const accounts = await client.lookupAccounts([accountA.id, accountB.id])\n const result = Math.floor((1000 * MAX_TRANSFERS)/benchmark.ms)\n console.log(\"=============================\")\n console.log(`${IS_TWO_PHASE_COMMIT ? 'two-phase ' : ''}transfers per second: ${result}`)\n console.log(`create transfers max p100 latency per 10 000 transfers = ${benchmark.maxCreateTransfersLatency}ms`)\n console.log(`commit transfers max p100 latency per 10 000 transfers = ${benchmark.maxCommitTransfersLatency}ms`)\n assert(accounts.length === 2)\n assert(accounts[0].debits_accepted === BigInt(MAX_TRANSFERS))\n assert(accounts[1].credits_accepted === BigInt(MAX_TRANSFERS))\n\n if (result < PREVIOUS_BENCHMARK * (100 - TOLERANCE)/100) {\n console.warn(`There has been a performance regression. Previous benchmark=${PREVIOUS_BENCHMARK}`)\n }\n}\n\nmain().catch(error => { \n console.log(error)\n}).finally(async () => {\n await client.destroy()\n})\n"]}
package/dist/index.d.ts CHANGED
@@ -104,39 +104,41 @@ export declare enum CommitTransferError {
104
104
  transfer_not_found = 4,
105
105
  transfer_not_two_phase_commit = 5,
106
106
  transfer_expired = 6,
107
- already_auto_committed = 7,
108
- already_committed = 8,
109
- already_committed_but_accepted = 9,
110
- already_committed_but_rejected = 10,
111
- debit_account_not_found = 11,
112
- credit_account_not_found = 12,
113
- debit_amount_was_not_reserved = 13,
114
- credit_amount_was_not_reserved = 14,
115
- exceeds_credits = 15,
116
- exceeds_debits = 16,
117
- condition_requires_preimage = 17,
118
- preimage_requires_condition = 18,
119
- preimage_invalid = 19
107
+ already_committed = 7,
108
+ already_committed_but_accepted = 8,
109
+ already_committed_but_rejected = 9,
110
+ debit_account_not_found = 10,
111
+ credit_account_not_found = 11,
112
+ debit_amount_was_not_reserved = 12,
113
+ credit_amount_was_not_reserved = 13,
114
+ exceeds_credits = 14,
115
+ exceeds_debits = 15,
116
+ condition_requires_preimage = 16,
117
+ preimage_requires_condition = 17,
118
+ preimage_invalid = 18
120
119
  }
121
120
  export declare type CommitTransfersError = {
122
121
  index: number;
123
122
  code: CommitTransferError;
124
123
  };
125
124
  export declare type AccountID = bigint;
126
- export declare type Event = Account | Transfer | Commit | AccountID;
127
- export declare type Result = CreateAccountsError | CreateTransfersError | CommitTransfersError | Account;
125
+ export declare type TransferID = bigint;
126
+ export declare type Event = Account | Transfer | Commit | AccountID | TransferID;
127
+ export declare type Result = CreateAccountsError | CreateTransfersError | CommitTransfersError | Account | Transfer;
128
128
  export declare type ResultCallback = (error: undefined | Error, results: Result[]) => void;
129
129
  export declare enum Operation {
130
130
  CREATE_ACCOUNT = 3,
131
131
  CREATE_TRANSFER = 4,
132
132
  COMMIT_TRANSFER = 5,
133
- ACCOUNT_LOOKUP = 6
133
+ ACCOUNT_LOOKUP = 6,
134
+ TRANSFER_LOOKUP = 7
134
135
  }
135
136
  export interface Client {
136
137
  createAccounts: (batch: Account[]) => Promise<CreateAccountsError[]>;
137
138
  createTransfers: (batch: Transfer[]) => Promise<CreateTransfersError[]>;
138
139
  commitTransfers: (batch: Commit[]) => Promise<CommitTransfersError[]>;
139
140
  lookupAccounts: (batch: AccountID[]) => Promise<Account[]>;
141
+ lookupTransfers: (batch: TransferID[]) => Promise<Transfer[]>;
140
142
  request: (operation: Operation, batch: Event[], callback: ResultCallback) => void;
141
143
  rawRequest: (operation: Operation, rawBatch: Buffer, callback: ResultCallback) => void;
142
144
  destroy: () => void;
package/dist/index.js CHANGED
@@ -68,19 +68,18 @@ var CommitTransferError;
68
68
  CommitTransferError[CommitTransferError["transfer_not_found"] = 4] = "transfer_not_found";
69
69
  CommitTransferError[CommitTransferError["transfer_not_two_phase_commit"] = 5] = "transfer_not_two_phase_commit";
70
70
  CommitTransferError[CommitTransferError["transfer_expired"] = 6] = "transfer_expired";
71
- CommitTransferError[CommitTransferError["already_auto_committed"] = 7] = "already_auto_committed";
72
- CommitTransferError[CommitTransferError["already_committed"] = 8] = "already_committed";
73
- CommitTransferError[CommitTransferError["already_committed_but_accepted"] = 9] = "already_committed_but_accepted";
74
- CommitTransferError[CommitTransferError["already_committed_but_rejected"] = 10] = "already_committed_but_rejected";
75
- CommitTransferError[CommitTransferError["debit_account_not_found"] = 11] = "debit_account_not_found";
76
- CommitTransferError[CommitTransferError["credit_account_not_found"] = 12] = "credit_account_not_found";
77
- CommitTransferError[CommitTransferError["debit_amount_was_not_reserved"] = 13] = "debit_amount_was_not_reserved";
78
- CommitTransferError[CommitTransferError["credit_amount_was_not_reserved"] = 14] = "credit_amount_was_not_reserved";
79
- CommitTransferError[CommitTransferError["exceeds_credits"] = 15] = "exceeds_credits";
80
- CommitTransferError[CommitTransferError["exceeds_debits"] = 16] = "exceeds_debits";
81
- CommitTransferError[CommitTransferError["condition_requires_preimage"] = 17] = "condition_requires_preimage";
82
- CommitTransferError[CommitTransferError["preimage_requires_condition"] = 18] = "preimage_requires_condition";
83
- CommitTransferError[CommitTransferError["preimage_invalid"] = 19] = "preimage_invalid";
71
+ CommitTransferError[CommitTransferError["already_committed"] = 7] = "already_committed";
72
+ CommitTransferError[CommitTransferError["already_committed_but_accepted"] = 8] = "already_committed_but_accepted";
73
+ CommitTransferError[CommitTransferError["already_committed_but_rejected"] = 9] = "already_committed_but_rejected";
74
+ CommitTransferError[CommitTransferError["debit_account_not_found"] = 10] = "debit_account_not_found";
75
+ CommitTransferError[CommitTransferError["credit_account_not_found"] = 11] = "credit_account_not_found";
76
+ CommitTransferError[CommitTransferError["debit_amount_was_not_reserved"] = 12] = "debit_amount_was_not_reserved";
77
+ CommitTransferError[CommitTransferError["credit_amount_was_not_reserved"] = 13] = "credit_amount_was_not_reserved";
78
+ CommitTransferError[CommitTransferError["exceeds_credits"] = 14] = "exceeds_credits";
79
+ CommitTransferError[CommitTransferError["exceeds_debits"] = 15] = "exceeds_debits";
80
+ CommitTransferError[CommitTransferError["condition_requires_preimage"] = 16] = "condition_requires_preimage";
81
+ CommitTransferError[CommitTransferError["preimage_requires_condition"] = 17] = "preimage_requires_condition";
82
+ CommitTransferError[CommitTransferError["preimage_invalid"] = 18] = "preimage_invalid";
84
83
  })(CommitTransferError = exports.CommitTransferError || (exports.CommitTransferError = {}));
85
84
  var Operation;
86
85
  (function (Operation) {
@@ -88,6 +87,7 @@ var Operation;
88
87
  Operation[Operation["CREATE_TRANSFER"] = 4] = "CREATE_TRANSFER";
89
88
  Operation[Operation["COMMIT_TRANSFER"] = 5] = "COMMIT_TRANSFER";
90
89
  Operation[Operation["ACCOUNT_LOOKUP"] = 6] = "ACCOUNT_LOOKUP";
90
+ Operation[Operation["TRANSFER_LOOKUP"] = 7] = "TRANSFER_LOOKUP";
91
91
  })(Operation = exports.Operation || (exports.Operation = {}));
92
92
  let _args = undefined;
93
93
  const isSameArgs = (args) => {
@@ -141,6 +141,7 @@ function createClient(args) {
141
141
  const callback = (error, results) => {
142
142
  if (error) {
143
143
  reject(error);
144
+ return;
144
145
  }
145
146
  resolve(results);
146
147
  };
@@ -165,6 +166,7 @@ function createClient(args) {
165
166
  const callback = (error, results) => {
166
167
  if (error) {
167
168
  reject(error);
169
+ return;
168
170
  }
169
171
  resolve(results);
170
172
  };
@@ -189,6 +191,7 @@ function createClient(args) {
189
191
  const callback = (error, results) => {
190
192
  if (error) {
191
193
  reject(error);
194
+ return;
192
195
  }
193
196
  resolve(results);
194
197
  };
@@ -205,6 +208,7 @@ function createClient(args) {
205
208
  const callback = (error, results) => {
206
209
  if (error) {
207
210
  reject(error);
211
+ return;
208
212
  }
209
213
  resolve(results);
210
214
  };
@@ -216,6 +220,23 @@ function createClient(args) {
216
220
  }
217
221
  });
218
222
  };
223
+ const lookupTransfers = async (batch) => {
224
+ return new Promise((resolve, reject) => {
225
+ const callback = (error, results) => {
226
+ if (error) {
227
+ reject(error);
228
+ return;
229
+ }
230
+ resolve(results);
231
+ };
232
+ try {
233
+ binding.request(context, Operation.TRANSFER_LOOKUP, batch, callback);
234
+ }
235
+ catch (error) {
236
+ reject(error);
237
+ }
238
+ });
239
+ };
219
240
  const destroy = () => {
220
241
  binding.deinit(context);
221
242
  if (_interval) {
@@ -228,6 +249,7 @@ function createClient(args) {
228
249
  createTransfers,
229
250
  commitTransfers,
230
251
  lookupAccounts,
252
+ lookupTransfers,
231
253
  request,
232
254
  rawRequest,
233
255
  destroy
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,kBAYX;AAZD,WAAY,kBAAkB;IAC5B,yFAAuB,CAAA;IACvB,+DAAM,CAAA;IACN,iHAA+B,CAAA;IAC/B,2HAAoC,CAAA;IACpC,uGAA0B,CAAA;IAC1B,uGAA0B,CAAA;IAC1B,yGAA2B,CAAA;IAC3B,iFAAe,CAAA;IACf,+EAAc,CAAA;IACd,gFAAc,CAAA;IACd,8FAAqB,CAAA;AACvB,CAAC,EAZW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAY7B;AAoBD,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,qDAAiB,CAAA;IACjB,yEAA2B,CAAA;IAC3B,2DAAoB,CAAA;AACtB,CAAC,EAJW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAIxB;AAED,IAAY,mBAwBX;AAxBD,WAAY,mBAAmB;IAC7B,2FAAuB,CAAA;IACvB,iEAAM,CAAA;IACN,iIAAsC,CAAA;IACtC,mIAAuC,CAAA;IACvC,mHAA+B,CAAA;IAC/B,6HAAoC,CAAA;IACpC,yGAA0B,CAAA;IAC1B,6GAA4B,CAAA;IAC5B,+GAA6B,CAAA;IAC7B,4GAA2B,CAAA;IAC3B,wIAAyC,CAAA;IACzC,wIAAyC,CAAA;IACzC,kFAAc,CAAA;IACd,gGAAqB,CAAA;IACrB,oGAAuB,CAAA;IACvB,sGAAwB,CAAA;IACxB,gGAAqB,CAAA;IACrB,gHAA6B,CAAA;IAC7B,kF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G,KAAK,EAAE,KAAkB,EAAsB,EAAE;QACtE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,QAAQ,GAAG,CAAC,KAAwB,EAAE,OAAkB,EAAE,EAAE;gBAChE,IAAI,KAAK,EAAE;oBACT,MAAM,CAAC,KAAK,CAAC,CAAA;iBACd;gBACD,OAAO,CAAC,OAAO,CAAC,CAAA;YAClB,CAAC,CAAA;YAED,IAAI;gBACF,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,cAAc,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAA;aACpE;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,eAAe;QACf,cAAc;QACd,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;AA9ID,oCA8IC","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 unit: number // u16, unit of value\n code: number // u16, A chart of accounts code describing the type of account (e.g. clearing, settlement)\n flags: number // u32\n debits_reserved: bigint // u64\n debits_accepted: bigint // u64\n credits_reserved: bigint // u64\n credits_accepted: 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 linked_event_failed = 1,\n exists,\n exists_with_different_user_data,\n exists_with_different_reserved_field,\n exists_with_different_unit,\n exists_with_different_code,\n exists_with_different_flags,\n exceeds_credits,\n exceeds_debits,\n reserved_field,\n reserved_flag_padding,\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: Buffer, // [32]u8\n timeout: bigint, // u64, in nano-seconds\n code: number, // u32 accounting system code to describe the type of transfer (e.g. settlement)\n flags: number, // u32\n amount: bigint, // u64,\n timestamp: bigint, // u64, Set this to 0n - the actual value will be set by TigerBeetle server\n}\n\nexport enum TransferFlags {\n linked = (1 << 0),\n two_phase_commit = (1 << 1),\n condition = (1 << 2) // whether or not a condition will be supplied\n}\n\nexport enum CreateTransferError {\n linked_event_failed = 1,\n exists,\n exists_with_different_debit_account_id,\n exists_with_different_credit_account_id,\n exists_with_different_user_data,\n exists_with_different_reserved_field,\n exists_with_different_code,\n exists_with_different_amount,\n exists_with_different_timeout,\n exists_with_different_flags,\n exists_and_already_committed_and_accepted,\n exists_and_already_committed_and_rejected,\n reserved_field,\n reserved_flag_padding,\n debit_account_not_found,\n credit_account_not_found,\n accounts_are_the_same,\n accounts_have_different_units,\n amount_is_zero,\n exceeds_credits,\n exceeds_debits,\n two_phase_commit_must_timeout,\n timeout_reserved_for_two_phase_commit,\n}\n\nexport type CreateTransfersError = {\n index: number,\n code: CreateTransferError,\n}\n\nexport type Commit = {\n id: bigint, // u128\n reserved: Buffer, // [32]u8\n code: number, // u32 accounting system code describing the reason for accept/reject\n flags: number, // u32\n timestamp: bigint, // u64, Set this to 0n - the actual value will be set by TigerBeetle server\n}\n\nexport enum CommitFlags {\n linked = (1 << 0),\n reject = (1 << 1),\n preimage = (1 << 2) // whether or not a pre-image will be supplied\n}\n\nexport enum CommitTransferError {\n linked_event_failed = 1,\n reserved_field,\n reserved_flag_padding,\n transfer_not_found,\n transfer_not_two_phase_commit,\n transfer_expired,\n already_auto_committed,\n already_committed,\n already_committed_but_accepted,\n already_committed_but_rejected,\n debit_account_not_found,\n credit_account_not_found,\n debit_amount_was_not_reserved,\n credit_amount_was_not_reserved,\n exceeds_credits,\n exceeds_debits,\n condition_requires_preimage,\n preimage_requires_condition,\n preimage_invalid,\n}\n\nexport type CommitTransfersError = {\n index: number,\n code: CommitTransferError,\n}\n\nexport type AccountID = bigint // u128\n\nexport type Event = Account | Transfer | Commit | AccountID\nexport type Result = CreateAccountsError | CreateTransfersError | CommitTransfersError | Account\nexport type ResultCallback = (error: undefined | Error, results: Result[]) => void\n\nexport enum Operation {\n CREATE_ACCOUNT = 3,\n CREATE_TRANSFER,\n COMMIT_TRANSFER,\n ACCOUNT_LOOKUP\n}\n\nexport interface Client {\n createAccounts: (batch: Account[]) => Promise<CreateAccountsError[]>\n createTransfers: (batch: Transfer[]) => Promise<CreateTransfersError[]>\n commitTransfers: (batch: Commit[]) => Promise<CommitTransfersError[]>\n lookupAccounts: (batch: AccountID[]) => Promise<Account[]>\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 &&\n 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 }\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 }\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 commitTransfers = async (batch: Commit[]): Promise<CommitTransfersError[]> => {\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: CommitTransfersError[]) => {\n if (error) {\n reject(error)\n }\n resolve(results)\n }\n\n try {\n binding.request(context, Operation.COMMIT_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 }\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 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 commitTransfers,\n lookupAccounts,\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,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AC,OAAO,CAAC,CAAA;IACvB,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAEnB,OAAO,OAAO,CAAA;AAChB,CAAC;AArKD,oCAqKC","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 unit: number // u16, unit of value\n code: number // u16, A chart of accounts code describing the type of account (e.g. clearing, settlement)\n flags: number // u32\n debits_reserved: bigint // u64\n debits_accepted: bigint // u64\n credits_reserved: bigint // u64\n credits_accepted: 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 linked_event_failed = 1,\n exists,\n exists_with_different_user_data,\n exists_with_different_reserved_field,\n exists_with_different_unit,\n exists_with_different_code,\n exists_with_different_flags,\n exceeds_credits,\n exceeds_debits,\n reserved_field,\n reserved_flag_padding,\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: Buffer, // [32]u8\n timeout: bigint, // u64, in nano-seconds\n code: number, // u32 accounting system code to describe the type of transfer (e.g. settlement)\n flags: number, // u32\n amount: bigint, // u64,\n timestamp: bigint, // u64, Set this to 0n - the actual value will be set by TigerBeetle server\n}\n\nexport enum TransferFlags {\n linked = (1 << 0),\n two_phase_commit = (1 << 1),\n condition = (1 << 2) // whether or not a condition will be supplied\n}\n\nexport enum CreateTransferError {\n linked_event_failed = 1,\n exists,\n exists_with_different_debit_account_id,\n exists_with_different_credit_account_id,\n exists_with_different_user_data,\n exists_with_different_reserved_field,\n exists_with_different_code,\n exists_with_different_amount,\n exists_with_different_timeout,\n exists_with_different_flags,\n exists_and_already_committed_and_accepted,\n exists_and_already_committed_and_rejected,\n reserved_field,\n reserved_flag_padding,\n debit_account_not_found,\n credit_account_not_found,\n accounts_are_the_same,\n accounts_have_different_units,\n amount_is_zero,\n exceeds_credits,\n exceeds_debits,\n two_phase_commit_must_timeout,\n timeout_reserved_for_two_phase_commit,\n}\n\nexport type CreateTransfersError = {\n index: number,\n code: CreateTransferError,\n}\n\nexport type Commit = {\n id: bigint, // u128\n reserved: Buffer, // [32]u8\n code: number, // u32 accounting system code describing the reason for accept/reject\n flags: number, // u32\n timestamp: bigint, // u64, Set this to 0n - the actual value will be set by TigerBeetle server\n}\n\nexport enum CommitFlags {\n linked = (1 << 0),\n reject = (1 << 1),\n preimage = (1 << 2) // whether or not a pre-image will be supplied\n}\n\nexport enum CommitTransferError {\n linked_event_failed = 1,\n reserved_field,\n reserved_flag_padding,\n transfer_not_found,\n transfer_not_two_phase_commit,\n transfer_expired,\n already_committed,\n already_committed_but_accepted,\n already_committed_but_rejected,\n debit_account_not_found,\n credit_account_not_found,\n debit_amount_was_not_reserved,\n credit_amount_was_not_reserved,\n exceeds_credits,\n exceeds_debits,\n condition_requires_preimage,\n preimage_requires_condition,\n preimage_invalid,\n}\n\nexport type CommitTransfersError = {\n index: number,\n code: CommitTransferError,\n}\n\nexport type AccountID = bigint // u128\nexport type TransferID = bigint // u128\n\nexport type Event = Account | Transfer | Commit | AccountID | TransferID\nexport type Result = CreateAccountsError | CreateTransfersError | CommitTransfersError | Account | Transfer\nexport type ResultCallback = (error: undefined | Error, results: Result[]) => void\n\nexport enum Operation {\n CREATE_ACCOUNT = 3,\n CREATE_TRANSFER,\n COMMIT_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 commitTransfers: (batch: Commit[]) => Promise<CommitTransfersError[]>\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 &&\n 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 commitTransfers = async (batch: Commit[]): Promise<CommitTransfersError[]> => {\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: CommitTransfersError[]) => {\n if (error) {\n reject(error)\n return\n }\n resolve(results)\n }\n\n try {\n binding.request(context, Operation.COMMIT_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 commitTransfers,\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/dist/test.js CHANGED
@@ -149,6 +149,18 @@ test('can create a two-phase transfer', async () => {
149
149
  assert_1.default.strictEqual(accounts[1].credits_reserved, 0n);
150
150
  assert_1.default.strictEqual(accounts[1].debits_accepted, 100n);
151
151
  assert_1.default.strictEqual(accounts[1].debits_reserved, 50n);
152
+ const transfers = await client.lookupTransfers([transfer.id]);
153
+ assert_1.default.strictEqual(transfers.length, 1);
154
+ assert_1.default.strictEqual(transfers[0].id, 1n);
155
+ assert_1.default.strictEqual(transfers[0].debit_account_id, accountB.id);
156
+ assert_1.default.strictEqual(transfers[0].credit_account_id, accountA.id);
157
+ assert_1.default.strictEqual(transfers[0].user_data, 0n);
158
+ assert_1.default.notStrictEqual(transfers[0].reserved, Zeroed32Bytes);
159
+ assert_1.default.strictEqual(transfers[0].timeout > 0, true);
160
+ assert_1.default.strictEqual(transfers[0].code, 1);
161
+ assert_1.default.strictEqual(transfers[0].flags, 2);
162
+ assert_1.default.strictEqual(transfers[0].amount, 50n);
163
+ assert_1.default.strictEqual(transfers[0].timestamp > 0, true);
152
164
  });
153
165
  test('can commit a two-phase transfer', async () => {
154
166
  const commit = {
package/dist/test.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3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AI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAA;IAClC,IAAI;QACF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACnC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;gBAC9B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,UAAU,CAAC,CAAA;YACzC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;gBACf,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,UAAU,CAAC,CAAA;gBACvC,MAAM,KAAK,CAAA;YACb,CAAC,CAAC,CAAA;SACH;QACD,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAA;QAChC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC,GAAG,GAAG,KAAK,CAAC,GAAC,IAAI,CAAC,CAAA;KACnD;YAAS;QACR,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;KACvB;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAqB,EAAE,EAAE;IACrC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAA;IACxC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;AACpC,CAAC,CAAC,CAAA","sourcesContent":["import assert, { AssertionError } from 'assert'\nimport { CommitFlags,\n createClient,\n Commit,\n Account,\n Transfer,\n TransferFlags,\n CreateAccountError,\n CreateTransferError\n} from '.'\n\nconst client = createClient({\n cluster_id: 0,\n replica_addresses: ['3001']\n})\n\n// Test data\nconst Zeroed32Bytes = Buffer.alloc(32, 0)\nconst Zeroed48Bytes = Buffer.alloc(48, 0)\nconst accountA: Account = {\n id: 17n,\n reserved: Zeroed48Bytes,\n user_data: 0n,\n code: 718,\n unit: 1,\n flags: 0,\n credits_accepted: 0n,\n credits_reserved: 0n,\n debits_accepted: 0n,\n debits_reserved: 0n,\n timestamp: 0n // this will be set correctly by the TigerBeetle server\n}\nconst accountB: Account = {\n id: 19n,\n reserved: Zeroed48Bytes,\n user_data: 0n,\n code: 719,\n unit: 1,\n flags: 0,\n credits_accepted: 0n,\n credits_reserved: 0n,\n debits_accepted: 0n,\n debits_reserved: 0n,\n timestamp: 0n // this will be set correctly by the TigerBeetle server\n}\n\nconst tests: Array<{ name: string, fn: () => Promise<void> }> = []\nfunction test(name: string, fn: () => Promise<void>) {\n tests.push({ name, fn })\n}\ntest.skip = (name: string, fn: () => Promise<void>) => {\n console.log(name + ': SKIPPED')\n}\n\ntest('range checks `unit` and `code` on Account to be u16', async (): Promise<void> => {\n const account = { ...accountA, id: 0n, unit: 65535 + 1 }\n\n const unitError = await client.createAccounts([account]).catch(error => error)\n assert.strictEqual(unitError.message, 'unit must be a u16.')\n\n account.unit = 0\n account.code = 65535 + 1\n const codeError = await client.createAccounts([account]).catch(error => error)\n assert.strictEqual(codeError.message, 'code must be a u16.')\n\n const accounts = await client.lookupAccounts([0n])\n assert.strictEqual(accounts.length, 0)\n})\n\ntest('can create accounts', async (): Promise<void> => {\n const errors = await client.createAccounts([accountA])\n\n assert.strictEqual(errors.length, 0)\n})\n\ntest('can return error', async (): Promise<void> => {\n const errors = await client.createAccounts([accountA, accountB])\n\n assert.strictEqual(errors.length, 1)\n assert.deepStrictEqual(errors[0], { index: 0, code: CreateAccountError.exists })\n})\n\ntest('throws error if timestamp is not set to 0n', async (): Promise<void> => {\n const account = { ...accountA, timestamp: 2n, id: 3n }\n await assert.rejects(client.createAccounts([account]))\n})\n\ntest('can lookup accounts', async (): Promise<void> => {\n const accounts = await client.lookupAccounts([accountA.id, accountB.id])\n\n assert.strictEqual(accounts.length, 2)\n const account1 = accounts[0]\n assert.strictEqual(account1.id, 17n)\n assert.ok(account1.reserved.equals(Zeroed48Bytes))\n assert.strictEqual(account1.user_data, 0n)\n assert.strictEqual(account1.code, 718)\n assert.strictEqual(account1.unit, 1)\n assert.strictEqual(account1.flags, 0)\n assert.strictEqual(account1.credits_accepted, 0n)\n assert.strictEqual(account1.credits_reserved, 0n)\n assert.strictEqual(account1.debits_accepted, 0n)\n assert.strictEqual(account1.debits_reserved, 0n)\n assert.ok(account1.timestamp > 0n)\n\n const account2 = accounts[1]\n assert.strictEqual(account2.id, 19n)\n assert.ok(account2.reserved.equals(Zeroed48Bytes))\n assert.strictEqual(account2.user_data, 0n)\n assert.strictEqual(account2.code, 719)\n assert.strictEqual(account2.unit, 1)\n assert.strictEqual(account2.flags, 0)\n assert.strictEqual(account2.credits_accepted, 0n)\n assert.strictEqual(account2.credits_reserved, 0n)\n assert.strictEqual(account2.debits_accepted, 0n)\n assert.strictEqual(account2.debits_reserved, 0n)\n assert.ok(account2.timestamp > 0n)\n})\n\ntest('can create a transfer', async (): Promise<void> => {\n const transfer: Transfer = {\n id: 0n,\n amount: 100n,\n code: 1,\n credit_account_id: accountA.id,\n debit_account_id: accountB.id,\n flags: 0,\n user_data: 0n,\n reserved: Zeroed32Bytes,\n timeout: 0n,\n timestamp: 0n, // this will be set correctly by the TigerBeetle server\n }\n\n const errors = await client.createTransfers([transfer])\n assert.strictEqual(errors.length, 0)\n\n const accounts = await client.lookupAccounts([accountA.id, accountB.id])\n assert.strictEqual(accounts.length, 2)\n assert.strictEqual(accounts[0].credits_accepted, 100n)\n assert.strictEqual(accounts[0].credits_reserved, 0n)\n assert.strictEqual(accounts[0].debits_accepted, 0n)\n assert.strictEqual(accounts[0].debits_reserved, 0n)\n\n assert.strictEqual(accounts[1].credits_accepted, 0n)\n assert.strictEqual(accounts[1].credits_reserved, 0n)\n assert.strictEqual(accounts[1].debits_accepted, 100n)\n assert.strictEqual(accounts[1].debits_reserved, 0n)\n})\n\ntest('can create a two-phase transfer', async (): Promise<void> => {\n let flags = 0\n flags |= TransferFlags.two_phase_commit\n const transfer: Transfer = {\n id: 1n,\n amount: 50n,\n code: 1,\n credit_account_id: accountA.id,\n debit_account_id: accountB.id,\n flags,\n user_data: 0n,\n reserved: Zeroed32Bytes,\n timeout: BigInt(2e9),\n timestamp: 0n, // this will be set correctly by the TigerBeetle server\n }\n\n const errors = await client.createTransfers([transfer])\n assert.strictEqual(errors.length, 0)\n\n const accounts = await client.lookupAccounts([accountA.id, accountB.id])\n assert.strictEqual(accounts.length, 2)\n assert.strictEqual(accounts[0].credits_accepted, 100n)\n assert.strictEqual(accounts[0].credits_reserved, 50n)\n assert.strictEqual(accounts[0].debits_accepted, 0n)\n assert.strictEqual(accounts[0].debits_reserved, 0n)\n\n assert.strictEqual(accounts[1].credits_accepted, 0n)\n assert.strictEqual(accounts[1].credits_reserved, 0n)\n assert.strictEqual(accounts[1].debits_accepted, 100n)\n assert.strictEqual(accounts[1].debits_reserved, 50n)\n})\n\ntest('can commit a two-phase transfer', async (): Promise<void> => {\n const commit: Commit = {\n id: 1n, // must match the id of the create transfer\n code: 1,\n flags: 0, // defaults to accept\n reserved: Zeroed32Bytes,\n timestamp: 0n, // this will be set correctly by the TigerBeetle server\n }\n\n const errors = await client.commitTransfers([commit])\n assert.strictEqual(errors.length, 0)\n\n const accounts = await client.lookupAccounts([accountA.id, accountB.id])\n assert.strictEqual(accounts.length, 2)\n assert.strictEqual(accounts[0].credits_accepted, 150n)\n assert.strictEqual(accounts[0].credits_reserved, 0n)\n assert.strictEqual(accounts[0].debits_accepted, 0n)\n assert.strictEqual(accounts[0].debits_reserved, 0n)\n\n assert.strictEqual(accounts[1].credits_accepted, 0n)\n assert.strictEqual(accounts[1].credits_reserved, 0n)\n assert.strictEqual(accounts[1].debits_accepted, 150n)\n assert.strictEqual(accounts[1].debits_reserved, 0n)\n})\n\ntest('can reject a two-phase transfer', async (): Promise<void> => {\n // create a two-phase transfer\n const transfer: Transfer = {\n id: 3n,\n amount: 50n,\n code: 1,\n credit_account_id: accountA.id,\n debit_account_id: accountB.id,\n flags: TransferFlags.two_phase_commit,\n user_data: 0n,\n reserved: Zeroed32Bytes,\n timeout: BigInt(1e9),\n timestamp: 0n, // this will be set correctly by the TigerBeetle server\n }\n const transferErrors = await client.createTransfers([transfer])\n assert.strictEqual(transferErrors.length, 0)\n\n // send in the reject\n const reject: Commit = {\n id: 3n,\n code: 1,\n flags: CommitFlags.reject,\n reserved: Zeroed32Bytes,\n timestamp: 0n,// this will be set correctly by the TigerBeetle server\n }\n\n const errors = await client.commitTransfers([reject])\n assert.strictEqual(errors.length, 0)\n\n const accounts = await client.lookupAccounts([accountA.id, accountB.id])\n assert.strictEqual(accounts.length, 2)\n assert.strictEqual(accounts[0].credits_accepted, 150n)\n assert.strictEqual(accounts[0].credits_reserved, 0n)\n assert.strictEqual(accounts[0].debits_accepted, 0n)\n assert.strictEqual(accounts[0].debits_reserved, 0n)\n\n assert.strictEqual(accounts[1].credits_accepted, 0n)\n assert.strictEqual(accounts[1].credits_reserved, 0n)\n assert.strictEqual(accounts[1].debits_accepted, 150n)\n assert.strictEqual(accounts[1].debits_reserved, 0n)\n})\n\ntest('can link transfers', async (): Promise<void> => {\n const transfer1: Transfer = {\n id: 4n,\n amount: 100n,\n code: 1,\n credit_account_id: accountA.id,\n debit_account_id: accountB.id,\n flags: TransferFlags.linked, // points to transfer2\n user_data: 0n,\n reserved: Zeroed32Bytes,\n timeout: 0n,\n timestamp: 0n, // will be set correctly by the TigerBeetle server\n }\n const transfer2: Transfer = {\n id: 4n,\n amount: 100n,\n code: 1,\n credit_account_id: accountA.id,\n debit_account_id: accountB.id,\n // Does not have linked flag as it is the end of the chain.\n // This will also cause it to fail as this is now a duplicate with different flags\n flags: 0,\n user_data: 0n,\n reserved: Zeroed32Bytes,\n timeout: 0n,\n timestamp: 0n, // will be set correctly by the TigerBeetle server\n }\n\n const errors = await client.createTransfers([transfer1, transfer2])\n assert.strictEqual(errors.length, 2)\n assert.deepStrictEqual(errors[0], { index: 0, code: CreateTransferError.linked_event_failed })\n assert.deepStrictEqual(errors[1], { index: 1, code: CreateTransferError.exists_with_different_flags })\n\n const accounts = await client.lookupAccounts([accountA.id, accountB.id])\n assert.strictEqual(accounts.length, 2)\n assert.strictEqual(accounts[0].credits_accepted, 150n)\n assert.strictEqual(accounts[0].credits_reserved, 0n)\n assert.strictEqual(accounts[0].debits_accepted, 0n)\n assert.strictEqual(accounts[0].debits_reserved, 0n)\n\n assert.strictEqual(accounts[1].credits_accepted, 0n)\n assert.strictEqual(accounts[1].credits_reserved, 0n)\n assert.strictEqual(accounts[1].debits_accepted, 150n)\n assert.strictEqual(accounts[1].debits_reserved, 0n)\n})\n\nasync function main () {\n const start = new Date().getTime()\n try {\n for (let i = 0; i < tests.length; i++) {\n await tests[i].fn().then(() => {\n console.log(tests[i].name + \": PASSED\")\n }).catch(error => {\n console.log(tests[i].name + \": FAILED\")\n throw error\n })\n }\n const end = new Date().getTime()\n console.log('Time taken (s):', (end - start)/1000)\n } finally {\n await client.destroy()\n } \n}\n\nmain().catch((error: AssertionError) => {\n console.log('operator:', error.operator)\n console.log('stack:', error.stack)\n})\n"]}
1
+ {"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":";;;;;AAAA,oDAA+C;AAC/C,wBAQU;AAEV,MAAM,MAAM,GAAG,eAAY,CAAC;IAC1B,UAAU,EAAE,CAAC;IACb,iBAAiB,EAAE,CAAC,MAAM,CAAC;CAC5B,CAAC,CAAA;AAGF,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AACzC,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AACzC,MAAM,QAAQ,GAAY;IACxB,EAAE,EAAE,GAAG;IACP,QAAQ,EAAE,aAAa;IACvB,SAAS,EAAE,EAAE;IACb,IAAI,EAAE,GAAG;IACT,IAAI,EAA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AAE,CAAA;QAChC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC,GAAG,GAAG,KAAK,CAAC,GAAC,IAAI,CAAC,CAAA;KACnD;YAAS;QACR,MAAM,MAAM,CAAC,OAAO,EAAE,CAAA;KACvB;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAqB,EAAE,EAAE;IACrC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAA;IACxC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;AACpC,CAAC,CAAC,CAAA","sourcesContent":["import assert, { AssertionError } from 'assert'\nimport { CommitFlags,\n createClient,\n Commit,\n Account,\n Transfer,\n TransferFlags,\n CreateAccountError,\n CreateTransferError\n} from '.'\n\nconst client = createClient({\n cluster_id: 0,\n replica_addresses: ['3001']\n})\n\n// Test data\nconst Zeroed32Bytes = Buffer.alloc(32, 0)\nconst Zeroed48Bytes = Buffer.alloc(48, 0)\nconst accountA: Account = {\n id: 17n,\n reserved: Zeroed48Bytes,\n user_data: 0n,\n code: 718,\n unit: 1,\n flags: 0,\n credits_accepted: 0n,\n credits_reserved: 0n,\n debits_accepted: 0n,\n debits_reserved: 0n,\n timestamp: 0n // this will be set correctly by the TigerBeetle server\n}\nconst accountB: Account = {\n id: 19n,\n reserved: Zeroed48Bytes,\n user_data: 0n,\n code: 719,\n unit: 1,\n flags: 0,\n credits_accepted: 0n,\n credits_reserved: 0n,\n debits_accepted: 0n,\n debits_reserved: 0n,\n timestamp: 0n // this will be set correctly by the TigerBeetle server\n}\n\nconst tests: Array<{ name: string, fn: () => Promise<void> }> = []\nfunction test(name: string, fn: () => Promise<void>) {\n tests.push({ name, fn })\n}\ntest.skip = (name: string, fn: () => Promise<void>) => {\n console.log(name + ': SKIPPED')\n}\n\ntest('range checks `unit` and `code` on Account to be u16', async (): Promise<void> => {\n const account = { ...accountA, id: 0n, unit: 65535 + 1 }\n\n const unitError = await client.createAccounts([account]).catch(error => error)\n assert.strictEqual(unitError.message, 'unit must be a u16.')\n\n account.unit = 0\n account.code = 65535 + 1\n const codeError = await client.createAccounts([account]).catch(error => error)\n assert.strictEqual(codeError.message, 'code must be a u16.')\n\n const accounts = await client.lookupAccounts([0n])\n assert.strictEqual(accounts.length, 0)\n})\n\ntest('can create accounts', async (): Promise<void> => {\n const errors = await client.createAccounts([accountA])\n\n assert.strictEqual(errors.length, 0)\n})\n\ntest('can return error', async (): Promise<void> => {\n const errors = await client.createAccounts([accountA, accountB])\n\n assert.strictEqual(errors.length, 1)\n assert.deepStrictEqual(errors[0], { index: 0, code: CreateAccountError.exists })\n})\n\ntest('throws error if timestamp is not set to 0n', async (): Promise<void> => {\n const account = { ...accountA, timestamp: 2n, id: 3n }\n await assert.rejects(client.createAccounts([account]))\n})\n\ntest('can lookup accounts', async (): Promise<void> => {\n const accounts = await client.lookupAccounts([accountA.id, accountB.id])\n\n assert.strictEqual(accounts.length, 2)\n const account1 = accounts[0]\n assert.strictEqual(account1.id, 17n)\n assert.ok(account1.reserved.equals(Zeroed48Bytes))\n assert.strictEqual(account1.user_data, 0n)\n assert.strictEqual(account1.code, 718)\n assert.strictEqual(account1.unit, 1)\n assert.strictEqual(account1.flags, 0)\n assert.strictEqual(account1.credits_accepted, 0n)\n assert.strictEqual(account1.credits_reserved, 0n)\n assert.strictEqual(account1.debits_accepted, 0n)\n assert.strictEqual(account1.debits_reserved, 0n)\n assert.ok(account1.timestamp > 0n)\n\n const account2 = accounts[1]\n assert.strictEqual(account2.id, 19n)\n assert.ok(account2.reserved.equals(Zeroed48Bytes))\n assert.strictEqual(account2.user_data, 0n)\n assert.strictEqual(account2.code, 719)\n assert.strictEqual(account2.unit, 1)\n assert.strictEqual(account2.flags, 0)\n assert.strictEqual(account2.credits_accepted, 0n)\n assert.strictEqual(account2.credits_reserved, 0n)\n assert.strictEqual(account2.debits_accepted, 0n)\n assert.strictEqual(account2.debits_reserved, 0n)\n assert.ok(account2.timestamp > 0n)\n})\n\ntest('can create a transfer', async (): Promise<void> => {\n const transfer: Transfer = {\n id: 0n,\n amount: 100n,\n code: 1,\n credit_account_id: accountA.id,\n debit_account_id: accountB.id,\n flags: 0,\n user_data: 0n,\n reserved: Zeroed32Bytes,\n timeout: 0n,\n timestamp: 0n, // this will be set correctly by the TigerBeetle server\n }\n\n const errors = await client.createTransfers([transfer])\n assert.strictEqual(errors.length, 0)\n\n const accounts = await client.lookupAccounts([accountA.id, accountB.id])\n assert.strictEqual(accounts.length, 2)\n assert.strictEqual(accounts[0].credits_accepted, 100n)\n assert.strictEqual(accounts[0].credits_reserved, 0n)\n assert.strictEqual(accounts[0].debits_accepted, 0n)\n assert.strictEqual(accounts[0].debits_reserved, 0n)\n\n assert.strictEqual(accounts[1].credits_accepted, 0n)\n assert.strictEqual(accounts[1].credits_reserved, 0n)\n assert.strictEqual(accounts[1].debits_accepted, 100n)\n assert.strictEqual(accounts[1].debits_reserved, 0n)\n})\n\ntest('can create a two-phase transfer', async (): Promise<void> => {\n let flags = 0\n flags |= TransferFlags.two_phase_commit\n const transfer: Transfer = {\n id: 1n,\n amount: 50n,\n code: 1,\n credit_account_id: accountA.id,\n debit_account_id: accountB.id,\n flags,\n user_data: 0n,\n reserved: Zeroed32Bytes,\n timeout: BigInt(2e9),\n timestamp: 0n, // this will be set correctly by the TigerBeetle server\n }\n\n const errors = await client.createTransfers([transfer])\n assert.strictEqual(errors.length, 0)\n\n const accounts = await client.lookupAccounts([accountA.id, accountB.id])\n assert.strictEqual(accounts.length, 2)\n assert.strictEqual(accounts[0].credits_accepted, 100n)\n assert.strictEqual(accounts[0].credits_reserved, 50n)\n assert.strictEqual(accounts[0].debits_accepted, 0n)\n assert.strictEqual(accounts[0].debits_reserved, 0n)\n\n assert.strictEqual(accounts[1].credits_accepted, 0n)\n assert.strictEqual(accounts[1].credits_reserved, 0n)\n assert.strictEqual(accounts[1].debits_accepted, 100n)\n assert.strictEqual(accounts[1].debits_reserved, 50n)\n\n // Lookup the transfer\n const transfers = await client.lookupTransfers([transfer.id])\n assert.strictEqual(transfers.length, 1)\n assert.strictEqual(transfers[0].id, 1n)\n assert.strictEqual(transfers[0].debit_account_id, accountB.id)\n assert.strictEqual(transfers[0].credit_account_id, accountA.id)\n assert.strictEqual(transfers[0].user_data, 0n)\n assert.notStrictEqual(transfers[0].reserved, Zeroed32Bytes)\n assert.strictEqual(transfers[0].timeout > 0, true)\n assert.strictEqual(transfers[0].code, 1)\n assert.strictEqual(transfers[0].flags, 2)\n assert.strictEqual(transfers[0].amount, 50n)\n assert.strictEqual(transfers[0].timestamp > 0, true)\n})\n\ntest('can commit a two-phase transfer', async (): Promise<void> => {\n const commit: Commit = {\n id: 1n, // must match the id of the create transfer\n code: 1,\n flags: 0, // defaults to accept\n reserved: Zeroed32Bytes,\n timestamp: 0n, // this will be set correctly by the TigerBeetle server\n }\n\n const errors = await client.commitTransfers([commit])\n assert.strictEqual(errors.length, 0)\n\n const accounts = await client.lookupAccounts([accountA.id, accountB.id])\n assert.strictEqual(accounts.length, 2)\n assert.strictEqual(accounts[0].credits_accepted, 150n)\n assert.strictEqual(accounts[0].credits_reserved, 0n)\n assert.strictEqual(accounts[0].debits_accepted, 0n)\n assert.strictEqual(accounts[0].debits_reserved, 0n)\n\n assert.strictEqual(accounts[1].credits_accepted, 0n)\n assert.strictEqual(accounts[1].credits_reserved, 0n)\n assert.strictEqual(accounts[1].debits_accepted, 150n)\n assert.strictEqual(accounts[1].debits_reserved, 0n)\n})\n\ntest('can reject a two-phase transfer', async (): Promise<void> => {\n // create a two-phase transfer\n const transfer: Transfer = {\n id: 3n,\n amount: 50n,\n code: 1,\n credit_account_id: accountA.id,\n debit_account_id: accountB.id,\n flags: TransferFlags.two_phase_commit,\n user_data: 0n,\n reserved: Zeroed32Bytes,\n timeout: BigInt(1e9),\n timestamp: 0n, // this will be set correctly by the TigerBeetle server\n }\n const transferErrors = await client.createTransfers([transfer])\n assert.strictEqual(transferErrors.length, 0)\n\n // send in the reject\n const reject: Commit = {\n id: 3n,\n code: 1,\n flags: CommitFlags.reject,\n reserved: Zeroed32Bytes,\n timestamp: 0n,// this will be set correctly by the TigerBeetle server\n }\n\n const errors = await client.commitTransfers([reject])\n assert.strictEqual(errors.length, 0)\n\n const accounts = await client.lookupAccounts([accountA.id, accountB.id])\n assert.strictEqual(accounts.length, 2)\n assert.strictEqual(accounts[0].credits_accepted, 150n)\n assert.strictEqual(accounts[0].credits_reserved, 0n)\n assert.strictEqual(accounts[0].debits_accepted, 0n)\n assert.strictEqual(accounts[0].debits_reserved, 0n)\n\n assert.strictEqual(accounts[1].credits_accepted, 0n)\n assert.strictEqual(accounts[1].credits_reserved, 0n)\n assert.strictEqual(accounts[1].debits_accepted, 150n)\n assert.strictEqual(accounts[1].debits_reserved, 0n)\n})\n\ntest('can link transfers', async (): Promise<void> => {\n const transfer1: Transfer = {\n id: 4n,\n amount: 100n,\n code: 1,\n credit_account_id: accountA.id,\n debit_account_id: accountB.id,\n flags: TransferFlags.linked, // points to transfer2\n user_data: 0n,\n reserved: Zeroed32Bytes,\n timeout: 0n,\n timestamp: 0n, // will be set correctly by the TigerBeetle server\n }\n const transfer2: Transfer = {\n id: 4n,\n amount: 100n,\n code: 1,\n credit_account_id: accountA.id,\n debit_account_id: accountB.id,\n // Does not have linked flag as it is the end of the chain.\n // This will also cause it to fail as this is now a duplicate with different flags\n flags: 0,\n user_data: 0n,\n reserved: Zeroed32Bytes,\n timeout: 0n,\n timestamp: 0n, // will be set correctly by the TigerBeetle server\n }\n\n const errors = await client.createTransfers([transfer1, transfer2])\n assert.strictEqual(errors.length, 2)\n assert.deepStrictEqual(errors[0], { index: 0, code: CreateTransferError.linked_event_failed })\n assert.deepStrictEqual(errors[1], { index: 1, code: CreateTransferError.exists_with_different_flags })\n\n const accounts = await client.lookupAccounts([accountA.id, accountB.id])\n assert.strictEqual(accounts.length, 2)\n assert.strictEqual(accounts[0].credits_accepted, 150n)\n assert.strictEqual(accounts[0].credits_reserved, 0n)\n assert.strictEqual(accounts[0].debits_accepted, 0n)\n assert.strictEqual(accounts[0].debits_reserved, 0n)\n\n assert.strictEqual(accounts[1].credits_accepted, 0n)\n assert.strictEqual(accounts[1].credits_reserved, 0n)\n assert.strictEqual(accounts[1].debits_accepted, 150n)\n assert.strictEqual(accounts[1].debits_reserved, 0n)\n})\n\nasync function main () {\n const start = new Date().getTime()\n try {\n for (let i = 0; i < tests.length; i++) {\n await tests[i].fn().then(() => {\n console.log(tests[i].name + \": PASSED\")\n }).catch(error => {\n console.log(tests[i].name + \": FAILED\")\n throw error\n })\n }\n const end = new Date().getTime()\n console.log('Time taken (s):', (end - start)/1000)\n } finally {\n await client.destroy()\n } \n}\n\nmain().catch((error: AssertionError) => {\n console.log('operator:', error.operator)\n console.log('stack:', error.stack)\n})\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tigerbeetle-node",
3
- "version": "0.4.2",
3
+ "version": "0.5.2",
4
4
  "description": "TigerBeetle Node.js client",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -37,7 +37,7 @@
37
37
  "benchmark": "./scripts/benchmark.sh",
38
38
  "build": "yarn build:tsc && yarn build:zig",
39
39
  "build:tsc": "tsc",
40
- "build:zig": "mkdir -p dist && ZIG_SYSTEM_LINKER_HACK=1 zig/zig build-lib -mcpu=baseline -OReleaseSafe -dynamic -lc -isystem build/node-$(node --version)/include/node src/node.zig -fallow-shlib-undefined -femit-bin=dist/client.node",
40
+ "build:zig": "mkdir -p dist && zig/zig build-lib -mcpu=baseline -OReleaseSafe -dynamic -lc -isystem build/node-$(node --version)/include/node src/node.zig -fallow-shlib-undefined -femit-bin=dist/client.node",
41
41
  "clean": "rm -rf build dist node_modules src/zig-cache zig",
42
42
  "install:zig": "./src/tigerbeetle/scripts/install_zig.sh",
43
43
  "postinstall": "./scripts/postinstall.sh",
@@ -1,6 +1,6 @@
1
1
  #!/bin/bash
2
2
  set -e
3
3
 
4
- ./src/tigerbeetle/scripts/install_zig.sh 0.8.1
4
+ ./src/tigerbeetle/scripts/install_zig.sh
5
5
  ./scripts/download_node_headers.sh
6
- mkdir -p dist && ZIG_SYSTEM_LINKER_HACK=1 zig/zig build-lib -mcpu=baseline -OReleaseSafe -dynamic -lc -isystem build/node-$(node --version)/include/node src/node.zig -fallow-shlib-undefined -femit-bin=dist/client.node
6
+ mkdir -p dist && zig/zig build-lib -mcpu=baseline -OReleaseSafe -dynamic -lc -isystem build/node-$(node --version)/include/node src/node.zig -fallow-shlib-undefined -femit-bin=dist/client.node
package/src/benchmark.ts CHANGED
@@ -185,7 +185,7 @@ const runBenchmarkRawReqeust = async () => {
185
185
  let maxCommitTransfersLatency = 0
186
186
  const start = Date.now()
187
187
 
188
- for(let i = 0; i < transfers.length; i++) {
188
+ for (let i = 0; i < transfers.length; i++) {
189
189
  const ms1 = Date.now()
190
190
 
191
191
  const transferResults = await rawCreateTransfers(transfers[i])
@@ -265,7 +265,7 @@ const runBenchmark = async () => {
265
265
  let maxCommitTransfersLatency = 0
266
266
  const start = Date.now()
267
267
 
268
- for(let i = 0; i < transfers.length; i++) {
268
+ for (let i = 0; i < transfers.length; i++) {
269
269
  const ms1 = Date.now()
270
270
 
271
271
  const transferResults = await client.createTransfers(transfers[i])