@playfast/reform 0.0.4 → 0.0.7

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 (209) hide show
  1. package/dist/boundary/boundary.d.ts +72 -0
  2. package/dist/boundary/boundary.d.ts.map +1 -0
  3. package/dist/boundary/boundary.js +83 -0
  4. package/dist/boundary/boundary.js.map +1 -0
  5. package/dist/calc/asyncCalc.d.ts +91 -0
  6. package/dist/calc/asyncCalc.d.ts.map +1 -0
  7. package/dist/calc/asyncCalc.js +95 -0
  8. package/dist/calc/asyncCalc.js.map +1 -0
  9. package/{src/calc/asyncData.ts → dist/calc/asyncData.d.ts} +22 -53
  10. package/dist/calc/asyncData.d.ts.map +1 -0
  11. package/dist/calc/asyncData.js +34 -0
  12. package/dist/calc/asyncData.js.map +1 -0
  13. package/dist/calc/calc.d.ts +57 -0
  14. package/dist/calc/calc.d.ts.map +1 -0
  15. package/dist/calc/calc.js +58 -0
  16. package/dist/calc/calc.js.map +1 -0
  17. package/dist/calc/calcFamily.d.ts +57 -0
  18. package/dist/calc/calcFamily.d.ts.map +1 -0
  19. package/dist/calc/calcFamily.js +124 -0
  20. package/dist/calc/calcFamily.js.map +1 -0
  21. package/dist/calc/compose.d.ts +16 -0
  22. package/dist/calc/compose.d.ts.map +1 -0
  23. package/dist/calc/compose.js +7 -0
  24. package/dist/calc/compose.js.map +1 -0
  25. package/dist/channel/channel.d.ts +115 -0
  26. package/dist/channel/channel.d.ts.map +1 -0
  27. package/dist/channel/channel.js +138 -0
  28. package/dist/channel/channel.js.map +1 -0
  29. package/dist/compose/composition.d.ts +72 -0
  30. package/dist/compose/composition.d.ts.map +1 -0
  31. package/dist/compose/composition.js +46 -0
  32. package/dist/compose/composition.js.map +1 -0
  33. package/{src/compose/host.ts → dist/compose/host.d.ts} +8 -6
  34. package/dist/compose/host.d.ts.map +1 -0
  35. package/dist/compose/host.js +6 -0
  36. package/dist/compose/host.js.map +1 -0
  37. package/dist/compose/props.d.ts +13 -0
  38. package/dist/compose/props.d.ts.map +1 -0
  39. package/{src/compose/props.ts → dist/compose/props.js} +5 -3
  40. package/dist/compose/props.js.map +1 -0
  41. package/dist/compose/provide.d.ts +22 -0
  42. package/dist/compose/provide.d.ts.map +1 -0
  43. package/dist/compose/provide.js +28 -0
  44. package/dist/compose/provide.js.map +1 -0
  45. package/{src/compose/slot.ts → dist/compose/slot.d.ts} +19 -36
  46. package/dist/compose/slot.d.ts.map +1 -0
  47. package/dist/compose/slot.js +23 -0
  48. package/dist/compose/slot.js.map +1 -0
  49. package/dist/compose/ui.d.ts +135 -0
  50. package/dist/compose/ui.d.ts.map +1 -0
  51. package/dist/compose/ui.js +63 -0
  52. package/dist/compose/ui.js.map +1 -0
  53. package/dist/definition/definition.d.ts +33 -0
  54. package/dist/definition/definition.d.ts.map +1 -0
  55. package/dist/definition/definition.js +42 -0
  56. package/dist/definition/definition.js.map +1 -0
  57. package/dist/event/event.d.ts +33 -0
  58. package/dist/event/event.d.ts.map +1 -0
  59. package/dist/event/event.js +30 -0
  60. package/dist/event/event.js.map +1 -0
  61. package/dist/event/eventGroup.d.ts +9 -0
  62. package/dist/event/eventGroup.d.ts.map +1 -0
  63. package/dist/event/eventGroup.js +4 -0
  64. package/dist/event/eventGroup.js.map +1 -0
  65. package/{src/feature/feature.ts → dist/feature/feature.d.ts} +92 -178
  66. package/dist/feature/feature.d.ts.map +1 -0
  67. package/dist/feature/feature.js +98 -0
  68. package/dist/feature/feature.js.map +1 -0
  69. package/dist/index.d.ts +53 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +62 -0
  72. package/dist/index.js.map +1 -0
  73. package/{src/internal/capture.ts → dist/internal/capture.d.ts} +11 -13
  74. package/dist/internal/capture.d.ts.map +1 -0
  75. package/dist/internal/capture.js +12 -0
  76. package/dist/internal/capture.js.map +1 -0
  77. package/{src/internal/ctx.ts → dist/internal/ctx.d.ts} +4 -8
  78. package/dist/internal/ctx.d.ts.map +1 -0
  79. package/dist/internal/ctx.js +2 -0
  80. package/dist/internal/ctx.js.map +1 -0
  81. package/dist/internal/errors.d.ts +89 -0
  82. package/dist/internal/errors.d.ts.map +1 -0
  83. package/dist/internal/errors.js +102 -0
  84. package/dist/internal/errors.js.map +1 -0
  85. package/dist/internal/inspect.d.ts +17 -0
  86. package/dist/internal/inspect.d.ts.map +1 -0
  87. package/dist/internal/inspect.js +32 -0
  88. package/dist/internal/inspect.js.map +1 -0
  89. package/dist/internal/queryDriver.d.ts +65 -0
  90. package/dist/internal/queryDriver.d.ts.map +1 -0
  91. package/dist/internal/queryDriver.js +134 -0
  92. package/dist/internal/queryDriver.js.map +1 -0
  93. package/dist/internal/reuse.d.ts +10 -0
  94. package/dist/internal/reuse.d.ts.map +1 -0
  95. package/dist/internal/reuse.js +68 -0
  96. package/dist/internal/reuse.js.map +1 -0
  97. package/dist/internal/scheduler.d.ts +47 -0
  98. package/dist/internal/scheduler.d.ts.map +1 -0
  99. package/dist/internal/scheduler.js +70 -0
  100. package/dist/internal/scheduler.js.map +1 -0
  101. package/{src/internal/seeds.ts → dist/internal/seeds.d.ts} +3 -6
  102. package/dist/internal/seeds.d.ts.map +1 -0
  103. package/dist/internal/seeds.js +17 -0
  104. package/dist/internal/seeds.js.map +1 -0
  105. package/dist/internal/sources.d.ts +39 -0
  106. package/dist/internal/sources.d.ts.map +1 -0
  107. package/dist/internal/sources.js +59 -0
  108. package/dist/internal/sources.js.map +1 -0
  109. package/dist/internal/stateRegistry.d.ts +2 -0
  110. package/dist/internal/stateRegistry.d.ts.map +1 -0
  111. package/dist/internal/stateRegistry.js +28 -0
  112. package/dist/internal/stateRegistry.js.map +1 -0
  113. package/dist/internal/store.d.ts +47 -0
  114. package/dist/internal/store.d.ts.map +1 -0
  115. package/dist/internal/store.js +73 -0
  116. package/dist/internal/store.js.map +1 -0
  117. package/{src/internal/track.ts → dist/internal/track.d.ts} +11 -15
  118. package/dist/internal/track.d.ts.map +1 -0
  119. package/dist/internal/track.js +19 -0
  120. package/dist/internal/track.js.map +1 -0
  121. package/dist/procedure/procedure.d.ts +40 -0
  122. package/dist/procedure/procedure.d.ts.map +1 -0
  123. package/dist/procedure/procedure.js +50 -0
  124. package/dist/procedure/procedure.js.map +1 -0
  125. package/dist/reducer/reducer.d.ts +44 -0
  126. package/dist/reducer/reducer.d.ts.map +1 -0
  127. package/dist/reducer/reducer.js +63 -0
  128. package/dist/reducer/reducer.js.map +1 -0
  129. package/dist/remote/remoteState.d.ts +119 -0
  130. package/dist/remote/remoteState.d.ts.map +1 -0
  131. package/dist/remote/remoteState.js +270 -0
  132. package/dist/remote/remoteState.js.map +1 -0
  133. package/dist/runtime/bus.d.ts +27 -0
  134. package/dist/runtime/bus.d.ts.map +1 -0
  135. package/{src/runtime/bus.ts → dist/runtime/bus.js} +8 -23
  136. package/dist/runtime/bus.js.map +1 -0
  137. package/dist/runtime/loop.d.ts +45 -0
  138. package/dist/runtime/loop.d.ts.map +1 -0
  139. package/dist/runtime/loop.js +117 -0
  140. package/dist/runtime/loop.js.map +1 -0
  141. package/dist/scene/scene.d.ts +44 -0
  142. package/dist/scene/scene.d.ts.map +1 -0
  143. package/dist/scene/scene.js +31 -0
  144. package/dist/scene/scene.js.map +1 -0
  145. package/dist/state/state.d.ts +37 -0
  146. package/dist/state/state.d.ts.map +1 -0
  147. package/dist/state/state.js +46 -0
  148. package/dist/state/state.js.map +1 -0
  149. package/dist/state/stateFamily.d.ts +79 -0
  150. package/dist/state/stateFamily.d.ts.map +1 -0
  151. package/dist/state/stateFamily.js +99 -0
  152. package/dist/state/stateFamily.js.map +1 -0
  153. package/dist/state/stateGroup.d.ts +50 -0
  154. package/dist/state/stateGroup.d.ts.map +1 -0
  155. package/dist/state/stateGroup.js +54 -0
  156. package/dist/state/stateGroup.js.map +1 -0
  157. package/{src/state/token.ts → dist/state/token.d.ts} +13 -21
  158. package/dist/state/token.d.ts.map +1 -0
  159. package/dist/state/token.js +20 -0
  160. package/dist/state/token.js.map +1 -0
  161. package/dist/synced/syncedStore.d.ts +51 -0
  162. package/dist/synced/syncedStore.d.ts.map +1 -0
  163. package/dist/synced/syncedStore.js +43 -0
  164. package/dist/synced/syncedStore.js.map +1 -0
  165. package/{src/ui/node.ts → dist/ui/node.d.ts} +3 -3
  166. package/dist/ui/node.d.ts.map +1 -0
  167. package/dist/ui/node.js +2 -0
  168. package/dist/ui/node.js.map +1 -0
  169. package/{src/ui/trigger.ts → dist/ui/trigger.d.ts} +2 -1
  170. package/dist/ui/trigger.d.ts.map +1 -0
  171. package/dist/ui/trigger.js +2 -0
  172. package/dist/ui/trigger.js.map +1 -0
  173. package/dist/wire/tree.d.ts +66 -0
  174. package/dist/wire/tree.d.ts.map +1 -0
  175. package/dist/wire/tree.js +60 -0
  176. package/dist/wire/tree.js.map +1 -0
  177. package/dist/wire/triggers.d.ts +44 -0
  178. package/dist/wire/triggers.d.ts.map +1 -0
  179. package/dist/wire/triggers.js +31 -0
  180. package/dist/wire/triggers.js.map +1 -0
  181. package/package.json +32 -11
  182. package/src/boundary/boundary.ts +0 -192
  183. package/src/calc/asyncCalc.ts +0 -267
  184. package/src/calc/calc.ts +0 -120
  185. package/src/calc/calcFamily.ts +0 -194
  186. package/src/calc/compose.ts +0 -69
  187. package/src/channel/channel.ts +0 -265
  188. package/src/compose/composition.ts +0 -112
  189. package/src/compose/provide.ts +0 -70
  190. package/src/compose/ui.ts +0 -97
  191. package/src/definition/definition.ts +0 -74
  192. package/src/event/event.ts +0 -65
  193. package/src/event/eventGroup.ts +0 -14
  194. package/src/index.ts +0 -140
  195. package/src/internal/errors.ts +0 -69
  196. package/src/internal/inspect.ts +0 -34
  197. package/src/internal/queryDriver.ts +0 -247
  198. package/src/internal/reuse.ts +0 -73
  199. package/src/internal/scheduler.ts +0 -91
  200. package/src/internal/sources.ts +0 -104
  201. package/src/internal/store.ts +0 -105
  202. package/src/procedure/procedure.ts +0 -89
  203. package/src/reducer/reducer.ts +0 -137
  204. package/src/remote/remoteState.ts +0 -571
  205. package/src/runtime/loop.ts +0 -169
  206. package/src/scene/scene.ts +0 -76
  207. package/src/state/state.ts +0 -91
  208. package/src/state/stateFamily.ts +0 -171
  209. package/src/state/stateGroup.ts +0 -78
