@playfast/reform 0.0.1 → 0.0.3

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 (231) hide show
  1. package/README.md +551 -53
  2. package/package.json +15 -13
  3. package/src/boundary/boundary.ts +192 -0
  4. package/src/calc/asyncCalc.ts +267 -0
  5. package/{dist/dts/calc/asyncData.d.ts → src/calc/asyncData.ts} +53 -20
  6. package/src/calc/calc.ts +120 -0
  7. package/src/calc/calcFamily.ts +194 -0
  8. package/src/calc/compose.ts +69 -0
  9. package/src/channel/channel.ts +265 -0
  10. package/src/compose/composition.ts +112 -0
  11. package/{dist/dts/compose/host.d.ts → src/compose/host.ts} +6 -8
  12. package/{dist/esm/compose/props.js → src/compose/props.ts} +3 -4
  13. package/src/compose/provide.ts +70 -0
  14. package/{dist/dts/compose/slot.d.ts → src/compose/slot.ts} +36 -19
  15. package/src/compose/ui.ts +97 -0
  16. package/src/definition/definition.ts +74 -0
  17. package/src/event/event.ts +65 -0
  18. package/src/event/eventGroup.ts +14 -0
  19. package/{dist/dts/feature/feature.d.ts → src/feature/feature.ts} +178 -92
  20. package/src/index.ts +140 -0
  21. package/{dist/dts/internal/capture.d.ts → src/internal/capture.ts} +13 -11
  22. package/{dist/dts/internal/ctx.d.ts → src/internal/ctx.ts} +8 -4
  23. package/{dist/esm/internal/errors.js → src/internal/errors.ts} +41 -26
  24. package/src/internal/inspect.ts +34 -0
  25. package/src/internal/queryDriver.ts +247 -0
  26. package/src/internal/reuse.ts +73 -0
  27. package/src/internal/scheduler.ts +91 -0
  28. package/{dist/dts/internal/seeds.d.ts → src/internal/seeds.ts} +6 -3
  29. package/src/internal/sources.ts +104 -0
  30. package/src/internal/store.ts +105 -0
  31. package/{dist/dts/internal/track.d.ts → src/internal/track.ts} +15 -11
  32. package/src/procedure/procedure.ts +89 -0
  33. package/src/reducer/reducer.ts +137 -0
  34. package/src/remote/remoteState.ts +571 -0
  35. package/{dist/cjs/runtime/bus.js → src/runtime/bus.ts} +23 -12
  36. package/src/runtime/loop.ts +169 -0
  37. package/src/scene/scene.ts +76 -0
  38. package/src/state/state.ts +91 -0
  39. package/src/state/stateFamily.ts +171 -0
  40. package/src/state/stateGroup.ts +78 -0
  41. package/{dist/dts/state/token.d.ts → src/state/token.ts} +21 -13
  42. package/{dist/dts/ui/node.d.ts → src/ui/node.ts} +3 -3
  43. package/{dist/dts/ui/trigger.d.ts → src/ui/trigger.ts} +1 -2
  44. package/dist/cjs/boundary/boundary.js +0 -86
  45. package/dist/cjs/calc/asyncCalc.js +0 -128
  46. package/dist/cjs/calc/asyncData.js +0 -37
  47. package/dist/cjs/calc/calc.js +0 -58
  48. package/dist/cjs/calc/calcFamily.js +0 -127
  49. package/dist/cjs/channel/channel.js +0 -142
  50. package/dist/cjs/compose/composition.js +0 -50
  51. package/dist/cjs/compose/host.js +0 -8
  52. package/dist/cjs/compose/props.js +0 -14
  53. package/dist/cjs/compose/provide.js +0 -30
  54. package/dist/cjs/compose/slot.js +0 -27
  55. package/dist/cjs/compose/ui.js +0 -61
  56. package/dist/cjs/definition/definition.js +0 -46
  57. package/dist/cjs/event/event.js +0 -36
  58. package/dist/cjs/event/eventGroup.js +0 -7
  59. package/dist/cjs/feature/feature.js +0 -102
  60. package/dist/cjs/index.js +0 -116
  61. package/dist/cjs/internal/capture.js +0 -14
  62. package/dist/cjs/internal/ctx.js +0 -2
  63. package/dist/cjs/internal/errors.js +0 -62
  64. package/dist/cjs/internal/inspect.js +0 -36
  65. package/dist/cjs/internal/queryDriver.js +0 -138
  66. package/dist/cjs/internal/reuse.js +0 -71
  67. package/dist/cjs/internal/scheduler.js +0 -73
  68. package/dist/cjs/internal/seeds.js +0 -19
  69. package/dist/cjs/internal/sources.js +0 -61
  70. package/dist/cjs/internal/store.js +0 -77
  71. package/dist/cjs/internal/track.js +0 -22
  72. package/dist/cjs/package.json +0 -4
  73. package/dist/cjs/procedure/procedure.js +0 -52
  74. package/dist/cjs/reducer/reducer.js +0 -64
  75. package/dist/cjs/remote/remoteState.js +0 -307
  76. package/dist/cjs/runtime/loop.js +0 -119
  77. package/dist/cjs/scene/scene.js +0 -36
  78. package/dist/cjs/state/state.js +0 -47
  79. package/dist/cjs/state/stateFamily.js +0 -101
  80. package/dist/cjs/state/stateGroup.js +0 -47
  81. package/dist/cjs/state/token.js +0 -23
  82. package/dist/cjs/ui/node.js +0 -2
  83. package/dist/cjs/ui/trigger.js +0 -2
  84. package/dist/dts/boundary/boundary.d.ts +0 -72
  85. package/dist/dts/boundary/boundary.d.ts.map +0 -1
  86. package/dist/dts/calc/asyncCalc.d.ts +0 -91
  87. package/dist/dts/calc/asyncCalc.d.ts.map +0 -1
  88. package/dist/dts/calc/asyncData.d.ts.map +0 -1
  89. package/dist/dts/calc/calc.d.ts +0 -57
  90. package/dist/dts/calc/calc.d.ts.map +0 -1
  91. package/dist/dts/calc/calcFamily.d.ts +0 -57
  92. package/dist/dts/calc/calcFamily.d.ts.map +0 -1
  93. package/dist/dts/channel/channel.d.ts +0 -115
  94. package/dist/dts/channel/channel.d.ts.map +0 -1
  95. package/dist/dts/compose/composition.d.ts +0 -72
  96. package/dist/dts/compose/composition.d.ts.map +0 -1
  97. package/dist/dts/compose/host.d.ts.map +0 -1
  98. package/dist/dts/compose/props.d.ts +0 -13
  99. package/dist/dts/compose/props.d.ts.map +0 -1
  100. package/dist/dts/compose/provide.d.ts +0 -22
  101. package/dist/dts/compose/provide.d.ts.map +0 -1
  102. package/dist/dts/compose/slot.d.ts.map +0 -1
  103. package/dist/dts/compose/ui.d.ts +0 -50
  104. package/dist/dts/compose/ui.d.ts.map +0 -1
  105. package/dist/dts/definition/definition.d.ts +0 -33
  106. package/dist/dts/definition/definition.d.ts.map +0 -1
  107. package/dist/dts/event/event.d.ts +0 -33
  108. package/dist/dts/event/event.d.ts.map +0 -1
  109. package/dist/dts/event/eventGroup.d.ts +0 -9
  110. package/dist/dts/event/eventGroup.d.ts.map +0 -1
  111. package/dist/dts/feature/feature.d.ts.map +0 -1
  112. package/dist/dts/index.d.ts +0 -43
  113. package/dist/dts/index.d.ts.map +0 -1
  114. package/dist/dts/internal/capture.d.ts.map +0 -1
  115. package/dist/dts/internal/ctx.d.ts.map +0 -1
  116. package/dist/dts/internal/errors.d.ts +0 -69
  117. package/dist/dts/internal/errors.d.ts.map +0 -1
  118. package/dist/dts/internal/inspect.d.ts +0 -17
  119. package/dist/dts/internal/inspect.d.ts.map +0 -1
  120. package/dist/dts/internal/queryDriver.d.ts +0 -65
  121. package/dist/dts/internal/queryDriver.d.ts.map +0 -1
  122. package/dist/dts/internal/reuse.d.ts +0 -10
  123. package/dist/dts/internal/reuse.d.ts.map +0 -1
  124. package/dist/dts/internal/scheduler.d.ts +0 -47
  125. package/dist/dts/internal/scheduler.d.ts.map +0 -1
  126. package/dist/dts/internal/seeds.d.ts.map +0 -1
  127. package/dist/dts/internal/sources.d.ts +0 -39
  128. package/dist/dts/internal/sources.d.ts.map +0 -1
  129. package/dist/dts/internal/store.d.ts +0 -47
  130. package/dist/dts/internal/store.d.ts.map +0 -1
  131. package/dist/dts/internal/track.d.ts.map +0 -1
  132. package/dist/dts/procedure/procedure.d.ts +0 -40
  133. package/dist/dts/procedure/procedure.d.ts.map +0 -1
  134. package/dist/dts/reducer/reducer.d.ts +0 -44
  135. package/dist/dts/reducer/reducer.d.ts.map +0 -1
  136. package/dist/dts/remote/remoteState.d.ts +0 -119
  137. package/dist/dts/remote/remoteState.d.ts.map +0 -1
  138. package/dist/dts/runtime/bus.d.ts +0 -27
  139. package/dist/dts/runtime/bus.d.ts.map +0 -1
  140. package/dist/dts/runtime/loop.d.ts +0 -45
  141. package/dist/dts/runtime/loop.d.ts.map +0 -1
  142. package/dist/dts/scene/scene.d.ts +0 -44
  143. package/dist/dts/scene/scene.d.ts.map +0 -1
  144. package/dist/dts/state/state.d.ts +0 -37
  145. package/dist/dts/state/state.d.ts.map +0 -1
  146. package/dist/dts/state/stateFamily.d.ts +0 -79
  147. package/dist/dts/state/stateFamily.d.ts.map +0 -1
  148. package/dist/dts/state/stateGroup.d.ts +0 -36
  149. package/dist/dts/state/stateGroup.d.ts.map +0 -1
  150. package/dist/dts/state/token.d.ts.map +0 -1
  151. package/dist/dts/ui/node.d.ts.map +0 -1
  152. package/dist/dts/ui/trigger.d.ts.map +0 -1
  153. package/dist/esm/boundary/boundary.js +0 -83
  154. package/dist/esm/boundary/boundary.js.map +0 -1
  155. package/dist/esm/calc/asyncCalc.js +0 -95
  156. package/dist/esm/calc/asyncCalc.js.map +0 -1
  157. package/dist/esm/calc/asyncData.js +0 -34
  158. package/dist/esm/calc/asyncData.js.map +0 -1
  159. package/dist/esm/calc/calc.js +0 -58
  160. package/dist/esm/calc/calc.js.map +0 -1
  161. package/dist/esm/calc/calcFamily.js +0 -124
  162. package/dist/esm/calc/calcFamily.js.map +0 -1
  163. package/dist/esm/channel/channel.js +0 -136
  164. package/dist/esm/channel/channel.js.map +0 -1
  165. package/dist/esm/compose/composition.js +0 -46
  166. package/dist/esm/compose/composition.js.map +0 -1
  167. package/dist/esm/compose/host.js +0 -5
  168. package/dist/esm/compose/host.js.map +0 -1
  169. package/dist/esm/compose/props.js.map +0 -1
  170. package/dist/esm/compose/provide.js +0 -28
  171. package/dist/esm/compose/provide.js.map +0 -1
  172. package/dist/esm/compose/slot.js +0 -23
  173. package/dist/esm/compose/slot.js.map +0 -1
  174. package/dist/esm/compose/ui.js +0 -57
  175. package/dist/esm/compose/ui.js.map +0 -1
  176. package/dist/esm/definition/definition.js +0 -42
  177. package/dist/esm/definition/definition.js.map +0 -1
  178. package/dist/esm/event/event.js +0 -30
  179. package/dist/esm/event/event.js.map +0 -1
  180. package/dist/esm/event/eventGroup.js +0 -4
  181. package/dist/esm/event/eventGroup.js.map +0 -1
  182. package/dist/esm/feature/feature.js +0 -98
  183. package/dist/esm/feature/feature.js.map +0 -1
  184. package/dist/esm/index.js +0 -45
  185. package/dist/esm/index.js.map +0 -1
  186. package/dist/esm/internal/capture.js +0 -11
  187. package/dist/esm/internal/capture.js.map +0 -1
  188. package/dist/esm/internal/ctx.js +0 -2
  189. package/dist/esm/internal/ctx.js.map +0 -1
  190. package/dist/esm/internal/errors.js.map +0 -1
  191. package/dist/esm/internal/inspect.js +0 -32
  192. package/dist/esm/internal/inspect.js.map +0 -1
  193. package/dist/esm/internal/queryDriver.js +0 -134
  194. package/dist/esm/internal/queryDriver.js.map +0 -1
  195. package/dist/esm/internal/reuse.js +0 -68
  196. package/dist/esm/internal/reuse.js.map +0 -1
  197. package/dist/esm/internal/scheduler.js +0 -69
  198. package/dist/esm/internal/scheduler.js.map +0 -1
  199. package/dist/esm/internal/seeds.js +0 -17
  200. package/dist/esm/internal/seeds.js.map +0 -1
  201. package/dist/esm/internal/sources.js +0 -59
  202. package/dist/esm/internal/sources.js.map +0 -1
  203. package/dist/esm/internal/store.js +0 -73
  204. package/dist/esm/internal/store.js.map +0 -1
  205. package/dist/esm/internal/track.js +0 -18
  206. package/dist/esm/internal/track.js.map +0 -1
  207. package/dist/esm/package.json +0 -4
  208. package/dist/esm/procedure/procedure.js +0 -50
  209. package/dist/esm/procedure/procedure.js.map +0 -1
  210. package/dist/esm/reducer/reducer.js +0 -63
  211. package/dist/esm/reducer/reducer.js.map +0 -1
  212. package/dist/esm/remote/remoteState.js +0 -270
  213. package/dist/esm/remote/remoteState.js.map +0 -1
  214. package/dist/esm/runtime/bus.js +0 -20
  215. package/dist/esm/runtime/bus.js.map +0 -1
  216. package/dist/esm/runtime/loop.js +0 -116
  217. package/dist/esm/runtime/loop.js.map +0 -1
  218. package/dist/esm/scene/scene.js +0 -31
  219. package/dist/esm/scene/scene.js.map +0 -1
  220. package/dist/esm/state/state.js +0 -43
  221. package/dist/esm/state/state.js.map +0 -1
  222. package/dist/esm/state/stateFamily.js +0 -96
  223. package/dist/esm/state/stateFamily.js.map +0 -1
  224. package/dist/esm/state/stateGroup.js +0 -46
  225. package/dist/esm/state/stateGroup.js.map +0 -1
  226. package/dist/esm/state/token.js +0 -20
  227. package/dist/esm/state/token.js.map +0 -1
  228. package/dist/esm/ui/node.js +0 -2
  229. package/dist/esm/ui/node.js.map +0 -1
  230. package/dist/esm/ui/trigger.js +0 -2
  231. package/dist/esm/ui/trigger.js.map +0 -1
