@dagger.io/dagger 0.9.3 → 0.9.5

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 (79) hide show
  1. package/dist/api/client.gen.d.ts +323 -280
  2. package/dist/api/client.gen.d.ts.map +1 -1
  3. package/dist/api/client.gen.js +1725 -1879
  4. package/dist/api/utils.js +73 -90
  5. package/dist/common/errors/DaggerSDKError.js +5 -1
  6. package/dist/common/errors/DockerImageRefValidationError.js +7 -3
  7. package/dist/common/errors/EngineSessionConnectParamsParseError.js +6 -2
  8. package/dist/common/errors/EngineSessionConnectionTimeoutError.js +6 -2
  9. package/dist/common/errors/EngineSessionErrorOptions.js +2 -2
  10. package/dist/common/errors/ExecError.js +18 -2
  11. package/dist/common/errors/GraphQLRequestError.js +10 -2
  12. package/dist/common/errors/InitEngineSessionBinaryError.js +2 -2
  13. package/dist/common/errors/NotAwaitedRequestError.js +2 -2
  14. package/dist/common/errors/TooManyNestedObjectsError.js +6 -2
  15. package/dist/common/errors/UnknownDaggerError.js +2 -2
  16. package/dist/common/errors/errors-codes.js +1 -1
  17. package/dist/common/utils.d.ts +4 -4
  18. package/dist/connect.d.ts +22 -27
  19. package/dist/connect.d.ts.map +1 -1
  20. package/dist/connect.js +43 -49
  21. package/dist/connectOpts.d.ts +25 -0
  22. package/dist/connectOpts.d.ts.map +1 -0
  23. package/dist/connectOpts.js +1 -0
  24. package/dist/context/builder.d.ts +9 -0
  25. package/dist/context/builder.d.ts.map +1 -0
  26. package/dist/context/builder.js +34 -0
  27. package/dist/context/context.d.ts +39 -0
  28. package/dist/context/context.d.ts.map +1 -0
  29. package/dist/context/context.js +51 -0
  30. package/dist/entrypoint/entrypoint.d.ts +2 -0
  31. package/dist/entrypoint/entrypoint.d.ts.map +1 -0
  32. package/dist/entrypoint/entrypoint.js +70 -0
  33. package/dist/entrypoint/invoke.d.ts +11 -0
  34. package/dist/entrypoint/invoke.d.ts.map +1 -0
  35. package/dist/entrypoint/invoke.js +14 -0
  36. package/dist/entrypoint/load.d.ts +16 -0
  37. package/dist/entrypoint/load.d.ts.map +1 -0
  38. package/dist/entrypoint/load.js +44 -0
  39. package/dist/entrypoint/register.d.ts +6 -0
  40. package/dist/entrypoint/register.d.ts.map +1 -0
  41. package/dist/entrypoint/register.js +93 -0
  42. package/dist/graphql/client.d.ts +3 -0
  43. package/dist/graphql/client.d.ts.map +1 -0
  44. package/dist/graphql/client.js +8 -0
  45. package/dist/index.d.ts +3 -1
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +2 -1
  48. package/dist/introspector/decorators/decorators.d.ts +4 -0
  49. package/dist/introspector/decorators/decorators.d.ts.map +1 -0
  50. package/dist/introspector/decorators/decorators.js +7 -0
  51. package/dist/introspector/registry/registry.d.ts +65 -0
  52. package/dist/introspector/registry/registry.d.ts.map +1 -0
  53. package/dist/introspector/registry/registry.js +125 -0
  54. package/dist/introspector/scanner/metadata.d.ts +23 -0
  55. package/dist/introspector/scanner/metadata.d.ts.map +1 -0
  56. package/dist/introspector/scanner/metadata.js +1 -0
  57. package/dist/introspector/scanner/scan.d.ts +17 -0
  58. package/dist/introspector/scanner/scan.d.ts.map +1 -0
  59. package/dist/introspector/scanner/scan.js +158 -0
  60. package/dist/introspector/scanner/serialize.d.ts +34 -0
  61. package/dist/introspector/scanner/serialize.d.ts.map +1 -0
  62. package/dist/introspector/scanner/serialize.js +62 -0
  63. package/dist/introspector/scanner/typeDefs.d.ts +70 -0
  64. package/dist/introspector/scanner/typeDefs.d.ts.map +1 -0
  65. package/dist/introspector/scanner/typeDefs.js +1 -0
  66. package/dist/introspector/scanner/utils.d.ts +62 -0
  67. package/dist/introspector/scanner/utils.d.ts.map +1 -0
  68. package/dist/introspector/scanner/utils.js +124 -0
  69. package/dist/introspector/utils/files.d.ts +5 -0
  70. package/dist/introspector/utils/files.d.ts.map +1 -0
  71. package/dist/introspector/utils/files.js +28 -0
  72. package/dist/provisioning/bin.d.ts +5 -3
  73. package/dist/provisioning/bin.d.ts.map +1 -1
  74. package/dist/provisioning/bin.js +185 -233
  75. package/dist/provisioning/default.d.ts +1 -1
  76. package/dist/provisioning/default.js +1 -1
  77. package/dist/provisioning/engineconn.d.ts +6 -2
  78. package/dist/provisioning/engineconn.d.ts.map +1 -1
  79. package/package.json +3 -3
