@playfast/reform 1.0.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/README.md +103 -56
  2. package/package.json +17 -17
  3. package/src/boundary/boundary.test.ts +63 -49
  4. package/src/boundary/boundary.ts +144 -113
  5. package/src/calc/asyncCalc.invalidate.test.ts +518 -32
  6. package/src/calc/asyncCalc.test.ts +207 -213
  7. package/src/calc/asyncCalc.ts +131 -154
  8. package/src/calc/asyncData.ts +0 -37
  9. package/src/calc/calc.test.ts +7 -33
  10. package/src/calc/calc.ts +44 -58
  11. package/src/calc/calcFamily.test.ts +80 -34
  12. package/src/calc/calcFamily.ts +54 -65
  13. package/src/calc/compose.test.ts +1 -12
  14. package/src/calc/compose.ts +1 -36
  15. package/src/calc/queryState.ts +0 -23
  16. package/src/channel/channel.ts +126 -111
  17. package/src/compose/composition.test.ts +19 -0
  18. package/src/compose/composition.ts +351 -127
  19. package/src/compose/host.ts +0 -6
  20. package/src/compose/props.ts +13 -12
  21. package/src/compose/provide.ts +189 -62
  22. package/src/compose/slot.ts +158 -49
  23. package/src/compose/structure.test.ts +6 -9
  24. package/src/compose/structure.ts +108 -79
  25. package/src/compose/ui.test.ts +19 -7
  26. package/src/compose/ui.ts +155 -156
  27. package/src/compose/ui.typecheck.ts +40 -18
  28. package/src/definition/definition.ts +22 -41
  29. package/src/event/event.fromSource.test.ts +172 -0
  30. package/src/event/event.test.ts +10 -3
  31. package/src/event/event.ts +102 -27
  32. package/src/event/eventGroup.ts +0 -1
  33. package/src/feature/feature.mount.test.ts +122 -43
  34. package/src/feature/feature.test.ts +46 -21
  35. package/src/feature/feature.ts +1347 -256
  36. package/src/feature/feature.typecheck.ts +273 -68
  37. package/src/graph/closure.ts +403 -0
  38. package/src/index.ts +68 -126
  39. package/src/internal/bucketCache.ts +39 -0
  40. package/src/internal/capture.ts +9 -24
  41. package/src/internal/env.ts +7 -0
  42. package/src/internal/errors.test.ts +0 -6
  43. package/src/internal/errors.ts +37 -60
  44. package/src/internal/inspect.test.ts +0 -6
  45. package/src/internal/inspect.ts +0 -12
  46. package/src/internal/queryDriver.ts +105 -201
  47. package/src/internal/queryDriverStore.ts +156 -0
  48. package/src/internal/queryDriverTypes.ts +59 -0
  49. package/src/internal/queryEvents.ts +0 -12
  50. package/src/internal/queryStore.ts +0 -14
  51. package/src/internal/reuse.test.ts +10 -14
  52. package/src/internal/reuse.ts +5 -30
  53. package/src/internal/scheduler.ts +4 -44
  54. package/src/internal/seeds.ts +0 -14
  55. package/src/internal/sources.ts +26 -49
  56. package/src/internal/stateRegistry.ts +0 -14
  57. package/src/internal/store.test.ts +1 -3
  58. package/src/internal/store.ts +0 -37
  59. package/src/internal/track.ts +3 -20
  60. package/src/internal/variance.ts +5 -0
  61. package/src/internal.ts +222 -0
  62. package/src/namespace/namespace.test.ts +46 -0
  63. package/src/namespace/namespace.ts +106 -0
  64. package/src/procedure/procedure.ts +40 -35
  65. package/src/reducer/reducer.ts +78 -52
  66. package/src/remote/remoteState.test.ts +590 -397
  67. package/src/remote/remoteState.ts +425 -347
  68. package/src/remote/remoteState.typecheck.ts +47 -56
  69. package/src/runtime/appRuntime.activation.test.ts +100 -0
  70. package/src/runtime/appRuntime.test.ts +249 -0
  71. package/src/runtime/appRuntime.ts +415 -97
  72. package/src/runtime/bus.ts +2 -15
  73. package/src/runtime/eventBudget.test.ts +152 -0
  74. package/src/runtime/eventBudget.ts +120 -0
  75. package/src/runtime/hardening.test.ts +73 -13
  76. package/src/runtime/instrumentation.test.ts +55 -52
  77. package/src/runtime/instrumentation.ts +6 -60
  78. package/src/runtime/loop.test.ts +36 -17
  79. package/src/runtime/loop.ts +87 -88
  80. package/src/runtime/queries.ts +0 -17
  81. package/src/scene/featureScene.test.ts +61 -0
  82. package/src/scene/scene.ts +247 -104
  83. package/src/scene/seedScene.test.ts +42 -79
  84. package/src/state/state.nominal.typecheck.ts +68 -0
  85. package/src/state/state.test.ts +17 -0
  86. package/src/state/state.ts +80 -46
  87. package/src/state/stateFamily.test.ts +16 -11
  88. package/src/state/stateFamily.ts +55 -65
  89. package/src/state/stateGroup.ts +53 -64
  90. package/src/state/token.ts +40 -23
  91. package/src/synced/syncedStore.ts +46 -58
  92. package/src/testkit/flight.testkit.ts +75 -0
  93. package/src/ui/node.ts +0 -6
  94. package/src/ui/trigger.ts +0 -5
  95. package/src/wire/tree.test.ts +8 -7
  96. package/src/wire/tree.ts +0 -39
  97. package/src/wire/triggers.test.ts +6 -6
  98. package/src/wire/triggers.ts +14 -32
  99. package/src/internal/ctx.ts +0 -16
