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

fix: import plugin wasn't activated for typescript #523

Merged
merged 3 commits into from
Mar 3, 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
26 changes: 20 additions & 6 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import eslint from "@eslint/js";
import tsparser from "@typescript-eslint/parser";
import esimport from "eslint-plugin-import";
import importPlugin from "eslint-plugin-import";
import prettier from "eslint-plugin-prettier";
import unusedImports from "eslint-plugin-unused-imports";
import vitest from "eslint-plugin-vitest";
import globals from "globals";
import tseslint from "typescript-eslint";
import { config as tsLintConfig, configs, plugin } from "typescript-eslint";

const config = tseslint.config(
/** @type {import("typescript-eslint").ConfigArray} */
const config = tsLintConfig(
{
ignores: [
"**/.env",
Expand All @@ -30,11 +31,17 @@ const config = tseslint.config(
],
},
eslint.configs.recommended,
tseslint.configs.strict,
configs.strict,
importPlugin.flatConfigs.recommended,
importPlugin.flatConfigs.typescript,
{
settings: {
"import/resolver": {
typescript: {},
},
},
plugins: {
"@typescript-eslint": tseslint.plugin,
"import": esimport,
"@typescript-eslint": plugin,
"prettier": prettier,
"unused-imports": unusedImports,
"vitest": vitest,
Expand Down Expand Up @@ -82,6 +89,13 @@ const config = tseslint.config(
},
},
],
"import/no-unresolved": [
"error",
{
ignore: ["@libp2p/bootstrap", "@libp2p/pubsub-peer-discovery"],
},
],
"import/no-cycle": "error",
},
}
);
Expand Down
3 changes: 2 additions & 1 deletion examples/canvas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
},
"dependencies": {
"@ts-drp/node": "0.8.5",
"@ts-drp/object": "0.8.5"
"@ts-drp/object": "0.8.5",
"@ts-drp/types": "0.8.5"
},
"devDependencies": {
"@types/node": "^22.5.4",
Expand Down
3 changes: 2 additions & 1 deletion examples/canvas/src/objects/canvas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ActionType, type DRP, type ResolveConflictsType, SemanticsType } from "@ts-drp/object";
import { type DRP, type ResolveConflictsType } from "@ts-drp/object";
import { ActionType, SemanticsType } from "@ts-drp/types";

import { Pixel } from "./pixel";

Expand Down
3 changes: 2 additions & 1 deletion examples/chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
},
"dependencies": {
"@ts-drp/node": "0.8.5",
"@ts-drp/object": "0.8.5"
"@ts-drp/object": "0.8.5",
"@ts-drp/types": "0.8.5"
},
"devDependencies": {
"@types/node": "^22.5.4",
Expand Down
3 changes: 2 additions & 1 deletion examples/chat/src/objects/chat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ActionType, type DRP, type ResolveConflictsType, SemanticsType } from "@ts-drp/object";
import { type DRP, type ResolveConflictsType } from "@ts-drp/object";
import { ActionType, SemanticsType } from "@ts-drp/types";

export class Chat implements DRP {
semanticsType: SemanticsType = SemanticsType.pair;
Expand Down
5 changes: 3 additions & 2 deletions examples/grid/src/objects/grid.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ActionType, type DRP, type ResolveConflictsType, SemanticsType } from "@ts-drp/object";
import { type Vertex } from "@ts-drp/types";
import { type DRP, type ResolveConflictsType } from "@ts-drp/object";
import { ActionType, SemanticsType, type Vertex } from "@ts-drp/types";

export class Grid implements DRP {
semanticsType: SemanticsType = SemanticsType.pair;
positions: Map<string, { x: number; y: number }>;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"assemblyscript": "^0.27.29",
"eslint": "^9.19.0",
"eslint-config-prettier": "^10.0.1",
"eslint-import-resolver-typescript": "^3.8.3",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-unused-imports": "^4.1.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/blueprints/src/AddMul/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ActionType, type DRP, type ResolveConflictsType, SemanticsType } from "@ts-drp/object";
import { type Vertex } from "@ts-drp/types";
import { type DRP, type ResolveConflictsType } from "@ts-drp/object";
import { ActionType, SemanticsType, type Vertex } from "@ts-drp/types";

