koffi 2.3.0-beta.2 → 2.3.0

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 (35) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/doc/callbacks.md +4 -2
  3. package/doc/calls.md +1 -1
  4. package/package.json +3 -2
  5. package/src/koffi/build/2.3.0/koffi_darwin_arm64.tar.gz +0 -0
  6. package/src/koffi/build/2.3.0/koffi_darwin_x64.tar.gz +0 -0
  7. package/src/koffi/build/2.3.0/koffi_freebsd_arm64.tar.gz +0 -0
  8. package/src/koffi/build/2.3.0/koffi_freebsd_ia32.tar.gz +0 -0
  9. package/src/koffi/build/2.3.0/koffi_freebsd_x64.tar.gz +0 -0
  10. package/src/koffi/build/2.3.0/koffi_linux_arm32hf.tar.gz +0 -0
  11. package/src/koffi/build/2.3.0/koffi_linux_arm64.tar.gz +0 -0
  12. package/src/koffi/build/2.3.0/koffi_linux_ia32.tar.gz +0 -0
  13. package/src/koffi/build/2.3.0/koffi_linux_riscv64hf64.tar.gz +0 -0
  14. package/src/koffi/build/2.3.0/koffi_linux_x64.tar.gz +0 -0
  15. package/src/koffi/build/2.3.0/koffi_openbsd_ia32.tar.gz +0 -0
  16. package/src/koffi/build/2.3.0/koffi_openbsd_x64.tar.gz +0 -0
  17. package/src/koffi/build/2.3.0/koffi_win32_arm64.tar.gz +0 -0
  18. package/src/koffi/build/2.3.0/koffi_win32_ia32.tar.gz +0 -0
  19. package/src/koffi/build/2.3.0/koffi_win32_x64.tar.gz +0 -0
  20. package/src/koffi/src/index.d.ts +96 -0
  21. package/src/koffi/build/2.3.0-beta.2/koffi_darwin_arm64.tar.gz +0 -0
  22. package/src/koffi/build/2.3.0-beta.2/koffi_darwin_x64.tar.gz +0 -0
  23. package/src/koffi/build/2.3.0-beta.2/koffi_freebsd_arm64.tar.gz +0 -0
  24. package/src/koffi/build/2.3.0-beta.2/koffi_freebsd_ia32.tar.gz +0 -0
  25. package/src/koffi/build/2.3.0-beta.2/koffi_freebsd_x64.tar.gz +0 -0
  26. package/src/koffi/build/2.3.0-beta.2/koffi_linux_arm32hf.tar.gz +0 -0
  27. package/src/koffi/build/2.3.0-beta.2/koffi_linux_arm64.tar.gz +0 -0
  28. package/src/koffi/build/2.3.0-beta.2/koffi_linux_ia32.tar.gz +0 -0
  29. package/src/koffi/build/2.3.0-beta.2/koffi_linux_riscv64hf64.tar.gz +0 -0
  30. package/src/koffi/build/2.3.0-beta.2/koffi_linux_x64.tar.gz +0 -0
  31. package/src/koffi/build/2.3.0-beta.2/koffi_openbsd_ia32.tar.gz +0 -0
  32. package/src/koffi/build/2.3.0-beta.2/koffi_openbsd_x64.tar.gz +0 -0
  33. package/src/koffi/build/2.3.0-beta.2/koffi_win32_arm64.tar.gz +0 -0
  34. package/src/koffi/build/2.3.0-beta.2/koffi_win32_ia32.tar.gz +0 -0
  35. package/src/koffi/build/2.3.0-beta.2/koffi_win32_x64.tar.gz +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  ## Version history
4
4
 