@@ -1,17 +1,28 @@
1
- import { Effect, Layer, Option } from 'effect'
2
- import { expect, test } from 'vitest'
1
+ import { Effect, Option } from 'effect'
2
+ import { expect, it } from '@effect/vitest'
3
3
  import * as Composition from '../compose/composition'
4
+ import { mount } from '../compose/structure'
4
5
  import { ui } from '../compose/ui'
5
6
  import * as Feature from './feature'
6
7
  import { featureModule, isFeature, isFeatureBinding, lazyImport } from './feature'
7
8
 
8
9
  // Minimal composition surface to hang features off — definitions only, no logic.
9
10
  class TestUi extends ui('TestUi')<{ props: {}; events: {} }>() {}
10
- class TestComp extends Composition.make('TestComp', { title: 'Test', ui: TestUi }) {}
11
- class FailComp extends Composition.make('FailComp', { title: 'Fail', ui: TestUi }) {}
11
+ class TestComp extends Composition.make('TestComp', {
12
+ title: 'Test',
13
+ ui: TestUi,
14
+ })<TestComp>() {}
15
+ class FailComp extends Composition.make('FailComp', {
16
+ title: 'Fail',
17
+ ui: TestUi,
18
+ })<FailComp>() {}
12
19
 
13
- // A trivial loaded module: empty layer, no shared requirements.
14
- const mod = featureModule([], Layer.empty)
20
+ const TestLive = Composition.live(TestComp, function* () {
21
+ return mount({ props: {}, slots: {} })
22
+ })
23
+
24
+ // A valid Feature module owns its declared root Composition service.
25
+ const mod = featureModule([], TestLive)
15
26
 
