@powerhousedao/shared 6.2.3-dev.1 → 6.2.3-dev.10

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 (37) hide show
  1. package/dist/clis/args/common-CcYbXrBx.mjs.map +1 -1
  2. package/dist/clis/build-config.d.mts.map +1 -1
  3. package/dist/clis/build-config.mjs +6 -1
  4. package/dist/clis/build-config.mjs.map +1 -1
  5. package/dist/clis/constants.d.mts +13 -0
  6. package/dist/clis/constants.d.mts.map +1 -1
  7. package/dist/clis/constants.mjs +8 -0
  8. package/dist/clis/constants.mjs.map +1 -1
  9. package/dist/clis/index.d.mts +21 -8
  10. package/dist/clis/index.d.mts.map +1 -1
  11. package/dist/clis/index.mjs +8 -0
  12. package/dist/clis/index.mjs.map +1 -1
  13. package/dist/connect/config-loader.d.ts +1 -1
  14. package/dist/connect/index.d.ts +1 -1
  15. package/dist/document-drive/index.d.ts +43 -3
  16. package/dist/document-drive/index.d.ts.map +1 -1
  17. package/dist/document-drive/index.js +94 -34
  18. package/dist/document-drive/index.js.map +1 -1
  19. package/dist/document-model/index.d.ts +2 -2
  20. package/dist/document-model/index.js +1 -0
  21. package/dist/document-model/index.js.map +1 -1
  22. package/dist/{index-DyYIJtVy.d.ts → index-DP3QgHTq.d.ts} +2 -2
  23. package/dist/{index-DyYIJtVy.d.ts.map → index-DP3QgHTq.d.ts.map} +1 -1
  24. package/dist/index.d.ts +2 -2
  25. package/dist/processors/index.d.ts +1 -1
  26. package/dist/registry/index.d.ts +2 -2
  27. package/dist/registry/index.js.map +1 -1
  28. package/dist/registry/manifest-slim.d.ts +1 -1
  29. package/dist/registry/manifest-slim.d.ts.map +1 -1
  30. package/dist/registry/manifest-slim.js +2 -1
  31. package/dist/registry/manifest-slim.js.map +1 -1
  32. package/dist/{types-CpnWmiFY.d.ts → types-BIoOWpOT.d.ts} +6 -1
  33. package/dist/types-BIoOWpOT.d.ts.map +1 -0
  34. package/dist/{types-YqLqb0Zb.d.ts → types-DDpRvBK_.d.ts} +2 -2
  35. package/dist/{types-YqLqb0Zb.d.ts.map → types-DDpRvBK_.d.ts.map} +1 -1
  36. package/package.json +1 -1
  37. package/dist/types-CpnWmiFY.d.ts.map +0 -1
@@ -1,4 +1,4 @@
1
- import { D as PHConnectRuntimeConfig } from "../types-CpnWmiFY.js";
1
+ import { D as PHConnectRuntimeConfig } from "../types-BIoOWpOT.js";
2
2
 
3
3
  //#region connect/config-loader.d.ts
