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
|
node_modules
|
||||||
|
dist
|
||||||
|
|||||||
Regular → Executable
-1
@@ -2,4 +2,3 @@
|
|||||||
. "$(dirname -- "$0")/_/husky.sh"
|
. "$(dirname -- "$0")/_/husky.sh"
|
||||||
|
|
||||||
npm run check
|
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()
|
const normalizeUrl = url => url.replace(/\/+$/, "").toLowerCase().trim()
|
||||||
|
|
||||||
export class Pool {
|
export class Pool {
|
||||||
|
relays: Map<string, Relay>
|
||||||
constructor() {
|
constructor() {
|
||||||
this.relays = new Map()
|
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"
|
import {Deferred, defer} from "./Deferred"
|
||||||
|
|
||||||
export class Relay {
|
export class Relay {
|
||||||
@@ -8,7 +9,7 @@ export class Relay {
|
|||||||
queue: string[]
|
queue: string[]
|
||||||
error: string
|
error: string
|
||||||
status: string
|
status: string
|
||||||
timeout?: number
|
timeout?: NodeJS.Timeout
|
||||||
bus: EventBus
|
bus: EventBus
|
||||||
static STATUS = {
|
static STATUS = {
|
||||||
NEW: "new",
|
NEW: "new",
|
||||||
@@ -23,10 +24,6 @@ export class Relay {
|
|||||||
FORBIDDEN: "forbidden",
|
FORBIDDEN: "forbidden",
|
||||||
}
|
}
|
||||||
constructor(url) {
|
constructor(url) {
|
||||||
if (connections[url]) {
|
|
||||||
error(`Connection to ${url} already exists`)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.ws = null
|
this.ws = null
|
||||||
this.url = url
|
this.url = url
|
||||||
this.ready = null
|
this.ready = null
|
||||||
@@ -39,7 +36,7 @@ export class Relay {
|
|||||||
async connect() {
|
async connect() {
|
||||||
if (this.status === Relay.STATUS.NEW) {
|
if (this.status === Relay.STATUS.NEW) {
|
||||||
if (this.ws) {
|
if (this.ws) {
|
||||||
error("Attempted to connect when already connected", this)
|
console.error("Attempted to connect when already connected", this)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ready = defer()
|
this.ready = defer()
|
||||||
@@ -47,7 +44,7 @@ export class Relay {
|
|||||||
this.status = Relay.STATUS.PENDING
|
this.status = Relay.STATUS.PENDING
|
||||||
|
|
||||||
this.ws.addEventListener("open", () => {
|
this.ws.addEventListener("open", () => {
|
||||||
log(`Opened connection to ${this.url}`)
|
console.log(`Opened connection to ${this.url}`)
|
||||||
|
|
||||||
this.status = Relay.STATUS.READY
|
this.status = Relay.STATUS.READY
|
||||||
this.ready.resolve()
|
this.ready.resolve()
|
||||||
@@ -57,12 +54,12 @@ export class Relay {
|
|||||||
this.queue.push(e.data)
|
this.queue.push(e.data)
|
||||||
|
|
||||||
if (!this.timeout) {
|
if (!this.timeout) {
|
||||||
this.timeout = global.setTimeout(() => this.handleMessages(), 10)
|
this.timeout = setTimeout(() => this.handleMessages(), 10)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
this.ws.addEventListener("error", e => {
|
this.ws.addEventListener("error", e => {
|
||||||
log(`Error on connection to ${this.url}`)
|
console.log(`Error on connection to ${this.url}`)
|
||||||
|
|
||||||
this.disconnect()
|
this.disconnect()
|
||||||
this.ready.reject()
|
this.ready.reject()
|
||||||
@@ -71,7 +68,7 @@ export class Relay {
|
|||||||
})
|
})
|
||||||
|
|
||||||
this.ws.addEventListener("close", () => {
|
this.ws.addEventListener("close", () => {
|
||||||
log(`Closed connection to ${this.url}`)
|
console.log(`Closed connection to ${this.url}`)
|
||||||
|
|
||||||
this.disconnect()
|
this.disconnect()
|
||||||
this.ready.reject()
|
this.ready.reject()
|
||||||
@@ -83,7 +80,7 @@ export class Relay {
|
|||||||
}
|
}
|
||||||
disconnect() {
|
disconnect() {
|
||||||
if (this.ws) {
|
if (this.ws) {
|
||||||
log(`Disconnecting from ${this.url}`)
|
console.log(`Disconnecting from ${this.url}`)
|
||||||
|
|
||||||
this.ws.close()
|
this.ws.close()
|
||||||
this.ws = null
|
this.ws = null
|
||||||
@@ -98,10 +95,12 @@ export class Relay {
|
|||||||
continue
|
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) {
|
send(...payload) {
|
||||||
if (this.ws?.readyState !== 1) {
|
if (this.ws?.readyState !== 1) {
|
||||||
@@ -112,8 +111,8 @@ export class Relay {
|
|||||||
}
|
}
|
||||||
subscribe(filters, id, {onEvent, onEose}) {
|
subscribe(filters, id, {onEvent, onEose}) {
|
||||||
const [eventChannel, eoseChannel] = [
|
const [eventChannel, eoseChannel] = [
|
||||||
this.bus.on("EVENT", (subid, e) => subid === id && onEvent(e)),
|
this.bus.on("EVENT", (subid, e) => subid === id && onEvent?.(e)),
|
||||||
this.bus.on("EOSE", subid => subid === id && onEose()),
|
this.bus.on("EOSE", subid => subid === id && onEose?.()),
|
||||||
]
|
]
|
||||||
|
|
||||||
this.send("REQ", id, ...filters)
|
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",
|
"name": "paravel",
|
||||||
"version": "1.0.0",
|
"version": "0.1.4",
|
||||||
"description": "Yet another toolkit for nostr",
|
"description": "Yet another toolkit for nostr",
|
||||||
"files": [
|
"repository": {
|
||||||
"dist"
|
"type": "git",
|
||||||
],
|
"url": "https://github.com/staab/paravel.git"
|
||||||
"main": "./dist/paravel.umd.js",
|
},
|
||||||
"module": "./dist/paravel.es.js",
|
"main": "./dist/paravel.cjs",
|
||||||
|
"module": "./dist/paravel.esm.js",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
"import": "./dist/paravel.esm.js",
|
||||||
"import": "./dist/paravel.es.js",
|
"require": "./dist/paravel.cjs"
|
||||||
"require": "./dist/paravel.umd.js"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"build": "node build.js",
|
||||||
"build": "vite build",
|
"pub": "npm i && node build.js && npm publish",
|
||||||
"preview": "vite preview",
|
"check:ts": "tsc --noEmit --esModuleInterop lib/*",
|
||||||
"check:fmt": "prettier --check lib/*",
|
"check:es": "eslint lib/*",
|
||||||
"check": "run-p check:*",
|
"check": "run-p check:*"
|
||||||
"format": "prettier --write lib/*"
|
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [
|
||||||
|
"nostr"
|
||||||
|
],
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tsconfig/recommended": "^1.0.2",
|
"@babel/core": "^7.20.7",
|
||||||
"prettier": "^2.8.7",
|
"@babel/preset-typescript": "^7.18.6",
|
||||||
"vite": "^4.2.1"
|
"@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": {
|
"dependencies": {
|
||||||
"husky": "^8.0.3",
|
"husky": "^8.0.3",
|
||||||
"npm-run-all": "^4.1.5",
|
"isomorphic-ws": "^5.0.0",
|
||||||
"typescript": "^5.0.2",
|
"nostr-tools": "^1.7.5",
|
||||||
"ws": "^8.13.0"
|
"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