@@ -114,15 +114,20 @@ export const uriRelativeToAbsolute = (input = '', base = '', extra = '') => {
114114 * @returns {object } The http response object
115115 */
116116export const setAtLocalsPodium = ( response = { } , property , value ) => {
117+ // @ts -expect-error We know response is an object
117118 if ( ! response . locals ) {
119+ // @ts -expect-error We know response is an object
118120 response . locals = { } ;
119121 }
120122
123+ // @ts -expect-error We know response is an object
121124 if ( ! response . locals . podium ) {
125+ // @ts -expect-error We know response is an object
122126 response . locals . podium = { } ;
123127 }
124128
125129 if ( isString ( property ) && property !== '' ) {
130+ // @ts -expect-error We know response is an object
126131 response . locals . podium [ property ] = value ;
127132 }
128133
@@ -133,20 +138,23 @@ export const setAtLocalsPodium = (response = {}, property, value) => {
133138 * Get the value from a property on .locals.podium on an HTTP response object.
134139 * Ensures that .locals.podium exists on the http response object.
135140 *
136- * @param {object } [response] An HTTP response object.
141+ * @param {unknown } [response] An HTTP response object.
137142 * @param {string } [property] Property for the value.
138143 * @returns {object | null } The property, or `null` if it does not exist.
139144 */
140145export const getFromLocalsPodium = ( response = { } , property ) => {
146+ // @ts -expect-error We know response is an object
141147 if ( ! response . locals ) {
142148 return null ;
143149 }
144150
151+ // @ts -expect-error We know response is an object
145152 if ( ! response . locals . podium ) {
146153 return null ;
147154 }
148155
149156 if ( isString ( property ) && property !== '' ) {
157+ // @ts -expect-error We know response is an object
150158 return response . locals . podium [ property ] ;
151159 }
152160
@@ -175,8 +183,8 @@ export const duplicateOnLocalsPodium = (
175183/**
176184 * Serialize a context object into an HTTP header object, calling the function if a context value is callable.
177185 *
178- * @param {object } [headers={}] An HTTP headers object the context will be copied to.
179- * @param {object } [context={}] A context object to copy from.
186+ * @param {Record<string, string> } [headers={}] An HTTP headers object the context will be copied to.
187+ * @param {Record<string, string | ((arg: unknown) => string)> } [context={}] A context object to copy from.
180188 * @param {unknown } [arg=""] An argument value passed on to the function if a context value is a function.
181189 * @returns {object } An object with deserialized context properties and values.
182190 *
@@ -193,14 +201,18 @@ export const duplicateOnLocalsPodium = (
193201 * ```
194202 */
195203export const serializeContext = ( headers = { } , context = { } , arg = '' ) => {
204+ /** @type {Record<string, string> } */
196205 const localHeaders = headers ;
197206 Object . keys ( context ) . forEach ( ( key ) => {
198207 if ( isString ( context [ key ] ) ) {
199- localHeaders [ key ] = context [ key ] ;
208+ localHeaders [ key ] = /** @type { string } */ ( context [ key ] ) ;
200209 }
201210
202211 if ( isFunction ( context [ key ] ) ) {
203- localHeaders [ key ] = context [ key ] ( arg ) ;
212+ const contextFn = /** @type {((arg: unknown) => string) } */ (
213+ context [ key ]
214+ ) ;
215+ localHeaders [ key ] = contextFn ( arg ) ;
204216 }
205217 } ) ;
206218 return localHeaders ;
@@ -209,7 +221,7 @@ export const serializeContext = (headers = {}, context = {}, arg = '') => {
209221/**
210222 * Deserialize a context object from an HTTP header object.
211223 *
212- * @param {object } [headers={}] An HTTP headers object the context will be extracted from.
224+ * @param {Record<string, string> } [headers={}] An HTTP headers object the context will be extracted from.
213225 * @param {string } [prefix="podium"] The prefix used to mark what properties are context properties.
214226 * @returns {object } An object with deserialized context properties and values.
215227 *
@@ -225,6 +237,7 @@ export const serializeContext = (headers = {}, context = {}, arg = '') => {
225237 * ```
226238 */
227239export const deserializeContext = ( headers = { } , prefix = 'podium' ) => {
240+ /** @type {Record<string, string> } */
228241 const context = { } ;
229242 Object . keys ( headers ) . forEach ( ( key ) => {
230243 if ( key . startsWith ( prefix ) ) {
0 commit comments