@getstrata/core 2.2.50 → 2.2.51
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/CHANGELOG.md +6 -0
- package/dist/core/database/relationQuery.d.ts +2 -2
- package/dist/core/security/safePath.d.ts +1 -1
- package/dist/entries/facades.js +8 -6
- package/dist/entries/security/safePath.js +8 -6
- package/dist/entries/storage/storage.js +8 -6
- package/dist/index.js +64 -20
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @getstrata/core changelog
|
|
2
2
|
|
|
3
|
+
## 2.2.51
|
|
4
|
+
|
|
5
|
+
- Decode static URL pathnames exactly once while preserving generic filesystem path semantics, malformed/traversal rejection and literal percent/space names.
|
|
6
|
+
- Load explicit nested polymorphic paths using their concrete model and nested relation owners, batching by constructor identity while preserving flat eager records, flat lazy models, private state and visibility scopes.
|
|
7
|
+
- Preserve retrieved-observer invalidation/materialization and once-per-hydration callback getter dispatch; cache bookkeeping inspects only the existing observer list.
|
|
8
|
+
|
|
3
9
|
## 2.2.50
|
|
4
10
|
|
|
5
11
|
- Align the lockstep version with the bootstrap HTTP-only drain-reporting correction. Core runtime, ORM, transaction, lifecycle coordinator and public/protected APIs are unchanged.
|
|
@@ -179,7 +179,7 @@ declare class MorphToRelationQuery<TChild extends object, ChildKey extends keyof
|
|
|
179
179
|
constructor(parent: RelationHost<TChild, ChildKey>, relatedByType: Record<string, RelatedModelClass<Record<string, unknown>, "id">>, relation: MorphToRelation<TChild, keyof TChild & string, keyof TChild & string>);
|
|
180
180
|
where(where: QueryWhere<Record<string, unknown>>): this;
|
|
181
181
|
applyEagerLoad(query: RepositoryQuery<TChild, ChildKey>, alias: string): void;
|
|
182
|
-
hydrateEager(row: Record<string, unknown>, alias: string): unknown;
|
|
182
|
+
hydrateEager(row: Record<string, unknown>, alias: string, forNestedLoading?: boolean): unknown;
|
|
183
183
|
toExistsClause(parentTable: string): ExistsClause;
|
|
184
184
|
get(): Promise<RelatedRecord | null>;
|
|
185
185
|
pluck(column: string): Promise<unknown[]>;
|
|
@@ -215,7 +215,7 @@ declare class HasManyThroughRelationQuery<TParent extends object, ParentKey exte
|
|
|
215
215
|
type AnyRelationQuery = {
|
|
216
216
|
kind: RelationKind;
|
|
217
217
|
applyEagerLoad(query: unknown, alias: string): void;
|
|
218
|
-
hydrateEager(row: Record<string, unknown>, alias: string): unknown;
|
|
218
|
+
hydrateEager(row: Record<string, unknown>, alias: string, forNestedLoading?: boolean): unknown;
|
|
219
219
|
get(): Promise<unknown>;
|
|
220
220
|
toExistsClause(parentTable: string): ExistsClause;
|
|
221
221
|
where?(where: Record<string, unknown>): unknown;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
declare function assertPathUnderRoot(rootDirectory: string, userPath: string): string;
|
|
2
|
-
/**
|
|
2
|
+
/** Decode a URL pathname once; leading slashes are not filesystem-absolute. */
|
|
3
3
|
declare function assertUrlPathUnderRoot(rootDirectory: string, urlPathname: string): string;
|
|
4
4
|
export { assertPathUnderRoot, assertUrlPathUnderRoot };
|
package/dist/entries/facades.js
CHANGED
|
@@ -512,23 +512,25 @@ var {S3Client } = globalThis.Bun;
|
|
|
512
512
|
|
|
513
513
|
// ../../src/core/security/safePath.ts
|
|
514
514
|
import { isAbsolute, resolve, sep } from "path";
|
|
515
|
-
function
|
|
516
|
-
|
|
517
|
-
if (trimmed.length === 0) {
|
|
515
|
+
function resolvePathUnderRoot(rootDirectory, path) {
|
|
516
|
+
if (path.length === 0) {
|
|
518
517
|
throw new Error("Path must not be empty.");
|
|
519
518
|
}
|
|
520
|
-
if (
|
|
519
|
+
if (path.includes("\x00")) {
|
|
521
520
|
throw new Error("Path must not contain a null byte.");
|
|
522
521
|
}
|
|
523
522
|
const root = resolve(rootDirectory);
|
|
524
|
-
const candidate = isAbsolute(
|
|
523
|
+
const candidate = isAbsolute(path) ? resolve(path) : resolve(root, path.replace(/^\/+/u, ""));
|
|
525
524
|
if (candidate === root || candidate.startsWith(`${root}${sep}`)) {
|
|
526
525
|
return candidate;
|
|
527
526
|
}
|
|
528
527
|
throw new Error("Path escapes the storage root.");
|
|
529
528
|
}
|
|
529
|
+
function assertPathUnderRoot(rootDirectory, userPath) {
|
|
530
|
+
return resolvePathUnderRoot(rootDirectory, userPath.trim());
|
|
531
|
+
}
|
|
530
532
|
function assertUrlPathUnderRoot(rootDirectory, urlPathname) {
|
|
531
|
-
return
|
|
533
|
+
return resolvePathUnderRoot(rootDirectory, decodeURIComponent(urlPathname).replace(/^\/+/u, ""));
|
|
532
534
|
}
|
|
533
535
|
|
|
534
536
|
// ../../src/core/storage/storage.ts
|
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// ../../src/core/security/safePath.ts
|
|
3
3
|
import { isAbsolute, resolve, sep } from "path";
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
if (trimmed.length === 0) {
|
|
4
|
+
function resolvePathUnderRoot(rootDirectory, path) {
|
|
5
|
+
if (path.length === 0) {
|
|
7
6
|
throw new Error("Path must not be empty.");
|
|
8
7
|
}
|
|
9
|
-
if (
|
|
8
|
+
if (path.includes("\x00")) {
|
|
10
9
|
throw new Error("Path must not contain a null byte.");
|
|
11
10
|
}
|
|
12
11
|
const root = resolve(rootDirectory);
|
|
13
|
-
const candidate = isAbsolute(
|
|
12
|
+
const candidate = isAbsolute(path) ? resolve(path) : resolve(root, path.replace(/^\/+/u, ""));
|
|
14
13
|
if (candidate === root || candidate.startsWith(`${root}${sep}`)) {
|
|
15
14
|
return candidate;
|
|
16
15
|
}
|
|
17
16
|
throw new Error("Path escapes the storage root.");
|
|
18
17
|
}
|
|
18
|
+
function assertPathUnderRoot(rootDirectory, userPath) {
|
|
19
|
+
return resolvePathUnderRoot(rootDirectory, userPath.trim());
|
|
20
|
+
}
|
|
19
21
|
function assertUrlPathUnderRoot(rootDirectory, urlPathname) {
|
|
20
|
-
return
|
|
22
|
+
return resolvePathUnderRoot(rootDirectory, decodeURIComponent(urlPathname).replace(/^\/+/u, ""));
|
|
21
23
|
}
|
|
22
24
|
export {
|
|
23
25
|
assertPathUnderRoot,
|
|
@@ -6,23 +6,25 @@ var {S3Client } = globalThis.Bun;
|
|
|
6
6
|
|
|
7
7
|
// ../../src/core/security/safePath.ts
|
|
8
8
|
import { isAbsolute, resolve, sep } from "path";
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
if (trimmed.length === 0) {
|
|
9
|
+
function resolvePathUnderRoot(rootDirectory, path) {
|
|
10
|
+
if (path.length === 0) {
|
|
12
11
|
throw new Error("Path must not be empty.");
|
|
13
12
|
}
|
|
14
|
-
if (
|
|
13
|
+
if (path.includes("\x00")) {
|
|
15
14
|
throw new Error("Path must not contain a null byte.");
|
|
16
15
|
}
|
|
17
16
|
const root = resolve(rootDirectory);
|
|
18
|
-
const candidate = isAbsolute(
|
|
17
|
+
const candidate = isAbsolute(path) ? resolve(path) : resolve(root, path.replace(/^\/+/u, ""));
|
|
19
18
|
if (candidate === root || candidate.startsWith(`${root}${sep}`)) {
|
|
20
19
|
return candidate;
|
|
21
20
|
}
|
|
22
21
|
throw new Error("Path escapes the storage root.");
|
|
23
22
|
}
|
|
23
|
+
function assertPathUnderRoot(rootDirectory, userPath) {
|
|
24
|
+
return resolvePathUnderRoot(rootDirectory, userPath.trim());
|
|
25
|
+
}
|
|
24
26
|
function assertUrlPathUnderRoot(rootDirectory, urlPathname) {
|
|
25
|
-
return
|
|
27
|
+
return resolvePathUnderRoot(rootDirectory, decodeURIComponent(urlPathname).replace(/^\/+/u, ""));
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
// ../../src/core/storage/storage.ts
|
package/dist/index.js
CHANGED
|
@@ -8316,10 +8316,27 @@ function flattenRelationNames(relations) {
|
|
|
8316
8316
|
function isLoadableModel(value) {
|
|
8317
8317
|
return Boolean(value && typeof value === "object" && typeof value.load === "function" && typeof value.loaded === "function" && typeof value.setLoaded === "function");
|
|
8318
8318
|
}
|
|
8319
|
-
|
|
8319
|
+
function resolveModelRelation(model, name) {
|
|
8320
|
+
const method = model[name];
|
|
8321
|
+
if (typeof method !== "function") {
|
|
8322
|
+
throw new Error(`${model.constructor.name} has no relation method ${name}().`);
|
|
8323
|
+
}
|
|
8324
|
+
return method.call(model);
|
|
8325
|
+
}
|
|
8326
|
+
async function eagerLoadOnModels(models, paths, knownAbsentMorphRoots = new Map) {
|
|
8320
8327
|
if (models.length === 0 || paths.length === 0) {
|
|
8321
8328
|
return;
|
|
8322
8329
|
}
|
|
8330
|
+
const byModel = new Map;
|
|
8331
|
+
for (const model of models) {
|
|
8332
|
+
const group = byModel.get(model.constructor) ?? [];
|
|
8333
|
+
group.push(model);
|
|
8334
|
+
byModel.set(model.constructor, group);
|
|
8335
|
+
}
|
|
8336
|
+
if (byModel.size > 1) {
|
|
8337
|
+
await Promise.all([...byModel.values()].map((group) => eagerLoadOnModels(group, paths, knownAbsentMorphRoots)));
|
|
8338
|
+
return;
|
|
8339
|
+
}
|
|
8323
8340
|
const grouped = new Map;
|
|
8324
8341
|
for (const path of paths) {
|
|
8325
8342
|
const [head, ...rest] = path.split(".");
|
|
@@ -8334,28 +8351,33 @@ async function eagerLoadOnModels(models, paths) {
|
|
|
8334
8351
|
grouped.set(head, existing);
|
|
8335
8352
|
}
|
|
8336
8353
|
await Promise.all([...grouped.entries()].map(async ([head, nested]) => {
|
|
8337
|
-
const unloaded = models.filter((model) => model.loaded(head) === undefined);
|
|
8354
|
+
const unloaded = models.filter((model) => model.loaded(head) === undefined && !knownAbsentMorphRoots.get(model)?.has(head));
|
|
8338
8355
|
if (unloaded.length > 0) {
|
|
8339
8356
|
const first = unloaded[0];
|
|
8340
8357
|
if (!first) {
|
|
8341
8358
|
return;
|
|
8342
8359
|
}
|
|
8343
|
-
const
|
|
8344
|
-
if (typeof method !== "function") {
|
|
8345
|
-
throw new Error(`${first.constructor.name} has no relation method ${head}().`);
|
|
8346
|
-
}
|
|
8347
|
-
const relationQuery = method.call(first);
|
|
8360
|
+
const relationQuery = resolveModelRelation(first, head);
|
|
8348
8361
|
const query = first.getRepository().query();
|
|
8349
8362
|
relationQuery.applyEagerLoad(query, head);
|
|
8350
8363
|
const attached = await query.attachToRows(unloaded.map((model) => model.toObject()));
|
|
8351
8364
|
for (const [index, model] of unloaded.entries()) {
|
|
8352
8365
|
const row = attached[index] ?? model.toObject();
|
|
8353
|
-
model.setLoaded(head, relationQuery.hydrateEager(row, head));
|
|
8366
|
+
model.setLoaded(head, relationQuery.hydrateEager(row, head, nested.length > 0));
|
|
8354
8367
|
}
|
|
8355
8368
|
}
|
|
8356
8369
|
if (nested.length === 0) {
|
|
8357
8370
|
return;
|
|
8358
8371
|
}
|
|
8372
|
+
for (const model of models) {
|
|
8373
|
+
const value = model.loaded(head);
|
|
8374
|
+
if (value && typeof value === "object" && !Array.isArray(value) && !isLoadableModel(value)) {
|
|
8375
|
+
const relationQuery = resolveModelRelation(model, head);
|
|
8376
|
+
if (relationQuery.kind === "morphTo") {
|
|
8377
|
+
model.setLoaded(head, relationQuery.hydrateEager({ ...model.toObject(), [head]: value }, head, true));
|
|
8378
|
+
}
|
|
8379
|
+
}
|
|
8380
|
+
}
|
|
8359
8381
|
const children = models.flatMap((model) => {
|
|
8360
8382
|
const loaded = model.loaded(head);
|
|
8361
8383
|
return Array.isArray(loaded) ? loaded : loaded ? [loaded] : [];
|
|
@@ -8559,16 +8581,31 @@ class ModelQuery {
|
|
|
8559
8581
|
async hydrateRows(rows) {
|
|
8560
8582
|
const statics = modelStatics(this.modelClass);
|
|
8561
8583
|
const models = [];
|
|
8584
|
+
const knownAbsentMorphRoots = new Map;
|
|
8585
|
+
const nested = this.eager.filter((item) => item.path.includes(".")).map((item) => item.path);
|
|
8586
|
+
const nestedRoots = new Set(this.eager.filter((item) => item.path.includes(".")).map((item) => item.name));
|
|
8562
8587
|
for (const row of rows) {
|
|
8563
8588
|
const model = statics.newFromRecord(row, true);
|
|
8589
|
+
const absentMorphRoots = new Set;
|
|
8564
8590
|
for (const { name, relationQuery } of this.eager) {
|
|
8565
|
-
|
|
8591
|
+
const value = relationQuery.hydrateEager(row, name, nestedRoots.has(name));
|
|
8592
|
+
model.setLoaded(name, value);
|
|
8593
|
+
if (relationQuery.kind === "morphTo" && value === undefined)
|
|
8594
|
+
absentMorphRoots.add(name);
|
|
8595
|
+
else
|
|
8596
|
+
absentMorphRoots.delete(name);
|
|
8566
8597
|
}
|
|
8598
|
+
if (absentMorphRoots.size > 0)
|
|
8599
|
+
knownAbsentMorphRoots.set(model, absentMorphRoots);
|
|
8567
8600
|
models.push(model);
|
|
8568
8601
|
}
|
|
8569
|
-
await Promise.all(models.map((model) =>
|
|
8570
|
-
|
|
8571
|
-
|
|
8602
|
+
await Promise.all(models.map((model) => {
|
|
8603
|
+
if (getModelObservers(model.constructor)?.length) {
|
|
8604
|
+
knownAbsentMorphRoots.delete(model);
|
|
8605
|
+
}
|
|
8606
|
+
return runObservers(model, "retrieved");
|
|
8607
|
+
}));
|
|
8608
|
+
await eagerLoadOnModels(models.filter(isLoadableModel), nested, knownAbsentMorphRoots);
|
|
8572
8609
|
return models;
|
|
8573
8610
|
}
|
|
8574
8611
|
async first() {
|
|
@@ -9254,8 +9291,13 @@ class MorphToRelationQuery {
|
|
|
9254
9291
|
relatedOptions(model, this.extraWhere)
|
|
9255
9292
|
])));
|
|
9256
9293
|
}
|
|
9257
|
-
hydrateEager(row, alias) {
|
|
9258
|
-
|
|
9294
|
+
hydrateEager(row, alias, forNestedLoading = false) {
|
|
9295
|
+
const value = row[alias];
|
|
9296
|
+
if (!forNestedLoading || !value)
|
|
9297
|
+
return value;
|
|
9298
|
+
const type = row[this.relation.morphTypeKey];
|
|
9299
|
+
const related = type === undefined || type === null ? undefined : this.relatedByType[String(type)];
|
|
9300
|
+
return related ? related.newFromRecord(value) : value;
|
|
9259
9301
|
}
|
|
9260
9302
|
toExistsClause(parentTable) {
|
|
9261
9303
|
const params = [];
|
|
@@ -11443,23 +11485,25 @@ var {S3Client } = globalThis.Bun;
|
|
|
11443
11485
|
|
|
11444
11486
|
// ../../src/core/security/safePath.ts
|
|
11445
11487
|
import { isAbsolute, resolve as resolve2, sep } from "path";
|
|
11446
|
-
function
|
|
11447
|
-
|
|
11448
|
-
if (trimmed.length === 0) {
|
|
11488
|
+
function resolvePathUnderRoot(rootDirectory, path) {
|
|
11489
|
+
if (path.length === 0) {
|
|
11449
11490
|
throw new Error("Path must not be empty.");
|
|
11450
11491
|
}
|
|
11451
|
-
if (
|
|
11492
|
+
if (path.includes("\x00")) {
|
|
11452
11493
|
throw new Error("Path must not contain a null byte.");
|
|
11453
11494
|
}
|
|
11454
11495
|
const root = resolve2(rootDirectory);
|
|
11455
|
-
const candidate = isAbsolute(
|
|
11496
|
+
const candidate = isAbsolute(path) ? resolve2(path) : resolve2(root, path.replace(/^\/+/u, ""));
|
|
11456
11497
|
if (candidate === root || candidate.startsWith(`${root}${sep}`)) {
|
|
11457
11498
|
return candidate;
|
|
11458
11499
|
}
|
|
11459
11500
|
throw new Error("Path escapes the storage root.");
|
|
11460
11501
|
}
|
|
11502
|
+
function assertPathUnderRoot(rootDirectory, userPath) {
|
|
11503
|
+
return resolvePathUnderRoot(rootDirectory, userPath.trim());
|
|
11504
|
+
}
|
|
11461
11505
|
function assertUrlPathUnderRoot(rootDirectory, urlPathname) {
|
|
11462
|
-
return
|
|
11506
|
+
return resolvePathUnderRoot(rootDirectory, decodeURIComponent(urlPathname).replace(/^\/+/u, ""));
|
|
11463
11507
|
}
|
|
11464
11508
|
|
|
11465
11509
|
// ../../src/core/storage/storage.ts
|