Sfoglia il codice sorgente

fix(price-service-client): fixed build

benduran 4 settimane fa
parent
commit
36e72e7c04

+ 3 - 3
lazer/contracts/sui/sdk/js/package.json

@@ -15,17 +15,17 @@
   "exports": {
     "./client": {
       "import": "./dist/esm/client.js",
-      "types": "./dist/cjs/client.d.ts",
+      "types": "./dist/esm/client.d.ts",
       "require": "./dist/cjs/client.js"
     },
     "./examples/fetch-and-verify-update": {
       "import": "./dist/esm/examples/fetch-and-verify-update.js",
-      "types": "./dist/cjs/examples/fetch-and-verify-update.d.ts",
+      "types": "./dist/esm/examples/fetch-and-verify-update.d.ts",
       "require": "./dist/cjs/examples/fetch-and-verify-update.js"
     },
     "./src/client": {
       "import": "./dist/esm/src/client.js",
-      "types": "./dist/cjs/src/client.d.ts",
+      "types": "./dist/esm/src/client.d.ts",
       "require": "./dist/cjs/src/client.js"
     },
     "./package.json": "./package.json"

+ 12 - 6
pnpm-lock.yaml

@@ -2424,33 +2424,39 @@ importers:
         specifier: ^8.6.0
         version: 8.18.1(bufferutil@4.0.9)(utf-8-validate@6.0.3)
     devDependencies:
+      '@cprussin/tsconfig':
+        specifier: 'catalog:'
+        version: 3.1.2(typescript@5.9.3)
       '@types/jest':
         specifier: ^29.4.0
         version: 29.5.14
+      '@types/node':
+        specifier: 'catalog:'
+        version: 22.14.0
       '@types/yargs':
         specifier: ^17.0.10
         version: 17.0.33
       '@typescript-eslint/eslint-plugin':
         specifier: ^5.21.0
-        version: 5.62.0(@typescript-eslint/parser@5.62.0(eslint@8.56.0)(typescript@4.9.5))(eslint@8.56.0)(typescript@4.9.5)
+        version: 5.62.0(@typescript-eslint/parser@5.62.0(eslint@8.56.0)(typescript@5.9.3))(eslint@8.56.0)(typescript@5.9.3)
       '@typescript-eslint/parser':
         specifier: ^5.21.0
-        version: 5.62.0(eslint@8.56.0)(typescript@4.9.5)
+        version: 5.62.0(eslint@8.56.0)(typescript@5.9.3)
       eslint:
         specifier: ^8.14.0
         version: 8.56.0
       jest:
         specifier: ^29.4.0
-        version: 29.7.0(@types/node@22.14.0)(ts-node@10.9.2(@swc/core@1.13.2)(@types/node@22.14.0)(typescript@4.9.5))
+        version: 29.7.0(@types/node@22.14.0)(ts-node@10.9.2(@swc/core@1.13.2)(@types/node@22.14.0)(typescript@5.9.3))
       prettier:
         specifier: 'catalog:'
         version: 3.5.3
       ts-jest:
         specifier: ^29.0.5
-        version: 29.3.1(@babel/core@7.27.1)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.27.1))(jest@29.7.0(@types/node@22.14.0)(ts-node@10.9.2(@swc/core@1.13.2)(@types/node@22.14.0)(typescript@4.9.5)))(typescript@4.9.5)
+        version: 29.3.1(@babel/core@7.27.1)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.27.1))(esbuild@0.25.9)(jest@29.7.0(@types/node@22.14.0)(ts-node@10.9.2(@swc/core@1.13.2)(@types/node@22.14.0)(typescript@5.9.3)))(typescript@5.9.3)
       typescript:
-        specifier: ^4.6.3
-        version: 4.9.5
+        specifier: 'catalog:'
+        version: 5.9.3
       yargs:
         specifier: ^17.4.1
         version: 17.7.2

+ 41 - 9
price_service/client/js/package.json

@@ -7,8 +7,8 @@
     "name": "Pyth Data Association"
   },
   "homepage": "https://pyth.network",
