tigerbeetle-node 0.12.28 → 0.12.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/aarch64-macos/client.node +0 -0
- package/dist/bin/x86_64-macos/client.node +0 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
|
Binary file
|
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -109,8 +109,8 @@ export declare enum CreateTransferError {
|
|
|
109
109
|
exists_with_different_flags = 37,
|
|
110
110
|
exists_with_different_debit_account_id = 38,
|
|
111
111
|
exists_with_different_credit_account_id = 39,
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
exists_with_different_pending_id = 40,
|
|
113
|
+
exists_with_different_user_data = 41,
|
|
114
114
|
exists_with_different_timeout = 42,
|
|
115
115
|
exists_with_different_code = 43,
|
|
116
116
|
exists_with_different_amount = 44,
|
package/dist/index.js
CHANGED
|
@@ -112,8 +112,8 @@ var CreateTransferError;
|
|
|
112
112
|
CreateTransferError[CreateTransferError["exists_with_different_flags"] = 37] = "exists_with_different_flags";
|
|
113
113
|
CreateTransferError[CreateTransferError["exists_with_different_debit_account_id"] = 38] = "exists_with_different_debit_account_id";
|
|
114
114
|
CreateTransferError[CreateTransferError["exists_with_different_credit_account_id"] = 39] = "exists_with_different_credit_account_id";
|
|
115
|
-
CreateTransferError[CreateTransferError["
|
|
116
|
-
CreateTransferError[CreateTransferError["
|
|
115
|
+
CreateTransferError[CreateTransferError["exists_with_different_pending_id"] = 40] = "exists_with_different_pending_id";
|
|
116
|
+
CreateTransferError[CreateTransferError["exists_with_different_user_data"] = 41] = "exists_with_different_user_data";
|
|
117
117
|
CreateTransferError[CreateTransferError["exists_with_different_timeout"] = 42] = "exists_with_different_timeout";
|
|
118
118
|
CreateTransferError[CreateTransferError["exists_with_different_code"] = 43] = "exists_with_different_code";
|
|
119
119
|
CreateTransferError[CreateTransferError["exists_with_different_amount"] = 44] = "exists_with_different_amount";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,SAAS,UAAU;IACjB,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAA;IAElC,MAAM,OAAO,GAAG;QACd,OAAO,EAAE,SAAS;QAClB,KAAK,EAAE,QAAQ;KAChB,CAAA;IAED,MAAM,WAAW,GAAG;QAClB,OAAO,EAAE,OAAO;QAChB,QAAQ,EAAE,OAAO;KAClB,CAAA;IAED,IAAI,CAAE,CAAC,IAAI,IAAI,OAAO,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,EAAE,CAAC,CAAA;KAC7C;IAED,IAAI,CAAE,CAAC,QAAQ,IAAI,WAAW,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAA;KACrD;IAED,IAAI,KAAK,GAAG,EAAE,CAAA;IAcd,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACxB,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAE5B,IAAI,QAAQ,KAAK,OAAO,EAAE;QACxB,KAAK,GAAG,MAAM,CAAA;QAEd,KAAK,MAAM,IAAI,IAAI,EAAE,CAAC,WAAW,CAAC,uBAAuB,CAAC,EAAE;YAC1D,MAAM,QAAQ,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC,CAAA;YAC1E,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;gBAC7B,KAAK,GAAG,OAAO,CAAA;gBACf,MAAK;aACN;SACF;KACF;IAED,MAAM,QAAQ,GAAG,SAAS,OAAO,CAAC,IAAI,CAA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CAAA;IACJ,CAAC,CAAA;IAED,MAAM,eAAe,GAAG,KAAK,EAAE,KAAmB,EAAuB,EAAE;QACzE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,QAAQ,GAAG,CAAC,KAAwB,EAAE,OAAmB,EAAE,EAAE;gBACjE,IAAI,KAAK,EAAE;oBACT,MAAM,CAAC,KAAK,CAAC,CAAA;oBACb,OAAM;iBACP;gBACD,OAAO,CAAC,OAAO,CAAC,CAAA;YAClB,CAAC,CAAA;YAED,IAAI;gBACF,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,eAAe,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAA;aACrE;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,CAAC,KAAK,CAAC,CAAA;aACd;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;IAED,MAAM,OAAO,GAAG,GAAS,EAAE;QACzB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QACvB,IAAI,SAAS,EAAC;YACZ,aAAa,CAAC,SAAS,CAAC,CAAA;SACzB;QACD,OAAO,GAAG,SAAS,CAAA;IACrB,CAAC,CAAA;IAED,OAAO,GAAG;QACR,cAAc;QACd,eAAe;QACf,cAAc;QACd,eAAe;QACf,OAAO;QACP,UAAU;QACV,OAAO;KACR,CAAA;IAED,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE;QAC3B,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACvB,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAEnB,OAAO,OAAO,CAAA;AAChB,CAAC;AAzID,oCAyIC","sourcesContent":["function getBinding (): Binding {\n const { arch, platform } = process\n\n const archMap = {\n \"arm64\": \"aarch64\",\n \"x64\": \"x86_64\"\n }\n\n const platformMap = {\n \"linux\": \"linux\",\n \"darwin\": \"macos\"\n }\n\n if (! (arch in archMap)) {\n throw new Error(`Unsupported arch: ${arch}`)\n }\n\n if (! (platform in platformMap)) {\n throw new Error(`Unsupported platform: ${platform}`)\n }\n\n let extra = ''\n\n /**\n * We need to detect during runtime which libc we're running on to load the correct NAPI.\n * binary.\n *\n * Rationale: The /proc/self/map_files/ subdirectory contains entries corresponding to\n * memory-mapped files loaded by Node.\n * https://man7.org/linux/man-pages/man5/proc.5.html: We detect a musl-based distro by\n * checking if any library contains the name \"musl\".\n *\n * Prior art: https://github.com/xerial/sqlite-jdbc/issues/623\n */\n\n const fs = require('fs')\n const path = require('path')\n\n if (platform === 'linux') {\n extra = '-gnu'\n\n for (const file of fs.readdirSync(\"/proc/self/map_files/\")) {\n const realPath = fs.readlinkSync(path.join(\"/proc/self/map_files/\", file))\n if (realPath.includes('musl')) {\n extra = '-musl'\n break\n }\n }\n }\n\n const filename = `./bin/${archMap[arch]}-${platformMap[platform]}${extra}/client.node`\n return require(filename)\n}\n\nconst binding = getBinding()\n\ninterface Binding {\n init: (args: BindingInitArgs) => Context\n request: (context: Context, operation: Operation, batch: Event[], result: ResultCallback) => void\n raw_request: (context: Context, operation: Operation, raw_batch: Buffer, result: ResultCallback) => void\n tick: (context: Context) => void,\n deinit: (context: Context) => void,\n tick_ms: number\n}\n\ninterface BindingInitArgs {\n cluster_id: number, // u32\n replica_addresses: Buffer,\n}\n\nexport interface InitArgs {\n cluster_id: number, // u32\n replica_addresses: Array<string | number>,\n}\n\nexport type Context = object\n\nexport type Account = {\n id: bigint // u128\n user_data: bigint // u128\n reserved: Buffer // [48]u8\n ledger: number // u32, ledger of value\n code: number // u16, A chart of accounts code describing the type of account (e.g. clearing, settlement)\n flags: number // u16\n debits_pending: bigint // u64\n debits_posted: bigint // u64\n credits_pending: bigint // u64\n credits_posted: bigint // u64\n timestamp: bigint // u64, Set this to 0n - the actual value will be set by TigerBeetle server\n}\n\nexport enum AccountFlags {\n linked = (1 << 0),\n debits_must_not_exceed_credits = (1 << 1),\n credits_must_not_exceed_debits = (1 << 2)\n}\n\nexport enum CreateAccountError {\n // ok = 0 (No Error)\n linked_event_failed = 1,\n linked_event_chain_open,\n timestamp_must_be_zero,\n\n reserved_flag,\n reserved_field,\n\n id_must_not_be_zero,\n id_must_not_be_int_max,\n\n flags_are_mutually_exclusive,\n\n ledger_must_not_be_zero,\n code_must_not_be_zero,\n debits_pending_must_be_zero,\n debits_posted_must_be_zero,\n credits_pending_must_be_zero,\n credits_posted_must_be_zero,\n\n exists_with_different_flags,\n exists_with_different_user_data,\n exists_with_different_ledger,\n exists_with_different_code,\n exists,\n}\n\nexport type CreateAccountsError = {\n index: number,\n code: CreateAccountError,\n}\n\nexport type Transfer = {\n id: bigint, // u128\n debit_account_id: bigint, // u128\n credit_account_id: bigint, // u128\n user_data: bigint, // u128\n reserved: bigint, // u128\n pending_id: bigint, // u128\n timeout: bigint, // u64, In nanoseconds.\n ledger: number // u32, The ledger of value.\n code: number, // u16, A user-defined accounting code to describe the type of transfer (e.g. settlement).\n flags: number, // u16\n amount: bigint, // u64,\n timestamp: bigint, // u64, Set this to 0n - the timestamp will be set by TigerBeetle.\n}\n\nexport enum TransferFlags {\n linked = (1 << 0),\n pending = (1 << 1),\n post_pending_transfer = (1 << 2),\n void_pending_transfer = (1 << 3),\n balancing_debit = (1 << 4),\n balancing_credit = (1 << 5),\n}\n\nexport enum CreateTransferError {\n // ok = 0 (No Error)\n linked_event_failed = 1,\n linked_event_chain_open,\n timestamp_must_be_zero,\n\n reserved_flag,\n reserved_field,\n\n id_must_not_be_zero,\n id_must_not_be_int_max,\n\n flags_are_mutually_exclusive,\n\n debit_account_id_must_not_be_zero,\n debit_account_id_must_not_be_int_max,\n credit_account_id_must_not_be_zero,\n credit_account_id_must_not_be_int_max,\n accounts_must_be_different,\n\n pending_id_must_be_zero,\n pending_id_must_not_be_zero,\n pending_id_must_not_be_int_max,\n pending_id_must_be_different,\n timeout_reserved_for_pending_transfer,\n\n ledger_must_not_be_zero,\n code_must_not_be_zero,\n amount_must_not_be_zero,\n\n debit_account_not_found,\n credit_account_not_found,\n\n accounts_must_have_the_same_ledger,\n transfer_must_have_the_same_ledger_as_accounts,\n\n pending_transfer_not_found,\n pending_transfer_not_pending,\n\n pending_transfer_has_different_debit_account_id,\n pending_transfer_has_different_credit_account_id,\n pending_transfer_has_different_ledger,\n pending_transfer_has_different_code,\n\n exceeds_pending_transfer_amount,\n pending_transfer_has_different_amount,\n\n pending_transfer_already_posted,\n pending_transfer_already_voided,\n\n pending_transfer_expired,\n\n exists_with_different_flags,\n exists_with_different_debit_account_id,\n exists_with_different_credit_account_id,\n exists_with_different_user_data,\n exists_with_different_pending_id,\n exists_with_different_timeout,\n exists_with_different_code,\n exists_with_different_amount,\n exists,\n\n overflows_debits_pending,\n overflows_credits_pending,\n overflows_debits_posted,\n overflows_credits_posted,\n overflows_debits,\n overflows_credits,\n overflows_timeout,\n\n exceeds_credits,\n exceeds_debits,\n}\n\nexport type CreateTransfersError = {\n index: number,\n code: CreateTransferError,\n}\n\nexport type AccountID = bigint // u128\nexport type TransferID = bigint // u128\n\nexport type Event = Account | Transfer | AccountID | TransferID\nexport type Result = CreateAccountsError | CreateTransfersError | Account | Transfer\nexport type ResultCallback = (error: undefined | Error, results: Result[]) => void\n\nexport enum Operation {\n CREATE_ACCOUNT = 3,\n CREATE_TRANSFER,\n ACCOUNT_LOOKUP,\n TRANSFER_LOOKUP\n}\n\nexport interface Client {\n createAccounts: (batch: Account[]) => Promise<CreateAccountsError[]>\n createTransfers: (batch: Transfer[]) => Promise<CreateTransfersError[]>\n lookupAccounts: (batch: AccountID[]) => Promise<Account[]>\n lookupTransfers: (batch: TransferID[]) => Promise<Transfer[]>\n request: (operation: Operation, batch: Event[], callback: ResultCallback) => void\n rawRequest: (operation: Operation, rawBatch: Buffer, callback: ResultCallback) => void\n destroy: () => void\n}\n\nlet _args: InitArgs | undefined = undefined\nconst isSameArgs = (args: InitArgs): boolean => {\n if (typeof _args === 'undefined') {\n return false\n }\n\n if (_args.replica_addresses.length !== args.replica_addresses.length) {\n return false\n }\n\n let isSameReplicas = true\n args.replica_addresses.forEach((entry, index) => {\n if (_args?.replica_addresses[index] !== entry) {\n isSameReplicas = false\n }\n })\n\n return args.cluster_id === _args.cluster_id && isSameReplicas\n}\n\nlet _client: Client | undefined = undefined\nlet _interval: NodeJS.Timeout | undefined = undefined\n// Here to wait until `ping` is sent to server so that connection is registered - temporary till client table and sessions are implemented.\nlet _pinged = false\n// TODO: allow creation of clients if the arguments are different. Will require changes in node.zig as well.\nexport function createClient (args: InitArgs): Client {\n const duplicateArgs = isSameArgs(args)\n if (!duplicateArgs && typeof _client !== 'undefined'){\n throw new Error('Client has already been initialized with different arguments.')\n }\n\n if (duplicateArgs && typeof _client !== 'undefined'){\n throw new Error('Client has already been initialized with the same arguments.')\n }\n\n _args = Object.assign({}, { ...args })\n const context = binding.init({\n ...args,\n replica_addresses: Buffer.from(args.replica_addresses.join(','))\n })\n\n const request = (operation: Operation, batch: Event[], callback: ResultCallback) => {\n binding.request(context, operation, batch, callback)\n }\n\n const rawRequest = (operation: Operation, rawBatch: Buffer, callback: ResultCallback) => {\n binding.raw_request(context, operation, rawBatch, callback)\n }\n\n const createAccounts = async (batch: Account[]): Promise<CreateAccountsError[]> => {\n // Here to wait until `ping` is sent to server so that connection is registered - temporary till client table and sessions are implemented.\n if (!_pinged) {\n await new Promise<void>(resolve => {\n setTimeout(() => {\n _pinged = true\n resolve()\n }, 600)\n })\n }\n return new Promise((resolve, reject) => {\n const callback = (error: undefined | Error, results: CreateAccountsError[]) => {\n if (error) {\n reject(error)\n return\n }\n resolve(results)\n }\n\n try {\n binding.request(context, Operation.CREATE_ACCOUNT, batch, callback)\n } catch (error) {\n reject(error)\n }\n })\n }\n\n const createTransfers = async (batch: Transfer[]): Promise<CreateTransfersError[]> => {\n // Here to wait until `ping` is sent to server so that connection is registered - temporary till client table and sessions are implemented.\n if (!_pinged) {\n await new Promise<void>(resolve => {\n setTimeout(() => {\n _pinged = true\n resolve()\n }, 600)\n })\n }\n return new Promise((resolve, reject) => {\n const callback = (error: undefined | Error, results: CreateTransfersError[]) => {\n if (error) {\n reject(error)\n return\n }\n resolve(results)\n }\n\n try {\n binding.request(context, Operation.CREATE_TRANSFER, batch, callback)\n } catch (error) {\n reject(error)\n }\n })\n }\n\n const lookupAccounts = async (batch: AccountID[]): Promise<Account[]> => {\n return new Promise((resolve, reject) => {\n const callback = (error: undefined | Error, results: Account[]) => {\n if (error) {\n reject(error)\n return\n }\n resolve(results)\n }\n\n try {\n binding.request(context, Operation.ACCOUNT_LOOKUP, batch, callback)\n } catch (error) {\n reject(error)\n }\n })\n }\n\n const lookupTransfers = async (batch: TransferID[]): Promise<Transfer[]> => {\n return new Promise((resolve, reject) => {\n const callback = (error: undefined | Error, results: Transfer[]) => {\n if (error) {\n reject(error)\n return\n }\n resolve(results)\n }\n\n try {\n binding.request(context, Operation.TRANSFER_LOOKUP, batch, callback)\n } catch (error) {\n reject(error)\n }\n })\n }\n\n const destroy = (): void => {\n binding.deinit(context)\n if (_interval){\n clearInterval(_interval)\n }\n _client = undefined\n }\n\n _client = {\n createAccounts,\n createTransfers,\n lookupAccounts,\n lookupTransfers,\n request,\n rawRequest,\n destroy\n }\n\n _interval = setInterval(() => {\n binding.tick(context)\n }, binding.tick_ms)\n\n return _client\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,SAAS,UAAU;IACjB,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAA;IAElC,MAAM,OAAO,GAAG;QACd,OAAO,EAAE,SAAS;QAClB,KAAK,EAAE,QAAQ;KAChB,CAAA;IAED,MAAM,WAAW,GAAG;QAClB,OAAO,EAAE,OAAO;QAChB,QAAQ,EAAE,OAAO;KAClB,CAAA;IAED,IAAI,CAAE,CAAC,IAAI,IAAI,OAAO,CAAC,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,EAAE,CAAC,CA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AAC,CAAC,CAAA;IACJ,CAAC,CAAA;IAED,MAAM,OAAO,GAAG,GAAS,EAAE;QACzB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QACvB,IAAI,SAAS,EAAC;YACZ,aAAa,CAAC,SAAS,CAAC,CAAA;SACzB;QACD,OAAO,GAAG,SAAS,CAAA;IACrB,CAAC,CAAA;IAED,OAAO,GAAG;QACR,cAAc;QACd,eAAe;QACf,cAAc;QACd,eAAe;QACf,OAAO;QACP,UAAU;QACV,OAAO;KACR,CAAA;IAED,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE;QAC3B,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACvB,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAEnB,OAAO,OAAO,CAAA;AAChB,CAAC;AAzID,oCAyIC","sourcesContent":["function getBinding (): Binding {\n const { arch, platform } = process\n\n const archMap = {\n \"arm64\": \"aarch64\",\n \"x64\": \"x86_64\"\n }\n\n const platformMap = {\n \"linux\": \"linux\",\n \"darwin\": \"macos\"\n }\n\n if (! (arch in archMap)) {\n throw new Error(`Unsupported arch: ${arch}`)\n }\n\n if (! (platform in platformMap)) {\n throw new Error(`Unsupported platform: ${platform}`)\n }\n\n let extra = ''\n\n /**\n * We need to detect during runtime which libc we're running on to load the correct NAPI.\n * binary.\n *\n * Rationale: The /proc/self/map_files/ subdirectory contains entries corresponding to\n * memory-mapped files loaded by Node.\n * https://man7.org/linux/man-pages/man5/proc.5.html: We detect a musl-based distro by\n * checking if any library contains the name \"musl\".\n *\n * Prior art: https://github.com/xerial/sqlite-jdbc/issues/623\n */\n\n const fs = require('fs')\n const path = require('path')\n\n if (platform === 'linux') {\n extra = '-gnu'\n\n for (const file of fs.readdirSync(\"/proc/self/map_files/\")) {\n const realPath = fs.readlinkSync(path.join(\"/proc/self/map_files/\", file))\n if (realPath.includes('musl')) {\n extra = '-musl'\n break\n }\n }\n }\n\n const filename = `./bin/${archMap[arch]}-${platformMap[platform]}${extra}/client.node`\n return require(filename)\n}\n\nconst binding = getBinding()\n\ninterface Binding {\n init: (args: BindingInitArgs) => Context\n request: (context: Context, operation: Operation, batch: Event[], result: ResultCallback) => void\n raw_request: (context: Context, operation: Operation, raw_batch: Buffer, result: ResultCallback) => void\n tick: (context: Context) => void,\n deinit: (context: Context) => void,\n tick_ms: number\n}\n\ninterface BindingInitArgs {\n cluster_id: number, // u32\n replica_addresses: Buffer,\n}\n\nexport interface InitArgs {\n cluster_id: number, // u32\n replica_addresses: Array<string | number>,\n}\n\nexport type Context = object\n\nexport type Account = {\n id: bigint // u128\n user_data: bigint // u128\n reserved: Buffer // [48]u8\n ledger: number // u32, ledger of value\n code: number // u16, A chart of accounts code describing the type of account (e.g. clearing, settlement)\n flags: number // u16\n debits_pending: bigint // u64\n debits_posted: bigint // u64\n credits_pending: bigint // u64\n credits_posted: bigint // u64\n timestamp: bigint // u64, Set this to 0n - the actual value will be set by TigerBeetle server\n}\n\nexport enum AccountFlags {\n linked = (1 << 0),\n debits_must_not_exceed_credits = (1 << 1),\n credits_must_not_exceed_debits = (1 << 2)\n}\n\nexport enum CreateAccountError {\n // ok = 0 (No Error)\n linked_event_failed = 1,\n linked_event_chain_open,\n timestamp_must_be_zero,\n\n reserved_flag,\n reserved_field,\n\n id_must_not_be_zero,\n id_must_not_be_int_max,\n\n flags_are_mutually_exclusive,\n\n ledger_must_not_be_zero,\n code_must_not_be_zero,\n debits_pending_must_be_zero,\n debits_posted_must_be_zero,\n credits_pending_must_be_zero,\n credits_posted_must_be_zero,\n\n exists_with_different_flags,\n exists_with_different_user_data,\n exists_with_different_ledger,\n exists_with_different_code,\n exists,\n}\n\nexport type CreateAccountsError = {\n index: number,\n code: CreateAccountError,\n}\n\nexport type Transfer = {\n id: bigint, // u128\n debit_account_id: bigint, // u128\n credit_account_id: bigint, // u128\n user_data: bigint, // u128\n reserved: bigint, // u128\n pending_id: bigint, // u128\n timeout: bigint, // u64, In nanoseconds.\n ledger: number // u32, The ledger of value.\n code: number, // u16, A user-defined accounting code to describe the type of transfer (e.g. settlement).\n flags: number, // u16\n amount: bigint, // u64,\n timestamp: bigint, // u64, Set this to 0n - the timestamp will be set by TigerBeetle.\n}\n\nexport enum TransferFlags {\n linked = (1 << 0),\n pending = (1 << 1),\n post_pending_transfer = (1 << 2),\n void_pending_transfer = (1 << 3),\n balancing_debit = (1 << 4),\n balancing_credit = (1 << 5),\n}\n\nexport enum CreateTransferError {\n // ok = 0 (No Error)\n linked_event_failed = 1,\n linked_event_chain_open,\n timestamp_must_be_zero,\n\n reserved_flag,\n reserved_field,\n\n id_must_not_be_zero,\n id_must_not_be_int_max,\n\n flags_are_mutually_exclusive,\n\n debit_account_id_must_not_be_zero,\n debit_account_id_must_not_be_int_max,\n credit_account_id_must_not_be_zero,\n credit_account_id_must_not_be_int_max,\n accounts_must_be_different,\n\n pending_id_must_be_zero,\n pending_id_must_not_be_zero,\n pending_id_must_not_be_int_max,\n pending_id_must_be_different,\n timeout_reserved_for_pending_transfer,\n\n ledger_must_not_be_zero,\n code_must_not_be_zero,\n amount_must_not_be_zero,\n\n debit_account_not_found,\n credit_account_not_found,\n\n accounts_must_have_the_same_ledger,\n transfer_must_have_the_same_ledger_as_accounts,\n\n pending_transfer_not_found,\n pending_transfer_not_pending,\n\n pending_transfer_has_different_debit_account_id,\n pending_transfer_has_different_credit_account_id,\n pending_transfer_has_different_ledger,\n pending_transfer_has_different_code,\n\n exceeds_pending_transfer_amount,\n pending_transfer_has_different_amount,\n\n pending_transfer_already_posted,\n pending_transfer_already_voided,\n\n pending_transfer_expired,\n\n exists_with_different_flags,\n exists_with_different_debit_account_id,\n exists_with_different_credit_account_id,\n exists_with_different_pending_id,\n exists_with_different_user_data,\n exists_with_different_timeout,\n exists_with_different_code,\n exists_with_different_amount,\n exists,\n\n overflows_debits_pending,\n overflows_credits_pending,\n overflows_debits_posted,\n overflows_credits_posted,\n overflows_debits,\n overflows_credits,\n overflows_timeout,\n\n exceeds_credits,\n exceeds_debits,\n}\n\nexport type CreateTransfersError = {\n index: number,\n code: CreateTransferError,\n}\n\nexport type AccountID = bigint // u128\nexport type TransferID = bigint // u128\n\nexport type Event = Account | Transfer | AccountID | TransferID\nexport type Result = CreateAccountsError | CreateTransfersError | Account | Transfer\nexport type ResultCallback = (error: undefined | Error, results: Result[]) => void\n\nexport enum Operation {\n CREATE_ACCOUNT = 3,\n CREATE_TRANSFER,\n ACCOUNT_LOOKUP,\n TRANSFER_LOOKUP\n}\n\nexport interface Client {\n createAccounts: (batch: Account[]) => Promise<CreateAccountsError[]>\n createTransfers: (batch: Transfer[]) => Promise<CreateTransfersError[]>\n lookupAccounts: (batch: AccountID[]) => Promise<Account[]>\n lookupTransfers: (batch: TransferID[]) => Promise<Transfer[]>\n request: (operation: Operation, batch: Event[], callback: ResultCallback) => void\n rawRequest: (operation: Operation, rawBatch: Buffer, callback: ResultCallback) => void\n destroy: () => void\n}\n\nlet _args: InitArgs | undefined = undefined\nconst isSameArgs = (args: InitArgs): boolean => {\n if (typeof _args === 'undefined') {\n return false\n }\n\n if (_args.replica_addresses.length !== args.replica_addresses.length) {\n return false\n }\n\n let isSameReplicas = true\n args.replica_addresses.forEach((entry, index) => {\n if (_args?.replica_addresses[index] !== entry) {\n isSameReplicas = false\n }\n })\n\n return args.cluster_id === _args.cluster_id && isSameReplicas\n}\n\nlet _client: Client | undefined = undefined\nlet _interval: NodeJS.Timeout | undefined = undefined\n// Here to wait until `ping` is sent to server so that connection is registered - temporary till client table and sessions are implemented.\nlet _pinged = false\n// TODO: allow creation of clients if the arguments are different. Will require changes in node.zig as well.\nexport function createClient (args: InitArgs): Client {\n const duplicateArgs = isSameArgs(args)\n if (!duplicateArgs && typeof _client !== 'undefined'){\n throw new Error('Client has already been initialized with different arguments.')\n }\n\n if (duplicateArgs && typeof _client !== 'undefined'){\n throw new Error('Client has already been initialized with the same arguments.')\n }\n\n _args = Object.assign({}, { ...args })\n const context = binding.init({\n ...args,\n replica_addresses: Buffer.from(args.replica_addresses.join(','))\n })\n\n const request = (operation: Operation, batch: Event[], callback: ResultCallback) => {\n binding.request(context, operation, batch, callback)\n }\n\n const rawRequest = (operation: Operation, rawBatch: Buffer, callback: ResultCallback) => {\n binding.raw_request(context, operation, rawBatch, callback)\n }\n\n const createAccounts = async (batch: Account[]): Promise<CreateAccountsError[]> => {\n // Here to wait until `ping` is sent to server so that connection is registered - temporary till client table and sessions are implemented.\n if (!_pinged) {\n await new Promise<void>(resolve => {\n setTimeout(() => {\n _pinged = true\n resolve()\n }, 600)\n })\n }\n return new Promise((resolve, reject) => {\n const callback = (error: undefined | Error, results: CreateAccountsError[]) => {\n if (error) {\n reject(error)\n return\n }\n resolve(results)\n }\n\n try {\n binding.request(context, Operation.CREATE_ACCOUNT, batch, callback)\n } catch (error) {\n reject(error)\n }\n })\n }\n\n const createTransfers = async (batch: Transfer[]): Promise<CreateTransfersError[]> => {\n // Here to wait until `ping` is sent to server so that connection is registered - temporary till client table and sessions are implemented.\n if (!_pinged) {\n await new Promise<void>(resolve => {\n setTimeout(() => {\n _pinged = true\n resolve()\n }, 600)\n })\n }\n return new Promise((resolve, reject) => {\n const callback = (error: undefined | Error, results: CreateTransfersError[]) => {\n if (error) {\n reject(error)\n return\n }\n resolve(results)\n }\n\n try {\n binding.request(context, Operation.CREATE_TRANSFER, batch, callback)\n } catch (error) {\n reject(error)\n }\n })\n }\n\n const lookupAccounts = async (batch: AccountID[]): Promise<Account[]> => {\n return new Promise((resolve, reject) => {\n const callback = (error: undefined | Error, results: Account[]) => {\n if (error) {\n reject(error)\n return\n }\n resolve(results)\n }\n\n try {\n binding.request(context, Operation.ACCOUNT_LOOKUP, batch, callback)\n } catch (error) {\n reject(error)\n }\n })\n }\n\n const lookupTransfers = async (batch: TransferID[]): Promise<Transfer[]> => {\n return new Promise((resolve, reject) => {\n const callback = (error: undefined | Error, results: Transfer[]) => {\n if (error) {\n reject(error)\n return\n }\n resolve(results)\n }\n\n try {\n binding.request(context, Operation.TRANSFER_LOOKUP, batch, callback)\n } catch (error) {\n reject(error)\n }\n })\n }\n\n const destroy = (): void => {\n binding.deinit(context)\n if (_interval){\n clearInterval(_interval)\n }\n _client = undefined\n }\n\n _client = {\n createAccounts,\n createTransfers,\n lookupAccounts,\n lookupTransfers,\n request,\n rawRequest,\n destroy\n }\n\n _interval = setInterval(() => {\n binding.tick(context)\n }, binding.tick_ms)\n\n return _client\n}\n"]}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -207,8 +207,8 @@ export enum CreateTransferError {
|
|
|
207
207
|
exists_with_different_flags,
|
|
208
208
|
exists_with_different_debit_account_id,
|
|
209
209
|
exists_with_different_credit_account_id,
|
|
210
|
-
exists_with_different_user_data,
|
|
211
210
|
exists_with_different_pending_id,
|
|
211
|
+
exists_with_different_user_data,
|
|
212
212
|
exists_with_different_timeout,
|
|
213
213
|
exists_with_different_code,
|
|
214
214
|
exists_with_different_amount,
|