@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
  [![npm](https://img.shields.io/npm/v/@nlozgachev/pipekit?style=for-the-badge&color=000&logo=npm&label&logoColor=fff)](https://www.npmjs.com/package/@nlozgachev/pipekit)[![JSR Version](https://img.shields.io/jsr/v/@nlozgachev/pipekit?style=for-the-badge&color=000&logo=jsr&label&logoColor=fff)](https://jsr.io/@nlozgachev/pipekit)[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/nlozgachev/pipekit/publish.yml?style=for-the-badge&color=000&logo=githubactions&label&logoColor=fff)](https://github.com/nlozgachev/pipekit/actions/workflows/publish.yml)[![Codecov](https://img.shields.io/codecov/c/github/nlozgachev/pipekit?style=for-the-badge&color=000&logo=codecov&label&logoColor=fff)](https://app.codecov.io/github/nlozgachev/pipekit)[![TypeScript](https://img.shields.io/badge/-0?style=for-the-badge&color=000&logo=typescript&label&logoColor=fff)](https://www.typescriptlang.org)[![Deno](https://img.shields.io/badge/-0?style=for-the-badge&color=000&logo=Deno&label&logoColor=fff)](https://deno.com)
4
4
 
5
- A TypeScript toolkit for writing code that means exactly what it says.
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 might not exist. Replaces `T | null | undefined`.
31
- - **`Result<E, A>`** — an operation that succeeds or fails. Replaces `try/catch`.
32
- - **`Validation<E, A>`** — like `Result`, but accumulates all errors instead of stopping at the
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 that doesn't run until called.
35
- - **`TaskResult<E, A>`** — `Task` + `Result`. A lazy async operation that can fail.
36
- - **`TaskOption<A>`** — `Task` + `Option`. Replaces `Promise<T | null>`.
37
- - **`TaskValidation<E, A>`** — `Task` + `Validation`. For async checks that all need to run.
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`, resolved later.
45
- - **`Arr`** — array utilities that return `Option` instead of `undefined`.
46
- - **`Rec`** — record/object utilities.
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
 
@@ -1,8 +1,8 @@
1
1
  export var Deferred;
2
2
  (function (Deferred) {
3
3
  /**
4
- * Wraps a `Promise` into a `Deferred`, hiding `.catch()`, `.finally()`,
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nlozgachev/pipekit",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Simple functional programming toolkit for TypeScript",
5
5
  "keywords": [
6
6
  "functional",
@@ -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`, hiding `.catch()`, `.finally()`,
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 nothing else.
3
+ * A nominally typed, one-shot async value that supports `await` but enforces infallibility.
3
4
  *
4
- * Unlike `Promise`, `Deferred` has no `.catch()` or `.finally()`, and its
5
- * `.then()` returns `void` — so it cannot be chained. This makes it the
6
- * natural return type for `Task`, which is guaranteed to never reject.
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`, hiding `.catch()`, `.finally()`,
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;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;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,CAIvD,CAAC;IAEH;;;;;;;;OAQG;IACI,MAAM,SAAS,GAAI,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CACZ,CAAC;CAC7C"}
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"}