Skip to content

Commit f309798

Browse files
committed
fix: type errors
1 parent f3c801e commit f309798

File tree

14 files changed

+61
-47
lines changed

14 files changed

+61
-47
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ Dockerfile
1515
*.md
1616
.nostr
1717
postgresql.conf
18+
test/integration/docker-compose.yml

Dockerfile.railwayapp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ RUN npm install --omit=dev --quiet
5353

5454
USER 1000:1000
5555

56-
CMD ["node", "src/index.js"]
56+
CMD ["node", "src/index.js"]

Dockerfile.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ ENV DB_MAX_POOL_SIZE=2
1010
ENV REDIS_HOST=cache-test
1111
ENV REDIS_PORT=6379
1212
ENV REDIS_USER=default
13-
ENV REDIS_PASSWORD=nostr_ts_relay
13+
ENV REDIS_PASSWORD=nostr_ts_relay_test
1414

1515
WORKDIR /code
1616

17-
COPY ["package.json", "settings.sample.json", "package-lock.json", ".nycrc.json", ".mocharc.js", "cucumber.js", "tsconfig.json", "knexfile.js", "./"]
17+
COPY ["package.json", "package-lock.json", "./"]
1818

1919
RUN npm install --quiet
2020

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ services:
33
build: .
44
container_name: nostr-ts-relay
55
environment:
6-
PORT: 8008
6+
RELAY_PORT: 8008
77
NOSTR_CONFIG_DIR: /home/node/
88
DB_HOST: db
99
DB_PORT: 5432

src/app/worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class AppWorker implements IRunnable {
1919
}
2020

2121
public run(): void {
22-
const port = Number(process.env.PORT) || 8008
22+
const port = Number(process.env.RELAY_PORT) || 8008
2323

2424
this.adapter.listen(port)
2525
}

src/cache/client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ export const getCacheConfig = (): RedisClientOptions => ({
66
password: process.env.REDIS_PASSWORD,
77
})
88

9-
let instance: CacheClient = undefined
9+
let instance: CacheClient | undefined = undefined
1010

1111
export const getCacheClient = (): CacheClient => {
1212
if (!instance) {
1313
const config = getCacheConfig()
1414

15+
console.log(config)
16+
1517
instance = createClient(config)
1618
}
1719

src/factories/worker-factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ export const workerFactory = (): AppWorker => {
1313
const dbClient = getDbClient()
1414
const eventRepository = new EventRepository(dbClient)
1515

16-
// deepcode ignore HttpToHttps: <please specify a reason of ignoring this>
16+
// deepcode ignore HttpToHttps: we use proxies
1717
const server = http.createServer()
1818
const webSocketServer = new WebSocketServer({
1919
server,
20-
maxPayload: 1024 * 1024,
20+
maxPayload: 102400, // 0.1 MB
2121
})
2222
const adapter = new WebSocketServerAdapter(
2323
server,

src/utils/event.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import * as secp256k1 from '@noble/secp256k1'
22
import { applySpec, converge, curry, mergeLeft, nth, omit, pipe, prop, reduceBy } from 'ramda'
33

4-
import { CanonicalEvent, Event } from '../@types/event'
5-
import { EventId, Pubkey } from '../@types/base'
4+
import { CanonicalEvent, DBEvent, Event } from '../@types/event'
5+
import { EventId, Pubkey, Tag } from '../@types/base'
66
import { EventKinds, EventTags } from '../constants/base'
77
import { fromBuffer } from './transform'
88
import { getLeadingZeroBits } from './proof-of-work'
99
import { isGenericTagQuery } from './filter'
1010
import { RuneLike } from './runes/rune-like'
1111
import { SubscriptionFilter } from '../@types/subscription'
1212

13-
export const serializeEvent = (event: Partial<Event>): CanonicalEvent => [
13+
export const serializeEvent = (event: Event): CanonicalEvent => [
1414
0,
1515
event.pubkey,
1616
event.created_at,
@@ -19,18 +19,18 @@ export const serializeEvent = (event: Partial<Event>): CanonicalEvent => [
1919
event.content,
2020
]
2121

22-
export const toNostrEvent = applySpec({
23-
id: pipe(prop('event_id'), fromBuffer),
24-
kind: prop('event_kind'),
25-
pubkey: pipe(prop('event_pubkey'), fromBuffer),
26-
created_at: prop('event_created_at'),
27-
content: prop('event_content'),
28-
tags: prop('event_tags'),
29-
sig: pipe(prop('event_signature'), fromBuffer),
22+
export const toNostrEvent: (event: DBEvent) => Event = applySpec({
23+
id: pipe(prop('event_id') as () => Buffer, fromBuffer),
24+
kind: prop('event_kind') as () => number,
25+
pubkey: pipe(prop('event_pubkey') as () => Buffer, fromBuffer),
26+
created_at: prop('event_created_at') as () => number,
27+
content: prop('event_content') as () => string,
28+
tags: prop('event_tags') as () => Tag[],
29+
sig: pipe(prop('event_signature') as () => Buffer, fromBuffer),
3030
})
3131

3232
export const isEventMatchingFilter = (filter: SubscriptionFilter) => (event: Event): boolean => {
33-
const startsWith = (input: string) => (prefix) => input.startsWith(prefix)
33+
const startsWith = (input: string) => (prefix: string) => input.startsWith(prefix)
3434

3535
// NIP-01: Basic protocol flow description
3636

@@ -58,6 +58,9 @@ export const isEventMatchingFilter = (filter: SubscriptionFilter) => (event: Eve
5858
) {
5959
if (isDelegatedEvent(event)) {
6060
const delegation = event.tags.find((tag) => tag[0] === EventTags.Delegation)
61+
if (typeof delegation === 'undefined') {
62+
return false
63+
}
6164

6265
if (!filter.authors.some(startsWith(delegation[1]))) {
6366
return false
@@ -119,10 +122,10 @@ export const isDelegatedEventValid = async (event: Event): Promise<boolean> => {
119122
omit(['tags']),
120123
pipe(
121124
prop('tags') as any,
122-
reduceBy(
125+
reduceBy<EventTags, string[]>(
123126
(acc, tag) => ([...acc, tag[1]]),
124127
[],
125-
nth(0),
128+
nth(0) as any,
126129
),
127130
),
128131
],

src/utils/runes/alternative.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { IAlternative } from '../../@types/runes'
22

33
const punctuations = /[!"#$%&'()*+-./:;<=>?@[\\\]^`{|}~]/
44

5-
const hasPunctuation = (input) => punctuations.test(input)
5+
const hasPunctuation = (input: string) => punctuations.test(input)
66

77
// Reference: https://github.com/rustyrussell/runes/blob/master/runes/runes.py
88

test/integration/docker-compose.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ services:
44
context: ../../
55
dockerfile: Dockerfile.test
66
environment:
7+
RELAY_PORT: 18808
78
DB_HOST: db-test
89
DB_PORT: 5432
910
DB_NAME: nostr_ts_relay_test
@@ -17,10 +18,14 @@ services:
1718
REDIS_PASSWORD: nostr_ts_relay_test
1819
NOSTR_CONFIG_DIR: /code
1920
volumes:
21+
- ../../package.json:/code/package.json
22+
- ../../settings.sample.json:/code/settings.sample.json
2023
- ../../src:/code/src
21-
- ../../test:/code/test
24+
- ../../test/integration:/code/test/integration
25+
- ../../cucumber.js:/code/cucumber.js
2226
- ../../.coverage:/code/.coverage
2327
- ../../.test-reports:/code/.test-reports
28+
- ../../tsconfig.json:/code/tsconfig.json
2429
working_dir: /code
2530
depends_on:
2631
cache-test:

0 commit comments

Comments
 (0)