MCPcopy
hub / github.com/sveltejs/kit / wrapper

Function wrapper

packages/kit/src/runtime/app/server/remote/query.js:74–110  ·  view source on GitHub ↗
(arg)

Source from the content-addressed store, hash-verified

72
73 /** @type {RemoteQueryFunction<Input, Output> & { __: RemoteInfo }} */
74 const wrapper = (arg) => {
75 if (prerendering) {
76 throw new Error(
77 `Cannot call query '${__.name}' while prerendering, as prerendered pages need static data. Use 'prerender' from $app/server instead`
78 );
79 }
80
81 const event = getRequestEvent();
82
83 /** @type {Promise<any> & Partial<RemoteQuery<any>>} */
84 const promise = get_response(__.id, arg, event, () =>
85 run_remote_function(event, false, arg, validate, fn)
86 );
87
88 promise.catch(() => {});
89
90 promise.refresh = async () => {
91 const event = getRequestEvent();
92 const state = get_event_state(event);
93 const refreshes = state?.refreshes;
94
95 if (!refreshes) {
96 throw new Error(
97 `Cannot call refresh on query '${__.name}' because it is not executed in the context of a command/form remote function`
98 );
99 }
100
101 const cache_key = create_remote_cache_key(__.id, stringify_remote_arg(arg, state.transport));
102 refreshes[cache_key] = await /** @type {Promise<any>} */ (promise);
103 };
104
105 promise.withOverride = () => {
106 throw new Error(`Cannot call '${__.name}.withOverride()' on the server`);
107 };
108
109 return /** @type {RemoteQuery<Output>} */ (promise);
110 };
111
112 Object.defineProperty(wrapper, '__', { value: __ });
113

Callers

nothing calls this directly

Calls 7

getRequestEventFunction · 0.90
get_responseFunction · 0.90
run_remote_functionFunction · 0.90
get_event_stateFunction · 0.90
create_remote_cache_keyFunction · 0.90
stringify_remote_argFunction · 0.90
catchMethod · 0.45

Tested by

no test coverage detected