@@ -1,11 +1,19 @@
1
- import { type Context, Effect, Layer, type Scope } from 'effect';
2
- import { type Engine } from '../runtime/loop.js';
3
- import { type StoresOf } from '../internal/sources.js';
4
- import { FeatureLoadFailed } from '../internal/errors.js';
5
- import { type Manifest } from '../definition/definition.js';
6
- import { type CompositionClass } from '../compose/composition.js';
7
- import { type UiContract } from '../compose/ui.js';
8
- import { type Tagged } from '../runtime/bus.js';
1
+ import { type Context, Effect, Layer, type Scope } from 'effect'
2
+ import { type Engine } from '../runtime/loop'
3
+ import { type StoresOf } from '../internal/sources'
4
+ import { FeatureLoadFailed } from '../internal/errors'
5
+ import { type Manifest, definitionClass } from '../definition/definition'
6
+ import { type CompositionClass } from '../compose/composition'
7
+ import { type UiContract } from '../compose/ui'
8
+ import { publish, type Tagged } from '../runtime/bus'
9
+
10
+ // A `Feature` is the unit of lazy code-split, ownership, reflection, and proof.
11
+ // It splits on the seam Reform already has: definitions (manifests, schemas, the
12
+ // composition class, placeholders) stay eager and reflectable; the heavy `.live`
13
+ // layer loads on demand. The whole-app *shape* stays inspectable with no chunk
14
+ // loaded. Everything here is additive — `provide(slot, Composition)` and eager
15
+ // scenes are unchanged. See `LAZY.md` for the design rationale and variance proof.
16
+
9
17
  /**
10
18
  * The always-on engine services a feature builds against: the shared event `Bus`
11
19
  * plus the reducer/channel/procedure registries. Derived from the `Engine`
@@ -13,20 +21,18 @@ import { type Tagged } from '../runtime/bus.js';
13
21
  * these only as OPEN requirements (its `RIn`) and must never *provide* them — that
14
22
  * is what keeps the engine single and shared across every lazily-mounted feature.
15
23
  */