@@ -0,0 +1,125 @@
1
+ import { UnknownDaggerError } from "../../common/errors/UnknownDaggerError.js";
2
+ /**
3
+ * Registry stores class and method that have the @object decorator.
4
+ *
5
+ * This is a convenient way to make possible the invocation of class' function.
6
+ *
7
+ * The decorator @object store the class into the Registry, but also all the
8
+ * users method's name.
9
+ * It doesn't consider the `@func` or `field` decorators because this is
10
+ * used by the Dagger API to know what to expose or not.
11
+ * This might lead to unnecessary data register into the registry, but
12
+ * we use map as datastructure to optimize the searching process
13
+ * since we directly look through a key into the `class_` member of
14
+ * RegistryClass.
15
+ */
16
+ export class Registry {
17
+ classes = {};
18
+ /**
19
+ * The definition of the @object decorator that should be on top of any
20
+ * class module that must be exposed to the Dagger API.
21
+ *
22
+ */
23
+ object = (constructor) => {
24
+ const methods = [];
25
+ // Create a dummy instance of the constructor to loop through its properties
26
+ // We only register user's method and ignore Typescript default method
27
+ let proto = new constructor();
28
+ while (proto && proto !== Object.prototype) {
29
+ const ownMethods = Object.getOwnPropertyNames(proto).filter((name) => {
30
+ const descriptor = Object.getOwnPropertyDescriptor(proto, name);
31
+ // Check if the descriptor exist, then if it's a function and finally
32
+ // if the function is owned by the class.
33
+ return (descriptor &&
34
+ typeof descriptor.value === "function" &&
35
+ Object.prototype.hasOwnProperty.call(proto, name));
36
+ });
37
+ methods.push(...ownMethods);
38
+ proto = Object.getPrototypeOf(proto);
39
+ }
40
+ // Add this to the registry
41
+ this.classes[constructor.name] = { class_: constructor, methods };
42
+ return constructor;
43
+ };
44
+ /**
45
+ * The definition of @field decorator that should be on top of any
46
+ * class' property that must be exposed to the Dagger API.
47
+ */
48
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
49
+ field = (target, propertyKey) => {
50
+ // A placeholder to declare fields
51
+ };
52
+ /**
53
+ * The definition of @func decorator that should be on top of any
54
+ * class' method that must be exposed to the Dagger API.
55
+ */
56
+ func = (
57
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
58
+ target,
59
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
60
+ propertyKey,
61
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
62
+ descriptor) => {
63
+ // The logic is done in the object constructor since it's not possible to
64
+ // access the class parent's name from a method constructor without calling
65
+ // the method itself
66
+ };
67
+ /**
68
+ * getResult check for the object and method in the registry and call it
69
+ * with the given input and state.
70
+ *
71
+ * This is the function responsible for any module methods execution.
72
+ *
73
+ * @param object The class to look for
74
+ * @param method The method to call in the class
75
+ * @param state The current state of the class
76
+ * @param inputs The input to send to the method to call
77
+ */
78
+ async getResult(object, method, state, inputs
79
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
+ ) {
81
+ // Retrieve the resolver class from its key
82
+ const resolver = this.classes[object];
83
+ if (!resolver) {
84
+ throw new UnknownDaggerError(`${object} is not register as a resolver`, {});
85
+ }
86
+ // If method is nil, apply the constructor.
87
+ if (method === "") {
88
+ return new resolver.class_(...this.getArgOrder(resolver.class_).map((arg) => inputs[arg]));
89
+ }
90
+ // Safety check to make sure the method called exist in the class
91
+ // to avoid the app to crash brutally.
92
+ if (!resolver.methods.find((m) => m === method)) {
93
+ throw new UnknownDaggerError(`${method} is not registered in the resolver ${object}`, {});
94
+ }
95
+ // Instantiate the class
96
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
97
+ let r = new resolver.class_();
98
+ // Apply state to the class
99
+ r = Object.assign(r, state);
100
+ // Order argument following the arg order and picking argument from the inputs map
101
+ const args = this.getArgOrder(r[method]).map((arg) => inputs[arg]);
102
+ // Execute and return the result
103
+ return await r[method](...args);
104
+ }
105
+ /**
106
+ * Get the order of argument by reading its content and create an array of its argument
107
+ * We cannot use r[method].prototype because it can be empty depending on the loading.
108
+ * Note(TomChv): This is a workaround until we find something more accurate.
109
+ * @param fct
110
+ * @private
111
+ */
112
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
113
+ getArgOrder(fct) {
114
+ const fnStr = fct
115
+ .toString()
116
+ .replace(/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm, "");
117
+ return (fnStr
118
+ .slice(fnStr.indexOf("(") + 1, fnStr.indexOf(")"))
119
+ .match(/\b(\w+)\b(?:(?=\s*[:=?]|,\s*|$))/g) ?? []);
120
+ }
121
+ }
122
+ /**
123
+ * The default registry used in any module.
124
+ */
125
+ export const registry = new Registry();
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Metadata of a variable (called symbol in the Typescript compiler)
3
+ */
4
+ export type SymbolMetadata = {
5
+ name: string;
6
+ description: string;
7
+ typeName: string;
8
+ };
9
+ /**
10
+ * Metadata of a function or method parameter.
11
+ */
12
+ export type ParamMetadata = SymbolMetadata & {
13
+ optional: boolean;
14
+ defaultValue?: string;
15
+ };
16
+ /**
17
+ * Metadata of a function's signature.
18
+ */
19
+ export type SignatureMetadata = {
20
+ params: ParamMetadata[];
21
+ returnType: string;
22
+ };
23
+ //# sourceMappingURL=metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/metadata.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,cAAc,GAAG;IAC3C,QAAQ,EAAE,OAAO,CAAA;IACjB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,aAAa,EAAE,CAAA;IACvB,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { ClassTypeDef, FunctionTypedef } from "./typeDefs.js";
2
+ export type ScanResult = {
3
+ classes: ClassTypeDef[];
4
+ functions: FunctionTypedef[];
5
+ };
6
+ /**
7
+ * Scan the list of Typescript File using the Typescript compiler API.
8
+ *
9
+ * This function introspect files and returns metadata of their class and
10
+ * functions that should be exposed to the Dagger API.
11
+ *
12
+ * WARNING(28/11/23): This does NOT include arrow style function.
13
+ *
14
+ * @param files List of Typescript files to introspect.
15
+ */
16
+ export declare function scan(files: string[]): ScanResult;
17
+ //# sourceMappingURL=scan.d.ts.map
@@ -0,0 +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;AAStB,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,YAAY,EAAE,CAAA;IACvB,SAAS,EAAE,eAAe,EAAE,CAAA;CAC7B,CAAA;AAED;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,UAAU,CA6BhD"}
@@ -0,0 +1,158 @@
1
+ import ts from "typescript";
2
+ import { UnknownDaggerError } from "../../common/errors/UnknownDaggerError.js";
3
+ import { serializeSignature, serializeSymbol } from "./serialize.js";
4
+ import { isFunction, isObject, isOptional, isPublicProperty, typeNameToTypedef, } from "./utils.js";
5
+ /**
6
+ * Scan the list of Typescript File using the Typescript compiler API.
7
+ *
8
+ * This function introspect files and returns metadata of their class and
9
+ * functions that should be exposed to the Dagger API.
10
+ *
11
+ * WARNING(28/11/23): This does NOT include arrow style function.
12
+ *
13
+ * @param files List of Typescript files to introspect.
14
+ */
15
+ export function scan(files) {
16
+ if (files.length === 0) {
17
+ throw new UnknownDaggerError("no files to introspect found", {});
18
+ }
19
+ // Interpret the given typescript source files.
20
+ const program = ts.createProgram(files, { experimentalDecorators: true });
21
+ const checker = program.getTypeChecker();
22
+ const metadata = {
23
+ classes: [],
24
+ functions: [],
25
+ };
26
+ for (const file of program.getSourceFiles()) {
27
+ // Ignore type declaration files.
28
+ if (file.isDeclarationFile) {
29
+ continue;
30
+ }
31
+ ts.forEachChild(file, (node) => {
32
+ // Handle class
33
+ if (ts.isClassDeclaration(node) && isObject(node)) {
34
+ metadata.classes.push(introspectClass(checker, node));
35
+ }
36
+ });
37
+ }
38
+ return metadata;
39
+ }
40
+ /**
41
+ * Introspect a class and return its metadata.
42
+ *
43
+ * This function goes throw all class' method that have the @fct decorator
44
+ * and all its public properties.
45
+ *
46
+ * This function throws an error if it cannot read its symbol.
47
+ *
48
+ * @param checker The typescript compiler checker.
49
+ * @param node The class to check.
50
+ */
51
+ function introspectClass(checker, node) {
52
+ // Throw error if node.name is undefined because we cannot scan its symbol.
53
+ if (!node.name) {
54
+ throw new UnknownDaggerError(`could not introspect class: ${node}`, {});
55
+ }
56
+ // Retrieve class symbol.
57
+ const classSymbol = checker.getSymbolAtLocation(node.name);
58
+ if (!classSymbol) {
59
+ throw new UnknownDaggerError(`could not get class symbol: ${node.name.getText()}`, {});
60
+ }
61
+ // Serialize class symbol to extract name and doc.
62
+ const { name, description } = serializeSymbol(checker, classSymbol);
63
+ // Create metadata object.
64
+ const metadata = {
65
+ name,
66
+ description,
67
+ constructor: undefined,
68
+ fields: [],
69
+ methods: [],
70
+ };
71
+ // Loop through all members in the class to get their metadata.
72
+ node.members.forEach((member) => {
73
+ // Handle constructor
74
+ if (ts.isConstructorDeclaration(member)) {
75
+ metadata.constructor = introspectConstructor(checker, member);
76
+ }
77
+ // Handle method from the class.
78
+ if (ts.isMethodDeclaration(member) && isFunction(member)) {
79
+ metadata.methods.push(introspectMethod(checker, member));
80
+ }
81
+ // Handle public properties from the class.
82
+ if (ts.isPropertyDeclaration(member) && isPublicProperty(member)) {
83
+ // Handle properties
84
+ metadata.fields.push(introspectProperty(checker, member));
85
+ }
86
+ });
87
+ return metadata;
88
+ }
89
+ /**
90
+ * Introspect a property from a class and return its metadata.
91
+ *
92
+ * This function throws an error if it cannot retrieve the property symbols.
93
+ *
94
+ * @param checker The typescript compiler checker.
95
+ * @param property The method to check.
96
+ */
97
+ function introspectProperty(checker, property) {
98
+ const propertySymbol = checker.getSymbolAtLocation(property.name);
99
+ if (!propertySymbol) {
100
+ throw new UnknownDaggerError(`could not get property symbol: ${property.name.getText()}`, {});
101
+ }
102
+ const { name, typeName, description } = serializeSymbol(checker, propertySymbol);
103
+ return { name, description, typeDef: typeNameToTypedef(typeName) };
104
+ }
105
+ /**
106
+ * Introspect the constructor of the class and return its metadata.
107
+ */
108
+ function introspectConstructor(checker, constructor) {
109
+ const args = constructor.parameters.map((param) => {
110
+ const paramSymbol = checker.getSymbolAtLocation(param.name);
111
+ if (!paramSymbol) {
112
+ throw new UnknownDaggerError(`could not get constructor param: ${param.name.getText()}`, {});
113
+ }
114
+ const { name, typeName, description } = serializeSymbol(checker, paramSymbol);
115
+ const { optional, defaultValue } = isOptional(paramSymbol);
116
+ return {
117
+ name,
118
+ description,
119
+ typeDef: typeNameToTypedef(typeName),
120
+ optional,
121
+ defaultValue,
122
+ };
123
+ });
124
+ return { args };
125
+ }
126
+ /**
127
+ * Introspect a method from a class and return its metadata.
128
+ *
129
+ * This function first retrieve the symbol of the function signature and then
130
+ * loop on its parameters to get their metadata.
131
+ *
132
+ * This function throws an error if it cannot retrieve the method symbols.
133
+ *
134
+ * @param checker The typescript compiler checker.
135
+ * @param method The method to check.
136
+ */
137
+ function introspectMethod(checker, method) {
138
+ const methodSymbol = checker.getSymbolAtLocation(method.name);
139
+ if (!methodSymbol) {
140
+ throw new UnknownDaggerError(`could not get method symbol: ${method.name.getText()}`, {});
141
+ }
142
+ const methodMetadata = serializeSymbol(checker, methodSymbol);
143
+ const methodSignature = methodMetadata.type
144
+ .getCallSignatures()
145
+ .map((methodSignature) => serializeSignature(checker, methodSignature))[0];
146
+ return {
147
+ name: methodMetadata.name,
148
+ description: methodMetadata.description,
149
+ args: methodSignature.params.map(({ name, typeName, description, optional, defaultValue }) => ({
150
+ name,
151
+ typeDef: typeNameToTypedef(typeName),
152
+ description,
153
+ optional,
154
+ defaultValue,
155
+ })),
156
+ returnType: typeNameToTypedef(methodSignature.returnType),
157
+ };
158
+ }
@@ -0,0 +1,34 @@
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
+ /**
27
+ * Convert the Typescript type from the compiler API into a readable textual
28
+ * type.
29
+ *
30
+ * @param checker The typescript compiler checker.
31
+ * @param type The type to convert.
32
+ */
33
+ export declare function serializeType(checker: ts.TypeChecker, type: ts.Type): string;
34
+ //# sourceMappingURL=serialize.d.ts.map
@@ -0,0 +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,CAanB;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"}
@@ -0,0 +1,62 @@
1
+ import ts from "typescript";
2
+ import { UnknownDaggerError } from "../../common/errors/UnknownDaggerError.js";
3
+ import { isOptional } 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
+ const { optional, defaultValue } = isOptional(param);
16
+ return {
17
+ ...serializeSymbol(checker, param),
18
+ optional,
19
+ defaultValue,
20
+ };
21
+ }),
22
+ returnType: serializeType(checker, signature.getReturnType()),
23
+ };
24
+ }
25
+ /**
26
+ * Convert the Typescript symbol from the compiler API into a lighter data type.
27
+ *
28
+ * This function returns the name of the symbol, with its typename and its
29
+ * documentation.
30
+ * This function also returns the actual Typescript type for additional
31
+ * introspection.
32
+ *
33
+ * @param checker The typescript compiler checker.
34
+ * @param symbol The type to convert.
35
+ */
36
+ export function serializeSymbol(checker, symbol) {
37
+ if (!symbol.valueDeclaration) {
38
+ throw new UnknownDaggerError("could not find symbol value declaration", {});
39
+ }
40
+ const type = checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration);
41
+ return {
42
+ name: symbol.getName(),
43
+ description: ts.displayPartsToString(symbol.getDocumentationComment(checker)),
44
+ typeName: serializeType(checker, type),
45
+ type,
46
+ };
47
+ }
48
+ /**
49
+ * Convert the Typescript type from the compiler API into a readable textual
50
+ * type.
51
+ *
52
+ * @param checker The typescript compiler checker.
53
+ * @param type The type to convert.
54
+ */
55
+ export function serializeType(checker, type) {
56
+ const strType = checker.typeToString(type);
57
+ // Remove Promise<> wrapper around type if it's a promise.
58
+ if (strType.startsWith("Promise")) {
59
+ return strType.substring("Promise<".length, strType.length - 1);
60
+ }
61
+ return strType;
62
+ }
@@ -0,0 +1,70 @@
1
+ import { TypeDefKind } from "../../api/client.gen.js";
2
+ /**
3
+ * Base type of argument, field or return type.
4
+ */
5
+ export type BaseTypeDef = {
6
+ kind: TypeDefKind;
7
+ };
8
+ /**
9
+ * Extends the base type def if it's an object to add its name.
10
+ */
11
+ export type ObjectTypeDef = BaseTypeDef & {
12
+ kind: TypeDefKind.Objectkind;
13
+ name: string;
14
+ };
15
+ /**
16
+ * Extends the base if it's a list to add its subtype.
17
+ */
18
+ export type ListTypeDef = BaseTypeDef & {
19
+ kind: TypeDefKind.Listkind;
20
+ typeDef: TypeDef<TypeDefKind>;
21
+ };
22
+ /**
23
+ * A generic TypeDef that will dynamically add necessary properties
24
+ * depending on its type.
25
+ *
26
+ * If it's type of kind list, it transforms the BaseTypeDef into an ObjectTypeDef.
27
+ * If it's a type of kind list, it transforms the BaseTypeDef into a ListTypeDef.
28
+ */
29
+ export type TypeDef<T extends BaseTypeDef["kind"]> = T extends TypeDefKind.Objectkind ? ObjectTypeDef : T extends TypeDefKind.Listkind ? ListTypeDef : BaseTypeDef;
30
+ /**
31
+ * The type of field in a class
32
+ */
33
+ export type FieldTypeDef = {
34
+ name: string;
35
+ description: string;
36
+ typeDef: TypeDef<TypeDefKind>;
37
+ };
38
+ /**
39
+ * The type of function argument in a method or function.
40
+ */
41
+ export type FunctionArg = {
42
+ name: string;
43
+ description: string;
44
+ optional: boolean;
45
+ defaultValue?: string;
46
+ typeDef: TypeDef<TypeDefKind>;
47
+ };
48
+ /**
49
+ * The type of function, it can be a method from a class or an actual function.
50
+ */
51
+ export type FunctionTypedef = {
52
+ name: string;
53
+ description: string;
54
+ args: FunctionArg[];
55
+ returnType: TypeDef<TypeDefKind>;
56
+ };
57
+ export type ConstructorTypeDef = {
58
+ args: FunctionArg[];
59
+ };
60
+ /**
61
+ * A type of Class.
62
+ */
63
+ export type ClassTypeDef = {
64
+ name: string;
65
+ description: string;
66
+ fields: FieldTypeDef[];
67
+ constructor?: ConstructorTypeDef;
68
+ methods: FunctionTypedef[];
69
+ };
70
+ //# sourceMappingURL=typeDefs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeDefs.d.ts","sourceRoot":"","sources":["../../../introspector/scanner/typeDefs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAErD;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,WAAW,CAAA;CAClB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG;IACxC,IAAI,EAAE,WAAW,CAAC,UAAU,CAAA;IAC5B,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACtC,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;CAC9B,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,IAC/C,CAAC,SAAS,WAAW,CAAC,UAAU,GAC5B,aAAa,GACb,CAAC,SAAS,WAAW,CAAC,QAAQ,GAC9B,WAAW,GACX,WAAW,CAAA;AAEjB;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;CAC9B,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,OAAO,CAAA;IACjB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;CAC9B,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,WAAW,EAAE,CAAA;IACnB,UAAU,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;CACjC,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,WAAW,EAAE,CAAA;CACpB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,YAAY,EAAE,CAAA;IACtB,WAAW,CAAC,EAAE,kBAAkB,CAAA;IAChC,OAAO,EAAE,eAAe,EAAE,CAAA;CAC3B,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,62 @@
1
+ import ts from "typescript";
2
+ import { TypeDefKind } from "../../api/client.gen.js";
3
+ import { TypeDef } from "./typeDefs.js";
4
+ /**
5
+ * Return true if the given class declaration has the decorator @obj on
6
+ * top of its declaration.
7
+ * @param object
8
+ */
9
+ export declare function isObject(object: ts.ClassDeclaration): boolean;
10
+ /**
11
+ * Return true if the given method has the decorator @fct on top
12
+ * of its declaration.
13
+ *
14
+ * @param method The method to check
15
+ */
16
+ export declare function isFunction(method: ts.MethodDeclaration): boolean;
17
+ /**
18
+ * Return true if the given property is public.
19
+ *
20
+ * This function actually in work the reverse, it checks if the property
21
+ * isn't private nor protected.
22
+ *
23
+ * It returns true if the property has no modifiers since no keyword
24
+ * has been set on the property.
25
+ *
26
+ * Example
27
+ * ```
28
+ * class Human {
29
+ * private age = 22 // Return false
30
+ * protected familyName = "Doe" // Return false
31
+ *
32
+ * @field
33
+ * name = "John" // Return true
34
+ *
35
+ * city = "Paris" // Return false because there's no decorator
36
+ * }
37
+ * ```
38
+ *
39
+ * @param property The property to check on.
40
+ */
41
+ export declare function isPublicProperty(property: ts.PropertyDeclaration): boolean;
42
+ type OptionalValue = {
43
+ optional: boolean;
44
+ defaultValue?: string;
45
+ };
46
+ /**
47
+ * Return true if the parameter is optional.
48
+ *
49
+ * This includes both optional value defines with `?` and value that
50
+ * have a default value.
51
+ *
52
+ * If there's a default value, its expression is returned in the result.
53
+ *
54
+ * @param param The param to check.
55
+ */
56
+ export declare function isOptional(param: ts.Symbol): OptionalValue;
57
+ /**
58
+ * Convert a typename into a Dagger Typedef using dynamic typing.
59
+ */
60
+ export declare function typeNameToTypedef(typeName: string): TypeDef<TypeDefKind>;
61
+ export {};
62
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +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,CAM7D;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,iBAAiB,GAAG,OAAO,CAKhE;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,EAAE,CAAC,mBAAmB,GAAG,OAAO,CAsB1E;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,CAwB1D;AAaD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAyBxE"}