-
-
Notifications
You must be signed in to change notification settings - Fork 747
Expand file tree
/
Copy pathcontext.ts
More file actions
54 lines (50 loc) · 1.76 KB
/
Copy pathcontext.ts
File metadata and controls
54 lines (50 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { createContext } from 'unctx'
type ContextKey = 'zod3' | 'zod4' | 'valibot' | 'effect' | 'unknown'
const nuxtContentContext = {
zod3: {
toJSONSchema: (_schema: unknown, _name: string) => {
throw new Error(
'It seems you are using Zod version 3 for collection schema, but Zod is not installed, '
+ 'Nuxt Content does not ship with zod, install `zod` and `zod-to-json-schema` and it will work.',
)
},
},
zod4: {
toJSONSchema: (_schema: unknown, _name: string) => {
throw new Error(
'It seems you are using Zod version 4 for collection schema, but Zod is not installed, '
+ 'Nuxt Content does not ship with zod, install `zod` and it will work.',
)
},
},
valibot: {
toJSONSchema: (_schema: unknown, _name: string) => {
throw new Error(
'It seems you are using Valibot for collection schema, but Valibot is not installed, '
+ 'Nuxt Content does not ship with valibot, install `valibot` and `@valibot/to-json-schema` and it will work.',
)
},
},
effect: {
toJSONSchema: (_schema: unknown, _name: string) => {
throw new Error(
'It seems you are using Effect Schema for collection schema, but Effect is not installed, '
+ 'Nuxt Content does not ship with effect, install `effect` it will work.',
)
},
},
unknown: {
toJSONSchema: (_schema: unknown, _name: string) => {
throw new Error('Unknown schema vendor')
},
},
set: (key: ContextKey, value: unknown) => {
nuxtContentContext[key] = value as typeof nuxtContentContext[ContextKey]
},
get: (key: ContextKey) => {
return nuxtContentContext[key]
},
}
const ctx = createContext<typeof nuxtContentContext>()
ctx.set(nuxtContentContext)
export default ctx.use