@tscircuit/fake-snippets 0.0.79 → 0.0.80
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.
- package/bun-tests/fake-snippets-api/routes/package_releases/create.test.ts +25 -0
- package/dist/bundle.js +14 -2
- package/fake-snippets-api/routes/api/package_releases/create.ts +14 -1
- package/package.json +1 -1
- package/src/hooks/use-create-package-release-mutation.ts +63 -13
- package/src/lib/templates/blank-package-template.ts +4 -5
|
@@ -8,6 +8,7 @@ export default withRouteSpec({
|
|
|
8
8
|
auth: "none",
|
|
9
9
|
jsonBody: z.object({
|
|
10
10
|
package_id: z.string().optional(),
|
|
11
|
+
package_name: z.string().optional(),
|
|
11
12
|
version: z.string().optional(),
|
|
12
13
|
is_latest: z.boolean().optional(),
|
|
13
14
|
commit_sha: z.string().optional(),
|
|
@@ -20,6 +21,7 @@ export default withRouteSpec({
|
|
|
20
21
|
})(async (req, ctx) => {
|
|
21
22
|
let {
|
|
22
23
|
package_id,
|
|
24
|
+
package_name,
|
|
23
25
|
is_latest = true,
|
|
24
26
|
version,
|
|
25
27
|
commit_sha,
|
|
@@ -41,10 +43,21 @@ export default withRouteSpec({
|
|
|
41
43
|
version = parsedVersion
|
|
42
44
|
}
|
|
43
45
|
|
|
46
|
+
if (!package_id && package_name) {
|
|
47
|
+
const pkg = ctx.db.packages.find((p) => p.name === package_name)
|
|
48
|
+
if (!pkg) {
|
|
49
|
+
return ctx.error(404, {
|
|
50
|
+
error_code: "package_not_found",
|
|
51
|
+
message: `Package not found: ${package_name}`,
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
package_id = pkg.package_id
|
|
55
|
+
}
|
|
56
|
+
|
|
44
57
|
if (!package_id || !version) {
|
|
45
58
|
return ctx.error(400, {
|
|
46
59
|
error_code: "missing_options",
|
|
47
|
-
message: "package_id and version are required",
|
|
60
|
+
message: "package_id or package_name and version are required",
|
|
48
61
|
})
|
|
49
62
|
}
|
|
50
63
|
|
package/package.json
CHANGED
|
@@ -29,21 +29,71 @@ export const useCreatePackageReleaseMutation = ({
|
|
|
29
29
|
)
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
let resolvedVersion = version
|
|
33
|
+
let resolvedPkgName = package_name_with_version
|
|
34
|
+
|
|
35
|
+
// Parse version from package_name_with_version if needed
|
|
36
|
+
if (package_name_with_version && !version) {
|
|
37
|
+
const [pkgName, parsedVersion] = package_name_with_version.split("@")
|
|
38
|
+
resolvedVersion = parsedVersion
|
|
39
|
+
resolvedPkgName = pkgName
|
|
40
|
+
} else if (package_name_with_version) {
|
|
41
|
+
const [pkgName] = package_name_with_version.split("@")
|
|
42
|
+
resolvedPkgName = pkgName
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Default version to 1.0.0 when it contains no digits
|
|
46
|
+
if (!resolvedVersion || !/[0-9]/.test(resolvedVersion)) {
|
|
47
|
+
resolvedVersion = "1.0.0"
|
|
44
48
|
}
|
|
45
49
|
|
|
46
|
-
|
|
50
|
+
const normalizedPackageNameWithVersion =
|
|
51
|
+
resolvedPkgName && `${resolvedPkgName}@${resolvedVersion}`
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
const {
|
|
55
|
+
data: { package_release: newPackageRelease },
|
|
56
|
+
} = await axios.post("/package_releases/create", {
|
|
57
|
+
package_id,
|
|
58
|
+
version: resolvedVersion,
|
|
59
|
+
is_latest,
|
|
60
|
+
commit_sha,
|
|
61
|
+
package_name_with_version: normalizedPackageNameWithVersion,
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
if (!newPackageRelease) {
|
|
65
|
+
throw new Error("Failed to create package release")
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return newPackageRelease
|
|
69
|
+
} catch (error: any) {
|
|
70
|
+
if (
|
|
71
|
+
error.status === 400 &&
|
|
72
|
+
error.data?.error?.error_code === "version_already_exists" &&
|
|
73
|
+
normalizedPackageNameWithVersion
|
|
74
|
+
) {
|
|
75
|
+
// Update the existing release with the provided data
|
|
76
|
+
await axios.post("/package_releases/update", {
|
|
77
|
+
package_name_with_version: normalizedPackageNameWithVersion,
|
|
78
|
+
is_latest,
|
|
79
|
+
commit_sha,
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
const {
|
|
83
|
+
data: { package_release },
|
|
84
|
+
} = await axios.post("/package_releases/get", {
|
|
85
|
+
package_name_with_version: normalizedPackageNameWithVersion,
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
if (!package_release) {
|
|
89
|
+
throw new Error("Failed to update package release")
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return package_release as PackageRelease
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
throw error
|
|
96
|
+
}
|
|
47
97
|
},
|
|
48
98
|
{
|
|
49
99
|
onSuccess: (packageRelease: PackageRelease) => {
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
export const blankPackageTemplate = {
|
|
2
2
|
type: "package",
|
|
3
3
|
code: `
|
|
4
|
-
import {
|
|
4
|
+
import type { ChipProps } from "@tscircuit/props"
|
|
5
5
|
|
|
6
|
-
export const MyChip = (props: { name: string }) => (
|
|
7
|
-
<chip {...props} pinLabels={pinLabels} footprint="soic8" />
|
|
8
|
-
)
|
|
9
6
|
const pinLabels = {
|
|
10
7
|
pin1: [],
|
|
11
8
|
pin2: [],
|
|
@@ -17,6 +14,8 @@ const pinLabels = {
|
|
|
17
14
|
pin8: [],
|
|
18
15
|
} as const
|
|
19
16
|
|
|
20
|
-
export const
|
|
17
|
+
export const MyChip = (props: ChipProps<typeof pinLabels>) => (
|
|
18
|
+
<chip footprint="soic8" pinLabels={pinLabels} {...props} />
|
|
19
|
+
)
|
|
21
20
|
`.trim(),
|
|
22
21
|
}
|