Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dbcfd committed May 9, 2023
0 parents commit 5f6eebc
Show file tree
Hide file tree
Showing 9 changed files with 743 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "cargo"
directory: "/"
schedule:
interval: "weekly"
ignore:
# These are peer deps of Cargo and should not be automatically bumped
- dependency-name: "semver"
- dependency-name: "crates-io"
rebase-strategy: "disabled"

115 changes: 115 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# CI that:
#
# * checks for a Git Tag that looks like a release ("v1.2.0")
# * creates a Github Release™️
# * builds binaries/packages with cargo-dist
# * uploads those packages to the Github Release™️
#
# Note that the Github Release™️ will be created before the packages,
# so there will be a few minutes where the release has no packages
# and then they will slowly trickle in, possibly failing. To make
# this more pleasant we mark the release as a "draft" until all
# artifacts have been successfully uploaded. This allows you to
# choose what to do with partial successes and avoids spamming
# anyone with notifications before the release is actually ready.
name: Release

permissions:
contents: write

on:
workflow_dispatch:
inputs:
level:
description: 'Release level'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major

jobs:
# Build and packages all the things
build-binaries:
strategy:
matrix:
# For these target platforms
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: aarch64-apple-darwin
os: macos-latest
#- target: x86_64-pc-windows-msvc
# os: windows-latest
runs-on: ${{ matrix.os }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- name: Install Rust
run: |
rustup update stable
rustup default stable
- name: Install cargo-zigbuild
run: |
pip3 install ziglang
cargo install cargo-zigbuild
- name: Setup target
run: rustup target add ${{ matrix.target }}
- name: Run cargo zigbuild
run: |
cargo zigbuild --release --target ${{ matrix.target }}
- name: Compress artifacts
run: |
tar -cvzf wheel_${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release wheel
- name: Archive artifact
uses: actions/upload-artifact@v3
with:
name: wheel_${{ matrix.target }}
path: |
wheel_${{ matrix.target }}.tar.gz
bump-versions:
needs: [build-binaries]
runs-on: ubuntu-latest
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_TOKEN }}
outputs:
tag: ${{ steps.release.outputs.tag }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- id: install-cargo-release
uses: taiki-e/install-action@v1
with:
tool: cargo-release
- id: release
run: |
git config user.email "github@3box.io"
git config user.name "Github Automation"
echo "tag="$(cargo metadata --format-version=1 --no-deps | jq '.packages[0].version' | tr -d '"') >> $GITHUB_OUTPUT
cargo release -vv ${{ inputs.level }} -x --no-confirm
publish-release:
needs: [bump-versions]
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
path: artifacts
- name: check artifacts
run: |
ls artifacts/**/*.tar.gz
- name: create release
run: |
echo "Creating release for "${{ needs.bump-versions.outputs.tag }}
gh release create v${{ needs.bump-versions.outputs.tag }} --title "v"${{ needs.bump-versions.outputs.tag }} --latest artifacts/**/*.tar.gz
22 changes: 22 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Rust

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
Cargo.lock
/target
34 changes: 34 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "ceramic-http-client"
version = "0.1.0"
edition = "2021"
authors = [
"Nathaniel Cook <nvcook42@gmail.com>",
"Danny Browning <dbrowning@3box.io>",
]
license = "MIT OR Apache-2.0"
repository = "https://github.com/3box/rust-ceramic-http-client"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1"
#ceramic-event = { git = "https://github.com/3box/rust-ceramic", branch = "main" }
ceramic-event = { path = "/Users/dbrowning/code/3box/rust-ceramic/event" }
json-patch = "0.3.0"
reqwest = { version = "0.11.14", features = ["json"], optional = true }
schemars = "0.8.12"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
ssi = { version = "0.6", features = ["ed25519"] }
url = { version = "2.2.2", optional = true }

[features]
default = ["remote"]
remote = ["reqwest", "url"]

[dev-dependencies]
test-log = { version = "0.2", default-features = false, features = ["trace"] }
tokio = { version = "1", default-features = false, features = ["macros", "rt"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
3 changes: 3 additions & 0 deletions release.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
consolidate-commits = false
allow-branch = ["main"]
tag-name = "{{prefix}}v{{prev_version}}"
91 changes: 91 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
use ceramic_event::{
Base64String, Jws, MultiBase32String, MultiBase36String, StreamId, StreamIdType,
};
use serde::{Deserialize, Serialize};

#[derive(Serialize)]
pub struct BlockHeader {
pub family: String,
pub controllers: Vec<String>,
pub model: Base64String,
}

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct BlockData<T: Serialize> {
pub header: BlockHeader,
#[serde(skip_serializing_if = "Option::is_none")]
pub data: Option<T>,
#[serde(skip_serializing_if = "Option::is_none")]
pub jws: Option<Jws>,
#[serde(skip_serializing_if = "Option::is_none")]
pub linked_block: Option<Base64String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub cacao_block: Option<MultiBase32String>,
}

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateRequest<T: Serialize> {
#[serde(rename = "type")]
pub r#type: StreamIdType,
#[serde(rename = "genesis")]
pub block: BlockData<T>,
}

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateRequest {
#[serde(rename = "type")]
pub r#type: StreamIdType,
#[serde(rename = "commit")]
pub block: BlockData<Base64String>,
pub stream_id: MultiBase36String,
}

#[derive(Deserialize)]
pub struct PostResponse {
error: Option<String>,
#[serde(rename = "streamId")]
stream_id: Option<StreamId>,
}

impl PostResponse {
pub fn resolve(self, context: &str) -> anyhow::Result<StreamId> {
if let Some(stream_id) = self.stream_id {
Ok(stream_id)
} else {
let post = if let Some(err) = self.error {
format!(": {}", err)
} else {
": No additional information provided by ceramic".to_string()
};
anyhow::bail!(format!("{}{}", context, post))
}
}
}

#[derive(Deserialize)]
pub struct StateLog {
pub cid: MultiBase36String,
}

#[derive(Deserialize)]
pub struct Metadata {
pub controllers: Vec<String>,
pub model: StreamId,
}

#[derive(Deserialize)]
pub struct StreamState {
pub content: serde_json::Value,
pub log: Vec<StateLog>,
pub metadata: Metadata,
}

#[derive(Deserialize)]
pub struct GetResponse {
#[serde(rename = "streamId")]
pub stream_id: StreamId,
pub state: StreamState,
}
Loading

0 comments on commit 5f6eebc

Please sign in to comment.