zce / velite

Turns Markdown / MDX, YAML, JSON, or others into app's data layer with Zod schema.
http://velite.js.org
MIT License
476 stars 23 forks source link

Error on top level array for JSON/YAML #103

Closed xiBread closed 6 months ago

xiBread commented 6 months ago

Given this config file:

import { defineConfig, s } from "velite";

export default defineConfig({
    collections: {
        data: {
            name: "Data",
            pattern: "data/index.json",
            single: true,
            schema: s.array(s.string()),
        },
    },
});

and this JSON file:

[
    "foo",
    "bar",
    "baz"
]

Running velite gives the following warnings and fails to produce any output.

Screenshot 2024-04-03 at 8 41 40 PM
zce commented 6 months ago
import { defineConfig, s } from "velite";

export default defineConfig({
    collections: {
        data: {
            name: "Data",
            pattern: "data/index.json",
            schema: s.string(),
        },
    },
});

The schema of velite is the schema of a single entity, not the array schema of a collection list

xiBread commented 6 months ago

Ah, got it.