'use strict';

var object = require('./object-68e154cb.js');
require('json-stringify-deterministic');
require('immer');
require('crypto');
require('fs');
require('https');
require('path');

const createEmptyDocumentModelState = () => ({
  "id": "",
  "name": "",
  "extension": "",
  "description": "",
  "author": {
    "name": "",
    "website": ""
  },
  "specifications": [
    {
      "version": 1,
      "changeLog": [],
      "state": {
        "schema": "",
        "initialValue": "",
        "examples": []
      },
      "modules": []
    }
  ]
});
const dateTimeNow = (/* @__PURE__ */ new Date()).toISOString();
const createEmptyExtendedDocumentModelState = () => ({
  name: "",
  created: dateTimeNow,
  lastModified: dateTimeNow,
  documentType: "powerhouse/document-model",
  revision: 0,
  state: createEmptyDocumentModelState(),
  attachments: {}
});

// node_modules/@acaldas/document-model-graphql/dist/document-model.js
var r = (t) => t != null;
var Y = object.z.any().refine((t) => r(t));
function i() {
  return object.z.object({
    __typename: object.z.literal("AddChangeLogItemInput").optional(),
    content: object.z.string(),
    insertBefore: object.z.string().nullable()
  });
}
function o() {
  return object.z.object({
    description: object.z.string().nullish(),
    name: object.z.string()
  });
}
function a() {
  return object.z.object({
    errorCode: object.z.string().nullish(),
    errorDescription: object.z.string().nullish(),
    errorName: object.z.string().nullish(),
    errorTemplate: object.z.string().nullish(),
    operationId: object.z.string()
  });
}
function u() {
  return object.z.object({
    example: object.z.string(),
    operationId: object.z.string()
  });
}
function c() {
  return object.z.object({
    description: object.z.string().nullish(),
    moduleId: object.z.string(),
    name: object.z.string(),
    reducer: object.z.string().nullish(),
    schema: object.z.string().nullish(),
    template: object.z.string().nullish()
  });
}
function l() {
  return object.z.object({
    example: object.z.string(),
    insertBefore: object.z.string().nullish()
  });
}
function s() {
  return object.z.object({
    __typename: object.z.literal("Author").optional(),
    name: object.z.string(),
    website: object.z.string().nullable()
  });
}
function n() {
  return object.z.object({
    __typename: object.z.literal("CodeExample").optional(),
    id: object.z.string(),
    value: object.z.string()
  });
}
function p() {
  return object.z.object({
    __typename: object.z.literal("DeleteChangeLogItemInput").optional(),
    id: object.z.string()
  });
}
function m() {
  return object.z.object({
    id: object.z.string()
  });
}
function g() {
  return object.z.object({
    id: object.z.string()
  });
}
function d() {
  return object.z.object({
    id: object.z.string()
  });
}
function h() {
  return object.z.object({
    id: object.z.string()
  });
}
function S() {
  return object.z.object({
    id: object.z.string()
  });
}
function Z() {
  return object.z.union([i(), o(), a(), u(), c(), l(), p(), m(), g(), d(), h(), S(), f(), _(), O(), E(), x(), D(), M(), C(), A(), N(), L(), R(), T(), v(), w(), z2(), U(), B(), V(), W(), P(), k(), q(), F(), G(), H(), K(), Q(), X()]);
}
function $() {
  return object.z.object({
    __typename: object.z.literal("DocumentModelState").optional(),
    author: s(),
    description: object.z.string(),
    extension: object.z.string(),
    id: object.z.string(),
    name: object.z.string(),
    specifications: object.z.array(b())
  });
}
function b() {
  return object.z.object({
    __typename: object.z.literal("DocumentSpecification").optional(),
    changeLog: object.z.array(object.z.string()),
    modules: object.z.array(I()),
    state: J(),
    version: object.z.number()
  });
}
function I() {
  return object.z.object({
    __typename: object.z.literal("Module").optional(),
    description: object.z.string().nullable(),
    id: object.z.string(),
    name: object.z.string(),
    operations: object.z.array(j())
  });
}
function f() {
  return object.z.object({
    newModuleId: object.z.string(),
    operationId: object.z.string()
  });
}
function j() {
  return object.z.object({
    __typename: object.z.literal("Operation").optional(),
    description: object.z.string().nullable(),
    errors: object.z.array(y()),
    examples: object.z.array(n()),
    id: object.z.string(),
    name: object.z.string().nullable(),
    reducer: object.z.string().nullable(),
    schema: object.z.string().nullable(),
    template: object.z.string().nullable()
  });
}
function y() {
  return object.z.object({
    __typename: object.z.literal("OperationError").optional(),
    code: object.z.string().nullable(),
    description: object.z.string().nullable(),
    id: object.z.string(),
    name: object.z.string().nullable(),
    template: object.z.string().nullable()
  });
}
function _() {
  return object.z.object({
    __typename: object.z.literal("ReorderChangeLogItemsInput").optional(),
    order: object.z.array(object.z.string())
  });
}
function O() {
  return object.z.object({
    moduleId: object.z.string(),
    order: object.z.array(object.z.string())
  });
}
function E() {
  return object.z.object({
    order: object.z.array(object.z.string())
  });
}
function x() {
  return object.z.object({
    operationId: object.z.string(),
    order: object.z.array(object.z.string())
  });
}
function D() {
  return object.z.object({
    operationId: object.z.string(),
    order: object.z.array(object.z.string())
  });
}
function M() {
  return object.z.object({
    order: object.z.array(object.z.string())
  });
}
function C() {
  return object.z.object({
    authorName: object.z.string()
  });
}
function A() {
  return object.z.object({
    authorWebsite: object.z.string()
  });
}
function N() {
  return object.z.object({
    initialValue: object.z.string()
  });
}
function L() {
  return object.z.object({
    description: object.z.string()
  });
}
function R() {
  return object.z.object({
    extension: object.z.string()
  });
}
function T() {
  return object.z.object({
    id: object.z.string()
  });
}
function v() {
  return object.z.object({
    name: object.z.string()
  });
}
function w() {
  return object.z.object({
    description: object.z.string().nullish(),
    id: object.z.string()
  });
}
function z2() {
  return object.z.object({
    id: object.z.string(),
    name: object.z.string().nullish()
  });
}
function U() {
  return object.z.object({
    description: object.z.string().nullish(),
    id: object.z.string()
  });
}
function B() {
  return object.z.object({
    errorCode: object.z.string().nullish(),
    id: object.z.string()
  });
}
function V() {
  return object.z.object({
    errorDescription: object.z.string().nullish(),
    id: object.z.string()
  });
}
function W() {
  return object.z.object({
    errorName: object.z.string().nullish(),
    id: object.z.string()
  });
}
function P() {
  return object.z.object({
    errorTemplate: object.z.string().nullish(),
    id: object.z.string()
  });
}
function k() {
  return object.z.object({
    id: object.z.string(),
    name: object.z.string().nullish()
  });
}
function q() {
  return object.z.object({
    id: object.z.string(),
    reducer: object.z.string().nullish()
  });
}
function F() {
  return object.z.object({
    id: object.z.string(),
    schema: object.z.string().nullish()
  });
}
function G() {
  return object.z.object({
    id: object.z.string(),
    template: object.z.string().nullish()
  });
}
function H() {
  return object.z.object({
    schema: object.z.string()
  });
}
function J() {
  return object.z.object({
    __typename: object.z.literal("State").optional(),
    examples: object.z.array(n()),
    initialValue: object.z.string(),
    schema: object.z.string()
  });
}
function K() {
  return object.z.object({
    __typename: object.z.literal("UpdateChangeLogItemInput").optional(),
    id: object.z.string(),
    newContent: object.z.string()
  });
}
function Q() {
  return object.z.object({
    example: object.z.string(),
    id: object.z.string()
  });
}
function X() {
  return object.z.object({
    id: object.z.string(),
    newExample: object.z.string()
  });
}
var te = Object.freeze(Object.defineProperty({
  __proto__: null,
  AddChangeLogItemInputSchema: i,
  AddModuleInputSchema: o,
  AddOperationErrorInputSchema: a,
  AddOperationExampleInputSchema: u,
  AddOperationInputSchema: c,
  AddStateExampleInputSchema: l,
  AuthorSchema: s,
  CodeExampleSchema: n,
  DeleteChangeLogItemInputSchema: p,
  DeleteModuleInputSchema: m,
  DeleteOperationErrorInputSchema: g,
  DeleteOperationExampleInputSchema: d,
  DeleteOperationInputSchema: h,
  DeleteStateExampleInputSchema: S,
  DocumentModelInputSchema: Z,
  DocumentModelStateSchema: $,
  DocumentSpecificationSchema: b,
  ModuleSchema: I,
  MoveOperationInputSchema: f,
  OperationErrorSchema: y,
  OperationSchema: j,
  ReorderChangeLogItemsInputSchema: _,
  ReorderModuleOperationsInputSchema: O,
  ReorderModulesInputSchema: E,
  ReorderOperationErrorsInputSchema: x,
  ReorderOperationExamplesInputSchema: D,
  ReorderStateExamplesInputSchema: M,
  SetAuthorNameInputSchema: C,
  SetAuthorWebsiteInputSchema: A,
  SetInitialStateInputSchema: N,
  SetModelDescriptionInputSchema: L,
  SetModelExtensionInputSchema: R,
  SetModelIdInputSchema: T,
  SetModelNameInputSchema: v,
  SetModuleDescriptionInputSchema: w,
  SetModuleNameInputSchema: z2,
  SetOperationDescriptionInputSchema: U,
  SetOperationErrorCodeInputSchema: B,
  SetOperationErrorDescriptionInputSchema: V,
  SetOperationErrorNameInputSchema: W,
  SetOperationErrorTemplateInputSchema: P,
  SetOperationNameInputSchema: k,
  SetOperationReducerInputSchema: q,
  SetOperationSchemaInputSchema: F,
  SetOperationTemplateInputSchema: G,
  SetStateSchemaInputSchema: H,
  StateSchema: J,
  UpdateChangeLogItemInputSchema: K,
  UpdateOperationExampleInputSchema: Q,
  UpdateStateExampleInputSchema: X,
  definedNonNullAnySchema: Y,
  isDefinedNonNullAny: r
}, Symbol.toStringTag, { value: "Module" }));

