Skip to content

Commit 16add50

Browse files
committed
sync
1 parent 51368c2 commit 16add50

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

bun.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
},
157157
"packages/enterprise": {
158158
"name": "@opencode-ai/enterprise",
159+
"version": "0.0.0",
159160
"dependencies": {
160161
"@opencode-ai/util": "workspace:*",
161162
"@solidjs/router": "^0.15.0",
@@ -344,6 +345,9 @@
344345
"packages/util": {
345346
"name": "@opencode-ai/util",
346347
"version": "0.0.0",
348+
"dependencies": {
349+
"zod": "catalog:",
350+
},
347351
"devDependencies": {
348352
"typescript": "catalog:",
349353
},
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { fn } from "@opencode-ai/util/fn"
2+
import z from "zod"
3+
import { Storage } from "./storage"
4+
5+
export namespace Share {
6+
export const Info = z.object({
7+
id: z.string(),
8+
secret: z.string(),
9+
})
10+
export type Info = z.infer<typeof Info>
11+
12+
export const create = fn(Info.pick({ id: true }), async (body) => {
13+
const info: Info = {
14+
id: body.id,
15+
secret: crypto.randomUUID(),
16+
}
17+
await Storage.write(["share", info.id], info)
18+
})
19+
}

packages/util/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"scripts": {
1010
"typecheck": "tsc --noEmit"
1111
},
12+
"dependencies": {
13+
"zod": "catalog:"
14+
},
1215
"devDependencies": {
1316
"typescript": "catalog:"
1417
}

packages/util/src/fn.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { z } from "zod"
2+
3+
export function fn<T extends z.ZodType, Result>(schema: T, cb: (input: z.infer<T>) => Result) {
4+
const result = (input: z.infer<T>) => {
5+
const parsed = schema.parse(input)
6+
return cb(parsed)
7+
}
8+
result.force = (input: z.infer<T>) => cb(input)
9+
result.schema = schema
10+
return result
11+
}

0 commit comments

Comments
 (0)