UNPKG

@msquared/etherbase-client

Version:

React hooks for interacting with Etherbase smart contracts

85 lines (78 loc) 2.56 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/server/index.ts var server_exports = {}; __export(server_exports, { getConfig: () => getConfig, getEventDefinitions: () => getEventDefinitions, getSources: () => getSources, initializeApp: () => initializeApp }); module.exports = __toCommonJS(server_exports); // src/config.ts var config = null; function initializeApp(userConfig) { if (!userConfig.wsReaderUrl && !userConfig.wsWriterUrl && !userConfig.httpReaderUrl) { throw new Error( "wsReaderUrl or wsWriterUrl or httpReaderUrl must be provided in etherbase config" ); } config = userConfig; } function getConfig() { if (!config) { throw new Error( "Etherbase must be initialized with initializeApp() before use, or use the EtherbaseProvider" ); } return config; } // src/etherbaseSource.ts async function fetchEventDefinitionsData(sourceAddress, config2) { const { httpReaderUrl } = config2 || getConfig(); const response = await fetch( `${httpReaderUrl}/event-definitions?sourceAddress=${sourceAddress}`, { cache: "no-store" } ); return response.json(); } // src/server/etherbaseSource.ts async function getEventDefinitions(sourceAddress, config2) { return fetchEventDefinitionsData(sourceAddress, config2); } // src/etherbase.ts async function fetchSourcesData(config2) { const { httpReaderUrl } = config2 || getConfig(); const response = await fetch(`${httpReaderUrl}/sources`, { cache: "no-store" }); const data = await response.json(); return data; } // src/server/etherbase.ts async function getSources(config2) { return fetchSourcesData(config2); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getConfig, getEventDefinitions, getSources, initializeApp });