@workos/oagen 0.1.1 → 0.3.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/cli/index.d.mts +2 -0
- package/dist/cli/index.mjs +6233 -0
- package/dist/cli/index.mjs.map +1 -0
- package/dist/compat/{index.d.ts → index.d.mts} +43 -114
- package/dist/compat/index.d.mts.map +1 -0
- package/dist/compat/index.mjs +4562 -0
- package/dist/compat/index.mjs.map +1 -0
- package/dist/diff-Cn6S74vV.mjs +2432 -0
- package/dist/diff-Cn6S74vV.mjs.map +1 -0
- package/dist/differ-B6472Yef.mjs +1100 -0
- package/dist/differ-B6472Yef.mjs.map +1 -0
- package/dist/index.d.mts +324 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1553 -0
- package/dist/index.mjs.map +1 -0
- package/dist/scripts/smoke/baseline.d.mts +1 -0
- package/dist/scripts/smoke/baseline.mjs +1951 -0
- package/dist/scripts/smoke/baseline.mjs.map +1 -0
- package/dist/scripts/smoke/sdk-test.d.mts +1 -0
- package/dist/scripts/smoke/sdk-test.mjs +111 -0
- package/dist/scripts/smoke/sdk-test.mjs.map +1 -0
- package/dist/smoke.d.mts +331 -0
- package/dist/smoke.d.mts.map +1 -0
- package/dist/smoke.mjs +2119 -0
- package/dist/smoke.mjs.map +1 -0
- package/dist/tree-sitter-DFRXfWg9.mjs +394 -0
- package/dist/tree-sitter-DFRXfWg9.mjs.map +1 -0
- package/dist/types-O25qZxMl.d.mts +397 -0
- package/dist/types-O25qZxMl.d.mts.map +1 -0
- package/dist/verify/index.d.mts +82 -0
- package/dist/verify/index.d.mts.map +1 -0
- package/dist/verify/index.mjs +327 -0
- package/dist/verify/index.mjs.map +1 -0
- package/package.json +19 -16
- package/dist/chunk-2JXFTDTO.js +0 -1669
- package/dist/chunk-CIX5NOBF.js +0 -263
- package/dist/chunk-IJ5E5AE7.js +0 -1040
- package/dist/cli/index.js +0 -5322
- package/dist/compat/index.js +0 -4491
- package/dist/index.d.ts +0 -277
- package/dist/index.js +0 -1565
- package/dist/scripts/smoke/baseline.js +0 -1813
- package/dist/scripts/smoke/sdk-test.js +0 -93
- package/dist/smoke.js +0 -2025
- package/dist/types-B5t9O9Wm.d.ts +0 -367
- package/dist/verify/index.d.ts +0 -76
- package/dist/verify/index.js +0 -336
package/dist/verify/index.js
DELETED
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
diffSpecs,
|
|
3
|
-
generate,
|
|
4
|
-
getEmitter
|
|
5
|
-
} from "../chunk-2JXFTDTO.js";
|
|
6
|
-
import {
|
|
7
|
-
buildOverlayLookup,
|
|
8
|
-
diffSurfaces,
|
|
9
|
-
filterSurface,
|
|
10
|
-
getExtractor,
|
|
11
|
-
patchOverlay,
|
|
12
|
-
specDerivedEnumValues,
|
|
13
|
-
specDerivedFieldPaths,
|
|
14
|
-
specDerivedMethodPaths,
|
|
15
|
-
specDerivedNames
|
|
16
|
-
} from "../chunk-IJ5E5AE7.js";
|
|
17
|
-
import {
|
|
18
|
-
CommandError
|
|
19
|
-
} from "../chunk-CIX5NOBF.js";
|
|
20
|
-
|
|
21
|
-
// src/verify/run-compat-check.ts
|
|
22
|
-
async function runCompatCheck(baseline, outputDir, lang, spec) {
|
|
23
|
-
const extractor = getExtractor(lang);
|
|
24
|
-
const candidate = await extractor.extract(outputDir);
|
|
25
|
-
let scopedBaseline = baseline;
|
|
26
|
-
let scopedToSpec = false;
|
|
27
|
-
let scopedSymbolCount;
|
|
28
|
-
if (spec) {
|
|
29
|
-
const allowed = specDerivedNames(spec, extractor.hints);
|
|
30
|
-
const fieldPaths = specDerivedFieldPaths(spec, extractor.hints);
|
|
31
|
-
const methodPaths = specDerivedMethodPaths(spec);
|
|
32
|
-
const enumVals = specDerivedEnumValues(spec);
|
|
33
|
-
scopedBaseline = filterSurface(baseline, allowed, { fieldPaths, methodPaths, enumValues: enumVals });
|
|
34
|
-
scopedToSpec = true;
|
|
35
|
-
scopedSymbolCount = Object.keys(scopedBaseline.interfaces).length + Object.keys(scopedBaseline.classes).length + Object.keys(scopedBaseline.typeAliases).length + Object.keys(scopedBaseline.enums).length;
|
|
36
|
-
}
|
|
37
|
-
const diff = diffSurfaces(scopedBaseline, candidate, extractor.hints);
|
|
38
|
-
const passed = diff.violations.every((v) => v.severity !== "breaking");
|
|
39
|
-
return { passed, diff, scopedToSpec, scopedSymbolCount };
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// src/verify/run-overlay-retry-loop.ts
|
|
43
|
-
import { existsSync, readFileSync, readdirSync, unlinkSync, statSync, openSync, readSync, closeSync } from "fs";
|
|
44
|
-
import * as path from "path";
|
|
45
|
-
var PATCHABLE_CATEGORIES = /* @__PURE__ */ new Set(["public-api", "export-structure"]);
|
|
46
|
-
var GENERATED_MARKERS = ["Code generated by oagen", "auto-generated by oagen", "This file is auto-generated"];
|
|
47
|
-
function cleanGeneratedFiles(dir) {
|
|
48
|
-
let entries;
|
|
49
|
-
try {
|
|
50
|
-
entries = readdirSync(dir);
|
|
51
|
-
} catch {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
for (const entry of entries) {
|
|
55
|
-
const full = path.join(dir, entry);
|
|
56
|
-
let stat;
|
|
57
|
-
try {
|
|
58
|
-
stat = statSync(full);
|
|
59
|
-
} catch {
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
if (stat.isDirectory()) {
|
|
63
|
-
cleanGeneratedFiles(full);
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
if (entry.endsWith(".json") || entry.endsWith(".lock")) continue;
|
|
67
|
-
try {
|
|
68
|
-
const buf = Buffer.alloc(200);
|
|
69
|
-
const fd = openSync(full, "r");
|
|
70
|
-
try {
|
|
71
|
-
readSync(fd, buf, 0, 200, 0);
|
|
72
|
-
} finally {
|
|
73
|
-
closeSync(fd);
|
|
74
|
-
}
|
|
75
|
-
const header = buf.toString("utf-8");
|
|
76
|
-
if (GENERATED_MARKERS.some((m) => header.includes(m))) {
|
|
77
|
-
unlinkSync(full);
|
|
78
|
-
}
|
|
79
|
-
} catch {
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function loadManifestFromDir(outputDir) {
|
|
84
|
-
const manifestPath = path.join(outputDir, "smoke-manifest.json");
|
|
85
|
-
if (!existsSync(manifestPath)) return void 0;
|
|
86
|
-
try {
|
|
87
|
-
const parsed = JSON.parse(readFileSync(manifestPath, "utf-8"));
|
|
88
|
-
if (Array.isArray(parsed)) return parsed;
|
|
89
|
-
if (typeof parsed === "object" && parsed !== null) {
|
|
90
|
-
return Object.entries(parsed).map(([httpKey, value]) => {
|
|
91
|
-
const spaceIdx = httpKey.indexOf(" ");
|
|
92
|
-
const httpMethod = httpKey.slice(0, spaceIdx);
|
|
93
|
-
const httpPath = httpKey.slice(spaceIdx + 1);
|
|
94
|
-
const v = value;
|
|
95
|
-
return {
|
|
96
|
-
operationId: "",
|
|
97
|
-
sdkResourceProperty: v.service ?? "",
|
|
98
|
-
sdkMethodName: v.sdkMethod ?? "",
|
|
99
|
-
httpMethod,
|
|
100
|
-
path: httpPath,
|
|
101
|
-
pathParams: [],
|
|
102
|
-
bodyFields: [],
|
|
103
|
-
queryFields: []
|
|
104
|
-
};
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
} catch {
|
|
108
|
-
}
|
|
109
|
-
return void 0;
|
|
110
|
-
}
|
|
111
|
-
async function runOverlayRetryLoop(opts) {
|
|
112
|
-
const { baseline, parsedSpec, outputDir, lang, maxRetries, namespace, onRetry } = opts;
|
|
113
|
-
const manifest = loadManifestFromDir(outputDir);
|
|
114
|
-
const extractor = getExtractor(lang);
|
|
115
|
-
let overlay = buildOverlayLookup(baseline, manifest, parsedSpec, extractor.hints);
|
|
116
|
-
let prevPreserved = -1;
|
|
117
|
-
const patchedPerIteration = [];
|
|
118
|
-
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
119
|
-
const compatResult2 = await runCompatCheck(baseline, outputDir, lang, parsedSpec);
|
|
120
|
-
if (compatResult2.passed) {
|
|
121
|
-
return {
|
|
122
|
-
status: "passed",
|
|
123
|
-
attempts: attempt,
|
|
124
|
-
patchedPerIteration,
|
|
125
|
-
compatResult: compatResult2
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
if (attempt === maxRetries) {
|
|
129
|
-
return {
|
|
130
|
-
status: "max-retries",
|
|
131
|
-
attempts: attempt,
|
|
132
|
-
patchedPerIteration,
|
|
133
|
-
compatResult: compatResult2
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
const patchable = compatResult2.diff.violations.filter((v) => PATCHABLE_CATEGORIES.has(v.category));
|
|
137
|
-
if (patchable.length === 0) {
|
|
138
|
-
return {
|
|
139
|
-
status: "no-patchable",
|
|
140
|
-
attempts: attempt,
|
|
141
|
-
patchedPerIteration,
|
|
142
|
-
compatResult: compatResult2
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
const currentPreserved = compatResult2.diff.preservedSymbols;
|
|
146
|
-
if (attempt > 0 && currentPreserved <= prevPreserved) {
|
|
147
|
-
return {
|
|
148
|
-
status: "stalled",
|
|
149
|
-
attempts: attempt,
|
|
150
|
-
patchedPerIteration,
|
|
151
|
-
compatResult: compatResult2
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
prevPreserved = currentPreserved;
|
|
155
|
-
patchedPerIteration.push(patchable.length);
|
|
156
|
-
onRetry?.(attempt + 1, maxRetries, patchable.length);
|
|
157
|
-
overlay = patchOverlay(overlay, patchable, baseline);
|
|
158
|
-
cleanGeneratedFiles(outputDir);
|
|
159
|
-
const emitter = getEmitter(lang);
|
|
160
|
-
await generate(parsedSpec, emitter, {
|
|
161
|
-
namespace: namespace ?? parsedSpec.name,
|
|
162
|
-
outputDir,
|
|
163
|
-
overlayLookup: overlay,
|
|
164
|
-
apiSurface: baseline
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
const compatResult = await runCompatCheck(baseline, outputDir, lang, parsedSpec);
|
|
168
|
-
return {
|
|
169
|
-
status: "max-retries",
|
|
170
|
-
attempts: maxRetries,
|
|
171
|
-
patchedPerIteration,
|
|
172
|
-
compatResult
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// src/compat/staleness.ts
|
|
177
|
-
function detectStaleSymbols(liveSurface, oldSpec, newSpec, hints) {
|
|
178
|
-
const violations = [];
|
|
179
|
-
const oldNames = specDerivedNames(oldSpec, hints);
|
|
180
|
-
const newNames = specDerivedNames(newSpec, hints);
|
|
181
|
-
const removedNames = /* @__PURE__ */ new Set();
|
|
182
|
-
for (const name of oldNames) {
|
|
183
|
-
if (!newNames.has(name)) removedNames.add(name);
|
|
184
|
-
}
|
|
185
|
-
for (const name of removedNames) {
|
|
186
|
-
if (liveSurface.classes[name]) {
|
|
187
|
-
violations.push({
|
|
188
|
-
category: "staleness",
|
|
189
|
-
severity: "warning",
|
|
190
|
-
symbolPath: name,
|
|
191
|
-
baseline: name,
|
|
192
|
-
candidate: "(removed from spec)",
|
|
193
|
-
message: `Class "${name}" is no longer defined in the OpenAPI spec`
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
if (liveSurface.interfaces[name]) {
|
|
197
|
-
violations.push({
|
|
198
|
-
category: "staleness",
|
|
199
|
-
severity: "warning",
|
|
200
|
-
symbolPath: name,
|
|
201
|
-
baseline: name,
|
|
202
|
-
candidate: "(removed from spec)",
|
|
203
|
-
message: `Interface "${name}" is no longer defined in the OpenAPI spec`
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
if (liveSurface.typeAliases[name]) {
|
|
207
|
-
violations.push({
|
|
208
|
-
category: "staleness",
|
|
209
|
-
severity: "warning",
|
|
210
|
-
symbolPath: name,
|
|
211
|
-
baseline: name,
|
|
212
|
-
candidate: "(removed from spec)",
|
|
213
|
-
message: `Type alias "${name}" is no longer defined in the OpenAPI spec`
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
if (liveSurface.enums[name]) {
|
|
217
|
-
violations.push({
|
|
218
|
-
category: "staleness",
|
|
219
|
-
severity: "warning",
|
|
220
|
-
symbolPath: name,
|
|
221
|
-
baseline: name,
|
|
222
|
-
candidate: "(removed from spec)",
|
|
223
|
-
message: `Enum "${name}" is no longer defined in the OpenAPI spec`
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
const oldFieldPaths = specDerivedFieldPaths(oldSpec, hints);
|
|
228
|
-
const newFieldPaths = specDerivedFieldPaths(newSpec, hints);
|
|
229
|
-
for (const fieldPath of oldFieldPaths) {
|
|
230
|
-
if (newFieldPaths.has(fieldPath)) continue;
|
|
231
|
-
const [modelName, fieldName] = fieldPath.split(".");
|
|
232
|
-
if (removedNames.has(modelName)) continue;
|
|
233
|
-
const iface = liveSurface.interfaces[modelName];
|
|
234
|
-
if (iface?.fields[fieldName]) {
|
|
235
|
-
violations.push({
|
|
236
|
-
category: "staleness",
|
|
237
|
-
severity: "warning",
|
|
238
|
-
symbolPath: fieldPath,
|
|
239
|
-
baseline: fieldName,
|
|
240
|
-
candidate: "(removed from spec)",
|
|
241
|
-
message: `Field "${fieldPath}" is no longer defined in the OpenAPI spec`
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
const diff = diffSpecs(oldSpec, newSpec);
|
|
246
|
-
for (const change of diff.changes) {
|
|
247
|
-
if (change.kind === "operation-removed") {
|
|
248
|
-
const cls = liveSurface.classes[change.serviceName];
|
|
249
|
-
if (cls?.methods[change.operationName]) {
|
|
250
|
-
violations.push({
|
|
251
|
-
category: "staleness",
|
|
252
|
-
severity: "warning",
|
|
253
|
-
symbolPath: `${change.serviceName}.${change.operationName}`,
|
|
254
|
-
baseline: change.operationName,
|
|
255
|
-
candidate: "(removed from spec)",
|
|
256
|
-
message: `Method "${change.serviceName}.${change.operationName}" is no longer defined in the OpenAPI spec`
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
return violations;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// src/verify/run-staleness-check.ts
|
|
265
|
-
function runStalenessCheck(baseline, oldSpec, newSpec, lang) {
|
|
266
|
-
const extractor = getExtractor(lang);
|
|
267
|
-
const violations = detectStaleSymbols(baseline, oldSpec, newSpec, extractor.hints);
|
|
268
|
-
return { violations };
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// src/verify/run-smoke-check.ts
|
|
272
|
-
import { execFileSync } from "child_process";
|
|
273
|
-
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
274
|
-
import { fileURLToPath } from "url";
|
|
275
|
-
import * as path2 from "path";
|
|
276
|
-
var __filename = fileURLToPath(import.meta.url);
|
|
277
|
-
var __dirname = path2.dirname(__filename);
|
|
278
|
-
function resolveScript(scriptRelPath) {
|
|
279
|
-
const distScript = path2.resolve(__dirname, "..", "..", "dist", "scripts", scriptRelPath.replace(/\.ts$/, ".js"));
|
|
280
|
-
if (existsSync2(distScript)) {
|
|
281
|
-
return { bin: "node", script: distScript };
|
|
282
|
-
}
|
|
283
|
-
const srcScript = path2.resolve(__dirname, "..", "..", "scripts", scriptRelPath);
|
|
284
|
-
return { bin: "npx", script: srcScript };
|
|
285
|
-
}
|
|
286
|
-
function runPackagedScript(scriptRelPath, args) {
|
|
287
|
-
const { bin, script } = resolveScript(scriptRelPath);
|
|
288
|
-
const fullArgs = bin === "npx" ? ["tsx", script, ...args] : [script, ...args];
|
|
289
|
-
execFileSync(bin, fullArgs, { stdio: "inherit", env: process.env });
|
|
290
|
-
}
|
|
291
|
-
function runSmokeCheck(opts) {
|
|
292
|
-
const { spec, lang, output, rawResults, smokeConfig, smokeRunner } = opts;
|
|
293
|
-
let baselinePath = rawResults ?? "smoke-results-raw.json";
|
|
294
|
-
let generatedBaseline = false;
|
|
295
|
-
if (!rawResults && !existsSync2("smoke-results-raw.json")) {
|
|
296
|
-
if (!spec) {
|
|
297
|
-
throw new CommandError(
|
|
298
|
-
"error: --spec <path> or OPENAPI_SPEC_PATH env var is required when no raw baseline exists",
|
|
299
|
-
"",
|
|
300
|
-
1
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
try {
|
|
304
|
-
runPackagedScript("smoke/baseline.ts", ["--spec", spec]);
|
|
305
|
-
} catch {
|
|
306
|
-
throw new CommandError("Baseline generation failed", "", 1);
|
|
307
|
-
}
|
|
308
|
-
baselinePath = "smoke-results-spec-baseline.json";
|
|
309
|
-
generatedBaseline = true;
|
|
310
|
-
}
|
|
311
|
-
const smokeArgs = ["--lang", lang, "--sdk-path", output, "--raw-results", baselinePath];
|
|
312
|
-
if (spec) smokeArgs.push("--spec", spec);
|
|
313
|
-
if (smokeConfig) smokeArgs.push("--smoke-config", smokeConfig);
|
|
314
|
-
try {
|
|
315
|
-
if (smokeRunner) {
|
|
316
|
-
const bin = smokeRunner.endsWith(".ts") ? "npx" : "node";
|
|
317
|
-
const fullArgs = bin === "npx" ? ["tsx", smokeRunner, ...smokeArgs] : [smokeRunner, ...smokeArgs];
|
|
318
|
-
execFileSync(bin, fullArgs, { stdio: "inherit", env: process.env });
|
|
319
|
-
} else {
|
|
320
|
-
runPackagedScript("smoke/sdk-test.ts", smokeArgs);
|
|
321
|
-
}
|
|
322
|
-
return { passed: true, baselinePath, generatedBaseline };
|
|
323
|
-
} catch {
|
|
324
|
-
if (existsSync2("smoke-compile-errors.json")) {
|
|
325
|
-
return { passed: false, compileErrors: true, baselinePath, generatedBaseline };
|
|
326
|
-
}
|
|
327
|
-
const findingsCount = existsSync2("smoke-diff-findings.json") ? JSON.parse(readFileSync2("smoke-diff-findings.json", "utf-8")).length : void 0;
|
|
328
|
-
return { passed: false, findingsCount, baselinePath, generatedBaseline };
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
export {
|
|
332
|
-
runCompatCheck,
|
|
333
|
-
runOverlayRetryLoop,
|
|
334
|
-
runSmokeCheck,
|
|
335
|
-
runStalenessCheck
|
|
336
|
-
};
|