@blogmcp/mdx-codemods 0.1.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/index.d.ts +17 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/migrations.d.ts +26 -0
- package/dist/migrations.js +75 -0
- package/dist/migrations.js.map +1 -0
- package/dist/runner.d.ts +97 -0
- package/dist/runner.js +384 -0
- package/dist/runner.js.map +1 -0
- package/dist/types.d.ts +174 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/package.json +60 -0
- package/src/index.ts +18 -0
- package/src/migrations.ts +82 -0
- package/src/runner.ts +483 -0
- package/src/types.ts +188 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @blogmcp/mdx-codemods
|
|
3
|
+
*
|
|
4
|
+
* Storage-agnostic codemod runner for MDX article content. Consumers
|
|
5
|
+
* (the KB API graphile-worker task in PR 4) implement `CodemodStore`
|
|
6
|
+
* against `kb_articles_translations` + `mdx_codemod_errors` + tenant
|
|
7
|
+
* settings, then call `runMigrations({ targetVersion, migrations,
|
|
8
|
+
* store })` at app boot whenever `SCHEMA_VERSION > MAX(schema_version)`.
|
|
9
|
+
*
|
|
10
|
+
* See `competitor-monitor/docs/internal/optimistic-concurrency.md`
|
|
11
|
+
* for the write-path contract the store must implement, and the plan
|
|
12
|
+
* file's "PR 3" / "Codemod runner" sections for the architectural
|
|
13
|
+
* design.
|
|
14
|
+
*/
|
|
15
|
+
export * from './types.js';
|
|
16
|
+
export * from './runner.js';
|
|
17
|
+
export * from './migrations.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @blogmcp/mdx-codemods
|
|
3
|
+
*
|
|
4
|
+
* Storage-agnostic codemod runner for MDX article content. Consumers
|
|
5
|
+
* (the KB API graphile-worker task in PR 4) implement `CodemodStore`
|
|
6
|
+
* against `kb_articles_translations` + `mdx_codemod_errors` + tenant
|
|
7
|
+
* settings, then call `runMigrations({ targetVersion, migrations,
|
|
8
|
+
* store })` at app boot whenever `SCHEMA_VERSION > MAX(schema_version)`.
|
|
9
|
+
*
|
|
10
|
+
* See `competitor-monitor/docs/internal/optimistic-concurrency.md`
|
|
11
|
+
* for the write-path contract the store must implement, and the plan
|
|
12
|
+
* file's "PR 3" / "Codemod runner" sections for the architectural
|
|
13
|
+
* design.
|
|
14
|
+
*/
|
|
15
|
+
export * from './types.js';
|
|
16
|
+
export * from './runner.js';
|
|
17
|
+
export * from './migrations.js';
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static migration registry.
|
|
3
|
+
*
|
|
4
|
+
* Each migration is a TypeScript file in `src/migrations/<to>-<slug>.ts`
|
|
5
|
+
* that exports a `migration: Migration` constant. This file collects them
|
|
6
|
+
* into a single `ALL_MIGRATIONS` array consumed by the runner.
|
|
7
|
+
*
|
|
8
|
+
* No filesystem globbing: keeping the registry static keeps tree-shaking
|
|
9
|
+
* correct in bundlers + makes the load order explicit (the runner sorts
|
|
10
|
+
* by `from` version internally, so order in this array doesn't affect
|
|
11
|
+
* correctness).
|
|
12
|
+
*
|
|
13
|
+
* The example / no-op fixture migrations live in `test/fixtures/`, not
|
|
14
|
+
* here — they must NOT ship to production. When the first real
|
|
15
|
+
* migration lands, add a literal import below and append it to the
|
|
16
|
+
* array.
|
|
17
|
+
*/
|
|
18
|
+
import type { Migration } from './types.js';
|
|
19
|
+
export declare function __setMigrationsForTests(migrations: Migration[] | null): void;
|
|
20
|
+
/**
|
|
21
|
+
* The live registry the runner consumes. Reads the test override if set,
|
|
22
|
+
* otherwise the static production list. Exported as a getter via Proxy so
|
|
23
|
+
* existing `import { ALL_MIGRATIONS }` consumers (e.g. the KB API task)
|
|
24
|
+
* don't need to change call sites, but tests can still inject fixtures.
|
|
25
|
+
*/
|
|
26
|
+
export declare const ALL_MIGRATIONS: Migration[];
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static migration registry.
|
|
3
|
+
*
|
|
4
|
+
* Each migration is a TypeScript file in `src/migrations/<to>-<slug>.ts`
|
|
5
|
+
* that exports a `migration: Migration` constant. This file collects them
|
|
6
|
+
* into a single `ALL_MIGRATIONS` array consumed by the runner.
|
|
7
|
+
*
|
|
8
|
+
* No filesystem globbing: keeping the registry static keeps tree-shaking
|
|
9
|
+
* correct in bundlers + makes the load order explicit (the runner sorts
|
|
10
|
+
* by `from` version internally, so order in this array doesn't affect
|
|
11
|
+
* correctness).
|
|
12
|
+
*
|
|
13
|
+
* The example / no-op fixture migrations live in `test/fixtures/`, not
|
|
14
|
+
* here — they must NOT ship to production. When the first real
|
|
15
|
+
* migration lands, add a literal import below and append it to the
|
|
16
|
+
* array.
|
|
17
|
+
*/
|
|
18
|
+
const PRODUCTION_MIGRATIONS = [
|
|
19
|
+
// Example (do not uncomment in production):
|
|
20
|
+
//
|
|
21
|
+
// import { migration as removeCalloutType } from './migrations/0.3.0-remove-callout-type.js'
|
|
22
|
+
// PRODUCTION_MIGRATIONS.push(removeCalloutType)
|
|
23
|
+
//
|
|
24
|
+
// See `test/fixtures/*.ts` for the migration shape.
|
|
25
|
+
];
|
|
26
|
+
/**
|
|
27
|
+
* Test-only override slot. Set via `__setMigrationsForTests([...])` from a
|
|
28
|
+
* test's `beforeAll`; reset with `__setMigrationsForTests(null)` in
|
|
29
|
+
* `afterAll` so subsequent test files see the production registry again.
|
|
30
|
+
*
|
|
31
|
+
* Production code that imports `ALL_MIGRATIONS` (the runtime task, the
|
|
32
|
+
* MCP introspection endpoint) always sees the live override when one is
|
|
33
|
+
* active. The override module-level — there is no per-call argument
|
|
34
|
+
* because the task code intentionally has no test seam, and threading a
|
|
35
|
+
* config option from `kb_run_mdx_codemods` payload up through the
|
|
36
|
+
* runner only to satisfy tests would leak test concerns into a production
|
|
37
|
+
* payload schema.
|
|
38
|
+
*
|
|
39
|
+
* Do NOT call this from anywhere except a test's `beforeAll` /
|
|
40
|
+
* `afterAll`. If `MDX_CODEMODS_TEST_OVERRIDE_DISABLED=true` is set at
|
|
41
|
+
* boot, the hook becomes a hard error (defense in depth for prod pods).
|
|
42
|
+
*/
|
|
43
|
+
let TEST_OVERRIDE = null;
|
|
44
|
+
export function __setMigrationsForTests(migrations) {
|
|
45
|
+
if (process.env.MDX_CODEMODS_TEST_OVERRIDE_DISABLED === 'true') {
|
|
46
|
+
throw new Error('[mdx-codemods] __setMigrationsForTests called with MDX_CODEMODS_TEST_OVERRIDE_DISABLED=true ' +
|
|
47
|
+
'— this hook is for tests only and must not be reachable in production.');
|
|
48
|
+
}
|
|
49
|
+
TEST_OVERRIDE = migrations;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The live registry the runner consumes. Reads the test override if set,
|
|
53
|
+
* otherwise the static production list. Exported as a getter via Proxy so
|
|
54
|
+
* existing `import { ALL_MIGRATIONS }` consumers (e.g. the KB API task)
|
|
55
|
+
* don't need to change call sites, but tests can still inject fixtures.
|
|
56
|
+
*/
|
|
57
|
+
export const ALL_MIGRATIONS = new Proxy(PRODUCTION_MIGRATIONS, {
|
|
58
|
+
get(target, prop, receiver) {
|
|
59
|
+
const source = TEST_OVERRIDE ?? target;
|
|
60
|
+
return Reflect.get(source, prop, receiver);
|
|
61
|
+
},
|
|
62
|
+
has(target, prop) {
|
|
63
|
+
const source = TEST_OVERRIDE ?? target;
|
|
64
|
+
return Reflect.has(source, prop);
|
|
65
|
+
},
|
|
66
|
+
ownKeys(target) {
|
|
67
|
+
const source = TEST_OVERRIDE ?? target;
|
|
68
|
+
return Reflect.ownKeys(source);
|
|
69
|
+
},
|
|
70
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
71
|
+
const source = TEST_OVERRIDE ?? target;
|
|
72
|
+
return Reflect.getOwnPropertyDescriptor(source, prop);
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=migrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrations.js","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,MAAM,qBAAqB,GAAgB;AACzC,4CAA4C;AAC5C,EAAE;AACF,+FAA+F;AAC/F,kDAAkD;AAClD,EAAE;AACF,oDAAoD;CACrD,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,IAAI,aAAa,GAAuB,IAAI,CAAA;AAE5C,MAAM,UAAU,uBAAuB,CAAC,UAA8B;IACpE,IAAI,OAAO,CAAC,GAAG,CAAC,mCAAmC,KAAK,MAAM,EAAE,CAAC;QAC/D,MAAM,IAAI,KAAK,CACb,8FAA8F;YAC5F,wEAAwE,CAC3E,CAAA;IACH,CAAC;IACD,aAAa,GAAG,UAAU,CAAA;AAC5B,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAgB,IAAI,KAAK,CAAC,qBAAqB,EAAE;IAC1E,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;QACxB,MAAM,MAAM,GAAG,aAAa,IAAI,MAAM,CAAA;QACtC,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;IAC5C,CAAC;IACD,GAAG,CAAC,MAAM,EAAE,IAAI;QACd,MAAM,MAAM,GAAG,aAAa,IAAI,MAAM,CAAA;QACtC,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAClC,CAAC;IACD,OAAO,CAAC,MAAM;QACZ,MAAM,MAAM,GAAG,aAAa,IAAI,MAAM,CAAA;QACtC,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAChC,CAAC;IACD,wBAAwB,CAAC,MAAM,EAAE,IAAI;QACnC,MAAM,MAAM,GAAG,aAAa,IAAI,MAAM,CAAA;QACtC,OAAO,OAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IACvD,CAAC;CACF,CAAC,CAAA"}
|
package/dist/runner.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MDX codemod runner.
|
|
3
|
+
*
|
|
4
|
+
* Walks every translation row stored at `schemaVersion < effectiveTarget`,
|
|
5
|
+
* applies the chain of registered migrations that brings each row up to
|
|
6
|
+
* the effective target, and persists the rewritten content through the
|
|
7
|
+
* store's optimistic-concurrency write path.
|
|
8
|
+
*
|
|
9
|
+
* Design notes (cross-referenced with `competitor-monitor/docs/internal/optimistic-concurrency.md`
|
|
10
|
+
* and the plan file's PR 3 section):
|
|
11
|
+
*
|
|
12
|
+
* - **Per-translation independent:** Czech and English translations of
|
|
13
|
+
* the same article are separate rows; a failure on one doesn't block
|
|
14
|
+
* the other.
|
|
15
|
+
* - **Pin-respecting:** `effectiveTarget = min(targetVersion, tenantPin ?? targetVersion)`.
|
|
16
|
+
* Tenants pinned below the runtime SCHEMA_VERSION stop migrating at
|
|
17
|
+
* the pin; raising the pin later resumes migration on next boot.
|
|
18
|
+
* - **Skip-and-log:** a transform that throws or a write conflict
|
|
19
|
+
* that exhausts retries → translation recorded in
|
|
20
|
+
* `mdx_codemod_errors`, batch continues.
|
|
21
|
+
* - **Idempotent in aggregate:** transforms must be idempotent
|
|
22
|
+
* individually (author contract). The runner adds:
|
|
23
|
+
* (a) `changed: false` short-circuits the write path entirely,
|
|
24
|
+
* (b) re-running the runner against the same DB state is a no-op
|
|
25
|
+
* (no row matches the `< effectiveTarget` filter once all are
|
|
26
|
+
* stamped at target).
|
|
27
|
+
* - **Cache + embedding invalidation:** after a successful migration
|
|
28
|
+
* chain on at least one of an article's translations, the article
|
|
29
|
+
* is marked for re-embedding and a cache-bust event is emitted.
|
|
30
|
+
*/
|
|
31
|
+
import type { CodemodStore, Migration, RunMigrationsResult } from './types.js';
|
|
32
|
+
export interface RunMigrationsOpts {
|
|
33
|
+
/**
|
|
34
|
+
* The runtime's compiled SCHEMA_VERSION. The runner clamps it down
|
|
35
|
+
* to `min(targetVersion, tenantPin)` for the effective target.
|
|
36
|
+
*/
|
|
37
|
+
targetVersion: string;
|
|
38
|
+
/**
|
|
39
|
+
* Every migration the runtime knows about. Static array from
|
|
40
|
+
* `migrations.ts` (or a custom subset for tests). The runner sorts
|
|
41
|
+
* by `from` semver ascending before walking, so order in this array
|
|
42
|
+
* is not load-bearing.
|
|
43
|
+
*/
|
|
44
|
+
migrations: Migration[];
|
|
45
|
+
/** Pluggable storage layer. PR 4 wires it to KB API services. */
|
|
46
|
+
store: CodemodStore;
|
|
47
|
+
/** Batch size for fetching translations. Default 50. */
|
|
48
|
+
batchSize?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Max retries on optimistic-write conflict per migration step.
|
|
51
|
+
* Default 3. After the cap the translation is recorded in
|
|
52
|
+
* `mdx_codemod_errors` and the batch continues.
|
|
53
|
+
*/
|
|
54
|
+
maxRetries?: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Apply the registered migration chain to a single content blob,
|
|
58
|
+
* outside the DB-backed runner. Used by `restoreVersion` (Fix 5) to
|
|
59
|
+
* bring an older snapshot's content forward to the current runtime's
|
|
60
|
+
* SCHEMA_VERSION before writing it back as the latest version.
|
|
61
|
+
*
|
|
62
|
+
* Differs from `runMigrations` in that:
|
|
63
|
+
* - No store; no batch loop; no per-row error capture. The single
|
|
64
|
+
* content blob is migrated synchronously and the result returned.
|
|
65
|
+
* - It does NOT throw on an unbridged version gap. When no (or only a
|
|
66
|
+
* partial) chain exists, it returns the content unchanged at the
|
|
67
|
+
* highest version it could actually reach (`finalVersion` ≤ target) —
|
|
68
|
+
* the same "leave the row alone" stance `runMigrations` takes for an
|
|
69
|
+
* empty chain. This is correct because the renderer's `prepareProps`
|
|
70
|
+
* shim handles every shimmable (Tier-1/Tier-2) change at render time
|
|
71
|
+
* regardless of the stamped version, and a genuinely Tier-3 gap is
|
|
72
|
+
* left at its true version so the codemod runner reconciles it once a
|
|
73
|
+
* codemod is registered (rather than being silently over-stamped to
|
|
74
|
+
* the target and skipped forever). Keying the decision on the major
|
|
75
|
+
* version was wrong: a Tier-2-only MAJOR bump is shim-only (no
|
|
76
|
+
* codemod) yet would have falsely thrown, and a non-contiguous chain
|
|
77
|
+
* within a major would have silently restamped past a registered
|
|
78
|
+
* codemod.
|
|
79
|
+
* - `changed=false` means every step was a no-op; the content is
|
|
80
|
+
* bit-for-bit identical to the input (with `finalVersion` updated).
|
|
81
|
+
*
|
|
82
|
+
* Idempotency contract is identical to runMigrations — each transform
|
|
83
|
+
* MUST be idempotent.
|
|
84
|
+
*/
|
|
85
|
+
export declare class UnmigratableContentError extends Error {
|
|
86
|
+
readonly fromSchemaVersion: string;
|
|
87
|
+
readonly toSchemaVersion: string;
|
|
88
|
+
constructor(fromSchemaVersion: string, toSchemaVersion: string);
|
|
89
|
+
}
|
|
90
|
+
export interface MigrateContentResult {
|
|
91
|
+
content: string;
|
|
92
|
+
finalVersion: string;
|
|
93
|
+
changed: boolean;
|
|
94
|
+
appliedSlugs: string[];
|
|
95
|
+
}
|
|
96
|
+
export declare function migrateContentToCurrent(content: string, fromSchemaVersion: string, toSchemaVersion: string, migrations: Migration[]): MigrateContentResult;
|
|
97
|
+
export declare function runMigrations(opts: RunMigrationsOpts): Promise<RunMigrationsResult>;
|
package/dist/runner.js
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MDX codemod runner.
|
|
3
|
+
*
|
|
4
|
+
* Walks every translation row stored at `schemaVersion < effectiveTarget`,
|
|
5
|
+
* applies the chain of registered migrations that brings each row up to
|
|
6
|
+
* the effective target, and persists the rewritten content through the
|
|
7
|
+
* store's optimistic-concurrency write path.
|
|
8
|
+
*
|
|
9
|
+
* Design notes (cross-referenced with `competitor-monitor/docs/internal/optimistic-concurrency.md`
|
|
10
|
+
* and the plan file's PR 3 section):
|
|
11
|
+
*
|
|
12
|
+
* - **Per-translation independent:** Czech and English translations of
|
|
13
|
+
* the same article are separate rows; a failure on one doesn't block
|
|
14
|
+
* the other.
|
|
15
|
+
* - **Pin-respecting:** `effectiveTarget = min(targetVersion, tenantPin ?? targetVersion)`.
|
|
16
|
+
* Tenants pinned below the runtime SCHEMA_VERSION stop migrating at
|
|
17
|
+
* the pin; raising the pin later resumes migration on next boot.
|
|
18
|
+
* - **Skip-and-log:** a transform that throws or a write conflict
|
|
19
|
+
* that exhausts retries → translation recorded in
|
|
20
|
+
* `mdx_codemod_errors`, batch continues.
|
|
21
|
+
* - **Idempotent in aggregate:** transforms must be idempotent
|
|
22
|
+
* individually (author contract). The runner adds:
|
|
23
|
+
* (a) `changed: false` short-circuits the write path entirely,
|
|
24
|
+
* (b) re-running the runner against the same DB state is a no-op
|
|
25
|
+
* (no row matches the `< effectiveTarget` filter once all are
|
|
26
|
+
* stamped at target).
|
|
27
|
+
* - **Cache + embedding invalidation:** after a successful migration
|
|
28
|
+
* chain on at least one of an article's translations, the article
|
|
29
|
+
* is marked for re-embedding and a cache-bust event is emitted.
|
|
30
|
+
*/
|
|
31
|
+
import { gt, gte, lt, valid } from 'semver';
|
|
32
|
+
function assertValidSemver(label, version) {
|
|
33
|
+
if (!valid(version)) {
|
|
34
|
+
throw new Error(`[mdx-codemods] runMigrations: ${label} version "${version}" is not valid semver`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Picks the migrations to apply, in order, that bring a translation
|
|
39
|
+
* stamped at `currentVersion` up to `effectiveTarget`.
|
|
40
|
+
*
|
|
41
|
+
* Migrations are sorted by their `from` version ascending. The chain
|
|
42
|
+
* starts at `currentVersion` and walks: for each step, find a
|
|
43
|
+
* migration whose `from === currentVersion` AND `to <= effectiveTarget`,
|
|
44
|
+
* advance `currentVersion = migration.to`, repeat.
|
|
45
|
+
*
|
|
46
|
+
* Multiple migrations starting from the same `from` are not supported
|
|
47
|
+
* (it would make the walk non-deterministic). The classifier should
|
|
48
|
+
* eventually reject that shape; the runner will pick the first match
|
|
49
|
+
* here, which is fine for the well-formed case.
|
|
50
|
+
*/
|
|
51
|
+
function planMigrationChain(currentVersion, effectiveTarget, migrations) {
|
|
52
|
+
const sorted = [...migrations].sort((a, b) => {
|
|
53
|
+
if (gt(a.from, b.from))
|
|
54
|
+
return 1;
|
|
55
|
+
if (lt(a.from, b.from))
|
|
56
|
+
return -1;
|
|
57
|
+
return 0;
|
|
58
|
+
});
|
|
59
|
+
const chain = [];
|
|
60
|
+
let cursor = currentVersion;
|
|
61
|
+
// Defensive cap: never walk more than the registered migration count.
|
|
62
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
63
|
+
const next = sorted.find(m => m.from === cursor && !gt(m.to, effectiveTarget));
|
|
64
|
+
if (!next)
|
|
65
|
+
break;
|
|
66
|
+
chain.push(next);
|
|
67
|
+
cursor = next.to;
|
|
68
|
+
if (cursor === effectiveTarget)
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
return chain;
|
|
72
|
+
}
|
|
73
|
+
async function applyChainToTranslation(translation, chain, store, maxRetries) {
|
|
74
|
+
let current = translation;
|
|
75
|
+
let anyChanged = false;
|
|
76
|
+
for (const migration of chain) {
|
|
77
|
+
let attempt = 0;
|
|
78
|
+
while (true) {
|
|
79
|
+
let result;
|
|
80
|
+
try {
|
|
81
|
+
result = migration.transform(current.content);
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
const e = err;
|
|
85
|
+
return {
|
|
86
|
+
outcome: 'failed',
|
|
87
|
+
error: {
|
|
88
|
+
translationId: translation.id,
|
|
89
|
+
migrationSlug: migration.slug,
|
|
90
|
+
fromVersion: migration.from,
|
|
91
|
+
toVersion: migration.to,
|
|
92
|
+
errorMessage: e.message,
|
|
93
|
+
errorStack: e.stack,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (!result.changed) {
|
|
98
|
+
// Stamp the version forward even on no-op so a later
|
|
99
|
+
// re-invocation doesn't re-walk this row.
|
|
100
|
+
const stamp = await store.writeTranslation(current.id, current.content, migration.to, current.schemaVersion, migration.slug);
|
|
101
|
+
if (stamp.success) {
|
|
102
|
+
current = { ...current, schemaVersion: migration.to };
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
// Fix 8: pin violation is NOT retryable — surface as a failure
|
|
106
|
+
// with a descriptive message. The store already wrote a
|
|
107
|
+
// __pin_violation__ row in mdx_codemod_errors.
|
|
108
|
+
if (stamp.pinViolation) {
|
|
109
|
+
return {
|
|
110
|
+
outcome: 'failed',
|
|
111
|
+
error: {
|
|
112
|
+
translationId: translation.id,
|
|
113
|
+
migrationSlug: migration.slug,
|
|
114
|
+
fromVersion: migration.from,
|
|
115
|
+
toVersion: migration.to,
|
|
116
|
+
errorMessage: 'pin violation — content after migration uses components/props forbidden by the tenant pin',
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
// No-op + conflict: re-fetch + retry stamping. Don't count
|
|
121
|
+
// this against the transform retry cap because nothing changed.
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
const stamp = await store.writeTranslation(current.id, result.content, migration.to, current.schemaVersion, migration.slug);
|
|
125
|
+
if (stamp.success) {
|
|
126
|
+
current = {
|
|
127
|
+
...current,
|
|
128
|
+
content: result.content,
|
|
129
|
+
schemaVersion: migration.to,
|
|
130
|
+
};
|
|
131
|
+
anyChanged = true;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
// Fix 8: same pin-violation early exit on the changed-content path.
|
|
135
|
+
if (stamp.pinViolation) {
|
|
136
|
+
return {
|
|
137
|
+
outcome: 'failed',
|
|
138
|
+
error: {
|
|
139
|
+
translationId: translation.id,
|
|
140
|
+
migrationSlug: migration.slug,
|
|
141
|
+
fromVersion: migration.from,
|
|
142
|
+
toVersion: migration.to,
|
|
143
|
+
errorMessage: 'pin violation — content after migration uses components/props forbidden by the tenant pin',
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
attempt++;
|
|
149
|
+
if (attempt > maxRetries) {
|
|
150
|
+
return {
|
|
151
|
+
outcome: 'failed',
|
|
152
|
+
error: {
|
|
153
|
+
translationId: translation.id,
|
|
154
|
+
migrationSlug: migration.slug,
|
|
155
|
+
fromVersion: migration.from,
|
|
156
|
+
toVersion: migration.to,
|
|
157
|
+
errorMessage: `optimistic-write conflict exceeded ${maxRetries} retries`,
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
const refreshed = await store.getTranslation(translation.id);
|
|
162
|
+
if (!refreshed) {
|
|
163
|
+
return {
|
|
164
|
+
outcome: 'failed',
|
|
165
|
+
error: {
|
|
166
|
+
translationId: translation.id,
|
|
167
|
+
migrationSlug: migration.slug,
|
|
168
|
+
fromVersion: migration.from,
|
|
169
|
+
toVersion: migration.to,
|
|
170
|
+
errorMessage: 'translation disappeared during retry (deleted concurrently?)',
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
// If the refreshed row has already moved past this migration's
|
|
175
|
+
// `to` (someone else ran the same migration in parallel), stop —
|
|
176
|
+
// the chain may need replanning from the new cursor.
|
|
177
|
+
if (gte(refreshed.schemaVersion, migration.to)) {
|
|
178
|
+
current = refreshed;
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
current = refreshed;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (anyChanged) {
|
|
185
|
+
return { outcome: 'migrated', finalVersion: current.schemaVersion };
|
|
186
|
+
}
|
|
187
|
+
return { outcome: 'skipped' };
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Apply the registered migration chain to a single content blob,
|
|
191
|
+
* outside the DB-backed runner. Used by `restoreVersion` (Fix 5) to
|
|
192
|
+
* bring an older snapshot's content forward to the current runtime's
|
|
193
|
+
* SCHEMA_VERSION before writing it back as the latest version.
|
|
194
|
+
*
|
|
195
|
+
* Differs from `runMigrations` in that:
|
|
196
|
+
* - No store; no batch loop; no per-row error capture. The single
|
|
197
|
+
* content blob is migrated synchronously and the result returned.
|
|
198
|
+
* - It does NOT throw on an unbridged version gap. When no (or only a
|
|
199
|
+
* partial) chain exists, it returns the content unchanged at the
|
|
200
|
+
* highest version it could actually reach (`finalVersion` ≤ target) —
|
|
201
|
+
* the same "leave the row alone" stance `runMigrations` takes for an
|
|
202
|
+
* empty chain. This is correct because the renderer's `prepareProps`
|
|
203
|
+
* shim handles every shimmable (Tier-1/Tier-2) change at render time
|
|
204
|
+
* regardless of the stamped version, and a genuinely Tier-3 gap is
|
|
205
|
+
* left at its true version so the codemod runner reconciles it once a
|
|
206
|
+
* codemod is registered (rather than being silently over-stamped to
|
|
207
|
+
* the target and skipped forever). Keying the decision on the major
|
|
208
|
+
* version was wrong: a Tier-2-only MAJOR bump is shim-only (no
|
|
209
|
+
* codemod) yet would have falsely thrown, and a non-contiguous chain
|
|
210
|
+
* within a major would have silently restamped past a registered
|
|
211
|
+
* codemod.
|
|
212
|
+
* - `changed=false` means every step was a no-op; the content is
|
|
213
|
+
* bit-for-bit identical to the input (with `finalVersion` updated).
|
|
214
|
+
*
|
|
215
|
+
* Idempotency contract is identical to runMigrations — each transform
|
|
216
|
+
* MUST be idempotent.
|
|
217
|
+
*/
|
|
218
|
+
// Retained as exported API (re-exported by ArticleService, caught in the
|
|
219
|
+
// articles route) even though `migrateContentToCurrent` no longer throws it —
|
|
220
|
+
// removing it would break those imports, and a future caller may still want it.
|
|
221
|
+
export class UnmigratableContentError extends Error {
|
|
222
|
+
fromSchemaVersion;
|
|
223
|
+
toSchemaVersion;
|
|
224
|
+
constructor(fromSchemaVersion, toSchemaVersion) {
|
|
225
|
+
super(`[mdx-codemods] no migration chain from ${fromSchemaVersion} to ${toSchemaVersion} ` +
|
|
226
|
+
`(content predates a registered migration; refusing to silently restore stale schema)`);
|
|
227
|
+
this.fromSchemaVersion = fromSchemaVersion;
|
|
228
|
+
this.toSchemaVersion = toSchemaVersion;
|
|
229
|
+
this.name = 'UnmigratableContentError';
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
export function migrateContentToCurrent(content, fromSchemaVersion, toSchemaVersion, migrations) {
|
|
233
|
+
assertValidSemver('fromSchemaVersion', fromSchemaVersion);
|
|
234
|
+
assertValidSemver('toSchemaVersion', toSchemaVersion);
|
|
235
|
+
if (gte(fromSchemaVersion, toSchemaVersion)) {
|
|
236
|
+
// Restoring a version that's already at or ahead of the runtime is
|
|
237
|
+
// a no-op chain (current === target). Stay quiet — this is the
|
|
238
|
+
// common case during a restore-to-recent.
|
|
239
|
+
return {
|
|
240
|
+
content,
|
|
241
|
+
finalVersion: fromSchemaVersion,
|
|
242
|
+
changed: false,
|
|
243
|
+
appliedSlugs: [],
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
const chain = planMigrationChain(fromSchemaVersion, toSchemaVersion, migrations);
|
|
247
|
+
if (chain.length === 0) {
|
|
248
|
+
// No registered migration bridges these versions. Leave the content
|
|
249
|
+
// alone at its CURRENT version — exactly what `runMigrations` does for an
|
|
250
|
+
// empty chain (it skips the row, leaving `schema_version` untouched). We do
|
|
251
|
+
// NOT restamp to the target: the content is forward-compatible at render
|
|
252
|
+
// time via `prepareProps` (Tier-1 additive / Tier-2 shim), and returning
|
|
253
|
+
// `fromSchemaVersion` keeps the row eligible for the codemod runner to
|
|
254
|
+
// finish later if a Tier-3 codemod is ever registered for this span. (The
|
|
255
|
+
// previous major()-keyed throw/restamp was wrong both ways — see the
|
|
256
|
+
// function docstring.)
|
|
257
|
+
return {
|
|
258
|
+
content,
|
|
259
|
+
finalVersion: fromSchemaVersion,
|
|
260
|
+
changed: false,
|
|
261
|
+
appliedSlugs: [],
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
let current = content;
|
|
265
|
+
let cursor = fromSchemaVersion;
|
|
266
|
+
let anyChanged = false;
|
|
267
|
+
const appliedSlugs = [];
|
|
268
|
+
for (const m of chain) {
|
|
269
|
+
const out = m.transform(current);
|
|
270
|
+
appliedSlugs.push(m.slug);
|
|
271
|
+
if (out.changed) {
|
|
272
|
+
current = out.content;
|
|
273
|
+
anyChanged = true;
|
|
274
|
+
}
|
|
275
|
+
cursor = m.to;
|
|
276
|
+
}
|
|
277
|
+
return {
|
|
278
|
+
content: current,
|
|
279
|
+
finalVersion: cursor,
|
|
280
|
+
changed: anyChanged,
|
|
281
|
+
appliedSlugs,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
export async function runMigrations(opts) {
|
|
285
|
+
assertValidSemver('targetVersion', opts.targetVersion);
|
|
286
|
+
for (const m of opts.migrations) {
|
|
287
|
+
assertValidSemver(`migration "${m.slug}".from`, m.from);
|
|
288
|
+
assertValidSemver(`migration "${m.slug}".to`, m.to);
|
|
289
|
+
if (!gt(m.to, m.from)) {
|
|
290
|
+
throw new Error(`[mdx-codemods] migration "${m.slug}" has to (${m.to}) not strictly greater than from (${m.from})`);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
// Fix 15: pin is re-fetched per batch INSIDE the loop, so an operator
|
|
294
|
+
// who lowers the pin mid-run sees the change on the very next batch.
|
|
295
|
+
// The first read also validates the semver up front so an invalid pin
|
|
296
|
+
// surfaces immediately rather than after the first batch worth of
|
|
297
|
+
// wasted work.
|
|
298
|
+
const initialPin = await opts.store.getTenantPin();
|
|
299
|
+
if (initialPin !== null && !valid(initialPin)) {
|
|
300
|
+
throw new Error(`[mdx-codemods] runMigrations: tenant pin "${initialPin}" is not valid semver`);
|
|
301
|
+
}
|
|
302
|
+
let effectiveTarget = initialPin !== null && lt(initialPin, opts.targetVersion) ? initialPin : opts.targetVersion;
|
|
303
|
+
const batchSize = opts.batchSize ?? 50;
|
|
304
|
+
const maxRetries = opts.maxRetries ?? 3;
|
|
305
|
+
const result = {
|
|
306
|
+
translationsProcessed: 0,
|
|
307
|
+
translationsMigrated: 0,
|
|
308
|
+
translationsSkipped: 0,
|
|
309
|
+
translationsFailed: 0,
|
|
310
|
+
articlesInvalidated: new Set(),
|
|
311
|
+
effectiveTargetVersion: effectiveTarget,
|
|
312
|
+
};
|
|
313
|
+
let cursor = undefined;
|
|
314
|
+
let prevCursor = undefined;
|
|
315
|
+
while (true) {
|
|
316
|
+
// Fix 15: re-fetch the pin per batch so an operator lowering the pin
|
|
317
|
+
// mid-run gets immediate effect. If the new pin drops below an
|
|
318
|
+
// already-stamped row's version, listTranslationsBelow naturally
|
|
319
|
+
// returns 0 rows (the loop exits cleanly). Invalid mid-run pin =
|
|
320
|
+
// log + exit cleanly rather than crashing the worker pod.
|
|
321
|
+
const pin = await opts.store.getTenantPin();
|
|
322
|
+
if (pin !== null && !valid(pin)) {
|
|
323
|
+
// eslint-disable-next-line no-console
|
|
324
|
+
console.warn(`[mdx-codemods] tenant pin "${pin}" became invalid mid-run; exiting cleanly`);
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
effectiveTarget = pin !== null && lt(pin, opts.targetVersion) ? pin : opts.targetVersion;
|
|
328
|
+
result.effectiveTargetVersion = effectiveTarget;
|
|
329
|
+
const batch = await opts.store.listTranslationsBelow(effectiveTarget, {
|
|
330
|
+
batchSize,
|
|
331
|
+
afterId: cursor,
|
|
332
|
+
});
|
|
333
|
+
if (batch.length === 0)
|
|
334
|
+
break;
|
|
335
|
+
cursor = batch[batch.length - 1].id;
|
|
336
|
+
// Defensive: if the store hands back a batch whose last id equals
|
|
337
|
+
// the cursor we passed in, it isn't honoring `afterId` and we'd
|
|
338
|
+
// spin forever. Surfaces a store-implementation bug loudly instead
|
|
339
|
+
// of hanging the whole graphile-worker pod.
|
|
340
|
+
if (prevCursor !== undefined && cursor === prevCursor) {
|
|
341
|
+
throw new Error(`[mdx-codemods] runner cursor stalled at "${cursor}" — store.listTranslationsBelow ` +
|
|
342
|
+
`is not honoring \`afterId\` (returned the same trailing row twice in a row). ` +
|
|
343
|
+
`Check the store implementation against the contract in src/types.ts.`);
|
|
344
|
+
}
|
|
345
|
+
prevCursor = cursor;
|
|
346
|
+
for (const translation of batch) {
|
|
347
|
+
result.translationsProcessed++;
|
|
348
|
+
// Skip translations whose schemaVersion is already at/past the
|
|
349
|
+
// effective target — defensive, the store query should have
|
|
350
|
+
// filtered these out but pin changes mid-batch are possible.
|
|
351
|
+
if (gte(translation.schemaVersion, effectiveTarget)) {
|
|
352
|
+
result.translationsSkipped++;
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
const chain = planMigrationChain(translation.schemaVersion, effectiveTarget, opts.migrations);
|
|
356
|
+
if (chain.length === 0) {
|
|
357
|
+
// No registered migration knows how to bring this version
|
|
358
|
+
// forward — leave the row alone. (This can happen for legacy
|
|
359
|
+
// versions we never published a codemod for; operator decides
|
|
360
|
+
// whether to backport or leave as-is.)
|
|
361
|
+
result.translationsSkipped++;
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
const applied = await applyChainToTranslation(translation, chain, opts.store, maxRetries);
|
|
365
|
+
if (applied.outcome === 'failed') {
|
|
366
|
+
result.translationsFailed++;
|
|
367
|
+
await opts.store.recordError(applied.error);
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
if (applied.outcome === 'skipped') {
|
|
371
|
+
result.translationsSkipped++;
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
result.translationsMigrated++;
|
|
375
|
+
if (!result.articlesInvalidated.has(translation.articleId)) {
|
|
376
|
+
result.articlesInvalidated.add(translation.articleId);
|
|
377
|
+
await opts.store.invalidateEmbedding(translation.articleId);
|
|
378
|
+
await opts.store.emitCacheBust(translation.articleId);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return result;
|
|
383
|
+
}
|
|
384
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAsC3C,SAAS,iBAAiB,CAAC,KAAa,EAAE,OAAe;IACvD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,iCAAiC,KAAK,aAAa,OAAO,uBAAuB,CAClF,CAAA;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAS,kBAAkB,CACzB,cAAsB,EACtB,eAAuB,EACvB,UAAuB;IAEvB,MAAM,MAAM,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC3C,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;YAAE,OAAO,CAAC,CAAA;QAChC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;YAAE,OAAO,CAAC,CAAC,CAAA;QACjC,OAAO,CAAC,CAAA;IACV,CAAC,CAAC,CAAA;IACF,MAAM,KAAK,GAAgB,EAAE,CAAA;IAC7B,IAAI,MAAM,GAAG,cAAc,CAAA;IAC3B,sEAAsE;IACtE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,MAAM,IAAI,GAAG,M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