Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tigerbeetle-node

Package Overview
Dependencies
Maintainers
3
Versions
318
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tigerbeetle-node - npm Package Compare versions

Comparing version 0.14.171 to 0.14.174

15

dist/bindings.d.ts

@@ -16,2 +16,8 @@ export declare enum AccountFlags {

}
export declare enum GetAccountTransfersFlags {
none = 0,
debits = 1,
credits = 2,
reversed = 4
}
export declare type Account = {

@@ -137,2 +143,8 @@ id: bigint;

};
export declare type GetAccountTransfers = {
account_id: bigint;
timestamp: bigint;
limit: number;
flags: number;
};
export declare enum Operation {

@@ -142,3 +154,4 @@ create_accounts = 128,

lookup_accounts = 130,
lookup_transfers = 131
lookup_transfers = 131,
get_account_transfers = 132
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Operation = exports.CreateTransferError = exports.CreateAccountError = exports.TransferFlags = exports.AccountFlags = void 0;
exports.Operation = exports.CreateTransferError = exports.CreateAccountError = exports.GetAccountTransfersFlags = exports.TransferFlags = exports.AccountFlags = void 0;
var AccountFlags;

@@ -21,2 +21,9 @@ (function (AccountFlags) {

})(TransferFlags = exports.TransferFlags || (exports.TransferFlags = {}));
var GetAccountTransfersFlags;
(function (GetAccountTransfersFlags) {
GetAccountTransfersFlags[GetAccountTransfersFlags["none"] = 0] = "none";
GetAccountTransfersFlags[GetAccountTransfersFlags["debits"] = 1] = "debits";
GetAccountTransfersFlags[GetAccountTransfersFlags["credits"] = 2] = "credits";
GetAccountTransfersFlags[GetAccountTransfersFlags["reversed"] = 4] = "reversed";
})(GetAccountTransfersFlags = exports.GetAccountTransfersFlags || (exports.GetAccountTransfersFlags = {}));
var CreateAccountError;

@@ -112,3 +119,4 @@ (function (CreateAccountError) {

Operation[Operation["lookup_transfers"] = 131] = "lookup_transfers";
Operation[Operation["get_account_transfers"] = 132] = "get_account_transfers";
})(Operation = exports.Operation || (exports.Operation = {}));
//# sourceMappingURL=bindings.js.map

5

dist/index.d.ts
export * from './bindings';
import { Account, Transfer, CreateAccountsError, CreateTransfersError } from './bindings';
import { Account, Transfer, CreateAccountsError, CreateTransfersError, GetAccountTransfers } from './bindings';
export declare type Context = object;
export declare type AccountID = bigint;
export declare type TransferID = bigint;
export declare type Event = Account | Transfer | AccountID | TransferID;
export declare type Event = Account | Transfer | AccountID | TransferID | GetAccountTransfers;
export declare type Result = CreateAccountsError | CreateTransfersError | Account | Transfer;

@@ -19,4 +19,5 @@ export declare type ResultCallback = (error: Error | null, results: Result[] | null) => void;

lookupTransfers: (batch: TransferID[]) => Promise<Transfer[]>;
getAccountTransfers: (filter: GetAccountTransfers) => Promise<Transfer[]>;
destroy: () => void;
}
export declare function createClient(args: ClientInitArgs): Client;

@@ -50,3 +50,3 @@ "use strict";

