Skip to content
Myr

server.ts

This file

Path

apps/web/src/dev/server.ts

103 lines · 3.6 KiB · TypeScript

Last changed by

Merge perf/code-store into mainoscabrielbefore adoptionef0ddbd

History of this file

Take it

The walk stopped after 200 commits: lines older than f9808ff point at it.

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

line 1why, one step back
1import { RepoHost } from "@repo/artifacts/repo-host";

Merge perf/code-store into mainoscabrielbefore adoptionef0ddbd

lines 2–3why, one step back
2import { CodeStore } from "@repo/project/code-store";
3import { CodeCache } from "@repo/project/code/cache";

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

lines 4–5why, one step back
4import { rawFor } from "@repo/project/code/raw";
5import { Projects } from "@repo/project/projects";

Tell stage 1 a pusher reads the layers only when they read every one, and give the no-oracle path rule one owner in the gateoscabrielbefore adoptionf9808ff

line 6why, one step back
6import { Contracts } from "@repo/protocol/contracts";

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

lines 7–8why, one step back
7import { ProjectName } from "@repo/protocol/ids";
8import { Context, Effect, Layer, Option, Schema } from "effect";

Merge dev/live-clock into mainoscabrielbefore adoption923d465

line 9why, one step back
9import type { DateTime, Duration } from "effect";

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

line 10why, one step back
10import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";

Tell stage 1 a pusher reads the layers only when they read every one, and give the no-oracle path rule one owner in the gateoscabrielbefore adoptionf9808ff

lines 11–12why, one step back
11import { RpcSerialization, RpcServer } from "effect/rpc";
12

Merge dev/live-clock into mainoscabrielbefore adoption923d465

line 13why, one step back
13import { DevClock, devStart, startEndingNow } from "./clock.ts";

Merge build/1205-dev-fixturesoscabrielbefore adoptionc816189

lines 14–15why, one step back
14import { withFixtures } from "./fixtures.ts";
15import type { FixtureMode } from "./fixtures.ts";

Merge dev/live-clock into mainoscabrielbefore adoption923d465

line 16why, one step back
16import { fixturesNow } from "./fixtures/vellum.ts";

Tell stage 1 a pusher reads the layers only when they read every one, and give the no-oracle path rule one owner in the gateoscabrielbefore adoptionf9808ff

line 17why, one step back
17import { devHandlers } from "./handlers.ts";

Merge dev/live-clock into mainoscabrielbefore adoption923d465

line 18why, one step back
18import { seedDev, seedEnd } from "./seed.ts";

Tell stage 1 a pusher reads the layers only when they read every one, and give the no-oracle path rule one owner in the gateoscabrielbefore adoptionf9808ff

line 19why, one step back
19import { devSessions } from "./sessions.ts";

Merge dev/live-clock into mainoscabrielbefore adoption923d465

line 20why, one step back
20import { devWorldAt } from "./world.ts";

Tell stage 1 a pusher reads the layers only when they read every one, and give the no-oracle path rule one owner in the gateoscabrielbefore adoptionf9808ff

line 21why, one step back
21

Merge build/1205-dev-fixturesoscabrielbefore adoptionc816189

lines 22–24why, one step back
22export interface DevWorldOptions {
23 readonly fixtures?: FixtureMode;24 readonly liveAfter?: Duration.Duration;

Merge dev/live-clock into mainoscabrielbefore adoption923d465

line 25why, one step back
25 readonly time?: "fixed" | "present";

Merge build/1205-dev-fixturesoscabrielbefore adoptionc816189

line 26why, one step back
26}

Tell stage 1 a pusher reads the layers only when they read every one, and give the no-oracle path rule one owner in the gateoscabrielbefore adoptionf9808ff

line 27why, one step back
27

Merge dev/live-clock into mainoscabrielbefore adoption923d465

