tigerbeetle-node 0.13.98 → 0.13.100

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.
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tigerbeetle-node",
3
- "version": "0.13.98",
3
+ "version": "0.13.100",
4
4
  "description": "TigerBeetle Node.js client",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  "test": "node dist/test",
29
29
  "build": "npm run build_tsc && npm run build_lib",
30
30
  "build_tsc": "./node_modules/typescript/bin/tsc",
31
- "build_lib": "node scripts/windows_generate_node_lib.js && cd ../../.. && ./zig/zig build node_client -Drelease-safe",
31
+ "build_lib": "node scripts/windows_generate_node_lib.js && cd ../../.. && ./zig/zig build node_client -Doptimize=ReleaseSafe",
32
32
  "prepack": "npm run build && find dist/bin -name '*.o' -delete && for path in dist/bin/*; do mv ${path}/libtb_nodeclient.* ${path}/client.node; done",
33
33
  "clean": "rm -rf build dist node_modules src/zig-cache zig"
34
34
  },
package/src/node.zig CHANGED
@@ -24,8 +24,10 @@ const vsr = @import("../../../vsr.zig");
24
24
  const Header = vsr.Header;
25
25
  const Client = vsr.Client(StateMachine, MessageBus);
26
26
 
27
- // Since this is running in application space, log only critical messages to reduce noise.
28
- pub const log_level: std.log.Level = .err;
27
+ pub const std_options = struct {
28
+ // Since this is running in application space, log only critical messages to reduce noise.
29
+ pub const log_level: std.log.Level = .err;
30
+ };
29
31
 
30
32
  /// N-API will call this constructor automatically to register the module.
