@nicolastoulemont/std 0.7.2 → 0.8.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 +571 -166
- package/dist/adt/index.d.mts +1 -1
- package/dist/adt/index.mjs +1 -1
- package/dist/adt-CPG_sa8q.mjs +2 -0
- package/dist/adt-CPG_sa8q.mjs.map +1 -0
- package/dist/brand/index.d.mts +1 -1
- package/dist/brand/index.mjs +1 -1
- package/dist/brand-DZgGDrAe.mjs +2 -0
- package/dist/brand-DZgGDrAe.mjs.map +1 -0
- package/dist/brand.types-B3NDX1vo.d.mts +62 -0
- package/dist/brand.types-B3NDX1vo.d.mts.map +1 -0
- package/dist/context/index.d.mts +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/{context-CCHj1nab.mjs → context-0xDbwtpx.mjs} +2 -2
- package/dist/context-0xDbwtpx.mjs.map +1 -0
- package/dist/{context-r8ESJiFn.d.mts → context-B2dWloPl.d.mts} +2 -18
- package/dist/context-B2dWloPl.d.mts.map +1 -0
- package/dist/data/index.d.mts +1 -1
- package/dist/data/index.mjs +1 -1
- package/dist/{data-BLXO4XwS.mjs → data-BHYPdqWZ.mjs} +2 -2
- package/dist/{data-BLXO4XwS.mjs.map → data-BHYPdqWZ.mjs.map} +1 -1
- package/dist/{discriminator.types-CTURejXz.d.mts → discriminator.types-C-ygT2S1.d.mts} +1 -1
- package/dist/discriminator.types-C-ygT2S1.d.mts.map +1 -0
- package/dist/{dual-CZhzZslG.mjs → dual-fN6OUwN_.mjs} +1 -1
- package/dist/{dual-CZhzZslG.mjs.map → dual-fN6OUwN_.mjs.map} +1 -1
- package/dist/duration/index.d.mts +2 -0
- package/dist/duration/index.mjs +1 -0
- package/dist/duration-CYoDHcOR.mjs +2 -0
- package/dist/duration-CYoDHcOR.mjs.map +1 -0
- package/dist/either/index.d.mts +1 -1
- package/dist/either/index.mjs +1 -1
- package/dist/{either-BMLPfvMl.mjs → either-G7uOu4Ar.mjs} +2 -2
- package/dist/either-G7uOu4Ar.mjs.map +1 -0
- package/dist/{equality-CoyUHWh9.mjs → equality-BX6BUidG.mjs} +1 -1
- package/dist/{equality-CoyUHWh9.mjs.map → equality-BX6BUidG.mjs.map} +1 -1
- package/dist/{flow-D8_tllWl.mjs → flow-CNyLsPGb.mjs} +1 -1
- package/dist/flow-CNyLsPGb.mjs.map +1 -0
- package/dist/functions/index.d.mts +1 -1
- package/dist/functions/index.mjs +1 -1
- package/dist/functions-ByAk682_.mjs +2 -0
- package/dist/functions-ByAk682_.mjs.map +1 -0
- package/dist/fx/index.d.mts +1 -1
- package/dist/fx/index.mjs +1 -1
- package/dist/fx-DUXDxwsU.mjs +2 -0
- package/dist/fx-DUXDxwsU.mjs.map +1 -0
- package/dist/{fx.runtime-DclEDyjY.mjs → fx.runtime-jQxh77s3.mjs} +2 -2
- package/dist/{fx.runtime-DclEDyjY.mjs.map → fx.runtime-jQxh77s3.mjs.map} +1 -1
- package/dist/{fx.types-DeEWEltG.d.mts → fx.types-BdN1EWxr.d.mts} +1 -1
- package/dist/{fx.types-DeEWEltG.d.mts.map → fx.types-BdN1EWxr.d.mts.map} +1 -1
- package/dist/{fx.types-Bg-Mmdm5.mjs → fx.types-DyQVgTS8.mjs} +1 -1
- package/dist/{fx.types-Bg-Mmdm5.mjs.map → fx.types-DyQVgTS8.mjs.map} +1 -1
- package/dist/index-B4WfexUL.d.mts +57 -0
- package/dist/index-B4WfexUL.d.mts.map +1 -0
- package/dist/{index-DXbYlSnB.d.mts → index-BA0EsFxS.d.mts} +5 -74
- package/dist/index-BA0EsFxS.d.mts.map +1 -0
- package/dist/{index-UzMbg1dh.d.mts → index-BqJ1GWAF.d.mts} +20 -56
- package/dist/index-BqJ1GWAF.d.mts.map +1 -0
- package/dist/index-BsPOcZk9.d.mts +96 -0
- package/dist/index-BsPOcZk9.d.mts.map +1 -0
- package/dist/{index-DEAWPlcI.d.mts → index-CIvNgjsx.d.mts} +24 -56
- package/dist/index-CIvNgjsx.d.mts.map +1 -0
- package/dist/{index-B_iY5tq0.d.mts → index-CNTYbcY9.d.mts} +1 -21
- package/dist/index-CNTYbcY9.d.mts.map +1 -0
- package/dist/{index-Cq2IFito.d.mts → index-Ctqe1fD1.d.mts} +3 -17
- package/dist/index-Ctqe1fD1.d.mts.map +1 -0
- package/dist/{index-B_wWGszy.d.mts → index-D7mFNjot.d.mts} +1 -5
- package/dist/index-D7mFNjot.d.mts.map +1 -0
- package/dist/{index-CUZn-ohG.d.mts → index-D8rDE60Y.d.mts} +23 -54
- package/dist/index-D8rDE60Y.d.mts.map +1 -0
- package/dist/{index-By6dNRc4.d.mts → index-DR7hzXU4.d.mts} +3 -23
- package/dist/{index-By6dNRc4.d.mts.map → index-DR7hzXU4.d.mts.map} +1 -1
- package/dist/{index-DKS1g1oC.d.mts → index-DUki2Bcp.d.mts} +54 -45
- package/dist/index-DUki2Bcp.d.mts.map +1 -0
- package/dist/{index-BNQ9xSAz.d.mts → index-MsJqfQu0.d.mts} +64 -70
- package/dist/index-MsJqfQu0.d.mts.map +1 -0
- package/dist/{index-CGiLfREk.d.mts → index-UINIHFuh.d.mts} +39 -15
- package/dist/index-UINIHFuh.d.mts.map +1 -0
- package/dist/{index-BiiE8NS7.d.mts → index-crtzMG48.d.mts} +14 -23
- package/dist/index-crtzMG48.d.mts.map +1 -0
- package/dist/{index-B1-tBzc0.d.mts → index-dCRymj_g.d.mts} +23 -71
- package/dist/{index-B1-tBzc0.d.mts.map → index-dCRymj_g.d.mts.map} +1 -1
- package/dist/index-uE3S3Krx.d.mts +245 -0
- package/dist/index-uE3S3Krx.d.mts.map +1 -0
- package/dist/index.d.mts +21 -19
- package/dist/index.mjs +1 -1
- package/dist/layer/index.d.mts +1 -1
- package/dist/layer/index.mjs +1 -1
- package/dist/{layer-BttmtDrs.mjs → layer-CKtH7TRL.mjs} +2 -2
- package/dist/layer-CKtH7TRL.mjs.map +1 -0
- package/dist/{layer.types-DgpCIsk_.d.mts → layer.types-BB0MrvLg.d.mts} +4 -4
- package/dist/{layer.types-DgpCIsk_.d.mts.map → layer.types-BB0MrvLg.d.mts.map} +1 -1
- package/dist/multithread/index.d.mts +1 -1
- package/dist/multithread/index.mjs +1 -1
- package/dist/{multithread-xUUh4eLn.mjs → multithread-Cyc8Bz45.mjs} +2 -2
- package/dist/multithread-Cyc8Bz45.mjs.map +1 -0
- package/dist/option/index.d.mts +1 -1
- package/dist/option/index.mjs +1 -1
- package/dist/{option-Tfbo4wty.mjs → option-C2iCxAuJ.mjs} +2 -2
- package/dist/option-C2iCxAuJ.mjs.map +1 -0
- package/dist/{option.types-D1mm0zUb.mjs → option.types-CbY_swma.mjs} +1 -1
- package/dist/{option.types-D1mm0zUb.mjs.map → option.types-CbY_swma.mjs.map} +1 -1
- package/dist/{option.types-qPevEZQd.d.mts → option.types-D9hrKcfa.d.mts} +3 -3
- package/dist/{option.types-qPevEZQd.d.mts.map → option.types-D9hrKcfa.d.mts.map} +1 -1
- package/dist/order/index.d.mts +1 -1
- package/dist/order/index.mjs +1 -1
- package/dist/order-BXOBEKvB.mjs +2 -0
- package/dist/order-BXOBEKvB.mjs.map +1 -0
- package/dist/{pipeable-rfqacPxZ.d.mts → pipeable-BIrevC0D.d.mts} +1 -1
- package/dist/{pipeable-rfqacPxZ.d.mts.map → pipeable-BIrevC0D.d.mts.map} +1 -1
- package/dist/pipeable-Dp1_23zH.mjs +2 -0
- package/dist/{pipeable-COGyGMUV.mjs.map → pipeable-Dp1_23zH.mjs.map} +1 -1
- package/dist/predicate/index.d.mts +1 -1
- package/dist/predicate/index.mjs +1 -1
- package/dist/{predicate-DUhhQqWY.mjs → predicate-D_1SsIi4.mjs} +2 -2
- package/dist/predicate-D_1SsIi4.mjs.map +1 -0
- package/dist/provide/index.d.mts +1 -1
- package/dist/provide/index.mjs +1 -1
- package/dist/{provide-BmSM3Ruy.mjs → provide--yZE8x-n.mjs} +2 -2
- package/dist/provide--yZE8x-n.mjs.map +1 -0
- package/dist/queue/index.d.mts +1 -1
- package/dist/queue/index.mjs +1 -1
- package/dist/{queue-Sg6KJerl.mjs → queue-apiEOlRD.mjs} +2 -2
- package/dist/queue-apiEOlRD.mjs.map +1 -0
- package/dist/{queue.types-CD2LOu37.d.mts → queue.types-B-l5XYbU.d.mts} +1 -1
- package/dist/{queue.types-CD2LOu37.d.mts.map → queue.types-B-l5XYbU.d.mts.map} +1 -1
- package/dist/result/index.d.mts +1 -1
- package/dist/result/index.mjs +1 -1
- package/dist/{result-BEzV0DYC.mjs → result-D3VY0qBG.mjs} +2 -2
- package/dist/result-D3VY0qBG.mjs.map +1 -0
- package/dist/{result.types-_xDAei3-.d.mts → result.types-BKzChyWY.d.mts} +3 -3
- package/dist/{result.types-_xDAei3-.d.mts.map → result.types-BKzChyWY.d.mts.map} +1 -1
- package/dist/schedule/index.d.mts +1 -1
- package/dist/schedule/index.mjs +1 -1
- package/dist/schedule-B9K_2Z21.d.mts +183 -0
- package/dist/schedule-B9K_2Z21.d.mts.map +1 -0
- package/dist/schedule-C6iN3oMt.mjs +2 -0
- package/dist/schedule-C6iN3oMt.mjs.map +1 -0
- package/dist/schema/index.d.mts +2 -0
- package/dist/schema/index.mjs +1 -0
- package/dist/schema-CJ-aaQe8.mjs +2 -0
- package/dist/schema-CJ-aaQe8.mjs.map +1 -0
- package/dist/schema.shared-Bjyroa6b.mjs +2 -0
- package/dist/schema.shared-Bjyroa6b.mjs.map +1 -0
- package/dist/schema.types-CBEXCwfs.d.mts +60 -0
- package/dist/schema.types-CBEXCwfs.d.mts.map +1 -0
- package/dist/scope/index.d.mts +1 -1
- package/dist/scope/index.mjs +1 -1
- package/dist/{scope-CZdp4wKX.d.mts → scope-CuM3CzwG.d.mts} +3 -9
- package/dist/scope-CuM3CzwG.d.mts.map +1 -0
- package/dist/{scope-D_kzd1nT.mjs → scope-gVt4PESc.mjs} +2 -2
- package/dist/scope-gVt4PESc.mjs.map +1 -0
- package/dist/service/index.d.mts +1 -1
- package/dist/service/index.mjs +1 -1
- package/dist/{service-3PYQTUdH.mjs → service-CWAIEH46.mjs} +2 -2
- package/dist/service-CWAIEH46.mjs.map +1 -0
- package/dist/{service-DrXU7KJG.d.mts → service-D8mr0wwg.d.mts} +2 -8
- package/dist/service-D8mr0wwg.d.mts.map +1 -0
- package/dist/{service-resolution-C19smeaO.mjs → service-resolution-BefYr4nR.mjs} +1 -1
- package/dist/{service-resolution-C19smeaO.mjs.map → service-resolution-BefYr4nR.mjs.map} +1 -1
- package/package.json +9 -1
- package/dist/adt-DajUZvJe.mjs +0 -2
- package/dist/adt-DajUZvJe.mjs.map +0 -1
- package/dist/brand-Bia3Vj6l.mjs +0 -2
- package/dist/brand-Bia3Vj6l.mjs.map +0 -1
- package/dist/context-CCHj1nab.mjs.map +0 -1
- package/dist/context-r8ESJiFn.d.mts.map +0 -1
- package/dist/data.tagged-error.types-CGiKD-ES.d.mts +0 -29
- package/dist/data.tagged-error.types-CGiKD-ES.d.mts.map +0 -1
- package/dist/discriminator.types-CTURejXz.d.mts.map +0 -1
- package/dist/either-BMLPfvMl.mjs.map +0 -1
- package/dist/flow-D8_tllWl.mjs.map +0 -1
- package/dist/functions-BkevX2Dw.mjs +0 -2
- package/dist/functions-BkevX2Dw.mjs.map +0 -1
- package/dist/fx-K-a9Smhn.mjs +0 -2
- package/dist/fx-K-a9Smhn.mjs.map +0 -1
- package/dist/index-7Lv982Om.d.mts +0 -217
- package/dist/index-7Lv982Om.d.mts.map +0 -1
- package/dist/index-BNQ9xSAz.d.mts.map +0 -1
- package/dist/index-B_iY5tq0.d.mts.map +0 -1
- package/dist/index-B_wWGszy.d.mts.map +0 -1
- package/dist/index-BiiE8NS7.d.mts.map +0 -1
- package/dist/index-CGiLfREk.d.mts.map +0 -1
- package/dist/index-CUZn-ohG.d.mts.map +0 -1
- package/dist/index-Cq2IFito.d.mts.map +0 -1
- package/dist/index-DEAWPlcI.d.mts.map +0 -1
- package/dist/index-DKS1g1oC.d.mts.map +0 -1
- package/dist/index-DXbYlSnB.d.mts.map +0 -1
- package/dist/index-UzMbg1dh.d.mts.map +0 -1
- package/dist/layer-BttmtDrs.mjs.map +0 -1
- package/dist/multithread-xUUh4eLn.mjs.map +0 -1
- package/dist/option-Tfbo4wty.mjs.map +0 -1
- package/dist/order-D5c4QChk.mjs +0 -2
- package/dist/order-D5c4QChk.mjs.map +0 -1
- package/dist/pipeable-COGyGMUV.mjs +0 -2
- package/dist/predicate-DUhhQqWY.mjs.map +0 -1
- package/dist/provide-BmSM3Ruy.mjs.map +0 -1
- package/dist/queue-Sg6KJerl.mjs.map +0 -1
- package/dist/result-BEzV0DYC.mjs.map +0 -1
- package/dist/schedule-C6tjcJ1O.mjs +0 -2
- package/dist/schedule-C6tjcJ1O.mjs.map +0 -1
- package/dist/schedule-DlX2Dg69.d.mts +0 -144
- package/dist/schedule-DlX2Dg69.d.mts.map +0 -1
- package/dist/scope-CZdp4wKX.d.mts.map +0 -1
- package/dist/scope-D_kzd1nT.mjs.map +0 -1
- package/dist/service-3PYQTUdH.mjs.map +0 -1
- package/dist/service-DrXU7KJG.d.mts.map +0 -1
- /package/dist/{chunk-C934ptG5.mjs → chunk-oQKkju2G.mjs} +0 -0
- /package/dist/{option-CBCwzF0L.mjs → option-CXXiA1w-.mjs} +0 -0
- /package/dist/{result-B5WbPg8C.mjs → result-xFLfwriM.mjs} +0 -0
package/dist/adt/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as adt_d_exports } from "../index-
|
|
1
|
+
import { t as adt_d_exports } from "../index-DUki2Bcp.mjs";
|
|
2
2
|
export { adt_d_exports as Adt };
|
package/dist/adt/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"../adt-
|
|
1
|
+
import{t as e}from"../adt-CPG_sa8q.mjs";export{e as Adt};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{t as e}from"./chunk-oQKkju2G.mjs";import{i as t,n,r,t as i}from"./equality-BX6BUidG.mjs";import{i as a,t as o}from"./result-D3VY0qBG.mjs";import{r as s}from"./schema.shared-Bjyroa6b.mjs";function c(e,t){let n=t[e._tag];return n(e)}function l(e){return typeof e!=`object`||!e?!1:Object.getPrototypeOf(e)===null||Object.getPrototypeOf(e)===Object.prototype}function u(e){return typeof e==`function`&&`_variant`in e&&e._variant===!0}function d(e,t,n){return s(e,t,`ADT variant "${n}"`)}function f(e){return t=>l(t)&&`_tag`in t&&t._tag===e}function p(e){let t=new Set(e);return e=>l(e)&&`_tag`in e&&typeof e._tag==`string`&&t.has(e._tag)}function m(e,t,n,r){return n!==void 0&&r!==void 0?{kind:e,message:t,cause:n,validationIssues:r}:n===void 0?r===void 0?{kind:e,message:t}:{kind:e,message:t,validationIssues:r}:{kind:e,message:t,cause:n}}function h(e){return{to:e=>JSON.stringify(e),from:e=>{try{let t=JSON.parse(e);if(typeof t==`object`&&t&&`_tag`in t){let{_tag:e,...n}=t;return n}return t}catch{return null}}}}function g(e,t,n){let r=h(e),i={json:n=>{let i=d(t,{...n,_tag:e},e);if(i._tag===`Err`)return o(m(`ValidationError`,`Cannot encode invalid data: ${i.error.issues.map(e=>e.message).join(`, `)}`,void 0,i.error.issues));try{return a(r.to(i.value))}catch(e){return o(m(`EncodingError`,`JSON encoding failed: ${e instanceof Error?e.message:String(e)}`,e))}}};if(n)for(let[r,s]of Object.entries(n))i[r]=n=>{let i=d(t,{...n,_tag:e},e);if(i._tag===`Err`)return o(m(`ValidationError`,`Cannot encode invalid data: ${i.error.issues.map(e=>e.message).join(`, `)}`,void 0,i.error.issues));try{return a(s.to(i.value))}catch(e){return o(m(`EncodingError`,`Encoding with codec '${r}' failed: ${e instanceof Error?e.message:String(e)}`,e))}};return i}function _(e,t,n){let r=h(e),i={json:n=>{let i=r.from(n);if(i===null)return o(m(`DecodingError`,`Invalid JSON format`));let s=d(t,{...i,_tag:e},e);return s._tag===`Err`?o(m(`ValidationError`,`Decoded data failed schema validation`,void 0,s.error.issues)):a({...s.value,_tag:e})}};if(n)for(let[r,s]of Object.entries(n))i[r]=n=>{let i;try{i=s.from(n)}catch(e){return o(m(`DecodingError`,`Decoding with codec '${r}' threw an error`,e))}if(i===null)return o(m(`DecodingError`,`Codec '${r}' failed to decode input`));let c=d(t,{...i,_tag:e},e);return c._tag===`Err`?o(m(`ValidationError`,`Decoded data failed schema validation`,void 0,c.error.issues)):a({...c.value,_tag:e})};return i}function v(e,n,i){let s=f(e),c=g(e,n,i),l=_(e,n,i),u=r(e),p=t(e),m=t=>{let r=d(n,{...t,_tag:e},e);return r._tag===`Err`?o(r.error):a({...r.value,_tag:e})};return m._variant=!0,m._tag=e,m.schema=n,i&&(m.codecs=i),m.is=s,m.to=c,m.from=l,m.equals=u,m.hash=p,m}function y(e,t){let r=Object.keys(t),a={};for(let[e,n]of Object.entries(t))u(n)?n._tag===e?a[e]=n:n.codecs?a[e]=v(e,n.schema,n.codecs):a[e]=v(e,n.schema):a[e]=v(e,n);return{_name:e,is:p(r),equals:i(r),hash:n(r),...a}}var b=e({match:()=>C,union:()=>x,variant:()=>S});const x=y,S=v,C=c;export{b as t};
|
|
2
|
+
//# sourceMappingURL=adt-CPG_sa8q.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adt-CPG_sa8q.mjs","names":["match","validateSchemaSync","variant","union","variant","unionImpl","variantImpl","matchImpl"],"sources":["../src/adt/adt.match.ts","../src/shared/is-plain-object.ts","../src/adt/adt.utils.ts","../src/adt/adt.codec.ts","../src/adt/adt.variant.ts","../src/adt/adt.union.ts","../src/adt/adt.ts"],"sourcesContent":["/**\n * Handler functions for each variant in a discriminated union.\n * Each key maps to a function that receives the variant value and returns TResult.\n *\n * @template T - The discriminated union type (must have readonly _tag)\n * @template TResult - The return type of all handlers\n */\ntype AdtMatchHandlers<T extends { readonly _tag: string }, TResult> = {\n [K in T[\"_tag\"]]: (value: Extract<T, { readonly _tag: K }>) => TResult\n}\n\n/**\n * Exhaustive pattern matching for discriminated unions.\n *\n * TypeScript will error if any variant is missing from handlers,\n * ensuring exhaustive handling of all cases.\n *\n * @template T - The discriminated union type (must have readonly _tag)\n * @template TResult - The return type of all handlers\n * @template Handlers - The handler object type (inferred)\n * @param value - A discriminated union value with _tag\n * @param handlers - An object with a handler function for each variant\n * @returns The result of calling the matching handler\n *\n * @see {@link union} for creating discriminated unions\n * @see {@link variant} for creating individual variant types\n *\n * @example\n * ```ts\n * import { Adt } from \"@nicolastoulemont/std\"\n * import { z } from \"zod\"\n *\n * // Adt accepts any Standard Schema-compatible schema, such as zod, valibot, or arktype.\n * const Circle = Adt.variant(\"Circle\", z.object({ radius: z.number() }))\n * const Square = Adt.variant(\"Square\", z.object({ size: z.number() }))\n * const Shape = Adt.union(\"Shape\", { Circle, Square })\n * type Shape = Adt.Infer<typeof Shape>\n *\n * function describeShape(shape: Shape): string {\n * return Adt.match(shape, {\n * Circle: (c) => `Circle with radius ${c.radius}`,\n * Square: (s) => `Square with size ${s.size}`,\n * })\n * }\n * ```\n */\nexport function match<\n T extends { readonly _tag: string },\n TResult,\n Handlers extends AdtMatchHandlers<T, TResult> = AdtMatchHandlers<T, TResult>,\n>(value: T, handlers: Handlers): TResult {\n const tag = value._tag as keyof Handlers\n const handler = handlers[tag]\n // oxlint-disable-next-line no-explicit-any, no-unsafe-argument, no-unsafe-type-assertion -- Required for variant dispatch\n return handler(value as any)\n}\n","/**\n * Check if a value is a plain object.\n * A plain object is an object created with `{}`, `Object.create(null)`, or `new Object()`.\n * Arrays, functions, dates, maps, etc. are not considered plain objects.\n */\nexport function isPlainObject(value: unknown): value is Record<PropertyKey, unknown> {\n if (value === null || typeof value !== \"object\") {\n return false\n }\n\n return Object.getPrototypeOf(value) === null || Object.getPrototypeOf(value) === Object.prototype\n}\n","import { validateSync as validateSchemaSync } from \"../schema/schema.shared\"\nimport { isPlainObject } from \"../shared/is-plain-object\"\nimport type { AdtVariant } from \"./adt.types\"\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\"\n\n/**\n * Check if a value is an AdtVariant created by variant().\n * AdtVariants are callable functions with static properties.\n */\nexport function isVariant(value: unknown): value is AdtVariant {\n return typeof value === \"function\" && \"_variant\" in value && value[\"_variant\"] === true\n}\n\n/**\n * Validate data using a Standard Schema, enforcing sync-only validation.\n * Throws if the schema returns a Promise.\n */\nexport function validateSync<T>(schema: StandardSchemaV1<unknown, T>, data: unknown, _tag: string) {\n return validateSchemaSync(schema, data, `ADT variant \"${_tag}\"`)\n}\n\n/**\n * Create a type guard function for a specific _tag.\n */\nexport function createIsGuard<Tag extends string, T>(\n _tag: Tag,\n): (value: unknown) => value is T & { readonly _tag: Tag } {\n return (value: unknown): value is T & { readonly _tag: Tag } => {\n return isPlainObject(value) && \"_tag\" in value && value[\"_tag\"] === _tag\n }\n}\n\n/**\n * Create a type guard function for multiple _tags (AdtUnion root guard).\n */\nexport function createIsAnyGuard<T>(_tags: readonly string[]): (value: unknown) => value is T {\n const _tagSet = new Set(_tags)\n return (value: unknown): value is T => {\n return isPlainObject(value) && \"_tag\" in value && typeof value[\"_tag\"] === \"string\" && _tagSet.has(value[\"_tag\"])\n }\n}\n","import { ok, err } from \"../result/result\"\nimport type { Result } from \"../result/result.types\"\nimport type { ValidationError } from \"../schema/schema.types\"\nimport type { Discriminator } from \"../shared/discriminator.types\"\nimport type {\n AdtCodecConstraint,\n AdtCodecDef,\n AdtCodecError,\n AdtInferInput,\n AdtInferOutput,\n ToMethods,\n FromMethods,\n} from \"./adt.types\"\nimport { validateSync } from \"./adt.utils\"\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\"\n\n/**\n * Create a AdtCodecError with consistent structure.\n */\nfunction createCodecError(\n kind: AdtCodecError[\"kind\"],\n message: string,\n cause?: unknown,\n validationIssues?: ValidationError[\"issues\"],\n): AdtCodecError {\n if (cause !== undefined && validationIssues !== undefined) {\n return { kind, message, cause, validationIssues }\n }\n if (cause !== undefined) {\n return { kind, message, cause }\n }\n if (validationIssues !== undefined) {\n return { kind, message, validationIssues }\n }\n return { kind, message }\n}\n\n/**\n * Built-in JSON codec that works with any schema.\n * Encodes to JSON string and decodes with JSON.parse.\n */\nfunction createJsonCodec<Tag extends string, S extends StandardSchemaV1>(\n _tag: Tag,\n): AdtCodecDef<AdtInferOutput<S> & Discriminator<Tag>, string, AdtInferInput<S>> {\n return {\n to: (value) => {\n // JSON.stringify can throw for circular references, BigInt, etc.\n // We let it throw and catch it in the wrapper\n return JSON.stringify(value)\n },\n /* oxlint-disable no-unsafe-assignment, no-unsafe-type-assertion, no-unsafe-return -- Required for JSON parsing which returns unknown types */\n from: (input: string) => {\n try {\n const parsed = JSON.parse(input)\n // Return parsed object without _tag - it will be added during validation\n if (typeof parsed === \"object\" && parsed !== null && \"_tag\" in parsed) {\n const { _tag: _, ...rest } = parsed\n return rest as AdtInferInput<S>\n }\n return parsed\n } catch {\n return null\n }\n },\n /* oxlint-enable no-unsafe-assignment, no-unsafe-type-assertion, no-unsafe-return */\n }\n}\n\n/**\n * Create the \"to\" methods object with JSON codec and custom codecs.\n * All methods return Result<T, AdtCodecError> for consistent error handling.\n */\nexport function createToMethods<\n Tag extends string,\n S extends StandardSchemaV1,\n Codecs extends AdtCodecConstraint<Tag, S> | undefined = undefined,\n>(_tag: Tag, schema: S, customCodecs?: Codecs): ToMethods<S, Codecs> {\n type Output = AdtInferOutput<S> & Discriminator<Tag>\n\n const jsonCodec = createJsonCodec<Tag, S>(_tag)\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const to: Record<string, (value: AdtInferInput<S>) => Result<any, AdtCodecError>> = {\n json: (value: AdtInferInput<S>): Result<string, AdtCodecError> => {\n // First, create a validated variant to ensure the encoded payload is well-typed.\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for spreading generic input into object\n const taggedInput = { ...(value as object), _tag }\n const result = validateSync(schema, taggedInput, _tag)\n\n if (result._tag === \"Err\") {\n return err(\n createCodecError(\n \"ValidationError\",\n `Cannot encode invalid data: ${result.error.issues.map((i) => i.message).join(\", \")}`,\n undefined,\n result.error.issues,\n ),\n )\n }\n\n try {\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for validated value cast\n return ok(jsonCodec.to(result.value as Output))\n } catch (e) {\n return err(\n createCodecError(\"EncodingError\", `JSON encoding failed: ${e instanceof Error ? e.message : String(e)}`, e),\n )\n }\n },\n }\n\n // Add custom codecs\n if (customCodecs) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n for (const [name, codec] of Object.entries(customCodecs) as Array<[string, AdtCodecDef<Output, any, any>]>) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n to[name] = (value: AdtInferInput<S>): Result<any, AdtCodecError> => {\n // Validate input first\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for spreading generic input\n const taggedInput = { ...(value as object), _tag }\n const result = validateSync(schema, taggedInput, _tag)\n\n if (result._tag === \"Err\") {\n return err(\n createCodecError(\n \"ValidationError\",\n `Cannot encode invalid data: ${result.error.issues.map((i) => i.message).join(\", \")}`,\n undefined,\n result.error.issues,\n ),\n )\n }\n\n try {\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for validated value cast\n return ok(codec.to(result.value as Output))\n } catch (e) {\n return err(\n createCodecError(\n \"EncodingError\",\n `Encoding with codec '${name}' failed: ${e instanceof Error ? e.message : String(e)}`,\n e,\n ),\n )\n }\n }\n }\n }\n\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for generic return type\n return to as ToMethods<S, Codecs>\n}\n\n/**\n * Create the \"from\" methods object with JSON codec and custom codecs.\n * All methods return Result<T, AdtCodecError> for consistent error handling.\n */\nexport function createFromMethods<\n Tag extends string,\n S extends StandardSchemaV1,\n Codecs extends AdtCodecConstraint<Tag, S> | undefined = undefined,\n>(_tag: Tag, schema: S, customCodecs?: Codecs): FromMethods<Tag, S, Codecs> {\n type Output = AdtInferOutput<S> & Discriminator<Tag>\n\n const jsonCodec = createJsonCodec<Tag, S>(_tag)\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const from: Record<string, (input: any) => Result<Output, AdtCodecError>> = {\n json: (input: string): Result<Output, AdtCodecError> => {\n // Decode\n const decoded = jsonCodec.from(input)\n if (decoded === null) {\n return err(createCodecError(\"DecodingError\", \"Invalid JSON format\"))\n }\n\n // Validate through schema\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for spreading decoded value\n const taggedInput = { ...(decoded as object), _tag }\n const result = validateSync(schema, taggedInput, _tag)\n\n if (result._tag === \"Err\") {\n return err(\n createCodecError(\"ValidationError\", \"Decoded data failed schema validation\", undefined, result.error.issues),\n )\n }\n\n // Ensure _tag in output\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for output construction\n const output = { ...(result.value as object), _tag } as Output\n return ok(output)\n },\n }\n\n // Add custom codecs\n if (customCodecs) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n for (const [name, codec] of Object.entries(customCodecs) as Array<[string, AdtCodecDef<Output, any, any>]>) {\n from[name] = (input: unknown): Result<Output, AdtCodecError> => {\n // Decode\n let decoded: unknown\n try {\n decoded = codec.from(input)\n } catch (e) {\n return err(createCodecError(\"DecodingError\", `Decoding with codec '${name}' threw an error`, e))\n }\n\n if (decoded === null) {\n return err(createCodecError(\"DecodingError\", `Codec '${name}' failed to decode input`))\n }\n\n // Validate through schema\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for spreading decoded value\n const taggedInput = { ...(decoded as object), _tag }\n const result = validateSync(schema, taggedInput, _tag)\n\n if (result._tag === \"Err\") {\n return err(\n createCodecError(\n \"ValidationError\",\n \"Decoded data failed schema validation\",\n undefined,\n result.error.issues,\n ),\n )\n }\n\n // Ensure _tag in output\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for output construction\n const output = { ...(result.value as object), _tag } as Output\n return ok(output)\n }\n }\n }\n\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for generic return type\n return from as FromMethods<Tag, S, Codecs>\n}\n","import { createEqualsMethod, createHashMethod } from \"../equality/equality\"\nimport { ok, err } from \"../result/result\"\nimport type { Result } from \"../result/result.types\"\nimport type { ValidationError } from \"../schema/schema.types\"\nimport type { Discriminator } from \"../shared/discriminator.types\"\nimport { createToMethods, createFromMethods } from \"./adt.codec\"\nimport type { AdtCodecConstraint, AdtInferInput, AdtInferOutput, AdtVariant } from \"./adt.types\"\nimport { createIsGuard, validateSync } from \"./adt.utils\"\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\"\n\n/**\n * Create a standalone tagged variant from a Standard Schema with optional codecs.\n *\n * Variants can be used independently or composed into an AdtUnion via union().\n * All defaults should be defined at the schema level (e.g., Zod's .default()).\n *\n * @template Tag - The string literal type for the _tag discriminator\n * @template S - The Standard Schema type for validation\n * @template Codecs - Optional codec definitions for custom serialization formats\n * @param _tag - The _tag discriminator value\n * @param schema - A Standard Schema compliant validator\n * @param codecs - Optional codec definitions for custom serialization formats\n * @returns A callable AdtVariant with is(), to, and from methods\n *\n * @see {@link union} for composing variants into discriminated unions\n * @see {@link tagged} for unvalidated tagged value constructors\n *\n * @example\n * ```ts\n * const CircleSchema = z.object({\n * radius: z.number().positive(),\n * color: z.string().default('blue')\n * })\n *\n * // Basic variant with JSON codec (always included)\n * const Circle = variant('Circle', CircleSchema)\n *\n * const result = Circle({ radius: 10 })\n * // { _tag: \"Ok\", value: { _tag: \"Circle\", radius: 10, color: \"blue\" } }\n *\n * Circle.is(someValue) // type guard\n *\n * const json = Circle.to.json({ radius: 10 }) // JSON string\n * const result2 = Circle.from.json(json) // Result<Circle, AdtCodecError>\n *\n * // Variant with custom codec\n * const Circle2 = variant('Circle', CircleSchema, {\n * graphic: {\n * to: (circle) => `(${circle.radius})`,\n * from: (input: string) => {\n * const match = input.match(/^\\((\\d+)\\)$/)\n * return match ? { radius: parseInt(match[1]!) } : null\n * }\n * }\n * })\n *\n * const graphic = Circle2.to.graphic({ radius: 10 }) // \"(10)\"\n * const result3 = Circle2.from.graphic(\"(10)\") // Result<Circle, AdtCodecError>\n * ```\n */\n// Overload: with codecs\nexport function variant<Tag extends string, S extends StandardSchemaV1, Codecs extends AdtCodecConstraint<Tag, S>>(\n _tag: Tag,\n schema: S,\n codecs: Codecs,\n): AdtVariant<Tag, S, Codecs>\n\n// Overload: without codecs\nexport function variant<Tag extends string, S extends StandardSchemaV1>(_tag: Tag, schema: S): AdtVariant<Tag, S>\n\n// Implementation\nexport function variant<\n Tag extends string,\n S extends StandardSchemaV1,\n Codecs extends AdtCodecConstraint<Tag, S> | undefined,\n>(_tag: Tag, schema: S, codecs?: Codecs): AdtVariant<Tag, S, Codecs> {\n type Output = AdtInferOutput<S> & Discriminator<Tag>\n\n const isGuard = createIsGuard<Tag, Output>(_tag)\n const to = createToMethods(_tag, schema, codecs)\n const from = createFromMethods(_tag, schema, codecs)\n const equals = createEqualsMethod<Tag, AdtInferOutput<S>>(_tag)\n const hash = createHashMethod<Tag, AdtInferOutput<S>>(_tag)\n\n // Constructor function\n const constructor = (input: AdtInferInput<S>): Result<Output, ValidationError> => {\n // Add _tag to the input before validation\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for spreading generic input\n const taggedInput = { ...(input as object), _tag }\n\n // Validate using the schema\n const result = validateSync(schema, taggedInput, _tag)\n\n if (result._tag === \"Err\") {\n return err(result.error)\n }\n\n // Ensure _tag is in the output (schema might strip unknown keys)\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for output construction\n const output = { ...(result.value as object), _tag } as Output\n return ok(output)\n }\n\n // Attach static properties to constructor function\n constructor._variant = true as const\n constructor._tag = _tag\n constructor.schema = schema\n if (codecs) {\n // oxlint-disable-next-line no-unsafe-type-assertion -- Conditional assignment of codecs\n ;(constructor as { codecs?: Codecs }).codecs = codecs\n }\n constructor.is = isGuard\n constructor.to = to\n constructor.from = from\n constructor.equals = equals\n constructor.hash = hash\n\n return constructor as AdtVariant<Tag, S, Codecs>\n}\n","import { createADTEqualsMethod, createADTHashMethod } from \"../equality/equality\"\nimport type { AdtUnion, AdtVariantDef, AdtVariant } from \"./adt.types\"\nimport { createIsAnyGuard, isVariant } from \"./adt.utils\"\nimport { variant } from \"./adt.variant\"\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\"\n\n/**\n * Compose records or schemas into a discriminated union (AdtUnion).\n *\n * Accepts either:\n * - Pre-built AdtVariants from variant() (codecs are preserved)\n * - Raw Standard Schema validators (will be wrapped internally)\n *\n * When using pre-built records, the object key overrides the original _tag.\n *\n * @template R - Record of variant names to AdtVariants or StandardSchema validators\n * @param name - The name of this AdtUnion (for identification)\n * @param records - An object mapping _tag names to AdtVariants or schemas\n * @returns An AdtUnion object with accessors for each variant\n *\n * @see {@link variant} for creating individual variant types\n * @see {@link match} for exhaustive pattern matching on AdtUnion values\n *\n * @example\n * ```ts\n * // From pre-built variants\n * const Circle = variant('Circle', CircleSchema)\n * const Square = variant('Square', SquareSchema)\n * const Shape = union('Shape', { Circle, Square })\n *\n * // From raw schemas (JSON codec is automatically included)\n * const Shape = union('Shape', {\n * Circle: CircleSchema,\n * Square: SquareSchema\n * })\n *\n * // JSON codec works on all variants\n * Shape.Circle.to.json({ radius: 10 })\n * Shape.Circle.from.json(jsonString)\n *\n * // Mixed\n * const Shape = union('Shape', {\n * Circle, // Pre-built variant\n * Square: SquareSchema // Raw schema\n * })\n *\n * // Usage\n * Shape.Circle({ radius: 10 })\n * Shape.is(someValue) // type guard for any variant\n * Shape.Circle.is(someValue) // type guard for Circle\n * ```\n */\nexport function union<R extends Record<string, AdtVariantDef>>(name: string, records: R): AdtUnion<R> {\n const tags = Object.keys(records)\n const variants: Record<string, AdtVariant> = {}\n\n for (const [_tag, def] of Object.entries(records)) {\n if (isVariant(def)) {\n // Pre-built AdtVariant - key overrides original _tag\n if (def._tag === _tag) {\n // _tag matches key, use as-is (preserves codecs)\n variants[_tag] = def\n // oxlint-disable-next-line strict-boolean-expressions -- codecs can be undefined\n } else if (def.codecs) {\n // _tag differs from key - create new variant with key as _tag\n // Preserve codecs\n variants[_tag] = variant(_tag, def.schema, def.codecs)\n } else {\n // _tag differs from key and no codecs\n variants[_tag] = variant(_tag, def.schema)\n }\n } else {\n // Raw schema - wrap in variant\n // Note: Even without custom codecs, this still gets JSON codec!\n // oxlint-disable-next-line no-unsafe-type-assertion -- def is a StandardSchemaV1 in this branch\n variants[_tag] = variant(_tag, def as StandardSchemaV1)\n }\n }\n\n // Create the root type guard for any variant\n const isAnyVariant = createIsAnyGuard(tags)\n const equals = createADTEqualsMethod(tags)\n const hash = createADTHashMethod(tags)\n\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for generic AdtUnion return type\n return {\n _name: name,\n is: isAnyVariant,\n equals,\n hash,\n ...variants,\n } as AdtUnion<R>\n}\n","/**\n * Tagged union builders and match helpers.\n *\n * **Mental model**\n * - `Adt` helps build discriminated unions with runtime validation.\n * - Use `union`, `variant`, and `match` to model algebraic data types.\n *\n * **Common tasks**\n * - Define variants with `Adt.variant`.\n * - Combine variants with `Adt.union`.\n * - Pattern-match with `Adt.match`.\n *\n * **Gotchas**\n * - `Adt` codec/type helpers are mostly type-level.\n * - Prefer namespace imports from `@nicolastoulemont/std`.\n *\n * **Quickstart**\n *\n * @example\n * ```ts\n * import { Adt } from \"@nicolastoulemont/std\"\n * import { z } from \"zod\"\n *\n * // Adt accepts any Standard Schema-compatible schema, such as zod, valibot, or arktype.\n * const CircleSchema = z.object({ radius: z.number() })\n *\n * const Shape = Adt.union(\"Shape\", { Circle: CircleSchema })\n * const result = Shape.Circle({ radius: 2 })\n * // => { _tag: \"Ok\", value: { _tag: \"Circle\", radius: 2 } }\n * ```\n *\n * @module\n */\nimport { match as matchImpl } from \"./adt.match\"\nimport type {\n AdtInfer as AdtInferType,\n AdtVariantNames as AdtVariantNamesType,\n AdtVariantOf as AdtVariantOfType,\n} from \"./adt.types\"\nimport { union as unionImpl } from \"./adt.union\"\nimport { variant as variantImpl } from \"./adt.variant\"\n\n/**\n * Re-exported ADT inferred union helper.\n *\n * @example\n * ```ts\n * import { Adt } from \"@nicolastoulemont/std\"\n * import { z } from \"zod\"\n *\n * // Adt accepts any Standard Schema-compatible schema, such as zod, valibot, or arktype.\n * const Shape = Adt.union(\"Shape\", {\n * Circle: z.object({ radius: z.number() }),\n * })\n * type Shape = Adt.Infer<typeof Shape>\n * ```\n */\nexport type Infer<T> = AdtInferType<T>\n\n/**\n * Re-exported union variant name helper.\n *\n * @example\n * ```ts\n * import { Adt } from \"@nicolastoulemont/std\"\n * import { z } from \"zod\"\n *\n * // Adt accepts any Standard Schema-compatible schema, such as zod, valibot, or arktype.\n * const Shape = Adt.union(\"Shape\", {\n * Circle: z.object({ radius: z.number() }),\n * })\n * type Names = Adt.VariantNames<typeof Shape>\n * ```\n */\nexport type VariantNames<T> = AdtVariantNamesType<T>\n\n/**\n * Re-exported helper to extract a specific variant from an ADT.\n *\n * @example\n * ```ts\n * import { Adt } from \"@nicolastoulemont/std\"\n * import { z } from \"zod\"\n *\n * // Adt accepts any Standard Schema-compatible schema, such as zod, valibot, or arktype.\n * const Shape = Adt.union(\"Shape\", {\n * Circle: z.object({ radius: z.number() }),\n * })\n * type Circle = Adt.VariantOf<typeof Shape, \"Circle\">\n * ```\n */\nexport type VariantOf<T, K extends string> = AdtVariantOfType<T, K>\n\n/**\n * Build an ADT union from named variants.\n *\n * @example\n * ```ts\n * import { Adt } from \"@nicolastoulemont/std\"\n * import { z } from \"zod\"\n *\n * // Adt accepts any Standard Schema-compatible schema, such as zod, valibot, or arktype.\n * const CircleSchema = z.object({ radius: z.number() })\n *\n * const Shape = Adt.union(\"Shape\", { Circle: CircleSchema })\n * const result = Shape.Circle({ radius: 2 })\n * // => { _tag: \"Ok\", value: { _tag: \"Circle\", radius: 2 } }\n * ```\n */\nexport const union = unionImpl\n\n/**\n * Define one ADT variant with schema-backed validation.\n *\n * @example\n * ```ts\n * import { Adt } from \"@nicolastoulemont/std\"\n * import { z } from \"zod\"\n *\n * // Adt accepts any Standard Schema-compatible schema, such as zod, valibot, or arktype.\n * const CircleSchema = z.object({ radius: z.number() })\n *\n * const Circle = Adt.variant(\"Circle\", CircleSchema)\n * const result = Circle({ radius: 2 })\n * // => { _tag: \"Ok\", value: { _tag: \"Circle\", radius: 2 } }\n * ```\n */\nexport const variant = variantImpl\n\n/**\n * Match over ADT variants by discriminator tag.\n *\n * @example\n * ```ts\n * import { Adt } from \"@nicolastoulemont/std\"\n *\n * const label = Adt.match({ _tag: \"Circle\", radius: 2 } as const, {\n * Circle: (circle) => `r=${circle.radius}` ,\n * })\n * // => \"r=2\"\n * ```\n */\nexport const match = matchImpl\n"],"mappings":"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"}
|
package/dist/brand/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as brand_d_exports } from "../index-
|
|
1
|
+
import { t as brand_d_exports } from "../index-BA0EsFxS.mjs";
|
|
2
2
|
export { brand_d_exports as Brand };
|
package/dist/brand/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"../brand-
|
|
1
|
+
import{t as e}from"../brand-DZgGDrAe.mjs";export{e as Brand};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{t as e}from"./chunk-oQKkju2G.mjs";import{i as t,t as n}from"./result-D3VY0qBG.mjs";var r=e({is:()=>o,make:()=>i,refine:()=>s,unsafeMake:()=>a});const i=e=>e,a=e=>e,o=e=>t=>e(t),s=(e,r)=>i=>e(i)?t(i):n({_tag:`BrandError`,value:i,message:typeof r==`function`?r(i):r??`Brand validation failed`});export{i as n,r as t};
|
|
2
|
+
//# sourceMappingURL=brand-DZgGDrAe.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brand-DZgGDrAe.mjs","names":["Result.err","Result.ok"],"sources":["../src/brand/brand.ts"],"sourcesContent":["/**\n * Nominal branding utilities for lightweight domain types.\n *\n * **Mental model**\n * - Brands let you distinguish semantically different values with the same runtime shape.\n * - `Brand.refine` validates and returns `Result`, while `Brand.make` is unchecked.\n *\n * **Common tasks**\n * - Create branded values with `Brand.make`.\n * - Add runtime validation with `Brand.refine`.\n * - Build guards with `Brand.is`.\n *\n * **Gotchas**\n * - Branding is a type-level operation and does not change runtime representation.\n * - `unsafeMake` should be reserved for trusted sources.\n *\n * **Quickstart**\n *\n * @example\n * ```ts\n * import { Brand } from \"@nicolastoulemont/std\"\n *\n * type UserId = Brand.Branded<string, \"UserId\">\n * const raw = \"user_123\" as UserId\n * const userId = Brand.make<UserId>(raw)\n * // => brand-preserving cast\n * ```\n *\n * @module\n */\nimport { Result } from \"../result\"\nimport type { Result as ResultType } from \"../result/result.types\"\nimport type { BrandError as BrandErrorType, Branded as BrandedType, Unbrand, Validator } from \"./brand.types\"\n\n/**\n * Re-exported nominal brand helper type.\n *\n * @example\n * ```ts\n * import { Brand } from \"@nicolastoulemont/std\"\n *\n * type Example = typeof Brand\n * ```\n */\nexport type Branded<T, K extends string> = BrandedType<T, K>\n\n/**\n * Re-exported brand validation error type.\n *\n * @example\n * ```ts\n * import { Brand } from \"@nicolastoulemont/std\"\n *\n * type Example = typeof Brand\n * ```\n */\nexport type BrandError<T> = BrandErrorType<T>\n\n/* oxlint-disable no-unsafe-type-assertion -- Branding is a deliberate nominal cast at the type level and requires explicit assertions. */\n\n/**\n * Create a branded value without validation.\n * This is a type-level cast with zero runtime cost.\n *\n * Use this when you trust the value source (e.g., from a database)\n * or when validation happens elsewhere.\n *\n * @template B - The branded type\n * @param value - The value to brand\n * @returns The value as a branded type\n *\n * @example\n * ```ts\n * import { Brand } from \"@nicolastoulemont/std\"\n *\n * type UserId = Brand.Branded<string, \"UserId\">\n * const raw = \"user_123\" as UserId\n * const userId = Brand.make<UserId>(raw)\n * // => brand-preserving cast\n * ```\n */\nexport const make = <B extends Branded<unknown, string>>(value: Unbrand<B>): B => {\n return value as B\n}\n\n/**\n * Alias for make() - explicitly indicates no validation occurs.\n * Prefer this when readability about the lack of validation is important.\n *\n * @template B - The branded type\n * @param value - The value to brand (unchecked)\n * @returns The value as a branded type\n *\n * @example\n * ```ts\n * import { Brand } from \"@nicolastoulemont/std\"\n *\n * type UserId = Brand.Branded<string, \"UserId\">\n * const raw = \"user_123\" as UserId\n * const userId = Brand.unsafeMake<UserId>(raw)\n * // => unchecked brand cast\n * ```\n */\nexport const unsafeMake = <B extends Branded<unknown, string>>(value: Unbrand<B>): B => {\n return value as B\n}\n\n/**\n * Create a type guard with validation for a branded type.\n * Returns a refinement predicate that narrows to the branded type.\n *\n * @template T - The base type\n * @template K - The brand key (string literal)\n * @param validator - A function that validates the base value\n * @returns A type guard that returns true if validation passes\n *\n * @example\n * ```ts\n * import { Brand } from \"@nicolastoulemont/std\"\n *\n * type UserId = Brand.Branded<string, \"UserId\">\n * const isUserId = Brand.is<string, \"UserId\">((value) => value.startsWith(\"user_\"))\n * const valid = isUserId(\"user_123\")\n * // => true\n * ```\n */\nexport const is = <T, K extends string>(validator: Validator<T>): ((value: T) => value is Branded<T, K>) => {\n return (value: T): value is Branded<T, K> => validator(value)\n}\n\n/**\n * Create a validated branded value wrapped in a Result.\n * Returns `Result.ok(brandedValue)` on success, `Result.err(BrandError)` on failure.\n *\n * The returned Result is yieldable in Fx.gen computations via `yield*`.\n *\n * @template B - The branded type\n * @param validator - A function that validates the base value\n * @param errorMessage - Optional custom error message (or function)\n * @returns A function that takes a value and returns a Result\n *\n * @example\n * ```ts\n * import { Brand } from \"@nicolastoulemont/std\"\n *\n * type UserId = Brand.Branded<string, \"UserId\">\n * const toUserId = Brand.refine<UserId>((value) => value.startsWith(\"user_\"), \"Invalid user id\")\n * const parsed = toUserId(\"user_123\")\n * // => { _tag: \"Ok\", value: \"user_123\" }\n * ```\n */\nexport const refine = <B extends Branded<unknown, string>>(\n validator: Validator<Unbrand<B>>,\n errorMessage?: string | ((value: Unbrand<B>) => string),\n): ((value: Unbrand<B>) => ResultType<B, BrandError<Unbrand<B>>>) => {\n return (value: Unbrand<B>) => {\n if (!validator(value)) {\n const msg = typeof errorMessage === \"function\" ? errorMessage(value) : (errorMessage ?? \"Brand validation failed\")\n return Result.err({ _tag: \"BrandError\" as const, value, message: msg })\n }\n return Result.ok(value as B)\n }\n}\n\n/* oxlint-enable no-unsafe-type-assertion */\n"],"mappings":"uJAiFA,MAAa,EAA4C,GAChD,EAqBI,EAAkD,GACtD,EAsBI,EAA2B,GAC9B,GAAqC,EAAU,EAAM,CAwBlD,GACX,EACA,IAEQ,GACD,EAAU,EAAM,CAIdC,EAAU,EAAW,CAFnBD,EAAW,CAAE,KAAM,aAAuB,QAAO,QAD5C,OAAO,GAAiB,WAAa,EAAa,EAAM,CAAI,GAAgB,0BAClB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//#region src/brand/brand.types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Unique symbol for brand keys to ensure true nominal typing.
|
|
4
|
+
* Using a symbol prevents collision with actual property keys.
|
|
5
|
+
*/
|
|
6
|
+
declare const BrandSymbol: unique symbol;
|
|
7
|
+
/**
|
|
8
|
+
* A brand type that adds nominal typing to TypeScript.
|
|
9
|
+
* The brand exists only at the type level - no runtime cost.
|
|
10
|
+
*
|
|
11
|
+
* @template K - The brand key (typically a string literal type)
|
|
12
|
+
*/
|
|
13
|
+
type Brand<K extends string> = {
|
|
14
|
+
readonly [BrandSymbol]: K;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Create a branded type by intersecting a base type with a brand.
|
|
18
|
+
* The resulting type is structurally compatible with T but nominally unique.
|
|
19
|
+
*
|
|
20
|
+
* @template T - The base type to brand
|
|
21
|
+
* @template K - The brand key (string literal)
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* type UserId = Branded<string, "UserId">
|
|
26
|
+
* type OrderId = Branded<string, "OrderId">
|
|
27
|
+
*
|
|
28
|
+
* // UserId and OrderId are incompatible even though both are strings
|
|
29
|
+
* declare const userId: UserId
|
|
30
|
+
* declare const orderId: OrderId
|
|
31
|
+
* userId = orderId // Type error!
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
type Branded<T, K extends string> = T & Brand<K>;
|
|
35
|
+
/**
|
|
36
|
+
* Extract the base type from a branded type.
|
|
37
|
+
* Useful for working with the underlying value.
|
|
38
|
+
*
|
|
39
|
+
* @template B - A branded type
|
|
40
|
+
*/
|
|
41
|
+
type Unbrand<B> = B extends Branded<infer T, string> ? T : B;
|
|
42
|
+
/**
|
|
43
|
+
* A validation function that checks if a value can be branded.
|
|
44
|
+
* Returns true if the value passes validation, false otherwise.
|
|
45
|
+
*
|
|
46
|
+
* @template T - The base type being validated
|
|
47
|
+
*/
|
|
48
|
+
type Validator<T> = (value: T) => boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Error type returned when brand validation fails.
|
|
51
|
+
* Contains the original value and error message for debugging.
|
|
52
|
+
*
|
|
53
|
+
* @template T - The type of the value that failed validation
|
|
54
|
+
*/
|
|
55
|
+
type BrandError<T = unknown> = {
|
|
56
|
+
readonly _tag: "BrandError";
|
|
57
|
+
readonly value: T;
|
|
58
|
+
readonly message: string;
|
|
59
|
+
};
|
|
60
|
+
//#endregion
|
|
61
|
+
export { Validator as i, Branded as n, Unbrand as r, BrandError as t };
|
|
62
|
+
//# sourceMappingURL=brand.types-B3NDX1vo.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brand.types-B3NDX1vo.d.mts","names":[],"sources":["../src/brand/brand.types.ts"],"sourcesContent":[],"mappings":";;;AAIwC;AA8BxC;cA9Bc,WA8B6B,EAAA,OAAA,MAAA;;;;AAQ3C;;;KA9BK,KA8B6D,CAAA,UAAA,MAAA,CAAA,GAAA;EAAC,UA7BvD,WAAA,CA6BuD,EA7BzC,CA6ByC;AAQnE,CAAA;AAQA;;;;;;;;;;;;;;;;;;KAxBY,+BAA+B,IAAI,MAAM;;;;;;;KAQzC,aAAa,UAAU,+BAA+B;;;;;;;KAQtD,uBAAuB;;;;;;;KAQvB;;kBAEM"}
|
package/dist/context/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as context_d_exports } from "../context-
|
|
1
|
+
import { n as context_d_exports } from "../context-B2dWloPl.mjs";
|
|
2
2
|
export { context_d_exports as Context };
|
package/dist/context/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"../context-
|
|
1
|
+
import{t as e}from"../context-0xDbwtpx.mjs";export{e as Context};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=context-
|
|
1
|
+
import{t as e}from"./chunk-oQKkju2G.mjs";var t=e({add:()=>i,empty:()=>n,get:()=>o,has:()=>s,make:()=>r,merge:()=>a,size:()=>c});const n=()=>({_tag:`Context`,_services:new Map,_Services:void 0}),r=(e,t)=>({_tag:`Context`,_services:new Map([[e.key,t]]),_Services:void 0}),i=(e,t)=>n=>({_tag:`Context`,_services:new Map([...n._services,[e.key,t]]),_Services:void 0}),a=(e,t)=>({_tag:`Context`,_services:new Map([...e._services,...t._services]),_Services:void 0});function o(e,t){if(t===void 0){let t=e;return e=>{let n=e._services.get(t.key);if(n===void 0)throw Error(`Service "${t.key}" not found in context. Available services: [${[...e._services.keys()].join(`, `)}]`);return n}}let n=e,r=t,i=n._services.get(r.key);if(i===void 0)throw Error(`Service "${r.key}" not found in context. Available services: [${[...n._services.keys()].join(`, `)}]`);return i}const s=(e,t)=>e._services.has(t.key),c=e=>e._services.size;export{a as i,n,r,t};
|
|
2
|
+
//# sourceMappingURL=context-0xDbwtpx.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-0xDbwtpx.mjs","names":["service","impl","ctx"],"sources":["../src/context/context.ts"],"sourcesContent":["/**\n * Immutable service context map used by `Fx`, `Layer`, and `Provide`.\n *\n * **Mental model**\n * - A `Context` is a typed map from service key to implementation.\n * - Use it as the runtime carrier for dependency injection.\n *\n * **Common tasks**\n * - Start with `Context.empty` or `Context.make`.\n * - Combine contexts with `Context.add` and `Context.merge`.\n * - Resolve implementations with `Context.get`.\n *\n * **Gotchas**\n * - `Context.get` throws when a service is missing.\n * - Context values are immutable snapshots.\n *\n * **Quickstart**\n *\n * @example\n * ```ts\n * import { Context } from \"@nicolastoulemont/std\"\n *\n * const ctx = Context.empty()\n * // => { _tag: \"Context\", _services: Map(0) }\n * ```\n *\n * @module\n */\nimport type { ServiceClass } from \"../service/service\"\n\n/* oxlint-disable no-unsafe-type-assertion -- Context uses phantom service-type markers and overloaded accessors that require narrowed assertions. */\n\n// ============================================================================\n// Context Type\n// ============================================================================\n\n/**\n * Context<Services> is an immutable map storing service implementations.\n * The Services type parameter tracks which services are available.\n *\n * @example\n * ```ts\n * import { Context } from \"@nicolastoulemont/std\"\n *\n * type Example = typeof Context\n * ```\n */\nexport type Context<Services = never> = {\n readonly _tag: \"Context\"\n readonly _services: ReadonlyMap<string, unknown>\n // Phantom type for tracking available services\n readonly _Services: Services\n}\n\n// ============================================================================\n// Context Constructors\n// ============================================================================\n\n/**\n * Create an empty context with no services.\n *\n * @example\n * ```ts\n * import { Context } from \"@nicolastoulemont/std\"\n *\n * const ctx = Context.empty()\n * // => { _tag: \"Context\", _services: Map(0) }\n * ```\n */\nexport const empty = (): Context => ({\n _tag: \"Context\",\n _services: new Map(),\n _Services: undefined as never,\n})\n\n/**\n * Create a context with a single service.\n *\n * @param service - The service class (tag)\n * @param impl - The service implementation\n * @returns A context containing the service\n *\n * @example\n * ```ts\n * import { Context } from \"@nicolastoulemont/std\"\n *\n * import { Service } from \"@nicolastoulemont/std\"\n *\n * const Logger = Service.tag<{ log: (message: string) => void }>(\"Logger\")\n * const ctx = Context.make(Logger, { log: (message) => console.log(message) })\n * // => context containing Logger\n * ```\n */\nexport const make = <S>(service: ServiceClass<S>, impl: S): Context<S> => ({\n _tag: \"Context\",\n _services: new Map([[service.key, impl]]),\n _Services: undefined as unknown as S,\n})\n\n// ============================================================================\n// Context Operations\n// ============================================================================\n\n/**\n * Add a service to an existing context (returns new context).\n * Curried for use with pipe.\n *\n * @param service - The service class (tag)\n * @param impl - The service implementation\n * @returns A function that takes a context and returns a new context with the service added\n *\n * @example\n * ```ts\n * import { Context } from \"@nicolastoulemont/std\"\n *\n * import { Service } from \"@nicolastoulemont/std\"\n *\n * const Logger = Service.tag<{ log: (message: string) => void }>(\"Logger\")\n * const Clock = Service.tag<{ now: () => number }>(\"Clock\")\n * const base = Context.make(Logger, { log: () => undefined })\n * const extended = Context.add(Clock, { now: () => 123 })(base)\n * // => context with Logger and Clock\n * ```\n */\nexport const add =\n <S>(service: ServiceClass<S>, impl: S) =>\n <Existing>(ctx: Context<Existing>): Context<Existing | S> => ({\n _tag: \"Context\",\n _services: new Map([...ctx._services, [service.key, impl]]),\n _Services: undefined as unknown as Existing | S,\n })\n\n/**\n * Merge two contexts together.\n * If both contexts have the same service, the second context's implementation wins.\n *\n * @param a - First context\n * @param b - Second context\n * @returns A new context with services from both\n *\n * @example\n * ```ts\n * import { Context } from \"@nicolastoulemont/std\"\n *\n * import { Service } from \"@nicolastoulemont/std\"\n *\n * const Logger = Service.tag<{ log: (message: string) => void }>(\"Logger\")\n * const Clock = Service.tag<{ now: () => number }>(\"Clock\")\n * const a = Context.make(Logger, { log: () => undefined })\n * const b = Context.make(Clock, { now: () => 123 })\n * const merged = Context.merge(a, b)\n * // => context with both services\n * ```\n */\nexport const merge = <A, B>(a: Context<A>, b: Context<B>): Context<A | B> => ({\n _tag: \"Context\",\n _services: new Map([...a._services, ...b._services]),\n _Services: undefined as unknown as A | B,\n})\n\n/**\n * Get a service from a context.\n * Throws if the service is not found.\n *\n * @param service - The service class (tag)\n * @returns The service implementation\n * @throws Error if service not found\n *\n * @example\n * ```ts\n * import { Context } from \"@nicolastoulemont/std\"\n *\n * import { Service } from \"@nicolastoulemont/std\"\n *\n * const Port = Service.tag<number>(\"Port\")\n * const ctx = Context.make(Port, 3000)\n * const port = Context.get(ctx, Port)\n * // => 3000\n * ```\n */\n// Use overload to handle both curried and uncurried calls\nexport function get<S>(ctx: Context<S>, service: ServiceClass<S>): S\nexport function get<S>(service: ServiceClass<S>): (ctx: Context<S>) => S\nexport function get<S>(\n ctxOrService: Context<S> | ServiceClass<S>,\n maybeService?: ServiceClass<S>,\n): S | ((ctx: Context<S>) => S) {\n // Curried form: get(service)(ctx)\n if (maybeService === undefined) {\n const service = ctxOrService as ServiceClass<S>\n return (ctx: Context<S>): S => {\n const impl = ctx._services.get(service.key)\n if (impl === undefined) {\n throw new Error(\n `Service \"${service.key}\" not found in context. Available services: [${[...ctx._services.keys()].join(\", \")}]`,\n )\n }\n return impl as S\n }\n }\n\n // Uncurried form: get(ctx, service)\n const ctx = ctxOrService as Context<S>\n const service = maybeService\n const impl = ctx._services.get(service.key)\n if (impl === undefined) {\n throw new Error(\n `Service \"${service.key}\" not found in context. Available services: [${[...ctx._services.keys()].join(\", \")}]`,\n )\n }\n return impl as S\n}\n\n/**\n * Check if a context contains a specific service.\n *\n * @param ctx - The context to check\n * @param service - The service class (tag)\n * @returns true if the service is in the context\n *\n * @example\n * ```ts\n * import { Context } from \"@nicolastoulemont/std\"\n *\n * import { Service } from \"@nicolastoulemont/std\"\n *\n * const Port = Service.tag<number>(\"Port\")\n * const ctx = Context.make(Port, 3000)\n * const present = Context.has(ctx, Port)\n * // => true\n * ```\n */\nexport const has = <S>(ctx: Context<unknown>, service: ServiceClass<S>): boolean => ctx._services.has(service.key)\n\n/**\n * Get the size (number of services) in a context.\n *\n * @example\n * ```ts\n * import { Context } from \"@nicolastoulemont/std\"\n *\n * import { Service } from \"@nicolastoulemont/std\"\n *\n * const Port = Service.tag<number>(\"Port\")\n * const Logger = Service.tag<{ log: (message: string) => void }>(\"Logger\")\n * const ctx = Context.add(Logger, { log: () => undefined })(Context.make(Port, 3000))\n * const count = Context.size(ctx)\n * // => 2\n * ```\n */\nexport const size = (ctx: Context<unknown>): number => ctx._services.size\n\n/* oxlint-enable no-unsafe-type-assertion */\n"],"mappings":"gIAqEA,MAAa,OAAwB,CACnC,KAAM,UACN,UAAW,IAAI,IACf,UAAW,IAAA,GACZ,EAoBY,GAAW,EAA0B,KAAyB,CACzE,KAAM,UACN,UAAW,IAAI,IAAI,CAAC,CAAC,EAAQ,IAAK,EAAK,CAAC,CAAC,CACzC,UAAW,IAAA,GACZ,EA2BY,GACP,EAA0B,IACnB,IAAmD,CAC5D,KAAM,UACN,UAAW,IAAI,IAAI,CAAC,GAAG,EAAI,UAAW,CAAC,EAAQ,IAAK,EAAK,CAAC,CAAC,CAC3D,UAAW,IAAA,GACZ,EAwBU,GAAe,EAAe,KAAmC,CAC5E,KAAM,UACN,UAAW,IAAI,IAAI,CAAC,GAAG,EAAE,UAAW,GAAG,EAAE,UAAU,CAAC,CACpD,UAAW,IAAA,GACZ,EAyBD,SAAgB,EACd,EACA,EAC8B,CAE9B,GAAI,IAAiB,IAAA,GAAW,CAC9B,IAAMA,EAAU,EAChB,MAAQ,IAAuB,CAC7B,IAAMC,EAAOC,EAAI,UAAU,IAAIF,EAAQ,IAAI,CAC3C,GAAIC,IAAS,IAAA,GACX,MAAU,MACR,YAAYD,EAAQ,IAAI,+CAA+C,CAAC,GAAGE,EAAI,UAAU,MAAM,CAAC,CAAC,KAAK,KAAK,CAAC,GAC7G,CAEH,OAAOD,GAKX,IAAM,EAAM,EACN,EAAU,EACV,EAAO,EAAI,UAAU,IAAI,EAAQ,IAAI,CAC3C,GAAI,IAAS,IAAA,GACX,MAAU,MACR,YAAY,EAAQ,IAAI,+CAA+C,CAAC,GAAG,EAAI,UAAU,MAAM,CAAC,CAAC,KAAK,KAAK,CAAC,GAC7G,CAEH,OAAO,EAsBT,MAAa,GAAU,EAAuB,IAAsC,EAAI,UAAU,IAAI,EAAQ,IAAI,CAkBrG,EAAQ,GAAkC,EAAI,UAAU"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as ServiceClass } from "./service-
|
|
1
|
+
import { t as ServiceClass } from "./service-D8mr0wwg.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/context/context.d.ts
|
|
4
4
|
declare namespace context_d_exports {
|
|
@@ -14,8 +14,6 @@ declare namespace context_d_exports {
|
|
|
14
14
|
*
|
|
15
15
|
* type Example = typeof Context
|
|
16
16
|
* ```
|
|
17
|
-
*
|
|
18
|
-
* @category Models
|
|
19
17
|
*/
|
|
20
18
|
type Context<Services = never> = {
|
|
21
19
|
readonly _tag: "Context";
|
|
@@ -32,8 +30,6 @@ type Context<Services = never> = {
|
|
|
32
30
|
* const ctx = Context.empty()
|
|
33
31
|
* // => { _tag: "Context", _services: Map(0) }
|
|
34
32
|
* ```
|
|
35
|
-
*
|
|
36
|
-
* @category Constructors
|
|
37
33
|
*/
|
|
38
34
|
declare const empty: () => Context;
|
|
39
35
|
/**
|
|
@@ -53,8 +49,6 @@ declare const empty: () => Context;
|
|
|
53
49
|
* const ctx = Context.make(Logger, { log: (message) => console.log(message) })
|
|
54
50
|
* // => context containing Logger
|
|
55
51
|
* ```
|
|
56
|
-
*
|
|
57
|
-
* @category Utilities
|
|
58
52
|
*/
|
|
59
53
|
declare const make: <S>(service: ServiceClass<S>, impl: S) => Context<S>;
|
|
60
54
|
/**
|
|
@@ -77,8 +71,6 @@ declare const make: <S>(service: ServiceClass<S>, impl: S) => Context<S>;
|
|
|
77
71
|
* const extended = Context.add(Clock, { now: () => 123 })(base)
|
|
78
72
|
* // => context with Logger and Clock
|
|
79
73
|
* ```
|
|
80
|
-
*
|
|
81
|
-
* @category Utilities
|
|
82
74
|
*/
|
|
83
75
|
declare const add: <S>(service: ServiceClass<S>, impl: S) => <Existing>(ctx: Context<Existing>) => Context<Existing | S>;
|
|
84
76
|
/**
|
|
@@ -102,8 +94,6 @@ declare const add: <S>(service: ServiceClass<S>, impl: S) => <Existing>(ctx: Con
|
|
|
102
94
|
* const merged = Context.merge(a, b)
|
|
103
95
|
* // => context with both services
|
|
104
96
|
* ```
|
|
105
|
-
*
|
|
106
|
-
* @category Utilities
|
|
107
97
|
*/
|
|
108
98
|
declare const merge: <A, B>(a: Context<A>, b: Context<B>) => Context<A | B>;
|
|
109
99
|
/**
|
|
@@ -125,8 +115,6 @@ declare const merge: <A, B>(a: Context<A>, b: Context<B>) => Context<A | B>;
|
|
|
125
115
|
* const port = Context.get(ctx, Port)
|
|
126
116
|
* // => 3000
|
|
127
117
|
* ```
|
|
128
|
-
*
|
|
129
|
-
* @category Utilities
|
|
130
118
|
*/
|
|
131
119
|
declare function get<S>(ctx: Context<S>, service: ServiceClass<S>): S;
|
|
132
120
|
declare function get<S>(service: ServiceClass<S>): (ctx: Context<S>) => S;
|
|
@@ -148,8 +136,6 @@ declare function get<S>(service: ServiceClass<S>): (ctx: Context<S>) => S;
|
|
|
148
136
|
* const present = Context.has(ctx, Port)
|
|
149
137
|
* // => true
|
|
150
138
|
* ```
|
|
151
|
-
*
|
|
152
|
-
* @category Guards
|
|
153
139
|
*/
|
|
154
140
|
declare const has: <S>(ctx: Context<unknown>, service: ServiceClass<S>) => boolean;
|
|
155
141
|
/**
|
|
@@ -167,10 +153,8 @@ declare const has: <S>(ctx: Context<unknown>, service: ServiceClass<S>) => boole
|
|
|
167
153
|
* const count = Context.size(ctx)
|
|
168
154
|
* // => 2
|
|
169
155
|
* ```
|
|
170
|
-
*
|
|
171
|
-
* @category Getters
|
|
172
156
|
*/
|
|
173
157
|
declare const size: (ctx: Context<unknown>) => number;
|
|
174
158
|
//#endregion
|
|
175
159
|
export { context_d_exports as n, Context as t };
|
|
176
|
-
//# sourceMappingURL=context-
|
|
160
|
+
//# sourceMappingURL=context-B2dWloPl.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-B2dWloPl.d.mts","names":[],"sources":["../src/context/context.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AA0JA;;;;;;;AAA2D,KA3G/C,OA2G+C,CAAA,WAAA,KAAA,CAAA,GAAA;EAAO,SAAA,IAAA,EAAA,SAAA;EA2BlD,SAAG,SAAA,EApIG,WAoIH,CAAA,MAAA,EAAA,OAAA,CAAA;EAAiB,SAAA,SAAA,EAlId,QAkIc;CAAR;;;;;AAC5B;;;;;;;AAkDa,cAnKA,KAmKqG,EAAA,GAAA,GAnKzF,OAmKyF;;;;;AAkBlH;;;;;;;;;;;;;;cA7Ja,mBAAoB,aAAa,UAAU,MAAI,QAAQ;;;;;;;;;;;;;;;;;;;;;;cA+BvD,kBACE,aAAa,UAAU,sBACpB,QAAQ,cAAY,QAAQ,WAAW;;;;;;;;;;;;;;;;;;;;;;;cA4B5C,iBAAkB,QAAQ,OAAO,QAAQ,OAAK,QAAQ,IAAI;;;;;;;;;;;;;;;;;;;;;iBA2BvD,YAAY,QAAQ,aAAa,aAAa,KAAK;iBACnD,gBAAgB,aAAa,WAAW,QAAQ,OAAO;;;;;;;;;;;;;;;;;;;;cAkD1D,cAAe,2BAA2B,aAAa;;;;;;;;;;;;;;;;;cAkBvD,YAAa"}
|
package/dist/data/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as data_d_exports } from "../index-
|
|
1
|
+
import { t as data_d_exports } from "../index-UINIHFuh.mjs";
|
|
2
2
|
export { data_d_exports as Data };
|
package/dist/data/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"../data-
|
|
1
|
+
import{n as e}from"../data-BHYPdqWZ.mjs";export{e as Data};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=data-
|
|
1
|
+
import{t as e}from"./chunk-oQKkju2G.mjs";import{a as t,i as n,o as r,r as i}from"./equality-BX6BUidG.mjs";import{t as a}from"./fx.types-DyQVgTS8.mjs";function o(e){let n=[...e];Object.defineProperty(n,`equals`,{value:e=>t(n,e),enumerable:!1,writable:!1,configurable:!1}),Object.defineProperty(n,`hash`,{value:()=>r(n),enumerable:!1,writable:!1,configurable:!1});let i=n.map.bind(n);Object.defineProperty(n,`map`,{value:e=>o(i(e)),enumerable:!1,writable:!1,configurable:!1});let a=n.filter.bind(n);Object.defineProperty(n,`filter`,{value:e=>o(a(e)),enumerable:!1,writable:!1,configurable:!1});let s=n.slice.bind(n);Object.defineProperty(n,`slice`,{value:(e,t)=>o(s(e,t)),enumerable:!1,writable:!1,configurable:!1});let c=n.concat.bind(n);return Object.defineProperty(n,`concat`,{value:(...e)=>o(c(...e)),enumerable:!1,writable:!1,configurable:!1}),Object.freeze(n)}function s(e){let n={...e};return Object.defineProperty(n,`equals`,{value:e=>t(n,e),enumerable:!1,writable:!1,configurable:!1}),Object.defineProperty(n,`hash`,{value:()=>r(n),enumerable:!1,writable:!1,configurable:!1}),Object.freeze(n)}function c(e){let t=t=>Object.freeze({...t,_tag:e});return t.is=t=>typeof t==`object`&&!!t&&`_tag`in t&&t._tag===e,t.equals=i(e),t.hash=n(e),t._tag=e,t}function l(e){return class extends Error{static _tag=e;_tag=e;[a]={_A:()=>void 0,_E:()=>this,_R:()=>void 0};constructor(...t){super(e),this.name=e;let n=t[0];n&&Object.assign(this,n),Object.setPrototypeOf(this,new.target.prototype)}*[Symbol.iterator](){throw yield this,Error(`Unreachable: Fx.gen should short-circuit on error`)}}}function u(...e){let n=[...e];return Object.defineProperty(n,`equals`,{value:e=>t(n,e),enumerable:!1,writable:!1,configurable:!1}),Object.defineProperty(n,`hash`,{value:()=>r(n),enumerable:!1,writable:!1,configurable:!1}),Object.freeze(n)}var d=e({TaggedError:()=>p,array:()=>g,struct:()=>m,tagged:()=>f,tuple:()=>h});const f=c,p=l,m=s,h=u,g=o;export{d as n,p as t};
|
|
2
|
+
//# sourceMappingURL=data-BHYPdqWZ.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-BLXO4XwS.mjs","names":["array","struct","tagged","TaggedError","tuple","taggedImpl","TaggedErrorImpl","structImpl","tupleImpl","arrayImpl"],"sources":["../src/data/data.array.ts","../src/data/data.struct.ts","../src/data/data.tagged.ts","../src/data/data.tagged-error.ts","../src/data/data.tuple.ts","../src/data/data.ts"],"sourcesContent":["import { deepEquals, deepHash } from \"../equality/equality\"\nimport type { ArrayValue } from \"./data.types\"\n\n/**\n * Create an array with structural equality.\n *\n * The returned array is frozen (immutable) and has non-enumerable\n * equals() and hash() methods for structural comparison.\n *\n * The map() and filter() methods are overridden to return ArrayValue,\n * enabling method chaining with preserved equality semantics.\n *\n * @template T - The element type of the array\n * @param items - The array elements\n * @returns A frozen array with equals(), hash(), map(), and filter()\n *\n * @see {@link tuple} for fixed-length typed tuples\n * @see {@link struct} for object value types\n *\n * @example\n * ```ts\n * const arr1 = array([1, 2, 3])\n * const arr2 = array([1, 2, 3])\n *\n * arr1.equals(arr2) // true\n * arr1.hash() // number\n *\n * // Chainable operations return ArrayValue\n * arr1.map(x => x * 2) // ArrayValue<number>\n * arr1.filter(x => x > 1) // ArrayValue<number>\n *\n * // Chained equality check\n * arr1.map(x => x * 2).equals(array([2, 4, 6])) // true\n *\n * // Array is frozen\n * arr1[0] = 5 // TypeError\n * arr1.push(4) // TypeError\n * ```\n */\nexport function array<T>(items: readonly T[]): ArrayValue<T> {\n const value = [...items]\n\n // Add equals method (non-enumerable)\n Object.defineProperty(value, \"equals\", {\n value: (other: readonly T[]) => deepEquals(value, other),\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Add hash method (non-enumerable)\n Object.defineProperty(value, \"hash\", {\n value: () => deepHash(value),\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Override map to return ArrayValue\n const originalMap = value.map.bind(value)\n Object.defineProperty(value, \"map\", {\n value: <U>(fn: (item: T, index: number, arr: readonly T[]) => U): ArrayValue<U> => {\n return array(originalMap(fn))\n },\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Override filter to return ArrayValue\n const originalFilter = value.filter.bind(value)\n Object.defineProperty(value, \"filter\", {\n value: (fn: (item: T, index: number, arr: readonly T[]) => boolean): ArrayValue<T> => {\n return array(originalFilter(fn))\n },\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Override slice to return ArrayValue\n const originalSlice = value.slice.bind(value)\n Object.defineProperty(value, \"slice\", {\n value: (start?: number, end?: number): ArrayValue<T> => {\n return array(originalSlice(start, end))\n },\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Override concat to return ArrayValue\n const originalConcat = value.concat.bind(value)\n Object.defineProperty(value, \"concat\", {\n value: (...args: readonly (T | readonly T[])[]): ArrayValue<T> => {\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for concat argument spread\n return array(originalConcat(...(args as T[][])))\n },\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for generic array return type\n return Object.freeze(value) as unknown as ArrayValue<T>\n}\n","import { deepEquals, deepHash } from \"../equality/equality\"\nimport type { StructValue } from \"./data.types\"\n\n/**\n * Create a frozen value object with structural equality.\n *\n * Unlike tagged(), struct() does not add a _tag discriminator.\n * Use this for simple value objects that don't need discrimination.\n *\n * The returned object is frozen (immutable) and has non-enumerable\n * equals() and hash() methods for structural comparison.\n *\n * @template T - The object shape type\n * @param input - The object to wrap\n * @returns A frozen object with equals() and hash() methods\n *\n * @see {@link tagged} for discriminated value objects with _tag\n * @see {@link array} for array value types\n *\n * @example\n * ```ts\n * const point = struct({ x: 10, y: 20 })\n * const point2 = struct({ x: 10, y: 20 })\n *\n * point.equals(point2) // true\n * point.hash() // number\n *\n * // Object is frozen\n * point.x = 5 // TypeError\n *\n * // equals/hash are non-enumerable\n * Object.keys(point) // [\"x\", \"y\"]\n * ```\n */\nexport function struct<T extends Record<string, unknown>>(input: T): StructValue<T> {\n const value = { ...input }\n\n // Add equals method (non-enumerable)\n Object.defineProperty(value, \"equals\", {\n value: (other: T) => deepEquals(value, other),\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Add hash method (non-enumerable)\n Object.defineProperty(value, \"hash\", {\n value: () => deepHash(value),\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for generic struct return type\n return Object.freeze(value) as StructValue<T>\n}\n","import { createEqualsMethod, createHashMethod } from \"../equality/equality\"\nimport type { Discriminator } from \"../shared/discriminator.types\"\nimport type { TaggedConstructor, TaggedValue } from \"./data.types\"\n\n/**\n * Create a tagged value constructor without schema validation.\n *\n * Unlike variant(), this creates values directly without validation.\n * Values are frozen and have structural equality via equals() and hash() methods.\n *\n * @template T - The data shape type (excluding _tag)\n * @param tag - The _tag discriminator value\n * @returns A constructor function with is(), equals(), and hash() methods\n *\n * @see {@link variant} for validated variant with schema support\n * @see {@link struct} for untagged value objects\n *\n * @example\n * ```ts\n * const Person = tagged<{ name: string; age: number }>(\"Person\")\n *\n * const alice = Person({ name: \"Alice\", age: 30 })\n * // => { _tag: \"Person\", name: \"Alice\", age: 30 }\n *\n * Person.equals(alice, Person({ name: \"Alice\", age: 30 })) // true\n * Person.is(alice) // true\n *\n * // Type guard usage\n * if (Person.is(unknownValue)) {\n * console.log(unknownValue.name) // TypeScript knows it's a Person\n * }\n *\n * // Values are frozen (immutable)\n * alice.name = \"Bob\" // TypeError\n * ```\n */\nexport function tagged<T extends Record<string, unknown>>(tag: string): TaggedConstructor<typeof tag, T> {\n type Output = TaggedValue<typeof tag, T>\n\n // Constructor function\n const constructor = (input: T): Output => {\n return Object.freeze({ ...input, _tag: tag }) as Output\n }\n\n // Type guard\n constructor.is = (value: unknown): value is Output => {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"_tag\" in value &&\n // oxlint-disable-next-line no-unsafe-type-assertion -- Already checked with 'in' operator\n (value as Discriminator)._tag === tag\n )\n }\n\n // Equality (static method on constructor)\n constructor.equals = createEqualsMethod<typeof tag, T>(tag)\n\n // Hashing (static method on constructor)\n constructor.hash = createHashMethod<typeof tag, T>(tag)\n\n // Store tag for reflection\n constructor._tag = tag\n\n return constructor as TaggedConstructor<typeof tag, T>\n}\n","import { FxTypeId } from \"../fx/fx.types\"\nimport type { TaggedErrorFactory } from \"./data.tagged-error.types\"\n\n/* oxlint-disable no-unsafe-type-assertion -- Tagged error factories intentionally cast to preserve ergonomic constructor signatures and Fx marker channels. */\n\n/**\n * Create a class-based tagged error type (Effect-style syntax).\n * Returns a class that can be extended to create custom error types.\n * Errors are native Error objects with proper stack traces and instanceof support.\n * Implements Yieldable protocol so errors can be directly yielded in Fx.gen computations.\n *\n * @template Tag - The error tag (discriminator string)\n * @param tag - The error tag\n * @returns A class that can be extended with custom data\n *\n * @example\n * ```ts\n * // Error with data\n * class NotFoundError extends TaggedError(\"NotFoundError\")<{ id: string }> {}\n * const err = new NotFoundError({ id: \"123\" })\n * err.id // \"123\"\n * err._tag // \"NotFoundError\"\n * err.stack // Error stack trace\n *\n * // Error without data\n * class UnauthorizedError extends TaggedError(\"UnauthorizedError\") {}\n * const err2 = new UnauthorizedError()\n *\n * // Direct yielding in Fx.gen computation\n * const program = Fx.gen(function* () {\n * yield* new NotFoundError({ id: \"123\" }) // Short-circuits with error\n * })\n *\n * // instanceof checks work\n * if (err instanceof NotFoundError) {\n * console.log(err.id)\n * }\n * ```\n */\nexport function TaggedError<Tag extends string>(tag: Tag): TaggedErrorFactory<Tag> {\n return class TaggedErrorImpl<Data extends object = object> extends Error {\n static readonly _tag: Tag = tag\n readonly _tag: Tag = tag\n\n readonly [FxTypeId] = {\n _A: () => undefined as never,\n _E: () => this as TaggedErrorImpl<Data>,\n _R: () => undefined as never,\n }\n\n constructor(...args: keyof Data extends never ? [] : [data: Data]) {\n super(tag)\n this.name = tag\n const data = args[0]\n if (data) Object.assign(this, data)\n Object.setPrototypeOf(this, new.target.prototype)\n }\n\n *[Symbol.iterator](): Generator<this, never, unknown> {\n yield this\n throw new Error(\"Unreachable: Fx.gen should short-circuit on error\")\n }\n } as unknown as TaggedErrorFactory<Tag>\n}\n\n/* oxlint-enable no-unsafe-type-assertion */\n","import { deepEquals, deepHash } from \"../equality/equality\"\nimport type { TupleValue } from \"./data.types\"\n\n/**\n * Create a tuple with structural equality.\n *\n * The returned tuple is frozen (immutable) and has non-enumerable\n * equals() and hash() methods for structural comparison.\n *\n * @template T - The tuple type as a readonly array of element types\n * @param args - The tuple elements\n * @returns A frozen tuple-like array with equals() and hash() methods\n *\n * @see {@link array} for variable-length arrays with equality\n * @see {@link struct} for object value types\n *\n * @example\n * ```ts\n * const t1 = tuple(1, \"hello\", true)\n * const t2 = tuple(1, \"hello\", true)\n *\n * t1.equals(t2) // true\n * t1.hash() // number\n *\n * // Access elements (typed)\n * t1[0] // number\n * t1[1] // string\n * t1[2] // boolean\n *\n * // Tuple is frozen\n * t1[0] = 5 // TypeError\n * ```\n */\nexport function tuple<T extends readonly unknown[]>(...args: T): TupleValue<T> {\n const value = [...args]\n\n // Add equals method (non-enumerable)\n Object.defineProperty(value, \"equals\", {\n value: (other: readonly unknown[]) => deepEquals(value, other),\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Add hash method (non-enumerable)\n Object.defineProperty(value, \"hash\", {\n value: () => deepHash(value),\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for generic tuple return type\n return Object.freeze(value) as unknown as TupleValue<T>\n}\n","/**\n * Structural data constructors for tagged objects, tuples, arrays, and records.\n *\n * **Mental model**\n * - `Data` helpers create immutable-friendly values with structural equality semantics.\n * - Use `tagged` and `TaggedError` to model domain objects and errors.\n *\n * **Common tasks**\n * - Build tagged records via `Data.tagged`.\n * - Define typed tagged errors with `Data.TaggedError`.\n * - Create structural containers with `Data.struct`, `Data.tuple`, and `Data.array`.\n *\n * **Gotchas**\n * - These constructors are value-level utilities, not validation schemas.\n * - Prefer explicit tagged names for debugging and pattern matching.\n *\n * **Quickstart**\n *\n * @example\n * ```ts\n * import { Data } from \"@nicolastoulemont/std\"\n *\n * const User = Data.tagged<{ id: string }>(\"User\")\n * const user = User({ id: \"u1\" })\n * // => { _tag: \"User\", id: \"u1\" }\n * ```\n *\n * @module\n */\nimport { array as arrayImpl } from \"./data.array\"\nimport { struct as structImpl } from \"./data.struct\"\nimport { tagged as taggedImpl } from \"./data.tagged\"\nimport { TaggedError as TaggedErrorImpl } from \"./data.tagged-error\"\nimport { tuple as tupleImpl } from \"./data.tuple\"\n\n/**\n * Construct tagged data objects.\n *\n * @example\n * ```ts\n * import { Data } from \"@nicolastoulemont/std\"\n *\n * const User = Data.tagged<{ id: string }>(\"User\")\n * const user = User({ id: \"u1\" })\n * // => { _tag: \"User\", id: \"u1\" }\n * ```\n *\n * @category Constructors\n */\nexport const tagged = taggedImpl\n\n/**\n * Construct tagged error classes.\n *\n * @example\n * ```ts\n * import { Data } from \"@nicolastoulemont/std\"\n *\n * class NotFoundError extends Data.TaggedError(\"NotFoundError\")<{ id: string }> {}\n * const error = new NotFoundError({ id: \"u1\" })\n * // => { _tag: \"NotFoundError\", id: \"u1\" }\n * ```\n *\n * @category Constructors\n */\nexport const TaggedError = TaggedErrorImpl\n\n/**\n * Construct immutable-like structs with stable structural behavior.\n *\n * @example\n * ```ts\n * import { Data } from \"@nicolastoulemont/std\"\n *\n * const point = Data.struct({ x: 1, y: 2 })\n * const same = point.equals({ x: 1, y: 2 })\n * // => true\n * ```\n *\n * @category Constructors\n */\nexport const struct = structImpl\n\n/**\n * Construct immutable-like tuples with stable structural behavior.\n *\n * @example\n * ```ts\n * import { Data } from \"@nicolastoulemont/std\"\n *\n * const pair = Data.tuple(\"left\", 1)\n * const first = pair[0]\n * // => \"left\"\n * ```\n *\n * @category Constructors\n */\nexport const tuple = tupleImpl\n\n/**\n * Construct immutable-like arrays with stable structural behavior.\n *\n * @example\n * ```ts\n * import { Data } from \"@nicolastoulemont/std\"\n *\n * const ids = Data.array([\"a\", \"b\"])\n * const upper = ids.map((id) => id.toUpperCase())\n * // => [\"A\", \"B\"]\n * ```\n *\n * @category Constructors\n */\nexport const array = arrayImpl\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"data-BHYPdqWZ.mjs","names":["array","struct","tagged","TaggedError","tuple","taggedImpl","TaggedErrorImpl","structImpl","tupleImpl","arrayImpl"],"sources":["../src/data/data.array.ts","../src/data/data.struct.ts","../src/data/data.tagged.ts","../src/data/data.tagged-error.ts","../src/data/data.tuple.ts","../src/data/data.ts"],"sourcesContent":["import { deepEquals, deepHash } from \"../equality/equality\"\nimport type { ArrayValue } from \"./data.types\"\n\n/**\n * Create an array with structural equality.\n *\n * The returned array is frozen (immutable) and has non-enumerable\n * equals() and hash() methods for structural comparison.\n *\n * The map() and filter() methods are overridden to return ArrayValue,\n * enabling method chaining with preserved equality semantics.\n *\n * @template T - The element type of the array\n * @param items - The array elements\n * @returns A frozen array with equals(), hash(), map(), and filter()\n *\n * @see {@link tuple} for fixed-length typed tuples\n * @see {@link struct} for object value types\n *\n * @example\n * ```ts\n * const arr1 = array([1, 2, 3])\n * const arr2 = array([1, 2, 3])\n *\n * arr1.equals(arr2) // true\n * arr1.hash() // number\n *\n * // Chainable operations return ArrayValue\n * arr1.map(x => x * 2) // ArrayValue<number>\n * arr1.filter(x => x > 1) // ArrayValue<number>\n *\n * // Chained equality check\n * arr1.map(x => x * 2).equals(array([2, 4, 6])) // true\n *\n * // Array is frozen\n * arr1[0] = 5 // TypeError\n * arr1.push(4) // TypeError\n * ```\n */\nexport function array<T>(items: readonly T[]): ArrayValue<T> {\n const value = [...items]\n\n // Add equals method (non-enumerable)\n Object.defineProperty(value, \"equals\", {\n value: (other: readonly T[]) => deepEquals(value, other),\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Add hash method (non-enumerable)\n Object.defineProperty(value, \"hash\", {\n value: () => deepHash(value),\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Override map to return ArrayValue\n const originalMap = value.map.bind(value)\n Object.defineProperty(value, \"map\", {\n value: <U>(fn: (item: T, index: number, arr: readonly T[]) => U): ArrayValue<U> => {\n return array(originalMap(fn))\n },\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Override filter to return ArrayValue\n const originalFilter = value.filter.bind(value)\n Object.defineProperty(value, \"filter\", {\n value: (fn: (item: T, index: number, arr: readonly T[]) => boolean): ArrayValue<T> => {\n return array(originalFilter(fn))\n },\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Override slice to return ArrayValue\n const originalSlice = value.slice.bind(value)\n Object.defineProperty(value, \"slice\", {\n value: (start?: number, end?: number): ArrayValue<T> => {\n return array(originalSlice(start, end))\n },\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Override concat to return ArrayValue\n const originalConcat = value.concat.bind(value)\n Object.defineProperty(value, \"concat\", {\n value: (...args: readonly (T | readonly T[])[]): ArrayValue<T> => {\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for concat argument spread\n return array(originalConcat(...(args as T[][])))\n },\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for generic array return type\n return Object.freeze(value) as unknown as ArrayValue<T>\n}\n","import { deepEquals, deepHash } from \"../equality/equality\"\nimport type { StructValue } from \"./data.types\"\n\n/**\n * Create a frozen value object with structural equality.\n *\n * Unlike tagged(), struct() does not add a _tag discriminator.\n * Use this for simple value objects that don't need discrimination.\n *\n * The returned object is frozen (immutable) and has non-enumerable\n * equals() and hash() methods for structural comparison.\n *\n * @template T - The object shape type\n * @param input - The object to wrap\n * @returns A frozen object with equals() and hash() methods\n *\n * @see {@link tagged} for discriminated value objects with _tag\n * @see {@link array} for array value types\n *\n * @example\n * ```ts\n * const point = struct({ x: 10, y: 20 })\n * const point2 = struct({ x: 10, y: 20 })\n *\n * point.equals(point2) // true\n * point.hash() // number\n *\n * // Object is frozen\n * point.x = 5 // TypeError\n *\n * // equals/hash are non-enumerable\n * Object.keys(point) // [\"x\", \"y\"]\n * ```\n */\nexport function struct<T extends Record<string, unknown>>(input: T): StructValue<T> {\n const value = { ...input }\n\n // Add equals method (non-enumerable)\n Object.defineProperty(value, \"equals\", {\n value: (other: T) => deepEquals(value, other),\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Add hash method (non-enumerable)\n Object.defineProperty(value, \"hash\", {\n value: () => deepHash(value),\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for generic struct return type\n return Object.freeze(value) as StructValue<T>\n}\n","import { createEqualsMethod, createHashMethod } from \"../equality/equality\"\nimport type { Discriminator } from \"../shared/discriminator.types\"\nimport type { TaggedConstructor, TaggedValue } from \"./data.types\"\n\n/**\n * Create a tagged value constructor without schema validation.\n *\n * Unlike variant(), this creates values directly without validation.\n * Values are frozen and have structural equality via equals() and hash() methods.\n *\n * @template T - The data shape type (excluding _tag)\n * @param tag - The _tag discriminator value\n * @returns A constructor function with is(), equals(), and hash() methods\n *\n * @see {@link variant} for validated variant with schema support\n * @see {@link struct} for untagged value objects\n *\n * @example\n * ```ts\n * const Person = tagged<{ name: string; age: number }>(\"Person\")\n *\n * const alice = Person({ name: \"Alice\", age: 30 })\n * // => { _tag: \"Person\", name: \"Alice\", age: 30 }\n *\n * Person.equals(alice, Person({ name: \"Alice\", age: 30 })) // true\n * Person.is(alice) // true\n *\n * // Type guard usage\n * if (Person.is(unknownValue)) {\n * console.log(unknownValue.name) // TypeScript knows it's a Person\n * }\n *\n * // Values are frozen (immutable)\n * alice.name = \"Bob\" // TypeError\n * ```\n */\nexport function tagged<T extends Record<string, unknown>>(tag: string): TaggedConstructor<typeof tag, T> {\n type Output = TaggedValue<typeof tag, T>\n\n // Constructor function\n const constructor = (input: T): Output => {\n return Object.freeze({ ...input, _tag: tag }) as Output\n }\n\n // Type guard\n constructor.is = (value: unknown): value is Output => {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"_tag\" in value &&\n // oxlint-disable-next-line no-unsafe-type-assertion -- Already checked with 'in' operator\n (value as Discriminator)._tag === tag\n )\n }\n\n // Equality (static method on constructor)\n constructor.equals = createEqualsMethod<typeof tag, T>(tag)\n\n // Hashing (static method on constructor)\n constructor.hash = createHashMethod<typeof tag, T>(tag)\n\n // Store tag for reflection\n constructor._tag = tag\n\n return constructor as TaggedConstructor<typeof tag, T>\n}\n","import { FxTypeId } from \"../fx/fx.types\"\nimport type { TaggedErrorFactory } from \"./data.tagged-error.types\"\n\n/* oxlint-disable no-unsafe-type-assertion -- Tagged error factories intentionally cast to preserve ergonomic constructor signatures and Fx marker channels. */\n\n/**\n * Create a class-based tagged error type (Effect-style syntax).\n * Returns a class that can be extended to create custom error types.\n * Errors are native Error objects with proper stack traces and instanceof support.\n * Implements Yieldable protocol so errors can be directly yielded in Fx.gen computations.\n *\n * @template Tag - The error tag (discriminator string)\n * @param tag - The error tag\n * @returns A class that can be extended with custom data\n *\n * @example\n * ```ts\n * // Error with data\n * class NotFoundError extends TaggedError(\"NotFoundError\")<{ id: string }> {}\n * const err = new NotFoundError({ id: \"123\" })\n * err.id // \"123\"\n * err._tag // \"NotFoundError\"\n * err.stack // Error stack trace\n *\n * // Error without data\n * class UnauthorizedError extends TaggedError(\"UnauthorizedError\") {}\n * const err2 = new UnauthorizedError()\n *\n * // Direct yielding in Fx.gen computation\n * const program = Fx.gen(function* () {\n * yield* new NotFoundError({ id: \"123\" }) // Short-circuits with error\n * })\n *\n * // instanceof checks work\n * if (err instanceof NotFoundError) {\n * console.log(err.id)\n * }\n * ```\n */\nexport function TaggedError<Tag extends string>(tag: Tag): TaggedErrorFactory<Tag> {\n return class TaggedErrorImpl<Data extends object = object> extends Error {\n static readonly _tag: Tag = tag\n readonly _tag: Tag = tag\n\n readonly [FxTypeId] = {\n _A: () => undefined as never,\n _E: () => this as TaggedErrorImpl<Data>,\n _R: () => undefined as never,\n }\n\n constructor(...args: keyof Data extends never ? [] : [data: Data]) {\n super(tag)\n this.name = tag\n const data = args[0]\n if (data) Object.assign(this, data)\n Object.setPrototypeOf(this, new.target.prototype)\n }\n\n *[Symbol.iterator](): Generator<this, never, unknown> {\n yield this\n throw new Error(\"Unreachable: Fx.gen should short-circuit on error\")\n }\n } as unknown as TaggedErrorFactory<Tag>\n}\n\n/* oxlint-enable no-unsafe-type-assertion */\n","import { deepEquals, deepHash } from \"../equality/equality\"\nimport type { TupleValue } from \"./data.types\"\n\n/**\n * Create a tuple with structural equality.\n *\n * The returned tuple is frozen (immutable) and has non-enumerable\n * equals() and hash() methods for structural comparison.\n *\n * @template T - The tuple type as a readonly array of element types\n * @param args - The tuple elements\n * @returns A frozen tuple-like array with equals() and hash() methods\n *\n * @see {@link array} for variable-length arrays with equality\n * @see {@link struct} for object value types\n *\n * @example\n * ```ts\n * const t1 = tuple(1, \"hello\", true)\n * const t2 = tuple(1, \"hello\", true)\n *\n * t1.equals(t2) // true\n * t1.hash() // number\n *\n * // Access elements (typed)\n * t1[0] // number\n * t1[1] // string\n * t1[2] // boolean\n *\n * // Tuple is frozen\n * t1[0] = 5 // TypeError\n * ```\n */\nexport function tuple<T extends readonly unknown[]>(...args: T): TupleValue<T> {\n const value = [...args]\n\n // Add equals method (non-enumerable)\n Object.defineProperty(value, \"equals\", {\n value: (other: readonly unknown[]) => deepEquals(value, other),\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // Add hash method (non-enumerable)\n Object.defineProperty(value, \"hash\", {\n value: () => deepHash(value),\n enumerable: false,\n writable: false,\n configurable: false,\n })\n\n // oxlint-disable-next-line no-unsafe-type-assertion -- Required for generic tuple return type\n return Object.freeze(value) as unknown as TupleValue<T>\n}\n","/**\n * Structural data constructors for tagged objects, tuples, arrays, and records.\n *\n * **Mental model**\n * - `Data` helpers create immutable-friendly values with structural equality semantics.\n * - Use `tagged` and `TaggedError` to model domain objects and errors.\n *\n * **Common tasks**\n * - Build tagged records via `Data.tagged`.\n * - Define typed tagged errors with `Data.TaggedError`.\n * - Create structural containers with `Data.struct`, `Data.tuple`, and `Data.array`.\n *\n * **Gotchas**\n * - These constructors are value-level utilities, not validation schemas.\n * - Prefer explicit tagged names for debugging and pattern matching.\n *\n * **Quickstart**\n *\n * @example\n * ```ts\n * import { Data } from \"@nicolastoulemont/std\"\n *\n * const User = Data.tagged<{ id: string }>(\"User\")\n * const user = User({ id: \"u1\" })\n * // => { _tag: \"User\", id: \"u1\" }\n * ```\n *\n * @module\n */\nimport { array as arrayImpl } from \"./data.array\"\nimport { struct as structImpl } from \"./data.struct\"\nimport { tagged as taggedImpl } from \"./data.tagged\"\nimport { TaggedError as TaggedErrorImpl } from \"./data.tagged-error\"\nexport type { TaggedErrorClass, TaggedErrorFactory, TaggedErrorInstance } from \"./data.tagged-error.types\"\nimport { tuple as tupleImpl } from \"./data.tuple\"\n\n/**\n * Construct tagged data objects.\n *\n * @example\n * ```ts\n * import { Data } from \"@nicolastoulemont/std\"\n *\n * const User = Data.tagged<{ id: string }>(\"User\")\n * const user = User({ id: \"u1\" })\n * // => { _tag: \"User\", id: \"u1\" }\n * ```\n */\nexport const tagged = taggedImpl\n\n/**\n * Construct tagged error classes.\n *\n * @example\n * ```ts\n * import { Data } from \"@nicolastoulemont/std\"\n *\n * class NotFoundError extends Data.TaggedError(\"NotFoundError\")<{ id: string }> {}\n * const error = new NotFoundError({ id: \"u1\" })\n * // => { _tag: \"NotFoundError\", id: \"u1\" }\n * ```\n */\nexport const TaggedError = TaggedErrorImpl\n\n/**\n * Construct immutable-like structs with stable structural behavior.\n *\n * @example\n * ```ts\n * import { Data } from \"@nicolastoulemont/std\"\n *\n * const point = Data.struct({ x: 1, y: 2 })\n * const same = point.equals({ x: 1, y: 2 })\n * // => true\n * ```\n */\nexport const struct = structImpl\n\n/**\n * Construct immutable-like tuples with stable structural behavior.\n *\n * @example\n * ```ts\n * import { Data } from \"@nicolastoulemont/std\"\n *\n * const pair = Data.tuple(\"left\", 1)\n * const first = pair[0]\n * // => \"left\"\n * ```\n */\nexport const tuple = tupleImpl\n\n/**\n * Construct immutable-like arrays with stable structural behavior.\n *\n * @example\n * ```ts\n * import { Data } from \"@nicolastoulemont/std\"\n *\n * const ids = Data.array([\"a\", \"b\"])\n * const upper = ids.map((id) => id.toUpperCase())\n * // => [\"A\", \"B\"]\n * ```\n */\nexport const array = arrayImpl\n"],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discriminator.types-C-ygT2S1.d.mts","names":[],"sources":["../src/shared/discriminator.types.ts"],"sourcesContent":[],"mappings":";KAAY;EAAA,SAAA,IAAA,EAA8D,GAAjD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
const e=function(e,t){if(typeof e==`function`)return function(){return e(arguments)?t.apply(this,arguments):(e=>t(e,...arguments))};switch(e){case 0:return t;case 1:return function(e){return arguments.length>0?t.call(this,e):t.bind(this)};case 2:return function(e,n){return arguments.length>=2?t.call(this,e,n):n=>t(n,e)};case 3:return function(e,n,r){return arguments.length>=3?t.call(this,e,n,r):r=>t(r,e,n)};case 4:return function(e,n,r,i){return arguments.length>=4?t.call(this,e,n,r,i):i=>t(i,e,n,r)};case 5:return function(e,n,r,i,a){return arguments.length>=5?t.call(this,e,n,r,i,a):a=>t(a,e,n,r,i)};default:return function(){if(arguments.length>=e)return t.apply(this,arguments);let n=arguments;return e=>t(e,...n)}}};export{e as t};
|
|
2
|
-
//# sourceMappingURL=dual-
|
|
2
|
+
//# sourceMappingURL=dual-fN6OUwN_.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dual-
|
|
1
|
+
{"version":3,"file":"dual-fN6OUwN_.mjs","names":[],"sources":["../src/shared/dual.ts"],"sourcesContent":["/**\n * Dual function utility for creating functions that support both\n * data-first and data-last (curried) calling styles.\n *\n * This pattern is inspired by Effect's dual function implementation.\n * It enables better ergonomics by allowing direct function calls\n * without requiring pipe() for simple operations.\n *\n * @example\n * ```ts\n * // Define a dual function\n * const map = dual<\n * <T, U>(self: Option<T>, fn: (value: T) => U) => Option<U>,\n * <T, U>(fn: (value: T) => U) => (self: Option<T>) => Option<U>\n * >(2, (self, fn) => self.some ? some(fn(self.value)) : none())\n *\n * // Use data-first (direct call)\n * map(some(5), x => x * 2) // Option<10>\n *\n * // Use data-last (curried for pipe)\n * pipe(some(5), map(x => x * 2)) // Option<10>\n * ```\n */\n\n/**\n * Creates a function that can be called with all arguments (data-first)\n * or partially applied (data-last) for use in pipe chains.\n *\n * @param arity - The number of arguments in the data-first version (including self)\n * @param body - The implementation function that receives all arguments\n * @returns A function that supports both calling styles\n *\n * @remarks\n * The arity parameter is used to determine whether the function is being\n * called in data-first mode (all arguments provided) or data-last mode\n * (partial application for piping).\n *\n * TypeScript 5.4+ NoInfer is used where appropriate in consuming code\n * to prevent inference from fallback positions.\n */\n/* oxlint-disable no-explicit-any, ban-types, no-unsafe-function-type, no-unsafe-assignment, no-unsafe-return, no-unsafe-call, no-unsafe-type-assertion -- Required for highly polymorphic dual implementation that relies on runtime arity dispatch */\nexport const dual: {\n <DataFirst extends (...args: any) => any, DataLast extends (...args: any) => any>(\n arity: Parameters<DataFirst>[\"length\"],\n body: DataFirst,\n ): DataFirst & DataLast\n <DataFirst extends (...args: any) => any, DataLast extends (...args: any) => any>(\n isDataFirst: (args: IArguments) => boolean,\n body: DataFirst,\n ): DataFirst & DataLast\n} = function (arityOrIsDataFirst: number | ((args: IArguments) => boolean), body: Function) {\n if (typeof arityOrIsDataFirst === \"function\") {\n return function (this: unknown) {\n // oxlint-disable-next-line prefer-rest-params\n if (arityOrIsDataFirst(arguments)) {\n // oxlint-disable-next-line prefer-rest-params\n return body.apply(this, arguments)\n }\n // oxlint-disable-next-line prefer-rest-params\n return ((self: unknown) => body(self, ...arguments)) as unknown\n }\n }\n switch (arityOrIsDataFirst) {\n case 0:\n return body\n case 1:\n return function (this: unknown, a: unknown) {\n if (arguments.length > 0) {\n return body.call(this, a)\n }\n return body.bind(this)\n }\n case 2:\n return function (this: unknown, a: unknown, b: unknown) {\n if (arguments.length >= 2) {\n return body.call(this, a, b)\n }\n return (self: unknown) => body(self, a)\n }\n case 3:\n return function (this: unknown, a: unknown, b: unknown, c: unknown) {\n if (arguments.length >= 3) {\n return body.call(this, a, b, c)\n }\n return (self: unknown) => body(self, a, b)\n }\n case 4:\n return function (this: unknown, a: unknown, b: unknown, c: unknown, d: unknown) {\n if (arguments.length >= 4) {\n return body.call(this, a, b, c, d)\n }\n return (self: unknown) => body(self, a, b, c)\n }\n case 5:\n return function (this: unknown, a: unknown, b: unknown, c: unknown, d: unknown, e: unknown) {\n if (arguments.length >= 5) {\n return body.call(this, a, b, c, d, e)\n }\n return (self: unknown) => body(self, a, b, c, d)\n }\n default:\n return function (this: unknown) {\n // oxlint-disable-next-line prefer-rest-params\n if (arguments.length >= arityOrIsDataFirst) {\n // oxlint-disable-next-line prefer-rest-params\n return body.apply(this, arguments)\n }\n const args = arguments\n return (self: unknown) => body(self, ...args)\n }\n }\n} as any\n/* oxlint-enable no-explicit-any, ban-types, no-unsafe-function-type, no-unsafe-assignment, no-unsafe-return, no-unsafe-call, no-unsafe-type-assertion */\n"],"mappings":"AAyCA,MAAa,EAST,SAAU,EAA8D,EAAgB,CAC1F,GAAI,OAAO,GAAuB,WAChC,OAAO,UAAyB,CAO9B,OALI,EAAmB,UAAU,CAExB,EAAK,MAAM,KAAM,UAAU,EAG3B,GAAkB,EAAK,EAAM,GAAG,UAAU,GAGvD,OAAQ,EAAR,CACE,IAAK,GACH,OAAO,EACT,IAAK,GACH,OAAO,SAAyB,EAAY,CAI1C,OAHI,UAAU,OAAS,EACd,EAAK,KAAK,KAAM,EAAE,CAEpB,EAAK,KAAK,KAAK,EAE1B,IAAK,GACH,OAAO,SAAyB,EAAY,EAAY,CAItD,OAHI,UAAU,QAAU,EACf,EAAK,KAAK,KAAM,EAAG,EAAE,CAEtB,GAAkB,EAAK,EAAM,EAAE,EAE3C,IAAK,GACH,OAAO,SAAyB,EAAY,EAAY,EAAY,CAIlE,OAHI,UAAU,QAAU,EACf,EAAK,KAAK,KAAM,EAAG,EAAG,EAAE,CAEzB,GAAkB,EAAK,EAAM,EAAG,EAAE,EAE9C,IAAK,GACH,OAAO,SAAyB,EAAY,EAAY,EAAY,EAAY,CAI9E,OAHI,UAAU,QAAU,EACf,EAAK,KAAK,KAAM,EAAG,EAAG,EAAG,EAAE,CAE5B,GAAkB,EAAK,EAAM,EAAG,EAAG,EAAE,EAEjD,IAAK,GACH,OAAO,SAAyB,EAAY,EAAY,EAAY,EAAY,EAAY,CAI1F,OAHI,UAAU,QAAU,EACf,EAAK,KAAK,KAAM,EAAG,EAAG,EAAG,EAAG,EAAE,CAE/B,GAAkB,EAAK,EAAM,EAAG,EAAG,EAAG,EAAE,EAEpD,QACE,OAAO,UAAyB,CAE9B,GAAI,UAAU,QAAU,EAEtB,OAAO,EAAK,MAAM,KAAM,UAAU,CAEpC,IAAM,EAAO,UACb,MAAQ,IAAkB,EAAK,EAAM,GAAG,EAAK"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"../duration-CYoDHcOR.mjs";export{e as Duration};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{t as e}from"./chunk-oQKkju2G.mjs";import{i as t,t as n}from"./result-D3VY0qBG.mjs";import{n as r}from"./brand-DZgGDrAe.mjs";import{t as i}from"./data-BHYPdqWZ.mjs";var a=e({DurationInvalidInputError:()=>c,DurationInvalidValueError:()=>s,DurationParseError:()=>o,days:()=>v,from:()=>C,hours:()=>_,millis:()=>m,minutes:()=>g,parse:()=>S,seconds:()=>h,toMillis:()=>b,weeks:()=>y}),o=class extends i(`DurationParseError`){},s=class extends i(`DurationInvalidValueError`){},c=class extends i(`DurationInvalidInputError`){};const l=/^\s*(-?\d+(?:\.\d+)?)\s+(milli|millis|second|seconds|minute|minutes|hour|hours|day|days|week|weeks)\s*$/i,u=e=>`Duration value must be a finite number, received: ${String(e)}`,d=e=>`Invalid duration input: ${String(e)}`,f=e=>`Invalid duration string: ${e}. Expected "{number} {milli|millis|second|seconds|minute|minutes|hour|hours|day|days|week|weeks}".`,p=e=>{if(!Number.isFinite(e))throw new s({input:e,message:u(e)});return r(e)},m=e=>p(e),h=e=>m(e*1e3),g=e=>m(e*6e4),_=e=>m(e*36e5),v=e=>m(e*864e5),y=e=>m(e*6048e5),b=e=>e,x=(e,t,n)=>{switch(n.toLowerCase()){case`milli`:case`millis`:return m(t);case`second`:case`seconds`:return h(t);case`minute`:case`minutes`:return g(t);case`hour`:case`hours`:return _(t);case`day`:case`days`:return v(t);case`week`:case`weeks`:return y(t);default:throw new o({input:e,message:f(e)})}},S=e=>{let r=l.exec(e);if(!r)return n(new o({input:e,message:f(e)}));let i=Number(r[1]),a=r[2];try{return t(x(e,i,a))}catch(t){if(t instanceof s||t instanceof o)return n(new o({input:e,message:f(e)}));throw t}},C=e=>{if(typeof e==`number`)try{return t(m(e))}catch(e){if(e instanceof s)return n(e);throw e}return typeof e==`string`?S(e):n(new c({input:e,message:d(e)}))};export{C as n,b as r,a as t};
|
|
2
|
+
//# sourceMappingURL=duration-CYoDHcOR.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration-CYoDHcOR.mjs","names":["Data.TaggedError","Brand.make","Result.err","Result.ok"],"sources":["../src/duration/duration.ts"],"sourcesContent":["/**\n * Fixed-size duration helpers backed by branded millisecond numbers.\n *\n * **Mental model**\n * - `Duration` is a finite JavaScript `number` interpreted as milliseconds.\n * - Use constructors for direct code and `parse` / `from` for ergonomic input handling.\n *\n * **Common tasks**\n * - Build durations with `Duration.seconds(5)` or `Duration.minutes(2)`.\n * - Parse config-like strings with `Duration.parse(\"5 minutes\")`.\n * - Normalize mixed inputs with `Duration.from(...)`.\n *\n * **Gotchas**\n * - Only fixed-size units are supported.\n * - Months, years, micros, and nanos are intentionally not supported.\n * - Invalid values use tagged errors instead of plain `RangeError`.\n *\n * @module\n */\n/* oxlint-disable eslint/max-classes-per-file -- TaggedError classes are part of the public API surface for this small module. */\nimport { Brand } from \"../brand\"\nimport type { Branded } from \"../brand/brand.types\"\nimport { Data } from \"../data\"\nimport { Result } from \"../result\"\n\n/**\n * Millisecond-backed branded duration type.\n */\nexport type Duration = Branded<number, \"Duration\">\n\n/**\n * Supported textual duration units.\n */\nexport type Unit =\n | \"milli\"\n | \"millis\"\n | \"second\"\n | \"seconds\"\n | \"minute\"\n | \"minutes\"\n | \"hour\"\n | \"hours\"\n | \"day\"\n | \"days\"\n | \"week\"\n | \"weeks\"\n\n/**\n * String input for durations.\n */\nexport type StringInput = `${number} ${Unit}`\n\n/**\n * Accepted duration input shapes.\n */\nexport type Input = Duration | number | StringInput\n\n/**\n * Tagged parse error for invalid duration strings.\n */\nexport class DurationParseError extends Data.TaggedError(\"DurationParseError\")<{\n input: string\n message: string\n}> {}\n\n/**\n * Tagged error for invalid numeric duration values.\n */\nexport class DurationInvalidValueError extends Data.TaggedError(\"DurationInvalidValueError\")<{\n input: number\n message: string\n}> {}\n\n/**\n * Tagged error for invalid duration input values outside supported shapes.\n */\nexport class DurationInvalidInputError extends Data.TaggedError(\"DurationInvalidInputError\")<{\n input: Input\n message: string\n cause?: DurationParseError | DurationInvalidValueError\n}> {}\n\n/**\n * Re-exported parse error type.\n */\nexport type ParseError = DurationParseError\n\n/**\n * Re-exported duration input error union.\n */\nexport type InputError = DurationInvalidInputError | DurationParseError | DurationInvalidValueError\n\nconst DURATION_REGEXP =\n /^\\s*(-?\\d+(?:\\.\\d+)?)\\s+(milli|millis|second|seconds|minute|minutes|hour|hours|day|days|week|weeks)\\s*$/i\n\nconst invalidValueMessage = (value: number) => `Duration value must be a finite number, received: ${String(value)}`\nconst invalidInputMessage = (input: Input) => `Invalid duration input: ${String(input)}`\nconst invalidStringMessage = (input: string) =>\n `Invalid duration string: ${input}. Expected \"{number} {milli|millis|second|seconds|minute|minutes|hour|hours|day|days|week|weeks}\".`\n\nconst validateFinite = (value: number): Duration => {\n if (!Number.isFinite(value)) {\n throw new DurationInvalidValueError({\n input: value,\n message: invalidValueMessage(value),\n })\n }\n\n return Brand.make<Branded<number, \"Duration\">>(value)\n}\n\n/**\n * Create a duration from milliseconds.\n */\nexport const millis = (value: number): Duration => validateFinite(value)\n\n/**\n * Create a duration from seconds.\n */\nexport const seconds = (value: number): Duration => millis(value * 1_000)\n\n/**\n * Create a duration from minutes.\n */\nexport const minutes = (value: number): Duration => millis(value * 60_000)\n\n/**\n * Create a duration from hours.\n */\nexport const hours = (value: number): Duration => millis(value * 3_600_000)\n\n/**\n * Create a duration from days.\n */\nexport const days = (value: number): Duration => millis(value * 86_400_000)\n\n/**\n * Create a duration from weeks.\n */\nexport const weeks = (value: number): Duration => millis(value * 604_800_000)\n\n/**\n * Convert a duration to raw milliseconds.\n */\nexport const toMillis = (duration: Duration): number => duration\n\nconst parseUnit = (input: string, value: number, unit: string): Duration => {\n switch (unit.toLowerCase()) {\n case \"milli\":\n case \"millis\":\n return millis(value)\n case \"second\":\n case \"seconds\":\n return seconds(value)\n case \"minute\":\n case \"minutes\":\n return minutes(value)\n case \"hour\":\n case \"hours\":\n return hours(value)\n case \"day\":\n case \"days\":\n return days(value)\n case \"week\":\n case \"weeks\":\n return weeks(value)\n default:\n throw new DurationParseError({\n input,\n message: invalidStringMessage(input),\n })\n }\n}\n\n/**\n * Parse a duration string.\n */\nexport const parse = (input: string): Result.Result<Duration, DurationParseError> => {\n const match = DURATION_REGEXP.exec(input)\n if (!match) {\n return Result.err(\n new DurationParseError({\n input,\n message: invalidStringMessage(input),\n }),\n )\n }\n\n const value = Number(match[1])\n const unit = match[2]!\n\n try {\n return Result.ok(parseUnit(input, value, unit))\n } catch (error) {\n if (error instanceof DurationInvalidValueError || error instanceof DurationParseError) {\n return Result.err(\n new DurationParseError({\n input,\n message: invalidStringMessage(input),\n }),\n )\n }\n throw error\n }\n}\n\n/**\n * Normalize supported duration inputs to a branded duration.\n */\nexport const from = (input: Input): Result.Result<Duration, InputError> => {\n if (typeof input === \"number\") {\n try {\n return Result.ok(millis(input))\n } catch (error) {\n if (error instanceof DurationInvalidValueError) {\n return Result.err(error)\n }\n throw error\n }\n }\n\n if (typeof input === \"string\") {\n return parse(input)\n }\n\n return Result.err(\n new DurationInvalidInputError({\n input,\n message: invalidInputMessage(input),\n }),\n )\n}\n"],"mappings":"iYA4Da,EAAb,cAAwCA,EAAiB,qBAAqB,AAG3E,GAKU,EAAb,cAA+CA,EAAiB,4BAA4B,AAGzF,GAKU,EAAb,cAA+CA,EAAiB,4BAA4B,AAIzF,GAYH,MAAM,EACJ,2GAEI,EAAuB,GAAkB,qDAAqD,OAAO,EAAM,GAC3G,EAAuB,GAAiB,2BAA2B,OAAO,EAAM,GAChF,EAAwB,GAC5B,4BAA4B,EAAM,oGAE9B,EAAkB,GAA4B,CAClD,GAAI,CAAC,OAAO,SAAS,EAAM,CACzB,MAAM,IAAI,EAA0B,CAClC,MAAO,EACP,QAAS,EAAoB,EAAM,CACpC,CAAC,CAGJ,OAAOC,EAAwC,EAAM,EAM1C,EAAU,GAA4B,EAAe,EAAM,CAK3D,EAAW,GAA4B,EAAO,EAAQ,IAAM,CAK5D,EAAW,GAA4B,EAAO,EAAQ,IAAO,CAK7D,EAAS,GAA4B,EAAO,EAAQ,KAAU,CAK9D,EAAQ,GAA4B,EAAO,EAAQ,MAAW,CAK9D,EAAS,GAA4B,EAAO,EAAQ,OAAY,CAKhE,EAAY,GAA+B,EAElD,GAAa,EAAe,EAAe,IAA2B,CAC1E,OAAQ,EAAK,aAAa,CAA1B,CACE,IAAK,QACL,IAAK,SACH,OAAO,EAAO,EAAM,CACtB,IAAK,SACL,IAAK,UACH,OAAO,EAAQ,EAAM,CACvB,IAAK,SACL,IAAK,UACH,OAAO,EAAQ,EAAM,CACvB,IAAK,OACL,IAAK,QACH,OAAO,EAAM,EAAM,CACrB,IAAK,MACL,IAAK,OACH,OAAO,EAAK,EAAM,CACpB,IAAK,OACL,IAAK,QACH,OAAO,EAAM,EAAM,CACrB,QACE,MAAM,IAAI,EAAmB,CAC3B,QACA,QAAS,EAAqB,EAAM,CACrC,CAAC,GAOK,EAAS,GAA+D,CACnF,IAAM,EAAQ,EAAgB,KAAK,EAAM,CACzC,GAAI,CAAC,EACH,OAAOC,EACL,IAAI,EAAmB,CACrB,QACA,QAAS,EAAqB,EAAM,CACrC,CAAC,CACH,CAGH,IAAM,EAAQ,OAAO,EAAM,GAAG,CACxB,EAAO,EAAM,GAEnB,GAAI,CACF,OAAOC,EAAU,EAAU,EAAO,EAAO,EAAK,CAAC,OACxC,EAAO,CACd,GAAI,aAAiB,GAA6B,aAAiB,EACjE,OAAOD,EACL,IAAI,EAAmB,CACrB,QACA,QAAS,EAAqB,EAAM,CACrC,CAAC,CACH,CAEH,MAAM,IAOG,EAAQ,GAAsD,CACzE,GAAI,OAAO,GAAU,SACnB,GAAI,CACF,OAAOC,EAAU,EAAO,EAAM,CAAC,OACxB,EAAO,CACd,GAAI,aAAiB,EACnB,OAAOD,EAAW,EAAM,CAE1B,MAAM,EAQV,OAJI,OAAO,GAAU,SACZ,EAAM,EAAM,CAGdA,EACL,IAAI,EAA0B,CAC5B,QACA,QAAS,EAAoB,EAAM,CACpC,CAAC,CACH"}
|
package/dist/either/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as either_d_exports } from "../index-
|
|
1
|
+
import { t as either_d_exports } from "../index-dCRymj_g.mjs";
|
|
2
2
|
export { either_d_exports as Either };
|
package/dist/either/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"../either-
|
|
1
|
+
import{t as e}from"../either-G7uOu4Ar.mjs";export{e as Either};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=either-
|
|
1
|
+
import{t as e}from"./chunk-oQKkju2G.mjs";import{t}from"./fx.types-DyQVgTS8.mjs";import{t as n}from"./dual-fN6OUwN_.mjs";import{n as r}from"./flow-CNyLsPGb.mjs";import{t as i}from"./pipeable-Dp1_23zH.mjs";import{i as a,t as o}from"./result-D3VY0qBG.mjs";import{i as s,n as c}from"./option-C2iCxAuJ.mjs";var l=e({all:()=>C,bimap:()=>g,filter:()=>S,flatMap:()=>_,fromNullable:()=>j,fromOption:()=>k,fromPredicate:()=>M,fromResult:()=>D,isLeft:()=>p,isRight:()=>f,left:()=>d,map:()=>m,mapLeft:()=>h,match:()=>E,orElse:()=>b,right:()=>u,swap:()=>x,tap:()=>v,tapLeft:()=>y,toOption:()=>A,toResult:()=>O,unwrapOr:()=>w,unwrapOrElse:()=>T});const u=e=>({_tag:`Right`,value:e,[t]:{_A:()=>e,_E:()=>void 0,_R:()=>void 0},pipe:i,*[Symbol.iterator](){return e}}),d=e=>({_tag:`Left`,value:e,[t]:{_A:()=>e,_E:()=>void 0,_R:()=>void 0},pipe:i,*[Symbol.iterator](){return e}}),f=e=>e._tag===`Right`,p=e=>e._tag===`Left`,m=n(2,(e,t)=>{if(e._tag===`Left`)return e;let n=t(e.value);return r(n)?Promise.resolve(n).then(u):u(n)}),h=n(2,(e,t)=>{if(e._tag===`Right`)return e;let n=t(e.value);return r(n)?Promise.resolve(n).then(d):d(n)}),g=n(3,(e,t,n)=>{if(e._tag===`Right`){let t=n(e.value);return r(t)?Promise.resolve(t).then(u):u(t)}let i=t(e.value);return r(i)?Promise.resolve(i).then(d):d(i)}),_=n(2,(e,t)=>e._tag===`Left`?e:t(e.value)),v=n(2,(e,t)=>{if(e._tag===`Left`)return e;let n=t(e.value);return r(n)?Promise.resolve(n).then(()=>e):e}),y=n(2,(e,t)=>{if(e._tag===`Right`)return e;let n=t(e.value);return r(n)?Promise.resolve(n).then(()=>e):e}),b=n(2,(e,t)=>e._tag===`Right`?e:t(e.value)),x=()=>e=>e._tag===`Left`?u(e.value):d(e.value),S=n(3,(e,t,n)=>e._tag===`Left`||t(e.value)?e:d(n(e.value))),C=e=>{if(Array.isArray(e)){let t=[];for(let n of e){if(n._tag===`Left`)return n;t.push(n.value)}return u(t)}let t={};for(let n in e){let r=e[n];if(r._tag===`Left`)return r;t[n]=r.value}return u(t)},w=n(2,(e,t)=>e._tag===`Right`?e.value:t),T=n(2,(e,t)=>e._tag===`Right`?e.value:t(e.value)),E=n(2,(e,t)=>e._tag===`Right`?t.Right(e.value):t.Left(e.value)),D=e=>e._tag===`Ok`?u(e.value):d(e.error),O=e=>e._tag===`Right`?a(e.value):o(e.value),k=(e,t)=>e._tag===`Some`?u(e.value):d(t()),A=e=>e._tag===`Right`?s(e.value):c(),j=(e,t)=>e==null?d(t()):u(e),M=(e,t,n)=>t(e)?u(e):d(n(e));export{l as t};
|
|
2
|
+
//# sourceMappingURL=either-G7uOu4Ar.mjs.map
|