promise-tuple 1.1.4 → 1.2.0

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 +1 @@
1
- {"version":3,"sources":["../index.ts"],"sourcesContent":["/**\n * Handles a promise and returns a tuple with error and result.\n *\n * This function wraps a promise and returns a tuple containing either an error or a result,\n * similar to Go's error handling pattern. If the promise resolves, the tuple will contain\n * `[undefined, result]`. If the promise rejects, the tuple will contain `[error, undefined]`.\n *\n * @template R - The type of the resolved value. Defaults to `unknown`.\n * @template E - The type of the error. Defaults to `unknown`.\n * @param promise - The promise to handle.\n * @param successCallback - Optional callback to execute when the promise resolves successfully.\n * @param failureCallback - Optional callback to execute when the promise rejects.\n * @returns A promise that resolves to a tuple containing either an error or a result.\n * On success: `[undefined, result]`\n * On failure: `[error, undefined]`\n *\n * @example\n * const [error, data] = await promiseTuple(fetchData());\n * if (error) {\n * console.error('Error:', error);\n * } else {\n * console.log('Data:', data);\n * }\n *\n * @example\n * const [error, data] = await promiseTuple(\n * fetchData(),\n * () => console.log('Success!'),\n * () => console.log('Failed!')\n * );\n */\nexport async function promiseTuple<R = unknown, E = unknown>(\n promise: Promise<R>,\n successCallback?: () => void,\n failureCallback?: () => void,\n): Promise<[E, undefined] | [undefined, R]> {\n return promise\n .then(\n (result) => (\n successCallback?.(),\n [undefined, result] as [undefined, R]\n ),\n )\n .catch(\n (error) => (\n failureCallback?.(),\n [error, undefined] as [E, undefined]\n ),\n );\n}\n\nexport default promiseTuple;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+BA,eAAsB,aAClB,SACA,iBACA,iBACwC;AACxC,SAAO,QACF;AAAA,IACG,CAAC,YACG,kBAAkB,GAClB,CAAC,QAAW,MAAM;AAAA,EAE1B,EACC;AAAA,IACG,CAAC,WACG,kBAAkB,GAClB,CAAC,OAAO,MAAS;AAAA,EAEzB;AACR;AAEA,IAAO,gBAAQ;","names":[]}
1
+ {"version":3,"sources":["../index.ts"],"sourcesContent":["/**\n * Handles a promise and returns a tuple with error and result.\n *\n * This function wraps a promise and returns a tuple containing either an error or a result,\n * similar to Go's error handling pattern. If the promise resolves, the tuple will contain\n * `[undefined, result]`. If the promise rejects, the tuple will contain `[error, undefined]`.\n *\n * @template R - The type of the resolved value. Defaults to `unknown`.\n * @template E - The type of the error. Defaults to `unknown`.\n * @param promise - The promise to handle.\n * @param successCallback - Optional callback to execute when the promise resolves successfully.\n * @param failureCallback - Optional callback to execute when the promise rejects.\n * @returns A promise that resolves to a tuple containing either an error or a result.\n * On success: `[undefined, result]`\n * On failure: `[error, undefined]`\n *\n * @example\n * const [error, data] = await promiseTuple(fetchData());\n * if (error) {\n * console.error('Error:', error);\n * } else {\n * console.log('Data:', data);\n * }\n *\n * @example\n * const [error, data] = await promiseTuple(\n * fetchData(),\n * () => console.log('Success!'),\n * () => console.log('Failed!')\n * );\n */\nexport async function promiseTuple<R = unknown, E = unknown>(\n promise: Promise<R>,\n successCallback?: () => void,\n failureCallback?: () => void,\n): Promise<[E & {}, undefined] | [undefined, R]> {\n return promise\n .then(\n (result) => (\n successCallback?.(),\n [undefined, result] as [undefined, R]\n ),\n )\n .catch(\n (error) => (\n failureCallback?.(),\n [error, undefined] as [E & {}, undefined]\n ),\n );\n}\n\nexport default promiseTuple;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+BA,eAAsB,aAClB,SACA,iBACA,iBAC6C;AAC7C,SAAO,QACF;AAAA,IACG,CAAC,YACG,kBAAkB,GAClB,CAAC,QAAW,MAAM;AAAA,EAE1B,EACC;AAAA,IACG,CAAC,WACG,kBAAkB,GAClB,CAAC,OAAO,MAAS;AAAA,EAEzB;AACR;AAEA,IAAO,gBAAQ;","names":[]}
package/dist/index.d.cts CHANGED
@@ -29,6 +29,6 @@
29
29
  * () => console.log('Failed!')
30
30
  * );
31
31
  */
32
- declare function promiseTuple<R = unknown, E = unknown>(promise: Promise<R>, successCallback?: () => void, failureCallback?: () => void): Promise<[E, undefined] | [undefined, R]>;
32
+ declare function promiseTuple<R = unknown, E = unknown>(promise: Promise<R>, successCallback?: () => void, failureCallback?: () => void): Promise<[E & {}, undefined] | [undefined, R]>;
33
33
 
34
34
  export { promiseTuple as default, promiseTuple };
package/dist/index.d.ts CHANGED
@@ -29,6 +29,6 @@
29
29
  * () => console.log('Failed!')
30
30
  * );
