content-query 0.0.2 → 0.2.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 (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +91 -2
  3. package/dist/build-DfKd2bpf.d.mts +25 -0
  4. package/dist/build-Dxz7P1ur.mjs +1439 -0
  5. package/dist/build.d.mts +2 -0
  6. package/dist/build.mjs +1 -0
  7. package/dist/cli.d.mts +1 -0
  8. package/dist/cli.mjs +97 -0
  9. package/dist/computed.d.mts +43 -0
  10. package/dist/computed.mjs +139 -0
  11. package/dist/content-G69dPPuo.d.mts +109 -0
  12. package/dist/content-N1gYshjg.mjs +1028 -0
  13. package/dist/descriptor-D9Th5hzk.d.mts +18 -0
  14. package/dist/diagnostics-Cu94mZhl.mjs +80 -0
  15. package/dist/dist-C7_FOzY_.mjs +5405 -0
  16. package/dist/errors-C2iuBM0G.mjs +72 -0
  17. package/dist/github-slugger-BMgR_Q0I.mjs +72 -0
  18. package/dist/glob-Bv0dpvCQ.mjs +159 -0
  19. package/dist/index.d.mts +78 -0
  20. package/dist/index.mjs +46 -0
  21. package/dist/internal/markdown.d.mts +5 -0
  22. package/dist/internal/markdown.mjs +1 -0
  23. package/dist/internal.d.mts +54 -0
  24. package/dist/internal.mjs +89 -0
  25. package/dist/loaders.d.mts +11 -0
  26. package/dist/loaders.mjs +86 -0
  27. package/dist/markdown-CHvBBJNa.mjs +54 -0
  28. package/dist/next.d.mts +20 -0
  29. package/dist/next.mjs +142 -0
  30. package/dist/operators-UqWUhKQJ.mjs +173 -0
  31. package/dist/query.d.mts +44 -0
  32. package/dist/query.mjs +1 -0
  33. package/dist/relational-types-DgK3rLuw.d.mts +278 -0
  34. package/dist/rolldown-runtime-Bg1v5YCA.mjs +34 -0
  35. package/dist/runtime.d.mts +3 -0
  36. package/dist/runtime.mjs +5 -0
  37. package/dist/schema-C5Str-E8.mjs +20 -0
  38. package/dist/schema.d.mts +11 -0
  39. package/dist/schema.mjs +1 -0
  40. package/dist/server-only-CIJUlyL-.mjs +7 -0
  41. package/dist/types-C-kdMblM.d.mts +69 -0
  42. package/dist/types-ChaNhj42.d.mts +143 -0
  43. package/dist/types-Dh-Sydyw.d.mts +20 -0
  44. package/dist/validation-D_XdE1pF.mjs +84 -0
  45. package/dist/values-BbTV4QT-.mjs +901 -0
  46. package/dist/vite.d.mts +6 -0
  47. package/dist/vite.mjs +296 -0
  48. package/package.json +92 -10
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yangshun Tay
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,92 @@
1
- Contact me via [GitHub](https://github.com/yangshun) / [LinkedIn](https://linkedin/in/yangshun) / [X](https://x.com/yangshun) if you're interested in this package name.
1
+ # ContentQuery
2
2
 
3
- In most cases I'm happy to just transfer it to you if you have a serious use.
3
+ Typed collections and queries for Markdown, JSON, YAML, and TOML. ContentQuery validates your content at build time and produces portable data your application can query and render on the server.
4
+
5
+ Use it with your existing framework. Your application owns its routes, layouts, and public URLs; production reads prepared content without loading the original source files.
6
+
7
+ ## Features
8
+
9
+ - **Typed schemas.** Validate metadata with bundled schema builders or any Standard Schema V1 provider, with inferred TypeScript types.
10
+ - **Flexible sources.** Load local files, use Astro-compatible content loaders, or write your own loader.
11
+ - **Queries and relationships.** Select fields, filter, sort, paginate, and load related entries with validated references.
12
+ - **Markdown rendering.** Request HTML, headings, and syntax highlighting as query payloads, loaded only when a query asks for them.
13
+ - **Framework integrations.** Use Vite, Next.js, or the standalone CLI, with content updates during development.
14
+
15
+ ## Usage
16
+
17
+ Requires Node.js 22.12 or later. Install ContentQuery:
18
+
19
+ ```sh
20
+ npm install content-query
21
+ ```
22
+
23
+ Define `content-query.config.ts`:
24
+
25
+ ```ts
26
+ import { defineCollection } from "content-query";
27
+ import { schema } from "content-query/schema";
28
+
29
+ export const collections = {
30
+ posts: defineCollection({
31
+ source: "./content/posts",
32
+ schema: schema.object({
33
+ title: schema.string(),
34
+ draft: schema.boolean().default(false),
35
+ }),
36
+ }),
37
+ };
38
+ ```
39
+
40
+ Add Markdown files with `title` frontmatter under `content/posts/`, then build:
41
+
42
+ ```sh
43
+ npx content-query build
44
+ ```
45
+
46
+ Query the generated module from server code:
47
+
48
+ ```ts
49
+ import { content } from "./.content-query/server.js";
50
+ import { eq } from "content-query/query";
51
+
52
+ const posts = await content
53
+ .select("id", "title")
54
+ .from("posts")
55
+ .where((fields) => eq(fields.draft, false))
56
+ .orderBy("title");
57
+
58
+ const post = await content.query.posts.findFirst({
59
+ where: { id: posts[0]!.id },
60
+ payloads: { _rendered: true },
61
+ });
62
+ const { html, headings } = post!._payloads._rendered;
63
+ ```
64
+
65
+ Add `.content-query/` to `.gitignore`. Follow the quick start for a complete walkthrough, or choose a framework example below.
66
+
67
+ ## Migrating to 0.2
68
+
69
+ Version 0.2.0 removes `content.readBody()` and `content.render()`. Request bodies and rendered output as payloads in the query that loads the entry:
70
+
71
+ | 0.1 | 0.2 |
72
+ | ------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
73
+ | `await content.readBody("posts", id)` | `(await content.query.posts.findFirst({ where: { id }, payloads: { _body: true } }))?._payloads._body` |
74
+ | `await content.render("posts", id)` | `(await content.query.posts.findFirst({ where: { id }, payloads: { _rendered: true } }))?._payloads._rendered` |
75
+ | Fluent queries | Add `.withPayload("_rendered")` or `.withPayload("_body")` before the terminal. |
76
+
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. Rebuild generated content after upgrading; 0.1 artifacts are rejected.
78
+
79
+ ## Documentation
80
+
81
+ - [Quick start](https://github.com/yangshun/content-query/blob/main/website/content/guides/quick-start.md)
82
+ - [Framework examples](https://github.com/yangshun/content-query/blob/main/examples/README.md)
83
+ - [API and usage](https://github.com/yangshun/content-query/blob/main/docs/API.md)
84
+ - [Guides and reference](https://github.com/yangshun/content-query/blob/main/docs/README.md)
85
+
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.
87
+
88
+ 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
+
90
+ 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
+
92
+ Released under the [MIT license](https://github.com/yangshun/content-query/blob/main/LICENSE).
@@ -0,0 +1,25 @@
1
+ import { i as CollectionRegistry } from "./types-C-kdMblM.mjs";
2
+ import { s as InvalidRelationships, t as Content } from "./content-G69dPPuo.mjs";
3
+ //#region src/preparation/session.d.ts
4
+ type ContentSession<Registry extends CollectionRegistry = {}> = {
5
+ content: Content<Registry>;
6
+ dispose(): Promise<void>;
7
+ };
8
+ //#endregion
9
+ //#region src/preparation/build.d.ts
10
+ /** Options shared by standalone content builds and host integrations. */
11
+ type BuildContentOptions = {
12
+ /** Exact config path; omission discovers one content-query.config.{ts,mts,cts,js,mjs,cjs} file. */
13
+ config?: string;
14
+ backend?: "in-memory" | "generated";
15
+ /** Generated backend output directory, relative to the application root; defaults to ./.content-query. */
16
+ outDir?: string;
17
+ watch?: boolean;
18
+ };
19
+ /**
20
+ * Builds content independently of a bundler; bind the registry through an erased type import.
21
+ * Generated watch sessions prune previous-run artifacts after their first successful publication.
22
+ */
23
+ declare function buildContent<Registry extends CollectionRegistry = {}>(...arguments_: InvalidRelationships<Registry> extends never ? [options?: BuildContentOptions] : [invalidRegistry: never]): Promise<ContentSession<Registry>>;
24
+ //#endregion
25
+ export { buildContent as n, ContentSession as r, BuildContentOptions as t };