@sveltejs/kit 1.7.2 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,8 @@
1
- import * as devalue from 'devalue';
2
1
  import { json, text } from '../../exports/index.js';
3
2
  import { coalesce_to_error } from '../../utils/error.js';
4
3
  import { negotiate } from '../../utils/http.js';
5
4
  import { HttpError } from '../control.js';
6
- import { fix_stack_trace } from '../shared.js';
5
+ import { fix_stack_trace } from '../shared-server.js';
7
6
 
8
7
  /** @param {any} body */
9
8
  export function is_pojo(body) {
@@ -99,7 +98,7 @@ export async function handle_error_and_jsonify(event, options, error) {
99
98
  if (error instanceof HttpError) {
100
99
  return error.body;
101
100
  } else {
102
- if (__SVELTEKIT_DEV__) {
101
+ if (__SVELTEKIT_DEV__ && typeof error == 'object') {
103
102
  error = new Proxy(error, {
104
103
  get: (target, property) => {
105
104
  if (property === 'stack') {
@@ -148,31 +147,23 @@ export function clarify_devalue_error(event, error) {
148
147
  return error.message;
149
148
  }
150
149
 
151
- /** @param {import('types').ServerDataNode | import('types').ServerDataSkippedNode | import('types').ServerErrorNode | null} node */
152
- export function serialize_data_node(node) {
153
- if (!node) return 'null';
154
-
155
- if (node.type === 'error' || node.type === 'skip') {
156
- return JSON.stringify(node);
157
- }
158
-
159
- const stringified = devalue.stringify(node.data);
160
-
150
+ /**
151
+ * @param {import('types').ServerDataNode} node
152
+ */
153
+ export function stringify_uses(node) {
161
154
  const uses = [];
162
155
 
163
- if (node.uses.dependencies.size > 0) {
156
+ if (node.uses && node.uses.dependencies.size > 0) {
164
157
  uses.push(`"dependencies":${JSON.stringify(Array.from(node.uses.dependencies))}`);
165
158
  }
166
159
 
167
- if (node.uses.params.size > 0) {
160
+ if (node.uses && node.uses.params.size > 0) {
168
161
  uses.push(`"params":${JSON.stringify(Array.from(node.uses.params))}`);
169
162
  }
170
163
 
171
- if (node.uses.parent) uses.push(`"parent":1`);
172
- if (node.uses.route) uses.push(`"route":1`);
173
- if (node.uses.url) uses.push(`"url":1`);
164
+ if (node.uses?.parent) uses.push(`"parent":1`);
165
+ if (node.uses?.route) uses.push(`"route":1`);
166
+ if (node.uses?.url) uses.push(`"url":1`);
174
167
 
175
- return `{"type":"data","data":${stringified},"uses":{${uses.join(',')}}${
176
- node.slash ? `,"slash":${JSON.stringify(node.slash)}` : ''
177
- }}`;
168
+ return `"uses":{${uses.join(',')}}`;
178
169
  }
@@ -1,8 +1,5 @@
1
1
  export { set_assets } from '__sveltekit/paths';
2
2
 
3
- export let building = false;
4
- export let version = '';
5
-
6
3
  /** @type {Record<string, string>} */
7
4
  export let private_env = {};
8
5
 
@@ -12,11 +9,6 @@ export let public_env = {};
12
9
  /** @param {string} stack */
13
10
  export let fix_stack_trace = (stack) => stack;
14
11
 
15
- /** @param {boolean} value */
16
- export function set_building(value) {
17
- building = value;
18
- }
19
-
20
12
  /** @type {(environment: Record<string, string>) => void} */
21
13
  export function set_private_env(environment) {
22
14
  private_env = environment;
@@ -27,11 +19,6 @@ export function set_public_env(environment) {
27
19
  public_env = environment;
28
20
  }
29
21
 
30
- /** @param {string} value */
31
- export function set_version(value) {
32
- version = value;
33
- }
34
-
35
22
  /** @param {(stack: string) => string} value */
36
23
  export function set_fix_stack_trace(value) {
37
24
  fix_stack_trace = value;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @returns {import("types").Deferred & { promise: Promise<any> }}}
3
+ */
4
+ function defer() {
5
+ let fulfil;
6
+ let reject;
7
+
8
+ const promise = new Promise((f, r) => {
9
+ fulfil = f;
10
+ reject = r;
11
+ });
12
+
13
+ // @ts-expect-error
14
+ return { promise, fulfil, reject };
15
+ }
16
+
17
+ /**
18
+ * Create an async iterator and a function to push values into it
19
+ * @returns {{
20
+ * iterator: AsyncIterable<any>;
21
+ * push: (value: any) => void;
22
+ * done: () => void;
23
+ * }}
24
+ */
25
+ export function create_async_iterator() {
26
+ let deferred = defer();
27
+
28
+ return {
29
+ iterator: {
30
+ [Symbol.asyncIterator]() {
31
+ return {
32
+ next: () => deferred.promise
33
+ };
34
+ }
35
+ },
36
+ push: (value) => {
37
+ deferred.fulfil({ value, done: false });
38
+ deferred = defer();
39
+ },
40
+ done: () => {
41
+ deferred.fulfil({ done: true });
42
+ }
43
+ };
44
+ }
package/types/index.d.ts CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  RouteSegment,
19
19
  UniqueInterface
20
20
  } from './private.js';
21
- import { SSRNodeLoader, SSRRoute, ValidatedConfig } from './internal.js';
21
+ import { AssetDependencies, SSRNodeLoader, SSRRoute, ValidatedConfig } from './internal.js';
22
22
 
23
23
  export { PrerenderOption } from './private.js';
24
24
 
@@ -534,7 +534,7 @@ export interface KitConfig {
534
534
  *
535
535
  * beforeNavigate(({ willUnload, to }) => {
536
536
  * if ($updated && !willUnload && to?.url) {
537
- * location.href = to.route.url.href;
537
+ * location.href = to.url.href;
538
538
  * }
539
539
  * });
540
540
  * </script>
@@ -1008,11 +1008,9 @@ export interface SSRManifest {
1008
1008
 
1009
1009
  /** private fields */
1010
1010
  _: {
1011
- entry: {
1012
- file: string;
1013
- imports: string[];
1014
- stylesheets: string[];
1015
- fonts: string[];
1011
+ client: {
1012
+ start: AssetDependencies;
1013
+ app: AssetDependencies;
1016
1014
  };
1017
1015
  nodes: SSRNodeLoader[];
1018
1016
  routes: SSRRoute[];
@@ -42,16 +42,21 @@ export interface Asset {
42
42
  type: string | null;
43
43
  }
44
44
 
45
+ export interface AssetDependencies {
46
+ file: string;
47
+ imports: string[];
48
+ stylesheets: string[];
49
+ fonts: string[];
50
+ }
51
+
45
52
  export interface BuildData {
46
53
  app_dir: string;
47
54
  app_path: string;
48
55
  manifest_data: ManifestData;
49
56
  service_worker: string | null;
50
- client_entry: {
51
- file: string;
52
- imports: string[];
53
- stylesheets: string[];
54
- fonts: string[];
57
+ client: {
58
+ start: AssetDependencies;
59
+ app: AssetDependencies;
55
60
  } | null;
56
61
  server_manifest: import('vite').Manifest;
57
62
  }
@@ -78,6 +83,11 @@ export type CSRRoute = {
78
83
  leaf: [has_server_load: boolean, node_loader: CSRPageNodeLoader];
79
84
  };
80
85
 
86
+ export interface Deferred {
87
+ fulfil: (value: any) => void;
88
+ reject: (error: Error) => void;
89
+ }
90
+
81
91
  export type GetParams = (match: RegExpExecArray) => Record<string, string>;
82
92
 
83
93
  export interface ServerHooks {
@@ -90,6 +100,11 @@ export interface ClientHooks {
90
100
  handleError: HandleClientError;
91
101
  }
92
102
 
103
+ export interface Env {
104
+ private: Record<string, string>;
105
+ public: Record<string, string>;
106
+ }
107
+
93
108
  export class InternalServer extends Server {
94
109
  init(options: ServerInitOptions): Promise<void>;
95
110
  respond(
@@ -187,18 +202,20 @@ export interface RouteData {
187
202
  } | null;
188
203
  }
189
204
 
190
- export type ServerData =
191
- | {
192
- type: 'redirect';
193
- location: string;
194
- }
195
- | {
196
- type: 'data';
197
- /**
198
- * If `null`, then there was no load function
199
- */
200
- nodes: Array<ServerDataNode | ServerDataSkippedNode | ServerErrorNode | null>;
201
- };
205
+ export type ServerRedirectNode = {
206
+ type: 'redirect';
207
+ location: string;
208
+ };
209
+
210
+ export type ServerNodesResponse = {
211
+ type: 'data';
212
+ /**
213
+ * If `null`, then there was no load function <- TODO is this outdated now with the recent changes?
214
+ */
215
+ nodes: Array<ServerDataNode | ServerDataSkippedNode | ServerErrorNode | null>;
216
+ };
217
+
218
+ export type ServerDataResponse = ServerRedirectNode | ServerNodesResponse;
202
219
 
203
220
  /**
204
221
  * Signals a successful response of the server `load` function.
@@ -207,11 +224,25 @@ export type ServerData =
207
224
  */
208
225
  export interface ServerDataNode {
209
226
  type: 'data';
227
+ /**
228
+ * The serialized version of this contains a serialized representation of any deferred promises,
229
+ * which will be resolved later through chunk nodes.
230
+ */
210
231
  data: Record<string, any> | null;
211
232
  uses: Uses;
212
233
  slash?: TrailingSlash;
213
234
  }
214
235
 
236
+ /**
237
+ * Resolved data/error of a deferred promise.
238
+ */
239
+ export interface ServerDataChunkNode {
240
+ type: 'chunk';
241
+ id: number;
242
+ data?: Record<string, any>;
243
+ error?: any;
244
+ }
245
+
215
246
  /**
216
247
  * Signals that the server `load` function was not run, and the
217
248
  * client should use what it has in memory
@@ -318,6 +349,7 @@ export interface SSROptions {
318
349
  }): string;
319
350
  error(values: { message: string; status: number }): string;
320
351
  };
352
+ version_hash: string;
321
353
  }
322
354
 
323
355
  export interface SSRErrorPage {
@@ -1,30 +0,0 @@
1
- declare module '__CLIENT__/manifest.js' {
2
- import { CSRPageNodeLoader, ClientHooks, ParamMatcher } from 'types';
3
-
4
- /**
5
- * A list of all the error/layout/page nodes used in the app
6
- */
7
- export const nodes: CSRPageNodeLoader[];
8
-
9
- /**
10
- * A list of all layout node ids that have a server load function.
11
- * Pages are not present because it's shorter to encode it on the leaf itself.
12
- */
13
- export const server_loads: number[];
14
-
15
- /**
16
- * A map of `[routeId: string]: [leaf, layouts, errors]` tuples, which
17
- * is parsed into an array of routes on startup. The numbers refer to the indices in `nodes`.
18
- * If the leaf number is negative, it means it does use a server load function and the complement is the node index.
19
- * The route layout and error nodes are not referenced, they are always number 0 and 1 and always apply.
20
- */
21
- export const dictionary: Record<string, [leaf: number, layouts: number[], errors?: number[]]>;
22
-
23
- export const matchers: Record<string, ParamMatcher>;
24
-
25
- export const hooks: ClientHooks;
26
- }
27
-
28
- declare module '__GENERATED__/root.svelte' {
29
- export { SvelteComponent as default } from 'svelte';
30
- }