functype 1.0.1 → 1.2.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/dist/{Tuple-De-FhPDq.d.ts → Tuple-8yRldBty.d.ts} +37 -1
- package/dist/Tuple-knEoDiKZ.js +4 -0
- package/dist/branded/index.d.ts +1 -1
- package/dist/chunk-DK3Fl9T5.js +1 -0
- package/dist/cli/exports.d.ts +1 -0
- package/dist/cli/exports.js +1 -1
- package/dist/cli/index.js +5 -5
- package/dist/do/index.d.ts +1 -1
- package/dist/do/index.js +1 -1
- package/dist/either/index.d.ts +1 -1
- package/dist/either/index.js +1 -1
- package/dist/{full-interfaces-BmfIKqhj.js → full-interfaces-CLF4LjBB.js} +53 -8
- package/dist/{index-BYF5RMBp.d.ts → index-DAKubqXO.d.ts} +509 -76
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/list/index.d.ts +1 -1
- package/dist/list/index.js +1 -1
- package/dist/map/index.d.ts +1 -1
- package/dist/map/index.js +1 -1
- package/dist/option/index.d.ts +1 -1
- package/dist/option/index.js +1 -1
- package/dist/set/index.d.ts +1 -1
- package/dist/set/index.js +1 -1
- package/dist/src-CONOwKkM.js +17 -0
- package/dist/try/index.d.ts +1 -1
- package/dist/try/index.js +1 -1
- package/dist/tuple/index.d.ts +1 -1
- package/dist/tuple/index.js +1 -1
- package/package.json +12 -4
- package/dist/Tuple-DY00RBep.js +0 -1
- package/dist/src-Djzr1skt.js +0 -19
- /package/dist/{Brand-BJIRbUKB.d.ts → Brand-bfnGXuum.d.ts} +0 -0
|
@@ -54,8 +54,37 @@ interface SerializationMethods<T> {
|
|
|
54
54
|
toYAML(): string;
|
|
55
55
|
toBinary(): string;
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Shape of the envelope object emitted by a Serializable's instance-level
|
|
59
|
+
* `toJSON()` (the method native `JSON.stringify` picks up via protocol).
|
|
60
|
+
* Concrete types narrow this with their specific marker/tag literals.
|
|
61
|
+
*
|
|
62
|
+
* The `@functype` marker is the type discriminator (defends against
|
|
63
|
+
* `_tag`-collision with Effect/fp-ts). `_tag` is the variant discriminator
|
|
64
|
+
* within that type — kept across the board (variant-less types repeat the
|
|
65
|
+
* marker for back-compat with 1.1.0 readers that did `parsed._tag === "List"`).
|
|
66
|
+
*
|
|
67
|
+
* Payload shape is type-specific: canonical types carry `value`; failure
|
|
68
|
+
* branches (`Try.Failure`, `Task.Err`, `Lazy` with thrown thunk) carry
|
|
69
|
+
* `error: SerializedError` instead.
|
|
70
|
+
*/
|
|
71
|
+
interface SerializableEnvelope {
|
|
72
|
+
readonly "@functype": string;
|
|
73
|
+
readonly _tag: string;
|
|
74
|
+
readonly [key: string]: unknown;
|
|
75
|
+
}
|
|
57
76
|
interface Serializable<out T> {
|
|
58
77
|
serialize(): SerializationMethods<T>;
|
|
78
|
+
/**
|
|
79
|
+
* Custom JSON serialization. Returns the canonical `@functype`-marked
|
|
80
|
+
* envelope object so native `JSON.stringify` (and the rest of the JSON
|
|
81
|
+
* `toJSON` protocol) emits a round-trip-able shape that
|
|
82
|
+
* `Serialization.deserialize` can reconstruct.
|
|
83
|
+
*
|
|
84
|
+
* Added in 1.2.0. Concrete types narrow the return to their specific
|
|
85
|
+
* marker/tag literals.
|
|
86
|
+
*/
|
|
87
|
+
toJSON(): SerializableEnvelope;
|
|
59
88
|
}
|
|
60
89
|
//#endregion
|
|
61
90
|
//#region src/typeable/Typeable.d.ts
|
|
@@ -175,6 +204,13 @@ declare const Tuple: (<T extends Type[]>(values: T) => Tuple<T>) & {
|
|
|
175
204
|
* const t = Tuple.from([1, 2, 3])
|
|
176
205
|
*/
|
|
177
206
|
from: <T extends Type[]>(values: T) => Tuple<T>;
|
|
207
|
+
/**
|
|
208
|
+
* Reconstruct a Tuple from a JSON envelope emitted by `serialize().toJSON()`
|
|
209
|
+
* or instance `toJSON()`. Verifies `@functype === "Tuple"` if the marker is
|
|
210
|
+
* present (the marker became canonical in 1.2.0; older envelopes are
|
|
211
|
+
* accepted by leniently treating missing-marker as opt-in legacy).
|
|
212
|
+
*/
|
|
213
|
+
fromJSON: <T extends Type[]>(json: string) => Tuple<T>;
|
|
178
214
|
};
|
|
179
215
|
//#endregion
|
|
180
|
-
export { isTypeable as a,
|
|
216
|
+
export { isTypeable as a, SerializationMethods as c, Type as d, TypeableParams as i, Pipe as l, ExtractTag as n, Serializable as o, Typeable as r, SerializableEnvelope as s, Tuple as t, Foldable as u };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
function e(e,t){return Object.assign(e,t)}function t(t,n){return e(t,n)}function n(e){if(e===void 0||typeof e==`symbol`||typeof e==`function`)return;let t=new Set;function n(e){if(e===null)return`null`;switch(typeof e){case`string`:return JSON.stringify(e);case`number`:return isFinite(e)?String(e):`null`;case`boolean`:return String(e);case`bigint`:return`"${e}"`;case`undefined`:case`symbol`:case`function`:return}let r=e;if(t.has(r))return`"[Circular]"`;t.add(r);try{if(`toJSON`in r&&typeof r.toJSON==`function`)return n(r.toJSON());if(Array.isArray(r))return`[${r.map(e=>n(e)??`null`).join(`,`)}]`;let e=Object.keys(r).sort(),t=[];for(let i of e){let e=n(r[i]);e!==void 0&&t.push(`${JSON.stringify(i)}:${e}`)}return`{${t.join(`,`)}}`}finally{t.delete(r)}}try{return n(e)}catch{return}}const r=`@functype`,i=(e,t,n)=>({[r]:e,_tag:t??e,value:n}),a=(e,t,n)=>({[r]:e,_tag:t,...n});function o(e,t,a){let o=arguments.length===3,s=o?t:e,c=o?a:t,l=i(e,s,c);return{toJSON:()=>JSON.stringify(l),toYAML:()=>`${r}: ${e}\n_tag: ${s}\nvalue: ${n(c)}`,toBinary:()=>Buffer.from(JSON.stringify(l)).toString(`base64`)}}const s=(e,t,r)=>{let i=a(e,t,r);return{toJSON:()=>JSON.stringify(i),toYAML:()=>Object.entries(i).map(([e,t])=>`${e}: ${n(t)}`).join(`
|
|
2
|
+
`),toBinary:()=>Buffer.from(JSON.stringify(i)).toString(`base64`)}},c=e=>({toJSON:()=>JSON.stringify(e),toYAML:()=>Object.entries(e).map(([e,t])=>`${e}: ${n(t)}`).join(`
|
|
3
|
+
`),toBinary:()=>Buffer.from(JSON.stringify(e)).toString(`base64`)}),l=(e,t)=>t(JSON.parse(e)),u=(e,t)=>{let n=e.split(`
|
|
4
|
+
`),r={};for(let e of n){let t=e.indexOf(`: `);if(t===-1)continue;let n=e.substring(0,t),i=e.substring(t+2);if(!i){r[n]=null;continue}try{r[n]=i===`null`?null:JSON.parse(i)}catch{r[n]=i}}return t(r)},d=(e,t)=>l(Buffer.from(e,`base64`).toString(),t),f=e=>({fromJSON:t=>l(t,e),fromYAML:t=>u(t,e),fromBinary:t=>d(t,e)}),p=e=>{let t={[Symbol.toStringTag]:`Tuple`,_tag:`Tuple`,map:t=>m(t(e)),flatMap:t=>t(e),get:t=>e[t],toArray:()=>e,length:e.length,[Symbol.iterator](){let t=0;return{next:()=>t<e.length?{value:e[t++],done:!1}:{value:void 0,done:!0}}},fold:(t,n)=>e.reduce(n,t),foldLeft:t=>n=>e.reduce(n,t),foldRight:t=>n=>e.reduceRight((e,t)=>n(t,e),t),pipe:e=>e(t),serialize:()=>o(`Tuple`,e),toJSON:()=>({"@functype":`Tuple`,_tag:`Tuple`,value:[...e]}),toValue:()=>({_tag:`Tuple`,value:e}),toString:()=>`Tuple(${e.map(e=>String(e)).join(`, `)})`};return t},m=t(e=>p(e),{of:(...e)=>p(e),pair:(e,t)=>p([e,t]),triple:(e,t,n)=>p([e,t,n]),empty:()=>p([]),from:e=>p(e),fromJSON:e=>{let t=JSON.parse(e);if(t[`@functype`]!==void 0&&t[`@functype`]!==`Tuple`)throw Error(`Tuple.fromJSON: expected @functype="Tuple", got ${JSON.stringify(t[`@functype`])}`);return p(t.value)}});export{o as a,d as c,a as d,n as f,f as i,l,e as m,r as n,s as o,t as p,c as r,i as s,m as t,u};
|
package/dist/branded/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as ExtractBrand, c as hasBrand, i as BrandedString, l as unwrapBrand, n as BrandedBoolean, o as Unwrap, r as BrandedNumber, s as createBrander, t as Brand } from "../Brand-
|
|
1
|
+
import { a as ExtractBrand, c as hasBrand, i as BrandedString, l as unwrapBrand, n as BrandedBoolean, o as Unwrap, r as BrandedNumber, s as createBrander, t as Brand } from "../Brand-bfnGXuum.js";
|
|
2
2
|
export { Brand, BrandedBoolean, BrandedNumber, BrandedString, ExtractBrand, Unwrap, createBrander, hasBrand, unwrapBrand as unwrap, unwrapBrand };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r};export{t};
|
package/dist/cli/exports.d.ts
CHANGED
package/dist/cli/exports.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,i as t,n,r,t as i}from"../full-interfaces-
|
|
1
|
+
import{a as e,i as t,n,r,t as i}from"../full-interfaces-CLF4LjBB.js";export{n as CATEGORIES,i as FULL_INTERFACES,r as INTERFACES,t as TYPES,e as VERSION};
|
package/dist/cli/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{
|
|
3
|
-
`)},l=(
|
|
4
|
-
`).trimEnd()},u=()=>{let e=
|
|
5
|
-
`).trimEnd()},d=e=>JSON.stringify(e,null,2),f=()=>({version:r,categories:a,types:i}),p=e
|
|
2
|
+
import{Mt as e,St as t,Z as n}from"../src-CONOwKkM.js";import{a as r,i,n as a,r as o,t as s}from"../full-interfaces-CLF4LjBB.js";const c=()=>{let n=t([`functype ${r} - Scala-inspired FP for TypeScript`,``]);return t(Object.entries(a)).foldLeft(n)((n,[r,a])=>{let o=n.add(r.toUpperCase());return t(a).foldLeft(o)((t,n)=>e(i[n]).fold(()=>t,e=>{let r=e.interfaces.length>0?` [${e.interfaces.join(`, `)}]`:``;return t.add(` ${n}${r}`).add(` ${e.description}`)})).add(``)}).concat(t([`Use: npx functype <Type> for details`,`Use: npx functype interfaces for interface reference`])).toArray().join(`
|
|
3
|
+
`)},l=(n,r)=>{let i=r.interfaces.length>0?` [${r.interfaces.join(`, `)}]`:``,a=t([`create`,`transform`,`extract`,`check`,`other`]),o=t([`${n}<T>${i}`,``,r.description,``]);return a.foldLeft(o)((n,i)=>e(r.methods[i]).filter(e=>e.length>0).fold(()=>n,e=>{let r=n.add(i.toUpperCase());return t(e).foldLeft(r)((e,t)=>e.add(` ${t}`)).add(``)})).toArray().join(`
|
|
4
|
+
`).trimEnd()},u=()=>{let e=t([`INTERFACES`,``]);return t(Object.entries(o)).foldLeft(e)((e,[n,r])=>{let i=r.extends?` extends ${r.extends}`:``,a=e.add(`${n}<A>${i}`).add(` ${r.description}`);return t(r.methods).foldLeft(a)((e,t)=>e.add(` ${t}`)).add(``)}).toArray().join(`
|
|
5
|
+
`).trimEnd()},d=e=>JSON.stringify(e,null,2),f=()=>({version:r,categories:a,types:i}),p=n=>e(i[n]).map(e=>({name:n,data:e})).or(t(Object.entries(i)).find(([e])=>e.toLowerCase()===n.toLowerCase()).map(([e,t])=>({name:e,data:t}))).orUndefined(),m=()=>Object.keys(i),h=()=>o,g=e=>{let n=t(e.slice(2));return{flags:{json:n.contains(`--json`),full:n.contains(`--full`),help:n.exists(e=>e===`--help`||e===`-h`)},args:n.filter(e=>!e.startsWith(`--`)&&e!==`-h`)}},_=n=>e(s[n]).or(t(Object.entries(s)).find(([e])=>e.toLowerCase()===n.toLowerCase()).map(([,e])=>e)),v=()=>{let e=t([`FULL INTERFACE DEFINITIONS`,`=`.repeat(60),``]);return t(Object.entries(s)).foldLeft(e)((e,[n,r])=>e.concat(t([`// ${n}`,r,``,`-`.repeat(60),``]))).toArray().join(`
|
|
6
6
|
`).trimEnd()},y=()=>{console.log(`functype - API documentation for LLMs
|
|
7
7
|
|
|
8
8
|
USAGE
|
|
@@ -24,4 +24,4 @@ EXAMPLES
|
|
|
24
24
|
npx functype Option --json # Option as JSON
|
|
25
25
|
npx functype Option --full # Full TypeScript interface
|
|
26
26
|
npx functype --full # All full interfaces (large output!)
|
|
27
|
-
`)},b=e=>{console.error(`Unknown type: ${e}`),console.error(``),console.error(`Available types: ${m().join(`, `)}`),console.error(``),console.error(`Use: npx functype interfaces - for interface reference`),process.exit(1)},x=e=>console.log(e),S=(
|
|
27
|
+
`)},b=e=>{console.error(`Unknown type: ${e}`),console.error(``),console.error(`Available types: ${m().join(`, `)}`),console.error(``),console.error(`Use: npx functype interfaces - for interface reference`),process.exit(1)},x=e=>console.log(e),S=(t,n)=>e(p(t)).fold(()=>b(t),e=>{n.full?_(e.name).fold(()=>x(n.json?d({[e.name]:e.data}):l(e.name,e.data)),t=>x(n.json?d({[e.name]:{...e.data,fullInterface:t}}):t)):x(n.json?d({[e.name]:e.data}):l(e.name,e.data))});(()=>{let{flags:e,args:t}=g(process.argv);n(!0).when(()=>e.help,()=>y()).when(()=>t.isEmpty,()=>e.full?x(e.json?d(s):v()):x(e.json?d(f()):c())).when(()=>t.headOption.contains(`interfaces`),()=>x(e.json?d(h()):u())).default(()=>t.headOption.fold(()=>x(e.json?d(f()):c()),t=>S(t,e)))})();
|
package/dist/do/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Er as Doable, Tr as DoResult, a as EmptyListError, c as LeftError, d as isDoCapable, f as unwrap, i as DoGenerator, l as LeftErrorType, n as Do, o as FailureError, r as DoAsync, s as FailureErrorType, t as $, u as NoneError } from "../index-DAKubqXO.js";
|
|
2
2
|
export { $, Do, DoAsync, DoGenerator, type DoResult, type Doable, EmptyListError, FailureError, FailureErrorType, LeftError, LeftErrorType, NoneError, isDoCapable, unwrap };
|
package/dist/do/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{A as e,F as t,I as n,L as r,M as i,N as a,P as o,R as s,j as c}from"../src-CONOwKkM.js";export{e as $,c as Do,i as DoAsync,a as EmptyListError,o as FailureError,t as LeftError,n as NoneError,r as isDoCapable,s as unwrap};
|
package/dist/either/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as isRight, S as isLeft, T as tryCatchAsync, _ as Right, b as TypeCheckLeft, g as LeftOf, h as Left, m as EitherBase, p as Either, v as RightOf, w as tryCatch, x as TypeCheckRight, y as TestEither } from "../index-
|
|
1
|
+
import { C as isRight, S as isLeft, T as tryCatchAsync, _ as Right, b as TypeCheckLeft, g as LeftOf, h as Left, m as EitherBase, p as Either, v as RightOf, w as tryCatch, x as TypeCheckRight, y as TestEither } from "../index-DAKubqXO.js";
|
|
2
2
|
export { Either, EitherBase, Left, LeftOf, Right, RightOf, TestEither, TypeCheckLeft, TypeCheckRight, isLeft, isRight, tryCatch, tryCatchAsync };
|
package/dist/either/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_t as e,
|
|
1
|
+
import{_t as e,bt as t,gt as n,ht as r,mt as i,pt as a,vt as o,xt as s,yt as c}from"../src-CONOwKkM.js";export{a as Either,i as Left,r as Right,n as TypeCheckLeft,e as TypeCheckRight,o as isLeft,c as isRight,t as tryCatch,s as tryCatchAsync};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var e=`1.0.1`;const t={Option:[`Applicative`,`AsyncMonad`,`Doable`,`Extractable`,`Foldable`,`Functor`,`Matchable`,`Monad`,`Promisable`,`Reshapeable`,`Serializable`,`Traversable`],Either:[`Applicative`,`AsyncMonad`,`Doable`,`Extractable`,`Foldable`,`Functor`,`Monad`,`Promisable`,`Reshapeable`,`Serializable`],Try:[`Applicative`,`AsyncMonad`,`Doable`,`Extractable`,`Foldable`,`Functor`,`Monad`,`Promisable`,`Reshapeable`,`Serializable`],List:[`Collection`,`Doable`,`Iterable`,`Reshapeable`],Set:[`Collection`,`Iterable`],Map:[`Collection`,`Foldable`,`Iterable`,`KVTraversable`,`Serializable`],Obj:[`Doable`,`Promisable`,`Reshapeable`],Lazy:[`Applicative`,`AsyncMonad`,`Extractable`,`Foldable`,`Functor`,`Monad`,`Serializable`,`Traversable`],LazyList:[`Foldable`,`Serializable`],Tuple:[`Foldable`,`Serializable`],Task:[`Applicative`,`AsyncMonad`,`Doable`,`Extractable`,`Foldable`,`Functor`,`Monad`,`Promisable`,`Serializable`,`Traversable`]},n=e,r=(e,...n)=>Array.from(new Set([...t[e],...n])).sort(),i={Option:{description:`Safe nullable handling - Some<T> or None`,interfaces:r(`Option`),methods:{create:[`Option(v)`,`Option.none()`,`Some(v)`,`None()`],transform:[`.map(f)`,`.flatMap(f)`,`.filter(p)`,`.ap(ff)`],extract:[`.fold(n, s)`,`.foldAsync(n, s)`,`.orElse(d)`,`.orThrow()`,`.expect(() => never)`,`.orNull()`,`.match({Some, None})`],check:[`.isSome`,`.isNone`,`.isDefined`,`.isEmpty`],other:[`Option.sequence(arr)`,`Option.traverse(arr, f)`]}},Either:{description:`Error handling with Left (error) or Right (success)`,interfaces:r(`Either`,`Traversable`),methods:{create:[`Right(v)`,`Left(e)`,`Either.right(v)`,`Either.left(e)`,`Either.void()`],transform:[`.map(f)`,`.flatMap(f)`,`.mapLeft(f)`,`.swap()`],extract:[`.fold(l, r)`,`.foldAsync(l, r)`,`.orElse(d)`,`.orThrow()`,`.expect((l) => never)`,`.match({Left, Right})`],check:[`.isRight`,`.isLeft`],other:[`Either.sequence(arr)`,`Either.traverse(arr, f)`,`Either.fromNullable(v, e)`]}},Try:{description:`Wrap operations that may throw - Success<T> or Failure`,interfaces:r(`Try`,`Matchable`,`Traversable`),methods:{create:[`Try(() => expr)`,`Try.success(v)`,`Try.failure(e)`,`Try.fromPromise(p)`],transform:[`.map(f)`,`.flatMap(f)`,`.recover(f)`,`.recoverWith(f)`],extract:[`.fold(f, s)`,`.foldAsync(f, s)`,`.orElse(d)`,`.orThrow()`,`.expect((e) => never)`,`.toOption()`,`.toEither()`],check:[`.isSuccess`,`.isFailure`],other:[`Try.sequence(arr)`,`Try.traverse(arr, f)`]}},List:{description:`Immutable array with functional operations`,interfaces:r(`List`,`Functor`,`Monad`,`Foldable`,`Serializable`,`Traversable`),methods:{create:[`List([...])`,`List.of(...)`,`List.empty()`],transform:[`.map(f)`,`.flatMap(f)`,`.filter(p)`,`.take(n)`,`.takeWhile(p)`,`.takeRight(n)`,`.drop(n)`,`.dropWhile(p)`,`.concat(list)`,`.reverse()`,`.distinct()`,`.sorted()`,`.sortBy(f)`,`.zip(list)`,`.zipWithIndex()`,`.prepend(v)`,`.slice(s, e)`],extract:[`.fold(z, f)`,`.reduce(f)`,`.head`,`.headOption`,`.tail`,`.last`,`.lastOption`,`.init`,`.indexOf(v)`,`.toArray()`],check:[`.isEmpty`,`.nonEmpty`,`.size`,`.contains(v)`],other:[`.groupBy(f)`,`.partition(p)`,`.span(p)`]}},Set:{description:`Immutable set of unique values`,interfaces:r(`Set`,`Functor`,`Foldable`,`Serializable`,`Traversable`),methods:{create:[`Set([...])`,`Set.of(...)`,`Set.empty()`],transform:[`.map(f)`,`.filter(p)`,`.union(s)`,`.intersection(s)`,`.difference(s)`,`.add(v)`],extract:[`.fold(z, f)`,`.toArray()`],check:[`.has(v)`,`.isEmpty`,`.size`]}},Obj:{description:`Immutable object wrapper with fluent operations`,interfaces:r(`Obj`,`KVTraversable`,`Foldable`,`Matchable`,`Extractable`,`Serializable`),methods:{create:[`Obj({...})`,`Obj.of({...})`,`Obj.empty()`],transform:[`.set(k, v)`,`.assign(partial)`,`.merge(obj)`,`.when(cond, partial)`,`.omit(...keys)`,`.pick(...keys)`,`.map(f)`,`.flatMap(f)`],extract:[`.get(k)`,`.value()`,`.keys()`,`.values()`,`.entries()`,`.fold(n, s)`,`.match({Obj})`],check:[`.has(k)`,`.isEmpty`,`.size`]}},Map:{description:`Immutable key-value store`,interfaces:r(`Map`),methods:{create:[`Map([[k, v], ...])`,`Map.of([k, v], ...)`,`Map.empty()`],transform:[`.set(k, v)`,`.delete(k)`,`.map(f)`,`.filter(p)`,`.add(k, v)`],extract:[`.get(k)`,`.keys()`,`.values()`,`.entries()`,`.fold(z, f)`],check:[`.has(k)`,`.isEmpty`,`.size`]}},Lazy:{description:`Deferred computation with memoization`,interfaces:r(`Lazy`),methods:{create:[`Lazy(() => expr)`],transform:[`.map(f)`,`.flatMap(f)`],extract:[`.fold(n, s)`,`.orElse(d)`,`.orThrow()`,`.get()`],check:[`.isEvaluated`]}},LazyList:{description:`Lazy sequences for large/infinite data`,interfaces:r(`LazyList`,`Functor`,`Monad`,`Iterable`),methods:{create:[`LazyList.from(iter)`,`LazyList.range(start, end)`,`LazyList.infinite(f)`],transform:[`.map(f)`,`.filter(p)`,`.take(n)`,`.takeRight(n)`,`.drop(n)`,`.takeWhile(p)`,`.dropWhile(p)`,`.concat(ll)`,`.reverse()`,`.distinct()`,`.zip(ll)`,`.zipWithIndex()`],extract:[`.head`,`.headOption`,`.tail`,`.last`,`.lastOption`,`.init`,`.toArray()`],check:[`.isEmpty`]}},Task:{description:`Async operations with cancellation and progress tracking. Returns TaskOutcome<T> (Ok/Err) which implements Functor, AsyncMonad, Foldable, Extractable, Serializable`,interfaces:r(`Task`),methods:{create:[`Task(params).Async(fn, errFn)`,`Task(params).Sync(fn, errFn)`,`Task.ok(value)`,`Task.err(error)`,`Task.fromEither(either)`,`Task.fromTry(try)`,`Task.fromPromise(fn)`,`Task.fromNodeCallback(fn)`],transform:[`.map(f)`,`.flatMap(f)`,`.mapError(f)`,`.recover(v)`,`.recoverWith(f)`],extract:[`.fold(onErr, onOk)`,`.match({Ok, Err})`,`.orElse(v)`,`.orThrow()`,`.toEither()`,`.toOption()`],other:[`Task.cancellable(fn)`,`Task.withProgress(fn, onProgress)`,`Task.race(tasks, timeout?)`,`Task.getErrorChain(error)`,`Task.formatErrorChain(error)`]}},IO:{description:`Lazy effect type with typed errors and dependency injection`,interfaces:[`Functor`,`Monad`,`Foldable`,`Matchable`],methods:{create:[`IO(() => v)`,`IO.succeed(v)`,`IO.fail(e)`,`IO.sync(f)`,`IO.async(f)`,`IO.tryPromise({try, catch})`,`IO.fromEither(e)`,`IO.fromOption(o)`,`IO.fromTry(t)`],transform:[`.map(f)`,`.flatMap(f)`,`.tap(f)`,`.mapError(f)`,`.recover(v)`,`.recoverWith(f)`],extract:[`.run()`,`.runOrThrow()`,`.runSync()`,`.runSyncOrThrow()`,`.runExit()`,`.runOption()`,`.runTry()`,`.fold(onErr, onOk)`,`.match({failure, success})`],check:[],other:[`.catchTag(tag, f)`,`.catchAll(f)`,`.retry(n)`,`.retryWithDelay(n, ms)`,`.timeout(ms)`,`.delay(ms)`,`.zip(io)`,`.pipe(f)`,`IO.all([...])`,`IO.race([...])`,`IO.bracket(acquire, use, release)`,`IO.gen(function*() {...})`,`IO.Do.bind().map()`,`IO.service(Tag)`,`.provideService(Tag, impl)`,`.provideLayer(layer)`]}},Cond:{description:`Conditional expression builder - replace if-else chains`,interfaces:[],methods:{create:[`Cond<T>()`],other:[`.case(pred, result)`,`.otherwise(result)`,`.eval()`]}},Match:{description:`Pattern matching - replace switch statements`,interfaces:[],methods:{create:[`Match(value)`],other:[`.case(pattern, result)`,`.when(pred, result)`,`.default(result)`,`.done()`]}},Brand:{description:`Nominal typing without runtime overhead`,interfaces:[],methods:{create:[`Brand<K, T>(value)`],extract:[`.unwrap()`,`.toString()`]}},ValidatedBrand:{description:`Branded types with runtime validation`,interfaces:[],methods:{create:[`ValidatedBrand(validator)`,`.of(v)`,`.from(v)`,`.unsafeOf(v)`],check:[`.is(v)`],other:[`.refine(validator)`]}},Tuple:{description:`Fixed-size typed array`,interfaces:r(`Tuple`,`Typeable`,`Valuable`,`Iterable`),methods:{create:[`Tuple([a, b, ...])`,`Tuple.of(a, b, ...)`],extract:[`.first`,`.second`,`.toArray()`],transform:[`.map(f)`]}},Stack:{description:`Immutable LIFO stack`,interfaces:[`Foldable`,`Collection`,`Serializable`,`Traversable`],methods:{create:[`Stack()`,`Stack.of(...)`],transform:[`.push(v)`,`.pop()`],extract:[`.peek()`,`.toArray()`],check:[`.isEmpty`,`.size`]}},Http:{description:`HTTP fetch wrapper returning IO<never, HttpError, HttpResponse<unknown>> by default. Provide a validate function to get typed responses (BYOV: bring your own validator). Works with Zod, TypeBox, Valibot, or manual validators. The returned IO supports the full IO chain (.tap, .map, .flatMap, .catchTag, .mapError, .retry, .timeout). Http.client config accepts a beforeRequest hook — an effectful (IO-returning) transformer that closes the symmetry with the response chain so request-side concerns (auth refresh, request IDs, entry logging) compose via IO operators rather than fetch-wrapper substitution.`,interfaces:[],methods:{create:[`Http.get(url, { validate }?)`,`Http.post(url, { body, validate }?)`,`Http.put(url, { body, validate }?)`,`Http.patch(url, { body, validate }?)`,`Http.delete(url, { validate }?)`,`Http.request({ url, validate })`,`Http.client({ baseUrl, defaultHeaders, fetch, beforeRequest })`],transform:[`.tap(f)`,`.map(f)`,`.flatMap(f)`,`.mapError(f)`,`.retry(n)`,`.retryWithDelay(n, ms)`,`.timeout(ms)`],extract:[`.run()`,`.runOrThrow()`,`.runOption()`,`.runTry()`,`.runExit()`],check:[],other:[`.catchTag(tag, handler)`,`.catchAll(handler)`,`.recover(fallback)`,`beforeRequest: (req) => IO<never, HttpError, HttpRequestView>`]}},HttpError:{description:`Three-variant ADT for HTTP failures: NetworkError | HttpStatusError | DecodeError`,interfaces:[],methods:{create:[`HttpError.networkError(url, method, cause)`,`HttpError.httpStatusError(url, method, status, statusText, body)`,`HttpError.decodeError(url, method, body, cause)`],check:[`HttpError.isNetworkError(e)`,`HttpError.isHttpStatusError(e)`,`HttpError.isDecodeError(e)`],other:[`HttpError.match(error, { NetworkError, HttpStatusError, DecodeError })`]}}},a={Functor:{description:`Transform contained values`,methods:[`.map<B>(f: A => B): Functor<B>`]},Applicative:{extends:`Functor`,description:`Apply wrapped functions`,methods:[`.ap<B>(ff: Applicative<A => B>): Applicative<B>`]},Monad:{extends:`Applicative`,description:`Chain operations returning wrapped values`,methods:[`.flatMap<B>(f: A => Monad<B>): Monad<B>`]},Foldable:{description:`Extract via pattern matching`,methods:[`.fold<B>(empty: () => B, f: A => B): B`,`.foldLeft<B>(z: B, op: (B, A) => B): B`,`.foldRight<B>(z: B, op: (A, B) => B): B`]},Extractable:{description:`Get contained value with fallback`,methods:[`.orElse(d: T): T`,`.orThrow(e?: Error): T`,`.expect(handler: (e?) => never): T`,`.orNull(): T | null`,`.orUndefined(): T | undefined`]},Matchable:{description:`Pattern match on type variants`,methods:[`.match<R>(patterns: Record<Tag, Handler>): R`]},Traversable:{description:`Iterate and check contents`,methods:[`.size: number`,`.isEmpty: boolean`,`.contains(v: A): boolean`,`.reduce<B>(f, init): B`]},Collection:{description:`Collection operations`,methods:[`.toArray(): A[]`,`.forEach(f: A => void): void`]},Serializable:{description:`Convert to string formats`,methods:[`.serialize().toJSON(): string`,`.serialize().toYAML(): string`]}},o={Core:[`Option`,`Either`,`Try`,`Obj`],Collection:[`List`,`Set`,`Map`,`LazyList`,`Tuple`,`Stack`],Effect:[`IO`,`Task`,`Http`,`HttpError`],Utility:[`Lazy`,`Cond`,`Match`,`Brand`,`ValidatedBrand`]},s={Option:`export interface Option<out T extends Type>
|
|
1
|
+
var e=`1.2.0`;const t={Option:[`Applicative`,`AsyncMonad`,`Doable`,`Extractable`,`Foldable`,`Functor`,`Matchable`,`Monad`,`Promisable`,`Reshapeable`,`Serializable`,`Traversable`],Either:[`Applicative`,`AsyncMonad`,`Doable`,`Extractable`,`Foldable`,`Functor`,`Monad`,`Promisable`,`Reshapeable`,`Serializable`],Try:[`Applicative`,`AsyncMonad`,`Doable`,`Extractable`,`Foldable`,`Functor`,`Monad`,`Promisable`,`Reshapeable`,`Serializable`],List:[`Collection`,`Doable`,`Iterable`,`Reshapeable`],Set:[`Collection`,`Iterable`],Map:[`Collection`,`Foldable`,`Iterable`,`KVTraversable`,`Serializable`],Obj:[`Doable`,`Promisable`,`Reshapeable`],Lazy:[`Applicative`,`AsyncMonad`,`Extractable`,`Foldable`,`Functor`,`Monad`,`Serializable`,`Traversable`],LazyList:[`Foldable`,`Serializable`],Tuple:[`Foldable`,`Serializable`],Task:[`Applicative`,`AsyncMonad`,`Doable`,`Extractable`,`Foldable`,`Functor`,`Monad`,`Promisable`,`Serializable`,`Traversable`]},n=e,r=(e,...n)=>Array.from(new Set([...t[e],...n])).sort(),i={Option:{description:`Safe nullable handling - Some<T> or None`,interfaces:r(`Option`),methods:{create:[`Option(v)`,`Option.none()`,`Some(v)`,`None()`],transform:[`.map(f)`,`.flatMap(f)`,`.filter(p)`,`.ap(ff)`],extract:[`.fold(n, s)`,`.foldAsync(n, s)`,`.orElse(d)`,`.orThrow()`,`.expect(() => never)`,`.orNull()`,`.match({Some, None})`],check:[`.isSome`,`.isNone`,`.isDefined`,`.isEmpty`],other:[`Option.sequence(arr)`,`Option.traverse(arr, f)`]}},Either:{description:`Error handling with Left (error) or Right (success)`,interfaces:r(`Either`,`Traversable`),methods:{create:[`Right(v)`,`Left(e)`,`Either.right(v)`,`Either.left(e)`,`Either.void()`],transform:[`.map(f)`,`.flatMap(f)`,`.mapLeft(f)`,`.swap()`],extract:[`.fold(l, r)`,`.foldAsync(l, r)`,`.orElse(d)`,`.orThrow()`,`.expect((l) => never)`,`.match({Left, Right})`],check:[`.isRight`,`.isLeft`],other:[`Either.sequence(arr)`,`Either.traverse(arr, f)`,`Either.fromNullable(v, e)`]}},Try:{description:`Wrap operations that may throw - Success<T> or Failure`,interfaces:r(`Try`,`Matchable`,`Traversable`),methods:{create:[`Try(() => expr)`,`Try.success(v)`,`Try.failure(e)`,`Try.fromPromise(p)`],transform:[`.map(f)`,`.flatMap(f)`,`.recover(f)`,`.recoverWith(f)`],extract:[`.fold(f, s)`,`.foldAsync(f, s)`,`.orElse(d)`,`.orThrow()`,`.expect((e) => never)`,`.toOption()`,`.toEither()`],check:[`.isSuccess`,`.isFailure`],other:[`Try.sequence(arr)`,`Try.traverse(arr, f)`]}},List:{description:`Immutable array with functional operations`,interfaces:r(`List`,`Functor`,`Monad`,`Foldable`,`Serializable`,`Traversable`),methods:{create:[`List([...])`,`List.of(...)`,`List.empty()`],transform:[`.map(f)`,`.flatMap(f)`,`.filter(p)`,`.take(n)`,`.takeWhile(p)`,`.takeRight(n)`,`.drop(n)`,`.dropWhile(p)`,`.concat(list)`,`.reverse()`,`.distinct()`,`.sorted()`,`.sortBy(f)`,`.zip(list)`,`.zipWithIndex()`,`.prepend(v)`,`.slice(s, e)`],extract:[`.fold(z, f)`,`.reduce(f)`,`.head`,`.headOption`,`.tail`,`.last`,`.lastOption`,`.init`,`.indexOf(v)`,`.toArray()`],check:[`.isEmpty`,`.nonEmpty`,`.size`,`.contains(v)`],other:[`.groupBy(f)`,`.partition(p)`,`.span(p)`]}},Set:{description:`Immutable set of unique values`,interfaces:r(`Set`,`Functor`,`Foldable`,`Serializable`,`Traversable`),methods:{create:[`Set([...])`,`Set.of(...)`,`Set.empty()`],transform:[`.map(f)`,`.filter(p)`,`.union(s)`,`.intersection(s)`,`.difference(s)`,`.add(v)`],extract:[`.fold(z, f)`,`.toArray()`],check:[`.has(v)`,`.isEmpty`,`.size`]}},Obj:{description:`Immutable object wrapper with fluent operations`,interfaces:r(`Obj`,`KVTraversable`,`Foldable`,`Matchable`,`Extractable`,`Serializable`),methods:{create:[`Obj({...})`,`Obj.of({...})`,`Obj.empty()`],transform:[`.set(k, v)`,`.assign(partial)`,`.merge(obj)`,`.when(cond, partial)`,`.omit(...keys)`,`.pick(...keys)`,`.map(f)`,`.flatMap(f)`],extract:[`.get(k)`,`.value()`,`.keys()`,`.values()`,`.entries()`,`.fold(n, s)`,`.match({Obj})`],check:[`.has(k)`,`.isEmpty`,`.size`]}},Map:{description:`Immutable key-value store`,interfaces:r(`Map`),methods:{create:[`Map([[k, v], ...])`,`Map.of([k, v], ...)`,`Map.empty()`],transform:[`.set(k, v)`,`.delete(k)`,`.map(f)`,`.filter(p)`,`.add(k, v)`],extract:[`.get(k)`,`.keys()`,`.values()`,`.entries()`,`.fold(z, f)`],check:[`.has(k)`,`.isEmpty`,`.size`]}},Lazy:{description:"Deferred computation with memoization. Note: `serialize()` and `toValue()` FORCE the thunk (visible side effect) since a closure cannot be JSON-serialized — there is no representable 'unevaluated post-serialize' state. Thunk failures are captured via SerializedError and rethrown on access after fromJSON.",interfaces:r(`Lazy`),methods:{create:[`Lazy(() => expr)`,`Lazy.fromValue(value) — wrap a non-deferred value`,`Lazy.evaluated(value) — reads as 'already-forced'; used by fromJSON`,`Lazy.fail(error) — Lazy that throws on access`],transform:[`.map(f)`,`.flatMap(f)`],extract:[`.fold(n, s)`,`.orElse(d)`,`.orThrow()`,`.get()`,`.toJSON()`,`Lazy.fromJSON(json)`],check:[`.isEvaluated`]}},LazyList:{description:`Lazy sequences for large/infinite data`,interfaces:r(`LazyList`,`Functor`,`Monad`,`Iterable`),methods:{create:[`LazyList.from(iter)`,`LazyList.range(start, end)`,`LazyList.infinite(f)`,`LazyList.fromJSON(json)`],transform:[`.map(f)`,`.filter(p)`,`.take(n)`,`.takeRight(n)`,`.drop(n)`,`.takeWhile(p)`,`.dropWhile(p)`,`.concat(ll)`,`.reverse()`,`.distinct()`,`.zip(ll)`,`.zipWithIndex()`],extract:[`.head`,`.headOption`,`.tail`,`.last`,`.lastOption`,`.init`,`.toArray()`,`.toJSON()`],check:[`.isEmpty`]}},Task:{description:`Async operations with cancellation and progress tracking. Returns TaskOutcome<T> (Ok/Err) which implements Functor, AsyncMonad, Foldable, Extractable, Serializable`,interfaces:r(`Task`),methods:{create:[`Task(params).Async(fn, errFn)`,`Task(params).Sync(fn, errFn)`,`Task.ok(value)`,`Task.err(error)`,`Task.fromEither(either)`,`Task.fromTry(try)`,`Task.fromPromise(fn)`,`Task.fromNodeCallback(fn)`,`Task.fromJSON(json) — reconstruct from serialize() output`],transform:[`.map(f)`,`.flatMap(f)`,`.mapError(f)`,`.recover(v)`,`.recoverWith(f)`],extract:[`.fold(onErr, onOk)`,`.match({Ok, Err})`,`.orElse(v)`,`.orThrow()`,`.toEither()`,`.toOption()`,`.toJSON()`],other:[`Task.cancellable(fn)`,`Task.withProgress(fn, onProgress)`,`Task.race(tasks, timeout?)`,`Task.getErrorChain(error)`,`Task.formatErrorChain(error)`]}},IO:{description:`Lazy effect type with typed errors and dependency injection`,interfaces:[`Functor`,`Monad`,`Foldable`,`Matchable`],methods:{create:[`IO(() => v)`,`IO.succeed(v)`,`IO.fail(e)`,`IO.sync(f)`,`IO.async(f)`,`IO.tryPromise({try, catch})`,`IO.fromEither(e)`,`IO.fromOption(o)`,`IO.fromTry(t)`],transform:[`.map(f)`,`.flatMap(f)`,`.tap(f)`,`.mapError(f)`,`.recover(v)`,`.recoverWith(f)`],extract:[`.run()`,`.runOrThrow()`,`.runSync()`,`.runSyncOrThrow()`,`.runExit()`,`.runOption()`,`.runTry()`,`.fold(onErr, onOk)`,`.match({failure, success})`],check:[],other:[`.catchTag(tag, f)`,`.catchAll(f)`,`.retry(n)`,`.retryWithDelay(n, ms)`,`.timeout(ms)`,`.delay(ms)`,`.zip(io)`,`.pipe(f)`,`IO.all([...])`,`IO.race([...])`,`IO.bracket(acquire, use, release)`,`IO.gen(function*() {...})`,`IO.Do.bind().map()`,`IO.service(Tag)`,`.provideService(Tag, impl)`,`.provideLayer(layer)`]}},Cond:{description:`Conditional expression builder - replace if-else chains`,interfaces:[],methods:{create:[`Cond<T>()`],other:[`.case(pred, result)`,`.otherwise(result)`,`.eval()`]}},Match:{description:`Pattern matching - replace switch statements`,interfaces:[],methods:{create:[`Match(value)`],other:[`.case(pattern, result)`,`.when(pred, result)`,`.default(result)`,`.done()`]}},Brand:{description:`Nominal typing without runtime overhead`,interfaces:[],methods:{create:[`Brand<K, T>(value)`],extract:[`.unwrap()`,`.toString()`]}},ValidatedBrand:{description:`Branded types with runtime validation`,interfaces:[],methods:{create:[`ValidatedBrand(validator)`,`.of(v)`,`.from(v)`,`.unsafeOf(v)`],check:[`.is(v)`],other:[`.refine(validator)`]}},Tuple:{description:`Fixed-size typed array`,interfaces:r(`Tuple`,`Typeable`,`Valuable`,`Iterable`),methods:{create:[`Tuple([a, b, ...])`,`Tuple.of(a, b, ...)`,`Tuple.fromJSON(json)`],extract:[`.first`,`.second`,`.toArray()`,`.toJSON()`],transform:[`.map(f)`]}},Stack:{description:`Immutable LIFO stack`,interfaces:[`Foldable`,`Collection`,`Serializable`,`Traversable`],methods:{create:[`Stack()`,`Stack.of(...)`],transform:[`.push(v)`,`.pop()`],extract:[`.peek()`,`.toArray()`],check:[`.isEmpty`,`.size`]}},Http:{description:"HTTP fetch wrapper returning IO<never, HttpError, HttpResponse<T>>. Pass `decode: Decoder<T>` (Either-returning) for typed responses; the deprecated `validate: (data) => T` field is still accepted for throw-pattern back-compat. Request bodies auto-flatten functype ADTs to primitives; `flatten: false` preserves tagged emission for functype-to-functype services. Http.client accepts `beforeRequest` (effectful IO transformer for auth refresh, request IDs, etc.). Composes via .tap/.map/.flatMap/.catchTag/.retry/.timeout.",interfaces:[],methods:{create:[`Http.get(url, { decode }?)`,`Http.post(url, { body, decode }?)`,`Http.put(url, { body, decode }?)`,`Http.patch(url, { body, decode }?)`,`Http.delete(url, { decode }?)`,`Http.request({ url, decode })`,`Http.client({ baseUrl, defaultHeaders, fetch, beforeRequest })`],transform:[`.tap(f)`,`.map(f)`,`.flatMap(f)`,`.mapError(f)`,`.retry(n)`,`.retryWithDelay(n, ms)`,`.timeout(ms)`],extract:[`.run()`,`.runOrThrow()`,`.runOption()`,`.runTry()`,`.runExit()`],check:[],other:[`.catchTag(tag, handler)`,`.catchAll(handler)`,`.recover(fallback)`,`decode: Decoder<T> (Either-returning, structural failures preserved)`,`validate: (data) => T (deprecated, throws — for back-compat / Zod .parse)`,`flatten: boolean (default true; false preserves tagged emission)`,`beforeRequest: (req) => IO<never, HttpError, HttpRequestView>`]}},HttpError:{description:`Three-variant ADT for HTTP failures: NetworkError | HttpStatusError | DecodeError (also exported as ResponseDecodeError alias)`,interfaces:[],methods:{create:[`HttpError.networkError(url, method, cause)`,`HttpError.httpStatusError(url, method, status, statusText, body)`,`HttpError.decodeError(url, method, body, cause)`],check:[`HttpError.isNetworkError(e)`,`HttpError.isHttpStatusError(e)`,`HttpError.isDecodeError(e)`],other:[`HttpError.match(error, { NetworkError, HttpStatusError, DecodeError })`]}},Decoder:{description:"Either-returning decoder contract: `Decoder<A> = (raw: unknown) => Either<DecoderError, A>`. Bundled combinators for primitives + functype ADTs (Option/Either/List/Map, null-bias). `Decoder.tagged.*` round-trips the `{_tag, value}` shape for functype-to-functype services.",interfaces:[],methods:{create:[`Decoder.string / .number / .boolean / .unknown / .nullable(inner)`,`Decoder.option(inner)`,`Decoder.either.envelope({ok, err})`,`Decoder.either.discriminated({tag, leftTag, rightTag}, l, r)`,`Decoder.list(inner) / .array(inner) / .map(inner)`,`Decoder.object({k: Decoder<V>, ...}) — accumulates field failures into Composite`,`Decoder.tagged.option/either/try/list/map/obj(inner?) — round-trips {_tag, value}`],other:[`Pluggable by construction: any (raw) => Either<DecoderError, T> IS a Decoder<T>`,`Composes across sources: Decoder.object({a: Decoder.fromZod(s), b: Decoder.option(myAjv)})`]}},DecoderError:{description:"Recursive ADT for decoder failures: Leaf | Composite. Children mirror the input tree so multi-field failures preserve structural paths. Distinct from `HttpError.DecodeError` — this is the inner structural cause that the HTTP wrapper carries.",interfaces:[],methods:{create:[`DecoderError.leaf(path, message, cause?)`,`DecoderError.composite(path, children: List<DecoderError>)`],check:[`DecoderError.isLeaf(e)`,`DecoderError.isComposite(e)`],other:[`DecoderError.match(e, { Leaf, Composite })`,`DecoderError.prepend(segment, e) — used by combinators to attribute child failures`,`DecoderError.flatten(e): List<{path, message}> — collect leaves`,`DecoderError.format(e): string — render tree as multi-line`]}},Serialization:{description:"Universal `@functype`-marked JSON serialization. `deserialize` walks parsed JSON and reconstructs any functype value found — no type argument needed. Plain JSON passes through. Strict on unknown markers (defends against Effect/fp-ts `_tag` collision).",interfaces:[],methods:{create:[],transform:[`Serialization.serialize(value: unknown): string`,`Serialization.deserialize(json: string): Try<unknown>`],check:[`Serialization.isFunctypeValue(v): v is Serializable<unknown>`],other:[`Plain JSON passthrough: non-functype data walks through unchanged`,`Strict policy: unknown @functype marker → Try.Failure`,`Dispatch table covers all 12 Serializable types (Option, Either, Try, List, Set, Map, Obj, Stack, Tuple, LazyList, Lazy, Task)`,`No DBOS / SuperJSON facade — consumers wire host serializer in ~8 lines`]}},SerializedError:{description:"Canonical Error projection used by Try.Failure, Task.Err, Lazy-with-thrown-thunk. Round-trips name + message + stack + cause chain. `e.name === 'TypeError'` survives; `instanceof TypeError` does NOT.",interfaces:[],methods:{create:[`serializeError(err: unknown): SerializedError`,`deserializeError(s: SerializedError | string): Error`],other:[`Shape: { name: string; message: string; stack?: string; cause?: SerializedError | string }`,`Non-Error throwables (strings, plain objects) projected under name: 'NonErrorThrowable'`,`Cause chain is recursive — arbitrary nesting depth survives`]}}},a={Functor:{description:`Transform contained values`,methods:[`.map<B>(f: A => B): Functor<B>`]},Applicative:{extends:`Functor`,description:`Apply wrapped functions`,methods:[`.ap<B>(ff: Applicative<A => B>): Applicative<B>`]},Monad:{extends:`Applicative`,description:`Chain operations returning wrapped values`,methods:[`.flatMap<B>(f: A => Monad<B>): Monad<B>`]},Foldable:{description:`Extract via pattern matching`,methods:[`.fold<B>(empty: () => B, f: A => B): B`,`.foldLeft<B>(z: B, op: (B, A) => B): B`,`.foldRight<B>(z: B, op: (A, B) => B): B`]},Extractable:{description:`Get contained value with fallback`,methods:[`.orElse(d: T): T`,`.orThrow(e?: Error): T`,`.expect(handler: (e?) => never): T`,`.orNull(): T | null`,`.orUndefined(): T | undefined`]},Matchable:{description:`Pattern match on type variants`,methods:[`.match<R>(patterns: Record<Tag, Handler>): R`]},Traversable:{description:`Iterate and check contents`,methods:[`.size: number`,`.isEmpty: boolean`,`.contains(v: A): boolean`,`.reduce<B>(f, init): B`]},Collection:{description:`Collection operations`,methods:[`.toArray(): A[]`,`.forEach(f: A => void): void`]},Serializable:{description:`Convert to string formats`,methods:[`.serialize().toJSON(): string`,`.serialize().toYAML(): string`]}},o={Core:[`Option`,`Either`,`Try`,`Obj`],Collection:[`List`,`Set`,`Map`,`LazyList`,`Tuple`,`Stack`],Effect:[`IO`,`Task`,`Http`,`HttpError`,`Decoder`,`DecoderError`],Utility:[`Lazy`,`Cond`,`Match`,`Brand`,`ValidatedBrand`],Serialization:[`Serialization`,`SerializedError`]},s={Option:`export interface Option<out T extends Type>
|
|
2
2
|
extends Functype<T, "Some" | "None">, Promisable<T>, Doable<T>, Reshapeable<T> {
|
|
3
3
|
/** The contained value (undefined for None) */
|
|
4
4
|
readonly value: T | undefined
|
|
@@ -136,6 +136,12 @@ var e=`1.0.1`;const t={Option:[`Applicative`,`AsyncMonad`,`Doable`,`Extractable`
|
|
|
136
136
|
* @returns An object with _tag and value properties
|
|
137
137
|
*/
|
|
138
138
|
toValue(): { _tag: "Some" | "None"; value: T }
|
|
139
|
+
/**
|
|
140
|
+
* Custom JSON serialization producing the canonical \`@functype\`-marked
|
|
141
|
+
* envelope so native \`JSON.stringify\` recursion (e.g. inside a plain
|
|
142
|
+
* object) emits a round-trip-able shape.
|
|
143
|
+
*/
|
|
144
|
+
toJSON(): { "@functype": "Option"; _tag: "Some" | "None"; value: T | null }
|
|
139
145
|
/**
|
|
140
146
|
* Pattern matches over the Option, applying a handler function based on the variant
|
|
141
147
|
* @param patterns - Object with handler functions for Some and None variants
|
|
@@ -183,7 +189,7 @@ const RightConstructor = <L extends Type, R extends Type>(value: R): RightOf<L,
|
|
|
183
189
|
toEither: <E extends Type>(_leftValue: E) => Right<E, R>(value),
|
|
184
190
|
toTry: () => Try(() => value),
|
|
185
191
|
toJSON() {
|
|
186
|
-
return { _tag: "Right", value }
|
|
192
|
+
return { "@functype": "Either" as const, _tag: "Right" as const, value }
|
|
187
193
|
},
|
|
188
194
|
toString: () => {
|
|
189
195
|
return \`Right(\${safeStringify(value)})\`
|
|
@@ -222,7 +228,7 @@ const RightConstructor = <L extends Type, R extends Type>(value: R): RightOf<L,
|
|
|
222
228
|
toValue: () => ({ _tag: "Right", value }),
|
|
223
229
|
pipeEither: <U extends Type>(_onLeft: (value: L) => U, onRight: (value: R) => U) => onRight(value),
|
|
224
230
|
pipe: <U extends Type>(f: (value: L | R) => U) => f(value),
|
|
225
|
-
serialize: () => createSerializer("Right", value),
|
|
231
|
+
serialize: () => createSerializer("Either", "Right", value),
|
|
226
232
|
contains: (v: R) => value === v,
|
|
227
233
|
exists: (p: (a: R) => boolean) => p(value),
|
|
228
234
|
forEach: (f: (a: R) => void) => f(value),
|
|
@@ -289,9 +295,13 @@ export interface EitherBase<out L extends Type, out R extends Type>
|
|
|
289
295
|
*/
|
|
290
296
|
toValue(): { _tag: "Left" | "Right"; value: L | R }
|
|
291
297
|
/**
|
|
292
|
-
* Custom JSON serialization that excludes getter properties
|
|
298
|
+
* Custom JSON serialization that excludes getter properties.
|
|
299
|
+
* Emits the canonical functype envelope with \`@functype: "Either"\` so
|
|
300
|
+
* native \`JSON.stringify\` recursion (e.g. inside a plain object body)
|
|
301
|
+
* produces a marker-bearing envelope that survives a round-trip through
|
|
302
|
+
* \`Serialization.deserialize\`.
|
|
293
303
|
*/
|
|
294
|
-
toJSON(): { _tag: "Left" | "Right"; value: L | R }
|
|
304
|
+
toJSON(): { "@functype": "Either"; _tag: "Left" | "Right"; value: L | R }
|
|
295
305
|
}
|
|
296
306
|
|
|
297
307
|
export interface LeftOf<out L extends Type, out R extends Type> extends EitherBase<L, R> {
|
|
@@ -370,6 +380,15 @@ export interface RightOf<out L extends Type, out R extends Type> extends EitherB
|
|
|
370
380
|
*/
|
|
371
381
|
recoverWith<U extends Type>(f: (error: Error) => Try<U>): Try<T | U>
|
|
372
382
|
toValue(): { _tag: TypeNames; value: T | Error }
|
|
383
|
+
/**
|
|
384
|
+
* Custom JSON serialization. Success emits \`{"@functype":"Try","_tag":"Success","value":T}\`.
|
|
385
|
+
* Failure emits \`{"@functype":"Try","_tag":"Failure","error":SerializedError}\` where
|
|
386
|
+
* SerializedError captures \`name\`, \`message\`, \`stack\`, and the full \`cause\` chain —
|
|
387
|
+
* \`e.name\` survives round-trip but \`instanceof SomeError\` does not.
|
|
388
|
+
*/
|
|
389
|
+
toJSON():
|
|
390
|
+
| { "@functype": "Try"; _tag: "Success"; value: T }
|
|
391
|
+
| { "@functype": "Try"; _tag: "Failure"; error: SerializedError }
|
|
373
392
|
}`,List:`export interface List<out A> extends FunctypeCollection<A, "List">, Doable<A>, Reshapeable<A> {
|
|
374
393
|
readonly length: number
|
|
375
394
|
readonly [Symbol.iterator]: () => Iterator<A>
|
|
@@ -608,10 +627,28 @@ export interface RightOf<out L extends Type, out R extends Type> extends EitherB
|
|
|
608
627
|
*/
|
|
609
628
|
toString(): string
|
|
610
629
|
/**
|
|
611
|
-
* Converts the Lazy to a value object
|
|
612
|
-
*
|
|
630
|
+
* Converts the Lazy to a value object.
|
|
631
|
+
*
|
|
632
|
+
* **Forces the thunk** as a side effect — Lazy serialization (and projection
|
|
633
|
+
* to a plain value object) cannot represent an unevaluated thunk in JSON;
|
|
634
|
+
* forcing is the only way to produce a complete projection. If the thunk
|
|
635
|
+
* threw, the failure is captured in the \`error\` field (real Error, with
|
|
636
|
+
* full prototype intact for in-memory inspection — \`toJSON\` projects to
|
|
637
|
+
* \`SerializedError\` for the wire).
|
|
638
|
+
*
|
|
639
|
+
* Changed in 1.2.0 — pre-1.2.0 Lazy emitted \`{_tag, evaluated, value?}\`
|
|
640
|
+
* without forcing. See \`docs/proposals/serializable-audit-q1-q2.md\`.
|
|
613
641
|
*/
|
|
614
|
-
toValue(): { _tag: "Lazy";
|
|
642
|
+
toValue(): { _tag: "Lazy"; value: T } | { _tag: "Lazy"; error: Error }
|
|
643
|
+
/**
|
|
644
|
+
* Custom JSON serialization. Forces the thunk (see \`toValue\` for the
|
|
645
|
+
* side-effect contract). Emits \`{"@functype":"Lazy","_tag":"Lazy","value":T}\`
|
|
646
|
+
* on success, or \`{"@functype":"Lazy","_tag":"Lazy","error":SerializedError}\`
|
|
647
|
+
* if the thunk threw — see error-envelope.ts for round-trip semantics.
|
|
648
|
+
*/
|
|
649
|
+
toJSON():
|
|
650
|
+
| { "@functype": "Lazy"; _tag: "Lazy"; value: T }
|
|
651
|
+
| { "@functype": "Lazy"; _tag: "Lazy"; error: SerializedError }
|
|
615
652
|
}`,LazyList:`export interface LazyList<out A extends Type>
|
|
616
653
|
extends Foldable<A>, Pipe<LazyList<A>>, Serializable<LazyList<A>>, Typeable<"LazyList"> {
|
|
617
654
|
readonly [Symbol.toStringTag]: string
|
|
@@ -694,6 +731,14 @@ export interface RightOf<out L extends Type, out R extends Type> extends EitherB
|
|
|
694
731
|
// Pattern matching
|
|
695
732
|
readonly fold: <U>(onErr: (error: Throwable) => U, onOk: (value: T) => U) => U
|
|
696
733
|
readonly match: <U>(patterns: { Ok: (value: T) => U; Err: (error: Throwable) => U }) => U
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* Custom JSON serialization. Ok emits \`{"@functype":"Task","_tag":"Ok","value":T}\`.
|
|
737
|
+
* Err emits \`{"@functype":"Task","_tag":"Err","error":SerializedError}\` capturing the
|
|
738
|
+
* Throwable's name, message, stack, and cause chain. See error-envelope.ts —
|
|
739
|
+
* \`instanceof\` does NOT survive round-trip but \`error.name\` does.
|
|
740
|
+
*/
|
|
741
|
+
toJSON(): { "@functype": "Task"; _tag: "Ok"; value: T } | { "@functype": "Task"; _tag: "Err"; error: SerializedError }
|
|
697
742
|
}`,Tuple:`export interface Tuple<out T extends Type[]>
|
|
698
743
|
extends Foldable<T[number]>, Pipe<Tuple<T>>, Serializable<Tuple<T>>, Typeable<"Tuple"> {
|
|
699
744
|
readonly [Symbol.toStringTag]: string
|