@ir-kit/fn-schema-typescript 0.1.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/LICENSE.md +21 -0
- package/README.md +85 -0
- package/dist/aliases.d.ts +37 -0
- package/dist/aliases.d.ts.map +1 -0
- package/dist/aliases.js +468 -0
- package/dist/aliases.js.map +1 -0
- package/dist/discover.d.ts +24 -0
- package/dist/discover.d.ts.map +1 -0
- package/dist/discover.js +284 -0
- package/dist/discover.js.map +1 -0
- package/dist/extractor.d.ts +9 -0
- package/dist/extractor.d.ts.map +1 -0
- package/dist/extractor.js +94 -0
- package/dist/extractor.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/jsdoc.d.ts +4 -0
- package/dist/jsdoc.d.ts.map +1 -0
- package/dist/jsdoc.js +22 -0
- package/dist/jsdoc.js.map +1 -0
- package/dist/schema.d.ts +17 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +344 -0
- package/dist/schema.js.map +1 -0
- package/dist/well-known.d.ts +17 -0
- package/dist/well-known.d.ts.map +1 -0
- package/dist/well-known.js +50 -0
- package/dist/well-known.js.map +1 -0
- package/package.json +68 -0
package/dist/discover.js
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { Node, } from "ts-morph";
|
|
2
|
+
import { resolveTypeExpression } from "./aliases.js";
|
|
3
|
+
import { parseJsDoc } from "./jsdoc.js";
|
|
4
|
+
export function discoverFunctions(project, files, virtualDirFor) {
|
|
5
|
+
const acc = [];
|
|
6
|
+
for (const filePath of files) {
|
|
7
|
+
const sf = project.getSourceFile(filePath);
|
|
8
|
+
if (!sf)
|
|
9
|
+
continue;
|
|
10
|
+
acc.push(...discoverInFile(sf, virtualDirFor));
|
|
11
|
+
}
|
|
12
|
+
return acc;
|
|
13
|
+
}
|
|
14
|
+
function discoverInFile(sf, virtualDirFor) {
|
|
15
|
+
const out = [];
|
|
16
|
+
const filePath = sf.getFilePath();
|
|
17
|
+
const virtualDir = virtualDirFor(filePath);
|
|
18
|
+
for (const fd of sf.getFunctions()) {
|
|
19
|
+
const info = describeFunctionDeclaration(fd, filePath, sf, virtualDir);
|
|
20
|
+
if (info)
|
|
21
|
+
out.push(info);
|
|
22
|
+
}
|
|
23
|
+
for (const vd of sf.getVariableDeclarations()) {
|
|
24
|
+
const info = describeVariableDeclaration(vd, filePath, sf, virtualDir);
|
|
25
|
+
if (info) {
|
|
26
|
+
out.push(info);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
out.push(...describeObjectLiteralMembers(vd, filePath, sf, virtualDir));
|
|
30
|
+
}
|
|
31
|
+
for (const cls of sf.getClasses()) {
|
|
32
|
+
const className = cls.getName() ?? "";
|
|
33
|
+
const exported = cls.isExported() || cls.isDefaultExport();
|
|
34
|
+
for (const m of cls.getMethods()) {
|
|
35
|
+
const info = describeMethod(m, filePath, className, exported, sf, virtualDir);
|
|
36
|
+
if (info)
|
|
37
|
+
out.push(info);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
for (const ea of sf.getExportAssignments()) {
|
|
41
|
+
const info = describeExportAssignment(ea, filePath, sf, virtualDir);
|
|
42
|
+
if (info)
|
|
43
|
+
out.push(info);
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
function describeFunctionDeclaration(fd, filePath, sf, virtualDir) {
|
|
48
|
+
const name = fd.getName();
|
|
49
|
+
if (!name)
|
|
50
|
+
return null;
|
|
51
|
+
const exported = fd.isExported() || fd.isDefaultExport();
|
|
52
|
+
const overloadDecls = collectFunctionOverloads(fd);
|
|
53
|
+
const overloads = overloadDecls.map((decl) => describeSignature(decl, sf, virtualDir));
|
|
54
|
+
const impl = overloads[overloads.length - 1];
|
|
55
|
+
if (!impl)
|
|
56
|
+
return null;
|
|
57
|
+
return {
|
|
58
|
+
name,
|
|
59
|
+
file: filePath,
|
|
60
|
+
location: positionOf(fd),
|
|
61
|
+
kind: "function",
|
|
62
|
+
language: "typescript",
|
|
63
|
+
exported,
|
|
64
|
+
async: fd.isAsync(),
|
|
65
|
+
generic: hasUnresolvedGenerics(fd.getTypeParameters().length, overloads),
|
|
66
|
+
parameters: impl.parameters.map(stripAlias),
|
|
67
|
+
jsDoc: parseJsDoc(fd.getJsDocs()),
|
|
68
|
+
sourceFilePath: filePath,
|
|
69
|
+
importable: exported,
|
|
70
|
+
resolvedParameters: impl.parameters,
|
|
71
|
+
returnAlias: impl.returnAlias,
|
|
72
|
+
overloads,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function describeVariableDeclaration(vd, filePath, sf, virtualDir) {
|
|
76
|
+
const init = vd.getInitializer();
|
|
77
|
+
if (!init)
|
|
78
|
+
return null;
|
|
79
|
+
if (!Node.isArrowFunction(init) && !Node.isFunctionExpression(init))
|
|
80
|
+
return null;
|
|
81
|
+
const stmt = vd.getVariableStatement();
|
|
82
|
+
const exported = stmt?.isExported() ?? false;
|
|
83
|
+
const name = vd.getName();
|
|
84
|
+
const fn = init;
|
|
85
|
+
const kind = Node.isArrowFunction(init)
|
|
86
|
+
? "arrow"
|
|
87
|
+
: "expression";
|
|
88
|
+
const sig = describeSignature(fn, sf, virtualDir);
|
|
89
|
+
return {
|
|
90
|
+
name,
|
|
91
|
+
file: filePath,
|
|
92
|
+
location: positionOf(vd),
|
|
93
|
+
kind,
|
|
94
|
+
language: "typescript",
|
|
95
|
+
exported,
|
|
96
|
+
async: fn.isAsync(),
|
|
97
|
+
generic: hasUnresolvedGenerics(fn.getTypeParameters().length, [sig]),
|
|
98
|
+
parameters: sig.parameters.map(stripAlias),
|
|
99
|
+
jsDoc: parseJsDoc(stmt?.getJsDocs() ?? []),
|
|
100
|
+
sourceFilePath: filePath,
|
|
101
|
+
importable: exported,
|
|
102
|
+
resolvedParameters: sig.parameters,
|
|
103
|
+
returnAlias: sig.returnAlias,
|
|
104
|
+
overloads: [sig],
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function describeObjectLiteralMembers(vd, filePath, sf, virtualDir) {
|
|
108
|
+
const init = vd.getInitializer();
|
|
109
|
+
if (!init || !Node.isObjectLiteralExpression(init))
|
|
110
|
+
return [];
|
|
111
|
+
const stmt = vd.getVariableStatement();
|
|
112
|
+
const exported = stmt?.isExported() ?? false;
|
|
113
|
+
const containerName = vd.getName();
|
|
114
|
+
const out = [];
|
|
115
|
+
const obj = init;
|
|
116
|
+
for (const prop of obj.getProperties()) {
|
|
117
|
+
if (Node.isMethodDeclaration(prop)) {
|
|
118
|
+
const memberName = prop.getName();
|
|
119
|
+
const sig = describeSignature(prop, sf, virtualDir);
|
|
120
|
+
out.push({
|
|
121
|
+
name: memberName,
|
|
122
|
+
file: filePath,
|
|
123
|
+
location: positionOf(prop),
|
|
124
|
+
kind: "method",
|
|
125
|
+
language: "typescript",
|
|
126
|
+
exported,
|
|
127
|
+
async: prop.isAsync(),
|
|
128
|
+
generic: prop.getTypeParameters().length > 0,
|
|
129
|
+
parameters: sig.parameters.map(stripAlias),
|
|
130
|
+
jsDoc: parseJsDoc(prop.getJsDocs()),
|
|
131
|
+
className: containerName,
|
|
132
|
+
sourceFilePath: filePath,
|
|
133
|
+
importable: exported,
|
|
134
|
+
resolvedParameters: sig.parameters,
|
|
135
|
+
returnAlias: sig.returnAlias,
|
|
136
|
+
overloads: [sig],
|
|
137
|
+
});
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (Node.isPropertyAssignment(prop)) {
|
|
141
|
+
const memberInit = prop.getInitializer();
|
|
142
|
+
if (!memberInit ||
|
|
143
|
+
(!Node.isArrowFunction(memberInit) &&
|
|
144
|
+
!Node.isFunctionExpression(memberInit)))
|
|
145
|
+
continue;
|
|
146
|
+
const fn = memberInit;
|
|
147
|
+
const sig = describeSignature(fn, sf, virtualDir);
|
|
148
|
+
const memberName = prop.getName();
|
|
149
|
+
out.push({
|
|
150
|
+
name: memberName,
|
|
151
|
+
file: filePath,
|
|
152
|
+
location: positionOf(prop),
|
|
153
|
+
kind: Node.isArrowFunction(memberInit) ? "arrow" : "expression",
|
|
154
|
+
language: "typescript",
|
|
155
|
+
exported,
|
|
156
|
+
async: fn.isAsync(),
|
|
157
|
+
generic: fn.getTypeParameters().length > 0,
|
|
158
|
+
parameters: sig.parameters.map(stripAlias),
|
|
159
|
+
jsDoc: undefined,
|
|
160
|
+
className: containerName,
|
|
161
|
+
sourceFilePath: filePath,
|
|
162
|
+
importable: exported,
|
|
163
|
+
resolvedParameters: sig.parameters,
|
|
164
|
+
returnAlias: sig.returnAlias,
|
|
165
|
+
overloads: [sig],
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
function describeMethod(m, filePath, className, classExported, sf, virtualDir) {
|
|
172
|
+
const name = m.getName();
|
|
173
|
+
if (!name)
|
|
174
|
+
return null;
|
|
175
|
+
if (m.isAbstract())
|
|
176
|
+
return null;
|
|
177
|
+
const overloadDecls = collectMethodOverloads(m);
|
|
178
|
+
const overloads = overloadDecls.map((decl) => describeSignature(decl, sf, virtualDir));
|
|
179
|
+
const impl = overloads[overloads.length - 1];
|
|
180
|
+
if (!impl)
|
|
181
|
+
return null;
|
|
182
|
+
return {
|
|
183
|
+
name,
|
|
184
|
+
file: filePath,
|
|
185
|
+
location: positionOf(m),
|
|
186
|
+
kind: "method",
|
|
187
|
+
language: "typescript",
|
|
188
|
+
exported: classExported,
|
|
189
|
+
async: m.isAsync(),
|
|
190
|
+
generic: hasUnresolvedGenerics(m.getTypeParameters().length, overloads),
|
|
191
|
+
parameters: impl.parameters.map(stripAlias),
|
|
192
|
+
jsDoc: parseJsDoc(m.getJsDocs()),
|
|
193
|
+
className,
|
|
194
|
+
decorators: m.getDecorators().map((d) => d.getName()),
|
|
195
|
+
sourceFilePath: filePath,
|
|
196
|
+
importable: classExported,
|
|
197
|
+
resolvedParameters: impl.parameters,
|
|
198
|
+
returnAlias: impl.returnAlias,
|
|
199
|
+
overloads,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function describeExportAssignment(ea, filePath, sf, virtualDir) {
|
|
203
|
+
if (ea.isExportEquals())
|
|
204
|
+
return null;
|
|
205
|
+
const expr = ea.getExpression();
|
|
206
|
+
if (!Node.isArrowFunction(expr) && !Node.isFunctionExpression(expr))
|
|
207
|
+
return null;
|
|
208
|
+
const fn = expr;
|
|
209
|
+
const sig = describeSignature(fn, sf, virtualDir);
|
|
210
|
+
const kind = Node.isArrowFunction(expr)
|
|
211
|
+
? "arrow"
|
|
212
|
+
: "expression";
|
|
213
|
+
return {
|
|
214
|
+
name: "default",
|
|
215
|
+
file: filePath,
|
|
216
|
+
location: positionOf(ea),
|
|
217
|
+
kind,
|
|
218
|
+
language: "typescript",
|
|
219
|
+
exported: true,
|
|
220
|
+
async: fn.isAsync(),
|
|
221
|
+
generic: hasUnresolvedGenerics(fn.getTypeParameters().length, [sig]),
|
|
222
|
+
parameters: sig.parameters.map(stripAlias),
|
|
223
|
+
jsDoc: parseJsDoc(ea.getJsDocs()),
|
|
224
|
+
sourceFilePath: filePath,
|
|
225
|
+
importable: true,
|
|
226
|
+
resolvedParameters: sig.parameters,
|
|
227
|
+
returnAlias: sig.returnAlias,
|
|
228
|
+
overloads: [sig],
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function describeSignature(node, hostFile, virtualDir) {
|
|
232
|
+
const params = node.getParameters();
|
|
233
|
+
const resolved = [];
|
|
234
|
+
for (let i = 0; i < params.length; i++) {
|
|
235
|
+
const p = params[i];
|
|
236
|
+
// `this` is a TS-only narrowing parameter, not a real arg.
|
|
237
|
+
if (i === 0 && p.getName() === "this")
|
|
238
|
+
continue;
|
|
239
|
+
resolved.push(resolveParameter(p, resolved.length, hostFile, virtualDir));
|
|
240
|
+
}
|
|
241
|
+
const returnAlias = resolveTypeExpression(node, node.getReturnType(), hostFile, virtualDir, node.getReturnTypeNode());
|
|
242
|
+
return { parameters: resolved, returnAlias };
|
|
243
|
+
}
|
|
244
|
+
function resolveParameter(p, index, hostFile, virtualDir) {
|
|
245
|
+
const alias = resolveTypeExpression(p, p.getType(), hostFile, virtualDir, p.getTypeNode());
|
|
246
|
+
return {
|
|
247
|
+
name: p.getName(),
|
|
248
|
+
index,
|
|
249
|
+
optional: p.isOptional() || p.hasInitializer(),
|
|
250
|
+
rest: p.isRestParameter(),
|
|
251
|
+
typeText: p.getTypeNode()?.getText(),
|
|
252
|
+
alias,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function stripAlias(p) {
|
|
256
|
+
const { alias: _drop, ...rest } = p;
|
|
257
|
+
return rest;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Methods on generic classes (`class Box<T> { get(): T }`) declare zero
|
|
261
|
+
* type parameters at the method level but `T` still escapes into the
|
|
262
|
+
* resolved signature; treat them as generic so the skip path triggers.
|
|
263
|
+
*/
|
|
264
|
+
function hasUnresolvedGenerics(declaredTypeParamCount, overloads) {
|
|
265
|
+
if (declaredTypeParamCount > 0)
|
|
266
|
+
return true;
|
|
267
|
+
return overloads.some((o) => o.returnAlias.hasUnresolvedGenerics ||
|
|
268
|
+
o.parameters.some((p) => p.alias.hasUnresolvedGenerics));
|
|
269
|
+
}
|
|
270
|
+
function collectFunctionOverloads(impl) {
|
|
271
|
+
const overloads = impl.getOverloads();
|
|
272
|
+
return [...overloads, impl];
|
|
273
|
+
}
|
|
274
|
+
function collectMethodOverloads(impl) {
|
|
275
|
+
const overloads = impl.getOverloads();
|
|
276
|
+
return [...overloads, impl];
|
|
277
|
+
}
|
|
278
|
+
function positionOf(node) {
|
|
279
|
+
const sf = node.getSourceFile();
|
|
280
|
+
const pos = node.getStart();
|
|
281
|
+
const { line, column } = sf.getLineAndColumnAtPos(pos);
|
|
282
|
+
return { line, column };
|
|
283
|
+
}
|
|
284
|
+
//# sourceMappingURL=discover.js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AAC;IACpC,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,SAAS,qBAAqB,CAC5B,sBAA8B,EAC9B,SAA8B;IAE9B,IAAI,sBAAsB,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5C,OAAO,SAAS,CAAC,IAAI,CACnB,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,WAAW,CAAC,qBAAqB;QACnC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAC1D,CAAC;AACJ,CAAC;AAED,SAAS,wBAAwB,CAC/B,IAAyB;IAEzB,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;IACtC,OAAO,CAAC,GAAG,SAAS,EAAE,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAuB;IACrD,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;IACtC,OAAO,CAAC,GAAG,SAAS,EAAE,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,UAAU,CAAC,IAAU;IAC5B,MAAM,EAAE,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;IAChC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC5B,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC;IACvD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Extractor } from "@ir-kit/fn-schema-core";
|
|
2
|
+
export interface TypescriptExtractorOptions {
|
|
3
|
+
/** Path to tsconfig.json. Default: nearest tsconfig from cwd. */
|
|
4
|
+
tsConfigPath?: string;
|
|
5
|
+
/** Override compiler options (merged on top of tsconfig). */
|
|
6
|
+
compilerOptions?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
export declare function typescript(options?: TypescriptExtractorOptions): Extractor;
|
|
9
|
+
//# sourceMappingURL=extractor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractor.d.ts","sourceRoot":"","sources":["../src/extractor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EAQV,MAAM,wBAAwB,CAAC;AAOhC,MAAM,WAAW,0BAA0B;IACzC,iEAAiE;IACjE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6DAA6D;IAC7D,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC3C;AAED,wBAAgB,UAAU,CACxB,OAAO,GAAE,0BAA+B,GACvC,SAAS,CAyDX"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Project as TsMorphProject } from "ts-morph";
|
|
2
|
+
import { discoverFunctions } from "./discover.js";
|
|
3
|
+
import { buildSchemas, SignatureSkipped, virtualDirFor } from "./schema.js";
|
|
4
|
+
const TS_EXTENSIONS = [".ts", ".tsx", ".mts", ".cts"];
|
|
5
|
+
export function typescript(options = {}) {
|
|
6
|
+
return {
|
|
7
|
+
extensions: TS_EXTENSIONS,
|
|
8
|
+
language: "typescript",
|
|
9
|
+
async init(initOpts) {
|
|
10
|
+
const project = createTsMorphProject(options, initOpts);
|
|
11
|
+
return {
|
|
12
|
+
async discover(files, _filter) {
|
|
13
|
+
ensureFilesLoaded(project, files);
|
|
14
|
+
return discoverFunctions(project, files, virtualDirFor);
|
|
15
|
+
},
|
|
16
|
+
async toSchemas(fn, opts) {
|
|
17
|
+
const discovered = fn;
|
|
18
|
+
if (!discovered.sourceFilePath ||
|
|
19
|
+
!discovered.resolvedParameters ||
|
|
20
|
+
!discovered.returnAlias) {
|
|
21
|
+
throw new Error("fn-schema-typescript: received a FunctionInfo not produced by this extractor");
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
return buildSchemas(discovered, {
|
|
25
|
+
project,
|
|
26
|
+
signature: pickSignature(opts),
|
|
27
|
+
schema: pickSchema(opts),
|
|
28
|
+
typeMappers: opts.typeMappers,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
if (err instanceof SignatureSkipped) {
|
|
33
|
+
const wrapped = new Error(err.message);
|
|
34
|
+
wrapped.name = "SignatureSkipped";
|
|
35
|
+
throw wrapped;
|
|
36
|
+
}
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
refresh(files) {
|
|
41
|
+
for (const f of files) {
|
|
42
|
+
const sf = project.getSourceFile(f);
|
|
43
|
+
if (sf)
|
|
44
|
+
sf.refreshFromFileSystemSync();
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
dispose() {
|
|
48
|
+
// ts-morph holds no external handles.
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function createTsMorphProject(opts, init) {
|
|
55
|
+
const tsConfigFilePath = opts.tsConfigPath ?? init.tsConfigPath;
|
|
56
|
+
return new TsMorphProject({
|
|
57
|
+
tsConfigFilePath,
|
|
58
|
+
skipAddingFilesFromTsConfig: tsConfigFilePath ? false : true,
|
|
59
|
+
skipFileDependencyResolution: false,
|
|
60
|
+
compilerOptions: opts.compilerOptions,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function ensureFilesLoaded(project, files) {
|
|
64
|
+
for (const f of files) {
|
|
65
|
+
if (!project.getSourceFile(f)) {
|
|
66
|
+
project.addSourceFileAtPathIfExists(f);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function pickSignature(opts) {
|
|
71
|
+
return {
|
|
72
|
+
parameters: opts.parameters,
|
|
73
|
+
unwrapPromise: opts.unwrapPromise,
|
|
74
|
+
generics: opts.generics,
|
|
75
|
+
overloads: opts.overloads,
|
|
76
|
+
skipParameter: opts.skipParameter,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function pickSchema(opts) {
|
|
80
|
+
return {
|
|
81
|
+
dialect: opts.dialect,
|
|
82
|
+
refStrategy: opts.refStrategy,
|
|
83
|
+
definitionsPath: opts.definitionsPath,
|
|
84
|
+
topRef: opts.topRef,
|
|
85
|
+
additionalProperties: opts.additionalProperties,
|
|
86
|
+
encodeRefs: opts.encodeRefs,
|
|
87
|
+
expose: opts.expose,
|
|
88
|
+
typeMappers: opts.typeMappers,
|
|
89
|
+
identity: opts.identity,
|
|
90
|
+
transport: opts.transport,
|
|
91
|
+
sourceLocations: opts.sourceLocations,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=extractor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../src/extractor.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAA2B,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5E,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAU,CAAC;AAS/D,MAAM,UAAU,UAAU,CACxB,UAAsC,EAAE;IAExC,OAAO;QACL,UAAU,EAAE,aAAa;QACzB,QAAQ,EAAE,YAAY;QACtB,KAAK,CAAC,IAAI,CAAC,QAA8B;YACvC,MAAM,OAAO,GAAG,oBAAoB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YAExD,OAAO;gBACL,KAAK,CAAC,QAAQ,CACZ,KAAwB,EACxB,OAAuB;oBAEvB,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;oBAClC,OAAO,iBAAiB,CAAC,OA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/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ExtractOptions, type ExtractResult } from "@ir-kit/fn-schema-core";
|
|
2
|
+
import { type TypescriptExtractorOptions } from "./extractor.js";
|
|
3
|
+
export { emit } from "@ir-kit/fn-schema-core";
|
|
4
|
+
export { type TypescriptExtractorOptions, typescript } from "./extractor.js";
|
|
5
|
+
/**
|
|
6
|
+
* Convenience one-shot — pre-wires the TypeScript extractor. Equivalent to
|
|
7
|
+
* `createProject({ extractors: [typescript(opts)] }).extract(opts)`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function extract(options?: ExtractOptions & {
|
|
10
|
+
typescript?: TypescriptExtractorOptions;
|
|
11
|
+
}): Promise<ExtractResult>;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,aAAa,EACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,KAAK,0BAA0B,EAAc,MAAM,gBAAgB,CAAC;AAE7E,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,KAAK,0BAA0B,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE7E;;;GAGG;AACH,wBAAsB,OAAO,CAC3B,OAAO,GAAE,cAAc,GAAG;IACxB,UAAU,CAAC,EAAE,0BAA0B,CAAC;CACpC,GACL,OAAO,CAAC,aAAa,CAAC,CAYxB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createProject, } from "@ir-kit/fn-schema-core";
|
|
2
|
+
import { typescript } from "./extractor.js";
|
|
3
|
+
export { emit } from "@ir-kit/fn-schema-core";
|
|
4
|
+
export { typescript } from "./extractor.js";
|
|
5
|
+
/**
|
|
6
|
+
* Convenience one-shot — pre-wires the TypeScript extractor. Equivalent to
|
|
7
|
+
* `createProject({ extractors: [typescript(opts)] }).extract(opts)`.
|
|
8
|
+
*/
|
|
9
|
+
export async function extract(options = {}) {
|
|
10
|
+
const { typescript: tsOpts, ...rest } = options;
|
|
11
|
+
const project = createProject({
|
|
12
|
+
cwd: rest.cwd,
|
|
13
|
+
tsConfigPath: rest.tsConfigPath,
|
|
14
|
+
extractors: [typescript(tsOpts)],
|
|
15
|
+
});
|
|
16
|
+
try {
|
|
17
|
+
return await project.extract(rest);
|
|
18
|
+
}
|
|
19
|
+
finally {
|
|
20
|
+
project.dispose();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,GAGd,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAmC,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE7E,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAmC,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE7E;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,UAEI,EAAE;IAEN,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IAChD,MAAM,OAAO,GAAG,aAAa,CAAC;QAC5B,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,UAAU,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;KACjC,CAAC,CAAC;IACH,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;AACH,CAAC"}
|
package/dist/jsdoc.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsdoc.d.ts","sourceRoot":"","sources":["../src/jsdoc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC,wBAAgB,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,SAAS,GAAG,SAAS,CAoB/D"}
|
package/dist/jsdoc.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function parseJsDoc(docs) {
|
|
2
|
+
if (docs.length === 0)
|
|
3
|
+
return undefined;
|
|
4
|
+
const tags = {};
|
|
5
|
+
const descriptionParts = [];
|
|
6
|
+
for (const doc of docs) {
|
|
7
|
+
const desc = doc.getDescription().trim();
|
|
8
|
+
if (desc)
|
|
9
|
+
descriptionParts.push(desc);
|
|
10
|
+
for (const tag of doc.getTags()) {
|
|
11
|
+
const name = tag.getTagName();
|
|
12
|
+
const value = tag.getCommentText()?.trim();
|
|
13
|
+
tags[name] = value && value.length > 0 ? value : true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const description = descriptionParts.join("\n").trim();
|
|
17
|
+
return {
|
|
18
|
+
description: description.length > 0 ? description : undefined,
|
|
19
|
+
tags,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=jsdoc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsdoc.js","sourceRoot":"","sources":["../src/jsdoc.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,UAAU,CAAC,IAAa;IACtC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACxC,MAAM,IAAI,GAAkC,EAAE,CAAC;IAC/C,MAAM,gBAAgB,GAAa,EAAE,CAAC;IAEtC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,IAAI,GAAG,GAAG,CAAC,cAAc,EAAE,CAAC,IAAI,EAAE,CAAC;QACzC,IAAI,IAAI;YAAE,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtC,KAAK,MAAM,GAAG,IAAI,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC;YAChC,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,EAAE,CAAC;YAC9B,MAAM,KAAK,GAAG,GAAG,CAAC,cAAc,EAAE,EAAE,IAAI,EAAE,CAAC;YAC3C,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;QACxD,CAAC;IACH,CAAC;IAED,MAAM,WAAW,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;IACvD,OAAO;QACL,WAAW,EAAE,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS;QAC7D,IAAI;KACL,CAAC;AACJ,CAAC"}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { JSONSchema, ResolvedSchemaOptions, ResolvedSignatureOptions, SignaturePair } from "@ir-kit/fn-schema-core";
|
|
2
|
+
import type { Project as TsMorphProject } from "ts-morph";
|
|
3
|
+
import type { DiscoveredFunction } from "./discover.js";
|
|
4
|
+
export declare const VIRTUAL_DIR = "__fn_schema_virtual__";
|
|
5
|
+
interface BuildContext {
|
|
6
|
+
project: TsMorphProject;
|
|
7
|
+
signature: ResolvedSignatureOptions;
|
|
8
|
+
schema: ResolvedSchemaOptions;
|
|
9
|
+
typeMappers?: Record<string, JSONSchema>;
|
|
10
|
+
}
|
|
11
|
+
export declare class SignatureSkipped extends Error {
|
|
12
|
+
constructor(message: string);
|
|
13
|
+
}
|
|
14
|
+
export declare function virtualDirFor(sourceFile: string): string;
|
|
15
|
+
export declare function buildSchemas(fn: DiscoveredFunction, ctx: BuildContext): SignaturePair;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,UAAU,EAEV,qBAAqB,EACrB,wBAAwB,EACxB,aAAa,EACd,MAAM,wBAAwB,CAAC;AAShC,OAAO,KAAK,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,UAAU,CAAC;AAQ1D,OAAO,KAAK,EACV,kBAAkB,EAGnB,MAAM,eAAe,CAAC;AASvB,eAAO,MAAM,WAAW,0BAA0B,CAAC;AAInD,UAAU,YAAY;IACpB,OAAO,EAAE,cAAc,CAAC;IACxB,SAAS,EAAE,wBAAwB,CAAC;IACpC,MAAM,EAAE,qBAAqB,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CAC1C;AAED,qBAAa,gBAAiB,SAAQ,KAAK;gBAC7B,OAAO,EAAE,MAAM;CAI5B;AAED,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,YAAY,CAC1B,EAAE,EAAE,kBAAkB,EACtB,GAAG,EAAE,YAAY,GAChB,aAAa,CAuHf"}
|