diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4e4bf99..9fac7b0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,7 +7,7 @@ on: branches: [main] env: - JS_PACKAGES: "['clients-js-legacy']" + JS_PACKAGES: "['clients-js', 'clients-js-legacy']" SBPF_PROGRAM_PACKAGES: "['program']" RUST_PACKAGES: "['program']" WASM_PACKAGES: "['program']" diff --git a/.github/workflows/publish-js.yml b/.github/workflows/publish-js.yml index 5d066d2..6c78658 100644 --- a/.github/workflows/publish-js.yml +++ b/.github/workflows/publish-js.yml @@ -6,9 +6,10 @@ on: package-path: description: Path to directory with package to release required: true - default: 'clients/js-legacy' + default: "clients/js" type: choice options: + - clients/js - clients/js-legacy level: description: Version level diff --git a/Makefile b/Makefile index e0c5556..d2fa0e1 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,9 @@ clippy-%: --deny=clippy::manual_let_else \ --deny=clippy::used_underscore_binding $(ARGS) +format-check-js-%: + cd $(call make-path,$*) && pnpm install && pnpm format $(ARGS) + format-check-%: cargo $(nightly) fmt --check --manifest-path $(call make-path,$*)/Cargo.toml $(ARGS) @@ -73,20 +76,17 @@ build-doc-%: test-doc-%: cargo $(nightly) test --doc --all-features --manifest-path $(call make-path,$*)/Cargo.toml $(ARGS) +test-js-%: + make restart-test-validator + cd $(call make-path,$*) && pnpm install && pnpm build && pnpm test $(ARGS) + make stop-test-validator + test-%: SBF_OUT_DIR=$(PWD)/target/deploy cargo $(nightly) test --manifest-path $(call make-path,$*)/Cargo.toml $(ARGS) -format-check-js-%: - cd $(call make-path,$*) && pnpm install && pnpm format $(ARGS) - lint-js-%: cd $(call make-path,$*) && pnpm install && pnpm lint $(ARGS) -test-js-%: - make restart-test-validator - cd $(call make-path,$*) && pnpm install && pnpm build && pnpm test $(ARGS) - make stop-test-validator - build-js-%: cd $(call make-path,$*) && pnpm install && pnpm build diff --git a/clients/js/.eslintrc.js b/clients/js/.eslintrc.js new file mode 100644 index 0000000..465c1c7 --- /dev/null +++ b/clients/js/.eslintrc.js @@ -0,0 +1,17 @@ +module.exports = { + extends: ["@solana/eslint-config-solana"], + ignorePatterns: [".eslintrc.cjs", "tsup.config.ts", "env-shim.ts"], + parserOptions: { + project: "tsconfig.json", + tsconfigRootDir: __dirname, + sourceType: "module", + }, + rules: { + "@typescript-eslint/ban-types": "off", + "@typescript-eslint/sort-type-constituents": "off", + "prefer-destructuring": "off", + "simple-import-sort/imports": "off", + "sort-keys-fix/sort-keys-fix": "off", + "typescript-sort-keys/interface": "off", + }, +}; diff --git a/clients/js/.prettierrc.json b/clients/js/.prettierrc.json new file mode 100644 index 0000000..0c75014 --- /dev/null +++ b/clients/js/.prettierrc.json @@ -0,0 +1,10 @@ +{ + "semi": true, + "singleQuote": true, + "trailingComma": "es5", + "useTabs": false, + "tabWidth": 2, + "arrowParens": "always", + "printWidth": 80 +} + diff --git a/clients/js/src/actions.ts b/clients/js/src/actions.ts index 718cc13..6f16583 100644 --- a/clients/js/src/actions.ts +++ b/clients/js/src/actions.ts @@ -7,11 +7,11 @@ import { KeyPairSigner, Rpc, TransactionSigner, -} from "@solana/kit"; +} from '@solana/kit'; import { getCreateAccountInstruction, getTransferSolInstruction, -} from "@solana-program/system"; +} from '@solana-program/system'; import { getCloseAccountInstruction, getInitializeInstruction, @@ -19,8 +19,8 @@ import { getSetAuthorityInstruction, getWriteInstruction, SPL_RECORD_PROGRAM_ADDRESS, -} from "./generated"; -import { RECORD_META_DATA_SIZE } from "./constants"; +} from './generated'; +import { RECORD_META_DATA_SIZE } from './constants'; export interface CreateRecordArgs { rpc: Rpc; @@ -66,7 +66,7 @@ export async function createRecord({ recordAccount: recordSigner.address, authority, }, - { programAddress: programId }, + { programAddress: programId } ); return { @@ -95,7 +95,7 @@ export function createWriteInstruction(args: WriteRecordArgs): Instruction { offset: BigInt(args.offset), data: args.data, }, - { programAddress: args.programId }, + { programAddress: args.programId } ); } @@ -134,7 +134,7 @@ export async function reallocateRecord({ source: payer, destination: recordAccount, amount: lamportsNeeded, - }), + }) ); } @@ -145,8 +145,8 @@ export async function reallocateRecord({ authority, dataLength: BigInt(newDataLength), }, - { programAddress: programId }, - ), + { programAddress: programId } + ) ); return ixs; @@ -160,7 +160,7 @@ export interface SetAuthorityArgs { } export function createSetAuthorityInstruction( - args: SetAuthorityArgs, + args: SetAuthorityArgs ): Instruction { return getSetAuthorityInstruction( { @@ -168,7 +168,7 @@ export function createSetAuthorityInstruction( authority: args.authority, newAuthority: args.newAuthority, }, - { programAddress: args.programId }, + { programAddress: args.programId } ); } @@ -180,7 +180,7 @@ export interface CloseRecordArgs { } export function createCloseRecordInstruction( - args: CloseRecordArgs, + args: CloseRecordArgs ): Instruction { return getCloseAccountInstruction( { @@ -188,6 +188,6 @@ export function createCloseRecordInstruction( authority: args.authority, receiver: args.receiver, }, - { programAddress: args.programId }, + { programAddress: args.programId } ); } diff --git a/clients/js/src/index.ts b/clients/js/src/index.ts index 6bebd37..237c949 100644 --- a/clients/js/src/index.ts +++ b/clients/js/src/index.ts @@ -1,3 +1,3 @@ -export * from "./constants"; -export * from "./generated"; -export * from "./actions"; +export * from './constants'; +export * from './generated'; +export * from './actions'; diff --git a/clients/js/test/_setup.ts b/clients/js/test/_setup.ts index b3495a8..db1d48a 100644 --- a/clients/js/test/_setup.ts +++ b/clients/js/test/_setup.ts @@ -23,7 +23,7 @@ import { setTransactionMessageFeePayerSigner, setTransactionMessageLifetimeUsingBlockhash, signTransactionMessageWithSigners, -} from "@solana/kit"; +} from '@solana/kit'; export type Client = { rpc: Rpc; @@ -31,27 +31,27 @@ export type Client = { }; export const createDefaultSolanaClient = (): Client => { - const rpc = createSolanaRpc("http://127.0.0.1:8899"); - const rpcSubscriptions = createSolanaRpcSubscriptions("ws://127.0.0.1:8900"); + const rpc = createSolanaRpc('http://127.0.0.1:8899'); + const rpcSubscriptions = createSolanaRpcSubscriptions('ws://127.0.0.1:8900'); return { rpc, rpcSubscriptions }; }; export const generateKeyPairSignerWithSol = async ( client: Client, - putativeLamports: bigint = 1_000_000_000n, + putativeLamports: bigint = 1_000_000_000n ) => { const signer = await generateKeyPairSigner(); await airdropFactory(client)({ recipientAddress: signer.address, lamports: lamports(putativeLamports), - commitment: "confirmed", + commitment: 'confirmed', }); return signer; }; export const createDefaultTransaction = async ( client: Client, - feePayer: TransactionSigner, + feePayer: TransactionSigner ) => { const { value: latestBlockhash } = await client.rpc .getLatestBlockhash() @@ -59,7 +59,7 @@ export const createDefaultTransaction = async ( return pipe( createTransactionMessage({ version: 0 }), (tx) => setTransactionMessageFeePayerSigner(feePayer, tx), - (tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx), + (tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx) ); }; @@ -68,7 +68,7 @@ export const signAndSendTransaction = async ( transactionMessage: BaseTransactionMessage & TransactionMessageWithFeePayer & TransactionMessageWithBlockhashLifetime, - commitment: Commitment = "confirmed", + commitment: Commitment = 'confirmed' ) => { const signedTransaction = await signTransactionMessageWithSigners(transactionMessage); @@ -83,12 +83,12 @@ export const signAndSendTransaction = async ( export const sendAndConfirmInstructions = async ( client: Client, payer: TransactionSigner, - instructions: Instruction[], + instructions: Instruction[] ) => { const signature = await pipe( await createDefaultTransaction(client, payer), (tx) => appendTransactionMessageInstructions(instructions, tx), - (tx) => signAndSendTransaction(client, tx), + (tx) => signAndSendTransaction(client, tx) ); return signature; }; diff --git a/clients/js/test/basic.test.ts b/clients/js/test/basic.test.ts index 45c6221..e393f30 100644 --- a/clients/js/test/basic.test.ts +++ b/clients/js/test/basic.test.ts @@ -1,5 +1,5 @@ -import test from "ava"; -import { generateKeyPairSigner } from "@solana/kit"; +import test from 'ava'; +import { generateKeyPairSigner } from '@solana/kit'; import { fetchRecordData, createRecord, @@ -8,14 +8,14 @@ import { createSetAuthorityInstruction, createCloseRecordInstruction, RECORD_META_DATA_SIZE, -} from "../src"; +} from '../src'; import { createDefaultSolanaClient, generateKeyPairSignerWithSol, sendAndConfirmInstructions, -} from "./_setup"; +} from './_setup'; -test("basic instructions flow", async (t) => { +test('basic instructions flow', async (t) => { const client = createDefaultSolanaClient(); const payer = await generateKeyPairSignerWithSol(client); @@ -54,13 +54,13 @@ test("basic instructions flow", async (t) => { // Verify Reallocate let rawAccount = await client.rpc - .getAccountInfo(recordAccount.address, { encoding: "base64" }) + .getAccountInfo(recordAccount.address, { encoding: 'base64' }) .send(); // Ensure RECORD_META_DATA_SIZE is defined (it is 33n), convert to Number for subarray const offset = Number(RECORD_META_DATA_SIZE); let actualData = rawAccount.value?.data?.[0] - ? Buffer.from(rawAccount.value.data[0], "base64").subarray(offset) + ? Buffer.from(rawAccount.value.data[0], 'base64').subarray(offset) : new Uint8Array([]); t.deepEqual(actualData, Buffer.from([0, 0, 0, 0, 0])); @@ -77,10 +77,10 @@ test("basic instructions flow", async (t) => { // Verify Write rawAccount = await client.rpc - .getAccountInfo(recordAccount.address, { encoding: "base64" }) + .getAccountInfo(recordAccount.address, { encoding: 'base64' }) .send(); actualData = rawAccount.value?.data?.[0] - ? Buffer.from(rawAccount.value.data[0], "base64").subarray(offset) + ? Buffer.from(rawAccount.value.data[0], 'base64').subarray(offset) : new Uint8Array([]); t.deepEqual(actualData, Buffer.from([0, 1, 2, 3, 4])); diff --git a/clients/js/test/longRecord.test.ts b/clients/js/test/longRecord.test.ts index 1aa9544..c411bbf 100644 --- a/clients/js/test/longRecord.test.ts +++ b/clients/js/test/longRecord.test.ts @@ -1,19 +1,19 @@ -import test from "ava"; -import { generateKeyPairSigner } from "@solana/kit"; +import test from 'ava'; +import { generateKeyPairSigner } from '@solana/kit'; import { createRecord, createWriteInstruction, RECORD_META_DATA_SIZE, RECORD_CHUNK_SIZE_PRE_INITIALIZE, RECORD_CHUNK_SIZE_POST_INITIALIZE, -} from "../src"; +} from '../src'; import { createDefaultSolanaClient, generateKeyPairSignerWithSol, sendAndConfirmInstructions, -} from "./_setup"; +} from './_setup'; -test("long record data flow", async (t) => { +test('long record data flow', async (t) => { const client = createDefaultSolanaClient(); const payer = await generateKeyPairSignerWithSol(client); const recordAuthority = await generateKeyPairSigner(); @@ -67,12 +67,12 @@ test("long record data flow", async (t) => { // 3. Verify Data const rawAccount = await client.rpc - .getAccountInfo(recordAccount.address, { encoding: "base64" }) + .getAccountInfo(recordAccount.address, { encoding: 'base64' }) .send(); const headerSize = Number(RECORD_META_DATA_SIZE); const actualData = rawAccount.value?.data?.[0] - ? Buffer.from(rawAccount.value.data[0], "base64").subarray(headerSize) + ? Buffer.from(rawAccount.value.data[0], 'base64').subarray(headerSize) : new Uint8Array([]); t.deepEqual(actualData, Buffer.from(recordData));