Skip to content

Commit

Permalink
[ECO-2669] Fix the aliased path resolution issues in the TypeScript S…
Browse files Browse the repository at this point in the history
…DK (#511)
xbtmatt authored Feb 1, 2025
1 parent ad47a88 commit ab1e412
Showing 30 changed files with 800 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/typescript/frontend/src/app/home/page.tsx
Original file line number Diff line number Diff line change
@@ -13,9 +13,9 @@ import { parseJSON, stringifyJSON } from "utils";
import { type DatabaseModels, toPriceFeed } from "@sdk/indexer-v2/types";
import { type DatabaseJsonType } from "@sdk/indexer-v2/types/json-types";
import { SortMarketsBy } from "@sdk/indexer-v2/types/common";
import { ORDER_BY } from "@sdk/queries";
import { getAptPrice } from "lib/queries/get-apt-price";
import { AptPriceContextProvider } from "context/AptPrice";
import { ORDER_BY } from "@sdk/indexer-v2/const";

export const revalidate = 2;

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fetchMarkets } from "@/queries/home";
import { fetchUserLiquidityPools } from "@/queries/pools";
import type { SortMarketsBy } from "@sdk/indexer-v2/types/common";
import { toOrderBy } from "@sdk/queries";
import { toOrderBy } from "@sdk/indexer-v2/const";
import { MARKETS_PER_PAGE } from "lib/queries/sorting/const";
import { stringifyJSON } from "utils";

2 changes: 1 addition & 1 deletion src/typescript/frontend/src/app/stats/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { fetchMarkets, fetchPriceFeedWithMarketState } from "@/queries/home";
import { toPriceFeed } from "@sdk/indexer-v2/types";
import { SortMarketsBy } from "@sdk/indexer-v2/types/common";
import { ORDER_BY } from "@sdk/queries";
import StatsPageComponent from "./StatsPage";
import { compareNumber, getAptosClient } from "@sdk/utils";
import { RegistryView } from "@/contract-apis";
import { toRegistryView } from "@sdk-types";
import { ORDER_BY } from "@sdk/indexer-v2/const";

export const revalidate = 60;
export const dynamic = "force-static";
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import { HEADERS, MOBILE_HEADERS } from "./constants";

import { getEmptyListTr } from "utils";
import type { SortByPageQueryParams } from "lib/queries/sorting/types";
import type { OrderByStrings } from "@sdk/queries/const";
import type { OrderByStrings } from "@sdk/indexer-v2/const";
import useElementDimensions from "@hooks/use-element-dimensions";
import { type PoolsData } from "../../ClientPoolsPage";

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type OrderByStrings } from "@sdk/queries/const";
import { type OrderByStrings } from "@sdk/indexer-v2/const";
import { toMarketDataSortByHomePage, type SortByPageQueryParams } from "./types";
import { safeParsePageWithDefault } from "lib/routes/home-page-params";
import { DEFAULT_SORT_BY, type SortMarketsBy } from "@sdk/indexer-v2/types/common";
2 changes: 1 addition & 1 deletion src/typescript/frontend/src/lib/routes/home-page-params.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { toOrderBy } from "@sdk/queries/const";
import { toOrderBy } from "@sdk/indexer-v2/const";
import { type HomePageSearchParams } from "lib/queries/sorting/query-params";
import { toMarketDataSortByHomePage } from "lib/queries/sorting/types";

2 changes: 1 addition & 1 deletion src/typescript/frontend/src/types/server-only.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
declare module "server-only";
declare module "server-only" {}
671 changes: 668 additions & 3 deletions src/typescript/pnpm-lock.yaml

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion src/typescript/sdk/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
// cspell:word tsup

