@blac/core 2.0.19 → 2.0.21

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 (236) hide show
  1. package/README.md +19 -29
  2. package/dist/{StateContainerRegistry-CSNm2Ws5.cjs → StateContainerRegistry-141uHhtF.cjs} +300 -397
  3. package/dist/StateContainerRegistry-141uHhtF.cjs.map +1 -0
  4. package/dist/{StateContainerRegistry-CvBOhAT2.js → StateContainerRegistry-vWgsD-RP.js} +277 -392
  5. package/dist/StateContainerRegistry-vWgsD-RP.js.map +1 -0
  6. package/dist/config.d.cts +2 -2
  7. package/dist/config.d.ts +2 -2
  8. package/dist/constants.d.cts +11 -20
  9. package/dist/constants.d.ts +11 -20
  10. package/dist/core/Cubit.d.ts +14 -10
  11. package/dist/core/StateContainer.d.ts +61 -4
  12. package/dist/core/StateContainerRegistry.d.ts +119 -16
  13. package/dist/core/meta.d.ts +5 -11
  14. package/dist/core/symbols.d.ts +24 -1
  15. package/dist/decorators/blac.d.ts +28 -26
  16. package/dist/{ensure-CQimeD0I.cjs → ensure-ORVw-WRE.cjs} +234 -40
  17. package/dist/ensure-ORVw-WRE.cjs.map +1 -0
  18. package/dist/{ensure-DTTTd2h8.js → ensure-k-6q7O25.js} +203 -39
  19. package/dist/ensure-k-6q7O25.js.map +1 -0
  20. package/dist/index.cjs +213 -32
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +6 -8
  23. package/dist/index.d.ts +6 -8
  24. package/dist/index.js +192 -12
  25. package/dist/index.js.map +1 -1
  26. package/dist/plugin/BlacPlugin.d.ts +14 -0
  27. package/dist/plugin/PluginManager.d.ts +23 -7
  28. package/dist/plugins.cjs +400 -3
  29. package/dist/plugins.cjs.map +1 -0
  30. package/dist/plugins.d.cts +6 -2
  31. package/dist/plugins.d.ts +6 -2
  32. package/dist/plugins.js +398 -1
  33. package/dist/plugins.js.map +1 -0
  34. package/dist/registry/acquire.d.ts +2 -2
  35. package/dist/registry/config.d.ts +9 -0
  36. package/dist/registry/management.d.ts +3 -0
  37. package/dist/registry/queries.d.ts +15 -0
  38. package/dist/registry/release.d.ts +3 -3
  39. package/dist/testing.cjs +13 -15
  40. package/dist/testing.cjs.map +1 -1
  41. package/dist/testing.d.cts +1 -1
  42. package/dist/testing.d.ts +1 -1
  43. package/dist/testing.js +2 -4
  44. package/dist/testing.js.map +1 -1
  45. package/dist/types/branded.d.ts +3 -3
  46. package/dist/types/utilities.d.ts +45 -18
  47. package/dist/utils/idGenerator.d.ts +0 -36
  48. package/dist/utils/static-props.d.ts +25 -1
  49. package/dist/utils/structural-key.d.ts +0 -7
  50. package/dist/watch/index.d.ts +1 -1
  51. package/dist/watch/watch.d.ts +22 -3
  52. package/package.json +17 -55
  53. package/dist/StateContainerRegistry-4Ljd9EJx.js +0 -1018
  54. package/dist/StateContainerRegistry-4Ljd9EJx.js.map +0 -1
  55. package/dist/StateContainerRegistry-B1GYx9Xo.js +0 -975
  56. package/dist/StateContainerRegistry-B1GYx9Xo.js.map +0 -1
  57. package/dist/StateContainerRegistry-B_ViBLvJ.js +0 -975
  58. package/dist/StateContainerRegistry-B_ViBLvJ.js.map +0 -1
  59. package/dist/StateContainerRegistry-C0dCNlTF.js +0 -1005
  60. package/dist/StateContainerRegistry-C0dCNlTF.js.map +0 -1
  61. package/dist/StateContainerRegistry-CEWpc1bj.cjs +0 -1113
  62. package/dist/StateContainerRegistry-CEWpc1bj.cjs.map +0 -1
  63. package/dist/StateContainerRegistry-CSNm2Ws5.cjs.map +0 -1
  64. package/dist/StateContainerRegistry-CchRjnjX.cjs +0 -1094
  65. package/dist/StateContainerRegistry-CchRjnjX.cjs.map +0 -1
  66. package/dist/StateContainerRegistry-CvBOhAT2.js.map +0 -1
  67. package/dist/StateContainerRegistry-D9BIRjwv.cjs +0 -1088
  68. package/dist/StateContainerRegistry-D9BIRjwv.cjs.map +0 -1
  69. package/dist/StateContainerRegistry-DJQqLrli.cjs +0 -1046
  70. package/dist/StateContainerRegistry-DJQqLrli.cjs.map +0 -1
  71. package/dist/StateContainerRegistry-DVIBTxGZ.js +0 -999
  72. package/dist/StateContainerRegistry-DVIBTxGZ.js.map +0 -1
  73. package/dist/StateContainerRegistry-Dj77cok9.js +0 -1005
  74. package/dist/StateContainerRegistry-Dj77cok9.js.map +0 -1
  75. package/dist/StateContainerRegistry-FWKzPfS-.cjs +0 -1046
  76. package/dist/StateContainerRegistry-FWKzPfS-.cjs.map +0 -1
  77. package/dist/StateContainerRegistry-lIwo-0m3.cjs +0 -1094
  78. package/dist/StateContainerRegistry-lIwo-0m3.cjs.map +0 -1
  79. package/dist/acquire-B1Wuqla6.cjs +0 -46
  80. package/dist/acquire-B1Wuqla6.cjs.map +0 -1
  81. package/dist/acquire-BP-ZfUH2.js +0 -35
  82. package/dist/acquire-BP-ZfUH2.js.map +0 -1
  83. package/dist/acquire-BRIJVJaA.js +0 -35
  84. package/dist/acquire-BRIJVJaA.js.map +0 -1
  85. package/dist/acquire-BZIs6tpN.cjs +0 -46
  86. package/dist/acquire-BZIs6tpN.cjs.map +0 -1
  87. package/dist/acquire-C3nOb3XR.cjs +0 -46
  88. package/dist/acquire-C3nOb3XR.cjs.map +0 -1
  89. package/dist/acquire-C4WAS13G.cjs +0 -46
  90. package/dist/acquire-C4WAS13G.cjs.map +0 -1
  91. package/dist/acquire-C7beGI55.cjs +0 -46
  92. package/dist/acquire-C7beGI55.cjs.map +0 -1
  93. package/dist/acquire-CbMz7gWs.cjs +0 -46
  94. package/dist/acquire-CbMz7gWs.cjs.map +0 -1
  95. package/dist/acquire-CwB083au.js +0 -35
  96. package/dist/acquire-CwB083au.js.map +0 -1
  97. package/dist/acquire-DHEOEVcj.cjs +0 -46
  98. package/dist/acquire-DHEOEVcj.cjs.map +0 -1
  99. package/dist/acquire-DXEQDZGr.js +0 -35
  100. package/dist/acquire-DXEQDZGr.js.map +0 -1
  101. package/dist/acquire-Dg-uXwjF.js +0 -35
  102. package/dist/acquire-Dg-uXwjF.js.map +0 -1
  103. package/dist/acquire-Don7499S.js +0 -35
  104. package/dist/acquire-Don7499S.js.map +0 -1
  105. package/dist/acquire-G8aB3GAx.js +0 -35
  106. package/dist/acquire-G8aB3GAx.js.map +0 -1
  107. package/dist/branded-BybA0_xw.cjs +0 -18
  108. package/dist/branded-BybA0_xw.cjs.map +0 -1
  109. package/dist/branded-DkbUzncc.js +0 -13
  110. package/dist/branded-DkbUzncc.js.map +0 -1
  111. package/dist/config-8pyOC5gv.js +0 -16
  112. package/dist/config-8pyOC5gv.js.map +0 -1
  113. package/dist/config-B1l8ZGlU.cjs +0 -32
  114. package/dist/config-B1l8ZGlU.cjs.map +0 -1
  115. package/dist/config-C7Ktkjh2.cjs +0 -32
  116. package/dist/config-C7Ktkjh2.cjs.map +0 -1
  117. package/dist/config-COT4Xkbc.js +0 -16
  118. package/dist/config-COT4Xkbc.js.map +0 -1
  119. package/dist/config-CzcoAvBo.js +0 -16
  120. package/dist/config-CzcoAvBo.js.map +0 -1
  121. package/dist/config-D6BoWWPv.js +0 -16
  122. package/dist/config-D6BoWWPv.js.map +0 -1
  123. package/dist/config-DVM_ESQt.js +0 -16
  124. package/dist/config-DVM_ESQt.js.map +0 -1
  125. package/dist/config-DVMnlHLv.cjs +0 -32
  126. package/dist/config-DVMnlHLv.cjs.map +0 -1
  127. package/dist/config-Dk1FxfXj.js +0 -16
  128. package/dist/config-Dk1FxfXj.js.map +0 -1
  129. package/dist/config-b2z51Y_C.cjs +0 -32
  130. package/dist/config-b2z51Y_C.cjs.map +0 -1
  131. package/dist/config-buwpT7l3.js +0 -16
  132. package/dist/config-buwpT7l3.js.map +0 -1
  133. package/dist/config-d9_U58ef.cjs +0 -32
  134. package/dist/config-d9_U58ef.cjs.map +0 -1
  135. package/dist/config-hWTayX76.cjs +0 -32
  136. package/dist/config-hWTayX76.cjs.map +0 -1
  137. package/dist/config-sCPKPYxZ.cjs +0 -32
  138. package/dist/config-sCPKPYxZ.cjs.map +0 -1
  139. package/dist/debug.cjs +0 -14
  140. package/dist/debug.d.cts +0 -34
  141. package/dist/debug.d.ts +0 -34
  142. package/dist/debug.js +0 -4
  143. package/dist/ensure-B1dEDsZV.cjs +0 -559
  144. package/dist/ensure-B1dEDsZV.cjs.map +0 -1
  145. package/dist/ensure-B9oOqpOB.cjs +0 -558
  146. package/dist/ensure-B9oOqpOB.cjs.map +0 -1
  147. package/dist/ensure-BfYnvAsI.js +0 -709
  148. package/dist/ensure-BfYnvAsI.js.map +0 -1
  149. package/dist/ensure-Bm91o37h.js +0 -536
  150. package/dist/ensure-Bm91o37h.js.map +0 -1
  151. package/dist/ensure-C1a8IFWy.js +0 -535
  152. package/dist/ensure-C1a8IFWy.js.map +0 -1
  153. package/dist/ensure-CLQEx0Nn.cjs +0 -528
  154. package/dist/ensure-CLQEx0Nn.cjs.map +0 -1
  155. package/dist/ensure-CPMiGvov.js +0 -493
  156. package/dist/ensure-CPMiGvov.js.map +0 -1
  157. package/dist/ensure-CQimeD0I.cjs.map +0 -1
  158. package/dist/ensure-DEXSmA-N.js +0 -526
  159. package/dist/ensure-DEXSmA-N.js.map +0 -1
  160. package/dist/ensure-DTTTd2h8.js.map +0 -1
  161. package/dist/ensure-Dx86f80B.cjs +0 -567
  162. package/dist/ensure-Dx86f80B.cjs.map +0 -1
  163. package/dist/ensure-DzqGej43.js +0 -526
  164. package/dist/ensure-DzqGej43.js.map +0 -1
  165. package/dist/ensure-VuiNPccZ.cjs +0 -559
  166. package/dist/ensure-VuiNPccZ.cjs.map +0 -1
  167. package/dist/ensure-_Oh8XPm4.cjs +0 -732
  168. package/dist/ensure-_Oh8XPm4.cjs.map +0 -1
  169. package/dist/ensure-fsQMjaQL.cjs +0 -567
  170. package/dist/ensure-fsQMjaQL.cjs.map +0 -1
  171. package/dist/ensure-vxAGa2v3.js +0 -536
  172. package/dist/ensure-vxAGa2v3.js.map +0 -1
  173. package/dist/management-14vsHr4t.cjs +0 -85
  174. package/dist/management-14vsHr4t.cjs.map +0 -1
  175. package/dist/management-444tdCBG.js +0 -38
  176. package/dist/management-444tdCBG.js.map +0 -1
  177. package/dist/management-7jLjVHJd.js +0 -38
  178. package/dist/management-7jLjVHJd.js.map +0 -1
  179. package/dist/management-AFuqQEwz.js +0 -38
  180. package/dist/management-AFuqQEwz.js.map +0 -1
  181. package/dist/management-BodVLAfJ.cjs +0 -85
  182. package/dist/management-BodVLAfJ.cjs.map +0 -1
  183. package/dist/management-BqGBdL01.js +0 -38
  184. package/dist/management-BqGBdL01.js.map +0 -1
  185. package/dist/management-BvUAjril.js +0 -38
  186. package/dist/management-BvUAjril.js.map +0 -1
  187. package/dist/management-C2wv4vGS.cjs +0 -85
  188. package/dist/management-C2wv4vGS.cjs.map +0 -1
  189. package/dist/management-D2pjr38g.js +0 -38
  190. package/dist/management-D2pjr38g.js.map +0 -1
  191. package/dist/management-D5WsZoTV.js +0 -38
  192. package/dist/management-D5WsZoTV.js.map +0 -1
  193. package/dist/management-DAV9sN-k.cjs +0 -85
  194. package/dist/management-DAV9sN-k.cjs.map +0 -1
  195. package/dist/management-Df7Y2sF1.cjs +0 -85
  196. package/dist/management-Df7Y2sF1.cjs.map +0 -1
  197. package/dist/management-DwO0nBzL.cjs +0 -85
  198. package/dist/management-DwO0nBzL.cjs.map +0 -1
  199. package/dist/management-GcnNJjnm.cjs +0 -85
  200. package/dist/management-GcnNJjnm.cjs.map +0 -1
  201. package/dist/types.cjs +0 -3
  202. package/dist/types.d.cts +0 -8
  203. package/dist/types.d.ts +0 -8
  204. package/dist/types.js +0 -2
  205. package/dist/watch-B91opmva.cjs +0 -70
  206. package/dist/watch-B91opmva.cjs.map +0 -1
  207. package/dist/watch-BHfCtbn1.cjs +0 -119
  208. package/dist/watch-BHfCtbn1.cjs.map +0 -1
  209. package/dist/watch-BmC-Tyqg.js +0 -59
  210. package/dist/watch-BmC-Tyqg.js.map +0 -1
  211. package/dist/watch-CKWt788i.cjs +0 -70
  212. package/dist/watch-CKWt788i.cjs.map +0 -1
  213. package/dist/watch-CfrSSrRY.js +0 -59
  214. package/dist/watch-CfrSSrRY.js.map +0 -1
  215. package/dist/watch-Cnh3PtQA.cjs +0 -70
  216. package/dist/watch-Cnh3PtQA.cjs.map +0 -1
  217. package/dist/watch-D01MdwKy.js +0 -108
  218. package/dist/watch-D01MdwKy.js.map +0 -1
  219. package/dist/watch-D8hwbFU1.js +0 -59
  220. package/dist/watch-D8hwbFU1.js.map +0 -1
  221. package/dist/watch-DPVUwPUY.js +0 -59
  222. package/dist/watch-DPVUwPUY.js.map +0 -1
  223. package/dist/watch-DVmvZBMD.cjs +0 -70
  224. package/dist/watch-DVmvZBMD.cjs.map +0 -1
  225. package/dist/watch-DkDGmGAx.cjs +0 -119
  226. package/dist/watch-DkDGmGAx.cjs.map +0 -1
  227. package/dist/watch-DztcJuUy.cjs +0 -119
  228. package/dist/watch-DztcJuUy.cjs.map +0 -1
  229. package/dist/watch-IrR8G28N.js +0 -108
  230. package/dist/watch-IrR8G28N.js.map +0 -1
  231. package/dist/watch-entry.cjs +0 -4
  232. package/dist/watch-entry.d.cts +0 -24
  233. package/dist/watch-entry.d.ts +0 -24
  234. package/dist/watch-entry.js +0 -2
  235. package/dist/watch-hx0r92Zc.js +0 -108
  236. package/dist/watch-hx0r92Zc.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"config-hWTayX76.cjs","names":["globalRegistry"],"sources":["../src/registry/config.ts"],"sourcesContent":["import {\n globalRegistry,\n StateContainerRegistry,\n} from '../core/StateContainerRegistry';\n\nlet _registry = globalRegistry;\n\nexport function getRegistry(): StateContainerRegistry {\n return _registry;\n}\n\nexport function setRegistry(registry: StateContainerRegistry): void {\n _registry = registry;\n}\n\nexport function getStats(): {\n registeredTypes: number;\n totalInstances: number;\n typeBreakdown: Record<string, number>;\n} {\n return _registry.getStats();\n}\n"],"mappings":";AAKA,IAAI,2DAAYA,EAAAA;AAEhB,SAAgB,cAAsC;CACpD,OAAO;AACT;AAEA,SAAgB,YAAY,UAAwC;CAClE,YAAY;AACd;AAEA,SAAgB,WAId;CACA,OAAO,UAAU,SAAS;AAC5B"}
