@hamur/content 0.0.0-stage → 0.0.1
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/LICENSE +22 -0
- package/README.md +14 -2
- package/dist/chunks/bun-render-65mwzeq2.js +58 -0
- package/dist/chunks/bun-render-7jxnxg3v.js +714 -0
- package/dist/chunks/bun-render-mxhn5twt.js +130 -0
- package/dist/chunks/bun-render-w7fh3fg7.js +36 -0
- package/dist/src/adapters/html.js +134 -0
- package/dist/src/adapters/preact.js +126 -0
- package/dist/src/adapters/react.js +116 -0
- package/dist/src/adapters/solid.js +153 -0
- package/dist/src/adapters/svelte.js +90 -0
- package/dist/src/adapters/vue.js +166 -0
- package/dist/src/index.js +2732 -0
- package/dist/src/query.js +97 -0
- package/dist/src/render.js +12 -0
- package/dist/src/server/index.js +349 -0
- package/dist/types/src/adapters/html.d.ts +54 -0
- package/dist/types/src/adapters/page.d.ts +21 -0
- package/dist/types/src/adapters/preact.d.ts +53 -0
- package/dist/types/src/adapters/prose.d.ts +21 -0
- package/dist/types/src/adapters/react.d.ts +53 -0
- package/dist/types/src/adapters/search.d.ts +12 -0
- package/dist/types/src/adapters/solid.d.ts +54 -0
- package/dist/types/src/adapters/svelte-page.d.ts +9 -0
- package/dist/types/src/adapters/svelte-search.d.ts +9 -0
- package/dist/types/src/adapters/svelte.d.ts +24 -0
- package/dist/types/src/adapters/vue.d.ts +189 -0
- package/dist/types/src/build/api.d.ts +24 -0
- package/dist/types/src/build/dev-route.d.ts +4 -0
- package/dist/types/src/build/dev.d.ts +48 -0
- package/dist/types/src/build/graphql.d.ts +10 -0
- package/dist/types/src/build/image.d.ts +16 -0
- package/dist/types/src/build/index.d.ts +76 -0
- package/dist/types/src/build/live.d.ts +6 -0
- package/dist/types/src/build/prerender.d.ts +8 -0
- package/dist/types/src/build/query.d.ts +10 -0
- package/dist/types/src/build/raw.d.ts +23 -0
- package/dist/types/src/build/search.d.ts +9 -0
- package/dist/types/src/build/types.d.ts +16 -0
- package/dist/types/src/component.d.ts +10 -0
- package/dist/types/src/config.d.ts +6 -0
- package/dist/types/src/define.d.ts +14 -0
- package/dist/types/src/error.d.ts +4 -0
- package/dist/types/src/image.d.ts +15 -0
- package/dist/types/src/index.d.ts +64 -0
- package/dist/types/src/loaders/data.d.ts +12 -0
- package/dist/types/src/loaders/file.d.ts +3 -0
- package/dist/types/src/loaders/git.d.ts +27 -0
- package/dist/types/src/loaders/glob.d.ts +14 -0
- package/dist/types/src/module.d.ts +3 -0
- package/dist/types/src/query.d.ts +17 -0
- package/dist/types/src/render.d.ts +9 -0
- package/dist/types/src/runtime/client.d.ts +25 -0
- package/dist/types/src/runtime/dev-client.d.ts +4 -0
- package/dist/types/src/runtime/dev-plugin.d.ts +12 -0
- package/dist/types/src/runtime/dev-store.d.ts +5 -0
- package/dist/types/src/runtime/live.d.ts +36 -0
- package/dist/types/src/runtime/navigation.d.ts +35 -0
- package/dist/types/src/runtime/page-plugin.d.ts +2 -0
- package/dist/types/src/runtime/page-source.d.ts +12 -0
- package/dist/types/src/runtime/query.d.ts +100 -0
- package/dist/types/src/runtime/raw-path.d.ts +2 -0
- package/dist/types/src/runtime/refresh-body.d.ts +4 -0
- package/dist/types/src/runtime/search-loaders.d.ts +7 -0
- package/dist/types/src/runtime/search-plugin.d.ts +2 -0
- package/dist/types/src/runtime/search-store.d.ts +19 -0
- package/dist/types/src/runtime/search.d.ts +28 -0
- package/dist/types/src/runtime/sections.d.ts +36 -0
- package/dist/types/src/runtime/server-store.d.ts +4 -0
- package/dist/types/src/runtime/store.d.ts +31 -0
- package/dist/types/src/server/door-dev-static.d.ts +3 -0
- package/dist/types/src/server/door-dev.d.ts +4 -0
- package/dist/types/src/server/door-static.d.ts +2 -0
- package/dist/types/src/server/door.d.ts +3 -0
- package/dist/types/src/server/endpoint.d.ts +1 -0
- package/dist/types/src/server/graphql.d.ts +24 -0
- package/dist/types/src/server/index.d.ts +10 -0
- package/dist/types/src/server/install.d.ts +1 -0
- package/dist/types/src/server/live.d.ts +10 -0
- package/dist/types/src/server/query.d.ts +15 -0
- package/dist/types/src/server/refresh.d.ts +2 -0
- package/dist/types/src/server/rest.d.ts +62 -0
- package/dist/types/src/server/search.d.ts +5 -0
- package/dist/types/src/server-config.d.ts +12 -0
- package/dist/types/src/source.d.ts +24 -0
- package/dist/types/src/types.d.ts +293 -0
- package/package.json +110 -4
- package/src/adapters/ContentRenderer.svelte +27 -0
- package/src/adapters/ProseA.svelte +11 -0
- package/src/adapters/ProseBlockquote.svelte +7 -0
- package/src/adapters/ProseCode.svelte +7 -0
- package/src/adapters/ProseEm.svelte +7 -0
- package/src/adapters/ProseH1.svelte +7 -0
- package/src/adapters/ProseH2.svelte +7 -0
- package/src/adapters/ProseH3.svelte +7 -0
- package/src/adapters/ProseH4.svelte +7 -0
- package/src/adapters/ProseH5.svelte +7 -0
- package/src/adapters/ProseH6.svelte +7 -0
- package/src/adapters/ProseHr.svelte +5 -0
- package/src/adapters/ProseImg.svelte +5 -0
- package/src/adapters/ProseLi.svelte +7 -0
- package/src/adapters/ProseOl.svelte +7 -0
- package/src/adapters/ProseP.svelte +7 -0
- package/src/adapters/ProsePre.svelte +21 -0
- package/src/adapters/ProseStrong.svelte +7 -0
- package/src/adapters/ProseTable.svelte +7 -0
- package/src/adapters/ProseUl.svelte +7 -0
- package/src/adapters/html.ts +152 -0
- package/src/adapters/page.ts +52 -0
- package/src/adapters/preact.ts +154 -0
- package/src/adapters/prose.ts +55 -0
- package/src/adapters/react.ts +142 -0
- package/src/adapters/search.ts +32 -0
- package/src/adapters/solid.ts +183 -0
- package/src/adapters/svelte-defaults.ts +41 -0
- package/src/adapters/svelte-page.ts +29 -0
- package/src/adapters/svelte-search.ts +36 -0
- package/src/adapters/svelte.ts +30 -0
- package/src/adapters/test/OwnA.svelte +7 -0
- package/src/adapters/test/OwnH1.svelte +7 -0
- package/src/adapters/test/OwnPre.svelte +7 -0
- package/src/adapters/test/support.ts +106 -0
- package/src/adapters/vue.ts +182 -0
- package/src/build/api.ts +201 -0
- package/src/build/dev-route.ts +5 -0
- package/src/build/dev.ts +299 -0
- package/src/build/graphql.ts +197 -0
- package/src/build/image.ts +60 -0
- package/src/build/index.ts +597 -0
- package/src/build/live.ts +34 -0
- package/src/build/prerender.ts +34 -0
- package/src/build/query.ts +70 -0
- package/src/build/raw.ts +157 -0
- package/src/build/search.ts +64 -0
- package/src/build/types.ts +108 -0
- package/src/component.ts +86 -0
- package/src/config.ts +156 -0
- package/src/define.ts +33 -0
- package/src/env.d.ts +34 -0
- package/src/error.ts +4 -0
- package/src/image.ts +41 -0
- package/src/index.ts +103 -0
- package/src/loaders/data.ts +186 -0
- package/src/loaders/file.ts +53 -0
- package/src/loaders/git.ts +266 -0
- package/src/loaders/glob.ts +179 -0
- package/src/module.ts +26 -0
- package/src/query.ts +82 -0
- package/src/render.ts +16 -0
- package/src/runtime/client.ts +75 -0
- package/src/runtime/dev-client.ts +6 -0
- package/src/runtime/dev-plugin.ts +64 -0
- package/src/runtime/dev-store.ts +19 -0
- package/src/runtime/live.ts +331 -0
- package/src/runtime/navigation.ts +225 -0
- package/src/runtime/page-plugin.ts +13 -0
- package/src/runtime/page-source.ts +22 -0
- package/src/runtime/query.ts +605 -0
- package/src/runtime/raw-path.ts +2 -0
- package/src/runtime/refresh-body.ts +22 -0
- package/src/runtime/search-loaders.ts +14 -0
- package/src/runtime/search-plugin.ts +6 -0
- package/src/runtime/search-store.ts +73 -0
- package/src/runtime/search.ts +126 -0
- package/src/runtime/sections.ts +155 -0
- package/src/runtime/server-store.ts +12 -0
- package/src/runtime/store.ts +59 -0
- package/src/server/door-dev-static.ts +6 -0
- package/src/server/door-dev.ts +7 -0
- package/src/server/door-static.ts +4 -0
- package/src/server/door.ts +6 -0
- package/src/server/endpoint.ts +17 -0
- package/src/server/graphql.ts +59 -0
- package/src/server/index.ts +17 -0
- package/src/server/install.ts +6 -0
- package/src/server/live.ts +51 -0
- package/src/server/query.ts +46 -0
- package/src/server/refresh.ts +19 -0
- package/src/server/rest.ts +157 -0
- package/src/server/search.ts +22 -0
- package/src/server-config.ts +24 -0
- package/src/source.ts +99 -0
- package/src/types.ts +282 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "hamur/server";
|
|
2
|
+
/** What `image()` outputs: an `ImageMeta` of `hamur` without `animated`. */
|
|
3
|
+
export interface ContentImage {
|
|
4
|
+
src: string;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
format: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const IMAGE_SCOPE: unique symbol;
|
|
10
|
+
/** What the content build gives `image()` while it validates one entry; `undefined` for a message means the file is read. */
|
|
11
|
+
export interface ImageScope {
|
|
12
|
+
resolve(path: string): Promise<ContentImage | string>;
|
|
13
|
+
}
|
|
14
|
+
/** A relative path in frontmatter or data, resolved against the entry file, as `{ src, width, height, format }` of the emitted image. */
|
|
15
|
+
export declare function image(): StandardSchemaV1<unknown, ContentImage>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { ContentEntry, LiveCollectionDefinition, LiveCollectionItemOf } from "./types.ts";
|
|
2
|
+
export { default } from "./module.ts";
|
|
3
|
+
export { defineCollection, defineContentConfig, defineLiveCollection, defineTransformer } from "./define.ts";
|
|
4
|
+
export { fromComponent } from "./component.ts";
|
|
5
|
+
export { image } from "./image.ts";
|
|
6
|
+
export type { ContentImage } from "./image.ts";
|
|
7
|
+
export type { PropsSchemaOf } from "./component.ts";
|
|
8
|
+
export { file } from "./loaders/file.ts";
|
|
9
|
+
export { glob } from "./loaders/glob.ts";
|
|
10
|
+
export type { GlobOptions } from "./loaders/glob.ts";
|
|
11
|
+
export type { CacheHint, CollectionDefinition, CollectionItemOf, CollectionSource, ContentConfig, ContentEntry, ContentFile, ContentOptions, ContentLoader, LiveCollectionDefinition, LiveCollectionItemOf, LiveLoader, LiveLoaderEntry, LlmsOptions, DataEntry, DataFields, LoaderContext, LoaderEntry, PageEntry, PageFields, RemoteSourceOptions, Serialized, SourceOptions, Transformer, } from "./types.ts";
|
|
12
|
+
/** Typegen fills it, `HamurContentCollections[<collection>] = <item type>`; empty until the app has a `content.config.ts` typegen has read. */
|
|
13
|
+
export interface HamurContentCollections {
|
|
14
|
+
}
|
|
15
|
+
/** The collection names of `content.config.ts`, `string` while typegen has written none. */
|
|
16
|
+
export type CollectionName = keyof HamurContentCollections extends never ? string : keyof HamurContentCollections & string;
|
|
17
|
+
/** The item type of collection `N`; `ContentEntry` while typegen has written none. */
|
|
18
|
+
export type CollectionItem<N extends string> = N extends keyof HamurContentCollections ? HamurContentCollections[N] : ContentEntry;
|
|
19
|
+
/** The field names of collection `N`; `string` while typegen has written none or the schema has an open output. */
|
|
20
|
+
export type CollectionField<N extends string> = keyof CollectionItem<N> & string;
|
|
21
|
+
/** Typegen fills it, `HamurLiveCollections[<collection>] = <its defineLiveCollection(…)>`. */
|
|
22
|
+
export interface HamurLiveCollections {
|
|
23
|
+
}
|
|
24
|
+
/** The live collection names of `content.config.ts`, `string` while typegen has written none. */
|
|
25
|
+
export type LiveCollectionName = keyof HamurLiveCollections extends never ? string : keyof HamurLiveCollections & string;
|
|
26
|
+
type LiveDefinitionOf<N extends string> = N extends keyof HamurLiveCollections ? HamurLiveCollections[N] : LiveCollectionDefinition;
|
|
27
|
+
/** The `data` type of live collection `N`'s entries; `Record<string, unknown>` while typegen has written none. */
|
|
28
|
+
export type LiveCollectionItem<N extends string> = N extends keyof HamurLiveCollections ? LiveCollectionItemOf<HamurLiveCollections[N]> : Record<string, unknown>;
|
|
29
|
+
/** The filter `getLiveCollection(N, filter)` passes to `loadCollection`. */
|
|
30
|
+
export type LiveCollectionFilter<N extends string> = LiveDefinitionOf<N> extends {
|
|
31
|
+
loader: {
|
|
32
|
+
loadCollection(filter: infer F): unknown;
|
|
33
|
+
};
|
|
34
|
+
} ? F : unknown;
|
|
35
|
+
/** The filter `getLiveEntry(N, filter)` passes to `loadEntry`. */
|
|
36
|
+
export type LiveEntryFilter<N extends string> = LiveDefinitionOf<N> extends {
|
|
37
|
+
loader: {
|
|
38
|
+
loadEntry(filter: infer F): unknown;
|
|
39
|
+
};
|
|
40
|
+
} ? F : unknown;
|
|
41
|
+
declare module "hamur" {
|
|
42
|
+
interface HamurModuleOptions {
|
|
43
|
+
content?: import("./types.ts").ContentOptions;
|
|
44
|
+
}
|
|
45
|
+
/** What `hamur dev` sends a page when a content file is saved. */
|
|
46
|
+
interface HamurDevEvents {
|
|
47
|
+
"content:update": import("./build/dev.ts").ContentUpdate;
|
|
48
|
+
"content:error": import("./build/dev.ts").ContentFailure;
|
|
49
|
+
"content:fixed": import("./build/dev.ts").ContentFixed;
|
|
50
|
+
}
|
|
51
|
+
interface HamurHooks {
|
|
52
|
+
/** Before a file is parsed; assign `file.body` to change what the parser reads. */
|
|
53
|
+
"content:file:beforeParse": (context: {
|
|
54
|
+
file: import("./types.ts").ContentFile;
|
|
55
|
+
collection: string;
|
|
56
|
+
}) => void | Promise<void>;
|
|
57
|
+
/** After the schema and the transformers; change `entry` in place. */
|
|
58
|
+
"content:file:afterParse": (context: {
|
|
59
|
+
file: import("./types.ts").ContentFile;
|
|
60
|
+
entry: import("./types.ts").ContentEntry;
|
|
61
|
+
collection: string;
|
|
62
|
+
}) => void | Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface CsvOptions {
|
|
2
|
+
delimiter: string;
|
|
3
|
+
header: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare const DEFAULT_CSV: CsvOptions;
|
|
6
|
+
export declare const DATA_FORMATS: readonly ["yml", "yaml", "json", "json5", "toml", "csv"];
|
|
7
|
+
/** `content.csv`, merged over the defaults. */
|
|
8
|
+
export declare function resolveCsv(value: unknown): CsvOptions;
|
|
9
|
+
/** One object per record, keyed by the header row, or by `"0"`, `"1"`, … without one. */
|
|
10
|
+
export declare function parseCsv(text: string, options: CsvOptions, shown: string): Array<Record<string, string>>;
|
|
11
|
+
/** The value of one data file; an error is `<file>:<line>:<column>: <message>`. */
|
|
12
|
+
export declare function parseDataText(text: string, extension: string, shown: string, csv?: CsvOptions): unknown;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ContentLoader } from "../types.ts";
|
|
2
|
+
/** One data file (yml, yaml, json, json5, toml or csv) below `<rootDir>/content`: an array (an item's `id` field, else its index, is its id) or an object (one entry per key). */
|
|
3
|
+
export declare function file(path: string): ContentLoader;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Logger } from "hamur/server";
|
|
2
|
+
import type { RemoteSourceOptions } from "../types.ts";
|
|
3
|
+
export declare const MAX_ARCHIVE_BYTES: number;
|
|
4
|
+
export declare const MAX_UNPACKED_BYTES: number;
|
|
5
|
+
export interface Repository {
|
|
6
|
+
host: "github" | "gitlab";
|
|
7
|
+
/** `org/docs`, or `group/sub/docs` on GitLab. */
|
|
8
|
+
path: string;
|
|
9
|
+
}
|
|
10
|
+
export interface FetchRepositoryOptions {
|
|
11
|
+
cacheDir: string;
|
|
12
|
+
logger?: Logger;
|
|
13
|
+
maxBytes?: number;
|
|
14
|
+
maxUnpackedBytes?: number;
|
|
15
|
+
}
|
|
16
|
+
/** An `https:` URL of a github.com or gitlab.com repository. */
|
|
17
|
+
export declare function parseRepository(repository: string): Repository;
|
|
18
|
+
/** The tarball URL and its headers; the token only ever goes in a header. */
|
|
19
|
+
export declare function archiveRequest(repository: Repository, ref: {
|
|
20
|
+
kind: "branch" | "tag";
|
|
21
|
+
name: string;
|
|
22
|
+
} | undefined, token: string | undefined): {
|
|
23
|
+
url: string;
|
|
24
|
+
headers: Record<string, string>;
|
|
25
|
+
};
|
|
26
|
+
/** Downloads the repository's tarball below `<cacheDir>/content/<sha256 of repository + ref>` and returns the unpacked copy; a failed fetch falls back to the last copy. */
|
|
27
|
+
export declare function fetchRepository(source: RemoteSourceOptions, { cacheDir, logger, maxBytes, maxUnpackedBytes }: FetchRepositoryOptions): Promise<string>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CollectionSource, ContentLoader } from "../types.ts";
|
|
2
|
+
/** What a `source` desugars to; sources of one collection share a file list, so a file matched twice is read once. */
|
|
3
|
+
export declare function sourceLoader(source: CollectionSource, cacheDir?: string): ContentLoader;
|
|
4
|
+
export interface GlobOptions {
|
|
5
|
+
/** A glob relative to `base`. */
|
|
6
|
+
pattern: string;
|
|
7
|
+
/** A directory relative to `<rootDir>/content`; default that directory. */
|
|
8
|
+
base?: string;
|
|
9
|
+
exclude?: string[];
|
|
10
|
+
/** The path prefix of a page collection; default `/`. */
|
|
11
|
+
prefix?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Reads `.md`, `.yml`, `.yaml`, `.json`, `.json5`, `.toml` and `.csv` files matching `pattern` below `base`. */
|
|
14
|
+
export declare function glob({ pattern, base, exclude, prefix }: GlobOptions): ContentLoader;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { findPageBreadcrumb, findPageChildren, findPageHeadline, findPageSiblings, type NavigationItem, type SurroundingsOptions } from "./runtime/navigation.ts";
|
|
2
|
+
import { type CollectionQueryBuilder } from "./runtime/query.ts";
|
|
3
|
+
import { type HeadingTag, type SearchSection, type SearchSectionsOptions } from "./runtime/sections.ts";
|
|
4
|
+
import type { CollectionField, CollectionItem, CollectionName } from "./index.ts";
|
|
5
|
+
import type { ContentEntry } from "./types.ts";
|
|
6
|
+
export { findPageBreadcrumb, findPageChildren, findPageHeadline, findPageSiblings };
|
|
7
|
+
export type { HeadingTag, NavigationItem, SearchSection, SearchSectionsOptions, SurroundingsOptions };
|
|
8
|
+
export type { CollectionQuery, CollectionQueryBuilder, FieldHead, FieldPath, QueryClause, QueryCondition, QueryDirection, QueryGroup, QueryGroupBuilder, QueryOperator, QueryResult, } from "./runtime/query.ts";
|
|
9
|
+
/** On the server the store in process, in the browser `content.clientQuery`'s way. */
|
|
10
|
+
export declare function queryCollection<N extends CollectionName>(name: N): CollectionQueryBuilder<CollectionItem<N>, never, CollectionField<N>>;
|
|
11
|
+
export declare function queryCollection<T = ContentEntry>(name: CollectionName): CollectionQueryBuilder<T>;
|
|
12
|
+
/** The tree of a page collection by directory. */
|
|
13
|
+
export declare function queryCollectionNavigation(name: CollectionName, extraFields?: string[]): Promise<NavigationItem[]>;
|
|
14
|
+
/** The entries before and after `path` in the collection's order, `null` where there is none. */
|
|
15
|
+
export declare function queryCollectionItemSurroundings<N extends CollectionName, F extends string = never>(name: N, path: string, options?: SurroundingsOptions<F>): Promise<(import("./query.ts").QueryResult<CollectionItem<N>, "path" | F> | null)[]>;
|
|
16
|
+
/** Every page of the collection split at its headings, from the server or the browser. */
|
|
17
|
+
export declare function queryCollectionSearchSections(name: CollectionName, options?: SearchSectionsOptions): Promise<SearchSection[]>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type MdHeading, type MdRoot } from "hamur/markdown";
|
|
2
|
+
import type { ContentEntry } from "./types.ts";
|
|
3
|
+
export interface RenderedEntry {
|
|
4
|
+
html: string;
|
|
5
|
+
headings: MdHeading[];
|
|
6
|
+
ast: MdRoot;
|
|
7
|
+
}
|
|
8
|
+
/** Plain ESM over `renderMarkdownAst`, so it runs on every preset and in the browser. */
|
|
9
|
+
export declare function renderEntry(entry: ContentEntry): Promise<RenderedEntry>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ContentEntry } from "../types.ts";
|
|
2
|
+
import { type CollectionQuery, type CollectionQueryBuilder, type QueriedCollection } from "./query.ts";
|
|
3
|
+
export declare const QUERY_PATH = "/_hamur/content/query";
|
|
4
|
+
/** One collection as `#hamur/content/client` lists it; `load` only for an exposed collection under `"local"`. */
|
|
5
|
+
export interface ClientCollection extends QueriedCollection {
|
|
6
|
+
expose: boolean;
|
|
7
|
+
load?: () => Promise<{
|
|
8
|
+
default: ContentEntry[];
|
|
9
|
+
}>;
|
|
10
|
+
}
|
|
11
|
+
export interface ClientQueryConfig {
|
|
12
|
+
mode: "api" | "local";
|
|
13
|
+
/** `app.baseURL`, present when `content.raw` is on. */
|
|
14
|
+
raw?: string;
|
|
15
|
+
collections: Record<string, ClientCollection>;
|
|
16
|
+
}
|
|
17
|
+
/** `POST <baseURL>_hamur/content/query`; a 400 is the engine's refusal. */
|
|
18
|
+
export declare function postQuery(body: {
|
|
19
|
+
collection: string;
|
|
20
|
+
query: CollectionQuery;
|
|
21
|
+
}): Promise<unknown>;
|
|
22
|
+
/** `hamur dev`: drops the fetched chunk of `name`, so the next local query fetches it again. */
|
|
23
|
+
export declare function forgetChunk(name: string): void;
|
|
24
|
+
/** `queryCollection` in the browser, over the endpoint or the collection's chunk fetched once. */
|
|
25
|
+
export declare function createClientQuery(config: ClientQueryConfig, post?: typeof postQuery): <T = ContentEntry>(name: string) => CollectionQueryBuilder<T>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { refreshData, type AppContext } from "hamur/app";
|
|
2
|
+
/** An async-data key holds a collection when the name is one of its words: `blog`, `blog:/hello`, `blog-post`. */
|
|
3
|
+
export declare const holdsCollection: (key: string, name: string) => boolean;
|
|
4
|
+
/** Re-runs the loads that queried one of `names` (each records `content:<name>`), and refreshes the mounted async-data entries whose key holds one, as `router.refresh()` does for each. */
|
|
5
|
+
export declare function refreshCollections(app: AppContext, names: readonly string[], refresh?: typeof refreshData): void;
|
|
6
|
+
/**
|
|
7
|
+
* `hamur dev`: `content:update` drops the collection's chunk and search index and refreshes its loads and
|
|
8
|
+
* async data; `content:error` opens the overlay, and `content:fixed` of a file the page showed reloads it. The errors
|
|
9
|
+
* still standing are read once at start, so a reload with a file still broken shows the overlay again.
|
|
10
|
+
*/
|
|
11
|
+
declare const _default: import("hamur/app").AppPlugin<{}>;
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { MdRoot } from "hamur/markdown";
|
|
2
|
+
import type { CacheHint, LiveCollectionDefinition, LiveCollectionResult, LiveEntryResult } from "../types.ts";
|
|
3
|
+
/** The part of a `useStorage` mount live results are kept in. */
|
|
4
|
+
export interface LiveStorage {
|
|
5
|
+
getItem(key: string): Promise<unknown>;
|
|
6
|
+
setItem(key: string, value: unknown, options?: {
|
|
7
|
+
ttl?: number;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
removeItem(key: string): Promise<void>;
|
|
10
|
+
clear(prefix: string): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export interface LiveContentOptions {
|
|
13
|
+
/** The live collections of `content.config.ts`. */
|
|
14
|
+
collections: Record<string, LiveCollectionDefinition>;
|
|
15
|
+
/** Every collection name of `content.config.ts`, live or not. */
|
|
16
|
+
names: readonly string[];
|
|
17
|
+
storage(): LiveStorage;
|
|
18
|
+
/** Parses a Markdown body; absent where `Bun.markdown` is not. */
|
|
19
|
+
parseMarkdown?: (source: string) => Promise<MdRoot>;
|
|
20
|
+
/** Told once per process when the cache cannot be read or written; the result is then loaded, or not kept. */
|
|
21
|
+
warn?: (message: string) => void;
|
|
22
|
+
}
|
|
23
|
+
export interface LiveContent {
|
|
24
|
+
getLiveCollection(name: string, filter?: unknown): Promise<LiveCollectionResult>;
|
|
25
|
+
getLiveEntry(name: string, filter: unknown): Promise<LiveEntryResult>;
|
|
26
|
+
refreshContent(options?: {
|
|
27
|
+
collections?: string[];
|
|
28
|
+
}): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export declare const liveKeyPrefix: (collection: string) => string;
|
|
31
|
+
/** `content:live:<collection>:<hash of the call and its filter>`; an `undefined` filter is no filter. */
|
|
32
|
+
export declare function liveKey(collection: string, kind: "collection" | "entry", filter: unknown): Promise<string>;
|
|
33
|
+
/** The tags of every hint, the shortest `maxAge` and the latest `lastModified`. */
|
|
34
|
+
export declare function mergeHints(hints: readonly (CacheHint | undefined)[]): CacheHint;
|
|
35
|
+
/** The live collections' request-time reads and their cache. */
|
|
36
|
+
export declare function createLiveContent({ collections, names, storage, parseMarkdown, warn, }: LiveContentOptions): LiveContent;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type CollectionQueryBuilder, type QueryResult } from "./query.ts";
|
|
2
|
+
import type { ContentEntry } from "../types.ts";
|
|
3
|
+
/** One node of the tree `queryCollectionNavigation` returns. */
|
|
4
|
+
export interface NavigationItem {
|
|
5
|
+
title: string;
|
|
6
|
+
path: string;
|
|
7
|
+
stem: string;
|
|
8
|
+
icon?: string;
|
|
9
|
+
children?: NavigationItem[];
|
|
10
|
+
[field: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
type Row = Record<string, unknown>;
|
|
13
|
+
/** The tree of a page collection's rows `{ stem, path, title, navigation, navigationDirs, ...extra }`. */
|
|
14
|
+
export declare function buildNavigation(rows: readonly Row[], fields?: readonly string[]): NavigationItem[];
|
|
15
|
+
/** What `queryCollectionNavigation` runs: one `select` query, then the tree. */
|
|
16
|
+
export declare function navigationOf(query: () => CollectionQueryBuilder, extraFields?: readonly string[]): Promise<NavigationItem[]>;
|
|
17
|
+
export interface SurroundingsOptions<F extends string = never> {
|
|
18
|
+
/** How many entries before the path; default 1. */
|
|
19
|
+
before?: number;
|
|
20
|
+
/** How many entries after the path; default 1. */
|
|
21
|
+
after?: number;
|
|
22
|
+
/** Fields returned next to `id` and `path`. */
|
|
23
|
+
fields?: F[];
|
|
24
|
+
}
|
|
25
|
+
/** `[...previous, ...next]` around `path` in the collection's order, `null` where there is none. */
|
|
26
|
+
export declare function surroundingsOf<T = ContentEntry, F extends string = never>(query: () => CollectionQueryBuilder<T>, path: string, options?: SurroundingsOptions<F>): Promise<Array<QueryResult<T, "path" | F> | null>>;
|
|
27
|
+
/** The title of the parent of the item at `path`; `undefined` at the top level or for an unknown path. */
|
|
28
|
+
export declare function findPageHeadline(tree: readonly NavigationItem[], path: string): string | undefined;
|
|
29
|
+
/** The items from the top level down to the one at `path`, each without its `children`; empty for an unknown path. */
|
|
30
|
+
export declare function findPageBreadcrumb(tree: readonly NavigationItem[], path: string): NavigationItem[];
|
|
31
|
+
/** The children of the item at `path`; empty for a leaf or an unknown path. */
|
|
32
|
+
export declare function findPageChildren(tree: readonly NavigationItem[], path: string): NavigationItem[];
|
|
33
|
+
/** The items beside the one at `path`, itself left out; empty for an unknown path. */
|
|
34
|
+
export declare function findPageSiblings(tree: readonly NavigationItem[], path: string): NavigationItem[];
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CollectionQueryBuilder } from "./query.ts";
|
|
2
|
+
import type { PageEntry } from "../types.ts";
|
|
3
|
+
export interface PageSource {
|
|
4
|
+
/** `queryCollection`, handed over so the adapters import no `#hamur/content/*` module an app without the content module lacks. */
|
|
5
|
+
query(name: string): CollectionQueryBuilder<PageEntry>;
|
|
6
|
+
/** The type of each collection of `content.config.ts`. */
|
|
7
|
+
types: Record<string, "page" | "data">;
|
|
8
|
+
/** `app.baseURL` when `content.raw` is on: the pages then have a Markdown copy at `<path>.md`. */
|
|
9
|
+
rawBase?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function setPageSource(source: PageSource): void;
|
|
12
|
+
export declare function pageSource(): PageSource;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { CollectionDefinition, ContentEntry } from "../types.ts";
|
|
2
|
+
import type { ContentStore } from "./store.ts";
|
|
3
|
+
export type QueryOperator = "=" | "<>" | ">" | ">=" | "<" | "<=" | "IN" | "NOT IN" | "BETWEEN" | "NOT BETWEEN" | "IS NULL" | "IS NOT NULL" | "LIKE" | "NOT LIKE";
|
|
4
|
+
/** One comparison of a query: `field` is a name or a dotted path into an object (`author.name`). */
|
|
5
|
+
export interface QueryCondition {
|
|
6
|
+
field: string;
|
|
7
|
+
operator: QueryOperator;
|
|
8
|
+
value?: unknown;
|
|
9
|
+
}
|
|
10
|
+
/** A parenthesised list of clauses, built by a callback. */
|
|
11
|
+
export interface QueryGroup {
|
|
12
|
+
where: QueryClause[];
|
|
13
|
+
}
|
|
14
|
+
/** A condition or a group, joined to the clauses before it, left to right. */
|
|
15
|
+
export type QueryClause = {
|
|
16
|
+
join: "AND" | "OR";
|
|
17
|
+
} & (QueryCondition | QueryGroup);
|
|
18
|
+
export type QueryDirection = "ASC" | "DESC";
|
|
19
|
+
/** The JSON description of the builder's calls that `"api"` posts and every engine runs. */
|
|
20
|
+
export interface CollectionQuery {
|
|
21
|
+
where?: QueryClause[];
|
|
22
|
+
select?: string[];
|
|
23
|
+
order?: Array<[field: string, direction: QueryDirection]>;
|
|
24
|
+
limit?: number;
|
|
25
|
+
skip?: number;
|
|
26
|
+
/** Answers the number of matching entries; `select`, `order`, `skip` and `limit` do not apply. */
|
|
27
|
+
count?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** A query the engine refuses; the message is the endpoint's 400 text, and the builder puts `queryCollection: ` before it. */
|
|
30
|
+
export declare class QueryError extends Error {
|
|
31
|
+
}
|
|
32
|
+
export declare const QUERY_LIMITS: {
|
|
33
|
+
readonly conditions: 100;
|
|
34
|
+
readonly depth: 8;
|
|
35
|
+
readonly values: 1000;
|
|
36
|
+
readonly select: 100;
|
|
37
|
+
readonly order: 10;
|
|
38
|
+
readonly field: 200;
|
|
39
|
+
readonly pattern: 200;
|
|
40
|
+
};
|
|
41
|
+
/** Checks an operator and its value as the query operators type them. */
|
|
42
|
+
export declare function checkCondition(field: unknown, operator: unknown, value: unknown): void;
|
|
43
|
+
/** The names a query may start a field with: the collection's built fields and every key an entry has. */
|
|
44
|
+
export declare function fieldsOf(type: CollectionDefinition["type"], entries: readonly ContentEntry[]): Set<string>;
|
|
45
|
+
/** The strict check of a query object, so a client cannot make an engine do unbounded work. */
|
|
46
|
+
export declare function checkQuery(value: unknown, fields: ReadonlySet<string>, collection: string): CollectionQuery;
|
|
47
|
+
export interface QueriedCollection {
|
|
48
|
+
type: CollectionDefinition["type"];
|
|
49
|
+
order?: CollectionDefinition["order"];
|
|
50
|
+
}
|
|
51
|
+
/** The engine, over one collection's entries in source order. */
|
|
52
|
+
export declare function runQuery(name: string, collection: QueriedCollection, entries: readonly ContentEntry[], value: unknown): ContentEntry[] | Record<string, unknown>[] | number;
|
|
53
|
+
/** The server's run of a query: any collection, exposed or not. */
|
|
54
|
+
export declare function queryStore(store: ContentStore, name: string, query: unknown): Promise<unknown>;
|
|
55
|
+
/** What `POST /_hamur/content/query` answers for its body `{ collection, query }`. */
|
|
56
|
+
export declare function answerQuery(store: ContentStore, body: unknown): Promise<unknown>;
|
|
57
|
+
/** A field name of a collection or a dotted path that starts with one; `string` while no collection is typed. */
|
|
58
|
+
export type FieldPath<K extends string = string> = K | `${K}.${string}`;
|
|
59
|
+
type Where<K extends string> = {
|
|
60
|
+
(field: FieldPath<K>, operator: QueryOperator, value?: unknown): QueryGroupBuilder<K>;
|
|
61
|
+
(group: (query: QueryGroupBuilder<K>) => unknown): QueryGroupBuilder<K>;
|
|
62
|
+
};
|
|
63
|
+
/** `where`, `andWhere` and `orWhere` combine left to right (`where` is `andWhere`); a callback builds a group. */
|
|
64
|
+
export interface QueryGroupBuilder<K extends string = string> {
|
|
65
|
+
where: Where<K>;
|
|
66
|
+
andWhere: Where<K>;
|
|
67
|
+
orWhere: Where<K>;
|
|
68
|
+
}
|
|
69
|
+
type Chained<B, K extends string> = {
|
|
70
|
+
(field: FieldPath<K>, operator: QueryOperator, value?: unknown): B;
|
|
71
|
+
(group: (query: QueryGroupBuilder<K>) => unknown): B;
|
|
72
|
+
};
|
|
73
|
+
/** The top-level key a field path writes: `"author"` for `"author.name"`. */
|
|
74
|
+
export type FieldHead<F extends string> = F extends `${infer Head}.${string}` ? Head : F;
|
|
75
|
+
/** What a query returns: the entry, or after `select` its `id` and the selected top-level keys. */
|
|
76
|
+
export type QueryResult<T, S extends string> = [S] extends [never] ? T : {
|
|
77
|
+
id: string;
|
|
78
|
+
} & {
|
|
79
|
+
[K in Exclude<S, "id">]: K extends keyof T ? T[K] : unknown;
|
|
80
|
+
};
|
|
81
|
+
/** The builder `queryCollection` returns; `S` collects the top-level keys `select` named, `K` is the field names `where`, `order` and `select` take (dotted paths are typed by their first segment). */
|
|
82
|
+
export interface CollectionQueryBuilder<T = ContentEntry, S extends string = never, K extends string = string> {
|
|
83
|
+
where: Chained<CollectionQueryBuilder<T, S, K>, K>;
|
|
84
|
+
andWhere: Chained<CollectionQueryBuilder<T, S, K>, K>;
|
|
85
|
+
orWhere: Chained<CollectionQueryBuilder<T, S, K>, K>;
|
|
86
|
+
/** `where("path", "=", path)`. */
|
|
87
|
+
path(path: string): CollectionQueryBuilder<T, S, K>;
|
|
88
|
+
/** Limits the returned fields; `id` is always returned. Calls add up. */
|
|
89
|
+
select<F extends FieldPath<K>>(...fields: F[]): CollectionQueryBuilder<T, S | FieldHead<F>, K>;
|
|
90
|
+
/** Stacks: the first call sorts first. Without one, the collection's `order`, else source order. */
|
|
91
|
+
order(field: FieldPath<K>, direction: QueryDirection): CollectionQueryBuilder<T, S, K>;
|
|
92
|
+
limit(limit: number): CollectionQueryBuilder<T, S, K>;
|
|
93
|
+
skip(skip: number): CollectionQueryBuilder<T, S, K>;
|
|
94
|
+
all(): Promise<QueryResult<T, S>[]>;
|
|
95
|
+
first(): Promise<QueryResult<T, S> | undefined>;
|
|
96
|
+
count(): Promise<number>;
|
|
97
|
+
}
|
|
98
|
+
/** The builder over `run`, which takes the checked-later query object and answers what the engine answers. */
|
|
99
|
+
export declare function createQuery<T = ContentEntry, K extends string = string>(run: (query: CollectionQuery) => Promise<unknown>): CollectionQueryBuilder<T, never, K>;
|
|
100
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SearchIndex } from "./search.ts";
|
|
2
|
+
export type SearchLoaders = Record<string, () => Promise<{
|
|
3
|
+
default: SearchIndex;
|
|
4
|
+
}>>;
|
|
5
|
+
/** The client plugin hands over `#hamur/content/search`, so the adapters need no virtual module an app without the content module lacks. */
|
|
6
|
+
export declare function setSearchLoaders(loaders: SearchLoaders): void;
|
|
7
|
+
export declare function searchLoaders(): SearchLoaders;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type SearchHit, type SearchIndex } from "./search.ts";
|
|
2
|
+
export type SearchStatus = "idle" | "loading" | "ready" | "error";
|
|
3
|
+
export interface SearchOptions {
|
|
4
|
+
/** The most hits returned; default `20`. */
|
|
5
|
+
limit?: number;
|
|
6
|
+
}
|
|
7
|
+
/** One collection's search index in the browser: loaded once, shared by every caller. */
|
|
8
|
+
export interface SearchCollection {
|
|
9
|
+
readonly status: SearchStatus;
|
|
10
|
+
subscribe(listener: () => void): () => void;
|
|
11
|
+
/** Loads the index; a load in flight is shared, a loaded index answers at once, a failed load is tried again. */
|
|
12
|
+
init(): Promise<void>;
|
|
13
|
+
search(query: string, options?: SearchOptions): Promise<SearchHit[]>;
|
|
14
|
+
/** `hamur dev`: an index loaded or loading is loaded again; an idle one stays idle. */
|
|
15
|
+
reset(): void;
|
|
16
|
+
}
|
|
17
|
+
export declare function createSearchCollection(load: () => Promise<{
|
|
18
|
+
default: SearchIndex;
|
|
19
|
+
}>): SearchCollection;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { SearchSection } from "./sections.ts";
|
|
2
|
+
/** An inverted index as JSON; `postings[i]` is `[section, title count, body count, …]` for `terms[i]`. */
|
|
3
|
+
export interface SearchIndex {
|
|
4
|
+
version: 1;
|
|
5
|
+
sections: Array<Pick<SearchSection, "id" | "title" | "titles" | "level">>;
|
|
6
|
+
/** Token count of each section's title and of its content. */
|
|
7
|
+
titleLengths: number[];
|
|
8
|
+
bodyLengths: number[];
|
|
9
|
+
avgTitleLength: number;
|
|
10
|
+
avgBodyLength: number;
|
|
11
|
+
/** Folded terms in code-unit order. */
|
|
12
|
+
terms: string[];
|
|
13
|
+
postings: number[][];
|
|
14
|
+
}
|
|
15
|
+
export interface SearchHit {
|
|
16
|
+
id: string;
|
|
17
|
+
title: string;
|
|
18
|
+
titles: string[];
|
|
19
|
+
level: number;
|
|
20
|
+
score: number;
|
|
21
|
+
}
|
|
22
|
+
/** Lower case, then `normalize("NFD")` with the combining marks removed. */
|
|
23
|
+
export declare const fold: (text: string) => string;
|
|
24
|
+
export declare const tokenize: (text: string) => string[];
|
|
25
|
+
/** The index of `sections`, each term counted apart in its title and its content. */
|
|
26
|
+
export declare function buildSearchIndex(sections: readonly SearchSection[]): SearchIndex;
|
|
27
|
+
/** BM25 over the terms of `query`; the last term also matches by prefix, all its matches counting as one term. Hits are new objects, best first, ties in section order. */
|
|
28
|
+
export declare function searchIndex(index: SearchIndex, query: string, limit: number): SearchHit[];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type CollectionQueryBuilder } from "./query.ts";
|
|
2
|
+
export type HeadingTag = "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
|
|
3
|
+
/** The split of `queryCollectionSearchSections`. */
|
|
4
|
+
export interface SearchSectionsOptions {
|
|
5
|
+
/** Tags whose text is left out of `content`, `pre` and `code` for example; default none. */
|
|
6
|
+
ignoredTags?: string[];
|
|
7
|
+
/** The shallowest heading that starts a section; default `"h1"`. */
|
|
8
|
+
minHeading?: HeadingTag;
|
|
9
|
+
/** The deepest heading that starts a section; default `"h6"`. */
|
|
10
|
+
maxHeading?: HeadingTag;
|
|
11
|
+
}
|
|
12
|
+
export interface SearchSection {
|
|
13
|
+
/** `<path>#<heading id>`, or the page's `path` for the text before its first section heading. */
|
|
14
|
+
id: string;
|
|
15
|
+
title: string;
|
|
16
|
+
/** The titles of the headings above this section, outermost first. */
|
|
17
|
+
titles: string[];
|
|
18
|
+
content: string;
|
|
19
|
+
/** The heading's depth, 1 for the text before the first heading. */
|
|
20
|
+
level: number;
|
|
21
|
+
}
|
|
22
|
+
export interface ResolvedSectionOptions {
|
|
23
|
+
ignored: ReadonlySet<string>;
|
|
24
|
+
min: number;
|
|
25
|
+
max: number;
|
|
26
|
+
}
|
|
27
|
+
export declare function resolveSectionOptions(options?: SearchSectionsOptions): ResolvedSectionOptions;
|
|
28
|
+
export interface SectionedPage {
|
|
29
|
+
path: string;
|
|
30
|
+
title?: string | undefined;
|
|
31
|
+
body: readonly unknown[];
|
|
32
|
+
}
|
|
33
|
+
/** Splits one page at the headings in `[min, max]`; the text before the first one is a section with the page's own title. */
|
|
34
|
+
export declare function sectionsOf(page: SectionedPage, { ignored, min, max }: ResolvedSectionOptions): SearchSection[];
|
|
35
|
+
/** The sections of every page of a collection, over any `queryCollection` builder. */
|
|
36
|
+
export declare function searchSectionsOf(query: () => CollectionQueryBuilder<Record<string, unknown>>, options?: SearchSectionsOptions): Promise<SearchSection[]>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ContentStore } from "./store.ts";
|
|
2
|
+
/** The door's plugin hands over `#hamur/content/store` at start, so `queryCollection` reaches it without the client graph importing it. */
|
|
3
|
+
export declare function setServerStore(store: ContentStore): void;
|
|
4
|
+
export declare function serverStore(): ContentStore | undefined;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CollectionDefinition, ContentEntry } from "../types.ts";
|
|
2
|
+
/** One chunk of a collection, with the `id` of its first and last entry. */
|
|
3
|
+
export interface StoredChunk {
|
|
4
|
+
first: string;
|
|
5
|
+
last: string;
|
|
6
|
+
load(): Promise<{
|
|
7
|
+
default: ContentEntry[];
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
10
|
+
export interface StoredCollection {
|
|
11
|
+
type: CollectionDefinition["type"];
|
|
12
|
+
expose: boolean;
|
|
13
|
+
order?: CollectionDefinition["order"];
|
|
14
|
+
/** Imports the whole collection as one JSON chunk (`hamur dev`). */
|
|
15
|
+
load?(): Promise<{
|
|
16
|
+
default: ContentEntry[];
|
|
17
|
+
}>;
|
|
18
|
+
/** The collection's chunks in source order, each imported on the collection's first read. */
|
|
19
|
+
chunks?: StoredChunk[];
|
|
20
|
+
}
|
|
21
|
+
export interface ContentStore {
|
|
22
|
+
readonly collections: Readonly<Record<string, Omit<StoredCollection, "load">>>;
|
|
23
|
+
/** The collection's entries in source order; its chunks are imported together on the first call in a process. */
|
|
24
|
+
entries(name: string): Promise<ContentEntry[]>;
|
|
25
|
+
}
|
|
26
|
+
export interface StoreOptions {
|
|
27
|
+
/** `false` calls `load` on every read: `hamur dev`'s loader reads the entries as they are now. Default `true`. */
|
|
28
|
+
cache?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/** The store the server reads, over the chunks `#hamur/content/store` lists. */
|
|
31
|
+
export declare function createStore(collections: Record<string, StoredCollection>, { cache }?: StoreOptions): ContentStore;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const contentQuery: import("hamur/server").Handler<unknown, unknown, unknown, unknown, {}>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CollectionQuery } from "../runtime/query.ts";
|
|
2
|
+
import type { ContentStore } from "../runtime/store.ts";
|
|
3
|
+
/** The arguments of `Query.<collection>` in `content.graphql`. */
|
|
4
|
+
export interface ListArgs {
|
|
5
|
+
where?: Array<{
|
|
6
|
+
field: string;
|
|
7
|
+
operator?: string | null;
|
|
8
|
+
value?: string | null;
|
|
9
|
+
}> | null;
|
|
10
|
+
order?: Array<{
|
|
11
|
+
field: string;
|
|
12
|
+
direction?: "ASC" | "DESC" | null;
|
|
13
|
+
}> | null;
|
|
14
|
+
limit?: number | null;
|
|
15
|
+
skip?: number | null;
|
|
16
|
+
}
|
|
17
|
+
/** The arguments as the engine's query: a `value` is read as a REST query value is, and `limit` is capped as REST caps it. */
|
|
18
|
+
export declare function graphqlQuery({ where, order, limit, skip }: ListArgs): CollectionQuery;
|
|
19
|
+
/** `Query.<collection>`: the entries the arguments select. */
|
|
20
|
+
export declare const contentList: (store: ContentStore, name: string, args: ListArgs) => Promise<unknown>;
|
|
21
|
+
/** `Query.<collection>Item`: the entry whose `key` (`path` for a page, `id` for data) is `value`, or null. */
|
|
22
|
+
export declare function contentItem(store: ContentStore, name: string, key: "path" | "id", value: string): Promise<unknown>;
|
|
23
|
+
/** A field with no GraphQL type of its own: its value as JSON text, null when it is missing. */
|
|
24
|
+
export declare const jsonField: (field: string) => (parent: Record<string, unknown>) => string | null;
|