const reducer$7 = {
  setModelNameOperation(state, action) {
    state.name = action.input.name;
  },
  setModelIdOperation(state, action) {
    state.id = action.input.id;
  },
  setModelExtensionOperation(state, action) {
    state.extension = action.input.extension;
  },
  setModelDescriptionOperation(state, action) {
    state.description = action.input.description;
  },
  setAuthorNameOperation(state, action) {
    state.author = state.author || { name: "", website: null };
    state.author.name = action.input.authorName;
  },
  setAuthorWebsiteOperation(state, action) {
    state.author = state.author || { name: "", website: null };
    state.author.website = action.input.authorWebsite;
  }
};

const reducer$6 = {
  addChangeLogItemOperation(state, action) {
    throw new Error('Reducer "addChangeLogItemOperation" not yet implemented');
  },
  updateChangeLogItemOperation(state, action) {
    throw new Error('Reducer "updateChangeLogItemOperation" not yet implemented');
  },
  deleteChangeLogItemOperation(state, action) {
    throw new Error('Reducer "deleteChangeLogItemOperation" not yet implemented');
  },
  reorderChangeLogItemsOperation(state, action) {
    throw new Error('Reducer "reorderChangeLogItemsOperation" not yet implemented');
  },
  releaseNewVersionOperation(state, action) {
    throw new Error('Reducer "releaseNewVersionOperation" not yet implemented');
  }
};

