effectable 0.1.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 (124) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +157 -0
  3. package/build/LICENSE +21 -0
  4. package/build/bootstrap/bootstrap.d.ts +32 -0
  5. package/build/bootstrap/bootstrap.d.ts.map +1 -0
  6. package/build/bootstrap/bootstrap.js +179 -0
  7. package/build/bootstrap/bootstrap.js.map +1 -0
  8. package/build/bootstrap/index.d.ts +9 -0
  9. package/build/bootstrap/index.d.ts.map +1 -0
  10. package/build/bootstrap/index.js +14 -0
  11. package/build/bootstrap/index.js.map +1 -0
  12. package/build/bootstrap/types.d.ts +105 -0
  13. package/build/bootstrap/types.d.ts.map +1 -0
  14. package/build/bootstrap/types.js +26 -0
  15. package/build/bootstrap/types.js.map +1 -0
  16. package/build/component/Component.d.ts +126 -0
  17. package/build/component/Component.d.ts.map +1 -0
  18. package/build/component/Component.js +123 -0
  19. package/build/component/Component.js.map +1 -0
  20. package/build/component/GraphRuntime.d.ts +457 -0
  21. package/build/component/GraphRuntime.d.ts.map +1 -0
  22. package/build/component/GraphRuntime.js +1168 -0
  23. package/build/component/GraphRuntime.js.map +1 -0
  24. package/build/component/constants.d.ts +1 -0
  25. package/build/component/constants.d.ts.map +1 -0
  26. package/build/component/constants.js +2 -0
  27. package/build/component/constants.js.map +1 -0
  28. package/build/component/context.d.ts +199 -0
  29. package/build/component/context.d.ts.map +1 -0
  30. package/build/component/context.js +262 -0
  31. package/build/component/context.js.map +1 -0
  32. package/build/component/graphRuntime.constants.d.ts +13 -0
  33. package/build/component/graphRuntime.constants.d.ts.map +1 -0
  34. package/build/component/graphRuntime.constants.js +15 -0
  35. package/build/component/graphRuntime.constants.js.map +1 -0
  36. package/build/component/h.d.ts +48 -0
  37. package/build/component/h.d.ts.map +1 -0
  38. package/build/component/h.js +72 -0
  39. package/build/component/h.js.map +1 -0
  40. package/build/component/index.d.ts +19 -0
  41. package/build/component/index.d.ts.map +1 -0
  42. package/build/component/index.js +39 -0
  43. package/build/component/index.js.map +1 -0
  44. package/build/component/lifecycle.d.ts +179 -0
  45. package/build/component/lifecycle.d.ts.map +1 -0
  46. package/build/component/lifecycle.js +367 -0
  47. package/build/component/lifecycle.js.map +1 -0
  48. package/build/component/refs.d.ts +105 -0
  49. package/build/component/refs.d.ts.map +1 -0
  50. package/build/component/refs.js +128 -0
  51. package/build/component/refs.js.map +1 -0
  52. package/build/component/types.d.ts +169 -0
  53. package/build/component/types.d.ts.map +1 -0
  54. package/build/component/types.js +40 -0
  55. package/build/component/types.js.map +1 -0
  56. package/build/connect/connect.d.ts +31 -0
  57. package/build/connect/connect.d.ts.map +1 -0
  58. package/build/connect/connect.js +500 -0
  59. package/build/connect/connect.js.map +1 -0
  60. package/build/connect/index.d.ts +8 -0
  61. package/build/connect/index.d.ts.map +1 -0
  62. package/build/connect/index.js +11 -0
  63. package/build/connect/index.js.map +1 -0
  64. package/build/connect/types.d.ts +90 -0
  65. package/build/connect/types.d.ts.map +1 -0
  66. package/build/connect/types.js +8 -0
  67. package/build/connect/types.js.map +1 -0
  68. package/build/index.d.ts +26 -0
  69. package/build/index.d.ts.map +1 -0
  70. package/build/index.js +60 -0
  71. package/build/index.js.map +1 -0
  72. package/build/runtime/BusDecorators.d.ts +113 -0
  73. package/build/runtime/BusDecorators.d.ts.map +1 -0
  74. package/build/runtime/BusDecorators.js +302 -0
  75. package/build/runtime/BusDecorators.js.map +1 -0
  76. package/build/runtime/CommandBus.d.ts +43 -0
  77. package/build/runtime/CommandBus.d.ts.map +1 -0
  78. package/build/runtime/CommandBus.js +65 -0
  79. package/build/runtime/CommandBus.js.map +1 -0
  80. package/build/runtime/EventBus.d.ts +50 -0
  81. package/build/runtime/EventBus.d.ts.map +1 -0
  82. package/build/runtime/EventBus.js +90 -0
  83. package/build/runtime/EventBus.js.map +1 -0
  84. package/build/runtime/HandleRegistry.d.ts +143 -0
  85. package/build/runtime/HandleRegistry.d.ts.map +1 -0
  86. package/build/runtime/HandleRegistry.js +244 -0
  87. package/build/runtime/HandleRegistry.js.map +1 -0
  88. package/build/runtime/QueryBus.d.ts +43 -0
  89. package/build/runtime/QueryBus.d.ts.map +1 -0
  90. package/build/runtime/QueryBus.js +65 -0
  91. package/build/runtime/QueryBus.js.map +1 -0
  92. package/build/runtime/index.d.ts +13 -0
  93. package/build/runtime/index.d.ts.map +1 -0
  94. package/build/runtime/index.js +32 -0
  95. package/build/runtime/index.js.map +1 -0
  96. package/build/runtime/types.d.ts +79 -0
  97. package/build/runtime/types.d.ts.map +1 -0
  98. package/build/runtime/types.js +8 -0
  99. package/build/runtime/types.js.map +1 -0
  100. package/build/store/createStore.d.ts +36 -0
  101. package/build/store/createStore.d.ts.map +1 -0
  102. package/build/store/createStore.js +131 -0
  103. package/build/store/createStore.js.map +1 -0
  104. package/build/store/index.d.ts +14 -0
  105. package/build/store/index.d.ts.map +1 -0
  106. package/build/store/index.js +39 -0
  107. package/build/store/index.js.map +1 -0
  108. package/build/store/middleware.d.ts +38 -0
  109. package/build/store/middleware.d.ts.map +1 -0
  110. package/build/store/middleware.js +99 -0
  111. package/build/store/middleware.js.map +1 -0
  112. package/build/store/selector.d.ts +62 -0
  113. package/build/store/selector.d.ts.map +1 -0
  114. package/build/store/selector.js +226 -0
  115. package/build/store/selector.js.map +1 -0
  116. package/build/store/semanticStateTree.d.ts +91 -0
  117. package/build/store/semanticStateTree.d.ts.map +1 -0
  118. package/build/store/semanticStateTree.js +263 -0
  119. package/build/store/semanticStateTree.js.map +1 -0
  120. package/build/store/types.d.ts +259 -0
  121. package/build/store/types.d.ts.map +1 -0
  122. package/build/store/types.js +28 -0
  123. package/build/store/types.js.map +1 -0
  124. package/package.json +109 -0
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Base class with state and lifecycle for Effectable: GraphRuntime,
3
+ * connect-HOC (class-based), and standalone use.
4
+ *
5
+ * Holds `state`, updates it via {@link Component.setState}, and after each update calls
6
+ * {@link Component.onUpdate}.
7
+ *
8
+ * **Modes:**
9
+ * - **Standalone** — `Component` as a lightweight stateful object without GraphRuntime: `setState`
10
+ * immediately leads to `onUpdate`, with no “only after mount” restriction.
11
+ * - **Mounted (GraphRuntime)** — LifecycleEngine defines hook order; `onUpdate` runs only after
12
+ * a successful {@link Component.onMount}.
13
+ *
14
+ * **Who calls hooks:** `onMount`, `onUnmount`, {@link Component.compose} — GraphRuntime in mounted mode.
15
+ * `connect`-HOC overrides `onMount`/`onUnmount` to manage the store subscription and delegates to
16
+ * `super.onMount?.()` / `super.onUnmount?.()` on the subclass.
17
+ *
18
+ * @module Effectable/component/Component
19
+ */
20
+ import type { Lifecycle } from './types';
21
+ import type { VirtualServiceNode } from './types';
22
+ /**
23
+ * Argument to {@link Component.setState}: a partial state (shallow-merged with previous `state`) or
24
+ * a function `(prevState, props) => Partial<S>`.
25
+ *
26
+ * @template S Instance state type.
27
+ * @template P Instance props type.
28
+ */
29
+ export type SetStateUpdate<S, P = unknown> = Partial<S> | ((prevState: S, props: P) => Partial<S>);
30
+ /**
31
+ * Abstract base class with state and lifecycle.
32
+ * Implements the {@link Lifecycle} contract: `onMount` → `onUpdate*` → `onUnmount`.
33
+ * GraphRuntime additionally uses {@link Component.compose} for a declarative subtree.
34
+ *
35
+ * @template S Type of {@link Component.state}.
36
+ * @template P Type of {@link Component.props}.
37
+ * @implements {Lifecycle}
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * class Tick extends Component<{ count: number }, { step: number }> {
42
+ * constructor (props: { step: number }) {
43
+ * super(props);
44
+ * this.state = { count: 0 };
45
+ * }
46
+ * bump () {
47
+ * this.setState((s, p) => ({ count: s.count + p.step }));
48
+ * }
49
+ * }
50
+ * ```
51
+ */
52
+ export declare abstract class Component<S = unknown, P = unknown> implements Lifecycle {
53
+ /**
54
+ * Opt-in flag for HFT components: if `true`, {@link Component.setState} applies
55
+ * updates **in-place** on the current `this.state` instead of creating a new object via spread.
56
+ *
57
+ * Yields 8.6x–710x speedup depending on state size,
58
+ * but breaks immutability semantics: `prev` and `next` in `onUpdate` point to the same object.
59
+ * Enable only for components whose `onUpdate` does not rely on prev/next separation.
60
+ *
61
+ * Subclass activates the flag like this:
62
+ * ```ts
63
+ * class FastTicker extends Component<State, Props> {
64
+ * public static override readonly mutableState = true;
65
+ * }
66
+ * ```
67
+ */
68
+ static readonly mutableState: boolean;
69
+ /** Current instance state after the last assignment in {@link Component.setState}. */
70
+ state: S;
71
+ /** Instance inputs: filled by GraphRuntime, connect-HOC, or calling code. */
72
+ props: P;
73
+ /**
74
+ * @param {P} props Props available in the {@link Component.setState} callback and in the subclass.
75
+ * @param {S} [initialState] Initial state; if omitted, an empty object is used as `S`.
76
+ */
77
+ constructor(props: P, initialState?: S);
78
+ /**
79
+ * Computes the next state as a shallow merge of `prev` with the update object or with the
80
+ * function result, then calls {@link Component.onUpdate}.
81
+ *
82
+ * If the class sets `static mutableState = true`, applies updates in-place
83
+ * on `this.state` — zero allocations, but `prev === next`.
84
+ *
85
+ * @param {SetStateUpdate<S, P>} update Partial state or `(prevState, props) => Partial<S>`.
86
+ * @returns {void}
87
+ */
88
+ setState(update: SetStateUpdate<S, P>): void;
89
+ /**
90
+ * Called on every `state` change (from {@link Component.setState} or from connect-HOC
91
+ * via `setState({})` after merging mapped props).
92
+ * In standalone — immediately after `setState`. In mounted mode — only after a successful
93
+ * {@link Component.onMount} (decided by GraphRuntime). Override in subclasses.
94
+ *
95
+ * @param {S} _prev State before the update was applied.
96
+ * @param {S} _next State after the update was applied.
97
+ * @returns {void}
98
+ */
99
+ onUpdate(_prev: S, _next: S): void;
100
+ /**
101
+ * Optional: node mount in GraphRuntime. Typically used to start subscriptions,
102
+ * timers, and background work. Called by LifecycleEngine exactly once before transitioning
103
+ * to the `ready` stage. Mounted mode only.
104
+ *
105
+ * @returns {void | Promise<void>}
106
+ */
107
+ onMount?(): void | Promise<void>;
108
+ /**
109
+ * Optional: node unmount from GraphRuntime. Typically used to drop subscriptions and stop
110
+ * side effects. Called by LifecycleEngine exactly once during shutdown. Mounted mode only.
111
+ *
112
+ * @returns {void | Promise<void>}
113
+ */
114
+ onUnmount?(): void | Promise<void>;
115
+ /**
116
+ * Optional: declarative subtree description with no side effects.
117
+ * Called by GraphRuntime during materialization and reconcile.
118
+ *
119
+ * Forbidden inside: network, bus subscriptions, handler registration, mutating global state.
120
+ *
121
+ * @returns {VirtualServiceNode | VirtualServiceNode[] | null} One or more virtual nodes,
122
+ * or `null` if the subtree is empty.
123
+ */
124
+ compose?(): VirtualServiceNode | VirtualServiceNode[] | null;
125
+ }
126
+ //# sourceMappingURL=Component.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Component.d.ts","sourceRoot":"","sources":["../../src/component/Component.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGlD;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,IACrC,OAAO,CAAC,CAAC,CAAC,GACV,CAAC,CAAC,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,8BAAsB,SAAS,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,CACxD,YAAW,SAAS;IAClB;;;;;;;;;;;;;;OAcG;IACH,gBAAuB,YAAY,EAAE,OAAO,CAAS;IAErD,sFAAsF;IAC/E,KAAK,EAAE,CAAC,CAAC;IAEhB,6EAA6E;IACtE,KAAK,EAAE,CAAC,CAAC;IAEhB;;;OAGG;gBACU,KAAK,EAAE,CAAC,EAAE,YAAY,CAAC,EAAE,CAAC;IAKvC;;;;;;;;;OASG;IACI,QAAQ,CAAE,MAAM,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI;IA0BpD;;;;;;;;;OASG;IACI,QAAQ,CAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAI1C;;;;;;OAMG;IACH,OAAO,CAAC,IAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAEjC;;;;;OAKG;IACH,SAAS,CAAC,IAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAEnC;;;;;;;;OAQG;IACH,OAAO,CAAC,IAAK,kBAAkB,GAAG,kBAAkB,EAAE,GAAG,IAAI;CAC9D"}
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ /**
3
+ * Base class with state and lifecycle for Effectable: GraphRuntime,
4
+ * connect-HOC (class-based), and standalone use.
5
+ *
6
+ * Holds `state`, updates it via {@link Component.setState}, and after each update calls
7
+ * {@link Component.onUpdate}.
8
+ *
9
+ * **Modes:**
10
+ * - **Standalone** — `Component` as a lightweight stateful object without GraphRuntime: `setState`
11
+ * immediately leads to `onUpdate`, with no “only after mount” restriction.
12
+ * - **Mounted (GraphRuntime)** — LifecycleEngine defines hook order; `onUpdate` runs only after
13
+ * a successful {@link Component.onMount}.
14
+ *
15
+ * **Who calls hooks:** `onMount`, `onUnmount`, {@link Component.compose} — GraphRuntime in mounted mode.
16
+ * `connect`-HOC overrides `onMount`/`onUnmount` to manage the store subscription and delegates to
17
+ * `super.onMount?.()` / `super.onUnmount?.()` on the subclass.
18
+ *
19
+ * @module Effectable/component/Component
20
+ */
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.Component = void 0;
23
+ const types_1 = require("./types");
24
+ /**
25
+ * Abstract base class with state and lifecycle.
26
+ * Implements the {@link Lifecycle} contract: `onMount` → `onUpdate*` → `onUnmount`.
27
+ * GraphRuntime additionally uses {@link Component.compose} for a declarative subtree.
28
+ *
29
+ * @template S Type of {@link Component.state}.
30
+ * @template P Type of {@link Component.props}.
31
+ * @implements {Lifecycle}
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * class Tick extends Component<{ count: number }, { step: number }> {
36
+ * constructor (props: { step: number }) {
37
+ * super(props);
38
+ * this.state = { count: 0 };
39
+ * }
40
+ * bump () {
41
+ * this.setState((s, p) => ({ count: s.count + p.step }));
42
+ * }
43
+ * }
44
+ * ```
45
+ */
46
+ class Component {
47
+ /**
48
+ * Opt-in flag for HFT components: if `true`, {@link Component.setState} applies
49
+ * updates **in-place** on the current `this.state` instead of creating a new object via spread.
50
+ *
51
+ * Yields 8.6x–710x speedup depending on state size,
52
+ * but breaks immutability semantics: `prev` and `next` in `onUpdate` point to the same object.
53
+ * Enable only for components whose `onUpdate` does not rely on prev/next separation.
54
+ *
55
+ * Subclass activates the flag like this:
56
+ * ```ts
57
+ * class FastTicker extends Component<State, Props> {
58
+ * public static override readonly mutableState = true;
59
+ * }
60
+ * ```
61
+ */
62
+ static mutableState = false;
63
+ /** Current instance state after the last assignment in {@link Component.setState}. */
64
+ state;
65
+ /** Instance inputs: filled by GraphRuntime, connect-HOC, or calling code. */
66
+ props;
67
+ /**
68
+ * @param {P} props Props available in the {@link Component.setState} callback and in the subclass.
69
+ * @param {S} [initialState] Initial state; if omitted, an empty object is used as `S`.
70
+ */
71
+ constructor(props, initialState) {
72
+ this.props = props;
73
+ this.state = (initialState ?? {});
74
+ }
75
+ /**
76
+ * Computes the next state as a shallow merge of `prev` with the update object or with the
77
+ * function result, then calls {@link Component.onUpdate}.
78
+ *
79
+ * If the class sets `static mutableState = true`, applies updates in-place
80
+ * on `this.state` — zero allocations, but `prev === next`.
81
+ *
82
+ * @param {SetStateUpdate<S, P>} update Partial state or `(prevState, props) => Partial<S>`.
83
+ * @returns {void}
84
+ */
85
+ setState(update) {
86
+ const prev = this.state;
87
+ const delta = typeof update === 'function'
88
+ ? update(prev, this.props)
89
+ : update;
90
+ // HFT fast-path: in-place state mutation without allocating a new object
91
+ // (8.6x–710x speedup). Enabled via static mutableState = true.
92
+ if (this.constructor.mutableState === true) {
93
+ const target = prev;
94
+ const src = delta;
95
+ for (const k in src) {
96
+ target[k] = src[k];
97
+ }
98
+ this.onUpdate(prev, prev);
99
+ this[types_1.SCHEDULE_UPDATE_HOOK]?.();
100
+ return;
101
+ }
102
+ // Shallow-copy previous state and delta to avoid mutating the original state
103
+ const next = { ...prev, ...delta };
104
+ this.state = next;
105
+ this.onUpdate(prev, next);
106
+ this[types_1.SCHEDULE_UPDATE_HOOK]?.();
107
+ }
108
+ /**
109
+ * Called on every `state` change (from {@link Component.setState} or from connect-HOC
110
+ * via `setState({})` after merging mapped props).
111
+ * In standalone — immediately after `setState`. In mounted mode — only after a successful
112
+ * {@link Component.onMount} (decided by GraphRuntime). Override in subclasses.
113
+ *
114
+ * @param {S} _prev State before the update was applied.
115
+ * @param {S} _next State after the update was applied.
116
+ * @returns {void}
117
+ */
118
+ onUpdate(_prev, _next) {
119
+ // Empty by default; subclass overrides as needed.
120
+ }
121
+ }
122
+ exports.Component = Component;
123
+ //# sourceMappingURL=Component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Component.js","sourceRoot":"","sources":["../../src/component/Component.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;;AAIH,mCAA+C;AAa/C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAsB,SAAS;IAE7B;;;;;;;;;;;;;;OAcG;IACI,MAAM,CAAU,YAAY,GAAY,KAAK,CAAC;IAErD,sFAAsF;IAC/E,KAAK,CAAI;IAEhB,6EAA6E;IACtE,KAAK,CAAI;IAEhB;;;OAGG;IACH,YAAa,KAAQ,EAAE,YAAgB;QACrC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,CAAC,YAAY,IAAI,EAAE,CAAM,CAAC;IACzC,CAAC;IAED;;;;;;;;;OASG;IACI,QAAQ,CAAE,MAA4B;QAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,MAAM,KAAK,GAAG,OAAO,MAAM,KAAK,UAAU;YACxC,CAAC,CAAE,MAA4C,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC;YACjE,CAAC,CAAC,MAAM,CAAC;QAEX,yEAAyE;QACzE,+DAA+D;QAC/D,IAAK,IAAI,CAAC,WAA0C,CAAC,YAAY,KAAK,IAAI,EAAE,CAAC;YAC3E,MAAM,MAAM,GAAG,IAA0C,CAAC;YAC1D,MAAM,GAAG,GAAG,KAA2C,CAAC;YACxD,KAAK,MAAM,CAAC,IAAI,GAAG,EAAE,CAAC;gBACpB,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;YACrB,CAAC;YACD,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACzB,IAA2D,CAAC,4BAAoB,CAAC,EAAE,EAAE,CAAC;YACvF,OAAO;QACT,CAAC;QAED,6EAA6E;QAC7E,MAAM,IAAI,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,EAAE,CAAC;QACnC,IAAI,CAAC,KAAK,GAAG,IAAS,CAAC;QACvB,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACzB,IAA2D,CAAC,4BAAoB,CAAC,EAAE,EAAE,CAAC;IACzF,CAAC;IAED;;;;;;;;;OASG;IACI,QAAQ,CAAE,KAAQ,EAAE,KAAQ;QACjC,kDAAkD;IACpD,CAAC;;AAlFH,8BA+GC"}