lines 28–31why, one step back
28const seedEndOf = (fixtures: FixtureMode) =>
29 fixtures === "off" ? seedEnd : fixturesNow;3031const seededFrom = (start: DateTime.Utc, options: DevWorldOptions) => {

Merge build/1205-dev-fixturesoscabrielbefore adoptionc816189

lines 32–34why, one step back
32 const { fixtures = "off" } = options;
3334 return fixtures === "off"

Merge dev/live-clock into mainoscabrielbefore adoption923d465

lines 35–50why, one step back
35 ? Layer.effectDiscard(seedDev).pipe(Layer.provideMerge(devWorldAt(start)))
36 : withFixtures(fixtures, options.liveAfter, start);37};3839const seededWorld = (options: DevWorldOptions) => {40 const { fixtures = "off", time = "fixed" } = options;4142 return time === "fixed"43 ? seededFrom(devStart, options)44 : Layer.unwrap(45 Effect.map(startEndingNow(seedEndOf(fixtures)), (start) =>46 Layer.effectDiscard(47 Effect.flatMap(Effect.service(DevClock), (clock) => clock.run)48 ).pipe(Layer.provideMerge(seededFrom(start, options)))49 )50 );

Merge build/1205-dev-fixturesoscabrielbefore adoptionc816189

lines 51–52why, one step back
51};
52

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

lines 53–57why, one step back
53const decodeProject = Schema.decodeUnknownOption(ProjectName);
5455const raw = Layer.unwrap(56 Effect.gen(function* () {57 const services = Context.make(RepoHost, yield* RepoHost).pipe(

Merge perf/code-store into mainoscabrielbefore adoptionef0ddbd

lines 58–60why, one step back
58 Context.add(Projects, yield* Projects),
59 Context.add(CodeCache, yield* CodeCache),60 Context.add(CodeStore, yield* CodeStore)

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

lines 61–62why, one step back
61 );
62

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

lines 63–65why, one step back
63 const answer = Effect.gen(function* () {
64 const params = yield* HttpRouter.params;65 const request = yield* HttpServerRequest.HttpServerRequest;

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

line 66why, one step back
66

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

lines 67–84why, one step back
67 const spelled = [params.host, params.owner, params.project]
68 .filter((segment) => segment !== undefined)69 .join("/");7071 return yield* Option.match(decodeProject(spelled), {72 onNone: () => Effect.succeed(HttpServerResponse.empty({ status: 404 })),73 onSome: (project) =>74 rawFor(project, request.url).pipe(75 Effect.provide(services),76 Effect.map(HttpServerResponse.fromWeb)77 ),78 });79 });8081 return Layer.mergeAll(82 HttpRouter.add("GET", "/:project/raw/*", answer),83 HttpRouter.add("GET", "/:owner/:project/raw/*", answer),84 HttpRouter.add("GET", "/:host/:owner/:project/raw/*", answer)

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

lines 85–88why, one step back
85 );
86 })87);88

Merge build/comments-web-rest into mainoscabrielbefore adoption0eb1248

line 89why, one step back
89// `toWebHandler` builds its layer as soon as it is called; a request that arrives before the seed is done waits for it.

Merge build/1205-dev-fixturesoscabrielbefore adoptionc816189

line 90why, one step back
90export const devServer = (options: DevWorldOptions = {}) =>

Tell stage 1 a pusher reads the layers only when they read every one, and give the no-oracle path rule one owner in the gateoscabrielbefore adoptionf9808ff

line 91why, one step back
91 HttpRouter.toWebHandler(

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

lines 92–100why, one step back
92 Layer.merge(
93 RpcServer.layerHttp({94 group: Contracts,95 path: "/rpc",96 protocol: "http",97 }).pipe(98 Layer.provide([devHandlers, devSessions, RpcSerialization.layerJson])99 ),100 raw

Merge build/1205-dev-fixturesoscabrielbefore adoptionc816189

line 101why, one step back
101 ).pipe(Layer.provide(seededWorld(options))),

Tell stage 1 a pusher reads the layers only when they read every one, and give the no-oracle path rule one owner in the gateoscabrielbefore adoptionf9808ff

lines 102–103why, one step back
102 { disableLogger: true }
103 );