@osdk/foundry-sdk-generator 1.4.0-beta.4 → 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.
@@ -6,13 +6,13 @@ import { hideBin } from 'yargs/helpers';
6
6
  import { exit } from 'process';
7
7
  import { namespaces } from '@osdk/gateway';
8
8
  import { UserTokenAuth } from '@osdk/legacy-client';
9
- import { generateClientSdkVersionOneDotOne, generateClientSdkVersionTwoPointZero } from '@osdk/generator';
9
+ import { generateClientSdkVersionTwoPointZero } from '@osdk/generator';
10
10
  import { mkdir, writeFile, readFile, readdir } from 'fs/promises';
11
11
  import commonjs from '@rollup/plugin-commonjs';
12
12
  import { nodeResolve } from '@rollup/plugin-node-resolve';
13
13
  import { rollup } from 'rollup';
14
14
  import nodePolyfill from 'rollup-plugin-polyfill-node';
15
- import { Project, Node, SyntaxKind } from 'ts-morph';
15
+ import { Project, Node } from 'ts-morph';
16
16
  import * as fs from 'fs';
17
17
  import { ModuleKind, ScriptTarget, createCompilerHost, createSourceFile, createProgram } from 'typescript';
18
18
 
@@ -561,7 +561,7 @@ function isValidSemver(semverString) {
561
561
  }
562
562
 
563
563
  // src/utils/UserAgent.ts