31
33
  export fn napi_register_module_v1(env: c.napi_env, exports: c.napi_value) c.napi_value {
@@ -57,7 +59,7 @@ export fn napi_register_module_v1(env: c.napi_env, exports: c.napi_value) c.napi
57
59
  // state.
58
60
  translate.set_instance_data(
59
61
  env,
60
- @ptrCast(*anyopaque, @alignCast(@alignOf(u8), global)),
62
+ @ptrCast(@alignCast(global)),
61
63
  Globals.destroy,
62
64
  ) catch {
63
65
  global.deinit();
@@ -115,7 +117,7 @@ const Globals = struct {
115
117
  };
116
118
 
117
119
  fn globalsCast(globals_raw: *anyopaque) *Globals {
118
- return @ptrCast(*Globals, @alignCast(@alignOf(Globals), globals_raw));
120
+ return @ptrCast(@alignCast(globals_raw));
119
121
  }
120
122
 
121
123
  const Context = struct {
@@ -147,7 +149,7 @@ const Context = struct {
147
149
  allocator,
148
150
  client_id,
149
151
  cluster,
150
- @intCast(u8, context.addresses.len),
152
+ @as(u8, @intCast(context.addresses.len)),
151
153
  &context.message_pool,
152
154
  .{
153
155
  .configuration = context.addresses,
@@ -161,7 +163,7 @@ const Context = struct {
161
163
  };
162
164
 
163
165
  fn contextCast(context_raw: *anyopaque) !*Context {
164
- return @ptrCast(*Context, @alignCast(@alignOf(Context), context_raw));
166
+ return @ptrCast(@alignCast(context_raw));
165
167
  }
166
168
 
167
169
  fn validate_timestamp(env: c.napi_env, object: c.napi_value) !u64 {
@@ -188,7 +190,7 @@ fn decode_from_object(comptime T: type, env: c.napi_env, object: c.napi_value) !
188
190
  .timeout = try translate.u64_from_object(env, object, "timeout"),
189
191
  .ledger = try translate.u32_from_object(env, object, "ledger"),
190
192
  .code = try translate.u16_from_object(env, object, "code"),
191
- .flags = @bitCast(TransferFlags, try translate.u16_from_object(env, object, "flags")),
193
+ .flags = @as(TransferFlags, @bitCast(try translate.u16_from_object(env, object, "flags"))),
192
194
  .amount = try translate.u64_from_object(env, object, "amount"),
193
195
  .timestamp = try validate_timestamp(env, object),
194
196
  },
@@ -198,7 +200,7 @@ fn decode_from_object(comptime T: type, env: c.napi_env, object: c.napi_value) !
198
200
  .reserved = try translate.bytes_from_object(env, object, 48, "reserved"),
199
201
  .ledger = try translate.u32_from_object(env, object, "ledger"),
200
202
  .code = try translate.u16_from_object(env, object, "code"),
201
- .flags = @bitCast(AccountFlags, try translate.u16_from_object(env, object, "flags")),
203
+ .flags = @as(AccountFlags, @bitCast(try translate.u16_from_object(env, object, "flags"))),
202
204
  .debits_pending = try translate.u64_from_object(env, object, "debits_pending"),
203
205
  .debits_posted = try translate.u64_from_object(env, object, "debits_posted"),
204
206
  .credits_pending = try translate.u64_from_object(env, object, "credits_pending"),
@@ -259,7 +261,7 @@ fn encode_napi_results_array(
259
261
  const results = std.mem.bytesAsSlice(Result, data);
260
262
  const napi_array = try translate.create_array(
261
263
  env,
262
- @intCast(u32, results.len),
264
+ @as(u32, @intCast(results.len)),
263
265
  "Failed to allocate array for results.",
264
266
  );
265
267
 
@@ -285,7 +287,7 @@ fn encode_napi_results_array(
285
287
  env,
286
288
  napi_object,
287
289
  "result",
288
- @enumToInt(result.result),
290
+ @intFromEnum(result.result),
289
291
  "Failed to set property \"result\" of result.",
290
292
  );
291
293
 
@@ -335,7 +337,7 @@ fn encode_napi_results_array(
335
337
  env,
336
338
  napi_object,
337
339
  "ledger",
338
- @intCast(u32, result.ledger),
340
+ @as(u32, @intCast(result.ledger)),
339
341
  "Failed to set property \"ledger\" of account lookup result.",
340
342
  );
341
343
 
@@ -343,7 +345,7 @@ fn encode_napi_results_array(
343
345
  env,
344
346
  napi_object,
345
347
  "code",
346
- @intCast(u16, result.code),
348
+ @as(u16, @intCast(result.code)),
347
349
  "Failed to set property \"code\" of account lookup result.",
348
350
  );
349
351
 
@@ -351,7 +353,7 @@ fn encode_napi_results_array(
351
353
  env,
352
354
  napi_object,
353
355
  "flags",
354
- @bitCast(u16, result.flags),
356
+ @as(u16, @bitCast(result.flags)),
355
357
  "Failed to set property \"flags\" of account lookup result.",
356
358
  );
357
359
 
@@ -473,7 +475,7 @@ fn encode_napi_results_array(
473
475
  env,
474
476
  napi_object,
475
477
  "ledger",
476
- @intCast(u32, result.ledger),
478
+ @as(u32, @intCast(result.ledger)),
477
479
  "Failed to set property \"ledger\" of transfer lookup result.",
478
480
  );
479
481
 
@@ -481,7 +483,7 @@ fn encode_napi_results_array(
481
483
  env,
482
484
  napi_object,
483
485
  "code",
484
- @intCast(u16, result.code),
486
+ @as(u16, @intCast(result.code)),
485
487
  "Failed to set property \"code\" of transfer lookup result.",
486
488
  );
487
489
 
@@ -489,7 +491,7 @@ fn encode_napi_results_array(
489
491
  env,
490
492
  napi_object,
491
493
  "flags",
492
- @bitCast(u16, result.flags),
494
+ @as(u16, @bitCast(result.flags)),
493
495
  "Failed to set property \"flags\" of transfer lookup result.",
494
496
  );
495
497
 
@@ -578,7 +580,7 @@ fn request(env: c.napi_env, info: c.napi_callback_info) callconv(.C) c.napi_valu
578
580
  const context = contextCast(context_raw.?) catch return null;
579
581
  const operation_int = translate.u32_from_value(env, argv[1], "operation") catch return null;
580
582
 
581
- if (!@intToEnum(vsr.Operation, operation_int).valid(StateMachine)) {
583
+ if (!@as(vsr.Operation, @enumFromInt(operation_int)).valid(StateMachine)) {
582
584
  translate.throw(env, "Unknown operation.") catch return null;
583
585
  }
584
586
 
@@ -591,7 +593,7 @@ fn request(env: c.napi_env, info: c.napi_callback_info) callconv(.C) c.napi_valu
591
593
  const message = context.client.get_message();
592
594
  defer context.client.unref(message);
593
595
 
594
- const operation = @intToEnum(Operation, @intCast(u8, operation_int));
596
+ const operation = @as(Operation, @enumFromInt(@as(u8, @intCast(operation_int))));
595
597
  const body_length = decode_events(
596
598
  env,
597
599
  argv[2],
@@ -605,7 +607,7 @@ fn request(env: c.napi_env, info: c.napi_callback_info) callconv(.C) c.napi_valu
605
607
  // free in order to avoid a leak. We therefore do this last to ensure we cannot fail after
606
608
  // taking this reference.
607
609
  const user_data = translate.user_data_from_value(env, argv[3]) catch return null;
608
- context.client.request(@bitCast(u128, user_data), on_result, operation, message, body_length);
610
+ context.client.request(@as(u128, @bitCast(user_data)), on_result, operation, message, body_length);
609
611
 
610
612
  return null;
611
613
  }
@@ -633,10 +635,10 @@ fn raw_request(env: c.napi_env, info: c.napi_callback_info) callconv(.C) c.napi_
633
635
  const context = contextCast(context_raw.?) catch return null;
634
636
  const operation_int = translate.u32_from_value(env, argv[1], "operation") catch return null;
635
637
 
636
- if (!@intToEnum(vsr.Operation, operation_int).valid(StateMachine)) {
638
+ if (!@as(vsr.Operation, @enumFromInt(operation_int)).valid(StateMachine)) {
637
639
  translate.throw(env, "Unknown operation.") catch return null;
638
640
  }
639
- const operation = @intToEnum(Operation, @intCast(u8, operation_int));
641
+ const operation = @as(Operation, @enumFromInt(@as(u8, @intCast(operation_int))));
640
642
 
641
643
  if (context.client.messages_available == 0) {
642
644
  translate.throw(
@@ -660,7 +662,7 @@ fn raw_request(env: c.napi_env, info: c.napi_callback_info) callconv(.C) c.napi_
660
662
  // free in order to avoid a leak. We therefore do this last to ensure we cannot fail after
661
663
  // taking this reference.
662
664
  const user_data = translate.user_data_from_value(env, argv[3]) catch return null;
663
- context.client.request(@bitCast(u128, user_data), on_result, operation, message, body_length);
665
+ context.client.request(@as(u128, @bitCast(user_data)), on_result, operation, message, body_length);
664
666
 
665
667
  return null;
666
668
  }
@@ -668,8 +670,8 @@ fn raw_request(env: c.napi_env, info: c.napi_callback_info) callconv(.C) c.napi_
668
670
  fn on_result(user_data: u128, operation: Operation, results: []const u8) void {
669
671
  // A reference to the user's JS callback was made in `request` or `raw_request`. This MUST be
670
672
  // cleaned up regardless of the result of this function.
671
- const env = @bitCast(translate.UserData, user_data).env;
672
- const callback_reference = @bitCast(translate.UserData, user_data).callback_reference;
673
+ const env = @as(translate.UserData, @bitCast(user_data)).env;
674
+ const callback_reference = @as(translate.UserData, @bitCast(user_data)).callback_reference;
673
675
  defer translate.delete_reference(env, callback_reference) catch {
674
676
  std.log.warn("on_result: Failed to delete reference to user's JS callback.", .{});
675
677
  };
package/src/translate.zig CHANGED
@@ -13,14 +13,14 @@ pub fn register_function(
13
13
  return throw(env, "Failed to create function " ++ name ++ "().");
14
14
  }
15
15
 
16
- if (c.napi_set_named_property(env, exports, @ptrCast([*c]const u8, 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, @ptrCast([*c]const u8, 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,
@@ -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, @ptrCast([*c]const u8, 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, @ptrCast([*c]const u8, 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, @ptrCast([*c]const u8, 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, @ptrCast([*c]const u8, 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, @ptrCast([*c]const u8, 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, @ptrCast([*c]const u8, 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, @ptrCast([*c]const u8, 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, @ptrCast([*c]const u8, 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, @ptrCast([*c]const u8, 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
  }