16
- export type EngineServices = Layer.Layer.Success<typeof Engine>;
24
+ export type EngineServices = Layer.Layer.Success<typeof Engine>
25
+
17
26
  /**
18
27
  * A shared-state carrier a feature may declare in `requires`: a `State`,
19
28
  * `StateFamily`, `Calc`, or `AsyncCalc` (each carrying a `store` tag), or a
20
29
  * `StateGroup` (carrying `members`, each with its own `store`). Per the design,
21
30
  * a feature depends on shared state/calc only — never on another feature.
22
31
  */
23
- export type RequireCarrier = {
24
- readonly store: Context.Tag<any, any>;
25
- } | {
26
- readonly members: ReadonlyArray<{
27
- readonly store: Context.Tag<any, any>;
28
- }>;
29
- };
32
+ export type RequireCarrier =
33
+ | { readonly store: Context.Tag<any, any> }
34
+ | { readonly members: ReadonlyArray<{ readonly store: Context.Tag<any, any> }> }
35
+
30
36
  /**
31
37
  * The Context services a `requires` tuple makes available to a feature layer: a
32
38
  * `StateGroup` contributes its members' stores (the shared `StoresOf`); every
@@ -37,12 +43,15 @@ export type RequireCarrier = {
37
43
  * is ordinary assignability — no `as`, no `infer` gymnastics in user code.
38
44
  */
