@osdk/foundry-sdk-generator 1.4.0-beta.4 → 2.0.0-beta.10

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.
Files changed (74) hide show
  1. package/CHANGELOG.md +120 -0
  2. package/bin/{foundry-sdk-generator.cjs → foundry-sdk-generator.mjs} +2 -2
  3. package/build/browser/index.js +18 -544
  4. package/build/browser/index.js.map +1 -1
  5. package/build/esm/generate/betaClient/generatePackage.d.ts.map +1 -1
  6. package/build/esm/index.js +18 -544
  7. package/build/esm/index.js.map +1 -1
  8. package/build/esm/ontologyMetadata/ontologyMetadataResolver.d.ts +1 -1
  9. package/build/esm/ontologyMetadata/ontologyMetadataResolver.d.ts.map +1 -1
  10. package/package.json +15 -15
  11. package/build/cjs/cli/foundrySdkGeneratorCli.d.cts +0 -6
  12. package/build/cjs/cli/foundrySdkGeneratorCli.d.ts.map +0 -1
  13. package/build/cjs/generate/GeneratePackageCommand.d.cts +0 -24
  14. package/build/cjs/generate/GeneratePackageCommand.d.ts.map +0 -1
  15. package/build/cjs/generate/betaClient/__tests__/bundleDependencies.test.d.cts +0 -2
  16. package/build/cjs/generate/betaClient/__tests__/bundleDependencies.test.d.ts.map +0 -1
  17. package/build/cjs/generate/betaClient/bundleDependencies.d.cts +0 -6
  18. package/build/cjs/generate/betaClient/bundleDependencies.d.ts.map +0 -1
  19. package/build/cjs/generate/betaClient/compileInMemory.d.cts +0 -18
  20. package/build/cjs/generate/betaClient/compileInMemory.d.ts.map +0 -1
  21. package/build/cjs/generate/betaClient/copyFiles.d.cts +0 -5
  22. package/build/cjs/generate/betaClient/copyFiles.d.ts.map +0 -1
  23. package/build/cjs/generate/betaClient/generatePackage.d.cts +0 -8
  24. package/build/cjs/generate/betaClient/generatePackage.d.ts.map +0 -1
  25. package/build/cjs/generate/betaClient/generatePackageJson.d.cts +0 -11
  26. package/build/cjs/generate/betaClient/generatePackageJson.d.ts.map +0 -1
  27. package/build/cjs/generate/betaClient/getModuleSourceFile.d.cts +0 -4
  28. package/build/cjs/generate/betaClient/getModuleSourceFile.d.ts.map +0 -1
  29. package/build/cjs/generate/betaClient/minifyBundle.d.cts +0 -23
  30. package/build/cjs/generate/betaClient/minifyBundle.d.ts.map +0 -1
  31. package/build/cjs/generate/commandUtils.d.cts +0 -2
  32. package/build/cjs/generate/commandUtils.d.ts.map +0 -1
  33. package/build/cjs/generate/generateBundles.d.cts +0 -2
  34. package/build/cjs/generate/generateBundles.d.ts.map +0 -1
  35. package/build/cjs/generate/index.d.cts +0 -2
  36. package/build/cjs/generate/index.d.ts.map +0 -1
  37. package/build/cjs/index.cjs +0 -1407
  38. package/build/cjs/index.cjs.map +0 -1
  39. package/build/cjs/index.d.cts +0 -3
  40. package/build/cjs/index.d.ts.map +0 -1
  41. package/build/cjs/net/BaseError.d.cts +0 -8
  42. package/build/cjs/net/BaseError.d.ts.map +0 -1
  43. package/build/cjs/net/Constants.d.cts +0 -2
  44. package/build/cjs/net/Constants.d.ts.map +0 -1
  45. package/build/cjs/net/FetchClient.d.cts +0 -23
  46. package/build/cjs/net/FetchClient.d.ts.map +0 -1
  47. package/build/cjs/net/MediaType.d.cts +0 -8
  48. package/build/cjs/net/MediaType.d.ts.map +0 -1
  49. package/build/cjs/net/ResponseType.d.cts +0 -7
  50. package/build/cjs/net/ResponseType.d.ts.map +0 -1
  51. package/build/cjs/net/fetch/authenticatedFetch.d.cts +0 -8
  52. package/build/cjs/net/fetch/authenticatedFetch.d.ts.map +0 -1
  53. package/build/cjs/net/fetch/fetchFactory.d.cts +0 -13
  54. package/build/cjs/net/fetch/fetchFactory.d.ts.map +0 -1
  55. package/build/cjs/net/fetch/index.d.cts +0 -4
  56. package/build/cjs/net/fetch/index.d.ts.map +0 -1
  57. package/build/cjs/net/fetch/retryingFetch.d.cts +0 -13
  58. package/build/cjs/net/fetch/retryingFetch.d.ts.map +0 -1
  59. package/build/cjs/ontologyMetadata/Result.d.cts +0 -32
  60. package/build/cjs/ontologyMetadata/Result.d.ts.map +0 -1
  61. package/build/cjs/ontologyMetadata/index.d.cts +0 -2
  62. package/build/cjs/ontologyMetadata/index.d.ts.map +0 -1
  63. package/build/cjs/ontologyMetadata/metadataResolver.test.d.cts +0 -2
  64. package/build/cjs/ontologyMetadata/metadataResolver.test.d.ts.map +0 -1
  65. package/build/cjs/ontologyMetadata/ontologyMetadataResolver.d.cts +0 -23
  66. package/build/cjs/ontologyMetadata/ontologyMetadataResolver.d.ts.map +0 -1
  67. package/build/cjs/utils/UserAgent.d.cts +0 -2
  68. package/build/cjs/utils/UserAgent.d.ts.map +0 -1
  69. package/build/cjs/utils/index.d.cts +0 -2
  70. package/build/cjs/utils/index.d.ts.map +0 -1
  71. package/build/cjs/utils/semverUtils.d.cts +0 -2
  72. package/build/cjs/utils/semverUtils.d.ts.map +0 -1
  73. package/build/esm/net/FetchClient.d.ts +0 -23
  74. package/build/esm/net/FetchClient.d.ts.map +0 -1
