@prunellejs/content 0.0.0-stage → 0.7.2

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/src/types.ts ADDED
@@ -0,0 +1,202 @@
1
+ // Shared public and internal types and symbol keys for @prunellejs/content.
2
+
3
+ import type { ContentImageResolver, ContentImageResult } from 'prunelle/config'
4
+ import type { StandardSchemaV1 } from 'prunelle/server'
5
+
6
+ export const COLLECTION_VALIDATE_KEY = Symbol.for('pru.content.validateAll')
7
+ export const COLLECTION_DIR_FOR_ROOT_KEY = Symbol.for('pru.content.dirForRoot')
8
+ export const COLLECTION_OWNER_ROOT_KEY = Symbol.for('pru.content.ownerRoot')
9
+ export const COLLECTION_META_KEY = Symbol.for('pru.content.meta')
10
+
11
+ export interface InternalCollectionMeta {
12
+ readonly name: string
13
+ readonly dir?: string | undefined
14
+ readonly localized: boolean
15
+ readonly defaultLocale: string
16
+ readonly locales?: readonly string[] | undefined
17
+ readonly schema?: StandardSchemaV1 | undefined
18
+ readonly isAsync: boolean
19
+ }
20
+
21
+ export interface ContentHeading {
22
+ level: number
23
+ id: string
24
+ text: string
25
+ }
26
+
27
+ export interface RenderedMarkdown {
28
+ readonly html: string
29
+ readonly headings: readonly ContentHeading[]
30
+ readonly wordCount: number
31
+ readonly readingMinutes: number
32
+ }
33
+
34
+ export interface ContentEntry<TData = Record<string, unknown>> {
35
+ readonly slug: string
36
+ readonly locale?: string | undefined
37
+ readonly file: string
38
+ readonly data: TData
39
+ readonly body: string
40
+ readonly html: string
41
+ readonly headings: readonly ContentHeading[]
42
+ readonly wordCount: number
43
+ readonly readingMinutes: number
44
+ /** Lazily resolves async collection renderers (`highlight`, `components`) and renders Markdown once. */
45
+ render(): Promise<RenderedMarkdown>
46
+ }
47
+
48
+ export type MarkdownComponent = (props: never) => unknown
49
+ export type CodeHighlighter = (code: string, language: string | undefined) => string
50
+ export type MarkdownImageResult = ContentImageResult
51
+ export type MarkdownImageResolver = ContentImageResolver
52
+
53
+ export interface CollectionRenderConfig {
54
+ /** Custom syntax highlighter for fenced code blocks (e.g. Shiki). */
55
+ highlight?: CodeHighlighter | undefined
56
+ /** Embedded Prunelle TSX components usable directly inside Markdown (`<Note>`, `<BarChart rows={[...]} />`). */
57
+ components?: Record<string, MarkdownComponent> | undefined
58
+ /** Wrap h2-h6 headings in self-referencing `<a href="#id">` links. */
59
+ headingLinks?: boolean | undefined
60
+ /** Optional image resolver (set to `false` to disable automatic `@prunellejs/images` optimization). */
61
+ resolveImage?: MarkdownImageResolver | false | undefined
62
+ /** Opt out of default Markdown HTML sanitization for fully trusted content (default: false). */
63
+ trusted?: boolean | undefined
64
+ }
65
+
66
+ export interface RenderMarkdownOptions {
67
+ highlight?: CodeHighlighter | undefined
68
+ components?: Record<string, MarkdownComponent> | undefined
69
+ /** Wrap h2-h6 headings in self-referencing `<a href="#id">` links. */
70
+ headingLinks?: boolean | undefined
71
+ /** Active locale passed into embedded components as `props.locale`. */
72
+ locale?: string | undefined
73
+ /** Optional image resolver for rewriting `<img src="...">` (defaults to auto-wired `@prunellejs/images` when active; `false` disables). */
74
+ resolveImage?: MarkdownImageResolver | false | undefined
75
+ /** Source file path passed to `resolveImage`. */
76
+ file?: string | undefined
77
+ /** Opt out of default Markdown HTML sanitization for fully trusted content (default: false). */
78
+ trusted?: boolean | undefined
79
+ }
80
+
81
+ export interface CollectionLoadContext {
82
+ /** Requested locale when `localized: true`; `undefined` otherwise. */
83
+ readonly locale?: string | undefined
84
+ /** Aborted after `timeoutMs` or when the collection's cache is cleared: pass it to `fetch()` or the database client. */
85
+ readonly signal: AbortSignal
86
+ }
87
+
88
+ export interface LoadedEntryInput {
89
+ /** Entry slug used for `.get(slug)` and `.paths(prefix)`. */
90
+ readonly slug: string
91
+ /** Raw entry metadata validated against `schema` when configured. */
92
+ readonly data: unknown
93
+ /** Optional Markdown body rendered through the standard content pipeline. */
94
+ readonly body?: string | undefined
95
+ /** Optional locale tag; when `localized: true`, entries with a non-matching locale are filtered out. */
96
+ readonly locale?: string | undefined
97
+ /** Optional upstream identifier (e.g. CMS record ID) surfaced as `entry.file`. */
98
+ readonly id?: string | undefined
99
+ }
100
+
101
+ export type CollectionLoader = (
102
+ ctx: CollectionLoadContext,
103
+ ) => LoadedEntryInput[] | Promise<LoadedEntryInput[]>
104
+
105
+ export interface BaseCollectionOptions<TData = Record<string, unknown>> {
106
+ /** Collection identifier for diagnostics, CMS, and search (defaults to `dir` basename or `'collection'`). */
107
+ name?: string | undefined
108
+ /** When true, queries are scoped by locale. */
109
+ localized?: boolean | undefined
110
+ /** Default locale when `localized: true` and no locale is passed (default: app defaultLocale or `'en'`). */
111
+ defaultLocale?: string | undefined
112
+ /** Known locales for localized collections (used by `prunelle check`, search, and CMS). */
113
+ locales?: readonly string[] | undefined
114
+ /** Optional Standard Schema (Zod, Valibot, ArkType, custom) to validate entry metadata. */
115
+ schema?: StandardSchemaV1<unknown, TData> | undefined
116
+ /** Custom syntax highlighter for fenced code blocks (e.g. Shiki). */
117
+ highlight?: CodeHighlighter | undefined
118
+ /** Embedded Prunelle TSX components usable directly inside Markdown (`<Note>`, `<BarChart rows={[...]} />`). */
119
+ components?: Record<string, MarkdownComponent> | undefined
120
+ /** Wrap h2-h6 headings in self-referencing `<a href="#id">` links. */
121
+ headingLinks?: boolean | undefined
122
+ /** Optional image resolver for rewriting Markdown images (defaults to auto-wired `@prunellejs/images`; `false` disables). */
123
+ resolveImage?: MarkdownImageResolver | false | undefined
124
+ /** Opt out of default Markdown HTML sanitization for fully trusted collections (default: false). */
125
+ trusted?: boolean | undefined
126
+ /** Lazy renderer loader (`async () => ({ highlight, components })`) so config/index/RSS never load Shiki or TSX components. */
127
+ render?: (() => CollectionRenderConfig | Promise<CollectionRenderConfig>) | undefined
128
+ /** Include entries with `draft: true` (default: `true` in dev, `false` in production/build). */
129
+ includeDrafts?: boolean | undefined
130
+ /** Custom comparator for `all()` (defaults to newest `date` first, then alphabetical `slug`). */
131
+ sort?: ((a: ContentEntry<TData>, b: ContentEntry<TData>) => number) | undefined
132
+ }
133
+
134
+ export interface CollectionOptions<TData = Record<string, unknown>> extends BaseCollectionOptions<TData> {
135
+ /** Directory containing `.md` / `.markdown` files (or `<locale>/*.md` when `localized: true`). */
136
+ dir: string
137
+ load?: undefined
138
+ }
139
+
140
+ export interface CollectionOptionsWithSchema<TData> extends Omit<CollectionOptions<TData>, 'schema'> {
141
+ /** Standard Schema (Zod, Valibot, ArkType, custom) validating frontmatter into `TData`. */
142
+ schema: StandardSchemaV1<unknown, TData>
143
+ }
144
+
145
+ export interface CollectionOptionsWithoutSchema extends Omit<CollectionOptions<Record<string, unknown>>, 'schema'> {
146
+ schema?: undefined
147
+ }
148
+
149
+ export interface LoaderCollectionOptions<TData = Record<string, unknown>> extends BaseCollectionOptions<TData> {
150
+ dir?: undefined
151
+ /** Async or sync loader returning entries from a headless CMS, database, or API. */
152
+ load: CollectionLoader
153
+ /** At runtime, how long every request reuses the entries of a finished load, per locale (default: 0, a load per request; `Infinity` keeps them until the cache is cleared). */
154
+ ttlMs?: number | undefined
155
+ /** How long a load may run before its signal aborts and the load fails (default: 30,000). */
156
+ timeoutMs?: number | undefined
157
+ }
158
+
159
+ export interface LoaderCollectionOptionsWithSchema<TData> extends Omit<LoaderCollectionOptions<TData>, 'schema'> {
160
+ /** Standard Schema (Zod, Valibot, ArkType, custom) validating loaded entry data into `TData`. */
161
+ schema: StandardSchemaV1<unknown, TData>
162
+ }
163
+
164
+ export interface LoaderCollectionOptionsWithoutSchema extends Omit<LoaderCollectionOptions<Record<string, unknown>>, 'schema'> {
165
+ schema?: undefined
166
+ }
167
+
168
+ export interface Collection<TData = Record<string, unknown>> {
169
+ readonly dir: string
170
+ readonly name: string
171
+ all(locale?: string): ContentEntry<TData>[]
172
+ get(slug: string, locale?: string): ContentEntry<TData> | undefined
173
+ byTag(tag: string, locale?: string): ContentEntry<TData>[]
174
+ /** Returns URL paths for `export const prerender = true; export const paths = () => col.paths('/blog')`. */
175
+ paths(prefix?: string, locale?: string): string[]
176
+ clearCache(): void
177
+ }
178
+
179
+ export interface AsyncCollection<TData = Record<string, unknown>> {
180
+ readonly dir?: undefined
181
+ readonly name: string
182
+ all(locale?: string): Promise<ContentEntry<TData>[]>
183
+ get(slug: string, locale?: string): Promise<ContentEntry<TData> | undefined>
184
+ byTag(tag: string, locale?: string): Promise<ContentEntry<TData>[]>
185
+ /** Returns URL paths for `export const prerender = true; export const paths = () => col.paths('/blog')`. */
186
+ paths(prefix?: string, locale?: string): Promise<string[]>
187
+ clearCache(): void
188
+ }
189
+
190
+ export type AnyCollection<TData = Record<string, unknown>> = Collection<TData> | AsyncCollection<TData>
191
+
192
+ export interface InternalCollection {
193
+ readonly dir?: string | undefined
194
+ readonly name?: string | undefined
195
+ all(locale?: string): ContentEntry<unknown>[] | Promise<ContentEntry<unknown>[]>
196
+ get(slug: string, locale?: string): ContentEntry<unknown> | undefined | Promise<ContentEntry<unknown> | undefined>
197
+ clearCache(): void
198
+ [COLLECTION_VALIDATE_KEY]?: (root: string) => string[] | Promise<string[]>
199
+ [COLLECTION_DIR_FOR_ROOT_KEY]?: (root?: string) => string | undefined
200
+ [COLLECTION_OWNER_ROOT_KEY]?: string | undefined
201
+ [COLLECTION_META_KEY]?: (root?: string) => InternalCollectionMeta
202
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.