-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94c9d07
commit 53a033a
Showing
9 changed files
with
321 additions
and
117 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
|
||
echo "🦀 Testing WebAssembly package..." | ||
wasm-pack test --headless --firefox | ||
|
||
echo "🦀 Building WebAssembly package..." | ||
wasm-pack build --target web --out-dir dist | ||
|
||
echo "📋 Copying package.json and Readme files to dist..." | ||
cp pkg/* dist/ | ||
|
||
# echo "📦 Installing npm dependencies..." | ||
# cd dist && npm install | ||
|
||
# echo "🧪 Running JavaScript tests..." | ||
# npm test | ||
|
||
echo "✨ Building and testing completed!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "pubky-app-specs", | ||
"type": "module", | ||
"description": "Pubky.app Data Model Specifications", | ||
"version": "0.3.0", | ||
"license": "MIT", | ||
"collaborators": [ | ||
"SHAcollision" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/pubky/pubky-app-specs" | ||
}, | ||
"files": [ | ||
"pubky_app_specs_bg.wasm", | ||
"pubky_app_specs.js", | ||
"pubky_app_specs.d.ts" | ||
], | ||
"main": "pubky_app_specs.js", | ||
"homepage": "https://pubky.app", | ||
"types": "pubky_app_specs.d.ts", | ||
"sideEffects": [ | ||
"./snippets/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,27 @@ | ||
#[cfg(target_arch = "wasm32")] | ||
use js_sys::Date; | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
use std::time::{SystemTime, UNIX_EPOCH}; | ||
|
||
pub static VERSION: &str = "0.3.0"; | ||
pub static APP_PATH: &str = "/pub/pubky.app/"; | ||
pub static PROTOCOL: &str = "pubky://"; | ||
|
||
/// Returns the current timestamp in microseconds since the UNIX epoch. | ||
#[cfg(target_arch = "wasm32")] | ||
pub fn timestamp() -> i64 { | ||
// Use JS Date.now() which returns ms since Unix epoch | ||
let ms = Date::now() as i64; | ||
// Convert to microseconds if you like | ||
ms * 1_000 | ||
} | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
pub fn timestamp() -> i64 { | ||
use std::time::{SystemTime, UNIX_EPOCH}; | ||
SystemTime::now() | ||
.duration_since(UNIX_EPOCH) | ||
.expect("Time went backwards") | ||
.unwrap() | ||
.as_micros() as i64 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// tests/wasm_follow_test.rs | ||
|
||
#![cfg(target_arch = "wasm32")] | ||
|
||
extern crate wasm_bindgen_test; | ||
use wasm_bindgen::JsValue; | ||
use wasm_bindgen_test::*; | ||
|
||
use js_sys::Object; | ||
use pubky_app_specs::create_pubky_app_follow; | ||
|
||
wasm_bindgen_test_configure!(run_in_browser); | ||
|
||
#[wasm_bindgen_test] | ||
fn test_create_pubky_app_follow() { | ||
let pubky_id = "fake_pubky_id"; | ||
|
||
// Call the wasm-exported function | ||
let result = create_pubky_app_follow(pubky_id.into()).unwrap(); | ||
|
||
// The returned `JsValue` is the JSON object { json, id, path } | ||
// We can convert it to a JS object so we can extract fields | ||
let result_obj = Object::try_from(&result).expect("expected a JS object"); | ||
|
||
// For example, check the `path` field | ||
let path_val = | ||
js_sys::Reflect::get(&result_obj, &JsValue::from_str("path")).expect("no path field"); | ||
let path_str = path_val.as_string().expect("path must be a string"); | ||
|
||
assert_eq!( | ||
path_str, | ||
format!("/pub/pubky.app/follows/{}", pubky_id), | ||
"create_pubky_app_follow did not produce expected path" | ||
); | ||
} |