1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(dead_code)]

use std::os::raw::{c_char, c_int, c_uint, c_void};

#[repr(C)]
#[derive(Copy, Clone)]
pub struct napi_env__ {
  _unused: [u8; 0],
}

/// Env ptr
pub type napi_env = *mut napi_env__;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct napi_value__ {
  _unused: [u8; 0],
}

/// JsValue ptr
pub type napi_value = *mut napi_value__;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct napi_ref__ {
  _unused: [u8; 0],
}
pub type napi_ref = *mut napi_ref__;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct napi_handle_scope__ {
  _unused: [u8; 0],
}
pub type napi_handle_scope = *mut napi_handle_scope__;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct napi_escapable_handle_scope__ {
  _unused: [u8; 0],
}
pub type napi_escapable_handle_scope = *mut napi_escapable_handle_scope__;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct napi_callback_info__ {
  _unused: [u8; 0],
}
pub type napi_callback_info = *mut napi_callback_info__;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct napi_deferred__ {
  _unused: [u8; 0],
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct uv_loop_s {
  _unused: [u8; 0],
}
#[repr(C)]
#[derive(Copy, Clone)]
pub enum uv_run_mode {
  UV_RUN_DEFAULT = 0,
  UV_RUN_ONCE = 1,
  UV_RUN_NOWAIT = 2,
}
pub type napi_deferred = *mut napi_deferred__;

pub type napi_property_attributes = i32;

pub mod PropertyAttributes {
  use super::napi_property_attributes;

  pub const default: napi_property_attributes = 0;
  pub const writable: napi_property_attributes = 1 << 0;
  pub const enumerable: napi_property_attributes = 1 << 1;
  pub const configurable: napi_property_attributes = 1 << 2;

  // Used with napi_define_class to distinguish static properties
  // from instance properties. Ignored by napi_define_properties.
  pub const static_: napi_property_attributes = 1 << 10;
}

pub type napi_valuetype = i32;

pub mod ValueType {
  pub const napi_undefined: i32 = 0;
  pub const napi_null: i32 = 1;
  pub const napi_boolean: i32 = 2;
  pub const napi_number: i32 = 3;
  pub const napi_string: i32 = 4;
  pub const napi_symbol: i32 = 5;
  pub const napi_object: i32 = 6;
  pub const napi_function: i32 = 7;
  pub const napi_external: i32 = 8;
  #[cfg(feature = "napi6")]
  pub const napi_bigint: i32 = 9;
}

pub type napi_typedarray_type = i32;

pub mod TypedarrayType {
  pub const int8_array: i32 = 0;
  pub const uint8_array: i32 = 1;
  pub const uint8_clamped_array: i32 = 2;
  pub const int16_array: i32 = 3;
  pub const uint16_array: i32 = 4;
  pub const int32_array: i32 = 5;
  pub const uint32_array: i32 = 6;
  pub const float32_array: i32 = 7;
  pub const float64_array: i32 = 8;
  #[cfg(feature = "napi6")]
  pub const bigint64_array: i32 = 9;
  #[cfg(feature = "napi6")]
  pub const biguint64_array: i32 = 10;
}

pub type napi_status = i32;

pub mod Status {
  pub const napi_ok: i32 = 0;
  pub const napi_invalid_arg: i32 = 1;
  pub const napi_object_expected: i32 = 2;
  pub const napi_string_expected: i32 = 3;
  pub const napi_name_expected: i32 = 4;
  pub const napi_function_expected: i32 = 5;
  pub const napi_number_expected: i32 = 6;
  pub const napi_boolean_expected: i32 = 7;
  pub const napi_array_expected: i32 = 8;
  pub const napi_generic_failure: i32 = 9;
  pub const napi_pending_exception: i32 = 10;
  pub const napi_cancelled: i32 = 11;
  pub const napi_escape_called_twice: i32 = 12;
  pub const napi_handle_scope_mismatch: i32 = 13;
  pub const napi_callback_scope_mismatch: i32 = 14;
  pub const napi_queue_full: i32 = 15;
  pub const napi_closing: i32 = 16;
  pub const napi_bigint_expected: i32 = 17;
  pub const napi_date_expected: i32 = 18;
  pub const napi_arraybuffer_expected: i32 = 19;
  pub const napi_detachable_arraybuffer_expected: i32 = 20;
  pub const napi_would_deadlock: i32 = 21; // unused
  pub const napi_no_external_buffers_allowed: i32 = 22;
}

pub type napi_callback =
  Option<unsafe extern "C" fn(env: napi_env, info: napi_callback_info) -> napi_value>;
pub type napi_finalize = Option<
  unsafe extern "C" fn(env: napi_env, finalize_data: *mut c_void, finalize_hint: *mut c_void),
>;
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct napi_property_descriptor {
  pub utf8name: *const c_char,
  pub name: napi_value,
  pub method: napi_callback,
  pub getter: napi_callback,
  pub setter: napi_callback,
  pub value: napi_value,
  pub attributes: napi_property_attributes,
  pub data: *mut c_void,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct napi_extended_error_info {
  pub error_message: *const c_char,
  pub engine_reserved: *mut c_void,
  pub engine_error_code: u32,
  pub error_code: napi_status,
}

#[cfg(feature = "napi6")]
pub type napi_key_collection_mode = i32;

#[cfg(feature = "napi6")]
pub mod KeyCollectionMode {
  pub use super::napi_key_collection_mode;
  pub const include_prototypes: napi_key_collection_mode = 0;
  pub const own_only: napi_key_collection_mode = 1;
}

#[cfg(feature = "napi6")]
pub type napi_key_filter = i32;

#[cfg(feature = "napi6")]
pub mod KeyFilter {
  use super::napi_key_filter;

  pub const all_properties: napi_key_filter = 0;
  pub const writable: napi_key_filter = 1;
  pub const enumerable: napi_key_filter = 1 << 1;
  pub const configurable: napi_key_filter = 1 << 2;
  pub const skip_strings: napi_key_filter = 1 << 3;
  pub const skip_symbols: napi_key_filter = 1 << 4;
}

#[cfg(feature = "napi6")]
pub type napi_key_conversion = i32;

#[cfg(feature = "napi6")]
pub mod KeyConversion {
  use super::napi_key_conversion;

  pub const keep_numbers: napi_key_conversion = 0;
  pub const numbers_to_strings: napi_key_conversion = 1;
}
#[cfg(feature = "napi8")]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct napi_async_cleanup_hook_handle__ {
  _unused: [u8; 0],
}
#[cfg(feature = "napi8")]
pub type napi_async_cleanup_hook_handle = *mut napi_async_cleanup_hook_handle__;
#[cfg(feature = "napi8")]
pub type napi_async_cleanup_hook =
  Option<unsafe extern "C" fn(handle: napi_async_cleanup_hook_handle, data: *mut c_void)>;

#[repr(C)]
#[derive(Copy, Clone)]
pub struct napi_callback_scope__ {
  _unused: [u8; 0],
}
pub type napi_callback_scope = *mut napi_callback_scope__;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct napi_async_context__ {
  _unused: [u8; 0],
}
pub type napi_async_context = *mut napi_async_context__;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct napi_async_work__ {
  _unused: [u8; 0],
}
pub type napi_async_work = *mut napi_async_work__;

#[cfg(feature = "napi4")]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct napi_threadsafe_function__ {
  _unused: [u8; 0],
}

