@powerhousedao/shared 6.0.2-staging.8 → 6.1.0-dev.0

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 (73) hide show
  1. package/dist/actions-UH5nIJcP.d.ts +21068 -0
  2. package/dist/actions-UH5nIJcP.d.ts.map +1 -0
  3. package/dist/clis/args/access-token.mjs +1 -1
  4. package/dist/clis/args/{common-Bc8EcW9w.mjs → common-DPYlcz-d.mjs} +7 -1
  5. package/dist/clis/args/common-DPYlcz-d.mjs.map +1 -0
  6. package/dist/clis/args/{common-BQ2pvhCr.d.mts → common-Dmf4BGPa.d.mts} +3 -3
  7. package/dist/clis/args/{common-BQ2pvhCr.d.mts.map → common-Dmf4BGPa.d.mts.map} +1 -1
  8. package/dist/clis/args/common.d.mts +1 -1
  9. package/dist/clis/args/common.mjs +1 -1
  10. package/dist/clis/args/connect.d.mts +4 -4
  11. package/dist/clis/args/connect.mjs +1 -1
  12. package/dist/clis/args/{generate-DNGRYRdp.mjs → generate-BJPBa0mK.mjs} +2 -2
  13. package/dist/clis/args/{generate-DNGRYRdp.mjs.map → generate-BJPBa0mK.mjs.map} +1 -1
  14. package/dist/clis/args/generate.mjs +1 -1
  15. package/dist/clis/args/{help-CFAVJzhI.mjs → help-rztSuf9S.mjs} +3 -3
  16. package/dist/clis/args/{help-CFAVJzhI.mjs.map → help-rztSuf9S.mjs.map} +1 -1
  17. package/dist/clis/args/help.mjs +1 -1
  18. package/dist/clis/args/index.d.mts +2 -2
  19. package/dist/clis/args/index.mjs +3 -3
  20. package/dist/clis/args/init.mjs +1 -1
  21. package/dist/clis/args/inspect.mjs +1 -1
  22. package/dist/clis/args/install.mjs +1 -1
  23. package/dist/clis/args/list.mjs +1 -1
  24. package/dist/clis/args/login.mjs +1 -1
  25. package/dist/clis/args/migrate.mjs +1 -1
  26. package/dist/clis/args/publish.mjs +1 -1
  27. package/dist/clis/args/registry.mjs +1 -1
  28. package/dist/clis/args/service-LXIFUZ_8.d.mts +106 -0
  29. package/dist/clis/args/service-LXIFUZ_8.d.mts.map +1 -0
  30. package/dist/clis/args/service.d.mts +1 -1
  31. package/dist/clis/args/service.mjs +1 -1
  32. package/dist/clis/args/switchboard.d.mts +6 -0
  33. package/dist/clis/args/switchboard.d.mts.map +1 -1
  34. package/dist/clis/args/switchboard.mjs +12 -1
  35. package/dist/clis/args/switchboard.mjs.map +1 -1
  36. package/dist/clis/args/uninstall.mjs +1 -1
  37. package/dist/clis/args/unpublish.mjs +1 -1
  38. package/dist/clis/args/vetra.d.mts +4 -1
  39. package/dist/clis/args/vetra.d.mts.map +1 -1
  40. package/dist/clis/args/vetra.mjs +6 -1
  41. package/dist/clis/args/vetra.mjs.map +1 -1
  42. package/dist/clis/constants.d.mts +248 -1
  43. package/dist/clis/constants.d.mts.map +1 -1
  44. package/dist/clis/constants.mjs +139 -9
  45. package/dist/clis/constants.mjs.map +1 -1
  46. package/dist/clis/index.d.mts +276 -4
  47. package/dist/clis/index.d.mts.map +1 -1
  48. package/dist/clis/index.mjs +187 -15
  49. package/dist/clis/index.mjs.map +1 -1
  50. package/dist/clis/utils.d.mts +11 -1
  51. package/dist/clis/utils.d.mts.map +1 -1
  52. package/dist/clis/utils.mjs +17 -2
  53. package/dist/clis/utils.mjs.map +1 -1
  54. package/dist/document-drive/index.d.ts +2 -2
  55. package/dist/document-model/index.d.ts +3 -3
  56. package/dist/document-model/index.js +162 -59
  57. package/dist/document-model/index.js.map +1 -1
  58. package/dist/{index-dcU9nj_u.d.ts → index-DkRWfM_V.d.ts} +18 -7
  59. package/dist/index-DkRWfM_V.d.ts.map +1 -0
  60. package/dist/index.d.ts +3 -3
  61. package/dist/processors/index.d.ts +1 -1
  62. package/dist/registry/index.d.ts +1 -1
  63. package/dist/registry/index.js +6 -0
  64. package/dist/registry/index.js.map +1 -1
  65. package/dist/{types-DyMP31mD.d.ts → types-WzwAClp2.d.ts} +2 -2
  66. package/dist/{types-DyMP31mD.d.ts.map → types-WzwAClp2.d.ts.map} +1 -1
  67. package/package.json +17 -5
  68. package/dist/actions-_5ZcthYq.d.ts +0 -2444
  69. package/dist/actions-_5ZcthYq.d.ts.map +0 -1
  70. package/dist/clis/args/common-Bc8EcW9w.mjs.map +0 -1
  71. package/dist/clis/args/service-C88bN_g_.d.mts +0 -22
  72. package/dist/clis/args/service-C88bN_g_.d.mts.map +0 -1
  73. package/dist/index-dcU9nj_u.d.ts.map +0 -1
