@sveltejs/kit 1.0.0-next.438 → 1.0.0-next.440
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 +6 -3
- package/src/core/sync/sync.js +1 -1
- package/src/core/sync/write_client_manifest.js +2 -6
- package/src/core/sync/{write_types.js → write_types/index.js} +128 -98
- package/src/core/sync/write_types/test/layout/+layout.js +5 -0
- package/src/core/sync/write_types/test/layout/+layout.server.js +5 -0
- package/src/core/sync/write_types/test/layout/+layout.svelte +0 -0
- package/src/core/sync/write_types/test/layout/+page.js +5 -0
- package/src/core/sync/write_types/test/layout/+page.server.js +5 -0
- package/src/core/sync/write_types/test/layout/+page.svelte +0 -0
- package/src/core/sync/write_types/test/layout/_expected/$types.d.ts +67 -0
- package/src/core/sync/write_types/test/layout-advanced/(main)/+layout.server.js +5 -0
- package/src/core/sync/write_types/test/layout-advanced/(main)/+layout.svelte +0 -0
- package/src/core/sync/write_types/test/layout-advanced/(main)/+page.js +5 -0
- package/src/core/sync/write_types/test/layout-advanced/(main)/+page@.svelte +0 -0
- package/src/core/sync/write_types/test/layout-advanced/(main)/sub/+page.js +5 -0
- package/src/core/sync/write_types/test/layout-advanced/(main)/sub/+page.svelte +0 -0
- package/src/core/sync/write_types/test/layout-advanced/+layout.js +5 -0
- package/src/core/sync/write_types/test/layout-advanced/+layout.svelte +0 -0
- package/src/core/sync/write_types/test/layout-advanced/_expected/$types.d.ts +32 -0
- package/src/core/sync/write_types/test/layout-advanced/_expected/(main)/$types.d.ts +42 -0
- package/src/core/sync/write_types/test/layout-advanced/_expected/(main)/sub/$types.d.ts +32 -0
- package/src/core/sync/write_types/test/simple-page-server-and-shared/+page.js +5 -0
- package/src/core/sync/write_types/test/simple-page-server-and-shared/+page.server.js +5 -0
- package/src/core/sync/write_types/test/simple-page-server-and-shared/+page.svelte +0 -0
- package/src/core/sync/write_types/test/simple-page-server-and-shared/_expected/$types.d.ts +44 -0
- package/src/core/sync/write_types/test/simple-page-server-only/+page.server.js +5 -0
- package/src/core/sync/write_types/test/simple-page-server-only/+page.svelte +0 -0
- package/src/core/sync/write_types/test/simple-page-server-only/_expected/$types.d.ts +30 -0
- package/src/core/sync/write_types/test/simple-page-shared-only/+page.js +5 -0
- package/src/core/sync/write_types/test/simple-page-shared-only/+page.svelte +0 -0
- package/src/core/sync/write_types/test/simple-page-shared-only/_expected/$types.d.ts +33 -0
- package/src/core/sync/write_types/test/slugs/+layout.js +1 -0
- package/src/core/sync/write_types/test/slugs/+layout.svelte +1 -0
- package/src/core/sync/write_types/test/slugs/[...rest]/+page.js +3 -0
- package/src/core/sync/write_types/test/slugs/[...rest]/+page.svelte +0 -0
- package/src/core/sync/write_types/test/slugs/[slug]/+page.js +3 -0
- package/src/core/sync/write_types/test/slugs/[slug]/+page.svelte +0 -0
- package/src/core/sync/write_types/test/slugs/_expected/$types.d.ts +32 -0
- package/src/core/sync/write_types/test/slugs/_expected/[...rest]/$types.d.ts +29 -0
- package/src/core/sync/write_types/test/slugs/_expected/[slug]/$types.d.ts +29 -0
- package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/+layout.js +1 -0
- package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/+layout.svelte +1 -0
- package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/_expected/$types.d.ts +30 -0
- package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/_expected/nested/$types.d.ts +32 -0
- package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/_expected/nested/[...rest]/$types.d.ts +36 -0
- package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/_expected/nested/[slug]/$types.d.ts +17 -0
- package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/nested/+layout.js +1 -0
- package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/nested/+layout.svelte +1 -0
- package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/nested/[...rest]/+page.js +3 -0
- package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/nested/[...rest]/+page.svelte +0 -0
- package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/nested/[slug]/+page@.svelte +0 -0
- package/types/ambient.d.ts +9 -0
- package/types/index.d.ts +9 -7
- package/types/internal.d.ts +4 -0
package/package.json
CHANGED
|
@@ -180,7 +180,7 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
180
180
|
component: project_relative
|
|
181
181
|
};
|
|
182
182
|
} else if (item.is_layout) {
|
|
183
|
-
if (!route.layout) route.layout = { depth };
|
|
183
|
+
if (!route.layout) route.layout = { depth, child_pages: [] };
|
|
184
184
|
route.layout.component = project_relative;
|
|
185
185
|
if (item.uses_layout !== undefined) route.layout.parent_id = item.uses_layout;
|
|
186
186
|
} else {
|
|
@@ -189,7 +189,7 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
189
189
|
if (item.uses_layout !== undefined) route.leaf.parent_id = item.uses_layout;
|
|
190
190
|
}
|
|
191
191
|
} else if (item.is_layout) {
|
|
192
|
-
if (!route.layout) route.layout = { depth };
|
|
192
|
+
if (!route.layout) route.layout = { depth, child_pages: [] };
|
|
193
193
|
route.layout[item.kind] = project_relative;
|
|
194
194
|
} else if (item.is_page) {
|
|
195
195
|
if (!route.leaf) route.leaf = { depth };
|
|
@@ -223,7 +223,7 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
if (!root.layout?.component) {
|
|
226
|
-
if (!root.layout) root.layout = { depth: 0 };
|
|
226
|
+
if (!root.layout) root.layout = { depth: 0, child_pages: [] };
|
|
227
227
|
root.layout.component = posixify(path.relative(cwd, `${fallback}/layout.svelte`));
|
|
228
228
|
}
|
|
229
229
|
|
|
@@ -290,6 +290,9 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
290
290
|
}
|
|
291
291
|
|
|
292
292
|
if (current_route.layout) {
|
|
293
|
+
/** @type {import('types').PageNode[]} */ (current_route.layout.child_pages).push(
|
|
294
|
+
route.leaf
|
|
295
|
+
);
|
|
293
296
|
current_node.parent = current_node = current_route.layout;
|
|
294
297
|
parent_id = current_node.parent_id;
|
|
295
298
|
} else {
|
package/src/core/sync/sync.js
CHANGED
|
@@ -4,7 +4,7 @@ import { write_client_manifest } from './write_client_manifest.js';
|
|
|
4
4
|
import { write_matchers } from './write_matchers.js';
|
|
5
5
|
import { write_root } from './write_root.js';
|
|
6
6
|
import { write_tsconfig } from './write_tsconfig.js';
|
|
7
|
-
import { write_types, write_all_types } from './write_types.js';
|
|
7
|
+
import { write_types, write_all_types } from './write_types/index.js';
|
|
8
8
|
import { write_ambient } from './write_ambient.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -53,17 +53,13 @@ export function write_client_manifest(manifest_data, output) {
|
|
|
53
53
|
while (layouts.at(-1) === '') layouts.pop();
|
|
54
54
|
while (errors.at(-1) === '') errors.pop();
|
|
55
55
|
|
|
56
|
-
/** @type {import('types').RouteData | null} */
|
|
57
|
-
let current_route = route;
|
|
58
|
-
|
|
59
56
|
/** @type {import('types').PageNode | null} */
|
|
60
57
|
let current_node = route.leaf;
|
|
61
58
|
|
|
62
59
|
let uses_server_data = false;
|
|
63
|
-
while (
|
|
60
|
+
while (current_node && !uses_server_data) {
|
|
64
61
|
uses_server_data = !!current_node?.server;
|
|
65
|
-
|
|
66
|
-
current_node = current_route?.layout ?? null;
|
|
62
|
+
current_node = current_node?.parent ?? null;
|
|
67
63
|
}
|
|
68
64
|
|
|
69
65
|
// encode whether or not the route uses the server data
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import MagicString from 'magic-string';
|
|
4
|
-
import { posixify, rimraf, walk } from '
|
|
5
|
-
import { compact } from '
|
|
4
|
+
import { posixify, rimraf, walk } from '../../../utils/filesystem.js';
|
|
5
|
+
import { compact } from '../../../utils/array.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @typedef {{
|
|
@@ -49,9 +49,10 @@ export async function write_all_types(config, manifest_data) {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
const routes_map = create_routes_map(manifest_data);
|
|
52
53
|
// For each directory, write $types.d.ts
|
|
53
54
|
for (const route of manifest_data.routes) {
|
|
54
|
-
update_types(config,
|
|
55
|
+
update_types(config, routes_map, route);
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
|
|
@@ -76,16 +77,33 @@ export async function write_types(config, manifest_data, file) {
|
|
|
76
77
|
const route = manifest_data.routes.find((route) => route.id === id);
|
|
77
78
|
if (!route) return; // this shouldn't ever happen
|
|
78
79
|
|
|
79
|
-
update_types(config, manifest_data, route);
|
|
80
|
+
update_types(config, create_routes_map(manifest_data), route);
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
/**
|
|
83
|
-
*
|
|
84
|
-
* @param {import('types').ValidatedConfig} config
|
|
84
|
+
* Collect all leafs into a leaf -> route map
|
|
85
85
|
* @param {import('types').ManifestData} manifest_data
|
|
86
|
+
*/
|
|
87
|
+
function create_routes_map(manifest_data) {
|
|
88
|
+
/** @type {Map<import('types').PageNode, import('types').RouteData>} */
|
|
89
|
+
const map = new Map();
|
|
90
|
+
for (const route of manifest_data.routes) {
|
|
91
|
+
if (route.leaf) {
|
|
92
|
+
map.set(route.leaf, route);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return map;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Update types for a specific route
|
|
100
|
+
* @param {import('types').ValidatedConfig} config
|
|
101
|
+
* @param {Map<import('types').PageNode, import('types').RouteData>} routes
|
|
86
102
|
* @param {import('types').RouteData} route
|
|
87
103
|
*/
|
|
88
|
-
function update_types(config,
|
|
104
|
+
function update_types(config, routes, route) {
|
|
105
|
+
if (!route.leaf && !route.layout && !route.endpoint) return; // nothing to do
|
|
106
|
+
|
|
89
107
|
const routes_dir = posixify(path.relative('.', config.kit.files.routes));
|
|
90
108
|
const outdir = path.join(config.kit.outDir, 'types', routes_dir, route.id);
|
|
91
109
|
|
|
@@ -112,8 +130,6 @@ function update_types(config, manifest_data, route) {
|
|
|
112
130
|
input_files.push(route.endpoint.file);
|
|
113
131
|
}
|
|
114
132
|
|
|
115
|
-
if (!route.leaf && !route.layout && !route.endpoint) return; // nothing to do
|
|
116
|
-
|
|
117
133
|
try {
|
|
118
134
|
fs.mkdirSync(outdir, { recursive: true });
|
|
119
135
|
} catch {}
|
|
@@ -138,6 +154,7 @@ function update_types(config, manifest_data, route) {
|
|
|
138
154
|
// track which old files end up being surplus to requirements
|
|
139
155
|
const to_delete = new Set(output_files.map((file) => file.name));
|
|
140
156
|
|
|
157
|
+
// now generate new types
|
|
141
158
|
const imports = [`import type * as Kit from '@sveltejs/kit';`];
|
|
142
159
|
|
|
143
160
|
/** @type {string[]} */
|
|
@@ -146,41 +163,29 @@ function update_types(config, manifest_data, route) {
|
|
|
146
163
|
/** @type {string[]} */
|
|
147
164
|
const exports = [];
|
|
148
165
|
|
|
149
|
-
|
|
150
|
-
|
|
166
|
+
declarations.push(
|
|
167
|
+
`type RouteParams = { ${route.names.map((param) => `${param}: string`).join('; ')} }`
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
if (route.layout || route.leaf) {
|
|
171
|
+
// 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
|
|
172
|
+
declarations.push(`type MaybeWithVoid<T> = {} extends T ? T | void : T;`);
|
|
151
173
|
declarations.push(
|
|
152
|
-
`
|
|
174
|
+
`export type RequiredKeys<T> = { [K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K; }[keyof T];`
|
|
153
175
|
);
|
|
154
|
-
|
|
155
|
-
|
|
176
|
+
declarations.push(
|
|
177
|
+
`type OutputDataShape<T> = MaybeWithVoid<Omit<App.PageData, RequiredKeys<T>> & Partial<Pick<App.PageData, keyof T & keyof App.PageData>> & Record<string, any>>`
|
|
178
|
+
);
|
|
179
|
+
declarations.push(`type EnsureParentData<T> = NonNullable<T> extends never ? {} : T;`);
|
|
156
180
|
}
|
|
157
181
|
|
|
158
182
|
if (route.leaf) {
|
|
159
|
-
const {
|
|
160
|
-
route.leaf,
|
|
161
|
-
outdir,
|
|
162
|
-
'RouteParams'
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
for (const file of written_proxies) to_delete.delete(file);
|
|
183
|
+
const { declarations: d, exports: e, written_proxies } = process_node(route.leaf, outdir, true);
|
|
166
184
|
|
|
167
|
-
exports.push(
|
|
185
|
+
exports.push(...e);
|
|
186
|
+
declarations.push(...d);
|
|
168
187
|
|
|
169
|
-
|
|
170
|
-
if (load) {
|
|
171
|
-
exports.push(
|
|
172
|
-
`export type PageLoad<OutputData extends Record<string, any> | void = Record<string, any> | void> = ${load};`
|
|
173
|
-
);
|
|
174
|
-
exports.push('export type PageLoadEvent = Parameters<PageLoad>[0];');
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
exports.push(`export type PageServerData = ${server_data};`);
|
|
178
|
-
if (server_load) {
|
|
179
|
-
exports.push(
|
|
180
|
-
`export type PageServerLoad<OutputData extends Record<string, any> | void = Record<string, any> | void> = ${server_load};`
|
|
181
|
-
);
|
|
182
|
-
exports.push('export type PageServerLoadEvent = Parameters<PageServerLoad>[0];');
|
|
183
|
-
}
|
|
188
|
+
for (const file of written_proxies) to_delete.delete(file);
|
|
184
189
|
|
|
185
190
|
if (route.leaf.server) {
|
|
186
191
|
exports.push(`export type Action = Kit.Action<RouteParams>`);
|
|
@@ -188,47 +193,36 @@ function update_types(config, manifest_data, route) {
|
|
|
188
193
|
}
|
|
189
194
|
|
|
190
195
|
if (route.layout) {
|
|
191
|
-
|
|
196
|
+
let all_pages_have_load = true;
|
|
192
197
|
const layout_params = new Set();
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
for (const name of
|
|
198
|
+
route.layout.child_pages?.forEach((page) => {
|
|
199
|
+
const leaf = routes.get(page);
|
|
200
|
+
if (leaf) {
|
|
201
|
+
for (const name of leaf.names) {
|
|
197
202
|
layout_params.add(name);
|
|
198
203
|
}
|
|
199
204
|
}
|
|
205
|
+
if (!page.server && !page.shared) {
|
|
206
|
+
all_pages_have_load = false;
|
|
207
|
+
}
|
|
200
208
|
});
|
|
201
209
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
declarations.push(`interface LayoutParams extends RouteParams {}`);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const { data, server_data, load, server_load, written_proxies } = process_node(
|
|
210
|
-
route.layout,
|
|
211
|
-
outdir,
|
|
212
|
-
'LayoutParams'
|
|
210
|
+
declarations.push(
|
|
211
|
+
`type LayoutParams = RouteParams & { ${Array.from(layout_params).map(
|
|
212
|
+
(param) => `${param}?: string`
|
|
213
|
+
)} }`
|
|
213
214
|
);
|
|
214
215
|
|
|
215
|
-
|
|
216
|
+
const {
|
|
217
|
+
exports: e,
|
|
218
|
+
declarations: d,
|
|
219
|
+
written_proxies
|
|
220
|
+
} = process_node(route.layout, outdir, false, all_pages_have_load);
|
|
216
221
|
|
|
217
|
-
exports.push(
|
|
218
|
-
|
|
219
|
-
exports.push(
|
|
220
|
-
`export type LayoutLoad<OutputData extends Record<string, any> | void = Record<string, any> | void> = ${load};`
|
|
221
|
-
);
|
|
222
|
-
exports.push('export type LayoutLoadEvent = Parameters<LayoutLoad>[0];');
|
|
223
|
-
}
|
|
222
|
+
exports.push(...e);
|
|
223
|
+
declarations.push(...d);
|
|
224
224
|
|
|
225
|
-
|
|
226
|
-
if (server_load) {
|
|
227
|
-
exports.push(
|
|
228
|
-
`export type LayoutServerLoad<OutputData extends Record<string, any> | void = Record<string, any> | void> = ${server_load};`
|
|
229
|
-
);
|
|
230
|
-
exports.push('export type LayoutServerLoadEvent = Parameters<LayoutServerLoad>[0];');
|
|
231
|
-
}
|
|
225
|
+
for (const file of written_proxies) to_delete.delete(file);
|
|
232
226
|
}
|
|
233
227
|
|
|
234
228
|
if (route.endpoint) {
|
|
@@ -251,18 +245,24 @@ function update_types(config, manifest_data, route) {
|
|
|
251
245
|
/**
|
|
252
246
|
* @param {import('types').PageNode} node
|
|
253
247
|
* @param {string} outdir
|
|
254
|
-
* @param {
|
|
248
|
+
* @param {boolean} is_page
|
|
249
|
+
* @param {boolean} [all_pages_have_load]
|
|
255
250
|
*/
|
|
256
|
-
function process_node(node, outdir,
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
let server_load;
|
|
260
|
-
let errors;
|
|
251
|
+
function process_node(node, outdir, is_page, all_pages_have_load = true) {
|
|
252
|
+
const params = `${is_page ? 'Route' : 'Layout'}Params`;
|
|
253
|
+
const prefix = is_page ? 'Page' : 'Layout';
|
|
261
254
|
|
|
262
255
|
/** @type {string[]} */
|
|
263
256
|
let written_proxies = [];
|
|
257
|
+
/** @type {string[]} */
|
|
258
|
+
const declarations = [];
|
|
259
|
+
/** @type {string[]} */
|
|
260
|
+
const exports = [];
|
|
264
261
|
|
|
262
|
+
/** @type {string} */
|
|
265
263
|
let server_data;
|
|
264
|
+
/** @type {string} */
|
|
265
|
+
let data;
|
|
266
266
|
|
|
267
267
|
if (node.server) {
|
|
268
268
|
const content = fs.readFileSync(node.server, 'utf8');
|
|
@@ -274,33 +274,52 @@ function process_node(node, outdir, params) {
|
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
server_data = get_data_type(node.server, 'null', proxy);
|
|
277
|
-
server_load = `Kit.ServerLoad<${params}, ${get_parent_type(
|
|
278
|
-
node,
|
|
279
|
-
'LayoutServerData'
|
|
280
|
-
)}, OutputData>`;
|
|
281
277
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
278
|
+
const parent_type = `${prefix}ServerParentData`;
|
|
279
|
+
|
|
280
|
+
declarations.push(
|
|
281
|
+
`type ${parent_type} = EnsureParentData<${get_parent_type(node, 'LayoutServerData')}>;`
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
// +page.js load present -> server can return all-optional data
|
|
285
|
+
const output_data_shape =
|
|
286
|
+
node.shared || (!is_page && all_pages_have_load)
|
|
287
|
+
? `Partial<App.PageData> & Record<string, any> | void`
|
|
288
|
+
: `OutputDataShape<${parent_type}>`;
|
|
289
|
+
exports.push(
|
|
290
|
+
`export type ${prefix}ServerLoad<OutputData extends ${output_data_shape} = ${output_data_shape}> = Kit.ServerLoad<${params}, ${parent_type}, OutputData>;`
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
exports.push(`export type ${prefix}ServerLoadEvent = Parameters<${prefix}ServerLoad>[0];`);
|
|
294
|
+
|
|
295
|
+
if (is_page) {
|
|
296
|
+
let errors = 'unknown';
|
|
297
|
+
if (proxy) {
|
|
298
|
+
const types = [];
|
|
299
|
+
for (const method of ['POST', 'PUT', 'PATCH', 'DELETE']) {
|
|
300
|
+
if (proxy.exports.includes(method)) {
|
|
301
|
+
// If the file wasn't tweaked, we can use the return type of the original file.
|
|
302
|
+
// The advantage is that type updates are reflected without saving.
|
|
303
|
+
const from = proxy.modified
|
|
304
|
+
? `./proxy${replace_ext_with_js(basename)}`
|
|
305
|
+
: path_to_original(outdir, node.server);
|
|
306
|
+
|
|
307
|
+
types.push(`Kit.AwaitedErrors<typeof import('${from}').${method}>`);
|
|
308
|
+
}
|
|
293
309
|
}
|
|
310
|
+
errors = types.length ? types.join(' | ') : 'null';
|
|
294
311
|
}
|
|
295
|
-
|
|
296
|
-
} else {
|
|
297
|
-
errors = 'unknown';
|
|
312
|
+
exports.push(`export type Errors = ${errors};`);
|
|
298
313
|
}
|
|
299
314
|
} else {
|
|
300
315
|
server_data = 'null';
|
|
301
316
|
}
|
|
317
|
+
exports.push(`export type ${prefix}ServerData = ${server_data};`);
|
|
302
318
|
|
|
303
|
-
const parent_type =
|
|
319
|
+
const parent_type = `${prefix}ParentData`;
|
|
320
|
+
declarations.push(
|
|
321
|
+
`type ${parent_type} = EnsureParentData<${get_parent_type(node, 'LayoutData')}>;`
|
|
322
|
+
);
|
|
304
323
|
|
|
305
324
|
if (node.shared) {
|
|
306
325
|
const content = fs.readFileSync(node.shared, 'utf8');
|
|
@@ -310,17 +329,28 @@ function process_node(node, outdir, params) {
|
|
|
310
329
|
written_proxies.push(`proxy${path.basename(node.shared)}`);
|
|
311
330
|
}
|
|
312
331
|
|
|
313
|
-
const type = get_data_type(node.shared, `${parent_type} & ${
|
|
332
|
+
const type = get_data_type(node.shared, `${parent_type} & ${prefix}ServerData`, proxy);
|
|
314
333
|
|
|
315
334
|
data = `Omit<${parent_type}, keyof ${type}> & ${type}`;
|
|
316
|
-
|
|
335
|
+
|
|
336
|
+
const output_data_shape =
|
|
337
|
+
!is_page && all_pages_have_load
|
|
338
|
+
? `Partial<App.PageData> & Record<string, any> | void`
|
|
339
|
+
: `OutputDataShape<${parent_type}>`;
|
|
340
|
+
exports.push(
|
|
341
|
+
`export type ${prefix}Load<OutputData extends ${output_data_shape} = ${output_data_shape}> = Kit.Load<${params}, ${prefix}ServerData, ${parent_type}, OutputData>;`
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
exports.push(`export type ${prefix}LoadEvent = Parameters<${prefix}Load>[0];`);
|
|
317
345
|
} else if (server_data === 'null') {
|
|
318
346
|
data = parent_type;
|
|
319
347
|
} else {
|
|
320
|
-
data = `Omit<${parent_type}, keyof ${
|
|
348
|
+
data = `Omit<${parent_type}, keyof ${prefix}ServerData> & ${prefix}ServerData`;
|
|
321
349
|
}
|
|
322
350
|
|
|
323
|
-
|
|
351
|
+
exports.push(`export type ${prefix}Data = ${data};`);
|
|
352
|
+
|
|
353
|
+
return { declarations, exports, written_proxies };
|
|
324
354
|
|
|
325
355
|
/**
|
|
326
356
|
* @param {string} file_path
|
|
@@ -364,7 +394,7 @@ function get_parent_type(node, type) {
|
|
|
364
394
|
parent = parent.parent;
|
|
365
395
|
}
|
|
366
396
|
|
|
367
|
-
let parent_str = parent_imports[0] || '
|
|
397
|
+
let parent_str = parent_imports[0] || '{}';
|
|
368
398
|
for (let i = 1; i < parent_imports.length; i++) {
|
|
369
399
|
// Omit is necessary because a parent could have a property with the same key which would
|
|
370
400
|
// cause a type conflict. At runtime the child overwrites the parent property in this case,
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type * as Kit from '@sveltejs/kit';
|
|
2
|
+
|
|
3
|
+
type RouteParams = {};
|
|
4
|
+
type MaybeWithVoid<T> = {} extends T ? T | void : T;
|
|
5
|
+
export type RequiredKeys<T> = {
|
|
6
|
+
[K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K;
|
|
7
|
+
}[keyof T];
|
|
8
|
+
type OutputDataShape<T> = MaybeWithVoid<
|
|
9
|
+
Omit<App.PageData, RequiredKeys<T>> &
|
|
10
|
+
Partial<Pick<App.PageData, keyof T & keyof App.PageData>> &
|
|
11
|
+
Record<string, any>
|
|
12
|
+
>;
|
|
13
|
+
type EnsureParentData<T> = NonNullable<T> extends never ? {} : T;
|
|
14
|
+
type PageServerParentData = EnsureParentData<LayoutServerData>;
|
|
15
|
+
type PageParentData = EnsureParentData<LayoutData>;
|
|
16
|
+
type LayoutParams = RouteParams & {};
|
|
17
|
+
type LayoutServerParentData = EnsureParentData<{}>;
|
|
18
|
+
type LayoutParentData = EnsureParentData<{}>;
|
|
19
|
+
|
|
20
|
+
export type PageServerLoad<
|
|
21
|
+
OutputData extends (Partial<App.PageData> & Record<string, any>) | void =
|
|
22
|
+
| (Partial<App.PageData> & Record<string, any>)
|
|
23
|
+
| void
|
|
24
|
+
> = Kit.ServerLoad<RouteParams, PageServerParentData, OutputData>;
|
|
25
|
+
export type PageServerLoadEvent = Parameters<PageServerLoad>[0];
|
|
26
|
+
export type Errors = null;
|
|
27
|
+
export type PageServerData = Kit.AwaitedProperties<
|
|
28
|
+
Awaited<ReturnType<typeof import('../../../../../../../../+page.server.js').load>>
|
|
29
|
+
>;
|
|
30
|
+
export type PageLoad<
|
|
31
|
+
OutputData extends OutputDataShape<PageParentData> = OutputDataShape<PageParentData>
|
|
32
|
+
> = Kit.Load<RouteParams, PageServerData, PageParentData, OutputData>;
|
|
33
|
+
export type PageLoadEvent = Parameters<PageLoad>[0];
|
|
34
|
+
export type PageData = Omit<
|
|
35
|
+
PageParentData,
|
|
36
|
+
keyof Kit.AwaitedProperties<
|
|
37
|
+
Awaited<ReturnType<typeof import('../../../../../../../../+page.js').load>>
|
|
38
|
+
>
|
|
39
|
+
> &
|
|
40
|
+
Kit.AwaitedProperties<
|
|
41
|
+
Awaited<ReturnType<typeof import('../../../../../../../../+page.js').load>>
|
|
42
|
+
>;
|
|
43
|
+
export type Action = Kit.Action<RouteParams>;
|
|
44
|
+
export type LayoutServerLoad<
|
|
45
|
+
OutputData extends (Partial<App.PageData> & Record<string, any>) | void =
|
|
46
|
+
| (Partial<App.PageData> & Record<string, any>)
|
|
47
|
+
| void
|
|
48
|
+
> = Kit.ServerLoad<LayoutParams, LayoutServerParentData, OutputData>;
|
|
49
|
+
export type LayoutServerLoadEvent = Parameters<LayoutServerLoad>[0];
|
|
50
|
+
export type LayoutServerData = Kit.AwaitedProperties<
|
|
51
|
+
Awaited<ReturnType<typeof import('../../../../../../../../+layout.server.js').load>>
|
|
52
|
+
>;
|
|
53
|
+
export type LayoutLoad<
|
|
54
|
+
OutputData extends (Partial<App.PageData> & Record<string, any>) | void =
|
|
55
|
+
| (Partial<App.PageData> & Record<string, any>)
|
|
56
|
+
| void
|
|
57
|
+
> = Kit.Load<LayoutParams, LayoutServerData, LayoutParentData, OutputData>;
|
|
58
|
+
export type LayoutLoadEvent = Parameters<LayoutLoad>[0];
|
|
59
|
+
export type LayoutData = Omit<
|
|
60
|
+
LayoutParentData,
|
|
61
|
+
keyof Kit.AwaitedProperties<
|
|
62
|
+
Awaited<ReturnType<typeof import('../../../../../../../../+layout.js').load>>
|
|
63
|
+
>
|
|
64
|
+
> &
|
|
65
|
+
Kit.AwaitedProperties<
|
|
66
|
+
Awaited<ReturnType<typeof import('../../../../../../../../+layout.js').load>>
|
|
67
|
+
>;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type * as Kit from '@sveltejs/kit';
|
|
2
|
+
|
|
3
|
+
type RouteParams = {};
|
|
4
|
+
type MaybeWithVoid<T> = {} extends T ? T | void : T;
|
|
5
|
+
export type RequiredKeys<T> = {
|
|
6
|
+
[K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K;
|
|
7
|
+
}[keyof T];
|
|
8
|
+
type OutputDataShape<T> = MaybeWithVoid<
|
|
9
|
+
Omit<App.PageData, RequiredKeys<T>> &
|
|
10
|
+
Partial<Pick<App.PageData, keyof T & keyof App.PageData>> &
|
|
11
|
+
Record<string, any>
|
|
12
|
+
>;
|
|
13
|
+
type EnsureParentData<T> = NonNullable<T> extends never ? {} : T;
|
|
14
|
+
type LayoutParams = RouteParams & {};
|
|
15
|
+
type LayoutParentData = EnsureParentData<{}>;
|
|
16
|
+
|
|
17
|
+
export type LayoutServerData = null;
|
|
18
|
+
export type LayoutLoad<
|
|
19
|
+
OutputData extends (Partial<App.PageData> & Record<string, any>) | void =
|
|
20
|
+
| (Partial<App.PageData> & Record<string, any>)
|
|
21
|
+
| void
|
|
22
|
+
> = Kit.Load<LayoutParams, LayoutServerData, LayoutParentData, OutputData>;
|
|
23
|
+
export type LayoutLoadEvent = Parameters<LayoutLoad>[0];
|
|
24
|
+
export type LayoutData = Omit<
|
|
25
|
+
LayoutParentData,
|
|
26
|
+
keyof Kit.AwaitedProperties<
|
|
27
|
+
Awaited<ReturnType<typeof import('../../../../../../../../+layout.js').load>>
|
|
28
|
+
>
|
|
29
|
+
> &
|
|
30
|
+
Kit.AwaitedProperties<
|
|
31
|
+
Awaited<ReturnType<typeof import('../../../../../../../../+layout.js').load>>
|
|
32
|
+
>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type * as Kit from '@sveltejs/kit';
|
|
2
|
+
|
|
3
|
+
type RouteParams = {};
|
|
4
|
+
type MaybeWithVoid<T> = {} extends T ? T | void : T;
|
|
5
|
+
export type RequiredKeys<T> = {
|
|
6
|
+
[K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K;
|
|
7
|
+
}[keyof T];
|
|
8
|
+
type OutputDataShape<T> = MaybeWithVoid<
|
|
9
|
+
Omit<App.PageData, RequiredKeys<T>> &
|
|
10
|
+
Partial<Pick<App.PageData, keyof T & keyof App.PageData>> &
|
|
11
|
+
Record<string, any>
|
|
12
|
+
>;
|
|
13
|
+
type EnsureParentData<T> = NonNullable<T> extends never ? {} : T;
|
|
14
|
+
type PageParentData = EnsureParentData<import('../$types.js').LayoutData>;
|
|
15
|
+
type LayoutParams = RouteParams & {};
|
|
16
|
+
type LayoutServerParentData = EnsureParentData<import('../$types.js').LayoutServerData>;
|
|
17
|
+
type LayoutParentData = EnsureParentData<import('../$types.js').LayoutData>;
|
|
18
|
+
|
|
19
|
+
export type PageServerData = null;
|
|
20
|
+
export type PageLoad<
|
|
21
|
+
OutputData extends OutputDataShape<PageParentData> = OutputDataShape<PageParentData>
|
|
22
|
+
> = Kit.Load<RouteParams, PageServerData, PageParentData, OutputData>;
|
|
23
|
+
export type PageLoadEvent = Parameters<PageLoad>[0];
|
|
24
|
+
export type PageData = Omit<
|
|
25
|
+
PageParentData,
|
|
26
|
+
keyof Kit.AwaitedProperties<
|
|
27
|
+
Awaited<ReturnType<typeof import('../../../../../../../../../(main)/+page.js').load>>
|
|
28
|
+
>
|
|
29
|
+
> &
|
|
30
|
+
Kit.AwaitedProperties<
|
|
31
|
+
Awaited<ReturnType<typeof import('../../../../../../../../../(main)/+page.js').load>>
|
|
32
|
+
>;
|
|
33
|
+
export type LayoutServerLoad<
|
|
34
|
+
OutputData extends (Partial<App.PageData> & Record<string, any>) | void =
|
|
35
|
+
| (Partial<App.PageData> & Record<string, any>)
|
|
36
|
+
| void
|
|
37
|
+
> = Kit.ServerLoad<LayoutParams, LayoutServerParentData, OutputData>;
|
|
38
|
+
export type LayoutServerLoadEvent = Parameters<LayoutServerLoad>[0];
|
|
39
|
+
export type LayoutServerData = Kit.AwaitedProperties<
|
|
40
|
+
Awaited<ReturnType<typeof import('../../../../../../../../../(main)/+layout.server.js').load>>
|
|
41
|
+
>;
|
|
42
|
+
export type LayoutData = Omit<LayoutParentData, keyof LayoutServerData> & LayoutServerData;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type * as Kit from '@sveltejs/kit';
|
|
2
|
+
|
|
3
|
+
type RouteParams = {};
|
|
4
|
+
type MaybeWithVoid<T> = {} extends T ? T | void : T;
|
|
5
|
+
export type RequiredKeys<T> = {
|
|
6
|
+
[K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K;
|
|
7
|
+
}[keyof T];
|
|
8
|
+
type OutputDataShape<T> = MaybeWithVoid<
|
|
9
|
+
Omit<App.PageData, RequiredKeys<T>> &
|
|
10
|
+
Partial<Pick<App.PageData, keyof T & keyof App.PageData>> &
|
|
11
|
+
Record<string, any>
|
|
12
|
+
>;
|
|
13
|
+
type EnsureParentData<T> = NonNullable<T> extends never ? {} : T;
|
|
14
|
+
type PageParentData = EnsureParentData<
|
|
15
|
+
Omit<import('../../$types.js').LayoutData, keyof import('../$types.js').LayoutData> &
|
|
16
|
+
import('../$types.js').LayoutData
|
|
17
|
+
>;
|
|
18
|
+
|
|
19
|
+
export type PageServerData = null;
|
|
20
|
+
export type PageLoad<
|
|
21
|
+
OutputData extends OutputDataShape<PageParentData> = OutputDataShape<PageParentData>
|
|
22
|
+
> = Kit.Load<RouteParams, PageServerData, PageParentData, OutputData>;
|
|
23
|
+
export type PageLoadEvent = Parameters<PageLoad>[0];
|
|
24
|
+
export type PageData = Omit<
|
|
25
|
+
PageParentData,
|
|
26
|
+
keyof Kit.AwaitedProperties<
|
|
27
|
+
Awaited<ReturnType<typeof import('../../../../../../../../../../(main)/sub/+page.js').load>>
|
|
28
|
+
>
|
|
29
|
+
> &
|
|
30
|
+
Kit.AwaitedProperties<
|
|
31
|
+
Awaited<ReturnType<typeof import('../../../../../../../../../../(main)/sub/+page.js').load>>
|
|
32
|
+
>;
|
|
File without changes
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type * as Kit from '@sveltejs/kit';
|
|
2
|
+
|
|
3
|
+
type RouteParams = {};
|
|
4
|
+
type MaybeWithVoid<T> = {} extends T ? T | void : T;
|
|
5
|
+
export type RequiredKeys<T> = {
|
|
6
|
+
[K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K;
|
|
7
|
+
}[keyof T];
|
|
8
|
+
type OutputDataShape<T> = MaybeWithVoid<
|
|
9
|
+
Omit<App.PageData, RequiredKeys<T>> &
|
|
10
|
+
Partial<Pick<App.PageData, keyof T & keyof App.PageData>> &
|
|
11
|
+
Record<string, any>
|
|
12
|
+
>;
|
|
13
|
+
type EnsureParentData<T> = NonNullable<T> extends never ? {} : T;
|
|
14
|
+
type PageServerParentData = EnsureParentData<LayoutServerData>;
|
|
15
|
+
type PageParentData = EnsureParentData<LayoutData>;
|
|
16
|
+
type LayoutParams = RouteParams & {};
|
|
17
|
+
type LayoutParentData = EnsureParentData<{}>;
|
|
18
|
+
|
|
19
|
+
export type PageServerLoad<
|
|
20
|
+
OutputData extends (Partial<App.PageData> & Record<string, any>) | void =
|
|
21
|
+
| (Partial<App.PageData> & Record<string, any>)
|
|
22
|
+
| void
|
|
23
|
+
> = Kit.ServerLoad<RouteParams, PageServerParentData, OutputData>;
|
|
24
|
+
export type PageServerLoadEvent = Parameters<PageServerLoad>[0];
|
|
25
|
+
export type Errors = null;
|
|
26
|
+
export type PageServerData = Kit.AwaitedProperties<
|
|
27
|
+
Awaited<ReturnType<typeof import('../../../../../../../../+page.server.js').load>>
|
|
28
|
+
>;
|
|
29
|
+
export type PageLoad<
|
|
30
|
+
OutputData extends OutputDataShape<PageParentData> = OutputDataShape<PageParentData>
|
|
31
|
+
> = Kit.Load<RouteParams, PageServerData, PageParentData, OutputData>;
|
|
32
|
+
export type PageLoadEvent = Parameters<PageLoad>[0];
|
|
33
|
+
export type PageData = Omit<
|
|
34
|
+
PageParentData,
|
|
35
|
+
keyof Kit.AwaitedProperties<
|
|
36
|
+
Awaited<ReturnType<typeof import('../../../../../../../../+page.js').load>>
|
|
37
|
+
>
|
|
38
|
+
> &
|
|
39
|
+
Kit.AwaitedProperties<
|
|
40
|
+
Awaited<ReturnType<typeof import('../../../../../../../../+page.js').load>>
|
|
41
|
+
>;
|
|
42
|
+
export type Action = Kit.Action<RouteParams>;
|
|
43
|
+
export type LayoutServerData = null;
|
|
44
|
+
export type LayoutData = LayoutParentData;
|
|
File without changes
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type * as Kit from '@sveltejs/kit';
|
|
2
|
+
|
|
3
|
+
type RouteParams = {};
|
|
4
|
+
type MaybeWithVoid<T> = {} extends T ? T | void : T;
|
|
5
|
+
export type RequiredKeys<T> = {
|
|
6
|
+
[K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K;
|
|
7
|
+
}[keyof T];
|
|
8
|
+
type OutputDataShape<T> = MaybeWithVoid<
|
|
9
|
+
Omit<App.PageData, RequiredKeys<T>> &
|
|
10
|
+
Partial<Pick<App.PageData, keyof T & keyof App.PageData>> &
|
|
11
|
+
Record<string, any>
|
|
12
|
+
>;
|
|
13
|
+
type EnsureParentData<T> = NonNullable<T> extends never ? {} : T;
|
|
14
|
+
type PageServerParentData = EnsureParentData<LayoutServerData>;
|
|
15
|
+
type PageParentData = EnsureParentData<LayoutData>;
|
|
16
|
+
type LayoutParams = RouteParams & {};
|
|
17
|
+
type LayoutParentData = EnsureParentData<{}>;
|
|
18
|
+
|
|
19
|
+
export type PageServerLoad<
|
|
20
|
+
OutputData extends OutputDataShape<PageServerParentData> = OutputDataShape<PageServerParentData>
|
|
21
|
+
> = Kit.ServerLoad<RouteParams, PageServerParentData, OutputData>;
|
|
22
|
+
export type PageServerLoadEvent = Parameters<PageServerLoad>[0];
|
|
23
|
+
export type Errors = null;
|
|
24
|
+
export type PageServerData = Kit.AwaitedProperties<
|
|
25
|
+
Awaited<ReturnType<typeof import('../../../../../../../../+page.server.js').load>>
|
|
26
|
+
>;
|
|
27
|
+
export type PageData = Omit<PageParentData, keyof PageServerData> & PageServerData;
|
|
28
|
+
export type Action = Kit.Action<RouteParams>;
|
|
29
|
+
export type LayoutServerData = null;
|
|
30
|
+
export type LayoutData = LayoutParentData;
|
|
File without changes
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type * as Kit from '@sveltejs/kit';
|
|
2
|
+
|
|
3
|
+
type RouteParams = {};
|
|
4
|
+
type MaybeWithVoid<T> = {} extends T ? T | void : T;
|
|
5
|
+
export type RequiredKeys<T> = {
|
|
6
|
+
[K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K;
|
|
7
|
+
}[keyof T];
|
|
8
|
+
type OutputDataShape<T> = MaybeWithVoid<
|
|
9
|
+
Omit<App.PageData, RequiredKeys<T>> &
|
|
10
|
+
Partial<Pick<App.PageData, keyof T & keyof App.PageData>> &
|
|
11
|
+
Record<string, any>
|
|
12
|
+
>;
|
|
13
|
+
type EnsureParentData<T> = NonNullable<T> extends never ? {} : T;
|
|
14
|
+
type PageParentData = EnsureParentData<LayoutData>;
|
|
15
|
+
type LayoutParams = RouteParams & {};
|
|
16
|
+
type LayoutParentData = EnsureParentData<{}>;
|
|
17
|
+
|
|
18
|
+
export type PageServerData = null;
|
|
19
|
+
export type PageLoad<
|
|
20
|
+
OutputData extends OutputDataShape<PageParentData> = OutputDataShape<PageParentData>
|
|
21
|
+
> = Kit.Load<RouteParams, PageServerData, PageParentData, OutputData>;
|
|
22
|
+
export type PageLoadEvent = Parameters<PageLoad>[0];
|
|
23
|
+
export type PageData = Omit<
|
|
24
|
+
PageParentData,
|
|
25
|
+
keyof Kit.AwaitedProperties<
|
|
26
|
+
Awaited<ReturnType<typeof import('../../../../../../../../+page.js').load>>
|
|
27
|
+
>
|
|
28
|
+
> &
|
|
29
|
+
Kit.AwaitedProperties<
|
|
30
|
+
Awaited<ReturnType<typeof import('../../../../../../../../+page.js').load>>
|
|
31
|
+
>;
|
|
32
|
+
export type LayoutServerData = null;
|
|
33
|
+
export type LayoutData = LayoutParentData;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function load() {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function load() {}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type * as Kit from '@sveltejs/kit';
|
|
2
|
+
|
|
3
|
+
type RouteParams = {};
|
|
4
|
+
type MaybeWithVoid<T> = {} extends T ? T | void : T;
|
|
5
|
+
export type RequiredKeys<T> = {
|
|
6
|
+
[K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K;
|
|
7
|
+
}[keyof T];
|
|
8
|
+
type OutputDataShape<T> = MaybeWithVoid<
|
|
9
|
+
Omit<App.PageData, RequiredKeys<T>> &
|
|
10
|
+
Partial<Pick<App.PageData, keyof T & keyof App.PageData>> &
|
|
11
|
+
Record<string, any>
|
|
12
|
+
>;
|
|
13
|
+
type EnsureParentData<T> = NonNullable<T> extends never ? {} : T;
|
|
14
|
+
type LayoutParams = RouteParams & { rest?: string; slug?: string };
|
|
15
|
+
type LayoutParentData = EnsureParentData<{}>;
|
|
16
|
+
|
|
17
|
+
export type LayoutServerData = null;
|
|
18
|
+
export type LayoutLoad<
|
|
19
|
+
OutputData extends (Partial<App.PageData> & Record<string, any>) | void =
|
|
20
|
+
| (Partial<App.PageData> & Record<string, any>)
|
|
21
|
+
| void
|
|
22
|
+
> = Kit.Load<LayoutParams, LayoutServerData, LayoutParentData, OutputData>;
|
|
23
|
+
export type LayoutLoadEvent = Parameters<LayoutLoad>[0];
|
|
24
|
+
export type LayoutData = Omit<
|
|
25
|
+
LayoutParentData,
|
|
26
|
+
keyof Kit.AwaitedProperties<
|
|
27
|
+
Awaited<ReturnType<typeof import('../../../../../../../../+layout.js').load>>
|
|
28
|
+
>
|
|
29
|
+
> &
|
|
30
|
+
Kit.AwaitedProperties<
|
|
31
|
+
Awaited<ReturnType<typeof import('../../../../../../../../+layout.js').load>>
|
|
32
|
+
>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type * as Kit from '@sveltejs/kit';
|
|
2
|
+
|
|
3
|
+
type RouteParams = { rest: string };
|
|
4
|
+
type MaybeWithVoid<T> = {} extends T ? T | void : T;
|
|
5
|
+
export type RequiredKeys<T> = {
|
|
6
|
+
[K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K;
|
|
7
|
+
}[keyof T];
|
|
8
|
+
type OutputDataShape<T> = MaybeWithVoid<
|
|
9
|
+
Omit<App.PageData, RequiredKeys<T>> &
|
|
10
|
+
Partial<Pick<App.PageData, keyof T & keyof App.PageData>> &
|
|
11
|
+
Record<string, any>
|
|
12
|
+
>;
|
|
13
|
+
type EnsureParentData<T> = NonNullable<T> extends never ? {} : T;
|
|
14
|
+
type PageParentData = EnsureParentData<import('../$types.js').LayoutData>;
|
|
15
|
+
|
|
16
|
+
export type PageServerData = null;
|
|
17
|
+
export type PageLoad<
|
|
18
|
+
OutputData extends OutputDataShape<PageParentData> = OutputDataShape<PageParentData>
|
|
19
|
+
> = Kit.Load<RouteParams, PageServerData, PageParentData, OutputData>;
|
|
20
|
+
export type PageLoadEvent = Parameters<PageLoad>[0];
|
|
21
|
+
export type PageData = Omit<
|
|
22
|
+
PageParentData,
|
|
23
|
+
keyof Kit.AwaitedProperties<
|
|
24
|
+
Awaited<ReturnType<typeof import('../../../../../../../../../[...rest]/+page.js').load>>
|
|
25
|
+
>
|
|
26
|
+
> &
|
|
27
|
+
Kit.AwaitedProperties<
|
|
28
|
+
Awaited<ReturnType<typeof import('../../../../../../../../../[...rest]/+page.js').load>>
|
|
29
|
+
>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type * as Kit from '@sveltejs/kit';
|
|
2
|
+
|
|
3
|
+
type RouteParams = { slug: string };
|
|
4
|
+
type MaybeWithVoid<T> = {} extends T ? T | void : T;
|
|
5
|
+
export type RequiredKeys<T> = {
|
|
6
|
+
[K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K;
|
|
7
|
+
}[keyof T];
|
|
8
|
+
type OutputDataShape<T> = MaybeWithVoid<
|
|
9
|
+
Omit<App.PageData, RequiredKeys<T>> &
|
|
10
|
+
Partial<Pick<App.PageData, keyof T & keyof App.PageData>> &
|
|
11
|
+
Record<string, any>
|
|
12
|
+
>;
|
|
13
|
+
type EnsureParentData<T> = NonNullable<T> extends never ? {} : T;
|
|
14
|
+
type PageParentData = EnsureParentData<import('../$types.js').LayoutData>;
|
|
15
|
+
|
|
16
|
+
export type PageServerData = null;
|
|
17
|
+
export type PageLoad<
|
|
18
|
+
OutputData extends OutputDataShape<PageParentData> = OutputDataShape<PageParentData>
|
|
19
|
+
> = Kit.Load<RouteParams, PageServerData, PageParentData, OutputData>;
|
|
20
|
+
export type PageLoadEvent = Parameters<PageLoad>[0];
|
|
21
|
+
export type PageData = Omit<
|
|
22
|
+
PageParentData,
|
|
23
|
+
keyof Kit.AwaitedProperties<
|
|
24
|
+
Awaited<ReturnType<typeof import('../../../../../../../../../[slug]/+page.js').load>>
|
|
25
|
+
>
|
|
26
|
+
> &
|
|
27
|
+
Kit.AwaitedProperties<
|
|
28
|
+
Awaited<ReturnType<typeof import('../../../../../../../../../[slug]/+page.js').load>>
|
|
29
|
+
>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function load() {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function load() {}
|
package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/_expected/$types.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type * as Kit from '@sveltejs/kit';
|
|
2
|
+
|
|
3
|
+
type RouteParams = {};
|
|
4
|
+
type MaybeWithVoid<T> = {} extends T ? T | void : T;
|
|
5
|
+
export type RequiredKeys<T> = {
|
|
6
|
+
[K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K;
|
|
7
|
+
}[keyof T];
|
|
8
|
+
type OutputDataShape<T> = MaybeWithVoid<
|
|
9
|
+
Omit<App.PageData, RequiredKeys<T>> &
|
|
10
|
+
Partial<Pick<App.PageData, keyof T & keyof App.PageData>> &
|
|
11
|
+
Record<string, any>
|
|
12
|
+
>;
|
|
13
|
+
type EnsureParentData<T> = NonNullable<T> extends never ? {} : T;
|
|
14
|
+
type LayoutParams = RouteParams & { rest?: string; slug?: string };
|
|
15
|
+
type LayoutParentData = EnsureParentData<{}>;
|
|
16
|
+
|
|
17
|
+
export type LayoutServerData = null;
|
|
18
|
+
export type LayoutLoad<
|
|
19
|
+
OutputData extends OutputDataShape<LayoutParentData> = OutputDataShape<LayoutParentData>
|
|
20
|
+
> = Kit.Load<LayoutParams, LayoutServerData, LayoutParentData, OutputData>;
|
|
21
|
+
export type LayoutLoadEvent = Parameters<LayoutLoad>[0];
|
|
22
|
+
export type LayoutData = Omit<
|
|
23
|
+
LayoutParentData,
|
|
24
|
+
keyof Kit.AwaitedProperties<
|
|
25
|
+
Awaited<ReturnType<typeof import('../../../../../../../../+layout.js').load>>
|
|
26
|
+
>
|
|
27
|
+
> &
|
|
28
|
+
Kit.AwaitedProperties<
|
|
29
|
+
Awaited<ReturnType<typeof import('../../../../../../../../+layout.js').load>>
|
|
30
|
+
>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type * as Kit from '@sveltejs/kit';
|
|
2
|
+
|
|
3
|
+
type RouteParams = {};
|
|
4
|
+
type MaybeWithVoid<T> = {} extends T ? T | void : T;
|
|
5
|
+
export type RequiredKeys<T> = {
|
|
6
|
+
[K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K;
|
|
7
|
+
}[keyof T];
|
|
8
|
+
type OutputDataShape<T> = MaybeWithVoid<
|
|
9
|
+
Omit<App.PageData, RequiredKeys<T>> &
|
|
10
|
+
Partial<Pick<App.PageData, keyof T & keyof App.PageData>> &
|
|
11
|
+
Record<string, any>
|
|
12
|
+
>;
|
|
13
|
+
type EnsureParentData<T> = NonNullable<T> extends never ? {} : T;
|
|
14
|
+
type LayoutParams = RouteParams & { rest?: string };
|
|
15
|
+
type LayoutParentData = EnsureParentData<import('../$types.js').LayoutData>;
|
|
16
|
+
|
|
17
|
+
export type LayoutServerData = null;
|
|
18
|
+
export type LayoutLoad<
|
|
19
|
+
OutputData extends (Partial<App.PageData> & Record<string, any>) | void =
|
|
20
|
+
| (Partial<App.PageData> & Record<string, any>)
|
|
21
|
+
| void
|
|
22
|
+
> = Kit.Load<LayoutParams, LayoutServerData, LayoutParentData, OutputData>;
|
|
23
|
+
export type LayoutLoadEvent = Parameters<LayoutLoad>[0];
|
|
24
|
+
export type LayoutData = Omit<
|
|
25
|
+
LayoutParentData,
|
|
26
|
+
keyof Kit.AwaitedProperties<
|
|
27
|
+
Awaited<ReturnType<typeof import('../../../../../../../../../nested/+layout.js').load>>
|
|
28
|
+
>
|
|
29
|
+
> &
|
|
30
|
+
Kit.AwaitedProperties<
|
|
31
|
+
Awaited<ReturnType<typeof import('../../../../../../../../../nested/+layout.js').load>>
|
|
32
|
+
>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type * as Kit from '@sveltejs/kit';
|
|
2
|
+
|
|
3
|
+
type RouteParams = { rest: string };
|
|
4
|
+
type MaybeWithVoid<T> = {} extends T ? T | void : T;
|
|
5
|
+
export type RequiredKeys<T> = {
|
|
6
|
+
[K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K;
|
|
7
|
+
}[keyof T];
|
|
8
|
+
type OutputDataShape<T> = MaybeWithVoid<
|
|
9
|
+
Omit<App.PageData, RequiredKeys<T>> &
|
|
10
|
+
Partial<Pick<App.PageData, keyof T & keyof App.PageData>> &
|
|
11
|
+
Record<string, any>
|
|
12
|
+
>;
|
|
13
|
+
type EnsureParentData<T> = NonNullable<T> extends never ? {} : T;
|
|
14
|
+
type PageParentData = EnsureParentData<
|
|
15
|
+
Omit<import('../../$types.js').LayoutData, keyof import('../$types.js').LayoutData> &
|
|
16
|
+
import('../$types.js').LayoutData
|
|
17
|
+
>;
|
|
18
|
+
|
|
19
|
+
export type PageServerData = null;
|
|
20
|
+
export type PageLoad<
|
|
21
|
+
OutputData extends OutputDataShape<PageParentData> = OutputDataShape<PageParentData>
|
|
22
|
+
> = Kit.Load<RouteParams, PageServerData, PageParentData, OutputData>;
|
|
23
|
+
export type PageLoadEvent = Parameters<PageLoad>[0];
|
|
24
|
+
export type PageData = Omit<
|
|
25
|
+
PageParentData,
|
|
26
|
+
keyof Kit.AwaitedProperties<
|
|
27
|
+
Awaited<
|
|
28
|
+
ReturnType<typeof import('../../../../../../../../../../nested/[...rest]/+page.js').load>
|
|
29
|
+
>
|
|
30
|
+
>
|
|
31
|
+
> &
|
|
32
|
+
Kit.AwaitedProperties<
|
|
33
|
+
Awaited<
|
|
34
|
+
ReturnType<typeof import('../../../../../../../../../../nested/[...rest]/+page.js').load>
|
|
35
|
+
>
|
|
36
|
+
>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type * as Kit from '@sveltejs/kit';
|
|
2
|
+
|
|
3
|
+
type RouteParams = { slug: string };
|
|
4
|
+
type MaybeWithVoid<T> = {} extends T ? T | void : T;
|
|
5
|
+
export type RequiredKeys<T> = {
|
|
6
|
+
[K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K;
|
|
7
|
+
}[keyof T];
|
|
8
|
+
type OutputDataShape<T> = MaybeWithVoid<
|
|
9
|
+
Omit<App.PageData, RequiredKeys<T>> &
|
|
10
|
+
Partial<Pick<App.PageData, keyof T & keyof App.PageData>> &
|
|
11
|
+
Record<string, any>
|
|
12
|
+
>;
|
|
13
|
+
type EnsureParentData<T> = NonNullable<T> extends never ? {} : T;
|
|
14
|
+
type PageParentData = EnsureParentData<import('../../$types.js').LayoutData>;
|
|
15
|
+
|
|
16
|
+
export type PageServerData = null;
|
|
17
|
+
export type PageData = PageParentData;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function load() {}
|
package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/nested/+layout.svelte
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function load() {}
|
|
File without changes
|
|
File without changes
|
package/types/ambient.d.ts
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* declare namespace App {
|
|
8
8
|
* interface Locals {}
|
|
9
9
|
*
|
|
10
|
+
* interface PageData {}
|
|
11
|
+
*
|
|
10
12
|
* interface Platform {}
|
|
11
13
|
*
|
|
12
14
|
* interface PrivateEnv {}
|
|
@@ -47,6 +49,13 @@ declare namespace App {
|
|
|
47
49
|
*/
|
|
48
50
|
export interface Locals {}
|
|
49
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Defines the common shape of the [$page.data store](https://kit.svelte.dev/docs/modules#$app-stores-page) - that is, the data that is shared between all pages.
|
|
54
|
+
* The `Load` and `ServerLoad` functions in `./$types` will be narrowed accordingly.
|
|
55
|
+
* Use optional properties for data that is only present on specific pages. Do not add an index signature (`[key: string]: any`).
|
|
56
|
+
*/
|
|
57
|
+
export interface PageData {}
|
|
58
|
+
|
|
50
59
|
/**
|
|
51
60
|
* If your adapter provides [platform-specific context](https://kit.svelte.dev/docs/adapters#supported-environments-platform-specific-context) via `event.platform`, you can specify it here.
|
|
52
61
|
*/
|
package/types/index.d.ts
CHANGED
|
@@ -195,17 +195,17 @@ export interface HandleError {
|
|
|
195
195
|
*/
|
|
196
196
|
export interface Load<
|
|
197
197
|
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
198
|
-
InputData extends Record<string,
|
|
199
|
-
ParentData extends Record<string,
|
|
200
|
-
OutputData extends Record<string,
|
|
198
|
+
InputData extends Record<string, unknown> | null = Record<string, any> | null,
|
|
199
|
+
ParentData extends Record<string, unknown> = Record<string, any>,
|
|
200
|
+
OutputData extends Record<string, unknown> | void = Record<string, any> | void
|
|
201
201
|
> {
|
|
202
202
|
(event: LoadEvent<Params, InputData, ParentData>): MaybePromise<OutputData>;
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
export interface LoadEvent<
|
|
206
206
|
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
207
|
-
Data extends Record<string,
|
|
208
|
-
ParentData extends Record<string,
|
|
207
|
+
Data extends Record<string, unknown> | null = Record<string, any> | null,
|
|
208
|
+
ParentData extends Record<string, unknown> = Record<string, any>
|
|
209
209
|
> {
|
|
210
210
|
fetch(info: RequestInfo, init?: RequestInit): Promise<Response>;
|
|
211
211
|
params: Params;
|
|
@@ -228,7 +228,7 @@ export interface Page<Params extends Record<string, string> = Record<string, str
|
|
|
228
228
|
routeId: string | null;
|
|
229
229
|
status: number;
|
|
230
230
|
error: HttpError | Error | null;
|
|
231
|
-
data: Record<string, any>;
|
|
231
|
+
data: App.PageData & Record<string, any>;
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
export interface ParamMatcher {
|
|
@@ -253,7 +253,9 @@ export interface RequestEvent<
|
|
|
253
253
|
*
|
|
254
254
|
* It receives `Params` as the first generic argument, which you can skip by using [generated types](/docs/types#generated-types) instead.
|
|
255
255
|
*/
|
|
256
|
-
export interface RequestHandler<
|
|
256
|
+
export interface RequestHandler<
|
|
257
|
+
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>
|
|
258
|
+
> {
|
|
257
259
|
(event: RequestEvent<Params>): MaybePromise<Response>;
|
|
258
260
|
}
|
|
259
261
|
|
package/types/internal.d.ts
CHANGED
|
@@ -122,6 +122,10 @@ export interface PageNode {
|
|
|
122
122
|
server?: string;
|
|
123
123
|
parent_id?: string;
|
|
124
124
|
parent?: PageNode;
|
|
125
|
+
/**
|
|
126
|
+
* Filled with the pages that reference this layout (if this is a layout)
|
|
127
|
+
*/
|
|
128
|
+
child_pages?: PageNode[];
|
|
125
129
|
}
|
|
126
130
|
|
|
127
131
|
export type PayloadScriptAttributes =
|