@dagger.io/dagger 0.10.1 → 0.10.3

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.
Files changed (56) hide show
  1. package/dist/api/client.gen.d.ts +80 -5
  2. package/dist/api/client.gen.d.ts.map +1 -1
  3. package/dist/api/client.gen.js +168 -5
  4. package/dist/api/utils.d.ts.map +1 -1
  5. package/dist/api/utils.js +6 -2
  6. package/dist/common/errors/ExecError.d.ts.map +1 -1
  7. package/dist/entrypoint/context.d.ts +8 -0
  8. package/dist/entrypoint/context.d.ts.map +1 -0
  9. package/dist/entrypoint/invoke.d.ts +3 -9
  10. package/dist/entrypoint/invoke.d.ts.map +1 -1
  11. package/dist/entrypoint/invoke.js +17 -28
  12. package/dist/entrypoint/load.d.ts +29 -69
  13. package/dist/entrypoint/load.d.ts.map +1 -1
  14. package/dist/entrypoint/load.js +93 -173
  15. package/dist/entrypoint/register.d.ts +2 -2
  16. package/dist/entrypoint/register.d.ts.map +1 -1
  17. package/dist/entrypoint/register.js +12 -12
  18. package/dist/index.d.ts +3 -2
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/introspector/scanner/abtractions/argument.d.ts +75 -0
  21. package/dist/introspector/scanner/abtractions/argument.d.ts.map +1 -0
  22. package/dist/introspector/scanner/abtractions/argument.js +137 -0
  23. package/dist/introspector/scanner/abtractions/constructor.d.ts +16 -0
  24. package/dist/introspector/scanner/abtractions/constructor.d.ts.map +1 -0
  25. package/dist/introspector/scanner/abtractions/constructor.js +42 -0
  26. package/dist/introspector/scanner/abtractions/method.d.ts +51 -0
  27. package/dist/introspector/scanner/abtractions/method.d.ts.map +1 -0
  28. package/dist/introspector/scanner/abtractions/method.js +105 -0
  29. package/dist/introspector/scanner/abtractions/module.d.ts +18 -0
  30. package/dist/introspector/scanner/abtractions/module.d.ts.map +1 -0
  31. package/dist/introspector/scanner/abtractions/module.js +59 -0
  32. package/dist/introspector/scanner/abtractions/object.d.ts +37 -0
  33. package/dist/introspector/scanner/abtractions/object.d.ts.map +1 -0
  34. package/dist/introspector/scanner/abtractions/object.js +94 -0
  35. package/dist/introspector/scanner/abtractions/property.d.ts +46 -0
  36. package/dist/introspector/scanner/abtractions/property.d.ts.map +1 -0
  37. package/dist/introspector/scanner/abtractions/property.js +93 -0
  38. package/dist/introspector/scanner/scan.d.ts +2 -1
  39. package/dist/introspector/scanner/scan.d.ts.map +1 -1
  40. package/dist/introspector/scanner/scan.js +2 -181
  41. package/dist/introspector/scanner/serialize.d.ts +0 -24
  42. package/dist/introspector/scanner/serialize.d.ts.map +1 -1
  43. package/dist/introspector/scanner/serialize.js +0 -53
  44. package/dist/introspector/scanner/typeDefs.d.ts +3 -3
  45. package/dist/introspector/scanner/typeDefs.d.ts.map +1 -1
  46. package/dist/introspector/scanner/utils.d.ts +1 -57
  47. package/dist/introspector/scanner/utils.d.ts.map +1 -1
  48. package/dist/introspector/scanner/utils.js +16 -149
  49. package/dist/provisioning/bin.d.ts.map +1 -1
  50. package/dist/provisioning/bin.js +10 -4
  51. package/dist/provisioning/default.d.ts +1 -1
  52. package/dist/provisioning/default.js +1 -1
  53. package/package.json +5 -2
  54. package/dist/introspector/scanner/metadata.d.ts +0 -24
  55. package/dist/introspector/scanner/metadata.d.ts.map +0 -1
  56. /package/dist/{introspector/scanner/metadata.js → entrypoint/context.js} +0 -0