@@ -2,6 +2,7 @@ import { a as buildOperationSignatureParams, c as hex2ab, i as buildOperationSig
2
2
  import { generateMock } from "./mock.js";
3
3
  import { ZodError, z } from "zod";
4
4
  import { stringify } from "safe-stable-stringify";
5
+ import { strFromU8, strToU8, unzip, zip } from "fflate";
5
6
  import { castDraft, create, unsafe } from "mutative";
6
7
  import { pascalCase } from "change-case";
7
8
  //#region document-model/errors.ts
@@ -57,6 +58,7 @@ const Load_StateSchema = z.enum(["LOAD_STATE"]);
57
58
  const PruneSchema = z.enum(["PRUNE"]);
58
59
  const RedoSchema = z.enum(["REDO"]);
59
60
  const Set_NameSchema = z.enum(["SET_NAME"]);
61
+ const Set_PreferredEditorSchema = z.enum(["SET_PREFERRED_EDITOR"]);
60
62
  const UndoSchema = z.enum(["UNDO"]);
61
63
  function OperationScopeSchema() {
62
64
  return z.string();
@@ -67,6 +69,7 @@ function DocumentActionSchema() {
67
69
  PruneActionSchema(),
68
70
  RedoActionSchema(),
69
71
  SetNameActionSchema(),
72
+ SetPreferredEditorActionSchema(),
70
73
  UndoActionSchema()
71
74
  ]);
72
75
  }
@@ -139,6 +142,18 @@ function SetNameActionSchema() {
139
142
  scope: z.literal("global")
140
143
  });
141
144
  }
145
+ function SetPreferredEditorActionInputSchema() {
146
+ return z.object({ preferredEditor: z.string().nullable() });
147
+ }
148
+ function SetPreferredEditorActionSchema() {
149
+ return z.object({
150
+ id: z.string(),
151
+ timestampUtcMs: z.string().datetime(),
152
+ input: SetPreferredEditorActionInputSchema(),
153
+ type: Set_PreferredEditorSchema,
154
+ scope: z.literal("header")
155
+ });
156
+ }
142
157
  function UndoActionInputSchema() {
143
158
  return z.object({ count: z.number() });
144
159
  }
