foldkit 0.152.0 → 0.153.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 (56) hide show
  1. package/dist/asyncData/asyncData.d.ts.map +1 -1
  2. package/dist/asyncData/asyncData.js +10 -7
  3. package/dist/canvas/shape.d.ts.map +1 -1
  4. package/dist/canvas/shape.js +11 -11
  5. package/dist/command/interruptible/interruptible.d.ts +12 -23
  6. package/dist/command/interruptible/interruptible.d.ts.map +1 -1
  7. package/dist/command/interruptible/interruptible.js +12 -16
  8. package/dist/command/interruptible/public.d.ts +1 -1
  9. package/dist/command/interruptible/public.d.ts.map +1 -1
  10. package/dist/command/interruptible/public.js +1 -1
  11. package/dist/devTools/protocol.d.ts +391 -527
  12. package/dist/devTools/protocol.d.ts.map +1 -1
  13. package/dist/devTools/protocol.js +96 -192
  14. package/dist/devTools/public.d.ts +1 -1
  15. package/dist/devTools/public.d.ts.map +1 -1
  16. package/dist/devTools/public.js +1 -1
  17. package/dist/devTools/summarize.d.ts +19 -25
  18. package/dist/devTools/summarize.d.ts.map +1 -1
  19. package/dist/devTools/summarize.js +19 -24
  20. package/dist/devTools/webSocketBridge.d.ts +1 -1
  21. package/dist/devTools/webSocketBridge.d.ts.map +1 -1
  22. package/dist/devTools/webSocketBridge.js +45 -41
  23. package/dist/navigation/index.d.ts +1 -1
  24. package/dist/navigation/index.d.ts.map +1 -1
  25. package/dist/navigation/index.js +1 -1
  26. package/dist/navigation/public.d.ts +1 -1
  27. package/dist/navigation/public.d.ts.map +1 -1
  28. package/dist/navigation/public.js +1 -1
  29. package/dist/navigation/urlRequest.d.ts +15 -31
  30. package/dist/navigation/urlRequest.d.ts.map +1 -1
  31. package/dist/navigation/urlRequest.js +5 -10
  32. package/dist/route/index.d.ts +2 -1
  33. package/dist/route/index.d.ts.map +1 -1
  34. package/dist/route/index.js +1 -1
  35. package/dist/route/public.d.ts +2 -2
  36. package/dist/route/public.d.ts.map +1 -1
  37. package/dist/route/public.js +1 -1
  38. package/dist/runtime/browserListeners.d.ts.map +1 -1
  39. package/dist/runtime/browserListeners.js +3 -3
  40. package/dist/schema/index.d.ts +140 -49
  41. package/dist/schema/index.d.ts.map +1 -1
  42. package/dist/schema/index.js +132 -31
  43. package/dist/schema/public.d.ts +2 -2
  44. package/dist/schema/public.d.ts.map +1 -1
  45. package/dist/schema/public.js +1 -1
  46. package/dist/test/apps/contextMenu.d.ts +10 -7
  47. package/dist/test/apps/contextMenu.d.ts.map +1 -1
  48. package/dist/test/apps/contextMenu.js +6 -7
  49. package/dist/test/apps/formChild.d.ts +0 -16
  50. package/dist/test/apps/formChild.d.ts.map +1 -1
  51. package/dist/test/apps/formChild.js +0 -3
  52. package/dist/test/apps/uploads.d.ts +4 -1
  53. package/dist/test/apps/uploads.d.ts.map +1 -1
  54. package/dist/test/scene.d.ts +1 -1
  55. package/dist/test/scene.d.ts.map +1 -1
  56. package/package.json +1 -1
@@ -6,50 +6,73 @@ export type CallableTaggedStruct<Tag extends string, Fields extends S.Struct.Fie
6
6
  readonly _tag: S.tag<Tag>;
7
7
  } & Fields>>);
8
8
  type TaggedUnionProperty = keyof S.TaggedUnion<{}>;
