@osdk/foundry-sdk-generator 2.1.0-beta.9 → 2.2.0-beta.1

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 (81) hide show
  1. package/CHANGELOG.md +290 -0
  2. package/build/esm/index.js +120 -61
  3. package/build/esm/index.js.map +1 -1
  4. package/build/types/cli/foundrySdkGeneratorCli.d.ts +1 -0
  5. package/build/types/cli/foundrySdkGeneratorCli.d.ts.map +1 -0
  6. package/build/types/generate/GeneratePackageCommand.d.ts +24 -0
  7. package/build/types/generate/GeneratePackageCommand.d.ts.map +1 -0
  8. package/build/types/generate/betaClient/__tests__/bundleDependencies.test.d.ts +1 -0
  9. package/build/types/generate/betaClient/__tests__/bundleDependencies.test.d.ts.map +1 -0
  10. package/build/{esm → types}/generate/betaClient/bundleDependencies.d.ts +1 -2
  11. package/build/types/generate/betaClient/bundleDependencies.d.ts.map +1 -0
  12. package/build/types/generate/betaClient/compileInMemory.d.ts +15 -0
  13. package/build/types/generate/betaClient/compileInMemory.d.ts.map +1 -0
  14. package/build/{esm → types}/generate/betaClient/copyFiles.d.ts +1 -2
  15. package/build/types/generate/betaClient/copyFiles.d.ts.map +1 -0
  16. package/build/{esm → types}/generate/betaClient/generatePackage.d.ts +4 -5
  17. package/build/types/generate/betaClient/generatePackage.d.ts.map +1 -0
  18. package/build/types/generate/betaClient/generatePackageJson.d.ts +24 -0
  19. package/build/types/generate/betaClient/generatePackageJson.d.ts.map +1 -0
  20. package/build/types/generate/betaClient/getModuleSourceFile.d.ts +3 -0
  21. package/build/types/generate/betaClient/getModuleSourceFile.d.ts.map +1 -0
  22. package/build/types/generate/betaClient/minifyBundle.d.ts +22 -0
  23. package/build/types/generate/betaClient/minifyBundle.d.ts.map +1 -0
  24. package/build/{esm → types}/generate/commandUtils.d.ts +0 -1
  25. package/build/types/generate/commandUtils.d.ts.map +1 -0
  26. package/build/{esm → types}/generate/generateBundles.d.ts +0 -1
  27. package/build/types/generate/generateBundles.d.ts.map +1 -0
  28. package/build/types/generate/index.d.ts +2 -0
  29. package/build/types/generate/index.d.ts.map +1 -0
  30. package/build/{esm → types}/index.d.ts +0 -1
  31. package/build/types/index.d.ts.map +1 -0
  32. package/build/types/ontologyMetadata/Result.d.ts +55 -0
  33. package/build/types/ontologyMetadata/Result.d.ts.map +1 -0
  34. package/build/{esm → types}/ontologyMetadata/index.d.ts +0 -1
  35. package/build/types/ontologyMetadata/index.d.ts.map +1 -0
  36. package/build/types/ontologyMetadata/metadataResolver.test.d.ts +1 -0
  37. package/build/types/ontologyMetadata/metadataResolver.test.d.ts.map +1 -0
  38. package/build/types/ontologyMetadata/ontologyMetadataResolver.d.ts +35 -0
  39. package/build/types/ontologyMetadata/ontologyMetadataResolver.d.ts.map +1 -0
  40. package/build/{esm → types}/utils/UserAgent.d.ts +0 -1
  41. package/build/types/utils/UserAgent.d.ts.map +1 -0
  42. package/build/types/utils/index.d.ts +1 -0
  43. package/build/types/utils/index.d.ts.map +1 -0
  44. package/build/{esm → types}/utils/semverUtils.d.ts +0 -1
  45. package/build/types/utils/semverUtils.d.ts.map +1 -0
  46. package/package.json +28 -28
  47. package/build/browser/index.js +0 -1049
  48. package/build/browser/index.js.map +0 -1
  49. package/build/esm/cli/foundrySdkGeneratorCli.d.ts +0 -6
  50. package/build/esm/cli/foundrySdkGeneratorCli.d.ts.map +0 -1
  51. package/build/esm/generate/GeneratePackageCommand.d.ts +0 -25
  52. package/build/esm/generate/GeneratePackageCommand.d.ts.map +0 -1
  53. package/build/esm/generate/betaClient/__tests__/bundleDependencies.test.d.ts +0 -2
  54. package/build/esm/generate/betaClient/__tests__/bundleDependencies.test.d.ts.map +0 -1
  55. package/build/esm/generate/betaClient/bundleDependencies.d.ts.map +0 -1
  56. package/build/esm/generate/betaClient/compileInMemory.d.ts +0 -18
  57. package/build/esm/generate/betaClient/compileInMemory.d.ts.map +0 -1
  58. package/build/esm/generate/betaClient/copyFiles.d.ts.map +0 -1
  59. package/build/esm/generate/betaClient/generatePackage.d.ts.map +0 -1
  60. package/build/esm/generate/betaClient/generatePackageJson.d.ts +0 -15
  61. package/build/esm/generate/betaClient/generatePackageJson.d.ts.map +0 -1
  62. package/build/esm/generate/betaClient/getModuleSourceFile.d.ts +0 -4
  63. package/build/esm/generate/betaClient/getModuleSourceFile.d.ts.map +0 -1
  64. package/build/esm/generate/betaClient/minifyBundle.d.ts +0 -23
  65. package/build/esm/generate/betaClient/minifyBundle.d.ts.map +0 -1
  66. package/build/esm/generate/commandUtils.d.ts.map +0 -1
  67. package/build/esm/generate/generateBundles.d.ts.map +0 -1
  68. package/build/esm/generate/index.d.ts +0 -3
  69. package/build/esm/generate/index.d.ts.map +0 -1
  70. package/build/esm/index.d.ts.map +0 -1
  71. package/build/esm/ontologyMetadata/Result.d.ts +0 -32
  72. package/build/esm/ontologyMetadata/Result.d.ts.map +0 -1
  73. package/build/esm/ontologyMetadata/index.d.ts.map +0 -1
  74. package/build/esm/ontologyMetadata/metadataResolver.test.d.ts +0 -2
  75. package/build/esm/ontologyMetadata/metadataResolver.test.d.ts.map +0 -1
  76. package/build/esm/ontologyMetadata/ontologyMetadataResolver.d.ts +0 -36
  77. package/build/esm/ontologyMetadata/ontologyMetadataResolver.d.ts.map +0 -1
  78. package/build/esm/utils/UserAgent.d.ts.map +0 -1
  79. package/build/esm/utils/index.d.ts +0 -2
  80. package/build/esm/utils/index.d.ts.map +0 -1
  81. package/build/esm/utils/semverUtils.d.ts.map +0 -1
