Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: 🎨 import type when it's only used as type #532

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ const config = tsLintConfig(
"@typescript-eslint/no-dynamic-delete": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/consistent-type-imports": [
"error",
{
prefer: "type-imports",
fixStyle: "inline-type-imports",
},
],
"no-unused-vars": "off",
"unused-imports/no-unused-imports": "error",
"prefer-const": "error",
Expand All @@ -96,6 +103,10 @@ const config = tsLintConfig(
},
],
"import/no-cycle": "error",
"import/no-self-import": "error",
"import/no-duplicates": "error",
"import/no-named-default": "error",
"import/no-webpack-loader-syntax": "error",
},
}
);
Expand Down
2 changes: 1 addition & 1 deletion examples/grid/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DRPNode } from "@ts-drp/node";
import { enableTracing, IMetrics, OpentelemetryMetrics } from "@ts-drp/tracer";
import { enableTracing, type IMetrics, OpentelemetryMetrics } from "@ts-drp/tracer";

import { env } from "./env";
import { Grid } from "./objects/grid";
Expand Down
4 changes: 2 additions & 2 deletions examples/grid/src/state.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DRPNode } from "@ts-drp/node";
import { DRPObject } from "@ts-drp/object";
import { type DRPObject } from "@ts-drp/object";

import { Grid } from "./objects/grid";
import { type Grid } from "./objects/grid";

interface GridState {
node: DRPNode;
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LoggerOptions } from "@ts-drp/types";
import { type LoggerOptions } from "@ts-drp/types";
import loglevel from "loglevel";
import prefix from "loglevel-plugin-prefix";

Expand Down
11 changes: 8 additions & 3 deletions packages/network/tests/network.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { GossipSub, MeshPeer } from "@chainsafe/libp2p-gossipsub";
import { Connection, IdentifyResult, Libp2p, SubscriptionChangeData } from "@libp2p/interface";
import { type GossipSub, type MeshPeer } from "@chainsafe/libp2p-gossipsub";
import {
type Connection,
type IdentifyResult,
type Libp2p,
type SubscriptionChangeData,
} from "@libp2p/interface";
import { loadConfig } from "@ts-drp/node/src/config.js";
import { Message } from "@ts-drp/types";
import { raceEvent } from "race-event";
import { beforeAll, describe, expect, test, afterAll } from "vitest";

import { DRPNetworkNode, DRPNetworkNodeConfig, streamToUint8Array } from "../src/node.js";
import { DRPNetworkNode, type DRPNetworkNodeConfig, streamToUint8Array } from "../src/node.js";

