@c9up/atlas 0.1.18 → 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 +171 -7
- package/dist/BaseEntity.d.ts.map +1 -1
- package/dist/BaseEntity.js +339 -31
- 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 +77 -15
- package/dist/BaseRepository.d.ts.map +1 -1
- package/dist/BaseRepository.js +1423 -354
- package/dist/BaseRepository.js.map +1 -1
- package/dist/ModelQuery.d.ts +429 -11
- package/dist/ModelQuery.d.ts.map +1 -1
- package/dist/ModelQuery.js +1733 -145
- 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/SchemaCheck.d.ts.map +1 -1
- package/dist/schema/SchemaCheck.js +3 -1
- package/dist/schema/SchemaCheck.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/introspect.js.map +1 -1
- 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 +4 -1
- package/scripts/guard-publish.mjs +15 -0
- package/src/AtlasProvider.ts +8 -1
- package/src/BaseEntity.ts +449 -40
- package/src/BaseModel.ts +324 -0
- package/src/BaseRepository.ts +1659 -371
- package/src/ModelQuery.ts +2290 -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/SchemaCheck.ts +7 -2
- package/src/schema/TableBuilder.ts +735 -41
- package/src/schema/catalog.ts +166 -0
- package/src/schema/introspect.ts +3 -4
- 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
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import "reflect-metadata";
|
|
7
7
|
import { COLUMN_SERIALIZE_KEY, COMPUTED_KEY, } from "../metadata-keys.js";
|
|
8
|
+
import { getNamingStrategy } from "../naming/NamingStrategy.js";
|
|
8
9
|
const ENTITY_KEY = Symbol("atlas:entity");
|
|
9
10
|
const COLUMNS_KEY = Symbol("atlas:columns");
|
|
10
11
|
const PRIMARY_KEY = Symbol("atlas:primary");
|
|
@@ -32,6 +33,7 @@ export function Column(options) {
|
|
|
32
33
|
serialize: options?.serialize,
|
|
33
34
|
prepare: options?.prepare,
|
|
34
35
|
consume: options?.consume,
|
|
36
|
+
columnName: options?.columnName,
|
|
35
37
|
});
|
|
36
38
|
Reflect.defineMetadata(COLUMNS_KEY, columns, target.constructor);
|
|
37
39
|
}
|
|
@@ -202,7 +204,12 @@ export function HasMany(target, options = {}) {
|
|
|
202
204
|
});
|
|
203
205
|
};
|
|
204
206
|
}
|
|
205
|
-
/**
|
|
207
|
+
/**
|
|
208
|
+
* `@HasOneThrough(() => Related, () => Through, { firstKey, secondKey, localKey, secondLocalKey, onQuery })`
|
|
209
|
+
*
|
|
210
|
+
* An atlas addition — Lucid has no hasOneThrough relation. Same two-hop
|
|
211
|
+
* traversal as {@link HasManyThrough}, returning a single row.
|
|
212
|
+
*/
|
|
206
213
|
export function HasOneThrough(target, through, options = {}) {
|
|
207
214
|
return (proto, propertyKey) => {
|
|
208
215
|
addRelation(proto.constructor, {
|
|
@@ -234,6 +241,10 @@ export function ManyToMany(target, options) {
|
|
|
234
241
|
type: "manyToMany",
|
|
235
242
|
target,
|
|
236
243
|
pivot: options,
|
|
244
|
+
// `localKey` selects which parent column the pivot FK references
|
|
245
|
+
// (default: the parent PK). Without copying it here the value the type
|
|
246
|
+
// accepts is silently dropped and the pivot always targets the PK.
|
|
247
|
+
localKey: options.localKey,
|
|
237
248
|
onQuery: options.onQuery,
|
|
238
249
|
serializeAs: options.serializeAs,
|
|
239
250
|
});
|
|
@@ -248,12 +259,31 @@ function addRelation(target, relation) {
|
|
|
248
259
|
export function getEntityMetadata(target) {
|
|
249
260
|
return Reflect.getMetadata(ENTITY_KEY, target);
|
|
250
261
|
}
|
|
262
|
+
/**
|
|
263
|
+
* Return the class's `@Entity` metadata, SYNTHESIZING it when the decorator is
|
|
264
|
+
* absent: the table name is inferred from the class name via the naming strategy
|
|
265
|
+
* (or an explicit `static table`). AdonisJS Lucid parity — a model needs no
|
|
266
|
+
* explicit `@Entity('table')`. Used by both `BaseModel` and the `BaseRepository`
|
|
267
|
+
* constructor so the Data-Mapper and Active-Record paths share one convention.
|
|
268
|
+
*/
|
|
269
|
+
export function ensureEntityMetadata(target) {
|
|
270
|
+
const existing = getEntityMetadata(target);
|
|
271
|
+
if (existing)
|
|
272
|
+
return existing;
|
|
273
|
+
const staticTable = target.table;
|
|
274
|
+
const table = staticTable ?? getNamingStrategy(target).tableName(target.name);
|
|
275
|
+
Entity(table)(target);
|
|
276
|
+
return getEntityMetadata(target) ?? { tableName: table };
|
|
277
|
+
}
|
|
251
278
|
/** Get column metadata for a class (returns a copy). */
|
|
252
279
|
export function getColumnMetadata(target) {
|
|
253
280
|
return [...(Reflect.getMetadata(COLUMNS_KEY, target) ?? [])];
|
|
254
281
|
}
|
|
255
|
-
/** Get primary key property name. */
|
|
282
|
+
/** Get primary key property name. A `static primaryKey` (AdonisJS Lucid) wins over the `@PrimaryKey()` decorator. */
|
|
256
283
|
export function getPrimaryKey(target) {
|
|
284
|
+
const staticPk = target.primaryKey;
|
|
285
|
+
if (staticPk)
|
|
286
|
+
return staticPk;
|
|
257
287
|
return Reflect.getMetadata(PRIMARY_KEY, target);
|
|
258
288
|
}
|
|
259
289
|
/** Get relation metadata for a class (returns a copy). */
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/decorators/entity.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAA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,0DAA0D;AAC1D,MAAM,UAAU,mBAAmB,CAAC,MAAmB;IACtD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,MAAM,CAAC,IAAI,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"}
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query observability — atlas's equivalent of Lucid's `db:query` event.
|
|
3
|
+
*
|
|
4
|
+
* Agnostic by design: atlas cannot import the framework's emitter (it is a
|
|
5
|
+
* standalone package), so it owns a tiny listener registry instead. An
|
|
6
|
+
* integration package bridges it to whatever emitter the app uses:
|
|
7
|
+
*
|
|
8
|
+
* onDbQuery((event) => emitter.emit('db:query', event))
|
|
9
|
+
*
|
|
10
|
+
* Emission is opt-in. It costs a `performance.now()` pair per query, so it only
|
|
11
|
+
* happens when a connection is configured with `debug: true` or a single query
|
|
12
|
+
* asks via `.debug()` — and even then, only if someone is listening.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* A single executed SQL statement. Mirrors Lucid's `db:query` payload, minus
|
|
16
|
+
* the fields that only make sense inside AdonisJS.
|
|
17
|
+
*/
|
|
18
|
+
export interface DbQueryEvent {
|
|
19
|
+
/** The SQL as sent to the driver, placeholders included. */
|
|
20
|
+
sql: string;
|
|
21
|
+
/** The bound parameters. Never interpolated into `sql`. */
|
|
22
|
+
bindings: readonly unknown[];
|
|
23
|
+
/** Wall-clock duration in milliseconds, including the NAPI round-trip. */
|
|
24
|
+
duration: number;
|
|
25
|
+
/** Connection name, when the app named it. */
|
|
26
|
+
connection?: string;
|
|
27
|
+
/** Entity class name, when the query came from a repository/model. */
|
|
28
|
+
model?: string;
|
|
29
|
+
/** The call that produced it (`exec`, `first`, `paginate`, …). */
|
|
30
|
+
method?: string;
|
|
31
|
+
/** True for schema statements (migrations), false for DML/queries. */
|
|
32
|
+
ddl?: boolean;
|
|
33
|
+
/** True when the statement ran inside an interactive transaction. */
|
|
34
|
+
inTransaction?: boolean;
|
|
35
|
+
/** Set when the statement threw — the event is emitted either way. */
|
|
36
|
+
error?: Error;
|
|
37
|
+
}
|
|
38
|
+
export type DbQueryListener = (event: DbQueryEvent) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Subscribe to every observed query. Returns an unsubscribe function.
|
|
41
|
+
*
|
|
42
|
+
* A listener that throws would otherwise take down the query that triggered it,
|
|
43
|
+
* so throws are swallowed — observability must never change behaviour.
|
|
44
|
+
*/
|
|
45
|
+
export declare function onDbQuery(listener: DbQueryListener): () => void;
|
|
46
|
+
/** Remove every listener. Intended for test teardown. */
|
|
47
|
+
export declare function clearDbQueryListeners(): void;
|
|
48
|
+
/**
|
|
49
|
+
* Whether anyone is listening. Checked before timing a query so the
|
|
50
|
+
* instrumentation costs nothing when unused.
|
|
51
|
+
*/
|
|
52
|
+
export declare function hasDbQueryListeners(): boolean;
|
|
53
|
+
/** Emit to every listener. Package-internal. */
|
|
54
|
+
export declare function emitDbQuery(event: DbQueryEvent): void;
|
|
55
|
+
/**
|
|
56
|
+
* Render a query event as a single log line (Lucid's `prettyPrint`).
|
|
57
|
+
*
|
|
58
|
+
* The bindings are appended as JSON, NOT interpolated into the SQL: an
|
|
59
|
+
* interpolated line reads like runnable SQL while having none of the escaping
|
|
60
|
+
* that made the real statement safe, and it is exactly the string someone
|
|
61
|
+
* copies into a console later.
|
|
62
|
+
*/
|
|
63
|
+
export declare function prettyPrintQuery(event: DbQueryEvent): string;
|
|
64
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC5B,4DAA4D;IAC5D,GAAG,EAAE,MAAM,CAAC;IACZ,2DAA2D;IAC3D,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IAC7B,0EAA0E;IAC1E,QAAQ,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sEAAsE;IACtE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sEAAsE;IACtE,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,qEAAqE;IACrE,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,sEAAsE;IACtE,KAAK,CAAC,EAAE,KAAK,CAAC;CACd;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;AAI5D;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,IAAI,CAK/D;AAED,yDAAyD;AACzD,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAE7C;AAED,gDAAgD;AAChD,wBAAgB,WAAW,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAQrD;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAY5D"}
|
package/dist/events.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query observability — atlas's equivalent of Lucid's `db:query` event.
|
|
3
|
+
*
|
|
4
|
+
* Agnostic by design: atlas cannot import the framework's emitter (it is a
|
|
5
|
+
* standalone package), so it owns a tiny listener registry instead. An
|
|
6
|
+
* integration package bridges it to whatever emitter the app uses:
|
|
7
|
+
*
|
|
8
|
+
* onDbQuery((event) => emitter.emit('db:query', event))
|
|
9
|
+
*
|
|
10
|
+
* Emission is opt-in. It costs a `performance.now()` pair per query, so it only
|
|
11
|
+
* happens when a connection is configured with `debug: true` or a single query
|
|
12
|
+
* asks via `.debug()` — and even then, only if someone is listening.
|
|
13
|
+
*/
|
|
14
|
+
const listeners = new Set();
|
|
15
|
+
/**
|
|
16
|
+
* Subscribe to every observed query. Returns an unsubscribe function.
|
|
17
|
+
*
|
|
18
|
+
* A listener that throws would otherwise take down the query that triggered it,
|
|
19
|
+
* so throws are swallowed — observability must never change behaviour.
|
|
20
|
+
*/
|
|
21
|
+
export function onDbQuery(listener) {
|
|
22
|
+
listeners.add(listener);
|
|
23
|
+
return () => {
|
|
24
|
+
listeners.delete(listener);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** Remove every listener. Intended for test teardown. */
|
|
28
|
+
export function clearDbQueryListeners() {
|
|
29
|
+
listeners.clear();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Whether anyone is listening. Checked before timing a query so the
|
|
33
|
+
* instrumentation costs nothing when unused.
|
|
34
|
+
*/
|
|
35
|
+
export function hasDbQueryListeners() {
|
|
36
|
+
return listeners.size > 0;
|
|
37
|
+
}
|
|
38
|
+
/** Emit to every listener. Package-internal. */
|
|
39
|
+
export function emitDbQuery(event) {
|
|
40
|
+
for (const listener of listeners) {
|
|
41
|
+
try {
|
|
42
|
+
listener(event);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// A broken listener must not fail the query it is reporting on.
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Render a query event as a single log line (Lucid's `prettyPrint`).
|
|
51
|
+
*
|
|
52
|
+
* The bindings are appended as JSON, NOT interpolated into the SQL: an
|
|
53
|
+
* interpolated line reads like runnable SQL while having none of the escaping
|
|
54
|
+
* that made the real statement safe, and it is exactly the string someone
|
|
55
|
+
* copies into a console later.
|
|
56
|
+
*/
|
|
57
|
+
export function prettyPrintQuery(event) {
|
|
58
|
+
const parts = [`${event.duration.toFixed(2)}ms`];
|
|
59
|
+
if (event.connection)
|
|
60
|
+
parts.push(event.connection);
|
|
61
|
+
if (event.model)
|
|
62
|
+
parts.push(event.model);
|
|
63
|
+
if (event.method)
|
|
64
|
+
parts.push(event.method);
|
|
65
|
+
if (event.inTransaction)
|
|
66
|
+
parts.push("trx");
|
|
67
|
+
if (event.error)
|
|
68
|
+
parts.push(`ERROR: ${event.error.message}`);
|
|
69
|
+
const head = `[atlas] ${parts.join(" ")}`;
|
|
70
|
+
const bindings = event.bindings.length > 0 ? ` -- ${safeJson(event.bindings)}` : "";
|
|
71
|
+
return `${head} ${event.sql}${bindings}`;
|
|
72
|
+
}
|
|
73
|
+
/** JSON that can't throw on a circular / non-serialisable binding. */
|
|
74
|
+
function safeJson(value) {
|
|
75
|
+
try {
|
|
76
|
+
return JSON.stringify(value, (_k, v) => typeof v === "bigint" ? `${v}n` : v);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return "[unserialisable bindings]";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA6BH,MAAM,SAAS,GAAG,IAAI,GAAG,EAAmB,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,QAAyB;IAClD,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACxB,OAAO,GAAG,EAAE;QACX,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC,CAAC;AACH,CAAC;AAED,yDAAyD;AACzD,MAAM,UAAU,qBAAqB;IACpC,SAAS,CAAC,KAAK,EAAE,CAAC;AACnB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB;IAClC,OAAO,SAAS,CAAC,IAAI,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED,gDAAgD;AAChD,MAAM,UAAU,WAAW,CAAC,KAAmB;IAC9C,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QAClC,IAAI,CAAC;YACJ,QAAQ,CAAC,KAAK,CAAC,CAAC;QACjB,CAAC;QAAC,MAAM,CAAC;YACR,gEAAgE;QACjE,CAAC;IACF,CAAC;AACF,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAmB;IACnD,MAAM,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACjD,IAAI,KAAK,CAAC,UAAU;QAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACnD,IAAI,KAAK,CAAC,KAAK;QAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACzC,IAAI,KAAK,CAAC,MAAM;QAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC3C,IAAI,KAAK,CAAC,aAAa;QAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3C,IAAI,KAAK,CAAC,KAAK;QAAE,KAAK,CAAC,IAAI,CAAC,UAAU,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAE7D,MAAM,IAAI,GAAG,WAAW,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IAC1C,MAAM,QAAQ,GACb,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACpE,OAAO,GAAG,IAAI,IAAI,KAAK,CAAC,GAAG,GAAG,QAAQ,EAAE,CAAC;AAC1C,CAAC;AAED,sEAAsE;AACtE,SAAS,QAAQ,CAAC,KAAc;IAC/B,IAAI,CAAC;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CACtC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CACnC,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,2BAA2B,CAAC;IACpC,CAAC;AACF,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,14 +5,16 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import "reflect-metadata";
|
|
7
7
|
export { SQLITE_PROD_PRAGMAS } from "./AtlasProvider.js";
|
|
8
|
-
export type { AsyncDatabaseConnection, ConnectRetryOptions, } from "./adapters/NapiDbAdapter.js";
|
|
8
|
+
export type { AsyncDatabaseConnection, ConnectRetryOptions, ObservabilityOptions, QueryMeta, } from "./adapters/NapiDbAdapter.js";
|
|
9
9
|
export { createNapiConnection } from "./adapters/NapiDbAdapter.js";
|
|
10
10
|
export type { DomainEvent } from "./BaseEntity.js";
|
|
11
11
|
export { BaseEntity } from "./BaseEntity.js";
|
|
12
|
+
export { BaseModel } from "./BaseModel.js";
|
|
12
13
|
export type { DatabaseConnection } from "./BaseRepository.js";
|
|
13
14
|
export { BaseRepository } from "./BaseRepository.js";
|
|
14
15
|
export { defineConfig } from "./config.js";
|
|
15
16
|
export { configure } from "./configure.js";
|
|
17
|
+
export { dbWipeCommand, type MigrationCommandOptions, makeMigrationCommand, migrationRefreshCommand, migrationResetCommand, migrationRollbackCommand, migrationRunCommand, migrationStatusCommand, } from "./console/migrationCommands.js";
|
|
16
18
|
export { type AtlasCommand, schemaCheckCommand, } from "./console/schemaCheckCommand.js";
|
|
17
19
|
export type { ColumnAdapter, ColumnMetadata, ColumnOptions, DateColumnConfig, DateTimeColumnOptions, EntityMetadata, ManyToManyOptions, RelationMetadata, } from "./decorators/entity.js";
|
|
18
20
|
export { BelongsTo, Column, column, computed, Entity, getColumnMetadata, getDateColumnConfig, getEntityMetadata, getPrimaryKey, getRelationMetadata, HasMany, HasManyThrough, HasOne, HasOneThrough, hasSoftDeletes, ManyToMany, PrimaryKey, SoftDeletes, } from "./decorators/entity.js";
|
|
@@ -20,6 +22,8 @@ export { afterCreate, afterDelete, afterFetch, afterFind, afterPaginate, afterSa
|
|
|
20
22
|
export type { ScopeFn } from "./decorators/scope.js";
|
|
21
23
|
export { scope } from "./decorators/scope.js";
|
|
22
24
|
export { AtlasError, EntityNotFoundError, MassAssignmentError, OptimisticLockError, RelationNotLoadedError, } from "./errors.js";
|
|
25
|
+
export type { DbQueryEvent, DbQueryListener } from "./events.js";
|
|
26
|
+
export { clearDbQueryListeners, onDbQuery, prettyPrintQuery, } from "./events.js";
|
|
23
27
|
export { isAtlasStrictMode, ModelQuery, setAtlasStrictMode, } from "./ModelQuery.js";
|
|
24
28
|
export type { NamingStrategy } from "./naming/NamingStrategy.js";
|
|
25
29
|
export { CamelCaseNamingStrategy, defaultNamingStrategy, getNamingStrategy, } from "./naming/NamingStrategy.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,YAAY,EACX,uBAAuB,EACvB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,YAAY,EACX,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,EACpB,SAAS,GACT,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,YAAY,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EACN,aAAa,EACb,KAAK,uBAAuB,EAC5B,oBAAoB,EACpB,uBAAuB,EACvB,qBAAqB,EACrB,wBAAwB,EACxB,mBAAmB,EACnB,sBAAsB,GACtB,MA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_PRAGMAS } from "./AtlasProvider.js";
|
|
8
8
|
export { createNapiConnection } from "./adapters/NapiDbAdapter.js";
|
|
9
9
|
export { BaseEntity } from "./BaseEntity.js";
|
|
10
|
+
export { BaseModel } from "./BaseModel.js";
|
|
10
11
|
export { BaseRepository } from "./BaseRepository.js";
|
|
11
12
|
export { defineConfig } from "./config.js";
|
|
12
13
|
export { configure } from "./configure.js";
|
|
14
|
+
export { dbWipeCommand, makeMigrationCommand, migrationRefreshCommand, migrationResetCommand, migrationRollbackCommand, migrationRunCommand, migrationStatusCommand, } from "./console/migrationCommands.js";
|
|
13
15
|
export { schemaCheckCommand, } from "./console/schemaCheckCommand.js";
|
|
14
16
|
export { BelongsTo, Column, column, computed, Entity, getColumnMetadata, getDateColumnConfig, getEntityMetadata, getPrimaryKey, getRelationMetadata, HasMany, HasManyThrough, HasOne, HasOneThrough, hasSoftDeletes, ManyToMany, PrimaryKey, SoftDeletes, } from "./decorators/entity.js";
|
|
15
17
|
export { afterCreate, afterDelete, afterFetch, afterFind, afterPaginate, afterSave, afterUpdate, beforeCreate, beforeDelete, beforeFetch, beforeFind, beforePaginate, beforeSave, beforeUpdate, } from "./decorators/hooks.js";
|
|
16
18
|
export { scope } from "./decorators/scope.js";
|
|
17
19
|
export { AtlasError, EntityNotFoundError, MassAssignmentError, OptimisticLockError, RelationNotLoadedError, } from "./errors.js";
|
|
20
|
+
export { clearDbQueryListeners, onDbQuery, prettyPrintQuery, } from "./events.js";
|
|
18
21
|
export { isAtlasStrictMode, ModelQuery, setAtlasStrictMode, } from "./ModelQuery.js";
|
|
19
22
|
export { CamelCaseNamingStrategy, defaultNamingStrategy, getNamingStrategy, } from "./naming/NamingStrategy.js";
|
|
20
23
|
export { getAtlasDialect, setAtlasDialect } from "./query/native.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH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C;AAC9C,OAAO,EACN,UAAU,EACV,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,GACtB,MAAM,aAAa,CAAC;AAErB,OAAO,EACN,qBAAqB,EACrB,SAAS,EACT,gBAAgB,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,iBAAiB,EACjB,UAAU,EACV,kBAAkB,GAClB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,uBAAuB,EACvB,qBAAqB,EACrB,iBAAiB,GACjB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AASrE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAEN,eAAe,GACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAOlD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAG9D,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EACN,WAAW,EACX,oBAAoB,EACpB,cAAc,EAGd,aAAa,EACb,eAAe,EACf,YAAY,GACZ,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACN,UAAU,EACV,kBAAkB,EAClB,UAAU,EACV,MAAM,GACN,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/metadata-keys.d.ts
CHANGED
|
@@ -14,7 +14,8 @@ export declare const COLUMN_SERIALIZE_KEY: unique symbol;
|
|
|
14
14
|
export interface ColumnSerializeConfig {
|
|
15
15
|
/** Rename this column at toJSON time (e.g. `password` → `passwordHash`). Null = hidden. */
|
|
16
16
|
serializeAs?: string | null;
|
|
17
|
-
/** Transform function applied to the value at toJSON time.
|
|
18
|
-
|
|
17
|
+
/** Transform function applied to the value at toJSON time. Signature mirrors
|
|
18
|
+
* Adonis Lucid: `(value, attribute, model)`; extra args optional. */
|
|
19
|
+
serialize?: (value: unknown, attribute?: string, model?: unknown) => unknown;
|
|
19
20
|
}
|
|
20
21
|
//# sourceMappingURL=metadata-keys.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata-keys.d.ts","sourceRoot":"","sources":["../src/metadata-keys.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,iFAAiF;AACjF,eAAO,MAAM,YAAY,eAA+B,CAAC;AAEzD,kFAAkF;AAClF,eAAO,MAAM,oBAAoB,eAAsC,CAAC;AAExE,sEAAsE;AACtE,MAAM,WAAW,qBAAqB;IACrC,2FAA2F;IAC3F,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B
|
|
1
|
+
{"version":3,"file":"metadata-keys.d.ts","sourceRoot":"","sources":["../src/metadata-keys.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,iFAAiF;AACjF,eAAO,MAAM,YAAY,eAA+B,CAAC;AAEzD,kFAAkF;AAClF,eAAO,MAAM,oBAAoB,eAAsC,CAAC;AAExE,sEAAsE;AACtE,MAAM,WAAW,qBAAqB;IACrC,2FAA2F;IAC3F,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B;yEACqE;IACrE,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC;CAC7E"}
|
|
@@ -28,6 +28,12 @@ export interface NamingStrategy {
|
|
|
28
28
|
relationForeignKey(kind: "belongsTo" | "hasMany" | "hasOne" | "manyToMany", parentClass: string, parentPk: string): string;
|
|
29
29
|
/** Default pivot table name for a manyToMany relation. */
|
|
30
30
|
relationPivotTable(aClass: string, bClass: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Remap the pagination `meta` key names emitted by `Paginator.toJSON()`
|
|
33
|
+
* (AdonisJS Lucid `paginationMetaKeys`), e.g. `{ total: 'count', perPage:
|
|
34
|
+
* 'per_page' }`. Optional — omitted keys keep their default name.
|
|
35
|
+
*/
|
|
36
|
+
paginationMetaKeys?(): Record<string, string>;
|
|
31
37
|
}
|
|
32
38
|
/**
|
|
33
39
|
* Default strategy — camelCase TS properties, snake_case DB columns, plural
|
|
@@ -41,6 +47,7 @@ export declare class CamelCaseNamingStrategy implements NamingStrategy {
|
|
|
41
47
|
relationLocalKey(_kind: "belongsTo" | "hasMany" | "hasOne" | "manyToMany", parentPk: string): string;
|
|
42
48
|
relationForeignKey(_kind: "belongsTo" | "hasMany" | "hasOne" | "manyToMany", parentClass: string, parentPk: string): string;
|
|
43
49
|
relationPivotTable(aClass: string, bClass: string): string;
|
|
50
|
+
paginationMetaKeys(): Record<string, string>;
|
|
44
51
|
}
|
|
45
52
|
/** The default singleton — used when an entity doesn't override `static namingStrategy`. */
|
|
46
53
|
export declare const defaultNamingStrategy: NamingStrategy;
|
|
@@ -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,IAA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AAM,CAAC,CAAC;CAC9C;AAED;;;GAGG;AACH,qBAAa,uBAAwB,YAAW,cAAc;IAC7D,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAOpC,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IAIxC,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAIxC,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IAI5C,gBAAgB,CACf,KAAK,EAAE,WAAW,GAAG,SAAS,GAAG,QAAQ,GAAG,YAAY,EACxD,QAAQ,EAAE,MAAM,GACd,MAAM;IAIT,kBAAkB,CACjB,KAAK,EAAE,WAAW,GAAG,SAAS,GAAG,QAAQ,GAAG,YAAY,EACxD,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,GACd,MAAM;IAIT,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAM1D,kBAAkB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CAgB5C;AAED,4FAA4F;AAC5F,eAAO,MAAM,qBAAqB,EAAE,cACN,CAAC;AAE/B;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,cAAc,CASrE"}
|
|
@@ -44,6 +44,22 @@ export class CamelCaseNamingStrategy {
|
|
|
44
44
|
const [x, y] = [camelToSnake(aClass), camelToSnake(bClass)].sort();
|
|
45
45
|
return `${x}_${y}`;
|
|
46
46
|
}
|
|
47
|
+
paginationMetaKeys() {
|
|
48
|
+
// snake_case, matching Adonis Lucid's default paginator meta shape — even
|
|
49
|
+
// though model attributes serialize as camelCase, Lucid emits pagination
|
|
50
|
+
// meta in snake_case. Override this method to customize.
|
|
51
|
+
return {
|
|
52
|
+
total: "total",
|
|
53
|
+
perPage: "per_page",
|
|
54
|
+
currentPage: "current_page",
|
|
55
|
+
lastPage: "last_page",
|
|
56
|
+
firstPage: "first_page",
|
|
57
|
+
firstPageUrl: "first_page_url",
|
|
58
|
+
lastPageUrl: "last_page_url",
|
|
59
|
+
nextPageUrl: "next_page_url",
|
|
60
|
+
previousPageUrl: "previous_page_url",
|
|
61
|
+
};
|
|
62
|
+
}
|
|
47
63
|
}
|
|
48
64
|
/** The default singleton — used when an entity doesn't override `static namingStrategy`. */
|
|
49
65
|
export const defaultNamingStrategy = new CamelCaseNamingStrategy();
|
|
@@ -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;AAiChE;;;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,CAAC;IAClD,CAAC;IAED,UAAU,CAAC,YAAoB;QAC9B,OAAO,YAAY,CAAC,YAAY,CAAC,CAAC;IACnC,CAAC;IAED,YAAY,CAAC,UAAkB;QAC9B,OAAO,YAAY,CAAC,UAAU,CAAC,CAAC;IACjC,CAAC;IAED,cAAc,CAAC,YAAoB;QAClC,OAAO,YAAY,CAAC;IACrB,CAAC;IAED,gBAAgB,CACf,KAAwD,EACxD,QAAgB;QAEhB,OAAO,QAAQ,CAAC;IACjB,CAAC;IAED,kBAAkB,CACjB,KAAwD,E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query/QueryBuilder.js";
|
|
8
|
+
import type { CatalogConnection } from "./catalog.js";
|
|
8
9
|
import { Schema } from "./SchemaBuilder.js";
|
|
9
10
|
/**
|
|
10
11
|
* Base class for all migrations.
|
|
@@ -27,10 +28,28 @@ import { Schema } from "./SchemaBuilder.js";
|
|
|
27
28
|
* }
|
|
28
29
|
* }
|
|
29
30
|
*/
|
|
31
|
+
/**
|
|
32
|
+
* A deferred operation registered with `this.defer()`. Runs after the
|
|
33
|
+
* migration's schema statements, with a live connection handle (execute/query).
|
|
34
|
+
*/
|
|
35
|
+
export type DeferredMigrationCallback = (db: CatalogConnection) => Promise<void> | void;
|
|
30
36
|
export declare abstract class Migration {
|
|
31
37
|
#private;
|
|
32
38
|
readonly schema: Schema;
|
|
33
39
|
constructor(dialect?: AtlasDialect);
|
|
40
|
+
/**
|
|
41
|
+
* Register a callback to run AFTER this migration's schema statements execute
|
|
42
|
+
* (Adonis Lucid `this.defer`). Typically used to seed data into a table the
|
|
43
|
+
* same migration just created. The callback gets a live connection handle.
|
|
44
|
+
*
|
|
45
|
+
* Note: deferred callbacks run after the schema statements have committed, so
|
|
46
|
+
* they are outside the schema transaction (atlas builds schema as a batch);
|
|
47
|
+
* the migration is only recorded as applied once every deferred callback
|
|
48
|
+
* succeeds. Make deferred work idempotent.
|
|
49
|
+
*/
|
|
50
|
+
defer(callback: DeferredMigrationCallback): void;
|
|
51
|
+
/** @internal Return and clear the deferred callbacks — called by the runner. */
|
|
52
|
+
consumeDeferred(): DeferredMigrationCallback[];
|
|
34
53
|
/** Apply the migration. */
|
|
35
54
|
abstract up(): Promise<void> | void;
|
|
36
55
|
/** Rollback the migration. */
|
|
@@ -49,8 +68,12 @@ export declare abstract class Migration {
|
|
|
49
68
|
* default would blow up at DDL compile time.
|
|
50
69
|
*/
|
|
51
70
|
now(): RawSql;
|
|
52
|
-
/**
|
|
53
|
-
|
|
54
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Get the SQL statements generated by this migration. A `connection` (passed
|
|
73
|
+
* by the runner) is bound to the schema so `this.schema.hasTable()` /
|
|
74
|
+
* `hasColumn()` can query the live catalog from inside `up`/`down`.
|
|
75
|
+
*/
|
|
76
|
+
getUpSQL(connection?: CatalogConnection): Promise<string[]>;
|
|
77
|
+
getDownSQL(connection?: CatalogConnection): Promise<string[]>;
|
|
55
78
|
}
|
|
56
79
|
//# sourceMappingURL=Migration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Migration.d.ts","sourceRoot":"","sources":["../../src/schema/Migration.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,8BAAsB,SAAS;;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"Migration.d.ts","sourceRoot":"","sources":["../../src/schema/Migration.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH;;;GAGG;AACH,MAAM,MAAM,yBAAyB,GAAG,CACvC,EAAE,EAAE,iBAAiB,KACjB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAE1B,8BAAsB,SAAS;;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAIZ,OAAO,CAAC,EAAE,YAAY;IAQlC;;;;;;;;;OASG;IACH,KAAK,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI;IAIhD,gFAAgF;IAChF,eAAe,IAAI,yBAAyB,EAAE;IAM9C,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAEnC,8BAA8B;IAC9B,QAAQ,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAErC,sFAAsF;IACtF,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAI/B;;;;;;;;;;OAUG;IACH,GAAG,IAAI,MAAM;IAMb;;;;OAIG;IACG,QAAQ,CAAC,UAAU,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAQ3D,UAAU,CAAC,UAAU,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAOnE"}
|
package/dist/schema/Migration.js
CHANGED
|
@@ -5,30 +5,10 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { RawSql } from "../query/QueryBuilder.js";
|
|
7
7
|
import { Schema } from "./SchemaBuilder.js";
|
|
8
|
-
/**
|
|
9
|
-
* Base class for all migrations.
|
|
10
|
-
*
|
|
11
|
-
* Usage:
|
|
12
|
-
* import { Migration } from '@c9up/atlas'
|
|
13
|
-
*
|
|
14
|
-
* export default class CreateOrders extends Migration {
|
|
15
|
-
* async up() {
|
|
16
|
-
* this.schema.createTable('orders', (table) => {
|
|
17
|
-
* table.id()
|
|
18
|
-
* table.string('status', 50).notNullable().defaultTo("'pending'")
|
|
19
|
-
* table.decimal('total', 10, 2).notNullable()
|
|
20
|
-
* table.timestamps()
|
|
21
|
-
* })
|
|
22
|
-
* }
|
|
23
|
-
*
|
|
24
|
-
* async down() {
|
|
25
|
-
* this.schema.dropTable('orders')
|
|
26
|
-
* }
|
|
27
|
-
* }
|
|
28
|
-
*/
|
|
29
8
|
export class Migration {
|
|
30
9
|
schema;
|
|
31
10
|
#dialect;
|
|
11
|
+
#deferred = [];
|
|
32
12
|
constructor(dialect) {
|
|
33
13
|
this.schema = new Schema(dialect);
|
|
34
14
|
// Default to sqlite when no dialect is passed — the generator emits
|
|
@@ -36,6 +16,25 @@ export class Migration {
|
|
|
36
16
|
// on postgres/mysql too, so this is the safest conservative default.
|
|
37
17
|
this.#dialect = dialect ?? "sqlite";
|
|
38
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Register a callback to run AFTER this migration's schema statements execute
|
|
21
|
+
* (Adonis Lucid `this.defer`). Typically used to seed data into a table the
|
|
22
|
+
* same migration just created. The callback gets a live connection handle.
|
|
23
|
+
*
|
|
24
|
+
* Note: deferred callbacks run after the schema statements have committed, so
|
|
25
|
+
* they are outside the schema transaction (atlas builds schema as a batch);
|
|
26
|
+
* the migration is only recorded as applied once every deferred callback
|
|
27
|
+
* succeeds. Make deferred work idempotent.
|
|
28
|
+
*/
|
|
29
|
+
defer(callback) {
|
|
30
|
+
this.#deferred.push(callback);
|
|
31
|
+
}
|
|
32
|
+
/** @internal Return and clear the deferred callbacks — called by the runner. */
|
|
33
|
+
consumeDeferred() {
|
|
34
|
+
const deferred = this.#deferred;
|
|
35
|
+
this.#deferred = [];
|
|
36
|
+
return deferred;
|
|
37
|
+
}
|
|
39
38
|
/** Helper: raw SQL expression for a column DEFAULT — emitted verbatim, not quoted. */
|
|
40
39
|
raw(expression) {
|
|
41
40
|
return new RawSql(expression);
|
|
@@ -54,14 +53,24 @@ export class Migration {
|
|
|
54
53
|
now() {
|
|
55
54
|
return new RawSql(this.#dialect === "sqlite" ? "CURRENT_TIMESTAMP" : "NOW()");
|
|
56
55
|
}
|
|
57
|
-
/**
|
|
58
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Get the SQL statements generated by this migration. A `connection` (passed
|
|
58
|
+
* by the runner) is bound to the schema so `this.schema.hasTable()` /
|
|
59
|
+
* `hasColumn()` can query the live catalog from inside `up`/`down`.
|
|
60
|
+
*/
|
|
61
|
+
async getUpSQL(connection) {
|
|
62
|
+
if (connection)
|
|
63
|
+
this.schema.bindConnection(connection);
|
|
59
64
|
this.schema.reset();
|
|
65
|
+
this.#deferred = [];
|
|
60
66
|
await this.up();
|
|
61
67
|
return this.schema.toSQL();
|
|
62
68
|
}
|
|
63
|
-
async getDownSQL() {
|
|
69
|
+
async getDownSQL(connection) {
|
|
70
|
+
if (connection)
|
|
71
|
+
this.schema.bindConnection(connection);
|
|
64
72
|
this.schema.reset();
|
|
73
|
+
this.#deferred = [];
|
|
65
74
|
await this.down();
|
|
66
75
|
return this.schema.toSQL();
|
|
67
76
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Migration.js","sourceRoot":"","sources":["../../src/schema/Migration.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"Migration.js","sourceRoot":"","sources":["../../src/schema/Migration.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AA+B5C,MAAM,OAAgB,SAAS;IACrB,MAAM,CAAS;IACf,QAAQ,CAAe;IAChC,SAAS,GAAgC,EAAE,CAAC;IAE5C,YAAY,OAAsB;QACjC,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;QAClC,oEAAoE;QACpE,uEAAuE;QACvE,qEAAqE;QACrE,IAAI,CAAC,QAAQ,GAAG,OAAO,IAAI,QAAQ,CAAC;IACrC,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,QAAmC;QACxC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAED,gFAAgF;IAChF,eAAe;QACd,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI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