tigerbeetle-node 0.9.0 → 0.9.143

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +580 -179
  2. package/dist/benchmark.js +44 -36
  3. package/dist/benchmark.js.map +1 -1
  4. package/dist/bin/aarch64-linux-gnu/client.node +0 -0
  5. package/dist/bin/aarch64-linux-musl/client.node +0 -0
  6. package/dist/bin/aarch64-macos/client.node +0 -0
  7. package/dist/bin/x86_64-linux-gnu/client.node +0 -0
  8. package/dist/bin/x86_64-linux-musl/client.node +0 -0
  9. package/dist/bin/x86_64-macos/client.node +0 -0
  10. package/dist/bin/x86_64-windows/client.node +0 -0
  11. package/dist/bindings.d.ts +141 -0
  12. package/dist/bindings.js +112 -0
  13. package/dist/bindings.js.map +1 -0
  14. package/dist/index.d.ts +2 -125
  15. package/dist/index.js +51 -101
  16. package/dist/index.js.map +1 -1
  17. package/dist/test.js +68 -54
  18. package/dist/test.js.map +1 -1
  19. package/package-lock.json +26 -0
  20. package/package.json +13 -22
  21. package/src/benchmark.ts +58 -49
  22. package/src/bindings.ts +631 -0
  23. package/src/index.ts +71 -163
  24. package/src/node.zig +169 -148
  25. package/src/test.ts +71 -57
  26. package/src/translate.zig +19 -36
  27. package/scripts/download_node_headers.sh +0 -25
  28. package/src/tigerbeetle/scripts/benchmark.bat +0 -46
  29. package/src/tigerbeetle/scripts/benchmark.sh +0 -55
  30. package/src/tigerbeetle/scripts/install.sh +0 -6
  31. package/src/tigerbeetle/scripts/install_zig.bat +0 -109
  32. package/src/tigerbeetle/scripts/install_zig.sh +0 -84
  33. package/src/tigerbeetle/scripts/lint.zig +0 -199
  34. package/src/tigerbeetle/scripts/upgrade_ubuntu_kernel.sh +0 -39
  35. package/src/tigerbeetle/scripts/vopr.bat +0 -48
  36. package/src/tigerbeetle/scripts/vopr.sh +0 -33
  37. package/src/tigerbeetle/scripts/vr_state_enumerate +0 -46
  38. package/src/tigerbeetle/src/benchmark.zig +0 -290
  39. package/src/tigerbeetle/src/cli.zig +0 -244
  40. package/src/tigerbeetle/src/config.zig +0 -239
  41. package/src/tigerbeetle/src/demo.zig +0 -125
  42. package/src/tigerbeetle/src/demo_01_create_accounts.zig +0 -35
  43. package/src/tigerbeetle/src/demo_02_lookup_accounts.zig +0 -7
  44. package/src/tigerbeetle/src/demo_03_create_transfers.zig +0 -24
  45. package/src/tigerbeetle/src/demo_04_create_pending_transfers.zig +0 -61
  46. package/src/tigerbeetle/src/demo_05_post_pending_transfers.zig +0 -37
  47. package/src/tigerbeetle/src/demo_06_void_pending_transfers.zig +0 -24
  48. package/src/tigerbeetle/src/demo_07_lookup_transfers.zig +0 -7
  49. package/src/tigerbeetle/src/fifo.zig +0 -104
  50. package/src/tigerbeetle/src/io/benchmark.zig +0 -213
  51. package/src/tigerbeetle/src/io/darwin.zig +0 -793
  52. package/src/tigerbeetle/src/io/linux.zig +0 -1038
  53. package/src/tigerbeetle/src/io/test.zig +0 -643
  54. package/src/tigerbeetle/src/io/windows.zig +0 -1161
  55. package/src/tigerbeetle/src/io.zig +0 -34
  56. package/src/tigerbeetle/src/main.zig +0 -144
  57. package/src/tigerbeetle/src/message_bus.zig +0 -1000
  58. package/src/tigerbeetle/src/message_pool.zig +0 -142
  59. package/src/tigerbeetle/src/ring_buffer.zig +0 -289
  60. package/src/tigerbeetle/src/simulator.zig +0 -417
  61. package/src/tigerbeetle/src/state_machine.zig +0 -2470
  62. package/src/tigerbeetle/src/storage.zig +0 -308
  63. package/src/tigerbeetle/src/test/cluster.zig +0 -351
  64. package/src/tigerbeetle/src/test/message_bus.zig +0 -93
  65. package/src/tigerbeetle/src/test/network.zig +0 -179
  66. package/src/tigerbeetle/src/test/packet_simulator.zig +0 -387
  67. package/src/tigerbeetle/src/test/state_checker.zig +0 -145
  68. package/src/tigerbeetle/src/test/state_machine.zig +0 -76
  69. package/src/tigerbeetle/src/test/storage.zig +0 -438
  70. package/src/tigerbeetle/src/test/time.zig +0 -84
  71. package/src/tigerbeetle/src/tigerbeetle.zig +0 -222
  72. package/src/tigerbeetle/src/time.zig +0 -113
  73. package/src/tigerbeetle/src/unit_tests.zig +0 -14
  74. package/src/tigerbeetle/src/vsr/client.zig +0 -505
  75. package/src/tigerbeetle/src/vsr/clock.zig +0 -812
  76. package/src/tigerbeetle/src/vsr/journal.zig +0 -2293
  77. package/src/tigerbeetle/src/vsr/marzullo.zig +0 -309
  78. package/src/tigerbeetle/src/vsr/replica.zig +0 -5015
  79. package/src/tigerbeetle/src/vsr.zig +0 -1017