describe("DRPNetworkNode can connect & send messages", () => {
const controller = new AbortController();
Expand Down
8 changes: 4 additions & 4 deletions packages/node/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { peerIdFromPublicKey } from "@libp2p/peer-id";
import { Signature } from "@noble/secp256k1";
import { streamToUint8Array } from "@ts-drp/network";
import { type ACL, type DRPObject, HashGraph } from "@ts-drp/object";
import { type Vertex } from "@ts-drp/types";
import {
AggregatedAttestation,
Attestation,
type Vertex,
type AggregatedAttestation,
type Attestation,
AttestationUpdate,
DRPState,
type DRPState,
FetchState,
FetchStateResponse,
Message,
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { GossipsubMessage } from "@chainsafe/libp2p-gossipsub";
import type { EventCallback, IncomingStreamData, StreamHandler } from "@libp2p/interface";
import { KeychainConfig, Keychain } from "@ts-drp/keychain";
import { type KeychainConfig, Keychain } from "@ts-drp/keychain";
import { Logger } from "@ts-drp/logger";
import { DRPNetworkNode, type DRPNetworkNodeConfig } from "@ts-drp/network";
import { type ACL, type DRP, DRPObject } from "@ts-drp/object";
import { IMetrics } from "@ts-drp/tracer";
import { type IMetrics } from "@ts-drp/tracer";
import { Message, MessageType, type LoggerOptions } from "@ts-drp/types";

import { drpMessagesHandler } from "./handlers.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ILogger } from "@ts-drp/logger";
import { type ILogger } from "@ts-drp/logger";

// TODO: replace with the actual logger in each place that need a logger this is just a hack by the mean time to fix the circular dependency
export const log: ILogger = {
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/operations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GossipsubMessage } from "@chainsafe/libp2p-gossipsub";
import { type GossipsubMessage } from "@chainsafe/libp2p-gossipsub";
import { type DRP, DRPObject, HashGraph } from "@ts-drp/object";
import { IMetrics } from "@ts-drp/tracer";
import { type IMetrics } from "@ts-drp/tracer";
import { FetchState, Message, MessageType, Sync } from "@ts-drp/types";

import { drpMessagesHandler, drpObjectChangesHandler } from "./handlers.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/node/tests/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path, { dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { beforeAll, describe, expect, test } from "vitest";

import { GenericRespone, SubscribeDRPRequest } from "../src/proto/drp/node/v1/rpc_pb.js";
import { type GenericRespone, type SubscribeDRPRequest } from "../src/proto/drp/node/v1/rpc_pb.js";
import * as run from "../src/run.js";

const protoPath = path.resolve(
Expand Down
2 changes: 1 addition & 1 deletion packages/object/src/finality/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { bls } from "@chainsafe/bls/herumi";
import { Logger } from "@ts-drp/logger";
import { LoggerOptions, AggregatedAttestation, Attestation } from "@ts-drp/types";
import { type LoggerOptions, type AggregatedAttestation, type Attestation } from "@ts-drp/types";
import { fromString as uint8ArrayFromString } from "uint8arrays/from-string";

import { BitSet } from "../hashgraph/bitset.js";
Expand Down
8 changes: 7 additions & 1 deletion packages/object/src/hashgraph/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Logger } from "@ts-drp/logger";
import { LoggerOptions, Operation, Vertex, ActionType, SemanticsType } from "@ts-drp/types";
import {
type LoggerOptions,
type Operation,
Vertex,
ActionType,
SemanticsType,
} from "@ts-drp/types";

import { BitSet } from "./bitset.js";
import { linearizeMultipleSemantics } from "../linearize/multipleSemantics.js";
Expand Down
8 changes: 4 additions & 4 deletions packages/object/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Logger } from "@ts-drp/logger";
import { IMetrics } from "@ts-drp/tracer";
import { type IMetrics } from "@ts-drp/tracer";
import {
DRPObjectBase,
type DRPObjectBase,
DRPState,
DRPStateEntry,
Operation,
type Operation,
type Vertex,
type LoggerOptions,
} from "@ts-drp/types";
Expand All @@ -17,7 +17,7 @@ import type { ACL } from "./acl/interface.js";
import { type FinalityConfig, FinalityStore } from "./finality/index.js";
import { type Hash, HashGraph } from "./hashgraph/index.js";
import {
ConnectObjectOptions,
type ConnectObjectOptions,
type DRP,
type DRPObjectCallback,
type DRPPublicCredential,
Expand Down
4 changes: 2 additions & 2 deletions packages/object/src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IMetrics } from "@ts-drp/tracer";
import { Operation, SemanticsType, type LoggerOptions, type Vertex } from "@ts-drp/types";
import { type IMetrics } from "@ts-drp/tracer";
import { type Operation, type SemanticsType, type LoggerOptions, type Vertex } from "@ts-drp/types";

import type { ResolveConflictsType } from "./hashgraph/index.js";
import type { DRPObject } from "./index.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/object/src/linearize/multipleSemantics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActionType, Operation, Vertex } from "@ts-drp/types";
import { ActionType, type Operation, type Vertex } from "@ts-drp/types";

import { type Hash, type HashGraph } from "../hashgraph/index.js";
import type { ObjectSet } from "../utils/objectSet.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/object/src/linearize/pairSemantics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActionType, Operation } from "@ts-drp/types";
import { ActionType, type Operation } from "@ts-drp/types";

import { type Hash, type HashGraph } from "../hashgraph/index.js";
import type { ObjectSet } from "../utils/objectSet.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/object/tests/drpobject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SetDRP } from "@ts-drp/blueprints/src/index.js";
import { type Vertex, ActionType, SemanticsType } from "@ts-drp/types";
import { beforeEach, describe, expect, it, test, vi } from "vitest";

import { DRP, DRPObject, ObjectACL, ResolveConflictsType } from "../src/index.js";
import { type DRP, DRPObject, ObjectACL, type ResolveConflictsType } from "../src/index.js";

const acl = new ObjectACL({
admins: new Map([
Expand Down
2 changes: 1 addition & 1 deletion packages/object/tests/hashgraph.bench.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MapDRP, SetDRP } from "@ts-drp/blueprints/src/index.js";
import Benchmark from "benchmark";

import { DRP, DRPObject, ObjectACL } from "../src/index.js";
import { type DRP, DRPObject, ObjectACL } from "../src/index.js";

const acl = new ObjectACL({
admins: new Map([["peer1", { secp256k1PublicKey: "pubKey1", blsPublicKey: "pubKey1" }]]),
Expand Down
12 changes: 10 additions & 2 deletions packages/object/tests/hashgraph.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { MapConflictResolution, MapDRP } from "@ts-drp/blueprints/src/Map/index.js";
import { SetDRP } from "@ts-drp/blueprints/src/Set/index.js";
import { type Vertex, Operation, ActionType, SemanticsType } from "@ts-drp/types";
import { type Vertex, type Operation, ActionType, SemanticsType } from "@ts-drp/types";
import { beforeAll, beforeEach, describe, expect, test, vi } from "vitest";

import { ObjectACL } from "../src/acl/index.js";
import { ACLGroup, DRP, DRPObject, DrpType, Hash, HashGraph, newVertex } from "../src/index.js";
import {
ACLGroup,
type DRP,
DRPObject,
DrpType,
type Hash,
HashGraph,
newVertex,
} from "../src/index.js";
import { ObjectSet } from "../src/utils/objectSet.js";

const acl = new ObjectACL({
Expand Down
4 changes: 2 additions & 2 deletions packages/tracer/tests/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Span } from "@opentelemetry/api";
import { type Span } from "@opentelemetry/api";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
import { WebTracerProvider } from "@opentelemetry/sdk-trace-web";
import { beforeEach, describe, expect, test, vi } from "vitest";

import { disableTracing, enableTracing, flush, OpentelemetryMetrics } from "../src/index.js";
import { IMetrics } from "../src/interface.js";
import { type IMetrics } from "../src/interface.js";

// Mock OpenTelemetry dependencies
vi.mock("@opentelemetry/api", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/interval-runner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LoggerOptions } from "./logger.js";
import { type LoggerOptions } from "./logger.js";

type AnyFnCallback<T, Args extends unknown[] = []> =
| (() => T)
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import loglevel from "loglevel";
import type loglevel from "loglevel";

export interface LoggerOptions {
level?: loglevel.LogLevelDesc;
Expand Down