16
27
  class LazyFeature extends Feature.make('lazyFeature', {
17
28
  loadingStrategy: 'lazy',
@@ -20,41 +31,55 @@ class LazyFeature extends Feature.make('lazyFeature', {
20
31
  placeholder: { loading: TestComp, failed: FailComp },
21
32
  }) {}
22
33
 
34
+ class SameShapeFeature extends Feature.make('lazyFeature', {
35
+ loadingStrategy: 'lazy',
36
+ composition: TestComp,
37
+ load: lazyImport(() => Promise.resolve({ default: mod })),
38
+ placeholder: { loading: TestComp, failed: FailComp },
39
+ }) {}
40
+
23
41
  class EagerFeature extends Feature.make('eagerFeature', {
24
42
  composition: TestComp,
25
43
  module: mod,
26
44
  }) {}
27
45
 
28
- test('a lazy feature reflects as a Feature manifest with placeholders, no chunk loaded', () => {
46
+ const LazyNative = Feature.tree<typeof LazyFeature>(LazyFeature.token)
47
+ const EagerNative = Feature.tree<typeof EagerFeature>(EagerFeature.token)
48
+
49
+ it('a lazy feature reflects as a Feature manifest with placeholders, no chunk loaded', () => {
29
50
  expect(LazyFeature.manifest.kind).toBe('Feature')
30
51
  expect(LazyFeature.manifest.name).toBe('lazyFeature')
31
52
  expect(LazyFeature.manifest.strategy).toBe('lazy')
32
53
  expect(LazyFeature.manifest.composition.name).toBe('TestComp')
33
54
  expect(Option.getOrThrow(LazyFeature.manifest.placeholder).loading.name).toBe('TestComp')
34
55
  expect(Option.getOrThrow(LazyFeature.manifest.placeholder).failed.name).toBe('FailComp')
35
- expect(LazyFeature.eagerModule).toBeUndefined()
56
+ expect(LazyNative.eagerModule).toBeUndefined()
36
57
  })
37
58
 
38
- test('an eager feature reflects as default strategy with its module available', () => {
59
+ it('an eager feature reflects as default strategy with its module available', () => {
39
60
  expect(EagerFeature.manifest.strategy).toBe('default')
40
61
  expect(Option.isNone(EagerFeature.manifest.placeholder)).toBe(true)
41
- expect(EagerFeature.eagerModule).toBe(mod)
62
+ expect(EagerNative.eagerModule).toBe(mod)
42
63
  })
43
64
 
44
- test('isFeature / isFeatureBinding discriminate', () => {
65
+ it('isFeature / isFeatureBinding discriminate', () => {
45
66
  expect(isFeature(LazyFeature)).toBe(true)
46
67
  expect(isFeature(TestComp)).toBe(false)
47
68
  expect(isFeature(null)).toBe(false)
48
- expect(isFeatureBinding(LazyFeature.binding)).toBe(true)
69
+ expect(isFeatureBinding(LazyNative.binding)).toBe(true)
49
70
  expect(isFeatureBinding(TestComp)).toBe(false)
71
+ expect(LazyFeature.token).not.toBe(SameShapeFeature.token)
72
+ expect(LazyFeature.token.identity).not.toBe(SameShapeFeature.token.identity)
50
73
  })
51
74
 
52
- test('load is an Effect (not a thenable) that yields the module and its requires', async () => {
53
- // No `.then` on `load` — it is an Effect, run on the Effect runtime.
54
- expect(typeof (LazyFeature.load as { then?: unknown }).then).toBe('undefined')
55
- const loaded = await Effect.runPromise(LazyFeature.load)
56
- expect(loaded.requires).toEqual([])
57
- expect(loaded).toBe(mod)
58
- // default strategy resolves immediately to its module.
59
- expect(await Effect.runPromise(EagerFeature.load)).toBe(mod)
60
- })
75
+ it.live('load is an Effect (not a thenable) that yields the module and its requires', () =>
76
+ Effect.gen(function* () {
77
+ // No `.then` on `load` it is an Effect, run on the Effect runtime.
78
+ expect('then' in LazyNative.load).toBe(false)
79
+ const loaded = yield* LazyNative.load
80
+ expect(loaded.requires).toEqual([])
81
+ expect(loaded).toBe(mod)
82
+ // default strategy resolves immediately to its module.
83
+ expect(yield* EagerNative.load).toBe(mod)
84
+ }),
85
+ )