31
31
  */
32
- declare function promiseTuple<R = unknown, E = unknown>(promise: Promise<R>, successCallback?: () => void, failureCallback?: () => void): Promise<[E, undefined] | [undefined, R]>;
32
+ declare function promiseTuple<R = unknown, E = unknown>(promise: Promise<R>, successCallback?: () => void, failureCallback?: () => void): Promise<[E & {}, undefined] | [undefined, R]>;
33
33
 
34
34
  export { promiseTuple as default, promiseTuple };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts"],"sourcesContent":["/**\n * Handles a promise and returns a tuple with error and result.\n *\n * This function wraps a promise and returns a tuple containing either an error or a result,\n * similar to Go's error handling pattern. If the promise resolves, the tuple will contain\n * `[undefined, result]`. If the promise rejects, the tuple will contain `[error, undefined]`.\n *\n * @template R - The type of the resolved value. Defaults to `unknown`.\n * @template E - The type of the error. Defaults to `unknown`.\n * @param promise - The promise to handle.\n * @param successCallback - Optional callback to execute when the promise resolves successfully.\n * @param failureCallback - Optional callback to execute when the promise rejects.\n * @returns A promise that resolves to a tuple containing either an error or a result.\n * On success: `[undefined, result]`\n * On failure: `[error, undefined]`\n *\n * @example\n * const [error, data] = await promiseTuple(fetchData());\n * if (error) {\n * console.error('Error:', error);\n * } else {\n * console.log('Data:', data);\n * }\n *\n * @example\n * const [error, data] = await promiseTuple(\n * fetchData(),\n * () => console.log('Success!'),\n * () => console.log('Failed!')\n * );\n */\nexport async function promiseTuple<R = unknown, E = unknown>(\n promise: Promise<R>,\n successCallback?: () => void,\n failureCallback?: () => void,\n): Promise<[E, undefined] | [undefined, R]> {\n return promise\n .then(\n (result) => (\n successCallback?.(),\n [undefined, result] as [undefined, R]\n ),\n )\n .catch(\n (error) => (\n failureCallback?.(),\n [error, undefined] as [E, undefined]\n ),\n );\n}\n\nexport default promiseTuple;\n"],"mappings":";AA+BA,eAAsB,aAClB,SACA,iBACA,iBACwC;AACxC,SAAO,QACF;AAAA,IACG,CAAC,YACG,kBAAkB,GAClB,CAAC,QAAW,MAAM;AAAA,EAE1B,EACC;AAAA,IACG,CAAC,WACG,kBAAkB,GAClB,CAAC,OAAO,MAAS;AAAA,EAEzB;AACR;AAEA,IAAO,gBAAQ;","names":[]}
1
+ {"version":3,"sources":["../index.ts"],"sourcesContent":["/**\n * Handles a promise and returns a tuple with error and result.\n *\n * This function wraps a promise and returns a tuple containing either an error or a result,\n * similar to Go's error handling pattern. If the promise resolves, the tuple will contain\n * `[undefined, result]`. If the promise rejects, the tuple will contain `[error, undefined]`.\n *\n * @template R - The type of the resolved value. Defaults to `unknown`.\n * @template E - The type of the error. Defaults to `unknown`.\n * @param promise - The promise to handle.\n * @param successCallback - Optional callback to execute when the promise resolves successfully.\n * @param failureCallback - Optional callback to execute when the promise rejects.\n * @returns A promise that resolves to a tuple containing either an error or a result.\n * On success: `[undefined, result]`\n * On failure: `[error, undefined]`\n *\n * @example\n * const [error, data] = await promiseTuple(fetchData());\n * if (error) {\n * console.error('Error:', error);\n * } else {\n * console.log('Data:', data);\n * }\n *\n * @example\n * const [error, data] = await promiseTuple(\n * fetchData(),\n * () => console.log('Success!'),\n * () => console.log('Failed!')\n * );\n */\nexport async function promiseTuple<R = unknown, E = unknown>(\n promise: Promise<R>,\n successCallback?: () => void,\n failureCallback?: () => void,\n): Promise<[E & {}, undefined] | [undefined, R]> {\n return promise\n .then(\n (result) => (\n successCallback?.(),\n [undefined, result] as [undefined, R]\n ),\n )\n .catch(\n (error) => (\n failureCallback?.(),\n [error, undefined] as [E & {}, undefined]\n ),\n );\n}\n\nexport default promiseTuple;\n"],"mappings":";AA+BA,eAAsB,aAClB,SACA,iBACA,iBAC6C;AAC7C,SAAO,QACF;AAAA,IACG,CAAC,YACG,kBAAkB,GAClB,CAAC,QAAW,MAAM;AAAA,EAE1B,EACC;AAAA,IACG,CAAC,WACG,kBAAkB,GAClB,CAAC,OAAO,MAAS;AAAA,EAEzB;AACR;AAEA,IAAO,gBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "promise-tuple",
3
- "version": "1.1.4",
3
+ "version": "1.2.0",
4
4
  "description": "A utility function for handling promises with Go-like error handling pattern",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",