@workos/oagen 0.22.6 → 0.22.7

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.
@@ -2667,6 +2667,60 @@ function collectTsImports(lines) {
2667
2667
  return out;
2668
2668
  }
2669
2669
  /**
2670
+ * Remove the given symbols from generated `import type` bindings, in place.
2671
+ *
2672
+ * Called when an existing *value* import for the same symbol is being spliced
2673
+ * back into the file. A value import satisfies both runtime and type uses, so
2674
+ * leaving the generated `import type { X }` would re-declare `X` (TS2300
2675
+ * duplicate identifier). Callers guarantee every symbol here is absent from
2676
+ * generated *value* imports, so each occurrence is type-only and safe to drop.
2677
+ *
2678
+ * Handles whole-line `import type { … }` and inline `import { …, type X }`,
2679
+ * single- or multi-line. A statement whose bindings all get stripped is
2680
+ * removed entirely.
2681
+ */
2682
+ function dropGeneratedTypeOnlyBindings(resultLines, symbols) {
2683
+ if (symbols.size === 0) return;
2684
+ const out = [];
2685
+ for (let i = 0; i < resultLines.length; i++) {
2686
+ const line = resultLines[i];
2687
+ const trimmed = line.trim();
2688
+ if (!/^import\b/.test(trimmed) || !trimmed.includes("{")) {
2689
+ out.push(line);
2690
+ continue;
2691
+ }
2692
+ const span = [line];
2693
+ while (!span.join(" ").includes("}") && i + 1 < resultLines.length) {
2694
+ i++;
2695
+ span.push(resultLines[i]);
2696
+ }
2697
+ const m = span.join(" ").replace(/\s+/g, " ").trim().replace(/;\s*$/, "").match(/^import\s+(type\s+)?(?:(\w+)\s*,\s*)?\{\s*([^}]*)\s*\}\s+from\s+(['"][^'"]+['"])$/);
2698
+ if (!m) {
2699
+ for (const s of span) out.push(s);
2700
+ continue;
2701
+ }
2702
+ const isTypeOnly = !!m[1];
2703
+ const defaultName = m[2];
2704
+ const items = m[3].split(",").map((s) => s.trim()).filter(Boolean);
2705
+ const modQuoted = m[4];
2706
+ const kept = items.filter((raw) => {
2707
+ const isTypeBinding = isTypeOnly || raw.startsWith("type ");
2708
+ const bare = raw.replace(/^type\s+/, "");
2709
+ return !(isTypeBinding && symbols.has(bare));
2710
+ });
2711
+ if (kept.length === items.length) {
2712
+ for (const s of span) out.push(s);
2713
+ continue;
2714
+ }
2715
+ if (kept.length === 0 && !defaultName) continue;
2716
+ const lead = line.match(/^(\s*)/)?.[1] ?? "";
2717
+ const prefix = isTypeOnly ? "import type " : "import ";
2718
+ const defaultPart = defaultName ? `${defaultName}, ` : "";
2719
+ out.push(`${lead}${prefix}${defaultPart}{ ${kept.join(", ")} } from ${modQuoted};`);
2720
+ }
2721
+ resultLines.splice(0, resultLines.length, ...out);
2722
+ }
2723
+ /**
2670
2724
  * Add imports from the existing file that are absent from the generated
2671
2725
  * result. Handles:
2672
2726
  *
@@ -2788,28 +2842,49 @@ function spliceExtraImports(existingLines, resultLines) {
2788
2842
  const existingTs = collectTsImports(existingOutsideIgnore);
2789
2843
  const generatedTs = collectTsImports(resultLines);
2790
2844
  const extraTsLines = [];
2845
+ const allGeneratedTsIds = /* @__PURE__ */ new Set();
2846
+ const generatedValueIds = /* @__PURE__ */ new Set();
2847
+ for (const ids of generatedTs.named.values()) for (const id of ids) {
2848
+ allGeneratedTsIds.add(id);
2849
+ generatedValueIds.add(id);
2850
+ }
2851
+ for (const ids of generatedTs.typeOnly.values()) for (const id of ids) allGeneratedTsIds.add(id);
2852
+ for (const name of generatedTs.defaults.values()) {
2853
+ allGeneratedTsIds.add(name);
2854
+ generatedValueIds.add(name);
2855
+ }
2856
+ for (const name of generatedTs.namespaces.values()) {
2857
+ allGeneratedTsIds.add(name);
2858
+ generatedValueIds.add(name);
2859
+ }
2860
+ const reclaimedValueIds = /* @__PURE__ */ new Set();
2861
+ const generatedHasValue = (id) => generatedValueIds.has(id);
2862
+ const generatedHasTypeOnly = (id) => allGeneratedTsIds.has(id) && !generatedValueIds.has(id);
2791
2863
  for (const mod of existingTs.sideEffects) if (!generatedTs.sideEffects.has(mod)) extraTsLines.push(`import '${mod}';`);
