functype 1.27.2 → 2.0.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/README.md +63 -88
- package/dist/_virtual/_rolldown/runtime.js +1 -0
- package/dist/branded/ValidatedBrand.d.ts +122 -0
- package/dist/branded/ValidatedBrand.js +1 -0
- package/dist/branded/index.d.ts +52 -2
- package/dist/cli/data.d.ts +37 -0
- package/dist/cli/data.js +1 -0
- package/dist/cli/exports.d.ts +5 -46
- package/dist/cli/exports.js +1 -1
- package/dist/cli/formatters.js +4 -0
- package/dist/cli/full-interfaces.d.ts +6 -0
- package/dist/cli/full-interfaces.js +1139 -0
- package/dist/cli/index.js +3 -6
- package/dist/cli/interfaces.generated.js +1 -0
- package/dist/collections/index.d.ts +13 -0
- package/dist/companion/Companion.d.ts +23 -0
- package/dist/companion/Companion.js +1 -0
- package/dist/companion/CompanionTypes.d.ts +30 -0
- package/dist/{CompanionTypes-BVqO7Kc2.js → companion/CompanionTypes.js} +1 -1
- package/dist/companion/index.d.ts +2 -1
- package/dist/companion/index.js +1 -1
- package/dist/conditional/Cond.d.ts +147 -0
- package/dist/conditional/Cond.js +1 -0
- package/dist/conditional/Match.d.ts +295 -0
- package/dist/conditional/Match.js +1 -0
- package/dist/conditional/index.d.ts +3 -2
- package/dist/conditional/index.js +1 -1
- package/dist/core/base/Base.d.ts +12 -0
- package/dist/core/base/Base.js +1 -0
- package/dist/core/throwable/Throwable.d.ts +38 -0
- package/dist/core/throwable/Throwable.js +1 -0
- package/dist/decoder/Decoder.d.ts +15 -0
- package/dist/decoder/DecoderCompanion.js +1 -0
- package/dist/decoder/DecoderError.d.ts +56 -0
- package/dist/decoder/DecoderError.js +2 -0
- package/dist/decoder/Encoder.d.ts +15 -0
- package/dist/decoder/index.d.ts +71 -2
- package/dist/decoder/index.js +1 -1
- package/dist/decoder/tagged.js +1 -0
- package/dist/do/index.d.ts +246 -2
- package/dist/do/index.js +1 -1
- package/dist/do/protocol.d.ts +29 -0
- package/dist/either/index.d.ts +279 -2
- package/dist/either/index.js +1 -1
- package/dist/error/ErrorChain.d.ts +60 -0
- package/dist/error/ErrorChain.js +4 -0
- package/dist/error/ErrorFormatter.d.ts +67 -0
- package/dist/error/ErrorFormatter.js +6 -0
- package/dist/error/ParseError.d.ts +6 -0
- package/dist/error/ParseError.js +1 -0
- package/dist/error/typed/TypedError.d.ts +146 -0
- package/dist/error/typed/TypedError.js +1 -0
- package/dist/error/typed/Validation.d.ts +76 -0
- package/dist/error/typed/Validation.js +1 -0
- package/dist/extractable/Extractable.d.ts +62 -0
- package/dist/extractable/Extractable.js +1 -0
- package/dist/fetch/Http.d.ts +32 -0
- package/dist/fetch/Http.js +1 -0
- package/dist/fetch/HttpClient.d.ts +80 -0
- package/dist/fetch/HttpClient.js +1 -0
- package/dist/fetch/HttpError.d.ts +57 -0
- package/dist/fetch/HttpError.js +1 -0
- package/dist/fetch/HttpRequest.d.ts +103 -0
- package/dist/fetch/index.d.ts +5 -2
- package/dist/fetch/index.js +1 -1
- package/dist/foldable/Foldable.d.ts +27 -0
- package/dist/foldable/index.d.ts +55 -0
- package/dist/foldable/index.js +1 -0
- package/dist/functype/Functype.d.ts +76 -0
- package/dist/functype/FunctypeSum.d.ts +39 -0
- package/dist/functype/index.d.ts +4 -2
- package/dist/hkt/index.d.ts +68 -0
- package/dist/hkt/index.js +1 -0
- package/dist/identity/Identity.d.ts +34 -0
- package/dist/identity/Identity.js +1 -0
- package/dist/index.d.ts +74 -8
- package/dist/index.js +1 -1
- package/dist/internal/base64.js +1 -0
- package/dist/internal/call-alone.js +1 -0
- package/dist/internal/concurrency.d.ts +11 -0
- package/dist/internal/concurrency.js +1 -0
- package/dist/internal/define.js +1 -0
- package/dist/internal/mutation-utils.js +1 -0
- package/dist/internal/signal.js +1 -0
- package/dist/internal/stringify.js +1 -0
- package/dist/invariant/index.d.ts +32 -2
- package/dist/io/Context.d.ts +112 -0
- package/dist/io/Context.js +1 -0
- package/dist/io/Exit.d.ts +249 -0
- package/dist/io/Exit.js +1 -0
- package/dist/io/IO.d.ts +1243 -0
- package/dist/io/IO.js +1 -0
- package/dist/io/Layer.d.ts +139 -0
- package/dist/io/Layer.js +1 -0
- package/dist/io/SpanTracer.d.ts +78 -0
- package/dist/io/SpanTracer.js +1 -0
- package/dist/io/Tag.d.ts +75 -0
- package/dist/io/Tag.js +1 -0
- package/dist/io/TestClock.d.ts +133 -0
- package/dist/io/TestClock.js +1 -0
- package/dist/io/index.d.ts +41 -2
- package/dist/io/index.js +1 -1
- package/dist/lazy/Lazy.d.ts +312 -0
- package/dist/lazy/Lazy.js +1 -0
- package/dist/lazy/index.d.ts +2 -2
- package/dist/lazy/index.js +1 -1
- package/dist/list/LazyList.d.ts +182 -0
- package/dist/list/LazyList.js +1 -0
- package/dist/list/index.d.ts +137 -2
- package/dist/list/index.js +1 -1
- package/dist/logger/index.d.ts +24 -2
- package/dist/map/index.d.ts +95 -2
- package/dist/map/index.js +1 -1
- package/dist/map/shim.d.ts +13 -0
- package/dist/map/shim.js +1 -0
- package/dist/matchable/Matchable.d.ts +38 -0
- package/dist/matchable/Matchable.js +1 -0
- package/dist/obj/Obj.d.ts +212 -0
- package/dist/obj/Obj.js +1 -0
- package/dist/obj/index.d.ts +2 -2
- package/dist/obj/index.js +1 -1
- package/dist/option/index.d.ts +304 -2
- package/dist/option/index.js +1 -1
- package/dist/package.json.js +1 -0
- package/dist/pipe/index.d.ts +14 -0
- package/dist/ref/Ref.d.ts +77 -0
- package/dist/ref/Ref.js +1 -0
- package/dist/reshapeable/Reshapeable.d.ts +90 -0
- package/dist/serializable/Serializable.d.ts +39 -0
- package/dist/serialization/Serialization.d.ts +147 -0
- package/dist/serialization/Serialization.js +1 -0
- package/dist/serialization/SerializationCompanion.d.ts +125 -0
- package/dist/serialization/SerializationCompanion.js +1 -0
- package/dist/serialization/error-envelope.d.ts +44 -0
- package/dist/serialization/error-envelope.js +1 -0
- package/dist/serialization/index.d.ts +4 -2
- package/dist/serialization/index.js +1 -1
- package/dist/set/index.d.ts +106 -2
- package/dist/set/index.js +1 -1
- package/dist/stack/Stack.d.ts +120 -0
- package/dist/stack/Stack.js +1 -0
- package/dist/traced/TraceEvent.d.ts +27 -0
- package/dist/traced/TracedOption.d.ts +46 -0
- package/dist/traced/TracedOption.js +1 -0
- package/dist/traced/Tracer.d.ts +26 -0
- package/dist/traversable/KVTraversable.d.ts +14 -0
- package/dist/traversable/Traversable.d.ts +30 -0
- package/dist/try/index.d.ts +238 -2
- package/dist/try/index.js +1 -1
- package/dist/tuple/index.d.ts +92 -2
- package/dist/tuple/index.js +1 -1
- package/dist/typeable/Typeable.d.ts +40 -0
- package/dist/typeable/Typeable.js +1 -0
- package/dist/typeclass/ContainerOps.d.ts +131 -0
- package/dist/typeclass/Functor.d.ts +41 -0
- package/dist/typeclass/Promisable.d.ts +33 -0
- package/dist/typeclass/index.d.ts +4 -1
- package/dist/typeclass/index.js +1 -1
- package/dist/typeclass/variance.d.ts +54 -0
- package/dist/typeclass/variance.js +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/util/index.d.ts +1 -3
- package/dist/valuable/Valuable.d.ts +28 -0
- package/dist/valuable/Valuable.js +1 -0
- package/dist/wire/index.d.ts +40 -2
- package/package.json +7 -12
- package/dist/Brand-bfnGXuum.d.ts +0 -54
- package/dist/Companion-DiOMBHDG.js +0 -1
- package/dist/CompanionTypes-Cc90cQ4P.d.ts +0 -58
- package/dist/Invariant-DEan-SxV.d.ts +0 -35
- package/dist/Logger-BmprRS8v.d.ts +0 -27
- package/dist/Tuple-B8KM-H8Y.d.ts +0 -213
- package/dist/Wire-3hvw0Ogg.d.ts +0 -42
- package/dist/core/task/index.d.ts +0 -2
- package/dist/core/task/index.js +0 -1
- package/dist/full-interfaces-BadxJrCt.js +0 -1202
- package/dist/index-CLYh2qZu.d.ts +0 -6649
- package/dist/rolldown-runtime-DK3Fl9T5.js +0 -1
- package/dist/serialization-9_SyrfdG.js +0 -3
- package/dist/src-BQPeS6p2.js +0 -10
- package/dist/typeclass-C61yDVYd.js +0 -1
package/dist/list/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Companion as e}from"../companion/Companion.js";import{Left as t,Right as n}from"../either/index.js";import{base64ToUtf8 as r}from"../internal/base64.js";import{traverseWithConcurrency as i}from"../internal/concurrency.js";import{define as a}from"../internal/define.js";import{safeStringify as o}from"../internal/stringify.js";import{None as s,Option as c}from"../option/index.js";import{createSerializer as l,expectMarker as u}from"../serialization/SerializationCompanion.js";import{Set as d}from"../set/index.js";import{Try as f}from"../try/index.js";import{isTypeable as p}from"../typeable/Typeable.js";import{reduceRightWiden as m,reduceWiden as h}from"../typeclass/variance.js";const g=e=>Array.isArray(e)||typeof e==`object`&&!!e&&Symbol.iterator in e,_=a()(`List`,{[Symbol.toStringTag]:`List`,get size(){return this.value.length},get length(){return this.value.length},get isEmpty(){return this.value.length===0},[Symbol.iterator](){return this.value[Symbol.iterator]()},head(){return this.value[0]},headOption(){return c(this.value[0])},last(){return this.value[this.value.length-1]},lastOption(){return c(this.value[this.value.length-1])},tail(){return v(this.value.slice(1))},init(){return v(this.value.slice(0,-1))},map(e){return v(this.value.map(e))},ap(e){let t=e.toArray();return v(this.value.flatMap(e=>t.map(t=>t(e))))},flatMap(e){return v(this.value.flatMap(t=>Array.from(e(t))))},async flatMapAsync(e,t){let n=await i(this.value,e,t?.concurrency??`unbounded`);return v(n.flatMap(e=>Array.from(e)))},async mapAsync(e,t){return v(await i(this.value,e,t?.concurrency??1))},forEach(e){this.value.forEach(e)},contains(e){return this.value.includes(e)},count(e){return this.value.filter(e).length},exists(e){return this.value.some(e)},every(e){return this.value.every(e)},filter(e){return v(this.value.filter(e))},filterNot(e){return v(this.value.filter(t=>!e(t)))},filterType(e){return v(this.value.filter(t=>p(t,e)))},find(e,t){let n=this.value.find(n=>e(n)&&(!t||p(n,t)));return c(n)},toArray(){return[...this.value]},reduce(e){return h(this.value,e)},reduceRight(e){return m(this.value,e)},fold(e,t){return this.value.reduce(t,e)},foldLeft(e){return t=>this.value.reduce(t,e)},foldRight(e){return t=>this.value.reduceRight((e,n)=>t(n,e),e)},match(e){return this.value.length===0?e.Empty():e.NonEmpty([...this.value])},remove(e){return v(this.value.filter(t=>t!==e))},removeAt(e){return e<0||e>=this.value.length?this:v([...this.value.slice(0,e),...this.value.slice(e+1)])},add(e){return v([...this.value,e])},get(e){return c(this.value[e])},concat(e){return v([...this.value,...e.toArray()])},take(e){return v(this.value.slice(0,Math.max(0,e)))},takeWhile(e){let t=[];for(let n of this.value){if(!e(n))break;t.push(n)}return v(t)},takeRight(e){return v(e>0?this.value.slice(-e):[])},reverse(){return v([...this.value].reverse())},indexOf(e){return this.value.indexOf(e)},prepend(e){return v([e,...this.value])},distinct(){let e=new globalThis.Set,t=[];for(let n of this.value)e.has(n)||(e.add(n),t.push(n));return v(t)},sorted(e){return v([...this.value].sort(e))},sortBy(e,t){return v([...this.value].sort((n,r)=>{let i=e(n),a=e(r);return t?t(i,a):i<a?-1:+(i>a)}))},zip(e){let t=e.toArray(),n=Math.min(this.value.length,t.length),r=[];for(let e=0;e<n;e++)r.push([this.value[e],t[e]]);return v(r)},zipWithIndex(){return v(this.value.map((e,t)=>[e,t]))},groupBy(e){let t=new globalThis.Map;for(let n of this.value){let r=e(n),i=t.get(r)??[];i.push(n),t.set(r,i)}let n=new globalThis.Map;for(let[e,r]of t)n.set(e,v(r));return n},partition(e){let t=[],n=[];for(let r of this.value)e(r)?t.push(r):n.push(r);return[v(t),v(n)]},span(e){let t=this.value.findIndex(t=>!e(t));return t===-1?[this,v([])]:[v(this.value.slice(0,t)),v(this.value.slice(t))]},slice(e,t){return v(this.value.slice(e,t))},drop(e){return v(this.value.slice(Math.max(0,e)))},dropRight(e){return e>0?v(this.value.slice(0,Math.max(0,this.value.length-Math.trunc(e)))):this},dropWhile(e){let t=this.value.findIndex(t=>!e(t));return v(t===-1?[]:this.value.slice(t))},flatten(){return v(this.value.flatMap(e=>g(e)?[...e]:[e]))},toList(){return this},toSet(){return d(this.value)},toOption(){return this.value.length>0?c(this.value[0]):s()},toEither(e){return this.value.length>0?n(this.value[0]):t(e)},toTry(){let e=this.value;return e.length>0?f(()=>e[0]):f(()=>{throw Error(`Empty list`)})},toString(){return`List(${o(this.value)})`},toValue(){return{_tag:`List`,value:[...this.value]}},toJSON(){return{"@functype":`List`,_tag:`List`,value:[...this.value]}},pipe(e){return e([...this.value])},serialize(){return l(`List`,this.value)},doUnwrap(){return this.value.length===0?{ok:!1,empty:!0}:{ok:!0,value:this.value[0]}}}),v=e=>{let t=Object.create(_);return t._tag=`List`,t.value=e,Object.freeze(t)},y=e=>v(Array.from(e??[])),b=v(Object.freeze([])),x=(e,t)=>(u(e,`List`,t),C(e.value??[])),S={empty:()=>b,of:(...e)=>v(e),fromJSON:e=>x(JSON.parse(e),`fromJSON`),fromBinary:e=>{let t=r(e);return S.fromJSON(t)}},C=e(y,S);export{C as List};
|
package/dist/logger/index.d.ts
CHANGED
|
@@ -1,2 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Minimal Logger interface for the functype ecosystem.
|
|
3
|
+
*
|
|
4
|
+
* One shared contract every present and future sibling package can reference
|
|
5
|
+
* without inventing its own ad-hoc logger interface. Type-only — no runtime,
|
|
6
|
+
* no opinion on output format, no `console`-global dependency. Default impls
|
|
7
|
+
* live in consumer packages (e.g. `consoleBootLogger` in `functype-os/config`).
|
|
8
|
+
*
|
|
9
|
+
* Four methods, all mandatory: `debug`, `info`, `warn`, `error`. Mandatory
|
|
10
|
+
* means no defensive `logger.debug?.()` checks at call sites.
|
|
11
|
+
*
|
|
12
|
+
* Richer loggers — `DirectLogger` from `functype-log/direct` for example —
|
|
13
|
+
* structurally satisfy `Logger` because their `debug/info/warn/error(msg, meta?)`
|
|
14
|
+
* signatures are a superset. Pass them directly anywhere a `Logger` is
|
|
15
|
+
* expected; no adapter required.
|
|
16
|
+
*
|
|
17
|
+
* @category Logger
|
|
18
|
+
*/
|
|
19
|
+
export interface Logger {
|
|
20
|
+
debug(message: string, metadata?: Record<string, unknown>): void;
|
|
21
|
+
info(message: string, metadata?: Record<string, unknown>): void;
|
|
22
|
+
warn(message: string, metadata?: Record<string, unknown>): void;
|
|
23
|
+
error(message: string, metadata?: Record<string, unknown>): void;
|
|
24
|
+
}
|
package/dist/map/index.d.ts
CHANGED
|
@@ -1,2 +1,95 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Collection } from "../collections/index.js";
|
|
2
|
+
import { Typeable } from "../typeable/Typeable.js";
|
|
3
|
+
import { Foldable } from "../foldable/Foldable.js";
|
|
4
|
+
import { List } from "../list/index.js";
|
|
5
|
+
import { Option } from "../option/index.js";
|
|
6
|
+
import { Pipe } from "../pipe/index.js";
|
|
7
|
+
import { Serializable } from "../serializable/Serializable.js";
|
|
8
|
+
import { KVTraversable } from "../traversable/KVTraversable.js";
|
|
9
|
+
import { Tuple } from "../tuple/index.js";
|
|
10
|
+
export interface Map<K, out V> extends KVTraversable<Tuple<[K, V]>>, Collection<Tuple<[K, V]>>, Typeable<"Map">, Serializable<[K, V][]>, Pipe<[K, V][]>, Foldable<Tuple<[K, V]>>, Iterable<[K, V]> {
|
|
11
|
+
readonly [Symbol.toStringTag]: string;
|
|
12
|
+
readonly _tag: "Map";
|
|
13
|
+
add(item: Tuple<[K, V]>): Map<K, V>;
|
|
14
|
+
remove(value: K): Map<K, V>;
|
|
15
|
+
map<U>(f: (value: V) => U): Map<K, U>;
|
|
16
|
+
ap<U>(ff: Map<K, (value: V) => U>): Map<K, U>;
|
|
17
|
+
flatMap<K2, V2>(f: (entry: Tuple<[K, V]>) => Iterable<[K2, V2]>): Map<K2, V2>;
|
|
18
|
+
flatMapAsync<U>(f: (value: V) => PromiseLike<Map<K, U>>): PromiseLike<Map<K, U>>;
|
|
19
|
+
get(key: K): Option<V>;
|
|
20
|
+
/**
|
|
21
|
+
* Whether the map holds an entry for `key`. Keys compare like a native `Map`:
|
|
22
|
+
* by identity for objects, by `SameValueZero` otherwise.
|
|
23
|
+
*
|
|
24
|
+
* True even when the stored value is `undefined`, where `get(key)` returns `None`.
|
|
25
|
+
* For an entry check (key and value), use `contains(Tuple([k, v]))`, which
|
|
26
|
+
* compares the value with `===`.
|
|
27
|
+
* @param key - The key to look up
|
|
28
|
+
* @returns true if the map has an entry for `key`
|
|
29
|
+
*/
|
|
30
|
+
has(key: K): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* The keys, in insertion order. A List, like `Obj.keys()`.
|
|
33
|
+
* @returns A List of the map's keys
|
|
34
|
+
*/
|
|
35
|
+
keys(): List<K>;
|
|
36
|
+
/**
|
|
37
|
+
* The values, in insertion order. Duplicates are kept.
|
|
38
|
+
* @returns A List of the map's values
|
|
39
|
+
*/
|
|
40
|
+
values(): List<V>;
|
|
41
|
+
/** Returns the value for `key`, or calls `defaultValue` if the key is absent. The default is lazy. */
|
|
42
|
+
getOrElse(key: K, defaultValue: () => V): V;
|
|
43
|
+
/** Returns `Some(value)` for `key`, or calls `alternative` for an Option if the key is absent. */
|
|
44
|
+
orElse(key: K, alternative: () => Option<V>): Option<V>;
|
|
45
|
+
fold<B>(initial: B, fn: (acc: B, a: Tuple<[K, V]>) => B): B;
|
|
46
|
+
foldLeft<B>(z: B): (op: (b: B, a: Tuple<[K, V]>) => B) => B;
|
|
47
|
+
foldRight<B>(z: B): (op: (a: Tuple<[K, V]>, b: B) => B) => B;
|
|
48
|
+
/**
|
|
49
|
+
* Pattern matches over the Map, applying a handler function based on whether it's empty
|
|
50
|
+
* @param patterns - Object with handler functions for Empty and NonEmpty variants
|
|
51
|
+
* @returns The result of applying the matching handler function
|
|
52
|
+
*/
|
|
53
|
+
match<R>(patterns: {
|
|
54
|
+
Empty: () => R;
|
|
55
|
+
NonEmpty: (entries: Array<Tuple<[K, V]>>) => R;
|
|
56
|
+
}): R;
|
|
57
|
+
toValue(): {
|
|
58
|
+
_tag: "Map";
|
|
59
|
+
value: [K, V][];
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
declare const MapConstructor: <K, V>(entries?: readonly (readonly [K, V])[] | IterableIterator<[K, V]> | null) => Map<K, V>;
|
|
63
|
+
declare const MapStatics: {
|
|
64
|
+
/**
|
|
65
|
+
* Creates an empty Map
|
|
66
|
+
* Builds a new one each call: a native Map can't be frozen, so a shared empty Map could be
|
|
67
|
+
* changed for every caller through a cast. It costs about 20 ns more than a shared one.
|
|
68
|
+
* @returns An empty Map instance
|
|
69
|
+
*/
|
|
70
|
+
empty: <K, V>() => Map<K, V>;
|
|
71
|
+
/**
|
|
72
|
+
* Creates a Map from variadic key-value pair arguments
|
|
73
|
+
* @param entries - Key-value pairs to create map from
|
|
74
|
+
* @returns A Map containing the entries
|
|
75
|
+
*/
|
|
76
|
+
of: <K, V>(...entries: [K, V][]) => Map<K, V>;
|
|
77
|
+
/**
|
|
78
|
+
* Creates a Map from JSON string
|
|
79
|
+
* @param json - The JSON string
|
|
80
|
+
* @returns Map instance
|
|
81
|
+
*/
|
|
82
|
+
fromJSON: <K, V>(json: string) => Map<K, V>;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a Map from binary string
|
|
85
|
+
* @param binary - The binary string
|
|
86
|
+
* @returns Map instance
|
|
87
|
+
*/
|
|
88
|
+
fromBinary: <K, V>(binary: string) => Map<K, V>;
|
|
89
|
+
};
|
|
90
|
+
export declare const Map: MapCompanion;
|
|
91
|
+
/** The type of `Map`: its constructor and its statics, named so that errors and hovers print `MapCompanion`. */
|
|
92
|
+
export interface MapCompanion extends MapConstructorType, MapStaticsType {}
|
|
93
|
+
type MapConstructorType = typeof MapConstructor;
|
|
94
|
+
type MapStaticsType = typeof MapStatics;
|
|
95
|
+
export {};
|
package/dist/map/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Companion as e}from"../companion/Companion.js";import{base64ToUtf8 as t}from"../internal/base64.js";import{define as n}from"../internal/define.js";import{List as r}from"../list/index.js";import{Option as i}from"../option/index.js";import{createSerializer as a,expectMarker as o}from"../serialization/SerializationCompanion.js";import{Set as s}from"../set/index.js";import{Tuple as c}from"../tuple/index.js";import{ESMap as l}from"./shim.js";const u=e=>Array.from(e,([e,t])=>c([e,t])),d=n()(`Map`,{[Symbol.toStringTag]:`FunctypeMap`,get size(){return this.value.size},get isEmpty(){return this.value.size===0},[Symbol.iterator](){return this.value.entries()},add(e){let[t,n]=e.toArray();return f(new l(this.value).set(t,n))},remove(e){if(!this.value.has(e))return this;let t=new l(this.value);return t.delete(e),f(t)},contains(e){if(!e||typeof e.toArray!=`function`)return!1;let[t,n]=e.toArray();return this.value.get(t)===n},map(e){return f(new l(Array.from(this.value,([t,n])=>[t,e(n)])))},flatMap(e){return f(new l(u(this.value).flatMap(t=>Array.from(e(t)))))},ap(e){let t=[];for(let[n,r]of this.value){let i=e.get(n);i._tag===`Some`&&i.value&&t.push([n,i.value(r)])}return f(new l(t))},async flatMapAsync(e){let t=new l;for(let n of this.value.values()){let r=await e(n);for(let[e,n]of r)t.set(e,n)}return f(t)},reduce(e){return r(u(this.value)).reduce(e)},reduceRight(e){return r(u(this.value)).reduceRight(e)},foldLeft(e){return t=>u(this.value).reduce(t,e)},foldRight(e){return t=>u(this.value).reduceRight((e,n)=>t(n,e),e)},fold(e,t){return u(this.value).reduce(t,e)},match(e){return this.value.size===0?e.Empty():e.NonEmpty(u(this.value))},get(e){return i(this.value.get(e))},has(e){return this.value.has(e)},keys(){return r(this.value.keys())},values(){return r(this.value.values())},getOrElse(e,t){return i(this.value.get(e)).getOrElse(t)},orElse(e,t){return i(this.value.get(e)).orElse(t)},toList(){return r(u(this.value))},toSet(){return s(u(this.value))},toString(){return`Map(${u(this.value).toString()})`},toValue(){return{_tag:`Map`,value:Array.from(this.value.entries())}},toJSON(){return{"@functype":`Map`,_tag:`Map`,value:Array.from(this.value.entries())}},pipe(e){return e(Array.from(this.value.entries()))},serialize(){return a(`Map`,Array.from(this.value.entries()))}}),f=e=>{let t=Object.create(d);return t._tag=`Map`,t.value=e,Object.freeze(t)},p=e=>f(new l(e)),m=(e,t)=>(o(e,`Map`,t),g(e.value??[])),h={empty:()=>f(new l),of:(...e)=>f(new l(e)),fromJSON:e=>m(JSON.parse(e),`fromJSON`),fromBinary:e=>{let n=t(e);return h.fromJSON(n)}},g=e(p,h);export{g as Map};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type alias for the native JavaScript Map
|
|
3
|
+
* @interface
|
|
4
|
+
* @module Map
|
|
5
|
+
* @category Collections
|
|
6
|
+
*/
|
|
7
|
+
export type ESMapType<K, V> = Map<K, V>;
|
|
8
|
+
/**
|
|
9
|
+
* Reference to the native JavaScript Map
|
|
10
|
+
* @module Map
|
|
11
|
+
* @category Collections
|
|
12
|
+
*/
|
|
13
|
+
export declare const ESMap: MapConstructor;
|
package/dist/map/shim.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=Map;export{e as ESMap};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pattern matching interface for functional data types.
|
|
3
|
+
*
|
|
4
|
+
* @typeParam A - The type of elements in the data structure
|
|
5
|
+
* @typeParam Tags - The type of tags used for pattern matching
|
|
6
|
+
*/
|
|
7
|
+
export interface Matchable<out A, Tags extends string = string> {
|
|
8
|
+
/**
|
|
9
|
+
* Pattern matches against this data structure, applying handlers for each variant based on tag.
|
|
10
|
+
* Similar to fold but with stronger type safety for tag-based variants.
|
|
11
|
+
*
|
|
12
|
+
* The return type is inferred from the pattern handlers when not explicitly specified.
|
|
13
|
+
*
|
|
14
|
+
* @param patterns - An object containing handler functions for each variant
|
|
15
|
+
* @returns The result of applying the matching handler function
|
|
16
|
+
*/
|
|
17
|
+
match<R>(patterns: Record<Tags, (value: A) => R>): R;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Utility functions for working with Matchable data structures
|
|
21
|
+
*/
|
|
22
|
+
export declare const MatchableUtils: {
|
|
23
|
+
/**
|
|
24
|
+
* Helper function to create a default case for pattern matching
|
|
25
|
+
*
|
|
26
|
+
* @param handler - The default handler function to apply
|
|
27
|
+
* @returns A function that always applies the default handler
|
|
28
|
+
*/
|
|
29
|
+
default: <A, R>(handler: (value: A) => R) => (value: A) => R;
|
|
30
|
+
/**
|
|
31
|
+
* Helper function to create a match pattern that guards based on a predicate
|
|
32
|
+
*
|
|
33
|
+
* @param predicate - The predicate function for guarding
|
|
34
|
+
* @param handler - The handler function to apply if the predicate passes
|
|
35
|
+
* @returns A function that applies the handler only if the predicate passes
|
|
36
|
+
*/
|
|
37
|
+
when: <A, R>(predicate: (value: A) => boolean, handler: (value: A) => R) => (value: A) => R | undefined;
|
|
38
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={default:e=>t=>e(t),when:(e,t)=>n=>e(n)?t(n):void 0};export{e as MatchableUtils};
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { Doable } from "../do/protocol.js";
|
|
2
|
+
import { FunctypeValue } from "../functype/Functype.js";
|
|
3
|
+
import { Option } from "../option/index.js";
|
|
4
|
+
import { Reshapeable } from "../reshapeable/Reshapeable.js";
|
|
5
|
+
import { Tuple } from "../tuple/index.js";
|
|
6
|
+
import { Promisable } from "../typeclass/Promisable.js";
|
|
7
|
+
import { Type } from "../types/index.js";
|
|
8
|
+
import { List } from "../list/index.js";
|
|
9
|
+
/**
|
|
10
|
+
* Obj type module
|
|
11
|
+
* @module Obj
|
|
12
|
+
* @category Core
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* The Obj type wraps a plain JavaScript object and provides fluent,
|
|
16
|
+
* immutable operations for building and transforming objects.
|
|
17
|
+
*
|
|
18
|
+
* @typeParam T - The record type of the contained object
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // Build HTTP headers immutably with conditional auth
|
|
23
|
+
* const headers = Obj({ "User-Agent": userAgent })
|
|
24
|
+
* .assign(options.headers)
|
|
25
|
+
* .when(requiresAuth, { Authorization: `Bearer ${token}` })
|
|
26
|
+
* .value()
|
|
27
|
+
*
|
|
28
|
+
* // Fluent object construction
|
|
29
|
+
* Obj.of({ name: "John" })
|
|
30
|
+
* .set("age", 31)
|
|
31
|
+
* .merge({ city: "NYC" })
|
|
32
|
+
* .value()
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export interface Obj<T extends Record<string, Type>> extends FunctypeValue<T, "Obj">, Promisable<T>, Doable<T>, Reshapeable<T> {
|
|
36
|
+
/** The contained object value */
|
|
37
|
+
readonly data: T;
|
|
38
|
+
/**
|
|
39
|
+
* Maps the contained object to a new object using the provided function
|
|
40
|
+
* @param f - The mapping function (must return a Record)
|
|
41
|
+
* @returns A new Obj containing the mapped value
|
|
42
|
+
*/
|
|
43
|
+
map<U extends Record<string, Type>>(f: (value: T) => U): Obj<U>;
|
|
44
|
+
/**
|
|
45
|
+
* FlatMaps the contained object using a function that returns an Obj
|
|
46
|
+
* @param f - The flatMap function
|
|
47
|
+
* @returns The Obj returned by f
|
|
48
|
+
*/
|
|
49
|
+
flatMap<U extends Record<string, Type>>(f: (value: T) => Obj<U>): Obj<U>;
|
|
50
|
+
/**
|
|
51
|
+
* Async flatMap for the contained object
|
|
52
|
+
* @param f - The async flatMap function
|
|
53
|
+
* @returns A Promise of the Obj returned by f
|
|
54
|
+
*/
|
|
55
|
+
flatMapAsync<U extends Record<string, Type>>(f: (value: T) => PromiseLike<Obj<U>>): PromiseLike<Obj<U>>;
|
|
56
|
+
/**
|
|
57
|
+
* Applies a wrapped function to the contained object
|
|
58
|
+
* @param ff - An Obj containing a function from T to U
|
|
59
|
+
* @returns A new Obj containing the result
|
|
60
|
+
*/
|
|
61
|
+
ap<U extends Record<string, Type>>(ff: Obj<Record<string, Type>>): Obj<U>;
|
|
62
|
+
/**
|
|
63
|
+
* Get a value by key, returning Option
|
|
64
|
+
* @param key - The key to look up
|
|
65
|
+
* @returns Option containing the value if present
|
|
66
|
+
*/
|
|
67
|
+
get<K extends keyof T>(key: K): Option<T[K]>;
|
|
68
|
+
/**
|
|
69
|
+
* Set a single key to a new value, returning a new Obj
|
|
70
|
+
* @param key - The key to set (must exist in T)
|
|
71
|
+
* @param value - The value to set
|
|
72
|
+
* @returns A new Obj with the updated key
|
|
73
|
+
*/
|
|
74
|
+
set<K extends keyof T>(key: K, value: T[K]): Obj<T>;
|
|
75
|
+
/**
|
|
76
|
+
* Merge a partial of the same shape (no new keys)
|
|
77
|
+
* @param partial - Partial object to merge
|
|
78
|
+
* @returns A new Obj with merged values
|
|
79
|
+
*/
|
|
80
|
+
assign(partial: Partial<T>): Obj<T>;
|
|
81
|
+
/**
|
|
82
|
+
* Merge with a potentially wider type (can add new keys)
|
|
83
|
+
* @param other - Object to merge in
|
|
84
|
+
* @returns A new Obj with the merged type
|
|
85
|
+
*/
|
|
86
|
+
merge<U extends Record<string, Type>>(other: U): Obj<T & U>;
|
|
87
|
+
/**
|
|
88
|
+
* Conditionally merge a partial based on a boolean or predicate
|
|
89
|
+
* @param condition - Boolean or predicate function
|
|
90
|
+
* @param partial - Partial to merge if condition is true
|
|
91
|
+
* @returns A new Obj, with or without the merge applied
|
|
92
|
+
*/
|
|
93
|
+
when(condition: boolean | (() => boolean), partial: Partial<T>): Obj<T>;
|
|
94
|
+
/**
|
|
95
|
+
* Return a new Obj without the specified keys
|
|
96
|
+
* @param keys - Keys to remove
|
|
97
|
+
* @returns A new Obj without the specified keys
|
|
98
|
+
*/
|
|
99
|
+
omit<K extends keyof T>(...keys: K[]): Obj<Omit<T, K>>;
|
|
100
|
+
/**
|
|
101
|
+
* Return a new Obj with only the specified keys
|
|
102
|
+
* @param keys - Keys to keep
|
|
103
|
+
* @returns A new Obj with only the specified keys
|
|
104
|
+
*/
|
|
105
|
+
pick<K extends keyof T>(...keys: K[]): Obj<Pick<T, K>>;
|
|
106
|
+
/**
|
|
107
|
+
* Return a List of keys
|
|
108
|
+
* @returns List of string keys
|
|
109
|
+
*/
|
|
110
|
+
keys(): List<string>;
|
|
111
|
+
/**
|
|
112
|
+
* Return a List of values
|
|
113
|
+
* @returns List of values
|
|
114
|
+
*/
|
|
115
|
+
values(): List<T[keyof T]>;
|
|
116
|
+
/**
|
|
117
|
+
* Return a List of [key, value] Tuples
|
|
118
|
+
* @returns List of key-value Tuples
|
|
119
|
+
*/
|
|
120
|
+
entries(): List<ReturnType<typeof Tuple<[string, T[keyof T]]>>>;
|
|
121
|
+
/**
|
|
122
|
+
* Unwrap to the plain object
|
|
123
|
+
* @returns The contained plain object
|
|
124
|
+
*/
|
|
125
|
+
value(): T;
|
|
126
|
+
/**
|
|
127
|
+
* Check if a key exists
|
|
128
|
+
* @param key - The key to check
|
|
129
|
+
* @returns true if the key exists
|
|
130
|
+
*/
|
|
131
|
+
has<K extends keyof T>(key: K): boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Pattern match fold — applies onEmpty if empty, onValue if non-empty
|
|
134
|
+
* @param onEmpty - Handler for empty Obj
|
|
135
|
+
* @param onValue - Handler for non-empty Obj
|
|
136
|
+
* @returns The result of the matching handler
|
|
137
|
+
*/
|
|
138
|
+
fold<U extends Type>(onEmpty: () => U, onValue: (value: T) => U): U;
|
|
139
|
+
/**
|
|
140
|
+
* Returns a string representation of this Obj
|
|
141
|
+
* @returns A string representation
|
|
142
|
+
*/
|
|
143
|
+
toString(): string;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Creates an Obj wrapping a plain object.
|
|
147
|
+
* Returns an immutable wrapper with fluent chainable operations.
|
|
148
|
+
*
|
|
149
|
+
* @param data - The plain object to wrap
|
|
150
|
+
* @returns A new Obj instance
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const obj = Obj({ name: "John", age: 30 })
|
|
155
|
+
* obj.get("name") // Some("John")
|
|
156
|
+
* obj.set("age", 31).value() // { name: "John", age: 31 }
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
declare const ObjConstructor: <T extends Record<string, Type>>(data: T) => Obj<T>;
|
|
160
|
+
declare const ObjStatics: {
|
|
161
|
+
/**
|
|
162
|
+
* Creates an Obj from a plain object. Alias for Obj().
|
|
163
|
+
* @param data - The plain object to wrap
|
|
164
|
+
* @returns A new Obj instance
|
|
165
|
+
*/
|
|
166
|
+
of: <T extends Record<string, Type>>(data: T) => Obj<T>;
|
|
167
|
+
/**
|
|
168
|
+
* Creates an empty Obj.
|
|
169
|
+
* @returns An empty Obj instance
|
|
170
|
+
*/
|
|
171
|
+
empty: <T extends Record<string, Type>>() => Obj<T>;
|
|
172
|
+
/**
|
|
173
|
+
* Deserializes an Obj from a JSON string.
|
|
174
|
+
* @param json - The JSON string to parse
|
|
175
|
+
* @returns A new Obj instance
|
|
176
|
+
*/
|
|
177
|
+
fromJSON: <T extends Record<string, Type>>(json: string) => Obj<T>;
|
|
178
|
+
/**
|
|
179
|
+
* Deserializes an Obj from a base64-encoded binary string.
|
|
180
|
+
* @param binary - The base64 string to decode
|
|
181
|
+
* @returns A new Obj instance
|
|
182
|
+
*/
|
|
183
|
+
fromBinary: <T extends Record<string, Type>>(binary: string) => Obj<T>;
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Obj - Immutable object wrapper with fluent operations.
|
|
187
|
+
*
|
|
188
|
+
* Wraps plain JavaScript objects and provides chainable, immutable
|
|
189
|
+
* operations for building and transforming them. Implements the full
|
|
190
|
+
* Functype interface (Functor, Foldable, Serializable, Matchable, etc.).
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* // Build headers with conditional auth
|
|
195
|
+
* const headers = Obj({ "User-Agent": "MyApp/1.0" })
|
|
196
|
+
* .assign(options.headers)
|
|
197
|
+
* .when(requiresAuth, { Authorization: `Bearer ${token}` })
|
|
198
|
+
* .value()
|
|
199
|
+
*
|
|
200
|
+
* // Object manipulation
|
|
201
|
+
* const user = Obj({ name: "John", age: 30, role: "admin" })
|
|
202
|
+
* user.pick("name", "role").value() // { name: "John", role: "admin" }
|
|
203
|
+
* user.omit("role").value() // { name: "John", age: 30 }
|
|
204
|
+
* user.get("name") // Some("John")
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
export declare const Obj: ObjCompanion;
|
|
208
|
+
/** The type of `Obj`: its constructor and its statics, named so that errors and hovers print `ObjCompanion`. */
|
|
209
|
+
export interface ObjCompanion extends ObjConstructorType, ObjStaticsType {}
|
|
210
|
+
type ObjConstructorType = typeof ObjConstructor;
|
|
211
|
+
type ObjStaticsType = typeof ObjStatics;
|
|
212
|
+
export {};
|
package/dist/obj/Obj.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Companion as e}from"../companion/Companion.js";import{base64ToUtf8 as t}from"../internal/base64.js";import{define as n}from"../internal/define.js";import{safeStringify as r}from"../internal/stringify.js";import{Option as i}from"../option/index.js";import{createSerializer as a}from"../serialization/SerializationCompanion.js";import{Tuple as o}from"../tuple/index.js";import{List as s}from"../list/index.js";import{Right as c}from"../either/index.js";import{Try as l}from"../try/index.js";const u=n()(`Obj`,{[Symbol.toStringTag]:`Obj`,get isEmpty(){return Object.keys(this.data).length===0},get size(){return Object.keys(this.data).length},get(e){return i(this.data[e])},set(e,t){return d({...this.data,[e]:t})},assign(e){return d({...this.data,...e})},merge(e){return d({...this.data,...e})},when(e,t){return(typeof e==`function`?e():e)?d({...this.data,...t}):d(this.data)},omit(...e){let t={...this.data};for(let n of e)delete t[n];return d(t)},pick(...e){let t={};for(let n of e)n in this.data&&(t[n]=this.data[n]);return d(t)},keys(){return s(Object.keys(this.data))},values(){return s(Object.values(this.data))},entries(){return s(Object.entries(this.data).map(([e,t])=>o([e,t])))},has(e){return e in this.data},value(){return this.data},map(e){return d(e(this.data))},flatMap(e){return e(this.data)},async flatMapAsync(e){return await e(this.data)},ap(e){let t=e.data;return d(t(this.data))},fold(e,t){return Object.keys(this.data).length===0?e():t(this.data)},match(e){return e.Obj(this.data)},foldLeft(e){return t=>t(e,this.data)},foldRight(e){return t=>t(this.data,e)},count(e){return+!!e(this.data)},find(e){return e(this.data)?i(this.data):i(void 0)},exists(e){return e(this.data)},forEach(e){e(this.data)},reduce(e){return this.data},reduceRight(e){return this.data},contains(e){return JSON.stringify(this.data)===JSON.stringify(e)},getOrElse(){return this.data},orThrow(){return this.data},orElse(e){return d(this.data)},orNull(){return this.data},orUndefined(){return this.data},toOption(){return i(this.data)},toEither(e){return c(this.data)},toList(){return s([this.data])},toTry(){let{data:e}=this;return l(()=>e)},toPromise(){return Promise.resolve(this.data)},toString(){return`Obj(${r(this.data)})`},toValue(){return{_tag:`Obj`,value:this.data}},toJSON(){return{"@functype":`Obj`,_tag:`Obj`,value:this.data}},pipe(e){return e(this.data)},serialize(){return a(`Obj`,this.data)},doUnwrap(){return{ok:!0,value:this.data}}}),d=e=>{let t=Object.create(u);return t._tag=`Obj`,t.data=e,Object.freeze(t)},f=e=>d(e),p={of:e=>d(e),empty:()=>d({}),fromJSON:e=>{let t=JSON.parse(e);if(t[`@functype`]!==void 0&&t[`@functype`]!==`Obj`)throw Error(`Obj.fromJSON: expected @functype="Obj", got ${JSON.stringify(t[`@functype`])}`);return d(t.value)},fromBinary:e=>{let n=t(e);return p.fromJSON(n)}},m=e(f,p);export{m as Obj};
|
package/dist/obj/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { Obj };
|
|
1
|
+
import { Obj, ObjCompanion } from "./Obj.js";
|
|
2
|
+
export { Obj, ObjCompanion };
|
package/dist/obj/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export{Obj}from"./Obj.js";
|