@coinbase/cdp-sdk 0.0.0 → 1.0.1
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/README.md +165 -0
- package/dist/accounts/evm/toEvmServerAccount.d.ts +19 -0
- package/dist/accounts/evm/toEvmServerAccount.js +42 -0
- package/dist/accounts/evm/toEvmSmartAccount.d.ts +24 -0
- package/dist/accounts/evm/toEvmSmartAccount.js +24 -0
- package/dist/accounts/types.d.ts +45 -0
- package/dist/accounts/types.js +2 -0
- package/dist/actions/evm/sendUserOperation.d.ts +95 -0
- package/dist/actions/evm/sendUserOperation.js +87 -0
- package/dist/actions/evm/waitForUserOperation.d.ts +63 -0
- package/dist/actions/evm/waitForUserOperation.js +60 -0
- package/dist/analytics.d.ts +30 -0
- package/dist/analytics.js +89 -0
- package/dist/auth/errors.d.ts +45 -0
- package/dist/auth/errors.js +62 -0
- package/dist/auth/hooks/axios/index.d.ts +1 -0
- package/dist/auth/hooks/axios/index.js +17 -0
- package/dist/auth/hooks/axios/withAuth.d.ts +37 -0
- package/dist/auth/hooks/axios/withAuth.js +73 -0
- package/dist/auth/index.d.ts +4 -0
- package/dist/auth/index.js +43 -0
- package/dist/auth/utils/http.d.ts +60 -0
- package/dist/auth/utils/http.js +72 -0
- package/dist/auth/utils/index.d.ts +2 -0
- package/dist/auth/utils/index.js +18 -0
- package/dist/auth/utils/jwt.d.ts +88 -0
- package/dist/auth/utils/jwt.js +235 -0
- package/dist/client/cdp.d.ts +43 -0
- package/dist/client/cdp.js +40 -0
- package/dist/client/evm/evm.d.ts +387 -0
- package/dist/client/evm/evm.js +520 -0
- package/dist/client/evm/evm.types.d.ts +254 -0
- package/dist/client/evm/evm.types.js +2 -0
- package/dist/client/evm/index.d.ts +1 -0
- package/dist/client/evm/index.js +5 -0
- package/dist/client/solana/index.d.ts +1 -0
- package/dist/client/solana/index.js +5 -0
- package/dist/client/solana/solana.d.ts +168 -0
- package/dist/client/solana/solana.js +207 -0
- package/dist/client/solana/solana.types.d.ts +94 -0
- package/dist/client/solana/solana.types.js +2 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +7 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.js +21 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +6 -0
- package/dist/openapi-client/cdpApiClient.d.ts +50 -0
- package/dist/openapi-client/cdpApiClient.js +146 -0
- package/dist/openapi-client/errors.d.ts +53 -0
- package/dist/openapi-client/errors.js +70 -0
- package/dist/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +345 -0
- package/dist/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +54 -0
- package/dist/openapi-client/generated/evm-accounts/evm-accounts.d.ts +62 -0
- package/dist/openapi-client/generated/evm-accounts/evm-accounts.js +85 -0
- package/dist/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts +17 -0
- package/dist/openapi-client/generated/evm-accounts/evm-accounts.msw.js +113 -0
- package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +48 -0
- package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +66 -0
- package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts +15 -0
- package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +99 -0
- package/dist/openapi-client/generated/faucets/faucets.d.ts +48 -0
- package/dist/openapi-client/generated/faucets/faucets.js +51 -0
- package/dist/openapi-client/generated/faucets/faucets.msw.d.ts +7 -0
- package/dist/openapi-client/generated/faucets/faucets.msw.js +43 -0
- package/dist/openapi-client/generated/index.msw.d.ts +4 -0
- package/dist/openapi-client/generated/index.msw.js +20 -0
- package/dist/openapi-client/generated/solana-accounts/solana-accounts.d.ts +61 -0
- package/dist/openapi-client/generated/solana-accounts/solana-accounts.js +79 -0
- package/dist/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts +15 -0
- package/dist/openapi-client/generated/solana-accounts/solana-accounts.msw.js +99 -0
- package/dist/openapi-client/index.d.ts +55 -0
- package/dist/openapi-client/index.js +65 -0
- package/dist/types/calls.d.ts +13 -0
- package/dist/types/calls.js +4 -0
- package/dist/types/contract.d.ts +30 -0
- package/dist/types/contract.js +4 -0
- package/dist/types/misc.d.ts +3 -0
- package/dist/types/misc.js +3 -0
- package/dist/types/multicall.d.ts +9 -0
- package/dist/types/multicall.js +2 -0
- package/dist/types/utils.d.ts +196 -0
- package/dist/types/utils.js +4 -0
- package/dist/utils/wait.d.ts +28 -0
- package/dist/utils/wait.js +34 -0
- package/package.json +72 -5
- package/index.js +0 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.signSolanaMessage = exports.signSolanaTransaction = exports.getSolanaAccountByName = exports.getSolanaAccount = exports.createSolanaAccount = exports.listSolanaAccounts = void 0;
|
|
4
|
+
const cdpApiClient_1 = require("../../cdpApiClient");
|
|
5
|
+
/**
|
|
6
|
+
* Lists the Solana accounts belonging to the developer.
|
|
7
|
+
The response is paginated, and by default, returns 20 accounts per page.
|
|
8
|
+
|
|
9
|
+
If a name is provided, the response will contain only the account with that name.
|
|
10
|
+
* @summary List Solana accounts or get account by name
|
|
11
|
+
*/
|
|
12
|
+
const listSolanaAccounts = (params, options) => {
|
|
13
|
+
return (0, cdpApiClient_1.cdpApiClient)({ url: `/v2/solana/accounts`, method: 'GET',
|
|
14
|
+
params
|
|
15
|
+
}, options);
|
|
16
|
+
};
|
|
17
|
+
exports.listSolanaAccounts = listSolanaAccounts;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new Solana account.
|
|
20
|
+
* @summary Create a Solana account
|
|
21
|
+
*/
|
|
22
|
+
const createSolanaAccount = (createSolanaAccountBody, options) => {
|
|
23
|
+
return (0, cdpApiClient_1.cdpApiClient)({ url: `/v2/solana/accounts`, method: 'POST',
|
|
24
|
+
headers: { 'Content-Type': 'application/json', },
|
|
25
|
+
data: createSolanaAccountBody
|
|
26
|
+
}, options);
|
|
27
|
+
};
|
|
28
|
+
exports.createSolanaAccount = createSolanaAccount;
|
|
29
|
+
/**
|
|
30
|
+
* Gets a Solana account by its address.
|
|
31
|
+
* @summary Get a Solana account by address
|
|
32
|
+
*/
|
|
33
|
+
const getSolanaAccount = (address, options) => {
|
|
34
|
+
return (0, cdpApiClient_1.cdpApiClient)({ url: `/v2/solana/accounts/${address}`, method: 'GET'
|
|
35
|
+
}, options);
|
|
36
|
+
};
|
|
37
|
+
exports.getSolanaAccount = getSolanaAccount;
|
|
38
|
+
/**
|
|
39
|
+
* Gets a Solana account by its name.
|
|
40
|
+
* @summary Get a Solana account by name
|
|
41
|
+
*/
|
|
42
|
+
const getSolanaAccountByName = (name, options) => {
|
|
43
|
+
return (0, cdpApiClient_1.cdpApiClient)({ url: `/v2/solana/accounts/by-name/${name}`, method: 'GET'
|
|
44
|
+
}, options);
|
|
45
|
+
};
|
|
46
|
+
exports.getSolanaAccountByName = getSolanaAccountByName;
|
|
47
|
+
/**
|
|
48
|
+
* Signs a transaction with the given Solana account.
|
|
49
|
+
The unsigned transaction should be serialized into a byte array and then encoded as base64.
|
|
50
|
+
|
|
51
|
+
**Transaction types**
|
|
52
|
+
|
|
53
|
+
The following transaction types are supported:
|
|
54
|
+
* [Legacy transactions](https://solana-labs.github.io/solana-web3.js/classes/Transaction.html)
|
|
55
|
+
* [Versioned transactions](https://solana-labs.github.io/solana-web3.js/classes/VersionedTransaction.html)
|
|
56
|
+
|
|
57
|
+
The developer is responsible for ensuring that the unsigned transaction is valid, as the API will not validate the transaction.
|
|
58
|
+
* @summary Sign a transaction
|
|
59
|
+
*/
|
|
60
|
+
const signSolanaTransaction = (address, signSolanaTransactionBody, options) => {
|
|
61
|
+
return (0, cdpApiClient_1.cdpApiClient)({ url: `/v2/solana/accounts/${address}/sign/transaction`, method: 'POST',
|
|
62
|
+
headers: { 'Content-Type': 'application/json', },
|
|
63
|
+
data: signSolanaTransactionBody
|
|
64
|
+
}, options);
|
|
65
|
+
};
|
|
66
|
+
exports.signSolanaTransaction = signSolanaTransaction;
|
|
67
|
+
/**
|
|
68
|
+
* Signs an arbitrary message with the given Solana account.
|
|
69
|
+
|
|
70
|
+
**WARNING:** Never sign a message that you didn't generate, as it can be an arbitrary transaction. For example, it might send all of your funds to an attacker.
|
|
71
|
+
* @summary Sign a message
|
|
72
|
+
*/
|
|
73
|
+
const signSolanaMessage = (address, signSolanaMessageBody, options) => {
|
|
74
|
+
return (0, cdpApiClient_1.cdpApiClient)({ url: `/v2/solana/accounts/${address}/sign/message`, method: 'POST',
|
|
75
|
+
headers: { 'Content-Type': 'application/json', },
|
|
76
|
+
data: signSolanaMessageBody
|
|
77
|
+
}, options);
|
|
78
|
+
};
|
|
79
|
+
exports.signSolanaMessage = signSolanaMessage;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { http } from 'msw';
|
|
2
|
+
import type { ListSolanaAccounts200, SignSolanaMessage200, SignSolanaTransaction200, SolanaAccount } from '../coinbaseDeveloperPlatformAPIs.schemas';
|
|
3
|
+
export declare const getListSolanaAccountsResponseMock: () => ListSolanaAccounts200;
|
|
4
|
+
export declare const getCreateSolanaAccountResponseMock: (overrideResponse?: Partial<SolanaAccount>) => SolanaAccount;
|
|
5
|
+
export declare const getGetSolanaAccountResponseMock: (overrideResponse?: Partial<SolanaAccount>) => SolanaAccount;
|
|
6
|
+
export declare const getGetSolanaAccountByNameResponseMock: (overrideResponse?: Partial<SolanaAccount>) => SolanaAccount;
|
|
7
|
+
export declare const getSignSolanaTransactionResponseMock: (overrideResponse?: Partial<SignSolanaTransaction200>) => SignSolanaTransaction200;
|
|
8
|
+
export declare const getSignSolanaMessageResponseMock: (overrideResponse?: Partial<SignSolanaMessage200>) => SignSolanaMessage200;
|
|
9
|
+
export declare const getListSolanaAccountsMockHandler: (overrideResponse?: ListSolanaAccounts200 | ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Promise<ListSolanaAccounts200> | ListSolanaAccounts200)) => import("msw").HttpHandler;
|
|
10
|
+
export declare const getCreateSolanaAccountMockHandler: (overrideResponse?: SolanaAccount | ((info: Parameters<Parameters<typeof http.post>[1]>[0]) => Promise<SolanaAccount> | SolanaAccount)) => import("msw").HttpHandler;
|
|
11
|
+
export declare const getGetSolanaAccountMockHandler: (overrideResponse?: SolanaAccount | ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Promise<SolanaAccount> | SolanaAccount)) => import("msw").HttpHandler;
|
|
12
|
+
export declare const getGetSolanaAccountByNameMockHandler: (overrideResponse?: SolanaAccount | ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Promise<SolanaAccount> | SolanaAccount)) => import("msw").HttpHandler;
|
|
13
|
+
export declare const getSignSolanaTransactionMockHandler: (overrideResponse?: SignSolanaTransaction200 | ((info: Parameters<Parameters<typeof http.post>[1]>[0]) => Promise<SignSolanaTransaction200> | SignSolanaTransaction200)) => import("msw").HttpHandler;
|
|
14
|
+
export declare const getSignSolanaMessageMockHandler: (overrideResponse?: SignSolanaMessage200 | ((info: Parameters<Parameters<typeof http.post>[1]>[0]) => Promise<SignSolanaMessage200> | SignSolanaMessage200)) => import("msw").HttpHandler;
|
|
15
|
+
export declare const getSolanaAccountsMock: () => import("msw").HttpHandler[];
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSolanaAccountsMock = exports.getSignSolanaMessageMockHandler = exports.getSignSolanaTransactionMockHandler = exports.getGetSolanaAccountByNameMockHandler = exports.getGetSolanaAccountMockHandler = exports.getCreateSolanaAccountMockHandler = exports.getListSolanaAccountsMockHandler = exports.getSignSolanaMessageResponseMock = exports.getSignSolanaTransactionResponseMock = exports.getGetSolanaAccountByNameResponseMock = exports.getGetSolanaAccountResponseMock = exports.getCreateSolanaAccountResponseMock = exports.getListSolanaAccountsResponseMock = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Generated by orval v7.6.0 🍺
|
|
6
|
+
* Do not edit manually.
|
|
7
|
+
* Coinbase Developer Platform APIs
|
|
8
|
+
* The Coinbase Developer Platform APIs - leading the world's transition onchain.
|
|
9
|
+
* OpenAPI spec version: 2.0.0
|
|
10
|
+
*/
|
|
11
|
+
const faker_1 = require("@faker-js/faker");
|
|
12
|
+
const msw_1 = require("msw");
|
|
13
|
+
const getListSolanaAccountsResponseMock = () => ({ ...{ accounts: Array.from({ length: faker_1.faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ address: faker_1.faker.helpers.fromRegExp('^[1-9A-HJ-NP-Za-km-z]{32,44}$'), name: faker_1.faker.helpers.arrayElement([faker_1.faker.helpers.fromRegExp('^[A-Za-z0-9][A-Za-z0-9-]{0,34}[A-Za-z0-9]$'), undefined]) })) }, ...{ nextPageToken: faker_1.faker.helpers.arrayElement([faker_1.faker.string.alpha(20), undefined]) }, });
|
|
14
|
+
exports.getListSolanaAccountsResponseMock = getListSolanaAccountsResponseMock;
|
|
15
|
+
const getCreateSolanaAccountResponseMock = (overrideResponse = {}) => ({ address: faker_1.faker.helpers.fromRegExp('^[1-9A-HJ-NP-Za-km-z]{32,44}$'), name: faker_1.faker.helpers.arrayElement([faker_1.faker.helpers.fromRegExp('^[A-Za-z0-9][A-Za-z0-9-]{0,34}[A-Za-z0-9]$'), undefined]), ...overrideResponse });
|
|
16
|
+
exports.getCreateSolanaAccountResponseMock = getCreateSolanaAccountResponseMock;
|
|
17
|
+
const getGetSolanaAccountResponseMock = (overrideResponse = {}) => ({ address: faker_1.faker.helpers.fromRegExp('^[1-9A-HJ-NP-Za-km-z]{32,44}$'), name: faker_1.faker.helpers.arrayElement([faker_1.faker.helpers.fromRegExp('^[A-Za-z0-9][A-Za-z0-9-]{0,34}[A-Za-z0-9]$'), undefined]), ...overrideResponse });
|
|
18
|
+
exports.getGetSolanaAccountResponseMock = getGetSolanaAccountResponseMock;
|
|
19
|
+
const getGetSolanaAccountByNameResponseMock = (overrideResponse = {}) => ({ address: faker_1.faker.helpers.fromRegExp('^[1-9A-HJ-NP-Za-km-z]{32,44}$'), name: faker_1.faker.helpers.arrayElement([faker_1.faker.helpers.fromRegExp('^[A-Za-z0-9][A-Za-z0-9-]{0,34}[A-Za-z0-9]$'), undefined]), ...overrideResponse });
|
|
20
|
+
exports.getGetSolanaAccountByNameResponseMock = getGetSolanaAccountByNameResponseMock;
|
|
21
|
+
const getSignSolanaTransactionResponseMock = (overrideResponse = {}) => ({ signedTransaction: faker_1.faker.string.alpha(20), ...overrideResponse });
|
|
22
|
+
exports.getSignSolanaTransactionResponseMock = getSignSolanaTransactionResponseMock;
|
|
23
|
+
const getSignSolanaMessageResponseMock = (overrideResponse = {}) => ({ signature: faker_1.faker.string.alpha(20), ...overrideResponse });
|
|
24
|
+
exports.getSignSolanaMessageResponseMock = getSignSolanaMessageResponseMock;
|
|
25
|
+
const getListSolanaAccountsMockHandler = (overrideResponse) => {
|
|
26
|
+
return msw_1.http.get('*/v2/solana/accounts', async (info) => {
|
|
27
|
+
await (0, msw_1.delay)(0);
|
|
28
|
+
return new msw_1.HttpResponse(JSON.stringify(overrideResponse !== undefined
|
|
29
|
+
? (typeof overrideResponse === "function" ? await overrideResponse(info) : overrideResponse)
|
|
30
|
+
: (0, exports.getListSolanaAccountsResponseMock)()), { status: 200,
|
|
31
|
+
headers: { 'Content-Type': 'application/json' }
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
exports.getListSolanaAccountsMockHandler = getListSolanaAccountsMockHandler;
|
|
36
|
+
const getCreateSolanaAccountMockHandler = (overrideResponse) => {
|
|
37
|
+
return msw_1.http.post('*/v2/solana/accounts', async (info) => {
|
|
38
|
+
await (0, msw_1.delay)(0);
|
|
39
|
+
return new msw_1.HttpResponse(JSON.stringify(overrideResponse !== undefined
|
|
40
|
+
? (typeof overrideResponse === "function" ? await overrideResponse(info) : overrideResponse)
|
|
41
|
+
: (0, exports.getCreateSolanaAccountResponseMock)()), { status: 201,
|
|
42
|
+
headers: { 'Content-Type': 'application/json' }
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
exports.getCreateSolanaAccountMockHandler = getCreateSolanaAccountMockHandler;
|
|
47
|
+
const getGetSolanaAccountMockHandler = (overrideResponse) => {
|
|
48
|
+
return msw_1.http.get('*/v2/solana/accounts/:address', async (info) => {
|
|
49
|
+
await (0, msw_1.delay)(0);
|
|
50
|
+
return new msw_1.HttpResponse(JSON.stringify(overrideResponse !== undefined
|
|
51
|
+
? (typeof overrideResponse === "function" ? await overrideResponse(info) : overrideResponse)
|
|
52
|
+
: (0, exports.getGetSolanaAccountResponseMock)()), { status: 200,
|
|
53
|
+
headers: { 'Content-Type': 'application/json' }
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
exports.getGetSolanaAccountMockHandler = getGetSolanaAccountMockHandler;
|
|
58
|
+
const getGetSolanaAccountByNameMockHandler = (overrideResponse) => {
|
|
59
|
+
return msw_1.http.get('*/v2/solana/accounts/by-name/:name', async (info) => {
|
|
60
|
+
await (0, msw_1.delay)(0);
|
|
61
|
+
return new msw_1.HttpResponse(JSON.stringify(overrideResponse !== undefined
|
|
62
|
+
? (typeof overrideResponse === "function" ? await overrideResponse(info) : overrideResponse)
|
|
63
|
+
: (0, exports.getGetSolanaAccountByNameResponseMock)()), { status: 200,
|
|
64
|
+
headers: { 'Content-Type': 'application/json' }
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
exports.getGetSolanaAccountByNameMockHandler = getGetSolanaAccountByNameMockHandler;
|
|
69
|
+
const getSignSolanaTransactionMockHandler = (overrideResponse) => {
|
|
70
|
+
return msw_1.http.post('*/v2/solana/accounts/:address/sign/transaction', async (info) => {
|
|
71
|
+
await (0, msw_1.delay)(0);
|
|
72
|
+
return new msw_1.HttpResponse(JSON.stringify(overrideResponse !== undefined
|
|
73
|
+
? (typeof overrideResponse === "function" ? await overrideResponse(info) : overrideResponse)
|
|
74
|
+
: (0, exports.getSignSolanaTransactionResponseMock)()), { status: 200,
|
|
75
|
+
headers: { 'Content-Type': 'application/json' }
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
exports.getSignSolanaTransactionMockHandler = getSignSolanaTransactionMockHandler;
|
|
80
|
+
const getSignSolanaMessageMockHandler = (overrideResponse) => {
|
|
81
|
+
return msw_1.http.post('*/v2/solana/accounts/:address/sign/message', async (info) => {
|
|
82
|
+
await (0, msw_1.delay)(0);
|
|
83
|
+
return new msw_1.HttpResponse(JSON.stringify(overrideResponse !== undefined
|
|
84
|
+
? (typeof overrideResponse === "function" ? await overrideResponse(info) : overrideResponse)
|
|
85
|
+
: (0, exports.getSignSolanaMessageResponseMock)()), { status: 200,
|
|
86
|
+
headers: { 'Content-Type': 'application/json' }
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
exports.getSignSolanaMessageMockHandler = getSignSolanaMessageMockHandler;
|
|
91
|
+
const getSolanaAccountsMock = () => [
|
|
92
|
+
(0, exports.getListSolanaAccountsMockHandler)(),
|
|
93
|
+
(0, exports.getCreateSolanaAccountMockHandler)(),
|
|
94
|
+
(0, exports.getGetSolanaAccountMockHandler)(),
|
|
95
|
+
(0, exports.getGetSolanaAccountByNameMockHandler)(),
|
|
96
|
+
(0, exports.getSignSolanaTransactionMockHandler)(),
|
|
97
|
+
(0, exports.getSignSolanaMessageMockHandler)()
|
|
98
|
+
];
|
|
99
|
+
exports.getSolanaAccountsMock = getSolanaAccountsMock;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export * from "./generated/coinbaseDeveloperPlatformAPIs.schemas";
|
|
2
|
+
export * from "./generated/evm-accounts/evm-accounts";
|
|
3
|
+
export * from "./generated/evm-smart-accounts/evm-smart-accounts";
|
|
4
|
+
export * from "./generated/solana-accounts/solana-accounts";
|
|
5
|
+
export * from "./generated/faucets/faucets";
|
|
6
|
+
export declare const CdpOpenApiClient: {
|
|
7
|
+
configure: (options: import("./cdpApiClient").CdpOptions) => void;
|
|
8
|
+
requestEvmFaucet: (requestEvmFaucetBody: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").RequestEvmFaucetBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").RequestEvmFaucet200>;
|
|
9
|
+
requestSolanaFaucet: (requestSolanaFaucetBody: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").RequestSolanaFaucetBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").RequestSolanaFaucet200>;
|
|
10
|
+
listSolanaAccounts: (params?: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").ListSolanaAccountsParams, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").ListSolanaAccounts200>;
|
|
11
|
+
createSolanaAccount: (createSolanaAccountBody?: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").CreateSolanaAccountBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SolanaAccount>;
|
|
12
|
+
getSolanaAccount: (address: string, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SolanaAccount>;
|
|
13
|
+
getSolanaAccountByName: (name: string, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SolanaAccount>;
|
|
14
|
+
signSolanaTransaction: (address: string, signSolanaTransactionBody: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SignSolanaTransactionBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SignSolanaTransaction200>;
|
|
15
|
+
signSolanaMessage: (address: string, signSolanaMessageBody: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SignSolanaMessageBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SignSolanaMessage200>;
|
|
16
|
+
listEvmSmartAccounts: (params?: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").ListEvmSmartAccountsParams, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").ListEvmSmartAccounts200>;
|
|
17
|
+
createEvmSmartAccount: (createEvmSmartAccountBody: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").CreateEvmSmartAccountBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").EvmSmartAccount>;
|
|
18
|
+
getEvmSmartAccount: (address: string, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").EvmSmartAccount>;
|
|
19
|
+
prepareUserOperation: (address: string, prepareUserOperationBody: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").PrepareUserOperationBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").EvmUserOperation>;
|
|
20
|
+
getUserOperation: (address: string, userOpHash: string, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").EvmUserOperation>;
|
|
21
|
+
sendUserOperation: (address: string, userOpHash: string, sendUserOperationBody: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SendUserOperationBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").EvmUserOperation>;
|
|
22
|
+
listEvmAccounts: (params?: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").ListEvmAccountsParams, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").ListEvmAccounts200>;
|
|
23
|
+
createEvmAccount: (createEvmAccountBody?: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").CreateEvmAccountBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").EvmAccount>;
|
|
24
|
+
getEvmAccount: (address: string, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").EvmAccount>;
|
|
25
|
+
getEvmAccountByName: (name: string, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").EvmAccount>;
|
|
26
|
+
signEvmTransaction: (address: string, signEvmTransactionBody: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SignEvmTransactionBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SignEvmTransaction200>;
|
|
27
|
+
signEvmHash: (address: string, signEvmHashBody: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SignEvmHashBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SignEvmHash200>;
|
|
28
|
+
signEvmMessage: (address: string, signEvmMessageBody: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SignEvmMessageBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SignEvmMessage200>;
|
|
29
|
+
};
|
|
30
|
+
export declare const OpenApiEvmMethods: {
|
|
31
|
+
requestEvmFaucet: (requestEvmFaucetBody: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").RequestEvmFaucetBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").RequestEvmFaucet200>;
|
|
32
|
+
listEvmSmartAccounts: (params?: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").ListEvmSmartAccountsParams, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").ListEvmSmartAccounts200>;
|
|
33
|
+
createEvmSmartAccount: (createEvmSmartAccountBody: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").CreateEvmSmartAccountBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").EvmSmartAccount>;
|
|
34
|
+
getEvmSmartAccount: (address: string, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").EvmSmartAccount>;
|
|
35
|
+
prepareUserOperation: (address: string, prepareUserOperationBody: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").PrepareUserOperationBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").EvmUserOperation>;
|
|
36
|
+
getUserOperation: (address: string, userOpHash: string, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").EvmUserOperation>;
|
|
37
|
+
sendUserOperation: (address: string, userOpHash: string, sendUserOperationBody: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SendUserOperationBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").EvmUserOperation>;
|
|
38
|
+
listEvmAccounts: (params?: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").ListEvmAccountsParams, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").ListEvmAccounts200>;
|
|
39
|
+
createEvmAccount: (createEvmAccountBody?: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").CreateEvmAccountBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").EvmAccount>;
|
|
40
|
+
getEvmAccount: (address: string, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").EvmAccount>;
|
|
41
|
+
getEvmAccountByName: (name: string, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").EvmAccount>;
|
|
42
|
+
signEvmTransaction: (address: string, signEvmTransactionBody: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SignEvmTransactionBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SignEvmTransaction200>;
|
|
43
|
+
signEvmHash: (address: string, signEvmHashBody: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SignEvmHashBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SignEvmHash200>;
|
|
44
|
+
signEvmMessage: (address: string, signEvmMessageBody: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SignEvmMessageBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SignEvmMessage200>;
|
|
45
|
+
};
|
|
46
|
+
export declare const OpenApiSolanaMethods: {
|
|
47
|
+
requestSolanaFaucet: (requestSolanaFaucetBody: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").RequestSolanaFaucetBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").RequestSolanaFaucet200>;
|
|
48
|
+
listSolanaAccounts: (params?: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").ListSolanaAccountsParams, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").ListSolanaAccounts200>;
|
|
49
|
+
createSolanaAccount: (createSolanaAccountBody?: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").CreateSolanaAccountBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SolanaAccount>;
|
|
50
|
+
getSolanaAccount: (address: string, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SolanaAccount>;
|
|
51
|
+
getSolanaAccountByName: (name: string, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SolanaAccount>;
|
|
52
|
+
signSolanaTransaction: (address: string, signSolanaTransactionBody: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SignSolanaTransactionBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SignSolanaTransaction200>;
|
|
53
|
+
signSolanaMessage: (address: string, signSolanaMessageBody: import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SignSolanaMessageBody, options?: string | undefined) => Promise<import("./generated/coinbaseDeveloperPlatformAPIs.schemas").SignSolanaMessage200>;
|
|
54
|
+
};
|
|
55
|
+
export type CdpOpenApiClientType = typeof CdpOpenApiClient;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.OpenApiSolanaMethods = exports.OpenApiEvmMethods = exports.CdpOpenApiClient = void 0;
|
|
40
|
+
__exportStar(require("./generated/coinbaseDeveloperPlatformAPIs.schemas"), exports);
|
|
41
|
+
__exportStar(require("./generated/evm-accounts/evm-accounts"), exports);
|
|
42
|
+
__exportStar(require("./generated/evm-smart-accounts/evm-smart-accounts"), exports);
|
|
43
|
+
__exportStar(require("./generated/solana-accounts/solana-accounts"), exports);
|
|
44
|
+
__exportStar(require("./generated/faucets/faucets"), exports);
|
|
45
|
+
const evm = __importStar(require("./generated/evm-accounts/evm-accounts"));
|
|
46
|
+
const evmSmartAccounts = __importStar(require("./generated/evm-smart-accounts/evm-smart-accounts"));
|
|
47
|
+
const solana = __importStar(require("./generated/solana-accounts/solana-accounts"));
|
|
48
|
+
const faucets = __importStar(require("./generated/faucets/faucets"));
|
|
49
|
+
const cdpApiClient_1 = require("./cdpApiClient");
|
|
50
|
+
exports.CdpOpenApiClient = {
|
|
51
|
+
...evm,
|
|
52
|
+
...evmSmartAccounts,
|
|
53
|
+
...solana,
|
|
54
|
+
...faucets,
|
|
55
|
+
configure: cdpApiClient_1.configure,
|
|
56
|
+
};
|
|
57
|
+
exports.OpenApiEvmMethods = {
|
|
58
|
+
...evm,
|
|
59
|
+
...evmSmartAccounts,
|
|
60
|
+
requestEvmFaucet: faucets.requestEvmFaucet,
|
|
61
|
+
};
|
|
62
|
+
exports.OpenApiSolanaMethods = {
|
|
63
|
+
...solana,
|
|
64
|
+
requestSolanaFaucet: faucets.requestSolanaFaucet,
|
|
65
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AbiStateMutability, Address } from "viem";
|
|
2
|
+
import type { GetMulticallContractParameters } from "./multicall";
|
|
3
|
+
import type { OneOf, Prettify } from "./utils";
|
|
4
|
+
import type { Hex } from "./misc";
|
|
5
|
+
export type Call<call = unknown, extraProperties extends Record<string, unknown> = {}> = OneOf<(extraProperties & {
|
|
6
|
+
data?: Hex | undefined;
|
|
7
|
+
to: Address;
|
|
8
|
+
value?: bigint | undefined;
|
|
9
|
+
}) | (extraProperties & (Omit<GetMulticallContractParameters<call, AbiStateMutability>, "address"> & {
|
|
10
|
+
to: Address;
|
|
11
|
+
value?: bigint | undefined;
|
|
12
|
+
}))>;
|
|
13
|
+
export type Calls<calls extends readonly unknown[], extraProperties extends Record<string, unknown> = {}, result extends readonly any[] = []> = calls extends readonly [] ? readonly [] : calls extends readonly [infer call] ? readonly [...result, Prettify<Call<call, extraProperties>>] : calls extends readonly [infer call, ...infer rest] ? Calls<[...rest], extraProperties, [...result, Prettify<Call<call, extraProperties>>]> : readonly unknown[] extends calls ? calls : calls extends readonly (infer call extends OneOf<Call>)[] ? readonly Prettify<call>[] : readonly OneOf<Call>[];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Abi, AbiFunction, AbiParametersToPrimitiveTypes, AbiStateMutability, Address, ExtractAbiFunction, ExtractAbiFunctionNames, ResolvedRegister } from "abitype";
|
|
2
|
+
import type { Hex } from "./misc";
|
|
3
|
+
import type { IsUnion, UnionToTuple } from "./utils";
|
|
4
|
+
export type ContractFunctionName<abi extends Abi | readonly unknown[] = Abi, mutability extends AbiStateMutability = AbiStateMutability> = ExtractAbiFunctionNames<abi extends Abi ? abi : Abi, mutability> extends infer functionName extends string ? [functionName] extends [never] ? string : functionName : string;
|
|
5
|
+
export type ContractFunctionArgs<abi extends Abi | readonly unknown[] = Abi, mutability extends AbiStateMutability = AbiStateMutability, functionName extends ContractFunctionName<abi, mutability> = ContractFunctionName<abi, mutability>> = AbiParametersToPrimitiveTypes<ExtractAbiFunction<abi extends Abi ? abi : Abi, functionName, mutability>["inputs"], "inputs"> extends infer args ? [args] extends [never] ? readonly unknown[] : args : readonly unknown[];
|
|
6
|
+
export type Widen<type> = ([unknown] extends [type] ? unknown : never) | (type extends Function ? type : never) | (type extends ResolvedRegister["BigIntType"] ? bigint : never) | (type extends boolean ? boolean : never) | (type extends ResolvedRegister["IntType"] ? number : never) | (type extends string ? type extends ResolvedRegister["AddressType"] ? ResolvedRegister["AddressType"] : type extends ResolvedRegister["BytesType"]["inputs"] ? ResolvedRegister["BytesType"] : string : never) | (type extends readonly [] ? readonly [] : never) | (type extends Record<string, unknown> ? {
|
|
7
|
+
[K in keyof type]: Widen<type[K]>;
|
|
8
|
+
} : never) | (type extends {
|
|
9
|
+
length: number;
|
|
10
|
+
} ? {
|
|
11
|
+
[K in keyof type]: Widen<type[K]>;
|
|
12
|
+
} extends infer Val extends readonly unknown[] ? readonly [...Val] : never : never);
|
|
13
|
+
export type UnionWiden<type> = type extends any ? Widen<type> : never;
|
|
14
|
+
export type ExtractAbiFunctionForArgs<abi extends Abi, mutability extends AbiStateMutability, functionName extends ContractFunctionName<abi, mutability>, args extends ContractFunctionArgs<abi, mutability, functionName>> = ExtractAbiFunction<abi, functionName, mutability> extends infer abiFunction extends AbiFunction ? IsUnion<abiFunction> extends true ? UnionToTuple<abiFunction> extends infer abiFunctions extends readonly AbiFunction[] ? {
|
|
15
|
+
[k in keyof abiFunctions]: CheckArgs<abiFunctions[k], args>;
|
|
16
|
+
}[number] : never : abiFunction : never;
|
|
17
|
+
type CheckArgs<abiFunction extends AbiFunction, args, targetArgs extends AbiParametersToPrimitiveTypes<abiFunction["inputs"], "inputs"> = AbiParametersToPrimitiveTypes<abiFunction["inputs"], "inputs">> = (readonly [] extends args ? readonly [] : args) extends targetArgs ? abiFunction : never;
|
|
18
|
+
export type ContractFunctionParameters<abi extends Abi | readonly unknown[] = Abi, mutability extends AbiStateMutability = AbiStateMutability, functionName extends ContractFunctionName<abi, mutability> = ContractFunctionName<abi, mutability>, args extends ContractFunctionArgs<abi, mutability, functionName> = ContractFunctionArgs<abi, mutability, functionName>, deployless extends boolean = false, allFunctionNames = ContractFunctionName<abi, mutability>, allArgs = ContractFunctionArgs<abi, mutability, functionName>> = {
|
|
19
|
+
abi: abi;
|
|
20
|
+
functionName: allFunctionNames | (functionName extends allFunctionNames ? functionName : never);
|
|
21
|
+
args?: (abi extends Abi ? UnionWiden<args> : never) | allArgs | undefined;
|
|
22
|
+
} & (readonly [] extends allArgs ? {} : {
|
|
23
|
+
args: Widen<args>;
|
|
24
|
+
}) & (deployless extends true ? {
|
|
25
|
+
address?: undefined;
|
|
26
|
+
code: Hex;
|
|
27
|
+
} : {
|
|
28
|
+
address: Address;
|
|
29
|
+
});
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Abi, AbiStateMutability } from "abitype";
|
|
2
|
+
import type { ContractFunctionArgs, ContractFunctionName, ContractFunctionParameters } from "./contract";
|
|
3
|
+
export type GetMulticallContractParameters<contract, mutability extends AbiStateMutability> = contract extends {
|
|
4
|
+
abi: infer abi extends Abi;
|
|
5
|
+
} ? contract extends {
|
|
6
|
+
functionName: infer functionName extends ContractFunctionName<abi, mutability>;
|
|
7
|
+
} ? contract extends {
|
|
8
|
+
args: infer args extends ContractFunctionArgs<abi, mutability, functionName>;
|
|
9
|
+
} ? ContractFunctionParameters<abi, mutability, functionName, args> : ContractFunctionParameters<abi, mutability, functionName> : Abi extends abi ? ContractFunctionParameters : ContractFunctionParameters<abi, mutability> : ContractFunctionParameters<readonly unknown[]>;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filters out all members of {@link T} that are not {@link P}
|
|
3
|
+
*
|
|
4
|
+
* @param T - Items to filter
|
|
5
|
+
* @param P - Type to filter out
|
|
6
|
+
* @returns Filtered items
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* type Result = Filter<['a', 'b', 'c'], 'b'>
|
|
10
|
+
* // ^? type Result = ['a', 'c']
|
|
11
|
+
*/
|
|
12
|
+
export type Filter<T extends readonly unknown[], P, Acc extends readonly unknown[] = []> = T extends readonly [infer F, ...infer Rest extends readonly unknown[]] ? [F] extends [P] ? Filter<Rest, P, [...Acc, F]> : Filter<Rest, P, Acc> : readonly [...Acc];
|
|
13
|
+
/**
|
|
14
|
+
* @description Checks if {@link T} can be narrowed further than {@link U}
|
|
15
|
+
* @param T - Type to check
|
|
16
|
+
* @param U - Type to against
|
|
17
|
+
* @example
|
|
18
|
+
* type Result = IsNarrowable<'foo', string>
|
|
19
|
+
* // ^? true
|
|
20
|
+
*/
|
|
21
|
+
export type IsNarrowable<T, U> = IsNever<(T extends U ? true : false) & (U extends T ? false : true)> extends true ? false : true;
|
|
22
|
+
/**
|
|
23
|
+
* @description Checks if {@link T} is `never`
|
|
24
|
+
* @param T - Type to check
|
|
25
|
+
* @example
|
|
26
|
+
* type Result = IsNever<never>
|
|
27
|
+
* // ^? type Result = true
|
|
28
|
+
*/
|
|
29
|
+
export type IsNever<T> = [T] extends [never] ? true : false;
|
|
30
|
+
/** Removes `readonly` from all properties of an object. */
|
|
31
|
+
export type Mutable<type extends object> = {
|
|
32
|
+
-readonly [key in keyof type]: type[key];
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* @description Evaluates boolean "or" condition for {@link T} properties.
|
|
36
|
+
* @param T - Type to check
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* type Result = Or<[false, true, false]>
|
|
40
|
+
* // ^? type Result = true
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* type Result = Or<[false, false, false]>
|
|
44
|
+
* // ^? type Result = false
|
|
45
|
+
*/
|
|
46
|
+
export type Or<T extends readonly unknown[]> = T extends readonly [infer Head, ...infer Tail] ? Head extends true ? true : Or<Tail> : false;
|
|
47
|
+
/**
|
|
48
|
+
* @description Checks if {@link T} is `undefined`
|
|
49
|
+
* @param T - Type to check
|
|
50
|
+
* @example
|
|
51
|
+
* type Result = IsUndefined<undefined>
|
|
52
|
+
* // ^? type Result = true
|
|
53
|
+
*/
|
|
54
|
+
export type IsUndefined<T> = [undefined] extends [T] ? true : false;
|
|
55
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
56
|
+
/**
|
|
57
|
+
* @description Makes attributes on the type T required if required is true.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* MaybeRequired<{ a: string, b?: number }, true>
|
|
61
|
+
* => { a: string, b: number }
|
|
62
|
+
*
|
|
63
|
+
* MaybeRequired<{ a: string, b?: number }, false>
|
|
64
|
+
* => { a: string, b?: number }
|
|
65
|
+
*/
|
|
66
|
+
export type MaybeRequired<T, required extends boolean> = required extends true ? ExactRequired<T> : T;
|
|
67
|
+
/**
|
|
68
|
+
* @description Assigns the properties of U onto T.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* Assign<{ a: string, b: number }, { a: undefined, c: boolean }>
|
|
72
|
+
* => { a: undefined, b: number, c: boolean }
|
|
73
|
+
*/
|
|
74
|
+
export type Assign<T, U> = Assign_<T, U> & U;
|
|
75
|
+
type Assign_<T, U> = {
|
|
76
|
+
[K in keyof T as K extends keyof U ? (U[K] extends void ? never : K) : K]: K extends keyof U ? U[K] : T[K];
|
|
77
|
+
};
|
|
78
|
+
export type NoInfer<type> = [type][type extends any ? 0 : never];
|
|
79
|
+
/**
|
|
80
|
+
* @description Constructs a type by excluding `undefined` from `T`.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* NoUndefined<string | undefined>
|
|
84
|
+
* => string
|
|
85
|
+
*
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
export type NoUndefined<T> = T extends undefined ? never : T;
|
|
89
|
+
/** Strict version of built-in Omit type */
|
|
90
|
+
export type Omit<type, keys extends keyof type> = Pick<type, Exclude<keyof type, keys>>;
|
|
91
|
+
/**
|
|
92
|
+
* @description Creates a type that is a partial of T, but with the required keys K.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* PartialBy<{ a: string, b: number }, 'a'>
|
|
96
|
+
* => { a?: string, b: number }
|
|
97
|
+
*/
|
|
98
|
+
export type PartialBy<T, K extends keyof T> = Omit<T, K> & ExactPartial<Pick<T, K>>;
|
|
99
|
+
/**
|
|
100
|
+
* @description Combines members of an intersection into a readable type.
|
|
101
|
+
*
|
|
102
|
+
* @see {@link https://twitter.com/mattpocockuk/status/1622730173446557697?s=20&t=NdpAcmEFXY01xkqU3KO0Mg}
|
|
103
|
+
* @example
|
|
104
|
+
* Prettify<{ a: string } & { b: string } & { c: number, d: bigint }>
|
|
105
|
+
* => { a: string, b: string, c: number, d: bigint }
|
|
106
|
+
*/
|
|
107
|
+
export type Prettify<T> = {
|
|
108
|
+
[K in keyof T]: T[K];
|
|
109
|
+
} & {};
|
|
110
|
+
/** @internal */
|
|
111
|
+
export type Evaluate<type> = {
|
|
112
|
+
[key in keyof type]: type[key];
|
|
113
|
+
} & {};
|
|
114
|
+
/**
|
|
115
|
+
* @description Creates a type that is T with the required keys K.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* RequiredBy<{ a?: string, b: number }, 'a'>
|
|
119
|
+
* => { a: string, b: number }
|
|
120
|
+
*/
|
|
121
|
+
export type RequiredBy<T, K extends keyof T> = Omit<T, K> & ExactRequired<Pick<T, K>>;
|
|
122
|
+
/**
|
|
123
|
+
* @description Returns truthy if `array` contains `value`.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* Some<[1, 2, 3], 2>
|
|
127
|
+
* => true
|
|
128
|
+
*/
|
|
129
|
+
export type Some<array extends readonly unknown[], value> = array extends readonly [
|
|
130
|
+
value,
|
|
131
|
+
...unknown[]
|
|
132
|
+
] ? true : array extends readonly [unknown, ...infer rest] ? Some<rest, value> : false;
|
|
133
|
+
/**
|
|
134
|
+
* @description Creates a type that extracts the values of T.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ValueOf<{ a: string, b: number }>
|
|
138
|
+
* => string | number
|
|
139
|
+
*
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
142
|
+
export type ValueOf<T> = T[keyof T];
|
|
143
|
+
export type UnionToTuple<union, last = LastInUnion<union>> = [union] extends [never] ? [] : [...UnionToTuple<Exclude<union, last>>, last];
|
|
144
|
+
type LastInUnion<U> = UnionToIntersection<U extends unknown ? (x: U) => 0 : never> extends (x: infer l) => 0 ? l : never;
|
|
145
|
+
type UnionToIntersection<union> = (union extends unknown ? (arg: union) => 0 : never) extends (arg: infer i) => 0 ? i : never;
|
|
146
|
+
export type IsUnion<union, union2 = union> = union extends union2 ? ([union2] extends [union] ? false : true) : never;
|
|
147
|
+
export type MaybePartial<type, enabled extends boolean | undefined> = enabled extends true ? Prettify<ExactPartial<type>> : type;
|
|
148
|
+
export type ExactPartial<type> = {
|
|
149
|
+
[key in keyof type]?: type[key] | undefined;
|
|
150
|
+
};
|
|
151
|
+
export type ExactRequired<type> = {
|
|
152
|
+
[P in keyof type]-?: Exclude<type[P], undefined>;
|
|
153
|
+
};
|
|
154
|
+
export type OneOf<union extends object, fallback extends object | undefined = undefined, keys extends KeyofUnion<union> = KeyofUnion<union>> = union extends infer item ? Prettify<item & {
|
|
155
|
+
[key in Exclude<keys, keyof item>]?: fallback extends object ? key extends keyof fallback ? fallback[key] : undefined : undefined;
|
|
156
|
+
}> : never;
|
|
157
|
+
type KeyofUnion<type> = type extends type ? keyof type : never;
|
|
158
|
+
/**
|
|
159
|
+
* Loose version of {@link Omit}
|
|
160
|
+
*
|
|
161
|
+
* @internal
|
|
162
|
+
*/
|
|
163
|
+
export type LooseOmit<type, keys extends string> = Pick<type, Exclude<keyof type, keys>>;
|
|
164
|
+
export type UnionEvaluate<type> = type extends object ? Prettify<type> : type;
|
|
165
|
+
export type UnionLooseOmit<type, keys extends string> = type extends any ? LooseOmit<type, keys> : never;
|
|
166
|
+
/**
|
|
167
|
+
* @description Construct a type with the properties of union type T except for those in type K.
|
|
168
|
+
* @example
|
|
169
|
+
* type Result = UnionOmit<{ a: string, b: number } | { a: string, b: undefined, c: number }, 'a'>
|
|
170
|
+
* => { b: number } | { b: undefined, c: number }
|
|
171
|
+
*/
|
|
172
|
+
export type UnionOmit<type, keys extends keyof type> = type extends any ? Omit<type, keys> : never;
|
|
173
|
+
/**
|
|
174
|
+
* @description Construct a type with the properties of union type T except for those in type K.
|
|
175
|
+
* @example
|
|
176
|
+
* type Result = UnionOmit<{ a: string, b: number } | { a: string, b: undefined, c: number }, 'a'>
|
|
177
|
+
* => { b: number } | { b: undefined, c: number }
|
|
178
|
+
*/
|
|
179
|
+
export type UnionPick<type, keys extends keyof type> = type extends any ? Pick<type, keys> : never;
|
|
180
|
+
/**
|
|
181
|
+
* @description Creates a type that is a partial of T, but with the required keys K.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* PartialBy<{ a: string, b: number } | { a: string, b: undefined, c: number }, 'a'>
|
|
185
|
+
* => { a?: string, b: number } | { a?: string, b: undefined, c: number }
|
|
186
|
+
*/
|
|
187
|
+
export type UnionPartialBy<T, K extends keyof T> = T extends any ? PartialBy<T, K> : never;
|
|
188
|
+
/**
|
|
189
|
+
* @description Creates a type that is T with the required keys K.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* RequiredBy<{ a?: string, b: number } | { a?: string, c?: number }, 'a'>
|
|
193
|
+
* => { a: string, b: number } | { a: string, c?: number }
|
|
194
|
+
*/
|
|
195
|
+
export type UnionRequiredBy<T, K extends keyof T> = T extends any ? RequiredBy<T, K> : never;
|
|
196
|
+
export {};
|