2792
2864
  for (const [mod, name] of existingTs.defaults) {
2793
2865
  if (generatedTs.defaults.has(mod)) continue;
2794
2866
  if (!identifierUsed(ignoreRegionText, name)) continue;
2867
+ if (generatedHasValue(name)) continue;
2868
+ if (generatedHasTypeOnly(name)) reclaimedValueIds.add(name);
2795
2869
  extraTsLines.push(`import ${name} from '${mod}';`);
2796
2870
  }
2797
2871
  for (const [mod, name] of existingTs.namespaces) {
2798
2872
  if (!identifierUsed(ignoreRegionText, name)) continue;
2799
- if (!generatedTs.namespaces.has(mod)) extraTsLines.push(`import * as ${name} from '${mod}';`);
2873
+ if (generatedHasValue(name)) continue;
2874
+ if (generatedTs.namespaces.has(mod)) continue;
2875
+ if (generatedHasTypeOnly(name)) reclaimedValueIds.add(name);
2876
+ extraTsLines.push(`import * as ${name} from '${mod}';`);
2800
2877
  }
2801
2878
  for (const [mod, existIds] of existingTs.named) {
2802
- const genIds = generatedTs.named.get(mod) ?? /* @__PURE__ */ new Set();
2803
- const genTypeIds = generatedTs.typeOnly.get(mod) ?? /* @__PURE__ */ new Set();
2804
- const extra = [...existIds].filter((id) => !genIds.has(id) && !genTypeIds.has(id) && identifierUsed(ignoreRegionText, id));
2879
+ const extra = [...existIds].filter((id) => !generatedHasValue(id) && identifierUsed(ignoreRegionText, id));
2880
+ for (const id of extra) if (generatedHasTypeOnly(id)) reclaimedValueIds.add(id);
2805
2881
  if (extra.length > 0) extraTsLines.push(`import { ${extra.join(", ")} } from '${mod}';`);
2806
2882
  }
2807
2883
  for (const [mod, existIds] of existingTs.typeOnly) {
2808
- const genIds = generatedTs.typeOnly.get(mod) ?? /* @__PURE__ */ new Set();
2809
- const genNamedIds = generatedTs.named.get(mod) ?? /* @__PURE__ */ new Set();
2810
- const extra = [...existIds].filter((id) => !genIds.has(id) && !genNamedIds.has(id) && identifierUsed(ignoreRegionText, id));
2884
+ const extra = [...existIds].filter((id) => !allGeneratedTsIds.has(id) && identifierUsed(ignoreRegionText, id));
2811
2885
  if (extra.length > 0) extraTsLines.push(`import type { ${extra.join(", ")} } from '${mod}';`);
2812
2886
  }
2887
+ dropGeneratedTypeOnlyBindings(resultLines, reclaimedValueIds);
2813
2888
  const isPhpUseImport = (l) => /^use\s+[\w\\]+\\[\w\\]*(\s+as\s+\w+)?\s*;?$/.test(l);
2814
2889
  const existingPhpUse = new Set(existingOutsideIgnore.filter(isPhpUseImport).map((l) => l.trim()));
2815
2890
  const generatedPhpUse = new Set(resultLines.filter(isPhpUseImport).map((l) => l.trim()));
@@ -2853,7 +2928,31 @@ function spliceExtraImports(existingLines, resultLines) {
2853
2928
  if ((resultLines[i].match(/[)}]/g) ?? []).length > 0) break;
2854
2929
  }
2855
2930
  }
2856
- if (lastImportIdx >= 0) resultLines.splice(lastImportIdx + 1, 0, ...allExtra);
2931
+ if (lastImportIdx >= 0) {
2932
+ resultLines.splice(lastImportIdx + 1, 0, ...allExtra);
2933
+ return;
2934
+ }
2935
+ let insertAt = 0;
2936
+ let inBlockComment = false;
2937
+ for (let i = 0; i < resultLines.length; i++) {
2938
+ const t = resultLines[i].trim();
2939
+ if (inBlockComment) {
2940
+ insertAt = i + 1;
2941
+ if (t.includes("*/")) inBlockComment = false;
2942
+ continue;
2943
+ }
2944
+ if (t.startsWith("//")) {
2945
+ insertAt = i + 1;
2946
+ continue;
2947
+ }
2948
+ if (t.startsWith("/*")) {
2949
+ insertAt = i + 1;
2950
+ inBlockComment = !t.includes("*/");
2951
+ continue;
2952
+ }
2953
+ break;
2954
+ }
2955
+ resultLines.splice(insertAt, 0, ...allExtra);
2857
2956
  }
2858
2957
  //#endregion
2859
2958
  //#region src/engine/generate-files.ts
@@ -3861,4 +3960,4 @@ function summarize(changes) {
3861
3960
  //#endregion
3862
3961
  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 };
3863
3962
 
3864
- //# sourceMappingURL=diff-CQzcGuFJ.mjs.map
3963
+ //# sourceMappingURL=diff-D4XaiPeA.mjs.map