@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.
Files changed (213) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +88 -0
  3. package/dist/src/api/client.gen.d.ts +6123 -0
  4. package/dist/src/api/client.gen.d.ts.map +1 -0
  5. package/dist/src/api/client.gen.js +8494 -0
  6. package/dist/src/common/context.d.ts +12 -0
  7. package/dist/src/common/context.d.ts.map +1 -0
  8. package/dist/src/common/context.js +22 -0
  9. package/dist/src/common/errors/DaggerSDKError.d.ts +32 -0
  10. package/dist/src/common/errors/DaggerSDKError.d.ts.map +1 -0
  11. package/dist/src/common/errors/DaggerSDKError.js +26 -0
  12. package/dist/src/common/errors/DockerImageRefValidationError.d.ts +22 -0
  13. package/dist/src/common/errors/DockerImageRefValidationError.d.ts.map +1 -0
  14. package/dist/src/common/errors/DockerImageRefValidationError.js +21 -0
  15. package/dist/src/common/errors/EngineSessionConnectParamsParseError.d.ts +21 -0
  16. package/dist/src/common/errors/EngineSessionConnectParamsParseError.d.ts.map +1 -0
  17. package/dist/src/common/errors/EngineSessionConnectParamsParseError.js +20 -0
  18. package/dist/src/common/errors/EngineSessionConnectionTimeoutError.d.ts +21 -0
  19. package/dist/src/common/errors/EngineSessionConnectionTimeoutError.d.ts.map +1 -0
  20. package/dist/src/common/errors/EngineSessionConnectionTimeoutError.js +20 -0
  21. package/dist/src/common/errors/EngineSessionErrorOptions.d.ts +16 -0
  22. package/dist/src/common/errors/EngineSessionErrorOptions.d.ts.map +1 -0
  23. package/dist/src/common/errors/EngineSessionErrorOptions.js +16 -0
  24. package/dist/src/common/errors/ExecError.d.ts +42 -0
  25. package/dist/src/common/errors/ExecError.d.ts.map +1 -0
  26. package/dist/src/common/errors/ExecError.js +40 -0
  27. package/dist/src/common/errors/FunctionNotFound.d.ts +7 -0
  28. package/dist/src/common/errors/FunctionNotFound.d.ts.map +1 -0
  29. package/dist/src/common/errors/FunctionNotFound.js +9 -0
  30. package/dist/src/common/errors/GraphQLRequestError.d.ts +31 -0
  31. package/dist/src/common/errors/GraphQLRequestError.d.ts.map +1 -0
  32. package/dist/src/common/errors/GraphQLRequestError.js +30 -0
  33. package/dist/src/common/errors/InitEngineSessionBinaryError.d.ts +13 -0
  34. package/dist/src/common/errors/InitEngineSessionBinaryError.d.ts.map +1 -0
  35. package/dist/src/common/errors/InitEngineSessionBinaryError.js +15 -0
  36. package/dist/src/common/errors/IntrospectionError.d.ts +7 -0
  37. package/dist/src/common/errors/IntrospectionError.d.ts.map +1 -0
  38. package/dist/src/common/errors/IntrospectionError.js +9 -0
  39. package/dist/src/common/errors/NotAwaitedRequestError.d.ts +13 -0
  40. package/dist/src/common/errors/NotAwaitedRequestError.d.ts.map +1 -0
  41. package/dist/src/common/errors/NotAwaitedRequestError.js +15 -0
  42. package/dist/src/common/errors/TooManyNestedObjectsError.d.ts +21 -0
  43. package/dist/src/common/errors/TooManyNestedObjectsError.d.ts.map +1 -0
  44. package/dist/src/common/errors/TooManyNestedObjectsError.js +20 -0
  45. package/dist/src/common/errors/UnknownDaggerError.d.ts +13 -0
  46. package/dist/src/common/errors/UnknownDaggerError.d.ts.map +1 -0
  47. package/dist/src/common/errors/UnknownDaggerError.js +15 -0
  48. package/dist/src/common/errors/errors-codes.d.ts +55 -0
  49. package/dist/src/common/errors/errors-codes.d.ts.map +1 -0
  50. package/dist/src/common/errors/errors-codes.js +47 -0
  51. package/dist/src/common/errors/index.d.ts +15 -0
  52. package/dist/src/common/errors/index.d.ts.map +1 -0
  53. package/dist/src/common/errors/index.js +14 -0
  54. package/dist/src/common/graphql/client.d.ts +3 -0
  55. package/dist/src/common/graphql/client.d.ts.map +1 -0
  56. package/dist/src/common/graphql/client.js +58 -0
  57. package/dist/src/common/graphql/compute_query.d.ts +37 -0
  58. package/dist/src/common/graphql/compute_query.d.ts.map +1 -0
  59. package/dist/src/common/graphql/compute_query.js +171 -0
  60. package/dist/src/common/graphql/connect.d.ts +8 -0
  61. package/dist/src/common/graphql/connect.d.ts.map +1 -0
  62. package/dist/src/common/graphql/connect.js +22 -0
  63. package/dist/src/common/graphql/connection.d.ts +14 -0
  64. package/dist/src/common/graphql/connection.d.ts.map +1 -0
  65. package/dist/src/common/graphql/connection.js +23 -0
  66. package/dist/src/common/utils.d.ts +70 -0
  67. package/dist/src/common/utils.d.ts.map +1 -0
  68. package/dist/src/common/utils.js +6 -0
  69. package/dist/src/connect.d.ts +28 -0
  70. package/dist/src/connect.d.ts.map +1 -0
  71. package/dist/src/connect.js +64 -0
  72. package/dist/src/connectOpts.d.ts +24 -0
  73. package/dist/src/connectOpts.d.ts.map +1 -0
  74. package/dist/src/connectOpts.js +1 -0
  75. package/dist/src/index.d.ts +11 -0
  76. package/dist/src/index.d.ts.map +1 -0
  77. package/dist/src/index.js +13 -0
  78. package/dist/src/module/decorators.d.ts +52 -0
  79. package/dist/src/module/decorators.d.ts.map +1 -0
  80. package/dist/src/module/decorators.js +55 -0
  81. package/dist/src/module/entrypoint/context.d.ts +8 -0
  82. package/dist/src/module/entrypoint/context.d.ts.map +1 -0
  83. package/dist/src/module/entrypoint/context.js +1 -0
  84. package/dist/src/module/entrypoint/entrypoint.d.ts +2 -0
  85. package/dist/src/module/entrypoint/entrypoint.d.ts.map +1 -0
  86. package/dist/src/module/entrypoint/entrypoint.js +92 -0
  87. package/dist/src/module/entrypoint/introspection_entrypoint.d.ts +2 -0
  88. package/dist/src/module/entrypoint/introspection_entrypoint.d.ts.map +1 -0
  89. package/dist/src/module/entrypoint/introspection_entrypoint.js +52 -0
  90. package/dist/src/module/entrypoint/invoke.d.ts +14 -0
  91. package/dist/src/module/entrypoint/invoke.d.ts.map +1 -0
  92. package/dist/src/module/entrypoint/invoke.js +66 -0
  93. package/dist/src/module/entrypoint/load.d.ts +53 -0
  94. package/dist/src/module/entrypoint/load.d.ts.map +1 -0
  95. package/dist/src/module/entrypoint/load.js +237 -0
  96. package/dist/src/module/entrypoint/register.d.ts +33 -0
  97. package/dist/src/module/entrypoint/register.d.ts.map +1 -0
  98. package/dist/src/module/entrypoint/register.js +227 -0
  99. package/dist/src/module/executor.d.ts +28 -0
  100. package/dist/src/module/executor.d.ts.map +1 -0
  101. package/dist/src/module/executor.js +171 -0
  102. package/dist/src/module/introspector/case_convertor.d.ts +2 -0
  103. package/dist/src/module/introspector/case_convertor.d.ts.map +1 -0
  104. package/dist/src/module/introspector/case_convertor.js +15 -0
  105. package/dist/src/module/introspector/dagger_module/argument.d.ts +50 -0
  106. package/dist/src/module/introspector/dagger_module/argument.d.ts.map +1 -0
  107. package/dist/src/module/introspector/dagger_module/argument.js +118 -0
  108. package/dist/src/module/introspector/dagger_module/constructor.d.ts +18 -0
  109. package/dist/src/module/introspector/dagger_module/constructor.d.ts.map +1 -0
  110. package/dist/src/module/introspector/dagger_module/constructor.js +38 -0
  111. package/dist/src/module/introspector/dagger_module/decorator.d.ts +8 -0
  112. package/dist/src/module/introspector/dagger_module/decorator.d.ts.map +1 -0
  113. package/dist/src/module/introspector/dagger_module/decorator.js +7 -0
  114. package/dist/src/module/introspector/dagger_module/enum.d.ts +41 -0
  115. package/dist/src/module/introspector/dagger_module/enum.d.ts.map +1 -0
  116. package/dist/src/module/introspector/dagger_module/enum.js +63 -0
  117. package/dist/src/module/introspector/dagger_module/enumBase.d.ts +19 -0
  118. package/dist/src/module/introspector/dagger_module/enumBase.d.ts.map +1 -0
  119. package/dist/src/module/introspector/dagger_module/enumBase.js +1 -0
  120. package/dist/src/module/introspector/dagger_module/enumClass.d.ts +41 -0
  121. package/dist/src/module/introspector/dagger_module/enumClass.d.ts.map +1 -0
  122. package/dist/src/module/introspector/dagger_module/enumClass.js +69 -0
  123. package/dist/src/module/introspector/dagger_module/function.d.ts +39 -0
  124. package/dist/src/module/introspector/dagger_module/function.d.ts.map +1 -0
  125. package/dist/src/module/introspector/dagger_module/function.js +102 -0
  126. package/dist/src/module/introspector/dagger_module/index.d.ts +15 -0
  127. package/dist/src/module/introspector/dagger_module/index.d.ts.map +1 -0
  128. package/dist/src/module/introspector/dagger_module/index.js +14 -0
  129. package/dist/src/module/introspector/dagger_module/interface.d.ts +25 -0
  130. package/dist/src/module/introspector/dagger_module/interface.d.ts.map +1 -0
  131. package/dist/src/module/introspector/dagger_module/interface.js +56 -0
  132. package/dist/src/module/introspector/dagger_module/interfaceFunction.d.ts +35 -0
  133. package/dist/src/module/introspector/dagger_module/interfaceFunction.d.ts.map +1 -0
  134. package/dist/src/module/introspector/dagger_module/interfaceFunction.js +92 -0
  135. package/dist/src/module/introspector/dagger_module/locatable.d.ts +12 -0
  136. package/dist/src/module/introspector/dagger_module/locatable.d.ts.map +1 -0
  137. package/dist/src/module/introspector/dagger_module/locatable.js +14 -0
  138. package/dist/src/module/introspector/dagger_module/module.d.ts +118 -0
  139. package/dist/src/module/introspector/dagger_module/module.d.ts.map +1 -0
  140. package/dist/src/module/introspector/dagger_module/module.js +316 -0
  141. package/dist/src/module/introspector/dagger_module/object.d.ts +46 -0
  142. package/dist/src/module/introspector/dagger_module/object.d.ts.map +1 -0
  143. package/dist/src/module/introspector/dagger_module/object.js +113 -0
  144. package/dist/src/module/introspector/dagger_module/objectBase.d.ts +32 -0
  145. package/dist/src/module/introspector/dagger_module/objectBase.d.ts.map +1 -0
  146. package/dist/src/module/introspector/dagger_module/objectBase.js +1 -0
  147. package/dist/src/module/introspector/dagger_module/property.d.ts +36 -0
  148. package/dist/src/module/introspector/dagger_module/property.d.ts.map +1 -0
  149. package/dist/src/module/introspector/dagger_module/property.js +82 -0
  150. package/dist/src/module/introspector/dagger_module/reference.d.ts +13 -0
  151. package/dist/src/module/introspector/dagger_module/reference.d.ts.map +1 -0
  152. package/dist/src/module/introspector/dagger_module/reference.js +33 -0
  153. package/dist/src/module/introspector/dagger_module/typeObject.d.ts +49 -0
  154. package/dist/src/module/introspector/dagger_module/typeObject.d.ts.map +1 -0
  155. package/dist/src/module/introspector/dagger_module/typeObject.js +87 -0
  156. package/dist/src/module/introspector/dagger_module/typeObjectProperty.d.ts +34 -0
  157. package/dist/src/module/introspector/dagger_module/typeObjectProperty.d.ts.map +1 -0
  158. package/dist/src/module/introspector/dagger_module/typeObjectProperty.js +60 -0
  159. package/dist/src/module/introspector/index.d.ts +3 -0
  160. package/dist/src/module/introspector/index.d.ts.map +1 -0
  161. package/dist/src/module/introspector/index.js +19 -0
  162. package/dist/src/module/introspector/typedef.d.ts +52 -0
  163. package/dist/src/module/introspector/typedef.d.ts.map +1 -0
  164. package/dist/src/module/introspector/typedef.js +1 -0
  165. package/dist/src/module/introspector/typescript_module/ast.d.ts +64 -0
  166. package/dist/src/module/introspector/typescript_module/ast.d.ts.map +1 -0
  167. package/dist/src/module/introspector/typescript_module/ast.js +476 -0
  168. package/dist/src/module/introspector/typescript_module/declarations.d.ts +15 -0
  169. package/dist/src/module/introspector/typescript_module/declarations.d.ts.map +1 -0
  170. package/dist/src/module/introspector/typescript_module/declarations.js +10 -0
  171. package/dist/src/module/introspector/typescript_module/index.d.ts +4 -0
  172. package/dist/src/module/introspector/typescript_module/index.d.ts.map +1 -0
  173. package/dist/src/module/introspector/typescript_module/index.js +3 -0
  174. package/dist/src/module/introspector/typescript_module/location.d.ts +6 -0
  175. package/dist/src/module/introspector/typescript_module/location.d.ts.map +1 -0
  176. package/dist/src/module/introspector/typescript_module/location.js +1 -0
  177. package/dist/src/module/introspector/typescript_module/typedef_utils.d.ts +5 -0
  178. package/dist/src/module/introspector/typescript_module/typedef_utils.d.ts.map +1 -0
  179. package/dist/src/module/introspector/typescript_module/typedef_utils.js +26 -0
  180. package/dist/src/module/introspector/utils/files.d.ts +5 -0
  181. package/dist/src/module/introspector/utils/files.d.ts.map +1 -0
  182. package/dist/src/module/introspector/utils/files.js +28 -0
  183. package/dist/src/module/registry.d.ts +109 -0
  184. package/dist/src/module/registry.d.ts.map +1 -0
  185. package/dist/src/module/registry.js +123 -0
  186. package/dist/src/provisioning/bin.d.ts +77 -0
  187. package/dist/src/provisioning/bin.d.ts.map +1 -0
  188. package/dist/src/provisioning/bin.js +353 -0
  189. package/dist/src/provisioning/default.d.ts +2 -0
  190. package/dist/src/provisioning/default.d.ts.map +1 -0
  191. package/dist/src/provisioning/default.js +2 -0
  192. package/dist/src/provisioning/engineconn.d.ts +30 -0
  193. package/dist/src/provisioning/engineconn.d.ts.map +1 -0
  194. package/dist/src/provisioning/engineconn.js +1 -0
  195. package/dist/src/provisioning/index.d.ts +4 -0
  196. package/dist/src/provisioning/index.d.ts.map +1 -0
  197. package/dist/src/provisioning/index.js +14 -0
  198. package/dist/src/telemetry/index.d.ts +3 -0
  199. package/dist/src/telemetry/index.d.ts.map +1 -0
  200. package/dist/src/telemetry/index.js +2 -0
  201. package/dist/src/telemetry/init.d.ts +21 -0
  202. package/dist/src/telemetry/init.d.ts.map +1 -0
  203. package/dist/src/telemetry/init.js +86 -0
  204. package/dist/src/telemetry/live_processor.d.ts +12 -0
  205. package/dist/src/telemetry/live_processor.d.ts.map +1 -0
  206. package/dist/src/telemetry/live_processor.js +13 -0
  207. package/dist/src/telemetry/telemetry.d.ts +16 -0
  208. package/dist/src/telemetry/telemetry.d.ts.map +1 -0
  209. package/dist/src/telemetry/telemetry.js +38 -0
  210. package/dist/src/telemetry/tracer.d.ts +32 -0
  211. package/dist/src/telemetry/tracer.d.ts.map +1 -0
  212. package/dist/src/telemetry/tracer.js +54 -0
  213. package/package.json +74 -0