39
45
  export type ProvidedBy<Requires extends ReadonlyArray<RequireCarrier>> = {
40
- [I in keyof Requires]: Requires[I] extends {
41
- readonly members: infer M extends ReadonlyArray<unknown>;
42
- } ? StoresOf<M> : Requires[I] extends {
43
- readonly store: Context.Tag<infer Svc, any>;
44
- } ? Svc : never;
45
- }[number];
46
+ [I in keyof Requires]: Requires[I] extends {
47
+ readonly members: infer M extends ReadonlyArray<unknown>
48
+ }
49
+ ? StoresOf<M>
50
+ : Requires[I] extends { readonly store: Context.Tag<infer Svc, any> }
51
+ ? Svc
52
+ : never
53
+ }[number]
54
+
46
55
  /**
47
56
  * A loaded feature's two artifacts. `requires` is the runtime-enumerable list the
48
57
  * editor reads (types are erased, so the carriers are kept as values); `layer` is
@@ -53,9 +62,10 @@ export type ProvidedBy<Requires extends ReadonlyArray<RequireCarrier>> = {
53
62
  * a feature's lazy half.
54
63
  */
55
64
  export interface FeatureModule<ROut, Requires extends ReadonlyArray<RequireCarrier>> {
56
- readonly requires: Requires;
57
- readonly layer: Layer.Layer<ROut, never, EngineServices | ProvidedBy<Requires>>;
65
+ readonly requires: Requires
66
+ readonly layer: Layer.Layer<ROut, never, EngineServices | ProvidedBy<Requires>>
58
67
  }
68
+
59
69
  /**
60
70
  * Publish a feature's lazy half: pair its `requires` (a runtime tuple of shared
61
71
  * carriers) with its `layer`. The covariant `RIn` bound does the checking — a
@@ -67,7 +77,11 @@ export interface FeatureModule<ROut, Requires extends ReadonlyArray<RequireCarri
67
77
  * be open `RIn`), structurally enforcing the liveness rule: a feature can never
68
78
  * bundle its own engine — it always shares the root's bus and registries.
69
79
  */
70
- export declare const featureModule: <const Requires extends ReadonlyArray<RequireCarrier>, ROut>(requires: Requires, layer: Layer.Layer<ROut, never, EngineServices | ProvidedBy<Requires>>) => FeatureModule<ROut, Requires>;
80
+ export const featureModule = <const Requires extends ReadonlyArray<RequireCarrier>, ROut>(
81
+ requires: Requires,
82
+ layer: Layer.Layer<ROut, never, EngineServices | ProvidedBy<Requires>>,
83
+ ): FeatureModule<ROut, Requires> => ({ requires, layer })
84
+
71
85
  /**
72
86
  * Wrap a dynamic `import()` of a feature's `.live` module as an `Effect` — Reform
73
87
  * never exposes a Promise/`await` on the feature surface. The unavoidable thenable
@@ -75,14 +89,20 @@ export declare const featureModule: <const Requires extends ReadonlyArray<Requir
75
89
  * throw) surfaces as a typed `FeatureLoadFailed` the host hands to
76
90
  * `placeholder.failed`. The module's default export is its `FeatureModule`.
77
91
  */
78
- export declare const lazyImport: <M>(thunk: () => Promise<{
79
- readonly default: M;
80
- }>) => Effect.Effect<M, FeatureLoadFailed>;
92
+ export const lazyImport = <M>(
93
+ thunk: () => Promise<{ readonly default: M }>,
94
+ ): Effect.Effect<M, FeatureLoadFailed> =>
95
+ Effect.tryPromise({
96
+ try: thunk,
97
+ catch: (cause) => new FeatureLoadFailed({ cause }),
98
+ }).pipe(Effect.map((module) => module.default))
99
+
81
100
  /** The props the host injects into a lazy feature's `failed` placeholder. */
82
101
  export interface FailedProps {
83
- readonly error: FeatureLoadFailed;
84
- readonly retry: () => void;
102
+ readonly error: FeatureLoadFailed
103
+ readonly retry: () => void
85
104
  }