564
- var USER_AGENT = `typescript-sdk-generator/${"1.4.0-beta.4"}`;
564
+ var USER_AGENT = `typescript-sdk-generator/${"2.0.0-beta.6"}`;
565
565
  async function createRollupBuild(absolutePackagePath, packageName) {
566
566
  const inputPath = `${absolutePackagePath}/${packageName}/index.js`;
567
567
  const {
@@ -604,23 +604,6 @@ async function generateEsmBuild(absolutePackagePath, packageName) {
604
604
  async function generateBundles(absolutePackagePath, packageName) {
605
605
  await Promise.all([generateEsmBuild(absolutePackagePath, packageName)]);
606
606
  }
607
-
608
- // src/generate/betaClient/getModuleSourceFile.ts
609
- function getModuleSourceFile(project, node) {
610
- let exportSourceFile;
611
- try {
612
- exportSourceFile = project.getSourceFile(`/${node.getLiteralText()}.ts`);
613
- if (!exportSourceFile) {
614
- exportSourceFile = project.getSourceFile(`/${node.getLiteralText()}/index.ts`);
615
- if (!exportSourceFile) {
616
- return void 0;
617
- }
618
- }
619
- } catch (e) {
620
- return void 0;
621
- }
622
- return exportSourceFile;
623
- }
624
607
  function withoutTrailingIndex(filePath) {
625
608
  return filePath.endsWith("/index") ? filePath.slice(0, -6) : filePath;
626
609
  }
@@ -751,277 +734,6 @@ function transformModuleSpecifier(value, filePath) {
751
734
  function withoutExtension(value) {
752
735
  return value.replace(".js", "");
753
736
  }
754
- var ProjectMinifier = class {
755
- nodesToKeep = {};
756
- visitedImports = {};
757
- dependentExport = {};
758
- stack = [];
759
- constructor(project, startingImportSet, startingFilePath) {
760
- this.project = project;
761
- this.startingImportSet = startingImportSet;
762
- this.startingFilePath = startingFilePath;
763
- this.stack.push({
764
- sourceFile: this.project.getSourceFile(this.startingFilePath),
765
- imports: this.startingImportSet
766
- });
767
- }
768
- shouldContinueVisiting() {
769
- return this.stack.length > 0;
770
- }
771
- getNextVisit() {
772
- if (this.stack.length === 0) {
773
- throw new Error("Done processing");
774
- }
775
- return this.stack.pop();
776
- }
777
- pushNextVisit(sourceFile, imports) {
778
- this.stack.push({
779
- sourceFile,
780
- imports
781
- });
782
- }
783
- shouldSkipTraversal(traversalStep) {
784
- const filePath = traversalStep.sourceFile.getFilePath();
785
- if (!this.visitedImports[filePath]) {
786
- this.visitedImports[filePath] = /* @__PURE__ */ new Set();
787
- }
788
- let shouldSkipCheck = true;
789
- for (const importToCheck of traversalStep.imports) {
790
- if (!this.visitedImports[filePath].has(importToCheck)) {
791
- shouldSkipCheck = false;
792
- this.visitedImports[filePath].add(importToCheck);
793
- }
794
- }
795
- return shouldSkipCheck;
796
- }
797
- getNodesToKeepForModule(moduleName) {
798
- if (!this.nodesToKeep[moduleName]) {
799
- this.nodesToKeep[moduleName] = /* @__PURE__ */ new Set();
800
- }
801
- return this.nodesToKeep[moduleName];
802
- }
803
- minifyProject() {
804
- while (this.shouldContinueVisiting()) {
805
- const visitImports = this.getNextVisit();
806
- if (this.shouldSkipTraversal(visitImports)) {
807
- continue;
808
- }
809
- const identifiersToResolve = /* @__PURE__ */ new Set();
810
- const sourceFile = visitImports.sourceFile;
811
- const moduleName = getModuleFromFileName(sourceFile);
812
- const nodeSet = this.getNodesToKeepForModule(moduleName);
813
- for (const [key, declarations] of sourceFile.getExportedDeclarations()) {
814
- if (!visitImports.imports.has(key)) {
815
- continue;
816
- }
817
- this.visitDependentExports(moduleName);
818
- this.visitDeclaration(declarations, nodeSet, identifiersToResolve);
819
- }
820
- for (const declaration of sourceFile.getExportDeclarations()) {
821
- const moduleSpecifier = declaration.getModuleSpecifier();
822
- if (!moduleSpecifier) {
823
- continue;
824
- }
825
- const literalText = moduleSpecifier.getLiteralText();
826
- const exportSourceFile = getModuleSourceFile(this.project, moduleSpecifier);
827
- if (!exportSourceFile) {
828
- continue;
829
- }
830
- if (declaration.isNamespaceExport()) {
831
- const namespaceExport = declaration.getNamespaceExport();
832
- if (namespaceExport) {
833
- if (visitImports.imports.has(namespaceExport.getName())) {
834
- this.getNodesToKeepForModule(moduleName).add(namespaceExport);
835
- const nodesToKeepForModule = this.getNodesToKeepForModule(getModuleFromFileName(exportSourceFile));
836
- nodesToKeepForModule.add(exportSourceFile);
837
- const importsFromNamespace = new Set(exportSourceFile.getExportedDeclarations().keys());
838
- this.pushNextVisit(exportSourceFile, importsFromNamespace);
839
- }
840
- }
841
- }
842
- const namedExports = declaration.getNamedExports();
843
- if (namedExports.length === 0) {
844
- this.pushNextVisit(exportSourceFile, visitImports.imports);
845
- if (!this.dependentExport[literalText]) {
846
- this.dependentExport[literalText] = /* @__PURE__ */ new Set();
847
- }
848
- this.dependentExport[literalText].add(declaration);
849
- continue;
850
- }
851
- this.visitNamedExports(namedExports, visitImports, nodeSet, exportSourceFile);
852
- }
853
- for (const declaration of sourceFile.getImportDeclarations()) {
854
- const namedImports = declaration.getNamedImports();
855
- const moduleSpecifier = declaration.getModuleSpecifier();
856
- if (!moduleSpecifier) {
857
- continue;
858
- }
859
- const importSourceFile = getModuleSourceFile(this.project, moduleSpecifier);
860
- if (!importSourceFile) {
861
- continue;
862
- }
863
- if (namedImports.length === 0) {
864
- const aliasedSymbol = declaration.getImportClause()?.getNamespaceImport()?.getSymbol();
865
- if (aliasedSymbol && identifiersToResolve.has(aliasedSymbol)) {
866
- this.getNodesToKeepForModule(moduleName).add(declaration);
867
- const importsFromNamespace = new Set(importSourceFile.getExportedDeclarations().keys());
868
- importSourceFile.getExportDeclarations().forEach((decl) => {
869
- this.getNodesToKeepForModule(moduleSpecifier.getLiteralText()).add(decl);
870
- });
871
- this.getNodesToKeepForModule(moduleSpecifier.getLiteralText()).add(sourceFile);
872
- this.pushNextVisit(importSourceFile, importsFromNamespace);
873
- }
874
- continue;
875
- }
876
- this.visitNamedImports(namedImports, identifiersToResolve, moduleName, declaration, importSourceFile);
877
- }
878
- }
879
- this.deleteUnused();
880
- }
881
- visitNamedImports(namedImports, identifiersToResolve, moduleName, declaration, importSourceFile) {
882
- const importsToVisit = /* @__PURE__ */ new Set();
883
- for (const namedImport of namedImports) {
884
- const symbol = namedImport.getSymbol();
885
- if (!symbol) {
886
- continue;
887
- }
888
- if (identifiersToResolve.has(symbol)) {
889
- importsToVisit.add(symbol.getName());
890
- importsToVisit.add(namedImport.getName());
891
- this.getNodesToKeepForModule(moduleName).add(namedImport);
892
- this.getNodesToKeepForModule(moduleName).add(declaration);
893
- }
894
- }
895
- this.pushNextVisit(importSourceFile, importsToVisit);
896
- }
897
- // For each named export if it is something that we need, we keep the export
898
- // And visit the module it is exported from
899
- // export { A } from ".."
900
- visitNamedExports(namedExports, visitImports, nodeSet, exportSourceFile) {
901
- const exportsToVisit = /* @__PURE__ */ new Set();
902
- for (const namedExport of namedExports) {
903
- const symbol = namedExport.getSymbol();
904
- if (!symbol) {
905
- continue;
906
- }
907
- if (!visitImports.imports.has(symbol.getName())) {
908
- continue;
909
- }
910
- exportsToVisit.add(symbol.getName());
911
- nodeSet.add(namedExport);
912
- for (const ancestor of namedExport.getAncestors()) {
913
- nodeSet.add(ancestor);
914
- }
915
- }
916
- this.pushNextVisit(exportSourceFile, exportsToVisit);
917
- }
918
- // Traverse the declaration and it's dependent symbols
919
- visitDeclaration(declarations, nodeSet, identifiers) {
920
- const declarationStack = declarations;
921
- while (declarationStack.length > 0) {
922
- const currentDeclaration = declarationStack.pop();
923
- if (nodeSet.has(currentDeclaration)) {
924
- continue;
925
- }
926
- nodeSet.add(currentDeclaration);
927
- for (const ancestor of currentDeclaration.getAncestors()) {
928
- nodeSet.add(ancestor);
929
- }
930
- for (const child of currentDeclaration.getDescendantsOfKind(SyntaxKind.Identifier)) {
931
- const symbol = child.getSymbol();
932
- if (!symbol || identifiers.has(symbol)) {
933
- continue;
934
- }
935
- identifiers.add(symbol);
936
- for (const symbolDeclaration of symbol.getDeclarations()) {
937
- if (Node.isImportDeclaration(symbolDeclaration)) {
938
- const importSourceFile = getModuleSourceFile(this.project, symbolDeclaration.getModuleSpecifier());
939
- if (!importSourceFile) {
940
- continue;
941
- }
942
- this.pushNextVisit(importSourceFile, new Set(symbol.getName()));
943
- } else {
944
- declarationStack.push(symbolDeclaration);
945
- }
946
- }
947
- }
948
- }
949
- }
950
- deleteUnused() {
951
- const deletedModules = /* @__PURE__ */ new Set();
952
- this.project.getSourceFiles().forEach((sourceFile) => {
953
- if (sourceFile.getFilePath().startsWith("/internal")) {
954
- const moduleName = getModuleFromFileName(sourceFile);
955
- const nodesToKeepForModule = this.nodesToKeep[moduleName];
956
- if (!nodesToKeepForModule || nodesToKeepForModule.size === 0) {
957
- deletedModules.add(moduleName);
958
- sourceFile.deleteImmediatelySync();
959
- return;
960
- }
961
- sourceFile.getImportDeclarations().forEach((importDeclaration) => {
962
- importDeclaration.getNamedImports().forEach((namedImport) => {
963
- if (nodesToKeepForModule && !nodesToKeepForModule.has(namedImport)) {
964
- namedImport.remove();
965
- }
966
- });
967
- });
968
- for (const exportDeclaration of sourceFile.getExportDeclarations()) {
969
- const targetModuleSpecifier = exportDeclaration.getModuleSpecifier();
970
- if (!targetModuleSpecifier) {
971
- continue;
972
- }
973
- const targetModuleLiteralText = targetModuleSpecifier.getLiteralText();
974
- if (deletedModules.has(targetModuleLiteralText)) {
975
- continue;
976
- }
977
- const nodesToKeepForTargetModule = this.nodesToKeep[targetModuleLiteralText];
978
- if (!nodesToKeepForTargetModule || nodesToKeepForTargetModule.size === 0) {
979
- exportDeclaration.remove();
980
- continue;
981
- }
982
- for (const namedExport of exportDeclaration.getNamedExports()) {
983
- if (!nodesToKeepForTargetModule.has(namedExport)) {
984
- namedExport.remove();
985
- }
986
- }
987
- }
988
- sourceFile.forEachChild((node) => {
989
- if (!nodesToKeepForModule.has(node)) {
990
- node.replaceWithText("");
991
- }
992
- });
993
- const lines = sourceFile.getText().split("\n");
994
- if (lines.length === 0) {
995
- deletedModules.add(moduleName);
996
- sourceFile.deleteImmediatelySync();
997
- return;
998
- }
999
- }
1000
- });
1001
- }
1002
- // Visit all files up which have done
1003
- // `export * from "moduleName"`
1004
- visitDependentExports(moduleName) {
1005
- if (!this.dependentExport[moduleName]) {
1006
- return;
1007
- }
1008
- const dependentExportStack = [moduleName];
1009
- while (dependentExportStack.length > 0) {
1010
- const nextModuleName = dependentExportStack.pop();
1011
- if (!this.dependentExport[nextModuleName]) {
1012
- continue;
1013
- }
1014
- for (const node of this.dependentExport[nextModuleName]) {
1015
- const reexportModuleName = getModuleFromFileName(node.getSourceFile());
1016
- this.getNodesToKeepForModule(reexportModuleName).add(node);
1017
- dependentExportStack.push(reexportModuleName);
1018
- }
1019
- }
1020
- }
1021
- };
1022
- function getModuleFromFileName(sourceFile) {
1023
- return sourceFile.getFilePath().replace("/", "").replace(".ts", "").replace("/index", "");
1024
- }
1025
737
 
1026
738
  // src/generate/betaClient/bundleDependencies.ts
1027
739
  async function bundleDependencies(dirs, generatedPackageName, generatedFiles, entry) {
@@ -1033,11 +745,7 @@ async function bundleDependencies(dirs, generatedPackageName, generatedFiles, en
1033
745
  outFile: "dist/bundle/index.d.ts"
1034
746
  }
1035
747
  });
1036
- const importSet = await copyFiles(project, dirs, generatedPackageName, generatedFiles);
1037
- if (entry) {
1038
- const projectMinifier = new ProjectMinifier(project, importSet, entry);
1039
- projectMinifier.minifyProject();
1040
- }
748
+ await copyFiles(project, dirs, generatedPackageName, generatedFiles);
1041
749
  return outputModule(project);
1042
750
  }
1043
751
  function outputModule(project) {
@@ -1134,9 +842,6 @@ async function generatePackageJson(options) {
1134
842
  }
1135
843
 
1136
844
  // src/generate/betaClient/generatePackage.ts
1137
- var dependencies = {
1138
- "@osdk/legacy-client": typeof __OSDK_LEGACY_CLIENT_VERSION__ !== "undefined" ? __OSDK_LEGACY_CLIENT_VERSION__ : void 0
1139
- };
1140
845
  var betaDependencies = {
1141
846
  "@osdk/client.api": typeof __OSDK_CLIENT_API_VERSION__ !== "undefined" ? __OSDK_CLIENT_API_VERSION__ : void 0,
1142
847
  "@osdk/api": typeof __OSDK_API_VERSION__ !== "undefined" ? __OSDK_API_VERSION__ : void 0
@@ -1146,7 +851,7 @@ async function generatePackage(ontology, options) {
1146
851
  consola
1147
852
  } = await import('consola');
1148
853
  const packagePath = join(options.outputDir, options.packageName);
1149
- const resolvedDependencies = await Promise.all(Object.keys(options.beta ? betaDependencies : dependencies).map(async (dependency) => {
854
+ const resolvedDependencies = await Promise.all(Object.keys(betaDependencies).map(async (dependency) => {
1150
855
  return {
1151
856
  dependencyName: dependency,
1152
857
  dependencyVersion: await getDependencyVersion(dependency)
@@ -1168,7 +873,7 @@ async function generatePackage(ontology, options) {
1168
873
  readdir: (path3) => readdir(path3)
1169
874
  };
1170
875
  if (!options.beta) {
1171
- await generateClientSdkVersionOneDotOne(ontology, `typescript-sdk/${options.packageVersion} ${USER_AGENT}`, hostFs, packagePath);
876
+ throw new Error("Only beta is supported in this version");
1172
877
  } else {
1173
878
  await generateClientSdkVersionTwoPointZero(ontology, `typescript-sdk/${options.packageVersion} ${USER_AGENT}`, hostFs, packagePath, "module");
1174
879
  }
@@ -1189,7 +894,7 @@ async function generatePackage(ontology, options) {
1189
894
  let bundleDts = "";
1190
895
  if (nodeModulesPath) {
1191
896
  try {
1192
- bundleDts = await bundleDependencies(options.beta ? [] : [join(nodeModulesPath, "@osdk", "legacy-client"), join(nodeModulesPath, "@osdk", "api"), join(nodeModulesPath, "@osdk", "gateway")], options.packageName, compilerOutput.files, options.beta ? void 0 : `internal/@osdk/legacy-client/index.ts`);
897
+ bundleDts = await bundleDependencies([], options.packageName, compilerOutput.files, void 0);
1193
898
  } catch (e) {
1194
899
  consola.error("Failed bundling DTS", e);
1195
900
  }
@@ -1217,9 +922,6 @@ async function generatePackage(ontology, options) {
1217
922
  }
1218
923
  }
1219
924
  async function getDependencyVersion(dependency) {
1220
- if (dependencies[dependency] !== void 0) {
1221
- return dependencies[dependency];
1222
- }
1223
925
  const {
1224
926
  findUp
1225
927
  } = await import('find-up');