@hub3js/std 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- var a=Object.defineProperty;var o=(e,t)=>a(e,"name",{value:t,configurable:!0});function c(e){let[,t]=e.state();t("connecting",!0)}o(c,"intoConnecting");var u=[["connect",c]];function s(e){let[,t]=e.state();t("connecting",!1)}o(s,"intoConnectionFinished");var m=[["connect",s]];import{AccountId as p}from"caip";function n(e){try{return p.parse(e),!0}catch{return!1}}o(n,"isValidCaipAddress");function f(e,t){if(!t.every(n))throw new Error(`Your provider should format account addresses in CAIP-10 format. Your provided accounts: ${t}`);let[,r]=e.state();return r("accounts",t),r("connected",!0),t}o(f,"connectAndUpdateStateForSingleNetwork");function h(e,t){if(!t.accounts.every(n))throw new Error(`Your provider should format account addresses in CAIP-10 format. Your provided accounts: ${t.accounts}`);let[,r]=e.state();return r("accounts",t.accounts),r("network",t.network),r("connected",!0),t}o(h,"connectAndUpdateStateForMultiNetworks");var x=[];var d={4001:"User rejected the request.",4100:"The requested method and/or account has not been authorized by the user.",4200:"The Provider does not support the requested method.",4900:"The Provider is disconnected from all chains.",4901:"The Provider is not connected to the requested chain."};function i(e){if(e instanceof Error)throw e;let t;typeof e=="object"&&e!==null&&"message"in e&&typeof e.message=="string"?t=e.message:typeof e=="object"&&e!==null&&"code"in e&&d[Number(e.code)]?t=d[Number(e.code)]:typeof e=="string"?t=e:t=String(e);let r=new Error(t);throw typeof e=="object"&&e!==null&&("code"in e&&(r.code=e.code),"data"in e&&(r.data=e.data)),r}o(i,"parseErrorAndThrowStandardizeError");function l(e,t){i(t)}o(l,"standardizeAndThrowError");export{m as afterRecommended,x as andRecommended,u as beforeRecommended,h as connectAndUpdateStateForMultiNetworks,f as connectAndUpdateStateForSingleNetwork,c as intoConnecting,s as intoConnectionFinished,l as standardizeAndThrowError};
1
+ var a=Object.defineProperty;var o=(e,t)=>a(e,"name",{value:t,configurable:!0});function c(e){let[,t]=e.state();t("connecting",!0)}o(c,"intoConnecting");var u=[["connect",c]];function s(e){let[,t]=e.state();t("connecting",!1)}o(s,"intoConnectionFinished");var m=[["connect",s]];import{AccountId as p}from"caip";function n(e){try{return p.parse(e),!0}catch{return!1}}o(n,"isValidCaipAddress");function f(e,t){if(!t.every(n))throw new Error(`Your provider should format account addresses in CAIP-10 format. Your provided accounts: ${t}`);let[,r]=e.state();return r("accounts",t),r("connected",!0),t}o(f,"connectAndUpdateStateForSingleNetwork");function h(e,t){if(!t.accounts.every(n))throw new Error(`Your provider should format account addresses in CAIP-10 format. Your provided accounts: ${t.accounts}`);let[,r]=e.state();return r("accounts",t.accounts),r("network",t.network),r("connected",!0),t}o(h,"connectAndUpdateStateForMultiNetworks");var l=[];var d={4001:"User rejected the request.",4100:"The requested method and/or account has not been authorized by the user.",4200:"The Provider does not support the requested method.",4900:"The Provider is disconnected from all chains.",4901:"The Provider is not connected to the requested chain."};function i(e){if(e instanceof Error)throw e;let t;typeof e=="object"&&e!==null&&"message"in e&&typeof e.message=="string"&&e.message.length>0?t=e.message:typeof e=="object"&&e!==null&&"code"in e&&d[Number(e.code)]?t=d[Number(e.code)]:typeof e=="string"?t=e:t=String(e);let r=new Error(t);throw typeof e=="object"&&e!==null&&("code"in e&&(r.code=e.code),"data"in e&&(r.data=e.data)),r}o(i,"parseErrorAndThrowStandardizeError");function x(e,t){i(t)}o(x,"standardizeAndThrowError");export{m as afterRecommended,l as andRecommended,u as beforeRecommended,h as connectAndUpdateStateForMultiNetworks,f as connectAndUpdateStateForSingleNetwork,c as intoConnecting,s as intoConnectionFinished,x as standardizeAndThrowError};
2
2
  //# sourceMappingURL=mod.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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", "const EIP_1193_ERROR_CODE_TO_MESSAGE: Record<number, string> = {\n [4001]: 'User rejected the request.',\n [4100]:\n 'The requested method and/or account has not been authorized by the user.',\n [4200]: 'The Provider does not support the requested method.',\n [4900]: 'The Provider is disconnected from all chains.',\n [4901]: 'The Provider is not connected to the requested chain.',\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 (\n typeof e === 'object' &&\n e !== null &&\n 'code' in e &&\n EIP_1193_ERROR_CODE_TO_MESSAGE[Number(e.code)]\n ) {\n errorMessage = EIP_1193_ERROR_CODE_TO_MESSAGE[Number(e.code)];\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,ECtC5B,IAAMC,EAAyD,CAC5D,KAAO,6BACP,KACC,2EACD,KAAO,sDACP,KAAO,gDACP,KAAO,uDACV,EAWO,SAASC,EAAmC,EAAmB,CACpE,GAAI,aAAa,MACf,MAAM,EAGR,IAAIC,EAEF,OAAO,GAAM,UACb,IAAM,MACN,YAAa,GACb,OAAO,EAAE,SAAY,SAErBA,EAAe,EAAE,QAEjB,OAAO,GAAM,UACb,IAAM,MACN,SAAU,GACVF,EAA+B,OAAO,EAAE,IAAI,CAAC,EAE7CE,EAAeF,EAA+B,OAAO,EAAE,IAAI,CAAC,EACnD,OAAO,GAAM,SACtBE,EAAe,EAEfA,EAAe,OAAO,CAAC,EAGzB,IAAMC,EAAM,IAAI,MAAMD,CAAY,EAKlC,MAAI,OAAO,GAAM,UAAY,IAAM,OAC7B,SAAU,IACZC,EAAI,KAAO,EAAE,MAEX,SAAU,IACZA,EAAI,KAAO,EAAE,OAIXA,CACR,CAzCgBC,EAAAH,EAAA,sCCFT,SAASI,EAAyBC,EAAmBC,EAAmB,CAC7EC,EAAmCD,CAAC,CACtC,CAFgBE,EAAAJ,EAAA",
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", "const EIP_1193_ERROR_CODE_TO_MESSAGE: Record<number, string> = {\n [4001]: 'User rejected the request.',\n [4100]:\n 'The requested method and/or account has not been authorized by the user.',\n [4200]: 'The Provider does not support the requested method.',\n [4900]: 'The Provider is disconnected from all chains.',\n [4901]: 'The Provider is not connected to the requested chain.',\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 e.message.length > 0\n ) {\n errorMessage = e.message;\n } else if (\n typeof e === 'object' &&\n e !== null &&\n 'code' in e &&\n EIP_1193_ERROR_CODE_TO_MESSAGE[Number(e.code)]\n ) {\n errorMessage = EIP_1193_ERROR_CODE_TO_MESSAGE[Number(e.code)];\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,ECtC5B,IAAMC,EAAyD,CAC5D,KAAO,6BACP,KACC,2EACD,KAAO,sDACP,KAAO,gDACP,KAAO,uDACV,EAWO,SAASC,EAAmC,EAAmB,CACpE,GAAI,aAAa,MACf,MAAM,EAGR,IAAIC,EAEF,OAAO,GAAM,UACb,IAAM,MACN,YAAa,GACb,OAAO,EAAE,SAAY,UACrB,EAAE,QAAQ,OAAS,EAEnBA,EAAe,EAAE,QAEjB,OAAO,GAAM,UACb,IAAM,MACN,SAAU,GACVF,EAA+B,OAAO,EAAE,IAAI,CAAC,EAE7CE,EAAeF,EAA+B,OAAO,EAAE,IAAI,CAAC,EACnD,OAAO,GAAM,SACtBE,EAAe,EAEfA,EAAe,OAAO,CAAC,EAGzB,IAAMC,EAAM,IAAI,MAAMD,CAAY,EAKlC,MAAI,OAAO,GAAM,UAAY,IAAM,OAC7B,SAAU,IACZC,EAAI,KAAO,EAAE,MAEX,SAAU,IACZA,EAAI,KAAO,EAAE,OAIXA,CACR,CA1CgBC,EAAAH,EAAA,sCCFT,SAASI,EAAyBC,EAAmBC,EAAmB,CAC7EC,EAAmCD,CAAC,CACtC,CAFgBE,EAAAJ,EAAA",
6
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", "EIP_1193_ERROR_CODE_TO_MESSAGE", "parseErrorAndThrowStandardizeError", "errorMessage", "err", "__name", "standardizeAndThrowError", "_context", "e", "parseErrorAndThrowStandardizeError", "__name"]
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/utils/error.ts"],"names":[],"mappings":"AASA;;;;;;;;GAQG;AACH,wBAAgB,kCAAkC,CAAC,CAAC,EAAE,OAAO,GAAG,KAAK,CAyCpE"}
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/utils/error.ts"],"names":[],"mappings":"AASA;;;;;;;;GAQG;AACH,wBAAgB,kCAAkC,CAAC,CAAC,EAAE,OAAO,GAAG,KAAK,CA0CpE"}
package/dist/utils/mod.js CHANGED
@@ -1,2 +1,2 @@
1
- var s=Object.defineProperty;var o=(r,e)=>s(r,"name",{value:e,configurable:!0});import{AccountId as d}from"caip";function i(r){try{return d.parse(r),!0}catch{return!1}}o(i,"isValidCaipAddress");var n={4001:"User rejected the request.",4100:"The requested method and/or account has not been authorized by the user.",4200:"The Provider does not support the requested method.",4900:"The Provider is disconnected from all chains.",4901:"The Provider is not connected to the requested chain."};function a(r){if(r instanceof Error)throw r;let e;typeof r=="object"&&r!==null&&"message"in r&&typeof r.message=="string"?e=r.message:typeof r=="object"&&r!==null&&"code"in r&&n[Number(r.code)]?e=n[Number(r.code)]:typeof r=="string"?e=r:e=String(r);let t=new Error(e);throw typeof r=="object"&&r!==null&&("code"in r&&(t.code=r.code),"data"in r&&(t.data=r.data)),t}o(a,"parseErrorAndThrowStandardizeError");export{i as isValidCaipAddress,a as parseErrorAndThrowStandardizeError};
1
+ var s=Object.defineProperty;var o=(r,e)=>s(r,"name",{value:e,configurable:!0});import{AccountId as d}from"caip";function i(r){try{return d.parse(r),!0}catch{return!1}}o(i,"isValidCaipAddress");var n={4001:"User rejected the request.",4100:"The requested method and/or account has not been authorized by the user.",4200:"The Provider does not support the requested method.",4900:"The Provider is disconnected from all chains.",4901:"The Provider is not connected to the requested chain."};function a(r){if(r instanceof Error)throw r;let e;typeof r=="object"&&r!==null&&"message"in r&&typeof r.message=="string"&&r.message.length>0?e=r.message:typeof r=="object"&&r!==null&&"code"in r&&n[Number(r.code)]?e=n[Number(r.code)]:typeof r=="string"?e=r:e=String(r);let t=new Error(e);throw typeof r=="object"&&r!==null&&("code"in r&&(t.code=r.code),"data"in r&&(t.data=r.data)),t}o(a,"parseErrorAndThrowStandardizeError");export{i as isValidCaipAddress,a as parseErrorAndThrowStandardizeError};
2
2
  //# sourceMappingURL=mod.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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", "const EIP_1193_ERROR_CODE_TO_MESSAGE: Record<number, string> = {\n [4001]: 'User rejected the request.',\n [4100]:\n 'The requested method and/or account has not been authorized by the user.',\n [4200]: 'The Provider does not support the requested method.',\n [4900]: 'The Provider is disconnected from all chains.',\n [4901]: 'The Provider is not connected to the requested chain.',\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 (\n typeof e === 'object' &&\n e !== null &&\n 'code' in e &&\n EIP_1193_ERROR_CODE_TO_MESSAGE[Number(e.code)]\n ) {\n errorMessage = EIP_1193_ERROR_CODE_TO_MESSAGE[Number(e.code)];\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,sBCFhB,IAAMI,EAAyD,CAC5D,KAAO,6BACP,KACC,2EACD,KAAO,sDACP,KAAO,gDACP,KAAO,uDACV,EAWO,SAASC,EAAmCC,EAAmB,CACpE,GAAIA,aAAa,MACf,MAAMA,EAGR,IAAIC,EAEF,OAAOD,GAAM,UACbA,IAAM,MACN,YAAaA,GACb,OAAOA,EAAE,SAAY,SAErBC,EAAeD,EAAE,QAEjB,OAAOA,GAAM,UACbA,IAAM,MACN,SAAUA,GACVF,EAA+B,OAAOE,EAAE,IAAI,CAAC,EAE7CC,EAAeH,EAA+B,OAAOE,EAAE,IAAI,CAAC,EACnD,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,CAzCgBC,EAAAJ,EAAA",
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", "const EIP_1193_ERROR_CODE_TO_MESSAGE: Record<number, string> = {\n [4001]: 'User rejected the request.',\n [4100]:\n 'The requested method and/or account has not been authorized by the user.',\n [4200]: 'The Provider does not support the requested method.',\n [4900]: 'The Provider is disconnected from all chains.',\n [4901]: 'The Provider is not connected to the requested chain.',\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 e.message.length > 0\n ) {\n errorMessage = e.message;\n } else if (\n typeof e === 'object' &&\n e !== null &&\n 'code' in e &&\n EIP_1193_ERROR_CODE_TO_MESSAGE[Number(e.code)]\n ) {\n errorMessage = EIP_1193_ERROR_CODE_TO_MESSAGE[Number(e.code)];\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,sBCFhB,IAAMI,EAAyD,CAC5D,KAAO,6BACP,KACC,2EACD,KAAO,sDACP,KAAO,gDACP,KAAO,uDACV,EAWO,SAASC,EAAmCC,EAAmB,CACpE,GAAIA,aAAa,MACf,MAAMA,EAGR,IAAIC,EAEF,OAAOD,GAAM,UACbA,IAAM,MACN,YAAaA,GACb,OAAOA,EAAE,SAAY,UACrBA,EAAE,QAAQ,OAAS,EAEnBC,EAAeD,EAAE,QAEjB,OAAOA,GAAM,UACbA,IAAM,MACN,SAAUA,GACVF,EAA+B,OAAOE,EAAE,IAAI,CAAC,EAE7CC,EAAeH,EAA+B,OAAOE,EAAE,IAAI,CAAC,EACnD,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,CA1CgBC,EAAAJ,EAAA",
6
6
  "names": ["AccountId", "isValidCaipAddress", "address", "AccountId", "__name", "EIP_1193_ERROR_CODE_TO_MESSAGE", "parseErrorAndThrowStandardizeError", "e", "errorMessage", "err", "__name"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hub3js/std",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -26,7 +26,8 @@ export function parseErrorAndThrowStandardizeError(e: unknown): never {
26
26
  typeof e === 'object' &&
27
27
  e !== null &&
28
28
  'message' in e &&
29
- typeof e.message === 'string'
29
+ typeof e.message === 'string' &&
30
+ e.message.length > 0
30
31
  ) {
31
32
  errorMessage = e.message;
32
33
  } else if (