module.exports = {
env: {
browser: true,
es2021: true,
jest: true,
node: true,
},
ignorePatterns: ["dist/**", "node_modules/**", ".eslintrc.js", "jest.config.js"],
ignorePatterns: [
"dist/**",
"node_modules/**",
".eslintrc.js",
"jest.config.js",
"tsup.config.ts",
],
extends: [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
44 changes: 40 additions & 4 deletions src/typescript/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"dependencies": {
"@aptos-labs/ts-sdk": "1.27.1",
"@econia-labs/emojicoin-sdk": "0.3.0-rc.7",
"@keyvhq/core": "^2.1.1",
"@noble/hashes": "^1.5.0",
"@supabase/postgrest-js": "^1.16.2",
@@ -38,17 +39,52 @@
"tree-kill": "^1.2.2",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"tsup": "^8.3.6",
"typescript": "5.6.2",
"ws": "^8.18.0"
},
"engines": {
"node": ">=v20.12.2"
},
"exports": {
".": "./src/*"
".": {
"source": "./src/index.ts",
"require": {
"types": "./dist/common/index.d.ts",
"default": "./dist/common/index.js"
},
"import": {
"types": "./dist/esm/index.d.mts",
"default": "./dist/esm/index.mjs"
}
},
"./client": {
"source": "./src/client/index.ts",
"require": {
"types": "./dist/common/client/index.d.ts",
"default": "./dist/common/client/index.js"
},
"import": {
"types": "./dist/esm/client/index.d.mts",
"default": "./dist/esm/client/index.mjs"
}
},
"./indexer-v2": {
"source": "./src/indexer-v2/index.ts",
"require": {
"types": "./dist/common/indexer-v2/index.d.ts",
"default": "./dist/common/indexer-v2/index.js"
},
"import": {
"types": "./dist/esm/indexer-v2/index.d.mts",
"default": "./dist/esm/indexer-v2/index.mjs"
}
},
"./package.json": "./package.json"
},
"files": [
"dist"
"dist",
"src"
],
"homepage": "https://github.com/econia-labs/emojicoin-dot-fun#readme",
"license": "Apache-2.0",
@@ -62,7 +98,7 @@
"build": "tsc",
"build:debug": "BUILD_DEBUG=true pnpm run build",
"build:no-checks": "tsc --skipLibCheck",
"build:publish": "tsc -p tsconfig.publish.json",
"build:publish": "tsup",
"check": "tsc -p tests/tsconfig.json --noEmit",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
"e2e:testnet": "pnpm load-test-env -v NO_TEST_SETUP=true -- pnpm jest tests/e2e/queries/testnet",
@@ -81,6 +117,6 @@
"test:unit": "pnpm jest tests/unit",
"verify-processor-data": "pnpm dotenv -e ../.env -- pnpm tsx --conditions=react-server src/scripts/verify-processor-data.ts"
},
"typings": "dist/index.d.ts",
"typings": "dist/common/index.d.ts",
"version": "0.3.0"
}
18 changes: 15 additions & 3 deletions src/typescript/sdk/src/client/emojicoin-client.ts
Original file line number Diff line number Diff line change
@@ -154,6 +154,7 @@ export class EmojicoinClient {

constructor(args?: {
aptos?: Aptos;
aptosApiKey?: string;
integrator?: AccountAddressInput;
integratorFeeRateBPs?: bigint | number;
minOutputAmount?: bigint | number;
@@ -165,13 +166,24 @@ export class EmojicoinClient {
integratorFeeRateBPs = 0,
minOutputAmount = 1n,
alwaysWaitForIndexer = false,
aptosApiKey,
} = args ?? {};
const clientConfig = {
...aptos.config.clientConfig,
// If the Aptos API key is passed in, use it, otherwise, use the default one set by
// environment variables.
...(aptosApiKey
? {
API_KEY: aptosApiKey,
}
: APTOS_CONFIG),
};
// Create a client that always uses the static API_KEY config options.
const hardCodedConfig = new AptosConfig({
const aptosConfig = new AptosConfig({
...aptos.config,
clientConfig: { ...aptos.config.clientConfig, ...APTOS_CONFIG },
clientConfig,
});
this.aptos = new Aptos(hardCodedConfig);
this.aptos = new Aptos(aptosConfig);
this.integrator = AccountAddress.from(integrator);
this.integratorFeeRateBPs = Number(integratorFeeRateBPs);
this.minOutputAmount = BigInt(minOutputAmount);
2 changes: 2 additions & 0 deletions src/typescript/sdk/src/const.ts
Original file line number Diff line number Diff line change
@@ -62,6 +62,8 @@ const serverKeys: Record<Network, string | undefined> = {
const clientApiKey = clientKeys[APTOS_NETWORK];
const serverApiKey = serverKeys[APTOS_NETWORK];

// If the server api key is available, use it. If it's not available, that means the runtime
// is in a client-side context, and it should use the API key for client-side queries.
export const getAptosApiKey = () => serverApiKey ?? clientApiKey;

// Select the API key from the list of env API keys. This means we don't have to change the env
File renamed without changes.
1 change: 1 addition & 0 deletions src/typescript/sdk/src/indexer-v2/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./const";
export * from "./json-bigint";
export * from "./mini-processor";
export * from "./queries";
2 changes: 1 addition & 1 deletion src/typescript/sdk/src/indexer-v2/queries/app/arena.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ if (process.env.NODE_ENV !== "test") {
require("server-only");
}

import { ORDER_BY } from "../../../queries";
import { TableName } from "../../types/json-types";
import { postgrest } from "../client";
import { queryHelperSingle } from "../utils";
@@ -12,6 +11,7 @@ import {
toArenaPositionsModel,
toMarketStateModel,
} from "../../types";
import { ORDER_BY } from "../../const";

const selectMelee = () =>
postgrest
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import {
toMarketRegistrationEventModel,
toSwapEventModel,
} from "../../types";
import { LIMIT } from "../../../queries";
import { LIMIT } from "../../const";
import type { MarketStateQueryArgs } from "../../types/common";
import { postgrest, toQueryArray } from "../client";
import { TableName } from "../../types/json-types";
2 changes: 1 addition & 1 deletion src/typescript/sdk/src/indexer-v2/queries/app/home.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ if (process.env.NODE_ENV !== "test") {
require("server-only");
}

import { LIMIT, ORDER_BY } from "../../../queries/const";
import { LIMIT, ORDER_BY } from "../../const";
import { DEFAULT_SORT_BY, type MarketStateQueryArgs } from "../../types/common";
import { type DatabaseJsonType, TableName } from "../../types/json-types";
import { postgrest, toQueryArray } from "../client";
2 changes: 1 addition & 1 deletion src/typescript/sdk/src/indexer-v2/queries/app/market.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ if (process.env.NODE_ENV !== "test") {
require("server-only");
}

import { LIMIT, ORDER_BY } from "../../../queries";
import { LIMIT, ORDER_BY } from "../../const";
import { type AnyNumberString } from "../../../types";
import { TableName } from "../../types/json-types";
import { postgrest, toQueryArray } from "../client";
2 changes: 1 addition & 1 deletion src/typescript/sdk/src/indexer-v2/queries/app/pools.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type AccountAddressInput, type Account } from "@aptos-labs/ts-sdk";
import { LIMIT, ORDER_BY } from "../../../queries";
import { LIMIT, ORDER_BY } from "../../const";
import { toAccountAddressString } from "../../../utils";
import { toUserPoolsRPCResponse } from "../../types";
import { postgrest } from "../client";
2 changes: 1 addition & 1 deletion src/typescript/sdk/src/indexer-v2/queries/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Account, type AccountAddressInput } from "@aptos-labs/ts-sdk";
import { LIMIT, ORDER_BY, type OrderBy } from "../../../queries";
import { LIMIT, ORDER_BY, type OrderBy } from "../../const";
import { type AnyNumberString } from "../../../types";
import {
toChatEventModel,
2 changes: 1 addition & 1 deletion src/typescript/sdk/src/indexer-v2/types/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Period } from "../../const";
import { type OrderBy } from "../../queries/const";
import { type OrderBy } from "../const";
import { type AnyNumberString } from "../../types";

export enum SortMarketsBy {
1 change: 0 additions & 1 deletion src/typescript/sdk/src/queries/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/typescript/sdk/src/types/server-only.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
declare module "server-only";
declare module "server-only" {}
2 changes: 1 addition & 1 deletion src/typescript/sdk/tests/e2e/emoji-data.test.ts
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ import { getFundedAccount } from "../utils/test-accounts";
import TestHelpers from "../utils/helpers";
import { waitForEmojicoinIndexer } from "../../src/indexer-v2/queries";
import { fetchMarketRegistrationEvents } from "./queries";
import { ORDER_BY } from "../../src/queries";
import { ORDER_BY } from "../../src/indexer-v2/const";

jest.setTimeout(10000);

Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@ import { EXACT_TRANSITION_INPUT_AMOUNT } from "../../../utils/helpers";
import { getFundedAccounts } from "../../../utils/test-accounts";
import { waitForEmojicoinIndexer } from "../../../../src/indexer-v2/queries/utils";
import { fetchMarkets, fetchUserLiquidityPools } from "../../../../src/indexer-v2/queries";
import { LIMIT } from "../../../../src/queries";
import { EmojicoinClient } from "../../../../src/client/emojicoin-client";
import { LIMIT } from "../../../../src/indexer-v2/const";

jest.setTimeout(20000);

3 changes: 1 addition & 2 deletions src/typescript/sdk/tests/e2e/queries/liquidity-pools.test.ts
Original file line number Diff line number Diff line change
@@ -4,12 +4,11 @@ import { type TypeTag, type UserTransactionResponse } from "@aptos-labs/ts-sdk";
import { maxBigInt, type SymbolEmoji } from "../../../src";
import TestHelpers, { EXACT_TRANSITION_INPUT_AMOUNT } from "../../utils/helpers";
import { getFundedAccounts } from "../../utils/test-accounts";

import { waitForEmojicoinIndexer } from "../../../src/indexer-v2/queries/utils";
import { ProvideLiquidity, Swap } from "@/contract-apis/emojicoin-dot-fun";
import { getAptosClient } from "../../utils";
import { fetchMarkets, fetchUserLiquidityPools } from "../../../src/indexer-v2/queries";
import { LIMIT } from "../../../src/queries";
import { LIMIT } from "../../../src/indexer-v2/const";

jest.setTimeout(20000);

2 changes: 1 addition & 1 deletion src/typescript/sdk/tests/e2e/queries/price-feed.test.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ import {
} from "../../../src";
import { calculateDeltaPercentageForQ64s, toPriceFeed } from "../../../src/indexer-v2/types";
import { SortMarketsBy } from "../../../src/indexer-v2/types/common";
import { ORDER_BY } from "../../../src/queries";
import { ORDER_BY } from "../../../src/indexer-v2/const";
import Big from "big.js";

jest.setTimeout(30000);
2 changes: 1 addition & 1 deletion src/typescript/sdk/tests/e2e/queries/sorted/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { compareBigInt, sortBigIntArrays } from "../../../../src";
import { LIMIT } from "../../../../src/indexer-v2/const";
import { postgrest, queryHelper } from "../../../../src/indexer-v2/queries";
import { type MarketStateModel, toMarketStateModel } from "../../../../src/indexer-v2/types";
import { TableName } from "../../../../src/indexer-v2/types/json-types";
import { LIMIT } from "../../../../src/queries";

// differences there are in the marketIDs, values and sort order.
type SortableResults = {
5 changes: 3 additions & 2 deletions src/typescript/sdk/tsconfig.json
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
"allowJs": true,
"allowSyntheticDefaultImports": true,
"declaration": true,
"declarationDir": "dist",
"declarationDir": "types",
"declarationMap": true,
"esModuleInterop": true,
"experimentalDecorators": true,
@@ -43,6 +43,7 @@
"node_modules"
],
"include": [
"src"
"src",
"tsup.config.ts"
]
}
42 changes: 42 additions & 0 deletions src/typescript/sdk/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// cspell:word tsup

import { defineConfig } from "tsup";
import type { Options, Format } from "tsup";

// Ensure that these option fields are not undefined.
type MandatoryOptions = Options & {
outDir: string;
format: Format | Format[];
};

// Default config, used as a base template
const DEFAULT_CONFIG: Options = {
bundle: true,
clean: true,
dts: true,
minify: true,
entry: ["src/index.ts"], // Include everything exported from src/index.ts.
skipNodeModulesBundle: true,
sourcemap: true,
splitting: true,
target: "es2020",
platform: "node",
};

// Common.js config
const COMMON_CONFIG: MandatoryOptions = {
...DEFAULT_CONFIG,
entry: ["src/index.ts", "src/indexer-v2/index.ts", "src/client/index.ts"],
format: "cjs",
outDir: "dist/common",
};

// ESM config
const ESM_CONFIG: MandatoryOptions = {
...DEFAULT_CONFIG,
entry: ["src/**/*.ts"],
format: "esm",
outDir: "dist/esm",
};

export default defineConfig([COMMON_CONFIG, ESM_CONFIG]);

0 comments on commit ab1e412

Please sign in to comment.