@playfast/reform 1.1.1 → 1.2.1

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 (106) hide show
  1. package/README.md +85 -55
  2. package/package.json +17 -17
  3. package/src/boundary/boundary.test.ts +82 -33
  4. package/src/boundary/boundary.ts +141 -32
  5. package/src/calc/asyncCalc.invalidate.test.ts +733 -32
  6. package/src/calc/asyncCalc.test.ts +397 -225
  7. package/src/calc/asyncCalc.ts +115 -100
  8. package/src/calc/asyncCalcTypes.ts +147 -0
  9. package/src/calc/calc.test.ts +13 -16
  10. package/src/calc/calc.ts +44 -18
  11. package/src/calc/calcFamily.test.ts +90 -32
  12. package/src/calc/calcFamily.ts +56 -25
  13. package/src/calc/compose.ts +1 -14
  14. package/src/channel/channel.ts +25 -6
  15. package/src/channel/{procedureRegistry.ts → procedures.ts} +41 -23
  16. package/src/compose/composition.test.ts +19 -0
  17. package/src/compose/composition.ts +168 -81
  18. package/src/compose/compositionTypes.ts +249 -0
  19. package/src/compose/props.ts +13 -6
  20. package/src/compose/provide.ts +187 -46
  21. package/src/compose/slot.ts +156 -19
  22. package/src/compose/structure.test.ts +6 -3
  23. package/src/compose/structure.ts +106 -13
  24. package/src/compose/ui.test.ts +19 -3
  25. package/src/compose/ui.ts +147 -54
  26. package/src/compose/ui.typecheck.ts +40 -4
  27. package/src/definition/definition.ts +22 -9
  28. package/src/event/event.fromSource.test.ts +172 -0
  29. package/src/event/event.test.ts +10 -0
  30. package/src/event/event.ts +102 -18
  31. package/src/feature/feature.mount.test.ts +123 -56
  32. package/src/feature/feature.test.ts +67 -63
  33. package/src/feature/feature.ts +222 -262
  34. package/src/feature/feature.typecheck.ts +224 -91
  35. package/src/feature/featureBinding.ts +130 -20
  36. package/src/feature/featureClass.ts +162 -0
  37. package/src/feature/featureConfig.ts +192 -0
  38. package/src/feature/featureFactory.ts +163 -0
  39. package/src/feature/featureModule.ts +136 -0
  40. package/src/feature/featureModule.typecheck.ts +63 -0
  41. package/src/feature/featureNativeTree.ts +152 -0
  42. package/src/feature/featureRequirement.ts +82 -0
  43. package/src/feature/featureVariants.ts +234 -0
  44. package/src/feature/mountFeature.ts +54 -0
  45. package/src/graph/closure.ts +222 -0
  46. package/src/graph/services.ts +95 -0
  47. package/src/graph/summary.ts +134 -0
  48. package/src/index.ts +171 -245
  49. package/src/internal/bucketCache.ts +39 -0
  50. package/src/internal/capture.ts +9 -4
  51. package/src/internal/env.ts +1 -3
  52. package/src/internal/errors.ts +21 -10
  53. package/src/internal/queryDriver.ts +61 -25
  54. package/src/internal/queryDriverHydrate.ts +45 -0
  55. package/src/internal/queryDriverStore.ts +8 -5
  56. package/src/internal/queryDriverTypes.ts +11 -11
  57. package/src/internal/reuse.test.ts +10 -3
  58. package/src/internal/reuse.ts +5 -2
  59. package/src/internal/scheduler.ts +4 -1
  60. package/src/internal/sources.ts +25 -11
  61. package/src/internal/store.test.ts +27 -6
  62. package/src/internal/track.ts +3 -2
  63. package/src/internal.ts +222 -0
  64. package/src/namespace/namespace.ts +46 -25
  65. package/src/procedure/procedure.ts +38 -11
  66. package/src/reducer/reducer.ts +78 -34
  67. package/src/remote/pendingQueue.ts +145 -0
  68. package/src/remote/remoteState.test.ts +536 -354
  69. package/src/remote/remoteState.ts +145 -106
  70. package/src/remote/remoteState.typecheck.ts +47 -23
  71. package/src/remote/remoteStateMake.ts +97 -0
  72. package/src/remote/remoteStateSend.ts +95 -37
  73. package/src/remote/remoteStateTypes.ts +155 -0
  74. package/src/runtime/appRuntime.activation.test.ts +104 -0
  75. package/src/runtime/appRuntime.test.ts +187 -111
  76. package/src/runtime/appRuntime.ts +36 -130
  77. package/src/runtime/capturedAppRuntime.ts +274 -0
  78. package/src/runtime/eventBudget.test.ts +39 -12
  79. package/src/runtime/eventBudget.ts +9 -8
  80. package/src/runtime/featureMount.ts +94 -0
  81. package/src/runtime/hardening.test.ts +22 -13
  82. package/src/runtime/instrumentation.test.ts +213 -194
  83. package/src/runtime/instrumentation.ts +6 -11
  84. package/src/runtime/loop.test.ts +84 -7
  85. package/src/runtime/loop.ts +69 -40
  86. package/src/runtime/runtimeHandle.ts +124 -0
  87. package/src/scene/featureScene.test.ts +4 -2
  88. package/src/scene/scene.ts +234 -64
  89. package/src/scene/seedScene.test.ts +69 -86
  90. package/src/state/state.nominal.typecheck.ts +68 -0
  91. package/src/state/state.test.ts +17 -0
  92. package/src/state/state.ts +79 -26
  93. package/src/state/stateFamily.test.ts +39 -8
  94. package/src/state/stateFamily.ts +55 -22
  95. package/src/state/stateGroup.ts +53 -17
  96. package/src/state/token.ts +40 -10
  97. package/src/synced/syncedStore.ts +46 -23
  98. package/src/testkit/flight.testkit.ts +84 -0
  99. package/src/wire/tree.test.ts +8 -4
  100. package/src/wire/triggers.test.ts +6 -2
  101. package/src/wire/triggers.ts +14 -10
  102. package/src/calc/asyncCalcDefinitions.ts +0 -48
  103. package/src/internal/ctx.ts +0 -9
  104. package/src/remote/remoteStateDefinition.ts +0 -135
  105. package/src/remote/remoteStateLayers.ts +0 -118
  106. package/src/remote/remoteStateLiveTypes.ts +0 -59
