houdini-react 1.2.12 → 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 +267 -528
  4. package/build/plugin-esm/index.js +265 -526
  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
@@ -16419,7 +16419,6 @@ var import_node_util4 = require("node:util");
16419
16419
  var graphql3 = __toESM(require("graphql"), 1);
16420
16420
  var graphql4 = __toESM(require("graphql"), 1);
16421
16421
  var graphql5 = __toESM(require("graphql"), 1);
16422
- var import_vite = require("vite");
16423
16422
  var import_meta = {};
16424
16423
  var require2 = (0, import_module.createRequire)(import_meta.url);
16425
16424
  var __create2 = Object.create;
@@ -74894,8 +74893,8 @@ function computeID(configFile, type, data) {
74894
74893
  return id.slice(0, -2);
74895
74894
  }
74896
74895
  var _configFile = null;
74897
- function localApiSessionKeys(configFile) {
74898
- return configFile.router?.auth?.sessionKeys ?? [];
74896
+ function localApiEndpoint(configFile) {
74897
+ return configFile.router?.apiEndpoint ?? "/_api";
74899
74898
  }
74900
74899
  function getCurrentConfig() {
74901
74900
  const mockConfig2 = getMockConfig();
@@ -75587,10 +75586,10 @@ var validateHeaderValue = typeof import_node_http.default.validateHeaderValue ==
75587
75586
  throw error;
75588
75587
  }
75589
75588
  };
