@crewhaus/migration-engine 0.1.1 → 0.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewhaus/migration-engine",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "description": "IR version migrations: register up/down chains; migrate(spec, fromVersion, toVersion) walks the chain",
6
6
  "main": "src/index.ts",
@@ -12,13 +12,13 @@
12
12
  "test": "bun test src"
13
13
  },
14
14
  "dependencies": {
15
- "@crewhaus/errors": "0.1.1"
15
+ "@crewhaus/errors": "0.1.2"
16
16
  },
17
17
  "license": "Apache-2.0",
18
18
  "author": {
19
19
  "name": "Max Meier",
20
- "email": "max@studiomax.io",
21
- "url": "https://studiomax.io"
20
+ "email": "max@crewhaus.ai",
21
+ "url": "https://crewhaus.ai"
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",
@@ -30,12 +30,7 @@
30
30
  "url": "https://github.com/crewhaus/factory/issues"
31
31
  },
32
32
  "publishConfig": {
33
- "access": "restricted"
33
+ "access": "public"
34
34
  },
35
- "files": [
36
- "src",
37
- "README.md",
38
- "LICENSE",
39
- "NOTICE"
40
- ]
35
+ "files": ["src", "README.md", "LICENSE", "NOTICE"]
41
36
  }
package/src/index.test.ts CHANGED
@@ -115,4 +115,46 @@ describe("migration-engine — T4 multi-step chain replay", () => {
115
115
  });
116
116
  expect(e.list()).toEqual(["0→1", "1→2"]);
117
117
  });
118
+
119
+ test("clear empties the registry", () => {
120
+ const e = createDefaultEngine();
121
+ expect(e.list()).toEqual(["0→1"]);
122
+ e.clear();
123
+ expect(e.list()).toEqual([]);
124
+ // After clearing, the previously-registered step is gone.
125
+ expect(() => e.migrate({ version: 0 }, 1)).toThrow(MigrationError);
126
+ });
127
+ });
128
+
129
+ describe("migration-engine — additional coverage", () => {
130
+ test("NOOP_0_TO_1.up stamps version 1 and preserves other keys", () => {
131
+ const out = NOOP_0_TO_1.up({ name: "x", version: 0 });
132
+ expect(out).toEqual({ name: "x", version: 1 });
133
+ });
134
+
135
+ test("NOOP_0_TO_1.down stamps version 0 and preserves other keys", () => {
136
+ const out = NOOP_0_TO_1.down({ name: "x", version: 1 });
137
+ expect(out).toEqual({ name: "x", version: 0 });
138
+ });
139
+
140
+ test("migrate treats a spec with no version field as version 0", () => {
141
+ const e = createDefaultEngine();
142
+ // No `version` key at all -> fromVersion defaults to 0, so 0 -> 1 runs.
143
+ const out = e.migrate({ name: "no-version" }, 1);
144
+ expect(out.version).toBe(1);
145
+ });
146
+
147
+ test("downgrade throws when the needed step is not registered", () => {
148
+ const e = new MigrationEngine();
149
+ // Walking down from 1 to 0 needs the 0→1 step's down(); none registered.
150
+ expect(() => e.migrate({ version: 1 }, 0)).toThrow(MigrationError);
151
+ });
152
+
153
+ test("MigrationError carries the config code and an optional cause", () => {
154
+ const cause = new Error("root");
155
+ const err = new MigrationError("boom", cause);
156
+ expect(err).toBeInstanceOf(MigrationError);
157
+ expect(err.name).toBe("MigrationError");
158
+ expect(err.cause).toBe(cause);
159
+ });
118
160
  });
package/src/index.ts CHANGED
@@ -33,7 +33,11 @@ export class MigrationError extends CrewhausError {
33
33
  }
34
34
 
35
35
  export class MigrationEngine {
36
- private readonly migrations = new Map<string, Migration>();
36
+ private readonly migrations: Map<string, Migration>;
37
+
38
+ constructor() {
39
+ this.migrations = new Map<string, Migration>();
40
+ }
37
41
 
38
42
  register(m: Migration): void {
39
43
  if (m.from === m.to) {