koffi 3.0.0 → 3.0.2

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/CHANGELOG.md CHANGED
@@ -7,6 +7,25 @@
7
7
 
8
8
  ### Koffi 3.0
9
9
 
10
+ #### Koffi 3.0.2
11
+
12
+ *Released on 2026-05-26*
13
+
14
+ - Fix unexpected type error when passing array of pointers (see [Koromix/koffi#269](https://github.com/Koromix/koffi/issues/269))
15
+ - Search more native addons directories under process.resourcesPath
16
+ - Rearrange Koffi loading to use require() for static packages
17
+ - Fix error when using 'String' array hint with String32 type
18
+ - Add Buffer array hint to create Node Buffer objects
19
+ - Reduce overhead of various Koffi functions
20
+
21
+ #### Koffi 3.0.1
22
+
23
+ *Released on 2026-05-20*
24
+
25
+ - Fix error when importing default koffi module from TypeScript
26
+ - Optimize creation of new JS objects for return values
27
+ - Adjust build flags for performance
28
+
10
29
  #### Koffi 3.0.0
11
30
 
12
31
  *Released on 2026-05-16*
@@ -22,10 +41,10 @@
22
41
  * Use `koffi.type()` to resolve type specifiers (strings or objects) to type objects
23
42
  * Access type information directly on type objects without `koffi.introspect()`
24
43
  - Replace use of externals with BigInt pointers
25
- - Support ESM and CJS module types
26
44
 
27
45
  **Other changes:**
28
46
 
47
+ - Support ESM and CJS module types
29
48
  - Add `koffi.enumeration()` to create [enum types](input#enum-types)
30
49
  - Add fast decode functions for integers, floats and strings
31
50
  - Use proper types for various objects and handles:
package/README.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # Overview
2
2
 
3
- Koffi is a fast and easy-to-use C FFI module for Node.js, featuring:
3
+ Koffi is a fast and easy-to-use dynamic C FFI module for Node.js, featuring:
4
4
 
5
- * Low-overhead and fast performance (see [benchmarks](https://koffi.dev/benchmarks))
5
+ * Low-overhead compared to a static Node-API implementation (see [benchmarks](https://koffi.dev/benchmarks))
6
6
  * Support for primitive and aggregate data types (structs and fixed-size arrays), both by reference (pointer) and by value
7
+ * Support for synchronous and asynchronous calls
7
8
  * Javascript functions can be used as C callbacks
8
9
  * Well-tested code base for popular OS/architecture combinations
9
10
 
@@ -14,11 +15,11 @@ ISA / OS | Windows | Linux/glibc | Linux/musl | macOS | Fre
14
15
  x86 (IA32) [^1] | ✅ Yes | ✅ Yes | 🟨 Probably | ⬜️ *N/A* | ✅ Yes | ✅ Yes
15
16
  x86_64 (AMD64) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes
16
17
  ARM64 (AArch64) LE | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | 🟨 Probably
17
- RISC-V 64 [^3] | ⬜️ *N/A* | ✅ Yes | 🟨 Probably | ⬜️ *N/A* | 🟨 Probably | 🟨 Probably
18
+ RISC-V 64 [^2] | ⬜️ *N/A* | ✅ Yes | 🟨 Probably | ⬜️ *N/A* | 🟨 Probably | 🟨 Probably
18
19
  LoongArch64 | ⬜️ *N/A* | ✅ Yes | 🟨 Probably | ⬜️ *N/A* | 🟨 Probably | 🟨 Probably
19
20
 
20
21
  [^1]: The following call conventions are supported: cdecl, stdcall, MS fastcall, thiscall.
21
- [^3]: The prebuilt binary uses the LP64D (double-precision float) ABI. The LP64 ABI is supported in theory if you build Koffi from source but this is untested. The LP64F ABI is not supported.
22
+ [^2]: The prebuilt binary uses the LP64D (double-precision float) ABI. The LP64 ABI is supported in theory if you build Koffi from source but this is untested. The LP64F ABI is not supported.
22
23
 
23
24
  Go to the web site for more information: https://koffi.dev/
24
25
 
package/cnoke.cjs CHANGED
@@ -22,19 +22,19 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
22
  mod
23
23
  ));
24
24
 
25
- // ../cnoke/cnoke.js
25
+ // src/cnoke/cnoke.js
26
26
  var import_node_fs4 = __toESM(require("node:fs"), 1);
27
27
 
28
- // ../cnoke/src/builder.js
28
+ // src/cnoke/src/builder.js
29
29
  var import_node_fs3 = __toESM(require("node:fs"), 1);
30
30
  var import_node_os = __toESM(require("node:os"), 1);
31
31
  var import_node_path = __toESM(require("node:path"), 1);
32
32
  var import_node_child_process = require("node:child_process");
33
33
 
34
- // ../cnoke/src/abi.js
34
+ // src/cnoke/src/abi.js
35
35
  var import_node_fs = __toESM(require("node:fs"), 1);
36
36
  function determineAbi() {
37
- let abi = process.arch;
37
+ let abi = process.arch.toString();
38
38
  if (abi == "riscv32" || abi == "riscv64") {
39
39
  let buf = readFileHeader(process.execPath, 512);
40
40
  let header = decodeElfHeader(buf);
@@ -121,7 +121,7 @@ function decodeElfHeader(buf) {
121
121
  return header;
122
122
  }
123
123
 
124
- // ../cnoke/src/util.js
124
+ // src/cnoke/src/util.js
125
125
  var import_node_fs2 = __toESM(require("node:fs"), 1);
126
126
  function pathIsAbsolute(path2) {
127
127
  if (process.platform == "win32" && path2.match(/^[a-zA-Z]:/))
@@ -194,7 +194,7 @@ function compareVersions(ver1, ver2) {
194
194
  return cmp;
195
195
  }
196
196
 
197
- // ../cnoke/src/assets.js
197
+ // src/cnoke/src/assets.js
198
198
  var FIND_CNOKE_CMAKE = `# SPDX-License-Identifier: MIT
199
199
  # SPDX-FileCopyrightText: 2026 Niels Martign\xE8ne <niels.martignene@protonmail.com>
200
200
 
@@ -361,7 +361,7 @@ const PfnDliHook __pfnDliNotifyHook2 = self_exe_hook;
361
361
  #endif
362
362
  `;
363
363
 
364
- // ../cnoke/src/builder.js
364
+ // src/cnoke/src/builder.js
365
365
  var DefaultOptions = {
366
366
  mode: "RelWithDebInfo"
367
367
  };
@@ -586,9 +586,9 @@ function Builder(config = {}) {
586
586
  let major = parseInt(runtime_version, 10);
587
587
  let required = getNapiVersion(options2.napi, major);
588
588
  if (required == null)
589
- throw new Error(`Project ${options2.name} does not support the Node ${major}.x branch (old or missing N-API)`);
589
+ throw new Error(`Project ${options2.name} does not support the Node ${major}.x branch (old or missing Node-API)`);
590
590
  if (compareVersions(runtime_version, required) < 0)
591
- throw new Error(`Project ${options2.name} requires Node >= ${required} in the Node ${major}.x branch (with N-API >= ${options2.napi})`);
591
+ throw new Error(`Project ${options2.name} requires Node >= ${required} in the Node ${major}.x branch (with Node-API >= ${options2.napi})`);
592
592
  }
593
593
  }
594
594
  function readCNokeOptions() {
@@ -650,7 +650,7 @@ function Builder(config = {}) {
650
650
  }
651
651
  }
652
652
 
653
- // ../cnoke/cnoke.js
653
+ // src/cnoke/cnoke.js
654
654
  var VALID_COMMANDS = ["build", "configure", "clean"];
655
655
  main();
656
656
  async function main() {
package/doc/benchmarks.md CHANGED
@@ -1,86 +1,63 @@
1
1
  # Overview
2
2
 
3
- Here is a quick overview of the execution time of Koffi calls on three benchmarks, where it is compared to a theoretical ideal FFI implementation (approximated with pre-compiled static N-API glue code):
3
+ This pages presents the execution time of Koffi calls on three benchmarks, where it is compared to a theoretical ideal FFI implementation (approximated with pre-compiled static Node-API glue code), and other FFI implementations:
4
4
 
5
- - The first benchmark is based on `rand()` calls
6
- - The second benchmark is based on `atoi()` calls
7
- - The third benchmark is based on `memset()` calls
8
-
9
- <div class="benchmark chart" data-platform="linux_x64"></div>
10
- <div class="benchmark chart" data-platform="win32_x64"></div>
11
- <div class="benchmark chart" data-platform="darwin_arm64"></div>
12
-
13
- These results are detailed and explained below, and compared to node-ffi/node-ffi-napi.
5
+ - The first benchmark is based on `atoi()` calls
6
+ - The second benchmark is based on `memset()` calls
14
7
 
15
8
  # Linux x86_64
16
9
 
17
- The results presented below were measured on my x86_64 Linux machine (Intel® CoreUltra 9 185H).
18
-
19
- ## rand results
20
-
21
- This test is based around repeated calls to a simple standard C function `rand`, which takes no parameter and returns a 32-bit integer.
22
-
23
- <div class="benchmark table" data-platform="linux_x64" data-benchmark="rand"></div>
10
+ The results presented below were measured on my x86_64 Linux machine (AMD Ryzen5 2600).
24
11
 
25
- Because rand is a pretty small function, the FFI overhead is clearly visible.
12
+ <div class="benchmark chart" data-platform="linux_x64"></div>
26
13
 
27
- ## atoi results
14
+ ## atoi results for Linux x86_64 ^ atoi results
28
15
 
29
- This test is similar to the rand one, but it is based on `atoi`, which takes a string parameter. Javascript (V8) to C string conversion is relatively slow and heavy.
16
+ This test is based on `atoi`, which takes a string parameter. Javascript (V8) to C string conversion is relatively slow and heavy.
30
17
 
31
18
  <div class="benchmark table" data-platform="linux_x64" data-benchmark="atoi"></div>
32
19
 
33
- ## memset results
20
+ ## memset results for Linux x86_64 ^ memset results
34
21
 
35
22
  This test is based around repeated calls to the standard C function `memset`. All implementations pass a Node.js Buffer for the pointer argument.
36
23
 
37
24
  <div class="benchmark table" data-platform="linux_x64" data-benchmark="memset"></div>
38
25
 
39
- # Windows x86_64
40
-
41
- The results presented below were measured on my x86_64 Windows machine (Intel® Core™ i5-4460).
42
-
43
- ## rand results
26
+ # macOS ARM64
44
27
 
45
- This test is based around repeated calls to a simple standard C function `rand`, which takes no parameter and returns a 32-bit integer.
28
+ The results presented below were measured on an Apple Mac mini M2 hosted by Scaleway.
46
29
 
47
- <div class="benchmark table" data-platform="win32_x64" data-benchmark="rand"></div>
30
+ <div class="benchmark chart" data-platform="darwin_arm64"></div>
48
31
 
49
- ## atoi results
32
+ ## atoi results for macOS ARM64 ^ atoi results
50
33
 
51
- This test is similar to the rand one, but it is based on `atoi`, which takes a string parameter. Javascript (V8) to C string conversion is relatively slow and heavy.
34
+ This test is based on `atoi`, which takes a string parameter. Javascript (V8) to C string conversion is relatively slow and heavy.
52
35
 
53
- <div class="benchmark table" data-platform="win32_x64" data-benchmark="atoi"></div>
36
+ <div class="benchmark table" data-platform="darwin_arm64" data-benchmark="atoi"></div>
54
37
 
55
- ## memset results
38
+ ## memset results for macOS ARM64 ^ memset results
56
39
 
57
40
  This test is based around repeated calls to the standard C function `memset`. All implementations pass a Node.js Buffer for the pointer argument.
58
41
 
59
- <div class="benchmark table" data-platform="win32_x64" data-benchmark="memset"></div>
60
-
61
- # macOS ARM64
62
-
63
- The results presented below were measured on an Apple Mac mini M2 hosted by Scaleway.
64
-
65
- ## rand results
42
+ <div class="benchmark table" data-platform="darwin_arm64" data-benchmark="memset"></div>
66
43
 
67
- This test is based around repeated calls to a simple standard C function `rand`, which takes no parameter and returns a 32-bit integer.
44
+ # Windows x86_64
68
45
 
69
- <div class="benchmark table" data-platform="darwin_arm64" data-benchmark="rand"></div>
46
+ The results presented below were measured on my x86_64 Windows machine (AMD Ryzen™ 5 2600).
70
47
 
71
- Because rand is a pretty small function, the FFI overhead is clearly visible.
48
+ <div class="benchmark chart" data-platform="win32_x64"></div>
72
49
 
73
- ## atoi results
50
+ ## atoi results for Windows x86_64 ^ atoi results
74
51
 
75
- This test is similar to the rand one, but it is based on `atoi`, which takes a string parameter. Javascript (V8) to C string conversion is relatively slow and heavy.
52
+ This test is based on `atoi`, which takes a string parameter. Javascript (V8) to C string conversion is relatively slow and heavy.
76
53
 
77
- <div class="benchmark table" data-platform="darwin_arm64" data-benchmark="atoi"></div>
54
+ <div class="benchmark table" data-platform="win32_x64" data-benchmark="atoi"></div>
78
55
 
79
- ## memset results
56
+ ## memset results for Windows x86_64 ^ memset results
80
57
 
81
58
  This test is based around repeated calls to the standard C function `memset`. All implementations pass a Node.js Buffer for the pointer argument.
82
59
 
83
- <div class="benchmark table" data-platform="darwin_arm64" data-benchmark="memset"></div>
60
+ <div class="benchmark table" data-platform="win32_x64" data-benchmark="memset"></div>
84
61
 
85
62
  # Running benchmarks
86
63
 
package/doc/callbacks.md CHANGED
@@ -142,19 +142,10 @@ koffi.unregister(cb1);
142
142
  koffi.unregister(cb2);
143
143
  ```
144
144
 
145
- Starting *with Koffi 2.2*, you can optionally specify the `this` value for the function as the first argument.
146
-
147
- ```js
148
- class ValueStore {
149
- constructor(value) { this.value = value; }
150
- get() { return this.value; }
151
- }
152
-
153
- let store = new ValueStore(42);
154
-
155
- let cb1 = koffi.register(store.get, 'IntCallback *'); // If a C function calls cb1 it will fail because this will be undefined
156
- let cb2 = koffi.register(store, store.get, 'IntCallback *'); // However in this case, this will match the store object
157
- ```
145
+ > [!NOTE]
146
+ > In Koffi 2.x (starting with Koffi 2.2), you could bind a specific `this` value to the callback function, by giving an object as the first argument to `koffi.register()`.
147
+ >
148
+ > This feature has been deprecated in Koffi 3 and will eventually be removed. Replace with an explicit call to `function.bind()` instead.
158
149
 
159
150
  # Special considerations
160
151
 
package/doc/contribute.md CHANGED
@@ -6,7 +6,7 @@ Please note that the source code is not in this repository, instead it lives in
6
6
 
7
7
  # Build from source
8
8
 
9
- We provide prebuilt binaries, packaged in the NPM archive, so in most cases it should be as simple as `npm install koffi`. If you want to hack Koffi or use a specific platform, follow the instructions below.
9
+ We provide prebuilt binaries, packaged in NPM packages, so in most cases it should be as simple as `npm install koffi`. If you want to hack Koffi or use a specific platform, follow the instructions below.
10
10
 
11
11
  Start by cloning the repository with [Git](https://git-scm.com/):
12
12
 
@@ -25,7 +25,7 @@ First, make sure the following dependencies are met:
25
25
  - [CMake meta build system](https://cmake.org/)
26
26
  - [Node.js](https://nodejs.org/) 16 or later
27
27
 
28
- Once this is done, run this command _from the test or the benchmark directory_ (depending on what you want to build):
28
+ Once this is done, run this command from the _src/koffi_ directory:
29
29
 
30
30
  ```sh
31
31
  cd src/koffi
@@ -44,7 +44,7 @@ Make sure the following dependencies are met:
44
44
  - [CMake meta build system](https://cmake.org/)
45
45
  - [Node.js](https://nodejs.org/) 16 or later
46
46
 
47
- Once this is done, run this command _from the test or the benchmark directory_ (depending on what you want to build):
47
+ Once this is done, run this command from the _src/koffi_ directory:
48
48
 
49
49
  ```sh
50
50
  cd src/koffi
@@ -145,7 +145,7 @@ cd src/koffi
145
145
  node tools/brew.js test # If not done before
146
146
  node tools/brew.js build
147
147
 
148
- cd ../../bin/koffi/packages
148
+ cd ../../bin/Koffi/packages
149
149
 
150
150
  ./prepare.sh
151
151
  ./publish.sh
package/doc/index.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # Overview
2
2
 
3
- Koffi is a **fast and easy-to-use C FFI module for Node.js**, featuring:
3
+ Koffi is a **fast and easy-to-use dynamic C FFI module for Node.js**, featuring:
4
4
 
5
- * Low-overhead and fast performance (see [benchmarks](benchmarks))
5
+ * Low-overhead compared to a static Node-API implementation (see [benchmarks](benchmarks))
6
6
  * Support for primitive and aggregate data types (structs and fixed-size arrays), both by reference (pointer) and by value
7
+ * Support for synchronous and asynchronous calls
7
8
  * Javascript functions can be used as C callbacks
8
9
  * Well-tested code base for popular OS/architecture combinations
9
10
 
package/doc/migration.md CHANGED
@@ -1,3 +1,103 @@
1
+ # Koffi 2.x to 3.x
2
+
3
+ Most programs should work as-is with Koffi 3.x.
4
+
5
+ However, some changes could impact your code:
6
+
7
+ - Koffi is now distributed in [split packages](#split-packages) to reduce install size/bloat.
8
+ - Pointers are now [BigInt values](#bigint-pointers) instead of opaque V8 external values.
9
+ - Types created by koffi are now [type objects](#type-objects) insted of opaque V8 external values.
10
+ - Using `koffi.register()` with a [receiver value](#registered-callback-binding) is deprecated.
11
+ - Several old [deprecated functions](#removed-functions) have been removed.
12
+
13
+ ## Split packages
14
+
15
+ The main koffi package does not contain native code any longer. Instead, it depends on platform-specific packages (such as `@koromix/koffi-linux-x64`) for platform support, specified through `optionalDependencies`.
16
+
17
+ Your package manager should automatically install the binary package relevant to your platform. Importing koffi should work transparently, just as before.
18
+
19
+ However, if you redistribute software that uses Koffi, you will probably **need to change your packaging system** or configure your bundler differently.
20
+
21
+ ## BigInt pointers
22
+
23
+ For performance reasons, Koffi now uses BigInt numbers for pointers instead of V8 external objects.
24
+
25
+ Most code should work without any change, but there are two cases where this might impact you:
26
+
27
+ - If you use a **type system**, for example in TypeScript code (e.g. for parameters), you may need to accept BigInt values now if you pass pointer values around.
28
+ - BigInt pointers **do not carry the C type around**. In Koffi 2.x, trying to pass a pointer to an integer to a `void Myfunc(MyStruct *)` function would have triggerd an exception, but in Koffi 3.x this will "work" (and probably crash).
29
+
30
+ ## Type objects
31
+
32
+ Type functions, such as `koffi.struct()`, now create *TypeObject* objects, and type information is directly available without `koffi.introspect()`.
33
+
34
+ You can resolve type strings to type objects with `koffi.type()`. This function replaces `koffi.resolve()`, which is now a deprecated alias for `koffi.type()`.
35
+
36
+ > [!NOTE]
37
+ > For compatibility reasons, both `koffi.resolve()` and `koffi.introspect()` still exist, as aliases for `koffi.type()`. Using them will emit a deprecation warning.
38
+
39
+ Read the documentation about [type specifiers](migration#type-specifiers) for more information.
40
+
41
+ The two versions below illustrate the API difference between Koffi 2.x and Koffi 3.x:
42
+
43
+ ```js
44
+ // Koffi 2.x
45
+
46
+ const MyStruct = koffi.struct('MyStruct', {
47
+ a: 'int',
48
+ b: 'int'
49
+ });
50
+
51
+ console.log(koffi.introspect(MyStruct).members); // Prints MyStruct members
52
+ console.log(koffi.introspect('MyStruct').members); // Prints MyStruct members
53
+
54
+ console.log(koffi.introspect(koffi.types.int).alignment); // Prints MyStruct members
55
+ console.log(koffi.introspect('int').alignment); // Prints alignment of int type
56
+
57
+ // Koffi 3.x
58
+
59
+ const MyStruct = koffi.struct('MyStruct', {
60
+ a: 'int',
61
+ b: 'int'
62
+ });
63
+
64
+ console.log(MyStruct.members); // Prints MyStruct members
65
+ console.log(koffi.type('MyStruct').members); // Prints MyStruct members
66
+
67
+ console.log(koffi.types.int.alignment); // Prints alignment of int type
68
+ console.log(koffi.type('int').alignment); // Prints alignment of int type
69
+ ```
70
+
71
+ ## Registered callback binding
72
+
73
+ In Koffi 2.x, it was possible to bind a specific `this` value to the callback function when using `koffi.register()`, by passing an object as the first argument. This feature has been deprecated, it still works but will emit a warning.
74
+
75
+ You should replace these calls with an explicit call to the `bind()` method:
76
+
77
+ ```js
78
+ class ValueStore {
79
+ constructor(value) { this.value = value; }
80
+ get() { return this.value; }
81
+ }
82
+
83
+ let store = new ValueStore(42);
84
+
85
+ // Koffi 2.x
86
+
87
+ let cb = koffi.register(store, store.get, 'IntCallback *');
88
+
89
+ // Koffi 3.x
90
+
91
+ let cb = koffi.register(store.get.bind(store), 'IntCallback *');
92
+ ```
93
+
94
+ ## Removed functions
95
+
96
+ Two deprecated functions have been removed:
97
+
98
+ - `koffi.callback()`: if you still use it, replace with `koffi.proto()`.
99
+ - `koffi.handle()`: if you still use it, replace with `koffi.opaque()`.
100
+
1
101
  # Koffi 1.x to 2.x
2
102
 
3
103
  The API was changed in 2.x in a few ways, in order to reduce some excessively "magic" behavior and reduce the syntax differences between C and the C-like prototypes.
package/doc/start.md CHANGED
@@ -9,11 +9,11 @@ npm install koffi
9
9
  Once you have installed Koffi, you can start by loading it:
10
10
 
11
11
  ```js
12
- // CommonJS syntax
13
- const koffi = require('koffi');
14
-
15
12
  // ES6 modules
16
13
  import koffi from 'koffi';
14
+
15
+ // CommonJS syntax
16
+ const koffi = require('koffi');
17
17
  ```
18
18
 
19
19
  # Simple examples
@@ -112,7 +112,9 @@ Please read the [dedicated page](packaging) for information about bundling and p
112
112
 
113
113
  # Build manually
114
114
 
115
- Follow the [build instrutions](contribute#build-from-source) if you want to build the native Koffi code yourself.
115
+ Follow the [build instructions](contribute#build-from-source) if you want to build the native Koffi code yourself.
116
116
 
117
117
  > [!NOTE]
118
- > This is only needed if you want to hack on Koffi. The official NPM package provide prebuilt binaries and you don't need to compile anything if you only want to use Koffi in Node.js.
118
+ > This is only needed if you want to hack on Koffi. The official NPM package provides prebuilt binaries and you don't need to compile anything if you only want to use Koffi in Node.js.
119
+ >
120
+ > Just run `npm install koffi`!
package/index.d.ts CHANGED
@@ -5,7 +5,7 @@ type PrimitiveKind = 'Void' | 'Bool' | 'Int8' | 'UInt8' | 'Int16' | 'Int16S' | '
5
5
  'Int32' | 'Int32S' | 'UInt32' | 'UInt32S' | 'Int64' | 'Int64S' | 'UInt64' | 'UInt64S' |
6
6
  'String' | 'String16' | 'Pointer' | 'Record' | 'Union' | 'Array' | 'Float32' | 'Float64' |
7
7
  'Prototype' | 'Callback';
8
- type ArrayHint = 'Array' | 'Typed' | 'String';
8
+ type ArrayHint = 'Array' | 'Typed' | 'Buffer' | 'String';
9
9
 
10
10
  type PrototypeInfo = {
11
11
  name: string;
@@ -66,8 +66,6 @@ export type LibraryHandle = {
66
66
  symbol(name: string, type: TypeSpec): any;
67
67
 
68
68
  unload(): void;
69
-
70
- [Symbol.dispose](): void;
71
69
  };
72
70
 
73
71
  export function load(path: string | null, options?: LoadOptions): LibraryHandle;
@@ -313,10 +311,60 @@ export namespace node {
313
311
 
314
312
  unref(): void;
315
313
  ref(): void;
316
-
317
- [Symbol.dispose](): void;
318
314
  }
319
315
 
320
316
  export function poll(fd: number, opts: PollOptions, callback: (ev: PollEvents) => void): PollHandle;
321
317
  export function poll(fd: number, callback: (ev: PollEvents) => void): PollHandle;
322
318
  }
319
+
320
+ export const version: string;
321
+
322
+ // We want the same module with a default export and named exports.
323
+ // If someone knows a better way, feel free to help ;)
324
+
325
+ declare const DefaultObject: {
326
+ LibraryHandle: LibraryHandle;
327
+ TypeObject: TypeObject;
328
+ Union: Union;
329
+
330
+ address: typeof address;
331
+ alias: typeof alias;
332
+ alignof: typeof alignof;
333
+ alloc: typeof alloc;
334
+ array: typeof array;
335
+ as: typeof as;
336
+ call: typeof call;
337
+ config: typeof config;
338
+ decode: typeof decode;
339
+ disposable: typeof disposable;
340
+ encode: typeof encode;
341
+ enumeration: typeof enumeration;
342
+ errno: typeof errno;
343
+ extension: typeof extension;
344
+ free: typeof free;
345
+ inout: typeof inout;
346
+ introspect: typeof introspect;
347
+ load: typeof load;
348
+ node: typeof node;
349
+ offsetof: typeof offsetof;
350
+ opaque: typeof opaque;
351
+ os: typeof os;
352
+ out: typeof out;
353
+ pack: typeof pack;
354
+ pointer: typeof pointer;
355
+ proto: typeof proto;
356
+ register: typeof register;
357
+ reset: typeof reset;
358
+ resolve: typeof resolve;
359
+ sizeof: typeof sizeof;
360
+ stats: typeof stats;
361
+ struct: typeof struct;
362
+ type: typeof type;
363
+ types: typeof types;
364
+ union: typeof union;
365
+ unregister: typeof unregister;
366
+ version: typeof version;
367
+ view: typeof view;
368
+ }
369
+
370
+ export default DefaultObject;
package/index.js CHANGED
@@ -1 +1,2 @@
1
- export { default } from "./src/koffi/index.js";
1
+ export { default } from "./src/koffi/index.js";
2
+ export * from "./src/koffi/index.js";
package/indirect.js CHANGED
@@ -1 +1,2 @@
1
- export { default } from "./src/koffi/indirect.js";
1
+ export { default } from "./src/koffi/indirect.js";
2
+ export * from "./src/koffi/indirect.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koffi",
3
- "version": "3.0.0",
4
- "description": "Fast and simple C FFI (foreign function interface) for Node.js",
3
+ "version": "3.0.2",
4
+ "description": "Fast and easy-to-use dynamic C FFI (foreign function interface) for Node.js",
5
5
  "keywords": [
6
6
  "foreign",
7
7
  "function",
@@ -33,20 +33,20 @@
33
33
  },
34
34
  "funding": "https://liberapay.com/Koromix",
35
35
  "optionalDependencies": {
36
- "@koromix/koffi-linux-arm64": "3.0.0",
37
- "@koromix/koffi-linux-ia32": "3.0.0",
38
- "@koromix/koffi-linux-x64": "3.0.0",
39
- "@koromix/koffi-linux-riscv64": "3.0.0",
40
- "@koromix/koffi-freebsd-ia32": "3.0.0",
41
- "@koromix/koffi-freebsd-x64": "3.0.0",
42
- "@koromix/koffi-freebsd-arm64": "3.0.0",
43
- "@koromix/koffi-openbsd-ia32": "3.0.0",
44
- "@koromix/koffi-openbsd-x64": "3.0.0",
45
- "@koromix/koffi-win32-ia32": "3.0.0",
46
- "@koromix/koffi-win32-x64": "3.0.0",
47
- "@koromix/koffi-darwin-x64": "3.0.0",
48
- "@koromix/koffi-darwin-arm64": "3.0.0",
49
- "@koromix/koffi-linux-loong64": "3.0.0"
36
+ "@koromix/koffi-linux-arm64": "3.0.2",
37
+ "@koromix/koffi-linux-ia32": "3.0.2",
38
+ "@koromix/koffi-linux-x64": "3.0.2",
39
+ "@koromix/koffi-linux-riscv64": "3.0.2",
40
+ "@koromix/koffi-freebsd-ia32": "3.0.2",
41
+ "@koromix/koffi-freebsd-x64": "3.0.2",
42
+ "@koromix/koffi-freebsd-arm64": "3.0.2",
43
+ "@koromix/koffi-openbsd-ia32": "3.0.2",
44
+ "@koromix/koffi-openbsd-x64": "3.0.2",
45
+ "@koromix/koffi-win32-ia32": "3.0.2",
46
+ "@koromix/koffi-win32-x64": "3.0.2",
47
+ "@koromix/koffi-darwin-x64": "3.0.2",
48
+ "@koromix/koffi-darwin-arm64": "3.0.2",
49
+ "@koromix/koffi-linux-loong64": "3.0.2"
50
50
  },
51
51
  "type": "module",
52
52
  "main": "./index.cjs",
@@ -54,11 +54,13 @@
54
54
  "exports": {
55
55
  ".": {
56
56
  "import": "./index.js",
57
- "require": "./index.cjs"
57
+ "require": "./index.cjs",
58
+ "types": "./index.d.ts"
58
59
  },
59
60
  "./indirect": {
60
61
  "import": "./indirect.js",
61
- "require": "./indirect.cjs"
62
+ "require": "./indirect.cjs",
63
+ "types": "./index.d.ts"
62
64
  }
63
65
  },
64
66
  "types": "./index.d.ts"