houdini-react 1.2.13 → 1.2.15

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 +265 -514
  4. package/build/plugin-esm/index.js +265 -514
  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,8 @@ 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,
78617
+ app_component_path: () => app_component_path,
78500
78618
  fallback_unit_path: () => fallback_unit_path,
78501
78619
  is_layout: () => is_layout,
78502
78620
  layout_unit_path: () => layout_unit_path,
@@ -78508,13 +78626,10 @@ __export2(conventions_exports, {
78508
78626
  read_layoutView: () => read_layoutView,
78509
78627
  read_pageQuery: () => read_pageQuery,
78510
78628
  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
78629
  router_index_path: () => router_index_path,
78516
78630
  router_path: () => router_path,
78517
- serialized_manifest_path: () => serialized_manifest_path
78631
+ serialized_manifest_path: () => serialized_manifest_path,
78632
+ server_adapter_path: () => server_adapter_path
78518
78633
  });
78519
78634
  function router_path(config2) {
78520
78635
  return path_exports.join(base_dir(config2), "Router.jsx");
@@ -78522,16 +78637,13 @@ function router_path(config2) {
78522
78637
  function page_entry_path(config2, id, base) {
78523
78638
  return path_exports.join(page_entries_dir(config2, base), `${id}.jsx`);
78524
78639
  }
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) {
78640
+ function server_adapter_path(config2, base) {
78529
78641
  return path_exports.join(units_dir(config2, base), "render", "server.js");
78530
78642
  }
78531
- function render_yoga_path(config2, base) {
78532
- return path_exports.join(units_dir(config2, base), "render", "yoga.js");
78643
+ function adapter_config_path(config2, base) {
78644
+ return path_exports.join(units_dir(config2, base), "render", "config.js");
78533
78645
  }
78534
- function render_app_path(config2, base) {
78646
+ function app_component_path(config2, base) {
78535
78647
  return path_exports.join(units_dir(config2, base), "render", "App.jsx");
78536
78648
  }
78537
78649
  function page_unit_path(config2, id, base) {
@@ -78841,245 +78953,6 @@ async function extractQueries(source) {
78841
78953
  function isSecondaryBuild() {
78842
78954
  return process.env.HOUDINI_SCHEMA_BUILD === "true";
78843
78955
  }
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
78956
 
79084
78957
  // src/plugin/index.ts
79085
78958
  var import_node_path2 = __toESM(require("node:path"));
@@ -79116,7 +78989,7 @@ async function generate_routing_units(args) {
79116
78989
  const relative_path = path_exports.relative(path_exports.dirname(unit_path), page_path);
79117
78990
  const component_name = "Component_" + page.id;
79118
78991
  let source = [
79119
- "import { useQueryResult } from '$houdini/plugins/houdini-react/runtime/routing/components/Router'",
78992
+ "import { useQueryResult } from '$houdini/plugins/houdini-react/runtime/routing'",
79120
78993
  `import ${component_name} from "${relative_path}"`
79121
78994
  ];
79122
78995
  source.push(`export default ({ children }) => {
@@ -79308,8 +79181,11 @@ async function write_manifest({
79308
79181
  }
79309
79182
 
79310
79183
  // 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)));
79184
+ async function generate_renders({
79185
+ config,
79186
+ manifest: manifest3
79187
+ }) {
79188
+ await fs_exports.mkdirp(path_exports.dirname(conventions_exports.server_adapter_path(config)));
79313
79189
  const app_index = `
79314
79190
  import React from 'react'
79315
79191
  import Shell from '../../../../../src/+index'
@@ -79317,43 +79193,91 @@ import { Router } from '$houdini'
79317
79193
 
79318
79194
  export default (props) => <Shell><Router {...props} /></Shell>
79319
79195
  `;
79320
- const render_server = `
79196
+ let adapter_config = `
79197
+ import createAdapter from './server'
79198
+
79199
+ export const endpoint = ${JSON.stringify(localApiEndpoint(config.configFile))}
79200
+
79201
+ ${manifest3.local_schema ? `import schema from '../../../../../src/api/+schema'` : " const schema = null"}
79202
+
79203
+ ${manifest3.local_yoga ? `import yoga from '.../../../../../src/api/+yoga'` : " const yoga = null"}
79204
+
79205
+ export function createServerAdapter(options) {
79206
+ return createAdapter({
79207
+ schema,
79208
+ yoga,
79209
+ graphqlEndpoint: endpoint,
79210
+ ...options,
79211
+ })
79212
+ }
79213
+ `;
79214
+ const server_adapter = `
79321
79215
  import React from 'react'
79322
79216
  import { renderToStream } from 'react-streaming/server'
79217
+ import { Cache } from '$houdini/runtime/cache/cache'
79218
+ import { serverAdapterFactory } from '$houdini/runtime/router/server'
79323
79219
 
79220
+ import { Router, router_cache } from '../../runtime'
79221
+ import manifest from '../../runtime/manifest'
79324
79222
  import App from './App'
79325
- import { router_cache } from '$houdini'
79326
79223
 
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'
79224
+ import Shell from '../../../../../src/+index'
79225
+
79226
+ export default (options) => {
79227
+ return serverAdapterFactory({
79228
+ manifest,
79229
+ ...options,
79230
+ on_render: async ({url, match, session, pipe , manifest }) => {
79231
+ // instanitate a cache we can use for this request
79232
+ const cache = new Cache({ disabled: false })
79233
+
79234
+ if (!match) {
79235
+ return new Response('not found', { status: 404 })
79236
+ }
79237
+
79238
+ const { readable, injectToStream, pipe: pipeTo } = await renderToStream(
79239
+ React.createElement(App, {
79240
+ initialURL: url,
79241
+ cache: cache,
79242
+ session: session,
79243
+ assetPrefix: options.assetPrefix,
79244
+ manifest: manifest,
79245
+ ...router_cache()
79246
+ }),
79247
+ {
79248
+ userAgent: 'Vite',
79249
+ }
79250
+ )
79251
+
79252
+ // add the initial scripts to the page
79253
+ injectToStream(\`
79254
+ <script>
79255
+ window.__houdini__initial__cache__ = \${cache.serialize()};
79256
+ window.__houdini__initial__session__ = \${JSON.stringify(session)};
79257
+ <\/script>
79258
+
79259
+ <!--
79260
+ add a virtual module that hydrates the client and sets up the initial pending cache.
79261
+ the dynamic extension is to support dev which sees the raw jsx, and production which sees the bundled asset
79262
+ -->
79263
+ <script type="module" src="\${options.assetPrefix}/pages/\${match.id}.\${options.production ? 'js' : 'jsx'}" async=""><\/script>
79264
+ \`)
79344
79265
 
79345
- export default function({ schema = internalSchema, ...opts } = {}) {
79346
- return createYoga({
79347
- schema,
79348
- landingPage: false,
79349
- ...opts
79266
+ if (pipe && pipeTo) {
79267
+ // pipe the response to the client
79268
+ pipeTo(pipe)
79269
+ } else {
79270
+ // and deliver our Response while that's running.
79271
+ return new Response(readable)
79272
+ }
79273
+ },
79350
79274
  })
79351
79275
  }
79352
79276
  `;
79353
79277
  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)
79278
+ fs_exports.writeFile(conventions_exports.server_adapter_path(config), server_adapter),
79279
+ fs_exports.writeFile(conventions_exports.adapter_config_path(config), adapter_config),
79280
+ fs_exports.writeFile(conventions_exports.app_component_path(config), app_index)
79357
79281
  ]);
79358
79282
  }
79359
79283
 
@@ -79483,130 +79407,12 @@ async function routerCodegen({
79483
79407
  }) {
79484
79408
  await Promise.all([
79485
79409
  generate_entries({ config, manifest: manifest3 }),
79486
- generate_renders(config),
79410
+ generate_renders({ config, manifest: manifest3 }),
79487
79411
  generate_type_root({ config, manifest: manifest3 }),
79488
79412
  write_manifest({ config, manifest: manifest3 })
79489
79413
  ]);
79490
79414
  }
79491
79415
 
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
79416
  // src/plugin/codegen/router.ts
79611
79417
  function format_router_manifest({
79612
79418
  config,
@@ -79754,6 +79560,7 @@ var vite_default = {
79754
79560
  }
79755
79561
  };
79756
79562
  if (!isSecondaryBuild()) {
79563
+ await fs_exports.mkdirp(config.compiledAssetsDir);
79757
79564
  rollupConfig.outDir = config.compiledAssetsDir;
79758
79565
  rollupConfig.rollupOptions.input = {};
79759
79566
  for (const [id, page] of Object.entries(manifest.pages)) {
@@ -79790,7 +79597,7 @@ var vite_default = {
79790
79597
  arg = parsedPath.name;
79791
79598
  if (which === "pages") {
79792
79599
  const [id2, query_names] = arg.split("@");
79793
- const queries = query_names.split(",");
79600
+ const queries = query_names ? query_names.split(",") : [];
79794
79601
  return `
79795
79602
  import { hydrateRoot } from 'react-dom/client';
79796
79603
  import App from '$houdini/plugins/houdini-react/units/render/App'
@@ -79799,6 +79606,7 @@ var vite_default = {
79799
79606
  import client from '$houdini/plugins/houdini-react/runtime/client'
79800
79607
  import Component from '$houdini/plugins/houdini-react/units/entries/${id2}.jsx'
79801
79608
 
79609
+
79802
79610
  // if there is pending data (or artifacts) then we should prime the caches
79803
79611
  let initialData = {}
79804
79612
  let initialArtifacts = {}
@@ -79806,7 +79614,7 @@ var vite_default = {
79806
79614
  if (!window.__houdini__cache__) {
79807
79615
  window.__houdini__cache__ = new Cache()
79808
79616
  window.__houdini__hydration__layer__ = window.__houdini__cache__._internal_unstable.storage.createLayer(true)
79809
- window.__houdini__client__ = client
79617
+ window.__houdini__client__ = client()
79810
79618
  }
79811
79619
 
79812
79620
  // the artifacts are the source of the zip (without them, we can't prime either cache)
@@ -79817,7 +79625,7 @@ var vite_default = {
79817
79625
  // if we also have data for the artifact, save it in the initial data cache
79818
79626
  if (window.__houdini__pending_data__?.[artifactName]) {
79819
79627
  // 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] })
79628
+ const observer = window.__houdini__client__.observe({ artifact, cache: window.__houdini__cache__, initialValue: window.__houdini__pending_data__[artifactName] })
79821
79629
 
79822
79630
  // save it in the cache
79823
79631
  initialData[artifactName] = observer
@@ -79860,113 +79668,56 @@ if (window.__houdini__nav_caches__ && window.__houdini__nav_caches__.artifact_ca
79860
79668
  `;
79861
79669
  }
79862
79670
  },
79863
- configureServer(server) {
79864
- if (manifest.local_schema) {
79865
- server.middlewares.use(async (req, res, next) => {
79866
- if (!req.url?.startsWith(server.houdiniConfig.localAPIUrl)) {
79671
+ async configureServer(server) {
79672
+ server.middlewares.use(async (req, res, next) => {
79673
+ const { default: router_manifest } = await server.ssrLoadModule(
79674
+ path_exports.join(
79675
+ server.houdiniConfig.pluginRuntimeDirectory("houdini-react"),
79676
+ "manifest.js"
79677
+ )
79678
+ );
79679
+ try {
79680
+ const [match] = find_match(router_manifest, req.url ?? "/");
79681
+ if (!match) {
79682
+ throw new Error();
79683
+ }
79684
+ } catch {
79685
+ if (req.url !== localApiEndpoint(server.houdiniConfig.configFile)) {
79867
79686
  return next();
79868
79687
  }
79869
- let yoga;
79870
- if (manifest.local_yoga) {
79871
- const yogaPath = path_exports.join(
79688
+ }
79689
+ const project_manifest = await load_manifest({ config: server.houdiniConfig });
79690
+ let schema = null;
79691
+ if (project_manifest.local_schema) {
79692
+ schema = (await server.ssrLoadModule(
79693
+ path_exports.join(
79872
79694
  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)
79695
+ "+schema?t=" + new Date().getTime()
79696
+ )
79697
+ )).default;
79698
+ }
79699
+ const serverAdapter = (await server.ssrLoadModule(
79700
+ conventions_exports.server_adapter_path(server.houdiniConfig) + "?t=" + new Date().getTime()
79701
+ )).default;
79702
+ let yoga = null;
79703
+ if (project_manifest.local_yoga) {
79704
+ const yogaPath = path_exports.join(
79705
+ server.houdiniConfig.localApiDir,
79706
+ "+yoga?t=" + new Date().getTime()
79707
+ );
79708
+ yoga = await server.ssrLoadModule(yogaPath);
79709
+ }
79710
+ await serverAdapter({
79711
+ schema,
79712
+ yoga,
79713
+ assetPrefix: "/virtual:houdini",
79714
+ production: false,
79715
+ manifest: router_manifest,
79716
+ pipe: res
79717
+ })(req, res);
79918
79718
  });
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
79719
  }
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
79720
  };
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
79721
 
79971
79722
  // src/plugin/index.ts
79972
79723
  var manifest2;
@@ -80008,7 +79759,7 @@ var hooks = async () => ({
80008
79759
  import_node_path2.default.join(config.projectRoot, "src", "+client")
80009
79760
  );
80010
79761
  return `${importStatement(relativePath, "client")}
80011
- ${exportDefaultStatement("client")}
79762
+ ${exportDefaultStatement("() => client")}
80012
79763
  `;
80013
79764
  },
80014
79765
  "manifest.js": ({ config, exportDefaultStatement, importStatement }) => {