Skip to content

Commit

Permalink
fix: many type fixes, eslint bump and config migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jaybuidl committed Oct 10, 2024
1 parent f897258 commit 34fb467
Show file tree
Hide file tree
Showing 15 changed files with 816 additions and 458 deletions.
21 changes: 12 additions & 9 deletions eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
"main": ".eslintrc.js",
"license": "MIT",
"dependencies": {
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"@typescript-eslint/utils": "^5.62.0",
"eslint-config-prettier": "^8.10.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.29.1",
"@typescript-eslint/eslint-plugin": "^8.8.1",
"@typescript-eslint/parser": "^8.8.1",
"@typescript-eslint/utils": "^8.8.1",
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^5.2.0",
"eslint-plugin-security": "^1.7.1",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-security": "^3.0.1",
"eslint-utils": "^3.0.0"
},
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.12.0",
"globals": "^15.11.0",
"typescript": "^5.3.3"
},
"peerDependencies": {
Expand Down
1 change: 1 addition & 0 deletions kleros-sdk/src/dataMappings/actions/callAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const callAction = async (mapping: AbiCallMapping, alchemyApiKey: string)
const data = await publicClient.readContract({
address,
abi: [parsedAbi],
functionName: "TODO: FIX ME",
args,
});

Expand Down
9 changes: 5 additions & 4 deletions kleros-sdk/src/dataMappings/actions/eventAction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { parseAbiItem } from "viem";
import { type AbiEvent } from "abitype";
import { AbiEventMapping } from "src/dataMappings/utils/actionTypes";
import { createResultObject } from "src/dataMappings/utils/createResultObject";
import { configureSDK, getPublicClient } from "src/sdk";
Expand All @@ -8,17 +9,17 @@ export const eventAction = async (mapping: AbiEventMapping, alchemyApiKey: strin
const publicClient = getPublicClient();

const { abi: source, address, eventFilter, seek, populate } = mapping;
const parsedAbi = typeof source === "string" ? parseAbiItem(source) : source;
const parsedAbi = parseAbiItem(source) as AbiEvent;

const filter = await publicClient.createEventFilter({
address,
event: parsedAbi,
args: eventFilter.args,
fromBlock: eventFilter.fromBlock,
toBlock: eventFilter.toBlock,
fromBlock: eventFilter.fromBlock ? BigInt(eventFilter.fromBlock.toString()) : undefined,
toBlock: eventFilter.toBlock ? BigInt(eventFilter.toBlock.toString()) : undefined,
});

const contractEvent = await publicClient.getFilterLogs({ filter: filter as any });
const contractEvent = await publicClient.getFilterLogs({ filter });
const eventData = contractEvent[0].args;

return createResultObject(eventData, seek, populate);
Expand Down
2 changes: 1 addition & 1 deletion kleros-sdk/src/dataMappings/executeActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const executeAction = async (
mapping: ActionMapping,
context: Record<string, unknown> = {}
): Promise<ActionResult> => {
mapping = replacePlaceholdersWithValues(mapping, context);
mapping = replacePlaceholdersWithValues(mapping, context) as ActionMapping;

switch (mapping.type) {
case "graphql":
Expand Down
6 changes: 4 additions & 2 deletions kleros-sdk/src/dataMappings/utils/actionTypes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { type Address } from "viem";

export type JsonMapping = {
type: string;
value: object;
Expand All @@ -17,7 +19,7 @@ export interface SubgraphMapping {
export type AbiCallMapping = {
type: string;
abi: string;
address: string;
address: Address;
args: any[];
seek: string[];
populate: string[];
Expand All @@ -26,7 +28,7 @@ export type AbiCallMapping = {
export type AbiEventMapping = {
type: string;
abi: string;
address: string;
address: Address;
eventFilter: {
fromBlock: BigInt | string;
toBlock: BigInt | string;
Expand Down
6 changes: 3 additions & 3 deletions kleros-sdk/src/dataMappings/utils/disputeDetailsSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { z } from "zod";
import { isAddress } from "viem";
import { normalize } from "viem/ens";

const isHexAddress = (str: string): boolean => /^0x[a-fA-F0-9]{40}$/.test(str);
const isHexId = (str: string): boolean => /^0x[a-fA-F0-9]{1,64}$/.test(str);
const isMultiaddr = (str: string): boolean =>
export const isHexAddress = (str: string): boolean => /^0x[a-fA-F0-9]{40}$/.test(str);
export const isHexId = (str: string): boolean => /^0x[a-fA-F0-9]{1,64}$/.test(str);
export const isMultiaddr = (str: string): boolean =>
/^\/(?:ip4|ip6|dns4|dns6|dnsaddr|tcp|udp|utp|tls|ws|wss|p2p-circuit|p2p-webrtc-star|p2p-webrtc-direct|p2p-websocket-star|onion|ipfs)(\/[^\s\/]+)+$|^ipfs:\/\/[a-zA-Z0-9]+\/[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)?$/.test(
str
);
Expand Down
20 changes: 13 additions & 7 deletions kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import mustache from "mustache";
import { ActionMapping } from "./actionTypes";

export const replacePlaceholdersWithValues = (mapping: any, context: Record<string, unknown>) => {
const replace = (obj) => {
export function replacePlaceholdersWithValues(
mapping: ActionMapping,
context: Record<string, unknown>
): ActionMapping | ActionMapping[] {
function replace(obj: ActionMapping): ActionMapping | ActionMapping[] {
if (typeof obj === "string") {
return mustache.render(obj, context);
return mustache.render(obj, context) as unknown as ActionMapping;
} else if (Array.isArray(obj)) {
return obj.map(replace);
return obj.map(replace) as unknown as ActionMapping[];
} else if (typeof obj === "object" && obj !== null) {
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, replace(value)]));
return Object.fromEntries(
Object.entries(obj).map(([key, value]) => [key, replace(value)])
) as unknown as ActionMapping[];
} else {
return obj;
}
};
}

return replace(mapping);
};
}
6 changes: 3 additions & 3 deletions kleros-sdk/src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createPublicClient, webSocket } from "viem";
import { createPublicClient, webSocket, type PublicClient } from "viem";
import { arbitrumSepolia } from "viem/chains";

let publicClient;
let publicClient: PublicClient | undefined;

export const configureSDK = (config: { apiKey?: string }) => {
if (config.apiKey) {
Expand All @@ -14,7 +14,7 @@ export const configureSDK = (config: { apiKey?: string }) => {
}
};

export const getPublicClient = () => {
export const getPublicClient = (): PublicClient => {
if (!publicClient) {
throw new Error("SDK not configured. Please call `configureSDK` before using.");
}
Expand Down
2 changes: 1 addition & 1 deletion prettier-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"eslint": "^8.56.0",
"eslint": "^8.57.1",
"prettier": "^2.8.8",
"prettier-plugin-solidity": "^1.3.1"
},
Expand Down
3 changes: 0 additions & 3 deletions web-devtools/.eslintignore

This file was deleted.

166 changes: 0 additions & 166 deletions web-devtools/.eslintrc.json

This file was deleted.

Loading

0 comments on commit 34fb467

Please sign in to comment.