@osdk/foundry-sdk-generator 1.4.0-beta.5 → 2.0.0-beta.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.
- package/CHANGELOG.md +44 -0
- package/build/browser/index.js +18 -544
- package/build/browser/index.js.map +1 -1
- package/build/cjs/generate/betaClient/generatePackage.d.ts.map +1 -1
- package/build/cjs/index.cjs +16 -542
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/ontologyMetadata/ontologyMetadataResolver.d.cts +1 -1
- package/build/cjs/ontologyMetadata/ontologyMetadataResolver.d.ts.map +1 -1
- package/build/esm/generate/betaClient/generatePackage.d.ts.map +1 -1
- package/build/esm/index.js +18 -544
- package/build/esm/index.js.map +1 -1
- package/build/esm/ontologyMetadata/ontologyMetadataResolver.d.ts +1 -1
- package/build/esm/ontologyMetadata/ontologyMetadataResolver.d.ts.map +1 -1
- package/package.json +13 -10
- package/build/cjs/net/FetchClient.d.cts +0 -23
- package/build/cjs/net/FetchClient.d.ts.map +0 -1
- package/build/esm/net/FetchClient.d.ts +0 -23
- package/build/esm/net/FetchClient.d.ts.map +0 -1
package/build/cjs/index.cjs
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
var yargs = require('yargs');
|
|
4
4
|
var helpers = require('yargs/helpers');
|
|
5
5
|
var process$1 = require('process');
|
|
6
|
-
var
|
|
7
|
-
var legacyClient = require('@osdk/legacy-client');
|
|
6
|
+
var shared_net = require('@osdk/shared.net');
|
|
8
7
|
var generator = require('@osdk/generator');
|
|
9
8
|
var promises = require('fs/promises');
|
|
10
9
|
var path = require('path');
|
|
@@ -44,237 +43,6 @@ var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
|
44
43
|
|
|
45
44
|
// src/cli/foundrySdkGeneratorCli.ts
|
|
46
45
|
|
|
47
|
-
// src/net/Constants.ts
|
|
48
|
-
var API_BASE_URL = (host) => {
|
|
49
|
-
if (host.startsWith("http") || host.startsWith("https")) {
|
|
50
|
-
return `${host}`;
|
|
51
|
-
}
|
|
52
|
-
return `https://${host}`;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// src/net/fetch/authenticatedFetch.ts
|
|
56
|
-
var AuthenticatedFetch = class {
|
|
57
|
-
constructor(fetchFunction, auth) {
|
|
58
|
-
this.fetchFunction = fetchFunction;
|
|
59
|
-
this.auth = auth;
|
|
60
|
-
}
|
|
61
|
-
getFetch() {
|
|
62
|
-
return (input, init) => {
|
|
63
|
-
return this.auth.executeWithToken((token) => {
|
|
64
|
-
return this.fetchFunction(input, {
|
|
65
|
-
...init,
|
|
66
|
-
headers: {
|
|
67
|
-
// Don't override auth headers if they are already set
|
|
68
|
-
Authorization: `Bearer ${token.accessToken}`,
|
|
69
|
-
...init?.headers
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// src/net/fetch/retryingFetch.ts
|
|
78
|
-
var RetryingFetch = class {
|
|
79
|
-
constructor(fetchFunction, initialDelay = 1e3, jitterFactor = 0.5, maxRetries = 3) {
|
|
80
|
-
this.fetchFunction = fetchFunction;
|
|
81
|
-
this.initialDelay = initialDelay;
|
|
82
|
-
this.jitterFactor = jitterFactor;
|
|
83
|
-
this.maxRetries = maxRetries;
|
|
84
|
-
}
|
|
85
|
-
SERVICE_UNAVAILABLE = 503;
|
|
86
|
-
TOO_MANY_REQUESTS = 429;
|
|
87
|
-
getFetch() {
|
|
88
|
-
return this.retryWithBackoff.bind(this, 0);
|
|
89
|
-
}
|
|
90
|
-
async retryWithBackoff(retries, url, init) {
|
|
91
|
-
let response;
|
|
92
|
-
let backoffDelay;
|
|
93
|
-
try {
|
|
94
|
-
response = await this.fetchFunction(url, init);
|
|
95
|
-
if (response.ok) {
|
|
96
|
-
return response;
|
|
97
|
-
}
|
|
98
|
-
backoffDelay = this.calculateBackoffDelay(retries, response.status);
|
|
99
|
-
if (!backoffDelay) {
|
|
100
|
-
return response;
|
|
101
|
-
}
|
|
102
|
-
} catch (error) {
|
|
103
|
-
backoffDelay = this.calculateBackoffDelay(retries);
|
|
104
|
-
if (!backoffDelay) {
|
|
105
|
-
throw error;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
await new Promise((resolve) => setTimeout(resolve, backoffDelay));
|
|
109
|
-
return this.retryWithBackoff(retries + 1, url, init);
|
|
110
|
-
}
|
|
111
|
-
calculateBackoffDelay(retries, status) {
|
|
112
|
-
if (retries >= this.maxRetries) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
if (status && status !== this.SERVICE_UNAVAILABLE && status !== this.TOO_MANY_REQUESTS) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const delay = this.initialDelay * 2 ** retries;
|
|
119
|
-
const jitter = delay * this.jitterFactor * (Math.random() * 2 - 1);
|
|
120
|
-
return delay + jitter;
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
// src/net/fetch/fetchFactory.ts
|
|
125
|
-
var FetchFactory = class {
|
|
126
|
-
constructor(fetchFunction) {
|
|
127
|
-
this.fetchFunction = fetchFunction;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Creates a fetch instance with authentication, error handling, and retrying.
|
|
131
|
-
*
|
|
132
|
-
* @returns A fetch instance
|
|
133
|
-
*/
|
|
134
|
-
getDefaultFetch(auth) {
|
|
135
|
-
const authenticatedFetch = new AuthenticatedFetch(this.baseFetch, auth);
|
|
136
|
-
const retryingFetch = new RetryingFetch(authenticatedFetch.getFetch());
|
|
137
|
-
return retryingFetch.getFetch();
|
|
138
|
-
}
|
|
139
|
-
baseFetch = (input, auth) => {
|
|
140
|
-
const fetchFunction = this.fetchFunction ?? globalThis.fetch;
|
|
141
|
-
return fetchFunction(input, auth);
|
|
142
|
-
};
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
// src/net/MediaType.ts
|
|
146
|
-
var MediaType = /* @__PURE__ */ function(MediaType2) {
|
|
147
|
-
MediaType2["APPLICATION_JSON"] = "application/json";
|
|
148
|
-
MediaType2["APPLICATION_OCTET_STREAM"] = "application/octet-stream";
|
|
149
|
-
MediaType2["APPLICATION_X_WWW_FORM_URLENCODED"] = "application/x-www-form-urlencoded";
|
|
150
|
-
MediaType2["MULTIPART_FORM_DATA"] = "multipart/form-data";
|
|
151
|
-
MediaType2["TEXT_PLAIN"] = "text/plain";
|
|
152
|
-
return MediaType2;
|
|
153
|
-
}({});
|
|
154
|
-
|
|
155
|
-
// src/net/ResponseType.ts
|
|
156
|
-
var ResponseType = /* @__PURE__ */ function(ResponseType2) {
|
|
157
|
-
ResponseType2[ResponseType2["JSON"] = 0] = "JSON";
|
|
158
|
-
ResponseType2[ResponseType2["BLOB"] = 1] = "BLOB";
|
|
159
|
-
ResponseType2[ResponseType2["TEXT"] = 2] = "TEXT";
|
|
160
|
-
ResponseType2[ResponseType2["STREAM"] = 3] = "STREAM";
|
|
161
|
-
return ResponseType2;
|
|
162
|
-
}({});
|
|
163
|
-
|
|
164
|
-
// src/net/FetchClient.ts
|
|
165
|
-
function getApiRequestFunction(auth, url, userAgent, contextPath = "/api", fetchFunction) {
|
|
166
|
-
const fetchClient = new FetchClient(auth, url, userAgent, contextPath, fetchFunction);
|
|
167
|
-
return (method, endpointPath, data, queryArguments, headers, requestMediaType, responseMediaType) => fetchClient.request(method, endpointPath, data, queryArguments, headers, requestMediaType, responseMediaType);
|
|
168
|
-
}
|
|
169
|
-
var FetchClient = class {
|
|
170
|
-
constructor(auth, url, userAgent, contextPath = "/api", fetchFunction) {
|
|
171
|
-
this.userAgent = userAgent;
|
|
172
|
-
this.contextPath = contextPath;
|
|
173
|
-
const fetchFactory = new FetchFactory(fetchFunction);
|
|
174
|
-
this.fetchFunction = fetchFactory.getDefaultFetch(auth);
|
|
175
|
-
this.url = API_BASE_URL(url);
|
|
176
|
-
}
|
|
177
|
-
async request(method, endpointPath, data, queryArguments, headers, _requestMediaType = "application/json", responseMediaType = "application/json", responseAsStream) {
|
|
178
|
-
const url = new URL(`${this.contextPath}${endpointPath}`, `${this.url}`);
|
|
179
|
-
for (const [queryArgumentName, queryArgumentValue] of Object.entries(queryArguments || {})) {
|
|
180
|
-
if (queryArgumentValue) {
|
|
181
|
-
if (queryArgumentValue.constructor === Array) {
|
|
182
|
-
for (const value of queryArgumentValue) {
|
|
183
|
-
url.searchParams.append(queryArgumentName, value);
|
|
184
|
-
}
|
|
185
|
-
continue;
|
|
186
|
-
} else {
|
|
187
|
-
url.searchParams.append(queryArgumentName, queryArgumentValue);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
const headersInit = {};
|
|
192
|
-
Object.entries(headers || {}).forEach(([key, value]) => {
|
|
193
|
-
if (value != null) {
|
|
194
|
-
headersInit[key] = value.toString();
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
const response = await this.fetchWithContentType(url, {
|
|
198
|
-
method,
|
|
199
|
-
body: data,
|
|
200
|
-
headers: headersInit
|
|
201
|
-
});
|
|
202
|
-
if (responseAsStream && response.body) {
|
|
203
|
-
return response.body;
|
|
204
|
-
}
|
|
205
|
-
if (responseMediaType === MediaType.APPLICATION_JSON) {
|
|
206
|
-
return response.json();
|
|
207
|
-
} else if (responseMediaType === "*/*") {
|
|
208
|
-
return response.blob();
|
|
209
|
-
}
|
|
210
|
-
return response.json();
|
|
211
|
-
}
|
|
212
|
-
async callAPI(url, method = "GET", body, responseType = ResponseType.JSON) {
|
|
213
|
-
const response = await this.fetchWithContentType(url, {
|
|
214
|
-
method,
|
|
215
|
-
body
|
|
216
|
-
});
|
|
217
|
-
const contentType = response.headers.get("Content-Type") != null ? response.headers.get("Content-Type") : "";
|
|
218
|
-
let bodyPromise;
|
|
219
|
-
if (responseType === ResponseType.BLOB) {
|
|
220
|
-
bodyPromise = response.blob();
|
|
221
|
-
} else if (contentType.includes(MediaType.APPLICATION_JSON)) {
|
|
222
|
-
bodyPromise = response.json();
|
|
223
|
-
} else if (contentType.includes(MediaType.APPLICATION_OCTET_STREAM)) {
|
|
224
|
-
bodyPromise = response.blob();
|
|
225
|
-
} else {
|
|
226
|
-
bodyPromise = response.text();
|
|
227
|
-
}
|
|
228
|
-
const responseBody = await bodyPromise;
|
|
229
|
-
return responseBody;
|
|
230
|
-
}
|
|
231
|
-
async fetchWithContentType(url, init) {
|
|
232
|
-
if (!init?.body) {
|
|
233
|
-
return this.fetchFunction(url.toString(), {
|
|
234
|
-
...init,
|
|
235
|
-
headers: this.getHeaders(init?.headers)
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
const contentType = this.getContentTypeForBody(init.body);
|
|
239
|
-
return this.fetchFunction(url.toString(), {
|
|
240
|
-
...init,
|
|
241
|
-
headers: this.getHeaders(init?.headers, contentType),
|
|
242
|
-
body: this.getBodyForContentType(init.body)
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
getContentTypeForBody(body) {
|
|
246
|
-
if (globalThis.Blob && body instanceof globalThis.Blob) {
|
|
247
|
-
return body.type;
|
|
248
|
-
}
|
|
249
|
-
if (typeof body === "string") {
|
|
250
|
-
return MediaType.TEXT_PLAIN;
|
|
251
|
-
}
|
|
252
|
-
if (globalThis.ArrayBuffer && (globalThis.ArrayBuffer.isView(body) || body instanceof globalThis.ArrayBuffer)) {
|
|
253
|
-
return MediaType.APPLICATION_OCTET_STREAM;
|
|
254
|
-
}
|
|
255
|
-
if (globalThis.Uint8Array && body instanceof globalThis.Uint8Array) {
|
|
256
|
-
return MediaType.APPLICATION_OCTET_STREAM;
|
|
257
|
-
}
|
|
258
|
-
return MediaType.APPLICATION_JSON;
|
|
259
|
-
}
|
|
260
|
-
getBodyForContentType(body) {
|
|
261
|
-
if (!body) {
|
|
262
|
-
return void 0;
|
|
263
|
-
}
|
|
264
|
-
if (globalThis.Blob && body instanceof globalThis.Blob) {
|
|
265
|
-
return body;
|
|
266
|
-
}
|
|
267
|
-
return JSON.stringify(body);
|
|
268
|
-
}
|
|
269
|
-
getHeaders(init, contentType = MediaType.APPLICATION_JSON) {
|
|
270
|
-
return {
|
|
271
|
-
"Content-Type": contentType,
|
|
272
|
-
"Fetch-User-Agent": this.userAgent,
|
|
273
|
-
...init
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
|
|
278
46
|
// src/ontologyMetadata/Result.ts
|
|
279
47
|
var Ok = class {
|
|
280
48
|
constructor(value) {
|
|
@@ -353,10 +121,8 @@ var OntologyMetadataResolver = class {
|
|
|
353
121
|
this.stackName = stackName;
|
|
354
122
|
this.#authToken = authToken;
|
|
355
123
|
}
|
|
356
|
-
|
|
357
|
-
return
|
|
358
|
-
userToken: this.#authToken
|
|
359
|
-
}), this.stackName, `foundry-typescript-osdk-generator/${process.env.npm_package_version}`, "/api");
|
|
124
|
+
getClientContext() {
|
|
125
|
+
return shared_net.createClientContext(this.stackName, () => this.#authToken, `foundry-typescript-osdk-generator/${process.env.npm_package_version}`);
|
|
360
126
|
}
|
|
361
127
|
filterMetadata(ontologyFullMetadata, expectedEntities) {
|
|
362
128
|
const filteredObjectTypes = Object.fromEntries(Object.entries(ontologyFullMetadata.objectTypes).filter(([objectTypeApiName]) => expectedEntities.objectTypes.has(objectTypeApiName.toLowerCase())));
|
|
@@ -387,12 +153,18 @@ var OntologyMetadataResolver = class {
|
|
|
387
153
|
}
|
|
388
154
|
async getWireOntologyDefinition(ontologyRid, entities) {
|
|
389
155
|
let ontology;
|
|
156
|
+
const {
|
|
157
|
+
Ontologies
|
|
158
|
+
} = await import('@osdk/internal.foundry.ontologies');
|
|
159
|
+
const {
|
|
160
|
+
OntologiesV2
|
|
161
|
+
} = await import('@osdk/internal.foundry.ontologiesv2');
|
|
390
162
|
try {
|
|
391
|
-
ontology = await
|
|
163
|
+
ontology = await Ontologies.getOntology(this.getClientContext(), ontologyRid);
|
|
392
164
|
} catch (e) {
|
|
393
165
|
return Result.err([`Unable to load the specified Ontology with network error: ${JSON.stringify(e)}`]);
|
|
394
166
|
}
|
|
395
|
-
const ontologyFullMetadata = await
|
|
167
|
+
const ontologyFullMetadata = await OntologiesV2.getOntologyFullMetadata(this.getClientContext(), ontology.rid);
|
|
396
168
|
if (ontologyFullMetadata.errorName != null) {
|
|
397
169
|
return Result.err([`Unable to load the specified Ontology metadata.
|
|
398
170
|
${JSON.stringify(ontologyFullMetadata, null, 2)}`]);
|
|
@@ -584,7 +356,7 @@ function isValidSemver(semverString) {
|
|
|
584
356
|
}
|
|
585
357
|
|
|
586
358
|
// src/utils/UserAgent.ts
|
|
587
|
-
var USER_AGENT = `typescript-sdk-generator/${"
|
|
359
|
+
var USER_AGENT = `typescript-sdk-generator/${"2.0.0-beta.7"}`;
|
|
588
360
|
async function createRollupBuild(absolutePackagePath, packageName) {
|
|
589
361
|
const inputPath = `${absolutePackagePath}/${packageName}/index.js`;
|
|
590
362
|
const {
|
|
@@ -627,23 +399,6 @@ async function generateEsmBuild(absolutePackagePath, packageName) {
|
|
|
627
399
|
async function generateBundles(absolutePackagePath, packageName) {
|
|
628
400
|
await Promise.all([generateEsmBuild(absolutePackagePath, packageName)]);
|
|
629
401
|
}
|
|
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
402
|
function withoutTrailingIndex(filePath) {
|
|
648
403
|
return filePath.endsWith("/index") ? filePath.slice(0, -6) : filePath;
|
|
649
404
|
}
|
|
@@ -774,277 +529,6 @@ function transformModuleSpecifier(value, filePath) {
|
|
|
774
529
|
function withoutExtension(value) {
|
|
775
530
|
return value.replace(".js", "");
|
|
776
531
|
}
|
|
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
532
|
|
|
1049
533
|
// src/generate/betaClient/bundleDependencies.ts
|
|
1050
534
|
async function bundleDependencies(dirs, generatedPackageName, generatedFiles, entry) {
|
|
@@ -1056,11 +540,7 @@ async function bundleDependencies(dirs, generatedPackageName, generatedFiles, en
|
|
|
1056
540
|
outFile: "dist/bundle/index.d.ts"
|
|
1057
541
|
}
|
|
1058
542
|
});
|
|
1059
|
-
|
|
1060
|
-
if (entry) {
|
|
1061
|
-
const projectMinifier = new ProjectMinifier(project, importSet, entry);
|
|
1062
|
-
projectMinifier.minifyProject();
|
|
1063
|
-
}
|
|
543
|
+
await copyFiles(project, dirs, generatedPackageName, generatedFiles);
|
|
1064
544
|
return outputModule(project);
|
|
1065
545
|
}
|
|
1066
546
|
function outputModule(project) {
|
|
@@ -1157,9 +637,6 @@ async function generatePackageJson(options) {
|
|
|
1157
637
|
}
|
|
1158
638
|
|
|
1159
639
|
// 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
640
|
var betaDependencies = {
|
|
1164
641
|
"@osdk/client.api": typeof __OSDK_CLIENT_API_VERSION__ !== "undefined" ? __OSDK_CLIENT_API_VERSION__ : void 0,
|
|
1165
642
|
"@osdk/api": typeof __OSDK_API_VERSION__ !== "undefined" ? __OSDK_API_VERSION__ : void 0
|
|
@@ -1169,7 +646,7 @@ async function generatePackage(ontology, options) {
|
|
|
1169
646
|
consola
|
|
1170
647
|
} = await import('consola');
|
|
1171
648
|
const packagePath = path.join(options.outputDir, options.packageName);
|
|
1172
|
-
const resolvedDependencies = await Promise.all(Object.keys(
|
|
649
|
+
const resolvedDependencies = await Promise.all(Object.keys(betaDependencies).map(async (dependency) => {
|
|
1173
650
|
return {
|
|
1174
651
|
dependencyName: dependency,
|
|
1175
652
|
dependencyVersion: await getDependencyVersion(dependency)
|
|
@@ -1191,7 +668,7 @@ async function generatePackage(ontology, options) {
|
|
|
1191
668
|
readdir: (path2) => promises.readdir(path2)
|
|
1192
669
|
};
|
|
1193
670
|
if (!options.beta) {
|
|
1194
|
-
|
|
671
|
+
throw new Error("Only beta is supported in this version");
|
|
1195
672
|
} else {
|
|
1196
673
|
await generator.generateClientSdkVersionTwoPointZero(ontology, `typescript-sdk/${options.packageVersion} ${USER_AGENT}`, hostFs, packagePath, "module");
|
|
1197
674
|
}
|
|
@@ -1212,7 +689,7 @@ async function generatePackage(ontology, options) {
|
|
|
1212
689
|
let bundleDts = "";
|
|
1213
690
|
if (nodeModulesPath) {
|
|
1214
691
|
try {
|
|
1215
|
-
bundleDts = await bundleDependencies(
|
|
692
|
+
bundleDts = await bundleDependencies([], options.packageName, compilerOutput.files, void 0);
|
|
1216
693
|
} catch (e) {
|
|
1217
694
|
consola.error("Failed bundling DTS", e);
|
|
1218
695
|
}
|
|
@@ -1240,9 +717,6 @@ async function generatePackage(ontology, options) {
|
|
|
1240
717
|
}
|
|
1241
718
|
}
|
|
1242
719
|
async function getDependencyVersion(dependency) {
|
|
1243
|
-
if (dependencies[dependency] !== void 0) {
|
|
1244
|
-
return dependencies[dependency];
|
|
1245
|
-
}
|
|
1246
720
|
const {
|
|
1247
721
|
findUp
|
|
1248
722
|
} = await import('find-up');
|