-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a4f93e8
Showing
36 changed files
with
1,350 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Code quality | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
quality: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Setup Biome | ||
uses: biomejs/setup-biome@v2 | ||
with: | ||
version: latest | ||
- name: Run Biome | ||
run: biome ci . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
# Logs | ||
|
||
logs | ||
_.log | ||
npm-debug.log_ | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
|
||
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json | ||
|
||
# Runtime data | ||
|
||
pids | ||
_.pid | ||
_.seed | ||
\*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
|
||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
|
||
coverage | ||
\*.lcov | ||
|
||
# nyc test coverage | ||
|
||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
|
||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
|
||
bower_components | ||
|
||
# node-waf configuration | ||
|
||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
|
||
build/Release | ||
|
||
# Dependency directories | ||
|
||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
|
||
web_modules/ | ||
|
||
# TypeScript cache | ||
|
||
\*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
|
||
.npm | ||
|
||
# Optional eslint cache | ||
|
||
.eslintcache | ||
|
||
# Optional stylelint cache | ||
|
||
.stylelintcache | ||
|
||
# Microbundle cache | ||
|
||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
|
||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
|
||
\*.tgz | ||
|
||
# Yarn Integrity file | ||
|
||
.yarn-integrity | ||
|
||
# dotenv environment variable files | ||
|
||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
|
||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
|
||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
|
||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
|
||
.cache/ | ||
|
||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
|
||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
|
||
# public | ||
|
||
# vuepress build output | ||
|
||
.vuepress/dist | ||
|
||
# vuepress v2.x temp and cache directory | ||
|
||
.temp | ||
.cache | ||
|
||
# Docusaurus cache and generated files | ||
|
||
.docusaurus | ||
|
||
# Serverless directories | ||
|
||
.serverless/ | ||
|
||
# FuseBox cache | ||
|
||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
|
||
.dynamodb/ | ||
|
||
# TernJS port file | ||
|
||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
|
||
.vscode-test | ||
|
||
# yarn v2 | ||
|
||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.\* | ||
|
||
# wrangler project | ||
|
||
.dev.vars | ||
.wrangler/ | ||
worker-configuration.d.ts | ||
assets/built.css |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
;(() => { | ||
const v = localStorage.getItem('color-scheme') | ||
const a = window.matchMedia('(prefers-color-scheme: dark)').matches | ||
const cl = document.documentElement.classList | ||
const setColorScheme = (v) => | ||
(!v || v === 'auto' ? a : v === 'dark') ? cl.add('dark') : cl.remove('dark') | ||
setColorScheme(v) | ||
window.setColorScheme = (v) => { | ||
setColorScheme(v) | ||
localStorage.setItem('color-scheme', v) | ||
} | ||
window.toggleColorScheme = () => { | ||
const cl = document.documentElement.classList | ||
const currentScheme = cl.contains('dark') ? 'light' : 'dark' | ||
cl.toggle('dark') | ||
localStorage.setItem('color-scheme', currentScheme) | ||
} | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json", | ||
"organizeImports": { | ||
"enabled": true | ||
}, | ||
"vcs": { | ||
"enabled": true, | ||
"clientKind": "git" | ||
}, | ||
"javascript": { | ||
"formatter": { | ||
"enabled": true, | ||
"quoteStyle": "single", | ||
"semicolons": "asNeeded", | ||
"trailingComma": "none" | ||
} | ||
}, | ||
"linter": { | ||
"enabled": true, | ||
"rules": { | ||
"recommended": true | ||
} | ||
}, | ||
"formatter": { | ||
"enabled": true, | ||
"lineWidth": 80 | ||
}, | ||
"css": { | ||
"formatter": { | ||
"enabled": true | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
pre-commit: | ||
parallel: true | ||
commands: | ||
check: | ||
glob: '*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}' | ||
run: | ||
bunx biome check --apply --no-errors-on-unmatched | ||
--files-ignore-unknown=true {staged_files} && git update-index --again |
22 changes: 22 additions & 0 deletions
22
migrations/0000_create_events_and_probe_statuses_tables.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
-- Migration number: 0000 | ||
|
||
CREATE TABLE events ( | ||
id INTEGER PRIMARY KEY, | ||
created_at TEXT NOT NULL, | ||
probe_id TEXT, | ||
webhook_id TEXT, | ||
duration INTEGER, | ||
result TEXT NOT NULL, | ||
category TEXT NOT NULL, | ||
description TEXT | ||
) STRICT; | ||
|
||
CREATE TABLE probe_statuses ( | ||
id TEXT PRIMARY KEY, | ||
last_result TEXT NOT NULL, | ||
last_started_at TEXT NOT NULL, | ||
last_success_at TEXT, | ||
last_failure_at TEXT, | ||
same_result_since TEXT | ||
) STRICT; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CREATE TABLE log_lines ( | ||
id INTEGER PRIMARY KEY, | ||
created_at TEXT NOT NULL, | ||
level TEXT NOT NULL, | ||
message TEXT NOT NULL | ||
) STRICT; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "simulation", | ||
"version": "1.0.0", | ||
"private": true, | ||
"scripts": { | ||
"db:insights": "wrangler d1 insights simulation", | ||
"db:migrate:local": "wrangler d1 migrations apply --local simulation", | ||
"db:migrate:prod": "wrangler d1 migrations apply simulation", | ||
"deploy": "wrangler deploy", | ||
"dev": "wrangler dev", | ||
"postinstall": "wrangler types && lefthook install", | ||
"tail": "wrangler tail", | ||
"typecheck": "wrangler types && tsc" | ||
}, | ||
"dependencies": { | ||
"clsx": "^2.1.0", | ||
"d1-sql-tag": "^0.3.0", | ||
"hono": "^3.11.2" | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "1.5.3", | ||
"@cloudflare/workers-types": "^4.20240208.0", | ||
"lefthook": "^1.6.1", | ||
"tailwindcss": "^3.4.1", | ||
"typescript": "^5.3.3", | ||
"wrangler": "^3.28.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function convertDate(date: string): Date | ||
export function convertDate(date: string | null): Date | null | ||
export function convertDate(date: string | null) { | ||
return date ? new Date(date) : null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
type Brand<K, T> = K & { __brand: T } | ||
|
||
export type EventId = Brand<number, 'EventId'> | ||
export type LogLineId = Brand<number, 'LogLineId'> | ||
export type ProbeId = Brand<string, 'ProbeId'> | ||
export type WebhookId = Brand<string, 'WebhookId'> | ||
|
||
export interface DatabaseSchema { | ||
events: { | ||
id: EventId | ||
created_at: string | ||
probe_id: ProbeId | null | ||
webhook_id: WebhookId | null | ||
duration: number | null | ||
result: 'success' | 'failure' | ||
category: string | ||
description: string | null | ||
} | ||
|
||
log_lines: { | ||
id: LogLineId | ||
created_at: string | ||
level: 'info' | 'warn' | 'error' | ||
message: string | ||
} | ||
|
||
probe_statuses: { | ||
id: ProbeId | ||
last_started_at: string | ||
last_result: 'success' | 'failure' | '' | ||
last_success_at: string | null | ||
last_failure_at: string | null | ||
same_result_since: string | null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { createD1SqlTag, logQueryResults } from 'd1-sql-tag' | ||
import { type Context } from 'hono' | ||
import { endTime, setMetric, startTime } from 'hono/timing' | ||
import type { Bindings } from '..' | ||
|
||
export function createSqlTag(c: Context<{ Bindings: Bindings }>) { | ||
return createD1SqlTag(c.env.DB, { | ||
beforeQuery(batchId, queries) { | ||
startTime(c, `db-${batchId}`) | ||
}, | ||
afterQuery(batchId, queries, results, duration) { | ||
endTime(c, `db-${batchId}`) | ||
results.forEach((result, i) => { | ||
setMetric(c, `db-${batchId}-query-${i + 1}`, result.meta.duration) | ||
}) | ||
logQueryResults(queries, results, duration) | ||
} | ||
}) | ||
} | ||
|
||
export function createCronSqlTag(env: Bindings) { | ||
return createD1SqlTag(env.DB, { | ||
afterQuery(batchId, queries, results, duration) { | ||
logQueryResults(queries, results, duration) | ||
} | ||
}) | ||
} |
Oops, something went wrong.