content-query 0.3.0 → 0.4.0

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.
Files changed (36) hide show
  1. package/README.md +21 -1
  2. package/dist/{build-CI4s0oFP.mjs → build-CcqIpkes.mjs} +709 -39
  3. package/dist/{build-jKnjDjQE.d.mts → build-DL1GzmRy.d.mts} +12 -5
  4. package/dist/build.d.mts +1 -1
  5. package/dist/build.mjs +1 -1
  6. package/dist/cli.mjs +14 -8
  7. package/dist/computed.d.mts +2 -2
  8. package/dist/{content-N1gYshjg.mjs → content-BXrgP7nL.mjs} +271 -81
  9. package/dist/{content-lwPxE9Yu.d.mts → content-CwTKqRs9.d.mts} +39 -14
  10. package/dist/{types-FmUJ3cH1.d.mts → descriptor-bcPa6XLk.d.mts} +17 -1
  11. package/dist/{diagnostics-Cu94mZhl.mjs → diagnostics-DmUZtrJ6.mjs} +3 -1
  12. package/dist/{errors-C2iuBM0G.mjs → errors-Bfd0R4_P.mjs} +16 -1
  13. package/dist/file-DSOcdFj0.mjs +81 -0
  14. package/dist/{glob-Bv0dpvCQ.mjs → glob-BXJuwy_p.mjs} +94 -6
  15. package/dist/index.d.mts +61 -18
  16. package/dist/index.mjs +1 -1
  17. package/dist/internal.d.mts +11 -4
  18. package/dist/internal.mjs +29 -5
  19. package/dist/loaders.d.mts +1 -2
  20. package/dist/loaders.mjs +2 -81
  21. package/dist/next.d.mts +1 -1
  22. package/dist/next.mjs +2 -2
  23. package/dist/{operators-UqWUhKQJ.mjs → operators-Cwy8Kx4o.mjs} +88 -2
  24. package/dist/query-style-eXENQJ0O.d.mts +22 -0
  25. package/dist/query.d.mts +25 -2
  26. package/dist/query.mjs +1 -1
  27. package/dist/{relational-types-B45zM34W.d.mts → relational-types-C8xJtLG5.d.mts} +113 -38
  28. package/dist/runtime.d.mts +3 -2
  29. package/dist/runtime.mjs +1 -1
  30. package/dist/types-DbFfF6JE.d.mts +181 -0
  31. package/dist/vite.d.mts +1 -1
  32. package/dist/vite.mjs +2 -2
  33. package/package.json +1 -1
  34. package/dist/descriptor-BUPT2J7X.d.mts +0 -18
  35. package/dist/types-BC8gVJ6u.d.mts +0 -69
  36. package/dist/validation-D_XdE1pF.mjs +0 -84
package/README.md CHANGED
@@ -10,6 +10,7 @@ Use it with your existing framework. Your application owns its routes, layouts,
10
10
  - **Flexible sources.** Load local files, use Astro-compatible content loaders, or write your own loader.
11
11
  - **Queries and relationships.** Select fields, filter, sort, paginate, and load related entries with validated references.
12
12
  - **Markdown rendering.** Request HTML, headings, and syntax highlighting as query payloads, loaded only when a query asks for them.
13
+ - **Custom payloads.** Declare schema-validated per-entry data, optionally by variant such as locale, resolved during the build from tracked related files, and loaded only when a query names it. Development edits re-resolve only the variants whose files changed.
13
14
  - **Optional MDX companion.** [`@content-query/mdx`](https://github.com/yangshun/content-query/tree/main/packages/mdx) supplies React islands and ordinary React document modules with Vite SSR. Core has no MDX or React dependency.
14
15
  - **Framework integrations.** Use Vite, Next.js, or the standalone CLI, with content updates during development.
15
16
 
@@ -51,8 +52,8 @@ import { content } from "./.content-query/server.js";
51
52
  import { eq } from "content-query/query";
52
53
 
53
54
  const posts = await content
54
- .select("id", "title")
55
55
  .from("posts")
56
+ .select("id", "title")
56
57
  .where((fields) => eq(fields.draft, false))
57
58
  .orderBy("title");
58
59
 
@@ -63,8 +64,25 @@ const post = await content.query.posts.findFirst({
63
64
  const { html, headings } = post!._payloads._rendered;
64
65
  ```
65
66
 
67
+ Queries return only the data they select, not even `id` implicitly. A query must select fields, include a relationship, request a payload, or select adjacent entries; otherwise it fails to type-check and throws an `invalid-query` error. Counts need no selection.
68
+
66
69
  Add `.content-query/` to `.gitignore`. Follow the quick start for a complete walkthrough, or choose a framework example below.
67
70
 
71
+ ## Migrating to 0.4
72
+
73
+ Version 0.4.0 starts fluent queries from the collection and selects no data implicitly:
74
+
75
+ | 0.3 | 0.4 |
76
+ | --------------------------------------------- | ---------------------------------------------------------------------------------- |
77
+ | `content.select("id", "title").from("posts")` | `content.from("posts").select("id", "title")` |
78
+ | `content.select().from("posts")` | `content.from("posts").select(...)` listing the fields used |
79
+ | `findMany()` or `findMany({ where })` | Add `columns: { field: true }` for each field used |
80
+ | `columns: { draft: false }` | List the included fields with `true` |
81
+ | `with: { author: true }` | `with: { author: { columns: { name: true } } }` |
82
+ | `adjacent: true` or `.selectAdjacent()` | `adjacent: { scope: "results", columns: { id: true } }` or `.selectAdjacent("id")` |
83
+
84
+ Results include `id` only when it is selected. Queries that request only payloads, such as `findFirst({ where: { id }, payloads: { _rendered: true } })`, need no columns.
85
+
68
86
  ## Migrating to 0.2
69
87
 
70
88
  Version 0.2.0 removes `content.readBody()` and `content.render()`. Request bodies and rendered output as payloads in the query that loads the entry:
@@ -86,6 +104,8 @@ Built-in payload names start with an underscore: `_body` and `_rendered`. A quer
86
104
 
87
105
  The Vite integration supports Vite 8, and the Next.js integration supports Next.js 15 and 16. Both integrations are optional; standalone builds and queries require neither framework.
88
106
 
107
+ To allow only one query API, export `queryStyle` from the config: `export const queryStyle = "relational";` keeps `content.query` and `content.count()`, and `"fluent"` keeps `content.from()`. Generated types report the disabled API in the editor, and the runtime throws an `invalid-query` error for it. See [query style](https://github.com/yangshun/content-query/blob/main/docs/API.md#query-style).
108
+
89
109
  Pass `contentQuery()` directly to Vite or Vite+'s `plugins` array. No `Plugin` type cast is needed; workspace consumers share the pinned toolchain versions in the dependency catalog.
90
110
 
91
111
  Repository development checks package types and isolated consumers with [tsrs](https://github.com/oxc-project/tsrs). Run `vp run check` in the package directory for formatting, linting, and type checks; build tools use the shared TypeScript 6 compatibility package for its `6.0.3` JavaScript API. Native TypeScript `7.1.0-beta` is available at the repository root as `vp exec tsc`.