@@ -1,105 +1,192 @@
1
- import { Context, Effect, Layer, type Schema } from 'effect'
1
+ import { Context, Effect, GlobalValue, Layer, MutableRef, Option, Schema } from 'effect'
2
2
  import type { YieldWrap } from 'effect/Utils'
3
- import { type Manifest, definitionClass } from '../definition/definition'
4
- import { type Ctx } from '../internal/ctx'
5
- import type { Tracker } from '../internal/track'
3
+ import { definitionClass } from '../definition/definition'
6
4
  import { CurrentTracker } from '../internal/track'
7
- import type { SlotClass } from './slot'
8
- import type { Structure } from './structure'
9
- import type { UiClass, UiContract } from './ui'
10
- import { Props } from './props'
11
- import type { AnyValue } from '../internal/variance'
5
+ import { propsTag } from './props'
6
+ import type { UiContract } from './ui'
7
+ import type {
8
+ CompositionActivation,
9
+ CompositionActivationLayerInput,
10
+ CompositionCapture,
11
+ CompositionClass,
12
+ CompositionConfig,
13
+ CompositionDefinitionStatics,
14
+ CompositionId,
15
+ CompositionLayerInput,
16
+ CompositionManifest,
17
+ CompositionService,
18
+ ContextFreeProps,
19
+ ContractSlots,
20
+ EncodedPropsOf,
21
+ Frame,
22
+ GeneratorContext,
23
+ PropsOf,
24
+ RenderEnv,
25
+ RequiredSlotIdentities,
26
+ ScopedCompositionLiveConfig,
27
+ StatesOf,
28
+ UiCarrier,
29
+ } from './compositionTypes'
12
30
 
