@hub3js/core 0.0.0-experimental-03bf1f89-20260602

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.
Files changed (105) hide show
  1. package/CHANGELOG.md +381 -0
  2. package/dist/builders/action.d.ts +22 -0
  3. package/dist/builders/action.d.ts.map +1 -0
  4. package/dist/builders/mod.d.ts +5 -0
  5. package/dist/builders/mod.d.ts.map +1 -0
  6. package/dist/builders/namespace.d.ts +47 -0
  7. package/dist/builders/namespace.d.ts.map +1 -0
  8. package/dist/builders/provider.d.ts +37 -0
  9. package/dist/builders/provider.d.ts.map +1 -0
  10. package/dist/builders/types.d.ts +23 -0
  11. package/dist/builders/types.d.ts.map +1 -0
  12. package/dist/hub/helpers.d.ts +6 -0
  13. package/dist/hub/helpers.d.ts.map +1 -0
  14. package/dist/hub/hub.d.ts +44 -0
  15. package/dist/hub/hub.d.ts.map +1 -0
  16. package/dist/hub/mod.d.ts +11 -0
  17. package/dist/hub/mod.d.ts.map +1 -0
  18. package/dist/hub/namespaces/errors.d.ts +5 -0
  19. package/dist/hub/namespaces/errors.d.ts.map +1 -0
  20. package/dist/hub/namespaces/mod.d.ts +3 -0
  21. package/dist/hub/namespaces/mod.d.ts.map +1 -0
  22. package/dist/hub/namespaces/namespace.d.ts +148 -0
  23. package/dist/hub/namespaces/namespace.d.ts.map +1 -0
  24. package/dist/hub/namespaces/types.d.ts +36 -0
  25. package/dist/hub/namespaces/types.d.ts.map +1 -0
  26. package/dist/hub/provider/mod.d.ts +3 -0
  27. package/dist/hub/provider/mod.d.ts.map +1 -0
  28. package/dist/hub/provider/provider.d.ts +102 -0
  29. package/dist/hub/provider/provider.d.ts.map +1 -0
  30. package/dist/hub/provider/types.d.ts +28 -0
  31. package/dist/hub/provider/types.d.ts.map +1 -0
  32. package/dist/hub/store/events.d.ts +54 -0
  33. package/dist/hub/store/events.d.ts.map +1 -0
  34. package/dist/hub/store/extend.d.ts +14 -0
  35. package/dist/hub/store/extend.d.ts.map +1 -0
  36. package/dist/hub/store/hub.d.ts +11 -0
  37. package/dist/hub/store/hub.d.ts.map +1 -0
  38. package/dist/hub/store/mod.d.ts +8 -0
  39. package/dist/hub/store/mod.d.ts.map +1 -0
  40. package/dist/hub/store/mod.js +2 -0
  41. package/dist/hub/store/mod.js.map +7 -0
  42. package/dist/hub/store/namespaces.d.ts +38 -0
  43. package/dist/hub/store/namespaces.d.ts.map +1 -0
  44. package/dist/hub/store/providers.d.ts +84 -0
  45. package/dist/hub/store/providers.d.ts.map +1 -0
  46. package/dist/hub/store/selectors.d.ts +18 -0
  47. package/dist/hub/store/selectors.d.ts.map +1 -0
  48. package/dist/hub/store/store.d.ts +14 -0
  49. package/dist/hub/store/store.d.ts.map +1 -0
  50. package/dist/hub/types.d.ts +5 -0
  51. package/dist/hub/types.d.ts.map +1 -0
  52. package/dist/mod.d.ts +5 -0
  53. package/dist/mod.d.ts.map +1 -0
  54. package/dist/mod.js +2 -0
  55. package/dist/mod.js.map +7 -0
  56. package/dist/test-utils/fixtures.d.ts +4 -0
  57. package/dist/test-utils/fixtures.d.ts.map +1 -0
  58. package/dist/test-utils/mod.d.ts +2 -0
  59. package/dist/test-utils/mod.d.ts.map +1 -0
  60. package/dist/test-utils/mod.js +2 -0
  61. package/dist/test-utils/mod.js.map +7 -0
  62. package/dist/utils/mod.d.ts +3 -0
  63. package/dist/utils/mod.d.ts.map +1 -0
  64. package/dist/utils/mod.js +2 -0
  65. package/dist/utils/mod.js.map +7 -0
  66. package/dist/utils/versions.d.ts +50 -0
  67. package/dist/utils/versions.d.ts.map +1 -0
  68. package/package.json +49 -0
  69. package/readme.md +4 -0
  70. package/src/builders/action.test.ts +225 -0
  71. package/src/builders/action.ts +86 -0
  72. package/src/builders/mod.ts +5 -0
  73. package/src/builders/namespace.ts +258 -0
  74. package/src/builders/provider.ts +101 -0
  75. package/src/builders/types.ts +28 -0
  76. package/src/hub/helpers.ts +11 -0
  77. package/src/hub/hub.test.ts +108 -0
  78. package/src/hub/hub.ts +145 -0
  79. package/src/hub/mod.ts +21 -0
  80. package/src/hub/namespaces/errors.ts +11 -0
  81. package/src/hub/namespaces/mod.ts +10 -0
  82. package/src/hub/namespaces/namespace.test.ts +443 -0
  83. package/src/hub/namespaces/namespace.ts +470 -0
  84. package/src/hub/namespaces/types.ts +58 -0
  85. package/src/hub/provider/mod.ts +9 -0
  86. package/src/hub/provider/provider.test.ts +277 -0
  87. package/src/hub/provider/provider.ts +286 -0
  88. package/src/hub/provider/types.ts +37 -0
  89. package/src/hub/store/events.ts +89 -0
  90. package/src/hub/store/extend.ts +125 -0
  91. package/src/hub/store/hub.ts +18 -0
  92. package/src/hub/store/mod.ts +26 -0
  93. package/src/hub/store/namespaces.ts +177 -0
  94. package/src/hub/store/providers.ts +183 -0
  95. package/src/hub/store/selectors.ts +59 -0
  96. package/src/hub/store/store.test.ts +50 -0
  97. package/src/hub/store/store.ts +30 -0
  98. package/src/hub/types.ts +13 -0
  99. package/src/mod.ts +27 -0
  100. package/src/test-utils/fixtures.ts +13 -0
  101. package/src/test-utils/mod.ts +1 -0
  102. package/src/utils/mod.ts +2 -0
  103. package/src/utils/versions.test.ts +23 -0
  104. package/src/utils/versions.ts +91 -0
  105. package/store/package.json +8 -0
