tigerbeetle-node 0.13.118 → 0.13.119

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,7 +11,7 @@ The TigerBeetle client for Node.js.
11
11
  ### Prerequisites
12
12
 
13
13
  Linux >= 5.6 is the only production environment we
14
- support. But for ease of development we also support macOS. Windows is not yet supported.
14
+ support. But for ease of development we also support macOS and Windows.
15
15
  * NodeJS >= `14`
16
16
 
17
17
  ## Setup
@@ -615,4 +615,14 @@ npm pack
615
615
 
616
616
  ### On Windows
617
617
 
618
- Not yet supported.
618
+ In PowerShell run:
619
+
620
+ ```console
621
+ git clone https://github.com/tigerbeetle/tigerbeetle
622
+ cd tigerbeetle
623
+ git submodule update --init --recursive
624
+ .\scripts\install_zig.bat
625
+ cd src/clients/node
626
+ npm install --include dev
627
+ npm pack
628
+ ```
Binary file
Binary file
Binary file
package/dist/index.js CHANGED
@@ -21,7 +21,8 @@ function getBinding() {
21
21
  };
22
22
  const platformMap = {
23
23
  "linux": "linux",
24
- "darwin": "macos"
24
+ "darwin": "macos",
25
+ "win32": "windows",
25
26
  };
