@nlozgachev/pipekit 0.5.0 → 0.5.1
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/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@nlozgachev/pipekit)[](https://jsr.io/@nlozgachev/pipekit)[](https://github.com/nlozgachev/pipekit/actions/workflows/publish.yml)[](https://app.codecov.io/github/nlozgachev/pipekit)[](https://www.typescriptlang.org)[](https://deno.com)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Opinionated functional abstractions for TypeScript.
|
|
6
6
|
|
|
7
7
|
> **Note:** pipekit is pre-1.0. The API may change between minor versions until the 1.0 release.
|
|
8
8
|
|
|
@@ -27,23 +27,24 @@ No FP jargon required. You won't find `Monad`, `Functor`, or `Applicative` in th
|
|
|
27
27
|
|
|
28
28
|
### pipekit/Core
|
|
29
29
|
|
|
30
|
-
- **`Option<A>`** — a value that
|
|
31
|
-
- **`Result<E, A>`** — an operation that succeeds or fails
|
|
32
|
-
- **`Validation<E, A>`** — like `Result`, but accumulates
|
|
30
|
+
- **`Option<A>`** — a value that may not exist; propagates absence without null checks.
|
|
31
|
+
- **`Result<E, A>`** — an operation that succeeds or fails with a typed error.
|
|
32
|
+
- **`Validation<E, A>`** — like `Result`, but accumulates every failure instead of stopping at the
|
|
33
33
|
first.
|
|
34
|
-
- **`Task<A>`** — a lazy async operation
|
|
35
|
-
- **`TaskResult<E, A>`** —
|
|
36
|
-
- **`TaskOption<A>`** —
|
|
37
|
-
- **`TaskValidation<E, A>`** —
|
|
34
|
+
- **`Task<A>`** — a lazy, infallible async operation; nothing runs until called.
|
|
35
|
+
- **`TaskResult<E, A>`** — a lazy async operation that can fail with a typed error.
|
|
36
|
+
- **`TaskOption<A>`** — a lazy async operation that may produce nothing.
|
|
37
|
+
- **`TaskValidation<E, A>`** — a lazy async operation that accumulates validation errors.
|
|
38
38
|
- **`These<E, A>`** — an inclusive OR: holds an error, a value, or both at once.
|
|
39
39
|
- **`RemoteData<E, A>`** — the four states of a data fetch: `NotAsked`, `Loading`, `Failure`,
|
|
40
40
|
`Success`.
|
|
41
41
|
- **`Lens<S, A>`** — focus on a required field in a nested structure. Read, set, and modify
|
|
42
42
|
immutably.
|
|
43
43
|
- **`Optional<S, A>`** — like `Lens`, but the target may be absent (nullable fields, array indices).
|
|
44
|
-
- **`Reader<R, A>`** — a computation that depends on an environment `R`,
|
|
45
|
-
|
|
46
|
-
- **`
|
|
44
|
+
- **`Reader<R, A>`** — a computation that depends on an environment `R`, supplied once at the
|
|
45
|
+
boundary.
|
|
46
|
+
- **`Arr`** — array utilities, data-last, returning `Option` instead of `undefined`.
|
|
47
|
+
- **`Rec`** — record utilities, data-last, with `Option`-returning key lookup.
|
|
47
48
|
|
|
48
49
|
### pipekit/Types
|
|
49
50
|
|
package/esm/src/Core/Deferred.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export var Deferred;
|
|
2
2
|
(function (Deferred) {
|
|
3
3
|
/**
|
|
4
|
-
* Wraps a `Promise` into a `Deferred`,
|
|
5
|
-
* and chainable `.then()`.
|
|
4
|
+
* Wraps a `Promise` into a `Deferred`, structurally excluding rejection handlers,
|
|
5
|
+
* `.catch()`, `.finally()`, and chainable `.then()`.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```ts
|
|
@@ -11,9 +11,7 @@ export var Deferred;
|
|
|
11
11
|
* ```
|
|
12
12
|
*/
|
|
13
13
|
Deferred.fromPromise = (p) => ({
|
|
14
|
-
then: (f) =>
|
|
15
|
-
p.then(f);
|
|
16
|
-
},
|
|
14
|
+
then: ((f) => p.then(f)),
|
|
17
15
|
});
|
|
18
16
|
/**
|
|
19
17
|
* Converts a `Deferred` back into a `Promise`.
|
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@ exports.Deferred = void 0;
|
|
|
4
4
|
var Deferred;
|
|
5
5
|
(function (Deferred) {
|
|
6
6
|
/**
|
|
7
|
-
* Wraps a `Promise` into a `Deferred`,
|
|
8
|
-
* and chainable `.then()`.
|
|
7
|
+
* Wraps a `Promise` into a `Deferred`, structurally excluding rejection handlers,
|
|
8
|
+
* `.catch()`, `.finally()`, and chainable `.then()`.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
@@ -14,9 +14,7 @@ var Deferred;
|
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
16
|
Deferred.fromPromise = (p) => ({
|
|
17
|
-
then: (f) =>
|
|
18
|
-
p.then(f);
|
|
19
|
-
},
|
|
17
|
+
then: ((f) => p.then(f)),
|
|
20
18
|
});
|
|
21
19
|
/**
|
|
22
20
|
* Converts a `Deferred` back into a `Promise`.
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
declare const _deferred: unique symbol;
|
|
1
2
|
/**
|
|
2
|
-
* A one-shot async value that supports `await` but
|
|
3
|
+
* A nominally typed, one-shot async value that supports `await` but enforces infallibility.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Two design choices work together to make the guarantee structural rather than documentary:
|
|
6
|
+
*
|
|
7
|
+
* - The phantom `[_deferred]` symbol makes the type **nominal**: only values produced by
|
|
8
|
+
* `Deferred.fromPromise` satisfy it. A plain object `{ then: ... }` does not.
|
|
9
|
+
* - The single-parameter `.then()` **excludes rejection handlers** by construction. There is
|
|
10
|
+
* no second argument to pass, so chaining and `.catch()` are impossible.
|
|
11
|
+
*
|
|
12
|
+
* This makes `Deferred<A>` the natural return type for `Task<A>`, which is guaranteed to
|
|
13
|
+
* never reject.
|
|
7
14
|
*
|
|
8
15
|
* @example
|
|
9
16
|
* ```ts
|
|
@@ -12,12 +19,13 @@
|
|
|
12
19
|
* ```
|
|
13
20
|
*/
|
|
14
21
|
export type Deferred<A> = {
|
|
22
|
+
readonly [_deferred]: A;
|
|
15
23
|
readonly then: (onfulfilled: (value: A) => void) => void;
|
|
16
24
|
};
|
|
17
25
|
export declare namespace Deferred {
|
|
18
26
|
/**
|
|
19
|
-
* Wraps a `Promise` into a `Deferred`,
|
|
20
|
-
* and chainable `.then()`.
|
|
27
|
+
* Wraps a `Promise` into a `Deferred`, structurally excluding rejection handlers,
|
|
28
|
+
* `.catch()`, `.finally()`, and chainable `.then()`.
|
|
21
29
|
*
|
|
22
30
|
* @example
|
|
23
31
|
* ```ts
|
|
@@ -37,4 +45,5 @@ export declare namespace Deferred {
|
|
|
37
45
|
*/
|
|
38
46
|
const toPromise: <A>(d: Deferred<A>) => Promise<A>;
|
|
39
47
|
}
|
|
48
|
+
export {};
|
|
40
49
|
//# sourceMappingURL=Deferred.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Deferred.d.ts","sourceRoot":"","sources":["../../../src/src/Core/Deferred.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Deferred.d.ts","sourceRoot":"","sources":["../../../src/src/Core/Deferred.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,SAAS,EAAE,OAAO,MAAM,CAAC;AAEvC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;IACxB,QAAQ,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,KAAK,IAAI,CAAC;CAC1D,CAAC;AAEF,yBAAiB,QAAQ,CAAC;IACxB;;;;;;;;;OASG;IACI,MAAM,WAAW,GAAI,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,KAAG,QAAQ,CAAC,CAAC,CAGtC,CAAC;IAEpB;;;;;;;;OAQG;IACI,MAAM,SAAS,GAAI,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CACZ,CAAC;CAC7C"}
|