Skip to content

Commit a8b96ac

Browse files
committed
clean up nomenclature
1 parent 13bb644 commit a8b96ac

File tree

4 files changed

+18
-24
lines changed

4 files changed

+18
-24
lines changed

packages/kit/src/runtime/app/server/remote/query.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/** @import { RemoteInfo, MaybePromise } from 'types' */
33
/** @import { StandardSchemaV1 } from '@standard-schema/spec' */
44
import { 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';
66
import { prerendering } from '__sveltekit/environment';
77
import { 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
*/
253253
function 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
*/
276277
function 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-
}

packages/kit/src/runtime/client/remote-functions/shared.svelte.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as devalue from 'devalue';
55
import { app, goto, query_map, remote_responses } from '../client.js';
66
import { HttpError, Redirect } from '@sveltejs/kit/internal';
77
import { tick } from 'svelte';
8-
import { create_remote_cache_key, stringify_remote_arg } from '../../shared.js';
8+
import { create_remote_key, stringify_remote_arg } from '../../shared.js';
99

1010
/**
1111
*
@@ -48,7 +48,7 @@ export async function remote_request(url) {
4848
export function create_remote_function(id, create) {
4949
return (/** @type {any} */ arg) => {
5050
const payload = stringify_remote_arg(arg, app.hooks.transport);
51-
const cache_key = create_remote_cache_key(id, payload);
51+
const cache_key = create_remote_key(id, payload);
5252
let entry = query_map.get(cache_key);
5353

5454
let tracking = true;

packages/kit/src/runtime/server/page/render.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { add_resolution_suffix } from '../../pathname.js';
1616
import { try_get_request_store, with_request_store } from '@sveltejs/kit/internal/server';
1717
import { text_encoder } from '../../utils.js';
1818
import { get_global_name } from '../utils.js';
19-
import { create_remote_cache_key } from '../../shared.js';
19+
import { create_remote_key } from '../../shared.js';
2020

2121
// TODO rename this function/module
2222

@@ -493,7 +493,7 @@ export async function render_response({
493493
if (!info.id) continue;
494494

495495
for (const key in cache) {
496-
remote[create_remote_cache_key(info.id, key)] = await cache[key];
496+
remote[create_remote_key(info.id, key)] = await cache[key];
497497
}
498498
}
499499

packages/kit/src/runtime/shared.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@ export function parse_remote_arg(string, transport) {
8888
* @param {string} id
8989
* @param {string} payload
9090
*/
91-
export function create_remote_cache_key(id, payload) {
91+
export function create_remote_key(id, payload) {
9292
return id + '/' + payload;
9393
}

0 commit comments

Comments
 (0)