houdini-react 1.2.13 → 1.2.14

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.
Files changed (56) hide show
  1. package/build/plugin/codegen/render.d.ts +5 -2
  2. package/build/plugin/vite.d.ts +8 -10
  3. package/build/plugin-cjs/index.js +263 -523
  4. package/build/plugin-esm/index.js +263 -523
  5. package/build/runtime/client.d.ts +1 -1
  6. package/build/runtime/index.d.ts +2 -9
  7. package/build/runtime/manifest.d.ts +1 -1
  8. package/build/runtime/routing/{components/Router.d.ts → Router.d.ts} +5 -9
  9. package/build/runtime/routing/index.d.ts +2 -3
  10. package/build/runtime-cjs/client.d.ts +1 -1
  11. package/build/runtime-cjs/client.js +2 -1
  12. package/build/runtime-cjs/hooks/useDocumentHandle.js +1 -1
  13. package/build/runtime-cjs/hooks/useDocumentSubscription.js +1 -1
  14. package/build/runtime-cjs/hooks/useFragment.js +5 -3
  15. package/build/runtime-cjs/hooks/useMutation.js +1 -1
  16. package/build/runtime-cjs/index.d.ts +2 -9
  17. package/build/runtime-cjs/index.js +7 -20
  18. package/build/runtime-cjs/manifest.d.ts +1 -1
  19. package/build/runtime-cjs/routing/{components/Router.d.ts → Router.d.ts} +5 -9
  20. package/build/runtime-cjs/routing/{components/Router.js → Router.js} +3 -17
  21. package/build/runtime-cjs/routing/index.d.ts +2 -3
  22. package/build/runtime-cjs/routing/index.js +2 -2
  23. package/build/runtime-esm/client.d.ts +1 -1
  24. package/build/runtime-esm/client.js +2 -1
  25. package/build/runtime-esm/hooks/useDocumentHandle.js +1 -1
  26. package/build/runtime-esm/hooks/useDocumentSubscription.js +1 -1
  27. package/build/runtime-esm/hooks/useFragment.js +4 -2
  28. package/build/runtime-esm/hooks/useMutation.js +1 -1
  29. package/build/runtime-esm/index.d.ts +2 -9
  30. package/build/runtime-esm/index.js +7 -16
  31. package/build/runtime-esm/manifest.d.ts +1 -1
  32. package/build/runtime-esm/routing/{components/Router.d.ts → Router.d.ts} +5 -9
  33. package/build/runtime-esm/routing/{components/Router.js → Router.js} +3 -17
  34. package/build/runtime-esm/routing/index.d.ts +2 -3
  35. package/build/runtime-esm/routing/index.js +2 -2
  36. package/package.json +3 -2
  37. package/build/runtime/routing/components/index.d.ts +0 -1
  38. package/build/runtime/routing/lib/match.d.ts +0 -38
  39. package/build/runtime/routing/lib/types.d.ts +0 -19
  40. package/build/runtime-cjs/routing/components/index.d.ts +0 -1
  41. package/build/runtime-cjs/routing/components/index.js +0 -34
  42. package/build/runtime-cjs/routing/lib/match.d.ts +0 -38
  43. package/build/runtime-cjs/routing/lib/match.js +0 -149
  44. package/build/runtime-cjs/routing/lib/types.d.ts +0 -19
  45. package/build/runtime-cjs/routing/lib/types.js +0 -16
  46. package/build/runtime-esm/routing/components/index.d.ts +0 -1
  47. package/build/runtime-esm/routing/components/index.js +0 -7
  48. package/build/runtime-esm/routing/lib/match.d.ts +0 -38
  49. package/build/runtime-esm/routing/lib/match.js +0 -122
  50. package/build/runtime-esm/routing/lib/types.d.ts +0 -19
  51. package/build/runtime-esm/routing/lib/types.js +0 -0
  52. /package/build/runtime/routing/{lib/cache.d.ts → cache.d.ts} +0 -0
  53. /package/build/runtime-cjs/routing/{lib/cache.d.ts → cache.d.ts} +0 -0
  54. /package/build/runtime-cjs/routing/{lib/cache.js → cache.js} +0 -0
  55. /package/build/runtime-esm/routing/{lib/cache.d.ts → cache.d.ts} +0 -0
  56. /package/build/runtime-esm/routing/{lib/cache.js → cache.js} +0 -0
@@ -74893,8 +74893,8 @@ function computeID(configFile, type, data) {
74893
74893
  return id.slice(0, -2);
74894
74894
  }
74895
74895
  var _configFile = null;
74896
- function localApiSessionKeys(configFile) {
74897
- return configFile.router?.auth?.sessionKeys ?? [];
74896
+ function localApiEndpoint(configFile) {
74897
+ return configFile.router?.apiEndpoint ?? "/_api";
74898
74898
  }
74899
74899
  function getCurrentConfig() {
74900
74900
  const mockConfig2 = getMockConfig();
@@ -75586,10 +75586,10 @@ var validateHeaderValue = typeof import_node_http.default.validateHeaderValue ==
75586
75586
  throw error;
75587
75587
  }
75588
75588
  };