const moduleSorter = (order) => {
  const mapping = {};
  order.forEach((key, index) => mapping[key] = index);
  return (a, b) => (mapping[b.id] || 999999) - (mapping[a.id] || 999999);
};
const reducer$5 = {
  addModuleOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    latestSpec.modules.push({
      id: object.hashKey(),
      name: action.input.name,
      description: action.input.description || "",
      operations: []
    });
  },
  setModuleNameOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      if (latestSpec.modules[i].id === action.input.id) {
        latestSpec.modules[i].name = action.input.name || "";
      }
    }
  },
  setModuleDescriptionOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      if (latestSpec.modules[i].id === action.input.id) {
        latestSpec.modules[i].description = action.input.description || "";
      }
    }
  },
  deleteModuleOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    latestSpec.modules = latestSpec.modules.filter((m) => m.id != action.input.id);
  },
  reorderModulesOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    latestSpec.modules.sort(moduleSorter(action.input.order));
  }
};

const errorSorter = (order) => {
  const mapping = {};
  order.forEach((key, index) => mapping[key] = index);
  return (a, b) => (mapping[b.id] || 999999) - (mapping[a.id] || 999999);
};
const reducer$4 = {
  addOperationErrorOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      for (let j = 0; j < latestSpec.modules[i].operations.length; j++) {
        if (latestSpec.modules[i].operations[j].id == action.input.operationId) {
          latestSpec.modules[i].operations[j].errors.push({
            id: object.hashKey(),
            name: action.input.errorName || "",
            code: action.input.errorCode || "",
            description: action.input.errorDescription || "",
            template: action.input.errorTemplate || ""
          });
        }
      }
    }
  },
  setOperationErrorCodeOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      for (let j = 0; j < latestSpec.modules[i].operations.length; j++) {
        for (let k = 0; k < latestSpec.modules[i].operations[j].errors.length; k++) {
          if (latestSpec.modules[i].operations[j].errors[k].id == action.input.id) {
            latestSpec.modules[i].operations[j].errors[k].code = action.input.errorCode || "";
          }
        }
      }
    }
  },
  setOperationErrorNameOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      for (let j = 0; j < latestSpec.modules[i].operations.length; j++) {
        for (let k = 0; k < latestSpec.modules[i].operations[j].errors.length; k++) {
          if (latestSpec.modules[i].operations[j].errors[k].id == action.input.id) {
            latestSpec.modules[i].operations[j].errors[k].name = action.input.errorName || "";
          }
        }
      }
    }
  },
  setOperationErrorDescriptionOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      for (let j = 0; j < latestSpec.modules[i].operations.length; j++) {
        for (let k = 0; k < latestSpec.modules[i].operations[j].errors.length; k++) {
          if (latestSpec.modules[i].operations[j].errors[k].id == action.input.id) {
            latestSpec.modules[i].operations[j].errors[k].description = action.input.errorDescription || "";
          }
        }
      }
    }
  },
  setOperationErrorTemplateOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      for (let j = 0; j < latestSpec.modules[i].operations.length; j++) {
        for (let k = 0; k < latestSpec.modules[i].operations[j].errors.length; k++) {
          if (latestSpec.modules[i].operations[j].errors[k].id == action.input.id) {
            latestSpec.modules[i].operations[j].errors[k].template = action.input.errorTemplate || "";
          }
        }
      }
    }
  },
  deleteOperationErrorOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      for (let j = 0; j < latestSpec.modules[i].operations.length; j++) {
        latestSpec.modules[i].operations[j].errors = latestSpec.modules[i].operations[j].errors.filter((e) => e.id != action.input.id);
      }
    }
  },
  reorderOperationErrorsOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      for (let j = 0; j < latestSpec.modules[i].operations.length; j++) {
        if (latestSpec.modules[i].operations[j].id == action.input.operationId) {
          latestSpec.modules[i].operations[j].errors.sort(
            errorSorter(action.input.order)
          );
        }
      }
    }
  }
};

