@orieljs/framework 0.1.0-alpha.15 → 0.1.0-alpha.16

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 (68) hide show
  1. package/dist/{chunk-GCMPAXIK.js → chunk-3QHTNAMZ.js} +6 -4
  2. package/dist/{chunk-GCMPAXIK.js.map → chunk-3QHTNAMZ.js.map} +1 -1
  3. package/dist/{chunk-BKA5F3TH.js → chunk-6AXJB4CD.js} +5 -1
  4. package/dist/chunk-6AXJB4CD.js.map +1 -0
  5. package/dist/{chunk-7GPMFMS7.js → chunk-MG4YEWMV.js} +1239 -488
  6. package/dist/chunk-MG4YEWMV.js.map +1 -0
  7. package/dist/{chunk-FVI6X3VJ.js → chunk-YNDMTTWL.js} +114 -8
  8. package/dist/chunk-YNDMTTWL.js.map +1 -0
  9. package/dist/contracts.d.ts +112 -1
  10. package/dist/contracts.js +5 -1
  11. package/dist/{index.d-lffxurFs.d.ts → index.d-DA-Iu2a2.d.ts} +39 -2
  12. package/dist/index.d.ts +2780 -2137
  13. package/dist/index.js +1410 -543
  14. package/dist/index.js.map +1 -1
  15. package/dist/{jsx-runtime-Bc5KJzwb.d.ts → jsx-runtime-CenT41Y0.d.ts} +1 -1
  16. package/dist/jsx-runtime.d.ts +2 -2
  17. package/dist/jsx-runtime.js +3 -3
  18. package/dist/{testing-CVpo7aRl.d.ts → testing-B8J_HhF4.d.ts} +6 -2
  19. package/dist/testing.d.ts +2 -2
  20. package/dist/testing.js +3 -3
  21. package/docs/authentication.md +45 -3
  22. package/docs/authorization.md +2 -4
  23. package/docs/cache.md +29 -5
  24. package/docs/configuration.md +84 -7
  25. package/docs/console.md +41 -2
  26. package/docs/container.md +4 -0
  27. package/docs/csrf.md +2 -2
  28. package/docs/database.md +22 -0
  29. package/docs/deployment.md +39 -17
  30. package/docs/eloquent-factories.md +4 -3
  31. package/docs/eloquent-mutators.md +2 -1
  32. package/docs/eloquent-relationships.md +28 -3
  33. package/docs/eloquent-resources.md +253 -0
  34. package/docs/eloquent.md +41 -0
  35. package/docs/errors.md +12 -3
  36. package/docs/events.md +3 -1
  37. package/docs/facades.md +1 -0
  38. package/docs/helpers.md +33 -2
  39. package/docs/inertia.md +11 -2
  40. package/docs/installation.md +4 -2
  41. package/docs/laravel.md +71 -0
  42. package/docs/lifecycle.md +5 -2
  43. package/docs/live.md +88 -8
  44. package/docs/mail.md +28 -3
  45. package/docs/middleware.md +20 -12
  46. package/docs/navigation.json +8 -0
  47. package/docs/notifications.md +22 -0
  48. package/docs/pagination.md +4 -0
  49. package/docs/passwords.md +4 -6
  50. package/docs/providers.md +3 -5
  51. package/docs/queues.md +64 -2
  52. package/docs/requests.md +42 -3
  53. package/docs/responses.md +7 -4
  54. package/docs/routing.md +85 -7
  55. package/docs/scheduling.md +25 -0
  56. package/docs/session.md +2 -2
  57. package/docs/starter-kits.md +26 -7
  58. package/docs/storage.md +10 -4
  59. package/docs/testing.md +10 -2
  60. package/docs/two-factor.md +34 -1
  61. package/docs/upgrade.md +111 -2
  62. package/docs/validation.md +70 -9
  63. package/docs/views.md +1 -0
  64. package/docs/vite.md +2 -1
  65. package/package.json +43 -35
  66. package/dist/chunk-7GPMFMS7.js.map +0 -1
  67. package/dist/chunk-BKA5F3TH.js.map +0 -1
  68. package/dist/chunk-FVI6X3VJ.js.map +0 -1
