@tscircuit/fake-snippets 0.0.9 → 0.0.10

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.
@@ -983,6 +983,27 @@ const initializer = combine(databaseSchema.parse({}), (set, get) => ({
983
983
  }))
984
984
  return newPackage as Package
985
985
  },
986
+ updatePackage: (
987
+ packageId: string,
988
+ updates: Partial<Package>,
989
+ ): Package | undefined => {
990
+ let updatedPackage: Package | undefined
991
+ set((state) => {
992
+ const packageIndex = state.packages.findIndex(
993
+ (pkg) => pkg.package_id === packageId,
994
+ )
995
+ if (packageIndex === -1) return state
996
+
997
+ const updatedPackages = [...state.packages]
998
+ updatedPackages[packageIndex] = {
999
+ ...updatedPackages[packageIndex],
1000
+ ...updates,
1001
+ }
1002
+ updatedPackage = updatedPackages[packageIndex]
1003
+ return { ...state, packages: updatedPackages }
1004
+ })
1005
+ return updatedPackage
1006
+ },
986
1007
  getPackageById: (packageId: string): Package | undefined => {
987
1008
  const state = get()
988
1009
  const pkg = state.packages.find((pkg) => pkg.package_id === packageId)
@@ -0,0 +1,91 @@
1
+ import { z } from "zod"
2
+ import { packageSchema } from "../../../lib/db/schema"
3
+ import { withRouteSpec } from "../../../lib/middleware/with-winter-spec"
4
+
5
+ export default withRouteSpec({
6
+ methods: ["POST"],
7
+ auth: "session",
8
+ jsonBody: z
9
+ .object({
10
+ package_id: z.string(),
11
+ name: z
12
+ .string()
13
+ .regex(
14
+ /^[@a-zA-Z0-9-_\/]+$/,
15
+ "Package name can only contain letters, numbers, hyphens, underscores, and forward slashes",
16
+ )
17
+ .transform((name) => name.replace(/^@/, ""))
18
+ .optional(),
19
+ description: z.string().optional(),
20
+ is_private: z.boolean().optional(),
21
+ is_unlisted: z.boolean().optional(),
22
+ })
23
+ .transform((data) => ({
24
+ ...data,
25
+ is_unlisted: data.is_private ? true : data.is_unlisted,
26
+ })),
27
+ jsonResponse: z.object({
28
+ ok: z.boolean(),
29
+ package: packageSchema,
30
+ }),
31
+ })(async (req, ctx) => {
32
+ const { package_id, name, description, is_private, is_unlisted } =
33
+ req.jsonBody
34
+
35
+ const packageIndex = ctx.db.packages.findIndex(
36
+ (p) => p.package_id === package_id,
37
+ )
38
+
39
+ if (packageIndex === -1) {
40
+ return ctx.error(404, {
41
+ error_code: "package_not_found",
42
+ message: "Package not found",
43
+ })
44
+ }
45
+
46
+ const existingPackage = ctx.db.packages[packageIndex]
47
+
48
+ // Check if user has permission to update the package
49
+ if (existingPackage.creator_account_id !== ctx.auth.account_id) {
50
+ return ctx.error(403, {
51
+ error_code: "forbidden",
52
+ message: "You don't have permission to update this package",
53
+ })
54
+ }
55
+
56
+ // Check for duplicate package name if name is being updated
57
+ if (name) {
58
+ const newFullName = `${ctx.auth.github_username}/${name}`
59
+ const duplicatePackage = ctx.db.packages.find(
60
+ (p) => p.name === newFullName && p.package_id !== package_id,
61
+ )
62
+ if (duplicatePackage) {
63
+ return ctx.error(400, {
64
+ error_code: "package_already_exists",
65
+ message: "A package with this name already exists",
66
+ })
67
+ }
68
+ }
69
+
70
+ const updatedPackage = ctx.db.updatePackage(package_id, {
71
+ name: name ? `${ctx.auth.github_username}/${name}` : existingPackage.name,
72
+ description: description ?? existingPackage.description,
73
+ is_private: is_private ?? existingPackage.is_private,
74
+ is_public:
75
+ is_private !== undefined ? !is_private : existingPackage.is_public,
76
+ is_unlisted: is_unlisted ?? existingPackage.is_unlisted,
77
+ updated_at: new Date().toISOString(),
78
+ })
79
+
80
+ if (!updatedPackage) {
81
+ return ctx.error(500, {
82
+ error_code: "update_failed",
83
+ message: "Failed to update package",
84
+ })
85
+ }
86
+
87
+ return ctx.json({
88
+ ok: true,
89
+ package: updatedPackage,
90
+ })
91
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/fake-snippets",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",