whymidnight / deno-specta

Completely typesafe Tauri commands

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

deno-specta

This library will generate a runtime.js for your Deno Runtime and an abi.ts to contextualize ts conventions against.

Convention

To generate a runtime.js from your app:

Import deno-specta via:

[build-dependencies]
deno_specta = { git = "https://github.com/whymidnight/deno-specta.git", features = ["runtime"] }
specta = { git = "https://github.com/whymidnight/specta.git" }

[dependencies]
deno_specta = { git = "https://github.com/whymidnight/deno-specta.git", features = ["runtime"] }
specta = { git = "https://github.com/whymidnight/specta.git" }

Feature guard specta/codegen and deno_core::op/deno_op:

[features]
default = []
codegen = []
deno_op = []

Declare a function:

use specta::specta;
use deno_core::op;

#[cfg_attr(feature = "deno_op", op)]
#[cfg_attr(feature = "codegen", specta)]
pub async fn foo(
    my_name: String,
    your_name: String,
) -> Result<String, deno_core::anyhow::Error> {
    Ok(format!(
        "Hello, {my_name}! You've been greeted by {your_name}!"
    ))
}

Then in build.rs:

use deno_specta::runtime;

runtime::export(
    collect_types![foo],
    "./runtime.js",
)
.unwrap();

About

Completely typesafe Tauri commands

License:MIT License


Languages

Language:Rust 100.0%