@tsukilabs/nil-ffi 0.7.18 → 0.7.20

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/dist/index.js CHANGED
@@ -94,7 +94,9 @@ var Queue = class Queue {
94
94
  this.pendingRequests = /* @__PURE__ */ new Map();
95
95
  this.functions = handle.functions;
96
96
  this.errorHandler = options?.onError ?? console.error;
97
+ this.eventHandler = options?.onEvent ?? console.log;
97
98
  this.emitter.on("error", this.errorHandler);
99
+ this.emitter.on("event", this.eventHandler);
98
100
  this.emitter.on("response", this.onResponse.bind(this));
99
101
  this.timer = setTimeout(() => this.drain(), 0);
100
102
  }
@@ -148,6 +150,11 @@ var Queue = class Queue {
148
150
  }
149
151
  dispatch(entry) {
150
152
  switch (entry.kind) {
153
+ case "event": {
154
+ const event = JSON.parse(entry.jsonStr);
155
+ this.emitter.emit("event", event);
156
+ break;
157
+ }
151
158
  case "response": {
152
159
  const response = JSON.parse(entry.jsonStr);
153
160
  this.emitter.emit("response", response);
@@ -790,7 +797,7 @@ var definitions = {
790
797
  };
791
798
  //#endregion
792
799
  //#region package.json
793
- var version = "0.7.18";
800
+ var version = "0.7.20";
794
801
  //#endregion
795
802
  //#region \0@oxc-project+runtime@0.142.0/helpers/esm/decorate.js
796
803
  function __decorate(decorators, target, key, desc) {
@@ -846,7 +853,8 @@ var Nil = class Nil {
846
853
  const file = `libnil.${ffi.suffix}`;
847
854
  const filePath = path.resolve(options?.outDir ?? cwd(), file);
848
855
  if (!(options?.overwrite ?? true) && existsSync(filePath)) return filePath;
849
- const response = await fetch(`https://tsukilabs.dev.br/download/nil/${file}`, { headers: { "User-Agent": USER_AGENT } });
856
+ const url = `https://tsukilabs.dev.br/download/nil/${file}`;
857
+ const response = await fetch(new URL(url), { headers: { "User-Agent": USER_AGENT } });
850
858
  if (!response.ok) throw new Error(`failed to download ${file}: ${response.status} ${response.statusText}`);
851
859
  const bytes = await response.bytes();
852
860
  await fs.writeFile(filePath, bytes);
package/dist/queue.d.ts CHANGED
@@ -11,6 +11,7 @@ export declare class Queue implements Disposable {
11
11
  private readonly pendingRequests;
12
12
  private timer;
13
13
  private readonly errorHandler;
14
+ private readonly eventHandler;
14
15
  constructor(handle: Handle, options?: QueueOptions);
15
16
  [Symbol.dispose](): void;
16
17
  request<T = nil>(start: RequestFn): Promise<T>;
package/dist/types.d.ts CHANGED
@@ -1,10 +1,13 @@
1
1
  import { definitions } from './def';
2
2
  import { Option } from '@tb-dev/utils';
3
+ import { Event } from '@tsukilabs/nil-bindings';
3
4
  import { DynamicLibraryResult } from 'node:ffi';
4
5
  export type Handle = DynamicLibraryResult<typeof definitions>;
5
6
  export type ErrorHandler = (error: unknown) => void;
7
+ export type EventHandler = (event: Event) => void;
6
8
  export interface QueueOptions {
7
9
  onError?: Option<ErrorHandler>;
10
+ onEvent?: Option<EventHandler>;
8
11
  }
9
12
  export interface NilOptions extends QueueOptions {
10
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsukilabs/nil-ffi",
3
- "version": "0.7.18",
3
+ "version": "0.7.20",
4
4
  "description": "FFI bindings for Call of Nil",
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@11.20.0",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@tb-dev/utils": "^8.1.3",
34
- "@tsukilabs/nil-bindings": "^0.7.17",
34
+ "@tsukilabs/nil-bindings": "^0.7.19",
35
35
  "es-toolkit": "^1.50.0"
36
36
  },
37
37
  "files": ["dist"],