@dagger.io/dagger 0.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 +191 -0
- package/README.md +88 -0
- package/dist/src/api/client.gen.d.ts +6123 -0
- package/dist/src/api/client.gen.d.ts.map +1 -0
- package/dist/src/api/client.gen.js +8494 -0
- package/dist/src/common/context.d.ts +12 -0
- package/dist/src/common/context.d.ts.map +1 -0
- package/dist/src/common/context.js +22 -0
- package/dist/src/common/errors/DaggerSDKError.d.ts +32 -0
- package/dist/src/common/errors/DaggerSDKError.d.ts.map +1 -0
- package/dist/src/common/errors/DaggerSDKError.js +26 -0
- package/dist/src/common/errors/DockerImageRefValidationError.d.ts +22 -0
- package/dist/src/common/errors/DockerImageRefValidationError.d.ts.map +1 -0
- package/dist/src/common/errors/DockerImageRefValidationError.js +21 -0
- package/dist/src/common/errors/EngineSessionConnectParamsParseError.d.ts +21 -0
- package/dist/src/common/errors/EngineSessionConnectParamsParseError.d.ts.map +1 -0
- package/dist/src/common/errors/EngineSessionConnectParamsParseError.js +20 -0
- package/dist/src/common/errors/EngineSessionConnectionTimeoutError.d.ts +21 -0
- package/dist/src/common/errors/EngineSessionConnectionTimeoutError.d.ts.map +1 -0
- package/dist/src/common/errors/EngineSessionConnectionTimeoutError.js +20 -0
- package/dist/src/common/errors/EngineSessionErrorOptions.d.ts +16 -0
- package/dist/src/common/errors/EngineSessionErrorOptions.d.ts.map +1 -0
- package/dist/src/common/errors/EngineSessionErrorOptions.js +16 -0
- package/dist/src/common/errors/ExecError.d.ts +42 -0
- package/dist/src/common/errors/ExecError.d.ts.map +1 -0
- package/dist/src/common/errors/ExecError.js +40 -0
- package/dist/src/common/errors/FunctionNotFound.d.ts +7 -0
- package/dist/src/common/errors/FunctionNotFound.d.ts.map +1 -0
- package/dist/src/common/errors/FunctionNotFound.js +9 -0
- package/dist/src/common/errors/GraphQLRequestError.d.ts +31 -0
- package/dist/src/common/errors/GraphQLRequestError.d.ts.map +1 -0
- package/dist/src/common/errors/GraphQLRequestError.js +30 -0
- package/dist/src/common/errors/InitEngineSessionBinaryError.d.ts +13 -0
- package/dist/src/common/errors/InitEngineSessionBinaryError.d.ts.map +1 -0
- package/dist/src/common/errors/InitEngineSessionBinaryError.js +15 -0
- package/dist/src/common/errors/IntrospectionError.d.ts +7 -0
- package/dist/src/common/errors/IntrospectionError.d.ts.map +1 -0
- package/dist/src/common/errors/IntrospectionError.js +9 -0
- package/dist/src/common/errors/NotAwaitedRequestError.d.ts +13 -0
- package/dist/src/common/errors/NotAwaitedRequestError.d.ts.map +1 -0
- package/dist/src/common/errors/NotAwaitedRequestError.js +15 -0
- package/dist/src/common/errors/TooManyNestedObjectsError.d.ts +21 -0
- package/dist/src/common/errors/TooManyNestedObjectsError.d.ts.map +1 -0
- package/dist/src/common/errors/TooManyNestedObjectsError.js +20 -0
- package/dist/src/common/errors/UnknownDaggerError.d.ts +13 -0
- package/dist/src/common/errors/UnknownDaggerError.d.ts.map +1 -0
- package/dist/src/common/errors/UnknownDaggerError.js +15 -0
- package/dist/src/common/errors/errors-codes.d.ts +55 -0
- package/dist/src/common/errors/errors-codes.d.ts.map +1 -0
- package/dist/src/common/errors/errors-codes.js +47 -0
- package/dist/src/common/errors/index.d.ts +15 -0
- package/dist/src/common/errors/index.d.ts.map +1 -0
- package/dist/src/common/errors/index.js +14 -0
- package/dist/src/common/graphql/client.d.ts +3 -0
- package/dist/src/common/graphql/client.d.ts.map +1 -0
- package/dist/src/common/graphql/client.js +58 -0
- package/dist/src/common/graphql/compute_query.d.ts +37 -0
- package/dist/src/common/graphql/compute_query.d.ts.map +1 -0
- package/dist/src/common/graphql/compute_query.js +171 -0
- package/dist/src/common/graphql/connect.d.ts +8 -0
- package/dist/src/common/graphql/connect.d.ts.map +1 -0
- package/dist/src/common/graphql/connect.js +22 -0
- package/dist/src/common/graphql/connection.d.ts +14 -0
- package/dist/src/common/graphql/connection.d.ts.map +1 -0
- package/dist/src/common/graphql/connection.js +23 -0
- package/dist/src/common/utils.d.ts +70 -0
- package/dist/src/common/utils.d.ts.map +1 -0
- package/dist/src/common/utils.js +6 -0
- package/dist/src/connect.d.ts +28 -0
- package/dist/src/connect.d.ts.map +1 -0
- package/dist/src/connect.js +64 -0
- package/dist/src/connectOpts.d.ts +24 -0
- package/dist/src/connectOpts.d.ts.map +1 -0
- package/dist/src/connectOpts.js +1 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +13 -0
- package/dist/src/module/decorators.d.ts +52 -0
- package/dist/src/module/decorators.d.ts.map +1 -0
- package/dist/src/module/decorators.js +55 -0
- package/dist/src/module/entrypoint/context.d.ts +8 -0
- package/dist/src/module/entrypoint/context.d.ts.map +1 -0
- package/dist/src/module/entrypoint/context.js +1 -0
- package/dist/src/module/entrypoint/entrypoint.d.ts +2 -0
- package/dist/src/module/entrypoint/entrypoint.d.ts.map +1 -0
- package/dist/src/module/entrypoint/entrypoint.js +92 -0
- package/dist/src/module/entrypoint/introspection_entrypoint.d.ts +2 -0
- package/dist/src/module/entrypoint/introspection_entrypoint.d.ts.map +1 -0
- package/dist/src/module/entrypoint/introspection_entrypoint.js +52 -0
- package/dist/src/module/entrypoint/invoke.d.ts +14 -0
- package/dist/src/module/entrypoint/invoke.d.ts.map +1 -0
- package/dist/src/module/entrypoint/invoke.js +66 -0
- package/dist/src/module/entrypoint/load.d.ts +53 -0
- package/dist/src/module/entrypoint/load.d.ts.map +1 -0
- package/dist/src/module/entrypoint/load.js +237 -0
- package/dist/src/module/entrypoint/register.d.ts +33 -0
- package/dist/src/module/entrypoint/register.d.ts.map +1 -0
- package/dist/src/module/entrypoint/register.js +227 -0
- package/dist/src/module/executor.d.ts +28 -0
- package/dist/src/module/executor.d.ts.map +1 -0
- package/dist/src/module/executor.js +171 -0
- package/dist/src/module/introspector/case_convertor.d.ts +2 -0
- package/dist/src/module/introspector/case_convertor.d.ts.map +1 -0
- package/dist/src/module/introspector/case_convertor.js +15 -0
- package/dist/src/module/introspector/dagger_module/argument.d.ts +50 -0
- package/dist/src/module/introspector/dagger_module/argument.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/argument.js +118 -0
- package/dist/src/module/introspector/dagger_module/constructor.d.ts +18 -0
- package/dist/src/module/introspector/dagger_module/constructor.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/constructor.js +38 -0
- package/dist/src/module/introspector/dagger_module/decorator.d.ts +8 -0
- package/dist/src/module/introspector/dagger_module/decorator.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/decorator.js +7 -0
- package/dist/src/module/introspector/dagger_module/enum.d.ts +41 -0
- package/dist/src/module/introspector/dagger_module/enum.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/enum.js +63 -0
- package/dist/src/module/introspector/dagger_module/enumBase.d.ts +19 -0
- package/dist/src/module/introspector/dagger_module/enumBase.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/enumBase.js +1 -0
- package/dist/src/module/introspector/dagger_module/enumClass.d.ts +41 -0
- package/dist/src/module/introspector/dagger_module/enumClass.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/enumClass.js +69 -0
- package/dist/src/module/introspector/dagger_module/function.d.ts +39 -0
- package/dist/src/module/introspector/dagger_module/function.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/function.js +102 -0
- package/dist/src/module/introspector/dagger_module/index.d.ts +15 -0
- package/dist/src/module/introspector/dagger_module/index.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/index.js +14 -0
- package/dist/src/module/introspector/dagger_module/interface.d.ts +25 -0
- package/dist/src/module/introspector/dagger_module/interface.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/interface.js +56 -0
- package/dist/src/module/introspector/dagger_module/interfaceFunction.d.ts +35 -0
- package/dist/src/module/introspector/dagger_module/interfaceFunction.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/interfaceFunction.js +92 -0
- package/dist/src/module/introspector/dagger_module/locatable.d.ts +12 -0
- package/dist/src/module/introspector/dagger_module/locatable.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/locatable.js +14 -0
- package/dist/src/module/introspector/dagger_module/module.d.ts +118 -0
- package/dist/src/module/introspector/dagger_module/module.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/module.js +316 -0
- package/dist/src/module/introspector/dagger_module/object.d.ts +46 -0
- package/dist/src/module/introspector/dagger_module/object.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/object.js +113 -0
- package/dist/src/module/introspector/dagger_module/objectBase.d.ts +32 -0
- package/dist/src/module/introspector/dagger_module/objectBase.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/objectBase.js +1 -0
- package/dist/src/module/introspector/dagger_module/property.d.ts +36 -0
- package/dist/src/module/introspector/dagger_module/property.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/property.js +82 -0
- package/dist/src/module/introspector/dagger_module/reference.d.ts +13 -0
- package/dist/src/module/introspector/dagger_module/reference.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/reference.js +33 -0
- package/dist/src/module/introspector/dagger_module/typeObject.d.ts +49 -0
- package/dist/src/module/introspector/dagger_module/typeObject.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/typeObject.js +87 -0
- package/dist/src/module/introspector/dagger_module/typeObjectProperty.d.ts +34 -0
- package/dist/src/module/introspector/dagger_module/typeObjectProperty.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/typeObjectProperty.js +60 -0
- package/dist/src/module/introspector/index.d.ts +3 -0
- package/dist/src/module/introspector/index.d.ts.map +1 -0
- package/dist/src/module/introspector/index.js +19 -0
- package/dist/src/module/introspector/typedef.d.ts +52 -0
- package/dist/src/module/introspector/typedef.d.ts.map +1 -0
- package/dist/src/module/introspector/typedef.js +1 -0
- package/dist/src/module/introspector/typescript_module/ast.d.ts +64 -0
- package/dist/src/module/introspector/typescript_module/ast.d.ts.map +1 -0
- package/dist/src/module/introspector/typescript_module/ast.js +476 -0
- package/dist/src/module/introspector/typescript_module/declarations.d.ts +15 -0
- package/dist/src/module/introspector/typescript_module/declarations.d.ts.map +1 -0
- package/dist/src/module/introspector/typescript_module/declarations.js +10 -0
- package/dist/src/module/introspector/typescript_module/index.d.ts +4 -0
- package/dist/src/module/introspector/typescript_module/index.d.ts.map +1 -0
- package/dist/src/module/introspector/typescript_module/index.js +3 -0
- package/dist/src/module/introspector/typescript_module/location.d.ts +6 -0
- package/dist/src/module/introspector/typescript_module/location.d.ts.map +1 -0
- package/dist/src/module/introspector/typescript_module/location.js +1 -0
- package/dist/src/module/introspector/typescript_module/typedef_utils.d.ts +5 -0
- package/dist/src/module/introspector/typescript_module/typedef_utils.d.ts.map +1 -0
- package/dist/src/module/introspector/typescript_module/typedef_utils.js +26 -0
- package/dist/src/module/introspector/utils/files.d.ts +5 -0
- package/dist/src/module/introspector/utils/files.d.ts.map +1 -0
- package/dist/src/module/introspector/utils/files.js +28 -0
- package/dist/src/module/registry.d.ts +109 -0
- package/dist/src/module/registry.d.ts.map +1 -0
- package/dist/src/module/registry.js +123 -0
- package/dist/src/provisioning/bin.d.ts +77 -0
- package/dist/src/provisioning/bin.d.ts.map +1 -0
- package/dist/src/provisioning/bin.js +353 -0
- package/dist/src/provisioning/default.d.ts +2 -0
- package/dist/src/provisioning/default.d.ts.map +1 -0
- package/dist/src/provisioning/default.js +2 -0
- package/dist/src/provisioning/engineconn.d.ts +30 -0
- package/dist/src/provisioning/engineconn.d.ts.map +1 -0
- package/dist/src/provisioning/engineconn.js +1 -0
- package/dist/src/provisioning/index.d.ts +4 -0
- package/dist/src/provisioning/index.d.ts.map +1 -0
- package/dist/src/provisioning/index.js +14 -0
- package/dist/src/telemetry/index.d.ts +3 -0
- package/dist/src/telemetry/index.d.ts.map +1 -0
- package/dist/src/telemetry/index.js +2 -0
- package/dist/src/telemetry/init.d.ts +21 -0
- package/dist/src/telemetry/init.d.ts.map +1 -0
- package/dist/src/telemetry/init.js +86 -0
- package/dist/src/telemetry/live_processor.d.ts +12 -0
- package/dist/src/telemetry/live_processor.d.ts.map +1 -0
- package/dist/src/telemetry/live_processor.js +13 -0
- package/dist/src/telemetry/telemetry.d.ts +16 -0
- package/dist/src/telemetry/telemetry.d.ts.map +1 -0
- package/dist/src/telemetry/telemetry.js +38 -0
- package/dist/src/telemetry/tracer.d.ts +32 -0
- package/dist/src/telemetry/tracer.d.ts.map +1 -0
- package/dist/src/telemetry/tracer.js +54 -0
- package/package.json +74 -0
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { TypeDefKind } from "../../../api/client.gen.js";
|
|
4
|
+
import { IntrospectionError } from "../../../common/errors/index.js";
|
|
5
|
+
import { isDeclarationOf } from "./declarations.js";
|
|
6
|
+
export const CLIENT_GEN_FILE = "client.gen.ts";
|
|
7
|
+
export class AST {
|
|
8
|
+
files;
|
|
9
|
+
userModule;
|
|
10
|
+
checker;
|
|
11
|
+
sourceFiles;
|
|
12
|
+
constructor(files, userModule) {
|
|
13
|
+
this.files = files;
|
|
14
|
+
this.userModule = userModule;
|
|
15
|
+
this.files = files.map((f) => path.resolve(f));
|
|
16
|
+
const program = ts.createProgram(files, {
|
|
17
|
+
experimentalDecorators: true,
|
|
18
|
+
moduleResolution: ts.ModuleResolutionKind.Node10,
|
|
19
|
+
target: ts.ScriptTarget.ES2022,
|
|
20
|
+
});
|
|
21
|
+
this.checker = program.getTypeChecker();
|
|
22
|
+
this.sourceFiles = program
|
|
23
|
+
.getSourceFiles()
|
|
24
|
+
.filter((file) => !file.isDeclarationFile);
|
|
25
|
+
}
|
|
26
|
+
findResolvedNodeByName(name,
|
|
27
|
+
/**
|
|
28
|
+
* Optionally look for a specific node kind if we already know
|
|
29
|
+
* what we're looking for.
|
|
30
|
+
*/
|
|
31
|
+
kind) {
|
|
32
|
+
let result;
|
|
33
|
+
for (const sourceFile of this.sourceFiles) {
|
|
34
|
+
ts.forEachChild(sourceFile, (node) => {
|
|
35
|
+
if (result !== undefined)
|
|
36
|
+
return;
|
|
37
|
+
// Skip if it's not from the client gen nor the user module
|
|
38
|
+
if (!sourceFile.fileName.endsWith(CLIENT_GEN_FILE) &&
|
|
39
|
+
!this.files.includes(path.resolve(sourceFile.fileName))) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (kind !== undefined && node.kind === kind) {
|
|
43
|
+
const isDeclarationValid = isDeclarationOf[kind](node);
|
|
44
|
+
if (!isDeclarationValid)
|
|
45
|
+
return;
|
|
46
|
+
const convertedNode = node;
|
|
47
|
+
if (!convertedNode.name || convertedNode.name.getText() !== name) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const symbol = this.checker.getSymbolAtLocation(convertedNode.name);
|
|
51
|
+
if (!symbol) {
|
|
52
|
+
console.debug(`missing symbol for ${name} at ${sourceFile.fileName}:${node.pos}`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
result = {
|
|
56
|
+
type: kind,
|
|
57
|
+
node: convertedNode,
|
|
58
|
+
symbol: symbol,
|
|
59
|
+
file: sourceFile,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
findAllDeclarations(kind) {
|
|
67
|
+
const results = [];
|
|
68
|
+
for (const sourceFile of this.sourceFiles) {
|
|
69
|
+
ts.forEachChild(sourceFile, (node) => {
|
|
70
|
+
// Skip if it's not from the client gen nor the user module
|
|
71
|
+
if (!sourceFile.fileName.endsWith(CLIENT_GEN_FILE) &&
|
|
72
|
+
!this.files.includes(path.resolve(sourceFile.fileName))) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (kind !== undefined && node.kind === kind) {
|
|
76
|
+
const isDeclarationValid = isDeclarationOf[kind](node);
|
|
77
|
+
if (!isDeclarationValid)
|
|
78
|
+
return;
|
|
79
|
+
const convertedNode = node;
|
|
80
|
+
if (!convertedNode.name) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const symbol = this.checker.getSymbolAtLocation(convertedNode.name);
|
|
84
|
+
if (!symbol) {
|
|
85
|
+
console.debug(`missing symbol for ${convertedNode.name.getText()} at ${sourceFile.fileName}:${node.pos}`);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
results.push({
|
|
89
|
+
type: kind,
|
|
90
|
+
node: convertedNode,
|
|
91
|
+
symbol: symbol,
|
|
92
|
+
file: sourceFile,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return results;
|
|
98
|
+
}
|
|
99
|
+
getTypeFromTypeAlias(typeAlias) {
|
|
100
|
+
const symbol = this.getSymbolOrThrow(typeAlias.name);
|
|
101
|
+
return this.checker.getDeclaredTypeOfSymbol(symbol);
|
|
102
|
+
}
|
|
103
|
+
static getNodePosition(node) {
|
|
104
|
+
const sourceFile = node.getSourceFile();
|
|
105
|
+
const position = ts.getLineAndCharacterOfPosition(sourceFile, node.getStart());
|
|
106
|
+
return `${sourceFile.fileName}:${position.line}:${position.character}`;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Returns the location of the node in the source file.
|
|
110
|
+
*
|
|
111
|
+
* The filepath is relative to the module root directory.
|
|
112
|
+
* Ideally, we use the identifier of the node accessible by node.name but fallback
|
|
113
|
+
* to node itself if it's not available.
|
|
114
|
+
*
|
|
115
|
+
* The TypeScript SDK based it's line and column on index 0 but editors starts
|
|
116
|
+
* at 1 so we always add 1 to fix that difference.
|
|
117
|
+
*/
|
|
118
|
+
static getNodeLocation(node) {
|
|
119
|
+
const sourceFile = node.getSourceFile();
|
|
120
|
+
// Use the identifier of the node if available.
|
|
121
|
+
const targetNode = node.name ?? node;
|
|
122
|
+
const position = ts.getLineAndCharacterOfPosition(sourceFile, targetNode.getStart(sourceFile));
|
|
123
|
+
// sourceFile.fileName is the absolute path to the file, we need to get the relative path
|
|
124
|
+
// from the module path so we exclude the module path from the given path.
|
|
125
|
+
// But since root will always start with `/src`, we want to catch the second `src`
|
|
126
|
+
// inside the module.
|
|
127
|
+
const pathParts = path.resolve(sourceFile.fileName).split(path.sep);
|
|
128
|
+
const srcIndex = pathParts.indexOf("src", 2);
|
|
129
|
+
return {
|
|
130
|
+
filepath: pathParts.slice(srcIndex).join(path.sep),
|
|
131
|
+
line: position.line + 1,
|
|
132
|
+
column: position.character + 1,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
getDocFromSymbol(symbol) {
|
|
136
|
+
return this.getSymbolDoc(symbol).description;
|
|
137
|
+
}
|
|
138
|
+
getSymbolDoc(symbol) {
|
|
139
|
+
const description = ts
|
|
140
|
+
.displayPartsToString(symbol.getDocumentationComment(this.checker))
|
|
141
|
+
.trim();
|
|
142
|
+
let deprecated;
|
|
143
|
+
let hasDeprecatedTag = false;
|
|
144
|
+
for (const tag of symbol.getJsDocTags()) {
|
|
145
|
+
if (tag.name !== "deprecated")
|
|
146
|
+
continue;
|
|
147
|
+
hasDeprecatedTag = true;
|
|
148
|
+
const text = tag.text?.map((part) => ("text" in part ? part.text : part)).join("") ??
|
|
149
|
+
"";
|
|
150
|
+
deprecated = text.trim();
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
if (!hasDeprecatedTag) {
|
|
154
|
+
return { description };
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
description,
|
|
158
|
+
deprecated: deprecated ?? "",
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
getSymbolOrThrow(node) {
|
|
162
|
+
const symbol = this.getSymbol(node);
|
|
163
|
+
if (!symbol) {
|
|
164
|
+
throw new IntrospectionError(`could not find symbol at ${AST.getNodePosition(node)}`);
|
|
165
|
+
}
|
|
166
|
+
return symbol;
|
|
167
|
+
}
|
|
168
|
+
getSignatureFromFunctionOrThrow(node) {
|
|
169
|
+
const signature = this.checker.getSignatureFromDeclaration(node);
|
|
170
|
+
if (!signature) {
|
|
171
|
+
throw new IntrospectionError(`could not find signature at ${AST.getNodePosition(node)}`);
|
|
172
|
+
}
|
|
173
|
+
return signature;
|
|
174
|
+
}
|
|
175
|
+
getSymbol(node) {
|
|
176
|
+
return this.checker.getSymbolAtLocation(node);
|
|
177
|
+
}
|
|
178
|
+
isNodeDecoratedWith(node, daggerDecorator) {
|
|
179
|
+
const decorators = ts.getDecorators(node);
|
|
180
|
+
if (!decorators) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
const decorator = decorators.find((d) => d.expression.getText().startsWith(daggerDecorator));
|
|
184
|
+
if (!decorator) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
if (!ts.isCallExpression(decorator.expression)) {
|
|
188
|
+
throw new IntrospectionError(`decorator at ${AST.getNodePosition(node)} should be a call expression, please use ${daggerDecorator}() instead.`);
|
|
189
|
+
}
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
getDecoratorArgument(node, daggerDecorator, type, position = 0) {
|
|
193
|
+
const decorators = ts.getDecorators(node);
|
|
194
|
+
if (!decorators) {
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
const decorator = decorators.find((d) => d.expression.getText().startsWith(daggerDecorator));
|
|
198
|
+
if (!decorator) {
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
const argument = decorator.expression.arguments[position];
|
|
202
|
+
if (!argument) {
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
switch (type) {
|
|
206
|
+
case "string":
|
|
207
|
+
return argument.getText();
|
|
208
|
+
case "object":
|
|
209
|
+
return eval(`(${argument.getText()})`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
unwrapTypeStringFromPromise(type) {
|
|
213
|
+
if (type.startsWith("Promise<")) {
|
|
214
|
+
return type.slice("Promise<".length, -">".length);
|
|
215
|
+
}
|
|
216
|
+
if (type.startsWith("Awaited<")) {
|
|
217
|
+
return type.slice("Awaited<".length, -">".length);
|
|
218
|
+
}
|
|
219
|
+
return type;
|
|
220
|
+
}
|
|
221
|
+
unwrapTypeStringFromArray(type) {
|
|
222
|
+
if (type.endsWith("[]")) {
|
|
223
|
+
return type.replace("[]", "");
|
|
224
|
+
}
|
|
225
|
+
if (type.startsWith("Array<")) {
|
|
226
|
+
return type.slice("Array<".length, -">".length);
|
|
227
|
+
}
|
|
228
|
+
return type;
|
|
229
|
+
}
|
|
230
|
+
stringTypeToUnwrappedType(type) {
|
|
231
|
+
type = this.unwrapTypeStringFromPromise(type);
|
|
232
|
+
// If they are difference, that means we upwrapped the array.
|
|
233
|
+
const extractedTypeFromArray = this.unwrapTypeStringFromArray(type);
|
|
234
|
+
if (extractedTypeFromArray !== type) {
|
|
235
|
+
return this.stringTypeToUnwrappedType(extractedTypeFromArray);
|
|
236
|
+
}
|
|
237
|
+
return type;
|
|
238
|
+
}
|
|
239
|
+
typeToStringType(type) {
|
|
240
|
+
const stringType = this.checker.typeToString(type);
|
|
241
|
+
return this.stringTypeToUnwrappedType(stringType);
|
|
242
|
+
}
|
|
243
|
+
tsTypeToTypeDef(node, type) {
|
|
244
|
+
if (type.flags & ts.TypeFlags.String)
|
|
245
|
+
return { kind: TypeDefKind.StringKind };
|
|
246
|
+
if (type.flags & ts.TypeFlags.Number) {
|
|
247
|
+
// Float will be interpreted as number by the TypeScript compiler so we need to check if the
|
|
248
|
+
// text is "float" to know if it's a float or an integer.
|
|
249
|
+
// It can also be interpreted as a reference, but this is handled separately at an upper level.
|
|
250
|
+
if (node.getText().includes("float")) {
|
|
251
|
+
return { kind: TypeDefKind.FloatKind };
|
|
252
|
+
}
|
|
253
|
+
return { kind: TypeDefKind.IntegerKind };
|
|
254
|
+
}
|
|
255
|
+
if (type.flags & ts.TypeFlags.Boolean)
|
|
256
|
+
return { kind: TypeDefKind.BooleanKind };
|
|
257
|
+
if (type.flags & ts.TypeFlags.Void)
|
|
258
|
+
return { kind: TypeDefKind.VoidKind };
|
|
259
|
+
// If a type has a flag Object, is can basically be anything.
|
|
260
|
+
// We firstly wants to see if it's a promise or an array so we can unwrap the
|
|
261
|
+
// actual type.
|
|
262
|
+
if (type.flags & ts.TypeFlags.Object) {
|
|
263
|
+
const objectType = type;
|
|
264
|
+
// If it's a reference, that means it's a generic type like
|
|
265
|
+
// `Promise<T>` or `number[]` or `Array<T>`.
|
|
266
|
+
if (objectType.objectFlags & ts.ObjectFlags.Reference) {
|
|
267
|
+
const typeArguments = this.checker.getTypeArguments(type);
|
|
268
|
+
switch (typeArguments.length) {
|
|
269
|
+
case 0:
|
|
270
|
+
// Might change after to support more complex type
|
|
271
|
+
break;
|
|
272
|
+
case 1: {
|
|
273
|
+
const typeArgument = typeArguments[0];
|
|
274
|
+
if (type.symbol.getName() === "Promise") {
|
|
275
|
+
return this.tsTypeToTypeDef(node, typeArgument);
|
|
276
|
+
}
|
|
277
|
+
if (type.symbol.getName() === "Array") {
|
|
278
|
+
return {
|
|
279
|
+
kind: TypeDefKind.ListKind,
|
|
280
|
+
typeDef: this.tsTypeToTypeDef(node, typeArgument),
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
default: {
|
|
286
|
+
throw new IntrospectionError(`could not resolve type ${type.symbol.getName()} at ${AST.getNodePosition(node)}, dagger does not support generics with argument yet.`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
resolveParameterDefaultValueTypeReference(expression, value) {
|
|
293
|
+
const type = typeof value;
|
|
294
|
+
switch (type) {
|
|
295
|
+
case "string":
|
|
296
|
+
case "number": // float is also included here
|
|
297
|
+
case "bigint":
|
|
298
|
+
case "boolean":
|
|
299
|
+
case "object":
|
|
300
|
+
// Value will be jsonified on registration.
|
|
301
|
+
return value;
|
|
302
|
+
default:
|
|
303
|
+
// If we cannot resolve the value, we skip it and let the value be resolved automatically by the runtime
|
|
304
|
+
return undefined;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
// Try to extract literal values (enum members, string/number/boolean/bigint
|
|
308
|
+
// literals) directly from the type checker. Returns undefined if the
|
|
309
|
+
// expression is not a literal.
|
|
310
|
+
getLiteralValueFromExpression(expression) {
|
|
311
|
+
const type = this.checker.getTypeAtLocation(expression);
|
|
312
|
+
if (!type) {
|
|
313
|
+
return undefined;
|
|
314
|
+
}
|
|
315
|
+
const resolveLiteral = (t) => {
|
|
316
|
+
if (t.flags & ts.TypeFlags.BooleanLiteral) {
|
|
317
|
+
const intrinsic = t;
|
|
318
|
+
// Handle boolean value
|
|
319
|
+
switch (intrinsic.intrinsicName) {
|
|
320
|
+
case "true":
|
|
321
|
+
return true;
|
|
322
|
+
case "false":
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (t.flags &
|
|
327
|
+
(ts.TypeFlags.EnumLiteral |
|
|
328
|
+
ts.TypeFlags.StringLiteral |
|
|
329
|
+
ts.TypeFlags.NumberLiteral |
|
|
330
|
+
ts.TypeFlags.BigIntLiteral)) {
|
|
331
|
+
const literal = t;
|
|
332
|
+
if (literal.value !== undefined) {
|
|
333
|
+
return literal.value;
|
|
334
|
+
}
|
|
335
|
+
// Some literals only expose `intrinsicName`. Example:
|
|
336
|
+
// const yes = true; function use(flag: boolean = yes) {}
|
|
337
|
+
// The checker reports `intrinsicName: "true"` without a `value`, so we fallback.
|
|
338
|
+
const intrinsic = literal;
|
|
339
|
+
if (intrinsic.intrinsicName !== undefined) {
|
|
340
|
+
return intrinsic.intrinsicName;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return undefined;
|
|
344
|
+
};
|
|
345
|
+
if (type.isUnion()) {
|
|
346
|
+
// Walk union members to surface the literal. Example:
|
|
347
|
+
// ```ts
|
|
348
|
+
// const defaults = { proto: NetworkProtocol.Udp }
|
|
349
|
+
// function use(proto: NetworkProtocol = defaults.proto) {}
|
|
350
|
+
// ```
|
|
351
|
+
// The checker reports `defaults.proto` as `NetworkProtocol.Tcp | NetworkProtocol.Udp`,
|
|
352
|
+
// so we inspect each subtype to recover the actual default value.
|
|
353
|
+
for (const subtype of type.types) {
|
|
354
|
+
const literal = resolveLiteral(subtype);
|
|
355
|
+
if (literal !== undefined) {
|
|
356
|
+
return literal;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return undefined;
|
|
360
|
+
}
|
|
361
|
+
return resolveLiteral(type);
|
|
362
|
+
}
|
|
363
|
+
warnUnresolvedDefaultValue(expression) {
|
|
364
|
+
console.warn(`default value '${expression.getText()}' at ${AST.getNodePosition(expression)} cannot be resolved, dagger does not support object or function as default value.
|
|
365
|
+
The value will be ignored by the introspection and resolve at the runtime.`);
|
|
366
|
+
}
|
|
367
|
+
resolveParameterDefaultValue(expression) {
|
|
368
|
+
const kind = expression.kind;
|
|
369
|
+
switch (kind) {
|
|
370
|
+
case ts.SyntaxKind.StringLiteral:
|
|
371
|
+
return `${eval(expression.getText())}`;
|
|
372
|
+
case ts.SyntaxKind.NumericLiteral:
|
|
373
|
+
return parseInt(expression.getText());
|
|
374
|
+
case ts.SyntaxKind.TrueKeyword:
|
|
375
|
+
return true;
|
|
376
|
+
case ts.SyntaxKind.FalseKeyword:
|
|
377
|
+
return false;
|
|
378
|
+
case ts.SyntaxKind.NullKeyword:
|
|
379
|
+
return null;
|
|
380
|
+
case ts.SyntaxKind.ArrayLiteralExpression:
|
|
381
|
+
return eval(expression.getText());
|
|
382
|
+
case ts.SyntaxKind.Identifier: {
|
|
383
|
+
const symbol = this.checker.getSymbolAtLocation(expression);
|
|
384
|
+
if (!symbol) {
|
|
385
|
+
throw new IntrospectionError(`could not resolve default value reference to the variable: '${expression.getText()}' from ${AST.getNodePosition(expression)}. Is it exported by the module?`);
|
|
386
|
+
}
|
|
387
|
+
// Parse the default value from the variable declaration
|
|
388
|
+
// ```
|
|
389
|
+
// export const foo = "A"
|
|
390
|
+
//
|
|
391
|
+
// function bar(baz: string = foo) {}
|
|
392
|
+
// ```
|
|
393
|
+
const decl = symbol.valueDeclaration ?? symbol.declarations?.[0];
|
|
394
|
+
if (!decl) {
|
|
395
|
+
this.warnUnresolvedDefaultValue(expression);
|
|
396
|
+
return undefined;
|
|
397
|
+
}
|
|
398
|
+
if (ts.isVariableDeclaration(decl) && decl.initializer) {
|
|
399
|
+
return this.resolveParameterDefaultValue(decl.initializer);
|
|
400
|
+
}
|
|
401
|
+
// Parse the default value from the enum member
|
|
402
|
+
// ```
|
|
403
|
+
// enum Foo {
|
|
404
|
+
// A = "a"
|
|
405
|
+
// }
|
|
406
|
+
//
|
|
407
|
+
// function bar(baz: string = Foo.A) {}
|
|
408
|
+
// ```
|
|
409
|
+
if (ts.isEnumMember(decl)) {
|
|
410
|
+
const val = this.checker.getConstantValue(decl);
|
|
411
|
+
if (val !== undefined)
|
|
412
|
+
return val;
|
|
413
|
+
if (decl.initializer)
|
|
414
|
+
return this.resolveParameterDefaultValue(decl.initializer);
|
|
415
|
+
}
|
|
416
|
+
// Parse the default value from the import specifier
|
|
417
|
+
// ```
|
|
418
|
+
// import { foo } from "bar"
|
|
419
|
+
//
|
|
420
|
+
// function bar(baz: string = foo) {}
|
|
421
|
+
// ```
|
|
422
|
+
if (ts.isImportSpecifier(decl)) {
|
|
423
|
+
const aliased = this.checker.getAliasedSymbol(symbol);
|
|
424
|
+
const aliasedDecl = aliased?.valueDeclaration ?? aliased?.declarations?.[0];
|
|
425
|
+
if (aliasedDecl &&
|
|
426
|
+
ts.isVariableDeclaration(aliasedDecl) &&
|
|
427
|
+
aliasedDecl.initializer) {
|
|
428
|
+
return this.resolveParameterDefaultValue(aliasedDecl.initializer);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
// Warn the user if the default value cannot be resolved
|
|
432
|
+
this.warnUnresolvedDefaultValue(expression);
|
|
433
|
+
return undefined;
|
|
434
|
+
}
|
|
435
|
+
case ts.SyntaxKind.PropertyAccessExpression: {
|
|
436
|
+
const propertyAccess = expression;
|
|
437
|
+
// Quick path: TypeScript already computed the literal value.
|
|
438
|
+
const directConstant = this.checker.getConstantValue(propertyAccess);
|
|
439
|
+
if (directConstant !== undefined) {
|
|
440
|
+
return directConstant;
|
|
441
|
+
}
|
|
442
|
+
// Otherwise inspect the enum member backing the property accessor.
|
|
443
|
+
const nameSymbol = this.checker.getSymbolAtLocation(propertyAccess.name);
|
|
444
|
+
if (nameSymbol) {
|
|
445
|
+
const declarations = nameSymbol.declarations ?? [];
|
|
446
|
+
const decls = nameSymbol.valueDeclaration
|
|
447
|
+
? [nameSymbol.valueDeclaration, ...declarations]
|
|
448
|
+
: declarations;
|
|
449
|
+
for (const decl of decls) {
|
|
450
|
+
if (ts.isEnumMember(decl)) {
|
|
451
|
+
const val = this.checker.getConstantValue(decl);
|
|
452
|
+
if (val !== undefined) {
|
|
453
|
+
return val;
|
|
454
|
+
}
|
|
455
|
+
if (decl.initializer) {
|
|
456
|
+
return this.resolveParameterDefaultValue(decl.initializer);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
// Fall back to literal type information if available.
|
|
462
|
+
const literal = this.getLiteralValueFromExpression(propertyAccess);
|
|
463
|
+
if (literal !== undefined) {
|
|
464
|
+
return literal;
|
|
465
|
+
}
|
|
466
|
+
// Warn the user if the default value cannot be resolved.
|
|
467
|
+
this.warnUnresolvedDefaultValue(expression);
|
|
468
|
+
return undefined;
|
|
469
|
+
}
|
|
470
|
+
default: {
|
|
471
|
+
// Warn the user if the default value cannot be resolved
|
|
472
|
+
this.warnUnresolvedDefaultValue(expression);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
export type DeclarationsMap = {
|
|
3
|
+
[ts.SyntaxKind.ClassDeclaration]: ts.ClassDeclaration;
|
|
4
|
+
[ts.SyntaxKind.MethodDeclaration]: ts.MethodDeclaration;
|
|
5
|
+
[ts.SyntaxKind.PropertyDeclaration]: ts.PropertyDeclaration;
|
|
6
|
+
[ts.SyntaxKind.FunctionDeclaration]: ts.FunctionDeclaration;
|
|
7
|
+
[ts.SyntaxKind.EnumDeclaration]: ts.EnumDeclaration;
|
|
8
|
+
[ts.SyntaxKind.InterfaceDeclaration]: ts.InterfaceDeclaration;
|
|
9
|
+
[ts.SyntaxKind.TypeAliasDeclaration]: ts.TypeAliasDeclaration;
|
|
10
|
+
};
|
|
11
|
+
export type Declarations<T extends ts.SyntaxKind> = T extends keyof DeclarationsMap ? DeclarationsMap[T] : ts.Node;
|
|
12
|
+
export declare const isDeclarationOf: {
|
|
13
|
+
[K in keyof DeclarationsMap]: (node: ts.Node) => node is DeclarationsMap[K];
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=declarations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declarations.d.ts","sourceRoot":"","sources":["../../../../../src/module/introspector/typescript_module/declarations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,MAAM,MAAM,eAAe,GAAG;IAC5B,CAAC,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAA;IACrD,CAAC,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAA;IACvD,CAAC,EAAE,CAAC,UAAU,CAAC,mBAAmB,CAAC,EAAE,EAAE,CAAC,mBAAmB,CAAA;IAC3D,CAAC,EAAE,CAAC,UAAU,CAAC,mBAAmB,CAAC,EAAE,EAAE,CAAC,mBAAmB,CAAA;IAC3D,CAAC,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,EAAE,CAAC,eAAe,CAAA;IACnD,CAAC,EAAE,CAAC,UAAU,CAAC,oBAAoB,CAAC,EAAE,EAAE,CAAC,oBAAoB,CAAA;IAC7D,CAAC,EAAE,CAAC,UAAU,CAAC,oBAAoB,CAAC,EAAE,EAAE,CAAC,oBAAoB,CAAA;CAC9D,CAAA;AAED,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,EAAE,CAAC,UAAU,IAC9C,CAAC,SAAS,MAAM,eAAe,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,CAAA;AAEhE,eAAO,MAAM,eAAe,EAAE;KAC3B,CAAC,IAAI,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,IAAI,IAAI,eAAe,CAAC,CAAC,CAAC;CAS5E,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
export const isDeclarationOf = {
|
|
3
|
+
[ts.SyntaxKind.ClassDeclaration]: ts.isClassDeclaration,
|
|
4
|
+
[ts.SyntaxKind.MethodDeclaration]: ts.isMethodDeclaration,
|
|
5
|
+
[ts.SyntaxKind.PropertyDeclaration]: ts.isPropertyDeclaration,
|
|
6
|
+
[ts.SyntaxKind.FunctionDeclaration]: ts.isFunctionDeclaration,
|
|
7
|
+
[ts.SyntaxKind.EnumDeclaration]: ts.isEnumDeclaration,
|
|
8
|
+
[ts.SyntaxKind.InterfaceDeclaration]: ts.isInterfaceDeclaration,
|
|
9
|
+
[ts.SyntaxKind.TypeAliasDeclaration]: ts.isTypeAliasDeclaration,
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/module/introspector/typescript_module/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"location.d.ts","sourceRoot":"","sources":["../../../../../src/module/introspector/typescript_module/location.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TypeDefKind } from "../../../api/client.gen.js";
|
|
2
|
+
import { TypeDef } from "../typedef.js";
|
|
3
|
+
export declare function isTypeDefResolved(typeDef: TypeDef<TypeDefKind>): boolean;
|
|
4
|
+
export declare function resolveTypeDef(typeDef: TypeDef<TypeDefKind> | undefined, reference: TypeDef<TypeDefKind>): TypeDef<TypeDefKind>;
|
|
5
|
+
//# sourceMappingURL=typedef_utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typedef_utils.d.ts","sourceRoot":"","sources":["../../../../../src/module/introspector/typescript_module/typedef_utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAExD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAgBxE;AAED,wBAAgB,cAAc,CAC5B,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,SAAS,EACzC,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,GAC9B,OAAO,CAAC,WAAW,CAAC,CAetB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TypeDefKind } from "../../../api/client.gen.js";
|
|
2
|
+
import { IntrospectionError } from "../../../common/errors/index.js";
|
|
3
|
+
export function isTypeDefResolved(typeDef) {
|
|
4
|
+
if (typeDef.kind !== TypeDefKind.ListKind) {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
const arrayTypeDef = typeDef;
|
|
8
|
+
if (arrayTypeDef.typeDef === undefined) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (arrayTypeDef.typeDef.kind === TypeDefKind.ListKind) {
|
|
12
|
+
return isTypeDefResolved(arrayTypeDef.typeDef);
|
|
13
|
+
}
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
export function resolveTypeDef(typeDef, reference) {
|
|
17
|
+
if (typeDef === undefined) {
|
|
18
|
+
return reference;
|
|
19
|
+
}
|
|
20
|
+
if (typeDef.kind === TypeDefKind.ListKind) {
|
|
21
|
+
const listTypeDef = typeDef;
|
|
22
|
+
listTypeDef.typeDef = resolveTypeDef(listTypeDef.typeDef, reference);
|
|
23
|
+
return listTypeDef;
|
|
24
|
+
}
|
|
25
|
+
throw new IntrospectionError(`type ${JSON.stringify(typeDef)} has already been resolved, it should not be overwritten ; reference: ${JSON.stringify(reference)}`);
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../../../src/module/introspector/utils/files.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,wBAAsB,SAAS,CAAC,GAAG,SAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA0B5D"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
/**
|
|
4
|
+
* Extensions supported by the loader.
|
|
5
|
+
*/
|
|
6
|
+
const allowedExtensions = [".ts", ".mts"];
|
|
7
|
+
/**
|
|
8
|
+
* Returns a list of path of all files in the given directory
|
|
9
|
+
*/
|
|
10
|
+
export async function listFiles(dir = ".") {
|
|
11
|
+
const res = await Promise.all(fs.readdirSync(dir).map(async (file) => {
|
|
12
|
+
const filepath = path.join(dir, file);
|
|
13
|
+
// Ignore node_modules and transpiled typescript
|
|
14
|
+
if (filepath.includes("node_modules") || filepath.includes("dist")) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
const stat = fs.statSync(filepath);
|
|
18
|
+
if (stat.isDirectory()) {
|
|
19
|
+
return await listFiles(filepath);
|
|
20
|
+
}
|
|
21
|
+
const ext = path.extname(filepath);
|
|
22
|
+
if (allowedExtensions.find((allowedExt) => allowedExt === ext)) {
|
|
23
|
+
return [path.join(dir, file)];
|
|
24
|
+
}
|
|
25
|
+
return [];
|
|
26
|
+
}));
|
|
27
|
+
return res.reduce((p, c) => [...c, ...p], []);
|
|
28
|
+
}
|