@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,65 @@
1
+ import { Brand, Effect, Schema, type Scope } from 'effect';
2
+ import { type AnyAsyncData } from '../calc/asyncData';
3
+ import { type InputsObject, type InputStores, type InvalidateBy } from './sources';
4
+ import { type Store } from './store';
5
+ import { type AnySource } from '../state/token';
6
+ /** `Gated` (whether the `Idle` arm exists) is the inverse of `alwaysOn`. */
7
+ export type GatedOf<AlwaysOn extends boolean> = AlwaysOn extends true ? false : true;
8
+ /** The runtime gated flag for an `alwaysOn` config, typed as its `Gated` literal. */
9
+ export declare const gatedFlag: <AlwaysOn extends boolean>(alwaysOn: AlwaysOn | undefined) => GatedOf<AlwaysOn>;
10
+ export type Revision = number & Brand.Brand<'reform/Revision'>;
11
+ export declare const Revision: Brand.Brand.Constructor<Revision>;
12
+ export declare const RevisionSchema: Schema.Schema<Revision, number>;
13
+ export declare const revisionZero: Revision;
14
+ export declare const bumpRevision: (r: Revision) => Revision;
15
+ export interface QueryDriverOptions<Inputs extends ReadonlyArray<AnySource>, A, E, R> {
16
+ /** The owning definition's name — only for the defect log line. */
17
+ readonly name: string;
18
+ /** The owning primitive's kind label — only for the defect log line. */
19
+ readonly label: string;
20
+ /** Whether `disabled` is honored / the `Idle` arm can occur. */
21
+ readonly gated: boolean;
22
+ readonly inputs: Inputs;
23
+ readonly query: (inputs: InputsObject<Inputs>) => Effect.Effect<A, E, R>;
24
+ readonly invalidateBy?: InvalidateBy<Inputs> | undefined;
25
+ readonly disabled?: ((inputs: InputsObject<Inputs>) => boolean) | undefined;
26
+ readonly coalesce?: 'switch' | 'trailing' | undefined;
27
+ readonly reuse?: boolean | undefined;
28
+ /**
29
+ * An extra key segment + wake source beyond the declared inputs — the hidden
30
+ * `invalidateOn` revision. Kept out of `wireSources` so the user's `query`
31
+ * and `invalidateBy` see exactly the declared inputs.
32
+ */
33
+ readonly extraKey?: {
34
+ readonly read: () => unknown;
35
+ readonly subscribe: (listener: () => void) => () => void;
36
+ } | undefined;
37
+ /**
38
+ * Fired when a run's `Success` value has landed in the store (same scheduler
39
+ * flush — never before the converged value is readable), with the run's
40
+ * generation. Not fired on `Error`, interrupt, or while disabled. The seam
41
+ * `RemoteState` settles pending intents through.
42
+ */
43
+ readonly onSettled?: ((generation: number) => void) | undefined;
44
+ }
45
+ export interface QueryDriver<A, E> {
46
+ /** The lifecycle store (the full union — callers narrow to their arms). */
47
+ readonly store: Store<AnyAsyncData<A, E>>;
48
+ /**
49
+ * The highest generation requested so far (0 before the first kick).
50
+ * Generations are assigned when a run is REQUESTED (enqueued), so a waiter
51
+ * registered as `requested() + 1` is satisfied only by a run that began
52
+ * after registration — the settle-ordering rule `RemoteState` builds on.
53
+ */
54
+ readonly requested: () => number;
55
+ }
56
+ /**
57
+ * Build the driver: store + subscription + request queue + run fiber, all owned
58
+ * by the ambient scope (callers run this under `Layer.scoped`). A change to an
59
+ * input re-runs the query latest-wins (a new run cancels the in-flight one; or,
60
+ * with `coalesce: 'trailing'`, lets it finish and runs one trailing refetch);
61
+ * while a re-run is in flight the last `Success`/`Error` is kept with
62
+ * `refetching: true`.
63
+ */
64
+ export declare const makeQueryDriver: <Inputs extends ReadonlyArray<AnySource>, A, E, R>(options: QueryDriverOptions<Inputs, A, E, R>) => Effect.Effect<QueryDriver<A, E>, never, InputStores<Inputs> | R | Scope.Scope>;
65
+ //# sourceMappingURL=queryDriver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryDriver.d.ts","sourceRoot":"","sources":["../../src/internal/queryDriver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAGL,MAAM,EAIN,MAAM,EACN,KAAK,KAAK,EAEX,MAAM,QAAQ,CAAA;AACf,OAAO,EAAE,KAAK,YAAY,EAAa,MAAM,mBAAmB,CAAA;AAGhE,OAAO,EAC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WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CA0I5E,CAAA"}
@@ -0,0 +1,134 @@
1
+ import { Brand, Cause, Chunk, Effect, MutableRef, Option, Queue, Schema, Stream, } from 'effect';
2
+ import { AsyncData } from '../calc/asyncData';
3
+ import { reuse } from './reuse';
4
+ import { resolveScheduler } from './scheduler';
5
+ import { sameKey, wireSources, } from './sources';
6
+ import { makeStore } from './store';
7
+ import {} from '../state/token';
8
+ /** The runtime gated flag for an `alwaysOn` config, typed as its `Gated` literal. */
9
+ export const gatedFlag = (alwaysOn) => (alwaysOn !== true);
10
+ export const Revision = Brand.nominal();
11
+ export const RevisionSchema = Schema.Number.pipe(Schema.brand('reform/Revision'));
12
+ export const revisionZero = Revision(0);
13
+ export const bumpRevision = (r) => Revision(r + 1);
14
+ /**
15
+ * Build the driver: store + subscription + request queue + run fiber, all owned
16
+ * by the ambient scope (callers run this under `Layer.scoped`). A change to an
17
+ * input re-runs the query latest-wins (a new run cancels the in-flight one; or,
18
+ * with `coalesce: 'trailing'`, lets it finish and runs one trailing refetch);
19
+ * while a re-run is in flight the last `Success`/`Error` is kept with
20
+ * `refetching: true`.
21
+ */
22
+ export const makeQueryDriver = (options) => Effect.gen(function* () {
23
+ const scheduler = yield* resolveScheduler;
24
+ const sources = yield* wireSources(options.inputs, options.invalidateBy);
25
+ const extraKey = options.extraKey;
26
+ const keyOf = (args) => extraKey === undefined ? sources.keyOf(args) : [...sources.keyOf(args), extraKey.read()];
27
+ const subscribeAll = (listener) => {
28
+ const offSources = sources.subscribe(listener);
29
+ const offExtra = extraKey?.subscribe(listener);
30
+ return () => {
31
+ offSources();
32
+ offExtra?.();
33
+ };
34
+ };
35
+ const disabledNow = (args = sources.snapshot()) => options.gated && options.disabled !== undefined ? options.disabled(args) : false;
36
+ const store = makeStore(disabledNow() ? AsyncData.idle : AsyncData.loading, scheduler);
37
+ // The last requested key, so a change that doesn't move it (or only churns
38
+ // an input `invalidateBy` ignores) doesn't re-fetch.
39
+ const lastKey = MutableRef.make(undefined);
40
+ // The run-generation counter: bumped when a run is REQUESTED (enqueued), so
41
+ // `requested()` names the newest run that could possibly be in flight.
42
+ const generation = MutableRef.make(0);
43
+ const nextGeneration = () => {
44
+ MutableRef.update(generation, (n) => n + 1);
45
+ return MutableRef.get(generation);
46
+ };
47
+ // Mark a re-fetch in flight without dropping the visible value (SWR).
48
+ const markRefetching = () => {
49
+ const prev = store.get();
50
+ if (prev._tag === 'Success')
51
+ store.set(AsyncData.success(prev.value, true));
52
+ else if (prev._tag === 'Error')
53
+ store.set(AsyncData.error(prev.error, true));
54
+ else
55
+ store.set(AsyncData.loading);
56
+ };
57
+ // One run of the query, folded into the store. A failure becomes `Error`; an
58
+ // interrupt (latest-wins cancel) leaves the state untouched; a defect (a bug
59
+ // in the body) is logged and isolated — the driver keeps running. A `Success`
60
+ // additionally reports its generation through `onSettled`, after the write,
61
+ // so settle-driven consequences observe the converged value.
62
+ const runQuery = (request) => options.query(request.args).pipe(Effect.tapDefect((defect) => Effect.logError(`reform: ${options.label} '${options.name}' query defect`, defect)), Effect.matchCause({
63
+ onSuccess: (value) => {
64
+ if (!disabledNow()) {
65
+ // `reuse`: share unchanged subtrees with the previous Success
66
+ // value, so a refetch that barely moved keeps identities stable.
67
+ const prev = store.get();
68
+ const shared = options.reuse === true && prev._tag === 'Success'
69
+ ? reuse(prev.value, value)
70
+ : value;
71
+ store.set(AsyncData.success(shared, false));
72
+ options.onSettled?.(request.generation);
73
+ }
74
+ },
75
+ onFailure: (cause) => {
76
+ const failure = Cause.failureOption(cause);
77
+ if (Option.isSome(failure) && !disabledNow()) {
78
+ store.set(AsyncData.error(failure.value, false));
79
+ }
80
+ },
81
+ }));
82
+ // The driver. `'switch'` (default): each new request cancels the in-flight
83
+ // run — the same latest-wins semantics a `latest` channel gives procedures.
84
+ // `'trailing'`: a strictly sequential consumer that, on wake, drains every
85
+ // request that piled up during the flight and runs the LATEST one —
86
+ // "exactly one trailing run after settle" by construction. The trailing
87
+ // run's generation is the max drained (the latest request's), so it
88
+ // vouches for every request it conflated.
89
+ const trailing = options.coalesce === 'trailing';
90
+ const requests = yield* Queue.unbounded();
91
+ yield* Effect.forkScoped(trailing
92
+ ? Effect.forever(Effect.gen(function* () {
93
+ const first = yield* Queue.take(requests);
94
+ const queued = yield* Queue.takeAll(requests);
95
+ const request = Option.getOrElse(Chunk.last(queued), () => first);
96
+ // A disable that landed while the request waited: skip the run.
97
+ if (!disabledNow())
98
+ yield* runQuery(request);
99
+ // The settle may have written a stale-key result with
100
+ // `refetching: false`; if a newer request is already waiting,
101
+ // restore the syncing flag before the next take — both writes
102
+ // coalesce into one scheduler flush for subscribers.
103
+ const pending = yield* Queue.size(requests);
104
+ if (pending > 0 && !disabledNow())
105
+ yield* Effect.sync(markRefetching);
106
+ }))
107
+ : Stream.fromQueue(requests).pipe(Stream.flatMap((request) => Stream.fromEffect(runQuery(request)), { switch: true }), Stream.runDrain));
108
+ const trigger = () => {
109
+ const args = sources.snapshot();
110
+ if (disabledNow(args)) {
111
+ // Switched off: show Idle and forget the key so re-enabling always re-runs.
112
+ MutableRef.set(lastKey, undefined);
113
+ store.set(AsyncData.idle);
114
+ return;
115
+ }
116
+ const key = keyOf(args);
117
+ const previous = MutableRef.get(lastKey);
118
+ if (previous !== undefined && sameKey(key, previous))
119
+ return;
120
+ MutableRef.set(lastKey, key);
121
+ markRefetching();
122
+ Queue.unsafeOffer(requests, { args, generation: nextGeneration() });
123
+ };
124
+ const unsubscribe = subscribeAll(trigger);
125
+ yield* Effect.addFinalizer(() => Effect.sync(unsubscribe));
126
+ // Kick off the first fetch unless the query starts disabled.
127
+ const initial = sources.snapshot();
128
+ if (!disabledNow(initial)) {
129
+ MutableRef.set(lastKey, keyOf(initial));
130
+ Queue.unsafeOffer(requests, { args: initial, generation: nextGeneration() });
131
+ }
132
+ return { store, requested: () => MutableRef.get(generation) };
133
+ });
134
+ //# sourceMappingURL=queryDriver.js.map
@@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C,OAAO,CAAC,CAAA;QACxC,IAAI,QAAQ,KAAK,SAAS,IAAI,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC;YAAE,OAAM;QAC5D,UAAU,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;QAC5B,cAAc,EAAE,CAAA;QAChB,KAAK,CAAC,WAAW,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,EAAE,CAAC,CAAA;IACrE,CAAC,CAAA;IACD,MAAM,WAAW,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;IACzC,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAA;IAE1D,6DAA6D;IAC7D,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAA;IAClC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1B,UAAU,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAA;QACvC,KAAK,CAAC,WAAW,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,EAAE,CAAC,CAAA;IAC9E,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAA;AAC/D,CAAC,CAAC,CAAA"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Substitute `previous` nodes into `next` wherever they are value-equal. The
3
+ * walker only ever returns `previous`, `next`, or a key/index-wise
4
+ * reconstruction of `next` whose every leaf came from one of them, so the
5
+ * result is value-equal to `next` and the type is preserved by construction —
6
+ * the single cast below is that argument, in the style of `wireSources` /
7
+ * `narrowStore`.
8
+ */
9
+ export declare const reuse: <A>(previous: A, next: A) => A;
10
+ //# sourceMappingURL=reuse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reuse.d.ts","sourceRoot":"","sources":["../../src/internal/reuse.ts"],"names":[],"mappings":"AAgEA;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,KAAG,CAAsC,CAAA"}
@@ -0,0 +1,68 @@
1
+ import { Equal } from 'effect';
2
+ // Structural sharing for recomputed calc outputs: reconcile a fresh output
3
+ // against the previous one, substituting previous nodes wherever value equality
4
+ // holds, so identities only move where values moved. Downstream memo boundaries
5
+ // (React subtrees keyed on object identity) then skip everything that didn't
6
+ // change. Referentially transparent: the result is value-equal to `next` — only
7
+ // identities shift toward `previous` — and neither argument is mutated, so the
8
+ // pass composes with the framework's Equal-based invalidation untouched.
9
+ // Bounds the walk; calc outputs are shallow plain data by framework convention.
10
+ const maxDepth = 16;
11
+ const isPlainRecord = (v) => typeof v === 'object' &&
12
+ v !== null &&
13
+ (Object.getPrototypeOf(v) === Object.prototype || Object.getPrototypeOf(v) === null);
14
+ const go = (prev, next, depth) => {
15
+ if (Object.is(prev, next))
16
+ return prev;
17
+ // Data/Schema classes implement Equal+Hash: substitute wholesale on value
18
+ // equality. Plain objects/arrays fall through (their Equal is referential).
19
+ if (Equal.equals(prev, next))
20
+ return prev;
21
+ if (depth <= 0)
22
+ return next;
23
+ if (Array.isArray(prev) && Array.isArray(next)) {
24
+ const out = next.map((item, i) => (i < prev.length ? go(prev[i], item, depth - 1) : item));
25
+ return prev.length === next.length && out.every((v, i) => Object.is(v, prev[i]))
26
+ ? prev
27
+ : out;
28
+ }
29
+ if (isPlainRecord(prev) && isPlainRecord(next)) {
30
+ const keys = Object.keys(next);
31
+ const out = {};
32
+ for (const key of keys)
33
+ out[key] = key in prev ? go(prev[key], next[key], depth - 1) : next[key];
34
+ const allPrev = keys.length === Object.keys(prev).length &&
35
+ keys.every((key) => key in prev && Object.is(out[key], prev[key]));
36
+ return allPrev ? prev : out;
37
+ }
38
+ // Data/Schema class instances that DIFFER still get walked: their Equal is
39
+ // fieldwise over own enumerable fields, so a reconstruction over reconciled
40
+ // fields (same prototype; the constructor is bypassed, but every leaf is a
41
+ // validated value out of `prev` or `next`) stays value-equal to `next` while
42
+ // unchanged children — e.g. one untouched element inside a class-typed
43
+ // container — keep their `prev` identity.
44
+ if (Equal.isEqual(prev) &&
45
+ Equal.isEqual(next) &&
46
+ Object.getPrototypeOf(prev) === Object.getPrototypeOf(next)) {
47
+ const prevFields = Object.fromEntries(Object.entries(prev));
48
+ const nextFields = Object.entries(next);
49
+ const out = {};
50
+ for (const [key, value] of nextFields)
51
+ out[key] = key in prevFields ? go(prevFields[key], value, depth - 1) : value;
52
+ const allPrev = nextFields.length === Object.keys(prevFields).length &&
53
+ nextFields.every(([key]) => key in prevFields && Object.is(out[key], prevFields[key]));
54
+ return allPrev ? prev : Object.assign(Object.create(Object.getPrototypeOf(next)), out);
55
+ }
56
+ // Class instances without Equal (Date, Map, …) are opaque leaves.
57
+ return next;
58
+ };
59
+ /**
60
+ * Substitute `previous` nodes into `next` wherever they are value-equal. The
61
+ * walker only ever returns `previous`, `next`, or a key/index-wise
62
+ * reconstruction of `next` whose every leaf came from one of them, so the
63
+ * result is value-equal to `next` and the type is preserved by construction —
64
+ * the single cast below is that argument, in the style of `wireSources` /
65
+ * `narrowStore`.
66
+ */
67
+ export const reuse = (previous, next) => go(previous, next, maxDepth);
68
+ //# sourceMappingURL=reuse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reuse.js","sourceRoot":"","sources":["../../src/internal/reuse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAE9B,2EAA2E;AAC3E,gFAAgF;AAChF,gFAAgF;AAChF,6EAA6E;AAC7E,gFAAgF;AAChF,+EAA+E;AAC/E,yEAAyE;AAEzE,gFAAgF;AAChF,MAAM,QAAQ,GAAG,EAAE,CAAA;AAEnB,MAAM,aAAa,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,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,UAAU;YACnC,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;QAC9E,MAAM,OAAO,GACX,UAAU,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM;YACpD,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,UAAU,IAAI,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QACxF,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IACxF,CAAC;IACD,kEAAkE;IAClE,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAI,QAAW,EAAE,IAAO,EAAK,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAM,CAAA"}
@@ -0,0 +1,47 @@
1
+ import { Context, Effect, Layer } from 'effect';
2
+ /**
3
+ * Coalesces store notifications into a single microtask flush so a batch of
4
+ * writes wakes each subscriber at most once (RESEARCH #3). React owns frame
5
+ * timing; we only collapse the notifications.
6
+ *
7
+ * One scheduler is shared by every store in a runtime, so writes across
8
+ * different stores in the same tick batch into one flush. The instance is
9
+ * resolved per store at creation: `Notifications` when a runtime provides it
10
+ * (per-runtime isolation — see `resolveScheduler`), else the process-wide
11
+ * `defaultScheduler`.
12
+ */
13
+ export interface Scheduler {
14
+ readonly schedule: (listeners: Iterable<() => void>) => void;
15
+ }
16
+ export declare const makeScheduler: () => Scheduler;
17
+ /**
18
+ * The process-wide scheduler, used by any store created outside a runtime that
19
+ * provides its own `Notifications`. Fine for a single client app (microtask
20
+ * ordering is global anyway); a runtime that needs isolation — concurrent SSR,
21
+ * multiple mounted roots — provides `Notifications` upstream of its stores.
22
+ */
23
+ export declare const defaultScheduler: Scheduler;
24
+ /**
25
+ * Optional per-runtime scheduler. When a runtime provides it upstream of its
26
+ * state/calc layers, those stores coalesce on it instead of the global default,
27
+ * isolating their notification timing from other runtimes in the same process.
28
+ */
29
+ declare const NotificationsBase: Context.TagClass<Notifications, 'reform/Notifications', Scheduler>;
30
+ export declare class Notifications extends NotificationsBase {
31
+ }
32
+ /**
33
+ * A fresh per-runtime scheduler. Merged into `Engine`, so a runtime that wires
34
+ * its state/calc layers *downstream* of `Engine` gets isolated notification
35
+ * timing; the common sibling wiring falls back to `defaultScheduler` (still
36
+ * correct, just process-shared).
37
+ */
38
+ export declare const notificationsLayer: Layer.Layer<Notifications>;
39
+ /**
40
+ * Resolve the scheduler a store should use: the runtime's `Notifications` if one
41
+ * is in context, else the global default. Uses `serviceOption` so it imposes no
42
+ * hard requirement — a store layer wired as a sibling of the runtime (the common
43
+ * pattern) simply falls back to the default.
44
+ */
45
+ export declare const resolveScheduler: Effect.Effect<Scheduler>;
46
+ export {};
47
+ //# sourceMappingURL=scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../src/internal/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAsB,MAAM,QAAQ,CAAA;AAEnE;;;;;;;;;;GAUG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,IAAI,CAAC,KAAK,IAAI,CAAA;CAC7D;AAED,eAAO,MAAM,aAAa,QAAO,SAuChC,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,SAA2B,CAAA;AAE1D;;;;GAIG;AACH,QAAA,MAAM,iBAAiB,EAAE,OAAO,CAAC,QAAQ,CAAC,aAAa,EAAE,sBAAsB,EAAE,SAAS,CACzB,CAAA;AACjE,qBAAa,aAAc,SAAQ,iBAAiB;CAAG;AAEvD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,KAAK,CAAC,aAAa,CAA4C,CAAA;AAEtG;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAGrD,CAAA"}
@@ -0,0 +1,70 @@
1
+ import { Context, Effect, Layer, MutableRef, Option } from 'effect';
2
+ export const makeScheduler = () => {
3
+ const pending = new Set();
4
+ const armed = MutableRef.make(false);
5
+ const flush = () => {
6
+ MutableRef.set(armed, false);
7
+ // Drain to a fixpoint within ONE microtask. A derived store's `onChange`
8
+ // re-schedules during the pass (it is itself a listener of its upstream), so
9
+ // resolving the whole dependency graph here — instead of re-arming a fresh
10
+ // microtask per layer — collapses a depth-N propagation into a single flush
11
+ // and wakes each leaf subscriber once at its final value. Converges because
12
+ // a derived store schedules only when its output actually moves (Equal).
13
+ while (pending.size > 0) {
14
+ const due = [...pending];
15
+ pending.clear();
16
+ for (const listener of due) {
17
+ // One listener's throw (a defect in a user calc body) must not abandon
18
+ // the rest of the flush; surface it to the host's global handler on a
19
+ // fresh microtask instead of unwinding this loop.
20
+ try {
21
+ listener();
22
+ }
23
+ catch (error) {
24
+ queueMicrotask(() => {
25
+ throw error;
26
+ });
27
+ }
28
+ }
29
+ }
30
+ };
31
+ const schedule = (listeners) => {
32
+ for (const listener of listeners)
33
+ pending.add(listener);
34
+ if (pending.size > 0 && !MutableRef.get(armed)) {
35
+ MutableRef.set(armed, true);
36
+ queueMicrotask(flush);
37
+ }
38
+ };
39
+ return { schedule };
40
+ };
41
+ /**
42
+ * The process-wide scheduler, used by any store created outside a runtime that
43
+ * provides its own `Notifications`. Fine for a single client app (microtask
44
+ * ordering is global anyway); a runtime that needs isolation — concurrent SSR,
45
+ * multiple mounted roots — provides `Notifications` upstream of its stores.
46
+ */
47
+ export const defaultScheduler = makeScheduler();
48
+ /**
49
+ * Optional per-runtime scheduler. When a runtime provides it upstream of its
50
+ * state/calc layers, those stores coalesce on it instead of the global default,
51
+ * isolating their notification timing from other runtimes in the same process.
52
+ */
53
+ const NotificationsBase = Context.Tag('reform/Notifications')();
54
+ export class Notifications extends NotificationsBase {
55
+ }
56
+ /**
57
+ * A fresh per-runtime scheduler. Merged into `Engine`, so a runtime that wires
58
+ * its state/calc layers *downstream* of `Engine` gets isolated notification
59
+ * timing; the common sibling wiring falls back to `defaultScheduler` (still
60
+ * correct, just process-shared).
61
+ */
62
+ export const notificationsLayer = Layer.sync(Notifications, makeScheduler);
63
+ /**
64
+ * Resolve the scheduler a store should use: the runtime's `Notifications` if one
65
+ * is in context, else the global default. Uses `serviceOption` so it imposes no
66
+ * hard requirement — a store layer wired as a sibling of the runtime (the common
67
+ * pattern) simply falls back to the default.
68
+ */
69
+ export const resolveScheduler = Effect.map(Effect.serviceOption(Notifications), Option.getOrElse(() => defaultScheduler));
70
+ //# sourceMappingURL=scheduler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../src/internal/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAiBnE,MAAM,CAAC,MAAM,aAAa,GAAG,GAAc,EAAE;IAC3C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAc,CAAA;IACrC,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAEpC,MAAM,KAAK,GAAG,GAA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AAQ,iBAAiB;CAAG;AAEvD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAA+B,KAAK,CAAC,IAAI,CAAC,aAAa,EAAE,aAAa,CAAC,CAAA;AAEtG;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAA6B,MAAM,CAAC,GAAG,CAClE,MAAM,CAAC,aAAa,CAAC,aAAa,CAAC,EACnC,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,CACzC,CAAA"}
@@ -1,5 +1,4 @@
1
- import { FiberRef, GlobalValue } from 'effect'
2
-
1
+ import { FiberRef } from 'effect';
3
2
  /**
4
3
  * The sanctioned tooling/test seam for seeding CLOSED scenes. A scene's layers
5
4
  * are pre-composed (each state group seeds its own live store), so an outer
@@ -14,7 +13,5 @@ import { FiberRef, GlobalValue } from 'effect'
14
13
  * keeps a single ref instance even if the module is loaded twice (duplicated
15
14
  * bundles, HMR), so the writer and the reader always agree.
16
15
  */