const exampleSorter$1 = (order) => {
  const mapping = {};
  order.forEach((key, index) => mapping[key] = index);
  return (a, b) => (mapping[b.id] || 999999) - (mapping[a.id] || 999999);
};
const reducer$3 = {
  addOperationExampleOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      for (let j = 0; j < latestSpec.modules[i].operations.length; j++) {
        if (latestSpec.modules[i].operations[j].id == action.input.operationId) {
          latestSpec.modules[i].operations[j].examples.push({
            id: object.hashKey(),
            value: action.input.example
          });
        }
      }
    }
  },
  updateOperationExampleOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      for (let j = 0; j < latestSpec.modules[i].operations.length; j++) {
        for (let k = 0; k < latestSpec.modules[i].operations[j].examples.length; k++) {
          if (latestSpec.modules[i].operations[j].examples[k].id == action.input.id) {
            latestSpec.modules[i].operations[j].examples[k].value = action.input.example;
          }
        }
      }
    }
  },
  deleteOperationExampleOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      for (let j = 0; j < latestSpec.modules[i].operations.length; j++) {
        latestSpec.modules[i].operations[j].examples = latestSpec.modules[i].operations[j].examples.filter((e) => e.id != action.input.id);
      }
    }
  },
  reorderOperationExamplesOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      for (let j = 0; j < latestSpec.modules[i].operations.length; j++) {
        if (latestSpec.modules[i].operations[j].id == action.input.operationId) {
          latestSpec.modules[i].operations[j].examples.sort(
            exampleSorter$1(action.input.order)
          );
        }
      }
    }
  }
};

const operationSorter = (order) => {
  const mapping = {};
  order.forEach((key, index) => mapping[key] = index);
  return (a, b) => (mapping[b.id] || 999999) - (mapping[a.id] || 999999);
};
const reducer$2 = {
  addOperationOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      if (latestSpec.modules[i].id == action.input.moduleId) {
        latestSpec.modules[i].operations.push({
          id: object.hashKey(),
          name: action.input.name,
          description: action.input.description || "",
          schema: action.input.schema || "",
          template: action.input.template || action.input.description || "",
          reducer: action.input.reducer || "",
          errors: [],
          examples: []
        });
      }
    }
  },
  setOperationNameOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      for (let j = 0; j < latestSpec.modules[i].operations.length; j++) {
        if (latestSpec.modules[i].operations[j].id == action.input.id) {
          latestSpec.modules[i].operations[j].name = action.input.name || "";
        }
      }
    }
  },
  setOperationSchemaOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      for (let j = 0; j < latestSpec.modules[i].operations.length; j++) {
        if (latestSpec.modules[i].operations[j].id == action.input.id) {
          latestSpec.modules[i].operations[j].schema = action.input.schema || "";
        }
      }
    }
  },
  setOperationDescriptionOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      for (let j = 0; j < latestSpec.modules[i].operations.length; j++) {
        if (latestSpec.modules[i].operations[j].id == action.input.id) {
          latestSpec.modules[i].operations[j].description = action.input.description || "";
        }
      }
    }
  },
  setOperationTemplateOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      for (let j = 0; j < latestSpec.modules[i].operations.length; j++) {
        if (latestSpec.modules[i].operations[j].id == action.input.id) {
          latestSpec.modules[i].operations[j].template = action.input.template || "";
        }
      }
    }
  },
  setOperationReducerOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      for (let j = 0; j < latestSpec.modules[i].operations.length; j++) {
        if (latestSpec.modules[i].operations[j].id == action.input.id) {
          latestSpec.modules[i].operations[j].reducer = action.input.reducer || "";
        }
      }
    }
  },
  moveOperationOperation(state, action) {
    const moveOperations = [];
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      latestSpec.modules[i].operations = latestSpec.modules[i].operations.filter(
        (operation) => {
          if (operation.id == action.input.operationId) {
            moveOperations.push(operation);
            return false;
          }
          return true;
        }
      );
    }
    for (let i = 0; i < latestSpec.modules.length; i++) {
      if (latestSpec.modules[i].id == action.input.newModuleId) {
        latestSpec.modules[i].operations.push(...moveOperations);
      }
    }
  },
  deleteOperationOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      latestSpec.modules[i].operations = latestSpec.modules[i].operations.filter(
        (operation) => operation.id != action.input.id
      );
    }
  },
  reorderModuleOperationsOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.modules.length; i++) {
      if (latestSpec.modules[i].id == action.input.moduleId) {
        latestSpec.modules[i].operations.sort(
          operationSorter(action.input.order)
        );
      }
    }
  }
};

const exampleSorter = (order) => {
  const mapping = {};
  order.forEach((key, index) => mapping[key] = index);
  return (a, b) => (mapping[b.id] || 999999) - (mapping[a.id] || 999999);
};
const reducer$1 = {
  setStateSchemaOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    latestSpec.state.schema = action.input.schema;
  },
  setInitialStateOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    latestSpec.state.initialValue = action.input.initialValue;
  },
  addStateExampleOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    latestSpec.state.examples.push({
      id: object.hashKey(),
      value: action.input.example
    });
  },
  updateStateExampleOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    for (let i = 0; i < latestSpec.state.examples.length; i++) {
      if (latestSpec.state.examples[i].id == action.input.id) {
        latestSpec.state.examples[i].value = action.input.newExample;
      }
    }
  },
  deleteStateExampleOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    latestSpec.state.examples = latestSpec.state.examples.filter(
      (e) => e.id != action.input.id
    );
  },
  reorderStateExamplesOperation(state, action) {
    const latestSpec = state.specifications[state.specifications.length - 1];
    latestSpec.state.examples.sort(exampleSorter(action.input.order));
  }
};