function createClient(args) {
const concurrency_max_default = 32;
const concurrency_max_default = 256;
const context = binding.init({

@@ -82,2 +82,3 @@ cluster_id: args.cluster_id,

lookupTransfers(batch) { return request(bindings_1.Operation.lookup_transfers, batch); },
getAccountTransfers(filter) { return request(bindings_1.Operation.get_account_transfers, [filter]); },
destroy() { binding.deinit(context); },

@@ -84,0 +85,0 @@ };

@@ -298,2 +298,143 @@ "use strict";

});
test('can get account transfers', async () => {
const accountC = {
id: 21n,
debits_pending: 0n,
debits_posted: 0n,
credits_pending: 0n,
credits_posted: 0n,
user_data_128: 0n,
user_data_64: 0n,
user_data_32: 0,
reserved: 0,
ledger: 1,
code: 718,
flags: 0,
timestamp: 0n
};
const account_errors = await client.createAccounts([accountC]);
assert_1.default.strictEqual(account_errors.length, 0);
var transfers_created = [];
for (var i = 0; i < 10; i++) {
transfers_created.push({
id: BigInt(i + 10000),
debit_account_id: i % 2 == 0 ? accountC.id : accountA.id,
credit_account_id: i % 2 == 0 ? accountB.id : accountC.id,
amount: 100n,
user_data_128: 0n,
user_data_64: 0n,
user_data_32: 0,
pending_id: 0n,
timeout: 0,
ledger: 1,
code: 1,
flags: 0,
timestamp: 0n,
});
}
const transfers_created_result = await client.createTransfers(transfers_created);
assert_1.default.strictEqual(transfers_created_result.length, 0);
var filter = {
account_id: accountC.id,
timestamp: 0n,
limit: 0,
flags: _1.GetAccountTransfersFlags.credits | _1.GetAccountTransfersFlags.debits,
};
var transfers = await client.getAccountTransfers(filter);
assert_1.default.strictEqual(transfers.length, transfers_created.length);
var timestamp = 0n;
for (var transfer of transfers) {
assert_1.default.ok(timestamp < transfer.timestamp);
timestamp = transfer.timestamp;
}
filter = {
account_id: accountC.id,
timestamp: 0n,
limit: 8190,
flags: _1.GetAccountTransfersFlags.debits | _1.GetAccountTransfersFlags.reversed,
};
transfers = await client.getAccountTransfers(filter);
assert_1.default.strictEqual(transfers.length, transfers_created.length / 2);
timestamp = 1n << 64n;
for (var transfer of transfers) {
assert_1.default.ok(transfer.timestamp < timestamp);
timestamp = transfer.timestamp;
}
filter = {
account_id: accountC.id,
timestamp: 0n,
limit: 8190,
flags: _1.GetAccountTransfersFlags.credits | _1.GetAccountTransfersFlags.reversed,
};
transfers = await client.getAccountTransfers(filter);
assert_1.default.strictEqual(transfers.length, transfers_created.length / 2);
timestamp = 1n << 64n;
for (var transfer of transfers) {
assert_1.default.ok(transfer.timestamp < timestamp);
timestamp = transfer.timestamp;
}
filter = {
account_id: accountC.id,
timestamp: 0n,
limit: transfers_created.length / 2,
flags: _1.GetAccountTransfersFlags.credits | _1.GetAccountTransfersFlags.debits,
};
transfers = await client.getAccountTransfers(filter);
assert_1.default.strictEqual(transfers.length, transfers_created.length / 2);
timestamp = 0n;
for (var transfer of transfers) {
assert_1.default.ok(timestamp < transfer.timestamp);
timestamp = transfer.timestamp;
}
filter = {
account_id: accountC.id,
timestamp: timestamp,
limit: transfers_created.length / 2,
flags: _1.GetAccountTransfersFlags.credits | _1.GetAccountTransfersFlags.debits,
};
transfers = await client.getAccountTransfers(filter);
assert_1.default.strictEqual(transfers.length, transfers_created.length / 2);
for (var transfer of transfers) {
assert_1.default.ok(timestamp < transfer.timestamp);
timestamp = transfer.timestamp;
}
filter = {
account_id: accountC.id,
timestamp: timestamp,
limit: transfers_created.length / 2,
flags: _1.GetAccountTransfersFlags.credits | _1.GetAccountTransfersFlags.debits,
};
transfers = await client.getAccountTransfers(filter);
assert_1.default.strictEqual(transfers.length, 0);
assert_1.default.strictEqual((await client.getAccountTransfers({
account_id: 0n,
timestamp: timestamp,
limit: 8190,
flags: _1.GetAccountTransfersFlags.credits | _1.GetAccountTransfersFlags.debits,
})).length, 0);
assert_1.default.strictEqual((await client.getAccountTransfers({
account_id: accountC.id,
timestamp: (1n << 64n) - 1n,
limit: 8190,
flags: _1.GetAccountTransfersFlags.credits | _1.GetAccountTransfersFlags.debits,
})).length, 0);
assert_1.default.strictEqual((await client.getAccountTransfers({
account_id: accountC.id,
timestamp: 0n,
limit: 0,
flags: _1.GetAccountTransfersFlags.credits | _1.GetAccountTransfersFlags.debits,
})).length, 0);
assert_1.default.strictEqual((await client.getAccountTransfers({
account_id: accountC.id,
timestamp: 0n,
limit: 8190,
flags: _1.GetAccountTransfersFlags.none,
})).length, 0);
assert_1.default.strictEqual((await client.getAccountTransfers({
account_id: accountC.id,
timestamp: 0n,
limit: 8190,
flags: 0xFFFF,
})).length, 0);
});
async function main() {

@@ -300,0 +441,0 @@ const start = new Date().getTime();

{
"name": "tigerbeetle-node",
"version": "0.14.171",
"version": "0.14.174",
"description": "TigerBeetle Node.js client",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -552,2 +552,25 @@ ---

## Get Account Transfers
NOTE: This is a preview API that is subject to breaking changes once we have
a stable querying API.
Fetches the transfers involving a given account, allowing basic filter and pagination
capabilities.
The transfers in the response are sorted by `timestamp` in chronological or
reverse-chronological order.
```javascript
let filter = {
account_id: 2n,
timestamp: 0n, // No filter by Timestamp.
limit: 10, // Limit to ten transfers at most.
flags: GetAccountTransfersFlags.debits | // Include transfer from the debit side.
GetAccountTransfersFlags.credits | // Include transfer from the credit side.
GetAccountTransfersFlags.reversed, // Sort by timestamp in reverse-chronological order.
}
const account_transfers = await client.getAccountTransfers(filter)
```
## Linked Events

@@ -554,0 +577,0 @@

@@ -69,2 +69,25 @@ ///////////////////////////////////////////////////////

/**
* See [GetAccountTransfersFlags](https://docs.tigerbeetle.com/reference/operations/get_account_transfers#flags)
*/
export enum GetAccountTransfersFlags {
none = 0,
/**
* See [debits](https://docs.tigerbeetle.com/reference/operations/get_account_transfers#flagsdebits)
*/
debits = (1 << 0),
/**
* See [credits](https://docs.tigerbeetle.com/reference/operations/get_account_transfers#flagscredits)
*/
credits = (1 << 1),
/**
* See [reversed](https://docs.tigerbeetle.com/reference/operations/get_account_transfers#flagsreversed)
*/
reversed = (1 << 2),
}
/**
* See [Account](https://docs.tigerbeetle.com/reference/accounts/#)

@@ -626,2 +649,29 @@ */

/**
* See [GetAccountTransfers](https://docs.tigerbeetle.com/reference/operations/get_account_transfers#)
*/
export type GetAccountTransfers = {
/**
* See [account_id](https://docs.tigerbeetle.com/reference/operations/get_account_transfers#account_id)
*/
account_id: bigint
/**
* See [timestamp](https://docs.tigerbeetle.com/reference/operations/get_account_transfers#timestamp)
*/
timestamp: bigint
/**
* See [limit](https://docs.tigerbeetle.com/reference/operations/get_account_transfers#limit)
*/
limit: number
/**
* See [flags](https://docs.tigerbeetle.com/reference/operations/get_account_transfers#flags)
*/
flags: number
}
export enum Operation {

@@ -632,3 +682,4 @@ create_accounts = 128,

lookup_transfers = 131,
get_account_transfers = 132,
}

@@ -8,2 +8,3 @@ export * from './bindings'

Operation,
GetAccountTransfers,
} from './bindings'

@@ -69,3 +70,3 @@

export type TransferID = bigint // u128
export type Event = Account | Transfer | AccountID | TransferID
export type Event = Account | Transfer | AccountID | TransferID | GetAccountTransfers
export type Result = CreateAccountsError | CreateTransfersError | Account | Transfer

@@ -97,2 +98,3 @@ export type ResultCallback = (error: Error | null, results: Result[] | null) => void

lookupTransfers: (batch: TransferID[]) => Promise<Transfer[]>
getAccountTransfers: (filter: GetAccountTransfers) => Promise<Transfer[]>
destroy: () => void

@@ -102,3 +104,3 @@ }

