@llipe.com/dev-tasks 0.6.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/CHANGELOG.md +104 -0
- package/README.md +823 -0
- package/bundle-manifest.json +113 -0
- package/dist/adapters/cli/extract-all.d.ts +31 -0
- package/dist/adapters/cli/extract-all.d.ts.map +1 -0
- package/dist/adapters/cli/extract-all.js +374 -0
- package/dist/adapters/cli/extract-all.js.map +1 -0
- package/dist/adapters/cli/extract-asyncapi.d.ts +26 -0
- package/dist/adapters/cli/extract-asyncapi.d.ts.map +1 -0
- package/dist/adapters/cli/extract-asyncapi.js +142 -0
- package/dist/adapters/cli/extract-asyncapi.js.map +1 -0
- package/dist/adapters/cli/extract-component.d.ts +24 -0
- package/dist/adapters/cli/extract-component.d.ts.map +1 -0
- package/dist/adapters/cli/extract-component.js +198 -0
- package/dist/adapters/cli/extract-component.js.map +1 -0
- package/dist/adapters/cli/extract-detect.d.ts +19 -0
- package/dist/adapters/cli/extract-detect.d.ts.map +1 -0
- package/dist/adapters/cli/extract-detect.js +98 -0
- package/dist/adapters/cli/extract-detect.js.map +1 -0
- package/dist/adapters/cli/extract-openapi.d.ts +29 -0
- package/dist/adapters/cli/extract-openapi.d.ts.map +1 -0
- package/dist/adapters/cli/extract-openapi.js +111 -0
- package/dist/adapters/cli/extract-openapi.js.map +1 -0
- package/dist/adapters/cli/extract-schema.d.ts +15 -0
- package/dist/adapters/cli/extract-schema.d.ts.map +1 -0
- package/dist/adapters/cli/extract-schema.js +39 -0
- package/dist/adapters/cli/extract-schema.js.map +1 -0
- package/dist/adapters/cli/index.d.ts +6 -0
- package/dist/adapters/cli/index.d.ts.map +1 -0
- package/dist/adapters/cli/index.js +5 -0
- package/dist/adapters/cli/index.js.map +1 -0
- package/dist/adapters/cli/parse-args.d.ts +22 -0
- package/dist/adapters/cli/parse-args.d.ts.map +1 -0
- package/dist/adapters/cli/parse-args.js +63 -0
- package/dist/adapters/cli/parse-args.js.map +1 -0
- package/dist/adapters/mcp/index.d.ts +5 -0
- package/dist/adapters/mcp/index.d.ts.map +1 -0
- package/dist/adapters/mcp/index.js +2 -0
- package/dist/adapters/mcp/index.js.map +1 -0
- package/dist/bin/dev-tasks.d.ts +7 -0
- package/dist/bin/dev-tasks.d.ts.map +1 -0
- package/dist/bin/dev-tasks.js +275 -0
- package/dist/bin/dev-tasks.js.map +1 -0
- package/dist/bin/dt.d.ts +7 -0
- package/dist/bin/dt.d.ts.map +1 -0
- package/dist/bin/dt.js +159 -0
- package/dist/bin/dt.js.map +1 -0
- package/dist/core/catalog/index.d.ts +5 -0
- package/dist/core/catalog/index.d.ts.map +1 -0
- package/dist/core/catalog/index.js +2 -0
- package/dist/core/catalog/index.js.map +1 -0
- package/dist/core/context/index.d.ts +5 -0
- package/dist/core/context/index.d.ts.map +1 -0
- package/dist/core/context/index.js +2 -0
- package/dist/core/context/index.js.map +1 -0
- package/dist/core/distribution/backup.d.ts +24 -0
- package/dist/core/distribution/backup.d.ts.map +1 -0
- package/dist/core/distribution/backup.js +37 -0
- package/dist/core/distribution/backup.js.map +1 -0
- package/dist/core/distribution/doctor.d.ts +35 -0
- package/dist/core/distribution/doctor.d.ts.map +1 -0
- package/dist/core/distribution/doctor.js +158 -0
- package/dist/core/distribution/doctor.js.map +1 -0
- package/dist/core/distribution/hash.d.ts +14 -0
- package/dist/core/distribution/hash.d.ts.map +1 -0
- package/dist/core/distribution/hash.js +21 -0
- package/dist/core/distribution/hash.js.map +1 -0
- package/dist/core/distribution/index.d.ts +18 -0
- package/dist/core/distribution/index.d.ts.map +1 -0
- package/dist/core/distribution/index.js +12 -0
- package/dist/core/distribution/index.js.map +1 -0
- package/dist/core/distribution/install.d.ts +25 -0
- package/dist/core/distribution/install.d.ts.map +1 -0
- package/dist/core/distribution/install.js +81 -0
- package/dist/core/distribution/install.js.map +1 -0
- package/dist/core/distribution/manifest.d.ts +28 -0
- package/dist/core/distribution/manifest.d.ts.map +1 -0
- package/dist/core/distribution/manifest.js +38 -0
- package/dist/core/distribution/manifest.js.map +1 -0
- package/dist/core/distribution/migrate.d.ts +54 -0
- package/dist/core/distribution/migrate.d.ts.map +1 -0
- package/dist/core/distribution/migrate.js +200 -0
- package/dist/core/distribution/migrate.js.map +1 -0
- package/dist/core/distribution/pin.d.ts +15 -0
- package/dist/core/distribution/pin.d.ts.map +1 -0
- package/dist/core/distribution/pin.js +37 -0
- package/dist/core/distribution/pin.js.map +1 -0
- package/dist/core/distribution/status.d.ts +20 -0
- package/dist/core/distribution/status.d.ts.map +1 -0
- package/dist/core/distribution/status.js +39 -0
- package/dist/core/distribution/status.js.map +1 -0
- package/dist/core/distribution/update.d.ts +41 -0
- package/dist/core/distribution/update.d.ts.map +1 -0
- package/dist/core/distribution/update.js +148 -0
- package/dist/core/distribution/update.js.map +1 -0
- package/dist/core/exit-codes.d.ts +23 -0
- package/dist/core/exit-codes.d.ts.map +1 -0
- package/dist/core/exit-codes.js +22 -0
- package/dist/core/exit-codes.js.map +1 -0
- package/dist/core/extract/asyncapi/index.d.ts +11 -0
- package/dist/core/extract/asyncapi/index.d.ts.map +1 -0
- package/dist/core/extract/asyncapi/index.js +7 -0
- package/dist/core/extract/asyncapi/index.js.map +1 -0
- package/dist/core/extract/asyncapi/payloads.d.ts +20 -0
- package/dist/core/extract/asyncapi/payloads.d.ts.map +1 -0
- package/dist/core/extract/asyncapi/payloads.js +421 -0
- package/dist/core/extract/asyncapi/payloads.js.map +1 -0
- package/dist/core/extract/asyncapi/topics.d.ts +27 -0
- package/dist/core/extract/asyncapi/topics.d.ts.map +1 -0
- package/dist/core/extract/asyncapi/topics.js +368 -0
- package/dist/core/extract/asyncapi/topics.js.map +1 -0
- package/dist/core/extract/asyncapi/types.d.ts +129 -0
- package/dist/core/extract/asyncapi/types.d.ts.map +1 -0
- package/dist/core/extract/asyncapi/types.js +5 -0
- package/dist/core/extract/asyncapi/types.js.map +1 -0
- package/dist/core/extract/asyncapi/validate.d.ts +29 -0
- package/dist/core/extract/asyncapi/validate.d.ts.map +1 -0
- package/dist/core/extract/asyncapi/validate.js +156 -0
- package/dist/core/extract/asyncapi/validate.js.map +1 -0
- package/dist/core/extract/component.d.ts +201 -0
- package/dist/core/extract/component.d.ts.map +1 -0
- package/dist/core/extract/component.js +258 -0
- package/dist/core/extract/component.js.map +1 -0
- package/dist/core/extract/detect.d.ts +35 -0
- package/dist/core/extract/detect.d.ts.map +1 -0
- package/dist/core/extract/detect.js +89 -0
- package/dist/core/extract/detect.js.map +1 -0
- package/dist/core/extract/index.d.ts +12 -0
- package/dist/core/extract/index.d.ts.map +1 -0
- package/dist/core/extract/index.js +6 -0
- package/dist/core/extract/index.js.map +1 -0
- package/dist/core/extract/openapi/index.d.ts +13 -0
- package/dist/core/extract/openapi/index.d.ts.map +1 -0
- package/dist/core/extract/openapi/index.js +9 -0
- package/dist/core/extract/openapi/index.js.map +1 -0
- package/dist/core/extract/openapi/llm-descriptions.d.ts +41 -0
- package/dist/core/extract/openapi/llm-descriptions.d.ts.map +1 -0
- package/dist/core/extract/openapi/llm-descriptions.js +36 -0
- package/dist/core/extract/openapi/llm-descriptions.js.map +1 -0
- package/dist/core/extract/openapi/route1.d.ts +36 -0
- package/dist/core/extract/openapi/route1.d.ts.map +1 -0
- package/dist/core/extract/openapi/route1.js +327 -0
- package/dist/core/extract/openapi/route1.js.map +1 -0
- package/dist/core/extract/openapi/route2.d.ts +46 -0
- package/dist/core/extract/openapi/route2.d.ts.map +1 -0
- package/dist/core/extract/openapi/route2.js +19 -0
- package/dist/core/extract/openapi/route2.js.map +1 -0
- package/dist/core/extract/openapi/route3.d.ts +26 -0
- package/dist/core/extract/openapi/route3.d.ts.map +1 -0
- package/dist/core/extract/openapi/route3.js +737 -0
- package/dist/core/extract/openapi/route3.js.map +1 -0
- package/dist/core/extract/openapi/types.d.ts +125 -0
- package/dist/core/extract/openapi/types.d.ts.map +1 -0
- package/dist/core/extract/openapi/types.js +5 -0
- package/dist/core/extract/openapi/types.js.map +1 -0
- package/dist/core/extract/openapi/validate.d.ts +29 -0
- package/dist/core/extract/openapi/validate.d.ts.map +1 -0
- package/dist/core/extract/openapi/validate.js +200 -0
- package/dist/core/extract/openapi/validate.js.map +1 -0
- package/dist/core/extract/orm/drizzle.d.ts +20 -0
- package/dist/core/extract/orm/drizzle.d.ts.map +1 -0
- package/dist/core/extract/orm/drizzle.js +283 -0
- package/dist/core/extract/orm/drizzle.js.map +1 -0
- package/dist/core/extract/orm/information-schema.d.ts +26 -0
- package/dist/core/extract/orm/information-schema.d.ts.map +1 -0
- package/dist/core/extract/orm/information-schema.js +142 -0
- package/dist/core/extract/orm/information-schema.js.map +1 -0
- package/dist/core/extract/orm/llm-descriptions.d.ts +28 -0
- package/dist/core/extract/orm/llm-descriptions.d.ts.map +1 -0
- package/dist/core/extract/orm/llm-descriptions.js +64 -0
- package/dist/core/extract/orm/llm-descriptions.js.map +1 -0
- package/dist/core/extract/orm/migration-inference.d.ts +25 -0
- package/dist/core/extract/orm/migration-inference.d.ts.map +1 -0
- package/dist/core/extract/orm/migration-inference.js +76 -0
- package/dist/core/extract/orm/migration-inference.js.map +1 -0
- package/dist/core/extract/orm/prisma.d.ts +23 -0
- package/dist/core/extract/orm/prisma.d.ts.map +1 -0
- package/dist/core/extract/orm/prisma.js +234 -0
- package/dist/core/extract/orm/prisma.js.map +1 -0
- package/dist/core/extract/orm/typeorm.d.ts +22 -0
- package/dist/core/extract/orm/typeorm.d.ts.map +1 -0
- package/dist/core/extract/orm/typeorm.js +269 -0
- package/dist/core/extract/orm/typeorm.js.map +1 -0
- package/dist/core/extract/orm/types.d.ts +97 -0
- package/dist/core/extract/orm/types.d.ts.map +1 -0
- package/dist/core/extract/orm/types.js +6 -0
- package/dist/core/extract/orm/types.js.map +1 -0
- package/dist/core/extract/prompt.d.ts +21 -0
- package/dist/core/extract/prompt.d.ts.map +1 -0
- package/dist/core/extract/prompt.js +79 -0
- package/dist/core/extract/prompt.js.map +1 -0
- package/dist/core/extract/provider.d.ts +117 -0
- package/dist/core/extract/provider.d.ts.map +1 -0
- package/dist/core/extract/provider.js +6 -0
- package/dist/core/extract/provider.js.map +1 -0
- package/dist/core/extract/providers/node-ts.d.ts +69 -0
- package/dist/core/extract/providers/node-ts.d.ts.map +1 -0
- package/dist/core/extract/providers/node-ts.js +311 -0
- package/dist/core/extract/providers/node-ts.js.map +1 -0
- package/dist/core/extract/render/schema-md.d.ts +16 -0
- package/dist/core/extract/render/schema-md.d.ts.map +1 -0
- package/dist/core/extract/render/schema-md.js +140 -0
- package/dist/core/extract/render/schema-md.js.map +1 -0
- package/dist/core/extract/report.d.ts +97 -0
- package/dist/core/extract/report.d.ts.map +1 -0
- package/dist/core/extract/report.js +47 -0
- package/dist/core/extract/report.js.map +1 -0
- package/dist/core/extract/schema.d.ts +36 -0
- package/dist/core/extract/schema.d.ts.map +1 -0
- package/dist/core/extract/schema.js +141 -0
- package/dist/core/extract/schema.js.map +1 -0
- package/dist/core/index.d.ts +15 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +14 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/providers/index.d.ts +5 -0
- package/dist/core/providers/index.d.ts.map +1 -0
- package/dist/core/providers/index.js +2 -0
- package/dist/core/providers/index.js.map +1 -0
- package/dist/core/reconcile.d.ts +25 -0
- package/dist/core/reconcile.d.ts.map +1 -0
- package/dist/core/reconcile.js +36 -0
- package/dist/core/reconcile.js.map +1 -0
- package/dist/core/scope/index.d.ts +5 -0
- package/dist/core/scope/index.d.ts.map +1 -0
- package/dist/core/scope/index.js +2 -0
- package/dist/core/scope/index.js.map +1 -0
- package/package.json +77 -0
- package/schemas/.gitkeep +0 -0
- package/skills/.gitkeep +0 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Update command logic — reconcile each installed skill file against the package.
|
|
3
|
+
* Uses the generic reconcile engine from core/reconcile.ts.
|
|
4
|
+
*/
|
|
5
|
+
import { readFile, writeFile, mkdir, access } from "node:fs/promises";
|
|
6
|
+
import { join, dirname } from "node:path";
|
|
7
|
+
import { hashFile } from "./hash.js";
|
|
8
|
+
import { readManifest, writeManifest } from "./manifest.js";
|
|
9
|
+
import { reconcile } from "../reconcile.js";
|
|
10
|
+
import { createBackupDir, backupFile } from "./backup.js";
|
|
11
|
+
/**
|
|
12
|
+
* Check if a file exists.
|
|
13
|
+
*/
|
|
14
|
+
async function fileExists(path) {
|
|
15
|
+
try {
|
|
16
|
+
await access(path);
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Run the update reconciliation for all skills in the manifest.
|
|
25
|
+
*
|
|
26
|
+
* For each skill file:
|
|
27
|
+
* 1. Compute localHash from the installed file (null if missing)
|
|
28
|
+
* 2. Read originHash from the manifest
|
|
29
|
+
* 3. Compute packageHash from the package source
|
|
30
|
+
* 4. Call reconcile() to determine the action
|
|
31
|
+
* 5. Execute the action (install/overwrite/skip or report conflict)
|
|
32
|
+
*/
|
|
33
|
+
export async function runUpdate(options) {
|
|
34
|
+
const { targetDir, sourceDir, force, version } = options;
|
|
35
|
+
const manifest = await readManifest(targetDir);
|
|
36
|
+
if (!manifest) {
|
|
37
|
+
return {
|
|
38
|
+
conflicts: [],
|
|
39
|
+
updated: [],
|
|
40
|
+
installed: [],
|
|
41
|
+
skipped: [],
|
|
42
|
+
backupDir: null,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const skillsTargetDir = join(targetDir, ".dev-tasks", "skills");
|
|
46
|
+
const skillsSourceDir = join(sourceDir, "skills");
|
|
47
|
+
const conflicts = [];
|
|
48
|
+
const updated = [];
|
|
49
|
+
const installed = [];
|
|
50
|
+
const skipped = [];
|
|
51
|
+
let backupDir = null;
|
|
52
|
+
// Process each skill entry from the manifest
|
|
53
|
+
for (const entry of manifest.skills) {
|
|
54
|
+
const localPath = join(skillsTargetDir, entry.path);
|
|
55
|
+
const packagePath = join(skillsSourceDir, entry.path);
|
|
56
|
+
// Compute local hash (null if file doesn't exist)
|
|
57
|
+
let localHash = null;
|
|
58
|
+
if (await fileExists(localPath)) {
|
|
59
|
+
localHash = await hashFile(localPath);
|
|
60
|
+
}
|
|
61
|
+
// Compute package hash — if the package file doesn't exist, skip this entry
|
|
62
|
+
let packageHash;
|
|
63
|
+
try {
|
|
64
|
+
packageHash = await hashFile(packagePath);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// Package file doesn't exist (skill removed from package?) — skip
|
|
68
|
+
skipped.push({
|
|
69
|
+
path: entry.path,
|
|
70
|
+
action: "skip",
|
|
71
|
+
localHash,
|
|
72
|
+
originHash: entry.origin_sha256,
|
|
73
|
+
packageHash: entry.origin_sha256,
|
|
74
|
+
});
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const action = reconcile(localHash, entry.origin_sha256, packageHash);
|
|
78
|
+
const fileResult = {
|
|
79
|
+
path: entry.path,
|
|
80
|
+
action,
|
|
81
|
+
localHash,
|
|
82
|
+
originHash: entry.origin_sha256,
|
|
83
|
+
packageHash,
|
|
84
|
+
};
|
|
85
|
+
switch (action) {
|
|
86
|
+
case "install": {
|
|
87
|
+
// File doesn't exist locally — copy from package
|
|
88
|
+
const destPath = join(skillsTargetDir, entry.path);
|
|
89
|
+
await mkdir(dirname(destPath), { recursive: true });
|
|
90
|
+
const content = await readFile(packagePath, "utf-8");
|
|
91
|
+
await writeFile(destPath, content, "utf-8");
|
|
92
|
+
installed.push(fileResult);
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case "overwrite": {
|
|
96
|
+
// User hasn't edited — safe to overwrite
|
|
97
|
+
const destPath = join(skillsTargetDir, entry.path);
|
|
98
|
+
const content = await readFile(packagePath, "utf-8");
|
|
99
|
+
await writeFile(destPath, content, "utf-8");
|
|
100
|
+
updated.push(fileResult);
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
case "skip": {
|
|
104
|
+
skipped.push(fileResult);
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
case "conflict": {
|
|
108
|
+
if (force) {
|
|
109
|
+
// Back up the conflicting file, then overwrite
|
|
110
|
+
if (!backupDir) {
|
|
111
|
+
backupDir = await createBackupDir(targetDir);
|
|
112
|
+
}
|
|
113
|
+
await backupFile(backupDir, localPath, entry.path);
|
|
114
|
+
const destPath = join(skillsTargetDir, entry.path);
|
|
115
|
+
const content = await readFile(packagePath, "utf-8");
|
|
116
|
+
await writeFile(destPath, content, "utf-8");
|
|
117
|
+
updated.push({ ...fileResult, action: "overwrite" });
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
conflicts.push(fileResult);
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// Update manifest with new hashes for installed/updated files
|
|
127
|
+
if (installed.length > 0 || updated.length > 0) {
|
|
128
|
+
const updatedManifest = {
|
|
129
|
+
...manifest,
|
|
130
|
+
version,
|
|
131
|
+
installed_at: new Date().toISOString(),
|
|
132
|
+
skills: manifest.skills.map((entry) => {
|
|
133
|
+
const installedResult = [...installed, ...updated].find((r) => r.path === entry.path);
|
|
134
|
+
if (installedResult) {
|
|
135
|
+
return {
|
|
136
|
+
...entry,
|
|
137
|
+
sha256: installedResult.packageHash,
|
|
138
|
+
origin_sha256: installedResult.packageHash,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
return entry;
|
|
142
|
+
}),
|
|
143
|
+
};
|
|
144
|
+
await writeManifest(targetDir, updatedManifest);
|
|
145
|
+
}
|
|
146
|
+
return { conflicts, updated, installed, skipped, backupDir };
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=update.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../../core/distribution/update.ts"],"names":[],"mappings":"A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const object for use across all CLI binaries.
|
|
4
|
+
*/
|
|
5
|
+
export declare const ExitCode: {
|
|
6
|
+
readonly Success: 0;
|
|
7
|
+
readonly GeneralError: 1;
|
|
8
|
+
readonly InvalidUsage: 2;
|
|
9
|
+
readonly NetworkError: 3;
|
|
10
|
+
readonly AuthError: 4;
|
|
11
|
+
readonly NotFound: 5;
|
|
12
|
+
readonly Conflict: 6;
|
|
13
|
+
readonly Timeout: 7;
|
|
14
|
+
readonly RateLimit: 8;
|
|
15
|
+
readonly ValidationError: 9;
|
|
16
|
+
readonly ConfigurationError: 10;
|
|
17
|
+
readonly DependencyError: 11;
|
|
18
|
+
readonly PermissionDenied: 12;
|
|
19
|
+
readonly MissingRequiredField: 13;
|
|
20
|
+
readonly ReconciliationConflict: 14;
|
|
21
|
+
};
|
|
22
|
+
export type ExitCodeValue = (typeof ExitCode)[keyof typeof ExitCode];
|
|
23
|
+
//# sourceMappingURL=exit-codes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit-codes.d.ts","sourceRoot":"","sources":["../../core/exit-codes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;CAgBX,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process exit codes per spec §6.7.
|
|
3
|
+
* Exported as a const object for use across all CLI binaries.
|
|
4
|
+
*/
|
|
5
|
+
export const ExitCode = {
|
|
6
|
+
Success: 0,
|
|
7
|
+
GeneralError: 1,
|
|
8
|
+
InvalidUsage: 2,
|
|
9
|
+
NetworkError: 3,
|
|
10
|
+
AuthError: 4,
|
|
11
|
+
NotFound: 5,
|
|
12
|
+
Conflict: 6,
|
|
13
|
+
Timeout: 7,
|
|
14
|
+
RateLimit: 8,
|
|
15
|
+
ValidationError: 9,
|
|
16
|
+
ConfigurationError: 10,
|
|
17
|
+
DependencyError: 11,
|
|
18
|
+
PermissionDenied: 12,
|
|
19
|
+
MissingRequiredField: 13,
|
|
20
|
+
ReconciliationConflict: 14,
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=exit-codes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit-codes.js","sourceRoot":"","sources":["../../core/exit-codes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,OAAO,EAAE,CAAC;IACV,YAAY,EAAE,CAAC;IACf,YAAY,EAAE,CAAC;IACf,YAAY,EAAE,CAAC;IACf,SAAS,EAAE,CAAC;IACZ,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC;IACX,OAAO,EAAE,CAAC;IACV,SAAS,EAAE,CAAC;IACZ,eAAe,EAAE,CAAC;IAClB,kBAAkB,EAAE,EAAE;IACtB,eAAe,EAAE,EAAE;IACnB,gBAAgB,EAAE,EAAE;IACpB,oBAAoB,EAAE,EAAE;IACxB,sBAAsB,EAAE,EAAE;CAClB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AsyncAPI extraction module barrel export.
|
|
3
|
+
*/
|
|
4
|
+
export type { AsyncApiChannel, AsyncApiConfidence, AsyncApiDocument, AsyncApiExtractionResult, AsyncApiOperation, PayloadSource, ResolvedPayload, ResolvedTopic, TopicDirection, TopicResolutionSource, UnresolvedEntry, } from "./types.js";
|
|
5
|
+
export { extractTopics } from "./topics.js";
|
|
6
|
+
export type { TopicExtractionResult } from "./topics.js";
|
|
7
|
+
export { extractPayloads } from "./payloads.js";
|
|
8
|
+
export type { PayloadExtractionResult } from "./payloads.js";
|
|
9
|
+
export { validateAsyncApi, extractionResultToAsyncApiDocument } from "./validate.js";
|
|
10
|
+
export type { AsyncApiValidationResult, AsyncApiValidationError } from "./validate.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../core/extract/asyncapi/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EACV,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,wBAAwB,EACxB,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,eAAe,GAChB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,YAAY,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAE7D,OAAO,EAAE,gBAAgB,EAAE,kCAAkC,EAAE,MAAM,eAAe,CAAC;AACrF,YAAY,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AsyncAPI extraction module barrel export.
|
|
3
|
+
*/
|
|
4
|
+
export { extractTopics } from "./topics.js";
|
|
5
|
+
export { extractPayloads } from "./payloads.js";
|
|
6
|
+
export { validateAsyncApi, extractionResultToAsyncApiDocument } from "./validate.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../core/extract/asyncapi/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAgBH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE,kCAAkC,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AsyncAPI payload classification.
|
|
3
|
+
* Analyzes producer.send() calls to classify the message payload:
|
|
4
|
+
* - Typed send (generic or interface in the signature) → medium confidence, derive schema
|
|
5
|
+
* - Inline object literal built at call site → low, LLM infers shape
|
|
6
|
+
* - Opaque serialization (Buffer, JSON.stringify(variable)) → low + unresolved[]
|
|
7
|
+
*/
|
|
8
|
+
import type { ResolvedPayload, UnresolvedEntry } from "./types.js";
|
|
9
|
+
/**
|
|
10
|
+
* Result of payload extraction.
|
|
11
|
+
*/
|
|
12
|
+
export interface PayloadExtractionResult {
|
|
13
|
+
payloads: ResolvedPayload[];
|
|
14
|
+
unresolved: UnresolvedEntry[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Extract and classify Kafka message payloads from a repository.
|
|
18
|
+
*/
|
|
19
|
+
export declare function extractPayloads(rootDir: string): PayloadExtractionResult;
|
|
20
|
+
//# sourceMappingURL=payloads.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payloads.d.ts","sourceRoot":"","sources":["../../../../core/extract/asyncapi/payloads.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,UAAU,EAAE,eAAe,EAAE,CAAC;CAC/B;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,uBAAuB,CAiBxE"}
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AsyncAPI payload classification.
|
|
3
|
+
* Analyzes producer.send() calls to classify the message payload:
|
|
4
|
+
* - Typed send (generic or interface in the signature) → medium confidence, derive schema
|
|
5
|
+
* - Inline object literal built at call site → low, LLM infers shape
|
|
6
|
+
* - Opaque serialization (Buffer, JSON.stringify(variable)) → low + unresolved[]
|
|
7
|
+
*/
|
|
8
|
+
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
9
|
+
import { join, relative } from "node:path";
|
|
10
|
+
import ts from "typescript";
|
|
11
|
+
/**
|
|
12
|
+
* Extract and classify Kafka message payloads from a repository.
|
|
13
|
+
*/
|
|
14
|
+
export function extractPayloads(rootDir) {
|
|
15
|
+
const sourceFiles = findTypeScriptFiles(rootDir);
|
|
16
|
+
const program = createProgram(sourceFiles, rootDir);
|
|
17
|
+
const checker = program.getTypeChecker();
|
|
18
|
+
const payloads = [];
|
|
19
|
+
const unresolved = [];
|
|
20
|
+
for (const sourceFile of program.getSourceFiles()) {
|
|
21
|
+
const filePath = sourceFile.fileName;
|
|
22
|
+
if (filePath.includes("node_modules") || !filePath.startsWith(rootDir))
|
|
23
|
+
continue;
|
|
24
|
+
const relPath = relative(rootDir, filePath);
|
|
25
|
+
visitNode(sourceFile, relPath, checker, payloads, unresolved);
|
|
26
|
+
}
|
|
27
|
+
return { payloads, unresolved };
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Visit AST nodes to find producer.send calls and classify payloads.
|
|
31
|
+
*/
|
|
32
|
+
function visitNode(node, filePath, checker, payloads, unresolved) {
|
|
33
|
+
if (ts.isCallExpression(node)) {
|
|
34
|
+
handleSendCall(node, filePath, checker, payloads, unresolved);
|
|
35
|
+
}
|
|
36
|
+
ts.forEachChild(node, (child) => visitNode(child, filePath, checker, payloads, unresolved));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Handle producer.send({ topic, messages }) to classify the payload.
|
|
40
|
+
*/
|
|
41
|
+
function handleSendCall(node, filePath, checker, payloads, unresolved) {
|
|
42
|
+
if (!ts.isPropertyAccessExpression(node.expression))
|
|
43
|
+
return;
|
|
44
|
+
const methodName = node.expression.name.text;
|
|
45
|
+
if (methodName !== "send")
|
|
46
|
+
return;
|
|
47
|
+
if (node.arguments.length < 1)
|
|
48
|
+
return;
|
|
49
|
+
const arg = node.arguments[0];
|
|
50
|
+
if (!ts.isObjectLiteralExpression(arg))
|
|
51
|
+
return;
|
|
52
|
+
// Confirm this is a kafkajs-style send (has topic + messages)
|
|
53
|
+
const topicProp = findProperty(arg, "topic");
|
|
54
|
+
const messagesProp = findProperty(arg, "messages");
|
|
55
|
+
if (!topicProp || !messagesProp)
|
|
56
|
+
return;
|
|
57
|
+
const sourceFile = node.getSourceFile();
|
|
58
|
+
const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
59
|
+
const topicName = resolveTopicName(topicProp);
|
|
60
|
+
// Analyze the messages array for payload classification
|
|
61
|
+
const messagesInit = getPropertyInitializer(messagesProp);
|
|
62
|
+
if (!messagesInit)
|
|
63
|
+
return;
|
|
64
|
+
if (ts.isArrayLiteralExpression(messagesInit)) {
|
|
65
|
+
for (const msgElement of messagesInit.elements) {
|
|
66
|
+
if (!ts.isObjectLiteralExpression(msgElement))
|
|
67
|
+
continue;
|
|
68
|
+
const valueProp = findProperty(msgElement, "value");
|
|
69
|
+
if (!valueProp)
|
|
70
|
+
continue;
|
|
71
|
+
const valueInit = getPropertyInitializer(valueProp);
|
|
72
|
+
if (!valueInit)
|
|
73
|
+
continue;
|
|
74
|
+
classifyPayload(valueInit, topicName, filePath, line + 1, checker, node, payloads, unresolved);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Classify a message value expression into typed/inline/opaque.
|
|
80
|
+
*/
|
|
81
|
+
function classifyPayload(valueExpr, topic, filePath, line, checker, sendCallNode, payloads, unresolved) {
|
|
82
|
+
// Check for Buffer reference → opaque
|
|
83
|
+
if (isBufferReference(valueExpr, checker)) {
|
|
84
|
+
payloads.push({
|
|
85
|
+
topic,
|
|
86
|
+
source: "opaque",
|
|
87
|
+
payload_confidence: "low",
|
|
88
|
+
schema: null,
|
|
89
|
+
file: filePath,
|
|
90
|
+
line,
|
|
91
|
+
});
|
|
92
|
+
unresolved.push({
|
|
93
|
+
file: filePath,
|
|
94
|
+
line,
|
|
95
|
+
reason: "Opaque payload: Buffer value, cannot derive schema",
|
|
96
|
+
snippet: valueExpr.getText().slice(0, 100),
|
|
97
|
+
type: "payload",
|
|
98
|
+
});
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
// Check for JSON.stringify(X) calls
|
|
102
|
+
if (ts.isCallExpression(valueExpr) && isJsonStringify(valueExpr)) {
|
|
103
|
+
const innerArg = valueExpr.arguments[0];
|
|
104
|
+
if (innerArg) {
|
|
105
|
+
// Check if inner arg is an inline object literal → always classify as "inline"
|
|
106
|
+
if (ts.isObjectLiteralExpression(innerArg)) {
|
|
107
|
+
const inlineSchema = inferInlineObjectSchema(innerArg);
|
|
108
|
+
payloads.push({
|
|
109
|
+
topic,
|
|
110
|
+
source: "inline",
|
|
111
|
+
payload_confidence: "low",
|
|
112
|
+
schema: inlineSchema,
|
|
113
|
+
file: filePath,
|
|
114
|
+
line,
|
|
115
|
+
});
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
// Check if inner arg is a typed parameter/variable reference with a known interface
|
|
119
|
+
if (ts.isIdentifier(innerArg) || ts.isPropertyAccessExpression(innerArg)) {
|
|
120
|
+
const typedSchema = resolveTypedArgSchema(innerArg, checker);
|
|
121
|
+
if (typedSchema) {
|
|
122
|
+
payloads.push({
|
|
123
|
+
topic,
|
|
124
|
+
source: "typed",
|
|
125
|
+
payload_confidence: "medium",
|
|
126
|
+
schema: typedSchema,
|
|
127
|
+
file: filePath,
|
|
128
|
+
line,
|
|
129
|
+
});
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// Otherwise opaque (untyped variable or complex expression)
|
|
134
|
+
payloads.push({
|
|
135
|
+
topic,
|
|
136
|
+
source: "opaque",
|
|
137
|
+
payload_confidence: "low",
|
|
138
|
+
schema: null,
|
|
139
|
+
file: filePath,
|
|
140
|
+
line,
|
|
141
|
+
});
|
|
142
|
+
unresolved.push({
|
|
143
|
+
file: filePath,
|
|
144
|
+
line,
|
|
145
|
+
reason: `Opaque payload: JSON.stringify with unresolvable type`,
|
|
146
|
+
snippet: valueExpr.getText().slice(0, 100),
|
|
147
|
+
type: "payload",
|
|
148
|
+
});
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// Direct identifier/expression as value → check type
|
|
153
|
+
if (ts.isIdentifier(valueExpr)) {
|
|
154
|
+
const typedSchema = resolveTypedArgSchema(valueExpr, checker);
|
|
155
|
+
if (typedSchema) {
|
|
156
|
+
payloads.push({
|
|
157
|
+
topic,
|
|
158
|
+
source: "typed",
|
|
159
|
+
payload_confidence: "medium",
|
|
160
|
+
schema: typedSchema,
|
|
161
|
+
file: filePath,
|
|
162
|
+
line,
|
|
163
|
+
});
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
// Opaque variable
|
|
167
|
+
payloads.push({
|
|
168
|
+
topic,
|
|
169
|
+
source: "opaque",
|
|
170
|
+
payload_confidence: "low",
|
|
171
|
+
schema: null,
|
|
172
|
+
file: filePath,
|
|
173
|
+
line,
|
|
174
|
+
});
|
|
175
|
+
unresolved.push({
|
|
176
|
+
file: filePath,
|
|
177
|
+
line,
|
|
178
|
+
reason: `Opaque payload: unresolvable variable type`,
|
|
179
|
+
snippet: valueExpr.getText().slice(0, 100),
|
|
180
|
+
type: "payload",
|
|
181
|
+
});
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
// Inline object literal directly as value
|
|
185
|
+
if (ts.isObjectLiteralExpression(valueExpr)) {
|
|
186
|
+
const inlineSchema = inferInlineObjectSchema(valueExpr);
|
|
187
|
+
payloads.push({
|
|
188
|
+
topic,
|
|
189
|
+
source: "inline",
|
|
190
|
+
payload_confidence: "low",
|
|
191
|
+
schema: inlineSchema,
|
|
192
|
+
file: filePath,
|
|
193
|
+
line,
|
|
194
|
+
});
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
// Default: opaque
|
|
198
|
+
payloads.push({
|
|
199
|
+
topic,
|
|
200
|
+
source: "opaque",
|
|
201
|
+
payload_confidence: "low",
|
|
202
|
+
schema: null,
|
|
203
|
+
file: filePath,
|
|
204
|
+
line,
|
|
205
|
+
});
|
|
206
|
+
unresolved.push({
|
|
207
|
+
file: filePath,
|
|
208
|
+
line,
|
|
209
|
+
reason: `Opaque payload: cannot classify expression`,
|
|
210
|
+
snippet: valueExpr.getText().slice(0, 100),
|
|
211
|
+
type: "payload",
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Check if an expression is a Buffer reference.
|
|
216
|
+
*/
|
|
217
|
+
function isBufferReference(expr, checker) {
|
|
218
|
+
// Direct identifier named 'data' with Buffer type annotation
|
|
219
|
+
if (ts.isIdentifier(expr)) {
|
|
220
|
+
const symbol = checker.getSymbolAtLocation(expr);
|
|
221
|
+
if (symbol && symbol.valueDeclaration) {
|
|
222
|
+
const decl = symbol.valueDeclaration;
|
|
223
|
+
if (ts.isParameter(decl) && decl.type) {
|
|
224
|
+
const typeText = decl.type.getText();
|
|
225
|
+
if (typeText === "Buffer" || typeText === "Uint8Array")
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// Also check the type from checker
|
|
230
|
+
const type = checker.getTypeAtLocation(expr);
|
|
231
|
+
const typeName = checker.typeToString(type);
|
|
232
|
+
if (typeName === "Buffer" || typeName.includes("Buffer"))
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Check if a call expression is JSON.stringify().
|
|
239
|
+
*/
|
|
240
|
+
function isJsonStringify(call) {
|
|
241
|
+
if (!ts.isPropertyAccessExpression(call.expression))
|
|
242
|
+
return false;
|
|
243
|
+
const methodName = call.expression.name.text;
|
|
244
|
+
if (methodName !== "stringify")
|
|
245
|
+
return false;
|
|
246
|
+
const obj = call.expression.expression;
|
|
247
|
+
return ts.isIdentifier(obj) && obj.text === "JSON";
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Try to resolve a typed argument to a JSON Schema.
|
|
251
|
+
* Works when the argument has an interface/type annotation.
|
|
252
|
+
*/
|
|
253
|
+
function resolveTypedArgSchema(expr, checker) {
|
|
254
|
+
const type = checker.getTypeAtLocation(expr);
|
|
255
|
+
const typeStr = checker.typeToString(type);
|
|
256
|
+
// Skip 'any', 'unknown', primitive types
|
|
257
|
+
if (typeStr === "any" || typeStr === "unknown" || typeStr === "never")
|
|
258
|
+
return null;
|
|
259
|
+
if (typeStr === "string" ||
|
|
260
|
+
typeStr === "number" ||
|
|
261
|
+
typeStr === "boolean" ||
|
|
262
|
+
typeStr === "Buffer") {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
// Try to extract properties from the type
|
|
266
|
+
const properties = type.getProperties();
|
|
267
|
+
if (properties.length === 0)
|
|
268
|
+
return null;
|
|
269
|
+
const schema = { type: "object", properties: {} };
|
|
270
|
+
const props = {};
|
|
271
|
+
const required = [];
|
|
272
|
+
for (const prop of properties) {
|
|
273
|
+
const propType = checker.getTypeOfSymbol(prop);
|
|
274
|
+
const propTypeStr = checker.typeToString(propType);
|
|
275
|
+
props[prop.name] = { type: tsTypeToJsonSchemaType(propTypeStr) };
|
|
276
|
+
if (!(prop.flags & ts.SymbolFlags.Optional)) {
|
|
277
|
+
required.push(prop.name);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
schema.properties = props;
|
|
281
|
+
if (required.length > 0)
|
|
282
|
+
schema.required = required;
|
|
283
|
+
return schema;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Infer a schema from an inline object literal.
|
|
287
|
+
*/
|
|
288
|
+
function inferInlineObjectSchema(obj) {
|
|
289
|
+
const properties = {};
|
|
290
|
+
for (const prop of obj.properties) {
|
|
291
|
+
if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name)) {
|
|
292
|
+
const name = prop.name.text;
|
|
293
|
+
const valueType = inferLiteralType(prop.initializer);
|
|
294
|
+
properties[name] = { type: valueType };
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return { type: "object", properties };
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Infer the JSON Schema type of a literal expression.
|
|
301
|
+
*/
|
|
302
|
+
function inferLiteralType(expr) {
|
|
303
|
+
if (ts.isStringLiteral(expr) || ts.isNoSubstitutionTemplateLiteral(expr))
|
|
304
|
+
return "string";
|
|
305
|
+
if (ts.isNumericLiteral(expr))
|
|
306
|
+
return "number";
|
|
307
|
+
if (expr.kind === ts.SyntaxKind.TrueKeyword || expr.kind === ts.SyntaxKind.FalseKeyword)
|
|
308
|
+
return "boolean";
|
|
309
|
+
if (ts.isArrayLiteralExpression(expr))
|
|
310
|
+
return "array";
|
|
311
|
+
if (ts.isObjectLiteralExpression(expr))
|
|
312
|
+
return "object";
|
|
313
|
+
return "string";
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Map TypeScript type strings to JSON Schema types.
|
|
317
|
+
*/
|
|
318
|
+
function tsTypeToJsonSchemaType(tsType) {
|
|
319
|
+
if (tsType === "string")
|
|
320
|
+
return "string";
|
|
321
|
+
if (tsType === "number")
|
|
322
|
+
return "number";
|
|
323
|
+
if (tsType === "boolean")
|
|
324
|
+
return "boolean";
|
|
325
|
+
if (tsType.startsWith("Array") || tsType.endsWith("[]"))
|
|
326
|
+
return "array";
|
|
327
|
+
return "string";
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Resolve the topic name from a topic property (best-effort for payload association).
|
|
331
|
+
*/
|
|
332
|
+
function resolveTopicName(prop) {
|
|
333
|
+
const init = getPropertyInitializer(prop);
|
|
334
|
+
if (!init)
|
|
335
|
+
return null;
|
|
336
|
+
if (ts.isStringLiteral(init) || ts.isNoSubstitutionTemplateLiteral(init)) {
|
|
337
|
+
return init.text;
|
|
338
|
+
}
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
// --- Utility helpers ---
|
|
342
|
+
function findProperty(obj, name) {
|
|
343
|
+
return obj.properties.find((p) => {
|
|
344
|
+
if (ts.isPropertyAssignment(p) && ts.isIdentifier(p.name)) {
|
|
345
|
+
return p.name.text === name;
|
|
346
|
+
}
|
|
347
|
+
if (ts.isShorthandPropertyAssignment(p)) {
|
|
348
|
+
return p.name.text === name;
|
|
349
|
+
}
|
|
350
|
+
return false;
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
function getPropertyInitializer(prop) {
|
|
354
|
+
if (ts.isPropertyAssignment(prop)) {
|
|
355
|
+
return prop.initializer;
|
|
356
|
+
}
|
|
357
|
+
if (ts.isShorthandPropertyAssignment(prop)) {
|
|
358
|
+
return prop.name;
|
|
359
|
+
}
|
|
360
|
+
return undefined;
|
|
361
|
+
}
|
|
362
|
+
// --- File and program utilities ---
|
|
363
|
+
function findTypeScriptFiles(rootDir) {
|
|
364
|
+
const files = [];
|
|
365
|
+
function walk(dir) {
|
|
366
|
+
let entries;
|
|
367
|
+
try {
|
|
368
|
+
entries = readdirSync(dir);
|
|
369
|
+
}
|
|
370
|
+
catch {
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
for (const entry of entries) {
|
|
374
|
+
if (entry === "node_modules" || entry === "dist" || entry === ".git")
|
|
375
|
+
continue;
|
|
376
|
+
const fullPath = join(dir, entry);
|
|
377
|
+
try {
|
|
378
|
+
const stat = statSync(fullPath);
|
|
379
|
+
if (stat.isDirectory()) {
|
|
380
|
+
walk(fullPath);
|
|
381
|
+
}
|
|
382
|
+
else if (entry.endsWith(".ts") &&
|
|
383
|
+
!entry.endsWith(".d.ts") &&
|
|
384
|
+
!entry.endsWith(".test.ts") &&
|
|
385
|
+
!entry.endsWith(".spec.ts")) {
|
|
386
|
+
files.push(fullPath);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
catch {
|
|
390
|
+
// Skip unreadable
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
walk(rootDir);
|
|
395
|
+
return files;
|
|
396
|
+
}
|
|
397
|
+
function createProgram(files, rootDir) {
|
|
398
|
+
const configPath = join(rootDir, "tsconfig.json");
|
|
399
|
+
let compilerOptions = {
|
|
400
|
+
target: ts.ScriptTarget.ES2022,
|
|
401
|
+
module: ts.ModuleKind.NodeNext,
|
|
402
|
+
moduleResolution: ts.ModuleResolutionKind.NodeNext,
|
|
403
|
+
strict: true,
|
|
404
|
+
esModuleInterop: true,
|
|
405
|
+
skipLibCheck: true,
|
|
406
|
+
noEmit: true,
|
|
407
|
+
};
|
|
408
|
+
try {
|
|
409
|
+
const configText = readFileSync(configPath, "utf-8");
|
|
410
|
+
const parsedConfig = ts.parseConfigFileTextToJson(configPath, configText);
|
|
411
|
+
if (parsedConfig.config) {
|
|
412
|
+
const parsed = ts.parseJsonConfigFileContent(parsedConfig.config, ts.sys, rootDir);
|
|
413
|
+
compilerOptions = parsed.options;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
catch {
|
|
417
|
+
// Use defaults
|
|
418
|
+
}
|
|
419
|
+
return ts.createProgram(files, compilerOptions);
|
|
420
|
+
}
|
|
421
|
+
//# sourceMappingURL=payloads.js.map
|