@rango-dev/wallets-core 0.46.1-next.0 → 0.46.1-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hub/store/selectors.ts", "../../../src/hub/store/store.ts", "../../../src/hub/store/extend.ts", "../../../src/hub/store/hub.ts", "../../../src/hub/store/namespaces.ts", "../../../src/hub/store/events.ts", "../../../src/hub/store/providers.ts"],
4
- "sourcesContent": ["/**\n * Note: Zustand has some difficulty when you are trying to `previous` state on `subscribe`.\n * If these selectors define inside store directly and use `get()` for accessing state, it will get the latest state\n * instead of previous state which desired.\n * So make them a helper will let us to reuse them both in store and outside of store in a `subscribe`.\n */\nimport type { State } from '../mod.js';\nimport type { State as InternalProviderState } from '../provider/mod.js';\n\n/**\n * Legacy provider state includes `connecting` and `connected` values. It hadn't a separation layer for `namespaces`.\n * For compatibility reasons, we should produce these two values somehow.\n *\n * Currently, We return `true` if any of namespaces return true. We are missing failed namespace here.\n * But if we want to solve that, we should migrate our client code to use `namespace` state directly and not from `provider`\n */\nexport function guessProviderStateSelector(\n state: State,\n providerId: string\n): InternalProviderState {\n /*\n * We keep namespaces in a separate branch than providers.\n * We should look at all of them and find all the namespaces that for our current proivder.\n */\n const allNamespaces = state.namespaces.list;\n const currentProviderNamespaces = Object.keys(allNamespaces).filter(\n (key) => allNamespaces[key].info.providerId === providerId\n );\n\n // Returning provider state value directly.\n const installed = !!state.providers.list[providerId]?.data.installed;\n\n /*\n * If any namespaces returns `true`, we consider the whole provider for this field to be `true`.\n * it has a downside regarding errors which explained on top of the function.\n */\n const connected =\n currentProviderNamespaces.length > 0\n ? currentProviderNamespaces.some(\n (key) => allNamespaces[key].data.connected\n )\n : false;\n const connecting =\n currentProviderNamespaces.length > 0\n ? currentProviderNamespaces.some(\n (key) => allNamespaces[key].data.connecting\n )\n : false;\n\n return {\n installed,\n connected,\n connecting,\n };\n}\n\nexport function namespaceStateSelector(state: State, storeId: string) {\n return state.namespaces.list[storeId].data;\n}\n", "import type { StoreApi } from 'zustand/vanilla';\n\nimport { createStore as createZustandStore } from 'zustand/vanilla';\n\nimport { extend, type Store } from './extend.js';\nimport { hubStore, type HubStore } from './hub.js';\nimport { namespacesStore, type NamespaceStore } from './namespaces.js';\nimport { providersStore, type ProviderStore } from './providers.js';\n\n/************ State ************/\n\nexport interface State {\n hub: HubStore;\n providers: ProviderStore;\n namespaces: NamespaceStore;\n}\n\nexport type RawStore = StoreApi<State>;\n\nexport const createStore = (): Store => {\n const store = createZustandStore<State>((...api) => {\n return {\n hub: hubStore(...api),\n providers: providersStore(...api),\n namespaces: namespacesStore(...api),\n };\n });\n\n return extend(store);\n};\n", "import type {\n Event,\n ProviderConnectedEvent,\n ProviderConnectingEvent,\n ProviderDisconnectedEvent,\n} from './events.js';\nimport type { RawStore, State } from './store.js';\n\nimport { guessProviderStateSelector } from './selectors.js';\n\nexport interface Store extends Omit<RawStore, 'subscribe'> {\n subscribe(listener: (event: Event, state: State, prevState: State) => void): {\n flushEvents(): void;\n };\n}\n\n/**\n * Zustand's store provides a set of built-in functionalities,\n * but it may not meet all our requirements.\n * This function modifies the interface and adds or updates the available methods.\n */\nexport function extend(store: RawStore): Store {\n const extendedSubscribe: (store: RawStore) => Store['subscribe'] =\n (store) => (listener) => {\n const executeListener = (\n events: Event[],\n state: State,\n prevState: State\n ) => {\n for (const ev of events) {\n listener(ev, state, prevState);\n }\n };\n\n /*\n * only known changes will fire event for lib users\n * so all the changes in store won't trigger a user-face event\n */\n store.subscribe((state, prevState) => {\n const eventsLike = getEventsLike(state, prevState);\n const events = tryConsumeEvents(state);\n const allQueuedEvents = [...events, ...eventsLike];\n executeListener(allQueuedEvents, state, prevState);\n });\n\n return {\n /**\n * Manually run pending events.\n * This useful when use `subscribe` method after sometime and when store initialized.\n *\n * Note: Please consider both current and previous state will be same and we don't have access to previous state in a such scenario.\n */\n flushEvents: () => {\n const state = store.getState();\n const events = tryConsumeEvents(state);\n executeListener(events, state, state);\n },\n };\n };\n\n return new Proxy(store, {\n get: function (target, prop, receiver) {\n if (prop === 'subscribe') {\n return extendedSubscribe(target);\n }\n return Reflect.get(target, prop, receiver);\n },\n }) as unknown as Store;\n}\n\n/**\n * Retrieves the ConsumableEvent from the store and returns its values.\n * The values will be consumed by iterating over the field.\n */\nfunction tryConsumeEvents(state: State): Event[] {\n return [...state.providers.events, ...state.namespaces.events];\n}\n\n/**\n * In certain cases, adding events to the store is not possible (e.g., namespace or provider layer).\n * In these cases, we observe store changes and treat specific patterns as events when detected.\n *\n * Note: This approach should be avoided in most cases. It is used here to maintain backward compatibility\n * with the provider's legacy interface.\n */\nfunction getEventsLike(state: State, prevState: State): Event[] {\n const events: Event[] = [];\n\n for (const providerId of Object.keys(state.providers.list)) {\n const currentProviderState = guessProviderStateSelector(state, providerId);\n const previousProviderState = guessProviderStateSelector(\n prevState,\n providerId\n );\n\n if (previousProviderState.connecting !== currentProviderState.connecting) {\n const ev: ProviderConnectingEvent = {\n type: 'provider_connecting',\n provider: providerId,\n value: currentProviderState.connecting,\n };\n events.push(ev);\n }\n\n if (!previousProviderState.connected && currentProviderState.connected) {\n const ev: ProviderConnectedEvent = {\n type: 'provider_connected',\n provider: providerId,\n };\n\n events.push(ev);\n }\n\n if (previousProviderState.connected && !currentProviderState.connected) {\n const ev: ProviderDisconnectedEvent = {\n type: 'provider_disconnected',\n provider: providerId,\n };\n\n events.push(ev);\n }\n }\n\n return events;\n}\n", "/************ Hub ************/\n\nimport type { State } from './mod.js';\nimport type { StateCreator } from 'zustand';\n\ntype HubConfig = object;\n\nexport interface HubStore {\n config: HubConfig;\n}\n\ntype HubStateCreator = StateCreator<State, [], [], HubStore>;\n\nconst hubStore: HubStateCreator = () => ({\n config: {},\n});\n\nexport { hubStore };\n", "/************ Namespace ************/\n\nimport type { StateCreator } from 'zustand';\n\nimport { produce } from 'immer';\n\nimport {\n ConsumableEvents,\n type NamespaceConnectedEvent,\n type NamespaceDisconnectedEvent,\n type NamespaceSwitchedAccountEvent,\n type NamespaceSwitchedNetworkEvent,\n} from './events.js';\nimport { namespaceStateSelector, type State } from './mod.js';\n\n// Currently, namespace doesn't has any config.\nexport type NamespaceConfig = object;\n\nexport interface NamespaceData {\n accounts: null | string[];\n network: null | string;\n connected: boolean;\n connecting: boolean;\n}\n\ninterface NamespaceInfo {\n providerId: string;\n namespaceId: string;\n}\n\ninterface NamespaceItem {\n info: NamespaceInfo;\n data: NamespaceData;\n error: unknown;\n}\n\ntype NamespaceState = {\n events: InstanceType<typeof ConsumableEvents>;\n list: Record<string, NamespaceItem>;\n};\n\ninterface NamespaceActions {\n addNamespace: (id: string, config: NamespaceInfo) => void;\n updateStatus: <K extends keyof NamespaceData>(\n id: string,\n key: K,\n value: NamespaceData[K]\n ) => void;\n\n _produceEventsWhenUpdatingStatus: <K extends keyof NamespaceData>(\n namespace: NamespaceItem,\n id: string,\n key: K,\n value: NamespaceData[K]\n ) => void;\n}\ninterface NamespaceSelectors {\n getNamespaceData(storeId: string): NamespaceData;\n}\n\nexport type NamespaceStore = NamespaceState &\n NamespaceActions &\n NamespaceSelectors;\ntype NamespaceStateCreator = StateCreator<State, [], [], NamespaceStore>;\n\nconst namespacesStore: NamespaceStateCreator = (set, get) => ({\n events: new ConsumableEvents(),\n\n list: {},\n addNamespace: (id, info) => {\n const data: NamespaceData = {\n accounts: null,\n network: null,\n connected: false,\n connecting: false,\n };\n\n const item = {\n data,\n error: '',\n info,\n };\n\n set(\n produce((state: State) => {\n state.namespaces.list[id] = item;\n })\n );\n },\n updateStatus: (id, key, value) => {\n const ns = get().namespaces.list[id];\n if (!ns) {\n throw new Error(`No namespace with '${id}' found.`);\n }\n\n get().namespaces._produceEventsWhenUpdatingStatus(ns, id, key, value);\n\n // Updating state\n set(\n produce((state: State) => {\n state.namespaces.list[id].data[key] = value;\n })\n );\n },\n getNamespaceData(storeId) {\n return namespaceStateSelector(get(), storeId);\n },\n\n _produceEventsWhenUpdatingStatus: (namespace, id, key, value) => {\n if (key === 'accounts') {\n // check for both null and empty array\n const isAccountsEmpty =\n Object.is(value, null) || (Array.isArray(value) && value.length === 0);\n\n if (isAccountsEmpty) {\n const currentConnectedStatus = get().namespaces.list[id].data.connected;\n if (currentConnectedStatus) {\n const event: NamespaceDisconnectedEvent = {\n type: 'namespace_disconnected',\n provider: namespace.info.providerId,\n namespace: namespace.info.namespaceId,\n };\n\n get().namespaces.events.push(event);\n }\n // Skip emitting disconnect event, if the `connected` is false\n } else {\n const currentAccounts = get().namespaces.list[id].data.accounts;\n\n if (!currentAccounts) {\n const event: NamespaceConnectedEvent = {\n type: 'namespace_connected',\n provider: namespace.info.providerId,\n namespace: namespace.info.namespaceId,\n accounts: value as string[],\n };\n\n get().namespaces.events.push(event);\n } else {\n const areSameAccounts =\n currentAccounts.sort().toString() ===\n (value as string[]).sort().toString();\n\n if (!areSameAccounts) {\n const event: NamespaceSwitchedAccountEvent = {\n type: 'namespace_account_switched',\n provider: namespace.info.providerId,\n namespace: namespace.info.namespaceId,\n previousAccounts: currentAccounts,\n accounts: value as string[],\n };\n\n get().namespaces.events.push(event);\n }\n }\n }\n } else if (key === 'network') {\n const currentNetwork = get().namespaces.list[id].data.network;\n\n const event: NamespaceSwitchedNetworkEvent = {\n type: 'namespace_network_switched',\n provider: namespace.info.providerId,\n namespace: namespace.info.namespaceId,\n network: value as string,\n previousNetwork: currentNetwork,\n };\n\n get().namespaces.events.push(event);\n }\n },\n});\n\nexport { namespacesStore };\n", "export type NamespaceDisconnectedEvent = {\n type: 'namespace_disconnected';\n provider: string;\n namespace: string;\n};\n\nexport type NamespaceConnectedEvent = {\n type: 'namespace_connected';\n provider: string;\n namespace: string;\n accounts: string[];\n};\n\nexport type NamespaceSwitchedAccountEvent = {\n type: 'namespace_account_switched';\n provider: string;\n namespace: string;\n accounts: string[];\n previousAccounts: string[];\n};\n\nexport type NamespaceSwitchedNetworkEvent = {\n type: 'namespace_network_switched';\n provider: string;\n namespace: string;\n network: string;\n previousNetwork: string | null;\n};\n\nexport type ProviderDetectedEvent = {\n type: 'provider_detected';\n provider: string;\n};\n\nexport type ProviderConnectingEvent = {\n type: 'provider_connecting';\n provider: string;\n value: boolean;\n};\n\nexport type ProviderConnectedEvent = {\n type: 'provider_connected';\n provider: string;\n};\n\nexport type ProviderDisconnectedEvent = {\n type: 'provider_disconnected';\n provider: string;\n};\n\nexport type Event =\n | NamespaceDisconnectedEvent\n | NamespaceConnectedEvent\n | NamespaceSwitchedAccountEvent\n | NamespaceSwitchedNetworkEvent\n | ProviderDetectedEvent\n | ProviderConnectingEvent\n | ProviderConnectedEvent\n | ProviderDisconnectedEvent;\n\n/**\n *\n * Keeping an array of Event and when iterates over its values, it will be removed (consume) from the array.\n *\n */\nexport class ConsumableEvents {\n #data: Event[] = [];\n\n push(val: Event) {\n this.#data.push(val);\n }\n\n [Symbol.iterator](): Iterator<Event> {\n return {\n next: (): IteratorResult<Event> => {\n if (this.#data.length == 0) {\n return { done: true, value: undefined };\n }\n\n // Typescript can not narrow the type, but we have a runtime check to ensure it will never be an empty list\n const value = this.#data.shift()!;\n return {\n done: false,\n value,\n };\n },\n };\n }\n}\n", "import type { Namespace } from '../../namespaces/common/types.js';\nimport type { State as InternalProviderState } from '../provider/mod.js';\nimport type { BlockchainMeta } from 'rango-types';\nimport type { StateCreator } from 'zustand';\n\nimport { produce } from 'immer';\n\nimport { ConsumableEvents, type ProviderDetectedEvent } from './events.js';\nimport { guessProviderStateSelector, type State } from './mod.js';\n\ntype Browsers = 'firefox' | 'chrome' | 'edge' | 'brave' | 'homepage';\ntype Property<N extends string, V> = { name: N; value: V };\n\ntype NamespacesProperty = Property<\n 'namespaces',\n {\n selection: 'single' | 'multiple';\n data: {\n label: string;\n id: string;\n value: Namespace;\n unsupported?: boolean;\n getSupportedChains: (chains: BlockchainMeta[]) => BlockchainMeta[];\n }[];\n }\n>;\ntype DerivationPathProperty = Property<\n 'derivationPath',\n {\n data: {\n id: string;\n label: string;\n namespace: Namespace;\n generateDerivationPath: (index: string) => string;\n }[];\n }\n>;\ntype DetailsProperty = Property<\n 'details',\n {\n mobileWallet?: boolean;\n showOnMobile?: boolean;\n isContractWallet?: boolean;\n }\n>;\n\nexport type ProviderInfo = {\n name: string;\n icon: string;\n extensions: Partial<Record<Browsers, string>>;\n properties?: Array<\n NamespacesProperty | DerivationPathProperty | DetailsProperty\n >;\n};\n\nexport interface ProviderConfig {\n info: ProviderInfo;\n}\n\ninterface ProviderData {\n installed: boolean;\n}\n\ninterface ProviderItem {\n config: ProviderConfig;\n data: ProviderData;\n error: unknown;\n}\n\ntype ProviderState = {\n events: ConsumableEvents;\n list: Record<string, ProviderItem>;\n};\ninterface ProviderActions {\n addProvider: (id: string, config: ProviderConfig) => void;\n removeProvider: (id: string) => void;\n updateStatus: <K extends keyof ProviderData>(\n id: string,\n key: K,\n value: ProviderData[K]\n ) => void;\n\n _produceEventsWhenUpdatingStatus: <K extends keyof ProviderData>(\n provider: ProviderItem,\n id: string,\n key: K,\n value: ProviderData[K]\n ) => void;\n}\n\ninterface ProviderSelectors {\n /**\n * Provider has a limited state to itself, to be compatible with legacy, we try to produce same object as legacy\n * which includes namespace state as well.\n */\n guessNamespacesState: (id: string) => InternalProviderState;\n}\n\nexport type ProviderStore = ProviderState & ProviderActions & ProviderSelectors;\ntype ProvidersStateCreator = StateCreator<State, [], [], ProviderStore>;\n\nconst providersStore: ProvidersStateCreator = (set, get) => ({\n events: new ConsumableEvents(),\n\n list: {},\n addProvider: (id, config) => {\n const item = {\n data: {\n installed: false,\n },\n error: '',\n config,\n };\n\n set(\n produce((state: State) => {\n state.providers.list[id] = item;\n })\n );\n },\n removeProvider: (id) => {\n set(\n produce((state: State) => {\n delete state.providers.list[id];\n })\n );\n },\n updateStatus: (id, key, value) => {\n const provider = get().providers.list[id];\n if (!provider) {\n throw new Error(`No namespace namespace with '${id}' found.`);\n }\n\n get().providers._produceEventsWhenUpdatingStatus(provider, id, key, value);\n\n set(\n produce((state: State) => {\n state.providers.list[id].data[key] = value;\n })\n );\n },\n guessNamespacesState: (providerId: string): InternalProviderState => {\n return guessProviderStateSelector(get(), providerId);\n },\n\n _produceEventsWhenUpdatingStatus: (_provider, id, key, _value) => {\n if (key === 'installed') {\n const event: ProviderDetectedEvent = {\n type: 'provider_detected',\n provider: id,\n };\n\n get().providers.events.push(event);\n }\n },\n});\n\nexport { providersStore };\n"],
5
- "mappings": "+EAgBO,SAASA,EACdC,EACAC,EACuB,CAKvB,IAAMC,EAAgBF,EAAM,WAAW,KACjCG,EAA4B,OAAO,KAAKD,CAAa,EAAE,OAC1DE,GAAQF,EAAcE,CAAG,EAAE,KAAK,aAAeH,CAClD,EAGMI,EAAY,CAAC,CAACL,EAAM,UAAU,KAAKC,CAAU,GAAG,KAAK,UAMrDK,EACJH,EAA0B,OAAS,EAC/BA,EAA0B,KACvBC,GAAQF,EAAcE,CAAG,EAAE,KAAK,SACnC,EACA,GACAG,EACJJ,EAA0B,OAAS,EAC/BA,EAA0B,KACvBC,GAAQF,EAAcE,CAAG,EAAE,KAAK,UACnC,EACA,GAEN,MAAO,CACL,UAAAC,EACA,UAAAC,EACA,WAAAC,CACF,CACF,CAtCgBC,EAAAT,EAAA,8BAwCT,SAASU,EAAuBT,EAAcU,EAAiB,CACpE,OAAOV,EAAM,WAAW,KAAKU,CAAO,EAAE,IACxC,CAFgBF,EAAAC,EAAA,0BCtDhB,OAAS,eAAeE,MAA0B,kBCmB3C,SAASC,EAAOC,EAAwB,CAC7C,IAAMC,EACJC,EAACF,GAAWG,GAAa,CACvB,IAAMC,EAAkBF,EAAA,CACtBG,EACAC,EACAC,IACG,CACH,QAAWC,KAAMH,EACfF,EAASK,EAAIF,EAAOC,CAAS,CAEjC,EARwB,mBAcxB,OAAAP,EAAM,UAAU,CAACM,EAAOC,IAAc,CACpC,IAAME,EAAaC,EAAcJ,EAAOC,CAAS,EAE3CI,EAAkB,CAAC,GADVC,EAAiBN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D,CACF,EAEAJ,EACEM,EAASC,GAAiB,CACxBA,EAAM,UAAU,KAAKJ,CAAE,EAAIE,CAC7B,CAAC,CACH,CACF,EACA,eAAiBF,GAAO,CACtBH,EACEM,EAASC,GAAiB,CACxB,OAAOA,EAAM,UAAU,KAAKJ,CAAE,CAChC,CAAC,CACH,CACF,EACA,aAAc,CAACA,EAAIK,EAAKC,IAAU,CAChC,IAAMC,EAAWT,EAAI,EAAE,UAAU,KAAKE,CAAE,EACxC,GAAI,CAACO,EACH,MAAM,IAAI,MAAM,gCAAgCP,CAAE,UAAU,EAG9DF,EAAI,EAAE,UAAU,iCAAiCS,EAAUP,EAAIK,EAAKC,CAAK,EAEzET,EACEM,EAASC,GAAiB,CACxBA,EAAM,UAAU,KAAKJ,CAAE,EAAE,KAAKK,CAAG,EAAIC,CACvC,CAAC,CACH,CACF,EACA,qBAAuBE,GACdC,EAA2BX,EAAI,EAAGU,CAAU,EAGrD,iCAAkC,CAACE,EAAWV,EAAIK,EAAKM,IAAW,CAChE,GAAIN,IAAQ,YAAa,CACvB,IAAMO,EAA+B,CACnC,KAAM,oBACN,SAAUZ,CACZ,EAEAF,EAAI,EAAE,UAAU,OAAO,KAAKc,CAAK,CACnC,CACF,CACF,GAtD8C,kBLlFvC,IAAMC,EAAcC,EAAA,IAAa,CACtC,IAAMC,EAAQC,EAA0B,IAAIC,KACnC,CACL,IAAKC,EAAS,GAAGD,CAAG,EACpB,UAAWE,EAAe,GAAGF,CAAG,EAChC,WAAYG,EAAgB,GAAGH,CAAG,CACpC,EACD,EAED,OAAOI,EAAON,CAAK,CACrB,EAV2B",
4
+ "sourcesContent": ["/**\n * Note: Zustand has some difficulty when you are trying to `previous` state on `subscribe`.\n * If these selectors define inside store directly and use `get()` for accessing state, it will get the latest state\n * instead of previous state which desired.\n * So make them a helper will let us to reuse them both in store and outside of store in a `subscribe`.\n */\nimport type { State } from '../mod.js';\nimport type { State as InternalProviderState } from '../provider/mod.js';\n\n/**\n * Legacy provider state includes `connecting` and `connected` values. It hadn't a separation layer for `namespaces`.\n * For compatibility reasons, we should produce these two values somehow.\n *\n * Currently, We return `true` if any of namespaces return true. We are missing failed namespace here.\n * But if we want to solve that, we should migrate our client code to use `namespace` state directly and not from `provider`\n */\nexport function guessProviderStateSelector(\n state: State,\n providerId: string\n): InternalProviderState {\n /*\n * We keep namespaces in a separate branch than providers.\n * We should look at all of them and find all the namespaces that for our current proivder.\n */\n const allNamespaces = state.namespaces.list;\n const currentProviderNamespaces = Object.keys(allNamespaces).filter(\n (key) => allNamespaces[key].info.providerId === providerId\n );\n\n // Returning provider state value directly.\n const installed = !!state.providers.list[providerId]?.data.installed;\n\n /*\n * If any namespaces returns `true`, we consider the whole provider for this field to be `true`.\n * it has a downside regarding errors which explained on top of the function.\n */\n const connected =\n currentProviderNamespaces.length > 0\n ? currentProviderNamespaces.some(\n (key) => allNamespaces[key].data.connected\n )\n : false;\n const connecting =\n currentProviderNamespaces.length > 0\n ? currentProviderNamespaces.some(\n (key) => allNamespaces[key].data.connecting\n )\n : false;\n\n return {\n installed,\n connected,\n connecting,\n };\n}\n\nexport function namespaceStateSelector(state: State, storeId: string) {\n return state.namespaces.list[storeId].data;\n}\n", "import type { StoreApi } from 'zustand/vanilla';\n\nimport { createStore as createZustandStore } from 'zustand/vanilla';\n\nimport { extend, type Store } from './extend.js';\nimport { hubStore, type HubStore } from './hub.js';\nimport { namespacesStore, type NamespaceStore } from './namespaces.js';\nimport { providersStore, type ProviderStore } from './providers.js';\n\n/************ State ************/\n\nexport interface State {\n hub: HubStore;\n providers: ProviderStore;\n namespaces: NamespaceStore;\n}\n\nexport type RawStore = StoreApi<State>;\n\nexport const createStore = (): Store => {\n const store = createZustandStore<State>((...api) => {\n return {\n hub: hubStore(...api),\n providers: providersStore(...api),\n namespaces: namespacesStore(...api),\n };\n });\n\n return extend(store);\n};\n", "import type {\n Event,\n ProviderConnectedEvent,\n ProviderConnectingEvent,\n ProviderDisconnectedEvent,\n} from './events.js';\nimport type { RawStore, State } from './store.js';\n\nimport { guessProviderStateSelector } from './selectors.js';\n\nexport interface Store extends Omit<RawStore, 'subscribe'> {\n subscribe(listener: (event: Event, state: State, prevState: State) => void): {\n flushEvents(): void;\n };\n}\n\n/**\n * Zustand's store provides a set of built-in functionalities,\n * but it may not meet all our requirements.\n * This function modifies the interface and adds or updates the available methods.\n */\nexport function extend(store: RawStore): Store {\n const extendedSubscribe: (store: RawStore) => Store['subscribe'] =\n (store) => (listener) => {\n const executeListener = (\n events: Event[],\n state: State,\n prevState: State\n ) => {\n for (const ev of events) {\n listener(ev, state, prevState);\n }\n };\n\n /*\n * only known changes will fire event for lib users\n * so all the changes in store won't trigger a user-face event\n */\n store.subscribe((state, prevState) => {\n const eventsLike = getEventsLike(state, prevState);\n const events = tryConsumeEvents(state);\n const allQueuedEvents = [...events, ...eventsLike];\n executeListener(allQueuedEvents, state, prevState);\n });\n\n return {\n /**\n * Manually run pending events.\n * This useful when use `subscribe` method after sometime and when store initialized.\n *\n * Note: Please consider both current and previous state will be same and we don't have access to previous state in a such scenario.\n */\n flushEvents: () => {\n const state = store.getState();\n const events = tryConsumeEvents(state);\n executeListener(events, state, state);\n },\n };\n };\n\n return new Proxy(store, {\n get: function (target, prop, receiver) {\n if (prop === 'subscribe') {\n return extendedSubscribe(target);\n }\n return Reflect.get(target, prop, receiver);\n },\n }) as unknown as Store;\n}\n\n/**\n * Retrieves the ConsumableEvent from the store and returns its values.\n * The values will be consumed by iterating over the field.\n */\nfunction tryConsumeEvents(state: State): Event[] {\n return [...state.providers.events, ...state.namespaces.events];\n}\n\n/**\n * In certain cases, adding events to the store is not possible (e.g., namespace or provider layer).\n * In these cases, we observe store changes and treat specific patterns as events when detected.\n *\n * Note: This approach should be avoided in most cases. It is used here to maintain backward compatibility\n * with the provider's legacy interface.\n */\nfunction getEventsLike(state: State, prevState: State): Event[] {\n const events: Event[] = [];\n\n for (const providerId of Object.keys(state.providers.list)) {\n const currentProviderState = guessProviderStateSelector(state, providerId);\n const previousProviderState = guessProviderStateSelector(\n prevState,\n providerId\n );\n\n if (previousProviderState.connecting !== currentProviderState.connecting) {\n const ev: ProviderConnectingEvent = {\n type: 'provider_connecting',\n provider: providerId,\n value: currentProviderState.connecting,\n };\n events.push(ev);\n }\n\n if (!previousProviderState.connected && currentProviderState.connected) {\n const ev: ProviderConnectedEvent = {\n type: 'provider_connected',\n provider: providerId,\n };\n\n events.push(ev);\n }\n\n if (previousProviderState.connected && !currentProviderState.connected) {\n const ev: ProviderDisconnectedEvent = {\n type: 'provider_disconnected',\n provider: providerId,\n };\n\n events.push(ev);\n }\n }\n\n return events;\n}\n", "/************ Hub ************/\n\nimport type { State } from './mod.js';\nimport type { StateCreator } from 'zustand';\n\ntype HubConfig = object;\n\nexport interface HubStore {\n config: HubConfig;\n}\n\ntype HubStateCreator = StateCreator<State, [], [], HubStore>;\n\nconst hubStore: HubStateCreator = () => ({\n config: {},\n});\n\nexport { hubStore };\n", "/************ Namespace ************/\n\nimport type { StateCreator } from 'zustand';\n\nimport { produce } from 'immer';\n\nimport {\n ConsumableEvents,\n type NamespaceConnectedEvent,\n type NamespaceDisconnectedEvent,\n type NamespaceSwitchedAccountEvent,\n type NamespaceSwitchedNetworkEvent,\n} from './events.js';\nimport { namespaceStateSelector, type State } from './mod.js';\n\n// Currently, namespace doesn't has any config.\nexport type NamespaceConfig = object;\n\nexport interface NamespaceData {\n accounts: null | string[];\n network: null | string;\n connected: boolean;\n connecting: boolean;\n}\n\ninterface NamespaceInfo {\n providerId: string;\n namespaceId: string;\n}\n\ninterface NamespaceItem {\n info: NamespaceInfo;\n data: NamespaceData;\n error: unknown;\n}\n\ntype NamespaceState = {\n events: InstanceType<typeof ConsumableEvents>;\n list: Record<string, NamespaceItem>;\n};\n\ninterface NamespaceActions {\n addNamespace: (id: string, config: NamespaceInfo) => void;\n updateStatus: <K extends keyof NamespaceData>(\n id: string,\n key: K,\n value: NamespaceData[K]\n ) => void;\n\n _produceEventsWhenUpdatingStatus: <K extends keyof NamespaceData>(\n namespace: NamespaceItem,\n id: string,\n key: K,\n value: NamespaceData[K]\n ) => void;\n}\ninterface NamespaceSelectors {\n getNamespaceData(storeId: string): NamespaceData;\n}\n\nexport type NamespaceStore = NamespaceState &\n NamespaceActions &\n NamespaceSelectors;\ntype NamespaceStateCreator = StateCreator<State, [], [], NamespaceStore>;\n\nconst namespacesStore: NamespaceStateCreator = (set, get) => ({\n events: new ConsumableEvents(),\n\n list: {},\n addNamespace: (id, info) => {\n const data: NamespaceData = {\n accounts: null,\n network: null,\n connected: false,\n connecting: false,\n };\n\n const item = {\n data,\n error: '',\n info,\n };\n\n set(\n produce((state: State) => {\n state.namespaces.list[id] = item;\n })\n );\n },\n updateStatus: (id, key, value) => {\n const ns = get().namespaces.list[id];\n if (!ns) {\n throw new Error(`No namespace with '${id}' found.`);\n }\n\n get().namespaces._produceEventsWhenUpdatingStatus(ns, id, key, value);\n\n // Updating state\n set(\n produce((state: State) => {\n state.namespaces.list[id].data[key] = value;\n })\n );\n },\n getNamespaceData(storeId) {\n return namespaceStateSelector(get(), storeId);\n },\n\n _produceEventsWhenUpdatingStatus: (namespace, id, key, value) => {\n if (key === 'accounts') {\n // check for both null and empty array\n const isAccountsEmpty =\n Object.is(value, null) || (Array.isArray(value) && value.length === 0);\n\n if (isAccountsEmpty) {\n const currentConnectedStatus = get().namespaces.list[id].data.connected;\n if (currentConnectedStatus) {\n const event: NamespaceDisconnectedEvent = {\n type: 'namespace_disconnected',\n provider: namespace.info.providerId,\n namespace: namespace.info.namespaceId,\n };\n\n get().namespaces.events.push(event);\n }\n // Skip emitting disconnect event, if the `connected` is false\n } else {\n const currentAccounts = get().namespaces.list[id].data.accounts;\n\n if (!currentAccounts) {\n const event: NamespaceConnectedEvent = {\n type: 'namespace_connected',\n provider: namespace.info.providerId,\n namespace: namespace.info.namespaceId,\n accounts: value as string[],\n };\n\n get().namespaces.events.push(event);\n } else {\n const areSameAccounts =\n currentAccounts.sort().toString() ===\n (value as string[]).sort().toString();\n\n if (!areSameAccounts) {\n const event: NamespaceSwitchedAccountEvent = {\n type: 'namespace_account_switched',\n provider: namespace.info.providerId,\n namespace: namespace.info.namespaceId,\n previousAccounts: currentAccounts,\n accounts: value as string[],\n };\n\n get().namespaces.events.push(event);\n }\n }\n }\n } else if (key === 'network') {\n const currentNetwork = get().namespaces.list[id].data.network;\n\n const event: NamespaceSwitchedNetworkEvent = {\n type: 'namespace_network_switched',\n provider: namespace.info.providerId,\n namespace: namespace.info.namespaceId,\n network: value as string,\n previousNetwork: currentNetwork,\n };\n\n get().namespaces.events.push(event);\n }\n },\n});\n\nexport { namespacesStore };\n", "export type NamespaceDisconnectedEvent = {\n type: 'namespace_disconnected';\n provider: string;\n namespace: string;\n};\n\nexport type NamespaceConnectedEvent = {\n type: 'namespace_connected';\n provider: string;\n namespace: string;\n accounts: string[];\n};\n\nexport type NamespaceSwitchedAccountEvent = {\n type: 'namespace_account_switched';\n provider: string;\n namespace: string;\n accounts: string[];\n previousAccounts: string[];\n};\n\nexport type NamespaceSwitchedNetworkEvent = {\n type: 'namespace_network_switched';\n provider: string;\n namespace: string;\n network: string;\n previousNetwork: string | null;\n};\n\nexport type ProviderDetectedEvent = {\n type: 'provider_detected';\n provider: string;\n};\n\nexport type ProviderConnectingEvent = {\n type: 'provider_connecting';\n provider: string;\n value: boolean;\n};\n\nexport type ProviderConnectedEvent = {\n type: 'provider_connected';\n provider: string;\n};\n\nexport type ProviderDisconnectedEvent = {\n type: 'provider_disconnected';\n provider: string;\n};\n\nexport type Event =\n | NamespaceDisconnectedEvent\n | NamespaceConnectedEvent\n | NamespaceSwitchedAccountEvent\n | NamespaceSwitchedNetworkEvent\n | ProviderDetectedEvent\n | ProviderConnectingEvent\n | ProviderConnectedEvent\n | ProviderDisconnectedEvent;\n\n/**\n *\n * Keeping an array of Event and when iterates over its values, it will be removed (consume) from the array.\n *\n */\nexport class ConsumableEvents {\n #data: Event[] = [];\n\n push(val: Event) {\n this.#data.push(val);\n }\n\n [Symbol.iterator](): Iterator<Event> {\n return {\n next: (): IteratorResult<Event> => {\n if (this.#data.length == 0) {\n return { done: true, value: undefined };\n }\n\n // Typescript can not narrow the type, but we have a runtime check to ensure it will never be an empty list\n const value = this.#data.shift()!;\n return {\n done: false,\n value,\n };\n },\n };\n }\n}\n", "import type { Namespace } from '../../namespaces/common/types.js';\nimport type { State as InternalProviderState } from '../provider/mod.js';\nimport type { BlockchainMeta, SignerFactory } from 'rango-types';\nimport type { StateCreator } from 'zustand';\n\nimport { produce } from 'immer';\n\nimport { ConsumableEvents, type ProviderDetectedEvent } from './events.js';\nimport { guessProviderStateSelector, type State } from './mod.js';\n\ntype Browsers = 'firefox' | 'chrome' | 'edge' | 'brave' | 'homepage';\ntype Property<N extends string, V> = { name: N; value: V };\n\ntype NamespacesProperty = Property<\n 'namespaces',\n {\n selection: 'single' | 'multiple';\n data: {\n label: string;\n id: string;\n value: Namespace;\n unsupported?: boolean;\n getSupportedChains: (chains: BlockchainMeta[]) => BlockchainMeta[];\n }[];\n }\n>;\ntype DerivationPathProperty = Property<\n 'derivationPath',\n {\n data: {\n id: string;\n label: string;\n namespace: Namespace;\n generateDerivationPath: (index: string) => string;\n }[];\n }\n>;\ntype DetailsProperty = Property<\n 'details',\n {\n mobileWallet?: boolean;\n showOnMobile?: boolean;\n isContractWallet?: boolean;\n }\n>;\ntype SignersProperty = Property<\n 'signers',\n {\n getSigners: () => Promise<SignerFactory>;\n }\n>;\n\nexport type ProviderInfo = {\n name: string;\n icon: string;\n extensions: Partial<Record<Browsers, string>>;\n properties?: Array<\n | NamespacesProperty\n | DerivationPathProperty\n | DetailsProperty\n | SignersProperty\n >;\n};\n\nexport interface ProviderConfig {\n info: ProviderInfo;\n}\n\ninterface ProviderData {\n installed: boolean;\n}\n\ninterface ProviderItem {\n config: ProviderConfig;\n data: ProviderData;\n error: unknown;\n}\n\ntype ProviderState = {\n events: ConsumableEvents;\n list: Record<string, ProviderItem>;\n};\ninterface ProviderActions {\n addProvider: (id: string, config: ProviderConfig) => void;\n removeProvider: (id: string) => void;\n updateStatus: <K extends keyof ProviderData>(\n id: string,\n key: K,\n value: ProviderData[K]\n ) => void;\n\n _produceEventsWhenUpdatingStatus: <K extends keyof ProviderData>(\n provider: ProviderItem,\n id: string,\n key: K,\n value: ProviderData[K]\n ) => void;\n}\n\ninterface ProviderSelectors {\n /**\n * Provider has a limited state to itself, to be compatible with legacy, we try to produce same object as legacy\n * which includes namespace state as well.\n */\n guessNamespacesState: (id: string) => InternalProviderState;\n}\n\nexport type ProviderStore = ProviderState & ProviderActions & ProviderSelectors;\ntype ProvidersStateCreator = StateCreator<State, [], [], ProviderStore>;\n\nconst providersStore: ProvidersStateCreator = (set, get) => ({\n events: new ConsumableEvents(),\n\n list: {},\n addProvider: (id, config) => {\n const item = {\n data: {\n installed: false,\n },\n error: '',\n config,\n };\n\n set(\n produce((state: State) => {\n state.providers.list[id] = item;\n })\n );\n },\n removeProvider: (id) => {\n set(\n produce((state: State) => {\n delete state.providers.list[id];\n })\n );\n },\n updateStatus: (id, key, value) => {\n const provider = get().providers.list[id];\n if (!provider) {\n throw new Error(`No namespace namespace with '${id}' found.`);\n }\n\n get().providers._produceEventsWhenUpdatingStatus(provider, id, key, value);\n\n set(\n produce((state: State) => {\n state.providers.list[id].data[key] = value;\n })\n );\n },\n guessNamespacesState: (providerId: string): InternalProviderState => {\n return guessProviderStateSelector(get(), providerId);\n },\n\n _produceEventsWhenUpdatingStatus: (_provider, id, key, _value) => {\n if (key === 'installed') {\n const event: ProviderDetectedEvent = {\n type: 'provider_detected',\n provider: id,\n };\n\n get().providers.events.push(event);\n }\n },\n});\n\nexport { providersStore };\n"],
5
+ "mappings": "+EAgBO,SAASA,EACdC,EACAC,EACuB,CAKvB,IAAMC,EAAgBF,EAAM,WAAW,KACjCG,EAA4B,OAAO,KAAKD,CAAa,EAAE,OAC1DE,GAAQF,EAAcE,CAAG,EAAE,KAAK,aAAeH,CAClD,EAGMI,EAAY,CA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AKJ,CAAE,EAAE,KAAKK,CAAG,EAAIC,CACvC,CAAC,CACH,CACF,EACA,qBAAuBE,GACdC,EAA2BX,EAAI,EAAGU,CAAU,EAGrD,iCAAkC,CAACE,EAAWV,EAAIK,EAAKM,IAAW,CAChE,GAAIN,IAAQ,YAAa,CACvB,IAAMO,EAA+B,CACnC,KAAM,oBACN,SAAUZ,CACZ,EAEAF,EAAI,EAAE,UAAU,OAAO,KAAKc,CAAK,CACnC,CACF,CACF,GAtD8C,kBL3FvC,IAAMC,EAAcC,EAAA,IAAa,CACtC,IAAMC,EAAQC,EAA0B,IAAIC,KACnC,CACL,IAAKC,EAAS,GAAGD,CAAG,EACpB,UAAWE,EAAe,GAAGF,CAAG,EAChC,WAAYG,EAAgB,GAAGH,CAAG,CACpC,EACD,EAED,OAAOI,EAAON,CAAK,CACrB,EAV2B",
6
6
  "names": ["guessProviderStateSelector", "state", "providerId", "allNamespaces", "currentProviderNamespaces", "key", "installed", "connected", "connecting", "__name", "namespaceStateSelector", "storeId", "createZustandStore", "extend", "store", "extendedSubscribe", "__name", "listener", "executeListener", "events", "state", "prevState", "ev", "eventsLike", "getEventsLike", "allQueuedEvents", "tryConsumeEvents", "target", "prop", "receiver", "providerId", "currentProviderState", "guessProviderStateSelector", "previousProviderState", "hubStore", "__name", "produce", "ConsumableEvents", "__name", "#data", "val", "namespacesStore", "__name", "set", "get", "ConsumableEvents", "id", "info", "item", "produce", "state", "key", "value", "ns", "storeId", "namespaceStateSelector", "namespace", "event", "currentAccounts", "currentNetwork", "produce", "providersStore", "__name", "set", "get", "ConsumableEvents", "id", "config", "item", "produce", "state", "key", "value", "provider", "providerId", "guessProviderStateSelector", "_provider", "_value", "event", "createStore", "__name", "store", "createZustandStore", "api", "hubStore", "providersStore", "namespacesStore", "extend"]
