|
Two related cleanups landed together because they touch the same pattern:
1. Intra-module imports now use relative paths rather than the module's
own path alias. rng/seeded.ts imports from './derive', not 'rng/derive';
time/gameTime.ts from './calendar', not 'time/calendar'; the utils
barrel from './result' etc. This matches rules/01-code-style.md:
"Relative imports only for same-directory siblings." The alias form
is reserved for imports *between* modules — how external callers refer
to a module's public surface.
(The TS language server in the IDE had trouble resolving the self-
aliased form even though svelte-check accepted it; this change
removes the ambiguity.)
2. utils/ is now folder-per-concept. Each utility owns a directory with
its files broken up into small pieces:
utils/result/ types, constructors, predicates, map, unwrap
utils/assert/ assert, assert-never, assert-defined
utils/equal/ deep
utils/types/ brand, deep-readonly, element-of, json, non-empty-array
utils/log/ log
utils/index.ts re-exports from each subfolder via the barrel. External
callers import from 'utils' unchanged; internal references are relative.
One reason to prefer folders over flat files here is headroom — when a
concept grows, new files sit alongside their siblings inside the
concept's folder rather than crowding the utils/ root.
No API changes. All 128 tests still green.
|
|
Foundational helpers referenced by most subsequent code. Small, pure,
no dependencies on anything in the project.
utils/result.ts Result<T, E> = Ok<T> | Err<E> for recoverable
failures at system boundaries (save/load, manifest
fetch, content validation). Internal pure logic
still uses throw for programmer errors.
ok / err / isOk / isErr / mapResult / mapErr /
unwrap / unwrapOr.
utils/assert.ts assert (with type-narrowing asserts), assertNever
for exhaustive-switch termination, assertDefined
for narrowing T | null | undefined → T.
utils/equal.ts Structural deepEqual for tests comparing simulation
snapshots. Handles plain objects, arrays, Map, Set,
Date, primitives. Does not handle cyclic graphs
(simulation state is a tree).
utils/types.ts Common type aliases: NonEmptyArray, JsonValue,
ElementOf, DeepReadonly, Brand<T, B> for nominal /
branded types (PersonId vs RelationshipId).
utils/log.ts Structured logging wrapping console. Developer-
facing only; the game ships with no runtime
telemetry.
utils/index.ts Public re-exports.
40 unit tests in tests/unit/utils/ cover Result constructors and
combinators, assert variants, and deepEqual's primitive / array /
object / Map / Set / Date paths plus a realistic simulation-snapshot
comparison.
|