@ai-matrx/summon 0.1.16 → 0.1.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.
package/dist/index.js CHANGED
@@ -1579,10 +1579,7 @@ import { combineReducers, configureStore } from "@reduxjs/toolkit";
1579
1579
  // src/core/middleware/closeLifecycle.ts
1580
1580
  import { globalSlot as globalSlot5 } from "@ai-matrx/kit/global-slot";
1581
1581
 
1582
- // src/handles/callbackManager.ts
1583
- import { globalSlot as globalSlot3 } from "@ai-matrx/kit/global-slot";
1584
-
1585
- // src/handles/ids.ts
1582
+ // src/open/ids.ts
1586
1583
  function newHandleId() {
1587
1584
  const c = typeof globalThis.crypto === "undefined" ? void 0 : globalThis.crypto;
1588
1585
  if (c && typeof c.randomUUID === "function") return c.randomUUID();
@@ -1601,13 +1598,69 @@ function newHandleId() {
1601
1598
  // src/handles/slot.ts
1602
1599
  var HANDLES_SLOT = "ai-matrx.summon.handles";
1603
1600
 
1604
- // src/handles/callbackManager.ts
1601
+ // src/open/handleEntries.ts
1602
+ import { globalSlot as globalSlot3 } from "@ai-matrx/kit/global-slot";
1605
1603
  var handlesState = () => globalSlot3(HANDLES_SLOT, () => ({
1606
1604
  callbacks: /* @__PURE__ */ new Map(),
1607
1605
  groups: /* @__PURE__ */ new Map(),
1608
1606
  owners: /* @__PURE__ */ new Map(),
1609
1607
  registryListeners: /* @__PURE__ */ new Set()
1610
1608
  }));
1609
+ function notifyHandlesRegistry() {
1610
+ for (const listener of [...handlesState().registryListeners]) listener();
1611
+ }
1612
+ function deleteHandleEntry(id, notify = true) {
1613
+ const s = handlesState();
1614
+ const entry = s.callbacks.get(id);
1615
+ if (!entry) return;
1616
+ s.callbacks.delete(id);
1617
+ if (entry.groupId !== void 0) {
1618
+ const group = s.groups.get(entry.groupId);
1619
+ group?.delete(id);
1620
+ if (group?.size === 0) s.groups.delete(entry.groupId);
1621
+ }
1622
+ if (entry.owner !== void 0) {
1623
+ const owned = s.owners.get(entry.owner);
1624
+ owned?.delete(id);
1625
+ if (owned?.size === 0) s.owners.delete(entry.owner);
1626
+ }
1627
+ if (notify) notifyHandlesRegistry();
1628
+ entry.onRemove?.();
1629
+ }
1630
+ function registerHandleEntry(slot2, options = {}) {
1631
+ const s = handlesState();
1632
+ const id = options.id ?? newHandleId();
1633
+ if (s.callbacks.has(id)) deleteHandleEntry(id, false);
1634
+ const entry = { callback: slot2 };
1635
+ if (options.context !== void 0) entry.context = options.context;
1636
+ if (options.groupId !== void 0) entry.groupId = options.groupId;
1637
+ if (options.owner !== void 0) entry.owner = options.owner;
1638
+ if (options.onRemove !== void 0) entry.onRemove = options.onRemove;
1639
+ s.callbacks.set(id, entry);
1640
+ if (options.groupId !== void 0) {
1641
+ const group = s.groups.get(options.groupId) ?? /* @__PURE__ */ new Set();
1642
+ group.add(id);
1643
+ s.groups.set(options.groupId, group);
1644
+ }
1645
+ if (options.owner !== void 0) {
1646
+ const owned = s.owners.get(options.owner) ?? /* @__PURE__ */ new Set();
1647
+ owned.add(id);
1648
+ s.owners.set(options.owner, owned);
1649
+ }
1650
+ notifyHandlesRegistry();
1651
+ return id;
1652
+ }
1653
+ function removeHandleGroup(groupId) {
1654
+ const s = handlesState();
1655
+ const group = s.groups.get(groupId);
1656
+ if (!group) return;
1657
+ s.groups.delete(groupId);
1658
+ for (const id of [...group]) deleteHandleEntry(id, false);
1659
+ notifyHandlesRegistry();
1660
+ }
1661
+
1662
+ // src/handles/callbackManager.ts
1663
+ var handlesState2 = () => handlesState();
1611
1664
  function invoke(slot2, data, context) {
1612
1665
  if (typeof slot2 !== "function") return void 0;
1613
1666
  return slot2(data, context);
@@ -1617,7 +1670,7 @@ function invokeListener(listener, data, context) {
1617
1670
  }
1618
1671
  var CallbackManager = class {
1619
1672
  get s() {
1620
- return handlesState();
1673
+ return handlesState2();
1621
1674
  }
1622
1675
  /**
1623
1676
  * Observe the registry itself: `listener` runs after any entry is added or removed. This lets a
@@ -1631,7 +1684,7 @@ var CallbackManager = class {
1631
1684
  };
1632
1685
  }
1633
1686
  notifyRegistry() {
1634
- for (const listener of [...this.s.registryListeners]) listener();
1687
+ notifyHandlesRegistry();
1635
1688
  }
1636
1689
  /** Register a callback; returns its id. */
1637
1690
  register(callback) {
@@ -1643,27 +1696,7 @@ var CallbackManager = class {
1643
1696
  }
1644
1697
  /** @internal The one insertion path (typed helpers pass a fixed id and a removal hook). */
1645
1698
  registerEntry(slot2, options) {
1646
- const s = this.s;
1647
- const callbackId = options.id ?? newHandleId();
1648
- if (s.callbacks.has(callbackId)) this.deleteEntry(callbackId, false);
1649
- const entry = { callback: slot2 };
1650
- if (options.context !== void 0) entry.context = options.context;
1651
- if (options.groupId !== void 0) entry.groupId = options.groupId;
1652
- if (options.owner !== void 0) entry.owner = options.owner;
1653
- if (options.onRemove !== void 0) entry.onRemove = options.onRemove;
1654
- s.callbacks.set(callbackId, entry);
1655
- if (options.groupId !== void 0) {
1656
- const group = s.groups.get(options.groupId) ?? /* @__PURE__ */ new Set();
1657
- group.add(callbackId);
1658
- s.groups.set(options.groupId, group);
1659
- }
1660
- if (options.owner !== void 0) {
1661
- const owned = s.owners.get(options.owner) ?? /* @__PURE__ */ new Set();
1662
- owned.add(callbackId);
1663
- s.owners.set(options.owner, owned);
1664
- }
1665
- this.notifyRegistry();
1666
- return callbackId;
1699
+ return registerHandleEntry(slot2, options);
1667
1700
  }
1668
1701
  /** Subscribe to results for a callback id. */
1669
1702
  subscribe(callbackId, listener) {
@@ -1781,12 +1814,7 @@ var CallbackManager = class {
1781
1814
  }
1782
1815
  /** Remove a group and all its callbacks. */
1783
1816
  removeGroup(groupId) {
1784
- const s = this.s;
1785
- const group = s.groups.get(groupId);
1786
- if (!group) return;
1787
- s.groups.delete(groupId);
1788
- for (const callbackId of [...group]) this.deleteEntry(callbackId, false);
1789
- this.notifyRegistry();
1817
+ removeHandleGroup(groupId);
1790
1818
  }
1791
1819
  /** Remove everything registered with `owner` (an InstanceKey). Returns how many were removed. */
1792
1820
  disposeOwner(owner) {
@@ -1816,22 +1844,7 @@ var CallbackManager = class {
1816
1844
  * (the old `removeFromGroups`-after-delete bug), then runs the entry's removal hook.
1817
1845
  */
1818
1846
  deleteEntry(callbackId, notify) {
1819
- const s = this.s;
1820
- const entry = s.callbacks.get(callbackId);
1821
- if (!entry) return;
1822
- s.callbacks.delete(callbackId);
1823
- if (entry.groupId !== void 0) {
1824
- const group = s.groups.get(entry.groupId);
1825
- group?.delete(callbackId);
1826
- if (group?.size === 0) s.groups.delete(entry.groupId);
1827
- }
1828
- if (entry.owner !== void 0) {
1829
- const owned = s.owners.get(entry.owner);
1830
- owned?.delete(callbackId);
1831
- if (owned?.size === 0) s.owners.delete(entry.owner);
1832
- }
1833
- if (notify) this.notifyRegistry();
1834
- entry.onRemove?.();
1847
+ deleteHandleEntry(callbackId, notify);
1835
1848
  }
1836
1849
  };
1837
1850
  var callbackManager = new CallbackManager();