7
7
  }
@@ -1,6 +1,6 @@
1
1
  import type { Namespace } from '../../namespaces/common/types.js';
2
2
  import type { State as InternalProviderState } from '../provider/mod.js';
3
- import type { BlockchainMeta } from 'rango-types';
3
+ import type { BlockchainMeta, SignerFactory } from 'rango-types';
4
4
  import type { StateCreator } from 'zustand';
5
5
  import { ConsumableEvents } from './events.js';
6
6
  import { type State } from './mod.js';
@@ -32,11 +32,14 @@ type DetailsProperty = Property<'details', {
32
32
  showOnMobile?: boolean;
33
33
  isContractWallet?: boolean;
34
34
  }>;
35
+ type SignersProperty = Property<'signers', {
36
+ getSigners: () => Promise<SignerFactory>;
37
+ }>;
35
38
  export type ProviderInfo = {
36
39
  name: string;
37
40
  icon: string;
38
41
  extensions: Partial<Record<Browsers, string>>;
39
- properties?: Array<NamespacesProperty | DerivationPathProperty | DetailsProperty>;
42
+ properties?: Array<NamespacesProperty | DerivationPathProperty | DetailsProperty | SignersProperty>;
40
43
  };
41
44
  export interface ProviderConfig {
42
45
  info: ProviderInfo;
@@ -1 +1 @@
1
- {"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../../src/hub/store/providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,IAAI,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,EAAE,gBAAgB,EAA8B,MAAM,aAAa,CAAC;AAC3E,OAAO,EAA8B,KAAK,KAAK,EAAE,MAAM,UAAU,CAAC;AAElE,KAAK,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC;AACrE,KAAK,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,IAAI;IAAE,IAAI,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAE3D,KAAK,kBAAkB,GAAG,QAAQ,CAChC,YAAY,EACZ;IACE,SAAS,EAAE,Q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M,KAAK,qBAAqB,CAAC;CAC7D;AAED,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG,eAAe,GAAG,iBAAiB,CAAC;AAChF,KAAK,qBAAqB,GAAG,YAAY,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,aAAa,CAAC,CAAC;AAExE,QAAA,MAAM,cAAc,EAAE,qBAsDpB,CAAC;AAEH,OAAO,EAAE,cAAc,EAAE,CAAC"}
package/dist/mod.js CHANGED
@@ -1,2 +1,2 @@
1
- var D=Object.defineProperty;var a=(i,e)=>D(i,"name",{value:e,configurable:!0});function w(i){return i.constructor.name==="AsyncFunction"}a(w,"isAsync");function l(i,e){return`${i}$$${e}`}a(l,"generateStoreId");var y=a(i=>`Couldn't find "${i}" action. Are you sure you've added the action?`,"ACTION_NOT_FOUND_ERROR"),E=a(i=>`An error occurred during running ${i}`,"OR_ELSE_ACTION_FAILED_ERROR"),P=a(i=>`An error occurred during running before for "${i}" action`,"BEFORE_ACTION_FAILED_ERROR"),A="For setup store, you should set `store` first.";var u=class{static{a(this,"Namespace")}namespaceId;providerId;#e;#r=new Map;#n=new Map;#t=new Map;#o=new Map;#s=!1;#i;#c;constructor(e,t,r){let{configs:n,actions:o}=r;this.namespaceId=e,this.providerId=t,this.#c=n||new Map,this.#e=o,r.store&&this.store(r.store)}init(){if(this.#s)return;let e=this.#e.get("init");e&&e(this.#a()),this.#s=!0}state(){let e=this.#i;if(!e)throw new Error("You need to set your store using `.store` method first.");let t=this.#h();return[a(o=>{let s=e.getState().namespaces.getNamespaceData(t);return o?s[o]:s},"getState"),a((o,s)=>{e.getState().namespaces.updateStatus(t,o,s)},"setState")]}store(e){return this.#i&&console.warn("You've already set an store for your Namespace. Old store will be replaced by the new one."),this.#i=e,this.#l(),this}and_then(e,t){let r=this.#r.get(e)||[];return this.#r.set(e,r.concat(t)),this}or_else(e,t){let r=this.#n.get(e)||[];return this.#n.set(e,r.concat(t)),this}after(e,t,r){let n=this.#o.get(e)||[],o={hook:t,options:{context:r?.context}};return this.#o.set(e,n.concat(o)),this}before(e,t,r){let n=this.#t.get(e)||[],o={hook:t,options:{context:r?.context}};return this.#t.set(e,n.concat(o)),this}has(e){return!!this.#e.get(e)}run(e,...t){let r=this.#e.get(e);if(!r)throw new Error(y(e.toString()));return w(r)?this.#v(e,t):this.#d(e,t)}#d(e,t){try{this.#u(e)}catch(s){throw this.#p(e),new Error(P(e.toString()),{cause:s})}let r=this.#e.get(e);if(!r)throw new Error(y(e.toString()));let n=this.#a(),o;try{o=r(n,...t),o=this.#m(e,o)}catch(s){o=this.#f(e,s)}finally{this.#p(e)}return o}async#v(e,t){try{this.#u(e)}catch(o){throw this.#p(e),new Error(P(e.toString()),{cause:o})}let r=this.#e.get(e);if(!r)throw new Error(y(e.toString()));let n=this.#a();return await r(n,...t).then(o=>this.#m(e,o)).catch(o=>this.#f(e,o)).finally(()=>this.#p(e))}#p(e){let t=this.#o.get(e);t&&t.forEach(r=>{let n=r.options?.context||this.#a();r.hook(n)})}#u(e){let t=this.#t.get(e);t&&t.forEach(r=>{let n=r.options?.context||this.#a();r.hook(n)})}#m(e,t){let r=this.#r.get(e);if(r){let n=this.#a();t=r.reduce((o,s)=>s(n,o),t)}return t}#f(e,t){let r=this.#n.get(e);if(r)try{let n=this.#a();return r.reduce((o,s)=>s(n,o),t)}catch(n){if(n instanceof Error)throw n.cause=t,n;let o=E(`${e.toString()} for ${this.namespaceId} namespace.`),s=new Error(String(n),{cause:t});throw new Error(o,{cause:s})}else throw t}#l(){let e=this.#i;if(!e)throw new Error(A);let t=this.#h();e.getState().namespaces.addNamespace(t,{namespaceId:this.namespaceId,providerId:this.providerId})}#h(){return l(this.providerId,this.namespaceId)}#a(){return{state:this.state.bind(this),action:this.run.bind(this)}}};var V="1.0",m=class{static{a(this,"Provider")}id;version=V;#e;#r=!1;#n={};#t;#o;constructor(e,t,r,n){this.id=e,this.#o=r,this.#n=n?.extendInternalActions||{},this.#e=t,n?.store&&(this.#t=n.store,this.#i())}init(){if(this.#r)return;let e=this.#n.init;e&&e(this.#c()),this.#r=!0}state(){let e=this.#t;if(!e)throw new Error(`Any store detected for ${this.id}. You need to set your store using '.store' method first.`);return[a(n=>{let o=e.getState().providers.guessNamespacesState(this.id);if(!n)return o;switch(n){case"installed":case"connected":case"connecting":return o[n];default:throw new Error("Unhandled state for provider")}},"getState"),a((n,o)=>{switch(n){case"installed":return e.getState().providers.updateStatus(this.id,n,o);default:throw new Error(`Unhandled state update for provider. (provider id: ${this.id}, state name: ${n})`)}},"setState")]}store(e){return this.#t&&console.warn("You've already set an store for your Provider. Old store will be replaced by the new one."),this.#t=e,this.#i(),this}info(){let e=this.#t;return e?e.getState().providers.list[this.id].config.info:this.#o.info}getAll(){return this.#e}get(e){return this.#e.get(e)}findByNamespace(e){let t;return this.#e.forEach(r=>{r.namespaceId===e&&(t=r)}),t}before(e,t){return this.#s("before",e,t),this}after(e,t){return this.#s("after",e,t),this}#s(e,t,r){let n={state:this.state.bind(this)};return this.#e.forEach(o=>{if(e==="after")o.after(t,r,{context:n});else if(e==="before")o.before(t,r,{context:n});else throw new Error(`You hook name is invalid: ${e}`)}),this}#i(){let e=this.#t;if(!e)throw new Error("For setup store, you should set `store` first.");e.getState().providers.addProvider(this.id,this.#o),this.#e.forEach(t=>{t.store(e)})}#c(){return{state:this.state.bind(this)}}};var S=class{static{a(this,"Hub")}#e=new Map;#r;constructor(e){this.#r=e??{}}init(){this.runAll("init")}runAll(e){let t=[],r=this.#e.values();for(let n of r){let o={id:n.id,provider:void 0,namespaces:[]},s=n[e];typeof s=="function"&&(o.provider=s.call(n));let c=n.getAll().values();for(let p of c){let f=p[e];if(typeof f=="function"){let j=f();o.namespaces.push(j)}}t.push(o)}return t}add(e,t){return this.#r.store&&t.store(this.#r.store),this.#e.set(e,t),this}remove(e){if(!this.#e.get(e))throw new Error(`Provider not found: No provider exists with ID "${e}"`);return this.#r.store?.getState().providers.removeProvider(e),this.#e.delete(e),this}get(e){return this.#e.get(e)}getAll(){return this.#e}state(){let e=this.runAll("state"),t={};return e.forEach(r=>{let n=[];r.namespaces.forEach(s=>{let[c]=s;n.push(c())});let[o]=r.provider;t[r.id]={...o()||{},namespaces:n}}),t}};function d(i,e){let t=i.namespaces.list,r=Object.keys(t).filter(c=>t[c].info.providerId===e),n=!!i.providers.list[e]?.data.installed,o=r.length>0?r.some(c=>t[c].data.connected):!1,s=r.length>0?r.some(c=>t[c].data.connecting):!1;return{installed:n,connected:o,connecting:s}}a(d,"guessProviderStateSelector");function v(i,e){return i.namespaces.list[e].data}a(v,"namespaceStateSelector");import{createStore as H}from"zustand/vanilla";function k(i){let e=a(t=>r=>{let n=a((o,s,c)=>{for(let p of o)r(p,s,c)},"executeListener");return t.subscribe((o,s)=>{let c=W(o,s),f=[...T(o),...c];n(f,o,s)}),{flushEvents:()=>{let o=t.getState(),s=T(o);n(s,o,o)}}},"extendedSubscribe");return new Proxy(i,{get:function(t,r,n){return r==="subscribe"?e(t):Reflect.get(t,r,n)}})}a(k,"extend");function T(i){return[...i.providers.events,...i.namespaces.events]}a(T,"tryConsumeEvents");function W(i,e){let t=[];for(let r of Object.keys(i.providers.list)){let n=d(i,r),o=d(e,r);if(o.connecting!==n.connecting){let s={type:"provider_connecting",provider:r,value:n.connecting};t.push(s)}if(!o.connected&&n.connected){let s={type:"provider_connected",provider:r};t.push(s)}if(o.connected&&!n.connected){let s={type:"provider_disconnected",provider:r};t.push(s)}}return t}a(W,"getEventsLike");var I=a(()=>({config:{}}),"hubStore");import{produce as K}from"immer";var h=class{static{a(this,"ConsumableEvents")}#e=[];push(e){this.#e.push(e)}[Symbol.iterator](){return{next:()=>this.#e.length==0?{done:!0,value:void 0}:{done:!1,value:this.#e.shift()}}}};var O=a((i,e)=>({events:new h,list:{},addNamespace:(t,r)=>{let o={data:{accounts:null,network:null,connected:!1,connecting:!1},error:"",info:r};i(K(s=>{s.namespaces.list[t]=o}))},updateStatus:(t,r,n)=>{let o=e().namespaces.list[t];if(!o)throw new Error(`No namespace with '${t}' found.`);e().namespaces._produceEventsWhenUpdatingStatus(o,t,r,n),i(K(s=>{s.namespaces.list[t].data[r]=n}))},getNamespaceData(t){return v(e(),t)},_produceEventsWhenUpdatingStatus:(t,r,n,o)=>{if(n==="accounts")if(Object.is(o,null)||Array.isArray(o)&&o.length===0){if(e().namespaces.list[r].data.connected){let p={type:"namespace_disconnected",provider:t.info.providerId,namespace:t.info.namespaceId};e().namespaces.events.push(p)}}else{let c=e().namespaces.list[r].data.accounts;if(c){if(!(c.sort().toString()===o.sort().toString())){let f={type:"namespace_account_switched",provider:t.info.providerId,namespace:t.info.namespaceId,previousAccounts:c,accounts:o};e().namespaces.events.push(f)}}else{let p={type:"namespace_connected",provider:t.info.providerId,namespace:t.info.namespaceId,accounts:o};e().namespaces.events.push(p)}}else if(n==="network"){let s=e().namespaces.list[r].data.network,c={type:"namespace_network_switched",provider:t.info.providerId,namespace:t.info.namespaceId,network:o,previousNetwork:s};e().namespaces.events.push(c)}}}),"namespacesStore");import{produce as C}from"immer";var R=a((i,e)=>({events:new h,list:{},addProvider:(t,r)=>{let n={data:{installed:!1},error:"",config:r};i(C(o=>{o.providers.list[t]=n}))},removeProvider:t=>{i(C(r=>{delete r.providers.list[t]}))},updateStatus:(t,r,n)=>{let o=e().providers.list[t];if(!o)throw new Error(`No namespace namespace with '${t}' found.`);e().providers._produceEventsWhenUpdatingStatus(o,t,r,n),i(C(s=>{s.providers.list[t].data[r]=n}))},guessNamespacesState:t=>d(e(),t),_produceEventsWhenUpdatingStatus:(t,r,n,o)=>{if(n==="installed"){let s={type:"provider_detected",provider:r};e().providers.events.push(s)}}}),"providersStore");var N=a(()=>{let i=H((...e)=>({hub:I(...e),providers:R(...e),namespaces:O(...e)}));return k(i)},"createStore");var _=["init","state","after","before","and_then","or_else","store"],F=["string","number"],g=class{static{a(this,"NamespaceBuilder")}#e;#r;#n=new Map;#t=[];#o;constructor(e,t){this.#e=e,this.#r=t,this.#o={}}config(e,t){return this.#o[e]=t,this}action(e,t){return Array.isArray(e)?(e.forEach(([r,n])=>{this.#n.set(r,n)}),this):typeof e=="object"&&e?.actionName?(this.#t.push(e),this):(t&&this.#n.set(e,t),this)}build(){if(this.#s(this.#o))return this.#d(this.#o);throw new Error("You namespace config isn't valid.")}#s(e){return!0}#i(e){this.#t.forEach(t=>{t.after.forEach(r=>{r.map(n=>{e.after(t.actionName,n)})}),t.before.forEach(r=>{r.map(n=>{e.before(t.actionName,n)})}),t.and.forEach(r=>{r.map(n=>{e.and_then(t.actionName,n)})}),t.or.forEach(r=>{r.map(n=>{e.or_else(t.actionName,n)})})})}#c(){this.#t.forEach(e=>{this.#n.set(e.actionName,e.action)})}#d(e){this.#c();let t=new u(this.#e,this.#r,{configs:e,actions:this.#n});return this.#i(t),new Proxy(t,{has:(n,o)=>{if(typeof o!="string")throw new Error("You can use string as your property on Namespace instance.");return _.includes(o)||F.includes(typeof t[o])?!0:t.has(o)},get:(n,o)=>{if(typeof o!="string")throw new Error("You can use string as your property on Namespace instance.");let s=t[o];return _.includes(o)?s.bind(t):F.includes(typeof s)?s:t.run.bind(t,o)},set:()=>{throw new Error("You can not set anything on this object.")}})}};var x=class{static{a(this,"ProviderBuilder")}#e;#r=new Map;#n={};#t={};#o;constructor(e,t){this.#e=e,this.#o=t||{}}add(e,t){return this.#o.store&&t.store(this.#o.store),this.#r.set(e,t),this}config(e,t){return this.#t[e]=t,this}init(e){return this.#n.init=e,this}build(){if(this.#s(this.#t))return new m(this.#e,this.#r,this.#t,{extendInternalActions:this.#n,store:this.#o.store});throw new Error("You need to set all required configs.")}#s(e){return!!e.info}};var b=class{static{a(this,"ActionBuilder")}name;#e=new Map;#r=new Map;#n=new Map;#t=new Map;#o;constructor(e){this.name=e}and(e){return this.#e.has(this.name)||this.#e.set(this.name,[]),this.#e.get(this.name)?.push(e),this}or(e){return this.#r.has(this.name)||this.#r.set(this.name,[]),this.#r.get(this.name)?.push(e),this}before(e){return this.#t.has(this.name)||this.#t.set(this.name,[]),this.#t.get(this.name)?.push(e),this}after(e){return this.#n.has(this.name)||this.#n.set(this.name,[]),this.#n.get(this.name)?.push(e),this}action(e){return this.#o=e,this}build(){if(!this.#o)throw new Error("Your action builder should includes an action.");return{actionName:this.name,action:this.#o,before:this.#t,after:this.#n,and:this.#e,or:this.#r}}};import*as rt from"caip";function M(i,e){if(!e)throw new Error("You should provide a valid semver, e.g 1.0.0.");let t=i.find(([r])=>r===e);if(!t)throw new Error(`You target version hasn't been found. Available versions: ${Object.keys(i).join(", ")}`);return t}a(M,"pickVersion");function B(){let i=[],e={version:(t,r)=>(i.push([t,r]),e),build:()=>i};return e}a(B,"defineVersions");export{b as ActionBuilder,S as Hub,u as Namespace,g as NamespaceBuilder,m as Provider,x as ProviderBuilder,N as createStore,B as defineVersions,d as guessProviderStateSelector,v as namespaceStateSelector,M as pickVersion};
1
+ var D=Object.defineProperty;var a=(i,e)=>D(i,"name",{value:e,configurable:!0});function w(i){return i.constructor.name==="AsyncFunction"}a(w,"isAsync");function l(i,e){return`${i}$$${e}`}a(l,"generateStoreId");var y=a(i=>`Couldn't find "${i}" action. Are you sure you've added the action?`,"ACTION_NOT_FOUND_ERROR"),E=a(i=>`An error occurred during running ${i}`,"OR_ELSE_ACTION_FAILED_ERROR"),P=a(i=>`An error occurred during running before for "${i}" action`,"BEFORE_ACTION_FAILED_ERROR"),A="For setup store, you should set `store` first.";var u=class{static{a(this,"Namespace")}namespaceId;providerId;#e;#r=new Map;#n=new Map;#t=new Map;#o=new Map;#s=!1;#i;#c;constructor(e,t,r){let{configs:n,actions:o}=r;this.namespaceId=e,this.providerId=t,this.#c=n||new Map,this.#e=o,r.store&&this.store(r.store)}init(){if(this.#s)return;let e=this.#e.get("init");e&&e(this.#a()),this.#s=!0}state(){let e=this.#i;if(!e)throw new Error("You need to set your store using `.store` method first.");let t=this.#h();return[a(o=>{let s=e.getState().namespaces.getNamespaceData(t);return o?s[o]:s},"getState"),a((o,s)=>{e.getState().namespaces.updateStatus(t,o,s)},"setState")]}store(e){return this.#i&&console.warn("You've already set an store for your Namespace. Old store will be replaced by the new one."),this.#i=e,this.#l(),this}and_then(e,t){let r=this.#r.get(e)||[];return this.#r.set(e,r.concat(t)),this}or_else(e,t){let r=this.#n.get(e)||[];return this.#n.set(e,r.concat(t)),this}after(e,t,r){let n=this.#o.get(e)||[],o={hook:t,options:{context:r?.context}};return this.#o.set(e,n.concat(o)),this}before(e,t,r){let n=this.#t.get(e)||[],o={hook:t,options:{context:r?.context}};return this.#t.set(e,n.concat(o)),this}has(e){return!!this.#e.get(e)}run(e,...t){let r=this.#e.get(e);if(!r)throw new Error(y(e.toString()));return w(r)?this.#v(e,t):this.#d(e,t)}#d(e,t){try{this.#u(e)}catch(s){throw this.#p(e),new Error(P(e.toString()),{cause:s})}let r=this.#e.get(e);if(!r)throw new Error(y(e.toString()));let n=this.#a(),o;try{o=r(n,...t),o=this.#m(e,o)}catch(s){o=this.#f(e,s)}finally{this.#p(e)}return o}async#v(e,t){try{this.#u(e)}catch(o){throw this.#p(e),new Error(P(e.toString()),{cause:o})}let r=this.#e.get(e);if(!r)throw new Error(y(e.toString()));let n=this.#a();return await r(n,...t).then(o=>this.#m(e,o)).catch(o=>this.#f(e,o)).finally(()=>this.#p(e))}#p(e){let t=this.#o.get(e);t&&t.forEach(r=>{let n=r.options?.context||this.#a();r.hook(n)})}#u(e){let t=this.#t.get(e);t&&t.forEach(r=>{let n=r.options?.context||this.#a();r.hook(n)})}#m(e,t){let r=this.#r.get(e);if(r){let n=this.#a();t=r.reduce((o,s)=>s(n,o),t)}return t}#f(e,t){let r=this.#n.get(e);if(r)try{let n=this.#a();return r.reduce((o,s)=>s(n,o),t)}catch(n){if(n instanceof Error)throw n.cause=t,n;let o=E(`${e.toString()} for ${this.namespaceId} namespace.`),s=new Error(String(n),{cause:t});throw new Error(o,{cause:s})}else throw t}#l(){let e=this.#i;if(!e)throw new Error(A);let t=this.#h();e.getState().namespaces.addNamespace(t,{namespaceId:this.namespaceId,providerId:this.providerId})}#h(){return l(this.providerId,this.namespaceId)}#a(){return{state:this.state.bind(this),action:this.run.bind(this)}}};var V="1.0",m=class{static{a(this,"Provider")}id;version=V;#e;#r=!1;#n={};#t;#o;constructor(e,t,r,n){this.id=e,this.#o=r,this.#n=n?.extendInternalActions||{},this.#e=t,n?.store&&(this.#t=n.store,this.#i())}init(){if(this.#r)return;let e=this.#n.init;e&&e(this.#c()),this.#r=!0}state(){let e=this.#t;if(!e)throw new Error(`Any store detected for ${this.id}. You need to set your store using '.store' method first.`);return[a(n=>{let o=e.getState().providers.guessNamespacesState(this.id);if(!n)return o;switch(n){case"installed":case"connected":case"connecting":return o[n];default:throw new Error("Unhandled state for provider")}},"getState"),a((n,o)=>{switch(n){case"installed":return e.getState().providers.updateStatus(this.id,n,o);default:throw new Error(`Unhandled state update for provider. (provider id: ${this.id}, state name: ${n})`)}},"setState")]}store(e){return this.#t&&console.warn("You've already set an store for your Provider. Old store will be replaced by the new one."),this.#t=e,this.#i(),this}info(){let e=this.#t;return e?e.getState().providers.list[this.id].config.info:this.#o.info}getAll(){return this.#e}get(e){return this.#e.get(e)}findByNamespace(e){let t;return this.#e.forEach(r=>{r.namespaceId===e&&(t=r)}),t}before(e,t){return this.#s("before",e,t),this}after(e,t){return this.#s("after",e,t),this}#s(e,t,r){let n={state:this.state.bind(this)};return this.#e.forEach(o=>{if(e==="after")o.after(t,r,{context:n});else if(e==="before")o.before(t,r,{context:n});else throw new Error(`You hook name is invalid: ${e}`)}),this}#i(){let e=this.#t;if(!e)throw new Error("For setup store, you should set `store` first.");e.getState().providers.addProvider(this.id,this.#o),this.#e.forEach(t=>{t.store(e)})}#c(){return{state:this.state.bind(this)}}};var g=class{static{a(this,"Hub")}#e=new Map;#r;constructor(e){this.#r=e??{}}init(){this.runAll("init")}runAll(e){let t=[],r=this.#e.values();for(let n of r){let o={id:n.id,provider:void 0,namespaces:[]},s=n[e];typeof s=="function"&&(o.provider=s.call(n));let c=n.getAll().values();for(let p of c){let f=p[e];if(typeof f=="function"){let j=f();o.namespaces.push(j)}}t.push(o)}return t}add(e,t){return this.#r.store&&t.store(this.#r.store),this.#e.set(e,t),this}remove(e){if(!this.#e.get(e))throw new Error(`Provider not found: No provider exists with ID "${e}"`);return this.#r.store?.getState().providers.removeProvider(e),this.#e.delete(e),this}get(e){return this.#e.get(e)}getAll(){return this.#e}state(){let e=this.runAll("state"),t={};return e.forEach(r=>{let n=[];r.namespaces.forEach(s=>{let[c]=s;n.push(c())});let[o]=r.provider;t[r.id]={...o()||{},namespaces:n}}),t}};function d(i,e){let t=i.namespaces.list,r=Object.keys(t).filter(c=>t[c].info.providerId===e),n=!!i.providers.list[e]?.data.installed,o=r.length>0?r.some(c=>t[c].data.connected):!1,s=r.length>0?r.some(c=>t[c].data.connecting):!1;return{installed:n,connected:o,connecting:s}}a(d,"guessProviderStateSelector");function v(i,e){return i.namespaces.list[e].data}a(v,"namespaceStateSelector");import{createStore as H}from"zustand/vanilla";function k(i){let e=a(t=>r=>{let n=a((o,s,c)=>{for(let p of o)r(p,s,c)},"executeListener");return t.subscribe((o,s)=>{let c=W(o,s),f=[...T(o),...c];n(f,o,s)}),{flushEvents:()=>{let o=t.getState(),s=T(o);n(s,o,o)}}},"extendedSubscribe");return new Proxy(i,{get:function(t,r,n){return r==="subscribe"?e(t):Reflect.get(t,r,n)}})}a(k,"extend");function T(i){return[...i.providers.events,...i.namespaces.events]}a(T,"tryConsumeEvents");function W(i,e){let t=[];for(let r of Object.keys(i.providers.list)){let n=d(i,r),o=d(e,r);if(o.connecting!==n.connecting){let s={type:"provider_connecting",provider:r,value:n.connecting};t.push(s)}if(!o.connected&&n.connected){let s={type:"provider_connected",provider:r};t.push(s)}if(o.connected&&!n.connected){let s={type:"provider_disconnected",provider:r};t.push(s)}}return t}a(W,"getEventsLike");var I=a(()=>({config:{}}),"hubStore");import{produce as K}from"immer";var h=class{static{a(this,"ConsumableEvents")}#e=[];push(e){this.#e.push(e)}[Symbol.iterator](){return{next:()=>this.#e.length==0?{done:!0,value:void 0}:{done:!1,value:this.#e.shift()}}}};var O=a((i,e)=>({events:new h,list:{},addNamespace:(t,r)=>{let o={data:{accounts:null,network:null,connected:!1,connecting:!1},error:"",info:r};i(K(s=>{s.namespaces.list[t]=o}))},updateStatus:(t,r,n)=>{let o=e().namespaces.list[t];if(!o)throw new Error(`No namespace with '${t}' found.`);e().namespaces._produceEventsWhenUpdatingStatus(o,t,r,n),i(K(s=>{s.namespaces.list[t].data[r]=n}))},getNamespaceData(t){return v(e(),t)},_produceEventsWhenUpdatingStatus:(t,r,n,o)=>{if(n==="accounts")if(Object.is(o,null)||Array.isArray(o)&&o.length===0){if(e().namespaces.list[r].data.connected){let p={type:"namespace_disconnected",provider:t.info.providerId,namespace:t.info.namespaceId};e().namespaces.events.push(p)}}else{let c=e().namespaces.list[r].data.accounts;if(c){if(!(c.sort().toString()===o.sort().toString())){let f={type:"namespace_account_switched",provider:t.info.providerId,namespace:t.info.namespaceId,previousAccounts:c,accounts:o};e().namespaces.events.push(f)}}else{let p={type:"namespace_connected",provider:t.info.providerId,namespace:t.info.namespaceId,accounts:o};e().namespaces.events.push(p)}}else if(n==="network"){let s=e().namespaces.list[r].data.network,c={type:"namespace_network_switched",provider:t.info.providerId,namespace:t.info.namespaceId,network:o,previousNetwork:s};e().namespaces.events.push(c)}}}),"namespacesStore");import{produce as C}from"immer";var R=a((i,e)=>({events:new h,list:{},addProvider:(t,r)=>{let n={data:{installed:!1},error:"",config:r};i(C(o=>{o.providers.list[t]=n}))},removeProvider:t=>{i(C(r=>{delete r.providers.list[t]}))},updateStatus:(t,r,n)=>{let o=e().providers.list[t];if(!o)throw new Error(`No namespace namespace with '${t}' found.`);e().providers._produceEventsWhenUpdatingStatus(o,t,r,n),i(C(s=>{s.providers.list[t].data[r]=n}))},guessNamespacesState:t=>d(e(),t),_produceEventsWhenUpdatingStatus:(t,r,n,o)=>{if(n==="installed"){let s={type:"provider_detected",provider:r};e().providers.events.push(s)}}}),"providersStore");var N=a(()=>{let i=H((...e)=>({hub:I(...e),providers:R(...e),namespaces:O(...e)}));return k(i)},"createStore");var F=["init","state","after","before","and_then","or_else","store"],_=["string","number"],S=class{static{a(this,"NamespaceBuilder")}#e;#r;#n=new Map;#t=[];#o;constructor(e,t){this.#e=e,this.#r=t,this.#o={}}config(e,t){return this.#o[e]=t,this}action(e,t){return Array.isArray(e)?(e.forEach(([r,n])=>{this.#n.set(r,n)}),this):typeof e=="object"&&e?.actionName?(this.#t.push(e),this):(t&&this.#n.set(e,t),this)}build(){if(this.#s(this.#o))return this.#d(this.#o);throw new Error("You namespace config isn't valid.")}#s(e){return!0}#i(e){this.#t.forEach(t=>{t.after.forEach(r=>{r.map(n=>{e.after(t.actionName,n)})}),t.before.forEach(r=>{r.map(n=>{e.before(t.actionName,n)})}),t.and.forEach(r=>{r.map(n=>{e.and_then(t.actionName,n)})}),t.or.forEach(r=>{r.map(n=>{e.or_else(t.actionName,n)})})})}#c(){this.#t.forEach(e=>{this.#n.set(e.actionName,e.action)})}#d(e){this.#c();let t=new u(this.#e,this.#r,{configs:e,actions:this.#n});return this.#i(t),new Proxy(t,{has:(n,o)=>{if(typeof o!="string")throw new Error("You can use string as your property on Namespace instance.");return F.includes(o)||_.includes(typeof t[o])?!0:t.has(o)},get:(n,o)=>{if(typeof o!="string")throw new Error("You can use string as your property on Namespace instance.");let s=t[o];return F.includes(o)?s.bind(t):_.includes(typeof s)?s:t.run.bind(t,o)},set:()=>{throw new Error("You can not set anything on this object.")}})}};var x=class{static{a(this,"ProviderBuilder")}#e;#r=new Map;#n={};#t={};#o;constructor(e,t){this.#e=e,this.#o=t||{}}add(e,t){return this.#o.store&&t.store(this.#o.store),this.#r.set(e,t),this}config(e,t){return this.#t[e]=t,this}init(e){return this.#n.init=e,this}build(){if(this.#s(this.#t))return new m(this.#e,this.#r,this.#t,{extendInternalActions:this.#n,store:this.#o.store});throw new Error("You need to set all required configs.")}#s(e){return!!e.info}};var b=class{static{a(this,"ActionBuilder")}name;#e=new Map;#r=new Map;#n=new Map;#t=new Map;#o;constructor(e){this.name=e}and(e){return this.#e.has(this.name)||this.#e.set(this.name,[]),this.#e.get(this.name)?.push(e),this}or(e){return this.#r.has(this.name)||this.#r.set(this.name,[]),this.#r.get(this.name)?.push(e),this}before(e){return this.#t.has(this.name)||this.#t.set(this.name,[]),this.#t.get(this.name)?.push(e),this}after(e){return this.#n.has(this.name)||this.#n.set(this.name,[]),this.#n.get(this.name)?.push(e),this}action(e){return this.#o=e,this}build(){if(!this.#o)throw new Error("Your action builder should includes an action.");return{actionName:this.name,action:this.#o,before:this.#t,after:this.#n,and:this.#e,or:this.#r}}};import*as rt from"caip";function M(i,e){if(!e)throw new Error("You should provide a valid semver, e.g 1.0.0.");let t=i.find(([r])=>r===e);if(!t)throw new Error(`You target version hasn't been found. Available versions: ${Object.keys(i).join(", ")}`);return t}a(M,"pickVersion");function B(){let i=[],e={version:(t,r)=>(i.push([t,r]),e),build:()=>i};return e}a(B,"defineVersions");export{b as ActionBuilder,g as Hub,u as Namespace,S as NamespaceBuilder,m as Provider,x as ProviderBuilder,N as createStore,B as defineVersions,d as guessProviderStateSelector,v as namespaceStateSelector,M as pickVersion};
2
2
  //# sourceMappingURL=mod.js.map