@orieljs/framework 0.1.0-alpha.13 → 0.1.0-alpha.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/{chunk-6GMXKQ6O.js → chunk-4NCMY3ZS.js} +48 -2
  2. package/dist/chunk-4NCMY3ZS.js.map +1 -0
  3. package/dist/{chunk-CKH4KCYF.js → chunk-BKA5F3TH.js} +1 -1
  4. package/dist/{chunk-CKH4KCYF.js.map → chunk-BKA5F3TH.js.map} +1 -1
  5. package/dist/{chunk-OTCTQVDQ.js → chunk-UBSIBGXR.js} +233 -54
  6. package/dist/chunk-UBSIBGXR.js.map +1 -0
  7. package/dist/{chunk-ZRTWDJKD.js → chunk-X4N74JDO.js} +98 -4
  8. package/dist/chunk-X4N74JDO.js.map +1 -0
  9. package/dist/contracts.d.ts +4 -1
  10. package/dist/contracts.js +1 -1
  11. package/dist/{index.d-WQpfdIbG.d.ts → index.d-lffxurFs.d.ts} +10 -1
  12. package/dist/index.d.ts +121 -19
  13. package/dist/index.js +408 -183
  14. package/dist/index.js.map +1 -1
  15. package/dist/{jsx-runtime-6um4Mwfb.d.ts → jsx-runtime-Bc5KJzwb.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-B8NOiQC9.d.ts → testing-CVpo7aRl.d.ts} +41 -7
  19. package/dist/testing.d.ts +2 -2
  20. package/dist/testing.js +5 -3
  21. package/docs/authentication.md +40 -1
  22. package/docs/console.md +16 -5
  23. package/docs/database-testing.md +21 -0
  24. package/docs/database.md +12 -0
  25. package/docs/deployment.md +9 -2
  26. package/docs/encryption.md +2 -0
  27. package/docs/installation.md +2 -1
  28. package/docs/live-tests.md +20 -0
  29. package/docs/live.md +2 -0
  30. package/docs/pagination.md +10 -0
  31. package/docs/session.md +19 -2
  32. package/docs/starter-kits.md +4 -0
  33. package/docs/storage.md +21 -3
  34. package/docs/testing.md +9 -6
  35. package/docs/two-factor.md +10 -1
  36. package/docs/views.md +2 -0
  37. package/docs/vite.md +1 -1
  38. package/package.json +54 -38
  39. package/dist/chunk-6GMXKQ6O.js.map +0 -1
  40. package/dist/chunk-OTCTQVDQ.js.map +0 -1
  41. package/dist/chunk-ZRTWDJKD.js.map +0 -1
@@ -10,7 +10,7 @@ import {
10
10
  facade,
11
11
  fileType_exports,
12
12
  inject
13
- } from "./chunk-6GMXKQ6O.js";
13
+ } from "./chunk-4NCMY3ZS.js";
14
14
  import {
15
15
  Application,
16
16
  AuthFactory,
@@ -47,7 +47,7 @@ import {
47
47
  ValidationFactory,
48
48
  ViewFactory,
49
49
  token
50
- } from "./chunk-CKH4KCYF.js";
50
+ } from "./chunk-BKA5F3TH.js";
51
51
 
52
52
  // ../Config/dist/index.js
53
53
  import { existsSync, readFileSync } from "fs";
@@ -700,7 +700,7 @@ var Application2 = class _Application extends Container2 {
700
700
  this.singleton(ClassNames, () => new ClassNameMap(this));
701
701
  }
702
702
  base;
703
- version = "0.1.0-alpha.13";
703
+ version = "0.1.0-alpha.14";
704
704
  providers = [];
705
705
  bootingCallbacks = [];
706
706
  bootedCallbacks = [];
@@ -3292,6 +3292,14 @@ var FileNotPreviewableError = class extends LiveError {
3292
3292
  super(`File with extension "${extension}" is not previewable. See the live.temporary_file_upload.preview_mimes config.`);
3293
3293
  }
3294
3294
  };
