@openpkg-ts/doc-generator 0.1.0 → 0.1.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.
@@ -1,12 +1,172 @@
1
- import {
2
- buildSignatureString,
3
- formatParameters,
4
- formatReturnType,
5
- formatSchema,
6
- getMethods,
7
- getProperties,
8
- sortByName
9
- } from "./chunk-taeg9090.js";
1
+ import { createRequire } from "node:module";
2
+ var __create = Object.create;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __toESM = (mod, isNodeMode, target) => {
8
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
9
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
+ for (let key of __getOwnPropNames(mod))
11
+ if (!__hasOwnProp.call(to, key))
12
+ __defProp(to, key, {
13
+ get: () => mod[key],
14
+ enumerable: true
15
+ });
16
+ return to;
17
+ };
18
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
19
+
20
+ // src/core/query.ts
21
+ function formatSchema(schema) {
22
+ if (!schema)
23
+ return "unknown";
24
+ if (typeof schema === "string")
25
+ return schema;
26
+ if (typeof schema === "object" && schema !== null) {
27
+ if ("$ref" in schema && typeof schema.$ref === "string") {
28
+ return schema.$ref.replace("#/types/", "");
29
+ }
30
+ if ("anyOf" in schema && Array.isArray(schema.anyOf)) {
31
+ return schema.anyOf.map((s) => formatSchema(s)).join(" | ");
32
+ }
33
+ if ("allOf" in schema && Array.isArray(schema.allOf)) {
34
+ return schema.allOf.map((s) => formatSchema(s)).join(" & ");
35
+ }
36
+ if ("type" in schema && schema.type === "array") {
37
+ const items = "items" in schema ? formatSchema(schema.items) : "unknown";
38
+ return `${items}[]`;
39
+ }
40
+ if ("type" in schema && schema.type === "tuple" && "items" in schema) {
41
+ const items = schema.items.map(formatSchema).join(", ");
42
+ return `[${items}]`;
43
+ }
44
+ if ("type" in schema && schema.type === "object") {
45
+ if ("properties" in schema && schema.properties) {
46
+ const props = Object.entries(schema.properties).map(([k, v]) => `${k}: ${formatSchema(v)}`).join("; ");
47
+ return `{ ${props} }`;
48
+ }
49
+ return "object";
50
+ }
51
+ if ("type" in schema && typeof schema.type === "string") {
52
+ return schema.type;
53
+ }
54
+ }
55
+ return "unknown";
56
+ }
57
+ function formatTypeParameters(typeParams) {
58
+ if (!typeParams?.length)
59
+ return "";
60
+ const params = typeParams.map((tp) => {
61
+ let str = tp.name;
62
+ if (tp.constraint)
63
+ str += ` extends ${tp.constraint}`;
64
+ if (tp.default)
65
+ str += ` = ${tp.default}`;
66
+ return str;
67
+ });
68
+ return `<${params.join(", ")}>`;
69
+ }
70
+ function formatParameters(sig) {
71
+ if (!sig?.parameters?.length)
72
+ return "()";
73
+ const params = sig.parameters.map((p) => {
74
+ const optional = p.required === false ? "?" : "";
75
+ const rest = p.rest ? "..." : "";
76
+ const type = formatSchema(p.schema);
77
+ return `${rest}${p.name}${optional}: ${type}`;
78
+ });
79
+ return `(${params.join(", ")})`;
80
+ }
81
+ function formatReturnType(sig) {
82
+ if (!sig?.returns)
83
+ return "void";
84
+ return formatSchema(sig.returns.schema);
85
+ }
86
+ function buildSignatureString(exp, sigIndex = 0) {
87
+ const sig = exp.signatures?.[sigIndex];
88
+ const typeParams = formatTypeParameters(exp.typeParameters || sig?.typeParameters);
89
+ switch (exp.kind) {
90
+ case "function": {
91
+ const params = formatParameters(sig);
92
+ const returnType = formatReturnType(sig);
93
+ return `function ${exp.name}${typeParams}${params}: ${returnType}`;
94
+ }
95
+ case "class": {
96
+ const ext = exp.extends ? ` extends ${exp.extends}` : "";
97
+ const impl = exp.implements?.length ? ` implements ${exp.implements.join(", ")}` : "";
98
+ return `class ${exp.name}${typeParams}${ext}${impl}`;
99
+ }
100
+ case "interface": {
101
+ const ext = exp.extends ? ` extends ${exp.extends}` : "";
102
+ return `interface ${exp.name}${typeParams}${ext}`;
103
+ }
104
+ case "type": {
105
+ const typeValue = typeof exp.type === "string" ? exp.type : formatSchema(exp.schema);
106
+ return `type ${exp.name}${typeParams} = ${typeValue}`;
107
+ }
108
+ case "enum": {
109
+ return `enum ${exp.name}`;
110
+ }
111
+ case "variable": {
112
+ const typeValue = typeof exp.type === "string" ? exp.type : formatSchema(exp.schema);
113
+ return `const ${exp.name}: ${typeValue}`;
114
+ }
115
+ default:
116
+ return exp.name;
117
+ }
118
+ }
119
+ function resolveTypeRef(ref, spec) {
120
+ const id = ref.replace("#/types/", "");
121
+ return spec.types?.find((t) => t.id === id);
122
+ }
123
+ function isMethod(member) {
124
+ return !!member.signatures?.length;
125
+ }
126
+ function isProperty(member) {
127
+ return !member.signatures?.length;
128
+ }
129
+ function getMethods(members) {
130
+ return members?.filter(isMethod) ?? [];
131
+ }
132
+ function getProperties(members) {
133
+ return members?.filter(isProperty) ?? [];
134
+ }
135
+ function groupByVisibility(members) {
136
+ const groups = {
137
+ public: [],
138
+ protected: [],
139
+ private: []
140
+ };
141
+ for (const member of members ?? []) {
142
+ const visibility = member.visibility ?? "public";
143
+ groups[visibility].push(member);
144
+ }
145
+ return groups;
146
+ }
147
+ function sortByName(items) {
148
+ return [...items].sort((a, b) => a.name.localeCompare(b.name));
149
+ }
150
+ function sortByKindThenName(exports) {
151
+ const kindOrder = {
152
+ function: 0,
153
+ class: 1,
154
+ interface: 2,
155
+ type: 3,
156
+ enum: 4,
157
+ variable: 5,
158
+ namespace: 6,
159
+ module: 7,
160
+ reference: 8,
161
+ external: 9
162
+ };
163
+ return [...exports].sort((a, b) => {
164
+ const kindDiff = kindOrder[a.kind] - kindOrder[b.kind];
165
+ if (kindDiff !== 0)
166
+ return kindDiff;
167
+ return a.name.localeCompare(b.name);
168
+ });
169
+ }
10
170
 
