Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Create subpackages for internal-ish code #2351

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion packages/accounts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
],
"scripts": {
"compile:js": "tsup --config build-scripts/tsup.config.package.ts",
"compile:typedefs": "tsc -p ./tsconfig.declarations.json && node ../../node_modules/@solana/build-scripts/add-js-extension-to-types.mjs",
"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:-preview} --access public --no-git-checks",
Expand Down
2 changes: 1 addition & 1 deletion packages/accounts/src/__tests__/__setup__.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
SolanaRpcResponse,
} from '@solana/rpc-types';

import type { GetAccountInfoApi, GetMultipleAccountsApi, JsonParsedDataResponse } from '../rpc-api';
import type { GetAccountInfoApi, GetMultipleAccountsApi, JsonParsedDataResponse } from '../rpc-api/index.js';

export type Base64RpcAccount = AccountInfoBase & AccountInfoWithBase64EncodedData;
export type Base58RpcAccount = AccountInfoBase & (AccountInfoWithBase58Bytes | AccountInfoWithBase58EncodedData);
Expand Down
8 changes: 4 additions & 4 deletions packages/accounts/src/__tests__/decode-account-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
SolanaError,
} from '@solana/errors';

import { Account, EncodedAccount } from '../account';
import { assertAccountDecoded, assertAccountsDecoded, decodeAccount } from '../decode-account';
import { MaybeAccount, MaybeEncodedAccount } from '../maybe-account';
import { getMockDecoder } from './__setup__';
import { Account, EncodedAccount } from '../account.js';
import { assertAccountDecoded, assertAccountsDecoded, decodeAccount } from '../decode-account.js';
import { MaybeAccount, MaybeEncodedAccount } from '../maybe-account.js';
import { getMockDecoder } from './__setup__.js';

