@layerzerolabs/dfs 0.0.17 → 0.0.19

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.
@@ -10,9 +10,9 @@
10
10
  CLI Cleaning output folder
11
11
  CJS Build start
12
12
  ESM Build start
13
- CJS dist/index.cjs 1.40 KB
14
- CJS dist/index.cjs.map 5.35 KB
15
- CJS ⚡️ Build success in 81ms
16
- ESM dist/index.js 1.38 KB
17
- ESM dist/index.js.map 5.35 KB
18
- ESM ⚡️ Build success in 81ms
13
+ CJS dist/index.cjs 1.38 KB
14
+ CJS dist/index.cjs.map 5.33 KB
15
+ CJS ⚡️ Build success in 120ms
16
+ ESM dist/index.js 1.36 KB
17
+ ESM dist/index.js.map 5.32 KB
18
+ ESM ⚡️ Build success in 120ms
@@ -5,11 +5,11 @@
5
5
 
6
6
   RUN  v3.2.3 /home/runner/work/monorepo-internal/monorepo-internal/packages/dfs
7
7
 
8
- ✓ test/dfs.test.ts (3 tests) 311ms
9
- ✓ DI Depth-first-search > The handlers for each of a node's dependencies should be completed before that node  306ms
8
+ ✓ test/dfs.test.ts (3 tests) 310ms
9
+ ✓ DI Depth-first-search > The handlers for each of a node's dependencies should be completed before that node  304ms
10
10
 
11
11
   Test Files  1 passed (1)
12
12
   Tests  3 passed (3)
13
-  Start at  17:27:09
14
-  Duration  1.18s (transform 119ms, setup 0ms, collect 76ms, tests 311ms, environment 0ms, prepare 415ms)
13
+  Start at  23:51:51
14
+  Duration  1.19s (transform 136ms, setup 0ms, collect 81ms, tests 310ms, environment 0ms, prepare 358ms)
15
15
 
package/dist/index.cjs CHANGED
@@ -36,10 +36,9 @@ var dfs = /* @__PURE__ */ __name((node, handler, prehandler = (node2) => node2,
36
36
  resolver();
37
37
  return _returns;
38
38
  } catch (error) {
39
- throw new Error(`Failed at ${_backtrack.map((n) => n.name).join("/")}.
40
- ${error?.message}`, {
41
- cause: error
42
- });
39
+ console.error(`Failed at ${_backtrack.map((n) => n.name).join("/")}
40
+ ${error?.message}`);
41
+ throw error;
43
42
  }
44
43
  };
