@c9up/atlas 0.1.19 → 0.2.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/README.md +55 -14
- package/db.darwin-arm64.node +0 -0
- package/db.darwin-x64.node +0 -0
- package/db.linux-arm64-gnu.node +0 -0
- package/db.linux-x64-gnu.node +0 -0
- package/db.win32-x64-msvc.node +0 -0
- package/dist/AtlasProvider.d.ts +6 -0
- package/dist/AtlasProvider.d.ts.map +1 -1
- package/dist/AtlasProvider.js +2 -2
- package/dist/AtlasProvider.js.map +1 -1
- package/dist/BaseEntity.d.ts +164 -5
- package/dist/BaseEntity.d.ts.map +1 -1
- package/dist/BaseEntity.js +339 -33
- package/dist/BaseEntity.js.map +1 -1
- package/dist/BaseModel.d.ts +91 -0
- package/dist/BaseModel.d.ts.map +1 -0
- package/dist/BaseModel.js +193 -0
- package/dist/BaseModel.js.map +1 -0
- package/dist/BaseRepository.d.ts +71 -15
- package/dist/BaseRepository.d.ts.map +1 -1
- package/dist/BaseRepository.js +1355 -384
- package/dist/BaseRepository.js.map +1 -1
- package/dist/ModelQuery.d.ts +341 -18
- package/dist/ModelQuery.d.ts.map +1 -1
- package/dist/ModelQuery.js +1406 -177
- package/dist/ModelQuery.js.map +1 -1
- package/dist/Transaction.d.ts +17 -0
- package/dist/Transaction.d.ts.map +1 -1
- package/dist/Transaction.js +57 -5
- package/dist/Transaction.js.map +1 -1
- package/dist/adapters/NapiDbAdapter.d.ts +33 -4
- package/dist/adapters/NapiDbAdapter.d.ts.map +1 -1
- package/dist/adapters/NapiDbAdapter.js +101 -11
- package/dist/adapters/NapiDbAdapter.js.map +1 -1
- package/dist/console/migrationCommands.d.ts +48 -0
- package/dist/console/migrationCommands.d.ts.map +1 -0
- package/dist/console/migrationCommands.js +220 -0
- package/dist/console/migrationCommands.js.map +1 -0
- package/dist/decorators/entity.d.ts +37 -6
- package/dist/decorators/entity.d.ts.map +1 -1
- package/dist/decorators/entity.js +32 -2
- package/dist/decorators/entity.js.map +1 -1
- package/dist/events.d.ts +64 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +82 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/metadata-keys.d.ts +3 -2
- package/dist/metadata-keys.d.ts.map +1 -1
- package/dist/naming/NamingStrategy.d.ts +7 -0
- package/dist/naming/NamingStrategy.d.ts.map +1 -1
- package/dist/naming/NamingStrategy.js +16 -0
- package/dist/naming/NamingStrategy.js.map +1 -1
- package/dist/schema/Migration.d.ts +26 -3
- package/dist/schema/Migration.d.ts.map +1 -1
- package/dist/schema/Migration.js +33 -24
- package/dist/schema/Migration.js.map +1 -1
- package/dist/schema/MigrationRunner.d.ts +43 -32
- package/dist/schema/MigrationRunner.d.ts.map +1 -1
- package/dist/schema/MigrationRunner.js +211 -26
- package/dist/schema/MigrationRunner.js.map +1 -1
- package/dist/schema/Schema.d.ts +57 -0
- package/dist/schema/Schema.d.ts.map +1 -1
- package/dist/schema/Schema.js +138 -3
- package/dist/schema/Schema.js.map +1 -1
- package/dist/schema/TableBuilder.d.ts +247 -8
- package/dist/schema/TableBuilder.d.ts.map +1 -1
- package/dist/schema/TableBuilder.js +607 -41
- package/dist/schema/TableBuilder.js.map +1 -1
- package/dist/schema/catalog.d.ts +47 -0
- package/dist/schema/catalog.d.ts.map +1 -0
- package/dist/schema/catalog.js +111 -0
- package/dist/schema/catalog.js.map +1 -0
- package/dist/schema/types.d.ts +150 -1
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema/types.js +11 -0
- package/dist/schema/types.js.map +1 -1
- package/dist/services/db.d.ts +6 -0
- package/dist/services/db.d.ts.map +1 -1
- package/dist/services/db.js +17 -0
- package/dist/services/db.js.map +1 -1
- package/dist/testing/DatabaseCleanup.d.ts +7 -4
- package/dist/testing/DatabaseCleanup.d.ts.map +1 -1
- package/dist/testing/DatabaseCleanup.js +21 -18
- package/dist/testing/DatabaseCleanup.js.map +1 -1
- package/dist/testing/Factory.d.ts +70 -5
- package/dist/testing/Factory.d.ts.map +1 -1
- package/dist/testing/Factory.js +209 -10
- package/dist/testing/Factory.js.map +1 -1
- package/index.darwin-arm64.node +0 -0
- package/index.darwin-x64.node +0 -0
- package/index.linux-arm64-gnu.node +0 -0
- package/index.linux-x64-gnu.node +0 -0
- package/index.win32-x64-msvc.node +0 -0
- package/package.json +3 -1
- package/scripts/guard-publish.mjs +15 -0
- package/src/AtlasProvider.ts +8 -1
- package/src/BaseEntity.ts +431 -41
- package/src/BaseModel.ts +324 -0
- package/src/BaseRepository.ts +1589 -419
- package/src/ModelQuery.ts +1817 -203
- package/src/Transaction.ts +68 -5
- package/src/adapters/NapiDbAdapter.ts +159 -10
- package/src/console/migrationCommands.ts +258 -0
- package/src/decorators/entity.ts +53 -6
- package/src/events.ts +112 -0
- package/src/index.ts +19 -0
- package/src/metadata-keys.ts +3 -2
- package/src/naming/NamingStrategy.ts +23 -0
- package/src/schema/Migration.ts +42 -3
- package/src/schema/MigrationRunner.ts +270 -27
- package/src/schema/Schema.ts +210 -3
- package/src/schema/TableBuilder.ts +735 -41
- package/src/schema/catalog.ts +166 -0
- package/src/schema/types.ts +137 -2
- package/src/services/db.ts +28 -0
- package/src/testing/DatabaseCleanup.ts +23 -22
- package/src/testing/Factory.ts +332 -15
package/README.md
CHANGED
|
@@ -1,11 +1,52 @@
|
|
|
1
1
|
# @c9up/atlas
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
AdonisJS Lucid–style ORM for Node.js — Active Record **models** *and* a Data Mapper **repository**, entity decorators, a fluent QueryBuilder, and domain events.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Active Record (AdonisJS Lucid parity)
|
|
6
|
+
|
|
7
|
+
Extend `BaseModel` for the Lucid-style Active Record API: static finders/creators
|
|
8
|
+
plus `instance.save()` / `instance.delete()`. `@Entity('table')` is **optional** —
|
|
9
|
+
the table name is inferred from the class name (`User` → `users`).
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { BaseModel, Column, PrimaryKey } from '@c9up/atlas'
|
|
13
|
+
|
|
14
|
+
class User extends BaseModel {
|
|
15
|
+
@PrimaryKey() declare id: number
|
|
16
|
+
@Column() declare email: string
|
|
17
|
+
@Column() declare role: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const user = await User.find(1)
|
|
21
|
+
const admin = await User.findBy({ role: 'admin' }) // object clause
|
|
22
|
+
const fresh = await User.create({ email: 'a@b.co', role: 'user' })
|
|
23
|
+
|
|
24
|
+
if (user) {
|
|
25
|
+
user.email = 'new@b.co'
|
|
26
|
+
await user.save() // UPDATE only the dirty columns
|
|
27
|
+
console.log(user.$isPersisted, user.$isDirty)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// bulk, keyed by a unique column, in one transaction
|
|
31
|
+
await User.updateOrCreateMany('email', rows)
|
|
32
|
+
|
|
33
|
+
// per-instance serialization visibility
|
|
34
|
+
user?.makeHidden('role').toJSON()
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Static surface: `find`, `findOrFail`, `findBy`, `findByOrFail`, `findMany`,
|
|
38
|
+
`findManyBy`, `all`, `first`, `firstOrFail`, `query`, `create`, `createMany`,
|
|
39
|
+
`firstOrCreate`, `firstOrNew`, `updateOrCreate`, `updateOrCreateMany`,
|
|
40
|
+
`fetchOrCreateMany`, `fetchOrNewUpMany`, `truncate`. Config: `static table`,
|
|
41
|
+
`static connection`.
|
|
42
|
+
|
|
43
|
+
## Data Mapper
|
|
44
|
+
|
|
45
|
+
Prefer separation of persistence from the model? Use `BaseRepository` directly —
|
|
46
|
+
same surface, with the connection injected.
|
|
6
47
|
|
|
7
48
|
```typescript
|
|
8
|
-
import { Entity, Column, PrimaryKey, BaseEntity
|
|
49
|
+
import { BaseRepository, Entity, Column, PrimaryKey, BaseEntity } from '@c9up/atlas'
|
|
9
50
|
|
|
10
51
|
@Entity('orders')
|
|
11
52
|
class Order extends BaseEntity {
|
|
@@ -14,21 +55,21 @@ class Order extends BaseEntity {
|
|
|
14
55
|
@Column({ type: 'decimal' }) declare total: number
|
|
15
56
|
}
|
|
16
57
|
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
.orderBy('createdAt', 'desc')
|
|
20
|
-
.paginate(1, 20)
|
|
21
|
-
.toSQL()
|
|
58
|
+
const repo = new BaseRepository(Order, db)
|
|
59
|
+
const active = await repo.query().where('status', 'active').exec()
|
|
22
60
|
```
|
|
23
61
|
|
|
24
62
|
## Features
|
|
25
63
|
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
- `
|
|
30
|
-
-
|
|
31
|
-
-
|
|
64
|
+
- **Two styles** — Active Record (`BaseModel`) and Data Mapper (`BaseRepository`), same repository underneath
|
|
65
|
+
- Zero-config conventions: table + primary key inferred, overridable via `static table` / `@Entity` / `@PrimaryKey`
|
|
66
|
+
- Model state: `$isPersisted`, `$isNew`, `$isLocal`, `$isDeleted`, `$dirty` / `isDirty()`, `$primaryKeyValue`
|
|
67
|
+
- Mass-assignment protection (`static fillable` / `guarded`) enforced on `create` / `createMany` / `updateOrCreate`
|
|
68
|
+
- Serialization: `static hidden`/`visible`, per-instance `makeHidden`/`makeVisible`, `@Column({ serializeAs, serialize })`, `@computed`
|
|
69
|
+
- `@Entity`, `@Column`, `@PrimaryKey`, `@BelongsTo`, `@HasMany`, `@ManyToMany` + relation preloading
|
|
70
|
+
- Fluent QueryBuilder with parameterized SQL (injection-safe): CTE (`.with()`), UNION, WHERE EXISTS, GROUP BY, HAVING, DISTINCT
|
|
71
|
+
- `RawSql` tagged template; domain events accumulated on entities, dispatched after save
|
|
72
|
+
- Interactive transactions, soft deletes, multi-dialect (sqlite / postgres / mysql)
|
|
32
73
|
|
|
33
74
|
## License
|
|
34
75
|
|
package/db.darwin-arm64.node
CHANGED
|
Binary file
|
package/db.darwin-x64.node
CHANGED
|
Binary file
|
package/db.linux-arm64-gnu.node
CHANGED
|
Binary file
|
package/db.linux-x64-gnu.node
CHANGED
|
Binary file
|
package/db.win32-x64-msvc.node
CHANGED
|
Binary file
|
package/dist/AtlasProvider.d.ts
CHANGED
|
@@ -66,6 +66,12 @@ export interface ConnectionConfig {
|
|
|
66
66
|
poolMin?: number;
|
|
67
67
|
/** Maximum pool connections (default: 10) */
|
|
68
68
|
poolMax?: number;
|
|
69
|
+
/**
|
|
70
|
+
* Emit a `db:query` event for every statement on this connection (Lucid's
|
|
71
|
+
* `debug` connection option). Off by default — subscribe with `onDbQuery`
|
|
72
|
+
* to receive them; with no subscriber nothing is emitted either way.
|
|
73
|
+
*/
|
|
74
|
+
debug?: boolean;
|
|
69
75
|
/**
|
|
70
76
|
* Connection-level pragmas (sqlite only). Each entry becomes a
|
|
71
77
|
* `PRAGMA <key> = <value>;` issued before the first query.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AtlasProvider.d.ts","sourceRoot":"","sources":["../src/AtlasProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAaH;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,eAAe;IAC/B,SAAS,EAAE;QACV,SAAS,CACR,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,KAAK,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC,EAC5D,OAAO,EAAE,MAAM,OAAO,GACpB,IAAI,CAAC;KACR,CAAC;IACF,MAAM,EAAE;QAAE,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAA;KAAE,CAAC;CACzD;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB;;;EAGrB,CAAC;AAEZ,iCAAiC;AACjC,MAAM,WAAW,gBAAgB;IAChC,4EAA4E;IAC5E,GAAG,EAAE,MAAM,CAAC;IACZ,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E,OAAO,EAAE,KAAK,OAAO,CAAC,CAAC;QAC7D,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;KACxB,CAAC;CACF;AAED,MAAM,CAAC,OAAO,OAAO,aAAa;;IAKrB,SAAS,CAAC,GAAG,EAAE,eAAe;gBAApB,GAAG,EAAE,eAAe;IAE1C,QAAQ;IAEF,IAAI;IAoGJ,QAAQ;IAqCR,KAAK;IAiBL,KAAK;CAwDX"}
|
package/dist/AtlasProvider.js
CHANGED
|
@@ -67,11 +67,11 @@ export default class AtlasProvider {
|
|
|
67
67
|
// close every successful one before rethrowing so a partial boot never
|
|
68
68
|
// leaks pools/sockets.
|
|
69
69
|
const entries = Object.entries(connections);
|
|
70
|
-
const results = await Promise.allSettled(entries.map(([, settings]) => createNapiConnection(settings.url, settings.poolMin ?? 1, settings.poolMax ?? 10, settings.pragmas, {
|
|
70
|
+
const results = await Promise.allSettled(entries.map(([name, settings]) => createNapiConnection(settings.url, settings.poolMin ?? 1, settings.poolMax ?? 10, settings.pragmas, {
|
|
71
71
|
retries: settings.connectRetries,
|
|
72
72
|
backoffMs: settings.connectBackoffMs,
|
|
73
73
|
timeoutMs: settings.connectTimeoutMs,
|
|
74
|
-
})));
|
|
74
|
+
}, { debug: settings.debug ?? false, connectionName: name })));
|
|
75
75
|
const failures = [];
|
|
76
76
|
const successes = [];
|
|
77
77
|
results.forEach((r, i) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AtlasProvider.js","sourceRoot":"","sources":["../src/AtlasProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAEN,oBAAoB,GACpB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAEN,eAAe,GACf,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAw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MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC;QAC/C,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC;YAAE,OAAO;QAExC,MAAM,OAAO,GAAoB;YAChC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE;gBAC9B,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YAC/B,CAAC;YACD,KAAK,EAAE,CAAI,GAAW,EAAE,MAAkB,EAAE,EAAE,CAC7C,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,CAAiB;YACtC,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE;YACvB,qEAAqE;YACrE,yEAAyE;YACzE,wEAAwE;YACxE,sDAAsD;YACtD,gBAAgB,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC;SAC7D,CAAC;QACF,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,OAAO,EAAE;YAC3C,aAAa,EAAE,cAAc;YAC7B,OAAO,EAAE,cAAc,CAAC,GAAG,CAAC;YAC5B,SAAS;SACT,CAAC,CAAC;QACH,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;CACD"}
|
package/dist/BaseEntity.d.ts
CHANGED
|
@@ -55,15 +55,35 @@ export interface HasOneRelationProxy extends BaseRelationProxy, RelationUpsertPr
|
|
|
55
55
|
export interface HasManyRelationProxy extends BulkRelationProxy, RelationUpsertProxy {
|
|
56
56
|
readonly type: "hasMany";
|
|
57
57
|
}
|
|
58
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* `@BelongsTo` — the FK lives on THIS model, so the only writes are `associate`
|
|
60
|
+
* (link an owner) / `dissociate` (clear it). create/save/createMany/saveMany are
|
|
61
|
+
* NOT valid here (they'd inject the FK into the owner table and save this model
|
|
62
|
+
* before it has an owner): they throw at runtime and are typed `Promise<never>`
|
|
63
|
+
* so a caller who narrows to belongsTo gets a compile-time signal too — same
|
|
64
|
+
* pattern as `@HasOne`'s bulk methods. AdonisJS Lucid's belongsTo client exposes
|
|
65
|
+
* only associate/dissociate.
|
|
66
|
+
*/
|
|
59
67
|
export interface BelongsToRelationProxy extends BulkRelationProxy {
|
|
60
68
|
readonly type: "belongsTo";
|
|
69
|
+
create(data: Record<string, unknown>): Promise<never>;
|
|
70
|
+
save(related: BaseEntity): Promise<never>;
|
|
71
|
+
createMany(rows: Array<Record<string, unknown>>): Promise<never>;
|
|
72
|
+
saveMany(related: BaseEntity[]): Promise<never>;
|
|
61
73
|
/** Set `parent.<fk> = model.<ownerKey>` and save the parent. Rejects null/undefined. */
|
|
62
74
|
associate(model: BaseEntity): Promise<void>;
|
|
63
75
|
/** Clear the FK and save the parent. */
|
|
64
76
|
dissociate(): Promise<void>;
|
|
65
77
|
}
|
|
66
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
* `@ManyToMany` — the pivot write API.
|
|
80
|
+
*
|
|
81
|
+
* Not the *full* Lucid surface, despite what this used to say. Still missing:
|
|
82
|
+
* `pivotAttributes`/`performSync` on `save`/`saveMany`/`create`/`createMany`
|
|
83
|
+
* (they attach with empty extras), a public `updatePivot` (it exists but only
|
|
84
|
+
* `sync` calls it), `pivotQuery`, and an overridable `relatedKey` (the related
|
|
85
|
+
* primary key is assumed).
|
|
86
|
+
*/
|
|
67
87
|
export interface ManyToManyRelationProxy extends BulkRelationProxy {
|
|
68
88
|
readonly type: "manyToMany";
|
|
69
89
|
/** Insert pivot rows. Accepts `id[]` or `{ id: extras }`. */
|
|
@@ -76,7 +96,27 @@ export interface ManyToManyRelationProxy extends BulkRelationProxy {
|
|
|
76
96
|
*/
|
|
77
97
|
sync(target: Array<string | number> | Record<string, Record<string, unknown>>, additive?: boolean): Promise<void>;
|
|
78
98
|
}
|
|
79
|
-
|
|
99
|
+
/**
|
|
100
|
+
* `@HasOneThrough` / `@HasManyThrough` — READ-ONLY two-hop relations. Lucid does
|
|
101
|
+
* NOT expose persistence on a through relation (verified against the Lucid docs):
|
|
102
|
+
* you persist via the intermediate model. `query()` traverses the through table;
|
|
103
|
+
* create/save/createMany/saveMany throw at runtime and are typed `Promise<never>`
|
|
104
|
+
* so a caller who narrows to a through relation gets a compile-time signal too.
|
|
105
|
+
*
|
|
106
|
+
* `@HasManyThrough` is Lucid parity. `@HasOneThrough` is an atlas addition —
|
|
107
|
+
* Lucid has no such relation (checked against adonisjs/lucid `develop`:
|
|
108
|
+
* `src/orm/relations/` holds belongs_to, has_many, has_many_through, has_one and
|
|
109
|
+
* many_to_many, and no hasOneThrough appears in its types). It is the same
|
|
110
|
+
* two-hop traversal returning a single row instead of an array.
|
|
111
|
+
*/
|
|
112
|
+
export interface HasManyThroughRelationProxy extends BulkRelationProxy {
|
|
113
|
+
readonly type: "hasOneThrough" | "hasManyThrough";
|
|
114
|
+
create(data: Record<string, unknown>): Promise<never>;
|
|
115
|
+
save(related: BaseEntity): Promise<never>;
|
|
116
|
+
createMany(rows: Array<Record<string, unknown>>): Promise<never>;
|
|
117
|
+
saveMany(related: BaseEntity[]): Promise<never>;
|
|
118
|
+
}
|
|
119
|
+
export type RelationProxy = HasOneRelationProxy | HasManyRelationProxy | BelongsToRelationProxy | ManyToManyRelationProxy | HasManyThroughRelationProxy;
|
|
80
120
|
export type { ColumnSerializeConfig };
|
|
81
121
|
export declare class BaseEntity {
|
|
82
122
|
#private;
|
|
@@ -90,6 +130,13 @@ export declare class BaseEntity {
|
|
|
90
130
|
* @implements Story 32.5
|
|
91
131
|
*/
|
|
92
132
|
$extras: Record<string, unknown>;
|
|
133
|
+
/**
|
|
134
|
+
* Sideloaded data — arbitrary context attached to the instance (AdonisJS Lucid
|
|
135
|
+
* `$sideloaded`), e.g. the current tenant/user threaded through from a query.
|
|
136
|
+
* Never a column, never dirty-tracked, never serialized. Set it manually;
|
|
137
|
+
* query-level `.sideload()` auto-propagation to hydrated results is not wired.
|
|
138
|
+
*/
|
|
139
|
+
$sideloaded: Record<string, unknown>;
|
|
93
140
|
/**
|
|
94
141
|
* Snapshot of the column values at the moment this entity was hydrated from
|
|
95
142
|
* the database. Used by dirty tracking (`isDirty`, `$dirty`). Populated by
|
|
@@ -99,6 +146,47 @@ export declare class BaseEntity {
|
|
|
99
146
|
* @implements Story 32.2
|
|
100
147
|
*/
|
|
101
148
|
$original: Record<string, unknown>;
|
|
149
|
+
/**
|
|
150
|
+
* Force the next `save()` to run an UPDATE even when nothing is dirty — e.g. to
|
|
151
|
+
* fire DB triggers or re-persist the current state (AdonisJS Lucid
|
|
152
|
+
* `enableForceUpdate`). The flag is consumed by that save. Chainable.
|
|
153
|
+
*/
|
|
154
|
+
enableForceUpdate(): this;
|
|
155
|
+
/** @internal Read-and-clear the force-update flag — called by `BaseRepository`. */
|
|
156
|
+
$consumeForceUpdate(): boolean;
|
|
157
|
+
/**
|
|
158
|
+
* `true` once the row exists in the database — after `save()`/`create()`
|
|
159
|
+
* inserts it or a fetch hydrates it. AdonisJS Lucid `$isPersisted`.
|
|
160
|
+
*/
|
|
161
|
+
get $isPersisted(): boolean;
|
|
162
|
+
/** Inverse of {@link $isPersisted} — a never-persisted instance. Lucid `$isNew`. */
|
|
163
|
+
get $isNew(): boolean;
|
|
164
|
+
/**
|
|
165
|
+
* `true` when the instance originated in memory (`new Model()` / `create()`),
|
|
166
|
+
* `false` when it was fetched from the database. Lucid `$isLocal`.
|
|
167
|
+
*/
|
|
168
|
+
get $isLocal(): boolean;
|
|
169
|
+
/**
|
|
170
|
+
* `true` once `delete()` has removed the row; the instance must not be saved
|
|
171
|
+
* again. Lucid `$isDeleted`.
|
|
172
|
+
*/
|
|
173
|
+
get $isDeleted(): boolean;
|
|
174
|
+
/** The primary-key column's current value. Lucid `$primaryKeyValue`. */
|
|
175
|
+
get $primaryKeyValue(): unknown;
|
|
176
|
+
/** @internal Repository marks the instance deleted after DELETE. */
|
|
177
|
+
markAsDeleted(): void;
|
|
178
|
+
/** @internal Repository flags a DB-originated instance (`$isLocal = false`). */
|
|
179
|
+
markAsFromDatabase(): void;
|
|
180
|
+
/**
|
|
181
|
+
* @internal Revert a fresh INSERT that was rolled back — the row never
|
|
182
|
+
* persisted, so the instance must report `$isNew` again. Named safety
|
|
183
|
+
* deviation from Lucid (which keeps `$isPersisted` after rollback): without
|
|
184
|
+
* this, a later `parent.related('x').create(...)` reads `$isPersisted === true`,
|
|
185
|
+
* skips re-saving the parent, and writes a child with a foreign key pointing at
|
|
186
|
+
* a phantom row. Only used for instances that were provably not persisted
|
|
187
|
+
* before the failed batch.
|
|
188
|
+
*/
|
|
189
|
+
markAsNotPersisted(): void;
|
|
102
190
|
/** Set a property dynamically (used by hydrate/create). */
|
|
103
191
|
setProp(key: string, value: unknown): void;
|
|
104
192
|
/** Set an `$extras` value (used by `withCount`, pivot extras, aggregate loaders). */
|
|
@@ -147,6 +235,11 @@ export declare class BaseEntity {
|
|
|
147
235
|
* when called without arguments.
|
|
148
236
|
*/
|
|
149
237
|
isDirty(field?: string): boolean;
|
|
238
|
+
/**
|
|
239
|
+
* `true` when the instance has unsaved changes since it was hydrated/persisted
|
|
240
|
+
* (AdonisJS Lucid `$isDirty` getter). Equivalent to `isDirty()` with no args.
|
|
241
|
+
*/
|
|
242
|
+
get $isDirty(): boolean;
|
|
150
243
|
/**
|
|
151
244
|
* Revert all dirty columns back to their `$original` values.
|
|
152
245
|
*
|
|
@@ -198,6 +291,11 @@ export declare class BaseEntity {
|
|
|
198
291
|
* @implements Story 31.10
|
|
199
292
|
*/
|
|
200
293
|
load(relationName: string, callback?: (q: unknown) => void): Promise<this>;
|
|
294
|
+
/**
|
|
295
|
+
* Like {@link load} but a no-op when the relation is already populated on this
|
|
296
|
+
* instance (AdonisJS Lucid `loadOnce`). Chainable.
|
|
297
|
+
*/
|
|
298
|
+
loadOnce(relationName: string, callback?: (q: unknown) => void): Promise<this>;
|
|
201
299
|
/**
|
|
202
300
|
* Return a relation proxy bound to this instance. The proxy exposes
|
|
203
301
|
* `create` / `createMany` / `save` / `saveMany` that auto-set the FK.
|
|
@@ -213,19 +311,41 @@ export declare class BaseEntity {
|
|
|
213
311
|
*
|
|
214
312
|
* @implements Story 30.7
|
|
215
313
|
*/
|
|
216
|
-
fill(payload: Record<string, unknown
|
|
314
|
+
fill(payload: Record<string, unknown>, allowExtraProperties?: boolean): this;
|
|
315
|
+
/**
|
|
316
|
+
* Throw `MassAssignmentError` if `key` is blocked by the class's static
|
|
317
|
+
* `fillable` allowlist / `guarded` denylist — the SAME rule `fill()`/`merge()`
|
|
318
|
+
* enforce. Repositories call this in `create`/`createMany`/`updateOrCreate` so
|
|
319
|
+
* those paths cannot bypass mass-assignment protection (a `guarded` column
|
|
320
|
+
* like `role`/`isAdmin` must not be settable from a plain payload).
|
|
321
|
+
*/
|
|
322
|
+
assertMassAssignable(key: string): void;
|
|
217
323
|
/**
|
|
218
324
|
* Patch the entity with a payload, only touching the provided keys. Same
|
|
219
325
|
* allowlist/blocklist rules as `fill` but preserves fields not present in
|
|
220
326
|
* the payload.
|
|
221
327
|
*/
|
|
222
|
-
merge(payload: Record<string, unknown
|
|
328
|
+
merge(payload: Record<string, unknown>, allowExtraProperties?: boolean): this;
|
|
223
329
|
/** Add a domain event to be dispatched after save. */
|
|
224
330
|
addDomainEvent(name: string, data: Record<string, unknown>): void;
|
|
225
331
|
/** Get accumulated domain events (non-destructive read). */
|
|
226
332
|
getDomainEvents(): readonly DomainEvent[];
|
|
227
333
|
/** Clear accumulated domain events. */
|
|
228
334
|
clearDomainEvents(): void;
|
|
335
|
+
/**
|
|
336
|
+
* Number of queued domain events — snapshot this BEFORE a transactional write
|
|
337
|
+
* so a rollback can drop only the events that write added (see
|
|
338
|
+
* {@link restoreDomainEventsTo}), preserving any the caller queued earlier.
|
|
339
|
+
*/
|
|
340
|
+
domainEventCount(): number;
|
|
341
|
+
/**
|
|
342
|
+
* Truncate the queued domain events back to a floor captured before a
|
|
343
|
+
* transactional write. On rollback this drops the tx-added events while
|
|
344
|
+
* KEEPING pre-existing ones (which describe work outside the rolled-back
|
|
345
|
+
* transaction). Events are append-only (`push`), so the first `n` are the
|
|
346
|
+
* pre-existing ones. A floor past the current length is a no-op.
|
|
347
|
+
*/
|
|
348
|
+
restoreDomainEventsTo(n: number): void;
|
|
229
349
|
/** Get and clear accumulated domain events atomically. */
|
|
230
350
|
flushDomainEvents(): DomainEvent[];
|
|
231
351
|
/** Check if entity has pending domain events. */
|
|
@@ -239,6 +359,45 @@ export declare class BaseEntity {
|
|
|
239
359
|
* @implements Story 32.4
|
|
240
360
|
*/
|
|
241
361
|
toJSON(): Record<string, unknown>;
|
|
362
|
+
/**
|
|
363
|
+
* Serialize the regular `@column` attributes only — respecting hidden/visible
|
|
364
|
+
* allowlists and per-column `serializeAs`/`serialize` overrides. Override this
|
|
365
|
+
* to customize attribute serialization (AdonisJS Lucid `serializeAttributes`).
|
|
366
|
+
*/
|
|
367
|
+
protected serializeAttributes(): Record<string, unknown>;
|
|
368
|
+
/**
|
|
369
|
+
* Serialize preloaded relations only — honouring each relation's `serializeAs`
|
|
370
|
+
* (rename, or `null` to hide). Nested entities serialize via their own
|
|
371
|
+
* `toJSON`. Override to customize (AdonisJS Lucid `serializeRelations`).
|
|
372
|
+
*/
|
|
373
|
+
protected serializeRelations(): Record<string, unknown>;
|
|
374
|
+
/**
|
|
375
|
+
* Serialize `@computed` getters only. Override to customize
|
|
376
|
+
* (AdonisJS Lucid `serializeComputed`).
|
|
377
|
+
*/
|
|
378
|
+
protected serializeComputed(): Record<string, unknown>;
|
|
379
|
+
/**
|
|
380
|
+
* Hide these fields when serializing THIS instance, on top of the class-level
|
|
381
|
+
* `static hidden`. Chainable.
|
|
382
|
+
*
|
|
383
|
+
* An atlas addition, not Lucid — see the `#hiddenOverride` note. Lucid's
|
|
384
|
+
* equivalent is the static `@column({ serializeAs: null })`, which atlas
|
|
385
|
+
* supports too; this is the per-instance form Lucid has no answer for.
|
|
386
|
+
*/
|
|
387
|
+
makeHidden(...fields: string[]): this;
|
|
388
|
+
/**
|
|
389
|
+
* Force these fields visible when serializing THIS instance, overriding the
|
|
390
|
+
* class-level `static hidden`/`visible`. Chainable.
|
|
391
|
+
*
|
|
392
|
+
* An atlas addition, not Lucid — see {@link makeHidden}.
|
|
393
|
+
*/
|
|
394
|
+
makeVisible(...fields: string[]): this;
|
|
395
|
+
/**
|
|
396
|
+
* Plain object of the raw columns + preloaded relations + `$extras`, WITHOUT
|
|
397
|
+
* any serialization transform (no `hidden`/`visible`, no `serializeAs`, no
|
|
398
|
+
* per-column `serialize`) — AdonisJS Lucid `toObject()`.
|
|
399
|
+
*/
|
|
400
|
+
toObject(): Record<string, unknown>;
|
|
242
401
|
/**
|
|
243
402
|
* Pick / limit the fields returned by `toJSON()` for a single call.
|
|
244
403
|
*
|
package/dist/BaseEntity.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseEntity.d.ts","sourceRoot":"","sources":["../src/BaseEntity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"BaseEntity.d.ts","sourceRoot":"","sources":["../src/BaseEntity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AASH,OAAO,EACN,oBAAoB,EACpB,YAAY,EACZ,KAAK,qBAAqB,EAC1B,MAAM,oBAAoB,CAAC;AAE5B,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC9B;AAKD,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,CAAC;AAE9C,mFAAmF;AACnF,eAAO,MAAM,QAAQ,eAA8B,CAAC;AAEpD,kHAAkH;AAClH,MAAM,WAAW,aAAa;IAC7B,OAAO,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,KAAK,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