@@ -1,32 +0,0 @@
1
- //#region src/registry/config.ts
2
- let _registry = require("./StateContainerRegistry-DJQqLrli.cjs").globalRegistry;
3
- function getRegistry() {
4
- return _registry;
5
- }
6
- function setRegistry(registry) {
7
- _registry = registry;
8
- }
9
- function getStats() {
10
- return _registry.getStats();
11
- }
12
- //#endregion
13
- Object.defineProperty(exports, "getRegistry", {
14
- enumerable: true,
15
- get: function() {
16
- return getRegistry;
17
- }
18
- });
19
- Object.defineProperty(exports, "getStats", {
20
- enumerable: true,
21
- get: function() {
22
- return getStats;
23
- }
24
- });
25
- Object.defineProperty(exports, "setRegistry", {
26
- enumerable: true,
27
- get: function() {
28
- return setRegistry;
29
- }
30
- });
31
-
32
- //# sourceMappingURL=config-sCPKPYxZ.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config-sCPKPYxZ.cjs","names":["globalRegistry"],"sources":["../src/registry/config.ts"],"sourcesContent":["import {\n globalRegistry,\n StateContainerRegistry,\n} from '../core/StateContainerRegistry';\n\nlet _registry = globalRegistry;\n\nexport function getRegistry(): StateContainerRegistry {\n return _registry;\n}\n\nexport function setRegistry(registry: StateContainerRegistry): void {\n _registry = registry;\n}\n\nexport function getStats(): {\n registeredTypes: number;\n totalInstances: number;\n typeBreakdown: Record<string, number>;\n} {\n return _registry.getStats();\n}\n"],"mappings":";AAKA,IAAI,2DAAYA,EAAAA;AAEhB,SAAgB,cAAsC;CACpD,OAAO;AACT;AAEA,SAAgB,YAAY,UAAwC;CAClE,YAAY;AACd;AAEA,SAAgB,WAId;CACA,OAAO,UAAU,SAAS;AAC5B"}
package/dist/debug.cjs DELETED
@@ -1,14 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_StateContainerRegistry = require("./StateContainerRegistry-lIwo-0m3.cjs");
3
- const require_config = require("./config-B1l8ZGlU.cjs");
4
- const require_management = require("./management-DwO0nBzL.cjs");
5
- exports.forEach = require_management.forEach;
6
- exports.getAll = require_management.getAll;
7
- exports.getRefCount = require_management.getRefCount;
8
- exports.getRefIds = require_management.getRefIds;
9
- exports.getRegistry = require_config.getRegistry;
10
- exports.getStats = require_config.getStats;
11
- exports.globalRegistry = require_StateContainerRegistry.globalRegistry;
12
- exports.hasInstance = require_management.hasInstance;
13
- exports.register = require_management.register;
14
- exports.setRegistry = require_config.setRegistry;
package/dist/debug.d.cts DELETED
@@ -1,34 +0,0 @@
1
- /**
2
- * Debug/Advanced Subpath Export
3
- *
4
- * Advanced registry introspection and debugging utilities.
5
- * Import from '@blac/core/debug'
6
- *
7
- * These utilities are intended for debugging, testing, and advanced use cases.
8
- * Most applications don't need these - use the main '@blac/core' exports instead.
9
- *
10
- * @example
11
- * ```typescript
12
- * import { getStats, globalRegistry, hasInstance, getRefIds } from '@blac/core/debug';
13
- *
14
- * // Get registry statistics
15
- * const stats = getStats();
16
- * console.log(`Total instances: ${stats.totalInstances}`);
17
- *
18
- * // Check if an instance exists
19
- * if (hasInstance(UserBloc)) {
20
- * console.log('UserBloc is registered');
21
- * }
22
- *
23
- * // See who holds a reference
24
- * const refs = getRefIds(UserBloc);
25
- * console.log('Ref holders:', refs);
26
- * ```
27
- *
28
- * @packageDocumentation
29
- */
30
- export { hasInstance, getRefCount, getRefIds, getAll, forEach, } from './registry/queries';
31
- export { register } from './registry/management';
32
- export { getRegistry, setRegistry, getStats } from './registry/config';
33
- export { globalRegistry } from './core/StateContainerRegistry';
34
- export type { LifecycleEvent, LifecycleListener, InstanceEntry, } from './core/StateContainerRegistry';
package/dist/debug.d.ts DELETED
@@ -1,34 +0,0 @@
1
- /**
2
- * Debug/Advanced Subpath Export
3
- *
4
- * Advanced registry introspection and debugging utilities.
5
- * Import from '@blac/core/debug'
6
- *
7
- * These utilities are intended for debugging, testing, and advanced use cases.
8
- * Most applications don't need these - use the main '@blac/core' exports instead.
9
- *
10
- * @example
11
- * ```typescript
12
- * import { getStats, globalRegistry, hasInstance, getRefIds } from '@blac/core/debug';
13
- *
14
- * // Get registry statistics
15
- * const stats = getStats();
16
- * console.log(`Total instances: ${stats.totalInstances}`);
17
- *
18
- * // Check if an instance exists
19
- * if (hasInstance(UserBloc)) {
20
- * console.log('UserBloc is registered');
21
- * }
22
- *
23
- * // See who holds a reference
24
- * const refs = getRefIds(UserBloc);
25
- * console.log('Ref holders:', refs);
26
- * ```
27
- *
28
- * @packageDocumentation
29
- */
30
- export { hasInstance, getRefCount, getRefIds, getAll, forEach, } from './registry/queries';
31
- export { register } from './registry/management';
32
- export { getRegistry, setRegistry, getStats } from './registry/config';
33
- export { globalRegistry } from './core/StateContainerRegistry';
34
- export type { LifecycleEvent, LifecycleListener, InstanceEntry, } from './core/StateContainerRegistry';
package/dist/debug.js DELETED
@@ -1,4 +0,0 @@
1
- import { r as globalRegistry } from "./StateContainerRegistry-Dj77cok9.js";
2
- import { n as getStats, r as setRegistry, t as getRegistry } from "./config-CzcoAvBo.js";
3
- import { a as getAll, c as hasInstance, i as forEach, o as getRefCount, r as register, s as getRefIds } from "./management-AFuqQEwz.js";
4
- export { forEach, getAll, getRefCount, getRefIds, getRegistry, getStats, globalRegistry, hasInstance, register, setRegistry };
@@ -1,559 +0,0 @@
1
- const require_StateContainerRegistry = require("./StateContainerRegistry-CchRjnjX.cjs");
2
- const require_config = require("./config-d9_U58ef.cjs");
3
- let _dirtytalk_structural = require("@dirtytalk/structural");
4
- //#region src/utils/idGenerator.ts
5
- /**
6
- * Generate simple ID with timestamp and random (no counter tracking)
7
- *
8
- * Format: `${prefix}:${timestamp}_${random}`
9
- *
10
- * @param prefix - Prefix for the ID
11
- * @returns Branded ID string
12
- *
13
- * @example
14
- * ```ts
15
- * const id = generateSimpleId('CounterBloc');
16
- * // Returns: "CounterBloc:1698765432100_a3k9d7f2q"
17
- * ```
18
- */
19
- function generateSimpleId(prefix, affix) {
20
- if (affix) return `${prefix}:${affix}`;
21
- return `${prefix}:${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
22
- }
23
- //#endregion
24
- //#region src/core/meta.ts
25
- /**
26
- * Non-enumerable brand carried on every `$blac` object produced by
27
- * {@link createMeta}. Used by the clobber guard in `StateContainer` to detect
28
- * a subclass class-field shadowing the base's own `$blac` property, and by the
29
- * meta tests. Intentionally NOT re-exported from the package barrel.
30
- */
31
- const META_BRAND = Symbol("blac.meta");
32
- const EMPTY_DEPS = /* @__PURE__ */ new Map();
33
- /**
34
- * Build the frozen, branded `$blac` meta object for a container.
35
- *
36
- * Called from a `StateContainer` field initializer (`$blac = createMeta(this)`).
37
- * Only the back-reference is captured at this point; every getter/method reads
38
- * the container's `_`-private fields lazily on access, so field-initializer
39
- * ordering relative to those private fields is irrelevant.
40
- *
41
- * The getters close over `container` (the real instance), never over a
42
- * `this`-receiver — this is what keeps `$blac` reads safe through
43
- * `buildTrackedProxy`.
44
- */
45
- function createMeta(container) {
46
- const c = container;
47
- const meta = {
48
- get name() {
49
- return c._name;
50
- },
51
- get id() {
52
- return c._instanceId;
53
- },
54
- get debug() {
55
- return c._debug;
56
- },
57
- get createdAt() {
58
- return c._createdAt;
59
- },
60
- get disposed() {
61
- return c._disposed;
62
- },
63
- get dependencies() {
64
- return c._dependencies ?? EMPTY_DEPS;
65
- },
66
- hydration: Object.freeze({
67
- get status() {
68
- return c._hydrationStatus;
69
- },
70
- get error() {
71
- return c._hydrationError;
72
- },
73
- get isHydrated() {
74
- return c._hydrationStatus === "hydrated";
75
- },
76
- get changedWhileHydrating() {
77
- return c._changedWhileHydrating;
78
- },
79
- begin() {
80
- c._beginHydration();
81
- },
82
- apply(next) {
83
- return c._applyHydratedState(next);
84
- },
85
- finish() {
86
- c._finishHydration();
87
- },
88
- fail(error) {
89
- c._failHydration(error);
90
- },
91
- wait() {
92
- return c._waitForHydration();
93
- }
94
- })
95
- };
96
- Object.defineProperty(meta, META_BRAND, {
97
- value: true,
98
- enumerable: false,
99
- writable: false,
100
- configurable: false
101
- });
102
- return Object.freeze(meta);
103
- }
104
- //#endregion
105
- //#region src/core/StateContainer.ts
106
- /**
107
- * Brand symbol carried (non-enumerable) on every handle returned by
108
- * `depend()`. Framework adapters (`@blac/react`) use this to detect handles
109
- * inside a tracked-proxy and swap in a session-bound wrapper.
110
- *
111
- * @internal — exported for `@blac/react`; not part of the public API.
112
- */
113
- const DEP_BRAND = Symbol("blac.depHandle");
114
- /**
115
- * Shallow per-key `Object.is` comparison of two plain records. Keys are
116
- * considered: a key present in one but not the other (regardless of value)
117
- * makes the records unequal. Used to detect real deps changes.
118
- */
119
- function shallowEqualRecord(a, b) {
120
- if (a === b) return true;
121
- const aKeys = Object.keys(a);
122
- if (aKeys.length !== Object.keys(b).length) return false;
123
- for (const key of aKeys) {
124
- if (!(key in b)) return false;
125
- if (!Object.is(a[key], b[key])) return false;
126
- }
127
- return true;
128
- }
129
- /**
130
- * BlaC's lifecycle/identity/dependency layer on top of `StructuralContainer`.
131
- *
132
- * StructuralContainer provides:
133
- * - `state` getter
134
- * - `emit` / `patch` / `update` (path-tracked, microtask-flushed)
135
- * - `channel` (the underlying `DirtyChannel`)
136
- * - `registerConsumerPaths` / `unregisterConsumer` (for fine-grained consumers)
137
- * - per-class `PathInterner`
138
- *
139
- * StateContainer layers on:
140
- * - identity / lifecycle / hydration (exposed via `$blac: BlacMeta`)
141
- * - cross-bloc deps (`depend()`, `$blac.dependencies`)
142
- * - per-consumer deps slices (`APPLY_DEPS` / `REMOVE_DEPS_OWNER` / `onDepsChanged`)
143
- * - registry integration (config-driven equality, emit-rate circuit breaker)
144
- *
145
- * Subscribers can attach via:
146
- * - `onSystemEvent('stateChanged' | 'dispose' | 'hydrationChanged', cb)` —
147
- * coarse lifecycle events.
148
- * - `this.channel.subscribe(interest, cb)` — path-scoped.
149
- */
150
- var StateContainer = class extends _dirtytalk_structural.StructuralContainer {
151
- static {
152
- this.__excludeFromDevTools = false;
153
- }
154
- get deps() {
155
- return this._deps;
156
- }
157
- /**
158
- * @internal Apply one owner's (consumer's) deps slice. Shallow-merges the
159
- * slice, reconciles keys the owner dropped since its last apply (other
160
- * owners' keys untouched), dev-warns on cross-owner key collisions, then
161
- * recomputes the merged view and fires onDepsChanged if it changed.
162
- *
163
- * Idempotent: re-applying an identical slice for the same owner is a no-op.
164
- */
165
- [require_StateContainerRegistry.APPLY_DEPS](ownerId, slice) {
166
- if (this._disposed) return;
167
- const owners = this._depsByOwner ??= /* @__PURE__ */ new Map();
168
- const prevSlice = owners.get(ownerId);
169
- if (prevSlice && shallowEqualRecord(prevSlice, slice)) return;
170
- if (process.env.NODE_ENV !== "production") for (const key of Object.keys(slice)) for (const [otherOwner, otherSlice] of owners) {
171
- if (otherOwner === ownerId) continue;
172
- if (key in otherSlice && otherSlice[key] !== slice[key]) console.warn(`[${this._name}] multiple owners writing dep \`${String(key)}\`; last write wins`);
173
- }
174
- owners.set(ownerId, { ...slice });
175
- this.reconcileDeps();
176
- }
177
- /**
178
- * @internal Withdraw an owner's entire deps slice (consumer unmounted).
179
- */
180
- [require_StateContainerRegistry.REMOVE_DEPS_OWNER](ownerId) {
181
- if (this._disposed) return;
182
- if (!this._depsByOwner?.delete(ownerId)) return;
183
- this.reconcileDeps();
184
- }
185
- reconcileDeps() {
186
- const prev = this._deps;
187
- const next = {};
188
- if (this._depsByOwner) for (const slice of this._depsByOwner.values()) Object.assign(next, slice);
189
- for (const key of Object.keys(prev)) if (!(key in next)) next[key] = void 0;
190
- if (shallowEqualRecord(prev, next)) return;
191
- this._deps = next;
192
- this.onDepsChanged(next, prev);
193
- this._registry.emit("depsChanged", this, prev, next);
194
- }
195
- onDepsChanged(_next, _prev) {}
196
- get args() {
197
- return this._config.args;
198
- }
199
- /**
200
- * Declare a cross-bloc dependency. Returns a branded handle with two
201
- * accessors — the dep instance is resolved against the registry on each call,
202
- * which keeps the surface immune to dep-instance churn:
203
- *
204
- * - `handle.track(options?)` — reactive read. Returns `[state, instance]`.
205
- * Inside a getter reached through the React proxy this subscribes the
206
- * reading component to the dep's changes (base impl: live, no subscription).
207
- * - `handle.untracked(options?)` — returns the live instance with no tracking,
208
- * for imperative method calls and one-off reads.
209
- *
210
- * `defaultArgs` resolves the dep instance when an accessor is called without
211
- * its own `args`; per-call `options.args` overrides it and can derive from
212
- * current state. This does NOT auto-resubscribe outside the React proxy;
213
- * non-React consumers needing updates should subscribe explicitly.
214
- */
215
- depend(Type, defaultArgs) {
216
- if (!this._dependencies) this._dependencies = /* @__PURE__ */ new Map();
217
- this._dependencies.set(Type, this._registry.resolveKey(Type, void 0, defaultArgs));
218
- const resolve = (args) => {
219
- const effectiveArgs = args ?? defaultArgs;
220
- const key = this._registry.resolveKey(Type, void 0, effectiveArgs);
221
- return this._registry.ensure(Type, key, effectiveArgs);
222
- };
223
- const handle = {
224
- track: (options) => {
225
- const instance = resolve(options?.args);
226
- return [instance.state, instance];
227
- },
228
- untracked: (options) => resolve(options?.args)
229
- };
230
- Object.defineProperty(handle, DEP_BRAND, {
231
- value: {
232
- Type,
233
- defaultArgs
234
- },
235
- enumerable: false,
236
- writable: false,
237
- configurable: false
238
- });
239
- return handle;
240
- }
241
- constructor(initialState, options) {
242
- super(initialState, options);
243
- this._depsByOwner = null;
244
- this._deps = {};
245
- this._disposed = false;
246
- this._hydrationStatus = "idle";
247
- this._changedWhileHydrating = false;
248
- this._hydrationPromise = null;
249
- this._hydrationPromiseSettled = false;
250
- this._config = {};
251
- this._initCalled = false;
252
- this._emitWindowStart = 0;
253
- this._emitCount = 0;
254
- this._emitRateWarned = false;
255
- this._systemEventHandlers = /* @__PURE__ */ new Map();
256
- this._dependencies = null;
257
- this._pendingChange = null;
258
- this._bridgeUnsub = null;
259
- this._registry = require_config.getRegistry();
260
- this._equalityFn = require_StateContainerRegistry.getBlacConfig().equality;
261
- this._name = this.constructor.name;
262
- this._debug = false;
263
- this._instanceId = generateSimpleId(this.constructor.name, "main");
264
- this._createdAt = Date.now();
265
- this.$blac = createMeta(this);
266
- this.onSystemEvent = (event, handler) => {
267
- let handlers = this._systemEventHandlers.get(event);
268
- if (!handlers) {
269
- handlers = /* @__PURE__ */ new Set();
270
- this._systemEventHandlers.set(event, handlers);
271
- }
272
- handlers.add(handler);
273
- return () => {
274
- handlers?.delete(handler);
275
- };
276
- };
277
- this._bridgeUnsub = this.channel.subscribe(() => _dirtytalk_structural.ALL_PATHS, () => this._drainPending());
278
- }
279
- /**
280
- * Called once after construction with the args passed at acquire time, before the first
281
- * state snapshot is read by any consumer. Override to seed args-derived state (via
282
- * this.emit(...)) or kick off loads.
283
- */
284
- init(_args) {}
285
- /**
286
- * @internal Framework-only configuration entry point (registry + testing
287
- * helpers). Writes the `_`-private identity fields directly, resolves
288
- * per-class equality, emits the registry `created` event, and runs `init()`
289
- * once. See {@link INIT_CONFIG}.
290
- */
291
- [require_StateContainerRegistry.INIT_CONFIG](config) {
292
- this._config = { ...config };
293
- this._name = this._config.name || this.constructor.name;
294
- this._debug = this._config.debug ?? false;
295
- this._instanceId = generateSimpleId(this.constructor.name, this._config.instanceId);
296
- const perClass = require_StateContainerRegistry.getClassEquality(this.constructor);
297
- this._equalityFn = perClass ?? require_StateContainerRegistry.getBlacConfig().equality;
298
- this._registry.emit("created", this);
299
- if (!this._initCalled) {
300
- this._initCalled = true;
301
- this.init(this._config.args);
302
- }
303
- if (process.env.NODE_ENV !== "production") {
304
- if (!this.$blac?.[META_BRAND]) console.warn(`[blac] ${this.constructor.name} appears to declare its own \`$blac\` member, which shadows the reserved meta namespace. \`$blac\` is reserved by StateContainer — remove the subclass field.`);
305
- }
306
- }
307
- dispose() {
308
- if (this._disposed) return;
309
- if (this._debug) console.log(`[${this._name}] Disposing...`);
310
- if (this._depsByOwner) {
311
- this._depsByOwner.clear();
312
- this.reconcileDeps();
313
- }
314
- this._disposed = true;
315
- if (this._hydrationStatus === "hydrating") this._failHydration(/* @__PURE__ */ new Error(`Hydration cancelled because ${this._name} was disposed`));
316
- this.emitSystemEvent("dispose", void 0);
317
- this._bridgeUnsub?.();
318
- this._bridgeUnsub = null;
319
- this._systemEventHandlers.clear();
320
- this._pendingChange = null;
321
- this._registry.emit("disposed", this);
322
- if (this._debug) console.log(`[${this._name}] Disposed successfully`);
323
- }
324
- emit(next) {
325
- this.applyState(next, "default");
326
- }
327
- /**
328
- * Override of `StructuralContainer.patch` that routes through the
329
- * StateContainer concerns: disposed guard, dev-only emit-rate check,
330
- * `_changedWhileHydrating` flag, pending-change capture (so `stateChanged`
331
- * system events see the merged prev/next), and the registry-level
332
- * `stateChanged` notification. We still call
333
- * `super.patch` so path-marking semantics (the whole point of patch) are
334
- * preserved.
335
- */
336
- patch(partial) {
337
- if (this._disposed) throw new Error(`Cannot emit state from disposed container ${this._name}`);
338
- const partialKeys = Object.keys(partial);
339
- if (partialKeys.length === 0) return;
340
- const prev = this.state;
341
- let allEqual = true;
342
- for (const key of partialKeys) if (!Object.is(prev[key], partial[key])) {
343
- allEqual = false;
344
- break;
345
- }
346
- if (allEqual) return;
347
- if (process.env.NODE_ENV !== "production") this._checkEmitRate();
348
- super.patch(partial);
349
- const next = this.state;
350
- if (Object.is(prev, next)) return;
351
- if (this._hydrationStatus === "hydrating") this._changedWhileHydrating = true;
352
- if (this._pendingChange) this._pendingChange.next = next;
353
- else this._pendingChange = {
354
- prev,
355
- next
356
- };
357
- if (this._registry.hasStateChangedListeners) this._registry.notifyStateChanged(this, prev, next);
358
- }
359
- applyState(next, source) {
360
- if (this._disposed) throw new Error(`Cannot emit state from disposed container ${this._name}`);
361
- const prev = this.state;
362
- if (prev === next) return;
363
- if (this._equalityFn(prev, next)) return;
364
- if (process.env.NODE_ENV !== "production") this._checkEmitRate();
365
- if (this._hydrationStatus === "hydrating" && source !== "hydration") this._changedWhileHydrating = true;
366
- if (this._pendingChange) this._pendingChange.next = next;
367
- else this._pendingChange = {
368
- prev,
369
- next
370
- };
371
- super.emit(next);
372
- if (this._registry.hasStateChangedListeners) this._registry.notifyStateChanged(this, prev, next);
373
- }
374
- /**
375
- * Called by the channel-bridge subscriber on each flush. Drains the
376
- * pending change (if any) into the 'stateChanged' system event.
377
- * No pending change == flush from a no-op patch == skip.
378
- */
379
- _drainPending() {
380
- const pending = this._pendingChange;
381
- if (!pending) return;
382
- this._pendingChange = null;
383
- const handlers = this._systemEventHandlers.get("stateChanged");
384
- if (handlers && handlers.size > 0) {
385
- const payload = {
386
- state: pending.next,
387
- previousState: pending.prev
388
- };
389
- let count = 0;
390
- const size = handlers.size;
391
- for (const handler of handlers) {
392
- if (++count > size) break;
393
- try {
394
- handler(payload);
395
- } catch (error) {
396
- console.error(`[${this._name}] Error in system event handler:`, error);
397
- }
398
- }
399
- }
400
- }
401
- _beginHydration() {
402
- if (this._disposed) throw new Error(`Cannot begin hydration for disposed container ${this._name}`);
403
- this._changedWhileHydrating = false;
404
- this._hydrationError = void 0;
405
- this._hydrationPromise = null;
406
- this._resolveHydrationPromise = void 0;
407
- this._rejectHydrationPromise = void 0;
408
- this._hydrationPromiseSettled = false;
409
- this.ensureHydrationPromise();
410
- this.setHydrationStatus("hydrating");
411
- }
412
- _applyHydratedState(next) {
413
- if (this._disposed) return false;
414
- if (this._hydrationStatus !== "hydrating" || this._changedWhileHydrating) return false;
415
- this.applyState(next, "hydration");
416
- return true;
417
- }
418
- _finishHydration() {
419
- if (this._hydrationStatus !== "hydrating") {
420
- if (this._hydrationStatus === "hydrated") return;
421
- if (this._hydrationStatus === "error") this.ensureHydrationPromise();
422
- }
423
- this.setHydrationStatus("hydrated");
424
- this.resolveHydration();
425
- }
426
- _failHydration(error) {
427
- const err = error instanceof Error ? error : /* @__PURE__ */ new Error(`Hydration failed: ${String(error)}`);
428
- this._hydrationError = err;
429
- this.setHydrationStatus("error", err);
430
- this.rejectHydration(err);
431
- }
432
- _waitForHydration() {
433
- if (this._hydrationStatus === "idle" || this._hydrationStatus === "hydrated") return Promise.resolve();
434
- if (this._hydrationStatus === "error") return Promise.reject(this._hydrationError ?? /* @__PURE__ */ new Error(`Hydration failed for container ${this._name}`));
435
- return this.ensureHydrationPromise();
436
- }
437
- setHydrationStatus(status, error) {
438
- const previousStatus = this._hydrationStatus;
439
- this._hydrationStatus = status;
440
- this._hydrationError = error;
441
- this.emitSystemEvent("hydrationChanged", {
442
- status,
443
- previousStatus,
444
- error,
445
- changedWhileHydrating: this._changedWhileHydrating
446
- });
447
- this._registry.emit("hydrationChanged", this, status, previousStatus);
448
- }
449
- ensureHydrationPromise() {
450
- if (!this._hydrationPromise || this._hydrationPromiseSettled) {
451
- this._hydrationPromiseSettled = false;
452
- this._hydrationPromise = new Promise((resolve, reject) => {
453
- this._resolveHydrationPromise = () => {
454
- if (this._hydrationPromiseSettled) return;
455
- this._hydrationPromiseSettled = true;
456
- resolve();
457
- };
458
- this._rejectHydrationPromise = (error) => {
459
- if (this._hydrationPromiseSettled) return;
460
- this._hydrationPromiseSettled = true;
461
- reject(error);
462
- };
463
- });
464
- this._hydrationPromise.catch(() => {});
465
- }
466
- return this._hydrationPromise;
467
- }
468
- resolveHydration() {
469
- this._resolveHydrationPromise?.();
470
- }
471
- rejectHydration(error) {
472
- this.ensureHydrationPromise();
473
- this._rejectHydrationPromise?.(error);
474
- }
475
- emitSystemEvent(event, payload) {
476
- const handlers = this._systemEventHandlers.get(event);
477
- if (!handlers) return;
478
- for (const handler of handlers) try {
479
- handler(payload);
480
- } catch (error) {
481
- console.error(`[${this._name}] Error in system event handler:`, error);
482
- }
483
- }
484
- /**
485
- * Dev-only soft circuit breaker. Counts real state changes in a rolling 1s
486
- * window and warns once if the rate exceeds `maxEmitsPerSecond` — the
487
- * signature of a runaway loop (RAF/animation or emit-on-every-commit) pushing
488
- * high-frequency data through state, which freezes subscribers/plugins.
489
- */
490
- _checkEmitRate() {
491
- const limit = require_StateContainerRegistry.getBlacConfig().maxEmitsPerSecond;
492
- if (!(limit > 0) || !Number.isFinite(limit) || this._emitRateWarned) return;
493
- const now = Date.now();
494
- if (now - this._emitWindowStart >= 1e3) {
495
- this._emitWindowStart = now;
496
- this._emitCount = 1;
497
- return;
498
- }
499
- this._emitCount++;
500
- if (this._emitCount > limit) {
501
- this._emitRateWarned = true;
502
- console.warn(`[${this._name}] emitted more than ${limit} state changes in under a second. This is usually a runaway loop pushing high-frequency data through state (e.g. \`emit\`/\`patch\` inside a requestAnimationFrame loop, or an effect that emits on every render). It can freeze the app by saturating subscribers and plugins (logging/devtools). Keep high-frequency work imperative and emit only coarse/throttled state, or raise \`configureBlac({ maxEmitsPerSecond })\`. (This warning fires once.)`);
503
- }
504
- }
505
- };
506
- //#endregion
507
- //#region src/core/Cubit.ts
508
- /**
509
- * `Cubit<S>` is a `StateContainer<S>` with `emit` / `patch` exposed as
510
- * public mutation surface. Today it adds nothing structurally beyond
511
- * `StateContainer` — both are inherited from the underlying
512
- * `StructuralContainer<S>`. Kept as a real class (not a type alias) because
513
- * downstream code does `instance instanceof Cubit` checks.
514
- *
515
- * The class body is intentionally empty: a no-op `emit` override would
516
- * still go through `applyState`, and `patch` is inherited from
517
- * `StructuralContainer` (path-diffed, microtask-flushed). A caller that
518
- * wants "skip if no real change" patch semantics can wrap `patch`
519
- * themselves or call `emit` after a manual equality check.
520
- */
521
- var Cubit = class extends StateContainer {};
522
- //#endregion
523
- //#region src/registry/ensure.ts
524
- /**
525
- * Ensure an instance exists without taking ownership (no ref added). Instance
526
- * identity is derived purely from `args`, matching `acquire`.
527
- */
528
- function ensure(BlocClass, opts) {
529
- const registry = require_config.getRegistry();
530
- const key = registry.resolveKey(BlocClass, void 0, opts?.args);
531
- return registry.ensure(BlocClass, key, opts?.args);
532
- }
533
- //#endregion
534
- Object.defineProperty(exports, "Cubit", {
535
- enumerable: true,
536
- get: function() {
537
- return Cubit;
538
- }
539
- });
540
- Object.defineProperty(exports, "DEP_BRAND", {
541
- enumerable: true,
542
- get: function() {
543
- return DEP_BRAND;
544
- }
545
- });
546
- Object.defineProperty(exports, "StateContainer", {
547
- enumerable: true,
548
- get: function() {
549
- return StateContainer;
550
- }
551
- });
552
- Object.defineProperty(exports, "ensure", {
553
- enumerable: true,
554
- get: function() {
555
- return ensure;
556
- }
557
- });
558
-
559
- //# sourceMappingURL=ensure-B1dEDsZV.cjs.map