Changelog
napi-derive

napi-derive

napi-derive@2.5.0

6/10/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.4.1...napi-derive@2.5.0

napi-derive@2.3.3

4/27/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.3.2...napi-derive@2.3.3

napi-derive@2.3.2

4/27/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.3.1...napi-derive@2.3.2

napi-derive@2.3.1

4/25/2022

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.3.1...napi-derive@2.3.1

napi-derive@2.1.0

2/9/2022

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.0.8...napi-derive@2.1.0

napi-derive@2.0.8

1/18/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.0.7...napi-derive@2.0.8

napi-derive@2.0.7

1/7/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.0.6...napi-derive@2.0.7

napi-derive@2.0.6

1/6/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.0.5...napi-derive@2.0.6

napi-derive@2.0.5

1/4/2022

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.0.4...napi-derive@2.0.5

napi-derive@2.0.4

12/24/2021

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.0.3...napi-derive@2.0.4

napi-derive@2.0.3

12/24/2021

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.0.2...napi-derive@2.0.3

napi-derive@2.0.2

12/23/2021

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.0.1...napi-derive@2.0.2

napi-derive@2.0.1

12/21/2021

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.0.0...napi-derive@2.0.1

napi-derive@2.0.0-beta.5

12/8/2021

Bugfix

napi-derive@2.0.0-beta.4

12/8/2021

Feature

This feature is useful for sharing code between Node.js native addon and wasm

napi-derive@2.0.0-beta.3

12/7/2021

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.0.0-beta.3...napi-derive@2.0.0-beta.3

napi-derive@2.0.0-beta.2

12/6/2021

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.0.0-beta.1...napi-derive@2.0.0-beta.2

napi-derive@2.0.0-beta.1

12/2/2021

Bugfix

napi-derive@2.0.0-alpha.10

11/29/2021

Features

  • Output Rust doc comments in definitions as jsdoc comments #885 @timfish
/// `constructor` option for `struct` requires all fields to be public,
/// otherwise tag impl fn as constructor
/// #[napi(constructor)]
#[napi]
pub struct Animal {
  #[napi(readonly)]
  /// Kind of animal
  pub kind: Kind,

  name: String,
}

#[napi]
impl Animal {
  /// This is the constructor
  #[napi(constructor)]
  pub fn new(kind: Kind, name: String) -> Self {
    Animal { kind, name }
  }

  /// This is a factory method
  #[napi(factory)]
  pub fn with_kind(kind: Kind) -> Self {
    Animal {
      kind,
      name: "Default".to_owned(),
    }
  }

  #[napi(getter)]
  pub fn get_name(&self) -> &str {
    self.name.as_str()
  }

  #[napi(setter)]
  pub fn set_name(&mut self, name: String) {
    self.name = name;
  }

  /// This is a
  /// multi-line comment
  /// with an emoji 🚀
  #[napi]
  pub fn whoami(&self) -> String {
    match self.kind {
      Kind::Dog => {
        format!("Dog: {}", self.name)
      }
      Kind::Cat => format!("Cat: {}", self.name),
      Kind::Duck => format!("Duck: {}", self.name),
    }
  }

  #[napi]
  /// This is static...
  pub fn get_dog_kind() -> Kind {
    Kind::Dog
  }
}

⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️ ```ts /

  • constructor option for struct requires all fields to be public,
  • otherwise tag impl fn as constructor
  • #[napi(constructor)] */ export class Animal { / Kind of animal */ readonly kind: Kind / This is the constructor */ constructor(kind: Kind, name: string) / This is a factory method */ static withKind(kind: Kind): Animal get name(): string set name(name: string) /
    • This is a
    • multi-line comment
    • with an emoji 🚀 */ whoami(): string / This is static... */ static getDogKind(): Kind } ```

napi-derive@2.0.0-alpha.9

11/26/2021

Features

use napi::bindgen_prelude::*;
use napi_derive::napi;

#[napi(ts_args_type = "a: { foo: number }", ts_return_type = "string[]")]
fn ts_rename(a: Object) -> Result<Object> {
  a.get_property_names()
}

⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️⬇️

export function tsRename(a: { foo: number }): string[]

napi-derive@2.0.0-alpha.6

11/16/2021

What's Changed

  • Generate TypeScript optional types from Rust Option
#[napi]
fn map_option(val: Option<u32>) -> Option<u32> {
  val.map(|v| v + 1)
}
export function mapOption(val?: number | undefined | null): number | undefined | null
#[napi]
pub struct Context {
  data: String,
  pub maybe_need: Option<bool>,
}
export class Context {
  maybeNeed?: boolean | undefined | null
}
#[napi]
fn read_file<T: Fn(Result<()>, Option<String>) -> Result<()>>(callback: T) {
  match read_file_content() {
    Ok(s) => callback(Ok(()), Some(s)),
    Err(e) => callback(Err(e), None),
  }
  .unwrap();
}
export function readFile(callback: (arg0: Error | undefined, arg1?: string | undefined | null) => void): void

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.0.0-alpha.5...napi-derive@2.0.0-alpha.6

napi-derive@2.0.0-alpha.5

11/16/2021

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi-derive@2.0.0-alpha.4...napi-derive@2.0.0-alpha.5