@@ -0,0 +1,237 @@
1
+ import { dag, TypeDefKind } from "../../api/client.gen.js";
2
+ import { DaggerEnum, DaggerObject, DaggerTypeObject, DaggerEnumClass, } from "../introspector/dagger_module/index.js";
3
+ /**
4
+ * Import all given typescript files so that trigger their decorators
5
+ * and register their class and functions inside the Registry.
6
+ *
7
+ * @param files List of files to load.
8
+ */
9
+ export async function load(files) {
10
+ return await Promise.all(files.map(async (f) => await import(f)));
11
+ }
12
+ /**
13
+ * Return the object invoked from the module.
14
+ *
15
+ * @param module The module to load the object from.
16
+ * @param parentName The name of the parent object.
17
+ */
18
+ export function loadInvokedObject(module, parentName) {
19
+ return module.objects[parentName];
20
+ }
21
+ export function loadInvokedMethod(object, ctx) {
22
+ if (ctx.fnName === "") {
23
+ return object._constructor;
24
+ }
25
+ return object.methods[ctx.fnName];
26
+ }
27
+ /**
28
+ * Load the values of the arguments from the context.
29
+ *
30
+ * @param method Method to load the arguments from.
31
+ * @param ctx The context of the invocation.
32
+ */
33
+ export async function loadArgs(executor, method, ctx) {
34
+ const args = {};
35
+ // Load arguments
36
+ for (const argName of method.getArgsOrder()) {
37
+ const argument = method.arguments[argName];
38
+ if (!argument) {
39
+ throw new Error(`could not find argument ${argName}`);
40
+ }
41
+ if (!argument.type) {
42
+ throw new Error(`could not find type for argument ${argName}`);
43
+ }
44
+ const loadedArg = await loadValue(executor, ctx.fnArgs[argName], argument.type);
45
+ // If the argument is variadic, we need to load each args independently
46
+ // so it's correctly propagated when it's sent to the function.
47
+ // Note: variadic args are always last in the list of args.
48
+ if (argument.isVariadic) {
49
+ for (const [i, arg] of (loadedArg ?? []).entries()) {
50
+ args[`${argName}${i}`] = arg;
51
+ }
52
+ continue;
53
+ }
54
+ // If the argument is nullable and the loaded arg is undefined with no default value, we set it to null.
55
+ if (argument.isNullable &&
56
+ loadedArg === undefined &&
57
+ !argument.defaultValue) {
58
+ args[argName] = null;
59
+ continue;
60
+ }
61
+ args[argName] = loadedArg;
62
+ }
63
+ return args;
64
+ }
65
+ /**
66
+ * Load the state of the parent object from the context.
67
+ *
68
+ * @param object The object to load the parent state from.
69
+ * @param ctx The context of the invocation.
70
+ */
71
+ export async function loadParentState(executor, object, ctx) {
72
+ const parentState = {};
73
+ for (const [key, value] of Object.entries(ctx.parentArgs)) {
74
+ const property = object.properties[key];
75
+ if (!property) {
76
+ throw new Error(`could not find parent property ${key}`);
77
+ }
78
+ if (!property.type) {
79
+ throw new Error(`could not find type for parent property ${key}`);
80
+ }
81
+ parentState[property.name] = await loadValue(executor, value, property.type);
82
+ }
83
+ return parentState;
84
+ }
85
+ /**
86
+ * This function load the value as a Dagger type.
87
+ *
88
+ * Note: The JSON.parse() is required to remove extra quotes
89
+ */
90
+ export async function loadValue(executor, value, type) {
91
+ // If value is undefinied, return it directly.
92
+ if (value === undefined) {
93
+ return value;
94
+ }
95
+ switch (type.kind) {
96
+ case TypeDefKind.ListKind:
97
+ return Promise.all(value.map(async (v) => await loadValue(executor, v, type.typeDef)));
98
+ case TypeDefKind.ObjectKind: {
99
+ const objectType = type.name;
100
+ // Workaround to call get any object that has an id
101
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
102
+ // @ts-ignore
103
+ if (dag[`load${objectType}FromID`]) {
104
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
105
+ // @ts-ignore
106
+ return dag[`load${objectType}FromID`](value);
107
+ }
108
+ return executor.buildClass(objectType, value);
109
+ }
110
+ case TypeDefKind.InterfaceKind: {
111
+ const interfaceType = type.name;
112
+ return executor.buildInterface(interfaceType, value);
113
+ }
114
+ case TypeDefKind.EnumKind: {
115
+ const enumType = type.name;
116
+ return executor.buildEnum(enumType, value);
117
+ }
118
+ // Cannot use `,` to specify multiple matching case so instead we use fallthrough.
119
+ case TypeDefKind.StringKind:
120
+ case TypeDefKind.IntegerKind:
121
+ case TypeDefKind.BooleanKind:
122
+ case TypeDefKind.FloatKind:
123
+ case TypeDefKind.VoidKind:
124
+ case TypeDefKind.ScalarKind:
125
+ return value;
126
+ default:
127
+ throw new Error(`unsupported type ${type.kind}`);
128
+ }
129
+ }
130
+ /**
131
+ * Load the object type from the return type of the method.
132
+ * This covers the case where the return type is an other object of the module.
133
+ * For example: `msg(): Message` where message is an object of the module.
134
+ *
135
+ * @param module The module to load the object from.
136
+ * @param object The current object to load the return type from.
137
+ * @param method The method to load the return type from.
138
+ */
139
+ export function loadObjectReturnType(module, object, method) {
140
+ const retType = method.returnType;
141
+ if (!retType) {
142
+ throw new Error(`could not find return type for ${method.name}`);
143
+ }
144
+ switch (retType.kind) {
145
+ case TypeDefKind.ListKind: {
146
+ // Loop until we find the original object type.
147
+ // This way we handle the list of list (e.g Object[][][]...[])
148
+ let listType = retType;
149
+ while (listType.kind === TypeDefKind.ListKind) {
150
+ listType = listType.typeDef;
151
+ }
152
+ if (listType.kind === TypeDefKind.EnumKind) {
153
+ return module.enums[listType.name];
154
+ }
155
+ return module.objects[listType.name];
156
+ }
157
+ case TypeDefKind.ObjectKind:
158
+ return module.objects[retType.name];
159
+ case TypeDefKind.EnumKind:
160
+ return module.enums[retType.name];
161
+ default:
162
+ return object;
163
+ }
164
+ }
165
+ export async function loadResult(result, module, object) {
166
+ // Handle IDable objects
167
+ if (result && typeof result?.id === "function") {
168
+ return await result.id();
169
+ }
170
+ // Handle arrays
171
+ if (Array.isArray(result)) {
172
+ result = await Promise.all(result.map(async (r) => await loadResult(r, module, object)));
173
+ return result;
174
+ }
175
+ // Handle objects
176
+ if (typeof result === "object" &&
177
+ (object instanceof DaggerObject || object instanceof DaggerTypeObject)) {
178
+ const state = {};
179
+ for (const [key, value] of Object.entries(result)) {
180
+ const property = Object.values(object.properties).find((p) => p.name === key);
181
+ if (!property) {
182
+ throw new Error(`could not find result property ${key}`);
183
+ }
184
+ if (!property.type) {
185
+ throw new Error(`could not find type for result property ${key}`);
186
+ }
187
+ let referencedObject = undefined;
188
+ // Handle nested objects
189
+ if (property.type.kind === TypeDefKind.ObjectKind) {
190
+ referencedObject =
191
+ module.objects[property.type.name];
192
+ }
193
+ // Handle list of nested objects
194
+ if (property.type.kind === TypeDefKind.ListKind) {
195
+ let _property = property.type;
196
+ // Loop until we find the original type.
197
+ while (_property.kind === TypeDefKind.ListKind) {
198
+ _property = _property.typeDef;
199
+ }
200
+ // If the original type is an object, we use it as the referenced object.
201
+ if (_property.kind === TypeDefKind.ObjectKind) {
202
+ referencedObject =
203
+ module.objects[_property.name];
204
+ }
205
+ // If the original type is a enum, we use it as the referenced object.
206
+ if (_property.kind === TypeDefKind.EnumKind) {
207
+ referencedObject =
208
+ module.enums[_property.name];
209
+ }
210
+ }
211
+ // Handle enums
212
+ if (property.type.kind === TypeDefKind.EnumKind) {
213
+ referencedObject =
214
+ module.enums[property.type.name];
215
+ }
216
+ // If there's no referenced object, we use the current object.
217
+ if (!referencedObject) {
218
+ referencedObject = object;
219
+ }
220
+ state[property.alias ?? property.name] = await loadResult(value, module, referencedObject);
221
+ }
222
+ return state;
223
+ }
224
+ // If it's an enum, we need to resolve the enum member name instead of the value.
225
+ // A enum value A = "a" will be returned as "a" by the function so we need to
226
+ // transform it back to "A" to be sent as result to the engine.
227
+ if (object instanceof DaggerEnum || object instanceof DaggerEnumClass) {
228
+ const enumMember = Object.entries(object.values).find(([, member]) => member.value === result);
229
+ // If the enum member is not found, we return the result as is and let the engine handle it.
230
+ if (!enumMember) {
231
+ return result;
232
+ }
233
+ return enumMember[0];
234
+ }
235
+ // Handle primitive types
236
+ return result;
237
+ }
@@ -0,0 +1,33 @@
1
+ import { Function_, ModuleID, TypeDef } from "../../api/client.gen.js";
2
+ import { DaggerArguments as Arguments, DaggerConstructor as Constructor, DaggerFunction as Method, DaggerModule, DaggerArgument } from "../introspector/dagger_module/index.js";
3
+ import { DaggerInterfaceFunction } from "../introspector/dagger_module/interfaceFunction.js";
4
+ export declare class Register {
5
+ private readonly module;
6
+ constructor(module: DaggerModule);
7
+ /**
8
+ * Register the module in the engine and returns its ID
9
+ */
10
+ run(): Promise<ModuleID>;
11
+ /**
12
+ * Bind a constructor to the given object.
13
+ */
14
+ addConstructor(constructor: Constructor, owner: TypeDef): Function_;
15
+ /**
16
+ * Create a function in the Dagger API.
17
+ */
18
+ addFunction(fct: Method | DaggerInterfaceFunction): Function_;
19
+ /**
20
+ * Register all arguments in the function.
21
+ */
22
+ addArg(args: Arguments): (fct: Function_) => Function_;
23
+ /**
24
+ * Extract the default value from the argument.
25
+ * - If the argument isn't a primitive type, we can't resolve it so we make it optional and let the runtime
26
+ * resolve it on execution.
27
+ * - If the argument is a primitive type but not an enum, we resolve it directly.
28
+ * - If the argument is an enum but not registered in the module, it must be a core enum so we keep the value as is.
29
+ * - If the argument is an enum registered in the module, we resolve the value to the member name.
30
+ */
31
+ getDefaultValueFromArg(arg: DaggerArgument): unknown | undefined;
32
+ }
33
+ //# sourceMappingURL=register.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../src/module/entrypoint/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,EAET,QAAQ,EACR,OAAO,EAQR,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,eAAe,IAAI,SAAS,EAC5B,iBAAiB,IAAI,WAAW,EAChC,cAAc,IAAI,MAAM,EACxB,YAAY,EAEZ,cAAc,EACf,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,oDAAoD,CAAA;AAU5F,qBAAa,QAAQ;IACP,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,YAAY;IAEjD;;OAEG;IACG,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC;IAyF9B;;OAEG;IACH,cAAc,CAAC,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,GAAG,SAAS;IAInE;;OAEG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,uBAAuB,GAAG,SAAS;IAoC7D;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,CAAC,GAAG,EAAE,SAAS,KAAK,SAAS;IAmDtD;;;;;;;OAOG;IACH,sBAAsB,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,GAAG,SAAS;CA4BjE"}
@@ -0,0 +1,227 @@
1
+ import { dag, TypeDefKind, FunctionCachePolicy, } from "../../api/client.gen.js";
2
+ export class Register {
3
+ module;
4
+ constructor(module) {
5
+ this.module = module;
6
+ }
7
+ /**
8
+ * Register the module in the engine and returns its ID
9
+ */
10
+ async run() {
11
+ // Get a new module that we will fill in with all the types
12
+ let mod = dag.module_();
13
+ // Add module description if any.
14
+ if (this.module.description) {
15
+ mod = mod.withDescription(this.module.description);
16
+ }
17
+ // For each class scanned, register its type, method and properties in the module.
18
+ Object.values(this.module.objects).forEach((object) => {
19
+ const objectOpts = {
20
+ description: object.description,
21
+ sourceMap: addSourceMap(object),
22
+ deprecated: object.deprecated,
23
+ };
24
+ // Register the class Typedef object in Dagger
25
+ let typeDef = dag.typeDef().withObject(object.name, objectOpts);
26
+ // Register all functions (methods) to this object
27
+ Object.values(object.methods).forEach((method) => {
28
+ typeDef = typeDef.withFunction(this.addFunction(method));
29
+ });
30
+ // Register all fields that belong to this object
31
+ Object.values(object.properties).forEach((field) => {
32
+ if (field.isExposed) {
33
+ const fieldOpts = {
34
+ description: field.description,
35
+ sourceMap: addSourceMap(field),
36
+ deprecated: field.deprecated,
37
+ };
38
+ typeDef = typeDef.withField(field.alias ?? field.name, addTypeDef(field.type), fieldOpts);
39
+ }
40
+ });
41
+ if (object._constructor) {
42
+ typeDef = typeDef.withConstructor(this.addConstructor(object._constructor, typeDef));
43
+ }
44
+ // Add it to the module object
45
+ mod = mod.withObject(typeDef);
46
+ });
47
+ // Register all enums defined by this modules
48
+ Object.values(this.module.enums).forEach((enum_) => {
49
+ let typeDef = dag.typeDef().withEnum(enum_.name, {
50
+ description: enum_.description,
51
+ sourceMap: addSourceMap(enum_),
52
+ });
53
+ Object.values(enum_.values).forEach((value) => {
54
+ const memberOpts = {
55
+ value: value.value,
56
+ description: value.description,
57
+ sourceMap: addSourceMap(value),
58
+ deprecated: value.deprecated,
59
+ };
60
+ typeDef = typeDef.withEnumMember(value.name, memberOpts);
61
+ });
62
+ mod = mod.withEnum(typeDef);
63
+ });
64
+ // Register all interfaces defined by this module
65
+ Object.values(this.module.interfaces).forEach((interface_) => {
66
+ let typeDef = dag.typeDef().withInterface(interface_.name, {
67
+ description: interface_.description,
68
+ });
69
+ Object.values(interface_.functions).forEach((function_) => {
70
+ typeDef = typeDef.withFunction(this.addFunction(function_));
71
+ });
72
+ mod = mod.withInterface(typeDef);
73
+ });
74
+ return await mod.id();
75
+ }
76
+ /**
77
+ * Bind a constructor to the given object.
78
+ */
79
+ addConstructor(constructor, owner) {
80
+ return dag.function_("", owner).with(this.addArg(constructor.arguments));
81
+ }
82
+ /**
83
+ * Create a function in the Dagger API.
84
+ */
85
+ addFunction(fct) {
86
+ let fnDef = dag
87
+ .function_(fct.alias ?? fct.name, addTypeDef(fct.returnType))
88
+ .withDescription(fct.description)
89
+ .withSourceMap(addSourceMap(fct))
90
+ .with(this.addArg(fct.arguments));
91
+ switch (fct.cache) {
92
+ case "never": {
93
+ fnDef = fnDef.withCachePolicy(FunctionCachePolicy.Never);
94
+ break;
95
+ }
96
+ case "session": {
97
+ fnDef = fnDef.withCachePolicy(FunctionCachePolicy.PerSession);
98
+ break;
99
+ }
100
+ case "": {
101
+ break;
102
+ }
103
+ default: {
104
+ const opts = { timeToLive: fct.cache };
105
+ fnDef = fnDef.withCachePolicy(FunctionCachePolicy.Default, opts);
106
+ }
107
+ }
108
+ if (fct.deprecated !== undefined) {
109
+ fnDef = fnDef.withDeprecated({ reason: fct.deprecated });
110
+ }
111
+ if (fct.isCheck) {
112
+ fnDef = fnDef.withCheck();
113
+ }
114
+ return fnDef;
115
+ }
116
+ /**
117
+ * Register all arguments in the function.
118
+ */
119
+ addArg(args) {
120
+ return (fct) => {
121
+ Object.values(args).forEach((arg) => {
122
+ const opts = {
123
+ description: arg.description,
124
+ sourceMap: addSourceMap(arg),
125
+ deprecated: arg.deprecated,
126
+ };
127
+ let typeDef = addTypeDef(arg.type);
128
+ if (arg.isOptional) {
129
+ typeDef = typeDef.withOptional(true);
130
+ }
131
+ // Check if both values are used, return an error if so.
132
+ if ([arg.defaultValue, arg.defaultPath].filter((v) => v).length > 1) {
133
+ throw new Error("cannot set multiple defaults");
134
+ }
135
+ // We do not set the default value if it's not a primitive type, we let TypeScript
136
+ // resolve the default value during the runtime instead.
137
+ // If it has a default value but is not primitive, we set the value as optional
138
+ // to workaround the fact that the API isn't aware of the default value and will
139
+ // expect it to be set as required input.
140
+ if (arg.defaultValue !== undefined) {
141
+ const defaultValue = this.getDefaultValueFromArg(arg);
142
+ if (defaultValue === undefined) {
143
+ typeDef = typeDef.withOptional(true);
144
+ }
145
+ else {
146
+ opts.defaultValue = JSON.stringify(defaultValue);
147
+ }
148
+ }
149
+ // If the argument is a contextual argument, it becomes optional.
150
+ if (arg.defaultPath) {
151
+ opts.defaultPath = arg.defaultPath;
152
+ }
153
+ if (arg.ignore) {
154
+ opts.ignore = arg.ignore;
155
+ }
156
+ fct = fct.withArg(arg.name, typeDef, opts);
157
+ });
158
+ return fct;
159
+ };
160
+ }
161
+ /**
162
+ * Extract the default value from the argument.
163
+ * - If the argument isn't a primitive type, we can't resolve it so we make it optional and let the runtime
164
+ * resolve it on execution.
165
+ * - If the argument is a primitive type but not an enum, we resolve it directly.
166
+ * - If the argument is an enum but not registered in the module, it must be a core enum so we keep the value as is.
167
+ * - If the argument is an enum registered in the module, we resolve the value to the member name.
168
+ */
169
+ getDefaultValueFromArg(arg) {
170
+ if (!isPrimitiveType(arg.type)) {
171
+ return undefined;
172
+ }
173
+ if (arg.type.kind !== TypeDefKind.EnumKind) {
174
+ return arg.defaultValue;
175
+ }
176
+ const enumObj = this.module.enums[arg.type.name];
177
+ if (!enumObj) {
178
+ // If the enum isn't found in the module, it may be a core enum so we keep the value
179
+ return arg.defaultValue;
180
+ }
181
+ // If it's a known enum, we need to resolve set the name of the member as default value instead of the actual value
182
+ const enumMember = Object.entries(enumObj.values).find(([, member]) => member.value === arg.defaultValue);
183
+ if (!enumMember) {
184
+ throw new Error(`could not resolve default value '${arg.defaultValue}' for enum ${arg.type.name}`);
185
+ }
186
+ return enumMember[0];
187
+ }
188
+ }
189
+ /**
190
+ * Wrapper around TypeDef to return the right Dagger TypesDef with its options.
191
+ *
192
+ * This function only convert the Typedef into correct dagger call
193
+ * but, it's up to function above with more context to add documentation,
194
+ * define if it's an optional value or its default's.
195
+ *
196
+ * We cannot do it there because the Typedef can come from any source:
197
+ * a field, a param, a return value etc...
198
+ */
199
+ function addTypeDef(type) {
200
+ switch (type.kind) {
201
+ case TypeDefKind.ScalarKind:
202
+ return dag.typeDef().withScalar(type.name);
203
+ case TypeDefKind.ObjectKind:
204
+ return dag.typeDef().withObject(type.name);
205
+ case TypeDefKind.ListKind:
206
+ return dag.typeDef().withListOf(addTypeDef(type.typeDef));
207
+ case TypeDefKind.VoidKind:
208
+ return dag.typeDef().withKind(type.kind).withOptional(true);
209
+ case TypeDefKind.EnumKind:
210
+ return dag.typeDef().withEnum(type.name);
211
+ case TypeDefKind.InterfaceKind:
212
+ return dag.typeDef().withInterface(type.name);
213
+ default:
214
+ return dag.typeDef().withKind(type.kind);
215
+ }
216
+ }
217
+ function addSourceMap(object) {
218
+ const { filepath, line, column } = object.getLocation();
219
+ return dag.sourceMap(filepath, line, column);
220
+ }
221
+ function isPrimitiveType(type) {
222
+ return (type.kind === TypeDefKind.BooleanKind ||
223
+ type.kind === TypeDefKind.IntegerKind ||
224
+ type.kind === TypeDefKind.StringKind ||
225
+ type.kind === TypeDefKind.FloatKind ||
226
+ type.kind === TypeDefKind.EnumKind);
227
+ }
@@ -0,0 +1,28 @@
1
+ import Module from "node:module";
2
+ import { DaggerModule } from "./introspector/dagger_module/index.js";
3
+ export type State = {
4
+ [property: string]: any;
5
+ };
6
+ export type Args = Record<string, unknown>;
7
+ export declare class Executor {
8
+ readonly modules: Module[];
9
+ private readonly daggerModule;
10
+ constructor(modules: Module[], daggerModule: DaggerModule);
11
+ private getExportedObject;
12
+ buildClass(object: string, state: State): any;
13
+ /**
14
+ * Transform a Dagger interface identifier into an implementation of this
15
+ * interface serves as module call binding to reach the true implementation.
16
+ */
17
+ buildInterface(iface: string, id: string): any;
18
+ /**
19
+ * Transfer a Dagger enum member name into its implemented value.
20
+ * An enum value A = "a" will be received as "A" by the entrypoint
21
+ * but should be transformed into "a" to be sent to the function.
22
+ * If the enum isn't found in the module, it may be a core enum so we keep the value
23
+ * as is.
24
+ */
25
+ buildEnum(enumName: string, value: string): any;
26
+ getResult(object: string, method: string, state: State, inputs: Args): Promise<any>;
27
+ }
28
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/module/executor.ts"],"names":[],"mappings":"AAEA,OAAO,MAAM,MAAM,aAAa,CAAA;AAMhC,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAA;AAIpE,MAAM,MAAM,KAAK,GAAG;IAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAAA;AAE/C,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAE1C,qBAAa,QAAQ;aAED,OAAO,EAAE,MAAM,EAAE;IACjC,OAAO,CAAC,QAAQ,CAAC,YAAY;gBADb,OAAO,EAAE,MAAM,EAAE,EAChB,YAAY,EAAE,YAAY;IAG7C,OAAO,CAAC,iBAAiB;IAUzB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,GAAG;IAqB7C;;;OAGG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,GAAG;IAiB9C;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG;IAazC,SAAS,CACb,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,IAAI,GACX,OAAO,CAAC,GAAG,CAAC;CAchB"}