describe('decodeAccount', () => {
it('decodes the account data of an existing encoded account', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/accounts/src/__tests__/fetch-account-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
fetchEncodedAccounts,
fetchJsonParsedAccount,
fetchJsonParsedAccounts,
} from '../fetch-account';
import { MaybeAccount, MaybeEncodedAccount } from '../maybe-account';
import { Base64RpcAccount, getMockRpc, JsonParsedRpcAccount } from './__setup__';
} from '../fetch-account.js';
import { MaybeAccount, MaybeEncodedAccount } from '../maybe-account.js';
import { Base64RpcAccount, getMockRpc, JsonParsedRpcAccount } from './__setup__.js';

describe('fetchEncodedAccount', () => {
it('fetches and parses an existing base64-encoded account from an RPC', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/accounts/src/__tests__/maybe-account-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
SolanaError,
} from '@solana/errors';

import { assertAccountExists, assertAccountsExist, MaybeEncodedAccount } from '../maybe-account';
import { assertAccountExists, assertAccountsExist, MaybeEncodedAccount } from '../maybe-account.js';

describe('assertAccountExists', () => {
it('fails if the provided MaybeAccount does not exist', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/accounts/src/__tests__/parse-account-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import '@solana/test-matchers/toBeFrozenObject';
import type { Address } from '@solana/addresses';
import { lamports } from '@solana/rpc-types';

import { Account, EncodedAccount } from '../account';
import { MaybeAccount, MaybeEncodedAccount } from '../maybe-account';
import { parseBase58RpcAccount, parseBase64RpcAccount, parseJsonRpcAccount } from '../parse-account';
import { Base58RpcAccount, Base64RpcAccount, JsonParsedRpcAccount } from './__setup__';
import { Account, EncodedAccount } from '../account.js';
import { MaybeAccount, MaybeEncodedAccount } from '../maybe-account.js';
import { parseBase58RpcAccount, parseBase64RpcAccount, parseJsonRpcAccount } from '../parse-account.js';
import { Base58RpcAccount, Base64RpcAccount, JsonParsedRpcAccount } from './__setup__.js';

describe('parseBase64RpcAccount', () => {
it('parses an encoded account with base64 data', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Address } from '@solana/addresses';
import { Decoder } from '@solana/codecs-core';

import { Account, EncodedAccount } from '../account';
import { assertAccountDecoded, assertAccountsDecoded, decodeAccount } from '../decode-account';
import { MaybeAccount, MaybeEncodedAccount } from '../maybe-account';
import { Account, EncodedAccount } from '../account.js';
import { assertAccountDecoded, assertAccountsDecoded, decodeAccount } from '../decode-account.js';
import { MaybeAccount, MaybeEncodedAccount } from '../maybe-account.js';

type MockData = { foo: 42 };
type MockDataDecoder = Decoder<MockData>;
Expand Down
6 changes: 3 additions & 3 deletions packages/accounts/src/__typetests__/fetch-account-typetest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
fetchEncodedAccounts,
fetchJsonParsedAccount,
fetchJsonParsedAccounts,
} from '../fetch-account';
import type { MaybeAccount, MaybeEncodedAccount } from '../maybe-account';
import type { GetAccountInfoApi, GetMultipleAccountsApi } from '../rpc-api';
} from '../fetch-account.js';
import type { MaybeAccount, MaybeEncodedAccount } from '../maybe-account.js';
import type { GetAccountInfoApi, GetMultipleAccountsApi } from '../rpc-api/index.js';

const rpc = {} as Rpc<GetAccountInfoApi & GetMultipleAccountsApi>;
const address = '1111' as Address<'1111'>;
Expand Down
4 changes: 2 additions & 2 deletions packages/accounts/src/__typetests__/maybe-account-typetest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Address } from '@solana/addresses';

import { Account } from '../account';
import { assertAccountExists, assertAccountsExist, MaybeAccount } from '../maybe-account';
import { Account } from '../account.js';
import { assertAccountExists, assertAccountsExist, MaybeAccount } from '../maybe-account.js';

type MockData = { foo: 42 };

Expand Down
8 changes: 4 additions & 4 deletions packages/accounts/src/__typetests__/parse-account-typetest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Address } from '@solana/addresses';

import { Base58RpcAccount, Base64RpcAccount, JsonParsedRpcAccount } from '../__tests__/__setup__';
import { Account, EncodedAccount } from '../account';
import { MaybeAccount, MaybeEncodedAccount } from '../maybe-account';
import { parseBase58RpcAccount, parseBase64RpcAccount, parseJsonRpcAccount } from '../parse-account';
import { Base58RpcAccount, Base64RpcAccount, JsonParsedRpcAccount } from '../__tests__/__setup__.js';
import { Account, EncodedAccount } from '../account.js';
import { MaybeAccount, MaybeEncodedAccount } from '../maybe-account.js';
import { parseBase58RpcAccount, parseBase64RpcAccount, parseJsonRpcAccount } from '../parse-account.js';

const address = '1111' as Address<'1111'>;
type MyData = { mint: Address; token: Address };
Expand Down
4 changes: 2 additions & 2 deletions packages/accounts/src/decode-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
SolanaError,
} from '@solana/errors';

import type { Account, EncodedAccount } from './account';
import type { MaybeAccount, MaybeEncodedAccount } from './maybe-account';
import type { Account, EncodedAccount } from './account.js';
import type { MaybeAccount, MaybeEncodedAccount } from './maybe-account.js';

/** Decodes the data of a given account using the provided decoder. */
export function decodeAccount<TData extends object, TAddress extends string = string>(
Expand Down
6 changes: 3 additions & 3 deletions packages/accounts/src/fetch-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type { Address } from '@solana/addresses';
import type { Rpc } from '@solana/rpc-spec';
import type { Commitment, Slot } from '@solana/rpc-types';

import type { MaybeAccount, MaybeEncodedAccount } from './maybe-account';
import { parseBase64RpcAccount, parseJsonRpcAccount } from './parse-account';
import type { GetAccountInfoApi, GetMultipleAccountsApi } from './rpc-api';
import type { MaybeAccount, MaybeEncodedAccount } from './maybe-account.js';
import { parseBase64RpcAccount, parseJsonRpcAccount } from './parse-account.js';
import type { GetAccountInfoApi, GetMultipleAccountsApi } from './rpc-api/index.js';

/** Optional configuration for fetching a singular account. */
export type FetchAccountConfig = {
Expand Down
10 changes: 5 additions & 5 deletions packages/accounts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './account';
export * from './decode-account';
export * from './fetch-account';
export * from './maybe-account';
export * from './parse-account';
export * from './account.js';
export * from './decode-account.js';
export * from './fetch-account.js';
export * from './maybe-account.js';
export * from './parse-account.js';
2 changes: 1 addition & 1 deletion packages/accounts/src/maybe-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
SolanaError,
} from '@solana/errors';

import { Account } from './account';
import { Account } from './account.js';

/** Defines a Solana account that may or may not exist after having tried to fetch it. */
export type MaybeAccount<TData extends Uint8Array | object, TAddress extends string = string> =
Expand Down
6 changes: 3 additions & 3 deletions packages/accounts/src/parse-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import type {
AccountInfoWithBase64EncodedData,
} from '@solana/rpc-types';

import type { Account, BaseAccount, EncodedAccount } from './account';
import type { MaybeAccount, MaybeEncodedAccount } from './maybe-account';
import type { JsonParsedDataResponse } from './rpc-api';
import type { Account, BaseAccount, EncodedAccount } from './account.js';
import type { MaybeAccount, MaybeEncodedAccount } from './maybe-account.js';
import type { JsonParsedDataResponse } from './rpc-api/index.js';

type Base64EncodedRpcAccount = AccountInfoBase & AccountInfoWithBase64EncodedData;

Expand Down
6 changes: 3 additions & 3 deletions packages/accounts/src/rpc-api/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './common';
export * from './getAccountInfo';
export * from './getMultipleAccounts';
export * from './common.js';
export * from './getAccountInfo.js';
export * from './getMultipleAccounts.js';
2 changes: 1 addition & 1 deletion packages/addresses/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
],
"scripts": {
"compile:js": "tsup --config build-scripts/tsup.config.package.ts",
"compile:typedefs": "tsc -p ./tsconfig.declarations.json && node ../../node_modules/@solana/build-scripts/add-js-extension-to-types.mjs",
"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:-preview} --access public --no-git-checks",
Expand Down
10 changes: 5 additions & 5 deletions packages/addresses/src/__tests__/address-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
SolanaError,
} from '@solana/errors';

import { Address, getAddressCodec, getAddressComparator } from '../address';
import { Address, getAddressCodec, getAddressComparator } from '../address.js';

jest.mock('@solana/codecs-strings', () => ({
...jest.requireActual('@solana/codecs-strings'),
Expand All @@ -22,14 +22,14 @@ const originalGetBase58Decoder = originalBase58Module.getBase58Decoder();

describe('Address', () => {
describe('assertIsAddress()', () => {
let assertIsAddress: typeof import('../address').assertIsAddress;
let assertIsAddress: typeof import('../address.js').assertIsAddress;
// Reload `assertIsAddress` before each test to reset memoized state
beforeEach(async () => {
await jest.isolateModulesAsync(async () => {
const base58ModulePromise =
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import('../address');
import('../address.js');
assertIsAddress = (await base58ModulePromise).assertIsAddress;
});
});
Expand Down Expand Up @@ -171,12 +171,12 @@ describe('Address', () => {
expect.assertions(2);

// reload the module to reset memoized state
let getAddressCodec: typeof import('../address').getAddressCodec;
let getAddressCodec: typeof import('../address.js').getAddressCodec;
await jest.isolateModulesAsync(async () => {
const base58ModulePromise =
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import('../address');
import('../address.js');
getAddressCodec = (await base58ModulePromise).getAddressCodec;
});

Expand Down
2 changes: 1 addition & 1 deletion packages/addresses/src/__tests__/coercions-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
SolanaError,
} from '@solana/errors';

import { Address, address } from '../address';
import { Address, address } from '../address.js';

describe('coercions', () => {
describe('address', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/addresses/src/__tests__/curve-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { compressedPointBytesAreOnCurve } from '../curve';
import { compressedPointBytesAreOnCurve } from '../curve.js';

const OFF_CURVE_KEY_BYTES = [
new Uint8Array([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
SolanaError,
} from '@solana/errors';

import { Address } from '../address';
import { createAddressWithSeed, getProgramDerivedAddress } from '../program-derived-address';
import { Address } from '../address.js';
import { createAddressWithSeed, getProgramDerivedAddress } from '../program-derived-address.js';

describe('getProgramDerivedAddress()', () => {
it('fatals when supplied more than 16 seeds', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/addresses/src/__tests__/public-key-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getAddressFromPublicKey } from '../public-key';
import { getAddressFromPublicKey } from '../public-key.js';

// Corresponds to address `DcESq8KFcdTdpjWtr2DoGcvu5McM3VJoBetgM1X1vVct`
const MOCK_PUBLIC_KEY_BYTES = new Uint8Array([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { Address, address } from '../address';
import { Address, address } from '../address.js';

address('555555555555555555555555') satisfies Address<'555555555555555555555555'>;
2 changes: 1 addition & 1 deletion packages/addresses/src/curve.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pointIsOnCurve } from './vendor/noble/ed25519';
import { pointIsOnCurve } from './vendor/noble/ed25519.js';

function byteToHex(byte: number): string {
const hexString = byte.toString(16);
Expand Down
6 changes: 3 additions & 3 deletions packages/addresses/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './address';
export * from './program-derived-address';
export * from './public-key';
export * from './address.js';
export * from './program-derived-address.js';
export * from './public-key.js';
4 changes: 2 additions & 2 deletions packages/addresses/src/program-derived-address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
SolanaError,
} from '@solana/errors';

import { Address, assertIsAddress, getAddressCodec, isAddress } from './address';
import { compressedPointBytesAreOnCurve } from './curve';
import { Address, assertIsAddress, getAddressCodec, isAddress } from './address.js';
import { compressedPointBytesAreOnCurve } from './curve.js';

/**
* An address derived from a program address and a set of seeds.
Expand Down
2 changes: 1 addition & 1 deletion packages/addresses/src/public-key.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assertKeyExporterIsAvailable } from '@solana/assertions';
import { SOLANA_ERROR__ADDRESSES__INVALID_ED25519_PUBLIC_KEY, SolanaError } from '@solana/errors';

import { Address, getAddressDecoder } from './address';
import { Address, getAddressDecoder } from './address.js';

export async function getAddressFromPublicKey(publicKey: CryptoKey): Promise<Address> {
assertKeyExporterIsAvailable();
Expand Down
2 changes: 1 addition & 1 deletion packages/assertions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
],
"scripts": {
"compile:js": "tsup --config build-scripts/tsup.config.package.ts",
"compile:typedefs": "tsc -p ./tsconfig.declarations.json && node ../../node_modules/@solana/build-scripts/add-js-extension-to-types.mjs",
"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:-preview} --access public --no-git-checks",
Expand Down
6 changes: 3 additions & 3 deletions packages/assertions/src/__tests__/subtle-crypto-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
assertKeyExporterIsAvailable,
assertSigningCapabilityIsAvailable,
assertVerificationCapabilityIsAvailable,
} from '../subtle-crypto';
} from '../subtle-crypto.js';

describe('assertDigestCapabilityIsAvailable()', () => {
describe('when `SubtleCrypto::digest` is available', () => {
Expand Down Expand Up @@ -97,13 +97,13 @@ describe('assertKeyExporterIsAvailable()', () => {
});

describe('assertKeyGenerationIsAvailable()', () => {
let assertKeyGenerationIsAvailable: typeof import('../subtle-crypto').assertKeyGenerationIsAvailable;
let assertKeyGenerationIsAvailable: typeof import('../subtle-crypto.js').assertKeyGenerationIsAvailable;
beforeEach(async () => {
await jest.isolateModulesAsync(async () => {
const guardModulePromise =
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import('../subtle-crypto');
import('../subtle-crypto.js');
assertKeyGenerationIsAvailable = (await guardModulePromise).assertKeyGenerationIsAvailable;
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/assertions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './subtle-crypto';
export * from './subtle-crypto.js';
50 changes: 0 additions & 50 deletions packages/build-scripts/add-js-extension-to-types.mjs

This file was deleted.