3295
+ var UploadAlreadyStoredError = class extends LiveError {
3296
+ constructor(path) {
3297
+ super(`This upload was stored already, at ${path}. Reset the property after storing it.`);
3298
+ this.path = path;
3299
+ }
3300
+ path;
3301
+ name = "UploadAlreadyStoredError";
3302
+ };
3295
3303
  var UploadValidationError = class extends LiveError {
3296
3304
  constructor(errors) {
3297
3305
  super("The upload failed.");
@@ -3411,6 +3419,8 @@ var TemporaryUploadedFile = class {
3411
3419
  mimeType;
3412
3420
  size;
3413
3421
  #extension;
3422
+ /** Where store() put it, once it has. */
3423
+ #storedAt;
3414
3424
  constructor(data) {
3415
3425
  if (!isTemporaryFileData(data)) throw new LiveError("A temporary upload needs a stored name, a name, a size, a type and an extension.");
3416
3426
  this.filename = data.filename;
@@ -3464,17 +3474,34 @@ var TemporaryUploadedFile = class {
3464
3474
  }
3465
3475
  });
3466
3476
  }
3467
- /** Stores a copy under a random name in `directory`, on `disk` (by default the temporary disk, as Livewire's). */
3477
+ /**
3478
+ * Moves the file under a random name to `directory`, on `disk` (by default the temporary disk, as Livewire's), so no
3479
+ * temporary copy is left behind: on a public disk it could be fetched at its address. An upload stores once.
3480
+ */
3468
3481
  store(directory, disk) {
3469
- return container().make(FilesystemManager).disk(disk ?? uploadSetting("disk") ?? void 0).putFile(directory, this);
3470
- }
3471
- storeAs(directory, name, disk) {
3472
- return container().make(FilesystemManager).disk(disk ?? uploadSetting("disk") ?? void 0).putFileAs(directory, this, name);
3482
+ return this.storeAs(directory, this.hashName(), disk);
3483
+ }
3484
+ /** store(), under the name you give it. */
3485
+ async storeAs(directory, name, disk) {
3486
+ if (this.#storedAt !== void 0) throw new UploadAlreadyStoredError(this.#storedAt);
3487
+ const target2 = container().make(FilesystemManager).disk(disk ?? uploadSetting("disk") ?? void 0);
3488
+ const temporary = temporaryDisk();
3489
+ let path;
3490
+ if (target2 === temporary) {
3491
+ const folder = directory.replace(/^\/+|\/+$/g, "");
3492
+ path = folder === "" ? name : `${folder}/${name}`;
3493
+ await target2.move(this.path, path);
3494
+ } else {
3495
+ path = await target2.putFileAs(directory, this, name);
3496
+ await temporary.delete(this.path);
3497
+ }
3498
+ this.#storedAt = path;
3499
+ return path;
3473
3500
  }
3474
3501
  exists() {
3475
3502
  return temporaryDisk().exists(this.path);
3476
3503
  }
3477
- /** Removes the temporary file (a stored copy stays). */
3504
+ /** Removes the temporary file, if it hasn't been stored. */
3478
3505
  delete() {
3479
3506
  return temporaryDisk().delete(this.path);
3480
3507
  }
@@ -3487,6 +3514,7 @@ var TemporaryUploadedFile = class {
3487
3514
  * at least 30 minutes away (Livewire's), so a re-render keeps the same link and the browser doesn't reload it.
3488
3515
  */
3489
3516
  temporaryUrl() {
3517
+ if (this.#storedAt !== void 0) throw new UploadAlreadyStoredError(this.#storedAt);
3490
3518
  if (!this.isPreviewable()) throw new FileNotPreviewableError(this.#extension);
3491
3519
  const expires = new Date((Math.floor((Date.now() + 30 * 6e4) / HOUR) + 1) * HOUR - 1e3);
3492
3520
  return container().make(UrlGenerator).temporarySignedRoute("live.preview-file", expires, { filename: this.filename }, false);
@@ -4133,14 +4161,24 @@ function currentSession() {
4133
4161
  return void 0;
4134
4162
  }
4135
4163
  }
4164
+ function queuedCookies() {
4165
+ const container2 = currentContainer();
4166
+ if (container2?.bound(CookieJar) !== true) return {};
4167
+ try {
4168
+ return Object.fromEntries(container2.make(CookieJar).queued().map((cookie) => [cookie.name, cookie.minutes < 0 ? null : cookie.value]));
4169
+ } catch {
4170
+ return {};
4171
+ }
4172
+ }
4136
4173
  var Testable = class _Testable {
4137
- constructor(manager, scope, result) {
4174
+ constructor(manager, scope, result, cookies) {
4138
4175
  this.manager = manager;
4139
4176
  this.scope = scope;
4140
4177
  this.#snapshot = JSON.stringify(result.snapshot);
4141
4178
  this.#html = result.html ?? "";
4142
4179
  this.#effects = result.effects;
4143
4180
  this.#instance = result.instance;
4181
+ this.#cookies = cookies;
4144
4182
  }
4145
4183
  manager;
4146
4184
  scope;
@@ -4148,6 +4186,7 @@ var Testable = class _Testable {
4148
4186
  #html;
4149
4187
  #effects;
4150
4188
  #instance;
4189
+ #cookies;
4151
4190
  /**
4152
4191
  * Mounts `component` with `params`, as `<Live component={…} {...params} />` would. A lazy component mounts at once
4153
4192
  * (Livewire's withoutLazyLoading()); `{ lazy: true }` renders its placeholder, and `call('__lazyLoad', …)` loads it.
@@ -4155,7 +4194,11 @@ var Testable = class _Testable {
4155
4194
  static async create(component, params = {}) {
4156
4195
  const scope = requestScope2();
4157
4196
  const manager = inject(LiveManager);
4158
- return new _Testable(manager, scope, await scope(() => manager.mountComponent(component, { lazy: false, ...params })));
4197
+ const { result, cookies } = await scope(async () => {
4198
+ const result2 = await manager.mountComponent(component, { lazy: false, ...params });
4199
+ return { result: result2, cookies: queuedCookies() };
4200
+ });
4201
+ return new _Testable(manager, scope, result, cookies);
4159
4202
  }
4160
4203
  /** The component instance after the last request. */
4161
4204
  instance() {
@@ -4173,6 +4216,10 @@ var Testable = class _Testable {
4173
4216
  effects() {
4174
4217
  return this.#effects;
4175
4218
  }
4219
+ /** The cookies the last request queued, by name; null for one it deleted. */
4220
+ cookies() {
4221
+ return { ...this.#cookies };
4222
+ }
4176
4223
  /**
4177
4224
  * Sets public properties through an update. A file (a FakeFile) or an array of files is uploaded as `o:model` on a
4178
4225
  * file input does it: the upload rules, the temporary disk, then a TemporaryUploadedFile (or an array) in the
@@ -4205,12 +4252,13 @@ var Testable = class _Testable {
4205
4252
  return this.#update({}, [{ method: "$refresh", params: [] }]);
4206
4253
  }
4207
4254
  async #update(updates, calls) {
4208
- const result = await this.scope(async () => {
4255
+ const { result, cookies } = await this.scope(async () => {
4209
4256
  const flashed = trackFlash(currentSession(), { saved: false });
4210
4257
  const updated = await this.manager.updateComponent(this.#snapshot, updates, calls);
4211
4258
  flashed(updated.effects.redirect !== void 0);
4212
- return updated;
4259
+ return { result: updated, cookies: queuedCookies() };
4213
4260
  });
4261
+ this.#cookies = cookies;
4214
4262
  this.#snapshot = JSON.stringify(result.snapshot);
4215
4263
  if (result.html !== void 0) this.#html = result.html;
4216
4264
  this.#effects = result.effects;
@@ -5046,11 +5094,12 @@ function urlWindow(current, last, onEachSide) {
5046
5094
  if (current > last - size) return [...range(1, 2), "...", ...range(last - (size + (onEachSide - 1)), last)];
5047
5095
  return [...range(1, 2), "...", ...range(current - onEachSide, current + onEachSide), "...", ...range(last - 1, last)];
5048
5096
  }
5049
- function button(label, action, attributes = "") {
5097
+ var classAttribute = (classes) => classes === "" ? "" : ` class="${escapeAttribute2(classes)}"`;
5098
+ function button(label, action, classes, attributes = "") {
5050
5099
  const live2 = action === void 0 ? " disabled" : ` o:click="${escapeAttribute2(action)}"`;
5051
- return `<button type="button" class="btn btn-secondary"${attributes}${live2}>${escapeAttribute2(label)}</button>`;
5100
+ return `<button type="button"${classAttribute(classes)}${attributes}${live2}>${escapeAttribute2(label)}</button>`;
5052
5101
  }
5053
- function Pagination({ paginator, class: className }) {
5102
+ function Pagination({ paginator, class: className, buttonClass = "btn btn-secondary", currentClass = "btn" }) {
5054
5103
  if (typeof paginator.nextCursor === "function") {
5055
5104
  throw new LiveError("<Pagination> needs paginate() or simplePaginate(): a cursor paginator has no page numbers.");
5056
5105
  }
@@ -5058,26 +5107,28 @@ function Pagination({ paginator, class: className }) {
5058
5107
  const onFirst = paginator.onFirstPage();
5059
5108
  const hasMore = paginator.hasMorePages();
5060
5109
  if (onFirst && !hasMore) return { toHtml: () => "" };
5061
- const parts = [button("\xAB Previous", onFirst ? void 0 : "previousPage")];
5110
+ const parts = [button("\xAB Previous", onFirst ? void 0 : "previousPage", buttonClass)];
5062
5111
  if (typeof paginator.lastPage === "function") {
5063
5112
  const onEachSide = Number.isInteger(paginator.onEachSideCount) && paginator.onEachSideCount >= 0 ? paginator.onEachSideCount : 3;
5064
5113
  for (const page of urlWindow(current, paginator.lastPage(), onEachSide)) {
5065
5114
  if (page === "...") parts.push('<span aria-hidden="true">...</span>');
5066
- else if (page === current) parts.push(`<button type="button" class="btn" aria-current="page" disabled>${page}</button>`);
5067
- else parts.push(button(String(page), `gotoPage(${page})`, ` aria-label="Go to page ${page}"`));
5115
+ else if (page === current) parts.push(`<button type="button"${classAttribute(currentClass)} aria-current="page" disabled>${page}</button>`);
5116
+ else parts.push(button(String(page), `gotoPage(${page})`, buttonClass, ` aria-label="Go to page ${page}"`));
5068
5117
  }
5069
5118
  }
5070
- parts.push(button("Next \xBB", hasMore ? "nextPage" : void 0));
5071
- const classes = className === void 0 || className === "" ? "" : ` class="${escapeAttribute2(className)}"`;
5072
- const html = `<nav aria-label="Pagination"${classes}>${parts.join("")}</nav>`;
5119
+ parts.push(button("Next \xBB", hasMore ? "nextPage" : void 0, buttonClass));
5120
+ const html = `<nav aria-label="Pagination"${classAttribute(className ?? "")}>${parts.join("")}</nav>`;
5073
5121
  return { toHtml: () => html };
5074
5122
  }
5075
5123
 
5076
5124
  // ../Testing/dist/index.js
5077
5125
  import { AssertionError as AssertionError2 } from "assert";
5078
5126
  import { isDeepStrictEqual as isDeepStrictEqual2 } from "util";
5079
- import { existsSync as existsSync6 } from "fs";
5127
+ import { existsSync as existsSync6, readFileSync as readFileSync4 } from "fs";
5080
5128
  import { join as join7 } from "path";
5129
+ import { parse as parse2 } from "dotenv";
5130
+ import { existsSync as existsSync25 } from "fs";
5131
+ import { join as join25 } from "path";
5081
5132
  import { createHmac as createHmac2 } from "crypto";
5082
5133
  import { randomUUID } from "crypto";
5083
5134
  import { randomUUID as randomUUID2 } from "crypto";
@@ -5286,6 +5337,7 @@ var PendingCommand = class {
5286
5337
  app;
5287
5338
  command;
5288
5339
  parameters;
5340
+ answers = [];
5289
5341
  checks = [];
5290
5342
  result;
5291
5343
  /** A line of output equals `line` exactly; with no argument, the command printed something. */
@@ -5338,6 +5390,11 @@ ${output}`, { actual: output, expected: text }));
5338
5390
  assertFailed() {
5339
5391
  return this.assertNotExitCode(0);
5340
5392
  }
5393
+ /** Answers the command's questions (ask(), secret(), confirm(), choice()), in order. A question beyond them fails. */
5394
+ withAnswers(...answers) {
5395
+ this.answers.push(...answers);
5396
+ return this;
5397
+ }
5341
5398
  /** Runs the command once and checks the expectations; resolves to the exit code. */
5342
5399
  run() {
5343
5400
  return this.result ??= this.execute();
@@ -5348,7 +5405,7 @@ ${output}`, { actual: output, expected: text }));
5348
5405
  async execute() {
5349
5406
  if (!this.app.bound(ConsoleKernel)) throw new Error(`Cannot run [${this.command}]: the Console component (ConsoleKernel) is not registered.`);
5350
5407
  const kernel = this.app.make(ConsoleKernel);
5351
- const exitCode = await kernel.call(this.command, this.parameters);
5408
+ const exitCode = await kernel.call(this.command, this.parameters, { answers: this.answers });
5352
5409
  const output = kernel.output();
5353
5410
  const lines = output.split("\n").map((line) => line.replace(/\r$/, ""));
5354
5411
  for (const check of this.checks) check(output, lines, exitCode);
@@ -5407,6 +5464,96 @@ async function assertNotSoftDeleted(db, table, data = {}, connection, deletedAtC
5407
5464
  const count = await constrain(t.connection.table(t.table), t.data).whereNull(t.column).count();
5408
5465
  assert(count > 0, `Failed asserting that any existing row in the table [${t.table}] matches the attributes ${JSON.stringify(t.data, null, 2)}.`);
5409
5466
  }
5467
+ var TESTING_ENVIRONMENT = Object.freeze({
5468
+ APP_ENV: "testing",
5469
+ BCRYPT_ROUNDS: "4",
5470
+ CACHE_STORE: "array",
5471
+ DB_CONNECTION: "sqlite",
5472
+ DB_DATABASE: ":memory:",
5473
+ DB_URL: "",
5474
+ MAIL_MAILER: "array",
5475
+ QUEUE_CONNECTION: "sync",
5476
+ SESSION_DRIVER: "array"
5477
+ });
5478
+ var DRIVERS = {
5479
+ "postgres:": { driver: "pgsql", port: "5432" },
5480
+ "postgresql:": { driver: "pgsql", port: "5432" },
5481
+ "mysql:": { driver: "mysql", port: "3306" },
5482
+ "mariadb:": { driver: "mysql", port: "3306" }
5483
+ };
5484
+ var DEFAULT_PORTS = { pgsql: "5432", mysql: "3306", mariadb: "3306" };
5485
+ var LOOPBACK = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
5486
+ var placeOf = (host, port, database) => `${LOOPBACK.has(host.toLowerCase()) ? "localhost" : host.toLowerCase()}:${port}/${database}`;
5487
+ function parseAddress(address) {
5488
+ let url2;
5489
+ try {
5490
+ url2 = new URL(address);
5491
+ } catch {
5492
+ return void 0;
5493
+ }
5494
+ const known = DRIVERS[url2.protocol];
5495
+ if (known === void 0) return void 0;
5496
+ const database = decodeURIComponent(url2.pathname.slice(1));
5497
+ const port = url2.port || known.port;
5498
+ return { driver: known.driver, database, place: placeOf(url2.hostname, port, database), shown: `${url2.hostname}:${port}/${database}` };
5499
+ }
5500
+ function dotEnv(cwd) {
5501
+ const file = join7(cwd, ".env");
5502
+ return existsSync6(file) ? parse2(readFileSync4(file, "utf8")) : {};
5503
+ }
5504
+ function serverDatabase(connection) {
5505
+ if (typeof connection.url === "string" && connection.url !== "") return parseAddress(connection.url);
5506
+ const driver = String(connection.driver ?? "");
5507
+ const port = DEFAULT_PORTS[driver];
5508
+ if (port === void 0) return void 0;
5509
+ const host = String(connection.host ?? "127.0.0.1");
5510
+ const at = String(connection.port ?? port);
5511
+ const database = String(connection.database ?? "oriel");
5512
+ return { driver, place: placeOf(host, at, database), shown: `${host}:${at}/${database}` };
5513
+ }
5514
+ function ownDatabases(env2, cwd) {
5515
+ const file = dotEnv(cwd);
5516
+ const setting = (key2) => env2[key2] !== void 0 && env2[key2] !== "" ? env2[key2] : file[key2] !== "" ? file[key2] : void 0;
5517
+ const places = [];
5518
+ for (const url2 of [env2.DB_URL, file.DB_URL]) {
5519
+ const place = url2 === void 0 || url2 === "" ? void 0 : parseAddress(url2)?.place;
5520
+ if (place !== void 0) places.push(place);
5521
+ }
5522
+ const port = DEFAULT_PORTS[setting("DB_CONNECTION") ?? ""];
5523
+ if (port !== void 0) places.push(placeOf(setting("DB_HOST") ?? "127.0.0.1", setting("DB_PORT") ?? port, setting("DB_DATABASE") ?? "oriel"));
5524
+ return places;
5525
+ }
5526
+ function testingConfig(env2 = process.env, log = (line) => console.log(line), cwd = process.cwd()) {
5527
+ const address = env2.TEST_DATABASE_URL;
5528
+ if (address === void 0 || address === "") {
5529
+ const ignored = env2.DB_CONNECTION !== void 0 && env2.DB_CONNECTION !== "" && env2.DB_CONNECTION !== "sqlite" || env2.DB_URL !== void 0 && env2.DB_URL !== "";
5530
+ log(`Tests run on SQLite, in memory.${ignored ? " DB_CONNECTION and DB_URL are ignored in tests: set TEST_DATABASE_URL to use another database." : ""}`);
5531
+ return { env: { ...TESTING_ENVIRONMENT }, fileParallelism: true };
5532
+ }
5533
+ const database = parseAddress(address);
5534
+ if (database === void 0) throw new Error("TEST_DATABASE_URL must be a postgres:// or mysql:// address.");
5535
+ if (database.database === "") throw new Error("TEST_DATABASE_URL must name a database.");
5536
+ if (ownDatabases(env2, cwd).includes(database.place)) {
5537
+ throw new Error("TEST_DATABASE_URL is the app's own database (DB_URL): the tests would wipe it.");
5538
+ }
5539
+ log(`Tests run on ${database.driver} at ${database.shown} (TEST_DATABASE_URL), one file at a time.`);
5540
+ return {
5541
+ env: { ...TESTING_ENVIRONMENT, DB_CONNECTION: database.driver, DB_URL: address, DB_DATABASE: database.database },
5542
+ fileParallelism: false
5543
+ };
5544
+ }
5545
+ function applyEnvironment(values, env2 = process.env) {
5546
+ for (const [key2, value] of Object.entries(values)) env2[key2] ??= value;
5547
+ }
5548
+ function clonePlain2(value) {
5549
+ if (Array.isArray(value)) return value.map((item) => clonePlain2(item));
5550
+ if (typeof value === "object" && value !== null) {
5551
+ const proto = Object.getPrototypeOf(value);
5552
+ if (proto !== Object.prototype && proto !== null) return value;
5553
+ return Object.fromEntries(Object.entries(value).map(([key2, item]) => [key2, clonePlain2(item)]));
5554
+ }
5555
+ return value;
5556
+ }
5410
5557
  var RefreshDatabaseState = { migrated: false };
5411
5558
  async function runCommand(app, command, parameters = {}) {
5412
5559
  if (!app.bound(ConsoleKernel)) throw new Error(`Running [${command}] needs the Console component (ConsoleKernel is not bound).`);
@@ -5422,7 +5569,8 @@ function seedOptions(test) {
5422
5569
  function usingInMemoryDatabase(app) {
5423
5570
  const config = app.make(ConfigRepository);
5424
5571
  const name = config.get("database.default");
5425
- return name !== void 0 && config.get(`database.connections.${name}.database`) === ":memory:";
5572
+ if (name === void 0) return false;
5573
+ return config.get(`database.connections.${name}.driver`) === "sqlite" && config.get(`database.connections.${name}.database`) === ":memory:";
5426
5574
  }
5427
5575
  function connectionsOf(test) {
5428
5576
  const db = test.app.make(DatabaseManager);
@@ -5444,9 +5592,19 @@ async function rollBackTo(connection, level) {
5444
5592
  current = next;
5445
5593
  }
5446
5594
  }
5595
+ function refuseOwnDatabase(app, trait) {
5596
+ const config = app.make(ConfigRepository);
5597
+ const connection = config.get(`database.connections.${config.get("database.default")}`);
5598
+ const target2 = serverDatabase(connection ?? {});
5599
+ if (target2 === void 0 || !ownDatabases({}, app.basePath()).includes(target2.place)) return;
5600
+ throw new Error(
5601
+ `${trait} would empty the app's own database (${target2.driver} at ${target2.shown}, from .env). Give the tests a database of their own: set TEST_DATABASE_URL, and spread testingConfig() into vitest.config.ts.`
5602
+ );
5603
+ }
5447
5604
  var RefreshDatabase = {
5448
5605
  async setUp(test) {
5449
5606
  if (usingInMemoryDatabase(test.app)) return runCommand(test.app, "migrate", seedOptions(test));
5607
+ refuseOwnDatabase(test.app, "RefreshDatabase");
5450
5608
  if (!RefreshDatabaseState.migrated) {
5451
5609
  if (test.migrateFreshUsing !== void 0) await test.migrateFreshUsing();
5452
5610
  else await runCommand(test.app, "migrate:fresh", seedOptions(test));
@@ -5457,6 +5615,7 @@ var RefreshDatabase = {
5457
5615
  };
5458
5616
  var DatabaseMigrations = {
5459
5617
  async setUp(test) {
5618
+ refuseOwnDatabase(test.app, "DatabaseMigrations");
5460
5619
  await runCommand(test.app, "migrate:fresh", seedOptions(test));
5461
5620
  test.beforeApplicationDestroyed(() => runCommand(test.app, "migrate:rollback"));
5462
5621
  }
@@ -5466,28 +5625,6 @@ var DatabaseTransactions = {
5466
5625
  await beginTransactions(test, connectionsOf(test));
5467
5626
  }
5468
5627
  };
5469
- var TESTING_ENVIRONMENT = Object.freeze({
5470
- APP_ENV: "testing",
5471
- BCRYPT_ROUNDS: "4",
5472
- CACHE_STORE: "array",
5473
- DB_CONNECTION: "sqlite",
5474
- DB_DATABASE: ":memory:",
5475
- MAIL_MAILER: "array",
5476
- QUEUE_CONNECTION: "sync",
5477
- SESSION_DRIVER: "array"
5478
- });
5479
- function applyEnvironment(values, env2 = process.env) {
5480
- for (const [key2, value] of Object.entries(values)) env2[key2] ??= value;
5481
- }
5482
- function clonePlain2(value) {
5483
- if (Array.isArray(value)) return value.map((item) => clonePlain2(item));
5484
- if (typeof value === "object" && value !== null) {
5485
- const proto = Object.getPrototypeOf(value);
5486
- if (proto !== Object.prototype && proto !== null) return value;
5487
- return Object.fromEntries(Object.entries(value).map(([key2, item]) => [key2, clonePlain2(item)]));
5488
- }
5489
- return value;
5490
- }
5491
5628
  function typeOf(value) {
5492
5629
  if (value === null) return ["null"];
5493
5630
  if (Array.isArray(value)) return ["array"];
@@ -5781,7 +5918,7 @@ var AssertableInertia = class _AssertableInertia extends AssertableJson {
5781
5918
  if (shouldExist === true || shouldExist === void 0 && config?.get("inertia.testing.ensure_pages_exist", true) !== false) {
5782
5919
  const paths = config?.get("inertia.pages.paths", []) ?? [];
5783
5920
  const extensions = config?.get("inertia.pages.extensions", []) ?? [];
5784
- const exists = paths.some((path) => extensions.some((extension) => existsSync6(join7(path, `${value}.${extension}`))));
5921
+ const exists = paths.some((path) => extensions.some((extension) => existsSync25(join25(path, `${value}.${extension}`))));
5785
5922
  if (!exists) fail2(`Inertia page component file [${value}] does not exist.`);
5786
5923
  }
5787
5924
  return this;
@@ -6617,16 +6754,39 @@ var HttpClient = class {
6617
6754
  const result = await scope.run(async () => {
6618
6755
  this.beforeRequest(scope, context);
6619
6756
  if (context.session !== void 0) this.applyPending(context.session);
6620
- scope.instance(HttpRequest, new IncomingRequest(request2));
6757
+ const incoming = new IncomingRequest(request2);
6758
+ incoming.setCookies(this.plainCookies());
6759
+ scope.instance(HttpRequest, incoming);
6621
6760
  if (scope.bound(AuthFactory)) {
6622
6761
  try {
6623
6762
  await scope.make(AuthFactory).guard().check();
6624
6763
  } catch {
6625
6764
  }
6626
6765
  }
6627
- return run();
6766
+ const result2 = await run();
6767
+ if (scope.bound(CookieJar)) {
6768
+ for (const cookie of scope.make(CookieJar).queued()) {
6769
+ if (cookie.minutes < 0) this.cookies.delete(cookie.name);
6770
+ else this.cookies.set(cookie.name, { value: cookie.value, encrypt: true });
6771
+ }
6772
+ }
6773
+ if (scope.bound(AuthFactory)) {
6774
+ try {
6775
+ ;
6776
+ scope.make(AuthFactory).guard().keepPasswordHash?.();
6777
+ } catch {
6778
+ }
6779
+ }
6780
+ return result2;
6628
6781
  });
6629
6782
  await scope.run(() => this.afterRequest(scope, context));
6783
+ if (context.session !== void 0) {
6784
+ const carried = clonePlain2(context.session.all());
6785
+ this.sessionChanges.splice(0, Infinity, (session) => {
6786
+ session.flush();
6787
+ session.put(clonePlain2(carried));
6788
+ });
6789
+ }
6630
6790
  return result;
6631
6791
  }
6632
6792
  /** Runs the request through the app's real HttpKernel, in a request scope this client owns. */
@@ -6745,8 +6905,25 @@ var HttpClient = class {
6745
6905
  const configured = this.app.bound(ConfigRepository) ? this.app.make(ConfigRepository).get("app.url") : void 0;
6746
6906
  return typeof configured === "string" && configured !== "" ? configured : "http://localhost";
6747
6907
  }
6908
+ /** The cookies as EncryptCookies would leave them, since no middleware runs for a Live test. */
6909
+ plainCookies() {
6910
+ const plain = {};
6911
+ for (const [name, { value, encrypt }] of this.cookies) {
6912
+ plain[name] = encrypt ? value : this.decrypted(name, value) ?? value;
6913
+ }
6914
+ return plain;
6915
+ }
6916
+ /** A cookie kept from a response is as it was sent: encrypted, unless the app excepts it. */
6917
+ decrypted(name, value) {
6918
+ try {
6919
+ return this.app.bound(Encrypter) ? decryptCookie(this.app.make(Encrypter), name, value) : void 0;
6920
+ } catch {
6921
+ return void 0;
6922
+ }
6923
+ }
6748
6924
  cookieHeader() {
6749
- const encrypter = this.app.bound(Encrypter) ? this.app.make(Encrypter) : void 0;
6925
+ const needsKey = [...this.cookies.values()].some(({ encrypt }) => encrypt);
6926
+ const encrypter = needsKey && this.app.bound(Encrypter) ? this.app.make(Encrypter) : void 0;
6750
6927
  const values = /* @__PURE__ */ new Map();
6751
6928
  for (const [name, { value, encrypt }] of this.cookies) {
6752
6929
  values.set(name, encrypt && encrypter !== void 0 ? encryptCookie(encrypter, name, value) : value);
@@ -8697,6 +8874,7 @@ export {
8697
8874
  InvalidUploadSignatureError,
8698
8875
  TemporaryFileNotFoundError,
8699
8876
  FileNotPreviewableError,
8877
+ UploadAlreadyStoredError,
8700
8878
  UploadValidationError,
8701
8879
  On,
8702
8880
  Locked,
@@ -8731,14 +8909,15 @@ export {
8731
8909
  travel,
8732
8910
  Wormhole,
8733
8911
  PendingCommand,
8912
+ TESTING_ENVIRONMENT,
8913
+ testingConfig,
8914
+ applyEnvironment,
8734
8915
  RefreshDatabaseState,
8735
8916
  runCommand,
8736
8917
  usingInMemoryDatabase,
8737
8918
  RefreshDatabase,
8738
8919
  DatabaseMigrations,
8739
8920
  DatabaseTransactions,
8740
- TESTING_ENVIRONMENT,
8741
- applyEnvironment,
8742
8921
  AssertableJson,
8743
8922
  inertiaPageOf,
8744
8923
  AssertableInertia,
@@ -8776,4 +8955,4 @@ export {
8776
8955
  StorageFake,
8777
8956
  FakeFile
8778
8957
  };
8779
- //# sourceMappingURL=chunk-OTCTQVDQ.js.map
8958
+ //# sourceMappingURL=chunk-UBSIBGXR.js.map