4
4
  /** Recursive Partial. Arrays are leaves — `write({ packages: [...] })`
@@ -1,4 +1,4 @@
1
- import { D as PHConnectRuntimeConfig, I as PowerhouseConfig, L as PowerhousePackage, S as PHConnectPwaUrlPattern, _ as PHConnectPwaCacheStrategy, b as PHConnectPwaManifest, g as PHConnectPwa, v as PHConnectPwaFileHandler, x as PHConnectPwaRuntimeCaching, y as PHConnectPwaIcon } from "../types-CpnWmiFY.js";
1
+ import { D as PHConnectRuntimeConfig, I as PowerhouseConfig, L as PowerhousePackage, S as PHConnectPwaUrlPattern, _ as PHConnectPwaCacheStrategy, b as PHConnectPwaManifest, g as PHConnectPwa, v as PHConnectPwaFileHandler, x as PHConnectPwaRuntimeCaching, y as PHConnectPwaIcon } from "../types-BIoOWpOT.js";
2
2
  import { ConfigAdapter, ConfigLoader, ConfigShape, DeepPartial, deepMerge } from "./config-loader.js";
3
3
  import { JsonConfigAdapter, JsonConfigAdapterOptions } from "./json-adapter.js";
4
4
  import { z } from "zod";
@@ -1,5 +1,5 @@
1
- import { Bt as DocumentModelGlobalState, En as IsStateOfType, On as LoadFromInput, Qu as PHBaseState, Rn as Maybe, Tn as IsDocumentOfType, bi as SaveToFileHandle, ei as Reducer, gt as CreateDocument, ot as AssertIsDocumentOfType, st as AssertIsStateOfType, yt as CreateState } from "../types-CpnWmiFY.js";
2
- import { $ as LegacySynchronizationUnit, A as TriggerData, C as RemoveTriggerInput, D as SetSharingTypeInput, E as SetDriveNameInput, G as DriveInput, J as SharingType, K as GenerateNodesCopyIdGenerator, M as TriggerType, N as UpdateFileInput, O as TransmitterType, P as UpdateNodeInput, Q as LegacyAddFileInput, S as RemoveListenerInput, T as SetDriveIconInput, U as DocumentDrivePHState, W as DriveDocumentModelModule, X as DocumentDriveDocument, Y as DocumentDriveAction, Z as LegacyAddFileAction, _ as ListenerInput, _t as SetDriveNameAction, a as CopyNodeInput, at as DocumentDriveNodeOperations, b as PullResponderTriggerData, c as DocumentDriveLocalState, ct as UpdateNodeAction, d as FolderNode, dt as DocumentDriveDriveAction, et as AddFileAction, f as Listener, ft as DocumentDriveDriveOperations, g as ListenerFilterInput, gt as SetDriveIconAction, h as ListenerFilter, ht as SetAvailableOfflineAction, i as AddTriggerInput, it as DocumentDriveNodeAction, j as TriggerInput, k as Trigger, l as DocumentDrivePHState$1, lt as AddListenerAction, m as ListenerCallInfoInput, mt as RemoveTriggerAction, n as AddFolderInput, nt as CopyNodeAction, o as DeleteNodeInput, ot as MoveNodeAction, p as ListenerCallInfo, pt as RemoveListenerAction, q as GenerateNodesCopySrc, r as AddListenerInput, rt as DeleteNodeAction, s as DocumentDriveGlobalState, st as UpdateFileAction, t as AddFileInput, tt as AddFolderAction, u as FileNode, ut as AddTriggerAction, v as MoveNodeInput, vt as SetSharingTypeAction, w as SetAvailableOfflineInput, x as PullResponderTriggerDataInput, y as Node } from "../types-YqLqb0Zb.js";
1
+ import { Bt as DocumentModelGlobalState, En as IsStateOfType, On as LoadFromInput, Qu as PHBaseState, Rn as Maybe, Tn as IsDocumentOfType, bi as SaveToFileHandle, ei as Reducer, gt as CreateDocument, ot as AssertIsDocumentOfType, st as AssertIsStateOfType, yt as CreateState } from "../types-BIoOWpOT.js";
2
+ import { $ as LegacySynchronizationUnit, A as TriggerData, C as RemoveTriggerInput, D as SetSharingTypeInput, E as SetDriveNameInput, G as DriveInput, J as SharingType, K as GenerateNodesCopyIdGenerator, M as TriggerType, N as UpdateFileInput, O as TransmitterType, P as UpdateNodeInput, Q as LegacyAddFileInput, S as RemoveListenerInput, T as SetDriveIconInput, U as DocumentDrivePHState, W as DriveDocumentModelModule, X as DocumentDriveDocument, Y as DocumentDriveAction, Z as LegacyAddFileAction, _ as ListenerInput, _t as SetDriveNameAction, a as CopyNodeInput, at as DocumentDriveNodeOperations, b as PullResponderTriggerData, c as DocumentDriveLocalState, ct as UpdateNodeAction, d as FolderNode, dt as DocumentDriveDriveAction, et as AddFileAction, f as Listener, ft as DocumentDriveDriveOperations, g as ListenerFilterInput, gt as SetDriveIconAction, h as ListenerFilter, ht as SetAvailableOfflineAction, i as AddTriggerInput, it as DocumentDriveNodeAction, j as TriggerInput, k as Trigger, l as DocumentDrivePHState$1, lt as AddListenerAction, m as ListenerCallInfoInput, mt as RemoveTriggerAction, n as AddFolderInput, nt as CopyNodeAction, o as DeleteNodeInput, ot as MoveNodeAction, p as ListenerCallInfo, pt as RemoveListenerAction, q as GenerateNodesCopySrc, r as AddListenerInput, rt as DeleteNodeAction, s as DocumentDriveGlobalState, st as UpdateFileAction, t as AddFileInput, tt as AddFolderAction, u as FileNode, ut as AddTriggerAction, v as MoveNodeInput, vt as SetSharingTypeAction, w as SetAvailableOfflineInput, x as PullResponderTriggerDataInput, y as Node } from "../types-DDpRvBK_.js";
3
3
  import { z } from "zod";
4
4
 
5
5
  //#region document-drive/constants.d.ts
@@ -212,6 +212,46 @@ declare function getDescendants(node: Node, allNodes: Node[]): Node[];
212
212
  declare function generateNodesCopy(src: GenerateNodesCopySrc, idGenerator: GenerateNodesCopyIdGenerator, nodes: Node[]): CopyNodeInput[];
213
213
  declare function getNextCopyNumber(files: string[], baseFilename: string): number;
214
214
  declare function escapeRegExp(string: string): string;
215
+ /**
216
+ * A plain, unfrozen copy of the node list for read-only scans. Inside a
217
+ * mutative draft the copy is taken from the untouched base list, so a find or
218
+ * filter over it does not create a child draft per element it visits, and it is
219
+ * a copy because the stored list is frozen and V8 scans a frozen array several
220
+ * times slower than a normal one. Callers must read before they write: the base
221
+ * list does not see mutations made earlier in the same action.
222
+ */
223
+ declare function readNodes(state: {
224
+ nodes: Node[];
225
+ }): Node[];
226
+ /**
227
+ * A copy of the given list, sorted by id and frozen, which is the shape the
228
+ * node reducer assigns. Read the list with readNodes, build the new list from
229
+ * it, and pass what this returns to assignNodes. The copy is what keeps the
230
+ * freeze off the caller's array.
231
+ */
232
+ declare function sortNodesById(nodes: readonly Node[]): readonly Node[];
233
+ /**
234
+ * The node list with a node added, ordered by id and frozen, in the same shape
235
+ * sortNodesById returns. The list is built and sorted as plain objects, so
236
+ * inside a mutative draft the comparator never reads an element through the
237
+ * draft proxy. Pass the list read with readNodes: the draft's own list would
238
+ * put child drafts in the result, which the freeze then keeps mutative from
239
+ * resolving.
240
+ */
241
+ declare function insertNodeSorted(nodes: readonly Node[], node: Node): readonly Node[];
242
+ /**
243
+ * Installs a node list as state.nodes. Every assignment the node reducer makes
244
+ * goes through here, and this is the one place a frozen array crosses into
245
+ * state: the generated DocumentDriveGlobalState types nodes as a mutable
246
+ * Node[], so the cast below is where that gap is paid rather than spread over
247
+ * the reducer. Consumers must treat drive.state.global.nodes as read-only --
248
+ * mutating it in place (push, sort, splice) throws in strict mode; copy it
249
+ * first, as readNodes does. Note that LOAD_STATE replaces a whole scope and can
250
+ * install a list this function never saw.
251
+ */
252
+ declare function assignNodes(state: {
253
+ nodes: Node[];
254
+ }, nodes: readonly Node[]): void;
215
255
  declare function handleTargetNameCollisions(params: {
216
256
  nodes: Node[];
217
257
  targetParentFolder: string | null;
@@ -220,5 +260,5 @@ declare function handleTargetNameCollisions(params: {
220
260
  }): string;
221
261
  declare const isValidName: (name: string) => boolean;
222
262
  //#endregion
223
- export { AddFileAction, AddFileInput, AddFileInputSchema, AddFolderAction, AddFolderInput, AddFolderInputSchema, AddListenerAction, AddListenerInput, AddListenerInputSchema, AddTriggerAction, AddTriggerInput, AddTriggerInputSchema, CopyNodeAction, CopyNodeInput, CopyNodeInputSchema, DeleteNodeAction, DeleteNodeInput, DeleteNodeInputSchema, DocumentDriveAction, DocumentDriveDocument, DocumentDriveDriveAction, DocumentDriveDriveOperations, DocumentDriveGlobalState, DocumentDriveLocalState, DocumentDriveLocalStateSchema, DocumentDriveNodeAction, DocumentDriveNodeOperations, DocumentDrivePHState, DocumentDriveStateSchema, DriveDocumentHeaderSchema, DriveDocumentModelModule, DriveDocumentSchema, DriveInput, DrivePHStateSchema, FileNode, FileNodeSchema, FolderNode, FolderNodeSchema, GenerateNodesCopyIdGenerator, GenerateNodesCopySrc, LegacyAddFileAction, LegacyAddFileInput, LegacySynchronizationUnit, Listener, ListenerCallInfo, ListenerCallInfoInput, ListenerCallInfoInputSchema, ListenerCallInfoSchema, ListenerFilter, ListenerFilterInput, ListenerFilterInputSchema, ListenerFilterSchema, ListenerInput, ListenerInputSchema, ListenerSchema, MoveNodeAction, MoveNodeInput, MoveNodeInputSchema, Node, NodeSchema, PullResponderTriggerData, PullResponderTriggerDataInput, PullResponderTriggerDataInputSchema, PullResponderTriggerDataSchema, RemoveListenerAction, RemoveListenerInput, RemoveListenerInputSchema, RemoveTriggerAction, RemoveTriggerInput, RemoveTriggerInputSchema, SetAvailableOfflineAction, SetAvailableOfflineInput, SetAvailableOfflineInputSchema, SetDriveIconAction, SetDriveIconInput, SetDriveIconInputSchema, SetDriveNameAction, SetDriveNameInput, SetDriveNameInputSchema, SetSharingTypeAction, SetSharingTypeInput, SetSharingTypeInputSchema, SharingType, TransmitterType, TransmitterTypeSchema, Trigger, TriggerData, TriggerDataSchema, TriggerInput, TriggerInputSchema, TriggerSchema, TriggerType, TriggerTypeSchema, UpdateFileAction, UpdateFileInput, UpdateFileInputSchema, UpdateNodeAction, UpdateNodeInput, UpdateNodeInputSchema, addFile, addFolder, addListener, addTrigger, assertIsDocumentOfType, assertIsDriveDocument, assertIsDriveState, assertIsStateOfType, copyNode, createGlobalState, createLocalState, createState, defaultGlobalState, defaultLocalState, defaultPHState, definedNonNullAnySchema, deleteNode, driveCreateDocument, driveCreateState, driveDocumentFileExtension, driveDocumentModel, driveDocumentModelModule, driveDocumentReducer, driveDocumentType, driveLoadFromInput, driveReducer, driveSaveToFileHandle, escapeRegExp, generateNodesCopy, getAncestors, getDescendants, getNextCopyNumber, handleTargetNameCollisions, initialGlobalState, initialLocalState, isDefinedNonNullAny, isDocumentOfType, isDriveDocument, isDriveState, isFileNode, isFolderNode, isStateOfType, isValidName, moveNode, nodeReducer, removeListener, removeTrigger, setAvailableOffline, setDriveIcon, setDriveName, setSharingType, updateFile, updateNode };
263
+ export { AddFileAction, AddFileInput, AddFileInputSchema, AddFolderAction, AddFolderInput, AddFolderInputSchema, AddListenerAction, AddListenerInput, AddListenerInputSchema, AddTriggerAction, AddTriggerInput, AddTriggerInputSchema, CopyNodeAction, CopyNodeInput, CopyNodeInputSchema, DeleteNodeAction, DeleteNodeInput, DeleteNodeInputSchema, DocumentDriveAction, DocumentDriveDocument, DocumentDriveDriveAction, DocumentDriveDriveOperations, DocumentDriveGlobalState, DocumentDriveLocalState, DocumentDriveLocalStateSchema, DocumentDriveNodeAction, DocumentDriveNodeOperations, DocumentDrivePHState, DocumentDriveStateSchema, DriveDocumentHeaderSchema, DriveDocumentModelModule, DriveDocumentSchema, DriveInput, DrivePHStateSchema, FileNode, FileNodeSchema, FolderNode, FolderNodeSchema, GenerateNodesCopyIdGenerator, GenerateNodesCopySrc, LegacyAddFileAction, LegacyAddFileInput, LegacySynchronizationUnit, Listener, ListenerCallInfo, ListenerCallInfoInput, ListenerCallInfoInputSchema, ListenerCallInfoSchema, ListenerFilter, ListenerFilterInput, ListenerFilterInputSchema, ListenerFilterSchema, ListenerInput, ListenerInputSchema, ListenerSchema, MoveNodeAction, MoveNodeInput, MoveNodeInputSchema, Node, NodeSchema, PullResponderTriggerData, PullResponderTriggerDataInput, PullResponderTriggerDataInputSchema, PullResponderTriggerDataSchema, RemoveListenerAction, RemoveListenerInput, RemoveListenerInputSchema, RemoveTriggerAction, RemoveTriggerInput, RemoveTriggerInputSchema, SetAvailableOfflineAction, SetAvailableOfflineInput, SetAvailableOfflineInputSchema, SetDriveIconAction, SetDriveIconInput, SetDriveIconInputSchema, SetDriveNameAction, SetDriveNameInput, SetDriveNameInputSchema, SetSharingTypeAction, SetSharingTypeInput, SetSharingTypeInputSchema, SharingType, TransmitterType, TransmitterTypeSchema, Trigger, TriggerData, TriggerDataSchema, TriggerInput, TriggerInputSchema, TriggerSchema, TriggerType, TriggerTypeSchema, UpdateFileAction, UpdateFileInput, UpdateFileInputSchema, UpdateNodeAction, UpdateNodeInput, UpdateNodeInputSchema, addFile, addFolder, addListener, addTrigger, assertIsDocumentOfType, assertIsDriveDocument, assertIsDriveState, assertIsStateOfType, assignNodes, copyNode, createGlobalState, createLocalState, createState, defaultGlobalState, defaultLocalState, defaultPHState, definedNonNullAnySchema, deleteNode, driveCreateDocument, driveCreateState, driveDocumentFileExtension, driveDocumentModel, driveDocumentModelModule, driveDocumentReducer, driveDocumentType, driveLoadFromInput, driveReducer, driveSaveToFileHandle, escapeRegExp, generateNodesCopy, getAncestors, getDescendants, getNextCopyNumber, handleTargetNameCollisions, initialGlobalState, initialLocalState, insertNodeSorted, isDefinedNonNullAny, isDocumentOfType, isDriveDocument, isDriveState, isFileNode, isFolderNode, isStateOfType, isValidName, moveNode, nodeReducer, readNodes, removeListener, removeTrigger, setAvailableOffline, setDriveIcon, setDriveName, setSharingType, sortNodesById, updateFile, updateNode };
224
264
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../document-drive/constants.ts","../../document-drive/gen/node/creators.ts","../../document-drive/gen/drive/creators.ts","../../document-drive/gen/document-model.ts","../../document-drive/gen/document-schema.ts","../../document-drive/gen/document-type.ts","../../document-drive/gen/ph-factories.ts","../../document-drive/gen/reducer.ts","../../document-drive/gen/schema/zod.ts","../../document-drive/gen/utils.ts","../../document-drive/module.ts","../../document-drive/src/reducers/drive.ts","../../document-drive/src/reducers/node.ts","../../document-drive/src/utils.ts"],"mappings":";;;;;cAAa,0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c,sBAAA;AAAA,cAI7B,mBAAA,EAAqB,mBAAA,CAAoB,sBAAA;AAAA,cAMzC,gBAAA,EAAkB,gBAAA,CAAiB,sBAAA;AAAA,cAMnC,sBAAA,EAAwB,sBAAA,CACnC,sBAAA;;;cCrEW,wBAAA,EAA0B,wBAAA;;;cCP1B,YAAA,EAAc,4BAAA;;;cCOd,WAAA,EAAa,2BAAA;;;iBCLV,UAAA,CAAW,IAAA,EAAM,IAAA,GAAO,IAAA,IAAQ,QAAA;AAAA,iBAIhC,YAAA,CAAa,IAAA,EAAM,IAAA,GAAO,IAAA,IAAQ,UAAA;AAAA,iBAIlC,YAAA,CAAa,IAAA,EAAM,IAAA,EAAM,QAAA,EAAU,IAAA,KAAS,IAAA;AAAA,iBAY5C,cAAA,CAAe,IAAA,EAAM,IAAA,EAAM,QAAA,EAAU,IAAA,KAAS,IAAA;;;Ab/B9D;;;;;;iBa6CgB,iBAAA,CACd,GAAA,EAAK,oBAAA,EACL,WAAA,EAAa,4BAAA,EACb,KAAA,EAAO,IAAA,KACN,aAAA;AAAA,iBA6Ca,iBAAA,CACd,KAAA,YACA,YAAA;AAAA,iBAsBc,YAAA,CAAa,MAAA;AAAA,iBAIb,0BAAA,CAA2B,MAAA;EACzC,KAAA,EAAO,IAAA;EACP,kBAAA;EACA,OAAA;EACA,OAAA;AAAA;AAAA,cAsBW,WAAA,GAAe,IAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../document-drive/constants.ts","../../document-drive/gen/node/creators.ts","../../document-drive/gen/drive/creators.ts","../../document-drive/gen/document-model.ts","../../document-drive/gen/document-schema.ts","../../document-drive/gen/document-type.ts","../../document-drive/gen/ph-factories.ts","../../document-drive/gen/reducer.ts","../../document-drive/gen/schema/zod.ts","../../document-drive/gen/utils.ts","../../document-drive/module.ts","../../document-drive/src/reducers/drive.ts","../../document-drive/src/reducers/node.ts","../../document-drive/src/utils.ts"],"mappings":";;;;;cAAa,0BAAA;;;;;;iBCiCG,OAAA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ocument, baseLoadFromInput, baseSaveToFileHandle, createAction, createBaseState, createReducer, createState as createState$1, defaultBaseState, isDocumentAction } from "../document-model/index.js";
2
2
  import { z } from "zod";
3
+ import { isDraft, original } from "mutative";
3
4
  //#region \0rolldown/runtime.js
4
5
  var __defProp = Object.defineProperty;
5
6
  var __exportAll = (all, no_symbols) => {
@@ -673,6 +674,65 @@ function getNextCopyNumber(files, baseFilename) {
673
674
  function escapeRegExp(string) {
674
675
  return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
675
676
  }
677
+ /**
678
+ * A plain, unfrozen copy of the node list for read-only scans. Inside a
679
+ * mutative draft the copy is taken from the untouched base list, so a find or
680
+ * filter over it does not create a child draft per element it visits, and it is
681
+ * a copy because the stored list is frozen and V8 scans a frozen array several
682
+ * times slower than a normal one. Callers must read before they write: the base
683
+ * list does not see mutations made earlier in the same action.
684
+ */
685
+ function readNodes(state) {
686
+ return [...isDraft(state) ? original(state).nodes : state.nodes];
687
+ }
688
+ /**
689
+ * The given array sorted by id and frozen, in place -- it takes ownership of
690
+ * the array it is handed, which is why it is private to this module and only
691
+ * ever given a list built at the call site. The freeze is what makes assigning
692
+ * the list to a mutative draft cheap: assigning a draftable value to a draft
693
+ * property queues a finalize pass that walks every element of the assigned
694
+ * value, and the walk exits at its Object.isFrozen check instead. Elements must
695
+ * be plain nodes -- an element that is still a draft would never be replaced by
696
+ * its final value, because the walk that does that replacement is the one being
697
+ * skipped.
698
+ */
699
+ function freezeSortedById(nodes) {
700
+ nodes.sort((a, b) => a.id.localeCompare(b.id));
701
+ return Object.freeze(nodes);
702
+ }
703
+ /**
704
+ * A copy of the given list, sorted by id and frozen, which is the shape the
705
+ * node reducer assigns. Read the list with readNodes, build the new list from
706
+ * it, and pass what this returns to assignNodes. The copy is what keeps the
707
+ * freeze off the caller's array.
708
+ */
709
+ function sortNodesById(nodes) {
710
+ return freezeSortedById([...nodes]);
711
+ }
712
+ /**
713
+ * The node list with a node added, ordered by id and frozen, in the same shape
714
+ * sortNodesById returns. The list is built and sorted as plain objects, so
715
+ * inside a mutative draft the comparator never reads an element through the
716
+ * draft proxy. Pass the list read with readNodes: the draft's own list would
717
+ * put child drafts in the result, which the freeze then keeps mutative from
718
+ * resolving.
719
+ */
720
+ function insertNodeSorted(nodes, node) {
721
+ return freezeSortedById([...nodes, node]);
722
+ }
723
+ /**
724
+ * Installs a node list as state.nodes. Every assignment the node reducer makes
725
+ * goes through here, and this is the one place a frozen array crosses into
726
+ * state: the generated DocumentDriveGlobalState types nodes as a mutable
727
+ * Node[], so the cast below is where that gap is paid rather than spread over
728
+ * the reducer. Consumers must treat drive.state.global.nodes as read-only --
729
+ * mutating it in place (push, sort, splice) throws in strict mode; copy it
730
+ * first, as readNodes does. Note that LOAD_STATE replaces a whole scope and can
731
+ * install a list this function never saw.
732
+ */
733
+ function assignNodes(state, nodes) {
734
+ state.nodes = nodes;
735
+ }
676
736
  function handleTargetNameCollisions(params) {
677
737
  const { nodes, targetParentFolder, srcName, srcKind } = params;
678
738
  const targetNodeChildrenNames = nodes.filter((node) => targetParentFolder === "" ? node.parentFolder === null : node.parentFolder === targetParentFolder).filter((node) => node.kind === srcKind).map((node) => node.name);
@@ -685,23 +745,22 @@ const isValidName = (name) => {
685
745
  //#region document-drive/src/reducers/node.ts
686
746
  const nodeReducer = {
687
747
  addFileOperation(state, action, dispatch) {
688
- if (state.nodes.find((node) => node.id === action.input.id)) throw new Error(`Node with id ${action.input.id} already exists!`);
748
+ const nodes = readNodes(state);
749
+ if (nodes.find((node) => node.id === action.input.id)) throw new Error(`Node with id ${action.input.id} already exists!`);
689
750
  if (!isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must not be empty or contain control characters.`);
690
751
  const name = handleTargetNameCollisions({
691
- nodes: state.nodes,
752
+ nodes,
692
753
  srcName: action.input.name,
693
754
  srcKind: "file",
694
755
  targetParentFolder: action.input.parentFolder || null
695
756
  });
696
- const fileNode = {
757
+ assignNodes(state, insertNodeSorted(nodes, {
697
758
  id: action.input.id,
698
759
  name,
699
760
  kind: "file",
700
761
  parentFolder: action.input.parentFolder ?? null,
701
762
  documentType: action.input.documentType
702
- };
703
- state.nodes.push(fileNode);
704
- state.nodes.sort((a, b) => a.id.localeCompare(b.id));
763
+ }));
705
764
  dispatch?.({
706
765
  type: "CREATE_CHILD_DOCUMENT",
707
766
  input: {
@@ -711,27 +770,28 @@ const nodeReducer = {
711
770
  });
712
771
  },
713
772
  addFolderOperation(state, action) {
714
- if (state.nodes.find((node) => node.id === action.input.id)) throw new Error(`Node with id ${action.input.id} already exists!`);
773
+ const nodes = readNodes(state);
774
+ if (nodes.find((node) => node.id === action.input.id)) throw new Error(`Node with id ${action.input.id} already exists!`);
715
775
  if (!isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must not be empty or contain control characters.`);
716
776
  const name = handleTargetNameCollisions({
717
- nodes: state.nodes,
777
+ nodes,
718
778
  srcName: action.input.name,
719
779
  srcKind: "folder",
720
780
  targetParentFolder: action.input.parentFolder || null
721
781
  });
722
- state.nodes.push({
782
+ assignNodes(state, insertNodeSorted(nodes, {
723
783
  ...action.input,
724
784
  name,
725
785
  kind: "folder",
726
786
  parentFolder: action.input.parentFolder ?? null
727
- });
728
- state.nodes.sort((a, b) => a.id.localeCompare(b.id));
787
+ }));
729
788
  },
730
789
  deleteNodeOperation(state, action, dispatch) {
731
- const node = state.nodes.find((node) => node.id === action.input.id);
790
+ const nodes = readNodes(state);
791
+ const node = nodes.find((node) => node.id === action.input.id);
732
792
  if (!node) throw new Error(`Node with id ${action.input.id} not found`);
733
- const descendants = getDescendants(node, state.nodes);
734
- state.nodes = state.nodes.filter((node) => node.id !== action.input.id && !descendants.find((descendant) => descendant.id === node.id));
793
+ const descendants = getDescendants(node, nodes);
794
+ assignNodes(state, sortNodesById(nodes.filter((node) => node.id !== action.input.id && !descendants.find((descendant) => descendant.id === node.id))));
735
795
  [node, ...descendants].filter((node) => isFileNode(node)).forEach((node) => {
736
796
  dispatch?.({
737
797
  type: "DELETE_CHILD_DOCUMENT",
@@ -741,38 +801,39 @@ const nodeReducer = {
741
801
  },
742
802
  updateFileOperation(state, action) {
743
803
  if (action.input.name && !isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must not be empty or contain control characters.`);
744
- state.nodes = state.nodes.map((node) => node.id === action.input.id ? {
804
+ const nodes = readNodes(state);
805
+ assignNodes(state, sortNodesById(nodes.map((node) => node.id === action.input.id ? {
745
806
  ...node,
746
807
  name: handleTargetNameCollisions({
747
- nodes: state.nodes.filter((n) => n.id !== action.input.id),
808
+ nodes: nodes.filter((n) => n.id !== action.input.id),
748
809
  srcName: action.input.name ?? node.name,
749
810
  srcKind: "file",
750
811
  targetParentFolder: action.input.parentFolder ?? node.parentFolder
751
812
  }),
752
813
  documentType: action.input.documentType ?? node.documentType
753
- } : node);
754
- state.nodes.sort((a, b) => a.id.localeCompare(b.id));
814
+ } : node)));
755
815
  },
756
816
  updateNodeOperation(state, action) {
757
817
  if (action.input.name && !isValidName(action.input.name)) throw new Error(`Invalid name: '${action.input.name}'. Names must not be empty or contain control characters.`);
758
- state.nodes = state.nodes.map((node) => node.id === action.input.id ? {
818
+ const nodes = readNodes(state);
819
+ assignNodes(state, sortNodesById(nodes.map((node) => node.id === action.input.id ? {
759
820
  ...node,
760
821
  name: handleTargetNameCollisions({
761
- nodes: state.nodes.filter((n) => n.id !== action.input.id),
822
+ nodes: nodes.filter((n) => n.id !== action.input.id),
762
823
  srcName: action.input.name ?? node.name,
763
824
  srcKind: node.kind === "file" ? "file" : "folder",
764
825
  targetParentFolder: action.input.parentFolder ?? node.parentFolder
765
826
  }),
766
827
  parentFolder: action.input.parentFolder === null ? null : node.parentFolder
767
- } : node);
768
- state.nodes.sort((a, b) => a.id.localeCompare(b.id));
828
+ } : node)));
769
829
  },
770
830
  copyNodeOperation(state, action, dispatch) {
771
- const node = state.nodes.find((node) => node.id === action.input.srcId);
831
+ const nodes = readNodes(state);
832
+ const node = nodes.find((node) => node.id === action.input.srcId);
772
833
  if (!node) throw new Error(`Node with id ${action.input.srcId} not found`);
773
- if (state.nodes.find((node) => node.id === action.input.targetId)) throw new Error(`Node with id ${action.input.targetId} already exists`);
834
+ if (nodes.find((node) => node.id === action.input.targetId)) throw new Error(`Node with id ${action.input.targetId} already exists`);
774
835
  const name = handleTargetNameCollisions({
775
- nodes: state.nodes,
836
+ nodes,
776
837
  srcName: action.input.targetName || node.name,
777
838
  srcKind: node.kind === "file" ? "file" : "folder",
778
839
  targetParentFolder: action.input.targetParentFolder || null
@@ -784,8 +845,7 @@ const nodeReducer = {
784
845
  name,
785
846
  parentFolder: action.input.targetParentFolder || null
786
847
  };
787
- state.nodes.push(newNode);
788
- state.nodes.sort((a, b) => a.id.localeCompare(b.id));
848
+ assignNodes(state, insertNodeSorted(nodes, newNode));
789
849
  if (isFileNode(newNode)) dispatch?.({
790
850
  type: "COPY_CHILD_DOCUMENT",
791
851
  input: {
@@ -796,26 +856,26 @@ const nodeReducer = {
796
856
  },
797
857
  moveNodeOperation(state, action) {
798
858
  if (action.input.srcFolder === action.input.targetParentFolder) throw new Error("Circular Reference Error: Attempting to move a node to its current parent folder");
799
- const node = state.nodes.find((node) => node.id === action.input.srcFolder);
859
+ const nodes = readNodes(state);
860
+ const node = nodes.find((node) => node.id === action.input.srcFolder);
800
861
  if (!node) throw new Error(`Node with id ${action.input.srcFolder} not found`);
801
862
  const name = handleTargetNameCollisions({
802
- nodes: state.nodes,
863
+ nodes,
803
864
  srcName: node.name,
804
865
  srcKind: node.kind === "file" ? "file" : "folder",
805
866
  targetParentFolder: action.input.targetParentFolder || null
806
867
  });
807
868
  if (isFolderNode(node)) {
808
- if (getDescendants(node, state.nodes).find((descendant) => descendant.id === action.input.targetParentFolder)) throw new Error("Circular Reference Error: Cannot move a folder to one of its descendants");
869
+ if (getDescendants(node, nodes).find((descendant) => descendant.id === action.input.targetParentFolder)) throw new Error("Circular Reference Error: Cannot move a folder to one of its descendants");
809
870
  }
810
- state.nodes = state.nodes.map((node) => {
871
+ assignNodes(state, sortNodesById(nodes.map((node) => {
811
872
  if (node.id === action.input.srcFolder) return {
812
873
  ...node,
813
874
  name,
814
875
  parentFolder: action.input.targetParentFolder || null
815
876
  };
816
877
  return node;
817
- });
818
- state.nodes.sort((a, b) => a.id.localeCompare(b.id));
878
+ })));
819
879
  }
820
880
  };
821
881
  //#endregion
@@ -954,6 +1014,6 @@ const driveDocumentModelModule = {
954
1014
  }
955
1015
  };
956
1016
  //#endregion
957
- export { AddFileInputSchema, AddFolderInputSchema, AddListenerInputSchema, AddTriggerInputSchema, CopyNodeInputSchema, DeleteNodeInputSchema, DocumentDriveLocalStateSchema, DocumentDriveStateSchema, DriveDocumentHeaderSchema, DriveDocumentSchema, DrivePHStateSchema, FileNodeSchema, FolderNodeSchema, ListenerCallInfoInputSchema, ListenerCallInfoSchema, ListenerFilterInputSchema, ListenerFilterSchema, ListenerInputSchema, ListenerSchema, MoveNodeInputSchema, NodeSchema, PullResponderTriggerDataInputSchema, PullResponderTriggerDataSchema, RemoveListenerInputSchema, RemoveTriggerInputSchema, SetAvailableOfflineInputSchema, SetDriveIconInputSchema, SetDriveNameInputSchema, SetSharingTypeInputSchema, TransmitterTypeSchema, TriggerDataSchema, TriggerInputSchema, TriggerSchema, TriggerTypeSchema, UpdateFileInputSchema, UpdateNodeInputSchema, addFile, addFolder, addListener, addTrigger, assertIsDocumentOfType, assertIsDriveDocument, assertIsDriveState, assertIsStateOfType, copyNode, createGlobalState, createLocalState, createState, defaultGlobalState, defaultLocalState, defaultPHState, definedNonNullAnySchema, deleteNode, driveCreateDocument, driveCreateState, driveDocumentFileExtension, driveDocumentModel, driveDocumentModelModule, driveDocumentReducer, driveDocumentType, driveLoadFromInput, driveReducer, driveSaveToFileHandle, escapeRegExp, generateNodesCopy, getAncestors, getDescendants, getNextCopyNumber, handleTargetNameCollisions, initialGlobalState, initialLocalState, isDefinedNonNullAny, isDocumentOfType, isDriveDocument, isDriveState, isFileNode, isFolderNode, isStateOfType, isValidName, moveNode, nodeReducer, removeListener, removeTrigger, setAvailableOffline, setDriveIcon, setDriveName, setSharingType, updateFile, updateNode };
1017
+ export { AddFileInputSchema, AddFolderInputSchema, AddListenerInputSchema, AddTriggerInputSchema, CopyNodeInputSchema, DeleteNodeInputSchema, DocumentDriveLocalStateSchema, DocumentDriveStateSchema, DriveDocumentHeaderSchema, DriveDocumentSchema, DrivePHStateSchema, FileNodeSchema, FolderNodeSchema, ListenerCallInfoInputSchema, ListenerCallInfoSchema, ListenerFilterInputSchema, ListenerFilterSchema, ListenerInputSchema, ListenerSchema, MoveNodeInputSchema, NodeSchema, PullResponderTriggerDataInputSchema, PullResponderTriggerDataSchema, RemoveListenerInputSchema, RemoveTriggerInputSchema, SetAvailableOfflineInputSchema, SetDriveIconInputSchema, SetDriveNameInputSchema, SetSharingTypeInputSchema, TransmitterTypeSchema, TriggerDataSchema, TriggerInputSchema, TriggerSchema, TriggerTypeSchema, UpdateFileInputSchema, UpdateNodeInputSchema, addFile, addFolder, addListener, addTrigger, assertIsDocumentOfType, assertIsDriveDocument, assertIsDriveState, assertIsStateOfType, assignNodes, copyNode, createGlobalState, createLocalState, createState, defaultGlobalState, defaultLocalState, defaultPHState, definedNonNullAnySchema, deleteNode, driveCreateDocument, driveCreateState, driveDocumentFileExtension, driveDocumentModel, driveDocumentModelModule, driveDocumentReducer, driveDocumentType, driveLoadFromInput, driveReducer, driveSaveToFileHandle, escapeRegExp, generateNodesCopy, getAncestors, getDescendants, getNextCopyNumber, handleTargetNameCollisions, initialGlobalState, initialLocalState, insertNodeSorted, isDefinedNonNullAny, isDocumentOfType, isDriveDocument, isDriveState, isFileNode, isFolderNode, isStateOfType, isValidName, moveNode, nodeReducer, readNodes, removeListener, removeTrigger, setAvailableOffline, setDriveIcon, setDriveName, setSharingType, sortNodesById, updateFile, updateNode };
958
1018
 
959
1019
  //# sourceMappingURL=index.js.map