export function createClient (args: ClientInitArgs): Client {
const concurrency_max_default = 32 // arbitrary
const concurrency_max_default = 256 // arbitrary
const context = binding.init({

@@ -133,4 +135,5 @@ cluster_id: args.cluster_id,

lookupTransfers(batch) { return request(Operation.lookup_transfers, batch) },
getAccountTransfers(filter) { return request(Operation.get_account_transfers, [filter]) },
destroy() { binding.deinit(context) },
}
}

@@ -8,3 +8,5 @@ import assert, { AssertionError } from 'assert'

CreateAccountError,
CreateTransferError
CreateTransferError,
GetAccountTransfers,
GetAccountTransfersFlags,
} from '.'

@@ -344,2 +346,171 @@

test('can get account transfers', async (): Promise<void> => {
const accountC: Account = {
id: 21n,
debits_pending: 0n,
debits_posted: 0n,
credits_pending: 0n,
credits_posted: 0n,
user_data_128: 0n,
user_data_64: 0n,
user_data_32: 0,
reserved: 0,
ledger: 1,
code: 718,
flags: 0,
timestamp: 0n
}
const account_errors = await client.createAccounts([accountC])
assert.strictEqual(account_errors.length, 0)
var transfers_created : Transfer[] = [];
// Create transfers where the new account is either the debit or credit account:
for (var i=0; i<10;i++) {
transfers_created.push({
id: BigInt(i + 10000),
debit_account_id: i % 2 == 0 ? accountC.id : accountA.id,
credit_account_id: i % 2 == 0 ? accountB.id : accountC.id,
amount: 100n,
user_data_128: 0n,
user_data_64: 0n,
user_data_32: 0,
pending_id: 0n,
timeout: 0,
ledger: 1,
code: 1,
flags: 0,
timestamp: 0n,
});
}
const transfers_created_result = await client.createTransfers(transfers_created)
assert.strictEqual(transfers_created_result.length, 0)
// Query all transfers for accountC:
var filter: GetAccountTransfers = {
account_id: accountC.id,
timestamp: 0n,
limit: 0,
flags: GetAccountTransfersFlags.credits | GetAccountTransfersFlags.debits,
}
var transfers = await client.getAccountTransfers(filter)
assert.strictEqual(transfers.length, transfers_created.length)
var timestamp = 0n;
for (var transfer of transfers) {
assert.ok(timestamp < transfer.timestamp);
timestamp = transfer.timestamp;
}
// Query only the debit transfers for accountC, descending:
filter = {
account_id: accountC.id,
timestamp: 0n,
limit: 8190,
flags: GetAccountTransfersFlags.debits | GetAccountTransfersFlags.reversed,
}
transfers = await client.getAccountTransfers(filter)
assert.strictEqual(transfers.length, transfers_created.length / 2)
timestamp = 1n << 64n;
for (var transfer of transfers) {
assert.ok(transfer.timestamp < timestamp);
timestamp = transfer.timestamp;
}
// Query only the credit transfers for accountC, descending:
filter = {
account_id: accountC.id,
timestamp: 0n,
limit: 8190,
flags: GetAccountTransfersFlags.credits | GetAccountTransfersFlags.reversed,
}
transfers = await client.getAccountTransfers(filter)
assert.strictEqual(transfers.length, transfers_created.length / 2)
timestamp = 1n << 64n;
for (var transfer of transfers) {
assert.ok(transfer.timestamp < timestamp);
timestamp = transfer.timestamp;
}
// Query the first 5 transfers for accountC:
filter = {
account_id: accountC.id,
timestamp: 0n,
limit: transfers_created.length / 2,
flags: GetAccountTransfersFlags.credits | GetAccountTransfersFlags.debits,
}
transfers = await client.getAccountTransfers(filter)
assert.strictEqual(transfers.length, transfers_created.length / 2)
timestamp = 0n;
for (var transfer of transfers) {
assert.ok(timestamp < transfer.timestamp);
timestamp = transfer.timestamp;
}
// Query the next 5 transfers for accountC, with pagination:
filter = {
account_id: accountC.id,
timestamp: timestamp,
limit: transfers_created.length / 2,
flags: GetAccountTransfersFlags.credits | GetAccountTransfersFlags.debits,
}
transfers = await client.getAccountTransfers(filter)
assert.strictEqual(transfers.length, transfers_created.length / 2)
for (var transfer of transfers) {
assert.ok(timestamp < transfer.timestamp);
timestamp = transfer.timestamp;
}
// Query again, no more transfers should be found:
filter = {
account_id: accountC.id,
timestamp: timestamp,
limit: transfers_created.length / 2,
flags: GetAccountTransfersFlags.credits | GetAccountTransfersFlags.debits,
}
transfers = await client.getAccountTransfers(filter)
assert.strictEqual(transfers.length, 0)
// Invalid account:
assert.strictEqual((await client.getAccountTransfers({
account_id: 0n,
timestamp: timestamp,
limit: 8190,
flags: GetAccountTransfersFlags.credits | GetAccountTransfersFlags.debits,
})).length, 0)
// Invalid timestamp:
assert.strictEqual((await client.getAccountTransfers({
account_id: accountC.id,
timestamp: (1n << 64n) - 1n,
limit: 8190,
flags: GetAccountTransfersFlags.credits | GetAccountTransfersFlags.debits,
})).length, 0)
// Zero limit:
assert.strictEqual((await client.getAccountTransfers({
account_id: accountC.id,
timestamp: 0n,
limit: 0,
flags: GetAccountTransfersFlags.credits | GetAccountTransfersFlags.debits,
})).length, 0)
// Empty flags:
assert.strictEqual((await client.getAccountTransfers({
account_id: accountC.id,
timestamp: 0n,
limit: 8190,
flags: GetAccountTransfersFlags.none,
})).length, 0)
// Invalid flags:
assert.strictEqual((await client.getAccountTransfers({
account_id: accountC.id,
timestamp: 0n,
limit: 8190,
flags: 0xFFFF,
})).length, 0)
})
async function main () {

@@ -346,0 +517,0 @@ const start = new Date().getTime()

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc