Remove tsc-multi, re-install gts, apply autoformatting and linting

This commit is contained in:
Jon Staab
2024-12-17 10:59:27 -08:00
parent 0b86613161
commit f33e03740e
122 changed files with 2243 additions and 2178 deletions
+5 -5
View File
@@ -29,11 +29,11 @@ req.emitter.on(DVMEvent.Result, (url, event) => console.log(event))
# Handler example
```javascript
const {bytesToHex} = require('@noble/hashes/utils')
const {generateSecretKey} = require('nostr-tools')
const {createEvent} = require('@welshman/util')
const {subscribe} = require('@welshman/net')
const {DVM} = require('@welshman/dvm')
import {bytesToHex} from '@noble/hashes/utils'
import {generateSecretKey} from 'nostr-tools'
import {createEvent} from '@welshman/util'
import {subscribe} from '@welshman/net'
import {DVM} from '@welshman/dvm'
// Your DVM's private key. Store this somewhere safe
// const hexPrivateKey = bytesToHex(generateSecretKey())
+4 -8
View File
@@ -15,22 +15,18 @@
"exports": {
".": {
"types": "./build/src/index.d.ts",
"import": "./build/src/index.mjs",
"require": "./build/src/index.cjs"
"import": "./build/src/index.js",
"require": "./build/src/index.js"
}
},
"scripts": {
"pub": "npm run lint && npm run build && npm publish",
"build": "gts clean && tsc-multi",
"build": "gts clean && tsc",
"lint": "gts lint",
"fix": "gts fix"
},
"devDependencies": {
"gts": "^5.0.1",
"tsc-multi": "^1.1.0",
"typescript": "~5.1.6"
},
"dependencies": {
"@noble/hashes": "^1.6.1",
"@welshman/lib": "~0.0.33",
"@welshman/net": "~0.0.41",
"@welshman/util": "~0.0.50",
+16 -16
View File
@@ -1,8 +1,8 @@
import {hexToBytes} from '@noble/hashes/utils'
import {getPublicKey, finalizeEvent} from 'nostr-tools'
import {now} from '@welshman/lib'
import type {TrustedEvent, StampedEvent, Filter} from '@welshman/util'
import {subscribe, publish} from '@welshman/net'
import {hexToBytes} from "@noble/hashes/utils"
import {getPublicKey, finalizeEvent} from "nostr-tools/pure"
import {now} from "@welshman/lib"
import type {TrustedEvent, StampedEvent, Filter} from "@welshman/util"
import {subscribe, publish} from "@welshman/net"
export type DVMHandler = {
stop?: () => void
@@ -43,14 +43,14 @@ export class DVM {
const filter: Filter = {kinds, since}
if (requireMention) {
filter['#p'] = [getPublicKey(hexToBytes(sk))]
filter["#p"] = [getPublicKey(hexToBytes(sk))]
}
const filters = [filter]
const sub = subscribe({relays, filters})
sub.emitter.on('event', (url: string, e: TrustedEvent) => this.onEvent(e))
sub.emitter.on('complete', () => resolve())
sub.emitter.on("event", (url: string, e: TrustedEvent) => this.onEvent(e))
sub.emitter.on("complete", () => resolve())
})
}
}
@@ -79,29 +79,29 @@ export class DVM {
this.seen.add(request.id)
if (this.logEvents) {
console.info('Handling request', request)
console.info("Handling request", request)
}
for await (const event of handler.handleEvent(request)) {
if (event.kind !== 7000) {
event.tags.push(['request', JSON.stringify(request)])
event.tags.push(["request", JSON.stringify(request)])
const inputTag = request.tags.find((t: string[]) => t[0] === 'i')
const inputTag = request.tags.find((t: string[]) => t[0] === "i")
if (inputTag) {
event.tags.push(inputTag)
}
}
event.tags.push(['p', request.pubkey])
event.tags.push(['e', request.id])
event.tags.push(["p", request.pubkey])
event.tags.push(["e", request.id])
if (expireAfter) {
event.tags.push(['expiration', String(now() + expireAfter)])
event.tags.push(["expiration", String(now() + expireAfter)])
}
if (this.logEvents) {
console.info('Publishing event', event)
console.info("Publishing event", event)
}
this.publish(event)
@@ -113,7 +113,7 @@ export class DVM {
const event = finalizeEvent(template, hexToBytes(sk))
await new Promise<void>(resolve => {
publish({event, relays}).emitter.on('success', () => resolve())
publish({event, relays}).emitter.on("success", () => resolve())
})
}
}
+2 -2
View File
@@ -1,2 +1,2 @@
export * from './handler'
export * from './request'
export * from "./handler.js"
export * from "./request.js"
+5 -5
View File
@@ -1,7 +1,7 @@
import {Emitter, now} from '@welshman/lib'
import type {TrustedEvent, SignedEvent, Filter} from '@welshman/util'
import {subscribe, publish, SubscriptionEvent} from '@welshman/net'
import type {Subscription, Publish} from '@welshman/net'
import {Emitter, now} from "@welshman/lib"
import type {TrustedEvent, SignedEvent, Filter} from "@welshman/util"
import {subscribe, publish, SubscriptionEvent} from "@welshman/net"
import type {Subscription, Publish} from "@welshman/net"
export enum DVMEvent {
Progress = "progress",
@@ -18,7 +18,7 @@ export type DVMRequestOptions = {
export type DVMRequest = {
request: DVMRequestOptions
emitter: Emitter,
emitter: Emitter
sub: Subscription
pub: Publish
}
-7
View File
@@ -1,7 +0,0 @@
{
"targets": [
{"extname": ".cjs", "module": "commonjs"},
{"extname": ".mjs", "module": "esnext", "moduleResolution": "node"}
],
"projects": ["tsconfig.json"]
}
+7 -4
View File
@@ -3,9 +3,12 @@
"compilerOptions": {
"rootDir": ".",
"outDir": "build",
"esModuleInterop": true,
"skipLibCheck": true,
"lib": ["esnext", "dom", "dom.iterable"]
"module": "nodenext",
"moduleResolution": "nodenext",
"lib": ["esnext", "dom"]
},
"include": ["src/**/*.ts"]
"include": [
"src/**/*.ts",
"test/**/*.ts"
]
}