17
- export const CurrentSeedOverrides: FiberRef.FiberRef<Readonly<Record<string, unknown>>> =
18
- GlobalValue.globalValue(Symbol.for('reform/CurrentSeedOverrides'), () =>
19
- FiberRef.unsafeMake<Readonly<Record<string, unknown>>>({}),
20
- )
16
+ export declare const CurrentSeedOverrides: FiberRef.FiberRef<Readonly<Record<string, unknown>>>;
17
+ //# sourceMappingURL=seeds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seeds.d.ts","sourceRoot":"","sources":["../../src/internal/seeds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAe,MAAM,QAAQ,CAAA;AAE9C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAGnF,CAAA"}
@@ -0,0 +1,17 @@
1
+ import { FiberRef, GlobalValue } from 'effect';
2
+ /**
3
+ * The sanctioned tooling/test seam for seeding CLOSED scenes. A scene's layers
4
+ * are pre-composed (each state group seeds its own live store), so an outer
5
+ * layer cannot override an inner store — but a FiberRef set via
6
+ * `Layer.locally(ref, value)(layer)` IS visible inside the construction effects
7
+ * of nested layers. `State.live` consults this ref at store-construction time:
8
+ * if the state's member name is present, the (schema-validated) value replaces
9
+ * the authored seed; otherwise the authored seed wins.
10
+ *
11
+ * Empty by default — production wiring never touches it. The dev-tool inspector
12
+ * (`Scene.seedScene`) and proofs are the only intended writers. `globalValue`
13
+ * keeps a single ref instance even if the module is loaded twice (duplicated
14
+ * bundles, HMR), so the writer and the reader always agree.
15
+ */
16
+ export const CurrentSeedOverrides = GlobalValue.globalValue(Symbol.for('reform/CurrentSeedOverrides'), () => FiberRef.unsafeMake({}));
17
+ //# sourceMappingURL=seeds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seeds.js","sourceRoot":"","sources":["../../src/internal/seeds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAE9C;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAC/B,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,6BAA6B,CAAC,EAAE,GAAG,EAAE,CACtE,QAAQ,CAAC,UAAU,CAAoC,EAAE,CAAC,CAC3D,CAAA"}
@@ -0,0 +1,39 @@
1
+ import { type Context, Effect } from 'effect';
2
+ import { type AnySource, type SourceName, type SourceValue } from '../state/token';
3
+ /** The decoded inputs handed to a calc body, keyed by each source's name. */
4
+ export type InputsObject<Inputs extends ReadonlyArray<AnySource>> = {
5
+ readonly [S in Inputs[number] as SourceName<S>]: SourceValue<S>;
6
+ };
7
+ /**
8
+ * The store services a list of store-carriers requires, as a *union of distinct*
9
+ * stores (each carrier has its own backing tag), not a single store of a union.
10
+ * Structural over the `store` tag, so it serves both calc inputs (`Source`s) and
11
+ * state-group members (`StateClass`es) — anything carrying a `store` tag.
12
+ */
13
+ export type StoresOf<Items extends ReadonlyArray<unknown>> = {
14
+ [I in keyof Items]: Items[I] extends {
15
+ readonly store: Context.Tag<infer Svc, any>;
16
+ } ? Svc : never;
17
+ }[number];
18
+ /** The store requirement a calc's inputs impose. */
19
+ export type InputStores<Inputs extends ReadonlyArray<AnySource>> = StoresOf<Inputs>;
20
+ /** Project inputs into a comparable key; the calc reacts only when it moves. */
21
+ export type InvalidateBy<Inputs extends ReadonlyArray<AnySource>> = (inputs: InputsObject<Inputs>) => ReadonlyArray<unknown>;
22
+ /** Element-wise value equality of two invalidation keys. */
23
+ export declare const sameKey: (a: ReadonlyArray<unknown>, b: ReadonlyArray<unknown>) => boolean;
24
+ /** The sensing surface both `Calc.live` and `AsyncCalc.live` build on. */
25
+ export interface WiredSources<Inputs extends ReadonlyArray<AnySource>> {
26
+ /** Snapshot every input by name — the decoded inputs object a calc body sees. */
27
+ readonly snapshot: () => InputsObject<Inputs>;
28
+ /** The invalidation key for an inputs object: the projection, or all input values. */
29
+ readonly keyOf: (inputs: InputsObject<Inputs>) => ReadonlyArray<unknown>;
30
+ /** Subscribe to every source at once; the returned thunk unsubscribes from all. */
31
+ readonly subscribe: (listener: () => void) => () => void;
32
+ }
33
+ /**
34
+ * Read each input's backing store and return the shared sensing surface. The
35
+ * caller owns lifecycle: register the `subscribe` result's unsubscribe as a
36
+ * scope finalizer (both live bodies run under `Layer.scoped`).
37
+ */
38
+ export declare const wireSources: <Inputs extends ReadonlyArray<AnySource>>(inputs: Inputs, invalidateBy?: InvalidateBy<Inputs>) => Effect.Effect<WiredSources<Inputs>, never, InputStores<Inputs>>;
39
+ //# sourceMappingURL=sources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sources.d.ts","sourceRoot":"","sources":["../../src/internal/sources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,EAAoB,MAAM,QAAQ,CAAA;AAC/D,OAAO,EAAE,K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AAM,EAAE,YAAY,CAAC,MAAM,CAAC,KAAK,aAAa,CAAC,OAAO,CAAC,CAAA;IACxE,mFAAmF;IACnF,QAAQ,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAA;CACzD;AAED;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,SAAS,aAAa,CAAC,SAAS,CAAC,EACjE,QAAQ,MAAM,EACd,eAAe,YAAY,CAAC,MAAM,CAAC,KAClC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CA4BM,CAAA"}
@@ -0,0 +1,59 @@
1
+ import { Effect, Equal, Predicate } from 'effect';
2
+ import {} from '../state/token';
3
+ import {} from './store';
4
+ /**
5
+ * The runtime key an input contributes to the inputs object. Prefer the
6
+ * explicit `manifest.name` — the string handed to `make` — over the structural
7
+ * `name`: a `Calc`/`AsyncCalc` *class* satisfies `Source` through its static
8
+ * `name`, and a user subclass declaration (`class Feed extends Calc.make(…)`)
9
+ * defines its OWN `name` from the class binding, shadowing the explicit one.
10
+ * That binding is what minifiers rename, so keying the snapshot by `input.name`
11
+ * made every subclassed calc input `undefined` in production builds (and would
12
+ * silently mis-key in dev whenever the binding differs from the `make` name —
13
+ * the type-level key, `SourceName<S>`, is always the `make` string). The
14
+ * manifest is inherited through the static prototype chain and never shadowed.
15
+ * `StateToken`s carry no manifest; their `name` is an instance field holding
16
+ * the explicit member key, so the fallback is always the declared string.
17
+ */
18
+ const inputKey = (input) => Predicate.hasProperty(input, 'manifest') &&
19
+ Predicate.isRecord(input.manifest) &&
20
+ Predicate.isString(input.manifest['name'])
21
+ ? input.manifest['name']
22
+ : input.name;
23
+ /** Element-wise value equality of two invalidation keys. */
24
+ export const sameKey = (a, b) => a.length === b.length && a.every((value, i) => Equal.equals(value, b[i]));
25
+ /**
26
+ * Read each input's backing store and return the shared sensing surface. The
27
+ * caller owns lifecycle: register the `subscribe` result's unsubscribe as a
28
+ * scope finalizer (both live bodies run under `Layer.scoped`).
29
+ */
30
+ export const wireSources = (inputs, invalidateBy) => Effect.gen(function* () {
31
+ const sources = [];
32
+ for (const input of inputs)
33
+ sources.push(yield* input.store);
34
+ const snapshot = () => {
35
+ const args = {};
36
+ inputs.forEach((input, i) => {
37
+ // `noUncheckedIndexedAccess`: `sources` is built 1:1 with `inputs`, but
38
+ // guard the index so the read is honestly total.
39
+ const source = sources[i];
40
+ if (source !== undefined)
41
+ args[inputKey(input)] = source.getSnapshot();
42
+ });
43
+ return args;
44
+ };
45
+ const keyOf = (args) => invalidateBy ? invalidateBy(args) : Object.values(args);
46
+ const subscribe = (listener) => {
47
+ const unsubscribes = sources.map((source) => source.subscribe(listener));
48
+ return () => {
49
+ for (const unsubscribe of unsubscribes)
50
+ unsubscribe();
51
+ };
52
+ };
53
+ return { snapshot, keyOf, subscribe };
54
+ // Yielding each `input.store` (a `Context.Tag<Store<unknown>>`) widens the
55
+ // inferred requirement to `Store<unknown>`; restate the precise per-input
56
+ // `InputStores<Inputs>` union the signature promises. This is the single
57
+ // place that cast lives — `Calc.live`/`AsyncCalc.live` inherit it.
58
+ });
59
+ //# sourceMappingURL=sources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sources.js","sourceRoot":"","sources":["../../src/internal/sources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAC/D,OAAO,EAAqD,MAAM,gBAAgB,CAAA;AAClF,OAAO,EAAc,MAAM,SAAS,CAAA;AA8BpC;;;;;;;;;;;;;GAaG;AACH,MAAM,QAAQ,GAAG,CAAC,KAAgB,EAAU,EAAE,CAC5C,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC;IACxC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC;IAClC,SAAS,CAAC,QAAQ,CAA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CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACzD,MAAM,SAAS,GAAG,CAAC,QAAoB,EAAgB,EAAE;QACvD,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAA;QACxE,OAAO,GAAG,EAAE;YACV,KAAK,MAAM,WAAW,IAAI,YAAY;gBAAE,WAAW,EAAE,CAAA;QACvD,CAAC,CAAA;IACH,CAAC,CAAA;IACD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,CAAA;IACrC,2EAA2E;IAC3E,0EAA0E;IAC1E,yEAAyE;IACzE,mEAAmE;AACrE,CAAC,CAAoE,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const claimStateTag: (identifier: string) => void;
2
+ //# sourceMappingURL=stateRegistry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stateRegistry.d.ts","sourceRoot":"","sources":["../../src/internal/stateRegistry.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,aAAa,GAAI,YAAY,MAAM,KAAG,IAYlD,CAAA"}