@dagger.io/dagger 0.13.5 → 0.13.7

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.
@@ -1,5 +1,7 @@
1
+ import Module from "node:module";
1
2
  import { TypeDefKind } from "../api/client.gen.js";
2
- import { Args, Registry } from "../introspector/registry/registry.js";
3
+ import { Executor } from "../introspector/executor/executor.js";
4
+ import { Args } from "../introspector/executor/executor.js";
3
5
  import { Constructor } from "../introspector/scanner/abtractions/constructor.js";
4
6
  import { DaggerEnum } from "../introspector/scanner/abtractions/enum.js";
5
7
  import { Method } from "../introspector/scanner/abtractions/method.js";
@@ -13,7 +15,7 @@ import { InvokeCtx } from "./context.js";
13
15
  *
14
16
  * @param files List of files to load.
15
17
  */
16
- export declare function load(files: string[]): Promise<void>;
18
+ export declare function load(files: string[]): Promise<Module[]>;
17
19
  /**
18
20
  * Return the object invoked from the module.
19
21
  *
@@ -28,20 +30,20 @@ export declare function loadInvokedMethod(object: DaggerObject, ctx: InvokeCtx):
28
30
  * @param method Method to load the arguments from.
29
31
  * @param ctx The context of the invocation.
30
32
  */
31
- export declare function loadArgs(registry: Registry, method: Method | Constructor, ctx: InvokeCtx): Promise<Args>;
33
+ export declare function loadArgs(executor: Executor, method: Method | Constructor, ctx: InvokeCtx): Promise<Args>;
32
34
  /**
33
35
  * Load the state of the parent object from the context.
34
36
  *
35
37
  * @param object The object to load the parent state from.
36
38
  * @param ctx The context of the invocation.
37
39
  */
38
- export declare function loadParentState(registry: Registry, object: DaggerObject, ctx: InvokeCtx): Promise<Args>;
40
+ export declare function loadParentState(executor: Executor, object: DaggerObject, ctx: InvokeCtx): Promise<Args>;
39
41
  /**
40
42
  * This function load the value as a Dagger type.
41
43
  *
42
44
  * Note: The JSON.parse() is required to remove extra quotes
43
45
  */
44
- export declare function loadValue(registry: Registry, value: any, type: TypeDef<TypeDefKind>): Promise<any>;
46
+ export declare function loadValue(executor: Executor, value: any, type: TypeDef<TypeDefKind>): Promise<any>;
45
47
  /**
46
48
  * Load the object type from the return type of the method.
47
49
  * This covers the case where the return type is an other object of the module.
@@ -1 +1 @@
1
- {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../entrypoint/load.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAA;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,oDAAoD,CAAA;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,6CAA6C,CAAA;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,+CAA+C,CAAA;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,+CAA+C,CAAA;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,+CAA+C,CAAA;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,MAAM,GACjB,YAAY,CAEd;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,SAAS,GACb,CAAC,MAAM,GAAG,WAAW,CAAC,GAAG,SAAS,CAMpC;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,CAC5B,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,GAAG,WAAW,EAC5B,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,IAAI,CAAC,CAyCf;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,SAAS,GAC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,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,MAAM,GACjB,YAAY,CAEd;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,SAAS,GACb,CAAC,MAAM,GAAG,WAAW,CAAC,GAAG,SAAS,CAMpC;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,CAC5B,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,GAAG,WAAW,EAC5B,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,IAAI,CAAC,CAyCf;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,IAAI,CAAC,CAaf;AAED;;;;GAIG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,GAAG,EACV,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,GACzB,OAAO,CAAC,GAAG,CAAC,CA4Cd;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,GACb,YAAY,GAAG,UAAU,CAqB3B;AAED,wBAAsB,UAAU,CAC9B,MAAM,EAAE,GAAG,EACX,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,YAAY,GAAG,UAAU,GAChC,OAAO,CAAC,GAAG,CAAC,CA0Ed"}
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
1
  import { dag, TypeDefKind } from "../api/client.gen.js";
3
2
  import { DaggerEnum } from "../introspector/scanner/abtractions/enum.js";
4
3
  import { DaggerObject } from "../introspector/scanner/abtractions/object.js";
@@ -9,7 +8,7 @@ import { DaggerObject } from "../introspector/scanner/abtractions/object.js";
9
8
  * @param files List of files to load.
10
9
  */
11
10
  export async function load(files) {
12
- await Promise.all(files.map(async (f) => await import(f)));
11
+ return await Promise.all(files.map(async (f) => await import(f)));
13
12
  }
14
13
  /**
15
14
  * Return the object invoked from the module.
@@ -32,7 +31,7 @@ export function loadInvokedMethod(object, ctx) {
32
31
  * @param method Method to load the arguments from.
33
32
  * @param ctx The context of the invocation.
34
33
  */
