@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,316 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { TypeDefKind } from "../../../api/client.gen.js";
|
|
3
|
+
import { IntrospectionError } from "../../../common/errors/index.js";
|
|
4
|
+
import { 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 { DaggerInterface } from "./interface.js";
|
|
9
|
+
import { DaggerObject } from "./object.js";
|
|
10
|
+
import { DaggerTypeObject } from "./typeObject.js";
|
|
11
|
+
/**
|
|
12
|
+
* DaggerModule represents a TypeScript module with a set of files
|
|
13
|
+
* with Dagger object conversion and notation.
|
|
14
|
+
*
|
|
15
|
+
* It starts from the module entrypoint (the class named the same as the module) and
|
|
16
|
+
* then recursively resolve every references to other declared identifiers.
|
|
17
|
+
* After resolution, it propagates all the references to the modules declarations
|
|
18
|
+
* and finally it generates the final Dagger module representation.
|
|
19
|
+
*/
|
|
20
|
+
export class DaggerModule {
|
|
21
|
+
name;
|
|
22
|
+
userModule;
|
|
23
|
+
ast;
|
|
24
|
+
/**
|
|
25
|
+
* An object is either a decorated class or a type alias object.
|
|
26
|
+
* Type alias objects cannot be decorated so they are resolved if referenced in the module.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* @object()
|
|
31
|
+
* export class MyObject {
|
|
32
|
+
* @func()
|
|
33
|
+
* public name: string
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* export type Example = {
|
|
40
|
+
* name: string
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
objects = {};
|
|
45
|
+
/**
|
|
46
|
+
* An enum is typically a native TypeScript enum declared with the `enum` keyword.
|
|
47
|
+
* Decorated classes using `@enumType()` are still supported for backward compatibility.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* export enum Example {
|
|
52
|
+
* A = "a",
|
|
53
|
+
* B = "b",
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
enums = {};
|
|
58
|
+
/**
|
|
59
|
+
* An interface is declared using the `interface` keyword.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* export interface Example {
|
|
64
|
+
* foo: (): string
|
|
65
|
+
* asyncFoo: (): Promise<string>
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
interfaces = {};
|
|
70
|
+
description;
|
|
71
|
+
references = {
|
|
72
|
+
// Float is a special case, it's an alias of number but it serves to declare a float type
|
|
73
|
+
// in the Dagger API.
|
|
74
|
+
// So we auto register it because it will be detected as a referenced type by the introspector.
|
|
75
|
+
float: { kind: TypeDefKind.FloatKind },
|
|
76
|
+
};
|
|
77
|
+
constructor(name, userModule, ast) {
|
|
78
|
+
this.name = name;
|
|
79
|
+
this.userModule = userModule;
|
|
80
|
+
this.ast = ast;
|
|
81
|
+
const classObjects = this.findClasses();
|
|
82
|
+
for (const classObject of classObjects) {
|
|
83
|
+
// This only applies to cloud. If this is the true main object, it is correct
|
|
84
|
+
// if this is a blueprint, the description will not matter in any situation
|
|
85
|
+
const mainFileContent = classObject.file.getFullText();
|
|
86
|
+
this.description = this.getDescription(mainFileContent);
|
|
87
|
+
const daggerObject = new DaggerObject(classObject.node, this.ast);
|
|
88
|
+
const objectName = classObject.node.name?.getText() || this.name;
|
|
89
|
+
this.objects[objectName] = daggerObject;
|
|
90
|
+
this.references[objectName] = {
|
|
91
|
+
kind: TypeDefKind.ObjectKind,
|
|
92
|
+
name: objectName,
|
|
93
|
+
};
|
|
94
|
+
this.resolveReferences(daggerObject.getReferences());
|
|
95
|
+
this.propagateReferences();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Find the reference of the module and register it to the module references.
|
|
100
|
+
*
|
|
101
|
+
* To do so, we check the user module to find a corresponding symbol (name) for each of
|
|
102
|
+
* typedef we support.
|
|
103
|
+
* This only applies for:
|
|
104
|
+
* - classes
|
|
105
|
+
* - enums
|
|
106
|
+
* - scalars
|
|
107
|
+
* - interfaces
|
|
108
|
+
*
|
|
109
|
+
* If the reference is an object, a class or an interface, recursively find the references of the object.
|
|
110
|
+
*
|
|
111
|
+
* *Note*: If a class is referenced but not exported and not decorated with `@object()`, we throw an error
|
|
112
|
+
* because we aim to be explicit. (TomChv: Should we change this behaviour?)
|
|
113
|
+
*/
|
|
114
|
+
resolveReferences(references) {
|
|
115
|
+
if (references.length === 0) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
for (const reference of references) {
|
|
119
|
+
// If we already know that reference, we don't need to explore it again.
|
|
120
|
+
if (this.references[reference]) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const classRef = this.ast.findResolvedNodeByName(reference, ts.SyntaxKind.ClassDeclaration);
|
|
124
|
+
if (classRef) {
|
|
125
|
+
if (classRef.file.fileName.endsWith(CLIENT_GEN_FILE)) {
|
|
126
|
+
this.references[reference] = {
|
|
127
|
+
kind: TypeDefKind.ObjectKind,
|
|
128
|
+
name: reference,
|
|
129
|
+
};
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (this.ast.isNodeDecoratedWith(classRef.node, OBJECT_DECORATOR)) {
|
|
133
|
+
const daggerObject = new DaggerObject(classRef.node, this.ast);
|
|
134
|
+
this.objects[daggerObject.name] = daggerObject;
|
|
135
|
+
this.references[daggerObject.name] = {
|
|
136
|
+
kind: TypeDefKind.ObjectKind,
|
|
137
|
+
name: daggerObject.name,
|
|
138
|
+
};
|
|
139
|
+
this.resolveReferences(daggerObject.getReferences());
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (this.ast.isNodeDecoratedWith(classRef.node, ENUM_DECORATOR)) {
|
|
143
|
+
const daggerEnum = new DaggerEnumClass(classRef.node, this.ast);
|
|
144
|
+
this.enums[daggerEnum.name] = daggerEnum;
|
|
145
|
+
this.references[daggerEnum.name] = {
|
|
146
|
+
kind: TypeDefKind.EnumKind,
|
|
147
|
+
name: daggerEnum.name,
|
|
148
|
+
};
|
|
149
|
+
// There should be no references in enums.
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
throw new IntrospectionError(`class ${reference} in ${AST.getNodePosition(classRef.node)} is used by the module but not exposed with a dagger decorator.`);
|
|
153
|
+
}
|
|
154
|
+
const enumRef = this.ast.findResolvedNodeByName(reference, ts.SyntaxKind.EnumDeclaration);
|
|
155
|
+
if (enumRef) {
|
|
156
|
+
if (enumRef.file.fileName.endsWith(CLIENT_GEN_FILE)) {
|
|
157
|
+
this.references[reference] = {
|
|
158
|
+
kind: TypeDefKind.EnumKind,
|
|
159
|
+
name: reference,
|
|
160
|
+
};
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
// Typescript enum declaration cannot be decorated, so we don't check it.
|
|
164
|
+
const daggerEnum = new DaggerEnum(enumRef.node, this.ast);
|
|
165
|
+
this.enums[daggerEnum.name] = daggerEnum;
|
|
166
|
+
this.references[daggerEnum.name] = {
|
|
167
|
+
kind: TypeDefKind.EnumKind,
|
|
168
|
+
name: daggerEnum.name,
|
|
169
|
+
};
|
|
170
|
+
// There should be no reference in enums.
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
const interfaceRef = this.ast.findResolvedNodeByName(reference, ts.SyntaxKind.InterfaceDeclaration);
|
|
174
|
+
if (interfaceRef) {
|
|
175
|
+
const daggerInterface = new DaggerInterface(interfaceRef.node, this.ast);
|
|
176
|
+
this.interfaces[daggerInterface.name] = daggerInterface;
|
|
177
|
+
this.references[daggerInterface.name] = {
|
|
178
|
+
kind: TypeDefKind.InterfaceKind,
|
|
179
|
+
name: daggerInterface.name,
|
|
180
|
+
};
|
|
181
|
+
this.resolveReferences(daggerInterface.getReferences());
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
const typeAliasRef = this.ast.findResolvedNodeByName(reference, ts.SyntaxKind.TypeAliasDeclaration);
|
|
185
|
+
if (typeAliasRef) {
|
|
186
|
+
// The resolution is to big so we split it in a sub function.
|
|
187
|
+
this.resolveTypeAlias(reference, typeAliasRef);
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
// Handle primitives here
|
|
191
|
+
if (reference === "String") {
|
|
192
|
+
throw new IntrospectionError(`Use of primitive 'String' type detected, please use 'string' instead.`);
|
|
193
|
+
}
|
|
194
|
+
if (reference === "Boolean") {
|
|
195
|
+
throw new IntrospectionError(`Use of primitive 'Boolean' type detected, please use 'boolean' instead.`);
|
|
196
|
+
}
|
|
197
|
+
if (reference === "Number") {
|
|
198
|
+
throw new IntrospectionError(`Use of primitive 'Number' type detected, please use 'number' instead.`);
|
|
199
|
+
}
|
|
200
|
+
throw new IntrospectionError(`could not resolve type reference for ${reference}.`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Resolve type alias to the corresponding TypeDef.
|
|
205
|
+
* A type might refer to anything typeable in TypeScript but right now we supports:
|
|
206
|
+
* - `type Example = string`
|
|
207
|
+
* - `type Example = { prop: string}`
|
|
208
|
+
* - `type Example = number`
|
|
209
|
+
* - `type Example = boolean`
|
|
210
|
+
* - `type Example = void`
|
|
211
|
+
*
|
|
212
|
+
* If the reference is an object, we recursively resolve its references.
|
|
213
|
+
* If the type cannot be resolved or is not supported, we throw an error.
|
|
214
|
+
*/
|
|
215
|
+
resolveTypeAlias(reference, typeAlias) {
|
|
216
|
+
const type = this.ast.getTypeFromTypeAlias(typeAlias.node);
|
|
217
|
+
if (type.flags & ts.TypeFlags.String) {
|
|
218
|
+
this.references[reference] = { kind: TypeDefKind.StringKind };
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (type.flags & ts.TypeFlags.Number) {
|
|
222
|
+
this.references[reference] = { kind: TypeDefKind.IntegerKind };
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (type.flags & ts.TypeFlags.Boolean) {
|
|
226
|
+
this.references[reference] = { kind: TypeDefKind.BooleanKind };
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (type.flags & ts.TypeFlags.Void) {
|
|
230
|
+
this.references[reference] = { kind: TypeDefKind.VoidKind };
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
// Scalar are defined with string intersection such as `type MyScalar = string & { __MyScalar: never }`
|
|
234
|
+
if (type.flags & ts.TypeFlags.Intersection ||
|
|
235
|
+
type.flags & ts.TypeFlags.Union) {
|
|
236
|
+
this.references[reference] = {
|
|
237
|
+
kind: TypeDefKind.ScalarKind,
|
|
238
|
+
name: reference,
|
|
239
|
+
};
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (type.flags & ts.TypeFlags.Object) {
|
|
243
|
+
if (typeAlias.file.fileName.endsWith(CLIENT_GEN_FILE)) {
|
|
244
|
+
this.references[reference] = {
|
|
245
|
+
kind: TypeDefKind.ObjectKind,
|
|
246
|
+
name: reference,
|
|
247
|
+
};
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const daggerObject = new DaggerTypeObject(typeAlias.node, this.ast);
|
|
251
|
+
this.objects[daggerObject.name] = daggerObject;
|
|
252
|
+
this.references[daggerObject.name] = {
|
|
253
|
+
kind: TypeDefKind.ObjectKind,
|
|
254
|
+
name: daggerObject.name,
|
|
255
|
+
};
|
|
256
|
+
this.resolveReferences(daggerObject.getReferences());
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
throw new IntrospectionError(`could not resolve type reference for ${reference} at ${AST.getNodePosition(typeAlias.node)}`);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Find the classes in the AST. Returns only our main class if it exists
|
|
263
|
+
*/
|
|
264
|
+
findClasses() {
|
|
265
|
+
const allClassDeclarations = this.ast.findAllDeclarations(ts.SyntaxKind.ClassDeclaration);
|
|
266
|
+
const allClasses = [];
|
|
267
|
+
for (const classDecl of allClassDeclarations) {
|
|
268
|
+
const convertedDecl = classDecl;
|
|
269
|
+
// Check if the class matches this.name and return only that if so
|
|
270
|
+
if (convertedDecl.node.name &&
|
|
271
|
+
convertedDecl.node.name.getText() === this.name) {
|
|
272
|
+
return [convertedDecl];
|
|
273
|
+
}
|
|
274
|
+
// or we return all classes decorated with @object
|
|
275
|
+
if (this.ast.isNodeDecoratedWith(classDecl.node, OBJECT_DECORATOR)) {
|
|
276
|
+
allClasses.push(convertedDecl);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return allClasses;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Recursively propagate references to all objects properties and functions.
|
|
283
|
+
*/
|
|
284
|
+
propagateReferences() {
|
|
285
|
+
for (const object of Object.values(this.objects)) {
|
|
286
|
+
object.propagateReferences(this.references);
|
|
287
|
+
}
|
|
288
|
+
for (const interface_ of Object.values(this.interfaces)) {
|
|
289
|
+
interface_.propagateReferences(this.references);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Get the top level comment of the file that contains the module entrypoint.
|
|
294
|
+
*/
|
|
295
|
+
getDescription(sourceFileContent) {
|
|
296
|
+
const regex = /^(?!.*import)[\s]*\/\*\*([\s\S]*?)\*\//;
|
|
297
|
+
const match = sourceFileContent.match(regex);
|
|
298
|
+
if (!match) {
|
|
299
|
+
return undefined;
|
|
300
|
+
}
|
|
301
|
+
const comment = match[1]
|
|
302
|
+
.split("\n")
|
|
303
|
+
.map((line) => line.replace(/^\s*\*\s?/, ""))
|
|
304
|
+
.join("\n");
|
|
305
|
+
return comment.trim();
|
|
306
|
+
}
|
|
307
|
+
toJSON() {
|
|
308
|
+
return {
|
|
309
|
+
name: this.name,
|
|
310
|
+
description: this.description,
|
|
311
|
+
objects: this.objects,
|
|
312
|
+
enums: this.enums,
|
|
313
|
+
interfaces: this.interfaces,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { AST, Location } from "../typescript_module/index.js";
|
|
3
|
+
import { DaggerConstructor } from "./constructor.js";
|
|
4
|
+
import { DaggerFunctions } from "./function.js";
|
|
5
|
+
import { Locatable } from "./locatable.js";
|
|
6
|
+
import { DaggerObjectBase } from "./objectBase.js";
|
|
7
|
+
import { DaggerProperties } from "./property.js";
|
|
8
|
+
import { References } from "./reference.js";
|
|
9
|
+
/**
|
|
10
|
+
* Represents an object defined using the `class` keyword.
|
|
11
|
+
*
|
|
12
|
+
* The class may contains methods and fields, that may or may not be exposed to the Dagger API.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* type MyObject = {
|
|
17
|
+
* name: string
|
|
18
|
+
* age: number
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class DaggerObject extends Locatable implements DaggerObjectBase {
|
|
23
|
+
private readonly node;
|
|
24
|
+
private readonly ast;
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
deprecated?: string;
|
|
28
|
+
_constructor: DaggerConstructor | undefined;
|
|
29
|
+
methods: DaggerFunctions;
|
|
30
|
+
properties: DaggerProperties;
|
|
31
|
+
private symbol;
|
|
32
|
+
kind(): "class" | "object";
|
|
33
|
+
constructor(node: ts.ClassDeclaration, ast: AST);
|
|
34
|
+
getLocation(): Location;
|
|
35
|
+
getReferences(): string[];
|
|
36
|
+
propagateReferences(references: References): void;
|
|
37
|
+
toJSON(): {
|
|
38
|
+
name: string;
|
|
39
|
+
description: string;
|
|
40
|
+
deprecated: string | undefined;
|
|
41
|
+
constructor: DaggerConstructor | undefined;
|
|
42
|
+
methods: DaggerFunctions;
|
|
43
|
+
properties: DaggerProperties;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# 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,QAAQ,EAAE,MAAM,+BAA+B,CAAA;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAEpD,OAAO,EAAkB,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAkB,MAAM,eAAe,CAAA;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C;;;;;;;;;;;;GAYG;AACH,qBAAa,YAAa,SAAQ,SAAU,YAAW,gBAAgB;IAenE,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAff,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,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;IAyDpB,WAAW,IAAI,QAAQ;IAIvB,aAAa,IAAI,MAAM,EAAE;IAqBzB,mBAAmB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAcjD,MAAM;;;;;;;;CAUd"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { IntrospectionError } from "../../../common/errors/index.js";
|
|
3
|
+
import { AST } from "../typescript_module/index.js";
|
|
4
|
+
import { DaggerConstructor } from "./constructor.js";
|
|
5
|
+
import { FUNCTION_DECORATOR, OBJECT_DECORATOR } from "./decorator.js";
|
|
6
|
+
import { DaggerFunction } from "./function.js";
|
|
7
|
+
import { Locatable } from "./locatable.js";
|
|
8
|
+
import { DaggerProperty } from "./property.js";
|
|
9
|
+
/**
|
|
10
|
+
* Represents an object defined using the `class` keyword.
|
|
11
|
+
*
|
|
12
|
+
* The class may contains methods and fields, that may or may not be exposed to the Dagger API.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* type MyObject = {
|
|
17
|
+
* name: string
|
|
18
|
+
* age: number
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export class DaggerObject extends Locatable {
|
|
23
|
+
node;
|
|
24
|
+
ast;
|
|
25
|
+
name;
|
|
26
|
+
description;
|
|
27
|
+
deprecated;
|
|
28
|
+
_constructor = undefined;
|
|
29
|
+
methods = {};
|
|
30
|
+
properties = {};
|
|
31
|
+
symbol;
|
|
32
|
+
kind() {
|
|
33
|
+
return "class";
|
|
34
|
+
}
|
|
35
|
+
constructor(node, ast) {
|
|
36
|
+
super(node);
|
|
37
|
+
this.node = node;
|
|
38
|
+
this.ast = ast;
|
|
39
|
+
if (!this.node.name) {
|
|
40
|
+
throw new IntrospectionError(`could not resolve name of class at ${AST.getNodePosition(node)}.`);
|
|
41
|
+
}
|
|
42
|
+
this.name = this.node.name.getText();
|
|
43
|
+
if (!this.ast.isNodeDecoratedWith(node, OBJECT_DECORATOR)) {
|
|
44
|
+
throw new IntrospectionError(`class ${this.name} at ${AST.getNodePosition(node)} is used by the module but not exposed with a dagger decorator.`);
|
|
45
|
+
}
|
|
46
|
+
const modifiers = ts.getCombinedModifierFlags(this.node);
|
|
47
|
+
if (!(modifiers & ts.ModifierFlags.Export)) {
|
|
48
|
+
console.warn(`missing export in class ${this.name} at ${AST.getNodePosition(node)} but it's used by the module.`);
|
|
49
|
+
}
|
|
50
|
+
this.symbol = this.ast.getSymbolOrThrow(this.node.name);
|
|
51
|
+
const { description, deprecated } = this.ast.getSymbolDoc(this.symbol);
|
|
52
|
+
this.description = description;
|
|
53
|
+
this.deprecated = deprecated;
|
|
54
|
+
for (const member of this.node.members) {
|
|
55
|
+
if (ts.isPropertyDeclaration(member)) {
|
|
56
|
+
const property = new DaggerProperty(member, this.ast);
|
|
57
|
+
this.properties[property.alias ?? property.name] = property;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (ts.isConstructorDeclaration(member)) {
|
|
61
|
+
this._constructor = new DaggerConstructor(member, this.ast);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (ts.isMethodDeclaration(member) &&
|
|
65
|
+
this.ast.isNodeDecoratedWith(member, FUNCTION_DECORATOR)) {
|
|
66
|
+
const daggerFunction = new DaggerFunction(member, this.ast);
|
|
67
|
+
this.methods[daggerFunction.alias ?? daggerFunction.name] =
|
|
68
|
+
daggerFunction;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
getLocation() {
|
|
74
|
+
return AST.getNodeLocation(this.node);
|
|
75
|
+
}
|
|
76
|
+
getReferences() {
|
|
77
|
+
const references = [];
|
|
78
|
+
if (this._constructor) {
|
|
79
|
+
references.push(...this._constructor.getReferences());
|
|
80
|
+
}
|
|
81
|
+
for (const property of Object.values(this.properties)) {
|
|
82
|
+
const ref = property.getReference();
|
|
83
|
+
if (ref) {
|
|
84
|
+
references.push(ref);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
for (const fn of Object.values(this.methods)) {
|
|
88
|
+
references.push(...fn.getReferences());
|
|
89
|
+
}
|
|
90
|
+
return references.filter((v, i, arr) => arr.indexOf(v) === i);
|
|
91
|
+
}
|
|
92
|
+
propagateReferences(references) {
|
|
93
|
+
if (this._constructor) {
|
|
94
|
+
this._constructor.propagateReferences(references);
|
|
95
|
+
}
|
|
96
|
+
for (const property of Object.values(this.properties)) {
|
|
97
|
+
property.propagateReferences(references);
|
|
98
|
+
}
|
|
99
|
+
for (const fn of Object.values(this.methods)) {
|
|
100
|
+
fn.propagateReferences(references);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
toJSON() {
|
|
104
|
+
return {
|
|
105
|
+
name: this.name,
|
|
106
|
+
description: this.description,
|
|
107
|
+
deprecated: this.deprecated,
|
|
108
|
+
constructor: this._constructor,
|
|
109
|
+
methods: this.methods,
|
|
110
|
+
properties: this.properties,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { TypeDefKind } from "../../../api/client.gen.js";
|
|
2
|
+
import { TypeDef } from "../typedef.js";
|
|
3
|
+
import { DaggerConstructor } from "./constructor.js";
|
|
4
|
+
import { DaggerFunctions } from "./function.js";
|
|
5
|
+
import { Locatable } from "./locatable.js";
|
|
6
|
+
import { References } from "./reference.js";
|
|
7
|
+
export interface DaggerObjectPropertyBase extends Locatable {
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
deprecated?: string;
|
|
11
|
+
alias?: string;
|
|
12
|
+
isExposed: boolean;
|
|
13
|
+
type?: TypeDef<TypeDefKind>;
|
|
14
|
+
propagateReferences(references: References): void;
|
|
15
|
+
}
|
|
16
|
+
export type DaggerObjectPropertiesBase = {
|
|
17
|
+
[name: string]: DaggerObjectPropertyBase;
|
|
18
|
+
};
|
|
19
|
+
export interface DaggerObjectBase extends Locatable {
|
|
20
|
+
name: string;
|
|
21
|
+
description: string;
|
|
22
|
+
deprecated?: string;
|
|
23
|
+
_constructor: DaggerConstructor | undefined;
|
|
24
|
+
methods: DaggerFunctions;
|
|
25
|
+
properties: DaggerObjectPropertiesBase;
|
|
26
|
+
kind(): "class" | "object";
|
|
27
|
+
propagateReferences(references: References): void;
|
|
28
|
+
}
|
|
29
|
+
export type DaggerObjectsBase = {
|
|
30
|
+
[name: string]: DaggerObjectBase;
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=objectBase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objectBase.d.ts","sourceRoot":"","sources":["../../../../../src/module/introspector/dagger_module/objectBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,MAAM,WAAW,wBAAyB,SAAQ,SAAS;IACzD,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;IAE3B,mBAAmB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAAA;CAClD;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,CAAC,IAAI,EAAE,MAAM,GAAG,wBAAwB,CAAA;CACzC,CAAA;AAED,MAAM,WAAW,gBAAiB,SAAQ,SAAS;IACjD,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,iBAAiB,GAAG,SAAS,CAAA;IAC3C,OAAO,EAAE,eAAe,CAAA;IACxB,UAAU,EAAE,0BAA0B,CAAA;IAEtC,IAAI,IAAI,OAAO,GAAG,QAAQ,CAAA;IAE1B,mBAAmB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAAA;CAClD;AAED,MAAM,MAAM,iBAAiB,GAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAAA;CAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
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 { Locatable } from "./locatable.js";
|
|
6
|
+
import { DaggerObjectPropertyBase } from "./objectBase.js";
|
|
7
|
+
import { References } from "./reference.js";
|
|
8
|
+
export type DaggerProperties = {
|
|
9
|
+
[name: string]: DaggerProperty;
|
|
10
|
+
};
|
|
11
|
+
export declare class DaggerProperty extends Locatable implements DaggerObjectPropertyBase {
|
|
12
|
+
private readonly node;
|
|
13
|
+
private readonly ast;
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
deprecated?: string;
|
|
17
|
+
alias: string | undefined;
|
|
18
|
+
isExposed: boolean;
|
|
19
|
+
private symbol;
|
|
20
|
+
private _typeRef?;
|
|
21
|
+
type?: TypeDef<TypeDefKind>;
|
|
22
|
+
constructor(node: ts.PropertyDeclaration, ast: AST);
|
|
23
|
+
private getAlias;
|
|
24
|
+
private getType;
|
|
25
|
+
getReference(): string | undefined;
|
|
26
|
+
propagateReferences(references: References): void;
|
|
27
|
+
toJSON(): {
|
|
28
|
+
name: string;
|
|
29
|
+
description: string;
|
|
30
|
+
deprecated: string | undefined;
|
|
31
|
+
alias: string | undefined;
|
|
32
|
+
type: TypeDef<TypeDefKind> | undefined;
|
|
33
|
+
isExposed: boolean;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=property.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../../../../src/module/introspector/dagger_module/property.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;AAEtC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,MAAM,MAAM,gBAAgB,GAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAAA;CAAE,CAAA;AAEjE,qBAAa,cACX,SAAQ,SACR,YAAW,wBAAwB;IAajC,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAZf,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,SAAS,EAAE,OAAO,CAAA;IAEzB,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,QAAQ,CAAC,CAAQ;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;gBAGf,IAAI,EAAE,EAAE,CAAC,mBAAmB,EAC5B,GAAG,EAAE,GAAG;IAuB3B,OAAO,CAAC,QAAQ;IAsBhB,OAAO,CAAC,OAAO;IAWR,YAAY,IAAI,MAAM,GAAG,SAAS;IAWlC,mBAAmB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAmBjD,MAAM;;;;;;;;CAUd"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { IntrospectionError } from "../../../common/errors/index.js";
|
|
2
|
+
import { AST, isTypeDefResolved, resolveTypeDef, } from "../typescript_module/index.js";
|
|
3
|
+
import { FIELD_DECORATOR, FUNCTION_DECORATOR } from "./decorator.js";
|
|
4
|
+
import { Locatable } from "./locatable.js";
|
|
5
|
+
export class DaggerProperty extends Locatable {
|
|
6
|
+
node;
|
|
7
|
+
ast;
|
|
8
|
+
name;
|
|
9
|
+
description;
|
|
10
|
+
deprecated;
|
|
11
|
+
alias;
|
|
12
|
+
isExposed;
|
|
13
|
+
symbol;
|
|
14
|
+
_typeRef;
|
|
15
|
+
type;
|
|
16
|
+
constructor(node, ast) {
|
|
17
|
+
super(node);
|
|
18
|
+
this.node = node;
|
|
19
|
+
this.ast = ast;
|
|
20
|
+
if (!this.node.name) {
|
|
21
|
+
throw new IntrospectionError(`could not resolve name of class at ${AST.getNodePosition(node)}.`);
|
|
22
|
+
}
|
|
23
|
+
this.symbol = this.ast.getSymbolOrThrow(this.node.name);
|
|
24
|
+
this.name = this.node.name.getText();
|
|
25
|
+
this.isExposed =
|
|
26
|
+
this.ast.isNodeDecoratedWith(this.node, FUNCTION_DECORATOR) ||
|
|
27
|
+
this.ast.isNodeDecoratedWith(this.node, FIELD_DECORATOR);
|
|
28
|
+
const { description, deprecated } = this.ast.getSymbolDoc(this.symbol);
|
|
29
|
+
this.description = description;
|
|
30
|
+
this.deprecated = deprecated;
|
|
31
|
+
this.alias = this.getAlias();
|
|
32
|
+
this.type = this.getType();
|
|
33
|
+
}
|
|
34
|
+
getAlias() {
|
|
35
|
+
let alias = this.ast.getDecoratorArgument(this.node, FUNCTION_DECORATOR, "string");
|
|
36
|
+
if (alias) {
|
|
37
|
+
return JSON.parse(alias.replace(/'/g, '"'));
|
|
38
|
+
}
|
|
39
|
+
alias = this.ast.getDecoratorArgument(this.node, FIELD_DECORATOR, "string");
|
|
40
|
+
if (alias) {
|
|
41
|
+
return JSON.parse(alias.replace(/'/g, '"'));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
getType() {
|
|
45
|
+
const type = this.ast.checker.getTypeAtLocation(this.node);
|
|
46
|
+
const typedef = this.ast.tsTypeToTypeDef(this.node, type);
|
|
47
|
+
if (typedef === undefined || !isTypeDefResolved(typedef)) {
|
|
48
|
+
this._typeRef = this.ast.typeToStringType(type);
|
|
49
|
+
}
|
|
50
|
+
return typedef;
|
|
51
|
+
}
|
|
52
|
+
getReference() {
|
|
53
|
+
if (this._typeRef &&
|
|
54
|
+
(this.type === undefined || !isTypeDefResolved(this.type))) {
|
|
55
|
+
return this._typeRef;
|
|
56
|
+
}
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
propagateReferences(references) {
|
|
60
|
+
if (!this._typeRef) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (this.type && isTypeDefResolved(this.type)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const typeDef = references[this._typeRef];
|
|
67
|
+
if (!typeDef) {
|
|
68
|
+
throw new IntrospectionError(`could not find type reference for ${this._typeRef} at ${AST.getNodePosition(this.node)}.`);
|
|
69
|
+
}
|
|
70
|
+
this.type = resolveTypeDef(this.type, typeDef);
|
|
71
|
+
}
|
|
72
|
+
toJSON() {
|
|
73
|
+
return {
|
|
74
|
+
name: this.name,
|
|
75
|
+
description: this.description,
|
|
76
|
+
deprecated: this.deprecated,
|
|
77
|
+
alias: this.alias,
|
|
78
|
+
type: this.type,
|
|
79
|
+
isExposed: this.isExposed,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TypeDefKind } from "../../../api/client.gen.js";
|
|
2
|
+
import { TypeDef } from "../typedef.js";
|
|
3
|
+
export type References = {
|
|
4
|
+
[name: string]: TypeDef<TypeDefKind>;
|
|
5
|
+
};
|
|
6
|
+
export type ReferencableType = TypeDef<TypeDefKind.ObjectKind> | TypeDef<TypeDefKind.EnumKind> | TypeDef<TypeDefKind.FloatKind> | TypeDef<TypeDefKind.ScalarKind> | TypeDef<TypeDefKind.InterfaceKind>;
|
|
7
|
+
export declare function isKindArray(type: TypeDef<TypeDefKind>): type is TypeDef<TypeDefKind.ListKind>;
|
|
8
|
+
export declare function isKindObject(type: TypeDef<TypeDefKind>): type is TypeDef<TypeDefKind.ObjectKind>;
|
|
9
|
+
export declare function isKindEnum(type: TypeDef<TypeDefKind>): type is TypeDef<TypeDefKind.EnumKind>;
|
|
10
|
+
export declare function isKindScalar(type: TypeDef<TypeDefKind>): type is TypeDef<TypeDefKind.ScalarKind>;
|
|
11
|
+
export declare function isReferencableTypeDef(type: TypeDef<TypeDefKind>): boolean;
|
|
12
|
+
export declare function getTypeDefArrayBaseType(type: TypeDef<TypeDefKind>): TypeDef<TypeDefKind>;
|
|
13
|
+
//# sourceMappingURL=reference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../../../../src/module/introspector/dagger_module/reference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC,MAAM,MAAM,UAAU,GAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;CAAE,CAAA;AAEjE,MAAM,MAAM,gBAAgB,GACxB,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,GAC/B,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,GAC7B,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,GAC9B,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,GAC/B,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,CAAA;AAEtC,wBAAgB,WAAW,CACzB,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,GACzB,IAAI,IAAI,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAEvC;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,GACzB,IAAI,IAAI,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,CAEzC;AAED,wBAAgB,UAAU,CACxB,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,GACzB,IAAI,IAAI,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAEvC;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,GACzB,IAAI,IAAI,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,CAEzC;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAazE;AAED,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,GACzB,OAAO,CAAC,WAAW,CAAC,CAMtB"}
|