const stateReducer = (state, action) => {
  if (object.isBaseAction(action)) {
    return state;
  }
  switch (action.type) {
    case "SET_MODEL_NAME":
      te.SetModelNameInputSchema().parse(action.input);
      reducer$7.setModelNameOperation(state, action);
      break;
    case "SET_MODEL_ID":
      te.SetModelIdInputSchema().parse(action.input);
      reducer$7.setModelIdOperation(state, action);
      break;
    case "SET_MODEL_EXTENSION":
      te.SetModelExtensionInputSchema().parse(action.input);
      reducer$7.setModelExtensionOperation(state, action);
      break;
    case "SET_MODEL_DESCRIPTION":
      te.SetModelDescriptionInputSchema().parse(action.input);
      reducer$7.setModelDescriptionOperation(state, action);
      break;
    case "SET_AUTHOR_NAME":
      te.SetAuthorNameInputSchema().parse(action.input);
      reducer$7.setAuthorNameOperation(state, action);
      break;
    case "SET_AUTHOR_WEBSITE":
      te.SetAuthorWebsiteInputSchema().parse(action.input);
      reducer$7.setAuthorWebsiteOperation(state, action);
      break;
    case "ADD_CHANGE_LOG_ITEM":
      te.AddChangeLogItemInputSchema().parse(action.input);
      reducer$6.addChangeLogItemOperation(state, action);
      break;
    case "UPDATE_CHANGE_LOG_ITEM":
      te.UpdateChangeLogItemInputSchema().parse(action.input);
      reducer$6.updateChangeLogItemOperation(state, action);
      break;
    case "DELETE_CHANGE_LOG_ITEM":
      te.DeleteChangeLogItemInputSchema().parse(action.input);
      reducer$6.deleteChangeLogItemOperation(state, action);
      break;
    case "REORDER_CHANGE_LOG_ITEMS":
      te.ReorderChangeLogItemsInputSchema().parse(action.input);
      reducer$6.reorderChangeLogItemsOperation(state, action);
      break;
    case "RELEASE_NEW_VERSION":
      if (Object.keys(action.input).length > 0)
        throw new Error("Expected empty input for action RELEASE_NEW_VERSION");
      reducer$6.releaseNewVersionOperation(state, action);
      break;
    case "ADD_MODULE":
      te.AddModuleInputSchema().parse(action.input);
      reducer$5.addModuleOperation(state, action);
      break;
    case "SET_MODULE_NAME":
      te.SetModuleNameInputSchema().parse(action.input);
      reducer$5.setModuleNameOperation(state, action);
      break;
    case "SET_MODULE_DESCRIPTION":
      te.SetModuleDescriptionInputSchema().parse(action.input);
      reducer$5.setModuleDescriptionOperation(state, action);
      break;
    case "DELETE_MODULE":
      te.DeleteModuleInputSchema().parse(action.input);
      reducer$5.deleteModuleOperation(state, action);
      break;
    case "REORDER_MODULES":
      te.ReorderModulesInputSchema().parse(action.input);
      reducer$5.reorderModulesOperation(state, action);
      break;
    case "ADD_OPERATION_ERROR":
      te.AddOperationErrorInputSchema().parse(action.input);
      reducer$4.addOperationErrorOperation(state, action);
      break;
    case "SET_OPERATION_ERROR_CODE":
      te.SetOperationErrorCodeInputSchema().parse(action.input);
      reducer$4.setOperationErrorCodeOperation(state, action);
      break;
    case "SET_OPERATION_ERROR_NAME":
      te.SetOperationErrorNameInputSchema().parse(action.input);
      reducer$4.setOperationErrorNameOperation(state, action);
      break;
    case "SET_OPERATION_ERROR_DESCRIPTION":
      te.SetOperationErrorDescriptionInputSchema().parse(action.input);
      reducer$4.setOperationErrorDescriptionOperation(state, action);
      break;
    case "SET_OPERATION_ERROR_TEMPLATE":
      te.SetOperationErrorTemplateInputSchema().parse(action.input);
      reducer$4.setOperationErrorTemplateOperation(state, action);
      break;
    case "DELETE_OPERATION_ERROR":
      te.DeleteOperationErrorInputSchema().parse(action.input);
      reducer$4.deleteOperationErrorOperation(state, action);
      break;
    case "REORDER_OPERATION_ERRORS":
      te.ReorderOperationErrorsInputSchema().parse(action.input);
      reducer$4.reorderOperationErrorsOperation(state, action);
      break;
    case "ADD_OPERATION_EXAMPLE":
      te.AddOperationExampleInputSchema().parse(action.input);
      reducer$3.addOperationExampleOperation(state, action);
      break;
    case "UPDATE_OPERATION_EXAMPLE":
      te.UpdateOperationExampleInputSchema().parse(action.input);
      reducer$3.updateOperationExampleOperation(state, action);
      break;
    case "DELETE_OPERATION_EXAMPLE":
      te.DeleteOperationExampleInputSchema().parse(action.input);
      reducer$3.deleteOperationExampleOperation(state, action);
      break;
    case "REORDER_OPERATION_EXAMPLES":
      te.ReorderOperationExamplesInputSchema().parse(action.input);
      reducer$3.reorderOperationExamplesOperation(state, action);
      break;
    case "ADD_OPERATION":
      te.AddOperationInputSchema().parse(action.input);
      reducer$2.addOperationOperation(state, action);
      break;
    case "SET_OPERATION_NAME":
      te.SetOperationNameInputSchema().parse(action.input);
      reducer$2.setOperationNameOperation(state, action);
      break;
    case "SET_OPERATION_SCHEMA":
      te.SetOperationSchemaInputSchema().parse(action.input);
      reducer$2.setOperationSchemaOperation(state, action);
      break;
    case "SET_OPERATION_DESCRIPTION":
      te.SetOperationDescriptionInputSchema().parse(action.input);
      reducer$2.setOperationDescriptionOperation(state, action);
      break;
    case "SET_OPERATION_TEMPLATE":
      te.SetOperationTemplateInputSchema().parse(action.input);
      reducer$2.setOperationTemplateOperation(state, action);
      break;
    case "SET_OPERATION_REDUCER":
      te.SetOperationReducerInputSchema().parse(action.input);
      reducer$2.setOperationReducerOperation(state, action);
      break;
    case "MOVE_OPERATION":
      te.MoveOperationInputSchema().parse(action.input);
      reducer$2.moveOperationOperation(state, action);
      break;
    case "DELETE_OPERATION":
      te.DeleteOperationInputSchema().parse(action.input);
      reducer$2.deleteOperationOperation(state, action);
      break;
    case "REORDER_MODULE_OPERATIONS":
      te.ReorderModuleOperationsInputSchema().parse(action.input);
      reducer$2.reorderModuleOperationsOperation(state, action);
      break;
    case "SET_STATE_SCHEMA":
      te.SetStateSchemaInputSchema().parse(action.input);
      reducer$1.setStateSchemaOperation(state, action);
      break;
    case "SET_INITIAL_STATE":
      te.SetInitialStateInputSchema().parse(action.input);
      reducer$1.setInitialStateOperation(state, action);
      break;
    case "ADD_STATE_EXAMPLE":
      te.AddStateExampleInputSchema().parse(action.input);
      reducer$1.addStateExampleOperation(state, action);
      break;
    case "UPDATE_STATE_EXAMPLE":
      te.UpdateStateExampleInputSchema().parse(action.input);
      reducer$1.updateStateExampleOperation(state, action);
      break;
    case "DELETE_STATE_EXAMPLE":
      te.DeleteStateExampleInputSchema().parse(action.input);
      reducer$1.deleteStateExampleOperation(state, action);
      break;
    case "REORDER_STATE_EXAMPLES":
      te.ReorderStateExamplesInputSchema().parse(action.input);
      reducer$1.reorderStateExamplesOperation(state, action);
      break;
    default:
      return state;
  }
};
const reducer = object.createReducer(stateReducer);