9
- type MessageVariantNameCollision<Name extends PropertyKey> = Readonly<{
10
- 'Message variant names must not conflict with Schema.TaggedUnion properties': Name;
9
+ type UnionProperty = TaggedUnionProperty | 'members' | 'subset';
10
+ type VariantNameCollision<Name extends PropertyKey> = Readonly<{
11
+ 'Variant names must not conflict with union properties': Name;
11
12
  }>;
12
- type ValidateMessageVariantNames<CasesByTag extends Record<string, S.Struct.Fields>> = Extract<keyof CasesByTag, TaggedUnionProperty> extends infer Name ? [Name] extends [never] ? unknown : MessageVariantNameCollision<Name & PropertyKey> : never;
13
- type TaggedMessageUnion<CasesByTag extends Record<string, S.Struct.Fields>> = S.TaggedUnion<{
13
+ type ValidateVariantNames<CasesByTag extends Record<string, S.Struct.Fields>> = Extract<keyof CasesByTag, UnionProperty> extends infer Name ? [Name] extends [never] ? unknown : VariantNameCollision<Name & PropertyKey> : never;
14
+ type BaseTaggedUnion<CasesByTag extends Record<string, S.Struct.Fields>> = S.TaggedUnion<{
14
15
  readonly [Tag in keyof CasesByTag & string]: S.TaggedStruct<Tag, CasesByTag[Tag]>;
15
16
  }>;
16
- interface MessageSchema<CasesByTag extends Record<string, S.Struct.Fields>> extends S.BottomLazy<TaggedMessageUnion<CasesByTag>['ast'], MessageSchema<CasesByTag>> {
17
- readonly Type: TaggedMessageUnion<CasesByTag>['Type'];
18
- readonly Encoded: TaggedMessageUnion<CasesByTag>['Encoded'];
19
- readonly DecodingServices: TaggedMessageUnion<CasesByTag>['DecodingServices'];
20
- readonly EncodingServices: TaggedMessageUnion<CasesByTag>['EncodingServices'];
21
- readonly '~type.make.in': TaggedMessageUnion<CasesByTag>['~type.make.in'];
22
- readonly '~type.make': TaggedMessageUnion<CasesByTag>['~type.make'];
23
- readonly Iso: TaggedMessageUnion<CasesByTag>['Iso'];
24
- readonly match: TaggedMessageUnion<CasesByTag>['match'];
17
+ interface UnionSchema<CasesByTag extends Record<string, S.Struct.Fields>> extends S.BottomLazy<BaseTaggedUnion<CasesByTag>['ast'], UnionSchema<CasesByTag>> {
18
+ readonly Type: BaseTaggedUnion<CasesByTag>['Type'];
19
+ readonly Encoded: BaseTaggedUnion<CasesByTag>['Encoded'];
20
+ readonly DecodingServices: BaseTaggedUnion<CasesByTag>['DecodingServices'];
21
+ readonly EncodingServices: BaseTaggedUnion<CasesByTag>['EncodingServices'];
22
+ readonly '~type.make.in': BaseTaggedUnion<CasesByTag>['~type.make.in'];
23
+ readonly '~type.make': BaseTaggedUnion<CasesByTag>['~type.make'];
24
+ readonly Iso: BaseTaggedUnion<CasesByTag>['Iso'];
25
+ readonly match: BaseTaggedUnion<CasesByTag>['match'];
25
26
  }
26
- /** The union `defineMessageUnion` returns. A Schema with exhaustive matching
27
- * and one callable constructor per variant, reachable by tag. */
28
- export type MessageUnion<CasesByTag extends Record<string, S.Struct.Fields>> = MessageSchema<CasesByTag> & {
27
+ type TaggedUnionMemberFor<CasesByTag extends Record<string, S.Struct.Fields>, Tag extends keyof CasesByTag & string> = CallableTaggedStruct<Tag, CasesByTag[Tag]>;
28
+ type TaggedUnionMember<CasesByTag extends Record<string, S.Struct.Fields>> = {
29
+ readonly [Tag in keyof CasesByTag & string]: TaggedUnionMemberFor<CasesByTag, Tag>;
30
+ }[keyof CasesByTag & string];
31
+ type TaggedUnionSubsetMembers<CasesByTag extends Record<string, S.Struct.Fields>, Tags extends ReadonlyArray<keyof CasesByTag & string>> = {
32
+ readonly [Index in keyof Tags]: Tags[Index] extends keyof CasesByTag & string ? TaggedUnionMemberFor<CasesByTag, Tags[Index]> : never;
33
+ };
34
+ interface RichUnionSchema<CasesByTag extends Record<string, S.Struct.Fields>> extends UnionSchema<CasesByTag> {
35
+ readonly guards: BaseTaggedUnion<CasesByTag>['guards'];
36
+ readonly isAnyOf: BaseTaggedUnion<CasesByTag>['isAnyOf'];
37
+ readonly members: ReadonlyArray<TaggedUnionMember<CasesByTag>>;
38
+ /** Returns a Schema that accepts only the named variants. */
39
+ readonly subset: <const Tags extends ReadonlyArray<keyof CasesByTag & string>>(tags: Tags) => S.Union<TaggedUnionSubsetMembers<CasesByTag, Tags>>;
40
+ }
41
+ /** The Schema returned by `defineTaggedUnion`. It includes callable variant
42
+ * constructors, exhaustive `match`, `guards`, `isAnyOf`, `subset`, and
43
+ * `members`. */
44
+ export type TaggedUnion<CasesByTag extends Record<string, S.Struct.Fields>> = RichUnionSchema<CasesByTag> & {
45
+ readonly [Tag in keyof CasesByTag & string]: CallableTaggedStruct<Tag, CasesByTag[Tag]>;
46
+ };
47
+ /** The Schema returned by `defineMessageUnion`. Each variant is a callable
48
+ * property on the union, and `match` handles the union exhaustively. */
49
+ export type MessageUnion<CasesByTag extends Record<string, S.Struct.Fields>> = UnionSchema<CasesByTag> & {
29
50
  readonly [Tag in keyof CasesByTag & string]: CallableTaggedStruct<Tag, CasesByTag[Tag]>;
30
51
  };
52
+ /** The Schema returned by `defineRouteUnion`. It has the same constructors and
53
+ * helpers as `TaggedUnion`, with a Route-specific name for public signatures. */
54
+ export type RouteUnion<CasesByTag extends Record<string, S.Struct.Fields>> = TaggedUnion<CasesByTag>;
31
55
  /**
32
- * Declares a whole Message union from one record of fields per variant, naming
33
- * each variant once instead of once per constructor and once in the union list.
56
+ * Declares every Message variant in one object. Each key is a tag, and its
57
+ * value lists that Message's fields.
34
58
  *
35
- * The result is a Schema, so it decodes and nests in a Model. Its focused
36
- * Message surface is exhaustive `match` plus one callable constructor per
37
- * variant. Each constructor is itself a schema, which is what `Command.define`
38
- * needs for its `messages` list.
59
+ * The result is both a Schema and a namespace. Construct a Message with a
60
+ * variant such as `Message.ClickedReset()`, and handle every variant with
61
+ * `Message.match`. Each constructor is also a Schema, so it can appear in a
62
+ * `Command.define` `messages` list.
39
63
  *
40
- * Use `Message.match` for exhaustive dispatch. The values are ordinary tagged
41
- * objects, so Effect `Match` remains available for partial matching, one
42
- * handler over several tags, and fallbacks.
64
+ * Message unions intentionally expose only constructors and exhaustive
65
+ * `match`. Use Effect `Match` when only some tags need handling or several tags
66
+ * share one handler.
43
67
  *
44
- * A Submodel's OutMessage is declared the same way, with variants of its own. A
45
- * Message is a fact the Submodel handles; an OutMessage is a fact it reports to
46
- * its parent. Sharing one variant between the two unions puts the child's
47
- * internal vocabulary in the parent's contract, so declare them separately even
48
- * when a pair happens to carry the same fields.
68
+ * Declare a Submodel's OutMessages in their own `defineMessageUnion`. Messages
69
+ * are facts the Submodel handles; OutMessages are facts it reports to its
70
+ * parent. Keep the two unions separate even when two variants carry the same
71
+ * fields.
49
72
  *
50
- * A variant may not be named after the schema surface it would shadow, such as
51
- * `make`, `match`, `cases`, or `ast`. TypeScript reports the conflicting names,
52
- * and untyped calls fail with a runtime error.
73
+ * A tag cannot use a name already owned by the union, such as `make`, `match`,
74
+ * `cases`, `ast`, `members`, or `subset`. TypeScript rejects these names, and
75
+ * untyped calls throw an error.
53
76
  *
54
77
  * @example
55
78
  * ```typescript
@@ -63,37 +86,105 @@ export type MessageUnion<CasesByTag extends Record<string, S.Struct.Fields>> = M
63
86
  * Message.ChangedCount({ count: 1 }) // { _tag: 'ChangedCount', count: 1 }
64
87
  * ```
65
88
  */
66
- export declare function defineMessageUnion<const CasesByTag extends Record<string, S.Struct.Fields>>(casesByTag: CasesByTag & ValidateMessageVariantNames<CasesByTag>): MessageUnion<CasesByTag>;
89
+ export declare function defineMessageUnion<const CasesByTag extends Record<string, S.Struct.Fields>>(casesByTag: CasesByTag & ValidateVariantNames<CasesByTag>): MessageUnion<CasesByTag>;
67
90
  /**
68
- * Wraps `Schema.TaggedStruct` to create a route variant you can call directly as a constructor.
69
- * Use `r` for route types enabling `Home()` instead of `Home.make()`.
91
+ * Declares every variant of a domain union in one object. Use it for Model
92
+ * states, submission results, filter modes, and other unions that are not
93
+ * Messages or Routes.
94
+ *
95
+ * The result is both a Schema and a namespace. It provides:
96
+ *
97
+ * - One callable Schema constructor per variant.
98
+ * - `match` for exhaustive handling.
99
+ * - `guards` and `isAnyOf` for variant checks.
100
+ * - `subset` for a Schema that accepts only the named variants.
101
+ * - `members` for APIs such as `Machine.define` that enumerate the union.
102
+ *
103
+ * Use `taggedStruct` when the variants cannot be declared together. Recursive
104
+ * unions and standalone tagged structs are the common cases.
105
+ *
106
+ * A tag cannot use a name already owned by the union, such as `make`, `match`,
107
+ * `cases`, `ast`, `members`, or `subset`. TypeScript rejects these names, and
108
+ * untyped calls throw an error.
70
109
  *
71
110
  * @example
72
111
  * ```typescript
73
- * const Home = r('Home')
74
- * Home() // { _tag: 'Home' }
112
+ * export const Submission = defineTaggedUnion({
113
+ * NotSubmitted: {},
114
+ * Submitting: {},
115
+ * Succeeded: {},
116
+ * Failed: { error: S.String },
117
+ * })
118
+ * export type Submission = typeof Submission.Type
75
119
  *
76
- * const UserProfile = r('UserProfile', { id: S.String })
77
- * UserProfile({ id: 'abc' }) // { _tag: 'UserProfile', id: 'abc' }
120
+ * Submission.NotSubmitted() // { _tag: 'NotSubmitted' }
121
+ * Submission.Failed({ error: 'timeout' })
78
122
  * ```
79
123
  */
80
- export declare function r<Tag extends string>(tag: Tag): CallableTaggedStruct<Tag, {}>;
81
- export declare function r<Tag extends string, Fields extends S.Struct.Fields>(tag: Tag, fields: Fields): CallableTaggedStruct<Tag, Fields>;
124
+ export declare function defineTaggedUnion<const CasesByTag extends Record<string, S.Struct.Fields>>(casesByTag: CasesByTag & ValidateVariantNames<CasesByTag>): TaggedUnion<CasesByTag>;
82
125
  /**
83
- * Wraps `Schema.TaggedStruct` to create a callable tagged struct you can call directly as a constructor.
84
- * Use `ts` for non-message, non-route tagged structs — enabling `Loading()`
85
- * instead of `Loading.make()`.
126
+ * Declares every application Route in one object. Each key is a tag, and its
127
+ * value lists the fields parsed from the URL.
128
+ *
129
+ * The result is both a Schema and the `AppRoute` namespace. Each variant is a
130
+ * callable Schema, so `AppRoute.Person` works with `mapTo` and
131
+ * `parseUrlWithFallback`, while `AppRoute.Person({ personId: 42 })` constructs
132
+ * a value.
133
+ *
134
+ * Use `match` to handle every Route, `guards` or `isAnyOf` to check selected
135
+ * tags, and `subset` when another Schema accepts only some Routes. A subset
136
+ * includes only the tags named in the call. Adding a Route to `AppRoute` does
137
+ * not change an existing subset.
138
+ *
139
+ * Routers remain separate. A Route is the parsed value; a Router describes the
140
+ * URL that produces it.
141
+ *
142
+ * A tag cannot use a name already owned by the union, such as `make`, `match`,
143
+ * `cases`, `ast`, `members`, or `subset`. TypeScript rejects these names, and
144
+ * untyped calls throw an error.
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * export const AppRoute = defineRouteUnion({
149
+ * Home: {},
150
+ * Person: { personId: S.Number },
151
+ * NotFound: { path: S.String },
152
+ * })
153
+ * export type AppRoute = typeof AppRoute.Type
154
+ *
155
+ * export const homeRouter = pipe(root, mapTo(AppRoute.Home))
156
+ * export const personRouter = pipe(
157
+ * literal('people'),
158
+ * slash(int('personId')),
159
+ * mapTo(AppRoute.Person),
160
+ * )
161
+ *
162
+ * export const urlToAppRoute = parseUrlWithFallback(
163
+ * oneOf(personRouter, homeRouter),
164
+ * AppRoute.NotFound,
165
+ * )
166
+ * ```
167
+ */
168
+ export declare function defineRouteUnion<const CasesByTag extends Record<string, S.Struct.Fields>>(casesByTag: CasesByTag & ValidateVariantNames<CasesByTag>): RouteUnion<CasesByTag>;
169
+ /**
170
+ * Declares one tagged struct as a callable Schema. Call `Loading()` instead of
171
+ * `Loading.make()`.
172
+ *
173
+ * Prefer `defineTaggedUnion` when every variant can be declared together. Use
174
+ * `taggedStruct` for a recursive union, a union assembled across modules, a
175
+ * tagged child struct that is not a union variant, or a variant created inside
176
+ * a generic Schema factory.
86
177
  *
87
178
  * @example
88
179
  * ```typescript
89
- * const Loading = ts('Loading')
180
+ * const Loading = taggedStruct('Loading')
90
181
  * Loading() // { _tag: 'Loading' }
91
182
  *
92
- * const Ok = ts('Ok', { data: S.String })
183
+ * const Ok = taggedStruct('Ok', { data: S.String })
93
184
  * Ok({ data: 'hello' }) // { _tag: 'Ok', data: 'hello' }
94
185
  * ```
95
186
  */
96
- export declare function ts<Tag extends string>(tag: Tag): CallableTaggedStruct<Tag, {}>;
97
- export declare function ts<Tag extends string, Fields extends S.Struct.Fields>(tag: Tag, fields: Fields): CallableTaggedStruct<Tag, Fields>;
187
+ export declare function taggedStruct<Tag extends string>(tag: Tag): CallableTaggedStruct<Tag, {}>;
188
+ export declare function taggedStruct<Tag extends string, Fields extends S.Struct.Fields>(tag: Tag, fields: Fields): CallableTaggedStruct<Tag, Fields>;
98
189
  export {};
99
190
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,MAAM,IAAI,CAAC,EAAa,KAAK,EAAE,MAAM,QAAQ,CAAA;AAEzE,qIAAqI;AACrI,MAAM,MAAM,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UAAU,EAAE,UAAU,GAAG,oBAAoB,CAAC,UAAU,CAAC,GACxD,YAAY,CAAC,UAAU,CAAC,CAE1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,CAAC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAExD,UAAU,EAAE,UAAU,GAAG,oBAAoB,CAAC,UAAU,CAAC,GACxD,WAAW,CAAC,UAAU,CAAC,CAEzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,CAAC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAExD,UAAU,EAAE,UAAU,GAAG,oBAAoB,CAAC,UAAU,CAAC,GACxD,UAAU,CAAC,UAAU,CAAC,CAExB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,GAAG,SAAS,MAAM,EAC7C,GAAG,EAAE,GAAG,GACP,oBAAoB,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;AAChC,wBAAgB,YAAY,CAC1B,GAAG,SAAS,MAAM,EAClB,MAAM,SAAS,CAAC,CAAC,MAAM,CAAC,MAAM,EAC9B,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,oBAAoB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA"}
@@ -109,6 +109,7 @@ const makeCallable = (tag, fields) => {
109
109
  },
110
110
  });
111
111
  };
112
+ const reservedUnionPropertyNames = new Set(['members', 'subset']);
112
113
  const taggedUnionTypeOnlyPropertyNames = new Set([
113
114
  'Rebuild',
114
115
  '~type.parameters',
@@ -125,28 +126,58 @@ const taggedUnionTypeOnlyPropertyNames = new Set([
125
126
  '~encoded.mutability',
126
127
  '~encoded.optionality',
127
128
  ]);
129
+ const defineUnion = (variantLabel, casesByTag) => {
130
+ const union = S.TaggedUnion(casesByTag);
131
+ const conflictingNames = Array.filter(Object.keys(casesByTag), name => Reflect.has(union, name) ||
132
+ taggedUnionTypeOnlyPropertyNames.has(name) ||
133
+ reservedUnionPropertyNames.has(name));
134
+ if (Array.isArrayNonEmpty(conflictingNames)) {
135
+ throw new Error(`${variantLabel} names conflict with union properties: ${conflictingNames.join(', ')}`);
136
+ }
137
+ const callables = {};
138
+ for (const [tag, fields] of Object.entries(casesByTag)) {
139
+ callables[tag] = makeCallable(tag, fields);
140
+ }
141
+ const subset = (tags) => {
142
+ const members = [];
143
+ for (const tag of tags) {
144
+ const member = callables[tag];
145
+ if (!Object.hasOwn(callables, tag) || member === undefined) {
146
+ throw new Error(`Union subset contains an unknown variant: ${tag}`);
147
+ }
148
+ members.push(member);
149
+ }
150
+ return S.Union(members);
151
+ };
152
+ /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions */
153
+ return Object.assign(union, callables, {
154
+ // NOTE: Schema.TaggedUnion does not expose the member list that Schema.Union
155
+ // does. Machine.define uses that list to enumerate the state tags.
156
+ members: Object.values(callables),
157
+ subset,
158
+ });
159
+ };
128
160
  /**
129
- * Declares a whole Message union from one record of fields per variant, naming
130
- * each variant once instead of once per constructor and once in the union list.
161
+ * Declares every Message variant in one object. Each key is a tag, and its
162
+ * value lists that Message's fields.
131
163
  *
132
- * The result is a Schema, so it decodes and nests in a Model. Its focused
133
- * Message surface is exhaustive `match` plus one callable constructor per
134
- * variant. Each constructor is itself a schema, which is what `Command.define`
135
- * needs for its `messages` list.
164
+ * The result is both a Schema and a namespace. Construct a Message with a
165
+ * variant such as `Message.ClickedReset()`, and handle every variant with
166
+ * `Message.match`. Each constructor is also a Schema, so it can appear in a
167
+ * `Command.define` `messages` list.
136
168
  *
137
- * Use `Message.match` for exhaustive dispatch. The values are ordinary tagged
138
- * objects, so Effect `Match` remains available for partial matching, one
139
- * handler over several tags, and fallbacks.
169
+ * Message unions intentionally expose only constructors and exhaustive
170
+ * `match`. Use Effect `Match` when only some tags need handling or several tags
171
+ * share one handler.
140
172
  *
141
- * A Submodel's OutMessage is declared the same way, with variants of its own. A
142
- * Message is a fact the Submodel handles; an OutMessage is a fact it reports to
143
- * its parent. Sharing one variant between the two unions puts the child's
144
- * internal vocabulary in the parent's contract, so declare them separately even
145
- * when a pair happens to carry the same fields.
173
+ * Declare a Submodel's OutMessages in their own `defineMessageUnion`. Messages
174
+ * are facts the Submodel handles; OutMessages are facts it reports to its
175
+ * parent. Keep the two unions separate even when two variants carry the same
176
+ * fields.
146
177
  *
147
- * A variant may not be named after the schema surface it would shadow, such as
148
- * `make`, `match`, `cases`, or `ast`. TypeScript reports the conflicting names,
149
- * and untyped calls fail with a runtime error.
178
+ * A tag cannot use a name already owned by the union, such as `make`, `match`,
179
+ * `cases`, `ast`, `members`, or `subset`. TypeScript rejects these names, and
180
+ * untyped calls throw an error.
150
181
  *
151
182
  * @example
152
183
  * ```typescript
@@ -161,21 +192,91 @@ const taggedUnionTypeOnlyPropertyNames = new Set([
161
192
  * ```
162
193
  */
163
194
  export function defineMessageUnion(casesByTag) {
164
- const union = S.TaggedUnion(casesByTag);
165
- const conflictingNames = Array.filter(Object.keys(casesByTag), name => Reflect.has(union, name) || taggedUnionTypeOnlyPropertyNames.has(name));
166
- if (Array.isArrayNonEmpty(conflictingNames)) {
167
- throw new Error(`Message variant names conflict with Schema.TaggedUnion properties: ${conflictingNames.join(', ')}`);
168
- }
169
- const callables = {};
170
- for (const [tag, fields] of Object.entries(casesByTag)) {
171
- callables[tag] = makeCallable(tag, fields);
172
- }
173
- /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions */
174
- return Object.assign(union, callables);
195
+ return defineUnion('Message variant', casesByTag);
175
196
  }
176
- export function r(tag, fields = {}) {
177
- return makeCallable(tag, fields);
197
+ /**
198
+ * Declares every variant of a domain union in one object. Use it for Model
199
+ * states, submission results, filter modes, and other unions that are not
200
+ * Messages or Routes.
201
+ *
202
+ * The result is both a Schema and a namespace. It provides:
203
+ *
204
+ * - One callable Schema constructor per variant.
205
+ * - `match` for exhaustive handling.
206
+ * - `guards` and `isAnyOf` for variant checks.
207
+ * - `subset` for a Schema that accepts only the named variants.
208
+ * - `members` for APIs such as `Machine.define` that enumerate the union.
209
+ *
210
+ * Use `taggedStruct` when the variants cannot be declared together. Recursive
211
+ * unions and standalone tagged structs are the common cases.
212
+ *
213
+ * A tag cannot use a name already owned by the union, such as `make`, `match`,
214
+ * `cases`, `ast`, `members`, or `subset`. TypeScript rejects these names, and
215
+ * untyped calls throw an error.
216
+ *
217
+ * @example
218
+ * ```typescript
219
+ * export const Submission = defineTaggedUnion({
220
+ * NotSubmitted: {},
221
+ * Submitting: {},
222
+ * Succeeded: {},
223
+ * Failed: { error: S.String },
224
+ * })
225
+ * export type Submission = typeof Submission.Type
226
+ *
227
+ * Submission.NotSubmitted() // { _tag: 'NotSubmitted' }
228
+ * Submission.Failed({ error: 'timeout' })
229
+ * ```
230
+ */
231
+ export function defineTaggedUnion(casesByTag) {
232
+ return defineUnion('Variant', casesByTag);
233
+ }
234
+ /**
235
+ * Declares every application Route in one object. Each key is a tag, and its
236
+ * value lists the fields parsed from the URL.
237
+ *
238
+ * The result is both a Schema and the `AppRoute` namespace. Each variant is a
239
+ * callable Schema, so `AppRoute.Person` works with `mapTo` and
240
+ * `parseUrlWithFallback`, while `AppRoute.Person({ personId: 42 })` constructs
241
+ * a value.
242
+ *
243
+ * Use `match` to handle every Route, `guards` or `isAnyOf` to check selected
244
+ * tags, and `subset` when another Schema accepts only some Routes. A subset
245
+ * includes only the tags named in the call. Adding a Route to `AppRoute` does
246
+ * not change an existing subset.
247
+ *
248
+ * Routers remain separate. A Route is the parsed value; a Router describes the
249
+ * URL that produces it.
250
+ *
251
+ * A tag cannot use a name already owned by the union, such as `make`, `match`,
252
+ * `cases`, `ast`, `members`, or `subset`. TypeScript rejects these names, and
253
+ * untyped calls throw an error.
254
+ *
255
+ * @example
256
+ * ```typescript
257
+ * export const AppRoute = defineRouteUnion({
258
+ * Home: {},
259
+ * Person: { personId: S.Number },
260
+ * NotFound: { path: S.String },
261
+ * })
262
+ * export type AppRoute = typeof AppRoute.Type
263
+ *
264
+ * export const homeRouter = pipe(root, mapTo(AppRoute.Home))
265
+ * export const personRouter = pipe(
266
+ * literal('people'),
267
+ * slash(int('personId')),
268
+ * mapTo(AppRoute.Person),
269
+ * )
270
+ *
271
+ * export const urlToAppRoute = parseUrlWithFallback(
272
+ * oneOf(personRouter, homeRouter),
273
+ * AppRoute.NotFound,
274
+ * )
275
+ * ```
276
+ */
277
+ export function defineRouteUnion(casesByTag) {
278
+ return defineUnion('Route variant', casesByTag);
178
279
  }
179
- export function ts(tag, fields = {}) {
280
+ export function taggedStruct(tag, fields = {}) {
180
281
  return makeCallable(tag, fields);
181
282
  }
@@ -1,3 +1,3 @@
1
- export { ts } from './index.js';
2
- export type { CallableTaggedStruct } from './index.js';
1
+ export { defineTaggedUnion, taggedStruct } from './index.js';
2
+ export type { CallableTaggedStruct, TaggedUnion } from './index.js';
3
3
  //# sourceMappingURL=public.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/schema/public.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,YAAY,CAAA;AAC/B,YAAY,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA"}
1
+ {"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/schema/public.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC5D,YAAY,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA"}
@@ -1 +1 @@
1
- export { ts } from './index.js';
1
+ export { defineTaggedUnion, taggedStruct } from './index.js';
@@ -2,9 +2,12 @@ import { Schema as S } from 'effect';
2
2
  import type { Html, HtmlBuilder } from '../../html/index.js';
3
3
  import type * as Update from '../../update/index.js';
4
4
  export declare const Model: S.Struct<{
5
- readonly contextMenu: S.Union<readonly [import("../../schema/index.js").CallableTaggedStruct<"Closed", {}>, import("../../schema/index.js").CallableTaggedStruct<"Open", {
6
- source: S.Literals<readonly ["Direct", "Inner", "Outer"]>;
7
- }>]>;
5
+ readonly contextMenu: import("../../schema/index.js").TaggedUnion<{
6
+ readonly Closed: {};
7
+ readonly Open: {
8
+ readonly source: S.Literals<readonly ["Direct", "Inner", "Outer"]>;
9
+ };
10
+ }>;
8
11
  readonly openCount: S.Number;
9
12
  }>;
10
13
  export type Model = typeof Model.Type;
@@ -16,20 +19,20 @@ declare const Message: import("../../schema/index.js").MessageUnion<{
16
19
  type Message = typeof Message.Type;
17
20
  export declare const initialModel: {
18
21
  readonly contextMenu: {
19
- readonly _tag: "Closed";
20
- } | {
21
22
  readonly _tag: "Open";
22
23
  readonly source: "Direct" | "Inner" | "Outer";
24
+ } | {
25
+ readonly _tag: "Closed";
23
26
  };
24
27
  readonly openCount: number;
25
28
  };
26
29
  export declare const update: (model: Model, message: Message) => Readonly<{
27
30
  model: {
28
31
  readonly contextMenu: {
29
- readonly _tag: "Closed";
30
- } | {
31
32
  readonly _tag: "Open";
32
33
  readonly source: "Direct" | "Inner" | "Outer";
34
+ } | {
35
+ readonly _tag: "Closed";
33
36
  };
34
37
  readonly openCount: number;
35
38
  };
@@ -1 +1 @@
1
- {"version":3,"file":"contextMenu.d.ts","sourceRoot":"","sources":["../../../src/test/apps/contextMenu.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAA;AAExD,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAI5D,OAAO,KAAK,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAcpD,eAAO,MAAM,KAAK;;;;;EAGhB,CAAA;AACF,MAAM,MAAM,KAAK,GAAG,OAAO,KAAK,CAAC,IAAI,CAAA;AAIrC,QAAA,MAAM,OAAO;;;;EAEX,CAAA;AACF,KAAK,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAA;AAIlC,eAAO,MAAM,YAAY;;;;;;;;CAGvB,CAAA;AAIF,eAAO,MAAM,MAAM,GAAI,OAAO,KAAK,EAAE,SAAS,OAAO;;;;;;;;;;;;;;;EAQjD,CAAA;AAIJ,eAAO,MAAM,IAAI,GAAI,OAAO,KAAK,EAAE,GAAG,WAAW,CAAC,OAAO,CAAC,KAAG,IA8C5D,CAAA"}
1
+ {"version":3,"file":"contextMenu.d.ts","sourceRoot":"","sources":["../../../src/test/apps/contextMenu.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAA;AAExD,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAI5D,OAAO,KAAK,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAYpD,eAAO,MAAM,KAAK;;;;;;;;EAGhB,CAAA;AACF,MAAM,MAAM,KAAK,GAAG,OAAO,KAAK,CAAC,IAAI,CAAA;AAIrC,QAAA,MAAM,OAAO;;;;EAEX,CAAA;AACF,KAAK,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAA;AAIlC,eAAO,MAAM,YAAY;;;;;;;;CAGvB,CAAA;AAIF,eAAO,MAAM,MAAM,GAAI,OAAO,KAAK,EAAE,SAAS,OAAO;;;;;;;;;;;;;;;EAQjD,CAAA;AAIJ,eAAO,MAAM,IAAI,GAAI,OAAO,KAAK,EAAE,GAAG,WAAW,CAAC,OAAO,CAAC,KAAG,IA8C5D,CAAA"}
@@ -1,14 +1,13 @@
1
1
  import { Match as M, Number, Schema as S } from 'effect';
2
2
  import { defineMessageUnion } from '../../message/index.js';
3
- import { ts } from '../../schema/index.js';
3
+ import { defineTaggedUnion } from '../../schema/index.js';
4
4
  import { evo } from '../../struct/index.js';
5
5
  // MODEL
6
6
  const ContextMenuSource = S.Literals(['Direct', 'Inner', 'Outer']);
7
- const Closed = ts('Closed');
8
- const Open = ts('Open', {
9
- source: ContextMenuSource,
7
+ const ContextMenuState = defineTaggedUnion({
8
+ Closed: {},
9
+ Open: { source: ContextMenuSource },
10
10
  });
11
- const ContextMenuState = S.Union([Closed, Open]);
12
11
  export const Model = S.Struct({
13
12
  contextMenu: ContextMenuState,
14
13
  openCount: S.Number,
@@ -19,14 +18,14 @@ const Message = defineMessageUnion({
19
18
  });
20
19
  // INIT
21
20
  export const initialModel = Model.make({
22
- contextMenu: Closed(),
21
+ contextMenu: ContextMenuState.Closed(),
23
22
  openCount: 0,
24
23
  });
25
24
  // UPDATE
26
25
  export const update = (model, message) => Message.match(message, {
27
26
  OpenedContextMenu: ({ source }) => ({
28
27
  model: evo(model, {
29
- contextMenu: () => Open({ source }),
28
+ contextMenu: () => ContextMenuState.Open({ source }),
30
29
  openCount: Number.increment,
31
30
  }),
32
31
  }),
@@ -13,9 +13,6 @@ export declare const ChildMessage: import("../../schema/index.js").MessageUnion<
13
13
  readonly CancelledForm: {};
14
14
  readonly CompletedResetForm: {};
15
15
  }>;
16
- export declare const SubmittedForm: import("../../schema/index.js").CallableTaggedStruct<"SubmittedForm", {}>, SucceededSubmitForm: import("../../schema/index.js").CallableTaggedStruct<"SucceededSubmitForm", {
17
- readonly id: S.String;
18
- }>, CancelledForm: import("../../schema/index.js").CallableTaggedStruct<"CancelledForm", {}>, CompletedResetForm: import("../../schema/index.js").CallableTaggedStruct<"CompletedResetForm", {}>;
19
16
  export type ChildMessage = typeof ChildMessage.Type;
20
17
  export declare const ChildOutMessage: import("../../schema/index.js").MessageUnion<{
21
18
  readonly RequestedSave: {
@@ -23,9 +20,6 @@ export declare const ChildOutMessage: import("../../schema/index.js").MessageUni
23
20
  };
24
21
  readonly RequestedCancel: {};
25
22
  }>;
26
- export declare const RequestedSave: import("../../schema/index.js").CallableTaggedStruct<"RequestedSave", {
27
- readonly id: S.String;
28
- }>, RequestedCancel: import("../../schema/index.js").CallableTaggedStruct<"RequestedCancel", {}>;
29
23
  export type ChildOutMessage = typeof ChildOutMessage.Type;
30
24
  export declare const SubmitForm: Command.CommandDefinitionNoArgs<"SubmitForm", Effect.Effect<{
31
25
  readonly _tag: "SucceededSubmitForm";
@@ -77,16 +71,6 @@ export declare const ParentMessage: import("../../schema/index.js").MessageUnion
77
71
  };
78
72
  readonly CompletedParentReset: {};
79
73
  }>;
80
- export declare const GotChildMessage: import("../../schema/index.js").CallableTaggedStruct<"GotChildMessage", {
81
- readonly message: import("../../schema/index.js").MessageUnion<{
82
- readonly SubmittedForm: {};
83
- readonly SucceededSubmitForm: {
84
- readonly id: S.String;
85
- };
86
- readonly CancelledForm: {};
87
- readonly CompletedResetForm: {};
88
- }>;
89
- }>, CompletedParentReset: import("../../schema/index.js").CallableTaggedStruct<"CompletedParentReset", {}>;
90
74
  export type ParentMessage = typeof ParentMessage.Type;
91
75
  export declare const initialParentModel: ParentModel;
92
76
  export declare const parentUpdate: (parentModel: ParentModel, message: ParentMessage) => Readonly<{
@@ -1 +1 @@
1
- {"version":3,"file":"formChild.d.ts","sourceRoot":"","sources":["../../../src/test/apps/formChild.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAsB,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAA;AAEhE,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAA;AAEjD,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAI/C,eAAO,MAAM,UAAU;;EAErB,CAAA;AACF,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC,IAAI,CAAA;AAI/C,eAAO,MAAM,YAAY;;;;;;;EAKvB,CAAA;AAEF,eAAO,MACL,aAAa,6EACb,mBAAmB;;IACnB,aAAa,6EACb,kBAAkB,gFACJ,CAAA;AAEhB,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAA;AAInD,eAAO,MAAM,eAAe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CAAA;AAInD,eAAO,MAAM,eAAe;;;;;EAG1B,CAAA;AACF,MAAM,MAAM,eAAe,GAAG,OAAO,eAAe,CAAC,IAAI,CAAA;AAIzD,eAAO,MAAM,UAAU;;;iBAGrB,CAAA;AAEF,eAAO,MAAM,SAAS;;iBAGpB,CAAA;AAIF,eAAO,MAAM,iBAAiB,EAAE,UAA+B,CAAA;AAI/D,eAAO,MAAM,WAAW,GAAI,QAAQ,UAAU,EAAE,SAAS,YAAY;;;;;;;;;;;;;;;;;;;;EAkBjE,CAAA;AAIJ,eAAO,MAAM,WAAW;;;;;;EAItB,CAAA;AACF,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,IAAI,CAAA;AAIjD,eAAO,MAAM,aAAa;;;;;;;;;;;;EAGxB,CAAA;AACF,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC,IAAI,CAAA;AAIrD,eAAO,MAAM,kBAAkB,EAAE,WAIhC,CAAA;AA0BD,eAAO,MAAM,YAAY,GACvB,aAAa,WAAW,EACxB,SAAS,aAAa;;;;;;;;;;;;;;;;;;;;;;;;EAMpB,CAAA"}
@@ -13,13 +13,11 @@ export const ChildMessage = defineMessageUnion({
13
13
  CancelledForm: {},
14
14
  CompletedResetForm: {},
15
15
  });
16
- export const { SubmittedForm, SucceededSubmitForm, CancelledForm, CompletedResetForm, } = ChildMessage;
17
16
  // CHILD OUT MESSAGE
18
17
  export const ChildOutMessage = defineMessageUnion({
19
18
  RequestedSave: { id: S.String },
20
19
  RequestedCancel: {},
21
20
  });
22
- export const { RequestedSave, RequestedCancel } = ChildOutMessage;
23
21
  // CHILD COMMAND
24
22
  export const SubmitForm = Command.define('SubmitForm', {
25
23
  messages: [ChildMessage.SucceededSubmitForm],
@@ -59,7 +57,6 @@ export const ParentMessage = defineMessageUnion({
59
57
  GotChildMessage: { message: ChildMessage },
60
58
  CompletedParentReset: {},
61
59
  });
62
- export const { GotChildMessage, CompletedParentReset } = ParentMessage;
63
60
  // PARENT INIT
64
61
  export const initialParentModel = {
65
62
  child: { status: 'Idle' },
@@ -33,7 +33,10 @@ export declare const Message: import("../../schema/index.js").MessageUnion<{
33
33
  };
34
34
  readonly CompletedCancelUploadFile: {
35
35
  readonly uploadId: S.Number;
36
- readonly outcome: S.Union<readonly [import("../../schema/index.js").CallableTaggedStruct<"Interrupted", {}>, import("../../schema/index.js").CallableTaggedStruct<"NotFound", {}>]>;
36
+ readonly outcome: import("../../schema/index.js").TaggedUnion<{
37
+ readonly Interrupted: {};
38
+ readonly NotFound: {};
39
+ }>;
37
40
  };
38
41
  }>;
39
42
  export type Message = typeof Message.Type;