Skip to content

Commit

Permalink
improve nip11 validation + add json highlighting block
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Jan 15, 2025
1 parent 2dceafe commit d34f74f
Show file tree
Hide file tree
Showing 191 changed files with 1,167 additions and 947 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A Typescript stack for monitoring, auditing, describing and validating anything
| @nostrwatch/gui | webapp | NIP-66 nostr client. | alpha || | | |
| @nostrwatch/trawler | agent | Scraps all of the known nostr-verse for relays, sanitizes and dedupes them. | alpha | || | rewrite imminent |
| @nostrwatch/nocapd | agent | Persistently checks relays on a regular interval with many configuration options. | alpha | || | rewrite imminent |
| @nostrwatch/nip66 | library | Library that manages NIP-66 aggregation control flow and provides utilities that help conform to NIP-66 | alpha ||| | |
| @nostrwatch/route66 | library | Library that manages NIP-66 aggregation control flow and provides utilities that help conform to NIP-66 | alpha ||| | |
| @nostrwatch/auditor | library | Checks relays against their advertised supported nips and runs a variety of passive validations along the way. | alpha |||| |
| @nostrwatch/nocap | library | Extensible library for checking relay liveness via websocket and optionally fetches geodata, SSL, NIP-11 and DNS | alpha ||| | |
| @nostrwatch/schemata | library | JSON-Schemas for low-level protocol JSON, note kinds, protocol messages and NIP-11 information documents. | alpha ||| | |
Expand Down
7 changes: 4 additions & 3 deletions apps/gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@
"dependencies": {
"@careswitch/svelte-data-table": "^0.6.3",
"@nostrwatch/auditor": "workspace:*",
"@nostrwatch/nip66": "workspace:^",
"@nostrwatch/nip66-cacheadapter-nostrsqlite": "workspace:^",
"@nostrwatch/nip66-wsadapter-nostrtools": "workspace:^",
"@nostrwatch/nocap": "workspace:^",
"@nostrwatch/nocap-websocket-adapter-default": "workspace:^",
"@nostrwatch/route66": "workspace:^",
"@nostrwatch/route66-cacheadapter-nostrsqlite": "workspace:^",
"@nostrwatch/route66-wsadapter-nostrtools": "workspace:^",
"@nostrwatch/schemata-js-ajv": "workspace:^",
"@nostrwatch/utils": "workspace:^",
"@nostrwatch/worker-relay": "workspace:^",
Expand All @@ -117,6 +117,7 @@
"dexie": "^4.0.8",
"dompurify": "^3.2.3",
"iso-3166": "^4.3.0",
"json-source-map": "^0.6.1",
"light-bolt11-decoder": "^3.2.0",
"lodash": "^4.17.21",
"lucide-svelte": "^0.462.0",
Expand Down
4 changes: 2 additions & 2 deletions apps/gui/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default [
css({ output: 'bundle.css' }),
resolve({
browser: true,
dedupe: ['svelte', '@nostrwatch/nip66', '@nostrwatch/nip66-cacheadapter-dexieetl', '@nostrwatch/nip66-wsadapter-nostrtools'],
dedupe: ['svelte', '@nostrwatch/route66', '@nostrwatch/route66-cacheadapter-dexieetl', '@nostrwatch/route66-wsadapter-nostrtools'],
exportConditions: ['svelte']
}),
commonjs({
Expand Down Expand Up @@ -84,7 +84,7 @@ export default [
css({ output: 'bundle.css' }),
resolve({
browser: true,
dedupe: ['svelte', '@nostrwatch/nip66', '@nostrwatch/nip66-cacheadapter-dexieetl', '@nostrwatch/nip66-wsadapter-nostrtools'],
dedupe: ['svelte', '@nostrwatch/route66', '@nostrwatch/route66-cacheadapter-dexieetl', '@nostrwatch/route66-wsadapter-nostrtools'],
exportConditions: ['svelte']
}),
commonjs(),
Expand Down
77 changes: 77 additions & 0 deletions apps/gui/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
declare module 'json-source-map' {
// Options for parsing JSON, allowing for custom behavior such as bigint support and jsonc (JSON with comments).
export interface ParseOptions {
bigint?: boolean; // Specifies if BigInt values should be parsed as native BigInt types.
jsonc?: boolean; // Specifies if JSON with comments (jsonc) should be correctly parsed.
}

// Options for stringifying values into JSON, allowing for customization of the output.
export interface StringifyOptions {
space?: string | number; // Specifies the indentation for beautifying the output JSON.
es6?: boolean; // Specifies if ES6 features (e.g., Set, Map) are allowed in the output.
}

// The result of parsing JSON, including the data and pointers to various elements within the JSON string.
export interface ParseResult {
data: any; // The parsed data as a JavaScript object.
pointers: {
[key: string]: {
value: { // The starting position of the value in the original JSON string.
line: number;
column: number;
pos: number;
};
valueEnd: { // The ending position of the value in the original JSON string.
line: number;
column: number;
pos: number;
};
key?: { // The starting position of the key in the original JSON string (for object properties).
line: number;
column: number;
pos: number;
};
keyEnd?: { // The ending position of the key in the original JSON string (for object properties).
line: number;
column: number;
pos: number;
};
};
};
}

// The result of stringifying a JavaScript value into JSON, including the JSON string and pointers to elements.
export interface StringifyResult {
json: string; // The generated JSON string.
pointers: {
[key: string]: {
value: { // The starting position of the value in the resulting JSON string.
line: number;
column: number;
pos: number;
};
valueEnd: { // The ending position of the value in the resulting JSON string.
line: number;
column: number;
pos: number;
};
key?: { // The starting position of the key in the resulting JSON string (for object properties).
line: number;
column: number;
pos: number;
};
keyEnd?: { // The ending position of the key in the resulting JSON string (for object properties).
line: number;
column: number;
pos: number;
};
};
};
}

// Parses a JSON string into a JavaScript object, with options for handling BigInt and comments (jsonc).
export function parse(json: string, _?: any, options?: ParseOptions): ParseResult;

// Converts a JavaScript value to a JSON string, with options for output formatting and ES6 feature inclusion.
export function stringify(value: any, _?: any, options?: string | number | StringifyOptions): StringifyResult;
}
2 changes: 1 addition & 1 deletion apps/gui/src/lib/components/layout/Stats.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
isps,
monitors
} from '$lib/stores/index.js';
import { StateManager } from '@nostrwatch/nip66';
import { StateManager } from '@nostrwatch/route66';
import { hasBeenBoostrapped } from '$lib/stores/app';
let eventsCount = StateManager.get('count:events:checks');
Expand Down
2 changes: 1 addition & 1 deletion apps/gui/src/lib/components/lists/table/DataTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import { Input } from '$lib/components/ui/input/index.js';
import { Badge } from '$lib/components/ui/badge/index.js';
import * as Table from '$lib/components/ui/table/index.js';
import { StateManager } from '@nostrwatch/nip66';
import { StateManager } from '@nostrwatch/route66';
import TableOptions from './TableOptions.svelte';
import * as Popover from "$lib/components/ui/popover";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import Checkbox from "../../ui/checkbox/checkbox.svelte";
import { StateManager } from "@nostrwatch/nip66";
import { StateManager } from "@nostrwatch/route66";
import type { Writable } from "svelte/store";
import { capitalize, delay } from "@nostrwatch/utils";
import type { DataTableConfig, Formatters } from "./DataTableTypes";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import Checkbox from "../../ui/checkbox/checkbox.svelte";
import { StateManager } from "@nostrwatch/nip66";
import { StateManager } from "@nostrwatch/route66";
import type { Writable } from "svelte/store";
import { capitalize } from "@nostrwatch/utils";
import type { DataTableConfig } from "./DataTableTypes";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { relayAggregates, relaysForMiniSearch } from "$lib/stores/checks.js";
import { StateManager } from "@nostrwatch/nip66";
import { StateManager } from "@nostrwatch/route66";
import AutoSuggest from "./AutoSuggest.svelte";
import * as searchConfig from "$lib/stores/search-relays.js";
import { derived } from "svelte/store";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { relayAggregates, relaysForMiniSearch } from "$lib/stores/checks.js";
import { StateManager } from "@nostrwatch/nip66";
import { StateManager } from "@nostrwatch/route66";
import AutoSuggest from "./AutoSuggest.svelte";
import * as searchConfig from "$lib/stores/search-relays.js";
Expand Down
15 changes: 15 additions & 0 deletions apps/gui/src/lib/components/partials/JsonHighlighter.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script lang="ts">
// import { onMount } from 'svelte';
import { JsonHighlighter, type AjvResult } from '$lib/utils/JsonHighlighter.js';
export let jsonString: string = '';
export let ajvResult: AjvResult = { errors: [] };
let highlightedHtml = '';
$: highlightedHtml = JsonHighlighter.highlight(jsonString, ajvResult);
</script>

{@html highlightedHtml}

<style></style>

12 changes: 6 additions & 6 deletions apps/gui/src/lib/components/partials/MonitorActions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import * as Table from '$lib/components/ui/table/index.js'
import { monitorsMap } from "$lib/stores/monitors.js";
import type { IEvent, Monitor } from '@nostrwatch/nip66/models';
import type { IEvent, Monitor } from '@nostrwatch/route66/models';
import { events, eventsArray } from '$lib/stores/events.js';
import { nip66 } from '$lib/stores';
import type Nip66 from '@nostrwatch/nip66';
import { route66 } from '$lib/stores';
import type Route66 from '@nostrwatch/route66';
import { onMount } from 'svelte';
import { eventKey } from '$lib/utils/event-keys';
import { activeMonitorChecksCount } from '$lib/stores';
Expand Down Expand Up @@ -55,18 +55,18 @@
sync: true,
batch: 25
},
relays: [ ...($nip66?.services?.monitors?.nip66Relays || []), ...monitor.relays ],
relays: [ ...($route66?.services?.monitors?.nip66Relays || []), ...monitor.relays ],
priority: 20
}
const onevents = (events: IEvent[]) => {
addEventsToStore(events)
}
await $nip66?.services?.monitors?.sync(options, { onevents })
await $route66?.services?.monitors?.sync(options, { onevents })
disabled.set(false);
await resumer();
}
$nip66?.services?.monitors?.manager?.updateMonitor?.(monitor)
$route66?.services?.monitors?.manager?.updateMonitor?.(monitor)
}
})
Expand Down
2 changes: 1 addition & 1 deletion apps/gui/src/lib/components/partials/MonitorDataRow.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { type Monitor } from '@nostrwatch/nip66/models';
import { type Monitor } from '@nostrwatch/route66/models';
import { monitorChecksCount } from '$lib/stores/monitors.js';
import Badge from '$lib/components/ui/badge/Badge.svelte';
import { PFP } from '$lib/utils/pfp.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { type Monitor } from '@nostrwatch/nip66/models';
import { type Monitor } from '@nostrwatch/route66/models';
import { PFP } from '$lib/utils/pfp.js';
export let monitor: Monitor;
Expand Down
2 changes: 1 addition & 1 deletion apps/gui/src/lib/components/partials/Nip66Check.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import * as Tabs from "$lib/components/ui/tabs";
import { Monitor, type Nip66Event } from '@nostrwatch/nip66/models';
import { Monitor, type Nip66Event } from '@nostrwatch/route66/models';
import { onMount } from 'svelte';
import { formatSeconds, timeAgo } from '$lib/utils/time.js';
import { clickToCopy } from "$lib/utils/ux";
Expand Down
2 changes: 1 addition & 1 deletion apps/gui/src/lib/components/partials/ProfileCompact.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { type Monitor, type PubkeyProfile } from '@nostrwatch/nip66/models';
import { type Monitor, type PubkeyProfile } from '@nostrwatch/route66/models';
import { PFP } from '$lib/utils/pfp.js';
export let pubkey: string;
Expand Down
4 changes: 2 additions & 2 deletions apps/gui/src/lib/components/partials/RelayMap.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import { writable, type Writable } from 'svelte/store';
import { MapPointLabelPosition, type MapData, type MapLink } from '@unovis/ts'
import { WorldMapTopoJSON } from '@unovis/ts/maps'
import type { Monitor, Nip66Event } from '@nostrwatch/nip66/models';
import { StateManager } from '@nostrwatch/nip66';
import type { Monitor, Nip66Event } from '@nostrwatch/route66/models';
import { StateManager } from '@nostrwatch/route66';
export let relay: string;
export let monitors: Writable<Monitor[]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import Masonry from 'svelte-bricks'
import type Nip66 from "@nostrwatch/nip66"
import { nip66 } from '$lib/stores';
import type Route66 from "@nostrwatch/route66"
import { route66 } from '$lib/stores';
import { isLivesyncing } from '$lib/stores/app';
Expand Down Expand Up @@ -60,7 +60,7 @@
wasLivesyncing = true;
stopLiveSync()
}
const instance: Nip66 = get(nip66);
const instance: Route66 = get(route66);
while(!instance || !instance.ready) {
await new Promise(resolve => setTimeout(resolve, 100));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { UserFeedItem } from '$lib/services/UserService';
import { parseNote } from '$lib/utils/notes';
import { timeAgo } from '$lib/utils/time';
import type { IEvent } from '@nostrwatch/nip66/models/Event';
import type { IEvent } from '@nostrwatch/route66/models/Event';
import type { UserFeedItemRelatives } from '$lib/services/UserService';
import { observeViewport } from '$lib/utils/ux';
import { onDestroy, onMount } from 'svelte';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<script lang="ts">
import type { Nip66Event } from "@nostrwatch/nip66/models";
import type { Nip66Event } from "@nostrwatch/route66/models";
import { formatRelayUrl } from "$lib/utils/routing.js";
import type { Writable } from "svelte/store";
import type Nip66 from "@nostrwatch/nip66";
import type Route66 from "@nostrwatch/route66";
export let event: Nip66Event;
export let nip66: Writable<Nip66>;
export let route66: Writable<Route66>;
$: status =
$nip66?.services?.monitors?.manager?.isRelayOnline(event)
$route66?.services?.monitors?.manager?.isRelayOnline(event)
? 'online'
: $nip66?.services?.monitors?.manager?.isRelayDead(event)
: $route66?.services?.monitors?.manager?.isRelayDead(event)
? 'dead'
: 'offline'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import { derived, writable, type Writable } from 'svelte/store';
import { eventsArray, nip66 } from '$lib/stores';
import { type IEvent, Monitor, Nip66Event } from '@nostrwatch/nip66/models';
import { eventsArray, route66 } from '$lib/stores';
import { type IEvent, Monitor, Nip66Event } from '@nostrwatch/route66/models';
import OperatorRelay from './OperatorRelay.svelte';
export let pubkey: string;
Expand All @@ -16,8 +16,8 @@
const deadRelays: Writable<Nip66Event[]> = writable([])
const fetchDeadRelays = async () => {
if(!$nip66) return;
const deadRelays = await $nip66.services.monitors.fetchOperatorRelaysNotOnline(pubkey) || []
if(!$route66) return;
const deadRelays = await $route66.services.monitors.fetchOperatorRelaysNotOnline(pubkey) || []
//console.log('dead relays fetched:', deadRelays.length)
deadRelays?.forEach( (event: IEvent) => {
deadRelays.update( ( events: Nip66Event[] ): Nip66Event[] => {
Expand All @@ -37,20 +37,20 @@
});
const mount = async () => {
if(!$nip66) return;
await $nip66.ready();
if(!$route66) return;
await $route66.ready();
fetchDeadRelays()
}
const destroy = async () => {
// await $nip66.shutdown()
// await $route66.shutdown()
}
onMount(mount)
onDestroy(destroy)
</script>
{#if pubkey}
{#each $operatorRelays as event}
<OperatorRelay {event} {nip66} />
<OperatorRelay {event} {route66} />
{/each}
{/if}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { pauseLiveSync } from '$lib/utils/lifecycle.js'; // Update the path as necessary
import type { Note } from "nostr-tools/nip19";
import Badge from "../../ui/badge/badge.svelte";
import type { Nip11 } from "@nostrwatch/nip66/models";
import type { Nip11 } from "@nostrwatch/route66/models";
import * as Alert from "$lib/components/ui/alert/index.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import Nip66Check from "$lib/components/partials/Nip66Check.svelte";
import ProfileCompact from '../ProfileCompact.svelte';
import type { Monitor } from "@nostrwatch/nip66/models";
import type { Monitor } from "@nostrwatch/route66/models";
import { monitors } from '$lib/stores/monitors.js';
import { PFP } from '$lib/utils/pfp.js';
Expand Down
Loading

0 comments on commit d34f74f

Please sign in to comment.