@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 139 lines 3.45 KB
Raw
1 // Alchemy modifications are licensed under Apache-2.0.
2 // This file includes third-party code; see /THIRD_PARTY_LICENSES.md.
3 export class OkResponse extends Response {
4 static readonly status = 200;
5
6 constructor(body: BodyInit | null, init?: ResponseInit) {
7 super(body, {
8 ...init,
9 status: OkResponse.status,
10 });
11 }
12 }
13
14 export class NotFoundResponse extends Response {
15 static readonly status = 404;
16
17 constructor(...[body, init]: ConstructorParameters<typeof Response>) {
18 super(body, {
19 ...init,
20 status: NotFoundResponse.status,
21 statusText: "Not Found",
22 });
23 }
24 }
25
26 // A magical response type which is used to signal that a user worker should be invoked if one is present.
27 export class NoIntentResponse extends NotFoundResponse {
28 constructor() {
29 super();
30 }
31 }
32
33 export class MethodNotAllowedResponse extends Response {
34 static readonly status = 405;
35
36 constructor(...[body, init]: ConstructorParameters<typeof Response>) {
37 super(body, {
38 ...init,
39 status: MethodNotAllowedResponse.status,
40 statusText: "Method Not Allowed",
41 });
42 }
43 }
44
45 export class InternalServerErrorResponse extends Response {
46 static readonly status = 500;
47
48 constructor(_: Error, init?: ResponseInit) {
49 super(null, {
50 ...init,
51 status: InternalServerErrorResponse.status,
52 });
53 }
54 }
55
56 export class NotModifiedResponse extends Response {
57 static readonly status = 304;
58
59 constructor(...[_body, init]: ConstructorParameters<typeof Response>) {
60 super(null, {
61 ...init,
62 status: NotModifiedResponse.status,
63 statusText: "Not Modified",
64 });
65 }
66 }
67
68 // `init.headers` may be a `Headers` instance or entry array, which object
69 // spread would silently drop, so normalize through `Headers`.
70 const withLocation = (init: ResponseInit | undefined, location: string): Headers => {
71 const headers = new Headers(init?.headers);
72 headers.set("Location", location);
73 return headers;
74 };
75
76 export class MovedPermanentlyResponse extends Response {
77 static readonly status = 301;
78
79 constructor(location: string, init?: ResponseInit) {
80 super(null, {
81 ...init,
82 status: MovedPermanentlyResponse.status,
83 statusText: "Moved Permanently",
84 headers: withLocation(init, location),
85 });
86 }
87 }
88
89 export class FoundResponse extends Response {
90 static readonly status = 302;
91
92 constructor(location: string, init?: ResponseInit) {
93 super(null, {
94 ...init,
95 status: FoundResponse.status,
96 statusText: "Found",
97 headers: withLocation(init, location),
98 });
99 }
100 }
101
102 export class SeeOtherResponse extends Response {
103 static readonly status = 303;
104
105 constructor(location: string, init?: ResponseInit) {
106 super(null, {
107 ...init,
108 status: SeeOtherResponse.status,
109 statusText: "See Other",
110 headers: withLocation(init, location),
111 });
112 }
113 }
114
115 export class TemporaryRedirectResponse extends Response {
116 static readonly status = 307;
117
118 constructor(location: string, init?: ResponseInit) {
119 super(null, {
120 ...init,
121 status: TemporaryRedirectResponse.status,
122 statusText: "Temporary Redirect",
123 headers: withLocation(init, location),
124 });
125 }
126 }
127
128 export class PermanentRedirectResponse extends Response {
129 static readonly status = 308;
130
131 constructor(location: string, init?: ResponseInit) {
132 super(null, {
133 ...init,
134 status: PermanentRedirectResponse.status,
135 statusText: "Permanent Redirect",
136 headers: withLocation(init, location),
137 });
138 }
139 }