45
44
  }, "dfs");
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["dfs","node","handler","prehandler","_visited","Map","_returns","_backtrack","_node","has","name","get","resolver","set","Promise","res","resolverFunctions","dependencies","nextBacktrack","_","dependencyValue","Object","entries","push","all","map","f","regRes","key","value","error","Error","n","join","message","cause"],"mappings":";;;;;;AA8BO,IAAMA,sBAAM,MAAA,CAAA,CACfC,IAAAA,EACAC,OAAAA,EACAC,UAAAA,GAAqC,CAACF,KAAAA,KAASA,KAAAA,EAC/CG,QAAAA,mBAAuC,IAAIC,KAAAA,EAC3CC,QAAAA,GAAwB,EAAC,EACzBC,UAAAA,GAA6D,EAAA,KAAE;AAE/D,EAAA,MAAMC,KAAAA,GAAQL,WAAWF,IAAAA,CAAAA;AACzB,EAAA,IAAIG,QAAAA,CAASK,GAAAA,CAAID,KAAAA,CAAME,IAAI,CAAA,EAAG;AAC1B,IAAA,OAAO,YAAA;AACH,MAAA,MAAMN,QAAAA,CAASO,GAAAA,CAAIH,KAAAA,CAAME,IAAI,CAAA;AAC7B,MAAA,OAAOJ,QAAAA;AACX,IAAA,CAAA;AACJ,EAAA;AACA,EAAA,IAAIM,QAAAA;AAEJR,EAAAA,QAAAA,CAASS,IACLL,KAAAA,CAAME,IAAAA,EACN,IAAII,OAAAA,CAAc,CAACC,GAAAA,KAAAA;AACfH,IAAAA,QAAAA,GAAWG,GAAAA;AACf,EAAA,CAAA,CAAA,CAAA;AAIJ,EAAA,MAAMC,oBAA4C,EAAA;AAClD,EAAA,IAAIR,MAAMS,YAAAA,EAAc;AACpB,IAAA,MAAMC,aAAAA,GAAgB;AAAIX,MAAAA,GAAAA,UAAAA;AAAYC,MAAAA;;AACtC,IAAA,KAAA,MAAW,CAACW,GAAGC,eAAAA,CAAAA,IAAoBC,OAAOC,OAAAA,CAAQd,KAAAA,CAAMS,YAAY,CAAA,EAAG;AACnED,MAAAA,iBAAAA,CAAkBO,IAAAA,CACdvB,IAAIoB,eAAAA,EAAiBlB,OAAAA,EAASC,YAAYC,QAAAA,EAAUE,QAAAA,EAAUY,aAAAA,CAAAA,CAAAA;AAEtE,IAAA;AACJ,EAAA;AAEA,EAAA,OAAO,YAAA;AACH,IAAA,IAAI;AACA,MAAA,MAAMJ,OAAAA,CAAQU,IAAIR,iBAAAA,CAAkBS,GAAAA,CAAI,CAACC,CAAAA,KAAMA,CAAAA,EAAAA,CAAAA,CAAAA;AAC/C,MAAA,MAAMC,MAAAA,GAAS,MAAMzB,OAAAA,CAAQM,KAAAA,CAAAA;AAC7B,MAAA,IAAImB,MAAAA,EAAQ;AACP,QAAA,CAACrB,QAAAA,CAAiBqB,OAAOC,GAAG,CAAA,KAAM,EAAC,EAAGpB,KAAAA,CAAME,IAAI,CAAA,GAAIiB,MAAAA,CAAOE,KAAAA;AAChE,MAAA;AACAjB,MAAAA,QAAAA,EAAAA;AACA,MAAA,OAAON,QAAAA;AACX,IAAA,CAAA,CAAA,OAASwB,KAAAA,EAAY;AACjB,MAAA,MAAM,IAAIC,KAAAA,CACN,CAAA,UAAA,EAAaxB,UAAAA,CAAWkB,GAAAA,CAAI,CAACO,CAAAA,KAAMA,CAAAA,CAAEtB,IAAI,CAAA,CAAEuB,IAAAA,CAAK,GAAA,CAAA,CAAA;AAAUH,EAAAA,KAAAA,EAAOI,OAAAA,CAAAA,CAAAA,EACjE;QAAEC,KAAAA,EAAOL;OAAM,CAAA;AAEvB,IAAA;AACJ,EAAA,CAAA;AACJ,CAAA,EAnDmB,KAAA","file":"index.cjs","sourcesContent":["import type { Dependencies, DependencyNode } from '@layerzerolabs/dependency-graph';\n\n/**\n * A registrar is a simple interface for an object that provides the ability to traverse the dependency graph.\n * It is implicit in this definition that the registrar should also *register* values adhering to the schemata\n * of the graph.\n */\nexport interface Registrar<ReturnType> {\n traverseDependencies: (rootNode: DependencyNode<any, any>) => Promise<ReturnType>;\n}\nexport type NodeHandlerFunction = (\n node: DependencyNode<any, Dependencies>,\n) => Promise<{ key: string; value: any }>;\nexport type NodePreHandlerFunction = (\n node: DependencyNode<any, Dependencies>,\n) => DependencyNode<any, Dependencies>;\n\n/**\n * Performs a depth-first-search on a tree of dependency nodes, and returns a function\n * that will call the handler for each node in the tree, ordered s.t. the handler of N\n * will be called only after the handlers of dependencies(N) have been called.\n * The resolver function will only call the handler once for each unique definition node.\n * The resolver function returns an object whose keys are the keys defined\n * by each of the handlers, and whose values are objects whose keys are the names\n * of the nodes resolved and whose values are the values defined by the handlers.\n * @param node the root node of the tree\n * @param handler a function that accepts a node and registers it\n * @param prehandler a function that accepts a node and returns a node. will be use to pre-process the graph\n * @returns a resolver function\n */\nexport const dfs = <DependencyName extends string, ReturnTypes>(\n node: DependencyNode<DependencyName, Dependencies>,\n handler: NodeHandlerFunction,\n prehandler: NodePreHandlerFunction = (node) => node,\n _visited: Map<string, Promise<void>> = new Map(),\n _returns: ReturnTypes = {} as any,\n _backtrack: DependencyNode<DependencyName, Dependencies>[] = [],\n): (() => Promise<ReturnTypes>) => {\n const _node = prehandler(node);\n if (_visited.has(_node.name)) {\n return async () => {\n await _visited.get(_node.name);\n return _returns;\n };\n }\n let resolver: (value: void | PromiseLike<void>) => void;\n\n _visited.set(\n _node.name,\n new Promise<void>((res) => {\n resolver = res;\n }),\n );\n\n // Resolve dependencies first\n const resolverFunctions: (() => Promise<any>)[] = [];\n if (_node.dependencies) {\n const nextBacktrack = [..._backtrack, _node];\n for (const [_, dependencyValue] of Object.entries(_node.dependencies)) {\n resolverFunctions.push(\n dfs(dependencyValue, handler, prehandler, _visited, _returns, nextBacktrack),\n );\n }\n }\n\n return async () => {\n try {\n await Promise.all(resolverFunctions.map((f) => f()));\n const regRes = await handler(_node);\n if (regRes) {\n ((_returns as any)[regRes.key] ??= {})[_node.name] = regRes.value;\n }\n resolver();\n return _returns;\n } catch (error: any) {\n throw new Error(\n `Failed at ${_backtrack.map((n) => n.name).join('/')}.\\n${error?.message}`,\n { cause: error },\n );\n }\n };\n};\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["dfs","node","handler","prehandler","_visited","Map","_returns","_backtrack","_node","has","name","get","resolver","set","Promise","res","resolverFunctions","dependencies","nextBacktrack","_","dependencyValue","Object","entries","push","all","map","f","regRes","key","value","error","console","n","join","message"],"mappings":";;;;;;AA8BO,IAAMA,sBAAM,MAAA,CAAA,CACfC,IAAAA,EACAC,OAAAA,EACAC,UAAAA,GAAqC,CAACF,KAAAA,KAASA,KAAAA,EAC/CG,QAAAA,mBAAuC,IAAIC,KAAAA,EAC3CC,QAAAA,GAAwB,EAAC,EACzBC,UAAAA,GAA6D,EAAA,KAAE;AAE/D,EAAA,MAAMC,KAAAA,GAAQL,WAAWF,IAAAA,CAAAA;AACzB,EAAA,IAAIG,QAAAA,CAASK,GAAAA,CAAID,KAAAA,CAAME,IAAI,CAAA,EAAG;AAC1B,IAAA,OAAO,YAAA;AACH,MAAA,MAAMN,QAAAA,CAASO,GAAAA,CAAIH,KAAAA,CAAME,IAAI,CAAA;AAC7B,MAAA,OAAOJ,QAAAA;AACX,IAAA,CAAA;AACJ,EAAA;AACA,EAAA,IAAIM,QAAAA;AAEJR,EAAAA,QAAAA,CAASS,IACLL,KAAAA,CAAME,IAAAA,EACN,IAAII,OAAAA,CAAc,CAACC,GAAAA,KAAAA;AACfH,IAAAA,QAAAA,GAAWG,GAAAA;AACf,EAAA,CAAA,CAAA,CAAA;AAIJ,EAAA,MAAMC,oBAA4C,EAAA;AAClD,EAAA,IAAIR,MAAMS,YAAAA,EAAc;AACpB,IAAA,MAAMC,aAAAA,GAAgB;AAAIX,MAAAA,GAAAA,UAAAA;AAAYC,MAAAA;;AACtC,IAAA,KAAA,MAAW,CAACW,GAAGC,eAAAA,CAAAA,IAAoBC,OAAOC,OAAAA,CAAQd,KAAAA,CAAMS,YAAY,CAAA,EAAG;AACnED,MAAAA,iBAAAA,CAAkBO,IAAAA,CACdvB,IAAIoB,eAAAA,EAAiBlB,OAAAA,EAASC,YAAYC,QAAAA,EAAUE,QAAAA,EAAUY,aAAAA,CAAAA,CAAAA;AAEtE,IAAA;AACJ,EAAA;AAEA,EAAA,OAAO,YAAA;AACH,IAAA,IAAI;AACA,MAAA,MAAMJ,OAAAA,CAAQU,IAAIR,iBAAAA,CAAkBS,GAAAA,CAAI,CAACC,CAAAA,KAAMA,CAAAA,EAAAA,CAAAA,CAAAA;AAC/C,MAAA,MAAMC,MAAAA,GAAS,MAAMzB,OAAAA,CAAQM,KAAAA,CAAAA;AAC7B,MAAA,IAAImB,MAAAA,EAAQ;AACP,QAAA,CAACrB,QAAAA,CAAiBqB,OAAOC,GAAG,CAAA,KAAM,EAAC,EAAGpB,KAAAA,CAAME,IAAI,CAAA,GAAIiB,MAAAA,CAAOE,KAAAA;AAChE,MAAA;AACAjB,MAAAA,QAAAA,EAAAA;AACA,MAAA,OAAON,QAAAA;AACX,IAAA,CAAA,CAAA,OAASwB,KAAAA,EAAY;AACjBC,MAAAA,OAAAA,CAAQD,KAAAA,CACJ,CAAA,UAAA,EAAavB,UAAAA,CAAWkB,GAAAA,CAAI,CAACO,CAAAA,KAAMA,CAAAA,CAAEtB,IAAI,CAAA,CAAEuB,IAAAA,CAAK,GAAA,CAAA;AAASH,EAAAA,KAAAA,EAAOI,OAAAA,CAAAA,CAAS,CAAA;AAE7E,MAAA,MAAMJ,KAAAA;AACV,IAAA;AACJ,EAAA,CAAA;AACJ,CAAA,EAnDmB,KAAA","file":"index.cjs","sourcesContent":["import type { Dependencies, DependencyNode } from '@layerzerolabs/dependency-graph';\n\n/**\n * A registrar is a simple interface for an object that provides the ability to traverse the dependency graph.\n * It is implicit in this definition that the registrar should also *register* values adhering to the schemata\n * of the graph.\n */\nexport interface Registrar<ReturnType> {\n traverseDependencies: (rootNode: DependencyNode<any, any>) => Promise<ReturnType>;\n}\nexport type NodeHandlerFunction = (\n node: DependencyNode<any, Dependencies>,\n) => Promise<{ key: string; value: any }>;\nexport type NodePreHandlerFunction = (\n node: DependencyNode<any, Dependencies>,\n) => DependencyNode<any, Dependencies>;\n\n/**\n * Performs a depth-first-search on a tree of dependency nodes, and returns a function\n * that will call the handler for each node in the tree, ordered s.t. the handler of N\n * will be called only after the handlers of dependencies(N) have been called.\n * The resolver function will only call the handler once for each unique definition node.\n * The resolver function returns an object whose keys are the keys defined\n * by each of the handlers, and whose values are objects whose keys are the names\n * of the nodes resolved and whose values are the values defined by the handlers.\n * @param node the root node of the tree\n * @param handler a function that accepts a node and registers it\n * @param prehandler a function that accepts a node and returns a node. will be use to pre-process the graph\n * @returns a resolver function\n */\nexport const dfs = <DependencyName extends string, ReturnTypes>(\n node: DependencyNode<DependencyName, Dependencies>,\n handler: NodeHandlerFunction,\n prehandler: NodePreHandlerFunction = (node) => node,\n _visited: Map<string, Promise<void>> = new Map(),\n _returns: ReturnTypes = {} as any,\n _backtrack: DependencyNode<DependencyName, Dependencies>[] = [],\n): (() => Promise<ReturnTypes>) => {\n const _node = prehandler(node);\n if (_visited.has(_node.name)) {\n return async () => {\n await _visited.get(_node.name);\n return _returns;\n };\n }\n let resolver: (value: void | PromiseLike<void>) => void;\n\n _visited.set(\n _node.name,\n new Promise<void>((res) => {\n resolver = res;\n }),\n );\n\n // Resolve dependencies first\n const resolverFunctions: (() => Promise<any>)[] = [];\n if (_node.dependencies) {\n const nextBacktrack = [..._backtrack, _node];\n for (const [_, dependencyValue] of Object.entries(_node.dependencies)) {\n resolverFunctions.push(\n dfs(dependencyValue, handler, prehandler, _visited, _returns, nextBacktrack),\n );\n }\n }\n\n return async () => {\n try {\n await Promise.all(resolverFunctions.map((f) => f()));\n const regRes = await handler(_node);\n if (regRes) {\n ((_returns as any)[regRes.key] ??= {})[_node.name] = regRes.value;\n }\n resolver();\n return _returns;\n } catch (error: any) {\n console.error(\n `Failed at ${_backtrack.map((n) => n.name).join('/')}\\n${error?.message}`,\n );\n throw error;\n }\n };\n};\n"]}
package/dist/index.js CHANGED
@@ -34,10 +34,9 @@ var dfs = /* @__PURE__ */ __name((node, handler, prehandler = (node2) => node2,
34
34
  resolver();
35
35
  return _returns;
36
36
  } catch (error) {
37
- throw new Error(`Failed at ${_backtrack.map((n) => n.name).join("/")}.
38
- ${error?.message}`, {
39
- cause: error
40
- });
37
+ console.error(`Failed at ${_backtrack.map((n) => n.name).join("/")}
38
+ ${error?.message}`);
39
+ throw error;
41
40
  }
42
41
  };
43
42
  }, "dfs");
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["dfs","node","handler","prehandler","_visited","Map","_returns","_backtrack","_node","has","name","get","resolver","set","Promise","res","resolverFunctions","dependencies","nextBacktrack","_","dependencyValue","Object","entries","push","all","map","f","regRes","key","value","error","Error","n","join","message","cause"],"mappings":";;;;AA8BO,IAAMA,sBAAM,MAAA,CAAA,CACfC,IAAAA,EACAC,OAAAA,EACAC,UAAAA,GAAqC,CAACF,KAAAA,KAASA,KAAAA,EAC/CG,QAAAA,mBAAuC,IAAIC,KAAAA,EAC3CC,QAAAA,GAAwB,EAAC,EACzBC,UAAAA,GAA6D,EAAA,KAAE;AAE/D,EAAA,MAAMC,KAAAA,GAAQL,WAAWF,IAAAA,CAAAA;AACzB,EAAA,IAAIG,QAAAA,CAASK,GAAAA,CAAID,KAAAA,CAAME,IAAI,CAAA,EAAG;AAC1B,IAAA,OAAO,YAAA;AACH,MAAA,MAAMN,QAAAA,CAASO,GAAAA,CAAIH,KAAAA,CAAME,IAAI,CAAA;AAC7B,MAAA,OAAOJ,QAAAA;AACX,IAAA,CAAA;AACJ,EAAA;AACA,EAAA,IAAIM,QAAAA;AAEJR,EAAAA,QAAAA,CAASS,IACLL,KAAAA,CAAME,IAAAA,EACN,IAAII,OAAAA,CAAc,CAACC,GAAAA,KAAAA;AACfH,IAAAA,QAAAA,GAAWG,GAAAA;AACf,EAAA,CAAA,CAAA,CAAA;AAIJ,EAAA,MAAMC,oBAA4C,EAAA;AAClD,EAAA,IAAIR,MAAMS,YAAAA,EAAc;AACpB,IAAA,MAAMC,aAAAA,GAAgB;AAAIX,MAAAA,GAAAA,UAAAA;AAAYC,MAAAA;;AACtC,IAAA,KAAA,MAAW,CAACW,GAAGC,eAAAA,CAAAA,IAAoBC,OAAOC,OAAAA,CAAQd,KAAAA,CAAMS,YAAY,CAAA,EAAG;AACnED,MAAAA,iBAAAA,CAAkBO,IAAAA,CACdvB,IAAIoB,eAAAA,EAAiBlB,OAAAA,EAASC,YAAYC,QAAAA,EAAUE,QAAAA,EAAUY,aAAAA,CAAAA,CAAAA;AAEtE,IAAA;AACJ,EAAA;AAEA,EAAA,OAAO,YAAA;AACH,IAAA,IAAI;AACA,MAAA,MAAMJ,OAAAA,CAAQU,IAAIR,iBAAAA,CAAkBS,GAAAA,CAAI,CAACC,CAAAA,KAAMA,CAAAA,EAAAA,CAAAA,CAAAA;AAC/C,MAAA,MAAMC,MAAAA,GAAS,MAAMzB,OAAAA,CAAQM,KAAAA,CAAAA;AAC7B,MAAA,IAAImB,MAAAA,EAAQ;AACP,QAAA,CAACrB,QAAAA,CAAiBqB,OAAOC,GAAG,CAAA,KAAM,EAAC,EAAGpB,KAAAA,CAAME,IAAI,CAAA,GAAIiB,MAAAA,CAAOE,KAAAA;AAChE,MAAA;AACAjB,MAAAA,QAAAA,EAAAA;AACA,MAAA,OAAON,QAAAA;AACX,IAAA,CAAA,CAAA,OAASwB,KAAAA,EAAY;AACjB,MAAA,MAAM,IAAIC,KAAAA,CACN,CAAA,UAAA,EAAaxB,UAAAA,CAAWkB,GAAAA,CAAI,CAACO,CAAAA,KAAMA,CAAAA,CAAEtB,IAAI,CAAA,CAAEuB,IAAAA,CAAK,GAAA,CAAA,CAAA;AAAUH,EAAAA,KAAAA,EAAOI,OAAAA,CAAAA,CAAAA,EACjE;QAAEC,KAAAA,EAAOL;OAAM,CAAA;AAEvB,IAAA;AACJ,EAAA,CAAA;AACJ,CAAA,EAnDmB,KAAA","file":"index.js","sourcesContent":["import type { Dependencies, DependencyNode } from '@layerzerolabs/dependency-graph';\n\n/**\n * A registrar is a simple interface for an object that provides the ability to traverse the dependency graph.\n * It is implicit in this definition that the registrar should also *register* values adhering to the schemata\n * of the graph.\n */\nexport interface Registrar<ReturnType> {\n traverseDependencies: (rootNode: DependencyNode<any, any>) => Promise<ReturnType>;\n}\nexport type NodeHandlerFunction = (\n node: DependencyNode<any, Dependencies>,\n) => Promise<{ key: string; value: any }>;\nexport type NodePreHandlerFunction = (\n node: DependencyNode<any, Dependencies>,\n) => DependencyNode<any, Dependencies>;\n\n/**\n * Performs a depth-first-search on a tree of dependency nodes, and returns a function\n * that will call the handler for each node in the tree, ordered s.t. the handler of N\n * will be called only after the handlers of dependencies(N) have been called.\n * The resolver function will only call the handler once for each unique definition node.\n * The resolver function returns an object whose keys are the keys defined\n * by each of the handlers, and whose values are objects whose keys are the names\n * of the nodes resolved and whose values are the values defined by the handlers.\n * @param node the root node of the tree\n * @param handler a function that accepts a node and registers it\n * @param prehandler a function that accepts a node and returns a node. will be use to pre-process the graph\n * @returns a resolver function\n */\nexport const dfs = <DependencyName extends string, ReturnTypes>(\n node: DependencyNode<DependencyName, Dependencies>,\n handler: NodeHandlerFunction,\n prehandler: NodePreHandlerFunction = (node) => node,\n _visited: Map<string, Promise<void>> = new Map(),\n _returns: ReturnTypes = {} as any,\n _backtrack: DependencyNode<DependencyName, Dependencies>[] = [],\n): (() => Promise<ReturnTypes>) => {\n const _node = prehandler(node);\n if (_visited.has(_node.name)) {\n return async () => {\n await _visited.get(_node.name);\n return _returns;\n };\n }\n let resolver: (value: void | PromiseLike<void>) => void;\n\n _visited.set(\n _node.name,\n new Promise<void>((res) => {\n resolver = res;\n }),\n );\n\n // Resolve dependencies first\n const resolverFunctions: (() => Promise<any>)[] = [];\n if (_node.dependencies) {\n const nextBacktrack = [..._backtrack, _node];\n for (const [_, dependencyValue] of Object.entries(_node.dependencies)) {\n resolverFunctions.push(\n dfs(dependencyValue, handler, prehandler, _visited, _returns, nextBacktrack),\n );\n }\n }\n\n return async () => {\n try {\n await Promise.all(resolverFunctions.map((f) => f()));\n const regRes = await handler(_node);\n if (regRes) {\n ((_returns as any)[regRes.key] ??= {})[_node.name] = regRes.value;\n }\n resolver();\n return _returns;\n } catch (error: any) {\n throw new Error(\n `Failed at ${_backtrack.map((n) => n.name).join('/')}.\\n${error?.message}`,\n { cause: error },\n );\n }\n };\n};\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["dfs","node","handler","prehandler","_visited","Map","_returns","_backtrack","_node","has","name","get","resolver","set","Promise","res","resolverFunctions","dependencies","nextBacktrack","_","dependencyValue","Object","entries","push","all","map","f","regRes","key","value","error","console","n","join","message"],"mappings":";;;;AA8BO,IAAMA,sBAAM,MAAA,CAAA,CACfC,IAAAA,EACAC,OAAAA,EACAC,UAAAA,GAAqC,CAACF,KAAAA,KAASA,KAAAA,EAC/CG,QAAAA,mBAAuC,IAAIC,KAAAA,EAC3CC,QAAAA,GAAwB,EAAC,EACzBC,UAAAA,GAA6D,EAAA,KAAE;AAE/D,EAAA,MAAMC,KAAAA,GAAQL,WAAWF,IAAAA,CAAAA;AACzB,EAAA,IAAIG,QAAAA,CAASK,GAAAA,CAAID,KAAAA,CAAME,IAAI,CAAA,EAAG;AAC1B,IAAA,OAAO,YAAA;AACH,MAAA,MAAMN,QAAAA,CAASO,GAAAA,CAAIH,KAAAA,CAAME,IAAI,CAAA;AAC7B,MAAA,OAAOJ,QAAAA;AACX,IAAA,CAAA;AACJ,EAAA;AACA,EAAA,IAAIM,QAAAA;AAEJR,EAAAA,QAAAA,CAASS,IACLL,KAAAA,CAAME,IAAAA,EACN,IAAII,OAAAA,CAAc,CAACC,GAAAA,KAAAA;AACfH,IAAAA,QAAAA,GAAWG,GAAAA;AACf,EAAA,CAAA,CAAA,CAAA;AAIJ,EAAA,MAAMC,oBAA4C,EAAA;AAClD,EAAA,IAAIR,MAAMS,YAAAA,EAAc;AACpB,IAAA,MAAMC,aAAAA,GAAgB;AAAIX,MAAAA,GAAAA,UAAAA;AAAYC,MAAAA;;AACtC,IAAA,KAAA,MAAW,CAACW,GAAGC,eAAAA,CAAAA,IAAoBC,OAAOC,OAAAA,CAAQd,KAAAA,CAAMS,YAAY,CAAA,EAAG;AACnED,MAAAA,iBAAAA,CAAkBO,IAAAA,CACdvB,IAAIoB,eAAAA,EAAiBlB,OAAAA,EAASC,YAAYC,QAAAA,EAAUE,QAAAA,EAAUY,aAAAA,CAAAA,CAAAA;AAEtE,IAAA;AACJ,EAAA;AAEA,EAAA,OAAO,YAAA;AACH,IAAA,IAAI;AACA,MAAA,MAAMJ,OAAAA,CAAQU,IAAIR,iBAAAA,CAAkBS,GAAAA,CAAI,CAACC,CAAAA,KAAMA,CAAAA,EAAAA,CAAAA,CAAAA;AAC/C,MAAA,MAAMC,MAAAA,GAAS,MAAMzB,OAAAA,CAAQM,KAAAA,CAAAA;AAC7B,MAAA,IAAImB,MAAAA,EAAQ;AACP,QAAA,CAACrB,QAAAA,CAAiBqB,OAAOC,GAAG,CAAA,KAAM,EAAC,EAAGpB,KAAAA,CAAME,IAAI,CAAA,GAAIiB,MAAAA,CAAOE,KAAAA;AAChE,MAAA;AACAjB,MAAAA,QAAAA,EAAAA;AACA,MAAA,OAAON,QAAAA;AACX,IAAA,CAAA,CAAA,OAASwB,KAAAA,EAAY;AACjBC,MAAAA,OAAAA,CAAQD,KAAAA,CACJ,CAAA,UAAA,EAAavB,UAAAA,CAAWkB,GAAAA,CAAI,CAACO,CAAAA,KAAMA,CAAAA,CAAEtB,IAAI,CAAA,CAAEuB,IAAAA,CAAK,GAAA,CAAA;AAASH,EAAAA,KAAAA,EAAOI,OAAAA,CAAAA,CAAS,CAAA;AAE7E,MAAA,MAAMJ,KAAAA;AACV,IAAA;AACJ,EAAA,CAAA;AACJ,CAAA,EAnDmB,KAAA","file":"index.js","sourcesContent":["import type { Dependencies, DependencyNode } from '@layerzerolabs/dependency-graph';\n\n/**\n * A registrar is a simple interface for an object that provides the ability to traverse the dependency graph.\n * It is implicit in this definition that the registrar should also *register* values adhering to the schemata\n * of the graph.\n */\nexport interface Registrar<ReturnType> {\n traverseDependencies: (rootNode: DependencyNode<any, any>) => Promise<ReturnType>;\n}\nexport type NodeHandlerFunction = (\n node: DependencyNode<any, Dependencies>,\n) => Promise<{ key: string; value: any }>;\nexport type NodePreHandlerFunction = (\n node: DependencyNode<any, Dependencies>,\n) => DependencyNode<any, Dependencies>;\n\n/**\n * Performs a depth-first-search on a tree of dependency nodes, and returns a function\n * that will call the handler for each node in the tree, ordered s.t. the handler of N\n * will be called only after the handlers of dependencies(N) have been called.\n * The resolver function will only call the handler once for each unique definition node.\n * The resolver function returns an object whose keys are the keys defined\n * by each of the handlers, and whose values are objects whose keys are the names\n * of the nodes resolved and whose values are the values defined by the handlers.\n * @param node the root node of the tree\n * @param handler a function that accepts a node and registers it\n * @param prehandler a function that accepts a node and returns a node. will be use to pre-process the graph\n * @returns a resolver function\n */\nexport const dfs = <DependencyName extends string, ReturnTypes>(\n node: DependencyNode<DependencyName, Dependencies>,\n handler: NodeHandlerFunction,\n prehandler: NodePreHandlerFunction = (node) => node,\n _visited: Map<string, Promise<void>> = new Map(),\n _returns: ReturnTypes = {} as any,\n _backtrack: DependencyNode<DependencyName, Dependencies>[] = [],\n): (() => Promise<ReturnTypes>) => {\n const _node = prehandler(node);\n if (_visited.has(_node.name)) {\n return async () => {\n await _visited.get(_node.name);\n return _returns;\n };\n }\n let resolver: (value: void | PromiseLike<void>) => void;\n\n _visited.set(\n _node.name,\n new Promise<void>((res) => {\n resolver = res;\n }),\n );\n\n // Resolve dependencies first\n const resolverFunctions: (() => Promise<any>)[] = [];\n if (_node.dependencies) {\n const nextBacktrack = [..._backtrack, _node];\n for (const [_, dependencyValue] of Object.entries(_node.dependencies)) {\n resolverFunctions.push(\n dfs(dependencyValue, handler, prehandler, _visited, _returns, nextBacktrack),\n );\n }\n }\n\n return async () => {\n try {\n await Promise.all(resolverFunctions.map((f) => f()));\n const regRes = await handler(_node);\n if (regRes) {\n ((_returns as any)[regRes.key] ??= {})[_node.name] = regRes.value;\n }\n resolver();\n return _returns;\n } catch (error: any) {\n console.error(\n `Failed at ${_backtrack.map((n) => n.name).join('/')}\\n${error?.message}`,\n );\n throw error;\n }\n };\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layerzerolabs/dfs",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,13 +14,13 @@
14
14
  "module": "./dist/index.js",
15
15
  "types": "./dist/index.d.ts",
16
16
  "dependencies": {
17
- "@layerzerolabs/dependency-graph": "0.0.17"
17
+ "@layerzerolabs/dependency-graph": "0.0.19"
18
18
  },
19
19
  "devDependencies": {
20
20
  "tsup": "^8.4.0",
21
21
  "vitest": "^3.2.3",
22
- "@layerzerolabs/tsup-configuration": "0.0.17",
23
- "@layerzerolabs/typescript-configuration": "0.0.17"
22
+ "@layerzerolabs/typescript-configuration": "0.0.19",
23
+ "@layerzerolabs/tsup-configuration": "0.0.19"
24
24
  },
25
25
  "publishConfig": {
26
26
  "access": "restricted",
package/src/index.ts CHANGED
@@ -73,10 +73,10 @@ export const dfs = <DependencyName extends string, ReturnTypes>(
73
73
  resolver();
74
74
  return _returns;
75
75
  } catch (error: any) {
76
- throw new Error(
77
- `Failed at ${_backtrack.map((n) => n.name).join('/')}.\n${error?.message}`,
78
- { cause: error },
76
+ console.error(
77
+ `Failed at ${_backtrack.map((n) => n.name).join('/')}\n${error?.message}`,
79
78
  );
79
+ throw error;
80
80
  }
81
81
  };
82
82
  };