@hub3js/std 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 (72) hide show
  1. package/actions/package.json +8 -0
  2. package/builders/package.json +8 -0
  3. package/dist/actions/disconnect.d.ts +8 -0
  4. package/dist/actions/disconnect.d.ts.map +1 -0
  5. package/dist/actions/mod.d.ts +2 -0
  6. package/dist/actions/mod.d.ts.map +1 -0
  7. package/dist/actions/mod.js +2 -0
  8. package/dist/actions/mod.js.map +7 -0
  9. package/dist/builders/disconnect.d.ts +10 -0
  10. package/dist/builders/disconnect.d.ts.map +1 -0
  11. package/dist/builders/mod.d.ts +2 -0
  12. package/dist/builders/mod.d.ts.map +1 -0
  13. package/dist/builders/mod.js +2 -0
  14. package/dist/builders/mod.js.map +7 -0
  15. package/dist/hooks/changeAccountSubscriber.d.ts +89 -0
  16. package/dist/hooks/changeAccountSubscriber.d.ts.map +1 -0
  17. package/dist/hooks/mod.d.ts +2 -0
  18. package/dist/hooks/mod.d.ts.map +1 -0
  19. package/dist/hooks/mod.js +2 -0
  20. package/dist/hooks/mod.js.map +7 -0
  21. package/dist/operators/after.d.ts +4 -0
  22. package/dist/operators/after.d.ts.map +1 -0
  23. package/dist/operators/and.d.ts +6 -0
  24. package/dist/operators/and.d.ts.map +1 -0
  25. package/dist/operators/before.d.ts +8 -0
  26. package/dist/operators/before.d.ts.map +1 -0
  27. package/dist/operators/mod.d.ts +5 -0
  28. package/dist/operators/mod.d.ts.map +1 -0
  29. package/dist/operators/mod.js +2 -0
  30. package/dist/operators/mod.js.map +7 -0
  31. package/dist/operators/or.d.ts +15 -0
  32. package/dist/operators/or.d.ts.map +1 -0
  33. package/dist/types/accounts.d.ts +11 -0
  34. package/dist/types/accounts.d.ts.map +1 -0
  35. package/dist/types/mod.d.ts +3 -0
  36. package/dist/types/mod.d.ts.map +1 -0
  37. package/dist/types/mod.js +1 -0
  38. package/dist/types/mod.js.map +7 -0
  39. package/dist/types/namespace.d.ts +10 -0
  40. package/dist/types/namespace.d.ts.map +1 -0
  41. package/dist/utils/caip.d.ts +2 -0
  42. package/dist/utils/caip.d.ts.map +1 -0
  43. package/dist/utils/error.d.ts +11 -0
  44. package/dist/utils/error.d.ts.map +1 -0
  45. package/dist/utils/mod.d.ts +3 -0
  46. package/dist/utils/mod.d.ts.map +1 -0
  47. package/dist/utils/mod.js +2 -0
  48. package/dist/utils/mod.js.map +7 -0
  49. package/hooks/package.json +8 -0
  50. package/operators/package.json +8 -0
  51. package/package.json +61 -0
  52. package/readme.md +15 -0
  53. package/src/actions/disconnect.ts +16 -0
  54. package/src/actions/mod.ts +1 -0
  55. package/src/builders/disconnect.ts +19 -0
  56. package/src/builders/mod.ts +1 -0
  57. package/src/hooks/changeAccountSubscriber.test.ts +172 -0
  58. package/src/hooks/changeAccountSubscriber.ts +239 -0
  59. package/src/hooks/mod.ts +1 -0
  60. package/src/operators/after.ts +8 -0
  61. package/src/operators/and.ts +39 -0
  62. package/src/operators/before.ts +12 -0
  63. package/src/operators/mod.ts +11 -0
  64. package/src/operators/or.ts +19 -0
  65. package/src/types/accounts.ts +13 -0
  66. package/src/types/mod.ts +11 -0
  67. package/src/types/namespace.ts +26 -0
  68. package/src/utils/caip.ts +10 -0
  69. package/src/utils/error.ts +44 -0
  70. package/src/utils/mod.ts +2 -0
  71. package/types/package.json +8 -0
  72. package/utils/package.json +8 -0
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@hub3js/std/actions",
3
+ "type": "module",
4
+ "main": "../dist/actions/mod.js",
5
+ "module": "../dist/actions/mod.js",
6
+ "types": "../dist/actions/mod.d.ts",
7
+ "sideEffects": false
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@hub3js/std/builders",
3
+ "type": "module",
4
+ "main": "../dist/builders/mod.js",
5
+ "module": "../dist/builders/mod.js",
6
+ "types": "../dist/builders/mod.d.ts",
7
+ "sideEffects": false
8
+ }
@@ -0,0 +1,8 @@
1
+ import type { Context } from '@hub3js/core';
2
+ export declare function disconnect(context: Context): void;
3
+ /**
4
+ * Recommended action defaults every namespace should wire up. Tuple shape
5
+ * matches what `NamespaceBuilder.action(...)` accepts as a list.
6
+ */
7
+ export declare const recommended: (readonly ["disconnect", typeof disconnect])[];
8
+ //# sourceMappingURL=disconnect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disconnect.d.ts","sourceRoot":"","sources":["../../src/actions/disconnect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAOjD;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,gDAAwC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { disconnect, recommended as recommendedActions } from './disconnect.js';
2
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/actions/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,IAAI,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,2 @@
1
+ var c=Object.defineProperty;var t=(n,e)=>c(n,"name",{value:e,configurable:!0});function o(n){let[,e]=n.state();e("network",null),e("accounts",null),e("connected",!1),e("connecting",!1),e("connectArgs",null)}t(o,"disconnect");var s=[["disconnect",o]];export{o as disconnect,s as recommendedActions};
2
+ //# sourceMappingURL=mod.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/actions/disconnect.ts"],
4
+ "sourcesContent": ["import type { Context } from '@hub3js/core';\n\nexport function disconnect(context: Context): void {\n const [, setState] = context.state();\n setState('network', null);\n setState('accounts', null);\n setState('connected', false);\n setState('connecting', false);\n setState('connectArgs', null);\n}\n\n/**\n * Recommended action defaults every namespace should wire up. Tuple shape\n * matches what `NamespaceBuilder.action(...)` accepts as a list.\n */\nexport const recommended = [['disconnect', disconnect] as const];\n"],
5
+ "mappings": "+EAEO,SAASA,EAAWC,EAAwB,CACjD,GAAM,CAAC,CAAEC,CAAQ,EAAID,EAAQ,MAAM,EACnCC,EAAS,UAAW,IAAI,EACxBA,EAAS,WAAY,IAAI,EACzBA,EAAS,YAAa,EAAK,EAC3BA,EAAS,aAAc,EAAK,EAC5BA,EAAS,cAAe,IAAI,CAC9B,CAPgBC,EAAAH,EAAA,cAaT,IAAMI,EAAc,CAAC,CAAC,aAAcJ,CAAU,CAAU",
6
+ "names": ["disconnect", "context", "setState", "__name", "recommended"]
7
+ }
@@ -0,0 +1,10 @@
1
+ import type { AutoImplementedActionsByRecommended } from '../types/namespace.js';
2
+ import type { Actions } from '@hub3js/core';
3
+ import { ActionBuilder } from '@hub3js/core';
4
+ /**
5
+ * Pre-wired `ActionBuilder` for the canonical `disconnect` action. The wallet
6
+ * package's own action type `T` must include a `disconnect` member compatible
7
+ * with `AutoImplementedActionsByRecommended['disconnect']`.
8
+ */
9
+ export declare const disconnect: <T extends Actions<T> & Record<"disconnect", AutoImplementedActionsByRecommended["disconnect"]>>() => ActionBuilder<T, "disconnect">;
10
+ //# sourceMappingURL=disconnect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disconnect.d.ts","sourceRoot":"","sources":["../../src/builders/disconnect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,uBAAuB,CAAC;AACjF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7C;;;;GAIG;AACH,eAAO,MAAM,UAAU,GACrB,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,GAClB,MAAM,CAAC,YAAY,EAAE,mCAAmC,CAAC,YAAY,CAAC,CAAC,OAIhC,aAAa,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { disconnect } from './disconnect.js';
2
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/builders/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,2 @@
1
+ var c=Object.defineProperty;var e=(o,n)=>c(o,"name",{value:n,configurable:!0});import{ActionBuilder as s}from"@hub3js/core";function t(o){let[,n]=o.state();n("network",null),n("accounts",null),n("connected",!1),n("connecting",!1),n("connectArgs",null)}e(t,"disconnect");var i=e(()=>new s("disconnect").action(t),"disconnect");export{i as disconnect};
2
+ //# sourceMappingURL=mod.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/builders/disconnect.ts", "../../src/actions/disconnect.ts"],
4
+ "sourcesContent": ["import type { AutoImplementedActionsByRecommended } from '../types/namespace.js';\nimport type { Actions } from '@hub3js/core';\n\nimport { ActionBuilder } from '@hub3js/core';\n\nimport { disconnect as disconnectAction } from '../actions/disconnect.js';\n\n/**\n * Pre-wired `ActionBuilder` for the canonical `disconnect` action. The wallet\n * package's own action type `T` must include a `disconnect` member compatible\n * with `AutoImplementedActionsByRecommended['disconnect']`.\n */\nexport const disconnect = <\n T extends Actions<T> &\n Record<'disconnect', AutoImplementedActionsByRecommended['disconnect']>,\n>() =>\n new ActionBuilder<AutoImplementedActionsByRecommended, 'disconnect'>(\n 'disconnect',\n ).action(disconnectAction) as unknown as ActionBuilder<T, 'disconnect'>;\n", "import type { Context } from '@hub3js/core';\n\nexport function disconnect(context: Context): void {\n const [, setState] = context.state();\n setState('network', null);\n setState('accounts', null);\n setState('connected', false);\n setState('connecting', false);\n setState('connectArgs', null);\n}\n\n/**\n * Recommended action defaults every namespace should wire up. Tuple shape\n * matches what `NamespaceBuilder.action(...)` accepts as a list.\n */\nexport const recommended = [['disconnect', disconnect] as const];\n"],
5
+ "mappings": "+EAGA,OAAS,iBAAAA,MAAqB,eCDvB,SAASC,EAAWC,EAAwB,CACjD,GAAM,CAAC,CAAEC,CAAQ,EAAID,EAAQ,MAAM,EACnCC,EAAS,UAAW,IAAI,EACxBA,EAAS,WAAY,IAAI,EACzBA,EAAS,YAAa,EAAK,EAC3BA,EAAS,aAAc,EAAK,EAC5BA,EAAS,cAAe,IAAI,CAC9B,CAPgBC,EAAAH,EAAA,cDUT,IAAMI,EAAaC,EAAA,IAIxB,IAAIC,EACF,YACF,EAAE,OAAOF,CAAgB,EAND",
6
+ "names": ["ActionBuilder", "disconnect", "context", "setState", "__name", "disconnect", "__name", "ActionBuilder"]
7
+ }
@@ -0,0 +1,89 @@
1
+ import type { AutoImplementedActionsByRecommended } from '../types/namespace.js';
2
+ import type { Actions, Context, Subscriber, SubscriberCleanUp } from '@hub3js/core';
3
+ type OnSwitchAccountEvent<EventType> = {
4
+ payload: EventType;
5
+ preventDefault: () => void;
6
+ };
7
+ export declare class ChangeAccountSubscriberBuilder<EventType, ProviderAPI, ActionsType extends Actions<ActionsType> & Actions<AutoImplementedActionsByRecommended>> {
8
+ #private;
9
+ /**
10
+ * Sets the function that provides the provider API instance.
11
+ *
12
+ * @param operator - Function that returns the provider API instance
13
+ * @returns The builder instance for method chaining
14
+ * @example
15
+ * ```typescript
16
+ * builder.getInstance(() => window.ethereum)
17
+ * ```
18
+ */
19
+ getInstance(operator: () => ProviderAPI): this;
20
+ /**
21
+ * Sets the formatter function that converts provider events to account strings.
22
+ *
23
+ * @param operator - Function that takes a provider instance and event, returns array of account strings
24
+ * @returns The builder instance for method chaining
25
+ * @example
26
+ * ```typescript
27
+ * builder.format(async (instance, event) => event.accounts || [])
28
+ * ```
29
+ */
30
+ format(operator: (instance: ProviderAPI, event: EventType) => Promise<string[]>): this;
31
+ /**
32
+ * Set a handler that runs whenever a **switch-account** event occurs.
33
+ *
34
+ * The provided operator is called with:
35
+ * - `event`: An object containing:
36
+ * - `payload`: The event payload associated with the account switch.
37
+ * - `preventDefault`: A function that prevents the default switch-account
38
+ * behavior (e.g., updating the active accounts list).
39
+ * - `context`: The execution context of the current flow or action.
40
+ *
41
+ * Calling `event.preventDefault()` inside the handler cancels the built-in
42
+ * account switching logic.
43
+ *
44
+ * @param operator - A function invoked on each switch-account event.
45
+ * It receives `(event, context)` and can call `event.preventDefault()` to
46
+ * stop the default behavior.
47
+ *
48
+ * @returns The builder instance for method chaining.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * builder.onSwitchAccount((event, context) => {
53
+ * if (!event.payload.userConfirmed) {
54
+ * event.preventDefault(); // cancel default account switch
55
+ * }
56
+ *
57
+ * console.log("Switching account:", event.payload.accountId);
58
+ * });
59
+ * ```
60
+ */
61
+ onSwitchAccount(operator: (event: OnSwitchAccountEvent<EventType>, context: Context<ActionsType>) => void): this;
62
+ /**
63
+ * Sets the event listener attachment function.
64
+ *
65
+ * @param operator - Function that attaches an event listener and optionally returns a cleanup function
66
+ * @returns The builder instance for method chaining
67
+ * @example
68
+ * ```typescript
69
+ * builder.addEventListener((instance, callback) => {
70
+ * return instance.on('accountsChanged', callback);
71
+ * })
72
+ * ```
73
+ */
74
+ addEventListener(operator: (instance: ProviderAPI, callback: (event: EventType) => void) => (() => void) | void): this;
75
+ /**
76
+ * Sets the event listener removal function.
77
+ *
78
+ * @param operator - Function that removes an event listener from the provider
79
+ * @returns The builder instance for method chaining
80
+ * @example
81
+ * ```typescript
82
+ * builder.removeEventListener((instance, callback) => instance.off('accountsChanged', callback))
83
+ * ```
84
+ */
85
+ removeEventListener(operator: (instance: ProviderAPI, callback: (event: EventType) => void) => void): this;
86
+ build(): [Subscriber<ActionsType>, SubscriberCleanUp<ActionsType>];
87
+ }
88
+ export {};
89
+ //# sourceMappingURL=changeAccountSubscriber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"changeAccountSubscriber.d.ts","sourceRoot":"","sources":["../../src/hooks/changeAccountSubscriber.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,uBAAuB,CAAC;AACjF,OAAO,KAAK,EACV,OAAO,EACP,OAAO,EACP,UAAU,EACV,iBAAiB,EAClB,MAAM,cAAc,CAAC;AAEtB,KAAK,oBAAoB,CAAC,SAAS,IAAI;IACrC,OAAO,EAAE,SAAS,CAAC;IACnB,cAAc,EAAE,MAAM,IAAI,CAAC;CAC5B,CAAC;AAEF,qBAAa,8BAA8B,CACzC,SAAS,EACT,WAAW,EACX,WAAW,SAAS,OAAO,CAAC,WAAW,CAAC,GACtC,OAAO,CAAC,mCAAmC,CAAC;;IAuB9C;;;;;;;;;OASG;IACI,WAAW,CAAC,QAAQ,EAAE,MAAM,WAAW;IAK9C;;;;;;;;;OASG;IACI,MAAM,CACX,QAAQ,EAAE,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC;IAM1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACI,eAAe,CACpB,QAAQ,EAAE,CACR,KAAK,EAAE,oBAAoB,CAAC,SAAS,CAAC,EACtC,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,KAC1B,IAAI;IAMX;;;;;;;;;;;OAWG;IACI,gBAAgB,CACrB,QAAQ,EAAE,CACR,QAAQ,EAAE,WAAW,EACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,KACjC,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI;IAM1B;;;;;;;;;OASG;IACI,mBAAmB,CACxB,QAAQ,EAAE,CACR,QAAQ,EAAE,WAAW,EACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,KACjC,IAAI;IAMJ,KAAK,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,iBAAiB,CAAC,WAAW,CAAC,CAAC;CAoF1E"}
@@ -0,0 +1,2 @@
1
+ export { ChangeAccountSubscriberBuilder } from './changeAccountSubscriber.js';
2
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/hooks/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,8BAA8B,CAAC"}
@@ -0,0 +1,2 @@
1
+ var b=Object.defineProperty;var i=(v,e)=>b(v,"name",{value:e,configurable:!0});var c=class{static{i(this,"ChangeAccountSubscriberBuilder")}#t=null;#n=null;#o=null;#i=null;#r=null;getInstance(e){return this.#t=e,this}format(e){return this.#n=e,this}onSwitchAccount(e){return this.#o=e,this}addEventListener(e){return this.#i=e,this}removeEventListener(e){return this.#r=e,this}build(){if(this.#t===null)throw new Error(this.#e("getInstance"));if(this.#n===null)throw new Error(this.#e("format"));if(this.#i===null)throw new Error(this.#e("addEventListener"));if(this.#r===null)throw new Error(this.#e("removeEventListener"));let e=this.#t,a=this.#n,d=this.#i,p=this.#r,h=this.#o,r,n;return[async o=>{let[,s]=o.state(),t=e();if(!t)throw new Error("Trying to subscribe to your wallet, but seems its instance is not available.");r=i(async l=>{let u=!0;h?.({payload:l,preventDefault:i(()=>{u=!1},"preventDefault")},o),u&&s("accounts",await a(t,l))},"subscriber"),n=d(t,r)},(o,s)=>{n&&typeof n=="function"&&n();let t=e();return p(t,r),s}]}#e(e){return`Required "${e}" operation has not been set for "changeAccountSubscriber"`}};export{c as ChangeAccountSubscriberBuilder};
2
+ //# sourceMappingURL=mod.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/hooks/changeAccountSubscriber.ts"],
4
+ "sourcesContent": ["import type { AutoImplementedActionsByRecommended } from '../types/namespace.js';\nimport type {\n Actions,\n Context,\n Subscriber,\n SubscriberCleanUp,\n} from '@hub3js/core';\n\ntype OnSwitchAccountEvent<EventType> = {\n payload: EventType;\n preventDefault: () => void;\n};\n\nexport class ChangeAccountSubscriberBuilder<\n EventType,\n ProviderAPI,\n ActionsType extends Actions<ActionsType> &\n Actions<AutoImplementedActionsByRecommended>,\n> {\n #getInstance: (() => ProviderAPI) | null = null;\n #format:\n | ((instance: ProviderAPI, event: EventType) => Promise<string[]>)\n | null = null;\n #onSwitchAccount:\n | ((\n event: OnSwitchAccountEvent<EventType>,\n context: Context<ActionsType>,\n ) => void)\n | null = null;\n\n #addEventListener:\n | ((\n instance: ProviderAPI,\n callback: (event: EventType) => void,\n ) => (() => void) | void)\n | null = null;\n #removeEventListener:\n | ((instance: ProviderAPI, callback: (event: EventType) => void) => void)\n | null = null;\n\n /**\n * Sets the function that provides the provider API instance.\n *\n * @param operator - Function that returns the provider API instance\n * @returns The builder instance for method chaining\n * @example\n * ```typescript\n * builder.getInstance(() => window.ethereum)\n * ```\n */\n public getInstance(operator: () => ProviderAPI) {\n this.#getInstance = operator;\n return this;\n }\n\n /**\n * Sets the formatter function that converts provider events to account strings.\n *\n * @param operator - Function that takes a provider instance and event, returns array of account strings\n * @returns The builder instance for method chaining\n * @example\n * ```typescript\n * builder.format(async (instance, event) => event.accounts || [])\n * ```\n */\n public format(\n operator: (instance: ProviderAPI, event: EventType) => Promise<string[]>,\n ) {\n this.#format = operator;\n return this;\n }\n\n /**\n * Set a handler that runs whenever a **switch-account** event occurs.\n *\n * The provided operator is called with:\n * - `event`: An object containing:\n * - `payload`: The event payload associated with the account switch.\n * - `preventDefault`: A function that prevents the default switch-account\n * behavior (e.g., updating the active accounts list).\n * - `context`: The execution context of the current flow or action.\n *\n * Calling `event.preventDefault()` inside the handler cancels the built-in\n * account switching logic.\n *\n * @param operator - A function invoked on each switch-account event.\n * It receives `(event, context)` and can call `event.preventDefault()` to\n * stop the default behavior.\n *\n * @returns The builder instance for method chaining.\n *\n * @example\n * ```ts\n * builder.onSwitchAccount((event, context) => {\n * if (!event.payload.userConfirmed) {\n * event.preventDefault(); // cancel default account switch\n * }\n *\n * console.log(\"Switching account:\", event.payload.accountId);\n * });\n * ```\n */\n public onSwitchAccount(\n operator: (\n event: OnSwitchAccountEvent<EventType>,\n context: Context<ActionsType>,\n ) => void,\n ) {\n this.#onSwitchAccount = operator;\n return this;\n }\n\n /**\n * Sets the event listener attachment function.\n *\n * @param operator - Function that attaches an event listener and optionally returns a cleanup function\n * @returns The builder instance for method chaining\n * @example\n * ```typescript\n * builder.addEventListener((instance, callback) => {\n * return instance.on('accountsChanged', callback);\n * })\n * ```\n */\n public addEventListener(\n operator: (\n instance: ProviderAPI,\n callback: (event: EventType) => void,\n ) => (() => void) | void,\n ) {\n this.#addEventListener = operator;\n return this;\n }\n\n /**\n * Sets the event listener removal function.\n *\n * @param operator - Function that removes an event listener from the provider\n * @returns The builder instance for method chaining\n * @example\n * ```typescript\n * builder.removeEventListener((instance, callback) => instance.off('accountsChanged', callback))\n * ```\n */\n public removeEventListener(\n operator: (\n instance: ProviderAPI,\n callback: (event: EventType) => void,\n ) => void,\n ) {\n this.#removeEventListener = operator;\n return this;\n }\n\n public build(): [Subscriber<ActionsType>, SubscriberCleanUp<ActionsType>] {\n if (this.#getInstance === null) {\n throw new Error(this.#getErrorMessage('getInstance'));\n }\n if (this.#format === null) {\n throw new Error(this.#getErrorMessage('format'));\n }\n if (this.#addEventListener === null) {\n throw new Error(this.#getErrorMessage('addEventListener'));\n }\n if (this.#removeEventListener === null) {\n throw new Error(this.#getErrorMessage('removeEventListener'));\n }\n\n /*\n * Capture current operator state at build time to ensure immutability.\n *\n * This creates a snapshot of all operators, preventing the built subscriber\n * from being affected by subsequent changes to the builder instance.\n * Each call to build() gets its own isolated set of operators, allowing\n * the builder to be reused for creating multiple independent subscribers.\n */\n const getInstance = this.#getInstance;\n const format = this.#format;\n const addEventListener = this.#addEventListener;\n const removeEventListener = this.#removeEventListener;\n const onSwitchAccount = this.#onSwitchAccount;\n\n let subscriber: (event: EventType) => void;\n let unsubscribe: (() => void) | void;\n return [\n async (context) => {\n const [, setState] = context.state();\n const instance = getInstance();\n\n if (!instance) {\n throw new Error(\n 'Trying to subscribe to your wallet, but seems its instance is not available.',\n );\n }\n subscriber = async (event) => {\n let shouldProceedWithDefault = true;\n onSwitchAccount?.(\n {\n payload: event,\n preventDefault: () => {\n shouldProceedWithDefault = false;\n },\n },\n context,\n );\n if (!shouldProceedWithDefault) {\n return;\n }\n setState('accounts', await format(instance, event));\n };\n unsubscribe = addEventListener(instance, subscriber);\n },\n (_, err) => {\n /*\n * Call the cleanup function if addEventListener returned one.\n * This handles providers that return an unsubscribe function from\n * their event listeners.\n */\n if (unsubscribe && typeof unsubscribe === 'function') {\n unsubscribe();\n }\n const instance = getInstance();\n\n /*\n * Always call removeEventListener as well to handle the on/off pattern.\n * This ensures cleanup works regardless of which pattern the provider uses.\n */\n removeEventListener(instance, subscriber);\n\n // subscriber can be passed to `or`; rethrow to chain into next `or`.\n return err;\n },\n ];\n }\n\n #getErrorMessage(operatorName: string) {\n return `Required \"${operatorName}\" operation has not been set for \"changeAccountSubscriber\"`;\n }\n}\n"],
5
+ "mappings": "+EAaO,IAAMA,EAAN,KAKL,CAlBF,MAkBE,CAAAC,EAAA,uCACAC,GAA2C,KAC3CC,GAEW,KACXC,GAKW,KAEXC,GAKW,KACXC,GAEW,KAYJ,YAAYC,EAA6B,CAC9C,YAAKL,GAAeK,EACb,IACT,CAYO,OACLA,EACA,CACA,YAAKJ,GAAUI,EACR,IACT,CAgCO,gBACLA,EAIA,CACA,YAAKH,GAAmBG,EACjB,IACT,CAcO,iBACLA,EAIA,CACA,YAAKF,GAAoBE,EAClB,IACT,CAYO,oBACLA,EAIA,CACA,YAAKD,GAAuBC,EACrB,IACT,CAEO,OAAmE,CACxE,GAAI,KAAKL,KAAiB,KACxB,MAAM,IAAI,MAAM,KAAKM,GAAiB,aAAa,CAAC,EAEtD,GAAI,KAAKL,KAAY,KACnB,MAAM,IAAI,MAAM,KAAKK,GAAiB,QAAQ,CAAC,EAEjD,GAAI,KAAKH,KAAsB,KAC7B,MAAM,IAAI,MAAM,KAAKG,GAAiB,kBAAkB,CAAC,EAE3D,GAAI,KAAKF,KAAyB,KAChC,MAAM,IAAI,MAAM,KAAKE,GAAiB,qBAAqB,CAAC,EAW9D,IAAMC,EAAc,KAAKP,GACnBQ,EAAS,KAAKP,GACdQ,EAAmB,KAAKN,GACxBO,EAAsB,KAAKN,GAC3BO,EAAkB,KAAKT,GAEzBU,EACAC,EACJ,MAAO,CACL,MAAOC,GAAY,CACjB,GAAM,CAAC,CAAEC,CAAQ,EAAID,EAAQ,MAAM,EAC7BE,EAAWT,EAAY,EAE7B,GAAI,CAACS,EACH,MAAM,IAAI,MACR,8EACF,EAEFJ,EAAab,EAAA,MAAOkB,GAAU,CAC5B,IAAIC,EAA2B,GAC/BP,IACE,CACE,QAASM,EACT,eAAgBlB,EAAA,IAAM,CACpBmB,EAA2B,EAC7B,EAFgB,iBAGlB,EACAJ,CACF,EACKI,GAGLH,EAAS,WAAY,MAAMP,EAAOQ,EAAUC,CAAK,CAAC,CACpD,EAfa,cAgBbJ,EAAcJ,EAAiBO,EAAUJ,CAAU,CACrD,EACA,CAACO,EAAGC,IAAQ,CAMNP,GAAe,OAAOA,GAAgB,YACxCA,EAAY,EAEd,IAAMG,EAAWT,EAAY,EAM7B,OAAAG,EAAoBM,EAAUJ,CAAU,EAGjCQ,CACT,CACF,CACF,CAEAd,GAAiBe,EAAsB,CACrC,MAAO,aAAaA,CAAY,4DAClC,CACF",
6
+ "names": ["ChangeAccountSubscriberBuilder", "__name", "#getInstance", "#format", "#onSwitchAccount", "#addEventListener", "#removeEventListener", "operator", "#getErrorMessage", "getInstance", "format", "addEventListener", "removeEventListener", "onSwitchAccount", "subscriber", "unsubscribe", "context", "setState", "instance", "event", "shouldProceedWithDefault", "_", "err", "operatorName"]
7
+ }
@@ -0,0 +1,4 @@
1
+ import type { Context } from '@hub3js/core';
2
+ export declare function intoConnectionFinished(context: Context): void;
3
+ export declare const recommended: (readonly ["connect", typeof intoConnectionFinished])[];
4
+ //# sourceMappingURL=after.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"after.d.ts","sourceRoot":"","sources":["../../src/operators/after.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,QAGtD;AAED,eAAO,MAAM,WAAW,yDAAiD,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { Accounts, AccountsWithActiveChain } from '../types/accounts.js';
2
+ import type { Context } from '@hub3js/core';
3
+ export declare function connectAndUpdateStateForSingleNetwork(context: Context, accounts: Accounts): Accounts;
4
+ export declare function connectAndUpdateStateForMultiNetworks(context: Context, accounts: AccountsWithActiveChain): AccountsWithActiveChain;
5
+ export declare const recommended: never[];
6
+ //# sourceMappingURL=and.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"and.d.ts","sourceRoot":"","sources":["../../src/operators/and.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAI5C,wBAAgB,qCAAqC,CACnD,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,YAYnB;AAED,wBAAgB,qCAAqC,CACnD,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,uBAAuB,2BAalC;AAED,eAAO,MAAM,WAAW,SAAK,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { Context } from '@hub3js/core';
2
+ export declare function intoConnecting(context: Context): void;
3
+ /**
4
+ * Recommended `before` hooks every namespace should wire up. Tuple shape
5
+ * matches what `NamespaceBuilder.before(...)` expects.
6
+ */
7
+ export declare const recommended: (readonly ["connect", typeof intoConnecting])[];
8
+ //# sourceMappingURL=before.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"before.d.ts","sourceRoot":"","sources":["../../src/operators/before.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,QAG9C;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,iDAAyC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { intoConnecting, recommended as beforeRecommended } from './before.js';
2
+ export { intoConnectionFinished, recommended as afterRecommended, } from './after.js';
3
+ export { connectAndUpdateStateForMultiNetworks, connectAndUpdateStateForSingleNetwork, recommended as andRecommended, } from './and.js';
4
+ export { standardizeAndThrowError } from './or.js';
5
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/operators/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,IAAI,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EACL,sBAAsB,EACtB,WAAW,IAAI,gBAAgB,GAChC,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,qCAAqC,EACrC,qCAAqC,EACrC,WAAW,IAAI,cAAc,GAC9B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ var d=Object.defineProperty;var e=(t,o)=>d(t,"name",{value:o,configurable:!0});function c(t){let[,o]=t.state();o("connecting",!0)}e(c,"intoConnecting");var a=[["connect",c]];function s(t){let[,o]=t.state();o("connecting",!1)}e(s,"intoConnectionFinished");var m=[["connect",s]];import{AccountId as p}from"caip";function n(t){try{return p.parse(t),!0}catch{return!1}}e(n,"isValidCaipAddress");function u(t,o){if(!o.every(n))throw new Error(`Your provider should format account addresses in CAIP-10 format. Your provided accounts: ${o}`);let[,r]=t.state();return r("accounts",o),r("connected",!0),o}e(u,"connectAndUpdateStateForSingleNetwork");function f(t,o){if(!o.accounts.every(n))throw new Error(`Your provider should format account addresses in CAIP-10 format. Your provided accounts: ${o.accounts}`);let[,r]=t.state();return r("accounts",o.accounts),r("network",o.network),r("connected",!0),o}e(f,"connectAndUpdateStateForMultiNetworks");var x=[];function i(t){if(t instanceof Error)throw t;let o;typeof t=="object"&&t!==null&&"message"in t&&typeof t.message=="string"?o=t.message:typeof t=="string"?o=t:o=String(t);let r=new Error(o);throw typeof t=="object"&&t!==null&&("code"in t&&(r.code=t.code),"data"in t&&(r.data=t.data)),r}e(i,"parseErrorAndThrowStandardizeError");function h(t,o){i(o)}e(h,"standardizeAndThrowError");export{m as afterRecommended,x as andRecommended,a as beforeRecommended,f as connectAndUpdateStateForMultiNetworks,u as connectAndUpdateStateForSingleNetwork,c as intoConnecting,s as intoConnectionFinished,h as standardizeAndThrowError};
2
+ //# sourceMappingURL=mod.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/operators/before.ts", "../../src/operators/after.ts", "../../src/utils/caip.ts", "../../src/operators/and.ts", "../../src/utils/error.ts", "../../src/operators/or.ts"],
4
+ "sourcesContent": ["import type { Context } from '@hub3js/core';\n\nexport function intoConnecting(context: Context) {\n const [, setState] = context.state();\n setState('connecting', true);\n}\n\n/**\n * Recommended `before` hooks every namespace should wire up. Tuple shape\n * matches what `NamespaceBuilder.before(...)` expects.\n */\nexport const recommended = [['connect', intoConnecting] as const];\n", "import type { Context } from '@hub3js/core';\n\nexport function intoConnectionFinished(context: Context) {\n const [, setState] = context.state();\n setState('connecting', false);\n}\n\nexport const recommended = [['connect', intoConnectionFinished] as const];\n", "import { AccountId } from 'caip';\n\nexport function isValidCaipAddress(address: string): boolean {\n try {\n AccountId.parse(address);\n return true;\n } catch {\n return false;\n }\n}\n", "import type { Accounts, AccountsWithActiveChain } from '../types/accounts.js';\nimport type { Context } from '@hub3js/core';\n\nimport { isValidCaipAddress } from '../utils/caip.js';\n\nexport function connectAndUpdateStateForSingleNetwork(\n context: Context,\n accounts: Accounts,\n) {\n if (!accounts.every(isValidCaipAddress)) {\n throw new Error(\n `Your provider should format account addresses in CAIP-10 format. Your provided accounts: ${accounts}`,\n );\n }\n\n const [, setState] = context.state();\n setState('accounts', accounts);\n setState('connected', true);\n return accounts;\n}\n\nexport function connectAndUpdateStateForMultiNetworks(\n context: Context,\n accounts: AccountsWithActiveChain,\n) {\n if (!accounts.accounts.every(isValidCaipAddress)) {\n throw new Error(\n `Your provider should format account addresses in CAIP-10 format. Your provided accounts: ${accounts.accounts}`,\n );\n }\n\n const [, setState] = context.state();\n setState('accounts', accounts.accounts);\n setState('network', accounts.network);\n setState('connected', true);\n return accounts;\n}\n\nexport const recommended = [];\n", "/**\n * Standardizes an unknown error into an `Error` object and throws it.\n * If the input is already an `Error`, it's thrown directly. Otherwise a new\n * `Error` is created with the input's message or string representation,\n * preserving `code` and `data` fields when present.\n *\n * @param e - The unknown error object.\n * @throws {Error} - The standardized `Error` object.\n */\nexport function parseErrorAndThrowStandardizeError(e: unknown): never {\n if (e instanceof Error) {\n throw e;\n }\n\n let errorMessage: string;\n if (\n typeof e === 'object' &&\n e !== null &&\n 'message' in e &&\n typeof e.message === 'string'\n ) {\n errorMessage = e.message;\n } else if (typeof e === 'string') {\n errorMessage = e;\n } else {\n errorMessage = String(e);\n }\n\n const err = new Error(errorMessage) as Error & {\n code?: unknown;\n data?: unknown;\n };\n\n if (typeof e === 'object' && e !== null) {\n if ('code' in e) {\n err.code = e.code;\n }\n if ('data' in e) {\n err.data = e.data;\n }\n }\n\n throw err;\n}\n", "import type { Context } from '@hub3js/core';\n\nimport { parseErrorAndThrowStandardizeError } from '../utils/error.js';\n\n/**\n * Standardizes an unknown error into an `Error` object and throws it. If the\n * input is already an `Error`, it's thrown directly. Otherwise a new `Error`\n * is created with the input's message or string representation.\n *\n * The actual standardization lives in `parseErrorAndThrowStandardizeError`,\n * which can be called independently outside an action context.\n *\n * @param _context - The action context (unused).\n * @param e - The unknown error object.\n * @throws {Error} - The standardized `Error` object.\n */\nexport function standardizeAndThrowError(_context: Context, e: unknown): never {\n parseErrorAndThrowStandardizeError(e);\n}\n"],
5
+ "mappings": "+EAEO,SAASA,EAAeC,EAAkB,CAC/C,GAAM,CAAC,CAAEC,CAAQ,EAAID,EAAQ,MAAM,EACnCC,EAAS,aAAc,EAAI,CAC7B,CAHgBC,EAAAH,EAAA,kBAST,IAAMI,EAAc,CAAC,CAAC,UAAWJ,CAAc,CAAU,ECTzD,SAASK,EAAuBC,EAAkB,CACvD,GAAM,CAAC,CAAEC,CAAQ,EAAID,EAAQ,MAAM,EACnCC,EAAS,aAAc,EAAK,CAC9B,CAHgBC,EAAAH,EAAA,0BAKT,IAAMI,EAAc,CAAC,CAAC,UAAWJ,CAAsB,CAAU,ECPxE,OAAS,aAAAK,MAAiB,OAEnB,SAASC,EAAmBC,EAA0B,CAC3D,GAAI,CACF,OAAAC,EAAU,MAAMD,CAAO,EAChB,EACT,MAAQ,CACN,MAAO,EACT,CACF,CAPgBE,EAAAH,EAAA,sBCGT,SAASI,EACdC,EACAC,EACA,CACA,GAAI,CAACA,EAAS,MAAMC,CAAkB,EACpC,MAAM,IAAI,MACR,4FAA4FD,CAAQ,EACtG,EAGF,GAAM,CAAC,CAAEE,CAAQ,EAAIH,EAAQ,MAAM,EACnC,OAAAG,EAAS,WAAYF,CAAQ,EAC7BE,EAAS,YAAa,EAAI,EACnBF,CACT,CAdgBG,EAAAL,EAAA,yCAgBT,SAASM,EACdL,EACAC,EACA,CACA,GAAI,CAACA,EAAS,SAAS,MAAMC,CAAkB,EAC7C,MAAM,IAAI,MACR,4FAA4FD,EAAS,QAAQ,EAC/G,EAGF,GAAM,CAAC,CAAEE,CAAQ,EAAIH,EAAQ,MAAM,EACnC,OAAAG,EAAS,WAAYF,EAAS,QAAQ,EACtCE,EAAS,UAAWF,EAAS,OAAO,EACpCE,EAAS,YAAa,EAAI,EACnBF,CACT,CAfgBG,EAAAC,EAAA,yCAiBT,IAAMC,EAAc,CAAC,EC7BrB,SAASC,EAAmCC,EAAmB,CACpE,GAAIA,aAAa,MACf,MAAMA,EAGR,IAAIC,EAEF,OAAOD,GAAM,UACbA,IAAM,MACN,YAAaA,GACb,OAAOA,EAAE,SAAY,SAErBC,EAAeD,EAAE,QACR,OAAOA,GAAM,SACtBC,EAAeD,EAEfC,EAAe,OAAOD,CAAC,EAGzB,IAAME,EAAM,IAAI,MAAMD,CAAY,EAKlC,MAAI,OAAOD,GAAM,UAAYA,IAAM,OAC7B,SAAUA,IACZE,EAAI,KAAOF,EAAE,MAEX,SAAUA,IACZE,EAAI,KAAOF,EAAE,OAIXE,CACR,CAlCgBC,EAAAJ,EAAA,sCCOT,SAASK,EAAyBC,EAAmBC,EAAmB,CAC7EC,EAAmCD,CAAC,CACtC,CAFgBE,EAAAJ,EAAA",
6
+ "names": ["intoConnecting", "context", "setState", "__name", "recommended", "intoConnectionFinished", "context", "setState", "__name", "recommended", "AccountId", "isValidCaipAddress", "address", "AccountId", "__name", "connectAndUpdateStateForSingleNetwork", "context", "accounts", "isValidCaipAddress", "setState", "__name", "connectAndUpdateStateForMultiNetworks", "recommended", "parseErrorAndThrowStandardizeError", "e", "errorMessage", "err", "__name", "standardizeAndThrowError", "_context", "e", "parseErrorAndThrowStandardizeError", "__name"]
7
+ }
@@ -0,0 +1,15 @@
1
+ import type { Context } from '@hub3js/core';
2
+ /**
3
+ * Standardizes an unknown error into an `Error` object and throws it. If the
4
+ * input is already an `Error`, it's thrown directly. Otherwise a new `Error`
5
+ * is created with the input's message or string representation.
6
+ *
7
+ * The actual standardization lives in `parseErrorAndThrowStandardizeError`,
8
+ * which can be called independently outside an action context.
9
+ *
10
+ * @param _context - The action context (unused).
11
+ * @param e - The unknown error object.
12
+ * @throws {Error} - The standardized `Error` object.
13
+ */
14
+ export declare function standardizeAndThrowError(_context: Context, e: unknown): never;
15
+ //# sourceMappingURL=or.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"or.d.ts","sourceRoot":"","sources":["../../src/operators/or.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAI5C;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,KAAK,CAE7E"}
@@ -0,0 +1,11 @@
1
+ type CaipNamespace = string;
2
+ type CaipChainId = string;
3
+ type CaipAccountAddress = string;
4
+ export type CaipAccount = `${CaipNamespace}:${CaipChainId}:${CaipAccountAddress}`;
5
+ export type Accounts = CaipAccount[];
6
+ export type AccountsWithActiveChain = {
7
+ accounts: Accounts;
8
+ network: string;
9
+ };
10
+ export {};
11
+ //# sourceMappingURL=accounts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../src/types/accounts.ts"],"names":[],"mappings":"AAAA,KAAK,aAAa,GAAG,MAAM,CAAC;AAC5B,KAAK,WAAW,GAAG,MAAM,CAAC;AAC1B,KAAK,kBAAkB,GAAG,MAAM,CAAC;AAEjC,MAAM,MAAM,WAAW,GACrB,GAAG,aAAa,IAAI,WAAW,IAAI,kBAAkB,EAAE,CAAC;AAE1D,MAAM,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;AAErC,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export type { Namespace, CommonActions, AutoImplementedActionsByRecommended, } from './namespace.js';
2
+ export type { CaipAccount, Accounts, AccountsWithActiveChain, } from './accounts.js';
3
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/types/mod.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,SAAS,EACT,aAAa,EACb,mCAAmC,GACpC,MAAM,gBAAgB,CAAC;AAExB,YAAY,EACV,WAAW,EACX,QAAQ,EACR,uBAAuB,GACxB,MAAM,eAAe,CAAC"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=mod.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,10 @@
1
+ type KnownNamespace = 'EVM' | 'Solana' | 'Cosmos' | 'UTXO' | 'Starknet' | 'Tron' | 'Ton' | 'Sui' | 'XRPL' | 'Stellar';
2
+ export type Namespace = KnownNamespace | (string & {});
3
+ export interface CommonActions {
4
+ init: () => void;
5
+ }
6
+ export interface AutoImplementedActionsByRecommended {
7
+ disconnect: () => void;
8
+ }
9
+ export {};
10
+ //# sourceMappingURL=namespace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../../src/types/namespace.ts"],"names":[],"mappings":"AAKA,KAAK,cAAc,GACf,KAAK,GACL,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,UAAU,GACV,MAAM,GACN,KAAK,GACL,KAAK,GACL,MAAM,GACN,SAAS,CAAC;AAEd,MAAM,MAAM,SAAS,GAAG,cAAc,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAEvD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,IAAI,CAAC;CAClB;AAED,MAAM,WAAW,mCAAmC;IAClD,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB"}
@@ -0,0 +1,2 @@
1
+ export declare function isValidCaipAddress(address: string): boolean;
2
+ //# sourceMappingURL=caip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caip.d.ts","sourceRoot":"","sources":["../../src/utils/caip.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAO3D"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Standardizes an unknown error into an `Error` object and throws it.
3
+ * If the input is already an `Error`, it's thrown directly. Otherwise a new
4
+ * `Error` is created with the input's message or string representation,
5
+ * preserving `code` and `data` fields when present.
6
+ *
7
+ * @param e - The unknown error object.
8
+ * @throws {Error} - The standardized `Error` object.
9
+ */
10
+ export declare function parseErrorAndThrowStandardizeError(e: unknown): never;
11
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/utils/error.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,kCAAkC,CAAC,CAAC,EAAE,OAAO,GAAG,KAAK,CAkCpE"}
@@ -0,0 +1,3 @@
1
+ export { isValidCaipAddress } from './caip.js';
2
+ export { parseErrorAndThrowStandardizeError } from './error.js';
3
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/utils/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,kCAAkC,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,2 @@
1
+ var e=Object.defineProperty;var n=(r,o)=>e(r,"name",{value:o,configurable:!0});import{AccountId as a}from"caip";function s(r){try{return a.parse(r),!0}catch{return!1}}n(s,"isValidCaipAddress");function i(r){if(r instanceof Error)throw r;let o;typeof r=="object"&&r!==null&&"message"in r&&typeof r.message=="string"?o=r.message:typeof r=="string"?o=r:o=String(r);let t=new Error(o);throw typeof r=="object"&&r!==null&&("code"in r&&(t.code=r.code),"data"in r&&(t.data=r.data)),t}n(i,"parseErrorAndThrowStandardizeError");export{s as isValidCaipAddress,i as parseErrorAndThrowStandardizeError};
2
+ //# sourceMappingURL=mod.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/caip.ts", "../../src/utils/error.ts"],
4
+ "sourcesContent": ["import { AccountId } from 'caip';\n\nexport function isValidCaipAddress(address: string): boolean {\n try {\n AccountId.parse(address);\n return true;\n } catch {\n return false;\n }\n}\n", "/**\n * Standardizes an unknown error into an `Error` object and throws it.\n * If the input is already an `Error`, it's thrown directly. Otherwise a new\n * `Error` is created with the input's message or string representation,\n * preserving `code` and `data` fields when present.\n *\n * @param e - The unknown error object.\n * @throws {Error} - The standardized `Error` object.\n */\nexport function parseErrorAndThrowStandardizeError(e: unknown): never {\n if (e instanceof Error) {\n throw e;\n }\n\n let errorMessage: string;\n if (\n typeof e === 'object' &&\n e !== null &&\n 'message' in e &&\n typeof e.message === 'string'\n ) {\n errorMessage = e.message;\n } else if (typeof e === 'string') {\n errorMessage = e;\n } else {\n errorMessage = String(e);\n }\n\n const err = new Error(errorMessage) as Error & {\n code?: unknown;\n data?: unknown;\n };\n\n if (typeof e === 'object' && e !== null) {\n if ('code' in e) {\n err.code = e.code;\n }\n if ('data' in e) {\n err.data = e.data;\n }\n }\n\n throw err;\n}\n"],
5
+ "mappings": "+EAAA,OAAS,aAAAA,MAAiB,OAEnB,SAASC,EAAmBC,EAA0B,CAC3D,GAAI,CACF,OAAAC,EAAU,MAAMD,CAAO,EAChB,EACT,MAAQ,CACN,MAAO,EACT,CACF,CAPgBE,EAAAH,EAAA,sBCOT,SAASI,EAAmCC,EAAmB,CACpE,GAAIA,aAAa,MACf,MAAMA,EAGR,IAAIC,EAEF,OAAOD,GAAM,UACbA,IAAM,MACN,YAAaA,GACb,OAAOA,EAAE,SAAY,SAErBC,EAAeD,EAAE,QACR,OAAOA,GAAM,SACtBC,EAAeD,EAEfC,EAAe,OAAOD,CAAC,EAGzB,IAAME,EAAM,IAAI,MAAMD,CAAY,EAKlC,MAAI,OAAOD,GAAM,UAAYA,IAAM,OAC7B,SAAUA,IACZE,EAAI,KAAOF,EAAE,MAEX,SAAUA,IACZE,EAAI,KAAOF,EAAE,OAIXE,CACR,CAlCgBC,EAAAJ,EAAA",
6
+ "names": ["AccountId", "isValidCaipAddress", "address", "AccountId", "__name", "parseErrorAndThrowStandardizeError", "e", "errorMessage", "err", "__name"]
7
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@hub3js/std/hooks",
3
+ "type": "module",
4
+ "main": "../dist/hooks/mod.js",
5
+ "module": "../dist/hooks/mod.js",
6
+ "types": "../dist/hooks/mod.d.ts",
7
+ "sideEffects": false
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@hub3js/std/operators",
3
+ "type": "module",
4
+ "main": "../dist/operators/mod.js",
5
+ "module": "../dist/operators/mod.js",
6
+ "types": "../dist/operators/mod.d.ts",
7
+ "sideEffects": false
8
+ }
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@hub3js/std",
3
+ "version": "0.0.0-experimental-03bf1f89-20260602",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "exports": {
7
+ "./operators": {
8
+ "types": "./dist/operators/mod.d.ts",
9
+ "default": "./dist/operators/mod.js"
10
+ },
11
+ "./actions": {
12
+ "types": "./dist/actions/mod.d.ts",
13
+ "default": "./dist/actions/mod.js"
14
+ },
15
+ "./builders": {
16
+ "types": "./dist/builders/mod.d.ts",
17
+ "default": "./dist/builders/mod.js"
18
+ },
19
+ "./hooks": {
20
+ "types": "./dist/hooks/mod.d.ts",
21
+ "default": "./dist/hooks/mod.js"
22
+ },
23
+ "./types": {
24
+ "types": "./dist/types/mod.d.ts",
25
+ "default": "./dist/types/mod.js"
26
+ },
27
+ "./utils": {
28
+ "types": "./dist/utils/mod.d.ts",
29
+ "default": "./dist/utils/mod.js"
30
+ }
31
+ },
32
+ "files": [
33
+ "dist",
34
+ "src",
35
+ "operators",
36
+ "actions",
37
+ "builders",
38
+ "hooks",
39
+ "types",
40
+ "utils"
41
+ ],
42
+ "scripts": {
43
+ "build": "yarn run rangutopia library build --inputs src/operators/mod.ts,src/actions/mod.ts,src/builders/mod.ts,src/hooks/mod.ts,src/types/mod.ts,src/utils/mod.ts",
44
+ "ts-check": "tsc --declaration --emitDeclarationOnly -p tsconfig.json",
45
+ "clean": "rimraf dist",
46
+ "format": "prettier --write '{.,src}/**/*.{ts,tsx}'",
47
+ "lint": "eslint \"**/*.{ts,tsx}\"",
48
+ "test": "vitest run",
49
+ "test:watch": "vitest",
50
+ "coverage": "vitest run --coverage"
51
+ },
52
+ "peerDependencies": {
53
+ "@hub3js/core": "*"
54
+ },
55
+ "dependencies": {
56
+ "caip": "^1.1.1"
57
+ },
58
+ "publishConfig": {
59
+ "access": "public"
60
+ }
61
+ }
package/readme.md ADDED
@@ -0,0 +1,15 @@
1
+ # @hub3js/std
2
+
3
+ Shared standard layer for `@hub3js` namespace packages. Provides operator
4
+ primitives, shared action implementations, builders, hooks, and types that
5
+ chain-specific namespace packages (`@hub3js/evm`, `@hub3js/solana`, …) build on
6
+ top of.
7
+
8
+ Exposed via subpaths:
9
+
10
+ - `@hub3js/std/operators` — `before` / `after` / `and` / `or` recommended hooks
11
+ - `@hub3js/std/actions` — shared action implementations (e.g. `disconnect`)
12
+ - `@hub3js/std/builders` — pre-wired `ActionBuilder` factories
13
+ - `@hub3js/std/hooks` — reusable subscriber builders (e.g. `ChangeAccountSubscriberBuilder`)
14
+ - `@hub3js/std/types` — foundational types (`Namespace`, CAIP accounts, common actions)
15
+ - `@hub3js/std/utils` — CAIP validation, error standardization
@@ -0,0 +1,16 @@
1
+ import type { Context } from '@hub3js/core';
2
+
3
+ export function disconnect(context: Context): void {
4
+ const [, setState] = context.state();
5
+ setState('network', null);
6
+ setState('accounts', null);
7
+ setState('connected', false);
8
+ setState('connecting', false);
9
+ setState('connectArgs', null);
10
+ }
11
+
12
+ /**
13
+ * Recommended action defaults every namespace should wire up. Tuple shape
14
+ * matches what `NamespaceBuilder.action(...)` accepts as a list.
15
+ */
16
+ export const recommended = [['disconnect', disconnect] as const];
@@ -0,0 +1 @@
1
+ export { disconnect, recommended as recommendedActions } from './disconnect.js';
@@ -0,0 +1,19 @@
1
+ import type { AutoImplementedActionsByRecommended } from '../types/namespace.js';
2
+ import type { Actions } from '@hub3js/core';
3
+
4
+ import { ActionBuilder } from '@hub3js/core';
5
+
6
+ import { disconnect as disconnectAction } from '../actions/disconnect.js';
7
+
8
+ /**
9
+ * Pre-wired `ActionBuilder` for the canonical `disconnect` action. The wallet
10
+ * package's own action type `T` must include a `disconnect` member compatible
11
+ * with `AutoImplementedActionsByRecommended['disconnect']`.
12
+ */
13
+ export const disconnect = <
14
+ T extends Actions<T> &
15
+ Record<'disconnect', AutoImplementedActionsByRecommended['disconnect']>,
16
+ >() =>
17
+ new ActionBuilder<AutoImplementedActionsByRecommended, 'disconnect'>(
18
+ 'disconnect',
19
+ ).action(disconnectAction) as unknown as ActionBuilder<T, 'disconnect'>;
@@ -0,0 +1 @@
1
+ export { disconnect } from './disconnect.js';