Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,042 changes: 1,815 additions & 227 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["server", "cli", "lib"]
members = ["server", "cli", "lib", "plugin-examples/random-folder-extender"]
# Tauri build is deprecated, see
# https://github.com/atomicdata-dev/atomic-server/issues/718
exclude = ["desktop"]
22 changes: 22 additions & 0 deletions atomic-plugin/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Contributing to Atomic Plugin

When updating the bindings, keep the following in mind:
There is a weird issue where the bindings do not work when using the standard `wit_bidgen::generate!` macro.
To get the right bindings change bindings.rs to the following:

```rust
wit_bindgen::generate!({
path: "wit/class-extender.wit",
world: "class-extender",
pub_export_macro: true,
});
```

Then run `cargo component check` on the atomic-plugin crate, for some reason this expands the macro in a way that it actually works.
The only thing left is to mark the following macro as exported:

```rust
#[doc(hidden)]
#[macro_export] // <-- add this line
macro_rules! __export_world_class_extender_cabi {
```
11 changes: 11 additions & 0 deletions atomic-plugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "atomic-plugin"
version = "0.1.1"
edition = "2021"
description = "Helper library for building Atomic Data class extender plugins in Wasm"

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = { version = "0.48.1", features = ["realloc", "macros"] }
wit-bindgen-rt = "0.44.0"
44 changes: 44 additions & 0 deletions atomic-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# atomic-plugin

A helper library that removes a lot of the boilerplate when building AtomicServer Wasm plugins.

## Class Extenders

Atomic Data Classextenders are plugins that can modify the behavior of an Atomic Data class.
For example you might want to add some custom verification logic to a class

## How to use

Simply implement the `ClassExtender` trait on a struct and export it using the `export_plugin!` macro.

```rust
use atomic_plugin::{ClassExtender, Commit, Resource};

struct FolderExtender;

impl ClassExtender for FolderExtender {
// REQUIRED: Returns the class that this class extender applies to.
fn class_url() -> String {
"https://atomicdata.dev/classes/Folder".to_string()
}

// Prevent commits where the name contains "Tailwind CSS".
fn before_commit(commit: &Commit, _snapshot: Option<&Resource>) -> Result<(), String> {
let Some(set) = &commit.set else {
return Ok(());
};

let Some(name) = set.get(NAME_PROP).and_then(|val| val.as_str()) else {
return Ok(());
};

if name.contains("Tailwind CSS") {
return Err("Tailwind CSS is not allowed".into());
}

Ok(())
}
}

atomic_plugin::export_plugin!(FolderExtender);
```
Loading
Loading