@@ -4,15 +4,14 @@ import path2__default, { join, isAbsolute, normalize } from 'path';
4
4
  import yargs from 'yargs';
5
5
  import { hideBin } from 'yargs/helpers';
6
6
  import { exit } from 'process';
7
- import { namespaces } from '@osdk/gateway';
8
- import { UserTokenAuth } from '@osdk/legacy-client';
9
- import { generateClientSdkVersionOneDotOne, generateClientSdkVersionTwoPointZero } from '@osdk/generator';
7
+ import { createClientContext } from '@osdk/shared.net';
8
+ import { generateClientSdkVersionTwoPointZero } from '@osdk/generator';
10
9
  import { mkdir, writeFile, readFile, readdir } from 'fs/promises';
11
10
  import commonjs from '@rollup/plugin-commonjs';
12
11
  import { nodeResolve } from '@rollup/plugin-node-resolve';
13
12
  import { rollup } from 'rollup';
14
13
  import nodePolyfill from 'rollup-plugin-polyfill-node';
15
- import { Project, Node, SyntaxKind } from 'ts-morph';
14
+ import { Project, Node } from 'ts-morph';
16
15
  import * as fs from 'fs';
17
16
  import { ModuleKind, ScriptTarget, createCompilerHost, createSourceFile, createProgram } from 'typescript';
18
17
 
@@ -21,237 +20,6 @@ var getFilename = () => fileURLToPath(import.meta.url);
21
20
  var getDirname = () => path2__default.dirname(getFilename());
22
21
  var __dirname = /* @__PURE__ */ getDirname();
23
22
 