13
- export type Frame<C extends UiContract = UiContract> = Structure<C>
31
+ export { CompositionIdTypeId } from './compositionTypes'
32
+ export type {
33
+ AnyComposition,
34
+ CompositionActivation,
35
+ CompositionCapture,
36
+ CompositionClass,
37
+ CompositionConfig,
38
+ CompositionId,
39
+ CompositionInstance,
40
+ CompositionManifest,
41
+ CompositionPropsReceiver,
42
+ CompositionReflection,
43
+ CompositionService,
44
+ CompositionTag,
45
+ Frame,
46
+ HasExactCompositionId,
47
+ RenderEnv,
48
+ RequiredSlotIdentities,
49
+ ScopedCompositionLiveConfig,
50
+ SlotClassesOf,
51
+ } from './compositionTypes'
14
52
 
15
- export interface RenderEnv {
16
- readonly props: unknown
17
- readonly tracker: Tracker
18
- }
19
-
20
- export interface CompositionService {
21
- readonly render: (env: RenderEnv) => Effect.Effect<Frame, never, never>
22
- }
23
-
24
- // Optional fields drive Config extends { props/states: … } inference — cannot be Option
25
- export interface CompositionConfig {
26
- readonly title: string
27
- // oxlint-disable-next-line reform-rules/no-optional-fields -- optional config field on a reflectable manifest carrier (see note above)
28
- readonly description?: string
29
- // Schema variance needs any in encoded/context; only decoded P is used
30
- // oxlint-disable-next-line reform-rules/no-optional-fields -- drives `Config extends { props: … }` inference (PropsOf)
31
- readonly props?: Schema.Schema.AnyNoContext
32
- // oxlint-disable-next-line reform-rules/no-optional-fields -- drives `Config extends { states: … }` inference (StatesOf)
33
- readonly states?: ReadonlyArray<unknown>
34
- // oxlint-disable-next-line reform-rules/no-optional-fields -- optional config field on a reflectable manifest carrier (see note above)
35
- readonly calcs?: ReadonlyArray<unknown>
36
- // oxlint-disable-next-line reform-rules/no-optional-fields -- optional config field on a reflectable manifest carrier (see note above)
37
- readonly events?: ReadonlyArray<unknown>
38
- // oxlint-disable-next-line reform-rules/no-optional-fields -- optional config field on a reflectable manifest carrier (see note above)
39
- readonly slots?: Record<string, SlotClass>
40
- // Manifest carrier only — full UiClass's invariant impl tag would leak C
41
- readonly ui: { readonly manifest: Manifest & { readonly kind: 'Ui' } }
42
- }
43
-
44
- type PropsOf<Config> = Config extends { props: Schema.Schema<infer P, AnyValue> } ? P : unknown
45
53
 
46
- type StatesOf<Config> = Config extends { states: infer S extends ReadonlyArray<unknown> }
47
- ? S
48
- : readonly []
54
+ const compositionDefinitionSequence: MutableRef.MutableRef<number> = GlobalValue.globalValue(
55
+ Symbol.for('reform/CompositionDefinitionSequence'),
56
+ () => MutableRef.make(0),
57
+ )
49
58
 
50
- export interface CompositionClass<
51
- out P,
52
- out C extends UiContract = UiContract,
53
- out S extends ReadonlyArray<unknown> = ReadonlyArray<unknown>,
54
- > {
55
- new (): {}
56
- readonly manifest: Manifest & { readonly kind: 'Composition' } & CompositionConfig
57
- readonly Props: P
58
- readonly Contract: C
59
- readonly States: S
60
- readonly tag: Context.Tag<CompositionService, CompositionService>
61
- }
59
+ const nextCompositionTagKey = (name: string): string =>
60
+ `reform/composition/${name}/${MutableRef.incrementAndGet(compositionDefinitionSequence)}`
62
61
 
