@workos/oagen 0.22.3 → 0.22.5
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.md +1 -1
- package/dist/cli/index.mjs +150 -2
- package/dist/cli/index.mjs.map +1 -1
- package/dist/{diff-DkeDowzz.mjs → diff-CQzcGuFJ.mjs} +151 -3
- package/dist/diff-CQzcGuFJ.mjs.map +1 -0
- package/dist/index.mjs +1 -1
- package/dist/verify/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/diff-DkeDowzz.mjs.map +0 -1
|
@@ -2312,8 +2312,23 @@ async function overwriteWithPreservedRegions(existingContent, generatedContent,
|
|
|
2312
2312
|
}
|
|
2313
2313
|
replacements.sort((a, b) => b.startLine - a.startLine);
|
|
2314
2314
|
for (const rep of replacements) result.splice(rep.startLine, rep.endLine - rep.startLine, ...rep.content);
|
|
2315
|
+
let regionDeclarationEdits = 0;
|
|
2316
|
+
{
|
|
2317
|
+
const topLevelEntries = blocksByClass.get("");
|
|
2318
|
+
if (topLevelEntries) {
|
|
2319
|
+
const alreadyPlaced = handledBlockKeys.has("");
|
|
2320
|
+
const remaining = [];
|
|
2321
|
+
for (const entry of topLevelEntries) {
|
|
2322
|
+
const outcome = await applyRegionDeclarationOverride(result, entry.lines, language, !alreadyPlaced);
|
|
2323
|
+
if (outcome.edited) regionDeclarationEdits++;
|
|
2324
|
+
if (!alreadyPlaced && !outcome.placed) remaining.push(entry);
|
|
2325
|
+
}
|
|
2326
|
+
if (!alreadyPlaced) if (remaining.length === 0) blocksByClass.delete("");
|
|
2327
|
+
else blocksByClass.set("", remaining);
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2315
2330
|
let effectiveClassEndLines = classEndLines;
|
|
2316
|
-
if (replacedClasses.size > 0) effectiveClassEndLines = await extractClassEndLines(result.join("\n"), language);
|
|
2331
|
+
if (replacedClasses.size > 0 || regionDeclarationEdits > 0) effectiveClassEndLines = await extractClassEndLines(result.join("\n"), language);
|
|
2317
2332
|
const insertions = [];
|
|
2318
2333
|
let insertionOrder = 0;
|
|
2319
2334
|
for (const [className, classBlocks] of blocksByClass) {
|
|
@@ -2344,7 +2359,7 @@ async function overwriteWithPreservedRegions(existingContent, generatedContent,
|
|
|
2344
2359
|
}
|
|
2345
2360
|
if (entry.lines.some((l) => /^\s*import\s/.test(l))) while (insertLine >= 2 && result[insertLine - 1]?.trim() === "" && /^\s*(import|using|from)\s/.test(result[insertLine - 2] ?? "")) insertLine--;
|
|
2346
2361
|
const prevLine = insertLine > 0 ? result[insertLine - 1]?.trimStart() ?? "" : "";
|
|
2347
|
-
const blockContent = /^import\s/.test(prevLine) || /^
|
|
2362
|
+
const blockContent = /^import\s/.test(prevLine) || /^from\s/.test(prevLine) || insertLine > 0 && prevLine === "" ? [...entry.lines] : ["", ...entry.lines];
|
|
2348
2363
|
if ((result[insertLine]?.trimStart() ?? "").startsWith("///")) blockContent.push("");
|
|
2349
2364
|
insertions.push({
|
|
2350
2365
|
line: insertLine,
|
|
@@ -2439,6 +2454,139 @@ function findClassDeclarationStart(lines, className, beforeLine) {
|
|
|
2439
2454
|
return -1;
|
|
2440
2455
|
}
|
|
2441
2456
|
/**
|
|
2457
|
+
* Conservative top-level declaration matcher for ignore-block content.
|
|
2458
|
+
* Matches column-0 declarations like `export interface X`, `type X = …`,
|
|
2459
|
+
* `const X = …`, `function X(…)`, `class X` (export optional). Names found
|
|
2460
|
+
* here are only acted on when the language's merge adapter also reports a
|
|
2461
|
+
* generated top-level statement with the same key, so false positives are
|
|
2462
|
+
* filtered by the real parser.
|
|
2463
|
+
*/
|
|
2464
|
+
const REGION_DECLARATION_PATTERN = /^(?:export\s+)?(?:declare\s+)?(?:interface|type|enum|class|const|let|var|async\s+function|function)\s+([A-Za-z_$][\w$]*)/;
|
|
2465
|
+
/** Extract top-level symbol names declared inside an ignore block's lines. */
|
|
2466
|
+
function collectRegionDeclaredNames(blockLines) {
|
|
2467
|
+
const names = /* @__PURE__ */ new Set();
|
|
2468
|
+
for (const line of blockLines) {
|
|
2469
|
+
if (line.includes("@oagen-ignore")) continue;
|
|
2470
|
+
const m = line.match(REGION_DECLARATION_PATTERN);
|
|
2471
|
+
if (m) names.add(m[1]);
|
|
2472
|
+
}
|
|
2473
|
+
return names;
|
|
2474
|
+
}
|
|
2475
|
+
/** Inclusive line ranges of `@oagen-ignore-start`..`@oagen-ignore-end` regions. */
|
|
2476
|
+
function collectIgnoreRegionLineRanges(lines) {
|
|
2477
|
+
const ranges = [];
|
|
2478
|
+
let start = -1;
|
|
2479
|
+
for (let i = 0; i < lines.length; i++) {
|
|
2480
|
+
if (start === -1 && lines[i].includes("@oagen-ignore-start")) {
|
|
2481
|
+
start = i;
|
|
2482
|
+
continue;
|
|
2483
|
+
}
|
|
2484
|
+
if (start !== -1 && lines[i].includes("@oagen-ignore-end")) {
|
|
2485
|
+
ranges.push({
|
|
2486
|
+
start,
|
|
2487
|
+
end: i
|
|
2488
|
+
});
|
|
2489
|
+
start = -1;
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
return ranges;
|
|
2493
|
+
}
|
|
2494
|
+
/**
|
|
2495
|
+
* Walk upward from a declaration's first line over its contiguous comment
|
|
2496
|
+
* block (doc comment), so the comment is dropped together with the
|
|
2497
|
+
* declaration. Stops at blank lines, region markers, and line 0 (a comment
|
|
2498
|
+
* on line 0 is the file header, not a docstring).
|
|
2499
|
+
*/
|
|
2500
|
+
function extendOverPrecedingComments(lines, startLine) {
|
|
2501
|
+
let s = startLine;
|
|
2502
|
+
while (s > 1) {
|
|
2503
|
+
const prev = lines[s - 1].trim();
|
|
2504
|
+
if (prev === "" || prev.includes("@oagen-ignore")) break;
|
|
2505
|
+
if (!(prev.startsWith("//") || prev.startsWith("/*") || prev.startsWith("*") || prev.startsWith("#"))) break;
|
|
2506
|
+
s--;
|
|
2507
|
+
}
|
|
2508
|
+
return s;
|
|
2509
|
+
}
|
|
2510
|
+
/**
|
|
2511
|
+
* Drop generated top-level declarations that are redeclared inside an ignore
|
|
2512
|
+
* block ("region wins"). When `placeBlock` is set and at least one generated
|
|
2513
|
+
* declaration matches, the block's lines replace the first match in place
|
|
2514
|
+
* (mirroring the class-replacement behavior above); any further matches are
|
|
2515
|
+
* deleted. Mutates `result` in place.
|
|
2516
|
+
*
|
|
2517
|
+
* Returns `placed` (the block content now lives in `result` and must not be
|
|
2518
|
+
* inserted again) and `edited` (line numbers shifted).
|
|
2519
|
+
*/
|
|
2520
|
+
async function applyRegionDeclarationOverride(result, blockLines, language, placeBlock) {
|
|
2521
|
+
const names = collectRegionDeclaredNames(blockLines);
|
|
2522
|
+
if (names.size === 0) return {
|
|
2523
|
+
placed: false,
|
|
2524
|
+
edited: false
|
|
2525
|
+
};
|
|
2526
|
+
const source = result.join("\n");
|
|
2527
|
+
let parsed;
|
|
2528
|
+
try {
|
|
2529
|
+
parsed = await extractStatements(source, language);
|
|
2530
|
+
} catch {
|
|
2531
|
+
return {
|
|
2532
|
+
placed: false,
|
|
2533
|
+
edited: false
|
|
2534
|
+
};
|
|
2535
|
+
}
|
|
2536
|
+
const regionRanges = collectIgnoreRegionLineRanges(result);
|
|
2537
|
+
const inRegion = (line) => regionRanges.some((r) => line >= r.start && line <= r.end);
|
|
2538
|
+
const spans = [];
|
|
2539
|
+
for (const stmt of parsed.statements) {
|
|
2540
|
+
if (stmt.kind !== "declaration" || !stmt.key || !names.has(stmt.key)) continue;
|
|
2541
|
+
let idx = source.indexOf(stmt.text);
|
|
2542
|
+
let startLine = -1;
|
|
2543
|
+
while (idx !== -1) {
|
|
2544
|
+
const line = source.slice(0, idx).split("\n").length - 1;
|
|
2545
|
+
if (!inRegion(line)) {
|
|
2546
|
+
startLine = line;
|
|
2547
|
+
break;
|
|
2548
|
+
}
|
|
2549
|
+
idx = source.indexOf(stmt.text, idx + 1);
|
|
2550
|
+
}
|
|
2551
|
+
if (startLine === -1) continue;
|
|
2552
|
+
const endLine = startLine + stmt.text.split("\n").length - 1;
|
|
2553
|
+
spans.push({
|
|
2554
|
+
start: extendOverPrecedingComments(result, startLine),
|
|
2555
|
+
end: endLine
|
|
2556
|
+
});
|
|
2557
|
+
}
|
|
2558
|
+
if (spans.length === 0) return {
|
|
2559
|
+
placed: false,
|
|
2560
|
+
edited: false
|
|
2561
|
+
};
|
|
2562
|
+
spans.sort((a, b) => a.start - b.start);
|
|
2563
|
+
for (let i = spans.length - 1; i >= 1; i--) {
|
|
2564
|
+
const span = spans[i];
|
|
2565
|
+
let deleteCount = span.end - span.start + 1;
|
|
2566
|
+
const prevBlank = span.start === 0 || (result[span.start - 1] ?? "").trim() === "";
|
|
2567
|
+
const nextBlank = (result[span.end + 1] ?? "").trim() === "";
|
|
2568
|
+
if (prevBlank && nextBlank && span.end + 1 < result.length) deleteCount++;
|
|
2569
|
+
result.splice(span.start, deleteCount);
|
|
2570
|
+
}
|
|
2571
|
+
const first = spans[0];
|
|
2572
|
+
if (placeBlock) {
|
|
2573
|
+
result.splice(first.start, first.end - first.start + 1, ...blockLines);
|
|
2574
|
+
return {
|
|
2575
|
+
placed: true,
|
|
2576
|
+
edited: true
|
|
2577
|
+
};
|
|
2578
|
+
}
|
|
2579
|
+
let deleteCount = first.end - first.start + 1;
|
|
2580
|
+
const prevBlank = first.start === 0 || (result[first.start - 1] ?? "").trim() === "";
|
|
2581
|
+
const nextBlank = (result[first.end + 1] ?? "").trim() === "";
|
|
2582
|
+
if (prevBlank && nextBlank && first.end + 1 < result.length) deleteCount++;
|
|
2583
|
+
result.splice(first.start, deleteCount);
|
|
2584
|
+
return {
|
|
2585
|
+
placed: false,
|
|
2586
|
+
edited: true
|
|
2587
|
+
};
|
|
2588
|
+
}
|
|
2589
|
+
/**
|
|
2442
2590
|
* Collect `from X import Y, Z` identifiers grouped by module, handling
|
|
2443
2591
|
* both single-line and multiline (parenthesized) forms.
|
|
2444
2592
|
*/
|
|
@@ -3713,4 +3861,4 @@ function summarize(changes) {
|
|
|
3713
3861
|
//#endregion
|
|
3714
3862
|
export { MANIFEST_FILENAME as a, treeShakeFiles as c, collectReferencedNames as d, generateAllFiles as f, resolveOperations as h, generate as i, applyFileHeaders as l, deriveMethodName as m, getEmitter as n, integrateGeneratedFiles as o, generateFiles as p, registerEmitter as r, mapFilesForTargetIntegration as s, diffSpecs as t, buildEmitterContext as u };
|
|
3715
3863
|
|
|
3716
|
-
//# sourceMappingURL=diff-
|
|
3864
|
+
//# sourceMappingURL=diff-CQzcGuFJ.mjs.map
|