@c9up/atlas 0.2.7 → 0.3.0
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/db.win32-x64-msvc.node +0 -0
- package/dist/AtlasProvider.d.ts.map +1 -1
- package/dist/AtlasProvider.js +54 -2
- package/dist/AtlasProvider.js.map +1 -1
- package/dist/BaseEntity.d.ts +7 -0
- package/dist/BaseEntity.d.ts.map +1 -1
- package/dist/BaseEntity.js +100 -34
- package/dist/BaseEntity.js.map +1 -1
- package/dist/BaseRepository.d.ts +1 -1
- package/dist/BaseRepository.d.ts.map +1 -1
- package/dist/BaseRepository.js +26 -14
- package/dist/BaseRepository.js.map +1 -1
- package/dist/ModelQuery.d.ts +35 -4
- package/dist/ModelQuery.d.ts.map +1 -1
- package/dist/ModelQuery.js +60 -19
- package/dist/ModelQuery.js.map +1 -1
- package/dist/decorators/entity.d.ts +10 -0
- package/dist/decorators/entity.d.ts.map +1 -1
- package/dist/decorators/entity.js +13 -0
- package/dist/decorators/entity.js.map +1 -1
- package/dist/naming/NamingStrategy.d.ts +9 -1
- package/dist/naming/NamingStrategy.d.ts.map +1 -1
- package/dist/naming/NamingStrategy.js +6 -1
- package/dist/naming/NamingStrategy.js.map +1 -1
- package/index.win32-x64-msvc.node +0 -0
- package/package.json +1 -1
- package/src/AtlasProvider.ts +81 -2
- package/src/BaseEntity.ts +140 -43
- package/src/BaseRepository.ts +27 -13
- package/src/ModelQuery.ts +82 -20
- package/src/decorators/entity.ts +21 -0
- package/src/naming/NamingStrategy.ts +15 -2
|
@@ -317,6 +317,19 @@ export function getPrimaryKey(target) {
|
|
|
317
317
|
return staticPk;
|
|
318
318
|
return Reflect.getMetadata(PRIMARY_KEY, target);
|
|
319
319
|
}
|
|
320
|
+
/**
|
|
321
|
+
* The foreign key a relation falls back to when none is declared.
|
|
322
|
+
*
|
|
323
|
+
* Goes through the entity's naming strategy rather than hardcoding `_id`, so a
|
|
324
|
+
* model whose primary key is not `id` gets `user_uuid` instead of a `user_id`
|
|
325
|
+
* column that does not exist. Lucid derives it the same way
|
|
326
|
+
* (`relationForeignKey` / `relationPivotForeignKey`), and for the usual `id`
|
|
327
|
+
* the result is unchanged.
|
|
328
|
+
*/
|
|
329
|
+
export function defaultRelationForeignKey(kind, entityClass) {
|
|
330
|
+
const pk = getPrimaryKey(entityClass) ?? "id";
|
|
331
|
+
return getNamingStrategy(entityClass).relationForeignKey(kind, entityClass.name, pk);
|
|
332
|
+
}
|
|
320
333
|
/** Get relation metadata for a class (returns a copy). */
|
|
321
334
|
export function getRelationMetadata(target) {
|
|
322
335
|
return [...(Reflect.getMetadata(RELATIONS_KEY, target) ?? [])];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/decorators/entity.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EACN,oBAAoB,EACpB,YAAY,GAEZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,MAAM,UAAU,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AAC1C,MAAM,WAAW,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAC5C,MAAM,WAAW,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAC5C,MAAM,eAAe,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AACpD,MAAM,aAAa,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AA8LhD,kEAAkE;AAClE,MAAM,UAAU,MAAM,CAAC,SAAiB;IACvC,OAAO,CAAC,MAAM,EAAE,EAAE;QACjB,OAAO,CAAC,cAAc,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;IAC3D,CAAC,CAAC;AACH,CAAC;AAED,yDAAyD;AACzD,MAAM,UAAU,MAAM,CAAC,OAAuB;IAC7C,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AI,EAAE,CAAC,CAAC,CAAC;AAChE,CAAC;AAED,gEAAgE;AAEhE,MAAM,eAAe,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAEpD,6EAA6E;AAC7E,MAAM,UAAU,WAAW;IAC1B,OAAO,CAAC,MAAM,EAAE,EAAE;QACjB,OAAO,CAAC,cAAc,CAAC,eAAe,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QACtD,kCAAkC;QAClC,MAAM,OAAO,GACZ,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QACnD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,KAAK,WAAW,CAAC,EAAE,CAAC;YACzD,OAAO,CAAC,IAAI,CAAC;gBACZ,WAAW,EAAE,WAAW;gBACxB,IAAI,EAAE,WAAW;gBACjB,QAAQ,EAAE,IAAI;aACd,CAAC,CAAC;YACH,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QACtD,CAAC;IACF,CAAC,CAAC;AACH,CAAC;AAED,kDAAkD;AAClD,MAAM,UAAU,cAAc,CAAC,MAAmB;IACjD,OAAO,OAAO,CAAC,WAAW,CAAC,eAAe,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;AAC9D,CAAC"}
|
|
@@ -24,7 +24,15 @@ export interface NamingStrategy {
|
|
|
24
24
|
serializedName(propertyName: string): string;
|
|
25
25
|
/** Local key for a belongsTo/hasMany relation (usually the parent PK). */
|
|
26
26
|
relationLocalKey(kind: "belongsTo" | "hasMany" | "hasOne" | "manyToMany", parentPk: string): string;
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Foreign key COLUMN name on the owning side of a relation.
|
|
29
|
+
*
|
|
30
|
+
* NAMED DEVIATION — Lucid's method of the same name returns the model
|
|
31
|
+
* ATTRIBUTE (camelCase), which it then runs through `columnName()`; the one
|
|
32
|
+
* that returns a column upstream is `relationPivotForeignKey`. Atlas
|
|
33
|
+
* resolves relations by column throughout, so one method answers for both
|
|
34
|
+
* and it answers in snake_case. An override must return a column name.
|
|
35
|
+
*/
|
|
28
36
|
relationForeignKey(kind: "belongsTo" | "hasMany" | "hasOne" | "manyToMany", parentClass: string, parentPk: string): string;
|
|
29
37
|
/** Default pivot table name for a manyToMany relation. */
|
|
30
38
|
relationPivotTable(aClass: string, bClass: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NamingStrategy.d.ts","sourceRoot":"","sources":["../../src/naming/NamingStrategy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,wFAAwF;AACxF,MAAM,WAAW,cAAc;IAC9B,kEAAkE;IAClE,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IACrC,0EAA0E;IAC1E,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC;IACzC,4EAA4E;IAC5E,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;IACzC,0EAA0E;IAC1E,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7C,0EAA0E;IAC1E,gBAAgB,CACf,IAAI,EAAE,WAAW,GAAG,SAAS,GAAG,QAAQ,GAAG,YAAY,EACvD,QAAQ,EAAE,MAAM,GACd,MAAM,CAAC;IACV
|
|
1
|
+
{"version":3,"file":"NamingStrategy.d.ts","sourceRoot":"","sources":["../../src/naming/NamingStrategy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,wFAAwF;AACxF,MAAM,WAAW,cAAc;IAC9B,kEAAkE;IAClE,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IACrC,0EAA0E;IAC1E,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC;IACzC,4EAA4E;IAC5E,YAAY,CAAC,UAAU,EAAE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MAAM,qBAAqB,EAAE,cACN,CAAC;AAE/B;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,cAAc,CASrE"}
|
|
@@ -37,7 +37,12 @@ export class CamelCaseNamingStrategy {
|
|
|
37
37
|
return parentPk;
|
|
38
38
|
}
|
|
39
39
|
relationForeignKey(_kind, parentClass, parentPk) {
|
|
40
|
-
|
|
40
|
+
// The PK is snake_cased too, as Lucid does
|
|
41
|
+
// (`snakeCase(`${model.name}_${model.primaryKey}`)`). Identical to the
|
|
42
|
+
// old output for the usual `id`; a multi-word PK now yields a column
|
|
43
|
+
// name a migration would actually have created (`user_user_id`, not
|
|
44
|
+
// `user_userId`).
|
|
45
|
+
return `${camelToSnake(parentClass)}_${camelToSnake(parentPk)}`;
|
|
41
46
|
}
|
|
42
47
|
relationPivotTable(aClass, bClass) {
|
|
43
48
|
// Sort alphabetically so `UserSkill` and `SkillUser` collapse to the same name.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NamingStrategy.js","sourceRoot":"","sources":["../../src/naming/NamingStrategy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"NamingStrategy.js","sourceRoot":"","sources":["../../src/naming/NamingStrategy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAyChE;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IACnC,SAAS,CAAC,SAAiB;QAC1B,+EAA+E;QAC/E,sEAAsE;QACtE,MAAM,KAAK,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;QACtC,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CA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AC,WAAmB;IACpD,IAAI,OAAO,GAAkB,WAAW,CAAC;IACzC,OAAO,OAAO,IAAI,OAAO,KAAK,QAAQ,CAAC,SAAS,EAAE,CAAC;QAClD,MAAM,QAAQ,GAAI,OAA+C;aAC/D,cAAc,CAAC;QACjB,IAAI,QAAQ;YAAE,OAAO,QAAQ,CAAC;QAC9B,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,qBAAqB,CAAC;AAC9B,CAAC"}
|
|
Binary file
|
package/package.json
CHANGED
package/src/AtlasProvider.ts
CHANGED
|
@@ -436,6 +436,22 @@ export default class AtlasProvider {
|
|
|
436
436
|
"[atlas] Migrations are configured but were NOT run: boot auto-migrate is disabled in production. Run `migration:run` before serving traffic, or set migrations.autoRunInProduction = true to opt in.",
|
|
437
437
|
);
|
|
438
438
|
}
|
|
439
|
+
// Register with the framework's migration registry, so `ream migrate`
|
|
440
|
+
// can drive atlas without naming it. Independent of auto-migrate: the
|
|
441
|
+
// CLI sets REAM_SKIP_BOOT_MIGRATE precisely so boot does NOT migrate,
|
|
442
|
+
// and that is exactly the run that needs the registration.
|
|
443
|
+
if (migrationsPath) {
|
|
444
|
+
await this.#registerMigrationSource(
|
|
445
|
+
migrationsPath,
|
|
446
|
+
connections[defaultName]?.url,
|
|
447
|
+
defaultConn,
|
|
448
|
+
config.migrations?.table,
|
|
449
|
+
{
|
|
450
|
+
naturalSort: config.migrations?.naturalSort,
|
|
451
|
+
disableTransactions: config.migrations?.disableTransactions,
|
|
452
|
+
},
|
|
453
|
+
);
|
|
454
|
+
}
|
|
439
455
|
if (migrationsPath && !cliDrivesMigrations && autoMigrateAllowed) {
|
|
440
456
|
await this.#runMigrations(
|
|
441
457
|
migrationsPath,
|
|
@@ -589,7 +605,71 @@ export default class AtlasProvider {
|
|
|
589
605
|
): Promise<void> {
|
|
590
606
|
const { existsSync } = await import("node:fs");
|
|
591
607
|
if (!existsSync(migrationsPath)) return;
|
|
608
|
+
await this.#buildRunner(
|
|
609
|
+
migrationsPath,
|
|
610
|
+
url,
|
|
611
|
+
db,
|
|
612
|
+
tableName,
|
|
613
|
+
options,
|
|
614
|
+
).migrate();
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* Hand atlas's runner to the framework's `migrations` registry.
|
|
619
|
+
*
|
|
620
|
+
* Best-effort by design: a host with no registry (an older ream, or another
|
|
621
|
+
* framework entirely) must still boot. atlas does not import `@c9up/ream`,
|
|
622
|
+
* so the registry is duck-typed here like every other host binding.
|
|
623
|
+
*/
|
|
624
|
+
async #registerMigrationSource(
|
|
625
|
+
migrationsPath: string,
|
|
626
|
+
url: string,
|
|
627
|
+
db: AsyncDatabaseConnection,
|
|
628
|
+
tableName: string | undefined,
|
|
629
|
+
options?: { naturalSort?: boolean; disableTransactions?: boolean },
|
|
630
|
+
): Promise<void> {
|
|
631
|
+
const resolve = this.app.container.resolve;
|
|
632
|
+
if (typeof resolve !== "function") return;
|
|
592
633
|
|
|
634
|
+
let registry: unknown;
|
|
635
|
+
try {
|
|
636
|
+
registry = await resolve.call(this.app.container, "migrations");
|
|
637
|
+
} catch {
|
|
638
|
+
// No registry bound — an older ream. Booting still has to work; the
|
|
639
|
+
// CLI is the one that reports it, where the user can act on it.
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
if (
|
|
643
|
+
typeof registry !== "object" ||
|
|
644
|
+
registry === null ||
|
|
645
|
+
!("register" in registry) ||
|
|
646
|
+
typeof registry.register !== "function"
|
|
647
|
+
) {
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
(registry.register as (source: unknown) => unknown)({
|
|
652
|
+
name: "atlas",
|
|
653
|
+
directory: migrationsPath,
|
|
654
|
+
runner: this.#buildRunner(migrationsPath, url, db, tableName, options),
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Build the runner without running it.
|
|
660
|
+
*
|
|
661
|
+
* Split out of `#runMigrations` so the same runner can be handed to the
|
|
662
|
+
* `migrations` registry, where `ream migrate` drives it. Two constructions
|
|
663
|
+
* would be two chances for boot-time and CLI-time migrations to disagree
|
|
664
|
+
* about the table, the dialect or the sort.
|
|
665
|
+
*/
|
|
666
|
+
#buildRunner(
|
|
667
|
+
migrationsPath: string,
|
|
668
|
+
url: string,
|
|
669
|
+
db: AsyncDatabaseConnection,
|
|
670
|
+
tableName: string | undefined,
|
|
671
|
+
options?: { naturalSort?: boolean; disableTransactions?: boolean },
|
|
672
|
+
): MigrationRunner {
|
|
593
673
|
const adapter: DatabaseAdapter = {
|
|
594
674
|
execute: async (sql, params) => {
|
|
595
675
|
await db.execute(sql, params);
|
|
@@ -606,13 +686,12 @@ export default class AtlasProvider {
|
|
|
606
686
|
// atomically (schema + deferred + tracking committed together).
|
|
607
687
|
transaction: db.transaction?.bind(db),
|
|
608
688
|
};
|
|
609
|
-
|
|
689
|
+
return new MigrationRunner(adapter, {
|
|
610
690
|
migrationsDir: migrationsPath,
|
|
611
691
|
dialect: dialectFromUrl(url),
|
|
612
692
|
tableName,
|
|
613
693
|
naturalSort: options?.naturalSort,
|
|
614
694
|
disableTransactions: options?.disableTransactions,
|
|
615
695
|
});
|
|
616
|
-
await runner.migrate();
|
|
617
696
|
}
|
|
618
697
|
}
|
package/src/BaseEntity.ts
CHANGED
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
COMPUTED_KEY,
|
|
31
31
|
type ColumnSerializeConfig,
|
|
32
32
|
} from "./metadata-keys.js";
|
|
33
|
+
import { getNamingStrategy } from "./naming/NamingStrategy.js";
|
|
33
34
|
|
|
34
35
|
export interface DomainEvent {
|
|
35
36
|
name: string;
|
|
@@ -225,7 +226,26 @@ export type { ColumnSerializeConfig };
|
|
|
225
226
|
* Internal reserved keys on BaseEntity that must never be treated as database
|
|
226
227
|
* columns or serialized as data. Used by dirty tracking and by `toJSON`.
|
|
227
228
|
*/
|
|
228
|
-
const INTERNAL_KEYS = new Set<string>([
|
|
229
|
+
const INTERNAL_KEYS = new Set<string>([
|
|
230
|
+
"$extras",
|
|
231
|
+
"$original",
|
|
232
|
+
"$sideloaded",
|
|
233
|
+
// Serialization config, not a column. It only needs listing because Lucid
|
|
234
|
+
// serializes from `$attributes` while atlas walks the instance's own
|
|
235
|
+
// properties, so an instance-level `serializeExtras = true` would otherwise
|
|
236
|
+
// come out in the JSON it is configuring.
|
|
237
|
+
"serializeExtras",
|
|
238
|
+
]);
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* How a model opts into serializing `$extras` (Lucid `serializeExtras`).
|
|
242
|
+
*
|
|
243
|
+
* `true` nests the bag under `meta`; a function returns the shape to merge
|
|
244
|
+
* verbatim and receives the bag.
|
|
245
|
+
*/
|
|
246
|
+
export type SerializeExtras =
|
|
247
|
+
| boolean
|
|
248
|
+
| ((extras: Record<string, unknown>) => Record<string, unknown>);
|
|
229
249
|
|
|
230
250
|
/**
|
|
231
251
|
* Structural (cross-realm-safe) check for a date value exposing `toISO()` — a
|
|
@@ -652,7 +672,6 @@ export class BaseEntity {
|
|
|
652
672
|
`${ctor.name}: cannot declare both 'fillable' and 'guarded'`,
|
|
653
673
|
);
|
|
654
674
|
}
|
|
655
|
-
const known = this.#knownColumnKeys();
|
|
656
675
|
const allowed = (key: string): boolean => {
|
|
657
676
|
if (ctor.fillable) return ctor.fillable.includes(key);
|
|
658
677
|
if (ctor.guarded) return !ctor.guarded.includes(key);
|
|
@@ -676,25 +695,109 @@ export class BaseEntity {
|
|
|
676
695
|
}
|
|
677
696
|
}
|
|
678
697
|
for (const [k, v] of Object.entries(payload)) {
|
|
679
|
-
|
|
680
|
-
if (!allowed(k)) throw new MassAssignmentError(ctor.name, k);
|
|
681
|
-
// Otherwise reject keys that aren't declared columns at all (Lucid
|
|
682
|
-
// strict), unless the caller opts into dropping extras.
|
|
683
|
-
if (!known.has(k)) {
|
|
684
|
-
if (allowExtraProperties) continue;
|
|
685
|
-
throw new AtlasError(
|
|
686
|
-
"E_EXTRA_PROPERTIES",
|
|
687
|
-
`Cannot fill '${k}' on ${ctor.name}: it is not a declared column.`,
|
|
688
|
-
{
|
|
689
|
-
hint: "Declare it with @Column, or pass allowExtraProperties=true to ignore extra keys.",
|
|
690
|
-
},
|
|
691
|
-
);
|
|
692
|
-
}
|
|
693
|
-
this[k] = v;
|
|
698
|
+
this.#assign(ctor, "fill", allowed, k, v, allowExtraProperties);
|
|
694
699
|
}
|
|
695
700
|
return this;
|
|
696
701
|
}
|
|
697
702
|
|
|
703
|
+
/**
|
|
704
|
+
* Apply one payload entry, shared by `fill` and `merge`.
|
|
705
|
+
*
|
|
706
|
+
* The key is resolved to its property BEFORE the mass-assignment gate runs:
|
|
707
|
+
* gating the raw key would let `{ is_admin: true }` past a
|
|
708
|
+
* `guarded = ['isAdmin']` on its way to being resolved.
|
|
709
|
+
*/
|
|
710
|
+
#assign(
|
|
711
|
+
ctor: typeof BaseEntity,
|
|
712
|
+
operation: "fill" | "merge",
|
|
713
|
+
allowed: (key: string) => boolean,
|
|
714
|
+
key: string,
|
|
715
|
+
value: unknown,
|
|
716
|
+
allowExtraProperties: boolean,
|
|
717
|
+
): void {
|
|
718
|
+
// Mass assignment is the more specific gate and it wins: a key a
|
|
719
|
+
// `fillable` list does not cover is a blocked assignment, not an
|
|
720
|
+
// undeclared column.
|
|
721
|
+
if (!allowed(key)) throw new MassAssignmentError(ctor.name, key);
|
|
722
|
+
|
|
723
|
+
const target = this.#resolveAssignment(key);
|
|
724
|
+
|
|
725
|
+
if (target.kind === "ignore") return;
|
|
726
|
+
|
|
727
|
+
if (target.kind === "extra") {
|
|
728
|
+
// Lucid keeps an unknown key in `$extras` rather than dropping it:
|
|
729
|
+
// an aggregate or a pivot value travelling with the row is exactly
|
|
730
|
+
// what the bag is for. It is never a column, so it cannot reach an
|
|
731
|
+
// INSERT.
|
|
732
|
+
if (allowExtraProperties) {
|
|
733
|
+
this.$extras[key] = value;
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
throw new AtlasError(
|
|
737
|
+
"E_EXTRA_PROPERTIES",
|
|
738
|
+
`Cannot ${operation} '${key}' on ${ctor.name}: it is not a declared column.`,
|
|
739
|
+
{
|
|
740
|
+
hint: `Declare it with @Column, or pass allowExtraProperties=true to keep extra keys in $extras.`,
|
|
741
|
+
},
|
|
742
|
+
);
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
// Checked again under the resolved name: the gate above saw the DB column
|
|
746
|
+
// name, so `{ is_admin: true }` would otherwise walk past a
|
|
747
|
+
// `guarded = ['isAdmin']` on its way to resolving.
|
|
748
|
+
if (target.property !== key && !allowed(target.property)) {
|
|
749
|
+
throw new MassAssignmentError(ctor.name, target.property);
|
|
750
|
+
}
|
|
751
|
+
this[target.property] = value;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* Where a payload key should land: the property to assign, or why it cannot
|
|
756
|
+
* be assigned. Lucid's `merge` resolution order, in one place so `fill` and
|
|
757
|
+
* `merge` cannot drift apart.
|
|
758
|
+
*
|
|
759
|
+
* The DB column name resolves to its property (Lucid's
|
|
760
|
+
* `$keys.columnsToAttributes`): a payload coming straight off an API or a
|
|
761
|
+
* raw row keys by `created_at`, and refusing it while the model declares
|
|
762
|
+
* `createdAt` is a false rejection.
|
|
763
|
+
*/
|
|
764
|
+
#resolveAssignment(
|
|
765
|
+
key: string,
|
|
766
|
+
):
|
|
767
|
+
| { kind: "property"; property: string }
|
|
768
|
+
| { kind: "ignore" }
|
|
769
|
+
| { kind: "extra" } {
|
|
770
|
+
const ctor = this.constructor as typeof BaseEntity & {
|
|
771
|
+
fillable?: string[];
|
|
772
|
+
guarded?: string[];
|
|
773
|
+
};
|
|
774
|
+
|
|
775
|
+
if (this.#knownColumnKeys().has(key))
|
|
776
|
+
return { kind: "property", property: key };
|
|
777
|
+
|
|
778
|
+
const columns = getColumnMetadata(ctor);
|
|
779
|
+
const naming = getNamingStrategy(ctor);
|
|
780
|
+
for (const column of columns) {
|
|
781
|
+
const dbName = column.columnName ?? naming.columnName(column.propertyKey);
|
|
782
|
+
if (dbName === key)
|
|
783
|
+
return { kind: "property", property: column.propertyKey };
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
// A relation is set through its own API, never by mass assignment —
|
|
787
|
+
// Lucid ignores the key rather than treating it as an extra.
|
|
788
|
+
for (const relation of getRelationMetadata(ctor)) {
|
|
789
|
+
if (relation.propertyKey === key) return { kind: "ignore" };
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
// `$extras`, `$original`, `$sideloaded`: framework state that leaks in
|
|
793
|
+
// when an entity instance is passed as a payload. Not a column, not a
|
|
794
|
+
// typo, and certainly not something to overwrite.
|
|
795
|
+
if (INTERNAL_KEYS.has(key) || key.startsWith("$"))
|
|
796
|
+
return { kind: "ignore" };
|
|
797
|
+
|
|
798
|
+
return { kind: "extra" };
|
|
799
|
+
}
|
|
800
|
+
|
|
698
801
|
/**
|
|
699
802
|
* The set of keys `fill`/`merge` treat as declared attributes: `@Column`
|
|
700
803
|
* property keys, the primary key, and any names the user listed in
|
|
@@ -755,27 +858,13 @@ export class BaseEntity {
|
|
|
755
858
|
`${ctor.name}: cannot declare both 'fillable' and 'guarded'`,
|
|
756
859
|
);
|
|
757
860
|
}
|
|
758
|
-
const known = this.#knownColumnKeys();
|
|
759
861
|
const allowed = (key: string): boolean => {
|
|
760
862
|
if (ctor.fillable) return ctor.fillable.includes(key);
|
|
761
863
|
if (ctor.guarded) return !ctor.guarded.includes(key);
|
|
762
864
|
return true;
|
|
763
865
|
};
|
|
764
866
|
for (const [k, v] of Object.entries(payload)) {
|
|
765
|
-
|
|
766
|
-
throw new MassAssignmentError(ctor.name, k);
|
|
767
|
-
}
|
|
768
|
-
if (!known.has(k)) {
|
|
769
|
-
if (allowExtraProperties) continue;
|
|
770
|
-
throw new AtlasError(
|
|
771
|
-
"E_EXTRA_PROPERTIES",
|
|
772
|
-
`Cannot merge '${k}' on ${ctor.name}: it is not a declared column.`,
|
|
773
|
-
{
|
|
774
|
-
hint: "Declare it with @Column, or pass allowExtraProperties=true to ignore extra keys.",
|
|
775
|
-
},
|
|
776
|
-
);
|
|
777
|
-
}
|
|
778
|
-
this[k] = v;
|
|
867
|
+
this.#assign(ctor, "merge", allowed, k, v, allowExtraProperties);
|
|
779
868
|
}
|
|
780
869
|
return this;
|
|
781
870
|
}
|
|
@@ -838,9 +927,7 @@ export class BaseEntity {
|
|
|
838
927
|
*/
|
|
839
928
|
toJSON(): Record<string, unknown> {
|
|
840
929
|
const ctor = this.constructor as typeof BaseEntity & {
|
|
841
|
-
serializeExtras?:
|
|
842
|
-
| boolean
|
|
843
|
-
| ((extras: Record<string, unknown>) => Record<string, unknown>);
|
|
930
|
+
serializeExtras?: SerializeExtras;
|
|
844
931
|
};
|
|
845
932
|
const result: Record<string, unknown> = {
|
|
846
933
|
...this.serializeAttributes(),
|
|
@@ -849,14 +936,24 @@ export class BaseEntity {
|
|
|
849
936
|
};
|
|
850
937
|
|
|
851
938
|
// $extras (aggregates / pivot values) are serialized only when the model
|
|
852
|
-
// opts in
|
|
853
|
-
//
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
939
|
+
// opts in — Lucid parity (default OFF), so internal aggregates never leak
|
|
940
|
+
// into API JSON by default.
|
|
941
|
+
//
|
|
942
|
+
// Lucid reads `serializeExtras` off the INSTANCE. The static form is what
|
|
943
|
+
// atlas shipped, so both are honoured and the instance wins; a model
|
|
944
|
+
// written for either works unchanged.
|
|
945
|
+
const optIn =
|
|
946
|
+
(this as { serializeExtras?: SerializeExtras }).serializeExtras ??
|
|
947
|
+
ctor.serializeExtras;
|
|
948
|
+
if (!optIn) return result;
|
|
949
|
+
|
|
950
|
+
// `true` nests the bag under `meta`, as Lucid does — spreading it at the
|
|
951
|
+
// top level let an aggregate collide with a real column of the same name.
|
|
952
|
+
// A function returns the shape verbatim, so it can choose otherwise.
|
|
953
|
+
if (typeof optIn === "function") {
|
|
954
|
+
return { ...result, ...optIn.call(this, this.$extras) };
|
|
955
|
+
}
|
|
956
|
+
return { ...result, meta: this.$extras };
|
|
860
957
|
}
|
|
861
958
|
|
|
862
959
|
/**
|
package/src/BaseRepository.ts
CHANGED
|
@@ -24,6 +24,7 @@ import type {
|
|
|
24
24
|
import { REPO_REF } from "./BaseEntity.js";
|
|
25
25
|
import {
|
|
26
26
|
type DateColumnConfig,
|
|
27
|
+
defaultRelationForeignKey,
|
|
27
28
|
ensureEntityMetadata,
|
|
28
29
|
getColumnMetadata,
|
|
29
30
|
getDateColumnConfig,
|
|
@@ -413,7 +414,8 @@ export class BaseRepository<T extends BaseEntity> {
|
|
|
413
414
|
const related = rel.target();
|
|
414
415
|
if (rel.type === "belongsTo") {
|
|
415
416
|
// FK lives on THIS table, references the related (owner) PK.
|
|
416
|
-
const fk =
|
|
417
|
+
const fk =
|
|
418
|
+
rel.foreignKey ?? defaultRelationForeignKey("hasMany", related);
|
|
417
419
|
const ownerKey = rel.ownerKey ?? getPrimaryKey(related) ?? "id";
|
|
418
420
|
const ownerDb =
|
|
419
421
|
getColumnMetadata(related).find((c) => c.propertyKey === ownerKey)
|
|
@@ -422,7 +424,8 @@ export class BaseRepository<T extends BaseEntity> {
|
|
|
422
424
|
if (cast) registerColumnCast(this.#tableName, fk, cast);
|
|
423
425
|
} else {
|
|
424
426
|
// hasOne / hasMany: FK lives on the RELATED table, references THIS PK.
|
|
425
|
-
const fk =
|
|
427
|
+
const fk =
|
|
428
|
+
rel.foreignKey ?? defaultRelationForeignKey("hasMany", entityClass);
|
|
426
429
|
const localKey = rel.localKey ?? this.#primaryKey;
|
|
427
430
|
const cast = this.#castTypes[this.#dbColumn(localKey)];
|
|
428
431
|
// Boot the related model on demand (Lucid lazy-boot): a related model
|
|
@@ -660,7 +663,7 @@ export class BaseRepository<T extends BaseEntity> {
|
|
|
660
663
|
* the specific hook runs before the general `beforeSave`).
|
|
661
664
|
*
|
|
662
665
|
* An unknown key throws by default (Lucid); pass `{ allowExtraProperties: true }`
|
|
663
|
-
* to
|
|
666
|
+
* to keep it in `$extras` instead. A bare boolean is the legacy `quiet` flag.
|
|
664
667
|
*/
|
|
665
668
|
async create(
|
|
666
669
|
data: Partial<Record<string, unknown>>,
|
|
@@ -681,14 +684,20 @@ export class BaseRepository<T extends BaseEntity> {
|
|
|
681
684
|
} else if (key.startsWith("$")) {
|
|
682
685
|
// Framework-internal (`$extras`, `$trx`, …) — leaks in when an entity
|
|
683
686
|
// instance is passed as data. Not a user column and not a typo; skip.
|
|
684
|
-
} else if (
|
|
687
|
+
} else if (allowExtraProperties) {
|
|
688
|
+
// Kept, not dropped: Lucid puts an unknown key in `$extras`
|
|
689
|
+
// (`this.$extras[key] = value`), which is where an aggregate or a
|
|
690
|
+
// pivot value travelling with the payload belongs. It is not a
|
|
691
|
+
// declared column, so it can never reach the INSERT.
|
|
692
|
+
entity.$extras[key] = value;
|
|
693
|
+
} else {
|
|
685
694
|
// Adonis Lucid throws on an unknown property by default (a typo'd or
|
|
686
695
|
// stray key is a bug, not something to silently drop). Opt out with
|
|
687
696
|
// `create(data, { allowExtraProperties: true })`.
|
|
688
697
|
throw new AtlasError(
|
|
689
698
|
"E_UNKNOWN_COLUMN",
|
|
690
699
|
`Cannot assign '${key}' — it is not a column on ${this.#entityClass.name}. ` +
|
|
691
|
-
"Pass { allowExtraProperties: true } to
|
|
700
|
+
"Pass { allowExtraProperties: true } to keep unknown keys in $extras.",
|
|
692
701
|
);
|
|
693
702
|
}
|
|
694
703
|
}
|
|
@@ -2163,8 +2172,8 @@ export class BaseRepository<T extends BaseEntity> {
|
|
|
2163
2172
|
const fkCol =
|
|
2164
2173
|
relation.foreignKey ??
|
|
2165
2174
|
(relation.type === "belongsTo"
|
|
2166
|
-
?
|
|
2167
|
-
:
|
|
2175
|
+
? defaultRelationForeignKey("belongsTo", relatedClass)
|
|
2176
|
+
: defaultRelationForeignKey("hasMany", this.#entityClass));
|
|
2168
2177
|
const fkProp = snakeToCamel(fkCol);
|
|
2169
2178
|
|
|
2170
2179
|
const injectFk = (
|
|
@@ -2363,9 +2372,11 @@ export class BaseRepository<T extends BaseEntity> {
|
|
|
2363
2372
|
throw new Error(`@ManyToMany ${relationName} requires pivot options`);
|
|
2364
2373
|
const pivot = relation.pivot;
|
|
2365
2374
|
const pivotFk =
|
|
2366
|
-
pivot.foreignKey ??
|
|
2375
|
+
pivot.foreignKey ??
|
|
2376
|
+
defaultRelationForeignKey("manyToMany", this.#entityClass);
|
|
2367
2377
|
const pivotOther =
|
|
2368
|
-
pivot.otherKey ??
|
|
2378
|
+
pivot.otherKey ??
|
|
2379
|
+
defaultRelationForeignKey("manyToMany", relatedClass);
|
|
2369
2380
|
// Resolve the related PK to its DB column (multi-word / columnName),
|
|
2370
2381
|
// mirroring the eager-preload fix — a raw property name here targets
|
|
2371
2382
|
// the wrong column in the correlated EXISTS.
|
|
@@ -2463,9 +2474,11 @@ export class BaseRepository<T extends BaseEntity> {
|
|
|
2463
2474
|
const parentLocal =
|
|
2464
2475
|
relation.localKey ?? getPrimaryKey(this.#entityClass) ?? "id";
|
|
2465
2476
|
const firstKey =
|
|
2466
|
-
relation.firstKey ??
|
|
2477
|
+
relation.firstKey ??
|
|
2478
|
+
defaultRelationForeignKey("hasMany", this.#entityClass);
|
|
2467
2479
|
const secondKey =
|
|
2468
|
-
relation.secondKey ??
|
|
2480
|
+
relation.secondKey ??
|
|
2481
|
+
defaultRelationForeignKey("hasMany", throughClass);
|
|
2469
2482
|
const secondLocal = relation.secondLocalKey ?? throughPk;
|
|
2470
2483
|
q.whereIn(
|
|
2471
2484
|
secondKey,
|
|
@@ -2607,9 +2620,10 @@ export class BaseRepository<T extends BaseEntity> {
|
|
|
2607
2620
|
const pivot = relation.pivot;
|
|
2608
2621
|
const pivotTable = pivot.pivotTable;
|
|
2609
2622
|
const pivotFk =
|
|
2610
|
-
pivot.foreignKey ??
|
|
2623
|
+
pivot.foreignKey ??
|
|
2624
|
+
defaultRelationForeignKey("manyToMany", this.#entityClass);
|
|
2611
2625
|
const pivotOther =
|
|
2612
|
-
pivot.otherKey ??
|
|
2626
|
+
pivot.otherKey ?? defaultRelationForeignKey("manyToMany", relatedClass);
|
|
2613
2627
|
const tsConfig = pivot.pivotTimestamps;
|
|
2614
2628
|
const pivotAdapters = pivot.pivotColumnAdapters;
|
|
2615
2629
|
const dialect = this.#dialect;
|