selaws 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +355 -2
- package/dist/evidence.d.ts +45 -0
- package/dist/evidence.d.ts.map +1 -0
- package/dist/evidence.js +22 -0
- package/dist/evidence.js.map +1 -0
- package/dist/identity.d.ts +52 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +22 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/callback.d.ts +13 -0
- package/dist/internal/callback.d.ts.map +1 -0
- package/dist/internal/callback.js +2 -0
- package/dist/internal/callback.js.map +1 -0
- package/dist/internal/promise-like.d.ts +8 -0
- package/dist/internal/promise-like.d.ts.map +1 -0
- package/dist/internal/promise-like.js +12 -0
- package/dist/internal/promise-like.js.map +1 -0
- package/dist/internal/scalar.d.ts +18 -0
- package/dist/internal/scalar.d.ts.map +1 -0
- package/dist/internal/scalar.js +6 -0
- package/dist/internal/scalar.js.map +1 -0
- package/dist/option.d.ts +90 -0
- package/dist/option.d.ts.map +1 -0
- package/dist/option.js +96 -0
- package/dist/option.js.map +1 -0
- package/dist/protocol.d.ts +42 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +67 -0
- package/dist/protocol.js.map +1 -0
- package/dist/result/capture.d.ts +42 -0
- package/dist/result/capture.d.ts.map +1 -0
- package/dist/result/capture.js +41 -0
- package/dist/result/capture.js.map +1 -0
- package/dist/result/core.d.ts +98 -0
- package/dist/result/core.d.ts.map +1 -0
- package/dist/result/core.js +103 -0
- package/dist/result/core.js.map +1 -0
- package/dist/result/index.d.ts +4 -0
- package/dist/result/index.d.ts.map +1 -0
- package/dist/result/index.js +4 -0
- package/dist/result/index.js.map +1 -0
- package/dist/result/throw.d.ts +4 -0
- package/dist/result/throw.d.ts.map +1 -0
- package/dist/result/throw.js +8 -0
- package/dist/result/throw.js.map +1 -0
- package/dist/validation.d.ts +126 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +240 -0
- package/dist/validation.js.map +1 -0
- package/dist/variant.d.ts +97 -0
- package/dist/variant.d.ts.map +1 -0
- package/dist/variant.js +102 -0
- package/dist/variant.js.map +1 -0
- package/docs/API.md +543 -0
- package/docs/GUIDE.md +739 -0
- package/docs/SEMANTICS.md +319 -0
- package/docs/laws/evidence.md +113 -0
- package/docs/laws/identity.md +126 -0
- package/docs/laws/match.md +163 -0
- package/docs/laws/option.md +100 -0
- package/docs/laws/protocol.md +152 -0
- package/docs/laws/result.md +124 -0
- package/docs/laws/validation.md +111 -0
- package/docs/laws/variant.md +251 -0
- package/package.json +87 -3
- package/src/evidence.ts +120 -0
- package/src/identity.ts +129 -0
- package/src/index.ts +54 -0
- package/src/internal/callback.ts +54 -0
- package/src/internal/promise-like.ts +32 -0
- package/src/internal/scalar.ts +43 -0
- package/src/option.ts +214 -0
- package/src/protocol.ts +174 -0
- package/src/result/capture.ts +209 -0
- package/src/result/core.ts +229 -0
- package/src/result/index.ts +3 -0
- package/src/result/throw.ts +13 -0
- package/src/validation.ts +491 -0
- package/src/variant.ts +363 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variant.d.ts","sourceRoot":"","sources":["../src/variant.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE5E,KAAK,QAAQ,GAAG,MAAM,GAAG;IACvB,QAAQ,CAAC,sBAAsB,EAAE,MAAM,CAAC;CACzC,CAAC;AAEF,KAAK,WAAW,CAAC,CAAC,IAAI,MAAM,GAAG;IAC7B,QAAQ,CAAC,sBAAsB,EAAE,SAAS,CAAC;IAC3C,QAAQ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");
|
|
3
|
+
/** Declares one nullary Variant case. */
|
|
4
|
+
export const unit = unitSpec;
|
|
5
|
+
/** Declares one Variant case carrying a payload of T. */
|
|
6
|
+
export const payload = () => payloadSpec;
|
|
7
|
+
const createFamily = (token, entries) => {
|
|
8
|
+
void token;
|
|
9
|
+
if (!Array.isArray(entries)) {
|
|
10
|
+
throw new TypeError("Variant case declarations must be arrays.");
|
|
11
|
+
}
|
|
12
|
+
const length = entries.length;
|
|
13
|
+
const kinds = new Map();
|
|
14
|
+
const constructors = Object.create(null);
|
|
15
|
+
for (let index = 0; index < length; index += 1) {
|
|
16
|
+
if (!Object.hasOwn(entries, index)) {
|
|
17
|
+
throw new TypeError("Variant case declarations must contain own case entries.");
|
|
18
|
+
}
|
|
19
|
+
const entry = entries[index];
|
|
20
|
+
if (!Array.isArray(entry) ||
|
|
21
|
+
entry.length !== 2 ||
|
|
22
|
+
!Object.hasOwn(entry, 0) ||
|
|
23
|
+
!Object.hasOwn(entry, 1)) {
|
|
24
|
+
throw new TypeError("Variant cases must be own [name, spec] pairs.");
|
|
25
|
+
}
|
|
26
|
+
const name = entry[0];
|
|
27
|
+
const spec = entry[1];
|
|
28
|
+
if (typeof name !== "string") {
|
|
29
|
+
throw new TypeError("Variant case names must be strings.");
|
|
30
|
+
}
|
|
31
|
+
if (kinds.has(name)) {
|
|
32
|
+
throw new TypeError("Variant case names must be unique.");
|
|
33
|
+
}
|
|
34
|
+
if (spec === unitSpec) {
|
|
35
|
+
kinds.set(name, "unit");
|
|
36
|
+
Object.defineProperty(constructors, name, {
|
|
37
|
+
configurable: false,
|
|
38
|
+
enumerable: true,
|
|
39
|
+
value: () => ({ tag: name }),
|
|
40
|
+
writable: false,
|
|
41
|
+
});
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (spec === payloadSpec) {
|
|
45
|
+
kinds.set(name, "payload");
|
|
46
|
+
Object.defineProperty(constructors, name, {
|
|
47
|
+
configurable: false,
|
|
48
|
+
enumerable: true,
|
|
49
|
+
value: (value) => ({ tag: name, value }),
|
|
50
|
+
writable: false,
|
|
51
|
+
});
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
throw new TypeError("Variant cases must be declared with Variant.unit or Variant.payload().");
|
|
55
|
+
}
|
|
56
|
+
Object.freeze(constructors);
|
|
57
|
+
const family = {
|
|
58
|
+
make: constructors,
|
|
59
|
+
match(value, handlers) {
|
|
60
|
+
if (value === null ||
|
|
61
|
+
(typeof value !== "object" && typeof value !== "function")) {
|
|
62
|
+
throw new TypeError("Variant values must be tagged objects.");
|
|
63
|
+
}
|
|
64
|
+
const tagDescriptor = Object.getOwnPropertyDescriptor(value, "tag");
|
|
65
|
+
const tag = tagDescriptor !== undefined && Object.hasOwn(tagDescriptor, "value")
|
|
66
|
+
? tagDescriptor.value
|
|
67
|
+
: undefined;
|
|
68
|
+
if (typeof tag !== "string") {
|
|
69
|
+
throw new TypeError("Variant values must provide an own data tag.");
|
|
70
|
+
}
|
|
71
|
+
const kind = kinds.get(tag);
|
|
72
|
+
if (kind === undefined) {
|
|
73
|
+
throw new TypeError("Variant value has an undeclared case tag.");
|
|
74
|
+
}
|
|
75
|
+
const descriptor = Object.getOwnPropertyDescriptor(handlers, tag);
|
|
76
|
+
const handler = descriptor !== undefined && Object.hasOwn(descriptor, "value")
|
|
77
|
+
? descriptor.value
|
|
78
|
+
: undefined;
|
|
79
|
+
if (typeof handler !== "function") {
|
|
80
|
+
throw new TypeError("Variant match handlers must provide an own function for every declared case.");
|
|
81
|
+
}
|
|
82
|
+
if (kind === "unit") {
|
|
83
|
+
return handler();
|
|
84
|
+
}
|
|
85
|
+
const valueDescriptor = Object.getOwnPropertyDescriptor(value, "value");
|
|
86
|
+
if (valueDescriptor === undefined || !Object.hasOwn(valueDescriptor, "value")) {
|
|
87
|
+
throw new TypeError("Variant payload cases must provide an own data value.");
|
|
88
|
+
}
|
|
89
|
+
return handler(valueDescriptor.value);
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
return Object.freeze(family);
|
|
93
|
+
};
|
|
94
|
+
/** Defines one named or declaration-owned closed Variant family. */
|
|
95
|
+
export const define = (token, entries, ..._closed) => createFamily(token, entries);
|
|
96
|
+
/** Closed labeled alternatives with correlated payloads and exhaustive elimination. */
|
|
97
|
+
export const Variant = {
|
|
98
|
+
define,
|
|
99
|
+
payload,
|
|
100
|
+
unit,
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=variant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variant.js","sourceRoot":"","sources":["../src/variant.ts"],"names":[],"mappings":"AA4LA,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,qBAAqB,CAAa,CAAC;AAC/D,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,wBAAwB,CAAyB,CAAC;AAEjF,yCAAyC;AACzC,MAAM,CAAC,MAAM,IAAI,GAAa,QAAQ,CAAC;AAEvC,yDAAyD;AACzD,MAAM,CAAC,MAAM,OAAO,GAAG,GAAsB,EAAE,CAAC,WAA6B,CAAC;AAI9E,MAAM,YAAY,GAAG,CACnB,KAAiB,EACjB,OAAgB,EAC0C,EAAE;IAC5D,KAAK,KAAK,CAAC;IAEX,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,SAAS,CAAC,2CAA2C,CAAC,CAAC;IACnE,CAAC;IAED,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC9B,MAAM,KAAK,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC7C,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAA4B,CAAC;IAEpE,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QAC/C,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE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CAAC;YAClE,MAAM,OAAO,GACX,UAAU,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC;gBAC5D,CAAC,CAAC,UAAU,CAAC,KAAK;gBAClB,CAAC,CAAC,SAAS,CAAC;YAEhB,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;gBAClC,MAAM,IAAI,SAAS,CACjB,8EAA8E,CAC/E,CAAC;YACJ,CAAC;YAED,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;gBACpB,OAAO,OAAO,EAA0D,CAAC;YAC3E,CAAC;YAED,MAAM,eAAe,GAAG,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YACxE,IAAI,eAAe,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC,EAAE,CAAC;gBAC9E,MAAM,IAAI,SAAS,CAAC,uDAAuD,CAAC,CAAC;YAC/E,CAAC;YAED,OAAO,OAAO,CAAC,eAAe,CAAC,KAAK,CAGnC,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC,CAAC;AAQF,oEAAoE;AACpE,MAAM,CAAC,MAAM,MAAM,GAAG,CAIpB,KAA+B,EAC/B,OAAgB,EAChB,GAAG,OAAgE,EACT,EAAE,CAC5D,YAAY,CAAsB,KAAmB,EAAE,OAAO,CAAC,CAAC;AAQlE,uFAAuF;AACvF,MAAM,CAAC,MAAM,OAAO,GAAkB;IACpC,MAAM;IACN,OAAO;IACP,IAAI;CACL,CAAC"}
|
package/docs/API.md
ADDED
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
# Selaws API
|
|
2
|
+
|
|
3
|
+
This document is the public-surface index. For design guidance and complete
|
|
4
|
+
examples, see [GUIDE.md](./GUIDE.md). Normative behavior is defined in
|
|
5
|
+
[SEMANTICS.md](./SEMANTICS.md) and the owner/shared laws under
|
|
6
|
+
[docs/laws](./laws/).
|
|
7
|
+
|
|
8
|
+
## Root: `selaws`
|
|
9
|
+
|
|
10
|
+
The root exposes owner facades and principal carrier types so mixed-owner
|
|
11
|
+
application code can keep ownership visible.
|
|
12
|
+
|
|
13
|
+
Runtime values:
|
|
14
|
+
|
|
15
|
+
```text
|
|
16
|
+
identity
|
|
17
|
+
evidence
|
|
18
|
+
Protocol
|
|
19
|
+
Variant
|
|
20
|
+
Option
|
|
21
|
+
Validation
|
|
22
|
+
Result
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Principal types:
|
|
26
|
+
|
|
27
|
+
```text
|
|
28
|
+
Scalar
|
|
29
|
+
Identity
|
|
30
|
+
Evidence
|
|
31
|
+
Protocol
|
|
32
|
+
Variant
|
|
33
|
+
|
|
34
|
+
Option
|
|
35
|
+
Some
|
|
36
|
+
None
|
|
37
|
+
OptionValue
|
|
38
|
+
|
|
39
|
+
Validation
|
|
40
|
+
Valid
|
|
41
|
+
Invalid
|
|
42
|
+
ValidationIssues
|
|
43
|
+
ValidationValue
|
|
44
|
+
ValidationError
|
|
45
|
+
|
|
46
|
+
Result
|
|
47
|
+
Ok
|
|
48
|
+
Err
|
|
49
|
+
AsyncResult
|
|
50
|
+
ResultValue
|
|
51
|
+
ResultError
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Generic operation names such as `map`, `match`, `define`, and `Next` are
|
|
55
|
+
not exported as root-level functions. They belong to focused subpaths or to the
|
|
56
|
+
corresponding facade.
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import {
|
|
60
|
+
Option,
|
|
61
|
+
Protocol,
|
|
62
|
+
Result,
|
|
63
|
+
Validation,
|
|
64
|
+
Variant,
|
|
65
|
+
} from "selaws";
|
|
66
|
+
|
|
67
|
+
const maybe = Option.some(1);
|
|
68
|
+
const success = Result.ok(1);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Result capture helpers such as `attempt` and `wrap` live on
|
|
72
|
+
`selaws/result`; they are explicit JavaScript control-boundary operations, not
|
|
73
|
+
members of the root Result data facade.
|
|
74
|
+
|
|
75
|
+
## Shared Match law
|
|
76
|
+
|
|
77
|
+
Match is a first-class shared elimination law, not a public namespace or
|
|
78
|
+
dispatcher. There is no root `Match` export and no `selaws/match` entry point.
|
|
79
|
+
|
|
80
|
+
The public realizations stay on the semantic owner that defines the branch
|
|
81
|
+
universe:
|
|
82
|
+
|
|
83
|
+
```text
|
|
84
|
+
Option.match
|
|
85
|
+
Result.match
|
|
86
|
+
Validation.match
|
|
87
|
+
VariantFamily.match
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
All four require typed total handling of the owner's branches, invoke exactly
|
|
91
|
+
one selected handler without a library-defined `this` receiver, leave
|
|
92
|
+
unselected handlers untouched, and preserve the selected handler's ordinary
|
|
93
|
+
return, throw, or Promise completion.
|
|
94
|
+
|
|
95
|
+
The owner remains responsible for branch meaning and any extra runtime
|
|
96
|
+
validation. Variant therefore retains family-specific runtime representation
|
|
97
|
+
checks that fixed structural carriers do not share.
|
|
98
|
+
|
|
99
|
+
See [the Match law](./laws/match.md) for the normative cross-owner contract.
|
|
100
|
+
|
|
101
|
+
## `selaws/identity`
|
|
102
|
+
|
|
103
|
+
Exports:
|
|
104
|
+
|
|
105
|
+
```text
|
|
106
|
+
Scalar
|
|
107
|
+
Identity
|
|
108
|
+
defineIdentity
|
|
109
|
+
identity
|
|
110
|
+
|
|
111
|
+
identity.string
|
|
112
|
+
identity.number
|
|
113
|
+
identity.bigint
|
|
114
|
+
identity.boolean
|
|
115
|
+
identity.symbol
|
|
116
|
+
identity.define
|
|
117
|
+
identity.Value
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Named formation
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
const UserId = identity.string("UserId");
|
|
124
|
+
type UserId = identity.Value<typeof UserId>;
|
|
125
|
+
|
|
126
|
+
const id = UserId("u_1");
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Each carrier factory accepts either a concrete string name or a narrow symbol.
|
|
130
|
+
Without a predicate, a correctly typed carrier is formed directly and unknown
|
|
131
|
+
input is checked for the correct scalar kind. With a predicate, formation can
|
|
132
|
+
return `undefined`.
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
const Port = identity.number(
|
|
136
|
+
"Port",
|
|
137
|
+
(value) =>
|
|
138
|
+
Number.isInteger(value) &&
|
|
139
|
+
value >= 0 &&
|
|
140
|
+
value <= 65_535,
|
|
141
|
+
);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
String names define package-copy-stable structural identity. A bound symbol
|
|
145
|
+
defines declaration-owned identity.
|
|
146
|
+
|
|
147
|
+
### `defineIdentity`
|
|
148
|
+
|
|
149
|
+
`defineIdentity<T>()(token, build)` supplies a private `mint` function to the
|
|
150
|
+
declaration callback. Use it when the declaring module needs a custom formation
|
|
151
|
+
API rather than one scalar factory function.
|
|
152
|
+
|
|
153
|
+
## `selaws/evidence`
|
|
154
|
+
|
|
155
|
+
Exports:
|
|
156
|
+
|
|
157
|
+
```text
|
|
158
|
+
Scalar
|
|
159
|
+
Evidence
|
|
160
|
+
defineFact
|
|
161
|
+
evidence
|
|
162
|
+
|
|
163
|
+
evidence.string
|
|
164
|
+
evidence.number
|
|
165
|
+
evidence.bigint
|
|
166
|
+
evidence.boolean
|
|
167
|
+
evidence.symbol
|
|
168
|
+
evidence.define
|
|
169
|
+
evidence.Proven
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Every Evidence factory requires a predicate.
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
const NonEmpty = evidence.string(
|
|
176
|
+
"NonEmpty",
|
|
177
|
+
(value) => value.length > 0,
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const checked = NonEmpty(value);
|
|
181
|
+
// proven value | undefined
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Successful establishment preserves identity and previously established evidence
|
|
185
|
+
on the same scalar.
|
|
186
|
+
|
|
187
|
+
`evidence.Proven<typeof Fact, Value>` applies a fact declaration's evidence
|
|
188
|
+
type to an already compatible scalar type.
|
|
189
|
+
|
|
190
|
+
`defineFact<T>()(token, build)` is the declaration-owned form. Its callback
|
|
191
|
+
receives the private establishment function.
|
|
192
|
+
|
|
193
|
+
## `selaws/protocol`
|
|
194
|
+
|
|
195
|
+
Types:
|
|
196
|
+
|
|
197
|
+
```text
|
|
198
|
+
State
|
|
199
|
+
Label
|
|
200
|
+
Transition
|
|
201
|
+
States
|
|
202
|
+
Labels
|
|
203
|
+
Next
|
|
204
|
+
Protocol
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Runtime exports:
|
|
208
|
+
|
|
209
|
+
```text
|
|
210
|
+
define
|
|
211
|
+
Protocol
|
|
212
|
+
Protocol.define
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Define a relation
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
const transitions = [
|
|
219
|
+
["pending", "pay", "paid"],
|
|
220
|
+
["pending", "cancel", "cancelled"],
|
|
221
|
+
] as const;
|
|
222
|
+
|
|
223
|
+
const OrderProtocol =
|
|
224
|
+
Protocol.define(transitions);
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
`Protocol.define` snapshots a readonly relation of readonly
|
|
228
|
+
`[from, label, to]` triples into an immutable membership relation. Typed
|
|
229
|
+
declarations reject directly mutable outer arrays and triples. A readonly view
|
|
230
|
+
over a separately mutable alias is still subject to the TypeScript trust model
|
|
231
|
+
described in [SEMANTICS.md](./SEMANTICS.md).
|
|
232
|
+
|
|
233
|
+
### Static projections
|
|
234
|
+
|
|
235
|
+
```ts
|
|
236
|
+
type State =
|
|
237
|
+
States<typeof transitions>;
|
|
238
|
+
|
|
239
|
+
type Label =
|
|
240
|
+
Labels<typeof transitions>;
|
|
241
|
+
|
|
242
|
+
type AfterPay =
|
|
243
|
+
Next<
|
|
244
|
+
typeof transitions,
|
|
245
|
+
"pending",
|
|
246
|
+
"pay"
|
|
247
|
+
>;
|
|
248
|
+
// "paid"
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
`States` contains source and target identifiers that occur in the declaration.
|
|
252
|
+
`Labels` contains declared labels. `Next` projects the targets statically
|
|
253
|
+
admissible for a source/label pair.
|
|
254
|
+
|
|
255
|
+
### Runtime membership
|
|
256
|
+
|
|
257
|
+
```ts
|
|
258
|
+
OrderProtocol.allows(
|
|
259
|
+
"pending",
|
|
260
|
+
"pay",
|
|
261
|
+
"paid",
|
|
262
|
+
);
|
|
263
|
+
// boolean
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
`allows` tests one concrete triple. It returns a boolean rather than a
|
|
267
|
+
target-narrowing type predicate. The relation may be nondeterministic.
|
|
268
|
+
|
|
269
|
+
Protocol does not store current state or perform a transition.
|
|
270
|
+
|
|
271
|
+
## `selaws/variant`
|
|
272
|
+
|
|
273
|
+
Type:
|
|
274
|
+
|
|
275
|
+
```text
|
|
276
|
+
Variant
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
Runtime exports and facade members:
|
|
280
|
+
|
|
281
|
+
```text
|
|
282
|
+
define
|
|
283
|
+
payload
|
|
284
|
+
unit
|
|
285
|
+
Variant
|
|
286
|
+
|
|
287
|
+
Variant.define
|
|
288
|
+
Variant.payload
|
|
289
|
+
Variant.unit
|
|
290
|
+
Variant.Value
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Declare a family
|
|
294
|
+
|
|
295
|
+
```ts
|
|
296
|
+
const Message = Variant.define("Message", [
|
|
297
|
+
["quit", Variant.unit],
|
|
298
|
+
["write", Variant.payload<string>()],
|
|
299
|
+
]);
|
|
300
|
+
|
|
301
|
+
type Message =
|
|
302
|
+
Variant.Value<typeof Message>;
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
`Variant.define` accepts one finite readonly tuple of `[caseName, caseSpec]`
|
|
306
|
+
entries, snapshots that tuple, and returns an immutable family with:
|
|
307
|
+
|
|
308
|
+
```text
|
|
309
|
+
family.make.<case>(...)
|
|
310
|
+
family.match(value, handlers)
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
`Variant.unit` declares a nullary case.
|
|
314
|
+
`Variant.payload<T>()` declares a case carrying exactly one typed payload.
|
|
315
|
+
Case names must be concrete string literals. The outer declaration tuple and
|
|
316
|
+
each case-entry pair must be readonly. Duplicate names and broad-length or
|
|
317
|
+
union declaration lists are outside the typed grammar.
|
|
318
|
+
|
|
319
|
+
`Variant.Value<Family>` extracts the complete tagged value union. The
|
|
320
|
+
top-level type `Variant<Family>` is the equivalent carrier type.
|
|
321
|
+
|
|
322
|
+
### Construct and eliminate
|
|
323
|
+
|
|
324
|
+
```ts
|
|
325
|
+
const value =
|
|
326
|
+
Message.make.write("hello");
|
|
327
|
+
|
|
328
|
+
const length = Message.match(value, {
|
|
329
|
+
quit: () => 0,
|
|
330
|
+
write: (text) => text.length,
|
|
331
|
+
});
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Typed `match` requires handlers for the complete family. At runtime, the
|
|
335
|
+
Variant value must carry its tag as an own data property; payload cases must
|
|
336
|
+
also carry their payload as an own data `value` property. The selected tag must
|
|
337
|
+
belong to the declaration, and the selected handler must be an own function
|
|
338
|
+
property.
|
|
339
|
+
|
|
340
|
+
A string family token defines named package-copy-stable identity. A bound
|
|
341
|
+
symbol defines declaration-owned family identity.
|
|
342
|
+
|
|
343
|
+
## `selaws/option`
|
|
344
|
+
|
|
345
|
+
Types:
|
|
346
|
+
|
|
347
|
+
```text
|
|
348
|
+
Some
|
|
349
|
+
None
|
|
350
|
+
Option
|
|
351
|
+
OptionValue
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
Runtime exports and facade members:
|
|
355
|
+
|
|
356
|
+
```text
|
|
357
|
+
some
|
|
358
|
+
none
|
|
359
|
+
isSome
|
|
360
|
+
isNone
|
|
361
|
+
match
|
|
362
|
+
map
|
|
363
|
+
andThen
|
|
364
|
+
orElse
|
|
365
|
+
flatten
|
|
366
|
+
filter
|
|
367
|
+
inspect
|
|
368
|
+
unwrapOr
|
|
369
|
+
unwrapOrElse
|
|
370
|
+
all
|
|
371
|
+
fromUndefined
|
|
372
|
+
fromNullable
|
|
373
|
+
toUndefined
|
|
374
|
+
toNullable
|
|
375
|
+
Option
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
Operation groups:
|
|
379
|
+
|
|
380
|
+
| Group | Operations | Meaning |
|
|
381
|
+
| --- | --- | --- |
|
|
382
|
+
| Formation | `some`, `none`, `fromUndefined`, `fromNullable` | create explicit presence/absence |
|
|
383
|
+
| Narrowing/elimination | `isSome`, `isNone`, `match` | inspect the branch |
|
|
384
|
+
| Composition | `map`, `andThen`, `orElse`, `flatten`, `filter` | transform while preserving Option meaning |
|
|
385
|
+
| Observation/fallback | `inspect`, `unwrapOr`, `unwrapOrElse` | observe or leave Option |
|
|
386
|
+
| Collection | `all` | combine already-materialized Options |
|
|
387
|
+
| JS boundary | `toUndefined`, `toNullable` | project None to a conventional JS sentinel |
|
|
388
|
+
|
|
389
|
+
`OptionValue<O>` extracts the Some payload type.
|
|
390
|
+
|
|
391
|
+
`some(undefined)` is Some; `fromUndefined(undefined)` is None.
|
|
392
|
+
|
|
393
|
+
`inspect` is synchronous and returns the original Option.
|
|
394
|
+
|
|
395
|
+
`Option.all` preserves finite tuple positions. Typed input arrays must be
|
|
396
|
+
readonly; broad `readonly Option<T>[]` inputs remain valid.
|
|
397
|
+
|
|
398
|
+
## `selaws/validation`
|
|
399
|
+
|
|
400
|
+
Types:
|
|
401
|
+
|
|
402
|
+
```text
|
|
403
|
+
Valid
|
|
404
|
+
Invalid
|
|
405
|
+
Validation
|
|
406
|
+
ValidationIssues
|
|
407
|
+
ValidationValue
|
|
408
|
+
ValidationError
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
Runtime exports and facade members:
|
|
412
|
+
|
|
413
|
+
```text
|
|
414
|
+
valid
|
|
415
|
+
invalid
|
|
416
|
+
isValid
|
|
417
|
+
isInvalid
|
|
418
|
+
match
|
|
419
|
+
map
|
|
420
|
+
mapError
|
|
421
|
+
inspect
|
|
422
|
+
inspectErrors
|
|
423
|
+
unwrapOr
|
|
424
|
+
unwrapOrElse
|
|
425
|
+
all
|
|
426
|
+
struct
|
|
427
|
+
fromOption
|
|
428
|
+
fromResult
|
|
429
|
+
Validation
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
Operation groups:
|
|
433
|
+
|
|
434
|
+
| Group | Operations | Meaning |
|
|
435
|
+
| --- | --- | --- |
|
|
436
|
+
| Formation | `valid`, `invalid` | construct valid data or non-empty issues |
|
|
437
|
+
| Narrowing/elimination | `isValid`, `isInvalid`, `match` | inspect the branch |
|
|
438
|
+
| Mapping | `map`, `mapError` | transform values or every issue |
|
|
439
|
+
| Observation/fallback | `inspect`, `inspectErrors`, `unwrapOr`, `unwrapOrElse` | observe or leave Validation |
|
|
440
|
+
| Accumulation | `all`, `struct` | combine independent available checks |
|
|
441
|
+
| Conversion | `fromOption`, `fromResult` | introduce Validation meaning at an explicit boundary |
|
|
442
|
+
|
|
443
|
+
`ValidationIssues<E>` is a non-empty readonly tuple type.
|
|
444
|
+
|
|
445
|
+
`ValidationValue<V>` extracts the Valid payload.
|
|
446
|
+
`ValidationError<V>` extracts one issue type.
|
|
447
|
+
|
|
448
|
+
`Validation.all` preserves finite tuple positions. Typed input arrays must be
|
|
449
|
+
readonly; broad readonly Validation arrays remain valid. `Validation.struct` accepts one
|
|
450
|
+
finite readonly tuple of readonly `[key, Validation]` entries, preserves those
|
|
451
|
+
string or symbol keys, and accumulates issues in entry order. Directly mutable
|
|
452
|
+
outer or inner tuples, duplicate keys, broad keys, and broad-length declarations
|
|
453
|
+
are outside the typed grammar. Readonly views over separately mutable aliases
|
|
454
|
+
remain subject to the package TypeScript trust model.
|
|
455
|
+
|
|
456
|
+
`Validation.fromResult` turns one Err value into one Validation issue even
|
|
457
|
+
when that Err value is itself an array.
|
|
458
|
+
|
|
459
|
+
## `selaws/result`
|
|
460
|
+
|
|
461
|
+
Types:
|
|
462
|
+
|
|
463
|
+
```text
|
|
464
|
+
Ok
|
|
465
|
+
Err
|
|
466
|
+
Result
|
|
467
|
+
AsyncResult
|
|
468
|
+
ResultValue
|
|
469
|
+
ResultError
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
### Result data algebra
|
|
473
|
+
|
|
474
|
+
Runtime exports and Result facade members:
|
|
475
|
+
|
|
476
|
+
```text
|
|
477
|
+
ok
|
|
478
|
+
err
|
|
479
|
+
isOk
|
|
480
|
+
isErr
|
|
481
|
+
match
|
|
482
|
+
map
|
|
483
|
+
mapError
|
|
484
|
+
andThen
|
|
485
|
+
orElse
|
|
486
|
+
flatten
|
|
487
|
+
inspect
|
|
488
|
+
inspectError
|
|
489
|
+
unwrapOr
|
|
490
|
+
unwrapOrElse
|
|
491
|
+
all
|
|
492
|
+
fromOption
|
|
493
|
+
fromValidation
|
|
494
|
+
Result
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
Operation groups:
|
|
498
|
+
|
|
499
|
+
| Group | Operations | Meaning |
|
|
500
|
+
| --- | --- | --- |
|
|
501
|
+
| Formation | `ok`, `err` | construct recoverable success/error data |
|
|
502
|
+
| Narrowing/elimination | `isOk`, `isErr`, `match` | inspect the branch |
|
|
503
|
+
| Composition | `map`, `mapError`, `andThen`, `orElse`, `flatten` | transform or sequence Result data |
|
|
504
|
+
| Observation/fallback | `inspect`, `inspectError`, `unwrapOr`, `unwrapOrElse` | observe or leave Result |
|
|
505
|
+
| Collection | `all` | combine already-materialized Results, stopping at the first Err |
|
|
506
|
+
| Conversion | `fromOption`, `fromValidation` | introduce Result meaning at an explicit boundary |
|
|
507
|
+
|
|
508
|
+
`ResultValue<R>` extracts the Ok payload.
|
|
509
|
+
`ResultError<R>` extracts the Err payload.
|
|
510
|
+
|
|
511
|
+
`Result.all` traverses in input order and returns the first Err object itself.
|
|
512
|
+
Typed input arrays must be readonly; broad readonly Result arrays remain valid.
|
|
513
|
+
|
|
514
|
+
`Result.fromValidation` carries the entire non-empty issue collection as one
|
|
515
|
+
Err value.
|
|
516
|
+
|
|
517
|
+
### JavaScript control boundaries
|
|
518
|
+
|
|
519
|
+
Focused-only runtime exports:
|
|
520
|
+
|
|
521
|
+
```text
|
|
522
|
+
attempt
|
|
523
|
+
attemptAsync
|
|
524
|
+
wrap
|
|
525
|
+
wrapAsync
|
|
526
|
+
orThrow
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
`attempt(read, mapThrown)` captures one synchronous invocation boundary.
|
|
530
|
+
Thrown values become Err through `mapThrown`. A Promise-like return violates
|
|
531
|
+
the synchronous contract and raises `TypeError`.
|
|
532
|
+
|
|
533
|
+
`attemptAsync(read, mapThrown)` captures invocation throws and Promise
|
|
534
|
+
rejection into `Promise<Result<...>>`.
|
|
535
|
+
|
|
536
|
+
`wrap` and `wrapAsync` produce reusable wrapped functions while preserving
|
|
537
|
+
arguments and `this`.
|
|
538
|
+
|
|
539
|
+
`orThrow(result, mapErrorToThrowable)` returns the Ok value or explicitly maps
|
|
540
|
+
Err back to a thrown JavaScript value.
|
|
541
|
+
|
|
542
|
+
Promise remains the async scheduling owner; these helpers do not introduce an
|
|
543
|
+
async Result runtime.
|