wip: add no-network address type constants to upend_js

feat/type-attributes
Tomáš Mládek 2023-06-28 18:36:47 +02:00
parent 3ede48236c
commit 509b640dcd
5 changed files with 52 additions and 10 deletions

View File

@ -15,6 +15,7 @@ import type {
import init_wasm from "upend_wasm";
import {
AddressComponents,
AddressTypeConstants,
addr_to_components,
components_to_addr,
} from "upend_wasm";
@ -209,6 +210,15 @@ export class UpEndApi {
): Promise<string> {
let response;
if (typeof input === "string") {
try {
await this.initWasm();
const addressConstants = new AddressTypeConstants();
return addressConstants[
input.toLowerCase() as "hash" | "uuid" | "attribute" | "url"
];
} catch (err) {
console.warn(err);
}
response = await fetch(`${this.apiUrl}/address?type=${input}`);
} else {
if ("attribute" in input) {

View File

@ -21,6 +21,6 @@
"dependencies": {
"debug": "^4.3.4",
"lru-cache": "^7.0.0",
"upend_wasm": "file:../upend_wasm/pkg"
"upend_wasm": "../upend_wasm/pkg"
}
}

View File

@ -3632,14 +3632,14 @@ __metadata:
eslint: ^8.7.0
lru-cache: ^7.0.0
typescript: ^4.4.4
upend_wasm: "file:../upend_wasm/pkg"
upend_wasm: ../upend_wasm/pkg
languageName: unknown
linkType: soft
"upend_wasm@file:../upend_wasm/pkg::locator=upend%40workspace%3A.":
version: 0.1.0
resolution: "upend_wasm@file:../upend_wasm/pkg#../upend_wasm/pkg::hash=10772a&locator=upend%40workspace%3A."
checksum: 26c11aa145ba9a5209dac83cbf6c4bc6236d88364a9797030afe9cc3452f1f5daf23014926dfe2f1aea5289494ff166f8c897e766c808af939f1d953ddc0d483
resolution: "upend_wasm@file:../upend_wasm/pkg#../upend_wasm/pkg::hash=aca1db&locator=upend%40workspace%3A."
checksum: 16eccf41a8d884154d2170602da4ffa44cf3f601c8f6a9cd26637864183bba003f9bb38ecdab93306dd6f6d22a3893946676f211a3e14581bc249f0ce1dd0b1c
languageName: node
linkType: hard

View File

@ -1,5 +1,6 @@
use upend_base::{
addressing::{Address, AddressComponents},
constants,
error::UpEndError,
};
use wasm_bindgen::prelude::*;
@ -40,3 +41,34 @@ pub fn components_to_addr(components: AddressComponents) -> Result<String, WasmE
Ok(address.to_string())
}
#[wasm_bindgen]
pub struct AddressTypeConstants {}
#[wasm_bindgen]
impl AddressTypeConstants {
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
AddressTypeConstants {}
}
#[wasm_bindgen(getter)]
pub fn hash(&self) -> String {
constants::TYPE_HASH_ADDRESS.to_string()
}
#[wasm_bindgen(getter)]
pub fn uuid(&self) -> String {
constants::TYPE_UUID_ADDRESS.to_string()
}
#[wasm_bindgen(getter)]
pub fn attribute(&self) -> String {
constants::TYPE_ATTRIBUTE_ADDRESS.to_string()
}
#[wasm_bindgen(getter)]
pub fn url(&self) -> String {
constants::TYPE_URL_ADDRESS.to_string()
}
}

View File

@ -12585,19 +12585,19 @@ __metadata:
"upend@file:../tools/upend_js::locator=upend-kestrel%40workspace%3A.":
version: 0.0.1
resolution: "upend@file:../tools/upend_js#../tools/upend_js::hash=2d3140&locator=upend-kestrel%40workspace%3A."
resolution: "upend@file:../tools/upend_js#../tools/upend_js::hash=6d7a60&locator=upend-kestrel%40workspace%3A."
dependencies:
debug: ^4.3.4
lru-cache: ^7.0.0
upend_wasm: "file:../upend_wasm/pkg"
checksum: 3ac07a91311fe2fbf25d1e95dd8231b87d82457457c242c6095ee6419f3f5997a037a6f0eaa826e90ba16f70985750da2f7af2a8f4da25f421370e42fbb2def1
upend_wasm: ../upend_wasm/pkg
checksum: 4b4d166c0e048ae2c3d3dc72519a64e7b3b30e3c357c5333bc2361d28a218bc9e28e333f9a3fa02896143065a3b9efc337a860bb550eb78635a5607d2afcfe50
languageName: node
linkType: hard
"upend_wasm@file:../upend_wasm/pkg::locator=upend%40file%3A..%2Ftools%2Fupend_js%23..%2Ftools%2Fupend_js%3A%3Ahash%3D2d3140%26locator%3Dupend-kestrel%2540workspace%253A.":
"upend_wasm@file:../upend_wasm/pkg::locator=upend%40file%3A..%2Ftools%2Fupend_js%23..%2Ftools%2Fupend_js%3A%3Ahash%3D6d7a60%26locator%3Dupend-kestrel%2540workspace%253A.":
version: 0.1.0
resolution: "upend_wasm@file:../upend_wasm/pkg#../upend_wasm/pkg::hash=10772a&locator=upend%40file%3A..%2Ftools%2Fupend_js%23..%2Ftools%2Fupend_js%3A%3Ahash%3D2d3140%26locator%3Dupend-kestrel%2540workspace%253A."
checksum: 26c11aa145ba9a5209dac83cbf6c4bc6236d88364a9797030afe9cc3452f1f5daf23014926dfe2f1aea5289494ff166f8c897e766c808af939f1d953ddc0d483
resolution: "upend_wasm@file:../upend_wasm/pkg#../upend_wasm/pkg::hash=cb9d21&locator=upend%40file%3A..%2Ftools%2Fupend_js%23..%2Ftools%2Fupend_js%3A%3Ahash%3D6d7a60%26locator%3Dupend-kestrel%2540workspace%253A."
checksum: 51385c3bfda2d3fff7e579e9b350866ef5f8f3f5cac30d5ae1a0a6785c0ff49b2018b68b3492f1be8e983395c5685b09d799d368a5b2d9d6e8a4ec0f38bd0d21
languageName: node
linkType: hard