@osdk/foundry-sdk-generator 1.4.0-beta.5 → 2.0.0-beta.6

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.
@@ -584,7 +584,7 @@ function isValidSemver(semverString) {
584
584
  }
585
585
 
586
586
  // src/utils/UserAgent.ts
587
- var USER_AGENT = `typescript-sdk-generator/${"1.4.0-beta.5"}`;
587
+ var USER_AGENT = `typescript-sdk-generator/${"2.0.0-beta.6"}`;
588
588
  async function createRollupBuild(absolutePackagePath, packageName) {
589
589
  const inputPath = `${absolutePackagePath}/${packageName}/index.js`;
590
590
  const {
@@ -627,23 +627,6 @@ async function generateEsmBuild(absolutePackagePath, packageName) {
627
627
  async function generateBundles(absolutePackagePath, packageName) {
628
628
  await Promise.all([generateEsmBuild(absolutePackagePath, packageName)]);
629
629
  }
630
-
631
- // src/generate/betaClient/getModuleSourceFile.ts
632
- function getModuleSourceFile(project, node) {
633
- let exportSourceFile;
634
- try {
635
- exportSourceFile = project.getSourceFile(`/${node.getLiteralText()}.ts`);
636
- if (!exportSourceFile) {
637
- exportSourceFile = project.getSourceFile(`/${node.getLiteralText()}/index.ts`);
638
- if (!exportSourceFile) {
639
- return void 0;
640
- }
641
- }
642
- } catch (e) {
643
- return void 0;
644
- }
645
- return exportSourceFile;
646
- }
647
630
  function withoutTrailingIndex(filePath) {
648
631
  return filePath.endsWith("/index") ? filePath.slice(0, -6) : filePath;
649
632
  }
@@ -774,277 +757,6 @@ function transformModuleSpecifier(value, filePath) {
774
757
  function withoutExtension(value) {
775
758
  return value.replace(".js", "");
776
759
  }
777
- var ProjectMinifier = class {
778
- nodesToKeep = {};
779
- visitedImports = {};
780
- dependentExport = {};
781
- stack = [];
782
- constructor(project, startingImportSet, startingFilePath) {
783
- this.project = project;
784
- this.startingImportSet = startingImportSet;
785
- this.startingFilePath = startingFilePath;
786
- this.stack.push({
787
- sourceFile: this.project.getSourceFile(this.startingFilePath),
788
- imports: this.startingImportSet
789
- });
790
- }
791
- shouldContinueVisiting() {
792
- return this.stack.length > 0;
793
- }
794
- getNextVisit() {
795
- if (this.stack.length === 0) {
796
- throw new Error("Done processing");
797
- }
798
- return this.stack.pop();
799
- }
800
- pushNextVisit(sourceFile, imports) {
801
- this.stack.push({
802
- sourceFile,
803
- imports
804
- });
805
- }
806
- shouldSkipTraversal(traversalStep) {
807
- const filePath = traversalStep.sourceFile.getFilePath();
808
- if (!this.visitedImports[filePath]) {
809
- this.visitedImports[filePath] = /* @__PURE__ */ new Set();
810
- }
811
- let shouldSkipCheck = true;
812
- for (const importToCheck of traversalStep.imports) {
813
- if (!this.visitedImports[filePath].has(importToCheck)) {
814
- shouldSkipCheck = false;
815
- this.visitedImports[filePath].add(importToCheck);
816
- }
817
- }
818
- return shouldSkipCheck;
819
- }
820
- getNodesToKeepForModule(moduleName) {
821
- if (!this.nodesToKeep[moduleName]) {
822
- this.nodesToKeep[moduleName] = /* @__PURE__ */ new Set();
823
- }
824
- return this.nodesToKeep[moduleName];
825
- }
826
- minifyProject() {
827
- while (this.shouldContinueVisiting()) {
828
- const visitImports = this.getNextVisit();
829
- if (this.shouldSkipTraversal(visitImports)) {
830
- continue;
831
- }
832
- const identifiersToResolve = /* @__PURE__ */ new Set();
833
- const sourceFile = visitImports.sourceFile;
834
- const moduleName = getModuleFromFileName(sourceFile);
835
- const nodeSet = this.getNodesToKeepForModule(moduleName);
836
- for (const [key, declarations] of sourceFile.getExportedDeclarations()) {
837
- if (!visitImports.imports.has(key)) {
838
- continue;
839
- }
840
- this.visitDependentExports(moduleName);
841
- this.visitDeclaration(declarations, nodeSet, identifiersToResolve);
842
- }
843
- for (const declaration of sourceFile.getExportDeclarations()) {
844
- const moduleSpecifier = declaration.getModuleSpecifier();
845
- if (!moduleSpecifier) {
846
- continue;
847
- }
848
- const literalText = moduleSpecifier.getLiteralText();
849
- const exportSourceFile = getModuleSourceFile(this.project, moduleSpecifier);
850
- if (!exportSourceFile) {
851
- continue;
852
- }
853
- if (declaration.isNamespaceExport()) {
854
- const namespaceExport = declaration.getNamespaceExport();
855
- if (namespaceExport) {
856
- if (visitImports.imports.has(namespaceExport.getName())) {
857
- this.getNodesToKeepForModule(moduleName).add(namespaceExport);
858
- const nodesToKeepForModule = this.getNodesToKeepForModule(getModuleFromFileName(exportSourceFile));
859
- nodesToKeepForModule.add(exportSourceFile);
860
- const importsFromNamespace = new Set(exportSourceFile.getExportedDeclarations().keys());
861
- this.pushNextVisit(exportSourceFile, importsFromNamespace);
862
- }
863
- }
864
- }
865
- const namedExports = declaration.getNamedExports();
866
- if (namedExports.length === 0) {
867
- this.pushNextVisit(exportSourceFile, visitImports.imports);
868
- if (!this.dependentExport[literalText]) {
869
- this.dependentExport[literalText] = /* @__PURE__ */ new Set();
870
- }
871
- this.dependentExport[literalText].add(declaration);
872
- continue;
873
- }
874
- this.visitNamedExports(namedExports, visitImports, nodeSet, exportSourceFile);
875
- }
876
- for (const declaration of sourceFile.getImportDeclarations()) {
877
- const namedImports = declaration.getNamedImports();
878
- const moduleSpecifier = declaration.getModuleSpecifier();
879
- if (!moduleSpecifier) {
880
- continue;
881
- }
882
- const importSourceFile = getModuleSourceFile(this.project, moduleSpecifier);
883
- if (!importSourceFile) {
884
- continue;
885
- }
886
- if (namedImports.length === 0) {
887
- const aliasedSymbol = declaration.getImportClause()?.getNamespaceImport()?.getSymbol();
888
- if (aliasedSymbol && identifiersToResolve.has(aliasedSymbol)) {
889
- this.getNodesToKeepForModule(moduleName).add(declaration);
890
- const importsFromNamespace = new Set(importSourceFile.getExportedDeclarations().keys());
891
- importSourceFile.getExportDeclarations().forEach((decl) => {
892
- this.getNodesToKeepForModule(moduleSpecifier.getLiteralText()).add(decl);
893
- });
894
- this.getNodesToKeepForModule(moduleSpecifier.getLiteralText()).add(sourceFile);
895
- this.pushNextVisit(importSourceFile, importsFromNamespace);
896
- }
897
- continue;
898
- }
899
- this.visitNamedImports(namedImports, identifiersToResolve, moduleName, declaration, importSourceFile);
900
- }
901
- }
902
- this.deleteUnused();
903
- }
904
- visitNamedImports(namedImports, identifiersToResolve, moduleName, declaration, importSourceFile) {
905
- const importsToVisit = /* @__PURE__ */ new Set();
906
- for (const namedImport of namedImports) {
907
- const symbol = namedImport.getSymbol();
908
- if (!symbol) {
909
- continue;
910
- }
911
- if (identifiersToResolve.has(symbol)) {
912
- importsToVisit.add(symbol.getName());
913
- importsToVisit.add(namedImport.getName());
914
- this.getNodesToKeepForModule(moduleName).add(namedImport);
915
- this.getNodesToKeepForModule(moduleName).add(declaration);
916
- }
917
- }
918
- this.pushNextVisit(importSourceFile, importsToVisit);
919
- }
920
- // For each named export if it is something that we need, we keep the export
921
- // And visit the module it is exported from
922
- // export { A } from ".."
923
- visitNamedExports(namedExports, visitImports, nodeSet, exportSourceFile) {
924
- const exportsToVisit = /* @__PURE__ */ new Set();
925
- for (const namedExport of namedExports) {
926
- const symbol = namedExport.getSymbol();
927
- if (!symbol) {
928
- continue;
929
- }
930
- if (!visitImports.imports.has(symbol.getName())) {
931
- continue;
932
- }
933
- exportsToVisit.add(symbol.getName());
934
- nodeSet.add(namedExport);
935
- for (const ancestor of namedExport.getAncestors()) {
936
- nodeSet.add(ancestor);
937
- }
938
- }
939
- this.pushNextVisit(exportSourceFile, exportsToVisit);
940
- }
941
- // Traverse the declaration and it's dependent symbols
942
- visitDeclaration(declarations, nodeSet, identifiers) {
943
- const declarationStack = declarations;
944
- while (declarationStack.length > 0) {
945
- const currentDeclaration = declarationStack.pop();
946
- if (nodeSet.has(currentDeclaration)) {
947
- continue;
948
- }
949
- nodeSet.add(currentDeclaration);
950
- for (const ancestor of currentDeclaration.getAncestors()) {
951
- nodeSet.add(ancestor);
952
- }
953
- for (const child of currentDeclaration.getDescendantsOfKind(tsMorph.SyntaxKind.Identifier)) {
954
- const symbol = child.getSymbol();
955
- if (!symbol || identifiers.has(symbol)) {
956
- continue;
957
- }
958
- identifiers.add(symbol);
959
- for (const symbolDeclaration of symbol.getDeclarations()) {
960
- if (tsMorph.Node.isImportDeclaration(symbolDeclaration)) {
961
- const importSourceFile = getModuleSourceFile(this.project, symbolDeclaration.getModuleSpecifier());
962
- if (!importSourceFile) {
963
- continue;
964
- }
965
- this.pushNextVisit(importSourceFile, new Set(symbol.getName()));
966
- } else {
967
- declarationStack.push(symbolDeclaration);
968
- }
969
- }
970
- }
971
- }
972
- }
973
- deleteUnused() {
974
- const deletedModules = /* @__PURE__ */ new Set();
975
- this.project.getSourceFiles().forEach((sourceFile) => {
976
- if (sourceFile.getFilePath().startsWith("/internal")) {
977
- const moduleName = getModuleFromFileName(sourceFile);
978
- const nodesToKeepForModule = this.nodesToKeep[moduleName];
979
- if (!nodesToKeepForModule || nodesToKeepForModule.size === 0) {
980
- deletedModules.add(moduleName);
981
- sourceFile.deleteImmediatelySync();
982
- return;
983
- }
984
- sourceFile.getImportDeclarations().forEach((importDeclaration) => {
985
- importDeclaration.getNamedImports().forEach((namedImport) => {
986
- if (nodesToKeepForModule && !nodesToKeepForModule.has(namedImport)) {
987
- namedImport.remove();
988
- }
989
- });
990
- });
991
- for (const exportDeclaration of sourceFile.getExportDeclarations()) {
992
- const targetModuleSpecifier = exportDeclaration.getModuleSpecifier();
993
- if (!targetModuleSpecifier) {
994
- continue;
995
- }
996
- const targetModuleLiteralText = targetModuleSpecifier.getLiteralText();
997
- if (deletedModules.has(targetModuleLiteralText)) {
998
- continue;
999
- }
1000
- const nodesToKeepForTargetModule = this.nodesToKeep[targetModuleLiteralText];
1001
- if (!nodesToKeepForTargetModule || nodesToKeepForTargetModule.size === 0) {
1002
- exportDeclaration.remove();
1003
- continue;
1004
- }
1005
- for (const namedExport of exportDeclaration.getNamedExports()) {
1006
- if (!nodesToKeepForTargetModule.has(namedExport)) {
1007
- namedExport.remove();
1008
- }
1009
- }
1010
- }
1011
- sourceFile.forEachChild((node) => {
1012
- if (!nodesToKeepForModule.has(node)) {
1013
- node.replaceWithText("");
1014
- }
1015
- });
1016
- const lines = sourceFile.getText().split("\n");
1017
- if (lines.length === 0) {
1018
- deletedModules.add(moduleName);
1019
- sourceFile.deleteImmediatelySync();
1020
- return;
1021
- }
1022
- }
1023
- });
1024
- }
1025
- // Visit all files up which have done
1026
- // `export * from "moduleName"`
1027
- visitDependentExports(moduleName) {
1028
- if (!this.dependentExport[moduleName]) {
1029
- return;
1030
- }
1031
- const dependentExportStack = [moduleName];
1032
- while (dependentExportStack.length > 0) {
1033
- const nextModuleName = dependentExportStack.pop();
1034
- if (!this.dependentExport[nextModuleName]) {
1035
- continue;
1036
- }
1037
- for (const node of this.dependentExport[nextModuleName]) {
1038
- const reexportModuleName = getModuleFromFileName(node.getSourceFile());
1039
- this.getNodesToKeepForModule(reexportModuleName).add(node);
1040
- dependentExportStack.push(reexportModuleName);
1041
- }
1042
- }
1043
- }
1044
- };
1045
- function getModuleFromFileName(sourceFile) {
1046
- return sourceFile.getFilePath().replace("/", "").replace(".ts", "").replace("/index", "");
1047
- }
1048
760
 
1049
761
  // src/generate/betaClient/bundleDependencies.ts
1050
762
  async function bundleDependencies(dirs, generatedPackageName, generatedFiles, entry) {
@@ -1056,11 +768,7 @@ async function bundleDependencies(dirs, generatedPackageName, generatedFiles, en
1056
768
  outFile: "dist/bundle/index.d.ts"
1057
769
  }
1058
770
  });
1059
- const importSet = await copyFiles(project, dirs, generatedPackageName, generatedFiles);
1060
- if (entry) {
1061
- const projectMinifier = new ProjectMinifier(project, importSet, entry);
1062
- projectMinifier.minifyProject();
1063
- }
771
+ await copyFiles(project, dirs, generatedPackageName, generatedFiles);
1064
772
  return outputModule(project);
1065
773
  }
1066
774
  function outputModule(project) {
@@ -1157,9 +865,6 @@ async function generatePackageJson(options) {
1157
865
  }
1158
866
 
1159
867
  // src/generate/betaClient/generatePackage.ts
1160
- var dependencies = {
1161
- "@osdk/legacy-client": typeof __OSDK_LEGACY_CLIENT_VERSION__ !== "undefined" ? __OSDK_LEGACY_CLIENT_VERSION__ : void 0
1162
- };
1163
868
  var betaDependencies = {
1164
869
  "@osdk/client.api": typeof __OSDK_CLIENT_API_VERSION__ !== "undefined" ? __OSDK_CLIENT_API_VERSION__ : void 0,
1165
870
  "@osdk/api": typeof __OSDK_API_VERSION__ !== "undefined" ? __OSDK_API_VERSION__ : void 0
@@ -1169,7 +874,7 @@ async function generatePackage(ontology, options) {
1169
874
  consola
1170
875
  } = await import('consola');
1171
876
  const packagePath = path.join(options.outputDir, options.packageName);
1172
- const resolvedDependencies = await Promise.all(Object.keys(options.beta ? betaDependencies : dependencies).map(async (dependency) => {
877
+ const resolvedDependencies = await Promise.all(Object.keys(betaDependencies).map(async (dependency) => {
1173
878
  return {
1174
879
  dependencyName: dependency,
1175
880
  dependencyVersion: await getDependencyVersion(dependency)
@@ -1191,7 +896,7 @@ async function generatePackage(ontology, options) {
1191
896
  readdir: (path2) => promises.readdir(path2)
1192
897
  };
1193
898
  if (!options.beta) {
1194
- await generator.generateClientSdkVersionOneDotOne(ontology, `typescript-sdk/${options.packageVersion} ${USER_AGENT}`, hostFs, packagePath);
899
+ throw new Error("Only beta is supported in this version");
1195
900
  } else {
1196
901
  await generator.generateClientSdkVersionTwoPointZero(ontology, `typescript-sdk/${options.packageVersion} ${USER_AGENT}`, hostFs, packagePath, "module");
1197
902
  }
@@ -1212,7 +917,7 @@ async function generatePackage(ontology, options) {
1212
917
  let bundleDts = "";
1213
918
  if (nodeModulesPath) {
1214
919
  try {
1215
- bundleDts = await bundleDependencies(options.beta ? [] : [path.join(nodeModulesPath, "@osdk", "legacy-client"), path.join(nodeModulesPath, "@osdk", "api"), path.join(nodeModulesPath, "@osdk", "gateway")], options.packageName, compilerOutput.files, options.beta ? void 0 : `internal/@osdk/legacy-client/index.ts`);
920
+ bundleDts = await bundleDependencies([], options.packageName, compilerOutput.files, void 0);
1216
921
  } catch (e) {
1217
922
  consola.error("Failed bundling DTS", e);
1218
923
  }
@@ -1240,9 +945,6 @@ async function generatePackage(ontology, options) {
1240
945
  }
1241
946
  }
1242
947
  async function getDependencyVersion(dependency) {
1243
- if (dependencies[dependency] !== void 0) {
1244
- return dependencies[dependency];
1245
- }
1246
948
  const {
1247
949
  findUp
1248
950
  } = await import('find-up');