75589
- var Headers2 = class extends URLSearchParams {
75589
+ var Headers = class extends URLSearchParams {
75590
75590
  constructor(init) {
75591
75591
  let result = [];
75592
- if (init instanceof Headers2) {
75592
+ if (init instanceof Headers) {
75593
75593
  const raw = init.raw();
75594
75594
  for (const [name, values] of Object.entries(raw)) {
75595
75595
  result.push(...values.map((value) => [name, value]));
@@ -75713,7 +75713,7 @@ var Headers2 = class extends URLSearchParams {
75713
75713
  }
75714
75714
  };
75715
75715
  Object.defineProperties(
75716
- Headers2.prototype,
75716
+ Headers.prototype,
75717
75717
  ["get", "entries", "forEach", "values"].reduce((result, property) => {
75718
75718
  result[property] = { enumerable: true };
75719
75719
  return result;
@@ -75728,7 +75728,7 @@ var Response2 = class extends Body {
75728
75728
  constructor(body = null, options = {}) {
75729
75729
  super(body, options);
75730
75730
  const status = options.status != null ? options.status : 200;
75731
- const headers = new Headers2(options.headers);
75731
+ const headers = new Headers(options.headers);
75732
75732
  if (body !== null && !headers.has("Content-Type")) {
75733
75733
  const contentType = extractContentType(body, this);
75734
75734
  if (contentType) {
@@ -75803,7 +75803,7 @@ var Response2 = class extends Body {
75803
75803
  if (body === void 0) {
75804
75804
  throw new TypeError("data is not JSON serializable");
75805
75805
  }
75806
- const headers = new Headers2(init && init.headers);
75806
+ const headers = new Headers(init && init.headers);
75807
75807
  if (!headers.has("content-type")) {
75808
75808
  headers.set("content-type", "application/json");
75809
75809
  }
@@ -75879,7 +75879,7 @@ var Request2 = class extends Body {
75879
75879
  super(inputBody, {
75880
75880
  size: init.size || input.size || 0
75881
75881
  });
75882
- const headers = new Headers2(init.headers || input.headers || {});
75882
+ const headers = new Headers(init.headers || input.headers || {});
75883
75883
  if (inputBody !== null && !headers.has("Content-Type")) {
75884
75884
  const contentType = extractContentType(inputBody, this);
75885
75885
  if (contentType) {
@@ -78238,7 +78238,7 @@ var mutation = documentPlugin(ArtifactKind.Mutation, () => {
78238
78238
  }
78239
78239
  };
78240
78240
  });
78241
- var currentDir = global.__dirname || dirname((0, import_node_url.fileURLToPath)(import_meta.url));
78241
+ var currentDir = dirname((0, import_node_url.fileURLToPath)(import_meta.url));
78242
78242
  var DEFAULT_CONFIG_PATH = join2(process.cwd(), "houdini.config.js");
78243
78243
  var emptySchema = graphql2.buildSchema("type Query { hello: String }");
78244
78244
  var defaultDirectives = emptySchema.getDirectives().map((dir) => dir.name);
@@ -78320,6 +78320,122 @@ function ensureImports({
78320
78320
  }
78321
78321
  return Array.isArray(importID) ? toImport : toImport[0];
78322
78322
  }
78323
+ var param_pattern = /^(\[)?(\.\.\.)?(\w+)(?:=(\w+))?(\])?$/;
78324
+ function find_match(manifest3, current, allowNull = true) {
78325
+ let match = null;
78326
+ let matchVariables = null;
78327
+ for (const page of Object.values(manifest3.pages)) {
78328
+ const urlMatch = current.match(page.pattern);
78329
+ if (!urlMatch) {
78330
+ continue;
78331
+ }
78332
+ match = page;
78333
+ matchVariables = exec(urlMatch, page.params) || {};
78334
+ break;
78335
+ }
78336
+ if (!match && !allowNull) {
78337
+ throw new Error("404");
78338
+ }
78339
+ return [match, matchVariables];
78340
+ }
78341
+ function parse_page_pattern(id) {
78342
+ const params = [];
78343
+ const pattern = id === "/" ? /^\/$/ : new RegExp(
78344
+ `^${get_route_segments(id).map((segment) => {
78345
+ const rest_match = /^\[\.\.\.(\w+)(?:=(\w+))?\]$/.exec(segment);
78346
+ if (rest_match) {
78347
+ params.push({
78348
+ name: rest_match[1],
78349
+ matcher: rest_match[2],
78350
+ optional: false,
78351
+ rest: true,
78352
+ chained: true
78353
+ });
78354
+ return "(?:/(.*))?";
78355
+ }
78356
+ const optional_match = /^\[\[(\w+)(?:=(\w+))?\]\]$/.exec(segment);
78357
+ if (optional_match) {
78358
+ params.push({
78359
+ name: optional_match[1],
78360
+ matcher: optional_match[2],
78361
+ optional: true,
78362
+ rest: false,
78363
+ chained: true
78364
+ });
78365
+ return "(?:/([^/]+))?";
78366
+ }
78367
+ if (!segment) {
78368
+ return;
78369
+ }
78370
+ const parts = segment.split(/\[(.+?)\](?!\])/);
78371
+ const result = parts.map((content, i2) => {
78372
+ if (i2 % 2) {
78373
+ if (content.startsWith("x+")) {
78374
+ return escape2(
78375
+ String.fromCharCode(parseInt(content.slice(2), 16))
78376
+ );
78377
+ }
78378
+ if (content.startsWith("u+")) {
78379
+ return escape2(
78380
+ String.fromCharCode(
78381
+ ...content.slice(2).split("-").map((code) => parseInt(code, 16))
78382
+ )
78383
+ );
78384
+ }
78385
+ const match = param_pattern.exec(content);
78386
+ if (!match) {
78387
+ throw new Error(
78388
+ `Invalid param: ${content}. Params and matcher names can only have underscores and alphanumeric characters.`
78389
+ );
78390
+ }
78391
+ const [, is_optional, is_rest, name, matcher] = match;
78392
+ params.push({
78393
+ name,
78394
+ matcher,
78395
+ optional: !!is_optional,
78396
+ rest: !!is_rest,
78397
+ chained: is_rest ? i2 === 1 && parts[0] === "" : false
78398
+ });
78399
+ return is_rest ? "(.*?)" : is_optional ? "([^/]*)?" : "([^/]+?)";
78400
+ }
78401
+ return escape2(content);
78402
+ }).join("");
78403
+ return "/" + result;
78404
+ }).join("")}/?$`
78405
+ );
78406
+ return { pattern, params, page_id: id };
78407
+ }
78408
+ function affects_path(segment) {
78409
+ return !/^\([^)]+\)$/.test(segment);
78410
+ }
78411
+ function get_route_segments(route) {
78412
+ return route.slice(1).split("/").filter(affects_path);
78413
+ }
78414
+ function exec(match, params) {
78415
+ const result = {};
78416
+ const values = match.slice(1);
78417
+ let buffered = "";
78418
+ for (let i2 = 0; i2 < params.length; i2 += 1) {
78419
+ const param = params[i2];
78420
+ let value = values[i2];
78421
+ if (param.chained && param.rest && buffered) {
78422
+ value = value ? buffered + "/" + value : buffered;
78423
+ }
78424
+ buffered = "";
78425
+ if (value === void 0) {
78426
+ if (param.rest)
78427
+ result[param.name] = "";
78428
+ } else {
78429
+ result[param.name] = value;
78430
+ }
78431
+ }
78432
+ if (buffered)
78433
+ return;
78434
+ return result;
78435
+ }
78436
+ function escape2(str) {
78437
+ return str.normalize().replace(/[[\]]/g, "\\$&").replace(/%/g, "%25").replace(/\//g, "%2[Ff]").replace(/\?/g, "%3[Ff]").replace(/#/g, "%23").replace(/[.*+?^${}()|\\]/g, "\\$&");
78438
+ }
78323
78439
  var WalkerBase = class {
78324
78440
  constructor() {
78325
78441
  this.should_skip = false;
@@ -78497,6 +78613,7 @@ async function find_graphql(config2, parsedScript, walker) {
78497
78613
  }
78498
78614
  var conventions_exports = {};
78499
78615
  __export2(conventions_exports, {
78616
+ adapter_config_path: () => adapter_config_path,
78500
78617
  fallback_unit_path: () => fallback_unit_path,
78501
78618
  is_layout: () => is_layout,
78502
78619
  layout_unit_path: () => layout_unit_path,
@@ -78508,13 +78625,10 @@ __export2(conventions_exports, {
78508
78625
  read_layoutView: () => read_layoutView,
78509
78626
  read_pageQuery: () => read_pageQuery,
78510
78627
  read_pageView: () => read_pageView,
78511
- render_app_path: () => render_app_path,
78512
- render_client_path: () => render_client_path,
78513
- render_server_path: () => render_server_path,
78514
- render_yoga_path: () => render_yoga_path,
78515
78628
  router_index_path: () => router_index_path,
78516
78629
  router_path: () => router_path,
78517
- serialized_manifest_path: () => serialized_manifest_path
78630
+ serialized_manifest_path: () => serialized_manifest_path,
78631
+ server_adapter_path: () => server_adapter_path
78518
78632
  });
78519
78633
  function router_path(config2) {
78520
78634
  return path_exports.join(base_dir(config2), "Router.jsx");
@@ -78522,17 +78636,11 @@ function router_path(config2) {
78522
78636
  function page_entry_path(config2, id, base) {
78523
78637
  return path_exports.join(page_entries_dir(config2, base), `${id}.jsx`);
78524
78638
  }
78525
- function render_client_path(config2, base) {
78526
- return path_exports.join(units_dir(config2, base), "render", "client.jsx");
78527
- }
78528
- function render_server_path(config2, base) {
78639
+ function server_adapter_path(config2, base) {
78529
78640
  return path_exports.join(units_dir(config2, base), "render", "server.js");
78530
78641
  }
78531
- function render_yoga_path(config2, base) {
78532
- return path_exports.join(units_dir(config2, base), "render", "yoga.js");
78533
- }
78534
- function render_app_path(config2, base) {
78535
- return path_exports.join(units_dir(config2, base), "render", "App.jsx");
78642
+ function adapter_config_path(config2, base) {
78643
+ return path_exports.join(units_dir(config2, base), "render", "config.js");
78536
78644
  }
78537
78645
  function page_unit_path(config2, id, base) {
78538
78646
  return path_exports.join(page_units_dir(config2, base), `${id}.jsx`);
@@ -78841,245 +78949,6 @@ async function extractQueries(source) {
78841
78949
  function isSecondaryBuild() {
78842
78950
  return process.env.HOUDINI_SCHEMA_BUILD === "true";
78843
78951
  }
78844
- function parse6(str, options) {
78845
- if (typeof str !== "string") {
78846
- throw new TypeError("argument str must be a string");
78847
- }
78848
- let obj = {};
78849
- let opt = options || {};
78850
- let dec = opt.decode || decode;
78851
- let index = 0;
78852
- while (index < str.length) {
78853
- let eqIdx = str.indexOf("=", index);
78854
- if (eqIdx === -1) {
78855
- break;
78856
- }
78857
- let endIdx = str.indexOf(";", index);
78858
- if (endIdx === -1) {
78859
- endIdx = str.length;
78860
- } else if (endIdx < eqIdx) {
78861
- index = str.lastIndexOf(";", eqIdx - 1) + 1;
78862
- continue;
78863
- }
78864
- let key = str.slice(index, eqIdx).trim();
78865
- if (void 0 === obj[key]) {
78866
- let val = str.slice(eqIdx + 1, endIdx).trim();
78867
- if (val.charCodeAt(0) === 34) {
78868
- val = val.slice(1, -1);
78869
- }
78870
- obj[key] = tryDecode(val, dec);
78871
- }
78872
- index = endIdx + 1;
78873
- }
78874
- return obj;
78875
- }
78876
- function decode(str) {
78877
- return str.indexOf("%") !== -1 ? decodeURIComponent(str) : str;
78878
- }
78879
- function tryDecode(str, decode3) {
78880
- try {
78881
- return decode3(str);
78882
- } catch (e2) {
78883
- return str;
78884
- }
78885
- }
78886
- function base64UrlParse(s2) {
78887
- return new Uint8Array(
78888
- Array.prototype.map.call(
78889
- atob(s2.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "")),
78890
- (c) => c.charCodeAt(0)
78891
- )
78892
- );
78893
- }
78894
- function base64UrlStringify(a) {
78895
- return btoa(String.fromCharCode.apply(0, a)).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
78896
- }
78897
- var algorithms = {
78898
- ES256: { name: "ECDSA", namedCurve: "P-256", hash: { name: "SHA-256" } },
78899
- ES384: { name: "ECDSA", namedCurve: "P-384", hash: { name: "SHA-384" } },
78900
- ES512: { name: "ECDSA", namedCurve: "P-521", hash: { name: "SHA-512" } },
78901
- HS256: { name: "HMAC", hash: { name: "SHA-256" } },
78902
- HS384: { name: "HMAC", hash: { name: "SHA-384" } },
78903
- HS512: { name: "HMAC", hash: { name: "SHA-512" } },
78904
- RS256: { name: "RSASSA-PKCS1-v1_5", hash: { name: "SHA-256" } },
78905
- RS384: { name: "RSASSA-PKCS1-v1_5", hash: { name: "SHA-384" } },
78906
- RS512: { name: "RSASSA-PKCS1-v1_5", hash: { name: "SHA-512" } }
78907
- };
78908
- function _utf8ToUint8Array(str) {
78909
- return base64UrlParse(btoa(unescape(encodeURIComponent(str))));
78910
- }
78911
- function _str2ab(str) {
78912
- str = atob(str);
78913
- const buf = new ArrayBuffer(str.length);
78914
- const bufView = new Uint8Array(buf);
78915
- for (let i2 = 0, strLen = str.length; i2 < strLen; i2++) {
78916
- bufView[i2] = str.charCodeAt(i2);
78917
- }
78918
- return buf;
78919
- }
78920
- function _decodePayload(raw) {
78921
- switch (raw.length % 4) {
78922
- case 0:
78923
- break;
78924
- case 2:
78925
- raw += "==";
78926
- break;
78927
- case 3:
78928
- raw += "=";
78929
- break;
78930
- default:
78931
- throw new Error("Illegal base64url string!");
78932
- }
78933
- try {
78934
- return JSON.parse(decodeURIComponent(escape(atob(raw))));
78935
- } catch {
78936
- return null;
78937
- }
78938
- }
78939
- async function encode(payload, secret, options = { algorithm: "HS256", header: { typ: "JWT" } }) {
78940
- if (typeof options === "string")
78941
- options = { algorithm: options, header: { typ: "JWT" } };
78942
- options = { algorithm: "HS256", header: { typ: "JWT" }, ...options };
78943
- if (payload === null || typeof payload !== "object")
78944
- throw new Error("payload must be an object");
78945
- if (typeof secret !== "string" && typeof secret !== "object")
78946
- throw new Error("secret must be a string or a JWK object");
78947
- if (typeof options.algorithm !== "string")
78948
- throw new Error("options.algorithm must be a string");
78949
- const algorithm = algorithms[options.algorithm];
78950
- if (!algorithm)
78951
- throw new Error("algorithm not found");
78952
- if (!payload.iat)
78953
- payload.iat = Math.floor(Date.now() / 1e3);
78954
- const payloadAsJSON = JSON.stringify(payload);
78955
- const partialToken = `${base64UrlStringify(
78956
- _utf8ToUint8Array(JSON.stringify({ ...options.header, alg: options.algorithm }))
78957
- )}.${base64UrlStringify(_utf8ToUint8Array(payloadAsJSON))}`;
78958
- let keyFormat = "raw";
78959
- let keyData;
78960
- if (typeof secret === "object") {
78961
- keyFormat = "jwk";
78962
- keyData = secret;
78963
- } else if (typeof secret === "string" && secret.startsWith("-----BEGIN")) {
78964
- keyFormat = "pkcs8";
78965
- keyData = _str2ab(
78966
- secret.replace(/-----BEGIN.*?-----/g, "").replace(/-----END.*?-----/g, "").replace(/\s/g, "")
78967
- );
78968
- } else
78969
- keyData = _utf8ToUint8Array(secret);
78970
- const key = await crypto.subtle.importKey(keyFormat, keyData, algorithm, false, ["sign"]);
78971
- const signature = await crypto.subtle.sign(algorithm, key, _utf8ToUint8Array(partialToken));
78972
- return `${partialToken}.${base64UrlStringify(new Uint8Array(signature))}`;
78973
- }
78974
- async function verify(token, secret, options = { algorithm: "HS256", throwError: false }) {
78975
- if (typeof options === "string")
78976
- options = { algorithm: options, throwError: false };
78977
- options = { algorithm: "HS256", throwError: false, ...options };
78978
- if (typeof token !== "string")
78979
- throw new Error("token must be a string");
78980
- if (typeof secret !== "string" && typeof secret !== "object")
78981
- throw new Error("secret must be a string or a JWK object");
78982
- if (typeof options.algorithm !== "string")
78983
- throw new Error("options.algorithm must be a string");
78984
- const tokenParts = token.split(".");
78985
- if (tokenParts.length !== 3)
78986
- throw new Error("token must consist of 3 parts");
78987
- const algorithm = algorithms[options.algorithm];
78988
- if (!algorithm)
78989
- throw new Error("algorithm not found");
78990
- const { payload } = decode2(token);
78991
- if (!payload) {
78992
- if (options.throwError)
78993
- throw "PARSE_ERROR";
78994
- return false;
78995
- }
78996
- if (payload.nbf && payload.nbf > Math.floor(Date.now() / 1e3)) {
78997
- if (options.throwError)
78998
- throw "NOT_YET_VALID";
78999
- return false;
79000
- }
79001
- if (payload.exp && payload.exp <= Math.floor(Date.now() / 1e3)) {
79002
- if (options.throwError)
79003
- throw "EXPIRED";
79004
- return false;
79005
- }
79006
- let keyFormat = "raw";
79007
- let keyData;
79008
- if (typeof secret === "object") {
79009
- keyFormat = "jwk";
79010
- keyData = secret;
79011
- } else if (typeof secret === "string" && secret.startsWith("-----BEGIN")) {
79012
- keyFormat = "spki";
79013
- keyData = _str2ab(
79014
- secret.replace(/-----BEGIN.*?-----/g, "").replace(/-----END.*?-----/g, "").replace(/\s/g, "")
79015
- );
79016
- } else
79017
- keyData = _utf8ToUint8Array(secret);
79018
- const key = await crypto.subtle.importKey(keyFormat, keyData, algorithm, false, ["verify"]);
79019
- return await crypto.subtle.verify(
79020
- algorithm,
79021
- key,
79022
- base64UrlParse(tokenParts[2]),
79023
- _utf8ToUint8Array(`${tokenParts[0]}.${tokenParts[1]}`)
79024
- );
79025
- }
79026
- function decode2(token) {
79027
- return {
79028
- header: _decodePayload(
79029
- token.split(".")[0].replace(/-/g, "+").replace(/_/g, "/")
79030
- ),
79031
- payload: _decodePayload(
79032
- token.split(".")[1].replace(/-/g, "+").replace(/_/g, "/")
79033
- )
79034
- };
79035
- }
79036
- async function handle_request(args) {
79037
- const plugin_config = args.config.router ?? {};
79038
- if (plugin_config.auth && "redirect" in plugin_config.auth && args.url.startsWith(plugin_config.auth.redirect)) {
79039
- return await redirect_auth(args);
79040
- }
79041
- args.next();
79042
- }
79043
- async function redirect_auth(args) {
79044
- const { searchParams } = new URL(args.url, `http://${args.get_header("host")}`);
79045
- const { redirectTo, ...session } = Object.fromEntries(searchParams.entries());
79046
- await set_session(args, session);
79047
- if (redirectTo) {
79048
- return args.redirect(302, redirectTo);
79049
- }
79050
- args.next();
79051
- }
79052
- var session_cookie_name = "__houdini__";
79053
- async function set_session(req, value) {
79054
- const today = new Date();
79055
- const expires = new Date(today.getTime() + 7 * 24 * 60 * 60 * 1e3);
79056
- const serialized = await encode(value, req.session_keys[0]);
79057
- req.set_header(
79058
- "Set-Cookie",
79059
- `${session_cookie_name}=${serialized}; Path=/; HttpOnly; Secure; SameSite=Lax; Expires=${expires.toUTCString()} `
79060
- );
79061
- }
79062
- async function get_session(req, secrets) {
79063
- const cookies = req.get("cookie");
79064
- if (!cookies) {
79065
- return {};
79066
- }
79067
- const cookie = parse6(cookies)[session_cookie_name];
79068
- if (!cookie) {
79069
- return {};
79070
- }
79071
- for (const secret of secrets) {
79072
- if (!await verify(cookie, secret)) {
79073
- continue;
79074
- }
79075
- const parsed = decode2(cookie);
79076
- if (!parsed) {
79077
- return {};
79078
- }
79079
- return parsed.payload;
79080
- }
79081
- return {};
79082
- }
79083
78952
 
79084
78953
  // src/plugin/index.ts
79085
78954
  var import_node_path2 = __toESM(require("node:path"));
@@ -79116,7 +78985,7 @@ async function generate_routing_units(args) {
79116
78985
  const relative_path = path_exports.relative(path_exports.dirname(unit_path), page_path);
79117
78986
  const component_name = "Component_" + page.id;
79118
78987
  let source = [
79119
- "import { useQueryResult } from '$houdini/plugins/houdini-react/runtime/routing/components/Router'",
78988
+ "import { useQueryResult } from '$houdini/plugins/houdini-react/runtime/routing'",
79120
78989
  `import ${component_name} from "${relative_path}"`
79121
78990
  ];
79122
78991
  source.push(`export default ({ children }) => {
@@ -79308,52 +79177,96 @@ async function write_manifest({
79308
79177
  }
79309
79178
 
79310
79179
  // src/plugin/codegen/render.ts
79311
- async function generate_renders(config) {
79312
- await fs_exports.mkdirp(path_exports.dirname(conventions_exports.render_client_path(config)));
79313
- const app_index = `
79314
- import React from 'react'
79315
- import Shell from '../../../../../src/+index'
79316
- import { Router } from '$houdini'
79180
+ async function generate_renders({
79181
+ config,
79182
+ manifest: manifest3
79183
+ }) {
79184
+ await fs_exports.mkdirp(path_exports.dirname(conventions_exports.server_adapter_path(config)));
79185
+ let adapter_config = `
79186
+ import createAdapter from './server'
79317
79187
 
79318
- export default (props) => <Shell><Router {...props} /></Shell>
79319
- `;
79320
- const render_server = `
79188
+ export const endpoint = ${JSON.stringify(localApiEndpoint(config.configFile))}
79189
+
79190
+ ${manifest3.local_schema ? `import schema from '../../../../../src/api/+schema'` : " const schema = null"}
79191
+
79192
+ ${manifest3.local_yoga ? `import yoga from '.../../../../../src/api/+yoga'` : " const yoga = null"}
79193
+
79194
+ export function createServerAdapter(options) {
79195
+ return createAdapter({
79196
+ schema,
79197
+ yoga,
79198
+ graphqlEndpoint: endpoint,
79199
+ ...options,
79200
+ })
79201
+ }
79202
+ `;
79203
+ const server_adapter = `
79321
79204
  import React from 'react'
79322
79205
  import { renderToStream } from 'react-streaming/server'
79206
+ import { Cache } from '$houdini/runtime/cache/cache'
79207
+ import { serverAdapterFactory } from '$houdini/runtime/router/server'
79323
79208
 
79324
- import App from './App'
79325
- import { router_cache } from '$houdini'
79209
+ import { Router, router_cache } from '../../runtime'
79210
+ import manifest from '../../runtime/manifest'
79326
79211
 
79327
- export function render_to_stream({url, cache, loaded_queries, loaded_artifacts, session, assetPrefix, ...config}) {
79328
- return renderToStream(
79329
- React.createElement(App, {
79330
- initialURL: url,
79331
- cache,
79332
- ...router_cache(),
79333
- loaded_queries,
79334
- session,
79335
- loaded_artifacts,
79336
- assetPrefix,
79337
- }), config
79338
- )
79339
- }
79340
- `;
79341
- const create_yoga = `
79342
- import { createYoga } from 'graphql-yoga'
79343
- import internalSchema from '../../../../../src/api/+schema'
79212
+ import Shell from '../../../../../src/+index'
79213
+
79214
+ export default (options) => {
79215
+ return serverAdapterFactory({
79216
+ manifest,
79217
+ ...options,
79218
+ on_render: async ({url, match, session, pipe , manifest }) => {
79219
+ // instanitate a cache we can use for this request
79220
+ const cache = new Cache({ disabled: false })
79221
+
79222
+ if (!match) {
79223
+ return new Response('not found', { status: 404 })
79224
+ }
79225
+
79226
+ const { readable, injectToStream, pipe: pipeTo } = await renderToStream(
79227
+ React.createElement(Shell, {
79228
+ children: React.createElement(Router, {
79229
+ initialURL: url,
79230
+ cache: cache,
79231
+ session: session,
79232
+ assetPrefix: options.assetPrefix,
79233
+ manifest: manifest,
79234
+ ...router_cache()
79235
+ })
79236
+ }),
79237
+ {
79238
+ userAgent: 'Vite',
79239
+ }
79240
+ )
79344
79241
 
79345
- export default function({ schema = internalSchema, ...opts } = {}) {
79346
- return createYoga({
79347
- schema,
79348
- landingPage: false,
79349
- ...opts
79242
+ // add the initial scripts to the page
79243
+ injectToStream(\`
79244
+ <script>
79245
+ window.__houdini__initial__cache__ = \${cache.serialize()};
79246
+ window.__houdini__initial__session__ = \${JSON.stringify(session)};
79247
+ <\/script>
79248
+
79249
+ <!--
79250
+ add a virtual module that hydrates the client and sets up the initial pending cache.
79251
+ the dynamic extension is to support dev which sees the raw jsx, and production which sees the bundled asset
79252
+ -->
79253
+ <script type="module" src="\${options.assetPrefix}/pages/\${match.id}.\${options.production ? 'js' : 'jsx'}" async=""><\/script>
79254
+ \`)
79255
+
79256
+ if (pipe && pipeTo) {
79257
+ // pipe the response to the client
79258
+ pipeTo(pipe)
79259
+ } else {
79260
+ // and deliver our Response while that's running.
79261
+ return new Response(readable)
79262
+ }
79263
+ },
79350
79264
  })
79351
79265
  }
79352
79266
  `;
79353
79267
  await Promise.all([
79354
- fs_exports.writeFile(conventions_exports.render_server_path(config), render_server),
79355
- fs_exports.writeFile(conventions_exports.render_app_path(config), app_index),
79356
- fs_exports.writeFile(conventions_exports.render_yoga_path(config), create_yoga)
79268
+ fs_exports.writeFile(conventions_exports.server_adapter_path(config), server_adapter),
79269
+ fs_exports.writeFile(conventions_exports.adapter_config_path(config), adapter_config)
79357
79270
  ]);
79358
79271
  }
79359
79272
 
@@ -79483,130 +79396,12 @@ async function routerCodegen({
79483
79396
  }) {
79484
79397
  await Promise.all([
79485
79398
  generate_entries({ config, manifest: manifest3 }),
79486
- generate_renders(config),
79399
+ generate_renders({ config, manifest: manifest3 }),
79487
79400
  generate_type_root({ config, manifest: manifest3 }),
79488
79401
  write_manifest({ config, manifest: manifest3 })
79489
79402
  ]);
79490
79403
  }
79491
79404
 
79492
- // src/runtime/routing/lib/match.ts
79493
- var param_pattern = /^(\[)?(\.\.\.)?(\w+)(?:=(\w+))?(\])?$/;
79494
- function find_match(manifest3, current, allowNull) {
79495
- let match = null;
79496
- let matchVariables = null;
79497
- for (const page of Object.values(manifest3.pages)) {
79498
- const urlMatch = current.match(page.pattern);
79499
- if (!urlMatch) {
79500
- continue;
79501
- }
79502
- match = page;
79503
- matchVariables = exec(urlMatch, page.params) || {};
79504
- break;
79505
- }
79506
- if (!match && !allowNull) {
79507
- throw new Error("404");
79508
- }
79509
- return [match, matchVariables];
79510
- }
79511
- function parse_page_pattern(id) {
79512
- const params = [];
79513
- const pattern = id === "/" ? /^\/$/ : new RegExp(
79514
- `^${get_route_segments(id).map((segment) => {
79515
- const rest_match = /^\[\.\.\.(\w+)(?:=(\w+))?\]$/.exec(segment);
79516
- if (rest_match) {
79517
- params.push({
79518
- name: rest_match[1],
79519
- matcher: rest_match[2],
79520
- optional: false,
79521
- rest: true,
79522
- chained: true
79523
- });
79524
- return "(?:/(.*))?";
79525
- }
79526
- const optional_match = /^\[\[(\w+)(?:=(\w+))?\]\]$/.exec(segment);
79527
- if (optional_match) {
79528
- params.push({
79529
- name: optional_match[1],
79530
- matcher: optional_match[2],
79531
- optional: true,
79532
- rest: false,
79533
- chained: true
79534
- });
79535
- return "(?:/([^/]+))?";
79536
- }
79537
- if (!segment) {
79538
- return;
79539
- }
79540
- const parts = segment.split(/\[(.+?)\](?!\])/);
79541
- const result = parts.map((content, i2) => {
79542
- if (i2 % 2) {
79543
- if (content.startsWith("x+")) {
79544
- return escape2(
79545
- String.fromCharCode(parseInt(content.slice(2), 16))
79546
- );
79547
- }
79548
- if (content.startsWith("u+")) {
79549
- return escape2(
79550
- String.fromCharCode(
79551
- ...content.slice(2).split("-").map((code) => parseInt(code, 16))
79552
- )
79553
- );
79554
- }
79555
- const match = param_pattern.exec(content);
79556
- if (!match) {
79557
- throw new Error(
79558
- `Invalid param: ${content}. Params and matcher names can only have underscores and alphanumeric characters.`
79559
- );
79560
- }
79561
- const [, is_optional, is_rest, name, matcher] = match;
79562
- params.push({
79563
- name,
79564
- matcher,
79565
- optional: !!is_optional,
79566
- rest: !!is_rest,
79567
- chained: is_rest ? i2 === 1 && parts[0] === "" : false
79568
- });
79569
- return is_rest ? "(.*?)" : is_optional ? "([^/]*)?" : "([^/]+?)";
79570
- }
79571
- return escape2(content);
79572
- }).join("");
79573
- return "/" + result;
79574
- }).join("")}/?$`
79575
- );
79576
- return { pattern, params, page_id: id };
79577
- }
79578
- function affects_path(segment) {
79579
- return !/^\([^)]+\)$/.test(segment);
79580
- }
79581
- function get_route_segments(route) {
79582
- return route.slice(1).split("/").filter(affects_path);
79583
- }
79584
- function exec(match, params) {
79585
- const result = {};
79586
- const values = match.slice(1);
79587
- let buffered = "";
79588
- for (let i2 = 0; i2 < params.length; i2 += 1) {
79589
- const param = params[i2];
79590
- let value = values[i2];
79591
- if (param.chained && param.rest && buffered) {
79592
- value = value ? buffered + "/" + value : buffered;
79593
- }
79594
- buffered = "";
79595
- if (value === void 0) {
79596
- if (param.rest)
79597
- result[param.name] = "";
79598
- } else {
79599
- result[param.name] = value;
79600
- }
79601
- }
79602
- if (buffered)
79603
- return;
79604
- return result;
79605
- }
79606
- function escape2(str) {
79607
- return str.normalize().replace(/[[\]]/g, "\\$&").replace(/%/g, "%25").replace(/\//g, "%2[Ff]").replace(/\?/g, "%3[Ff]").replace(/#/g, "%23").replace(/[.*+?^${}()|\\]/g, "\\$&");
79608
- }
79609
-
79610
79405
  // src/plugin/codegen/router.ts
79611
79406
  function format_router_manifest({
79612
79407
  config,
@@ -79754,6 +79549,7 @@ var vite_default = {
79754
79549
  }
79755
79550
  };
79756
79551
  if (!isSecondaryBuild()) {
79552
+ await fs_exports.mkdirp(config.compiledAssetsDir);
79757
79553
  rollupConfig.outDir = config.compiledAssetsDir;
79758
79554
  rollupConfig.rollupOptions.input = {};
79759
79555
  for (const [id, page] of Object.entries(manifest.pages)) {
@@ -79790,7 +79586,7 @@ var vite_default = {
79790
79586
  arg = parsedPath.name;
79791
79587
  if (which === "pages") {
79792
79588
  const [id2, query_names] = arg.split("@");
79793
- const queries = query_names.split(",");
79589
+ const queries = query_names ? query_names.split(",") : [];
79794
79590
  return `
79795
79591
  import { hydrateRoot } from 'react-dom/client';
79796
79592
  import App from '$houdini/plugins/houdini-react/units/render/App'
@@ -79799,6 +79595,7 @@ var vite_default = {
79799
79595
  import client from '$houdini/plugins/houdini-react/runtime/client'
79800
79596
  import Component from '$houdini/plugins/houdini-react/units/entries/${id2}.jsx'
79801
79597
 
79598
+
79802
79599
  // if there is pending data (or artifacts) then we should prime the caches
79803
79600
  let initialData = {}
79804
79601
  let initialArtifacts = {}
@@ -79806,7 +79603,7 @@ var vite_default = {
79806
79603
  if (!window.__houdini__cache__) {
79807
79604
  window.__houdini__cache__ = new Cache()
79808
79605
  window.__houdini__hydration__layer__ = window.__houdini__cache__._internal_unstable.storage.createLayer(true)
79809
- window.__houdini__client__ = client
79606
+ window.__houdini__client__ = client()
79810
79607
  }
79811
79608
 
79812
79609
  // the artifacts are the source of the zip (without them, we can't prime either cache)
@@ -79817,7 +79614,7 @@ var vite_default = {
79817
79614
  // if we also have data for the artifact, save it in the initial data cache
79818
79615
  if (window.__houdini__pending_data__?.[artifactName]) {
79819
79616
  // create the store we'll put in the cache
79820
- const observer = client.observe({ artifact, cache: window.__houdini__cache__, initialValue: window.__houdini__pending_data__[artifactName] })
79617
+ const observer = window.__houdini__client__.observe({ artifact, cache: window.__houdini__cache__, initialValue: window.__houdini__pending_data__[artifactName] })
79821
79618
 
79822
79619
  // save it in the cache
79823
79620
  initialData[artifactName] = observer
@@ -79860,113 +79657,56 @@ if (window.__houdini__nav_caches__ && window.__houdini__nav_caches__.artifact_ca
79860
79657
  `;
79861
79658
  }
79862
79659
  },
79863
- configureServer(server) {
79864
- if (manifest.local_schema) {
79865
- server.middlewares.use(async (req, res, next) => {
79866
- if (!req.url?.startsWith(server.houdiniConfig.localAPIUrl)) {
79660
+ async configureServer(server) {
79661
+ server.middlewares.use(async (req, res, next) => {
79662
+ const { default: router_manifest } = await server.ssrLoadModule(
79663
+ path_exports.join(
79664
+ server.houdiniConfig.pluginRuntimeDirectory("houdini-react"),
79665
+ "manifest.js"
79666
+ )
79667
+ );
79668
+ try {
79669
+ const [match] = find_match(router_manifest, req.url ?? "/");
79670
+ if (!match) {
79671
+ throw new Error();
79672
+ }
79673
+ } catch {
79674
+ if (req.url !== localApiEndpoint(server.houdiniConfig.configFile)) {
79867
79675
  return next();
79868
79676
  }
79869
- let yoga;
79870
- if (manifest.local_yoga) {
79871
- const yogaPath = path_exports.join(
79677
+ }
79678
+ const project_manifest = await load_manifest({ config: server.houdiniConfig });
79679
+ let schema = null;
79680
+ if (project_manifest.local_schema) {
79681
+ schema = (await server.ssrLoadModule(
79682
+ path_exports.join(
79872
79683
  server.houdiniConfig.localApiDir,
79873
- "+yoga?t=" + new Date().getTime()
79874
- );
79875
- yoga = await server.ssrLoadModule(yogaPath);
79876
- } else {
79877
- const { default: schema } = await server.ssrLoadModule(
79878
- path_exports.join(
79879
- server.houdiniConfig.localApiDir,
79880
- "+schema?t=" + new Date().getTime()
79881
- )
79882
- );
79883
- const { default: createYoga } = await server.ssrLoadModule(
79884
- conventions_exports.render_yoga_path(server.houdiniConfig) + "?t=" + new Date().getTime()
79885
- );
79886
- yoga = createYoga({
79887
- schema,
79888
- graphqlEndpoint: server.houdiniConfig.localAPIUrl,
79889
- landingPage: false
79890
- });
79891
- }
79892
- return yoga(req, res, next);
79893
- });
79894
- }
79895
- server.middlewares.use(houdini_auth_routes(server));
79896
- server.middlewares.use(render_stream(server));
79897
- }
79898
- };
79899
- var houdini_auth_routes = (server) => {
79900
- return async (req, res, next) => {
79901
- if (!req.url) {
79902
- return next();
79903
- }
79904
- handle_request({
79905
- config: server.houdiniConfig.configFile,
79906
- session_keys: localApiSessionKeys(server.houdiniConfig.configFile),
79907
- next,
79908
- url: req.url,
79909
- ...res,
79910
- redirect(status = 307, url) {
79911
- res.statusCode = status;
79912
- res.setHeader("location", url);
79913
- res.setHeader("content-length", "0");
79914
- return res.end();
79915
- },
79916
- get_header: res.getHeader.bind(res),
79917
- set_header: res.setHeader.bind(res)
79684
+ "+schema?t=" + new Date().getTime()
79685
+ )
79686
+ )).default;
79687
+ }
79688
+ const serverAdapter = (await server.ssrLoadModule(
79689
+ conventions_exports.server_adapter_path(server.houdiniConfig) + "?t=" + new Date().getTime()
79690
+ )).default;
79691
+ let yoga = null;
79692
+ if (project_manifest.local_yoga) {
79693
+ const yogaPath = path_exports.join(
79694
+ server.houdiniConfig.localApiDir,
79695
+ "+yoga?t=" + new Date().getTime()
79696
+ );
79697
+ yoga = await server.ssrLoadModule(yogaPath);
79698
+ }
79699
+ await serverAdapter({
79700
+ schema,
79701
+ yoga,
79702
+ assetPrefix: "/virtual:houdini",
79703
+ production: false,
79704
+ manifest: router_manifest,
79705
+ pipe: res
79706
+ })(req, res);
79918
79707
  });
79919
- };
79920
- };
79921
- var render_stream = (server) => async (request, response, next) => {
79922
- if (!request.url) {
79923
- return next();
79924
- }
79925
- const { default: manifest3 } = await server.ssrLoadModule(
79926
- path_exports.join(server.houdiniConfig.pluginRuntimeDirectory("houdini-react"), "manifest.js")
79927
- );
79928
- const [match] = find_match(manifest3, request.url, true);
79929
- if (!match) {
79930
- return next();
79931
79708
  }
79932
- const session = get_session(
79933
- new Headers(request.headers),
79934
- localApiSessionKeys(server.houdiniConfig.configFile)
79935
- );
79936
- const { render_to_stream } = await load_render(server);
79937
- const cache = new Cache({ disabled: false });
79938
- const loaded_queries = {};
79939
- const loaded_artifacts = {};
79940
- const { pipe, injectToStream } = await render_to_stream({
79941
- loaded_queries,
79942
- loaded_artifacts,
79943
- url: request.url,
79944
- cache,
79945
- session,
79946
- userAgent: "Vite",
79947
- assetPrefix: "/virtual:houdini"
79948
- });
79949
- const pending_queries = Object.keys(match.documents);
79950
- const pending_query_names = pending_queries.filter((q) => !(q in loaded_queries)).join(",");
79951
- pipe?.(response);
79952
- const entry = `/virtual:houdini/pages/${match.id}@${pending_query_names}.jsx`;
79953
- injectToStream(`
79954
- <script>
79955
- window.__houdini__initial__cache__ = ${cache.serialize()};
79956
- window.__houdini__initial__session__ = ${JSON.stringify(session)};
79957
- <\/script>
79958
-
79959
- <script type="module" src="/@vite/client" async=""><\/script>
79960
-
79961
- <!-- add a virtual module that hydrates the client and sets up the initial pending cache -->
79962
- <script type="module" src="${entry}" async=""><\/script>
79963
- `);
79964
79709
  };
79965
- async function load_render(server) {
79966
- return await server.ssrLoadModule(
79967
- conventions_exports.render_server_path(server.houdiniConfig) + "?t=" + new Date().getTime()
79968
- );
79969
- }
79970
79710
 
79971
79711
  // src/plugin/index.ts
79972
79712
  var manifest2;
@@ -80008,7 +79748,7 @@ var hooks = async () => ({
80008
79748
  import_node_path2.default.join(config.projectRoot, "src", "+client")
80009
79749
  );
80010
79750
  return `${importStatement(relativePath, "client")}
80011
- ${exportDefaultStatement("client")}
79751
+ ${exportDefaultStatement("() => client")}
80012
79752
  `;
80013
79753
  },
80014
79754
  "manifest.js": ({ config, exportDefaultStatement, importStatement }) => {