26
27
  if (!(arch in archMap)) {
27
28
  throw new Error(`Unsupported arch: ${arch}`);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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,IA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AAO,CAAC,OAAO,CAAC,CAAA;YAClB,CAAC,CAAA;YAED,IAAI;gBACF,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,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\n// Note: as of #990, the error is always `undefined` here.\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"]}
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;QACjB,OAAO,EAAG,SAAS;KACpB,CAAA;IAED,IAAI,CAAE,CAAC,IAAI,IAAI,OAAO,CAAC,EAAE;QACvB,MAAM,IAAI,K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CAAC,OAAO,CAAC,CAAA;YAClB,CAAC,CAAA;YAED,IAAI;gBACF,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,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 \"win32\" : \"windows\",\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\n// Note: as of #990, the error is always `undefined` here.\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/dist/test.js CHANGED
@@ -59,7 +59,7 @@ test('can create accounts', async () => {
59
59
  test('can return error on account', async () => {
60
60
  const errors = await client.createAccounts([accountA, accountB]);
61
61
  assert_1.default.strictEqual(errors.length, 1);
62
- assert_1.default.deepStrictEqual(errors[0], { index: 0, code: _1.CreateAccountError.exists });
62
+ assert_1.default.deepStrictEqual(errors[0], { index: 0, result: _1.CreateAccountError.exists });
63
63
  });
64
64
  test('throws error if timestamp is not set to 0n on account', async () => {
65
65
  const account = { ...accountA, timestamp: 2n, id: 3n };
@@ -268,8 +268,8 @@ test('can link transfers', async () => {
268
268
  };
269
269
  const errors = await client.createTransfers([transfer1, transfer2]);
270
270
  assert_1.default.strictEqual(errors.length, 2);
271
- assert_1.default.deepStrictEqual(errors[0], { index: 0, code: _1.CreateTransferError.linked_event_failed });
272
- assert_1.default.deepStrictEqual(errors[1], { index: 1, code: _1.CreateTransferError.exists_with_different_flags });
271
+ assert_1.default.deepStrictEqual(errors[0], { index: 0, result: _1.CreateTransferError.linked_event_failed });
272
+ assert_1.default.deepStrictEqual(errors[1], { index: 1, result: _1.CreateTransferError.exists_with_different_flags });
273
273
  const accounts = await client.lookupAccounts([accountA.id, accountB.id]);
274
274
  assert_1.default.strictEqual(accounts.length, 2);
275
275
  assert_1.default.strictEqual(accounts[0].credits_posted, 150n);
package/dist/test.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":";;;;;AAAA,oDAA+C;AAC/C,wBAOU;AAEV,MAAM,MAAM,GAAG,IAAA,eAAY,EAAC;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,SAAS,EAAE,EAAE;IACb,QAAQ,EAAE,aAAa;IACvB,MAAM,EAAE,CAAC;IACT,IAAI,EAAE,GAAG;IACT,KAAK,EAAE,CAAC;IACR,cAAc,EAAE,EAAE;IAClB,aAAa,EAAE,EAAE;IACjB,eAAe,EAAE,EAAE;IACnB,cAAc,EAAE,EAAE;IAClB,SAAS,EAAE,EAAE;CACd,CAAA;AACD,MAAM,QAAQ,GAAY;IACxB,EAAE,EAAE,GAAG;IACP,SAAS,EAAE,EAAE;IACb,QAAQ,EAAE,aAAa;IACvB,MAAM,EAAE,CAAC;IACT,IAAI,EAAE,GAAG;I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AAC,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 {\n createClient,\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 user_data: 0n,\n reserved: Zeroed48Bytes,\n ledger: 1,\n code: 718,\n flags: 0,\n debits_pending: 0n,\n debits_posted: 0n,\n credits_pending: 0n,\n credits_posted: 0n,\n timestamp: 0n // this will be set correctly by the TigerBeetle server\n}\nconst accountB: Account = {\n id: 19n,\n user_data: 0n,\n reserved: Zeroed48Bytes,\n ledger: 1,\n code: 719,\n flags: 0,\n debits_pending: 0n,\n debits_posted: 0n,\n credits_pending: 0n,\n credits_posted: 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 check `code` on Account to be u16', async (): Promise<void> => {\n const account = { ...accountA, id: 0n }\n\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([account.id])\n assert.strictEqual(accounts.length, 0)\n})\n\ntest('can create accounts', async (): Promise<void> => {\n const errors = await client.createAccounts([accountA])\n assert.strictEqual(errors.length, 0)\n})\n\ntest('can return error on account', 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 on account', 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.ledger, 1)\n assert.strictEqual(account1.flags, 0)\n assert.strictEqual(account1.credits_posted, 0n)\n assert.strictEqual(account1.credits_pending, 0n)\n assert.strictEqual(account1.debits_posted, 0n)\n assert.strictEqual(account1.debits_pending, 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.ledger, 1)\n assert.strictEqual(account2.flags, 0)\n assert.strictEqual(account2.credits_posted, 0n)\n assert.strictEqual(account2.credits_pending, 0n)\n assert.strictEqual(account2.debits_posted, 0n)\n assert.strictEqual(account2.debits_pending, 0n)\n assert.ok(account2.timestamp > 0n)\n})\n\ntest('can create a transfer', async (): Promise<void> => {\n const transfer: Transfer = {\n id: 1n,\n debit_account_id: accountB.id,\n credit_account_id: accountA.id,\n user_data: 0n,\n reserved: 0n,\n pending_id: 0n,\n timeout: 0n,\n ledger: 1,\n code: 1,\n flags: 0,\n amount: 100n,\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_posted, 100n)\n assert.strictEqual(accounts[0].credits_pending, 0n)\n assert.strictEqual(accounts[0].debits_posted, 0n)\n assert.strictEqual(accounts[0].debits_pending, 0n)\n\n assert.strictEqual(accounts[1].credits_posted, 0n)\n assert.strictEqual(accounts[1].credits_pending, 0n)\n assert.strictEqual(accounts[1].debits_posted, 100n)\n assert.strictEqual(accounts[1].debits_pending, 0n)\n})\n\ntest('can create a two-phase transfer', async (): Promise<void> => {\n let flags = 0\n flags |= TransferFlags.pending\n const transfer: Transfer = {\n id: 2n,\n debit_account_id: accountB.id,\n credit_account_id: accountA.id,\n user_data: 0n,\n reserved: 0n,\n pending_id: 0n,\n timeout: BigInt(2e9),\n ledger: 1,\n code: 1,\n flags,\n amount: 50n,\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_posted, 100n)\n assert.strictEqual(accounts[0].credits_pending, 50n)\n assert.strictEqual(accounts[0].debits_posted, 0n)\n assert.strictEqual(accounts[0].debits_pending, 0n)\n\n assert.strictEqual(accounts[1].credits_posted, 0n)\n assert.strictEqual(accounts[1].credits_pending, 0n)\n assert.strictEqual(accounts[1].debits_posted, 100n)\n assert.strictEqual(accounts[1].debits_pending, 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, 2n)\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 post a two-phase transfer', async (): Promise<void> => {\n let flags = 0\n flags |= TransferFlags.post_pending_transfer\n\n const commit: Transfer = {\n id: 3n,\n debit_account_id: BigInt(0),\n credit_account_id: BigInt(0),\n user_data: 0n,\n reserved: 0n,\n pending_id: 2n,// must match the id of the pending transfer\n timeout: 0n,\n ledger: 1,\n code: 1,\n flags: flags,\n amount: 0n,\n timestamp: 0n, // this will be set correctly by the TigerBeetle server\n }\n\n const errors = await client.createTransfers([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_posted, 150n)\n assert.strictEqual(accounts[0].credits_pending, 0n)\n assert.strictEqual(accounts[0].debits_posted, 0n)\n assert.strictEqual(accounts[0].debits_pending, 0n)\n\n assert.strictEqual(accounts[1].credits_posted, 0n)\n assert.strictEqual(accounts[1].credits_pending, 0n)\n assert.strictEqual(accounts[1].debits_posted, 150n)\n assert.strictEqual(accounts[1].debits_pending, 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: 4n,\n debit_account_id: accountB.id,\n credit_account_id: accountA.id,\n user_data: 0n,\n reserved: 0n,\n pending_id: 0n,\n timeout: BigInt(1e9),\n ledger: 1,\n code: 1,\n flags: TransferFlags.pending,\n amount: 50n,\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: Transfer = {\n id: 5n,\n debit_account_id: BigInt(0),\n credit_account_id: BigInt(0),\n user_data: 0n,\n reserved: 0n,\n pending_id: 4n, // must match the id of the pending transfer\n timeout: 0n,\n ledger: 1,\n code: 1,\n flags: TransferFlags.void_pending_transfer,\n amount: 0n,\n timestamp: 0n, // this will be set correctly by the TigerBeetle server\n }\n\n const errors = await client.createTransfers([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_posted, 150n)\n assert.strictEqual(accounts[0].credits_pending, 0n)\n assert.strictEqual(accounts[0].debits_posted, 0n)\n assert.strictEqual(accounts[0].debits_pending, 0n)\n\n assert.strictEqual(accounts[1].credits_posted, 0n)\n assert.strictEqual(accounts[1].credits_pending, 0n)\n assert.strictEqual(accounts[1].debits_posted, 150n)\n assert.strictEqual(accounts[1].debits_pending, 0n)\n})\n\ntest('can link transfers', async (): Promise<void> => {\n const transfer1: Transfer = {\n id: 6n,\n debit_account_id: accountB.id,\n credit_account_id: accountA.id,\n user_data: 0n,\n reserved: 0n,\n pending_id: 0n,\n timeout: 0n,\n ledger: 1,\n code: 1,\n flags: TransferFlags.linked, // points to transfer2\n amount: 100n,\n timestamp: 0n, // will be set correctly by the TigerBeetle server\n }\n const transfer2: Transfer = {\n id: 6n,\n debit_account_id: accountB.id,\n credit_account_id: accountA.id,\n user_data: 0n,\n reserved: 0n,\n pending_id: 0n,\n timeout: 0n,\n ledger: 1,\n code: 1,\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 amount: 100n,\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_posted, 150n)\n assert.strictEqual(accounts[0].credits_pending, 0n)\n assert.strictEqual(accounts[0].debits_posted, 0n)\n assert.strictEqual(accounts[0].debits_pending, 0n)\n\n assert.strictEqual(accounts[1].credits_posted, 0n)\n assert.strictEqual(accounts[1].credits_pending, 0n)\n assert.strictEqual(accounts[1].debits_posted, 150n)\n assert.strictEqual(accounts[1].debits_pending, 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,wBAOU;AAEV,MAAM,MAAM,GAAG,IAAA,eAAY,EAAC;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,SAAS,EAAE,EAAE;IACb,QAAQ,EAAE,aAAa;IACvB,MAAM,EAAE,CAA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C,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 {\n createClient,\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 user_data: 0n,\n reserved: Zeroed48Bytes,\n ledger: 1,\n code: 718,\n flags: 0,\n debits_pending: 0n,\n debits_posted: 0n,\n credits_pending: 0n,\n credits_posted: 0n,\n timestamp: 0n // this will be set correctly by the TigerBeetle server\n}\nconst accountB: Account = {\n id: 19n,\n user_data: 0n,\n reserved: Zeroed48Bytes,\n ledger: 1,\n code: 719,\n flags: 0,\n debits_pending: 0n,\n debits_posted: 0n,\n credits_pending: 0n,\n credits_posted: 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 check `code` on Account to be u16', async (): Promise<void> => {\n const account = { ...accountA, id: 0n }\n\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([account.id])\n assert.strictEqual(accounts.length, 0)\n})\n\ntest('can create accounts', async (): Promise<void> => {\n const errors = await client.createAccounts([accountA])\n assert.strictEqual(errors.length, 0)\n})\n\ntest('can return error on account', 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, result: CreateAccountError.exists })\n})\n\ntest('throws error if timestamp is not set to 0n on account', 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.ledger, 1)\n assert.strictEqual(account1.flags, 0)\n assert.strictEqual(account1.credits_posted, 0n)\n assert.strictEqual(account1.credits_pending, 0n)\n assert.strictEqual(account1.debits_posted, 0n)\n assert.strictEqual(account1.debits_pending, 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.ledger, 1)\n assert.strictEqual(account2.flags, 0)\n assert.strictEqual(account2.credits_posted, 0n)\n assert.strictEqual(account2.credits_pending, 0n)\n assert.strictEqual(account2.debits_posted, 0n)\n assert.strictEqual(account2.debits_pending, 0n)\n assert.ok(account2.timestamp > 0n)\n})\n\ntest('can create a transfer', async (): Promise<void> => {\n const transfer: Transfer = {\n id: 1n,\n debit_account_id: accountB.id,\n credit_account_id: accountA.id,\n user_data: 0n,\n reserved: 0n,\n pending_id: 0n,\n timeout: 0n,\n ledger: 1,\n code: 1,\n flags: 0,\n amount: 100n,\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_posted, 100n)\n assert.strictEqual(accounts[0].credits_pending, 0n)\n assert.strictEqual(accounts[0].debits_posted, 0n)\n assert.strictEqual(accounts[0].debits_pending, 0n)\n\n assert.strictEqual(accounts[1].credits_posted, 0n)\n assert.strictEqual(accounts[1].credits_pending, 0n)\n assert.strictEqual(accounts[1].debits_posted, 100n)\n assert.strictEqual(accounts[1].debits_pending, 0n)\n})\n\ntest('can create a two-phase transfer', async (): Promise<void> => {\n let flags = 0\n flags |= TransferFlags.pending\n const transfer: Transfer = {\n id: 2n,\n debit_account_id: accountB.id,\n credit_account_id: accountA.id,\n user_data: 0n,\n reserved: 0n,\n pending_id: 0n,\n timeout: BigInt(2e9),\n ledger: 1,\n code: 1,\n flags,\n amount: 50n,\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_posted, 100n)\n assert.strictEqual(accounts[0].credits_pending, 50n)\n assert.strictEqual(accounts[0].debits_posted, 0n)\n assert.strictEqual(accounts[0].debits_pending, 0n)\n\n assert.strictEqual(accounts[1].credits_posted, 0n)\n assert.strictEqual(accounts[1].credits_pending, 0n)\n assert.strictEqual(accounts[1].debits_posted, 100n)\n assert.strictEqual(accounts[1].debits_pending, 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, 2n)\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 post a two-phase transfer', async (): Promise<void> => {\n let flags = 0\n flags |= TransferFlags.post_pending_transfer\n\n const commit: Transfer = {\n id: 3n,\n debit_account_id: BigInt(0),\n credit_account_id: BigInt(0),\n user_data: 0n,\n reserved: 0n,\n pending_id: 2n,// must match the id of the pending transfer\n timeout: 0n,\n ledger: 1,\n code: 1,\n flags: flags,\n amount: 0n,\n timestamp: 0n, // this will be set correctly by the TigerBeetle server\n }\n\n const errors = await client.createTransfers([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_posted, 150n)\n assert.strictEqual(accounts[0].credits_pending, 0n)\n assert.strictEqual(accounts[0].debits_posted, 0n)\n assert.strictEqual(accounts[0].debits_pending, 0n)\n\n assert.strictEqual(accounts[1].credits_posted, 0n)\n assert.strictEqual(accounts[1].credits_pending, 0n)\n assert.strictEqual(accounts[1].debits_posted, 150n)\n assert.strictEqual(accounts[1].debits_pending, 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: 4n,\n debit_account_id: accountB.id,\n credit_account_id: accountA.id,\n user_data: 0n,\n reserved: 0n,\n pending_id: 0n,\n timeout: BigInt(1e9),\n ledger: 1,\n code: 1,\n flags: TransferFlags.pending,\n amount: 50n,\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: Transfer = {\n id: 5n,\n debit_account_id: BigInt(0),\n credit_account_id: BigInt(0),\n user_data: 0n,\n reserved: 0n,\n pending_id: 4n, // must match the id of the pending transfer\n timeout: 0n,\n ledger: 1,\n code: 1,\n flags: TransferFlags.void_pending_transfer,\n amount: 0n,\n timestamp: 0n, // this will be set correctly by the TigerBeetle server\n }\n\n const errors = await client.createTransfers([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_posted, 150n)\n assert.strictEqual(accounts[0].credits_pending, 0n)\n assert.strictEqual(accounts[0].debits_posted, 0n)\n assert.strictEqual(accounts[0].debits_pending, 0n)\n\n assert.strictEqual(accounts[1].credits_posted, 0n)\n assert.strictEqual(accounts[1].credits_pending, 0n)\n assert.strictEqual(accounts[1].debits_posted, 150n)\n assert.strictEqual(accounts[1].debits_pending, 0n)\n})\n\ntest('can link transfers', async (): Promise<void> => {\n const transfer1: Transfer = {\n id: 6n,\n debit_account_id: accountB.id,\n credit_account_id: accountA.id,\n user_data: 0n,\n reserved: 0n,\n pending_id: 0n,\n timeout: 0n,\n ledger: 1,\n code: 1,\n flags: TransferFlags.linked, // points to transfer2\n amount: 100n,\n timestamp: 0n, // will be set correctly by the TigerBeetle server\n }\n const transfer2: Transfer = {\n id: 6n,\n debit_account_id: accountB.id,\n credit_account_id: accountA.id,\n user_data: 0n,\n reserved: 0n,\n pending_id: 0n,\n timeout: 0n,\n ledger: 1,\n code: 1,\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 amount: 100n,\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, result: CreateTransferError.linked_event_failed })\n assert.deepStrictEqual(errors[1], { index: 1, result: 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_posted, 150n)\n assert.strictEqual(accounts[0].credits_pending, 0n)\n assert.strictEqual(accounts[0].debits_posted, 0n)\n assert.strictEqual(accounts[0].debits_pending, 0n)\n\n assert.strictEqual(accounts[1].credits_posted, 0n)\n assert.strictEqual(accounts[1].credits_pending, 0n)\n assert.strictEqual(accounts[1].debits_posted, 150n)\n assert.strictEqual(accounts[1].debits_pending, 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.13.118",
3
+ "version": "0.13.119",
4
4
  "description": "TigerBeetle Node.js client",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -26,11 +26,11 @@
26
26
  "scripts": {
27
27
  "benchmark": "./scripts/benchmark.sh",
28
28
  "test": "node dist/test",
29
- "build": "npm run build_tsc && npm run build_lib",
30
- "build_tsc": "./node_modules/typescript/bin/tsc",
31
- "build_lib": "node scripts/build_lib.js",
32
- "prepack": "npm run build && find dist/bin \\( -iname \\*.so -o -iname \\*.dylib -o -iname \\*.dll \\) -printf \"mv '%h/%f' '%h/client.node'\\n\" | sh",
33
- "clean": "rm -rf build dist node_modules src/zig-cache zig"
29
+ "build": "node ./scripts/build.js",
30
+ "build_tsc": "node ./node_modules/typescript/bin/tsc",
31
+ "build_lib": "node ./scripts/build_lib.js",
32
+ "prepack": "node ./scripts/prepack.js",
33
+ "clean": "node ./scripts/clean.js"
34
34
  },
35
35
  "author": "TigerBeetle, Inc",
36
36
  "license": "Apache-2.0",
package/src/index.ts CHANGED
@@ -17,7 +17,8 @@ function getBinding (): Binding {
17
17
 
18
18
  const platformMap = {
19
19
  "linux": "linux",
20
- "darwin": "macos"
20
+ "darwin": "macos",
21
+ "win32" : "windows",
21
22
  }
22
23
 
23
24
  if (! (arch in archMap)) {
package/src/test.ts CHANGED
@@ -71,7 +71,7 @@ test('can return error on account', async (): Promise<void> => {
71
71
  const errors = await client.createAccounts([accountA, accountB])
72
72
 
73
73
  assert.strictEqual(errors.length, 1)
74
- assert.deepStrictEqual(errors[0], { index: 0, code: CreateAccountError.exists })
74
+ assert.deepStrictEqual(errors[0], { index: 0, result: CreateAccountError.exists })
75
75
  })
76
76
 
77
77
  test('throws error if timestamp is not set to 0n on account', async (): Promise<void> => {
@@ -310,8 +310,8 @@ test('can link transfers', async (): Promise<void> => {
310
310
 
311
311
  const errors = await client.createTransfers([transfer1, transfer2])
312
312
  assert.strictEqual(errors.length, 2)
313
- assert.deepStrictEqual(errors[0], { index: 0, code: CreateTransferError.linked_event_failed })
314
- assert.deepStrictEqual(errors[1], { index: 1, code: CreateTransferError.exists_with_different_flags })
313
+ assert.deepStrictEqual(errors[0], { index: 0, result: CreateTransferError.linked_event_failed })
314
+ assert.deepStrictEqual(errors[1], { index: 1, result: CreateTransferError.exists_with_different_flags })
315
315
 
316
316
  const accounts = await client.lookupAccounts([accountA.id, accountB.id])
317
317
  assert.strictEqual(accounts.length, 2)