From e66e0728713c5d400d7d708c622c2428b184ea16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Wed, 28 Jun 2023 18:44:08 +0200 Subject: [PATCH] wip: constant name case --- tools/upend_js/api.ts | 13 +++++-------- tools/upend_js/types.ts | 1 + tools/upend_wasm/src/lib.rs | 9 +++++---- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/tools/upend_js/api.ts b/tools/upend_js/api.ts index 54e3335..af1b547 100644 --- a/tools/upend_js/api.ts +++ b/tools/upend_js/api.ts @@ -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 { 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); } diff --git a/tools/upend_js/types.ts b/tools/upend_js/types.ts index 34b25c5..e359b20 100644 --- a/tools/upend_js/types.ts +++ b/tools/upend_js/types.ts @@ -1,4 +1,5 @@ export type Address = string; +export type ADDRESS_TYPE = "Hash" | "Uuid" | "Attribute" | "Url"; export type VALUE_TYPE = "Address" | "String" | "Number" | "Invalid"; /** diff --git a/tools/upend_wasm/src/lib.rs b/tools/upend_wasm/src/lib.rs index 22a5554..8d3a11e 100644 --- a/tools/upend_wasm/src/lib.rs +++ b/tools/upend_wasm/src/lib.rs @@ -46,6 +46,7 @@ pub fn components_to_addr(components: AddressComponents) -> Result 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() } }