@@ -6,16 +6,20 @@ import {
6
6
  ContainerNotAvailableError,
7
7
  ServiceProvider,
8
8
  Str,
9
+ ValidatedInput,
9
10
  currentContainer,
10
11
  facade,
11
12
  fileType_exports,
12
13
  inject,
13
- isPublicAsset
14
- } from "./chunk-FVI6X3VJ.js";
14
+ isPublicAsset,
15
+ serializeDate,
16
+ warnProcessWide
17
+ } from "./chunk-YNDMTTWL.js";
15
18
  import {
16
19
  Application,
17
20
  AuthFactory,
18
21
  BusDispatcher,
22
+ CacheManager,
19
23
  ClassNames,
20
24
  ClassRegistry,
21
25
  ConfigRepository,
@@ -34,6 +38,7 @@ import {
34
38
  LiveManager,
35
39
  LogManager,
36
40
  MailManager,
41
+ MaintenanceMode,
37
42
  MiddlewareCallbacks,
38
43
  NotificationDispatcher,
39
44
  PaginationState,
@@ -45,10 +50,11 @@ import {
45
50
  RoutingPaths,
46
51
  Session,
47
52
  UrlGenerator,
53
+ VALIDATED_INPUT,
48
54
  ValidationFactory,
49
55
  ViewFactory,
50
56
  token
51
- } from "./chunk-BKA5F3TH.js";
57
+ } from "./chunk-6AXJB4CD.js";
52
58
 
53
59
  // ../Config/dist/index.js
54
60
  import { existsSync, readFileSync } from "fs";
@@ -57,16 +63,16 @@ import { parse } from "dotenv";
57
63
  import { existsSync as existsSync2, readdirSync } from "fs";
58
64
  import { join as join2 } from "path";
59
65
  import { pathToFileURL } from "url";
60
- var kind = (value) => value === null ? "null" : Array.isArray(value) ? "array" : typeof value;
61
- var isPlainObject = (value) => {
62
- if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
63
- const proto = Object.getPrototypeOf(value);
66
+ var kind = (value2) => value2 === null ? "null" : Array.isArray(value2) ? "array" : typeof value2;
67
+ var isPlainObject = (value2) => {
68
+ if (typeof value2 !== "object" || value2 === null || Array.isArray(value2)) return false;
69
+ const proto = Object.getPrototypeOf(value2);
64
70
  return proto === Object.prototype || proto === null;
65
71
  };
66
72
  function typed(repository, key2, defaultValue, expected, check) {
67
- const value = repository.get(key2, defaultValue);
68
- if (!check(value)) throw new TypeError(`Configuration value for key [${key2}] must be ${expected}, ${kind(value)} given.`);
69
- return value;
73
+ const value2 = repository.get(key2, defaultValue);
74
+ if (!check(value2)) throw new TypeError(`Configuration value for key [${key2}] must be ${expected}, ${kind(value2)} given.`);
75
+ return value2;
70
76
  }
71
77
  var Config = facade(ConfigRepository, {
72
78
  /** Several keys at once: a list of keys, or an object of keys and their defaults. */
@@ -75,24 +81,24 @@ var Config = facade(ConfigRepository, {
75
81
  return Object.fromEntries(entries.map(([key2, fallback]) => [key2, this.get(key2, fallback)]));
76
82
  },
77
83
  /** Puts a value first in the array at `key` (creating it when missing). */
78
- prepend(key2, value) {
84
+ prepend(key2, value2) {
79
85
  const current = this.get(key2, []);
80
- this.set(key2, [value, ...Array.isArray(current) ? current : [current]]);
86
+ this.set(key2, [value2, ...Array.isArray(current) ? current : [current]]);
81
87
  },
82
88
  string(key2, defaultValue) {
83
- return typed(this, key2, defaultValue, "a string", (value) => typeof value === "string");
89
+ return typed(this, key2, defaultValue, "a string", (value2) => typeof value2 === "string");
84
90
  },
85
91
  integer(key2, defaultValue) {
86
- return typed(this, key2, defaultValue, "an integer", (value) => Number.isInteger(value));
92
+ return typed(this, key2, defaultValue, "an integer", (value2) => Number.isInteger(value2));
87
93
  },
88
94
  float(key2, defaultValue) {
89
- return typed(this, key2, defaultValue, "a float", (value) => typeof value === "number");
95
+ return typed(this, key2, defaultValue, "a float", (value2) => typeof value2 === "number");
90
96
  },
91
97
  boolean(key2, defaultValue) {
92
- return typed(this, key2, defaultValue, "a boolean", (value) => typeof value === "boolean");
98
+ return typed(this, key2, defaultValue, "a boolean", (value2) => typeof value2 === "boolean");
93
99
  },
94
100
  array(key2, defaultValue) {
95
- return typed(this, key2, defaultValue, "an array", (value) => Array.isArray(value) || isPlainObject(value));
101
+ return typed(this, key2, defaultValue, "an array", (value2) => Array.isArray(value2) || isPlainObject(value2));
96
102
  }
97
103
  });
98
104
  var Repository = class {
@@ -106,13 +112,14 @@ var Repository = class {
106
112
  get(key2, defaultValue) {
107
113
  return Arr.get(this.items, key2, defaultValue);
108
114
  }
109
- set(keyOrValues, value) {
110
- const entries = typeof keyOrValues === "string" ? [[keyOrValues, value]] : Object.entries(keyOrValues);
115
+ set(keyOrValues, value2) {
116
+ warnProcessWide("config()", "set it in a service provider's boot()");
117
+ const entries = typeof keyOrValues === "string" ? [[keyOrValues, value2]] : Object.entries(keyOrValues);
111
118
  for (const [k, v] of entries) Arr.set(this.items, k, v);
112
119
  }
113
- push(key2, value) {
120
+ push(key2, value2) {
114
121
  const current = this.get(key2, []);
115
- this.set(key2, [...Array.isArray(current) ? current : [current], value]);
122
+ this.set(key2, [...Array.isArray(current) ? current : [current], value2]);
116
123
  }
117
124
  all() {
118
125
  return this.items;
@@ -141,7 +148,18 @@ function singleQuoted(source) {
141
148
  for (const match of source.matchAll(/^[ \t]*(?:export[ \t]+)?([\w.-]+)[ \t]*=[ \t]*'/gm)) keys.add(match[1]);
142
149
  return keys;
143
150
  }
144
- function loadEnvironment(basePath) {
151
+ function envOption(argv) {
152
+ for (let i = 0; i < argv.length; i++) {
153
+ const token2 = argv[i];
154
+ if (token2 === "--") return void 0;
155
+ if (token2.startsWith("--env=")) return token2.slice("--env=".length) || void 0;
156
+ if (token2 === "--env" && argv[i + 1] !== void 0 && !argv[i + 1].startsWith("-")) return argv[i + 1];
157
+ }
158
+ return void 0;
159
+ }
160
+ function loadEnvironment(basePath, argv = process.argv.slice(2)) {
161
+ const option = envOption(argv);
162
+ if (option !== void 0) process.env.APP_ENV = option;
145
163
  const appEnv = process.env.APP_ENV;
146
164
  const specific = appEnv ? join(basePath, `.env.${appEnv}`) : void 0;
147
165
  const file = specific && existsSync(specific) ? specific : join(basePath, ".env");
@@ -149,20 +167,20 @@ function loadEnvironment(basePath) {
149
167
  const source = readFileSync(file, "utf8");
150
168
  const literal = singleQuoted(source);
151
169
  for (const [key2, raw] of Object.entries(parse(source))) {
152
- const value = literal.has(key2) ? raw : raw.replace(/\$\{([A-Za-z_][A-Za-z0-9_.]*)\}/g, (match, name) => process.env[name] ?? match);
153
- if (process.env[key2] === void 0) process.env[key2] = value;
170
+ const value2 = literal.has(key2) ? raw : raw.replace(/\$\{([A-Za-z_][A-Za-z0-9_.]*)\}/g, (match, name) => process.env[name] ?? match);
171
+ if (process.env[key2] === void 0) process.env[key2] = value2;
154
172
  }
155
173
  return file;
156
174
  }
157
175
  var CONFIG_FILE = /^(?!.*\.d\.ts$)([A-Za-z0-9_-]+)\.(ts|js|mjs)$/;
158
- function clonePlain(value) {
159
- if (Array.isArray(value)) return value.map((item) => clonePlain(item));
160
- if (typeof value === "object" && value !== null) {
161
- const proto = Object.getPrototypeOf(value);
162
- if (proto !== Object.prototype && proto !== null) return value;
163
- return Object.fromEntries(Object.entries(value).map(([key2, item]) => [key2, clonePlain(item)]));
176
+ function clonePlain(value2) {
177
+ if (Array.isArray(value2)) return value2.map((item) => clonePlain(item));
178
+ if (typeof value2 === "object" && value2 !== null) {
179
+ const proto = Object.getPrototypeOf(value2);
180
+ if (proto !== Object.prototype && proto !== null) return value2;
181
+ return Object.fromEntries(Object.entries(value2).map(([key2, item]) => [key2, clonePlain(item)]));
164
182
  }
165
- return value;
183
+ return value2;
166
184
  }
167
185
  async function loadConfiguration(configPath) {
168
186
  if (!existsSync2(configPath)) return {};
@@ -226,9 +244,9 @@ function replaceHtmlClasses(html, replace, options = {}) {
226
244
  const valueStart = quote2 === "" ? j : j + 1;
227
245
  const valueEnd = quote2 === "" ? unquotedEnd(html, valueStart) : indexOrEnd(html, quote2, valueStart);
228
246
  if (CLASS_ATTRIBUTE.test(name) || options.alpine && ALPINE_CLASS_LIST.test(name)) {
229
- const value = html.slice(valueStart, valueEnd);
230
- const renamed = value.replace(/\S+/g, replace);
231
- if (renamed !== value) {
247
+ const value2 = html.slice(valueStart, valueEnd);
248
+ const renamed = value2.replace(/\S+/g, replace);
249
+ if (renamed !== value2) {
232
250
  out += html.slice(last, valueStart) + renamed;
233
251
  last = valueEnd;
234
252
  }
@@ -254,7 +272,7 @@ function replaceHtmlClasses(html, replace, options = {}) {
254
272
  return out + html.slice(last);
255
273
  }
256
274
  var ATTRIBUTE_ESCAPES = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#039;" };
257
- var encodeAttribute = (value) => value.replace(/[&<>"']/g, (character) => ATTRIBUTE_ESCAPES[character]);
275
+ var encodeAttribute = (value2) => value2.replace(/[&<>"']/g, (character) => ATTRIBUTE_ESCAPES[character]);
258
276
  function rewriteClassExpression(expression, replace) {
259
277
  let out = "";
260
278
  let previous = "";
@@ -359,9 +377,9 @@ function indexOrEnd(html, search, from) {
359
377
  return index === -1 ? html.length : index;
360
378
  }
361
379
  var NAMED = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'", nbsp: "\xA0" };
362
- function decodeEntities(value) {
363
- if (!value.includes("&")) return value;
364
- return value.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (entity, body) => {
380
+ function decodeEntities(value2) {
381
+ if (!value2.includes("&")) return value2;
382
+ return value2.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (entity, body) => {
365
383
  if (body[0] === "#") return String.fromCodePoint(body[1] === "x" || body[1] === "X" ? Number.parseInt(body.slice(2), 16) : Number(body.slice(1)));
366
384
  return NAMED[body.toLowerCase()] ?? entity;
367
385
  });
@@ -537,7 +555,7 @@ var ViteHtml = class {
537
555
  var TRACKED = { "data-navigate-track": true };
538
556
  var CSS_PATH = /\.(css|less|sass|scss|styl|stylus|pcss|postcss)(\?[^.]*)?$/;
539
557
  var manifests = /* @__PURE__ */ new Map();
540
- var escapeAttribute = (value) => value.replace(/&/g, "&amp;").replace(/"/g, "&quot;");
558
+ var escapeAttribute = (value2) => value2.replace(/&/g, "&amp;").replace(/"/g, "&quot;");
541
559
  var Vite = class {
542
560
  constructor(app) {
543
561
  this.app = app;
@@ -773,7 +791,7 @@ var Vite = class {
773
791
  }
774
792
  /** false/null/undefined are dropped, true is a bare attribute, anything else name="value". */
775
793
  #parseAttributes(attributes) {
776
- return Object.entries(attributes).filter(([, value]) => value !== false && value !== null && value !== void 0).map(([name, value]) => value === true ? name : `${name}="${escapeAttribute(String(value))}"`);
794
+ return Object.entries(attributes).filter(([, value2]) => value2 !== false && value2 !== null && value2 !== void 0).map(([name, value2]) => value2 === true ? name : `${name}="${escapeAttribute(String(value2))}"`);
777
795
  }
778
796
  };
779
797
  function currentVite() {
@@ -802,7 +820,7 @@ var Application2 = class _Application extends Container2 {
802
820
  this.singleton(ClassNames, () => new ClassNameMap(this));
803
821
  }
804
822
  base;
805
- version = "0.1.0-alpha.15";
823
+ version = "0.1.0-alpha.16";
806
824
  providers = [];
807
825
  bootingCallbacks = [];
808
826
  bootedCallbacks = [];
@@ -857,8 +875,8 @@ var Application2 = class _Application extends Container2 {
857
875
  runningInConsole() {
858
876
  return this.inConsole;
859
877
  }
860
- setRunningInConsole(value = true) {
861
- this.inConsole = value;
878
+ setRunningInConsole(value2 = true) {
879
+ this.inConsole = value2;
862
880
  }
863
881
  async register(provider) {
864
882
  const cls = typeof provider === "function" ? provider : provider.constructor;
@@ -906,6 +924,14 @@ var Application2 = class _Application extends Container2 {
906
924
  * A callback for the end of the process (the CLI after its command, the server on SIGTERM): close DB pools, Redis
907
925
  * clients and log files. Not in Laravel, whose PHP processes end with each request.
908
926
  */
927
+ /** The maintenance mode driver `app.maintenance.driver` names, bound by the Http service provider. */
928
+ maintenanceMode() {
929
+ return this.make(MaintenanceMode);
930
+ }
931
+ /** Whether `oriel down` put the app in maintenance mode (Laravel's isDownForMaintenance()). */
932
+ async isDownForMaintenance() {
933
+ return this.bound(MaintenanceMode) ? this.make(MaintenanceMode).active() : false;
934
+ }
909
935
  onShutdown(callback) {
910
936
  this.shutdownCallbacks.push(callback);
911
937
  }
@@ -954,35 +980,21 @@ var Application2 = class _Application extends Container2 {
954
980
  }
955
981
  }
956
982
  };
957
- var ClosureKernel = class {
958
- routes = /* @__PURE__ */ new Map();
959
- on(method, path, handler) {
960
- this.routes.set(`${method.toUpperCase()} ${path}`, handler);
961
- return this;
962
- }
963
- async handle(request2) {
964
- const handler = this.routes.get(`${request2.method} ${new URL(request2.url).pathname}`);
965
- if (!handler) return new Response("Not Found", { status: 404, headers: { "content-type": "text/plain; charset=utf-8" } });
966
- return toResponse(await handler(request2));
967
- }
968
- };
969
- function toResponse(output) {
970
- if (output instanceof Response) return output;
971
- if (output === void 0 || output === null) return new Response(null, { status: 204 });
972
- if (typeof output === "string") return new Response(output, { headers: { "content-type": "text/html; charset=utf-8" } });
973
- return Response.json(output);
974
- }
975
983
 
976
984
  // ../Http/dist/index.js
977
985
  import { createReadStream } from "fs";
978
986
  import { stat } from "fs/promises";
979
987
  import { basename } from "path";
980
988
  import { Readable } from "stream";
981
- import { readFile } from "fs/promises";
989
+ import { createHmac, timingSafeEqual } from "crypto";
990
+ import { existsSync as existsSync4 } from "fs";
991
+ import { mkdir, readFile, rm, writeFile } from "fs/promises";
992
+ import { dirname } from "path";
993
+ import { readFile as readFile2 } from "fs/promises";
982
994
  import { fileURLToPath } from "url";
983
- import { existsSync as existsSync4, lstatSync, readdirSync as readdirSync2, statSync as statSync3 } from "fs";
984
- import { cp, mkdir, mkdtemp, rename, rm, writeFile } from "fs/promises";
985
- import { basename as basename2, dirname, join as join5, relative as relative2, resolve as resolve2 } from "path";
995
+ import { existsSync as existsSync23, lstatSync, readdirSync as readdirSync2, statSync as statSync3 } from "fs";
996
+ import { cp, mkdir as mkdir2, mkdtemp, rename, rm as rm2, writeFile as writeFile2 } from "fs/promises";
997
+ import { basename as basename2, dirname as dirname2, join as join5, relative as relative2, resolve as resolve2 } from "path";
986
998
  import { createReadStream as createReadStream2 } from "fs";
987
999
  import { stat as stat2 } from "fs/promises";
988
1000
  import { Readable as Readable2 } from "stream";
@@ -991,13 +1003,13 @@ import { posix } from "path";
991
1003
  import { createServer } from "http";
992
1004
  import { Readable as Readable3 } from "stream";
993
1005
  import { pipeline } from "stream/promises";
994
- import { existsSync as existsSync42 } from "fs";
995
- import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
996
- import { dirname as dirname2, resolve as resolve3 } from "path";
997
- import { existsSync as existsSync23, readFileSync as readFileSync3 } from "fs";
1006
+ import { existsSync as existsSync5 } from "fs";
1007
+ import { mkdir as mkdir3, readFile as readFile3, writeFile as writeFile3 } from "fs/promises";
1008
+ import { dirname as dirname3, resolve as resolve3 } from "path";
1009
+ import { existsSync as existsSync32, readFileSync as readFileSync3 } from "fs";
998
1010
  import { join as join23 } from "path";
999
1011
  import * as util from "util";
1000
- import { existsSync as existsSync32, statSync as statSync22, watch as watchPath } from "fs";
1012
+ import { existsSync as existsSync42, statSync as statSync22, watch as watchPath } from "fs";
1001
1013
  import { join as join32 } from "path";
1002
1014
  import { createServer as createServer2 } from "net";
1003
1015
  import { spawn as spawnProcess } from "child_process";
@@ -1054,14 +1066,14 @@ async function readBody(raw, limit) {
1054
1066
  const chunks = [];
1055
1067
  let size = 0;
1056
1068
  for (; ; ) {
1057
- const { done, value } = await reader.read();
1069
+ const { done, value: value2 } = await reader.read();
1058
1070
  if (done) break;
1059
- size += value.byteLength;
1071
+ size += value2.byteLength;
1060
1072
  if (limit !== null && size > limit) {
1061
1073
  await reader.cancel();
1062
1074
  throw new HttpException(413, "Content Too Large");
1063
1075
  }
1064
- chunks.push(value);
1076
+ chunks.push(value2);
1065
1077
  }
1066
1078
  const out = new Uint8Array(size);
1067
1079
  let offset = 0;
@@ -1105,10 +1117,10 @@ var HttpRedirectResponse = class {
1105
1117
  targetUrl;
1106
1118
  status;
1107
1119
  #headers;
1108
- with(key2, value) {
1120
+ with(key2, value2) {
1109
1121
  const session = optionalSession();
1110
1122
  if (session === void 0) return this;
1111
- if (typeof key2 === "string") session.flash(key2, value);
1123
+ if (typeof key2 === "string") session.flash(key2, value2);
1112
1124
  else for (const [name, item] of Object.entries(key2)) session.flash(name, item);
1113
1125
  return this;
1114
1126
  }
@@ -1135,14 +1147,14 @@ var HttpRedirectResponse = class {
1135
1147
  * Always a Set-Cookie header on this response (Laravel's RedirectResponse::withCookie). A bound CookieJar only
1136
1148
  * supplies the defaults (path, domain, secure, same-site); queueing would lose the cookie outside the web group.
1137
1149
  */
1138
- withCookie(name, value, minutes = 0) {
1150
+ withCookie(name, value2, minutes = 0) {
1139
1151
  const jar = optionalCookieJar();
1140
- const cookie = jar !== void 0 ? jar.make(name, value, minutes) : { name, value, minutes, path: "/", secure: false, httpOnly: true, sameSite: "lax" };
1152
+ const cookie = jar !== void 0 ? jar.make(name, value2, minutes) : { name, value: value2, minutes, path: "/", secure: false, httpOnly: true, sameSite: "lax" };
1141
1153
  this.#headers.append("Set-Cookie", serializeCookie(cookie));
1142
1154
  return this;
1143
1155
  }
1144
- header(name, value) {
1145
- this.#headers.set(name, value);
1156
+ header(name, value2) {
1157
+ this.#headers.set(name, value2);
1146
1158
  return this;
1147
1159
  }
1148
1160
  toResponse() {
@@ -1328,11 +1340,12 @@ var FormUploadedFile = class _FormUploadedFile {
1328
1340
  return inject(FilesystemManager).disk(disk).putFileAs(directory, this, name);
1329
1341
  }
1330
1342
  };
1343
+ var MAX_INPUT_NESTING = 64;
1331
1344
  var FORBIDDEN = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
1332
1345
  var INTEGER_KEY = /^(?:0|[1-9]\d*)$/;
1333
- var isPlainObject2 = (value) => {
1334
- if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
1335
- const prototype = Object.getPrototypeOf(value);
1346
+ var isPlainObject2 = (value2) => {
1347
+ if (typeof value2 !== "object" || value2 === null || Array.isArray(value2)) return false;
1348
+ const prototype = Object.getPrototypeOf(value2);
1336
1349
  return prototype === Object.prototype || prototype === null;
1337
1350
  };
1338
1351
  function parseBracketKey(name) {
@@ -1340,25 +1353,26 @@ function parseBracketKey(name) {
1340
1353
  if (open <= 0 || !name.endsWith("]")) return [name];
1341
1354
  const segments = [name.slice(0, open)];
1342
1355
  const rest = name.slice(open);
1343
- const matches2 = rest.match(/\[[^[\]]*\]/g);
1344
- if (matches2 === null || matches2.join("") !== rest) return [name];
1345
- for (const match of matches2) segments.push(match.slice(1, -1));
1356
+ const matches22 = rest.match(/\[[^[\]]*\]/g);
1357
+ if (matches22 === null || matches22.join("") !== rest) return [name];
1358
+ for (const match of matches22) segments.push(match.slice(1, -1));
1346
1359
  return segments;
1347
1360
  }
1348
- function normalizeLists(value) {
1349
- if (Array.isArray(value)) return value.map(normalizeLists);
1350
- if (!isPlainObject2(value)) return value;
1351
- const keys = Object.keys(value);
1361
+ function normalizeLists(value2) {
1362
+ if (Array.isArray(value2)) return value2.map(normalizeLists);
1363
+ if (!isPlainObject2(value2)) return value2;
1364
+ const keys = Object.keys(value2);
1352
1365
  const out = {};
1353
- for (const key2 of keys) out[key2] = normalizeLists(value[key2]);
1366
+ for (const key2 of keys) out[key2] = normalizeLists(value2[key2]);
1354
1367
  if (keys.length > 0 && keys.every((key2, index) => key2 === String(index))) return keys.map((key2) => out[key2]);
1355
1368
  return out;
1356
1369
  }
1357
1370
  function fromEntries(entries) {
1358
1371
  const root = {};
1359
1372
  const nextIndex = /* @__PURE__ */ new WeakMap();
1360
- for (const [name, value] of entries) {
1373
+ for (const [name, value2] of entries) {
1361
1374
  const segments = parseBracketKey(name);
1375
+ if (segments.length - 1 > MAX_INPUT_NESTING) throw new HttpException(400, "The request input is nested too deeply.");
1362
1376
  if (segments.some((segment) => FORBIDDEN.has(segment))) continue;
1363
1377
  let node = root;
1364
1378
  for (let i = 0; i < segments.length; i++) {
@@ -1371,7 +1385,7 @@ function fromEntries(entries) {
1371
1385
  nextIndex.set(node, Number(segment) + 1);
1372
1386
  }
1373
1387
  if (i === segments.length - 1) {
1374
- node[segment] = value;
1388
+ node[segment] = value2;
1375
1389
  break;
1376
1390
  }
1377
1391
  if (!isPlainObject2(node[segment])) node[segment] = {};
@@ -1380,38 +1394,38 @@ function fromEntries(entries) {
1380
1394
  }
1381
1395
  return normalizeLists(root);
1382
1396
  }
1383
- function sanitize(value) {
1384
- if (Array.isArray(value)) return value.map(sanitize);
1385
- if (!isPlainObject2(value)) return value;
1397
+ function sanitize(value2) {
1398
+ if (Array.isArray(value2)) return value2.map(sanitize);
1399
+ if (!isPlainObject2(value2)) return value2;
1386
1400
  const out = {};
1387
- for (const [key2, item] of Object.entries(value)) if (!FORBIDDEN.has(key2)) out[key2] = sanitize(item);
1401
+ for (const [key2, item] of Object.entries(value2)) if (!FORBIDDEN.has(key2)) out[key2] = sanitize(item);
1388
1402
  return out;
1389
1403
  }
1390
1404
  function mergeRecursive(base, override) {
1391
1405
  const out = { ...base };
1392
- for (const [key2, value] of Object.entries(override)) {
1406
+ for (const [key2, value2] of Object.entries(override)) {
1393
1407
  if (FORBIDDEN.has(key2)) continue;
1394
1408
  const current = out[key2];
1395
- out[key2] = (isPlainObject2(current) || Array.isArray(current)) && (isPlainObject2(value) || Array.isArray(value)) ? normalizeLists(mergeRecursive({ ...current }, { ...value })) : value;
1409
+ out[key2] = (isPlainObject2(current) || Array.isArray(current)) && (isPlainObject2(value2) || Array.isArray(value2)) ? normalizeLists(mergeRecursive({ ...current }, { ...value2 })) : value2;
1396
1410
  }
1397
1411
  return out;
1398
1412
  }
1399
- function isBlank(value) {
1400
- if (value === null || value === void 0) return true;
1401
- if (typeof value === "string") return value.trim() === "";
1402
- if (Array.isArray(value)) return value.length === 0;
1403
- if (isPlainObject2(value)) return Object.keys(value).length === 0;
1413
+ function isBlank(value2) {
1414
+ if (value2 === null || value2 === void 0) return true;
1415
+ if (typeof value2 === "string") return value2.trim() === "";
1416
+ if (Array.isArray(value2)) return value2.length === 0;
1417
+ if (isPlainObject2(value2)) return Object.keys(value2).length === 0;
1404
1418
  return false;
1405
1419
  }
1406
1420
  function transformLeaves(tree, transform, prefix = "") {
1407
1421
  const out = {};
1408
- for (const [key2, value] of Object.entries(tree)) out[key2] = transformValue(`${prefix}${key2}`, value, transform);
1422
+ for (const [key2, value2] of Object.entries(tree)) out[key2] = transformValue(`${prefix}${key2}`, value2, transform);
1409
1423
  return out;
1410
1424
  }
1411
- function transformValue(path, value, transform) {
1412
- if (Array.isArray(value)) return value.map((item, index) => transformValue(`${path}.${index}`, item, transform));
1413
- if (isPlainObject2(value)) return transformLeaves(value, transform, `${path}.`);
1414
- return transform(path, value);
1425
+ function transformValue(path, value2, transform) {
1426
+ if (Array.isArray(value2)) return value2.map((item, index) => transformValue(`${path}.${index}`, item, transform));
1427
+ if (isPlainObject2(value2)) return transformLeaves(value2, transform, `${path}.`);
1428
+ return transform(path, value2);
1415
1429
  }
1416
1430
  var TRUE_VALUES = /* @__PURE__ */ new Set(["1", "true", "on", "yes"]);
1417
1431
  var normalizeIp = (ip) => ip.trim().replace(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/i, "$1");
@@ -1427,11 +1441,11 @@ function ipMatches(ip, patterns) {
1427
1441
  if (!pattern.includes("/")) return normalizeIp(pattern) === address;
1428
1442
  const [range, bits] = pattern.split("/");
1429
1443
  const base = ipv4ToNumber(range);
1430
- const value = ipv4ToNumber(address);
1444
+ const value2 = ipv4ToNumber(address);
1431
1445
  const size = Number(bits);
1432
- if (base === void 0 || value === void 0 || !(size >= 0 && size <= 32)) return false;
1446
+ if (base === void 0 || value2 === void 0 || !(size >= 0 && size <= 32)) return false;
1433
1447
  const mask = size === 0 ? 0 : ~0 << 32 - size >>> 0;
1434
- return (base & mask) >>> 0 === (value & mask) >>> 0;
1448
+ return (base & mask) >>> 0 === (value2 & mask) >>> 0;
1435
1449
  });
1436
1450
  }
1437
1451
  var IncomingRequest = class {
@@ -1441,7 +1455,12 @@ var IncomingRequest = class {
1441
1455
  this.#trustedProxies = options.trustedProxies ?? [];
1442
1456
  this.#maxBodySize = options.maxBodySize === void 0 ? 8 * 1024 * 1024 : options.maxBodySize;
1443
1457
  this.#maxJsonDepth = options.maxJsonDepth === void 0 ? 512 : options.maxJsonDepth;
1444
- this.#query = fromEntries(this.#url.searchParams.entries());
1458
+ try {
1459
+ this.#query = fromEntries(this.#url.searchParams.entries());
1460
+ } catch (error) {
1461
+ this.#query = {};
1462
+ this.#inputError = error;
1463
+ }
1445
1464
  this.#method = raw.method.toUpperCase();
1446
1465
  }
1447
1466
  raw;
@@ -1456,12 +1475,16 @@ var IncomingRequest = class {
1456
1475
  #method;
1457
1476
  #cookies;
1458
1477
  #loading;
1478
+ #inputError;
1459
1479
  #userResolver;
1480
+ /** What the last validate() returned (a FormRequest's writes it too), for safe(). */
1481
+ [VALIDATED_INPUT];
1460
1482
  /** Reads and parses the body (JSON, urlencoded or multipart) once, then applies method spoofing. */
1461
1483
  load() {
1462
1484
  return this.#loading ??= this.#load();
1463
1485
  }
1464
1486
  async #load() {
1487
+ if (this.#inputError !== void 0) throw this.#inputError;
1465
1488
  const method = this.raw.method.toUpperCase();
1466
1489
  if (method !== "GET" && method !== "HEAD" && this.raw.body !== null) {
1467
1490
  const type = (this.raw.headers.get("content-type") ?? "").toLowerCase();
@@ -1483,7 +1506,8 @@ var IncomingRequest = class {
1483
1506
  } else {
1484
1507
  await this.#parseForm(await new Response(bytes, { headers: { "content-type": this.raw.headers.get("content-type") ?? "" } }).formData());
1485
1508
  }
1486
- } catch {
1509
+ } catch (error) {
1510
+ if (error instanceof HttpException) throw error;
1487
1511
  }
1488
1512
  }
1489
1513
  }
@@ -1509,15 +1533,15 @@ var IncomingRequest = class {
1509
1533
  async #parseForm(form) {
1510
1534
  const fields = [];
1511
1535
  const files = [];
1512
- for (const [name, value] of form.entries()) {
1513
- if (typeof value === "string") fields.push([name, value]);
1514
- else if (!((value.name ?? "") === "" && value.size === 0)) files.push([name, await FormUploadedFile.fromFile(value)]);
1536
+ for (const [name, value2] of form.entries()) {
1537
+ if (typeof value2 === "string") fields.push([name, value2]);
1538
+ else if (!((value2.name ?? "") === "" && value2.size === 0)) files.push([name, await FormUploadedFile.fromFile(value2)]);
1515
1539
  }
1516
1540
  this.#body = fromEntries(fields);
1517
1541
  this.#files = fromEntries(files);
1518
1542
  }
1519
- #string(value) {
1520
- return typeof value === "string" && value !== "" ? value : void 0;
1543
+ #string(value2) {
1544
+ return typeof value2 === "string" && value2 !== "" ? value2 : void 0;
1521
1545
  }
1522
1546
  method() {
1523
1547
  return this.#method;
@@ -1653,8 +1677,8 @@ var IncomingRequest = class {
1653
1677
  }
1654
1678
  /** Laravel's string(): the input as a Stringable (the default when it is missing or null): request().string('q').trim(). */
1655
1679
  string(key2, defaultValue = "") {
1656
- const value = this.input(key2);
1657
- return Str.of(value === void 0 || value === null ? defaultValue : value);
1680
+ const value2 = this.input(key2);
1681
+ return Str.of(value2 === void 0 || value2 === null ? defaultValue : value2);
1658
1682
  }
1659
1683
  /** Laravel's str(): string() under its short name. */
1660
1684
  str(key2, defaultValue = "") {
@@ -1662,19 +1686,19 @@ var IncomingRequest = class {
1662
1686
  }
1663
1687
  /** PHP's FILTER_VALIDATE_BOOLEAN: '1', 'true', 'on', 'yes' (any case) and true are true. */
1664
1688
  boolean(key2, defaultValue = false) {
1665
- const value = this.input(key2);
1666
- if (value === void 0) return defaultValue;
1667
- if (typeof value === "boolean") return value;
1668
- if (typeof value === "number") return value === 1;
1669
- return typeof value === "string" && TRUE_VALUES.has(value.trim().toLowerCase());
1689
+ const value2 = this.input(key2);
1690
+ if (value2 === void 0) return defaultValue;
1691
+ if (typeof value2 === "boolean") return value2;
1692
+ if (typeof value2 === "number") return value2 === 1;
1693
+ return typeof value2 === "string" && TRUE_VALUES.has(value2.trim().toLowerCase());
1670
1694
  }
1671
1695
  /** PHP's intval: leading digits, else 0. */
1672
1696
  integer(key2, defaultValue = 0) {
1673
- const value = this.input(key2);
1674
- if (value === void 0) return defaultValue;
1675
- if (typeof value === "number") return Number.isFinite(value) ? Math.trunc(value) : 0;
1676
- if (typeof value === "boolean") return value ? 1 : 0;
1677
- const parsed = Number.parseInt(String(value).trim(), 10);
1697
+ const value2 = this.input(key2);
1698
+ if (value2 === void 0) return defaultValue;
1699
+ if (typeof value2 === "number") return Number.isFinite(value2) ? Math.trunc(value2) : 0;
1700
+ if (typeof value2 === "boolean") return value2 ? 1 : 0;
1701
+ const parsed = Number.parseInt(String(value2).trim(), 10);
1678
1702
  return Number.isNaN(parsed) ? 0 : parsed;
1679
1703
  }
1680
1704
  /** Adds or replaces top-level body values. */
@@ -1689,12 +1713,12 @@ var IncomingRequest = class {
1689
1713
  return this;
1690
1714
  }
1691
1715
  file(key2) {
1692
- const value = Arr.get(this.#files, key2);
1693
- return value instanceof FormUploadedFile ? value : void 0;
1716
+ const value2 = Arr.get(this.#files, key2);
1717
+ return value2 instanceof FormUploadedFile ? value2 : void 0;
1694
1718
  }
1695
1719
  hasFile(key2) {
1696
- const value = Arr.get(this.#files, key2);
1697
- return value instanceof FormUploadedFile || Array.isArray(value) && value.some((item) => item instanceof FormUploadedFile);
1720
+ const value2 = Arr.get(this.#files, key2);
1721
+ return value2 instanceof FormUploadedFile || Array.isArray(value2) && value2.some((item) => item instanceof FormUploadedFile);
1698
1722
  }
1699
1723
  allFiles() {
1700
1724
  return { ...this.#files };
@@ -1710,12 +1734,12 @@ var IncomingRequest = class {
1710
1734
  if (index === -1) continue;
1711
1735
  const name = part.slice(0, index).trim();
1712
1736
  if (name === "" || Object.hasOwn(cookies, name)) continue;
1713
- let value = part.slice(index + 1).trim();
1714
- if (value.startsWith('"') && value.endsWith('"')) value = value.slice(1, -1);
1737
+ let value2 = part.slice(index + 1).trim();
1738
+ if (value2.startsWith('"') && value2.endsWith('"')) value2 = value2.slice(1, -1);
1715
1739
  try {
1716
- cookies[name] = decodeURIComponent(value);
1740
+ cookies[name] = decodeURIComponent(value2);
1717
1741
  } catch {
1718
- cookies[name] = value;
1742
+ cookies[name] = value2;
1719
1743
  }
1720
1744
  }
1721
1745
  this.#cookies = cookies;
@@ -1752,7 +1776,16 @@ var IncomingRequest = class {
1752
1776
  * rules: `validate({ title: 'required|string' })` is `{ title: string }`.
1753
1777
  */
1754
1778
  validate(rules, messages, attributes) {
1755
- return inject(ValidationFactory).make(this.all(), rules, messages, attributes).validated();
1779
+ return inject(ValidationFactory).make(this.all(), rules, messages, attributes).validated().then((data) => {
1780
+ this[VALIDATED_INPUT] = data;
1781
+ return data;
1782
+ });
1783
+ }
1784
+ /** What the last validate() (this one, or a FormRequest's) returned, as a ValidatedInput; throws before any. */
1785
+ safe() {
1786
+ const data = this[VALIDATED_INPUT];
1787
+ if (data === void 0) throw new HttpServerError("safe() reads what validate() returned: validate the request first.");
1788
+ return new ValidatedInput(data);
1756
1789
  }
1757
1790
  #currentRoute() {
1758
1791
  const container2 = currentContainer();
@@ -1761,8 +1794,8 @@ var IncomingRequest = class {
1761
1794
  };
1762
1795
  function structuredCloneInput(tree) {
1763
1796
  const out = {};
1764
- for (const [key2, value] of Object.entries(tree)) {
1765
- out[key2] = isPlainObject2(value) ? structuredCloneInput(value) : Array.isArray(value) ? [...value] : value;
1797
+ for (const [key2, value2] of Object.entries(tree)) {
1798
+ out[key2] = isPlainObject2(value2) ? structuredCloneInput(value2) : Array.isArray(value2) ? [...value2] : value2;
1766
1799
  }
1767
1800
  return out;
1768
1801
  }
@@ -1846,32 +1879,282 @@ var HttpResponseFactory = class {
1846
1879
  return new Response(body, { status: 200, headers: merged });
1847
1880
  }
1848
1881
  };
1849
- var ConvertEmptyStringsToNull = class {
1882
+ var TRIM = /^[\s\uFEFF\u200B\u200E]+|[\s\uFEFF\u200B\u200E]+$/g;
1883
+ var TrimStrings = class _TrimStrings {
1884
+ static #skip = [];
1885
+ /** Dotted input keys left untouched. Override in a subclass to change. */
1886
+ except = ["current_password", "password", "password_confirmation"];
1887
+ /** Leaves a request untouched when the callback returns true, in every app until flushState() (Laravel's skipWhen()). */
1888
+ static skipWhen(callback) {
1889
+ _TrimStrings.#skip.push(callback);
1890
+ }
1891
+ /** Forgets the skipWhen() callbacks. */
1892
+ static flushState() {
1893
+ _TrimStrings.#skip = [];
1894
+ }
1850
1895
  async handle(request2, next) {
1851
- if (request2 instanceof IncomingRequest) request2.transformInput((_key, value) => value === "" ? null : value);
1896
+ if (request2 instanceof IncomingRequest) {
1897
+ const configured = configuredExceptions("http.trim_strings_except");
1898
+ const skips = [..._TrimStrings.#skip, ...configured.filter((entry) => typeof entry === "function")];
1899
+ if (!skips.some((skip) => skip(request2))) {
1900
+ const except = [...this.except, ...configured.filter((entry) => typeof entry === "string")];
1901
+ request2.transformInput((key2, value2) => typeof value2 === "string" && !except.includes(key2) ? value2.replace(TRIM, "") : value2);
1902
+ }
1903
+ }
1852
1904
  return next(request2);
1853
1905
  }
1854
1906
  };
1855
- var TRIM = /^[\s\uFEFF\u200B\u200E]+|[\s\uFEFF\u200B\u200E]+$/g;
1856
- var TrimStrings = class {
1857
- /** Dotted input keys left untouched. Override in a subclass to change. */
1858
- except = ["current_password", "password", "password_confirmation"];
1907
+ function configuredExceptions(key2) {
1908
+ const container2 = currentContainer();
1909
+ if (container2 === void 0 || !container2.bound(ConfigRepository)) return [];
1910
+ return container2.make(ConfigRepository).get(key2, []) ?? [];
1911
+ }
1912
+ var ConvertEmptyStringsToNull = class _ConvertEmptyStringsToNull {
1913
+ static #skip = [];
1914
+ /** Leaves a request untouched when the callback returns true, in every app until flushState() (Laravel's skipWhen()). */
1915
+ static skipWhen(callback) {
1916
+ _ConvertEmptyStringsToNull.#skip.push(callback);
1917
+ }
1918
+ /** Forgets the skipWhen() callbacks. */
1919
+ static flushState() {
1920
+ _ConvertEmptyStringsToNull.#skip = [];
1921
+ }
1859
1922
  async handle(request2, next) {
1860
1923
  if (request2 instanceof IncomingRequest) {
1861
- request2.transformInput(
1862
- (key2, value) => typeof value === "string" && !this.except.includes(key2) ? value.replace(TRIM, "") : value
1863
- );
1924
+ const configured = configuredExceptions("http.convert_empty_strings_except").filter((entry) => typeof entry === "function");
1925
+ if (![..._ConvertEmptyStringsToNull.#skip, ...configured].some((skip) => skip(request2))) {
1926
+ request2.transformInput((_key, value2) => value2 === "" ? null : value2);
1927
+ }
1864
1928
  }
1865
1929
  return next(request2);
1866
1930
  }
1867
1931
  };
1932
+ var CORS_DEFAULTS = {
1933
+ paths: ["api/*"],
1934
+ allowed_methods: ["*"],
1935
+ allowed_origins: ["*"],
1936
+ allowed_origins_patterns: [],
1937
+ allowed_headers: ["*"],
1938
+ exposed_headers: [],
1939
+ max_age: 0,
1940
+ supports_credentials: false
1941
+ };
1942
+ var CORS_CONFIG_STUB = `export default {
1943
+ paths: ['api/*'],
1944
+ allowed_methods: ['*'],
1945
+ allowed_origins: ['*'],
1946
+ allowed_origins_patterns: [],
1947
+ allowed_headers: ['*'],
1948
+ exposed_headers: [],
1949
+ max_age: 0,
1950
+ supports_credentials: false,
1951
+ }
1952
+ `;
1953
+ var HandleCors = class {
1954
+ async handle(request2, next) {
1955
+ const options = corsOptions();
1956
+ if (!options.paths.some((path) => matches(request2, path))) return next(request2);
1957
+ const cors = new Cors(options);
1958
+ if (request2.method() === "OPTIONS" && request2.header("access-control-request-method") !== void 0) {
1959
+ const headers2 = new Headers();
1960
+ cors.preflightHeaders(request2, headers2);
1961
+ vary(headers2, "Access-Control-Request-Method");
1962
+ return new Response(null, { status: 204, headers: headers2 });
1963
+ }
1964
+ const response2 = await next(request2);
1965
+ const headers = new Headers();
1966
+ if (request2.method() === "OPTIONS") vary(headers, "Access-Control-Request-Method");
1967
+ cors.actualHeaders(request2, headers);
1968
+ return withHeaders(response2, headers);
1969
+ }
1970
+ };
1971
+ function corsOptions() {
1972
+ const container2 = currentContainer();
1973
+ const configured = container2?.bound(ConfigRepository) ? container2.make(ConfigRepository).get("cors") : void 0;
1974
+ return { ...CORS_DEFAULTS, ...configured };
1975
+ }
1976
+ function matches(request2, path) {
1977
+ const pattern = path === "/" ? path : path.replace(/^\/+|\/+$/g, "");
1978
+ return request2.is(pattern) || request2.fullUrl() === path;
1979
+ }
1980
+ var wildcard = (origin) => new RegExp(`^${origin.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\\\*/g, ".*")}$`, "u");
1981
+ var Cors = class {
1982
+ constructor(options) {
1983
+ this.options = options;
1984
+ this.#allowAllOrigins = options.allowed_origins.includes("*");
1985
+ this.#origins = options.allowed_origins.filter((origin) => !origin.includes("*"));
1986
+ this.#patterns = [
1987
+ ...options.allowed_origins.filter((origin) => origin !== "*" && origin.includes("*")).map(wildcard),
1988
+ ...options.allowed_origins_patterns.map((pattern) => pattern instanceof RegExp ? pattern : new RegExp(pattern, "u"))
1989
+ ];
1990
+ }
1991
+ options;
1992
+ #allowAllOrigins;
1993
+ #origins;
1994
+ #patterns;
1995
+ preflightHeaders(request2, headers) {
1996
+ this.#origin(request2, headers);
1997
+ if (!headers.has("access-control-allow-origin")) return;
1998
+ this.#credentials(headers);
1999
+ this.#methods(request2, headers);
2000
+ this.#allowedHeaders(request2, headers);
2001
+ if (this.options.max_age !== null && this.options.max_age !== void 0) {
2002
+ headers.set("Access-Control-Max-Age", String(this.options.max_age));
2003
+ }
2004
+ }
2005
+ actualHeaders(request2, headers) {
2006
+ this.#origin(request2, headers);
2007
+ if (!headers.has("access-control-allow-origin")) return;
2008
+ this.#credentials(headers);
2009
+ if (this.options.exposed_headers.length > 0) headers.set("Access-Control-Expose-Headers", this.options.exposed_headers.join(", "));
2010
+ }
2011
+ #origin(request2, headers) {
2012
+ const origin = request2.header("origin");
2013
+ if (this.#allowAllOrigins && !this.options.supports_credentials) {
2014
+ headers.set("Access-Control-Allow-Origin", "*");
2015
+ } else if (!this.#allowAllOrigins && this.#patterns.length === 0 && this.#origins.length === 1) {
2016
+ headers.set("Access-Control-Allow-Origin", this.#origins[0]);
2017
+ } else {
2018
+ if (origin !== void 0 && this.#allowed(origin)) headers.set("Access-Control-Allow-Origin", origin);
2019
+ vary(headers, "Origin");
2020
+ }
2021
+ }
2022
+ #allowed(origin) {
2023
+ return this.#allowAllOrigins || this.#origins.includes(origin) || this.#patterns.some((pattern) => pattern.test(origin));
2024
+ }
2025
+ #credentials(headers) {
2026
+ if (this.options.supports_credentials) headers.set("Access-Control-Allow-Credentials", "true");
2027
+ }
2028
+ #methods(request2, headers) {
2029
+ let methods = this.options.allowed_methods.map((method) => method.toUpperCase()).join(", ");
2030
+ if (this.options.allowed_methods.includes("*")) {
2031
+ methods = (request2.header("access-control-request-method") ?? "").toUpperCase();
2032
+ vary(headers, "Access-Control-Request-Method");
2033
+ }
2034
+ if (methods !== "") headers.set("Access-Control-Allow-Methods", methods);
2035
+ }
2036
+ #allowedHeaders(request2, headers) {
2037
+ let allowed = this.options.allowed_headers.join(", ");
2038
+ if (this.options.allowed_headers.includes("*")) {
2039
+ allowed = request2.header("access-control-request-headers") ?? "";
2040
+ vary(headers, "Access-Control-Request-Headers");
2041
+ }
2042
+ if (allowed !== "") headers.set("Access-Control-Allow-Headers", allowed);
2043
+ }
2044
+ };
2045
+ function vary(headers, name) {
2046
+ const current = headers.get("vary");
2047
+ if (current === null || current === "") headers.set("Vary", name);
2048
+ else if (!current.split(",").some((entry) => entry.trim().toLowerCase() === name.toLowerCase())) headers.set("Vary", `${current}, ${name}`);
2049
+ }
2050
+ function withHeaders(response2, cors) {
2051
+ const apply = (target2) => {
2052
+ for (const [name, value2] of cors) {
2053
+ if (name === "vary") for (const entry of value2.split(",")) vary(target2, entry.trim());
2054
+ else target2.set(name, value2);
2055
+ }
2056
+ };
2057
+ try {
2058
+ apply(response2.headers);
2059
+ return response2;
2060
+ } catch {
2061
+ const copy = new Headers(response2.headers);
2062
+ apply(copy);
2063
+ return new Response(response2.body, { status: response2.status, statusText: response2.statusText, headers: copy });
2064
+ }
2065
+ }
2066
+ var BYPASS_COOKIE = "oriel_maintenance";
2067
+ var BYPASS_SECONDS = 12 * 60 * 60;
2068
+ var mac = (expiresAt, secret) => createHmac("sha256", secret).update(String(expiresAt)).digest("hex");
2069
+ function bypassCookieValue(secret, now = Date.now()) {
2070
+ const expiresAt = Math.floor(now / 1e3) + BYPASS_SECONDS;
2071
+ return { value: Buffer.from(JSON.stringify({ expires_at: expiresAt, mac: mac(expiresAt, secret) })).toString("base64"), expiresAt };
2072
+ }
2073
+ function isValidBypassCookie(value2, secret, now = Date.now()) {
2074
+ if (value2 === void 0 || value2 === "") return false;
2075
+ let payload;
2076
+ try {
2077
+ payload = JSON.parse(Buffer.from(value2, "base64").toString("utf8"));
2078
+ } catch {
2079
+ return false;
2080
+ }
2081
+ if (typeof payload !== "object" || payload === null) return false;
2082
+ const { expires_at: expiresAt, mac: given } = payload;
2083
+ if (typeof expiresAt !== "number" || typeof given !== "string") return false;
2084
+ const expected = Buffer.from(mac(expiresAt, secret));
2085
+ const actual = Buffer.from(given);
2086
+ return expected.length === actual.length && timingSafeEqual(expected, actual) && expiresAt >= Math.floor(now / 1e3);
2087
+ }
2088
+ var trimSlashes = (path) => path === "/" ? path : path.replace(/^\/+|\/+$/g, "");
2089
+ var PreventRequestsDuringMaintenance = class {
2090
+ /** Paths that answer while the app is down, as `request.is()` patterns. Override in a subclass to add some. */
2091
+ except = [];
2092
+ async handle(request2, next) {
2093
+ const container2 = currentContainer();
2094
+ if (container2 === void 0 || !container2.bound(MaintenanceMode)) return next(request2);
2095
+ const mode = container2.make(MaintenanceMode);
2096
+ if (!await mode.active()) return next(request2);
2097
+ if (this.inExceptArray(request2, container2)) return next(request2);
2098
+ const data = await mode.data() ?? { status: 503 };
2099
+ if (data.secret !== void 0 && request2.path() === data.secret) return this.bypassResponse(request2, data.secret, container2);
2100
+ if (data.secret !== void 0 && isValidBypassCookie(request2.cookie(BYPASS_COOKIE), data.secret)) return next(request2);
2101
+ if (data.redirect !== void 0) {
2102
+ const path = trimSlashes(data.redirect);
2103
+ if (request2.path() !== path) return redirectTo(request2, path);
2104
+ }
2105
+ const headers = this.headers(data);
2106
+ if (data.template !== void 0) {
2107
+ return new Response(data.template, { status: data.status ?? 503, headers: { ...headers, "content-type": "text/html; charset=utf-8" } });
2108
+ }
2109
+ throw new HttpException(data.status ?? 503, "Service Unavailable", headers);
2110
+ }
2111
+ /** The health route, the subclass's `except`, and `withMiddleware((m) => m.preventRequestsDuringMaintenance({ except }))`'s. */
2112
+ inExceptArray(request2, container2) {
2113
+ const configured = container2.bound(ConfigRepository) ? container2.make(ConfigRepository).get("http.maintenance_except", []) : [];
2114
+ const health = container2.bound(RoutingPaths) ? container2.make(RoutingPaths).health : void 0;
2115
+ const paths = [...this.except, ...configured ?? [], ...health === void 0 ? [] : [health]];
2116
+ return paths.some((path) => {
2117
+ const pattern = trimSlashes(path);
2118
+ return request2.fullUrl() === path || request2.is(pattern);
2119
+ });
2120
+ }
2121
+ headers(data) {
2122
+ const headers = {};
2123
+ if (data.retry !== void 0) headers["Retry-After"] = String(data.retry);
2124
+ if (data.refresh !== void 0) headers.Refresh = String(data.refresh);
2125
+ return headers;
2126
+ }
2127
+ /** A 302 to `/` with the bypass cookie, on the session's path and domain. */
2128
+ bypassResponse(request2, secret, container2) {
2129
+ const config = container2.bound(ConfigRepository) ? container2.make(ConfigRepository) : void 0;
2130
+ const path = config?.get("session.path", "/") ?? "/";
2131
+ const domain = config?.get("session.domain", null) ?? null;
2132
+ const { value: value2, expiresAt } = bypassCookieValue(secret);
2133
+ const cookie = [
2134
+ `${BYPASS_COOKIE}=${encodeURIComponent(value2)}`,
2135
+ `Expires=${new Date(expiresAt * 1e3).toUTCString()}`,
2136
+ `Max-Age=${BYPASS_SECONDS}`,
2137
+ `Path=${path}`,
2138
+ ...domain ? [`Domain=${domain}`] : [],
2139
+ "HttpOnly",
2140
+ "SameSite=Lax"
2141
+ ].join("; ");
2142
+ const response2 = redirectTo(request2, "/");
2143
+ response2.headers.append("Set-Cookie", cookie);
2144
+ return response2;
2145
+ }
2146
+ };
2147
+ function redirectTo(request2, path) {
2148
+ const origin = new URL(request2.url()).origin;
2149
+ return new Response(null, { status: 302, headers: { Location: path === "/" ? `${origin}/` : `${origin}/${path}` } });
2150
+ }
1868
2151
  var plainServerError = () => new Response("Server Error", { status: 500, headers: { "content-type": "text/plain; charset=utf-8" } });
1869
2152
  var Kernel = class {
1870
2153
  constructor(app) {
1871
2154
  this.app = app;
1872
2155
  }
1873
2156
  app;
1874
- #middleware = [TrimStrings, ConvertEmptyStringsToNull];
2157
+ #middleware = [HandleCors, PreventRequestsDuringMaintenance, TrimStrings, ConvertEmptyStringsToNull];
1875
2158
  #requests = /* @__PURE__ */ new WeakMap();
1876
2159
  getGlobalMiddleware() {
1877
2160
  return [...this.#middleware];
@@ -1888,6 +2171,10 @@ var Kernel = class {
1888
2171
  for (const cls of [...middleware].reverse()) if (!this.#middleware.includes(cls)) this.#middleware.unshift(cls);
1889
2172
  return this;
1890
2173
  }
2174
+ removeMiddleware(...middleware) {
2175
+ this.#middleware = this.#middleware.filter((cls) => !middleware.includes(cls));
2176
+ return this;
2177
+ }
1891
2178
  hasMiddleware(middleware) {
1892
2179
  return this.#middleware.includes(middleware);
1893
2180
  }
@@ -2010,31 +2297,166 @@ var Kernel = class {
2010
2297
  /** config('http.max_body_size'): bytes, or null for no limit. Anything else is a configuration error. */
2011
2298
  #maxBodySize() {
2012
2299
  if (!this.app.bound(ConfigRepository)) return 8 * 1024 * 1024;
2013
- const value = this.app.make(ConfigRepository).get("http.max_body_size", 8 * 1024 * 1024);
2014
- if (value === null) return null;
2015
- if (typeof value === "number" && Number.isFinite(value) && value >= 0) return value;
2300
+ const value2 = this.app.make(ConfigRepository).get("http.max_body_size", 8 * 1024 * 1024);
2301
+ if (value2 === null) return null;
2302
+ if (typeof value2 === "number" && Number.isFinite(value2) && value2 >= 0) return value2;
2016
2303
  throw new HttpServerError(
2017
- `Invalid http.max_body_size ${JSON.stringify(value) ?? String(value)}: use a number of bytes (0 or more), or null for no limit.`
2304
+ `Invalid http.max_body_size ${JSON.stringify(value2) ?? String(value2)}: use a number of bytes (0 or more), or null for no limit.`
2018
2305
  );
2019
2306
  }
2020
2307
  /** config('http.max_json_depth'): how deep a JSON body may nest, or null for no limit. */
2021
2308
  #maxJsonDepth() {
2022
2309
  if (!this.app.bound(ConfigRepository)) return 512;
2023
- const value = this.app.make(ConfigRepository).get("http.max_json_depth", 512);
2024
- if (value === null) return null;
2025
- if (typeof value === "number" && Number.isInteger(value) && value >= 1) return value;
2310
+ const value2 = this.app.make(ConfigRepository).get("http.max_json_depth", 512);
2311
+ if (value2 === null) return null;
2312
+ if (typeof value2 === "number" && Number.isInteger(value2) && value2 >= 1) return value2;
2026
2313
  throw new HttpServerError(
2027
- `Invalid http.max_json_depth ${JSON.stringify(value) ?? String(value)}: use a whole number (1 or more), or null for no limit.`
2314
+ `Invalid http.max_json_depth ${JSON.stringify(value2) ?? String(value2)}: use a whole number (1 or more), or null for no limit.`
2028
2315
  );
2029
2316
  }
2030
2317
  /** config('http.trusted_proxies'): an array, or a comma-separated string such as '*' or '10.0.0.0/8,::1'. */
2031
2318
  #trustedProxies() {
2032
2319
  if (!this.app.bound(ConfigRepository)) return [];
2033
- const value = this.app.make(ConfigRepository).get("http.trusted_proxies", []);
2034
- if (typeof value === "string") return value.split(",").map((entry) => entry.trim()).filter((entry) => entry !== "");
2035
- return Array.isArray(value) ? value.map(String) : [];
2320
+ const value2 = this.app.make(ConfigRepository).get("http.trusted_proxies", []);
2321
+ if (typeof value2 === "string") return value2.split(",").map((entry) => entry.trim()).filter((entry) => entry !== "");
2322
+ return Array.isArray(value2) ? value2.map(String) : [];
2323
+ }
2324
+ };
2325
+ var MAINTENANCE_CACHE_KEY = "oriel:foundation:down";
2326
+ var CacheMaintenanceMode = class {
2327
+ constructor(store2) {
2328
+ this.store = store2;
2329
+ }
2330
+ store;
2331
+ async activate(data) {
2332
+ await this.store().forever(MAINTENANCE_CACHE_KEY, data);
2333
+ }
2334
+ async deactivate() {
2335
+ await this.store().forget(MAINTENANCE_CACHE_KEY);
2336
+ }
2337
+ async active() {
2338
+ return this.store().has(MAINTENANCE_CACHE_KEY);
2339
+ }
2340
+ async data() {
2341
+ return this.store().get(MAINTENANCE_CACHE_KEY);
2036
2342
  }
2037
2343
  };
2344
+ var FileMaintenanceMode = class {
2345
+ constructor(path) {
2346
+ this.path = path;
2347
+ }
2348
+ path;
2349
+ async activate(data) {
2350
+ await mkdir(dirname(this.path), { recursive: true });
2351
+ await writeFile(this.path, JSON.stringify(data, null, 4));
2352
+ }
2353
+ async deactivate() {
2354
+ await rm(this.path, { force: true });
2355
+ }
2356
+ async active() {
2357
+ return existsSync4(this.path);
2358
+ }
2359
+ async data() {
2360
+ if (!existsSync4(this.path)) return void 0;
2361
+ try {
2362
+ return JSON.parse(await readFile(this.path, "utf8"));
2363
+ } catch {
2364
+ return { status: 503 };
2365
+ }
2366
+ }
2367
+ };
2368
+ var DOWN = "down {--redirect= : The path that users should be redirected to} {--render= : The view that should be prerendered for display during maintenance mode} {--retry= : The number of seconds after which the request may be retried} {--refresh= : The number of seconds after which the browser may refresh} {--secret= : The secret phrase that may be used to bypass maintenance mode} {--with-secret : Generate a random secret phrase that may be used to bypass maintenance mode} {--status=503 : The status code that should be used when returning the maintenance mode response}";
2369
+ function value(command, name) {
2370
+ const given = command.option(name);
2371
+ return given === void 0 || given === null || given === false || given === "" ? void 0 : String(given);
2372
+ }
2373
+ function registerMaintenanceCommands(kernel, app) {
2374
+ kernel.command(DOWN, async function() {
2375
+ const numbers = {};
2376
+ for (const name of ["status", "retry", "refresh"]) {
2377
+ const given = value(this, name);
2378
+ if (given === void 0) continue;
2379
+ if (!/^\d+$/.test(given)) {
2380
+ this.error(`The --${name} option must be a number.`);
2381
+ return 1;
2382
+ }
2383
+ numbers[name] = Number(given);
2384
+ }
2385
+ const mode = app.maintenanceMode();
2386
+ const secret = this.option("with-secret") === true ? Str.random(16) : value(this, "secret");
2387
+ if (await mode.active() && secret === void 0) {
2388
+ this.info("Application is already down.");
2389
+ return 0;
2390
+ }
2391
+ const data = { status: numbers.status ?? 503 };
2392
+ const redirect2 = value(this, "redirect");
2393
+ if (redirect2 !== void 0) data.redirect = redirect2 === "/" ? "/" : `/${redirect2.replace(/^\/+|\/+$/g, "")}`;
2394
+ if (numbers.retry !== void 0 && numbers.retry > 0) data.retry = numbers.retry;
2395
+ if (numbers.refresh !== void 0 && numbers.refresh > 0) data.refresh = numbers.refresh;
2396
+ if (secret !== void 0) data.secret = secret;
2397
+ const render = value(this, "render");
2398
+ if (render !== void 0) {
2399
+ if (!app.bound(ViewFactory)) {
2400
+ this.error("--render needs the View service provider.");
2401
+ return 1;
2402
+ }
2403
+ data.template = await app.make(ViewFactory).make(render, { retryAfter: data.retry }).render();
2404
+ }
2405
+ await mode.activate(data);
2406
+ this.info("Application is now in maintenance mode.");
2407
+ if (secret !== void 0) {
2408
+ const url2 = (app.bound(ConfigRepository) ? app.make(ConfigRepository).get("app.url", "http://localhost") : "http://localhost") ?? "http://localhost";
2409
+ this.info(`You may bypass maintenance mode via [${url2.replace(/\/+$/, "")}/${secret}].`);
2410
+ }
2411
+ return 0;
2412
+ }).purpose("Put the application into maintenance / demo mode");
2413
+ kernel.command("up", async function() {
2414
+ const mode = app.maintenanceMode();
2415
+ if (!await mode.active()) {
2416
+ this.info("Application is already up.");
2417
+ return 0;
2418
+ }
2419
+ await mode.deactivate();
2420
+ this.info("Application is now live.");
2421
+ return 0;
2422
+ }).purpose("Bring the application out of maintenance mode");
2423
+ }
2424
+ var escape = (value2) => value2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2425
+ var TrustHosts = class {
2426
+ async handle(request2, next) {
2427
+ const container2 = currentContainer();
2428
+ const app = container2?.bound(Application) ? container2.make(Application) : void 0;
2429
+ if (app !== void 0 && !app.environment("local") && !app.runningUnitTests()) {
2430
+ const host = new URL(request2.url()).hostname.toLowerCase();
2431
+ if (!this.hosts().some((trusted) => typeof trusted === "string" ? trusted.toLowerCase() === host : trusted.test(host))) {
2432
+ throw new HttpException(404, "Bad hostname provided.");
2433
+ }
2434
+ }
2435
+ return next(request2);
2436
+ }
2437
+ /** The trusted hosts and patterns (Laravel's hosts()). */
2438
+ hosts() {
2439
+ const container2 = currentContainer();
2440
+ const config = container2?.bound(ConfigRepository) ? container2.make(ConfigRepository) : void 0;
2441
+ const options = config?.get("http.trusted_hosts") ?? {};
2442
+ const listed = typeof options.at === "function" ? options.at() : options.at ?? [];
2443
+ const hosts = [...listed];
2444
+ if (options.at === void 0 || options.subdomains !== false) {
2445
+ const appHost = this.#applicationHost(config?.get("app.url"));
2446
+ if (appHost !== void 0) hosts.push(new RegExp(`^(.+\\.)?${escape(appHost)}$`, "i"));
2447
+ }
2448
+ return hosts;
2449
+ }
2450
+ #applicationHost(url2) {
2451
+ if (url2 === void 0 || url2 === "") return void 0;
2452
+ try {
2453
+ return new URL(url2).hostname.toLowerCase();
2454
+ } catch {
2455
+ return void 0;
2456
+ }
2457
+ }
2458
+ };
2459
+ var FRAMEWORK_GLOBALS = [HandleCors, PreventRequestsDuringMaintenance, TrimStrings, ConvertEmptyStringsToNull];
2038
2460
  var MiddlewareConfiguration = class {
2039
2461
  constructor(kernel, router, config) {
2040
2462
  this.kernel = kernel;
@@ -2052,6 +2474,38 @@ var MiddlewareConfiguration = class {
2052
2474
  this.kernel.prependMiddleware(...middleware);
2053
2475
  return this;
2054
2476
  }
2477
+ /** Takes middleware out of the global list (Laravel 11's remove()); one that isn't there is ignored. */
2478
+ remove(...middleware) {
2479
+ this.kernel.removeMiddleware(...middleware);
2480
+ return this;
2481
+ }
2482
+ /**
2483
+ * Fields TrimStrings leaves as sent (dotted keys, added to the password fields), and callbacks that leave a whole
2484
+ * request untouched. Stored in config('http.trim_strings_except'), so each app has its own.
2485
+ */
2486
+ trimStrings(options) {
2487
+ return this.#addTo("http.trim_strings_except", options.except ?? []);
2488
+ }
2489
+ /** Callbacks that leave a whole request's empty strings as sent. Stored in config('http.convert_empty_strings_except'). */
2490
+ convertEmptyStringsToNull(options) {
2491
+ return this.#addTo("http.convert_empty_strings_except", options.except ?? []);
2492
+ }
2493
+ /**
2494
+ * Laravel 11's trustHosts(): puts TrustHosts in the global list, after what was prepended and before the framework's
2495
+ * own middleware, and stores the options in config('http.trusted_hosts').
2496
+ */
2497
+ trustHosts(options = {}) {
2498
+ const list = this.kernel.getGlobalMiddleware().filter((cls) => cls !== TrustHosts);
2499
+ const at = list.findIndex((cls) => FRAMEWORK_GLOBALS.includes(cls));
2500
+ list.splice(at === -1 ? 0 : at, 0, TrustHosts);
2501
+ this.kernel.setGlobalMiddleware(list);
2502
+ this.config?.set("http.trusted_hosts", options);
2503
+ return this;
2504
+ }
2505
+ /** Paths that still answer while the app is down (Laravel 11's preventRequestsDuringMaintenance(except:)). */
2506
+ preventRequestsDuringMaintenance(options) {
2507
+ return this.#addTo("http.maintenance_except", options.except ?? []);
2508
+ }
2055
2509
  web(options) {
2056
2510
  return this.#modifyGroup("web", options);
2057
2511
  }
@@ -2082,6 +2536,11 @@ var MiddlewareConfiguration = class {
2082
2536
  this.config?.set("http.redirect_users_to", url2);
2083
2537
  return this;
2084
2538
  }
2539
+ #addTo(key2, entries) {
2540
+ const current = this.config?.get(key2, []) ?? [];
2541
+ this.config?.set(key2, [...current, ...entries]);
2542
+ return this;
2543
+ }
2085
2544
  /** Laravel's order: prepends, then the group minus removals, then appends. */
2086
2545
  #modifyGroup(name, { append = [], prepend = [], remove = [] }) {
2087
2546
  const current = this.router.getMiddlewareGroups()[name] ?? [];
@@ -2144,8 +2603,8 @@ var STATUS_TEXTS = {
2144
2603
  function statusText(status) {
2145
2604
  return STATUS_TEXTS[status] ?? (status >= 500 ? "Server Error" : "Error");
2146
2605
  }
2147
- function escapeHtml(value) {
2148
- return value.replace(/[&<>"']/g, (char) => `&#${char.charCodeAt(0)};`);
2606
+ function escapeHtml(value2) {
2607
+ return value2.replace(/[&<>"']/g, (char) => `&#${char.charCodeAt(0)};`);
2149
2608
  }
2150
2609
  function minimalPage(status, message) {
2151
2610
  const title = escapeHtml(message);
@@ -2173,7 +2632,7 @@ function stackFrames(error) {
2173
2632
  return frames;
2174
2633
  }
2175
2634
  async function excerpt(frame, radius = 5) {
2176
- const source = await readFile(frame.file, "utf8").catch(() => void 0);
2635
+ const source = await readFile2(frame.file, "utf8").catch(() => void 0);
2177
2636
  if (source === void 0) return void 0;
2178
2637
  const lines = source.split("\n");
2179
2638
  const start = Math.max(1, frame.line - radius);
@@ -2313,7 +2772,7 @@ var ErrorHandler = class {
2313
2772
  else if (this.shouldReturnJson(http, error)) response2 = this.#renderJson(error);
2314
2773
  else response2 = await this.#renderHtml(http, error);
2315
2774
  const headers = error?.headers;
2316
- return headers === void 0 ? response2 : withHeaders(response2, headers);
2775
+ return headers === void 0 ? response2 : withHeaders2(response2, headers);
2317
2776
  }
2318
2777
  /** An error with its own render(request) or toResponse(request) (Laravel's renderable exceptions / Responsable). */
2319
2778
  async #renderCustom(request2, error) {
@@ -2433,9 +2892,9 @@ var ErrorHandler = class {
2433
2892
  return currentContainer() ?? this.app;
2434
2893
  }
2435
2894
  };
2436
- function withHeaders(response2, extra) {
2895
+ function withHeaders2(response2, extra) {
2437
2896
  const headers = new Headers(response2.headers);
2438
- for (const [name, value] of Object.entries(extra)) headers.set(name, value);
2897
+ for (const [name, value2] of Object.entries(extra)) headers.set(name, value2);
2439
2898
  return new Response(response2.body, { status: response2.status, statusText: response2.statusText, headers });
2440
2899
  }
2441
2900
  var ExceptionsConfiguration = class {
@@ -2576,16 +3035,16 @@ var NOT_FOUND_PATH = "/__oriel-export-not-found__";
2576
3035
  async function exportSite(app, options) {
2577
3036
  const output = resolve2(options.output);
2578
3037
  const publicPath = options.publicPath === false ? void 0 : resolve2(options.publicPath);
2579
- if (publicPath !== void 0 && existsSync4(join5(publicPath, "hot"))) {
3038
+ if (publicPath !== void 0 && existsSync23(join5(publicPath, "hot"))) {
2580
3039
  throw new Error("The Vite dev server is running (public/hot exists): stop `npm run dev`, build the assets with `npm run build`, then export.");
2581
3040
  }
2582
3041
  assertReplaceable(output);
2583
- const staging = await mkdtemp(join5(dirname(output), `.${basename2(output)}-`));
3042
+ const staging = await mkdtemp(join5(dirname2(output), `.${basename2(output)}-`));
2584
3043
  try {
2585
- if (publicPath !== void 0 && existsSync4(publicPath)) {
3044
+ if (publicPath !== void 0 && existsSync23(publicPath)) {
2586
3045
  await cp(publicPath, staging, { recursive: true, filter: (source) => basename2(source) !== "hot" && !lstatSync(source).isSymbolicLink() && isPublicAsset(relative2(publicPath, source)) });
2587
3046
  }
2588
- const excluded = (path) => options.exclude.some((pattern) => wildcard(pattern).test(path));
3047
+ const excluded = (path) => options.exclude.some((pattern) => wildcard2(pattern).test(path));
2589
3048
  const isPublicFile = (path) => publicPath !== void 0 && path !== "/" && isFile(join5(publicPath, path));
2590
3049
  const queue = [.../* @__PURE__ */ new Set(["/", ...options.paths.map(rooted)])].filter((path) => path === "/" || !excluded(path));
2591
3050
  const seen = new Set(queue);
@@ -2618,18 +3077,18 @@ async function exportSite(app, options) {
2618
3077
  const notFound = await fetchPage(app, new URL(NOT_FOUND_PATH, options.baseUrl).href);
2619
3078
  const notFoundPage = notFound.status === 404 && isHtml(notFound.headers);
2620
3079
  if (notFoundPage) await writeInto(staging, "404.html", notFound.body);
2621
- await writeFile(join5(staging, MARKER), "");
2622
- await rm(output, { recursive: true, force: true });
3080
+ await writeFile2(join5(staging, MARKER), "");
3081
+ await rm2(output, { recursive: true, force: true });
2623
3082
  await rename(staging, output);
2624
3083
  return { pages, redirects, notFoundPage };
2625
3084
  } catch (error) {
2626
- await rm(staging, { recursive: true, force: true });
3085
+ await rm2(staging, { recursive: true, force: true });
2627
3086
  throw error;
2628
3087
  }
2629
3088
  }
2630
3089
  function assertReplaceable(output) {
2631
- if (!existsSync4(output)) return;
2632
- if (statSync3(output).isDirectory() && (existsSync4(join5(output, MARKER)) || readdirSync2(output).length === 0)) return;
3090
+ if (!existsSync23(output)) return;
3091
+ if (statSync3(output).isDirectory() && (existsSync23(join5(output, MARKER)) || readdirSync2(output).length === 0)) return;
2633
3092
  throw new Error(`[${output}] exists and wasn't made by oriel export: remove it, or export somewhere else with --output.`);
2634
3093
  }
2635
3094
  async function fetchPage(app, url2) {
@@ -2641,13 +3100,13 @@ async function fetchPage(app, url2) {
2641
3100
  }
2642
3101
  async function writeInto(folder, file, body) {
2643
3102
  const path = join5(folder, file);
2644
- await mkdir(dirname(path), { recursive: true });
2645
- await writeFile(path, body);
3103
+ await mkdir2(dirname2(path), { recursive: true });
3104
+ await writeFile2(path, body);
2646
3105
  }
2647
3106
  var isHtml = (headers) => (headers.get("content-type") ?? "").includes("text/html");
2648
3107
  var rooted = (path) => path.startsWith("/") ? path : `/${path}`;
2649
- var isFile = (path) => existsSync4(path) && statSync3(path).isFile();
2650
- var wildcard = (pattern) => new RegExp(`^${rooted(pattern).replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")}$`);
3108
+ var isFile = (path) => existsSync23(path) && statSync3(path).isFile();
3109
+ var wildcard2 = (pattern) => new RegExp(`^${rooted(pattern).replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")}$`);
2651
3110
  function bunRuntime() {
2652
3111
  return globalThis.Bun;
2653
3112
  }
@@ -2660,7 +3119,7 @@ async function serveBun(app, options) {
2660
3119
  port: options.port,
2661
3120
  hostname: options.hostname,
2662
3121
  // Bun closes a connection idle for 10 seconds by default, a slow page included; 255 is the most it allows.
2663
- idleTimeout: 255,
3122
+ idleTimeout: options.requestTimeout === 0 ? 0 : Math.min(options.requestTimeout, 255),
2664
3123
  async fetch(request2, current) {
2665
3124
  setClientAddress(request2, current.requestIP(request2)?.address);
2666
3125
  const response2 = await handleSafely(app, request2, options.publicPath);
@@ -2763,8 +3222,8 @@ function toWebRequest(req, res, fallbackHost) {
2763
3222
  async function writeResponse(res, response2) {
2764
3223
  res.statusCode = response2.status;
2765
3224
  if (response2.statusText !== "") res.statusMessage = response2.statusText;
2766
- response2.headers.forEach((value, name) => {
2767
- if (name !== "set-cookie") res.setHeader(name, value);
3225
+ response2.headers.forEach((value2, name) => {
3226
+ if (name !== "set-cookie") res.setHeader(name, value2);
2768
3227
  });
2769
3228
  const cookies = response2.headers.getSetCookie();
2770
3229
  if (cookies.length > 0) res.setHeader("set-cookie", cookies);
@@ -2791,15 +3250,23 @@ function nodeRequestHandler(app, options) {
2791
3250
  } catch {
2792
3251
  res.destroy();
2793
3252
  }
2794
- await terminateRequest(app, request2, response2);
3253
+ const waitUntil = options.waitUntil?.();
3254
+ if (waitUntil !== void 0) waitUntil(terminateRequest(app, request2, response2));
3255
+ else await terminateRequest(app, request2, response2);
2795
3256
  };
2796
3257
  }
3258
+ function nodeTimeouts(options) {
3259
+ const keepAliveTimeout = options.keepAliveTimeout * 1e3;
3260
+ const requestTimeout = options.requestTimeout * 1e3;
3261
+ const headersTimeout = requestTimeout > 0 ? Math.min(keepAliveTimeout + 1e3, requestTimeout) : keepAliveTimeout + 1e3;
3262
+ return { keepAliveTimeout, headersTimeout, requestTimeout };
3263
+ }
2797
3264
  async function serveNode(app, options) {
2798
3265
  const handle = nodeRequestHandler(app, {
2799
3266
  ...options.publicPath !== void 0 && { publicPath: options.publicPath },
2800
3267
  fallbackHost: `${displayHost(options.hostname)}:${options.port}`
2801
3268
  });
2802
- const server = createServer((req, res) => void handle(req, res));
3269
+ const server = createServer(nodeTimeouts(options), (req, res) => void handle(req, res));
2803
3270
  await new Promise((resolve4, reject) => {
2804
3271
  server.once("error", reject);
2805
3272
  server.listen(options.port, options.hostname, () => {
@@ -2832,12 +3299,18 @@ async function serveNode(app, options) {
2832
3299
  function detectRuntime() {
2833
3300
  return bunRuntime() !== void 0 ? "bun" : "node";
2834
3301
  }
3302
+ var set = (value2) => value2 === void 0 || value2 === "" ? void 0 : value2;
3303
+ function defaultHostname() {
3304
+ return set(process.env.HOST) ?? set(process.env.SERVER_HOST) ?? "127.0.0.1";
3305
+ }
2835
3306
  async function serve(app, options = {}) {
2836
3307
  const resolved = {
2837
3308
  port: options.port ?? Number(process.env.PORT ?? process.env.SERVER_PORT ?? 8e3),
2838
- hostname: options.hostname ?? "127.0.0.1",
3309
+ hostname: options.hostname ?? defaultHostname(),
2839
3310
  signals: options.signals ?? true,
2840
3311
  shutdownTimeout: options.shutdownTimeout ?? 1e4,
3312
+ keepAliveTimeout: options.keepAliveTimeout ?? 65,
3313
+ requestTimeout: options.requestTimeout ?? 300,
2841
3314
  ...options.publicPath !== false && { publicPath: options.publicPath ?? app.publicPath() }
2842
3315
  };
2843
3316
  await app.boot();
@@ -2858,7 +3331,7 @@ var BUN_ENV_FILES = [
2858
3331
  ".env.production.local",
2859
3332
  ".env.test.local"
2860
3333
  ];
2861
- var expand = (value, env2) => value.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)/g, (_match, braced, bare) => env2[braced ?? bare] ?? "");
3334
+ var expand = (value2, env2) => value2.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)/g, (_match, braced, bare) => env2[braced ?? bare] ?? "");
2862
3335
  function serverEnvironment(options = {}) {
2863
3336
  const launched = options.launched ?? launchEnvironment;
2864
3337
  const env2 = { ...launched };
@@ -2868,7 +3341,7 @@ function serverEnvironment(options = {}) {
2868
3341
  const cwd = options.cwd ?? process.cwd();
2869
3342
  for (const name of BUN_ENV_FILES) {
2870
3343
  const file = join23(cwd, name);
2871
- if (!existsSync23(file)) continue;
3344
+ if (!existsSync32(file)) continue;
2872
3345
  let values;
2873
3346
  try {
2874
3347
  values = parseEnv2(readFileSync3(file, "utf8"));
@@ -2876,8 +3349,8 @@ function serverEnvironment(options = {}) {
2876
3349
  continue;
2877
3350
  }
2878
3351
  for (const [key2, raw] of Object.entries(values)) {
2879
- const value = launched[key2];
2880
- if (raw !== void 0 && value !== void 0 && (value === raw || value === expand(raw, launched))) delete env2[key2];
3352
+ const value2 = launched[key2];
3353
+ if (raw !== void 0 && value2 !== void 0 && (value2 === raw || value2 === expand(raw, launched))) delete env2[key2];
2881
3354
  }
2882
3355
  }
2883
3356
  return env2;
@@ -2943,7 +3416,7 @@ function watchFiles(basePath, onChange, options = {}) {
2943
3416
  };
2944
3417
  start(".", false, (file) => file === null ? void 0 : toSlashes(file));
2945
3418
  for (const folder of WATCHED_FOLDERS) {
2946
- if (existsSync32(join32(basePath, folder))) start(folder, true, (file) => `${folder}/${file === null ? "" : toSlashes(file)}`);
3419
+ if (existsSync42(join32(basePath, folder))) start(folder, true, (file) => `${folder}/${file === null ? "" : toSlashes(file)}`);
2947
3420
  }
2948
3421
  return {
2949
3422
  close() {
@@ -3076,12 +3549,12 @@ var WatchedServer = class {
3076
3549
  function io(command) {
3077
3550
  return {
3078
3551
  option: (name) => {
3079
- const value = command.option(name);
3080
- return value === void 0 || value === null || value === false || value === "" ? void 0 : String(value);
3552
+ const value2 = command.option(name);
3553
+ return value2 === void 0 || value2 === null || value2 === false || value2 === "" ? void 0 : String(value2);
3081
3554
  },
3082
3555
  flag: (name) => {
3083
- const value = command.option(name);
3084
- return value === true || value === "true" || value === "1";
3556
+ const value2 = command.option(name);
3557
+ return value2 === true || value2 === "true" || value2 === "1";
3085
3558
  },
3086
3559
  info: (message) => command.info(message),
3087
3560
  line: (message) => command.line(message),
@@ -3147,7 +3620,7 @@ ${create[0]}`);
3147
3620
  return void 0;
3148
3621
  }
3149
3622
  async function serveWatching(app, out, port, run) {
3150
- const hostname = out.option("host") ?? "127.0.0.1";
3623
+ const hostname = out.option("host") ?? defaultHostname();
3151
3624
  const requested = port !== void 0 ? Number(port) : Number(process.env.PORT ?? process.env.SERVER_PORT ?? 8e3);
3152
3625
  let claimed;
3153
3626
  try {
@@ -3207,7 +3680,7 @@ function registerHttpCommands(kernel, app, options = {}) {
3207
3680
  const terminalWidth = options.terminalWidth ?? (() => process.stdout.columns ?? 120);
3208
3681
  const runWatching = options.watch ?? ((watchOptions) => new WatchedServer(watchOptions).run());
3209
3682
  kernel.command(
3210
- "serve {--host=127.0.0.1 : The host address to serve the application on} {--port= : The port to serve the application on} {--watch : Automatically restart the server when the application is modified}",
3683
+ "serve {--host= : The host address to serve the application on} {--port= : The port to serve the application on} {--watch : Automatically restart the server when the application is modified}",
3211
3684
  async function() {
3212
3685
  const out = io(this);
3213
3686
  const port = out.option("port");
@@ -3216,8 +3689,9 @@ function registerHttpCommands(kernel, app, options = {}) {
3216
3689
  return 1;
3217
3690
  }
3218
3691
  if (out.flag("watch")) return serveWatching(app, out, port, runWatching);
3692
+ const host = out.option("host");
3219
3693
  const server = await serveApp(app, {
3220
- hostname: out.option("host") ?? "127.0.0.1",
3694
+ ...host !== void 0 && host !== "" && { hostname: host },
3221
3695
  ...port !== void 0 && { port: Number(port) },
3222
3696
  onListen: (running) => {
3223
3697
  out.info(`Server running on [${running.url}].`);
@@ -3266,22 +3740,28 @@ function registerHttpCommands(kernel, app, options = {}) {
3266
3740
  kernel.command("install:api {--force : Overwrite any existing API routes file}", async function() {
3267
3741
  const out = io(this);
3268
3742
  const routesFile = app.basePath("routes/api.ts");
3269
- if (existsSync42(routesFile) && !out.flag("force")) {
3743
+ if (existsSync5(routesFile) && !out.flag("force")) {
3270
3744
  out.error("API routes file already exists.");
3271
3745
  } else {
3272
- await mkdir2(dirname2(routesFile), { recursive: true });
3273
- await writeFile2(routesFile, API_ROUTES_STUB);
3746
+ await mkdir3(dirname3(routesFile), { recursive: true });
3747
+ await writeFile3(routesFile, API_ROUTES_STUB);
3274
3748
  out.info("Published API routes file.");
3275
3749
  }
3750
+ const corsFile = app.configPath("cors.ts");
3751
+ if (!existsSync5(corsFile)) {
3752
+ await mkdir3(dirname3(corsFile), { recursive: true });
3753
+ await writeFile3(corsFile, CORS_CONFIG_STUB);
3754
+ out.info("Published CORS config file.");
3755
+ }
3276
3756
  const bootstrapFile = app.bootstrapPath("app.ts");
3277
- const source = existsSync42(bootstrapFile) ? await readFile2(bootstrapFile, "utf8") : void 0;
3757
+ const source = existsSync5(bootstrapFile) ? await readFile3(bootstrapFile, "utf8") : void 0;
3278
3758
  const updated = source === void 0 ? void 0 : addApiRouting(source);
3279
3759
  if (updated === void 0) {
3280
3760
  out.warn(
3281
3761
  "Unable to automatically add API route definition to bootstrap file. Add api: 'routes/api.ts' to withRouting() in bootstrap/app.ts."
3282
3762
  );
3283
3763
  } else if (updated !== source) {
3284
- await writeFile2(bootstrapFile, updated);
3764
+ await writeFile3(bootstrapFile, updated);
3285
3765
  }
3286
3766
  out.info("API scaffolding installed.");
3287
3767
  return 0;
@@ -3300,12 +3780,14 @@ var HttpServiceProvider = class extends ServiceProvider {
3300
3780
  },
3301
3781
  "http"
3302
3782
  );
3783
+ this.mergeConfigFrom({ ...CORS_DEFAULTS }, "cors");
3303
3784
  this.app.singleton(HttpKernel, () => new Kernel(this.app));
3304
3785
  this.app.singleton(ExceptionHandler, () => {
3305
3786
  const handler = new ErrorHandler(this.app);
3306
3787
  applyExceptionCallbacks(this.app, handler);
3307
3788
  return handler;
3308
3789
  });
3790
+ this.app.singleton(MaintenanceMode, () => this.maintenanceMode());
3309
3791
  this.app.singleton(ResponseFactory, () => new HttpResponseFactory());
3310
3792
  this.app.singleton(Redirector, () => new HttpRedirector());
3311
3793
  }
@@ -3314,23 +3796,309 @@ var HttpServiceProvider = class extends ServiceProvider {
3314
3796
  const kernel = this.app.make(HttpKernel);
3315
3797
  if (kernel instanceof Kernel && this.app.bound(Router)) applyMiddlewareCallbacks(this.app, kernel);
3316
3798
  });
3317
- if (this.app.bound(ConsoleKernel)) registerHttpCommands(this.app.make(ConsoleKernel), this.app);
3799
+ if (this.app.bound(ConsoleKernel)) {
3800
+ registerHttpCommands(this.app.make(ConsoleKernel), this.app);
3801
+ registerMaintenanceCommands(this.app.make(ConsoleKernel), this.app);
3802
+ }
3803
+ }
3804
+ /** config('app.maintenance'): `file` (storage/framework/down, the default) or `cache` (a store every server shares). */
3805
+ maintenanceMode() {
3806
+ const config = this.app.bound(ConfigRepository) ? this.app.make(ConfigRepository) : void 0;
3807
+ const settings = config?.get("app.maintenance", {}) ?? {};
3808
+ const driver = settings.driver ?? "file";
3809
+ if (driver === "file") return new FileMaintenanceMode(this.app.storagePath("framework/down"));
3810
+ if (driver === "cache") {
3811
+ return new CacheMaintenanceMode(() => {
3812
+ const cache = this.app.make(CacheManager);
3813
+ return settings.store === void 0 || settings.store === "" ? cache.store() : cache.store(settings.store);
3814
+ });
3815
+ }
3816
+ throw new HttpServerError(`Unsupported maintenance mode driver [${driver}]: use "file" or "cache".`);
3318
3817
  }
3319
3818
  };
3819
+ var MissingValue = class {
3820
+ #missing = true;
3821
+ /** Laravel's isMissing(). */
3822
+ isMissing() {
3823
+ return this.#missing;
3824
+ }
3825
+ };
3826
+ var isMissing = (value2) => value2 instanceof MissingValue;
3827
+ var isPlainObject22 = (value2) => {
3828
+ if (typeof value2 !== "object" || value2 === null || Array.isArray(value2)) return false;
3829
+ const prototype = Object.getPrototypeOf(value2);
3830
+ return prototype === Object.prototype || prototype === null;
3831
+ };
3832
+ var isEmpty = (value2) => Object.keys(value2).length === 0;
3833
+ function mergeJson(target2, ...sources) {
3834
+ const merged = { ...target2 };
3835
+ for (const source of sources) {
3836
+ for (const [key2, value2] of Object.entries(source)) {
3837
+ const current = merged[key2];
3838
+ if (isPlainObject22(current) && isPlainObject22(value2)) merged[key2] = mergeJson(current, value2);
3839
+ else if (Array.isArray(current) && Array.isArray(value2)) merged[key2] = [...current, ...value2];
3840
+ else merged[key2] = value2;
3841
+ }
3842
+ }
3843
+ return merged;
3844
+ }
3845
+ var ResourceResponse = class {
3846
+ constructor(resource) {
3847
+ this.resource = resource;
3848
+ }
3849
+ resource;
3850
+ status;
3851
+ headers = new Headers();
3852
+ setStatusCode(status) {
3853
+ this.status = status;
3854
+ return this;
3855
+ }
3856
+ header(name, value2) {
3857
+ this.headers.set(name, value2);
3858
+ return this;
3859
+ }
3860
+ withHeaders(headers) {
3861
+ for (const [name, value2] of Object.entries(headers)) this.headers.set(name, value2);
3862
+ return this;
3863
+ }
3864
+ /** The body's top-level keys beside the data: with()'s and additional()'s (a paginated collection adds links and meta). */
3865
+ extra(request2) {
3866
+ return [this.resource.with(request2), this.resource.getAdditional()];
3867
+ }
3868
+ /** The JSON body: the resolved data, wrapped, beside the extra keys. */
3869
+ body(request2) {
3870
+ return this.wrap(this.resource.resolve(request2), this.extra(request2));
3871
+ }
3872
+ wrap(data, extra) {
3873
+ const wrapper = this.resource.wrapperKey();
3874
+ const unwrapped = (key2) => !isPlainObject22(data) || !Object.hasOwn(data, key2);
3875
+ const hasExtra = extra.some((keys) => !isEmpty(keys));
3876
+ let wrapped;
3877
+ if (wrapper !== null && unwrapped(wrapper)) wrapped = { [wrapper]: data };
3878
+ else if (hasExtra && (wrapper === null || unwrapped(wrapper))) wrapped = { [wrapper ?? "data"]: data };
3879
+ else if (isPlainObject22(data)) wrapped = data;
3880
+ if (wrapped === void 0) return data;
3881
+ return mergeJson(wrapped, ...extra);
3882
+ }
3883
+ defaultStatus() {
3884
+ const model = this.resource.resource;
3885
+ return typeof model === "object" && model !== null && model.wasRecentlyCreated === true ? 201 : 200;
3886
+ }
3887
+ async toResponse(request2) {
3888
+ const headers = new Headers(this.headers);
3889
+ headers.set("content-type", "application/json");
3890
+ const response2 = new Response(JSON.stringify(this.body(request2)), { status: this.status ?? this.defaultStatus(), headers });
3891
+ this.resource.withResponse(request2, response2);
3892
+ return response2;
3893
+ }
3894
+ };
3895
+ var LINK_KEYS = { first: "first_page_url", last: "last_page_url", prev: "prev_page_url", next: "next_page_url" };
3896
+ var PaginatedResourceResponse = class extends ResourceResponse {
3897
+ extra(request2) {
3898
+ return [this.paginationInformation(), ...super.extra(request2)];
3899
+ }
3900
+ paginationInformation() {
3901
+ const paginated = this.resource.resource.toArray();
3902
+ const links = {};
3903
+ for (const [name, key2] of Object.entries(LINK_KEYS)) links[name] = paginated[key2] ?? null;
3904
+ const meta = {};
3905
+ const moved = /* @__PURE__ */ new Set(["data", ...Object.values(LINK_KEYS)]);
3906
+ for (const [key2, value2] of Object.entries(paginated)) if (!moved.has(key2)) meta[key2] = value2;
3907
+ return { links, meta };
3908
+ }
3909
+ };
3910
+ var anonymousCollection = {
3911
+ Class: void 0
3912
+ };
3913
+ var isPlainObject3 = (value2) => {
3914
+ if (typeof value2 !== "object" || value2 === null) return false;
3915
+ const prototype = Object.getPrototypeOf(value2);
3916
+ return prototype === Object.prototype || prototype === null;
3917
+ };
3918
+ function resourceRequest() {
3919
+ const container2 = currentContainer();
3920
+ if (container2?.bound(HttpRequest)) {
3921
+ try {
3922
+ return container2.make(HttpRequest);
3923
+ } catch {
3924
+ }
3925
+ }
3926
+ const url2 = container2?.bound(ConfigRepository) ? container2.make(ConfigRepository).get("app.url", "") : "";
3927
+ return new IncomingRequest(new Request(url2 || "http://localhost"));
3928
+ }
3929
+ var leftOut = (value2) => isMissing(value2) || value2 instanceof JsonResource && isMissing(value2.resource);
3930
+ function resolveValue(value2, request2) {
3931
+ if (value2 instanceof JsonResource) return value2.resource === null || value2.resource === void 0 ? null : value2.resolve(request2);
3932
+ if (value2 instanceof Date) return serializeDate(value2);
3933
+ if (Array.isArray(value2)) return value2.filter((item) => !leftOut(item)).map((item) => resolveValue(item, request2));
3934
+ if (isPlainObject3(value2)) {
3935
+ const resolved = {};
3936
+ for (const [key2, item] of Object.entries(value2)) if (!leftOut(item)) resolved[key2] = resolveValue(item, request2);
3937
+ return resolved;
3938
+ }
3939
+ return value2;
3940
+ }
3941
+ var JsonResource = class {
3942
+ constructor(resource) {
3943
+ this.resource = resource;
3944
+ }
3945
+ resource;
3946
+ /**
3947
+ * The key the JSON is wrapped in (Laravel's `$wrap`): `data`, or none after `withoutWrapping()`. Set on the class it's
3948
+ * called on, so `JsonResource.withoutWrapping()` changes it for every resource.
3949
+ */
3950
+ static wrapper = "data";
3951
+ /** additional()'s keys, beside the data. */
3952
+ #additional = {};
3953
+ /**
3954
+ * A resource of this class: `PostResource.make(post)`, or `make(this.whenLoaded('post'))`. A null resource resolves
3955
+ * to null when nested, as a belongsTo that found nothing.
3956
+ */
3957
+ static make(resource) {
3958
+ return new this(resource);
3959
+ }
3960
+ /**
3961
+ * A collection of resources of this class: `PostResource.collection(posts)`, of a list, a collection or a paginator
3962
+ * (which adds Laravel's links and meta), or `collection(this.whenLoaded('posts'))`.
3963
+ */
3964
+ static collection(resource) {
3965
+ return new anonymousCollection.Class(resource, this);
3966
+ }
3967
+ /** Laravel's static wrap(): the key the JSON goes in, for this class and those that don't set their own. */
3968
+ static wrap(key2) {
3969
+ this.wrapper = key2;
3970
+ }
3971
+ /** Laravel's withoutWrapping(): the JSON goes bare. `JsonResource.withoutWrapping()` does it for every resource. */
3972
+ static withoutWrapping() {
3973
+ this.wrapper = null;
3974
+ }
3975
+ /** @internal The wrapper key of this resource's class. */
3976
+ wrapperKey() {
3977
+ return this.constructor.wrapper;
3978
+ }
3979
+ /** Top-level keys beside the data (Laravel's $additional): `PostResource.make(post).additional({ meta: { … } })`. */
3980
+ additional(data) {
3981
+ this.#additional = data;
3982
+ return this;
3983
+ }
3984
+ /** @internal additional()'s keys. */
3985
+ getAdditional() {
3986
+ return this.#additional;
3987
+ }
3988
+ /** Laravel's with(): top-level keys beside the data, for every response of this resource. None by default. */
3989
+ with(_request) {
3990
+ return {};
3991
+ }
3992
+ /** Laravel's withResponse(): change the response before it is sent (set a header). */
3993
+ withResponse(_request, _response) {
3994
+ }
3995
+ /** The response, to change its status or headers: `PostResource.make(post).response().setStatusCode(202)`. */
3996
+ response(_request) {
3997
+ return new ResourceResponse(this);
3998
+ }
3999
+ /** What toResponse() sends, as an object: what an Inertia page gets for a resource prop (inertia-laravel's getData()). */
4000
+ toResponseBody(request2 = resourceRequest()) {
4001
+ return this.response(request2).body(request2);
4002
+ }
4003
+ /** The JSON response: the data in its wrapper key, with()'s and additional()'s keys beside it. */
4004
+ toResponse(request2) {
4005
+ return this.response(request2).toResponse(request2);
4006
+ }
4007
+ /** The keys of the resource's JSON. By default the resource's own toArray(), the object itself, or {} for null. */
4008
+ toArray(_request) {
4009
+ const resource = this.resource;
4010
+ if (resource === null || resource === void 0) return {};
4011
+ if (typeof resource.toArray === "function") return resource.toArray();
4012
+ return resource;
4013
+ }
4014
+ /** toArray(), with its MissingValue keys removed and its nested resources resolved. */
4015
+ resolve(request2 = resourceRequest()) {
4016
+ return resolveValue(this.toArray(request2), request2);
4017
+ }
4018
+ /** The resolved JSON, unwrapped (Laravel's jsonSerialize()): what JSON.stringify() of a resource gives. */
4019
+ toJSON() {
4020
+ return this.resolve();
4021
+ }
4022
+ when(condition, value2, ...fallback) {
4023
+ if (condition) return typeof value2 === "function" ? value2() : value2;
4024
+ if (fallback.length > 0) return typeof fallback[0] === "function" ? fallback[0]() : fallback[0];
4025
+ return new MissingValue();
4026
+ }
4027
+ whenLoaded(relation, ...rest) {
4028
+ const model = this.resource;
4029
+ const loaded = typeof model?.relationLoaded === "function" && model.relationLoaded(relation);
4030
+ if (!loaded) return rest.length >= 2 ? typeof rest[1] === "function" ? rest[1]() : rest[1] : new MissingValue();
4031
+ const value2 = model.getRelation(relation);
4032
+ if (rest.length === 0) return value2;
4033
+ if (value2 === null || value2 === void 0) return null;
4034
+ return rest[0](value2);
4035
+ }
4036
+ whenCounted(relation, ...rest) {
4037
+ const attributes = this.resource?.getAttributes?.() ?? {};
4038
+ const key2 = `${Str.snake(relation)}_count`;
4039
+ if (!Object.hasOwn(attributes, key2)) return rest.length >= 2 ? typeof rest[1] === "function" ? rest[1]() : rest[1] : new MissingValue();
4040
+ const count = attributes[key2] === null ? null : Number(attributes[key2]);
4041
+ if (rest.length === 0) return count;
4042
+ if (count === null) return null;
4043
+ return rest[0](count);
4044
+ }
4045
+ /** The values when the condition holds, else none, for an object spread: `...this.mergeWhen(admin, { secret })`. */
4046
+ mergeWhen(condition, value2) {
4047
+ if (!condition) return {};
4048
+ return typeof value2 === "function" ? value2() : value2;
4049
+ }
4050
+ };
4051
+ var isPaginated = (value2) => typeof value2 === "object" && value2 !== null && typeof value2.items === "function" && typeof value2.getCollection === "function" && typeof value2.toArray === "function";
4052
+ var ResourceCollection = class extends JsonResource {
4053
+ /** The resource each item is made into. An instance field, read when the items are first read. */
4054
+ collects;
4055
+ #collection;
4056
+ /** The items, each made into `collects` (once, when first read: a subclass's field isn't set in the constructor). */
4057
+ get collection() {
4058
+ if (this.#collection === void 0) {
4059
+ const resource = this.resource;
4060
+ const items = isMissing(resource) || resource === null || resource === void 0 ? [] : isPaginated(resource) ? resource.items() : [...resource];
4061
+ const collects = this.collects;
4062
+ this.#collection = new Collection(collects === void 0 ? items : items.map((item) => item instanceof collects ? item : new collects(item)));
4063
+ }
4064
+ return this.#collection;
4065
+ }
4066
+ count() {
4067
+ return this.collection.count();
4068
+ }
4069
+ [Symbol.iterator]() {
4070
+ return this.collection[Symbol.iterator]();
4071
+ }
4072
+ /** Each item resolved: a resource's JSON, or the item itself. */
4073
+ toArray(request2) {
4074
+ return this.collection.all().map((item) => resolveValue(item, request2));
4075
+ }
4076
+ /** Over a paginator, a response with Laravel's links and meta. */
4077
+ response(_request) {
4078
+ return isPaginated(this.resource) ? new PaginatedResourceResponse(this) : new ResourceResponse(this);
4079
+ }
4080
+ };
4081
+ var AnonymousResourceCollection = class extends ResourceCollection {
4082
+ constructor(resource, collects) {
4083
+ super(resource);
4084
+ this.collects = collects;
4085
+ }
4086
+ };
4087
+ anonymousCollection.Class = AnonymousResourceCollection;
3320
4088
 
3321
4089
  // ../Live/dist/index.js
3322
4090
  import { AssertionError } from "assert";
3323
4091
  import { isDeepStrictEqual } from "util";
3324
- import { createHmac, timingSafeEqual } from "crypto";
4092
+ import { createHmac as createHmac2, timingSafeEqual as timingSafeEqual2 } from "crypto";
3325
4093
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
3326
4094
  import { randomBytes as randomBytes2 } from "crypto";
3327
- import { existsSync as existsSync5, readdirSync as readdirSync3 } from "fs";
4095
+ import { existsSync as existsSync6, readdirSync as readdirSync3 } from "fs";
3328
4096
  import { join as join6, relative as relative3, sep as sep2 } from "path";
3329
4097
  import { pathToFileURL as pathToFileURL2 } from "url";
3330
4098
  import { AsyncLocalStorage } from "async_hooks";
3331
4099
  import { existsSync as existsSync24 } from "fs";
3332
- import { mkdir as mkdir3, writeFile as writeFile3 } from "fs/promises";
3333
- import { dirname as dirname3, join as join24, relative as relative22, sep as sep22 } from "path";
4100
+ import { mkdir as mkdir4, writeFile as writeFile4 } from "fs/promises";
4101
+ import { dirname as dirname4, join as join24, relative as relative22, sep as sep22 } from "path";
3334
4102
  var LiveError = class extends Error {
3335
4103
  name = "LiveError";
3336
4104
  kind = "Server";
@@ -3510,9 +4278,9 @@ function temporaryDirectory() {
3510
4278
  return uploadSetting("directory").replace(/^\/+|\/+$/g, "");
3511
4279
  }
3512
4280
  var FILENAME = /^[A-Za-z0-9]{40}(?:\.[a-z0-9]+)?$/;
3513
- function isTemporaryFileData(value) {
3514
- if (typeof value !== "object" || value === null) return false;
3515
- const data = value;
4281
+ function isTemporaryFileData(value2) {
4282
+ if (typeof value2 !== "object" || value2 === null) return false;
4283
+ const data = value2;
3516
4284
  return typeof data.filename === "string" && FILENAME.test(data.filename) && typeof data.name === "string" && typeof data.size === "number" && Number.isSafeInteger(data.size) && data.size >= 0 && typeof data.type === "string" && typeof data.extension === "string" && /^[a-z0-9]*$/.test(data.extension);
3517
4285
  }
3518
4286
  var HOUR = 36e5;
@@ -3568,9 +4336,9 @@ var TemporaryUploadedFile = class {
3568
4336
  return new ReadableStream({
3569
4337
  pull: async (controller) => {
3570
4338
  reader ??= (await temporaryDisk().readStream(this.path)).getReader();
3571
- const { done, value } = await reader.read();
4339
+ const { done, value: value2 } = await reader.read();
3572
4340
  if (done) controller.close();
3573
- else controller.enqueue(value);
4341
+ else controller.enqueue(value2);
3574
4342
  },
3575
4343
  cancel: async (reason) => {
3576
4344
  await reader?.cancel(reason);
@@ -3623,36 +4391,36 @@ var TemporaryUploadedFile = class {
3623
4391
  return container().make(UrlGenerator).temporarySignedRoute("live.preview-file", expires, { filename: this.filename }, false);
3624
4392
  }
3625
4393
  };
3626
- function isModel(value) {
3627
- if (typeof value !== "object" || value === null) return false;
3628
- const candidate = value;
4394
+ function isModel(value2) {
4395
+ if (typeof value2 !== "object" || value2 === null) return false;
4396
+ const candidate = value2;
3629
4397
  return typeof candidate.getKey === "function" && typeof candidate.getKeyName === "function" && typeof candidate.getTable === "function" && typeof candidate.exists === "boolean";
3630
4398
  }
3631
- var isPlainObject3 = (value) => {
3632
- const proto = Object.getPrototypeOf(value);
4399
+ var isPlainObject4 = (value2) => {
4400
+ const proto = Object.getPrototypeOf(value2);
3633
4401
  return proto === Object.prototype || proto === null;
3634
4402
  };
3635
- var isTuple = (value) => Array.isArray(value) && value.length === 2 && typeof value[1] === "object" && value[1] !== null && !Array.isArray(value[1]) && typeof value[1].s === "string";
4403
+ var isTuple = (value2) => Array.isArray(value2) && value2.length === 2 && typeof value2[1] === "object" && value2[1] !== null && !Array.isArray(value2[1]) && typeof value2[1].s === "string";
3636
4404
  function classNameOf(registry, cls) {
3637
4405
  return registry.nameOf(cls) ?? registry.register(cls);
3638
4406
  }
3639
- function dehydrate(value, registry, path, seen = /* @__PURE__ */ new Set()) {
3640
- switch (typeof value) {
4407
+ function dehydrate(value2, registry, path, seen = /* @__PURE__ */ new Set()) {
4408
+ switch (typeof value2) {
3641
4409
  case "undefined":
3642
4410
  return [null, { s: "u" }];
3643
4411
  case "string":
3644
4412
  case "boolean":
3645
- return value;
4413
+ return value2;
3646
4414
  case "number":
3647
- if (!Number.isFinite(value)) throw new LiveError(`Property [${path}] is ${value}: Live state must be JSON (finite numbers only).`);
3648
- return value;
4415
+ if (!Number.isFinite(value2)) throw new LiveError(`Property [${path}] is ${value2}: Live state must be JSON (finite numbers only).`);
4416
+ return value2;
3649
4417
  case "bigint":
3650
4418
  case "symbol":
3651
4419
  case "function":
3652
- throw new LiveError(`Property [${path}] holds a ${typeof value}: Live state may only hold primitives, arrays, plain objects, Dates, models and collections.`);
4420
+ throw new LiveError(`Property [${path}] holds a ${typeof value2}: Live state may only hold primitives, arrays, plain objects, Dates, models and collections.`);
3653
4421
  }
3654
- if (value === null) return null;
3655
- const object = value;
4422
+ if (value2 === null) return null;
4423
+ const object = value2;
3656
4424
  if (seen.has(object)) throw new LiveError(`Property [${path}] contains a circular reference.`);
3657
4425
  seen.add(object);
3658
4426
  try {
@@ -3677,7 +4445,7 @@ function dehydrate(value, registry, path, seen = /* @__PURE__ */ new Set()) {
3677
4445
  const meta = object.constructor === Collection ? { s: "clctn" } : { s: "clctn", class: classNameOf(registry, object.constructor) };
3678
4446
  return [items.map((item, i) => dehydrate(item, registry, `${path}.${i}`, seen)), meta];
3679
4447
  }
3680
- if (isPlainObject3(object)) {
4448
+ if (isPlainObject4(object)) {
3681
4449
  const out = {};
3682
4450
  for (const [key2, item] of Object.entries(object)) out[key2] = dehydrate(item, registry, `${path}.${key2}`, seen);
3683
4451
  return [out, { s: "obj" }];
@@ -3699,9 +4467,9 @@ function collectionClass(registry, name) {
3699
4467
  if (typeof cls !== "function" || !(cls.prototype instanceof Collection)) throw new LiveError(`Unable to hydrate the [${name}] collection: it is not registered.`);
3700
4468
  return cls;
3701
4469
  }
3702
- async function hydrate(value, registry) {
3703
- if (!isTuple(value)) return value;
3704
- const [inner, meta] = value;
4470
+ async function hydrate(value2, registry) {
4471
+ if (!isTuple(value2)) return value2;
4472
+ const [inner, meta] = value2;
3705
4473
  switch (meta.s) {
3706
4474
  case "u":
3707
4475
  return void 0;
@@ -3783,8 +4551,8 @@ function stateOf(component) {
3783
4551
  if (state === void 0) states.set(component, state = { id: "", name: "", errors: {}, dispatches: [], skipRender: false });
3784
4552
  return state;
3785
4553
  }
3786
- function isComponentClass(value) {
3787
- return typeof value === "function" && value[COMPONENT] === true;
4554
+ function isComponentClass(value2) {
4555
+ return typeof value2 === "function" && value2[COMPONENT] === true;
3788
4556
  }
3789
4557
  var ErrorBag = class {
3790
4558
  constructor(messages) {
@@ -3965,8 +4733,8 @@ function trackFlash(session, { saved = true } = {}) {
3965
4733
  };
3966
4734
  }
3967
4735
  var ESCAPES = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#039;" };
3968
- function escapeAttribute2(value) {
3969
- return value.replace(/[&<>"']/g, (char) => ESCAPES[char]);
4736
+ function escapeAttribute2(value2) {
4737
+ return value2.replace(/[&<>"']/g, (char) => ESCAPES[char]);
3970
4738
  }
3971
4739
  function stripTags(html) {
3972
4740
  return html.replace(/<[^>]*>/g, "");
@@ -4013,31 +4781,31 @@ function insertAttributesIntoRoot(html, attributes) {
4013
4781
  const source = html.trim();
4014
4782
  const match = /^((?:<!--[\s\S]*?-->\s*)*<[A-Za-z][\w:-]*)/.exec(source);
4015
4783
  if (match === null) throw new LiveError("Live could not find the root element of the component.");
4016
- const rendered = Object.entries(attributes).map(([name, value]) => ` ${name}="${escapeAttribute2(value)}"`).join("");
4784
+ const rendered = Object.entries(attributes).map(([name, value2]) => ` ${name}="${escapeAttribute2(value2)}"`).join("");
4017
4785
  return match[1] + rendered + source.slice(match[1].length);
4018
4786
  }
4019
- function canonicalJson(value) {
4020
- if (Array.isArray(value)) return `[${value.map((item) => canonicalJson(item === void 0 ? null : item)).join(",")}]`;
4021
- if (typeof value === "object" && value !== null) {
4022
- const entries = Object.keys(value).sort().filter((key2) => value[key2] !== void 0).map((key2) => `${JSON.stringify(key2)}:${canonicalJson(value[key2])}`);
4787
+ function canonicalJson(value2) {
4788
+ if (Array.isArray(value2)) return `[${value2.map((item) => canonicalJson(item === void 0 ? null : item)).join(",")}]`;
4789
+ if (typeof value2 === "object" && value2 !== null) {
4790
+ const entries = Object.keys(value2).sort().filter((key2) => value2[key2] !== void 0).map((key2) => `${JSON.stringify(key2)}:${canonicalJson(value2[key2])}`);
4023
4791
  return `{${entries.join(",")}}`;
4024
4792
  }
4025
- return JSON.stringify(value);
4793
+ return JSON.stringify(value2);
4026
4794
  }
4027
4795
  function checksum(key2, payload) {
4028
- return createHmac("sha256", key2).update(canonicalJson({ data: payload.data, memo: payload.memo })).digest("hex");
4796
+ return createHmac2("sha256", key2).update(canonicalJson({ data: payload.data, memo: payload.memo })).digest("hex");
4029
4797
  }
4030
4798
  function verifyChecksum(key2, payload, given) {
4031
4799
  if (typeof given !== "string") return false;
4032
4800
  const expected = Buffer.from(checksum(key2, payload), "utf8");
4033
4801
  const actual = Buffer.from(given, "utf8");
4034
- return expected.length === actual.length && timingSafeEqual(expected, actual);
4802
+ return expected.length === actual.length && timingSafeEqual2(expected, actual);
4035
4803
  }
4036
4804
  function signatureOf(key2, purpose, payload) {
4037
- return createHmac("sha256", key2).update(`${purpose}|${payload}`).digest("base64url");
4805
+ return createHmac2("sha256", key2).update(`${purpose}|${payload}`).digest("base64url");
4038
4806
  }
4039
- function signValue(key2, purpose, value) {
4040
- const payload = Buffer.from(JSON.stringify(value), "utf8").toString("base64url");
4807
+ function signValue(key2, purpose, value2) {
4808
+ const payload = Buffer.from(JSON.stringify(value2), "utf8").toString("base64url");
4041
4809
  return `${payload}.${signatureOf(key2, purpose, payload)}`;
4042
4810
  }
4043
4811
  function verifiedValue(key2, purpose, token2) {
@@ -4047,7 +4815,7 @@ function verifiedValue(key2, purpose, token2) {
4047
4815
  const payload = token2.slice(0, dot);
4048
4816
  const expected = Buffer.from(signatureOf(key2, purpose, payload), "utf8");
4049
4817
  const given = Buffer.from(token2.slice(dot + 1), "utf8");
4050
- if (expected.length !== given.length || !timingSafeEqual(expected, given)) return void 0;
4818
+ if (expected.length !== given.length || !timingSafeEqual2(expected, given)) return void 0;
4051
4819
  try {
4052
4820
  return JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
4053
4821
  } catch {
@@ -4183,7 +4951,7 @@ function WithFileUploads(Base) {
4183
4951
  function usesFileUploads(component) {
4184
4952
  return component[UPLOADS] === true;
4185
4953
  }
4186
- var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4954
+ var isRecord = (value2) => typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
4187
4955
  var read = (component, path) => path.split(".").reduce((node, segment) => isRecord(node) || Array.isArray(node) ? node[segment] : void 0, component);
4188
4956
  function uploadErrors(name, errors, multiple) {
4189
4957
  if (typeof errors === "string") {
@@ -4202,23 +4970,23 @@ async function runUploadCall(component, method, params, update) {
4202
4970
  if (!usesFileUploads(component)) {
4203
4971
  throw new LiveError(`Cannot handle file upload without [WithFileUploads] on the [${stateOf(component).name}] component class.`);
4204
4972
  }
4205
- const [name, value, multiple] = [String(params[0] ?? ""), params[1], params[2] === true];
4973
+ const [name, value2, multiple] = [String(params[0] ?? ""), params[1], params[2] === true];
4206
4974
  switch (method) {
4207
4975
  case "_startUpload":
4208
4976
  component.skipRender();
4209
4977
  return inject(UrlGenerator).temporarySignedRoute("live.upload-file", uploadSetting("max_upload_time") * 60, void 0, false);
4210
4978
  case "_finishUpload": {
4211
4979
  await cleanupOldUploads();
4212
- const files = (Array.isArray(value) ? value : []).map((reference) => temporaryFileFromReference(reference, stateOf(component).name));
4980
+ const files = (Array.isArray(value2) ? value2 : []).map((reference) => temporaryFileFromReference(reference, stateOf(component).name));
4213
4981
  const current = read(component, name);
4214
4982
  const next = multiple ? files : Array.isArray(current) ? [...current, ...files] : files[0] ?? null;
4215
4983
  await update(name, next);
4216
4984
  return files.map((file) => file.filename);
4217
4985
  }
4218
4986
  case "_uploadErrored":
4219
- throw new UploadValidationError(uploadErrors(name, value, multiple));
4987
+ throw new UploadValidationError(uploadErrors(name, value2, multiple));
4220
4988
  case "_removeUpload": {
4221
- const filename = String(value ?? "");
4989
+ const filename = String(value2 ?? "");
4222
4990
  const current = read(component, name);
4223
4991
  if (Array.isArray(current)) {
4224
4992
  const removed = current.filter((file) => file instanceof TemporaryUploadedFile && file.filename === filename);
@@ -4328,10 +5096,10 @@ var Testable = class _Testable {
4328
5096
  * file input does it: the upload rules, the temporary disk, then a TemporaryUploadedFile (or an array) in the
4329
5097
  * property, or the upload's errors on it (Livewire's).
4330
5098
  */
4331
- async set(path, value) {
4332
- const files = [value].flat();
4333
- if (typeof path === "string" && files.length > 0 && files.every((file) => file instanceof Blob)) return this.upload(path, files, Array.isArray(value));
4334
- return this.#update(typeof path === "string" ? { [path]: value } : path, []);
5099
+ async set(path, value2) {
5100
+ const files = [value2].flat();
5101
+ if (typeof path === "string" && files.length > 0 && files.every((file) => file instanceof Blob)) return this.upload(path, files, Array.isArray(value2));
5102
+ return this.#update(typeof path === "string" ? { [path]: value2 } : path, []);
4335
5103
  }
4336
5104
  /** Uploads `files` into the property `name` (an array when `multiple`), as the browser's upload calls do. */
4337
5105
  async upload(name, files, multiple = false) {
@@ -4368,38 +5136,38 @@ var Testable = class _Testable {
4368
5136
  this.#instance = result.instance;
4369
5137
  return this;
4370
5138
  }
4371
- assertSet(path, value) {
5139
+ assertSet(path, value2) {
4372
5140
  const actual = this.get(path);
4373
- if (!isDeepStrictEqual(actual, value)) fail(`Failed asserting that property [${path}] is set to the expected value.`, actual, value);
5141
+ if (!isDeepStrictEqual(actual, value2)) fail(`Failed asserting that property [${path}] is set to the expected value.`, actual, value2);
4374
5142
  return this;
4375
5143
  }
4376
- assertNotSet(path, value) {
4377
- if (isDeepStrictEqual(this.get(path), value)) fail(`Failed asserting that property [${path}] is not set to the given value.`, this.get(path), value);
5144
+ assertNotSet(path, value2) {
5145
+ if (isDeepStrictEqual(this.get(path), value2)) fail(`Failed asserting that property [${path}] is not set to the given value.`, this.get(path), value2);
4378
5146
  return this;
4379
5147
  }
4380
5148
  /** Each value, HTML-escaped, appears in the rendered HTML. */
4381
5149
  assertSee(...values) {
4382
- for (const value of values) if (!this.html().includes(escapeAttribute2(value))) fail(`Failed asserting that [${value}] is in the rendered HTML.`, this.html(), value);
5150
+ for (const value2 of values) if (!this.html().includes(escapeAttribute2(value2))) fail(`Failed asserting that [${value2}] is in the rendered HTML.`, this.html(), value2);
4383
5151
  return this;
4384
5152
  }
4385
5153
  assertDontSee(...values) {
4386
- for (const value of values) if (this.html().includes(escapeAttribute2(value))) fail(`Failed asserting that [${value}] is not in the rendered HTML.`, this.html(), value);
5154
+ for (const value2 of values) if (this.html().includes(escapeAttribute2(value2))) fail(`Failed asserting that [${value2}] is not in the rendered HTML.`, this.html(), value2);
4387
5155
  return this;
4388
5156
  }
4389
5157
  /** Each value appears in the rendered HTML as written (not escaped). */
4390
5158
  assertSeeHtml(...values) {
4391
- for (const value of values) if (!this.html().includes(value)) fail(`Failed asserting that [${value}] is in the rendered HTML.`, this.html(), value);
5159
+ for (const value2 of values) if (!this.html().includes(value2)) fail(`Failed asserting that [${value2}] is in the rendered HTML.`, this.html(), value2);
4392
5160
  return this;
4393
5161
  }
4394
5162
  /** Each value, HTML-escaped, appears in the rendered text: the HTML with its tags stripped (Livewire's assertSeeText). */
4395
5163
  assertSeeText(...values) {
4396
5164
  const text = stripTags(this.html());
4397
- for (const value of values) if (!text.includes(escapeAttribute2(value))) fail(`Failed asserting that [${value}] is in the rendered text.`, text, value);
5165
+ for (const value2 of values) if (!text.includes(escapeAttribute2(value2))) fail(`Failed asserting that [${value2}] is in the rendered text.`, text, value2);
4398
5166
  return this;
4399
5167
  }
4400
5168
  assertDontSeeText(...values) {
4401
5169
  const text = stripTags(this.html());
4402
- for (const value of values) if (text.includes(escapeAttribute2(value))) fail(`Failed asserting that [${value}] is not in the rendered text.`, text, value);
5170
+ for (const value2 of values) if (text.includes(escapeAttribute2(value2))) fail(`Failed asserting that [${value2}] is not in the rendered text.`, text, value2);
4403
5171
  return this;
4404
5172
  }
4405
5173
  assertDispatched(name, params) {
@@ -4441,9 +5209,9 @@ var Testable = class _Testable {
4441
5209
  return this;
4442
5210
  }
4443
5211
  /** The last call returned `value`. */
4444
- assertReturned(value) {
5212
+ assertReturned(value2) {
4445
5213
  const returned = this.#effects.returns?.at(-1);
4446
- if (!isDeepStrictEqual(returned, value)) fail("Failed asserting that the method returned the expected value.", returned, value);
5214
+ if (!isDeepStrictEqual(returned, value2)) fail("Failed asserting that the method returned the expected value.", returned, value2);
4447
5215
  return this;
4448
5216
  }
4449
5217
  };
@@ -4482,7 +5250,7 @@ async function placeholderHtml(container2, instance, params) {
4482
5250
  return (typeof output === "string" ? output : await views.renderToString(output)).trim();
4483
5251
  }
4484
5252
  function lazyPayload(key2, registry, load) {
4485
- const params = Object.fromEntries(Object.entries(load.params).map(([name, value]) => [name, dehydrate(value, registry, `${load.name}.${name}`)]));
5253
+ const params = Object.fromEntries(Object.entries(load.params).map(([name, value2]) => [name, dehydrate(value2, registry, `${load.name}.${name}`)]));
4486
5254
  return signValue(key2, PURPOSE, { ...load, params });
4487
5255
  }
4488
5256
  async function lazyLoadOf(key2, registry, payload, component) {
@@ -4505,7 +5273,7 @@ function defaultName(cls) {
4505
5273
  return typeof name === "string" && name !== "" ? Str.kebab(name) : void 0;
4506
5274
  }
4507
5275
  function componentFiles(directory) {
4508
- if (!existsSync5(directory)) return [];
5276
+ if (!existsSync6(directory)) return [];
4509
5277
  return readdirSync3(directory, { recursive: true, encoding: "utf8" }).filter((file) => /\.(tsx|ts|jsx|js|mts|mjs)$/.test(file) && !/\.(test|spec|d)\.[^.]+$/.test(file)).map((file) => file.split(sep2).join("/")).sort();
4510
5278
  }
4511
5279
  async function discover(directory) {
@@ -4519,7 +5287,7 @@ async function discover(directory) {
4519
5287
  }
4520
5288
  return found;
4521
5289
  }
4522
- var PERSISTENT_MIDDLEWARE = ["auth", "verified", "guest", "can"];
5290
+ var PERSISTENT_MIDDLEWARE = ["auth", "verified", "guest", "can", "password.confirm"];
4523
5291
  var ROUTER_METHODS = ["getRoutesByMatchOrder", "getPatterns", "getPatternVersion", "getMiddleware", "getMiddlewareGroups", "substituteBindings"];
4524
5292
  function canMatch(router) {
4525
5293
  const methods = router;
@@ -4636,8 +5404,8 @@ async function throughMiddleware(container2, request2, pass, destination) {
4636
5404
  }
4637
5405
  }
4638
5406
  var PAGINATED = /* @__PURE__ */ Symbol.for("oriel:live.pagination");
4639
- function toPage(value) {
4640
- const page = typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" ? Number(value) : Number.NaN;
5407
+ function toPage(value2) {
5408
+ const page = typeof value2 === "number" ? value2 : typeof value2 === "string" && value2.trim() !== "" ? Number(value2) : Number.NaN;
4641
5409
  return Number.isFinite(page) && page >= 1 ? Math.min(Math.floor(page), Number.MAX_SAFE_INTEGER) : 1;
4642
5410
  }
4643
5411
  async function hook(instance, name, ...args) {
@@ -4669,12 +5437,12 @@ function WithPagination(Base) {
4669
5437
  Object.defineProperty(WithPaginationMixin.prototype, PAGINATED, { value: true });
4670
5438
  return WithPaginationMixin;
4671
5439
  }
4672
- function isPaginated(component) {
5440
+ function isPaginated2(component) {
4673
5441
  return component[PAGINATED] === true;
4674
5442
  }
4675
5443
  var rendering = new AsyncLocalStorage();
4676
5444
  function renderPaginated(component, url2, run) {
4677
- return rendering.run(isPaginated(component) ? { component, url: url2 } : void 0, run);
5445
+ return rendering.run(isPaginated2(component) ? { component, url: url2 } : void 0, run);
4678
5446
  }
4679
5447
  function outsidePagination(run) {
4680
5448
  return rendering.run(void 0, run);
@@ -4702,9 +5470,9 @@ function optional(container2, token2) {
4702
5470
  return void 0;
4703
5471
  }
4704
5472
  }
4705
- var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4706
- function setOwn(object, key2, value) {
4707
- Object.defineProperty(object, key2, { value, enumerable: true, writable: true, configurable: true });
5473
+ var isRecord2 = (value2) => typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
5474
+ function setOwn(object, key2, value2) {
5475
+ Object.defineProperty(object, key2, { value: value2, enumerable: true, writable: true, configurable: true });
4708
5476
  }
4709
5477
  async function hook2(instance, name, ...args) {
4710
5478
  const method = instance[name];
@@ -4777,8 +5545,8 @@ var LiveComponentManager = class {
4777
5545
  const lazy = lazyMode(cls, embedParams);
4778
5546
  await hook2(instance, "boot");
4779
5547
  if (lazy !== void 0) return this.mountPlaceholder(instance, params, lazy);
4780
- for (const [property, value] of Object.entries(params)) {
4781
- if (Object.hasOwn(instance, property)) instance[property] = value;
5548
+ for (const [property, value2] of Object.entries(params)) {
5549
+ if (Object.hasOwn(instance, property)) instance[property] = value2;
4782
5550
  }
4783
5551
  this.prepareComputed(instance);
4784
5552
  const request2 = optional(this.container(), HttpRequest);
@@ -4838,8 +5606,8 @@ var LiveComponentManager = class {
4838
5606
  state.errors = { ...snapshot.memo.errors };
4839
5607
  await hook2(instance, "boot");
4840
5608
  const registry = this.registry();
4841
- for (const [property, value] of Object.entries(snapshot.data)) {
4842
- Object.defineProperty(instance, property, { value: await hydrate(value, registry), enumerable: true, writable: true, configurable: true });
5609
+ for (const [property, value2] of Object.entries(snapshot.data)) {
5610
+ Object.defineProperty(instance, property, { value: await hydrate(value2, registry), enumerable: true, writable: true, configurable: true });
4843
5611
  }
4844
5612
  this.prepareComputed(instance);
4845
5613
  const returns = [];
@@ -4847,14 +5615,14 @@ var LiveComponentManager = class {
4847
5615
  if (load === void 0) await hook2(instance, "hydrate");
4848
5616
  try {
4849
5617
  if (load !== void 0) {
4850
- for (const [property, value] of Object.entries(load.params)) {
4851
- if (Object.hasOwn(instance, property)) instance[property] = value;
5618
+ for (const [property, value2] of Object.entries(load.params)) {
5619
+ if (Object.hasOwn(instance, property)) instance[property] = value2;
4852
5620
  }
4853
5621
  loading.set(instance, load.tag);
4854
5622
  await hook2(instance, "mount", load.params);
4855
5623
  returns.push(void 0);
4856
5624
  }
4857
- for (const [path, value] of Object.entries(updates)) await this.applyUpdate(instance, path, value);
5625
+ for (const [path, value2] of Object.entries(updates)) await this.applyUpdate(instance, path, value2);
4858
5626
  for (const call of load === void 0 ? calls : []) returns.push(await this.call(instance, call.method, call.params));
4859
5627
  } catch (error) {
4860
5628
  const errors = error.errors;
@@ -4981,15 +5749,15 @@ var LiveComponentManager = class {
4981
5749
  }
4982
5750
  }
4983
5751
  }
4984
- async applyUpdate(instance, path, value) {
5752
+ async applyUpdate(instance, path, value2) {
4985
5753
  if (!isUpdatable(instance, path)) throw new PropertyNotUpdatableError(path, stateOf(instance).name);
4986
5754
  const [root, ...rest] = path.split(".");
4987
5755
  const key2 = rest.length > 0 ? rest.join(".") : void 0;
4988
5756
  const studly = Str.studly(root);
4989
- await hook2(instance, "updating", path, value);
4990
- await hook2(instance, `updating${studly}`, value, key2);
5757
+ await hook2(instance, "updating", path, value2);
5758
+ await hook2(instance, `updating${studly}`, value2, key2);
4991
5759
  const target2 = instance;
4992
- if (rest.length === 0) target2[root] = value;
5760
+ if (rest.length === 0) target2[root] = value2;
4993
5761
  else {
4994
5762
  const assertSlot = (node2, segment) => {
4995
5763
  if (Array.isArray(node2) && !isArraySlot(node2, segment)) throw new PropertyNotUpdatableError(path, stateOf(instance).name);
@@ -5003,10 +5771,10 @@ var LiveComponentManager = class {
5003
5771
  }
5004
5772
  const last = rest.at(-1);
5005
5773
  assertSlot(node, last);
5006
- Object.defineProperty(node, last, { value, enumerable: true, writable: true, configurable: true });
5774
+ Object.defineProperty(node, last, { value: value2, enumerable: true, writable: true, configurable: true });
5007
5775
  }
5008
- await hook2(instance, "updated", path, value);
5009
- await hook2(instance, `updated${studly}`, value, key2);
5776
+ await hook2(instance, "updated", path, value2);
5777
+ await hook2(instance, `updated${studly}`, value2, key2);
5010
5778
  }
5011
5779
  /** Runs one call from the browser: a magic action, an event, an upload call, or a public method. Returns its return value. */
5012
5780
  async call(instance, method, params) {
@@ -5031,7 +5799,7 @@ var LiveComponentManager = class {
5031
5799
  return void 0;
5032
5800
  }
5033
5801
  }
5034
- if (UPLOAD_CALLS.has(method)) return runUploadCall(instance, method, params, (path, value) => this.applyUpdate(instance, path, value));
5802
+ if (UPLOAD_CALLS.has(method)) return runUploadCall(instance, method, params, (path, value2) => this.applyUpdate(instance, path, value2));
5035
5803
  if (!isCallable(instance, method)) throw new MethodNotCallableError(method, name);
5036
5804
  return instance[method](...params);
5037
5805
  }
@@ -5087,7 +5855,7 @@ var LiveComponentManager = class {
5087
5855
  await hook2(instance, "dehydrate");
5088
5856
  const registry = this.registry();
5089
5857
  const data = {};
5090
- for (const [property, value] of Object.entries(instance)) data[property] = dehydrate(value, registry, `${memo.name}.${property}`);
5858
+ for (const [property, value2] of Object.entries(instance)) data[property] = dehydrate(value2, registry, `${memo.name}.${property}`);
5091
5859
  const signed = { data, memo: { ...memo, errors: { ...stateOf(instance).errors } } };
5092
5860
  return { ...signed, checksum: checksum(this.key(), signed) };
5093
5861
  }
@@ -5114,7 +5882,7 @@ test('{{ name }} renders', async () => {
5114
5882
  `;
5115
5883
  var CLASS_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
5116
5884
  function importPath(from, to) {
5117
- const path = relative22(dirname3(from), to).split(sep22).join("/").replace(/\.tsx?$/, "");
5885
+ const path = relative22(dirname4(from), to).split(sep22).join("/").replace(/\.tsx?$/, "");
5118
5886
  return path.startsWith(".") ? path : `./${path}`;
5119
5887
  }
5120
5888
  function registerLiveCommands(kernel, app) {
@@ -5133,8 +5901,8 @@ function registerLiveCommands(kernel, app) {
5133
5901
  this.error(`Component [${relative22(app.basePath(), file)}] already exists.`);
5134
5902
  return 1;
5135
5903
  }
5136
- await mkdir3(dirname3(file), { recursive: true });
5137
- await writeFile3(file, COMPONENT_STUB.replace("{{ class }}", () => className));
5904
+ await mkdir4(dirname4(file), { recursive: true });
5905
+ await writeFile4(file, COMPONENT_STUB.replace("{{ class }}", () => className));
5138
5906
  this.info(`Component [${relative22(app.basePath(), file)}] created successfully.`);
5139
5907
  if (this.option("test") === true) {
5140
5908
  const testFile = app.basePath(join24("tests", "Feature", "Live", ...segments.slice(0, -1), `${className}.test.ts`));
@@ -5144,8 +5912,8 @@ function registerLiveCommands(kernel, app) {
5144
5912
  }
5145
5913
  const name = segments.map((segment) => Str.kebab(segment)).join(".");
5146
5914
  const test = TEST_STUB.replaceAll("{{ class }}", () => className).replace("{{ component }}", () => importPath(testFile, file)).replace("{{ testCase }}", () => importPath(testFile, app.basePath(join24("tests", "TestCase.ts")))).replace("{{ name }}", () => name);
5147
- await mkdir3(dirname3(testFile), { recursive: true });
5148
- await writeFile3(testFile, test);
5915
+ await mkdir4(dirname4(testFile), { recursive: true });
5916
+ await writeFile4(testFile, test);
5149
5917
  this.info(`Test [${relative22(app.basePath(), testFile)}] created successfully.`);
5150
5918
  }
5151
5919
  return 0;
@@ -5227,12 +5995,12 @@ function Pagination({ paginator, class: className, buttonClass = "btn btn-second
5227
5995
  // ../Testing/dist/index.js
5228
5996
  import { AssertionError as AssertionError2 } from "assert";
5229
5997
  import { isDeepStrictEqual as isDeepStrictEqual2 } from "util";
5230
- import { existsSync as existsSync6, readFileSync as readFileSync4 } from "fs";
5998
+ import { existsSync as existsSync7, readFileSync as readFileSync4 } from "fs";
5231
5999
  import { join as join7 } from "path";
5232
6000
  import { parse as parse2 } from "dotenv";
5233
6001
  import { existsSync as existsSync25 } from "fs";
5234
6002
  import { join as join25 } from "path";
5235
- import { createHmac as createHmac2 } from "crypto";
6003
+ import { createHmac as createHmac3 } from "crypto";
5236
6004
  import { randomUUID } from "crypto";
5237
6005
  import { randomUUID as randomUUID2 } from "crypto";
5238
6006
  import { randomUUID as randomUUID3 } from "crypto";
@@ -5295,12 +6063,12 @@ function freezeSecond(callback) {
5295
6063
  travelTo(at);
5296
6064
  return at;
5297
6065
  }
5298
- function travel(value) {
5299
- return new Wormhole(value);
6066
+ function travel(value2) {
6067
+ return new Wormhole(value2);
5300
6068
  }
5301
6069
  var Wormhole = class {
5302
- constructor(value) {
5303
- this.value = value;
6070
+ constructor(value2) {
6071
+ this.value = value2;
5304
6072
  }
5305
6073
  value;
5306
6074
  millisecond(callback) {
@@ -5371,17 +6139,17 @@ function fail2(message, details = {}) {
5371
6139
  function assert(condition, message, details) {
5372
6140
  if (!condition) fail2(typeof message === "function" ? message() : message, details);
5373
6141
  }
5374
- function format(value) {
5375
- if (typeof value === "string") return JSON.stringify(value);
5376
- if (typeof value === "function") return value.name === "" ? "[Function]" : `[Function ${value.name}]`;
6142
+ function format(value2) {
6143
+ if (typeof value2 === "string") return JSON.stringify(value2);
6144
+ if (typeof value2 === "function") return value2.name === "" ? "[Function]" : `[Function ${value2.name}]`;
5377
6145
  try {
5378
- return JSON.stringify(value, (_key, item) => typeof item === "bigint" ? `${item}n` : item) ?? String(value);
6146
+ return JSON.stringify(value2, (_key, item) => typeof item === "bigint" ? `${item}n` : item) ?? String(value2);
5379
6147
  } catch {
5380
- return String(value);
6148
+ return String(value2);
5381
6149
  }
5382
6150
  }
5383
- function escapeHtml2(value) {
5384
- return value.replace(/[&<>"']/g, (char) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#039;" })[char]);
6151
+ function escapeHtml2(value2) {
6152
+ return value2.replace(/[&<>"']/g, (char) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#039;" })[char]);
5385
6153
  }
5386
6154
  function stripTags2(html) {
5387
6155
  return html.replace(/<[^>]*>/g, "");
@@ -5389,23 +6157,23 @@ function stripTags2(html) {
5389
6157
  function equals(a, b) {
5390
6158
  return isDeepStrictEqual2(canonical(a), canonical(b));
5391
6159
  }
5392
- function canonical(value) {
5393
- if (Array.isArray(value)) return value.map(canonical);
5394
- if (typeof value === "object" && value !== null && Object.getPrototypeOf(value) === Object.prototype) {
5395
- return Object.fromEntries(Object.keys(value).sort().map((key2) => [key2, canonical(value[key2])]));
6160
+ function canonical(value2) {
6161
+ if (Array.isArray(value2)) return value2.map(canonical);
6162
+ if (typeof value2 === "object" && value2 !== null && Object.getPrototypeOf(value2) === Object.prototype) {
6163
+ return Object.fromEntries(Object.keys(value2).sort().map((key2) => [key2, canonical(value2[key2])]));
5396
6164
  }
5397
- return value;
6165
+ return value2;
5398
6166
  }
5399
6167
  function isSubset(subset, actual) {
5400
6168
  if (typeof subset !== "object" || subset === null) return equals(subset, actual);
5401
6169
  if (typeof actual !== "object" || actual === null) return false;
5402
6170
  if (Array.isArray(subset) !== Array.isArray(actual)) return false;
5403
- return Object.entries(subset).every(([key2, value]) => Object.hasOwn(actual, key2) && isSubset(value, actual[key2]));
6171
+ return Object.entries(subset).every(([key2, value2]) => Object.hasOwn(actual, key2) && isSubset(value2, actual[key2]));
5404
6172
  }
5405
- function* objectsIn(value) {
5406
- if (typeof value !== "object" || value === null) return;
5407
- if (!Array.isArray(value)) yield value;
5408
- for (const child of Object.values(value)) yield* objectsIn(child);
6173
+ function* objectsIn(value2) {
6174
+ if (typeof value2 !== "object" || value2 === null) return;
6175
+ if (!Array.isArray(value2)) yield value2;
6176
+ for (const child of Object.values(value2)) yield* objectsIn(child);
5409
6177
  }
5410
6178
  function containsPair(tree, key2, expected) {
5411
6179
  for (const object of objectsIn(tree)) if (Object.hasOwn(object, key2) && isSubset(expected, object[key2])) return true;
@@ -5521,9 +6289,9 @@ function target(db, table, connection) {
5521
6289
  return { table: table.getTable(), connection: db.connection(connection ?? table.getConnectionName?.()) };
5522
6290
  }
5523
6291
  function constrain(query, data) {
5524
- for (const [column, value] of Object.entries(data)) {
5525
- if (value === null) query.whereNull(column);
5526
- else query.where(column, value);
6292
+ for (const [column, value2] of Object.entries(data)) {
6293
+ if (value2 === null) query.whereNull(column);
6294
+ else query.where(column, value2);
5527
6295
  }
5528
6296
  return query;
5529
6297
  }
@@ -5602,7 +6370,7 @@ function parseAddress(address) {
5602
6370
  }
5603
6371
  function dotEnv(cwd) {
5604
6372
  const file = join7(cwd, ".env");
5605
- return existsSync6(file) ? parse2(readFileSync4(file, "utf8")) : {};
6373
+ return existsSync7(file) ? parse2(readFileSync4(file, "utf8")) : {};
5606
6374
  }
5607
6375
  function serverDatabase(connection) {
5608
6376
  if (typeof connection.url === "string" && connection.url !== "") return parseAddress(connection.url);
@@ -5646,16 +6414,16 @@ function testingConfig(env2 = process.env, log = (line) => console.log(line), cw
5646
6414
  };
5647
6415
  }
5648
6416
  function applyEnvironment(values, env2 = process.env) {
5649
- for (const [key2, value] of Object.entries(values)) env2[key2] ??= value;
6417
+ for (const [key2, value2] of Object.entries(values)) env2[key2] ??= value2;
5650
6418
  }
5651
- function clonePlain2(value) {
5652
- if (Array.isArray(value)) return value.map((item) => clonePlain2(item));
5653
- if (typeof value === "object" && value !== null) {
5654
- const proto = Object.getPrototypeOf(value);
5655
- if (proto !== Object.prototype && proto !== null) return value;
5656
- return Object.fromEntries(Object.entries(value).map(([key2, item]) => [key2, clonePlain2(item)]));
6419
+ function clonePlain2(value2) {
6420
+ if (Array.isArray(value2)) return value2.map((item) => clonePlain2(item));
6421
+ if (typeof value2 === "object" && value2 !== null) {
6422
+ const proto = Object.getPrototypeOf(value2);
6423
+ if (proto !== Object.prototype && proto !== null) return value2;
6424
+ return Object.fromEntries(Object.entries(value2).map(([key2, item]) => [key2, clonePlain2(item)]));
5657
6425
  }
5658
- return value;
6426
+ return value2;
5659
6427
  }
5660
6428
  var RefreshDatabaseState = { migrated: false };
5661
6429
  async function runCommand(app, command, parameters = {}) {
@@ -5681,7 +6449,10 @@ function connectionsOf(test) {
5681
6449
  }
5682
6450
  async function beginTransactions(test, connections) {
5683
6451
  const levels = connections.map((connection) => connection.transactionLevel());
5684
- for (const connection of connections) await connection.beginTransaction();
6452
+ for (const connection of connections) {
6453
+ await connection.beginTransaction();
6454
+ connection.ignoreAfterCommitAtCurrentLevel?.();
6455
+ }
5685
6456
  test.beforeApplicationDestroyed(async () => {
5686
6457
  for (const [index, connection] of [...connections.entries()].reverse()) await rollBackTo(connection, levels[index] ?? 0);
5687
6458
  });
@@ -5728,20 +6499,20 @@ var DatabaseTransactions = {
5728
6499
  await beginTransactions(test, connectionsOf(test));
5729
6500
  }
5730
6501
  };
5731
- function typeOf(value) {
5732
- if (value === null) return ["null"];
5733
- if (Array.isArray(value)) return ["array"];
5734
- switch (typeof value) {
6502
+ function typeOf(value2) {
6503
+ if (value2 === null) return ["null"];
6504
+ if (Array.isArray(value2)) return ["array"];
6505
+ switch (typeof value2) {
5735
6506
  case "string":
5736
6507
  return ["string"];
5737
6508
  case "boolean":
5738
6509
  return ["boolean"];
5739
6510
  case "number":
5740
- return Number.isInteger(value) ? ["integer", "number"] : ["double", "float", "number"];
6511
+ return Number.isInteger(value2) ? ["integer", "number"] : ["double", "float", "number"];
5741
6512
  case "object":
5742
6513
  return ["array", "object"];
5743
6514
  default:
5744
- return [typeof value];
6515
+ return [typeof value2];
5745
6516
  }
5746
6517
  }
5747
6518
  var AssertableJson = class _AssertableJson {
@@ -5890,7 +6661,7 @@ var AssertableJson = class _AssertableJson {
5890
6661
  return this;
5891
6662
  }
5892
6663
  whereAll(bindings) {
5893
- for (const [key2, value] of Object.entries(bindings)) this.where(key2, value);
6664
+ for (const [key2, value2] of Object.entries(bindings)) this.where(key2, value2);
5894
6665
  return this;
5895
6666
  }
5896
6667
  /** whereType('id', 'integer'), whereType('name', 'string|null'), whereType('tags', ['array', 'null']). */
@@ -5920,7 +6691,7 @@ var AssertableJson = class _AssertableJson {
5920
6691
  const values = typeof actual === "object" && actual !== null ? Object.values(actual) : [actual];
5921
6692
  const wanted = Array.isArray(expected) ? expected : [expected];
5922
6693
  const missing = wanted.filter(
5923
- (item) => typeof item === "function" ? !values.some((value) => item(value)) : !values.some((value) => equals(toPlain(item), value))
6694
+ (item) => typeof item === "function" ? !values.some((value2) => item(value2)) : !values.some((value2) => equals(toPlain(item), value2))
5924
6695
  );
5925
6696
  assert(missing.length === 0, `Property [${this.dotPath(key2)}] does not contain [${missing.map(format).join(", ")}].`, { actual });
5926
6697
  return this;
@@ -5970,14 +6741,14 @@ var AssertableJson = class _AssertableJson {
5970
6741
  return this.prop();
5971
6742
  }
5972
6743
  };
5973
- function sizeOf(value) {
5974
- if (Array.isArray(value)) return value.length;
5975
- if (typeof value === "object" && value !== null) return Object.keys(value).length;
5976
- if (typeof value === "string") return value.length;
6744
+ function sizeOf(value2) {
6745
+ if (Array.isArray(value2)) return value2.length;
6746
+ if (typeof value2 === "object" && value2 !== null) return Object.keys(value2).length;
6747
+ if (typeof value2 === "string") return value2.length;
5977
6748
  return 0;
5978
6749
  }
5979
- function toPlain(value) {
5980
- return value === void 0 ? void 0 : JSON.parse(JSON.stringify(value));
6750
+ function toPlain(value2) {
6751
+ return value2 === void 0 ? void 0 : JSON.parse(JSON.stringify(value2));
5981
6752
  }
5982
6753
  function inertiaPageOf(response2) {
5983
6754
  let page;
@@ -6013,25 +6784,25 @@ var AssertableInertia = class _AssertableInertia extends AssertableJson {
6013
6784
  return this.#page;
6014
6785
  }
6015
6786
  /** The component name; the page file must exist unless `shouldExist` is false (inertia.testing.ensure_pages_exist). */
6016
- component(value, shouldExist) {
6787
+ component(value2, shouldExist) {
6017
6788
  const actual = this.page.component;
6018
- assert(actual === value, "Unexpected Inertia page component.", { actual, expected: value });
6789
+ assert(actual === value2, "Unexpected Inertia page component.", { actual, expected: value2 });
6019
6790
  const app = this.#app();
6020
6791
  const config = app?.bound(ConfigRepository) ? app.make(ConfigRepository) : void 0;
6021
6792
  if (shouldExist === true || shouldExist === void 0 && config?.get("inertia.testing.ensure_pages_exist", true) !== false) {
6022
6793
  const paths = config?.get("inertia.pages.paths", []) ?? [];
6023
6794
  const extensions = config?.get("inertia.pages.extensions", []) ?? [];
6024
- const exists = paths.some((path) => extensions.some((extension) => existsSync25(join25(path, `${value}.${extension}`))));
6025
- if (!exists) fail2(`Inertia page component file [${value}] does not exist.`);
6795
+ const exists = paths.some((path) => extensions.some((extension) => existsSync25(join25(path, `${value2}.${extension}`))));
6796
+ if (!exists) fail2(`Inertia page component file [${value2}] does not exist.`);
6026
6797
  }
6027
6798
  return this;
6028
6799
  }
6029
- url(value) {
6030
- assert(this.page.url === value, "Unexpected Inertia page url.", { actual: this.page.url, expected: value });
6800
+ url(value2) {
6801
+ assert(this.page.url === value2, "Unexpected Inertia page url.", { actual: this.page.url, expected: value2 });
6031
6802
  return this;
6032
6803
  }
6033
- version(value) {
6034
- assert(this.page.version === value, "Unexpected Inertia asset version.", { actual: this.page.version, expected: value });
6804
+ version(value2) {
6805
+ assert(this.page.version === value2, "Unexpected Inertia asset version.", { actual: this.page.version, expected: value2 });
6035
6806
  return this;
6036
6807
  }
6037
6808
  /** The flash data has `key` (dot paths allowed), equal to `expected` when given. */
@@ -6118,14 +6889,14 @@ var AssertableInertia = class _AssertableInertia extends AssertableJson {
6118
6889
  }
6119
6890
  };
6120
6891
  function cookiePrefix(name, key2) {
6121
- return `${createHmac2("sha1", key2).update(`${name}v2`).digest("hex")}|`;
6892
+ return `${createHmac3("sha1", key2).update(`${name}v2`).digest("hex")}|`;
6122
6893
  }
6123
- function encryptCookie(encrypter, name, value) {
6124
- return encrypter.encrypt(cookiePrefix(name, encrypter.getKey()) + value, false);
6894
+ function encryptCookie(encrypter, name, value2) {
6895
+ return encrypter.encrypt(cookiePrefix(name, encrypter.getKey()) + value2, false);
6125
6896
  }
6126
- function decryptCookie(encrypter, name, value) {
6897
+ function decryptCookie(encrypter, name, value2) {
6127
6898
  try {
6128
- const plain = encrypter.decrypt(value, false);
6899
+ const plain = encrypter.decrypt(value2, false);
6129
6900
  const prefix = cookiePrefix(name, encrypter.getKey());
6130
6901
  return plain.startsWith(prefix) ? plain.slice(prefix.length) : void 0;
6131
6902
  } catch {
@@ -6151,14 +6922,14 @@ function parseSetCookie(header) {
6151
6922
  for (const attribute of attributes) {
6152
6923
  const at = attribute.indexOf("=");
6153
6924
  const key2 = (at === -1 ? attribute : attribute.slice(0, at)).trim().toLowerCase();
6154
- const value = at === -1 ? "" : attribute.slice(at + 1).trim();
6155
- if (key2 === "path") cookie.path = value;
6156
- else if (key2 === "domain") cookie.domain = value;
6157
- else if (key2 === "max-age") cookie.maxAge = Number(value);
6158
- else if (key2 === "expires") cookie.expires = new Date(value);
6925
+ const value2 = at === -1 ? "" : attribute.slice(at + 1).trim();
6926
+ if (key2 === "path") cookie.path = value2;
6927
+ else if (key2 === "domain") cookie.domain = value2;
6928
+ else if (key2 === "max-age") cookie.maxAge = Number(value2);
6929
+ else if (key2 === "expires") cookie.expires = new Date(value2);
6159
6930
  else if (key2 === "httponly") cookie.httpOnly = true;
6160
6931
  else if (key2 === "secure") cookie.secure = true;
6161
- else if (key2 === "samesite") cookie.sameSite = value;
6932
+ else if (key2 === "samesite") cookie.sameSite = value2;
6162
6933
  }
6163
6934
  return cookie;
6164
6935
  }
@@ -6170,7 +6941,7 @@ function responseCookies(response2) {
6170
6941
  return response2.headers.getSetCookie().map(parseSetCookie);
6171
6942
  }
6172
6943
  function cookieHeader(cookies) {
6173
- return [...cookies].map(([name, value]) => `${encodeURIComponent(name)}=${encodeURIComponent(value)}`).join("; ");
6944
+ return [...cookies].map(([name, value2]) => `${encodeURIComponent(name)}=${encodeURIComponent(value2)}`).join("; ");
6174
6945
  }
6175
6946
  var REDIRECTS = /* @__PURE__ */ new Set([201, 301, 302, 303, 307, 308]);
6176
6947
  var TestResponse = class _TestResponse {
@@ -6324,10 +7095,10 @@ ${this.excerpt()}`);
6324
7095
  return this;
6325
7096
  }
6326
7097
  // Headers -----------------------------------------------------------------------------------------------
6327
- assertHeader(name, value) {
7098
+ assertHeader(name, value2) {
6328
7099
  const actual = this.headers.get(name);
6329
7100
  assert(actual !== null, `Header [${name}] not present on response.`);
6330
- if (value !== void 0) assert(actual === value, `Header [${name}] was found, but value [${actual}] does not match [${value}].`, { actual, expected: value });
7101
+ if (value2 !== void 0) assert(actual === value2, `Header [${name}] was found, but value [${actual}] does not match [${value2}].`, { actual, expected: value2 });
6331
7102
  return this;
6332
7103
  }
6333
7104
  assertHeaderMissing(name) {
@@ -6344,49 +7115,49 @@ ${this.excerpt()}`);
6344
7115
  return this;
6345
7116
  }
6346
7117
  // Content -----------------------------------------------------------------------------------------------
6347
- assertContent(value) {
6348
- assert(this.content === value, "Response content does not match.", { actual: this.content, expected: value });
7118
+ assertContent(value2) {
7119
+ assert(this.content === value2, "Response content does not match.", { actual: this.content, expected: value2 });
6349
7120
  return this;
6350
7121
  }
6351
7122
  /** The content contains the value(s); values are HTML-escaped first unless `escape` is false (Laravel). */
6352
- assertSee(value, escape = true) {
6353
- for (const needle of this.needles(value, escape)) {
7123
+ assertSee(value2, escape2 = true) {
7124
+ for (const needle of this.needles(value2, escape2)) {
6354
7125
  assert(this.content.includes(needle), `Failed asserting that the response contains [${needle}].
6355
7126
 
6356
7127
  ${this.excerpt()}`);
6357
7128
  }
6358
7129
  return this;
6359
7130
  }
6360
- assertDontSee(value, escape = true) {
6361
- for (const needle of this.needles(value, escape)) {
7131
+ assertDontSee(value2, escape2 = true) {
7132
+ for (const needle of this.needles(value2, escape2)) {
6362
7133
  assert(!this.content.includes(needle), `Failed asserting that the response does not contain [${needle}].
6363
7134
 
6364
7135
  ${this.excerpt()}`);
6365
7136
  }
6366
7137
  return this;
6367
7138
  }
6368
- assertSeeInOrder(values, escape = true) {
6369
- return this.inOrder(this.content, this.needles(values, escape));
7139
+ assertSeeInOrder(values, escape2 = true) {
7140
+ return this.inOrder(this.content, this.needles(values, escape2));
6370
7141
  }
6371
7142
  /** Like assertSee, against the content with its tags stripped. */
6372
- assertSeeText(value, escape = true) {
7143
+ assertSeeText(value2, escape2 = true) {
6373
7144
  const text = stripTags2(this.content);
6374
- for (const needle of this.needles(value, escape)) {
7145
+ for (const needle of this.needles(value2, escape2)) {
6375
7146
  assert(text.includes(needle), `Failed asserting that the response text contains [${needle}].
6376
7147
 
6377
7148
  ${this.excerpt(text)}`);
6378
7149
  }
6379
7150
  return this;
6380
7151
  }
6381
- assertDontSeeText(value, escape = true) {
7152
+ assertDontSeeText(value2, escape2 = true) {
6382
7153
  const text = stripTags2(this.content);
6383
- for (const needle of this.needles(value, escape)) {
7154
+ for (const needle of this.needles(value2, escape2)) {
6384
7155
  assert(!text.includes(needle), `Failed asserting that the response text does not contain [${needle}].`);
6385
7156
  }
6386
7157
  return this;
6387
7158
  }
6388
- assertSeeTextInOrder(values, escape = true) {
6389
- return this.inOrder(stripTags2(this.content), this.needles(values, escape));
7159
+ assertSeeTextInOrder(values, escape2 = true) {
7160
+ return this.inOrder(stripTags2(this.content), this.needles(values, escape2));
6390
7161
  }
6391
7162
  // JSON --------------------------------------------------------------------------------------------------
6392
7163
  /**
@@ -6451,15 +7222,15 @@ ${this.excerpt(text)}`);
6451
7222
  /** Each key/value pair appears somewhere in the JSON (Laravel's assertJsonFragment). */
6452
7223
  assertJsonFragment(data) {
6453
7224
  const actual = this.json();
6454
- for (const [key2, value] of Object.entries(data)) {
6455
- assert(containsPair(actual, key2, value), `Unable to find JSON fragment ${format({ [key2]: value })} in the response.`, { actual, expected: data });
7225
+ for (const [key2, value2] of Object.entries(data)) {
7226
+ assert(containsPair(actual, key2, value2), `Unable to find JSON fragment ${format({ [key2]: value2 })} in the response.`, { actual, expected: data });
6456
7227
  }
6457
7228
  return this;
6458
7229
  }
6459
7230
  /** Passes when at least one pair of `data` is absent (Laravel's assertJsonMissing). */
6460
7231
  assertJsonMissing(data) {
6461
7232
  const actual = this.json();
6462
- const allPresent = Object.entries(data).every(([key2, value]) => containsPair(actual, key2, value));
7233
+ const allPresent = Object.entries(data).every(([key2, value2]) => containsPair(actual, key2, value2));
6463
7234
  assert(!allPresent, `Found unexpected JSON fragment ${format(data)} in the response.`, { actual });
6464
7235
  return this;
6465
7236
  }
@@ -6471,8 +7242,8 @@ ${this.excerpt(text)}`);
6471
7242
  }
6472
7243
  /** The JSON (or the value at `key`) has `count` elements. */
6473
7244
  assertJsonCount(count, key2) {
6474
- const value = this.json(key2);
6475
- const actual = Array.isArray(value) ? value.length : typeof value === "object" && value !== null ? Object.keys(value).length : -1;
7245
+ const value2 = this.json(key2);
7246
+ const actual = Array.isArray(value2) ? value2.length : typeof value2 === "object" && value2 !== null ? Object.keys(value2).length : -1;
6476
7247
  assert(actual === count, `Failed to assert that the response ${key2 === void 0 ? "" : `[${key2}] `}count matched the expected ${count} (got ${actual}).`, { actual, expected: count });
6477
7248
  return this;
6478
7249
  }
@@ -6522,38 +7293,38 @@ ${this.excerpt()}`);
6522
7293
  return session;
6523
7294
  }
6524
7295
  /** A key (with an optional value or predicate), several keys, or a { key: value } record. */
6525
- assertSessionHas(key2, value) {
7296
+ assertSessionHas(key2, value2) {
6526
7297
  if (Array.isArray(key2)) {
6527
7298
  for (const k of key2) this.assertSessionHas(k);
6528
7299
  return this;
6529
7300
  }
6530
7301
  if (typeof key2 === "object") return this.assertSessionHasAll(key2);
6531
7302
  const session = this.session();
6532
- if (value === void 0) {
7303
+ if (value2 === void 0) {
6533
7304
  assert(session.has(key2), `Session is missing expected key [${key2}].`);
6534
- } else if (typeof value === "function") {
6535
- assert(value(session.get(key2)) === true, `Session value for [${key2}] does not pass the given check.`);
7305
+ } else if (typeof value2 === "function") {
7306
+ assert(value2(session.get(key2)) === true, `Session value for [${key2}] does not pass the given check.`);
6536
7307
  } else {
6537
- assert(equals(session.get(key2), value), `Session value for [${key2}] does not match.`, { actual: session.get(key2), expected: value });
7308
+ assert(equals(session.get(key2), value2), `Session value for [${key2}] does not match.`, { actual: session.get(key2), expected: value2 });
6538
7309
  }
6539
7310
  return this;
6540
7311
  }
6541
7312
  assertSessionHasAll(bindings) {
6542
- for (const [key2, value] of Object.entries(bindings)) this.assertSessionHas(key2, value);
7313
+ for (const [key2, value2] of Object.entries(bindings)) this.assertSessionHas(key2, value2);
6543
7314
  return this;
6544
7315
  }
6545
- assertSessionMissing(key2, value) {
7316
+ assertSessionMissing(key2, value2) {
6546
7317
  const session = this.session();
6547
7318
  for (const k of [key2].flat()) {
6548
- if (value === void 0) assert(!session.has(k), `Session has unexpected key [${k}].`);
6549
- else assert(!equals(session.get(k), value), `Session has unexpected value for [${k}].`);
7319
+ if (value2 === void 0) assert(!session.has(k), `Session has unexpected key [${k}].`);
7320
+ else assert(!equals(session.get(k), value2), `Session has unexpected value for [${k}].`);
6550
7321
  }
6551
7322
  return this;
6552
7323
  }
6553
7324
  /** Old input flashed with the redirect (withInput()). */
6554
- assertSessionHasInput(key2, value) {
7325
+ assertSessionHasInput(key2, value2) {
6555
7326
  const session = this.session();
6556
- const entries = typeof key2 === "string" ? [[key2, value]] : Array.isArray(key2) ? key2.map((k) => [k, void 0]) : Object.entries(key2);
7327
+ const entries = typeof key2 === "string" ? [[key2, value2]] : Array.isArray(key2) ? key2.map((k) => [k, void 0]) : Object.entries(key2);
6557
7328
  for (const [k, expected] of entries) {
6558
7329
  const actual = session.getOldInput(k);
6559
7330
  assert(actual !== void 0, `Session is missing expected key [${k}] in the old input.`);
@@ -6612,16 +7383,16 @@ ${JSON.stringify(errors, null, 2)}`, { actual: errors, expected: {} });
6612
7383
  return responseCookies(this.baseResponse).findLast((cookie) => cookie.name === name);
6613
7384
  }
6614
7385
  /** The cookie is set; with `value`, its (decrypted, unless `encrypted` is false) value matches. */
6615
- assertCookie(name, value, encrypted = true) {
7386
+ assertCookie(name, value2, encrypted = true) {
6616
7387
  const cookie = this.getCookie(name);
6617
7388
  assert(cookie !== void 0, `Cookie [${name}] not present on response.`);
6618
- if (value === void 0) return this;
7389
+ if (value2 === void 0) return this;
6619
7390
  const actual = encrypted ? this.decrypted(cookie) : cookie.value;
6620
- assert(actual === value, `Cookie [${name}] was found, but value [${actual}] does not match [${value}].`, { actual, expected: value });
7391
+ assert(actual === value2, `Cookie [${name}] was found, but value [${actual}] does not match [${value2}].`, { actual, expected: value2 });
6621
7392
  return this;
6622
7393
  }
6623
- assertPlainCookie(name, value) {
6624
- return this.assertCookie(name, value, false);
7394
+ assertPlainCookie(name, value2) {
7395
+ return this.assertCookie(name, value2, false);
6625
7396
  }
6626
7397
  assertCookieExpired(name) {
6627
7398
  const cookie = this.getCookie(name);
@@ -6654,18 +7425,18 @@ ${JSON.stringify(errors, null, 2)}`, { actual: errors, expected: {} });
6654
7425
  return this;
6655
7426
  }
6656
7427
  /** The view received `key` (dot paths allowed), optionally with this value or passing this predicate. */
6657
- assertViewHas(key2, value) {
7428
+ assertViewHas(key2, value2) {
6658
7429
  if (typeof key2 !== "string") return this.assertViewHasAll(key2);
6659
7430
  const data = this.viewDataOf(this.ensureView());
6660
7431
  assert(Arr.has(data, key2), `Failed asserting that the view has key [${key2}].`, { actual: Object.keys(data) });
6661
7432
  const actual = Arr.get(data, key2);
6662
- if (typeof value === "function") assert(value(actual) === true, `View data [${key2}] does not pass the given check.`);
6663
- else if (value !== void 0) assert(equals(actual, value), `View data [${key2}] does not match the expected value.`, { actual, expected: value });
7433
+ if (typeof value2 === "function") assert(value2(actual) === true, `View data [${key2}] does not pass the given check.`);
7434
+ else if (value2 !== void 0) assert(equals(actual, value2), `View data [${key2}] does not match the expected value.`, { actual, expected: value2 });
6664
7435
  return this;
6665
7436
  }
6666
7437
  assertViewHasAll(bindings) {
6667
7438
  if (Array.isArray(bindings)) for (const key2 of bindings) this.assertViewHas(key2);
6668
- else for (const [key2, value] of Object.entries(bindings)) this.assertViewHas(key2, value);
7439
+ else for (const [key2, value2] of Object.entries(bindings)) this.assertViewHas(key2, value2);
6669
7440
  return this;
6670
7441
  }
6671
7442
  assertViewMissing(key2) {
@@ -6735,8 +7506,8 @@ ${this.excerpt()}`;
6735
7506
  if (app === void 0 || !app.bound(Encrypter)) return cookie.value;
6736
7507
  return decryptCookie(app.make(Encrypter), cookie.name, cookie.value);
6737
7508
  }
6738
- needles(value, escape) {
6739
- return [value].flat().map((needle) => escape ? escapeHtml2(needle) : needle);
7509
+ needles(value2, escape2) {
7510
+ return [value2].flat().map((needle) => escape2 ? escapeHtml2(needle) : needle);
6740
7511
  }
6741
7512
  inOrder(haystack, needles) {
6742
7513
  let position = 0;
@@ -6765,8 +7536,8 @@ function forward(target2, overrides, before) {
6765
7536
  get(object, property) {
6766
7537
  before?.();
6767
7538
  if (Object.hasOwn(overrides, property)) return overrides[property];
6768
- const value = Reflect.get(object, property, object);
6769
- return typeof value === "function" ? value.bind(object) : value;
7539
+ const value2 = Reflect.get(object, property, object);
7540
+ return typeof value2 === "function" ? value2.bind(object) : value2;
6770
7541
  }
6771
7542
  });
6772
7543
  }
@@ -6983,14 +7754,14 @@ var HttpClient = class {
6983
7754
  let body;
6984
7755
  const data = options.data ?? {};
6985
7756
  if (verb === "GET" || verb === "HEAD") {
6986
- for (const [key2, value] of flatten(data)) if (typeof value === "string") url2.searchParams.append(key2, value);
7757
+ for (const [key2, value2] of flatten(data)) if (typeof value2 === "string") url2.searchParams.append(key2, value2);
6987
7758
  } else if (options.json) {
6988
7759
  body = JSON.stringify(data);
6989
7760
  } else if (Object.keys(data).length > 0) {
6990
7761
  const fields = flatten(data);
6991
- if (fields.some(([, value]) => typeof value !== "string")) {
7762
+ if (fields.some(([, value2]) => typeof value2 !== "string")) {
6992
7763
  const form = new FormData();
6993
- for (const [key2, value] of fields) form.append(key2, value);
7764
+ for (const [key2, value2] of fields) form.append(key2, value2);
6994
7765
  body = form;
6995
7766
  } else {
6996
7767
  body = new URLSearchParams(fields);
@@ -7011,15 +7782,15 @@ var HttpClient = class {
7011
7782
  /** The cookies as EncryptCookies would leave them, since no middleware runs for a Live test. */
7012
7783
  plainCookies() {
7013
7784
  const plain = {};
7014
- for (const [name, { value, encrypt }] of this.cookies) {
7015
- plain[name] = encrypt ? value : this.decrypted(name, value) ?? value;
7785
+ for (const [name, { value: value2, encrypt }] of this.cookies) {
7786
+ plain[name] = encrypt ? value2 : this.decrypted(name, value2) ?? value2;
7016
7787
  }
7017
7788
  return plain;
7018
7789
  }
7019
7790
  /** A cookie kept from a response is as it was sent: encrypted, unless the app excepts it. */
7020
- decrypted(name, value) {
7791
+ decrypted(name, value2) {
7021
7792
  try {
7022
- return this.app.bound(Encrypter) ? decryptCookie(this.app.make(Encrypter), name, value) : void 0;
7793
+ return this.app.bound(Encrypter) ? decryptCookie(this.app.make(Encrypter), name, value2) : void 0;
7023
7794
  } catch {
7024
7795
  return void 0;
7025
7796
  }
@@ -7028,8 +7799,8 @@ var HttpClient = class {
7028
7799
  const needsKey = [...this.cookies.values()].some(({ encrypt }) => encrypt);
7029
7800
  const encrypter = needsKey && this.app.bound(Encrypter) ? this.app.make(Encrypter) : void 0;
7030
7801
  const values = /* @__PURE__ */ new Map();
7031
- for (const [name, { value, encrypt }] of this.cookies) {
7032
- values.set(name, encrypt && encrypter !== void 0 ? encryptCookie(encrypter, name, value) : value);
7802
+ for (const [name, { value: value2, encrypt }] of this.cookies) {
7803
+ values.set(name, encrypt && encrypter !== void 0 ? encryptCookie(encrypter, name, value2) : value2);
7033
7804
  }
7034
7805
  return cookieHeader(values);
7035
7806
  }
@@ -7050,15 +7821,15 @@ function setClientAddress2(request2, address) {
7050
7821
  }
7051
7822
  function flatten(data, prefix = "") {
7052
7823
  const out = [];
7053
- for (const [key2, value] of Object.entries(data)) {
7824
+ for (const [key2, value2] of Object.entries(data)) {
7054
7825
  const name = prefix === "" ? key2 : `${prefix}[${key2}]`;
7055
- if (value === void 0) continue;
7056
- if (value === null) out.push([name, ""]);
7057
- else if (value instanceof Blob) out.push([name, value]);
7058
- else if (value instanceof Date) out.push([name, value.toISOString()]);
7059
- else if (typeof value === "object") out.push(...flatten(value, name));
7060
- else if (typeof value === "boolean") out.push([name, value ? "1" : "0"]);
7061
- else out.push([name, String(value)]);
7826
+ if (value2 === void 0) continue;
7827
+ if (value2 === null) out.push([name, ""]);
7828
+ else if (value2 instanceof Blob) out.push([name, value2]);
7829
+ else if (value2 instanceof Date) out.push([name, value2.toISOString()]);
7830
+ else if (typeof value2 === "object") out.push(...flatten(value2, name));
7831
+ else if (typeof value2 === "boolean") out.push([name, value2 ? "1" : "0"]);
7832
+ else out.push([name, String(value2)]);
7062
7833
  }
7063
7834
  return out;
7064
7835
  }
@@ -7209,8 +7980,8 @@ var MakesHttpRequests = class extends InteractsWithApplication {
7209
7980
  Object.assign(this.http.headers, headers);
7210
7981
  return this;
7211
7982
  }
7212
- withHeader(name, value) {
7213
- this.http.headers[name] = value;
7983
+ withHeader(name, value2) {
7984
+ this.http.headers[name] = value2;
7214
7985
  return this;
7215
7986
  }
7216
7987
  withToken(token2, type = "Bearer") {
@@ -7226,18 +7997,18 @@ var MakesHttpRequests = class extends InteractsWithApplication {
7226
7997
  }
7227
7998
  /** Cookies are encrypted the way EncryptCookies expects when the app has an Encrypter. */
7228
7999
  withCookies(cookies) {
7229
- for (const [name, value] of Object.entries(cookies)) this.http.cookies.set(name, { value, encrypt: true });
8000
+ for (const [name, value2] of Object.entries(cookies)) this.http.cookies.set(name, { value: value2, encrypt: true });
7230
8001
  return this;
7231
8002
  }
7232
- withCookie(name, value) {
7233
- return this.withCookies({ [name]: value });
8003
+ withCookie(name, value2) {
8004
+ return this.withCookies({ [name]: value2 });
7234
8005
  }
7235
8006
  withUnencryptedCookies(cookies) {
7236
- for (const [name, value] of Object.entries(cookies)) this.http.cookies.set(name, { value, encrypt: false });
8007
+ for (const [name, value2] of Object.entries(cookies)) this.http.cookies.set(name, { value: value2, encrypt: false });
7237
8008
  return this;
7238
8009
  }
7239
- withUnencryptedCookie(name, value) {
7240
- return this.withUnencryptedCookies({ [name]: value });
8010
+ withUnencryptedCookie(name, value2) {
8011
+ return this.withUnencryptedCookies({ [name]: value2 });
7241
8012
  }
7242
8013
  /** Follow redirects (always with GET, like Laravel) and return the final response. */
7243
8014
  followingRedirects() {
@@ -7402,8 +8173,8 @@ var InteractsWithTime = class extends InteractsWithConsole {
7402
8173
  travelTo(date, callback) {
7403
8174
  return callback ? travelTo(date, callback) : travelTo(date);
7404
8175
  }
7405
- travel(value) {
7406
- return travel(value);
8176
+ travel(value2) {
8177
+ return travel(value2);
7407
8178
  }
7408
8179
  travelBack() {
7409
8180
  return travelBack();
@@ -7437,15 +8208,15 @@ function nameOf(target2) {
7437
8208
  if (typeof target2 === "function") return target2.name;
7438
8209
  return target2.constructor.name;
7439
8210
  }
7440
- function matches(item, target2) {
8211
+ function matches2(item, target2) {
7441
8212
  if (typeof target2 === "string") return typeof item === "string" ? item === target2 : typeof item === "object" && item !== null && item.constructor.name === target2;
7442
8213
  return typeof item === "object" && item !== null && item.constructor === target2;
7443
8214
  }
7444
8215
  function matchesAny(item, targets) {
7445
- return targets.some((target2) => matches(item, target2));
8216
+ return targets.some((target2) => matches2(item, target2));
7446
8217
  }
7447
8218
  function sameJob(actual, expected) {
7448
- if (typeof expected === "function" || typeof expected === "string") return matches(actual, expected);
8219
+ if (typeof expected === "function" || typeof expected === "string") return matches2(actual, expected);
7449
8220
  return actual.constructor === expected.constructor && equals({ ...actual }, { ...expected });
7450
8221
  }
7451
8222
  var SHOULD_QUEUE = /* @__PURE__ */ Symbol.for("oriel:bus.shouldQueue");
@@ -7457,7 +8228,7 @@ function isQueueable(job) {
7457
8228
  if (QUEUE_OPTIONS.some((option) => members[option] !== void 0)) return true;
7458
8229
  return typeof members.uniqueId === "function" || typeof members.retryUntil === "function";
7459
8230
  }
7460
- var isClass = (value) => typeof value === "function" && typeof value.prototype?.handle === "function";
8231
+ var isClass = (value2) => typeof value2 === "function" && typeof value2.prototype?.handle === "function";
7461
8232
  var asPair = (listener) => {
7462
8233
  if (Array.isArray(listener) && listener.length === 2 && typeof listener[1] === "string") return [listener[0], listener[1]];
7463
8234
  return isClass(listener) ? [listener, "handle"] : void 0;
@@ -7891,6 +8662,16 @@ var QueueFake = class _QueueFake {
7891
8662
  }
7892
8663
  extend(_driver, _factory) {
7893
8664
  }
8665
+ /** The real manager's, so a job pushed past the fake still reaches the callback. */
8666
+ before(callback) {
8667
+ this.manager?.before(callback);
8668
+ }
8669
+ after(callback) {
8670
+ this.manager?.after(callback);
8671
+ }
8672
+ failing(callback) {
8673
+ this.manager?.failing(callback);
8674
+ }
7894
8675
  // Assertions ---------------------------------------------------------------------------------------------
7895
8676
  /** Pushed at least once; a number asserts the count; a filter gets (job, queue, connection). */
7896
8677
  assertPushed(job, callback) {
@@ -8671,8 +9452,8 @@ var BitWriter = class {
8671
9452
  bytes = [];
8672
9453
  buffer = 0;
8673
9454
  count = 0;
8674
- write(value, bits) {
8675
- this.buffer |= value << this.count;
9455
+ write(value2, bits) {
9456
+ this.buffer |= value2 << this.count;
8676
9457
  this.count += bits;
8677
9458
  while (this.count >= 8) {
8678
9459
  this.bytes.push(this.buffer & 255);
@@ -8900,29 +9681,12 @@ export {
8900
9681
  vite,
8901
9682
  viteReactRefresh,
8902
9683
  Application2 as Application,
8903
- ClosureKernel,
8904
9684
  HttpException,
8905
9685
  HttpResponseException,
8906
9686
  HttpServerError,
8907
- exceedsJsonDepth,
8908
- requestScope,
8909
- currentRequest,
8910
- optionalSession,
8911
- optionalCookieJar,
8912
9687
  HttpRedirectResponse,
8913
9688
  HttpRedirector,
8914
- setClientAddress,
8915
- clientAddress,
8916
- extensionFromMime,
8917
9689
  FormUploadedFile,
8918
- parseBracketKey,
8919
- normalizeLists,
8920
- fromEntries,
8921
- sanitize,
8922
- mergeRecursive,
8923
- isBlank,
8924
- transformLeaves,
8925
- ipMatches,
8926
9690
  IncomingRequest,
8927
9691
  request,
8928
9692
  response,
@@ -8935,39 +9699,26 @@ export {
8935
9699
  abortUnless,
8936
9700
  contentDisposition,
8937
9701
  HttpResponseFactory,
8938
- ConvertEmptyStringsToNull,
8939
9702
  TrimStrings,
9703
+ ConvertEmptyStringsToNull,
9704
+ HandleCors,
9705
+ PreventRequestsDuringMaintenance,
8940
9706
  Kernel,
9707
+ TrustHosts,
8941
9708
  MiddlewareConfiguration,
8942
- applyMiddlewareCallbacks,
8943
- statusText,
8944
- escapeHtml,
8945
- minimalPage,
8946
- stackFrames,
8947
- debugPage,
8948
- statusFor,
8949
- summarizeValidation,
8950
9709
  ErrorHandler,
8951
9710
  ExceptionsConfiguration,
8952
- applyExceptionCallbacks,
8953
- servePublicFile,
8954
9711
  ExportError,
8955
9712
  exportSite,
8956
- bunRuntime,
8957
- serveBun,
8958
- toWebRequest,
8959
- writeResponse,
8960
9713
  nodeRequestHandler,
8961
- serveNode,
8962
- detectRuntime,
8963
9714
  serve,
8964
9715
  routeListRows,
8965
- filterRouteList,
8966
- formatRouteList,
8967
- API_ROUTES_STUB,
8968
- addApiRouting,
8969
- registerHttpCommands,
8970
9716
  HttpServiceProvider,
9717
+ MissingValue,
9718
+ ResourceResponse,
9719
+ JsonResource,
9720
+ ResourceCollection,
9721
+ AnonymousResourceCollection,
8971
9722
  LiveError,
8972
9723
  CorruptComponentPayloadError,
8973
9724
  MethodNotCallableError,
@@ -9044,7 +9795,7 @@ export {
9044
9795
  TestCase,
9045
9796
  install2,
9046
9797
  nameOf,
9047
- matches,
9798
+ matches2 as matches,
9048
9799
  EventFake,
9049
9800
  BusFake,
9050
9801
  QueueFake,
@@ -9058,4 +9809,4 @@ export {
9058
9809
  StorageFake,
9059
9810
  FakeFile
9060
9811
  };
9061
- //# sourceMappingURL=chunk-7GPMFMS7.js.map
9812
+ //# sourceMappingURL=chunk-MG4YEWMV.js.map