@@ -142,7 +142,7 @@ export class Cookie<T> implements ElysiaCookie {
142142 }
143143
144144 protected get setCookie ( ) {
145- if ( ! ( this . name in this . jar ) ) this . jar [ this . name ] = { ... this . initial }
145+ if ( ! ( this . name in this . jar ) ) this . jar [ this . name ] = this . initial
146146
147147 return this . jar [ this . name ]
148148 }
@@ -156,93 +156,55 @@ export class Cookie<T> implements ElysiaCookie {
156156 }
157157
158158 set value ( value : T ) {
159- // Check if value actually changed before creating entry in jar
160- const current = this . cookie . value
161-
162- // Simple equality check
163- if ( current === value ) return
164-
165- // For objects, do a deep equality check
166- if (
167- typeof current === 'object' &&
168- current !== null &&
169- typeof value === 'object' &&
170- value !== null
171- ) {
172- try {
173- if ( JSON . stringify ( current ) === JSON . stringify ( value ) ) return
174- } catch {
175- // If stringify fails, proceed with setting the value
176- }
177- }
178-
179- // Only create entry in jar if value actually changed
180- if ( ! ( this . name in this . jar ) ) this . jar [ this . name ] = { ...this . initial }
181- this . jar [ this . name ] . value = value
159+ this . setCookie . value = value ;
182160 }
183161
184162 get expires ( ) {
185163 return this . cookie . expires
186164 }
187165
188166 set expires ( expires : Date | undefined ) {
189- // Handle undefined values and compare timestamps instead of Date objects
190- const currentExpires = this . cookie . expires
191- if ( currentExpires === undefined && expires === undefined ) return
192- if ( currentExpires ?. getTime ( ) === expires ?. getTime ( ) ) return
193-
194- if ( ! ( this . name in this . jar ) ) this . jar [ this . name ] = { ...this . initial }
195- this . jar [ this . name ] . expires = expires
167+ this . setCookie . expires = expires
196168 }
197169
198170 get maxAge ( ) {
199171 return this . cookie . maxAge
200172 }
201173
202174 set maxAge ( maxAge : number | undefined ) {
203- if ( this . cookie . maxAge === maxAge ) return
204- if ( ! ( this . name in this . jar ) ) this . jar [ this . name ] = { ...this . initial }
205- this . jar [ this . name ] . maxAge = maxAge
175+ this . setCookie . maxAge = maxAge ;
206176 }
207177
208178 get domain ( ) {
209179 return this . cookie . domain
210180 }
211181
212182 set domain ( domain : string | undefined ) {
213- if ( this . cookie . domain === domain ) return
214- if ( ! ( this . name in this . jar ) ) this . jar [ this . name ] = { ...this . initial }
215- this . jar [ this . name ] . domain = domain
183+ this . setCookie . domain = domain ;
216184 }
217185
218186 get path ( ) {
219187 return this . cookie . path
220188 }
221189
222190 set path ( path : string | undefined ) {
223- if ( this . cookie . path === path ) return
224- if ( ! ( this . name in this . jar ) ) this . jar [ this . name ] = { ...this . initial }
225- this . jar [ this . name ] . path = path
191+ this . setCookie . path = path
226192 }
227193
228194 get secure ( ) {
229195 return this . cookie . secure
230196 }
231197
232198 set secure ( secure : boolean | undefined ) {
233- if ( this . cookie . secure === secure ) return
234- if ( ! ( this . name in this . jar ) ) this . jar [ this . name ] = { ...this . initial }
235- this . jar [ this . name ] . secure = secure
199+ this . setCookie . secure = secure
236200 }
237201
238202 get httpOnly ( ) {
239203 return this . cookie . httpOnly
240204 }
241205
242206 set httpOnly ( httpOnly : boolean | undefined ) {
243- if ( this . cookie . httpOnly === httpOnly ) return
244- if ( ! ( this . name in this . jar ) ) this . jar [ this . name ] = { ...this . initial }
245- this . jar [ this . name ] . httpOnly = httpOnly
207+ this . setCookie . httpOnly = httpOnly
246208 }
247209
248210 get sameSite ( ) {
@@ -252,39 +214,31 @@ export class Cookie<T> implements ElysiaCookie {
252214 set sameSite (
253215 sameSite : true | false | 'lax' | 'strict' | 'none' | undefined
254216 ) {
255- if ( this . cookie . sameSite === sameSite ) return
256- if ( ! ( this . name in this . jar ) ) this . jar [ this . name ] = { ...this . initial }
257- this . jar [ this . name ] . sameSite = sameSite
217+ this . setCookie . sameSite = sameSite
258218 }
259219
260220 get priority ( ) {
261221 return this . cookie . priority
262222 }
263223
264224 set priority ( priority : 'low' | 'medium' | 'high' | undefined ) {
265- if ( this . cookie . priority === priority ) return
266- if ( ! ( this . name in this . jar ) ) this . jar [ this . name ] = { ...this . initial }
267- this . jar [ this . name ] . priority = priority
225+ this . setCookie . priority = priority
268226 }
269227
270228 get partitioned ( ) {
271229 return this . cookie . partitioned
272230 }
273231
274232 set partitioned ( partitioned : boolean | undefined ) {
275- if ( this . cookie . partitioned === partitioned ) return
276- if ( ! ( this . name in this . jar ) ) this . jar [ this . name ] = { ...this . initial }
277- this . jar [ this . name ] . partitioned = partitioned
233+ this . setCookie . partitioned = partitioned
278234 }
279235
280236 get secrets ( ) {
281237 return this . cookie . secrets
282238 }
283239
284240 set secrets ( secrets : string | string [ ] | undefined ) {
285- if ( this . cookie . secrets === secrets ) return
286- if ( ! ( this . name in this . jar ) ) this . jar [ this . name ] = { ...this . initial }
287- this . jar [ this . name ] . secrets = secrets
241+ this . setCookie . secrets = secrets
288242 }
289243
290244 update ( config : Updater < Partial < ElysiaCookie > > ) {
0 commit comments