105
+
86
106
  /**
87
107
  * The reflectable shape of a feature: its strategy, the composition it mounts,
88
108
  * and (when lazy) its placeholder compositions — all as manifests, so the editor
@@ -90,21 +110,16 @@ export interface FailedProps {
90
110
  * runtime data and lives on the `FeatureBinding`, not here.
91
111
  */
92
112
  export interface FeatureManifest extends Manifest {
93
- readonly kind: 'Feature';
94
- readonly name: string;
95
- readonly strategy: 'lazy' | 'default';
96
- readonly composition: Manifest & {
97
- readonly kind: 'Composition';
98
- };
99
- readonly placeholder?: {
100
- readonly loading: Manifest & {
101
- readonly kind: 'Composition';
102
- };
103
- readonly failed: Manifest & {
104
- readonly kind: 'Composition';
105
- };
106
- };
113
+ readonly kind: 'Feature'
114
+ readonly name: string
115
+ readonly strategy: 'lazy' | 'default'
116
+ readonly composition: Manifest & { readonly kind: 'Composition' }
117
+ readonly placeholder?: {
118
+ readonly loading: Manifest & { readonly kind: 'Composition' }
119
+ readonly failed: Manifest & { readonly kind: 'Composition' }
120
+ }
107
121
  }
122
+
108
123
  /**
109
124
  * A feature's loaded artifacts with type params erased, for the renderer-neutral,
110
125
  * strategy-uniform host. The erasure is cast-free *into*: because `Layer`'s `ROut`
@@ -114,12 +129,14 @@ export interface FeatureManifest extends Manifest {
114
129
  * documented boundary cast there, mirroring `buildRuntime`).
115
130
  */
116
131
  export interface LoadedModule {
117
- readonly requires: ReadonlyArray<RequireCarrier>;
118
- readonly layer: Layer.Layer<never, never, unknown>;
132
+ readonly requires: ReadonlyArray<RequireCarrier>
133
+ readonly layer: Layer.Layer<never, never, unknown>
119
134
  }
135
+
120
136
  /** Nominal brand identifying the value a `provide(slot, Feature)` puts under a slot tag. */
121
- export declare const FeatureBindingTypeId: unique symbol;
122
- export type FeatureBindingTypeId = typeof FeatureBindingTypeId;
137
+ export const FeatureBindingTypeId: unique symbol = Symbol.for('reform/FeatureBinding')
138
+ export type FeatureBindingTypeId = typeof FeatureBindingTypeId
139
+
123
140
  /**
124
141
  * What `provide(slot, Feature)` binds under the slot tag — everything the host
125
142
  * needs to mount the feature, with types erased (the host is renderer-neutral and
@@ -130,19 +147,22 @@ export type FeatureBindingTypeId = typeof FeatureBindingTypeId;
130
147
  * each.
131
148
  */
132
149
  export interface FeatureBinding {
133
- readonly [FeatureBindingTypeId]: FeatureBindingTypeId;
134
- readonly manifest: FeatureManifest;
135
- readonly composition: CompositionClass<unknown>;
136
- readonly strategy: 'lazy' | 'default';
137
- readonly load: Effect.Effect<LoadedModule, FeatureLoadFailed>;
138
- readonly placeholder?: {
139
- readonly loading: CompositionClass<unknown>;
140
- readonly failed: CompositionClass<unknown>;
141
- };
142
- readonly boot: ReadonlyArray<Tagged>;
150
+ readonly [FeatureBindingTypeId]: FeatureBindingTypeId
151
+ readonly manifest: FeatureManifest
152
+ readonly composition: CompositionClass<unknown>
153
+ readonly strategy: 'lazy' | 'default'
154
+ readonly load: Effect.Effect<LoadedModule, FeatureLoadFailed>
155
+ readonly placeholder?: {
156
+ readonly loading: CompositionClass<unknown>
157
+ readonly failed: CompositionClass<unknown>
158
+ }
159
+ readonly boot: ReadonlyArray<Tagged>
143
160
  }
161
+
144
162
  /** Whether a slot's bound child is a lazy/eager feature (vs a plain composition). */
145
- export declare const isFeatureBinding: (u: unknown) => u is FeatureBinding;
163
+ export const isFeatureBinding = (u: unknown): u is FeatureBinding =>
164
+ typeof u === 'object' && u !== null && FeatureBindingTypeId in u
165
+
146
166
  /**
147
167
  * A feature *definition*: a reflectable manifest (`kind: 'Feature'`) that carries
148
168
  * the eager half (composition + placeholders) and an Effect `load` for the heavy
@@ -150,25 +170,37 @@ export declare const isFeatureBinding: (u: unknown) => u is FeatureBinding;
150
170
  * shared-carrier tuple the loaded module declares. `load` is an `Effect`, never a
151
171
  * Promise — consumers `yield* Feature.load`.
152
172
  */
