@sdk-it/core 0.1.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.
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +412 -0
- package/dist/index.js.map +7 -0
- package/dist/lib/deriver.d.ts +13 -0
- package/dist/lib/deriver.d.ts.map +1 -0
- package/dist/lib/program.d.ts +7 -0
- package/dist/lib/program.d.ts.map +1 -0
- package/package.json +30 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
// packages/core/src/lib/deriver.ts
|
|
2
|
+
import ts, { TypeFlags } from "typescript";
|
|
3
|
+
var deriveSymbol = Symbol.for("serialize");
|
|
4
|
+
var $types = Symbol.for("types");
|
|
5
|
+
var TypeDeriver = class {
|
|
6
|
+
collector = {};
|
|
7
|
+
checker;
|
|
8
|
+
constructor(checker) {
|
|
9
|
+
this.checker = checker;
|
|
10
|
+
}
|
|
11
|
+
serializeType(type) {
|
|
12
|
+
if (type.flags & TypeFlags.Any) {
|
|
13
|
+
return {
|
|
14
|
+
[deriveSymbol]: true,
|
|
15
|
+
optional: false,
|
|
16
|
+
[$types]: []
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (type.isIntersection()) {
|
|
20
|
+
let optional;
|
|
21
|
+
const types = [];
|
|
22
|
+
for (const unionType of type.types) {
|
|
23
|
+
if (optional === void 0) {
|
|
24
|
+
optional = (unionType.flags & ts.TypeFlags.Undefined) !== 0;
|
|
25
|
+
if (optional) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
types.push(this.serializeType(unionType));
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
[deriveSymbol]: true,
|
|
33
|
+
kind: "intersection",
|
|
34
|
+
optional,
|
|
35
|
+
[$types]: types
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (type.isUnion()) {
|
|
39
|
+
let optional;
|
|
40
|
+
const types = [];
|
|
41
|
+
for (const unionType of type.types) {
|
|
42
|
+
if (optional === void 0) {
|
|
43
|
+
optional = (unionType.flags & ts.TypeFlags.Undefined) !== 0;
|
|
44
|
+
if (optional) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
types.push(this.serializeType(unionType));
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
[deriveSymbol]: true,
|
|
52
|
+
kind: "union",
|
|
53
|
+
optional,
|
|
54
|
+
[$types]: types
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (this.checker.isArrayLikeType(type)) {
|
|
58
|
+
const [argType] = this.checker.getTypeArguments(type);
|
|
59
|
+
if (!argType) {
|
|
60
|
+
const typeName = type.symbol?.getName() || "<unknown>";
|
|
61
|
+
console.warn(
|
|
62
|
+
`Could not find generic type argument for array type ${typeName}`
|
|
63
|
+
);
|
|
64
|
+
return {
|
|
65
|
+
[deriveSymbol]: true,
|
|
66
|
+
optional: false,
|
|
67
|
+
kind: "array",
|
|
68
|
+
[$types]: ["any"]
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const typeSymbol = argType.getSymbol();
|
|
72
|
+
if (!typeSymbol) {
|
|
73
|
+
console.warn(
|
|
74
|
+
`No symbol found for array type ${this.checker.typeToString(argType)}`
|
|
75
|
+
);
|
|
76
|
+
const typeString = this.checker.typeToString(argType);
|
|
77
|
+
return {
|
|
78
|
+
[deriveSymbol]: true,
|
|
79
|
+
optional: false,
|
|
80
|
+
kind: "array",
|
|
81
|
+
[$types]: typeString === "undefined" ? [] : [typeString]
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (typeSymbol.valueDeclaration) {
|
|
85
|
+
return {
|
|
86
|
+
kind: "array",
|
|
87
|
+
...this.serializeNode(typeSymbol.valueDeclaration)
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const maybeDeclaration = typeSymbol.declarations?.[0];
|
|
91
|
+
if (maybeDeclaration) {
|
|
92
|
+
if (ts.isMappedTypeNode(maybeDeclaration)) {
|
|
93
|
+
const resolvedType = this.checker.getPropertiesOfType(argType).reduce((acc, prop) => {
|
|
94
|
+
const propType = this.checker.getTypeOfSymbol(prop);
|
|
95
|
+
acc[prop.name] = this.serializeType(propType);
|
|
96
|
+
return acc;
|
|
97
|
+
}, {});
|
|
98
|
+
return {
|
|
99
|
+
kind: "array",
|
|
100
|
+
optional: false,
|
|
101
|
+
[deriveSymbol]: true,
|
|
102
|
+
[$types]: [resolvedType]
|
|
103
|
+
};
|
|
104
|
+
} else {
|
|
105
|
+
return {
|
|
106
|
+
kind: "array",
|
|
107
|
+
...this.serializeNode(maybeDeclaration)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
kind: "array",
|
|
113
|
+
optional: false,
|
|
114
|
+
[deriveSymbol]: true,
|
|
115
|
+
[$types]: ["any"]
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
if (type.isClass()) {
|
|
119
|
+
const declaration = type.symbol?.valueDeclaration;
|
|
120
|
+
if (!declaration) {
|
|
121
|
+
return {
|
|
122
|
+
[deriveSymbol]: true,
|
|
123
|
+
optional: false,
|
|
124
|
+
[$types]: [type.symbol.getName()]
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return this.serializeNode(declaration);
|
|
128
|
+
}
|
|
129
|
+
if (isInterfaceType(type)) {
|
|
130
|
+
const valueDeclaration = type.symbol.valueDeclaration ?? type.symbol.declarations?.[0];
|
|
131
|
+
if (!valueDeclaration) {
|
|
132
|
+
return {
|
|
133
|
+
[deriveSymbol]: true,
|
|
134
|
+
optional: false,
|
|
135
|
+
[$types]: [type.symbol.getName()]
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
return this.serializeNode(valueDeclaration);
|
|
139
|
+
}
|
|
140
|
+
if (type.flags & TypeFlags.Object) {
|
|
141
|
+
const properties = this.checker.getPropertiesOfType(type);
|
|
142
|
+
if (properties.length > 0) {
|
|
143
|
+
const serializedProps = properties.reduce(
|
|
144
|
+
(acc, prop) => {
|
|
145
|
+
const propType = this.checker.getTypeOfSymbol(prop);
|
|
146
|
+
acc[prop.name] = this.serializeType(propType);
|
|
147
|
+
return acc;
|
|
148
|
+
},
|
|
149
|
+
{}
|
|
150
|
+
);
|
|
151
|
+
return {
|
|
152
|
+
[deriveSymbol]: true,
|
|
153
|
+
kind: "object",
|
|
154
|
+
optional: false,
|
|
155
|
+
[$types]: [serializedProps]
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const declaration = type.symbol.valueDeclaration ?? type.symbol.declarations?.[0];
|
|
159
|
+
if (!declaration) {
|
|
160
|
+
return {
|
|
161
|
+
[deriveSymbol]: true,
|
|
162
|
+
optional: false,
|
|
163
|
+
[$types]: [type.symbol.getName()]
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
return this.serializeNode(declaration);
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
[deriveSymbol]: true,
|
|
170
|
+
optional: false,
|
|
171
|
+
[$types]: [
|
|
172
|
+
this.checker.typeToString(
|
|
173
|
+
type,
|
|
174
|
+
void 0,
|
|
175
|
+
ts.TypeFormatFlags.NoTruncation
|
|
176
|
+
)
|
|
177
|
+
]
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
serializeNode(node) {
|
|
181
|
+
if (ts.isObjectLiteralExpression(node)) {
|
|
182
|
+
const symbolType = this.checker.getTypeAtLocation(node);
|
|
183
|
+
const props = {};
|
|
184
|
+
for (const symbol of symbolType.getProperties()) {
|
|
185
|
+
const type = this.checker.getTypeOfSymbol(symbol);
|
|
186
|
+
props[symbol.name] = this.serializeType(type);
|
|
187
|
+
}
|
|
188
|
+
return props;
|
|
189
|
+
}
|
|
190
|
+
if (ts.isPropertyAccessExpression(node)) {
|
|
191
|
+
const symbol = this.checker.getSymbolAtLocation(node.name);
|
|
192
|
+
if (!symbol) {
|
|
193
|
+
console.warn(`No symbol found for ${node.name.getText()}`);
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
const type = this.checker.getTypeOfSymbol(symbol);
|
|
197
|
+
return this.serializeType(type);
|
|
198
|
+
}
|
|
199
|
+
if (ts.isPropertySignature(node)) {
|
|
200
|
+
const symbol = this.checker.getSymbolAtLocation(node.name);
|
|
201
|
+
if (!symbol) {
|
|
202
|
+
console.warn(`No symbol found for ${node.name.getText()}`);
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
const type = this.checker.getTypeOfSymbol(symbol);
|
|
206
|
+
return this.serializeType(type);
|
|
207
|
+
}
|
|
208
|
+
if (ts.isPropertyDeclaration(node)) {
|
|
209
|
+
const symbol = this.checker.getSymbolAtLocation(node.name);
|
|
210
|
+
if (!symbol) {
|
|
211
|
+
console.warn(`No symbol found for ${node.name.getText()}`);
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
const type = this.checker.getTypeOfSymbol(symbol);
|
|
215
|
+
return this.serializeType(type);
|
|
216
|
+
}
|
|
217
|
+
if (ts.isInterfaceDeclaration(node)) {
|
|
218
|
+
if (!node.name?.text) {
|
|
219
|
+
throw new Error("Interface has no name");
|
|
220
|
+
}
|
|
221
|
+
const defaults = {
|
|
222
|
+
ReadableStream: "ReadableStream",
|
|
223
|
+
DateConstructor: "Date"
|
|
224
|
+
};
|
|
225
|
+
if (defaults[node.name.text]) {
|
|
226
|
+
return {
|
|
227
|
+
[deriveSymbol]: true,
|
|
228
|
+
optional: false,
|
|
229
|
+
[$types]: [`#/components/schemas/${node.name.text}`]
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
if (!this.collector[node.name.text]) {
|
|
233
|
+
this.collector[node.name.text] = {};
|
|
234
|
+
const members = {};
|
|
235
|
+
for (const member of node.members.filter(ts.isPropertySignature)) {
|
|
236
|
+
members[member.name.getText()] = this.serializeNode(member);
|
|
237
|
+
}
|
|
238
|
+
this.collector[node.name.text] = members;
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
[deriveSymbol]: true,
|
|
242
|
+
optional: false,
|
|
243
|
+
[$types]: [`#/components/schemas/${node.name.text}`]
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
if (ts.isClassDeclaration(node)) {
|
|
247
|
+
if (!node.name?.text) {
|
|
248
|
+
throw new Error("Class has no name");
|
|
249
|
+
}
|
|
250
|
+
if (!this.collector[node.name.text]) {
|
|
251
|
+
this.collector[node.name.text] = {};
|
|
252
|
+
const members = {};
|
|
253
|
+
for (const member of node.members.filter(ts.isPropertyDeclaration)) {
|
|
254
|
+
members[member.name.getText()] = this.serializeNode(member);
|
|
255
|
+
}
|
|
256
|
+
this.collector[node.name.text] = members;
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
[deriveSymbol]: true,
|
|
260
|
+
optional: false,
|
|
261
|
+
[$types]: [node.name.text],
|
|
262
|
+
$ref: `#/components/schemas/${node.name.text}`
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
if (ts.isVariableDeclaration(node)) {
|
|
266
|
+
const symbol = this.checker.getSymbolAtLocation(node.name);
|
|
267
|
+
if (!symbol) {
|
|
268
|
+
console.warn(`No symbol found for ${node.name.getText()}`);
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
if (!node.type) {
|
|
272
|
+
console.warn(`No type found for ${node.name.getText()}`);
|
|
273
|
+
return "any";
|
|
274
|
+
}
|
|
275
|
+
const type = this.checker.getTypeFromTypeNode(node.type);
|
|
276
|
+
return this.serializeType(type);
|
|
277
|
+
}
|
|
278
|
+
if (ts.isIdentifier(node)) {
|
|
279
|
+
const symbol = this.checker.getSymbolAtLocation(node);
|
|
280
|
+
if (!symbol) {
|
|
281
|
+
console.warn(`Identifer: No symbol found for ${node.getText()}`);
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
const type = this.checker.getTypeAtLocation(node);
|
|
285
|
+
return this.serializeType(type);
|
|
286
|
+
}
|
|
287
|
+
if (ts.isAwaitExpression(node)) {
|
|
288
|
+
const type = this.checker.getTypeAtLocation(node);
|
|
289
|
+
return this.serializeType(type);
|
|
290
|
+
}
|
|
291
|
+
if (ts.isCallExpression(node)) {
|
|
292
|
+
const type = this.checker.getTypeAtLocation(node);
|
|
293
|
+
return this.serializeType(type);
|
|
294
|
+
}
|
|
295
|
+
if (ts.isAsExpression(node)) {
|
|
296
|
+
const type = this.checker.getTypeAtLocation(node);
|
|
297
|
+
return this.serializeType(type);
|
|
298
|
+
}
|
|
299
|
+
if (ts.isTypeLiteralNode(node)) {
|
|
300
|
+
const symbolType = this.checker.getTypeAtLocation(node);
|
|
301
|
+
const props = {};
|
|
302
|
+
for (const symbol of symbolType.getProperties()) {
|
|
303
|
+
const type = this.checker.getTypeOfSymbol(symbol);
|
|
304
|
+
props[symbol.name] = this.serializeType(type);
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
[deriveSymbol]: true,
|
|
308
|
+
optional: false,
|
|
309
|
+
[$types]: [props]
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
if (node.kind === ts.SyntaxKind.NullKeyword) {
|
|
313
|
+
return {
|
|
314
|
+
[deriveSymbol]: true,
|
|
315
|
+
optional: true,
|
|
316
|
+
[$types]: ["null"]
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
console.warn(`Unhandled node: ${ts.SyntaxKind[node.kind]} ${node.flags}`);
|
|
320
|
+
return {
|
|
321
|
+
[deriveSymbol]: true,
|
|
322
|
+
optional: false,
|
|
323
|
+
[$types]: ["any"]
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
function isInterfaceType(type) {
|
|
328
|
+
if (type.isClassOrInterface()) {
|
|
329
|
+
return !!(type.symbol.flags & ts.SymbolFlags.Interface);
|
|
330
|
+
}
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// packages/core/src/lib/program.ts
|
|
335
|
+
import debug from "debug";
|
|
336
|
+
import { dirname, join } from "node:path";
|
|
337
|
+
import ts2 from "typescript";
|
|
338
|
+
var logger = debug("january:client");
|
|
339
|
+
function parseTsConfig(tsconfigPath) {
|
|
340
|
+
logger(`Using TypeScript version: ${ts2.version}`);
|
|
341
|
+
const configContent = ts2.readConfigFile(tsconfigPath, ts2.sys.readFile);
|
|
342
|
+
if (configContent.error) {
|
|
343
|
+
console.error(
|
|
344
|
+
`Failed to read tsconfig file:`,
|
|
345
|
+
ts2.formatDiagnosticsWithColorAndContext([configContent.error], {
|
|
346
|
+
getCanonicalFileName: (path) => path,
|
|
347
|
+
getCurrentDirectory: ts2.sys.getCurrentDirectory,
|
|
348
|
+
getNewLine: () => ts2.sys.newLine
|
|
349
|
+
})
|
|
350
|
+
);
|
|
351
|
+
throw new Error("Failed to parse tsconfig.json");
|
|
352
|
+
}
|
|
353
|
+
const parsed = ts2.parseJsonConfigFileContent(
|
|
354
|
+
configContent.config,
|
|
355
|
+
ts2.sys,
|
|
356
|
+
dirname(tsconfigPath)
|
|
357
|
+
);
|
|
358
|
+
if (parsed.errors.length > 0) {
|
|
359
|
+
console.error(
|
|
360
|
+
`Errors found in tsconfig.json:`,
|
|
361
|
+
ts2.formatDiagnosticsWithColorAndContext(parsed.errors, {
|
|
362
|
+
getCanonicalFileName: (path) => path,
|
|
363
|
+
getCurrentDirectory: ts2.sys.getCurrentDirectory,
|
|
364
|
+
getNewLine: () => ts2.sys.newLine
|
|
365
|
+
})
|
|
366
|
+
);
|
|
367
|
+
throw new Error("Failed to parse tsconfig.json");
|
|
368
|
+
}
|
|
369
|
+
return parsed;
|
|
370
|
+
}
|
|
371
|
+
function getProgram(tsconfigPath) {
|
|
372
|
+
const tsConfigParseResult = parseTsConfig(tsconfigPath);
|
|
373
|
+
logger(`Parsing tsconfig`);
|
|
374
|
+
return ts2.createProgram({
|
|
375
|
+
options: {
|
|
376
|
+
...tsConfigParseResult.options,
|
|
377
|
+
noEmit: true,
|
|
378
|
+
incremental: true,
|
|
379
|
+
tsBuildInfoFile: join(dirname(tsconfigPath), "./.tsbuildinfo")
|
|
380
|
+
// not working atm
|
|
381
|
+
},
|
|
382
|
+
rootNames: tsConfigParseResult.fileNames,
|
|
383
|
+
projectReferences: tsConfigParseResult.projectReferences,
|
|
384
|
+
configFileParsingDiagnostics: tsConfigParseResult.errors
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
function getPropertyAssignment(node, name) {
|
|
388
|
+
if (ts2.isObjectLiteralExpression(node)) {
|
|
389
|
+
return node.properties.filter((prop) => ts2.isPropertyAssignment(prop)).find((prop) => prop.name.getText() === name);
|
|
390
|
+
}
|
|
391
|
+
return void 0;
|
|
392
|
+
}
|
|
393
|
+
function isCallExpression(node, name) {
|
|
394
|
+
return ts2.isCallExpression(node) && node.expression && ts2.isIdentifier(node.expression) && node.expression.text === name;
|
|
395
|
+
}
|
|
396
|
+
function isInterfaceType2(type) {
|
|
397
|
+
if (type.isClassOrInterface()) {
|
|
398
|
+
return !!(type.symbol.flags & ts2.SymbolFlags.Interface);
|
|
399
|
+
}
|
|
400
|
+
return false;
|
|
401
|
+
}
|
|
402
|
+
export {
|
|
403
|
+
$types,
|
|
404
|
+
TypeDeriver,
|
|
405
|
+
deriveSymbol,
|
|
406
|
+
getProgram,
|
|
407
|
+
getPropertyAssignment,
|
|
408
|
+
isCallExpression,
|
|
409
|
+
isInterfaceType2 as isInterfaceType,
|
|
410
|
+
parseTsConfig
|
|
411
|
+
};
|
|
412
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/lib/deriver.ts", "../src/lib/program.ts"],
|
|
4
|
+
"sourcesContent": ["import ts, { TypeFlags } from 'typescript';\n\ntype Collector = Record<string, any>;\nexport const deriveSymbol = Symbol.for('serialize');\nexport const $types = Symbol.for('types');\n\nexport class TypeDeriver {\n public readonly collector: Collector = {};\n public readonly checker: ts.TypeChecker;\n constructor(checker: ts.TypeChecker) {\n this.checker = checker;\n }\n\n serializeType(type: ts.Type): any {\n if (type.flags & TypeFlags.Any) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [],\n };\n }\n\n if (type.isIntersection()) {\n let optional: boolean | undefined;\n const types: any[] = [];\n for (const unionType of type.types) {\n if (optional === undefined) {\n optional = (unionType.flags & ts.TypeFlags.Undefined) !== 0;\n if (optional) {\n continue;\n }\n }\n\n types.push(this.serializeType(unionType));\n }\n return {\n [deriveSymbol]: true,\n kind: 'intersection',\n optional,\n [$types]: types,\n };\n }\n if (type.isUnion()) {\n let optional: boolean | undefined;\n const types: any[] = [];\n for (const unionType of type.types) {\n if (optional === undefined) {\n optional = (unionType.flags & ts.TypeFlags.Undefined) !== 0;\n if (optional) {\n continue;\n }\n }\n\n types.push(this.serializeType(unionType));\n }\n return {\n [deriveSymbol]: true,\n kind: 'union',\n optional,\n [$types]: types,\n };\n }\n if (this.checker.isArrayLikeType(type)) {\n const [argType] = this.checker.getTypeArguments(type as ts.TypeReference);\n if (!argType) {\n const typeName = type.symbol?.getName() || '<unknown>';\n console.warn(\n `Could not find generic type argument for array type ${typeName}`,\n );\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'array',\n [$types]: ['any'],\n };\n }\n const typeSymbol = argType.getSymbol();\n if (!typeSymbol) {\n console.warn(\n `No symbol found for array type ${this.checker.typeToString(argType)}`,\n );\n const typeString = this.checker.typeToString(argType);\n return {\n [deriveSymbol]: true,\n optional: false,\n kind: 'array',\n [$types]: typeString === 'undefined' ? [] : [typeString],\n };\n }\n\n if (typeSymbol.valueDeclaration) {\n return {\n kind: 'array',\n ...this.serializeNode(typeSymbol.valueDeclaration),\n };\n }\n const maybeDeclaration = typeSymbol.declarations?.[0];\n if (maybeDeclaration) {\n if (ts.isMappedTypeNode(maybeDeclaration)) {\n const resolvedType = this.checker\n .getPropertiesOfType(argType)\n .reduce<Record<string, unknown>>((acc, prop) => {\n const propType = this.checker.getTypeOfSymbol(prop);\n acc[prop.name] = this.serializeType(propType);\n return acc;\n }, {});\n return {\n kind: 'array',\n optional: false,\n [deriveSymbol]: true,\n [$types]: [resolvedType],\n };\n } else {\n return {\n kind: 'array',\n ...this.serializeNode(maybeDeclaration),\n };\n }\n }\n\n return {\n kind: 'array',\n optional: false,\n [deriveSymbol]: true,\n [$types]: ['any'],\n };\n }\n if (type.isClass()) {\n const declaration = type.symbol?.valueDeclaration;\n if (!declaration) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [type.symbol.getName()],\n };\n }\n return this.serializeNode(declaration);\n }\n if (isInterfaceType(type)) {\n const valueDeclaration =\n type.symbol.valueDeclaration ?? type.symbol.declarations?.[0];\n if (!valueDeclaration) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [type.symbol.getName()],\n };\n }\n return this.serializeNode(valueDeclaration);\n }\n if (type.flags & TypeFlags.Object) {\n const properties = this.checker.getPropertiesOfType(type);\n if (properties.length > 0) {\n const serializedProps = properties.reduce<Record<string, any>>(\n (acc, prop) => {\n const propType = this.checker.getTypeOfSymbol(prop);\n acc[prop.name] = this.serializeType(propType);\n return acc;\n },\n {},\n );\n return {\n [deriveSymbol]: true,\n kind: 'object',\n optional: false,\n [$types]: [serializedProps],\n };\n }\n const declaration =\n type.symbol.valueDeclaration ?? type.symbol.declarations?.[0];\n if (!declaration) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [type.symbol.getName()],\n };\n }\n return this.serializeNode(declaration);\n }\n\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [\n this.checker.typeToString(\n type,\n undefined,\n ts.TypeFormatFlags.NoTruncation,\n ),\n ],\n };\n }\n\n serializeNode(node: ts.Node): any {\n if (ts.isObjectLiteralExpression(node)) {\n const symbolType = this.checker.getTypeAtLocation(node);\n const props: Record<string, any> = {};\n for (const symbol of symbolType.getProperties()) {\n const type = this.checker.getTypeOfSymbol(symbol);\n props[symbol.name] = this.serializeType(type);\n }\n return props;\n }\n if (ts.isPropertyAccessExpression(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n console.warn(`No symbol found for ${node.name.getText()}`);\n return null;\n }\n const type = this.checker.getTypeOfSymbol(symbol);\n return this.serializeType(type);\n }\n if (ts.isPropertySignature(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n console.warn(`No symbol found for ${node.name.getText()}`);\n return null;\n }\n const type = this.checker.getTypeOfSymbol(symbol);\n return this.serializeType(type);\n }\n if (ts.isPropertyDeclaration(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n console.warn(`No symbol found for ${node.name.getText()}`);\n return null;\n }\n const type = this.checker.getTypeOfSymbol(symbol);\n return this.serializeType(type);\n }\n if (ts.isInterfaceDeclaration(node)) {\n if (!node.name?.text) {\n throw new Error('Interface has no name');\n }\n const defaults: Record<string, string> = {\n ReadableStream: 'ReadableStream',\n DateConstructor: 'Date',\n };\n if (defaults[node.name.text]) {\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [`#/components/schemas/${node.name.text}`],\n };\n }\n if (!this.collector[node.name.text]) {\n this.collector[node.name.text] = {};\n const members: Record<string, any> = {};\n for (const member of node.members.filter(ts.isPropertySignature)) {\n members[member.name.getText()] = this.serializeNode(member);\n }\n this.collector[node.name.text] = members;\n }\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [`#/components/schemas/${node.name.text}`],\n };\n }\n if (ts.isClassDeclaration(node)) {\n if (!node.name?.text) {\n throw new Error('Class has no name');\n }\n if (!this.collector[node.name.text]) {\n this.collector[node.name.text] = {};\n const members: Record<string, any> = {};\n for (const member of node.members.filter(ts.isPropertyDeclaration)) {\n members[member.name!.getText()] = this.serializeNode(member);\n }\n this.collector[node.name.text] = members;\n }\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [node.name.text],\n $ref: `#/components/schemas/${node.name.text}`,\n };\n }\n if (ts.isVariableDeclaration(node)) {\n const symbol = this.checker.getSymbolAtLocation(node.name);\n if (!symbol) {\n console.warn(`No symbol found for ${node.name.getText()}`);\n return null;\n }\n if (!node.type) {\n console.warn(`No type found for ${node.name.getText()}`);\n return 'any';\n }\n const type = this.checker.getTypeFromTypeNode(node.type);\n return this.serializeType(type);\n }\n if (ts.isIdentifier(node)) {\n const symbol = this.checker.getSymbolAtLocation(node);\n if (!symbol) {\n console.warn(`Identifer: No symbol found for ${node.getText()}`);\n return null;\n }\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n if (ts.isAwaitExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n if (ts.isCallExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n if (ts.isAsExpression(node)) {\n const type = this.checker.getTypeAtLocation(node);\n return this.serializeType(type);\n }\n if (ts.isTypeLiteralNode(node)) {\n const symbolType = this.checker.getTypeAtLocation(node);\n const props: Record<string, unknown> = {};\n for (const symbol of symbolType.getProperties()) {\n const type = this.checker.getTypeOfSymbol(symbol);\n props[symbol.name] = this.serializeType(type);\n }\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: [props],\n };\n }\n\n if (node.kind === ts.SyntaxKind.NullKeyword) {\n return {\n [deriveSymbol]: true,\n optional: true,\n [$types]: ['null'],\n };\n }\n console.warn(`Unhandled node: ${ts.SyntaxKind[node.kind]} ${node.flags}`);\n return {\n [deriveSymbol]: true,\n optional: false,\n [$types]: ['any'],\n };\n }\n}\n\nfunction isInterfaceType(type: ts.Type): boolean {\n if (type.isClassOrInterface()) {\n // Check if it's an interface\n return !!(type.symbol.flags & ts.SymbolFlags.Interface);\n }\n return false;\n}\n", "import debug from 'debug';\nimport { dirname, join } from 'node:path';\nimport ts from 'typescript';\n\n\n\n\n\nconst logger = debug('january:client');\n\nexport function parseTsConfig(tsconfigPath: string) {\n logger(`Using TypeScript version: ${ts.version}`);\n const configContent = ts.readConfigFile(tsconfigPath, ts.sys.readFile);\n\n if (configContent.error) {\n console.error(\n `Failed to read tsconfig file:`,\n ts.formatDiagnosticsWithColorAndContext([configContent.error], {\n getCanonicalFileName: (path) => path,\n getCurrentDirectory: ts.sys.getCurrentDirectory,\n getNewLine: () => ts.sys.newLine,\n }),\n );\n throw new Error('Failed to parse tsconfig.json');\n }\n\n const parsed = ts.parseJsonConfigFileContent(\n configContent.config,\n ts.sys,\n dirname(tsconfigPath),\n );\n\n if (parsed.errors.length > 0) {\n console.error(\n `Errors found in tsconfig.json:`,\n ts.formatDiagnosticsWithColorAndContext(parsed.errors, {\n getCanonicalFileName: (path) => path,\n getCurrentDirectory: ts.sys.getCurrentDirectory,\n getNewLine: () => ts.sys.newLine,\n }),\n );\n throw new Error('Failed to parse tsconfig.json');\n }\n return parsed;\n}\nexport function getProgram(tsconfigPath: string) {\n const tsConfigParseResult = parseTsConfig(tsconfigPath);\n logger(`Parsing tsconfig`);\n return ts.createProgram({\n options: {\n ...tsConfigParseResult.options,\n noEmit: true,\n incremental: true,\n tsBuildInfoFile: join(dirname(tsconfigPath), './.tsbuildinfo'), // not working atm\n },\n rootNames: tsConfigParseResult.fileNames,\n projectReferences: tsConfigParseResult.projectReferences,\n configFileParsingDiagnostics: tsConfigParseResult.errors,\n });\n}\nexport function getPropertyAssignment(node: ts.Node, name: string) {\n if (ts.isObjectLiteralExpression(node)) {\n return node.properties\n .filter((prop) => ts.isPropertyAssignment(prop))\n .find((prop) => prop.name!.getText() === name);\n }\n return undefined;\n}\nexport function isCallExpression(\n node: ts.Node,\n name: string,\n): node is ts.CallExpression {\n return (\n ts.isCallExpression(node) &&\n node.expression &&\n ts.isIdentifier(node.expression) &&\n node.expression.text === name\n );\n}\n\nexport function isInterfaceType(type: ts.Type): boolean {\n if (type.isClassOrInterface()) {\n // Check if it's an interface\n return !!(type.symbol.flags & ts.SymbolFlags.Interface);\n }\n return false;\n}"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,MAAM,iBAAiB;AAGvB,IAAM,eAAe,OAAO,IAAI,WAAW;AAC3C,IAAM,SAAS,OAAO,IAAI,OAAO;AAEjC,IAAM,cAAN,MAAkB;AAAA,EACP,YAAuB,CAAC;AAAA,EACxB;AAAA,EAChB,YAAY,SAAyB;AACnC,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,cAAc,MAAoB;AAChC,QAAI,KAAK,QAAQ,UAAU,KAAK;AAC9B,aAAO;AAAA,QACL,CAAC,YAAY,GAAG;AAAA,QAChB,UAAU;AAAA,QACV,CAAC,MAAM,GAAG,CAAC;AAAA,MACb;AAAA,IACF;AAEA,QAAI,KAAK,eAAe,GAAG;AACzB,UAAI;AACJ,YAAM,QAAe,CAAC;AACtB,iBAAW,aAAa,KAAK,OAAO;AAClC,YAAI,aAAa,QAAW;AAC1B,sBAAY,UAAU,QAAQ,GAAG,UAAU,eAAe;AAC1D,cAAI,UAAU;AACZ;AAAA,UACF;AAAA,QACF;AAEA,cAAM,KAAK,KAAK,cAAc,SAAS,CAAC;AAAA,MAC1C;AACA,aAAO;AAAA,QACL,CAAC,YAAY,GAAG;AAAA,QAChB,MAAM;AAAA,QACN;AAAA,QACA,CAAC,MAAM,GAAG;AAAA,MACZ;AAAA,IACF;AACA,QAAI,KAAK,QAAQ,GAAG;AAClB,UAAI;AACJ,YAAM,QAAe,CAAC;AACtB,iBAAW,aAAa,KAAK,OAAO;AAClC,YAAI,aAAa,QAAW;AAC1B,sBAAY,UAAU,QAAQ,GAAG,UAAU,eAAe;AAC1D,cAAI,UAAU;AACZ;AAAA,UACF;AAAA,QACF;AAEA,cAAM,KAAK,KAAK,cAAc,SAAS,CAAC;AAAA,MAC1C;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;AAC/C,QAAM,sBAAsB,cAAc,YAAY;AACtD,SAAO,kBAAkB;AACzB,SAAOA,IAAG,cAAc;AAAA,IACtB,SAAS;AAAA,MACP,GAAG,oBAAoB;AAAA,MACvB,QAAQ;AAAA,MACR,aAAa;AAAA,MACb,iBAAiB,KAAK,QAAQ,YAAY,GAAG,gBAAgB;AAAA;AAAA,IAC/D;AAAA,IACA,WAAW,oBAAoB;AAAA,IAC/B,mBAAmB,oBAAoB;AAAA,IACvC,8BAA8B,oBAAoB;AAAA,EACpD,CAAC;AACH;AACO,SAAS,sBAAsB,MAAe,MAAc;AACjE,MAAIA,IAAG,0BAA0B,IAAI,GAAG;AACtC,WAAO,KAAK,WACT,OAAO,CAAC,SAASA,IAAG,qBAAqB,IAAI,CAAC,EAC9C,KAAK,CAAC,SAAS,KAAK,KAAM,QAAQ,MAAM,IAAI;AAAA,EACjD;AACA,SAAO;AACT;AACO,SAAS,iBACd,MACA,MAC2B;AAC3B,SACEA,IAAG,iBAAiB,IAAI,KACxB,KAAK,cACLA,IAAG,aAAa,KAAK,UAAU,KAC/B,KAAK,WAAW,SAAS;AAE7B;AAEO,SAASC,iBAAgB,MAAwB;AACtD,MAAI,KAAK,mBAAmB,GAAG;AAE7B,WAAO,CAAC,EAAE,KAAK,OAAO,QAAQD,IAAG,YAAY;AAAA,EAC/C;AACA,SAAO;AACT;",
|
|
6
|
+
"names": ["ts", "isInterfaceType"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
type Collector = Record<string, any>;
|
|
3
|
+
export declare const deriveSymbol: unique symbol;
|
|
4
|
+
export declare const $types: unique symbol;
|
|
5
|
+
export declare class TypeDeriver {
|
|
6
|
+
readonly collector: Collector;
|
|
7
|
+
readonly checker: ts.TypeChecker;
|
|
8
|
+
constructor(checker: ts.TypeChecker);
|
|
9
|
+
serializeType(type: ts.Type): any;
|
|
10
|
+
serializeNode(node: ts.Node): any;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=deriver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deriver.d.ts","sourceRoot":"","sources":["../../src/lib/deriver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,YAAY,CAAC;AAE3C,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACrC,eAAO,MAAM,YAAY,eAA0B,CAAC;AACpD,eAAO,MAAM,MAAM,eAAsB,CAAC;AAE1C,qBAAa,WAAW;IACtB,SAAgB,SAAS,EAAE,SAAS,CAAM;IAC1C,SAAgB,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC;gBAC5B,OAAO,EAAE,EAAE,CAAC,WAAW;IAInC,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,GAAG;IAoLjC,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,GAAG;CAmJlC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
export declare function parseTsConfig(tsconfigPath: string): ts.ParsedCommandLine;
|
|
3
|
+
export declare function getProgram(tsconfigPath: string): ts.Program;
|
|
4
|
+
export declare function getPropertyAssignment(node: ts.Node, name: string): ts.PropertyAssignment | undefined;
|
|
5
|
+
export declare function isCallExpression(node: ts.Node, name: string): node is ts.CallExpression;
|
|
6
|
+
export declare function isInterfaceType(type: ts.Type): boolean;
|
|
7
|
+
//# sourceMappingURL=program.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../src/lib/program.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,YAAY,CAAC;AAQ5B,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,wBAkCjD;AACD,wBAAgB,UAAU,CAAC,YAAY,EAAE,MAAM,cAc9C;AACD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,qCAOhE;AACD,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,IAAI,EAAE,MAAM,GACX,IAAI,IAAI,EAAE,CAAC,cAAc,CAO3B;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,OAAO,CAMtD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sdk-it/core",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
"./package.json": "./package.json",
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"!**/*.tsbuildinfo"
|
|
22
|
+
],
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"debug": "^4.4.0",
|
|
25
|
+
"typescript": "~5.7.2"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/debug": "^4.1.12"
|
|
29
|
+
}
|
|
30
|
+
}
|