Stage 0-2 server spine: db, scheduler, REST, auth, economy, map
Built: SQLite (node:sqlite) via server/db.js with checksummed migrations, injectable clock, persistent event scheduler with catch-up, tiny REST router (error envelope, idempotency keys, rate limits, bearer tokens with scrypt passwords), lazy-resource economy in public/js/rules.js + data.js, build/cancel/rename commands, seeded map + spawn ring, generated docs/openapi.json. NETWALL net.js/static.js reused. Tested: manual smoke run only (signup, town view, build, map). No unit tests or e2e yet. NOT done: military, expansion, social, client, push, deploy docs, bots/admin. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
This commit is contained in:
parent
9fa76d53a8
commit
b56b13880e
39 changed files with 4450 additions and 0 deletions
43
server/routes/schemas.js
Normal file
43
server/routes/schemas.js
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
'use strict';
|
||||
/* Shared response schemas (JSON-schema subset), referenced from route meta as { $ref: 'Name' } and emitted into
|
||||
* openapi.json components. Responses are documentation (and checked by test/api-contract.test.js), not enforced at runtime. */
|
||||
const int = { type: 'integer' };
|
||||
const num = { type: 'number' };
|
||||
const str = { type: 'string' };
|
||||
const bool = { type: 'boolean' };
|
||||
const obj = (properties, required) => ({ type: 'object', properties, required: required || Object.keys(properties), additionalProperties: true });
|
||||
const arr = (items) => ({ type: 'array', items });
|
||||
|
||||
const Cost = obj({ fiber: int, hardware: int, capital: int });
|
||||
|
||||
const schemas = {
|
||||
Cost,
|
||||
Error: obj({ serverTime: int, error: obj({ code: str, message: str, details: { type: 'object', additionalProperties: true } }) }),
|
||||
World: obj({ id: int, name: str, speed: num, mapRadius: int, seed: int, startAt: int, endAt: { type: ['integer', 'null'] }, status: str, preset: str }),
|
||||
TownSummary: obj({ id: int, name: str, x: int, y: int, isCapital: bool }),
|
||||
Operator: obj({ id: int, name: str, asNumber: int, allianceId: { type: ['integer', 'null'] }, protectionUntil: int, world: { $ref: 'World' }, towns: arr({ $ref: 'TownSummary' }) }),
|
||||
Me: obj({ serverTime: int, user: obj({ id: int, username: str, createdAt: int }), operators: arr({ $ref: 'Operator' }) }),
|
||||
AuthResult: obj({ serverTime: int, token: str, tokenId: int, user: obj({ id: int, username: str }), operators: arr({ $ref: 'Operator' }) }),
|
||||
Token: obj({ id: int, device: str, createdAt: int, lastUsedAt: int, current: bool }),
|
||||
BuildPlan: obj({ ok: bool, code: { type: ['string', 'null'] }, toLevel: int, cost: { $ref: 'Cost' }, durationMs: int, missing: arr(obj({ type: str, level: int, have: int })) }, ['ok', 'code', 'toLevel']),
|
||||
BuildingView: obj({ key: str, type: str, kind: str, level: int, maxLevel: int, next: { $ref: 'BuildPlan' } }),
|
||||
QueueEntry: obj({ id: int, key: str, type: str, toLevel: int, startedAt: int, dueAt: int }),
|
||||
ResourceView: obj({ amount: num, rate: num, cap: num }),
|
||||
Town: obj({
|
||||
id: int, name: str, x: int, y: int, isCapital: bool, ownerId: int, worldId: int, loyalty: num, footprint: num, footprintPerDay: num,
|
||||
resources: obj({ fiber: { $ref: 'ResourceView' }, hardware: { $ref: 'ResourceView' }, capital: { $ref: 'ResourceView' } }),
|
||||
power: obj({ out: num, draw: num, net: num, buffer: num, bufferCap: num, bufferRate: num, online: bool }),
|
||||
buildings: arr({ $ref: 'BuildingView' }), queue: arr({ $ref: 'QueueEntry' }), queueSlots: int,
|
||||
bonus: obj({ fiber: num, hardware: num, capital: num }),
|
||||
}),
|
||||
TownResponse: obj({ serverTime: int, town: { $ref: 'Town' } }),
|
||||
MapTown: obj({ id: int, name: str, x: int, y: int, isCapital: bool, owner: obj({ id: int, name: str, asNumber: int, allianceId: { type: ['integer', 'null'] }, protected: bool }) }),
|
||||
MapSpecial: obj({ x: int, y: int, type: str, bonus: { type: ['string', 'null'] } }),
|
||||
MapResponse: obj({ serverTime: int, world: { $ref: 'World' }, bounds: obj({ x0: int, x1: int, y0: int, y1: int }), specials: arr({ $ref: 'MapSpecial' }), towns: arr({ $ref: 'MapTown' }) }),
|
||||
BuildResult: obj({ serverTime: int, eventId: int, key: str, type: str, toLevel: int, startedAt: int, dueAt: int, cost: { $ref: 'Cost' } }),
|
||||
Notification: obj({ id: int, type: str, worldId: { type: ['integer', 'null'] }, payload: { type: 'object', additionalProperties: true }, createdAt: int, readAt: { type: ['integer', 'null'] } }),
|
||||
NotificationList: obj({ serverTime: int, items: arr({ $ref: 'Notification' }), next: { type: ['integer', 'null'] } }),
|
||||
Ok: obj({ serverTime: int }),
|
||||
};
|
||||
|
||||
module.exports = { schemas, int, num, str, bool, obj, arr };
|
||||
Loading…
Add table
Add a link
Reference in a new issue