#[cfg(feature = "napi4")]
pub type napi_threadsafe_function = *mut napi_threadsafe_function__;

#[cfg(feature = "napi4")]
pub type napi_threadsafe_function_release_mode = i32;

#[cfg(feature = "napi4")]
pub mod ThreadsafeFunctionReleaseMode {
  use super::napi_threadsafe_function_release_mode;
  pub const release: napi_threadsafe_function_release_mode = 0;
  pub const abort: napi_threadsafe_function_release_mode = 1;
}

#[cfg(feature = "napi4")]
pub type napi_threadsafe_function_call_mode = i32;

#[cfg(feature = "napi4")]
pub mod ThreadsafeFunctionCallMode {
  use super::napi_threadsafe_function_call_mode;

  pub const nonblocking: napi_threadsafe_function_call_mode = 0;
  pub const blocking: napi_threadsafe_function_call_mode = 1;
}

pub type napi_async_execute_callback =
  Option<unsafe extern "C" fn(env: napi_env, data: *mut c_void)>;
pub type napi_async_complete_callback =
  Option<unsafe extern "C" fn(env: napi_env, status: napi_status, data: *mut c_void)>;

#[cfg(feature = "napi4")]
pub type napi_threadsafe_function_call_js = Option<
  unsafe extern "C" fn(
    env: napi_env,
    js_callback: napi_value,
    context: *mut c_void,
    data: *mut c_void,
  ),
>;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct napi_node_version {
  pub major: u32,
  pub minor: u32,
  pub patch: u32,
  pub release: *const c_char,
}

pub type napi_addon_register_func =
  Option<unsafe extern "C" fn(env: napi_env, exports: napi_value) -> napi_value>;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct napi_module {
  pub nm_version: c_int,
  pub nm_flags: c_uint,
  pub nm_filename: *const c_char,
  pub nm_register_func: napi_addon_register_func,
  pub nm_modname: *const c_char,
  pub nm_priv: *mut c_void,
  pub reserved: [*mut c_void; 4usize],
}