Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Created @solana/promises and moved getAbortablePromise into it
Browse files Browse the repository at this point in the history
  • Loading branch information
steveluscher committed Aug 7, 2024
1 parent 6c4e3ba commit e327607
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/sweet-cobras-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@solana/promises': patch
---

Created a package for dealing with JavaScript Promises, and copied the implementation of `getAbortablePromise` into it
1 change: 1 addition & 0 deletions packages/promises/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
1 change: 1 addition & 0 deletions packages/promises/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
1 change: 1 addition & 0 deletions packages/promises/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @solana/promises
20 changes: 20 additions & 0 deletions packages/promises/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2023 Solana Labs, Inc

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 changes: 32 additions & 0 deletions packages/promises/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[![npm][npm-image]][npm-url]
[![npm-downloads][npm-downloads-image]][npm-url]
[![semantic-release][semantic-release-image]][semantic-release-url]
<br />
[![code-style-prettier][code-style-prettier-image]][code-style-prettier-url]

[code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
[code-style-prettier-url]: https://github.com/prettier/prettier
[npm-downloads-image]: https://img.shields.io/npm/dm/@solana/promises/rc.svg?style=flat
[npm-image]: https://img.shields.io/npm/v/@solana/promises/rc.svg?style=flat
[npm-url]: https://www.npmjs.com/package/@solana/promises/v/rc
[semantic-release-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
[semantic-release-url]: https://github.com/semantic-release/semantic-release

# @solana/promises

This package contains helpers for using JavaScript promises.

## Functions

### `getAbortablePromise(promise, abortSignal?)`

Rejects if the `abortSignal` is aborted before the promise settles. Resolves or rejects with the value of the promise otherwise.

```ts
const result = await getAbortablePromise(
// Resolves or rejects when `fetch` settles.
fetch('https://example.com/json').then(r => r.json()),
// ...unless it takes longer than 5 seconds, after which the `AbortSignal` is triggered.
AbortSignal.timeout(5000),
);
```
76 changes: 76 additions & 0 deletions packages/promises/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "@solana/promises",
"version": "2.0.0-rc.0",
"description": "Helpers for using JavaScript promises",
"exports": {
"browser": {
"import": "./dist/index.browser.mjs",
"require": "./dist/index.browser.cjs"
},
"node": {
"import": "./dist/index.node.mjs",
"require": "./dist/index.node.cjs"
},
"react-native": "./dist/index.native.mjs",
"types": "./dist/types/index.d.ts"
},
"browser": {
"./dist/index.node.cjs": "./dist/index.browser.cjs",
"./dist/index.node.mjs": "./dist/index.browser.mjs"
},
"main": "./dist/index.node.cjs",
"module": "./dist/index.node.mjs",
"react-native": "./dist/index.native.mjs",
"types": "./dist/types/index.d.ts",
"type": "commonjs",
"files": [
"./dist/"
],
"sideEffects": false,
"keywords": [
"blockchain",
"solana",
"web3"
],
"scripts": {
"compile:js": "tsup --config build-scripts/tsup.config.package.ts",
"compile:typedefs": "tsc -p ./tsconfig.declarations.json",
"dev": "jest -c ../../node_modules/@solana/test-config/jest-dev.config.ts --rootDir . --watch",
"prepublishOnly": "pnpm pkg delete devDependencies",
"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",
"publish-packages": "pnpm prepublishOnly && pnpm publish-impl",
"style:fix": "pnpm eslint --fix src/* && pnpm prettier --log-level warn --ignore-unknown --write ./*",
"test:lint": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-lint.config.ts --rootDir . --silent",
"test:prettier": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-prettier.config.ts --rootDir . --silent",
"test:treeshakability:browser": "agadoo dist/index.browser.mjs",
"test:treeshakability:native": "agadoo dist/index.native.mjs",
"test:treeshakability:node": "agadoo dist/index.node.mjs",
"test:typecheck": "tsc --noEmit",
"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",
"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"
},
"author": "Solana Labs Maintainers <[email protected]>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/solana-labs/solana-web3.js"
},
"bugs": {
"url": "http://github.com/solana-labs/solana-web3.js/issues"
},
"browserslist": [
"supports bigint and not dead",
"maintained node versions"
],
"peerDependencies": {
"typescript": ">=5"
},
"bundlewatch": {
"defaultCompression": "gzip",
"files": [
{
"path": "./dist/index*.js"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getAbortablePromise } from '../abortable-promise';
import { getAbortablePromise } from '../abortable';

describe('getAbortablePromise()', () => {
let promise: Promise<unknown>;
Expand Down
1 change: 1 addition & 0 deletions packages/promises/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './abortable';
10 changes: 10 additions & 0 deletions packages/promises/tsconfig.declarations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "./dist/types"
},
"extends": "./tsconfig.json",
"include": ["src/index.ts", "src/types"]
}
9 changes: 9 additions & 0 deletions packages/promises/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"lib": ["DOM", "ES2015"]
},
"display": "@solana/promises",
"extends": "../tsconfig/base.json",
"include": ["src"]
}
1 change: 1 addition & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"@solana/addresses": "workspace:*",
"@solana/errors": "workspace:*",
"@solana/keys": "workspace:*",
"@solana/promises": "workspace:*",
"@solana/signers": "workspace:*",
"@solana/transactions": "workspace:*",
"@solana/wallet-standard-features": "^1.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/useWalletAccountMessageSigner.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Address, address } from '@solana/addresses';
import { SOLANA_ERROR__SIGNER__WALLET_MULTISIGN_UNIMPLEMENTED, SolanaError } from '@solana/errors';
import { SignatureBytes } from '@solana/keys';
import { getAbortablePromise } from '@solana/promises';
import { MessageModifyingSigner, SignableMessage } from '@solana/signers';
import type { UiWalletAccount } from '@wallet-standard/ui';
import { useMemo } from 'react';

import { getAbortablePromise } from './abortable-promise';
import { useSignMessage } from './useSignMessage';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { address } from '@solana/addresses';
import { SOLANA_ERROR__SIGNER__WALLET_MULTISIGN_UNIMPLEMENTED, SolanaError } from '@solana/errors';
import { SignatureBytes } from '@solana/keys';
import { getAbortablePromise } from '@solana/promises';
import { TransactionSendingSigner } from '@solana/signers';
import { getTransactionEncoder } from '@solana/transactions';
import { UiWalletAccount } from '@wallet-standard/ui';
import { useMemo, useRef } from 'react';

import { getAbortablePromise } from './abortable-promise';
import { OnlySolanaChains } from './chain';
import { useSignAndSendTransaction } from './useSignAndSendTransaction';

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/useWalletAccountTransactionSigner.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { address } from '@solana/addresses';
import { SOLANA_ERROR__SIGNER__WALLET_MULTISIGN_UNIMPLEMENTED, SolanaError } from '@solana/errors';
import { getAbortablePromise } from '@solana/promises';
import { TransactionModifyingSigner } from '@solana/signers';
import { getTransactionCodec } from '@solana/transactions';
import { UiWalletAccount } from '@wallet-standard/ui';
import { useMemo, useRef } from 'react';

import { getAbortablePromise } from './abortable-promise';
import { OnlySolanaChains } from './chain';
import { useSignTransaction } from './useSignTransaction';

Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e327607

Please sign in to comment.