@dagger.io/dagger 0.9.6 → 0.9.8

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.
@@ -5,6 +5,7 @@ export declare const log: (stack?: string) => {
5
5
  noColor: boolean;
6
6
  setLevel(level: "error" | "debug" | "info" | "warn" | "disable" | "success"): void;
7
7
  createNamedLogger(name: string): any;
8
+ setLogStream(stream: Stream): any;
8
9
  setLevelNoColor(): void;
9
10
  setLevelColor(): void;
10
11
  isLevelValid(level: "error" | "debug" | "info" | "warn" | "disable" | "success"): boolean;
@@ -18,6 +19,8 @@ export declare const log: (stack?: string) => {
18
19
  strikethrough?: boolean | undefined;
19
20
  }): string;
20
21
  joint(): any;
22
+ append(...args: any[]): any;
23
+ reset(): any;
21
24
  setDate(callback: Function): void;
22
25
  getDate(): string;
23
26
  color(ticket: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white"): any;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../common/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,GAAG,WAAY,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACe,CAAA"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../common/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,GAAG,WAAY,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACe,CAAA"}
@@ -1,2 +1,2 @@
1
- export {};
1
+ export declare function entrypoint(): Promise<void>;
2
2
  //# sourceMappingURL=entrypoint.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"entrypoint.d.ts","sourceRoot":"","sources":["../../entrypoint/entrypoint.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"entrypoint.d.ts","sourceRoot":"","sources":["../../entrypoint/entrypoint.ts"],"names":[],"mappings":"AAiBA,wBAAsB,UAAU,kBAyD/B"}
@@ -2,17 +2,19 @@ import * as path from "path";
2
2
  import { fileURLToPath } from "url";
3
3
  import { dag } from "../api/client.gen.js";
4
4
  import { connection } from "../connect.js";
5
+ import { scan } from "../introspector/scanner/scan.js";
5
6
  import { listFiles } from "../introspector/utils/files.js";
6
7
  import { invoke } from "./invoke.js";
7
- import { load, loadArg } from "./load.js";
8
+ import { load } from "./load.js";
8
9
  import { register } from "./register.js";
9
10
  const __filename = fileURLToPath(import.meta.url);
10
11
  const __dirname = path.dirname(__filename);
11
12
  const moduleSrcDirectory = `${__dirname}/../../src/`;
12
- async function entrypoint() {
13
+ export async function entrypoint() {
13
14
  // Pre list all files of the modules since we need it either for a registration
14
15
  // or an invocation
15
16
  const files = await listFiles(moduleSrcDirectory);
17
+ const scanResult = await scan(files);
16
18
  // Start a Dagger session to get the call context
17
19
  await connection(async () => {
18
20
  const fnCall = dag.currentFunctionCall();
@@ -23,7 +25,7 @@ async function entrypoint() {
23
25
  if (parentName === "") {
24
26
  // It's a registration, we register the module and assign the module id
25
27
  // to the result
26
- result = await register(files);
28
+ result = await register(files, scanResult);
27
29
  }
28
30
  else {
29
31
  // Invocation
@@ -31,30 +33,17 @@ async function entrypoint() {
31
33
  const parentJson = JSON.parse(await fnCall.parent());
32
34
  const fnArgs = await fnCall.inputArgs();
33
35
  const args = {};
34
- const parentArgs = {};
36
+ const parentArgs = parentJson ?? {};
35
37
  for (const arg of fnArgs) {
36
- args[await arg.name()] = await loadArg(await arg.value());
37
- }
38
- if (parentJson) {
39
- for (const [key, value] of Object.entries(parentJson)) {
40
- parentArgs[key] = await loadArg(value);
41
- }
38
+ args[await arg.name()] = JSON.parse(await arg.value());
42
39
  }
43
40
  await load(files);
44
- result = await invoke(parentName, fnName, parentArgs, args);
45
- // Load ID if it's a Dagger type with an id
46
- if (typeof result?.id === "function") {
47
- result = await result.id();
48
- }
49
- // Load its field ID if there are
50
- if (typeof result === "object") {
51
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
- for (const [key, value] of Object.entries(result)) {
53
- if (value.id && typeof value.id === "function") {
54
- result[key] = await value.id();
55
- }
56
- }
57
- }
41
+ result = await invoke(scanResult, {
42
+ parentName,
43
+ fnName,
44
+ parentArgs,
45
+ fnArgs: args,
46
+ });
58
47
  }
59
48
  // If result is set, we stringify it
60
49
  if (result !== undefined && result !== null) {
@@ -67,4 +56,3 @@ async function entrypoint() {
67
56
  await fnCall.returnValue(result);
68
57
  }, { LogOutput: process.stdout });
69
58
  }
70
- entrypoint();
@@ -1,11 +1,19 @@
1
- import { Args, State } from "../introspector/registry/registry.js";
1
+ import { Args } from "../introspector/registry/registry.js";
2
+ import { ScanResult } from "../introspector/scanner/scan.js";
3
+ export type InvokeCtx = {
4
+ parentName: string;
5
+ fnName: string;
6
+ parentArgs: Args;
7
+ fnArgs: Args;
8
+ };
2
9
  /**
3
10
  * A wrapper around the registry to invoke a function.
4
11
  *
5
- * @param objectName The class to look for
6
- * @param methodName The method to call in the class
7
- * @param state The current state of the class
8
- * @param inputs The input to send to the method to call
12
+ * @param scanResult The result of the scan.
13
+ * @param parentName The name of the parent object.
14
+ * @param fnName The name of the function to call.
15
+ * @param parentArgs The arguments of the parent object.
16
+ * @param fnArgs The arguments of the function to call.
9
17
  */
10
- export declare function invoke(objectName: string, methodName: string, state: State, inputs: Args): Promise<any>;
18
+ export declare function invoke(scanResult: ScanResult, { parentName, fnName, parentArgs, fnArgs }: InvokeCtx): Promise<any>;
11
19
  //# sourceMappingURL=invoke.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"invoke.d.ts","sourceRoot":"","sources":["../../entrypoint/invoke.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAY,KAAK,EAAE,MAAM,sCAAsC,CAAA;AAE5E;;;;;;;GAOG;AACH,wBAAsB,MAAM,CAC1B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,IAAI,GAEX,OAAO,CAAC,GAAG,CAAC,CAEd"}
1
+ {"version":3,"file":"invoke.d.ts","sourceRoot":"","sources":["../../entrypoint/invoke.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAY,MAAM,sCAAsC,CAAA;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;AAS5D,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,IAAI,CAAA;IAChB,MAAM,EAAE,IAAI,CAAA;CACb,CAAA;AAED;;;;;;;;GAQG;AACH,wBAAsB,MAAM,CAC1B,UAAU,EAAE,UAAU,EACtB,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,SAAS,GAEvD,OAAO,CAAC,GAAG,CAAC,CAyBX"}
@@ -1,14 +1,27 @@
1
1
  import { registry } from "../introspector/registry/registry.js";
2
+ import { loadArgOrder, loadArg, loadArgType, loadPropertyType, loadResult, } from "./load.js";
2
3
  /**
3
4
  * A wrapper around the registry to invoke a function.
4
5
  *
5
- * @param objectName The class to look for
6
- * @param methodName The method to call in the class
7
- * @param state The current state of the class
8
- * @param inputs The input to send to the method to call
6
+ * @param scanResult The result of the scan.
7
+ * @param parentName The name of the parent object.
8
+ * @param fnName The name of the function to call.
9
+ * @param parentArgs The arguments of the parent object.
10
+ * @param fnArgs The arguments of the function to call.
9
11
  */
10
- export async function invoke(objectName, methodName, state, inputs
11
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
- ) {
13
- return await registry.getResult(objectName, methodName, state, inputs);
12
+ export async function invoke(scanResult, { parentName, fnName, parentArgs, fnArgs }) {
13
+ const args = {};
14
+ // Load function arguments in the right order
15
+ for (const argName of loadArgOrder(scanResult, parentName, fnName)) {
16
+ args[argName] = await loadArg(fnArgs[argName], loadArgType(scanResult, parentName, fnName, argName));
17
+ }
18
+ // Load parent state
19
+ for (const [key, value] of Object.entries(parentArgs)) {
20
+ parentArgs[key] = await loadArg(value, loadPropertyType(scanResult, parentName, key));
21
+ }
22
+ let result = await registry.getResult(parentName, fnName, parentArgs, args);
23
+ if (result) {
24
+ result = await loadResult(result);
25
+ }
26
+ return result;
14
27
  }
@@ -1,3 +1,6 @@
1
+ import { TypeDefKind } from "../api/client.gen.js";
2
+ import { ScanResult } from "../introspector/scanner/scan.js";
3
+ import { TypeDef } from "../introspector/scanner/typeDefs.js";
1
4
  /**
2
5
  * Import all given typescript files so that trigger their decorators
3
6
  * and register their class and functions inside the Registry.
@@ -6,11 +9,45 @@
6
9
  */
7
10
  export declare function load(files: string[]): Promise<void>;
8
11
  /**
9
- * Load argument as Dagger type.
12
+ * Load the order of arguments for a given function from the scan result.
10
13
  *
11
- * This function remove the quote from the identifier and checks
12
- * if it's a Dagger type, if it is, it loads it according to
13
- * its type.
14
+ * @param scanResult The result of the scan.
15
+ * @param parentName The name of the class.
16
+ * @param fnName The name of the function.
17
+ *
18
+ * @returns An array of strings representing the order of arguments.
19
+ */
20
+ export declare function loadArgOrder(scanResult: ScanResult, parentName: string, fnName: string): string[];
21
+ /**
22
+ * Load the argument type from the scan result.
23
+ *
24
+ * @param scanResult Result of the scan
25
+ * @param parentName Class called
26
+ * @param fnName Function called
27
+ * @param argName Argument name
28
+ * @returns The type of the argument
29
+ */
30
+ export declare function loadArgType(scanResult: ScanResult, parentName: string, fnName: string, argName: string): TypeDef<TypeDefKind>;
31
+ /**
32
+ * Load the property type from the scan result.
33
+ *
34
+ * @param scanResult Result of the scan
35
+ * @param parentName Class called
36
+ * @param propertyName property of the class
37
+ * @returns the type of the property
38
+ */
39
+ export declare function loadPropertyType(scanResult: ScanResult, parentName: string, propertyName: string): TypeDef<TypeDefKind>;
40
+ /**
41
+ * This function load the argument as a Dagger type.
42
+ *
43
+ * Note: The JSON.parse() is required to remove extra quotes
44
+ */
45
+ export declare function loadArg(value: any, type: TypeDef<TypeDefKind>): Promise<any>;
46
+ /**
47
+ * Load subfields of the result and IDable object.
48
+ *
49
+ * @param result The result of the invocation.
50
+ * @returns Loaded result.
14
51
  */
15
- export declare function loadArg(value: string): Promise<any>;
52
+ export declare function loadResult(result: any): Promise<any>;
16
53
  //# sourceMappingURL=load.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../entrypoint/load.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzD;AAED;;;;;;GAMG;AAEH,wBAAsB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CA8BzD"}
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,UAAU,EAAE,MAAM,iCAAiC,CAAA;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAA;AAE7D;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzD;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,MAAM,EAAE,CAiBV;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CACzB,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,WAAW,CAAC,CA2BtB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,WAAW,CAAC,CAYtB;AAED;;;;GAIG;AACH,wBAAsB,OAAO,CAC3B,KAAK,EAAE,GAAG,EACV,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,GACzB,OAAO,CAAC,GAAG,CAAC,CAsCd;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAY1D"}
@@ -1,4 +1,5 @@
1
- import { dag } from "../api/client.gen.js";
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { dag, TypeDefKind } from "../api/client.gen.js";
2
3
  /**
3
4
  * Import all given typescript files so that trigger their decorators
4
5
  * and register their class and functions inside the Registry.
@@ -9,36 +10,130 @@ export async function load(files) {
9
10
  await Promise.all(files.map(async (f) => await import(f)));
10
11
  }
11
12
  /**
12
- * Load argument as Dagger type.
13
+ * Load the order of arguments for a given function from the scan result.
13
14
  *
14
- * This function remove the quote from the identifier and checks
15
- * if it's a Dagger type, if it is, it loads it according to
16
- * its type.
15
+ * @param scanResult The result of the scan.
16
+ * @param parentName The name of the class.
17
+ * @param fnName The name of the function.
18
+ *
19
+ * @returns An array of strings representing the order of arguments.
20
+ */
21
+ export function loadArgOrder(scanResult, parentName, fnName) {
22
+ const classTypeDef = scanResult.classes[parentName];
23
+ if (!classTypeDef) {
24
+ throw new Error(`could not find class ${parentName}`);
25
+ }
26
+ // Call for the constructor
27
+ if (fnName === "") {
28
+ return Object.keys(classTypeDef.constructor?.args ?? {});
29
+ }
30
+ const methodTypeDef = classTypeDef.methods[fnName];
31
+ if (!methodTypeDef) {
32
+ throw new Error(`could not find method ${fnName}`);
33
+ }
34
+ return Object.keys(methodTypeDef.args);
35
+ }
36
+ /**
37
+ * Load the argument type from the scan result.
38
+ *
39
+ * @param scanResult Result of the scan
40
+ * @param parentName Class called
41
+ * @param fnName Function called
42
+ * @param argName Argument name
43
+ * @returns The type of the argument
17
44
  */
18
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
- export async function loadArg(value) {
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
- let parsedValue;
22
- const isString = () => (value.startsWith('"') && value.endsWith('"')) ||
23
- (value.startsWith(`'`) && value.endsWith(`'`));
24
- const isArray = () => value.startsWith("[") && value.endsWith("]");
25
- // Apply JSON parse to parse array or string if the value is wrapped into a string or array
26
- if (isString() || isArray()) {
27
- parsedValue = JSON.parse(value);
28
- }
29
- else {
30
- parsedValue = value;
31
- }
32
- // If it's a string, it might contain an identifier to load ,or it might be a hidden array
33
- if (typeof parsedValue === "string") {
34
- const [source] = parsedValue.split(":");
35
- const [origin, type] = source.split(".");
36
- if (origin === "core") {
45
+ export function loadArgType(scanResult, parentName, fnName, argName) {
46
+ const classTypeDef = scanResult.classes[parentName];
47
+ if (!classTypeDef) {
48
+ throw new Error(`could not find class ${parentName}`);
49
+ }
50
+ // Call for the constructor
51
+ if (fnName === "") {
52
+ const argTypeDef = classTypeDef.constructor?.args[argName];
53
+ if (!argTypeDef) {
54
+ throw new Error(`could not find argument ${argName} type in constructor`);
55
+ }
56
+ return argTypeDef.typeDef;
57
+ }
58
+ const methodTypeDef = classTypeDef.methods[fnName];
59
+ if (!methodTypeDef) {
60
+ throw new Error(`could not find method ${fnName}`);
61
+ }
62
+ const argTypeDef = methodTypeDef.args[argName];
63
+ if (!argTypeDef) {
64
+ throw new Error(`could not find argument ${argName} type`);
65
+ }
66
+ return argTypeDef.typeDef;
67
+ }
68
+ /**
69
+ * Load the property type from the scan result.
70
+ *
71
+ * @param scanResult Result of the scan
72
+ * @param parentName Class called
73
+ * @param propertyName property of the class
74
+ * @returns the type of the property
75
+ */
76
+ export function loadPropertyType(scanResult, parentName, propertyName) {
77
+ const classTypeDef = scanResult.classes[parentName];
78
+ if (!classTypeDef) {
79
+ throw new Error(`could not find class ${parentName}`);
80
+ }
81
+ const propertyTypeDef = classTypeDef.fields[propertyName];
82
+ if (!propertyTypeDef) {
83
+ throw new Error(`could not find property ${propertyName} type`);
84
+ }
85
+ return propertyTypeDef.typeDef;
86
+ }
87
+ /**
88
+ * This function load the argument as a Dagger type.
89
+ *
90
+ * Note: The JSON.parse() is required to remove extra quotes
91
+ */
92
+ export async function loadArg(value, type) {
93
+ // If value is undefinied, return it directly.
94
+ if (value === undefined) {
95
+ return value;
96
+ }
97
+ switch (type.kind) {
98
+ case TypeDefKind.ListKind:
99
+ return Promise.all(value.map(async (v) => await loadArg(v, type.typeDef)));
100
+ case TypeDefKind.ObjectKind: {
101
+ const objectType = type.name;
37
102
  // Workaround to call get any object that has an id
38
103
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
39
104
  // @ts-ignore
40
- return dag[`load${type}FromID`](parsedValue);
105
+ if (dag[`load${objectType}FromID`]) {
106
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
107
+ // @ts-ignore
108
+ return dag[`load${objectType}FromID`](value);
109
+ }
110
+ // TODO(supports subfields serialization)
111
+ return value;
112
+ }
113
+ // Cannot use , to specify multiple matching case so instead we use fallthrough.
114
+ case TypeDefKind.StringKind:
115
+ case TypeDefKind.IntegerKind:
116
+ case TypeDefKind.BooleanKind:
117
+ case TypeDefKind.VoidKind:
118
+ return value;
119
+ default:
120
+ throw new Error(`unsupported type ${type.kind}`);
121
+ }
122
+ }
123
+ /**
124
+ * Load subfields of the result and IDable object.
125
+ *
126
+ * @param result The result of the invocation.
127
+ * @returns Loaded result.
128
+ */
129
+ export async function loadResult(result) {
130
+ if (result && typeof result?.id === "function") {
131
+ result = await result.id();
132
+ }
133
+ if (typeof result === "object") {
134
+ for (const [key, value] of Object.entries(result)) {
135
+ result[key] = await loadResult(value);
41
136
  }
42
137
  }
43
- return parsedValue;
138
+ return result;
44
139
  }
@@ -1,6 +1,7 @@
1
- import { ModuleID } from "../api/client.gen";
1
+ import { ModuleID } from "../api/client.gen.js";
2
+ import { ScanResult } from "../introspector/scanner/scan.js";
2
3
  /**
3
4
  * Register the module files and returns its ID
4
5
  */
5
- export declare function register(files: string[]): Promise<ModuleID>;
6
+ export declare function register(files: string[], scanResult: ScanResult): Promise<ModuleID>;
6
7
  //# sourceMappingURL=register.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../entrypoint/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,QAAQ,EAGT,MAAM,mBAAmB,CAAA;AAW1B;;GAEG;AACH,wBAAsB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,CAoCjE"}
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../entrypoint/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,QAAQ,EAGT,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;AAU5D;;GAEG;AACH,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,MAAM,EAAE,EACf,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,QAAQ,CAAC,CAqCnB"}
@@ -1,31 +1,30 @@
1
- import { dag, TypeDefKind, } from "../api/client.gen";
2
- import { scan } from "../introspector/scanner/scan.js";
1
+ import { dag, TypeDefKind, } from "../api/client.gen.js";
3
2
  /**
4
3
  * Register the module files and returns its ID
5
4
  */
6
- export async function register(files) {
7
- // Scan all files
8
- const scanResult = await scan(files);
9
- // Get the current module
10
- let mod = dag.currentModule();
5
+ export async function register(files, scanResult) {
6
+ // Get a new module that we will fill in with all the types
7
+ let mod = dag.module_();
11
8
  // For each class scanned, register its type, method and properties in the module.
12
- scanResult.classes.forEach((modClass) => {
9
+ Object.values(scanResult.classes).map((modClass) => {
13
10
  // Register the class Typedef object in Dagger
14
11
  let typeDef = dag.typeDef().withObject(modClass.name, {
15
12
  description: modClass.description,
16
13
  });
17
14
  // Register all functions (methods) to this object
18
- modClass.methods.forEach((method) => {
15
+ Object.values(modClass.methods).forEach((method) => {
19
16
  typeDef = typeDef.withFunction(addFunction(method));
20
17
  });
21
18
  // Register all fields that belong to this object
22
- modClass.fields.forEach((field) => {
23
- typeDef = typeDef.withField(field.name, addTypeDef(field.typeDef), {
24
- description: field.description,
25
- });
19
+ Object.values(modClass.fields).forEach((field) => {
20
+ if (field.isExposed) {
21
+ typeDef = typeDef.withField(field.name, addTypeDef(field.typeDef), {
22
+ description: field.description,
23
+ });
24
+ }
26
25
  });
27
26
  if (modClass.constructor) {
28
- typeDef.withConstructor(addConstructor(modClass.constructor, typeDef));
27
+ typeDef = typeDef.withConstructor(addConstructor(modClass.constructor, typeDef));
29
28
  }
30
29
  // Add it to the module object
31
30
  mod = mod.withObject(typeDef);
@@ -53,7 +52,7 @@ function addFunction(fct) {
53
52
  */
54
53
  function addArg(args) {
55
54
  return function (fct) {
56
- args.forEach((arg) => {
55
+ Object.values(args).forEach((arg) => {
57
56
  const opts = {
58
57
  description: arg.description,
59
58
  };
@@ -81,11 +80,11 @@ function addArg(args) {
81
80
  */
82
81
  function addTypeDef(type) {
83
82
  switch (type.kind) {
84
- case TypeDefKind.Objectkind:
83
+ case TypeDefKind.ObjectKind:
85
84
  return dag.typeDef().withObject(type.name);
86
- case TypeDefKind.Listkind:
85
+ case TypeDefKind.ListKind:
87
86
  return dag.typeDef().withListOf(addTypeDef(type.typeDef));
88
- case TypeDefKind.Voidkind:
87
+ case TypeDefKind.VoidKind:
89
88
  return dag.typeDef().withKind(type.kind).withOptional(true);
90
89
  default:
91
90
  return dag.typeDef().withKind(type.kind);
package/dist/index.d.ts CHANGED
@@ -5,4 +5,5 @@ export { GraphQLClient } from "graphql-request";
5
5
  export { connect, CallbackFct, connection, close } from "./connect.js";
6
6
  export { ConnectOpts } from "./connectOpts.js";
7
7
  export * from "./introspector/decorators/decorators.js";
8
+ export { entrypoint } from "./entrypoint/entrypoint.js";
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,0BAA0B,CAAA;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,cAAc,yCAAyC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,0BAA0B,CAAA;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,cAAc,yCAAyC,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA"}
package/dist/index.js CHANGED
@@ -4,3 +4,4 @@ export { gql } from "graphql-tag";
4
4
  export { GraphQLClient } from "graphql-request";
5
5
  export { connect, connection, close } from "./connect.js";
6
6
  export * from "./introspector/decorators/decorators.js";
7
+ export { entrypoint } from "./entrypoint/entrypoint.js";
@@ -1,3 +1,4 @@
1
+ import "reflect-metadata";
1
2
  export type Class = {
2
3
  new (...args: any[]): any;
3
4
  };
@@ -20,7 +21,6 @@ export type Args = Record<string, unknown>;
20
21
  * RegistryClass.
21
22
  */
22
23
  export declare class Registry {
23
- private classes;
24
24
  /**
25
25
  * The definition of the @object decorator that should be on top of any
26
26
  * class module that must be exposed to the Dagger API.
@@ -49,14 +49,6 @@ export declare class Registry {
49
49
  * @param inputs The input to send to the method to call
50
50
  */
51
51
  getResult(object: string, method: string, state: State, inputs: Args): Promise<any>;
52
- /**
53
- * Get the order of argument by reading its content and create an array of its argument
54
- * We cannot use r[method].prototype because it can be empty depending on the loading.
55
- * Note(TomChv): This is a workaround until we find something more accurate.
56
- * @param fct
57
- * @private
58
- */
59
- private getArgOrder;
60
52
  }
61
53
  /**
62
54
  * The default registry used in any module.
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../introspector/registry/registry.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,KAAK,GAAG;IAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;CAAE,CAAA;AAGjD,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;AAa1C;;;;;;;;;;;;;GAaG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,OAAO,CAAoB;IAEnC;;;;OAIG;IACH,MAAM,yCA4BL;IAED;;;OAGG;IAEH,KAAK,WAAY,MAAM,eAAe,MAAM,UAE3C;IAED;;;OAGG;IACH,IAAI,WAEM,MAAM,eAED,MAAM,GAAG,MAAM,cAEhB,kBAAkB,UAK/B;IAED;;;;;;;;;;OAUG;IACG,SAAS,CACb,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,IAAI,GAEX,OAAO,CAAC,GAAG,CAAC;IAwCf;;;;;;OAMG;IAEH,OAAO,CAAC,WAAW;CAWpB;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,UAAiB,CAAA"}
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../introspector/registry/registry.ts"],"names":[],"mappings":"AAGA,OAAO,kBAAkB,CAAA;AAIzB,MAAM,MAAM,KAAK,GAAG;IAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;CAAE,CAAA;AAEjD,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;AAW1C;;;;;;;;;;;;;GAaG;AACH,qBAAa,QAAQ;IACnB;;;;OAIG;IACH,MAAM,yCA+BL;IAED;;;OAGG;IACH,KAAK,WAAY,MAAM,eAAe,MAAM,UAE3C;IAED;;;OAGG;IACH,IAAI,WACM,MAAM,eACD,MAAM,GAAG,MAAM,cAChB,kBAAkB,UAK/B;IAED;;;;;;;;;;OAUG;IACG,SAAS,CACb,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,IAAI,GACX,OAAO,CAAC,GAAG,CAAC;CAiChB;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,UAAiB,CAAA"}
@@ -1,3 +1,6 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ import "reflect-metadata";
1
4
  import { UnknownDaggerError } from "../../common/errors/UnknownDaggerError.js";
2
5
  /**
3
6
  * Registry stores class and method that have the @object decorator.
@@ -14,7 +17,6 @@ import { UnknownDaggerError } from "../../common/errors/UnknownDaggerError.js";
14
17
  * RegistryClass.
15
18
  */
16
19
  export class Registry {
17
- classes = {};
18
20
  /**
19
21
  * The definition of the @object decorator that should be on top of any
20
22
  * class module that must be exposed to the Dagger API.
@@ -37,15 +39,13 @@ export class Registry {
37
39
  methods.push(...ownMethods);
38
40
  proto = Object.getPrototypeOf(proto);
39
41
  }
40
- // Add this to the registry
41
- this.classes[constructor.name] = { class_: constructor, methods };
42
+ Reflect.defineMetadata(constructor.name, { class_: constructor, methods }, this);
42
43
  return constructor;
43
44
  };
44
45
  /**
45
46
  * The definition of @field decorator that should be on top of any
46
47
  * class' property that must be exposed to the Dagger API.
47
48
  */
48
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
49
49
  field = (target, propertyKey) => {
50
50
  // A placeholder to declare fields
51
51
  };
@@ -53,13 +53,7 @@ export class Registry {
53
53
  * The definition of @func decorator that should be on top of any
54
54
  * class' method that must be exposed to the Dagger API.
55
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) => {
56
+ func = (target, propertyKey, descriptor) => {
63
57
  // The logic is done in the object constructor since it's not possible to
64
58
  // access the class parent's name from a method constructor without calling
65
59
  // the method itself
@@ -75,17 +69,15 @@ export class Registry {
75
69
  * @param state The current state of the class
76
70
  * @param inputs The input to send to the method to call
77
71
  */
78
- async getResult(object, method, state, inputs
79
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
- ) {
72
+ async getResult(object, method, state, inputs) {
81
73
  // Retrieve the resolver class from its key
82
- const resolver = this.classes[object];
74
+ const resolver = Reflect.getMetadata(object, this);
83
75
  if (!resolver) {
84
76
  throw new UnknownDaggerError(`${object} is not register as a resolver`, {});
85
77
  }
86
78
  // If method is nil, apply the constructor.
87
79
  if (method === "") {
88
- return new resolver.class_(...this.getArgOrder(resolver.class_).map((arg) => inputs[arg]));
80
+ return new resolver.class_(...Object.values(inputs));
89
81
  }
90
82
  // Safety check to make sure the method called exist in the class
91
83
  // to avoid the app to crash brutally.
@@ -93,30 +85,11 @@ export class Registry {
93
85
  throw new UnknownDaggerError(`${method} is not registered in the resolver ${object}`, {});
94
86
  }
95
87
  // Instantiate the class
96
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
97
88
  let r = new resolver.class_();
98
89
  // Apply state to the class
99
90
  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
91
  // 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) ?? []);
92
+ return await r[method](...Object.values(inputs));
120
93
  }
121
94
  }
122
95
  /**