24
- // src/net/Constants.ts
25
- var API_BASE_URL = (host) => {
26
- if (host.startsWith("http") || host.startsWith("https")) {
27
- return `${host}`;
28
- }
29
- return `https://${host}`;
30
- };
31
-
32
- // src/net/fetch/authenticatedFetch.ts
33
- var AuthenticatedFetch = class {
34
- constructor(fetchFunction, auth) {
35
- this.fetchFunction = fetchFunction;
36
- this.auth = auth;
37
- }
38
- getFetch() {
39
- return (input, init) => {
40
- return this.auth.executeWithToken((token) => {
41
- return this.fetchFunction(input, {
42
- ...init,
43
- headers: {
44
- // Don't override auth headers if they are already set
45
- Authorization: `Bearer ${token.accessToken}`,
46
- ...init?.headers
47
- }
48
- });
49
- });
50
- };
51
- }
52
- };
53
-
54
- // src/net/fetch/retryingFetch.ts
55
- var RetryingFetch = class {
56
- constructor(fetchFunction, initialDelay = 1e3, jitterFactor = 0.5, maxRetries = 3) {
57
- this.fetchFunction = fetchFunction;
58
- this.initialDelay = initialDelay;
59
- this.jitterFactor = jitterFactor;
60
- this.maxRetries = maxRetries;
61
- }
62
- SERVICE_UNAVAILABLE = 503;
63
- TOO_MANY_REQUESTS = 429;
64
- getFetch() {
65
- return this.retryWithBackoff.bind(this, 0);
66
- }
67
- async retryWithBackoff(retries, url, init) {
68
- let response;
69
- let backoffDelay;
70
- try {
71
- response = await this.fetchFunction(url, init);
72
- if (response.ok) {
73
- return response;
74
- }
75
- backoffDelay = this.calculateBackoffDelay(retries, response.status);
76
- if (!backoffDelay) {
77
- return response;
78
- }
79
- } catch (error) {
80
- backoffDelay = this.calculateBackoffDelay(retries);
81
- if (!backoffDelay) {
82
- throw error;
83
- }
84
- }
85
- await new Promise((resolve) => setTimeout(resolve, backoffDelay));
86
- return this.retryWithBackoff(retries + 1, url, init);
87
- }
88
- calculateBackoffDelay(retries, status) {
89
- if (retries >= this.maxRetries) {
90
- return;
91
- }
92
- if (status && status !== this.SERVICE_UNAVAILABLE && status !== this.TOO_MANY_REQUESTS) {
93
- return;
94
- }
95
- const delay = this.initialDelay * 2 ** retries;
96
- const jitter = delay * this.jitterFactor * (Math.random() * 2 - 1);
97
- return delay + jitter;
98
- }
99
- };
100
-
101
- // src/net/fetch/fetchFactory.ts
102
- var FetchFactory = class {
103
- constructor(fetchFunction) {
104
- this.fetchFunction = fetchFunction;
105
- }
106
- /**
107
- * Creates a fetch instance with authentication, error handling, and retrying.
108
- *
109
- * @returns A fetch instance
110
- */
111
- getDefaultFetch(auth) {
112
- const authenticatedFetch = new AuthenticatedFetch(this.baseFetch, auth);
113
- const retryingFetch = new RetryingFetch(authenticatedFetch.getFetch());
114
- return retryingFetch.getFetch();
115
- }
116
- baseFetch = (input, auth) => {
117
- const fetchFunction = this.fetchFunction ?? globalThis.fetch;
118
- return fetchFunction(input, auth);
119
- };
120
- };
121
-
122
- // src/net/MediaType.ts
123
- var MediaType = /* @__PURE__ */ function(MediaType2) {
124
- MediaType2["APPLICATION_JSON"] = "application/json";
125
- MediaType2["APPLICATION_OCTET_STREAM"] = "application/octet-stream";
126
- MediaType2["APPLICATION_X_WWW_FORM_URLENCODED"] = "application/x-www-form-urlencoded";
127
- MediaType2["MULTIPART_FORM_DATA"] = "multipart/form-data";
128
- MediaType2["TEXT_PLAIN"] = "text/plain";
129
- return MediaType2;
130
- }({});
131
-
132
- // src/net/ResponseType.ts
133
- var ResponseType = /* @__PURE__ */ function(ResponseType2) {
134
- ResponseType2[ResponseType2["JSON"] = 0] = "JSON";
135
- ResponseType2[ResponseType2["BLOB"] = 1] = "BLOB";
136
- ResponseType2[ResponseType2["TEXT"] = 2] = "TEXT";
137
- ResponseType2[ResponseType2["STREAM"] = 3] = "STREAM";
138
- return ResponseType2;
139
- }({});
140
-
141
- // src/net/FetchClient.ts
142
- function getApiRequestFunction(auth, url, userAgent, contextPath = "/api", fetchFunction) {
143
- const fetchClient = new FetchClient(auth, url, userAgent, contextPath, fetchFunction);
144
- return (method, endpointPath, data, queryArguments, headers, requestMediaType, responseMediaType) => fetchClient.request(method, endpointPath, data, queryArguments, headers, requestMediaType, responseMediaType);
145
- }
146
- var FetchClient = class {
147
- constructor(auth, url, userAgent, contextPath = "/api", fetchFunction) {
148
- this.userAgent = userAgent;
149
- this.contextPath = contextPath;
150
- const fetchFactory = new FetchFactory(fetchFunction);
151
- this.fetchFunction = fetchFactory.getDefaultFetch(auth);
152
- this.url = API_BASE_URL(url);
153
- }
154
- async request(method, endpointPath, data, queryArguments, headers, _requestMediaType = "application/json", responseMediaType = "application/json", responseAsStream) {
155
- const url = new URL(`${this.contextPath}${endpointPath}`, `${this.url}`);
156
- for (const [queryArgumentName, queryArgumentValue] of Object.entries(queryArguments || {})) {
157
- if (queryArgumentValue) {
158
- if (queryArgumentValue.constructor === Array) {
159
- for (const value of queryArgumentValue) {
160
- url.searchParams.append(queryArgumentName, value);
161
- }
162
- continue;
163
- } else {
164
- url.searchParams.append(queryArgumentName, queryArgumentValue);
165
- }
166
- }
167
- }
168
- const headersInit = {};
169
- Object.entries(headers || {}).forEach(([key, value]) => {
170
- if (value != null) {
171
- headersInit[key] = value.toString();
172
- }
173
- });
174
- const response = await this.fetchWithContentType(url, {
175
- method,
176
- body: data,
177
- headers: headersInit
178
- });
179
- if (responseAsStream && response.body) {
180
- return response.body;
181
- }
182
- if (responseMediaType === MediaType.APPLICATION_JSON) {
183
- return response.json();
184
- } else if (responseMediaType === "*/*") {
185
- return response.blob();
186
- }
187
- return response.json();
188
- }
189
- async callAPI(url, method = "GET", body, responseType = ResponseType.JSON) {
190
- const response = await this.fetchWithContentType(url, {
191
- method,
192
- body
193
- });
194
- const contentType = response.headers.get("Content-Type") != null ? response.headers.get("Content-Type") : "";
195
- let bodyPromise;
196
- if (responseType === ResponseType.BLOB) {
197
- bodyPromise = response.blob();
198
- } else if (contentType.includes(MediaType.APPLICATION_JSON)) {
199
- bodyPromise = response.json();
200
- } else if (contentType.includes(MediaType.APPLICATION_OCTET_STREAM)) {
201
- bodyPromise = response.blob();
202
- } else {
203
- bodyPromise = response.text();
204
- }
205
- const responseBody = await bodyPromise;
206
- return responseBody;
207
- }
208
- async fetchWithContentType(url, init) {
209
- if (!init?.body) {
210
- return this.fetchFunction(url.toString(), {
211
- ...init,
212
- headers: this.getHeaders(init?.headers)
213
- });
214
- }
215
- const contentType = this.getContentTypeForBody(init.body);
216
- return this.fetchFunction(url.toString(), {
217
- ...init,
218
- headers: this.getHeaders(init?.headers, contentType),
219
- body: this.getBodyForContentType(init.body)
220
- });
221
- }
222
- getContentTypeForBody(body) {
223
- if (globalThis.Blob && body instanceof globalThis.Blob) {
224
- return body.type;
225
- }
226
- if (typeof body === "string") {
227
- return MediaType.TEXT_PLAIN;
228
- }
229
- if (globalThis.ArrayBuffer && (globalThis.ArrayBuffer.isView(body) || body instanceof globalThis.ArrayBuffer)) {
230
- return MediaType.APPLICATION_OCTET_STREAM;
231
- }
232
- if (globalThis.Uint8Array && body instanceof globalThis.Uint8Array) {
233
- return MediaType.APPLICATION_OCTET_STREAM;
234
- }
235
- return MediaType.APPLICATION_JSON;
236
- }
237
- getBodyForContentType(body) {
238
- if (!body) {
239
- return void 0;
240
- }
241
- if (globalThis.Blob && body instanceof globalThis.Blob) {
242
- return body;
243
- }
244
- return JSON.stringify(body);
245
- }
246
- getHeaders(init, contentType = MediaType.APPLICATION_JSON) {
247
- return {
248
- "Content-Type": contentType,
249
- "Fetch-User-Agent": this.userAgent,
250
- ...init
251
- };
252
- }
253
- };
254
-
255
23
  // src/ontologyMetadata/Result.ts
