wip: constant name case

feat/type-attributes
Tomáš Mládek 2023-06-28 18:44:08 +02:00
parent 0b4bdf8c18
commit e66e072871
3 changed files with 11 additions and 12 deletions

View File

@ -1,6 +1,7 @@
import LRU from "lru-cache";
import { UpListing, UpObject } from ".";
import type {
ADDRESS_TYPE,
Address,
AttributeListingResult,
EntityListing,
@ -24,6 +25,8 @@ const dbg = debug("upend:api");
export { AddressComponents };
const addressConstants = new AddressTypeConstants();
export class UpEndApi {
private instanceUrl = "";
private wasmPath: string | undefined;
@ -203,19 +206,13 @@ export class UpEndApi {
| { attribute: string }
| { url: string }
| { urlContent: string }
| "Hash"
| "Uuid"
| "Attribute"
| "Url"
| ADDRESS_TYPE
): 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"
];
return addressConstants[input];
} catch (err) {
console.warn(err);
}

View File

@ -1,4 +1,5 @@
export type Address = string;
export type ADDRESS_TYPE = "Hash" | "Uuid" | "Attribute" | "Url";
export type VALUE_TYPE = "Address" | "String" | "Number" | "Invalid";
/**

View File

@ -46,6 +46,7 @@ pub fn components_to_addr(components: AddressComponents) -> Result<String, WasmE
pub struct AddressTypeConstants {}
#[wasm_bindgen]
#[allow(non_snake_case)]
impl AddressTypeConstants {
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
@ -53,22 +54,22 @@ impl AddressTypeConstants {
}
#[wasm_bindgen(getter)]
pub fn hash(&self) -> String {
pub fn Hash(&self) -> String {
constants::TYPE_HASH_ADDRESS.to_string()
}
#[wasm_bindgen(getter)]
pub fn uuid(&self) -> String {
pub fn Uuid(&self) -> String {
constants::TYPE_UUID_ADDRESS.to_string()
}
#[wasm_bindgen(getter)]
pub fn attribute(&self) -> String {
pub fn Attribute(&self) -> String {
constants::TYPE_ATTRIBUTE_ADDRESS.to_string()
}
#[wasm_bindgen(getter)]
pub fn url(&self) -> String {
pub fn Url(&self) -> String {
constants::TYPE_URL_ADDRESS.to_string()
}
}