@@ -0,0 +1,148 @@
1
+ import type { Actions, Context, GetState, RegisteredActions, SetState } from './types.js';
2
+ import type { NamespaceConfig, Store } from '../store/mod.js';
3
+ import type { AndFunction, AnyFunction, FunctionWithContext } from '../types.js';
4
+ type Params = any[];
5
+ /**
6
+ *
7
+ * A Namespace is a unit of wallets where usually handles connecting, signing, accounts, ...
8
+ * It will be injected by wallet in its object, for example, `window.phantom.ethereum` or `window.phantom.solana`
9
+ * Each namespace (like solana) has its own functionality which is not shared between all the blockchains.
10
+ * For example in EVM namespaces, you can have different networks (e.g. Ethereum,Polygon, ...) and there are specific flows to handle connecting to them or add a network and etc.
11
+ * But Solana doesn't have this concept and you will directly always connect to solana itself.
12
+ * This is true for signing a transaction, getting information about blockchain and more.
13
+ * So by creating a namespace for each of these, we can define a custom namespace based on blockchain's properties.
14
+ *
15
+ */
16
+ declare class Namespace<T extends Actions<T>> {
17
+ #private;
18
+ /** it will be used for `store` and accessing to store by its id mainly. */
19
+ readonly namespaceId: string;
20
+ /** it will be used for `store` and accessing to store by its id mainly. */
21
+ readonly providerId: string;
22
+ constructor(id: string, providerId: string, options: {
23
+ store?: Store;
24
+ configs?: NamespaceConfig;
25
+ actions: RegisteredActions<T>;
26
+ });
27
+ /**
28
+ * This is an special action that will be called **only once**.
29
+ * We don't call this in `constructor` and developer should call this manually. we only ensure it will be called once.
30
+ *
31
+ * ```ts
32
+ * const myInit = () => { whatever; }
33
+ * const actions = new Map();
34
+ * actions.set("init", myInit)
35
+ * const ns = new Namespace(..., {actions});
36
+ *
37
+ * // Will run `myInit`
38
+ * ns.init()
39
+ *
40
+ * // Will not run `myInit` anymore.
41
+ * ns.init()
42
+ * ns.init()
43
+ * ```
44
+ */
45
+ init(): void;
46
+ /**
47
+ * Reading states from store and also update them.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * const ns = new Namespace(...);
52
+ * const [getState, setState] = ns.state();
53
+ * ```
54
+ */
55
+ state(): [GetState, SetState];
56
+ /**
57
+ * For keeping state, we need a store. all the states will be write to/read from store.
58
+ *
59
+ * Note: Store can be setup on constructor as well.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * const myStore = createStore();
64
+ * const ns = new Namespace(...);
65
+ * ns.store(myStore);
66
+ * ```
67
+ */
68
+ store(store: Store): this;
69
+ /**
70
+ * It's a boolean operator to run a sync function if action ran successfully.
71
+ * For example, if we have a `connect` action, we can add function to be run after `connect` if it ran successfully.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const ns = new Namespace(..);
76
+ *
77
+ * ns.and_then('connect', (context) => {
78
+ * ...
79
+ * });
80
+ * ```
81
+ *
82
+ */
83
+ and_then<K extends keyof T>(actionName: K, operatorFn: FunctionWithContext<AndFunction<T, K>, Context>): this;
84
+ /**
85
+ * It's a boolean operator to run a function to handle when an action fails.
86
+ * For example, if we have a `connect` action, we can add function to be run when `connect` fails (throw an error).
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * const ns = new Namespace(..);
91
+ *
92
+ * ns.or_else('connect', (context, error) => {
93
+ * ...
94
+ * });
95
+ * ```
96
+ */
97
+ or_else<K extends keyof T>(actionName: K, operatorFn: FunctionWithContext<AnyFunction, Context>): this;
98
+ /**
99
+ * Running a function after a specific action
100
+ *
101
+ * Note: the context can be set from outside as well. this is useful for Provider to set its context instead of namespace context.
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * const ns = new Namespace(...);
106
+ *
107
+ * ns.after("connect", (context) => {});
108
+ * ```
109
+ */
110
+ after<K extends keyof T, C = unknown>(actionName: K, hook: FunctionWithContext<AnyFunction, C>, options?: {
111
+ context?: C;
112
+ }): this;
113
+ /**
114
+ * Running a function before a specific action
115
+ *
116
+ * Note: the context can be set from outside as well. this is useful for Provider to set its context instead of using namespace context.
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * const ns = new Namespace(...);
121
+ *
122
+ * ns.before("connect", (context) => {});
123
+ * ```
124
+ */
125
+ before<K extends keyof T, C = unknown>(actionName: K, hook: FunctionWithContext<AnyFunction, C>, options?: {
126
+ context?: C;
127
+ }): this;
128
+ has<K extends keyof T>(actionName: K): boolean;
129
+ /**
130
+ *
131
+ * Registered actions will be called using `run`. it will run an action and all the operators or hooks that assigned.
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * const actions = new Map();
136
+ * actions.set('connect', connectAction);
137
+ *
138
+ * const ns = new Namespace(NAMESPACE, PROVIDER_ID, {
139
+ * actions: actions,
140
+ * });
141
+ *
142
+ * ns.run("action");
143
+ * ```
144
+ */
145
+ run<K extends keyof T>(actionName: K, ...args: Params): unknown | Promise<unknown>;
146
+ }
147
+ export { Namespace };
148
+ //# sourceMappingURL=namespace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namespace.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U,EAAE,mBAAmB,CAAC,WAAW,EAAE,OAAO,CAAC,GACpD,IAAI;IAOP;;;;;;;;;;;OAWG;IACI,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,CAAC,GAAG,OAAO,EACzC,UAAU,EAAE,CAAC,EACb,IAAI,EAAE,mBAAmB,CAAC,WAAW,EAAE,CAAC,CAAC,EACzC,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,CAAC,CAAA;KAAE,GACxB,IAAI;IAaP;;;;;;;;;;;OAWG;IACI,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,CAAC,GAAG,OAAO,EAC1C,UAAU,EAAE,CAAC,EACb,IAAI,EAAE,mBAAmB,CAAC,WAAW,EAAE,CAAC,CAAC,EACzC,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,CAAC,CAAA;KAAE,GACxB,IAAI;IAeA,GAAG,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC,GAAG,OAAO;IAGrD;;;;;;;;;;;;;;;OAeG;IACI,GAAG,CAAC,CAAC,SAAS,MAAM,CAAC,EAC1B,UAAU,EAAE,CAAC,EACb,GAAG,IAAI,EAAE,MAAM,GACd,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;CAqK9B;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,36 @@
1
+ import type { NamespaceData } from '../store/mod.js';
2
+ import type { AnyFunction, FunctionWithContext } from '../types.js';
3
+ type ActionName<K> = K | Omit<K, string>;
4
+ type Args = any[];
5
+ type ActionResult = any;
6
+ export type Subscriber<C extends Actions<C>> = (context: Context<C>, ...args: Args) => void;
7
+ export type SubscriberCleanUp<C extends Actions<C>> = (context: Context<C>, ...args: Args) => void;
8
+ export type CanEagerConnect<C extends Actions<C>> = (context: Context<C>, ...args: Args) => void;
9
+ export type State = NamespaceData;
10
+ export type SetState = <K extends keyof State>(name: K, value: State[K]) => void;
11
+ export type GetState = {
12
+ (): State;
13
+ <K extends keyof State>(name: K): State[K];
14
+ };
15
+ export type RegisteredActions<T extends Actions<T>> = Map<ActionName<keyof T>, FunctionWithContext<T[keyof T], Context<T>>>;
16
+ export type AndUseActions<T> = Map<keyof T, AnyFunction>;
17
+ export type Operators<T> = Map<keyof T, AnyFunction[]>;
18
+ export type HooksWithOptions<T> = Map<keyof T, {
19
+ hook: AnyFunction;
20
+ options?: {
21
+ context?: unknown;
22
+ };
23
+ }[]>;
24
+ export type Context<T extends Actions<T> = object> = {
25
+ state: () => [GetState, SetState];
26
+ action: (name: keyof T, ...args: Args) => ActionResult;
27
+ };
28
+ /**
29
+ * This actually define what kind of action will be implemented in namespaces.
30
+ * For example evm namespace will have .connect(chain: string) and .switchNetwork
31
+ * But solana namespace only have: `.connect()`.
32
+ * This actions will be passed to this generic.
33
+ */
34
+ export type Actions<T> = Record<keyof T, AnyFunction>;
35
+ export {};
36
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/hub/namespaces/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEpE,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAEzC,KAAK,IAAI,GAAG,GAAG,EAAE,CAAC;AAElB,KAAK,YAAY,GAAG,GAAG,CAAC;AAExB,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,IAAI,CAC7C,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,GAAG,IAAI,EAAE,IAAI,KACV,IAAI,CAAC;AACV,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,IAAI,CACpD,OA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O,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI;IACnD,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAClC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,YAAY,CAAC;CACxD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export type { ExtendableInternalActions, RegisteredNamespaces, State, Context, ProviderBuilderOptions, } from './types.js';
2
+ export { Provider } from './provider.js';
3
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/hub/provider/mod.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,yBAAyB,EACzB,oBAAoB,EACpB,KAAK,EACL,OAAO,EACP,sBAAsB,GACvB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,102 @@
1
+ import type { Context, ExtendableInternalActions, GetState, RegisteredNamespaces, SetState } from './types.js';
2
+ import type { FindProxiedNamespace } from '../../builders/mod.js';
3
+ import type { ProviderConfig, ProviderInfo, Store } from '../store/mod.js';
4
+ import type { AnyFunction, FunctionWithContext } from '../types.js';
5
+ /**
6
+ * A `Provider` represents one wallet/integration and owns the set of namespaces
7
+ * that wallet exposes (e.g. `evm`, `solana`).
8
+ *
9
+ * The `TNS` generic captures exactly which namespaces this provider supports.
10
+ * It's normally inferred by `ProviderBuilder` from chained `.add()` calls, so
11
+ * `phantom.get('cosmos')` is a compile-time error if Phantom never registered
12
+ * `cosmos`. Construct directly only when you have a precise namespace shape
13
+ * to pass via `new Provider<MyNamespaces>(...)`.
14
+ */
15
+ export declare class Provider<TNS = unknown> {
16
+ #private;
17
+ readonly id: string;
18
+ readonly version = "1.0";
19
+ constructor(id: string, namespaces: RegisteredNamespaces<TNS>, configs: ProviderConfig<TNS>, options?: {
20
+ /**
21
+ * There are some cases we need to have a behavior like initializing a provider which will be run when we are creating an instance.
22
+ * These internal steps and behaviors will be useful for library user to extend the behavior by running a specific code.
23
+ */
24
+ extendInternalActions?: ExtendableInternalActions;
25
+ store?: Store;
26
+ });
27
+ /**
28
+ * This is an special callback that will be called **only once**.
29
+ * We don't call this in `constructor` and developer should call this manually. we only ensure it will be called once.
30
+ *
31
+ * ```ts
32
+ * const myInit = () => { whatever; } *
33
+ * const provider = new Provider(..., {extendInternalActions: {init: myInit} });
34
+ *
35
+ * // Will run `myInit`
36
+ * provider.init()
37
+ *
38
+ * // Will not run `myInit` anymore.
39
+ * provider.init()
40
+ * provider.init()
41
+ * ```
42
+ */
43
+ init(): void;
44
+ /**
45
+ * Getting state of a provider.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const provider = new Provider(...);
50
+ * const [getState, setState] = provider.state();
51
+ *
52
+ * getState('installed');
53
+ * // or
54
+ * getState().installed;
55
+ * ```
56
+ */
57
+ state(): [GetState, SetState];
58
+ /**
59
+ * For keeping state, we need a store. all the states will be write to/read from store.
60
+ *
61
+ * **Note: When you are setting an store for provider, it will be set for its namespaces automatically as well**
62
+ */
63
+ store(store: Store): this;
64
+ /**
65
+ * Getting information about a provider which has been set on constructing Provider.
66
+ */
67
+ info(): ProviderInfo<TNS> | undefined;
68
+ /**
69
+ * A list of registered _proxied_ namespaces.
70
+ */
71
+ getAll(): RegisteredNamespaces<TNS>;
72
+ /**
73
+ * Get a registered namespace in provider by its **namespace key**.
74
+ *
75
+ * Note: difference between namespace key and namespace id is the first one
76
+ * is the key under which the namespace is registered (the `K` in `.add(K, ns)`),
77
+ * and the second one is the runtime `namespaceId` (e.g. `'eip155'`) chosen
78
+ * when constructing the namespace itself.
79
+ */
80
+ get<K extends keyof TNS>(id: K): FindProxiedNamespace<K, TNS> | undefined;
81
+ /**
82
+ * Get a registered namespace by its **namespaceId** (the runtime id chosen
83
+ * when constructing the namespace). Returns the union of all namespaces this
84
+ * provider supports — caller is expected to discriminate via `namespaceId`.
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * const provider = new Provider(...);
89
+ * provider.findByNamespace("whatever-id-i-set-for-namespace")
90
+ * ```
91
+ */
92
+ findByNamespace(namespaceLookingFor: string): FindProxiedNamespace<keyof TNS, TNS> | undefined;
93
+ /**
94
+ * Running a hook function _before_ a specific action for **all registered namespaces**.
95
+ */
96
+ before(actionName: string, hookFn: FunctionWithContext<AnyFunction, Context>): this;
97
+ /**
98
+ * Running a hook function _after_ a specific action for **all registered namespaces**.
99
+ */
100
+ after(actionName: string, hookFn: FunctionWithContext<AnyFunction, Context>): this;
101
+ }
102
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/hub/provider/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,yBAAyB,EACzB,QAAQ,EACR,oBAAoB,EACpB,QAAQ,EAET,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAIpE;;;;;;;;;GASG;AACH,qBAAa,QAAQ,CAAC,GAAG,GAAG,OAAO;;IACjC,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,SAAgB,OAAO,SAAW;gBAShC,EAAE,EAAE,MAAM,EACV,UAAU,EAAE,oBAAoB,CAAC,GAAG,CAAC,EACrC,OAAO,EAAE,cAAc,CAAC,GAAG,CAAC,EAC5B,OAAO,CAAC,EAAE;QACR;;;WAGG;QACH,qBAAqB,CAAC,EAAE,yBAAyB,CAAC;QAClD,KAAK,CAAC,EAAE,KAAK,CAAC;KACf;IAkBH;;;;;;;;;;;;;;;OAeG;IACI,IAAI,IAAI,IAAI;IAanB;;;;;;;;;;;;OAYG;IACI,KAAK,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAyCpC;;;;OAIG;IACI,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAWhC;;OAEG;IACI,IAAI,IAAI,YAAY,CAAC,GAAG,CAAC,GAAG,SAAS;IAU5C;;OAEG;IACI,MAAM,IAAI,oBAAoB,CAAC,GAAG,CAAC;IAI1C;;;;;;;OAOG;IACI,GAAG,CAAC,CAAC,SAAS,MAAM,GAAG,EAC5B,EAAE,EAAE,CAAC,GACJ,oBAAoB,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS;IAI3C;;;;;;;;;;OAUG;IACI,eAAe,CACpB,mBAAmB,EAAE,MAAM,GAC1B,oBAAoB,CAAC,MAAM,GAAG,EAAE,GAAG,CAAC,GAAG,SAAS;IAYnD;;OAEG;IACI,MAAM,CACX,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,mBAAmB,CAAC,WAAW,EAAE,OAAO,CAAC,GAChD,IAAI;IAKP;;OAEG;IACI,KAAK,CACV,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,mBAAmB,CAAC,WAAW,EAAE,OAAO,CAAC,GAChD,IAAI;CA+CR"}
@@ -0,0 +1,28 @@
1
+ import type { FindProxiedNamespace } from '../../builders/mod.js';
2
+ import type { Store } from '../mod.js';
3
+ import type { AnyFunction, FunctionWithContext } from '../types.js';
4
+ export type Context = {
5
+ state: () => [GetState, SetState];
6
+ };
7
+ export interface State {
8
+ installed: boolean;
9
+ connected: boolean;
10
+ connecting: boolean;
11
+ }
12
+ export type SetState = <K extends keyof Pick<State, 'installed'>>(name: K, value: State[K]) => void;
13
+ export type GetState = {
14
+ (): State;
15
+ <K extends keyof State>(name: K): State[K];
16
+ };
17
+ export interface ExtendableInternalActions {
18
+ init?: FunctionWithContext<AnyFunction, Context>;
19
+ }
20
+ /**
21
+ * The internal `Provider.#namespaces` map type — keys are the registered
22
+ * namespace ids, values are their corresponding proxied namespaces.
23
+ */
24
+ export type RegisteredNamespaces<T> = Map<keyof T, FindProxiedNamespace<keyof T, T>>;
25
+ export type ProviderBuilderOptions = {
26
+ store?: Store;
27
+ };
28
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/hub/provider/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEpE,MAAM,MAAM,OAAO,GAAG;IACpB,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;CACnC,CAAC;AAEF,MAAM,WAAW,KAAK;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,EAC9D,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,KACZ,IAAI,CAAC;AACV,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,KAAK,CAAC;IACV,CAAC,CAAC,SAAS,MAAM,KAAK,EAAE,IAAI,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;CAC5C,CAAC;AAEF,MAAM,WAAW,yBAAyB;IACxC,IAAI,CAAC,EAAE,mBAAmB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;CAClD;AAED;;;GAGG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,GAAG,CACvC,MAAM,CAAC,EACP,oBAAoB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CACjC,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IAAE,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC"}
@@ -0,0 +1,54 @@
1
+ export type NamespaceDisconnectedEvent = {
2
+ type: 'namespace_disconnected';
3
+ provider: string;
4
+ namespace: string;
5
+ };
6
+ export type NamespaceConnectedEvent = {
7
+ type: 'namespace_connected';
8
+ provider: string;
9
+ namespace: string;
10
+ accounts: string[];
11
+ };
12
+ export type NamespaceSwitchedAccountEvent = {
13
+ type: 'namespace_account_switched';
14
+ provider: string;
15
+ namespace: string;
16
+ accounts: string[];
17
+ previousAccounts: string[];
18
+ };
19
+ export type NamespaceSwitchedNetworkEvent = {
20
+ type: 'namespace_network_switched';
21
+ provider: string;
22
+ namespace: string;
23
+ network: string;
24
+ previousNetwork: string | null;
25
+ };
26
+ export type ProviderDetectedEvent = {
27
+ type: 'provider_detected';
28
+ provider: string;
29
+ };
30
+ export type ProviderConnectingEvent = {
31
+ type: 'provider_connecting';
32
+ provider: string;
33
+ value: boolean;
34
+ };
35
+ export type ProviderConnectedEvent = {
36
+ type: 'provider_connected';
37
+ provider: string;
38
+ };
39
+ export type ProviderDisconnectedEvent = {
40
+ type: 'provider_disconnected';
41
+ provider: string;
42
+ };
43
+ export type Event = NamespaceDisconnectedEvent | NamespaceConnectedEvent | NamespaceSwitchedAccountEvent | NamespaceSwitchedNetworkEvent | ProviderDetectedEvent | ProviderConnectingEvent | ProviderConnectedEvent | ProviderDisconnectedEvent;
44
+ /**
45
+ *
46
+ * Keeping an array of Event and when iterates over its values, it will be removed (consume) from the array.
47
+ *
48
+ */
49
+ export declare class ConsumableEvents {
50
+ #private;
51
+ push(val: Event): void;
52
+ [Symbol.iterator](): Iterator<Event>;
53
+ }
54
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 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BAAuB,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,KAAK,GACb,0BAA0B,GAC1B,uBAAuB,GACvB,6BAA6B,GAC7B,6BAA6B,GAC7B,qBAAqB,GACrB,uBAAuB,GACvB,sBAAsB,GACtB,yBAAyB,CAAC;AAE9B;;;;GAIG;AACH,qBAAa,gBAAgB;;IAG3B,IAAI,CAAC,GAAG,EAAE,KAAK;IAIf,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC;CAgBrC"}
@@ -0,0 +1,14 @@
1
+ import type { Event } from './events.js';
2
+ import type { RawStore, State } from './store.js';
3
+ export interface Store extends Omit<RawStore, 'subscribe'> {
4
+ subscribe(listener: (event: Event, state: State, prevState: State) => void): {
5
+ flushEvents(): void;
6
+ };
7
+ }
8
+ /**
9
+ * Zustand's store provides a set of built-in functionalities,
10
+ * but it may not meet all our requirements.
11
+ * This function modifies the interface and adds or updates the available methods.
12
+ */
13
+ export declare function extend(store: RawStore): Store;
14
+ //# sourceMappingURL=extend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extend.d.ts","sourceRoot":"","sources":["../../../src/hub/store/extend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EAIN,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAIlD,MAAM,WAAW,KAAM,SAAQ,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC;IACxD,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,KAAK,IAAI,GAAG;QAC3E,WAAW,IAAI,IAAI,CAAC;KACrB,CAAC;CACH;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,QAAQ,GAAG,KAAK,CA+C7C"}
@@ -0,0 +1,11 @@
1
+ /************ Hub ************/
2
+ import type { State } from './mod.js';
3
+ import type { StateCreator } from 'zustand';
4
+ type HubConfig = object;
5
+ export interface HubStore {
6
+ config: HubConfig;
7
+ }
8
+ type HubStateCreator = StateCreator<State, [], [], HubStore>;
9
+ declare const hubStore: HubStateCreator;
10
+ export { hubStore };
11
+ //# sourceMappingURL=hub.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hub.d.ts","sourceRoot":"","sources":["../../../src/hub/store/hub.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,KAAK,SAAS,GAAG,MAAM,CAAC;AAExB,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,SAAS,CAAC;CACnB;AAED,KAAK,eAAe,GAAG,YAAY,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC;AAE7D,QAAA,MAAM,QAAQ,EAAE,eAEd,CAAC;AAEH,OAAO,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { guessProviderStateSelector, namespaceStateSelector, } from './selectors.js';
2
+ export type { Store } from './extend.js';
3
+ export type { State } from './store.js';
4
+ export type { Event, ProviderDetectedEvent, ProviderConnectingEvent, ProviderConnectedEvent, ProviderDisconnectedEvent, NamespaceDisconnectedEvent, NamespaceConnectedEvent, NamespaceSwitchedAccountEvent, } from './events.js';
5
+ export type { ProviderMetadata, ProviderConfig, ProviderInfo, ProviderProperty, } from './providers.js';
6
+ export type { NamespaceConfig, NamespaceData } from './namespaces.js';
7
+ export { createStore } from './store.js';
8
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/hub/store/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,YAAY,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,YAAY,EACV,KAAK,EAEL,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,yBAAyB,EAEzB,0BAA0B,EAC1B,uBAAuB,EACvB,6BAA6B,GAC9B,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,2 @@
1
+ var E=Object.defineProperty;var o=(i,r)=>E(i,"name",{value:r,configurable:!0});function d(i,r){let e=i.namespaces.list,n=Object.keys(e).filter(c=>e[c].info.providerId===r),a=!!i.providers.list[r]?.data.installed,t=n.length>0?n.some(c=>e[c].data.connected):!1,s=n.length>0?n.some(c=>e[c].data.connecting):!1;return{installed:a,connected:t,connecting:s}}o(d,"guessProviderStateSelector");function S(i,r){return i.namespaces.list[r].data}o(S,"namespaceStateSelector");import{createStore as x}from"zustand/vanilla";function f(i){let r=o(e=>n=>{let a=o((t,s,c)=>{for(let p of t)n(p,s,c)},"executeListener");return e.subscribe((t,s)=>{let c=h(t,s),m=[...l(t),...c];a(m,t,s)}),{flushEvents:o(()=>{let t=e.getState(),s=l(t);a(s,t,t)},"flushEvents")}},"extendedSubscribe");return new Proxy(i,{get:o(function(e,n,a){return n==="subscribe"?r(e):Reflect.get(e,n,a)},"get")})}o(f,"extend");function l(i){return[...i.providers.events,...i.namespaces.events]}o(l,"tryConsumeEvents");function h(i,r){let e=[];for(let n of Object.keys(i.providers.list)){let a=d(i,n),t=d(r,n);if(t.connecting!==a.connecting){let s={type:"provider_connecting",provider:n,value:a.connecting};e.push(s)}if(!t.connected&&a.connected){let s={type:"provider_connected",provider:n};e.push(s)}if(t.connected&&!a.connected){let s={type:"provider_disconnected",provider:n};e.push(s)}}return e}o(h,"getEventsLike");var y=o(()=>({config:{}}),"hubStore");import{produce as g}from"immer";var v=class{static{o(this,"ConsumableEvents")}#e=[];push(r){this.#e.push(r)}[Symbol.iterator](){return{next:o(()=>this.#e.length==0?{done:!0,value:void 0}:{done:!1,value:this.#e.shift()},"next")}}};var P=o((i,r)=>({events:new v,list:{},addNamespace:o((e,n)=>{let t={data:{accounts:null,network:null,connected:!1,connecting:!1,connectArgs:null},error:"",info:n};i(g(s=>{s.namespaces.list[e]=t}))},"addNamespace"),updateStatus:o((e,n,a)=>{let t=r().namespaces.list[e];if(!t)throw new Error(`No namespace with '${e}' found.`);r().namespaces._produceEventsWhenUpdatingStatus(t,e,n,a),i(g(s=>{s.namespaces.list[e].data[n]=a}))},"updateStatus"),getNamespaceData(e){return S(r(),e)},_produceEventsWhenUpdatingStatus:o((e,n,a,t)=>{if(a==="accounts")if(Object.is(t,null)||Array.isArray(t)&&t.length===0){if(r().namespaces.list[n].data.connected){let p={type:"namespace_disconnected",provider:e.info.providerId,namespace:e.info.namespaceId};r().namespaces.events.push(p)}}else{let c=r().namespaces.list[n].data.accounts;if(c){if(!([...c].sort().toString()===t.sort().toString())){let m={type:"namespace_account_switched",provider:e.info.providerId,namespace:e.info.namespaceId,previousAccounts:c,accounts:t};r().namespaces.events.push(m)}}else{let p={type:"namespace_connected",provider:e.info.providerId,namespace:e.info.namespaceId,accounts:t};r().namespaces.events.push(p)}}else if(a==="network"){let s=r().namespaces.list[n].data.network,c={type:"namespace_network_switched",provider:e.info.providerId,namespace:e.info.namespaceId,network:t,previousNetwork:s};r().namespaces.events.push(c)}},"_produceEventsWhenUpdatingStatus")}),"namespacesStore");import{produce as u}from"immer";var N=o((i,r)=>({events:new v,list:{},addProvider:o((e,n)=>{let a={data:{installed:!1},error:"",config:n};i(u(t=>{t.providers.list[e]=a}))},"addProvider"),removeProvider:o(e=>{i(u(n=>{delete n.providers.list[e]}))},"removeProvider"),updateStatus:o((e,n,a)=>{let t=r().providers.list[e];if(!t)throw new Error(`No namespace namespace with '${e}' found.`);r().providers._produceEventsWhenUpdatingStatus(t,e,n,a),i(u(s=>{s.providers.list[e].data[n]=a}))},"updateStatus"),guessNamespacesState:o(e=>d(r(),e),"guessNamespacesState"),_produceEventsWhenUpdatingStatus:o((e,n,a,t)=>{if(a==="installed"){let s={type:"provider_detected",provider:n};r().providers.events.push(s)}},"_produceEventsWhenUpdatingStatus")}),"providersStore");var w=o(()=>{let i=x((...r)=>({hub:y(...r),providers:N(...r),namespaces:P(...r)}));return f(i)},"createStore");export{w as createStore,d as guessProviderStateSelector,S as namespaceStateSelector};
2
+ //# sourceMappingURL=mod.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\n connectArgs: Record<string, any> | null;\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 connectArgs: null,\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 // Clone the object from the Zustand store, as it's immutable, to avoid errors during sorting.\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 { 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';\n\ntype Property<N extends string, V> = { name: N; value: V };\n\n/**\n * The set of namespace keys a provider registered. Falls back to `string` when\n * `TNS` is empty (e.g., `.config('metadata', ...)` was called before any\n * `.add()`), so the metadata can still be written. After `.add()` calls\n * accumulate, this narrows to exactly the registered keys.\n */\ntype RegisteredKey<TNS> = [keyof TNS] extends [never]\n ? string\n : keyof TNS & string;\n\nexport type NamespacesProperty<TNS = unknown> = Property<\n 'namespaces',\n {\n selection: 'single' | 'multiple';\n data: {\n label: string;\n id: string;\n value: RegisteredKey<TNS>;\n unsupported?: boolean;\n getSupportedChains: (chains: BlockchainMeta[]) => BlockchainMeta[];\n }[];\n }\n>;\n\nexport type DerivationPathProperty<TNS = unknown> = Property<\n 'derivationPath',\n {\n data: {\n id: string;\n label: string;\n namespace: RegisteredKey<TNS>;\n generateDerivationPath: (index: string) => string;\n }[];\n }\n>;\n\nexport type DetailsProperty = Property<\n 'details',\n {\n mobileWallet?: boolean;\n showOnMobile?: boolean;\n isContractWallet?: boolean;\n }\n>;\n\nexport type SignersProperty = Property<\n 'signers',\n {\n getSigners: () => Promise<SignerFactory>;\n }\n>;\n\nexport type ProviderProperty<TNS = unknown> =\n | NamespacesProperty<TNS>\n | DerivationPathProperty<TNS>\n | DetailsProperty\n | SignersProperty;\n\nexport interface ProviderMetadata<TNS = unknown> {\n name: string;\n icon: string;\n extensions: Partial<Record<Browsers, string>>;\n properties?: ProviderProperty<TNS>[];\n}\n\nexport interface ProviderConfig<TNS = unknown> {\n metadata: ProviderMetadata<TNS>;\n}\n\nexport type ProviderInfo<TNS = unknown> = ProviderConfig<TNS>;\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
+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ACxB,OAAOA,EAAM,UAAU,KAAKJ,CAAE,CAChC,CAAC,CACH,CACF,EANgB,kBAOhB,aAAcJ,EAAA,CAACI,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,EAbc,gBAcd,qBAAsBV,EAACY,GACdC,EAA2BX,EAAI,EAAGU,CAAU,EAD/B,wBAItB,iCAAkCZ,EAAA,CAACc,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,EATkC,mCAUpC,GAtD8C,kBL3GvC,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
+ "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
+ }
@@ -0,0 +1,38 @@
1
+ /************ Namespace ************/
2
+ import type { StateCreator } from 'zustand';
3
+ import { ConsumableEvents } from './events.js';
4
+ import { type State } from './mod.js';
5
+ export type NamespaceConfig = object;
6
+ export interface NamespaceData {
7
+ accounts: null | string[];
8
+ network: null | string;
9
+ connected: boolean;
10
+ connecting: boolean;
11
+ connectArgs: Record<string, any> | null;
12
+ }
13
+ interface NamespaceInfo {
14
+ providerId: string;
15
+ namespaceId: string;
16
+ }
17
+ interface NamespaceItem {
18
+ info: NamespaceInfo;
19
+ data: NamespaceData;
20
+ error: unknown;
21
+ }
22
+ type NamespaceState = {
23
+ events: InstanceType<typeof ConsumableEvents>;
24
+ list: Record<string, NamespaceItem>;
25
+ };
26
+ interface NamespaceActions {
27
+ addNamespace: (id: string, config: NamespaceInfo) => void;
28
+ updateStatus: <K extends keyof NamespaceData>(id: string, key: K, value: NamespaceData[K]) => void;
29
+ _produceEventsWhenUpdatingStatus: <K extends keyof NamespaceData>(namespace: NamespaceItem, id: string, key: K, value: NamespaceData[K]) => void;
30
+ }
31
+ interface NamespaceSelectors {
32
+ getNamespaceData(storeId: string): NamespaceData;
33
+ }
34
+ export type NamespaceStore = NamespaceState & NamespaceActions & NamespaceSelectors;
35
+ type NamespaceStateCreator = StateCreator<State, [], [], NamespaceStore>;
36
+ declare const namespacesStore: NamespaceStateCreator;
37
+ export { namespacesStore };
38
+ //# sourceMappingURL=namespaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namespaces.d.ts","sourceRoot":"","sources":["../../../src/hub/store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