@strapi/database 5.58.0 → 5.60.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/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +15 -2
- package/dist/connection.js.map +1 -1
- package/dist/connection.mjs +15 -2
- package/dist/connection.mjs.map +1 -1
- package/dist/dialects/sqlite/index.js +3 -3
- package/dist/dialects/sqlite/index.js.map +1 -1
- package/dist/dialects/sqlite/index.mjs +3 -3
- package/dist/dialects/sqlite/index.mjs.map +1 -1
- package/dist/entity-manager/index.d.ts.map +1 -1
- package/dist/entity-manager/index.js +94 -0
- package/dist/entity-manager/index.js.map +1 -1
- package/dist/entity-manager/index.mjs +95 -1
- package/dist/entity-manager/index.mjs.map +1 -1
- package/dist/entity-manager/regular-relations.d.ts.map +1 -1
- package/dist/entity-manager/regular-relations.js +7 -2
- package/dist/entity-manager/regular-relations.js.map +1 -1
- package/dist/entity-manager/regular-relations.mjs +9 -4
- package/dist/entity-manager/regular-relations.mjs.map +1 -1
- package/dist/entity-manager/types.d.ts +3 -0
- package/dist/entity-manager/types.d.ts.map +1 -1
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +65 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -3
- package/dist/index.mjs.map +1 -1
- package/dist/lifecycles/index.d.ts +1 -0
- package/dist/lifecycles/index.d.ts.map +1 -1
- package/dist/lifecycles/index.js +29 -1
- package/dist/lifecycles/index.js.map +1 -1
- package/dist/lifecycles/index.mjs +29 -1
- package/dist/lifecycles/index.mjs.map +1 -1
- package/dist/lifecycles/subscribers/timestamps.js +2 -2
- package/dist/lifecycles/subscribers/timestamps.js.map +1 -1
- package/dist/lifecycles/subscribers/timestamps.mjs +2 -2
- package/dist/lifecycles/subscribers/timestamps.mjs.map +1 -1
- package/dist/migrations/internal.d.ts.map +1 -1
- package/dist/migrations/internal.js +1 -0
- package/dist/migrations/internal.js.map +1 -1
- package/dist/migrations/internal.mjs +1 -0
- package/dist/migrations/internal.mjs.map +1 -1
- package/dist/migrations/runner.d.ts +2 -0
- package/dist/migrations/runner.d.ts.map +1 -1
- package/dist/migrations/runner.js +7 -2
- package/dist/migrations/runner.js.map +1 -1
- package/dist/migrations/runner.mjs +7 -2
- package/dist/migrations/runner.mjs.map +1 -1
- package/dist/migrations/users.d.ts.map +1 -1
- package/dist/migrations/users.js +1 -0
- package/dist/migrations/users.js.map +1 -1
- package/dist/migrations/users.mjs +1 -0
- package/dist/migrations/users.mjs.map +1 -1
- package/dist/pool-diagnostics/details.d.ts +58 -0
- package/dist/pool-diagnostics/details.d.ts.map +1 -0
- package/dist/pool-diagnostics/details.js +42 -0
- package/dist/pool-diagnostics/details.js.map +1 -0
- package/dist/pool-diagnostics/details.mjs +38 -0
- package/dist/pool-diagnostics/details.mjs.map +1 -0
- package/dist/pool-diagnostics/event-loop.d.ts +31 -0
- package/dist/pool-diagnostics/event-loop.d.ts.map +1 -0
- package/dist/pool-diagnostics/event-loop.js +59 -0
- package/dist/pool-diagnostics/event-loop.js.map +1 -0
- package/dist/pool-diagnostics/event-loop.mjs +54 -0
- package/dist/pool-diagnostics/event-loop.mjs.map +1 -0
- package/dist/pool-diagnostics/format.d.ts +9 -0
- package/dist/pool-diagnostics/format.d.ts.map +1 -0
- package/dist/pool-diagnostics/format.js +46 -0
- package/dist/pool-diagnostics/format.js.map +1 -0
- package/dist/pool-diagnostics/format.mjs +42 -0
- package/dist/pool-diagnostics/format.mjs.map +1 -0
- package/dist/pool-diagnostics/index.d.ts +33 -0
- package/dist/pool-diagnostics/index.d.ts.map +1 -0
- package/dist/pool-diagnostics/index.js +117 -0
- package/dist/pool-diagnostics/index.js.map +1 -0
- package/dist/pool-diagnostics/index.mjs +109 -0
- package/dist/pool-diagnostics/index.mjs.map +1 -0
- package/dist/pool-diagnostics/stack.d.ts +12 -0
- package/dist/pool-diagnostics/stack.d.ts.map +1 -0
- package/dist/pool-diagnostics/stack.js +46 -0
- package/dist/pool-diagnostics/stack.js.map +1 -0
- package/dist/pool-diagnostics/stack.mjs +44 -0
- package/dist/pool-diagnostics/stack.mjs.map +1 -0
- package/dist/query/helpers/populate/apply.d.ts.map +1 -1
- package/dist/query/helpers/populate/apply.js +21 -3
- package/dist/query/helpers/populate/apply.js.map +1 -1
- package/dist/query/helpers/populate/apply.mjs +21 -3
- package/dist/query/helpers/populate/apply.mjs.map +1 -1
- package/dist/query/helpers/streams/readable.d.ts +1 -1
- package/dist/query/helpers/streams/readable.d.ts.map +1 -1
- package/dist/query/helpers/streams/readable.js +2 -2
- package/dist/query/helpers/streams/readable.js.map +1 -1
- package/dist/query/helpers/streams/readable.mjs +1 -1
- package/dist/query/helpers/streams/readable.mjs.map +1 -1
- package/dist/schema/diff.d.ts.map +1 -1
- package/dist/schema/diff.js +3 -3
- package/dist/schema/diff.js.map +1 -1
- package/dist/schema/diff.mjs +3 -3
- package/dist/schema/diff.mjs.map +1 -1
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +20 -18
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/index.mjs +20 -18
- package/dist/schema/index.mjs.map +1 -1
- package/dist/utils/knex-log.d.ts +19 -0
- package/dist/utils/knex-log.d.ts.map +1 -0
- package/dist/utils/knex-log.js +51 -0
- package/dist/utils/knex-log.js.map +1 -0
- package/dist/utils/knex-log.mjs +47 -0
- package/dist/utils/knex-log.mjs.map +1 -0
- package/dist/utils/throttle.d.ts +26 -0
- package/dist/utils/throttle.d.ts.map +1 -0
- package/dist/utils/throttle.js +34 -0
- package/dist/utils/throttle.js.map +1 -0
- package/dist/utils/throttle.mjs +32 -0
- package/dist/utils/throttle.mjs.map +1 -0
- package/dist/utils/types.d.ts.map +1 -1
- package/dist/utils/types.js +9 -9
- package/dist/utils/types.js.map +1 -1
- package/dist/utils/types.mjs +9 -9
- package/dist/utils/types.mjs.map +1 -1
- package/package.json +7 -7
|
@@ -14,6 +14,7 @@ const wrapMigrationError = (name, direction, cause)=>{
|
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
16
|
const createMigrationRunner = (opts)=>{
|
|
17
|
+
const withPhase = opts.withPhase ?? ((_phase, fn)=>fn());
|
|
17
18
|
const getPendingMigrations = async ()=>{
|
|
18
19
|
const [migrations, executedNames] = await Promise.all([
|
|
19
20
|
opts.getMigrations(),
|
|
@@ -44,7 +45,9 @@ const createMigrationRunner = (opts)=>{
|
|
|
44
45
|
const start = Date.now();
|
|
45
46
|
logEvent(opts.logger, 'migrating', migration.name);
|
|
46
47
|
try {
|
|
47
|
-
await migration.
|
|
48
|
+
await withPhase(`migration ${migration.name}`, async ()=>{
|
|
49
|
+
await migration.up();
|
|
50
|
+
});
|
|
48
51
|
} catch (error) {
|
|
49
52
|
throw wrapMigrationError(migration.name, 'up', error);
|
|
50
53
|
}
|
|
@@ -68,7 +71,9 @@ const createMigrationRunner = (opts)=>{
|
|
|
68
71
|
const start = Date.now();
|
|
69
72
|
logEvent(opts.logger, 'reverting', migration.name);
|
|
70
73
|
try {
|
|
71
|
-
await migration.
|
|
74
|
+
await withPhase(`migration ${migration.name}`, async ()=>{
|
|
75
|
+
await migration.down();
|
|
76
|
+
});
|
|
72
77
|
} catch (error) {
|
|
73
78
|
throw wrapMigrationError(migration.name, 'down', error);
|
|
74
79
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sources":["../../src/migrations/runner.ts"],"sourcesContent":["import type { MigrationRunnerFn } from './common';\nimport type { createStorage } from './storage';\n\nexport interface MigrationMeta {\n name: string;\n path?: string;\n}\n\nexport interface RunnableMigration extends MigrationMeta {\n up: MigrationRunnerFn;\n down: MigrationRunnerFn;\n}\n\nexport interface MigrationRunnerLogger {\n info(message: unknown): void;\n}\n\nexport interface MigrationRunnerOptions {\n storage: ReturnType<typeof createStorage>;\n logger: MigrationRunnerLogger;\n getMigrations: () => Promise<RunnableMigration[]>;\n}\n\nconst logEvent = (\n logger: MigrationRunnerLogger,\n event: string,\n name: string,\n extra?: Record<string, unknown>\n) => {\n logger.info({ event, name, ...extra });\n};\n\nconst wrapMigrationError = (name: string, direction: 'up' | 'down', cause: unknown): Error => {\n const causeMessage =\n cause instanceof Error\n ? `Original error: ${cause.message}`\n : `Non-error value thrown. See cause for full value: ${String(cause)}`;\n\n return new Error(`Migration ${name} (${direction}) failed: ${causeMessage}`, { cause });\n};\n\nexport const createMigrationRunner = (opts: MigrationRunnerOptions) => {\n const getPendingMigrations = async (): Promise<RunnableMigration[]> => {\n const [migrations, executedNames] = await Promise.all([\n opts.getMigrations(),\n opts.storage.executed(),\n ]);\n\n const executedSet = new Set(executedNames);\n return migrations.filter((migration) => !executedSet.has(migration.name));\n };\n\n const getExecutedMigrations = async (): Promise<RunnableMigration[]> => {\n const [migrations, executedNames] = await Promise.all([\n opts.getMigrations(),\n opts.storage.executed(),\n ]);\n\n const executedSet = new Set(executedNames);\n return migrations.filter((migration) => executedSet.has(migration.name));\n };\n\n return {\n async pending(): Promise<MigrationMeta[]> {\n const pending = await getPendingMigrations();\n return pending.map(({ name, path }) => ({ name, path }));\n },\n\n async up(): Promise<MigrationMeta[]> {\n const toBeApplied = await getPendingMigrations();\n\n for (const migration of toBeApplied) {\n const start = Date.now();\n\n logEvent(opts.logger, 'migrating', migration.name);\n\n try {\n await migration.up();\n } catch (error) {\n throw wrapMigrationError(migration.name, 'up', error);\n }\n\n await opts.storage.logMigration({ name: migration.name });\n\n const durationSeconds = (Date.now() - start) / 1000;\n logEvent(opts.logger, 'migrated', migration.name, { durationSeconds });\n }\n\n return toBeApplied.map(({ name, path }) => ({ name, path }));\n },\n\n async down(): Promise<MigrationMeta[]> {\n const executedReversed = (await getExecutedMigrations()).slice().reverse();\n const toBeReverted = executedReversed.slice(0, 1);\n\n for (const migration of toBeReverted) {\n const start = Date.now();\n\n logEvent(opts.logger, 'reverting', migration.name);\n\n try {\n await migration.down();\n } catch (error) {\n throw wrapMigrationError(migration.name, 'down', error);\n }\n\n await opts.storage.unlogMigration({ name: migration.name });\n\n const durationSeconds = Number.parseFloat(((Date.now() - start) / 1000).toFixed(3));\n logEvent(opts.logger, 'reverted', migration.name, { durationSeconds });\n }\n\n return toBeReverted.map(({ name, path }) => ({ name, path }));\n },\n };\n};\n"],"names":["logEvent","logger","event","name","extra","info","wrapMigrationError","direction","cause","causeMessage","Error","message","String","createMigrationRunner","opts","getPendingMigrations","migrations","executedNames","Promise","all","getMigrations","storage","executed","executedSet","Set","filter","migration","has","getExecutedMigrations","pending","map","path","up","toBeApplied","start","Date","now","error","logMigration","durationSeconds","down","executedReversed","slice","reverse","toBeReverted","unlogMigration","Number","parseFloat","toFixed"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"runner.js","sources":["../../src/migrations/runner.ts"],"sourcesContent":["import type { MigrationRunnerFn } from './common';\nimport type { createStorage } from './storage';\n\nexport interface MigrationMeta {\n name: string;\n path?: string;\n}\n\nexport interface RunnableMigration extends MigrationMeta {\n up: MigrationRunnerFn;\n down: MigrationRunnerFn;\n}\n\nexport interface MigrationRunnerLogger {\n info(message: unknown): void;\n}\n\nexport interface MigrationRunnerOptions {\n storage: ReturnType<typeof createStorage>;\n logger: MigrationRunnerLogger;\n getMigrations: () => Promise<RunnableMigration[]>;\n /** Labels pool timeout reports with the running migration's name. */\n withPhase?: <T>(phase: string, fn: () => Promise<T>) => Promise<T>;\n}\n\nconst logEvent = (\n logger: MigrationRunnerLogger,\n event: string,\n name: string,\n extra?: Record<string, unknown>\n) => {\n logger.info({ event, name, ...extra });\n};\n\nconst wrapMigrationError = (name: string, direction: 'up' | 'down', cause: unknown): Error => {\n const causeMessage =\n cause instanceof Error\n ? `Original error: ${cause.message}`\n : `Non-error value thrown. See cause for full value: ${String(cause)}`;\n\n return new Error(`Migration ${name} (${direction}) failed: ${causeMessage}`, { cause });\n};\n\nexport const createMigrationRunner = (opts: MigrationRunnerOptions) => {\n const withPhase =\n opts.withPhase ?? (<T>(_phase: string, fn: () => Promise<T>): Promise<T> => fn());\n\n const getPendingMigrations = async (): Promise<RunnableMigration[]> => {\n const [migrations, executedNames] = await Promise.all([\n opts.getMigrations(),\n opts.storage.executed(),\n ]);\n\n const executedSet = new Set(executedNames);\n return migrations.filter((migration) => !executedSet.has(migration.name));\n };\n\n const getExecutedMigrations = async (): Promise<RunnableMigration[]> => {\n const [migrations, executedNames] = await Promise.all([\n opts.getMigrations(),\n opts.storage.executed(),\n ]);\n\n const executedSet = new Set(executedNames);\n return migrations.filter((migration) => executedSet.has(migration.name));\n };\n\n return {\n async pending(): Promise<MigrationMeta[]> {\n const pending = await getPendingMigrations();\n return pending.map(({ name, path }) => ({ name, path }));\n },\n\n async up(): Promise<MigrationMeta[]> {\n const toBeApplied = await getPendingMigrations();\n\n for (const migration of toBeApplied) {\n const start = Date.now();\n\n logEvent(opts.logger, 'migrating', migration.name);\n\n try {\n await withPhase(`migration ${migration.name}`, async () => {\n await migration.up();\n });\n } catch (error) {\n throw wrapMigrationError(migration.name, 'up', error);\n }\n\n await opts.storage.logMigration({ name: migration.name });\n\n const durationSeconds = (Date.now() - start) / 1000;\n logEvent(opts.logger, 'migrated', migration.name, { durationSeconds });\n }\n\n return toBeApplied.map(({ name, path }) => ({ name, path }));\n },\n\n async down(): Promise<MigrationMeta[]> {\n const executedReversed = (await getExecutedMigrations()).slice().reverse();\n const toBeReverted = executedReversed.slice(0, 1);\n\n for (const migration of toBeReverted) {\n const start = Date.now();\n\n logEvent(opts.logger, 'reverting', migration.name);\n\n try {\n await withPhase(`migration ${migration.name}`, async () => {\n await migration.down();\n });\n } catch (error) {\n throw wrapMigrationError(migration.name, 'down', error);\n }\n\n await opts.storage.unlogMigration({ name: migration.name });\n\n const durationSeconds = Number.parseFloat(((Date.now() - start) / 1000).toFixed(3));\n logEvent(opts.logger, 'reverted', migration.name, { durationSeconds });\n }\n\n return toBeReverted.map(({ name, path }) => ({ name, path }));\n },\n };\n};\n"],"names":["logEvent","logger","event","name","extra","info","wrapMigrationError","direction","cause","causeMessage","Error","message","String","createMigrationRunner","opts","withPhase","_phase","fn","getPendingMigrations","migrations","executedNames","Promise","all","getMigrations","storage","executed","executedSet","Set","filter","migration","has","getExecutedMigrations","pending","map","path","up","toBeApplied","start","Date","now","error","logMigration","durationSeconds","down","executedReversed","slice","reverse","toBeReverted","unlogMigration","Number","parseFloat","toFixed"],"mappings":";;AAyBA,MAAMA,QAAAA,GAAW,CACfC,MAAAA,EACAC,KAAAA,EACAC,IAAAA,EACAC,KAAAA,GAAAA;AAEAH,IAAAA,MAAAA,CAAOI,IAAI,CAAC;AAAEH,QAAAA,KAAAA;AAAOC,QAAAA,IAAAA;AAAM,QAAA,GAAGC;AAAM,KAAA,CAAA;AACtC,CAAA;AAEA,MAAME,kBAAAA,GAAqB,CAACH,IAAAA,EAAcI,SAAAA,EAA0BC,KAAAA,GAAAA;AAClE,IAAA,MAAMC,YAAAA,GACJD,KAAAA,YAAiBE,KAAAA,GACb,CAAC,gBAAgB,EAAEF,KAAAA,CAAMG,OAAO,CAAA,CAAE,GAClC,CAAC,kDAAkD,EAAEC,OAAOJ,KAAAA,CAAAA,CAAAA,CAAQ;AAE1E,IAAA,OAAO,IAAIE,KAAAA,CAAM,CAAC,UAAU,EAAEP,IAAAA,CAAK,EAAE,EAAEI,SAAAA,CAAU,UAAU,EAAEE,YAAAA,CAAAA,CAAc,EAAE;AAAED,QAAAA;AAAM,KAAA,CAAA;AACvF,CAAA;AAEO,MAAMK,wBAAwB,CAACC,IAAAA,GAAAA;IACpC,MAAMC,SAAAA,GACJD,KAAKC,SAAS,KAAK,CAAIC,MAAAA,EAAgBC,KAAqCA,EAAAA,EAAG,CAAA;AAEjF,IAAA,MAAMC,oBAAAA,GAAuB,UAAA;AAC3B,QAAA,MAAM,CAACC,UAAAA,EAAYC,aAAAA,CAAc,GAAG,MAAMC,OAAAA,CAAQC,GAAG,CAAC;AACpDR,YAAAA,IAAAA,CAAKS,aAAa,EAAA;YAClBT,IAAAA,CAAKU,OAAO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AAEc,SAAAA,CAAU1B,IAAI,EAAE,EAAE,UAAA;AAC7C,wBAAA,MAAM0B,UAAUc,IAAI,EAAA;AACtB,oBAAA,CAAA,CAAA;AACF,gBAAA,CAAA,CAAE,OAAOH,KAAAA,EAAO;AACd,oBAAA,MAAMlC,kBAAAA,CAAmBuB,SAAAA,CAAU1B,IAAI,EAAE,MAAA,EAAQqC,KAAAA,CAAAA;AACnD,gBAAA;AAEA,gBAAA,MAAM1B,IAAAA,CAAKU,OAAO,CAACwB,cAAc,CAAC;AAAE7C,oBAAAA,IAAAA,EAAM0B,UAAU1B;AAAK,iBAAA,CAAA;AAEzD,gBAAA,MAAMuC,kBAAkBO,MAAAA,CAAOC,UAAU,CAAE,CAAA,CAACZ,IAAAA,CAAKC,GAAG,KAAKF,KAAI,IAAK,IAAG,EAAGc,OAAO,CAAC,CAAA,CAAA,CAAA;AAChFnD,gBAAAA,QAAAA,CAASc,KAAKb,MAAM,EAAE,UAAA,EAAY4B,SAAAA,CAAU1B,IAAI,EAAE;AAAEuC,oBAAAA;AAAgB,iBAAA,CAAA;AACtE,YAAA;YAEA,OAAOK,YAAAA,CAAad,GAAG,CAAC,CAAC,EAAE9B,IAAI,EAAE+B,IAAI,EAAE,IAAM;AAAE/B,oBAAAA,IAAAA;AAAM+B,oBAAAA;iBAAK,CAAA,CAAA;AAC5D,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -12,6 +12,7 @@ const wrapMigrationError = (name, direction, cause)=>{
|
|
|
12
12
|
});
|
|
13
13
|
};
|
|
14
14
|
const createMigrationRunner = (opts)=>{
|
|
15
|
+
const withPhase = opts.withPhase ?? ((_phase, fn)=>fn());
|
|
15
16
|
const getPendingMigrations = async ()=>{
|
|
16
17
|
const [migrations, executedNames] = await Promise.all([
|
|
17
18
|
opts.getMigrations(),
|
|
@@ -42,7 +43,9 @@ const createMigrationRunner = (opts)=>{
|
|
|
42
43
|
const start = Date.now();
|
|
43
44
|
logEvent(opts.logger, 'migrating', migration.name);
|
|
44
45
|
try {
|
|
45
|
-
await migration.
|
|
46
|
+
await withPhase(`migration ${migration.name}`, async ()=>{
|
|
47
|
+
await migration.up();
|
|
48
|
+
});
|
|
46
49
|
} catch (error) {
|
|
47
50
|
throw wrapMigrationError(migration.name, 'up', error);
|
|
48
51
|
}
|
|
@@ -66,7 +69,9 @@ const createMigrationRunner = (opts)=>{
|
|
|
66
69
|
const start = Date.now();
|
|
67
70
|
logEvent(opts.logger, 'reverting', migration.name);
|
|
68
71
|
try {
|
|
69
|
-
await migration.
|
|
72
|
+
await withPhase(`migration ${migration.name}`, async ()=>{
|
|
73
|
+
await migration.down();
|
|
74
|
+
});
|
|
70
75
|
} catch (error) {
|
|
71
76
|
throw wrapMigrationError(migration.name, 'down', error);
|
|
72
77
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.mjs","sources":["../../src/migrations/runner.ts"],"sourcesContent":["import type { MigrationRunnerFn } from './common';\nimport type { createStorage } from './storage';\n\nexport interface MigrationMeta {\n name: string;\n path?: string;\n}\n\nexport interface RunnableMigration extends MigrationMeta {\n up: MigrationRunnerFn;\n down: MigrationRunnerFn;\n}\n\nexport interface MigrationRunnerLogger {\n info(message: unknown): void;\n}\n\nexport interface MigrationRunnerOptions {\n storage: ReturnType<typeof createStorage>;\n logger: MigrationRunnerLogger;\n getMigrations: () => Promise<RunnableMigration[]>;\n}\n\nconst logEvent = (\n logger: MigrationRunnerLogger,\n event: string,\n name: string,\n extra?: Record<string, unknown>\n) => {\n logger.info({ event, name, ...extra });\n};\n\nconst wrapMigrationError = (name: string, direction: 'up' | 'down', cause: unknown): Error => {\n const causeMessage =\n cause instanceof Error\n ? `Original error: ${cause.message}`\n : `Non-error value thrown. See cause for full value: ${String(cause)}`;\n\n return new Error(`Migration ${name} (${direction}) failed: ${causeMessage}`, { cause });\n};\n\nexport const createMigrationRunner = (opts: MigrationRunnerOptions) => {\n const getPendingMigrations = async (): Promise<RunnableMigration[]> => {\n const [migrations, executedNames] = await Promise.all([\n opts.getMigrations(),\n opts.storage.executed(),\n ]);\n\n const executedSet = new Set(executedNames);\n return migrations.filter((migration) => !executedSet.has(migration.name));\n };\n\n const getExecutedMigrations = async (): Promise<RunnableMigration[]> => {\n const [migrations, executedNames] = await Promise.all([\n opts.getMigrations(),\n opts.storage.executed(),\n ]);\n\n const executedSet = new Set(executedNames);\n return migrations.filter((migration) => executedSet.has(migration.name));\n };\n\n return {\n async pending(): Promise<MigrationMeta[]> {\n const pending = await getPendingMigrations();\n return pending.map(({ name, path }) => ({ name, path }));\n },\n\n async up(): Promise<MigrationMeta[]> {\n const toBeApplied = await getPendingMigrations();\n\n for (const migration of toBeApplied) {\n const start = Date.now();\n\n logEvent(opts.logger, 'migrating', migration.name);\n\n try {\n await migration.up();\n } catch (error) {\n throw wrapMigrationError(migration.name, 'up', error);\n }\n\n await opts.storage.logMigration({ name: migration.name });\n\n const durationSeconds = (Date.now() - start) / 1000;\n logEvent(opts.logger, 'migrated', migration.name, { durationSeconds });\n }\n\n return toBeApplied.map(({ name, path }) => ({ name, path }));\n },\n\n async down(): Promise<MigrationMeta[]> {\n const executedReversed = (await getExecutedMigrations()).slice().reverse();\n const toBeReverted = executedReversed.slice(0, 1);\n\n for (const migration of toBeReverted) {\n const start = Date.now();\n\n logEvent(opts.logger, 'reverting', migration.name);\n\n try {\n await migration.down();\n } catch (error) {\n throw wrapMigrationError(migration.name, 'down', error);\n }\n\n await opts.storage.unlogMigration({ name: migration.name });\n\n const durationSeconds = Number.parseFloat(((Date.now() - start) / 1000).toFixed(3));\n logEvent(opts.logger, 'reverted', migration.name, { durationSeconds });\n }\n\n return toBeReverted.map(({ name, path }) => ({ name, path }));\n },\n };\n};\n"],"names":["logEvent","logger","event","name","extra","info","wrapMigrationError","direction","cause","causeMessage","Error","message","String","createMigrationRunner","opts","getPendingMigrations","migrations","executedNames","Promise","all","getMigrations","storage","executed","executedSet","Set","filter","migration","has","getExecutedMigrations","pending","map","path","up","toBeApplied","start","Date","now","error","logMigration","durationSeconds","down","executedReversed","slice","reverse","toBeReverted","unlogMigration","Number","parseFloat","toFixed"],"mappings":"
|
|
1
|
+
{"version":3,"file":"runner.mjs","sources":["../../src/migrations/runner.ts"],"sourcesContent":["import type { MigrationRunnerFn } from './common';\nimport type { createStorage } from './storage';\n\nexport interface MigrationMeta {\n name: string;\n path?: string;\n}\n\nexport interface RunnableMigration extends MigrationMeta {\n up: MigrationRunnerFn;\n down: MigrationRunnerFn;\n}\n\nexport interface MigrationRunnerLogger {\n info(message: unknown): void;\n}\n\nexport interface MigrationRunnerOptions {\n storage: ReturnType<typeof createStorage>;\n logger: MigrationRunnerLogger;\n getMigrations: () => Promise<RunnableMigration[]>;\n /** Labels pool timeout reports with the running migration's name. */\n withPhase?: <T>(phase: string, fn: () => Promise<T>) => Promise<T>;\n}\n\nconst logEvent = (\n logger: MigrationRunnerLogger,\n event: string,\n name: string,\n extra?: Record<string, unknown>\n) => {\n logger.info({ event, name, ...extra });\n};\n\nconst wrapMigrationError = (name: string, direction: 'up' | 'down', cause: unknown): Error => {\n const causeMessage =\n cause instanceof Error\n ? `Original error: ${cause.message}`\n : `Non-error value thrown. See cause for full value: ${String(cause)}`;\n\n return new Error(`Migration ${name} (${direction}) failed: ${causeMessage}`, { cause });\n};\n\nexport const createMigrationRunner = (opts: MigrationRunnerOptions) => {\n const withPhase =\n opts.withPhase ?? (<T>(_phase: string, fn: () => Promise<T>): Promise<T> => fn());\n\n const getPendingMigrations = async (): Promise<RunnableMigration[]> => {\n const [migrations, executedNames] = await Promise.all([\n opts.getMigrations(),\n opts.storage.executed(),\n ]);\n\n const executedSet = new Set(executedNames);\n return migrations.filter((migration) => !executedSet.has(migration.name));\n };\n\n const getExecutedMigrations = async (): Promise<RunnableMigration[]> => {\n const [migrations, executedNames] = await Promise.all([\n opts.getMigrations(),\n opts.storage.executed(),\n ]);\n\n const executedSet = new Set(executedNames);\n return migrations.filter((migration) => executedSet.has(migration.name));\n };\n\n return {\n async pending(): Promise<MigrationMeta[]> {\n const pending = await getPendingMigrations();\n return pending.map(({ name, path }) => ({ name, path }));\n },\n\n async up(): Promise<MigrationMeta[]> {\n const toBeApplied = await getPendingMigrations();\n\n for (const migration of toBeApplied) {\n const start = Date.now();\n\n logEvent(opts.logger, 'migrating', migration.name);\n\n try {\n await withPhase(`migration ${migration.name}`, async () => {\n await migration.up();\n });\n } catch (error) {\n throw wrapMigrationError(migration.name, 'up', error);\n }\n\n await opts.storage.logMigration({ name: migration.name });\n\n const durationSeconds = (Date.now() - start) / 1000;\n logEvent(opts.logger, 'migrated', migration.name, { durationSeconds });\n }\n\n return toBeApplied.map(({ name, path }) => ({ name, path }));\n },\n\n async down(): Promise<MigrationMeta[]> {\n const executedReversed = (await getExecutedMigrations()).slice().reverse();\n const toBeReverted = executedReversed.slice(0, 1);\n\n for (const migration of toBeReverted) {\n const start = Date.now();\n\n logEvent(opts.logger, 'reverting', migration.name);\n\n try {\n await withPhase(`migration ${migration.name}`, async () => {\n await migration.down();\n });\n } catch (error) {\n throw wrapMigrationError(migration.name, 'down', error);\n }\n\n await opts.storage.unlogMigration({ name: migration.name });\n\n const durationSeconds = Number.parseFloat(((Date.now() - start) / 1000).toFixed(3));\n logEvent(opts.logger, 'reverted', migration.name, { durationSeconds });\n }\n\n return toBeReverted.map(({ name, path }) => ({ name, path }));\n },\n };\n};\n"],"names":["logEvent","logger","event","name","extra","info","wrapMigrationError","direction","cause","causeMessage","Error","message","String","createMigrationRunner","opts","withPhase","_phase","fn","getPendingMigrations","migrations","executedNames","Promise","all","getMigrations","storage","executed","executedSet","Set","filter","migration","has","getExecutedMigrations","pending","map","path","up","toBeApplied","start","Date","now","error","logMigration","durationSeconds","down","executedReversed","slice","reverse","toBeReverted","unlogMigration","Number","parseFloat","toFixed"],"mappings":"AAyBA,MAAMA,QAAAA,GAAW,CACfC,MAAAA,EACAC,KAAAA,EACAC,IAAAA,EACAC,KAAAA,GAAAA;AAEAH,IAAAA,MAAAA,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AA,IAAAA,EAAM0B,UAAU1B;AAAK,iBAAA,CAAA;AAEzD,gBAAA,MAAMuC,kBAAkBO,MAAAA,CAAOC,UAAU,CAAE,CAAA,CAACZ,IAAAA,CAAKC,GAAG,KAAKF,KAAI,IAAK,IAAG,EAAGc,OAAO,CAAC,CAAA,CAAA,CAAA;AAChFnD,gBAAAA,QAAAA,CAASc,KAAKb,MAAM,EAAE,UAAA,EAAY4B,SAAAA,CAAU1B,IAAI,EAAE;AAAEuC,oBAAAA;AAAgB,iBAAA,CAAA;AACtE,YAAA;YAEA,OAAOK,YAAAA,CAAad,GAAG,CAAC,CAAC,EAAE9B,IAAI,EAAE+B,IAAI,EAAE,IAAM;AAAE/B,oBAAAA,IAAAA;AAAM+B,oBAAAA;iBAAK,CAAA,CAAA;AAC5D,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../src/migrations/users.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAEnC,eAAO,MAAM,2BAA2B,GAAI,IAAI,QAAQ,KAAG,
|
|
1
|
+
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../src/migrations/users.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAEnC,eAAO,MAAM,2BAA2B,GAAI,IAAI,QAAQ,KAAG,qBAiC1D,CAAC"}
|
package/dist/migrations/users.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.js","sources":["../../src/migrations/users.ts"],"sourcesContent":["import path from 'path';\n\nimport fse from 'fs-extra';\n\nimport { discoverMigrationFiles } from './discover';\nimport { createMigrationRunner } from './runner';\nimport { resolveMigrationFiles } from './resolver';\nimport { createStorage } from './storage';\nimport { transformLogMessage } from './logger';\n\nimport type { UserMigrationProvider } from './common';\nimport type { Database } from '..';\n\nexport const createUserMigrationProvider = (db: Database): UserMigrationProvider => {\n const dir = db.config.settings.migrations.dir;\n\n fse.ensureDirSync(dir);\n\n const context = { db };\n\n const runner = createMigrationRunner({\n storage: createStorage({ db, tableName: 'strapi_migrations' }),\n logger: {\n info(message) {\n db.logger.info(transformLogMessage('info', message));\n },\n },\n async getMigrations() {\n const filepaths = discoverMigrationFiles(path.resolve(dir));\n return resolveMigrationFiles(filepaths, context);\n },\n });\n\n return {\n async shouldRun() {\n const pendingMigrations = await runner.pending();\n return pendingMigrations.length > 0 && db.config?.settings?.runMigrations === true;\n },\n async up() {\n await runner.up();\n },\n async down() {\n await runner.down();\n },\n };\n};\n"],"names":["createUserMigrationProvider","db","dir","config","settings","migrations","fse","ensureDirSync","context","runner","createMigrationRunner","storage","createStorage","tableName","logger","info","message","transformLogMessage","getMigrations","filepaths","discoverMigrationFiles","path","resolve","resolveMigrationFiles","shouldRun","pendingMigrations","pending","length","runMigrations","up","down"],"mappings":";;;;;;;;;;;;;;;AAaO,MAAMA,8BAA8B,CAACC,EAAAA,GAAAA;IAC1C,MAAMC,GAAAA,GAAMD,GAAGE,MAAM,CAACC,QAAQ,CAACC,UAAU,CAACH,GAAG;AAE7CI,IAAAA,oBAAAA,CAAIC,aAAa,CAACL,GAAAA,CAAAA;AAElB,IAAA,MAAMM,OAAAA,GAAU;AAAEP,QAAAA;AAAG,KAAA;AAErB,IAAA,MAAMQ,WAASC,4BAAAA,CAAsB;AACnCC,QAAAA,OAAAA,EAASC,qBAAAA,CAAc;AAAEX,YAAAA,EAAAA;YAAIY,SAAAA,EAAW;AAAoB,SAAA,CAAA;
|
|
1
|
+
{"version":3,"file":"users.js","sources":["../../src/migrations/users.ts"],"sourcesContent":["import path from 'path';\n\nimport fse from 'fs-extra';\n\nimport { discoverMigrationFiles } from './discover';\nimport { createMigrationRunner } from './runner';\nimport { resolveMigrationFiles } from './resolver';\nimport { createStorage } from './storage';\nimport { transformLogMessage } from './logger';\n\nimport type { UserMigrationProvider } from './common';\nimport type { Database } from '..';\n\nexport const createUserMigrationProvider = (db: Database): UserMigrationProvider => {\n const dir = db.config.settings.migrations.dir;\n\n fse.ensureDirSync(dir);\n\n const context = { db };\n\n const runner = createMigrationRunner({\n storage: createStorage({ db, tableName: 'strapi_migrations' }),\n withPhase: (phase, fn) => db.runInPhase(phase, fn),\n logger: {\n info(message) {\n db.logger.info(transformLogMessage('info', message));\n },\n },\n async getMigrations() {\n const filepaths = discoverMigrationFiles(path.resolve(dir));\n return resolveMigrationFiles(filepaths, context);\n },\n });\n\n return {\n async shouldRun() {\n const pendingMigrations = await runner.pending();\n return pendingMigrations.length > 0 && db.config?.settings?.runMigrations === true;\n },\n async up() {\n await runner.up();\n },\n async down() {\n await runner.down();\n },\n };\n};\n"],"names":["createUserMigrationProvider","db","dir","config","settings","migrations","fse","ensureDirSync","context","runner","createMigrationRunner","storage","createStorage","tableName","withPhase","phase","fn","runInPhase","logger","info","message","transformLogMessage","getMigrations","filepaths","discoverMigrationFiles","path","resolve","resolveMigrationFiles","shouldRun","pendingMigrations","pending","length","runMigrations","up","down"],"mappings":";;;;;;;;;;;;;;;AAaO,MAAMA,8BAA8B,CAACC,EAAAA,GAAAA;IAC1C,MAAMC,GAAAA,GAAMD,GAAGE,MAAM,CAACC,QAAQ,CAACC,UAAU,CAACH,GAAG;AAE7CI,IAAAA,oBAAAA,CAAIC,aAAa,CAACL,GAAAA,CAAAA;AAElB,IAAA,MAAMM,OAAAA,GAAU;AAAEP,QAAAA;AAAG,KAAA;AAErB,IAAA,MAAMQ,WAASC,4BAAAA,CAAsB;AACnCC,QAAAA,OAAAA,EAASC,qBAAAA,CAAc;AAAEX,YAAAA,EAAAA;YAAIY,SAAAA,EAAW;AAAoB,SAAA,CAAA;AAC5DC,QAAAA,SAAAA,EAAW,CAACC,KAAAA,EAAOC,EAAAA,GAAOf,EAAAA,CAAGgB,UAAU,CAACF,KAAAA,EAAOC,EAAAA,CAAAA;QAC/CE,MAAAA,EAAQ;AACNC,YAAAA,IAAAA,CAAAA,CAAKC,OAAO,EAAA;AACVnB,gBAAAA,EAAAA,CAAGiB,MAAM,CAACC,IAAI,CAACE,2BAAoB,MAAA,EAAQD,OAAAA,CAAAA,CAAAA;AAC7C,YAAA;AACF,SAAA;QACA,MAAME,aAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAMC,SAAAA,GAAYC,+BAAAA,CAAuBC,qBAAAA,CAAKC,OAAO,CAACxB,GAAAA,CAAAA,CAAAA;AACtD,YAAA,OAAOyB,+BAAsBJ,SAAAA,EAAWf,OAAAA,CAAAA;AAC1C,QAAA;AACF,KAAA,CAAA;IAEA,OAAO;QACL,MAAMoB,SAAAA,CAAAA,GAAAA;YACJ,MAAMC,iBAAAA,GAAoB,MAAMpB,QAAAA,CAAOqB,OAAO,EAAA;YAC9C,OAAOD,iBAAAA,CAAkBE,MAAM,GAAG,CAAA,IAAK9B,GAAGE,MAAM,EAAEC,UAAU4B,aAAAA,KAAkB,IAAA;AAChF,QAAA,CAAA;QACA,MAAMC,EAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAMxB,SAAOwB,EAAE,EAAA;AACjB,QAAA,CAAA;QACA,MAAMC,IAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAMzB,SAAOyB,IAAI,EAAA;AACnB,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.mjs","sources":["../../src/migrations/users.ts"],"sourcesContent":["import path from 'path';\n\nimport fse from 'fs-extra';\n\nimport { discoverMigrationFiles } from './discover';\nimport { createMigrationRunner } from './runner';\nimport { resolveMigrationFiles } from './resolver';\nimport { createStorage } from './storage';\nimport { transformLogMessage } from './logger';\n\nimport type { UserMigrationProvider } from './common';\nimport type { Database } from '..';\n\nexport const createUserMigrationProvider = (db: Database): UserMigrationProvider => {\n const dir = db.config.settings.migrations.dir;\n\n fse.ensureDirSync(dir);\n\n const context = { db };\n\n const runner = createMigrationRunner({\n storage: createStorage({ db, tableName: 'strapi_migrations' }),\n logger: {\n info(message) {\n db.logger.info(transformLogMessage('info', message));\n },\n },\n async getMigrations() {\n const filepaths = discoverMigrationFiles(path.resolve(dir));\n return resolveMigrationFiles(filepaths, context);\n },\n });\n\n return {\n async shouldRun() {\n const pendingMigrations = await runner.pending();\n return pendingMigrations.length > 0 && db.config?.settings?.runMigrations === true;\n },\n async up() {\n await runner.up();\n },\n async down() {\n await runner.down();\n },\n };\n};\n"],"names":["createUserMigrationProvider","db","dir","config","settings","migrations","fse","ensureDirSync","context","runner","createMigrationRunner","storage","createStorage","tableName","logger","info","message","transformLogMessage","getMigrations","filepaths","discoverMigrationFiles","path","resolve","resolveMigrationFiles","shouldRun","pendingMigrations","pending","length","runMigrations","up","down"],"mappings":";;;;;;;;AAaO,MAAMA,8BAA8B,CAACC,EAAAA,GAAAA;IAC1C,MAAMC,GAAAA,GAAMD,GAAGE,MAAM,CAACC,QAAQ,CAACC,UAAU,CAACH,GAAG;AAE7CI,IAAAA,GAAAA,CAAIC,aAAa,CAACL,GAAAA,CAAAA;AAElB,IAAA,MAAMM,OAAAA,GAAU;AAAEP,QAAAA;AAAG,KAAA;AAErB,IAAA,MAAMQ,SAASC,qBAAAA,CAAsB;AACnCC,QAAAA,OAAAA,EAASC,aAAAA,CAAc;AAAEX,YAAAA,EAAAA;YAAIY,SAAAA,EAAW;AAAoB,SAAA,CAAA;
|
|
1
|
+
{"version":3,"file":"users.mjs","sources":["../../src/migrations/users.ts"],"sourcesContent":["import path from 'path';\n\nimport fse from 'fs-extra';\n\nimport { discoverMigrationFiles } from './discover';\nimport { createMigrationRunner } from './runner';\nimport { resolveMigrationFiles } from './resolver';\nimport { createStorage } from './storage';\nimport { transformLogMessage } from './logger';\n\nimport type { UserMigrationProvider } from './common';\nimport type { Database } from '..';\n\nexport const createUserMigrationProvider = (db: Database): UserMigrationProvider => {\n const dir = db.config.settings.migrations.dir;\n\n fse.ensureDirSync(dir);\n\n const context = { db };\n\n const runner = createMigrationRunner({\n storage: createStorage({ db, tableName: 'strapi_migrations' }),\n withPhase: (phase, fn) => db.runInPhase(phase, fn),\n logger: {\n info(message) {\n db.logger.info(transformLogMessage('info', message));\n },\n },\n async getMigrations() {\n const filepaths = discoverMigrationFiles(path.resolve(dir));\n return resolveMigrationFiles(filepaths, context);\n },\n });\n\n return {\n async shouldRun() {\n const pendingMigrations = await runner.pending();\n return pendingMigrations.length > 0 && db.config?.settings?.runMigrations === true;\n },\n async up() {\n await runner.up();\n },\n async down() {\n await runner.down();\n },\n };\n};\n"],"names":["createUserMigrationProvider","db","dir","config","settings","migrations","fse","ensureDirSync","context","runner","createMigrationRunner","storage","createStorage","tableName","withPhase","phase","fn","runInPhase","logger","info","message","transformLogMessage","getMigrations","filepaths","discoverMigrationFiles","path","resolve","resolveMigrationFiles","shouldRun","pendingMigrations","pending","length","runMigrations","up","down"],"mappings":";;;;;;;;AAaO,MAAMA,8BAA8B,CAACC,EAAAA,GAAAA;IAC1C,MAAMC,GAAAA,GAAMD,GAAGE,MAAM,CAACC,QAAQ,CAACC,UAAU,CAACH,GAAG;AAE7CI,IAAAA,GAAAA,CAAIC,aAAa,CAACL,GAAAA,CAAAA;AAElB,IAAA,MAAMM,OAAAA,GAAU;AAAEP,QAAAA;AAAG,KAAA;AAErB,IAAA,MAAMQ,SAASC,qBAAAA,CAAsB;AACnCC,QAAAA,OAAAA,EAASC,aAAAA,CAAc;AAAEX,YAAAA,EAAAA;YAAIY,SAAAA,EAAW;AAAoB,SAAA,CAAA;AAC5DC,QAAAA,SAAAA,EAAW,CAACC,KAAAA,EAAOC,EAAAA,GAAOf,EAAAA,CAAGgB,UAAU,CAACF,KAAAA,EAAOC,EAAAA,CAAAA;QAC/CE,MAAAA,EAAQ;AACNC,YAAAA,IAAAA,CAAAA,CAAKC,OAAO,EAAA;AACVnB,gBAAAA,EAAAA,CAAGiB,MAAM,CAACC,IAAI,CAACE,oBAAoB,MAAA,EAAQD,OAAAA,CAAAA,CAAAA;AAC7C,YAAA;AACF,SAAA;QACA,MAAME,aAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAMC,SAAAA,GAAYC,sBAAAA,CAAuBC,IAAAA,CAAKC,OAAO,CAACxB,GAAAA,CAAAA,CAAAA;AACtD,YAAA,OAAOyB,sBAAsBJ,SAAAA,EAAWf,OAAAA,CAAAA;AAC1C,QAAA;AACF,KAAA,CAAA;IAEA,OAAO;QACL,MAAMoB,SAAAA,CAAAA,GAAAA;YACJ,MAAMC,iBAAAA,GAAoB,MAAMpB,MAAAA,CAAOqB,OAAO,EAAA;YAC9C,OAAOD,iBAAAA,CAAkBE,MAAM,GAAG,CAAA,IAAK9B,GAAGE,MAAM,EAAEC,UAAU4B,aAAAA,KAAkB,IAAA;AAChF,QAAA,CAAA;QACA,MAAMC,EAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAMxB,OAAOwB,EAAE,EAAA;AACjB,QAAA,CAAA;QACA,MAAMC,IAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAMzB,OAAOyB,IAAI,EAAA;AACnB,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { EventLoopDelay } from './event-loop';
|
|
2
|
+
export declare const POOL_TIMEOUT_CODE = "DB_POOL_ACQUIRE_TIMEOUT";
|
|
3
|
+
export interface PoolState {
|
|
4
|
+
used: number;
|
|
5
|
+
free: number;
|
|
6
|
+
pendingAcquires: number;
|
|
7
|
+
pendingCreates: number;
|
|
8
|
+
min?: number;
|
|
9
|
+
max?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface PoolTimeoutDetails {
|
|
12
|
+
code: typeof POOL_TIMEOUT_CODE;
|
|
13
|
+
/** How long this caller waited before knex gave up. */
|
|
14
|
+
waitedMs: number;
|
|
15
|
+
/** The timeout knex applied: the smaller of acquireConnectionTimeout and pool.acquireTimeoutMillis. */
|
|
16
|
+
acquireTimeoutMs?: number;
|
|
17
|
+
/** As configured, when set. */
|
|
18
|
+
acquireConnectionTimeout?: number;
|
|
19
|
+
poolAcquireTimeoutMillis?: number;
|
|
20
|
+
/** Pool counts at the moment of the timeout. */
|
|
21
|
+
pool?: PoolState;
|
|
22
|
+
/** tarn's message: the error of a failed connection attempt, or "operation timed out for an unknown reason". */
|
|
23
|
+
poolReason?: string;
|
|
24
|
+
eventLoopDelay?: EventLoopDelay;
|
|
25
|
+
phase?: string;
|
|
26
|
+
hostname: string;
|
|
27
|
+
pid: number;
|
|
28
|
+
}
|
|
29
|
+
export interface TarnPoolLike {
|
|
30
|
+
min?: number;
|
|
31
|
+
max?: number;
|
|
32
|
+
acquireTimeoutMillis?: number;
|
|
33
|
+
numUsed(): number;
|
|
34
|
+
numFree(): number;
|
|
35
|
+
numPendingAcquires(): number;
|
|
36
|
+
numPendingCreates(): number;
|
|
37
|
+
}
|
|
38
|
+
export interface KnexClientLike {
|
|
39
|
+
config?: {
|
|
40
|
+
acquireConnectionTimeout?: unknown;
|
|
41
|
+
pool?: {
|
|
42
|
+
acquireTimeoutMillis?: unknown;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/** A tarn pool, or knex's wrapper around a native driver pool, which has no counters. */
|
|
46
|
+
pool?: Partial<TarnPoolLike> | null;
|
|
47
|
+
}
|
|
48
|
+
export interface CollectInput {
|
|
49
|
+
waitedMs: number;
|
|
50
|
+
cause: unknown;
|
|
51
|
+
eventLoopDelay?: EventLoopDelay;
|
|
52
|
+
phase?: string;
|
|
53
|
+
hostname: string;
|
|
54
|
+
pid: number;
|
|
55
|
+
}
|
|
56
|
+
export declare const readPoolState: (pool: Partial<TarnPoolLike> | null | undefined) => PoolState | undefined;
|
|
57
|
+
export declare const collectPoolTimeoutDetails: (client: KnexClientLike, input: CollectInput) => PoolTimeoutDetails;
|
|
58
|
+
//# sourceMappingURL=details.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"details.d.ts","sourceRoot":"","sources":["../../src/pool-diagnostics/details.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,eAAO,MAAM,iBAAiB,4BAA4B,CAAC;AAE3D,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,OAAO,iBAAiB,CAAC;IAC/B,uDAAuD;IACvD,QAAQ,EAAE,MAAM,CAAC;IACjB,uGAAuG;IACvG,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,+BAA+B;IAC/B,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,gDAAgD;IAChD,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,gHAAgH;IAChH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,OAAO,IAAI,MAAM,CAAC;IAClB,OAAO,IAAI,MAAM,CAAC;IAClB,kBAAkB,IAAI,MAAM,CAAC;IAC7B,iBAAiB,IAAI,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE;QAAE,wBAAwB,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE;YAAE,oBAAoB,CAAC,EAAE,OAAO,CAAA;SAAE,CAAA;KAAE,CAAC;IAC3F,yFAAyF;IACzF,IAAI,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;CACrC;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb;AAWD,eAAO,MAAM,aAAa,GACxB,MAAM,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,GAAG,SAAS,KAC7C,SAAS,GAAG,SAcd,CAAC;AAEF,eAAO,MAAM,yBAAyB,GACpC,QAAQ,cAAc,EACtB,OAAO,YAAY,KAClB,kBAkBF,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const POOL_TIMEOUT_CODE = 'DB_POOL_ACQUIRE_TIMEOUT';
|
|
4
|
+
const asNumber = (value)=>typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
5
|
+
const hasCounters = (pool)=>typeof pool.numUsed === 'function' && typeof pool.numFree === 'function' && typeof pool.numPendingAcquires === 'function' && typeof pool.numPendingCreates === 'function';
|
|
6
|
+
const readPoolState = (pool)=>{
|
|
7
|
+
// knex also accepts a pool that only has acquire, release and destroy
|
|
8
|
+
if (!pool || !hasCounters(pool)) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
used: pool.numUsed(),
|
|
13
|
+
free: pool.numFree(),
|
|
14
|
+
pendingAcquires: pool.numPendingAcquires(),
|
|
15
|
+
pendingCreates: pool.numPendingCreates(),
|
|
16
|
+
min: asNumber(pool.min),
|
|
17
|
+
max: asNumber(pool.max)
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const collectPoolTimeoutDetails = (client, input)=>{
|
|
21
|
+
const config = client.config ?? {};
|
|
22
|
+
return {
|
|
23
|
+
code: POOL_TIMEOUT_CODE,
|
|
24
|
+
waitedMs: input.waitedMs,
|
|
25
|
+
// knex writes the effective (smaller) timeout into the tarn pool options
|
|
26
|
+
acquireTimeoutMs: asNumber(client.pool?.acquireTimeoutMillis),
|
|
27
|
+
acquireConnectionTimeout: asNumber(config.acquireConnectionTimeout),
|
|
28
|
+
poolAcquireTimeoutMillis: asNumber(config.pool?.acquireTimeoutMillis),
|
|
29
|
+
pool: readPoolState(client.pool),
|
|
30
|
+
// knex 3.3 keeps tarn's error as `cause`; its message is all tarn keeps of a failed attempt
|
|
31
|
+
poolReason: input.cause instanceof Error ? input.cause.message : undefined,
|
|
32
|
+
eventLoopDelay: input.eventLoopDelay,
|
|
33
|
+
phase: input.phase,
|
|
34
|
+
hostname: input.hostname,
|
|
35
|
+
pid: input.pid
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
exports.POOL_TIMEOUT_CODE = POOL_TIMEOUT_CODE;
|
|
40
|
+
exports.collectPoolTimeoutDetails = collectPoolTimeoutDetails;
|
|
41
|
+
exports.readPoolState = readPoolState;
|
|
42
|
+
//# sourceMappingURL=details.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"details.js","sources":["../../src/pool-diagnostics/details.ts"],"sourcesContent":["import type { EventLoopDelay } from './event-loop';\n\nexport const POOL_TIMEOUT_CODE = 'DB_POOL_ACQUIRE_TIMEOUT';\n\nexport interface PoolState {\n used: number;\n free: number;\n pendingAcquires: number;\n pendingCreates: number;\n min?: number;\n max?: number;\n}\n\nexport interface PoolTimeoutDetails {\n code: typeof POOL_TIMEOUT_CODE;\n /** How long this caller waited before knex gave up. */\n waitedMs: number;\n /** The timeout knex applied: the smaller of acquireConnectionTimeout and pool.acquireTimeoutMillis. */\n acquireTimeoutMs?: number;\n /** As configured, when set. */\n acquireConnectionTimeout?: number;\n poolAcquireTimeoutMillis?: number;\n /** Pool counts at the moment of the timeout. */\n pool?: PoolState;\n /** tarn's message: the error of a failed connection attempt, or \"operation timed out for an unknown reason\". */\n poolReason?: string;\n eventLoopDelay?: EventLoopDelay;\n phase?: string;\n hostname: string;\n pid: number;\n}\n\nexport interface TarnPoolLike {\n min?: number;\n max?: number;\n acquireTimeoutMillis?: number;\n numUsed(): number;\n numFree(): number;\n numPendingAcquires(): number;\n numPendingCreates(): number;\n}\n\nexport interface KnexClientLike {\n config?: { acquireConnectionTimeout?: unknown; pool?: { acquireTimeoutMillis?: unknown } };\n /** A tarn pool, or knex's wrapper around a native driver pool, which has no counters. */\n pool?: Partial<TarnPoolLike> | null;\n}\n\nexport interface CollectInput {\n waitedMs: number;\n cause: unknown;\n eventLoopDelay?: EventLoopDelay;\n phase?: string;\n hostname: string;\n pid: number;\n}\n\nconst asNumber = (value: unknown) =>\n typeof value === 'number' && Number.isFinite(value) ? value : undefined;\n\nconst hasCounters = (pool: Partial<TarnPoolLike>): pool is TarnPoolLike =>\n typeof pool.numUsed === 'function' &&\n typeof pool.numFree === 'function' &&\n typeof pool.numPendingAcquires === 'function' &&\n typeof pool.numPendingCreates === 'function';\n\nexport const readPoolState = (\n pool: Partial<TarnPoolLike> | null | undefined\n): PoolState | undefined => {\n // knex also accepts a pool that only has acquire, release and destroy\n if (!pool || !hasCounters(pool)) {\n return undefined;\n }\n\n return {\n used: pool.numUsed(),\n free: pool.numFree(),\n pendingAcquires: pool.numPendingAcquires(),\n pendingCreates: pool.numPendingCreates(),\n min: asNumber(pool.min),\n max: asNumber(pool.max),\n };\n};\n\nexport const collectPoolTimeoutDetails = (\n client: KnexClientLike,\n input: CollectInput\n): PoolTimeoutDetails => {\n const config = client.config ?? {};\n\n return {\n code: POOL_TIMEOUT_CODE,\n waitedMs: input.waitedMs,\n // knex writes the effective (smaller) timeout into the tarn pool options\n acquireTimeoutMs: asNumber(client.pool?.acquireTimeoutMillis),\n acquireConnectionTimeout: asNumber(config.acquireConnectionTimeout),\n poolAcquireTimeoutMillis: asNumber(config.pool?.acquireTimeoutMillis),\n pool: readPoolState(client.pool),\n // knex 3.3 keeps tarn's error as `cause`; its message is all tarn keeps of a failed attempt\n poolReason: input.cause instanceof Error ? input.cause.message : undefined,\n eventLoopDelay: input.eventLoopDelay,\n phase: input.phase,\n hostname: input.hostname,\n pid: input.pid,\n };\n};\n"],"names":["POOL_TIMEOUT_CODE","asNumber","value","Number","isFinite","undefined","hasCounters","pool","numUsed","numFree","numPendingAcquires","numPendingCreates","readPoolState","used","free","pendingAcquires","pendingCreates","min","max","collectPoolTimeoutDetails","client","input","config","code","waitedMs","acquireTimeoutMs","acquireTimeoutMillis","acquireConnectionTimeout","poolAcquireTimeoutMillis","poolReason","cause","Error","message","eventLoopDelay","phase","hostname","pid"],"mappings":";;AAEO,MAAMA,oBAAoB;AAuDjC,MAAMC,QAAAA,GAAW,CAACC,KAAAA,GAChB,OAAOA,KAAAA,KAAU,YAAYC,MAAAA,CAAOC,QAAQ,CAACF,KAAAA,CAAAA,GAASA,KAAAA,GAAQG,SAAAA;AAEhE,MAAMC,WAAAA,GAAc,CAACC,IAAAA,GACnB,OAAOA,KAAKC,OAAO,KAAK,cACxB,OAAOD,IAAAA,CAAKE,OAAO,KAAK,UAAA,IACxB,OAAOF,IAAAA,CAAKG,kBAAkB,KAAK,UAAA,IACnC,OAAOH,IAAAA,CAAKI,iBAAiB,KAAK,UAAA;AAE7B,MAAMC,gBAAgB,CAC3BL,IAAAA,GAAAA;;AAGA,IAAA,IAAI,CAACA,IAAAA,IAAQ,CAACD,WAAAA,CAAYC,IAAAA,CAAAA,EAAO;QAC/B,OAAOF,SAAAA;AACT,IAAA;IAEA,OAAO;AACLQ,QAAAA,IAAAA,EAAMN,KAAKC,OAAO,EAAA;AAClBM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+
const hasCounters = (pool)=>typeof pool.numUsed === 'function' && typeof pool.numFree === 'function' && typeof pool.numPendingAcquires === 'function' && typeof pool.numPendingCreates === 'function';
|
|
4
|
+
const readPoolState = (pool)=>{
|
|
5
|
+
// knex also accepts a pool that only has acquire, release and destroy
|
|
6
|
+
if (!pool || !hasCounters(pool)) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
used: pool.numUsed(),
|
|
11
|
+
free: pool.numFree(),
|
|
12
|
+
pendingAcquires: pool.numPendingAcquires(),
|
|
13
|
+
pendingCreates: pool.numPendingCreates(),
|
|
14
|
+
min: asNumber(pool.min),
|
|
15
|
+
max: asNumber(pool.max)
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const collectPoolTimeoutDetails = (client, input)=>{
|
|
19
|
+
const config = client.config ?? {};
|
|
20
|
+
return {
|
|
21
|
+
code: POOL_TIMEOUT_CODE,
|
|
22
|
+
waitedMs: input.waitedMs,
|
|
23
|
+
// knex writes the effective (smaller) timeout into the tarn pool options
|
|
24
|
+
acquireTimeoutMs: asNumber(client.pool?.acquireTimeoutMillis),
|
|
25
|
+
acquireConnectionTimeout: asNumber(config.acquireConnectionTimeout),
|
|
26
|
+
poolAcquireTimeoutMillis: asNumber(config.pool?.acquireTimeoutMillis),
|
|
27
|
+
pool: readPoolState(client.pool),
|
|
28
|
+
// knex 3.3 keeps tarn's error as `cause`; its message is all tarn keeps of a failed attempt
|
|
29
|
+
poolReason: input.cause instanceof Error ? input.cause.message : undefined,
|
|
30
|
+
eventLoopDelay: input.eventLoopDelay,
|
|
31
|
+
phase: input.phase,
|
|
32
|
+
hostname: input.hostname,
|
|
33
|
+
pid: input.pid
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { POOL_TIMEOUT_CODE, collectPoolTimeoutDetails, readPoolState };
|
|
38
|
+
//# sourceMappingURL=details.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"details.mjs","sources":["../../src/pool-diagnostics/details.ts"],"sourcesContent":["import type { EventLoopDelay } from './event-loop';\n\nexport const POOL_TIMEOUT_CODE = 'DB_POOL_ACQUIRE_TIMEOUT';\n\nexport interface PoolState {\n used: number;\n free: number;\n pendingAcquires: number;\n pendingCreates: number;\n min?: number;\n max?: number;\n}\n\nexport interface PoolTimeoutDetails {\n code: typeof POOL_TIMEOUT_CODE;\n /** How long this caller waited before knex gave up. */\n waitedMs: number;\n /** The timeout knex applied: the smaller of acquireConnectionTimeout and pool.acquireTimeoutMillis. */\n acquireTimeoutMs?: number;\n /** As configured, when set. */\n acquireConnectionTimeout?: number;\n poolAcquireTimeoutMillis?: number;\n /** Pool counts at the moment of the timeout. */\n pool?: PoolState;\n /** tarn's message: the error of a failed connection attempt, or \"operation timed out for an unknown reason\". */\n poolReason?: string;\n eventLoopDelay?: EventLoopDelay;\n phase?: string;\n hostname: string;\n pid: number;\n}\n\nexport interface TarnPoolLike {\n min?: number;\n max?: number;\n acquireTimeoutMillis?: number;\n numUsed(): number;\n numFree(): number;\n numPendingAcquires(): number;\n numPendingCreates(): number;\n}\n\nexport interface KnexClientLike {\n config?: { acquireConnectionTimeout?: unknown; pool?: { acquireTimeoutMillis?: unknown } };\n /** A tarn pool, or knex's wrapper around a native driver pool, which has no counters. */\n pool?: Partial<TarnPoolLike> | null;\n}\n\nexport interface CollectInput {\n waitedMs: number;\n cause: unknown;\n eventLoopDelay?: EventLoopDelay;\n phase?: string;\n hostname: string;\n pid: number;\n}\n\nconst asNumber = (value: unknown) =>\n typeof value === 'number' && Number.isFinite(value) ? value : undefined;\n\nconst hasCounters = (pool: Partial<TarnPoolLike>): pool is TarnPoolLike =>\n typeof pool.numUsed === 'function' &&\n typeof pool.numFree === 'function' &&\n typeof pool.numPendingAcquires === 'function' &&\n typeof pool.numPendingCreates === 'function';\n\nexport const readPoolState = (\n pool: Partial<TarnPoolLike> | null | undefined\n): PoolState | undefined => {\n // knex also accepts a pool that only has acquire, release and destroy\n if (!pool || !hasCounters(pool)) {\n return undefined;\n }\n\n return {\n used: pool.numUsed(),\n free: pool.numFree(),\n pendingAcquires: pool.numPendingAcquires(),\n pendingCreates: pool.numPendingCreates(),\n min: asNumber(pool.min),\n max: asNumber(pool.max),\n };\n};\n\nexport const collectPoolTimeoutDetails = (\n client: KnexClientLike,\n input: CollectInput\n): PoolTimeoutDetails => {\n const config = client.config ?? {};\n\n return {\n code: POOL_TIMEOUT_CODE,\n waitedMs: input.waitedMs,\n // knex writes the effective (smaller) timeout into the tarn pool options\n acquireTimeoutMs: asNumber(client.pool?.acquireTimeoutMillis),\n acquireConnectionTimeout: asNumber(config.acquireConnectionTimeout),\n poolAcquireTimeoutMillis: asNumber(config.pool?.acquireTimeoutMillis),\n pool: readPoolState(client.pool),\n // knex 3.3 keeps tarn's error as `cause`; its message is all tarn keeps of a failed attempt\n poolReason: input.cause instanceof Error ? input.cause.message : undefined,\n eventLoopDelay: input.eventLoopDelay,\n phase: input.phase,\n hostname: input.hostname,\n pid: input.pid,\n };\n};\n"],"names":["POOL_TIMEOUT_CODE","asNumber","value","Number","isFinite","undefined","hasCounters","pool","numUsed","numFree","numPendingAcquires","numPendingCreates","readPoolState","used","free","pendingAcquires","pendingCreates","min","max","collectPoolTimeoutDetails","client","input","config","code","waitedMs","acquireTimeoutMs","acquireTimeoutMillis","acquireConnectionTimeout","poolAcquireTimeoutMillis","poolReason","cause","Error","message","eventLoopDelay","phase","hostname","pid"],"mappings":"AAEO,MAAMA,oBAAoB;AAuDjC,MAAMC,QAAAA,GAAW,CAACC,KAAAA,GAChB,OAAOA,KAAAA,KAAU,YAAYC,MAAAA,CAAOC,QAAQ,CAACF,KAAAA,CAAAA,GAASA,KAAAA,GAAQG,SAAAA;AAEhE,MAAMC,WAAAA,GAAc,CAACC,IAAAA,GACnB,OAAOA,KAAKC,OAAO,KAAK,cACxB,OAAOD,IAAAA,CAAKE,OAAO,KAAK,UAAA,IACxB,OAAOF,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;AACpCC,QAAAA,KAAAA,EAAOb,MAAMa,KAAK;AAClBC,QAAAA,QAAAA,EAAUd,MAAMc,QAAQ;AACxBC,QAAAA,GAAAA,EAAKf,MAAMe;AACb,KAAA;AACF;;;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Sampling interval of the event loop delay histogram. */
|
|
2
|
+
export declare const EVENT_LOOP_RESOLUTION_MS = 20;
|
|
3
|
+
/** Every rotation drops the older half, so a report covers the last 30 to 60 s. */
|
|
4
|
+
export declare const EVENT_LOOP_ROTATION_MS = 30000;
|
|
5
|
+
export interface EventLoopDelay {
|
|
6
|
+
/** Longest delay seen in the window, in ms, sampling interval removed. */
|
|
7
|
+
maxMs: number;
|
|
8
|
+
p99Ms: number;
|
|
9
|
+
/** Length of the window the values cover. */
|
|
10
|
+
windowMs: number;
|
|
11
|
+
}
|
|
12
|
+
export interface EventLoopMonitor {
|
|
13
|
+
read(): EventLoopDelay | undefined;
|
|
14
|
+
stop(): void;
|
|
15
|
+
}
|
|
16
|
+
export interface EventLoopMonitorOptions {
|
|
17
|
+
/** Injectable clock for tests. */
|
|
18
|
+
now?: () => number;
|
|
19
|
+
/** How often the older histogram is cleared and reused. */
|
|
20
|
+
rotateEveryMs?: number;
|
|
21
|
+
}
|
|
22
|
+
/** The histogram records the time between samples, so an idle loop reads one sampling interval. */
|
|
23
|
+
export declare const toDelayMs: (nanoseconds: number) => number;
|
|
24
|
+
/**
|
|
25
|
+
* A starved process fires timers late, so an acquire can time out even though the database
|
|
26
|
+
* answered. Two histograms take turns so a report covers the last one to two rotation periods,
|
|
27
|
+
* not everything since the process started. Neither the histograms nor the rotation timer keep
|
|
28
|
+
* the process alive.
|
|
29
|
+
*/
|
|
30
|
+
export declare const createEventLoopMonitor: ({ now, rotateEveryMs, }?: EventLoopMonitorOptions) => EventLoopMonitor;
|
|
31
|
+
//# sourceMappingURL=event-loop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-loop.d.ts","sourceRoot":"","sources":["../../src/pool-diagnostics/event-loop.ts"],"names":[],"mappings":"AAEA,2DAA2D;AAC3D,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAE3C,mFAAmF;AACnF,eAAO,MAAM,sBAAsB,QAAS,CAAC;AAE7C,MAAM,WAAW,cAAc;IAC7B,0EAA0E;IAC1E,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,IAAI,cAAc,GAAG,SAAS,CAAC;IACnC,IAAI,IAAI,IAAI,CAAC;CACd;AAED,MAAM,WAAW,uBAAuB;IACtC,kCAAkC;IAClC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,2DAA2D;IAC3D,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,mGAAmG;AACnG,eAAO,MAAM,SAAS,GAAI,aAAa,MAAM,KAAG,MACuB,CAAC;AAQxE;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,GAAI,0BAGpC,uBAA4B,KAAG,gBAmCjC,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node_perf_hooks = require('node:perf_hooks');
|
|
4
|
+
|
|
5
|
+
/** Sampling interval of the event loop delay histogram. */ const EVENT_LOOP_RESOLUTION_MS = 20;
|
|
6
|
+
/** Every rotation drops the older half, so a report covers the last 30 to 60 s. */ const EVENT_LOOP_ROTATION_MS = 30000;
|
|
7
|
+
/** The histogram records the time between samples, so an idle loop reads one sampling interval. */ const toDelayMs = (nanoseconds)=>Math.max(0, Math.round(nanoseconds / 1e6 - EVENT_LOOP_RESOLUTION_MS));
|
|
8
|
+
const startHistogram = ()=>{
|
|
9
|
+
const histogram = node_perf_hooks.monitorEventLoopDelay({
|
|
10
|
+
resolution: EVENT_LOOP_RESOLUTION_MS
|
|
11
|
+
});
|
|
12
|
+
histogram.enable();
|
|
13
|
+
return histogram;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* A starved process fires timers late, so an acquire can time out even though the database
|
|
17
|
+
* answered. Two histograms take turns so a report covers the last one to two rotation periods,
|
|
18
|
+
* not everything since the process started. Neither the histograms nor the rotation timer keep
|
|
19
|
+
* the process alive.
|
|
20
|
+
*/ const createEventLoopMonitor = ({ now = ()=>Date.now(), rotateEveryMs = EVENT_LOOP_ROTATION_MS } = {})=>{
|
|
21
|
+
let older = startHistogram();
|
|
22
|
+
let newer = startHistogram();
|
|
23
|
+
let olderStartedAt = now();
|
|
24
|
+
let newerStartedAt = olderStartedAt;
|
|
25
|
+
const rotate = ()=>{
|
|
26
|
+
older.reset();
|
|
27
|
+
[older, newer] = [
|
|
28
|
+
newer,
|
|
29
|
+
older
|
|
30
|
+
];
|
|
31
|
+
olderStartedAt = newerStartedAt;
|
|
32
|
+
newerStartedAt = now();
|
|
33
|
+
};
|
|
34
|
+
const timer = setInterval(rotate, rotateEveryMs);
|
|
35
|
+
timer.unref();
|
|
36
|
+
return {
|
|
37
|
+
read () {
|
|
38
|
+
if (older.count === 0) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
maxMs: toDelayMs(older.max),
|
|
43
|
+
p99Ms: toDelayMs(older.percentile(99)),
|
|
44
|
+
windowMs: now() - olderStartedAt
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
stop () {
|
|
48
|
+
clearInterval(timer);
|
|
49
|
+
older.disable();
|
|
50
|
+
newer.disable();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
exports.EVENT_LOOP_RESOLUTION_MS = EVENT_LOOP_RESOLUTION_MS;
|
|
56
|
+
exports.EVENT_LOOP_ROTATION_MS = EVENT_LOOP_ROTATION_MS;
|
|
57
|
+
exports.createEventLoopMonitor = createEventLoopMonitor;
|
|
58
|
+
exports.toDelayMs = toDelayMs;
|
|
59
|
+
//# sourceMappingURL=event-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-loop.js","sources":["../../src/pool-diagnostics/event-loop.ts"],"sourcesContent":["import { monitorEventLoopDelay, type IntervalHistogram } from 'node:perf_hooks';\n\n/** Sampling interval of the event loop delay histogram. */\nexport const EVENT_LOOP_RESOLUTION_MS = 20;\n\n/** Every rotation drops the older half, so a report covers the last 30 to 60 s. */\nexport const EVENT_LOOP_ROTATION_MS = 30_000;\n\nexport interface EventLoopDelay {\n /** Longest delay seen in the window, in ms, sampling interval removed. */\n maxMs: number;\n p99Ms: number;\n /** Length of the window the values cover. */\n windowMs: number;\n}\n\nexport interface EventLoopMonitor {\n read(): EventLoopDelay | undefined;\n stop(): void;\n}\n\nexport interface EventLoopMonitorOptions {\n /** Injectable clock for tests. */\n now?: () => number;\n /** How often the older histogram is cleared and reused. */\n rotateEveryMs?: number;\n}\n\n/** The histogram records the time between samples, so an idle loop reads one sampling interval. */\nexport const toDelayMs = (nanoseconds: number): number =>\n Math.max(0, Math.round(nanoseconds / 1e6 - EVENT_LOOP_RESOLUTION_MS));\n\nconst startHistogram = (): IntervalHistogram => {\n const histogram = monitorEventLoopDelay({ resolution: EVENT_LOOP_RESOLUTION_MS });\n histogram.enable();\n return histogram;\n};\n\n/**\n * A starved process fires timers late, so an acquire can time out even though the database\n * answered. Two histograms take turns so a report covers the last one to two rotation periods,\n * not everything since the process started. Neither the histograms nor the rotation timer keep\n * the process alive.\n */\nexport const createEventLoopMonitor = ({\n now = () => Date.now(),\n rotateEveryMs = EVENT_LOOP_ROTATION_MS,\n}: EventLoopMonitorOptions = {}): EventLoopMonitor => {\n let older = startHistogram();\n let newer = startHistogram();\n let olderStartedAt = now();\n let newerStartedAt = olderStartedAt;\n\n const rotate = () => {\n older.reset();\n [older, newer] = [newer, older];\n olderStartedAt = newerStartedAt;\n newerStartedAt = now();\n };\n\n const timer = setInterval(rotate, rotateEveryMs);\n timer.unref();\n\n return {\n read() {\n if (older.count === 0) {\n return undefined;\n }\n\n return {\n maxMs: toDelayMs(older.max),\n p99Ms: toDelayMs(older.percentile(99)),\n windowMs: now() - olderStartedAt,\n };\n },\n\n stop() {\n clearInterval(timer);\n older.disable();\n newer.disable();\n },\n };\n};\n"],"names":["EVENT_LOOP_RESOLUTION_MS","EVENT_LOOP_ROTATION_MS","toDelayMs","nanoseconds","Math","max","round","startHistogram","histogram","monitorEventLoopDelay","resolution","enable","createEventLoopMonitor","now","Date","rotateEveryMs","older","newer","olderStartedAt","newerStartedAt","rotate","reset","timer","setInterval","unref","read","count","undefined","maxMs","p99Ms","percentile","windowMs","stop","clearInterval","disable"],"mappings":";;;;AAEA,4DACO,MAAMA,wBAAAA,GAA2B;AAExC,oFACO,MAAMC,sBAAAA,GAAyB;AAsBtC,oGACO,MAAMC,SAAAA,GAAY,CAACC,WAAAA,GACxBC,IAAAA,CAAKC,GAAG,CAAC,GAAGD,IAAAA,CAAKE,KAAK,CAACH,WAAAA,GAAc,MAAMH,wBAAAA,CAAAA;AAE7C,MAAMO,cAAAA,GAAiB,IAAA;AACrB,IAAA,MAAMC,YAAYC,qCAAAA,CAAsB;QAAEC,UAAAA,EAAYV;AAAyB,KAAA,CAAA;AAC/EQ,IAAAA,SAAAA,CAAUG,MAAM,EAAA;IAChB,OAAOH,SAAAA;AACT,CAAA;AAEA;;;;;AAKC,IACM,MAAMI,sBAAAA,GAAyB,CAAC,EACrCC,MAAM,IAAMC,IAAAA,CAAKD,GAAG,EAAE,EACtBE,aAAAA,GAAgBd,sBAAsB,EACd,GAAG,EAAE,GAAA;AAC7B,IAAA,IAAIe,KAAAA,GAAQT,cAAAA,EAAAA;AACZ,IAAA,IAAIU,KAAAA,GAAQV,cAAAA,EAAAA;AACZ,IAAA,IAAIW,cAAAA,GAAiBL,GAAAA,EAAAA;AACrB,IAAA,IAAIM,cAAAA,GAAiBD,cAAAA;AAErB,IAAA,MAAME,MAAAA,GAAS,IAAA;AACbJ,QAAAA,KAAAA,CAAMK,KAAK,EAAA;QACX,CAACL,KAAAA,EAAOC,MAAM,GAAG;AAACA,YAAAA,KAAAA;AAAOD,YAAAA;AAAM,SAAA;QAC/BE,cAAAA,GAAiBC,cAAAA;QACjBA,cAAAA,GAAiBN,GAAAA,EAAAA;AACnB,IAAA,CAAA;IAEA,MAAMS,KAAAA,GAAQC,YAAYH,MAAAA,EAAQL,aAAAA,CAAAA;AAClCO,IAAAA,KAAAA,CAAME,KAAK,EAAA;IAEX,OAAO;AACLC,QAAAA,IAAAA,CAAAA,GAAAA;YACE,IAAIT,KAAAA,CAAMU,KAAK,KAAK,CAAA,EAAG;gBACrB,OAAOC,SAAAA;AACT,YAAA;YAEA,OAAO;gBACLC,KAAAA,EAAO1B,SAAAA,CAAUc,MAAMX,GAAG,CAAA;gBAC1BwB,KAAAA,EAAO3B,SAAAA,CAAUc,KAAAA,CAAMc,UAAU,CAAC,EAAA,CAAA,CAAA;AAClCC,gBAAAA,QAAAA,EAAUlB,GAAAA,EAAAA,GAAQK;AACpB,aAAA;AACF,QAAA,CAAA;AAEAc,QAAAA,IAAAA,CAAAA,GAAAA;YACEC,aAAAA,CAAcX,KAAAA,CAAAA;AACdN,YAAAA,KAAAA,CAAMkB,OAAO,EAAA;AACbjB,YAAAA,KAAAA,CAAMiB,OAAO,EAAA;AACf,QAAA;AACF,KAAA;AACF;;;;;;;"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { monitorEventLoopDelay } from 'node:perf_hooks';
|
|
2
|
+
|
|
3
|
+
/** Sampling interval of the event loop delay histogram. */ const EVENT_LOOP_RESOLUTION_MS = 20;
|
|
4
|
+
/** Every rotation drops the older half, so a report covers the last 30 to 60 s. */ const EVENT_LOOP_ROTATION_MS = 30000;
|
|
5
|
+
/** The histogram records the time between samples, so an idle loop reads one sampling interval. */ const toDelayMs = (nanoseconds)=>Math.max(0, Math.round(nanoseconds / 1e6 - EVENT_LOOP_RESOLUTION_MS));
|
|
6
|
+
const startHistogram = ()=>{
|
|
7
|
+
const histogram = monitorEventLoopDelay({
|
|
8
|
+
resolution: EVENT_LOOP_RESOLUTION_MS
|
|
9
|
+
});
|
|
10
|
+
histogram.enable();
|
|
11
|
+
return histogram;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A starved process fires timers late, so an acquire can time out even though the database
|
|
15
|
+
* answered. Two histograms take turns so a report covers the last one to two rotation periods,
|
|
16
|
+
* not everything since the process started. Neither the histograms nor the rotation timer keep
|
|
17
|
+
* the process alive.
|
|
18
|
+
*/ const createEventLoopMonitor = ({ now = ()=>Date.now(), rotateEveryMs = EVENT_LOOP_ROTATION_MS } = {})=>{
|
|
19
|
+
let older = startHistogram();
|
|
20
|
+
let newer = startHistogram();
|
|
21
|
+
let olderStartedAt = now();
|
|
22
|
+
let newerStartedAt = olderStartedAt;
|
|
23
|
+
const rotate = ()=>{
|
|
24
|
+
older.reset();
|
|
25
|
+
[older, newer] = [
|
|
26
|
+
newer,
|
|
27
|
+
older
|
|
28
|
+
];
|
|
29
|
+
olderStartedAt = newerStartedAt;
|
|
30
|
+
newerStartedAt = now();
|
|
31
|
+
};
|
|
32
|
+
const timer = setInterval(rotate, rotateEveryMs);
|
|
33
|
+
timer.unref();
|
|
34
|
+
return {
|
|
35
|
+
read () {
|
|
36
|
+
if (older.count === 0) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
maxMs: toDelayMs(older.max),
|
|
41
|
+
p99Ms: toDelayMs(older.percentile(99)),
|
|
42
|
+
windowMs: now() - olderStartedAt
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
stop () {
|
|
46
|
+
clearInterval(timer);
|
|
47
|
+
older.disable();
|
|
48
|
+
newer.disable();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { EVENT_LOOP_RESOLUTION_MS, EVENT_LOOP_ROTATION_MS, createEventLoopMonitor, toDelayMs };
|
|
54
|
+
//# sourceMappingURL=event-loop.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-loop.mjs","sources":["../../src/pool-diagnostics/event-loop.ts"],"sourcesContent":["import { monitorEventLoopDelay, type IntervalHistogram } from 'node:perf_hooks';\n\n/** Sampling interval of the event loop delay histogram. */\nexport const EVENT_LOOP_RESOLUTION_MS = 20;\n\n/** Every rotation drops the older half, so a report covers the last 30 to 60 s. */\nexport const EVENT_LOOP_ROTATION_MS = 30_000;\n\nexport interface EventLoopDelay {\n /** Longest delay seen in the window, in ms, sampling interval removed. */\n maxMs: number;\n p99Ms: number;\n /** Length of the window the values cover. */\n windowMs: number;\n}\n\nexport interface EventLoopMonitor {\n read(): EventLoopDelay | undefined;\n stop(): void;\n}\n\nexport interface EventLoopMonitorOptions {\n /** Injectable clock for tests. */\n now?: () => number;\n /** How often the older histogram is cleared and reused. */\n rotateEveryMs?: number;\n}\n\n/** The histogram records the time between samples, so an idle loop reads one sampling interval. */\nexport const toDelayMs = (nanoseconds: number): number =>\n Math.max(0, Math.round(nanoseconds / 1e6 - EVENT_LOOP_RESOLUTION_MS));\n\nconst startHistogram = (): IntervalHistogram => {\n const histogram = monitorEventLoopDelay({ resolution: EVENT_LOOP_RESOLUTION_MS });\n histogram.enable();\n return histogram;\n};\n\n/**\n * A starved process fires timers late, so an acquire can time out even though the database\n * answered. Two histograms take turns so a report covers the last one to two rotation periods,\n * not everything since the process started. Neither the histograms nor the rotation timer keep\n * the process alive.\n */\nexport const createEventLoopMonitor = ({\n now = () => Date.now(),\n rotateEveryMs = EVENT_LOOP_ROTATION_MS,\n}: EventLoopMonitorOptions = {}): EventLoopMonitor => {\n let older = startHistogram();\n let newer = startHistogram();\n let olderStartedAt = now();\n let newerStartedAt = olderStartedAt;\n\n const rotate = () => {\n older.reset();\n [older, newer] = [newer, older];\n olderStartedAt = newerStartedAt;\n newerStartedAt = now();\n };\n\n const timer = setInterval(rotate, rotateEveryMs);\n timer.unref();\n\n return {\n read() {\n if (older.count === 0) {\n return undefined;\n }\n\n return {\n maxMs: toDelayMs(older.max),\n p99Ms: toDelayMs(older.percentile(99)),\n windowMs: now() - olderStartedAt,\n };\n },\n\n stop() {\n clearInterval(timer);\n older.disable();\n newer.disable();\n },\n };\n};\n"],"names":["EVENT_LOOP_RESOLUTION_MS","EVENT_LOOP_ROTATION_MS","toDelayMs","nanoseconds","Math","max","round","startHistogram","histogram","monitorEventLoopDelay","resolution","enable","createEventLoopMonitor","now","Date","rotateEveryMs","older","newer","olderStartedAt","newerStartedAt","rotate","reset","timer","setInterval","unref","read","count","undefined","maxMs","p99Ms","percentile","windowMs","stop","clearInterval","disable"],"mappings":";;AAEA,4DACO,MAAMA,wBAAAA,GAA2B;AAExC,oFACO,MAAMC,sBAAAA,GAAyB;AAsBtC,oGACO,MAAMC,SAAAA,GAAY,CAACC,WAAAA,GACxBC,IAAAA,CAAKC,GAAG,CAAC,GAAGD,IAAAA,CAAKE,KAAK,CAACH,WAAAA,GAAc,MAAMH,wBAAAA,CAAAA;AAE7C,MAAMO,cAAAA,GAAiB,IAAA;AACrB,IAAA,MAAMC,YAAYC,qBAAAA,CAAsB;QAAEC,UAAAA,EAAYV;AAAyB,KAAA,CAAA;AAC/EQ,IAAAA,SAAAA,CAAUG,MAAM,EAAA;IAChB,OAAOH,SAAAA;AACT,CAAA;AAEA;;;;;AAKC,IACM,MAAMI,sBAAAA,GAAyB,CAAC,EACrCC,MAAM,IAAMC,IAAAA,CAAKD,GAAG,EAAE,EACtBE,aAAAA,GAAgBd,sBAAsB,EACd,GAAG,EAAE,GAAA;AAC7B,IAAA,IAAIe,KAAAA,GAAQT,cAAAA,EAAAA;AACZ,IAAA,IAAIU,KAAAA,GAAQV,cAAAA,EAAAA;AACZ,IAAA,IAAIW,cAAAA,GAAiBL,GAAAA,EAAAA;AACrB,IAAA,IAAIM,cAAAA,GAAiBD,cAAAA;AAErB,IAAA,MAAME,MAAAA,GAAS,IAAA;AACbJ,QAAAA,KAAAA,CAAMK,KAAK,EAAA;QACX,CAACL,KAAAA,EAAOC,MAAM,GAAG;AAACA,YAAAA,KAAAA;AAAOD,YAAAA;AAAM,SAAA;QAC/BE,cAAAA,GAAiBC,cAAAA;QACjBA,cAAAA,GAAiBN,GAAAA,EAAAA;AACnB,IAAA,CAAA;IAEA,MAAMS,KAAAA,GAAQC,YAAYH,MAAAA,EAAQL,aAAAA,CAAAA;AAClCO,IAAAA,KAAAA,CAAME,KAAK,EAAA;IAEX,OAAO;AACLC,QAAAA,IAAAA,CAAAA,GAAAA;YACE,IAAIT,KAAAA,CAAMU,KAAK,KAAK,CAAA,EAAG;gBACrB,OAAOC,SAAAA;AACT,YAAA;YAEA,OAAO;gBACLC,KAAAA,EAAO1B,SAAAA,CAAUc,MAAMX,GAAG,CAAA;gBAC1BwB,KAAAA,EAAO3B,SAAAA,CAAUc,KAAAA,CAAMc,UAAU,CAAC,EAAA,CAAA,CAAA;AAClCC,gBAAAA,QAAAA,EAAUlB,GAAAA,EAAAA,GAAQK;AACpB,aAAA;AACF,QAAA,CAAA;AAEAc,QAAAA,IAAAA,CAAAA,GAAAA;YACEC,aAAAA,CAAcX,KAAAA,CAAAA;AACdN,YAAAA,KAAAA,CAAMkB,OAAO,EAAA;AACbjB,YAAAA,KAAAA,CAAMiB,OAAO,EAAA;AACf,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PoolTimeoutDetails } from './details';
|
|
2
|
+
/** Where the error and the warning point readers. The only place the URL lives. */
|
|
3
|
+
export declare const POOL_TIMEOUT_DOCS_URL = "https://docs.strapi.io/cms/configurations/database#connection-pool-timeouts";
|
|
4
|
+
export declare const appendDocsLink: (message: string) => string;
|
|
5
|
+
/** Facts only, one bullet per fact, in the house style of multi-line warnings. */
|
|
6
|
+
export declare const formatPoolTimeoutWarning: (details: PoolTimeoutDetails, { suppressed }: {
|
|
7
|
+
suppressed: number;
|
|
8
|
+
}) => string;
|
|
9
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/pool-diagnostics/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEpD,mFAAmF;AACnF,eAAO,MAAM,qBAAqB,gFAC6C,CAAC;AAEhF,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,KAAG,MAC+C,CAAC;AAQjG,kFAAkF;AAClF,eAAO,MAAM,wBAAwB,GACnC,SAAS,kBAAkB,EAC3B,gBAAgB;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,KACrC,MAsDF,CAAC"}
|