document-model 1.0.15 → 1.0.17

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.
Files changed (57) hide show
  1. package/dist/browser/document/actions/creators.d.ts +1 -1
  2. package/dist/browser/document/actions/index.d.ts +8 -8
  3. package/dist/browser/document/object.d.ts +123 -99
  4. package/dist/browser/document/reducer.d.ts +1 -1
  5. package/dist/browser/document/schema/types.d.ts +5 -0
  6. package/dist/browser/document/schema/zod.d.ts +39 -0
  7. package/dist/browser/document/types.d.ts +41 -31
  8. package/dist/browser/document/utils/base.d.ts +6 -6
  9. package/dist/browser/document/utils/file.d.ts +2 -2
  10. package/dist/browser/document-model/gen/object.d.ts +1 -1
  11. package/dist/browser/document-model/gen/reducer.d.ts +1 -1
  12. package/dist/browser/document-model/gen/schema/types.d.ts +13 -3
  13. package/dist/browser/document-model/gen/schema/zod.d.ts +20 -1
  14. package/dist/browser/document-model/index.d.ts +9 -9
  15. package/dist/browser/document-model.cjs +1 -1
  16. package/dist/browser/document-model.js +2 -2
  17. package/dist/browser/document.cjs +1 -1
  18. package/dist/browser/document.js +2 -2
  19. package/dist/browser/index.cjs +1 -1
  20. package/dist/browser/index.js +3 -3
  21. package/dist/browser/internal/index-01030c3f.js +22 -0
  22. package/dist/{node/internal/index-c9d178be.js → browser/internal/index-2aee8ea9.js} +1 -1
  23. package/dist/browser/internal/{index-8142b58e.js → index-5f1909ad.js} +513 -435
  24. package/dist/{node/internal/index-0b0cb8c2.js → browser/internal/index-a1282d5c.js} +1 -1
  25. package/dist/browser/internal/object-24df9d92.js +6 -0
  26. package/dist/browser/internal/{object-4ec03a36.js → object-7e8eaff4.js} +777 -731
  27. package/dist/node/document/actions/creators.d.ts +1 -1
  28. package/dist/node/document/actions/index.d.ts +8 -8
  29. package/dist/node/document/object.d.ts +123 -99
  30. package/dist/node/document/reducer.d.ts +1 -1
  31. package/dist/node/document/schema/types.d.ts +5 -0
  32. package/dist/node/document/schema/zod.d.ts +39 -0
  33. package/dist/node/document/types.d.ts +41 -31
  34. package/dist/node/document/utils/base.d.ts +6 -6
  35. package/dist/node/document/utils/file.d.ts +2 -2
  36. package/dist/node/document-model/gen/object.d.ts +1 -1
  37. package/dist/node/document-model/gen/reducer.d.ts +1 -1
  38. package/dist/node/document-model/gen/schema/types.d.ts +13 -3
  39. package/dist/node/document-model/gen/schema/zod.d.ts +20 -1
  40. package/dist/node/document-model/index.d.ts +9 -9
  41. package/dist/node/document-model.cjs +1 -1
  42. package/dist/node/document-model.js +2 -2
  43. package/dist/node/document.cjs +1 -1
  44. package/dist/node/document.js +2 -2
  45. package/dist/node/index.cjs +1 -1
  46. package/dist/node/index.js +3 -3
  47. package/dist/node/internal/{index-0c87fbed.js → index-0db636da.js} +513 -435
  48. package/dist/{browser/internal/index-cb990484.js → node/internal/index-2d4783d9.js} +1 -1
  49. package/dist/{browser/internal/index-9f1cf811.js → node/internal/index-5ef0c6b0.js} +1 -1
  50. package/dist/node/internal/index-cddc9dfd.js +22 -0
  51. package/dist/node/internal/object-21f3d2ee.js +1 -0
  52. package/dist/node/internal/{object-89d9b82f.js → object-c32ea0a0.js} +400 -356
  53. package/package.json +3 -3
  54. package/dist/browser/internal/index-cbe39f72.js +0 -22
  55. package/dist/browser/internal/object-5f03095e.js +0 -6
  56. package/dist/node/internal/index-63db4708.js +0 -22
  57. package/dist/node/internal/object-397a9b23.js +0 -1
@@ -1 +1 @@
1
- "use strict";const e=require("./object-5f03095e.js"),t=Object.freeze(Object.defineProperty({__proto__:null,createAction:e.createAction,createDocument:e.createDocument,createExtendedState:e.createExtendedState,createReducer:e.createReducer,createZip:e.createZip,getLocalFile:e.getLocalFile,getRemoteFile:e.getRemoteFile,hashDocument:e.hashDocument,hashKey:e.hashKey,isBaseAction:e.isBaseAction,loadFromFile:e.loadFromFile,loadFromInput:e.loadFromInput,readOnly:e.readOnly,saveToFile:e.saveToFile,saveToFileHandle:e.saveToFileHandle},Symbol.toStringTag,{value:"Module"})),o=Object.freeze(Object.defineProperty({__proto__:null,BaseDocument:e.BaseDocument,actions:e.BaseActions,applyMixins:e.applyMixins,baseReducer:e.baseReducer,utils:t,z:e.zod},Symbol.toStringTag,{value:"Module"}));exports.Document=o;exports.index=t;
1
+ "use strict";const e=require("./object-21f3d2ee.js"),t=Object.freeze(Object.defineProperty({__proto__:null,createAction:e.createAction,createDocument:e.createDocument,createExtendedState:e.createExtendedState,createReducer:e.createReducer,createZip:e.createZip,getLocalFile:e.getLocalFile,getRemoteFile:e.getRemoteFile,hashDocument:e.hashDocument,hashKey:e.hashKey,isBaseAction:e.isBaseAction,loadFromFile:e.loadFromFile,loadFromInput:e.loadFromInput,readOnly:e.readOnly,saveToFile:e.saveToFile,saveToFileHandle:e.saveToFileHandle},Symbol.toStringTag,{value:"Module"})),o=Object.freeze(Object.defineProperty({__proto__:null,BaseDocument:e.BaseDocument,actions:e.BaseActions,applyMixins:e.applyMixins,baseReducer:e.baseReducer,utils:t,z:e.zod},Symbol.toStringTag,{value:"Module"}));exports.Document=o;exports.index=t;
@@ -1,4 +1,4 @@
1
- import { f as e, b as a, a as s, c as t, j as o, k as r, m as c, n as l, o as n, i, l as d, e as u, r as m, s as p, d as b, B as _, h as g, g as y, p as F, z as f } from "./object-4ec03a36.js";
1
+ import { f as e, b as a, a as s, c as t, j as o, k as r, m as c, n as l, o as n, i, l as d, e as u, r as m, s as p, d as b, B as _, h as g, g as y, p as F, z as f } from "./object-c32ea0a0.js";
2
2
  const h = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3
3
  __proto__: null,
4
4
  createAction: e,
