@orieljs/framework 0.1.0-alpha.12 → 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.
- package/dist/{chunk-MURTCTRH.js → chunk-4NCMY3ZS.js} +48 -2
- package/dist/chunk-4NCMY3ZS.js.map +1 -0
- package/dist/{chunk-HTJKT2R2.js → chunk-BKA5F3TH.js} +1 -1
- package/dist/{chunk-HTJKT2R2.js.map → chunk-BKA5F3TH.js.map} +1 -1
- package/dist/{chunk-7NA4HALO.js → chunk-UBSIBGXR.js} +236 -54
- package/dist/chunk-UBSIBGXR.js.map +1 -0
- package/dist/{chunk-24673JQF.js → chunk-X4N74JDO.js} +98 -4
- package/dist/chunk-X4N74JDO.js.map +1 -0
- package/dist/contracts.d.ts +11 -1
- package/dist/contracts.js +1 -1
- package/dist/{index.d-WQpfdIbG.d.ts → index.d-lffxurFs.d.ts} +10 -1
- package/dist/index.d.ts +363 -19
- package/dist/index.js +1193 -189
- package/dist/index.js.map +1 -1
- package/dist/{jsx-runtime-6um4Mwfb.d.ts → jsx-runtime-Bc5KJzwb.d.ts} +1 -1
- package/dist/jsx-runtime.d.ts +2 -2
- package/dist/jsx-runtime.js +3 -3
- package/dist/{testing-CKwfWJGn.d.ts → testing-CVpo7aRl.d.ts} +46 -7
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +5 -3
- package/docs/authentication.md +42 -1
- package/docs/console.md +17 -6
- package/docs/database-testing.md +21 -0
- package/docs/database.md +12 -0
- package/docs/deployment.md +33 -6
- package/docs/encryption.md +2 -0
- package/docs/installation.md +2 -1
- package/docs/live-tests.md +20 -0
- package/docs/live.md +22 -0
- package/docs/navigation.json +4 -0
- package/docs/pagination.md +10 -0
- package/docs/routing.md +1 -1
- package/docs/scheduling.md +3 -0
- package/docs/session.md +19 -2
- package/docs/starter-kits.md +4 -0
- package/docs/storage.md +44 -5
- package/docs/testing.md +9 -6
- package/docs/two-factor.md +192 -0
- package/docs/views.md +2 -0
- package/docs/vite.md +1 -1
- package/package.json +56 -38
- package/dist/chunk-24673JQF.js.map +0 -1
- package/dist/chunk-7NA4HALO.js.map +0 -1
- package/dist/chunk-MURTCTRH.js.map +0 -1
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
facade,
|
|
11
11
|
fileType_exports,
|
|
12
12
|
inject
|
|
13
|
-
} from "./chunk-
|
|
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-
|
|
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.
|
|
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
|
-
/**
|
|
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
|
|
3470
|
-
}
|
|
3471
|
-
|
|
3472
|
-
|
|
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
|
|
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
|
-
|
|
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;
|
|
@@ -5001,6 +5049,7 @@ function registerLiveCommands(kernel, app) {
|
|
|
5001
5049
|
}).purpose("Create a new Live component");
|
|
5002
5050
|
}
|
|
5003
5051
|
var UPDATE_URI = "/oriel/live/update";
|
|
5052
|
+
var SESSION_URI = "/oriel/live/session";
|
|
5004
5053
|
var LiveServiceProvider = class extends ServiceProvider {
|
|
5005
5054
|
register() {
|
|
5006
5055
|
this.mergeConfigFrom({ class_path: this.app.appPath("Live"), layout: "components.layouts.app", persistent_middleware: [...PERSISTENT_MIDDLEWARE] }, "live");
|
|
@@ -5013,6 +5062,7 @@ var LiveServiceProvider = class extends ServiceProvider {
|
|
|
5013
5062
|
if (this.app.bound(Router)) {
|
|
5014
5063
|
const router = this.app.make(Router);
|
|
5015
5064
|
router.post(UPDATE_URI, () => manager.handle(inject(HttpRequest))).middleware("web").name("live.update");
|
|
5065
|
+
router.get(SESSION_URI, () => new Response(null, { status: 204, headers: { "Cache-Control": "no-store" } })).middleware("web").name("live.session");
|
|
5016
5066
|
router.post(UPLOAD_URI, () => handleUpload(inject(HttpRequest))).middleware(uploadMiddleware()).name("live.upload-file");
|
|
5017
5067
|
router.get(`${PREVIEW_URI}/{filename}`, (filename) => handlePreview(inject(HttpRequest), filename)).middleware("web").name("live.preview-file");
|
|
5018
5068
|
}
|
|
@@ -5044,11 +5094,12 @@ function urlWindow(current, last, onEachSide) {
|
|
|
5044
5094
|
if (current > last - size) return [...range(1, 2), "...", ...range(last - (size + (onEachSide - 1)), last)];
|
|
5045
5095
|
return [...range(1, 2), "...", ...range(current - onEachSide, current + onEachSide), "...", ...range(last - 1, last)];
|
|
5046
5096
|
}
|
|
5047
|
-
|
|
5097
|
+
var classAttribute = (classes) => classes === "" ? "" : ` class="${escapeAttribute2(classes)}"`;
|
|
5098
|
+
function button(label, action, classes, attributes = "") {
|
|
5048
5099
|
const live2 = action === void 0 ? " disabled" : ` o:click="${escapeAttribute2(action)}"`;
|
|
5049
|
-
return `<button type="button"
|
|
5100
|
+
return `<button type="button"${classAttribute(classes)}${attributes}${live2}>${escapeAttribute2(label)}</button>`;
|
|
5050
5101
|
}
|
|
5051
|
-
function Pagination({ paginator, class: className }) {
|
|
5102
|
+
function Pagination({ paginator, class: className, buttonClass = "btn btn-secondary", currentClass = "btn" }) {
|
|
5052
5103
|
if (typeof paginator.nextCursor === "function") {
|
|
5053
5104
|
throw new LiveError("<Pagination> needs paginate() or simplePaginate(): a cursor paginator has no page numbers.");
|
|
5054
5105
|
}
|
|
@@ -5056,26 +5107,28 @@ function Pagination({ paginator, class: className }) {
|
|
|
5056
5107
|
const onFirst = paginator.onFirstPage();
|
|
5057
5108
|
const hasMore = paginator.hasMorePages();
|
|
5058
5109
|
if (onFirst && !hasMore) return { toHtml: () => "" };
|
|
5059
|
-
const parts = [button("\xAB Previous", onFirst ? void 0 : "previousPage")];
|
|
5110
|
+
const parts = [button("\xAB Previous", onFirst ? void 0 : "previousPage", buttonClass)];
|
|
5060
5111
|
if (typeof paginator.lastPage === "function") {
|
|
5061
5112
|
const onEachSide = Number.isInteger(paginator.onEachSideCount) && paginator.onEachSideCount >= 0 ? paginator.onEachSideCount : 3;
|
|
5062
5113
|
for (const page of urlWindow(current, paginator.lastPage(), onEachSide)) {
|
|
5063
5114
|
if (page === "...") parts.push('<span aria-hidden="true">...</span>');
|
|
5064
|
-
else if (page === current) parts.push(`<button type="button"
|
|
5065
|
-
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}"`));
|
|
5066
5117
|
}
|
|
5067
5118
|
}
|
|
5068
|
-
parts.push(button("Next \xBB", hasMore ? "nextPage" : void 0));
|
|
5069
|
-
const
|
|
5070
|
-
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>`;
|
|
5071
5121
|
return { toHtml: () => html };
|
|
5072
5122
|
}
|
|
5073
5123
|
|
|
5074
5124
|
// ../Testing/dist/index.js
|
|
5075
5125
|
import { AssertionError as AssertionError2 } from "assert";
|
|
5076
5126
|
import { isDeepStrictEqual as isDeepStrictEqual2 } from "util";
|
|
5077
|
-
import { existsSync as existsSync6 } from "fs";
|
|
5127
|
+
import { existsSync as existsSync6, readFileSync as readFileSync4 } from "fs";
|
|
5078
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";
|
|
5079
5132
|
import { createHmac as createHmac2 } from "crypto";
|
|
5080
5133
|
import { randomUUID } from "crypto";
|
|
5081
5134
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
@@ -5284,6 +5337,7 @@ var PendingCommand = class {
|
|
|
5284
5337
|
app;
|
|
5285
5338
|
command;
|
|
5286
5339
|
parameters;
|
|
5340
|
+
answers = [];
|
|
5287
5341
|
checks = [];
|
|
5288
5342
|
result;
|
|
5289
5343
|
/** A line of output equals `line` exactly; with no argument, the command printed something. */
|
|
@@ -5336,6 +5390,11 @@ ${output}`, { actual: output, expected: text }));
|
|
|
5336
5390
|
assertFailed() {
|
|
5337
5391
|
return this.assertNotExitCode(0);
|
|
5338
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
|
+
}
|
|
5339
5398
|
/** Runs the command once and checks the expectations; resolves to the exit code. */
|
|
5340
5399
|
run() {
|
|
5341
5400
|
return this.result ??= this.execute();
|
|
@@ -5346,7 +5405,7 @@ ${output}`, { actual: output, expected: text }));
|
|
|
5346
5405
|
async execute() {
|
|
5347
5406
|
if (!this.app.bound(ConsoleKernel)) throw new Error(`Cannot run [${this.command}]: the Console component (ConsoleKernel) is not registered.`);
|
|
5348
5407
|
const kernel = this.app.make(ConsoleKernel);
|
|
5349
|
-
const exitCode = await kernel.call(this.command, this.parameters);
|
|
5408
|
+
const exitCode = await kernel.call(this.command, this.parameters, { answers: this.answers });
|
|
5350
5409
|
const output = kernel.output();
|
|
5351
5410
|
const lines = output.split("\n").map((line) => line.replace(/\r$/, ""));
|
|
5352
5411
|
for (const check of this.checks) check(output, lines, exitCode);
|
|
@@ -5405,6 +5464,96 @@ async function assertNotSoftDeleted(db, table, data = {}, connection, deletedAtC
|
|
|
5405
5464
|
const count = await constrain(t.connection.table(t.table), t.data).whereNull(t.column).count();
|
|
5406
5465
|
assert(count > 0, `Failed asserting that any existing row in the table [${t.table}] matches the attributes ${JSON.stringify(t.data, null, 2)}.`);
|
|
5407
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
|
+
}
|
|
5408
5557
|
var RefreshDatabaseState = { migrated: false };
|
|
5409
5558
|
async function runCommand(app, command, parameters = {}) {
|
|
5410
5559
|
if (!app.bound(ConsoleKernel)) throw new Error(`Running [${command}] needs the Console component (ConsoleKernel is not bound).`);
|
|
@@ -5420,7 +5569,8 @@ function seedOptions(test) {
|
|
|
5420
5569
|
function usingInMemoryDatabase(app) {
|
|
5421
5570
|
const config = app.make(ConfigRepository);
|
|
5422
5571
|
const name = config.get("database.default");
|
|
5423
|
-
|
|
5572
|
+
if (name === void 0) return false;
|
|
5573
|
+
return config.get(`database.connections.${name}.driver`) === "sqlite" && config.get(`database.connections.${name}.database`) === ":memory:";
|
|
5424
5574
|
}
|
|
5425
5575
|
function connectionsOf(test) {
|
|
5426
5576
|
const db = test.app.make(DatabaseManager);
|
|
@@ -5442,9 +5592,19 @@ async function rollBackTo(connection, level) {
|
|
|
5442
5592
|
current = next;
|
|
5443
5593
|
}
|
|
5444
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
|
+
}
|
|
5445
5604
|
var RefreshDatabase = {
|
|
5446
5605
|
async setUp(test) {
|
|
5447
5606
|
if (usingInMemoryDatabase(test.app)) return runCommand(test.app, "migrate", seedOptions(test));
|
|
5607
|
+
refuseOwnDatabase(test.app, "RefreshDatabase");
|
|
5448
5608
|
if (!RefreshDatabaseState.migrated) {
|
|
5449
5609
|
if (test.migrateFreshUsing !== void 0) await test.migrateFreshUsing();
|
|
5450
5610
|
else await runCommand(test.app, "migrate:fresh", seedOptions(test));
|
|
@@ -5455,6 +5615,7 @@ var RefreshDatabase = {
|
|
|
5455
5615
|
};
|
|
5456
5616
|
var DatabaseMigrations = {
|
|
5457
5617
|
async setUp(test) {
|
|
5618
|
+
refuseOwnDatabase(test.app, "DatabaseMigrations");
|
|
5458
5619
|
await runCommand(test.app, "migrate:fresh", seedOptions(test));
|
|
5459
5620
|
test.beforeApplicationDestroyed(() => runCommand(test.app, "migrate:rollback"));
|
|
5460
5621
|
}
|
|
@@ -5464,28 +5625,6 @@ var DatabaseTransactions = {
|
|
|
5464
5625
|
await beginTransactions(test, connectionsOf(test));
|
|
5465
5626
|
}
|
|
5466
5627
|
};
|
|
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
|
-
MAIL_MAILER: "array",
|
|
5474
|
-
QUEUE_CONNECTION: "sync",
|
|
5475
|
-
SESSION_DRIVER: "array"
|
|
5476
|
-
});
|
|
5477
|
-
function applyEnvironment(values, env2 = process.env) {
|
|
5478
|
-
for (const [key2, value] of Object.entries(values)) env2[key2] ??= value;
|
|
5479
|
-
}
|
|
5480
|
-
function clonePlain2(value) {
|
|
5481
|
-
if (Array.isArray(value)) return value.map((item) => clonePlain2(item));
|
|
5482
|
-
if (typeof value === "object" && value !== null) {
|
|
5483
|
-
const proto = Object.getPrototypeOf(value);
|
|
5484
|
-
if (proto !== Object.prototype && proto !== null) return value;
|
|
5485
|
-
return Object.fromEntries(Object.entries(value).map(([key2, item]) => [key2, clonePlain2(item)]));
|
|
5486
|
-
}
|
|
5487
|
-
return value;
|
|
5488
|
-
}
|
|
5489
5628
|
function typeOf(value) {
|
|
5490
5629
|
if (value === null) return ["null"];
|
|
5491
5630
|
if (Array.isArray(value)) return ["array"];
|
|
@@ -5779,7 +5918,7 @@ var AssertableInertia = class _AssertableInertia extends AssertableJson {
|
|
|
5779
5918
|
if (shouldExist === true || shouldExist === void 0 && config?.get("inertia.testing.ensure_pages_exist", true) !== false) {
|
|
5780
5919
|
const paths = config?.get("inertia.pages.paths", []) ?? [];
|
|
5781
5920
|
const extensions = config?.get("inertia.pages.extensions", []) ?? [];
|
|
5782
|
-
const exists = paths.some((path) => extensions.some((extension) =>
|
|
5921
|
+
const exists = paths.some((path) => extensions.some((extension) => existsSync25(join25(path, `${value}.${extension}`))));
|
|
5783
5922
|
if (!exists) fail2(`Inertia page component file [${value}] does not exist.`);
|
|
5784
5923
|
}
|
|
5785
5924
|
return this;
|
|
@@ -6615,16 +6754,39 @@ var HttpClient = class {
|
|
|
6615
6754
|
const result = await scope.run(async () => {
|
|
6616
6755
|
this.beforeRequest(scope, context);
|
|
6617
6756
|
if (context.session !== void 0) this.applyPending(context.session);
|
|
6618
|
-
|
|
6757
|
+
const incoming = new IncomingRequest(request2);
|
|
6758
|
+
incoming.setCookies(this.plainCookies());
|
|
6759
|
+
scope.instance(HttpRequest, incoming);
|
|
6619
6760
|
if (scope.bound(AuthFactory)) {
|
|
6620
6761
|
try {
|
|
6621
6762
|
await scope.make(AuthFactory).guard().check();
|
|
6622
6763
|
} catch {
|
|
6623
6764
|
}
|
|
6624
6765
|
}
|
|
6625
|
-
|
|
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;
|
|
6626
6781
|
});
|
|
6627
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
|
+
}
|
|
6628
6790
|
return result;
|
|
6629
6791
|
}
|
|
6630
6792
|
/** Runs the request through the app's real HttpKernel, in a request scope this client owns. */
|
|
@@ -6743,8 +6905,25 @@ var HttpClient = class {
|
|
|
6743
6905
|
const configured = this.app.bound(ConfigRepository) ? this.app.make(ConfigRepository).get("app.url") : void 0;
|
|
6744
6906
|
return typeof configured === "string" && configured !== "" ? configured : "http://localhost";
|
|
6745
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
|
+
}
|
|
6746
6924
|
cookieHeader() {
|
|
6747
|
-
const
|
|
6925
|
+
const needsKey = [...this.cookies.values()].some(({ encrypt }) => encrypt);
|
|
6926
|
+
const encrypter = needsKey && this.app.bound(Encrypter) ? this.app.make(Encrypter) : void 0;
|
|
6748
6927
|
const values = /* @__PURE__ */ new Map();
|
|
6749
6928
|
for (const [name, { value, encrypt }] of this.cookies) {
|
|
6750
6929
|
values.set(name, encrypt && encrypter !== void 0 ? encryptCookie(encrypter, name, value) : value);
|
|
@@ -8695,6 +8874,7 @@ export {
|
|
|
8695
8874
|
InvalidUploadSignatureError,
|
|
8696
8875
|
TemporaryFileNotFoundError,
|
|
8697
8876
|
FileNotPreviewableError,
|
|
8877
|
+
UploadAlreadyStoredError,
|
|
8698
8878
|
UploadValidationError,
|
|
8699
8879
|
On,
|
|
8700
8880
|
Locked,
|
|
@@ -8718,6 +8898,7 @@ export {
|
|
|
8718
8898
|
WithPagination,
|
|
8719
8899
|
LiveComponentManager,
|
|
8720
8900
|
UPDATE_URI,
|
|
8901
|
+
SESSION_URI,
|
|
8721
8902
|
LiveServiceProvider,
|
|
8722
8903
|
describeComponent,
|
|
8723
8904
|
Pagination,
|
|
@@ -8728,14 +8909,15 @@ export {
|
|
|
8728
8909
|
travel,
|
|
8729
8910
|
Wormhole,
|
|
8730
8911
|
PendingCommand,
|
|
8912
|
+
TESTING_ENVIRONMENT,
|
|
8913
|
+
testingConfig,
|
|
8914
|
+
applyEnvironment,
|
|
8731
8915
|
RefreshDatabaseState,
|
|
8732
8916
|
runCommand,
|
|
8733
8917
|
usingInMemoryDatabase,
|
|
8734
8918
|
RefreshDatabase,
|
|
8735
8919
|
DatabaseMigrations,
|
|
8736
8920
|
DatabaseTransactions,
|
|
8737
|
-
TESTING_ENVIRONMENT,
|
|
8738
|
-
applyEnvironment,
|
|
8739
8921
|
AssertableJson,
|
|
8740
8922
|
inertiaPageOf,
|
|
8741
8923
|
AssertableInertia,
|
|
@@ -8773,4 +8955,4 @@ export {
|
|
|
8773
8955
|
StorageFake,
|
|
8774
8956
|
FakeFile
|
|
8775
8957
|
};
|
|
8776
|
-
//# sourceMappingURL=chunk-
|
|
8958
|
+
//# sourceMappingURL=chunk-UBSIBGXR.js.map
|