@@ -1,1049 +0,0 @@
1
- import { fileURLToPath } from 'url';
2
- import * as path2 from 'path';
3
- import path2__default, { join, dirname, isAbsolute, normalize } from 'path';
4
- import yargs from 'yargs';
5
- import { hideBin } from 'yargs/helpers';
6
- import { exit } from 'process';
7
- import { createClientContext } from '@osdk/shared.net';
8
- import { generateClientSdkVersionTwoPointZero } from '@osdk/generator';
9
- import { mkdir, writeFile, readdir, readFile } from 'fs/promises';
10
- import commonjs from '@rollup/plugin-commonjs';
11
- import { nodeResolve } from '@rollup/plugin-node-resolve';
12
- import { rollup } from 'rollup';
13
- import nodePolyfill from 'rollup-plugin-polyfill-node';
14
- import { Project, Node } from 'ts-morph';
15
- import * as fs from 'fs';
16
- import { ModuleKind, ScriptTarget, createCompilerHost, createSourceFile, createProgram } from 'typescript';
17
-
18
- // ../../node_modules/.pnpm/tsup@8.2.3_@microsoft+api-extractor@7.47.0_@types+node@22.7.9__jiti@1.21.6_postcss@8.4.47_typescript@5.5.4_yaml@2.4.5/node_modules/tsup/assets/esm_shims.js
19
- var getFilename = () => fileURLToPath(import.meta.url);
20
- var getDirname = () => path2__default.dirname(getFilename());
21
- var __dirname = /* @__PURE__ */ getDirname();
22
-
23
- // ../../node_modules/.pnpm/conjure-lite@0.4.4/node_modules/conjure-lite/dist/index.mjs
24
- async function conjureFetch({
25
- fetchFn,
26
- baseUrl,
27
- servicePath,
28
- tokenProvider
29
- }, url, method, body, params, contentType, accept) {
30
- const queryParams = Object.entries({}).flatMap(([key, value]) => {
31
- if (value == null) {
32
- return [];
33
- }
34
- if (Array.isArray(value)) {
35
- return value.map((item) => [key, item]);
36
- }
37
- const stringValue = "" + value;
38
- return stringValue.length === 0 ? [] : [[key, stringValue]];
39
- });
40
- const query = Object.keys(queryParams).length === 0 ? "" : `?${new URLSearchParams(queryParams).toString()}`;
41
- const response = await (fetchFn ?? fetch)(`${baseUrl}${servicePath}${url}${query}`, {
42
- method,
43
- credentials: "same-origin",
44
- headers: {
45
- "Fetch-User-Agent": "conjure-lite",
46
- "Content-Type": "application/json",
47
- accept: "application/json",
48
- ...tokenProvider ? {
49
- "Authorization": `Bearer ${await tokenProvider()}`
50
- } : {}
51
- },
52
- ...{}
53
- });
54
- try {
55
- if (response.status === 204) {
56
- return void 0;
57
- }
58
- const body2 = await readBody(response);
59
- if (!response.ok) {
60
- throw new ConjureError("STATUS", void 0, response.status, body2);
61
- }
62
- return body2;
63
- } catch (error) {
64
- if (error instanceof ConjureError) {
65
- throw error;
66
- } else if (error instanceof TypeError) {
67
- throw new ConjureError("NETWORK", error);
68
- } else {
69
- throw new ConjureError("OTHER", error);
70
- }
71
- }
72
- }
73
- async function readBody(response) {
74
- const contentType = response.headers.get("Content-Type") != null ? response.headers.get("Content-Type") : "";
75
- try {
76
- if (contentType.includes("application/json")) {
77
- return await response.json();
78
- } else if (contentType.includes("application/octet-stream")) {
79
- return await response.blob();
80
- } else {
81
- return await response.text();
82
- }
83
- } catch (error) {
84
- throw new ConjureError("PARSE", error, response.status);
85
- }
86
- }
87
- var ConjureError = class {
88
- type;
89
- originalError;
90
- status;
91
- body;
92
- constructor(errorType, originalError, status, body) {
93
- this.type = errorType;
94
- this.originalError = originalError;
95
- this.status = status;
96
- this.body = body;
97
- }
98
- toString() {
99
- return JSON.stringify({
100
- body: this.body,
101
- originalError: this.originalError && this.originalError.toString(),
102
- status: this.status,
103
- type: this.type
104
- }, null, " ");
105
- }
106
- };
107
-
108
- // ../client.unstable.tpsa/build/esm/index.js
109
- async function getSdk(ctx, repositoryRid, packageName, sdkVersion) {
110
- return conjureFetch(ctx, `/sdks/${repositoryRid}/${packageName}/${sdkVersion}`, "GET");
111
- }
112
- async function getSdkPackage(ctx, sdkPackageRid) {
113
- return conjureFetch(ctx, `/sdks/packages/${sdkPackageRid}`, "GET");
114
- }
115
-
116
- // src/ontologyMetadata/Result.ts
117
- var Ok = class {
118
- constructor(value) {
119
- this.value = value;
120
- }
121
- isErr() {
122
- return false;
123
- }
124
- isOk() {
125
- return true;
126
- }
127
- transform(transformOk, _transformErr) {
128
- return transformOk(this.value);
129
- }
130
- map(transformOk) {
131
- return Result.ok(transformOk(this.value));
132
- }
133
- mapErr(_transformErr) {
134
- return Result.ok(this.value);
135
- }
136
- };
137
- var Err = class {
138
- constructor(error) {
139
- this.error = error;
140
- }
141
- isErr() {
142
- return true;
143
- }
144
- isOk() {
145
- return false;
146
- }
147
- transform(_transformOk, transformErr) {
148
- return transformErr(this.error);
149
- }
150
- map(_transformOk) {
151
- return Result.err(this.error);
152
- }
153
- mapErr(transformErr) {
154
- return Result.err(transformErr(this.error));
155
- }
156
- };
157
- var Result = {
158
- ok(ok) {
159
- return new Ok(ok);
160
- },
161
- err(err) {
162
- return new Err(err);
163
- },
164
- /**
165
- * Returns err E array if any result has an error.
166
- * Returns T array if all results are ok.
167
- */
168
- coalesce(results) {
169
- return results.reduce((acc, value) => {
170
- return value.transform((ok) => {
171
- return acc.transform((accOk) => {
172
- return Result.ok([...accOk, ok]);
173
- }, (accErr) => {
174
- return Result.err(accErr);
175
- });
176
- }, (err) => {
177
- return acc.transform(() => {
178
- return Result.err([...err]);
179
- }, (accErr) => {
180
- return Result.err([...accErr, ...err]);
181
- });
182
- });
183
- }, Result.ok([]));
184
- }
185
- };
186
-
187
- // src/ontologyMetadata/ontologyMetadataResolver.ts
188
- var OntologyMetadataResolver = class {
189
- #authToken;
190
- constructor(authToken, stackName) {
191
- this.stackName = stackName;
192
- this.#authToken = authToken;
193
- }
194
- getClientContext() {
195
- return createClientContext(this.stackName.match(/^https?:\/\//) ? this.stackName : `https://${this.stackName}`, () => this.#authToken, `foundry-typescript-osdk-generator/${process.env.npm_package_version}`);
196
- }
197
- filterMetadataByApiName(ontologyFullMetadata, expectedEntities, pkgInfo) {
198
- const filteredObjectTypes = Object.fromEntries(Object.entries(ontologyFullMetadata.objectTypes).filter(([, {
199
- objectType
200
- }]) => {
201
- for (const {
202
- sdk: {
203
- inputs: {
204
- dataScope
205
- }
206
- }
207
- } of pkgInfo.values()) {
208
- for (const objectTypeRid of dataScope.ontologyV2.objectTypes) {
209
- if (objectTypeRid === objectType.rid) {
210
- return true;
211
- }
212
- }
213
- }
214
- return expectedEntities.objectTypes.has(objectType.apiName);
215
- }));
216
- const filteredInterfaceTypes = Object.fromEntries(Object.entries(ontologyFullMetadata.interfaceTypes).filter(([interfaceApiName]) => expectedEntities.interfaceTypes.has(interfaceApiName)));
217
- Object.values(filteredObjectTypes).forEach((objectType) => {
218
- const linkTypesToKeep = expectedEntities.linkTypes.get(objectType.objectType.apiName);
219
- if (!linkTypesToKeep) {
220
- objectType.linkTypes = [];
221
- return;
222
- }
223
- objectType.linkTypes = objectType.linkTypes.filter((linkType) => linkTypesToKeep.has(linkType.apiName));
224
- });
225
- const filteredActionTypes = Object.fromEntries(Object.entries(ontologyFullMetadata.actionTypes).filter(([actionApiName]) => {
226
- if (expectedEntities.actionTypes.has(this.camelize(actionApiName))) {
227
- return true;
228
- }
229
- return false;
230
- }));
231
- const filteredQueryTypes = Object.fromEntries(Object.entries(ontologyFullMetadata.queryTypes).filter(([queryApiName]) => expectedEntities.queryTypes.has(queryApiName)));
232
- return {
233
- ontology: ontologyFullMetadata.ontology,
234
- objectTypes: filteredObjectTypes,
235
- actionTypes: filteredActionTypes,
236
- queryTypes: filteredQueryTypes,
237
- interfaceTypes: filteredInterfaceTypes,
238
- sharedPropertyTypes: {}
239
- };
240
- }
241
- async getInfoForPackages(pkgs) {
242
- const conjureCtx = {
243
- baseUrl: `https://${this.stackName}`,
244
- servicePath: "/third-party-application-service/api",
245
- tokenProvider: () => Promise.resolve(this.#authToken)
246
- };
247
- const ret = /* @__PURE__ */ new Map();
248
- for (const [packageRid, packageVersion] of pkgs) {
249
- const sdkPackage = await getSdkPackage(conjureCtx, packageRid);
250
- const sdk = await getSdk(conjureCtx, sdkPackage.repositoryRid, sdkPackage.packageName, packageVersion);
251
- ret.set(packageRid, {
252
- sdkPackage,
253
- sdk,
254
- packageVersion
255
- });
256
- }
257
- return ret;
258
- }
259
- async getWireOntologyDefinition(ontologyRid, entities, extPackageInfo = /* @__PURE__ */ new Map()) {
260
- let ontology;
261
- const {
262
- Ontologies
263
- } = await import('@osdk/internal.foundry.ontologies');
264
- const {
265
- OntologiesV2
266
- } = await import('@osdk/internal.foundry.ontologiesv2');
267
- try {
268
- ontology = await Ontologies.get(this.getClientContext(), ontologyRid);
269
- } catch (e) {
270
- return Result.err([`Unable to load the specified Ontology with network error: ${JSON.stringify(e)}`]);
271
- }
272
- const ontologyFullMetadata = await OntologiesV2.getFullMetadata(this.getClientContext(), ontology.rid);
273
- if (ontologyFullMetadata.errorName != null) {
274
- return Result.err([`Unable to load the specified Ontology metadata.
275
- ${JSON.stringify(ontologyFullMetadata, null, 2)}`]);
276
- }
277
- const externalObjects = /* @__PURE__ */ new Map();
278
- const externalInterfaces = /* @__PURE__ */ new Map();
279
- for (const {
280
- sdk
281
- } of extPackageInfo.values()) {
282
- if (sdk.npm?.npmPackageName == null) {
283
- throw new Error("External package is not generated as an npm package");
284
- }
285
- const dataScope = sdk.inputs.dataScope.ontologyV2;
286
- for (const rid of dataScope.objectTypes) {
287
- const ot = Object.values(ontologyFullMetadata.objectTypes).find((ot2) => ot2.objectType.rid === rid);
288
- if (!ot) {
289
- throw new Error(`Could not find external object type with rid ${rid}`);
290
- }
291
- externalObjects.set(ot.objectType.apiName, sdk.npm.npmPackageName);
292
- }
293
- for (const rid of dataScope.interfaceTypes) {
294
- const it = Object.values(ontologyFullMetadata.interfaceTypes).find((it2) => it2.rid === rid);
295
- if (!it) {
296
- throw new Error(`Could not find external interface type with rid ${rid}`);
297
- }
298
- externalInterfaces.set(it.apiName, sdk.npm.npmPackageName);
299
- }
300
- }
301
- const linkTypes = /* @__PURE__ */ new Map();
302
- const objectTypes = new Set(entities.objectTypesApiNamesToLoad);
303
- const queryTypes = new Set(entities.queryTypesApiNamesToLoad);
304
- const actionTypes = new Set(entities.actionTypesApiNamesToLoad?.map((action) => this.camelize(action)));
305
- const interfaceTypes = new Set(entities.interfaceTypesApiNamesToLoad);
306
- for (const linkType of entities.linkTypesApiNamesToLoad ?? []) {
307
- const [objectTypeApiName, linkTypeApiName] = linkType.split(".");
308
- if (!linkTypes.has(objectTypeApiName)) {
309
- linkTypes.set(objectTypeApiName, /* @__PURE__ */ new Set());
310
- }
311
- linkTypes.get(objectTypeApiName)?.add(linkTypeApiName);
312
- }
313
- const filteredFullMetadata = this.filterMetadataByApiName(ontologyFullMetadata, {
314
- objectTypes,
315
- linkTypes,
316
- actionTypes,
317
- queryTypes,
318
- interfaceTypes
319
- }, extPackageInfo);
320
- const validData = this.validateLoadedOntologyMetadata(filteredFullMetadata, {
321
- objectTypes,
322
- linkTypes,
323
- actionTypes,
324
- queryTypes
325
- }, ontologyFullMetadata, extPackageInfo);
326
- if (validData.isErr()) {
327
- return Result.err(validData.error);
328
- }
329
- return Result.ok({
330
- filteredFullMetadata,
331
- externalInterfaces,
332
- externalObjects
333
- });
334
- }
335
- validateLoadedOntologyMetadata(filteredFullMetadata, expectedEntities, fullOntology, packageInfo) {
336
- const errors = [];
337
- const loadedObjectTypes = Object.fromEntries(Object.values(filteredFullMetadata.objectTypes).map((object) => [object.objectType.apiName, object]));
338
- const loadedLinkTypes = Object.fromEntries(Object.values(filteredFullMetadata.objectTypes).map((object) => [object.objectType.apiName, Object.fromEntries(object.linkTypes.map((link) => [link.apiName, link]))]));
339
- const missingObjectTypes = [];
340
- for (const object of expectedEntities.objectTypes) {
341
- if (!loadedObjectTypes[object]) {
342
- missingObjectTypes.push(object);
343
- continue;
344
- }
345
- for (const expectedLink of expectedEntities.linkTypes.get(object) ?? []) {
346
- if (!loadedLinkTypes[object][expectedLink]) {
347
- errors.push(`Unable to find link type ${expectedLink} for Object Type ${object}`);
348
- }
349
- }
350
- for (const [, link] of Object.entries(loadedLinkTypes[object])) {
351
- if (!expectedEntities.objectTypes.has(link.objectTypeApiName)) {
352
- const fromFull = fullOntology.objectTypes[link.objectTypeApiName];
353
- if (fromFull && hasObjectType(packageInfo, fromFull)) {
354
- continue;
355
- }
356
- errors.push(`Unable to load link type ${link.apiName} for ${loadedObjectTypes[object].objectType.apiName}, because the target object type ${link.objectTypeApiName} is not loaded. Please specify the target Object type with --objectTypes ${link.objectTypeApiName}`);
357
- }
358
- }
359
- }
360
- if (missingObjectTypes.length > 0) {
361
- errors.push(`Unable to find the following Object Types: ${missingObjectTypes.join(", ")}`);
362
- }
363
- const loadedQueryTypes = Object.fromEntries(Object.entries(filteredFullMetadata.queryTypes).map(([queryApiName, query]) => [queryApiName, query]));
364
- const missingQueryTypes = [];
365
- for (const queryApiName of expectedEntities.queryTypes) {
366
- if (!loadedQueryTypes[queryApiName]) {
367
- missingQueryTypes.push(queryApiName);
368
- }
369
- }
370
- for (const query of Object.values(loadedQueryTypes)) {
371
- const result = this.validateQueryParametersAndOutput(query, expectedEntities.objectTypes);
372
- if (result.isErr()) {
373
- for (const errorString of result.error) {
374
- errors.push(errorString);
375
- }
376
- }
377
- }
378
- if (missingQueryTypes.length > 0) {
379
- errors.push(`Unable to find the following Query Types: ${missingQueryTypes.join()}`);
380
- }
381
- const loadedActionTypes = Object.fromEntries(Object.entries(filteredFullMetadata.actionTypes).map(([actionApiName, action]) => [this.camelize(actionApiName), action]));
382
- const missingActionTypes = [];
383
- for (const actionApiName of expectedEntities.actionTypes) {
384
- if (!loadedActionTypes[actionApiName]) {
385
- missingActionTypes.push(actionApiName);
386
- }
387
- }
388
- for (const action of Object.values(loadedActionTypes)) {
389
- const result = this.validateActionParameters(action, expectedEntities.objectTypes);
390
- if (result.isErr()) {
391
- for (const errorString of result.error) {
392
- errors.push(errorString);
393
- }
394
- }
395
- }
396
- if (missingActionTypes.length > 0) {
397
- errors.push(`Unable to find the following Action Types: ${missingActionTypes.join()}`);
398
- }
399
- if (errors.length > 0) {
400
- return Result.err(errors);
401
- }
402
- return Result.ok({});
403
- }
404
- validateQueryParametersAndOutput(query, loadedObjectApiNames) {
405
- const parameterValidation = Object.entries(query.parameters).map(([paramName, paramData]) => this.visitSupportedQueryTypes(query.apiName, paramName, paramData.dataType, loadedObjectApiNames));
406
- parameterValidation.push(this.visitSupportedQueryTypes(query.apiName, "output", query.output, loadedObjectApiNames));
407
- const results = Result.coalesce(parameterValidation);
408
- return results;
409
- }
410
- validateActionParameters(actionType, loadedObjectApiNames) {
411
- const camelizedApiName = this.camelize(actionType.apiName);
412
- const parameterValidation = Object.entries(actionType.parameters).map(([_paramName, paramData]) => this.isSupportedActionTypeParameter(camelizedApiName, paramData.dataType, loadedObjectApiNames));
413
- return Result.coalesce(parameterValidation);
414
- }
415
- visitSupportedQueryTypes(queryApiName, propertyName, baseType, loadedObjectApiNames) {
416
- switch (baseType.type) {
417
- case "array":
418
- case "set":
419
- return this.visitSupportedQueryTypes(queryApiName, propertyName, baseType.subType, loadedObjectApiNames);
420
- case "objectSet":
421
- case "object":
422
- if (loadedObjectApiNames.has(baseType.objectTypeApiName)) {
423
- return Result.ok({});
424
- }
425
- return Result.err([`Unable to load query ${queryApiName} because it takes an unloaded object type as a parameter: ${baseType.objectTypeApiName} in parameter ${propertyName}. Make sure to specify it as an argument with --ontologyObjects ${baseType.objectTypeApiName}.}`]);
426
- case "struct":
427
- const results = baseType.fields?.map((field) => {
428
- return this.visitSupportedQueryTypes(queryApiName, propertyName, field.fieldType, loadedObjectApiNames);
429
- });
430
- if (!results) {
431
- return Result.ok({});
432
- }
433
- return Result.coalesce(results);
434
- case "union":
435
- if (baseType.unionTypes.find((unionTypes) => unionTypes.type === "null")) {
436
- return Result.ok({});
437
- }
438
- return Result.err([`Unable to load query ${queryApiName} because it takes an unsupported parameter type: ${JSON.stringify(baseType)} in parameter ${propertyName}`]);
439
- case "string":
440
- case "boolean":
441
- case "attachment":
442
- case "date":
443
- case "double":
444
- case "float":
445
- case "integer":
446
- case "long":
447
- case "threeDimensionalAggregation":
448
- case "timestamp":
449
- case "twoDimensionalAggregation":
450
- case "null":
451
- return Result.ok({});
452
- case "unsupported":
453
- default:
454
- return Result.err([`Unable to load query ${queryApiName} because it takes an unsupported parameter type: ${JSON.stringify(baseType)} in parameter ${propertyName}`]);
455
- }
456
- }
457
- isSupportedActionTypeParameter(actionApiName, actonTypeParameter, loadedObjectApiNames) {
458
- switch (actonTypeParameter.type) {
459
- case "array":
460
- return this.isSupportedActionTypeParameter(actionApiName, actonTypeParameter.subType, loadedObjectApiNames);
461
- case "object":
462
- if (loadedObjectApiNames.has(actonTypeParameter.objectTypeApiName)) {
463
- return Result.ok({});
464
- }
465
- return Result.err([`Unable to load action ${actionApiName} because it takes an unloaded object type as a parameter: ${actonTypeParameter.objectTypeApiName} make sure to specify it as an argument with --ontologyObjects ${actonTypeParameter.objectTypeApiName})`]);
466
- case "objectSet":
467
- if (loadedObjectApiNames.has(actonTypeParameter.objectTypeApiName)) {
468
- return Result.ok({});
469
- }
470
- return Result.err([`Unable to load action ${actionApiName} because it takes an ObjectSet of unloaded object type as a parameter: ${actonTypeParameter.objectTypeApiName} make sure to specify it as an argument with --ontologyObjects ${actonTypeParameter.objectTypeApiName})`]);
471
- case "string":
472
- case "boolean":
473
- case "attachment":
474
- case "date":
475
- case "double":
476
- case "integer":
477
- case "long":
478
- case "timestamp":
479
- return Result.ok({});
480
- default:
481
- return Result.err([`Unable to load action ${actionApiName} because it takes an unsupported parameter: ${JSON.stringify(actonTypeParameter)} specify only the actions you want to load with the --actions argument.`]);
482
- }
483
- }
484
- camelize(name) {
485
- return name.replace(/-./g, (segment) => segment[1].toUpperCase());
486
- }
487
- };
488
- function hasObjectType(z, fromFull) {
489
- for (const q of z.values()) {
490
- const {
491
- objectTypes
492
- } = q.sdk.inputs.dataScope.ontologyV2;
493
- if (objectTypes.includes(fromFull.objectType.rid)) {
494
- return true;
495
- }
496
- }
497
- return false;
498
- }
499
-
500
- // src/utils/semverUtils.ts
501
- var semver = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
502
- function isValidSemver(semverString) {
503
- return semver.test(semverString);
504
- }
505
-
506
- // ../generator-utils/build/esm/changeVersionPrefix.js
507
- function changeVersionPrefix(version, prefix2) {
508
- const isWorkspaceProtocol = version.startsWith("workspace:");
509
- if (isWorkspaceProtocol) {
510
- version = version.slice("workspace:".length);
511
- }
512
- if (version[0] === "^" || version[0] === "~" || version[0] === "*") {
513
- version = version.slice(1);
514
- }
515
- return `${isWorkspaceProtocol ? "workspace:" : ""}${prefix2}${version}`;
516
- }
517
-
518
- // ../../node_modules/.pnpm/tiny-invariant@1.3.3/node_modules/tiny-invariant/dist/esm/tiny-invariant.js
519
- var isProduction = process.env.NODE_ENV === "production";
520
- var prefix = "Invariant failed";
521
- function invariant(condition, message) {
522
- if (isProduction) {
523
- throw new Error(prefix);
524
- }
525
- var provided = typeof message === "function" ? message() : message;
526
- var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
527
- throw new Error(value);
528
- }
529
-
530
- // ../generator-utils/build/esm/getDependencyVersionFromFindUpPackageJson.js
531
- async function getDependencyVersionFromFindUpPackageJson(name, opts) {
532
- const {
533
- findUp
534
- } = await import('find-up');
535
- const packageJsonPath = await findUp("package.json", opts);
536
- !(packageJsonPath !== void 0) ? process.env.NODE_ENV !== "production" ? process.env.NODE_ENV !== "production" ? invariant(false, "Could not find package.json") : invariant() : process.env.NODE_ENV !== "production" ? invariant() : invariant() : void 0;
537
- const packageJson = await readFile(packageJsonPath, {
538
- encoding: "utf-8"
539
- });
540
- if (!packageJson) {
541
- throw new Error(`Could not find package.json in current working directory: ${process.cwd()}`);
542
- }
543
- const parsedPackageJson = JSON.parse(packageJson);
544
- const version = parsedPackageJson.dependencies?.[name] ?? parsedPackageJson.devDependencies?.[name] ?? parsedPackageJson.peerDependencies?.[name];
545
- !(version !== void 0) ? process.env.NODE_ENV !== "production" ? process.env.NODE_ENV !== "production" ? invariant(false, `Could not find a dependency for ${name} in ${packageJsonPath}`) : invariant() : process.env.NODE_ENV !== "production" ? invariant() : invariant() : void 0;
546
- return version;
547
- }
548
-
549
- // ../generator-utils/build/esm/resolveDependenciesFromFindUp.js
550
- async function resolveDependenciesFromFindUp(deps, cwd) {
551
- return await Promise.all(Object.entries(deps).map(async ([dependencyName, dependencyVersion]) => {
552
- return {
553
- dependencyName,
554
- dependencyVersion: changeVersionPrefix(dependencyVersion ?? await getDependencyVersionFromFindUpPackageJson(dependencyName, {
555
- cwd
556
- }), "^")
557
- };
558
- }));
559
- }
560
-
561
- // src/utils/UserAgent.ts
562
- var USER_AGENT = `typescript-sdk-generator/${"2.1.0-beta.9"}`;
563
- async function createRollupBuild(absolutePackagePath, packageName) {
564
- const inputPath = `${absolutePackagePath}/${packageName}/index.js`;
565
- const {
566
- findUp
567
- } = await import('find-up');
568
- const nodeModulesPath = await findUp("node_modules", {
569
- cwd: __dirname,
570
- type: "directory"
571
- });
572
- return rollup({
573
- input: inputPath,
574
- plugins: [nodeResolve({
575
- browser: true,
576
- modulePaths: [nodeModulesPath]
577
- }), ("default" in commonjs ? commonjs.default : commonjs)({}), ("default" in nodePolyfill ? nodePolyfill.default : nodePolyfill)()],
578
- onwarn: (warning, warn) => {
579
- if (warning.code === "CIRCULAR_DEPENDENCY") {
580
- return;
581
- }
582
- warn(warning);
583
- }
584
- });
585
- }
586
- async function writeRollupBuild(rollupBuild, absolutePackagePath, packageName, format) {
587
- const outputPath = `${absolutePackagePath}/${packageName}/dist/bundle/index.${format}.js`;
588
- await Promise.all([rollupBuild.write({
589
- file: outputPath,
590
- format,
591
- name: packageName,
592
- amd: {
593
- id: packageName
594
- },
595
- plugins: []
596
- })]);
597
- }
598
- async function generateEsmBuild(absolutePackagePath, packageName) {
599
- const umdBuild = await createRollupBuild(absolutePackagePath, packageName);
600
- await writeRollupBuild(umdBuild, absolutePackagePath, packageName, "esm");
601
- }
602
- async function generateBundles(absolutePackagePath, packageName) {
603
- await Promise.all([generateEsmBuild(absolutePackagePath, packageName)]);
604
- }
605
- function withoutTrailingIndex(filePath) {
606
- return filePath.endsWith("/index") ? filePath.slice(0, -6) : filePath;
607
- }
608
-
609
- // src/generate/betaClient/copyFiles.ts
610
- var KNOWN_EXTERNAL = /* @__PURE__ */ new Set(["geojson"]);
611
- function removeDts(file) {
612
- return file.replace(/\.d\.c?ts$/, "");
613
- }
614
- async function copyFiles(project, dirs, generatedPackageName, generatedFiles) {
615
- const importSet = /* @__PURE__ */ new Set();
616
- for (const [fileName, file] of Object.entries(generatedFiles)) {
617
- if (!fileName.endsWith(".d.ts") && !fileName.endsWith(".d.cts")) {
618
- continue;
619
- }
620
- const indexOfPackageName = fileName.indexOf(generatedPackageName);
621
- const tsPath = removeDts(fileName.slice(indexOfPackageName + generatedPackageName.length));
622
- const newModulePath = `${generatedPackageName}${tsPath}`;
623
- const sourceFile = project.createSourceFile(newModulePath, file);
624
- for (const importDeclaration of sourceFile.getImportDeclarations()) {
625
- const moduleSpecifier = importDeclaration.getModuleSpecifier();
626
- const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier.getLiteralValue(), newModulePath);
627
- moduleSpecifier.setLiteralValue(newModuleSpecifier);
628
- if (newModuleSpecifier.startsWith("internal")) {
629
- for (const importName of importDeclaration.getNamedImports().map((imp) => imp.getName())) {
630
- importSet.add(importName);
631
- }
632
- }
633
- }
634
- for (const exportedDecl of sourceFile.getStatements()) {
635
- if (Node.isModifierable(exportedDecl)) {
636
- exportedDecl.toggleModifier("declare", false);
637
- }
638
- }
639
- for (const exportDeclaration of sourceFile.getExportDeclarations()) {
640
- const moduleSpecifier = exportDeclaration.getModuleSpecifier();
641
- if (moduleSpecifier) {
642
- const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier.getLiteralValue(), newModulePath);
643
- moduleSpecifier.setLiteralValue(newModuleSpecifier);
644
- if (newModuleSpecifier.startsWith("internal")) {
645
- for (const exportName of exportDeclaration.getNamedExports().map((exp) => exp.getName())) {
646
- importSet.add(exportName);
647
- }
648
- }
649
- }
650
- }
651
- }
652
- for (const dir of dirs) {
653
- const buildDirsToTry = ["build/cjs", "build/esm"];
654
- const packageName = getPackageName(dir);
655
- const relativeBuildDir = buildDirsToTry.find((buildDir) => {
656
- return ["d.ts", "d.cts", "d.mts"].some((ext) => {
657
- try {
658
- fs.statSync(path2.join(dir, buildDir, `index.${ext}`));
659
- return true;
660
- } catch (e) {
661
- return false;
662
- }
663
- });
664
- });
665
- if (!relativeBuildDir) {
666
- throw new Error("Couldn't find the right build dir");
667
- }
668
- for (const file of getTypeFiles(path2.join(dir, relativeBuildDir))) {
669
- const absoluteBuildDir = path2.join(dir, relativeBuildDir);
670
- const tsPath = removeDts(path2.relative(absoluteBuildDir, file));
671
- const newModulePath = `internal/${packageName}/${tsPath}`;
672
- const fileContents = fs.readFileSync(file).toString();
673
- const sourceFile = project.createSourceFile(`${newModulePath}.ts`, fileContents, {
674
- overwrite: true
675
- });
676
- for (const importDeclaration of sourceFile.getImportDeclarations()) {
677
- const moduleSpecifier = importDeclaration.getModuleSpecifier();
678
- const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier.getLiteralValue(), newModulePath);
679
- moduleSpecifier.setLiteralValue(newModuleSpecifier);
680
- }
681
- for (const exportedDecl of sourceFile.getStatements()) {
682
- if (Node.isModifierable(exportedDecl)) {
683
- exportedDecl.toggleModifier("declare", false);
684
- }
685
- }
686
- for (const exportDeclaration of sourceFile.getExportDeclarations()) {
687
- const moduleSpecifier = exportDeclaration.getModuleSpecifier();
688
- if (moduleSpecifier) {
689
- const newModuleSpecifier = transformModuleSpecifier(moduleSpecifier.getLiteralValue(), newModulePath);
690
- moduleSpecifier.setLiteralValue(withoutTrailingIndex(newModuleSpecifier));
691
- }
692
- }
693
- }
694
- }
695
- return importSet;
696
- }
697
- function getPackageName(dir) {
698
- const pkg = fs.readFileSync(path2.join(dir, "package.json"));
699
- const parsed = JSON.parse(pkg.toString());
700
- return parsed.name;
701
- }
702
- function* getTypeFiles(dir) {
703
- for (const item of fs.readdirSync(dir)) {
704
- const target = path2.join(dir, item);
705
- if (target.endsWith(".d.ts") && !target.endsWith(".test.d.ts") || target.endsWith(".d.cts") && !target.endsWith(".test.d.cts")) {
706
- yield target;
707
- } else {
708
- const stat = fs.lstatSync(target);
709
- if (stat.isDirectory() && item !== "test") {
710
- yield* getTypeFiles(target);
711
- }
712
- }
713
- }
714
- }
715
- function transformModuleSpecifier(value, filePath) {
716
- let moduleSpecifier;
717
- if (value.startsWith("@osdk")) {
718
- if (value.startsWith("@osdk/gateway/types")) {
719
- moduleSpecifier = `internal/${value.replace("@osdk/gateway/types", "@osdk/gateway/public/types")}`;
720
- } else {
721
- moduleSpecifier = `internal/${value}`;
722
- }
723
- } else if (value.startsWith(".")) {
724
- moduleSpecifier = path2.join(filePath, "..", value);
725
- } else if (KNOWN_EXTERNAL.has(value)) {
726
- moduleSpecifier = `internal/${value}`;
727
- } else {
728
- throw new Error("Failed generated DTS for package, no handling for: " + value);
729
- }
730
- return withoutTrailingIndex(withoutExtension(moduleSpecifier));
731
- }
732
- function withoutExtension(value) {
733
- return value.replace(".js", "");
734
- }
735
-
736
- // src/generate/betaClient/bundleDependencies.ts
737
- async function bundleDependencies(dirs, generatedPackageName, generatedFiles, entry) {
738
- const project = new Project({
739
- useInMemoryFileSystem: true,
740
- compilerOptions: {
741
- declaration: true,
742
- emitDeclarationOnly: true,
743
- outFile: "dist/bundle/index.d.ts"
744
- }
745
- });
746
- await copyFiles(project, dirs, generatedPackageName, generatedFiles);
747
- return outputModule(project);
748
- }
749
- function outputModule(project) {
750
- const modules = [];
751
- project.getSourceFiles().forEach((sourceFile) => {
752
- const lines = sourceFile.getText().split("\n");
753
- while (lines.length > 0 && lines[lines.length - 1] === "") {
754
- lines.pop();
755
- }
756
- if (lines.length === 0) {
757
- return;
758
- }
759
- const module = [];
760
- module.push(`/** ${sourceFile.getFilePath()} **/`);
761
- module.push(`declare module "${withoutTrailingIndex(sourceFile.getFilePath().replace(".ts", "").replace("/", ""))}" {`);
762
- for (const line of lines) {
763
- const trimmed = line.trim();
764
- if (trimmed.length === 0) {
765
- continue;
766
- }
767
- module.push(` ${line}`);
768
- }
769
- module.push(`}`);
770
- modules.push(module.join("\n"));
771
- });
772
- return modules.join("\n");
773
- }
774
- function compileInMemory(files, opts) {
775
- const inMemoryOutputFileSystem = {};
776
- const compilerOptions = {
777
- module: opts?.esm ? ModuleKind.NodeNext : ModuleKind.CommonJS,
778
- target: ScriptTarget.ES2019,
779
- declaration: true,
780
- skipLibCheck: true
781
- };
782
- const compilerHost = createCompilerHost(compilerOptions);
783
- compilerHost.writeFile = (fileName, data) => {
784
- inMemoryOutputFileSystem[fileName] = data;
785
- };
786
- const originalSourceFile = compilerHost.getSourceFile;
787
- compilerHost.getSourceFile = (fileName, languageVersion) => {
788
- const sourceText = files[fileName];
789
- return sourceText !== void 0 ? createSourceFile(fileName, sourceText, languageVersion) : originalSourceFile(fileName, languageVersion);
790
- };
791
- const program = createProgram(Object.keys(files), compilerOptions, compilerHost);
792
- const emitOutput = program.emit();
793
- return {
794
- files: inMemoryOutputFileSystem,
795
- diagnostics: emitOutput.diagnostics
796
- };
797
- }
798
- async function generatePackageJson(options) {
799
- const packageDeps = constructDependencies(options.dependencies);
800
- const packagePeerDeps = constructDependencies(options.peerDependencies);
801
- const packageJson = {
802
- name: options.packageName,
803
- version: options.packageVersion,
804
- main: "./index.js",
805
- types: "./index.d.ts",
806
- exports: {
807
- ".": {
808
- types: "./index.d.ts",
809
- script: {
810
- types: "./dist/bundle/index.d.ts",
811
- default: "./dist/bundle/index.esm.js"
812
- },
813
- default: "./index.js"
814
- }
815
- },
816
- dependencies: packageDeps,
817
- peerDependencies: packagePeerDeps,
818
- type: "module"
819
- };
820
- await writeFile(join(options.packagePath, "package.json"), JSON.stringify(packageJson, void 0, 4));
821
- }
822
- function constructDependencies(dependencies) {
823
- return dependencies?.reduce((acc, value) => {
824
- acc[value.dependencyName] = value.dependencyVersion;
825
- return acc;
826
- }, {});
827
- }
828
-
829
- // src/generate/betaClient/generatePackage.ts
830
- var betaPeerDependencies = {
831
- "@osdk/client": void 0
832
- };
833
- async function generatePackage(ontologyInfo, options) {
834
- const {
835
- consola
836
- } = await import('consola');
837
- const packagePath = join(options.outputDir, options.packageName);
838
- const resolvedPeerDependencies = await resolveDependenciesFromFindUp(betaPeerDependencies, dirname(fileURLToPath(import.meta.url)));
839
- await mkdir(packagePath, {
840
- recursive: true
841
- });
842
- const inMemoryFileSystem = {};
843
- const hostFs = {
844
- writeFile: async (path3, contents) => {
845
- inMemoryFileSystem[normalize(path3)] = contents;
846
- },
847
- mkdir: async (path3, _options) => {
848
- await mkdir(normalize(path3), {
849
- recursive: true
850
- });
851
- },
852
- readdir: (path3) => readdir(path3)
853
- };
854
- await generateClientSdkVersionTwoPointZero(ontologyInfo.filteredFullMetadata, `typescript-sdk/${options.packageVersion} ${USER_AGENT}`, hostFs, packagePath, "module", ontologyInfo.externalObjects, ontologyInfo.externalInterfaces);
855
- const compilerOutput = compileInMemory(inMemoryFileSystem, {
856
- esm: options.beta
857
- });
858
- compilerOutput.diagnostics.forEach((d) => consola.error(`Error compiling file`, d.file?.fileName, d.messageText));
859
- await mkdir(join(packagePath, "dist", "bundle"), {
860
- recursive: true
861
- });
862
- const {
863
- findUp
864
- } = await import('find-up');
865
- const nodeModulesPath = await findUp("node_modules", {
866
- cwd: dirname(fileURLToPath(import.meta.url)),
867
- type: "directory"
868
- });
869
- let bundleDts = "";
870
- if (nodeModulesPath) {
871
- try {
872
- bundleDts = await bundleDependencies([], options.packageName, compilerOutput.files, void 0);
873
- } catch (e) {
874
- consola.error("Failed bundling DTS", e);
875
- }
876
- } else {
877
- consola.error("Could not find node_modules directory, skipping DTS bundling");
878
- }
879
- await Promise.all([...Object.entries(compilerOutput.files).map(async ([path3, contents]) => {
880
- await writeFile(path3, contents, {
881
- flag: "w"
882
- });
883
- }), await writeFile(join(packagePath, "dist", "bundle", "index.d.ts"), bundleDts, {
884
- flag: "w"
885
- }), generatePackageJson({
886
- packageName: options.packageName,
887
- packagePath,
888
- packageVersion: options.packageVersion,
889
- dependencies: [],
890
- peerDependencies: resolvedPeerDependencies,
891
- beta: options.beta
892
- })]);
893
- const absolutePackagePath = isAbsolute(options.outputDir) ? options.outputDir : join(process.cwd(), options.outputDir);
894
- try {
895
- await generateBundles(absolutePackagePath, options.packageName);
896
- } catch (e) {
897
- consola.error(e);
898
- }
899
- }
900
-
901
- // src/generate/commandUtils.ts
902
- function transformArrayArg(arg) {
903
- if (arg && arg.length > 0) {
904
- if (arg[0] === void 0) {
905
- return void 0;
906
- }
907
- }
908
- return arg;
909
- }
910
-
911
- // src/generate/GeneratePackageCommand.ts
912
- var GeneratePackageCommand = class {
913
- command = "generatePackage";
914
- describe = "Generates a new npm package which can be published";
915
- constructor() {
916
- }
917
- builder(args) {
918
- return args.positional("authToken", {
919
- type: "string",
920
- demandOption: true
921
- }).positional("foundryHostname", {
922
- type: "string",
923
- demandOption: true
924
- }).positional("packageName", {
925
- type: "string",
926
- demandOption: true,
927
- description: "The name of the package to generate"
928
- }).positional("packageVersion", {
929
- type: "string",
930
- demandOption: true,
931
- description: "The version of the package to generate"
932
- }).positional("outputDir", {
933
- type: "string",
934
- demandOption: true,
935
- description: "The path where the package with the provided package name will be generated"
936
- }).positional("ontology", {
937
- type: "string",
938
- demandOption: true,
939
- description: `The ontology rid or ontology API name of the ontology to generate. Example Usage: --ontology palantirOntology`,
940
- default: "ri.ontology.main.ontology.00000000-0000-0000-0000-000000000000"
941
- }).options("objectTypes", {
942
- array: true,
943
- string: true,
944
- demandOption: false,
945
- description: `The API names of the object types to generate. Example Usage: --objectTypes Aircraft Airport`,
946
- default: void 0,
947
- defaultDescription: `By default, no arguments will not load any object type.`
948
- }).options("actionTypes", {
949
- array: true,
950
- string: true,
951
- demandOption: false,
952
- description: `The API names of the action types to generate. Example Usage: --actionTypes schedule-airplane-maintenance`,
953
- default: void 0,
954
- defaultDescription: `By default, no arguments will not load any action type.`
955
- }).options("linkTypes", {
956
- array: true,
957
- string: true,
958
- demandOption: false,
959
- description: `The link types to generate in the format of ObjectTypeApiName.LinkTypeApiName. Example Usage: --linkTypes Aircraft.scheduledFlight`,
960
- default: void 0,
961
- defaultDescription: `By default, no arguments will not load any link type.`
962
- }).options("queryTypes", {
963
- array: true,
964
- string: true,
965
- demandOption: false,
966
- description: `The API Names of the query types to generate. Example Usage: --queryTypes calculateMetric`,
967
- default: void 0,
968
- defaultDescription: `By default, no arguments will not load any query type.`
969
- }).options("interfaceTypes", {
970
- array: true,
971
- string: true,
972
- demandOption: false,
973
- description: `The API Names of the interface types to generate. Example Usage: --interfaceTypes Geolocatable`,
974
- default: void 0,
975
- defaultDescription: `By default, no arguments will not load any interface type.`
976
- }).options("experimentalFeatures", {
977
- array: true,
978
- string: true,
979
- demandOption: false,
980
- description: `Experimental features that can be modified or removed at any time. Example Usage: --experimentalFeatures realtimeUpdates`,
981
- default: void 0,
982
- defaultDescription: `By default, no arguments will not enable any experimental features.`
983
- }).options("beta", {
984
- boolean: true,
985
- demandOption: false,
986
- hidden: true,
987
- default: false
988
- }).options("sdkPackages", {
989
- array: true,
990
- string: true,
991
- // experimental for now
992
- hidden: true,
993
- coerce: (arg) => {
994
- return new Map(arg.map((sdkPackage) => sdkPackage.split("=", 2)));
995
- }
996
- }).strict();
997
- }
998
- handler = async (args) => {
999
- const {
1000
- consola
1001
- } = await import('consola');
1002
- consola.start(`Generating OSDK: ${args.packageName} at version: ${args.packageVersion}`);
1003
- const ontologyRid = args.ontology;
1004
- const ontologyMetadataResolver = new OntologyMetadataResolver(args.authToken, args.foundryHostname);
1005
- if (!isValidSemver(args.packageVersion)) {
1006
- consola.error(new Error(`Invalid argument provided for packageVersion: ${args.packageVersion}, expected valid semver`));
1007
- exit(1);
1008
- }
1009
- const packageInfo = await ontologyMetadataResolver.getInfoForPackages(args.sdkPackages ?? /* @__PURE__ */ new Map());
1010
- const timeStart = Date.now();
1011
- const wireOntologyDefinition = await ontologyMetadataResolver.getWireOntologyDefinition(ontologyRid, {
1012
- objectTypesApiNamesToLoad: transformArrayArg(args.objectTypes),
1013
- actionTypesApiNamesToLoad: transformArrayArg(args.actionTypes),
1014
- queryTypesApiNamesToLoad: transformArrayArg(args.queryTypes),
1015
- interfaceTypesApiNamesToLoad: transformArrayArg(args.interfaceTypes),
1016
- linkTypesApiNamesToLoad: transformArrayArg(args.linkTypes)
1017
- }, packageInfo);
1018
- if (wireOntologyDefinition.isErr()) {
1019
- wireOntologyDefinition.error.forEach((err) => {
1020
- consola.error(err);
1021
- });
1022
- consola.error("Failed generating package");
1023
- exit(1);
1024
- }
1025
- await generatePackage(wireOntologyDefinition.value, {
1026
- packageName: args.packageName,
1027
- packageVersion: args.packageVersion,
1028
- outputDir: args.outputDir,
1029
- beta: !!args.beta
1030
- });
1031
- const elapsedTime = Date.now() - timeStart;
1032
- consola.success(`Finished generating package in ${(elapsedTime / 1e3).toFixed(2)}s`);
1033
- return;
1034
- };
1035
- };
1036
-
1037
- // src/cli/foundrySdkGeneratorCli.ts
1038
- async function cli(args = process.argv) {
1039
- const base = yargs(hideBin(args)).command(new GeneratePackageCommand()).demandCommand().recommendCommands().strict().showHelpOnFail(true).help().version(process.env.npm_package_version);
1040
- try {
1041
- return base.parseAsync();
1042
- } catch (e) {
1043
- console.log(e);
1044
- }
1045
- }
1046
-
1047
- export { GeneratePackageCommand as __testSeamOnly_NotSemverStable__GeneratePackageCommand, cli };
1048
- //# sourceMappingURL=index.js.map
1049
- //# sourceMappingURL=index.js.map