@memberjunction/testing-integration 6.3.0-edge.0 → 6.3.0-edge.1

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.js CHANGED
@@ -25,6 +25,8 @@ export * from './fls-fixture.js';
25
25
  // every bundle on this registry. This framework package deliberately ships content-free.
26
26
  export * from './types.js';
27
27
  export * from './IntegrationTestDriver.js';
28
+ export * from './perf-profiler.js';
29
+ export * from './perf-harness.js';
28
30
  // The @RegisterClass decorator on IntegrationTestDriver fires via the export above.
29
31
  //
30
32
  // This block used to also re-export the bundle arrays and the RunQuery fixture helpers
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,yFAAyF;AACzF,6FAA6F;AAC7F,2FAA2F;AAC3F,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,OAAO,0BAA0B,CAAC,CAAC,0DAA0D;AAC7F,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,sEAAsE;AACtE,oFAAoF;AACpF,yFAAyF;AACzF,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC;AAExC,oFAAoF;AACpF,EAAE;AACF,uFAAuF;AACvF,2FAA2F;AAC3F,yFAAyF;AACzF,kFAAkF;AAClF,2FAA2F;AAC3F,gEAAgE;AAEhE;;;GAGG;AACH,MAAM,UAAU,sBAAsB;IAClC,sDAAsD;AAC1D,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,yFAAyF;AACzF,6FAA6F;AAC7F,2FAA2F;AAC3F,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,OAAO,0BAA0B,CAAC,CAAC,0DAA0D;AAC7F,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,sEAAsE;AACtE,oFAAoF;AACpF,yFAAyF;AACzF,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAE/B,oFAAoF;AACpF,EAAE;AACF,uFAAuF;AACvF,2FAA2F;AAC3F,yFAAyF;AACzF,kFAAkF;AAClF,2FAA2F;AAC3F,gEAAgE;AAEhE;;;GAGG;AACH,MAAM,UAAU,sBAAsB;IAClC,sDAAsD;AAC1D,CAAC"}
@@ -0,0 +1,149 @@
1
+ /**
2
+ * A single measured performance sample to evaluate against a baseline profile.
3
+ */
4
+ export interface PerfMetricSample {
5
+ Name: string;
6
+ Unit: string;
7
+ Value: number;
8
+ IsAggregate?: boolean;
9
+ WarnMultiplier?: number;
10
+ FailMultiplier?: number;
11
+ BaselineValue?: number;
12
+ }
13
+ /**
14
+ * A deterministic structural or invariant assertion evaluated alongside timing metrics.
15
+ */
16
+ export interface PerfStructuralAssertion {
17
+ Name: string;
18
+ Passed: boolean;
19
+ Message: string;
20
+ }
21
+ /**
22
+ * Regression gate thresholds governing WARN and FAIL classification for timing metrics.
23
+ */
24
+ export interface PerfGateThresholds {
25
+ MaxTimingRegressionPercentWarn: number;
26
+ MaxTimingRegressionMultiplierFail: number;
27
+ MinAbsoluteTimingDeltaMsWarn: number;
28
+ MinAbsoluteTimingDeltaMsFailLocal: number;
29
+ MinAbsoluteTimingDeltaMsFailCI: number;
30
+ }
31
+ /**
32
+ * A committed baseline profile (local or CI) storing reference metric values.
33
+ */
34
+ export interface PerfBaselineProfile {
35
+ Runner: string;
36
+ Timestamp: string;
37
+ Commit: string;
38
+ Database?: string;
39
+ AggregateValue?: number;
40
+ Metrics: Record<string, number>;
41
+ }
42
+ /**
43
+ * A historical snapshot archived before updating a baseline profile.
44
+ */
45
+ export interface PerfHistoricalSnapshot {
46
+ Commit: string;
47
+ Timestamp: string;
48
+ Metrics: Record<string, number>;
49
+ }
50
+ /**
51
+ * Committed baseline document containing local/CI profiles, historical snapshots, and gate thresholds.
52
+ */
53
+ export interface PerfBaselineDocument {
54
+ Version: number;
55
+ HistoricalSnapshots?: Record<string, PerfHistoricalSnapshot>;
56
+ Baseline: PerfBaselineProfile;
57
+ CIBaseline?: PerfBaselineProfile;
58
+ Gates: PerfGateThresholds;
59
+ }
60
+ /**
61
+ * Evaluation result for a single metric sample compared against its baseline.
62
+ */
63
+ export interface PerfComparisonRow {
64
+ Metric: string;
65
+ Unit: string;
66
+ Baseline: number;
67
+ Current: number;
68
+ DeltaPercent: number;
69
+ Status: 'IMPROVED' | 'PASS' | 'WARN' | 'FAIL';
70
+ }
71
+ /**
72
+ * Full evaluation summary produced by {@link PerfBenchmarkHarness.EvaluateMetrics}.
73
+ */
74
+ export interface PerfSuiteEvaluation {
75
+ ProfileName: 'local' | 'ci';
76
+ Runner: string;
77
+ Timestamp: string;
78
+ AggregateBaseline: number;
79
+ AggregateCurrent: number;
80
+ AggregateSlownessFactor: number;
81
+ Rows: PerfComparisonRow[];
82
+ FailedRows: PerfComparisonRow[];
83
+ WarnRows: PerfComparisonRow[];
84
+ SummaryMarkdown: string;
85
+ }
86
+ /**
87
+ * Options for updating a {@link PerfBaselineDocument} from a new set of metric samples.
88
+ */
89
+ export interface UpdatePerfBaselineOptions {
90
+ Target: 'local' | 'ci';
91
+ Commit: string;
92
+ RunnerLabel?: string;
93
+ Database?: string;
94
+ ArchivePreviousAs?: string;
95
+ }
96
+ /**
97
+ * Options for {@link PerfBenchmarkHarness.EvaluateMetrics}.
98
+ */
99
+ export interface EvaluatePerfMetricsOptions {
100
+ Env?: NodeJS.ProcessEnv;
101
+ StrictTiming?: boolean;
102
+ }
103
+ /**
104
+ * Paths of the benchmark artifacts written by {@link PerfBenchmarkHarness.WriteArtifacts}.
105
+ */
106
+ export interface PerfArtifactPaths {
107
+ LatestJsonPath: string;
108
+ LatestMarkdownPath: string;
109
+ HistoryJsonlPath: string;
110
+ }
111
+ /**
112
+ * Reusable performance benchmark evaluation, regression gating, artifact persistence,
113
+ * and baseline management harness for MemberJunction applications and packages.
114
+ */
115
+ export declare class PerfBenchmarkHarness {
116
+ /**
117
+ * Selects the active baseline profile (`ci` or `local`) based on environment variables
118
+ * and whether `doc.CIBaseline` is populated.
119
+ */
120
+ static SelectActiveProfile(doc: PerfBaselineDocument, env?: NodeJS.ProcessEnv): {
121
+ Name: 'local' | 'ci';
122
+ Profile: PerfBaselineProfile;
123
+ };
124
+ /**
125
+ * Evaluates measured {@link PerfMetricSample} values against a {@link PerfBaselineDocument},
126
+ * computing per-metric deltas, statuses (`IMPROVED` | `PASS` | `WARN` | `FAIL`), aggregate
127
+ * slowness factor, and a formatted Markdown summary table.
128
+ */
129
+ static EvaluateMetrics(samples: ReadonlyArray<PerfMetricSample>, doc: PerfBaselineDocument, options?: EvaluatePerfMetricsOptions): PerfSuiteEvaluation;
130
+ /**
131
+ * Asserts that all structural assertions passed and no metric rows were classified as `FAIL`.
132
+ */
133
+ static AssertEvaluationPassed(evaluation: PerfSuiteEvaluation, structuralAssertions?: ReadonlyArray<PerfStructuralAssertion>): void;
134
+ /**
135
+ * Loads and parses a {@link PerfBaselineDocument} JSON file directly inside a `try/catch` block.
136
+ */
137
+ static LoadBaselineDocument(filePath: string): PerfBaselineDocument;
138
+ /**
139
+ * Persists `latest.json`, `latest.md`, and appends a line to `history.jsonl` inside `outputDir`.
140
+ */
141
+ static WriteArtifacts(outputDir: string, evaluation: PerfSuiteEvaluation, extraMetadata?: Record<string, string | number | boolean>): PerfArtifactPaths;
142
+ /**
143
+ * Returns a new {@link PerfBaselineDocument} with the target profile (`local` or `ci`) updated
144
+ * from `samples`, optionally archiving the previous profile into `HistoricalSnapshots`.
145
+ */
146
+ static UpdateBaselineDocument(doc: PerfBaselineDocument, samples: ReadonlyArray<PerfMetricSample>, options: UpdatePerfBaselineOptions): PerfBaselineDocument;
147
+ private static formatMarkdown;
148
+ }
149
+ //# sourceMappingURL=perf-harness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"perf-harness.d.ts","sourceRoot":"","sources":["../src/perf-harness.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,8BAA8B,EAAE,MAAM,CAAC;IACvC,iCAAiC,EAAE,MAAM,CAAC;IAC1C,4BAA4B,EAAE,MAAM,CAAC;IACrC,iCAAiC,EAAE,MAAM,CAAC;IAC1C,8BAA8B,EAAE,MAAM,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,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GG;WACW,sBAAsB,CAChC,GAAG,EAAE,oBAAoB,EACzB,OAAO,EAAE,aAAa,CAAC,gBAAgB,CAAC,EACxC,OAAO,EAAE,yBAAyB,GACnC,oBAAoB;IAiDvB,OAAO,CAAC,MAAM,CAAC,cAAc;CA8BhC"}
@@ -0,0 +1,211 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { Assert } from './test-runner.js';
4
+ /**
5
+ * Reusable performance benchmark evaluation, regression gating, artifact persistence,
6
+ * and baseline management harness for MemberJunction applications and packages.
7
+ */
8
+ export class PerfBenchmarkHarness {
9
+ /**
10
+ * Selects the active baseline profile (`ci` or `local`) based on environment variables
11
+ * and whether `doc.CIBaseline` is populated.
12
+ */
13
+ static SelectActiveProfile(doc, env = process.env) {
14
+ const useCI = (env.GITHUB_ACTIONS === 'true' || env.MJ_PERF_PROFILE === 'ci') &&
15
+ env.MJ_PERF_PROFILE !== 'local' &&
16
+ Boolean(doc.CIBaseline);
17
+ if (useCI && doc.CIBaseline) {
18
+ return { Name: 'ci', Profile: doc.CIBaseline };
19
+ }
20
+ return { Name: 'local', Profile: doc.Baseline };
21
+ }
22
+ /**
23
+ * Evaluates measured {@link PerfMetricSample} values against a {@link PerfBaselineDocument},
24
+ * computing per-metric deltas, statuses (`IMPROVED` | `PASS` | `WARN` | `FAIL`), aggregate
25
+ * slowness factor, and a formatted Markdown summary table.
26
+ */
27
+ static EvaluateMetrics(samples, doc, options) {
28
+ const env = options?.Env ?? process.env;
29
+ const strictTiming = options?.StrictTiming ?? env.MJ_PERF_STRICT_TIMING === '1';
30
+ const { Name: profileName, Profile: activeProfile } = PerfBenchmarkHarness.SelectActiveProfile(doc, env);
31
+ const gates = doc.Gates;
32
+ const minFailDeltaMs = profileName === 'ci' ? gates.MinAbsoluteTimingDeltaMsFailCI : gates.MinAbsoluteTimingDeltaMsFailLocal;
33
+ const rows = samples.map((sample) => {
34
+ const base = sample.BaselineValue ?? activeProfile.Metrics[sample.Name] ?? 0;
35
+ const cur = sample.Value;
36
+ const deltaPct = base > 0 ? Number((((cur - base) / base) * 100).toFixed(1)) : 0;
37
+ const failMult = sample.FailMultiplier ?? gates.MaxTimingRegressionMultiplierFail;
38
+ const warnPct = sample.WarnMultiplier !== undefined
39
+ ? Number(((sample.WarnMultiplier - 1) * 100).toFixed(1))
40
+ : gates.MaxTimingRegressionPercentWarn;
41
+ let status = 'PASS';
42
+ if (deltaPct <= -10) {
43
+ status = 'IMPROVED';
44
+ }
45
+ else if (cur > base * failMult && cur - base > minFailDeltaMs) {
46
+ status = profileName === 'ci' && !sample.IsAggregate && !strictTiming ? 'WARN' : 'FAIL';
47
+ }
48
+ else if (deltaPct > warnPct && cur - base > gates.MinAbsoluteTimingDeltaMsWarn) {
49
+ status = strictTiming ? 'FAIL' : 'WARN';
50
+ }
51
+ return {
52
+ Metric: sample.Name,
53
+ Unit: sample.Unit,
54
+ Baseline: base,
55
+ Current: cur,
56
+ DeltaPercent: deltaPct,
57
+ Status: status,
58
+ };
59
+ });
60
+ const aggregateSamples = samples.filter((s) => s.IsAggregate === true);
61
+ const aggSource = aggregateSamples.length > 0 ? aggregateSamples : samples;
62
+ const aggregateCurrent = Number(aggSource.reduce((sum, s) => sum + s.Value, 0).toFixed(2));
63
+ const computedAggBaseline = Number(aggSource
64
+ .reduce((sum, s) => sum + (s.BaselineValue ?? activeProfile.Metrics[s.Name] ?? 0), 0)
65
+ .toFixed(2));
66
+ const aggregateBaseline = aggregateSamples.length > 0 && computedAggBaseline > 0
67
+ ? computedAggBaseline
68
+ : (activeProfile.AggregateValue ?? computedAggBaseline);
69
+ const aggregateSlownessFactor = aggregateBaseline > 0 ? Number((aggregateCurrent / aggregateBaseline).toFixed(2)) : 1;
70
+ const failedRows = rows.filter((r) => r.Status === 'FAIL');
71
+ const warnRows = rows.filter((r) => r.Status === 'WARN');
72
+ const timestamp = new Date().toISOString();
73
+ const summaryMarkdown = PerfBenchmarkHarness.formatMarkdown({
74
+ ProfileName: profileName,
75
+ Runner: activeProfile.Runner,
76
+ Timestamp: timestamp,
77
+ AggregateBaseline: aggregateBaseline,
78
+ AggregateCurrent: aggregateCurrent,
79
+ AggregateSlownessFactor: aggregateSlownessFactor,
80
+ Rows: rows,
81
+ });
82
+ return {
83
+ ProfileName: profileName,
84
+ Runner: activeProfile.Runner,
85
+ Timestamp: timestamp,
86
+ AggregateBaseline: aggregateBaseline,
87
+ AggregateCurrent: aggregateCurrent,
88
+ AggregateSlownessFactor: aggregateSlownessFactor,
89
+ Rows: rows,
90
+ FailedRows: failedRows,
91
+ WarnRows: warnRows,
92
+ SummaryMarkdown: summaryMarkdown,
93
+ };
94
+ }
95
+ /**
96
+ * Asserts that all structural assertions passed and no metric rows were classified as `FAIL`.
97
+ */
98
+ static AssertEvaluationPassed(evaluation, structuralAssertions) {
99
+ if (structuralAssertions) {
100
+ for (const assertion of structuralAssertions) {
101
+ Assert(assertion.Passed, `${assertion.Name}: ${assertion.Message}`);
102
+ }
103
+ }
104
+ Assert(evaluation.FailedRows.length === 0, `Performance regression gate failed on ${evaluation.FailedRows.length} metric(s): ${evaluation.FailedRows.map((r) => `${r.Metric} (current=${r.Current}${r.Unit}, baseline=${r.Baseline}${r.Unit}, delta=${r.DeltaPercent}%)`).join('; ')}`);
105
+ }
106
+ /**
107
+ * Loads and parses a {@link PerfBaselineDocument} JSON file directly inside a `try/catch` block.
108
+ */
109
+ static LoadBaselineDocument(filePath) {
110
+ let raw;
111
+ try {
112
+ raw = fs.readFileSync(filePath, 'utf8');
113
+ }
114
+ catch (err) {
115
+ const msg = err instanceof Error ? err.message : String(err);
116
+ throw new Error(`Failed to read performance baseline file at ${filePath}: ${msg}`);
117
+ }
118
+ try {
119
+ return JSON.parse(raw);
120
+ }
121
+ catch (err) {
122
+ const msg = err instanceof Error ? err.message : String(err);
123
+ throw new Error(`Failed to parse performance baseline JSON at ${filePath}: ${msg}`);
124
+ }
125
+ }
126
+ /**
127
+ * Persists `latest.json`, `latest.md`, and appends a line to `history.jsonl` inside `outputDir`.
128
+ */
129
+ static WriteArtifacts(outputDir, evaluation, extraMetadata) {
130
+ fs.mkdirSync(outputDir, { recursive: true });
131
+ const latestJsonPath = path.join(outputDir, 'latest.json');
132
+ const latestMarkdownPath = path.join(outputDir, 'latest.md');
133
+ const historyJsonlPath = path.join(outputDir, 'history.jsonl');
134
+ const jsonPayload = extraMetadata
135
+ ? { ...evaluation, Metadata: extraMetadata }
136
+ : evaluation;
137
+ fs.writeFileSync(latestJsonPath, JSON.stringify(jsonPayload, null, 2) + '\n', 'utf8');
138
+ fs.writeFileSync(latestMarkdownPath, evaluation.SummaryMarkdown, 'utf8');
139
+ fs.appendFileSync(historyJsonlPath, JSON.stringify(jsonPayload) + '\n', 'utf8');
140
+ return {
141
+ LatestJsonPath: latestJsonPath,
142
+ LatestMarkdownPath: latestMarkdownPath,
143
+ HistoryJsonlPath: historyJsonlPath,
144
+ };
145
+ }
146
+ /**
147
+ * Returns a new {@link PerfBaselineDocument} with the target profile (`local` or `ci`) updated
148
+ * from `samples`, optionally archiving the previous profile into `HistoricalSnapshots`.
149
+ */
150
+ static UpdateBaselineDocument(doc, samples, options) {
151
+ const metrics = {};
152
+ for (const sample of samples) {
153
+ metrics[sample.Name] = sample.Value;
154
+ }
155
+ const aggregateSamples = samples.filter((s) => s.IsAggregate === true);
156
+ const aggSource = aggregateSamples.length > 0 ? aggregateSamples : samples;
157
+ const aggregateValue = Number(aggSource.reduce((sum, s) => sum + s.Value, 0).toFixed(2));
158
+ const newProfile = {
159
+ Runner: options.RunnerLabel ?? (options.Target === 'ci' ? 'ubuntu-latest (GitHub Actions)' : 'Local Reference'),
160
+ Timestamp: new Date().toISOString(),
161
+ Commit: options.Commit,
162
+ ...(options.Database !== undefined ? { Database: options.Database } : {}),
163
+ AggregateValue: aggregateValue,
164
+ Metrics: metrics,
165
+ };
166
+ const historicalSnapshots = {
167
+ ...(doc.HistoricalSnapshots ?? {}),
168
+ };
169
+ if (options.ArchivePreviousAs) {
170
+ const previousProfile = options.Target === 'ci' ? doc.CIBaseline : doc.Baseline;
171
+ if (previousProfile) {
172
+ historicalSnapshots[options.ArchivePreviousAs] = {
173
+ Commit: previousProfile.Commit,
174
+ Timestamp: previousProfile.Timestamp,
175
+ Metrics: { ...previousProfile.Metrics },
176
+ };
177
+ }
178
+ }
179
+ const updatedDoc = {
180
+ Version: doc.Version,
181
+ ...(Object.keys(historicalSnapshots).length > 0 ? { HistoricalSnapshots: historicalSnapshots } : {}),
182
+ Baseline: options.Target === 'local' ? newProfile : { ...doc.Baseline, Metrics: { ...doc.Baseline.Metrics } },
183
+ ...(options.Target === 'ci'
184
+ ? { CIBaseline: newProfile }
185
+ : doc.CIBaseline
186
+ ? { CIBaseline: { ...doc.CIBaseline, Metrics: { ...doc.CIBaseline.Metrics } } }
187
+ : {}),
188
+ Gates: { ...doc.Gates },
189
+ };
190
+ return updatedDoc;
191
+ }
192
+ static formatMarkdown(input) {
193
+ const lines = [
194
+ `# Performance Benchmark Evaluation`,
195
+ ``,
196
+ `- **Profile**: \`${input.ProfileName}\` (${input.Runner})`,
197
+ `- **Timestamp**: \`${input.Timestamp}\``,
198
+ `- **Aggregate**: **${input.AggregateCurrent}** vs baseline **${input.AggregateBaseline}** (**${input.AggregateSlownessFactor}x**)`,
199
+ ``,
200
+ `| Metric | Unit | Baseline | Current | Delta | Status |`,
201
+ `|---|---|---:|---:|---:|---|`,
202
+ ];
203
+ for (const row of input.Rows) {
204
+ const deltaCell = `${row.DeltaPercent > 0 ? '+' : ''}${row.DeltaPercent}%`;
205
+ lines.push(`| **${row.Metric}** | \`${row.Unit}\` | ${row.Baseline} | **${row.Current}** | ${deltaCell} | **${row.Status}** |`);
206
+ }
207
+ lines.push('');
208
+ return lines.join('\n');
209
+ }
210
+ }
211
+ //# sourceMappingURL=perf-harness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"perf-harness.js","sourceRoot":"","sources":["../src/perf-harness.ts"],"names":[],"mappings":"AAAA,OAAO,EA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CAAC,gBAAgB,oBAAoB,KAAK,CAAC,iBAAiB,SAAS,KAAK,CAAC,uBAAuB,MAAM;YACnI,EAAE;YACF,yDAAyD;YACzD,8BAA8B;SACjC,CAAC;QAEF,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;YAC3B,MAAM,SAAS,GAAG,GAAG,GAAG,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,YAAY,GAAG,CAAC;YAC3E,KAAK,CAAC,IAAI,CACN,OAAO,GAAG,CAAC,MAAM,UAAU,GAAG,CAAC,IAAI,QAAQ,GAAG,CAAC,QAAQ,QAAQ,GAAG,CAAC,OAAO,QAAQ,SAAS,QAAQ,GAAG,CAAC,MAAM,MAAM,CACtH,CAAC;QACN,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;CACJ"}
@@ -0,0 +1,93 @@
1
+ import type { DatabaseProviderBase } from '@memberjunction/core';
2
+ /**
3
+ * A single SQL statement captured by {@link ProviderCallProfiler} during a profiled block.
4
+ */
5
+ export interface PerfSqlCaptureEntry {
6
+ Sql: string;
7
+ Kind: 'single' | 'batch';
8
+ DurationMs: number;
9
+ TimestampMs: number;
10
+ }
11
+ /**
12
+ * Aggregated database provider call and SQL statement metrics captured by {@link ProviderCallProfiler}.
13
+ */
14
+ export interface PerfCallMetrics {
15
+ SqlExecutions: number;
16
+ SqlBatches: number;
17
+ TotalSqlStatements: number;
18
+ CountOnlyQueries: number;
19
+ RunViewCalls: number;
20
+ RunViewsBatchCalls: number;
21
+ SaveCalls: number;
22
+ DeleteCalls: number;
23
+ DurationMs: number;
24
+ CapturedStatements: ReadonlyArray<PerfSqlCaptureEntry>;
25
+ }
26
+ /**
27
+ * Upper-bound call and SQL statement budgets enforced by {@link ProviderCallProfiler.AssertBudget}.
28
+ */
29
+ export interface PerfCallBudget {
30
+ MaxSqlExecutions?: number;
31
+ MaxTotalSqlStatements?: number;
32
+ MaxCountOnlyQueries?: number;
33
+ MaxRunViewCalls?: number;
34
+ MaxRunViewsBatchCalls?: number;
35
+ MaxSaveCalls?: number;
36
+ MaxDeleteCalls?: number;
37
+ MaxDurationMs?: number;
38
+ }
39
+ /**
40
+ * Non-invasive profiler that wraps a {@link DatabaseProviderBase} instance to count
41
+ * SQL executions, SQL batches, `SELECT COUNT(*)` queries, `RunView`/`RunViews`, `Save`,
42
+ * and `Delete` calls without altering provider behavior.
43
+ */
44
+ export declare class ProviderCallProfiler {
45
+ private readonly provider;
46
+ private originals;
47
+ private batchDepth;
48
+ private startTimeMs;
49
+ private sqlExecutions;
50
+ private sqlBatches;
51
+ private totalSqlStatements;
52
+ private countOnlyQueries;
53
+ private runViewCalls;
54
+ private runViewsBatchCalls;
55
+ private saveCalls;
56
+ private deleteCalls;
57
+ private capturedStatements;
58
+ constructor(provider: DatabaseProviderBase);
59
+ /**
60
+ * Patches the provider's query and persistence methods to record call metrics.
61
+ * Safe to call multiple times; subsequent calls while already attached are no-ops.
62
+ */
63
+ Attach(): void;
64
+ /**
65
+ * Restores the original methods on the wrapped provider. Safe to call when not attached.
66
+ */
67
+ Detach(): void;
68
+ /**
69
+ * Resets all captured counters and statements and restarts the elapsed timer.
70
+ */
71
+ Reset(): void;
72
+ /**
73
+ * Returns an immutable snapshot of the metrics captured since the last {@link Reset} or {@link Attach}.
74
+ */
75
+ Snapshot(): PerfCallMetrics;
76
+ /**
77
+ * Attaches the profiler, resets counters, executes `work`, captures a {@link Snapshot},
78
+ * and always restores the provider's original methods in a `finally` block.
79
+ */
80
+ Profile<T>(work: () => Promise<T>): Promise<{
81
+ Result: T;
82
+ Metrics: PerfCallMetrics;
83
+ }>;
84
+ /**
85
+ * Asserts that `metrics` satisfies every defined upper bound in `budget`.
86
+ */
87
+ AssertBudget(metrics: PerfCallMetrics, budget: PerfCallBudget, label: string): void;
88
+ /**
89
+ * Asserts that `metrics` satisfies every defined upper bound in `budget`.
90
+ */
91
+ static AssertBudget(metrics: PerfCallMetrics, budget: PerfCallBudget, label: string): void;
92
+ }
93
+ //# sourceMappingURL=perf-profiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"perf-profiler.d.ts","sourceRoot":"","sources":["../src/perf-profiler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAER,oBAAoB,EAOvB,MAAM,sBAAsB,CAAC;AAI9B;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAC;CAC1D;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B;AA2DD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