153
- export interface FeatureClass<P, C extends UiContract, ROut, Requires extends ReadonlyArray<RequireCarrier>> {
154
- new (): {};
155
- readonly manifest: FeatureManifest;
156
- /** Phantom carrying the mounted composition's props type (for `provide` checks). */
157
- readonly Props: P;
158
- /** Phantom carrying the composition's UI contract (for typed reflection consumers). */
159
- readonly Contract: C;
160
- /** Phantom carrying the declared shared-carrier tuple. */
161
- readonly Requires: Requires;
162
- /** Load the feature's module — `yield* Feature.load` → its `FeatureModule`, or `FeatureLoadFailed`. */
163
- readonly load: Effect.Effect<FeatureModule<ROut, Requires>, FeatureLoadFailed>;
164
- /** The value `provide(slot, Feature)` binds under the slot tag. */
165
- readonly binding: FeatureBinding;
166
- /** The eagerly-available module — present only for `loadingStrategy: 'default'`. */
167
- readonly eagerModule: FeatureModule<ROut, Requires> | undefined;
173
+ export interface FeatureClass<
174
+ P,
175
+ C extends UiContract,
176
+ ROut,
177
+ Requires extends ReadonlyArray<RequireCarrier>,
178
+ > {
179
+ new (): {}
180
+ readonly manifest: FeatureManifest
181
+ /** Phantom carrying the mounted composition's props type (for `provide` checks). */
182
+ readonly Props: P
183
+ /** Phantom carrying the composition's UI contract (for typed reflection consumers). */
184
+ readonly Contract: C
185
+ /** Phantom carrying the declared shared-carrier tuple. */
186
+ readonly Requires: Requires
187
+ /** Load the feature's module — `yield* Feature.load` → its `FeatureModule`, or `FeatureLoadFailed`. */
188
+ readonly load: Effect.Effect<FeatureModule<ROut, Requires>, FeatureLoadFailed>
189
+ /** The value `provide(slot, Feature)` binds under the slot tag. */
190
+ readonly binding: FeatureBinding
191
+ /** The eagerly-available module — present only for `loadingStrategy: 'default'`. */
192
+ readonly eagerModule: FeatureModule<ROut, Requires> | undefined
168
193
  }
169
- export type AnyFeature = FeatureClass<any, any, any, ReadonlyArray<RequireCarrier>>;
194
+
195
+ export type AnyFeature = FeatureClass<any, any, any, ReadonlyArray<RequireCarrier>>
196
+
170
197
  /** Whether a value is a feature definition (its target shape in `provide(slot, Feature)`). */
171
- export declare const isFeature: (u: unknown) => u is AnyFeature;
198
+ export const isFeature = (u: unknown): u is AnyFeature =>
199
+ (typeof u === 'function' || typeof u === 'object') &&
200
+ u !== null &&
201
+ 'manifest' in u &&
202
+ (u as { readonly manifest: { readonly kind?: unknown } }).manifest?.kind === 'Feature'
203
+
172
204
  /**
173
205
  * The placeholders a lazy feature must ship — both eager compositions (their
174
206
  * `.live` is in the eager bundle, so they paint the load gap). `loading` receives
@@ -177,20 +209,28 @@ export declare const isFeature: (u: unknown) => u is AnyFeature;
177
209
  * are not schema-decoded inputs.
178
210
  */
179
211
  export interface Placeholders {
180
- readonly loading: CompositionClass<any, UiContract>;
181
- readonly failed: CompositionClass<any, UiContract>;
212
+ readonly loading: CompositionClass<any, UiContract>
213
+ readonly failed: CompositionClass<any, UiContract>
182
214
  }
215
+
183
216
  type FeatureConfig<P, C extends UiContract, ROut, Requires extends ReadonlyArray<RequireCarrier>> = {
184
- readonly composition: CompositionClass<P, C>;
185
- readonly boot?: ReadonlyArray<Tagged>;
186
- } & ({
187
- readonly loadingStrategy?: 'default';
188
- readonly module: FeatureModule<ROut, Requires>;
189
- } | {
190
- readonly loadingStrategy: 'lazy';
191
- readonly load: Effect.Effect<FeatureModule<ROut, Requires>, FeatureLoadFailed>;
192
- readonly placeholder: Placeholders;
193
- });
217
+ readonly composition: CompositionClass<P, C>
218
+ readonly boot?: ReadonlyArray<Tagged>
219
+ } & (
220
+ | {
221
+ // EAGER: the module is statically present and merged into the runtime at
222
+ // boot. No load gap, so no placeholder.
223
+ readonly loadingStrategy?: 'default'
224
+ readonly module: FeatureModule<ROut, Requires>
225
+ }
226
+ | {
227
+ // LAZY: the module loads on mount via an Effect. Placeholders required.
228
+ readonly loadingStrategy: 'lazy'
229
+ readonly load: Effect.Effect<FeatureModule<ROut, Requires>, FeatureLoadFailed>
230
+ readonly placeholder: Placeholders
231
+ }
232
+ )
233
+
194
234
  /**
195
235
  * Define a feature. The whole-app shape (this manifest, the composition, the
196
236
  * placeholders) stays eager and reflectable; the `.live` layer in `module`/`load`
@@ -198,7 +238,41 @@ type FeatureConfig<P, C extends UiContract, ROut, Requires extends ReadonlyArray
198
238
  * the discriminated config *requires* `placeholder` — the compiler walks you to a
199
239
  * complete code-split feature.
200
240
  */
201
- export declare const make: <P, C extends UiContract, ROut, Requires extends ReadonlyArray<RequireCarrier>>(name: string, config: FeatureConfig<P, C, ROut, Requires>) => FeatureClass<P, C, ROut, Requires>;
241
+ export const make = <P, C extends UiContract, ROut, Requires extends ReadonlyArray<RequireCarrier>>(
242
+ name: string,
243
+ config: FeatureConfig<P, C, ROut, Requires>,
244
+ ): FeatureClass<P, C, ROut, Requires> => {
245
+ const strategy: 'lazy' | 'default' = config.loadingStrategy ?? 'default'
246
+ const load: Effect.Effect<FeatureModule<ROut, Requires>, FeatureLoadFailed> =
247
+ 'load' in config ? config.load : Effect.succeed(config.module)
248
+ const eagerModule = 'module' in config ? config.module : undefined
249
+ const placeholder = 'placeholder' in config ? config.placeholder : undefined
250
+
251
+ const manifest: FeatureManifest = {
252
+ kind: 'Feature',
253
+ name,
254
+ strategy,
255
+ composition: config.composition.manifest,
256
+ ...(placeholder
257
+ ? { placeholder: { loading: placeholder.loading.manifest, failed: placeholder.failed.manifest } }
258
+ : {}),
259
+ }
260
+
261
+ const binding: FeatureBinding = {
262
+ [FeatureBindingTypeId]: FeatureBindingTypeId,
263
+ manifest,
264
+ composition: config.composition,
265
+ strategy,
266
+ // The host is strategy-uniform: `default`'s `load` resolves immediately. The
267
+ // assignment to the erased `LoadedModule` needs no cast — see `LoadedModule`.
268
+ load,
269
+ ...(placeholder ? { placeholder: { loading: placeholder.loading, failed: placeholder.failed } } : {}),
270
+ boot: config.boot ?? [],
271
+ }
272
+
273
+ return definitionClass<FeatureClass<P, C, ROut, Requires>>({ manifest, load, binding, eagerModule })
274
+ }
275
+
202
276
  /**
203
277
  * Mount a feature against a live engine. The renderer-neutral lifecycle, run on a
204
278
  * per-feature `Scope`: load the module (an Effect — lazy = dynamic import; default
@@ -215,6 +289,18 @@ export declare const make: <P, C extends UiContract, ROut, Requires extends Read
215
289
  * we re-attach the concrete `engineContext` it builds against. `R` is the engine
216
290
  * context's service set, supplied by the host.
217
291
  */