package/src/test.ts CHANGED
@@ -18,28 +18,32 @@ const Zeroed32Bytes = Buffer.alloc(32, 0)
18
18
  const Zeroed48Bytes = Buffer.alloc(48, 0)
19
19
  const accountA: Account = {
20
20
  id: 17n,
21
- user_data: 0n,
22
- reserved: Zeroed48Bytes,
23
- ledger: 1,
24
- code: 718,
25
- flags: 0,
26
21
  debits_pending: 0n,
27
22
  debits_posted: 0n,
28
23
  credits_pending: 0n,
29
- credits_posted: 0n,
24
+ credits_posted: 0n,
25
+ user_data_128: 0n,
26
+ user_data_64: 0n,
27
+ user_data_32: 0,
28
+ reserved: 0,
29
+ ledger: 1,
30
+ code: 718,
31
+ flags: 0,
30
32
  timestamp: 0n // this will be set correctly by the TigerBeetle server
31
33
  }
32
34
  const accountB: Account = {
33
35
  id: 19n,
34
- user_data: 0n,
35
- reserved: Zeroed48Bytes,
36
- ledger: 1,
37
- code: 719,
38
- flags: 0,
39
36
  debits_pending: 0n,
40
37
  debits_posted: 0n,
41
38
  credits_pending: 0n,
42
- credits_posted: 0n,
39
+ credits_posted: 0n,
40
+ user_data_128: 0n,
41
+ user_data_64: 0n,
42
+ user_data_32: 0,
43
+ reserved: 0,
44
+ ledger: 1,
45
+ code: 719,
46
+ flags: 0,
43
47
  timestamp: 0n // this will be set correctly by the TigerBeetle server
44
48
  }
45
49
 
@@ -71,7 +75,7 @@ test('can return error on account', async (): Promise<void> => {
71
75
  const errors = await client.createAccounts([accountA, accountB])
72
76
 
73
77
  assert.strictEqual(errors.length, 1)
74
- assert.deepStrictEqual(errors[0], { index: 0, code: CreateAccountError.exists })
78
+ assert.deepStrictEqual(errors[0], { index: 0, result: CreateAccountError.exists })
75
79
  })
76
80
 
