From cc18f68c218e4463c21bf83f06241f346c20c34a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Sun, 25 Aug 2024 00:30:35 +0200 Subject: [PATCH] TagWithDecodingDefault & KindWithDecodingDefault --- bun.lockb | Bin 70373 -> 70373 bytes package.json | 12 ++++++------ src/Schema/Kind.ts | 13 ++++++++++--- src/Schema/Tag.ts | 13 ++++++++++--- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/bun.lockb b/bun.lockb index 8243ed5b535be505f94702ca99229f7b23c031df..5ff5c9a648528a222a0007fb5dbe75919f55bb12 100755 GIT binary patch delta 538 zcmV+#0_FYXr3B@r1duKuUQ1bt_1*tfBkD))Z*?}VM{pP~D<~stfl-cDl}3z?u}$8?1*F_n#rlpWOmdPqswLekekGOJcTB z=H@^%#Vf%^w;As&x+X_()U|-x#J*}9sg#xG!H=`WgLnZzUh!?VOMy_m?Ba*n_~k_4_MmT! zEIe-|X(YUe?qyVuShrlrGmmb@RtN)NN#mH~OLHBjRUV`*4T@SVDtOe`vwelzIsq}0 zS->*^Hj|CO7y&htroc=CF)lEZ^}tI3II}^)h!p`fv&z=)0s%O)x!JZclcDS)w~-40 cp9BFlmoX3lIsrDfY!Crb0Rb_$zYzf@0n-HSEC2ui delta 542 zcmV+(0^$ATr3B@r1duKuq?eSx<*?A{2+A20m7v&MOIx+fO=*2A|17DSahsJ#u}|1!h^Sl8H*Y{v>2#~wu}avF$O^Xtb@RfS(p(NhST>} z5sg9+Tb1+BpaCgLFOPkzz#*DLC!RY_CbRWNxHUj1D4HaFTz+_eM=Z*SGh;RN;BcXG zLe6>7NA);g*v-E&JD#xl66rtlibYIz-|@0P`HN!#DLC%AsyUT*9;48+?R`K6K%Cnr z`Ak2bhQ}!%FyoR4xq*uc0qjDDV?^+N1bW`eR0;Fdw}`ht0{=pYziz(MzY!XEdwMeG z3e!7ccBV$rN0V)X7(h_b9AT^nSmki^W)O7fBPR6FcIG8L$tFa~sRpOyT9q?+t%7Co z5B!su1b&h;Dsp~9VEvmae@Z1ctIVw<;NP>wgLnZzuML1dUYlK~qfl@iQf{a7qLR)V z*$I$8If_D|m3~857d7s=l?|FjhN4Q76vm>s_CAG?#y2wj9)zDGKf5kWvwelzIsq_~ zS->*^G?R_M7y&esroc=CFfKNe^}tI3H?u*(h!p`ev&z=)0s%L(x!JZcmthS7BDawX g0iOhy@eKhWmrxJ^8v!)8Y!Crb0Rb?#zYzf@0V3q=5dZ)H diff --git a/package.json b/package.json index 9e53189..7600ee7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@thilawyn/thilalib", - "version": "0.1.13", + "version": "0.1.14", "type": "module", "files": [ "./dist" @@ -70,16 +70,16 @@ "type-fest": "^4.25.0" }, "devDependencies": { - "@effect/schema": "^0.71.0", + "@effect/schema": "^0.71.1", "@types/jsonwebtoken": "^9.0.6", - "bun-types": "^1.1.24", - "effect": "^3.6.4", + "bun-types": "^1.1.26", + "effect": "^3.6.5", "jsonwebtoken": "^9.0.2", "mobx": "^6.13.1", - "npm-check-updates": "^17.0.6", + "npm-check-updates": "^17.1.0", "npm-sort": "^0.0.4", "tsup": "^8.2.4", - "tsx": "^4.17.0", + "tsx": "^4.18.0", "typescript": "^5.5.4" } } diff --git a/src/Schema/Kind.ts b/src/Schema/Kind.ts index 5f4b88b..8f6e323 100644 --- a/src/Schema/Kind.ts +++ b/src/Schema/Kind.ts @@ -2,7 +2,14 @@ import { Schema } from "@effect/schema" export const Kind = (kind: Kind) => - Schema.withConstructorDefault( - Schema.propertySignature(Schema.Literal(kind)), - () => kind, + Schema.Literal(kind).pipe( + Schema.propertySignature, + Schema.withConstructorDefault(() => kind), + ) + +export const KindWithDecodingDefault = (kind: Kind) => + Schema.Literal(kind).pipe( + Schema.optional, + Schema.withConstructorDefault(() => kind), + Schema.withDecodingDefault(() => kind), ) diff --git a/src/Schema/Tag.ts b/src/Schema/Tag.ts index 2181b7a..0425ae5 100644 --- a/src/Schema/Tag.ts +++ b/src/Schema/Tag.ts @@ -2,7 +2,14 @@ import { Schema } from "@effect/schema" export const Tag = (tag: Tag) => - Schema.withConstructorDefault( - Schema.propertySignature(Schema.Literal(tag)), - () => tag, + Schema.Literal(tag).pipe( + Schema.propertySignature, + Schema.withConstructorDefault(() => tag), + ) + +export const TagWithDecodingDefault = (tag: Tag) => + Schema.Literal(tag).pipe( + Schema.optional, + Schema.withConstructorDefault(() => tag), + Schema.withDecodingDefault(() => tag), ) -- 2.49.1