@openpkg-ts/sdk 0.33.0 → 0.34.0
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/README.md +76 -1
- package/dist/browser.d.ts +678 -0
- package/dist/browser.js +56 -0
- package/dist/index.d.ts +159 -67
- package/dist/index.js +320 -539
- package/dist/shared/chunk-91b592v7.js +552 -0
- package/package.json +5 -1
|
@@ -0,0 +1,552 @@
|
|
|
1
|
+
// src/core/query-builder.ts
|
|
2
|
+
class QueryBuilder {
|
|
3
|
+
spec;
|
|
4
|
+
predicates = [];
|
|
5
|
+
constructor(spec) {
|
|
6
|
+
this.spec = spec;
|
|
7
|
+
}
|
|
8
|
+
byKind(...kinds) {
|
|
9
|
+
if (kinds.length > 0) {
|
|
10
|
+
this.predicates.push((exp) => kinds.includes(exp.kind));
|
|
11
|
+
}
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
byName(pattern) {
|
|
15
|
+
if (typeof pattern === "string") {
|
|
16
|
+
this.predicates.push((exp) => exp.name === pattern);
|
|
17
|
+
} else {
|
|
18
|
+
this.predicates.push((exp) => pattern.test(exp.name));
|
|
19
|
+
}
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
byTag(...tags) {
|
|
23
|
+
if (tags.length > 0) {
|
|
24
|
+
this.predicates.push((exp) => {
|
|
25
|
+
const expTags = exp.tags?.map((t) => t.name) ?? [];
|
|
26
|
+
return tags.some((tag) => expTags.includes(tag));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
deprecated(include) {
|
|
32
|
+
if (include !== undefined) {
|
|
33
|
+
this.predicates.push((exp) => (exp.deprecated ?? false) === include);
|
|
34
|
+
}
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
withDescription() {
|
|
38
|
+
this.predicates.push((exp) => Boolean(exp.description?.trim()));
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
search(term) {
|
|
42
|
+
const lower = term.toLowerCase();
|
|
43
|
+
this.predicates.push((exp) => exp.name.toLowerCase().includes(lower) || (exp.description?.toLowerCase().includes(lower) ?? false));
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
where(predicate) {
|
|
47
|
+
this.predicates.push(predicate);
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
byModule(modulePath) {
|
|
51
|
+
this.predicates.push((exp) => exp.source?.file?.includes(modulePath) ?? false);
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
matches(exp) {
|
|
55
|
+
return this.predicates.every((p) => p(exp));
|
|
56
|
+
}
|
|
57
|
+
find() {
|
|
58
|
+
return this.spec.exports.filter((exp) => this.matches(exp));
|
|
59
|
+
}
|
|
60
|
+
first() {
|
|
61
|
+
return this.spec.exports.find((exp) => this.matches(exp));
|
|
62
|
+
}
|
|
63
|
+
count() {
|
|
64
|
+
return this.spec.exports.filter((exp) => this.matches(exp)).length;
|
|
65
|
+
}
|
|
66
|
+
ids() {
|
|
67
|
+
return this.find().map((exp) => exp.id);
|
|
68
|
+
}
|
|
69
|
+
toSpec() {
|
|
70
|
+
return {
|
|
71
|
+
...this.spec,
|
|
72
|
+
exports: this.find(),
|
|
73
|
+
types: this.spec.types ? [...this.spec.types] : undefined
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function query(spec) {
|
|
78
|
+
return new QueryBuilder(spec);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/core/diagnostics.ts
|
|
82
|
+
function hasDeprecatedTag(exp) {
|
|
83
|
+
if (exp.deprecated === true)
|
|
84
|
+
return true;
|
|
85
|
+
return exp.tags?.some((t) => t.name === "deprecated" || t.name === "@deprecated") ?? false;
|
|
86
|
+
}
|
|
87
|
+
function getDeprecationMessage(exp) {
|
|
88
|
+
const tag = exp.tags?.find((t) => t.name === "deprecated" || t.name === "@deprecated");
|
|
89
|
+
if (tag?.text.trim()) {
|
|
90
|
+
return tag.text.trim();
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
function findMissingParamDocs(exp) {
|
|
95
|
+
const missing = [];
|
|
96
|
+
for (const sig of exp.signatures ?? []) {
|
|
97
|
+
for (const param of sig.parameters ?? []) {
|
|
98
|
+
if (!param.description?.trim()) {
|
|
99
|
+
missing.push(param.name);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return missing;
|
|
104
|
+
}
|
|
105
|
+
function checkMemberDescriptions(exp, members) {
|
|
106
|
+
const items = [];
|
|
107
|
+
for (const member of members) {
|
|
108
|
+
if (!member.description?.trim() && member.name) {
|
|
109
|
+
items.push({
|
|
110
|
+
exportId: exp.id,
|
|
111
|
+
exportName: exp.name,
|
|
112
|
+
issue: "member missing description",
|
|
113
|
+
member: member.name
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return items;
|
|
118
|
+
}
|
|
119
|
+
function analyzeSpec(spec) {
|
|
120
|
+
const missingDescriptions = [];
|
|
121
|
+
const deprecatedNoReason = [];
|
|
122
|
+
const missingParamDocs = [];
|
|
123
|
+
for (const exp of spec.exports) {
|
|
124
|
+
if (!exp.description?.trim()) {
|
|
125
|
+
missingDescriptions.push({
|
|
126
|
+
exportId: exp.id,
|
|
127
|
+
exportName: exp.name,
|
|
128
|
+
issue: "missing description"
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (exp.members) {
|
|
132
|
+
missingDescriptions.push(...checkMemberDescriptions(exp, exp.members));
|
|
133
|
+
}
|
|
134
|
+
if (hasDeprecatedTag(exp) && !getDeprecationMessage(exp)) {
|
|
135
|
+
deprecatedNoReason.push({
|
|
136
|
+
exportId: exp.id,
|
|
137
|
+
exportName: exp.name,
|
|
138
|
+
issue: "deprecated without reason"
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
const missingParams = findMissingParamDocs(exp);
|
|
142
|
+
for (const param of missingParams) {
|
|
143
|
+
missingParamDocs.push({
|
|
144
|
+
exportId: exp.id,
|
|
145
|
+
exportName: exp.name,
|
|
146
|
+
issue: "param missing description",
|
|
147
|
+
param
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
missingDescriptions,
|
|
153
|
+
deprecatedNoReason,
|
|
154
|
+
missingParamDocs
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/core/format.ts
|
|
159
|
+
function getMemberBadges(member) {
|
|
160
|
+
const badges = [];
|
|
161
|
+
const visibility = member.visibility ?? "public";
|
|
162
|
+
if (visibility !== "public") {
|
|
163
|
+
badges.push(visibility);
|
|
164
|
+
}
|
|
165
|
+
const flags = member.flags;
|
|
166
|
+
if (flags?.static)
|
|
167
|
+
badges.push("static");
|
|
168
|
+
if (flags?.readonly)
|
|
169
|
+
badges.push("readonly");
|
|
170
|
+
if (flags?.async)
|
|
171
|
+
badges.push("async");
|
|
172
|
+
if (flags?.abstract)
|
|
173
|
+
badges.push("abstract");
|
|
174
|
+
return badges;
|
|
175
|
+
}
|
|
176
|
+
function formatBadges(badges) {
|
|
177
|
+
return badges.join(" ");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/core/query.ts
|
|
181
|
+
function formatFunctionSchema(schema) {
|
|
182
|
+
const sigs = schema["x-ts-signatures"];
|
|
183
|
+
if (!sigs?.length)
|
|
184
|
+
return "(...args: unknown[]) => unknown";
|
|
185
|
+
const sig = sigs[0];
|
|
186
|
+
const params = formatParameters(sig);
|
|
187
|
+
const ret = sig.returns ? formatSchema(sig.returns.schema) : "void";
|
|
188
|
+
return `${params} => ${ret}`;
|
|
189
|
+
}
|
|
190
|
+
function formatSchema(schema, options) {
|
|
191
|
+
if (!schema)
|
|
192
|
+
return "unknown";
|
|
193
|
+
if (typeof schema === "string")
|
|
194
|
+
return schema;
|
|
195
|
+
const withPackage = (typeStr) => {
|
|
196
|
+
if (options?.includePackage && typeof schema === "object" && "x-ts-package" in schema) {
|
|
197
|
+
const pkg = schema["x-ts-package"];
|
|
198
|
+
return `${typeStr} (from ${pkg})`;
|
|
199
|
+
}
|
|
200
|
+
return typeStr;
|
|
201
|
+
};
|
|
202
|
+
if (typeof schema === "object" && schema !== null) {
|
|
203
|
+
if ("x-ts-type" in schema && typeof schema["x-ts-type"] === "string") {
|
|
204
|
+
const tsType = schema["x-ts-type"];
|
|
205
|
+
if (tsType === "function" || schema["x-ts-function"]) {
|
|
206
|
+
return withPackage(formatFunctionSchema(schema));
|
|
207
|
+
}
|
|
208
|
+
return withPackage(tsType);
|
|
209
|
+
}
|
|
210
|
+
if ("x-ts-function" in schema && schema["x-ts-function"]) {
|
|
211
|
+
return withPackage(formatFunctionSchema(schema));
|
|
212
|
+
}
|
|
213
|
+
if ("x-ts-type-predicate" in schema) {
|
|
214
|
+
const pred = schema["x-ts-type-predicate"];
|
|
215
|
+
return `${pred.parameterName} is ${formatSchema(pred.type, options)}`;
|
|
216
|
+
}
|
|
217
|
+
if ("$ref" in schema && typeof schema.$ref === "string") {
|
|
218
|
+
const baseName = schema.$ref.replace("#/types/", "");
|
|
219
|
+
if ("x-ts-type-arguments" in schema && Array.isArray(schema["x-ts-type-arguments"])) {
|
|
220
|
+
const args = schema["x-ts-type-arguments"].map((s) => formatSchema(s, options)).join(", ");
|
|
221
|
+
return withPackage(`${baseName}<${args}>`);
|
|
222
|
+
}
|
|
223
|
+
return withPackage(baseName);
|
|
224
|
+
}
|
|
225
|
+
if ("anyOf" in schema && Array.isArray(schema.anyOf)) {
|
|
226
|
+
const threshold = options?.collapseUnionThreshold;
|
|
227
|
+
const members = schema.anyOf;
|
|
228
|
+
if (threshold && members.length > threshold) {
|
|
229
|
+
const shown = members.slice(0, 3);
|
|
230
|
+
const remaining = members.length - 3;
|
|
231
|
+
const shownStr = shown.map((s) => formatSchema(s, options)).join(" | ");
|
|
232
|
+
return `${shownStr} | ... (${remaining} more)`;
|
|
233
|
+
}
|
|
234
|
+
return members.map((s) => formatSchema(s, options)).join(" | ");
|
|
235
|
+
}
|
|
236
|
+
if ("allOf" in schema && Array.isArray(schema.allOf)) {
|
|
237
|
+
return schema.allOf.map((s) => formatSchema(s, options)).join(" & ");
|
|
238
|
+
}
|
|
239
|
+
if ("type" in schema && schema.type === "array") {
|
|
240
|
+
const items = "items" in schema ? formatSchema(schema.items, options) : "unknown";
|
|
241
|
+
return `${items}[]`;
|
|
242
|
+
}
|
|
243
|
+
if ("type" in schema && schema.type === "tuple" && "items" in schema) {
|
|
244
|
+
const items = schema.items.map((s) => formatSchema(s, options)).join(", ");
|
|
245
|
+
return `[${items}]`;
|
|
246
|
+
}
|
|
247
|
+
if ("type" in schema && schema.type === "object") {
|
|
248
|
+
if ("properties" in schema && schema.properties) {
|
|
249
|
+
const props = Object.entries(schema.properties).map(([k, v]) => `${k}: ${formatSchema(v, options)}`).join("; ");
|
|
250
|
+
return `{ ${props} }`;
|
|
251
|
+
}
|
|
252
|
+
return "object";
|
|
253
|
+
}
|
|
254
|
+
if ("type" in schema && typeof schema.type === "string") {
|
|
255
|
+
return withPackage(schema.type);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return "unknown";
|
|
259
|
+
}
|
|
260
|
+
function formatTypeParameters(typeParams) {
|
|
261
|
+
if (!typeParams?.length)
|
|
262
|
+
return "";
|
|
263
|
+
const params = typeParams.map((tp) => {
|
|
264
|
+
let str = "";
|
|
265
|
+
if ("const" in tp && tp.const)
|
|
266
|
+
str += "const ";
|
|
267
|
+
if (tp.variance === "in")
|
|
268
|
+
str += "in ";
|
|
269
|
+
else if (tp.variance === "out")
|
|
270
|
+
str += "out ";
|
|
271
|
+
else if (tp.variance === "inout")
|
|
272
|
+
str += "in out ";
|
|
273
|
+
str += tp.name;
|
|
274
|
+
if (tp.constraint)
|
|
275
|
+
str += ` extends ${tp.constraint}`;
|
|
276
|
+
if (tp.default)
|
|
277
|
+
str += ` = ${tp.default}`;
|
|
278
|
+
return str;
|
|
279
|
+
});
|
|
280
|
+
return `<${params.join(", ")}>`;
|
|
281
|
+
}
|
|
282
|
+
function formatParameters(sig) {
|
|
283
|
+
if (!sig?.parameters?.length)
|
|
284
|
+
return "()";
|
|
285
|
+
const params = sig.parameters.map((p) => {
|
|
286
|
+
const optional = p.required === false ? "?" : "";
|
|
287
|
+
const rest = p.rest ? "..." : "";
|
|
288
|
+
const type = formatSchema(p.schema);
|
|
289
|
+
return `${rest}${p.name}${optional}: ${type}`;
|
|
290
|
+
});
|
|
291
|
+
return `(${params.join(", ")})`;
|
|
292
|
+
}
|
|
293
|
+
function formatReturnType(sig) {
|
|
294
|
+
if (!sig?.returns)
|
|
295
|
+
return "void";
|
|
296
|
+
return formatSchema(sig.returns.schema);
|
|
297
|
+
}
|
|
298
|
+
function buildSignatureString(exp, sigIndex = 0) {
|
|
299
|
+
const sig = exp.signatures?.[sigIndex];
|
|
300
|
+
const typeParams = formatTypeParameters(exp.typeParameters || sig?.typeParameters);
|
|
301
|
+
switch (exp.kind) {
|
|
302
|
+
case "function": {
|
|
303
|
+
const params = formatParameters(sig);
|
|
304
|
+
const returnType = formatReturnType(sig);
|
|
305
|
+
return `function ${exp.name}${typeParams}${params}: ${returnType}`;
|
|
306
|
+
}
|
|
307
|
+
case "class": {
|
|
308
|
+
const ext = exp.extends ? ` extends ${exp.extends}` : "";
|
|
309
|
+
const impl = exp.implements?.length ? ` implements ${exp.implements.join(", ")}` : "";
|
|
310
|
+
return `class ${exp.name}${typeParams}${ext}${impl}`;
|
|
311
|
+
}
|
|
312
|
+
case "interface": {
|
|
313
|
+
const ext = exp.extends ? ` extends ${exp.extends}` : "";
|
|
314
|
+
return `interface ${exp.name}${typeParams}${ext}`;
|
|
315
|
+
}
|
|
316
|
+
case "type": {
|
|
317
|
+
const typeValue = typeof exp.type === "string" ? exp.type : formatSchema(exp.schema);
|
|
318
|
+
return `type ${exp.name}${typeParams} = ${typeValue}`;
|
|
319
|
+
}
|
|
320
|
+
case "enum": {
|
|
321
|
+
return `enum ${exp.name}`;
|
|
322
|
+
}
|
|
323
|
+
case "variable": {
|
|
324
|
+
const typeValue = typeof exp.type === "string" ? exp.type : formatSchema(exp.schema);
|
|
325
|
+
return `const ${exp.name}: ${typeValue}`;
|
|
326
|
+
}
|
|
327
|
+
default:
|
|
328
|
+
return exp.name;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
function resolveTypeRef(ref, spec) {
|
|
332
|
+
const id = ref.replace("#/types/", "");
|
|
333
|
+
return spec.types?.find((t) => t.id === id);
|
|
334
|
+
}
|
|
335
|
+
function isMethod(member) {
|
|
336
|
+
return !!member.signatures?.length;
|
|
337
|
+
}
|
|
338
|
+
function isProperty(member) {
|
|
339
|
+
return !member.signatures?.length;
|
|
340
|
+
}
|
|
341
|
+
function getMethods(members) {
|
|
342
|
+
return members?.filter(isMethod) ?? [];
|
|
343
|
+
}
|
|
344
|
+
function getProperties(members) {
|
|
345
|
+
return members?.filter(isProperty) ?? [];
|
|
346
|
+
}
|
|
347
|
+
function groupByVisibility(members) {
|
|
348
|
+
const groups = {
|
|
349
|
+
public: [],
|
|
350
|
+
protected: [],
|
|
351
|
+
private: []
|
|
352
|
+
};
|
|
353
|
+
for (const member of members ?? []) {
|
|
354
|
+
const visibility = member.visibility ?? "public";
|
|
355
|
+
groups[visibility].push(member);
|
|
356
|
+
}
|
|
357
|
+
return groups;
|
|
358
|
+
}
|
|
359
|
+
function sortByName(items) {
|
|
360
|
+
return [...items].sort((a, b) => a.name.localeCompare(b.name));
|
|
361
|
+
}
|
|
362
|
+
function formatConditionalType(condType) {
|
|
363
|
+
const check = formatSchema(condType.checkType);
|
|
364
|
+
const ext = formatSchema(condType.extendsType);
|
|
365
|
+
const trueT = formatSchema(condType.trueType);
|
|
366
|
+
const falseT = formatSchema(condType.falseType);
|
|
367
|
+
return `${check} extends ${ext} ? ${trueT} : ${falseT}`;
|
|
368
|
+
}
|
|
369
|
+
function formatMappedType(mappedType) {
|
|
370
|
+
const keyStr = formatSchema(mappedType.keyType);
|
|
371
|
+
const valueStr = formatSchema(mappedType.valueType);
|
|
372
|
+
let readonlyMod = "";
|
|
373
|
+
if (mappedType.readonly === true || mappedType.readonly === "add") {
|
|
374
|
+
readonlyMod = "readonly ";
|
|
375
|
+
} else if (mappedType.readonly === "remove") {
|
|
376
|
+
readonlyMod = "-readonly ";
|
|
377
|
+
}
|
|
378
|
+
let optionalMod = "";
|
|
379
|
+
if (mappedType.optional === true || mappedType.optional === "add") {
|
|
380
|
+
optionalMod = "?";
|
|
381
|
+
} else if (mappedType.optional === "remove") {
|
|
382
|
+
optionalMod = "-?";
|
|
383
|
+
}
|
|
384
|
+
return `{ ${readonlyMod}[${keyStr}]${optionalMod}: ${valueStr} }`;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// src/core/search.ts
|
|
388
|
+
var defaultSlugify = (name) => name.toLowerCase().replace(/[^a-z0-9]+/g, "-");
|
|
389
|
+
function extractKeywords(exp, options = {}) {
|
|
390
|
+
const keywords = new Set;
|
|
391
|
+
keywords.add(exp.name);
|
|
392
|
+
keywords.add(exp.name.toLowerCase());
|
|
393
|
+
const camelParts = exp.name.split(/(?=[A-Z])/);
|
|
394
|
+
for (const part of camelParts) {
|
|
395
|
+
if (part.length > 2)
|
|
396
|
+
keywords.add(part.toLowerCase());
|
|
397
|
+
}
|
|
398
|
+
if (exp.tags) {
|
|
399
|
+
for (const tag of exp.tags) {
|
|
400
|
+
keywords.add(tag.name.replace("@", ""));
|
|
401
|
+
const tagWords = tag.text.split(/\s+/);
|
|
402
|
+
for (const word of tagWords) {
|
|
403
|
+
if (word.length > 2)
|
|
404
|
+
keywords.add(word.toLowerCase());
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
if (exp.description) {
|
|
409
|
+
const descWords = exp.description.toLowerCase().split(/\W+/).filter((w) => w.length > 2);
|
|
410
|
+
for (const word of descWords) {
|
|
411
|
+
keywords.add(word);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
if (options.includeMembers && exp.members) {
|
|
415
|
+
for (const member of exp.members) {
|
|
416
|
+
if (member.name) {
|
|
417
|
+
keywords.add(member.name.toLowerCase());
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
if (options.includeParameters && exp.signatures) {
|
|
422
|
+
for (const sig of exp.signatures) {
|
|
423
|
+
for (const param of sig.parameters || []) {
|
|
424
|
+
keywords.add(param.name.toLowerCase());
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return Array.from(keywords);
|
|
429
|
+
}
|
|
430
|
+
function buildContent(exp, options = {}) {
|
|
431
|
+
const parts = [];
|
|
432
|
+
parts.push(exp.name);
|
|
433
|
+
if (exp.description) {
|
|
434
|
+
parts.push(exp.description);
|
|
435
|
+
}
|
|
436
|
+
if (options.includeSignatures !== false) {
|
|
437
|
+
parts.push(buildSignatureString(exp));
|
|
438
|
+
}
|
|
439
|
+
if (exp.tags) {
|
|
440
|
+
parts.push(...exp.tags.map((t) => `${t.name} ${t.text}`));
|
|
441
|
+
}
|
|
442
|
+
if (options.includeMembers !== false && exp.members) {
|
|
443
|
+
const props = getProperties(exp.members);
|
|
444
|
+
const methods = getMethods(exp.members);
|
|
445
|
+
for (const prop of props) {
|
|
446
|
+
if (prop.name) {
|
|
447
|
+
parts.push(prop.name);
|
|
448
|
+
if (prop.description)
|
|
449
|
+
parts.push(prop.description);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
for (const method of methods) {
|
|
453
|
+
if (method.name) {
|
|
454
|
+
parts.push(method.name);
|
|
455
|
+
if (method.description)
|
|
456
|
+
parts.push(method.description);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
if (options.includeParameters !== false && exp.signatures) {
|
|
461
|
+
for (const sig of exp.signatures) {
|
|
462
|
+
for (const param of sig.parameters || []) {
|
|
463
|
+
parts.push(param.name);
|
|
464
|
+
if (param.description)
|
|
465
|
+
parts.push(param.description);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return parts.join(" ");
|
|
470
|
+
}
|
|
471
|
+
function createSearchRecord(exp, _packageName, options = {}) {
|
|
472
|
+
const { baseUrl = "/api", slugify = defaultSlugify } = options;
|
|
473
|
+
return {
|
|
474
|
+
id: exp.id,
|
|
475
|
+
name: exp.name,
|
|
476
|
+
kind: exp.kind,
|
|
477
|
+
signature: buildSignatureString(exp),
|
|
478
|
+
description: exp.description,
|
|
479
|
+
content: buildContent(exp, options),
|
|
480
|
+
keywords: extractKeywords(exp, options),
|
|
481
|
+
url: `${baseUrl}/${slugify(exp.name)}`,
|
|
482
|
+
deprecated: exp.deprecated === true
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
function toSearchIndex(spec, options = {}) {
|
|
486
|
+
const records = spec.exports.map((exp) => createSearchRecord(exp, spec.meta.name, options));
|
|
487
|
+
return {
|
|
488
|
+
records,
|
|
489
|
+
version: spec.meta.version || "0.0.0",
|
|
490
|
+
generatedAt: new Date().toISOString(),
|
|
491
|
+
packageName: spec.meta.name
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
function toPagefindRecords(spec, options = {}) {
|
|
495
|
+
const { baseUrl = "/api", slugify = defaultSlugify, weights = {} } = options;
|
|
496
|
+
const { name: nameWeight = 10, description: descWeight = 5, signature: sigWeight = 3 } = weights;
|
|
497
|
+
return spec.exports.map((exp) => {
|
|
498
|
+
const content = buildContent(exp, options);
|
|
499
|
+
const signature = buildSignatureString(exp);
|
|
500
|
+
const filters = {
|
|
501
|
+
kind: [exp.kind]
|
|
502
|
+
};
|
|
503
|
+
if (exp.deprecated) {
|
|
504
|
+
filters.deprecated = ["true"];
|
|
505
|
+
}
|
|
506
|
+
if (exp.tags?.length) {
|
|
507
|
+
filters.tags = exp.tags.map((t) => t.name.replace("@", ""));
|
|
508
|
+
}
|
|
509
|
+
return {
|
|
510
|
+
url: `${baseUrl}/${slugify(exp.name)}`,
|
|
511
|
+
content,
|
|
512
|
+
word_count: content.split(/\s+/).length,
|
|
513
|
+
filters,
|
|
514
|
+
meta: {
|
|
515
|
+
title: exp.name,
|
|
516
|
+
kind: exp.kind,
|
|
517
|
+
description: exp.description?.slice(0, 160),
|
|
518
|
+
signature
|
|
519
|
+
},
|
|
520
|
+
weighted_sections: [
|
|
521
|
+
{ weight: nameWeight, text: exp.name },
|
|
522
|
+
...exp.description ? [{ weight: descWeight, text: exp.description }] : [],
|
|
523
|
+
{ weight: sigWeight, text: signature }
|
|
524
|
+
]
|
|
525
|
+
};
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
function toAlgoliaRecords(spec, options = {}) {
|
|
529
|
+
const { baseUrl = "/api", slugify = defaultSlugify } = options;
|
|
530
|
+
return spec.exports.map((exp) => ({
|
|
531
|
+
objectID: exp.id,
|
|
532
|
+
name: exp.name,
|
|
533
|
+
kind: exp.kind,
|
|
534
|
+
description: exp.description,
|
|
535
|
+
signature: buildSignatureString(exp),
|
|
536
|
+
content: buildContent(exp, options),
|
|
537
|
+
tags: (exp.tags || []).map((t) => t.name.replace("@", "")),
|
|
538
|
+
deprecated: exp.deprecated === true,
|
|
539
|
+
url: `${baseUrl}/${slugify(exp.name)}`,
|
|
540
|
+
hierarchy: {
|
|
541
|
+
lvl0: spec.meta.name,
|
|
542
|
+
lvl1: `${exp.kind.charAt(0).toUpperCase() + exp.kind.slice(1)}s`,
|
|
543
|
+
lvl2: exp.name
|
|
544
|
+
}
|
|
545
|
+
}));
|
|
546
|
+
}
|
|
547
|
+
function toSearchIndexJSON(spec, options = {}) {
|
|
548
|
+
const index = toSearchIndex(spec, options);
|
|
549
|
+
return options.pretty ? JSON.stringify(index, null, 2) : JSON.stringify(index);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
export { QueryBuilder, query, hasDeprecatedTag, getDeprecationMessage, findMissingParamDocs, analyzeSpec, getMemberBadges, formatBadges, formatSchema, formatTypeParameters, formatParameters, formatReturnType, buildSignatureString, resolveTypeRef, isMethod, isProperty, getMethods, getProperties, groupByVisibility, sortByName, formatConditionalType, formatMappedType, toSearchIndex, toPagefindRecords, toAlgoliaRecords, toSearchIndexJSON };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpkg-ts/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"description": "TypeScript API extraction SDK - programmatic primitives for OpenPkg specs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openpkg",
|
|
@@ -24,6 +24,10 @@
|
|
|
24
24
|
".": {
|
|
25
25
|
"import": "./dist/index.js",
|
|
26
26
|
"types": "./dist/index.d.ts"
|
|
27
|
+
},
|
|
28
|
+
"./browser": {
|
|
29
|
+
"import": "./dist/browser.js",
|
|
30
|
+
"types": "./dist/browser.d.ts"
|
|
27
31
|
}
|
|
28
32
|
},
|
|
29
33
|
"files": [
|