const setModelName = (input) => object.createAction(
  "SET_MODEL_NAME",
  { ...input }
);
const setModelId = (input) => object.createAction(
  "SET_MODEL_ID",
  { ...input }
);
const setModelExtension = (input) => object.createAction(
  "SET_MODEL_EXTENSION",
  { ...input }
);
const setModelDescription = (input) => object.createAction(
  "SET_MODEL_DESCRIPTION",
  { ...input }
);
const setAuthorName = (input) => object.createAction(
  "SET_AUTHOR_NAME",
  { ...input }
);
const setAuthorWebsite = (input) => object.createAction(
  "SET_AUTHOR_WEBSITE",
  { ...input }
);

class DocumentModel_Header extends object.BaseDocument {
  setModelName(input) {
    return this.dispatch(setModelName(input));
  }
  setModelId(input) {
    return this.dispatch(setModelId(input));
  }
  setModelExtension(input) {
    return this.dispatch(setModelExtension(input));
  }
  setModelDescription(input) {
    return this.dispatch(setModelDescription(input));
  }
  setAuthorName(input) {
    return this.dispatch(setAuthorName(input));
  }
  setAuthorWebsite(input) {
    return this.dispatch(setAuthorWebsite(input));
  }
}

const addChangeLogItem = (input) => object.createAction(
  "ADD_CHANGE_LOG_ITEM",
  { ...input }
);
const updateChangeLogItem = (input) => object.createAction(
  "UPDATE_CHANGE_LOG_ITEM",
  { ...input }
);
const deleteChangeLogItem = (input) => object.createAction(
  "DELETE_CHANGE_LOG_ITEM",
  { ...input }
);
const reorderChangeLogItems = (input) => object.createAction(
  "REORDER_CHANGE_LOG_ITEMS",
  { ...input }
);
const releaseNewVersion = () => object.createAction("RELEASE_NEW_VERSION");

class DocumentModel_Versioning extends object.BaseDocument {
  addChangeLogItem(input) {
    return this.dispatch(addChangeLogItem(input));
  }
  updateChangeLogItem(input) {
    return this.dispatch(updateChangeLogItem(input));
  }
  deleteChangeLogItem(input) {
    return this.dispatch(deleteChangeLogItem(input));
  }
  reorderChangeLogItems(input) {
    return this.dispatch(reorderChangeLogItems(input));
  }
  releaseNewVersion() {
    return this.dispatch(releaseNewVersion());
  }
}

