<commit_before>xquery version "1.0-ml";

module namespace resource = "http://marklogic.com/rest-api/resource/export-presentation-ml";

declare namespace html = "http://www.w3.org/1999/xhtml";
declare namespace zip = "xdmp:zip";

declare function get(
  $context as map:map,
  $params  as map:map
  ) as document-node()*
{
  let $dir := map:get($params, "dir")
  let $template := (map:get($params, "template"), "template")[1]
  let $zip-manifest :=
    <parts xmlns="xdmp:zip">
      <part>docProps/app.xml</part>
      <part>docProps/core.xml</part>
    </parts> 
  let $zip := 
    xdmp:zip-create(
      $zip-manifest,
      (
        fn:doc("/template.pptx/docProps/app.xml"),
        fn:doc("/template.pptx/docProps/core.xml")
      )
    ) 
  return 
  (
    (: Uncomment this line to return a PPTX file :)
    (: map:put($context, "output-types", "application/vnd.openxmlformats-officedocument.presentationml.presentation"), :)
    map:put($context, "output-types", "application/zip"),
    document{ binary {$zip} }
  )
};

declare function put(
  $context as map:map,
  $params  as map:map,
  $input   as document-node()*
  ) as document-node()?
{
  xdmp:log("PUT called")
};

declare function post(
  $context as map:map,
  $params  as map:map,
  $input   as document-node()*
  ) as document-node()*
{
  xdmp:log("POST called")
};

declare function delete(
  $context as map:map,
  $params  as map:map
  ) as document-node()?
{
  xdmp:log("DELETE called")<commit_msg>Dynamically create the zip manifest<commit_after>xquery version "1.0-ml";

module namespace resource = "http://marklogic.com/rest-api/resource/export-presentation-ml";

declare namespace html = "http://www.w3.org/1999/xhtml";
declare namespace zip = "xdmp:zip";

declare function get(
  $context as map:map,
  $params  as map:map
  ) as document-node()*
{
  let $dir := map:get($params, "dir")
  let $template := (map:get($params, "template"), "template")[1]
  let $uris := cts:uris("", (), cts:directory-query("/template.pptx/", "infinity"))
  let $zip-manifest :=
    element zip:parts {
      for $uri in $uris
      return element zip:part { fn:replace($uri, "/template.pptx/", "") }
    }
  let $zip := 
    xdmp:zip-create(
      $zip-manifest,
      (
        for $uri in $uris
        return fn:doc($uri)
      )
    ) 
  return 
  (
    (: Uncomment this line to return a PPTX file :)
    (: map:put($context, "output-types", "application/vnd.openxmlformats-officedocument.presentationml.presentation"), :) 
    map:put($context, "output-types", "application/zip"), 
    document{ binary {$zip} }
  )
};

declare function put(
  $context as map:map,
  $params  as map:map,
  $input   as document-node()*
  ) as document-node()?
{
  xdmp:log("PUT called")
};

declare function post(
  $context as map:map,
  $params  as map:map,
  $input   as document-node()*
  ) as document-node()*
{
  xdmp:log("POST called")
};

declare function delete(
  $context as map:map,
  $params  as map:map
  ) as document-node()?
{
  xdmp:log("DELETE called")
{'fraction_non_alphanumeric': 0.1684315023163468, 'fraction_numerical': 0.005294506949040371, 'mean_word_length': 3.4067055393586005, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 7}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6716735', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1049, 'n_words': 240}