@workos/oagen 0.4.0 → 0.5.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.
@@ -1,4 +1,4 @@
1
- import { $ as ApiField, Q as ApiEnum, X as Addition, Z as ApiClass, at as ApiTypeAlias, ct as LanguageHints, dt as Violation, et as ApiInterface, ft as ViolationCategory, it as ApiSurface, lt as MethodOverlay, nt as ApiParam, ot as DiffResult, pt as ViolationSeverity, rt as ApiProperty, st as Extractor, t as ApiSpec, tt as ApiMethod, ut as OverlayLookup } from "../types-D1tMqLVB.mjs";
1
+ import { $ as ApiField, Q as ApiEnum, X as Addition, Z as ApiClass, at as ApiTypeAlias, ct as LanguageHints, dt as Violation, et as ApiInterface, ft as ViolationCategory, it as ApiSurface, lt as MethodOverlay, nt as ApiParam, ot as DiffResult, pt as ViolationSeverity, rt as ApiProperty, st as Extractor, t as ApiSpec, tt as ApiMethod, ut as OverlayLookup } from "../types-D84LjrVG.mjs";
2
2
 
3
3
  //#region src/compat/extractor-registry.d.ts
4
4
  declare function registerExtractor(extractor: Extractor): void;
@@ -128,7 +128,9 @@ function resolveOperations(spec, hints, mountRules) {
128
128
  service,
129
129
  methodName,
130
130
  mountOn,
131
- wrappers
131
+ wrappers,
132
+ defaults: hint?.defaults ?? {},
133
+ inferFromClient: hint?.inferFromClient ?? []
132
134
  });
133
135
  }
134
136
  return resolved;
@@ -1496,6 +1498,30 @@ function getMergeAdapter(language) {
1496
1498
  * Supports any language with a tree-sitter grammar package.
1497
1499
  */
1498
1500
  const parserCache = /* @__PURE__ */ new Map();
1501
+ /**
1502
+ * When replacing an existing docstring with a generated one, carry over any
1503
+ * `@deprecated` lines from the existing doc that aren't present in the
1504
+ * generated doc. This prevents hand-written deprecation notices from being
1505
+ * silently dropped during docstring refresh.
1506
+ */
1507
+ function preserveDeprecatedTags(existingDoc, generatedDoc) {
1508
+ if (!existingDoc.includes("@deprecated")) return generatedDoc;
1509
+ if (generatedDoc.includes("@deprecated")) return generatedDoc;
1510
+ const deprecatedParts = [];
1511
+ for (const line of existingDoc.split("\n")) if (/@deprecated\b/.test(line)) {
1512
+ const match = line.match(/@deprecated\b.*/);
1513
+ if (match) {
1514
+ const cleaned = match[0].replace(/\s*\*\/\s*$/, "");
1515
+ deprecatedParts.push(` * ${cleaned}`);
1516
+ }
1517
+ }
1518
+ if (deprecatedParts.length === 0) return generatedDoc;
1519
+ const closingIdx = generatedDoc.lastIndexOf("*/");
1520
+ if (closingIdx === -1) return generatedDoc;
1521
+ const before = generatedDoc.slice(0, closingIdx);
1522
+ const after = generatedDoc.slice(closingIdx);
1523
+ return before + deprecatedParts.join("\n") + "\n " + after;
1524
+ }
1499
1525
  function findIgnoredRegions(source) {
1500
1526
  const regions = [];
1501
1527
  const startTag = "@oagen-ignore-start";
@@ -1609,10 +1635,21 @@ async function mergeIntoExisting(existingContent, generatedContent, language, he
1609
1635
  }
1610
1636
  for (const anchor of existingStatements.importAnchors) lastImportEndIndex = existingContent.slice(0, existingContent.indexOf(anchor)).split("\n").length - 1 + anchor.split("\n").length - 1;
1611
1637
  if (lastImportEndIndex === -1 && existingStatements.importInsertionAnchor) lastImportEndIndex = existingContent.slice(0, existingContent.indexOf(existingStatements.importInsertionAnchor)).split("\n").length - 1 + existingStatements.importInsertionAnchor.split("\n").length - 1;
1638
+ const existingExportedNames = /* @__PURE__ */ new Set();
1612
1639
  for (const stmt of existingStatements.statements) {
1613
- if (stmt.kind === "reexport") existingReexports.add(adapter.normalizeReexport ? adapter.normalizeReexport(stmt.text.trim()) : stmt.text.trim());
1614
- if (stmt.key) existingKeys.add(stmt.key);
1615
- else existingUnnamedTexts.add(stmt.text.trim());
1640
+ if (stmt.kind === "reexport") {
1641
+ existingReexports.add(adapter.normalizeReexport ? adapter.normalizeReexport(stmt.text.trim()) : stmt.text.trim());
1642
+ const braceMatch = stmt.text.match(/\{([^}]+)\}/);
1643
+ if (braceMatch) for (const part of braceMatch[1].split(",")) {
1644
+ const segments = part.trim().split(/\s+as\s+/);
1645
+ const exportedName = (segments[1] ?? segments[0]).trim();
1646
+ if (exportedName) existingExportedNames.add(exportedName);
1647
+ }
1648
+ }
1649
+ if (stmt.key) {
1650
+ existingKeys.add(stmt.key);
1651
+ existingExportedNames.add(stmt.key);
1652
+ } else existingUnnamedTexts.add(stmt.text.trim());
1616
1653
  }
1617
1654
  const headerLine = header.trim();
1618
1655
  const newImports = [];
@@ -1672,6 +1709,17 @@ async function mergeIntoExisting(existingContent, generatedContent, language, he
1672
1709
  preserved++;
1673
1710
  continue;
1674
1711
  }
1712
+ const braceMatch = stmt.text.match(/\{([^}]+)\}/);
1713
+ if (braceMatch) {
1714
+ const exportedNames = braceMatch[1].split(",").map((n) => {
1715
+ const parts = n.trim().split(/\s+as\s+/);
1716
+ return (parts[1] ?? parts[0]).trim();
1717
+ }).filter(Boolean);
1718
+ if (exportedNames.length > 0 && exportedNames.every((n) => existingExportedNames.has(n))) {
1719
+ preserved++;
1720
+ continue;
1721
+ }
1722
+ }
1675
1723
  }