@@ -0,0 +1,72 @@
1
+ import { Context, Effect, Layer } from 'effect';
2
+ import { type Manifest } from '../definition/definition';
3
+ import { type InputStores } from '../internal/sources';
4
+ import { type Store } from '../internal/store';
5
+ import { type Source } from '../state/token';
6
+ /** Some covered source is still on its FIRST load — show the fallback. */
7
+ export interface BoundaryPending {
8
+ readonly _tag: 'Pending';
9
+ }
10
+ /** Some covered source failed before its first value. */
11
+ export interface BoundaryErrored {
12
+ readonly _tag: 'Errored';
13
+ /** The failures, in `over` order (heterogeneous — display via `String`). */
14
+ readonly errors: ReadonlyArray<unknown>;
15
+ }
16
+ /** Every covered source has settled (or is deliberately gated off). */
17
+ export interface BoundaryReady {
18
+ readonly _tag: 'Ready';
19
+ }
20
+ export type BoundaryState = BoundaryPending | BoundaryErrored | BoundaryReady;
21
+ /**
22
+ * Anything a boundary can cover: a `Source` whose value is an async lifecycle —
23
+ * an `AsyncCalc`, or anything lifecycle-valued built over one (e.g. a
24
+ * `RemoteState` overlay). The constraint is the same erased `Source` every calc
25
+ * input uses (store invariance rules out a fixed lifecycle value type — each
26
+ * definition's union carries its own `Gated`/`E` arms); the captured `const`
27
+ * tuple keeps each member's precise store requirement, and the runtime merge
28
+ * reads arms through structural guards, so a non-lifecycle source simply
29
+ * counts as settled.
30
+ */
31
+ export type AnyLifecycleSource = Source<string, any>;
32
+ export interface BoundaryManifest<N extends string> extends Manifest {
33
+ readonly kind: 'Boundary';
34
+ readonly name: N;
35
+ }
36
+ export interface BoundaryClass<out N extends string, out Over extends ReadonlyArray<AnyLifecycleSource>> extends Effect.Effect<BoundaryState, never, Store<BoundaryState>> {
37
+ new (): {};
38
+ readonly manifest: BoundaryManifest<N>;
39
+ readonly store: Context.Tag<Store<BoundaryState>, Store<BoundaryState>>;
40
+ /** The boundary's name, so it doubles as a `Source` input to a calc. */
41
+ readonly name: N;
42
+ /** The covered lifecycle sources — read by `live` and the editor's graph. */
43
+ readonly over: Over;
44
+ }
45
+ export interface BoundaryConfig<Over extends ReadonlyArray<AnyLifecycleSource>> {
46
+ readonly over: Over;
47
+ }
48
+ export interface BoundaryOptions {
49
+ /**
50
+ * Latch: once Ready, stay Ready. A BOOT boundary wants this — a covered
51
+ * route-gated query that first enables on a later navigation (Idle →
52
+ * Loading) must not re-splash the whole shell; its own screen owns that
53
+ * loading state. Without the latch the boundary re-pends on any covered
54
+ * first load, which is what a per-screen boundary wants.
55
+ */
56
+ readonly once?: boolean;
57
+ }
58
+ /**
59
+ * Define a boundary over async sources. `yield* MyBoundary` reads the merged
60
+ * `Pending | Errored | Ready` lifecycle; the consuming view renders ONE
61
+ * fallback on Pending and its content slot on Ready — content reveals
62
+ * together, with data already present (fetching never waited on rendering).
63
+ */
64
+ export declare const make: <const N extends string, const Over extends ReadonlyArray<AnyLifecycleSource>>(name: N, config: BoundaryConfig<Over>) => BoundaryClass<N, Over>;
65
+ /**
66
+ * Wire the merge. A derived store over the covered stores (sensed through the
67
+ * same `wireSources` plumbing every calc uses): recomputes are memoized on the
68
+ * input snapshots and the arms are stable references, so input churn that does
69
+ * not move the merged arm wakes nobody.
70
+ */
71
+ export declare const live: <N extends string, Over extends ReadonlyArray<AnyLifecycleSource>>(boundary: BoundaryClass<N, Over>, options?: BoundaryOptions) => Layer.Layer<Store<BoundaryState>, never, InputStores<Over>>;
72
+ //# sourceMappingURL=boundary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../../src/boundary/boundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAQ,MAAM,EAAE,KAAK,EAAyB,MAAM,QAAQ,CAAA;AAC5E,OAAO,EAAE,KAAK,QAAQ,EAAkB,MAAM,0BAA0B,CAAA;AAExE,OAAO,EAAE,KAAK,WAAW,E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ACvE,wEAAwE;IACxE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IAChB,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;CACpB;AAED,MAAM,WAAW,cAAc,CAAC,IAAI,SAAS,aAAa,CAAC,kBAAkB,CAAC;IAC5E,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GAAI,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,CAAC,IAAI,SAAS,aAAa,CAAC,kBAAkB,CAAC,EAC/F,MAAM,CAAC,EACP,QAAQ,cAAc,CAAC,IAAI,CAAC,KAC3B,aAAa,CAAC,CAAC,EAAE,IAAI,CAOvB,CAAA;AAUD;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,MAAM,EAAE,IAAI,SAAS,aAAa,CAAC,kBAAkB,CAAC,EACnF,UAAU,aAAa,CAAC,CAAC,EAAE,IAAI,CAAC,EAChC,UAAS,eAAoB,KAC5B,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,IAAI,CAAC,CAiD1D,CAAA"}
@@ -0,0 +1,83 @@
1
+ import { Context, Data, Effect, Layer, MutableRef, Predicate } from 'effect';
2
+ import { yieldableClass } from '../definition/definition';
3
+ import { resolveScheduler } from '../internal/scheduler';
4
+ import { sameKey, wireSources } from '../internal/sources';
5
+ import { makeDerivedStore } from '../internal/store';
6
+ import { readTracked } from '../internal/track';
7
+ import {} from '../state/token';
8
+ // Stable arm references: repeated recomputes return the same object, so the
9
+ // derived store's Equal gate (and `useSyncExternalStore`'s stable-snapshot
10
+ // contract) hold without a wrapper. `Errored` carries data, so it is a `Data`
11
+ // struct — value-equal failures coalesce the same way.
12
+ const pendingArm = { _tag: 'Pending' };
13
+ const readyArm = { _tag: 'Ready' };
14
+ const erroredArm = (errors) => Data.struct({ _tag: 'Errored', errors: Data.array(errors) });
15
+ /**
16
+ * Define a boundary over async sources. `yield* MyBoundary` reads the merged
17
+ * `Pending | Errored | Ready` lifecycle; the consuming view renders ONE
18
+ * fallback on Pending and its content slot on Ready — content reveals
19
+ * together, with data already present (fetching never waited on rendering).
20
+ */
21
+ export const make = (name, config) => {
22
+ const store = Context.GenericTag(`reform/boundary/${name}`);
23
+ const manifest = { kind: 'Boundary', name };
24
+ const read = Effect.flatMap(store, readTracked);
25
+ return yieldableClass(read, { manifest, store, name, over: config.over });
26
+ };
27
+ // The snapshot values arrive through `wireSources`' erased key projection
28
+ // (`ReadonlyArray<unknown>`), so read the two facts the merge needs through
29
+ // honest structural guards — no cast back to `AnyAsyncData`.
30
+ const tagOf = (arm) => Predicate.hasProperty(arm, '_tag') && Predicate.isString(arm._tag) ? arm._tag : '';
31
+ const errorOf = (arm) => Predicate.hasProperty(arm, 'error') && tagOf(arm) === 'Error' ? [arm.error] : [];
32
+ /**
33
+ * Wire the merge. A derived store over the covered stores (sensed through the
34
+ * same `wireSources` plumbing every calc uses): recomputes are memoized on the
35
+ * input snapshots and the arms are stable references, so input churn that does
36
+ * not move the merged arm wakes nobody.
37
+ */
38
+ export const live = (boundary, options = {}) =>
39
+ // Scoped so the source subscriptions are released with the layer's scope.
40
+ Layer.scoped(boundary.store, Effect.gen(function* () {
41
+ const scheduler = yield* resolveScheduler;
42
+ const sources = yield* wireSources(boundary.over);
43
+ const latched = MutableRef.make(false);
44
+ const memo = MutableRef.make(undefined);
45
+ const recompute = () => {
46
+ if (options.once === true && MutableRef.get(latched))
47
+ return readyArm;
48
+ const arms = sources.keyOf(sources.snapshot());
49
+ const prev = MutableRef.get(memo);
50
+ if (prev !== undefined && sameKey(arms, prev.key))
51
+ return prev.value;
52
+ const errors = arms.flatMap(errorOf);
53
+ const value = errors.length > 0
54
+ ? erroredArm(errors)
55
+ : arms.some((arm) => tagOf(arm) === 'Loading')
56
+ ? pendingArm
57
+ : readyArm;
58
+ MutableRef.set(memo, { key: arms, value });
59
+ return value;
60
+ };
61
+ const derived = makeDerivedStore(recompute, sources.subscribe, scheduler);
62
+ yield* Effect.addFinalizer(() => Effect.sync(derived.unsubscribe));
63
+ if (options.once === true) {
64
+ // Latch on CONVERGED values only — at build and on (coalesced,
65
+ // post-fixpoint) notifications — never inside `recompute`. A chained
66
+ // gate with a plain Calc hop between the async stores (bootstrap →
67
+ // current-workspace → boards) propagates over TWO flush rounds, so a
68
+ // mid-flush recompute can observe the frame where the downstream
69
+ // driver has not yet flipped its query to Loading. That intermediate
70
+ // Ready self-corrects within the flush for readers, but a latch taken
71
+ // there would freeze it; a subscriber runs only after the fixpoint,
72
+ // where the value is converged.
73
+ if (recompute()._tag === 'Ready')
74
+ MutableRef.set(latched, true);
75
+ const offSelf = derived.store.subscribe(() => {
76
+ if (derived.store.get()._tag === 'Ready')
77
+ MutableRef.set(latched, true);
78
+ });
79
+ yield* Effect.addFinalizer(() => Effect.sync(offSelf));
80
+ }
81
+ return derived.store;
82
+ }));
83
+ //# sourceMappingURL=boundary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boundary.js","sourceRoot":"","sources":["../../src/boundary/boundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAC5E,OAAO,EAAiB,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAoB,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAC5E,OAAO,EAAE,gBAAgB,EAAc,MAAM,mBAAmB,CAAA;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,O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import { Context, Effect, Layer, Schema } from 'effect';
2
+ import { type Manifest } from '../definition/definition';
3
+ import { type AnyEvent } from '../event/event';
4
+ import { type InputsObject, type InputStores, type InvalidateBy } from '../internal/sources';
5
+ import { type GatedOf } from '../internal/queryDriver';
6
+ import { type Store } from '../internal/store';
7
+ import { Reducers } from '../runtime/loop';
8
+ import { type AnySource } from '../state/token';
9
+ import { type AsyncData } from './asyncData';
10
+ export interface AsyncCalcManifest<N extends string, A, E> extends Manifest {
11
+ readonly kind: 'AsyncCalc';
12
+ readonly name: N;
13
+ readonly output: Schema.Schema<A, any>;
14
+ readonly error?: Schema.Schema<E, any>;
15
+ /** Whether the query can be disabled (drives the `Idle` arm). */
16
+ readonly gated: boolean;
17
+ }
18
+ export interface AsyncCalcClass<out N extends string, out Inputs extends ReadonlyArray<AnySource>, in out A, in out E, in out Gated extends boolean> extends Effect.Effect<AsyncData<A, E, Gated>, never, Store<AsyncData<A, E, Gated>>> {
19
+ new (): {};
20
+ readonly manifest: AsyncCalcManifest<N, A, E>;
21
+ readonly store: Context.Tag<Store<AsyncData<A, E, Gated>>, Store<AsyncData<A, E, Gated>>>;
22
+ /** The calc's name, so it doubles as a `Source` input to another (async) calc. */
23
+ readonly name: N;
24
+ /** Marker data read by `AsyncCalc.live`. */
25
+ readonly inputs: Inputs;
26
+ /** Runtime mirror of `Gated`: whether `disabled` is honored / `Idle` can occur. */
27
+ readonly gated: Gated;
28
+ }
29
+ export interface AsyncCalcConfig<Inputs extends ReadonlyArray<AnySource>, A, E, AlwaysOn extends boolean> {
30
+ readonly inputs: Inputs;
31
+ /** Schema of the `Success` value. */
32
+ readonly output: Schema.Schema<A, any>;
33
+ /** Schema of the failure. Omitted ⇒ the query is infallible and there is no `Error` arm. */
34
+ readonly error?: Schema.Schema<E, any>;
35
+ /** `true` ⇒ the query is always on: no `Idle` arm and `disabled` is rejected on `.live`. */
36
+ readonly alwaysOn?: AlwaysOn;
37
+ }
38
+ /**
39
+ * The `.live` config: the effect plus the reactive logic. `disabled` is only
40
+ * accepted for a gateable query (no `alwaysOn`); `invalidateBy` is the same
41
+ * `queryKey` projection `Calc` uses.
42
+ */
43
+ export type AsyncCalcLive<Inputs extends ReadonlyArray<AnySource>, A, E, Gated extends boolean, R> = {
44
+ readonly query: (inputs: InputsObject<Inputs>) => Effect.Effect<A, E, R>;
45
+ readonly invalidateBy?: InvalidateBy<Inputs>;
46
+ /**
47
+ * Refetch conciliation. `'switch'` (default): a new key cancels the in-flight
48
+ * run (latest-wins). `'trailing'`: the in-flight run completes; key changes
49
+ * that arrive meanwhile conflate to the latest, and exactly ONE trailing
50
+ * refetch runs after it settles — a burst of N invalidations during one
51
+ * flight costs 2 fetches, not N cancel-restarts.
52
+ */
53
+ readonly coalesce?: 'switch' | 'trailing';
54
+ /**
55
+ * Structural sharing for `Success` values: reconcile each refetch result
56
+ * against the previous one, substituting previous nodes wherever value
57
+ * equality holds — refetches returning mostly-identical data keep unchanged
58
+ * subtree identities, so downstream memo boundaries skip them. Same pass as
59
+ * `Calc`'s `reuse`; opt-in (one O(result) walk per settle).
60
+ */
61
+ readonly reuse?: boolean;
62
+ } & (Gated extends true ? {
63
+ readonly disabled?: (inputs: InputsObject<Inputs>) => boolean;
64
+ } : {
65
+ readonly disabled?: never;
66
+ });
67
+ /**
68
+ * Define an async derived value. `output`/`error` schemas and `alwaysOn` shape
69
+ * the value type, so `yield* MyQuery` is typed to exactly the arms that can
70
+ * occur. The query effect itself is supplied by `AsyncCalc.live`.
71
+ */
72
+ export declare const make: <const N extends string, const Inputs extends ReadonlyArray<AnySource>, A, E = never, const AlwaysOn extends boolean = false>(name: N, config: AsyncCalcConfig<Inputs, A, E, AlwaysOn>) => AsyncCalcClass<N, Inputs, A, E, GatedOf<AlwaysOn>>;
73
+ /**
74
+ * Wire the query and its reactive logic. The query runs on the runtime (its `R`
75
+ * — RPC clients, etc. — is captured from the layer context). A change to an
76
+ * input re-runs it latest-wins (a new run cancels the in-flight one; or, with
77
+ * `coalesce: 'trailing'`, lets it finish and runs one trailing refetch); while a
78
+ * re-run is in flight the last `Success`/`Error` is kept with `refetching: true`.
79
+ * Re-runs are driven by inputs / `invalidateBy` / `disabled` — and, with
80
+ * `invalidateOn`, by listed events: pure sugar that generates a hidden revision
81
+ * state + reducer (the sole writer) and appends the revision to the calc's key,
82
+ * so an event-driven refetch is still just key movement under `Equal.equals`.
83
+ * The hidden pair stays internal — the user's `query`/`invalidateBy` see exactly
84
+ * the declared inputs — and costs the layer one extra requirement: the
85
+ * `Reducers` registry (the `Engine`).
86
+ */
87
+ export declare function live<N extends string, Inputs extends ReadonlyArray<AnySource>, A, E, Gated extends boolean, R>(calc: AsyncCalcClass<N, Inputs, A, E, Gated>, config: AsyncCalcLive<Inputs, A, E, Gated, R> & {
88
+ readonly invalidateOn: ReadonlyArray<AnyEvent>;
89
+ }): Layer.Layer<Store<AsyncData<A, E, Gated>>, never, InputStores<Inputs> | R | Reducers>;
90
+ export declare function live<N extends string, Inputs extends ReadonlyArray<AnySource>, A, E, Gated extends boolean, R>(calc: AsyncCalcClass<N, Inputs, A, E, Gated>, config: AsyncCalcLive<Inputs, A, E, Gated, R>): Layer.Layer<Store<AsyncData<A, E, Gated>>, never, InputStores<Inputs> | R>;
91
+ //# sourceMappingURL=asyncCalc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asyncCalc.d.ts","sourceRoot":"","sources":["../../src/calc/asyncCalc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/D,OAAO,EAAE,KAAK,QAAQ,EAAkB,MAAM,0BAA0B,CAAA;AACxE,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAEL,KAAK,OAAO,EAK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AW,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAA;AACxF,wBAAgB,IAAI,CAClB,CAAC,SAAS,MAAM,EAChB,MAAM,SAAS,aAAa,CAAC,SAAS,CAAC,EACvC,CAAC,EACD,CAAC,EACD,KAAK,SAAS,OAAO,EACrB,CAAC,EAED,IAAI,EAAE,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,EAC5C,MAAM,EAAE,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,GAC5C,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA"}
@@ -0,0 +1,95 @@
1
+ import { Context, Effect, Layer, Option, Schema } from 'effect';
2
+ import { yieldableClass } from '../definition/definition';
3
+ import {} from '../event/event';
4
+ import {} from '../internal/sources';
5
+ import { bumpRevision, gatedFlag, makeQueryDriver, RevisionSchema, revisionZero, } from '../internal/queryDriver';
6
+ import {} from '../internal/store';
7
+ import { readTracked } from '../internal/track';
8
+ import * as Reducer from '../reducer/reducer';
9
+ import { Reducers } from '../runtime/loop';
10
+ import * as State from '../state/state';
11
+ import {} from '../state/token';
12
+ import { narrowStore } from './asyncData';
13
+ /**
14
+ * Define an async derived value. `output`/`error` schemas and `alwaysOn` shape
15
+ * the value type, so `yield* MyQuery` is typed to exactly the arms that can
16
+ * occur. The query effect itself is supplied by `AsyncCalc.live`.
17
+ */
18
+ export const make = (name, config) => {
19
+ const store = Context.GenericTag(`reform/asyncCalc/${name}`);
20
+ // Runtime mirror of the type-level `Gated`, typed as its literal in one place.
21
+ const gated = gatedFlag(config.alwaysOn);
22
+ const manifest = {
23
+ kind: 'AsyncCalc',
24
+ name,
25
+ output: config.output,
26
+ gated,
27
+ ...(config.error !== undefined ? { error: config.error } : {}),
28
+ };
29
+ const read = Effect.flatMap(store, readTracked);
30
+ return yieldableClass(read, {
31
+ manifest,
32
+ store,
33
+ name,
34
+ inputs: config.inputs,
35
+ gated,
36
+ });
37
+ };
38
+ export function live(calc, config) {
39
+ // The hidden revision pair, built once per `live` call. Namespacing the state
40
+ // by the calc's name (`reform/state/${calcName}/invalidateOn`) keeps the tag
41
+ // out of any plausible user namespace; the duplicate-reducer check is
42
+ // warning-only and calc names are unique by convention.
43
+ const revisionState = config.invalidateOn === undefined
44
+ ? undefined
45
+ : State.make(`${calc.manifest.name}/invalidateOn`, RevisionSchema);
46
+ // Scoped so the source subscriptions and the driver fiber are released when
47
+ // the layer's scope closes (each proof/test builds and disposes its runtime).
48
+ const driver = Layer.scoped(calc.store, Effect.gen(function* () {
49
+ // `disabled` is rejected at the type level for non-gated calcs (erased to
50
+ // `never` there); read it through a loose view for the runtime.
51
+ const cfg = config;
52
+ // The hidden revision store, read requirement-free (`serviceOption`): the
53
+ // assembly below always provides it alongside this driver, and feeding it
54
+ // through `extraKey` (not `wireSources`) keeps it out of the snapshot —
55
+ // the user's `query` and `invalidateBy` receive exactly
56
+ // `InputsObject<Inputs>`, with no hidden property to leak into
57
+ // spread-into-RPC payloads.
58
+ const revision = revisionState === undefined
59
+ ? undefined
60
+ : Option.getOrUndefined(yield* Effect.serviceOption(revisionState.store));
61
+ const driver = yield* makeQueryDriver({
62
+ name: calc.manifest.name,
63
+ label: 'AsyncCalc',
64
+ gated: calc.gated,
65
+ inputs: calc.inputs,
66
+ query: cfg.query,
67
+ invalidateBy: cfg.invalidateBy,
68
+ disabled: cfg.disabled,
69
+ coalesce: cfg.coalesce,
70
+ reuse: cfg.reuse,
71
+ extraKey: revision === undefined
72
+ ? undefined
73
+ : {
74
+ read: () => revision.getSnapshot(),
75
+ subscribe: (listener) => revision.subscribe(listener),
76
+ },
77
+ });
78
+ // The internal store is the full union; narrow to the definition's arms.
79
+ return narrowStore(driver.store);
80
+ }));
81
+ if (config.invalidateOn === undefined || revisionState === undefined)
82
+ return driver;
83
+ // The hidden reducer: an ordinary `Reducer` folding every listed event to
84
+ // n + 1 — the revision's sole writer, registered/unregistered with this
85
+ // layer's scope like any user reducer. `Layer.provide` builds the hidden
86
+ // state once and feeds the same store to both the driver and the reducer,
87
+ // while the outer context (user inputs, the `Reducers` registry) passes
88
+ // through untouched.
89
+ const revisionReducer = Reducer.make(`${calc.manifest.name}/invalidateOn`, {
90
+ states: [revisionState],
91
+ events: config.invalidateOn,
92
+ });
93
+ return Layer.merge(driver, Reducer.live(revisionReducer, bumpRevision)).pipe(Layer.provide(State.live(revisionState, revisionZero)));
94
+ }
95
+ //# sourceMappingURL=asyncCalc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asyncCalc.js","sourceRoot":"","sources":["../../src/calc/asyncCalc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/D,OAAO,EAAiB,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACxE,OAAO,EAAiB,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAIN,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,YAAY,EAEZ,SAAS,EACT,eAAe,EACf,cAAc,EACd,YAAY,GACb,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAc,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC1C,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAkB,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAkB,WAAW,EAAE,MAAM,aAAa,CAAA;AAiFzD;;;;GAIG;AACH,M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,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,eAAe,EAAE;QACzE,MAAM,EAAE,CAAC,aAAa,CAAC;QACvB,MAAM,EAAE,MAAM,CAAC,YAAY;KAC5B,CAAC,CAAA;IACF,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC,CAAC,IAAI,CAC1E,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC,CACvD,CAAA;AACH,CAAC"}
@@ -1,81 +1,51 @@
1
- import { type Store } from '../internal/store'
2
-
3
- // The value an `AsyncCalc` holds: a tagged union of the query's lifecycle,
4
- // consumed with `effect`'s `Match` (`Match.value(data).pipe(Match.tag('Success', …))`).
5
- //
6
- // The shape is narrowed by the definition, so you only handle arms that can
7
- // occur: `Idle` exists only for a gateable query (no `alwaysOn`), and `Error`
8
- // exists only when the query declares an `error` schema. There is no separate
9
- // "refreshing" arm — a re-fetch keeps the last `Success`/`Error` and flips its
10
- // `refetching` flag (stale-while-revalidate), so the UI never flashes empty.
11
-
1
+ import { type Store } from '../internal/store';
12
2
  /** A gated query that is currently switched off (only when not `alwaysOn`). */