218
- export declare const mountFeature: <R>(binding: FeatureBinding, engineContext: Context.Context<R>) => Effect.Effect<Context.Context<unknown>, FeatureLoadFailed, Scope.Scope>;
219
- export {};
220
- //# sourceMappingURL=feature.d.ts.map
292
+ export const mountFeature = <R>(
293
+ binding: FeatureBinding,
294
+ engineContext: Context.Context<R>,
295
+ ): Effect.Effect<Context.Context<unknown>, FeatureLoadFailed, Scope.Scope> =>
296
+ Effect.gen(function* () {
297
+ const { layer } = yield* binding.load
298
+ const featureLayer = layer as Layer.Layer<unknown, never, R>
299
+ const context = yield* Layer.build(
300
+ Layer.provideMerge(featureLayer, Layer.succeedContext(engineContext)),
301
+ )
302
+ yield* Effect.forEach(binding.boot, (event) => publish('High', event), { discard: true }).pipe(
303
+ Effect.provide(context),
304
+ )
305
+ return context
306
+ })
package/src/index.ts ADDED
@@ -0,0 +1,140 @@
1
+ // Reform core — the renderer-neutral primitives and runtime.
2
+ // Definitions (`X.make`) are separate from implementations (`.live`)
3
+ // throughout, and nothing self-registers on import (principle #1, #6).
4
+
5
+ export * as State from './state/state'
6
+ export * as StateGroup from './state/stateGroup'
7
+ export * as StateFamily from './state/stateFamily'
8
+ export { StateToken } from './state/token'
9
+ export type { AnySource, Source } from './state/token'
10
+
11
+ export * as Event from './event/event'
12
+ // Direct type re-export alongside the namespace (TS2742 nameability): inferred
13
+ // types of layers built over intent/event unions reference `EventOf`, and the
14
+ // declaration emitter can only name it through a plain export.
15
+ export type { EventOf } from './event/event'
16
+ export * as EventGroup from './event/eventGroup'
17
+
18
+ export * as Reducer from './reducer/reducer'
19
+ export * as Calc from './calc/calc'
20
+ export * as CalcFamily from './calc/calcFamily'
21
+ export * as AsyncCalc from './calc/asyncCalc'
22
+ export { composeCalcs } from './calc/compose'
23
+ // The inputs-object/key/store types appearing in `AsyncCalc.live` /
24
+ // `RemoteState.live` signatures, exported so app code can annotate
25
+ // query-swapping helpers and layer types without re-spelling them.
26
+ export type { InputsObject, InputStores, InvalidateBy } from './internal/sources'
27
+ export {
28
+ type AsyncData,
29
+ type AsyncError,
30
+ type AsyncIdle,
31
+ type AsyncLoading,
32
+ type AsyncSuccess,
33
+ } from './calc/asyncData'
34
+ export * as RemoteState from './remote/remoteState'
35
+ // Direct type re-exports alongside the namespace (TS2742 nameability): an app
36
+ // layer's inferred type references these (`Store<ReadonlyArray<PendingIntent<…>>>`),
37
+ // and the declaration emitter can only name them through a plain export.
38
+ export type { FailedIntent, PendingIntent, RemoteStateClass } from './remote/remoteState'
39
+ export * as Boundary from './boundary/boundary'
40
+ // Direct type re-exports alongside the namespace (same TS2742 nameability
41
+ // reason as the RemoteState types above): app code annotates props with these.
42
+ export type {
43
+ BoundaryErrored,
44
+ BoundaryPending,
45
+ BoundaryReady,
46
+ BoundaryState,
47
+ } from './boundary/boundary'
48
+ export * as Procedure from './procedure/procedure'
49
+ export * as Channel from './channel/channel'
50
+
51
+ export * as Composition from './compose/composition'
52
+ export type {
53
+ CompositionClass,
54
+ CompositionService,
55
+ RenderEnv,
56
+ } from './compose/composition'
57
+ export { Props } from './compose/props'
58
+ export {
59
+ isSlot,
60
+ type Node,
61
+ slot,
62
+ type SlotClass,
63
+ type SlotInstance,
64
+ type SlotProps,
65
+ SlotTypeId,
66
+ } from './compose/slot'
67
+ export { CurrentSlots, type SlotHost } from './compose/host'
68
+ export * as Ui from './compose/ui'
69
+ export {
70
+ isUi,
71
+ type LogicView,
72
+ ui,
73
+ type UiClass,
74
+ type UiContract,
75
+ UiTypeId,
76
+ type ViewImpl,
77
+ } from './compose/ui'
78
+ export { provide } from './compose/provide'
79
+ export type { Trigger } from './ui/trigger'
80
+
81
+ // Feature: the lazy/eager code-split unit. Definitions stay eager and reflectable;
82
+ // the heavy `.live` layer loads on demand (an Effect, never a Promise). See LAZY.md.
83
+ export * as Feature from './feature/feature'
84
+ export {
85
+ type EngineServices,
86
+ type FailedProps,
87
+ type FeatureBinding,
88
+ FeatureBindingTypeId,
89
+ type FeatureClass,
90
+ type FeatureManifest,
91
+ featureModule,
92
+ type FeatureModule,
93
+ isFeature,
94
+ isFeatureBinding,
95
+ lazyImport,
96
+ type LoadedModule,
97
+ mountFeature,
98
+ type Placeholders,
99
+ type ProvidedBy,
100
+ type RequireCarrier,
101
+ } from './feature/feature'
102
+ export { type SlotChild } from './compose/slot'
103
+
104
+ // A scene bundles a composition with the closed wiring that runs it — the single
105
+ // handle the react host, proofs, and the dev tool all consume.
106
+ export { isScene, type MountedServices, type Scene, scene, seedScene } from './scene/scene'
107
+
108
+ // Runtime surface for hosts (`@reform/react`) and headless tests.
109
+ export { Bus, type Envelope, type Priority, publish, type Tagged } from './runtime/bus'
110
+ export { Engine, type ReducerEntry, Reducers } from './runtime/loop'
111
+ export {
112
+ type ChannelClass,
113
+ type ChannelPolicy,
114
+ type ChannelRuntime,
115
+ Channels,
116
+ type ProcedureEntry,
117
+ Procedures,
118
+ } from './channel/channel'
119
+ export { CurrentTracker, type Subscribable, type Tracker } from './internal/track'
120
+ export { CaptureSink, type CaptureSinkApi, type UiCapture } from './internal/capture'
121
+ export {
122
+ AsyncReducer,
123
+ DuplicateRegistration,
124
+ FeatureLoadFailed,
125
+ InvalidProvideTarget,
126
+ SlotRenderingUnavailable,
127
+ UnknownGroupState,
128
+ } from './internal/errors'
129
+ // Notification scheduler: hosts that need per-runtime isolation (concurrent SSR,
130
+ // multiple mounted roots) provide `Notifications` upstream of their state layers;
131
+ // everything else coalesces on the process-wide default.
132
+ export {
133
+ defaultScheduler,
134
+ makeScheduler,
135
+ Notifications,
136
+ notificationsLayer,
137
+ type Scheduler,
138
+ } from './internal/scheduler'
139
+ export type { Store } from './internal/store'
140
+ export type { FamilyStore } from './state/stateFamily'
@@ -1,20 +1,22 @@
1
- import { Context } from 'effect';
2
- import type { Trigger } from '../ui/trigger.js';
1
+ import { Context } from 'effect'
2
+ import type { Trigger } from '../ui/trigger'
3
+
3
4
  /**
4
5
  * A single rendered UI node's observable surface: which contract rendered, the
5
6
  * props it received, and the event triggers it was handed. This is exactly what
6
7
  * a headless inspector (the proof facade, the dev tool) needs — no DOM, no JSX.
7
8
  */