@@ -0,0 +1,22 @@
1
+ "use strict";var ut=Object.defineProperty;var mt=(t,e,o)=>e in t?ut(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var ue=(t,e,o)=>(mt(t,typeof e!="symbol"?e+"":e,o),o);const s=require("./object-21f3d2ee.js");require("json-stringify-deterministic");require("immer");require("crypto");require("fs");require("https");require("path");require("jszip");const r=require("zod"),Et=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),f={id:"powerhouse/document-model",name:"DocumentModel",extension:"phdm",description:"The Powerhouse Document Model describes the state and operations of a document type.",author:{name:"Powerhouse",website:"https://www.powerhouse.inc/"},specifications:[{version:1,changeLog:[],modules:[{name:"header",operations:[{name:"SetModelName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModelId",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModelExtension",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModelDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetAuthorName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetAuthorWebsite",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"versioning",operations:[{name:"AddChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"UpdateChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderChangeLogItems",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReleaseNewVersion",schema:null,id:"",description:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"module",operations:[{name:"AddModule",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModuleName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModuleDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteModule",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderModules",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"operation-error",operations:[{name:"AddOperationError",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationErrorCode",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationErrorName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationErrorDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationErrorTemplate",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteOperationError",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderOperationErrors",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"operation-example",operations:[{name:"AddOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"UpdateOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderOperationExamples",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"operation",operations:[{name:"AddOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationSchema",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationTemplate",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationReducer",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"MoveOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderModuleOperations",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"state",operations:[{name:"SetStateSchema",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetInitialState",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"AddStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"UpdateStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderStateExamples",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""}],state:{global:{schema:"",initialValue:`{
2
+ "id": "",
3
+ "name": "",
4
+ "extension": "",
5
+ "description": "",
6
+ "author": {
7
+ "name": "",
8
+ "website": ""
9
+ },
10
+ "specifications": [
11
+ {
12
+ "version": 1,
13
+ "changeLog": [],
14
+ "state": {
15
+ "schema": "",
16
+ "initialValue": "",
17
+ "examples": []
18
+ },
19
+ "modules": []
20
+ }
21
+ ]
22
+ }`,examples:[]},local:{schema:"",initialValue:"{}",examples:[]}}}]},me=t=>t!=null,ht=r.z.any().refine(t=>me(t));function _(){return r.z.object({__typename:r.z.literal("AddChangeLogItemInput").optional(),content:r.z.string(),id:r.z.string(),insertBefore:r.z.string().nullable()})}function z(){return r.z.object({description:r.z.string().nullish(),id:r.z.string(),name:r.z.string()})}function A(){return r.z.object({errorCode:r.z.string().nullish(),errorDescription:r.z.string().nullish(),errorName:r.z.string().nullish(),errorTemplate:r.z.string().nullish(),id:r.z.string(),operationId:r.z.string()})}function I(){return r.z.object({example:r.z.string(),id:r.z.string(),operationId:r.z.string()})}function T(){return r.z.object({description:r.z.string().nullish(),id:r.z.string(),moduleId:r.z.string(),name:r.z.string(),reducer:r.z.string().nullish(),schema:r.z.string().nullish(),template:r.z.string().nullish(),scope:r.z.literal("local").or(r.z.literal("global")).nullish()})}function R(){return r.z.object({scope:r.z.string(),example:r.z.string(),id:r.z.string(),insertBefore:r.z.string().nullish()})}function Ee(){return r.z.object({__typename:r.z.literal("Author").optional(),name:r.z.string(),website:r.z.string().nullable()})}function D(){return r.z.object({__typename:r.z.literal("CodeExample").optional(),id:r.z.string(),value:r.z.string()})}function M(){return r.z.object({__typename:r.z.literal("DeleteChangeLogItemInput").optional(),id:r.z.string()})}function x(){return r.z.object({id:r.z.string()})}function N(){return r.z.object({id:r.z.string()})}function L(){return r.z.object({id:r.z.string()})}function j(){return r.z.object({id:r.z.string()})}function P(){return r.z.object({scope:r.z.string(),id:r.z.string()})}function Ot(){return r.z.union([_(),z(),A(),I(),T(),R(),M(),x(),N(),L(),j(),P(),C(),k(),y(),w(),v(),U(),V(),F(),H(),$(),X(),G(),B(),W(),q(),J(),K(),Q(),Y(),Z(),ee(),te(),re(),oe(),ne(),ie(),se(),ae(),pe()])}function gt(){return r.z.object({__typename:r.z.literal("DocumentModelState").optional(),author:Ee(),description:r.z.string(),extension:r.z.string(),id:r.z.string(),name:r.z.string(),specifications:r.z.array(he())})}function he(){return r.z.object({__typename:r.z.literal("DocumentSpecification").optional(),changeLog:r.z.array(r.z.string()),modules:r.z.array(Oe()),state:fe(),version:r.z.number()})}function Oe(){return r.z.object({__typename:r.z.literal("Module").optional(),description:r.z.string().nullable(),id:r.z.string(),name:r.z.string(),operations:r.z.array(ge())})}function C(){return r.z.object({newModuleId:r.z.string(),operationId:r.z.string()})}function ge(){return r.z.object({__typename:r.z.literal("Operation").optional(),description:r.z.string().nullable(),errors:r.z.array(Se()),examples:r.z.array(D()),id:r.z.string(),name:r.z.string().nullable(),reducer:r.z.string().nullable(),schema:r.z.string().nullable(),template:r.z.string().nullable(),scope:r.z.literal("local").or(r.z.literal("global"))})}function Se(){return r.z.object({__typename:r.z.literal("OperationError").optional(),code:r.z.string().nullable(),description:r.z.string().nullable(),id:r.z.string(),name:r.z.string().nullable(),template:r.z.string().nullable()})}function k(){return r.z.object({__typename:r.z.literal("ReorderChangeLogItemsInput").optional(),order:r.z.array(r.z.string())})}function y(){return r.z.object({moduleId:r.z.string(),order:r.z.array(r.z.string())})}function w(){return r.z.object({order:r.z.array(r.z.string())})}function v(){return r.z.object({operationId:r.z.string(),order:r.z.array(r.z.string())})}function U(){return r.z.object({operationId:r.z.string(),order:r.z.array(r.z.string())})}function V(){return r.z.object({scope:r.z.string(),order:r.z.array(r.z.string())})}function F(){return r.z.object({authorName:r.z.string()})}function H(){return r.z.object({authorWebsite:r.z.string()})}function $(){return r.z.object({scope:r.z.string(),initialValue:r.z.string()})}function X(){return r.z.object({description:r.z.string()})}function G(){return r.z.object({extension:r.z.string()})}function B(){return r.z.object({id:r.z.string()})}function W(){return r.z.object({name:r.z.string()})}function q(){return r.z.object({description:r.z.string().nullish(),id:r.z.string()})}function J(){return r.z.object({id:r.z.string(),name:r.z.string().nullish()})}function K(){return r.z.object({description:r.z.string().nullish(),id:r.z.string()})}function Q(){return r.z.object({errorCode:r.z.string().nullish(),id:r.z.string()})}function Y(){return r.z.object({errorDescription:r.z.string().nullish(),id:r.z.string()})}function Z(){return r.z.object({errorName:r.z.string().nullish(),id:r.z.string()})}function ee(){return r.z.object({errorTemplate:r.z.string().nullish(),id:r.z.string()})}function te(){return r.z.object({id:r.z.string(),name:r.z.string().nullish()})}function be(){return r.z.object({id:r.z.string(),scope:r.z.literal("global").or(r.z.literal("local"))})}function re(){return r.z.object({id:r.z.string(),reducer:r.z.string().nullish()})}function oe(){return r.z.object({id:r.z.string(),schema:r.z.string().nullish()})}function ne(){return r.z.object({id:r.z.string(),template:r.z.string().nullish()})}function ie(){return r.z.object({scope:r.z.string(),schema:r.z.string()})}function b(){return r.z.object({__typename:r.z.literal("State").optional(),examples:r.z.array(D()),initialValue:r.z.string(),schema:r.z.string()})}function fe(){return r.z.object({global:b(),local:b()})}function se(){return r.z.object({__typename:r.z.literal("UpdateChangeLogItemInput").optional(),id:r.z.string(),newContent:r.z.string()})}function ae(){return r.z.object({example:r.z.string(),id:r.z.string()})}function pe(){return r.z.object({scope:r.z.string(),id:r.z.string(),newExample:r.z.string()})}const _e=Object.freeze(Object.defineProperty({__proto__:null,AddChangeLogItemInputSchema:_,AddModuleInputSchema:z,AddOperationErrorInputSchema:A,AddOperationExampleInputSchema:I,AddOperationInputSchema:T,AddStateExampleInputSchema:R,AuthorSchema:Ee,CodeExampleSchema:D,DeleteChangeLogItemInputSchema:M,DeleteModuleInputSchema:x,DeleteOperationErrorInputSchema:N,DeleteOperationExampleInputSchema:L,DeleteOperationInputSchema:j,DeleteStateExampleInputSchema:P,DocumentModelInputSchema:Ot,DocumentModelStateSchema:gt,DocumentSpecificationSchema:he,ModuleSchema:Oe,MoveOperationInputSchema:C,OperationErrorSchema:Se,OperationSchema:ge,ReorderChangeLogItemsInputSchema:k,ReorderModuleOperationsInputSchema:y,ReorderModulesInputSchema:w,ReorderOperationErrorsInputSchema:v,ReorderOperationExamplesInputSchema:U,ReorderStateExamplesInputSchema:V,ScopeStateSchema:fe,SetAuthorNameInputSchema:F,SetAuthorWebsiteInputSchema:H,SetInitialStateInputSchema:$,SetModelDescriptionInputSchema:X,SetModelExtensionInputSchema:G,SetModelIdInputSchema:B,SetModelNameInputSchema:W,SetModuleDescriptionInputSchema:q,SetModuleNameInputSchema:J,SetOperationDescriptionInputSchema:K,SetOperationErrorCodeInputSchema:Q,SetOperationErrorDescriptionInputSchema:Y,SetOperationErrorNameInputSchema:Z,SetOperationErrorTemplateInputSchema:ee,SetOperationNameInputSchema:te,SetOperationReducerInputSchema:re,SetOperationSchemaInputSchema:oe,SetOperationScopeInputSchema:be,SetOperationTemplateInputSchema:ne,SetStateSchemaInputSchema:ie,StateSchema:b,UpdateChangeLogItemInputSchema:se,UpdateOperationExampleInputSchema:ae,UpdateStateExampleInputSchema:pe,definedNonNullAnySchema:ht,isDefinedNonNullAny:me},Symbol.toStringTag,{value:"Module"})),c={setModelNameOperation(t,e){t.name=e.input.name},setModelIdOperation(t,e){t.id=e.input.id},setModelExtensionOperation(t,e){t.extension=e.input.extension},setModelDescriptionOperation(t,e){t.description=e.input.description},setAuthorNameOperation(t,e){t.author=t.author||{name:"",website:null},t.author.name=e.input.authorName},setAuthorWebsiteOperation(t,e){t.author=t.author||{name:"",website:null},t.author.website=e.input.authorWebsite}},E={addChangeLogItemOperation(t,e){throw new Error('Reducer "addChangeLogItemOperation" not yet implemented')},updateChangeLogItemOperation(t,e){throw new Error('Reducer "updateChangeLogItemOperation" not yet implemented')},deleteChangeLogItemOperation(t,e){throw new Error('Reducer "deleteChangeLogItemOperation" not yet implemented')},reorderChangeLogItemsOperation(t,e){throw new Error('Reducer "reorderChangeLogItemsOperation" not yet implemented')},releaseNewVersionOperation(t,e){throw new Error('Reducer "releaseNewVersionOperation" not yet implemented')}},St=t=>{const e={};return t.forEach((o,n)=>e[o]=n),(o,n)=>(e[n.id]||999999)-(e[o.id]||999999)},h={addModuleOperation(t,e){t.specifications[t.specifications.length-1].modules.push({id:e.input.id,name:e.input.name,description:e.input.description||"",operations:[]})},setModuleNameOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)o.modules[n].id===e.input.id&&(o.modules[n].name=e.input.name||"")},setModuleDescriptionOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)o.modules[n].id===e.input.id&&(o.modules[n].description=e.input.description||"")},deleteModuleOperation(t,e){const o=t.specifications[t.specifications.length-1];o.modules=o.modules.filter(n=>n.id!=e.input.id)},reorderModulesOperation(t,e){t.specifications[t.specifications.length-1].modules.sort(St(e.input.order))}},bt=t=>{const e={};return t.forEach((o,n)=>e[o]=n),(o,n)=>(e[n.id]||999999)-(e[o.id]||999999)},l={addOperationErrorOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)for(let i=0;i<o.modules[n].operations.length;i++)o.modules[n].operations[i].id==e.input.operationId&&o.modules[n].operations[i].errors.push({id:e.input.id,name:e.input.errorName||"",code:e.input.errorCode||"",description:e.input.errorDescription||"",template:e.input.errorTemplate||""})},setOperationErrorCodeOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)for(let i=0;i<o.modules[n].operations.length;i++)for(let a=0;a<o.modules[n].operations[i].errors.length;a++)o.modules[n].operations[i].errors[a].id==e.input.id&&(o.modules[n].operations[i].errors[a].code=e.input.errorCode||"")},setOperationErrorNameOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)for(let i=0;i<o.modules[n].operations.length;i++)for(let a=0;a<o.modules[n].operations[i].errors.length;a++)o.modules[n].operations[i].errors[a].id==e.input.id&&(o.modules[n].operations[i].errors[a].name=e.input.errorName||"")},setOperationErrorDescriptionOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)for(let i=0;i<o.modules[n].operations.length;i++)for(let a=0;a<o.modules[n].operations[i].errors.length;a++)o.modules[n].operations[i].errors[a].id==e.input.id&&(o.modules[n].operations[i].errors[a].description=e.input.errorDescription||"")},setOperationErrorTemplateOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)for(let i=0;i<o.modules[n].operations.length;i++)for(let a=0;a<o.modules[n].operations[i].errors.length;a++)o.modules[n].operations[i].errors[a].id==e.input.id&&(o.modules[n].operations[i].errors[a].template=e.input.errorTemplate||"")},deleteOperationErrorOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)for(let i=0;i<o.modules[n].operations.length;i++)o.modules[n].operations[i].errors=o.modules[n].operations[i].errors.filter(a=>a.id!=e.input.id)},reorderOperationErrorsOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)for(let i=0;i<o.modules[n].operations.length;i++)o.modules[n].operations[i].id==e.input.operationId&&o.modules[n].operations[i].errors.sort(bt(e.input.order))}},ft=t=>{const e={};return t.forEach((o,n)=>e[o]=n),(o,n)=>(e[n.id]||999999)-(e[o.id]||999999)},g={addOperationExampleOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)for(let i=0;i<o.modules[n].operations.length;i++)o.modules[n].operations[i].id==e.input.operationId&&o.modules[n].operations[i].examples.push({id:e.input.id,value:e.input.example})},updateOperationExampleOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)for(let i=0;i<o.modules[n].operations.length;i++)for(let a=0;a<o.modules[n].operations[i].examples.length;a++)o.modules[n].operations[i].examples[a].id==e.input.id&&(o.modules[n].operations[i].examples[a].value=e.input.example)},deleteOperationExampleOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)for(let i=0;i<o.modules[n].operations.length;i++)o.modules[n].operations[i].examples=o.modules[n].operations[i].examples.filter(a=>a.id!=e.input.id)},reorderOperationExamplesOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)for(let i=0;i<o.modules[n].operations.length;i++)o.modules[n].operations[i].id==e.input.operationId&&o.modules[n].operations[i].examples.sort(ft(e.input.order))}},_t=t=>{const e={};return t.forEach((o,n)=>e[o]=n),(o,n)=>(e[n.id]||999999)-(e[o.id]||999999)},p={addOperationOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)o.modules[n].id==e.input.moduleId&&o.modules[n].operations.push({id:e.input.id,name:e.input.name,description:e.input.description||"",schema:e.input.schema||"",template:e.input.template||e.input.description||"",reducer:e.input.reducer||"",errors:[],examples:[],scope:e.input.scope||"global"})},setOperationNameOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)for(let i=0;i<o.modules[n].operations.length;i++)o.modules[n].operations[i].id==e.input.id&&(o.modules[n].operations[i].name=e.input.name||"")},setOperationScopeOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)for(let i=0;i<o.modules[n].operations.length;i++)o.modules[n].operations[i].id==e.input.id&&(o.modules[n].operations[i].scope=e.input.scope||"global")},setOperationSchemaOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)for(let i=0;i<o.modules[n].operations.length;i++)o.modules[n].operations[i].id==e.input.id&&(o.modules[n].operations[i].schema=e.input.schema||"")},setOperationDescriptionOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)for(let i=0;i<o.modules[n].operations.length;i++)o.modules[n].operations[i].id==e.input.id&&(o.modules[n].operations[i].description=e.input.description||"")},setOperationTemplateOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)for(let i=0;i<o.modules[n].operations.length;i++)o.modules[n].operations[i].id==e.input.id&&(o.modules[n].operations[i].template=e.input.template||"")},setOperationReducerOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)for(let i=0;i<o.modules[n].operations.length;i++)o.modules[n].operations[i].id==e.input.id&&(o.modules[n].operations[i].reducer=e.input.reducer||"")},moveOperationOperation(t,e){const o=[],n=t.specifications[t.specifications.length-1];for(let i=0;i<n.modules.length;i++)n.modules[i].operations=n.modules[i].operations.filter(a=>a.id==e.input.operationId?(o.push(a),!1):!0);for(let i=0;i<n.modules.length;i++)n.modules[i].id==e.input.newModuleId&&n.modules[i].operations.push(...o)},deleteOperationOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)o.modules[n].operations=o.modules[n].operations.filter(i=>i.id!=e.input.id)},reorderModuleOperationsOperation(t,e){const o=t.specifications[t.specifications.length-1];for(let n=0;n<o.modules.length;n++)o.modules[n].id==e.input.moduleId&&o.modules[n].operations.sort(_t(e.input.order))}},zt=t=>{const e={};return t.forEach((o,n)=>e[o]=n),(o,n)=>(e[n.id]||999999)-(e[o.id]||999999)},d={setStateSchemaOperation(t,e){const o=t.specifications[t.specifications.length-1];if(Object.keys(o.state).includes(e.input.scope))o.state[e.input.scope].schema=e.input.schema;else throw new Error(`Invalid scope: ${e.input.scope}`)},setInitialStateOperation(t,e){const o=t.specifications[t.specifications.length-1];if(Object.keys(o.state).includes(e.input.scope))o.state[e.input.scope].initialValue=e.input.initialValue;else throw new Error(`Invalid scope: ${e.input.scope}`)},addStateExampleOperation(t,e){const o=t.specifications[t.specifications.length-1];if(Object.keys(o.state).includes(e.input.scope))o.state[e.input.scope].examples.push({id:e.input.id,value:e.input.example});else throw new Error(`Invalid scope: ${e.input.scope}`)},updateStateExampleOperation(t,e){const o=t.specifications[t.specifications.length-1];if(!Object.keys(o.state).includes(e.input.scope))throw new Error(`Invalid scope: ${e.input.scope}`);const n=o.state[e.input.scope].examples;for(let i=0;i<n.length;i++)n[i].id==e.input.id&&(n[i].value=e.input.newExample)},deleteStateExampleOperation(t,e){const o=t.specifications[t.specifications.length-1];if(Object.keys(o.state).includes(e.input.scope))o.state[e.input.scope].examples=o.state[e.input.scope].examples.filter(n=>n.id!=e.input.id);else throw new Error(`Invalid scope: ${e.input.scope}`)},reorderStateExamplesOperation(t,e){const o=t.specifications[t.specifications.length-1];if(Object.keys(o.state).includes(e.input.scope))o.state[e.input.scope].examples.sort(zt(e.input.order));else throw new Error(`Invalid scope: ${e.input.scope}`)}},At=(t,e)=>{if(s.isBaseAction(e))return t;switch(e.type){case"SET_MODEL_NAME":W().parse(e.input),c.setModelNameOperation(t.global,e);break;case"SET_MODEL_ID":B().parse(e.input),c.setModelIdOperation(t.global,e);break;case"SET_MODEL_EXTENSION":G().parse(e.input),c.setModelExtensionOperation(t.global,e);break;case"SET_MODEL_DESCRIPTION":X().parse(e.input),c.setModelDescriptionOperation(t.global,e);break;case"SET_AUTHOR_NAME":F().parse(e.input),c.setAuthorNameOperation(t.global,e);break;case"SET_AUTHOR_WEBSITE":H().parse(e.input),c.setAuthorWebsiteOperation(t.global,e);break;case"ADD_CHANGE_LOG_ITEM":_().parse(e.input),E.addChangeLogItemOperation(t.global,e);break;case"UPDATE_CHANGE_LOG_ITEM":se().parse(e.input),E.updateChangeLogItemOperation(t.global,e);break;case"DELETE_CHANGE_LOG_ITEM":M().parse(e.input),E.deleteChangeLogItemOperation(t.global,e);break;case"REORDER_CHANGE_LOG_ITEMS":k().parse(e.input),E.reorderChangeLogItemsOperation(t.global,e);break;case"RELEASE_NEW_VERSION":if(Object.keys(e.input).length>0)throw new Error("Expected empty input for action RELEASE_NEW_VERSION");E.releaseNewVersionOperation(t.global,e);break;case"ADD_MODULE":z().parse(e.input),h.addModuleOperation(t.global,e);break;case"SET_MODULE_NAME":J().parse(e.input),h.setModuleNameOperation(t.global,e);break;case"SET_MODULE_DESCRIPTION":q().parse(e.input),h.setModuleDescriptionOperation(t.global,e);break;case"DELETE_MODULE":x().parse(e.input),h.deleteModuleOperation(t.global,e);break;case"REORDER_MODULES":w().parse(e.input),h.reorderModulesOperation(t.global,e);break;case"ADD_OPERATION_ERROR":A().parse(e.input),l.addOperationErrorOperation(t.global,e);break;case"SET_OPERATION_ERROR_CODE":Q().parse(e.input),l.setOperationErrorCodeOperation(t.global,e);break;case"SET_OPERATION_ERROR_NAME":Z().parse(e.input),l.setOperationErrorNameOperation(t.global,e);break;case"SET_OPERATION_ERROR_DESCRIPTION":Y().parse(e.input),l.setOperationErrorDescriptionOperation(t.global,e);break;case"SET_OPERATION_ERROR_TEMPLATE":ee().parse(e.input),l.setOperationErrorTemplateOperation(t.global,e);break;case"DELETE_OPERATION_ERROR":N().parse(e.input),l.deleteOperationErrorOperation(t.global,e);break;case"REORDER_OPERATION_ERRORS":v().parse(e.input),l.reorderOperationErrorsOperation(t.global,e);break;case"ADD_OPERATION_EXAMPLE":I().parse(e.input),g.addOperationExampleOperation(t.global,e);break;case"UPDATE_OPERATION_EXAMPLE":ae().parse(e.input),g.updateOperationExampleOperation(t.global,e);break;case"DELETE_OPERATION_EXAMPLE":L().parse(e.input),g.deleteOperationExampleOperation(t.global,e);break;case"REORDER_OPERATION_EXAMPLES":U().parse(e.input),g.reorderOperationExamplesOperation(t.global,e);break;case"ADD_OPERATION":T().parse(e.input),p.addOperationOperation(t.global,e);break;case"SET_OPERATION_NAME":te().parse(e.input),p.setOperationNameOperation(t.global,e);break;case"SET_OPERATION_SCOPE":be().parse(e.input),p.setOperationScopeOperation(t.global,e);break;case"SET_OPERATION_SCHEMA":oe().parse(e.input),p.setOperationSchemaOperation(t.global,e);break;case"SET_OPERATION_DESCRIPTION":K().parse(e.input),p.setOperationDescriptionOperation(t.global,e);break;case"SET_OPERATION_TEMPLATE":ne().parse(e.input),p.setOperationTemplateOperation(t.global,e);break;case"SET_OPERATION_REDUCER":re().parse(e.input),p.setOperationReducerOperation(t.global,e);break;case"MOVE_OPERATION":C().parse(e.input),p.moveOperationOperation(t.global,e);break;case"DELETE_OPERATION":j().parse(e.input),p.deleteOperationOperation(t.global,e);break;case"REORDER_MODULE_OPERATIONS":y().parse(e.input),p.reorderModuleOperationsOperation(t.global,e);break;case"SET_STATE_SCHEMA":ie().parse(e.input),d.setStateSchemaOperation(t.global,e);break;case"SET_INITIAL_STATE":$().parse(e.input),d.setInitialStateOperation(t.global,e);break;case"ADD_STATE_EXAMPLE":R().parse(e.input),d.addStateExampleOperation(t.global,e);break;case"UPDATE_STATE_EXAMPLE":pe().parse(e.input),d.updateStateExampleOperation(t.global,e);break;case"DELETE_STATE_EXAMPLE":P().parse(e.input),d.deleteStateExampleOperation(t.global,e);break;case"REORDER_STATE_EXAMPLES":V().parse(e.input),d.reorderStateExamplesOperation(t.global,e);break;default:return t}},m=s.createReducer(At),It={id:"",name:"",extension:"",description:"",author:{name:"",website:""},specifications:[{version:1,changeLog:[],state:{global:{schema:"",initialValue:"",examples:[]},local:{schema:"",initialValue:"",examples:[]}},modules:[]}]},O={fileExtension:"phdm",createState(t){return{global:{...It,...t},local:{}}},createExtendedState(t){return s.createExtendedState({...t,documentType:"powerhouse/document-model"},O.createState)},createDocument(t){return s.createDocument(O.createExtendedState(t),O.createState)},saveToFile(t,e,o){return s.saveToFile(t,e,"phdm",o)},saveToFileHandle(t,e){return s.saveToFileHandle(t,e)},loadFromFile(t){return s.loadFromFile(t,m)},loadFromInput(t){return s.loadFromInput(t,m)}},ze=t=>s.createAction("SET_MODEL_NAME",{...t}),Ae=t=>s.createAction("SET_MODEL_ID",{...t}),Ie=t=>s.createAction("SET_MODEL_EXTENSION",{...t}),Te=t=>s.createAction("SET_MODEL_DESCRIPTION",{...t}),Re=t=>s.createAction("SET_AUTHOR_NAME",{...t}),De=t=>s.createAction("SET_AUTHOR_WEBSITE",{...t});class Tt extends s.BaseDocument{setModelName(e){return this.dispatch(ze(e))}setModelId(e){return this.dispatch(Ae(e))}setModelExtension(e){return this.dispatch(Ie(e))}setModelDescription(e){return this.dispatch(Te(e))}setAuthorName(e){return this.dispatch(Re(e))}setAuthorWebsite(e){return this.dispatch(De(e))}}const Me=t=>s.createAction("ADD_CHANGE_LOG_ITEM",{...t}),xe=t=>s.createAction("UPDATE_CHANGE_LOG_ITEM",{...t}),Ne=t=>s.createAction("DELETE_CHANGE_LOG_ITEM",{...t}),Le=t=>s.createAction("REORDER_CHANGE_LOG_ITEMS",{...t}),je=()=>s.createAction("RELEASE_NEW_VERSION");class Rt extends s.BaseDocument{addChangeLogItem(e){return this.dispatch(Me(e))}updateChangeLogItem(e){return this.dispatch(xe(e))}deleteChangeLogItem(e){return this.dispatch(Ne(e))}reorderChangeLogItems(e){return this.dispatch(Le(e))}releaseNewVersion(){return this.dispatch(je())}}const Pe=t=>s.createAction("ADD_MODULE",{...t}),Ce=t=>s.createAction("SET_MODULE_NAME",{...t}),ke=t=>s.createAction("SET_MODULE_DESCRIPTION",{...t}),ye=t=>s.createAction("DELETE_MODULE",{...t}),we=t=>s.createAction("REORDER_MODULES",{...t});class Dt extends s.BaseDocument{addModule(e){return this.dispatch(Pe(e))}setModuleName(e){return this.dispatch(Ce(e))}setModuleDescription(e){return this.dispatch(ke(e))}deleteModule(e){return this.dispatch(ye(e))}reorderModules(e){return this.dispatch(we(e))}}const ve=t=>s.createAction("ADD_OPERATION_ERROR",{...t}),Ue=t=>s.createAction("SET_OPERATION_ERROR_CODE",{...t}),Ve=t=>s.createAction("SET_OPERATION_ERROR_NAME",{...t}),Fe=t=>s.createAction("SET_OPERATION_ERROR_DESCRIPTION",{...t}),He=t=>s.createAction("SET_OPERATION_ERROR_TEMPLATE",{...t}),$e=t=>s.createAction("DELETE_OPERATION_ERROR",{...t}),Xe=t=>s.createAction("REORDER_OPERATION_ERRORS",{...t});class Mt extends s.BaseDocument{addOperationError(e){return this.dispatch(ve(e))}setOperationErrorCode(e){return this.dispatch(Ue(e))}setOperationErrorName(e){return this.dispatch(Ve(e))}setOperationErrorDescription(e){return this.dispatch(Fe(e))}setOperationErrorTemplate(e){return this.dispatch(He(e))}deleteOperationError(e){return this.dispatch($e(e))}reorderOperationErrors(e){return this.dispatch(Xe(e))}}const Ge=t=>s.createAction("ADD_OPERATION_EXAMPLE",{...t}),Be=t=>s.createAction("UPDATE_OPERATION_EXAMPLE",{...t}),We=t=>s.createAction("DELETE_OPERATION_EXAMPLE",{...t}),qe=t=>s.createAction("REORDER_OPERATION_EXAMPLES",{...t});class xt extends s.BaseDocument{addOperationExample(e){return this.dispatch(Ge(e))}updateOperationExample(e){return this.dispatch(Be(e))}deleteOperationExample(e){return this.dispatch(We(e))}reorderOperationExamples(e){return this.dispatch(qe(e))}}const Je=t=>s.createAction("ADD_OPERATION",{...t}),Ke=t=>s.createAction("SET_OPERATION_NAME",{...t}),Qe=t=>s.createAction("SET_OPERATION_SCOPE",{...t}),Ye=t=>s.createAction("SET_OPERATION_SCHEMA",{...t}),Ze=t=>s.createAction("SET_OPERATION_DESCRIPTION",{...t}),et=t=>s.createAction("SET_OPERATION_TEMPLATE",{...t}),tt=t=>s.createAction("SET_OPERATION_REDUCER",{...t}),rt=t=>s.createAction("MOVE_OPERATION",{...t}),ot=t=>s.createAction("DELETE_OPERATION",{...t}),nt=t=>s.createAction("REORDER_MODULE_OPERATIONS",{...t});class Nt extends s.BaseDocument{addOperation(e){return this.dispatch(Je(e))}setOperationName(e){return this.dispatch(Ke(e))}setOperationScope(e){return this.dispatch(Qe(e))}setOperationSchema(e){return this.dispatch(Ye(e))}setOperationDescription(e){return this.dispatch(Ze(e))}setOperationTemplate(e){return this.dispatch(et(e))}setOperationReducer(e){return this.dispatch(tt(e))}moveOperation(e){return this.dispatch(rt(e))}deleteOperation(e){return this.dispatch(ot(e))}reorderModuleOperations(e){return this.dispatch(nt(e))}}const it=t=>s.createAction("SET_STATE_SCHEMA",{...t}),st=t=>s.createAction("SET_INITIAL_STATE",{...t}),at=t=>s.createAction("ADD_STATE_EXAMPLE",{...t}),pt=t=>s.createAction("UPDATE_STATE_EXAMPLE",{...t}),lt=t=>s.createAction("DELETE_STATE_EXAMPLE",{...t}),ct=t=>s.createAction("REORDER_STATE_EXAMPLES",{...t});class Lt extends s.BaseDocument{setStateSchema(e){return this.dispatch(it(e))}setInitialState(e){return this.dispatch(st(e))}addStateExample(e){return this.dispatch(at(e))}updateStateExample(e){return this.dispatch(pt(e))}deleteStateExample(e){return this.dispatch(lt(e))}reorderStateExamples(e){return this.dispatch(ct(e))}}var u;let S=(u=class extends s.BaseDocument{constructor(e,o){super(m,O.createDocument(e),o)}saveToFile(e,o){return super.saveToFile(e,u.fileExtension,o)}loadFromFile(e){return super.loadFromFile(e)}static async fromFile(e){const o=new this;return await o.loadFromFile(e),o}},ue(u,"fileExtension","phdm"),u);s.applyMixins(S,[Tt,Rt,Dt,Mt,xt,Nt,Lt]);const jt=Object.freeze(Object.defineProperty({__proto__:null,addChangeLogItem:Me,addModule:Pe,addOperation:Je,addOperationError:ve,addOperationExample:Ge,addStateExample:at,deleteChangeLogItem:Ne,deleteModule:ye,deleteOperation:ot,deleteOperationError:$e,deleteOperationExample:We,deleteStateExample:lt,moveOperation:rt,releaseNewVersion:je,reorderChangeLogItems:Le,reorderModuleOperations:nt,reorderModules:we,reorderOperationErrors:Xe,reorderOperationExamples:qe,reorderStateExamples:ct,setAuthorName:Re,setAuthorWebsite:De,setInitialState:st,setModelDescription:Te,setModelExtension:Ie,setModelId:Ae,setModelName:ze,setModuleDescription:ke,setModuleName:Ce,setOperationDescription:Ze,setOperationErrorCode:Ue,setOperationErrorDescription:Fe,setOperationErrorName:Ve,setOperationErrorTemplate:He,setOperationName:Ke,setOperationReducer:tt,setOperationSchema:Ye,setOperationScope:Qe,setOperationTemplate:et,setStateSchema:it,updateChangeLogItem:xe,updateOperationExample:Be,updateStateExample:pt},Symbol.toStringTag,{value:"Module"})),le=S,ce={...O,...Et},de={...s.BaseActions,...jt},dt={Document:le,reducer:m,actions:de,utils:ce,documentModel:f},Pt=Object.freeze(Object.defineProperty({__proto__:null,Document:le,DocumentModel:S,actions:de,documentModel:f,module:dt,reducer:m,utils:ce,z:_e},Symbol.toStringTag,{value:"Module"}));exports.Document=le;exports.DocumentModel=Pt;exports.DocumentModel$1=S;exports.actions=de;exports.documentModel=f;exports.module=dt;exports.reducer=m;exports.utils=ce;exports.zod=_e;
@@ -0,0 +1 @@
1
+ "use strict";var ct=Object.defineProperty;var rt=(t,e,i)=>e in t?ct(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var f=(t,e,i)=>(rt(t,typeof e!="symbol"?e+"":e,i),i);const mt=require("json-stringify-deterministic"),x=require("immer"),q=require("jszip"),ut=require("crypto"),z=require("fs"),dt=require("https"),xt=require("path"),n=require("zod"),P=t=>t!=null,gt=n.z.any().refine(t=>P(t)),I=n.z.enum(["LOAD_STATE"]),M=n.z.enum(["PRUNE"]),R=n.z.enum(["REDO"]),L=n.z.enum(["SET_NAME"]),U=n.z.enum(["UNDO"]);function ft(){return n.z.object({__typename:n.z.literal("Action").optional(),type:n.z.string()})}function J(){return n.z.union([$(),C(),Z(),H(),K()])}function ht(){return n.z.object({__typename:n.z.literal("DocumentFile").optional(),data:n.z.string(),extension:n.z.string().nullable(),fileName:n.z.string().nullable(),mimeType:n.z.string()})}function $(){return n.z.object({input:n.z.lazy(()=>D()),type:I,scope:n.z.literal("global")})}function D(){return n.z.object({operations:n.z.number(),state:n.z.lazy(()=>B())})}function B(){return n.z.object({data:n.z.unknown().nullish(),name:n.z.string()})}function bt(){return n.z.object({__typename:n.z.literal("Operation").optional(),hash:n.z.string(),index:n.z.number(),timestamp:n.z.string().datetime(),type:n.z.string()})}function C(){return n.z.object({input:n.z.lazy(()=>k()),type:M,scope:n.z.literal("global")})}function k(){return n.z.object({end:n.z.number().nullish(),start:n.z.number().nullish()})}const E=n.z.number;function Z(){return n.z.object({input:E(),type:R,scope:n.z.literal("global")})}const A=n.z.string;function H(){return n.z.object({input:A(),type:L,scope:n.z.literal("global")})}function vt(){return n.z.object({__typename:n.z.literal("SetNameOperation").optional(),hash:n.z.string(),index:n.z.number(),input:n.z.string(),timestamp:n.z.string().datetime(),type:n.z.string()})}const N=n.z.number;function K(){return n.z.object({input:N(),type:U,scope:n.z.literal("global")})}const yt=Object.freeze(Object.defineProperty({__proto__:null,ActionSchema:ft,BaseActionSchema:J,DocumentFileSchema:ht,LoadStateActionInputSchema:D,LoadStateActionSchema:$,LoadStateActionStateInputSchema:B,Load_StateSchema:I,OperationSchema:bt,PruneActionInputSchema:k,PruneActionSchema:C,PruneSchema:M,RedoActionInputSchema:E,RedoActionSchema:Z,RedoSchema:R,SetNameActionInputSchema:A,SetNameActionSchema:H,SetNameOperationSchema:vt,Set_NameSchema:L,UndoActionInputSchema:N,UndoActionSchema:K,UndoSchema:U,definedNonNullAnySchema:gt,isDefinedNonNullAny:P},Symbol.toStringTag,{value:"Module"}));function jt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function b(){this._types=Object.create(null),this._extensions=Object.create(null);for(let t=0;t<arguments.length;t++)this.define(arguments[t]);this.define=this.define.bind(this),this.getType=this.getType.bind(this),this.getExtension=this.getExtension.bind(this)}b.prototype.define=function(t,e){for(let i in t){let a=t[i].map(function(o){return o.toLowerCase()});i=i.toLowerCase();for(let o=0;o<a.length;o++){const s=a[o];if(s[0]!=="*"){if(!e&&s in this._types)throw new Error('Attempt to change mapping for "'+s+'" extension from "'+this._types[s]+'" to "'+i+'". Pass `force=true` to allow this, otherwise remove "'+s+'" from the list of extensions for "'+i+'".');this._types[s]=i}}if(e||!this._extensions[i]){const o=a[0];this._extensions[i]=o[0]!=="*"?o:o.substr(1)}}};b.prototype.getType=function(t){t=String(t);let e=t.replace(/^.*[/\\]/,"").toLowerCase(),i=e.replace(/^.*\./,"").toLowerCase(),a=e.length<t.length;return(i.length<e.length-1||!a)&&this._types[i]||null};b.prototype.getExtension=function(t){return t=/^\s*([^;\s]*)/.test(t)&&RegExp.$1,t&&this._extensions[t.toLowerCase()]||null};var wt=b,zt={"application/andrew-inset":["ez"],"application/applixware":["aw"],"application/atom+xml":["atom"],"application/atomcat+xml":["atomcat"],"application/atomdeleted+xml":["atomdeleted"],"application/atomsvc+xml":["atomsvc"],"application/atsc-dwd+xml":["dwd"],"application/atsc-held+xml":["held"],"application/atsc-rsat+xml":["rsat"],"application/bdoc":["bdoc"],"application/calendar+xml":["xcs"],"application/ccxml+xml":["ccxml"],"application/cdfx+xml":["cdfx"],"application/cdmi-capability":["cdmia"],"application/cdmi-container":["cdmic"],"application/cdmi-domain":["cdmid"],"application/cdmi-object":["cdmio"],"application/cdmi-queue":["cdmiq"],"application/cu-seeme":["cu"],"application/dash+xml":["mpd"],"application/davmount+xml":["davmount"],"application/docbook+xml":["dbk"],"application/dssc+der":["dssc"],"application/dssc+xml":["xdssc"],"application/ecmascript":["es","ecma"],"application/emma+xml":["emma"],"application/emotionml+xml":["emotionml"],"application/epub+zip":["epub"],"application/exi":["exi"],"application/express":["exp"],"application/fdt+xml":["fdt"],"application/font-tdpfr":["pfr"],"application/geo+json":["geojson"],"application/gml+xml":["gml"],"application/gpx+xml":["gpx"],"application/gxf":["gxf"],"application/gzip":["gz"],"application/hjson":["hjson"],"application/hyperstudio":["stk"],"application/inkml+xml":["ink","inkml"],"application/ipfix":["ipfix"],"application/its+xml":["its"],"application/java-archive":["jar","war","ear"],"application/java-serialized-object":["ser"],"application/java-vm":["class"],"application/javascript":["js","mjs"],"application/json":["json","map"],"application/json5":["json5"],"application/jsonml+json":["jsonml"],"application/ld+json":["jsonld"],"application/lgr+xml":["lgr"],"application/lost+xml":["lostxml"],"application/mac-binhex40":["hqx"],"application/mac-compactpro":["cpt"],"application/mads+xml":["mads"],"application/manifest+json":["webmanifest"],"application/marc":["mrc"],"application/marcxml+xml":["mrcx"],"application/mathematica":["ma","nb","mb"],"application/mathml+xml":["mathml"],"application/mbox":["mbox"],"application/mediaservercontrol+xml":["mscml"],"application/metalink+xml":["metalink"],"application/metalink4+xml":["meta4"],"application/mets+xml":["mets"],"application/mmt-aei+xml":["maei"],"application/mmt-usd+xml":["musd"],"application/mods+xml":["mods"],"application/mp21":["m21","mp21"],"application/mp4":["mp4s","m4p"],"application/msword":["doc","dot"],"application/mxf":["mxf"],"application/n-quads":["nq"],"application/n-triples":["nt"],"application/node":["cjs"],"application/octet-stream":["bin","dms","lrf","mar","so","dist","distz","pkg","bpk","dump","elc","deploy","exe","dll","deb","dmg","iso","img","msi","msp","msm","buffer"],"application/oda":["oda"],"application/oebps-package+xml":["opf"],"application/ogg":["ogx"],"application/omdoc+xml":["omdoc"],"application/onenote":["onetoc","onetoc2","onetmp","onepkg"],"application/oxps":["oxps"],"application/p2p-overlay+xml":["relo"],"application/patch-ops-error+xml":["xer"],"application/pdf":["pdf"],"application/pgp-encrypted":["pgp"],"application/pgp-signature":["asc","sig"],"application/pics-rules":["prf"],"application/pkcs10":["p10"],"application/pkcs7-mime":["p7m","p7c"],"application/pkcs7-signature":["p7s"],"application/pkcs8":["p8"],"application/pkix-attr-cert":["ac"],"application/pkix-cert":["cer"],"application/pkix-crl":["crl"],"application/pkix-pkipath":["pkipath"],"application/pkixcmp":["pki"],"application/pls+xml":["pls"],"application/postscript":["ai","eps","ps"],"application/provenance+xml":["provx"],"application/pskc+xml":["pskcxml"],"application/raml+yaml":["raml"],"application/rdf+xml":["rdf","owl"],"application/reginfo+xml":["rif"],"application/relax-ng-compact-syntax":["rnc"],"application/resource-lists+xml":["rl"],"application/resource-lists-diff+xml":["rld"],"application/rls-services+xml":["rs"],"application/route-apd+xml":["rapd"],"application/route-s-tsid+xml":["sls"],"application/route-usd+xml":["rusd"],"application/rpki-ghostbusters":["gbr"],"application/rpki-manifest":["mft"],"application/rpki-roa":["roa"],"application/rsd+xml":["rsd"],"application/rss+xml":["rss"],"application/rtf":["rtf"],"application/sbml+xml":["sbml"],"application/scvp-cv-request":["scq"],"application/scvp-cv-response":["scs"],"application/scvp-vp-request":["spq"],"application/scvp-vp-response":["spp"],"application/sdp":["sdp"],"application/senml+xml":["senmlx"],"application/sensml+xml":["sensmlx"],"application/set-payment-initiation":["setpay"],"application/set-registration-initiation":["setreg"],"application/shf+xml":["shf"],"application/sieve":["siv","sieve"],"application/smil+xml":["smi","smil"],"application/sparql-query":["rq"],"application/sparql-results+xml":["srx"],"application/srgs":["gram"],"application/srgs+xml":["grxml"],"application/sru+xml":["sru"],"application/ssdl+xml":["ssdl"],"application/ssml+xml":["ssml"],"application/swid+xml":["swidtag"],"application/tei+xml":["tei","teicorpus"],"application/thraud+xml":["tfi"],"application/timestamped-data":["tsd"],"application/toml":["toml"],"application/trig":["trig"],"application/ttml+xml":["ttml"],"application/ubjson":["ubj"],"application/urc-ressheet+xml":["rsheet"],"application/urc-targetdesc+xml":["td"],"application/voicexml+xml":["vxml"],"application/wasm":["wasm"],"application/widget":["wgt"],"application/winhlp":["hlp"],"application/wsdl+xml":["wsdl"],"application/wspolicy+xml":["wspolicy"],"application/xaml+xml":["xaml"],"application/xcap-att+xml":["xav"],"application/xcap-caps+xml":["xca"],"application/xcap-diff+xml":["xdf"],"application/xcap-el+xml":["xel"],"application/xcap-ns+xml":["xns"],"application/xenc+xml":["xenc"],"application/xhtml+xml":["xhtml","xht"],"application/xliff+xml":["xlf"],"application/xml":["xml","xsl","xsd","rng"],"application/xml-dtd":["dtd"],"application/xop+xml":["xop"],"application/xproc+xml":["xpl"],"application/xslt+xml":["*xsl","xslt"],"application/xspf+xml":["xspf"],"application/xv+xml":["mxml","xhvml","xvml","xvm"],"application/yang":["yang"],"application/yin+xml":["yin"],"application/zip":["zip"],"audio/3gpp":["*3gpp"],"audio/adpcm":["adp"],"audio/amr":["amr"],"audio/basic":["au","snd"],"audio/midi":["mid","midi","kar","rmi"],"audio/mobile-xmf":["mxmf"],"audio/mp3":["*mp3"],"audio/mp4":["m4a","mp4a"],"audio/mpeg":["mpga","mp2","mp2a","mp3","m2a","m3a"],"audio/ogg":["oga","ogg","spx","opus"],"audio/s3m":["s3m"],"audio/silk":["sil"],"audio/wav":["wav"],"audio/wave":["*wav"],"audio/webm":["weba"],"audio/xm":["xm"],"font/collection":["ttc"],"font/otf":["otf"],"font/ttf":["ttf"],"font/woff":["woff"],"font/woff2":["woff2"],"image/aces":["exr"],"image/apng":["apng"],"image/avif":["avif"],"image/bmp":["bmp"],"image/cgm":["cgm"],"image/dicom-rle":["drle"],"image/emf":["emf"],"image/fits":["fits"],"image/g3fax":["g3"],"image/gif":["gif"],"image/heic":["heic"],"image/heic-sequence":["heics"],"image/heif":["heif"],"image/heif-sequence":["heifs"],"image/hej2k":["hej2"],"image/hsj2":["hsj2"],"image/ief":["ief"],"image/jls":["jls"],"image/jp2":["jp2","jpg2"],"image/jpeg":["jpeg","jpg","jpe"],"image/jph":["jph"],"image/jphc":["jhc"],"image/jpm":["jpm"],"image/jpx":["jpx","jpf"],"image/jxr":["jxr"],"image/jxra":["jxra"],"image/jxrs":["jxrs"],"image/jxs":["jxs"],"image/jxsc":["jxsc"],"image/jxsi":["jxsi"],"image/jxss":["jxss"],"image/ktx":["ktx"],"image/ktx2":["ktx2"],"image/png":["png"],"image/sgi":["sgi"],"image/svg+xml":["svg","svgz"],"image/t38":["t38"],"image/tiff":["tif","tiff"],"image/tiff-fx":["tfx"],"image/webp":["webp"],"image/wmf":["wmf"],"message/disposition-notification":["disposition-notification"],"message/global":["u8msg"],"message/global-delivery-status":["u8dsn"],"message/global-disposition-notification":["u8mdn"],"message/global-headers":["u8hdr"],"message/rfc822":["eml","mime"],"model/3mf":["3mf"],"model/gltf+json":["gltf"],"model/gltf-binary":["glb"],"model/iges":["igs","iges"],"model/mesh":["msh","mesh","silo"],"model/mtl":["mtl"],"model/obj":["obj"],"model/step+xml":["stpx"],"model/step+zip":["stpz"],"model/step-xml+zip":["stpxz"],"model/stl":["stl"],"model/vrml":["wrl","vrml"],"model/x3d+binary":["*x3db","x3dbz"],"model/x3d+fastinfoset":["x3db"],"model/x3d+vrml":["*x3dv","x3dvz"],"model/x3d+xml":["x3d","x3dz"],"model/x3d-vrml":["x3dv"],"text/cache-manifest":["appcache","manifest"],"text/calendar":["ics","ifb"],"text/coffeescript":["coffee","litcoffee"],"text/css":["css"],"text/csv":["csv"],"text/html":["html","htm","shtml"],"text/jade":["jade"],"text/jsx":["jsx"],"text/less":["less"],"text/markdown":["markdown","md"],"text/mathml":["mml"],"text/mdx":["mdx"],"text/n3":["n3"],"text/plain":["txt","text","conf","def","list","log","in","ini"],"text/richtext":["rtx"],"text/rtf":["*rtf"],"text/sgml":["sgml","sgm"],"text/shex":["shex"],"text/slim":["slim","slm"],"text/spdx":["spdx"],"text/stylus":["stylus","styl"],"text/tab-separated-values":["tsv"],"text/troff":["t","tr","roff","man","me","ms"],"text/turtle":["ttl"],"text/uri-list":["uri","uris","urls"],"text/vcard":["vcard"],"text/vtt":["vtt"],"text/xml":["*xml"],"text/yaml":["yaml","yml"],"video/3gpp":["3gp","3gpp"],"video/3gpp2":["3g2"],"video/h261":["h261"],"video/h263":["h263"],"video/h264":["h264"],"video/iso.segment":["m4s"],"video/jpeg":["jpgv"],"video/jpm":["*jpm","jpgm"],"video/mj2":["mj2","mjp2"],"video/mp2t":["ts"],"video/mp4":["mp4","mp4v","mpg4"],"video/mpeg":["mpeg","mpg","mpe","m1v","m2v"],"video/ogg":["ogv"],"video/quicktime":["qt","mov"],"video/webm":["webm"]};let St=wt;var _t=new St(zt);const Ot=jt(_t);function Dt(t,e,i){const a=xt.join(t,e);return z.mkdirSync(t,{recursive:!0}),new Promise((o,s)=>{try{z.writeFile(a,i,{},l=>{l?s(l):o(a)})}catch(l){s(l)}})}function W(t){return z.readFileSync(t)}function kt(t){return new Promise((e,i)=>{dt.get(t,a=>{const o=[],s=a.headers["content-type"];a.on("data",l=>{o.push(l)}),a.on("end",()=>{e({buffer:Buffer.concat(o),mimeType:s})})}).on("error",a=>{i(a)})})}const Et=async t=>W(t),v=(t,e="sha1")=>ut.createHash(e).update(t).digest("base64"),T=async t=>{const e=new q,{name:i,revision:a,documentType:o,created:s,lastModified:l}=t,p={name:i,revision:a,documentType:o,created:s,lastModified:l};return e.file("header.json",JSON.stringify(p,null,2)),e.file("state.json",JSON.stringify(t.initialState||{},null,2)),e.file("operations.json",JSON.stringify(t.operations,null,2)),Object.keys(t.attachments).forEach(m=>{const{data:r,...w}=t.attachments[m];e.file(m,r,{base64:!0,createFolders:!0,comment:JSON.stringify(w)})}),e},G=async(t,e,i,a)=>{const s=await(await T(t)).generateAsync({type:"uint8array",streamFiles:!0}),l=a??t.name,p=`.${i}.zip`;return Dt(e,l.endsWith(p)?l:`${l}${p}`,s)},At=async(t,e)=>{const a=await(await T(t)).generateAsync({type:"blob"}),o=await e.createWritable();await o.write(a),await o.close()},S=async(t,e)=>{const i=W(t);return Q(i,e)},Q=async(t,e)=>{const i=new q;return await i.loadAsync(t),Nt(i,e)};async function Nt(t,e){const i=t.file("state.json");if(!i)throw new Error("Initial state not found");const a=await i.async("string"),o=JSON.parse(a),s=t.file("header.json");let l=null;s&&(l=JSON.parse(await s.async("string")));const p=t.file("operations.json");if(!p)throw new Error("Operations history not found");const c=JSON.parse(await p.async("string")),m={...o,...l,initialState:o,operations:{global:[],local:[]},attachments:{...o.attachments}};let r=c.global.concat(c.local).slice(0,l==null?void 0:l.revision).reduce((w,pt)=>e(w,pt),m);return l&&(r={...r,...l,operations:{global:[...r.operations.global,...c.global.slice(l.revision)],local:r.operations.local}}),r}function V(t){const e=t.replace(/^.*\./,"")||void 0,i=t.replace(/^.*[/\\]/,"")||void 0;return{extension:e,fileName:i}}async function Tt(t){const{buffer:e,mimeType:i="application/octet-stream"}=await kt(t),a=V(t),o=e.toString("base64");return{data:o,hash:v(o),mimeType:i,...a}}async function Ft(t){const e=await Et(t),i=Ot.getType(t)||"application/octet-stream",a=V(t),o=e.toString("base64");return{data:o,hash:v(o),mimeType:i,...a}}function h(t,e,i,a){const o=at(t),s=et(i);return e.global.concat(e.local).reduce((l,p)=>s(l,p,a),o)}function qt(t,e){return{...t,name:e}}function Pt(t,e,i){const a=Math.min(e,t.revision),o=t.operations.global.slice(0,t.revision-a);return{...h(t.initialState,{global:o,local:t.operations.local},i),operations:t.operations,revision:t.revision-a}}function It(t,e,i){const a=t.operations.global.length-t.revision;if(!a)throw new Error("There is no UNDO operation to REDO");const o=e<a?e:a,s=t.operations.global.slice(0,t.revision+o);return{...h(t.initialState,{global:s,local:t.operations.local},i),operations:t.operations,revision:t.revision+o}}function Mt(t,e,i,a){e=e||0,i=i||t.operations.global.length;const o=t.operations.global.slice(e,i),s=t.operations.global.slice(0,e),l=t.operations.global.slice(i),p=h(t.initialState,{global:s.concat(o),local:t.operations.local},a),{name:c,state:m}=p;return h(t.initialState,{global:[...s,F({name:c,state:m},o.length),...l],local:t.operations.local},a)}function Rt(t,e){return{...t,name:e.name,state:e.state??{global:{},local:{}}}}const X="SET_NAME",y="UNDO",j="REDO",g="PRUNE",Y="LOAD_STATE";function Lt(t,e){return[y,j,g].includes(e.type)?t.revision:t.revision+1}function Ut(t,e){return{...t,revision:Lt(t,e),lastModified:new Date().toISOString()}}function Jt(t,e){if([y,j,g,g].includes(e.type))return t;const i=t.operations.global.slice(0,t.revision),a=t.operations.local.slice();return!e.scope||e.scope==="global"?i.push({...e,index:i.length,timestamp:new Date().toISOString(),hash:"",scope:"global"}):e.scope==="local"&&a.push({...e,index:a.length,timestamp:new Date().toISOString(),hash:"",scope:"local"}),{...t,operations:{global:i,local:a}}}function $t(t,e){let i=Jt(t,e);return(!e.scope||e.scope==="global")&&(i=Ut(i,e)),i}function Bt(t,e,i){switch(J().parse(e),e.type){case X:return qt(t,e.input);case y:return Pt(t,e.input,i);case j:return It(t,e.input,i);case g:return Mt(t,e.input.start,e.input.end,i);case Y:return Rt(t,e.input.state);default:return t}}function tt(t,e,i,a){let o=t;return _(e)&&(o=Bt(o,e,i)),o=$t(o,e),o=x.produce(o,s=>{const l=i(s.state,e,a);if(l)return x.castDraft({...o,state:l})}),x.produce(o,s=>{!e.scope||e.scope==="global"?s.operations.global[s.operations.global.length-1].hash=O(s,"global"):e.scope==="local"&&(s.operations.local[s.operations.local.length-1].hash=O(s,"local")),!_(e)&&e.attachments&&e.attachments.forEach(l=>{const{hash:p,...c}=l;s.attachments[p]={...c}})})}function _(t){return[X,y,j,g,Y].includes(t.type)}function u(t,e,i,a,o="global"){if(!t)throw new Error("Empty action type");if(typeof t!="string")throw new Error(`Invalid action type: ${t}`);const s={type:t,input:e,scope:o};i&&(s.attachments=i);try{a==null||a().parse(s.input)}catch(l){throw new Error(`Invalid action input: ${l}`)}return s}function et(t,e=tt){return(i,a,o)=>e(i,a,t,o)}const it=(t,e)=>({name:"",documentType:"",revision:0,created:new Date().toISOString(),lastModified:new Date().toISOString(),attachments:{},...t,state:(e==null?void 0:e(t==null?void 0:t.state))??(t==null?void 0:t.state)??{global:{},local:{}}}),at=(t,e)=>{const i=it(t,e);return{...i,initialState:i,operations:{global:[],local:[]}}},O=(t,e="global")=>v(mt(e==="local"?t.state.local:t.state.global)),Ct=(t,e=1e3)=>{const i=Math.random()*e;return v(`${(t??new Date).toISOString()}${i}`)};function d(t){return x.castImmutable(x.freeze(t,!0))}const ot=t=>u("SET_NAME",t,void 0,A),nt=(t=1)=>u("UNDO",t,void 0,N),st=(t=1)=>u("REDO",t,void 0,E),lt=(t,e)=>u("PRUNE",{start:t,end:e},void 0,k),F=(t,e)=>u("LOAD_STATE",{state:t,operations:e},void 0,D),Zt=Object.freeze(Object.defineProperty({__proto__:null,loadState:F,prune:lt,redo:st,setName:ot,undo:nt},Symbol.toStringTag,{value:"Module"}));class Ht{constructor(e,i,a){f(this,"_document");f(this,"_reducer");f(this,"_signalDispatch");this._reducer=e,this._document=i,this._signalDispatch=a}dispatch(e){return this._document=this._reducer(this._document,e,this._signalDispatch),this}saveToFile(e,i,a){return G(this._document,e,i,a)}async loadFromFile(e){this._document=await S(e,this._reducer)}static async stateFromFile(e,i){return await S(e,i)}get state(){return d(this._document.state)}get operations(){return d(this._document.operations)}get name(){return this._document.name}get documentType(){return this._document.documentType}get created(){return this._document.created}get lastModified(){return this._document.lastModified}get revision(){return this._document.revision}get initialState(){return d(this._document.initialState)}toDocument(){return d(this._document)}getAttachment(e){return this._document.attachments[e]}setName(e){return this.dispatch(ot(e)),this}undo(e){return this.dispatch(nt(e)),this}redo(e){return this.dispatch(st(e)),this}prune(e,i){return this.dispatch(lt(e,i)),this}loadState(e,i){return this.dispatch(F(e,i)),this}}function Kt(t,e){e.forEach(i=>{Object.getOwnPropertyNames(i.prototype).forEach(a=>{Object.defineProperty(t.prototype,a,Object.getOwnPropertyDescriptor(i.prototype,a)||Object.create(null))})})}exports.BaseActions=Zt;exports.BaseDocument=Ht;exports.applyMixins=Kt;exports.baseReducer=tt;exports.createAction=u;exports.createDocument=at;exports.createExtendedState=it;exports.createReducer=et;exports.createZip=T;exports.getLocalFile=Ft;exports.getRemoteFile=Tt;exports.hashDocument=O;exports.hashKey=Ct;exports.isBaseAction=_;exports.loadFromFile=S;exports.loadFromInput=Q;exports.readOnly=d;exports.saveToFile=G;exports.saveToFileHandle=At;exports.zod=yt;