@solana/promises 2.0.0-canary-20240807165603

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.
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2023 Solana Labs, Inc
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ [![npm][npm-image]][npm-url]
2
+ [![npm-downloads][npm-downloads-image]][npm-url]
3
+ [![semantic-release][semantic-release-image]][semantic-release-url]
4
+ <br />
5
+ [![code-style-prettier][code-style-prettier-image]][code-style-prettier-url]
6
+
7
+ [code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
8
+ [code-style-prettier-url]: https://github.com/prettier/prettier
9
+ [npm-downloads-image]: https://img.shields.io/npm/dm/@solana/promises/rc.svg?style=flat
10
+ [npm-image]: https://img.shields.io/npm/v/@solana/promises/rc.svg?style=flat
11
+ [npm-url]: https://www.npmjs.com/package/@solana/promises/v/rc
12
+ [semantic-release-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
13
+ [semantic-release-url]: https://github.com/semantic-release/semantic-release
14
+
15
+ # @solana/promises
16
+
17
+ This package contains helpers for using JavaScript promises.
18
+
19
+ ## Functions
20
+
21
+ ### `getAbortablePromise(promise, abortSignal?)`
22
+
23
+ Rejects if the `abortSignal` is aborted before the promise settles. Resolves or rejects with the value of the promise otherwise.
24
+
25
+ ```ts
26
+ const result = await getAbortablePromise(
27
+ // Resolves or rejects when `fetch` settles.
28
+ fetch('https://example.com/json').then(r => r.json()),
29
+ // ...unless it takes longer than 5 seconds, after which the `AbortSignal` is triggered.
30
+ AbortSignal.timeout(5000),
31
+ );
32
+ ```
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ // src/abortable.ts
4
+ function getAbortablePromise(promise, abortSignal) {
5
+ if (!abortSignal) {
6
+ return promise;
7
+ } else {
8
+ return Promise.race([
9
+ // This promise only ever rejects if the signal is aborted. Otherwise it idles forever.
10
+ // It's important that this come before the input promise; in the event of an abort, we
11
+ // want to throw even if the input promise's result is ready
12
+ new Promise((_, reject) => {
13
+ if (abortSignal.aborted) {
14
+ reject(abortSignal.reason);
15
+ } else {
16
+ abortSignal.addEventListener("abort", function() {
17
+ reject(this.reason);
18
+ });
19
+ }
20
+ }),
21
+ promise
22
+ ]);
23
+ }
24
+ }
25
+
26
+ exports.getAbortablePromise = getAbortablePromise;
27
+ //# sourceMappingURL=index.browser.cjs.map
28
+ //# sourceMappingURL=index.browser.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/abortable.ts"],"names":[],"mappings":";;;AAAO,SAAS,mBAAA,CAAuB,SAAqB,WAAuC,EAAA;AAC/F,EAAA,IAAI,CAAC,WAAa,EAAA;AACd,IAAO,OAAA,OAAA,CAAA;AAAA,GACJ,MAAA;AACH,IAAA,OAAO,QAAQ,IAAK,CAAA;AAAA;AAAA;AAAA;AAAA,MAIhB,IAAI,OAAA,CAAe,CAAC,CAAA,EAAG,MAAW,KAAA;AAC9B,QAAA,IAAI,YAAY,OAAS,EAAA;AACrB,UAAA,MAAA,CAAO,YAAY,MAAM,CAAA,CAAA;AAAA,SACtB,MAAA;AACH,UAAY,WAAA,CAAA,gBAAA,CAAiB,SAAS,WAAY;AAC9C,YAAA,MAAA,CAAO,KAAK,MAAM,CAAA,CAAA;AAAA,WACrB,CAAA,CAAA;AAAA,SACL;AAAA,OACH,CAAA;AAAA,MACD,OAAA;AAAA,KACH,CAAA,CAAA;AAAA,GACL;AACJ","file":"index.browser.cjs","sourcesContent":["export function getAbortablePromise<T>(promise: Promise<T>, abortSignal?: AbortSignal): Promise<T> {\n if (!abortSignal) {\n return promise;\n } else {\n return Promise.race([\n // This promise only ever rejects if the signal is aborted. Otherwise it idles forever.\n // It's important that this come before the input promise; in the event of an abort, we\n // want to throw even if the input promise's result is ready\n new Promise<never>((_, reject) => {\n if (abortSignal.aborted) {\n reject(abortSignal.reason);\n } else {\n abortSignal.addEventListener('abort', function () {\n reject(this.reason);\n });\n }\n }),\n promise,\n ]);\n }\n}\n"]}
@@ -0,0 +1,26 @@
1
+ // src/abortable.ts
2
+ function getAbortablePromise(promise, abortSignal) {
3
+ if (!abortSignal) {
4
+ return promise;
5
+ } else {
6
+ return Promise.race([
7
+ // This promise only ever rejects if the signal is aborted. Otherwise it idles forever.
8
+ // It's important that this come before the input promise; in the event of an abort, we
9
+ // want to throw even if the input promise's result is ready
10
+ new Promise((_, reject) => {
11
+ if (abortSignal.aborted) {
12
+ reject(abortSignal.reason);
13
+ } else {
14
+ abortSignal.addEventListener("abort", function() {
15
+ reject(this.reason);
16
+ });
17
+ }
18
+ }),
19
+ promise
20
+ ]);
21
+ }
22
+ }
23
+
24
+ export { getAbortablePromise };
25
+ //# sourceMappingURL=index.browser.mjs.map
26
+ //# sourceMappingURL=index.browser.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/abortable.ts"],"names":[],"mappings":";AAAO,SAAS,mBAAA,CAAuB,SAAqB,WAAuC,EAAA;AAC/F,EAAA,IAAI,CAAC,WAAa,EAAA;AACd,IAAO,OAAA,OAAA,CAAA;AAAA,GACJ,MAAA;AACH,IAAA,OAAO,QAAQ,IAAK,CAAA;AAAA;AAAA;AAAA;AAAA,MAIhB,IAAI,OAAA,CAAe,CAAC,CAAA,EAAG,MAAW,KAAA;AAC9B,QAAA,IAAI,YAAY,OAAS,EAAA;AACrB,UAAA,MAAA,CAAO,YAAY,MAAM,CAAA,CAAA;AAAA,SACtB,MAAA;AACH,UAAY,WAAA,CAAA,gBAAA,CAAiB,SAAS,WAAY;AAC9C,YAAA,MAAA,CAAO,KAAK,MAAM,CAAA,CAAA;AAAA,WACrB,CAAA,CAAA;AAAA,SACL;AAAA,OACH,CAAA;AAAA,MACD,OAAA;AAAA,KACH,CAAA,CAAA;AAAA,GACL;AACJ","file":"index.browser.mjs","sourcesContent":["export function getAbortablePromise<T>(promise: Promise<T>, abortSignal?: AbortSignal): Promise<T> {\n if (!abortSignal) {\n return promise;\n } else {\n return Promise.race([\n // This promise only ever rejects if the signal is aborted. Otherwise it idles forever.\n // It's important that this come before the input promise; in the event of an abort, we\n // want to throw even if the input promise's result is ready\n new Promise<never>((_, reject) => {\n if (abortSignal.aborted) {\n reject(abortSignal.reason);\n } else {\n abortSignal.addEventListener('abort', function () {\n reject(this.reason);\n });\n }\n }),\n promise,\n ]);\n }\n}\n"]}
@@ -0,0 +1,26 @@
1
+ // src/abortable.ts
2
+ function getAbortablePromise(promise, abortSignal) {
3
+ if (!abortSignal) {
4
+ return promise;
5
+ } else {
6
+ return Promise.race([
7
+ // This promise only ever rejects if the signal is aborted. Otherwise it idles forever.
8
+ // It's important that this come before the input promise; in the event of an abort, we
9
+ // want to throw even if the input promise's result is ready
10
+ new Promise((_, reject) => {
11
+ if (abortSignal.aborted) {
12
+ reject(abortSignal.reason);
13
+ } else {
14
+ abortSignal.addEventListener("abort", function() {
15
+ reject(this.reason);
16
+ });
17
+ }
18
+ }),
19
+ promise
20
+ ]);
21
+ }
22
+ }
23
+
24
+ export { getAbortablePromise };
25
+ //# sourceMappingURL=index.native.mjs.map
26
+ //# sourceMappingURL=index.native.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/abortable.ts"],"names":[],"mappings":";AAAO,SAAS,mBAAA,CAAuB,SAAqB,WAAuC,EAAA;AAC/F,EAAA,IAAI,CAAC,WAAa,EAAA;AACd,IAAO,OAAA,OAAA,CAAA;AAAA,GACJ,MAAA;AACH,IAAA,OAAO,QAAQ,IAAK,CAAA;AAAA;AAAA;AAAA;AAAA,MAIhB,IAAI,OAAA,CAAe,CAAC,CAAA,EAAG,MAAW,KAAA;AAC9B,QAAA,IAAI,YAAY,OAAS,EAAA;AACrB,UAAA,MAAA,CAAO,YAAY,MAAM,CAAA,CAAA;AAAA,SACtB,MAAA;AACH,UAAY,WAAA,CAAA,gBAAA,CAAiB,SAAS,WAAY;AAC9C,YAAA,MAAA,CAAO,KAAK,MAAM,CAAA,CAAA;AAAA,WACrB,CAAA,CAAA;AAAA,SACL;AAAA,OACH,CAAA;AAAA,MACD,OAAA;AAAA,KACH,CAAA,CAAA;AAAA,GACL;AACJ","file":"index.native.mjs","sourcesContent":["export function getAbortablePromise<T>(promise: Promise<T>, abortSignal?: AbortSignal): Promise<T> {\n if (!abortSignal) {\n return promise;\n } else {\n return Promise.race([\n // This promise only ever rejects if the signal is aborted. Otherwise it idles forever.\n // It's important that this come before the input promise; in the event of an abort, we\n // want to throw even if the input promise's result is ready\n new Promise<never>((_, reject) => {\n if (abortSignal.aborted) {\n reject(abortSignal.reason);\n } else {\n abortSignal.addEventListener('abort', function () {\n reject(this.reason);\n });\n }\n }),\n promise,\n ]);\n }\n}\n"]}
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ // src/abortable.ts
4
+ function getAbortablePromise(promise, abortSignal) {
5
+ if (!abortSignal) {
6
+ return promise;
7
+ } else {
8
+ return Promise.race([
9
+ // This promise only ever rejects if the signal is aborted. Otherwise it idles forever.
10
+ // It's important that this come before the input promise; in the event of an abort, we
11
+ // want to throw even if the input promise's result is ready
12
+ new Promise((_, reject) => {
13
+ if (abortSignal.aborted) {
14
+ reject(abortSignal.reason);
15
+ } else {
16
+ abortSignal.addEventListener("abort", function() {
17
+ reject(this.reason);
18
+ });
19
+ }
20
+ }),
21
+ promise
22
+ ]);
23
+ }
24
+ }
25
+
26
+ exports.getAbortablePromise = getAbortablePromise;
27
+ //# sourceMappingURL=index.node.cjs.map
28
+ //# sourceMappingURL=index.node.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/abortable.ts"],"names":[],"mappings":";;;AAAO,SAAS,mBAAA,CAAuB,SAAqB,WAAuC,EAAA;AAC/F,EAAA,IAAI,CAAC,WAAa,EAAA;AACd,IAAO,OAAA,OAAA,CAAA;AAAA,GACJ,MAAA;AACH,IAAA,OAAO,QAAQ,IAAK,CAAA;AAAA;AAAA;AAAA;AAAA,MAIhB,IAAI,OAAA,CAAe,CAAC,CAAA,EAAG,MAAW,KAAA;AAC9B,QAAA,IAAI,YAAY,OAAS,EAAA;AACrB,UAAA,MAAA,CAAO,YAAY,MAAM,CAAA,CAAA;AAAA,SACtB,MAAA;AACH,UAAY,WAAA,CAAA,gBAAA,CAAiB,SAAS,WAAY;AAC9C,YAAA,MAAA,CAAO,KAAK,MAAM,CAAA,CAAA;AAAA,WACrB,CAAA,CAAA;AAAA,SACL;AAAA,OACH,CAAA;AAAA,MACD,OAAA;AAAA,KACH,CAAA,CAAA;AAAA,GACL;AACJ","file":"index.node.cjs","sourcesContent":["export function getAbortablePromise<T>(promise: Promise<T>, abortSignal?: AbortSignal): Promise<T> {\n if (!abortSignal) {\n return promise;\n } else {\n return Promise.race([\n // This promise only ever rejects if the signal is aborted. Otherwise it idles forever.\n // It's important that this come before the input promise; in the event of an abort, we\n // want to throw even if the input promise's result is ready\n new Promise<never>((_, reject) => {\n if (abortSignal.aborted) {\n reject(abortSignal.reason);\n } else {\n abortSignal.addEventListener('abort', function () {\n reject(this.reason);\n });\n }\n }),\n promise,\n ]);\n }\n}\n"]}
@@ -0,0 +1,26 @@
1
+ // src/abortable.ts
2
+ function getAbortablePromise(promise, abortSignal) {
3
+ if (!abortSignal) {
4
+ return promise;
5
+ } else {
6
+ return Promise.race([
7
+ // This promise only ever rejects if the signal is aborted. Otherwise it idles forever.
8
+ // It's important that this come before the input promise; in the event of an abort, we
9
+ // want to throw even if the input promise's result is ready
10
+ new Promise((_, reject) => {
11
+ if (abortSignal.aborted) {
12
+ reject(abortSignal.reason);
13
+ } else {
14
+ abortSignal.addEventListener("abort", function() {
15
+ reject(this.reason);
16
+ });
17
+ }
18
+ }),
19
+ promise
20
+ ]);
21
+ }
22
+ }
23
+
24
+ export { getAbortablePromise };
25
+ //# sourceMappingURL=index.node.mjs.map
26
+ //# sourceMappingURL=index.node.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/abortable.ts"],"names":[],"mappings":";AAAO,SAAS,mBAAA,CAAuB,SAAqB,WAAuC,EAAA;AAC/F,EAAA,IAAI,CAAC,WAAa,EAAA;AACd,IAAO,OAAA,OAAA,CAAA;AAAA,GACJ,MAAA;AACH,IAAA,OAAO,QAAQ,IAAK,CAAA;AAAA;AAAA;AAAA;AAAA,MAIhB,IAAI,OAAA,CAAe,CAAC,CAAA,EAAG,MAAW,KAAA;AAC9B,QAAA,IAAI,YAAY,OAAS,EAAA;AACrB,UAAA,MAAA,CAAO,YAAY,MAAM,CAAA,CAAA;AAAA,SACtB,MAAA;AACH,UAAY,WAAA,CAAA,gBAAA,CAAiB,SAAS,WAAY;AAC9C,YAAA,MAAA,CAAO,KAAK,MAAM,CAAA,CAAA;AAAA,WACrB,CAAA,CAAA;AAAA,SACL;AAAA,OACH,CAAA;AAAA,MACD,OAAA;AAAA,KACH,CAAA,CAAA;AAAA,GACL;AACJ","file":"index.node.mjs","sourcesContent":["export function getAbortablePromise<T>(promise: Promise<T>, abortSignal?: AbortSignal): Promise<T> {\n if (!abortSignal) {\n return promise;\n } else {\n return Promise.race([\n // This promise only ever rejects if the signal is aborted. Otherwise it idles forever.\n // It's important that this come before the input promise; in the event of an abort, we\n // want to throw even if the input promise's result is ready\n new Promise<never>((_, reject) => {\n if (abortSignal.aborted) {\n reject(abortSignal.reason);\n } else {\n abortSignal.addEventListener('abort', function () {\n reject(this.reason);\n });\n }\n }),\n promise,\n ]);\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export declare function getAbortablePromise<T>(promise: Promise<T>, abortSignal?: AbortSignal): Promise<T>;
2
+ //# sourceMappingURL=abortable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abortable.d.ts","sourceRoot":"","sources":["../../src/abortable.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAoBjG"}
@@ -0,0 +1,2 @@
1
+ export * from './abortable';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "@solana/promises",
3
+ "version": "2.0.0-canary-20240807165603",
4
+ "description": "Helpers for using JavaScript promises",
5
+ "exports": {
6
+ "browser": {
7
+ "import": "./dist/index.browser.mjs",
8
+ "require": "./dist/index.browser.cjs"
9
+ },
10
+ "node": {
11
+ "import": "./dist/index.node.mjs",
12
+ "require": "./dist/index.node.cjs"
13
+ },
14
+ "react-native": "./dist/index.native.mjs",
15
+ "types": "./dist/types/index.d.ts"
16
+ },
17
+ "browser": {
18
+ "./dist/index.node.cjs": "./dist/index.browser.cjs",
19
+ "./dist/index.node.mjs": "./dist/index.browser.mjs"
20
+ },
21
+ "main": "./dist/index.node.cjs",
22
+ "module": "./dist/index.node.mjs",
23
+ "react-native": "./dist/index.native.mjs",
24
+ "types": "./dist/types/index.d.ts",
25
+ "type": "commonjs",
26
+ "files": [
27
+ "./dist/"
28
+ ],
29
+ "sideEffects": false,
30
+ "keywords": [
31
+ "blockchain",
32
+ "solana",
33
+ "web3"
34
+ ],
35
+ "author": "Solana Labs Maintainers <maintainers@solanalabs.com>",
36
+ "license": "MIT",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/solana-labs/solana-web3.js"
40
+ },
41
+ "bugs": {
42
+ "url": "http://github.com/solana-labs/solana-web3.js/issues"
43
+ },
44
+ "browserslist": [
45
+ "supports bigint and not dead",
46
+ "maintained node versions"
47
+ ],
48
+ "peerDependencies": {
49
+ "typescript": ">=5"
50
+ },
51
+ "bundlewatch": {
52
+ "defaultCompression": "gzip",
53
+ "files": [
54
+ {
55
+ "path": "./dist/index*.js"
56
+ }
57
+ ]
58
+ },
59
+ "scripts": {
60
+ "compile:js": "tsup --config build-scripts/tsup.config.package.ts",
61
+ "compile:typedefs": "tsc -p ./tsconfig.declarations.json",
62
+ "dev": "jest -c ../../node_modules/@solana/test-config/jest-dev.config.ts --rootDir . --watch",
63
+ "publish-impl": "npm view $npm_package_name@$npm_package_version > /dev/null 2>&1 || pnpm publish --tag ${PUBLISH_TAG:-canary} --access public --no-git-checks",
64
+ "publish-packages": "pnpm prepublishOnly && pnpm publish-impl",
65
+ "style:fix": "pnpm eslint --fix src/* && pnpm prettier --log-level warn --ignore-unknown --write ./*",
66
+ "test:lint": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-lint.config.ts --rootDir . --silent",
67
+ "test:prettier": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-prettier.config.ts --rootDir . --silent",
68
+ "test:treeshakability:browser": "agadoo dist/index.browser.mjs",
69
+ "test:treeshakability:native": "agadoo dist/index.native.mjs",
70
+ "test:treeshakability:node": "agadoo dist/index.node.mjs",
71
+ "test:typecheck": "tsc --noEmit",
72
+ "test:unit:browser": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-unit.config.browser.ts --rootDir . --silent",
73
+ "test:unit:node": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-unit.config.node.ts --rootDir . --silent"
74
+ }
75
+ }