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

🏷️ Use "import type" when possible #41

Merged
merged 2 commits into from
May 24, 2023
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
1 change: 1 addition & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run type-check
- run: npm run build --if-present
- run: npm test -- --testTimeout 5000
2 changes: 1 addition & 1 deletion author.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {OnEvent, OnEventObject, RelayPool} from "./relay-pool";
import {Filter, Kind} from "nostr-tools";
import {type Filter, Kind} from "nostr-tools";
import type {EventObject} from "./event";

export class Author {
Expand Down
4 changes: 2 additions & 2 deletions collect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Event} from "nostr-tools";
import {OnEvent} from "./on-event-filters";
import type {Event} from "nostr-tools";
import type {OnEvent} from "./on-event-filters";

const binarySearch = function (a: Event[], target: Event) {
var l = 0,
Expand Down
2 changes: 1 addition & 1 deletion event-cache-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env jest */

import {Kind, Event} from "nostr-tools";
import {Kind, type Event} from "nostr-tools";
import {EventCache} from "./event-cache";

describe("EventCache", () => {
Expand Down
2 changes: 1 addition & 1 deletion event-cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Filter, Kind, Event} from "nostr-tools";
import {type Filter, Kind, type Event} from "nostr-tools";

export class EventCache {
eventsById: Map<string, Event> = new Map();
Expand Down
2 changes: 1 addition & 1 deletion event-demultiplexer-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env jest */

import {Filter, matchFilter, Event, UnsignedEvent} from "nostr-tools";
import {type Filter, matchFilter, type Event, type UnsignedEvent} from "nostr-tools";
import {EventDemultiplexer} from "./event-demultiplexer";

let eventFrom = (event: UnsignedEvent & {id: string}) => {
Expand Down
4 changes: 2 additions & 2 deletions event-demultiplexer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Filter, matchFilter, Event} from "nostr-tools";
import {OnEvent} from "./on-event-filters";
import {type Filter, matchFilter, type Event} from "nostr-tools";
import type {OnEvent} from "./on-event-filters";

export class EventDemultiplexer {
filterAndOnEventByEvent: Map<string, [Filter, OnEvent][]> = new Map();
Expand Down
3 changes: 3 additions & 0 deletions event-persister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@
// }
// }
// }

// Needed for isolatedModules to not complain
export const __unused = true;
4 changes: 2 additions & 2 deletions event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Kind, Event} from "nostr-tools";
import type {Kind, Event} from "nostr-tools";
import {Author} from "./author";
import {RelayPool} from "./relay-pool";
import type {RelayPool} from "./relay-pool";

import type {OnEvent} from "./on-event-filters";
export class EventObject implements Event {
Expand Down
6 changes: 3 additions & 3 deletions group-filters-by-relay.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {Filter, Event} from "nostr-tools";
import type {Filter, Event} from "nostr-tools";
import {mergeSimilarAndRemoveEmptyFilters} from "./merge-similar-filters";
import {
doNotEmitDuplicateEvents,
doNotEmitOlderEvents,
matchOnEventFilters,
type OnEvent,
} from "./on-event-filters";
import {EventCache} from "./event-cache";
import {FilterToSubscribe} from "./relay-pool";
import type {EventCache} from "./event-cache";
import type {FilterToSubscribe} from "./relay-pool";
import {CallbackReplayer} from "./callback-replayer";

const unique = (arr: string[]) => [...new Set(arr)];
Expand Down
2 changes: 1 addition & 1 deletion in-memory-relay-server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Event, Filter, matchFilters} from "nostr-tools";
import {type Event, type Filter, matchFilters} from "nostr-tools";
import {WebSocket, WebSocketServer} from "isomorphic-ws";

const _ = WebSocket; // Importing WebSocket is needed for WebSocketServer to work
Expand Down
2 changes: 1 addition & 1 deletion metadata-cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Event} from "nostr-tools";
import type {Event} from "nostr-tools";

export class MetadataCache {
data: Map<string, Event>;
Expand Down
4 changes: 2 additions & 2 deletions newest-event-cache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Event, Filter} from "nostr-tools";
import {RelayPool} from "./relay-pool";
import type {Event, Filter} from "nostr-tools";
import type {RelayPool} from "./relay-pool";

export class NewestEventCache {
data: Map<string, Event>;
Expand Down
4 changes: 2 additions & 2 deletions on-event-filters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Filter, Kind, matchFilter, Event} from "nostr-tools";
import {EventObject} from "./event";
import {type Filter, Kind, matchFilter, type Event} from "nostr-tools";
import type {EventObject} from "./event";
export type OnEventArgs = [
event: Event,
afterEose: boolean,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"build": "node build.js",
"pretest": "node build.js",
"test": "NODE_OPTIONS=--experimental-vm-modules npx jest",
"publish": "npm i && npm run build && npm run test -- --testTimeout 5000 && npm publish"
"publish": "npm i && npm run build && npm run test -- --testTimeout 5000 && npm publish",
"type-check": "tsc"
}
}
2 changes: 1 addition & 1 deletion relay-pool-worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {Event} from "nostr-tools";
import {OnEose, OnEvent, SubscriptionOptions} from "./relay-pool";
import type {OnEose, OnEvent, SubscriptionOptions} from "./relay-pool";

export class RelayPoolWorker {
// eslint-disable-next-line no-undef
Expand Down
2 changes: 1 addition & 1 deletion relay-pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
generatePrivateKey,
getEventHash,
getPublicKey,
Event,
type Event,
} from "nostr-tools";
import {RelayPool} from "./relay-pool";
import {InMemoryRelayServer} from "./in-memory-relay-server";
Expand Down
8 changes: 4 additions & 4 deletions relay-pool.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {Filter, Event} from "nostr-tools";
import type {Filter, Event} from "nostr-tools";
import {mergeSimilarAndRemoveEmptyFilters} from "./merge-similar-filters";
import {type Relay, relayInit, Sub} from "./relay";
import {OnEventObject, type OnEvent} from "./on-event-filters";
import {type Relay, relayInit, type Sub} from "./relay";
import type {OnEventObject, OnEvent} from "./on-event-filters";
import {EventCache} from "./event-cache";
import {EventObject} from "./event";
import {
batchFiltersByRelay,
groupFiltersByRelayAndEmitCacheHits,
} from "./group-filters-by-relay";
import {CallbackReplayer} from "./callback-replayer";
import type {CallbackReplayer} from "./callback-replayer";
import {NewestEventCache} from "./newest-event-cache";

const unique = (arr: string[]) => [...new Set(arr)];
Expand Down
2 changes: 1 addition & 1 deletion relay-pool.worker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-undef */
// worker.ts
import {RelayPool, SubscriptionOptions} from "./relay-pool";
import {RelayPool, type SubscriptionOptions} from "./relay-pool";
import type {Event} from "nostr-tools";

let relayPool: RelayPool;
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"esModuleInterop": true,
"skipLibCheck": true,
"emitDeclarationOnly": true,
"importsNotUsedAsValues": "error",
"preserveValueImports": true,
"isolatedModules": true,
"outDir": "dist",
"rootDir": ".",
}
Expand Down