Skip to content

Commit

Permalink
feat: Make record_v2 and utils tree-shakeable
Browse files Browse the repository at this point in the history
  • Loading branch information
letehaha authored and dr497 committed May 22, 2024
1 parent 61f2077 commit fb6dcac
Show file tree
Hide file tree
Showing 49 changed files with 1,000 additions and 794 deletions.
109 changes: 99 additions & 10 deletions js/package-lock.json

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

2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.5",
"@solana/web3.js": "^1.87.6",
"@tsconfig/recommended": "^1.0.3",
"@types/bn.js": "^5.1.5",
"@types/bs58": "^4.0.4",
Expand All @@ -58,6 +57,7 @@
"jest": "^29.7.0",
"mathjs": "^12.4.2",
"prettier": "^3.1.0",
"rollup-plugin-multi-input": "^1.4.1",
"rollup-plugin-visualizer": "^5.12.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
Expand Down
18 changes: 15 additions & 3 deletions js/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,31 @@ import { nodeResolve } from "@rollup/plugin-node-resolve";
import replace from "@rollup/plugin-replace";
import babel from "@rollup/plugin-babel";
import { visualizer } from "rollup-plugin-visualizer";
import multiInput from 'rollup-plugin-multi-input';

/**
* @type {import('rollup').RollupOptions}
*/
export default {
input: "src/index.ts",
input: [
"src/index.ts",
"src/record_v2/**/*.ts",
"src/utils/**/*.ts",
],
treeshake: true,
output: [
{
file: "dist/index.mjs",
dir: "dist/",
format: "esm",
sourcemap: true,
entryFileNames: '[name].mjs',
exports: "named"
},
{ file: "dist/index.cjs", format: "cjs", sourcemap: true },
{ dir: "dist/", format: "cjs", sourcemap: true },
],
external: ["@solana/web3.js"],
plugins: [
multiInput.default(),
typescript(),
commonjs(),
babel({ babelHelpers: "bundled" }),
Expand Down
16 changes: 7 additions & 9 deletions js/src/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,20 @@ import {
METAPLEX_ID,
PYTH_PULL_FEEDS,
} from "./constants";
import {
check,
getDomainKeySync,
getHashedNameSync,
getNameAccountKeySync,
getPythFeedAccountKey,
getReverseKeySync,
} from "./utils";
import { check } from "./utils/check";
import { getDomainKeySync } from "./utils/getDomainKeySync";
import { getReverseKeySync } from "./utils/getReverseKeySync";
import { getHashedNameSync } from "./utils/getHashedNameSync";
import { getNameAccountKeySync } from "./utils/getNameAccountKeySync";
import { getPythFeedAccountKey } from "./utils/getPythFeedAccountKey";
import {
TOKEN_PROGRAM_ID,
getAssociatedTokenAddressSync,
createAssociatedTokenAccountIdempotentInstruction,
} from "@solana/spl-token";
import { serializeRecord, serializeSolRecord } from "./record";
import { Record, RecordVersion } from "./types/record";
import { serializeRecordV2Content } from "./record_v2";
import { serializeRecordV2Content } from "./record_v2/serializeRecordV2Content";
import {
editRecord,
allocateAndPostRecord,
Expand Down
3 changes: 2 additions & 1 deletion js/src/custom-bg.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { PublicKey } from "@solana/web3.js";
import { CUSTOM_BG_TLD } from "./constants";
import { CustomBg } from "./types/custom-bg";
import { getHashedNameSync, getNameAccountKeySync } from "./utils";
import { getHashedNameSync } from "./utils/getHashedNameSync";
import { getNameAccountKeySync } from "./utils/getNameAccountKeySync";
import { InvalidCustomBgError } from "./error";

const DEGEN_POET_KEY = new PublicKey(
Expand Down
8 changes: 3 additions & 5 deletions js/src/devnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ import {
NoAccountDataError,
PythFeedNotFoundError,
} from "./error";
import {
deserializeReverse,
getHashedNameSync,
getPythFeedAccountKey,
} from "./utils";
import { deserializeReverse } from "./utils/deserializeReverse";
import { getHashedNameSync } from "./utils/getHashedNameSync";
import { getPythFeedAccountKey } from "./utils/getPythFeedAccountKey";
import { PYTH_PULL_FEEDS } from "./constants";

const constants = {
Expand Down
12 changes: 5 additions & 7 deletions js/src/favorite-domain.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { Buffer } from "buffer";
import { deserialize } from "borsh";
import {
deserializeReverse,
getReverseKeyFromDomainKey,
reverseLookup,
} from "./utils";
import { PublicKey, Connection } from "@solana/web3.js";
import { FavouriteDomainNotFoundError } from "./error";
import { getDomainMint } from "./nft/name-tokenizer";
import {
AccountLayout,
getAssociatedTokenAddressSync,
} from "@solana/spl-token";
import { deserializeReverse } from "./utils/deserializeReverse";
import { getReverseKeyFromDomainKey } from "./utils/getReverseKeyFromDomainKey";
import { reverseLookup } from "./utils/reverseLookup";
import { FavouriteDomainNotFoundError } from "./error";
import { getDomainMint } from "./nft/name-tokenizer";
import { NameRegistryState } from "./state";

export const NAME_OFFERS_ID = new PublicKey(
Expand Down
29 changes: 27 additions & 2 deletions js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
export * from "./bindings";
export * from "./state";
export * from "./twitter_bindings";
export * from "./utils";

export * from "./utils/check";
export * from "./utils/deserializeReverse";
export * from "./utils/findSubdomains";
export * from "./utils/getAllDomains";
export * from "./utils/getAllRegisteredDomains";
export * from "./utils/getDomainKeySync";
export * from "./utils/getDomainKeysWithReverses";
export * from "./utils/getDomainPriceFromName";
export * from "./utils/getHashedNameSync";
export * from "./utils/getNameAccountKeySync";
export * from "./utils/getPythFeedAccountKey";
export * from "./utils/getReverseKeyFromDomainKey";
export * from "./utils/getReverseKeySync";
export * from "./utils/getTokenizedDomains";
export * from "./utils/reverseLookup";
export * from "./utils/reverseLookupBatch";

export * from "./instructions";
export * from "./nft";
export { getDomainMint } from "./nft/name-tokenizer";
Expand All @@ -15,6 +32,14 @@ export * from "./resolve";
export * from "./deprecated/utils";
export * from "./error";
export * from "./custom-bg";
export * from "./record_v2";

export * from "./record_v2/const";
export * from "./record_v2/deserializeRecordV2Content";
export * from "./record_v2/serializeRecordV2Content";
export * from "./record_v2/getRecordV2";
export * from "./record_v2/getRecordV2Key";
export * from "./record_v2/getMultipleRecordsV2";
export * from "./record_v2/verifyRightOfAssociation";
export * from "./record_v2/utils";

export * from "./devnet";
16 changes: 8 additions & 8 deletions js/src/record.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { RECORD_V1_SIZE, Record, RecordVersion } from "./types/record";
import { Connection, PublicKey } from "@solana/web3.js";
import { getDomainKeySync } from "./utils";
import { NameRegistryState } from "./state";
import { Buffer } from "buffer";
import { encode as bs58Encode } from "bs58";
import { Connection, PublicKey } from "@solana/web3.js";
import { ed25519 } from "@noble/curves/ed25519";
import { bech32 } from "@scure/base";
import { encode as encodePunycode, decode as decodePunnyCode } from "punycode";
import {
isValid as isValidIp,
fromByteArray as ipFromByteArray,
parse as parseIp,
} from "ipaddr.js";
import { encode as encodePunycode, decode as decodePunnyCode } from "punycode";
import { check } from "./utils";
import { ed25519 } from "@noble/curves/ed25519";
import { bech32 } from "@scure/base";
import { RECORD_V1_SIZE, Record, RecordVersion } from "./types/record";
import { getDomainKeySync } from "./utils/getDomainKeySync";
import { NameRegistryState } from "./state";
import { check } from "./utils/check";
import {
InvalidAAAARecordError,
InvalidARecordError,
Expand Down
Loading

0 comments on commit fb6dcac

Please sign in to comment.