-  "main": "./dist/cjs/index.js",
-  "types": "./dist/esm/index.d.mts",
+  "main": "./cjs/index.js",
+  "types": "./cjs/index.d.ts",
   "files": [
     "lib/**/*",
     "dist/**/*"
@@ -39,7 +39,9 @@
   ],
   "license": "Apache-2.0",
   "devDependencies": {
+    "@cprussin/tsconfig": "catalog:",
     "@types/jest": "^29.4.0",
+    "@types/node": "catalog:",
     "@types/yargs": "^17.0.10",
     "@typescript-eslint/eslint-plugin": "^5.21.0",
     "@typescript-eslint/parser": "^5.21.0",
@@ -47,7 +49,7 @@
     "jest": "^29.4.0",
     "prettier": "catalog:",
     "ts-jest": "^29.0.5",
-    "typescript": "^4.6.3",
+    "typescript": "catalog:",
     "yargs": "^17.4.1"
   },
   "dependencies": {
@@ -64,13 +66,43 @@
     "pnpm": ">=10.19.0"
   },
   "packageManager": "pnpm@10.19.0",
-  "module": "./dist/esm/index.mjs",
+  "module": "./esm/index.js",
   "exports": {
-    ".": "./src/index.ts",
-    "./examples/PriceServiceClient": "./src/examples/PriceServiceClient.ts",
-    "./PriceServiceConnection": "./src/PriceServiceConnection.ts",
-    "./ResillientWebSocket": "./src/ResillientWebSocket.ts",
-    "./utils": "./src/utils.ts",
+    "./PriceServiceConnection": {
+      "import": "./dist/esm/PriceServiceConnection.js",
+      "types": "./dist/esm/PriceServiceConnection.d.ts",
+      "require": "./dist/cjs/PriceServiceConnection.js"
+    },
+    "./ResillientWebSocket": {
+      "import": "./dist/esm/ResillientWebSocket.js",
+      "types": "./dist/esm/ResillientWebSocket.d.ts",
+      "require": "./dist/cjs/ResillientWebSocket.js"
+    },
+    "./__tests__/connection.e2e.test": {
+      "import": "./dist/esm/__tests__/connection.e2e.test.js",
+      "types": "./dist/esm/__tests__/connection.e2e.test.d.ts",
+      "require": "./dist/cjs/__tests__/connection.e2e.test.js"
+    },
+    "./examples/PriceServiceClient": {
+      "import": "./dist/esm/examples/PriceServiceClient.js",
+      "types": "./dist/esm/examples/PriceServiceClient.d.ts",
+      "require": "./dist/cjs/examples/PriceServiceClient.js"
+    },
+    ".": {
+      "import": "./dist/esm/index.js",
+      "types": "./dist/esm/index.d.ts",
+      "require": "./dist/cjs/index.js"
+    },
+    "./types": {
+      "import": "./dist/esm/types.js",
+      "types": "./dist/esm/types.d.ts",
+      "require": "./dist/cjs/types.js"
+    },
+    "./utils": {
+      "import": "./dist/esm/utils.js",
+      "types": "./dist/esm/utils.d.ts",
+      "require": "./dist/cjs/utils.js"
+    },
     "./package.json": "./package.json"
   }
 }

+ 15 - 14
price_service/client/js/src/PriceServiceConnection.ts

@@ -1,46 +1,47 @@
-import { HexString, PriceFeed } from "@pythnetwork/price-service-sdk";
-import axios, { AxiosInstance } from "axios";
+import { type HexString, PriceFeed } from "@pythnetwork/price-service-sdk";
+import axios, { type AxiosInstance } from "axios";
 import axiosRetry from "axios-retry";
 import * as WebSocket from "isomorphic-ws";
-import { Logger } from "ts-log";
+import { type Logger } from "ts-log";
 import { ResilientWebSocket } from "./ResillientWebSocket";
 import { makeWebsocketUrl, removeLeading0xIfExists } from "./utils";
