-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate RunFrame (Use Webworker Beta) (#586)
* start implementing necessary endpoints for package management * progress toward more accurate backend emulation * fix type errors with placeholders * adjust spacing on landing page * init runframe integration * run frame mostly working * make using main thread or webworker toggleable * improve clarity when webworker is on * exclude runframe and eval-webworker from optimizations to attempt to fix vercel build issue * remove manual output for eval webworker and runframe * remove unfinished endpoint * update to text lockfile, update to runframe version that uses CDN
- Loading branch information
Showing
15 changed files
with
3,945 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./middleware/with-winter-spec" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
import { withRouteSpec } from "fake-snippets-api/lib/with-winter-spec" | ||
import { z } from "zod" | ||
|
||
export default withRouteSpec({ | ||
methods: ["GET"], | ||
auth: "none", | ||
queryParams: z.object({ | ||
jsdelivr_resolve: z | ||
.enum(["true", "false"]) | ||
.optional() | ||
.transform((v) => v === "true"), | ||
jsdelivr_path: z.string(), | ||
}), | ||
jsonResponse: z.any(), | ||
})(async (req, ctx) => { | ||
const { jsdelivr_path, jsdelivr_resolve } = req.query | ||
|
||
// Parse the file path | ||
const [owner, packageWithVersion, ...rest] = jsdelivr_path.split("/") | ||
if (!packageWithVersion) { | ||
return ctx.error(400, { | ||
error_code: "invalid_path", | ||
message: "Invalid path", | ||
}) | ||
} | ||
const [packageName, version] = packageWithVersion.split("@") | ||
const fileName = rest.join("/") | ||
|
||
// Find the snippet | ||
// const snippet = | ||
|
||
// if (!snippet) { | ||
// return ctx.error(404, { | ||
// error_code: "snippet_not_found", | ||
// message: "Snippet not found", | ||
// }) | ||
// } | ||
|
||
// if (!fileName && !jsdelivr_resolve) { | ||
// return new Response( | ||
// JSON.stringify({ | ||
// tags: { | ||
// latest: "0.0.1", | ||
// }, | ||
// versions: ["0.0.1"], | ||
// }), | ||
// { | ||
// status: 200, | ||
// headers: { "Content-Type": "application/json" }, | ||
// }, | ||
// ) | ||
// } | ||
|
||
// if (!fileName && jsdelivr_resolve) { | ||
// return new Response( | ||
// JSON.stringify({ | ||
// version: "0.0.1", | ||
// }), | ||
// { | ||
// status: 200, | ||
// headers: { "Content-Type": "application/json" }, | ||
// }, | ||
// ) | ||
// } | ||
|
||
// const latestRelease = await ctx.db | ||
// .selectFrom("main.package_release") | ||
// .where("package_id", "=", snippet.snippet_id) | ||
// .where("is_latest", "=", true) | ||
// .selectAll() | ||
// .executeTakeFirst() | ||
|
||
// const dtsFile = await ctx.db | ||
// .selectFrom("main.package_file") | ||
// .where("package_release_id", "=", latestRelease!.package_release_id) | ||
// .where("file_path", "=", "/dist/index.d.ts") | ||
// .select("content_text") | ||
// .executeTakeFirst() | ||
|
||
// // If no fileName is provided, return the directory listing | ||
// if (!fileName || fileName === "flat") { | ||
// const files = [ | ||
// { | ||
// type: "file", | ||
// name: "index.ts", | ||
// hash: "placeholder_hash", | ||
// time: snippet.updated_at, | ||
// size: snippet.code?.length ?? 0, | ||
// }, | ||
// { | ||
// type: "file", | ||
// name: "index.d.ts", | ||
// hash: "placeholder_hash", | ||
// time: snippet.updated_at, | ||
// size: dtsFile?.content_text?.length ?? 0, | ||
// }, | ||
// { | ||
// type: "file", | ||
// name: "package.json", | ||
// hash: "placeholder_hash", | ||
// time: snippet.updated_at, | ||
// size: JSON.stringify({ | ||
// name: `@tsci/${owner}.${packageName}`, | ||
// version: version || "0.0.1", | ||
// main: "index.ts", | ||
// types: "index.d.ts", | ||
// }).length, | ||
// }, | ||
// ] | ||
|
||
// const response = { | ||
// default: "/index.ts", | ||
// files: | ||
// fileName === "flat" | ||
// ? files.map((f) => ({ | ||
// name: `/${f.name}`, | ||
// hash: f.hash, | ||
// time: f.time, | ||
// size: f.size, | ||
// })) | ||
// : [ | ||
// { | ||
// type: "directory", | ||
// name: ".", | ||
// files: files, | ||
// }, | ||
// ], | ||
// } | ||
|
||
// return new Response(JSON.stringify(response, null, 2), { | ||
// status: 200, | ||
// headers: { "Content-Type": "application/json" }, | ||
// }) | ||
// } | ||
|
||
// // Handle file downloads | ||
// let content: string | ||
// switch (fileName) { | ||
// case "index.ts": | ||
// content = snippet.code ?? "" | ||
// break | ||
// case "index.d.ts": | ||
// content = dtsFile?.content_text ?? "" | ||
// break | ||
// case "package.json": | ||
// content = JSON.stringify( | ||
// { | ||
// name: `@tsci/${owner}.${packageName}`, | ||
// version: version || "0.0.1", | ||
// main: "index.ts", | ||
// types: "index.d.ts", | ||
// }, | ||
// null, | ||
// 2, | ||
// ) | ||
// break | ||
// default: | ||
// return ctx.error(404, { | ||
// error_code: "file_not_found", | ||
// message: "Requested file not found", | ||
// }) | ||
// } | ||
|
||
const content = "TODO" | ||
|
||
return new Response(content, { | ||
status: 200, | ||
headers: { "Content-Type": "text/plain" }, | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { withRouteSpec } from "fake-snippets-api/lib/with-winter-spec" | ||
import { z } from "zod" | ||
import * as ZT from "fake-snippets-api/lib/db/schema" | ||
import { NotFoundError } from "winterspec/middleware" | ||
|
||
const routeSpec = { | ||
methods: ["POST"], | ||
auth: "none", | ||
jsonBody: z | ||
.object({ | ||
package_file_id: z.string().uuid(), | ||
}) | ||
.or( | ||
z.object({ | ||
package_release_id: z.string().uuid(), | ||
file_path: z.string(), | ||
}), | ||
) | ||
.or( | ||
z.object({ | ||
package_id: z.string().uuid(), | ||
version: z.string().optional(), | ||
file_path: z.string(), | ||
}), | ||
) | ||
.or( | ||
z.object({ | ||
package_name: z.string(), | ||
version: z.string().optional(), | ||
file_path: z.string(), | ||
}), | ||
) | ||
.or( | ||
z.object({ | ||
package_name_with_version: z.string(), | ||
file_path: z.string(), | ||
}), | ||
), | ||
jsonResponse: z | ||
.object({ | ||
ok: z.boolean(), | ||
package_file: ZT.packageFileSchema.optional(), | ||
}) | ||
.or(ZT.errorResponseSchema), | ||
} as const | ||
|
||
export default withRouteSpec(routeSpec)(async (req, ctx) => { | ||
return ctx.json({ | ||
ok: true, | ||
package_file: undefined, | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { withRouteSpec } from "fake-snippets-api/lib/with-winter-spec" | ||
import { z } from "zod" | ||
import * as ZT from "fake-snippets-api/lib/db/schema" | ||
|
||
const routeSpec = { | ||
methods: ["POST"], | ||
auth: "none", | ||
jsonBody: z | ||
.object({ | ||
package_release_id: z.string().uuid(), | ||
}) | ||
.or( | ||
z.object({ | ||
package_name: z.string(), | ||
use_latest_version: z.literal(true), | ||
}), | ||
) | ||
.or( | ||
z.object({ | ||
package_name_with_version: z.string(), | ||
}), | ||
), | ||
jsonResponse: z.object({ | ||
ok: z.boolean(), | ||
package_files: z.array(ZT.packageFileSchema), | ||
}), | ||
} as const | ||
|
||
export default withRouteSpec(routeSpec)(async (req, ctx) => { | ||
// const package_release_id = await findPackageReleaseId(req.jsonBody, ctx) | ||
// if (!package_release_id) { | ||
// return ctx.error(404, { | ||
// error_code: "package_release_not_found", | ||
// message: "Package release not found", | ||
// }) | ||
// } | ||
// const package_files = await ctx.db | ||
// .selectFrom("main.package_file") | ||
// .select([ | ||
// "package_file_id", | ||
// "package_release_id", | ||
// "content_mimetype", | ||
// "file_path", | ||
// "created_at", | ||
// ]) | ||
// .where("package_release_id", "=", package_release_id) | ||
// .where("file_path", "not like", ".tscircuit-internal/%") | ||
// .execute() | ||
// return ctx.json({ | ||
// ok: true, | ||
// package_files: package_files.map((pf) => ({ | ||
// ...pf, | ||
// created_at: pf.created_at.toISOString(), | ||
// })), | ||
// }) | ||
return ctx.json({ | ||
ok: true, | ||
package_files: [], | ||
}) | ||
}) |
Oops, something went wrong.