63
- interface UiCarrier<C extends UiContract> {
64
- readonly ui: UiClass<C>
65
- }
62
+ export const make =
63
+ <
64
+ const N extends string,
65
+ const Config extends CompositionConfig,
66
+ C extends UiContract,
67
+ const UiName extends string,
68
+ >(
69
+ name: N,
70
+ config: Config & UiCarrier<C, UiName> & ContractSlots<C> & ContextFreeProps<Config>,
71
+ ) =>
72
+ <Self>(): CompositionClass<PropsOf<Config>, C, StatesOf<Config>, N, Self> => {
73
+ const identity = Symbol(name)
74
+ const props = propsTag<PropsOf<Config>>()
75
+ const propsSchema = Schema.make<PropsOf<Config>, EncodedPropsOf<Config>>(
76
+ config.props?.ast ?? Schema.Unknown.ast,
77
+ )
78
+ const parseProps: (input: unknown) => Option.Option<PropsOf<Config>> =
79
+ Schema.decodeUnknownOption(propsSchema)
80
+ const tag = Context.GenericTag<
81
+ CompositionId<N, Self, RequiredSlotIdentities<C>>,
82
+ CompositionService<PropsOf<Config>, C>
83
+ >(nextCompositionTagKey(name))
84
+ const manifest = {
85
+ kind: 'Composition',
86
+ name,
87
+ ...config,
88
+ } satisfies CompositionManifest<C, N>
89
+ const composition = definitionClass<
90
+ CompositionClass<PropsOf<Config>, C, StatesOf<Config>, N, Self>
91
+ >({
92
+ manifest,
93
+ identity,
94
+ props,
95
+ parseProps,
96
+ acceptsProps: () => undefined,
97
+ tag,
98
+ capture: <Result>(visit: CompositionCapture<Result>): Result => visit(composition),
99
+ } satisfies CompositionDefinitionStatics<PropsOf<Config>, C, StatesOf<Config>, N, Self>)
100
+ return composition
101
+ }
66
102
 
67
- export const make = <const Config extends CompositionConfig, C extends UiContract>(
68
- name: string,
69
- // Constrain ui to full UiClass<C> for inference; stored manifest keeps erased carrier
70
- config: Config & UiCarrier<C>,
71
- ): CompositionClass<PropsOf<Config>, C, StatesOf<Config>> => {
72
- const tag = Context.GenericTag<CompositionService, CompositionService>(
73
- `reform/composition/${name}`,
74
- )
75
- const manifest = { kind: 'Composition' as const, name, ...config }
76
- return definitionClass<CompositionClass<PropsOf<Config>, C, StatesOf<Config>>>({ manifest, tag })
77
- }
78
103
 
79
104
  export const live = <
80
105
  P,
81
106
  C extends UiContract,
107
+ S extends ReadonlyArray<unknown>,
108
+ N extends string,
109
+ Identity,
82
110
  Eff extends YieldWrap<Effect.Effect<unknown, never, unknown>>,
