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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Selaws contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,356 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Selaws
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Independent semantic primitives for TypeScript with explicit laws.
|
|
4
|
+
|
|
5
|
+
Selaws gives common domain meanings small, separate owners instead of placing
|
|
6
|
+
them behind one framework abstraction. You can introduce nominal scalar
|
|
7
|
+
identity, establish stable facts, declare admissible transitions, define closed
|
|
8
|
+
variants, model optional values, accumulate independent validation issues, and
|
|
9
|
+
carry recoverable failures without changing ordinary JavaScript control flow.
|
|
10
|
+
|
|
11
|
+
| Owner | Question it answers | Typical code |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| Identity | What scalar value is this? | `UserId("user_1")` |
|
|
14
|
+
| Evidence | What stable fact is established about this scalar? | `NonEmpty(userId)` |
|
|
15
|
+
| Protocol | Which labeled transition is admissible? | `OrderProtocol.allows("pending", "pay", "paid")` |
|
|
16
|
+
| Variant | Which closed labeled alternative is this? | `Message.make.write("hello")` |
|
|
17
|
+
| Option | Is a value present? | `Option.fromUndefined(value)` |
|
|
18
|
+
| Validation | Which independent checks have issues? | `Validation.struct([["name", check], ...])` |
|
|
19
|
+
| Result | Did a recoverable computation succeed? | `Result.ok(value)` / `Result.err(error)` |
|
|
20
|
+
|
|
21
|
+
Each owner has its own laws and focused import path. The package does not add a
|
|
22
|
+
workflow runtime, async carrier, schema decoder, or application state store.
|
|
23
|
+
|
|
24
|
+
Match is a first-class shared elimination law across the sum-like owners, not a
|
|
25
|
+
separate owner or namespace:
|
|
26
|
+
|
|
27
|
+
```text
|
|
28
|
+
Option.match
|
|
29
|
+
Result.match
|
|
30
|
+
Validation.match
|
|
31
|
+
VariantFamily.match
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Each owning surface supplies the branch universe and payload meaning. Match
|
|
35
|
+
requires total typed handling, invokes exactly one selected handler without a
|
|
36
|
+
library-defined `this` receiver, and preserves ordinary return, throw, and
|
|
37
|
+
Promise completion.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
npm install selaws
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Selaws is ESM, emits ES2022 JavaScript, has zero runtime dependencies, and
|
|
46
|
+
targets the repository's pinned TypeScript 7 toolchain. Older TypeScript
|
|
47
|
+
compilers are outside the compatibility contract.
|
|
48
|
+
|
|
49
|
+
## Give scalar values domain identity
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { identity } from "selaws/identity";
|
|
53
|
+
|
|
54
|
+
export const UserId = identity.string("UserId");
|
|
55
|
+
export type UserId = identity.Value<typeof UserId>;
|
|
56
|
+
|
|
57
|
+
export const OrderId = identity.string("OrderId");
|
|
58
|
+
export type OrderId = identity.Value<typeof OrderId>;
|
|
59
|
+
|
|
60
|
+
function loadUser(id: UserId) {}
|
|
61
|
+
|
|
62
|
+
loadUser(UserId("user_1"));
|
|
63
|
+
// loadUser(OrderId("order_1")); // type error
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Identity formation returns the original JavaScript primitive. The type records
|
|
67
|
+
which domain identity the scalar carries.
|
|
68
|
+
|
|
69
|
+
Use a checked identity when formation itself owns a local condition:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
const Port = identity.number(
|
|
73
|
+
"Port",
|
|
74
|
+
(value) =>
|
|
75
|
+
Number.isInteger(value) &&
|
|
76
|
+
value >= 0 &&
|
|
77
|
+
value <= 65_535,
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const port = Port(input);
|
|
81
|
+
// Port | undefined
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
String names provide package-copy-stable named identity. A bound `Symbol`
|
|
85
|
+
provides declaration-owned identity when one declaration must control formation.
|
|
86
|
+
|
|
87
|
+
## Establish stable facts without replacing identity
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import { evidence } from "selaws/evidence";
|
|
91
|
+
import type { UserId } from "./user-id.js";
|
|
92
|
+
|
|
93
|
+
const NonEmpty = evidence.string(
|
|
94
|
+
"NonEmpty",
|
|
95
|
+
(value) => value.length > 0,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
declare const id: UserId;
|
|
99
|
+
|
|
100
|
+
const checked = NonEmpty(id);
|
|
101
|
+
|
|
102
|
+
if (checked !== undefined) {
|
|
103
|
+
const stillUserId: UserId = checked;
|
|
104
|
+
|
|
105
|
+
type NonEmptyUserId =
|
|
106
|
+
evidence.Proven<typeof NonEmpty, UserId>;
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Evidence describes a stable fact about the same immutable scalar. Independent
|
|
111
|
+
facts can accumulate while existing identity remains present.
|
|
112
|
+
|
|
113
|
+
## Declare transition admissibility
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { Protocol, type Next } from "selaws/protocol";
|
|
117
|
+
|
|
118
|
+
const orderTransitions = [
|
|
119
|
+
["pending", "pay", "paid"],
|
|
120
|
+
["pending", "cancel", "cancelled"],
|
|
121
|
+
["paid", "ship", "shipped"],
|
|
122
|
+
] as const;
|
|
123
|
+
|
|
124
|
+
const OrderProtocol = Protocol.define(orderTransitions);
|
|
125
|
+
|
|
126
|
+
type PendingPayNext =
|
|
127
|
+
Next<typeof orderTransitions, "pending", "pay">;
|
|
128
|
+
// "paid"
|
|
129
|
+
|
|
130
|
+
OrderProtocol.allows("pending", "pay", "paid"); // true
|
|
131
|
+
OrderProtocol.allows("pending", "pay", "cancelled"); // false
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Protocol owns the relation of admissible `[from, label, to]` triples. It does
|
|
135
|
+
not own the current state, choose a target, dispatch an event, perform effects,
|
|
136
|
+
persist state, or provide concurrency control.
|
|
137
|
+
|
|
138
|
+
The relation may be nondeterministic: one `(from, label)` pair may admit more
|
|
139
|
+
than one target.
|
|
140
|
+
|
|
141
|
+
## Define a closed labeled data vocabulary
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
import { Variant } from "selaws/variant";
|
|
145
|
+
|
|
146
|
+
const Message = Variant.define("Message", [
|
|
147
|
+
["quit", Variant.unit],
|
|
148
|
+
["write", Variant.payload<string>()],
|
|
149
|
+
["move", Variant.payload<Readonly<{ x: number; y: number }>>()],
|
|
150
|
+
]);
|
|
151
|
+
|
|
152
|
+
type Message = Variant.Value<typeof Message>;
|
|
153
|
+
|
|
154
|
+
const message: Message = Message.make.write("hello");
|
|
155
|
+
|
|
156
|
+
const size = Message.match(message, {
|
|
157
|
+
quit: () => 0,
|
|
158
|
+
write: (text) => text.length,
|
|
159
|
+
move: ({ x, y }) => x + y,
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
The finite case-entry tuple is the complete Variant family. `make.<case>`
|
|
164
|
+
preserves the correlation between a tag and its payload. `match` is exhaustive over the
|
|
165
|
+
family in typed TypeScript, so adding a case exposes every family-level match
|
|
166
|
+
that must be updated.
|
|
167
|
+
|
|
168
|
+
Variant values remain ordinary tagged JavaScript objects:
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
Message.make.quit();
|
|
172
|
+
// { tag: "quit" }
|
|
173
|
+
|
|
174
|
+
Message.make.write("hello");
|
|
175
|
+
// { tag: "write", value: "hello" }
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Represent reasonless absence with Option
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
import { Option } from "selaws/option";
|
|
182
|
+
|
|
183
|
+
const nickname = Option.fromUndefined(row.nickname);
|
|
184
|
+
|
|
185
|
+
const displayName = Option.unwrapOr(
|
|
186
|
+
nickname,
|
|
187
|
+
"Anonymous",
|
|
188
|
+
);
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Use Option when the whole meaning of the empty branch is “no value”. If absence
|
|
192
|
+
needs a reason, that reason belongs in Result or in a domain-specific Variant.
|
|
193
|
+
|
|
194
|
+
`some(undefined)` is still present. `Option.fromUndefined(undefined)` is
|
|
195
|
+
absent. The distinction is explicit.
|
|
196
|
+
|
|
197
|
+
## Accumulate independent issues with Validation
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
import { Validation } from "selaws/validation";
|
|
201
|
+
|
|
202
|
+
const input = Validation.struct([
|
|
203
|
+
["name", validateName(raw.name)],
|
|
204
|
+
["email", validateEmail(raw.email)],
|
|
205
|
+
]);
|
|
206
|
+
|
|
207
|
+
if (!input.valid) {
|
|
208
|
+
console.log(input.errors);
|
|
209
|
+
// non-empty issue collection
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Validation combines checks that are already independently available. It keeps
|
|
214
|
+
all issues in deterministic input order instead of stopping at the first
|
|
215
|
+
failure.
|
|
216
|
+
|
|
217
|
+
## Sequence recoverable work with Result
|
|
218
|
+
|
|
219
|
+
```ts
|
|
220
|
+
import { Result, type Result as ResultValue } from "selaws/result";
|
|
221
|
+
|
|
222
|
+
const parsePort = (
|
|
223
|
+
text: string,
|
|
224
|
+
): ResultValue<number, "invalid-port"> => {
|
|
225
|
+
const value = Number(text);
|
|
226
|
+
|
|
227
|
+
return Number.isInteger(value) && value > 0 && value <= 65_535
|
|
228
|
+
? Result.ok(value)
|
|
229
|
+
: Result.err("invalid-port");
|
|
230
|
+
};
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Result represents one recoverable success or error. Dependent composition is
|
|
234
|
+
fail-fast:
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
const user = await loadUser(userId);
|
|
238
|
+
|
|
239
|
+
if (!user.ok) {
|
|
240
|
+
return user;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return loadAccount(user.value.accountId);
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
Selaws does not hide that control flow behind a generator or async Result
|
|
247
|
+
runtime.
|
|
248
|
+
|
|
249
|
+
## Move between owners at explicit boundaries
|
|
250
|
+
|
|
251
|
+
A common application path is to accumulate independent input issues first, then
|
|
252
|
+
enter dependent Result-based work:
|
|
253
|
+
|
|
254
|
+
```ts
|
|
255
|
+
const input = Validation.struct([
|
|
256
|
+
["userId", validateUserId(raw.userId)],
|
|
257
|
+
["email", validateEmail(raw.email)],
|
|
258
|
+
]);
|
|
259
|
+
|
|
260
|
+
const ready = Result.fromValidation(input);
|
|
261
|
+
|
|
262
|
+
if (!ready.ok) {
|
|
263
|
+
return ready;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const user = await loadUser(ready.value.userId);
|
|
267
|
+
|
|
268
|
+
if (!user.ok) {
|
|
269
|
+
return user;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return saveUser(user.value, ready.value.email);
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
A Result error can itself use a Variant-owned domain vocabulary:
|
|
276
|
+
|
|
277
|
+
```ts
|
|
278
|
+
const LoadUserError = Variant.define("LoadUserError", [
|
|
279
|
+
["notFound", Variant.payload<{ id: string }>()],
|
|
280
|
+
["storage", Variant.payload<{ cause: unknown }>()],
|
|
281
|
+
]);
|
|
282
|
+
|
|
283
|
+
type LoadUserError = Variant.Value<typeof LoadUserError>;
|
|
284
|
+
|
|
285
|
+
type LoadUserResult =
|
|
286
|
+
ResultValue<User, LoadUserError>;
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
Result owns recoverable success/failure. Variant owns which error alternative
|
|
290
|
+
exists and which payload belongs to it. Neither owner absorbs the other's law.
|
|
291
|
+
|
|
292
|
+
## Keep JavaScript completion and Promise visible
|
|
293
|
+
|
|
294
|
+
Result capture helpers mark explicit boundaries around throwing APIs:
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
import { attempt } from "selaws/result";
|
|
298
|
+
|
|
299
|
+
const parsed = attempt(
|
|
300
|
+
() => JSON.parse(text) as unknown,
|
|
301
|
+
(cause) => ({
|
|
302
|
+
kind: "invalid-json" as const,
|
|
303
|
+
cause,
|
|
304
|
+
}),
|
|
305
|
+
);
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
`attempt` and `attemptAsync` translate explicit abrupt boundaries into Result
|
|
309
|
+
data. `orThrow` performs the reverse boundary when an Err should become a
|
|
310
|
+
thrown JavaScript value.
|
|
311
|
+
|
|
312
|
+
Promise remains the async owner:
|
|
313
|
+
|
|
314
|
+
```ts
|
|
315
|
+
Promise<ResultValue<T, E>>
|
|
316
|
+
Promise<Option<T>>
|
|
317
|
+
Promise<Validation<T, E>>
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## Imports
|
|
321
|
+
|
|
322
|
+
Use focused entry points when one owner dominates a module:
|
|
323
|
+
|
|
324
|
+
```text
|
|
325
|
+
selaws/identity
|
|
326
|
+
selaws/evidence
|
|
327
|
+
selaws/protocol
|
|
328
|
+
selaws/variant
|
|
329
|
+
selaws/option
|
|
330
|
+
selaws/validation
|
|
331
|
+
selaws/result
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Use the root facades when several owners are intentionally composed at one
|
|
335
|
+
application boundary:
|
|
336
|
+
|
|
337
|
+
```ts
|
|
338
|
+
import {
|
|
339
|
+
Option,
|
|
340
|
+
Protocol,
|
|
341
|
+
Result,
|
|
342
|
+
Validation,
|
|
343
|
+
Variant,
|
|
344
|
+
} from "selaws";
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
Generic helper names such as `map`, `match`, `define`, and `Next` stay on
|
|
348
|
+
focused subpaths so the semantic owner remains visible. Match is shared as a
|
|
349
|
+
law rather than centralized as a dispatcher.
|
|
350
|
+
|
|
351
|
+
## Documentation
|
|
352
|
+
|
|
353
|
+
- [Guide](./docs/GUIDE.md) — practical patterns and owner composition.
|
|
354
|
+
- [API](./docs/API.md) — public exports and operation groups.
|
|
355
|
+
- [Semantics](./docs/SEMANTICS.md) — package-wide normative ownership and shared laws.
|
|
356
|
+
- [Laws](./docs/laws/) — normative owner laws and shared laws such as [Match](./docs/laws/match.md).
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type NarrowSymbolSet, type Scalar, type SingleName, type SingleSymbol, type Token } from "./internal/scalar.js";
|
|
2
|
+
export type { Scalar } from "./internal/scalar.js";
|
|
3
|
+
type EvidenceMarker = {
|
|
4
|
+
readonly "~selaws.evidence": true;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* A stable fact established about a scalar value.
|
|
8
|
+
*
|
|
9
|
+
* Independent fact tokens occupy independent phantom properties, so evidence
|
|
10
|
+
* composes while preserving existing identity and evidence on the same scalar.
|
|
11
|
+
*/
|
|
12
|
+
export type Evidence<T extends Scalar, Fact extends symbol> = [Fact] extends [never] ? never : [Fact] extends [NarrowSymbolSet<Fact>] ? T & {
|
|
13
|
+
readonly [Key in Fact]: EvidenceMarker;
|
|
14
|
+
} : never;
|
|
15
|
+
type Establish<T extends Scalar, Fact extends symbol> = <Value extends T>(value: Value) => Evidence<Value, Fact>;
|
|
16
|
+
/** Defines an owner-scoped formation boundary for one stable fact. */
|
|
17
|
+
export declare function defineFact<T extends Scalar>(): <const Fact extends symbol, Api>(token: Fact & SingleSymbol<Fact>, build: (establish: Establish<T, Fact>) => Api) => Api;
|
|
18
|
+
type NamedEvidence<T extends Scalar, Name extends string> = T & {
|
|
19
|
+
readonly [Key in `~selaws.evidence:${Name}`]: true;
|
|
20
|
+
};
|
|
21
|
+
type FactEvidence<T extends Scalar, TokenValue extends Token> = TokenValue extends string ? NamedEvidence<T, TokenValue> : TokenValue extends symbol ? Evidence<T, TokenValue> : never;
|
|
22
|
+
type Predicate<T> = (value: T) => boolean;
|
|
23
|
+
interface Fact<T extends Scalar, TokenValue extends Token> {
|
|
24
|
+
<Value extends T>(value: Value): FactEvidence<Value, TokenValue> | undefined;
|
|
25
|
+
(value: unknown): FactEvidence<T, TokenValue> | undefined;
|
|
26
|
+
}
|
|
27
|
+
interface FactFactory<T extends Scalar> {
|
|
28
|
+
<const Name extends string>(name: Name & SingleName<Name>, predicate: Predicate<T>): Fact<T, Name>;
|
|
29
|
+
<const Key extends symbol>(key: Key & SingleSymbol<Key>, predicate: Predicate<T>): Fact<T, Key>;
|
|
30
|
+
}
|
|
31
|
+
type EvidenceFacade = Readonly<{
|
|
32
|
+
bigint: FactFactory<bigint>;
|
|
33
|
+
boolean: FactFactory<boolean>;
|
|
34
|
+
define: typeof defineFact;
|
|
35
|
+
number: FactFactory<number>;
|
|
36
|
+
string: FactFactory<string>;
|
|
37
|
+
symbol: FactFactory<symbol>;
|
|
38
|
+
}>;
|
|
39
|
+
/** Stable scalar facts with named or declaration-owned evidence. */
|
|
40
|
+
export declare const evidence: EvidenceFacade;
|
|
41
|
+
export declare namespace evidence {
|
|
42
|
+
/** Applies an evidence declaration's fact type to an existing scalar value. */
|
|
43
|
+
type Proven<F, Value extends Scalar> = F extends Fact<infer T, infer TokenValue> ? Value extends T ? FactEvidence<Value, TokenValue> : never : never;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=evidence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evidence.d.ts","sourceRoot":"","sources":["../src/evidence.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,YAAY,EAC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B,QAAQ,CAAC;IACxB,+EAA+E;IAC/E,KAAY,MAAM,CAAC,CAAC,EAAE,KAAK,SAAS,MAAM,IACxC,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,UAAU,CAAC,GACrC,KAAK,SAAS,CAAC,GACb,YAAY,CAAC,KAAK,EAAE,UAAU,CAAC,GAC/B,KAAK,GACP,KAAK,CAAC;CACb"}
|
package/dist/evidence.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isBigint, isBoolean, isNumber, isString, isSymbol, } from "./internal/scalar.js";
|
|
2
|
+
/** Defines an owner-scoped formation boundary for one stable fact. */
|
|
3
|
+
export function defineFact() {
|
|
4
|
+
return function define(token, build) {
|
|
5
|
+
void token;
|
|
6
|
+
const establish = (value) => value;
|
|
7
|
+
return build(establish);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
const factFactory = (isCarrier) => ((_token, predicate) => (value) => isCarrier(value) && predicate(value)
|
|
11
|
+
? value
|
|
12
|
+
: undefined);
|
|
13
|
+
/** Stable scalar facts with named or declaration-owned evidence. */
|
|
14
|
+
export const evidence = {
|
|
15
|
+
bigint: factFactory(isBigint),
|
|
16
|
+
boolean: factFactory(isBoolean),
|
|
17
|
+
define: defineFact,
|
|
18
|
+
number: factFactory(isNumber),
|
|
19
|
+
string: factFactory(isString),
|
|
20
|
+
symbol: factFactory(isSymbol),
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=evidence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evidence.js","sourceRoot":"","sources":["../src/evidence.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,QAAQ,GAMT,MAAM,sBAAsB,CAAC;AA0B9B,sEAAsE;AACtE,MAAM,UAAU,UAAU;IACxB,OAAO,SAAS,MAAM,CACpB,KAAgC,EAChC,KAA6C;QAE7C,KAAK,KAAK,CAAC;QAEX,MAAM,SAAS,GAAG,CAAkB,KAAY,EAAyB,EAAE,CACzE,KAA8B,CAAC;QAEjC,OAAO,KAAK,CAAC,SAAS,CAAC,CAAC;IAC1B,CAAC,CAAC;AACJ,CAAC;AAkCD,MAAM,WAAW,GAAG,CAClB,SAAyC,EACzB,EAAE,CAClB,CAAC,CAAC,MAAa,EAAE,SAAuB,EAAE,EAAE,CAAC,CAAC,KAAc,EAAE,EAAE,CAC9D,SAAS,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC;IAClC,CAAC,CAAC,KAAK;IACP,CAAC,CAAC,SAAS,CAA8B,CAAC;AAWhD,oEAAoE;AACpE,MAAM,CAAC,MAAM,QAAQ,GAAmB;IACtC,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC;IAC7B,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC;IAC/B,MAAM,EAAE,UAAU;IAClB,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC;IAC7B,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC;IAC7B,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC;CAC9B,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type Scalar, type SingleName, type SingleSymbol, type Token } from "./internal/scalar.js";
|
|
2
|
+
export type { Scalar } from "./internal/scalar.js";
|
|
3
|
+
type IdentityMarker = {
|
|
4
|
+
readonly "~selaws.identity": true;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* A scalar carrying one declaration-owned nominal identity.
|
|
8
|
+
*
|
|
9
|
+
* The domain token is the phantom property key itself, so identity belongs to
|
|
10
|
+
* the declaration that owns the token and remains stable across duplicate
|
|
11
|
+
* Selaws installations.
|
|
12
|
+
*/
|
|
13
|
+
export type Identity<T extends Scalar, Id extends symbol> = [Id] extends [never] ? never : [Id] extends [SingleSymbol<Id>] ? T & {
|
|
14
|
+
readonly [Key in Id]: IdentityMarker;
|
|
15
|
+
} : never;
|
|
16
|
+
type Mint<T extends Scalar, Id extends symbol> = <Value extends T>(value: Value) => Identity<Value, Id>;
|
|
17
|
+
/** Defines an owner-scoped formation boundary for one nominal identity. */
|
|
18
|
+
export declare function defineIdentity<T extends Scalar>(): <const Id extends symbol, Api>(token: Id & SingleSymbol<Id>, build: (mint: Mint<T, Id>) => Api) => Api;
|
|
19
|
+
type NamedIdentity<T extends Scalar, Name extends string> = T & {
|
|
20
|
+
readonly [Key in `~selaws.identity:${Name}`]: true;
|
|
21
|
+
};
|
|
22
|
+
type DomainIdentity<T extends Scalar, TokenValue extends Token> = TokenValue extends string ? NamedIdentity<T, TokenValue> : TokenValue extends symbol ? Identity<T, TokenValue> : never;
|
|
23
|
+
type Predicate<T> = (value: T) => boolean;
|
|
24
|
+
interface OpenIdentity<T extends Scalar, TokenValue extends Token> {
|
|
25
|
+
<Value extends T>(value: Value): DomainIdentity<Value, TokenValue>;
|
|
26
|
+
(value: unknown): DomainIdentity<T, TokenValue> | undefined;
|
|
27
|
+
}
|
|
28
|
+
interface CheckedIdentity<T extends Scalar, TokenValue extends Token> {
|
|
29
|
+
<Value extends T>(value: Value): DomainIdentity<Value, TokenValue> | undefined;
|
|
30
|
+
(value: unknown): DomainIdentity<T, TokenValue> | undefined;
|
|
31
|
+
}
|
|
32
|
+
interface IdentityFactory<T extends Scalar> {
|
|
33
|
+
<const Name extends string>(name: Name & SingleName<Name>): OpenIdentity<T, Name>;
|
|
34
|
+
<const Name extends string>(name: Name & SingleName<Name>, predicate: Predicate<T>): CheckedIdentity<T, Name>;
|
|
35
|
+
<const Key extends symbol>(key: Key & SingleSymbol<Key>): OpenIdentity<T, Key>;
|
|
36
|
+
<const Key extends symbol>(key: Key & SingleSymbol<Key>, predicate: Predicate<T>): CheckedIdentity<T, Key>;
|
|
37
|
+
}
|
|
38
|
+
type IdentityFacade = Readonly<{
|
|
39
|
+
bigint: IdentityFactory<bigint>;
|
|
40
|
+
boolean: IdentityFactory<boolean>;
|
|
41
|
+
define: typeof defineIdentity;
|
|
42
|
+
number: IdentityFactory<number>;
|
|
43
|
+
string: IdentityFactory<string>;
|
|
44
|
+
symbol: IdentityFactory<symbol>;
|
|
45
|
+
}>;
|
|
46
|
+
/** Scalar identity formation with named or declaration-owned identity. */
|
|
47
|
+
export declare const identity: IdentityFacade;
|
|
48
|
+
export declare namespace identity {
|
|
49
|
+
/** Extracts the scalar identity value type produced by an identity declaration. */
|
|
50
|
+
type Value<Domain> = Domain extends OpenIdentity<infer T, infer TokenValue> ? DomainIdentity<T, TokenValue> : Domain extends CheckedIdentity<infer T, infer TokenValue> ? DomainIdentity<T, TokenValue> : never;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,KAAK,EACX,MAAM,sBAAsB,CAAC;AAE9B,YAAY,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEnD,KAAK,cAAc,GAAG;IACpB,QAAQ,CAAC,kBAAkB,EAAE,IAAI,CAAC;CACnC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,EAAE,SAAS,MAAM,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,GAC5E,KAAK,GACL,CAAC,EAAE,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,GAC7B,CAAC,GAAG;IACF,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,cAAc;CACrC,GACD,KAAK,CAAC;AAEZ,KAAK,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,EAAE,SAAS,MAAM,IAAI,CAAC,KAAK,SAAS,CAAC,EAC/D,KAAK,EAAE,KAAK,KACT,QAAQ,CAAC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B,MAAM,SAAS,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,UAAU,CAAC,GAClD,cAAc,CAAC,CAAC,EAAE,UAAU,CAAC,GAC7B,MAAM,SAAS,eAAe,CAAC,MAAM,CAAC,EAAE,MAAM,UAAU,CAAC,GACvD,cAAc,CAAC,CAAC,EAAE,UAAU,CAAC,GAC7B,KAAK,CAAC;CACf"}
|
package/dist/identity.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isBigint, isBoolean, isNumber, isString, isSymbol, } from "./internal/scalar.js";
|
|
2
|
+
/** Defines an owner-scoped formation boundary for one nominal identity. */
|
|
3
|
+
export function defineIdentity() {
|
|
4
|
+
return function define(token, build) {
|
|
5
|
+
void token;
|
|
6
|
+
const mint = (value) => value;
|
|
7
|
+
return build(mint);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
const identityFactory = (isCarrier) => ((_token, predicate) => (value) => isCarrier(value) && (predicate === undefined || predicate(value))
|
|
11
|
+
? value
|
|
12
|
+
: undefined);
|
|
13
|
+
/** Scalar identity formation with named or declaration-owned identity. */
|
|
14
|
+
export const identity = {
|
|
15
|
+
bigint: identityFactory(isBigint),
|
|
16
|
+
boolean: identityFactory(isBoolean),
|
|
17
|
+
define: defineIdentity,
|
|
18
|
+
number: identityFactory(isNumber),
|
|
19
|
+
string: identityFactory(isString),
|
|
20
|
+
symbol: identityFactory(isSymbol),
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,QAAQ,GAKT,MAAM,sBAAsB,CAAC;AA2B9B,2EAA2E;AAC3E,MAAM,UAAU,cAAc;IAC5B,OAAO,SAAS,MAAM,CACpB,KAA4B,EAC5B,KAAiC;QAEjC,KAAK,KAAK,CAAC;QAEX,MAAM,IAAI,GAAG,CAAkB,KAAY,EAAuB,EAAE,CAClE,KAA4B,CAAC;QAE/B,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC;AA2CD,MAAM,eAAe,GAAG,CACtB,SAAyC,EACrB,EAAE,CACtB,CAAC,CAAC,MAAa,EAAE,SAAwB,EAAE,EAAE,CAAC,CAAC,KAAc,EAAE,EAAE,CAC/D,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,KAAK,SAAS,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/D,CAAC,CAAC,KAAK;IACP,CAAC,CAAC,SAAS,CAAkC,CAAC;AAWpD,0EAA0E;AAC1E,MAAM,CAAC,MAAM,QAAQ,GAAmB;IACtC,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC;IACjC,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC;IACnC,MAAM,EAAE,cAAc;IACtB,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC;IACjC,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC;IACjC,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC;CAClC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Option as OptionFacade } from "./option.js";
|
|
2
|
+
import { Protocol as ProtocolFacade } from "./protocol.js";
|
|
3
|
+
import { Result as ResultFacade } from "./result/core.js";
|
|
4
|
+
import { Validation as ValidationFacade } from "./validation.js";
|
|
5
|
+
import { Variant as VariantFacade } from "./variant.js";
|
|
6
|
+
export { type Evidence, evidence } from "./evidence.js";
|
|
7
|
+
export { type Identity, identity, type Scalar } from "./identity.js";
|
|
8
|
+
/** Root-entry Protocol carrier paired with the Protocol facade value. */
|
|
9
|
+
export type Protocol<Transitions extends readonly import("./protocol.js").Transition[]> = import("./protocol.js").Protocol<Transitions>;
|
|
10
|
+
/** Root-entry Protocol facade. */
|
|
11
|
+
export declare const Protocol: typeof ProtocolFacade;
|
|
12
|
+
/** Root-entry Variant carrier paired with the Variant facade value. */
|
|
13
|
+
export type Variant<Family> = import("./variant.js").Variant<Family>;
|
|
14
|
+
/** Root-entry Variant facade. */
|
|
15
|
+
export declare const Variant: typeof VariantFacade;
|
|
16
|
+
export declare namespace Variant {
|
|
17
|
+
/** Extracts the closed value union produced by one Variant family. */
|
|
18
|
+
type Value<Family> = import("./variant.js").Variant<Family>;
|
|
19
|
+
}
|
|
20
|
+
export type { None, OptionValue, Some } from "./option.js";
|
|
21
|
+
/** Root-entry Option carrier paired with the Option facade value. */
|
|
22
|
+
export type Option<T> = import("./option.js").Option<T>;
|
|
23
|
+
/** Root-entry Option facade. */
|
|
24
|
+
export declare const Option: typeof OptionFacade;
|
|
25
|
+
export type { Invalid, Valid, ValidationError, ValidationIssues, ValidationValue, } from "./validation.js";
|
|
26
|
+
/** Root-entry Validation carrier paired with the Validation facade value. */
|
|
27
|
+
export type Validation<T, E> = import("./validation.js").Validation<T, E>;
|
|
28
|
+
/** Root-entry Validation facade. */
|
|
29
|
+
export declare const Validation: typeof ValidationFacade;
|
|
30
|
+
export type { AsyncResult, Err, Ok, ResultError, ResultValue, } from "./result/core.js";
|
|
31
|
+
/** Root-entry Result carrier paired with the Result facade value. */
|
|
32
|
+
export type Result<T, E> = import("./result/core.js").Result<T, E>;
|
|
33
|
+
/** Root-entry Result facade. */
|
|
34
|
+
export declare const Result: typeof ResultFacade;
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,kBAAkB,CAAC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,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1E,oCAAoC;AACpC,eAAO,MAAM,UAAU,EAAE,OAAO,gBAAmC,CAAC;AAEpE,YAAY,EACV,WAAW,EACX,GAAG,EACH,EAAE,EACF,WAAW,EACX,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAC1B,qEAAqE;AACrE,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,OAAO,kBAAkB,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACnE,gCAAgC;AAChC,eAAO,MAAM,MAAM,EAAE,OAAO,YAA2B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Option as OptionFacade } from "./option.js";
|
|
2
|
+
import { Protocol as ProtocolFacade } from "./protocol.js";
|
|
3
|
+
import { Result as ResultFacade } from "./result/core.js";
|
|
4
|
+
import { Validation as ValidationFacade } from "./validation.js";
|
|
5
|
+
import { Variant as VariantFacade } from "./variant.js";
|
|
6
|
+
export { evidence } from "./evidence.js";
|
|
7
|
+
export { identity } from "./identity.js";
|
|
8
|
+
/** Root-entry Protocol facade. */
|
|
9
|
+
export const Protocol = ProtocolFacade;
|
|
10
|
+
/** Root-entry Variant facade. */
|
|
11
|
+
export const Variant = VariantFacade;
|
|
12
|
+
/** Root-entry Option facade. */
|
|
13
|
+
export const Option = OptionFacade;
|
|
14
|
+
/** Root-entry Validation facade. */
|
|
15
|
+
export const Validation = ValidationFacade;
|
|
16
|
+
/** Root-entry Result facade. */
|
|
17
|
+
export const Result = ResultFacade;
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,UAAU,IAAI,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,EAAiB,QAAQ,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAiB,QAAQ,EAAe,MAAM,eAAe,CAAC;AAMrE,kCAAkC;AAClC,MAAM,CAAC,MAAM,QAAQ,GAA0B,cAAc,CAAC;AAI9D,iCAAiC;AACjC,MAAM,CAAC,MAAM,OAAO,GAAyB,aAAa,CAAC;AAS3D,gCAAgC;AAChC,MAAM,CAAC,MAAM,MAAM,GAAwB,YAAY,CAAC;AAWxD,oCAAoC;AACpC,MAAM,CAAC,MAAM,UAAU,GAA4B,gBAAgB,CAAC;AAWpE,gCAAgC;AAChC,MAAM,CAAC,MAAM,MAAM,GAAwB,YAAY,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type Same<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => (T extends B ? 1 : 2) ? (<T>() => T extends B ? 1 : 2) extends <T>() => (T extends A ? 1 : 2) ? true : false : false;
|
|
2
|
+
type UnknownCallback = (this: void, ...args: never[]) => unknown;
|
|
3
|
+
type OverloadUnion<Callback, Partial = unknown, Previous = never, Repeated extends boolean = false, Accumulated = never> = Callback extends (this: infer This, ...args: infer Args) => infer Result ? ((this: This, ...args: Args) => Result) extends infer Current ? Same<Current, Previous> extends true ? Repeated extends true ? Accumulated | UnknownCallback : Partial extends Callback ? Accumulated : OverloadUnion<Partial & Callback, Partial & Current, Current, true, Accumulated | Current> : Partial extends Callback ? Accumulated : OverloadUnion<Partial & Callback, Partial & Current, Current, false, Accumulated | Current> : Accumulated : Accumulated;
|
|
4
|
+
/**
|
|
5
|
+
* Extracts a conservative union of callable return types.
|
|
6
|
+
*
|
|
7
|
+
* TypeScript exposes overloads as intersections. Generic callable reflection
|
|
8
|
+
* can repeat one instantiated signature indefinitely; repeated reflection
|
|
9
|
+
* widens to unknown instead of exhausting compiler instantiation depth.
|
|
10
|
+
*/
|
|
11
|
+
export type CallbackResult<Callback> = OverloadUnion<Callback> extends infer One ? One extends (...args: never[]) => infer Result ? Result : never : never;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=callback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callback.d.ts","sourceRoot":"","sources":["../../src/internal/callback.ts"],"names":[],"mappings":"AAAA,KAAK,IAAI,CAAC,CAAC,EAAE,CAAC,IACZ,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,QAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA,GAC/D,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,QAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA,GACjE,IAAI,GACJ,KAAK,GACP,KAAK,CAAC;AAEZ,KAAK,eAAe,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC;AAEjE,KAAK,aAAa,CAChB,QAAQ,EACR,OAAO,GAAG,OAAO,EACjB,QAAQ,GAAG,KAAK,EAChB,QAAQ,SAAS,OAAO,GAAG,KAAK,EAChC,WAAW,GAAG,KAAK,IACjB,QAAQ,SAAS,CAAC,IAAI,EAAE,MAAM,IAAI,EAAE,GAAG,IAAI,EAAE,MAAM,IAAI,KAAK,MAAM,MAAM,GACxE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC,SAAS,MAAM,OAAO,GAC3D,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,SAAS,IAAI,GAClC,QAAQ,SAAS,IAAI,GACnB,WAAW,GAAG,eAAe,GAC7B,OAAO,SAAS,QAAQ,GACtB,WAAW,GACX,aAAa,CACX,OAAO,GAAG,QAAQ,EAClB,OAAO,GAAG,OAAO,EACjB,OAAO,EACP,IAAI,EACJ,WAAW,GAAG,OAAO,CACtB,GACL,OAAO,SAAS,QAAQ,GACtB,WAAW,GACX,aAAa,CACX,OAAO,GAAG,QAAQ,EAClB,OAAO,GAAG,OAAO,EACjB,OAAO,EACP,KAAK,EACL,WAAW,GAAG,OAAO,CACtB,GACL,WAAW,GACb,WAAW,CAAC;AAEhB;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,CAAC,QAAQ,IACjC,aAAa,CAAC,QAAQ,CAAC,SAAS,MAAM,GAAG,GACrC,GAAG,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,MAAM,MAAM,GAC5C,MAAM,GACN,KAAK,GACP,KAAK,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callback.js","sourceRoot":"","sources":["../../src/internal/callback.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
2
|
+
type BroadFunction = FunctionConstructor["prototype"];
|
|
3
|
+
type HasCallableThen<T> = T extends object ? "then" extends keyof T ? Extract<T["then"], BroadFunction> extends never ? false : true : false : false;
|
|
4
|
+
export type NotPromiseLike<T> = IsAny<T> extends true ? T : true extends (T extends unknown ? HasCallableThen<T> : never) ? never : T;
|
|
5
|
+
export declare const isPromiseLike: (value: unknown) => value is PromiseLike<unknown>;
|
|
6
|
+
export declare const assertNotPromiseLike: (value: unknown, message: string) => void;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=promise-like.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promise-like.d.ts","sourceRoot":"","sources":["../../src/internal/promise-like.ts"],"names":[],"mappings":"AAAA,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;AAE/C,KAAK,aAAa,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC;AAEtD,KAAK,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GACtC,MAAM,SAAS,MAAM,CAAC,GACpB,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,SAAS,KAAK,GAC7C,KAAK,GACL,IAAI,GACN,KAAK,GACP,KAAK,CAAC;AAEV,MAAM,MAAM,cAAc,CAAC,CAAC,IAC1B,KAAK,CAAC,CAAC,CAAC,SAAS,IAAI,GACjB,CAAC,GACD,IAAI,SAAS,CAAC,CAAC,SAAS,OAAO,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,GAC3D,KAAK,GACL,CAAC,CAAC;AAEV,eAAO,MAAM,aAAa,UAAW,OAAO,KAAG,KAAK,IAAI,WAAW,CAAC,OAAO,CAM1E,CAAC;AAEF,eAAO,MAAM,oBAAoB,UAAW,OAAO,WAAW,MAAM,KAAG,IAItE,CAAC"}
|