Get ts/es etc figured out
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
module.exports = {
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es2021": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": "latest",
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"rules": {
|
||||
"@typescript-eslint/no-unused-vars": ["error", {args: "none"}],
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
}
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
node_modules
|
||||
dist
|
||||
|
||||
Regular → Executable
-1
@@ -2,4 +2,3 @@
|
||||
. "$(dirname -- "$0")/_/husky.sh"
|
||||
|
||||
npm run check
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const {build} = require('esbuild')
|
||||
|
||||
const common = {
|
||||
bundle: true,
|
||||
entryPoints: ['lib/main.ts'],
|
||||
sourcemap: 'external'
|
||||
}
|
||||
|
||||
build({
|
||||
...common,
|
||||
outfile: 'dist/paravel.esm.js',
|
||||
format: 'esm',
|
||||
packages: 'external'
|
||||
})
|
||||
.then(() => console.log('esm build success.'))
|
||||
|
||||
build({
|
||||
...common,
|
||||
outfile: 'dist/paravel.cjs',
|
||||
format: 'cjs',
|
||||
packages: 'external'
|
||||
})
|
||||
.then(() => console.log('cjs build success.'))
|
||||
Vendored
-4
@@ -1,4 +0,0 @@
|
||||
const t = 1;
|
||||
export {
|
||||
t as stuff
|
||||
};
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
(function(e,t){typeof exports=="object"&&typeof module<"u"?t(exports):typeof define=="function"&&define.amd?define(["exports"],t):(e=typeof globalThis<"u"?globalThis:e||self,t(e.paravel={}))})(this,function(e){"use strict";e.stuff=1,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|
||||
@@ -3,6 +3,7 @@ import {Relay} from "./Relay"
|
||||
const normalizeUrl = url => url.replace(/\/+$/, "").toLowerCase().trim()
|
||||
|
||||
export class Pool {
|
||||
relays: Map<string, Relay>
|
||||
constructor() {
|
||||
this.relays = new Map()
|
||||
}
|
||||
|
||||
+15
-16
@@ -1,4 +1,5 @@
|
||||
import {WebSocket} from "ws"
|
||||
import WebSocket from "isomorphic-ws"
|
||||
import {EventBus} from "./EventBus"
|
||||
import {Deferred, defer} from "./Deferred"
|
||||
|
||||
export class Relay {
|
||||
@@ -8,7 +9,7 @@ export class Relay {
|
||||
queue: string[]
|
||||
error: string
|
||||
status: string
|
||||
timeout?: number
|
||||
timeout?: NodeJS.Timeout
|
||||
bus: EventBus
|
||||
static STATUS = {
|
||||
NEW: "new",
|
||||
@@ -23,10 +24,6 @@ export class Relay {
|
||||
FORBIDDEN: "forbidden",
|
||||
}
|
||||
constructor(url) {
|
||||
if (connections[url]) {
|
||||
error(`Connection to ${url} already exists`)
|
||||
}
|
||||
|
||||
this.ws = null
|
||||
this.url = url
|
||||
this.ready = null
|
||||
@@ -39,7 +36,7 @@ export class Relay {
|
||||
async connect() {
|
||||
if (this.status === Relay.STATUS.NEW) {
|
||||
if (this.ws) {
|
||||
error("Attempted to connect when already connected", this)
|
||||
console.error("Attempted to connect when already connected", this)
|
||||
}
|
||||
|
||||
this.ready = defer()
|
||||
@@ -47,7 +44,7 @@ export class Relay {
|
||||
this.status = Relay.STATUS.PENDING
|
||||
|
||||
this.ws.addEventListener("open", () => {
|
||||
log(`Opened connection to ${this.url}`)
|
||||
console.log(`Opened connection to ${this.url}`)
|
||||
|
||||
this.status = Relay.STATUS.READY
|
||||
this.ready.resolve()
|
||||
@@ -57,12 +54,12 @@ export class Relay {
|
||||
this.queue.push(e.data)
|
||||
|
||||
if (!this.timeout) {
|
||||
this.timeout = global.setTimeout(() => this.handleMessages(), 10)
|
||||
this.timeout = setTimeout(() => this.handleMessages(), 10)
|
||||
}
|
||||
})
|
||||
|
||||
this.ws.addEventListener("error", e => {
|
||||
log(`Error on connection to ${this.url}`)
|
||||
console.log(`Error on connection to ${this.url}`)
|
||||
|
||||
this.disconnect()
|
||||
this.ready.reject()
|
||||
@@ -71,7 +68,7 @@ export class Relay {
|
||||
})
|
||||
|
||||
this.ws.addEventListener("close", () => {
|
||||
log(`Closed connection to ${this.url}`)
|
||||
console.log(`Closed connection to ${this.url}`)
|
||||
|
||||
this.disconnect()
|
||||
this.ready.reject()
|
||||
@@ -83,7 +80,7 @@ export class Relay {
|
||||
}
|
||||
disconnect() {
|
||||
if (this.ws) {
|
||||
log(`Disconnecting from ${this.url}`)
|
||||
console.log(`Disconnecting from ${this.url}`)
|
||||
|
||||
this.ws.close()
|
||||
this.ws = null
|
||||
@@ -98,10 +95,12 @@ export class Relay {
|
||||
continue
|
||||
}
|
||||
|
||||
this.bus.handle(...message)
|
||||
const [verb, ...args] = message
|
||||
|
||||
this.bus.handle(verb, ...args)
|
||||
}
|
||||
|
||||
this.timeout = this.queue.length > 0 ? global.setTimeout(() => this.handleMessages(), 10) : null
|
||||
this.timeout = this.queue.length > 0 ? setTimeout(() => this.handleMessages(), 10) : null
|
||||
}
|
||||
send(...payload) {
|
||||
if (this.ws?.readyState !== 1) {
|
||||
@@ -112,8 +111,8 @@ export class Relay {
|
||||
}
|
||||
subscribe(filters, id, {onEvent, onEose}) {
|
||||
const [eventChannel, eoseChannel] = [
|
||||
this.bus.on("EVENT", (subid, e) => subid === id && onEvent(e)),
|
||||
this.bus.on("EOSE", subid => subid === id && onEose()),
|
||||
this.bus.on("EVENT", (subid, e) => subid === id && onEvent?.(e)),
|
||||
this.bus.on("EOSE", subid => subid === id && onEose?.()),
|
||||
]
|
||||
|
||||
this.send("REQ", id, ...filters)
|
||||
|
||||
Generated
+6476
-454
File diff suppressed because it is too large
Load Diff
+37
-23
@@ -1,38 +1,52 @@
|
||||
{
|
||||
"name": "paravel",
|
||||
"version": "1.0.0",
|
||||
"version": "0.1.4",
|
||||
"description": "Yet another toolkit for nostr",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"main": "./dist/paravel.umd.js",
|
||||
"module": "./dist/paravel.es.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/staab/paravel.git"
|
||||
},
|
||||
"main": "./dist/paravel.cjs",
|
||||
"module": "./dist/paravel.esm.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/paravel.es.js",
|
||||
"require": "./dist/paravel.umd.js"
|
||||
}
|
||||
"import": "./dist/paravel.esm.js",
|
||||
"require": "./dist/paravel.cjs"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"check:fmt": "prettier --check lib/*",
|
||||
"check": "run-p check:*",
|
||||
"format": "prettier --write lib/*"
|
||||
"build": "node build.js",
|
||||
"pub": "npm i && node build.js && npm publish",
|
||||
"check:ts": "tsc --noEmit --esModuleInterop lib/*",
|
||||
"check:es": "eslint lib/*",
|
||||
"check": "run-p check:*"
|
||||
},
|
||||
"keywords": [],
|
||||
"keywords": [
|
||||
"nostr"
|
||||
],
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@tsconfig/recommended": "^1.0.2",
|
||||
"prettier": "^2.8.7",
|
||||
"vite": "^4.2.1"
|
||||
"@babel/core": "^7.20.7",
|
||||
"@babel/preset-typescript": "^7.18.6",
|
||||
"@types/node": "^18.0.3",
|
||||
"@types/ws": "^8.5.4",
|
||||
"@typescript-eslint/eslint-plugin": "^5.56.0",
|
||||
"@typescript-eslint/parser": "^5.56.0",
|
||||
"esbuild": "0.16.9",
|
||||
"esbuild-plugin-alias": "^0.2.1",
|
||||
"eslint": "^8.30.0",
|
||||
"eslint-config-prettier": "^8.6.0",
|
||||
"eslint-plugin-babel": "^5.3.1",
|
||||
"esm-loader-import-relative-extension": "^1.0.8",
|
||||
"esm-loader-typescript": "^1.0.3",
|
||||
"node-esm-loader": "^0.0.3",
|
||||
"prettier": "2.8.3",
|
||||
"tsd": "^0.22.0",
|
||||
"typescript": "^4.9.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"husky": "^8.0.3",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"typescript": "^5.0.2",
|
||||
"ws": "^8.13.0"
|
||||
"isomorphic-ws": "^5.0.0",
|
||||
"nostr-tools": "^1.7.5",
|
||||
"npm-run-all": "^4.1.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "esnext",
|
||||
"target": "esnext",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"declaration": true,
|
||||
"strict": true,
|
||||
"moduleResolution": "node",
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"outDir": "dist",
|
||||
"rootDir": ".",
|
||||
"useDefineForClassFields": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": false,
|
||||
"importsNotUsedAsValues": "preserve"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user