@sveltejs/kit 1.0.0-next.440 → 1.0.0-next.443
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.
- package/package.json +1 -1
- package/src/core/sync/create_manifest_data/index.js +18 -16
- package/src/core/sync/write_root.js +1 -1
- package/src/core/sync/write_types/index.js +28 -9
- package/src/core/sync/write_types/test/layout-advanced/_expected/(main)/sub/$types.d.ts +5 -4
- package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/_expected/nested/[...rest]/$types.d.ts +5 -4
- package/src/runtime/client/client.js +5 -2
- package/src/runtime/server/index.js +5 -2
- package/types/internal.d.ts +3 -0
package/package.json
CHANGED
|
@@ -109,23 +109,25 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
109
109
|
|
|
110
110
|
segment_map.set(
|
|
111
111
|
id,
|
|
112
|
-
segments
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
112
|
+
segments
|
|
113
|
+
.filter((segment) => segment !== '' && affects_path(segment))
|
|
114
|
+
.map((segment) => {
|
|
115
|
+
/** @type {import('./types').Part[]} */
|
|
116
|
+
const parts = [];
|
|
117
|
+
segment.split(/\[(.+?)\]/).map((content, i) => {
|
|
118
|
+
const dynamic = !!(i % 2);
|
|
119
|
+
|
|
120
|
+
if (!content) return;
|
|
121
|
+
|
|
122
|
+
parts.push({
|
|
123
|
+
content,
|
|
124
|
+
dynamic,
|
|
125
|
+
rest: dynamic && content.startsWith('...'),
|
|
126
|
+
type: (dynamic && content.split('=')[1]) || null
|
|
127
|
+
});
|
|
125
128
|
});
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
})
|
|
129
|
+
return parts;
|
|
130
|
+
})
|
|
129
131
|
);
|
|
130
132
|
|
|
131
133
|
/** @type {import('types').RouteData} */
|
|
@@ -26,7 +26,7 @@ export function write_root(manifest_data, output) {
|
|
|
26
26
|
while (l--) {
|
|
27
27
|
pyramid = `
|
|
28
28
|
{#if components[${l + 1}]}
|
|
29
|
-
<svelte:component this={components[${l}]} data={data_${l}}>
|
|
29
|
+
<svelte:component this={components[${l}]} data={data_${l}} {errors}>
|
|
30
30
|
${pyramid.replace(/\n/g, '\n\t\t\t\t\t')}
|
|
31
31
|
</svelte:component>
|
|
32
32
|
{:else}
|
|
@@ -167,15 +167,20 @@ function update_types(config, routes, route) {
|
|
|
167
167
|
`type RouteParams = { ${route.names.map((param) => `${param}: string`).join('; ')} }`
|
|
168
168
|
);
|
|
169
169
|
|
|
170
|
+
// These could also be placed in our public types, but it would bloat them unnecessarily and we may want to change these in the future
|
|
170
171
|
if (route.layout || route.leaf) {
|
|
171
|
-
//
|
|
172
|
+
// If T extends the empty object, void is also allowed as a return type
|
|
172
173
|
declarations.push(`type MaybeWithVoid<T> = {} extends T ? T | void : T;`);
|
|
174
|
+
// Returns the key of the object whose values are required.
|
|
173
175
|
declarations.push(
|
|
174
176
|
`export type RequiredKeys<T> = { [K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K; }[keyof T];`
|
|
175
177
|
);
|
|
178
|
+
// Helper type to get the correct output type for load functions. It should be passed the parent type to check what types from App.PageData are still required.
|
|
179
|
+
// If none, void is also allowed as a return type.
|
|
176
180
|
declarations.push(
|
|
177
181
|
`type OutputDataShape<T> = MaybeWithVoid<Omit<App.PageData, RequiredKeys<T>> & Partial<Pick<App.PageData, keyof T & keyof App.PageData>> & Record<string, any>>`
|
|
178
182
|
);
|
|
183
|
+
// null & {} == null, we need to prevent that in some situations
|
|
179
184
|
declarations.push(`type EnsureParentData<T> = NonNullable<T> extends never ? {} : T;`);
|
|
180
185
|
}
|
|
181
186
|
|
|
@@ -277,9 +282,7 @@ function process_node(node, outdir, is_page, all_pages_have_load = true) {
|
|
|
277
282
|
|
|
278
283
|
const parent_type = `${prefix}ServerParentData`;
|
|
279
284
|
|
|
280
|
-
declarations.push(
|
|
281
|
-
`type ${parent_type} = EnsureParentData<${get_parent_type(node, 'LayoutServerData')}>;`
|
|
282
|
-
);
|
|
285
|
+
declarations.push(`type ${parent_type} = ${get_parent_type(node, 'LayoutServerData')};`);
|
|
283
286
|
|
|
284
287
|
// +page.js load present -> server can return all-optional data
|
|
285
288
|
const output_data_shape =
|
|
@@ -317,9 +320,7 @@ function process_node(node, outdir, is_page, all_pages_have_load = true) {
|
|
|
317
320
|
exports.push(`export type ${prefix}ServerData = ${server_data};`);
|
|
318
321
|
|
|
319
322
|
const parent_type = `${prefix}ParentData`;
|
|
320
|
-
declarations.push(
|
|
321
|
-
`type ${parent_type} = EnsureParentData<${get_parent_type(node, 'LayoutData')}>;`
|
|
322
|
-
);
|
|
323
|
+
declarations.push(`type ${parent_type} = ${get_parent_type(node, 'LayoutData')};`);
|
|
323
324
|
|
|
324
325
|
if (node.shared) {
|
|
325
326
|
const content = fs.readFileSync(node.shared, 'utf8');
|
|
@@ -394,12 +395,14 @@ function get_parent_type(node, type) {
|
|
|
394
395
|
parent = parent.parent;
|
|
395
396
|
}
|
|
396
397
|
|
|
397
|
-
let parent_str = parent_imports[0] || '{}'
|
|
398
|
+
let parent_str = `EnsureParentData<${parent_imports[0] || '{}'}>`;
|
|
398
399
|
for (let i = 1; i < parent_imports.length; i++) {
|
|
399
400
|
// Omit is necessary because a parent could have a property with the same key which would
|
|
400
401
|
// cause a type conflict. At runtime the child overwrites the parent property in this case,
|
|
401
402
|
// so reflect that in the type definition.
|
|
402
|
-
|
|
403
|
+
// EnsureParentData is necessary because {something: string} & null becomes null.
|
|
404
|
+
// Output types of server loads can be null but when passed in through the `parent` parameter they are the empty object instead.
|
|
405
|
+
parent_str = `Omit<${parent_str}, keyof ${parent_imports[i]}> & EnsureParentData<${parent_imports[i]}>`;
|
|
403
406
|
}
|
|
404
407
|
return parent_str;
|
|
405
408
|
}
|
|
@@ -556,7 +559,13 @@ export function tweak_types(content, names) {
|
|
|
556
559
|
arg.name.end,
|
|
557
560
|
`: Parameters<${type}>[0]` + (add_parens ? ')' : '')
|
|
558
561
|
);
|
|
562
|
+
} else {
|
|
563
|
+
// prevent "type X is imported but not used" (isn't silenced by @ts-nocheck) when svelte-check runs
|
|
564
|
+
code.append(`;${type};`);
|
|
559
565
|
}
|
|
566
|
+
} else {
|
|
567
|
+
// prevent "type X is imported but not used" (isn't silenced by @ts-nocheck) when svelte-check runs
|
|
568
|
+
code.append(`;${type};`);
|
|
560
569
|
}
|
|
561
570
|
|
|
562
571
|
modified = true;
|
|
@@ -566,6 +575,16 @@ export function tweak_types(content, names) {
|
|
|
566
575
|
}
|
|
567
576
|
});
|
|
568
577
|
|
|
578
|
+
if (modified) {
|
|
579
|
+
// Ignore all type errors so they don't show up twice when svelte-check runs
|
|
580
|
+
// Account for possible @ts-check which would overwrite @ts-nocheck
|
|
581
|
+
if (code.original.startsWith('// @ts-check')) {
|
|
582
|
+
code.prependLeft('// @ts-check'.length, '\n// @ts-nocheck\n');
|
|
583
|
+
} else {
|
|
584
|
+
code.prepend('// @ts-nocheck\n');
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
569
588
|
return {
|
|
570
589
|
modified,
|
|
571
590
|
code: code.toString(),
|
|
@@ -11,10 +11,11 @@ type OutputDataShape<T> = MaybeWithVoid<
|
|
|
11
11
|
Record<string, any>
|
|
12
12
|
>;
|
|
13
13
|
type EnsureParentData<T> = NonNullable<T> extends never ? {} : T;
|
|
14
|
-
type PageParentData =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
type PageParentData = Omit<
|
|
15
|
+
EnsureParentData<import('../../$types.js').LayoutData>,
|
|
16
|
+
keyof import('../$types.js').LayoutData
|
|
17
|
+
> &
|
|
18
|
+
EnsureParentData<import('../$types.js').LayoutData>;
|
|
18
19
|
|
|
19
20
|
export type PageServerData = null;
|
|
20
21
|
export type PageLoad<
|
|
@@ -11,10 +11,11 @@ type OutputDataShape<T> = MaybeWithVoid<
|
|
|
11
11
|
Record<string, any>
|
|
12
12
|
>;
|
|
13
13
|
type EnsureParentData<T> = NonNullable<T> extends never ? {} : T;
|
|
14
|
-
type PageParentData =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
type PageParentData = Omit<
|
|
15
|
+
EnsureParentData<import('../../$types.js').LayoutData>,
|
|
16
|
+
keyof import('../$types.js').LayoutData
|
|
17
|
+
> &
|
|
18
|
+
EnsureParentData<import('../$types.js').LayoutData>;
|
|
18
19
|
|
|
19
20
|
export type PageServerData = null;
|
|
20
21
|
export type PageLoad<
|
|
@@ -638,9 +638,10 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
638
638
|
|
|
639
639
|
/**
|
|
640
640
|
* @param {import('types').ServerDataNode | import('types').ServerDataSkippedNode | null} node
|
|
641
|
+
* @param {import('./types').DataNode | null} [previous]
|
|
641
642
|
* @returns {import('./types').DataNode | null}
|
|
642
643
|
*/
|
|
643
|
-
function create_data_node(node) {
|
|
644
|
+
function create_data_node(node, previous) {
|
|
644
645
|
if (node?.type === 'data') {
|
|
645
646
|
return {
|
|
646
647
|
type: 'data',
|
|
@@ -652,6 +653,8 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
652
653
|
url: !!node.uses.url
|
|
653
654
|
}
|
|
654
655
|
};
|
|
656
|
+
} else if (node?.type === 'skip') {
|
|
657
|
+
return previous ?? null;
|
|
655
658
|
}
|
|
656
659
|
return null;
|
|
657
660
|
}
|
|
@@ -765,7 +768,7 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
765
768
|
}
|
|
766
769
|
return data;
|
|
767
770
|
},
|
|
768
|
-
server_data_node: create_data_node(server_data_node
|
|
771
|
+
server_data_node: create_data_node(server_data_node, previous?.server)
|
|
769
772
|
});
|
|
770
773
|
});
|
|
771
774
|
|
|
@@ -280,10 +280,13 @@ export async function respond(request, options, state) {
|
|
|
280
280
|
/** @type {Record<string, any>} */
|
|
281
281
|
const data = {};
|
|
282
282
|
for (let j = 0; j < i; j += 1) {
|
|
283
|
-
const parent = /** @type {import('types').ServerDataNode} */ (
|
|
283
|
+
const parent = /** @type {import('types').ServerDataNode | null} */ (
|
|
284
284
|
await functions[j]()
|
|
285
285
|
);
|
|
286
|
-
|
|
286
|
+
|
|
287
|
+
if (parent) {
|
|
288
|
+
Object.assign(data, parent.data);
|
|
289
|
+
}
|
|
287
290
|
}
|
|
288
291
|
return data;
|
|
289
292
|
}
|
package/types/internal.d.ts
CHANGED