···1+CREATE TABLE `auth_session` (
2+ `key` text PRIMARY KEY NOT NULL,
3+ `session` text NOT NULL
4+);
5+--> statement-breakpoint
6+CREATE TABLE `auth_state` (
7+ `key` text PRIMARY KEY NOT NULL,
8+ `state` text NOT NULL
9+);
10+--> statement-breakpoint
11+CREATE TABLE `status` (
12+ `uri` text PRIMARY KEY NOT NULL,
13+ `authorDid` text NOT NULL,
14+ `status` text NOT NULL,
15+ `createdAt` text NOT NULL,
16+ `indexedAt` text NOT NULL
17+);
···1+PRIVATE_KEY_1={"kty":"EC","d":"8rx-D2vaik7FgRUaMeK_M8yZQ57J5NFs4MP6300_gek","use":"sig","crv":"P-256","kid":"44J2ZYr_4O3wp1B8GSRPvHMb7Cf506Nss3ISOplRx9I","x":"f9RLs9sqKyL38dPKsQaX-P_qTHVnNRCXuzkjbPvh7Ls","y":"ZnH5GuTAl5TTb-hZzsVgf1kUl4OB6qCS0PmM4_SPXvw","alg":"ES256"}
2+PRIVATE_KEY_2={"kty":"EC","d":"5Rk8UuCz-chUX_OZ4WgB7lb3OELn-xlGEedk4P-qY_M","use":"sig","crv":"P-256","kid":"kzDrzoJdNtK3bfTiuJYQZSk_Z7nsZqEpzqYSqHVBN_Q","x":"WuMNQ3slMhmvUJze-q4pxmC_Xqu5MkpkD3eSh1dPDBs","y":"0CS96lObk2UWnRbbrhQQDbduyZ_A4zKZtwSQTfqVkcU","alg":"ES256"}
3+PRIVATE_KEY_3={"kty":"EC","d":"GvpzAoGaHCG3OFe8qqi8FRs3WShGvS8OAOhjcN2vyuQ","use":"sig","crv":"P-256","kid":"y0HFLgCqOSwfbRJdO48dM8prLrLrT-qxNs_UrdvrbNQ","x":"VJ13t663tWZa67wUNQw26iU9iatIg4ZIklNKOrqMiYw","y":"Fqyc7qiOfwaYDXO259G8T66Wg2Kf_WLEjyi0ZenX2pI","alg":"ES256"}
4+NODE_ENV=development # Options: development, production
5+PORT=3000 # The port your server will listen on
6+HOST=localhost # Hostname for the server
7+PUBLIC_URL= # Set when deployed publicly, e.g. "https://mysite.com". Informs OAuth client id.
8+DB_PATH=:memory: # The SQLite database path. Leave as ":memory:" to use a temporary in-memory database.
9+# Secrets
10+# Must set this in production. May be generated with `openssl rand -base64 33`=undefined
11+# COOKIE_SECRET=""
···1+/**
2+ * GENERATED CODE - DO NOT MODIFY
3+ */
4+import { ValidationResult, BlobRef } from '@atproto/lexicon'
5+import { lexicons } from '../../../lexicons'
6+import { isObj, hasProp } from '../../../util'
7+import { CID } from 'multiformats/cid'
8+9+export interface Record {
10+ status: string
11+ createdAt: string
12+ [k: string]: unknown
13+}
14+15+export function isRecord(v: unknown): v is Record {
16+ return (
17+ isObj(v) &&
18+ hasProp(v, '$type') &&
19+ (v.$type === 'xyz.statusphere.status#main' ||
20+ v.$type === 'xyz.statusphere.status')
21+ )
22+}
23+24+export function validateRecord(v: unknown): ValidationResult {
25+ return lexicons.validate('xyz.statusphere.status#main', v)
26+}
+13
apps/aqua/src/lexicon/util.ts
···0000000000000
···1+/**
2+ * GENERATED CODE - DO NOT MODIFY
3+ */
4+export function isObj(v: unknown): v is Record<string, unknown> {
5+ return typeof v === 'object' && v !== null
6+}
7+8+export function hasProp<K extends PropertyKey>(
9+ data: object,
10+ prop: K,
11+): data is Record<K, unknown> {
12+ return prop in data
13+}
···1+// @ts-ignore
2+import ssr from "uhtml/ssr";
3+import type initSSR from "uhtml/types/init-ssr";
4+import type { Hole } from "uhtml/types/keyed";
5+6+export type { Hole };
7+8+export const { html }: ReturnType<typeof initSSR> = ssr();
9+10+export function page(hole: Hole) {
11+ return `<!DOCTYPE html>\n${hole.toDOM().toString()}`;
12+}
···1+package main
2+3+import (
4+ "fmt"
5+ "sync"
6+7+ server "viridian/server"
8+ worker "viridian/worker"
9+)
10+11+func main() {
12+ var wg sync.WaitGroup
13+14+ // Run the server in a goroutine
15+ go server.RunServer()
16+17+ // Simulate workers, each running in a separate goroutine
18+ workerCount := worker.GetCoreCount()
19+ fmt.Printf("Starting %d workers\n", workerCount)
20+ for i := 1; i <= workerCount; i++ {
21+ fmt.Printf("Starting worker %d\n", i)
22+ workerID := fmt.Sprintf("worker-%d", i)
23+ wg.Add(1)
24+ go worker.RunWorker(workerID, &wg)
25+ }
26+27+ // Wait for all workers to complete (this won't happen in this example since workers run indefinitely)
28+ wg.Wait()
29+}
···1+package server
2+3+import (
4+ "fmt"
5+ "time"
6+7+ "viridian/types"
8+9+ zmq "github.com/pebbe/zmq4"
10+)
11+12+// RunServer launches the server that distributes jobs to workers
13+func RunServer() {
14+ server := &types.Server{
15+ Jobs: []types.Job{{"job1", "pending"}, {"job2", "pending"}, {"job3", "pending"}},
16+ WorkerJobs: make(map[string]string),
17+ JobStatus: make(map[string]string),
18+ }
19+20+ // Initialize job status
21+ for _, job := range server.Jobs {
22+ server.JobStatus[job.ID] = "pending"
23+ }
24+25+ // Create a ZeroMQ ROUTER socket for distributing jobs
26+ socket, _ := zmq.NewSocket(zmq.ROUTER)
27+ defer socket.Close()
28+ socket.Bind("tcp://*:5555")
29+30+ for len(server.Jobs) > 0 {
31+ // Wait for a worker to send a ready message
32+ workerAddr, _ := socket.RecvMessage(0)
33+34+ fmt.Printf("Received ready message from worker %s\n", workerAddr)
35+36+ fmt.Print(workerAddr[2])
37+38+ // Lock jobs to pick the next one safely
39+ server.Mu.Lock()
40+ if len(server.Jobs) == 0 {
41+ server.Mu.Unlock()
42+ continue
43+ }
44+ job := server.Jobs[0]
45+ server.Jobs = server.Jobs[1:]
46+ server.Mu.Unlock()
47+48+ // Track the job for this worker
49+ server.TrackJob(workerAddr[0], job.ID)
50+51+ // Send job to the worker
52+ fmt.Printf("Sending job %s to worker %s\n", job.ID, workerAddr[0])
53+ socket.SendMessage(workerAddr[0], "", job.ID)
54+55+ time.Sleep(1 * time.Second) // Simulate a delay
56+57+ // In a real-world scenario, this would be based on a worker response
58+ server.MarkJobCompleted(workerAddr[0])
59+ }
60+61+ fmt.Println("All jobs processed")
62+}
+46
apps/viridian/types/types.go
···0000000000000000000000000000000000000000000000
···1+package types
2+3+import (
4+ "strconv"
5+ "sync"
6+)
7+8+// Job represents a job with an ID and status
9+type Job struct {
10+ ID string
11+ Status string
12+}
13+14+// Server represents the state of the server, including jobs, worker-job associations, and job status
15+type Server struct {
16+ Jobs []Job // Job queue
17+ WorkerJobs map[string]string // Mapping worker ID -> job ID
18+ JobStatus map[string]string // Mapping job ID -> status
19+ Mu sync.Mutex // Mutex to handle concurrency
20+}
21+22+func (s *Server) AddJob() Job {
23+ s.Mu.Lock()
24+ defer s.Mu.Unlock()
25+ job := Job{"job" + strconv.Itoa(len(s.Jobs)), "pending"}
26+ s.Jobs = append(s.Jobs, job)
27+28+ return job
29+}
30+31+// TrackJob assigns a job to a worker and marks it as in-progress
32+func (s *Server) TrackJob(workerID, jobID string) {
33+ s.Mu.Lock()
34+ defer s.Mu.Unlock()
35+ s.WorkerJobs[workerID] = jobID
36+ s.JobStatus[jobID] = "in-progress"
37+}
38+39+// MarkJobCompleted marks a job as completed and removes the worker-job association
40+func (s *Server) MarkJobCompleted(workerID string) {
41+ s.Mu.Lock()
42+ defer s.Mu.Unlock()
43+ jobID := s.WorkerJobs[workerID]
44+ s.JobStatus[jobID] = "completed"
45+ delete(s.WorkerJobs, workerID) // Remove worker-job association
46+}
···11 // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
1213 /* Language and Environment */
14- "target": "ES2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15 // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16 // "jsx": "preserve", /* Specify what JSX code is generated. */
17 // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
···25 // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
2627 /* Modules */
28- "module": "ES2022", /* Specify what module code is generated. */
29 // "rootDir": "./", /* Specify the root folder within your source files. */
30- "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
31 // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32- // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33 // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
34 // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
35- "types": ["bun-types"], /* Specify type package names to be included without being referenced in a source file. */
36 // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
37 // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
38 // "resolveJsonModule": true, /* Enable importing .json files. */
···71 /* Interop Constraints */
72 // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
73 // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
74- "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
75 // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
76- "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
7778 /* Type Checking */
79- "strict": true, /* Enable all strict type-checking options. */
80 // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
81 // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
82 // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
···9899 /* Completeness */
100 // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
101- "skipLibCheck": true /* Skip type checking all .d.ts files. */
102 }
103}
···11 // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
1213 /* Language and Environment */
14+ "target": "ES2021" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
15 // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16 // "jsx": "preserve", /* Specify what JSX code is generated. */
17 // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
···25 // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
2627 /* Modules */
28+ "module": "ES2022" /* Specify what module code is generated. */,
29 // "rootDir": "./", /* Specify the root folder within your source files. */
30+ "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
31 // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32+ //"paths": {} /* Specify a set of entries that re-map imports to additional lookup locations. */,
33 // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
34 // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
35+ // "types": [] /* Specify type package names to be included without being referenced in a source file. */,
36 // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
37 // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
38 // "resolveJsonModule": true, /* Enable importing .json files. */
···71 /* Interop Constraints */
72 // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
73 // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
74+ "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
75 // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
76+ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
7778 /* Type Checking */
79+ "strict": true /* Enable all strict type-checking options. */,
80 // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
81 // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
82 // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
···9899 /* Completeness */
100 // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
101+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
102 }
103}