256
24
  var Ok = class {
257
25
  constructor(value) {
@@ -330,10 +98,8 @@ var OntologyMetadataResolver = class {
330
98
  this.stackName = stackName;
331
99
  this.#authToken = authToken;
332
100
  }
333
- getRequestFunction() {
334
- return getApiRequestFunction(new UserTokenAuth({
335
- userToken: this.#authToken
336
- }), this.stackName, `foundry-typescript-osdk-generator/${process.env.npm_package_version}`, "/api");
101
+ getClientContext() {
102
+ return createClientContext(this.stackName.match(/^https?:\/\//) ? this.stackName : `https://${this.stackName}`, () => this.#authToken, `foundry-typescript-osdk-generator/${process.env.npm_package_version}`);
337
103
  }
338
104
  filterMetadata(ontologyFullMetadata, expectedEntities) {
339
105
  const filteredObjectTypes = Object.fromEntries(Object.entries(ontologyFullMetadata.objectTypes).filter(([objectTypeApiName]) => expectedEntities.objectTypes.has(objectTypeApiName.toLowerCase())));
@@ -364,12 +130,18 @@ var OntologyMetadataResolver = class {
364
130
  }
365
131
  async getWireOntologyDefinition(ontologyRid, entities) {
366
132
  let ontology;
133
+ const {
134
+ Ontologies
135
+ } = await import('@osdk/internal.foundry.ontologies');
136
+ const {
137
+ OntologiesV2
138
+ } = await import('@osdk/internal.foundry.ontologiesv2');
367
139
  try {
368
- ontology = await namespaces.getOntology(this.getRequestFunction(), ontologyRid);
140
+ ontology = await Ontologies.getOntology(this.getClientContext(), ontologyRid);
369
141
  } catch (e) {
370
142
  return Result.err([`Unable to load the specified Ontology with network error: ${JSON.stringify(e)}`]);
371
143
  }
372
- const ontologyFullMetadata = await namespaces.getOntologyFullMetadata(this.getRequestFunction(), ontology.rid);
144
+ const ontologyFullMetadata = await OntologiesV2.getOntologyFullMetadata(this.getClientContext(), ontology.rid);
373
145
  if (ontologyFullMetadata.errorName != null) {
374
146
  return Result.err([`Unable to load the specified Ontology metadata.
375
147
  ${JSON.stringify(ontologyFullMetadata, null, 2)}`]);
@@ -561,7 +333,7 @@ function isValidSemver(semverString) {
561
333
  }
562
334
 
563
335
  // src/utils/UserAgent.ts
564
- var USER_AGENT = `typescript-sdk-generator/${"1.4.0-beta.4"}`;
336
+ var USER_AGENT = `typescript-sdk-generator/${"2.0.0-beta.10"}`;
565
337
  async function createRollupBuild(absolutePackagePath, packageName) {
566
338
  const inputPath = `${absolutePackagePath}/${packageName}/index.js`;
567
339
  const {
@@ -604,23 +376,6 @@ async function generateEsmBuild(absolutePackagePath, packageName) {
604
376
  async function generateBundles(absolutePackagePath, packageName) {
605
377
  await Promise.all([generateEsmBuild(absolutePackagePath, packageName)]);
606
378
  }
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
379
  function withoutTrailingIndex(filePath) {
625
380
  return filePath.endsWith("/index") ? filePath.slice(0, -6) : filePath;
626
381
  }
@@ -751,277 +506,6 @@ function transformModuleSpecifier(value, filePath) {
751
506
  function withoutExtension(value) {
752
507
  return value.replace(".js", "");
753
508
  }
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
509
 
1026
510
  // src/generate/betaClient/bundleDependencies.ts
1027
511
  async function bundleDependencies(dirs, generatedPackageName, generatedFiles, entry) {
@@ -1033,11 +517,7 @@ async function bundleDependencies(dirs, generatedPackageName, generatedFiles, en
1033
517
  outFile: "dist/bundle/index.d.ts"
1034
518
  }
1035
519
  });
1036
- const importSet = await copyFiles(project, dirs, generatedPackageName, generatedFiles);
1037
- if (entry) {
1038
- const projectMinifier = new ProjectMinifier(project, importSet, entry);
1039
- projectMinifier.minifyProject();
1040
- }
520
+ await copyFiles(project, dirs, generatedPackageName, generatedFiles);
1041
521
  return outputModule(project);
1042
522
  }
1043
523
  function outputModule(project) {
@@ -1134,9 +614,6 @@ async function generatePackageJson(options) {
1134
614
  }
1135
615
 
1136
616
  // 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
617
  var betaDependencies = {
1141
618
  "@osdk/client.api": typeof __OSDK_CLIENT_API_VERSION__ !== "undefined" ? __OSDK_CLIENT_API_VERSION__ : void 0,
1142
619
  "@osdk/api": typeof __OSDK_API_VERSION__ !== "undefined" ? __OSDK_API_VERSION__ : void 0
@@ -1146,7 +623,7 @@ async function generatePackage(ontology, options) {
1146
623
  consola
1147
624
  } = await import('consola');
1148
625
  const packagePath = join(options.outputDir, options.packageName);
1149
- const resolvedDependencies = await Promise.all(Object.keys(options.beta ? betaDependencies : dependencies).map(async (dependency) => {
626
+ const resolvedDependencies = await Promise.all(Object.keys(betaDependencies).map(async (dependency) => {
1150
627
  return {
1151
628
  dependencyName: dependency,
1152
629
  dependencyVersion: await getDependencyVersion(dependency)
@@ -1168,7 +645,7 @@ async function generatePackage(ontology, options) {
1168
645
  readdir: (path3) => readdir(path3)
1169
646
  };
1170
647
  if (!options.beta) {
1171
- await generateClientSdkVersionOneDotOne(ontology, `typescript-sdk/${options.packageVersion} ${USER_AGENT}`, hostFs, packagePath);
648
+ throw new Error("Only beta is supported in this version");
1172
649
  } else {
1173
650
  await generateClientSdkVersionTwoPointZero(ontology, `typescript-sdk/${options.packageVersion} ${USER_AGENT}`, hostFs, packagePath, "module");
1174
651
  }
@@ -1189,7 +666,7 @@ async function generatePackage(ontology, options) {
1189
666
  let bundleDts = "";
1190
667
  if (nodeModulesPath) {
1191
668
  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`);
669
+ bundleDts = await bundleDependencies([], options.packageName, compilerOutput.files, void 0);
1193
670
  } catch (e) {
1194
671
  consola.error("Failed bundling DTS", e);
1195
672
  }
@@ -1217,9 +694,6 @@ async function generatePackage(ontology, options) {
1217
694
  }
1218
695
  }
1219
696
  async function getDependencyVersion(dependency) {
1220
- if (dependencies[dependency] !== void 0) {
1221
- return dependencies[dependency];
1222
- }
1223
697
  const {
1224
698
  findUp
1225
699
  } = await import('find-up');