Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"@libsql/client": "*",
"@valibot/to-json-schema": "^1.5.0",
"better-sqlite3": "^12.5.0",
"effect": "^3.19.13",
"sqlite3": "*",
"valibot": "^1.2.0"
},
Expand Down Expand Up @@ -154,6 +155,7 @@
"@types/pg": "^8.16.0",
"@types/ws": "^8.18.1",
"@valibot/to-json-schema": "^1.5.0",
"effect": "^3.19.13",
"csvtojson": "^2.0.14",
"eslint": "^9.39.2",
"happy-dom": "^20.0.11",
Expand Down
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/utils/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createContext } from 'unctx'

type ContextKey = 'zod3' | 'zod4' | 'valibot' | 'unknown'
type ContextKey = 'zod3' | 'zod4' | 'valibot' | 'effect' | 'unknown'

const nuxtContentContext = {
zod3: {
Expand All @@ -27,6 +27,14 @@ const nuxtContentContext = {
)
},
},
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')
Expand Down
17 changes: 17 additions & 0 deletions src/utils/schema/effect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { JSONSchema } from 'effect'
import type { Draft07, Draft07Definition } from '../../types'

export function toJSONSchema(schema: unknown, name: string): Draft07 {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const definitions = JSONSchema.make(schema as any, {
target: 'jsonSchema7',
}) as Draft07Definition

return {
$schema: 'http://json-schema.org/draft-07/schema#',
$ref: `#/definitions/${name}`,
definitions: {
[name]: definitions,
},
}
}
7 changes: 7 additions & 0 deletions src/utils/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export function property<T extends ContentStandardSchemaV1>(input: T): Property<
case 'valibot':
schema.$content = $content
return
case 'effect':
schema.$content = $content
return
case 'zod4':
(schema as unknown as { def: { $content: ContentConfig } }).def.$content = $content
return
Expand Down Expand Up @@ -98,6 +101,10 @@ export function detectSchemaVendor(schema: ContentStandardSchemaV1) {
return 'valibot'
}

if (schema['~standard']?.vendor === 'effect') {
return 'effect'
}

if (schema['~standard']?.vendor === 'zod') {
return (schema as unknown as Record<string, unknown>).def ? 'zod4' : 'zod3'
}
Expand Down
Loading