13
3
  export interface AsyncIdle {
14
- readonly _tag: 'Idle'
4
+ readonly _tag: 'Idle';
15
5
  }
16
-
17
6
  /** The first fetch, before any value exists. */
18
7
  export interface AsyncLoading {
19
- readonly _tag: 'Loading'
8
+ readonly _tag: 'Loading';
20
9
  }
21
-
22
10
  /** A resolved value; `refetching` is true while a background re-fetch runs. */
23
11
  export interface AsyncSuccess<A> {
24
- readonly _tag: 'Success'
25
- readonly value: A
26
- readonly refetching: boolean
12
+ readonly _tag: 'Success';
13
+ readonly value: A;
14
+ readonly refetching: boolean;
27
15
  }
28
-
29
16
  /** A failed query; `refetching` is true while a background re-fetch runs. */
30
17
  export interface AsyncError<E> {
31
- readonly _tag: 'Error'
32
- readonly error: E
33
- readonly refetching: boolean
18
+ readonly _tag: 'Error';
19
+ readonly error: E;
20
+ readonly refetching: boolean;
34
21
  }
35
-
36
22
  /**
37
23
  * The query lifecycle. `Gated` adds the `Idle` arm (a disable-able query); a
38
24
  * non-`never` `E` adds the `Error` arm. Both are decided at `AsyncCalc.make`, so
39
25
  * `yield* MyQuery` is typed to exactly the arms that can occur.
40
26
  */
