import { c as create_ssr_component, g as getContext, b as subscribe, v as validate_component } from "../../chunks/index-0e008fb3.js";
import { E as Editor } from "../../chunks/editor-8f7742a9.js";
import { E as Error } from "../../chunks/error-b3674f8e.js";
import "js-yaml";
import "lodash/get.js";
var schemas = [
  {
    $id: "/schemas/datastore/aggregator/pipeline",
    type: "array",
    items: {
      oneOf: [
        {
          $ref: "/schemas/datastore/aggregator/step/fetch"
        },
        {
          $ref: "/schemas/datastore/aggregator/step/map"
        },
        {
          $ref: "/schemas/datastore/aggregator/step/unset"
        },
        {
          $ref: "/schemas/datastore/aggregator/step/validate"
        },
        {
          $ref: "/schemas/datastore/aggregator/step/each"
        },
        {
          $ref: "/schemas/datastore/aggregator/step/if"
        },
        {
          $ref: "/schemas/datastore/aggregator/step/filter"
        },
        {
          $ref: "/schemas/datastore/aggregator/step/op"
        },
        {
          $ref: "/schemas/datastore/aggregator/step/from"
        },
        {
          $ref: "/schemas/datastore/aggregator/step/persist"
        }
      ]
    }
  },
  {
    $id: "/schemas/datastore/aggregator/step/fetch",
    type: "object",
    required: [
      "type",
      "model"
    ],
    properties: {
      type: {
        $ref: "/schemas/datastore/aggregator/components/type",
        "enum": [
          "fetch"
        ]
      },
      name: {
        $ref: "/schemas/datastore/aggregator/components/step/name"
      },
      description: {
        $ref: "/schemas/datastore/aggregator/components/step/description"
      },
      destination: {
        $ref: "/schemas/datastore/aggregator/components/destination"
      },
      datastore: {
        $ref: "/schemas/datastore/aggregator/components/model"
      },
      model: {
        $ref: "/schemas/datastore/aggregator/components/model"
      },
      source: {
        $ref: "/schemas/datastore/aggregator/components/source"
      },
      timetravel: {
        $ref: "/schemas/datastore/aggregator/components/timetravel"
      },
      correlation_field: {
        $ref: "/schemas/datastore/aggregator/components/correlation_field",
        description: "Correlation field to use for timetravel"
      },
      query: {
        $ref: "/schemas/datastore/aggregator/components/query"
      },
      headers: {
        $ref: "/schemas/datastore/aggregator/components/headers"
      },
      map: {
        $ref: "/schemas/datastore/aggregator/components/map"
      },
      page: {
        type: "number",
        minimum: 0,
        description: "Page index of the fetch step"
      },
      page_size: {
        type: "number",
        minimum: 0,
        description: "Page size of the fetch step"
      },
      as_entity: {
        type: "boolean",
        description: "Does a single entity must be fetched?"
      },
      must_decrypt: {
        type: "boolean",
        description: "Does the entity content be decrypt before being persisted?"
      }
    }
  },
  {
    $id: "/schemas/datastore/aggregator/step/map",
    type: "object",
    required: [
      "type"
    ],
    properties: {
      type: {
        $ref: "/schemas/datastore/aggregator/components/type",
        "enum": [
          "map"
        ]
      },
      name: {
        $ref: "/schemas/datastore/aggregator/components/step/name"
      },
      description: {
        $ref: "/schemas/datastore/aggregator/components/step/description"
      },
      map: {
        $ref: "/schemas/datastore/aggregator/components/map"
      }
    }
  },
  {
    $id: "/schemas/datastore/aggregator/step/unset",
    type: "object",
    required: [
      "type"
    ],
    properties: {
      type: {
        $ref: "/schemas/datastore/aggregator/components/type",
        "enum": [
          "unset"
        ]
      },
      name: {
        $ref: "/schemas/datastore/aggregator/components/step/name"
      },
      description: {
        $ref: "/schemas/datastore/aggregator/components/step/description"
      },
      path: {
        $ref: "/schemas/datastore/aggregator/components/path"
      }
    }
  },
  {
    $id: "/schemas/datastore/aggregator/step/validate",
    type: "object",
    required: [
      "type"
    ],
    properties: {
      type: {
        $ref: "/schemas/datastore/aggregator/components/type",
        "enum": [
          "validate"
        ]
      },
      name: {
        $ref: "/schemas/datastore/aggregator/components/step/name"
      },
      description: {
        $ref: "/schemas/datastore/aggregator/components/step/description"
      },
      path: {
        $ref: "/schemas/datastore/aggregator/components/path",
        description: "Path in the current state to validate"
      },
      destination: {
        $ref: "/schemas/datastore/aggregator/components/path",
        description: "Validation result path"
      },
      must_throw: {
        type: "boolean",
        description: "Does an invalidation leads to an exception?"
      },
      schema: {
        type: "object",
        description: "JSON Schema to validate"
      }
    }
  },
  {
    $id: "/schemas/datastore/aggregator/step/each",
    type: "object",
    required: [
      "type"
    ],
    properties: {
      type: {
        $ref: "/schemas/datastore/aggregator/components/type",
        "enum": [
          "each"
        ]
      },
      name: {
        $ref: "/schemas/datastore/aggregator/components/step/name"
      },
      description: {
        $ref: "/schemas/datastore/aggregator/components/step/description"
      },
      path: {
        $ref: "/schemas/datastore/aggregator/components/path",
        description: "Path in the current state to iterate on"
      },
      destination: {
        $ref: "/schemas/datastore/aggregator/components/path",
        description: "Validation result path"
      },
      pipeline: {
        $ref: "/schemas/datastore/aggregator/pipeline"
      }
    }
  },
  {
    $id: "/schemas/datastore/aggregator/step/if",
    type: "object",
    required: [
      "type"
    ],
    properties: {
      type: {
        $ref: "/schemas/datastore/aggregator/components/type",
        "enum": [
          "if"
        ]
      },
      name: {
        $ref: "/schemas/datastore/aggregator/components/step/name"
      },
      description: {
        $ref: "/schemas/datastore/aggregator/components/step/description"
      },
      path: {
        $ref: "/schemas/datastore/aggregator/components/path",
        description: "Path in the current state to validate"
      },
      schema: {
        type: "object",
        description: "JSON Schema to validate"
      },
      pipeline: {
        $ref: "/schemas/datastore/aggregator/pipeline",
        description: "Sub pipeline to execute"
      },
      repeat_while_true: {
        type: "boolean",
        description: "Repeat the step while the validate part is true (while loop)"
      },
      max_iteration_count: {
        type: "number",
        minimum: 0,
        description: "Maximum number of iterations in case of a while loop iteration (default: 100)"
      }
    }
  },
  {
    $id: "/schemas/datastore/aggregator/step/filter",
    type: "object",
    required: [
      "type"
    ],
    properties: {
      type: {
        $ref: "/schemas/datastore/aggregator/components/type",
        "enum": [
          "filter"
        ]
      },
      name: {
        $ref: "/schemas/datastore/aggregator/components/step/name"
      },
      description: {
        $ref: "/schemas/datastore/aggregator/components/step/description"
      },
      path: {
        $ref: "/schemas/datastore/aggregator/components/path",
        description: "Path in the current state to validate"
      },
      destination: {
        $ref: "/schemas/datastore/aggregator/components/path",
        description: "Validation result path"
      },
      schema: {
        type: "object",
        description: "JSON Schema to validate"
      }
    }
  },
  {
    $id: "/schemas/datastore/aggregator/step/from",
    type: "object",
    required: [
      "type"
    ],
    properties: {
      type: {
        $ref: "/schemas/datastore/aggregator/components/type",
        "enum": [
          "from"
        ]
      },
      name: {
        $ref: "/schemas/datastore/aggregator/components/step/name"
      },
      description: {
        $ref: "/schemas/datastore/aggregator/components/step/description"
      },
      path: {
        $ref: "/schemas/datastore/aggregator/components/path",
        description: "Path in the current state to search steps to execute"
      }
    }
  },
  {
    $id: "/schemas/datastore/aggregator/step/op",
    type: "object",
    required: [
      "type"
    ],
    properties: {
      type: {
        $ref: "/schemas/datastore/aggregator/components/type",
        "enum": [
          "op"
        ]
      },
      name: {
        $ref: "/schemas/datastore/aggregator/components/step/name"
      },
      description: {
        $ref: "/schemas/datastore/aggregator/components/step/description"
      },
      path: {
        $ref: "/schemas/datastore/aggregator/components/path",
        description: "Path in the current state to validate"
      },
      destination: {
        $ref: "/schemas/datastore/aggregator/components/path",
        description: "Validation result path"
      },
      func: {
        type: "string",
        description: "Name of the function to invoke"
      },
      args_as_array: {
        type: "boolean",
        description: "Are the args be sent as array (true) to the function or as arguments (otherwise)?"
      },
      args: {
        type: "array",
        items: {
          type: "object",
          properties: {
            path: {
              $ref: "/schemas/datastore/aggregator/components/path"
            }
          }
        }
      }
    }
  },
  {
    $id: "/schemas/datastore/aggregator/step/persist",
    type: "object",
    required: [
      "type"
    ],
    properties: {
      type: {
        $ref: "/schemas/datastore/aggregator/components/type",
        "enum": [
          "persist"
        ]
      },
      name: {
        $ref: "/schemas/datastore/aggregator/components/step/name"
      },
      description: {
        $ref: "/schemas/datastore/aggregator/components/step/description"
      },
      destination: {
        $ref: "/schemas/datastore/aggregator/components/destination"
      },
      datastore: {
        $ref: "/schemas/datastore/aggregator/components/model"
      },
      model: {
        $ref: "/schemas/datastore/aggregator/components/model"
      },
      correlation_field: {
        $ref: "/schemas/datastore/aggregator/components/correlation_field",
        description: "Correlation field to use for update"
      },
      payload: {
        $ref: "/schemas/datastore/aggregator/components/query"
      },
      headers: {
        $ref: "/schemas/datastore/aggregator/components/headers"
      },
      map: {
        $ref: "/schemas/datastore/aggregator/components/map"
      }
    }
  },
  {
    $id: "/schemas/datastore/aggregator/components/type",
    type: "string",
    description: "Step type"
  },
  {
    $id: "/schemas/datastore/aggregator/components/path",
    oneOf: [
      {
        type: "string",
        description: "String path definition"
      },
      {
        type: "array",
        description: "Array based path definition",
        items: {
          type: "string"
        }
      }
    ]
  },
  {
    $id: "/schemas/datastore/aggregator/components/datastore",
    type: "string",
    description: "Datastore client to use",
    "default": "(The first one available)"
  },
  {
    $id: "/schemas/datastore/aggregator/components/model",
    type: "string",
    description: "Model to fetch data from"
  },
  {
    $id: "/schemas/datastore/aggregator/components/source",
    type: "string",
    "enum": [
      "entities",
      "events"
    ],
    description: "Source of data: entities or events",
    "default": "entities"
  },
  {
    $id: "/schemas/datastore/aggregator/components/timetravel",
    type: "string",
    description: "Path of the field to use for timetravel date"
  },
  {
    $id: "/schemas/datastore/aggregator/components/correlation_field",
    type: "string",
    description: "Correlation field"
  },
  {
    $id: "/schemas/datastore/aggregator/components/destination",
    $ref: "/schemas/datastore/aggregator/components/path",
    description: "Location of the persistence in the state as a lodash path format"
  },
  {
    $id: "/schemas/datastore/aggregator/components/query",
    type: "object",
    description: "Base query to use to perform the fetch"
  },
  {
    $id: "/schemas/datastore/aggregator/components/headers",
    type: "object",
    patternProperties: {
      ".*": {
        type: "string"
      }
    },
    description: "Headers to send along the fetch request"
  },
  {
    $id: "/schemas/datastore/aggregator/components/map",
    type: "array",
    items: {
      $ref: "/schemas/datastore/aggregator/components/map/item"
    }
  },
  {
    $id: "/schemas/datastore/aggregator/components/map/item",
    description: "Map step definition",
    type: "object",
    required: [
      "from",
      "to"
    ],
    properties: {
      from: {
        $ref: "/schemas/datastore/aggregator/components/path",
        description: "Source location of the data to map"
      },
      to: {
        $ref: "/schemas/datastore/aggregator/components/path",
        description: "Destination location of the mapped data"
      },
      must_hash: {
        type: "boolean",
        description: "Does the mapped value be hashed before being persisted?"
      },
      json_stringify: {
        type: "boolean",
        description: "Does the mapped value be JSON stringified before being hashed or persisted"
      },
      relative_date_in_seconds: {
        type: "number",
        description: "Change the date defined in value or current date of a specific quantity defined in seconds"
      }
    }
  },
  {
    $id: "/schemas/datastore/aggregator/components/step/name",
    type: "string",
    description: "Step name"
  },
  {
    $id: "/schemas/datastore/aggregator/components/step/description",
    type: "string",
    description: "Step description"
  }
];
const Aggregation = create_ssr_component(($$result, $$props, $$bindings, slots) => {
  let $$unsubscribe_datastore;
  let $value, $$unsubscribe_value;
  const datastore = getContext("stores").activeClient;
  $$unsubscribe_datastore = subscribe(datastore, (value2) => value2);
  const value = getContext("stores").editorValue;
  $$unsubscribe_value = subscribe(value, (value2) => $value = value2);
  let editor;
  let error;
  let logs = [];
  let $$settled;
  let $$rendered;
  do {
    $$settled = true;
    $$rendered = `${!!datastore ? `<div class="${"flex flex-column h-screen"}" style="${"background-color: #272822;"}"><div class="${"w-4/12 border-r-2"}" style="${"border-color: #171812;"}">${validate_component(Editor, "Editor").$$render($$result, {
      language: "json",
      schema: schemas,
      this: editor,
      value: $value
    }, {
      this: ($$value) => {
        editor = $$value;
        $$settled = false;
      },
      value: ($$value) => {
        $value = $$value;
        $$settled = false;
      }
    }, {})}</div>

		<div class="${"w-4/12 border-r-2"}" style="${"border-color: #171812;"}">${``}</div>

		<div class="${"w-4/12"}"><div class="${"w-full h-4/6"}">${validate_component(Editor, "Editor").$$render($$result, {
      language: "json",
      fontSize: "10px",
      isReadonly: true,
      value: JSON.stringify(logs.reverse(), null, 2)
    }, {}, {})}</div>

			<div class="${"w-full h-2/6 border-t-2"}" style="${"border-color: #171812;"}">${validate_component(Error, "Error").$$render($$result, { error }, {}, {})}</div></div></div>` : ``}`;
  } while (!$$settled);
  $$unsubscribe_datastore();
  $$unsubscribe_value();
  return $$rendered;
});
export { Aggregation as default };
