22/** @import { RemoteInfo, MaybePromise } from 'types' */
33/** @import { StandardSchemaV1 } from '@standard-schema/spec' */
44import { get_request_store } from '@sveltejs/kit/internal/server' ;
5- import { create_remote_cache_key , stringify_remote_arg } from '../../../shared.js' ;
5+ import { create_remote_key , stringify_remote_arg } from '../../../shared.js' ;
66import { prerendering } from '__sveltekit/environment' ;
77import { create_validator , get_cache , get_response , run_remote_function } from './shared.js' ;
88
@@ -84,7 +84,7 @@ export function query(validate_or_fn, maybe_fn) {
8484
8585 promise . refresh = ( ) => {
8686 const refresh_context = get_refresh_context ( __ , 'refresh' , arg ) ;
87- const is_immediate_refresh = ! refresh_context . cache [ refresh_context . key ] ;
87+ const is_immediate_refresh = ! refresh_context . cache [ refresh_context . cache_key ] ;
8888 const value = is_immediate_refresh ? promise : get_remote_function_result ( ) ;
8989 return update_refresh_value ( refresh_context , value , is_immediate_refresh ) ;
9090 } ;
@@ -224,7 +224,7 @@ function batch(validate_or_fn, maybe_fn) {
224224
225225 promise . refresh = ( ) => {
226226 const refresh_context = get_refresh_context ( __ , 'refresh' , arg ) ;
227- const is_immediate_refresh = ! refresh_context . cache [ refresh_context . key ] ;
227+ const is_immediate_refresh = ! refresh_context . cache [ refresh_context . cache_key ] ;
228228 const value = is_immediate_refresh ? promise : get_remote_function_result ( ) ;
229229 return update_refresh_value ( refresh_context , value , is_immediate_refresh ) ;
230230 } ;
@@ -248,52 +248,46 @@ Object.defineProperty(query, 'batch', { value: batch, enumerable: true });
248248 * @param {RemoteInfo } __
249249 * @param {'set' | 'refresh' } action
250250 * @param {any } [arg]
251- * @returns {{ __: RemoteInfo; state: any; refreshes: Record<string, Promise<any>>; cache: Record<string, Promise<any>>; cache_key : string; key : string } }
251+ * @returns {{ __: RemoteInfo; state: any; refreshes: Record<string, Promise<any>>; cache: Record<string, Promise<any>>; refreshes_key : string; cache_key : string } }
252252 */
253253function get_refresh_context ( __ , action , arg ) {
254254 const { state } = get_request_store ( ) ;
255255 const { refreshes } = state ;
256256
257257 if ( ! refreshes ) {
258+ const name = __ . type === 'query_batch' ? `query.batch '${ __ . name } '` : `query '${ __ . name } '` ;
258259 throw new Error (
259- `Cannot call ${ action } on ${ format_remote_name ( __ ) } because it is not executed in the context of a command/form remote function`
260+ `Cannot call ${ action } on ${ name } because it is not executed in the context of a command/form remote function`
260261 ) ;
261262 }
262263
263- const key = stringify_remote_arg ( arg , state . transport ) ;
264- const cache_key = create_remote_cache_key ( __ . id , key ) ;
265264 const cache = get_cache ( __ , state ) ;
265+ const cache_key = stringify_remote_arg ( arg , state . transport ) ;
266+ const refreshes_key = create_remote_key ( __ . id , cache_key ) ;
266267
267- return { __ , state, refreshes, cache , cache_key , key } ;
268+ return { __ , state, refreshes, refreshes_key , cache , cache_key } ;
268269}
269270
270271/**
271- * @param {{ __: RemoteInfo; refreshes: Record<string, Promise<any>>; cache: Record<string, Promise<any>>; cache_key : string; key : string } } context
272+ * @param {{ __: RemoteInfo; refreshes: Record<string, Promise<any>>; cache: Record<string, Promise<any>>; refreshes_key : string; cache_key : string } } context
272273 * @param {any } value
273274 * @param {boolean } [is_immediate_refresh=false]
274275 * @returns {Promise<void> }
275276 */
276277function update_refresh_value (
277- { __ , refreshes, cache , cache_key , key } ,
278+ { __ , refreshes, refreshes_key , cache , cache_key } ,
278279 value ,
279280 is_immediate_refresh = false
280281) {
281282 const promise = Promise . resolve ( value ) ;
282283
283284 if ( ! is_immediate_refresh ) {
284- cache [ key ] = promise ;
285+ cache [ cache_key ] = promise ;
285286 }
286287
287288 if ( __ . id ) {
288- refreshes [ cache_key ] = promise ;
289+ refreshes [ refreshes_key ] = promise ;
289290 }
290291
291292 return promise . then ( ( ) => { } ) ;
292293}
293-
294- /**
295- * @param {RemoteInfo } __
296- */
297- function format_remote_name ( __ ) {
298- return __ . type === 'query_batch' ? `query.batch '${ __ . name } '` : `query '${ __ . name } '` ;
299- }
0 commit comments