41
- export type AsyncData<A, E = never, Gated extends boolean = false> =
42
- | (Gated extends true ? AsyncIdle : never)
43
- | AsyncLoading
44
- | AsyncSuccess<A>
45
- | ([E] extends [never] ? never : AsyncError<E>)
46
-
27
+ export type AsyncData<A, E = never, Gated extends boolean = false> = (Gated extends true ? AsyncIdle : never) | AsyncLoading | AsyncSuccess<A> | ([E] extends [never] ? never : AsyncError<E>);
47
28
  /** The full (un-narrowed) union — used internally by the live store. */
48
- export type AnyAsyncData<A, E> = AsyncIdle | AsyncLoading | AsyncSuccess<A> | AsyncError<E>
49
-
50
- const idle: AsyncIdle = { _tag: 'Idle' }
51
- const loading: AsyncLoading = { _tag: 'Loading' }
52
- const success = <A>(value: A, refetching = false): AsyncSuccess<A> => ({
53
- _tag: 'Success',
54
- value,
55
- refetching,
56
- })
57
- const error = <E>(err: E, refetching = false): AsyncError<E> => ({
58
- _tag: 'Error',
59
- error: err,
60
- refetching,
61
- })
62
-
29
+ export type AnyAsyncData<A, E> = AsyncIdle | AsyncLoading | AsyncSuccess<A> | AsyncError<E>;
30
+ /** The arm-constructor namespace exposed as `AsyncData`. */
31
+ export interface AsyncDataConstructors {
32
+ readonly idle: AsyncIdle;
33
+ readonly loading: AsyncLoading;
34
+ readonly success: <A>(value: A, refetching?: boolean) => AsyncSuccess<A>;
35
+ readonly error: <E>(err: E, refetching?: boolean) => AsyncError<E>;
36
+ }
63
37
  /**
64
38
  * Constructors for the arms, namespaced under the same name as the type so call
65
39
  * sites read `AsyncData.success(v)` / `AsyncData.error(e)` — no `error` import
66
40
  * shadowing the keyword and one obvious home for every arm.
67
41
  */