5
+ ### Koffi 2.3
6
+
7
+ #### Koffi 2.3.0
8
+
9
+ **Main changes:**
10
+
11
+ - Allow buffers (TypedArray or ArrayBuffer) values for input and/or output pointer arguments (for polymorphic arguments)
12
+ - Support opaque buffers (TypedArray or ArrayBuffer) values in `koffi.decode()` to [decode output buffers](calls.md#output-parameters)
13
+ - Decode non-string types as arrays when an [explicit length is passed to koffi.decode()](callbacks.md#pointer-arguments)
14
+
15
+ **Other changes:**
16
+
17
+ - Drop TypedArray type check for array and pointer values (only the size matters)
18
+ - Allow ArrayBuffer everywhere TypedArray is supported
19
+ - Add TypeScript definition for Koffi ([@insraq](https://github.com/insraq))
20
+ - Improve documentation about opaque and polymorphic structs
21
+ - Improve documentation for `koffi.decode()`
22
+ - Reduce NPM package size (from 100 MB to 25 MB) by removing test code and dependencies
23
+
5
24
  ### Koffi 2.2
6
25
 
7
26
  #### Koffi 2.2.5
package/doc/callbacks.md CHANGED
@@ -134,7 +134,9 @@ let cb1 = koffi.register(store.get, 'IntCallback *'); // If a C function calls c
134
134
  let cb2 = koffi.register(store, store.get, 'IntCallback *'); // However in this case, this will match the store object
135
135
  ```
136
136
 
137
- ## Pointer arguments
137
+ ## Special considerations
138
+
139
+ ### Decoding pointer arguments
138
140
 
139
141
  *New in Koffi 2.2, changed in Koffi 2.3*
140
142
 
@@ -177,7 +179,7 @@ There is also an optional ending `length` argument that you can use in two cases
177
179
  In Koffi 2.2 and earlier versions, the length argument is only used to decode strings and is ignored otherwise.
178
180
  ```
179
181
 
180
- ## Asynchronous callbacks
182
+ ### Asynchronous callbacks
181
183
 
182
184
  *New in Koffi 2.2.2*
183
185
 
package/doc/calls.md CHANGED
@@ -261,7 +261,7 @@ console.log(vec1); // { x: 3, y: 2, z: 1 }
261
261
  console.log(vec2); // { x: 1, y: 2, z: 3 }
262
262
  ```
263
263
 
264
- See [pointer arguments](callbacks.md#pointer-arguments) for more information about the decode function.
264
+ See [pointer arguments](callbacks.md#decoding-pointer-arguments) for more information about the decode function.
265
265
 
266
266
  ## Heap-allocated values
267
267
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koffi",
3
- "version": "2.3.0-beta.2",
4
- "stable": "2.2.5",
3
+ "version": "2.3.0",
4
+ "stable": "2.3.0",
5
5
  "description": "Fast and simple C FFI (foreign function interface) for Node.js",
6
6
  "keywords": [
7
7
  "foreign",
@@ -19,6 +19,7 @@
19
19
  "homepage": "https://koffi.dev/",
20
20
  "author": "Niels Martignène <niels.martignene@protonmail.com>",
21
21
  "main": "src/koffi/src/index.js",
22
+ "types": "src/koffi/src/index.d.ts",
22
23
  "scripts": {
23
24
  "install": "cnoke --prebuild -d src/koffi"
24
25
  },
@@ -0,0 +1,96 @@
1
+ // This program is free software: you can redistribute it and/or modify
2
+ // it under the terms of the GNU Lesser General Public License as published by
3
+ // the Free Software Foundation, either version 3 of the License, or
4
+ // (at your option) any later version.
5
+ //
6
+ // This program is distributed in the hope that it will be useful,
7
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
8
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
+ // GNU Lesser General Public License for more details.
10
+ //
11
+ // You should have received a copy of the GNU Lesser General Public License
12
+ // along with this program. If not, see https://www.gnu.org/licenses/.
13
+
14
+ declare module 'koffi' {
15
+ export function load(path: string): IKoffiLib;
16
+
17
+ interface IKoffiCType { __brand: 'IKoffiCType' }
18
+ interface IKoffiPointerCast { __brand: 'IKoffiPointerCast' }
19
+ interface IKoffiRegisteredCallback { __brand: 'IKoffiRegisteredCallback' }
20
+
21
+ type TypeSpec = string | IKoffiCType;
22
+ type TypeSpecWithAlignment = TypeSpec | [number, TypeSpec];
23
+ type TypeInfo = {
24
+ name: string,
25
+ primitive: string,
26
+ size: number,
27
+ alignment: number,
28
+ length: number,
29
+ ref: IKoffiCType,
30
+ members: Record<string, { name: string, type: {}, offset: number }>
31
+ };
32
+ type KoffiFunction = Function | { async: Function };
33
+
34
+ export interface IKoffiLib {
35
+ func(definition: string): KoffiFunction;
36
+ func(name: string, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
37
+
38
+ cdecl(definition: string): KoffiFunction;
39
+ cdecl(name: string, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
40
+
41
+ stdcall(definition: string): KoffiFunction;
42
+ stdcall(name: string, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
43
+
44
+ fastcall(definition: string): KoffiFunction;
45
+ fastcall(name: string, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
46
+
47
+ thiscall(definition: string): KoffiFunction;
48
+ thiscall(name: string, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
49
+ }
50
+
51
+ export function struct(name: string, def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
52
+ export function struct(def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
53
+
54
+ export function pack(name: string, def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
55
+ export function pack(def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
56
+
57
+ export function opaque(name: string): IKoffiCType;
58
+ export function opaque(): IKoffiCType;
59
+
60
+ export function pointer(value: TypeSpec): IKoffiCType;
61
+ export function pointer(value: TypeSpec, asteriskCount: number): IKoffiCType;
62
+ export function pointer(name: string, value: TypeSpec, asteriskCount: number): IKoffiCType;
63
+
64
+ export function out(value: TypeSpec): IKoffiCType;
65
+ export function inout(value: TypeSpec): IKoffiCType;
66
+
67
+ export function as(value: {}, type: TypeSpec): IKoffiPointerCast;
68
+
69
+ export function disposable(type: TypeSpec): IKoffiCType;
70
+ export function disposable(name: string, type: TypeSpec): IKoffiCType;
71
+ export function disposable(name: string, type: TypeSpec, freeFunction: Function): IKoffiCType;
72
+
73
+ export function callback(definition: string): IKoffiCType;
74
+ export function callback(name: string, result: TypeSpec, arguments: TypeSpec[]): IKoffiCType;
75
+
76
+ interface IKoffiRegisteredCallback { __brand: 'IKoffiRegisteredCallback' }
77
+ export function register(callback: Function, type: TypeSpec): IKoffiRegisteredCallback;
78
+ export function register(thisValue: any, callback: Function, type: TypeSpec): IKoffiRegisteredCallback;
79
+ export function unregister(callback: IKoffiRegisteredCallback): void;
80
+
81
+ export function decode(value: {}, type: TypeSpec): {};
82
+ export function decode(value: {}, type: TypeSpec, len: number): {};
83
+ export function decode(value: {}, offset: number, type: TypeSpec): {};
84
+ export function decode(value: {}, offset: number, type: TypeSpec, len: number): {};
85
+
86
+ export function sizeof(type: TypeSpec): number;
87
+ export function alignof(type: TypeSpec): number;
88
+ export function offsetof(type: TypeSpec): number;
89
+ export function resolve(type: TypeSpec): IKoffiCType;
90
+ export function introspect(type: TypeSpec): TypeInfo;
91
+
92
+ export function alias(name: string, type: TypeSpec): IKoffiCType;
93
+
94
+ export function config(): {}
95
+ export function config({}): {}
96
+ }