mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
feat: scaffold Phase B + C (events, telemetry, plugins, Solid.js)
Phase B Step 6 — Solid.js incremental migration
- vite-plugin-solid + solid-js + @solidjs/testing-library in package.json
- vite.config.ts compiles src/components/solid/** as Solid TSX
- tsconfig.json gains jsx: preserve / jsxImportSource: solid-js
- lib/solidAdapter.ts wraps existing custom Stores as Solid signals
- lib/solidMount.ts adapts Solid render to {mount,destroy} contract
- components/solid/Badge.tsx (proof-of-concept leaf)
- components/solid/ChannelListItem.tsx (store-subscribed leaf)
- components/solid/Badge.test.tsx pipeline smoke test
- components/solid/README.md documents the migration recipe
Phase B Step 7 — Event persistence layer
- SQLite + Postgres migrations for the events table
- sqlc query files for both engines
- EventStore interface + SQLite raw-SQL impl + MemStore impl + pg stubs
- ws.EventPersister: async batched writer (queue / flush / drain / drop)
- ws.StartEventPruner: background retention pruner
- hub persists every replay-buffer push and exposes reconnect-tier counters
- serve.handleReconnect: tiered replay (buffer -> DB -> full re-sync)
- EventPersistenceConfig + main.go wiring
- event_persister_test.go covers batching / drops / drain
Phase B Step 8 — OpenTelemetry skeleton
- Server/telemetry package with public Provider/Tracer/Meter/Counter API
- telemetry_default.go (no-op build) + telemetry_otel.go (build tag otel)
- telemetry/metrics.go declares the AppMetrics bundle
- HTTPMiddleware mounted in Chi router (pass-through in default build)
- PrometheusHandler optionally mounted at /metrics
- Spans on MessageService.SendMessage, PermissionService.HasChannelPerm,
ChannelService.ListVisibleChannels
- Reconnect-tier counter wired into the global meter
- TelemetryConfig defaults
Phase C Step 9 — Wazero plugin runtime skeleton
- Server/plugin package: manifest parser, loader, registry, host APIs
(commands, storage, events, http, ui), errors
- sandbox_default.go (no-op) + sandbox_wazero.go (build tag wazero)
- SQLite + Postgres migrations for plugins + plugin_kv tables
- PluginStore interface + impls + pg stubs
- plugin/examples/hello manifest + README
- plugin_test.go covers manifest, loader, capability gating
- api/plugins_handler.go admin REST surface, mounted under admin group
- PluginsConfig + main.go wiring (disabled by default)
- Client: lib/pluginBridge.ts iframe + postMessage host
- Client: components/solid/PluginContainer.tsx Solid host component
Verification
- Default build (no -tags) is intended to compile cleanly with no new
third-party dependencies. The sandbox lacked Go 1.25.0 so go build
could not run; PHASE_BC_LOCAL_TODO.md enumerates the local follow-up
work (npm install, go mod tidy, sqlc-generate, real otel/wazero
wiring, remaining service spans, full Solid migration).
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package db
|
||||
|
||||
import "time"
|
||||
|
||||
// PersistedEvent is a single broadcast event written to the events table for
|
||||
// cold-replay during reconnection. The event payload is the same wire-format
|
||||
// JSON the WebSocket clients receive at broadcast time, including the seq
|
||||
// field injected by the hub.
|
||||
//
|
||||
// Phase B Step 7 (event persistence layer).
|
||||
type PersistedEvent struct {
|
||||
Seq int64
|
||||
EventType string
|
||||
ChannelID int64
|
||||
Payload []byte
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
// PluginRow represents a row in the plugins table (Phase C Step 9).
|
||||
type PluginRow struct {
|
||||
ID int64
|
||||
Name string
|
||||
Version string
|
||||
Enabled bool
|
||||
ManifestJSON string
|
||||
InstalledAt time.Time
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
-- name: PersistEvent :one
|
||||
INSERT INTO events (event_type, channel_id, payload)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING seq;
|
||||
|
||||
-- name: GetEventsSince :many
|
||||
SELECT seq, event_type, channel_id, payload, created_at
|
||||
FROM events
|
||||
WHERE seq > $1
|
||||
ORDER BY seq ASC
|
||||
LIMIT $2;
|
||||
|
||||
-- name: PruneEventsOlderThan :execrows
|
||||
DELETE FROM events WHERE created_at < $1;
|
||||
@@ -0,0 +1,36 @@
|
||||
-- name: InstallPlugin :one
|
||||
INSERT INTO plugins (name, version, manifest_json)
|
||||
VALUES ($1, $2, $3)
|
||||
ON CONFLICT (name) DO UPDATE
|
||||
SET version = excluded.version,
|
||||
manifest_json = excluded.manifest_json
|
||||
RETURNING id;
|
||||
|
||||
-- name: EnablePlugin :exec
|
||||
UPDATE plugins SET enabled = TRUE WHERE id = $1;
|
||||
|
||||
-- name: DisablePlugin :exec
|
||||
UPDATE plugins SET enabled = FALSE WHERE id = $1;
|
||||
|
||||
-- name: UninstallPlugin :exec
|
||||
DELETE FROM plugins WHERE id = $1;
|
||||
|
||||
-- name: GetPlugin :one
|
||||
SELECT id, name, version, enabled, manifest_json, installed_at FROM plugins WHERE id = $1;
|
||||
|
||||
-- name: GetPluginByName :one
|
||||
SELECT id, name, version, enabled, manifest_json, installed_at FROM plugins WHERE name = $1;
|
||||
|
||||
-- name: ListPlugins :many
|
||||
SELECT id, name, version, enabled, manifest_json, installed_at FROM plugins ORDER BY name;
|
||||
|
||||
-- name: PluginKVGet :one
|
||||
SELECT value FROM plugin_kv WHERE plugin_id = $1 AND key = $2;
|
||||
|
||||
-- name: PluginKVSet :exec
|
||||
INSERT INTO plugin_kv (plugin_id, key, value)
|
||||
VALUES ($1, $2, $3)
|
||||
ON CONFLICT (plugin_id, key) DO UPDATE SET value = excluded.value;
|
||||
|
||||
-- name: PluginKVDelete :exec
|
||||
DELETE FROM plugin_kv WHERE plugin_id = $1 AND key = $2;
|
||||
@@ -0,0 +1,12 @@
|
||||
-- name: PersistEvent :execresult
|
||||
INSERT INTO events (event_type, channel_id, payload) VALUES (?, ?, ?);
|
||||
|
||||
-- name: GetEventsSince :many
|
||||
SELECT seq, event_type, channel_id, payload, created_at
|
||||
FROM events
|
||||
WHERE seq > ?
|
||||
ORDER BY seq ASC
|
||||
LIMIT ?;
|
||||
|
||||
-- name: PruneEventsOlderThan :execrows
|
||||
DELETE FROM events WHERE created_at < ?;
|
||||
@@ -0,0 +1,31 @@
|
||||
-- name: InstallPlugin :execresult
|
||||
INSERT INTO plugins (name, version, manifest_json) VALUES (?, ?, ?)
|
||||
ON CONFLICT(name) DO UPDATE SET version = excluded.version, manifest_json = excluded.manifest_json;
|
||||
|
||||
-- name: EnablePlugin :exec
|
||||
UPDATE plugins SET enabled = 1 WHERE id = ?;
|
||||
|
||||
-- name: DisablePlugin :exec
|
||||
UPDATE plugins SET enabled = 0 WHERE id = ?;
|
||||
|
||||
-- name: UninstallPlugin :exec
|
||||
DELETE FROM plugins WHERE id = ?;
|
||||
|
||||
-- name: GetPlugin :one
|
||||
SELECT id, name, version, enabled, manifest_json, installed_at FROM plugins WHERE id = ?;
|
||||
|
||||
-- name: GetPluginByName :one
|
||||
SELECT id, name, version, enabled, manifest_json, installed_at FROM plugins WHERE name = ?;
|
||||
|
||||
-- name: ListPlugins :many
|
||||
SELECT id, name, version, enabled, manifest_json, installed_at FROM plugins ORDER BY name;
|
||||
|
||||
-- name: PluginKVGet :one
|
||||
SELECT value FROM plugin_kv WHERE plugin_id = ? AND key = ?;
|
||||
|
||||
-- name: PluginKVSet :exec
|
||||
INSERT INTO plugin_kv (plugin_id, key, value) VALUES (?, ?, ?)
|
||||
ON CONFLICT(plugin_id, key) DO UPDATE SET value = excluded.value;
|
||||
|
||||
-- name: PluginKVDelete :exec
|
||||
DELETE FROM plugin_kv WHERE plugin_id = ? AND key = ?;
|
||||
Reference in New Issue
Block a user