83
111
  >(
84
- composition: CompositionClass<P, C>,
112
+ composition: CompositionClass<P, C, S, N, Identity>,
85
113
  body: () => Generator<Eff, Frame<C>, never>,
86
- ): Layer.Layer<CompositionService, never, Exclude<Ctx<Eff>, Props>> => {
87
- const logic = Effect.gen(body)
114
+ ): Layer.Layer<
115
+ CompositionId<N, Identity, RequiredSlotIdentities<C>>,
116
+ never,
117
+ CompositionLayerInput<Eff>
118
+ > => {
119
+ const logic: Effect.Effect<Frame<C>, never, GeneratorContext<Eff>> = Effect.gen(body).pipe(
120
+ Effect.orDie,
121
+ )
88
122
  return Layer.effect(
89
123
  composition.tag,
90
124
  Effect.gen(function* () {
91
- const context = yield* Effect.context<Exclude<Ctx<Eff>, Props>>()
92
- const render = (env: RenderEnv): Effect.Effect<Frame, never, never> =>
93
- // oxlint-disable-next-line reform-rules/no-type-assertion -- the one documented render-boundary erasure: a fully-provided generic body's Structure<C> narrowed back to the contract-agnostic Frame service type
94
- logic.pipe(
95
- Effect.provideService(Props, env.props),
125
+ const context = yield* Effect.context<CompositionLayerInput<Eff>>()
126
+ const render = (env: RenderEnv<P>): Effect.Effect<Frame<C>, never, never> => {
127
+ return logic.pipe(
128
+ Effect.provideService(composition.props, env.props),
96
129
  Effect.provideService(CurrentTracker, env.tracker),
97
130
  Effect.provide(context),
98
- ) as unknown as Effect.Effect<Frame, never, never>
99
- return { render }
131
+ )
132
+ }
133
+ return { render, activation: () => Option.none() }
134
+ }),
135
+ )
136
+ }
137
+
138
+ export const liveScoped = <
139
+ P,
140
+ C extends UiContract,
141
+ S extends ReadonlyArray<unknown>,
142
+ N extends string,
143
+ Identity,
144
+ RenderEff extends YieldWrap<Effect.Effect<unknown, never, unknown>>,
145
+ ActivationEff extends YieldWrap<Effect.Effect<unknown, never, unknown>>,
146
+ >(
147
+ composition: CompositionClass<P, C, S, N, Identity>,
148
+ config: ScopedCompositionLiveConfig<C, RenderEff, ActivationEff>,
149
+ ): Layer.Layer<
150
+ CompositionId<N, Identity, RequiredSlotIdentities<C>>,
151
+ never,
152
+ CompositionLayerInput<RenderEff> | CompositionActivationLayerInput<ActivationEff>
153
+ > => {
154
+ const renderLogic: Effect.Effect<Frame<C>, never, GeneratorContext<RenderEff>> = Effect.gen(
155
+ config.render,
156
+ ).pipe(Effect.orDie)
157
+ const activationLogic: Effect.Effect<void, never, GeneratorContext<ActivationEff>> = Effect.gen(
158
+ config.activate,
159
+ ).pipe(Effect.orDie)
160
+
161
+ return Layer.effect(
162
+ composition.tag,
163
+ Effect.gen(function* () {
164
+ const renderContext = yield* Effect.context<CompositionLayerInput<RenderEff>>()
165
+ const activationContext =
166
+ yield* Effect.context<CompositionActivationLayerInput<ActivationEff>>()
167
+ const render = (env: RenderEnv<P>): Effect.Effect<Frame<C>, never, never> =>
168
+ renderLogic.pipe(
169
+ Effect.provideService(composition.props, env.props),
170
+ Effect.provideService(CurrentTracker, env.tracker),
171
+ Effect.provide(renderContext),
172
+ )
173
+ const activation = (props: P): Option.Option<CompositionActivation> => {
174
+ const scoped = Layer.scopedDiscard(
175
+ activationLogic.pipe(Effect.provideService(composition.props, props)),
176
+ )
177
+ return Option.some(scoped.pipe(Layer.provide(Layer.succeedContext(activationContext))))
178
+ }
179
+ return { render, activation }
100
180
  }),
101
181
  )
102
182
  }
103
183
 