const addModule = (input) => object.createAction(
  "ADD_MODULE",
  { ...input }
);
const setModuleName = (input) => object.createAction(
  "SET_MODULE_NAME",
  { ...input }
);
const setModuleDescription = (input) => object.createAction(
  "SET_MODULE_DESCRIPTION",
  { ...input }
);
const deleteModule = (input) => object.createAction(
  "DELETE_MODULE",
  { ...input }
);
const reorderModules = (input) => object.createAction(
  "REORDER_MODULES",
  { ...input }
);

class DocumentModel_Module extends object.BaseDocument {
  addModule(input) {
    return this.dispatch(addModule(input));
  }
  setModuleName(input) {
    return this.dispatch(setModuleName(input));
  }
  setModuleDescription(input) {
    return this.dispatch(setModuleDescription(input));
  }
  deleteModule(input) {
    return this.dispatch(deleteModule(input));
  }
  reorderModules(input) {
    return this.dispatch(reorderModules(input));
  }
}

const addOperationError = (input) => object.createAction(
  "ADD_OPERATION_ERROR",
  { ...input }
);
const setOperationErrorCode = (input) => object.createAction(
  "SET_OPERATION_ERROR_CODE",
  { ...input }
);
const setOperationErrorName = (input) => object.createAction(
  "SET_OPERATION_ERROR_NAME",
  { ...input }
);
const setOperationErrorDescription = (input) => object.createAction(
  "SET_OPERATION_ERROR_DESCRIPTION",
  { ...input }
);
const setOperationErrorTemplate = (input) => object.createAction(
  "SET_OPERATION_ERROR_TEMPLATE",
  { ...input }
);
const deleteOperationError = (input) => object.createAction(
  "DELETE_OPERATION_ERROR",
  { ...input }
);
const reorderOperationErrors = (input) => object.createAction(
  "REORDER_OPERATION_ERRORS",
  { ...input }
);

class DocumentModel_OperationError extends object.BaseDocument {
  addOperationError(input) {
    return this.dispatch(addOperationError(input));
  }
  setOperationErrorCode(input) {
    return this.dispatch(setOperationErrorCode(input));
  }
  setOperationErrorName(input) {
    return this.dispatch(setOperationErrorName(input));
  }
  setOperationErrorDescription(input) {
    return this.dispatch(setOperationErrorDescription(input));
  }
  setOperationErrorTemplate(input) {
    return this.dispatch(setOperationErrorTemplate(input));
  }
  deleteOperationError(input) {
    return this.dispatch(deleteOperationError(input));
  }
  reorderOperationErrors(input) {
    return this.dispatch(reorderOperationErrors(input));
  }
}

const addOperationExample = (input) => object.createAction(
  "ADD_OPERATION_EXAMPLE",
  { ...input }
);
const updateOperationExample = (input) => object.createAction(
  "UPDATE_OPERATION_EXAMPLE",
  { ...input }
);
const deleteOperationExample = (input) => object.createAction(
  "DELETE_OPERATION_EXAMPLE",
  { ...input }
);
const reorderOperationExamples = (input) => object.createAction(
  "REORDER_OPERATION_EXAMPLES",
  { ...input }
);

class DocumentModel_OperationExample extends object.BaseDocument {
  addOperationExample(input) {
    return this.dispatch(addOperationExample(input));
  }
  updateOperationExample(input) {
    return this.dispatch(updateOperationExample(input));
  }
  deleteOperationExample(input) {
    return this.dispatch(deleteOperationExample(input));
  }
  reorderOperationExamples(input) {
    return this.dispatch(reorderOperationExamples(input));
  }
}

const addOperation = (input) => object.createAction(
  "ADD_OPERATION",
  { ...input }
);
const setOperationName = (input) => object.createAction(
  "SET_OPERATION_NAME",
  { ...input }
);
const setOperationSchema = (input) => object.createAction(
  "SET_OPERATION_SCHEMA",
  { ...input }
);
const setOperationDescription = (input) => object.createAction(
  "SET_OPERATION_DESCRIPTION",
  { ...input }
);
const setOperationTemplate = (input) => object.createAction(
  "SET_OPERATION_TEMPLATE",
  { ...input }
);
const setOperationReducer = (input) => object.createAction(
  "SET_OPERATION_REDUCER",
  { ...input }
);
const moveOperation = (input) => object.createAction(
  "MOVE_OPERATION",
  { ...input }
);
const deleteOperation = (input) => object.createAction(
  "DELETE_OPERATION",
  { ...input }
);
const reorderModuleOperations = (input) => object.createAction(
  "REORDER_MODULE_OPERATIONS",
  { ...input }
);

class DocumentModel_Operation extends object.BaseDocument {
  addOperation(input) {
    return this.dispatch(addOperation(input));
  }
  setOperationName(input) {
    return this.dispatch(setOperationName(input));
  }
  setOperationSchema(input) {
    return this.dispatch(setOperationSchema(input));
  }
  setOperationDescription(input) {
    return this.dispatch(setOperationDescription(input));
  }
  setOperationTemplate(input) {
    return this.dispatch(setOperationTemplate(input));
  }
  setOperationReducer(input) {
    return this.dispatch(setOperationReducer(input));
  }
  moveOperation(input) {
    return this.dispatch(moveOperation(input));
  }
  deleteOperation(input) {
    return this.dispatch(deleteOperation(input));
  }
  reorderModuleOperations(input) {
    return this.dispatch(reorderModuleOperations(input));
  }
}