35
- export async function loadArgs(registry, method, ctx) {
34
+ export async function loadArgs(executor, method, ctx) {
36
35
  const args = {};
37
36
  // Load arguments
38
37
  for (const argName of method.getArgOrder()) {
@@ -40,7 +39,7 @@ export async function loadArgs(registry, method, ctx) {
40
39
  if (!argument) {
41
40
  throw new Error(`could not find argument ${argName}`);
42
41
  }
43
- const loadedArg = await loadValue(registry, ctx.fnArgs[argName], argument.type);
42
+ const loadedArg = await loadValue(executor, ctx.fnArgs[argName], argument.type);
44
43
  // If the argument is variadic, we need to load each args independently
45
44
  // so it's correctly propagated when it's sent to the function.
46
45
  // Note: variadic args are always last in the list of args.
@@ -67,14 +66,14 @@ export async function loadArgs(registry, method, ctx) {
67
66
  * @param object The object to load the parent state from.
68
67
  * @param ctx The context of the invocation.
69
68
  */
70
- export async function loadParentState(registry, object, ctx) {
69
+ export async function loadParentState(executor, object, ctx) {
71
70
  const parentState = {};
72
71
  for (const [key, value] of Object.entries(ctx.parentArgs)) {
73
72
  const property = object.properties[key];
74
73
  if (!property) {
75
74
  throw new Error(`could not find parent property ${key}`);
76
75
  }
77
- parentState[property.name] = await loadValue(registry, value, property.type);
76
+ parentState[property.name] = await loadValue(executor, value, property.type);
78
77
  }
79
78
  return parentState;
80
79
  }
@@ -83,14 +82,14 @@ export async function loadParentState(registry, object, ctx) {
83
82
  *
84
83
  * Note: The JSON.parse() is required to remove extra quotes
85
84
  */
86
- export async function loadValue(registry, value, type) {
85
+ export async function loadValue(executor, value, type) {
87
86
  // If value is undefinied, return it directly.
88
87
  if (value === undefined) {
89
88
  return value;
90
89
  }
91
90
  switch (type.kind) {
92
91
  case TypeDefKind.ListKind:
93
- return Promise.all(value.map(async (v) => await loadValue(registry, v, type.typeDef)));
92
+ return Promise.all(value.map(async (v) => await loadValue(executor, v, type.typeDef)));
94
93
  case TypeDefKind.ObjectKind: {
95
94
  const objectType = type.name;
96
95
  // Workaround to call get any object that has an id
@@ -102,7 +101,7 @@ export async function loadValue(registry, value, type) {
102
101
  return dag[`load${objectType}FromID`](value);
103
102
  }
104
103
  // TODO(supports subfields serialization)
105
- return registry.buildClass(objectType, value);
104
+ return executor.buildClass(objectType, value);
106
105
  }
107
106
  // Cannot use `,` to specify multiple matching case so instead we use fallthrough.
108
107
  case TypeDefKind.StringKind:
@@ -0,0 +1,13 @@
1
+ import Module from "node:module";
2
+ export type State = {
3
+ [property: string]: any;
4
+ };
5
+ export type Args = Record<string, unknown>;
6
+ export declare class Executor {
7
+ readonly modules: Module[];
8
+ constructor(modules: Module[]);
9
+ private getObject;
10
+ buildClass(object: string, state: State): any;
11
+ getResult(object: string, method: string, state: State, inputs: Args): Promise<any>;
12
+ }
13
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../introspector/executor/executor.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,aAAa,CAAA;AAIhC,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;aACS,OAAO,EAAE,MAAM,EAAE;gBAAjB,OAAO,EAAE,MAAM,EAAE;IAE7C,OAAO,CAAC,SAAS;IAUjB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,GAAG;IASvC,SAAS,CACb,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,IAAI,GACX,OAAO,CAAC,GAAG,CAAC;CAchB"}
@@ -0,0 +1,32 @@
1
+ import { FunctionNotFound } from "../../common/errors/FunctionNotFound.js";
2
+ export class Executor {
3
+ modules;
4
+ constructor(modules) {
5
+ this.modules = modules;
6
+ }
7
+ getObject(object) {
8
+ const key = object;
9
+ const module = this.modules.find((m) => m[key] !== undefined);
10
+ if (!module) {
11
+ throw new FunctionNotFound(`Object ${object} not found`);
12
+ }
13
+ return module[key];
14
+ }
15
+ buildClass(object, state) {
16
+ const obj = this.getObject(object);
17
+ const instanciatedClass = Object.create(obj.prototype);
18
+ Object.assign(instanciatedClass, state);
19
+ return instanciatedClass;
20
+ }
21
+ async getResult(object, method, state, inputs) {
22
+ const obj = this.getObject(object);
23
+ if (method === "") {
24
+ return new obj(...Object.values(inputs));
25
+ }
26
+ const builtObj = this.buildClass(object, state);
27
+ if (!builtObj[method]) {
28
+ throw new FunctionNotFound(`Method ${method} not found`);
29
+ }
30
+ return await builtObj[method](...Object.values(inputs));
31
+ }
32
+ }
@@ -1,2 +1,2 @@
1
- export declare const CLI_VERSION = "0.13.5";
1
+ export declare const CLI_VERSION = "0.13.7";
2
2
  //# sourceMappingURL=default.d.ts.map
@@ -1,2 +1,2 @@
1
1
  // Code generated by dagger. DO NOT EDIT.
2
- export const CLI_VERSION = "0.13.5";
2
+ export const CLI_VERSION = "0.13.7";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dagger.io/dagger",
3
- "version": "0.13.5",
3
+ "version": "0.13.7",
4
4
  "author": "hello@dagger.io",
5
5
  "license": "Apache-2.0",
6
6
  "types": "./dist/index.d.ts",