104
- export const render = (service: CompositionService, env: RenderEnv): Effect.Effect<Frame, never, never> =>
105
- service.render(env)
184
+ export const render = <P, C extends UiContract>(
185
+ service: CompositionService<P, C>,
186
+ env: RenderEnv<P>,
187
+ ): Effect.Effect<Frame<C>, never, never> => service.render(env)
188
+
189
+ export const activation = <P, C extends UiContract>(
190
+ service: CompositionService<P, C>,
191
+ props: P,
192
+ ): Option.Option<CompositionActivation> => service.activation(props)
@@ -0,0 +1,249 @@
1
+ import type { Context, Effect, Layer, Option, Schema, Scope } from 'effect'
2
+ import type { AST } from 'effect/SchemaAST'
3
+ import type { YieldWrap } from 'effect/Utils'
4
+ import type { Manifest } from '../definition/definition'
5
+ import type { Tracker } from '../internal/track'
6
+ import type { CurrentTracker } from '../internal/track'
7
+ import type { PropsId, PropsTag } from './props'
8
+ import type { AnySlot, AnySlotInstance, SlotClass, SlotInstance } from './slot'
9
+ import type { Structure } from './structure'
10
+ import type { UiClass, UiContract, UiReflection } from './ui'
11
+
12
+ export type Frame<C extends UiContract = UiContract> = Structure<C>
13
+
14
+ export interface RenderEnv<out P = unknown> {
15
+ readonly props: P
16
+ readonly tracker: Tracker
17
+ }
18
+
19
+ export type CompositionActivation = Layer.Layer<never, never, never>
20
+
21
+ export interface CompositionService<in out P = unknown, out C extends UiContract = UiContract> {
22
+ readonly render: (env: RenderEnv<P>) => Effect.Effect<Frame<C>, never, never>
23
+ readonly activation: (props: P) => Option.Option<CompositionActivation>
24
+ }
25
+
26
+ export const CompositionIdTypeId: unique symbol = Symbol.for('reform/CompositionId')
27
+ export type CompositionIdTypeId = typeof CompositionIdTypeId
28
+
29
+ export interface CompositionId<
30
+ out N extends string,
31
+ out Identity = unknown,
32
+ out RequiredSlots = unknown,
33
+ > {
34
+ readonly [CompositionIdTypeId]: {
35
+ readonly name: N
36
+ readonly identity: Identity
37
+ readonly requiredSlots: RequiredSlots
38
+ }
39
+ }
40
+
41
+ export type IsExact<Left, Right> = [Left] extends [Right] ? ([Right] extends [Left] ? true : false) : false
42
+
43
+ export type IsExactCompositionId<Service, N extends string, Identity> = Service extends {
44
+ readonly [CompositionIdTypeId]: {
45
+ readonly name: infer ServiceName extends string
46
+ readonly identity: infer ServiceIdentity
47
+ }
48
+ }
49
+ ? IsExact<ServiceName, N> extends true
50
+ ? IsExact<ServiceIdentity, Identity>
51
+ : false
52
+ : false
53
+
54
+ export type IsAny<T> = 0 extends 1 & T ? true : false
55
+
56
+ export type HasExactCompositionId<Services, N extends string, Identity> =
57
+ IsAny<Services> extends true
58
+ ? false
59
+ : true extends IsExactCompositionId<Services, N, Identity>
60
+ ? true
61
+ : false
62
+
63
+ export type CompositionTag<
64
+ N extends string,
65
+ P,
66
+ C extends UiContract,
67
+ Identity = unknown,
68
+ > = Context.Tag<CompositionId<N, Identity, RequiredSlotIdentities<C>>, CompositionService<P, C>>
69
+
70
+ export type SlotClassesOf<C extends UiContract> = C extends {
71
+ readonly slots: infer Slots extends Record<string, AnySlotInstance>
72
+ }
73
+ ? {
74
+ readonly [K in keyof Slots]: Slots[K] extends SlotInstance<
75
+ infer Child,
76
+ infer SlotName,
77
+ infer SlotIdentity
78
+ >
79
+ ? SlotClass<Child, SlotName, SlotIdentity>
80
+ : never
81
+ }
82
+ : Readonly<Record<PropertyKey, never>>
83
+
84
+ export type RequiredSlotIdentity<Slot> =
85
+ Slot extends SlotInstance<infer _Target, infer _Name, infer Identity> ? Identity : never
86
+
87
+ export type RequiredSlotIdentities<C extends UiContract> = C extends {
88
+ readonly slots: infer Slots extends Record<string, AnySlotInstance>
89
+ }
90
+ ? RequiredSlotIdentity<Slots[keyof Slots]>
91
+ : never
92
+
93
+ export type CompositionSlots<C extends UiContract> = C extends {
94
+ readonly slots: infer Slots extends Record<string, AnySlotInstance>
95
+ }
96
+ ? [Slots[keyof Slots]] extends [never]
97
+ ? {}
98
+ : { readonly slots: SlotClassesOf<C> }
99
+ : {}
100
+
101
+ export type CompositionManifest<
102
+ C extends UiContract = UiContract,
103
+ N extends string = string,
104
+ > = Manifest &
105
+ Omit<CompositionConfig, 'slots' | 'ui'> &
106
+ CompositionSlots<C> & {
107
+ readonly kind: 'Composition'
108
+ readonly name: N
109
+ readonly ui: UiReflection<C>
110
+ }
111
+
112
+ export interface CompositionInstance<out Identity = unknown> {
113
+ readonly _compositionIdentity: Identity
114
+ }
115
+
116
+ export interface CompositionReflection<
117
+ out P = unknown,
118
+ out C extends UiContract = UiContract,
119
+ out S extends ReadonlyArray<unknown> = ReadonlyArray<unknown>,
120
+ out N extends string = string,
121
+ out Identity = unknown,
122
+ > {
123
+ new (): CompositionInstance<Identity>
124
+ readonly manifest: CompositionManifest<C, N>
125
+ readonly Props: P
126
+ readonly Contract: C
127
+ readonly States: S
128
+ readonly parseProps: (input: unknown) => Option.Option<P>
129
+ }
130
+
131
+ export interface CompositionPropsReceiver<in P> {
132
+ readonly acceptsProps: (props: P) => void
133
+ }
134
+
135
+ export type CompositionCapture<Result> = <
136
+ P,
137
+ C extends UiContract,
138
+ S extends ReadonlyArray<unknown>,
139
+ N extends string,
140
+ Identity,
141
+ >(
142
+ composition: CompositionClass<P, C, S, N, Identity>,
143
+ ) => Result
144
+
145
+ export interface AnyComposition extends CompositionReflection {
146
+ readonly capture: <Result>(visit: CompositionCapture<Result>) => Result
147
+ }
148
+
149
+ export interface CompositionSchema {
150
+ readonly ast: AST
151
+ }
152
+
153
+ export type GeneratorContext<Eff> = [Eff] extends [never]
154
+ ? never
155
+ : [Eff] extends [YieldWrap<Effect.Effect<infer _Success, infer _Error, infer R>>]
156
+ ? R
157
+ : never
158
+
159
+ // Property presence drives Config conditional inference; Option would erase it.
160
+ export interface CompositionConfigOptionalFields {
161
+ readonly description: string
162
+ readonly props: CompositionSchema
163
+ readonly states: ReadonlyArray<unknown>
164
+ readonly calcs: ReadonlyArray<unknown>
165
+ readonly events: ReadonlyArray<unknown>
166
+ readonly slots: Record<string, AnySlot>
167
+ }
168
+
169
+ export interface CompositionConfig extends Partial<CompositionConfigOptionalFields> {
170
+ readonly title: string
171
+ readonly ui: UiReflection
172
+ }
173
+
174
+ export type PropsOf<Config> = Config extends { props: infer PropsSchema }
175
+ ? PropsSchema extends Schema.Schema<infer P, infer _Encoded, infer _Context>
176
+ ? P
177
+ : unknown
178
+ : unknown
179
+
180
+ export type EncodedPropsOf<Config> = Config extends { props: infer PropsSchema }
181
+ ? PropsSchema extends Schema.Schema<infer _Props, infer Encoded, infer _Context>
182
+ ? Encoded
183
+ : unknown
184
+ : unknown
185
+
186
+ export type StatesOf<Config> = Config extends {
187
+ states: infer S extends ReadonlyArray<unknown>
188
+ }
189
+ ? S
190
+ : readonly []
191
+
192
+ export interface CompositionClass<
193
+ in out P,
194
+ in out C extends UiContract = UiContract,
195
+ out S extends ReadonlyArray<unknown> = ReadonlyArray<unknown>,
196
+ in out N extends string = string,
197
+ in out Identity = unknown,
198
+ >
199
+ extends CompositionReflection<P, C, S, N, Identity>, CompositionPropsReceiver<P> {
200
+ readonly Props: P
201
+ readonly Contract: C
202
+ readonly States: S
203
+ readonly identity: symbol
204
+ readonly props: PropsTag<P>
205
+ readonly tag: CompositionTag<N, P, C, Identity>
206
+ readonly capture: <Result>(visit: CompositionCapture<Result>) => Result
207
+ }
208
+
209
+ export type CompositionDefinitionStatics<
210
+ P,
211
+ C extends UiContract,
212
+ S extends ReadonlyArray<unknown>,
213
+ N extends string,
214
+ Identity,
215
+ > = Pick<
216
+ CompositionClass<P, C, S, N, Identity>,
217
+ 'manifest' | 'identity' | 'props' | 'parseProps' | 'acceptsProps' | 'tag' | 'capture'
218
+ >
219
+
220
+ export interface UiCarrier<C extends UiContract, UiName extends string> {
221
+ readonly ui: UiClass<C, UiName>
222
+ }
223
+
224
+ export type ContractSlots<C extends UiContract> = CompositionSlots<C>
225
+
226
+ export type ContextFreeProps<Config> = Config extends {
227
+ readonly props: infer PropsSchema
228
+ }
229
+ ? PropsSchema extends Schema.Schema<infer _P, infer _Encoded, infer Context>
230
+ ? [Context] extends [never]
231
+ ? unknown
232
+ : { readonly propsSchemaMustNotRequireServices: never }
233
+ : unknown
234
+ : unknown
235
+ export type CompositionLayerInput<Eff> = Exclude<Exclude<GeneratorContext<Eff>, PropsId>, CurrentTracker>
236
+
237
+ export type CompositionActivationLayerInput<Eff> = Exclude<
238
+ Exclude<GeneratorContext<Eff>, PropsId>,
239
+ Scope.Scope
240
+ >
241
+
242
+ export interface ScopedCompositionLiveConfig<
243
+ C extends UiContract,
244
+ RenderEff extends YieldWrap<Effect.Effect<unknown, never, unknown>>,
245
+ ActivationEff extends YieldWrap<Effect.Effect<unknown, never, unknown>>,
246
+ > {
247
+ readonly render: () => Generator<RenderEff, Frame<C>, never>
248
+ readonly activate: () => Generator<ActivationEff, void, never>
249
+ }
@@ -1,8 +1,15 @@
1
1
  import { Context } from 'effect'
2
- import type { AnyValue } from '../internal/variance'
3
2
 
4
- const PropsBase: Context.TagClass<Props, 'reform/Props', AnyValue> = Context.Tag('reform/Props')<
5
- Props,
6
- AnyValue
7
- >()
8
- export class Props extends PropsBase {}
3
+ export const PropsIdTypeId: unique symbol = Symbol.for('reform/PropsId')
4
+ export type PropsIdTypeId = typeof PropsIdTypeId
5
+
6
+ export interface PropsId {
7
+ readonly [PropsIdTypeId]: PropsIdTypeId
8
+ }
9
+
10
+ export type PropsTag<P> = Context.Tag<PropsId, P>
11
+
12
+ export const propsTag = <P>(): PropsTag<P> => Context.GenericTag<PropsId, P>('reform/Props')
13
+
14
+ // Unknown keeps the compatibility reader from leaking untyped props.
15
+ export const Props: PropsTag<unknown> = propsTag<unknown>()