1676
1724
  if (stmt.key && (existingKeys.has(stmt.key) || existingImportedNames.has(stmt.key))) {
1677
1725
  preserved++;
@@ -1773,10 +1821,11 @@ async function mergeIntoExisting(existingContent, generatedContent, language, he
1773
1821
  const genDoc = genInfo.docstring && genInfo.docstring.text.trim() !== headerLine ? genInfo.docstring : null;
1774
1822
  if (genDoc) if (existInfo.docstring) {
1775
1823
  if (!existInfo.docstring.text.includes("@oagen-ignore") && existInfo.docstring.text !== genDoc.text) {
1824
+ const newText = preserveDeprecatedTags(existInfo.docstring.text, genDoc.text);
1776
1825
  edits.push({
1777
1826
  start: existInfo.docstring.startIndex,
1778
1827
  end: existInfo.docstring.endIndex,
1779
- newText: genDoc.text
1828
+ newText
1780
1829
  });
1781
1830
  docstringUpdates++;
1782
1831
  }
@@ -1793,14 +1842,16 @@ async function mergeIntoExisting(existingContent, generatedContent, language, he
1793
1842
  const matchedExistMembers = /* @__PURE__ */ new Set();
1794
1843
  for (const [memberName, genMember] of genInfo.members) {
1795
1844
  const existMember = existInfo.members.get(memberName);
1796
- if (!existMember || !genMember.docstring) continue;
1845
+ if (!existMember) continue;
1797
1846
  matchedExistMembers.add(memberName);
1847
+ if (!genMember.docstring) continue;
1798
1848
  if (existMember.docstring) {
1799
1849
  if (!existMember.docstring.text.includes("@oagen-ignore") && existMember.docstring.text !== genMember.docstring.text) {
1850
+ const newText = preserveDeprecatedTags(existMember.docstring.text, genMember.docstring.text);
1800
1851
  edits.push({
1801
1852
  start: existMember.docstring.startIndex,
1802
1853
  end: existMember.docstring.endIndex,
1803
- newText: genMember.docstring.text
1854
+ newText
1804
1855
  });
1805
1856
  docstringUpdates++;
1806
1857
  }
@@ -1815,34 +1866,59 @@ async function mergeIntoExisting(existingContent, generatedContent, language, he
1815
1866
  docstringUpdates++;
1816
1867
  }
1817
1868
  }
1818
- for (const [_genName, genMember] of genInfo.members) {
1869
+ const unmatchedGenByFp = /* @__PURE__ */ new Map();
1870
+ for (const [genName, genMember] of genInfo.members) {
1871
+ if (matchedExistMembers.has(genName)) continue;
1819
1872
  if (!genMember.docstring || !genMember.urlFingerprint) continue;
1820
- for (const [existName, existMember] of existInfo.members) {
1821
- if (matchedExistMembers.has(existName)) continue;
1822
- if (!existMember.urlFingerprint || existMember.urlFingerprint !== genMember.urlFingerprint) continue;
1823
- if (existMember.docstring) {
1824
- if (existMember.docstring.text.includes("@oagen-ignore")) continue;
1825
- if (existMember.docstring.text !== genMember.docstring.text) {
1826
- edits.push({
1827
- start: existMember.docstring.startIndex,
1828
- end: existMember.docstring.endIndex,
1829
- newText: genMember.docstring.text
1830
- });
1831
- docstringUpdates++;
1832
- }
1833
- } else {
1834
- const lineStart = existMember.declStartIndex - existMember.declColumn;
1835
- const indent = " ".repeat(existMember.declColumn);
1873
+ if (existInfo.members.has(genName)) continue;
1874
+ const bucket = unmatchedGenByFp.get(genMember.urlFingerprint) ?? [];
1875
+ bucket.push({
1876
+ name: genName,
1877
+ member: genMember
1878
+ });
1879
+ unmatchedGenByFp.set(genMember.urlFingerprint, bucket);
1880
+ }
1881
+ const unmatchedExistByFp = /* @__PURE__ */ new Map();
1882
+ for (const [existName, existMember] of existInfo.members) {
1883
+ if (matchedExistMembers.has(existName)) continue;
1884
+ if (!existMember.urlFingerprint) continue;
1885
+ const bucket = unmatchedExistByFp.get(existMember.urlFingerprint) ?? [];
1886
+ bucket.push({
1887
+ name: existName,
1888
+ member: existMember
1889
+ });
1890
+ unmatchedExistByFp.set(existMember.urlFingerprint, bucket);
1891
+ }
1892
+ for (const [fp, genBucket] of unmatchedGenByFp) {
1893
+ if (genBucket.length !== 1) continue;
1894
+ const existBucket = unmatchedExistByFp.get(fp);
1895
+ if (!existBucket || existBucket.length !== 1) continue;
1896
+ const genMember = genBucket[0].member;
1897
+ const existEntry = existBucket[0];
1898
+ const existMember = existEntry.member;
1899
+ if (!genMember.docstring) continue;
1900
+ if (existMember.docstring) {
1901
+ if (existMember.docstring.text.includes("@oagen-ignore")) continue;
1902
+ if (existMember.docstring.text !== genMember.docstring.text) {
1903
+ const newText = preserveDeprecatedTags(existMember.docstring.text, genMember.docstring.text);
1836
1904
  edits.push({
1837
- start: lineStart,
1838
- end: lineStart,
1839
- newText: indent + genMember.docstring.text + "\n"
1905
+ start: existMember.docstring.startIndex,
1906
+ end: existMember.docstring.endIndex,
1907
+ newText
1840
1908
  });
1841
1909
  docstringUpdates++;
1842
1910
  }
1843
- matchedExistMembers.add(existName);
1844
- break;
1911
+ } else {
1912
+ const lineStart = existMember.declStartIndex - existMember.declColumn;
1913
+ const indent = " ".repeat(existMember.declColumn);
1914
+ edits.push({
1915
+ start: lineStart,
1916
+ end: lineStart,
1917
+ newText: indent + genMember.docstring.text + "\n"
1918
+ });
1919
+ docstringUpdates++;
1845
1920
  }
1921
+ matchedExistMembers.add(existEntry.name);
1846
1922
  }
1847
1923
  }
1848
1924
  if (edits.length > 0) {
@@ -2129,12 +2205,16 @@ function spliceExtraImports(existingLines, resultLines) {
2129
2205
  const extraSimple = [...existingSimple].filter((l) => !generatedSimple.has(l));
2130
2206
  const existingFrom = collectFromImports(existingLines);
2131
2207
  const generatedFrom = collectFromImports(resultLines);
2208
+ const allGeneratedIds = /* @__PURE__ */ new Set();
2209
+ for (const ids of generatedFrom.values()) for (const id of ids) allGeneratedIds.add(id);
2132
2210
  const extraFromLines = [];
2133
2211
  for (const [mod, existIds] of existingFrom) {
2134
2212
  const genIds = generatedFrom.get(mod);
2135
- if (!genIds) extraFromLines.push(`from ${mod} import ${[...existIds].join(", ")}`);
2136
- else {
2137
- const extra = [...existIds].filter((id) => !genIds.has(id));
2213
+ if (!genIds) {
2214
+ const extra = [...existIds].filter((id) => !allGeneratedIds.has(id));
2215
+ if (extra.length > 0) extraFromLines.push(`from ${mod} import ${extra.join(", ")}`);
2216
+ } else {
2217
+ const extra = [...existIds].filter((id) => !genIds.has(id) && !allGeneratedIds.has(id));
2138
2218
  if (extra.length > 0) extraFromLines.push(`from ${mod} import ${extra.join(", ")}`);
2139
2219
  }
2140
2220
  }
@@ -2230,7 +2310,6 @@ function generateAllFiles(spec, emitter, ctx) {
2230
2310
  ...emitter.generateResources(spec.services, ctx),
2231
2311
  ...emitter.generateClient(spec, ctx),
2232
2312
  ...emitter.generateErrors(ctx),
2233
- ...emitter.generateConfig(ctx),
2234
2313
  ...emitter.generateTypeSignatures?.(reachableSpec, ctx) ?? [],
2235
2314
  ...emitter.generateTests(reachableSpec, ctx),
2236
2315
  ...emitter.generateManifest?.(spec, ctx) ?? []
@@ -2848,4 +2927,4 @@ function summarize(changes) {
2848
2927
  //#endregion
2849
2928
  export { integrateGeneratedFiles as a, applyFileHeaders as c, generateAllFiles as d, generateFiles as f, generate as i, buildEmitterContext as l, resolveOperations as m, getEmitter as n, mapFilesForTargetIntegration as o, deriveMethodName as p, registerEmitter as r, treeShakeFiles as s, diffSpecs as t, collectReferencedNames as u };
2850
2929
 
2851
- //# sourceMappingURL=diff-DcY93sii.mjs.map
2930
+ //# sourceMappingURL=diff-CSy3g-Bq.mjs.map