+import type { Nullish } from "./types";
 
 export type DurationInMs = number;
 
 export type PriceFeedRequestConfig = {
   /* Optional verbose to request for verbose information from the service */
-  verbose?: boolean;
+  verbose?: Nullish<boolean>;
   /* Optional binary to include the price feeds binary update data */
-  binary?: boolean;
+  binary?: Nullish<boolean>;
   /* Optional config for the websocket subscription to receive out of order updates */
-  allowOutOfOrder?: boolean;
+  allowOutOfOrder?: Nullish<boolean>;
 };
 
 export type PriceServiceConnectionConfig = {
   /* Timeout of each request (for all of retries). Default: 5000ms */
-  timeout?: DurationInMs;
+  timeout?: Nullish<DurationInMs>;
   /**
    * Number of times a HTTP request will be retried before the API returns a failure. Default: 3.
    *
    * The connection uses exponential back-off for the delay between retries. However,
    * it will timeout regardless of the retries at the configured `timeout` time.
    */
-  httpRetries?: number;
+  httpRetries?: Nullish<number>;
   /* Optional logger (e.g: console or any logging library) to log internal events */
-  logger?: Logger;
+  logger?: Nullish<Logger>;
   /* Deprecated: please use priceFeedRequestConfig.verbose instead */
-  verbose?: boolean;
+  verbose?: Nullish<boolean>;
   /* Configuration for the price feed requests */
-  priceFeedRequestConfig?: PriceFeedRequestConfig;
+  priceFeedRequestConfig?: Nullish<PriceFeedRequestConfig>;
 };
 
 type ClientMessage = {
   type: "subscribe" | "unsubscribe";
   ids: HexString[];
-  verbose?: boolean;
-  binary?: boolean;
-  allow_out_of_order?: boolean;
+  verbose?: Nullish<boolean>;
+  binary?: Nullish<boolean>;
+  allow_out_of_order?: Nullish<boolean>;
 };
 
 type ServerResponse = {

+ 5 - 3
price_service/client/js/src/__tests__/connection.e2e.test.ts

@@ -1,5 +1,5 @@
 import {
-  DurationInMs,
+  type DurationInMs,
   Price,
   PriceFeed,
   PriceFeedMetadata,
@@ -98,7 +98,7 @@ describe("Test http endpoints", () => {
 
     const publishTime10SecAgo = Math.floor(new Date().getTime() / 1000) - 10;
     const [vaa, vaaPublishTime] = await connection.getVaa(
-      ids[0],
+      ids[0] ?? '',
       publishTime10SecAgo,
     );
 
@@ -220,7 +220,9 @@ describe("Test websocket endpoints", () => {
 
       // Check for out of order slots but don't assert on it since it's not stable
       for (let i = 1; i < observedSlots.length; i++) {
-        if (observedSlots[i] < observedSlots[i - 1]) {
+        const curr = observedSlots[i];
+        const prev = observedSlots[i - 1];
+        if (curr !== undefined && prev !== undefined && curr < prev) {
           // Out of order slot found, but we don't assert on it
           break;
         }

+ 1 - 0
price_service/client/js/src/types.ts

@@ -0,0 +1 @@
+export type Nullish<T> = T | null | undefined;

+ 10 - 0
price_service/client/js/tsconfig.build.json

@@ -0,0 +1,10 @@
+{
+  "extends": "./tsconfig.json",
+  "compilerOptions": {
+    "declaration": true,
+    "incremental": false,
+    "noEmit": false,
+    "verbatimModuleSyntax": false
+  },
+  "exclude": ["dist", "node_modules"]
+}

+ 3 - 11
price_service/client/js/tsconfig.json

@@ -1,16 +1,8 @@
 {
-  "extends": "../../../tsconfig.base.json",
+  "extends": "@cprussin/tsconfig/nextjs.json",
   "compilerOptions": {
-    "target": "esnext",
-    "module": "commonjs",
-    "declaration": true,
-    "composite": true,
-    "declarationMap": true,
-    "incremental": true,
-    "outDir": "./lib",
-    "strict": true,
-    "rootDir": "src/"
+    "types": ["jest", "node"]
   },
   "include": ["src"],
-  "exclude": ["node_modules", "**/__tests__/*"]
+  "exclude": ["dist", "node_modules"]
 }