export class AddMulDRP implements DRP {
semanticsType = SemanticsType.pair;
Expand Down
4 changes: 2 additions & 2 deletions packages/blueprints/src/Map/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ActionType, type DRP, type ResolveConflictsType, SemanticsType } from "@ts-drp/object";
import { type Vertex } from "@ts-drp/types";
import { type DRP, type ResolveConflictsType } from "@ts-drp/object";
import { ActionType, SemanticsType, type Vertex } from "@ts-drp/types";

export enum MapConflictResolution {
SetWins = 0,
Expand Down
3 changes: 2 additions & 1 deletion packages/blueprints/src/Set/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type DRP, SemanticsType } from "@ts-drp/object";
import { type DRP } from "@ts-drp/object";
import { SemanticsType } from "@ts-drp/types";

export class SetDRP<T> implements DRP {
semanticsType = SemanticsType.pair;
Expand Down
2 changes: 1 addition & 1 deletion packages/blueprints/tests/AddMul.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActionType } from "@ts-drp/object";
import { ActionType } from "@ts-drp/types";
import { beforeEach, describe, expect, test } from "vitest";

import { AddMulDRP } from "../src/AddMul/index.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/blueprints/tests/Map.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActionType } from "@ts-drp/object";
import { ActionType } from "@ts-drp/types";
import { beforeEach, describe, expect, test } from "vitest";

import { MapDRP } from "../src/index.js";
Expand Down
8 changes: 1 addition & 7 deletions packages/keychain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@
"uint8arrays": "^5.1.0"
},
"devDependencies": {
"@eslint/js": "^9.18.0",
"@types/object-inspect": "^1.13.0",
"@typescript-eslint/eslint-plugin": "^8.20.0",
"@typescript-eslint/parser": "^8.20.0",
"eslint": "^9.18.0",
"typescript": "^5.7.3",
"typescript-eslint": "^8.20.0"
"@types/object-inspect": "^1.13.0"
}
}
2 changes: 1 addition & 1 deletion packages/keychain/src/keychain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bls from "@chainsafe/bls/herumi";
import { bls } from "@chainsafe/bls/herumi";
import type { SecretKey as BlsSecretKey } from "@chainsafe/bls/types";
import { deriveKeyFromEntropy } from "@chainsafe/bls-keygen";
import { generateKeyPair, generateKeyPairFromSeed } from "@libp2p/crypto/keys";
Expand Down
8 changes: 8 additions & 0 deletions packages/logger/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ export interface LoggerOptions {
level?: loglevel.LogLevelDesc;
}

export interface ILogger {
trace: (...args: unknown[]) => void;
debug: (...args: unknown[]) => void;
info: (...args: unknown[]) => void;
warn: (...args: unknown[]) => void;
error: (...args: unknown[]) => void;
}

