@doccov/fumadocs-adapter 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.
@@ -0,0 +1,10 @@
1
+ import { defineConfig } from 'bunup';
2
+
3
+ export default defineConfig({
4
+ entry: ['src/index.ts', 'src/server.ts', 'src/components/index.ts'],
5
+ dts: true,
6
+ clean: true,
7
+ format: ['esm'],
8
+ external: ['react', 'react-dom', '@doccov/ui'],
9
+ });
10
+
@@ -0,0 +1,160 @@
1
+ import { OpenPkg, SpecExport, SpecExportKind, SpecType } from "@openpkg-ts/spec";
2
+ interface OpenPkgInstance {
3
+ /** The parsed OpenPkg spec */
4
+ spec: OpenPkg;
5
+ /** Get an by its ID */
6
+ getExport(id: string): SpecExport | undefined;
7
+ /** Get a type definition by its ID */
8
+ getType(id: string): SpecType | undefined;
9
+ /** Get all exports of a specific kind */
10
+ getExportsByKind(kind: SpecExportKind): SpecExport[];
11
+ /** Get all exports */
12
+ getAllExports(): SpecExport[];
13
+ /** Get all type definitions */
14
+ getAllTypes(): SpecType[];
15
+ }
16
+ import { OpenPkg as OpenPkg2 } from "@openpkg-ts/spec";
17
+ interface APIPageProps {
18
+ /** Direct spec object */
19
+ spec?: OpenPkg2;
20
+ /** Or server instance from createOpenPkg() */
21
+ instance?: OpenPkgInstance;
22
+ /** Export ID to render */
23
+ id: string;
24
+ }
25
+ /**
26
+ * Main API page component that renders documentation for a single export.
27
+ *
28
+ * @example
29
+ * ```tsx
30
+ * import { APIPage } from '@doccov/fumadocs-adapter';
31
+ * import spec from './openpkg.json';
32
+ *
33
+ * <APIPage spec={spec} id="createClient" />
34
+ * ```
35
+ *
36
+ * @example
37
+ * ```tsx
38
+ * // With server instance
39
+ * import { APIPage } from '@doccov/fumadocs-adapter';
40
+ * import { openpkg } from '@/lib/openpkg';
41
+ *
42
+ * <APIPage instance={openpkg} id="createClient" />
43
+ * ```
44
+ */
45
+ declare function APIPage({ spec, instance, id }: APIPageProps);
46
+ import { OpenPkg as OpenPkg3, SpecExport as SpecExport2 } from "@openpkg-ts/spec";
47
+ interface FunctionPageProps {
48
+ export: SpecExport2;
49
+ spec: OpenPkg3;
50
+ }
51
+ declare function FunctionPage({ export: exp, spec }: FunctionPageProps);
52
+ import { OpenPkg as OpenPkg4, SpecExport as SpecExport3 } from "@openpkg-ts/spec";
53
+ interface ClassPageProps {
54
+ export: SpecExport3;
55
+ spec: OpenPkg4;
56
+ }
57
+ declare function ClassPage({ export: exp, spec }: ClassPageProps);
58
+ import { OpenPkg as OpenPkg5, SpecExport as SpecExport4 } from "@openpkg-ts/spec";
59
+ interface InterfacePageProps {
60
+ export: SpecExport4;
61
+ spec: OpenPkg5;
62
+ }
63
+ declare function InterfacePage({ export: exp, spec }: InterfacePageProps);
64
+ import { OpenPkg as OpenPkg6, SpecExport as SpecExport5 } from "@openpkg-ts/spec";
65
+ interface EnumPageProps {
66
+ export: SpecExport5;
67
+ spec: OpenPkg6;
68
+ }
69
+ declare function EnumPage({ export: exp, spec }: EnumPageProps);
70
+ import { OpenPkg as OpenPkg7, SpecExport as SpecExport6 } from "@openpkg-ts/spec";
71
+ interface VariablePageProps {
72
+ export: SpecExport6;
73
+ spec: OpenPkg7;
74
+ }
75
+ declare function VariablePage({ export: exp, spec }: VariablePageProps);
76
+ import { OpenPkg as OpenPkg8, SpecSignatureParameter, SpecMember } from "@openpkg-ts/spec";
77
+ interface TypeTableProps {
78
+ items: (SpecSignatureParameter | SpecMember)[];
79
+ spec?: OpenPkg8;
80
+ showRequired?: boolean;
81
+ }
82
+ declare function TypeTable({ items, showRequired }: TypeTableProps);
83
+ import { SpecExport as SpecExport7 } from "@openpkg-ts/spec";
84
+ interface SignatureProps {
85
+ export: SpecExport7;
86
+ signatureIndex?: number;
87
+ }
88
+ declare function Signature({ export: exp, signatureIndex }: SignatureProps);
89
+ interface ExamplesSectionProps {
90
+ examples: string[];
91
+ }
92
+ declare function ExamplesSection({ examples }: ExamplesSectionProps);
93
+ import { SpecDocsMetadata } from "@openpkg-ts/spec";
94
+ interface CoverageBadgeProps {
95
+ docs: SpecDocsMetadata;
96
+ showMissing?: boolean;
97
+ showDrift?: boolean;
98
+ }
99
+ declare function CoverageBadge({ docs, showMissing, showDrift }: CoverageBadgeProps);
100
+ import { SpecMember as SpecMember2, OpenPkg as OpenPkg9 } from "@openpkg-ts/spec";
101
+ interface MembersSectionProps {
102
+ members: SpecMember2[];
103
+ spec?: OpenPkg9;
104
+ title?: string;
105
+ }
106
+ declare function MembersSection({ members, spec, title }: MembersSectionProps);
107
+ import { OpenPkg as OpenPkg10, SpecSignatureParameter as SpecSignatureParameter2 } from "@openpkg-ts/spec";
108
+ interface ParameterCardProps {
109
+ param: SpecSignatureParameter2;
110
+ spec?: OpenPkg10;
111
+ }
112
+ declare function ParameterCard({ param, spec }: ParameterCardProps);
113
+ interface CodeExampleProps {
114
+ code: string;
115
+ filename?: string;
116
+ language?: string;
117
+ }
118
+ declare function CodeExample({ code, filename, language }: CodeExampleProps);
119
+ import { SpecSignatureParameter as SpecSignatureParameter3, SpecSchema } from "@openpkg-ts/spec";
120
+ interface ExpandablePropertyProps {
121
+ param: SpecSignatureParameter3;
122
+ depth?: number;
123
+ }
124
+ interface NestedPropertyProps {
125
+ name: string;
126
+ schema: SpecSchema;
127
+ required?: boolean;
128
+ depth?: number;
129
+ }
130
+ /**
131
+ * Nested property row with expandable nested objects
132
+ */
133
+ declare function NestedProperty({ name, schema, required, depth }: NestedPropertyProps);
134
+ /**
135
+ * Top-level expandable property for method parameters
136
+ * Entry point for rendering a parameter with progressive disclosure
137
+ */
138
+ declare function ExpandableProperty({ param, depth }: ExpandablePropertyProps);
139
+ import { SpecMember as SpecMember3 } from "@openpkg-ts/spec";
140
+ interface CollapsibleMethodProps {
141
+ member: SpecMember3;
142
+ defaultExpanded?: boolean;
143
+ }
144
+ /**
145
+ * Collapsible method section with expand/collapse behavior
146
+ * Shows compact signature when collapsed, full details when expanded
147
+ */
148
+ declare function CollapsibleMethod({ member, defaultExpanded }: CollapsibleMethodProps);
149
+ import { SpecMember as SpecMember4 } from "@openpkg-ts/spec";
150
+ interface MethodSectionProps {
151
+ member: SpecMember4;
152
+ /** @deprecated Use CollapsibleMethod directly with defaultExpanded */
153
+ defaultExpanded?: boolean;
154
+ }
155
+ /**
156
+ * Method display section with collapsible behavior
157
+ * @deprecated Use CollapsibleMethod directly for more control
158
+ */
159
+ declare function MethodSection({ member, defaultExpanded }: MethodSectionProps);
160
+ export { VariablePageProps, VariablePage, TypeTableProps, TypeTable, SignatureProps, Signature, ParameterCardProps, ParameterCard, NestedPropertyProps, NestedProperty, MethodSectionProps, MethodSection, MembersSectionProps, MembersSection, InterfacePageProps, InterfacePage, FunctionPageProps, FunctionPage, ExpandablePropertyProps, ExpandableProperty, ExamplesSectionProps, ExamplesSection, EnumPageProps, EnumPage, CoverageBadgeProps, CoverageBadge, CollapsibleMethodProps, CollapsibleMethod, CodeExampleProps, CodeExample, ClassPageProps, ClassPage, APIPageProps, APIPage };
@@ -0,0 +1,237 @@
1
+ "use client";
2
+ import {
3
+ APIPage,
4
+ ClassPage,
5
+ CodeExample,
6
+ CollapsibleMethod,
7
+ CoverageBadge,
8
+ EnumPage,
9
+ ExamplesSection,
10
+ ExpandableProperty,
11
+ FunctionPage,
12
+ InterfacePage,
13
+ NestedProperty,
14
+ ParameterCard,
15
+ Signature,
16
+ TypeTable,
17
+ VariablePage
18
+ } from "../shared/chunk-pqaj3kdh.js";
19
+ // src/components/members-section.tsx
20
+ import { jsxDEV } from "react/jsx-dev-runtime";
21
+
22
+ function formatSchema(schema) {
23
+ if (!schema)
24
+ return "unknown";
25
+ if (typeof schema === "string")
26
+ return schema;
27
+ if (typeof schema === "object" && schema !== null) {
28
+ const s = schema;
29
+ if (s.$ref && typeof s.$ref === "string") {
30
+ return s.$ref.replace("#/types/", "");
31
+ }
32
+ if (s.tsType)
33
+ return String(s.tsType);
34
+ if (s.type)
35
+ return String(s.type);
36
+ }
37
+ return "unknown";
38
+ }
39
+ function groupMembersByKind(members) {
40
+ const groups = {
41
+ constructors: [],
42
+ properties: [],
43
+ methods: [],
44
+ accessors: [],
45
+ other: []
46
+ };
47
+ for (const member of members) {
48
+ const kind = member.kind?.toLowerCase() ?? "other";
49
+ if (kind === "constructor") {
50
+ groups.constructors.push(member);
51
+ } else if (kind === "property" || kind === "field") {
52
+ groups.properties.push(member);
53
+ } else if (kind === "method" || kind === "function") {
54
+ groups.methods.push(member);
55
+ } else if (kind === "getter" || kind === "setter" || kind === "accessor") {
56
+ groups.accessors.push(member);
57
+ } else {
58
+ groups.other.push(member);
59
+ }
60
+ }
61
+ return groups;
62
+ }
63
+ function MemberRow({ member }) {
64
+ const visibility = member.visibility ?? "public";
65
+ const isStatic = member.flags?.static;
66
+ const isAbstract = member.flags?.abstract;
67
+ const isReadonly = member.flags?.readonly;
68
+ const badges = [];
69
+ if (visibility !== "public")
70
+ badges.push(visibility);
71
+ if (isStatic)
72
+ badges.push("static");
73
+ if (isAbstract)
74
+ badges.push("abstract");
75
+ if (isReadonly)
76
+ badges.push("readonly");
77
+ const type = formatSchema(member.schema);
78
+ const sig = member.signatures?.[0];
79
+ let signature = "";
80
+ if (sig) {
81
+ const params = sig.parameters?.map((p) => {
82
+ const optional = p.required === false ? "?" : "";
83
+ return `${p.name}${optional}: ${formatSchema(p.schema)}`;
84
+ }) ?? [];
85
+ const returnType = sig.returns?.tsType ?? formatSchema(sig.returns?.schema) ?? "void";
86
+ signature = `(${params.join(", ")}): ${returnType}`;
87
+ }
88
+ return /* @__PURE__ */ jsxDEV("div", {
89
+ className: "py-3 border-b border-fd-border last:border-0",
90
+ children: [
91
+ /* @__PURE__ */ jsxDEV("div", {
92
+ className: "flex items-start gap-2",
93
+ children: [
94
+ /* @__PURE__ */ jsxDEV("code", {
95
+ className: "font-mono text-sm text-fd-primary",
96
+ children: [
97
+ member.name,
98
+ signature
99
+ ]
100
+ }, undefined, true, undefined, this),
101
+ badges.length > 0 && /* @__PURE__ */ jsxDEV("div", {
102
+ className: "flex gap-1",
103
+ children: badges.map((badge) => /* @__PURE__ */ jsxDEV("span", {
104
+ className: "text-xs px-1.5 py-0.5 rounded bg-fd-secondary text-fd-muted-foreground",
105
+ children: badge
106
+ }, badge, false, undefined, this))
107
+ }, undefined, false, undefined, this)
108
+ ]
109
+ }, undefined, true, undefined, this),
110
+ !signature && type !== "unknown" && /* @__PURE__ */ jsxDEV("code", {
111
+ className: "text-xs text-fd-muted-foreground font-mono mt-1 block",
112
+ children: type
113
+ }, undefined, false, undefined, this),
114
+ member.description && /* @__PURE__ */ jsxDEV("p", {
115
+ className: "text-sm text-fd-muted-foreground mt-1",
116
+ children: member.description
117
+ }, undefined, false, undefined, this)
118
+ ]
119
+ }, undefined, true, undefined, this);
120
+ }
121
+ function MembersSection({ members, spec, title = "Members" }) {
122
+ if (!members?.length)
123
+ return null;
124
+ const groups = groupMembersByKind(members);
125
+ return /* @__PURE__ */ jsxDEV("div", {
126
+ className: "my-6",
127
+ children: [
128
+ /* @__PURE__ */ jsxDEV("h3", {
129
+ className: "text-lg font-semibold mb-3",
130
+ children: title
131
+ }, undefined, false, undefined, this),
132
+ groups.constructors.length > 0 && /* @__PURE__ */ jsxDEV("div", {
133
+ className: "mb-6",
134
+ children: [
135
+ /* @__PURE__ */ jsxDEV("h4", {
136
+ className: "text-sm font-medium text-fd-muted-foreground mb-2 uppercase tracking-wide",
137
+ children: "Constructor"
138
+ }, undefined, false, undefined, this),
139
+ /* @__PURE__ */ jsxDEV("div", {
140
+ className: "rounded-lg border border-fd-border bg-fd-card",
141
+ children: groups.constructors.map((member, index) => /* @__PURE__ */ jsxDEV(MemberRow, {
142
+ member
143
+ }, member.name ?? index, false, undefined, this))
144
+ }, undefined, false, undefined, this)
145
+ ]
146
+ }, undefined, true, undefined, this),
147
+ groups.properties.length > 0 && /* @__PURE__ */ jsxDEV("div", {
148
+ className: "mb-6",
149
+ children: [
150
+ /* @__PURE__ */ jsxDEV("h4", {
151
+ className: "text-sm font-medium text-fd-muted-foreground mb-2 uppercase tracking-wide",
152
+ children: "Properties"
153
+ }, undefined, false, undefined, this),
154
+ /* @__PURE__ */ jsxDEV("div", {
155
+ className: "rounded-lg border border-fd-border bg-fd-card",
156
+ children: groups.properties.map((member, index) => /* @__PURE__ */ jsxDEV(MemberRow, {
157
+ member
158
+ }, member.name ?? index, false, undefined, this))
159
+ }, undefined, false, undefined, this)
160
+ ]
161
+ }, undefined, true, undefined, this),
162
+ groups.methods.length > 0 && /* @__PURE__ */ jsxDEV("div", {
163
+ className: "mb-6",
164
+ children: [
165
+ /* @__PURE__ */ jsxDEV("h4", {
166
+ className: "text-sm font-medium text-fd-muted-foreground mb-2 uppercase tracking-wide",
167
+ children: "Methods"
168
+ }, undefined, false, undefined, this),
169
+ /* @__PURE__ */ jsxDEV("div", {
170
+ className: "rounded-lg border border-fd-border bg-fd-card",
171
+ children: groups.methods.map((member, index) => /* @__PURE__ */ jsxDEV(MemberRow, {
172
+ member
173
+ }, member.name ?? index, false, undefined, this))
174
+ }, undefined, false, undefined, this)
175
+ ]
176
+ }, undefined, true, undefined, this),
177
+ groups.accessors.length > 0 && /* @__PURE__ */ jsxDEV("div", {
178
+ className: "mb-6",
179
+ children: [
180
+ /* @__PURE__ */ jsxDEV("h4", {
181
+ className: "text-sm font-medium text-fd-muted-foreground mb-2 uppercase tracking-wide",
182
+ children: "Accessors"
183
+ }, undefined, false, undefined, this),
184
+ /* @__PURE__ */ jsxDEV("div", {
185
+ className: "rounded-lg border border-fd-border bg-fd-card",
186
+ children: groups.accessors.map((member, index) => /* @__PURE__ */ jsxDEV(MemberRow, {
187
+ member
188
+ }, member.name ?? index, false, undefined, this))
189
+ }, undefined, false, undefined, this)
190
+ ]
191
+ }, undefined, true, undefined, this),
192
+ groups.other.length > 0 && /* @__PURE__ */ jsxDEV("div", {
193
+ className: "mb-6",
194
+ children: [
195
+ /* @__PURE__ */ jsxDEV("h4", {
196
+ className: "text-sm font-medium text-fd-muted-foreground mb-2 uppercase tracking-wide",
197
+ children: "Other"
198
+ }, undefined, false, undefined, this),
199
+ /* @__PURE__ */ jsxDEV("div", {
200
+ className: "rounded-lg border border-fd-border bg-fd-card",
201
+ children: groups.other.map((member, index) => /* @__PURE__ */ jsxDEV(MemberRow, {
202
+ member
203
+ }, member.name ?? index, false, undefined, this))
204
+ }, undefined, false, undefined, this)
205
+ ]
206
+ }, undefined, true, undefined, this)
207
+ ]
208
+ }, undefined, true, undefined, this);
209
+ }
210
+ // src/components/method-section.tsx
211
+ import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
212
+
213
+ function MethodSection({ member, defaultExpanded = false }) {
214
+ return /* @__PURE__ */ jsxDEV2(CollapsibleMethod, {
215
+ member,
216
+ defaultExpanded
217
+ }, undefined, false, undefined, this);
218
+ }
219
+ export {
220
+ VariablePage,
221
+ TypeTable,
222
+ Signature,
223
+ ParameterCard,
224
+ NestedProperty,
225
+ MethodSection,
226
+ MembersSection,
227
+ InterfacePage,
228
+ FunctionPage,
229
+ ExpandableProperty,
230
+ ExamplesSection,
231
+ EnumPage,
232
+ CoverageBadge,
233
+ CollapsibleMethod,
234
+ CodeExample,
235
+ ClassPage,
236
+ APIPage
237
+ };
@@ -0,0 +1,64 @@
1
+ import { OpenPkg, SpecExport, SpecExportKind, SpecType } from "@openpkg-ts/spec";
2
+ interface OpenPkgOptions {
3
+ /** Path to openpkg.json file or the spec object directly */
4
+ input: string | OpenPkg;
5
+ }
6
+ interface OpenPkgInstance {
7
+ /** The parsed OpenPkg spec */
8
+ spec: OpenPkg;
9
+ /** Get an by its ID */
10
+ getExport(id: string): SpecExport | undefined;
11
+ /** Get a type definition by its ID */
12
+ getType(id: string): SpecType | undefined;
13
+ /** Get all exports of a specific kind */
14
+ getExportsByKind(kind: SpecExportKind): SpecExport[];
15
+ /** Get all exports */
16
+ getAllExports(): SpecExport[];
17
+ /** Get all type definitions */
18
+ getAllTypes(): SpecType[];
19
+ }
20
+ /**
21
+ * Creates an OpenPkg instance for use with Fumadocs components.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * // From file path
26
+ * const openpkg = createOpenPkg({ input: './openpkg.json' });
27
+ *
28
+ * // From spec object
29
+ * import spec from './openpkg.json';
30
+ * const openpkg = createOpenPkg({ input: spec });
31
+ * ```
32
+ */
33
+ declare function createOpenPkg(options: OpenPkgOptions): OpenPkgInstance;
34
+ import { OpenPkg as OpenPkg2 } from "@openpkg-ts/spec";
35
+ interface APIPageProps {
36
+ /** Direct spec object */
37
+ spec?: OpenPkg2;
38
+ /** Or server instance from createOpenPkg() */
39
+ instance?: OpenPkgInstance;
40
+ /** Export ID to render */
41
+ id: string;
42
+ }
43
+ /**
44
+ * Main API page component that renders documentation for a single export.
45
+ *
46
+ * @example
47
+ * ```tsx
48
+ * import { APIPage } from '@doccov/fumadocs-adapter';
49
+ * import spec from './openpkg.json';
50
+ *
51
+ * <APIPage spec={spec} id="createClient" />
52
+ * ```
53
+ *
54
+ * @example
55
+ * ```tsx
56
+ * // With server instance
57
+ * import { APIPage } from '@doccov/fumadocs-adapter';
58
+ * import { openpkg } from '@/lib/openpkg';
59
+ *
60
+ * <APIPage instance={openpkg} id="createClient" />
61
+ * ```
62
+ */
63
+ declare function APIPage({ spec, instance, id }: APIPageProps);
64
+ export { createOpenPkg, OpenPkgOptions, OpenPkgInstance, APIPageProps, APIPage };
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ import {
2
+ createOpenPkg
3
+ } from "./server.js";
4
+ import {
5
+ APIPage
6
+ } from "./shared/chunk-pqaj3kdh.js";
7
+ export {
8
+ createOpenPkg,
9
+ APIPage
10
+ };
@@ -0,0 +1,34 @@
1
+ import { OpenPkg, SpecExport, SpecExportKind, SpecType } from "@openpkg-ts/spec";
2
+ interface OpenPkgOptions {
3
+ /** Path to openpkg.json file or the spec object directly */
4
+ input: string | OpenPkg;
5
+ }
6
+ interface OpenPkgInstance {
7
+ /** The parsed OpenPkg spec */
8
+ spec: OpenPkg;
9
+ /** Get an by its ID */
10
+ getExport(id: string): SpecExport | undefined;
11
+ /** Get a type definition by its ID */
12
+ getType(id: string): SpecType | undefined;
13
+ /** Get all exports of a specific kind */
14
+ getExportsByKind(kind: SpecExportKind): SpecExport[];
15
+ /** Get all exports */
16
+ getAllExports(): SpecExport[];
17
+ /** Get all type definitions */
18
+ getAllTypes(): SpecType[];
19
+ }
20
+ /**
21
+ * Creates an OpenPkg instance for use with Fumadocs components.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * // From file path
26
+ * const openpkg = createOpenPkg({ input: './openpkg.json' });
27
+ *
28
+ * // From spec object
29
+ * import spec from './openpkg.json';
30
+ * const openpkg = createOpenPkg({ input: spec });
31
+ * ```
32
+ */
33
+ declare function createOpenPkg(options: OpenPkgOptions): OpenPkgInstance;
34
+ export { createOpenPkg, OpenPkgOptions, OpenPkgInstance };
package/dist/server.js ADDED
@@ -0,0 +1,38 @@
1
+ // src/server.ts
2
+ import * as fs from "node:fs";
3
+ function createOpenPkg(options) {
4
+ const spec = typeof options.input === "string" ? JSON.parse(fs.readFileSync(options.input, "utf-8")) : options.input;
5
+ const exportsById = new Map;
6
+ const typesById = new Map;
7
+ for (const exp of spec.exports) {
8
+ exportsById.set(exp.id, exp);
9
+ }
10
+ if (spec.types) {
11
+ for (const type of spec.types) {
12
+ typesById.set(type.id, type);
13
+ }
14
+ }
15
+ return {
16
+ spec,
17
+ getExport(id) {
18
+ return exportsById.get(id);
19
+ },
20
+ getType(id) {
21
+ return typesById.get(id);
22
+ },
23
+ getExportsByKind(kind) {
24
+ return spec.exports.filter((exp) => exp.kind === kind);
25
+ },
26
+ getAllExports() {
27
+ return spec.exports;
28
+ },
29
+ getAllTypes() {
30
+ return spec.types ?? [];
31
+ }
32
+ };
33
+ }
34
+ export {
35
+ createOpenPkg
36
+ };
37
+
38
+ export { createOpenPkg };