11
171
  // src/render/html.ts
12
172
  var defaultCSS = `
@@ -323,14 +483,14 @@ function simplifySignature(sig) {
323
483
  };
324
484
  }
325
485
  function simplifyMember(member) {
326
- const isMethod = !!member.signatures?.length;
486
+ const isMethod2 = !!member.signatures?.length;
327
487
  return {
328
488
  name: member.name || "",
329
- kind: isMethod ? "method" : "property",
330
- type: isMethod ? undefined : formatSchema(member.schema),
489
+ kind: isMethod2 ? "method" : "property",
490
+ type: isMethod2 ? undefined : formatSchema(member.schema),
331
491
  description: member.description,
332
492
  visibility: member.visibility || "public",
333
- signature: isMethod ? simplifySignature(member.signatures?.[0]) : undefined
493
+ signature: isMethod2 ? simplifySignature(member.signatures?.[0]) : undefined
334
494
  };
335
495
  }
336
496
  function simplifyExample(example) {
@@ -1157,4 +1317,4 @@ function extractModuleName(exp) {
1157
1317
  return;
1158
1318
  }
1159
1319
 
1160
- export { toHTML, toJSON, toJSONString, exportToMarkdown, toMarkdown, toNavigation, toFumadocsMetaJSON, toDocusaurusSidebarJS, toSearchIndex, toPagefindRecords, toAlgoliaRecords, toSearchIndexJSON, loadSpec, createDocs };
1320
+ export { __toESM, __require, formatSchema, formatTypeParameters, formatParameters, formatReturnType, buildSignatureString, resolveTypeRef, isMethod, isProperty, getMethods, getProperties, groupByVisibility, sortByName, sortByKindThenName, toHTML, toJSON, toJSONString, exportToMarkdown, toMarkdown, toNavigation, toFumadocsMetaJSON, toDocusaurusSidebarJS, toSearchIndex, toPagefindRecords, toAlgoliaRecords, toSearchIndexJSON, loadSpec, createDocs };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpkg-ts/doc-generator",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "API doc generator consuming OpenPkg specs. TypeDoc alternative for modern doc frameworks.",
5
5
  "keywords": [
6
6
  "openpkg",
@@ -55,7 +55,7 @@
55
55
  "test:watch": "bun test --watch"
56
56
  },
57
57
  "dependencies": {
58
- "@openpkg-ts/spec": "workspace:*",
58
+ "@openpkg-ts/spec": "^0.11.1",
59
59
  "commander": "^14.0.0"
60
60
  },
61
61
  "peerDependencies": {