Skip to content

Instantly share code, notes, and snippets.

View snuffyDev's full-sized avatar
😮‍💨
nice

snuffy snuffyDev

😮‍💨
nice
View GitHub Profile
/**
* TODO: clean this module up massively.
*
* - Use class instead of func impl (...?)
*
*/
import type { Item, Nullable } from "$lib/types";
import { Logger, addToQueue, getSrc, notify, seededShuffle, type ResponseBody } from "$lib/utils";
import { Mutex } from "$lib/utils/sync";
import { splice } from "$lib/utils/collections/array";
let intersectionObserver: IntersectionObserver;
const observerCallback = (entries: IntersectionObserverEntry[], ob) => {
for (let idx = 0; idx < entries.length; idx++) {
const entry = entries[idx];
const target = entry.target as HTMLImageElement;
if (entry.isIntersecting) {
target.decode().finally(() => {
target.src = target.dataset.src;
export function buildCron() {
const { update, subscribe, set } = writable<Cron>({
seconds: 0,
minutes: 0,
hours: "*",
month: "*",
dayOfMonth: "*",
days: "*",
});
/* eslint-disable @typescript-eslint/no-inferrable-types */
import { browser } from "$app/environment";
import { cubicOut } from "svelte/easing";
import { tweened } from "svelte/motion";
import type { Unsubscriber } from "svelte/store";
import { get } from "svelte/store";
import SessionListService, { type ISessionListProvider } from "./stores/list";
import { groupSession, type ConnectionState } from "./stores/sessions";
import { currentTitle } from "./stores/stores";
import type { Nullable } from "./types";
import { writable } from "svelte/store";
export type CronValue = "*" | `${"*" | number | string}/${number | string}` | `${string}/${string}` | string | number;
export type Cron = {
seconds: CronValue;
minutes: CronValue;
hours: CronValue;
month: CronValue;
dayOfMonth: CronValue;
days: (number | string)[] | "*";
let textDecoder: TextDecoder;
let textEncoder: TextEncoder = new TextEncoder();
type BufferEncoding =
| "ascii"
| "utf8"
| "utf-8"
| "utf16le"
| "ucs2"
| "ucs-2"
| "base64"
const _onEvent: onEventStore = (storeFn: (events: EventOrProfile[]) => Promise<void>) => {
let cursorIdx = 0;
let currentBatch: EventOrProfile[] = []
let isTaking = false;
const pool = new Map<number, EventOrProfile[]>([]);
let allEventIds: Set<string> = new Set([])
let size = 0;
function add(event: IEvent) {
if (event.id && allEventIds.has(event.id)) return;
export class LazyIterator<T extends any[] = any[]> {
#_: T[] = [] as T
#_iterator: IterableIterator<T> | Generator<T>
// #fnQueue: ((...args: T[number]) => T[number] | boolean)[] = []
constructor(...entries: readonly [...T[]])
constructor(entries: readonly T[])
constructor(entries: T) {
this.#elements = entries;
import { browser } from "./internals/utils";
import { Worker as NodeWorker } from "./internals/NodeWorker.js";
import { BroadcastChannel } from "./threads/channel";
import { StatusCode } from "./models";
import type {
GetReturnType,
IThreadSpawner,
} from "./models/thread";
const TEMPLATE_NODE = `const { parentPort } = require('worker_threads');
// import { relayPool } from 'nostr-tools';
// import { validateEvent } from 'nostr-tools';
import { relayPool, type RelayPool } from './lib/nostr-tools';
import { validateEvent } from './lib/nostr-tools';
import { db } from './db';
import type { IProfile, IEvent } from './db';
import { snooze, setImmediate, yieldMicrotask } from './utils';
export class $Data {
public pool!: RelayPool;
private allEventIds!: Set<string>