68
- export const AsyncData = { idle, loading, success, error } as const
69
-
42
+ export declare const AsyncData: AsyncDataConstructors;
70
43
  /**
71
44
  * Narrow the live store (which holds the full `AnyAsyncData` union) to the arms
72
45
  * the definition actually permits (`Gated`/`E`). The single documented home for
73
46
  * that narrowing, so `AsyncCalc.live` returns it without an inline cast.
74
47
  */
75
- export const narrowStore = <A, E, Gated extends boolean>(
76
- store: Store<AnyAsyncData<A, E>>,
77
- ): Store<AsyncData<A, E, Gated>> => store as unknown as Store<AsyncData<A, E, Gated>>
78
-
48
+ export declare const narrowStore: <A, E, Gated extends boolean>(store: Store<AnyAsyncData<A, E>>) => Store<AsyncData<A, E, Gated>>;
79
49
  /**
80
50
  * The read-only inverse of `narrowStore`: widen a definition-narrowed store back
81
51
  * to the full union, so a consumer (the `RemoteState` overlay) can dispatch on the
@@ -83,6 +53,5 @@ export const narrowStore = <A, E, Gated extends boolean>(
83
53
  * Sound for reads only — every narrowed value IS an `AnyAsyncData` — so callers
84
54
  * must never `set` through the widened view (derived stores ignore `set` anyway).
85
55
  */
