refactor: rename ws adapter to server across codebase

'ws' conflated storage mode with transport protocol (WebSocket). Renamed for
clarity: the adapter talks the self-hosted server (src/storage/server.js), which
happens to use WebSocket for realtime — but the name should describe what it
connects to, not how.

Renames:
- src/storage/ws.js -> server.js
- createWsStorage() -> createServerStorage()
- storage mode 'ws' -> 'server'
- REACT_APP_BACKEND_WS -> REACT_APP_BACKEND_REALTIME_URL
- factory param wsUrl -> realtimeUrl
- server/tests/ws-*.test.js -> server-*.test.js

Kept literal: 'ws' npm package, ws:// protocol URLs, /ws WebSocket endpoint.
Transport is accurate there; only storage-naming changed.

Updated all docs (DEVELOPMENT, TESTING, REWORK_PLAN, GLOSSARY, TODO), scripts
(dev-start.sh, replay-combat.js), factory + ESM tests. 204 tests green.
This commit is contained in:
david raistrick
2026-07-04 15:47:13 -04:00
parent cb41d9ec8f
commit e94e1959ff
16 changed files with 64 additions and 65 deletions
+6 -6
View File
@@ -1,5 +1,5 @@
// src/storage/index.js — storage factory + SDK re-exports.
// STORAGE=firebase (default): adapter wraps SDK. STORAGE=ws: backend.
// STORAGE=firebase (default): adapter wraps SDK. STORAGE=server: backend.
// App.js imports getStorage() for subscribe; still imports SDK pieces for writes (per-group refactor pending).
import { initializeApp } from 'firebase/app';
@@ -11,7 +11,7 @@ import {
onSnapshot, updateDoc, deleteDoc, query, orderBy, limit, writeBatch,
} from 'firebase/firestore';
import { initFirebase, createFirebaseStorage } from './firebase';
import { createWsStorage } from './ws';
import { createServerStorage } from './server';
let storageInstance = null;
@@ -23,13 +23,13 @@ export function getStorage() {
const ok = initFirebase();
if (!ok) throw new Error('Firebase config missing. Check REACT_APP_FIREBASE_* env.');
storageInstance = createFirebaseStorage();
} else if (mode === 'ws') {
storageInstance = createWsStorage({
} else if (mode === 'server') {
storageInstance = createServerStorage({
baseUrl: process.env.REACT_APP_BACKEND_URL || '',
wsUrl: process.env.REACT_APP_BACKEND_WS || '',
realtimeUrl: process.env.REACT_APP_BACKEND_REALTIME_URL || '',
});
} else {
throw new Error(`Unknown REACT_APP_STORAGE mode: ${mode}. Use 'firebase' or 'ws'.`);
throw new Error(`Unknown REACT_APP_STORAGE mode: ${mode}. Use 'firebase' or 'server'.`);
}
return storageInstance;
}
+4 -4
View File
@@ -11,13 +11,13 @@ if (typeof WebSocket !== 'undefined') {
WebSocketImpl = WebSocket;
}
function createWsStorage({ baseUrl, wsUrl } = {}) {
function createServerStorage({ baseUrl, realtimeUrl } = {}) {
// Same-origin by default: empty baseUrl = relative fetch (Caddy/proxy).
// Fallback to localhost for bare `npm start` dev without proxy.
const API = (baseUrl || (typeof window !== 'undefined' && window.location ? '' : 'http://127.0.0.1:4001')).replace(/\/$/, '');
let WS;
if (wsUrl) {
WS = wsUrl;
if (realtimeUrl) {
WS = realtimeUrl;
} else if (typeof window !== 'undefined' && window.location) {
// derive from current origin (http→ws, https→wss), same host/port.
const proto = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
@@ -259,4 +259,4 @@ function createWsStorage({ baseUrl, wsUrl } = {}) {
return storage;
}
export { createWsStorage };
export { createServerStorage };