wip: constant name case

This commit is contained in:
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 LRU from "lru-cache";
import { UpListing, UpObject } from "."; import { UpListing, UpObject } from ".";
import type { import type {
ADDRESS_TYPE,
Address, Address,
AttributeListingResult, AttributeListingResult,
EntityListing, EntityListing,
@ -24,6 +25,8 @@ const dbg = debug("upend:api");
export { AddressComponents }; export { AddressComponents };
const addressConstants = new AddressTypeConstants();
export class UpEndApi { export class UpEndApi {
private instanceUrl = ""; private instanceUrl = "";
private wasmPath: string | undefined; private wasmPath: string | undefined;
@ -203,19 +206,13 @@ export class UpEndApi {
| { attribute: string } | { attribute: string }
| { url: string } | { url: string }
| { urlContent: string } | { urlContent: string }
| "Hash" | ADDRESS_TYPE
| "Uuid"
| "Attribute"
| "Url"
): Promise<string> { ): Promise<string> {
let response; let response;
if (typeof input === "string") { if (typeof input === "string") {
try { try {
await this.initWasm(); await this.initWasm();
const addressConstants = new AddressTypeConstants(); return addressConstants[input];
return addressConstants[
input.toLowerCase() as "hash" | "uuid" | "attribute" | "url"
];
} catch (err) { } catch (err) {
console.warn(err); console.warn(err);
} }

View file

@ -1,4 +1,5 @@
export type Address = string; export type Address = string;
export type ADDRESS_TYPE = "Hash" | "Uuid" | "Attribute" | "Url";
export type VALUE_TYPE = "Address" | "String" | "Number" | "Invalid"; 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 {} pub struct AddressTypeConstants {}
#[wasm_bindgen] #[wasm_bindgen]
#[allow(non_snake_case)]
impl AddressTypeConstants { impl AddressTypeConstants {
#[wasm_bindgen(constructor)] #[wasm_bindgen(constructor)]
pub fn new() -> Self { pub fn new() -> Self {
@ -53,22 +54,22 @@ impl AddressTypeConstants {
} }
#[wasm_bindgen(getter)] #[wasm_bindgen(getter)]
pub fn hash(&self) -> String { pub fn Hash(&self) -> String {
constants::TYPE_HASH_ADDRESS.to_string() constants::TYPE_HASH_ADDRESS.to_string()
} }
#[wasm_bindgen(getter)] #[wasm_bindgen(getter)]
pub fn uuid(&self) -> String { pub fn Uuid(&self) -> String {
constants::TYPE_UUID_ADDRESS.to_string() constants::TYPE_UUID_ADDRESS.to_string()
} }
#[wasm_bindgen(getter)] #[wasm_bindgen(getter)]
pub fn attribute(&self) -> String { pub fn Attribute(&self) -> String {
constants::TYPE_ATTRIBUTE_ADDRESS.to_string() constants::TYPE_ATTRIBUTE_ADDRESS.to_string()
} }
#[wasm_bindgen(getter)] #[wasm_bindgen(getter)]
pub fn url(&self) -> String { pub fn Url(&self) -> String {
constants::TYPE_URL_ADDRESS.to_string() constants::TYPE_URL_ADDRESS.to_string()
} }
} }