@@ -289,29 +304,29 @@ function DocumentModelInputSchema() {
289
304
  function DocumentModelGlobalStateSchema() {
290
305
  return z.object({
291
306
  __typename: z.literal("DocumentModelGlobalState").optional(),
292
- author: AuthorSchema(),
293
- description: z.string(),
294
- extension: z.string(),
295
307
  id: z.string(),
296
308
  name: z.string(),
309
+ author: AuthorSchema(),
310
+ extension: z.string(),
311
+ description: z.string(),
297
312
  specifications: z.array(DocumentSpecificationSchema())
298
313
  });
299
314
  }
300
315
  function DocumentSpecificationSchema() {
301
316
  return z.object({
302
317
  __typename: z.literal("DocumentSpecification").optional(),
303
- changeLog: z.array(z.string()),
304
- modules: z.array(ModuleSchema()),
305
318
  state: ScopeStateSchema(),
306
- version: z.number().int()
319
+ modules: z.array(ModuleSchema()),
320
+ version: z.number().int(),
321
+ changeLog: z.array(z.string())
307
322
  });
308
323
  }
309
324
  function ModuleSchema() {
310
325
  return z.object({
311
326
  __typename: z.literal("ModuleSpecification").optional(),
312
- description: z.string().nullable(),
313
327
  id: z.string(),
314
328
  name: z.string(),
329
+ description: z.string().nullable(),
315
330
  operations: z.array(OperationSpecificationSchema())
316
331
  });
317
332
  }
@@ -324,24 +339,24 @@ function MoveOperationInputSchema() {
324
339
  function OperationSpecificationSchema() {
325
340
  return z.object({
326
341
  __typename: z.literal("OperationSpecification").optional(),
327
- description: z.string().nullable(),
328
- errors: z.array(OperationErrorSchema()),
329
- examples: z.array(CodeExampleSchema()),
330
342
  id: z.string(),
331
343
  name: z.string().nullable(),
332
- reducer: z.string().nullable(),
344
+ description: z.string().nullable(),
333
345
  schema: z.string().nullable(),
334
346
  template: z.string().nullable(),
347
+ reducer: z.string().nullable(),
348
+ errors: z.array(OperationErrorSchema()),
349
+ examples: z.array(CodeExampleSchema()),
335
350
  scope: OperationScopeSchema()
336
351
  });
337
352
  }
338
353
  function OperationErrorSchema() {
339
354
  return z.object({
340
355
  __typename: z.literal("OperationErrorSpecification").optional(),
341
- code: z.string().nullable(),
342
- description: z.string().nullable(),
343
356
  id: z.string(),
344
357
  name: z.string().nullable(),
358
+ code: z.string().nullable(),
359
+ description: z.string().nullable(),
345
360
  template: z.string().nullable()
346
361
  });
347
362
  }
@@ -483,15 +498,15 @@ function SetStateSchemaInputSchema() {
483
498
  function StateSchema() {
484
499
  return z.object({
485
500
  __typename: z.literal("State").optional(),
501
+ schema: z.string(),
486
502
  examples: z.array(CodeExampleSchema()),
487
- initialValue: z.string(),
488
- schema: z.string()
503
+ initialValue: z.string()
489
504
  });
490
505
  }
491
506
  function ScopeStateSchema() {
492
507
  return z.object({
493
- global: StateSchema(),
494
- local: StateSchema()
508
+ local: StateSchema(),
509
+ global: StateSchema()
495
510
  });
496
511
  }
497
512
  function UpdateChangeLogItemInputSchema() {
@@ -714,6 +729,14 @@ async function verifyOperationSignature(signature, signer, verifyHandler) {
714
729
  * @category Actions
715
730
  */
716
731
  const setName = (name) => createAction("SET_NAME", typeof name === "string" ? { name } : name, void 0, SetNameActionInputSchema, "global");
732
+ /**
733
+ * Changes the preferred editor recorded in the document header meta.
734
+ *
735
+ * Passing `null` clears the preferred editor.
736
+ *
737
+ * @category Actions
738
+ */
739
+ const setPreferredEditor = (input) => createAction("SET_PREFERRED_EDITOR", typeof input === "object" && input !== null ? input : { preferredEditor: input }, void 0, SetPreferredEditorActionInputSchema, "header");
717
740
  const setModelName = (input) => createAction("SET_MODEL_NAME", { ...input }, void 0, SetModelNameInputSchema, "global");
718
741
  const setModelId = (input) => createAction("SET_MODEL_ID", { ...input }, void 0, SetModelIdInputSchema, "global");
719
742
  const setModelExtension = (input) => createAction("SET_MODEL_EXTENSION", { ...input }, void 0, SetModelExtensionInputSchema, "global");
@@ -765,6 +788,7 @@ const reorderChangeLogItems = (input) => createAction("REORDER_CHANGE_LOG_ITEMS"
765
788
  const releaseNewVersion = () => createAction("RELEASE_NEW_VERSION", {}, void 0, void 0, "global");
766
789
  const baseActions = {
767
790
  setName,
791
+ setPreferredEditor,
768
792
  undo,
769
793
  redo,
770
794
  prune,
@@ -1616,6 +1640,7 @@ function isUndo(action) {
1616
1640
  function isDocumentAction(action) {
1617
1641
  return [
1618
1642
  "SET_NAME",
1643
+ "SET_PREFERRED_EDITOR",
1619
1644
  "UNDO",
1620
1645
  "REDO",
1621
1646
  "PRUNE",
@@ -2211,6 +2236,27 @@ function setNameOperation(document, input) {
2211
2236
  }
2212
2237
  };
2213
2238
  }
2239
+ function setPreferredEditorOperation(document, input) {
2240
+ const existingMeta = document.header.meta ?? {};
2241
+ if (input.preferredEditor) return {
2242
+ ...document,
2243
+ header: {
2244
+ ...document.header,
2245
+ meta: {
2246
+ ...existingMeta,
2247
+ preferredEditor: input.preferredEditor
2248
+ }
2249
+ }
2250
+ };
2251
+ const { preferredEditor: _removed, ...rest } = existingMeta;
2252
+ return {
2253
+ ...document,
2254
+ header: {
2255
+ ...document.header,
2256
+ meta: rest
2257
+ }
2258
+ };
2259
+ }
2214
2260
  function undoOperation(document, action, skip) {
2215
2261
  const { scope } = action;
2216
2262
  return create({
@@ -2372,6 +2418,7 @@ function _baseReducer(document, action, wrappedReducer) {
2372
2418
  const parsedAction = DocumentActionSchema().parse(action);
2373
2419
  switch (parsedAction.type) {
2374
2420
  case "SET_NAME": return setNameOperation(document, parsedAction.input);
2421
+ case "SET_PREFERRED_EDITOR": return setPreferredEditorOperation(document, parsedAction.input);
2375
2422
  case "PRUNE": return pruneOperation(document, parsedAction.input, wrappedReducer);
2376
2423
  case "LOAD_STATE": return loadStateOperation(document, parsedAction.input);
2377
2424
  default: return document;
@@ -2517,16 +2564,16 @@ function baseReducer(document, action, customReducer, dispatch, options = {}) {
2517
2564
  });
2518
2565
  } catch (error) {
2519
2566
  const actionScopeOps = newDocument.operations[_action.scope];
2520
- if (!actionScopeOps) throw new Error(`No operations found for scope: ${_action.scope}`);
2567
+ if (!actionScopeOps) throw new Error(`No operations found for scope: ${_action.scope}`, { cause: error });
2521
2568
  const lastOperationIndex = actionScopeOps.length - 1;
2522
2569
  const draftScopeOps = draft.operations[_action.scope];
2523
- if (!draftScopeOps) throw new Error(`No operations found in draft for scope: ${_action.scope}`);
2570
+ if (!draftScopeOps) throw new Error(`No operations found in draft for scope: ${_action.scope}`, { cause: error });
2524
2571
  draftScopeOps[lastOperationIndex].error = error.message;
2525
2572
  draftScopeOps[lastOperationIndex].skip = 0;
2526
2573
  if (shouldProcessSkipOperation) {
2527
2574
  draft.state = castDraft({ ...document.state });
2528
2575
  const documentScopeOps = document.operations[_action.scope];
2529
- if (!documentScopeOps) throw new Error(`No operations found for scope: ${_action.scope}`);
2576
+ if (!documentScopeOps) throw new Error(`No operations found for scope: ${_action.scope}`, { cause: error });
2530
2577
  draft.operations = castDraft({
2531
2578
  ...document.operations,
2532
2579
  [_action.scope]: [...documentScopeOps, { ...draftScopeOps[lastOperationIndex] }]
@@ -2625,6 +2672,7 @@ const RESERVED_OPERATION_NAMES = [
2625
2672
  "PRUNE",
2626
2673
  "LOAD_STATE",
2627
2674
  "SET_NAME",
2675
+ "SET_PREFERRED_EDITOR",
2628
2676
  "NOOP"
2629
2677
  ];
2630
2678
  /**
@@ -2729,6 +2777,29 @@ function validateModuleOperation(operation) {
2729
2777
  });
2730
2778
  return errors;
2731
2779
  }
2780
+ /**
2781
+ * Find a module in the latest specification by id, or throw. Reducers that
2782
+ * mutate-by-id should call this up front so an unknown id fails loudly
2783
+ * instead of silently no-opping.
2784
+ */
2785
+ function findModuleOrThrow(state, moduleId) {
2786
+ const mod = state.specifications[state.specifications.length - 1]?.modules.find((m) => m.id === moduleId);
2787
+ if (!mod) throw new Error(`Module "${moduleId}" not found in the latest specification`);
2788
+ return mod;
2789
+ }
2790
+ /**
2791
+ * Find an operation in the latest specification by id, or throw. Same
2792
+ * rationale as findModuleOrThrow — reducers that target an operation must
2793
+ * fail loudly when the operation doesn't exist.
2794
+ */
2795
+ function findOperationOrThrow(state, operationId) {
2796
+ const latestSpec = state.specifications[state.specifications.length - 1];
2797
+ if (latestSpec) for (const mod of latestSpec.modules) {
2798
+ const op = mod.operations.find((o) => o.id === operationId);
2799
+ if (op) return op;
2800
+ }
2801
+ throw new Error(`Operation "${operationId}" not found in the latest specification`);
2802
+ }
2732
2803
  function validateOperations(operations) {
2733
2804
  const errors = [];
2734
2805
  const scopes = Object.keys(operations);
@@ -2813,8 +2884,7 @@ const documentModelModuleReducer = {
2813
2884
  };
2814
2885
  const documentModelOperationErrorReducer = {
2815
2886
  addOperationErrorOperation(state, action) {
2816
- const latestSpec = state.specifications[state.specifications.length - 1];
2817
- 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({
2887
+ findOperationOrThrow(state, action.input.operationId).errors.push({
2818
2888
  id: action.input.id,
2819
2889
  name: action.input.errorName || "",
2820
2890
  code: action.input.errorCode || "",
@@ -2871,8 +2941,7 @@ const documentModelOperationExampleReducer = {
2871
2941
  const documentModelOperationReducer = {
2872
2942
  addOperationOperation(state, action) {
2873
2943
  validateOperationName(action.input.name, state);
2874
- const latestSpec = state.specifications[state.specifications.length - 1];
2875
- for (let i = 0; i < latestSpec.modules.length; i++) if (latestSpec.modules[i].id == action.input.moduleId) latestSpec.modules[i].operations.push({
2944
+ findModuleOrThrow(state, action.input.moduleId).operations.push({
2876
2945
  id: action.input.id,
2877
2946
  name: action.input.name,
2878
2947
  description: action.input.description || "",
@@ -2890,8 +2959,11 @@ const documentModelOperationReducer = {
2890
2959
  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 || "";
2891
2960
  },
2892
2961
  setOperationScopeOperation(state, action) {
2962
+ const targetOp = findOperationOrThrow(state, action.input.id);
2893
2963
  const latestSpec = state.specifications[state.specifications.length - 1];
2894
- 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].scope = action.input.scope || "global";
2964
+ const allowedScopes = Object.keys(latestSpec.state);
2965
+ if (action.input.scope && !allowedScopes.includes(action.input.scope)) throw new Error(`Invalid scope: ${action.input.scope}`);
2966
+ targetOp.scope = action.input.scope || "global";
2895
2967
  },
2896
2968
  setOperationSchemaOperation(state, action) {
2897
2969
  const latestSpec = state.specifications[state.specifications.length - 1];
@@ -3190,18 +3262,50 @@ const documentModelReducer = createReducer(documentModelStateReducer);
3190
3262
  //#endregion
3191
3263
  //#region document-model/files.ts
3192
3264
  const NON_DOMAIN_SCOPES = new Set(["auth", "document"]);
3193
- async function loadJSZip() {
3194
- const { default: JSZip } = await import("jszip");
3195
- return JSZip;
3265
+ function zipAsync(data) {
3266
+ return new Promise((resolve, reject) => {
3267
+ zip(data, (err, out) => err ? reject(err) : resolve(out));
3268
+ });
3269
+ }
3270
+ function unzipAsync(data) {
3271
+ return new Promise((resolve, reject) => {
3272
+ unzip(data, (err, out) => err ? reject(err) : resolve(out));
3273
+ });
3274
+ }
3275
+ const BASE64_RE = /^[A-Za-z0-9+/]+={0,2}$/;
3276
+ function isLikelyBase64(s) {
3277
+ if (s.length === 0 || s.length % 4 !== 0) return false;
3278
+ return BASE64_RE.test(s);
3279
+ }
3280
+ function binaryStringToUint8Array(s) {
3281
+ const arr = new Uint8Array(s.length);
3282
+ for (let i = 0; i < s.length; i++) arr[i] = s.charCodeAt(i) & 255;
3283
+ return arr;
3284
+ }
3285
+ function base64ToUint8Array(s) {
3286
+ if (typeof atob === "function") return binaryStringToUint8Array(atob(s));
3287
+ const BufferCtor = globalThis.Buffer;
3288
+ if (!BufferCtor) throw new Error("Cannot decode base64 string: neither `atob` nor `Buffer` is available in this environment");
3289
+ return BufferCtor.from(s, "base64");
3290
+ }
3291
+ async function toUint8Array(input) {
3292
+ if (input instanceof Uint8Array) return input;
3293
+ if (input instanceof ArrayBuffer) return new Uint8Array(input);
3294
+ if (typeof Blob !== "undefined" && input instanceof Blob) return new Uint8Array(await input.arrayBuffer());
3295
+ if (Array.isArray(input)) return new Uint8Array(input);
3296
+ if (typeof input === "string") return isLikelyBase64(input) ? base64ToUint8Array(input) : binaryStringToUint8Array(input);
3297
+ throw new Error("Unsupported FileInput type");
3298
+ }
3299
+ function jsonEntry(value) {
3300
+ return strToU8(JSON.stringify(value, null, 2));
3196
3301
  }
3197
3302
  async function createZip(document) {
3198
- const zip = new (await (loadJSZip()))();
3199
- const header = document.header;
3200
- zip.file("header.json", JSON.stringify(header, null, 2));
3201
- zip.file("state.json", JSON.stringify(document.initialState || {}, null, 2));
3202
- zip.file("current-state.json", JSON.stringify(document.state || {}, null, 2));
3203
- zip.file("operations.json", JSON.stringify(filterDocumentOperationsResultingState(document.operations), null, 2));
3204
- return zip;
3303
+ return zipAsync({
3304
+ "header.json": jsonEntry(document.header),
3305
+ "state.json": jsonEntry(document.initialState || {}),
3306
+ "current-state.json": jsonEntry(document.state || {}),
3307
+ "operations.json": jsonEntry(filterDocumentOperationsResultingState(document.operations))
3308
+ });
3205
3309
  }
3206
3310
  /**
3207
3311
  * Creates a minimal ZIP backup from strand data.
@@ -3209,7 +3313,6 @@ async function createZip(document) {
3209
3313
  * Creates a ZIP with minimal header and empty operations.
3210
3314
  */
3211
3315
  async function createMinimalZip(data) {
3212
- const JSZip = await loadJSZip();
3213
3316
  const now = (/* @__PURE__ */ new Date()).toISOString();
3214
3317
  const header = {
3215
3318
  id: data.documentId,
@@ -3225,30 +3328,32 @@ async function createMinimalZip(data) {
3225
3328
  revision: {},
3226
3329
  lastModifiedAtUtcIso: now
3227
3330
  };
3228
- const zip = new JSZip();
3229
- zip.file("header.json", JSON.stringify(header, null, 2));
3230
- zip.file("state.json", JSON.stringify(data.state, null, 2));
3231
- zip.file("current-state.json", JSON.stringify(data.state, null, 2));
3232
- zip.file("operations.json", JSON.stringify({}, null, 2));
3233
- return zip;
3331
+ return zipAsync({
3332
+ "header.json": jsonEntry(header),
3333
+ "state.json": jsonEntry(data.state),
3334
+ "current-state.json": jsonEntry(data.state),
3335
+ "operations.json": jsonEntry({})
3336
+ });
3234
3337
  }
3235
3338
  async function baseSaveToFileHandle(document, input) {
3236
- const blob = await (await createZip(document)).generateAsync({ type: "blob" });
3339
+ const data = await createZip(document);
3237
3340
  const writable = await input.createWritable();
3238
- await writable.write(blob);
3341
+ await writable.write(new Uint8Array(data));
3239
3342
  await writable.close();
3240
3343
  }
3241
- async function loadFromZip(zip, reducer, options) {
3242
- const initialStateZip = zip.file("state.json");
3243
- if (!initialStateZip) throw new Error("Initial state not found");
3244
- const initialStateStr = await initialStateZip.async("string");
3245
- const initialState = JSON.parse(initialStateStr);
3246
- const headerZip = zip.file("header.json");
3247
- if (!headerZip) throw new Error("Document header not found - file format may be outdated");
3248
- const header = JSON.parse(await headerZip.async("string"));
3249
- const operationsZip = zip.file("operations.json");
3250
- if (!operationsZip) throw new Error("Operations history not found");
3251
- const clearedOperations = garbageCollectDocumentOperations(JSON.parse(await operationsZip.async("string")));
3344
+ function readEntry(files, name) {
3345
+ const entry = files[name];
3346
+ if (!entry) throw new Error(`${name} not found in document zip`);
3347
+ return strFromU8(entry);
3348
+ }
3349
+ async function loadFromZipData(data, reducer, options) {
3350
+ const files = await unzipAsync(data);
3351
+ if (!files["state.json"]) throw new Error("Initial state not found");
3352
+ const initialState = JSON.parse(readEntry(files, "state.json"));
3353
+ if (!files["header.json"]) throw new Error("Document header not found - file format may be outdated");
3354
+ const header = JSON.parse(readEntry(files, "header.json"));
3355
+ if (!files["operations.json"]) throw new Error("Operations history not found");
3356
+ const clearedOperations = garbageCollectDocumentOperations(JSON.parse(readEntry(files, "operations.json")));
3252
3357
  const operationsError = validateOperations(clearedOperations);
3253
3358
  if (operationsError.length) {
3254
3359
  const errorMessages = operationsError.map((err) => err.message);
@@ -3260,9 +3365,7 @@ async function loadFromZip(zip, reducer, options) {
3260
3365
  };
3261
3366
  }
3262
3367
  async function baseLoadFromInput(input, reducer, options) {
3263
- const zip = new (await (loadJSZip()))();
3264
- await zip.loadAsync(input);
3265
- return loadFromZip(zip, reducer, options);
3368
+ return loadFromZipData(await toUint8Array(input), reducer, options);
3266
3369
  }
3267
3370
  const documentModelLoadFromInput = (input) => {
3268
3371
  return baseLoadFromInput(input, documentModelReducer);
@@ -3382,6 +3485,6 @@ function createState(baseState, globalState, localState) {
3382
3485
  };
3383
3486
  }
3384
3487
  //#endregion
3385
- export { AddChangeLogItemInputSchema, AddModuleInputSchema, AddOperationErrorInputSchema, AddOperationExampleInputSchema, AddOperationInputSchema, AddStateExampleInputSchema, AuthorSchema, BaseDocumentHeaderSchema, BaseDocumentStateSchema, CodeExampleSchema, ConfigEntrySchema, ConfigEntryTypeSchema, DeleteChangeLogItemInputSchema, DeleteModuleInputSchema, DeleteOperationErrorInputSchema, DeleteOperationExampleInputSchema, DeleteOperationInputSchema, DeleteStateExampleInputSchema, DocumentActionSchema, DocumentFileSchema, DocumentModelGlobalStateSchema, DocumentModelHeaderSchema, DocumentModelInputSchema, DocumentModelPHStateSchema, DocumentModelSchema, DocumentSpecificationSchema, FileSystemError, HASH_ALGORITHM_SHA1, HASH_ALGORITHM_SHA256, HASH_ALGORITHM_SHA512, HASH_ENCODING_BASE64, HASH_ENCODING_HEX, HashMismatchError, IntegrityIssueSubType, IntegrityIssueType, InvalidActionInputError, InvalidActionInputZodError, LoadStateActionInputSchema, LoadStateActionSchema, LoadStateActionStateInputSchema, Load_StateSchema, ManifestSchema, ModuleSchema, MoveOperationInputSchema, OperationErrorSchema, OperationScopeSchema, OperationSpecificationSchema, PowerhouseModuleSchema, PowerhouseModulesSchema, PruneActionInputSchema, PruneActionSchema, PruneSchema, PublisherSchema, RESERVED_OPERATION_NAMES, RedoActionInputSchema, RedoActionSchema, RedoSchema, ReorderChangeLogItemsInputSchema, ReorderModuleOperationsInputSchema, ReorderModulesInputSchema, ReorderOperationErrorsInputSchema, ReorderOperationExamplesInputSchema, ReorderStateExamplesInputSchema, ScopeStateSchema, SetAuthorNameInputSchema, SetAuthorWebsiteInputSchema, SetInitialStateInputSchema, SetModelDescriptionInputSchema, SetModelExtensionInputSchema, SetModelIdInputSchema, SetModelNameInputSchema, SetModuleDescriptionInputSchema, SetModuleNameInputSchema, SetNameActionInputSchema, SetNameActionSchema, SetOperationDescriptionInputSchema, SetOperationErrorCodeInputSchema, SetOperationErrorDescriptionInputSchema, SetOperationErrorNameInputSchema, SetOperationErrorTemplateInputSchema, SetOperationNameInputSchema, SetOperationReducerInputSchema, SetOperationSchemaInputSchema, SetOperationScopeInputSchema, SetOperationTemplateInputSchema, SetStateSchemaInputSchema, Set_NameSchema, StateSchema, UndoActionInputSchema, UndoActionSchema, UndoSchema, UpdateChangeLogItemInputSchema, UpdateOperationExampleInputSchema, UpdateStateExampleInputSchema, ab2hex, actionContext, actionFromAction, actionSigner, actions, addChangeLogItem, addModule, addOperation, addOperationError, addOperationExample, addStateExample, addUndo, assertIsDocumentModelDocument, assertIsDocumentModelState, attachBranch, baseActions, baseCreateDocument, baseLoadFromInput, baseReducer, baseSaveToFileHandle, buildOperationSignature, buildOperationSignatureMessage, buildOperationSignatureParams, buildSignedAction, checkCleanedOperationsIntegrity, checkOperationsIntegrity, createAction, createAuthState, createBaseState, createDocumentState, createGlobalState, createLocalState, createMinimalZip, createPresignedHeader, createReducer, createSignedHeader, createSignedHeaderForSigner, createState, createVerificationSigner, createZip, defaultAuthState, defaultBaseState, defaultDocumentState, defaultGlobalState, defaultLocalState, defaultPHState, definedNonNullAnySchema, deleteChangeLogItem, deleteModule, deleteOperation, deleteOperationError, deleteOperationExample, deleteStateExample, deriveOperationId, diffOperations, documentModelActions, documentModelDocumentType, documentModelFileExtension, documentModelGlobalState, documentModelHeaderReducer, documentModelInitialGlobalState, documentModelInitialLocalState, documentModelLoadFromInput, documentModelModuleReducer, documentModelOperationErrorReducer, documentModelOperationExampleReducer, documentModelOperationReducer, documentModelReducer, documentModelSaveToFileHandle, documentModelStateReducer, documentModelStateSchemaReducer, documentModelVersioningReducer, fetchFileBrowser, filterDocumentOperationsResultingState, filterDuplicatedOperations, garbageCollect, garbageCollectDocumentOperations, garbageCollectV2, generateId, generateMock, getAllOperationNames, getDocumentLastModified, getFileBrowser, getUnixTimestamp, groupOperationsByScope, hashBrowser, hashDocumentStateForScope, hex2ab, isDefinedNonNullAny, isDocumentAction, isDocumentModelDocument, isDocumentModelState, isNoopOperation, isReservedOperationName, isUndo, isUndoRedo, loadState, loadStateOperation, mapSkippedOperations, mapSkippedOperationsV2, merge, moveOperation, nextSkipNumber, noop, operationExampleCreators, operationFromAction, operationFromOperation, operationWithContext, operationsAreEqual, parseResultingState, precedes, prepareOperations, processUndoRedo, prune, pruneOperation, readFileBrowser, readOnly, redo, redoOperation, releaseNewVersion, removeExistingOperations, reorderChangeLogItems, reorderModuleOperations, reorderModules, reorderOperationErrors, reorderOperationExamples, reorderStateExamples, replayDocument, replayOperations, reshuffleByTimestamp, reshuffleByTimestampAndIndex, setAuthorName, setAuthorWebsite, setInitialState, setModelDescription, setModelExtension, setModelId, setModelName, setModuleDescription, setModuleName, setName, setNameOperation, setOperationDescription, setOperationErrorCode, setOperationErrorDescription, setOperationErrorName, setOperationErrorTemplate, setOperationName, setOperationReducer, setOperationSchema, setOperationScope, setOperationTemplate, setStateSchema, sign, skipHeaderOperations, sortMappedOperations, sortOperations, split, undo, undoOperation, undoOperationV2, updateChangeLogItem, updateDocument, updateHeaderRevision, updateOperationExample, updateStateExample, validateHeader, validateInitialState, validateModule, validateModuleOperation, validateModules, validateOperationName, validateOperations, validateStateSchemaName, verify, verifyOperationSignature, writeFileBrowser };
3488
+ export { AddChangeLogItemInputSchema, AddModuleInputSchema, AddOperationErrorInputSchema, AddOperationExampleInputSchema, AddOperationInputSchema, AddStateExampleInputSchema, AuthorSchema, BaseDocumentHeaderSchema, BaseDocumentStateSchema, CodeExampleSchema, ConfigEntrySchema, ConfigEntryTypeSchema, DeleteChangeLogItemInputSchema, DeleteModuleInputSchema, DeleteOperationErrorInputSchema, DeleteOperationExampleInputSchema, DeleteOperationInputSchema, DeleteStateExampleInputSchema, DocumentActionSchema, DocumentFileSchema, DocumentModelGlobalStateSchema, DocumentModelHeaderSchema, DocumentModelInputSchema, DocumentModelPHStateSchema, DocumentModelSchema, DocumentSpecificationSchema, FileSystemError, HASH_ALGORITHM_SHA1, HASH_ALGORITHM_SHA256, HASH_ALGORITHM_SHA512, HASH_ENCODING_BASE64, HASH_ENCODING_HEX, HashMismatchError, IntegrityIssueSubType, IntegrityIssueType, InvalidActionInputError, InvalidActionInputZodError, LoadStateActionInputSchema, LoadStateActionSchema, LoadStateActionStateInputSchema, Load_StateSchema, ManifestSchema, ModuleSchema, MoveOperationInputSchema, OperationErrorSchema, OperationScopeSchema, OperationSpecificationSchema, PowerhouseModuleSchema, PowerhouseModulesSchema, PruneActionInputSchema, PruneActionSchema, PruneSchema, PublisherSchema, RESERVED_OPERATION_NAMES, RedoActionInputSchema, RedoActionSchema, RedoSchema, ReorderChangeLogItemsInputSchema, ReorderModuleOperationsInputSchema, ReorderModulesInputSchema, ReorderOperationErrorsInputSchema, ReorderOperationExamplesInputSchema, ReorderStateExamplesInputSchema, ScopeStateSchema, SetAuthorNameInputSchema, SetAuthorWebsiteInputSchema, SetInitialStateInputSchema, SetModelDescriptionInputSchema, SetModelExtensionInputSchema, SetModelIdInputSchema, SetModelNameInputSchema, SetModuleDescriptionInputSchema, SetModuleNameInputSchema, SetNameActionInputSchema, SetNameActionSchema, SetOperationDescriptionInputSchema, SetOperationErrorCodeInputSchema, SetOperationErrorDescriptionInputSchema, SetOperationErrorNameInputSchema, SetOperationErrorTemplateInputSchema, SetOperationNameInputSchema, SetOperationReducerInputSchema, SetOperationSchemaInputSchema, SetOperationScopeInputSchema, SetOperationTemplateInputSchema, SetPreferredEditorActionInputSchema, SetPreferredEditorActionSchema, SetStateSchemaInputSchema, Set_NameSchema, Set_PreferredEditorSchema, StateSchema, UndoActionInputSchema, UndoActionSchema, UndoSchema, UpdateChangeLogItemInputSchema, UpdateOperationExampleInputSchema, UpdateStateExampleInputSchema, ab2hex, actionContext, actionFromAction, actionSigner, actions, addChangeLogItem, addModule, addOperation, addOperationError, addOperationExample, addStateExample, addUndo, assertIsDocumentModelDocument, assertIsDocumentModelState, attachBranch, baseActions, baseCreateDocument, baseLoadFromInput, baseReducer, baseSaveToFileHandle, buildOperationSignature, buildOperationSignatureMessage, buildOperationSignatureParams, buildSignedAction, checkCleanedOperationsIntegrity, checkOperationsIntegrity, createAction, createAuthState, createBaseState, createDocumentState, createGlobalState, createLocalState, createMinimalZip, createPresignedHeader, createReducer, createSignedHeader, createSignedHeaderForSigner, createState, createVerificationSigner, createZip, defaultAuthState, defaultBaseState, defaultDocumentState, defaultGlobalState, defaultLocalState, defaultPHState, definedNonNullAnySchema, deleteChangeLogItem, deleteModule, deleteOperation, deleteOperationError, deleteOperationExample, deleteStateExample, deriveOperationId, diffOperations, documentModelActions, documentModelDocumentType, documentModelFileExtension, documentModelGlobalState, documentModelHeaderReducer, documentModelInitialGlobalState, documentModelInitialLocalState, documentModelLoadFromInput, documentModelModuleReducer, documentModelOperationErrorReducer, documentModelOperationExampleReducer, documentModelOperationReducer, documentModelReducer, documentModelSaveToFileHandle, documentModelStateReducer, documentModelStateSchemaReducer, documentModelVersioningReducer, fetchFileBrowser, filterDocumentOperationsResultingState, filterDuplicatedOperations, findModuleOrThrow, findOperationOrThrow, garbageCollect, garbageCollectDocumentOperations, garbageCollectV2, generateId, generateMock, getAllOperationNames, getDocumentLastModified, getFileBrowser, getUnixTimestamp, groupOperationsByScope, hashBrowser, hashDocumentStateForScope, hex2ab, isDefinedNonNullAny, isDocumentAction, isDocumentModelDocument, isDocumentModelState, isNoopOperation, isReservedOperationName, isUndo, isUndoRedo, loadState, loadStateOperation, mapSkippedOperations, mapSkippedOperationsV2, merge, moveOperation, nextSkipNumber, noop, operationExampleCreators, operationFromAction, operationFromOperation, operationWithContext, operationsAreEqual, parseResultingState, precedes, prepareOperations, processUndoRedo, prune, pruneOperation, readFileBrowser, readOnly, redo, redoOperation, releaseNewVersion, removeExistingOperations, reorderChangeLogItems, reorderModuleOperations, reorderModules, reorderOperationErrors, reorderOperationExamples, reorderStateExamples, replayDocument, replayOperations, reshuffleByTimestamp, reshuffleByTimestampAndIndex, setAuthorName, setAuthorWebsite, setInitialState, setModelDescription, setModelExtension, setModelId, setModelName, setModuleDescription, setModuleName, setName, setNameOperation, setOperationDescription, setOperationErrorCode, setOperationErrorDescription, setOperationErrorName, setOperationErrorTemplate, setOperationName, setOperationReducer, setOperationSchema, setOperationScope, setOperationTemplate, setPreferredEditor, setPreferredEditorOperation, setStateSchema, sign, skipHeaderOperations, sortMappedOperations, sortOperations, split, undo, undoOperation, undoOperationV2, updateChangeLogItem, updateDocument, updateHeaderRevision, updateOperationExample, updateStateExample, validateHeader, validateInitialState, validateModule, validateModuleOperation, validateModules, validateOperationName, validateOperations, validateStateSchemaName, verify, verifyOperationSignature, writeFileBrowser };
3386
3489
 
3387
3490
  //# sourceMappingURL=index.js.map