86
- export const widenStore = <A, E, Gated extends boolean>(
87
- store: Store<AsyncData<A, E, Gated>>,
88
- ): Store<AnyAsyncData<A, E>> => store as unknown as Store<AnyAsyncData<A, E>>
56
+ export declare const widenStore: <A, E, Gated extends boolean>(store: Store<AsyncData<A, E, Gated>>) => Store<AnyAsyncData<A, E>>;
57
+ //# sourceMappingURL=asyncData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asyncData.d.ts","sourceRoot":"","sources":["../../src/calc/asyncData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAW9C,+EAA+E;AAC/E,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACtB;AAED,gDAAgD;AAChD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CACzB;AAED,+EA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AC,CAAA;CACnE;AAED;;;;GAIG;AACH,eAAO,MAAM,SAAS,EAAE,qBAAyD,CAAA;AAEjF;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,CAAC,EAAE,KAAK,SAAS,OAAO,EACrD,OAAO,KAAK,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAC/B,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAsD,CAAA;AAErF;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,EAAE,CAAC,EAAE,KAAK,SAAS,OAAO,EACpD,OAAO,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,KACnC,KAAK,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAkD,CAAA"}
@@ -0,0 +1,34 @@
1
+ import {} from '../internal/store';
2
+ const idle = { _tag: 'Idle' };
3
+ const loading = { _tag: 'Loading' };
4
+ const success = (value, refetching = false) => ({
5
+ _tag: 'Success',
6
+ value,
7
+ refetching,
8
+ });
9
+ const error = (err, refetching = false) => ({
10
+ _tag: 'Error',
11
+ error: err,
12
+ refetching,
13
+ });
14
+ /**
15
+ * Constructors for the arms, namespaced under the same name as the type so call
16
+ * sites read `AsyncData.success(v)` / `AsyncData.error(e)` — no `error` import
17
+ * shadowing the keyword and one obvious home for every arm.
18
+ */
19
+ export const AsyncData = { idle, loading, success, error };
20
+ /**
21
+ * Narrow the live store (which holds the full `AnyAsyncData` union) to the arms
22
+ * the definition actually permits (`Gated`/`E`). The single documented home for
23
+ * that narrowing, so `AsyncCalc.live` returns it without an inline cast.
24
+ */
25
+ export const narrowStore = (store) => store;
26
+ /**
27
+ * The read-only inverse of `narrowStore`: widen a definition-narrowed store back
28
+ * to the full union, so a consumer (the `RemoteState` overlay) can dispatch on the
29
+ * lifecycle arms without carrying the definition's `Gated`/`E` conditionals.
30
+ * Sound for reads only — every narrowed value IS an `AnyAsyncData` — so callers
31
+ * must never `set` through the widened view (derived stores ignore `set` anyway).
32
+ */
33
+ export const widenStore = (store) => store;
34
+ //# sourceMappingURL=asyncData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asyncData.js","sourceRoot":"","sources":["../../src/calc/asyncData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,mBAAmB,CAAA;AAiD9C,MAAM,IAAI,GAAc,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;AACxC,MAAM,OAAO,GAAiB,EAAE,IAAI,EAAE,SAAS,EAAE,CAAA;AACjD,MAAM,OAAO,GAAG,CAAI,KAAQ,EAAE,UAAU,GAAG,KAAK,EAAmB,EAAE,CAAC,CAAC;IACrE,IAAI,EAAE,SAAS;IACf,KAAK;IACL,UAAU;CACX,CAAC,CAAA;AACF,MAAM,KAAK,GAAG,CAAI,GAAM,EAAE,UAAU,GAAG,KAAK,EAAiB,EAAE,CAAC,CAAC;IAC/D,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,GAAG;IACV,UAAU;CACX,CAAC,CAAA;AAUF;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAA0B,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;AAEjF;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,KAAgC,EACD,EAAE,CAAC,KAAiD,CAAA;AAErF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,KAAoC,EACT,EAAE,CAAC,KAA6C,CAAA"}
@@ -0,0 +1,57 @@
1
+ import { Context, Effect, Layer, type Schema } from 'effect';
2
+ import { type Manifest } from '../definition/definition';
3
+ import { type InputsObject, type InputStores, type InvalidateBy } from '../internal/sources';
4
+ import { type Store } from '../internal/store';
5
+ import { type AnySource } from '../state/token';
6
+ export { type InputsObject, type InputStores, type InvalidateBy } from '../internal/sources';
7
+ export interface CalcOptions<Inputs extends ReadonlyArray<AnySource>> {
8
+ /**
9
+ * Custom invalidation: recompute only when the projected key changes by value
10
+ * equality (React-Query's `queryKey`). Omitted ⇒ recompute when any input
11
+ * value changes. Shared with `AsyncCalc`.
12
+ */
13
+ readonly invalidateBy?: InvalidateBy<Inputs>;
14
+ /**
15
+ * Structural sharing: reconcile each recomputed output against the previous
16
+ * one, substituting previous nodes wherever value equality holds — so
17
+ * identities only move where values moved and downstream memo boundaries
18
+ * (React subtrees) skip unchanged regions. Referentially transparent (the
19
+ * result is value-equal to the fresh output); costs one O(output) walk per
20
+ * recompute, so opt in for large projections.
21
+ */
22
+ readonly reuse?: boolean;
23
+ }
24
+ export interface CalcManifest<N extends string, Out> extends Manifest {
25
+ readonly kind: 'Calc';
26
+ readonly name: N;
27
+ readonly output: Schema.Schema<Out, any>;
28
+ }
29
+ export interface CalcClass<out N extends string, out Inputs extends ReadonlyArray<AnySource>, in out Out> extends Effect.Effect<Out, never, Store<Out>> {
30
+ new (): {};
31
+ readonly manifest: CalcManifest<N, Out>;
32
+ readonly store: Context.Tag<Store<Out>, Store<Out>>;
33
+ /** The calc's name, so it doubles as a `Source` input to another calc. */
34
+ readonly name: N;
35
+ /** Marker data read by `Calc.live`. */
36
+ readonly inputs: Inputs;
37
+ }
38
+ export interface CalcConfig<Inputs extends ReadonlyArray<AnySource>, Out> {
39
+ readonly inputs: Inputs;
40
+ readonly output: Schema.Schema<Out, any>;
41
+ }
42
+ /**
43
+ * A derived, memoized value over explicit inputs (state members, other calcs, or
44
+ * async calcs). The *definition* fixes the inputs and the output schema; the
45
+ * *implementation* is the pure projection. Recomputes only when an input changes;
46
+ * `yield* Calc` reads the memoized value.
47
+ */
48
+ export declare const make: <const N extends string, const Inputs extends ReadonlyArray<AnySource>, Out>(name: N, config: CalcConfig<Inputs, Out>) => CalcClass<N, Inputs, Out>;
49
+ /**
50
+ * Wire the pure projection for a calc. Recomputes only when its invalidation key
51
+ * changes (by default every input value; override with `invalidateBy`), memoized
52
+ * on that key; `yield* Calc` reads the memoized value. The derived store reuses
53
+ * the shared coalescing scheduler, so a recompute that yields an equal value
54
+ * wakes no subscriber.
55
+ */
56
+ export declare const live: <N extends string, Inputs extends ReadonlyArray<AnySource>, Out>(calc: CalcClass<N, Inputs, Out>, compute: (inputs: InputsObject<Inputs>) => Out, options?: CalcOptions<Inputs>) => Layer.Layer<Store<Out>, never, InputStores<Inputs>>;
57
+ //# sourceMappingURL=calc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calc.d.ts","sourceRoot":"","sources":["../../src/calc/calc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAc,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAA;AACxE,OAAO,EAAE,KAAK,QAAQ,EAAkB,MAAM,0BAA0B,CAAA;AACxE,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,YAAY,EAGlB,MAAM,qBAAqB,CAAA;AAG5B,OAAO,EAAoB,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAEhE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAI/C,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAE5F,MAAM,WAAW,WAAW,CAAC,MAAM,SAAS,aAAa,CAAC,SAAS,CAAC;IAClE;;;;OAIG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,CAAA;IAC5C;;;;;;;OAOG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,CAAE,SAAQ,QAAQ;IACnE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IAChB,QAAQ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