const setStateSchema = (input) => object.createAction(
  "SET_STATE_SCHEMA",
  { ...input }
);
const setInitialState = (input) => object.createAction(
  "SET_INITIAL_STATE",
  { ...input }
);
const addStateExample = (input) => object.createAction(
  "ADD_STATE_EXAMPLE",
  { ...input }
);
const updateStateExample = (input) => object.createAction(
  "UPDATE_STATE_EXAMPLE",
  { ...input }
);
const deleteStateExample = (input) => object.createAction(
  "DELETE_STATE_EXAMPLE",
  { ...input }
);
const reorderStateExamples = (input) => object.createAction(
  "REORDER_STATE_EXAMPLES",
  { ...input }
);

class DocumentModel_State extends object.BaseDocument {
  setStateSchema(input) {
    return this.dispatch(setStateSchema(input));
  }
  setInitialState(input) {
    return this.dispatch(setInitialState(input));
  }
  addStateExample(input) {
    return this.dispatch(addStateExample(input));
  }
  updateStateExample(input) {
    return this.dispatch(updateStateExample(input));
  }
  deleteStateExample(input) {
    return this.dispatch(deleteStateExample(input));
  }
  reorderStateExamples(input) {
    return this.dispatch(reorderStateExamples(input));
  }
}

let DocumentModel$2 = class DocumentModel extends object.BaseDocument {
  static fileExtension = "phdm";
  constructor(initialState) {
    super(reducer, initialState || createEmptyExtendedDocumentModelState());
  }
  saveToFile(path, name) {
    return super.saveToFile(path, DocumentModel.fileExtension, name);
  }
  loadFromFile(path) {
    return super.loadFromFile(path);
  }
  static async fromFile(path) {
    const document = new this();
    await document.loadFromFile(path);
    return document;
  }
};
object.applyMixins(DocumentModel$2, [
  DocumentModel_Header,
  DocumentModel_Versioning,
  DocumentModel_Module,
  DocumentModel_OperationError,
  DocumentModel_OperationExample,
  DocumentModel_Operation,
  DocumentModel_State
]);

var gen = /*#__PURE__*/Object.freeze({
    __proto__: null,
    DocumentModel: DocumentModel$2,
    addChangeLogItem: addChangeLogItem,
    addModule: addModule,
    addOperation: addOperation,
    addOperationError: addOperationError,
    addOperationExample: addOperationExample,
    addStateExample: addStateExample,
    deleteChangeLogItem: deleteChangeLogItem,
    deleteModule: deleteModule,
    deleteOperation: deleteOperation,
    deleteOperationError: deleteOperationError,
    deleteOperationExample: deleteOperationExample,
    deleteStateExample: deleteStateExample,
    moveOperation: moveOperation,
    releaseNewVersion: releaseNewVersion,
    reorderChangeLogItems: reorderChangeLogItems,
    reorderModuleOperations: reorderModuleOperations,
    reorderModules: reorderModules,
    reorderOperationErrors: reorderOperationErrors,
    reorderOperationExamples: reorderOperationExamples,
    reorderStateExamples: reorderStateExamples,
    setAuthorName: setAuthorName,
    setAuthorWebsite: setAuthorWebsite,
    setInitialState: setInitialState,
    setModelDescription: setModelDescription,
    setModelExtension: setModelExtension,
    setModelId: setModelId,
    setModelName: setModelName,
    setModuleDescription: setModuleDescription,
    setModuleName: setModuleName,
    setOperationDescription: setOperationDescription,
    setOperationErrorCode: setOperationErrorCode,
    setOperationErrorDescription: setOperationErrorDescription,
    setOperationErrorName: setOperationErrorName,
    setOperationErrorTemplate: setOperationErrorTemplate,
    setOperationName: setOperationName,
    setOperationReducer: setOperationReducer,
    setOperationSchema: setOperationSchema,
    setOperationTemplate: setOperationTemplate,
    setStateSchema: setStateSchema,
    updateChangeLogItem: updateChangeLogItem,
    updateOperationExample: updateOperationExample,
    updateStateExample: updateStateExample
});

const { DocumentModel, ...DocumentModelActions } = gen;
const actions = { ...object.BaseActions, ...DocumentModelActions };

var DocumentModel$1 = /*#__PURE__*/Object.freeze({
    __proto__: null,
    DocumentModel: DocumentModel,
    actions: actions,
    createEmptyDocumentModelState: createEmptyDocumentModelState,
    createEmptyExtendedDocumentModelState: createEmptyExtendedDocumentModelState,
    reducer: reducer
});

exports.DocumentModel = DocumentModel$1;
exports.DocumentModel$1 = DocumentModel;
exports.actions = actions;
exports.createEmptyDocumentModelState = createEmptyDocumentModelState;
exports.createEmptyExtendedDocumentModelState = createEmptyExtendedDocumentModelState;
exports.reducer = reducer;
//# sourceMappingURL=index-193ebabd.js.map
