@dagger.io/dagger 0.14.0 → 0.15.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/{api → src/api}/client.gen.d.ts +145 -201
- package/dist/src/api/client.gen.d.ts.map +1 -0
- package/dist/{api → src/api}/client.gen.js +1114 -3520
- 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/{common → src/common}/errors/DaggerSDKError.d.ts +1 -1
- package/dist/src/common/errors/DaggerSDKError.d.ts.map +1 -0
- package/dist/src/common/errors/DockerImageRefValidationError.d.ts.map +1 -0
- package/dist/src/common/errors/EngineSessionConnectParamsParseError.d.ts.map +1 -0
- package/dist/src/common/errors/EngineSessionConnectionTimeoutError.d.ts.map +1 -0
- package/dist/src/common/errors/EngineSessionErrorOptions.d.ts.map +1 -0
- package/dist/{common → src/common}/errors/ExecError.d.ts +0 -1
- package/dist/src/common/errors/ExecError.d.ts.map +1 -0
- package/dist/{common → src/common}/errors/ExecError.js +0 -3
- package/dist/src/common/errors/FunctionNotFound.d.ts.map +1 -0
- package/dist/src/common/errors/GraphQLRequestError.d.ts.map +1 -0
- package/dist/src/common/errors/InitEngineSessionBinaryError.d.ts.map +1 -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.map +1 -0
- package/dist/src/common/errors/TooManyNestedObjectsError.d.ts.map +1 -0
- package/dist/src/common/errors/UnknownDaggerError.d.ts.map +1 -0
- package/dist/{common → src/common}/errors/errors-codes.d.ts +4 -0
- package/dist/src/common/errors/errors-codes.d.ts.map +1 -0
- package/dist/{common → src/common}/errors/errors-codes.js +4 -0
- package/dist/{common → src/common}/errors/index.d.ts +2 -0
- package/dist/src/common/errors/index.d.ts.map +1 -0
- package/dist/{common → src/common}/errors/index.js +2 -0
- package/dist/src/common/graphql/client.d.ts.map +1 -0
- package/dist/{api/utils.d.ts → src/common/graphql/compute_query.d.ts} +10 -2
- package/dist/src/common/graphql/compute_query.d.ts.map +1 -0
- package/dist/{api/utils.js → src/common/graphql/compute_query.js} +4 -4
- 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/{common → src/common}/utils.d.ts +4 -4
- package/dist/src/common/utils.d.ts.map +1 -0
- package/dist/{connect.d.ts → src/connect.d.ts} +0 -4
- package/dist/src/connect.d.ts.map +1 -0
- package/dist/{connect.js → src/connect.js} +21 -23
- package/dist/src/connectOpts.d.ts.map +1 -0
- package/dist/{index.d.ts → src/index.d.ts} +5 -5
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +10 -0
- package/dist/{introspector/decorators → src/module}/decorators.d.ts +3 -3
- package/dist/src/module/decorators.d.ts.map +1 -0
- package/dist/{introspector/decorators → src/module}/decorators.js +1 -1
- package/dist/{entrypoint → src/module/entrypoint}/context.d.ts +1 -1
- package/dist/src/module/entrypoint/context.d.ts.map +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/{entrypoint → src/module/entrypoint}/entrypoint.js +7 -16
- package/dist/{entrypoint → src/module/entrypoint}/invoke.d.ts +2 -2
- package/dist/src/module/entrypoint/invoke.d.ts.map +1 -0
- package/dist/{entrypoint → src/module/entrypoint}/invoke.js +2 -2
- package/dist/{entrypoint → src/module/entrypoint}/load.d.ts +6 -11
- package/dist/src/module/entrypoint/load.d.ts.map +1 -0
- package/dist/{entrypoint → src/module/entrypoint}/load.js +15 -5
- package/dist/src/module/entrypoint/register.d.ts +7 -0
- package/dist/src/module/entrypoint/register.d.ts.map +1 -0
- package/dist/{entrypoint → src/module/entrypoint}/register.js +3 -3
- package/dist/{introspector/executor → src/module}/executor.d.ts +4 -2
- package/dist/src/module/executor.d.ts.map +1 -0
- package/dist/src/module/executor.js +45 -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 +17 -0
- package/dist/src/module/introspector/dagger_module/argument.d.ts +47 -0
- package/dist/src/module/introspector/dagger_module/argument.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/argument.js +109 -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 +7 -0
- package/dist/src/module/introspector/dagger_module/decorator.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/decorator.js +6 -0
- package/dist/src/module/introspector/dagger_module/enum.d.ts +37 -0
- package/dist/src/module/introspector/dagger_module/enum.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/enum.js +55 -0
- package/dist/src/module/introspector/dagger_module/enumBase.d.ts +17 -0
- package/dist/src/module/introspector/dagger_module/enumBase.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/enumClass.d.ts +37 -0
- package/dist/src/module/introspector/dagger_module/enumClass.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/enumClass.js +61 -0
- package/dist/src/module/introspector/dagger_module/function.d.ts +35 -0
- package/dist/src/module/introspector/dagger_module/function.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/function.js +86 -0
- package/dist/src/module/introspector/dagger_module/index.d.ts +13 -0
- package/dist/src/module/introspector/dagger_module/index.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/index.js +12 -0
- package/dist/src/module/introspector/dagger_module/module.d.ts +110 -0
- package/dist/src/module/introspector/dagger_module/module.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/module.js +275 -0
- package/dist/src/module/introspector/dagger_module/object.d.ts +29 -0
- package/dist/src/module/introspector/dagger_module/object.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/object.js +91 -0
- package/dist/src/module/introspector/dagger_module/objectBase.d.ts +29 -0
- package/dist/src/module/introspector/dagger_module/objectBase.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/property.d.ts +33 -0
- package/dist/src/module/introspector/dagger_module/property.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/property.js +76 -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 +25 -0
- package/dist/src/module/introspector/dagger_module/typeObject.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/typeObject.js +58 -0
- package/dist/src/module/introspector/dagger_module/typeObjectProperty.d.ts +31 -0
- package/dist/src/module/introspector/dagger_module/typeObjectProperty.d.ts.map +1 -0
- package/dist/src/module/introspector/dagger_module/typeObjectProperty.js +54 -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 +16 -0
- package/dist/{introspector/scanner/typeDefs.d.ts → src/module/introspector/typedef.d.ts} +1 -1
- package/dist/src/module/introspector/typedef.d.ts.map +1 -0
- package/dist/src/module/introspector/typescript_module/ast.d.ts +42 -0
- package/dist/src/module/introspector/typescript_module/ast.d.ts.map +1 -0
- package/dist/src/module/introspector/typescript_module/ast.js +254 -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/explorer.d.ts +4 -0
- package/dist/src/module/introspector/typescript_module/explorer.d.ts.map +1 -0
- package/dist/src/module/introspector/typescript_module/explorer.js +16 -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/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.map +1 -0
- package/dist/{introspector → src/module/introspector}/utils/files.js +1 -1
- package/dist/src/module/registry.d.ts.map +1 -0
- package/dist/{introspector/registry → src/module}/registry.js +1 -1
- package/dist/src/provisioning/bin.d.ts.map +1 -0
- package/dist/{provisioning → src/provisioning}/bin.js +1 -1
- package/dist/src/provisioning/default.d.ts +2 -0
- package/dist/src/provisioning/default.d.ts.map +1 -0
- package/dist/{provisioning → src/provisioning}/default.js +1 -1
- 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.map +1 -0
- package/dist/src/telemetry/init.d.ts.map +1 -0
- package/dist/src/telemetry/telemetry.d.ts.map +1 -0
- package/dist/src/telemetry/tracer.d.ts.map +1 -0
- package/package.json +5 -4
- package/dist/api/client.gen.d.ts.map +0 -1
- package/dist/api/utils.d.ts.map +0 -1
- package/dist/common/errors/DaggerSDKError.d.ts.map +0 -1
- package/dist/common/errors/DockerImageRefValidationError.d.ts.map +0 -1
- package/dist/common/errors/EngineSessionConnectParamsParseError.d.ts.map +0 -1
- package/dist/common/errors/EngineSessionConnectionTimeoutError.d.ts.map +0 -1
- package/dist/common/errors/EngineSessionErrorOptions.d.ts.map +0 -1
- package/dist/common/errors/ExecError.d.ts.map +0 -1
- package/dist/common/errors/FunctionNotFound.d.ts.map +0 -1
- package/dist/common/errors/GraphQLRequestError.d.ts.map +0 -1
- package/dist/common/errors/InitEngineSessionBinaryError.d.ts.map +0 -1
- package/dist/common/errors/NotAwaitedRequestError.d.ts.map +0 -1
- package/dist/common/errors/TooManyNestedObjectsError.d.ts.map +0 -1
- package/dist/common/errors/UnknownDaggerError.d.ts.map +0 -1
- package/dist/common/errors/errors-codes.d.ts.map +0 -1
- package/dist/common/errors/index.d.ts.map +0 -1
- package/dist/common/utils.d.ts.map +0 -1
- package/dist/connect.d.ts.map +0 -1
- package/dist/connectOpts.d.ts.map +0 -1
- package/dist/context/builder.d.ts +0 -9
- package/dist/context/builder.d.ts.map +0 -1
- package/dist/context/builder.js +0 -34
- package/dist/context/context.d.ts +0 -40
- package/dist/context/context.d.ts.map +0 -1
- package/dist/context/context.js +0 -53
- package/dist/entrypoint/context.d.ts.map +0 -1
- package/dist/entrypoint/entrypoint.d.ts +0 -2
- package/dist/entrypoint/entrypoint.d.ts.map +0 -1
- package/dist/entrypoint/invoke.d.ts.map +0 -1
- package/dist/entrypoint/load.d.ts.map +0 -1
- package/dist/entrypoint/register.d.ts +0 -7
- package/dist/entrypoint/register.d.ts.map +0 -1
- package/dist/graphql/client.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -7
- package/dist/introspector/decorators/decorators.d.ts.map +0 -1
- package/dist/introspector/executor/executor.d.ts.map +0 -1
- package/dist/introspector/executor/executor.js +0 -32
- package/dist/introspector/registry/registry.d.ts.map +0 -1
- package/dist/introspector/scanner/abtractions/argument.d.ts +0 -104
- package/dist/introspector/scanner/abtractions/argument.d.ts.map +0 -1
- package/dist/introspector/scanner/abtractions/argument.js +0 -207
- package/dist/introspector/scanner/abtractions/constructor.d.ts +0 -17
- package/dist/introspector/scanner/abtractions/constructor.d.ts.map +0 -1
- package/dist/introspector/scanner/abtractions/constructor.js +0 -40
- package/dist/introspector/scanner/abtractions/enum.d.ts +0 -33
- package/dist/introspector/scanner/abtractions/enum.d.ts.map +0 -1
- package/dist/introspector/scanner/abtractions/enum.js +0 -73
- package/dist/introspector/scanner/abtractions/enumValue.d.ts +0 -24
- package/dist/introspector/scanner/abtractions/enumValue.d.ts.map +0 -1
- package/dist/introspector/scanner/abtractions/enumValue.js +0 -51
- package/dist/introspector/scanner/abtractions/method.d.ts +0 -67
- package/dist/introspector/scanner/abtractions/method.d.ts.map +0 -1
- package/dist/introspector/scanner/abtractions/method.js +0 -132
- package/dist/introspector/scanner/abtractions/module.d.ts +0 -26
- package/dist/introspector/scanner/abtractions/module.d.ts.map +0 -1
- package/dist/introspector/scanner/abtractions/module.js +0 -103
- package/dist/introspector/scanner/abtractions/object.d.ts +0 -52
- package/dist/introspector/scanner/abtractions/object.d.ts.map +0 -1
- package/dist/introspector/scanner/abtractions/object.js +0 -118
- package/dist/introspector/scanner/abtractions/property.d.ts +0 -55
- package/dist/introspector/scanner/abtractions/property.d.ts.map +0 -1
- package/dist/introspector/scanner/abtractions/property.js +0 -110
- package/dist/introspector/scanner/abtractions/typeToTypedef.d.ts +0 -8
- package/dist/introspector/scanner/abtractions/typeToTypedef.d.ts.map +0 -1
- package/dist/introspector/scanner/abtractions/typeToTypedef.js +0 -85
- package/dist/introspector/scanner/scan.d.ts +0 -14
- package/dist/introspector/scanner/scan.d.ts.map +0 -1
- package/dist/introspector/scanner/scan.js +0 -26
- package/dist/introspector/scanner/typeDefs.d.ts.map +0 -1
- package/dist/introspector/scanner/utils.d.ts +0 -22
- package/dist/introspector/scanner/utils.d.ts.map +0 -1
- package/dist/introspector/scanner/utils.js +0 -101
- package/dist/introspector/utils/files.d.ts.map +0 -1
- package/dist/provisioning/bin.d.ts.map +0 -1
- package/dist/provisioning/default.d.ts +0 -2
- package/dist/provisioning/default.d.ts.map +0 -1
- package/dist/provisioning/engineconn.d.ts +0 -28
- package/dist/provisioning/engineconn.d.ts.map +0 -1
- package/dist/provisioning/index.d.ts +0 -4
- package/dist/provisioning/index.d.ts.map +0 -1
- package/dist/provisioning/index.js +0 -3
- package/dist/telemetry/attributes.d.ts +0 -2
- package/dist/telemetry/attributes.d.ts.map +0 -1
- package/dist/telemetry/index.d.ts.map +0 -1
- package/dist/telemetry/init.d.ts.map +0 -1
- package/dist/telemetry/telemetry.d.ts.map +0 -1
- package/dist/telemetry/tracer.d.ts.map +0 -1
- /package/dist/{common → src/common}/errors/DaggerSDKError.js +0 -0
- /package/dist/{common → src/common}/errors/DockerImageRefValidationError.d.ts +0 -0
- /package/dist/{common → src/common}/errors/DockerImageRefValidationError.js +0 -0
- /package/dist/{common → src/common}/errors/EngineSessionConnectParamsParseError.d.ts +0 -0
- /package/dist/{common → src/common}/errors/EngineSessionConnectParamsParseError.js +0 -0
- /package/dist/{common → src/common}/errors/EngineSessionConnectionTimeoutError.d.ts +0 -0
- /package/dist/{common → src/common}/errors/EngineSessionConnectionTimeoutError.js +0 -0
- /package/dist/{common → src/common}/errors/EngineSessionErrorOptions.d.ts +0 -0
- /package/dist/{common → src/common}/errors/EngineSessionErrorOptions.js +0 -0
- /package/dist/{common → src/common}/errors/FunctionNotFound.d.ts +0 -0
- /package/dist/{common → src/common}/errors/FunctionNotFound.js +0 -0
- /package/dist/{common → src/common}/errors/GraphQLRequestError.d.ts +0 -0
- /package/dist/{common → src/common}/errors/GraphQLRequestError.js +0 -0
- /package/dist/{common → src/common}/errors/InitEngineSessionBinaryError.d.ts +0 -0
- /package/dist/{common → src/common}/errors/InitEngineSessionBinaryError.js +0 -0
- /package/dist/{common → src/common}/errors/NotAwaitedRequestError.d.ts +0 -0
- /package/dist/{common → src/common}/errors/NotAwaitedRequestError.js +0 -0
- /package/dist/{common → src/common}/errors/TooManyNestedObjectsError.d.ts +0 -0
- /package/dist/{common → src/common}/errors/TooManyNestedObjectsError.js +0 -0
- /package/dist/{common → src/common}/errors/UnknownDaggerError.d.ts +0 -0
- /package/dist/{common → src/common}/errors/UnknownDaggerError.js +0 -0
- /package/dist/{graphql → src/common/graphql}/client.d.ts +0 -0
- /package/dist/{graphql → src/common/graphql}/client.js +0 -0
- /package/dist/{common → src/common}/utils.js +0 -0
- /package/dist/{connectOpts.d.ts → src/connectOpts.d.ts} +0 -0
- /package/dist/{connectOpts.js → src/connectOpts.js} +0 -0
- /package/dist/{entrypoint → src/module/entrypoint}/context.js +0 -0
- /package/dist/{introspector/scanner/typeDefs.js → src/module/introspector/dagger_module/enumBase.js} +0 -0
- /package/dist/{provisioning/engineconn.js → src/module/introspector/dagger_module/objectBase.js} +0 -0
- /package/dist/{telemetry/attributes.js → src/module/introspector/typedef.js} +0 -0
- /package/dist/{introspector → src/module/introspector}/utils/files.d.ts +0 -0
- /package/dist/{introspector/registry → src/module}/registry.d.ts +0 -0
- /package/dist/{provisioning → src/provisioning}/bin.d.ts +0 -0
- /package/dist/{telemetry → src/telemetry}/index.d.ts +0 -0
- /package/dist/{telemetry → src/telemetry}/index.js +0 -0
- /package/dist/{telemetry → src/telemetry}/init.d.ts +0 -0
- /package/dist/{telemetry → src/telemetry}/init.js +0 -0
- /package/dist/{telemetry → src/telemetry}/telemetry.d.ts +0 -0
- /package/dist/{telemetry → src/telemetry}/telemetry.js +0 -0
- /package/dist/{telemetry → src/telemetry}/tracer.d.ts +0 -0
- /package/dist/{telemetry → src/telemetry}/tracer.js +0 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { IntrospectionError } from "../../../common/errors/index.js";
|
|
3
|
+
import { AST } from "../typescript_module/index.js";
|
|
4
|
+
export class DaggerEnumClassValue {
|
|
5
|
+
node;
|
|
6
|
+
ast;
|
|
7
|
+
name;
|
|
8
|
+
value;
|
|
9
|
+
description;
|
|
10
|
+
symbol;
|
|
11
|
+
constructor(node, ast) {
|
|
12
|
+
this.node = node;
|
|
13
|
+
this.ast = ast;
|
|
14
|
+
this.name = this.node.name.getText();
|
|
15
|
+
this.symbol = this.ast.getSymbolOrThrow(this.node.name);
|
|
16
|
+
this.description = this.ast.getDocFromSymbol(this.symbol);
|
|
17
|
+
const initializer = this.node.initializer;
|
|
18
|
+
if (!initializer) {
|
|
19
|
+
throw new Error("Dagger enum value has no value set");
|
|
20
|
+
}
|
|
21
|
+
this.value = this.ast.resolveParameterDefaultValue(initializer);
|
|
22
|
+
}
|
|
23
|
+
toJSON() {
|
|
24
|
+
return {
|
|
25
|
+
name: this.value,
|
|
26
|
+
description: this.description,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export class DaggerEnumClass {
|
|
31
|
+
node;
|
|
32
|
+
ast;
|
|
33
|
+
name;
|
|
34
|
+
description;
|
|
35
|
+
values = {};
|
|
36
|
+
symbol;
|
|
37
|
+
constructor(node, ast) {
|
|
38
|
+
this.node = node;
|
|
39
|
+
this.ast = ast;
|
|
40
|
+
if (!this.node.name) {
|
|
41
|
+
throw new IntrospectionError(`could not resolve name of enum at ${AST.getNodePosition(node)}.`);
|
|
42
|
+
}
|
|
43
|
+
this.name = this.node.name.getText();
|
|
44
|
+
this.symbol = this.ast.getSymbolOrThrow(this.node.name);
|
|
45
|
+
this.description = this.ast.getDocFromSymbol(this.symbol);
|
|
46
|
+
const properties = this.node.members;
|
|
47
|
+
for (const property of properties) {
|
|
48
|
+
if (ts.isPropertyDeclaration(property)) {
|
|
49
|
+
const value = new DaggerEnumClassValue(property, this.ast);
|
|
50
|
+
this.values[value.name] = value;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
toJSON() {
|
|
55
|
+
return {
|
|
56
|
+
name: this.name,
|
|
57
|
+
description: this.description,
|
|
58
|
+
values: this.values,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { TypeDefKind } from "../../../api/client.gen.js";
|
|
3
|
+
import { TypeDef } from "../typedef.js";
|
|
4
|
+
import { AST } from "../typescript_module/index.js";
|
|
5
|
+
import { DaggerArguments } from "./argument.js";
|
|
6
|
+
import { References } from "./reference.js";
|
|
7
|
+
export type DaggerFunctions = {
|
|
8
|
+
[name: string]: DaggerFunction;
|
|
9
|
+
};
|
|
10
|
+
export declare class DaggerFunction {
|
|
11
|
+
private readonly node;
|
|
12
|
+
private readonly ast;
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
private _returnTypeRef?;
|
|
16
|
+
returnType?: TypeDef<TypeDefKind>;
|
|
17
|
+
alias: string | undefined;
|
|
18
|
+
arguments: DaggerArguments;
|
|
19
|
+
private signature;
|
|
20
|
+
private symbol;
|
|
21
|
+
constructor(node: ts.MethodDeclaration, ast: AST);
|
|
22
|
+
private getReturnType;
|
|
23
|
+
private getAlias;
|
|
24
|
+
getArgsOrder(): string[];
|
|
25
|
+
getReferences(): string[];
|
|
26
|
+
propagateReferences(references: References): void;
|
|
27
|
+
toJSON(): {
|
|
28
|
+
name: string;
|
|
29
|
+
description: string;
|
|
30
|
+
alias: string | undefined;
|
|
31
|
+
arguments: DaggerArguments;
|
|
32
|
+
returnType: TypeDef<TypeDefKind> | undefined;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=function.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../../../../src/module/introspector/dagger_module/function.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAExD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EACL,GAAG,EAGJ,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAkB,eAAe,EAAE,MAAM,eAAe,CAAA;AAE/D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,MAAM,MAAM,eAAe,GAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAAA;CAAE,CAAA;AAEhE,qBAAa,cAAc;IAYvB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAZf,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IAC1B,OAAO,CAAC,cAAc,CAAC,CAAQ;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;IACjC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,SAAS,EAAE,eAAe,CAAK;IAEtC,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,MAAM,CAAW;gBAGN,IAAI,EAAE,EAAE,CAAC,iBAAiB,EAC1B,GAAG,EAAE,GAAG;IAiB3B,OAAO,CAAC,aAAa;IAWrB,OAAO,CAAC,QAAQ;IAaT,YAAY,IAAI,MAAM,EAAE;IAIxB,aAAa,IAAI,MAAM,EAAE;IAoBzB,mBAAmB,CAAC,UAAU,EAAE,UAAU;IAuB1C,MAAM;;;;;;;CASd"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { IntrospectionError } from "../../../common/errors/index.js";
|
|
2
|
+
import { AST, isTypeDefResolved, resolveTypeDef, } from "../typescript_module/index.js";
|
|
3
|
+
import { DaggerArgument } from "./argument.js";
|
|
4
|
+
import { FUNCTION_DECORATOR } from "./decorator.js";
|
|
5
|
+
export class DaggerFunction {
|
|
6
|
+
node;
|
|
7
|
+
ast;
|
|
8
|
+
name;
|
|
9
|
+
description;
|
|
10
|
+
_returnTypeRef;
|
|
11
|
+
returnType;
|
|
12
|
+
alias;
|
|
13
|
+
arguments = {};
|
|
14
|
+
signature;
|
|
15
|
+
symbol;
|
|
16
|
+
constructor(node, ast) {
|
|
17
|
+
this.node = node;
|
|
18
|
+
this.ast = ast;
|
|
19
|
+
this.symbol = this.ast.getSymbolOrThrow(node.name);
|
|
20
|
+
this.signature = this.ast.getSignatureFromFunctionOrThrow(node);
|
|
21
|
+
this.name = this.node.name.getText();
|
|
22
|
+
this.description = this.ast.getDocFromSymbol(this.symbol);
|
|
23
|
+
for (const parameter of this.node.parameters) {
|
|
24
|
+
this.arguments[parameter.name.getText()] = new DaggerArgument(parameter, this.ast);
|
|
25
|
+
}
|
|
26
|
+
this.returnType = this.getReturnType();
|
|
27
|
+
this.alias = this.getAlias();
|
|
28
|
+
}
|
|
29
|
+
getReturnType() {
|
|
30
|
+
const type = this.signature.getReturnType();
|
|
31
|
+
const typedef = this.ast.tsTypeToTypeDef(this.node, type);
|
|
32
|
+
if (typedef === undefined || !isTypeDefResolved(typedef)) {
|
|
33
|
+
this._returnTypeRef = this.ast.typeToStringType(type);
|
|
34
|
+
}
|
|
35
|
+
return typedef;
|
|
36
|
+
}
|
|
37
|
+
getAlias() {
|
|
38
|
+
const alias = this.ast.getDecoratorArgument(this.node, FUNCTION_DECORATOR, "string");
|
|
39
|
+
if (!alias) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
return JSON.parse(alias.replace(/'/g, '"'));
|
|
43
|
+
}
|
|
44
|
+
getArgsOrder() {
|
|
45
|
+
return Object.keys(this.arguments);
|
|
46
|
+
}
|
|
47
|
+
getReferences() {
|
|
48
|
+
const references = [];
|
|
49
|
+
if (this._returnTypeRef &&
|
|
50
|
+
(this.returnType === undefined || !isTypeDefResolved(this.returnType))) {
|
|
51
|
+
references.push(this._returnTypeRef);
|
|
52
|
+
}
|
|
53
|
+
for (const argument of Object.values(this.arguments)) {
|
|
54
|
+
const reference = argument.getReference();
|
|
55
|
+
if (reference) {
|
|
56
|
+
references.push(reference);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return references;
|
|
60
|
+
}
|
|
61
|
+
propagateReferences(references) {
|
|
62
|
+
for (const argument of Object.values(this.arguments)) {
|
|
63
|
+
argument.propagateReferences(references);
|
|
64
|
+
}
|
|
65
|
+
if (!this._returnTypeRef) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (this.returnType && isTypeDefResolved(this.returnType)) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const typeDef = references[this._returnTypeRef];
|
|
72
|
+
if (!typeDef) {
|
|
73
|
+
throw new IntrospectionError(`could not find type reference for ${this._returnTypeRef} at ${AST.getNodePosition(this.node)}.`);
|
|
74
|
+
}
|
|
75
|
+
this.returnType = resolveTypeDef(this.returnType, typeDef);
|
|
76
|
+
}
|
|
77
|
+
toJSON() {
|
|
78
|
+
return {
|
|
79
|
+
name: this.name,
|
|
80
|
+
description: this.description,
|
|
81
|
+
alias: this.alias,
|
|
82
|
+
arguments: this.arguments,
|
|
83
|
+
returnType: this.returnType,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./constructor.js";
|
|
2
|
+
export * from "./argument.js";
|
|
3
|
+
export * from "./enum.js";
|
|
4
|
+
export * from "./enumBase.js";
|
|
5
|
+
export * from "./enumClass.js";
|
|
6
|
+
export * from "./function.js";
|
|
7
|
+
export * from "./module.js";
|
|
8
|
+
export * from "./object.js";
|
|
9
|
+
export * from "./objectBase.js";
|
|
10
|
+
export * from "./reference.js";
|
|
11
|
+
export * from "./typeObject.js";
|
|
12
|
+
export * from "./decorator.js";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/module/introspector/dagger_module/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./constructor.js";
|
|
2
|
+
export * from "./argument.js";
|
|
3
|
+
export * from "./enum.js";
|
|
4
|
+
export * from "./enumBase.js";
|
|
5
|
+
export * from "./enumClass.js";
|
|
6
|
+
export * from "./function.js";
|
|
7
|
+
export * from "./module.js";
|
|
8
|
+
export * from "./object.js";
|
|
9
|
+
export * from "./objectBase.js";
|
|
10
|
+
export * from "./reference.js";
|
|
11
|
+
export * from "./typeObject.js";
|
|
12
|
+
export * from "./decorator.js";
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import Module from "node:module";
|
|
2
|
+
import { AST } from "../typescript_module/index.js";
|
|
3
|
+
import { DaggerEnumsBase } from "./enumBase.js";
|
|
4
|
+
import { DaggerObjectsBase } from "./objectBase.js";
|
|
5
|
+
/**
|
|
6
|
+
* DaggerModule represents a TypeScript module with a set of files
|
|
7
|
+
* with Dagger object conversion and notation.
|
|
8
|
+
*
|
|
9
|
+
* It starts from the module entrypoint (the class named the same as the module) and
|
|
10
|
+
* then recursively resolve every references to other declared identifiers.
|
|
11
|
+
* After resolution, it propagates all the references to the modules declarations
|
|
12
|
+
* and finally it generates the final Dagger module representation.
|
|
13
|
+
*/
|
|
14
|
+
export declare class DaggerModule {
|
|
15
|
+
name: string;
|
|
16
|
+
private userModule;
|
|
17
|
+
private ast;
|
|
18
|
+
/**
|
|
19
|
+
* An object is either a decorated class or a type alias object.
|
|
20
|
+
* Type alias objects cannot be decorated so they are resolved if referenced in the module.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* @object()
|
|
25
|
+
* export class MyObject {
|
|
26
|
+
* @func()
|
|
27
|
+
* public name: string
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* export type Example = {
|
|
34
|
+
* name: string
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
objects: DaggerObjectsBase;
|
|
39
|
+
/**
|
|
40
|
+
* An enum is either a decorated class or a native enum.
|
|
41
|
+
* Native enum cannot be decorated so they are resolved if referenced in the module.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* @enumType()
|
|
46
|
+
* export class Example {
|
|
47
|
+
* static A: string = "a"
|
|
48
|
+
* static B: string = "b"
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* or
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* export enum Example {
|
|
57
|
+
* A = "a",
|
|
58
|
+
* B = "b",
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
enums: DaggerEnumsBase;
|
|
63
|
+
description: string | undefined;
|
|
64
|
+
private references;
|
|
65
|
+
constructor(name: string, userModule: Module[], ast: AST);
|
|
66
|
+
/**
|
|
67
|
+
* Find the reference of the module and register it to the module references.
|
|
68
|
+
*
|
|
69
|
+
* To do so, we check the user module to find a corresponding symbol (name) for each of
|
|
70
|
+
* typedef we support.
|
|
71
|
+
* This only applies for:
|
|
72
|
+
* - classes
|
|
73
|
+
* - enums
|
|
74
|
+
* - scalars
|
|
75
|
+
*
|
|
76
|
+
* If the reference is an object or a class, recursively find the references of the object.
|
|
77
|
+
*
|
|
78
|
+
* *Note*: If a class is referenced but not exported and not decorated with `@object()`, we throw an error
|
|
79
|
+
* because we aim to be explicit. (TomChv: Should we change this behaviour?)
|
|
80
|
+
*/
|
|
81
|
+
private resolveReferences;
|
|
82
|
+
/**
|
|
83
|
+
* Resolve type alias to the corresponding TypeDef.
|
|
84
|
+
* A type might refer to anything typeable in TypeScript but right now we supports:
|
|
85
|
+
* - `type Example = string`
|
|
86
|
+
* - `type Example = { prop: string}`
|
|
87
|
+
* - `type Example = number`
|
|
88
|
+
* - `type Example = boolean`
|
|
89
|
+
* - `type Example = void`
|
|
90
|
+
*
|
|
91
|
+
* If the reference is an object, we recursively resolve its references.
|
|
92
|
+
* If the type cannot be resolved or is not supported, we throw an error.
|
|
93
|
+
*/
|
|
94
|
+
private resolveTypeAlias;
|
|
95
|
+
/**
|
|
96
|
+
* Recursively propagate references to all objects properties and functions.
|
|
97
|
+
*/
|
|
98
|
+
private propagateReferences;
|
|
99
|
+
/**
|
|
100
|
+
* Get the top level comment of the file that contains the module entrypoint.
|
|
101
|
+
*/
|
|
102
|
+
private getDescription;
|
|
103
|
+
toJSON(): {
|
|
104
|
+
name: string;
|
|
105
|
+
description: string | undefined;
|
|
106
|
+
objects: DaggerObjectsBase;
|
|
107
|
+
enums: DaggerEnumsBase;
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../../../src/module/introspector/dagger_module/module.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAKhC,OAAO,EAEL,GAAG,EAGJ,MAAM,+BAA+B,CAAA;AAGtC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAG/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAInD;;;;;;;;GAQG;AACH,qBAAa,YAAY;IAoDd,IAAI,EAAE,MAAM;IACnB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,GAAG;IArDb;;;;;;;;;;;;;;;;;;;OAmBG;IACI,OAAO,EAAE,iBAAiB,CAAK;IAEtC;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACI,KAAK,EAAE,eAAe,CAAK;IAC3B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAEtC,OAAO,CAAC,UAAU,CAAiB;gBAG1B,IAAI,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,EAAE,EACpB,GAAG,EAAE,GAAG;IAkClB;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAC,iBAAiB;IAmHzB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,gBAAgB;IAsExB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAM3B;;OAEG;IACH,OAAO,CAAC,cAAc;IAgBtB,MAAM;;;;;;CAQP"}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { TypeDefKind } from "../../../api/client.gen.js";
|
|
3
|
+
import { IntrospectionError } from "../../../common/errors/index.js";
|
|
4
|
+
import { findModuleByExportedName, AST, CLIENT_GEN_FILE, } from "../typescript_module/index.js";
|
|
5
|
+
import { ENUM_DECORATOR, OBJECT_DECORATOR } from "./decorator.js";
|
|
6
|
+
import { DaggerEnum } from "./enum.js";
|
|
7
|
+
import { DaggerEnumClass } from "./enumClass.js";
|
|
8
|
+
import { DaggerObject } from "./object.js";
|
|
9
|
+
import { DaggerTypeObject } from "./typeObject.js";
|
|
10
|
+
/**
|
|
11
|
+
* DaggerModule represents a TypeScript module with a set of files
|
|
12
|
+
* with Dagger object conversion and notation.
|
|
13
|
+
*
|
|
14
|
+
* It starts from the module entrypoint (the class named the same as the module) and
|
|
15
|
+
* then recursively resolve every references to other declared identifiers.
|
|
16
|
+
* After resolution, it propagates all the references to the modules declarations
|
|
17
|
+
* and finally it generates the final Dagger module representation.
|
|
18
|
+
*/
|
|
19
|
+
export class DaggerModule {
|
|
20
|
+
name;
|
|
21
|
+
userModule;
|
|
22
|
+
ast;
|
|
23
|
+
/**
|
|
24
|
+
* An object is either a decorated class or a type alias object.
|
|
25
|
+
* Type alias objects cannot be decorated so they are resolved if referenced in the module.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* @object()
|
|
30
|
+
* export class MyObject {
|
|
31
|
+
* @func()
|
|
32
|
+
* public name: string
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* export type Example = {
|
|
39
|
+
* name: string
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
objects = {};
|
|
44
|
+
/**
|
|
45
|
+
* An enum is either a decorated class or a native enum.
|
|
46
|
+
* Native enum cannot be decorated so they are resolved if referenced in the module.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* @enumType()
|
|
51
|
+
* export class Example {
|
|
52
|
+
* static A: string = "a"
|
|
53
|
+
* static B: string = "b"
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* or
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* export enum Example {
|
|
62
|
+
* A = "a",
|
|
63
|
+
* B = "b",
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
enums = {};
|
|
68
|
+
description;
|
|
69
|
+
references = {};
|
|
70
|
+
constructor(name, userModule, ast) {
|
|
71
|
+
this.name = name;
|
|
72
|
+
this.userModule = userModule;
|
|
73
|
+
this.ast = ast;
|
|
74
|
+
const mainModule = findModuleByExportedName(this.name, this.userModule);
|
|
75
|
+
if (!mainModule) {
|
|
76
|
+
console.warn(`could not find module entrypoint: class ${this.name} from import. Class should be exported to benefit from all features.`);
|
|
77
|
+
}
|
|
78
|
+
const mainObjectNode = this.ast.findResolvedNodeByName(this.name, ts.SyntaxKind.ClassDeclaration);
|
|
79
|
+
if (!mainObjectNode) {
|
|
80
|
+
throw new IntrospectionError(`could not find main object ${this.name} in module ${JSON.stringify(mainModule, null, 2) ?? ""} located at ${this.ast.files}`);
|
|
81
|
+
}
|
|
82
|
+
const mainFileContent = mainObjectNode.file.getFullText();
|
|
83
|
+
this.description = this.getDescription(mainFileContent);
|
|
84
|
+
const mainDaggerObject = new DaggerObject(mainObjectNode.node, this.ast);
|
|
85
|
+
this.objects[this.name] = mainDaggerObject;
|
|
86
|
+
this.references[this.name] = {
|
|
87
|
+
kind: TypeDefKind.ObjectKind,
|
|
88
|
+
name: this.name,
|
|
89
|
+
};
|
|
90
|
+
this.resolveReferences(mainDaggerObject.getReferences());
|
|
91
|
+
this.propagateReferences();
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Find the reference of the module and register it to the module references.
|
|
95
|
+
*
|
|
96
|
+
* To do so, we check the user module to find a corresponding symbol (name) for each of
|
|
97
|
+
* typedef we support.
|
|
98
|
+
* This only applies for:
|
|
99
|
+
* - classes
|
|
100
|
+
* - enums
|
|
101
|
+
* - scalars
|
|
102
|
+
*
|
|
103
|
+
* If the reference is an object or a class, recursively find the references of the object.
|
|
104
|
+
*
|
|
105
|
+
* *Note*: If a class is referenced but not exported and not decorated with `@object()`, we throw an error
|
|
106
|
+
* because we aim to be explicit. (TomChv: Should we change this behaviour?)
|
|
107
|
+
*/
|
|
108
|
+
resolveReferences(references) {
|
|
109
|
+
if (references.length === 0) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
for (const reference of references) {
|
|
113
|
+
// If we already know that reference, we don't need to explore it again.
|
|
114
|
+
if (this.references[reference]) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const classRef = this.ast.findResolvedNodeByName(reference, ts.SyntaxKind.ClassDeclaration);
|
|
118
|
+
if (classRef) {
|
|
119
|
+
if (classRef.file.fileName.endsWith(CLIENT_GEN_FILE)) {
|
|
120
|
+
this.references[reference] = {
|
|
121
|
+
kind: TypeDefKind.ObjectKind,
|
|
122
|
+
name: reference,
|
|
123
|
+
};
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (this.ast.isNodeDecoratedWith(classRef.node, OBJECT_DECORATOR)) {
|
|
127
|
+
const daggerObject = new DaggerObject(classRef.node, this.ast);
|
|
128
|
+
this.objects[daggerObject.name] = daggerObject;
|
|
129
|
+
this.references[daggerObject.name] = {
|
|
130
|
+
kind: TypeDefKind.ObjectKind,
|
|
131
|
+
name: daggerObject.name,
|
|
132
|
+
};
|
|
133
|
+
this.resolveReferences(daggerObject.getReferences());
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (this.ast.isNodeDecoratedWith(classRef.node, ENUM_DECORATOR)) {
|
|
137
|
+
const daggerEnum = new DaggerEnumClass(classRef.node, this.ast);
|
|
138
|
+
this.enums[daggerEnum.name] = daggerEnum;
|
|
139
|
+
this.references[daggerEnum.name] = {
|
|
140
|
+
kind: TypeDefKind.EnumKind,
|
|
141
|
+
name: daggerEnum.name,
|
|
142
|
+
};
|
|
143
|
+
// There should be no references in enums.
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
throw new IntrospectionError(`class ${reference} in ${AST.getNodePosition(classRef.node)} is used by the module but not exposed with a dagger decorator.`);
|
|
147
|
+
}
|
|
148
|
+
const enumRef = this.ast.findResolvedNodeByName(reference, ts.SyntaxKind.EnumDeclaration);
|
|
149
|
+
if (enumRef) {
|
|
150
|
+
if (enumRef.file.fileName.endsWith(CLIENT_GEN_FILE)) {
|
|
151
|
+
this.references[reference] = {
|
|
152
|
+
kind: TypeDefKind.EnumKind,
|
|
153
|
+
name: reference,
|
|
154
|
+
};
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
// Typescript enum declaration cannot be decorated, so we don't check it.
|
|
158
|
+
const daggerEnum = new DaggerEnum(enumRef.node, this.ast);
|
|
159
|
+
this.enums[daggerEnum.name] = daggerEnum;
|
|
160
|
+
this.references[daggerEnum.name] = {
|
|
161
|
+
kind: TypeDefKind.EnumKind,
|
|
162
|
+
name: daggerEnum.name,
|
|
163
|
+
};
|
|
164
|
+
// There should be no reference in enums.
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const typeAliasRef = this.ast.findResolvedNodeByName(reference, ts.SyntaxKind.TypeAliasDeclaration);
|
|
168
|
+
if (typeAliasRef) {
|
|
169
|
+
// The resolution is to big so we split it in a sub function.
|
|
170
|
+
this.resolveTypeAlias(reference, typeAliasRef);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
// Handle primitives here
|
|
174
|
+
if (reference === "String") {
|
|
175
|
+
throw new IntrospectionError(`Use of primitive 'String' type detected, please use 'string' instead.`);
|
|
176
|
+
}
|
|
177
|
+
if (reference === "Boolean") {
|
|
178
|
+
throw new IntrospectionError(`Use of primitive 'Boolean' type detected, please use 'boolean' instead.`);
|
|
179
|
+
}
|
|
180
|
+
if (reference === "Number") {
|
|
181
|
+
throw new IntrospectionError(`Use of primitive 'Number' type detected, please use 'number' instead.`);
|
|
182
|
+
}
|
|
183
|
+
throw new IntrospectionError(`could not resolve type reference for ${reference}.`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Resolve type alias to the corresponding TypeDef.
|
|
188
|
+
* A type might refer to anything typeable in TypeScript but right now we supports:
|
|
189
|
+
* - `type Example = string`
|
|
190
|
+
* - `type Example = { prop: string}`
|
|
191
|
+
* - `type Example = number`
|
|
192
|
+
* - `type Example = boolean`
|
|
193
|
+
* - `type Example = void`
|
|
194
|
+
*
|
|
195
|
+
* If the reference is an object, we recursively resolve its references.
|
|
196
|
+
* If the type cannot be resolved or is not supported, we throw an error.
|
|
197
|
+
*/
|
|
198
|
+
resolveTypeAlias(reference, typeAlias) {
|
|
199
|
+
const type = this.ast.getTypeFromTypeAlias(typeAlias.node);
|
|
200
|
+
if (type.flags & ts.TypeFlags.String) {
|
|
201
|
+
this.references[reference] = { kind: TypeDefKind.StringKind };
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (type.flags & ts.TypeFlags.Number) {
|
|
205
|
+
this.references[reference] = { kind: TypeDefKind.IntegerKind };
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (type.flags & ts.TypeFlags.Boolean) {
|
|
209
|
+
this.references[reference] = { kind: TypeDefKind.BooleanKind };
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (type.flags & ts.TypeFlags.Void) {
|
|
213
|
+
this.references[reference] = { kind: TypeDefKind.VoidKind };
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
// Scalar are defined with string intersection such as `type MyScalar = string & { __MyScalar: never }`
|
|
217
|
+
if (type.flags & ts.TypeFlags.Intersection ||
|
|
218
|
+
type.flags & ts.TypeFlags.Union) {
|
|
219
|
+
this.references[reference] = {
|
|
220
|
+
kind: TypeDefKind.ScalarKind,
|
|
221
|
+
name: reference,
|
|
222
|
+
};
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (type.flags & ts.TypeFlags.Object) {
|
|
226
|
+
if (typeAlias.file.fileName.endsWith(CLIENT_GEN_FILE)) {
|
|
227
|
+
this.references[reference] = {
|
|
228
|
+
kind: TypeDefKind.ObjectKind,
|
|
229
|
+
name: reference,
|
|
230
|
+
};
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const daggerObject = new DaggerTypeObject(typeAlias.node, this.ast);
|
|
234
|
+
this.objects[daggerObject.name] = daggerObject;
|
|
235
|
+
this.references[daggerObject.name] = {
|
|
236
|
+
kind: TypeDefKind.ObjectKind,
|
|
237
|
+
name: daggerObject.name,
|
|
238
|
+
};
|
|
239
|
+
this.resolveReferences(daggerObject.getReferences());
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
throw new IntrospectionError(`could not resolve type reference for ${reference} at ${AST.getNodePosition(typeAlias.node)}`);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Recursively propagate references to all objects properties and functions.
|
|
246
|
+
*/
|
|
247
|
+
propagateReferences() {
|
|
248
|
+
for (const object of Object.values(this.objects)) {
|
|
249
|
+
object.propagateReferences(this.references);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Get the top level comment of the file that contains the module entrypoint.
|
|
254
|
+
*/
|
|
255
|
+
getDescription(sourceFileContent) {
|
|
256
|
+
const regex = /^(?!.*import)[\s]*\/\*\*([\s\S]*?)\*\//;
|
|
257
|
+
const match = sourceFileContent.match(regex);
|
|
258
|
+
if (!match) {
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
261
|
+
const comment = match[1]
|
|
262
|
+
.split("\n")
|
|
263
|
+
.map((line) => line.replace(/^\s*\*\s?/, ""))
|
|
264
|
+
.join("\n");
|
|
265
|
+
return comment.trim();
|
|
266
|
+
}
|
|
267
|
+
toJSON() {
|
|
268
|
+
return {
|
|
269
|
+
name: this.name,
|
|
270
|
+
description: this.description,
|
|
271
|
+
objects: this.objects,
|
|
272
|
+
enums: this.enums,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { AST } from "../typescript_module/index.js";
|
|
3
|
+
import { DaggerConstructor } from "./constructor.js";
|
|
4
|
+
import { DaggerFunctions } from "./function.js";
|
|
5
|
+
import { DaggerObjectBase } from "./objectBase.js";
|
|
6
|
+
import { DaggerProperties } from "./property.js";
|
|
7
|
+
import { References } from "./reference.js";
|
|
8
|
+
export declare class DaggerObject implements DaggerObjectBase {
|
|
9
|
+
private readonly node;
|
|
10
|
+
private readonly ast;
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
_constructor: DaggerConstructor | undefined;
|
|
14
|
+
methods: DaggerFunctions;
|
|
15
|
+
properties: DaggerProperties;
|
|
16
|
+
private symbol;
|
|
17
|
+
kind(): "class" | "object";
|
|
18
|
+
constructor(node: ts.ClassDeclaration, ast: AST);
|
|
19
|
+
getReferences(): string[];
|
|
20
|
+
propagateReferences(references: References): void;
|
|
21
|
+
toJSON(): {
|
|
22
|
+
name: string;
|
|
23
|
+
description: string;
|
|
24
|
+
constructor: DaggerConstructor | undefined;
|
|
25
|
+
methods: DaggerFunctions;
|
|
26
|
+
properties: DaggerProperties;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=object.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../../../../src/module/introspector/dagger_module/object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAG3B,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAA;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAEpD,OAAO,EAAkB,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAkB,MAAM,eAAe,CAAA;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,qBAAa,YAAa,YAAW,gBAAgB;IAcjD,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAdf,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,iBAAiB,GAAG,SAAS,CAAY;IACvD,OAAO,EAAE,eAAe,CAAK;IAC7B,UAAU,EAAE,gBAAgB,CAAK;IAExC,OAAO,CAAC,MAAM,CAAW;IAEzB,IAAI,IAAI,OAAO,GAAG,QAAQ;gBAKP,IAAI,EAAE,EAAE,CAAC,gBAAgB,EACzB,GAAG,EAAE,GAAG;IAqDpB,aAAa,IAAI,MAAM,EAAE;IAqBzB,mBAAmB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAcjD,MAAM;;;;;;;CASd"}
|