75590
- var Headers2 = class extends URLSearchParams {
75589
+ var Headers = class extends URLSearchParams {
75591
75590
  constructor(init) {
75592
75591
  let result = [];
75593
- if (init instanceof Headers2) {
75592
+ if (init instanceof Headers) {
75594
75593
  const raw = init.raw();
75595
75594
  for (const [name, values] of Object.entries(raw)) {
75596
75595
  result.push(...values.map((value) => [name, value]));
@@ -75714,7 +75713,7 @@ var Headers2 = class extends URLSearchParams {
75714
75713
  }
75715
75714
  };
75716
75715
  Object.defineProperties(
75717
- Headers2.prototype,
75716
+ Headers.prototype,
75718
75717
  ["get", "entries", "forEach", "values"].reduce((result, property) => {
75719
75718
  result[property] = { enumerable: true };
75720
75719
  return result;
@@ -75729,7 +75728,7 @@ var Response2 = class extends Body {
75729
75728
  constructor(body = null, options = {}) {
75730
75729
  super(body, options);
75731
75730
  const status = options.status != null ? options.status : 200;
75732
- const headers = new Headers2(options.headers);
75731
+ const headers = new Headers(options.headers);
75733
75732
  if (body !== null && !headers.has("Content-Type")) {
75734
75733
  const contentType = extractContentType(body, this);
75735
75734
  if (contentType) {
@@ -75804,7 +75803,7 @@ var Response2 = class extends Body {
75804
75803
  if (body === void 0) {
75805
75804
  throw new TypeError("data is not JSON serializable");
75806
75805
  }
75807
- const headers = new Headers2(init && init.headers);
75806
+ const headers = new Headers(init && init.headers);
75808
75807
  if (!headers.has("content-type")) {
75809
75808
  headers.set("content-type", "application/json");
75810
75809
  }
@@ -75880,7 +75879,7 @@ var Request2 = class extends Body {
75880
75879
  super(inputBody, {
75881
75880
  size: init.size || input.size || 0
75882
75881
  });
75883
- const headers = new Headers2(init.headers || input.headers || {});
75882
+ const headers = new Headers(init.headers || input.headers || {});
75884
75883
  if (inputBody !== null && !headers.has("Content-Type")) {
75885
75884
  const contentType = extractContentType(inputBody, this);
75886
75885
  if (contentType) {
@@ -78239,7 +78238,7 @@ var mutation = documentPlugin(ArtifactKind.Mutation, () => {
78239
78238
  }
78240
78239
  };
78241
78240
  });
78242
- 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));
78243
78242
  var DEFAULT_CONFIG_PATH = join2(process.cwd(), "houdini.config.js");
78244
78243
  var emptySchema = graphql2.buildSchema("type Query { hello: String }");
78245
78244
  var defaultDirectives = emptySchema.getDirectives().map((dir) => dir.name);
@@ -78321,6 +78320,122 @@ function ensureImports({
78321
78320
  }
78322
78321
  return Array.isArray(importID) ? toImport : toImport[0];
78323
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
+ }
78324
78439
  var WalkerBase = class {
78325
78440
  constructor() {
78326
78441
  this.should_skip = false;
@@ -78498,6 +78613,7 @@ async function find_graphql(config2, parsedScript, walker) {
78498
78613
  }
78499
78614
  var conventions_exports = {};
78500
78615
  __export2(conventions_exports, {
78616
+ adapter_config_path: () => adapter_config_path,
78501
78617
  fallback_unit_path: () => fallback_unit_path,
78502
78618
  is_layout: () => is_layout,
78503
78619
  layout_unit_path: () => layout_unit_path,
@@ -78509,13 +78625,10 @@ __export2(conventions_exports, {
78509
78625
  read_layoutView: () => read_layoutView,
78510
78626
  read_pageQuery: () => read_pageQuery,
78511
78627
  read_pageView: () => read_pageView,
78512
- render_app_path: () => render_app_path,
78513
- render_client_path: () => render_client_path,
78514
- render_server_path: () => render_server_path,
78515
- render_yoga_path: () => render_yoga_path,
78516
78628
  router_index_path: () => router_index_path,
78517
78629
  router_path: () => router_path,
78518
- serialized_manifest_path: () => serialized_manifest_path
78630
+ serialized_manifest_path: () => serialized_manifest_path,
78631
+ server_adapter_path: () => server_adapter_path
78519
78632
  });
78520
78633
  function router_path(config2) {
78521
78634
  return path_exports.join(base_dir(config2), "Router.jsx");
@@ -78523,17 +78636,11 @@ function router_path(config2) {
78523
78636
  function page_entry_path(config2, id, base) {
78524
78637
  return path_exports.join(page_entries_dir(config2, base), `${id}.jsx`);
78525
78638
  }
78526
- function render_client_path(config2, base) {
78527
- return path_exports.join(units_dir(config2, base), "render", "client.jsx");
78528
- }
78529
- function render_server_path(config2, base) {
78639
+ function server_adapter_path(config2, base) {
78530
78640
  return path_exports.join(units_dir(config2, base), "render", "server.js");
78531
78641
  }
78532
- function render_yoga_path(config2, base) {
78533
- return path_exports.join(units_dir(config2, base), "render", "yoga.js");
78534
- }
78535
- function render_app_path(config2, base) {
78536
- 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");
78537
78644
  }
78538
78645
  function page_unit_path(config2, id, base) {
78539
78646
  return path_exports.join(page_units_dir(config2, base), `${id}.jsx`);
@@ -78839,252 +78946,13 @@ async function extractQueries(source) {
78839
78946
  }
78840
78947
  return props.filter((p) => p !== "children");
78841
78948
  }
78842
- function isViteSchemaBuild() {
78949
+ function isSecondaryBuild() {
78843
78950
  return process.env.HOUDINI_SCHEMA_BUILD === "true";
78844
78951
  }
78845
- function parse6(str, options) {
78846
- if (typeof str !== "string") {
78847
- throw new TypeError("argument str must be a string");
78848
- }
78849
- let obj = {};
78850
- let opt = options || {};
78851
- let dec = opt.decode || decode;
78852
- let index = 0;
78853
- while (index < str.length) {
78854
- let eqIdx = str.indexOf("=", index);
78855
- if (eqIdx === -1) {
78856
- break;
78857
- }
78858
- let endIdx = str.indexOf(";", index);
78859
- if (endIdx === -1) {
78860
- endIdx = str.length;
78861
- } else if (endIdx < eqIdx) {
78862
- index = str.lastIndexOf(";", eqIdx - 1) + 1;
78863
- continue;
78864
- }
78865
- let key = str.slice(index, eqIdx).trim();
78866
- if (void 0 === obj[key]) {
78867
- let val = str.slice(eqIdx + 1, endIdx).trim();
78868
- if (val.charCodeAt(0) === 34) {
78869
- val = val.slice(1, -1);
78870
- }
78871
- obj[key] = tryDecode(val, dec);
78872
- }
78873
- index = endIdx + 1;
78874
- }
78875
- return obj;
78876
- }
78877
- function decode(str) {
78878
- return str.indexOf("%") !== -1 ? decodeURIComponent(str) : str;
78879
- }
78880
- function tryDecode(str, decode3) {
78881
- try {
78882
- return decode3(str);
78883
- } catch (e2) {
78884
- return str;
78885
- }
78886
- }
78887
- function base64UrlParse(s2) {
78888
- return new Uint8Array(
78889
- Array.prototype.map.call(
78890
- atob(s2.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "")),
78891
- (c) => c.charCodeAt(0)
78892
- )
78893
- );
78894
- }
78895
- function base64UrlStringify(a) {
78896
- return btoa(String.fromCharCode.apply(0, a)).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
78897
- }
78898
- var algorithms = {
78899
- ES256: { name: "ECDSA", namedCurve: "P-256", hash: { name: "SHA-256" } },
78900
- ES384: { name: "ECDSA", namedCurve: "P-384", hash: { name: "SHA-384" } },
78901
- ES512: { name: "ECDSA", namedCurve: "P-521", hash: { name: "SHA-512" } },
78902
- HS256: { name: "HMAC", hash: { name: "SHA-256" } },
78903
- HS384: { name: "HMAC", hash: { name: "SHA-384" } },
78904
- HS512: { name: "HMAC", hash: { name: "SHA-512" } },
78905
- RS256: { name: "RSASSA-PKCS1-v1_5", hash: { name: "SHA-256" } },
78906
- RS384: { name: "RSASSA-PKCS1-v1_5", hash: { name: "SHA-384" } },
78907
- RS512: { name: "RSASSA-PKCS1-v1_5", hash: { name: "SHA-512" } }
78908
- };
78909
- function _utf8ToUint8Array(str) {
78910
- return base64UrlParse(btoa(unescape(encodeURIComponent(str))));
78911
- }
78912
- function _str2ab(str) {
78913
- str = atob(str);
78914
- const buf = new ArrayBuffer(str.length);
78915
- const bufView = new Uint8Array(buf);
78916
- for (let i2 = 0, strLen = str.length; i2 < strLen; i2++) {
78917
- bufView[i2] = str.charCodeAt(i2);
78918
- }
78919
- return buf;
78920
- }
78921
- function _decodePayload(raw) {
78922
- switch (raw.length % 4) {
78923
- case 0:
78924
- break;
78925
- case 2:
78926
- raw += "==";
78927
- break;
78928
- case 3:
78929
- raw += "=";
78930
- break;
78931
- default:
78932
- throw new Error("Illegal base64url string!");
78933
- }
78934
- try {
78935
- return JSON.parse(decodeURIComponent(escape(atob(raw))));
78936
- } catch {
78937
- return null;
78938
- }
78939
- }
78940
- async function encode(payload, secret, options = { algorithm: "HS256", header: { typ: "JWT" } }) {
78941
- if (typeof options === "string")
78942
- options = { algorithm: options, header: { typ: "JWT" } };
78943
- options = { algorithm: "HS256", header: { typ: "JWT" }, ...options };
78944
- if (payload === null || typeof payload !== "object")
78945
- throw new Error("payload must be an object");
78946
- if (typeof secret !== "string" && typeof secret !== "object")
78947
- throw new Error("secret must be a string or a JWK object");
78948
- if (typeof options.algorithm !== "string")
78949
- throw new Error("options.algorithm must be a string");
78950
- const algorithm = algorithms[options.algorithm];
78951
- if (!algorithm)
78952
- throw new Error("algorithm not found");
78953
- if (!payload.iat)
78954
- payload.iat = Math.floor(Date.now() / 1e3);
78955
- const payloadAsJSON = JSON.stringify(payload);
78956
- const partialToken = `${base64UrlStringify(
78957
- _utf8ToUint8Array(JSON.stringify({ ...options.header, alg: options.algorithm }))
78958
- )}.${base64UrlStringify(_utf8ToUint8Array(payloadAsJSON))}`;
78959
- let keyFormat = "raw";
78960
- let keyData;
78961
- if (typeof secret === "object") {
78962
- keyFormat = "jwk";
78963
- keyData = secret;
78964
- } else if (typeof secret === "string" && secret.startsWith("-----BEGIN")) {
78965
- keyFormat = "pkcs8";
78966
- keyData = _str2ab(
78967
- secret.replace(/-----BEGIN.*?-----/g, "").replace(/-----END.*?-----/g, "").replace(/\s/g, "")
78968
- );
78969
- } else
78970
- keyData = _utf8ToUint8Array(secret);
78971
- const key = await crypto.subtle.importKey(keyFormat, keyData, algorithm, false, ["sign"]);
78972
- const signature = await crypto.subtle.sign(algorithm, key, _utf8ToUint8Array(partialToken));
78973
- return `${partialToken}.${base64UrlStringify(new Uint8Array(signature))}`;
78974
- }
78975
- async function verify(token, secret, options = { algorithm: "HS256", throwError: false }) {
78976
- if (typeof options === "string")
78977
- options = { algorithm: options, throwError: false };
78978
- options = { algorithm: "HS256", throwError: false, ...options };
78979
- if (typeof token !== "string")
78980
- throw new Error("token must be a string");
78981
- if (typeof secret !== "string" && typeof secret !== "object")
78982
- throw new Error("secret must be a string or a JWK object");
78983
- if (typeof options.algorithm !== "string")
78984
- throw new Error("options.algorithm must be a string");
78985
- const tokenParts = token.split(".");
78986
- if (tokenParts.length !== 3)
78987
- throw new Error("token must consist of 3 parts");
78988
- const algorithm = algorithms[options.algorithm];
78989
- if (!algorithm)
78990
- throw new Error("algorithm not found");
78991
- const { payload } = decode2(token);
78992
- if (!payload) {
78993
- if (options.throwError)
78994
- throw "PARSE_ERROR";
78995
- return false;
78996
- }
78997
- if (payload.nbf && payload.nbf > Math.floor(Date.now() / 1e3)) {
78998
- if (options.throwError)
78999
- throw "NOT_YET_VALID";
79000
- return false;
79001
- }
79002
- if (payload.exp && payload.exp <= Math.floor(Date.now() / 1e3)) {
79003
- if (options.throwError)
79004
- throw "EXPIRED";
79005
- return false;
79006
- }
79007
- let keyFormat = "raw";
79008
- let keyData;
79009
- if (typeof secret === "object") {
79010
- keyFormat = "jwk";
79011
- keyData = secret;
79012
- } else if (typeof secret === "string" && secret.startsWith("-----BEGIN")) {
79013
- keyFormat = "spki";
79014
- keyData = _str2ab(
79015
- secret.replace(/-----BEGIN.*?-----/g, "").replace(/-----END.*?-----/g, "").replace(/\s/g, "")
79016
- );
79017
- } else
79018
- keyData = _utf8ToUint8Array(secret);
79019
- const key = await crypto.subtle.importKey(keyFormat, keyData, algorithm, false, ["verify"]);
79020
- return await crypto.subtle.verify(
79021
- algorithm,
79022
- key,
79023
- base64UrlParse(tokenParts[2]),
79024
- _utf8ToUint8Array(`${tokenParts[0]}.${tokenParts[1]}`)
79025
- );
79026
- }
79027
- function decode2(token) {
79028
- return {
79029
- header: _decodePayload(
79030
- token.split(".")[0].replace(/-/g, "+").replace(/_/g, "/")
79031
- ),
79032
- payload: _decodePayload(
79033
- token.split(".")[1].replace(/-/g, "+").replace(/_/g, "/")
79034
- )
79035
- };
79036
- }
79037
- async function handle_request(args) {
79038
- const plugin_config = args.config.router ?? {};
79039
- if (plugin_config.auth && "redirect" in plugin_config.auth && args.url.startsWith(plugin_config.auth.redirect)) {
79040
- return await redirect_auth(args);
79041
- }
79042
- args.next();
79043
- }
79044
- async function redirect_auth(args) {
79045
- const { searchParams } = new URL(args.url, `http://${args.get_header("host")}`);
79046
- const { redirectTo, ...session } = Object.fromEntries(searchParams.entries());
79047
- await set_session(args, session);
79048
- if (redirectTo) {
79049
- return args.redirect(302, redirectTo);
79050
- }
79051
- args.next();
79052
- }
79053
- var session_cookie_name = "__houdini__";
79054
- async function set_session(req, value) {
79055
- const today = new Date();
79056
- const expires = new Date(today.getTime() + 7 * 24 * 60 * 60 * 1e3);
79057
- const serialized = await encode(value, req.session_keys[0]);
79058
- req.set_header(
79059
- "Set-Cookie",
79060
- `${session_cookie_name}=${serialized}; Path=/; HttpOnly; Secure; SameSite=Lax; Expires=${expires.toUTCString()} `
79061
- );
79062
- }
79063
- async function get_session(req, secrets) {
79064
- const cookies = req.get("cookie");
79065
- if (!cookies) {
79066
- return {};
79067
- }
79068
- const cookie = parse6(cookies)[session_cookie_name];
79069
- if (!cookie) {
79070
- return {};
79071
- }
79072
- for (const secret of secrets) {
79073
- if (!await verify(cookie, secret)) {
79074
- continue;
79075
- }
79076
- const parsed = decode2(cookie);
79077
- if (!parsed) {
79078
- return {};
79079
- }
79080
- return parsed.payload;
79081
- }
79082
- return {};
79083
- }
79084
78952
 
79085
78953
  // src/plugin/index.ts
79086
78954
  var import_node_path2 = __toESM(require("node:path"));
79087
- var import_vite2 = require("vite");
78955
+ var import_vite = require("vite");
79088
78956
 
79089
78957
  // src/plugin/codegen/entries.ts
79090
78958
  async function generate_entries({
@@ -79117,7 +78985,7 @@ async function generate_routing_units(args) {
79117
78985
  const relative_path = path_exports.relative(path_exports.dirname(unit_path), page_path);
79118
78986
  const component_name = "Component_" + page.id;
79119
78987
  let source = [
79120
- "import { useQueryResult } from '$houdini/plugins/houdini-react/runtime/routing/components/Router'",
78988
+ "import { useQueryResult } from '$houdini/plugins/houdini-react/runtime/routing'",
79121
78989
  `import ${component_name} from "${relative_path}"`
79122
78990
  ];
79123
78991
  source.push(`export default ({ children }) => {
@@ -79309,52 +79177,96 @@ async function write_manifest({
79309
79177
  }
79310
79178
 
79311
79179
  // src/plugin/codegen/render.ts
79312
- async function generate_renders(config) {
79313
- await fs_exports.mkdirp(path_exports.dirname(conventions_exports.render_client_path(config)));
79314
- const app_index = `
79315
- import React from 'react'
79316
- import Shell from '../../../../../src/+index'
79317
- 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'
79318
79187
 
79319
- export default (props) => <Shell><Router {...props} /></Shell>
79320
- `;
79321
- 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 = `
79322
79204
  import React from 'react'
79323
79205
  import { renderToStream } from 'react-streaming/server'
79206
+ import { Cache } from '$houdini/runtime/cache/cache'
79207
+ import { serverAdapterFactory } from '$houdini/runtime/router/server'
79324
79208
 
79325
- import App from './App'
79326
- import { router_cache } from '$houdini'
79209
+ import { Router, router_cache } from '../../runtime'
79210
+ import manifest from '../../runtime/manifest'
79327
79211
 
79328
- export function render_to_stream({url, cache, loaded_queries, loaded_artifacts, session, assetPrefix, ...config}) {
79329
- return renderToStream(
79330
- React.createElement(App, {
79331
- initialURL: url,
79332
- cache,
79333
- ...router_cache(),
79334
- loaded_queries,
79335
- session,
79336
- loaded_artifacts,
79337
- assetPrefix,
79338
- }), config
79339
- )
79340
- }
79341
- `;
79342
- const create_yoga = `
79343
- import { createYoga } from 'graphql-yoga'
79344
- 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
+ )
79241
+
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
+ \`)
79345
79255
 
79346
- export default function({ schema = internalSchema, ...opts } = {}) {
79347
- return createYoga({
79348
- schema,
79349
- landingPage: false,
79350
- ...opts
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
+ },
79351
79264
  })
79352
79265
  }
79353
79266
  `;
79354
79267
  await Promise.all([
79355
- fs_exports.writeFile(conventions_exports.render_server_path(config), render_server),
79356
- fs_exports.writeFile(conventions_exports.render_app_path(config), app_index),
79357
- 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)
79358
79270
  ]);
79359
79271
  }
79360
79272
 
@@ -79484,130 +79396,12 @@ async function routerCodegen({
79484
79396
  }) {
79485
79397
  await Promise.all([
79486
79398
  generate_entries({ config, manifest: manifest3 }),
79487
- generate_renders(config),
79399
+ generate_renders({ config, manifest: manifest3 }),
79488
79400
  generate_type_root({ config, manifest: manifest3 }),
79489
79401
  write_manifest({ config, manifest: manifest3 })
79490
79402
  ]);
79491
79403
  }
79492
79404
 
79493
- // src/runtime/routing/lib/match.ts
79494
- var param_pattern = /^(\[)?(\.\.\.)?(\w+)(?:=(\w+))?(\])?$/;
79495
- function find_match(manifest3, current, allowNull) {
79496
- let match = null;
79497
- let matchVariables = null;
79498
- for (const page of Object.values(manifest3.pages)) {
79499
- const urlMatch = current.match(page.pattern);
79500
- if (!urlMatch) {
79501
- continue;
79502
- }
79503
- match = page;
79504
- matchVariables = exec(urlMatch, page.params) || {};
79505
- break;
79506
- }
79507
- if (!match && !allowNull) {
79508
- throw new Error("404");
79509
- }
79510
- return [match, matchVariables];
79511
- }
79512
- function parse_page_pattern(id) {
79513
- const params = [];
79514
- const pattern = id === "/" ? /^\/$/ : new RegExp(
79515
- `^${get_route_segments(id).map((segment) => {
79516
- const rest_match = /^\[\.\.\.(\w+)(?:=(\w+))?\]$/.exec(segment);
79517
- if (rest_match) {
79518
- params.push({
79519
- name: rest_match[1],
79520
- matcher: rest_match[2],
79521
- optional: false,
79522
- rest: true,
79523
- chained: true
79524
- });
79525
- return "(?:/(.*))?";
79526
- }
79527
- const optional_match = /^\[\[(\w+)(?:=(\w+))?\]\]$/.exec(segment);
79528
- if (optional_match) {
79529
- params.push({
79530
- name: optional_match[1],
79531
- matcher: optional_match[2],
79532
- optional: true,
79533
- rest: false,
79534
- chained: true
79535
- });
79536
- return "(?:/([^/]+))?";
79537
- }
79538
- if (!segment) {
79539
- return;
79540
- }
79541
- const parts = segment.split(/\[(.+?)\](?!\])/);
79542
- const result = parts.map((content, i2) => {
79543
- if (i2 % 2) {
79544
- if (content.startsWith("x+")) {
79545
- return escape2(
79546
- String.fromCharCode(parseInt(content.slice(2), 16))
79547
- );
79548
- }
79549
- if (content.startsWith("u+")) {
79550
- return escape2(
79551
- String.fromCharCode(
79552
- ...content.slice(2).split("-").map((code) => parseInt(code, 16))
79553
- )
79554
- );
79555
- }
79556
- const match = param_pattern.exec(content);
79557
- if (!match) {
79558
- throw new Error(
79559
- `Invalid param: ${content}. Params and matcher names can only have underscores and alphanumeric characters.`
79560
- );
79561
- }
79562
- const [, is_optional, is_rest, name, matcher] = match;
79563
- params.push({
79564
- name,
79565
- matcher,
79566
- optional: !!is_optional,
79567
- rest: !!is_rest,
79568
- chained: is_rest ? i2 === 1 && parts[0] === "" : false
79569
- });
79570
- return is_rest ? "(.*?)" : is_optional ? "([^/]*)?" : "([^/]+?)";
79571
- }
79572
- return escape2(content);
79573
- }).join("");
79574
- return "/" + result;
79575
- }).join("")}/?$`
79576
- );
79577
- return { pattern, params, page_id: id };
79578
- }
79579
- function affects_path(segment) {
79580
- return !/^\([^)]+\)$/.test(segment);
79581
- }
79582
- function get_route_segments(route) {
79583
- return route.slice(1).split("/").filter(affects_path);
79584
- }
79585
- function exec(match, params) {
79586
- const result = {};
79587
- const values = match.slice(1);
79588
- let buffered = "";
79589
- for (let i2 = 0; i2 < params.length; i2 += 1) {
79590
- const param = params[i2];
79591
- let value = values[i2];
79592
- if (param.chained && param.rest && buffered) {
79593
- value = value ? buffered + "/" + value : buffered;
79594
- }
79595
- buffered = "";
79596
- if (value === void 0) {
79597
- if (param.rest)
79598
- result[param.name] = "";
79599
- } else {
79600
- result[param.name] = value;
79601
- }
79602
- }
79603
- if (buffered)
79604
- return;
79605
- return result;
79606
- }
79607
- function escape2(str) {
79608
- return str.normalize().replace(/[[\]]/g, "\\$&").replace(/%/g, "%25").replace(/\//g, "%2[Ff]").replace(/\?/g, "%3[Ff]").replace(/#/g, "%23").replace(/[.*+?^${}()|\\]/g, "\\$&");
79609
- }
79610
-
79611
79405
  // src/plugin/codegen/router.ts
79612
79406
  function format_router_manifest({
79613
79407
  config,
@@ -79754,7 +79548,8 @@ var vite_default = {
79754
79548
  }
79755
79549
  }
79756
79550
  };
79757
- if (!isViteSchemaBuild()) {
79551
+ if (!isSecondaryBuild()) {
79552
+ await fs_exports.mkdirp(config.compiledAssetsDir);
79758
79553
  rollupConfig.outDir = config.compiledAssetsDir;
79759
79554
  rollupConfig.rollupOptions.input = {};
79760
79555
  for (const [id, page] of Object.entries(manifest.pages)) {
@@ -79791,7 +79586,7 @@ var vite_default = {
79791
79586
  arg = parsedPath.name;
79792
79587
  if (which === "pages") {
79793
79588
  const [id2, query_names] = arg.split("@");
79794
- const queries = query_names.split(",");
79589
+ const queries = query_names ? query_names.split(",") : [];
79795
79590
  return `
79796
79591
  import { hydrateRoot } from 'react-dom/client';
79797
79592
  import App from '$houdini/plugins/houdini-react/units/render/App'
@@ -79800,6 +79595,7 @@ var vite_default = {
79800
79595
  import client from '$houdini/plugins/houdini-react/runtime/client'
79801
79596
  import Component from '$houdini/plugins/houdini-react/units/entries/${id2}.jsx'
79802
79597
 
79598
+
79803
79599
  // if there is pending data (or artifacts) then we should prime the caches
79804
79600
  let initialData = {}
79805
79601
  let initialArtifacts = {}
@@ -79807,7 +79603,7 @@ var vite_default = {
79807
79603
  if (!window.__houdini__cache__) {
79808
79604
  window.__houdini__cache__ = new Cache()
79809
79605
  window.__houdini__hydration__layer__ = window.__houdini__cache__._internal_unstable.storage.createLayer(true)
79810
- window.__houdini__client__ = client
79606
+ window.__houdini__client__ = client()
79811
79607
  }
79812
79608
 
79813
79609
  // the artifacts are the source of the zip (without them, we can't prime either cache)
@@ -79818,7 +79614,7 @@ var vite_default = {
79818
79614
  // if we also have data for the artifact, save it in the initial data cache
79819
79615
  if (window.__houdini__pending_data__?.[artifactName]) {
79820
79616
  // create the store we'll put in the cache
79821
- 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] })
79822
79618
 
79823
79619
  // save it in the cache
79824
79620
  initialData[artifactName] = observer
@@ -79861,113 +79657,56 @@ if (window.__houdini__nav_caches__ && window.__houdini__nav_caches__.artifact_ca
79861
79657
  `;
79862
79658
  }
79863
79659
  },
79864
- configureServer(server) {
79865
- if (manifest.local_schema) {
79866
- server.middlewares.use(async (req, res, next) => {
79867
- 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)) {
79868
79675
  return next();
79869
79676
  }
79870
- let yoga;
79871
- if (manifest.local_yoga) {
79872
- 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(
79873
79683
  server.houdiniConfig.localApiDir,
79874
- "+yoga?t=" + new Date().getTime()
79875
- );
79876
- yoga = await server.ssrLoadModule(yogaPath);
79877
- } else {
79878
- const { default: schema } = await server.ssrLoadModule(
79879
- path_exports.join(
79880
- server.houdiniConfig.localApiDir,
79881
- "+schema?t=" + new Date().getTime()
79882
- )
79883
- );
79884
- const { default: createYoga } = await server.ssrLoadModule(
79885
- conventions_exports.render_yoga_path(server.houdiniConfig) + "?t=" + new Date().getTime()
79886
- );
79887
- yoga = createYoga({
79888
- schema,
79889
- graphqlEndpoint: server.houdiniConfig.localAPIUrl,
79890
- landingPage: false
79891
- });
79892
- }
79893
- return yoga(req, res, next);
79894
- });
79895
- }
79896
- server.middlewares.use(houdini_auth_routes(server));
79897
- server.middlewares.use(render_stream(server));
79898
- }
79899
- };
79900
- var houdini_auth_routes = (server) => {
79901
- return async (req, res, next) => {
79902
- if (!req.url) {
79903
- return next();
79904
- }
79905
- handle_request({
79906
- config: server.houdiniConfig.configFile,
79907
- session_keys: localApiSessionKeys(server.houdiniConfig.configFile),
79908
- next,
79909
- url: req.url,
79910
- ...res,
79911
- redirect(status = 307, url) {
79912
- res.statusCode = status;
79913
- res.setHeader("location", url);
79914
- res.setHeader("content-length", "0");
79915
- return res.end();
79916
- },
79917
- get_header: res.getHeader.bind(res),
79918
- 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);
79919
79707
  });
79920
- };
79921
- };
79922
- var render_stream = (server) => async (request, response, next) => {
79923
- if (!request.url) {
79924
- return next();
79925
- }
79926
- const { default: manifest3 } = await server.ssrLoadModule(
79927
- path_exports.join(server.houdiniConfig.pluginRuntimeDirectory("houdini-react"), "manifest.js")
79928
- );
79929
- const [match] = find_match(manifest3, request.url, true);
79930
- if (!match) {
79931
- return next();
79932
79708
  }
79933
- const session = get_session(
79934
- new Headers(request.headers),
79935
- localApiSessionKeys(server.houdiniConfig.configFile)
79936
- );
79937
- const { render_to_stream } = await load_render(server);
79938
- const cache = new Cache({ disabled: false });
79939
- const loaded_queries = {};
79940
- const loaded_artifacts = {};
79941
- const { pipe, injectToStream } = await render_to_stream({
79942
- loaded_queries,
79943
- loaded_artifacts,
79944
- url: request.url,
79945
- cache,
79946
- session,
79947
- userAgent: "Vite",
79948
- assetPrefix: "/virtual:houdini"
79949
- });
79950
- const pending_queries = Object.keys(match.documents);
79951
- const pending_query_names = pending_queries.filter((q) => !(q in loaded_queries)).join(",");
79952
- pipe?.(response);
79953
- const entry = `/virtual:houdini/pages/${match.id}@${pending_query_names}.jsx`;
79954
- injectToStream(`
79955
- <script>
79956
- window.__houdini__initial__cache__ = ${cache.serialize()};
79957
- window.__houdini__initial__session__ = ${JSON.stringify(session)};
79958
- <\/script>
79959
-
79960
- <script type="module" src="/@vite/client" async=""><\/script>
79961
-
79962
- <!-- add a virtual module that hydrates the client and sets up the initial pending cache -->
79963
- <script type="module" src="${entry}" async=""><\/script>
79964
- `);
79965
79709
  };
79966
- async function load_render(server) {
79967
- return await server.ssrLoadModule(
79968
- conventions_exports.render_server_path(server.houdiniConfig) + "?t=" + new Date().getTime()
79969
- );
79970
- }
79971
79710
 
79972
79711
  // src/plugin/index.ts
79973
79712
  var manifest2;
@@ -80009,7 +79748,7 @@ var hooks = async () => ({
80009
79748
  import_node_path2.default.join(config.projectRoot, "src", "+client")
80010
79749
  );
80011
79750
  return `${importStatement(relativePath, "client")}
80012
- ${exportDefaultStatement("client")}
79751
+ ${exportDefaultStatement("() => client")}
80013
79752
  `;
80014
79753
  },
80015
79754
  "manifest.js": ({ config, exportDefaultStatement, importStatement }) => {
@@ -80116,7 +79855,7 @@ export function useFragmentHandle(reference: { readonly "${fragmentKey}": { ${do
80116
79855
  if (_env) {
80117
79856
  return _env;
80118
79857
  }
80119
- _env = (0, import_vite2.loadEnv)("dev", config.projectRoot || ".", "");
79858
+ _env = (0, import_vite.loadEnv)("dev", config.projectRoot || ".", "");
80120
79859
  return _env;
80121
79860
  }
80122
79861
  });