@piqit/resolvers 0.0.2 → 0.0.5
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/dist/file-markdown.d.ts +1 -1
- package/dist/file-markdown.d.ts.map +1 -1
- package/dist/file-markdown.js +2 -2
- package/dist/file-markdown.js.map +1 -1
- package/dist/path-pattern.d.ts +2 -1
- package/dist/path-pattern.d.ts.map +1 -1
- package/dist/path-pattern.js.map +1 -1
- package/dist/static.d.ts +1 -1
- package/dist/static.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/edge.ts +0 -15
- package/src/file-markdown.ts +0 -352
- package/src/frontmatter.ts +0 -269
- package/src/index.ts +0 -65
- package/src/markdown.ts +0 -262
- package/src/path-pattern.ts +0 -226
- package/src/static.ts +0 -227
package/dist/file-markdown.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* A resolver for querying markdown files from the filesystem.
|
|
5
5
|
* Optimized for reading only what's needed based on the query.
|
|
6
6
|
*/
|
|
7
|
-
import type { Resolver, StandardSchema, Infer } from "piqit";
|
|
7
|
+
import type { Resolver, StandardSchema, Infer } from "@piqit/core";
|
|
8
8
|
import { type PathParams } from "./path-pattern";
|
|
9
9
|
import { type BodyOptions, type BodyResult, type Heading } from "./markdown";
|
|
10
10
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-markdown.d.ts","sourceRoot":"","sources":["../src/file-markdown.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"file-markdown.d.ts","sourceRoot":"","sources":["../src/file-markdown.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAClE,OAAO,EAAsC,KAAK,UAAU,EAAE,MA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AAY,CAC1B,KAAK,SAAS,MAAM,EACpB,YAAY,SAAS,cAAc,EACnC,KAAK,SAAS,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAEjD,OAAO,EAAE,mBAAmB,CAAC,KAAK,EAAE,YAAY,EAAE,KAAK,CAAC,GACvD,QAAQ,CACT,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,EAC1C,YAAY,EACZ,cAAc,CACZ,kBAAkB,CAChB,UAAU,CAAC,KAAK,CAAC,EACjB,KAAK,CAAC,YAAY,CAAC,EACnB,cAAc,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CACzC,CACF,CACF,CA2HA"}
|
package/dist/file-markdown.js
CHANGED
|
@@ -20,7 +20,7 @@ function createResultSchema(_paramNames, frontmatterSchema, bodyOptions) {
|
|
|
20
20
|
"~standard": {
|
|
21
21
|
version: 1,
|
|
22
22
|
vendor: "piqit/resolvers",
|
|
23
|
-
validate(value) {
|
|
23
|
+
async validate(value) {
|
|
24
24
|
if (value === null || typeof value !== "object") {
|
|
25
25
|
return { issues: [{ message: "Expected object" }] };
|
|
26
26
|
}
|
|
@@ -30,7 +30,7 @@ function createResultSchema(_paramNames, frontmatterSchema, bodyOptions) {
|
|
|
30
30
|
return { issues: [{ message: "Missing params", path: ["params"] }] };
|
|
31
31
|
}
|
|
32
32
|
// Validate frontmatter using the provided schema
|
|
33
|
-
const fmResult = frontmatterSchema["~standard"].validate(obj.frontmatter);
|
|
33
|
+
const fmResult = await frontmatterSchema["~standard"].validate(obj.frontmatter);
|
|
34
34
|
if (fmResult.issues) {
|
|
35
35
|
return {
|
|
36
36
|
issues: fmResult.issues.map((issue) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-markdown.js","sourceRoot":"","sources":["../src/file-markdown.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAmB,MAAM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,SAAS,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,IAAI,CAAC,MAAiC,CAAC,EAAE,CAAC;wBACrF,SAAQ;oBACV,CAAC;gBACH,CAAC;gBAED,8BAA8B;gBAC9B,IAAI,QAAQ,EAAE,CAAC;oBACb,IAAI,CAAC,OAAO,EAAE,CAAC;wBACb,OAAO,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAA;oBAC3C,CAAC;oBAED,4CAA4C;oBAC5C,IAAI,GAAG,iBAAiB,CAAC,OAAO,EAAE,eAAe,CAAC,CAAA;gBACpD,CAAC;gBAED,0CAA0C;gBAC1C,MAAM,MAAM,GAMR,EAAE,CAAA;gBAEN,IAAI,UAAU,EAAE,CAAC;oBACf,MAAM,CAAC,MAAM,GAAG,MAA2B,CAAA;gBAC7C,CAAC;gBAED,IAAI,eAAe,EAAE,CAAC;oBACpB,MAAM,CAAC,WAAW,GAAG,WAAkC,CAAA;gBACzD,CAAC;gBAED,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;oBACrB,MAAM,CAAC,IAAI,GAAG,IAAgD,CAAA;gBAChE,CAAC;gBAED,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YACtB,CAAC;YAED,OAAO,OAAO,CAAA;QAChB,CAAC;KACF,CAAA;AACH,CAAC"}
|
package/dist/path-pattern.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* - Path matching to extract params
|
|
8
8
|
* - Path building from params
|
|
9
9
|
*/
|
|
10
|
+
import { StandardSchema } from "@piqit/core";
|
|
10
11
|
/**
|
|
11
12
|
* Extract params from a path pattern string at the type level.
|
|
12
13
|
*
|
|
@@ -92,5 +93,5 @@ export declare function compilePattern(pattern: string): CompiledPattern;
|
|
|
92
93
|
* @param pattern - The compiled pattern
|
|
93
94
|
* @returns A StandardSchema that validates param objects
|
|
94
95
|
*/
|
|
95
|
-
export declare function createParamsSchema(pattern: CompiledPattern):
|
|
96
|
+
export declare function createParamsSchema(pattern: CompiledPattern): StandardSchema<Record<string, string>>;
|
|
96
97
|
//# sourceMappingURL=path-pattern.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path-pattern.d.ts","sourceRoot":"","sources":["../src/path-pattern.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"path-pattern.d.ts","sourceRoot":"","sources":["../src/path-pattern.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAM7C;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,IAAI,MAAM,KAAK,IAAI,MAAM,IAAI,EAAE,GAC5F;KAAG,CAAC,IAAI,KAAK,GAAG,MAAM;CAAE,GAAG,aAAa,CAAC,IAAI,CAAC,GAC9C,EAAE,CAAA;AAEN;;;GAGG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAA;AAElD;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,MAAM,IAAI,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAA;AAMrE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,UAAU,EAAE,MAAM,EAAE,CAAA;IAEpB;;;;;;;;;OASG;IACH,MAAM,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAA;IAErD;;;;;;;;;OASG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAA;IAElD;;;;;;;;OAQG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAA;CAC9C;AAiBD;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAkE/D;AAMD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,eAAe,GACvB,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA4BxC"}
|
package/dist/path-pattern.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path-pattern.js","sourceRoot":"","sources":["../src/path-pattern.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"path-pattern.js","sourceRoot":"","sources":["../src/path-pattern.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAoFH,gFAAgF;AAChF,kBAAkB;AAClB,gFAAgF;AAEhF;;;GAGG;AACH,MAAM,WAAW,GAAG,+BAA+B,CAAA;AAEnD;;GAEG;AACH,MAAM,YAAY,GAAG,qBAAqB,CAAA;AAE1C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,uCAAuC;IACvC,MAAM,UAAU,GAAa,EAAE,CAAA;IAC/B,IAAI,KAA6B,CAAA;IACjC,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACjD,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAC9C,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IAC3B,CAAC;IAED,mEAAmE;IACnE,uDAAuD;IACvD,MAAM,YAAY,GAAG,OAAO;SACzB,OAAO,CAAC,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE;QAC9B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AC;yBACtE,CAAA;oBACH,CAAC;gBACH,CAAC;gBAED,OAAO,EAAE,KAAK,EAAE,GAA6B,EAAE,CAAA;YACjD,CAAC;SACF;KACF,CAAA;AACH,CAAC"}
|
package/dist/static.d.ts
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* .select("params.slug", "frontmatter.title")
|
|
28
28
|
* .exec();
|
|
29
29
|
*/
|
|
30
|
-
import type { Resolver, StandardSchema } from "piqit";
|
|
30
|
+
import type { Resolver, StandardSchema } from "@piqit/core";
|
|
31
31
|
/**
|
|
32
32
|
* Create a static content resolver from pre-compiled data.
|
|
33
33
|
*
|
package/dist/static.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../src/static.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../src/static.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AA2H3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAC5C,IAAI,EAAE,CAAC,EAAE,GACR,QAAQ,CACT,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,EAChD,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,EAChD,cAAc,CAAC,CAAC,CAAC,CAClB,CAiCA;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,sBAAgB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@piqit/resolvers",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
6
7
|
"exports": {
|
|
7
8
|
".": {
|
|
8
|
-
"types": "./
|
|
9
|
-
"
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
10
11
|
},
|
|
11
12
|
"./edge": {
|
|
12
|
-
"types": "./
|
|
13
|
-
"
|
|
13
|
+
"types": "./dist/edge.d.ts",
|
|
14
|
+
"default": "./dist/edge.js"
|
|
14
15
|
},
|
|
15
16
|
"./static": {
|
|
16
|
-
"types": "./
|
|
17
|
-
"
|
|
17
|
+
"types": "./dist/static.d.ts",
|
|
18
|
+
"default": "./dist/static.js"
|
|
18
19
|
}
|
|
19
20
|
},
|
|
20
21
|
"files": [
|
|
21
|
-
"src",
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"piqit": "0.0.
|
|
25
|
+
"@piqit/core": "0.0.5"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/bun": "latest",
|
package/src/edge.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @piqit/resolvers/edge - Edge-compatible resolvers
|
|
3
|
-
*
|
|
4
|
-
* This entry point only exports resolvers that work in edge environments
|
|
5
|
-
* like Cloudflare Workers, where dynamic code generation is not allowed.
|
|
6
|
-
*
|
|
7
|
-
* Use this instead of '@piqit/resolvers' in your Worker:
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* import { staticContent } from "@piqit/resolvers/edge";
|
|
11
|
-
*
|
|
12
|
-
* @packageDocumentation
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export { staticContent, staticResolver } from "./static"
|
package/src/file-markdown.ts
DELETED
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Filesystem Markdown Resolver
|
|
3
|
-
*
|
|
4
|
-
* A resolver for querying markdown files from the filesystem.
|
|
5
|
-
* Optimized for reading only what's needed based on the query.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { Resolver, StandardSchema, Infer } from "piqit"
|
|
9
|
-
import { compilePattern, createParamsSchema, type PathParams } from "./path-pattern"
|
|
10
|
-
import { parseFrontmatter } from "./frontmatter"
|
|
11
|
-
import { parseMarkdownBody, type BodyOptions, type BodyResult, type Heading } from "./markdown"
|
|
12
|
-
import path from "node:path"
|
|
13
|
-
|
|
14
|
-
// =============================================================================
|
|
15
|
-
// Types
|
|
16
|
-
// =============================================================================
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Options for creating a file markdown resolver.
|
|
20
|
-
*/
|
|
21
|
-
export interface FileMarkdownOptions<
|
|
22
|
-
TPath extends string,
|
|
23
|
-
TFrontmatter extends StandardSchema,
|
|
24
|
-
TBody extends BodyOptions
|
|
25
|
-
> {
|
|
26
|
-
/**
|
|
27
|
-
* Base directory for finding files.
|
|
28
|
-
* Can be absolute or relative to cwd.
|
|
29
|
-
*/
|
|
30
|
-
base: string
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Path pattern with {param} placeholders.
|
|
34
|
-
* @example '{year}/{slug}.md'
|
|
35
|
-
*/
|
|
36
|
-
path: TPath
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Schema for validating frontmatter.
|
|
40
|
-
* The schema's inferred type defines filter parameters.
|
|
41
|
-
*/
|
|
42
|
-
frontmatter: TFrontmatter
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Body parsing options.
|
|
46
|
-
* @default { raw: false, html: false, headings: false }
|
|
47
|
-
*/
|
|
48
|
-
body?: TBody
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* The shape of results from a file markdown resolver.
|
|
53
|
-
*/
|
|
54
|
-
export interface FileMarkdownResult<
|
|
55
|
-
TParams,
|
|
56
|
-
TFrontmatter,
|
|
57
|
-
TBody extends BodyResult
|
|
58
|
-
> {
|
|
59
|
-
params: TParams
|
|
60
|
-
frontmatter: TFrontmatter
|
|
61
|
-
body: TBody
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Type for body shape based on options.
|
|
66
|
-
*/
|
|
67
|
-
type ComputedBodyShape<T extends BodyOptions | undefined> = T extends BodyOptions
|
|
68
|
-
? {
|
|
69
|
-
raw: T["raw"] extends true ? string : never
|
|
70
|
-
html: T["html"] extends true ? string : never
|
|
71
|
-
headings: T["headings"] extends true ? Heading[] : never
|
|
72
|
-
}
|
|
73
|
-
: Record<string, never>
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Clean up body shape to remove never types.
|
|
77
|
-
*/
|
|
78
|
-
type CleanBodyShape<T> = {
|
|
79
|
-
[K in keyof T as T[K] extends never ? never : K]: T[K]
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// =============================================================================
|
|
83
|
-
// Result Schema Factory
|
|
84
|
-
// =============================================================================
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Create a result schema for the resolver.
|
|
88
|
-
* This schema validates the namespaced result shape.
|
|
89
|
-
*/
|
|
90
|
-
function createResultSchema<TFrontmatter, TBody extends BodyResult>(
|
|
91
|
-
_paramNames: string[],
|
|
92
|
-
frontmatterSchema: StandardSchema<TFrontmatter>,
|
|
93
|
-
bodyOptions: BodyOptions
|
|
94
|
-
): StandardSchema<FileMarkdownResult<Record<string, string>, TFrontmatter, TBody>> {
|
|
95
|
-
return {
|
|
96
|
-
"~standard": {
|
|
97
|
-
version: 1,
|
|
98
|
-
vendor: "piqit/resolvers",
|
|
99
|
-
validate(value: unknown) {
|
|
100
|
-
if (value === null || typeof value !== "object") {
|
|
101
|
-
return { issues: [{ message: "Expected object" }] }
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const obj = value as Record<string, unknown>
|
|
105
|
-
|
|
106
|
-
// Validate params
|
|
107
|
-
if (obj.params == null || typeof obj.params !== "object") {
|
|
108
|
-
return { issues: [{ message: "Missing params", path: ["params"] }] }
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Validate frontmatter using the provided schema
|
|
112
|
-
const fmResult = frontmatterSchema["~standard"].validate(obj.frontmatter)
|
|
113
|
-
if (fmResult.issues) {
|
|
114
|
-
return {
|
|
115
|
-
issues: fmResult.issues.map((issue) => ({
|
|
116
|
-
...issue,
|
|
117
|
-
path: ["frontmatter", ...(issue.path || [])],
|
|
118
|
-
})),
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Validate body shape
|
|
123
|
-
if (bodyOptions.raw || bodyOptions.html || bodyOptions.headings) {
|
|
124
|
-
if (obj.body == null || typeof obj.body !== "object") {
|
|
125
|
-
return { issues: [{ message: "Missing body", path: ["body"] }] }
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return { value: obj as unknown as FileMarkdownResult<Record<string, string>, TFrontmatter, TBody> }
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// =============================================================================
|
|
136
|
-
// Helper Functions
|
|
137
|
-
// =============================================================================
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Check if any select paths require frontmatter data.
|
|
141
|
-
*/
|
|
142
|
-
function needsFrontmatter(selectPaths: string[]): boolean {
|
|
143
|
-
return selectPaths.some((p) => p.startsWith("frontmatter.") || p === "frontmatter.*")
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Check if any select paths require body data.
|
|
148
|
-
*/
|
|
149
|
-
function needsBody(selectPaths: string[]): boolean {
|
|
150
|
-
return selectPaths.some((p) => p.startsWith("body.") || p === "body.*")
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Check if any select paths require params.
|
|
155
|
-
*/
|
|
156
|
-
function needsParams(selectPaths: string[]): boolean {
|
|
157
|
-
return selectPaths.some((p) => p.startsWith("params.") || p === "params.*")
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Get which body parts are needed based on select paths.
|
|
162
|
-
*/
|
|
163
|
-
function getNeededBodyParts(selectPaths: string[]): BodyOptions {
|
|
164
|
-
const result: BodyOptions = {}
|
|
165
|
-
|
|
166
|
-
for (const path of selectPaths) {
|
|
167
|
-
if (path === "body.*") {
|
|
168
|
-
// Need all body parts
|
|
169
|
-
return { raw: true, html: true, headings: true }
|
|
170
|
-
}
|
|
171
|
-
if (path === "body.raw") result.raw = true
|
|
172
|
-
if (path === "body.html") result.html = true
|
|
173
|
-
if (path === "body.headings") result.headings = true
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return result
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Check if filter constraints match frontmatter.
|
|
181
|
-
* Simple equality check for now.
|
|
182
|
-
*/
|
|
183
|
-
function matchesFilter(
|
|
184
|
-
frontmatter: Record<string, unknown>,
|
|
185
|
-
filter: Record<string, unknown>
|
|
186
|
-
): boolean {
|
|
187
|
-
for (const [key, value] of Object.entries(filter)) {
|
|
188
|
-
if (frontmatter[key] !== value) {
|
|
189
|
-
return false
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return true
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// =============================================================================
|
|
196
|
-
// Resolver Factory
|
|
197
|
-
// =============================================================================
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Create a filesystem markdown resolver.
|
|
201
|
-
*
|
|
202
|
-
* @example
|
|
203
|
-
* const postsResolver = fileMarkdown({
|
|
204
|
-
* base: 'content/posts',
|
|
205
|
-
* path: '{year}/{slug}.md',
|
|
206
|
-
* frontmatter: z.object({
|
|
207
|
-
* title: z.string(),
|
|
208
|
-
* status: z.enum(['draft', 'published']),
|
|
209
|
-
* }),
|
|
210
|
-
* body: { html: true, headings: true }
|
|
211
|
-
* })
|
|
212
|
-
*/
|
|
213
|
-
export function fileMarkdown<
|
|
214
|
-
TPath extends string,
|
|
215
|
-
TFrontmatter extends StandardSchema,
|
|
216
|
-
TBody extends BodyOptions = Record<string, never>
|
|
217
|
-
>(
|
|
218
|
-
options: FileMarkdownOptions<TPath, TFrontmatter, TBody>
|
|
219
|
-
): Resolver<
|
|
220
|
-
StandardSchema<Partial<PathParams<TPath>>>,
|
|
221
|
-
TFrontmatter,
|
|
222
|
-
StandardSchema<
|
|
223
|
-
FileMarkdownResult<
|
|
224
|
-
PathParams<TPath>,
|
|
225
|
-
Infer<TFrontmatter>,
|
|
226
|
-
CleanBodyShape<ComputedBodyShape<TBody>>
|
|
227
|
-
>
|
|
228
|
-
>
|
|
229
|
-
> {
|
|
230
|
-
const pattern = compilePattern(options.path)
|
|
231
|
-
const basePath = path.isAbsolute(options.base)
|
|
232
|
-
? options.base
|
|
233
|
-
: path.join(process.cwd(), options.base)
|
|
234
|
-
|
|
235
|
-
const bodyOptions: BodyOptions = options.body || {}
|
|
236
|
-
|
|
237
|
-
// Create schemas
|
|
238
|
-
const scanSchema = createParamsSchema(pattern) as StandardSchema<Partial<PathParams<TPath>>>
|
|
239
|
-
const resultSchema = createResultSchema(
|
|
240
|
-
pattern.paramNames,
|
|
241
|
-
options.frontmatter,
|
|
242
|
-
bodyOptions
|
|
243
|
-
) as StandardSchema<
|
|
244
|
-
FileMarkdownResult<
|
|
245
|
-
PathParams<TPath>,
|
|
246
|
-
Infer<TFrontmatter>,
|
|
247
|
-
CleanBodyShape<ComputedBodyShape<TBody>>
|
|
248
|
-
>
|
|
249
|
-
>
|
|
250
|
-
|
|
251
|
-
return {
|
|
252
|
-
schema: {
|
|
253
|
-
scanParams: scanSchema,
|
|
254
|
-
filterParams: options.frontmatter,
|
|
255
|
-
result: resultSchema,
|
|
256
|
-
},
|
|
257
|
-
|
|
258
|
-
async resolve(spec) {
|
|
259
|
-
const results: Array<
|
|
260
|
-
Partial<
|
|
261
|
-
FileMarkdownResult<
|
|
262
|
-
PathParams<TPath>,
|
|
263
|
-
Infer<TFrontmatter>,
|
|
264
|
-
CleanBodyShape<ComputedBodyShape<TBody>>
|
|
265
|
-
>
|
|
266
|
-
>
|
|
267
|
-
> = []
|
|
268
|
-
|
|
269
|
-
// 1. Generate glob pattern from scan constraints
|
|
270
|
-
const globPattern = pattern.toGlob(spec.scan as Record<string, unknown>)
|
|
271
|
-
|
|
272
|
-
// 2. Find matching files using Bun.Glob
|
|
273
|
-
const glob = new Bun.Glob(globPattern)
|
|
274
|
-
const files: string[] = []
|
|
275
|
-
|
|
276
|
-
for await (const file of glob.scan({ cwd: basePath, absolute: false })) {
|
|
277
|
-
files.push(file)
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// 3. Determine what we need to read
|
|
281
|
-
const wantParams = needsParams(spec.select)
|
|
282
|
-
const wantFrontmatter = needsFrontmatter(spec.select)
|
|
283
|
-
const wantBody = needsBody(spec.select)
|
|
284
|
-
const hasFilter = spec.filter && Object.keys(spec.filter).length > 0
|
|
285
|
-
const neededBodyParts = wantBody ? getNeededBodyParts(spec.select) : {}
|
|
286
|
-
|
|
287
|
-
// 4. Process each file
|
|
288
|
-
for (const relativePath of files) {
|
|
289
|
-
// Extract params from path
|
|
290
|
-
const params = pattern.match(relativePath)
|
|
291
|
-
if (!params) continue
|
|
292
|
-
|
|
293
|
-
const fullPath = path.join(basePath, relativePath)
|
|
294
|
-
|
|
295
|
-
// Read file content only if needed
|
|
296
|
-
let content: string | null = null
|
|
297
|
-
let frontmatter: Record<string, unknown> | null = null
|
|
298
|
-
let body: BodyResult | null = null
|
|
299
|
-
|
|
300
|
-
// If filtering or selecting frontmatter, we need to read it
|
|
301
|
-
if (hasFilter || wantFrontmatter) {
|
|
302
|
-
content = await Bun.file(fullPath).text()
|
|
303
|
-
frontmatter = parseFrontmatter(content)
|
|
304
|
-
|
|
305
|
-
if (!frontmatter) {
|
|
306
|
-
frontmatter = {}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// Check filter constraints
|
|
310
|
-
if (hasFilter && !matchesFilter(frontmatter, spec.filter as Record<string, unknown>)) {
|
|
311
|
-
continue
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
// If selecting body, parse it
|
|
316
|
-
if (wantBody) {
|
|
317
|
-
if (!content) {
|
|
318
|
-
content = await Bun.file(fullPath).text()
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// Only parse the body parts that are needed
|
|
322
|
-
body = parseMarkdownBody(content, neededBodyParts)
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// Build result with only requested fields
|
|
326
|
-
const result: Partial<
|
|
327
|
-
FileMarkdownResult<
|
|
328
|
-
PathParams<TPath>,
|
|
329
|
-
Infer<TFrontmatter>,
|
|
330
|
-
CleanBodyShape<ComputedBodyShape<TBody>>
|
|
331
|
-
>
|
|
332
|
-
> = {}
|
|
333
|
-
|
|
334
|
-
if (wantParams) {
|
|
335
|
-
result.params = params as PathParams<TPath>
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
if (wantFrontmatter) {
|
|
339
|
-
result.frontmatter = frontmatter as Infer<TFrontmatter>
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
if (wantBody && body) {
|
|
343
|
-
result.body = body as CleanBodyShape<ComputedBodyShape<TBody>>
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
results.push(result)
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
return results
|
|
350
|
-
},
|
|
351
|
-
}
|
|
352
|
-
}
|