77
81
  test('throws error if timestamp is not set to 0n on account', async (): Promise<void> => {
@@ -85,28 +89,30 @@ test('can lookup accounts', async (): Promise<void> => {
85
89
  assert.strictEqual(accounts.length, 2)
86
90
  const account1 = accounts[0]
87
91
  assert.strictEqual(account1.id, 17n)
88
- assert.ok(account1.reserved.equals(Zeroed48Bytes))
89
- assert.strictEqual(account1.user_data, 0n)
90
- assert.strictEqual(account1.code, 718)
91
- assert.strictEqual(account1.ledger, 1)
92
- assert.strictEqual(account1.flags, 0)
93
92
  assert.strictEqual(account1.credits_posted, 0n)
94
93
  assert.strictEqual(account1.credits_pending, 0n)
95
94
  assert.strictEqual(account1.debits_posted, 0n)
96
- assert.strictEqual(account1.debits_pending, 0n)
95
+ assert.strictEqual(account1.debits_pending, 0n)
96
+ assert.strictEqual(account1.user_data_128, 0n)
97
+ assert.strictEqual(account1.user_data_64, 0n)
98
+ assert.strictEqual(account1.user_data_32, 0)
99
+ assert.strictEqual(account1.code, 718)
100
+ assert.strictEqual(account1.ledger, 1)
101
+ assert.strictEqual(account1.flags, 0)
97
102
  assert.ok(account1.timestamp > 0n)
98
103
 
99
104
  const account2 = accounts[1]
100
105
  assert.strictEqual(account2.id, 19n)
101
- assert.ok(account2.reserved.equals(Zeroed48Bytes))
102
- assert.strictEqual(account2.user_data, 0n)
103
- assert.strictEqual(account2.code, 719)
104
- assert.strictEqual(account2.ledger, 1)
105
- assert.strictEqual(account2.flags, 0)
106
106
  assert.strictEqual(account2.credits_posted, 0n)
107
107
  assert.strictEqual(account2.credits_pending, 0n)
108
108
  assert.strictEqual(account2.debits_posted, 0n)
109
109
  assert.strictEqual(account2.debits_pending, 0n)
110
+ assert.strictEqual(account2.user_data_128, 0n)
111
+ assert.strictEqual(account2.user_data_64, 0n)
112
+ assert.strictEqual(account2.user_data_32, 0)
113
+ assert.strictEqual(account2.code, 719)
114
+ assert.strictEqual(account2.ledger, 1)
115
+ assert.strictEqual(account2.flags, 0)
110
116
  assert.ok(account2.timestamp > 0n)
111
117
  })
112
118
 
@@ -115,14 +121,15 @@ test('can create a transfer', async (): Promise<void> => {
115
121
  id: 1n,
116
122
  debit_account_id: accountB.id,
117
123
  credit_account_id: accountA.id,
118
- user_data: 0n,
119
- reserved: 0n,
124
+ amount: 100n,
125
+ user_data_128: 0n,
126
+ user_data_64: 0n,
127
+ user_data_32: 0,
120
128
  pending_id: 0n,
121
- timeout: 0n,
129
+ timeout: 0,
122
130
  ledger: 1,
123
131
  code: 1,
124
132
  flags: 0,
125
- amount: 100n,
126
133
  timestamp: 0n, // this will be set correctly by the TigerBeetle server
127
134
  }
128
135
 
@@ -149,14 +156,15 @@ test('can create a two-phase transfer', async (): Promise<void> => {
149
156
  id: 2n,
150
157
  debit_account_id: accountB.id,
151
158
  credit_account_id: accountA.id,
152
- user_data: 0n,
153
- reserved: 0n,
159
+ amount: 50n,
160
+ user_data_128: 0n,
161
+ user_data_64: 0n,
162
+ user_data_32: 0,
154
163
  pending_id: 0n,
155
- timeout: BigInt(2e9),
164
+ timeout: 2e9,
156
165
  ledger: 1,
157
166
  code: 1,
158
167
  flags,
159
- amount: 50n,
160
168
  timestamp: 0n, // this will be set correctly by the TigerBeetle server
161
169
  }
162
170
 
@@ -181,12 +189,13 @@ test('can create a two-phase transfer', async (): Promise<void> => {
181
189
  assert.strictEqual(transfers[0].id, 2n)
182
190
  assert.strictEqual(transfers[0].debit_account_id, accountB.id)
183
191
  assert.strictEqual(transfers[0].credit_account_id, accountA.id)
184
- assert.strictEqual(transfers[0].user_data, 0n)
185
- assert.notStrictEqual(transfers[0].reserved, Zeroed32Bytes)
192
+ assert.strictEqual(transfers[0].amount, 50n)
193
+ assert.strictEqual(transfers[0].user_data_128, 0n)
194
+ assert.strictEqual(transfers[0].user_data_64, 0n)
195
+ assert.strictEqual(transfers[0].user_data_32, 0)
186
196
  assert.strictEqual(transfers[0].timeout > 0, true)
187
197
  assert.strictEqual(transfers[0].code, 1)
188
198
  assert.strictEqual(transfers[0].flags, 2)
189
- assert.strictEqual(transfers[0].amount, 50n)
190
199
  assert.strictEqual(transfers[0].timestamp > 0, true)
191
200
  })
192
201
 
@@ -198,14 +207,15 @@ test('can post a two-phase transfer', async (): Promise<void> => {
198
207
  id: 3n,
199
208
  debit_account_id: BigInt(0),
200
209
  credit_account_id: BigInt(0),
201
- user_data: 0n,
202
- reserved: 0n,
210
+ amount: 0n,
211
+ user_data_128: 0n,
212
+ user_data_64: 0n,
213
+ user_data_32: 0,
203
214
  pending_id: 2n,// must match the id of the pending transfer
204
- timeout: 0n,
215
+ timeout: 0,
205
216
  ledger: 1,
206
217
  code: 1,
207
218
  flags: flags,
208
- amount: 0n,
209
219
  timestamp: 0n, // this will be set correctly by the TigerBeetle server
210
220
  }
211
221
 
@@ -231,14 +241,15 @@ test('can reject a two-phase transfer', async (): Promise<void> => {
231
241
  id: 4n,
232
242
  debit_account_id: accountB.id,
233
243
  credit_account_id: accountA.id,
234
- user_data: 0n,
235
- reserved: 0n,
244
+ amount: 50n,
245
+ user_data_128: 0n,
246
+ user_data_64: 0n,
247
+ user_data_32: 0,
236
248
  pending_id: 0n,
237
- timeout: BigInt(1e9),
249
+ timeout: 1e9,
238
250
  ledger: 1,
239
251
  code: 1,
240
252
  flags: TransferFlags.pending,
241
- amount: 50n,
242
253
  timestamp: 0n, // this will be set correctly by the TigerBeetle server
243
254
  }
244
255
  const transferErrors = await client.createTransfers([transfer])
@@ -249,14 +260,15 @@ test('can reject a two-phase transfer', async (): Promise<void> => {
249
260
  id: 5n,
250
261
  debit_account_id: BigInt(0),
251
262
  credit_account_id: BigInt(0),
252
- user_data: 0n,
253
- reserved: 0n,
263
+ amount: 0n,
264
+ user_data_128: 0n,
265
+ user_data_64: 0n,
266
+ user_data_32: 0,
254
267
  pending_id: 4n, // must match the id of the pending transfer
255
- timeout: 0n,
268
+ timeout: 0,
256
269
  ledger: 1,
257
270
  code: 1,
258
271
  flags: TransferFlags.void_pending_transfer,
259
- amount: 0n,
260
272
  timestamp: 0n, // this will be set correctly by the TigerBeetle server
261
273
  }
262
274
 
@@ -281,37 +293,39 @@ test('can link transfers', async (): Promise<void> => {
281
293
  id: 6n,
282
294
  debit_account_id: accountB.id,
283
295
  credit_account_id: accountA.id,
284
- user_data: 0n,
285
- reserved: 0n,
296
+ amount: 100n,
297
+ user_data_128: 0n,
298
+ user_data_64: 0n,
299
+ user_data_32: 0,
286
300
  pending_id: 0n,
287
- timeout: 0n,
301
+ timeout: 0,
288
302
  ledger: 1,
289
303
  code: 1,
290
304
  flags: TransferFlags.linked, // points to transfer2
291
- amount: 100n,
292
305
  timestamp: 0n, // will be set correctly by the TigerBeetle server
293
306
  }
294
307
  const transfer2: Transfer = {
295
308
  id: 6n,
296
309
  debit_account_id: accountB.id,
297
310
  credit_account_id: accountA.id,
298
- user_data: 0n,
299
- reserved: 0n,
311
+ amount: 100n,
312
+ user_data_128: 0n,
313
+ user_data_64: 0n,
314
+ user_data_32: 0,
300
315
  pending_id: 0n,
301
- timeout: 0n,
316
+ timeout: 0,
302
317
  ledger: 1,
303
318
  code: 1,
304
319
  // Does not have linked flag as it is the end of the chain.
305
320
  // This will also cause it to fail as this is now a duplicate with different flags
306
321
  flags: 0,
307
- amount: 100n,
308
322
  timestamp: 0n, // will be set correctly by the TigerBeetle server
309
323
  }
310
324
 
311
325
  const errors = await client.createTransfers([transfer1, transfer2])
312
326
  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 })
327
+ assert.deepStrictEqual(errors[0], { index: 0, result: CreateTransferError.linked_event_failed })
328
+ assert.deepStrictEqual(errors[1], { index: 1, result: CreateTransferError.exists_with_different_flags })
315
329
 
316
330
  const accounts = await client.lookupAccounts([accountA.id, accountB.id])
317
331
  assert.strictEqual(accounts.length, 2)
package/src/translate.zig CHANGED
@@ -6,21 +6,21 @@ pub fn register_function(
6
6
  env: c.napi_env,
7
7
  exports: c.napi_value,
8
8
  comptime name: [:0]const u8,
9
- function: fn (env: c.napi_env, info: c.napi_callback_info) callconv(.C) c.napi_value,
9
+ function: *const fn (env: c.napi_env, info: c.napi_callback_info) callconv(.C) c.napi_value,
10
10
  ) !void {
11
11
  var napi_function: c.napi_value = undefined;
12
12
  if (c.napi_create_function(env, null, 0, function, null, &napi_function) != c.napi_ok) {
13
13
  return throw(env, "Failed to create function " ++ name ++ "().");
14
14
  }
15
15
 
16
- if (c.napi_set_named_property(env, exports, name, napi_function) != c.napi_ok) {
16
+ if (c.napi_set_named_property(env, exports, @as([*c]const u8, @ptrCast(name)), napi_function) != c.napi_ok) {
17
17
  return throw(env, "Failed to add " ++ name ++ "() to exports.");
18
18
  }
19
19
  }
20
20
 
21
21
  const TranslationError = error{ExceptionThrown};
22
22
  pub fn throw(env: c.napi_env, comptime message: [:0]const u8) TranslationError {
23
- var result = c.napi_throw_error(env, null, message);
23
+ var result = c.napi_throw_error(env, null, @as([*c]const u8, @ptrCast(message)));
24
24
  switch (result) {
25
25
  c.napi_ok, c.napi_pending_exception => {},
26
26
  else => unreachable,
@@ -41,7 +41,7 @@ pub fn capture_undefined(env: c.napi_env) !c.napi_value {
41
41
  pub fn set_instance_data(
42
42
  env: c.napi_env,
43
43
  data: *anyopaque,
44
- finalize_callback: fn (env: c.napi_env, data: ?*anyopaque, hint: ?*anyopaque) callconv(.C) void,
44
+ finalize_callback: *const fn (env: c.napi_env, data: ?*anyopaque, hint: ?*anyopaque) callconv(.C) void,
45
45
  ) !void {
46
46
  if (c.napi_set_instance_data(env, data, finalize_callback, null) != c.napi_ok) {
47
47
  return throw(env, "Failed to initialize environment.");
@@ -70,7 +70,7 @@ pub fn value_external(
70
70
  return result;
71
71
  }
72
72
 
73
- pub const UserData = packed struct {
73
+ pub const UserData = extern struct {
74
74
  env: c.napi_env,
75
75
  callback_reference: c.napi_ref,
76
76
  };
@@ -110,7 +110,7 @@ pub fn slice_from_object(
110
110
  comptime key: [:0]const u8,
111
111
  ) ![]const u8 {
112
112
  var property: c.napi_value = undefined;
113
- if (c.napi_get_named_property(env, object, key, &property) != c.napi_ok) {
113
+ if (c.napi_get_named_property(env, object, @as([*c]const u8, @ptrCast(key)), &property) != c.napi_ok) {
114
114
  return throw(env, key ++ " must be defined");
115
115
  }
116
116
 
@@ -133,7 +133,7 @@ pub fn slice_from_value(
133
133
 
134
134
  if (data_length < 1) return throw(env, key ++ " must not be empty");
135
135
 
136
- return @ptrCast([*]u8, data.?)[0..data_length];
136
+ return @as([*]u8, @ptrCast(data.?))[0..data_length];
137
137
  }
138
138
 
139
139
  pub fn bytes_from_object(
@@ -143,7 +143,7 @@ pub fn bytes_from_object(
143
143
  comptime key: [:0]const u8,
144
144
  ) ![length]u8 {
145
145
  var property: c.napi_value = undefined;
146
- if (c.napi_get_named_property(env, object, key, &property) != c.napi_ok) {
146
+ if (c.napi_get_named_property(env, object, @as([*c]const u8, @ptrCast(key)), &property) != c.napi_ok) {
147
147
  return throw(env, key ++ " must be defined");
148
148
  }
149
149
 
@@ -181,7 +181,7 @@ pub fn bytes_from_buffer(
181
181
 
182
182
  pub fn u128_from_object(env: c.napi_env, object: c.napi_value, comptime key: [:0]const u8) !u128 {
183
183
  var property: c.napi_value = undefined;
184
- if (c.napi_get_named_property(env, object, key, &property) != c.napi_ok) {
184
+ if (c.napi_get_named_property(env, object, @as([*c]const u8, @ptrCast(key)), &property) != c.napi_ok) {
185
185
  return throw(env, key ++ " must be defined");
186
186
  }
187
187
 
@@ -190,7 +190,7 @@ pub fn u128_from_object(env: c.napi_env, object: c.napi_value, comptime key: [:0
190
190
 
191
191
  pub fn u64_from_object(env: c.napi_env, object: c.napi_value, comptime key: [:0]const u8) !u64 {
192
192
  var property: c.napi_value = undefined;
193
- if (c.napi_get_named_property(env, object, key, &property) != c.napi_ok) {
193
+ if (c.napi_get_named_property(env, object, @as([*c]const u8, @ptrCast(key)), &property) != c.napi_ok) {
194
194
  return throw(env, key ++ " must be defined");
195
195
  }
196
196
 
@@ -199,7 +199,7 @@ pub fn u64_from_object(env: c.napi_env, object: c.napi_value, comptime key: [:0]
199
199
 
200
200
  pub fn u32_from_object(env: c.napi_env, object: c.napi_value, comptime key: [:0]const u8) !u32 {
201
201
  var property: c.napi_value = undefined;
202
- if (c.napi_get_named_property(env, object, key, &property) != c.napi_ok) {
202
+ if (c.napi_get_named_property(env, object, @as([*c]const u8, @ptrCast(key)), &property) != c.napi_ok) {
203
203
  return throw(env, key ++ " must be defined");
204
204
  }
205
205
 
@@ -212,7 +212,7 @@ pub fn u16_from_object(env: c.napi_env, object: c.napi_value, comptime key: [:0]
212
212
  return throw(env, key ++ " must be a u16.");
213
213
  }
214
214
 
215
- return @intCast(u16, result);
215
+ return @as(u16, @intCast(result));
216
216
  }
217
217
 
218
218
  pub fn u128_from_value(env: c.napi_env, value: c.napi_value, comptime name: [:0]const u8) !u128 {
@@ -222,7 +222,7 @@ pub fn u128_from_value(env: c.napi_env, value: c.napi_value, comptime name: [:0]
222
222
  // we would need to convert, but big endian is not supported by tigerbeetle.
223
223
  var result: u128 = 0;
224
224
  var sign_bit: c_int = undefined;
225
- const words = @ptrCast(*[2]u64, &result);
225
+ const words = @as(*[2]u64, @ptrCast(&result));
226
226
  var word_count: usize = 2;
227
227
  switch (c.napi_get_value_bigint_words(env, value, &sign_bit, &word_count, words)) {
228
228
  c.napi_ok => {},
@@ -274,7 +274,7 @@ pub fn byte_slice_into_object(
274
274
  return throw(env, error_message ++ " Failed to allocate Buffer in V8.");
275
275
  }
276
276
 
277
- if (c.napi_set_named_property(env, object, key, result) != c.napi_ok) {
277
+ if (c.napi_set_named_property(env, object, @as([*c]const u8, @ptrCast(key)), result) != c.napi_ok) {
278
278
  return throw(env, error_message);
279
279
  }
280
280
  }
@@ -295,13 +295,13 @@ pub fn u128_into_object(
295
295
  env,
296
296
  0,
297
297
  2,
298
- @ptrCast(*const [2]u64, &value),
298
+ @as(*const [2]u64, @ptrCast(&value)),
299
299
  &bigint,
300
300
  ) != c.napi_ok) {
301
301
  return throw(env, error_message);
302
302
  }
303
303
 
304
- if (c.napi_set_named_property(env, object, key, bigint) != c.napi_ok) {
304
+ if (c.napi_set_named_property(env, object, @as([*c]const u8, @ptrCast(key)), bigint) != c.napi_ok) {
305
305
  return throw(env, error_message);
306
306
  }
307
307
  }
@@ -318,7 +318,7 @@ pub fn u64_into_object(
318
318
  return throw(env, error_message);
319
319
  }
320
320
 
321
- if (c.napi_set_named_property(env, object, key, result) != c.napi_ok) {
321
+ if (c.napi_set_named_property(env, object, @as([*c]const u8, @ptrCast(key)), result) != c.napi_ok) {
322
322
  return throw(env, error_message);
323
323
  }
324
324
  }
@@ -335,7 +335,7 @@ pub fn u32_into_object(
335
335
  return throw(env, error_message);
336
336
  }
337
337
 
338
- if (c.napi_set_named_property(env, object, key, result) != c.napi_ok) {
338
+ if (c.napi_set_named_property(env, object, @as([*c]const u8, @ptrCast(key)), result) != c.napi_ok) {
339
339
  return throw(env, error_message);
340
340
  }
341
341
  }
@@ -370,7 +370,7 @@ fn create_buffer(
370
370
  return throw(env, error_message);
371
371
  }
372
372
 
373
- std.mem.copy(u8, @ptrCast([*]u8, data.?)[0..value.len], value[0..value.len]);
373
+ std.mem.copy(u8, @as([*]u8, @ptrCast(data.?))[0..value.len], value[0..value.len]);
374
374
 
375
375
  return result;
376
376
  }
@@ -426,23 +426,6 @@ pub fn delete_reference(env: c.napi_env, reference: c.napi_ref) !void {
426
426
  }
427
427
  }
428
428
 
429
- pub fn create_error(
430
- env: c.napi_env,
431
- comptime message: [:0]const u8,
432
- ) TranslationError!c.napi_value {
433
- var napi_string: c.napi_value = undefined;
434
- if (c.napi_create_string_utf8(env, message, std.mem.len(message), &napi_string) != c.napi_ok) {
435
- return TranslationError.ExceptionThrown;
436
- }
437
-
438
- var napi_error: c.napi_value = undefined;
439
- if (c.napi_create_error(env, null, napi_string, &napi_error) != c.napi_ok) {
440
- return TranslationError.ExceptionThrown;
441
- }
442
-
443
- return napi_error;
444
- }
445
-
446
429
  pub fn call_function(
447
430
  env: c.napi_env,
448
431
  this: c.napi_value,
@@ -1,25 +0,0 @@
1
- #!/bin/bash
2
- set -e
3
-
4
- # Ask node for headers
5
- HEADERS_URL=$(node -p 'process.release.headersUrl')
6
-
7
- # Work out the filename from the URL, as well as the directory without the ".tar.gz" file extension:
8
- rm -rf ./build
9
- mkdir build
10
- HEADERS_TARBALL=./build/`basename "$HEADERS_URL"`
11
-
12
- # Download, making sure we download to the same output document, without wget adding "-1" etc. if the file was previously partially downloaded:
13
- echo "Downloading $HEADERS_URL..."
14
- if command -v wget &> /dev/null; then
15
- # -4 forces `wget` to connect to ipv4 addresses, as ipv6 fails to resolve on certain distros.
16
- # Only A records (for ipv4) are used in DNS:
17
- wget -4 --quiet --show-progress --output-document=$HEADERS_TARBALL $HEADERS_URL
18
- else
19
- curl --silent --progress-bar --output $HEADERS_TARBALL $HEADERS_URL
20
- fi
21
-
22
- # Extract and then remove the downloaded tarball:
23
- echo "Extracting $HEADERS_TARBALL..."
24
- tar -xf $HEADERS_TARBALL -C ./build
25
- rm $HEADERS_TARBALL
@@ -1,46 +0,0 @@
1
- @echo off
2
- setlocal enabledelayedexpansion
3
-
4
- if "%~1" equ ":main" (
5
- shift /1
6
- goto main
7
- )
8
-
9
- cmd /d /c "%~f0" :main %*
10
- set ZIG_RESULT=%ERRORLEVEL%
11
- taskkill /F /IM tigerbeetle.exe >nul
12
-
13
- if !ZIG_RESULT! equ 0 (
14
- del /f benchmark.log
15
- ) else (
16
- echo.
17
- echo Error running benchmark, here are more details
18
- type benchmark.log
19
- )
20
-
21
- echo.
22
- exit /b
23
-
24
- :main
25
- zig\zig.exe build -Drelease-safe
26
- move zig-out\bin\tigerbeetle.exe . >nul
27
-
28
- for /l %%i in (0, 1, 0) do (
29
- echo Initializing replica %%i
30
- set ZIG_FILE=.\cluster_0000000000_replica_00%%i.tigerbeetle
31
- if exist "!ZIG_FILE!" DEL /F "!ZIG_FILE!"
32
- .\tigerbeetle.exe init --directory=. --cluster=0 --replica=%%i > benchmark.log 2>&1
33
- )
34
-
35
- for /l %%i in (0, 1, 0) do (
36
- echo Starting replica %%i
37
- start /B "tigerbeetle_%%i" .\tigerbeetle.exe start --directory=. --cluster=0 --addresses=3001 --replica=%%i > benchmark.log 2>&1
38
- )
39
-
40
- rem Wait for replicas to start, listen and connect:
41
- timeout /t 2
42
-
43
- echo.
44
- echo Benchmarking...
45
- zig\zig.exe run -OReleaseSafe src\benchmark.zig
46
- exit /b %errorlevel%
@@ -1,55 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -e
3
-
4
- # Install Zig if it does not already exist:
5
- if [ ! -d "zig" ]; then
6
- scripts/install_zig.sh
7
- fi
8
-
9
- COLOR_RED='\033[1;31m'
10
- COLOR_END='\033[0m'
11
-
12
- zig/zig build -Drelease-safe
13
- mv zig-out/bin/tigerbeetle .
14
-
15
- function onerror {
16
- if [ "$?" == "0" ]; then
17
- rm benchmark.log
18
- else
19
- echo -e "${COLOR_RED}"
20
- echo "Error running benchmark, here are more details (from benchmark.log):"
21
- echo -e "${COLOR_END}"
22
- cat benchmark.log
23
- fi
24
-
25
- for I in 0
26
- do
27
- echo "Stopping replica $I..."
28
- done
29
- kill %1
30
- }
31
- trap onerror EXIT
32
-
33
- for I in 0
34
- do
35
- echo "Initializing replica $I..."
36
- FILE="./cluster_0000000000_replica_00${I}.tigerbeetle"
37
- if [ -f $FILE ]; then
38
- rm $FILE
39
- fi
40
- ./tigerbeetle init --directory=. --cluster=0 --replica=$I > benchmark.log 2>&1
41
- done
42
-
43
- for I in 0
44
- do
45
- echo "Starting replica $I..."
46
- ./tigerbeetle start --directory=. --cluster=0 --addresses=3001 --replica=$I > benchmark.log 2>&1 &
47
- done
48
-
49
- # Wait for replicas to start, listen and connect:
50
- sleep 1
51
-
52
- echo ""
53
- echo "Benchmarking..."
54
- zig/zig run -OReleaseSafe src/benchmark.zig
55
- echo ""
@@ -1,6 +0,0 @@
1
- #!/bin/bash
2
- set -e
3
- scripts/install_zig.sh
4
- echo "Building TigerBeetle..."
5
- zig/zig build -Dcpu=baseline -Drelease-safe
6
- mv zig-out/bin/tigerbeetle .
@@ -1,109 +0,0 @@
1
- @echo off
2
-
3
- set ZIG_RELEASE_DEFAULT=0.9.1
4
-
5
- :: Determine the Zig build:
6
- if "%~1"=="" (
7
- set ZIG_RELEASE=%ZIG_RELEASE_DEFAULT%
8
- ) else if "%~1"=="latest" (
9
- set ZIG_RELEASE=builds
10
- ) else (
11
- set ZIG_RELEASE=%~1
12
- )
13
-
14
- :: Checks format of release version.
15
- echo.%ZIG_RELEASE% | findstr /b /r /c:"builds" /c:"^[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*">nul || (echo.Unexpected release format. && exit 1)
16
-
17
- set ZIG_OS=windows
18
- set ZIG_ARCH=x86_64
19
-
20
- set ZIG_TARGET=zig-%ZIG_OS%-%ZIG_ARCH%
21
-
22
- :: Determine the build, split the JSON line on whitespace and extract the 2nd field:
23
- for /f "tokens=2" %%a in ('curl --silent https://ziglang.org/download/index.json ^| findstr %ZIG_TARGET% ^| findstr %ZIG_RELEASE%' ) do (
24
- set ZIG_URL=%%a
25
- )
26
-
27
- :: Then remove quotes and commas:
28
- for /f %%b in ("%ZIG_URL:,=%") do (
29
- set ZIG_URL=%%~b
30
- )
31
-
32
- :: Checks the ZIG_URL variable follows the expected format.
33
- echo.%ZIG_URL% | findstr /b /r /c:"https://ziglang.org/builds/" /c:"https://ziglang.org/download/%ZIG_RELEASE%">nul || (echo.Unexpected release URL format. && exit 1)
34
-
35
- if "%ZIG_RELEASE%"=="builds" (
36
- echo Installing Zig latest build...
37
- ) else (
38
- echo Installing Zig %ZIG_RELEASE% release build...
39
- )
40
-
41
- :: Using variable modifiers to determine the directory and filename from the URL:
42
- :: %%~ni Expands %%i to a file name only and %%~xi Expands %%i to a file name extension only.
43
- for /f %%i in ("%ZIG_URL%") do (
44
- set ZIG_DIRECTORY=%%~ni
45
- set ZIG_TARBALL=%%~nxi
46
- )
47
-
48
- :: Checks the ZIG_DIRECTORY variable follows the expected format.
49
- echo.%ZIG_DIRECTORY% | findstr /b /r /c:"zig-win64-" /c:"zig-windows-x86_64-">nul || (echo.Unexpected zip directory name format. && exit 1)
50
-
51
- :: Making sure we download to the same output document, without wget adding "-1" etc. if the file was previously partially downloaded:
52
- if exist %ZIG_TARBALL% (
53
- del /q %ZIG_TARBALL%
54
- if exist %ZIG_TARBALL% (
55
- echo Failed to delete %ZIG_TARBALL%.
56
- exit 1
57
- )
58
- )
59
-
60
- echo Downloading %ZIG_URL%...
61
- curl --silent --progress-bar --output %ZIG_TARBALL% %ZIG_URL%
62
- if not exist %ZIG_TARBALL% (
63
- echo Failed to download Zig zip file.
64
- exit 1
65
- )
66
-
67
- :: Replace any existing Zig installation so that we can install or upgrade:
68
- echo Removing any existing 'zig' and %ZIG_DIRECTORY% folders before extracting.
69
- if exist zig\ (
70
- rd /s /q zig\
71
- :: Ensure the directory has been deleted.
72
- if exist zig\ (
73
- echo The ‘zig’ directory could not be deleted.
74
- exit 1
75
- )
76
- )
77
-
78
- if exist %ZIG_DIRECTORY%\ (
79
- rd /s /q %ZIG_DIRECTORY%
80
- :: Ensure the directory has been deleted.
81
- if exist %ZIG_DIRECTORY% (
82
- echo The %ZIG_DIRECTORY% directory could not be deleted.
83
- exit 1
84
- )
85
- )
86
-
87
- :: Extract and then remove the downloaded tarball:
88
- echo Extracting %ZIG_TARBALL%...
89
- powershell -Command "Expand-Archive %ZIG_TARBALL% -DestinationPath ."
90
- if not exist %ZIG_TARBALL% (
91
- echo Failed to extract zip file.
92
- exit 1
93
- )
94
-
95
- echo Installing %ZIG_DIRECTORY% to 'zig' in current working directory...
96
- ren %ZIG_DIRECTORY% zig
97
- if exist %ZIG_DIRECTORY% (
98
- echo Failed to rename %ZIG_DIRECTORY% to zig.
99
- exit 1
100
- )
101
-
102
- :: Removes the zip file
103
- del /q %ZIG_TARBALL%
104
- if exist %ZIG_TARBALL% (
105
- echo Failed to delete %ZIG_TARBALL% file.
106
- exit 1
107
- )
108
-
109
- echo "Congratulations, you have successfully installed Zig version %ZIG_RELEASE%. Enjoy!"