@mandujs/core 0.3.2 → 0.3.3
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/README.ko.md +200 -200
- package/README.md +200 -200
- package/package.json +4 -2
- package/src/change/history.ts +145 -0
- package/src/change/index.ts +40 -0
- package/src/change/integrity.ts +81 -0
- package/src/change/snapshot.ts +233 -0
- package/src/change/transaction.ts +293 -0
- package/src/change/types.ts +102 -0
- package/src/error/classifier.ts +314 -0
- package/src/error/formatter.ts +237 -0
- package/src/error/index.ts +25 -0
- package/src/error/stack-analyzer.ts +295 -0
- package/src/error/types.ts +140 -0
- package/src/filling/context.ts +228 -219
- package/src/filling/filling.ts +256 -234
- package/src/filling/index.ts +7 -7
- package/src/generator/generate.ts +85 -3
- package/src/generator/index.ts +2 -2
- package/src/guard/auto-correct.ts +257 -203
- package/src/index.ts +2 -0
- package/src/report/index.ts +1 -1
- package/src/runtime/index.ts +3 -3
- package/src/runtime/router.ts +65 -65
- package/src/runtime/server.ts +189 -139
- package/src/runtime/ssr.ts +38 -38
- package/src/spec/index.ts +3 -3
- package/src/spec/load.ts +76 -76
- package/src/spec/lock.ts +56 -56
package/src/spec/lock.ts
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { createHash } from "crypto";
|
|
2
|
-
import type { RoutesManifest } from "./schema";
|
|
3
|
-
|
|
4
|
-
export interface SpecLock {
|
|
5
|
-
routesHash: string;
|
|
6
|
-
updatedAt: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function computeHash(manifest: RoutesManifest): string {
|
|
10
|
-
const content = JSON.stringify(manifest, null, 2);
|
|
11
|
-
return createHash("sha256").update(content).digest("hex");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function readLock(lockPath: string): Promise<SpecLock | null> {
|
|
15
|
-
try {
|
|
16
|
-
const file = Bun.file(lockPath);
|
|
17
|
-
const exists = await file.exists();
|
|
18
|
-
|
|
19
|
-
if (!exists) {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const content = await file.text();
|
|
24
|
-
return JSON.parse(content) as SpecLock;
|
|
25
|
-
} catch {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export async function writeLock(lockPath: string, manifest: RoutesManifest): Promise<SpecLock> {
|
|
31
|
-
const lock: SpecLock = {
|
|
32
|
-
routesHash: computeHash(manifest),
|
|
33
|
-
updatedAt: new Date().toISOString(),
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
await Bun.write(lockPath, JSON.stringify(lock, null, 2));
|
|
37
|
-
return lock;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export async function verifyLock(
|
|
41
|
-
lockPath: string,
|
|
42
|
-
manifest: RoutesManifest
|
|
43
|
-
): Promise<{ valid: boolean; currentHash: string; lockHash: string | null }> {
|
|
44
|
-
const currentHash = computeHash(manifest);
|
|
45
|
-
const lock = await readLock(lockPath);
|
|
46
|
-
|
|
47
|
-
if (!lock) {
|
|
48
|
-
return { valid: false, currentHash, lockHash: null };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
valid: lock.routesHash === currentHash,
|
|
53
|
-
currentHash,
|
|
54
|
-
lockHash: lock.routesHash,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
1
|
+
import { createHash } from "crypto";
|
|
2
|
+
import type { RoutesManifest } from "./schema";
|
|
3
|
+
|
|
4
|
+
export interface SpecLock {
|
|
5
|
+
routesHash: string;
|
|
6
|
+
updatedAt: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function computeHash(manifest: RoutesManifest): string {
|
|
10
|
+
const content = JSON.stringify(manifest, null, 2);
|
|
11
|
+
return createHash("sha256").update(content).digest("hex");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function readLock(lockPath: string): Promise<SpecLock | null> {
|
|
15
|
+
try {
|
|
16
|
+
const file = Bun.file(lockPath);
|
|
17
|
+
const exists = await file.exists();
|
|
18
|
+
|
|
19
|
+
if (!exists) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const content = await file.text();
|
|
24
|
+
return JSON.parse(content) as SpecLock;
|
|
25
|
+
} catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function writeLock(lockPath: string, manifest: RoutesManifest): Promise<SpecLock> {
|
|
31
|
+
const lock: SpecLock = {
|
|
32
|
+
routesHash: computeHash(manifest),
|
|
33
|
+
updatedAt: new Date().toISOString(),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
await Bun.write(lockPath, JSON.stringify(lock, null, 2));
|
|
37
|
+
return lock;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function verifyLock(
|
|
41
|
+
lockPath: string,
|
|
42
|
+
manifest: RoutesManifest
|
|
43
|
+
): Promise<{ valid: boolean; currentHash: string; lockHash: string | null }> {
|
|
44
|
+
const currentHash = computeHash(manifest);
|
|
45
|
+
const lock = await readLock(lockPath);
|
|
46
|
+
|
|
47
|
+
if (!lock) {
|
|
48
|
+
return { valid: false, currentHash, lockHash: null };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
valid: lock.routesHash === currentHash,
|
|
53
|
+
currentHash,
|
|
54
|
+
lockHash: lock.routesHash,
|
|
55
|
+
};
|
|
56
|
+
}
|