content-query 0.2.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.
- package/README.md +28 -3
- package/dist/{build-Dxz7P1ur.mjs → build-CcqIpkes.mjs} +763 -39
- package/dist/build-DL1GzmRy.d.mts +55 -0
- package/dist/build.d.mts +2 -2
- package/dist/build.mjs +1 -1
- package/dist/cli.mjs +14 -8
- package/dist/computed.d.mts +2 -2
- package/dist/{content-N1gYshjg.mjs → content-BXrgP7nL.mjs} +271 -81
- package/dist/{content-G69dPPuo.d.mts → content-CwTKqRs9.d.mts} +49 -24
- package/dist/{types-ChaNhj42.d.mts → descriptor-bcPa6XLk.d.mts} +26 -1
- package/dist/{diagnostics-Cu94mZhl.mjs → diagnostics-DmUZtrJ6.mjs} +3 -1
- package/dist/{errors-C2iuBM0G.mjs → errors-Bfd0R4_P.mjs} +16 -1
- package/dist/file-DSOcdFj0.mjs +81 -0
- package/dist/{glob-Bv0dpvCQ.mjs → glob-BXJuwy_p.mjs} +94 -6
- package/dist/index.d.mts +61 -17
- package/dist/index.mjs +1 -1
- package/dist/internal.d.mts +11 -4
- package/dist/internal.mjs +29 -5
- package/dist/loaders.d.mts +2 -3
- package/dist/loaders.mjs +2 -81
- package/dist/next.d.mts +1 -1
- package/dist/next.mjs +2 -2
- package/dist/{operators-UqWUhKQJ.mjs → operators-Cwy8Kx4o.mjs} +88 -2
- package/dist/query-style-eXENQJ0O.d.mts +22 -0
- package/dist/query.d.mts +25 -2
- package/dist/query.mjs +1 -1
- package/dist/{relational-types-DgK3rLuw.d.mts → relational-types-C8xJtLG5.d.mts} +113 -38
- package/dist/runtime.d.mts +3 -2
- package/dist/runtime.mjs +1 -1
- package/dist/types-DbFfF6JE.d.mts +181 -0
- package/dist/vite.d.mts +15 -3
- package/dist/vite.mjs +25 -2
- package/package.json +2 -2
- package/dist/build-DfKd2bpf.d.mts +0 -25
- package/dist/descriptor-D9Th5hzk.d.mts +0 -18
- package/dist/types-C-kdMblM.d.mts +0 -69
- package/dist/validation-D_XdE1pF.mjs +0 -84
package/README.md
CHANGED
|
@@ -10,6 +10,8 @@ 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.
|
|
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.
|
|
13
15
|
- **Framework integrations.** Use Vite, Next.js, or the standalone CLI, with content updates during development.
|
|
14
16
|
|
|
15
17
|
## Usage
|
|
@@ -50,8 +52,8 @@ import { content } from "./.content-query/server.js";
|
|
|
50
52
|
import { eq } from "content-query/query";
|
|
51
53
|
|
|
52
54
|
const posts = await content
|
|
53
|
-
.select("id", "title")
|
|
54
55
|
.from("posts")
|
|
56
|
+
.select("id", "title")
|
|
55
57
|
.where((fields) => eq(fields.draft, false))
|
|
56
58
|
.orderBy("title");
|
|
57
59
|
|
|
@@ -62,8 +64,25 @@ const post = await content.query.posts.findFirst({
|
|
|
62
64
|
const { html, headings } = post!._payloads._rendered;
|
|
63
65
|
```
|
|
64
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
|
+
|
|
65
69
|
Add `.content-query/` to `.gitignore`. Follow the quick start for a complete walkthrough, or choose a framework example below.
|
|
66
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
|
+
|
|
67
86
|
## Migrating to 0.2
|
|
68
87
|
|
|
69
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:
|
|
@@ -74,7 +93,7 @@ Version 0.2.0 removes `content.readBody()` and `content.render()`. Request bodie
|
|
|
74
93
|
| `await content.render("posts", id)` | `(await content.query.posts.findFirst({ where: { id }, payloads: { _rendered: true } }))?._payloads._rendered` |
|
|
75
94
|
| Fluent queries | Add `.withPayload("_rendered")` or `.withPayload("_body")` before the terminal. |
|
|
76
95
|
|
|
77
|
-
Built-in payload names start with an underscore: `_body` and `_rendered`. A query for a missing entry returns `undefined` instead of rejecting with `entry-not-found`, which no longer exists. JSON, YAML, and TOML sources and `file()` collections offer no payloads
|
|
96
|
+
Built-in payload names start with an underscore: `_body` and `_rendered`. A query for a missing entry returns `undefined` instead of rejecting with `entry-not-found`, which no longer exists. JSON, YAML, and TOML sources and `file()` collections offer no payloads, and custom loaders typed as `BodyLoader` offer only `_body`. Rebuild generated content after upgrading; 0.1 artifacts are rejected.
|
|
78
97
|
|
|
79
98
|
## Documentation
|
|
80
99
|
|
|
@@ -83,10 +102,16 @@ Built-in payload names start with an underscore: `_body` and `_rendered`. A quer
|
|
|
83
102
|
- [API and usage](https://github.com/yangshun/content-query/blob/main/docs/API.md)
|
|
84
103
|
- [Guides and reference](https://github.com/yangshun/content-query/blob/main/docs/README.md)
|
|
85
104
|
|
|
86
|
-
The Vite integration supports Vite 8, and the Next.js integration supports Next.js 16. Both integrations are optional; standalone builds and queries require neither framework.
|
|
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.
|
|
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).
|
|
87
108
|
|
|
88
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.
|
|
89
110
|
|
|
90
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`.
|
|
91
112
|
|
|
113
|
+
Build integrations can reuse the active source session without reading schemas or bodies. `ContentSession.sources()` from `content-query/build` returns an immutable `{ revision, entries: [{ collection, id, filePath? }] }` snapshot; `session.subscribe(listener)` reports successful publications (`{ type: "ready", snapshot }`) and errors (`{ type: "error", error }`) and returns an unsubscribe function. Revisions are opaque and session-scoped. In Vite, `contentQuery().api.prepare()` asynchronously prepares the shared session and returns its source snapshot, and `.api.subscribe()` forwards subsequent events. The [MDX architecture](https://github.com/yangshun/content-query/blob/main/docs/MDX-ARCHITECTURE.md) documents its use by companion integrations.
|
|
114
|
+
|
|
115
|
+
`prepare()` waits for pending preparation and rejects while validation errors are active. Successful unchanged reads reuse the frozen snapshot; publications supply a new revision. Subscribers can observe errors and recovery, and unsubscribing stops subsequent notifications. Development integrations should let core display recoverable errors without aborting the server or replacing the host's refresh subscription.
|
|
116
|
+
|
|
92
117
|
Released under the [MIT license](https://github.com/yangshun/content-query/blob/main/LICENSE).
|