effect 4.0.0-beta.28 → 4.0.0-beta.29
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/dist/Brand.d.ts +1 -1
- package/dist/Brand.d.ts.map +1 -1
- package/dist/Brand.js +1 -1
- package/dist/Brand.js.map +1 -1
- package/dist/Function.d.ts +1 -9
- package/dist/Function.d.ts.map +1 -1
- package/dist/Function.js +2 -10
- package/dist/Function.js.map +1 -1
- package/dist/Newtype.d.ts +291 -0
- package/dist/Newtype.d.ts.map +1 -0
- package/dist/Newtype.js +161 -0
- package/dist/Newtype.js.map +1 -0
- package/dist/Schema.d.ts +1 -1
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +1 -1
- package/dist/SchemaAST.js.map +1 -1
- package/dist/index.d.ts +69 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +69 -3
- package/dist/index.js.map +1 -1
- package/dist/unstable/cli/Prompt.js +4 -8
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/http/HttpClient.d.ts.map +1 -1
- package/dist/unstable/http/HttpClient.js +3 -7
- package/dist/unstable/http/HttpClient.js.map +1 -1
- package/dist/unstable/reactivity/Atom.d.ts +7 -2
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js +31 -7
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/reactivity/AtomRegistry.js +26 -2
- package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
- package/package.json +1 -1
- package/src/Brand.ts +1 -1
- package/src/Function.ts +2 -10
- package/src/Newtype.ts +308 -0
- package/src/Schema.ts +1 -1
- package/src/SchemaAST.ts +1 -4
- package/src/index.ts +70 -3
- package/src/unstable/cli/Prompt.ts +4 -9
- package/src/unstable/http/HttpClient.ts +5 -6
- package/src/unstable/reactivity/Atom.ts +45 -12
- package/src/unstable/reactivity/AtomRegistry.ts +30 -2
package/dist/Newtype.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { cast } from "./Function.js";
|
|
2
|
+
import * as Optic from "./Optic.js";
|
|
3
|
+
const TypeId = "~effect/Newtype";
|
|
4
|
+
/**
|
|
5
|
+
* Unwraps a newtype value, returning the underlying carrier value.
|
|
6
|
+
*
|
|
7
|
+
* - Use when you only need to read the inner value and do not need to wrap new
|
|
8
|
+
* values.
|
|
9
|
+
* - For both wrapping and unwrapping, prefer {@link makeIso}.
|
|
10
|
+
* - Zero runtime cost: this is an identity cast.
|
|
11
|
+
*
|
|
12
|
+
* **Example** (unwrapping a newtype)
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { Newtype } from "effect"
|
|
16
|
+
*
|
|
17
|
+
* interface Label extends Newtype.Newtype<"Label", string> {}
|
|
18
|
+
*
|
|
19
|
+
* const iso = Newtype.makeIso<Label>()
|
|
20
|
+
* const label = iso.set("hello")
|
|
21
|
+
*
|
|
22
|
+
* const raw: string = Newtype.value(label) // "hello"
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @see {@link makeIso} — two-way conversion (wrap and unwrap)
|
|
26
|
+
*
|
|
27
|
+
* @since 4.0.0
|
|
28
|
+
*/
|
|
29
|
+
export const value = cast;
|
|
30
|
+
/**
|
|
31
|
+
* Creates an `Optic.Iso` for a newtype, providing both wrapping (`set`) and
|
|
32
|
+
* unwrapping (`get`).
|
|
33
|
+
*
|
|
34
|
+
* - Use this as the primary way to construct and deconstruct newtype values.
|
|
35
|
+
* - The returned iso composes with other optics via the standard `Optic` API.
|
|
36
|
+
* - Zero runtime cost: both directions are identity casts.
|
|
37
|
+
*
|
|
38
|
+
* **Example** (wrapping and unwrapping with an iso)
|
|
39
|
+
*
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { Newtype } from "effect"
|
|
42
|
+
*
|
|
43
|
+
* interface Label extends Newtype.Newtype<"Label", string> {}
|
|
44
|
+
*
|
|
45
|
+
* const labelIso = Newtype.makeIso<Label>()
|
|
46
|
+
*
|
|
47
|
+
* const label: Label = labelIso.set("world")
|
|
48
|
+
* const str: string = labelIso.get(label) // "world"
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @see {@link value} — unwrap only
|
|
52
|
+
*
|
|
53
|
+
* @since 4.0.0
|
|
54
|
+
*/
|
|
55
|
+
export function makeIso() {
|
|
56
|
+
return Optic.makeIso(value, cast);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Lifts an `Equivalence` for the carrier type into an `Equivalence` for the
|
|
60
|
+
* newtype.
|
|
61
|
+
*
|
|
62
|
+
* - Use when you need to compare two newtype values for equality.
|
|
63
|
+
* - The returned equivalence delegates to the provided carrier equivalence.
|
|
64
|
+
* - Zero runtime cost beyond the underlying equivalence check.
|
|
65
|
+
*
|
|
66
|
+
* **Example** (comparing newtypes)
|
|
67
|
+
*
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { Newtype, Equivalence } from "effect"
|
|
70
|
+
*
|
|
71
|
+
* interface Label extends Newtype.Newtype<"Label", string> {}
|
|
72
|
+
*
|
|
73
|
+
* const eq = Newtype.makeEquivalence<Label>(Equivalence.String)
|
|
74
|
+
* const iso = Newtype.makeIso<Label>()
|
|
75
|
+
*
|
|
76
|
+
* eq(iso.set("a"), iso.set("a")) // true
|
|
77
|
+
* eq(iso.set("a"), iso.set("b")) // false
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @see {@link makeOrder} — lift an `Order` for the carrier
|
|
81
|
+
*
|
|
82
|
+
* @since 4.0.0
|
|
83
|
+
*/
|
|
84
|
+
export const makeEquivalence = cast;
|
|
85
|
+
/**
|
|
86
|
+
* Lifts an `Order` for the carrier type into an `Order` for the newtype.
|
|
87
|
+
*
|
|
88
|
+
* - Use when you need to sort or compare newtype values.
|
|
89
|
+
* - The returned order delegates to the provided carrier order.
|
|
90
|
+
*
|
|
91
|
+
* **Example** (ordering newtypes)
|
|
92
|
+
*
|
|
93
|
+
* ```ts
|
|
94
|
+
* import { Newtype, Order } from "effect"
|
|
95
|
+
*
|
|
96
|
+
* interface Score extends Newtype.Newtype<"Score", number> {}
|
|
97
|
+
*
|
|
98
|
+
* const ord = Newtype.makeOrder<Score>(Order.Number)
|
|
99
|
+
* const iso = Newtype.makeIso<Score>()
|
|
100
|
+
*
|
|
101
|
+
* ord(iso.set(1), iso.set(2)) // -1
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @see {@link makeEquivalence} — lift an `Equivalence` for the carrier
|
|
105
|
+
*
|
|
106
|
+
* @since 4.0.0
|
|
107
|
+
*/
|
|
108
|
+
export const makeOrder = cast;
|
|
109
|
+
/**
|
|
110
|
+
* Lifts a `Combiner` for the carrier type into a `Combiner` for the newtype.
|
|
111
|
+
*
|
|
112
|
+
* - Use when you need to combine (e.g. concatenate, add) newtype values.
|
|
113
|
+
* - The returned combiner delegates to the provided carrier combiner.
|
|
114
|
+
*
|
|
115
|
+
* **Example** (combining newtypes)
|
|
116
|
+
*
|
|
117
|
+
* ```ts
|
|
118
|
+
* import { Newtype, Combiner } from "effect"
|
|
119
|
+
*
|
|
120
|
+
* interface Amount extends Newtype.Newtype<"Amount", number> {}
|
|
121
|
+
*
|
|
122
|
+
* const sum = Combiner.make<number>((a, b) => a + b)
|
|
123
|
+
* const combiner = Newtype.makeCombiner<Amount>(sum)
|
|
124
|
+
* const iso = Newtype.makeIso<Amount>()
|
|
125
|
+
*
|
|
126
|
+
* const total = combiner.combine(iso.set(10), iso.set(20))
|
|
127
|
+
* Newtype.value(total) // 30
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @see {@link makeReducer} — lift a `Reducer` for the carrier
|
|
131
|
+
*
|
|
132
|
+
* @since 4.0.0
|
|
133
|
+
*/
|
|
134
|
+
export const makeCombiner = cast;
|
|
135
|
+
/**
|
|
136
|
+
* Lifts a `Reducer` for the carrier type into a `Reducer` for the newtype.
|
|
137
|
+
*
|
|
138
|
+
* - Use when you need to fold/reduce over a collection of newtype values.
|
|
139
|
+
* - The returned reducer delegates to the provided carrier reducer.
|
|
140
|
+
*
|
|
141
|
+
* **Example** (reducing newtypes)
|
|
142
|
+
*
|
|
143
|
+
* ```ts
|
|
144
|
+
* import { Newtype, Reducer } from "effect"
|
|
145
|
+
*
|
|
146
|
+
* interface Score extends Newtype.Newtype<"Score", number> {}
|
|
147
|
+
*
|
|
148
|
+
* const sum = Reducer.make<number>((a, b) => a + b, 0)
|
|
149
|
+
* const reducer = Newtype.makeReducer<Score>(sum)
|
|
150
|
+
* const iso = Newtype.makeIso<Score>()
|
|
151
|
+
*
|
|
152
|
+
* const total = reducer.combineAll([iso.set(1), iso.set(2), iso.set(3)])
|
|
153
|
+
* Newtype.value(total) // 6
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* @see {@link makeCombiner} — lift a `Combiner` for the carrier
|
|
157
|
+
*
|
|
158
|
+
* @since 4.0.0
|
|
159
|
+
*/
|
|
160
|
+
export const makeReducer = cast;
|
|
161
|
+
//# sourceMappingURL=Newtype.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Newtype.js","names":["cast","Optic","TypeId","value","makeIso","makeEquivalence","makeOrder","makeCombiner","makeReducer"],"sources":["../src/Newtype.ts"],"sourcesContent":[null],"mappings":"AAmEA,SAASA,IAAI,QAAQ,eAAe;AACpC,OAAO,KAAKC,KAAK,MAAM,YAAY;AAInC,MAAMC,MAAM,GAAG,iBAAiB;AAqEhC;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,OAAO,MAAMC,KAAK,GAA8DH,IAAI;AAEpF;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,OAAM,SAAUI,OAAOA,CAAA;EACrB,OAAOH,KAAK,CAACG,OAAO,CAACD,KAAK,EAAEH,IAAI,CAAC;AACnC;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,OAAO,MAAMK,eAAe,GAEML,IAAI;AAEtC;;;;;;;;;;;;;;;;;;;;;;;AAuBA,OAAO,MAAMM,SAAS,GAAsFN,IAAI;AAEhH;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,OAAO,MAAMO,YAAY,GAEGP,IAAI;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,OAAO,MAAMQ,WAAW,GACtBR,IAAI","ignoreList":[]}
|
package/dist/Schema.d.ts
CHANGED
|
@@ -2273,7 +2273,7 @@ export declare const isStringSymbol: (annotations?: Annotations.Filter) => AST.F
|
|
|
2273
2273
|
* @category String checks
|
|
2274
2274
|
* @since 4.0.0
|
|
2275
2275
|
*/
|
|
2276
|
-
export declare function isUUID(version
|
|
2276
|
+
export declare function isUUID(version?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8, annotations?: Annotations.Filter): AST.Filter<string>;
|
|
2277
2277
|
/**
|
|
2278
2278
|
* Validates that a string is a valid ULID (Universally Unique Lexicographically
|
|
2279
2279
|
* Sortable Identifier).
|