Recurring cleanup round over the code since round 6 (056a622), 105
commits. Behaviour is unchanged. Duplicated code in src went from 29
clones with 229 lines (0.32 %) to 14 clones with 109 lines (0.15 %),
measured with jscpd and the same settings as round 6.
- BehaviorSystem.ts shrinks from 941 to 589 lines. Collecting the
pulses (keys, timers, collisions, animations) moved to
behaviorPulses.ts. The NodeContext the nodes receive moved to
behaviorContext.ts. Imports from outside stay the same, TimeScaled
is still exported from BehaviorSystem.ts.
- PointKindButton and drawPointGrip replace the "Point:" button with
its menu and the point and handle drawing that the curve and the
vector art tab each had on their own.
- lerpVec, cubicAt and splitCubic in src/core/util/vec.ts replace four
copies of the cubic curve and two de Casteljau splits.
- mapNested in Properties.ts is the one walk over lists and structs
that liveObjects and objectRefs did separately. withFieldRenamed
and withoutField replace three copies of renaming a struct field
and two of removing one.
- jsonBody and staleRevision build the JSON body and turn a 409 into
StaleRevisionError for all stores. The auth store turns a 401 into
its error in one place.
- Smaller helpers: structAssetFrom for the two "Make struct type"
commands, shownObject in the inspector, selectedItem for the size
gizmo and the polygon corners, solidTiles in the tilemap collision,
requireVariablesAsset and requireBehaviorVariable.
- Left as is on purpose: the plain forwarding from the collision and
physics systems to Solids, the pointer wiring of the canvases and
the identical last lines of the two make commands.
- Removed unused code: tilemapTileIds and tilemapsUsing were never
called since #128 and #131. EditorState.runtimeProject became unused
with GameRun in #266. The assetId getter of the make commands was
read only by a test.
- 60 values used only in their own file lost their export. The shader
and particle node catalogues stay exported as in round 6.
- Five comments that told history now describe the current state. The
doc comment of BehaviorSystem sits on the class again.
- README lists the struct, clip area and curve assets and mentions the
game link from #266.
Findings:
- Deleting a tile that is painted on a tilemap leaves its cells in
place, and they draw nothing. The delete dialog does not mention the
tilemaps. That was probably the job of the unused tilemapsUsing.
Left as is, because fixing it changes behaviour.
- The solid filter for tile surfaces was untested. A bent filter
stayed green. A new test in tests/core/surface.test.ts now fails
against it.
Tests:
- ./check.sh: 195 files, 2815 tests, exit 0 (one test removed with
tilemapsUsing, one added for tile surfaces).
- Full e2e run: ALL PASSED, 1580 checks.
- Smokes jumprun, tetris, actor: 24, 19 and 21 checks, all passed.
The example project files were restored byte for byte afterwards.
- Counter-checks, 12, all fail as expected: 10 in unit tests (among
them mapNested, splitCubic, cubicAt, staleRevision, the stay pulse,
the late timer and the time scale), 2 in the browser (Point button
always enabled fails 47, selectedItem without a hit fails 29).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
import { type Role, roleOf } from './AuthStore';
|
|
import { apiRequest, jsonBody } from './http';
|
|
import type { Account, AccountChange, UsersStore } from './UsersStore';
|
|
|
|
/** A refusal of the API (4xx with an `{error}`) as its bare sentence, without route and status around it. */
|
|
function refusal(status: number, data: unknown): Error | undefined {
|
|
const message = (data as { error?: unknown } | null)?.error;
|
|
return status >= 400 && status < 500 && typeof message === 'string' ? new Error(message) : undefined;
|
|
}
|
|
|
|
export class HttpUsersStore implements UsersStore {
|
|
constructor(private readonly endpoint: string) {}
|
|
|
|
async list(): Promise<Account[]> {
|
|
const rows = await apiRequest<Account[]>(this.endpoint, 'GET', 'users', {}, refusal);
|
|
return rows.map((row) => ({ ...row, role: roleOf(row.role) }));
|
|
}
|
|
|
|
async create(username: string, password: string, role: Role): Promise<void> {
|
|
await apiRequest(this.endpoint, 'POST', 'users', jsonBody({ username, password, role }), refusal);
|
|
}
|
|
|
|
async update(username: string, change: AccountChange): Promise<void> {
|
|
await apiRequest(this.endpoint, 'PATCH', `users/${username}`, jsonBody(change), refusal);
|
|
}
|
|
|
|
async remove(username: string): Promise<void> {
|
|
await apiRequest<void>(this.endpoint, 'DELETE', `users/${username}`, {}, refusal);
|
|
}
|
|
}
|