@sveltejs/kit 1.0.0-next.299 → 1.0.0-next.300

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.
@@ -2,7 +2,7 @@ import { onMount, tick } from 'svelte';
2
2
  import { writable } from 'svelte/store';
3
3
  import { assets, set_paths } from '../paths.js';
4
4
  import Root from '__GENERATED__/root.svelte';
5
- import { components, dictionary, validators } from '__GENERATED__/client-manifest.js';
5
+ import { components, dictionary, matchers } from '__GENERATED__/client-manifest.js';
6
6
  import { init } from './singletons.js';
7
7
 
8
8
  /**
@@ -292,9 +292,9 @@ function parse_route_id(key) {
292
292
  * @param {RegExpMatchArray} match
293
293
  * @param {string[]} names
294
294
  * @param {string[]} types
295
- * @param {Record<string, import('types').ParamValidator>} validators
295
+ * @param {Record<string, import('types').ParamMatcher>} matchers
296
296
  */
297
- function exec(match, names, types, validators) {
297
+ function exec(match, names, types, matchers) {
298
298
  /** @type {Record<string, string>} */
299
299
  const params = {};
300
300
 
@@ -304,10 +304,10 @@ function exec(match, names, types, validators) {
304
304
  const value = match[i + 1] || '';
305
305
 
306
306
  if (type) {
307
- const validator = validators[type];
308
- if (!validator) throw new Error(`Missing "${type}" param validator`); // TODO do this ahead of time?
307
+ const matcher = matchers[type];
308
+ if (!matcher) throw new Error(`Missing "${type}" param matcher`); // TODO do this ahead of time?
309
309
 
310
- if (!validator(value)) return;
310
+ if (!matcher(value)) return;
311
311
  }
312
312
 
313
313
  params[name] = value;
@@ -319,10 +319,10 @@ function exec(match, names, types, validators) {
319
319
  /**
320
320
  * @param {import('types').CSRComponentLoader[]} components
321
321
  * @param {Record<string, [number[], number[], 1?]>} dictionary
322
- * @param {Record<string, (param: string) => boolean>} validators
322
+ * @param {Record<string, (param: string) => boolean>} matchers
323
323
  * @returns {import('types').CSRRoute[]}
324
324
  */
325
- function parse(components, dictionary, validators) {
325
+ function parse(components, dictionary, matchers) {
326
326
  const routes = Object.entries(dictionary).map(([id, [a, b, has_shadow]]) => {
327
327
  const { pattern, names, types } = parse_route_id(id);
328
328
 
@@ -331,7 +331,7 @@ function parse(components, dictionary, validators) {
331
331
  /** @param {string} path */
332
332
  exec: (path) => {
333
333
  const match = pattern.exec(path);
334
- if (match) return exec(match, names, types, validators);
334
+ if (match) return exec(match, names, types, matchers);
335
335
  },
336
336
  a: a.map((n) => components[n]),
337
337
  b: b.map((n) => components[n]),
@@ -345,7 +345,7 @@ function parse(components, dictionary, validators) {
345
345
  const SCROLL_KEY = 'sveltekit:scroll';
346
346
  const INDEX_KEY = 'sveltekit:index';
347
347
 
348
- const routes = parse(components, dictionary, validators);
348
+ const routes = parse(components, dictionary, matchers);
349
349
 
350
350
  // we import the root layout/error components eagerly, so that
351
351
  // connectivity errors after initialisation don't nuke the app
@@ -985,7 +985,7 @@ function create_client({ target, session, base, trailing_slash }) {
985
985
  // @ts-expect-error
986
986
  if (node.loaded.fallthrough) {
987
987
  throw new Error(
988
- 'fallthrough is no longer supported. Use validators instead: https://kit.svelte.dev/docs/routing#advanced-routing-validation'
988
+ 'fallthrough is no longer supported. Use matchers instead: https://kit.svelte.dev/docs/routing#advanced-routing-validation'
989
989
  );
990
990
  }
991
991
 
@@ -165,7 +165,7 @@ async function render_endpoint(event, mod) {
165
165
  // @ts-expect-error
166
166
  if (response.fallthrough) {
167
167
  throw new Error(
168
- 'fallthrough is no longer supported. Use validators instead: https://kit.svelte.dev/docs/routing#advanced-routing-validation'
168
+ 'fallthrough is no longer supported. Use matchers instead: https://kit.svelte.dev/docs/routing#advanced-routing-matching'
169
169
  );
170
170
  }
171
171
 
@@ -1872,7 +1872,7 @@ async function load_node({
1872
1872
  // @ts-expect-error
1873
1873
  if (loaded.fallthrough) {
1874
1874
  throw new Error(
1875
- 'fallthrough is no longer supported. Use validators instead: https://kit.svelte.dev/docs/routing#advanced-routing-validation'
1875
+ 'fallthrough is no longer supported. Use matchers instead: https://kit.svelte.dev/docs/routing#advanced-routing-matching'
1876
1876
  );
1877
1877
  }
1878
1878
  } else if (shadow.body) {
@@ -1949,7 +1949,7 @@ async function load_shadow_data(route, event, options, prerender) {
1949
1949
  // @ts-expect-error
1950
1950
  if (result.fallthrough) {
1951
1951
  throw new Error(
1952
- 'fallthrough is no longer supported. Use validators instead: https://kit.svelte.dev/docs/routing#advanced-routing-validation'
1952
+ 'fallthrough is no longer supported. Use matchers instead: https://kit.svelte.dev/docs/routing#advanced-routing-matching'
1953
1953
  );
1954
1954
  }
1955
1955
 
@@ -1980,7 +1980,7 @@ async function load_shadow_data(route, event, options, prerender) {
1980
1980
  // @ts-expect-error
1981
1981
  if (result.fallthrough) {
1982
1982
  throw new Error(
1983
- 'fallthrough is no longer supported. Use validators instead: https://kit.svelte.dev/docs/routing#advanced-routing-validation'
1983
+ 'fallthrough is no longer supported. Use matchers instead: https://kit.svelte.dev/docs/routing#advanced-routing-matching'
1984
1984
  );
1985
1985
  }
1986
1986
 
@@ -2504,9 +2504,9 @@ function negotiate(accept, types) {
2504
2504
  * @param {RegExpMatchArray} match
2505
2505
  * @param {string[]} names
2506
2506
  * @param {string[]} types
2507
- * @param {Record<string, import('types').ParamValidator>} validators
2507
+ * @param {Record<string, import('types').ParamMatcher>} matchers
2508
2508
  */
2509
- function exec(match, names, types, validators) {
2509
+ function exec(match, names, types, matchers) {
2510
2510
  /** @type {Record<string, string>} */
2511
2511
  const params = {};
2512
2512
 
@@ -2516,10 +2516,10 @@ function exec(match, names, types, validators) {
2516
2516
  const value = match[i + 1] || '';
2517
2517
 
2518
2518
  if (type) {
2519
- const validator = validators[type];
2520
- if (!validator) throw new Error(`Missing "${type}" param validator`); // TODO do this ahead of time?
2519
+ const matcher = matchers[type];
2520
+ if (!matcher) throw new Error(`Missing "${type}" param matcher`); // TODO do this ahead of time?
2521
2521
 
2522
- if (!validator(value)) return;
2522
+ if (!matcher(value)) return;
2523
2523
  }
2524
2524
 
2525
2525
  params[name] = value;
@@ -2581,7 +2581,7 @@ async function respond(request, options, state) {
2581
2581
  /** @type {Record<string, string>} */
2582
2582
  let params = {};
2583
2583
 
2584
- if (options.paths.base) {
2584
+ if (options.paths.base && !state.prerender?.fallback) {
2585
2585
  if (!decoded.startsWith(options.paths.base)) {
2586
2586
  return new Response(undefined, { status: 404 });
2587
2587
  }
@@ -2602,13 +2602,13 @@ async function respond(request, options, state) {
2602
2602
  }
2603
2603
 
2604
2604
  if (!state.prerender || !state.prerender.fallback) {
2605
- const validators = await options.manifest._.validators();
2605
+ const matchers = await options.manifest._.matchers();
2606
2606
 
2607
2607
  for (const candidate of options.manifest._.routes) {
2608
2608
  const match = candidate.pattern.exec(decoded);
2609
2609
  if (!match) continue;
2610
2610
 
2611
- const matched = exec(match, candidate.names, candidate.types, validators);
2611
+ const matched = exec(match, candidate.names, candidate.types, matchers);
2612
2612
  if (matched) {
2613
2613
  route = candidate;
2614
2614
  params = decode_params(matched);
@@ -149,23 +149,23 @@ async function create_plugin(config, cwd) {
149
149
  }
150
150
  };
151
151
  }),
152
- validators: async () => {
153
- /** @type {Record<string, import('types').ParamValidator>} */
154
- const validators = {};
152
+ matchers: async () => {
153
+ /** @type {Record<string, import('types').ParamMatcher>} */
154
+ const matchers = {};
155
155
 
156
- for (const key in manifest_data.validators) {
157
- const file = manifest_data.validators[key];
156
+ for (const key in manifest_data.matchers) {
157
+ const file = manifest_data.matchers[key];
158
158
  const url = path__default.resolve(cwd, file);
159
159
  const module = await vite.ssrLoadModule(url);
160
160
 
161
- if (module.validate) {
162
- validators[key] = module.validate;
161
+ if (module.match) {
162
+ matchers[key] = module.match;
163
163
  } else {
164
- throw new Error(`${file} does not export a \`validate\` function`);
164
+ throw new Error(`${file} does not export a \`match\` function`);
165
165
  }
166
166
  }
167
167
 
168
- return validators;
168
+ return matchers;
169
169
  }
170
170
  }
171
171
  };
@@ -209,7 +209,9 @@ async function create_plugin(config, cwd) {
209
209
  try {
210
210
  if (!req.url || !req.method) throw new Error('Incomplete request');
211
211
 
212
- const base = `${vite.config.server.https ? 'https' : 'http'}://${req.headers.host}`;
212
+ const base = `${vite.config.server.https ? 'https' : 'http'}://${
213
+ req.headers[':authority'] || req.headers.host
214
+ }`;
213
215
 
214
216
  const decoded = decodeURI(new URL(base + req.url).pathname);
215
217
 
@@ -434,9 +434,9 @@ async function build_server(
434
434
  input[name] = resolved;
435
435
  });
436
436
 
437
- // ...and every validator
438
- Object.entries(manifest_data.validators).forEach(([key, file]) => {
439
- const name = posixify(path__default.join('entries/validators', key));
437
+ // ...and every matcher
438
+ Object.entries(manifest_data.matchers).forEach(([key, file]) => {
439
+ const name = posixify(path__default.join('entries/matchers', key));
440
440
  input[name] = path__default.resolve(cwd, file);
441
441
  });
442
442
 
@@ -58,7 +58,7 @@ function generate_manifest({ build_data, relative_path, routes, format = 'esm' }
58
58
  /** @param {string} id */
59
59
  const get_index = (id) => id && /** @type {LookupEntry} */ (bundled_nodes.get(id)).index;
60
60
 
61
- const validators = new Set();
61
+ const matchers = new Set();
62
62
 
63
63
  // prettier-ignore
64
64
  return `{
@@ -75,7 +75,7 @@ function generate_manifest({ build_data, relative_path, routes, format = 'esm' }
75
75
  const { pattern, names, types } = parse_route_id(route.id);
76
76
 
77
77
  types.forEach(type => {
78
- if (type) validators.add(type);
78
+ if (type) matchers.add(type);
79
79
  });
80
80
 
81
81
  if (route.type === 'page') {
@@ -108,9 +108,9 @@ function generate_manifest({ build_data, relative_path, routes, format = 'esm' }
108
108
  }
109
109
  }).filter(Boolean).join(',\n\t\t\t\t')}
110
110
  ],
111
- validators: async () => {
112
- ${Array.from(validators).map(type => `const { validate: ${type} } = await ${load(`${relative_path}/entries/validators/${type}.js`)}`).join('\n\t\t\t\t')}
113
- return { ${Array.from(validators).join(', ')} };
111
+ matchers: async () => {
112
+ ${Array.from(matchers).map(type => `const { match: ${type} } = await ${load(`${relative_path}/entries/matchers/${type}.js`)}`).join('\n\t\t\t\t')}
113
+ return { ${Array.from(matchers).join(', ')} };
114
114
  }
115
115
  }
116
116
  }`.replace(/^\t/gm, '');
@@ -400,14 +400,14 @@ function create_manifest_data({
400
400
  const params_base = path__default.relative(cwd, config.kit.files.params);
401
401
 
402
402
  /** @type {Record<string, string>} */
403
- const validators = {};
403
+ const matchers = {};
404
404
  if (fs__default.existsSync(config.kit.files.params)) {
405
405
  for (const file of fs__default.readdirSync(config.kit.files.params)) {
406
406
  const ext = path__default.extname(file);
407
407
  const type = file.slice(0, -ext.length);
408
408
 
409
409
  if (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(type)) {
410
- validators[type] = path__default.join(params_base, file);
410
+ matchers[type] = path__default.join(params_base, file);
411
411
  } else {
412
412
  throw new Error(
413
413
  `Validator names must match /^[a-zA-Z_][a-zA-Z0-9_]*$/ — "${file}" is invalid`
@@ -422,7 +422,7 @@ function create_manifest_data({
422
422
  error,
423
423
  components,
424
424
  routes,
425
- validators
425
+ matchers
426
426
  };
427
427
  }
428
428
 
@@ -695,7 +695,7 @@ function write_manifest(manifest_data, base, output) {
695
695
  write_if_changed(
696
696
  `${output}/client-manifest.js`,
697
697
  trim(`
698
- export { validators } from './client-validators.js';
698
+ export { matchers } from './client-matchers.js';
699
699
 
700
700
  export const components = ${components};
701
701
 
@@ -941,7 +941,7 @@ function write_types(config, manifest_data) {
941
941
  /** @type {string[]} */
942
942
  const params = [];
943
943
 
944
- const pattern = /\[([^\]]+)\]/g;
944
+ const pattern = /\[(?:\.{3})?([^\]]+)\]/g;
945
945
  let match;
946
946
 
947
947
  while ((match = pattern.exec(key))) {
@@ -1009,20 +1009,20 @@ function write_types(config, manifest_data) {
1009
1009
  */
1010
1010
  function write_validators(manifest_data, output) {
1011
1011
  const imports = [];
1012
- const validators = [];
1012
+ const matchers = [];
1013
1013
 
1014
- for (const key in manifest_data.validators) {
1015
- const src = manifest_data.validators[key];
1014
+ for (const key in manifest_data.matchers) {
1015
+ const src = manifest_data.matchers[key];
1016
1016
 
1017
- imports.push(`import { validate as ${key} } from ${s(path__default.relative(output, src))};`);
1018
- validators.push(key);
1017
+ imports.push(`import { match as ${key} } from ${s(path__default.relative(output, src))};`);
1018
+ matchers.push(key);
1019
1019
  }
1020
1020
 
1021
1021
  const module = imports.length
1022
- ? `${imports.join('\n')}\n\nexport const validators = { ${validators.join(', ')} };`
1023
- : 'export const validators = {};';
1022
+ ? `${imports.join('\n')}\n\nexport const matchers = { ${matchers.join(', ')} };`
1023
+ : 'export const matchers = {};';
1024
1024
 
1025
- write_if_changed(`${output}/client-validators.js`, module);
1025
+ write_if_changed(`${output}/client-matchers.js`, module);
1026
1026
  }
1027
1027
 
1028
1028
  /** @param {import('types').ValidatedConfig} config */
package/dist/cli.js CHANGED
@@ -869,7 +869,7 @@ async function launch(port, https) {
869
869
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
870
870
  }
871
871
 
872
- const prog = sade('svelte-kit').version('1.0.0-next.299');
872
+ const prog = sade('svelte-kit').version('1.0.0-next.300');
873
873
 
874
874
  prog
875
875
  .command('dev')
@@ -1042,7 +1042,7 @@ async function check_port(port) {
1042
1042
  function welcome({ port, host, https, open, loose, allow, cwd }) {
1043
1043
  if (open) launch(port, https);
1044
1044
 
1045
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.299'}\n`));
1045
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.300'}\n`));
1046
1046
 
1047
1047
  const protocol = https ? 'https:' : 'http:';
1048
1048
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.299",
3
+ "version": "1.0.0-next.300",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
package/types/index.d.ts CHANGED
@@ -210,7 +210,7 @@ export interface Page<Params extends Record<string, string> = Record<string, str
210
210
  error: Error | null;
211
211
  }
212
212
 
213
- export interface ParamValidator {
213
+ export interface ParamMatcher {
214
214
  (param: string): boolean;
215
215
  }
216
216
 
@@ -257,6 +257,6 @@ export interface SSRManifest {
257
257
  };
258
258
  nodes: SSRNodeLoader[];
259
259
  routes: SSRRoute[];
260
- validators: () => Promise<Record<string, ParamValidator>>;
260
+ matchers: () => Promise<Record<string, ParamMatcher>>;
261
261
  };
262
262
  }
@@ -108,7 +108,7 @@ export interface ManifestData {
108
108
  error: string;
109
109
  components: string[];
110
110
  routes: RouteData[];
111
- validators: Record<string, string>;
111
+ matchers: Record<string, string>;
112
112
  }
113
113
 
114
114
  export interface MethodOverride {