@strapi/database 5.0.0-beta.10 → 5.0.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +45 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -2
- package/dist/index.mjs.map +1 -1
- package/dist/migrations/internal.d.ts.map +1 -1
- package/dist/migrations/logger.d.ts +10 -0
- package/dist/migrations/logger.d.ts.map +1 -0
- package/dist/migrations/users.d.ts.map +1 -1
- package/package.json +7 -6
package/dist/index.d.ts
CHANGED
|
@@ -19,9 +19,11 @@ interface Settings {
|
|
|
19
19
|
};
|
|
20
20
|
[key: string]: unknown;
|
|
21
21
|
}
|
|
22
|
+
export type Logger = Record<'info' | 'warn' | 'error' | 'debug', (message: string | Record<string, unknown>) => void>;
|
|
22
23
|
export interface DatabaseConfig {
|
|
23
24
|
connection: Knex.Config;
|
|
24
25
|
settings: Settings;
|
|
26
|
+
logger?: Logger;
|
|
25
27
|
}
|
|
26
28
|
declare class Database {
|
|
27
29
|
connection: Knex;
|
|
@@ -32,6 +34,7 @@ declare class Database {
|
|
|
32
34
|
migrations: MigrationProvider;
|
|
33
35
|
lifecycles: LifecycleProvider;
|
|
34
36
|
entityManager: EntityManager;
|
|
37
|
+
logger: Logger;
|
|
35
38
|
constructor(config: DatabaseConfig);
|
|
36
39
|
init({ models }: {
|
|
37
40
|
models: Model[];
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAEjC,OAAO,EAAE,OAAO,EAAc,MAAM,YAAY,CAAC;AACjD,OAAO,EAAwB,cAAc,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EAAkB,QAAQ,EAAE,M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QAAE,MAAM,EAAE,KAAK,EAAE,CAAA;KAAE;IAM1C,KAAK,CAAC,GAAG,EAAE,MAAM;IAQjB,aAAa;IAIb,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;IACzC,WAAW,CAAC,SAAS,SAAS,QAAQ,EAAE,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IA4CrF,aAAa,IAAI,MAAM,GAAG,SAAS;IAInC,aAAa,IAAI,IAAI;IACrB,aAAa,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,YAAY;IAOpD,mBAAmB,CAAC,GAAG,mBAAkB;IAKzC,YAAY,CAAC,GAAG,EAAE,MAAM;IAIlB,OAAO;CAId;AAED,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC5B,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5909,6 +5909,21 @@ const createStorage = (opts) => {
|
|
|
5909
5909
|
const wrapTransaction = (db) => (fn) => () => {
|
|
5910
5910
|
return db.transaction(({ trx }) => Promise.resolve(fn(trx, db)));
|
|
5911
5911
|
};
|
|
5912
|
+
const transformLogMessage = (level, message) => {
|
|
5913
|
+
if (typeof message === "string") {
|
|
5914
|
+
return { level, message };
|
|
5915
|
+
}
|
|
5916
|
+
if (typeof message === "object" && message !== null) {
|
|
5917
|
+
if ("event" in message && "name" in message) {
|
|
5918
|
+
return {
|
|
5919
|
+
level,
|
|
5920
|
+
message: `[internal migration]: ${message.event} ${message?.name}`,
|
|
5921
|
+
timestamp: Date.now()
|
|
5922
|
+
};
|
|
5923
|
+
}
|
|
5924
|
+
}
|
|
5925
|
+
return "";
|
|
5926
|
+
};
|
|
5912
5927
|
const migrationResolver = ({ name, path: path2, context }) => {
|
|
5913
5928
|
const { db } = context;
|
|
5914
5929
|
if (!path2) {
|
|
@@ -5937,7 +5952,20 @@ const createUserMigrationProvider = (db) => {
|
|
|
5937
5952
|
const context = { db };
|
|
5938
5953
|
const umzugProvider = new umzug.Umzug({
|
|
5939
5954
|
storage: createStorage({ db, tableName: "strapi_migrations" }),
|
|
5940
|
-
logger:
|
|
5955
|
+
logger: {
|
|
5956
|
+
info(message) {
|
|
5957
|
+
db.logger.info(transformLogMessage("info", message));
|
|
5958
|
+
},
|
|
5959
|
+
warn(message) {
|
|
5960
|
+
db.logger.warn(transformLogMessage("warn", message));
|
|
5961
|
+
},
|
|
5962
|
+
error(message) {
|
|
5963
|
+
db.logger.error(transformLogMessage("error", message));
|
|
5964
|
+
},
|
|
5965
|
+
debug(message) {
|
|
5966
|
+
db.logger.debug(transformLogMessage("debug", message));
|
|
5967
|
+
}
|
|
5968
|
+
},
|
|
5941
5969
|
context,
|
|
5942
5970
|
migrations: {
|
|
5943
5971
|
glob: ["*.{js,sql}", { cwd: dir }],
|
|
@@ -6262,7 +6290,20 @@ const createInternalMigrationProvider = (db) => {
|
|
|
6262
6290
|
const migrations = [...internalMigrations];
|
|
6263
6291
|
const umzugProvider = new umzug.Umzug({
|
|
6264
6292
|
storage: createStorage({ db, tableName: "strapi_migrations_internal" }),
|
|
6265
|
-
logger:
|
|
6293
|
+
logger: {
|
|
6294
|
+
info(message) {
|
|
6295
|
+
db.logger.debug(transformLogMessage("info", message));
|
|
6296
|
+
},
|
|
6297
|
+
warn(message) {
|
|
6298
|
+
db.logger.warn(transformLogMessage("warn", message));
|
|
6299
|
+
},
|
|
6300
|
+
error(message) {
|
|
6301
|
+
db.logger.error(transformLogMessage("error", message));
|
|
6302
|
+
},
|
|
6303
|
+
debug(message) {
|
|
6304
|
+
db.logger.debug(transformLogMessage("debug", message));
|
|
6305
|
+
}
|
|
6306
|
+
},
|
|
6266
6307
|
context,
|
|
6267
6308
|
migrations: () => migrations.map((migration) => {
|
|
6268
6309
|
return {
|
|
@@ -6533,6 +6574,7 @@ class Database {
|
|
|
6533
6574
|
migrations;
|
|
6534
6575
|
lifecycles;
|
|
6535
6576
|
entityManager;
|
|
6577
|
+
logger;
|
|
6536
6578
|
constructor(config) {
|
|
6537
6579
|
this.config = {
|
|
6538
6580
|
...config,
|
|
@@ -6552,6 +6594,7 @@ class Database {
|
|
|
6552
6594
|
this.migrations = createMigrationsProvider(this);
|
|
6553
6595
|
this.lifecycles = createLifecyclesProvider(this);
|
|
6554
6596
|
this.entityManager = createEntityManager(this);
|
|
6597
|
+
this.logger = config.logger ?? console;
|
|
6555
6598
|
}
|
|
6556
6599
|
async init({ models }) {
|
|
6557
6600
|
this.metadata.loadModels(models);
|