Skip to content

Commit 0a99da4

Browse files
committed
chore: add deprecation warnings
1 parent 386a5c0 commit 0a99da4

File tree

18 files changed

+145
-20
lines changed

18 files changed

+145
-20
lines changed

.changeset/small-sites-begin.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"near-api-js": patch
3+
"@near-js/accounts": patch
4+
"@near-js/types": patch
5+
"@near-js/utils": patch
6+
---
7+
8+
Add deprecation annotations and warnings to functions/classes that will be removed in the next major release

packages/accounts/src/account.ts

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import { viewFunction, viewState } from "./utils";
5050

5151
import type { FungibleToken, NativeToken } from "@near-js/tokens";
5252
import { NEAR } from "@near-js/tokens";
53+
import depd from "depd";
5354

5455
const {
5556
addKey,
@@ -772,7 +773,7 @@ export class Account {
772773
// DEPRECATED FUNCTIONS BELLOW - Please remove in next release
773774

774775
/**
775-
* @deprecated please use {@link Account.createSignedMetaTransaction} instead
776+
* @deprecated Will be removed in the next major release, please use {@link Account.createSignedMetaTransaction} instead
776777
*
777778
* Compose and sign a SignedDelegate action to be executed in a transaction on behalf of this Account instance
778779
*
@@ -786,6 +787,9 @@ export class Account {
786787
blockHeightTtl,
787788
receiverId,
788789
}: SignedDelegateOptions): Promise<SignedDelegate> {
790+
const deprecate = depd('Account.signedDelegate()');
791+
deprecate('It will be removed in the next major release, please switch to Account.createSignedMetaTransaction()');
792+
789793
const { header } = await this.provider.viewBlock({
790794
finality: DEFAULT_FINALITY,
791795
});
@@ -813,7 +817,7 @@ export class Account {
813817
}
814818

815819
/**
816-
* @deprecated, accounts no longer use Connections since it's deprecated too
820+
* @deprecated Will be removed in the next major release, accounts no longer use Connections since it's deprecated too
817821
*/
818822
public getConnection(): Connection {
819823
return new Connection("", this.provider, this.signer);
@@ -833,7 +837,7 @@ export class Account {
833837
}
834838

835839
/**
836-
* @deprecated please use {@link callFunction} instead
840+
* @deprecated Will be removed in the next major release, please use {@link Account.callFunction} instead
837841
*
838842
* Execute a function call.
839843
* @param options The options for the function call.
@@ -857,6 +861,9 @@ export class Account {
857861
walletCallbackUrl,
858862
stringify,
859863
}: ChangeFunctionCallOptions): Promise<FinalExecutionOutcome> {
864+
const deprecate = depd('Account.functionCall()');
865+
deprecate('It will be removed in the next major release, please switch to Account.callFunction()');
866+
860867
this.validateArgs(args);
861868

862869
const stringifyArg =
@@ -880,11 +887,14 @@ export class Account {
880887
}
881888

882889
/**
883-
* @deprecated use instead {@link Provider.viewTransactionStatus}
890+
* @deprecated Will be removed in the next major release, use instead {@link Provider.viewTransactionStatus}
884891
*/
885892
public async getTransactionStatus(
886893
txHash: string | Uint8Array
887894
): Promise<FinalExecutionOutcome> {
895+
const deprecate = depd('Account.getTransactionStatus()');
896+
deprecate('It will be removed in the next major release, please switch to Provider.viewTransactionStatus()');
897+
888898
return this.provider.viewTransactionStatus(
889899
txHash,
890900
this.accountId, // accountId is used to determine on which shard to look for a tx
@@ -893,7 +903,7 @@ export class Account {
893903
}
894904

895905
/**
896-
* @deprecated use ${@link createSignedTransaction}
906+
* @deprecated Will be removed in the next major release, use ${@link Account.createSignedTransaction}
897907
* Create a signed transaction which can be broadcast to the network
898908
* @param receiverId NEAR account receiving the transaction
899909
* @param actions list of actions to perform as part of the transaction
@@ -904,6 +914,9 @@ export class Account {
904914
actions: Action[],
905915
opts?: { signer: Signer }
906916
): Promise<[Uint8Array, SignedTransaction]> {
917+
const deprecate = depd('Account.signTransaction()');
918+
deprecate('It will be removed in the next major release, please switch to Account.createSignedTransaction()');
919+
907920
const signer = opts?.signer || this.signer;
908921

909922
if (!signer) throw new Error(`Please set a signer`);
@@ -932,7 +945,8 @@ export class Account {
932945
}
933946

934947
/**
935-
* @deprecated instead please create a transaction with
948+
* @deprecated Will be removed in the next major release,
949+
* instead please create a transaction with
936950
* the actions bellow and broadcast it to the network
937951
* 1. createAccount
938952
* 2. transfer some tokens
@@ -952,6 +966,9 @@ export class Account {
952966
data: Uint8Array,
953967
amount: bigint
954968
): Promise<Account> {
969+
const deprecate = depd('Account.createAndDeployContract()');
970+
deprecate('It will be removed in the next major release');
971+
955972
const accessKey = fullAccessKey();
956973
await this.signAndSendTransactionLegacy({
957974
receiverId: contractId,
@@ -966,7 +983,7 @@ export class Account {
966983
}
967984

968985
/**
969-
* @deprecated please instead use {@link transfer}
986+
* @deprecated Will be removed in the next major release, please instead use {@link Account.transfer}
970987
*
971988
* @param receiverId NEAR account receiving Ⓝ
972989
* @param amount Amount to send in yoctoⓃ
@@ -975,14 +992,17 @@ export class Account {
975992
receiverId: string,
976993
amount: bigint
977994
): Promise<FinalExecutionOutcome> {
995+
const deprecate = depd('Account.sendMoney()');
996+
deprecate('It will be removed in the next major release, please switch to Account.transfer()');
997+
978998
return this.signAndSendTransactionLegacy({
979999
receiverId,
9801000
actions: [transfer(amount)],
9811001
});
9821002
}
9831003

9841004
/**
985-
* @deprecated please instead use {@link signAndSendTransaction}
1005+
* @deprecated Will be removed in the next major release, please instead use {@link Account.signAndSendTransaction}
9861006
*
9871007
* Sign a transaction to perform a list of actions and broadcast it using the RPC API.
9881008
* @see {@link "@near-js/providers".json-rpc-provider.JsonRpcProvider | JsonRpcProvider }
@@ -998,6 +1018,9 @@ export class Account {
9981018
{ receiverId, actions, returnError }: SignAndSendTransactionOptions,
9991019
opts?: { signer: Signer }
10001020
): Promise<FinalExecutionOutcome> {
1021+
const deprecate = depd('Account.signAndSendTransactionLegacy()');
1022+
deprecate('It will be removed in the next major release, please switch to Account.signAndSendTransaction()');
1023+
10011024
let txHash, signedTx;
10021025

10031026
// Default number of retries with different nonce before giving up on a transaction.
@@ -1087,7 +1110,7 @@ export class Account {
10871110
accessKeyByPublicKeyCache: { [key: string]: AccessKeyView } = {};
10881111

10891112
/**
1090-
* @deprecated, accounts will no longer handle keystores
1113+
* @deprecated Will be removed in the next major release, accounts will no longer handle keystores
10911114
*
10921115
* Finds the {@link AccessKeyView} associated with the accounts {@link PublicKey} stored in the {@link "@near-js/keystores".keystore.KeyStore | Keystore}.
10931116
*
@@ -1100,6 +1123,9 @@ export class Account {
11001123
receiverId: string,
11011124
actions: Action[]
11021125
): Promise<{ publicKey: PublicKey; accessKey: AccessKeyView }> {
1126+
const deprecate = depd('Account.findAccessKey()');
1127+
deprecate('It will be removed in the next major release');
1128+
11031129
if (!this.signer) throw new Error(`Please set a signer`);
11041130

11051131
const publicKey = await this.signer.getPublicKey();
@@ -1153,7 +1179,7 @@ export class Account {
11531179
}
11541180

11551181
/**
1156-
* @deprecated please use {@link addFullAccessKey} or {@link addFunctionAccessKey}
1182+
* @deprecated Will be removed in the next major release, please use {@link Account.addFullAccessKey} or {@link Account.addFunctionAccessKey}
11571183
*
11581184
* @see [https://docs.near.org/concepts/basics/accounts/access-keys](https://docs.near.org/concepts/basics/accounts/access-keys)
11591185
* @todo expand this API to support more options.
@@ -1168,6 +1194,9 @@ export class Account {
11681194
methodNames?: string | string[],
11691195
amount?: bigint
11701196
): Promise<FinalExecutionOutcome> {
1197+
const deprecate = depd('Account.addKey()');
1198+
deprecate('It will be removed in the next major release, please switch to either Account.addFullAccessKey(), or Account.addFunctionAccessKey()');
1199+
11711200
if (!methodNames) {
11721201
methodNames = [];
11731202
}
@@ -1187,7 +1216,7 @@ export class Account {
11871216
}
11881217

11891218
/**
1190-
* @deprecated please use {@link Provider.callFunction} instead
1219+
* @deprecated Will be removed in the next major release, please use {@link Provider.callFunction} instead
11911220
*
11921221
* Invoke a contract view function using the RPC API.
11931222
* @see [https://docs.near.org/api/rpc/contracts#call-a-contract-function](https://docs.near.org/api/rpc/contracts#call-a-contract-function)
@@ -1202,11 +1231,13 @@ export class Account {
12021231
* @returns {Promise<any>}
12031232
*/
12041233
async viewFunction(options: ViewFunctionCallOptions): Promise<any> {
1234+
const deprecate = depd('Account.viewFunction()');
1235+
deprecate('It will be removed in the next major release, please switch to either Provider.callFunction()');
12051236
return await viewFunction(this.getConnection(), options);
12061237
}
12071238

12081239
/**
1209-
* @deprecated please use {@link getContractState} instead
1240+
* @deprecated Will be removed in the next major release, please use {@link Account.getContractState} instead
12101241
*
12111242
* Returns the state (key value pairs) of this account's contract based on the key prefix.
12121243
* Pass an empty string for prefix if you would like to return the entire state.
@@ -1219,6 +1250,9 @@ export class Account {
12191250
prefix: string | Uint8Array,
12201251
blockQuery: BlockReference = { finality: DEFAULT_FINALITY }
12211252
): Promise<Array<{ key: Buffer; value: Buffer }>> {
1253+
const deprecate = depd('Account.viewState()');
1254+
deprecate('It will be removed in the next major release, please switch to either Account.getContractState()');
1255+
12221256
return await viewState(
12231257
this.getConnection(),
12241258
this.accountId,
@@ -1228,13 +1262,16 @@ export class Account {
12281262
}
12291263

12301264
/**
1231-
* @deprecated please use {@link getAccessKeyList} instead
1265+
* @deprecated Will be removed in the next major release, please use {@link Account.getAccessKeyList} instead
12321266
*
12331267
* Get all access keys for the account
12341268
* @see [https://docs.near.org/api/rpc/access-keys#view-access-key-list](https://docs.near.org/api/rpc/access-keys#view-access-key-list)
12351269
*
12361270
*/
12371271
async getAccessKeys(): Promise<AccessKeyInfoView[]> {
1272+
const deprecate = depd('Account.getAccessKeys()');
1273+
deprecate('It will be removed in the next major release, please switch to either Account.getAccessKeyList()');
1274+
12381275
const response = await this.provider.query<AccessKeyList>({
12391276
request_type: "view_access_key_list",
12401277
account_id: this.accountId,
@@ -1279,12 +1316,15 @@ export class Account {
12791316
}
12801317

12811318
/**
1282-
* @deprecated please use {@link getState} instead
1319+
* @deprecated Will be removed in the next major release, please use {@link Account.getState} instead
12831320
*
12841321
* Returns basic NEAR account information via the `view_account` RPC query method
12851322
* @see [https://docs.near.org/api/rpc/contracts#view-account](https://docs.near.org/api/rpc/contracts#view-account)
12861323
*/
12871324
async state(): Promise<AccountView> {
1325+
const deprecate = depd('Account.state()');
1326+
deprecate('It will be removed in the next major release, please switch to either Account.getState()');
1327+
12881328
return this.provider.query<AccountView>({
12891329
request_type: "view_account",
12901330
account_id: this.accountId,
@@ -1293,10 +1333,13 @@ export class Account {
12931333
}
12941334

12951335
/**
1296-
* @deprecated please use {@link getState} instead
1336+
* @deprecated Will be removed in the next major release, please use {@link Account.getState} instead
12971337
*
12981338
*/
12991339
async getAccountBalance(): Promise<AccountBalance> {
1340+
const deprecate = depd('Account.getAccountBalance()');
1341+
deprecate('It will be removed in the next major release, please switch to either Account.getState()');
1342+
13001343
const protocolConfig = await this.provider.experimental_protocolConfig({
13011344
finality: DEFAULT_FINALITY,
13021345
});
@@ -1322,12 +1365,15 @@ export class Account {
13221365
/**
13231366
* Returns the NEAR tokens balance and validators of a given account that is delegated to the staking pools that are part of the validators set in the current epoch.
13241367
*
1325-
* @deprecated
1368+
* @deprecated Will be removed in the next major release
13261369
*
13271370
* NOTE: If the tokens are delegated to a staking pool that is currently on pause or does not have enough tokens to participate in validation, they won't be accounted for.
13281371
* @returns {Promise<ActiveDelegatedStakeBalance>}
13291372
*/
13301373
async getActiveDelegatedStakeBalance(): Promise<ActiveDelegatedStakeBalance> {
1374+
const deprecate = depd('Account.getActiveDelegatedStakeBalance()');
1375+
deprecate('It will be removed in the next major release');
1376+
13311377
const block = await this.provider.block({
13321378
finality: DEFAULT_FINALITY,
13331379
});

packages/accounts/src/account_creator.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,23 @@ import { PublicKey } from '@near-js/crypto';
22

33
import { Connection } from './connection';
44
import { Account } from './account';
5+
import depd from 'depd';
56

67
/**
8+
* @deprecated Will be removed in the next major release
9+
*
710
* Account creator provides an interface for implementations to actually create accounts
811
*/
912
export abstract class AccountCreator {
13+
constructor() {
14+
const deprecate = depd('AccountCreator');
15+
deprecate(`${this.constructor.name} is deprecated and will be removed in the next major release`);
16+
}
17+
1018
abstract createAccount(newAccountId: string, publicKey: PublicKey): Promise<void>;
1119
}
1220

21+
/** @deprecated Will be removed in the next major release */
1322
export class LocalAccountCreator extends AccountCreator {
1423
readonly masterAccount: Account;
1524
readonly initialBalance: bigint;
@@ -31,6 +40,7 @@ export class LocalAccountCreator extends AccountCreator {
3140
}
3241
}
3342

43+
/** @deprecated Will be removed in the next major release */
3444
export class UrlAccountCreator extends AccountCreator {
3545
readonly connection: Connection;
3646
readonly helperUrl: string;

packages/accounts/src/connection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function getSigner(config: any): Signer {
4545
}
4646

4747
/**
48-
* @deprecated
48+
* @deprecated Will be removed in the next major release
4949
*
5050
* Connects an account to a given network via a given provider
5151
*/

packages/accounts/src/constants.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { parseNearAmount } from '@near-js/utils';
2-
2+
/** @deprecated Will be removed in the next major release */
33
export const MULTISIG_STORAGE_KEY = '__multisigRequest';
4+
/** @deprecated Will be removed in the next major release */
45
export const MULTISIG_ALLOWANCE = BigInt(parseNearAmount('1'));
56
// TODO: Different gas value for different requests (can reduce gas usage dramatically)
7+
/** @deprecated Will be removed in the next major release */
68
export const MULTISIG_GAS = 100000000000000n;
9+
/** @deprecated Will be removed in the next major release */
710
export const MULTISIG_DEPOSIT = 0n;
11+
/** @deprecated Will be removed in the next major release */
812
export const MULTISIG_CHANGE_METHODS = ['add_request', 'add_request_and_confirm', 'delete_request', 'confirm'];
13+
/** @deprecated Will be removed in the next major release */
914
export const MULTISIG_CONFIRM_METHODS = ['confirm'];

packages/accounts/src/interface.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export interface IntoConnection {
66
}
77

88
/**
9+
* @deprecated Will be removed in the next major release
10+
*
911
* Options used to initiate a function call (especially a change function call)
1012
* @see {@link Account#viewFunction | viewFunction} to initiate a view function call
1113
*/
@@ -28,6 +30,7 @@ export interface FunctionCallOptions {
2830
stringify?: (input: any) => Buffer;
2931
}
3032

33+
/** @deprecated Will be removed in the next major release */
3134
export interface ChangeFunctionCallOptions extends FunctionCallOptions {
3235
/**
3336
* Metadata to send the NEAR Wallet if using it to sign transactions.
@@ -40,6 +43,8 @@ export interface ChangeFunctionCallOptions extends FunctionCallOptions {
4043
*/
4144
walletCallbackUrl?: string;
4245
}
46+
47+
/** @deprecated Will be removed in the next major release */
4348
export interface ViewFunctionCallOptions extends FunctionCallOptions {
4449
parse?: (response: Uint8Array) => any;
4550
blockQuery?: BlockReference;

0 commit comments

Comments
 (0)