export class Logger {
private log: loglevel.Logger;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import {
} from "@ts-drp/types";
import { fromString as uint8ArrayFromString } from "uint8arrays/from-string";

import { type DRPNode, log } from "./index.js";
import { type DRPNode } from "./index.js";
import { log } from "./logger.js";
import { deserializeStateMessage, serializeStateMessage } from "./utils.js";

/*
Handler for all DRP messages, including pubsub messages and direct messages
You need to setup stream xor data
Expand Down
11 changes: 7 additions & 4 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ import { IMetrics } from "@ts-drp/tracer";
import { Message, MessageType } from "@ts-drp/types";

import { drpMessagesHandler } from "./handlers.js";
import { log } from "./logger.js";
import * as operations from "./operations.js";
import { DRPObjectStore } from "./store/index.js";

// snake_casing to match the JSON config
export interface DRPNodeConfig {
log_config?: LoggerOptions;
network_config?: DRPNetworkNodeConfig;
keychain_config?: KeychainConfig;
}

export let log: Logger;

export class DRPNode {
config?: DRPNodeConfig;
objectStore: DRPObjectStore;
Expand All @@ -28,7 +26,12 @@ export class DRPNode {

constructor(config?: DRPNodeConfig) {
this.config = config;
log = new Logger("drp::node", config?.log_config);
const newLogger = new Logger("drp::node", config?.log_config);
log.trace = newLogger.trace;
log.debug = newLogger.debug;
log.info = newLogger.info;
log.warn = newLogger.warn;
log.error = newLogger.error;
this.networkNode = new DRPNetworkNode(config?.network_config);
this.objectStore = new DRPObjectStore();
this.keychain = new Keychain(config?.keychain_config);
Expand Down
10 changes: 10 additions & 0 deletions packages/node/src/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { 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 = {
trace: () => {},
debug: () => {},
info: () => {},
warn: () => {},
error: () => {},
};
3 changes: 2 additions & 1 deletion packages/node/src/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { IMetrics } from "@ts-drp/tracer";
import { FetchState, Message, MessageType, Sync } from "@ts-drp/types";

import { drpMessagesHandler, drpObjectChangesHandler } from "./handlers.js";
import { type DRPNode, log } from "./index.js";
import { type DRPNode } from "./index.js";
import { log } from "./logger.js";

export function createObject(node: DRPNode, object: DRPObject) {
node.objectStore.put(object.id, object);
Expand Down
3 changes: 2 additions & 1 deletion packages/node/src/rpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import * as reflection from "@grpc/reflection";
import path, { dirname } from "node:path";
import { fileURLToPath } from "node:url";

import { type DRPNode, log } from "../index.js";
import { type DRPNode } from "../index.js";
import { log } from "../logger.js";
import { DrpRpcService } from "../proto/drp/node/v1/rpc_grpc_pb.js";
import type {
AddCustomGroupRequest,
Expand Down
2 changes: 1 addition & 1 deletion packages/node/tests/node.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bls from "@chainsafe/bls/herumi";
import { bls } from "@chainsafe/bls/herumi";
import { SetDRP } from "@ts-drp/blueprints";
import { ACLGroup, ObjectACL } from "@ts-drp/object";
import { type DRP, DRPObject, DrpType } from "@ts-drp/object";
Expand Down
7 changes: 3 additions & 4 deletions packages/object/src/acl/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { type Vertex } from "@ts-drp/types";
import { type Vertex, ActionType, SemanticsType } from "@ts-drp/types";

import { ActionType, type ResolveConflictsType, SemanticsType } from "../index.js";
import { type ResolveConflictsType } from "../index.js";
import type { DRPPublicCredential } from "../interface.js";
import type { PeerPermissions } from "./interface.js";
import { type ACL, ACLConflictResolution, ACLGroup } from "./interface.js";
import { type ACL, ACLConflictResolution, type PeerPermissions, ACLGroup } from "./interface.js";

export class ObjectACL implements ACL {
semanticsType = SemanticsType.pair;
Expand Down
3 changes: 1 addition & 2 deletions packages/object/src/acl/interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { DRPPublicCredential } from "../interface.js";
import type { DRP } from "../interface.js";
import type { DRPPublicCredential, DRP } from "../interface.js";

export interface ACL extends DRP {
permissionless: boolean;
Expand Down
15 changes: 10 additions & 5 deletions packages/object/src/finality/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import bls from "@chainsafe/bls/herumi";
import { bls } from "@chainsafe/bls/herumi";
import { Logger, LoggerOptions } from "@ts-drp/logger";
import { AggregatedAttestation, Attestation } from "@ts-drp/types";
import { fromString as uint8ArrayFromString } from "uint8arrays/from-string";

import { BitSet } from "../hashgraph/bitset.js";
import type { Hash } from "../hashgraph/index.js";
import { type DRPPublicCredential, log } from "../index.js";
import { type DRPPublicCredential } from "../index.js";

const DEFAULT_FINALITY_THRESHOLD = 0.51;

Expand Down Expand Up @@ -97,9 +98,13 @@ export class FinalityStore {
states: Map<string, FinalityState>;
finalityThreshold: number;

constructor(config?: FinalityConfig) {
private log: Logger;

constructor(config?: FinalityConfig, logConfig?: LoggerOptions) {
this.states = new Map();
this.finalityThreshold = config?.finality_threshold ?? DEFAULT_FINALITY_THRESHOLD;

this.log = new Logger("drp::finality", logConfig);
}

initializeState(hash: Hash, signers: Map<string, DRPPublicCredential>) {
Expand Down Expand Up @@ -153,7 +158,7 @@ export class FinalityStore {
try {
this.states.get(attestation.data)?.addSignature(peerId, attestation.signature, verify);
} catch (e) {
log.error("::finality::addSignatures", e);
this.log.error("::finality::addSignatures", e);
}
}
}
Expand All @@ -176,7 +181,7 @@ export class FinalityStore {
try {
this.states.get(attestation.data)?.merge(attestation);
} catch (e) {
log.error("::finality::mergeSignatures", e);
this.log.error("::finality::mergeSignatures", e);
}
}
}
Expand Down
Loading