8
9
  export interface UiCapture {
9
- readonly name: string;
10
- readonly props: unknown;
11
- readonly events: Record<string, Trigger<unknown>>;
10
+ readonly name: string
11
+ readonly props: unknown
12
+ readonly events: Record<string, Trigger<unknown>>
12
13
  }
14
+
13
15
  /** Where captured renders are reported, when a capturing host is present. */
14
16
  export interface CaptureSinkApi {
15
- record(capture: UiCapture): void;
17
+ record(capture: UiCapture): void
16
18
  }
17
- declare const CaptureSink_base: Context.TagClass<CaptureSink, "reform/internal/CaptureSink", CaptureSinkApi>;
19
+
18
20
  /**
19
21
  * An OPTIONAL service. Core's `ui` read consults it via `serviceOption`: when a
20
22
  * capturing host provides it (proofs, the dev tool), every resolved view reports
@@ -22,7 +24,7 @@ declare const CaptureSink_base: Context.TagClass<CaptureSink, "reform/internal/C
22
24
  * replacing any presentation. Production never provides it, so nothing is
23
25
  * recorded and there is no cost beyond one `serviceOption` lookup per render.
24
26
  */
25
- export declare class CaptureSink extends CaptureSink_base {
26
- }
27
- export {};
28
- //# sourceMappingURL=capture.d.ts.map
27
+ export class CaptureSink extends Context.Tag('reform/internal/CaptureSink')<
28
+ CaptureSink,
29
+ CaptureSinkApi
30
+ >() {}
@@ -1,5 +1,6 @@
1
- import type { Effect } from 'effect';
2
- import type { YieldWrap } from 'effect/Utils';
1
+ import type { Effect } from 'effect'
2
+ import type { YieldWrap } from 'effect/Utils'
3
+
3
4
  /**
4
5
  * The context (`R`) a generator body requires, recovered from the effects it
5
6
  * yields. Shared by `Composition.live` and `Procedure.live`, whose bodies are
@@ -8,5 +9,8 @@ import type { YieldWrap } from 'effect/Utils';
8
9
  * A body that never yields (`Eff = never`) requires nothing — guard that case
9
10
  * first, or `infer R` resolves to `unknown` and leaks into the layer's `RIn`.
10
11
  */
11
- export type Ctx<Eff> = [Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect.Effect<any, any, infer R>>] ? R : never;
12
- //# sourceMappingURL=ctx.d.ts.map
12
+ export type Ctx<Eff> = [Eff] extends [never]
13
+ ? never
14
+ : [Eff] extends [YieldWrap<Effect.Effect<any, any, infer R>>]
15
+ ? R
16
+ : never