koffi-cream 2.13.0 → 2.14.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 (3) hide show
  1. package/README.md +9 -8
  2. package/index.d.ts +38 -13
  3. package/package.json +14 -14
package/README.md CHANGED
@@ -12,7 +12,7 @@ const some_func = lib.func('int some_func(int a, int b)')
12
12
  ```
13
13
 
14
14
  > [!IMPORTANT]
15
- > **This package is neither a fork nor a patch. It *is* the original Koffi**, only packaged differently to avoid downloading a megalithic[^1] package bloated with unnecessary files[^2].
15
+ > **This package is neither a fork nor a patch. It *is* the original Koffi**, only packaged differently to avoid downloading a megalithic[^1] package bloated with files unnecessary to the average user[^2].
16
16
 
17
17
 
18
18
  ## The why and the how
@@ -21,20 +21,20 @@ The discussion at https://github.com/Koromix/koffi/issues/201 explains why I dec
21
21
  `koffi-cream` repackages Koffi using the same strategy as many popular packages in the JavaScript community like `esbuild` or `swc`: by leveraging the `optionalDependencies`, `os`, `cpu` and `libc` properties in `package.json`.
22
22
 
23
23
  This way, when you install `koffi-cream`, your package manager will only download and install the build that is right for your platform. For example, on Windows AMD/Intel 64 bit, your package manager will install:
24
- - `koffi-cream` (this package): 3.4 kB compressed / 12.8 kB uncompressed
25
- - `@septh/koffi-win32-x64`: 455 kB compressed / 2.3 MB uncompressed
24
+ - `koffi-cream` (this package): 5.1 kB compressed / 19.8 kB uncompressed
25
+ - `@septh/koffi-win32-x64`: 536.2 kB compressed / 2.4 MB uncompressed
26
26
 
27
- **That's 97% off compared to the original Koffi package!**
27
+ **That's 97.2% off compared to the original Koffi package!**
28
28
 
29
29
  > [!NOTE]
30
30
  > The `os` and `cpu` are standard properties, supported by all package managers. But the `libc` property, used to distinguish Linux distros between gnu and musl, is newer and only supported by `npm 10.4.0` and later, `pnpm 7.1.0` and later, and `yarn 3.2.0` and later.
31
31
 
32
- [^1]: As of 2.11.0, Koffi weights 15 MB compressed and 75 MB uncompressed!
33
- [^2]: Koffi's package includes 17 natives binaries (of which 16 are not compatible with your platform), the build tools and the full source code!
32
+ [^1]: As of 2.14.0, Koffi weights 16.9 MB compressed and 86 MB uncompressed.
33
+ [^2]: Koffi's package includes 18 natives binaries (of which 17 are not compatible with your platform), the build tools and the full source code.
34
34
 
35
35
 
36
36
  ## Available packages
37
- `koffi-cream` only offers a subset of Koffi's 17 native builds:
37
+ `koffi-cream` only offers a subset of Koffi's 18 native builds:
38
38
 
39
39
  | Koffi binary | koffi-cream package |
40
40
  |---------------|--------------------------------------------------------------------------------------------|
@@ -43,12 +43,13 @@ This way, when you install `koffi-cream`, your package manager will only downloa
43
43
  | freebsd-arm64 | [@septh/koffi-freebsd-arm64](https://www.npmjs.com/package/@septh/koffi-freebsd-arm64) |
44
44
  | freebsd-ia32 | ❌ |
45
45
  | freebsd-x64 | [@septh/koffi-freebsd-x64](https://www.npmjs.com/package/@septh/koffi-freebsd-x64) |
46
- | linux-arm64 | [@septh/koffi-linux-arm64](https://www.npmjs.com/package/@septh/koffi-linux-arm64) |
46
+ | linux-arm64 | [@septh/koffi-linux-arm64-glibc](https://www.npmjs.com/package/@septh/koffi-linux-arm64) |
47
47
  | linux-armhf | ❌ |
48
48
  | linux-ia32 | ❌ |
49
49
  | linux-loong64 | [@septh/koffi-linux-loong64](https://www.npmjs.com/package/@septh/koffi-linux-loong64) |
50
50
  | linux-riscv64 | [@septh/koffi-linux-riscv64](https://www.npmjs.com/package/@septh/koffi-linux-riscv64) |
51
51
  | linux-x64 | [@septh/koffi-linux-x64-glibc](https://www.npmjs.com/package/@septh/koffi-linux-x64-glibc) |
52
+ | musl-arm64 | [@septh/koffi-linux-arm64-musl](https://www.npmjs.com/package/@septh/koffi-linux-arm64) |
52
53
  | musl-x64 | [@septh/koffi-linux-x64-musl](https://www.npmjs.com/package/@septh/koffi-linux-x64-musl) |
53
54
  | openbsd-ia32 | ❌ |
54
55
  | openbsd-x64 | [@septh/koffi-openbsd-x64](https://www.npmjs.com/package/@septh/koffi-openbsd-x64) |
package/index.d.ts CHANGED
@@ -19,7 +19,13 @@
19
19
  // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
20
  // OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- export function load(path: string | null): IKoffiLib;
22
+ type LoadOptions = {
23
+ lazy?: boolean,
24
+ global?: boolean,
25
+ deep?: boolean
26
+ };
27
+
28
+ export function load(path: string | null, options?: LoadOptions): IKoffiLib;
23
29
 
24
30
  interface IKoffiCType { __brand: 'IKoffiCType' }
25
31
  interface IKoffiPointerCast { __brand: 'IKoffiPointerCast' }
@@ -65,17 +71,17 @@ export type KoffiFunc<T extends (...args: any) => any> = T & {
65
71
 
66
72
  export interface IKoffiLib {
67
73
  func(definition: string): KoffiFunction;
68
- func(name: string, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
69
- func(convention: string, name: string, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
74
+ func(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
75
+ func(convention: string, name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
70
76
 
71
77
  /** @deprecated */ cdecl(definition: string): KoffiFunction;
72
- /** @deprecated */ cdecl(name: string, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
78
+ /** @deprecated */ cdecl(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
73
79
  /** @deprecated */ stdcall(definition: string): KoffiFunction;
74
- /** @deprecated */ stdcall(name: string, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
80
+ /** @deprecated */ stdcall(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
75
81
  /** @deprecated */ fastcall(definition: string): KoffiFunction;
76
- /** @deprecated */ fastcall(name: string, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
82
+ /** @deprecated */ fastcall(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
77
83
  /** @deprecated */ thiscall(definition: string): KoffiFunction;
78
- /** @deprecated */ thiscall(name: string, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
84
+ /** @deprecated */ thiscall(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
79
85
 
80
86
  symbol(name: string, type: TypeSpec): any;
81
87
 
@@ -99,6 +105,7 @@ export class Union {
99
105
  }
100
106
 
101
107
  export function array(ref: TypeSpec, len: number, hint?: ArrayHint | null): IKoffiCType;
108
+ export function array(ref: TypeSpec, countedBy: string, maxLen: number, hint?: ArrayHint | null): IKoffiCType;
102
109
 
103
110
  export function opaque(name: string | null | undefined): IKoffiCType;
104
111
  export function opaque(): IKoffiCType;
@@ -107,7 +114,7 @@ export function opaque(): IKoffiCType;
107
114
 
108
115
  export function pointer(ref: TypeSpec): IKoffiCType;
109
116
  export function pointer(ref: TypeSpec, count: number): IKoffiCType;
110
- export function pointer(name: string | null | undefined, ref: TypeSpec): IKoffiCType;
117
+ export function pointer(name: string | null | undefined, ref: TypeSpec, countedBy?: string | null): IKoffiCType;
111
118
  export function pointer(name: string | null | undefined, ref: TypeSpec, count: number): IKoffiCType;
112
119
 
113
120
  export function out(type: TypeSpec): IKoffiCType;
@@ -155,9 +162,22 @@ export function introspect(type: TypeSpec): TypeInfo;
155
162
 
156
163
  export function alias(name: string, type: TypeSpec): IKoffiCType;
157
164
 
158
- export function config(): Record<string, unknown>;
159
- export function config(cfg: Record<string, unknown>): Record<string, unknown>;
160
- export function stats(): Record<string, unknown>;
165
+ type KoffiConfig = {
166
+ sync_stack_size: number
167
+ sync_heap_size: number
168
+ async_stack_size: number
169
+ async_heap_size: number
170
+ resident_async_pools: number
171
+ max_async_calls: number
172
+ max_type_size: number
173
+ };
174
+ type KoffiStats = {
175
+ disposed: number
176
+ };
177
+
178
+ export function config(): KoffiConfig;
179
+ export function config(cfg: KoffiConfig): KoffiConfig;
180
+ export function stats(): KoffiStats;
161
181
 
162
182
  export function alloc(type: TypeSpec, length: number): any;
163
183
  export function free(value: any): void;
@@ -254,5 +274,10 @@ type PrimitiveTypes =
254
274
  | 'ushort'
255
275
  | 'void'
256
276
  | 'wchar'
257
- | 'wchar_t'
258
- export const types: Record<PrimitiveTypes, IKoffiCType>
277
+ | 'wchar_t';
278
+ export const types: Record<PrimitiveTypes, IKoffiCType>;
279
+
280
+ // Internal stuff, don't use!
281
+ export const node: {
282
+ env: { __brand: 'IKoffiNodeEnv' }
283
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koffi-cream",
3
- "version": "2.13.0",
3
+ "version": "2.14.0",
4
4
  "description": "A lighter packaging for Koffi, the fast and simple C FFI (foreign function interface) for Node.js",
5
5
  "author": {
6
6
  "name": "Stephan 'Septh' Schreiber",
@@ -41,18 +41,18 @@
41
41
  "main": "index.js",
42
42
  "types": "index.d.ts",
43
43
  "optionalDependencies": {
44
- "@septh/koffi-darwin-arm64": "2.13.0",
45
- "@septh/koffi-darwin-x64": "2.13.0",
46
- "@septh/koffi-freebsd-arm64": "2.13.0",
47
- "@septh/koffi-freebsd-x64": "2.13.0",
48
- "@septh/koffi-linux-arm64-glibc": "2.13.0",
49
- "@septh/koffi-linux-loong64": "2.13.0",
50
- "@septh/koffi-linux-riscv64": "2.13.0",
51
- "@septh/koffi-linux-x64-glibc": "2.13.0",
52
- "@septh/koffi-linux-arm64-musl": "2.13.0",
53
- "@septh/koffi-linux-x64-musl": "2.13.0",
54
- "@septh/koffi-openbsd-x64": "2.13.0",
55
- "@septh/koffi-win32-arm64": "2.13.0",
56
- "@septh/koffi-win32-x64": "2.13.0"
44
+ "@septh/koffi-darwin-arm64": "2.14.0",
45
+ "@septh/koffi-darwin-x64": "2.14.0",
46
+ "@septh/koffi-freebsd-arm64": "2.14.0",
47
+ "@septh/koffi-freebsd-x64": "2.14.0",
48
+ "@septh/koffi-linux-arm64-glibc": "2.14.0",
49
+ "@septh/koffi-linux-loong64": "2.14.0",
50
+ "@septh/koffi-linux-riscv64": "2.14.0",
51
+ "@septh/koffi-linux-x64-glibc": "2.14.0",
52
+ "@septh/koffi-linux-arm64-musl": "2.14.0",
53
+ "@septh/koffi-linux-x64-musl": "2.14.0",
54
+ "@septh/koffi-openbsd-x64": "2.14.0",
55
+ "@septh/koffi-win32-arm64": "2.14.0",
56
+ "@septh/koffi-win32-x64": "2.14.0"
57
57
  }
58
58
  }