@@ -0,0 +1,46 @@
1
+ import ts from "typescript";
2
+ import { FieldTypeDef, TypeDef } from "../typeDefs.js";
3
+ import { TypeDefKind } from "../../../api/client.gen.js";
4
+ export type Properties = {
5
+ [name: string]: Property;
6
+ };
7
+ /**
8
+ * Property is an abstraction of a class property.
9
+ *
10
+ * This aims to simplify and adds clarity to how we analyse the code and using
11
+ * clear accessor.
12
+ */
13
+ export declare class Property {
14
+ private symbol;
15
+ private checker;
16
+ private property;
17
+ private decorator;
18
+ /**
19
+ *
20
+ * @param checker Checker to use to introspect the property.
21
+ * @param property The property to introspect.
22
+ *
23
+ * @throws UnknownDaggerError If the property doesn't have any symbol.
24
+ */
25
+ constructor(checker: ts.TypeChecker, property: ts.PropertyDeclaration);
26
+ get name(): string;
27
+ get description(): string;
28
+ /**
29
+ * Return the alias of the property if it has one.
30
+ */
31
+ get alias(): string | undefined;
32
+ /**
33
+ * Return the type of the property in a Dagger TypeDef format.
34
+ */
35
+ get type(): TypeDef<TypeDefKind>;
36
+ get isExposed(): boolean;
37
+ get typeDef(): FieldTypeDef;
38
+ toJSON(): {
39
+ name: string;
40
+ description: string;
41
+ alias: string | undefined;
42
+ type: TypeDef<TypeDefKind>;
43
+ isExposed: boolean;
44
+ };
45
+ }
46
+ //# sourceMappingURL=property.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../../../introspector/scanner/abtractions/property.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAK3B,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAIxD,MAAM,MAAM,UAAU,GAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAA;AAErD;;;;;GAKG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,MAAM,CAAW;IAEzB,OAAO,CAAC,OAAO,CAAgB;IAE/B,OAAO,CAAC,QAAQ,CAAwB;IAExC,OAAO,CAAC,SAAS,CAA0B;IAE3C;;;;;;OAMG;gBACS,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,QAAQ,EAAE,EAAE,CAAC,mBAAmB;IAuBrE,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,WAAW,IAAI,MAAM,CAIxB;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,GAAG,SAAS,CAa9B;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,OAAO,CAAC,WAAW,CAAC,CAgB/B;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;IAID,IAAI,OAAO,IAAI,YAAY,CAQ1B;IAED,MAAM;;;;;;;CASP"}
@@ -0,0 +1,93 @@
1
+ import ts from "typescript";
2
+ import { UnknownDaggerError } from "../../../common/errors/UnknownDaggerError.js";
3
+ import { serializeType } from "../serialize.js";
4
+ import { typeNameToTypedef } from "../utils.js";
5
+ const PROPERTY_DECORATOR = "field";
6
+ /**
7
+ * Property is an abstraction of a class property.
8
+ *
9
+ * This aims to simplify and adds clarity to how we analyse the code and using
10
+ * clear accessor.
11
+ */
12
+ export class Property {
13
+ symbol;
14
+ checker;
15
+ property;
16
+ decorator;
17
+ /**
18
+ *
19
+ * @param checker Checker to use to introspect the property.
20
+ * @param property The property to introspect.
21
+ *
22
+ * @throws UnknownDaggerError If the property doesn't have any symbol.
23
+ */
24
+ constructor(checker, property) {
25
+ this.checker = checker;
26
+ this.property = property;
27
+ const propertySymbol = checker.getSymbolAtLocation(property.name);
28
+ if (!propertySymbol) {
29
+ throw new UnknownDaggerError(`could not get property symbol: ${property.name.getText()}`, {});
30
+ }
31
+ this.symbol = propertySymbol;
32
+ this.decorator = ts.getDecorators(property)?.find((d) => {
33
+ if (ts.isCallExpression(d.expression)) {
34
+ return d.expression.expression.getText() === PROPERTY_DECORATOR;
35
+ }
36
+ return false;
37
+ });
38
+ }
39
+ get name() {
40
+ return this.property.name.getText();
41
+ }
42
+ get description() {
43
+ return ts.displayPartsToString(this.symbol.getDocumentationComment(this.checker));
44
+ }
45
+ /**
46
+ * Return the alias of the property if it has one.
47
+ */
48
+ get alias() {
49
+ if (!this.decorator) {
50
+ return undefined;
51
+ }
52
+ const expression = this.decorator.expression;
53
+ const aliasArg = expression.arguments[0];
54
+ if (!aliasArg) {
55
+ return undefined;
56
+ }
57
+ return JSON.parse(aliasArg.getText().replace(/'/g, '"'));
58
+ }
59
+ /**
60
+ * Return the type of the property in a Dagger TypeDef format.
61
+ */
62
+ get type() {
63
+ if (!this.symbol.valueDeclaration) {
64
+ throw new UnknownDaggerError("could not find symbol value declaration", {});
65
+ }
66
+ const type = this.checker.getTypeOfSymbolAtLocation(this.symbol, this.symbol.valueDeclaration);
67
+ const typeName = serializeType(this.checker, type);
68
+ return typeNameToTypedef(typeName);
69
+ }
70
+ get isExposed() {
71
+ return this.decorator !== undefined;
72
+ }
73
+ // TODO(TomChv): replace with `ToJson` method
74
+ // after the refactor is complete.
75
+ get typeDef() {
76
+ return {
77
+ name: this.name,
78
+ description: this.description,
79
+ alias: this.alias,
80
+ typeDef: this.type,
81
+ isExposed: this.isExposed,
82
+ };
83
+ }
84
+ toJSON() {
85
+ return {
86
+ name: this.name,
87
+ description: this.description,
88
+ alias: this.alias,
89
+ type: this.type,
90
+ isExposed: this.isExposed,
91
+ };
92
+ }
93
+ }
@@ -1,4 +1,5 @@
1
1
  import { ClassTypeDef, FunctionTypedef } from "./typeDefs.js";
2
+ import { DaggerModule } from "./abtractions/module.js";
2
3
  export type ScanResult = {
3
4
  module: {
4
5
  description?: string;
@@ -21,5 +22,5 @@ export type ScanResult = {
21
22
  * @param files List of TypeScript files to introspect.
22
23
  * @param moduleName The name of the module to introspect.
23
24
  */
24
- export declare function scan(files: string[], moduleName?: string): ScanResult;
25
+ export declare function scan(files: string[], moduleName?: string): DaggerModule;
25
26
  //# sourceMappingURL=scan.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/scan.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,YAAY,EAIZ,eAAe,EAChB,MAAM,eAAe,CAAA;AAWtB,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE;QACN,WAAW,CAAC,EAAE,MAAM,CAAA;KACrB,CAAA;IACD,OAAO,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAA;KAAE,CAAA;IACzC,SAAS,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;KAAE,CAAA;CAC/C,CAAA;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,UAAU,SAAK,GAAG,UAAU,CAoCjE"}
1
+ {"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/scan.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAEtD,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE;QACN,WAAW,CAAC,EAAE,MAAM,CAAA;KACrB,CAAA;IACD,OAAO,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAA;KAAE,CAAA;IACzC,SAAS,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;KAAE,CAAA;CAC/C,CAAA;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,UAAU,SAAK,GAAG,YAAY,CAUnE"}
@@ -1,7 +1,6 @@
1
1
  import ts from "typescript";
2
2
  import { UnknownDaggerError } from "../../common/errors/UnknownDaggerError.js";
3
- import { serializeSignature, serializeSymbol } from "./serialize.js";
4
- import { getAlias, isFunction, isMainObject, isObject, isOptional, isPublicProperty, typeNameToTypedef, } from "./utils.js";
3
+ import { DaggerModule } from "./abtractions/module.js";
5
4
  /**
6
5
  * Scan the list of TypeScript File using the TypeScript compiler API.
7
6
  *
@@ -20,183 +19,5 @@ export function scan(files, moduleName = "") {
20
19
  // Interpret the given typescript source files.
21
20
  const program = ts.createProgram(files, { experimentalDecorators: true });
22
21
  const checker = program.getTypeChecker();
23
- const metadata = {
24
- module: {},
25
- classes: {},
26
- functions: {},
27
- };
28
- for (const file of program.getSourceFiles()) {
29
- // Ignore type declaration files.
30
- if (file.isDeclarationFile) {
31
- continue;
32
- }
33
- ts.forEachChild(file, (node) => {
34
- // Handle class
35
- if (ts.isClassDeclaration(node) && isObject(node)) {
36
- const classTypeDef = introspectClass(checker, node);
37
- if (isMainObject(classTypeDef.name, moduleName)) {
38
- metadata.module.description = introspectTopLevelComment(file);
39
- }
40
- metadata.classes[classTypeDef.name] = classTypeDef;
41
- }
42
- });
43
- }
44
- return metadata;
45
- }
46
- /**
47
- * Introspect a class and return its metadata.
48
- *
49
- * This function goes throw all class' method that have the @fct decorator
50
- * and all its public properties.
51
- *
52
- * This function throws an error if it cannot read its symbol.
53
- *
54
- * @param checker The typescript compiler checker.
55
- * @param node The class to check.
56
- */
57
- function introspectClass(checker, node) {
58
- // Throw error if node.name is undefined because we cannot scan its symbol.
59
- if (!node.name) {
60
- throw new UnknownDaggerError(`could not introspect class: ${node}`, {});
61
- }
62
- // Retrieve class symbol.
63
- const classSymbol = checker.getSymbolAtLocation(node.name);
64
- if (!classSymbol) {
65
- throw new UnknownDaggerError(`could not get class symbol: ${node.name.getText()}`, {});
66
- }
67
- // Serialize class symbol to extract name and doc.
68
- const { name, description } = serializeSymbol(checker, classSymbol);
69
- // Create metadata object.
70
- const metadata = {
71
- name,
72
- description,
73
- constructor: undefined,
74
- fields: {},
75
- methods: {},
76
- };
77
- // Loop through all members in the class to get their metadata.
78
- node.members.forEach((member) => {
79
- // Handle constructor
80
- if (ts.isConstructorDeclaration(member)) {
81
- metadata.constructor = introspectConstructor(checker, member);
82
- }
83
- // Handle method from the class.
84
- if (ts.isMethodDeclaration(member) && isFunction(member)) {
85
- const fctTypeDef = introspectMethod(checker, member);
86
- metadata.methods[fctTypeDef.alias ?? fctTypeDef.name] = fctTypeDef;
87
- }
88
- // Handle public properties from the class.
89
- if (ts.isPropertyDeclaration(member)) {
90
- const fieldTypeDef = introspectProperty(checker, member);
91
- metadata.fields[fieldTypeDef.alias ?? fieldTypeDef.name] = fieldTypeDef;
92
- }
93
- });
94
- return metadata;
95
- }
96
- /**
97
- * Introspect a property from a class and return its metadata.
98
- *
99
- * This function throws an error if it cannot retrieve the property symbols.
100
- *
101
- * @param checker The typescript compiler checker.
102
- * @param property The method to check.
103
- */
104
- function introspectProperty(checker, property) {
105
- const propertySymbol = checker.getSymbolAtLocation(property.name);
106
- if (!propertySymbol) {
107
- throw new UnknownDaggerError(`could not get property symbol: ${property.name.getText()}`, {});
108
- }
109
- const { name, typeName, description } = serializeSymbol(checker, propertySymbol);
110
- return {
111
- name,
112
- description,
113
- alias: getAlias(property, "field"),
114
- typeDef: typeNameToTypedef(typeName),
115
- isExposed: isPublicProperty(property),
116
- };
117
- }
118
- /**
119
- * Introspect the constructor of the class and return its metadata.
120
- */
121
- function introspectConstructor(checker, constructor) {
122
- const args = constructor.parameters.reduce((acc, param) => {
123
- const paramSymbol = checker.getSymbolAtLocation(param.name);
124
- if (!paramSymbol) {
125
- throw new UnknownDaggerError(`could not get constructor param: ${param.name.getText()}`, {});
126
- }
127
- const { name, typeName, description } = serializeSymbol(checker, paramSymbol);
128
- const { optional, defaultValue } = isOptional(paramSymbol);
129
- acc[name] = {
130
- name,
131
- description,
132
- typeDef: typeNameToTypedef(typeName),
133
- optional,
134
- defaultValue,
135
- isVariadic: false,
136
- };
137
- return acc;
138
- }, {});
139
- return { args };
140
- }
141
- /**
142
- * Introspect a method from a class and return its metadata.
143
- *
144
- * This function first retrieve the symbol of the function signature and then
145
- * loop on its parameters to get their metadata.
146
- *
147
- * This function throws an error if it cannot retrieve the method symbols.
148
- *
149
- * @param checker The typescript compiler checker.
150
- * @param method The method to check.
151
- */
152
- function introspectMethod(checker, method) {
153
- const methodSymbol = checker.getSymbolAtLocation(method.name);
154
- if (!methodSymbol) {
155
- throw new UnknownDaggerError(`could not get method symbol: ${method.name.getText()}`, {});
156
- }
157
- const methodMetadata = serializeSymbol(checker, methodSymbol);
158
- const methodSignature = methodMetadata.type
159
- .getCallSignatures()
160
- .map((methodSignature) => serializeSignature(checker, methodSignature))[0];
161
- return {
162
- name: methodMetadata.name,
163
- description: methodMetadata.description,
164
- alias: getAlias(method, "func"),
165
- args: methodSignature.params.reduce((acc, { name, typeName, description, optional, defaultValue, isVariadic }) => {
166
- acc[name] = {
167
- name,
168
- typeDef: typeNameToTypedef(typeName),
169
- description,
170
- optional,
171
- defaultValue,
172
- isVariadic,
173
- };
174
- return acc;
175
- }, {}),
176
- returnType: typeNameToTypedef(methodSignature.returnType),
177
- };
178
- }
179
- /**
180
- * Return the content of the top level comment of the given file.
181
- *
182
- * @param file The file to introspect.
183
- */
184
- function introspectTopLevelComment(file) {
185
- const firstStatement = file.statements[0];
186
- if (!firstStatement) {
187
- return undefined;
188
- }
189
- const commentRanges = ts.getLeadingCommentRanges(file.getFullText(), firstStatement.pos);
190
- if (!commentRanges || commentRanges.length === 0) {
191
- return undefined;
192
- }
193
- const commentRange = commentRanges[0];
194
- const comment = file
195
- .getFullText()
196
- .substring(commentRange.pos, commentRange.end)
197
- .split("\n")
198
- .slice(1, -1) // Remove start and ending comments characters `/** */`
199
- .map((line) => line.replace("*", "").trim()) // Remove leading * and spaces
200
- .join("\n");
201
- return comment;
22
+ return new DaggerModule(checker, moduleName, program.getSourceFiles());
202
23
  }
@@ -1,28 +1,4 @@
1
1
  import ts from "typescript";
2
- import { SignatureMetadata, SymbolMetadata } from "./metadata.js";
3
- /**
4
- * Convert the function signature from the compiler API into a lighter data type.
5
- *
6
- * This functions returns the params serialized and its returns type.
7
- *
8
- * @param checker The typescript compiler checker.
9
- * @param signature The signature to convert.
10
- */
11
- export declare function serializeSignature(checker: ts.TypeChecker, signature: ts.Signature): SignatureMetadata;
12
- /**
13
- * Convert the TypeScript symbol from the compiler API into a lighter data type.
14
- *
15
- * This function returns the name of the symbol, with its typename and its
16
- * documentation.
17
- * This function also returns the actual TypeScript type for additional
18
- * introspection.
19
- *
20
- * @param checker The typescript compiler checker.
21
- * @param symbol The type to convert.
22
- */
23
- export declare function serializeSymbol(checker: ts.TypeChecker, symbol: ts.Symbol): SymbolMetadata & {
24
- type: ts.Type;
25
- };
26
2
  /**
27
3
  * Convert the TypeScript type from the compiler API into a readable textual
28
4
  * type.
@@ -1 +1 @@
1
- {"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAG3B,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAGjE;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,SAAS,EAAE,EAAE,CAAC,SAAS,GACtB,iBAAiB,CAmBnB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,MAAM,EAAE,EAAE,CAAC,MAAM,GAChB,cAAc,GAAG;IAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAA;CAAE,CAkBpC;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,MAAM,CAS5E"}
1
+ {"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,MAAM,CAS5E"}
@@ -1,56 +1,3 @@
1
- import ts from "typescript";
2
- import { UnknownDaggerError } from "../../common/errors/UnknownDaggerError.js";
3
- import { isOptional, isVariadic } from "./utils.js";
4
- /**
5
- * Convert the function signature from the compiler API into a lighter data type.
6
- *
7
- * This functions returns the params serialized and its returns type.
8
- *
9
- * @param checker The typescript compiler checker.
10
- * @param signature The signature to convert.
11
- */
12
- export function serializeSignature(checker, signature) {
13
- return {
14
- params: signature.parameters.map((param) => {
15
- // eslint-disable-next-line prefer-const
16
- let { optional, defaultValue } = isOptional(param);
17
- const variadic = isVariadic(param);
18
- if (variadic) {
19
- optional = true;
20
- }
21
- return {
22
- ...serializeSymbol(checker, param),
23
- optional,
24
- defaultValue,
25
- isVariadic: variadic,
26
- };
27
- }),
28
- returnType: serializeType(checker, signature.getReturnType()),
29
- };
30
- }
31
- /**
32
- * Convert the TypeScript symbol from the compiler API into a lighter data type.
33
- *
34
- * This function returns the name of the symbol, with its typename and its
35
- * documentation.
36
- * This function also returns the actual TypeScript type for additional
37
- * introspection.
38
- *
39
- * @param checker The typescript compiler checker.
40
- * @param symbol The type to convert.
41
- */
42
- export function serializeSymbol(checker, symbol) {
43
- if (!symbol.valueDeclaration) {
44
- throw new UnknownDaggerError("could not find symbol value declaration", {});
45
- }
46
- const type = checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration);
47
- return {
48
- name: symbol.getName(),
49
- description: ts.displayPartsToString(symbol.getDocumentationComment(checker)),
50
- typeName: serializeType(checker, type),
51
- type,
52
- };
53
- }
54
1
  /**
55
2
  * Convert the TypeScript type from the compiler API into a readable textual
56
3
  * type.
@@ -40,7 +40,7 @@ export type FieldTypeDef = {
40
40
  /**
41
41
  * The type of function argument in a method or function.
42
42
  */
43
- export type FunctionArg = {
43
+ export type FunctionArgTypeDef = {
44
44
  name: string;
45
45
  description: string;
46
46
  optional: boolean;
@@ -56,13 +56,13 @@ export type FunctionTypedef = {
56
56
  description: string;
57
57
  alias?: string;
58
58
  args: {
59
- [name: string]: FunctionArg;
59
+ [name: string]: FunctionArgTypeDef;
60
60
  };
61
61
  returnType: TypeDef<TypeDefKind>;
62
62
  };
63
63
  export type ConstructorTypeDef = {
64
64
  args: {
65
- [name: string]: FunctionArg;
65
+ [name: string]: FunctionArgTypeDef;
66
66
  };
67
67
  };
68
68
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"typeDefs.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/typeDefs.ts"],"names":[],"m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AI,EAAE,MAAM,GAAG,eAAe,CAAA;KAAE,CAAA;CAC7C,CAAA"}
@@ -7,13 +7,7 @@ import { TypeDef } from "./typeDefs.js";
7
7
  * @param object
8
8
  */
9
9
  export declare function isObject(object: ts.ClassDeclaration): boolean;
10
- /**
11
- * Check if the class is the main object of the module.
12
- *
13
- * @param classtName The name of the class to check.
14
- * @param moduleName The name of the module.
15
- */
16
- export declare function isMainObject(className: string, moduleName: string): boolean;
10
+ export declare function toPascalCase(input: string): string;
17
11
  /**
18
12
  * Return true if the given method has the decorator @fct() on top
19
13
  * of its declaration.
@@ -21,58 +15,8 @@ export declare function isMainObject(className: string, moduleName: string): boo
21
15
  * @param method The method to check
22
16
  */
23
17
  export declare function isFunction(method: ts.MethodDeclaration): boolean;
24
- /**
25
- * Return true if the given property has the decorator @field() on top
26
- * of its declaration.
27
- *
28
- * @param property The property to check
29
- */
30
- export declare function isField(property: ts.PropertyDeclaration): boolean;
31
- export declare function getAlias(elem: ts.HasDecorators, kind: "field" | "func"): string | undefined;
32
- /**
33
- * Return true if the given property is public.
34
- *
35
- * This function actually in work the reverse, it checks if the property
36
- * isn't private nor protected.
37
- *
38
- * It returns true if the property has no modifiers since no keyword
39
- * has been set on the property.
40
- *
41
- * Example
42
- * ```
43
- * class Human {
44
- * private age = 22 // Return false
45
- * protected familyName = "Doe" // Return false
46
- *
47
- * @field
48
- * name = "John" // Return true
49
- *
50
- * city = "Paris" // Return false because there's no decorator
51
- * }
52
- * ```
53
- *
54
- * @param property The property to check on.
55
- */
56
- export declare function isPublicProperty(property: ts.PropertyDeclaration): boolean;
57
- type OptionalValue = {
58
- optional: boolean;
59
- defaultValue?: string;
60
- };
61
- /**
62
- * Return true if the parameter is optional.
63
- *
64
- * This only means optionals marked with `?`, or "nullable" types defined
65
- * with `| null`, to match the API's meaning of "optional".
66
- *
67
- * If there's a default value, its expression is returned in the result.
68
- *
69
- * @param param The param to check.
70
- */
71
- export declare function isOptional(param: ts.Symbol): OptionalValue;
72
- export declare function isVariadic(param: ts.Symbol): boolean;
73
18
  /**
74
19
  * Convert a typename into a Dagger Typedef using dynamic typing.
75
20
  */
76
21
  export declare function typeNameToTypedef(typeName: string): TypeDef<TypeDefKind>;
77
- export {};
78
22
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,gBAAgB,GAAG,OAAO,CAU7D;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAwB3E;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,iBAAiB,GAAG,OAAO,CAUhE;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,mBAAmB,GAAG,OAAO,CAUjE;AAED,wBAAgB,QAAQ,CACtB,IAAI,EAAE,EAAE,CAAC,aAAa,EACtB,IAAI,EAAE,OAAO,GAAG,MAAM,GACrB,MAAM,GAAG,SAAS,CAsBpB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,EAAE,CAAC,mBAAmB,GAAG,OAAO,CAe1E;AAED,KAAK,aAAa,GAAG;IACnB,QAAQ,EAAE,OAAO,CAAA;IACjB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,GAAG,aAAa,CAmC1D;AAED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