@tscircuit/fake-snippets 0.0.105 → 0.0.106

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,70 @@
1
+ import { withRouteSpec } from "fake-snippets-api/lib/middleware/with-winter-spec"
2
+ import { z } from "zod"
3
+ import { publicMapPackageBuild } from "fake-snippets-api/lib/public-mapping/public-map-package-build"
4
+
5
+ export default withRouteSpec({
6
+ methods: ["GET"],
7
+ auth: "session",
8
+ queryParams: z.object({
9
+ package_build_id: z.string(),
10
+ }),
11
+ jsonResponse: z.object({
12
+ package_build: z.any(),
13
+ }),
14
+ })(async (req, ctx) => {
15
+ const { package_build_id } = req.query
16
+
17
+ if (!package_build_id) {
18
+ return ctx.error(400, {
19
+ error_code: "invalid_request",
20
+ message: "package_build_id is required",
21
+ })
22
+ }
23
+
24
+ const packageBuild = ctx.db.packageBuilds.find(
25
+ (build) => build.package_build_id === package_build_id,
26
+ )
27
+
28
+ if (!packageBuild) {
29
+ return ctx.error(404, {
30
+ error_code: "package_build_not_found",
31
+ message: "Package build not found",
32
+ })
33
+ }
34
+
35
+ const packageRelease = ctx.db.packageReleases.find(
36
+ (pr) => pr.package_release_id === packageBuild.package_release_id,
37
+ )
38
+
39
+ if (!packageRelease) {
40
+ return ctx.error(404, {
41
+ error_code: "package_release_not_found",
42
+ message: "Package release not found",
43
+ })
44
+ }
45
+
46
+ const pkg = ctx.db.packages.find(
47
+ (p) => p.package_id === packageRelease.package_id,
48
+ )
49
+ if (!pkg) {
50
+ return ctx.error(404, {
51
+ error_code: "package_not_found",
52
+ message: "Package not found",
53
+ })
54
+ }
55
+
56
+ if (pkg.creator_account_id !== ctx.auth.account_id) {
57
+ return ctx.error(403, {
58
+ error_code: "unauthorized",
59
+ message: "You are not authorized to access this package build",
60
+ })
61
+ }
62
+
63
+ const publicBuild = publicMapPackageBuild(packageBuild, {
64
+ include_logs: true,
65
+ })
66
+
67
+ return ctx.json({
68
+ package_build: publicBuild,
69
+ })
70
+ })
@@ -0,0 +1,109 @@
1
+ import { withRouteSpec } from "fake-snippets-api/lib/middleware/with-winter-spec"
2
+ import { z } from "zod"
3
+ import { publicMapPackageBuild } from "fake-snippets-api/lib/public-mapping/public-map-package-build"
4
+
5
+ export default withRouteSpec({
6
+ methods: ["GET"],
7
+ auth: "session",
8
+ queryParams: z.object({
9
+ package_id: z.string().optional(),
10
+ package_release_id: z.string().optional(),
11
+ }),
12
+ jsonResponse: z.object({
13
+ package_build: z.any().nullable(),
14
+ }),
15
+ })(async (req, ctx) => {
16
+ const { package_id, package_release_id } = req.query
17
+
18
+ if (!package_id && !package_release_id) {
19
+ return ctx.error(400, {
20
+ error_code: "invalid_request",
21
+ message: "Either package_id or package_release_id must be provided",
22
+ })
23
+ }
24
+
25
+ let targetPackageId = package_id
26
+
27
+ if (package_release_id) {
28
+ const packageRelease = ctx.db.packageReleases.find(
29
+ (pr) => pr.package_release_id === package_release_id,
30
+ )
31
+ if (!packageRelease) {
32
+ return ctx.error(404, {
33
+ error_code: "package_release_not_found",
34
+ message: "Package release not found",
35
+ })
36
+ }
37
+ targetPackageId = packageRelease.package_id
38
+ }
39
+
40
+ if (targetPackageId) {
41
+ const pkg = ctx.db.packages.find((p) => p.package_id === targetPackageId)
42
+ if (!pkg) {
43
+ return ctx.error(404, {
44
+ error_code: "package_not_found",
45
+ message: "Package not found",
46
+ })
47
+ }
48
+ if (pkg.creator_account_id !== ctx.auth.account_id) {
49
+ console.log(
50
+ pkg.creator_account_id !== ctx.auth.account_id,
51
+ pkg.creator_account_id,
52
+ ctx.auth.account_id,
53
+ )
54
+ return ctx.error(403, {
55
+ error_code: "unauthorized",
56
+ message: "You are not authorized to access this package",
57
+ })
58
+ }
59
+ }
60
+
61
+ let builds = ctx.db.packageBuilds
62
+
63
+ if (package_id) {
64
+ const packageReleases = ctx.db.packageReleases.filter(
65
+ (x) => x.package_id === package_id,
66
+ )
67
+ if (packageReleases.length === 0) {
68
+ return ctx.error(404, {
69
+ error_code: "package_not_found",
70
+ message: "Package not found",
71
+ })
72
+ }
73
+
74
+ const packageReleaseIds = packageReleases
75
+ .filter((pr) => pr.package_id === package_id)
76
+ .map((pr) => pr.package_release_id)
77
+
78
+ builds = builds.filter((build) =>
79
+ packageReleaseIds.includes(build.package_release_id),
80
+ )
81
+ }
82
+
83
+ if (package_release_id) {
84
+ builds = builds.filter(
85
+ (build) => build.package_release_id === package_release_id,
86
+ )
87
+ }
88
+
89
+ builds = builds.sort(
90
+ (a, b) =>
91
+ new Date(b.created_at).getTime() - new Date(a.created_at).getTime(),
92
+ )
93
+
94
+ const latestBuild = builds[0] || null
95
+
96
+ if (!latestBuild) {
97
+ return ctx.json({
98
+ package_build: null,
99
+ })
100
+ }
101
+
102
+ const publicBuild = publicMapPackageBuild(latestBuild, {
103
+ include_logs: true,
104
+ })
105
+
106
+ return ctx.json({
107
+ package_build: publicBuild,
108
+ })
109
+ })
@@ -0,0 +1,98 @@
1
+ import { withRouteSpec } from "fake-snippets-api/lib/middleware/with-winter-spec"
2
+ import { z } from "zod"
3
+ import { publicMapPackageBuild } from "fake-snippets-api/lib/public-mapping/public-map-package-build"
4
+
5
+ export default withRouteSpec({
6
+ methods: ["GET"],
7
+ auth: "session",
8
+ queryParams: z.object({
9
+ package_id: z.string().optional(),
10
+ package_release_id: z.string().optional(),
11
+ }),
12
+ jsonResponse: z.object({
13
+ package_builds: z.array(z.any()),
14
+ }),
15
+ })(async (req, ctx) => {
16
+ const { package_id, package_release_id } = req.query
17
+ console.log(ctx.db.packageBuilds)
18
+ if (!package_id && !package_release_id) {
19
+ return ctx.error(400, {
20
+ error_code: "invalid_request",
21
+ message: "Either package_id or package_release_id must be provided",
22
+ })
23
+ }
24
+
25
+ let targetPackageId = package_id
26
+
27
+ if (package_release_id) {
28
+ const packageRelease = ctx.db.packageReleases.find(
29
+ (pr) => pr.package_release_id === package_release_id,
30
+ )
31
+ if (!packageRelease) {
32
+ return ctx.error(404, {
33
+ error_code: "package_release_not_found",
34
+ message: "Package release not found",
35
+ })
36
+ }
37
+ targetPackageId = packageRelease.package_id
38
+ }
39
+
40
+ if (targetPackageId) {
41
+ const pkg = ctx.db.packages.find((p) => p.package_id === targetPackageId)
42
+ if (!pkg) {
43
+ return ctx.error(404, {
44
+ error_code: "package_not_found",
45
+ message: "Package not found",
46
+ })
47
+ }
48
+ if (pkg.creator_account_id !== ctx.auth.account_id) {
49
+ return ctx.error(403, {
50
+ error_code: "unauthorized",
51
+ message: "You are not authorized to access this package",
52
+ })
53
+ }
54
+ }
55
+
56
+ let builds = ctx.db.packageBuilds
57
+
58
+ if (package_id) {
59
+ const packageReleases = ctx.db.packageReleases.filter(
60
+ (x) => x.package_id === package_id,
61
+ )
62
+ if (packageReleases.length === 0) {
63
+ return ctx.error(404, {
64
+ error_code: "package_not_found",
65
+ message: "Package not found",
66
+ })
67
+ }
68
+
69
+ const packageReleaseIds = packageReleases
70
+ .filter((pr) => pr.package_id === package_id)
71
+ .map((pr) => pr.package_release_id)
72
+
73
+ builds = builds.filter((build) =>
74
+ packageReleaseIds.includes(build.package_release_id),
75
+ )
76
+ }
77
+
78
+ if (package_release_id) {
79
+ builds = builds.filter(
80
+ (build) => build.package_release_id === package_release_id,
81
+ )
82
+ }
83
+
84
+ builds = builds.sort(
85
+ (a, b) =>
86
+ new Date(b.created_at).getTime() - new Date(a.created_at).getTime(),
87
+ )
88
+
89
+ const publicBuilds = builds.map((build) =>
90
+ publicMapPackageBuild(build, {
91
+ include_logs: false,
92
+ }),
93
+ )
94
+
95
+ return ctx.json({
96
+ package_builds: publicBuilds,
97
+ })
98
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/fake-snippets",
3
- "version": "0.0.105",
3
+ "version": "0.0.106",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
package/src/App.tsx CHANGED
@@ -143,7 +143,8 @@ class ErrorBoundary extends React.Component<
143
143
  this.cleanup() // Clean up listeners before reload
144
144
  this.setState({ reloading: true })
145
145
  this.reloadTimeout = window.setTimeout(() => {
146
- // window.location.reload()
146
+ if (window?.location.href.includes("localhost:")) return
147
+ window.location.reload()
147
148
  }, 500)
148
149
  }
149
150
 
@@ -5,12 +5,9 @@ import { usePackageReleaseById } from "@/hooks/use-package-release"
5
5
  import { timeAgo } from "@/lib/utils/timeAgo"
6
6
  import { BuildStatus, BuildStep } from "./build-status"
7
7
  import type { PackageRelease } from "fake-snippets-api/lib/db/schema"
8
- import {
9
- getBuildStatus,
10
- getLatestBuildFromPackageRelease,
11
- StatusIcon,
12
- } from "@/components/preview"
8
+ import { getBuildStatus, StatusIcon } from "@/components/preview"
13
9
  import { PrefetchPageLink } from "@/components/PrefetchPageLink"
10
+ import { useLatestPackageBuildByReleaseId } from "@/hooks/use-package-builds"
14
11
 
15
12
  function getTranspilationStatus(
16
13
  pr?: PackageRelease | null,
@@ -45,6 +42,9 @@ export default function SidebarReleasesSection() {
45
42
  const { data: packageRelease } = usePackageReleaseById(
46
43
  packageInfo?.latest_package_release_id,
47
44
  )
45
+ const { data: latestBuild } = useLatestPackageBuildByReleaseId(
46
+ packageRelease?.package_release_id,
47
+ )
48
48
 
49
49
  const buildSteps: BuildStep[] = [
50
50
  {
@@ -74,8 +74,9 @@ export default function SidebarReleasesSection() {
74
74
  )
75
75
  }
76
76
 
77
- const latestBuild = getLatestBuildFromPackageRelease(packageRelease)
78
- const { status, label } = getBuildStatus(latestBuild)
77
+ const { status, label } = latestBuild
78
+ ? getBuildStatus(latestBuild)
79
+ : { status: "pending", label: "pending" }
79
80
  return (
80
81
  <div className="mb-6">
81
82
  <h2 className="text-lg font-semibold mb-2">Releases</h2>